diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 3d05e9a4..76132e73 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -57,11 +57,16 @@ set (CMAKE_CXX_STANDARD_REQUIRED ON) set (rtphone_libs libs) set (rtphone_engine engine) -set (USE_AMR_CODEC OFF CACHE BOOL "Use AMR codec. Requires libraries.") -set (USE_EVS_CODEC OFF CACHE BOOL "Use EVS codec.") +option (USE_AMR_CODEC "Use AMR codec. Requires libraries." OFF) +option (USE_EVS_CODEC "Use EVS codec." OFF) set (CMAKE_POSITION_INDEPENDENT_CODE ON) +if (NOT DEFINED LIB_PLATFORM) + set (LIB_PLATFORM ${CMAKE_CURRENT_SOURCE_DIR}/../../libraries) +endif() + +message("Libraries: ${LIB_PLATFORM}") set (OPENSSL_INCLUDE ${LIB_PLATFORM}/openssl/1.0/include) message ("Using OpenSSL include files from ${OPENSSL_INCLUDE}") @@ -164,6 +169,10 @@ if (USE_AMR_CODEC) set (LIBS ${LIBS} opencore-amrnb opencore-amrwb) endif (USE_AMR_CODEC) +if (USE_EVS_CODEC) + add_definitions(-DUSE_EVS_CODEC) +endif() + target_link_libraries(rtphone ice_stack jrtplib g729_codec gsm_codec gsmhr_codec g722_codec srtp resiprocate @@ -186,6 +195,9 @@ target_include_directories(rtphone ${LIB_PLATFORM}/opus/include PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/libs/ + ${CMAKE_CURRENT_SOURCE_DIR}/libs/libevs/lib_com + ${CMAKE_CURRENT_SOURCE_DIR}/libs/libevs/lib_enc + ${CMAKE_CURRENT_SOURCE_DIR}/libs/libevs/lib_dec ${CMAKE_CURRENT_SOURCE_DIR}/libs/speex/include ${CMAKE_CURRENT_SOURCE_DIR}/libs/opus/include/ ${CMAKE_CURRENT_SOURCE_DIR}/libs/json diff --git a/src/engine/media/CMakeLists.txt b/src/engine/media/CMakeLists.txt index c0ff0a5d..b6d1b1ab 100644 --- a/src/engine/media/CMakeLists.txt +++ b/src/engine/media/CMakeLists.txt @@ -35,8 +35,16 @@ target_include_directories(media_lib ${CMAKE_CURRENT_SOURCE_DIR}/../../libs/webrtc ${CMAKE_CURRENT_SOURCE_DIR}/../../libs/opus/include/ ${CMAKE_CURRENT_SOURCE_DIR}/../../libs/resiprocate/ + ${CMAKE_CURRENT_SOURCE_DIR}/../../libs/libevs/ ) +target_include_directories(media_lib + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../../libs/libevs/lib_com + ${CMAKE_CURRENT_SOURCE_DIR}/../../libs/libevs/lib_dec + ${CMAKE_CURRENT_SOURCE_DIR}/../../libs/libevs/lib_enc + ${CMAKE_CURRENT_SOURCE_DIR}/../../libs/libevs/basic_op + ${CMAKE_CURRENT_SOURCE_DIR}/../../libs/libevs/basic_math +) if (USE_RESIP_INTEGRATION) message("USE_RESIP_INTEGRATION is turned on!") target_compile_definitions(media_lib PUBLIC -DUSE_RESIP_INTEGRATION) diff --git a/src/engine/media/MT_EvsCodec.cpp b/src/engine/media/MT_EvsCodec.cpp index e69de29b..ad84fda0 100644 --- a/src/engine/media/MT_EvsCodec.cpp +++ b/src/engine/media/MT_EvsCodec.cpp @@ -0,0 +1,206 @@ +#include "MT_EvsCodec.h" + +//bool + +EVSCodec::EVSFactory::EVSFactory(StreamParameters sp) : _sp(sp) +{} + +int EVSCodec::EVSFactory::samplerate() +{ + return 0; +} + +int EVSCodec::EVSFactory::payloadType() +{ + return 0; +} + +PCodec EVSCodec::EVSFactory::create() +{ + return std::static_pointer_cast(std::make_shared(_sp)); +} + +EVSCodec::EVSCodec(): EVSCodec(StreamParameters()) +{ +} + +EVSCodec::EVSCodec(const StreamParameters &sp) +{ + EVSCodec::sp = sp; + + if ((st_dec = (Decoder_State*)malloc(sizeof(Decoder_State))) == NULL) + { + std::stringstream out; + out << "Can not allocate memory for decoder state structure\n"; + throw std::out_of_range(out.str()); + } + /*if ((st_enc = (Encoder_State*)malloc(sizeof(Encoder_State))) == NULL) + { + std::stringstream out; + out << "Can not allocate memory for encoder state structure\n"; + throw std::out_of_range(out.str()); + }*/ + initDecoder(sp); +} + +EVSCodec::~EVSCodec() +{ + if (st_dec) + { + destroy_decoder(st_dec); + free(st_dec); + } +} + +int EVSCodec::samplerate() +{ + return st_dec->output_Fs; +} + +int EVSCodec::samplerate(int CodecMode) +{ + return samplerate(); +} + +int EVSCodec::pcmLength() +{ + return samplerate() / 50; +} + +int EVSCodec::pcmLength(int CodecMode) +{ + return pcmLength(); +} + +int EVSCodec::frameTime() +{ + return sp.ptime; +} + +int EVSCodec::rtpLength() +{ + return 0; +} + +int EVSCodec::encode(const void* input, int inputBytes, void* output, int outputCapacity) +{ + return 0; +} + +int EVSCodec::decode(const void* input, int input_length, void* output, int outputCapacity) +{ + if (outputCapacity < L_FRAME8k) + { + std::stringstream out; + out << "Buffer for pcm frame is to small\n"; + throw std::out_of_range(out.str()); + } + + std::string buffer; + + /*if we have FixedPayload without ToC*/ + if (FixedPayload_EVSPrimary.find(input_length * 8) != FixedPayload_EVSPrimary.end()) + { + char c = rate2EVSmode(FixedPayload_EVSPrimary.find(input_length * 8)->second); + /* Add ToC byte. + * WARNING maybe it will be work incorrect with 56bit payload, + * see 3GPP TS 26.445 Annex A, A.2.1.3 */ + buffer += c; + } + + buffer += std::string(reinterpret_cast(input), input_length); + + // Output buffer for 48 KHz + float data[L_FRAME48k]; + int offset = 0; + + /* Decode process */ + size_t buffer_processed = 0; + + while (st_dec->bitstreamformat == G192 ? read_indices(st_dec, buffer.c_str(), buffer.size(), &buffer_processed, 0) : read_indices_mime(st_dec, buffer.c_str(), buffer.size(), &buffer_processed, 0)) + { + if (st_dec->codec_mode == MODE1) + { + if (st_dec->Opt_AMR_WB) + { + amr_wb_dec(st_dec, data); + } + else + { + evs_dec(st_dec, data, FRAMEMODE_NORMAL); + } + } + else + { + if (!st_dec->bfi) + { + evs_dec(st_dec, data, FRAMEMODE_NORMAL); + } + else + { + evs_dec(st_dec, data, FRAMEMODE_MISSING); + } + } + + /* convert 'float' output data to 'short' */ + syn_output(data, this->pcmLength(), static_cast(output) + offset); + offset += this->pcmLength(); + if (st_dec->ini_frame < MAX_FRAME_COUNTER) + { + st_dec->ini_frame++; + } + } + // std::fclose(temp); + return 1; +} + +int EVSCodec::plc(int lostFrames, void* output, int outputCapacity) +{ + return 0; +} + +void EVSCodec::initDecoder(const StreamParameters& sp) +{ + /* set to NULL, to avoid reading of uninitialized memory in case of early abort */ + st_dec->cldfbAna = st_dec->cldfbBPF = st_dec->cldfbSyn = nullptr; + st_dec->hFdCngDec = nullptr; + st_dec->codec_mode = 0; /* unknown before first frame */ + st_dec->Opt_AMR_WB = 0; + st_dec->Opt_VOIP = 0; + + st_dec->bitstreamformat = G192; + st_dec->amrwb_rfc4867_flag = -1; + + /*Set MIME type*/ + if (sp.mime) { + st_dec->bitstreamformat = MIME; + st_dec->amrwb_rfc4867_flag = 0; + } + /*Set Bandwidth*/ + switch (sp.bw) { + case NB : + st_dec->output_Fs = 8000; + break; + case WB: + st_dec->output_Fs = 16000; + break; + case SWB: + st_dec->output_Fs = 32000; + break; + case FB: + st_dec->output_Fs = 48000; + break; + } + // st_enc->input_Fs = st_dec->output_Fs; //TODO: remove when func initEncoder() is added + /*------------------------------------------------------------------------------------------* + * Allocate memory for static variables + * Decoder initialization + *------------------------------------------------------------------------------------------*/ + + // TODO: add ability of reinit Decoder_state, may be need use destroy_decoder() + init_decoder(st_dec); + reset_indices_dec(st_dec); + + srand(static_cast(time(nullptr))); + +} diff --git a/src/engine/media/MT_EvsCodec.h b/src/engine/media/MT_EvsCodec.h index a40fee62..6a62aed2 100644 --- a/src/engine/media/MT_EvsCodec.h +++ b/src/engine/media/MT_EvsCodec.h @@ -1,157 +1,210 @@ -#ifndef MT_EVSCODEC_H -#define MT_EVSCODEC_H +#pragma once -#include "../config.h" +#include #include -#include "MT_Codec.h" -#include "../helper/HL_Pointer.h" +#include +#include +#include +#include +#include +#include +#include -#if defined(USE_EVS_CODEC) -namespace MT +extern "C" { + //#include "lib_dec/EvsRXlib.h" + #include "libevs/lib_com/prot.h" +} + +/*-------------------------------------------------------------------* +* rate2AMRWB_IOmode() +* +* lookup AMRWB IO mode +*-------------------------------------------------------------------*/ + +static Word16 rate2AMRWB_IOmode( + Word32 rate /* i: bit rate */ +); + +/*Revers Function*/ +extern Word16 AMRWB_IOmode2rate( + Word32 mode +); + +/*-------------------------------------------------------------------* +* rate2EVSmode() +* +* lookup EVS mode +*-------------------------------------------------------------------*/ +extern Word16 rate2EVSmode( + Word32 rate /* i: bit rate */ +); + +/*Revers Function*/ +extern Word16 EVSmode2rate( + Word32 mode +); + +class Codec; +typedef std::shared_ptr PCodec; + +#define CMR_OFF -1 +#define CMR_ON 0 +#define CMR_ONLY 1 + + +static const std::map> BitrateToBandwidth_Tab{ + {5900, {NB, WB}}, + {7200, {NB, WB}}, + {8000, {NB, WB}}, + {9600, {NB, WB, SWB}}, + {13200, {NB, WB, SWB}}, //if channel aware mode - WB, SWB + {16400, {NB, WB, SWB, FB}}, + {24400, {NB, WB, SWB, FB}}, + {32000, {WB, SWB, FB}}, + {48000, {WB, SWB, FB}}, + {64000, {WB, SWB, FB}}, + {96000, {WB, SWB, FB}}, + {128000, {WB, SWB, FB}} +}; + +/* Protected payload size/Fixed bitrate to EVS ()*/ +static const std::map Bitrate2PayloadSize_EVSAMR_WB{ + /*{bitrate, payload size}*/ + { SID_1k75, 56}, //AMR-WB I/O SIB + {ACELP_6k60, 136}, + {ACELP_8k85, 184}, + {ACELP_12k65, 256}, + {ACELP_14k25, 288}, + {ACELP_15k85, 320}, + {ACELP_18k25, 368}, + {ACELP_19k85, 400}, + {ACELP_23k05, 464}, + {ACELP_23k85, 480} +}; + +static const std::map Bitrate2PayloadSize_EVS{ + /*{bitrate, payload size}*/ + {FRAME__NO_DATA, 0}, + {SID_2k40, 48}, //EVS Primary SID + {PPP_NELP_2k80, 56}, //special for full header + {ACELP_7k20, 144}, + {ACELP_8k00, 160}, + {ACELP_9k60, 192}, + {ACELP_13k20, 264}, + {ACELP_16k40, 328}, + {ACELP_24k40, 488}, + {ACELP_32k, 640}, + {ACELP_48k, 960}, + {ACELP_64k, 1280}, + {HQ_96k, 1920}, + {HQ_128k, 2560} +}; + +/* Protected payload size/Fixed bitrate to EVS ()*/ +static const std::map FixedPayload_EVSPrimary{ + /*{payload size , bitrate}*/ + {48, 2400}, //EVS Primary SID + {56, 2800}, //special for full header + {144, 7200}, + {160, 8000}, + {192, 9600}, + {264, 13200}, + {328, 16400}, + {488, 24400}, + {640, 32000}, + {960, 48000}, + {1280, 64000}, + {1920, 96000}, + {2560, 128000} +}; + +static const std::map FixedPayload_EVSAMR_WB{ + /*{payload size , bitrate}*/ + {136, 6600}, + {184, 8850}, + {256, 12650}, + {288, 14250}, + {320, 15850}, + {368, 18250}, + {400, 19850}, + {464, 23050}, + {480, 23850} +}; + +struct StreamParameters { + bool mime = false; + bool fh_only = false; /*not use*/ + int CRMByte = CMR_OFF;/*not use*/ + int br = 0; /*not use*/ + int bw = NB; + int ptime = 20; +}; //Emulated SDP config/meadia type parameters + +class Codec { - struct AmrCodecConfig - { - bool mIuUP; - bool mOctetAligned; - int mPayloadType; - }; - - class AmrNbCodec : public Codec - { - protected: - void* mEncoderCtx; - void* mDecoderCtx; - AmrCodecConfig mConfig; - unsigned mCurrentDecoderTimestamp; - int mSwitchCounter; - int mPreviousPacketLength; - - public: - class CodecFactory: public Factory +public: + class Factory { public: - CodecFactory(const AmrCodecConfig& config); + virtual ~Factory() {} + virtual const char* name() = 0; + virtual int samplerate() = 0; + virtual int payloadType() = 0; + virtual PCodec create() = 0; - const char* name() override; - int samplerate() override; - int payloadType() override; - -#if defined(USE_RESIP_INTEGRATION) - void updateSdp(resip::SdpContents::Session::Medium::CodecContainer& codecs, SdpDirection direction) override; - int processSdp(const resip::SdpContents::Session::Medium::CodecContainer& codecs, SdpDirection direction) override; - void create(CodecMap& codecs) override; -#endif - PCodec create() override; - - protected: - AmrCodecConfig mConfig; + virtual int channels() = 0; }; + virtual ~Codec() {} + virtual const char* name() = 0; + virtual int samplerate() = 0; + virtual float timestampUnit() { return float(1.0 / samplerate()); } + virtual int pcmLength() = 0; + virtual int frameTime() = 0; + virtual int rtpLength() = 0; + virtual int channels() { return 1; } + virtual int encode(const void* input, int inputBytes, void* output, int outputCapacity) = 0; + virtual int decode(const void* input, int inputBytes, void* output, int outputCapacity) = 0; + virtual int plc(int lostFrames, void* output, int outputCapacity) = 0; - AmrNbCodec(const AmrCodecConfig& config); + // Returns size of codec in memory + virtual int getSize() const { return 0; }; +}; - virtual ~AmrNbCodec(); - const char* name() override; - int pcmLength() override; - int rtpLength() override; - int frameTime() override; - int samplerate() override; - int encode(const void* input, int inputBytes, void* output, int outputCapacity) override; - int decode(const void* input, int inputBytes, void* output, int outputCapacity) override; - int plc(int lostFrames, void* output, int outputCapacity) override; - int getSwitchCounter() const; - }; +class EVSCodec : public Codec +{ +private: + Decoder_State* st_dec; + //Encoder_State_fx* st_enc; + StreamParameters sp; - class AmrWbCodec : public Codec - { - protected: - void* mEncoderCtx; - void* mDecoderCtx; - AmrCodecConfig mConfig; - uint64_t mCurrentDecoderTimestamp; - int mSwitchCounter; - int mPreviousPacketLength; - - public: - class CodecFactory: public Factory +public: + class EVSFactory : public Factory { - public: - CodecFactory(const AmrCodecConfig& config); - - const char* name() override; - int samplerate() override; - int payloadType() override; - -#if defined(USE_RESIP_INTEGRATION) - void updateSdp(resip::SdpContents::Session::Medium::CodecContainer& codecs, SdpDirection direction) override; - int processSdp(const resip::SdpContents::Session::Medium::CodecContainer& codecs, SdpDirection direction) override; - void create(CodecMap& codecs) override; -#endif - PCodec create() override; - protected: - AmrCodecConfig mConfig; + StreamParameters _sp; + + public: + EVSFactory(StreamParameters sp); + const char* name() { return "EVS"; }; + int samplerate(); + int payloadType(); + PCodec create(); + int channels() { return 1; } //without support stereo audio transmition }; - AmrWbCodec(const AmrCodecConfig& config); - virtual ~AmrWbCodec(); - - const char* name() override; - int pcmLength() override; - int rtpLength() override; - int frameTime() override; - int samplerate() override; - int encode(const void* input, int inputBytes, void* output, int outputCapacity) override; - int decode(const void* input, int inputBytes, void* output, int outputCapacity) override; - int plc(int lostFrames, void* output, int outputCapacity) override; - int getSwitchCounter() const; - }; - - class GsmEfrCodec : public Codec - { - protected: - void* mEncoderCtx; - void* mDecoderCtx; - bool mIuUP; - - public: - class GsmEfrFactory: public Factory - { - public: - GsmEfrFactory(bool iuup, int ptype); - - const char* name() override; - int samplerate() override; - int payloadType() override; - -#if defined(USE_RESIP_INTEGRATION) - void updateSdp(resip::SdpContents::Session::Medium::CodecContainer& codecs, SdpDirection direction) override; - int processSdp(const resip::SdpContents::Session::Medium::CodecContainer& codecs, SdpDirection direction) override; - void create(CodecMap& codecs) override; -#endif - PCodec create() override; - - protected: - bool mIuUP; - int mPayloadType; - }; - - GsmEfrCodec(bool iuup = false); - - virtual ~GsmEfrCodec(); - const char* name() override; - int pcmLength() override; - int rtpLength() override; - int frameTime() override; - int samplerate() override; - int encode(const void* input, int inputBytes, void* output, int outputCapacity) override; - int decode(const void* input, int inputBytes, void* output, int outputCapacity) override; - int plc(int lostFrames, void* output, int outputCapacity) override; - }; - -} // End of MT namespace - - -#endif - -#endif // MT_EVSCODE_H + EVSCodec(); + EVSCodec(const StreamParameters& sp); + ~EVSCodec() override; + const char* name() { return "EVS"; }; + int samplerate(); + int samplerate(int CodecMode); // DEC or ENC defined in cnst.h + int pcmLength(); + int pcmLength(int CodecMode); // DEC or ENC defined in cnst.h + int frameTime(); + int rtpLength(); + int encode(const void* input, int inputBytes, void* output, int outputCapacity); + int decode(const void* input, int inputBytes, void* output, int outputCapacity); + int plc(int lostFrames, void* output, int outputCapacity) ; + void initDecoder(const StreamParameters& sp); +}; diff --git a/src/libs/libevs/CMakeLists.txt.user b/src/libs/libevs/CMakeLists.txt.user new file mode 100644 index 00000000..5d1207cb --- /dev/null +++ b/src/libs/libevs/CMakeLists.txt.user @@ -0,0 +1,345 @@ + + + + + + EnvironmentId + {3afbbbef-07ad-4e54-a4d3-e24ca448be01} + + + ProjectExplorer.Project.ActiveTarget + 0 + + + ProjectExplorer.Project.EditorSettings + + true + false + true + + Cpp + + CppGlobal + + + + QmlJS + + QmlJSGlobal + + + 2 + UTF-8 + false + 4 + false + 80 + true + true + 1 + true + false + 0 + true + true + 0 + 8 + true + 1 + true + true + true + false + + + + ProjectExplorer.Project.PluginSettings + + + true + + + + ProjectExplorer.Project.Target.0 + + Desktop Qt 5.14.0 GCC 64bit + Desktop Qt 5.14.0 GCC 64bit + qt.qt5.5140.gcc_64_kit + 0 + 0 + 0 + + + CMAKE_BUILD_TYPE:STRING=Debug + CMAKE_CXX_COMPILER:STRING=%{Compiler:Executable:Cxx} + CMAKE_C_COMPILER:STRING=%{Compiler:Executable:C} + CMAKE_PREFIX_PATH:STRING=%{Qt:QT_INSTALL_PREFIX} + QT_QMAKE_EXECUTABLE:STRING=%{Qt:qmakeExecutable} + + /home/anand/works/sevana/platform/rtphone/src/libs/build-libevs-Desktop_Qt_5_14_0_GCC_64bit-Debug + + + + + all + + true + CMakeProjectManager.MakeStep + + 1 + Build + Build + ProjectExplorer.BuildSteps.Build + + + + + + clean + + true + CMakeProjectManager.MakeStep + + 1 + Clean + Clean + ProjectExplorer.BuildSteps.Clean + + 2 + false + + Debug + CMakeProjectManager.CMakeBuildConfiguration + + + + CMAKE_BUILD_TYPE:STRING=Release + CMAKE_CXX_COMPILER:STRING=%{Compiler:Executable:Cxx} + CMAKE_C_COMPILER:STRING=%{Compiler:Executable:C} + CMAKE_PREFIX_PATH:STRING=%{Qt:QT_INSTALL_PREFIX} + QT_QMAKE_EXECUTABLE:STRING=%{Qt:qmakeExecutable} + + /home/anand/works/sevana/platform/rtphone/src/libs/build-libevs-Desktop_Qt_5_14_0_GCC_64bit-Release + + + + + all + + true + CMakeProjectManager.MakeStep + + 1 + Build + Build + ProjectExplorer.BuildSteps.Build + + + + + + clean + + true + CMakeProjectManager.MakeStep + + 1 + Clean + Clean + ProjectExplorer.BuildSteps.Clean + + 2 + false + + Release + CMakeProjectManager.CMakeBuildConfiguration + + + + CMAKE_BUILD_TYPE:STRING=RelWithDebInfo + CMAKE_CXX_COMPILER:STRING=%{Compiler:Executable:Cxx} + CMAKE_C_COMPILER:STRING=%{Compiler:Executable:C} + CMAKE_PREFIX_PATH:STRING=%{Qt:QT_INSTALL_PREFIX} + QT_QMAKE_EXECUTABLE:STRING=%{Qt:qmakeExecutable} + + /home/anand/works/sevana/platform/rtphone/src/libs/build-libevs-Desktop_Qt_5_14_0_GCC_64bit-RelWithDebInfo + + + + + all + + true + CMakeProjectManager.MakeStep + + 1 + Build + Build + ProjectExplorer.BuildSteps.Build + + + + + + clean + + true + CMakeProjectManager.MakeStep + + 1 + Clean + Clean + ProjectExplorer.BuildSteps.Clean + + 2 + false + + Release with Debug Information + CMakeProjectManager.CMakeBuildConfiguration + + + + CMAKE_BUILD_TYPE:STRING=MinSizeRel + CMAKE_CXX_COMPILER:STRING=%{Compiler:Executable:Cxx} + CMAKE_C_COMPILER:STRING=%{Compiler:Executable:C} + CMAKE_PREFIX_PATH:STRING=%{Qt:QT_INSTALL_PREFIX} + QT_QMAKE_EXECUTABLE:STRING=%{Qt:qmakeExecutable} + + /home/anand/works/sevana/platform/rtphone/src/libs/build-libevs-Desktop_Qt_5_14_0_GCC_64bit-MinSizeRel + + + + + all + + true + CMakeProjectManager.MakeStep + + 1 + Build + Build + ProjectExplorer.BuildSteps.Build + + + + + + clean + + true + CMakeProjectManager.MakeStep + + 1 + Clean + Clean + ProjectExplorer.BuildSteps.Clean + + 2 + false + + Minimum Size Release + CMakeProjectManager.CMakeBuildConfiguration + + 4 + + + 0 + Deploy + Deploy + ProjectExplorer.BuildSteps.Deploy + + 1 + ProjectExplorer.DefaultDeployConfiguration + + 1 + + + dwarf + + cpu-cycles + + + 250 + + -e + cpu-cycles + --call-graph + dwarf,4096 + -F + 250 + + -F + true + 4096 + false + false + 1000 + + true + + false + false + false + false + true + 0.01 + 10 + true + kcachegrind + 1 + 25 + + 0 + true + false + false + valgrind + + 0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12 + 13 + 14 + + 2 + + + ProjectExplorer.CustomExecutableRunConfiguration + + + false + + false + true + false + false + true + + + + 1 + + + + ProjectExplorer.Project.TargetCount + 1 + + + ProjectExplorer.Project.Updater.FileVersion + 22 + + + Version + 22 + + diff --git a/src/libs/libevs/basic_math/log2.cpp b/src/libs/libevs/basic_math/log2.cpp deleted file mode 100755 index 57abb335..00000000 --- a/src/libs/libevs/basic_math/log2.cpp +++ /dev/null @@ -1,211 +0,0 @@ -/******************************************************************************** -* -* File : log2.c -* Purpose : Computes log2(L_x) -* -******************************************************************************** -*/ - -/* -******************************************************************************** -* INCLUDE FILES -******************************************************************************** -*/ -#include "stl.h" -#include "math_op.h" -#include -#include "rom_basic_math.h" -#include "options.h" - -#define LW_SIGN (Word32)0x80000000 /* sign bit */ -#define LW_MIN (Word32)0x80000000 -#define LW_MAX (Word32)0x7fffffff - -#define SW_SIGN (Word16)0x8000 /* sign bit for Word16 type */ -#define SW_MIN (Word16)0x8000 /* smallest Ram */ -#define SW_MAX (Word16)0x7fff /* largest Ram */ - - -/* -******************************************************************************** -* PUBLIC PROGRAM CODE -******************************************************************************** -*/ - -/************************************************************************* - * - * FUNCTION: Log2_norm_lc() - * - * PURPOSE: Computes log2(L_x, exp), where L_x is positive and - * normalized, and exp is the normalisation exponent - * If L_x is negative or zero, the result is 0. - * - * DESCRIPTION: - * The function Log2(L_x) is approximated by a table and linear - * interpolation. The following steps are used to compute Log2(L_x) - * - * 1- exponent = 30-norm_exponent - * 2- i = bit25-b31 of L_x; 32<=i<=63 (because of normalization). - * 3- a = bit10-b24 - * 4- i -=32 - * 5- fraction = table[i]<<16 - (table[i] - table[i+1]) * a * 2 - * - *************************************************************************/ -Word16 Log2_norm_lc ( /* (o) : Fractional part of Log2. (range: 0<=val<1) */ - Word32 L_x /* (i) : input value (normalized) */ -) -{ - Word16 i, a; - Word16 y; - - if (L_x <= 0) - L_x = L_deposit_h(0x4000); - - L_x = L_shr (L_x, 9); - a = extract_l (L_x); /* Extract b10-b24 of fraction */ - a = lshr(a, 1); - - i = mac_r(L_x, -32*2-1, 16384); /* Extract b25-b31 minus 32 */ - - y = mac_r(L_table_Log2_norm_lc[i], table_diff_Log2_norm_lc[i], a); /* table[i] << 16 - diff*a*2 */ - - return y; -} - -Word32 log10_fx(Word32 Linput) -{ - Word16 n1, frac, p1, p2, q1; - Word32 Ltemp1, Ltemp2; - Word32 L_tmp; - - if (Linput<=0) return(LW_MIN); - n1=norm_l(Linput); - Ltemp1=(Word32)L_shl(Linput,n1); - - Ltemp2=L_mult(extract_h(Ltemp1),0x40); - frac=extract_l(Ltemp2); - - p1=log2_tab[sub(extract_h(Ltemp2),0x20)]; - p2=log2_tab[sub(extract_h(Ltemp2),0x1F)]; - Ltemp2=L_mult(n1,0x200); - n1=extract_l(Ltemp2); - - Ltemp1=L_add(L_deposit_h(p1),0x8000); /* Add rounding bit */ - - IF(frac >= 0) - { - Ltemp1=L_sub(Ltemp1,(Word32)L_mult0(p1,frac)); - Ltemp1=L_add(Ltemp1,(Word32)L_mult0(p2,frac)); - } - ELSE - { - L_tmp = L_add(65536,frac); - L_tmp = L_tmp*p1; - Ltemp1=L_sub(Ltemp1,L_tmp); - - L_tmp = L_add(65536,frac); - L_tmp = L_tmp*p2; - Ltemp1=L_add(Ltemp1,L_tmp); - } - q1=extract_h(Ltemp1); - Ltemp1=L_mult(q1,0x6054); - Ltemp1=L_msu(Ltemp1,0x6054,n1); - return(L_shr(Ltemp1,1)); - -} - -Word32 pow_10(Word32 x , Word16 *Q) -{ - Word16 xl,xh, t1, t2, n; - Word32 Ltemp1; - Word32 Lacc; - Word32 L_tmp; - Word16 n1,i; - Word16 count = 0; - - move16();; - - xl=extract_l(x); - xh=extract_h(x); - - IF(xl < 0) - { - L_tmp = L_add(65536,xl); - Ltemp1=(Word32) (0x6a4d*L_tmp ); - } - ELSE - { - Ltemp1=L_mult0(0x6a4d,xl); - } - Ltemp1=L_add(L_shr(Ltemp1,16),L_shr(L_mult(xh,0x6a4d),1)); - - - Lacc=L_sub(-1L, Ltemp1); /* Lacc=~Lacc, 1's complement */ - t1=extract_l(L_shr(Lacc,7)); - - Ltemp1=L_shr(Ltemp1,7); - n1 = extract_h(Ltemp1); - n=sub(n1,14); - *Q = 14; move16(); - IF(t1<0) - { - L_tmp = L_add(65536,t1); - t2=extract_h(L_tmp*L_tmp); - } - ELSE - { - t2=extract_h(L_mult0(t1,t1)); - } - - Lacc = L_deposit_h(0x1FEF); - IF(t2 < 0) - { - L_tmp = L_add(65536,t2); - Lacc = L_add(Lacc,(Word32)(L_tmp*0x057C)); - } - ELSE - { - Lacc = L_add(Lacc,(Word32)L_mult0(t2,0x057C)); - } - - IF(t1 < 0) - { - L_tmp = L_add(65536,t1); - Lacc = L_sub(Lacc,(Word32)(L_tmp*0x155C)); - } - ELSE - { - Lacc = L_sub(Lacc,(Word32)L_mult0(t1,0x155C)); - } - - L_tmp = Lacc; - FOR(i =1 ;i <= n ;i++) - { - Overflow = 0; move16(); - L_tmp = L_shl(L_tmp,i); - IF(Overflow) - { - count = add(count,1); - } - } - *Q = sub(*Q,count); move16(); - - return(L_shl(Lacc,sub(n,count))); - -} - -Word16 Log2_lc( /* (o) : Fractional part of Log2. (range: 0<=val<1) */ - Word32 L_x, /* (i) : input value */ - Word16 *exponent /* (o) : Integer part of Log2. (range: 0<=val<=30) */ -) -{ - Word16 exp; - - if (L_x <= 0) - L_x = L_deposit_l(0x1); - - exp = norm_l (L_x); - *exponent = sub(30, exp); move16(); - - return Log2_norm_lc(L_shl(L_x, exp)); -} diff --git a/src/libs/libevs/basic_math/log2.h b/src/libs/libevs/basic_math/log2.h deleted file mode 100755 index a8ff32e6..00000000 --- a/src/libs/libevs/basic_math/log2.h +++ /dev/null @@ -1,40 +0,0 @@ -/******************************************************************************** -* -* File : log2.h -* Purpose : Computes log2(L_x) -* -******************************************************************************** -*/ -#ifndef log2_h -#define log2_h "$Id $" - -/* -******************************************************************************** -* INCLUDE FILES -******************************************************************************** -*/ -#include "typedef.h" -#include "log2.h" - -/* -******************************************************************************** -* DEFINITION OF DATA TYPES -******************************************************************************** -*/ - -/* -******************************************************************************** -* DECLARATION OF PROTOTYPES -******************************************************************************** -*/ -Word16 Log2_norm_lc ( /* (o) : Fractional part of Log2. (range: 0<=val<1) */ - Word32 L_x /* (i) : input value (normalized) */ -); - -Word32 log10_fx(Word32 Linput); -Word32 pow_10(Word32 x, Word16 *Q); -Word16 Log2_lc( /* (o) : Fractional part of Log2. (range: 0<=val<1) */ - Word32 L_x, /* (i) : input value */ - Word16 *exponent /* (o) : Integer part of Log2. (range: 0<=val<=30) */ -); -#endif diff --git a/src/libs/libevs/basic_math/math_32.cpp b/src/libs/libevs/basic_math/math_32.cpp deleted file mode 100755 index cc8282f2..00000000 --- a/src/libs/libevs/basic_math/math_32.cpp +++ /dev/null @@ -1,77 +0,0 @@ -/*#include "options.h" */ -#include "stl.h" -#ifdef ALLOW_40bits -#include "enh40.h" -#endif -#include "oper_32b.h" - -/* 32x16 multiply: */ -Word32 Mult_32_16(Word32 a, Word16 b) -{ - Word32 result; -#ifdef ALLOW_40bits /* if activated; need 40 bits basic-op files */ - UWord16 lo; - /* use Mpy_32_16_ss(): */ - Mpy_32_16_ss(a, b, &result, &lo); -#else - Word16 lo, hi; - /* do things by hand: */ - lo = L_Extract_lc(a, &hi); - result = Mpy_32_16(hi, lo, b); -#endif - return result; -} -/* 32x32 multiply: */ -Word32 Mult_32_32(Word32 a, Word32 b) -{ - Word32 result; -#ifdef ALLOW_40bits /* if activated; need 40 bits basic-op files */ - UWord32 lo; - /* use Mpy_32_32_ss(): */ - Mpy_32_32_ss(a, b, &result, &lo); -#else - Word16 hi, lo, b_hi, b_lo; - /* do things by hand: */ - lo = L_Extract_lc(a, &hi); - b_lo = L_Extract_lc(b, &b_hi); - result = Mpy_32(hi, lo, b_hi, b_lo); -#endif - return result; -} - -/* 32x16 multiply-accumulate: */ -Word32 Madd_32_16(Word32 L_num, Word32 a, Word16 b) -{ - Word32 result; -#ifdef ALLOW_40bits /* if activated; need 40 bits basic-op files */ - UWord16 lo; - /* use Mpy_32_16_ss(): */ - Mpy_32_16_ss(a, b, &result, &lo); - result = L_add(L_num, result); -#else - Word16 lo, hi; - /* do things by hand: */ - lo = L_Extract_lc(a, &hi); - result = Mac_32_16(L_num, hi, lo, b); -#endif - return result; -} - -/* 32x16 multiply-substract: */ -Word32 Msub_32_16(Word32 L_num, Word32 a, Word16 b) -{ - Word32 result; -#ifdef ALLOW_40bits /* if activated; need 40 bits basic-op files */ - UWord16 lo; - /* use Mpy_32_16_ss(): */ - Mpy_32_16_ss(a, b, &result, &lo); - result = L_sub(L_num, result); -#else - Word16 lo, hi; - /* do things by hand: */ - lo = L_Extract_lc(a, &hi); - result = Msu_32_16(L_num, hi, lo, b); -#endif - return result; -} - diff --git a/src/libs/libevs/basic_math/math_32.h b/src/libs/libevs/basic_math/math_32.h deleted file mode 100755 index 0a2c1247..00000000 --- a/src/libs/libevs/basic_math/math_32.h +++ /dev/null @@ -1,12 +0,0 @@ -#ifndef _MATH_32_H_ -#define _MATH_32_H_ - -#include "typedef.h" -#include "basop32.h" - -extern Word32 Mult_32_16(Word32 a, Word16 b); -extern Word32 Madd_32_16(Word32 L_num, Word32 a, Word16 b); -extern Word32 Msub_32_16(Word32 L_num, Word32 a, Word16 b); -extern Word32 Mult_32_32(Word32 a, Word32 b); - -#endif diff --git a/src/libs/libevs/basic_math/math_op.cpp b/src/libs/libevs/basic_math/math_op.cpp deleted file mode 100755 index a5256a2a..00000000 --- a/src/libs/libevs/basic_math/math_op.cpp +++ /dev/null @@ -1,359 +0,0 @@ -/*___________________________________________________________________________ - | | - | This file contains mathematic operations in fixed point. | - | | - | Isqrt() : inverse square root (16 bits precision). | - | Pow2() : 2^x (16 bits precision). | - | Log2() : log2 (16 bits precision). | - | Dot_product() : scalar product of | - | | - | In this file, the values use theses representations: | - | | - | Word32 L_32 : standard signed 32 bits format | - | Word16 hi, lo : L_32 = hi<<16 + lo<<1 (DPF - Double Precision Format) | - | Word32 frac, Word16 exp : L_32 = frac << exp-31 (normalised format) | - | Word16 int, frac : L_32 = int.frac (fractional format) | - |___________________________________________________________________________| -*/ - -#include "stl.h" -#include "math_op.h" -#include "rom_basic_math.h" - -#include -#include - -/*___________________________________________________________________________ - | | - | Function Name : Isqrt | - | | - | Compute 1/sqrt(L_x). | - | if L_x is negative or zero, result is 1 (7fffffff). | - |---------------------------------------------------------------------------| - | Algorithm: | - | | - | 1- Normalization of L_x. | - | 2- call Isqrt_lc(L_x, exponant) | - | 3- L_y = L_x << exponant | - |___________________________________________________________________________| -*/ -Word32 Isqrt( /* (o) Q31 : output value (range: 0<=val<1) */ - Word32 L_x /* (i) Q0 : input value (range: 0<=val<=7fffffff) */ -) -{ - Word16 exp; - Word32 L_y; - - exp = norm_l(L_x); - L_x = L_shl(L_x, exp); /* L_x is normalized */ - exp = sub(31, exp); - - L_x = Isqrt_lc(L_x, &exp); - - L_y = L_shl(L_x, exp); /* denormalization */ - - return (L_y); -} - -/*___________________________________________________________________________ - | | - | Function Name : Isqrt_lc | - | | - | Compute 1/sqrt(value). | - | if value is negative or zero, result is 1 (frac=7fffffff, exp=0). | - |---------------------------------------------------------------------------| - | Algorithm: | - | | - | The function 1/sqrt(value) is approximated by a table and linear | - | interpolation. | - | | - | 1- If exponant is odd then shift fraction right once. | - | 2- exponant = -((exponant-1)>>1) | - | 3- i = bit25-b30 of fraction, 16 <= i <= 63 ->because of normalization. | - | 4- a = bit10-b24 | - | 5- i -=16 | - | 6- fraction = table[i]<<16 - (table[i] - table[i+1]) * a * 2 | - |___________________________________________________________________________| -*/ -Word32 Isqrt_lc( - Word32 frac, /* (i) Q31: normalized value (1.0 < frac <= 0.5) */ - Word16 * exp /* (i/o) : exponent (value = frac x 2^exponent) */ -) -{ - Word16 i, a; - Word32 L_tmp; - - IF (frac <= (Word32) 0) - { - *exp = 0; move16(); - return 0x7fffffff; /*0x7fffffff*/ - } - - /* If exponant odd -> shift right by 10 (otherwise 9) */ - L_tmp = L_shr(frac, shift_Isqrt_lc[s_and(*exp, 1)]); - - /* 1) -16384 to shift left and change sign */ - /* 2) 32768 to Add 1 to Exponent like it was divided by 2 */ - /* 3) We let the mac_r add another 0.5 because it imitates */ - /* the behavior of shr on negative number that should */ - /* not be rounded towards negative infinity. */ - /* It replaces: */ - /* *exp = negate(shr(sub(*exp, 1), 1)); move16(); */ - *exp = mac_r(32768, *exp, -16384); move16(); - - a = extract_l(L_tmp); /* Extract b10-b24 */ - a = lshr(a, 1); - - i = mac_r(L_tmp, -16*2-1, 16384); /* Extract b25-b31 minus 16 */ - - L_tmp = L_msu(L_table_isqrt[i], table_isqrt_diff[i], a);/* table[i] << 16 - diff*a*2 */ - - return L_tmp; -} - -/*___________________________________________________________________________ - | | - | Function Name : Pow2() | - | | - | L_x = pow(2.0, exponant.fraction) (exponant = interger part) | - | = pow(2.0, 0.fraction) << exponant | - |---------------------------------------------------------------------------| - | Algorithm: | - | | - | The function Pow2(L_x) is approximated by a table and linear | - | interpolation. | - | | - | 1- i = bit10-b15 of fraction, 0 <= i <= 31 | - | 2- a = bit0-b9 of fraction | - | 3- L_x = table[i]<<16 - (table[i] - table[i+1]) * a * 2 | - | 4- L_x = L_x >> (30-exponant) (with rounding) | - |___________________________________________________________________________| -*/ - -Word32 Pow2( /* (o) Q0 : result (range: 0<=val<=0x7fffffff) */ - Word16 exponant, /* (i) Q0 : Integer part. (range: 0<=val<=30) */ - Word16 fraction /* (i) Q15 : Fractionnal part. (range: 0.0<=val<1.0) */ -) -{ - Word16 exp, i, a; - Word32 L_x; - - - - i = mac_r(-32768, fraction, 32); /* Extract b10-b16 of fraction */ - a = s_and(fraction, 0x3ff); /* Extract b0-b9 of fraction */ - - L_x = L_deposit_h(table_pow2[i]); /* table[i] << 16 */ - L_x = L_mac(L_x, table_pow2_diff_x32[i], a);/* L_x -= diff*a*2 */ - - exp = sub(30, exponant); - - L_x = L_shr_r(L_x, exp); - - - return L_x; -} - -/*___________________________________________________________________________ - | | - | Function Name : Dot_product12() | - | | - | Compute scalar product of using accumulator. | - | | - | The result is normalized (in Q31) with exponent (0..30). | - |---------------------------------------------------------------------------| - | Algorithm: | - | | - | dot_product = sum(x[i]*y[i]) i=0..N-1 | - |___________________________________________________________________________| -*/ - -Word32 Dot_product12( /* (o) Q31: normalized result (1 < val <= -1) */ - const Word16 x[], /* (i) 12bits: x vector */ - const Word16 y[], /* (i) 12bits: y vector */ - const Word16 lg, /* (i) : vector length */ - Word16 * exp /* (o) : exponent of result (0..+30) */ -) -{ - Word16 i, sft; - Word32 L_sum; - - L_sum = L_mac(1, x[0], y[0]); - FOR (i = 1; i < lg; i++) - L_sum = L_mac(L_sum, x[i], y[i]); - - /* Normalize acc in Q31 */ - - sft = norm_l(L_sum); - L_sum = L_shl(L_sum, sft); - - *exp = sub(30, sft); move16(); /* exponent = 0..30 */ - - return L_sum; -} - -/*___________________________________________________________________________ - | | - | Function Name : Energy_scale() | - | | - | Compute energy of signal (scaling the input if specified) | - | | - | The result is normalized (in Q31) with exponent (0..30). | - |___________________________________________________________________________| -*/ - -Word32 Energy_scale( /* (o) : Q31: normalized result (1 < val <= -1) */ - const Word16 x[], /* (i) : input vector x */ - const Word16 lg, /* (i) : vector length */ - Word16 expi, /* (i) : exponent of input */ - Word16 *exp /* (o) : exponent of result (0..+30) */ -) -{ - Word16 i, sft, tmp; - Word32 L_sum; - - - L_sum = 0; /* just to avoid superflous compiler warning about uninitialized use of L_sum */ - - IF (expi == 0) - { - L_sum = L_mac(1, x[0], x[0]); - FOR (i = 1; i < lg; i++) - { - L_sum = L_mac(L_sum, x[i], x[i]); - } - } - IF (expi < 0) - { - sft = lshl(-32768 /* 0x8000 */, expi); - tmp = mult_r(x[0], sft); - L_sum = L_mac(1, tmp, tmp); - FOR (i = 1; i < lg; i++) - { - tmp = mult_r(x[i], sft); - L_sum = L_mac(L_sum, tmp, tmp); - } - } - IF (expi > 0) - { - tmp = shl(x[0], expi); - L_sum = L_mac(1, tmp, tmp); - FOR (i = 1; i < lg; i++) - { - tmp = shl(x[i], expi); - L_sum = L_mac(L_sum, tmp, tmp); - } - } - - /* Normalize acc in Q31 */ - - sft = norm_l(L_sum); - L_sum = L_shl(L_sum, sft); - - *exp = sub(30, sft); move16(); /* exponent = 0..30 */ - - - return L_sum; -} - -Word32 Sqrt_l( /* o : output value, Q31 */ - Word32 L_x, /* i : input value, Q31 */ - Word16 *exp /* o : right shift to be applied to result, Q1 */ -) -{ - /* - y = sqrt(x) - - x = f * 2^-e, 0.5 <= f < 1 (normalization) - - y = sqrt(f) * 2^(-e/2) - - a) e = 2k --> y = sqrt(f) * 2^-k (k = e div 2, - 0.707 <= sqrt(f) < 1) - b) e = 2k+1 --> y = sqrt(f/2) * 2^-k (k = e div 2, - 0.5 <= sqrt(f/2) < 0.707) - */ - - Word16 e, i, a, tmp; - Word32 L_y; - - if (L_x <= 0) - { - *exp = 0; move16 (); - return L_deposit_l(0); - } - - e = s_and(norm_l(L_x), 0x7FFE); /* get next lower EVEN norm. exp */ - L_x = L_shl(L_x, e); /* L_x is normalized to [0.25..1) */ - *exp = e; move16 (); /* return 2*exponent (or Q1) */ - - L_x = L_shr(L_x, 9); - a = extract_l(L_x); /* Extract b10-b24 */ - a = lshr(a, 1); - - i = mac_r(L_x, -16*2-1, 16384); /* Extract b25-b31 minus 16 */ - - L_y = L_deposit_h(sqrt_table[i]); /* table[i] << 16 */ - tmp = sub(sqrt_table[i], sqrt_table[i + 1]); /* table[i] - table[i+1]) */ - L_y = L_msu(L_y, tmp, a); /* L_y -= tmp*a*2 */ - - /* L_y = L_shr (L_y, *exp); */ /* denormalization done by caller */ - - return (L_y); -} - -/*---------------------------------------------------------------------------* - * L_Frac_sqrtQ31 - * - * Calculate square root from fractional values (Q31 -> Q31) - * Uses 32 bit internal representation for precision - *---------------------------------------------------------------------------*/ -Word32 L_Frac_sqrtQ31( /* o : Square root if input */ - const Word32 x /* i : Input */ -) -{ - Word32 log2_work; - Word16 log2_int, log2_frac; - - test(); - if (x > 0) - { - log2_int = norm_l(x); - log2_frac = Log2_norm_lc(L_shl(x, log2_int)); - - log2_work = L_msu((31+30)*65536L/2, 16384, log2_int); - log2_work = L_mac0(log2_work, log2_frac, 1); - - log2_frac = L_Extract_lc(log2_work, &log2_int); - - return Pow2(log2_int, log2_frac); - } - return 0; -} - -/*----------------------------------------------------------------------------------* - * Frac_sqrt - * - * Calculate square root from fractional values (Q15 -> Q15) - *----------------------------------------------------------------------------------*/ -Word16 Frac_sqrt( /* o : Square root if input */ - const Word16 x /* i : Input */ -) -{ - return round_fx(L_Frac_sqrtQ31(L_deposit_h(x))); -} - - -/*----------------------------------------------------------------------------------* - * i_mult2 - * - * Faster Integer Multiplication - *----------------------------------------------------------------------------------*/ - -Word16 i_mult2 (Word16 a, Word16 b) -{ - return extract_l(L_mult0(a, b)); -} - - - diff --git a/src/libs/libevs/basic_math/math_op.h b/src/libs/libevs/basic_math/math_op.h deleted file mode 100755 index 9a17485f..00000000 --- a/src/libs/libevs/basic_math/math_op.h +++ /dev/null @@ -1,48 +0,0 @@ -/*--------------------------------------------------------------------------* - * MATH_OP.H * - *--------------------------------------------------------------------------* - * Mathematical operations * - *--------------------------------------------------------------------------*/ -#include "oper_32b.h" -#include "log2.h" - -Word32 Isqrt( /* (o) Q31 : output value (range: 0<=val<1) */ - Word32 L_x /* (i) Q0 : input value (range: 0<=val<=7fffffff) */ -); -Word32 Isqrt_lc( - Word32 frac, /* (i/o) Q31: normalized value (1.0 < frac <= 0.5) */ - Word16 * exp /* (i/o) : exponent (value = frac x 2^exponent) */ -); - -Word32 Pow2( /* (o) Q0 : result (range: 0<=val<=0x7fffffff) */ - Word16 exponant, /* (i) Q0 : Integer part. (range: 0<=val<=30) */ - Word16 fraction /* (i) Q15 : Fractionnal part. (range: 0.0<=val<1.0) */ -); -Word32 Dot_product12( /* (o) Q31: normalized result (1 < val <= -1) */ - const Word16 x[], /* (i) 12bits: x vector */ - const Word16 y[], /* (i) 12bits: y vector */ - const Word16 lg, /* (i) : vector length */ - Word16 * exp /* (o) : exponent of result (0..+30) */ -); - -Word32 Energy_scale( /* (o) Q31: normalized result (1 < val <= -1) */ - const Word16 x[], /* (i) 12bits: x vector */ - const Word16 lg, /* (i) : vector length */ - Word16 expi, /* (i) : exponent of input */ - Word16 *exp /* (o) : exponent of result (0..+30) */ -); - -Word32 Sqrt_l(Word32 L_x, Word16 *exp); - -Word32 L_Frac_sqrtQ31( /* o : Square root if input */ - const Word32 x /* i : Input */ -); - -Word16 Frac_sqrt( /* o : Square root if input */ - const Word16 x /* i : Input */ -); - -Word16 i_mult2 (Word16 a, Word16 b); - -#include "math_32.h" - diff --git a/src/libs/libevs/basic_math/oper_32b.cpp b/src/libs/libevs/basic_math/oper_32b.cpp deleted file mode 100755 index 1904cdd8..00000000 --- a/src/libs/libevs/basic_math/oper_32b.cpp +++ /dev/null @@ -1,381 +0,0 @@ -/***************************************************************************** - * $Id: oper_32b.c 1094 2014-02-10 17:12:11Z jdr $ - * - * This file contains operations in double precision. * - * These operations are not standard double precision operations. * - * They are used where single precision is not enough but the full 32 bits * - * precision is not necessary. For example, the function Div_32() has a * - * 24 bits precision which is enough for our purposes. * - * * - * The double precision numbers use a special representation: * - * * - * L_32 = hi<<16 + lo<<1 * - * * - * L_32 is a 32 bit integer. * - * hi and lo are 16 bit signed integers. * - * As the low part also contains the sign, this allows fast multiplication. * - * * - * 0x8000 0000 <= L_32 <= 0x7fff fffe. * - * * - * We will use DPF (Double Precision Format) in this file to specify * - * this special format. * - ***************************************************************************** -*/ - -#include "stl.h" -#include "math_op.h" - -/***************************************************************************** - * * - * Function L_Extract() * - * * - * Extract from a 32 bit integer two 16 bit DPF. * - * * - * Arguments: * - * * - * L_32 : 32 bit integer. * - * 0x8000 0000 <= L_32 <= 0x7fff ffff. * - * hi : b16 to b31 of L_32 * - * lo : (L_32 - hi<<16)>>1 * - ***************************************************************************** -*/ - -void L_Extract (Word32 L_32, Word16 *hi, Word16 *lo) -{ - *hi = extract_h (L_32); - *lo = extract_l (L_msu (L_shr (L_32, 1), *hi, 16384)); - return; -} - -/***************************************************************************** - * * - * Function L_Extract_lc() * - * * - * Extract from a 32 bit integer two 16 bit DPF. * - * (lo is returned, store to memory is not accounted for) * - * * - * Arguments: * - * * - * L_32 : 32 bit integer. * - * 0x8000 0000 <= L_32 <= 0x7fff ffff. * - * hi : b16 to b31 of L_32 * - * lo : (L_32 - hi<<16)>>1 * - ***************************************************************************** -*/ - -Word16 L_Extract_lc (Word32 L_32, Word16 *hi) -{ - *hi = extract_h (L_32); - - return lshr(extract_l(L_32), 1); -} - -/***************************************************************************** - * * - * Function L_Comp() * - * * - * Compose from two 16 bit DPF a 32 bit integer. * - * * - * L_32 = hi<<16 + lo<<1 * - * * - * Arguments: * - * * - * hi msb * - * lo lsf (with sign) * - * * - * Return Value : * - * * - * 32 bit long signed integer (Word32) whose value falls in the * - * range : 0x8000 0000 <= L_32 <= 0x7fff fff0. * - * * - ***************************************************************************** -*/ - -Word32 L_Comp (Word16 hi, Word16 lo) -{ - Word32 L_32; - - L_32 = L_deposit_h (hi); - return (L_mac (L_32, lo, 1)); /* = hi<<16 + lo<<1 */ -} - -/***************************************************************************** - * Function Mpy_32() * - * * - * Multiply two 32 bit integers (DPF). The result is divided by 2**31 * - * * - * L_32 = (hi1*hi2)<<1 + ( (hi1*lo2)>>15 + (lo1*hi2)>>15 )<<1 * - * * - * This operation can also be viewed as the multiplication of two Q31 * - * number and the result is also in Q31. * - * * - * Arguments: * - * * - * hi1 hi part of first number * - * lo1 lo part of first number * - * hi2 hi part of second number * - * lo2 lo part of second number * - * * - ***************************************************************************** -*/ - -Word32 Mpy_32 (Word16 hi1, Word16 lo1, Word16 hi2, Word16 lo2) -{ - Word32 L_32; - - L_32 = L_mult (hi1, hi2); - L_32 = L_mac (L_32, mult (hi1, lo2), 1); - L_32 = L_mac (L_32, mult (lo1, hi2), 1); - - return (L_32); -} - -/***************************************************************************** - * Function Mac_32() * - * * - * Multiply two 32 bit integers (DPF). The result is divided by 2**31 * - * Adds a 32 bit integer (non DFP) * - * * - * L_32 = L_num + (hi1*hi2)<<1 + ( (hi1*lo2)>>15 + (lo1*hi2)>>15 )<<1 * - * * - * This operation can also be viewed as the multiplication of two Q31 * - * number and the result is also in Q31. * - * * - * Arguments: * - * * - * hi1 hi part of first number * - * lo1 lo part of first number * - * hi2 hi part of second number * - * lo2 lo part of second number * - * * - ***************************************************************************** -*/ - -Word32 Mac_32 (Word32 L_num, Word16 hi1, Word16 lo1, Word16 hi2, Word16 lo2) -{ - Word32 L_32; - - L_32 = L_mac (L_num, hi1, hi2); - L_32 = L_mac (L_32, mult (hi1, lo2), 1); - L_32 = L_mac (L_32, mult (lo1, hi2), 1); - - return (L_32); -} - -/***************************************************************************** - * Function Sqr_32() * - * * - * Square one 32 bit integer (DPF). The result is divided by 2**31 * - * * - * L_32 = (hi*hi)<<1 + ( (hi*lo)>>15 *2)<<1 * - * * - * This operation can also be viewed as the square of one Q31 * - * number and the result is also in Q31. * - * * - * Arguments: * - * * - * hi1 hi part of first number * - * lo1 lo part of first number * - * hi2 hi part of second number * - * lo2 lo part of second number * - * * - ***************************************************************************** -*/ - -Word32 Sqr_32 (Word16 hi, Word16 lo) -{ - Word32 L_32; - - L_32 = L_mult (hi, hi); - L_32 = L_mac (L_32, mult (hi, lo), 2); - - return (L_32); -} - -/***************************************************************************** - * Function Sad_32() * - * * - * Square one 32 bit integer (DPF). The result is divided by 2**31 * - * Adds a 32 bit integer (non DFP) * - * * - * L_32 = L_num + (hi*hi)<<1 + ( (hi*lo)>>15 *2)<<1 * - * * - * This operation can also be viewed as the square of one Q31 * - * number and the result is also in Q31. * - * * - * Arguments: * - * * - * hi1 hi part of first number * - * lo1 lo part of first number * - * hi2 hi part of second number * - * lo2 lo part of second number * - * * - ***************************************************************************** -*/ - -Word32 Sad_32 (Word32 L_num, Word16 hi, Word16 lo) -{ - Word32 L_32; - - L_32 = L_mac (L_num, hi, hi); - L_32 = L_mac (L_32, mult (hi, lo), 2); - - return (L_32); -} - -/***************************************************************************** - * Function Mpy_32_16() * - * * - * Multiply a 16 bit integer by a 32 bit (DPF). The result is divided * - * by 2**15 * - * * - * * - * L_32 = (hi1*lo2)<<1 + ((lo1*lo2)>>15)<<1 * - * * - * Arguments: * - * * - * hi hi part of 32 bit number. * - * lo lo part of 32 bit number. * - * n 16 bit number. * - * * - ***************************************************************************** -*/ - -Word32 Mpy_32_16 (Word16 hi, Word16 lo, Word16 n) -{ - Word32 L_32; - - L_32 = L_mult (hi, n); - L_32 = L_mac (L_32, mult (lo, n), 1); - - return (L_32); -} - -/***************************************************************************** - * Function Mac_32_16() * - * * - * Multiply a 16 bit integer by a 32 bit (DPF). The result is divided * - * by 2**15 * - * Adds a 32 bit integer (non DFP) * - * * - * * - * L_32 = L_num + (hi1*lo2)<<1 + ((lo1*lo2)>>15)<<1 * - * * - * Arguments: * - * * - * L_num 32 bit long signed integer (Word32) * - * hi hi part of 32 bit number. * - * lo lo part of 32 bit number. * - * n 16 bit number. * - * * - ***************************************************************************** -*/ - -Word32 Mac_32_16 (Word32 L_num, Word16 hi, Word16 lo, Word16 n) -{ - Word32 L_32; - - L_32 = L_mac (L_num, hi, n); - L_32 = L_mac (L_32, mult (lo, n), 1); - - return (L_32); -} - -/***************************************************************************** - * Function Msu_32_16() * - * * - * Substract a 32 bit integer (non DFP) * - * Multiply a 16 bit integer by a 32 bit (DPF). The result is divided * - * by 2**15 * - * * - * * - * L_32 = L_num - (hi1*lo2)<<1 + ((lo1*lo2)>>15)<<1 * - * * - * Arguments: * - * * - * L_num 32 bit long signed integer (Word32) * - * hi hi part of 32 bit number. * - * lo lo part of 32 bit number. * - * n 16 bit number. * - * * - ***************************************************************************** -*/ - -Word32 Msu_32_16 (Word32 L_num, Word16 hi, Word16 lo, Word16 n) -{ - Word32 L_32; - - L_32 = L_msu (L_num, hi, n); - L_32 = L_msu (L_32, mult (lo, n), 1); - - return (L_32); -} - -/***************************************************************************** - * * - * Function Name : Div_32 * - * * - * Purpose : * - * Fractional integer division of two 32 bit numbers. * - * L_num / L_denom. * - * L_num and L_denom must be positive and L_num < L_denom. * - * L_denom = denom_hi<<16 + denom_lo<<1 * - * denom_hi is a normalize number. * - * * - * Inputs : * - * * - * L_num * - * 32 bit long signed integer (Word32) whose value falls in the * - * range : 0x0000 0000 < L_num < L_denom * - * * - * L_denom = denom_hi<<16 + denom_lo<<1 (DPF) * - * * - * denom_hi * - * 16 bit positive normalized integer whose value falls in the * - * range : 0x4000 < hi < 0x7fff * - * denom_lo * - * 16 bit positive integer whose value falls in the * - * range : 0 < lo < 0x7fff * - * * - * Return Value : * - * * - * L_div * - * 32 bit long signed integer (Word32) whose value falls in the * - * range : 0x0000 0000 <= L_div <= 0x7fff ffff. * - * * - * Algorithm: * - * * - * - find = 1/L_denom. * - * First approximation: approx = 1 / denom_hi * - * 1/L_denom = approx * (2.0 - L_denom * approx ) * - * * - * - result = L_num * (1/L_denom) * - ***************************************************************************** -*/ - -Word32 Div_32 (Word32 L_num, Word16 denom_hi, Word16 denom_lo) -{ - Word16 approx, hi, lo, n_hi, n_lo; - Word32 L_32; - - /* First approximation: 1 / L_denom = 1/denom_hi */ - - approx = div_s ((Word16) 0x3fff, denom_hi); - - /* 1/L_denom = approx * (2.0 - L_denom * approx) */ - - L_32 = Msu_32_16 ((Word32) 0x7fffffffL, denom_hi, denom_lo, approx); - - lo = L_Extract_lc (L_32, &hi); - L_32 = Mpy_32_16 (hi, lo, approx); - - /* L_num * (1/L_denom) */ - - lo = L_Extract_lc (L_32, &hi); - n_lo = L_Extract_lc (L_num, &n_hi); - L_32 = Mpy_32 (n_hi, n_lo, hi, lo); - L_32 = L_shl (L_32, 2); - - return (L_32); -} - diff --git a/src/libs/libevs/basic_math/oper_32b.h b/src/libs/libevs/basic_math/oper_32b.h deleted file mode 100755 index 70d1c59d..00000000 --- a/src/libs/libevs/basic_math/oper_32b.h +++ /dev/null @@ -1,18 +0,0 @@ -/* Double precision operations */ -/* $Id: oper_32b.h 1094 2014-02-10 17:12:11Z jdr $ */ -#ifndef _OPER_32b_H -#define _OPER_32b_H - -void L_Extract (Word32 L_32, Word16 *hi, Word16 *lo); -Word16 L_Extract_lc (Word32 L_32, Word16 *hi); -Word32 L_Comp (Word16 hi, Word16 lo); -Word32 Mpy_32 (Word16 hi1, Word16 lo1, Word16 hi2, Word16 lo2); -Word32 Mac_32 (Word32 L_num, Word16 hi1, Word16 lo1, Word16 hi2, Word16 lo2); -Word32 Sqr_32 (Word16 hi, Word16 lo); -Word32 Sad_32 (Word32 L_num, Word16 hi, Word16 lo); -Word32 Mpy_32_16 (Word16 hi, Word16 lo, Word16 n); -Word32 Mac_32_16 (Word32 L_num, Word16 hi, Word16 lo, Word16 n); -Word32 Msu_32_16 (Word32 L_num, Word16 hi, Word16 lo, Word16 n); -Word32 Div_32 (Word32 L_num, Word16 denom_hi, Word16 denom_lo); - -#endif diff --git a/src/libs/libevs/basic_math/rom_basic_math.cpp b/src/libs/libevs/basic_math/rom_basic_math.cpp deleted file mode 100755 index 8c813782..00000000 --- a/src/libs/libevs/basic_math/rom_basic_math.cpp +++ /dev/null @@ -1,91 +0,0 @@ -#include "options.h" /* Compilation switches */ -#include "cnst_fx.h" /* Decoder static structure */ -#include "stl.h" - -/* math_op.c */ -const Word32 L_table_isqrt[48] = -{ - 2147418112L, 2083389440L, 2024669184L, 1970667520L, - 1920794624L, 1874460672L, 1831403520L, 1791098880L, - 1753415680L, 1717960704L, 1684602880L, 1653145600L, - 1623326720L, 1595080704L, 1568276480L, 1542782976L, - 1518469120L, 1495334912L, 1473183744L, 1451950080L, - 1431633920L, 1412169728L, 1393491968L, 1375469568L, - 1358168064L, 1341521920L, 1325465600L, 1309933568L, - 1294991360L, 1280507904L, 1266548736L, 1252982784L, - 1239875584L, 1227161600L, 1214775296L, 1202847744L, - 1191182336L, 1179910144L, 1168965632L, 1158283264L, - 1147863040L, 1137770496L, 1127940096L, 1118306304L, - 1108934656L, 1099825152L, 1090912256L, 1082261504L -}; - -/* table of table_isqrt[i] - table_isqrt[i+1] */ -const Word16 table_isqrt_diff[48] = -{ - 977, 896, 824, 761, 707, 657, 615, 575, - 541, 509, 480, 455, 431, 409, 389, 371, - 353, 338, 324, 310, 297, 285, 275, 264, - 254, 245, 237, 228, 221, 213, 207, 200, - 194, 189, 182, 178, 172, 167, 163, 159, - 154, 150, 147, 143, 139, 136, 132, 130 -}; - -const Word16 shift_Isqrt_lc[] = {9,10}; - -const Word16 table_pow2[32] = -{ - 16384, 16743, 17109, 17484, 17867, 18258, 18658, 19066, 19484, 19911, - 20347, 20792, 21247, 21713, 22188, 22674, 23170, 23678, 24196, 24726, - 25268, 25821, 26386, 26964, 27554, 28158, 28774, 29405, 30048, 30706, - 31379, 32066 -}; - -/* table of table_pow2[i+1] - table_pow2[i] */ -const Word16 table_pow2_diff_x32[32] = -{ - 11488, 11712, 12000, 12256, 12512, 12800, 13056, 13376, 13664, 13952, - 14240, 14560, 14912, 15200, 15552, 15872, 16256, 16576, 16960, 17344, - 17696, 18080, 18496, 18880, 19328, 19712, 20192, 20576, 21056, 21536, - 21984, 22432 -}; - -const Word16 sqrt_table[49] = -{ - 16384, 16888, 17378, 17854, 18318, 18770, 19212, - 19644, 20066, 20480, 20886, 21283, 21674, 22058, - 22435, 22806, 23170, 23530, 23884, 24232, 24576, - 24915, 25249, 25580, 25905, 26227, 26545, 26859, - 27170, 27477, 27780, 28081, 28378, 28672, 28963, - 29251, 29537, 29819, 30099, 30377, 30652, 30924, - 31194, 31462, 31727, 31991, 32252, 32511, 32767 -}; - -/* log2.c */ -const Word32 L_table_Log2_norm_lc[32] = -{ - -32768L, 95322112L, 187793408L, 277577728L, - 364871680L, 449740800L, 532381696L, 612859904L, - 691306496L, 767787008L, 842432512L, 915308544L, - 986546176L, 1056210944L, 1124302848L, 1190887424L, - 1256095744L, 1319993344L, 1382580224L, 1443921920L, - 1504083968L, 1563131904L, 1621000192L, 1677885440L, - 1733722112L, 1788510208L, 1842380800L, 1895399424L, - 1947435008L, 1998618624L, 2049015808L, 2098626560L -}; - -const Word16 table_diff_Log2_norm_lc[32] = -{ - 1455, 1411, 1370, 1332, 1295, 1261, 1228, 1197, - 1167, 1139, 1112, 1087, 1063, 1039, 1016, 995, - 975, 955, 936, 918, 901, 883, 868, 852, - 836, 822, 809, 794, 781, 769, 757, 744 -}; - -const Word16 log2_tab[33]={ - 0x7800, 0x782D, 0x785A, 0x7884, 0x78AE, 0x78D6, 0x78FE, 0x7924, - 0x794A, 0x796E, 0x7992, 0x79B4, 0x79D6, 0x79F8, 0x7A18, 0x7A38, - 0x7A57, 0x7A75, 0x7A93, 0x7AB1, 0x7ACD, 0x7AE9, 0x7B05, 0x7B20, - 0x7B3B, 0x7B55, 0x7B6F, 0x7B88, 0x7BA1, 0x7BB9, 0x7BD1, 0x7BE9, - 0x7C00 -}; - diff --git a/src/libs/libevs/basic_math/rom_basic_math.h b/src/libs/libevs/basic_math/rom_basic_math.h deleted file mode 100755 index f39ea847..00000000 --- a/src/libs/libevs/basic_math/rom_basic_math.h +++ /dev/null @@ -1,26 +0,0 @@ -#include "options.h" /* Compilation switches */ -#include "cnst_fx.h" /* Decoder static structure */ -#include "stl.h" - - -/* math_op.c */ -extern const Word32 L_table_isqrt[48]; - -/* table of table_isqrt[i] - table_isqrt[i+1] */ -extern const Word16 table_isqrt_diff[48]; - -extern const Word16 shift_Isqrt_lc[]; - -extern const Word16 table_pow2[32]; - -/* table of table_pow2[i+1] - table_pow2[i] */ -extern const Word16 table_pow2_diff_x32[32]; - -extern const Word16 sqrt_table[49]; - -/* log2.c */ -extern const Word32 L_table_Log2_norm_lc[32]; - -extern const Word16 table_diff_Log2_norm_lc[32]; - -extern const Word16 log2_tab[33]; diff --git a/src/libs/libevs/basic_op/basop.rme b/src/libs/libevs/basic_op/basop.rme deleted file mode 100755 index 8ae3dc46..00000000 --- a/src/libs/libevs/basic_op/basop.rme +++ /dev/null @@ -1,51 +0,0 @@ - - Read-me for ITU-T/UGST Basic Operator Module - (12.November.2004) - - ============================================================= - COPYRIGHT NOTE: This source code, and all of its derivations, - is subject to the "ITU-T General Public License". Please have - it read in the distribution disk, or in the ITU-T - Recommendation G.191 on "SOFTWARE TOOLS FOR SPEECH AND AUDIO - CODING STANDARDS". - ============================================================= - - -The ITU-T/UGST Basic Operator module contails the following files: - - -General: -~~~~~~~~ - basop.rme: ....... Read-me file for Basic Operator module (this file) - - -C code: ('model' directory) -~~~~~~~~~~~~~~~~~~~~~~~~~~~ - basop32.c: ....... 16/32 bit basic operators - basop32.h: ....... Prototypes for basop32.c - count.c: ......... Functions for WMOPS computation - count.h: ......... Prototypes for count.c - typedef.h: ....... Data type definitions - typedefs.h: ...... New data type definitions - move.h: .......... Move & miscellaneous legacy operators - control.c: ....... Control operator internal variable decl. - control.h: ....... Control operators - enh1632.c: ....... Enhanced 16/32 bit basic operators - enh1632.h: ....... Prototypes for enh1632.c - enh40.c: ......... 40 bit basic operators - enh40.h: ......... Prototypes for enh40.c - patch.h: ......... Backward compatibility for operator names - stl.h: ........... Main header file - -Demos: -~~~~~~ -Demo programs are not available for this module. - - -Makefiles -~~~~~~~~~ -Make files are not available for this module. - - --- - diff --git a/src/libs/libevs/basic_op/control.h b/src/libs/libevs/basic_op/control.h deleted file mode 100755 index 6420cff0..00000000 --- a/src/libs/libevs/basic_op/control.h +++ /dev/null @@ -1,307 +0,0 @@ -/* - =========================================================================== - File: CONTROL.H v.2.3 - 30.Nov.2009 - =========================================================================== - - ITU-T STL BASIC OPERATORS - - CONTROL FLOW OPERATORS - - History: - 07 Nov 04 v2.0 Incorporation of new 32-bit / 40-bit / control - operators for the ITU-T Standard Tool Library as - described in Geneva, 20-30 January 2004 WP 3/16 Q10/16 - TD 11 document and subsequent discussions on the - wp3audio@yahoogroups.com email reflector. - March 06 v2.1 Changed to improve portability. - - ============================================================================ -*/ - - -#ifndef _CONTROL_H -#define _CONTROL_H - -#include "stl.h" - -/***************************************************************************** - * - * Constants and Globals - * - *****************************************************************************/ -#if (WMOPS) -extern BASIC_OP multiCounter[MAXCOUNTERS]; -extern int currCounter; - - /* Technical note : - * The following 3 variables are only used for correct complexity - * evaluation of the following structure : - * IF{ - * ... - * } ELSE IF { - * ... - * } ELSE IF { - * ... - * } - * ... - * } ELSE { - * ... - * } - */ -extern int funcId_where_last_call_to_else_occurred; -extern long funcid_total_wmops_at_last_call_to_else; -extern int call_occurred; -#endif /* if WMOPS */ - - -/***************************************************************************** - * - * Function Macros - * - *****************************************************************************/ - -/***************************************************************************** - * - * Function Name : FOR - * - * Purpose : - * - * The macro FOR should be used instead of the 'for' C statement. - * The complexity is independent of the number of loop iterations that are - * performed. - * - * Complexity weight : 3 (regardless of number of iterations). - * - *****************************************************************************/ -#if !(WMOPS) -#define FOR( a) for( a) - -#else /* if !(WMOPS) */ -#define FOR( a) if( incrFor(), 0); else for( a) - -static __inline void incrFor( void) { - multiCounter[currCounter].For++; -} -#endif /* if !(WMOPS) */ - - -/***************************************************************************** - * - * Function Name : WHILE - * - * Purpose : - * - * The macro WHILE should be used instead of the 'while' C statement. - * The complexity is proportional to the number of loop iterations that - * are performed. - * - * Complexity weight : 4 x 'number of loop iterations'. - * - *****************************************************************************/ -#if !(WMOPS) -#define WHILE( a) while( a) - -#else /* if !(WMOPS) */ -#define WHILE( a) while( incrWhile(), a) - -static __inline void incrWhile( void) { - multiCounter[currCounter].While++; -} -#endif /* if !(WMOPS) */ - - -/***************************************************************************** - * - * Function Name : DO - * - * Purpose : - * - * The macro DO should be used instead of the 'do' C statement. - * - * Complexity weight : 0 (complexity counted by WHILE macro). - * - *****************************************************************************/ -#if !(WMOPS) -#define DO do - -#else /* if !(WMOPS) */ -#define DO do - -#endif /* if !(WMOPS) */ - - -/***************************************************************************** - * - * Function Name : IF - * - * Purpose : - * - * The macro IF should : - * - * - not be used when : - * - the 'if' structure does not have any 'else if' nor 'else' statement - * - and it conditions only one DSP basic operations. - * - * - be used instead of the 'if' C statement in every other case : - * - when there is an 'else' or 'else if' statement, - * - or when the 'if' conditions several DSP basic operations, - * - or when the 'if' conditions a function call. - * - * Complexity weight : 4 - * - *****************************************************************************/ -#if !(WMOPS) -#define IF( a) if( a) - -#else /* if !(WMOPS) */ -#define IF( a) if( incrIf(), a) - -static __inline void incrIf( void) { - /* Technical note : - * If the "IF" operator comes just after an "ELSE", its counter - * must not be incremented. - */ - if ( (currCounter != funcId_where_last_call_to_else_occurred) - || (TotalWeightedOperation() != funcid_total_wmops_at_last_call_to_else) - || (call_occurred == 1)) - multiCounter[currCounter].If++; - - call_occurred = 0; - funcId_where_last_call_to_else_occurred = MAXCOUNTERS; -} -#endif /* if !(WMOPS) */ - - -/***************************************************************************** - * - * Function Name : ELSE - * - * Purpose : - * - * The macro ELSE should be used instead of the 'else' C statement. - * - * Complexity weight : 4 - * - *****************************************************************************/ -#if !(WMOPS) -#define ELSE else - -#else /* if !(WMOPS) */ -#define ELSE else if( incrElse(), 0) ; else - -static __inline void incrElse( void) { - multiCounter[currCounter].If++; - - /* We keep track of the funcId of the last function - * which used ELSE {...} structure. - */ - funcId_where_last_call_to_else_occurred = currCounter; - - /* We keep track of the number of WMOPS of this funcId - * when the ELSE macro was called. - */ - funcid_total_wmops_at_last_call_to_else = TotalWeightedOperation(); - - /* call_occurred is set to 0, in order to count the next IF (if necessary) - */ - call_occurred=0; -} -#endif /* if !(WMOPS) */ - - -/***************************************************************************** - * - * Function Name : SWITCH - * - * Purpose : - * - * The macro SWITCH should be used instead of the 'switch' C statement. - * - * Complexity weight : 8 - * - *****************************************************************************/ -#if !(WMOPS) -#define SWITCH( a) switch( a) - -#else /* if !(WMOPS) */ -#define SWITCH( a) switch( incrSwitch(), a) - -static __inline void incrSwitch( void) { - multiCounter[currCounter].Switch++; -} -#endif /* if !(WMOPS) */ - - -/***************************************************************************** - * - * Function Name : CONTINUE - * - * Purpose : - * - * The macro CONTINUE should be used instead of the 'continue' C statement. - * - * Complexity weight : 4 - * - *****************************************************************************/ -#if !(WMOPS) -#define CONTINUE continue - -#else /* if !(WMOPS) */ -#define CONTINUE if( incrContinue(), 0); else continue - -static __inline void incrContinue( void) { - multiCounter[currCounter].Continue++; -} -#endif /* if !(WMOPS) */ - - -/***************************************************************************** - * - * Function Name : BREAK - * - * Purpose : - * - * The macro BREAK should be used instead of the 'break' C statement. - * - * Complexity weight : 4 - * - *****************************************************************************/ -#if !(WMOPS) -#define BREAK break - -#else /* if !(WMOPS) */ -#define BREAK if( incrBreak(), 0) break; else break - -static __inline void incrBreak( void) { - multiCounter[currCounter].Break++; -} -#endif /* if !(WMOPS) */ - - -/***************************************************************************** - * - * Function Name : GOTO - * - * Purpose : - * - * The macro GOTO should be used instead of the 'goto' C statement. - * - * Complexity weight : 4 - * - *****************************************************************************/ -#if !(WMOPS) -#define GOTO goto - -#else /* if !(WMOPS) */ -#define GOTO if( incrGoto(), 0); else goto - -static __inline void incrGoto( void) { - multiCounter[currCounter].Goto++; -} -#endif /* if !(WMOPS) */ - - -#endif /* _CONTROL_H */ - - -/* end of file */ diff --git a/src/libs/libevs/basic_op/count.cpp b/src/libs/libevs/basic_op/count.cpp deleted file mode 100755 index 26ba67a5..00000000 --- a/src/libs/libevs/basic_op/count.cpp +++ /dev/null @@ -1,624 +0,0 @@ -/* - =========================================================================== - File: COUNT.C v.2.3 - 30.Nov.2009 - =========================================================================== - - ITU-T STL BASIC OPERATORS - - COMPLEXITY EVALUATION FUNCTIONS - - History: - 03 Nov 04 v2.0 Incorporation of new 32-bit / 40-bit / control - operators for the ITU-T Standard Tool Library as - described in Geneva, 20-30 January 2004 WP 3/16 Q10/16 - TD 11 document and subsequent discussions on the - wp3audio@yahoogroups.com email reflector. - norm_s() weight reduced from 15 to 1. - norm_l() weight reduced from 30 to 1. - L_abs() weight reduced from 2 to 1. - L_add() weight reduced from 2 to 1. - L_negate() weight reduced from 2 to 1. - L_shl() weight reduced from 2 to 1. - L_shr() weight reduced from 2 to 1. - L_sub() weight reduced from 2 to 1. - mac_r() weight reduced from 2 to 1. - msu_r() weight reduced from 2 to 1. - mult_r() weight reduced from 2 to 1. - L_deposit_h() weight reduced from 2 to 1. - L_deposit_l() weight reduced from 2 to 1. - March 06 v2.1 Changed to improve portability. - Dec 06 v2.2 Changed to specify frame rate using setFrameRate() - Adding WMOPS_output_avg() for global average computation - L_mls() weight of 5. - div_l() weight of 32. - i_mult() weight of 3. - ============================================================================ -*/ - - -/***************************************************************************** - * - * This file contains functions for the automatic complexity calculation - * - *****************************************************************************/ - - -#include -#include -#include -#include "stl.h" - -#ifdef WMOPS -static double frameRate = FRAME_RATE; /* default value : 10 ms */ -#endif /* ifdef WMOPS */ - -#ifdef WMOPS -/* Global counter variable for calculation of complexity weight */ -BASIC_OP multiCounter[MAXCOUNTERS]; -int currCounter=0; /* Zero equals global counter */ -#endif /* ifdef WMOPS */ - -#ifdef WMOPS -void setFrameRate(int samplingFreq, int frameLength) -{ - if(frameLength > 0) - { - frameRate = samplingFreq / 1000000.0 / frameLength; - } - return; -} - -#endif /* ifdef WMOPS */ - -#ifdef WMOPS -/* - * Below list is used for displaying the code profiling information in - * the file which name is defined by CODE_PROFILE_FILENAME. - * For further details see generic_WMOPS_output() function. - * Attention, the ordering in this table must be kept in synchronisation - * with the structure definition BASIC_OP. - */ -char* BasicOperationList[] = -{ - "add", "sub", "abs_s", "shl", "shr", - "extract_h", "extract_l", "mult", "L_mult", "negate", - "round", "L_mac", "L_msu", "L_macNs", "L_msuNs", - "L_add", "L_sub", "L_add_c", "L_sub_c", "L_negate", - "L_shl", "L_shr", "mult_r", "shr_r", "mac_r", - - "msu_r", "L_deposit_h", "L_deposit_l", "L_shr_r", "L_abs", - "L_sat", "norm_s", "div_s", "norm_l", "move16", - "move32", "Logic16", "Logic32", "Test", "s_max", - "s_min", "L_max", "L_min", "L40_max", "L40_min", - "shl_r", "L_shl_r", "L40_shr_r", "L40_shl_r", "norm_L40", - - "L40_shl", "L40_shr", "L40_negate", "L40_add", "L40_sub", - "L40_abs", "L40_mult", "L40_mac", "mac_r40", - "L40_msu", "msu_r40", "Mpy_32_16_ss", "Mpy_32_32_ss", "L_mult0", - "L_mac0", "L_msu0", "lshl", "lshr", "L_lshl", - "L_lshr", "L40_lshl", "L40_lshr", "s_and", "s_or", - - "s_xor", "L_and", "L_or", "L_xor", "rotl", - "rotr", "L_rotl", "L_rotr", "L40_set", "L40_deposit_h", - "L40_deposit_l", "L40_deposit32", "Extract40_H", "Extract40_L", "L_Extract40", - "L40_round", "L_saturate40", "round40", "IF", "GOTO", - "BREAK", "SWITCH", "FOR", "WHILE", "CONTINUE" - - , "L_mls", "div_l", "i_mult" -}; -#endif /* ifdef WMOPS */ - - -#ifdef WMOPS -const BASIC_OP op_weight = -{ - 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, - 1, 1, 2, 2, 1, - 1, 1, 1, 3, 1, - - 1, 1, 1, 3, 1, - 4, 1, 18, 1, 1, - 2, 1, 2, 2, 1, - 1, 1, 1, 1, 1, - 3, 3, 3, 3, 1, - - 1, 1, 1, 1, 1, - 1, 1, 1, 2, - 1, 2, 2, 4, 1, - 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, - - 1, 1, 1, 1, 3, - 3, 3, 3, 3, 1, - 1, 1, 1, 1, 1, - 1, 1, 1, 4, 4, - 4, 8, 3, 4, 4 - - , 5, 32, 3 -}; -#endif /* ifdef WMOPS */ - - -Word32 TotalWeightedOperation (void); -Word32 DeltaWeightedOperation (void); - - -#ifdef WMOPS -/* Counters for separating counting for different objects */ - - -static int maxCounter=0; -static char* objectName[MAXCOUNTERS+1]; - -static Word16 fwc_corr[MAXCOUNTERS+1]; -static long int nbTimeObjectIsCalled[MAXCOUNTERS+1]; - -#define NbFuncMax 1024 - -static Word16 funcid[MAXCOUNTERS], nbframe[MAXCOUNTERS]; -static Word32 glob_wc[MAXCOUNTERS], wc[MAXCOUNTERS][NbFuncMax]; -static float total_wmops[MAXCOUNTERS]; - -static Word32 LastWOper[MAXCOUNTERS]; -#endif /* ifdef WMOPS */ - - -#ifdef WMOPS -static char* my_strdup(const char *s) { -/* - * duplicates UNIX function strdup() which is not ANSI standard: - * -- malloc() memory area big enough to hold the string s - * -- copy string into new area - * -- return pointer to new area - * - * returns NULL if either s==NULL or malloc() fails - */ - char *dup; - - if (s == NULL) - return NULL; - - /* allocate memory for copy of ID string (including string terminator) */ - /* NOTE: the ID strings will never be deallocated because there is no - way to "destroy" a counter that is not longer needed */ - if ((dup = (char *) malloc(strlen(s)+1)) == NULL) - return NULL; - - return strcpy(dup, s); -} -#endif /* ifdef WMOPS */ - - -int getCounterId( char *objectNameArg) { -#if WMOPS - if(maxCounter>=MAXCOUNTERS-1) return 0; - objectName[++maxCounter]=my_strdup(objectNameArg); - return maxCounter; - -#else /* ifdef WMOPS */ - (void)objectNameArg; - return 0; /* Dummy */ - -#endif /* ifdef WMOPS */ -} - - -#if WMOPS -int readCounterId() { - return currCounter; -} -#endif /* ifdef WMOPS */ - - -#ifdef WMOPS -char * readCounterIdName() { - return objectName[currCounter]; -} -#endif /* ifdef WMOPS */ - -void setCounter( int counterId) { -#if WMOPS - if( (counterId > maxCounter) - || (counterId < 0)) { - currCounter=0; - return; - } - currCounter=counterId; - call_occurred = 1; -#else - (void)counterId; -#endif /* ifdef WMOPS */ -} - - -void incrementNbTimeObjectIsCalled( int counterId) { -#if WMOPS - if( (counterId > maxCounter) - || (counterId < 0)) { - nbTimeObjectIsCalled[0]++; - return; - } - nbTimeObjectIsCalled[counterId]++; -#else - (void)counterId; -#endif /* ifdef WMOPS */ -} - - -#if WMOPS -static Word32 WMOPS_frameStat() { -/* calculate the WMOPS seen so far and update the global - per-frame maximum (glob_wc) - */ - Word32 tot; - - tot = TotalWeightedOperation (); - if (tot > glob_wc[currCounter]) - glob_wc[currCounter] = tot; - - /* check if fwc() was forgotten at end of last frame */ - if (tot > LastWOper[currCounter]) { - if (!fwc_corr[currCounter]) { - fprintf(stderr, - "count: operations counted after last fwc() for '%s'; " - "-> fwc() called\n", - objectName[currCounter]?objectName[currCounter]:""); - } - fwc(); - } - - return tot; -} -#endif /* ifdef WMOPS */ - - -#ifdef WMOPS -static void WMOPS_clearMultiCounter() { - Word16 i; - - Word32 *ptr = (Word32 *) &multiCounter[currCounter]; - for( i = 0; i < (Word16)(sizeof (multiCounter[currCounter])/ sizeof (Word32)); i++) { - *ptr++ = 0; - } -} -#endif /* ifdef WMOPS */ - - -void ClearNbTimeObjectsAreCalled() { -#if WMOPS - Word16 i; - - for (i = 0; i < (Word16)(sizeof (multiCounter[currCounter])/ sizeof (Word32)); i++) { - nbTimeObjectIsCalled[i] = 0; - } -#endif /* ifdef WMOPS */ -} - -Word32 TotalWeightedOperation () { -#if WMOPS - Word16 i; - Word32 tot, *ptr, *ptr2; - - tot = 0; - ptr = (Word32 *) &multiCounter[currCounter]; - ptr2 = (Word32 *) &op_weight; - for (i = 0; i < (Word16)(sizeof (multiCounter[currCounter])/ sizeof (Word32)); i++) { - tot += ((*ptr++) * (*ptr2++)); - } - - return ((Word32) tot); - -#else /* ifdef WMOPS */ - return 0; /* Dummy */ - -#endif /* ifdef WMOPS */ - -} - -Word32 DeltaWeightedOperation () { -#if WMOPS - Word32 NewWOper, delta; - - NewWOper = TotalWeightedOperation (); - delta = NewWOper - LastWOper[currCounter]; - LastWOper[currCounter] = NewWOper; - return (delta); - -#else /* ifdef WMOPS */ - return 0; /* Dummy */ - -#endif /* ifdef WMOPS */ -} - - -void Init_WMOPS_counter (void) { -#if WMOPS - Word16 i; - - /* reset function weight operation counter variable */ - - for (i = 0; i < NbFuncMax; i++) - wc[currCounter][i] = (Word32) 0; - glob_wc[currCounter] = 0; - nbframe[currCounter] = 0; - total_wmops[currCounter] = 0.0; - - /* initially clear all counters */ - WMOPS_clearMultiCounter(); - LastWOper[currCounter] = 0; - funcid[currCounter] = 0; - - /* Following line is useful for incrIf(), see control.h */ - call_occurred = 1; - funcId_where_last_call_to_else_occurred=MAXCOUNTERS; -#endif /* ifdef WMOPS */ -} - - -void Reset_WMOPS_counter (void) { -#if WMOPS - Word32 tot = WMOPS_frameStat(); - - /* increase the frame counter --> a frame is counted WHEN IT BEGINS */ - nbframe[currCounter]++; - /* add wmops used in last frame to count, then reset counter */ - /* (in first frame, this is a no-op */ - total_wmops[currCounter] += (float)( tot * frameRate ); - - /* clear counter before new frame starts */ - WMOPS_clearMultiCounter(); - LastWOper[currCounter] = 0; - funcid[currCounter] = 0; /* new frame, set function id to zero */ -#endif /* ifdef WMOPS */ -} - - -Word32 fwc (void) { -/* function worst case */ -#if WMOPS - Word32 tot; - - tot = DeltaWeightedOperation (); - if (tot > wc[currCounter][funcid[currCounter]]) - wc[currCounter][funcid[currCounter]] = tot; - - funcid[currCounter]++; - return (tot); - -#else /* ifdef WMOPS */ - return 0; /* Dummy */ - -#endif /* ifdef WMOPS */ -} - -void WMOPS_output (Word16 dtx_mode) { -#if WMOPS - Word16 i; - Word32 tot, tot_wm, tot_wc; - - /* get operations since last reset (or init), - but do not update the counters (except the glob_wc[] maximum) - so output CAN be called in each frame without problems. - The frame counter is NOT updated! - */ - tot = WMOPS_frameStat(); - tot_wm = (Word32)(total_wmops[currCounter] + ((float) tot) * frameRate); - - fprintf (stdout, "%10s:WMOPS=%.3f", - objectName[currCounter]?objectName[currCounter]:"", - ((float) tot) * frameRate); - - if (nbframe[currCounter] != 0) - { - fprintf (stdout, " Average=%.3f", - tot_wm / (float) nbframe[currCounter]); - } - fprintf (stdout, " WorstCase=%.3f", - ((float) glob_wc[currCounter]) * frameRate); - - /* Worst worst case printed only when not in DTX mode */ - if (dtx_mode == 0) - { - tot_wc = 0L; - for (i = 0; i < funcid[currCounter]; i++) - tot_wc += wc[currCounter][i]; - fprintf (stdout, " WorstWC=%.3f", ((float) tot_wc) * frameRate); - } - fprintf (stdout, " (%d frames)\n", nbframe[currCounter]); - -#else - (void)dtx_mode; -#endif /* ifdef WMOPS */ -} - - -void WMOPS_output_avg (Word16 dtx_mode, Word32 *tot_wm, Word16 *num_frames) { -#if WMOPS - Word16 i; - Word32 tot, tot_wc; - - /* get operations since last reset (or init), - but do not update the counters (except the glob_wc[] maximum) - so output CAN be called in each frame without problems. - The frame counter is NOT updated! - */ - tot = WMOPS_frameStat(); - *tot_wm = (Word32)(total_wmops[currCounter] + ((float) tot) * frameRate); - *num_frames = nbframe[currCounter]; - - fprintf (stdout, "%10s:WMOPS=%.3f", - objectName[currCounter]?objectName[currCounter]:"", - ((float) tot) * frameRate); - - if (nbframe[currCounter] != 0) - { - fprintf (stdout, " Average=%.3f", - *tot_wm / (float) nbframe[currCounter]); - } - fprintf (stdout, " WorstCase=%.3f", - ((float) glob_wc[currCounter]) * frameRate); - - /* Worst worst case printed only when not in DTX mode */ - if (dtx_mode == 0) - { - tot_wc = 0L; - for (i = 0; i < funcid[currCounter]; i++) - tot_wc += wc[currCounter][i]; - fprintf (stdout, " WorstWC=%.3f", ((float) tot_wc) * frameRate); - } - fprintf (stdout, " (%d frames)\n", nbframe[currCounter]); -#else - (void)dtx_mode; - (void)tot_wm; - (void)num_frames; -#endif /* ifdef WMOPS */ -} - -void generic_WMOPS_output (Word16 dtx_mode, char *test_file_name) -{ -#if WMOPS - int saved_value; - Word16 i; - Word32 tot, tot_wm, tot_wc, *ptr, *ptr2; - Word40 grand_total; - FILE *WMOPS_file; - - saved_value = currCounter; - - /*Count the grand_total WMOPS so that % ratio per function group - can be displayed. */ - grand_total = 0; - for( currCounter = 0; currCounter <= maxCounter; currCounter++) { - tot = WMOPS_frameStat(); - grand_total += tot; - - } - - - if( (WMOPS_file=fopen(WMOPS_DATA_FILENAME,"a"))!=NULL) { - - printf( "opened file %s in order to print WMOPS for each function group.\n", WMOPS_DATA_FILENAME); - - /* Print the file header line. */ - fprintf (WMOPS_file, "Test file name\tFunction Name \tFrame\tNb Times Called\tWMOPS\t%% versus grand total"); - - if (nbframe[saved_value] != 0) - fprintf (WMOPS_file, "\tAverage"); - - fprintf (WMOPS_file, "\tWorstCase"); - - /* Worst worst case printed only when not in DTX mode */ - if (dtx_mode == 0) - fprintf (WMOPS_file, "\tWorstWC"); - - fprintf (WMOPS_file, "\n"); - - /* Print the WMOPS for each Function Group by scanning - all the function groups with currCounter index.*/ - for( currCounter = 0; currCounter <= maxCounter; currCounter++) { - - fprintf (WMOPS_file, "%s", test_file_name); - fprintf (WMOPS_file, "\t%s", - objectName[currCounter] ? objectName[currCounter] : ""); - fprintf (WMOPS_file, "\t%d", nbframe[currCounter]); - - tot = WMOPS_frameStat(); - tot_wm = (Word32)(total_wmops[currCounter] + ((float) tot) * frameRate); - - fprintf (WMOPS_file, "\t\t%ld", nbTimeObjectIsCalled[currCounter]); - fprintf (WMOPS_file, "\t%.6f", ((float) tot) * frameRate); - fprintf (WMOPS_file, "\t%.3f", ((float) tot) / grand_total * 100); - - if (nbframe[currCounter] != 0) - fprintf (WMOPS_file, "\t%.3f", tot_wm / (float) nbframe[currCounter]); - - fprintf (WMOPS_file, "\t%.3f", ((float) glob_wc[currCounter]) * frameRate); - - /* Worst worst case printed only when not in DTX mode */ - if (dtx_mode == 0) { - tot_wc = 0L; - for (i = 0; i < funcid[currCounter]; i++) - tot_wc += wc[currCounter][i]; - fprintf (WMOPS_file, "\t%.3f", ((float) tot_wc) * frameRate); - } - fprintf (WMOPS_file, "\n"); - - } - - /* Print the file Grand Total line */ - fprintf (WMOPS_file, "%s", test_file_name); - fprintf (WMOPS_file, "\tGrand Total"); - fprintf (WMOPS_file, "\t%d", nbframe[saved_value]); - fprintf (WMOPS_file, "\t\t%.6f", ((float) grand_total) * frameRate); - fprintf (WMOPS_file, "\t100.000"); - fprintf (WMOPS_file, "\n"); - fclose(WMOPS_file); - - } else - printf( "Can not open file %s for WMOPS editing\n", WMOPS_DATA_FILENAME); - - - if( (WMOPS_file=fopen(WMOPS_TOTAL_FILENAME,"a"))!=NULL) { - printf( "opened file %s in order to print application's total WMOPS.\n", WMOPS_TOTAL_FILENAME); - fprintf (WMOPS_file, "%s", test_file_name); - fprintf (WMOPS_file, "\tframe=%d", nbframe[currCounter]); - fprintf (WMOPS_file, "\tWMOPS=%.6f", ((float) grand_total) * frameRate); - fprintf (WMOPS_file, "\n"); - fclose(WMOPS_file); - - } else - printf( "Can not open file %s for WMOPS editing.\n", WMOPS_TOTAL_FILENAME); - - - if( (WMOPS_file=fopen(CODE_PROFILE_FILENAME,"a"))!=NULL) { - - printf( "opened file %s in order to print basic operation distribution statistics.\n", CODE_PROFILE_FILENAME); - - /* Print the file header line. */ - fprintf (WMOPS_file, "Test file name\tBasic Operation Name\tframe\tWMOPS\t\t%% versus grand total\n"); - - /* Print the WMOPS for each Basic Operation across all the defined */ - /* Function Groups. */ - for( i = 0; i <(Word16)(sizeof(op_weight) / sizeof(Word32)); i++) { - fprintf (WMOPS_file, "%-16s", test_file_name); - fprintf (WMOPS_file, "\t%s", BasicOperationList[i]); - fprintf (WMOPS_file, "\t%d", nbframe[0]); - - tot = 0; - ptr = (Word32 *) &multiCounter[0] + i; - ptr2 = (Word32 *) &op_weight + i; - for( currCounter = 0; currCounter <= maxCounter; currCounter++) { - tot += ((*ptr) * (*ptr2)); - ptr += (sizeof(op_weight) / sizeof(Word32)); - } - - fprintf (WMOPS_file, "\t%.6f", ((float) tot) * frameRate); - fprintf (WMOPS_file, "\t%.3f", ((float) tot) / grand_total * 100); - fprintf (WMOPS_file, "\n"); - } - - /* Print the file Grand Total line */ - fprintf (WMOPS_file, "%s", test_file_name); - fprintf (WMOPS_file, "\tGrand Total"); - fprintf (WMOPS_file, "\t%d", nbframe[saved_value]); - fprintf (WMOPS_file, "\t%.6f", ((float) grand_total) * frameRate); - fprintf (WMOPS_file, "\t100.000"); - fprintf (WMOPS_file, "\n"); - fclose(WMOPS_file); - - } else - printf( "Can not open file %s for basic operations distribution statistic editing\n", CODE_PROFILE_FILENAME); - - currCounter = saved_value; - -#else - (void)dtx_mode; - (void)test_file_name; -#endif /* ifdef WMOPS */ -} - - -/* end of file */ - diff --git a/src/libs/libevs/basic_op/count.h b/src/libs/libevs/basic_op/count.h deleted file mode 100755 index 7886b8a0..00000000 --- a/src/libs/libevs/basic_op/count.h +++ /dev/null @@ -1,410 +0,0 @@ -/* - =========================================================================== - File: COUNT.H v.2.3 - 30.Nov.2009 - =========================================================================== - - ITU-T STL BASIC OPERATORS - - PROTOTYPES & DEFINITION FOR COUNTING OPERATIONS - - History - 09.Aug.1999 V1.0.0 Input to UGST from ETSI AMR (count.h); - - 26.Jan.2000 V1.1.0 Added counter entries for G.723.1's - L_mls(), div_l(), i_mult() [from basop32.c] - - 05.Jul.2000 V1.2.0 Added counter entries for 32bit shiftless - operators L_mult0(), L_mac0(), L_msu0() - - 03 Nov 04 v2.0 Incorporation of new 32-bit / 40-bit / control - operators for the ITU-T Standard Tool Library as - described in Geneva, 20-30 January 2004 WP 3/16 Q10/16 - TD 11 document and subsequent discussions on the - wp3audio@yahoogroups.com email reflector. - March 06 v2.1 Changed to improve portability. - Dec 06 v2.2 Changed to specify frame rate using setFrameRate() - Adding WMOPS_output_avg() for global average computation - L_mls() weight of 5. - div_l() weight of 32. - i_mult() weight of 3. - ============================================================================ -*/ - - -/****************************************************************************** - * Functions for counting operations. - * - * These functions make it possible to measure the wMOPS of a codec. - * - * All functions in this file, and in other *.h files, update a structure so - * that it will be possible to track how many calls to add(), sub(), L_mult() - * ... was made by the code and to estimate the wMOPS (and MIPS) for a certain - * part of the code. - * - * It is also possible to measure the wMOPS separatly for different parts - * of the codec. - * - * This is done by creating a counter group (getCounterId) for each part of - * the code that one wants a seperate measure for. Before a part of the code - * is executed a call to the "setCounter" function is needed to identify - * which counter group to use. - * - * Currently there is a limit of 255 different counter groups. - * - * In the end of this file, there is a piece of code illustrating how the - * functions can be used. - * -******************************************************************************/ - - -#ifndef _COUNT_H -#define _COUNT_H -/* #define WMOPS 1 */ /* enable WMOPS profiling features */ -/* #undef WMOPS */ /* disable WMOPS profiling features */ -#define MAXCOUNTERS (256) - -#define BASOP_sub_start(label) -#define BASOP_sub_end() -#define SUB_WMOPS_INIT(label) BASOP_sub_start(label) -#define END_SUB_WMOPS BASOP_sub_end() -#define BASOP_push_wmops(label) -#define BASOP_pop_wmops() -#define BASOP_end_noprint -#define BASOP_end -#define BASOP_init - -int getCounterId( char *objectName); -/* - * Create a counter group, the "objectname" will be used when printing - * statistics for this counter group. - * - * Returns 0 if no more counter groups are available. - */ - - -int readCounterId(void); -/* - * Returns the current CounterId. - */ - - -void setCounter( int counterId); -/* - * Defines which counter group to use, default is zero. - */ - - -char *readCounterIdName(void); -/* - * Returns the current CounterId name. - */ - - -void incrementNbTimeObjectIsCalled( int counterId); -/* - * This function enables to increment by 1 a counter - * tracking the number of times the application enters a groups of functions. - * If the counterId is not refering to a defined function counter group, then it is - * the default function group (0) which is impacted. - * - */ - - -void ClearNbTimeObjectsAreCalled(void); -/* - * This function enables to clear to 0 all the counters enabling to - * track the number of times the application enters any groups of functions. - */ - - -void Init_WMOPS_counter( void); -/* - * Initiates the current counter group. - */ - - -void Reset_WMOPS_counter( void); -/* - * Resets the current counter group. - */ - - -void WMOPS_output ( Word16 notPrintWorstWorstCase); -/* - * Prints the statistics to the screen, if the argument is non zero - * the statistics for worst worst case will not be printed. This is typically - * done for dtx frames. - * - */ - -void WMOPS_output_avg (Word16 dtx_mode, Word32 *tot_wm, Word16 *num_frames); -/* - * same as WMOPS_output + returns the total wmops counter and the number of frames - * to support the computation of global average. - * - */ - - -Word32 fwc( void); -/* - * worst worst case counter. - * - * This function calculates the worst possible case that can be reached. - * - * This is done by calling this function for each subpart of the calculations - * for a frame. This function then stores the maximum wMOPS for each part. - * - * The WMOPS_output function add together all parts and presents the sum. - */ - -void setFrameRate(int samplingFreq, int frameLength); -/* - * This function can overwrite the value of the frameRate variable that is - * initialized by the FRAME_RATE constant. - */ - - -#define WMOPS_DATA_FILENAME "wmops_data.txt" -/* - * WMOPS_DATA_FILENAME is the macro defining the name of the file - * where the Weighted Million of Operations per Second (wMOPS) - * are appended, function group by function group. -*/ - - -#define CODE_PROFILE_FILENAME "code_profile.txt" -/* - * CODE_PROFILE_FILENAME is the macro defining the name of the file - * where the Weighted Million of Operations per Second (WMOPS) - * are appended, basic operation by basic operation. -*/ - - -#define WMOPS_TOTAL_FILENAME "wmops_total.txt" -/* - * WMOPS_TOTAL_FILENAME is the macro defining the name of the file - * where the Weighted Million of Operations per Second (WMOPS) - * are printed, globally for the application. -*/ - - -#define FRAME_RATE (0.0001F) /*in this version frame_rate can be overwriten online by the new setFrameRate function */ -/* FRAME_RATE of 0.000025 is corresponding to 40ms frame.*/ -/* FRAME_RATE of 0.00005 is corresponding to 20ms frame.*/ -/* FRAME_RATE of 0.0001 is corresponding to 10ms frame.*/ -/* - * FRAME_RATE is the macro defining the calling rate of the - * application to benchmark. -*/ - - -/* Global counter variable for calculation of complexity weight */ -typedef struct -{ - UWord32 add; /* Complexity Weight of 1 */ - UWord32 sub; /* Complexity Weight of 1 */ - UWord32 abs_s; /* Complexity Weight of 1 */ - UWord32 shl; /* Complexity Weight of 1 */ - UWord32 shr; /* Complexity Weight of 1 */ - - UWord32 extract_h; /* Complexity Weight of 1 */ - UWord32 extract_l; /* Complexity Weight of 1 */ - UWord32 mult; /* Complexity Weight of 1 */ - UWord32 L_mult; /* Complexity Weight of 1 */ - UWord32 negate; /* Complexity Weight of 1 */ - - UWord32 round; /* Complexity Weight of 1 */ - UWord32 L_mac; /* Complexity Weight of 1 */ - UWord32 L_msu; /* Complexity Weight of 1 */ - UWord32 L_macNs; /* Complexity Weight of 1 */ - UWord32 L_msuNs; /* Complexity Weight of 1 */ - - UWord32 L_add; /* Complexity Weight of 1 */ - UWord32 L_sub; /* Complexity Weight of 1 */ - UWord32 L_add_c; /* Complexity Weight of 2 */ - UWord32 L_sub_c; /* Complexity Weight of 2 */ - UWord32 L_negate; /* Complexity Weight of 1 */ - - UWord32 L_shl; /* Complexity Weight of 1 */ - UWord32 L_shr; /* Complexity Weight of 1 */ - UWord32 mult_r; /* Complexity Weight of 1 */ - UWord32 shr_r; /* Complexity Weight of 3 */ - UWord32 mac_r; /* Complexity Weight of 1 */ - - UWord32 msu_r; /* Complexity Weight of 1 */ - UWord32 L_deposit_h; /* Complexity Weight of 1 */ - UWord32 L_deposit_l; /* Complexity Weight of 1 */ - UWord32 L_shr_r; /* Complexity Weight of 3 */ - UWord32 L_abs; /* Complexity Weight of 1 */ - - UWord32 L_sat; /* Complexity Weight of 4 */ - UWord32 norm_s; /* Complexity Weight of 1 */ - UWord32 div_s; /* Complexity Weight of 18 */ - UWord32 norm_l; /* Complexity Weight of 1 */ - UWord32 move16; /* Complexity Weight of 1 */ - - UWord32 move32; /* Complexity Weight of 2 */ - UWord32 Logic16; /* Complexity Weight of 1 */ - UWord32 Logic32; /* Complexity Weight of 2 */ - UWord32 Test; /* Complexity Weight of 2 */ - UWord32 s_max; /* Complexity Weight of 1 */ - - UWord32 s_min; /* Complexity Weight of 1 */ - UWord32 L_max; /* Complexity Weight of 1 */ - UWord32 L_min; /* Complexity Weight of 1 */ - UWord32 L40_max; /* Complexity Weight of 1 */ - UWord32 L40_min; /* Complexity Weight of 1 */ - - UWord32 shl_r; /* Complexity Weight of 3 */ - UWord32 L_shl_r; /* Complexity Weight of 3 */ - UWord32 L40_shr_r; /* Complexity Weight of 3 */ - UWord32 L40_shl_r; /* Complexity Weight of 3 */ - UWord32 norm_L40; /* Complexity Weight of 1 */ - - UWord32 L40_shl; /* Complexity Weight of 1 */ - UWord32 L40_shr; /* Complexity Weight of 1 */ - UWord32 L40_negate; /* Complexity Weight of 1 */ - UWord32 L40_add; /* Complexity Weight of 1 */ - UWord32 L40_sub; /* Complexity Weight of 1 */ - - UWord32 L40_abs; /* Complexity Weight of 1 */ - UWord32 L40_mult; /* Complexity Weight of 1 */ - UWord32 L40_mac; /* Complexity Weight of 1 */ - UWord32 mac_r40; /* Complexity Weight of 2 */ - - UWord32 L40_msu; /* Complexity Weight of 1 */ - UWord32 msu_r40; /* Complexity Weight of 2 */ - UWord32 Mpy_32_16_ss; /* Complexity Weight of 2 */ - UWord32 Mpy_32_32_ss; /* Complexity Weight of 4 */ - UWord32 L_mult0; /* Complexity Weight of 1 */ - - UWord32 L_mac0; /* Complexity Weight of 1 */ - UWord32 L_msu0; /* Complexity Weight of 1 */ - UWord32 lshl; /* Complexity Weight of 1 */ - UWord32 lshr; /* Complexity Weight of 1 */ - UWord32 L_lshl; /* Complexity Weight of 1 */ - - UWord32 L_lshr; /* Complexity Weight of 1 */ - UWord32 L40_lshl; /* Complexity Weight of 1 */ - UWord32 L40_lshr; /* Complexity Weight of 1 */ - UWord32 s_and; /* Complexity Weight of 1 */ - UWord32 s_or; /* Complexity Weight of 1 */ - - UWord32 s_xor; /* Complexity Weight of 1 */ - UWord32 L_and; /* Complexity Weight of 1 */ - UWord32 L_or; /* Complexity Weight of 1 */ - UWord32 L_xor; /* Complexity Weight of 1 */ - UWord32 rotl; /* Complexity Weight of 3 */ - - UWord32 rotr; /* Complexity Weight of 3 */ - UWord32 L_rotl; /* Complexity Weight of 3 */ - UWord32 L_rotr; /* Complexity Weight of 3 */ - UWord32 L40_set; /* Complexity Weight of 3 */ - UWord32 L40_deposit_h; /* Complexity Weight of 1 */ - - UWord32 L40_deposit_l; /* Complexity Weight of 1 */ - UWord32 L40_deposit32; /* Complexity Weight of 1 */ - UWord32 Extract40_H; /* Complexity Weight of 1 */ - UWord32 Extract40_L; /* Complexity Weight of 1 */ - UWord32 L_Extract40; /* Complexity Weight of 1 */ - - UWord32 L40_round; /* Complexity Weight of 1 */ - UWord32 L_saturate40; /* Complexity Weight of 1 */ - UWord32 round40; /* Complexity Weight of 1 */ - UWord32 If; /* Complexity Weight of 4 */ - UWord32 Goto; /* Complexity Weight of 4 */ - - UWord32 Break; /* Complexity Weight of 4 */ - UWord32 Switch; /* Complexity Weight of 8 */ - UWord32 For; /* Complexity Weight of 3 */ - UWord32 While; /* Complexity Weight of 4 */ - UWord32 Continue; /* Complexity Weight of 4 */ - - UWord32 L_mls; /* Complexity Weight of 6 */ - UWord32 div_l; /* Complexity Weight of 32 */ - UWord32 i_mult; /* Complexity Weight of 3 */ -} -BASIC_OP; - - -Word32 TotalWeightedOperation( void); -Word32 DeltaWeightedOperation( void); - - -void generic_WMOPS_output ( Word16 notPrintWorstWorstCase, char *test_file_name); -/* - * This function enable to append : - * - to WMOPS_DATA_FILENAME file, the WMOPS information related - * to the execution of the application, function group by function - * group. - * - to CODE_PROFILE_FILENAME file, the WMOPS information related - * to the execution of the application, basic operation by basic - * operation. - * - to WMOPS_TOTAL_FILENAME file, the total WMOPS information related - * to the execution of the application. - * - * Note that : - * if the files exists, the data will be written at the end of file. - * - * test_file_name : Is a character string referencing each calls to - * generic_WMOPS_output(). Usually, it is the name of a test - * sequence file. - * - * notPrintWorstWorstCase : Same usage as in WMOPS_output(). - */ - - -#if 0 -/* - * Example of how count.h could be used. - * - * In the example below it is assumed that the init_OBJECT functions - * does not use any calls to counter.h or basic_op.h. If this is the case - * a call to the function Reset_WMOPS_counter() must be done after each call - * to init_OBJECT if these operations is not to be included in the statistics. - */ - -int main(){ - int spe1Id,spe2Id,cheId; - - /* initiate counters and objects */ - spe1Id=getCounterId("Spe 5k8"); - setCounter(spe1Id); - Init_WMOPS_counter (); - init_spe1(...); - - spe2Id=getCounterId("Spe 12k2"); - setCounter(spe2Id); - Init_WMOPS_counter (); - init_spe2(...); - - cheId=getCounterId("Channel encoder"); - setCounter(cheId); - Init_WMOPS_counter (); - init_che(...); - ... - while(data){ - test(); /* Note this call to test(); */ - if(useSpe1) - setCounter(spe1Id); - else - setCounter(spe2Id); - Reset_WMOPS_counter(); - speEncode(...); - WMOPS_output(0); /* Normal routine for displaying WMOPS info */ - - setCounter(cheId); - Reset_WMOPS_counter(); - preChannelInter(...); fwc(); /* Note the call to fwc() for each part*/ - convolve(...); fwc(); /* of the channel encoder. */ - interleave(...); fwc(); - WMOPS_output(0); /* Normal routine for displaying WMOPS info */ - } -} -#endif /* #if 0*/ - - -#endif /* _COUNT_H */ - - -/* end of file */ diff --git a/src/libs/libevs/basic_op/enh40.cpp b/src/libs/libevs/basic_op/enh40.cpp deleted file mode 100755 index 010cc747..00000000 --- a/src/libs/libevs/basic_op/enh40.cpp +++ /dev/null @@ -1,688 +0,0 @@ -/* - =========================================================================== - File: ENH40.C v.2.3 - 30.Nov.2009 - =========================================================================== - - ITU-T STL BASIC OPERATORS - - 40-BIT ARITHMETIC OPERATORS - - History: - 07 Nov 04 v2.0 Incorporation of new 32-bit / 40-bit / control - operators for the ITU-T Standard Tool Library as - described in Geneva, 20-30 January 2004 WP 3/16 Q10/16 - TD 11 document and subsequent discussions on the - wp3audio@yahoogroups.com email reflector. - - 31 Mar 15 v2.1E Removal of operators not used in the EVS codec. - - ============================================================================ -*/ - - -/***************************************************************************** - * - * Enhanced 40 bit operators : - * - * Mpy_32_16_ss() - * Mpy_32_32_ss() - * - *****************************************************************************/ - - -/***************************************************************************** - * - * Include-Files - * - *****************************************************************************/ -#include -#include -#include "stl.h" - -#if (WMOPS) -extern BASIC_OP multiCounter[MAXCOUNTERS]; -extern int currCounter; -#endif /* if WMOPS */ - - -/***************************************************************************** - * - * Local Functions - * - *****************************************************************************/ -static __inline Word40 L40_shr( Word40 L40_var1, Word16 var2); -static __inline Word40 L40_shl( Word40 L40_var1, Word16 var2); -static __inline Word40 L40_set( Word40 L40_var1); -static __inline UWord16 Extract40_L( Word40 L40_var1); -static __inline Word40 L40_mult( Word16 var1, Word16 var2); -static __inline Word40 L40_add( Word40 L40_var1, Word40 L40_var2); -static __inline Word40 L40_mac( Word40 L40_var1, Word16 var2, Word16 var3); -static __inline UWord32 L_Extract40( Word40 L40_var1) ; - -/***************************************************************************** - * - * Macros for 40 bit arithmetic overflow management : - * Upon 40-bit overflow beyond MAX_40 or underflow beyond MIN_40, - * the application will exit. - * - *****************************************************************************/ -#define L40_OVERFLOW_OCCURED( L40_var1) (Overflow = 1, exit(1), L40_var1) -#define L40_UNDERFLOW_OCCURED( L40_var1) (Overflow = 1, exit(2), L40_var1) - -/***************************************************************************** - * - * Constants and Globals - * - *****************************************************************************/ - - -/***************************************************************************** - * - * Functions - * - *****************************************************************************/ - - -/***************************************************************************** - * - * Function Name : Mpy_32_16_ss - * - * Purpose : - * - * Multiplies the 2 signed values L_var1 and var2 with saturation control - * on 48-bit. The operation is performed in fractional mode : - * - L_var1 is supposed to be in 1Q31 format. - * - var2 is supposed to be in 1Q15 format. - * - The result is produced in 1Q47 format : L_varout_h points to the - * 32 MSBits while varout_l points to the 16 LSBits. - * - * Complexity weight : 2 - * - * Inputs : - * - * L_var1 32 bit long signed integer (Word32) whose value falls in - * the range : 0x8000 0000 <= L_var1 <= 0x7fff ffff. - * - * var2 16 bit short signed integer (Word16) whose value falls in - * the range : 0xffff 8000 <= var2 <= 0x0000 7fff. - * - * Outputs : - * - * *L_varout_h 32 bit long signed integer (Word32) whose value falls in - * the range : 0x8000 0000 <= L_varout_h <= 0x7fff ffff. - * - * *varout_l 16 bit short unsigned integer (UWord16) whose value falls in - * the range : 0x0000 0000 <= varout_l <= 0x0000 ffff. - * - * Return Value : - * - * none - * - *****************************************************************************/ -void Mpy_32_16_ss( Word32 L_var1, Word16 var2, Word32 *L_varout_h, UWord16 *varout_l) { - Word16 var1_h; - UWord16 uvar1_l; - Word40 L40_var1; - - if( (L_var1 == ( Word32) 0x80000000) - && (var2 == ( Word16) 0x8000)) { - *L_varout_h = 0x7fffffff; - *varout_l = ( UWord16) 0xffff; - - } else { - uvar1_l = extract_l( L_var1); - var1_h = extract_h( L_var1); - - /* Below line can not overflow, so we can use << instead of L40_shl. */ - L40_var1 = (( Word40) (( Word32) var2 * ( Word32) uvar1_l)) << 1; - - *varout_l = Extract40_L( L40_var1); - - L40_var1 = L40_shr( L40_var1, 16); - L40_var1 = L40_mac( L40_var1, var2, var1_h); - - *L_varout_h = L_Extract40( L40_var1); - - #if (WMOPS) - multiCounter[currCounter].extract_l--; - multiCounter[currCounter].extract_h--; - multiCounter[currCounter].Extract40_L--; - multiCounter[currCounter].L40_shr--; - multiCounter[currCounter].L40_mac--; - multiCounter[currCounter].L_Extract40--; - #endif /* if WMOPS */ - } - - #if (WMOPS) - multiCounter[currCounter].Mpy_32_16_ss++; - #endif /* if WMOPS */ - - return; -} - - -/***************************************************************************** - * - * Function Name : Mpy_32_32_ss - * - * Purpose : - * - * Multiplies the 2 signed values L_var1 and L_var2 with saturation control - * on 64-bit. The operation is performed in fractional mode : - * - L_var1 and L_var2 are supposed to be in 1Q31 format. - * - The result is produced in 1Q63 format : L_varout_h points to the - * 32 MSBits while L_varout_l points to the 32 LSBits. - * - * Complexity weight : 4 - * - * Inputs : - * - * L_var1 32 bit long signed integer (Word32) whose value falls in the - * range : 0x8000 0000 <= L_var1 <= 0x7fff ffff. - * - * L_var2 32 bit long signed integer (Word32) whose value falls in the - * range : 0x8000 0000 <= L_var2 <= 0x7fff ffff. - * - * Outputs : - * - * *L_varout_h 32 bit long signed integer (Word32) whose value falls in - * the range : 0x8000 0000 <= L_varout_h <= 0x7fff ffff. - * - * *L_varout_l 32 bit short unsigned integer (UWord32) whose value falls in - * the range : 0x0000 0000 <= L_varout_l <= 0xffff ffff. - * - * - * Return Value : - * - * none - * - *****************************************************************************/ -void Mpy_32_32_ss( Word32 L_var1, Word32 L_var2, Word32 *L_varout_h, UWord32 *L_varout_l) { - UWord16 uvar1_l, uvar2_l; - Word16 var1_h, var2_h; - Word40 L40_var1; - - if( (L_var1 == ( Word32)0x80000000) - && (L_var2 == ( Word32)0x80000000)) { - *L_varout_h = 0x7fffffff; - *L_varout_l = ( UWord32)0xffffffff; - - } else { - - uvar1_l = extract_l( L_var1); - var1_h = extract_h( L_var1); - uvar2_l = extract_l( L_var2); - var2_h = extract_h( L_var2); - - /* Below line can not overflow, so we can use << instead of L40_shl. */ - L40_var1 = (( Word40) (( UWord32) uvar2_l * ( UWord32) uvar1_l)) << 1; - - *L_varout_l = 0x0000ffff & L_Extract40( L40_var1); - - L40_var1 = L40_shr( L40_var1, 16); - L40_var1 = L40_add( L40_var1, (( Word40) (( Word32) var2_h * ( Word32) uvar1_l)) << 1); - L40_var1 = L40_add( L40_var1, (( Word40) (( Word32) var1_h * ( Word32) uvar2_l)) << 1); - *L_varout_l |= (L_Extract40( L40_var1)) << 16; - - L40_var1 = L40_shr( L40_var1, 16); - L40_var1 = L40_mac( L40_var1, var1_h, var2_h); - - *L_varout_h = L_Extract40( L40_var1); - - #if (WMOPS) - multiCounter[currCounter].extract_l-=2; - multiCounter[currCounter].extract_h-=2; - multiCounter[currCounter].L_Extract40-=3; - multiCounter[currCounter].L40_shr-=2; - multiCounter[currCounter].L40_add-=2; - multiCounter[currCounter].L40_mac--; - #endif /* if WMOPS */ - } - - #if (WMOPS) - multiCounter[currCounter].Mpy_32_32_ss++; - #endif /* if WMOPS */ - - return; -} - - -/***************************************************************************** - * - * Function Name : L40_set - * - * Purpose : - * - * Assigns a 40 constant to a Word40 with adequate initialization depending - * on underlying architecture constraints (for example to keep consistency - * of sign bits). Current implementation only validated on MSVC++6.0. - * - * Complexity weight : 3 - * - * Inputs : - * - * L40_var1 40 bit long signed integer (Word40) whose value falls in the - * range : MIN_40 <= L40_var1 <= MAX_40. - * - * Outputs : - * - * none - * - * Return Value : - * - * L40_var_out 40 bit long signed integer (Word40) whose value falls in - * the range : MIN_40 <= L40_var_out <= MAX_40. - * - *****************************************************************************/ -/*#ifdef _MSC_VER*/ -static __inline Word40 L40_set( Word40 L40_var1) { - Word40 L40_var_out; - -#if defined(_MSC_VER) && (_MSC_VER <= 1200) - L40_var_out = L40_var1 & 0x000000ffffffffff; - - if( L40_var1 & 0x8000000000) - L40_var_out = L40_var_out | 0xffffff0000000000; -#else - L40_var_out = L40_var1 & 0x000000ffffffffffLL; - - if( L40_var1 & 0x8000000000LL) - L40_var_out = L40_var_out | 0xffffff0000000000LL; -#endif - - #if WMOPS - multiCounter[currCounter].L40_set++; - #endif /* if WMOPS */ - - return( L40_var_out); -} -/*#endif*/ /* ifdef _MSC_VER */ - - -/***************************************************************************** - * - * Function Name : Extract40_L - * - * Purpose : - * - * Returns the bits [15-0] of L40_var1. - * - * Complexity weight : 1 - * - * Inputs : - * - * L40_var1 40 bit long signed integer (Word40) whose value falls in the - * range : MIN_40 <= L40_var1 <= MAX_40. - * - * Outputs : - * - * none - * - * Return Value : - * - * var_out 16 bit short unsigned integer (UWord16) whose value falls in - * the range : MIN_U_16 <= var_out <= MAX_U_16. - * - *****************************************************************************/ -static __inline UWord16 Extract40_L( Word40 L40_var1) { - UWord16 var_out; - - var_out = ( UWord16)( L40_var1); - - #if (WMOPS) - multiCounter[currCounter].Extract40_L++; - #endif /* if WMOPS */ - - return( var_out); -} - - -/***************************************************************************** - * - * Function Name : L40_mult - * - * Purpose : - * - * Multiplies var1 by var2 and shifts the result left by 1. Returns the - * full precision result on 40-bit. - * L40_mult( var1, var2) = shiftleft(( var1 times var2), 1) - * - * Complexity weight : 1 - * - * Inputs : - * - * var1 16 bit short signed integer (Word16) whose value falls in - * the range : MIN_16 <= var1 <= MAX_16. - * - * var2 16 bit short signed integer (Word16) whose value falls in - * the range : MIN_16 <= var2 <= MAX_16. - * - * Outputs : - * - * none - * - * Return Value : - * - * L40_var_out 40 bit long signed integer (Word40) whose value falls in - * the range : MIN_40 <= L40_var_out <= MAX_40. - * - *****************************************************************************/ -static __inline Word40 L40_mult( Word16 var1, Word16 var2) { - Word32 L_var_out; - Word40 L40_var_out; - - L_var_out = ( Word32) var1 * ( Word32) var2; - L40_var_out = ( Word40) L_var_out; - - /* Below line can not overflow, so we can use << instead of L40_shl. */ - L40_var_out = L40_var_out << 1; - - #if (WMOPS) - multiCounter[currCounter].L40_mult++; - #endif /* if WMOPS */ - - return( L40_var_out); -} - -/***************************************************************************** - * - * Function Name : L40_add - * - * Purpose : - * - * Adds L40_var1 and L40_var2 and returns the 40-bit result. - * Calls the macro L40_UNDERFLOW_OCCURED() in case of underflow on 40-bit. - * Calls the macro L40_OVERFLOW_OCCURED() in case of overflow on 40-bit. - * - * Complexity weight : 1 - * - * Inputs : - * - * L40_var1 40 bit long signed integer (Word40) whose value falls in the - * range : MIN_40 <= L40_var1 <= MAX_40. - * - * L40_var2 40 bit long signed integer (Word40) whose value falls in the - * range : MIN_40 <= L40_var2 <= MAX_40. - * - * Outputs : - * - * none - * - * Return Value : - * - * L40_var_out 40 bit long signed integer (Word40) whose value falls in - * the range : MIN_40 <= L40_var_out <= MAX_40. - * - *****************************************************************************/ -static __inline Word40 L40_add( Word40 L40_var1, Word40 L40_var2) { - Word40 L40_var_out; - - L40_var_out = L40_var1 + L40_var2; - -#if defined(_MSC_VER) && (_MSC_VER <= 1200) - if( ((( L40_var1 & 0x8000000000) >> 39) != 0) - && ((( L40_var2 & 0x8000000000) >> 39) != 0) - && ((( L40_var_out & 0x8000000000) >> 39) == 0)) { - L40_var_out = L40_UNDERFLOW_OCCURED( L40_var_out); - - } else if( (((L40_var1 & 0x8000000000) >> 39) == 0) - && (((L40_var2 & 0x8000000000) >> 39) == 0) - && (((L40_var_out & 0x8000000000) >> 39) != 0)) { - L40_var_out = L40_OVERFLOW_OCCURED( L40_var_out); - } -#else - if( ((( L40_var1 & 0x8000000000LL) >> 39) != 0) - && ((( L40_var2 & 0x8000000000LL) >> 39) != 0) - && ((( L40_var_out & 0x8000000000LL) >> 39) == 0)) { - L40_var_out = L40_UNDERFLOW_OCCURED( L40_var_out); - - } else if( (((L40_var1 & 0x8000000000LL) >> 39) == 0) - && (((L40_var2 & 0x8000000000LL) >> 39) == 0) - && (((L40_var_out & 0x8000000000LL) >> 39) != 0)) { - L40_var_out = L40_OVERFLOW_OCCURED( L40_var_out); - } -#endif - - #if (WMOPS) - multiCounter[currCounter].L40_add++; - #endif /* if WMOPS */ - - BASOP_CHECK(); - - return( L40_var_out); -} - -/***************************************************************************** - * - * Function Name : L40_mac - * - * Purpose : - * - * Multiplies var2 by var3. Shifts left the 40-bit result by 1 and adds - * the result to L40_var1. Returns a 40 bit result. - * L40_mac( L40_var1, var2, var3) - * = L40_add( L40_var1, L40_mult( var2, var3)) - * Calls the macro L40_UNDERFLOW_OCCURED() in case of underflow on 40-bit. - * Calls the macro L40_OVERFLOW_OCCURED() in case of overflow on 40-bit. - * - * Complexity weight : 1 - * - * Inputs : - * - * L40_var1 40 bit long signed integer (Word40) whose value falls in the - * range : MIN_40 <= L40_var1 <= MAX_40. - * - * var2 16 bit short signed integer (Word16) whose value falls in - * the range : MIN_16 <= var2 <= MAX_16. - * - * var3 16 bit short signed integer (Word16) whose value falls in - * the range : MIN_16 <= var3 <= MAX_16. - * - * Outputs : - * - * none - * - * Return Value : - * - * L40_var_out 40 bit long signed integer (Word40) whose value falls in - * the range : MIN_40 <= L40_var_out <= MAX_40. - * - *****************************************************************************/ -static __inline Word40 L40_mac( Word40 L40_var1, Word16 var2, Word16 var3) { - Word40 L40_var_out; - - L40_var_out = L40_mult( var2, var3); - L40_var_out = L40_add( L40_var1, L40_var_out); - - #if (WMOPS) - multiCounter[currCounter].L40_mult--; - multiCounter[currCounter].L40_add--; - multiCounter[currCounter].L40_mac++; - #endif /* if WMOPS */ - - return( L40_var_out); -} - -/***************************************************************************** - * - * Function Name : L_Extract40 - * - * Purpose : - * - * Returns the bits [31-0] of L40_var1. - * - * Complexity weight : 1 - * - * Inputs : - * - * L40_var1 40 bit long signed integer (Word40) whose value falls in the - * range : MIN_40 <= L40_var1 <= MAX_40. - * - * Outputs : - * - * none - * - * Return Value : - * - * L_var_out 32 bit long unsigned integer (UWord32) whose value falls in - * range : MIN_U_32 <= L_var_out <= MAX_U_32. - * - *****************************************************************************/ -static __inline UWord32 L_Extract40( Word40 L40_var1) { - UWord32 L_var_out; - - L_var_out = ( UWord32) L40_var1; - - #if (WMOPS) - multiCounter[currCounter].L_Extract40++; - #endif /* if WMOPS */ - - return(L_var_out); -} - - -/***************************************************************************** - * - * Function Name : L40_shl - * - * Purpose : - * - * Arithmetically shifts left L40_var1 by var2 positions. - * - If var2 is negative, L40_var1 is shifted to the LSBits by (-var2) - * positions with extension of the sign bit. - * - If var2 is positive, L40_var1 is shifted to the MSBits by (var2) - * positions. - * Calls the macro L40_UNDERFLOW_OCCURED() in case of underflow on 40-bit. - * Calls the macro L40_OVERFLOW_OCCURED() in case of overflow on 40-bit. - * - * Complexity weight : 1 - * - * Inputs : - * - * L40_var1 40 bit long signed integer (Word40) whose value falls in the - * range : MIN_40 <= L40_var1 <= MAX_40. - * - * var2 16 bit short signed integer (Word16) whose value falls in - * the range : MIN_16 <= var2 <= MAX_16. - * - * Outputs : - * - * none - * - * Return Value : - * - * L40_var_out 40 bit long signed integer (Word40) whose value falls in - * the range : MIN_40 <= L40_var_out <= MAX_40. - * - *****************************************************************************/ -static __inline Word40 L40_shl( Word40 L40_var1, Word16 var2) { - - Word40 L40_var_out; -#if defined(_MSC_VER) && (_MSC_VER <= 1200) - Word40 L40_constant = L40_set( 0xc000000000); -#else - Word40 L40_constant = L40_set( 0xc000000000LL); -#endif - - if( var2 < 0) { - var2 = -var2; - L40_var_out = L40_shr( L40_var1, var2); - - #if (WMOPS) - multiCounter[currCounter].L40_shr--; - #endif /* if WMOPS */ - } - - else { - L40_var_out = L40_var1; - - for ( ; var2 > 0; var2--) { -#if defined(_MSC_VER) && (_MSC_VER <= 1200) - if( L40_var_out > 0x003fffffffff) { -#else - if( L40_var_out > 0x003fffffffffLL) { -#endif - L40_var_out = L40_OVERFLOW_OCCURED( L40_var_out); - break; - } - - else if ( L40_var_out < L40_constant) { - L40_var_out = L40_UNDERFLOW_OCCURED( L40_var_out); - break; - } - - else { - L40_var_out = L40_var_out << 1; - } - } - } - - #if (WMOPS) - multiCounter[currCounter].L40_set--; - multiCounter[currCounter].L40_shl++; - #endif /* if WMOPS */ - - BASOP_CHECK(); - - return( L40_var_out); -} - - -/***************************************************************************** - * - * Function Name : L40_shr - * - * Purpose : - * - * Arithmetically shifts right L40_var1 by var2 positions. - * - If var2 is positive, L40_var1 is shifted to the LSBits by (var2) - * positions with extension of the sign bit. - * - If var2 is negative, L40_var1 is shifted to the MSBits by (-var2) - * positions. - * Calls the macro L40_UNDERFLOW_OCCURED() in case of underflow on 40-bit. - * Calls the macro L40_OVERFLOW_OCCURED() in case of overflow on 40-bit. - * - * Complexity weight : 1 - * - * Inputs : - * - * L40_var1 40 bit long signed integer (Word40) whose value falls in the - * range : MIN_40 <= L40_var1 <= MAX_40. - * - * var2 16 bit short signed integer (Word16) whose value falls in - * the range : MIN_16 <= var2 <= MAX_16. - * - * Outputs : - * - * none - * - * Return Value : - * - * L40_var_out 40 bit long signed integer (Word40) whose value falls in - * the range : MIN_40 <= L40_var_out <= MAX_40. - * - *****************************************************************************/ -static __inline Word40 L40_shr( Word40 L40_var1, Word16 var2) { - Word40 L40_var_out; - - if( var2 < 0) { - var2 = -var2; - L40_var_out = L40_shl ( L40_var1, var2); - - #if (WMOPS) - multiCounter[currCounter].L40_shl--; - #endif /* if WMOPS */ - - } else { - L40_var_out = L40_var1 >> var2; - - } - - #if (WMOPS) - multiCounter[currCounter].L40_shr++; - #endif /* if WMOPS */ - - return( L40_var_out); -} - -/* end of file */ diff --git a/src/libs/libevs/basic_op/enh40.h b/src/libs/libevs/basic_op/enh40.h deleted file mode 100755 index b3520e84..00000000 --- a/src/libs/libevs/basic_op/enh40.h +++ /dev/null @@ -1,44 +0,0 @@ -/* - =========================================================================== - File: ENH40.H v.2.3 - 30.Nov.2009 - =========================================================================== - - ITU-T STL BASIC OPERATORS - - 40-BIT ARITHMETIC OPERATORS - - History: - 07 Nov 04 v2.0 Incorporation of new 32-bit / 40-bit / control - operators for the ITU-T Standard Tool Library as - described in Geneva, 20-30 January 2004 WP 3/16 Q10/16 - TD 11 document and subsequent discussions on the - wp3audio@yahoogroups.com email reflector. - - March 06 v2.1 Changed to improve portability. - - 31 Mar 15 v2.1E Removal of operators not used in the EVS codec. - - ============================================================================ -*/ - - -#ifndef _ENH40_H -#define _ENH40_H - -#include "stl.h" - - /***************************************************************************** - * - * Prototypes for enhanced 40 bit arithmetic operators - * - *****************************************************************************/ - -void Mpy_32_16_ss( Word32 L_var1, Word16 var2, Word32 *L_varout_h, UWord16 *varout_l); -void Mpy_32_32_ss( Word32 L_var1, Word32 L_var2, Word32 *L_varout_h, UWord32 *L_varout_l); - -#endif /*_ENH40_H*/ - - -/* end of file */ - - diff --git a/src/libs/libevs/basic_op/enhUL32.cpp b/src/libs/libevs/basic_op/enhUL32.cpp deleted file mode 100755 index 8750338b..00000000 --- a/src/libs/libevs/basic_op/enhUL32.cpp +++ /dev/null @@ -1,430 +0,0 @@ -/* - =========================================================================== - File: ENHUL32.C v.0.5 - 21.March.2014 - =========================================================================== - - ENHANCED UNSIGNED 32-BIT ARITHMETIC OPERATORS - History: - - ============================================================================ -*/ - - /***************************************************************************** - * - * Enhanced Unsigned 32 bit operators : - * see complete list in .h file - * - *****************************************************************************/ - -/***************************************************************************** - * - * Include-Files - * - *****************************************************************************/ -#include -#include -#include "stl.h" -#include "enhUL32.h" - - -#if (WMOPS) -extern BASIC_OP multiCounter[MAXCOUNTERS]; -extern int currCounter; -#endif /* if WMOPS */ - - -/***************************************************************************** - * - * Constants and Globals - * - *****************************************************************************/ - - -/***************************************************************************** - * - * Functions - * - *****************************************************************************/ -#ifdef ENHUL32 - -/*___________________________________________________________________________ - | | - | Function Name : UL_deposit_l | - | | - | Purpose : | - | | - | Deposit the 16 bit var1 into the 16 LS bits of the 32 bit output. The | - | 16 MS bits of the output are not sign extended. | - | | - |___________________________________________________________________________ */ - -UWord32 UL_deposit_l(UWord16 uvar){ - UWord32 UL_result; - UL_result = (UWord32)uvar; /* no sign extension*/ -#if (WMOPS) - multiCounter[currCounter].L_deposit_l++; -#endif - return (UL_result); -} - - -/*___________________________________________________________________________ - | | - | Function Name : norm_ul | - | | - | Purpose : | - | | - | Produces the number of left shifts needed to normalize the 32 bit varia-| - | ble UL_var1 for positive values on the interval with minimum of | - | 0 and maximum of 0xffffffff, ; in order to normalize the | - | result, the following operation must be done : | - | | - | norm_UL_var1 = UL_lshl(UL_var1, norm_ul(UL_var1)). | - | | - | Complexity weight : 1 | - | | - | Inputs : | - | | - | UL_var1 | - | 32 bit long unsigned integer (UWord32) whose value falls in the | - | range : 0x0000 0000 <= var1 <= 0xffff ffff. | - | | - | Outputs : | - | | - | none | - | | - | Return Value : | - | | - | var_out | - | 16 bit short signed integer (Word16) whose value falls in the | - | range : 0x0000 0000 <= var_out <= 0x0000 001f. (0..31d) | - |___________________________________________________________________________| -*/ -Word16 norm_ul( UWord32 UL_var1) -{ - Word16 var_out; - - if (UL_var1 == 0) - { - var_out = 0; - } - else - { - /* simply test shift up until highest bit is set */ - for (var_out = 0; UL_var1 < (UWord32) 0x80000000U; var_out++) - { - UL_var1 <<= 1; - } - } - -#if (WMOPS) - multiCounter[currCounter].norm_l++; /* now new counter added for UL_ */ -#endif - return (var_out); -} - - -/*___________________________________________________________________________ - | | - | Function Name : UL_addNs | - | | - | Purpose : | - | | - | 32 bits addition of the two unsigned 32 bits variables | - | (L_var1+L_var2) with overflow control, but without saturation | - | - | Outputs : | - | *wrap = 1 if wrap occured, otherwize 0 | - | - | Return Value : - | UL_var3 = modulo(UL_var1+UL_var2,32) - |___________________________________________________________________________| -*/ - -UWord32 UL_addNs(UWord32 UL_var1, UWord32 UL_var2, UWord16 * wrap ) -{ - UWord32 UL_var3; - - /* STL Overflow flag is not updated */ - - UL_var3 = UL_var1 + UL_var2; /* 32bit wrap may occur, like in C */ - - if ( ( ((UWord64)UL_var1 + (UWord64)UL_var2) ) > ((UWord64) maxUWord32 ) ) - { - *wrap = 1; /* wrapped output */ - } - else - { - *wrap = 0; - } - -#if WMOPS - multiCounter[currCounter].L_add++; /* now new counter added for UL_ */ -#endif - return UL_var3; -} - -/*___________________________________________________________________________ - | | - | Function Name : UL_subNs | - | | - | Purpose : | - | | - | 32 bits subtraction of the two unsigned 32 bits variables | - | (L_var1-L_var2) with overflow control, but without saturation | - | - | Outputs : | - | *sgn = 1 if wrap (to "negative" occured, otherwise 0 | - | - | Return Value : - | UL_var3 = modulo(UL_var1-UL_var2,32) - |___________________________________________________________________________| -*/ - -UWord32 UL_subNs(UWord32 UL_var1, UWord32 UL_var2, UWord16 * sgn) -{ - UWord32 UL_var3; - - UL_var3 = UL_var1 - UL_var2; /*wrap may occur, like in C */ - if (UL_var1 >= UL_var2) - { - *sgn = 0; - } - else - { - *sgn = 1; /* "negative" , wrapped output */ - } - -#if WMOPS - multiCounter[currCounter].L_sub++; /* now new counter added for UL_ */ -#endif - return UL_var3; -} - - - - -/***************************************************************************** - * - * Function Name : Mpy_32_16_uu - * - * Purpose : - * - * Multiplies the 2 unsigned values UL_var1 and uvar2 - * with saturation control on 48-bit.( does not happen for unsigned) - * The operation is performed in fractional mode : - * - UL_var1 is supposed to be in Q32 format. - * - var2 is supposed to be in Q16 format. - * - The result is produced in Q48 format : UL_varout_h points to the - * 32 MSBits while varout_l points to the 16 LSBits. - * - * Complexity weight : 2 - * - * Inputs : - * - * UL_var1 32 bit long unsigned integer (UWord32) whose value falls in - * the range : 0x0000 0000 <= L_var1 <= 0xffff ffff. - * - * var2 16 bit short unsigned integer (UWord16) whose value falls in - * the range : 0x0000 <= var2 <= 0x0000 ffff. - * - * Outputs : - * - * *UL_varout_h 32 bit long unsigned integer (UWord32) whose value falls in - * the range : 0x0000 0000 <= UL_varout_h <= 0xffff ffff. - * - * *varout_l 16 bit short unsigned integer (UWord16) whose value falls in - * the range : 0x0000 0000 <= varout_l <= 0x0000 ffff. - * - * Return Value : - * - * none - * - *****************************************************************************/ -void Mpy_32_16_uu( UWord32 UL_var1, UWord16 uvar2, UWord32 *UL_varout_h, UWord16 *varout_l) { - UWord64 UL64_var1; - - /* 4294967295 * 65535 < 281474976710655 */ - /* (uint64(2)^16-1 )*(uint64(2)^32-1) < (uint64(2)^(16+32)-1) */ - { - UL64_var1 = ( UWord64) UL_var1 * ( UWord64)uvar2 ; - - *varout_l = ( UWord16)( UL64_var1 ); - - *UL_varout_h = (UWord32)(UL64_var1>>16); - } - - #if (WMOPS) - multiCounter[currCounter].Mpy_32_16_ss++; /* now new counter added for UL_ */ - #endif /* if WMOPS */ - - return; -} - - -/***************************************************************************** - * - * Function Name : Mpy_32_32_uu - * - * Purpose : - * - * Multiplies the 2 unsigned values UL_var1 and UL_var2 - * with saturation control on 64-bit. (not needed for unsigned) - * The operation is performed in fractional mode : - * - UL_var1 and UL_var2 are supposed to be in Q32 format. - * - The result is produced in Q64 format : UL_varout_h points to the - * 32 MSBits while UL_varout_l points to the 32 LSBits. - * - * Complexity weight : 4 - * - * Inputs : - * - * UL_var1 32 bit long unsigned integer (UWord32) whose value falls in the - * range : 0x0000 0000 <= L_var1 <= 0xffff ffff. - * - * UL_var2 32 bit long unsigned integer (UWord32) whose value falls in the - * range : 0x0000 0000 <= L_var2 <= 0xffff ffff. - * - * Outputs : - * - * *UL_varout_h 32 bit long signed integer (Word32) whose value falls in - * the range : 0x0000 0000 <= UL_varout_h <= 0xffff ffff. - * - * *UL_varout_l 32 bit short unsigned integer (UWord32) whose value falls in - * the range : 0x0000 0000 <= UL_varout_l <= 0xffff ffff. - * - * - * Return Value : - * - * none - * - *****************************************************************************/ -void Mpy_32_32_uu( UWord32 UL_var1, UWord32 UL_var2, UWord32 *UL_varout_h, UWord32 *UL_varout_l) -{ - UWord64 UL64_var1; - - /* (uint64(2)^32-1 )*(uint64(2)^32-1) < (uint64(2)^(32+32)-1) */ - { - UL64_var1 = ((UWord64) UL_var1)*((UWord64) UL_var2); - *UL_varout_h = (UWord32)(UL64_var1>>32); - *UL_varout_l = (UWord32)(UL64_var1); - } - #if (WMOPS) - multiCounter[currCounter].Mpy_32_32_ss++; /* now new counter added for UL_ */ - #endif /* if WMOPS */ - - return; -} - -/***************************************************************************** - * - * Function Name : UL_Mpy_32_32 - * - * Purpose : - * - * Multiplies the 2 unsigned values UL_var1 and UL_var2 - * and returns the lower 32 bits, without saturation control. - * - * - UL_var1 and UL_var2 are supposed to be in Q32 format. - * - The result is produced in Q64 format, (the 32 LSBits. ) - * - * operates like a regular 32-by-32 bit unsigned int multiplication in ANSI-C. - * UWord32) = (unsigned int)*(unsigned int); - * - * - * Complexity weight : 2 - * - * Inputs : - * - * UL_var1 32 bit long unsigned integer (UWord32) whose value falls in the - * range : 0x0000 0000 <= UL_var1 <= 0xffff ffff. - * - * UL_var2 32 bit long unsigned integer (UWord32) whose value falls in the - * range : 0x0000 0000 <= UL_var2 <= 0xffff ffff. - * - * Outputs : - * - * Return Value : - * *UL_varout_l 32 bit short unsigned integer (UWord32) whose value falls in - * the range : 0x0000 0000 <= UL_varout_l <= 0xffff ffff. - * - * none - * - *****************************************************************************/ -UWord32 UL_Mpy_32_32( UWord32 UL_var1, UWord32 UL_var2) -{ - UWord32 UL_varout_l; - -#define MASK32 0xFFFFFFFFU - /* MASK32 may be needed in case Hardware is using larger than 32 bits for UWord32 type) */ - UL_varout_l = (UL_var1&MASK32)*(UL_var2&MASK32); - UL_varout_l = (UL_varout_l&MASK32); -#undef MASK32 - - -#if (WMOPS) - multiCounter[currCounter].Mpy_32_16_ss++; /* now new counters added for UL_ ops*/ -#endif /* if WMOPS */ - - return UL_varout_l; -} - -#ifdef STL_TYPECASTS -/* (Reuse of existing signed STL "L" operators) with - typecasting to make the resulting "UL" code a lot cleaner and more readable. */ - -UWord32 UL_lshl( UWord32 UL_var1, Word16 var2) { - return( (UWord32)L_lshl( (Word32) UL_var1, var2)); -} - -UWord32 UL_lshr( UWord32 UL_var1, Word16 var2) { - return( (UWord32)L_lshr( (Word32) UL_var1, var2) ); -} - -UWord32 UL_and(UWord32 UL_var1, UWord32 UL_var2 ) -{ - return (UWord32) L_and((Word32)UL_var1,(Word32) UL_var2); -} - -UWord32 UL_or(UWord32 UL_var1, UWord32 UL_var2 ) -{ - return (UWord32) L_or((Word32)UL_var1,(Word32) UL_var2); -} - -UWord32 UL_xor(UWord32 UL_var1, UWord32 UL_var2 ) -{ - return (UWord32) L_xor((Word32)UL_var1,(Word32) UL_var2); -} - -UWord32 UL_deposit_h(UWord16 uvar1) -{ - return (UWord32) L_deposit_h((Word32)uvar1); -} - -UWord16 u_extract_h(UWord32 UL_var1) -{ - return (UWord16) extract_h((Word32)UL_var1); -} - -UWord16 u_extract_l(UWord32 UL_var1) -{ - return (UWord32)extract_l((Word32)UL_var1); -} - -/* enable convenient reuse of Non-saturating UL_subNs , UL_addNs while "D"iscarding the sgn/wrap output flags */ -UWord32 UL_subNsD(UWord32 UL_var1, UWord32 UL_var2 ) -{ - UWord16 dummy_sign; - return UL_subNs(UL_var1,UL_var2,&dummy_sign ); -} - -UWord32 UL_addNsD(UWord32 UL_var1, UWord32 UL_var2 ) -{ - UWord16 dummy_wrap; - return UL_addNs(UL_var1,UL_var2,&dummy_wrap ); -} -#endif - -#endif /* ENHUL32 */ - -/* end of file */ diff --git a/src/libs/libevs/basic_op/enhUL32.h b/src/libs/libevs/basic_op/enhUL32.h deleted file mode 100755 index f4bc820d..00000000 --- a/src/libs/libevs/basic_op/enhUL32.h +++ /dev/null @@ -1,82 +0,0 @@ -/* - =========================================================================== - File: ENHUL32.H v.0.5 - 19.Mar.2014 - =========================================================================== - - - ============================================================================ -*/ - - -#ifndef _ENHUL32_H -#define _ENHUL32_H - - -/***************************************************************************** - * - * Constants and Globals - * - *****************************************************************************/ -#define ENHUL32 /* all the enhanced unsigned operators */ -#define STL_TYPECASTS /* logical shift and bitwise manipulation functions */ - /* algorithmically exact to existing signed L_lshr and L_lshr */ -#include "stl.h" - - -#ifndef UWord64 -#define UWord64 unsigned long long /* for local use inside UL_Mpy_32_* */ -#endif - - - - -#if (WMOPS) -#include "count.h" -extern BASIC_OP multiCounter[MAXCOUNTERS]; /* existing signed counters are reused for unsigedn operators */ -extern int currCounter; -#endif /* if WMOPS */ - -/***************************************************************************** - * - * Prototypes for enhanced unsigned 32 bit arithmetic operators - * - *****************************************************************************/ -UWord32 UL_addNs(UWord32 a, UWord32 b, UWord16* wrap); -UWord32 UL_subNs(UWord32 a, UWord32 b, UWord16* sgn); - -UWord32 UL_Mpy_32_32(UWord32 a, UWord32 b); -void Mpy_32_32_uu( UWord32 a, UWord32 b, UWord32 *c_h, UWord32 *c_l); /* does not saturate */ -void Mpy_32_16_uu( UWord32 a, UWord16 b,UWord32 *c_h, UWord16 *c_l); /* does not saturate */ - -/* Other */ -Word16 norm_ul (UWord32 UL_var1); -UWord32 UL_deposit_l(UWord16); /* deposit low without sign extension ) */ - - -/***************************************************************************** - * - * Inline Functions - * - *****************************************************************************/ - -#ifdef STL_TYPECASTS -/* (Reuse of existing signed STL "L" operators) with - typecasting to make the resulting "UL" code a lot cleaner and more readable. */ -UWord32 UL_lshl( UWord32 UL_var1, Word16 var2); -UWord32 UL_lshr( UWord32 UL_var1, Word16 var2); -UWord32 UL_and(UWord32 UL_var1, UWord32 UL_var2 ); -UWord32 UL_or(UWord32 UL_var1, UWord32 UL_var2 ); -UWord32 UL_xor(UWord32 UL_var1, UWord32 UL_var2 ); -UWord32 UL_deposit_h(UWord16 uvar1); -UWord16 u_extract_h(UWord32 UL_var1); -UWord16 u_extract_l(UWord32 UL_var1); - -/* enable convenient reuse of Non-saturating UL_subNs , UL_addNs - while "D"iscarding the sgn/wrap output flags */ -UWord32 UL_subNsD(UWord32 UL_var1, UWord32 UL_var2 ); -UWord32 UL_addNsD(UWord32 UL_var1, UWord32 UL_var2 ); -#endif - -#endif /*_ENHUL32_H*/ - -/* end of file */ diff --git a/src/libs/libevs/basic_op/move.h b/src/libs/libevs/basic_op/move.h deleted file mode 100755 index 797d8570..00000000 --- a/src/libs/libevs/basic_op/move.h +++ /dev/null @@ -1,88 +0,0 @@ -/* - =========================================================================== - File: MOVE.H v.2.3 - 30.Nov.2009 - =========================================================================== - - ITU-T STL BASIC OPERATORS - - MOVE & MISC LEGACY OPERATORS - - History: - 07 Nov 04 v2.0 Incorporation of new 32-bit / 40-bit / control - operators for the ITU-T Standard Tool Library as - described in Geneva, 20-30 January 2004 WP 3/16 Q10/16 - TD 11 document and subsequent discussions on the - wp3audio@yahoogroups.com email reflector. - March 06 v2.1 Changed to improve portability. - - ============================================================================ -*/ - - -#ifndef _MOVE_H -#define _MOVE_H - - -#include "stl.h" - -#if (WMOPS) -extern BASIC_OP multiCounter[MAXCOUNTERS]; -extern int currCounter; -#endif /* if WMOPS */ - - -static __inline void move16( void) { -#if WMOPS - multiCounter[currCounter].move16++; -#endif /* if WMOPS */ -} - - - - - - -static __inline void move32( void) { -#if WMOPS - multiCounter[currCounter].move32++; -#endif /* if WMOPS */ -} - - - - - - -static __inline void test( void) { -#if WMOPS - multiCounter[currCounter].Test++; -#endif /* if WMOPS */ -} - - -static __inline void logic16( void) { -#if WMOPS - multiCounter[currCounter].Logic16++; -#endif /* if WMOPS */ -} - - -static __inline void logic32( void) { -#if WMOPS - multiCounter[currCounter].Logic32++; -#endif /* if WMOPS */ -} - - -/*-------- legacy ----------*/ -#define data_move() move16() -#define L_data_move() move32() -#define data_move_external() move16() -#define compare_zero() test() -/*-------- end legacy ----------*/ - - -#endif /* _MOVE_H */ - - -/* end of file */ diff --git a/src/libs/libevs/basic_op/stl.h b/src/libs/libevs/basic_op/stl.h deleted file mode 100755 index 740447c5..00000000 --- a/src/libs/libevs/basic_op/stl.h +++ /dev/null @@ -1,77 +0,0 @@ -/* - =========================================================================== - File: STL.H v.2.3 - 30.Nov.2009 - =========================================================================== - - ITU-T STL BASIC OPERATORS - - MAIN HEADER FILE - - History: - 07 Nov 04 v2.0 Incorporation of new 32-bit / 40-bit / control - operators for the ITU-T Standard Tool Library as - described in Geneva, 20-30 January 2004 WP 3/16 Q10/16 - TD 11 document and subsequent discussions on the - wp3audio@yahoogroups.com email reflector. - March 06 v2.1 Changed to improve portability. - 31 Mar 15 v2.1E Clarified usage of operators needed for the EVS codec. - - ============================================================================ -*/ - - -#ifndef _STL_H -#define _STL_H - -/* This is Defined right here, it should be put in an include file - * that is included from every file. So far, only "stl.h" fit this - * requirement as "options.h" and "options.h" are not included by - * all code files. Also, these definitions are not enclosed by - * #if DEBUG because in some files, "stl.h" is included before - * DEBUG had been defined. This would lead to these macros not - * being defined and the Stack Counting would be disabled for some - * files. The Stack Counting would still work but some functions - * would be missing from the tree. */ -extern int check_stack(const char*, const char*); -#define STACK_DEPTH_FCT_CALL (BASOP_push_wmops(__FUNCTION__), check_stack( __FILE__, __FUNCTION__)) -//#define STACK_DEPTH_FCT_RETURN (BASOP_pop_wmops(), check_stack("-"__FILE__, __FUNCTION__)) - -#include /* for size_t */ -extern void* check_alloc_in(const char*, const char *, size_t, size_t); -extern void check_alloc_out(void*); -extern void check_alloc_exit(void); - -//#define MALLOC_FCT_CALL(n1) check_alloc_in("m"##__FILE__, __FUNCTION__, n1, 0) -//#define CALLOC_FCT_CALL(n1, n2) check_alloc_in("c"##__FILE__, __FUNCTION__, n1, n2) -//#define FREE_FCT_CALL(ptr) check_alloc_out(ptr) - -/* both ALLOW_40bits and ALLOW_ENH_UL32 shall be enabled for the EVS codec. */ -#define ALLOW_40bits /* allow 32x16 and 32x32 multiplications */ -#define ALLOW_ENH_UL32 /* allow enhanced unsigned 32bit operators */ - - -#if (defined _MSC_VER || defined __GNUC__ ) -#include "typedef.h" -#include "basop32.h" -#include "count.h" -#include "move.h" -#include "control.h" -#include "enh1632.h" -#include "oper_32b.h" -#include "math_op.h" -#include "log2.h" - -#if defined (ALLOW_40bits) -#include "enh40.h" -#endif - -#if defined (ALLOW_ENH_UL32) -#include "enhUL32.h" -#endif - -#endif /* if (defined _MSC_VER || defined __CYGWIN__) */ - -#endif /* ifndef _STL_H */ - - -/* end of file */ diff --git a/src/libs/libevs/basic_op/typedefs.h b/src/libs/libevs/basic_op/typedefs.h deleted file mode 100755 index c3e19f71..00000000 --- a/src/libs/libevs/basic_op/typedefs.h +++ /dev/null @@ -1,205 +0,0 @@ -/* - =========================================================================== - File: TYPEDEFS.H v.2.3 - 30.Nov.2009 - =========================================================================== - - ITU-T STL BASIC OPERATORS - - NEW TYPE DEFINITION PROTOTYPES - - History: - 03 Nov 04 v2.0 Incorporation of new 32-bit / 40-bit / control - operators for the ITU-T Standard Tool Library as - described in Geneva, 20-30 January 2004 WP 3/16 Q10/16 - TD 11 document and subsequent discussions on the - wp3audio@yahoogroups.com email reflector. - - Editor comment : - This file is not yet used or validated since - ORIGINAL_TYPEDEF_H compilation flag is defined in - typedef.h. This file is incorporated for future - reference / usage. - - ============================================================================ -*/ - - -/****************************************************************************** - * - * File : typedefs.h - * Description : Definition of platform independent data - * types and constants - * - * - * The following platform independent data types and corresponding - * preprocessor (#define) constants are defined: - * - * defined type meaning corresponding constants - * ---------------------------------------------------------- - * Char character (none) - * Bool boolean true, false - * Word8 8-bit signed minWord8, maxWord8 - * UWord8 8-bit unsigned minUWord8, maxUWord8 - * Word16 16-bit signed minWord16, maxWord16 - * UWord16 16-bit unsigned minUWord16, maxUWord16 - * Word32 32-bit signed minWord32, maxWord32 - * UWord32 32-bit unsigned minUWord32, maxUWord32 - * Float floating point minFloat, maxFloat - * - * - * The following compile switches are #defined: - * - * PLATFORM string indicating platform progam is compiled on - * possible values: "OSF", "PC", "SUN" - * - * OSF only defined if the current platform is an Alpha - * PC only defined if the current platform is a PC - * SUN only defined if the current platform is a Sun - * - * LSBFIRST is defined if the byte order on this platform is - * "least significant byte first" -> defined on DEC Alpha - * and PC, undefined on Sun - * - *****************************************************************************/ - - -#ifndef _TYPEDEFS_H -#define _TYPEDEFS_H "$Id $" - -/***************************************************************************** - * INCLUDE FILES - *****************************************************************************/ -#include -#include - - - -/***************************************************************************** - * DEFINITION OF CONSTANTS - *****************************************************************************/ -/* - ********* define char type - */ -typedef char Char; - -typedef unsigned short int UNS_Word16; /* 16 bit "register" (sw*) */ -#ifdef UNS_Word16 -#pragma message ("UNS_Word16 is defined but not officially part of STL2009@") -#endif -/* - ********* define 8 bit signed/unsigned types & constants - */ -#if SCHAR_MAX == 127 -typedef signed char Word8; -#define minWord8 SCHAR_MIN -#define maxWord8 SCHAR_MAX - -typedef unsigned char UWord8; -#define minUWord8 0 -#define maxUWord8 UCHAR_MAX -#else -#error cannot find 8-bit type -#endif - -/* - ********* define 16 bit signed/unsigned types & constants - */ -#if INT_MAX == 32767 -typedef int Word16; -#define minWord16 INT_MIN -#define maxWord16 INT_MAX -typedef unsigned int UWord16; -#define minUWord16 0 -#define maxUWord16 UINT_MAX -#elif SHRT_MAX == 32767 -typedef short Word16; -#define minWord16 SHRT_MIN -#define maxWord16 SHRT_MAX -typedef unsigned short UWord16; -#define minUWord16 0 -#define maxUWord16 USHRT_MAX -#else -#error cannot find 16-bit type -#endif - -/* Definition of Word40 was missing 10/06/2013 */ -#define Word40 long long - -/* - ********* define 32 bit signed/unsigned types & constants - */ -#if INT_MAX == 2147483647 -typedef int Word32; -#define minWord32 INT_MIN -#define maxWord32 INT_MAX -typedef unsigned int UWord32; -#define minUWord32 0 -#define maxUWord32 UINT_MAX -#elif LONG_MAX == 2147483647 -typedef long Word32; -#define minWord32 LONG_MIN -#define maxWord32 LONG_MAX -typedef unsigned long UWord32; -#define minUWord32 0 -#define maxUWord32 ULONG_MAX -#else -#error cannot find 32-bit type -#endif - -/* - ********* define floating point type & constants - */ -/* use "if 0" below if Float should be double; - use "if 1" below if Float should be float - */ -typedef double Float; -#define maxFloat DBL_MAX -#define minFloat DBL_MIN - -/* - ********* define complex type - */ -typedef struct { - Float r; /* real part */ - Float i; /* imaginary part */ -} CPX; - -/* - ********* define boolean type - */ -typedef int Bool; -#define false 0 -#define true 1 - -/* - ********* Check current platform - */ -#if defined(__MSDOS__) -#define PC -#define PLATFORM "PC" -#define LSBFIRST -#elif defined(__osf__) -#define OSF -#define PLATFORM "OSF" -#define LSBFIRST -#elif defined(__sun__) || defined(__sun) -#define SUN -#define PLATFORM "SUN" -#undef LSBFIRST -#elif defined(linux) && defined(i386) -#define PC -#define PLATFORM "PC" -#define LSBFIRST -#else -/*#error "can't determine architecture; adapt typedefs.h to your platform"*/ -/* for MSVC 2008 10/06/2013 */ -#define PC -#define PLATFORM "PC" -#define LSBFIRST -#endif - - -#endif /* ifndef _TYPEDEFS_H */ - - -/* end of file */ diff --git a/src/libs/libevs/lib_com/ACcontextMapping.cpp b/src/libs/libevs/lib_com/ACcontextMapping.cpp old mode 100755 new mode 100644 index 93efb270..dae44216 --- a/src/libs/libevs/lib_com/ACcontextMapping.cpp +++ b/src/libs/libevs/lib_com/ACcontextMapping.cpp @@ -1,81 +1,73 @@ /*==================================================================================== - EVS Codec 3GPP TS26.442 Apr 03, 2018. Version 12.11.0 / 13.6.0 / 14.2.0 + EVS Codec 3GPP TS26.443 Nov 13, 2018. Version 12.11.0 / 13.7.0 / 14.3.0 / 15.1.0 ====================================================================================*/ -#include -#include -#include -#include #include "options.h" -#include "basop_util.h" -#include "cnst_fx.h" -#include "prot_fx.h" -#include "rom_com_fx.h" -#include "stl.h" +#include "cnst.h" +#include "prot.h" -/* Returns: index of next coefficient */ -Word16 get_next_coeff_mapped( - Word16 ii[2], /* i/o: coefficient indexes */ - Word16 *pp, /* o : peak(1)/hole(0) indicator */ - Word16 *idx, /* o : index in unmapped domain */ + +/*-------------------------------------------------------------------* +* get_next_coeff_mapped() +* +* +*-------------------------------------------------------------------*/ + +int get_next_coeff_mapped( /* o : index of next coefficient */ + int ii[2], /* i/o: coefficient indexes */ + int *pp, /* o : peak(1)/hole(0) indicator */ + int *idx, /* o : index in unmapped domain */ CONTEXT_HM_CONFIG *hm_cfg /* i : HM configuration */ ) { - Word16 p; + unsigned int p; - p = s_and(sub(ii[1], hm_cfg->numPeakIndices), sub(hm_cfg->indexBuffer[ii[1]], hm_cfg->indexBuffer[ii[0]])); - if (p > 0) - { - p = 0; - move16(); - } - if (p < 0) - { - p = 1; - move16(); - } + p = (ii[1] - hm_cfg->numPeakIndices) & (hm_cfg->indexBuffer[ii[1]] - hm_cfg->indexBuffer[ii[0]]); + p >>= sizeof(p)*8-1; *pp = p; - move16(); *idx = ii[p]; - move16(); - ii[p] = add(ii[p], 1); - move16(); + ii[p]++; + return hm_cfg->indexBuffer[*idx]; } -/* Returns: index of next coefficient */ -Word16 get_next_coeff_unmapped( - Word16 ii[2], /* i/o: coefficient indexes */ - Word16 *pp, /* o : peak(1)/hole(0) indicator */ - Word16 *idx, /* o : index in unmapped domain */ - CONTEXT_HM_CONFIG *hm_cfg /* i : HM configuration */ + +/*-------------------------------------------------------------------* +* get_next_coeff_unmapped() +* +* +*-------------------------------------------------------------------*/ + +int get_next_coeff_unmapped(/* o : index of next coefficient */ + int *ii, /* i/o: coefficient indexes */ + int *idx /* o : index in unmapped domain */ ) { - (void)pp; - (void)hm_cfg; + *idx = *ii; + (*ii)++; - *idx = ii[0]; - move16(); - ii[0] = add(ii[0], 1); - move16(); return *idx; } -Word16 update_mixed_context(Word16 ctx, Word16 a) +/*-------------------------------------------------------------------* +* update_mixed_context() +* +* +*-------------------------------------------------------------------*/ + +int update_mixed_context( + int ctx, + int a +) { - Word32 t32; - Word16 t=0; /* initialize just to avoid compiler warning */ + int t; - t32 = L_mac0(1-13, s_and(a, ~1), add(shr(a, 2), 1)); - if (t32 <= 0) + t = 1-13 + (a & ~1)*((a>>2)+1); + + if (t > 0) { - t = extract_l(t32); + t = min((a>>3), 2); } - a = shr(a, 3); - if (t32 > 0) - { - t = s_min(a, 2); - } - return add(shl(s_and(ctx, 0xf), 4), add(t, 13)); + + return (ctx & 0xf) * 16 + t + 13; } - diff --git a/src/libs/libevs/lib_com/ari.cpp b/src/libs/libevs/lib_com/ari.cpp old mode 100755 new mode 100644 index ca641e89..c95c1961 --- a/src/libs/libevs/lib_com/ari.cpp +++ b/src/libs/libevs/lib_com/ari.cpp @@ -1,57 +1,39 @@ /*==================================================================================== - EVS Codec 3GPP TS26.442 Apr 03, 2018. Version 12.11.0 / 13.6.0 / 14.2.0 + EVS Codec 3GPP TS26.443 Nov 13, 2018. Version 12.11.0 / 13.7.0 / 14.3.0 / 15.1.0 ====================================================================================*/ +#include #include +#include "cnst.h" +#include "prot.h" +#include "stat_com.h" #include "assert.h" -#include "prot_fx.h" -#include "basop_mpy.h" -#include "cnst_fx.h" -#include "stl.h" +#include "basop_util.h" -/** - * \brief 31x16 Bit multiply (x*y) - * - * \param[i] xh high part, bit [30..15] - * \param[i] xl low part, 15 LSBits - * \param[i] y - * - * \return x*y - */ -Word32 L_multi31x16_X2(Word16 xh, Word16 xl, Word16 y) -{ - Word32 z; +#ifndef int32 +#define int32 int +#endif - z = L_shl(L_mult0(xh,y),15); - z = L_mac0(z,xl,y); - return z; -} /*--------------------------------------------------------------- Ari 14 bits common routines -------------------------------------------------------------*/ /** - * \brief Integer Multiply + * \brief Integer Multiply * * \param[i] r * \param[i] c * * \return r*c */ -Word32 mul_sbc_14bits(Word32 r, Word16 c) +long mul_sbc_14bits(long r,long c) { - Word32 ret; + long temp; + /*function in line*/ + temp = (((int32) r)*((int32) c))>>stat_bitsnew; + return temp; - - /* - temp = (((int32) r)*((int32) c))>>stat_bitsnew; - */ - assert(stat_bitsnew == 14); - ret = Mpy_32_16_1(L_shl(r,15-stat_bitsnew), c); - - /*assert( (((int) r)*((int) c))>>stat_bitsnew == ret);*/ - - return (ret); + /*function in line*/ } diff --git a/src/libs/libevs/lib_com/ari_hm.cpp b/src/libs/libevs/lib_com/ari_hm.cpp old mode 100755 new mode 100644 index a99bd910..41b582c3 --- a/src/libs/libevs/lib_com/ari_hm.cpp +++ b/src/libs/libevs/lib_com/ari_hm.cpp @@ -1,211 +1,196 @@ /*==================================================================================== - EVS Codec 3GPP TS26.442 Apr 03, 2018. Version 12.11.0 / 13.6.0 / 14.2.0 + EVS Codec 3GPP TS26.443 Nov 13, 2018. Version 12.11.0 / 13.7.0 / 14.3.0 / 15.1.0 ====================================================================================*/ - -#include -#include -#include #include +#include +#include "cnst.h" #include "stl.h" -#include "cnst_fx.h" #include "basop_util.h" -#include "rom_com_fx.h" -#include "prot_fx.h" +#include "prot.h" +#include "rom_com.h" + + +/*-------------------------------------------------------------------* + * UnmapIndex() + * + * + *-------------------------------------------------------------------*/ void UnmapIndex( - Word16 PeriodicityIndex, - Word16 Bandwidth, - Word16 LtpPitchLag, - Word8 SmallerLags, - Word16 *FractionalResolution, - Word32 *Lag) + int PeriodicityIndex, + int Bandwidth, + short LtpPitchLag, + int SmallerLags, + int *FractionalResolution, + int *Lag) { - Word16 LtpPitchIndex, Multiplier; - Word16 Lag16; - - test(); - IF ((LtpPitchLag > 0) && (s_and(PeriodicityIndex, kLtpHmFlag) != 0)) + if ((LtpPitchLag > 0) && (PeriodicityIndex & kLtpHmFlag)) { - LtpPitchIndex = shr(PeriodicityIndex, 9); - Multiplier = s_and(PeriodicityIndex, 0xff); - + int LtpPitchIndex, Multiplier; + LtpPitchIndex = PeriodicityIndex >> 9; + Multiplier = PeriodicityIndex & 0xff; assert(0 <= LtpPitchIndex && LtpPitchIndex <= 16); assert(1 <= Multiplier && Multiplier <= (1 << NumRatioBits[Bandwidth][LtpPitchIndex])); - *FractionalResolution = kLtpHmFractionalResolution; - move16(); - *Lag = L_shr(L_mult0(LtpPitchLag, Ratios[Bandwidth][LtpPitchIndex][Multiplier-1]), 8); - move32(); + *Lag = (LtpPitchLag * (int)(4 * Ratios[Bandwidth][LtpPitchIndex][Multiplier-1])) >> 2; } - ELSE + else { - IF (sub(PeriodicityIndex, 16) < 0) + if (PeriodicityIndex < 16) { *FractionalResolution = 3; - move16(); - Lag16 = add(PeriodicityIndex, GET_ADJ2(0, 6, 3)); + *Lag = PeriodicityIndex + GET_ADJ(0, 6); } - ELSE IF (sub(PeriodicityIndex, 80) < 0) + else if (PeriodicityIndex < 80) { *FractionalResolution = 4; - move16(); - Lag16 = add(PeriodicityIndex, GET_ADJ2(16, 8, 4)); + *Lag = PeriodicityIndex + GET_ADJ(16, 8); } - ELSE IF (sub(PeriodicityIndex, 208) < 0) + else if (PeriodicityIndex < 208) { *FractionalResolution = 3; - move16(); - Lag16 = add(PeriodicityIndex, GET_ADJ2(80, 12, 3)); + *Lag = PeriodicityIndex + GET_ADJ(80, 12); } - ELSE { - test(); - IF (sub(PeriodicityIndex, 224) < 0 || SmallerLags != 0) - { - *FractionalResolution = 1; - move16(); - Lag16 = add(PeriodicityIndex, GET_ADJ2(208, 28, 1)); - } - ELSE { - *FractionalResolution = 0; - move16(); - Lag16 = add(PeriodicityIndex, GET_ADJ2(224, 188, 0)); - } + else if (PeriodicityIndex < 224 || SmallerLags) + { + *FractionalResolution = 1; + *Lag = PeriodicityIndex + GET_ADJ(208, 28); + } + else + { + *FractionalResolution = 0; + *Lag = PeriodicityIndex + GET_ADJ(224, 188); } - *Lag = L_deposit_l(Lag16); } + + return; } +/*-------------------------------------------------------------------* + * ConfigureContextHm() + * + * + *-------------------------------------------------------------------*/ + void ConfigureContextHm( - Word16 NumCoeffs, /* (I) Number of coefficients */ - Word16 TargetBits, /* (I) Target bit budget (excl. Done flag) */ - Word16 PeriodicityIndex, /* (I) Pitch related index */ - Word16 LtpPitchLag, /* (I) TCX-LTP pitch in F.D. */ + int NumCoeffs, /* (I) Number of coefficients */ + int TargetBits, /* (I) Target bit budget (excl. Done flag) */ + int PeriodicityIndex, /* (I) Pitch related index */ + short LtpPitchLag, /* (I) TCX-LTP pitch in F.D. */ CONTEXT_HM_CONFIG *hm_cfg /* (O) Context-based harmonic model configuration */ ) { - Word8 Bandwidth, SmallerLags; - Word32 i, Limit, Lag; - Word16 j, Index, FractionalResolution; - Word16 *tmp; - + int Bandwidth, SmallerLags; + int i, Limit, Lag; + int j, Index, FractionalResolution; + int *tmp; Bandwidth = 0; - move16(); - if (sub(NumCoeffs, 256) >= 0) + if (NumCoeffs >= 256) { Bandwidth = 1; - move16(); } SmallerLags = 0; - move16(); - test(); - if ((sub(TargetBits, kSmallerLagsTargetBitsThreshold) <= 0) || (Bandwidth == 0)) + + if (TargetBits <= kSmallerLagsTargetBitsThreshold || Bandwidth == 0) { SmallerLags = 1; - move16(); } - UnmapIndex(PeriodicityIndex, - Bandwidth, - LtpPitchLag, - SmallerLags, - &FractionalResolution, &Lag); + UnmapIndex(PeriodicityIndex, Bandwidth, LtpPitchLag, SmallerLags, &FractionalResolution, &Lag ); /* Set up and fill peakIndices */ hm_cfg->peakIndices = hm_cfg->indexBuffer; tmp = hm_cfg->peakIndices; - Limit = L_shl(L_deposit_l(sub(NumCoeffs, 1)), FractionalResolution); - IF (L_sub(Lag, Limit) < 0) + Limit = (NumCoeffs - 1) << FractionalResolution; + + for (i=Lag; i> FractionalResolution; + *tmp++ = Index - 1; + *tmp++ = Index; + *tmp++ = Index + 1; } - hm_cfg->numPeakIndices = (Word16)(tmp - hm_cfg->indexBuffer); + hm_cfg->numPeakIndices = tmp - hm_cfg->indexBuffer; /* Set up and fill holeIndices */ hm_cfg->holeIndices = hm_cfg->indexBuffer + hm_cfg->numPeakIndices; tmp = hm_cfg->holeIndices; Index = 0; - move16(); - IF (hm_cfg->numPeakIndices > 0) + + for (j=0; jnumPeakIndices; j+=3) { - FOR (j=0; jnumPeakIndices; j+=3) - { - FOR (; IndexpeakIndices[j]; ++Index) - { - *tmp++ = Index; - move16(); - } - Index = add(Index, 3); /* Skip the peak */ - } - } - IF (sub(Index, NumCoeffs) < 0) - { - FOR (; IndexpeakIndices[j]; ++Index) { *tmp++ = Index; - move16(); } + Index += 3; /* Skip the peak */ } - hm_cfg->numHoleIndices = (Word16)(tmp - hm_cfg->holeIndices); - *tmp++ = NumCoeffs; - move16(); /* Add extremal element signaling the end of the buffer */ -} - -Word16 CountIndexBits( - Word16 Bandwidth, - Word16 PeriodicityIndex) -{ - Word16 result; - Word16 PeriodicityIndexS; - - result = 8; - move16(); - PeriodicityIndexS = shr(PeriodicityIndex, 9); - - if (s_and(PeriodicityIndex, kLtpHmFlag) != 0) + for (; IndexnumHoleIndices = tmp - hm_cfg->holeIndices; + /* Add extremal element signaling the end of the buffer */ + *tmp++ = NumCoeffs; - return result; + return; } +/*-------------------------------------------------------------------* + * CountIndexBits() + * + * + *-------------------------------------------------------------------*/ + +int CountIndexBits( + int Bandwidth, + int PeriodicityIndex) +{ + + if (PeriodicityIndex & kLtpHmFlag) + { + int LtpPitchIndex = PeriodicityIndex >> 9; + return NumRatioBits[Bandwidth][LtpPitchIndex]; + } + return 8; +} + + +/*-------------------------------------------------------------------* + * tcx_hm_render() + * + * + *-------------------------------------------------------------------*/ int tcx_hm_render( - Word32 lag, /* i: pitch lag Q0 */ - Word16 fract_res, /* i: fractional resolution of the lag Q0 */ - Word16 p[] /* o: harmonic model Q13 */ + int lag, /* i: pitch lag */ + int fract_res, /* i: fractional resolution of the lag */ + float LtpGain, /* i: LTP gain */ + Word16 p[] /* o: harmonic model (Q13) */ ) { - Word16 k, tmp, height; - Word16 PeakDeviation; + int k; Word32 f0, tmp32; + Word16 height, PeakDeviation, tmp; /* Set up overall shape */ - f0 = L_shl(lag, sub(15, fract_res)); /* Q31 */ + (void)LtpGain; - tmp32 = Mpy_32_16_1(f0, -26474); + f0 = L_shl(lag, sub(15, fract_res)); /* Q15 */ + + tmp32 = Mpy_32_16(f0, -26474); tmp32 = L_shr_r(BASOP_Util_InvLog2(L_shl(tmp32, 7)), 2); tmp32 = L_sub(603979776L, tmp32); - tmp32 = L_add(L_add(tmp32, tmp32), Mpy_32_16_1(tmp32, 26214)); + tmp32 = L_add(L_add(tmp32, tmp32), Mpy_32_16(tmp32, 26214)); height = round_fx(tmp32); /* Q13 */ - tmp32 = Mpy_32_16_1(f0, -18910); + tmp32 = Mpy_32_16(f0, -18910); tmp32 = L_shr_r(BASOP_Util_InvLog2(L_shl(tmp32, 7)), 2); tmp32 = L_sub(1395864371L, tmp32); PeakDeviation = round_fx(tmp32); /* Q14 */ @@ -221,72 +206,65 @@ int tcx_hm_render( tmp = mult_r(tmp, tmp); /* Q15 */ } - tmp = div_s(13915, PeakDeviation); - tmp = mult_r(tmp, tmp); /* Q15 */ - /* Render the prototype peak */ p[kTcxHmParabolaHalfWidth] = height; - move16(); - FOR (k=1; k<=kTcxHmParabolaHalfWidth; ++k) + for (k=1; k<=kTcxHmParabolaHalfWidth; ++k) { - p[kTcxHmParabolaHalfWidth+k] = round_fx(Mpy_32_16_1(BASOP_Util_InvLog2(L_shl(L_mult0(i_mult2(negate(k),k), tmp),10)), height)); + p[kTcxHmParabolaHalfWidth+k] = round_fx(Mpy_32_16(BASOP_Util_InvLog2(L_shl(L_mult0(mult0(negate(k),k), tmp),10)), height)); } /* Mirror */ - FOR (k=-kTcxHmParabolaHalfWidth; k<0; ++k) + for (k=-kTcxHmParabolaHalfWidth; k<0; ++k) { p[kTcxHmParabolaHalfWidth+k] = p[kTcxHmParabolaHalfWidth-k]; - move16(); } return 0; } + +/*-------------------------------------------------------------------* + * tcx_hm_modify_envelope() + * + * + *-------------------------------------------------------------------*/ + void tcx_hm_modify_envelope( - Word16 gain, /* i: HM gain Q11 */ - Word32 lag, /* i: pitch lag Q0 */ - Word16 fract_res, /* i: fractional resolution of the lag Q0 */ - Word16 p[], /* i: harmonic model Q13 */ - Word32 env[], /* i/o: envelope Q16 */ - Word16 L_frame /* i: number of spectral lines Q0 */ + Word16 gain, /* i: HM gain (Q11) */ + int lag, + int fract_res, + Word16 p[], /* i: harmonic model (Q13) */ + Word32 env[], /* i/o: envelope (Q16) */ + int L_frame /* i: number of spectral lines */ ) { - Word16 k, h, x, l1,l2, L_frame_m1, L_frame_for_loop; - Word16 inv_shape[2*kTcxHmParabolaHalfWidth+1]; + int k; + int h, x; + Word16 inv_shape[2*kTcxHmParabolaHalfWidth+1]; /* Q15 */ - IF ( gain == 0 ) + if (gain == 0) { return; } - FOR (k=0; k<2*kTcxHmParabolaHalfWidth+1; ++k) + for (k=0; k<2*kTcxHmParabolaHalfWidth+1; ++k) { - /* Q24 = Q11 * Q13; 512 = 1.0 in Q24 format */ - inv_shape[k] = div_s(512, add(512, mult_r(gain, p[k]))); - move16(); + inv_shape[k] = div_s(512, add(512, round_fx(L_mult(gain, p[k])))); } h = 1; - move16(); - k = extract_l(L_shr(lag,fract_res)); + k = lag >> fract_res; - L_frame_m1 = sub(L_frame,1); - L_frame_for_loop = add(L_frame,kTcxHmParabolaHalfWidth - 1); - - WHILE ( sub(k,L_frame_for_loop) <= 0 ) + while (k <= L_frame + kTcxHmParabolaHalfWidth - 1) { - l1 = s_max(0, sub(k,kTcxHmParabolaHalfWidth)); - l2 = s_min(add(k,kTcxHmParabolaHalfWidth), L_frame_m1); - FOR (x=l1; x<=l2; ++x) - { - env[x] = Mpy_32_16_1(env[x], inv_shape[x-k+kTcxHmParabolaHalfWidth]); - move32(); - } - h = add(h,1); - k = extract_l(L_shr(imult3216(lag,h),fract_res)); + for (x=max(0, k-kTcxHmParabolaHalfWidth); x<=min(k+kTcxHmParabolaHalfWidth, L_frame-1); ++x) + { + env[x] = Mpy_32_16(env[x], inv_shape[x-k+kTcxHmParabolaHalfWidth]); + } + ++h; + k = (h * lag) >> fract_res; } + return; } - - diff --git a/src/libs/libevs/lib_com/arith_coder.cpp b/src/libs/libevs/lib_com/arith_coder.cpp old mode 100755 new mode 100644 index 7699550f..831b443b --- a/src/libs/libevs/lib_com/arith_coder.cpp +++ b/src/libs/libevs/lib_com/arith_coder.cpp @@ -1,31 +1,35 @@ /*==================================================================================== - EVS Codec 3GPP TS26.442 Apr 03, 2018. Version 12.11.0 / 13.6.0 / 14.2.0 + EVS Codec 3GPP TS26.443 Nov 13, 2018. Version 12.11.0 / 13.7.0 / 14.3.0 / 15.1.0 ====================================================================================*/ -#include -#include -#include +#include #include - -#include "prot_fx.h" -#include "basop_util.h" #include "options.h" -#include "cnst_fx.h" -#include "stl.h" +#include "cnst.h" +#include "prot.h" +#include "basop_util.h" +#include "basop_proto_func.h" -/* Fixed point implementation of exp(negate()) */ -Word32 expfp( /* o: Q31 */ - Word16 x, /* i: mantissa Q-e */ - Word16 x_e) /* i: exponent Q0 */ + + + +/*-------------------------------------------------------* + * expfp() + * + * Fixed point implementation of exp() + *-------------------------------------------------------*/ + +Word16 expfp( /* o: Q15 */ + Word16 x, /* i: mantissa Q15-e */ + Word16 x_e) /* i: exponent Q0 */ { Word16 xi, xf, tmp; Word16 b0, b1, b2, b3; Word32 y, L_tmp; + assert(x <= 0); - assert(x > 0); - - L_tmp = L_shl(L_deposit_h(x), x_e); + L_tmp = L_negate(L_shl(L_deposit_h(x), sub(x_e, 15))); /* split into integer and fractional parts */ xi = round_fx(L_tmp); @@ -55,10 +59,10 @@ Word32 expfp( /* o: Q31 */ b2 = s_and(xi, 4); b3 = s_and(xi, 8); - if (b0 != 0) y = Mpy_32_16_1(y, 24109); /* exp(-1) in -1Q16 */ - if (b1 != 0) y = Mpy_32_16_1(y, 17739); /* exp(-2) in -2Q17 */ - if (b2 != 0) y = Mpy_32_16_1(y, 19205); /* exp(-4) in -5Q20 */ - if (b3 != 0) y = Mpy_32_16_1(y, 22513); /* exp(-8) in -11Q26 */ + if (b0 != 0) y = Mpy_32_16(y, 24109); /* exp(-1) in -1Q16 */ + if (b1 != 0) y = Mpy_32_16(y, 17739); /* exp(-2) in -2Q17 */ + if (b2 != 0) y = Mpy_32_16(y, 19205); /* exp(-4) in -5Q20 */ + if (b3 != 0) y = Mpy_32_16(y, 22513); /* exp(-8) in -11Q26 */ /* scaling: -1*b0 - 2*b1 -5*b2 -11*b3 */ y = L_shr(y, add(add(xi, shr(xi, 2)), shr(b3, 3))); @@ -67,22 +71,31 @@ Word32 expfp( /* o: Q31 */ if (shr(xi, 4) > 0) { y = L_deposit_l(0); + move16(); } - - return L_shl(y, 15); + return round_fx(L_shl(y, 15)); } -/* Fixed point implementation of pow(), where base is fixed point (16/16) and exponent a small *odd* integer + +/*-------------------------------------------------------* + * powfp_odd2() + * + * Fixed point implementation of pow(), where base is fixed point (16/16) and exponent a small *odd* integer + *-------------------------------------------------------*/ +/* * * Returns: *pout1 = ( (base/65536)^(2*exp - 1) ) * 65536 * *pout2 = ( (base/65536)^(2*exp + 1) ) * 65536 * * NOTE: This function must be in sync with ari_decode_14bits_pow() */ -void powfp_odd2(Word16 base, /* Q15 */ - Word16 exp, /* Q0 */ - Word16 *pout1, /* Q15 */ - Word16 *pout2) /* Q15 */ + +void powfp_odd2( + Word16 base, /* Q15 */ + Word16 exp, /* Q0 */ + Word16 *pout1, /* Q15 */ + Word16 *pout2 /* Q15 */ +) { /* this version is in sync with ari_enc_14bits_pow() * that is, we have to start multiplication from the largest power-of-two, in order to @@ -144,8 +157,10 @@ void powfp_odd2(Word16 base, /* Q15 */ *pout2 = out; move16(); + return; } + /*------------------------------------------------------------------------ * Function: tcx_arith_scale_envelope * @@ -167,12 +182,13 @@ void powfp_odd2(Word16 base, /* Q15 */ * NOTE: This function must be bit-exact on all platforms such that encoder * and decoder remain synchronized. *-------------------------------------------------------------------------*/ + void tcx_arith_scale_envelope( Word16 L_spec_core, /* i: number of lines to scale Q0 */ Word16 L_frame, /* i: number of lines Q0 */ Word32 env[], /* i: unscaled envelope Q16 */ Word16 target_bits, /* i: number of available bits Q0 */ - Word16 low_complexity, /* i: low-complexity flag Q0 */ + Word16 low_complexity, /* i: low-complexity Q0 */ Word16 s_env[], /* o: scaled envelope Q15-e */ Word16 *s_env_e /* o: scaled envelope exponent Q0 */ ) @@ -186,7 +202,6 @@ void tcx_arith_scale_envelope( Word16 mean_e, tmp, tmp2; - lob_bits = 0; move16(); hib_bits = 0; @@ -194,10 +209,10 @@ void tcx_arith_scale_envelope( /* Boosting to account for expected spectrum truncation (kMax) */ /* target_bits = (int)(target_bits * (1.2f - 0.00045f * target_bits + 0.00000025f * target_bits * target_bits)); */ - L_tmp = L_shr(Mpy_32_16_1(L_mult0(target_bits, target_bits), 17180), 6); /* Q15; 17180 -> 0.00000025f (Q36) */ + L_tmp = L_shr(Mpy_32_16(L_mult0(target_bits, target_bits), 17180), 6); /* Q15; 17180 -> 0.00000025f (Q36) */ L_tmp = L_sub(L_tmp, L_shr(L_mult0(target_bits, 30199), 11)); /* Q15; 30199 -> 0.00045f (Q26) */ L_tmp = L_add(L_tmp, 39322); /* Q15; 39322 -> 1.2f (Q15) */ - L_tmp = Mpy_32_16_1(L_tmp, target_bits); /* Q0 */ + L_tmp = Mpy_32_16(L_tmp, target_bits); /* Q0 */ assert(L_tmp < 32768); target_bits = extract_l(L_tmp); @@ -216,12 +231,12 @@ void tcx_arith_scale_envelope( } tmp = norm_s(L_frame); tmp = shl(div_s(8192, shl(L_frame, tmp)), sub(tmp, 7)); - mean = L_shr(Mpy_32_16_1(mean, tmp), 6); /* Q16 */ + mean = L_shr(Mpy_32_16(mean, tmp), 6); /* Q16 */ /* Rate dependent compensation to get closer to the target on average */ /* mean = (float)pow(mean, (float)L_frame / (float)target_bits * 0.357f); */ tmp = BASOP_Util_Divide1616_Scale(L_frame, target_bits, &tmp2); - tmp = mult_r(tmp, 11698/*0.357f Q15*/); + tmp = mult_r(tmp, FL2WORD16(0.357f)); mean = BASOP_Util_fPow(mean, 15, L_deposit_h(tmp), tmp2, &mean_e); /* Find first-guess scaling coefficient "scale" such that if "mean" is the @@ -231,23 +246,28 @@ void tcx_arith_scale_envelope( */ /* a = 2*2.71828183f*mean*mean; */ tmp = round_fx(mean); - a = L_mult(mult_r(tmp, 22268/*2.71828183f Q13*/), tmp); + a = L_mult(mult_r(tmp, FL2WORD16_SCALE(2.71828183f, 2)), tmp); a_e = add(shl(mean_e, 1), 3); /* b = (0.15f - (float)pow(2.0f, target_bits/(float)L_frame)) * mean; */ tmp = BASOP_Util_Divide1616_Scale(target_bits, L_frame, &tmp2); tmp = round_fx(BASOP_util_Pow2(L_deposit_h(tmp), tmp2, &tmp2)); - b_e = BASOP_Util_Add_MantExp(4915/*0.15f Q15*/, 0, negate(tmp), tmp2, &b); + b_e = BASOP_Util_Add_MantExp(FL2WORD16(0.15f), 0, negate(tmp), tmp2, &b); b = mult_r(b, round_fx(mean)); b_e = add(b_e, mean_e); /* scale = (-b + (float)sqrt(b*b - 4.0f*a*0.035f)) / (2.0f * a); */ - tmp = round_fx(BASOP_Util_Add_Mant32Exp(L_mult(b, b), shl(b_e, 1), Mpy_32_16_1(a, -4588/*-4.0f*0.035f Q15*/), a_e, &tmp2)); + tmp = round_fx(BASOP_Util_Add_Mant32Exp(L_mult(b, b), shl(b_e, 1), Mpy_32_16(a, FL2WORD16(-4.0f*0.035f)), a_e, &tmp2)); IF( tmp <= 0 ) { tmp = 0; - set16_fx(s_env, 0, L_frame); + + FOR( k=0; k 255, bit consumption is approx log2(2*e*s) * further, we use round(log2(x)) = floor(log2(x)+0.5) = floor(log2(x*sqrt(2))) */ /* a = 5.436564f * s; */ - L_tmp = Mpy_32_16_1(s, 31492/*5.436564f * 1.4142f Q12*/); /* Q13 */ + L_tmp = Mpy_32_16(s, FL2WORD16_SCALE(5.436564f * 1.4142f, 3)); /* Q13 */ bits = add(bits, sub(17, norm_l(L_tmp))); } } - IF (sub(bits, target_bits) <= 0) /* Bits leftover => scale is too small */ + IF (sub(bits, target_bits) <= 0) { + /* Bits leftover => scale is too small */ lob = scale; move16(); lob_bits = bits; @@ -334,17 +355,19 @@ void tcx_arith_scale_envelope( adjust = div_s(sub(hib_bits, target_bits), sub(hib_bits, lob_bits)); scale = add(mult_r(sub(lob, hib), adjust), hib); } - ELSE /* Initial scale adaptation */ + ELSE { + /* Initial scale adaptation */ /* adjust = 1.05f * target_bits / (float)bits; scale *= adjust; */ - adjust = mult_r(17203/*1.05f Q14*/, target_bits); + adjust = mult_r(FL2WORD16_SCALE(1.05f, 1), target_bits); adjust = BASOP_Util_Divide1616_Scale(adjust, bits, &tmp); scale = shl(mult_r(scale, adjust), add(1, tmp)); } } - ELSE /* Ran out of bits => scale is too large */ + ELSE { + /* Ran out of bits => scale is too large */ hib = scale; move16(); hib_bits = bits; @@ -355,13 +378,19 @@ void tcx_arith_scale_envelope( adjust = div_s(sub(hib_bits, target_bits), sub(hib_bits, lob_bits)); scale = add(mult_r(sub(lob, hib), adjust), hib); } - ELSE { /* Initial scale adaptation */ + ELSE + { /* Initial scale adaptation */ test(); IF( target_bits <= 0 || bits <= 0 ) /* safety check in case of bit errors */ { adjust = 0; move16(); - set16_fx( s_env, 0, L_frame ); + + FOR( k=0; k weighted envelope factor */ - Word16 gamma_uw, /* i: A_ind -> non-weighted envelope factor */ - Word32 env[] /* o: shaped signal envelope */ + Word16 preemph_fac, /* i: pre-emphasis factor */ + Word16 gamma_w, /* i: A_ind -> weighted envelope factor */ + Word16 gamma_uw, /* i: A_ind -> non-weighted envelope factor */ + Word32 env[] /* o: shaped signal envelope */ ) { Word16 k; @@ -431,15 +469,14 @@ void tcx_arith_render_envelope( Word16 gainlpc[FDNS_NPTS], gainlpc_e[FDNS_NPTS]; - /* Compute perceptual LPC envelope, transform it into freq.-domain gains */ - weight_a_fx( A_ind, tmpA, gamma_w, M ); - lpc2mdct( tmpA, M, NULL, NULL, gainlpc, gainlpc_e ); + basop_weight_a(A_ind, tmpA, gamma_w); + basop_lpc2mdct(tmpA, M, NULL, NULL, gainlpc, gainlpc_e); /* Add pre-emphasis tilt to LPC envelope, transform LPC into MDCT gains */ - E_LPC_a_weight_inv(A_ind, signal_env, gamma_uw, M); - E_LPC_a_add_tilt(signal_env, tmpA, preemph_fac, M); - lpc2mdct(tmpA, M+1, signal_env, signal_env_e, NULL, NULL); + basop_weight_a_inv(A_ind, signal_env, gamma_uw); + basop_E_LPC_a_add_tilt(signal_env, tmpA, preemph_fac); + basop_lpc2mdct(tmpA, M+1, signal_env, signal_env_e, NULL, NULL); /* Compute weighted signal envelope in perceptual domain */ FOR (k = 0; k < FDNS_NPTS; k++) @@ -451,15 +488,16 @@ void tcx_arith_render_envelope( } /* Adaptive low frequency emphasis */ - set32_fx(env, 0x10000, L_frame); + FOR (k = 0; k < L_frame; k++) + { + env[k] = 0x10000; + move32(); + } - AdaptLowFreqDeemph(env, 15, - 1, - gainlpc, gainlpc_e, - L_frame, NULL); + basop_PsychAdaptLowFreqDeemph(env, gainlpc, gainlpc_e, NULL); /* Scale from FDNS_NPTS to L_frame and multiply LFE gains */ - mdct_noiseShaping_interp(env, L_frame, signal_env, signal_env_e); + basop_mdct_noiseShaping_interp(env, L_frame, signal_env, signal_env_e); FOR (k=L_frame; k #include #include "stl.h" -#if (WMOPS) -extern BASIC_OP multiCounter[MAXCOUNTERS]; -extern int currCounter; -#endif - - /*___________________________________________________________________________ | | | Local Functions | @@ -203,9 +201,6 @@ static Word16 saturate (Word32 L_var1) else { var_out = extract_l (L_var1); -#if (WMOPS) - multiCounter[currCounter].extract_l--; -#endif } BASOP_CHECK(); @@ -255,9 +250,7 @@ Word16 add (Word16 var1, Word16 var2) L_sum = (Word32) var1 + var2; var_out = saturate (L_sum); -#if (WMOPS) - multiCounter[currCounter].add++; -#endif + return (var_out); } @@ -303,9 +296,7 @@ Word16 sub (Word16 var1, Word16 var2) L_diff = (Word32) var1 - var2; var_out = saturate (L_diff); -#if (WMOPS) - multiCounter[currCounter].sub++; -#endif + return (var_out); } @@ -357,12 +348,9 @@ Word16 abs_s (Word16 var1) } } -#if (WMOPS) - multiCounter[currCounter].abs_s++; -#endif - BASOP_CHECK(); + return (var_out); } @@ -412,10 +400,6 @@ Word16 shl (Word16 var1, Word16 var2) var2 = -16; var2 = -var2; var_out = shr (var1, var2); - -#if (WMOPS) - multiCounter[currCounter].shr--; -#endif } else { @@ -429,19 +413,12 @@ Word16 shl (Word16 var1, Word16 var2) else { var_out = extract_l (result); - -#if (WMOPS) - multiCounter[currCounter].extract_l--; -#endif } } -#if (WMOPS) - multiCounter[currCounter].shl++; -#endif - BASOP_CHECK(); + return (var_out); } @@ -490,10 +467,6 @@ Word16 shr (Word16 var1, Word16 var2) var2 = -16; var2 = -var2; var_out = shl (var1, var2); - -#if (WMOPS) - multiCounter[currCounter].shl--; -#endif } else { @@ -514,12 +487,9 @@ Word16 shr (Word16 var1, Word16 var2) } } -#if (WMOPS) - multiCounter[currCounter].shr++; -#endif - BASOP_CHECK(); + return (var_out); } @@ -572,9 +542,7 @@ Word16 mult (Word16 var1, Word16 var2) var_out = saturate (L_product); -#if (WMOPS) - multiCounter[currCounter].mult++; -#endif + return (var_out); } @@ -629,12 +597,9 @@ Word32 L_mult (Word16 var1, Word16 var2) L_var_out = MAX_32; } -#if (WMOPS) - multiCounter[currCounter].L_mult++; -#endif - BASOP_CHECK(); + return (L_var_out); } @@ -674,12 +639,9 @@ Word16 negate (Word16 var1) var_out = (var1 == MIN_16) ? MAX_16 : -var1; -#if (WMOPS) - multiCounter[currCounter].negate++; -#endif - BASOP_CHECK(); + return (var_out); } @@ -717,12 +679,9 @@ Word16 extract_h (Word32 L_var1) var_out = (Word16) (L_var1 >> 16); -#if (WMOPS) - multiCounter[currCounter].extract_h++; -#endif - BASOP_CHECK(); + return (var_out); } @@ -760,12 +719,9 @@ Word16 extract_l (Word32 L_var1) var_out = (Word16) L_var1; -#if (WMOPS) - multiCounter[currCounter].extract_l++; -#endif - BASOP_CHECK(); + return (var_out); } @@ -805,19 +761,14 @@ Word16 round_fx (Word32 L_var1) Word16 var_out; Word32 L_rounded; -BASOP_SATURATE_WARNING_OFF + BASOP_SATURATE_WARNING_OFF L_rounded = L_add (L_var1, (Word32) 0x00008000L); -BASOP_SATURATE_WARNING_ON + BASOP_SATURATE_WARNING_ON var_out = extract_h (L_rounded); -#if (WMOPS) - multiCounter[currCounter].L_add--; - multiCounter[currCounter].extract_h--; - multiCounter[currCounter].round++; -#endif - BASOP_CHECK(); + return (var_out); } @@ -866,14 +817,9 @@ Word32 L_mac (Word32 L_var3, Word16 var1, Word16 var2) L_product = L_mult (var1, var2); L_var_out = L_add (L_var3, L_product); -#if (WMOPS) - multiCounter[currCounter].L_mult--; - multiCounter[currCounter].L_add--; - multiCounter[currCounter].L_mac++; -#endif - BASOP_CHECK(); + return (L_var_out); } @@ -922,14 +868,9 @@ Word32 L_msu (Word32 L_var3, Word16 var1, Word16 var2) L_product = L_mult (var1, var2); L_var_out = L_sub (L_var3, L_product); -#if (WMOPS) - multiCounter[currCounter].L_mult--; - multiCounter[currCounter].L_sub--; - multiCounter[currCounter].L_msu++; -#endif - BASOP_CHECK(); + return (L_var_out); } @@ -983,12 +924,6 @@ Word32 L_macNs (Word32 L_var3, Word16 var1, Word16 var2) L_var_out = L_mult (var1, var2); L_var_out = L_add_c (L_var3, L_var_out); -#if (WMOPS) - multiCounter[currCounter].L_mult--; - multiCounter[currCounter].L_add_c--; - multiCounter[currCounter].L_macNs++; -#endif - /* BASOP_CHECK(); Do not check for overflow here, function produces the carry bit instead */ @@ -1045,15 +980,9 @@ Word32 L_msuNs (Word32 L_var3, Word16 var1, Word16 var2) L_var_out = L_mult (var1, var2); L_var_out = L_sub_c (L_var3, L_var_out); -#if (WMOPS) - multiCounter[currCounter].L_mult--; - multiCounter[currCounter].L_sub_c--; - multiCounter[currCounter].L_msuNs++; - -#endif - /* BASOP_CHECK(); Do not check for overflow here, function produces the carry bit instead */ + return (L_var_out); } @@ -1104,12 +1033,9 @@ Word32 L_add (Word32 L_var1, Word32 L_var2) } } -#if (WMOPS) - multiCounter[currCounter].L_add++; -#endif - BASOP_CHECK(); + return (L_var_out); } @@ -1160,12 +1086,9 @@ Word32 L_sub (Word32 L_var1, Word32 L_var2) } } -#if (WMOPS) - multiCounter[currCounter].L_sub++; -#endif - BASOP_CHECK(); + return (L_var_out); } @@ -1276,12 +1199,9 @@ Word32 L_add_c (Word32 L_var1, Word32 L_var2) Carry = carry_int; } -#if (WMOPS) - multiCounter[currCounter].L_add_c++; -#endif - /* BASOP_CHECK(); Do not check for overflow here, function produces the carry bit instead */ + return (L_var_out); } @@ -1335,9 +1255,6 @@ Word32 L_sub_c (Word32 L_var1, Word32 L_var2) if (L_var2 != MIN_32) { L_var_out = L_add_c (L_var1, -L_var2); -#if (WMOPS) - multiCounter[currCounter].L_add_c--; -#endif } else { @@ -1380,12 +1297,9 @@ Word32 L_sub_c (Word32 L_var1, Word32 L_var2) } } -#if (WMOPS) - multiCounter[currCounter].L_sub_c++; -#endif - /* BASOP_CHECK(); Do not check for overflow here, function produces the carry bit instead */ + return (L_var_out); } @@ -1424,12 +1338,9 @@ Word32 L_negate (Word32 L_var1) L_var_out = (L_var1 == MIN_32) ? MAX_32 : -L_var1; -#if (WMOPS) - multiCounter[currCounter].L_negate++; -#endif - BASOP_CHECK(); + return (L_var_out); } @@ -1483,9 +1394,7 @@ Word16 mult_r (Word16 var1, Word16 var2) } var_out = saturate (L_product_arr); -#if (WMOPS) - multiCounter[currCounter].mult_r++; -#endif + return (var_out); } @@ -1534,9 +1443,6 @@ Word32 L_shl (Word32 L_var1, Word16 var2) var2 = -32; var2 = -var2; L_var_out = L_shr (L_var1, var2); -#if (WMOPS) - multiCounter[currCounter].L_shr--; -#endif } else { @@ -1561,12 +1467,10 @@ Word32 L_shl (Word32 L_var1, Word16 var2) L_var_out = L_var1; } } - #if (WMOPS) - multiCounter[currCounter].L_shl++; - #endif BASOP_CHECK(); + return (L_var_out); } @@ -1614,9 +1518,6 @@ Word32 L_shr (Word32 L_var1, Word16 var2) var2 = -32; var2 = -var2; L_var_out = L_shl (L_var1, var2); -#if (WMOPS) - multiCounter[currCounter].L_shl--; -#endif } else { @@ -1636,12 +1537,10 @@ Word32 L_shr (Word32 L_var1, Word16 var2) } } } - #if (WMOPS) - multiCounter[currCounter].L_shr++; - #endif BASOP_CHECK(); + return (L_var_out); } @@ -1699,10 +1598,6 @@ Word16 shr_r (Word16 var1, Word16 var2) { var_out = shr (var1, var2); -#if (WMOPS) - multiCounter[currCounter].shr--; -#endif - if (var2 > 0) { if ((var1 & ((Word16) 1 << (var2 - 1))) != 0) @@ -1712,12 +1607,9 @@ Word16 shr_r (Word16 var1, Word16 var2) } } -#if (WMOPS) - multiCounter[currCounter].shr_r++; -#endif - BASOP_CHECK(); + return (var_out); } @@ -1768,15 +1660,9 @@ Word16 mac_r (Word32 L_var3, Word16 var1, Word16 var2) L_var3 = L_add (L_var3, (Word32) 0x00008000L); var_out = extract_h (L_var3); -#if (WMOPS) - multiCounter[currCounter].L_mac--; - multiCounter[currCounter].L_add--; - multiCounter[currCounter].extract_h--; - multiCounter[currCounter].mac_r++; -#endif - BASOP_CHECK(); + return (var_out); } @@ -1827,15 +1713,9 @@ Word16 msu_r (Word32 L_var3, Word16 var1, Word16 var2) L_var3 = L_add (L_var3, (Word32) 0x00008000L); var_out = extract_h (L_var3); -#if (WMOPS) - multiCounter[currCounter].L_msu--; - multiCounter[currCounter].L_add--; - multiCounter[currCounter].extract_h--; - multiCounter[currCounter].msu_r++; -#endif - BASOP_CHECK(); + return (var_out); } @@ -1874,12 +1754,9 @@ Word32 L_deposit_h (Word16 var1) L_var_out = (Word32) var1 << 16; -#if (WMOPS) - multiCounter[currCounter].L_deposit_h++; -#endif - BASOP_CHECK(); + return (L_var_out); } @@ -1918,12 +1795,9 @@ Word32 L_deposit_l (Word16 var1) L_var_out = (Word32) var1; -#if (WMOPS) - multiCounter[currCounter].L_deposit_l++; -#endif - BASOP_CHECK(); + return (L_var_out); } @@ -1981,9 +1855,6 @@ Word32 L_shr_r (Word32 L_var1, Word16 var2) { L_var_out = L_shr (L_var1, var2); -#if (WMOPS) - multiCounter[currCounter].L_shr--; -#endif if (var2 > 0) { if ((L_var1 & ((Word32) 1 << (var2 - 1))) != 0) @@ -1993,12 +1864,9 @@ Word32 L_shr_r (Word32 L_var1, Word16 var2) } } -#if (WMOPS) - multiCounter[currCounter].L_shr_r++; -#endif - BASOP_CHECK(); + return (L_var_out); } @@ -2051,12 +1919,9 @@ Word32 L_abs (Word32 L_var1) } } -#if (WMOPS) - multiCounter[currCounter].L_abs++; -#endif - BASOP_CHECK(); + return (L_var_out); } @@ -2113,12 +1978,9 @@ Word32 L_sat (Word32 L_var1) Overflow = 0; } -#if (WMOPS) - multiCounter[currCounter].L_sat++; -#endif - BASOP_CHECK(); + return (L_var_out); } @@ -2182,12 +2044,9 @@ Word16 norm_s (Word16 var1) } } -#if (WMOPS) - multiCounter[currCounter].norm_s++; -#endif - BASOP_CHECK(); + return (var_out); } @@ -2239,7 +2098,7 @@ Word16 div_s (Word16 var1, Word16 var2) { /* printf ("Division Error var1=%d var2=%d in ", var1, var2); printStack(); */ char text[60]; - sprintf (text, "\nDivision Error var1=%d var2=%d in ", var1, var2); + sprintf (text, "Division Error var1=%d var2=%d in ", var1, var2); abort(); /* exit (0); */ } if (var2 == 0) @@ -2262,11 +2121,6 @@ Word16 div_s (Word16 var1, Word16 var2) L_num = L_deposit_l (var1); L_denom = L_deposit_l (var2); -#if (WMOPS) - multiCounter[currCounter].L_deposit_l--; - multiCounter[currCounter].L_deposit_l--; -#endif - for (iteration = 0; iteration < 15; iteration++) { var_out <<= 1; @@ -2276,21 +2130,14 @@ Word16 div_s (Word16 var1, Word16 var2) { L_num = L_sub (L_num, L_denom); var_out = add (var_out, 1); -#if (WMOPS) - multiCounter[currCounter].L_sub--; - multiCounter[currCounter].add--; -#endif } } } } -#if (WMOPS) - multiCounter[currCounter].div_s++; -#endif - BASOP_CHECK(); + return (var_out); } @@ -2354,12 +2201,9 @@ Word16 norm_l (Word32 L_var1) } } -#if (WMOPS) - multiCounter[currCounter].norm_l++; -#endif - BASOP_CHECK(); + return (var_out); } @@ -2411,24 +2255,17 @@ Word16 norm_l (Word32 L_var1) */ Word32 L_mls (Word32 Lv, Word16 v) { - Word32 Temp ; + Word32 Temp ; - Temp = Lv & (Word32) 0x0000ffff ; - Temp = Temp * (Word32) v ; - Temp = L_shr( Temp, (Word16) 15 ) ; - Temp = L_mac( Temp, v, extract_h(Lv) ) ; + Temp = Lv & (Word32) 0x0000ffff ; + Temp = Temp * (Word32) v ; + Temp = L_shr( Temp, (Word16) 15 ) ; + Temp = L_mac( Temp, v, extract_h(Lv) ) ; -#if (WMOPS) - multiCounter[currCounter].L_shr--; - multiCounter[currCounter].L_mac--; - multiCounter[currCounter].extract_h--; - multiCounter[currCounter].L_mls++; -#endif + BASOP_CHECK(); - BASOP_CHECK(); - - return Temp ; + return Temp ; } @@ -2476,55 +2313,44 @@ Word16 div_l (Word32 L_num, Word16 den) Word32 L_den; Word16 iteration; -#if (WMOPS) - multiCounter[currCounter].div_l++; -#endif - if ( den == (Word16) 0 ) { + if ( den == (Word16) 0 ) + { /* printf("Division by 0 in div_l, Fatal error in "); printStack(); */ exit(-1); } - if ( (L_num < (Word32) 0) || (den < (Word16) 0) ) { + if ( (L_num < (Word32) 0) || (den < (Word16) 0) ) + { /* printf("Division Error in div_l, Fatal error in "); printStack(); */ exit(-1); } L_den = L_deposit_h( den ) ; -#if (WMOPS) - multiCounter[currCounter].L_deposit_h--; -#endif - if ( L_num >= L_den ){ + if ( L_num >= L_den ) + { BASOP_CHECK(); - return MAX_16 ; } - else { + else + { L_num = L_shr(L_num, (Word16)1) ; L_den = L_shr(L_den, (Word16)1); -#if (WMOPS) - multiCounter[currCounter].L_shr-=2; -#endif - for(iteration=(Word16)0; iteration< (Word16)15;iteration++) { + for(iteration=(Word16)0; iteration< (Word16)15; iteration++) + { var_out = shl( var_out, (Word16)1); L_num = L_shl( L_num, (Word16)1); -#if (WMOPS) - multiCounter[currCounter].shl--; - multiCounter[currCounter].L_shl--; -#endif - if (L_num >= L_den) { + if (L_num >= L_den) + { L_num = L_sub(L_num,L_den); var_out = add(var_out, (Word16)1); -#if (WMOPS) - multiCounter[currCounter].L_sub--; - multiCounter[currCounter].add--; -#endif } } + BASOP_CHECK(); return var_out; @@ -2565,13 +2391,10 @@ Word16 div_l (Word32 L_num, Word16 den) Word16 i_mult (Word16 a, Word16 b) { #ifdef ORIGINAL_G7231 - return a*b ; + return a*b ; #else - Word32 /*register*/ c=a*b; -#if (WMOPS) - multiCounter[currCounter].i_mult++; -#endif - return saturate(c) ; + Word32 /*register*/ c=a*b; + return saturate(c) ; #endif } @@ -2612,17 +2435,14 @@ Word16 i_mult (Word16 a, Word16 b) */ Word32 L_mult0 (Word16 var1,Word16 var2) { - Word32 L_var_out; + Word32 L_var_out; - L_var_out = (Word32)var1 * (Word32)var2; + L_var_out = (Word32)var1 * (Word32)var2; -#if (WMOPS) - multiCounter[currCounter].L_mult0++; -#endif + BASOP_CHECK(); - BASOP_CHECK(); - return(L_var_out); + return(L_var_out); } @@ -2658,21 +2478,16 @@ Word32 L_mult0 (Word16 var1,Word16 var2) */ Word32 L_mac0 (Word32 L_var3, Word16 var1, Word16 var2) { - Word32 L_var_out; - Word32 L_product; + Word32 L_var_out; + Word32 L_product; - L_product = L_mult0(var1,var2); - L_var_out = L_add(L_var3,L_product); + L_product = L_mult0(var1,var2); + L_var_out = L_add(L_var3,L_product); -#if (WMOPS) - multiCounter[currCounter].L_mac0++; - multiCounter[currCounter].L_mult0--; - multiCounter[currCounter].L_add--; -#endif + BASOP_CHECK(); - BASOP_CHECK(); - return(L_var_out); + return(L_var_out); } @@ -2708,21 +2523,16 @@ Word32 L_mac0 (Word32 L_var3, Word16 var1, Word16 var2) */ Word32 L_msu0 (Word32 L_var3, Word16 var1, Word16 var2) { - Word32 L_var_out; - Word32 L_product; + Word32 L_var_out; + Word32 L_product; - L_product = L_mult0(var1,var2); - L_var_out = L_sub(L_var3,L_product); + L_product = L_mult0(var1,var2); + L_var_out = L_sub(L_var3,L_product); -#if (WMOPS) - multiCounter[currCounter].L_msu0++; - multiCounter[currCounter].L_mult0--; - multiCounter[currCounter].L_sub--; -#endif + BASOP_CHECK(); - BASOP_CHECK(); - return(L_var_out); + return(L_var_out); } diff --git a/src/libs/libevs/basic_op/basop32.h b/src/libs/libevs/lib_com/basop32.h old mode 100755 new mode 100644 similarity index 99% rename from src/libs/libevs/basic_op/basop32.h rename to src/libs/libevs/lib_com/basop32.h index 4348821a..f8126e96 --- a/src/libs/libevs/basic_op/basop32.h +++ b/src/libs/libevs/lib_com/basop32.h @@ -8,13 +8,13 @@ GLOBAL FUNCTION PROTOTYPES History: - 26.Jan.00 v1.0 Incorporated to the STL from updated G.723.1/G.729 - basic operator library (based on basic_op.h) and + 26.Jan.00 v1.0 Incorporated to the STL from updated G.723.1/G.729 + basic operator library (based on basic_op.h) and G.723.1's basop.h. 05.Jul.00 v1.1 Added 32-bit shiftless mult/mac/msub operators 03 Nov 04 v2.0 Incorporation of new 32-bit / 40-bit / control - operators for the ITU-T Standard Tool Library as + operators for the ITU-T Standard Tool Library as described in Geneva, 20-30 January 2004 WP 3/16 Q10/16 TD 11 document and subsequent discussions on the wp3audio@yahoogroups.com email reflector. diff --git a/src/libs/libevs/lib_com/basop_com_lpc.cpp b/src/libs/libevs/lib_com/basop_com_lpc.cpp new file mode 100644 index 00000000..9cd5ef75 --- /dev/null +++ b/src/libs/libevs/lib_com/basop_com_lpc.cpp @@ -0,0 +1,237 @@ +/*==================================================================================== + EVS Codec 3GPP TS26.443 Nov 13, 2018. Version 12.11.0 / 13.7.0 / 14.3.0 / 15.1.0 + ====================================================================================*/ + + +#include +#include +#include +#include +#include "typedef.h" +#include "basop_proto_func.h" +#include "cnst.h" + +#include "basop_util.h" +#include "stl.h" + +#define UNROLL_CHEBYSHEV_INNER_LOOP +#define NC_MAX 8 +#define GUESS_TBL_SZ 256 + +#define Madd_32_16(accu, x, y) L_add(accu, Mpy_32_16(x, y)) +#define Msub_32_16(accu, x, y) L_sub(accu, Mpy_32_16(x, y)) + + +/* + * weight_a + * + * Parameters: + * a I: LP filter coefficients Q12 + * ap O: weighted LP filter coefficients Q12 + * gamma I: weighting factor Q15 + * + * Function: + * Weighting of LP filter coefficients, ap[i] = a[i] * (gamma^i). + * + * Returns: + * void + */ +void basop_weight_a(const Word16 *a, Word16 *ap, const Word16 gamma) +{ + Word16 i, fac; + Word32 Amax; + Word16 shift; + + + + fac = gamma; + Amax = L_mult( 16384, a[0] ); + FOR (i = 1; i < M; i++) + { + Amax = L_max( Amax, L_abs( L_mult0( fac, a[i] ) ) ); + fac = mult_r( fac, gamma ); + } + Amax = L_max( Amax, L_abs( L_mult0( fac, a[M] ) ) ); + shift = norm_l( Amax ); + fac = gamma; + ap[0] = shl( a[0], sub(shift,1) ); + move16(); + FOR (i = 1; i < M; i++) + { + ap[i] = round_fx(L_shl(L_mult0(a[i], fac),shift)); + move16(); + fac = mult_r( fac, gamma ); + } + ap[M] = round_fx(L_shl(L_mult0(a[M], fac),shift)); + move16(); + + + return; +} + +/* + * weight_a_inv + * + * Parameters: + * a I: LP filter coefficients Q12 + * ap O: weighted LP filter coefficients Q12 + * inv_gamma I: inverse weighting factor Q14 + * + * Function: + * Weighting of LP filter coefficients, ap[i] = a[i] * (inv_gamma^i). + * + * Returns: + * void + */ +void basop_weight_a_inv(const Word16 *a, Word16 *ap, const Word16 inv_gamma) +{ + Word16 i; + static const Word16 inv_gamma_tab_12k8[16] = { 17809, 19357, 21041, 22870, 24859, 27020, 29370, 31924, /* Q14 */ + 17350, 18859, 20499, 22281, 24219, 26325, 28614, 31102 + }; /* Q13 */ + static const Word16 inv_gamma_tab_16k[16] = { 17430, 18542, 19726, 20985, 22324, 23749, 25265, 26878, /* Q14 */ + 14297, 15209, 16180, 17213, 18312, 19480, 20724, 22047 + }; /* Q13 */ + const Word16 *inv_gamma_tab; + Word32 L_tmp; + Word32 Amax; + Word16 shift; + + + IF (inv_gamma == 16384) + { + FOR (i = 0; i <= M; i++) + { + ap[i] = a[i]; + move16(); + } + return; + } + + assert( inv_gamma==GAMMA1_INV || inv_gamma==GAMMA16k_INV ); + + inv_gamma_tab = inv_gamma_tab_12k8; + move16(); + if (sub(inv_gamma,GAMMA16k_INV) == 0) + { + inv_gamma_tab = inv_gamma_tab_16k; + move16(); + } + + Amax = L_mult( 16384, a[0] ); + FOR (i = 1; i < 9; i++) + { + Amax = L_max( Amax, L_abs( L_mult( a[i], inv_gamma_tab[i-1] ) ) ); + } + FOR (i = 9; i < 17; i++) + { + Amax = L_max( Amax, L_abs( L_shl( L_mult( a[i], inv_gamma_tab[i-1] ), 1 ) ) ); + } + shift = norm_l( Amax ); + ap[0] = shl( a[0], sub(shift,1) ); + move16(); + FOR (i = 1; i < 9; i++) + { + L_tmp = L_mult( a[i], inv_gamma_tab[i-1] ); + ap[i] = round_fx( L_shl( L_tmp, shift ) ); + move16(); + } + shift = add(shift,1); + FOR (i = 9; i < 17; i++) + { + L_tmp = L_mult( a[i], inv_gamma_tab[i-1] ); + ap[i] = round_fx( L_shl( L_tmp, shift ) ); + move16(); + } + + + return; +} + +/* + * basop_E_LPC_a_add_tilt + * + * Parameters: + * a I: LP filter coefficients (m+1 coeffs) + * ap O: modified LP filter coefficients (m+2 coeffs) + * gamma I: tilt factor + * + * Function: + * Modified LP filter by adding 1st order pre-premphasis, Ap(z)=A(z).(1-gamma.z^(-1)) + * + * Returns: + * void + */ +void basop_E_LPC_a_add_tilt(const Word16 *a, Word16 *ap, Word16 gamma) +{ + Word16 i; + Word32 Amax, Atmp[M+2]; + Word16 shift; + + + + + Amax = L_mult( 16384, a[0] ); + FOR (i = 1; i <= M; i++) + { + Atmp[i] = L_sub( L_mult(16384, a[i]), L_mult0(gamma, a[i-1]) ); + move32(); + Amax = L_max( Amax, L_abs( Atmp[i] ) ); + } + Atmp[M+1] = L_negate( L_mult0(gamma, a[M]) ); + move32(); + Amax = L_max( Amax, L_abs( Atmp[M+1] ) ); + shift = norm_l( Amax ); + ap[0] = shl( a[0], sub(shift,1) ); + move16(); + FOR (i = 1; i <= M; i++) + { + ap[i] = round_fx( L_shl( Atmp[i], shift ) ); + move16(); + } + ap[M+1] = round_fx( L_shl( Atmp[M+1], shift ) ); + move16(); + + return; +} + + + +static Word16 xsf_to_xsp(Word16 xsf) +{ + /* xsp = cos(xsf * 3.1415/6400); */ + return getCosWord16R2(xsf); +} + +/* + * lsf2lsp + * + * Parameters: + * lsf I: lsf[m] normalized (range: 0 <= val <= 0.5) x2.56 + * lsp O: lsp[m] (range: -1 <= val < 1) Q15 + * + * Function: + * Transformation lsf to lsp + * + * LSF are line spectral pair in frequency domain (0 to 6400). + * LSP are line spectral pair in cosine domain (-1 to 1). + * + * Returns: + * void + */ +void basop_lsf2lsp(const Word16 lsf[], Word16 lsp[]) +{ + Word16 i; + + + + /* convert ISFs to the cosine domain */ + FOR (i = 0; i < M; i++) + { + *lsp++ = xsf_to_xsp(*lsf++); + move16(); + } + + + return; +} diff --git a/src/libs/libevs/lib_com/basop_lsf_tools.cpp b/src/libs/libevs/lib_com/basop_lsf_tools.cpp new file mode 100644 index 00000000..237c2db1 --- /dev/null +++ b/src/libs/libevs/lib_com/basop_lsf_tools.cpp @@ -0,0 +1,262 @@ +/*==================================================================================== + EVS Codec 3GPP TS26.443 Nov 13, 2018. Version 12.11.0 / 13.7.0 / 14.3.0 / 15.1.0 + ====================================================================================*/ + + +#include +#include +#include +#include "basop_proto_func.h" +#include "control.h" +#include "basop_util.h" + +#define NC_MAX 8 + +static Word16 E_LPC_f_lsp_pol_get(const Word16 lsp[], Word32 f[], const Word16 n, const Word16 past_Ovf, const Word16 isMODE1); + + +/* + * E_LPC_f_lsp_a_conversion + * + * Parameters: + * lsp I: Line spectral pairs Q15 + * a O: Predictor coefficients (order = m) Qx (The Q factor of the output to be deduced from a(0)) + * m I: order of LP filter + * + * Function: + * Convert ISPs to predictor coefficients a[] + * + * Returns: + * void + */ +void basop_E_LPC_f_lsp_a_conversion(const Word16 *lsp, Word16 *a, const Word16 m) +{ + Word16 i, j, k; + Word32 f1[NC_MAX+1], f2[NC_MAX+1]; + Word16 nc; + Word32 t0; + Word16 Ovf, Ovf2; + + + /*-----------------------------------------------------* + * Find the polynomials F1(z) and F2(z) * + *-----------------------------------------------------*/ + + nc = shr(m, 1); + + assert(m == 16 || m == 10); + + Ovf = 0; + move16(); + Ovf = E_LPC_f_lsp_pol_get(&lsp[0], f1, nc, Ovf, 1); + Ovf2 = E_LPC_f_lsp_pol_get(&lsp[1], f2, nc, Ovf, 1); + IF(sub(Ovf2,Ovf) !=0) + { + /* to ensure similar scaling for f1 and f2 in case + an overflow would be detected only in f2, + but this case never happen on my dtb */ + E_LPC_f_lsp_pol_get(&lsp[0], f1, nc, s_max(Ovf2,Ovf), 1); + } + /*-----------------------------------------------------* + * Multiply F1(z) by (1+z^-1) and F2(z) by (1-z^-1) * + *-----------------------------------------------------*/ + /*modification*/ + k = sub(nc,1); + FOR (i = 0; i <= k; i++) + { + f1[nc-i] = L_add(f1[nc-i],f1[nc-i-1]); + move32(); + f2[nc-i] = L_sub(f2[nc-i],f2[nc-i-1]); + move32(); + } + + /*-----------------------------------------------------* + * A(z) = (F1(z)+F2(z))/2 * + * F1(z) is symmetric and F2(z) is antisymmetric * + *-----------------------------------------------------*/ + + t0 = L_deposit_l(0); + FOR (i = 1; i <= nc; i++) + { + t0 = L_max( t0, L_abs(L_add(f1[i], f2[i])) ); + t0 = L_max( t0, L_abs(L_sub(f1[i], f2[i])) ); + } + k = s_min( norm_l(t0), 6 ); + a[0] = shl( 256, k ); + move16(); + test(); + IF( Ovf || Ovf2) + { + a[0] = shl( 256, sub(k,Ovf) ); + move16(); + } + j = m; + FOR (i = 1; i <= nc; i++) + { + /* a[i] = 0.5*(f1[i] + f2[i]) */ + t0 = L_add(f1[i],f2[i]); + t0 = L_shl(t0, k); + a[i] = round_fx(t0); /* from Q23 to Qx and * 0.5 */ + + /* a[j] = 0.5*(f1[i] - f2[i]) */ + t0 = L_sub(f1[i],f2[i]); + t0 = L_shl(t0, k); + a[j] = round_fx(t0); /* from Q23 to Qx and * 0.5 */ + j--; + } + + return; +} + + +/*--------------------------------------------------------------------------- +* procedure reorder_lsf() +* +* To make sure that the lsfs are properly ordered and to keep a certain +* minimum distance between consecutive lsfs. +*--------------------------------------------------------------------------*/ +void basop_reorder_lsf( + Word16 *lsf, /* i/o: LSFs in the frequency domain (0..0.5) Q(x2.56)*/ + const Word16 min_dist, /* i : minimum required distance x2.56*/ + const Word16 n, /* i : LPC order */ + const Word32 fs /* i : sampling frequency */ +) +{ + Word16 i, lsf_min, n_m_1; + Word16 lsf_max; + + lsf_min = min_dist; + move16(); + + /*-----------------------------------------------------------------------* + * Verify the LSF ordering and minimum GAP + *-----------------------------------------------------------------------*/ + + FOR (i = 0; i < n; i++) + { + if (sub(lsf[i], lsf_min) < 0) + { + lsf[i] = lsf_min; + move16(); + } + lsf_min = add(lsf[i], min_dist); + } + + /*-----------------------------------------------------------------------* + * Reverify the LSF ordering and minimum GAP in the reverse order (security) + *-----------------------------------------------------------------------*/ + lsf_max = round_fx(L_sub(L_shr(L_mult0(extract_l(L_shr(fs,1)), 1311),9-16), L_deposit_h(min_dist))); /* Q0 + Q9 , 1311 is 2.56 in Q9 */ + n_m_1 = sub(n,1); + IF (sub(lsf[n_m_1], lsf_max) > 0) /* If danger of unstable filter in case of resonance in HF */ + { + FOR (i = n_m_1; i >= 0; i--) /* Reverify the minimum LSF gap in the reverse direction */ + { + if (sub(lsf[i], lsf_max) > 0) + { + lsf[i] = lsf_max; + move16(); + } + lsf_max = sub(lsf[i], min_dist); + } + } +} + + +/* + * E_LPC_f_lsp_pol_get + * + * Parameters: + * lsp/isp I: Line spectral pairs (cosine domaine) Q15 + * f O: the coefficients of F1 or F2 Q23 + * n I: no of coefficients (m/2) + * == NC for F1(z); == NC-1 for F2(z) + * fact I: scaling factor + * + *-----------------------------------------------------------* + * procedure E_LPC_f_lsp_pol_get: * + * ~~~~~~~~~~~ * + * Find the polynomial F1(z) or F2(z) from the LSPs. * + * This is performed by expanding the product polynomials: * + * * + * F1(z) = product ( 1 - 2 LSF_i z^-1 + z^-2 ) * + * i=0,2,4,6,8 * + * F2(z) = product ( 1 - 2 LSF_i z^-1 + z^-2 ) * + * i=1,3,5,7,9 * + * * + * where LSP_i are the LSPs in the cosine domain. * + * * + *-----------------------------------------------------------* + * R.A.Salami October 1990 * + *-----------------------------------------------------------* + */ +static +Word16 E_LPC_f_lsp_pol_get(const Word16 lsp[], Word32 f[], const Word16 n, const Word16 past_Ovf, const Word16 isMODE1) +{ + /* All computation in Q23 */ + const Word16 *plsp; + Word16 i, j; + Word16 b; + Word32 b32; + Word16 Ovf = 0; + Word16 Q_out; + Word16 m2; + + + Q_out = 31-23; + move16(); + Ovf = past_Ovf; + move16(); + + test(); + if(past_Ovf && isMODE1) /* Currently this feature is implemented only in MODE1 */ + { + /* In some NB cases, overflow where detectected + in f1 or f2 polynomial computation when it + happen we reduce the precision of the computing + to limit the risk of saturation*/ + Q_out = add(Q_out, past_Ovf); + } + Overflow = 0; + move16(); + plsp = lsp; + f[0] = L_shl(1, sub(31, Q_out)); + move32(); + /*b = -2.0f * *plsp;*/ + b = *plsp; + move16(); + m2 = shl(-2, sub(15, Q_out)); + f[1] = L_mult(b, m2); + move32(); + + FOR (i = 2; i <= n; i++) + { + plsp += 2; + /*b = 2.0f * *plsp;*/ + move16(); + b = *plsp; + b32 = L_mult(b, m2); + + /*f[i] = -b*f[i-1] + 2.0f*f[i-2];*/ + move32(); + f[i] = L_shl(L_sub(f[i-2], Mpy_32_16(f[i-1], b)),1); + + FOR (j = i-1; j > 1; j--) + { + /*f[j] += b*f[j-1] + f[j-2];*/ + move32(); + f[j] = L_add(f[j], L_sub(f[j-2], L_shl(Mpy_32_16(f[j-1], b),1))); + } + move32(); + f[1] = L_add(f[1], b32); + } + + + test(); + IF (Overflow>0 && isMODE1) + { + /* If an overflow is detected, redo the computation with 1 bit less */ + Ovf = add(Ovf,1); + Ovf = E_LPC_f_lsp_pol_get(lsp, f, n ,Ovf, isMODE1); + } + return Ovf; +} diff --git a/src/libs/libevs/lib_com/basop_mpy.cpp b/src/libs/libevs/lib_com/basop_mpy.cpp old mode 100755 new mode 100644 index 0b75f99b..2579a8bd --- a/src/libs/libevs/lib_com/basop_mpy.cpp +++ b/src/libs/libevs/lib_com/basop_mpy.cpp @@ -1,10 +1,10 @@ /*==================================================================================== - EVS Codec 3GPP TS26.442 Apr 03, 2018. Version 12.11.0 / 13.6.0 / 14.2.0 + EVS Codec 3GPP TS26.443 Nov 13, 2018. Version 12.11.0 / 13.7.0 / 14.3.0 / 15.1.0 ====================================================================================*/ + #include "basop_mpy.h" -#include "stl.h" -#include "options.h" /* Needed for Stack Counting Mechanism Macros (when Instrumented) */ +#include "options.h" Word32 Mpy_32_16_1(Word32 x, Word16 y) { @@ -16,6 +16,16 @@ Word32 Mpy_32_16_1(Word32 x, Word16 y) return (mh); } +Word32 Mpy_32_16(Word32 x, Word16 y) +{ + Word32 mh; + UWord16 ml; + + Mpy_32_16_ss(x, y, &mh, &ml); + + return (mh); +} + Word32 Mpy_32_16_r(Word32 x, Word16 y) { Word32 mh; @@ -31,6 +41,7 @@ Word32 Mpy_32_16_r(Word32 x, Word16 y) return (mh); } + Word32 Mpy_32_32(Word32 x, Word32 y) { Word32 mh; @@ -41,18 +52,3 @@ Word32 Mpy_32_32(Word32 x, Word32 y) return (mh); } -Word32 Mpy_32_32_r(Word32 x, Word32 y) -{ - Word32 mh; - UWord32 ml; - - Mpy_32_32_ss(x, y, &mh, &ml); - - if(L_and(ml, 0x80000000)) - { - mh = L_add(mh, 1); - } - - return (mh); -} - diff --git a/src/libs/libevs/lib_com/basop_mpy.h b/src/libs/libevs/lib_com/basop_mpy.h old mode 100755 new mode 100644 index b0e7e08b..75e1559e --- a/src/libs/libevs/lib_com/basop_mpy.h +++ b/src/libs/libevs/lib_com/basop_mpy.h @@ -1,5 +1,5 @@ /*==================================================================================== - EVS Codec 3GPP TS26.442 Apr 03, 2018. Version 12.11.0 / 13.6.0 / 14.2.0 + EVS Codec 3GPP TS26.443 Nov 13, 2018. Version 12.11.0 / 13.7.0 / 14.3.0 / 15.1.0 ====================================================================================*/ #ifndef __BASOP_MPY_H @@ -9,7 +9,7 @@ #include "options.h" /** - * \brief 32*16 Bit fractional Multiplication using 40 bit OPS + * \brief 32*16 Bit fractional Multiplication using 40 bit OPS * Performs a multiplication of a 32-bit variable x by * a 16-bit variable y, returning a 32-bit value. * @@ -21,18 +21,33 @@ Word32 Mpy_32_16_1(Word32 x, Word16 y); + /** * \brief 32*16 Bit fractional Multiplication using 40 bit OPS * Performs a multiplication of a 32-bit variable x by - * a 16-bit variable y incl. rounding, returning a 32-bit value. + * a 16-bit variable y, returning a 32-bit value. * * \param[i] x * \param[i] y * * \return x*y */ -Word32 Mpy_32_16_r(Word32 x, - Word16 y); +Word32 Mpy_32_16(Word32 x, + Word16 y); + + +/** + * \brief 32*16 Bit fractional Multiplication using 40 bit OPS + * Performs a multiplication of a 32-bit variable x by + * a 16-bit variable y including rounding, returning a 32-bit value. + * + * \param[i] x + * \param[i] y + * + * \return x*y + */ +Word32 Mpy_32_16_r(Word32 x, Word16 y); + /** * \brief 32*32 Bit fractional Multiplication using 40 bit OPS @@ -45,60 +60,8 @@ Word32 Mpy_32_16_r(Word32 x, * * \return x*y */ + Word32 Mpy_32_32(Word32 x, Word32 y); -/** - * \brief 32*32 Bit fractional Multiplication using 40 bit OPS including rounding - * - * Performs a multiplication of a 32-bit variable x by - * a 32-bit variable y, returning a 32-bit value. - * - * \param[i] x - * \param[i] y - * - * \return x*y - */ -Word32 Mpy_32_32_r(Word32 x, Word32 y); - -/** - * \brief 32*16 Bit integer Multiplication using 40 bit OPS - * - * Performs a multiplication of a 32-bit variable x by - * a 16-bit variable y, returning a 32-bit value. - * - * \param[i] x - * \param[i] y - * - * \return x*y - */ -Word32 Mpy_32_16_2(Word32 x, - Word16 y); - - -/** - * \brief 32*16 Bit complex fractional multiplication using 40 Bit and 32 Bit operators - * - * The function mixes 40 Bit and 32 Bit operators, thus it must not be applied - * inside of loops where 32 and 16 bit operators are used. - * - * \param[i] c_Re - * \param[i] c_Im - * \param[i] a_Re - * \param[i] a_Im - * \param[i] b_Re - * \param[i] b_Im - * - * \return none - */ -void cplxMpy_32_16(Word32 *c_Re, - Word32 *c_Im, - const Word32 a_Re, - const Word32 a_Im, - const Word16 b_Re, - const Word16 b_Im - ); - -#define MUL_F(A,B) Mpy_32_16_1((A),(B)) - #endif /* __BASOP_SETTINGS_H */ diff --git a/src/libs/libevs/lib_com/basop_proto_func.h b/src/libs/libevs/lib_com/basop_proto_func.h new file mode 100644 index 00000000..8f3c633b --- /dev/null +++ b/src/libs/libevs/lib_com/basop_proto_func.h @@ -0,0 +1,39 @@ +/*==================================================================================== + EVS Codec 3GPP TS26.443 Nov 13, 2018. Version 12.11.0 / 13.7.0 / 14.3.0 / 15.1.0 + ====================================================================================*/ + +#ifndef BASOP_PROTO_FUNC_H +#define BASOP_PROTO_FUNC_H + +#include "stl.h" +#include "basop_util.h" + + +/* tcx_lpc_cdk.h */ +#define LSF_GAP_VAL(x) (Word16)((x)*2.0f*1.28f) +#define LSFM(x) FL2WORD16_SCALE(x*1.28, 15-1) /* 14Q1*1.28 */ + +/* cnst.h */ +#define GAMMA1_INV 17809 /* weighting factor (numerator) default:0.92 (1Q14format) */ +#define GAMMA16k_INV 17430 /* weighting factor (numerator) default:0.94 (1Q14format) */ +#define FS_2 16384 /* isf max value (Use in reorder_fx.c) */ +#define INT_FS_FX 12800 /* internal sampling frequency */ + +void basop_lsp2a_stab(const Word16 *lsp, Word16 *a); +void basop_lsf2lsp(const Word16 lsf[], Word16 lsp[]); +void basop_weight_a(const Word16 *a, Word16 *ap, const Word16 gamma); +void basop_weight_a_inv(const Word16 *a, Word16 *ap, const Word16 inv_gamma); +void basop_E_LPC_a_add_tilt(const Word16 *a, Word16 *ap, Word16 gamma); +void basop_reorder_lsf(Word16 *lsf, const Word16 min_dist, const Word16 n, const Word32 fs); +void basop_E_LPC_f_lsp_a_conversion(const Word16 *lsp, Word16 *a, const Word16 m); + +/* tcx_utils.c */ +void basop_lpc2mdct(Word16 *lpcCoeffs, Word16 lpcOrder, + Word16 *mdct_gains, Word16 *mdct_gains_exp, + Word16 *mdct_inv_gains, Word16 *mdct_inv_gains_exp); + +void basop_PsychAdaptLowFreqDeemph(Word32 x[], const Word16 lpcGains[], const Word16 lpcGains_e[], Word16 lf_deemph_factors[]); +void basop_mdct_noiseShaping_interp(Word32 x[], Word16 lg, Word16 gains[], Word16 gains_exp[]); + + +#endif diff --git a/src/libs/libevs/lib_com/basop_settings.h b/src/libs/libevs/lib_com/basop_settings.h new file mode 100644 index 00000000..da9a3887 --- /dev/null +++ b/src/libs/libevs/lib_com/basop_settings.h @@ -0,0 +1,85 @@ +/*==================================================================================== + EVS Codec 3GPP TS26.443 Nov 13, 2018. Version 12.11.0 / 13.7.0 / 14.3.0 / 15.1.0 + ====================================================================================*/ + +#ifndef __BASOP_SETTINGS_H +#define __BASOP_SETTINGS_H + +#include "stl.h" +#include "basop_mpy.h" + +#define _LONG long +#define _SHORT short +#ifdef _WIN32 +#define _INT64 __int64 +#else +#define _INT64 long long +#endif + +#define WORD32_BITS 32 +#define MAXVAL_WORD32 ((signed)0x7FFFFFFF) +#define MINVAL_WORD32 ((signed)0x80000000) +#define WORD32_FIX_SCALE ((_INT64)(1)<<(WORD32_BITS-1)) + +#define WORD16_BITS 16 +#define MAXVAL_WORD16 (((signed)0x7FFFFFFF)>>16) +#define MINVAL_WORD16 (((signed)0x80000000)>>16) +#define WORD16_FIX_SCALE ((_INT64)(1)<<(WORD16_BITS-1)) + +/*! + \def Macro converts a float < 1 to Word32 fixed point with saturation and rounding +*/ +#define FL2WORD32(val) \ +(Word32)( ( (val) >= 0) ? \ +((( (double)(val) * (WORD32_FIX_SCALE) + 0.5 ) >= (double)(MAXVAL_WORD32) ) ? (_LONG)(MAXVAL_WORD32) : (_LONG)( (double)(val) * (double)(WORD32_FIX_SCALE) + 0.5)) : \ +((( (double)(val) * (WORD32_FIX_SCALE) - 0.5) <= (double)(MINVAL_WORD32) ) ? (_LONG)(MINVAL_WORD32) : (_LONG)( (double)(val) * (double)(WORD32_FIX_SCALE) - 0.5)) ) + +/*! + \def Macro converts a float < 1 to Word16 fixed point with saturation and rounding +*/ +#define FL2WORD16(val) \ +(Word16)( ( (val) >= 0) ? \ +((( (double)(val) * (WORD16_FIX_SCALE) + 0.5 ) >= (double)(MAXVAL_WORD16) ) ? (_LONG)(MAXVAL_WORD16) : (_LONG)( (double)(val) * (double)(WORD16_FIX_SCALE) + 0.5)) : \ +((( (double)(val) * (WORD16_FIX_SCALE) - 0.5) <= (double)(MINVAL_WORD16) ) ? (_LONG)(MINVAL_WORD16) : (_LONG)( (double)(val) * (double)(WORD16_FIX_SCALE) - 0.5)) ) + +/*! + \def Macro converts a Word32 fixed point to Word16 fixed point <1 with saturation +*/ +#define WORD322WORD16(val) \ + ( ( ((((val) >> (WORD32_BITS-WORD16_BITS-1)) + 1) > (((_LONG)1< 0) ) ? \ + (Word16)(_SHORT)(((_LONG)1<<(WORD16_BITS-1))-1):(Word16)(_SHORT)((((val) >> (WORD32_BITS-WORD16_BITS-1)) + 1) >> 1) ) + +/*! + \def Macro converts a Word32 fixed point < 1 to float shifts result left by scale +*/ +#define WORD322FL_SCALE(x,scale) ( ((float)((_LONG)(x))) / (((_INT64)1<<(WORD32_BITS-1 - (scale)))) ) + +/*! + \def Macro converts a float < 1 to Word32 fixed point with saturation and rounding, shifts result right by scale +*/ +/* Note: Both x and scale must be constants at compile time, scale must be in range -31..31 */ +#define FL2WORD32_SCALE(x,scale) FL2WORD32((double)(x) *(((_INT64)1<<(WORD32_BITS-1 - (scale)))) / ((_INT64)1<<(WORD32_BITS-1))) + +/*! + \def Macro converts a Word16 fixed point < 1 to float shifts result left by scale +*/ +#define WORD162FL_SCALE(x,scale) ( ((float)((_LONG)(x))) / (((_INT64)1<<(WORD16_BITS-1 - (scale)))) ) + +/*! + \def Macro converts a float < 1 to Word16 fixed point with saturation and rounding, shifts result right by scale +*/ +/* Note: At compile time, x must be a float constant and scale must be an integer constant in range -15..15 */ +#define FL2WORD16_SCALE(x,scale) FL2WORD16((float)(x) *(((_INT64)1<<(WORD16_BITS-1 - (scale)))) / ((_INT64)1<<(WORD16_BITS-1))) + + +/* Word16 Packed Type */ +typedef struct +{ + struct + { + Word16 re; + Word16 im; + } v; +} PWord16; + +#endif /* __BASOP_SETTINGS_H */ diff --git a/src/libs/libevs/lib_com/basop_tcx_utils.cpp b/src/libs/libevs/lib_com/basop_tcx_utils.cpp new file mode 100644 index 00000000..49260ebd --- /dev/null +++ b/src/libs/libevs/lib_com/basop_tcx_utils.cpp @@ -0,0 +1,407 @@ +/*==================================================================================== + EVS Codec 3GPP TS26.443 Nov 13, 2018. Version 12.11.0 / 13.7.0 / 14.3.0 / 15.1.0 + ====================================================================================*/ + + +#include +#include +#include +#include "options.h" +#include "cnst.h" +#include "basop_proto_func.h" +#include "stl.h" +#include "prot.h" +#include "rom_com.h" + +/* compare two positive normalized 16 bit mantissa/exponent values */ +/* return value: positive if first value greater, negative if second value greater, zero if equal */ +static Word16 compMantExp16Unorm(Word16 m1, Word16 e1, Word16 m2, Word16 e2) +{ + Word16 tmp; + + assert((m1 >= 0x4000) && (m2 >= 0x4000)); /* comparisons below work only for normalized mantissas */ + + tmp = sub(e1, e2); + if (tmp == 0) tmp = sub(m1, m2); + + return tmp; +} + +void basop_lpc2mdct(Word16 *lpcCoeffs, Word16 lpcOrder, + Word16 *mdct_gains, Word16 *mdct_gains_exp, + Word16 *mdct_inv_gains, Word16 *mdct_inv_gains_exp) +{ + Word32 RealData[FDNS_NPTS]; + Word32 ImagData[FDNS_NPTS]; + Word16 i, j, k, step, scale, s, tmp16; + Word16 g, g_e, ig, ig_e; + Word32 tmp32; + const PWord16 *ptwiddle; + + + + /* short-cut, to avoid calling of BASOP_getTables() */ + ptwiddle = SineTable512_fx; + step = 8; + + /*ODFT*/ + assert(lpcOrder < FDNS_NPTS); + + /* pre-twiddle */ + FOR (i=0; i<=lpcOrder; i++) + { + RealData[i] = L_mult(lpcCoeffs[i], ptwiddle->v.re); + move32(); + ImagData[i] = L_negate(L_mult(lpcCoeffs[i], ptwiddle->v.im)); + move32(); + ptwiddle += step; + } + + /* zero padding */ + FOR ( ; i 0) pg = shr(pg, tmp); + if (tmp < 0) g = shl(g, tmp); + e = s_max(gains_exp[j], gains_exp[jp]); + + tmp = mac_r(L_mult(pg, FL2WORD16(0.375f)), g, FL2WORD16(0.625f)); + x[i] = L_shl(Mpy_32_16(x[i], tmp), e); + move32(); + + tmp = mac_r(L_mult(pg, FL2WORD16(0.125f)), g, FL2WORD16(0.875f)); + x[i+1] = L_shl(Mpy_32_16(x[i+1], tmp), e); + move32(); + + /* common exponent for g and ng */ + g = gains[j]; + move16(); + tmp = sub(gains_exp[j], gains_exp[jn]); + if (tmp > 0) ng = shr(ng, tmp); + if (tmp < 0) g = shl(g, tmp); + e = s_max(gains_exp[j], gains_exp[jn]); + + tmp = mac_r(L_mult(g, FL2WORD16(0.875f)), ng, FL2WORD16(0.125f)); + x[i+2] = L_shl(Mpy_32_16(x[i+2], tmp), e); + move32(); + + tmp = mac_r(L_mult(g, FL2WORD16(0.625f)), ng, FL2WORD16(0.375f)); + x[i+3] = L_shl(Mpy_32_16(x[i+3], tmp), e); + move32(); + + jp = j; + move16(); + j = jn; + move16(); + jn = s_min(add(jn, 1), FDNS_NPTS-1); + } + } + ELSE IF (sub(k, 5) == 0) + { + jp = 0; + move16(); + j = 0; + move16(); + jn = 1; + move16(); + + FOR (i = 0; i < lg; i += 5) + { + pg = gains[jp]; + move16(); + g = gains[j]; + move16(); + ng = gains[jn]; + move16(); + + /* common exponent for pg and g */ + tmp = sub(gains_exp[j], gains_exp[jp]); + if (tmp > 0) pg = shr(pg, tmp); + if (tmp < 0) g = shl(g, tmp); + e = s_max(gains_exp[j], gains_exp[jp]); + + tmp = mac_r(L_mult(pg, FL2WORD16(0.40f)), g, FL2WORD16(0.60f)); + x[i] = L_shl(Mpy_32_16(x[i], tmp), e); + move32(); + + tmp = mac_r(L_mult(pg, FL2WORD16(0.20f)), g, FL2WORD16(0.80f)); + x[i+1] = L_shl(Mpy_32_16(x[i+1], tmp), e); + move32(); + + + x[i+2] = L_shl(Mpy_32_16(x[i+2], gains[j]), gains_exp[j]); + move32(); + + /* common exponent for g and ng */ + g = gains[j]; + move16(); + tmp = sub(gains_exp[j], gains_exp[jn]); + if (tmp > 0) ng = shr(ng, tmp); + if (tmp < 0) g = shl(g, tmp); + e = s_max(gains_exp[j], gains_exp[jn]); + + tmp = mac_r(L_mult(g, FL2WORD16(0.80f)), ng, FL2WORD16(0.20f)); + x[i+3] = L_shl(Mpy_32_16(x[i+3], tmp), e); + move32(); + + tmp = mac_r(L_mult(g, FL2WORD16(0.60f)), ng, FL2WORD16(0.40f)); + x[i+4] = L_shl(Mpy_32_16(x[i+4], tmp), e); + move32(); + + jp = j; + move16(); + j = jn; + move16(); + jn = s_min(add(jn, 1), FDNS_NPTS-1); + } + } + ELSE /* no interpolation */ + { + FOR (i = 0; i < FDNS_NPTS; i++) + { + FOR (l = 0; l < k; l++) + { + *x = L_shl(Mpy_32_16(*x, *gains), *gains_exp); + move32(); + x++; + } + + gains++; + gains_exp++; + } + } + } + +} + + +void basop_PsychAdaptLowFreqDeemph(Word32 x[], + const Word16 lpcGains[], const Word16 lpcGains_e[], + Word16 lf_deemph_factors[] + ) +{ + Word16 i; + Word16 max, max_e, fac, min, min_e, tmp, tmp_e; + Word32 L_tmp; + + + + assert(lpcGains[0] >= 0x4000); + + max = lpcGains[0]; + move16(); + max_e = lpcGains_e[0]; + move16(); + min = lpcGains[0]; + move16(); + min_e = lpcGains_e[0]; + move16(); + + /* find minimum (min) and maximum (max) of LPC gains in low frequencies */ + FOR (i = 1; i < 9; i++) + { + IF (compMantExp16Unorm(lpcGains[i], lpcGains_e[i], min, min_e) < 0) + { + min = lpcGains[i]; + move16(); + min_e = lpcGains_e[i]; + move16(); + } + + IF (compMantExp16Unorm(lpcGains[i], lpcGains_e[i], max, max_e) > 0) + { + max = lpcGains[i]; + move16(); + max_e = lpcGains_e[i]; + move16(); + } + } + + min_e = add(min_e, 5); /* min *= 32.0f; */ + + test(); + IF ((compMantExp16Unorm(max, max_e, min, min_e) < 0) && (min > 0)) + { + /* fac = tmp = (float)pow(max / min, 0.0078125f); */ + tmp_e = min_e; + move16(); + tmp = Inv16(min, &tmp_e); + L_tmp = L_shl(L_mult(tmp, max), add(tmp_e, max_e)); /* Q31 */ + L_tmp = BASOP_Util_Log2(L_tmp); /* Q25 */ + L_tmp = L_shr(L_tmp, 7); /* 0.0078125f = 1.f/(1<<7) */ + L_tmp = BASOP_Util_InvLog2(L_tmp); /* Q31 */ + tmp = round_fx(L_tmp); /* Q15 */ + fac = tmp; /* Q15 */ move16(); + + /* gradual lowering of lowest 32 bins; DC is lowered by (max/tmp)^1/4 */ + FOR (i = 31; i >= 0; i--) + { + x[i] = Mpy_32_16(x[i], fac); + move32(); + if (lf_deemph_factors != NULL) + { + lf_deemph_factors[i] = mult_r(lf_deemph_factors[i], fac); + move16(); + } + fac = mult_r(fac, tmp); + } + } + +} + + + diff --git a/src/libs/libevs/lib_com/basop_util.cpp b/src/libs/libevs/lib_com/basop_util.cpp old mode 100755 new mode 100644 index c85f5ce4..e2c5448d --- a/src/libs/libevs/lib_com/basop_util.cpp +++ b/src/libs/libevs/lib_com/basop_util.cpp @@ -1,24 +1,17 @@ /*==================================================================================== - EVS Codec 3GPP TS26.442 Apr 03, 2018. Version 12.11.0 / 13.6.0 / 14.2.0 + EVS Codec 3GPP TS26.443 Nov 13, 2018. Version 12.11.0 / 13.7.0 / 14.3.0 / 15.1.0 ====================================================================================*/ -#include "basop_util.h" -#include "rom_basop_util.h" -#include "basop_mpy.h" -#include "cnst_fx.h" -#include "control.h" -#include "options.h" #include #include - -#include "stl.h" - -#define DOT12_SUBDIV_LD 2 /* log2(number of dot product sub divisions) */ - -#define HP20_COEF_SCALE 2 -#define INV_BANDS10 3277 /* 1/10 in Q15 */ -#define INV_BANDS9 3641 /* 1/9 in Q15 */ +#include "options.h" +#include "basop_util.h" +#include "rom_com.h" +#include "basop_settings.h" +#include "basop_mpy.h" +#include "control.h" +#include "cnst.h" extern const Word32 SqrtTable[32]; extern const Word16 SqrtDiffTable[32]; @@ -38,13 +31,10 @@ Word32 BASOP_Util_Log2(Word32 x) Word16 accuSqr; Word32 accuRes; - - assert(x >= 0); if (x == 0) { - return ((Word32)MIN_32); } @@ -92,10 +82,10 @@ Word32 BASOP_Util_Log2(Word32 x) exp = L_shl(exp,(31-LD_DATA_SCALE)); /* integer part/LD_DATA_SCALE */ accuRes = L_sub(accuRes,exp); /* result = integer part + fractional part */ - return (accuRes); } + Word32 BASOP_Util_InvLog2(Word32 x) { Word16 frac; @@ -108,17 +98,13 @@ Word32 BASOP_Util_InvLog2(Word32 x) UWord32 lookup12; UWord32 lookup; - - - if ( x < -1040187392l/*-31.0/64.0 Q31*/ ) + if ( x < FL2WORD32(-31.0/64.0) ) { - return 0; } test(); - if ( (L_sub(x,1040187392l/*31.0/64.0 Q31*/) >= 0) || (x == 0) ) + if ( (L_sub(x,FL2WORD32(31.0/64.0)) >= 0) || (x == 0) ) { - return 0x7FFFFFFF; } @@ -138,13 +124,12 @@ Word32 BASOP_Util_InvLog2(Word32 x) exp = negate(exp); } - lookup3f = L_add(exp2x_tab_long[index3],L_shr(Mpy_32_16_1(0x0016302F,frac),1)); + lookup3f = L_add(exp2x_tab_long[index3],L_shr(Mpy_32_16(0x0016302F,frac),1)); lookup12 = Mpy_32_32(exp2_tab_long[index1],exp2w_tab_long[index2]); lookup = Mpy_32_32(lookup12, lookup3f); retVal = L_shr(lookup,sub(exp,3)); - return retVal; } @@ -159,8 +144,6 @@ Word16 BASOP_Util_Add_MantExp /*!< Exponent of result Word32 L_lm, L_hm; Word16 shift; - - /* Compare exponents: the difference is limited to +/- 15 The Word16 mantissa of the operand with higher exponent is moved into the low part of a Word32 and shifted left by the exponent difference. Then, the @@ -170,14 +153,14 @@ Word16 BASOP_Util_Add_MantExp /*!< Exponent of result including the final 16-bit extraction. Note: The resulting mantissa may be inaccurate in the case, where the mantissa of the operand with higher exponent is not really left-aligned, while the mantissa of the operand with - lower exponent is so. If in such a case, the difference in exponents is more than 15, - an inaccuracy is introduced. - Example: - A: a_e = 20, a_m = 0x0001 - B: b_e = 0, b_m = 0x4000 + lower exponent is so. If in such a case, the difference in exponents is more than 15, + an inaccuracy is introduced. + Example: + A: a_e = 20, a_m = 0x0001 + B: b_e = 0, b_m = 0x4000 correct: A+B=1*2^20+1*2^14=0x0010.0000+0x0000.4000=0x0010.4000=0x4100*2^6 - previously: A+B=1*2^20+1*2^14=0x0001+0x0000=0x0001*2^20 - this version: A+B=1*2^20+1*2^14=0x0000.8000+0x0000.4000=0x6000*2^6 + previously: A+B=1*2^20+1*2^14=0x0001+0x0000=0x0001*2^20 + this version: A+B=1*2^20+1*2^14=0x0000.8000+0x0000.4000=0x6000*2^6 */ shift = sub(a_e, b_e); @@ -208,67 +191,12 @@ Word16 BASOP_Util_Add_MantExp /*!< Exponent of result a_e = sub(a_e,shift); if (L_hm) a_e = add(a_e,16); + return (a_e); } -void BASOP_Util_Divide_MantExp (Word16 a_m, /*!< Mantissa of dividend a */ - Word16 a_e, /*!< Exponent of dividend a */ - Word16 b_m, /*!< Mantissa of divisor b */ - Word16 b_e, /*!< Exponent of divisor b */ - Word16 *ptrResult_m, /*!< Mantissa of quotient a/b */ - Word16 *ptrResult_e /*!< Exponent of quotient a/b */ - ) -{ - Word16 index, frac; - Word16 preShift, postShift; - Word16 m; - Word32 m32; - - - - assert(b_m != 0); - - /* normalize b */ - preShift = norm_s(b_m); - m = shl(b_m, preShift); - - /* make b positive */ - BASOP_SATURATE_WARNING_OFF; - if (m < 0) m = negate(m); - BASOP_SATURATE_WARNING_ON; - - /* get table index (upper 6 bits minus 16) */ - /* index = (m >> 9) - 32; */ - index = mac_r(-32768 - (32 << 16), m, 1 << 6); - - /* get fractional part for interpolation (lower 9 bits) */ - frac = shl(s_and(m, 0x1FF), 1); /* Q10 */ - - /* interpolate 1/b */ - m = msu_r(InvTable[index], InvDiffTable[index], frac); - - /* restore sign */ - if (b_m < 0) m = negate(m); - - /* multiply with a */ - m32 = L_mult(a_m, m); - - /* normalize result */ - postShift = norm_l(m32); - m = round_fx(L_shl(m32, postShift)); - - /* exponent */ - *ptrResult_e = sub(add(add(a_e, sub(1, b_e)), preShift), postShift); - move16(); - - *ptrResult_m = m; - move16(); - -} - - -/* local function for Sqrt16 and Sqrt16norm */ +/* local function for Sqrt16 */ static Word16 Sqrt16_common(Word16 m, Word16 e) { @@ -297,87 +225,6 @@ static Word16 Sqrt16_common(Word16 m, return m; } -/* local function for Sqrt32 and Sqrt32norm */ -static Word32 Sqrt32_common(Word32 m, - Word16 e) -{ - Word16 m16, index, frac; - - assert((m >= 0x40000000) || (m == 0)); - - m16 = round_fx(m); - - /* get table index (upper 6 bits minus 32) */ - /* index = (m16 >> 9) - 32; */ - index = mac_r(-32768 - (32 << 16), m16, 1 << 6); - - /* get fractional part for interpolation (lower 9 bits) */ - frac = s_and(m16, 0x1FF); /* Q9 */ - - /* interpolate */ - if (m != 0) - { - BASOP_SATURATE_WARNING_OFF; - m = L_mac(SqrtTable[index], SqrtDiffTable[index], frac); - BASOP_SATURATE_WARNING_ON; - } - - /* handle odd exponents */ - if (s_and(e, 1) != 0) m = Mpy_32_16_1(m, 0x5a82); - - return m; -} - -/* local function for ISqrt16 and ISqrt16norm */ -static Word16 ISqrt16_common(Word16 m, - Word16 e) -{ - Word16 index, frac; - - assert(m >= 0x4000); - - /* get table index (upper 6 bits minus 32) */ - /* index = (m >> 9) - 32; */ - index = mac_r(-32768 - (32 << 16), m, 1 << 6); - - /* get fractional part for interpolation (lower 9 bits) */ - frac = s_and(m, 0x1FF); /* Q9 */ - - /* interpolate */ - m = msu_r(ISqrtTable[index], ISqrtDiffTable[index], frac); - - /* handle even exponents */ - if (s_and(e, 1) == 0) m = mult_r(m, 0x5a82); - - return m; -} - -/* local function for ISqrt32 and ISqrt32norm */ -static Word32 ISqrt32_common(Word32 m, - Word16 e) -{ - Word16 m16, index, frac; - - assert(m >= 0x40000000); - - m16 = round_fx(m); - - /* get table index (upper 6 bits minus 32) */ - /* index = (m16 >> 25) - 32; */ - index = mac_r(-32768 - (32 << 16), m16, 1 << 6); - - /* get fractional part for interpolation (lower 9 bits) */ - frac = s_and(m16, 0x1FF); /* Q9 */ - - /* interpolate */ - m = L_msu(ISqrtTable[index], ISqrtDiffTable[index], frac); - - /* handle even exponents */ - if (s_and(e, 1) == 0) m = Mpy_32_16_1(m, 0x5a82); - - return m; -} - Word16 Sqrt16( /*!< output mantissa */ Word16 mantissa, /*!< input mantissa */ @@ -404,139 +251,6 @@ Word16 Sqrt16( /*!< output mantissa */ return mantissa; } -Word16 Sqrt16norm( /*!< output mantissa */ - Word16 mantissa, /*!< normalized input mantissa */ - Word16 *exponent /*!< pointer to exponent */ -) -{ - - assert((mantissa >= 0x4000) || (mantissa == 0)); - - /* calc mantissa */ - mantissa = Sqrt16_common(mantissa, *exponent); - - /* e = (e + 1) >> 1 */ - *exponent = mult_r(*exponent, 1 << 14); - move16(); - - return mantissa; -} - - -Word16 ISqrt16( /*!< output mantissa */ - Word16 mantissa, /*!< input mantissa */ - Word16 *exponent /*!< pointer to exponent */ -) -{ - Word16 preShift, e; - - assert(mantissa > 0); - - /* normalize */ - preShift = norm_s(mantissa); - - e = sub(*exponent, preShift); - mantissa = shl(mantissa, preShift); - - /* calc mantissa */ - mantissa = ISqrt16_common(mantissa, e); - - /* e = (2 - e) >> 1 */ - *exponent = msu_r(1L << 15, e, 1 << 14); - move16(); - - return mantissa; -} - - -Word32 Sqrt32( /*!< output mantissa */ - Word32 mantissa, /*!< input mantissa */ - Word16 *exponent /*!< pointer to exponent */ -) -{ - Word16 preShift, e; - - assert(mantissa >= 0); - - /* normalize */ - preShift = norm_l(mantissa); - - e = sub(*exponent, preShift); - mantissa = L_shl(mantissa, preShift); - - /* calc mantissa */ - mantissa = Sqrt32_common(mantissa, e); - - /* e = (e + 1) >> 1 */ - *exponent = mult_r(e, 1 << 14); - move16(); - - return mantissa; -} - -Word32 Sqrt32norm( /*!< output mantissa */ - Word32 mantissa, /*!< normalized input mantissa */ - Word16 *exponent /*!< pointer to exponent */ -) -{ - - assert((mantissa >= 0x40000000) || (mantissa == 0)); - - /* calc mantissa */ - mantissa = Sqrt32_common(mantissa, *exponent); - - /* e = (e + 1) >> 1 */ - *exponent = mult_r(*exponent, 1 << 14); - move16(); - - return mantissa; -} - - -Word32 ISqrt32( /*!< output mantissa */ - Word32 mantissa, /*!< input mantissa */ - Word16 *exponent /*!< pointer to exponent */ -) -{ - Word16 preShift, e; - - assert(mantissa > 0); - - /* normalize */ - preShift = norm_l(mantissa); - - e = sub(*exponent, preShift); - mantissa = L_shl(mantissa, preShift); - - /* calc mantissa */ - mantissa = ISqrt32_common(mantissa, e); - - /* e = (2 - e) >> 1 */ - *exponent = msu_r(1L << 15, e, 1 << 14); - move16(); - - return mantissa; -} - -Word32 ISqrt32norm( /*!< output mantissa */ - Word32 mantissa, /*!< normalized input mantissa */ - Word16 *exponent /*!< pointer to exponent */ -) -{ - - assert(mantissa >= 0x40000000); - - /* calc mantissa */ - mantissa = ISqrt32_common(mantissa, *exponent); - - /* e = (2 - e) >> 1 */ - *exponent = msu_r(1L << 15, *exponent, 1 << 14); - move16(); - - return mantissa; -} - - Word16 Inv16( /*!< output mantissa */ Word16 mantissa, /*!< input mantissa */ Word16 *exponent /*!< pointer to exponent */ @@ -546,8 +260,6 @@ Word16 Inv16( /*!< output mantissa */ Word16 preShift; Word16 m, e; - - assert(mantissa != 0); /* absolute */ @@ -594,8 +306,6 @@ void BASOP_Util_Sqrt_InvSqrt_MantExp (Word16 mantissa, /*!< mantissa */ Word16 preShift; Word16 m, mi, e_odd; - - assert(mantissa > 0); /* normalize */ @@ -638,55 +348,6 @@ void BASOP_Util_Sqrt_InvSqrt_MantExp (Word16 mantissa, /*!< mantissa */ } -/********************************************************************/ -/*! - \brief Calculates the scalefactor needed to normalize input array - - The scalefactor needed to normalize the Word16 input array is returned
- If the input array contains only '0', a scalefactor 0 is returned
- Scaling factor is determined wrt a normalized target x: 16384 <= x <= 32767 for positive x
- and -32768 <= x <= -16384 for negative x -*/ - -Word16 getScaleFactor16( /* o: measured headroom in range [0..15], 0 if all x[i] == 0 */ - const Word16 *x, /* i: array containing 16-bit data */ - const Word16 len_x) /* i: length of the array to scan */ -{ - Word16 i, i_min, i_max; - Word16 x_min, x_max; - - - - x_max = 0; - move16(); - x_min = 0; - move16(); - FOR (i = 0; i < len_x; i++) - { - if (x[i] >= 0) - x_max = s_max(x_max,x[i]); - if (x[i] < 0) - x_min = s_min(x_min,x[i]); - } - - i_max = 0x10; - move16(); - i_min = 0x10; - move16(); - - if (x_max != 0) - i_max = norm_s(x_max); - - if (x_min != 0) - i_min = norm_s(x_min); - - i = s_and(s_min(i_max, i_min),0xF); - - - return i; -} - - /********************************************************************/ /*! \brief Calculates the scalefactor needed to normalize input array @@ -697,15 +358,13 @@ Word16 getScaleFactor16( /* o: measured headroom in range [0..15 and -2147483648 <= x <= -1073741824 for negative x */ -Word16 getScaleFactor32( /* o: measured headroom in range [0..31], 0 if all x[i] == 0 */ +Word16 getScaleFactor32( /* o: measured headroom in range [0..31], 0 if all x[i] == 0 */ const Word32 *x, /* i: array containing 32-bit data */ const Word16 len_x) /* i: length of the array to scan */ { Word16 i, i_min, i_max; Word32 x_min, x_max; - - x_max = L_add(0, 0); x_min = L_add(0, 0); FOR (i = 0; i < len_x; i++) @@ -729,221 +388,9 @@ Word16 getScaleFactor32( /* o: measured headroom in range [0..31], i = s_and(s_min(i_max, i_min),0x1F); - return i; } -Word16 normalize16(Word16 mantissa, Word16 *pexponent) -{ - Word16 tmp; - - tmp = norm_s(mantissa); - mantissa = shl(mantissa, tmp); - move16(); - *pexponent = sub(*pexponent, tmp); - - - return mantissa; -} -Word16 divide3216(Word32 x, Word16 y) -{ - Word16 z; - - - z = 0; - move16(); - if (0 == y) - { - return 0x7fff; - } - - IF (x != 0) - { - Word16 den, sign; - Word32 num; - num = L_abs(x); - den = abs_s(y); - - sign = s_and(s_xor(extract_h(x),y),-32768 /* 0x8000 */); - - z = div_l(num,den); - if (0 != sign) - { - z = negate(z); - } - } - - - return z; -} - -Word16 divide1616(Word16 x, Word16 y) -{ - Word16 z, num, den, sign; - - - num = abs_s(x); - den = abs_s(y); - - sign = s_and(s_xor(x,y),-32768 /* 0x8000 */); - - move16(); - z = 0x7fff; - if ( sub(num, den) < 0) - z = div_s(num,den); - - if (0 != sign) - { - z = negate(z); - } - - - return z; -} - -Word16 divide3232(Word32 L_num, Word32 L_denom) -{ - Word16 z; - Word32 sign; - - - sign = L_and(L_xor(L_num,L_denom),0x80000000); - - L_num = L_abs(L_num); - L_denom = L_abs(L_denom); - - /* limit the range of denominator to Word16 */ - z = s_min(norm_l(L_num),norm_l(L_denom)); - L_num = L_shl(L_num,z); - L_denom = L_shl(L_denom,z); - - /* round_fx instead of extract_h improves spectral distortion in E_UTIL_lev_dur (schur version). */ - z = div_l(L_num,round_fx(L_denom)); - if (0 != sign) - { - z = negate(z); - } - - - return z; -} - -Word16 BASOP_Util_Divide3232_uu_1616_Scale(Word32 x, Word32 y, Word16 *s) -{ - Word16 z; - Word16 sx; - Word16 sy; - Word16 x16; - Word16 y16; - - - - assert(x >= 0); - assert(y > 0); - - if ( x == 0 ) - { - *s = 0; - move16(); - - - return (0); - } - - sx = norm_l(x); - sy = norm_l(y); - - x16 = extract_h(L_shl(x,sx)); - y16 = extract_h(L_shl(y,sy)); - - if(sub(x16,y16) > 0) - { - sx = sub(sx,1); - } - - if(sub(y16,x16) < 0) - { - x16 = mult_r(x16,0x4000); - } - - - z = div_s(x16,y16); - move16(); - *s = sub(sy,sx); - - - return (z); -} - -Word16 BASOP_Util_Divide3232_Scale(Word32 x, Word32 y, Word16 *s) -{ - Word16 z; - Word16 sy; - - - - sy = norm_l(y); - if (sy > 0) - { - sy = sub(sy,1); - } - y = L_shl(y,sy); - - z = BASOP_Util_Divide3216_Scale(x, extract_h(y), s); - move16(); - *s = add(*s,sy); - - - return (z); -} - -Word16 BASOP_Util_Divide3216_Scale( /* o: result of division x/y, not normalized */ - Word32 x, /* i: numerator, signed */ - Word16 y, /* i: denominator, signed */ - Word16 *s) /* o: scaling, 0, if x==0 */ -{ - Word16 z; - Word16 sx; - Word16 sy; - Word16 sign; - - - - /*assert (x > (Word32)0); - assert (y >= (Word16)0);*/ - - /* check, if numerator equals zero, return zero then */ - IF ( x == (Word32)0 ) - { - move16(); - *s = 0; - - - return ((Word16)0); - } - - sign = s_xor(extract_h(x),y); /* just to exor the sign bits */ - BASOP_SATURATE_WARNING_OFF - x = L_abs(x); - y = abs_s(y); - BASOP_SATURATE_WARNING_ON - sx = sub(norm_l(x),1); - x = L_shl(x,sx); - sy = norm_s(y); - y = shl(y,sy); - *s = sub(sy,sx); - move16(); - - z = div_s(round_fx(x),y); - - if ( sign < 0 ) /* if sign bits differ, negate the result */ - { - z = negate(z); - } - - - return z; -} Word16 BASOP_Util_Divide1616_Scale(Word16 x, Word16 y, Word16 *s) { @@ -952,8 +399,6 @@ Word16 BASOP_Util_Divide1616_Scale(Word16 x, Word16 y, Word16 *s) Word16 sy; Word16 sign; - - /* assert (x >= (Word16)0); */ assert (y != (Word16)0); @@ -977,7 +422,6 @@ Word16 BASOP_Util_Divide1616_Scale(Word16 x, Word16 y, Word16 *s) move16(); *s = 0; - return ((Word16)0); } @@ -999,95 +443,47 @@ Word16 BASOP_Util_Divide1616_Scale(Word16 x, Word16 y, Word16 *s) z = negate(z); } - return z; } -void copyWord8(const Word8 *src, Word8 *dst, const Word32 n) + +void set_val_Word16(Word16 X[], const Word16 val, Word16 n) { - Word32 i; + Word16 i; - FOR (i=0; i= 0) - { - /* Yes */ - temp = temp2; - move16(); - } - return temp; -} -Word16 findIndexOfMinWord32(Word32 *x, const Word16 len) -{ - Word16 i, indx; - - - indx = 0; - move16(); - FOR (i = 1; i < len; i++) - { - if (L_sub(x[i],x[indx]) < 0) - { - indx = i; - move16(); - } - } - - - return indx; -} - - -Word16 imult1616(Word16 x, Word16 y) -{ - assert((int)x * (int)y < 32768 && (int)x * (int)y >= -32768); - return extract_l(L_mult0(x, y)); -} - -Word32 imult3216(Word32 x, Word16 y) -{ - Word32 mh; - UWord16 ml; - - Mpy_32_16_ss(x, y, &mh, &ml); - - mh = L_shl(mh, 15); - ml = lshr(ml, 1); - - return L_or(mh, L_deposit_l(ml)); -} - Word16 idiv1616U(Word16 x, Word16 y) { - Word16 sx, sy; - - /* make y > x to meet the requirements for div_s parameters */ - sx = norm_s(x); - sy = norm_s(y); - x = shl(x, sx); - y = shl(y, sy); - - if (x >= y) - { - x = shr(x,1); - sx = sub(sx,1); - } - - /* divide and shift */ - y = shr(div_s(x, y), sub(15, sub(sy,sx))); - - return y; -} + Word16 s; -Word16 idiv1616(Word16 x, Word16 y) -{ - Word16 s, num, den, sign; - - - num = abs_s(x); - den = abs_s(y); - - sign = s_and(s_xor(x,y),-32768 /* 0x8000 */); - - /* make num > den */ - s = add(sub(norm_s(den), norm_s(num)), 1); + /* make y > x */ + s = add(sub(norm_s(y), norm_s(x)), 1); s = s_max(s, 0); - den = shl(den, s); + BASOP_SATURATE_WARNING_OFF + y = shl(y, s); + BASOP_SATURATE_WARNING_ON /* divide and shift */ - y = shr(div_s(num, den), sub(15, s)); - - if (0 != sign) - { - y = negate(y); - } + y = shr(div_s(x, y), sub(15, s)); return y; } -Word32 norm_llQ31( /* o : normalized result Q31 */ - Word32 L_c, /* i : upper bits of accu Q-1 */ - Word32 L_sum, /* i : lower bits of accu, unsigned Q31 */ - Word16 * exp /* o : exponent of result in [-32,31] Q0 */ -) -{ - Word16 i; - Word32 L_tmp; - - /* Move MSBit of L_sum into L_c */ - Carry = 0; - L_tmp = L_add_c(L_sum, L_sum); /* L_tmp = L_sum << 1 */ - L_c = L_add_c(L_c,L_c); - L_add(0,0); - test(); - IF ((L_c != (Word32) 0L) && (L_c != (Word32) 0xFFFFFFFFL)) - { - i = norm_l(L_c); - L_c = L_shl(L_c,i); - i = sub(31,i); /* positive exponent */ - L_sum = L_lshr(L_tmp, 1); /* L_sum with MSBit=0 */ - L_sum = L_lshr(L_sum, i); - L_sum = L_add(L_c,L_sum); - } - ELSE - { - i = -32; - move16(); /* default exponent, if total sum=0 */ - IF (L_sum) - { - i = norm_l(L_sum); - L_sum = L_shl(L_sum,i); - i = negate(i); /* negative or zero exponent */ - } - } - *exp = i; - move16(); - return L_sum; -} - - -Word32 Dot_product16HQ( /* o : normalized result Q31 */ - const Word32 L_off, /* i : initial sum value Qn */ - const Word16 x[], /* i : x vector Qn */ - const Word16 y[], /* i : y vector Qn */ - const Word16 lg, /* i : vector length, range [0..7FFF] Q0 */ - Word16 * exp /* o : exponent of result in [-32,31] Q0 */ -) -{ - Word16 i; - Word32 L_sum, L_c, L_test; - /* Clear carry flag and init sum */ - Carry = 0; - L_c = L_add(0,0); - L_sum = L_macNs(L_off,0,0); - if (L_sum > 0) - L_c = L_macNs(L_c,0,0); - if (L_sum < 0) - L_c = L_msuNs(L_c,0,0); - - FOR (i=0; i < lg; i++) - { - BASOP_SATURATE_WARNING_OFF /*in case of both multiplicands being -32768, overflow occurs - not severe*/ - L_test = L_mult(x[i], y[i]); - BASOP_SATURATE_WARNING_ON - Carry = 0; - L_sum = L_macNs(L_sum, x[i], y[i]); - Overflow = 0; /* to avoid useless warning in L_macNs/L_msuNs calling L_mult */ - if (L_test >= 0) - L_c = L_macNs(L_c,0,0); - if (L_test < 0) - L_c = L_msuNs(L_c,0,0); - } - L_sum = norm_llQ31(L_c,L_sum,exp); - return L_sum; -} - -Word32 Norm32Norm(const Word32 *x, const Word16 headroom, const Word16 length, Word16 *result_e) -{ - Word32 L_tmp, L_tmp2; - Word16 i, shift, tmp; - - move16(); - shift = headroom; - - L_tmp = L_deposit_l(0); - - FOR (i=0; i= 0) shift = sub(shift,1); - if (L_tmp2 >= 0) L_tmp = L_shr(L_tmp, 2); - - tmp = round_fx(L_shl(x[i], shift)); - L_tmp = L_mac0(L_tmp, tmp, tmp); /* exponent = (1-shift*2) , Q(30+shift*2) */ - } - - move16(); - *result_e = sub(1, shl(shift,1)); - - return L_tmp; -} - -Word32 Dot_productSq16HQ( /* o : normalized result Q31 */ - const Word32 L_off, /* i : initial sum value Qn */ - const Word16 x[], /* i : x vector Qn */ - const Word16 lg, /* i : vector length, range [0..7FFF] Q0 */ - Word16 * exp /* o : exponent of result in [-32,31] Q0 */ -) -{ - Word16 i; - Word32 L_sum, L_c; - /* Clear carry flag and init sum */ - Carry = 0; - L_c = L_add(0,0); - L_sum = L_macNs(L_off,0,0); - if (L_sum > 0) - L_c = L_macNs(L_c,0,0); - if (L_sum < 0) - L_c = L_msuNs(L_c,0,0); - - FOR (i=0; i < lg; i++) - { - Carry = 0; - BASOP_SATURATE_WARNING_OFF /*multiplication of -32768 * -32768 throws an overflow, but is not critical*/ - L_sum = L_macNs(L_sum, x[i], x[i]); - BASOP_SATURATE_WARNING_ON - Overflow = 0; /* to avoid useless warning in L_macNs calling L_mult */ - L_c = L_macNs(L_c,0,0); - } - L_sum = norm_llQ31(L_c,L_sum,exp); - return L_sum; -} - -Word32 dotp_s_fx(const Word16 *x, const Word16 *y, const Word16 n, Word16 s) -{ - Word16 i; - Word16 n2; - Word32 L_tmp; - Word32 L_sum; - - - L_sum = L_add(0,0); - - n2 = shr(n,1); - - s = sub(s,1); - - FOR (i=0; i < n2; i++) - { - L_tmp = L_mult0(x[2*i], y[2*i]); - L_tmp = L_mac0(L_tmp, x[2*i+1], y[2*i+1]); - L_sum = L_add(L_sum, L_shr(L_tmp, s)); - } - - IF ( s_and(n,1) ) - { - L_tmp = L_mult0(x[n-1], y[n-1]); - L_sum = L_add(L_sum, L_shr(L_tmp, s)); - } - - - return L_sum; -} - Word32 BASOP_util_Pow2( const Word32 exp_m, const Word16 exp_e, Word16 *result_e @@ -1538,21 +613,18 @@ Word32 BASOP_util_Pow2( { static const Word16 pow2Coeff[8] = { - 22713/*0.693147180559945309417232121458177 Q15*/, /* ln(2)^1 /1! */ - 7872/*0.240226506959100712333551263163332 Q15*/, /* ln(2)^2 /2! */ - 1819/*0.0555041086648215799531422637686218 Q15*/, /* ln(2)^3 /3! */ - 315/*0.00961812910762847716197907157365887 Q15*/, /* ln(2)^4 /4! */ - 44/*0.00133335581464284434234122219879962 Q15*/, /* ln(2)^5 /5! */ - 5/*1.54035303933816099544370973327423e-4 Q15*/, /* ln(2)^6 /6! */ - 0/*1.52527338040598402800254390120096e-5 Q15*/, /* ln(2)^7 /7! */ - 0/*1.32154867901443094884037582282884e-6 Q15*/ /* ln(2)^8 /8! */ + FL2WORD16(0.693147180559945309417232121458177), /* ln(2)^1 /1! */ + FL2WORD16(0.240226506959100712333551263163332), /* ln(2)^2 /2! */ + FL2WORD16(0.0555041086648215799531422637686218), /* ln(2)^3 /3! */ + FL2WORD16(0.00961812910762847716197907157365887), /* ln(2)^4 /4! */ + FL2WORD16(0.00133335581464284434234122219879962), /* ln(2)^5 /5! */ + FL2WORD16(1.54035303933816099544370973327423e-4), /* ln(2)^6 /6! */ + FL2WORD16(1.52527338040598402800254390120096e-5), /* ln(2)^7 /7! */ + FL2WORD16(1.32154867901443094884037582282884e-6) /* ln(2)^8 /8! */ }; - Word32 frac_part, tmp_frac, result_m; - Word16 int_part; - - int_part = 0; /* to avoid compilation warnings */ - frac_part = 0; /* to avoid compilation warnings */ + Word32 frac_part = 0, tmp_frac, result_m; + Word16 int_part = 0; IF (exp_e > 0) { @@ -1571,15 +643,15 @@ Word32 BASOP_util_Pow2( } /* Best accuracy is around 0, so try to get there with the fractional part. */ - IF( (tmp_frac = L_sub(frac_part,1073741824l/*0.5 Q31*/)) >= 0) + IF( (tmp_frac = L_sub(frac_part,FL2WORD32(0.5))) >= 0) { int_part = add(int_part, 1); - frac_part = L_sub(tmp_frac,1073741824l/*0.5 Q31*/); + frac_part = L_sub(tmp_frac,FL2WORD32(0.5)); } - ELSE IF( (tmp_frac = L_add(frac_part,1073741824l/*0.5 Q31*/)) < 0) + ELSE IF( (tmp_frac = L_add(frac_part,FL2WORD32(0.5))) < 0) { int_part = sub(int_part, 1); - frac_part = L_add(tmp_frac,1073741824l/*0.5 Q31*/); + frac_part = L_add(tmp_frac,FL2WORD32(0.5)); } /* Evaluate taylor polynomial which approximates 2^x */ @@ -1589,56 +661,165 @@ Word32 BASOP_util_Pow2( /* First taylor series coefficient a_0 = 1.0, scaled by 0.5 due to L_shr(,1). */ - result_m = L_add(1073741824l/*1.0/2.0 Q31*/,L_shr(Mpy_32_16_1(frac_part, pow2Coeff[0]), 1)); + result_m = L_add(FL2WORD32(1.0/2.0),L_shr(Mpy_32_16(frac_part, pow2Coeff[0]), 1)); p = Mpy_32_32(frac_part, frac_part); FOR (i = 1; i < 7; i++) { /* next taylor series term: a_i * x^i, x=0 */ - result_m = L_add(result_m, L_shr(Mpy_32_16_1(p, pow2Coeff[i]), 1)); + result_m = L_add(result_m, L_shr(Mpy_32_16(p, pow2Coeff[i]), 1)); p = Mpy_32_32(p, frac_part); } - result_m = L_add(result_m, L_shr(Mpy_32_16_1(p, pow2Coeff[i]), 1)); + result_m = L_add(result_m, L_shr(Mpy_32_16(p, pow2Coeff[i]), 1)); } *result_e = int_part; move16(); + return result_m; } -Word16 findIndexOfMaxWord32(Word32 *x, const Word16 len) + +Word16 BASOP_Util_Divide3216_Scale( /* o: result of division x/y, not normalized */ + Word32 x, /* i: numerator, signed */ + Word16 y, /* i: denominator, signed */ + Word16 *s) /* o: scaling, 0, if x==0 */ { - Word16 i, indx; + Word16 z; + Word16 sx; + Word16 sy; + Word16 sign; + /*assert (x > (Word32)0); + assert (y >= (Word16)0);*/ - indx = 0; - move16(); - FOR (i = 1; i < len; i++) + /* check, if numerator equals zero, return zero then */ + IF ( x == (Word32)0 ) { - if (L_sub(x[i],x[indx]) > 0) - { - indx = i; - move16(); - } + *s = 0; + move16(); + + return ((Word16)0); } + sign = s_xor(extract_h(x),y); /* just to exor the sign bits */ + BASOP_SATURATE_WARNING_OFF + x = L_abs(x); + y = abs_s(y); + BASOP_SATURATE_WARNING_ON + sx = sub(norm_l(x),1); + x = L_shl(x,sx); + sy = norm_s(y); + y = shl(y,sy); + *s = sub(sy,sx); + move16(); - return indx; + z = div_s(round_fx(x),y); + + if ( sign < 0 ) /* if sign bits differ, negate the result */ + { + z = negate(z); + } + + return z; } -Word16 getNormReciprocalWord16(Word16 x) +static const Word16 table_pow2[32] = { - - assert(x < (Word16)(sizeof(BASOP_util_normReciprocal)/sizeof(BASOP_util_normReciprocal[0]))); - - return extract_h(BASOP_util_normReciprocal[x]); -} -Word16 getNormReciprocalWord16Scale(Word16 x, Word16 s) + 16384, 16743, 17109, 17484, 17867, 18258, 18658, 19066, 19484, 19911, + 20347, 20792, 21247, 21713, 22188, 22674, 23170, 23678, 24196, 24726, + 25268, 25821, 26386, 26964, 27554, 28158, 28774, 29405, 30048, 30706, + 31379, 32066 +}; +/* table of table_pow2[i+1] - table_pow2[i] */ +static const Word16 table_pow2_diff_x32[32] = { + 11488, 11712, 12000, 12256, 12512, 12800, 13056, 13376, 13664, 13952, + 14240, 14560, 14912, 15200, 15552, 15872, 16256, 16576, 16960, 17344, + 17696, 18080, 18496, 18880, 19328, 19712, 20192, 20576, 21056, 21536, + 21984, 22432 +}; - assert(x < (Word16)(sizeof(BASOP_util_normReciprocal)/sizeof(BASOP_util_normReciprocal[0]))); +Word32 Pow2( /* (o) Q0 : result (range: 0<=val<=0x7fffffff) */ + Word16 exponant, /* (i) Q0 : Integer part. (range: 0<=val<=30) */ + Word16 fraction /* (i) Q15 : Fractional part. (range: 0.0<=val<1.0) */ +) +{ + Word16 exp, i, a; + Word32 L_x; - return round_fx(L_shl(BASOP_util_normReciprocal[x],s)); + i = mac_r(-32768, fraction, 32); /* Extract b10-b16 of fraction */ + a = s_and(fraction, 0x3ff); /* Extract b0-b9 of fraction */ + + L_x = L_deposit_h(table_pow2[i]); /* table[i] << 16 */ + L_x = L_mac(L_x, table_pow2_diff_x32[i], a);/* L_x -= diff*a*2 */ + + exp = sub(30, exponant); + + L_x = L_shr_r(L_x, exp); + + return L_x; } +/************************************************************************* + * + * FUNCTION: Log2_norm() + * + * PURPOSE: Computes log2(L_x, exp), where L_x is positive and + * normalized, and exp is the normalisation exponent + * If L_x is negative or zero, the result is 0. + * + * DESCRIPTION: + * The function Log2(L_x) is approximated by a table and linear + * interpolation. The following steps are used to compute Log2(L_x) + * + * 1- exponent = 30-norm_exponent + * 2- i = bit25-b31 of L_x; 32<=i<=63 (because of normalization). + * 3- a = bit10-b24 + * 4- i -=32 + * 5- fraction = table[i]<<16 - (table[i] - table[i+1]) * a * 2 + * + *************************************************************************/ + +static const Word32 L_table[32] = +{ + -32768L, 95322112L, 187793408L, 277577728L, + 364871680L, 449740800L, 532381696L, 612859904L, + 691306496L, 767787008L, 842432512L, 915308544L, + 986546176L, 1056210944L, 1124302848L, 1190887424L, + 1256095744L, 1319993344L, 1382580224L, 1443921920L, + 1504083968L, 1563131904L, 1621000192L, 1677885440L, + 1733722112L, 1788510208L, 1842380800L, 1895399424L, + 1947435008L, 1998618624L, 2049015808L, 2098626560L +}; + +static const Word16 table_diff[32] = +{ + 1455, 1411, 1370, 1332, 1295, 1261, 1228, 1197, + 1167, 1139, 1112, 1087, 1063, 1039, 1016, 995, + 975, 955, 936, 918, 901, 883, 868, 852, + 836, 822, 809, 794, 781, 769, 757, 744 +}; + +Word16 Log2_norm_lc ( /* (o) : Fractional part of Log2. (range: 0<=val<1) */ + Word32 L_x /* (i) : input value (normalized) */ +) +{ + Word16 i, a; + Word16 y; + + + L_x = L_shr (L_x, 9); + a = extract_l (L_x); /* Extract b10-b24 of fraction */ + a = lshr(a, 1); + + i = mac_r(L_x, -32*2-1, 16384); /* Extract b25-b31 minus 32 */ + + y = mac_r(L_table[i], table_diff[i], a);/* table[i] << 16 - diff*a*2 */ + + + return y; +} + + Word32 BASOP_Util_fPow( Word32 base_m, Word16 base_e, Word32 exp_m, Word16 exp_e, @@ -1650,7 +831,6 @@ Word32 BASOP_Util_fPow( Word32 base_lg2_m, ans_lg2_m, result_m; Word16 shift; - test(); IF ((base_m == 0) && (exp_m != 0)) { @@ -1685,112 +865,6 @@ Word32 BASOP_Util_fPow( return result_m; } - -/*___________________________________________________________________________ - | | - | Function Name : Dot_product12_offs() | - | | - | Compute scalar product of using accumulator. | - | The parameter 'L_off' is added to the accumulation result. | - | The result is normalized (in Q31) with exponent (0..30). | - | Notes: | - | o data in x[],y[] must provide enough headroom for accumulation | - | o L_off must correspond in format with product of x,y | - | Example: 0.01f for Q9 x Q9: 0x0000147B in Q19 | - | means: L_off = FL2WORD32_SCALE(0.01,31-19) | - |---------------------------------------------------------------------------| - | Algorithm: | - | | - | dot_product = L_off + sum(x[i]*y[i]) i=0..N-1 | - |___________________________________________________________________________| -*/ -Word32 Dot_product12_offs( /* (o) Q31: normalized result (1 < val <= -1) */ - const Word16 x[], /* (i) 12bits: x vector */ - const Word16 y[], /* (i) 12bits: y vector */ - const Word16 lg, /* (i) : vector length in range [1..256] */ - Word16 * exp, /* (o) : exponent of result (0..+30) */ - Word32 L_off /* (i) initial summation offset / 2 */ -) -{ - Word16 i, sft; - Word32 L_sum; - - - L_sum = L_mac0(L_off, x[0], y[0]); - FOR (i = 1; i < lg; i++) - { - L_sum = L_mac0(L_sum, x[i], y[i]); - } - /* Normalize acc in Q31 */ - - sft = norm_l(L_sum); - if (exp != NULL) - { - L_sum = L_shl(L_sum, sft); - } - - /* exponent = 0..30, when L_sum != 0 */ - if (L_sum != 0) - { - sft = sub(31,sft); - } - - if (exp != NULL) - { - *exp = sft; - move16(); - } - - return L_sum; -} - -Word32 Dot_product15_offs( /* (o) Q31: normalized result (1 < val <= -1) */ - const Word16 x[], /* (i) 15bits: x vector */ - const Word16 y[], /* (i) 15bits: y vector */ - const Word16 lg, /* (i) : vector length in range [1..256] */ - Word16 *exp, /* (o) : exponent of result (0..+30) */ - Word32 L_off /* (i) initial summation offset */ -) -{ - Word16 i, sft, fac, ld; - Word32 L_sum; - - ld = sub(14,norm_s(lg)); - fac = shr(-32768,ld); - L_sum = L_shr(L_off,ld); - - FOR (i = 0; i < lg; i++) - { - L_sum = L_add(L_sum, Mpy_32_16_1(L_msu(0, y[i],fac),x[i])); - } - - /* Avoid returning 0 */ - if (L_sum == 0) - { - L_sum = L_add(L_sum, 1); - } - - /* Normalize acc in Q31 */ - sft = norm_l(L_sum); - L_sum = L_shl(L_sum, sft); - - /* exponent = 0..30, when L_sum != 0 */ - if (L_sum != 0) - { - sft = add(ld, sub(30,sft)); - } - - *exp = sft; - move16(); - - return L_sum; -} - - -/* - - precondition: headroom in Y is sufficient for n accumulations -*/ Word32 BASOP_Util_Add_Mant32Exp /*!< o: normalized result mantissa */ (Word32 a_m, /*!< i: Mantissa of 1st operand a */ Word16 a_e, /*!< i: Exponent of 1st operand a */ @@ -1801,8 +875,6 @@ Word32 BASOP_Util_Add_Mant32Exp /*!< o: normalized result manti Word32 L_tmp; Word16 shift; - - /* Compare exponents: the difference is limited to +/- 30 The Word32 mantissa of the operand with lower exponent is shifted right by the exponent difference. Then, the unshifted mantissa of the operand with the higher exponent is added. The addition result @@ -1843,394 +915,128 @@ Word32 BASOP_Util_Add_Mant32Exp /*!< o: normalized result manti return (L_tmp); } - -Word16 BASOP_Util_Cmp_Mant32Exp /*!< o: flag: result of comparison */ -/* 0, if a == b */ -/* 1, if a > b */ -/* -1, if a < b */ -(Word32 a_m, /*!< i: Mantissa of 1st operand a */ - Word16 a_e, /*!< i: Exponent of 1st operand a */ - Word32 b_m, /*!< i: Mantissa of 2nd operand b */ - Word16 b_e) /*!< i: Exponent of 2nd operand b */ - +static const Word32 L_table_isqrt[48] = { - Word32 diff_m; - Word16 diff_e, shift, result; + 2147418112L, 2083389440L, 2024669184L, 1970667520L, + 1920794624L, 1874460672L, 1831403520L, 1791098880L, + 1753415680L, 1717960704L, 1684602880L, 1653145600L, + 1623326720L, 1595080704L, 1568276480L, 1542782976L, + 1518469120L, 1495334912L, 1473183744L, 1451950080L, + 1431633920L, 1412169728L, 1393491968L, 1375469568L, + 1358168064L, 1341521920L, 1325465600L, 1309933568L, + 1294991360L, 1280507904L, 1266548736L, 1252982784L, + 1239875584L, 1227161600L, 1214775296L, 1202847744L, + 1191182336L, 1179910144L, 1168965632L, 1158283264L, + 1147863040L, 1137770496L, 1127940096L, 1118306304L, + 1108934656L, 1099825152L, 1090912256L, 1082261504L +}; +/* table of table_isqrt[i] - table_isqrt[i+1] */ +static const Word16 table_isqrt_diff[48] = +{ + 977, 896, 824, 761, 707, 657, 615, 575, + 541, 509, 480, 455, 431, 409, 389, 371, + 353, 338, 324, 310, 297, 285, 275, 264, + 254, 245, 237, 228, 221, 213, 207, 200, + 194, 189, 182, 178, 172, 167, 163, 159, + 154, 150, 147, 143, 139, 136, 132, 130 +}; +static const Word16 shift[] = {9,10}; +Word32 Isqrt_lc1( + Word32 frac, /* (i) Q31: normalized value (1.0 < frac <= 0.5) */ + Word16 * exp /* (i/o) : exponent (value = frac x 2^exponent) */ +) +{ + Word16 i, a; + Word32 L_tmp; + + IF (frac <= (Word32) 0) + { + *exp = 0; + move16(); + return 0x7fffffff; /*0x7fffffff*/ + } + + /* If exponant odd -> shift right by 10 (otherwise 9) */ + L_tmp = L_shr(frac, shift[s_and(*exp, 1)]); + + /* 1) -16384 to shift left and change sign */ + /* 2) 32768 to Add 1 to Exponent like it was divided by 2 */ + /* 3) We let the mac_r add another 0.5 because it imitates */ + /* the behavior of shr on negative number that should */ + /* not be rounded towards negative infinity. */ + /* It replaces: */ + /* *exp = negate(shr(sub(*exp, 1), 1)); move16(); */ + *exp = mac_r(32768, *exp, -16384); + move16(); + + a = extract_l(L_tmp); /* Extract b10-b24 */ + a = lshr(a, 1); + + i = mac_r(L_tmp, -16*2-1, 16384); /* Extract b25-b31 minus 16 */ + + L_tmp = L_msu(L_table_isqrt[i], table_isqrt_diff[i], a);/* table[i] << 16 - diff*a*2 */ + + return L_tmp; +} +static const Word16 sqrt_table[49] = +{ + 16384, 16888, 17378, 17854, 18318, 18770, 19212, + 19644, 20066, 20480, 20886, 21283, 21674, 22058, + 22435, 22806, 23170, 23530, 23884, 24232, 24576, + 24915, 25249, 25580, 25905, 26227, 26545, 26859, + 27170, 27477, 27780, 28081, 28378, 28672, 28963, + 29251, 29537, 29819, 30099, 30377, 30652, 30924, + 31194, 31462, 31727, 31991, 32252, 32511, 32767 +}; +Word32 Sqrt_l( /* o : output value, Q31 */ + Word32 L_x, /* i : input value, Q31 */ + Word16 *exp /* o : right shift to be applied to result, Q1 */ +) +{ /* - This function compares two input parameters, both represented by a 32-bit mantissa and a 16-bit exponent. - If both values are identical, 0 is returned. - If a is greater b, 1 is returned. - If a is less than b, -1 is returned. - */ + y = sqrt(x) - /* Check, if both mantissa and exponents are identical, when normalized: return 0 */ - shift = norm_l(a_m); - if (shift) - a_m = L_shl(a_m, shift); - if (shift) - a_e = sub(a_e, shift); + x = f * 2^-e, 0.5 <= f < 1 (normalization) - shift = norm_l(b_m); - if (shift) - b_m = L_shl(b_m, shift); - if (shift) - b_e = sub(b_e, shift); + y = sqrt(f) * 2^(-e/2) - /* align exponent, if any mantissa is zero */ - if (!a_m) - a_e = add(b_e,0); - if (!b_m) - b_e = add(a_e,0); + a) e = 2k --> y = sqrt(f) * 2^-k (k = e div 2, + 0.707 <= sqrt(f) < 1) + b) e = 2k+1 --> y = sqrt(f/2) * 2^-k (k = e div 2, + 0.5 <= sqrt(f/2) < 0.707) + */ - BASOP_SATURATE_WARNING_OFF - diff_m = L_sub(a_m,b_m); - BASOP_SATURATE_WARNING_ON - diff_e = sub(a_e,b_e); + Word16 e, i, a, tmp; + Word32 L_y; - test(); - IF(diff_m == 0 && diff_e == 0) + if (L_x <= 0) { - return 0; + *exp = 0; + move16 (); + return L_deposit_l(0); } - /* Check sign, exponent and mantissa to identify, whether a is greater b or not */ - result = sub(0,1); + e = s_and(norm_l(L_x), 0x7FFE); /* get next lower EVEN norm. exp */ + L_x = L_shl(L_x, e); /* L_x is normalized to [0.25..1) */ + *exp = e; + move16 (); /* return 2*exponent (or Q1) */ - IF (a_m >= 0) - { - /* a is positive */ - if (b_m < 0) - { - result = add(1,0); - } + L_x = L_shr(L_x, 9); + a = extract_l(L_x); /* Extract b10-b24 */ + a = lshr(a, 1); - test(); - test(); - test(); - if ((b_m >= 0) && ((diff_e > 0) || (diff_e == 0 && diff_m > 0))) - { - result = add(1,0); - } - } - ELSE - { - /* a is negative */ - test(); - test(); - test(); - if ((b_m < 0) && ((diff_e < 0) || (diff_e == 0 && diff_m > 0))) - { - result = add(1,0); - } - } - return result; -} + i = mac_r(L_x, -16*2-1, 16384); /* Extract b25-b31 minus 16 */ -/* + L_y = L_deposit_h(sqrt_table[i]); /* table[i] << 16 */ + tmp = sub(sqrt_table[i], sqrt_table[i + 1]); /* table[i] - table[i+1]) */ + L_y = L_msu(L_y, tmp, a); /* L_y -= tmp*a*2 */ - headroom is introduced into acc -*/ + /* L_y = L_shr (L_y, *exp); */ /* denormalization done by caller */ - - -void bufferCopyFx( - Word16* src, /*old_exc, exc_buf, st->old_exc_len);*/ - tmp_16 = sub(sub(Qf_src,Qf_dest),sub(Q_src,Q_dest)); - IF (tmp_16>0) /*if value will be shifted right, do a multiplication with rounding ->preserves more accuracy*/ - { - tmp_16 = shl(1,sub(15,tmp_16)); - FOR (i = 0 ; i < length ; i++) - { - *(dest+i) = mult_r(*(src+i),tmp_16); - move16(); - } - } - ELSE IF (tmp_16 <0)/*leftshift - no accuracy preservation needed*/ - { - FOR (i = 0 ; i < length ; i++) - { - *(dest+i) = shr(*(src+i),tmp_16); - move16(); - } - } - ELSE /*no shift, simply copy*/ - { - FOR (i = 0 ; i < length ; i++) - { - *(dest+i) = *(src+i); - move16(); - } - } -} - -Word32 dotWord32_16_Mant32Exp(const Word32 *bufX32,/* i: 32-bit buffer with unknown headroom */ - Word16 bufX32_exp, /* i: exponent of buffer bufX32 */ - const Word16 *bufY16,/* i: 16-bit buffer quite right-aligned */ - Word16 bufY16_exp, /* i: exponent of buffer bufY16 */ - Word16 len, /* i: buffer len to process */ - Word16 *exp) /* o: result exponent */ -{ - Word32 L_sum; - Word16 shift, shift1, i; - - - - shift = getScaleFactor32(bufX32, len); /* current available headroom */ - shift = sub(shift, sub(14,norm_s(len))); /* reduced required headroom */ - L_sum = L_add(0,0); /* Clear accu */ - FOR(i=0; i < len; i++) - { - L_sum = L_mac0(L_sum, round_fx(L_shl(bufX32[i], shift)), bufY16[i]); - } - shift1 = norm_l(L_sum); - L_sum = L_shl(L_sum, shift1); /* return value */ - - shift = sub(add(bufX32_exp, bufY16_exp), add(shift, shift1)); - shift = add(shift, 1); /* compensate for factor of 2 introduced by L_mac0 */ - /* In case of NULL result, we want to have a 0 exponent too */ - if (L_sum == 0) - shift = 0; - *exp = shift; - move16(); - - - return L_sum; + return (L_y); } -Word16 BASOP_Util_lin2dB(Word32 x, Word16 x_e, Word16 fEnergy) -{ - assert(x >= 0); - - /* log2 */ - x = L_shr(BASOP_Util_Log2(x), 25-16); /* Q16 */ - - /* add exponent */ - x = L_msu(x, x_e, -32768 /* 0x8000 */); - - /* convert log2 to 20*log10 */ - x = Mpy_32_16_1(x, 24660/*6.0206f Q12*/); /* Q13 */ - - /* if energy divide by 2 (->10*log10) */ - if (fEnergy != 0) x = L_shr(x, 1); - - /* return dB as 7Q8 */ - return round_fx(L_shl(x, 8-13+16)); /* Q8 */ -} - -/* --- fixp_atan() ---- */ -#define Q_ATANINP (25) /* Input in q25, Output in q14 */ -#define Q_ATANOUT (14) -#define ATI_SF ((32-1)-Q_ATANINP) /* 6 */ -#define ATO_SF ((16-1)-Q_ATANOUT) /* 1 ] -pi/2 .. pi/2 [ */ -/* --- fixp_atan2() --- */ -#define Q_ATAN2OUT (13) -#define AT2O_SF ((16-1)-Q_ATAN2OUT) /* 2 ] -pi .. pi ] */ - - -Word16 BASOP_util_atan2( /* o: atan2(y,x) [-pi,pi] Q13 */ - Word32 y, /* i: */ - Word32 x, /* i: */ - Word16 e /* i: exponent difference (exp_y - exp_x) */ -) -{ - Word16 q; - Word32 at; - Word16 ret = -32768/*-1.0f Q15*/; - Word16 sf,sfo,stf; - Word32 L_sign; - - if(L_or(y,x) == 0) - { - return 0; - } - - IF(x == 0) - { - ret = 12868/*+EVS_PI/2 Q13*/; - move16(); - if ( y < 0 ) - { - ret = negate(ret); - } - - return ret; - } - - /* --- division */ - L_sign = L_and(L_xor(x,y), 0x80000000 ); - - q = 32767/*1.0f Q15*/; /* y/x = neg/zero = -Inf */ - sf = 0; - BASOP_SATURATE_WARNING_OFF - q = BASOP_Util_Divide3232_uu_1616_Scale(L_abs(y),L_abs(x), &sf); - BASOP_SATURATE_WARNING_ON - - BASOP_SATURATE_WARNING_OFF - if(L_sign < 0) - q = negate(q); - BASOP_SATURATE_WARNING_ON - - sfo = add(sf,e); - - /* --- atan() */ - IF ( sub(sfo,ATI_SF) > 0 ) - { - /* --- could not calc fixp_atan() here bec of input data out of range - ==> therefore give back boundary values */ - - sfo = s_min(sfo, MAXSFTAB); - - /*q = FL2WORD16( 0.0f ); move16();*/ - - if( q > 0 ) - { - move16(); - q = +f_atan_expand_range[sfo-ATI_SF-1]; - } - if( q < 0 ) - { - move16(); - q = -f_atan_expand_range[sfo-ATI_SF-1]; - } - } - ELSE - { - /* --- calc of fixp_atan() is possible; input data within range - ==> set q on fixed scale level as desired from fixp_atan() */ - stf = sub(sfo, ATI_SF); - - at = L_deposit_h(q); - if (stf < 0) at = L_shl(at,stf); - - q = BASOP_util_atan(at); /* ATO_SF*/ - } - - - /* --- atan2() */ - - ret = shr(q,(AT2O_SF - ATO_SF)); /* now AT2O_SF for atan2 */ - IF ( x < 0 ) - { - if ( y >= 0 ) - { - ret = add(ret, 25736/*EVS_PI Q13*/); - } - if(y < 0) - { - ret = sub(ret, 25736/* EVS_PI Q13*/); - } - } - - return ret; -} - -/* SNR of fixp_atan() = 56 dB*/ -#define ONEBY3P56 0x26800000 /* 1.0/3.56 in q31*/ -#define P281 0x00026000 /* 0.281 in q19*/ -#define ONEP571 0x6487 /* 1.571 in q14*/ - -Word16 BASOP_util_atan( /* o: atan(x) [-pi/2;pi/2] 1Q14 */ - Word32 x /* i: input data (-64;64) 6Q25 */ -) -{ - Word16 sign, result, exp; - Word16 res_e; - Word16 tmp, xx; - - - - sign = 0; - move16(); - if (x < 0) - { - sign = 1; - move16(); - } - x = L_abs(x); - - /* calc of arctan */ - IF(L_sub(x, 1509950l/*0.045f/64.0f Q31*/) < 0 ) - { - result = round_fx(L_shl(x,5)); /*Q14*/ - /*BASOP_util_atan_16(0.0444059968): max error 0.0000567511, mean 0.000017, abs mean 0.000017*/ - } - ELSE - IF(L_sub(x,( L_shl(1,Q_ATANINP)-8482560l/*0.00395 Q31*/)) < 0 ) - { - xx =round_fx(L_shl(x,6)); - tmp = mult_r(xx, xx); /* q15 * q15 - (16-1) = q15*/ - tmp = mult_r(tmp, 0x1340); /* 15 * (ONEBY3P56) q14 - (16-1) = q14*/ - tmp = add(tmp, 0x4000); /*L_shl(1,14) = 524288*/ /* q14 + q14 = q14 */ - res_e=Q_ATANOUT-15+14-16+1; - move16(); - if(sub(xx,tmp) > 0) - { - res_e = add(res_e,1); - } - if(sub(xx,tmp) > 0) - { - xx = shr(xx,1); - } - result = div_s(xx, tmp); - result = msu_r(0, result, shl(-32768,res_e)); - /*BASOP_util_atan_16(0.7471138239): max error 0.0020029545, mean 0.000715, abs mean 0.000715*/ - } - ELSE IF( L_sub(x,42949673l/*1.28/64.0 Q31*/) < 0 ) - { - Word16 delta_fix; - Word32 PI_BY_4 = 1686629684l/*3.1415926/4.0 Q31*//2; /* pi/4 in q30 */ - - delta_fix = round_fx(L_shl(L_sub(x,33554432l/*1.0/64.0 Q31*/), 5)); /* q30 */ - result = round_fx(L_sub(L_add(PI_BY_4, L_msu(0,delta_fix,-16384)),(L_mult0(delta_fix, delta_fix)))); - /* BASOP_Util_fPow(0.7472000122): max error 0.0020237688, mean 0.000026, abs mean 0.000520 */ - } - ELSE - { - exp = sub(norm_l(x),1); - xx = round_fx(L_shl(x,exp)); - /* q25+exp * q25+exp - (16-1) = q19+2*exp*/ - tmp = mac_r(L_shl(P281,shl(exp,1)),xx, xx); /* q19+2*exp + q19+2*exp = q19+2*exp*/ - res_e = norm_s(tmp); - result = div_s(xx, shl(tmp,res_e)); - result = shl(result, add(add(Q_ATANOUT-Q_ATANINP/*-exp*/+19/*+2*exp*/-16+1, res_e ),exp)); - result = sub(ONEP571,result); /* q14 + q14 = q14*/ - /*BASOP_Util_fPow(1.2799999714): max error 0.0020168927, mean 0.000066, abs mean 0.000072*/ - } - - if (sign) - { - result = negate(result); - } - - return(result); -} - -/* compare two positive normalized 16 bit mantissa/exponent values */ -/* return value: positive if first value greater, negative if second value greater, zero if equal */ -Word16 compMantExp16Unorm(Word16 m1, Word16 e1, Word16 m2, Word16 e2) -{ - Word16 tmp; - - assert((m1 >= 0x4000) && (m2 >= 0x4000)); /* comparisons below work only for normalized mantissas */ - - tmp = sub(e1, e2); - if (tmp == 0) tmp = sub(m1, m2); - - return tmp; -} - diff --git a/src/libs/libevs/lib_com/basop_util.h b/src/libs/libevs/lib_com/basop_util.h old mode 100755 new mode 100644 index b92478aa..5195f437 --- a/src/libs/libevs/lib_com/basop_util.h +++ b/src/libs/libevs/lib_com/basop_util.h @@ -1,61 +1,27 @@ /*==================================================================================== - EVS Codec 3GPP TS26.442 Apr 03, 2018. Version 12.11.0 / 13.6.0 / 14.2.0 + EVS Codec 3GPP TS26.443 Nov 13, 2018. Version 12.11.0 / 13.7.0 / 14.3.0 / 15.1.0 ====================================================================================*/ #ifndef __BASOP_UTIL_H__ #define __BASOP_UTIL_H__ -#include "stl.h" +#include "basop_settings.h" #include "typedef.h" #include "basop32.h" #include "basop_mpy.h" -#define _LONG long -#define _SHORT short -#ifdef _WIN32 -#define _INT64 __int64 -#else -#define _INT64 long long -#endif - -#define WORD32_BITS 32 -#define MAXVAL_WORD32 ((signed)0x7FFFFFFF) -#define MINVAL_WORD32 ((signed)0x80000000) -#define WORD32_FIX_SCALE ((_INT64)(1)<<(WORD32_BITS-1)) - -#define WORD16_BITS 16 -#define MAXVAL_WORD16 (((signed)0x7FFFFFFF)>>16) -#define MINVAL_WORD16 (((signed)0x80000000)>>16) -#define WORD16_FIX_SCALE ((_INT64)(1)<<(WORD16_BITS-1)) - -/*! - \def Macro converts a Word32 fixed point to Word16 fixed point <1 with saturation -*/ -#define WORD322WORD16(val) \ - ( ( ((((val) >> (WORD32_BITS-WORD16_BITS-1)) + 1) > (((_LONG)1< 0) ) ? \ - (Word16)(_SHORT)(((_LONG)1<<(WORD16_BITS-1))-1):(Word16)(_SHORT)((((val) >> (WORD32_BITS-WORD16_BITS-1)) + 1) >> 1) ) - - -/* Word16 Packed Type */ -typedef struct -{ - struct - { - Word16 re; - Word16 im; - } v; -} PWord16; - -#define cast16 move16 - - #define LD_DATA_SCALE (6) + #define LD_DATA_SHIFT_I5 (7) #define modDiv2(x) sub(x,shl(shr(x,1),1)) #define modDiv8(x) L_sub(x,L_shl(L_shr(x,3),3)) +#ifndef CHEAP_NORM_SIZE +#define CHEAP_NORM_SIZE 161 +#endif + static __inline Word16 limitScale16( Word16 s) { /* It is assumed, that s is calculated just before, therefore we can switch upon sign */ @@ -76,6 +42,7 @@ static __inline Word16 limitScale32( Word16 s) return (s); } + /*!********************************************************************** \brief Add two values given by mantissa and exponent. @@ -90,23 +57,7 @@ Word16 BASOP_Util_Add_MantExp /*!< Exponent of result Word16 b_e, /*!< Exponent of 2nd operand b */ Word16 *ptrSum_m); /*!< Mantissa of result */ -/************************************************************************/ -/*! - \brief Divide two values given by mantissa and exponent. - Mantissas are in 16-bit-fractional format with values between 0 and 1.
- The base for exponents is 2. Example: \f$ a = a\_m * 2^{a\_e} \f$
- - For performance reasons, the division is based on a table lookup - which limits accuracy. -*/ -void BASOP_Util_Divide_MantExp (Word16 a_m, /*!< Mantissa of dividend a */ - Word16 a_e, /*!< Exponent of dividend a */ - Word16 b_m, /*!< Mantissa of divisor b */ - Word16 b_e, /*!< Exponent of divisor b */ - Word16 *ptrResult_m, /*!< Mantissa of quotient a/b */ - Word16 *ptrResult_e /*!< Exponent of quotient a/b */ - ); /************************************************************************/ /*! @@ -122,60 +73,6 @@ Word16 Sqrt16( /*!< output mantissa */ Word16 *exponent /*!< pointer to exponent */ ); -Word16 Sqrt16norm( /*!< output mantissa */ - Word16 mantissa, /*!< normalized input mantissa */ - Word16 *exponent /*!< pointer to exponent */ -); - -Word32 Sqrt32( /*!< output mantissa */ - Word32 mantissa, /*!< input mantissa */ - Word16 *exponent /*!< pointer to exponent */ -); - -Word32 Sqrt32norm( /*!< output mantissa */ - Word32 mantissa, /*!< normalized input mantissa */ - Word16 *exponent /*!< pointer to exponent */ -); - -/* deprecated, use Sqrt16! */ -void BASOP_Util_Sqrt_MantExp (Word16 *mantissa, /*!< Pointer to mantissa */ - Word16 *exponent /*!< Pointer to exponent */ - ); - -/* deprecated, use Sqrt16norm! */ -void BASOP_Util_Sqrt_MantExpNorm (Word16 *mantissa, /*!< Pointer to normalized mantissa */ - Word16 *exponent /*!< Pointer to exponent */ - ); - -/****************************************************************************/ -/*! - \brief Calculate the inverse of the squareroot of a number given by mantissa and exponent - - Mantissa is in 16/32-bit-fractional format with values between 0 and 1.
- For *norm versions mantissa has to be between 0.5 and 1.
- The base for the exponent is 2. Example: \f$ a = a\_m * 2^{a\_e} \f$
- The exponent is addressed via pointers and will be overwritten with the result. -*/ -Word16 ISqrt16( /*!< output mantissa */ - Word16 mantissa, /*!< input mantissa */ - Word16 *exponent /*!< pointer to exponent */ -); - -Word32 ISqrt32( /*!< output mantissa */ - Word32 mantissa, /*!< input mantissa */ - Word16 *exponent /*!< pointer to exponent */ -); - -Word32 ISqrt32norm( /*!< output mantissa */ - Word32 mantissa, /*!< normalized input mantissa */ - Word16 *exponent /*!< pointer to exponent */ -); - -/* deprecated, use ISqrt16! */ -void BASOP_Util_InvSqrt_MantExp (Word16 *mantissa, /*!< Pointer to mantissa */ - Word16 *exponent /*!< Pointer to exponent */ - ); - /*****************************************************************************/ /*! \brief Calculate the inverse of a number given by mantissa and exponent @@ -190,6 +87,7 @@ Word16 Inv16( /*!< output mantissa */ Word16 mantissa, /*!< input mantissa */ Word16 *exponent /*!< pointer to exponent */ ); + /******************************************************************************/ /*! \brief Calculate the squareroot and inverse of squareroot of a number given by mantissa and exponent @@ -205,19 +103,7 @@ void BASOP_Util_Sqrt_InvSqrt_MantExp (Word16 mantissa, /*!< mantissa */ Word16 *isqrt_exp /*!< Pointer to 1/sqrt exponent */ ); -/********************************************************************/ -/*! - \brief Calculates the scalefactor needed to normalize input array - The scalefactor needed to normalize the Word16 input array is returned
- If the input array contains only '0', a scalefactor 0 is returned
- Scaling factor is determined wrt a normalized target x: 16384 <= x <= 32767 for positive x
- and -32768 <= x <= -16384 for negative x -*/ - -Word16 getScaleFactor16( /* o: measured headroom in range [0..15], 0 if all x[i] == 0 */ - const Word16 *x, /* i: array containing 16-bit data */ - const Word16 len_x); /* i: length of the array to scan */ /********************************************************************/ /*! @@ -233,106 +119,17 @@ Word16 getScaleFactor32( /* o: measured headroom in range [0..31 const Word32 *x, /* i: array containing 32-bit data */ const Word16 len_x); /* i: length of the array to scan */ -/** - * \brief normalize mantissa and update the exponent accordingly. - * \param mantissa the mantissa to be normalized - * \param pexponent pointer to the exponent. - * \return the normalized mantissa. +/************************************************************************/ +/*! + \brief Binary logarithm with 7 iterations + + \param x + + \return log2(x)/64 */ -Word16 normalize16(Word16 mantissa, Word16 *pexponent); -/****************************************************************************/ -/*! - \brief Does fractional integer division of Word32 arg1 by Word16 arg2 +/************************************************************************/ +Word32 BASOP_Util_Log2(Word32 x); - both input arguments may be positive or negative
- the result is truncated to Word16 - - \return fractional integer Word16 result of arg1/arg2 -*/ -Word16 divide3216( Word32 x, /*!< Numerator*/ - Word16 y); /*!< Denominator*/ - - -/****************************************************************************/ -/*! - \brief Does fractional integer division of Word16 arg1 by Word16 arg2 - - both input arguments may be positive or negative
- the result is truncated to Word16 - - \return fractional integer Word16 result of arg1/arg2 -*/ -Word16 divide1616( Word16 x, /*!< Numerator*/ - Word16 y); /*!< Denominator*/ - - -/****************************************************************************/ -/*! - \brief Does fractional integer division of Word32 arg1 by Word32 arg2 - - this function makes both the numerator and the denominator positive integers, - and scales up both values to avoid losing the accuracy of the outcome - too much - - WARNING: it should be arg1 < arg2 because of the maximum degree of scaling for the mantissa! - - \return fractional Word16 integer z = arg1(32bits)/arg2(32bits) -*/ -Word16 divide3232( Word32 x, /*!< Numerator*/ - Word32 y); /*!< Denominator*/ - - -/****************************************************************************/ -/*! - \brief Does fractional integer division of UWord32 arg1 by UWord32 arg2 - - This function ensures both the numerator and the denominator are positive integers, - and scales up both values to avoid losing the accuracy of the outcome - too much.
- - CAUTION: Arg 3 is a Word16 pointer which will point to the scalefactor difference - s_diff = sub(s2,s1), where s1 and s2 are the scalefactors of the arguments, which - were shifted in order to e.g. preserve accuracy. - I.e. the result has to be scaled due to shifting it - s_diff to the right to obtain the real result of the division. - - \return fractional Word16 integer z = arg1(32bits)/arg2(32bits) -*/ -Word16 BASOP_Util_Divide3232_uu_1616_Scale( Word32 x, /*!< i : Numerator*/ - Word32 y, /*!< i : Denominator*/ - Word16 *s); /*!< o : Additional scalefactor difference*/ - - -/****************************************************************************/ -/*! - \brief Does fractional integer division of Word32 arg1 by Word32 arg2 - - This function scales up both values to avoid losing the accuracy of the outcome - too much.
- - CAUTION: Arg 3 is a Word16 pointer which will point to the scalefactor difference - s_diff = sub(s2,s1), where s1 and s2 are the scalefactors of the arguments, which - were shifted in order to e.g. preserve accuracy. - I.e. the result has to be scaled due to shifting it - s_diff to the right to obtain the real result of the division. - - \return fractional Word16 integer z = arg1(32bits)/arg2(32bits) -*/ -Word16 BASOP_Util_Divide3232_Scale( Word32 x, /*!< i : Numerator*/ - Word32 y, /*!< i : Denominator*/ - Word16 *s); /*!< o : Additional scalefactor difference*/ - - -/****************************************************************************/ -/*! - \brief Does fractional integer division of Word32 arg1 by Word16 arg2 - - - \return fractional Word16 integer z = arg1(32bits)/arg2(16bits) , z not normalized -*/ -Word16 BASOP_Util_Divide3216_Scale( Word32 x, /*!< i : Numerator */ - Word16 y, /*!< i : Denominator*/ - Word16 *s); /*!< o : Additional scalefactor difference*/ /****************************************************************************/ @@ -346,17 +143,28 @@ Word16 BASOP_Util_Divide1616_Scale( Word16 x, /*!< i : Numerator*/ Word16 y, /*!< i : Denominator*/ Word16 *s); /*!< o : Additional scalefactor difference*/ +/****************************************************************************/ +/*! + \brief Does fractional integer division of Word32 arg1 by Word16 arg2 + + + \return fractional Word16 integer z = arg1(32bits)/arg2(16bits) , z not normalized +*/ +Word16 BASOP_Util_Divide3216_Scale( Word32 x, /*!< i : Numerator */ + Word16 y, /*!< i : Denominator*/ + Word16 *s); /*!< o : Additional scalefactor difference*/ + + /************************************************************************/ /*! - \brief Binary logarithm with 7 iterations - - \param x - - \return log2(x)/64 + * \brief Binary logarithm with 5 iterations + * + * \param[i] val + * + * \return basop_log2(val)/128 */ /************************************************************************/ -Word32 BASOP_Util_Log2(Word32 x); - +Word32 BASOP_Util_log2_i5(Word32 val); /************************************************************************/ /*! @@ -399,49 +207,33 @@ Word32 BASOP_Util_Log2(Word32 x); /************************************************************************/ Word32 BASOP_Util_InvLog2(Word32 x); -Word16 BASOP_util_norm_s_bands2shift (Word16 x); -/***********************************************************************/ -/*! - \brief Calculate the headroom of the complex data in a 2 dimensional array - - \return number of headroom bits - */ -Word16 BASOP_util_norm_l_dim2_cplx (const Word32 * const *re, /*!< Real part of 32 Bit input */ - const Word32 * const *im, /*!< Imag part if 32 Bit input */ - Word16 startBand, /*!< start band of cplx data */ - Word16 stopBand, /*!< stop band of cplx data */ - Word16 startSlot, /*!< start slot of cplx data */ - Word16 stopSlot /*!< stop slot of cplx data */ - ); /****************************************************************************/ /*! - \brief Does a data copy of Word8 *arg1 to Word8 *arg2 with Word16 arg3 number of moves + \brief Sets Array Word16 arg1 to value Word16 arg2 for Word16 arg3 elements */ -void copyWord8( const Word8 *src, /*!< i : Source address */ - Word8 *dst, /*!< i : Destination address */ - const Word32 n); /*!< i : Number of elements to copy */ +void set_val_Word16( Word16 X[], /*!< Address of array */ + const Word16 val, /*!< Value to copy into array */ + Word16 n); /*!< Number of elements to process */ /****************************************************************************/ /*! - \brief Sets Word8 array arg1[] to zero for a length of Word16 arg2 elements + \brief Sets Array Word32 arg1 to value Word32 arg2 for Word16 arg3 elements */ -void set_zero_Word8( Word8 X[], /*!< i : Address of array */ - Word32 n); /*!< i : Number of elements to set to zero */ +void set_val_Word32( Word32 X[], /*!< Address of array */ + const Word32 val, /*!< Value to copy into array */ + Word16 n); /*!< Number of elements to process */ /****************************************************************************/ /*! - \brief Does a multiplication of Word32 * Word16 input values + \brief Does a multiplication of Word16 input values - \return z32 = x32 * y16 + \return z16 = x16 * y16 */ -Word32 L_mult0_3216( Word32 x, /*!< : Multiplier */ - Word16 y); /*!< : Multiplicand */ +Word16 mult0 ( Word16 x, /*!< i : Multiplier */ + Word16 y); /*!< i : Multiplicand */ -/* Calculate sin/cos. Angle in 2Q13 format, result has exponent = 1 */ -Word16 getCosWord16(Word16 theta); -Word32 getCosWord32(Word32 theta); /** * \brief calculate cosine of angle. Tuned for ISF domain. * \param theta Angle normalized to radix 2, theta = (angle in radians)*2.0/pi @@ -449,62 +241,6 @@ Word32 getCosWord32(Word32 theta); */ Word16 getCosWord16R2(Word16 theta); -/****************************************************************************/ -/*! - \brief square root abacus algorithm - - \return integer sqrt(x) - */ -Word16 getSqrtWord32(Word32 x); - -/****************************************************************************/ -/*! - \brief finds index of min Word16 in array - - \return index of min Word16 - */ -Word16 findIndexOfMinWord16(Word16 *x, const Word16 len); - -/****************************************************************************/ -/*! - \brief finds index of min Word32 in array - - \return index of min Word32 - */ -Word16 findIndexOfMinWord32(Word32 *x, const Word16 len); - -/****************************************************************************/ -/*! - \brief finds index of max Word16 in array - - \return index of max Word16 - */ -Word16 findIndexOfMaxWord16(Word16 *x, const Word16 len); - -/****************************************************************************/ -/*! - \brief finds index of max Word32 in array - - \return index of max Word32 - */ -Word16 findIndexOfMaxWord32(Word32 *x, const Word16 len); - -/****************************************************************************/ -/*! - \brief 16x16->16 integer multiplication without overflow control - - \return 16x16->16 integer - */ -Word16 imult1616(Word16 x, Word16 y); - -/****************************************************************************/ -/*! - \brief 32x16->32 integer multiplication with overflow control - - \return 32x16->32 integer - */ -Word32 imult3216(Word32 x, Word16 y); - /****************************************************************************/ /*! \brief 16/16->16 unsigned integer division @@ -516,100 +252,7 @@ Word32 imult3216(Word32 x, Word16 y); Word16 idiv1616U(Word16 x, Word16 y); -/****************************************************************************/ -/*! - \brief 16/16->16 signed integer division - x and y have to be positive, x has to be < 16384 - - \return 16/16->16 integer - */ - -Word16 idiv1616(Word16 x, Word16 y); - -/*------------------------------------------------------------------* - * Dot_product16HQ: - * - * \brief Compute scalar product of using 64-bit accumulator. - * - * Performs normalization of the result, returns the exponent - * Note: In contrast to dotWord32, no headroom is required for data - * in x[] and y[], means, they may have any format Qn - *------------------------------------------------------------------*/ -Word32 Dot_product16HQ( /* using 64-bit accumulator. - * - * Performs normalization of the result, returns the exponent - * Note: In contrast to dotWord32, no headroom is required for data - * in x[], means, they may have any format Qn - *------------------------------------------------------------------*/ -Word32 Dot_productSq16HQ( /* using 64-bit accumulator. - * - * Performs no normalization of the result - *------------------------------------------------------------------*/ -Word32 dotp_s_fx( /*> (30-exponant) (with rounding) | + |___________________________________________________________________________| +*/ +Word32 Pow2( /*!< (o) Q0 : result (range: 0<=val<=0x7fffffff) */ + Word16 exponant, /*!< (i) Q0 : Integer part. (range: 0<=val<=30) */ + Word16 fraction /*!< (i) Q15 : Fractionnal part. (range: 0.0<=val<1.0) */ +); + +/************************************************************************* + * + * FUNCTION: Log2_norm() + * + * PURPOSE: Computes log2(L_x, exp), where L_x is positive and + * normalized, and exp is the normalisation exponent + * If L_x is negative or zero, the result is 0. + * + * DESCRIPTION: + * The function Log2(L_x) is approximated by a table and linear + * interpolation. The following steps are used to compute Log2(L_x) + * + * 1- exponent = 30-norm_exponent + * 2- i = bit25-b31 of L_x; 32<=i<=63 (because of normalization). + * 3- a = bit10-b24 + * 4- i -=32 + * 5- fraction = table[i]<<16 - (table[i] - table[i+1]) * a * 2 + * + *************************************************************************/ + +Word16 Log2_norm_lc ( /* (o) : Fractional part of Log2. (range: 0<=val<1) */ + Word32 L_x /* (i) : input value (normalized) */ +); /************************************************************************* * @@ -674,41 +352,6 @@ Word32 BASOP_Util_fPow( /* (o) : mantissa of result Word16 *result_e /* (o) : output pointer to exponent of result */ ); -/*___________________________________________________________________________ - | | - | Function Name : Dot_product12_offs() | - | | - | Compute scalar product of using accumulator. | - | The parameter 'L_off' is added to the accumulation result. | - | The result is normalized (in Q31) with exponent (0..30). | - | Notes: | - | o data in x[],y[] must provide enough headroom for accumulation | - | o L_off must correspond in format with product of x,y | - | Example: 0.01f for Q9 x Q9: 0x0000147B in Q19 | - | means: L_off = FL2WORD32_SCALE(0.01f,31-19) | - |---------------------------------------------------------------------------| - | Algorithm: | - | | - | dot_product = L_off + sum(x[i]*y[i]) i=0..N-1 | - |___________________________________________________________________________| -*/ - -Word32 Dot_product12_offs( /* (o) Q31: normalized result (1 < val <= -1) */ - const Word16 x[], /* (i) 12bits: x vector */ - const Word16 y[], /* (i) 12bits: y vector */ - const Word16 lg, /* (i) : vector length in range [1..256] */ - Word16 * exp, /* (o) : exponent of result (0..+30) */ - Word32 L_off /* (i) initial summation offset /2 */ -); - -Word32 Dot_product15_offs( /* (o) Q31: normalized result (1 < val <= -1) */ - const Word16 x[], /* (i) 15bits: x vector */ - const Word16 y[], /* (i) 15bits: y vector */ - const Word16 lg, /* (i) : vector length in range [1..256] */ - Word16 *exp, /* (o) : exponent of result (0..+30) */ - Word32 L_off /* (i) initial summation offset */ -); - /*!********************************************************************** \brief Add two values given by mantissa and exponent. @@ -722,96 +365,22 @@ Word32 BASOP_Util_Add_Mant32Exp /*!< o: normalized result manti Word32 b_m, /*!< i: Mantissa of 2nd operand b */ Word16 b_e, /*!< i: Exponent of 2nd operand b */ Word16 *ptr_e); /*!< o: exponent of result */ -/*!********************************************************************** - \brief Returns the comparison result of two normalized values given by mantissa and exponent. - return value: -1: a < b, 0: a == b, 1; a > b - - Mantissas are in 32-bit-fractional format with values between 0 and 1.
- The base for exponents is 2. Example: \f$ a = a\_m * 2^{a\_e} \f$
- -************************************************************************/ -Word16 BASOP_Util_Cmp_Mant32Exp /*!< o: flag: result of comparison */ -(Word32 a_m, /*!< i: Mantissa of 1st operand a */ - Word16 a_e, /*!< i: Exponent of 1st operand a */ - Word32 b_m, /*!< i: Mantissa of 2nd operand b */ - Word16 b_e); /*!< i: Exponent of 2nd operand b */ - -/******************************************************************** - * bufferCopyFx - * - * \brief copies buffer while preserving Format of destination buffer -********************************************************************* -*/ -void bufferCopyFx( - Word16* src, /* - The base for exponent x_e is 2.
- -************************************************************************/ -Word16 BASOP_Util_lin2dB( /*!< o: dB value (7Q8) */ - Word32 x, /*!< i: mantissa */ - Word16 x_e, /*!< i: exponent */ - Word16 fEnergy); /*!< i: flag indicating if x is energy */ - -/*!********************************************************************** - \brief Calculates atan(x). -************************************************************************/ -Word16 BASOP_util_atan( /*!< o: atan(x) [-pi/2;pi/2] 1Q14 */ - Word32 x /*!< i: input data (-64;64) 6Q25 */ -); - -/*!********************************************************************** - \brief Calculates atan2(y,x). -************************************************************************/ -Word16 BASOP_util_atan2( /*!< o: atan2(y,x) [-pi,pi] Q13 */ - Word32 y, /*!< i: */ - Word32 x, /*!< i: */ - Word16 e /*!< i: exponent difference (exp_y - exp_x) */ -); -/*!********************************************************************** - \brief norm_llQ31 returns Word32 with scalingfactor, with 2 32bit accus as input - -************************************************************************/ -Word32 norm_llQ31( /* o : normalized result Q31 */ - Word32 L_c, /* i : upper bits of accu Q-1 */ - Word32 L_sum, /* i : lower bits of accu, unsigned Q31 */ - Word16 * exp /* o : exponent of result in [-32,31] Q0 */ -); - -/* compare two positive normalized 16 bit mantissa/exponent values */ -/* return value: positive if first value greater, negative if second value greater, zero if equal */ -Word16 compMantExp16Unorm(Word16 m1, Word16 e1, Word16 m2, Word16 e2); +Word32 dotWord32_16_guards(const Word32 * X, const Word16 * Y, Word16 n, Word16 hr, Word16 * shift); +Word32 Sqrt_l(Word32 L_x, Word16 *exp); + #endif /* __BASOP_UTIL_H__ */ diff --git a/src/libs/libevs/lib_com/bastypes.h b/src/libs/libevs/lib_com/bastypes.h new file mode 100644 index 00000000..57e958e6 --- /dev/null +++ b/src/libs/libevs/lib_com/bastypes.h @@ -0,0 +1,46 @@ +/*==================================================================================== + EVS Codec 3GPP TS26.443 Nov 13, 2018. Version 12.11.0 / 13.7.0 / 14.3.0 / 15.1.0 + ====================================================================================*/ + +#ifndef __BASTYPES_H +#define __BASTYPES_H + +typedef unsigned char BYTE; +typedef unsigned short WORD; +#if defined(__alpha__) || defined(__alpha) || defined(__sgi) +typedef unsigned int DWORD; /* long is 64 bits on these machines */ +#else +typedef unsigned long DWORD; +#endif + +typedef int BOOL; +typedef signed int INT; +typedef signed long LONG; +typedef unsigned long ULONG; +typedef unsigned int UINT; +typedef float FLOAT; +typedef double DOUBLE; +typedef unsigned char UCHAR; +typedef char CHAR; + +/* from uld_types.h: */ +typedef short SHORT; +typedef unsigned short USHORT; +typedef long int LINT; +typedef unsigned long int ULINT; + +#ifndef TRUE +#define TRUE 1 +#endif + +#ifndef FALSE +#define FALSE 0 +#endif + +#ifndef NULL +#define NULL 0 +#endif + +#define INVALID_HANDLE NULL + +#endif diff --git a/src/libs/libevs/lib_com/bitalloc_fx.cpp b/src/libs/libevs/lib_com/bitalloc.cpp old mode 100755 new mode 100644 similarity index 65% rename from src/libs/libevs/lib_com/bitalloc_fx.cpp rename to src/libs/libevs/lib_com/bitalloc.cpp index 2ba134a9..268829f4 --- a/src/libs/libevs/lib_com/bitalloc_fx.cpp +++ b/src/libs/libevs/lib_com/bitalloc.cpp @@ -1,209 +1,181 @@ /*==================================================================================== - EVS Codec 3GPP TS26.442 Apr 03, 2018. Version 12.11.0 / 13.6.0 / 14.2.0 + EVS Codec 3GPP TS26.443 Nov 13, 2018. Version 12.11.0 / 13.7.0 / 14.3.0 / 15.1.0 ====================================================================================*/ +#include "options.h" +#include "cnst.h" +#include "rom_com.h" +#include "prot.h" +#include "basop_util.h" +#include "basop_proto_func.h" -#include "options.h" /* Compilation switches */ -#include "cnst_fx.h" /* Common constants */ -#include "rom_com_fx.h" /* Static table prototypes */ -#include "prot_fx.h" /* Function prototypes */ -#include "stl.h" /* required for wmc_tool */ -void bitalloc_fx ( - Word16 *y, /* i : reordered norm of sub-vectors Q0 */ - Word16 *idx, /* i : reordered sub-vector indices Q0 */ - Word16 sum, /* i : number of available bits Q0 */ - Word16 N, /* i : number of norms Q0 */ - Word16 K, /* i : maximum number of bits per dimension Q0 */ - Word16 *r, /* o : bit-allacation vector Q0 */ - const Word16 *sfmsize, /* i : band length Q0 */ - const Word16 hqswb_clas /* i : signal classification flag Q0 */ +/*-------------------------------------------------------------------------- + * bitalloc() + * + * Adaptive bit allocation for 20kHz audio codec + *--------------------------------------------------------------------------*/ + +void bitalloc ( + short *y, /* i : reordered norm of sub-vectors */ + short *idx, /* i : reordered sub-vector indices */ + short sum, /* i : number of available bits */ + short N, /* i : number of norms */ + short K, /* i : maximum number of bits per dimension */ + short *r, /* o : bit-allacation vector */ + const short *sfmsize, /* i : band length */ + const short hqswb_clas /* i : signal classification flag */ ) { - Word16 i, j, k, n, m, v, im; - Word16 diff, temp; - Word16 fac; - Word16 ii; - Word16 SFM_thr = SFM_G1G2; - move16(); + short i, j, k, n, m, v, im; + short diff, temp; + short fac; + short ii; + short SFM_thr = SFM_G1G2; - N = sub(N, 1); + N -= 1; - if ( sub(hqswb_clas, HQ_HARMONIC) == 0 ) + if ( hqswb_clas == HQ_HARMONIC ) { SFM_thr = 22; - move16(); } fac = 3; - move16(); - K = sub(K,2); + K -= 2; im = 1; - move16(); diff = sum; - move16(); - n = shr(sum,3); - FOR ( i=0; i> 3; + for ( i=0; i= 0 && sub(r[j],K) < 0 ) + if ( sum >= sfmsize[j] && r[j] < K ) { - y[k] = sub(y[k], fac); - move16(); - r[j] = add(r[j], 1); - move16(); - - if ( sub(r[j], K) >= 0 ) + y[k] -= fac; + r[j]++; + if ( r[j] >= K ) { - y[k] = -32768; - move16(); + y[k] = MIN16B; } - sum = sub(sum,sfmsize[j]); + sum -= sfmsize[j]; } - ELSE + else { - y[k] = -32768; - move16(); - k = add(k, 1); - test(); - if ( sub(k, im) == 0 && sub(im, N) < 0 ) + y[k] = MIN16B; + k++; + if ( k == im && im < N ) { - im = add(im, 1); + im++; } } - test(); - IF ( (sub(sum, WID_G1)<0) || (sub(diff, sum)==0) ) + if ( sum < WID_G1 || diff == sum ) { - BREAK; + break; } diff = sum; - move16(); - v = sub(N, 1); + v = N - 1; - IF ( sub(k, v) > 0 ) + if (k > v) { - FOR ( ii=0; ii<=N; ii++ ) + for ( ii=0; ii<=N; ii++ ) { - IF ( sub(y[ii], -32768) > 0 ) + if ( y[ii] > MIN16B ) { - if ( sub(ii, N) < 0 ) + if( ii < N ) { - im = add(ii, 1); + im = ii + 1; } - BREAK; + + break; } } } } - - IF ( sub(sum, WID_G2) >= 0 ) + if ( sum >= WID_G2) { - FOR (i=0; i<=N; i++) + for (i=0; i<=N; i++) { j = idx[i]; - move16(); - test(); - test(); - IF ( sub(j, SFM_G1) >= 0 && sub(j, SFM_thr) < 0 && r[j] == 0 ) + if ( j >= SFM_G1 && j < SFM_thr && r[j] == 0 ) { r[j] = 1; - move16(); - sum = sub(sum, WID_G2); - IF (sub(sum, WID_G2) < 0) + sum -= WID_G2; + if ( sum < WID_G2 ) { - BREAK; + break; } } } } - IF ( sub(sum, WID_G2) >= 0 ) + if ( sum >= WID_G2 ) { - FOR (i=0; i<=N; i++) + for (i=0; i<=N; i++) { j = idx[i]; - move16(); - test(); - test(); - IF ( sub(j,SFM_G1) >= 0 && sub(j, SFM_thr) < 0 && sub(r[j], 1) == 0 ) + if ( j >= SFM_G1 && j < SFM_thr && r[j] == 1 ) { r[j] = 2; - move16(); - sum = sub(sum, WID_G2); - IF ( sub(sum, WID_G2) < 0 ) + sum -= WID_G2; + if ( sum < WID_G2 ) { - BREAK; + break; } } } } - IF ( sub(sum, WID_G1) >= 0 ) + if ( sum >= WID_G1 ) { - FOR (i=0; i<=N; i++) + for (i=0; i<=N; i++) { j = idx[i]; - move16(); - test(); - IF ( sub(j, SFM_G1) < 0 && r[j] == 0 ) + if ( j < SFM_G1 && r[j] == 0 ) { r[j] = 1; - move16(); - sum = sub(sum, WID_G1); - IF ( sub(sum, WID_G1) < 0 ) + sum -= WID_G1; + if ( sum < WID_G1 ) { - BREAK; + break; } } } } - IF ( sub(sum, WID_G1) >= 0 ) + if ( sum >= WID_G1 ) { - FOR (i=0; i<=N; i++) + for (i=0; i<=N; i++) { j = idx[i]; - move16(); - test(); - IF ( sub(j, SFM_G1) < 0 && sub(r[j], 1) == 0 ) + if ( j < SFM_G1 && r[j] == 1 ) { r[j] = 2; - move16(); - sum = sub(sum, WID_G1); - IF ( sub(sum, WID_G1) < 0 ) + sum -= WID_G1; + if ( sum < WID_G1 ) { - BREAK; + break; } } } @@ -212,21 +184,22 @@ void bitalloc_fx ( return; } + /*-------------------------------------------------------------------* * BitAllocF() * * Fractional bit allocation *-------------------------------------------------------------------*/ -Word16 BitAllocF_fx ( - Word16 *y, /* i : norm of sub-vectors :Q0 */ - Word32 bit_rate, /* i : bitrate :Q0 */ - Word16 B, /* i : number of available bits :Q0 */ - Word16 N, /* i : number of sub-vectors :Q0 */ - Word16 *R, /* o : bit-allocation indicator :Q0 */ - Word16 *Rsubband_fx /* o : sub-band bit-allocation vector :Q3 */ - ,const Word16 hqswb_clas, /* i : hq swb class :Q0 */ - const Word16 num_env_bands/* i : Number sub bands to be encoded for HF GNERIC :Q0 */ +short BitAllocF ( + short *y, /* i : norm of sub-vectors */ + long bit_rate, /* i : bitrate */ + short B, /* i : number of available bits */ + short N, /* i : number of sub-vectors */ + short *R, /* o : bit-allocation indicator */ + short *Rsubband, /* o : sub-band bit-allocation vector (Q3) */ + const short hqswb_clas, /* i : hq swb class */ + const short num_env_bands /* i : Number sub bands to be encoded for HQ_SWB_BWE */ ) { Word16 fac; @@ -234,55 +207,44 @@ Word16 BitAllocF_fx ( Word16 m_fx; Word32 t_fx, B_fx; - Word32 L_tmp1, L_tmp2, L_tmp3; + Word32 L_tmp1, L_tmp2; Word16 tmp, exp1, exp2; Word32 Rsubband_w32_fx[NB_SFM]; /* Q15 */ Word16 B_w16_fx; - set32_fx( Rsubband_w32_fx, 0, NB_SFM); + set_i( Rsubband_w32_fx, 0, NB_SFM); fac = 3; - move16(); - - IF (L_sub(bit_rate, 32000) < 0) + if (L_sub(bit_rate, 32000) < 0) { bs = 2; - move16(); } - ELSE + else { bs = 3; - move16(); } low_rate = 1; - move16(); Nmin = N; - move16(); if ( sub(Nmin,SFM_N) > 0) { Nmin = SFM_N; - move16(); } /* Initial bits distribution */ - test(); - IF (sub(hqswb_clas , HQ_GEN_SWB) == 0 || sub(hqswb_clas , HQ_GEN_FB) == 0) + if (sub(hqswb_clas , HQ_GEN_SWB) == 0 || sub(hqswb_clas , HQ_GEN_FB) == 0) { /* Initial bits distribution */ L_tmp1 = 0; - move16(); m_fx = 0; - move16(); - FOR ( i = 0; i < num_env_bands ; i++) + for ( i = 0; i < num_env_bands ; i++) { L_tmp1 = L_mac0(L_tmp1, Nb[i], y[i]); } L_tmp1 = L_msu0(L_tmp1, fac, B); - t_fx = L_deposit_l(0); + t_fx = 0; n = 0; - move16(); tmp = add(band_end_HQ[num_env_bands-1], shl(band_end_HQ[num_env_bands-1], 1)); exp1 = norm_s(tmp); tmp = div_s(16384, shl(tmp, exp1));/*15 + 14 - exp1*/ @@ -290,65 +252,65 @@ Word16 BitAllocF_fx ( tmp = shl(tmp, exp2); exp1 = add(29, sub(exp2, exp1)); - FOR ( i = 0; i < N; i++) + for ( i = 0; i < N; i++) { L_tmp2 = L_sub(L_mult0(y[i], band_end_HQ[num_env_bands-1]), L_tmp1); Rsubband_w32_fx[i] = L_mult0(extract_l(L_tmp2), Nb[i]); move32();/*Q0*/ - IF (Rsubband_w32_fx[i] > 0) + if (Rsubband_w32_fx[i] > 0) { n = add(n,Nb[i]); - Rsubband_w32_fx[i] = Mult_32_16(Rsubband_w32_fx[i], tmp); + Rsubband_w32_fx[i] = Mpy_32_16(Rsubband_w32_fx[i], tmp); move32();/*exp1 - 15*/ Rsubband_w32_fx[i] = L_shl(Rsubband_w32_fx[i], sub(30, exp1));/*Q15*/ t_fx = L_add(t_fx, Rsubband_w32_fx[i]);/*Q0*/ } - ELSE + else { - Rsubband_w32_fx[i] = L_deposit_l(0); + Rsubband_w32_fx[i] = 0; + move32(); } } } - ELSE + else { /* Initial bits distribution */ L_tmp1 = 0; - move16(); m_fx = 0; - move16(); - FOR ( i = 0; i < N ; i++) + for ( i = 0; i < N ; i++) { L_tmp1 = L_mac0(L_tmp1, Nb[i], y[i]); } L_tmp1 = L_msu0(L_tmp1, fac, B); - t_fx = L_deposit_l(0); + t_fx = 0; n = 0; - move16(); tmp = add(band_end_HQ[N-1], shl(band_end_HQ[N-1], 1)); exp1 = norm_s(tmp); tmp = div_s(16384, shl(tmp, exp1));/*15 + 14 - exp1*/ exp2 = norm_s(tmp); tmp = shl(tmp, exp2); exp1 = add(29, sub(exp2, exp1)); - FOR ( i = 0; i < N; i++) + for ( i = 0; i < N; i++) { L_tmp2 = L_sub(L_mult0(y[i], band_end_HQ[N-1]), L_tmp1); Rsubband_w32_fx[i] = L_mult0(extract_l(L_tmp2), Nb[i]); move32();/*Q0*/ - IF (Rsubband_w32_fx[i] > 0) + if (Rsubband_w32_fx[i] > 0) { n = add(n,Nb[i]); - L_tmp3 = Mult_32_16(Rsubband_w32_fx[i], tmp); /*exp1 - 15*/ - Rsubband_w32_fx[i] = L_shl(L_tmp3, sub(30, exp1)); /*Q15*/ move32(); + Rsubband_w32_fx[i] = Mpy_32_16(Rsubband_w32_fx[i], tmp); + move32();/*exp1 - 15*/ + Rsubband_w32_fx[i] = L_shl(Rsubband_w32_fx[i], sub(30, exp1));/*Q15*/ t_fx = L_add(t_fx, Rsubband_w32_fx[i]);/*Q0*/ } - ELSE + else { - Rsubband_w32_fx[i] = L_deposit_l(0); + Rsubband_w32_fx[i] = 0; + move32(); } } } @@ -363,52 +325,52 @@ Word16 BitAllocF_fx ( tmp = div_s(extract_h(L_shl(L_tmp1, exp1)), shl(n, exp2));/*15 + 15 + exp1 - 16 - exp2*/ m_fx = shl(tmp, sub(exp2, exp1));/*Q14*/ - t_fx = L_deposit_l(0); + t_fx = 0; n = 0; - move16(); - FOR ( i = 0; i < N; i++) + for ( i = 0; i < N; i++) { - IF (Rsubband_w32_fx[i] > 0) + if (Rsubband_w32_fx[i] > 0) { Rsubband_w32_fx[i] = L_msu(Rsubband_w32_fx[i], m_fx, Nb[i]); move32(); - IF (Rsubband_w32_fx[i] > 0) + if (Rsubband_w32_fx[i] > 0) { n = add(n,Nb[i]); t_fx = L_add(t_fx, Rsubband_w32_fx[i]); } - ELSE + else { - Rsubband_w32_fx[i] = L_deposit_l(0); + Rsubband_w32_fx[i] = 0; + move32(); } } } } Bits = B; - move16(); /* Impose bit-constraints to subbands with less than minimum bits*/ - t_fx = L_deposit_l(0); + t_fx = 0; n = 0; - move16(); - FOR ( i = 0; i < N; i++) + for ( i = 0; i < N; i++) { - IF (Rsubband_w32_fx[i] > 0) + if (Rsubband_w32_fx[i] > 0) { test(); - IF ((L_sub(Rsubband_w32_fx[i] , L_shl(add(bs, LNb[i]), 15)) <0) && (sub(low_rate,1) == 0)) + test(); + if ((L_sub(Rsubband_w32_fx[i] , L_shl(add(bs, LNb[i]), 15)) <0) && (sub(low_rate,1) == 0)) { - Rsubband_w32_fx[i] = L_deposit_l(0); + Rsubband_w32_fx[i] = 0; + move32(); } - ELSE IF ( L_sub(Rsubband_w32_fx[i] , L_shl(Nb[i], 15)) <=0) + else if ( L_sub(Rsubband_w32_fx[i] , L_shl(Nb[i], 15)) <=0) { B = sub(B,Nb[i]); Rsubband_w32_fx[i] = L_shl(Nb[i], 15); move32(); } - ELSE + else { n = add(n,Nb[i]); t_fx = L_add(t_fx, Rsubband_w32_fx[i]); @@ -422,7 +384,7 @@ Word16 BitAllocF_fx ( L_tmp1 = L_sub(t_fx, L_shl(B, 15)); L_tmp2 = L_abs(L_tmp1); - if (n>0) + if( n>0 ) { exp1 = sub(norm_l(L_tmp2), 1); exp2 = norm_s(n); @@ -433,22 +395,20 @@ Word16 BitAllocF_fx ( m_fx = negate(m_fx); } - t_fx = L_deposit_l(0); + t_fx = 0; n = 0; - move16(); - FOR( i = 0; i < N; i++) + for( i = 0; i < N; i++) { - IF (L_sub(Rsubband_w32_fx[i] , L_shl(Nb[i], 15)) > 0) + if (L_sub(Rsubband_w32_fx[i] , L_shl(Nb[i], 15)) > 0) { Rsubband_w32_fx[i] = L_msu(Rsubband_w32_fx[i], m_fx, Nb[i]); - move32(); - IF (L_sub(Rsubband_w32_fx[i] ,L_shl(Nb[i], 15)) > 0) + if (L_sub(Rsubband_w32_fx[i] ,L_shl(Nb[i], 15)) > 0) { n = add(n,Nb[i]); t_fx = L_add(t_fx, Rsubband_w32_fx[i]); } - ELSE + else { B = sub(B,Nb[i]); @@ -459,15 +419,16 @@ Word16 BitAllocF_fx ( } } /*In case no subband has enough bits more than 1-bit per sample, take bits off the higher subbands */ - IF (t_fx == 0) + if (t_fx == 0) { - FOR ( i = N-1; i >= 0; i--) + for ( i = N-1; i >= 0; i--) { - IF (Rsubband_w32_fx[i] > 0) + if (Rsubband_w32_fx[i] > 0) { B = add( B, Nb[i] ); - Rsubband_w32_fx[i] = L_deposit_l(0); - IF ( B >= 0) + Rsubband_w32_fx[i] = 0; + move32(); + if ( B >= 0) { BREAK; } @@ -479,60 +440,56 @@ Word16 BitAllocF_fx ( /* fine redistribution of over-allocated or under-allocated bits */ tmp = 0; - move16(); - FOR ( i = 0; i < N; i++) + for ( i = 0; i < N; i++) { - Rsubband_fx[i] = extract_l(L_shr(Rsubband_w32_fx[i], 12)); - tmp = add(tmp, Rsubband_fx[i]); + Rsubband[i] = extract_l(L_shr(Rsubband_w32_fx[i], 12)); + tmp = add(tmp, Rsubband[i]); } B = Bits; B_w16_fx = shl(B, 3); - IF (sub(tmp ,B_w16_fx)>0) + if (sub(tmp ,B_w16_fx)>0) { tmp = sub(tmp, B_w16_fx); - FOR ( i = 0; i < N; i++) + for ( i = 0; i < N; i++) { - IF (sub(Rsubband_fx[i], add(shl(Nb[i], 3), tmp)) >= 0) + if (sub(Rsubband[i], add(shl(Nb[i], 3), tmp)) >= 0) { - Rsubband_fx[i] = sub(Rsubband_fx[i], tmp); - move16(); + Rsubband[i] = sub(Rsubband[i], tmp); BREAK; } } } - ELSE + else { tmp = sub(tmp, B_w16_fx); - FOR ( i = 0; i < N; i++) + for ( i = 0; i < N; i++) { - IF (Rsubband_fx[i] > 0) + if (Rsubband[i] > 0) { - Rsubband_fx[i] = sub(Rsubband_fx[i], tmp); - move16(); + Rsubband[i] = sub(Rsubband[i], tmp); BREAK; } } } - /* Calcuate total used bits and initialize R to be used for Noise Filling */ + /* Calculate total used bits and initialize R to be used for Noise Filling */ tmp = 0; - move16(); - FOR ( i = 0; i < N; i++) + for ( i = 0; i < N; i++) { - tmp = add(tmp, Rsubband_fx[i]); - R[i] = shr(Rsubband_fx[i], 3); - move16(); + tmp = add(tmp, Rsubband[i]); + R[i] = shr(Rsubband[i], 3); } + return shr(tmp, 3); } + /*-------------------------------------------------------------------* * Bit_group() * * bit allocation in group *-------------------------------------------------------------------*/ -static -void Bit_group_fx ( +static void Bit_group_fx ( Word16 *y, /* i : norm of sub-band Q0*/ Word16 start_band, /* i : start band indices Q0*/ Word16 end_band, /* i : end band indices Q0*/ @@ -547,21 +504,22 @@ void Bit_group_fx ( Word16 factor_fx; Word32 R_temp_fx[16], R_sum_fx = 0, R_sum_org_fx = 0, Bits_avg_fx = 0; Word32 L_tmp; + UWord32 lo; /* initialization for bit allocation in one group*/ tmp = 6554; move16(); /*Q15 1/5 */ - if(sub(thr,5) == 0) + IF(sub(thr,5) == 0) { tmp = 6554; move16(); /*Q15 1/5 */ } - if(sub(thr,6) == 0) + IF(sub(thr,6) == 0) { tmp = 5462; move16();/*Q15 1/6 */ } - if(sub(thr,7) == 0) + IF(sub(thr,7) == 0) { tmp = 4682; move16();/*Q15 1/7 */ @@ -578,7 +536,7 @@ void Bit_group_fx ( } /* Rearrange norm vector in decreasing order */ - reordvct_fx(y_index, band_num, index); + reordvct(y_index, band_num, index); /* norm vector modification */ factor_fx = div_s(1, band_num);/*Q15 */ @@ -612,7 +570,7 @@ void Bit_group_fx ( { FOR ( j = 0; j < band_num; j++) { - if ( y_index[j] < 0 ) + IF ( y_index[j] < 0 ) { y_index[j] = 0; move16(); @@ -634,7 +592,8 @@ void Bit_group_fx ( { FOR (k = 0; k <= i; k++) { - R_temp_fx[k] = L_deposit_h(0);/*Q21 */ + R_temp_fx[k] = 0; + move32();/*Q21 */ } } ELSE @@ -647,7 +606,7 @@ void Bit_group_fx ( FOR (k = 0; k <= i; k++) { L_tmp = L_shl(L_deposit_l(y_index[k]),24); - L_tmp = Mult_32_32(Bits_avg_fx,L_tmp);/*Q(23-exp) */ + Mpy_32_32_ss(Bits_avg_fx,L_tmp,&L_tmp,&lo); R_temp_fx[k] = L_shl(L_tmp,sub(exp,2)); move32();/*Q21 */ @@ -657,7 +616,8 @@ void Bit_group_fx ( L_tmp = L_shl(L_deposit_l(thr),21);/*Q21 */ IF ( L_sub(R_temp_fx[i],L_tmp) < 0 ) { - R_temp_fx[i] = L_deposit_h(0); + R_temp_fx[i] = 0; + move32(); norm_sum = sub(norm_sum,y_index[i]); i--; } @@ -671,7 +631,7 @@ void Bit_group_fx ( { FOR ( j = 0; j < bit_band; j++ ) { - if ( y_index[j] < 0 ) + IF ( y_index[j] < 0 ) { y_index[j] = 0; move16(); @@ -682,7 +642,8 @@ void Bit_group_fx ( FOR ( j = bit_band; j < band_num; j++ ) { - R_temp_fx[j] = L_deposit_l(0); + R_temp_fx[j] = 0; + move32(); } norm_sum = 0; @@ -698,7 +659,8 @@ void Bit_group_fx ( { FOR (k = 0; k < i; k++) { - R_temp_fx[k] = L_deposit_l(0); /*Q21 */ + R_temp_fx[k] = 0; + move32();/*Q21 */ } } ELSE @@ -710,8 +672,7 @@ void Bit_group_fx ( FOR (k = 0; k < i; k++) { L_tmp = L_shl(L_deposit_l(y_index[k]),24); - L_tmp = Mult_32_32(Bits_avg_fx,L_tmp);/*Q(23-exp) */ - + Mpy_32_32_ss(Bits_avg_fx,L_tmp,&L_tmp,&lo); R_temp_fx[k] = L_shl(L_tmp,sub(exp,2)); move32();/*Q21 */ } @@ -725,7 +686,8 @@ void Bit_group_fx ( FOR(m = k; m < i; m++) { norm_sum = sub(norm_sum,y_index[m]); - R_temp_fx[m] = L_deposit_l(0); /*Q21 */ + R_temp_fx[m] = 0; + move32();/*Q21 */ } i = k; BREAK; @@ -763,12 +725,12 @@ void Bit_group_fx ( * WB bit allocation *-------------------------------------------------------------------*/ -Word16 BitAllocWB_fx( /* o : t Q0*/ - Word16 *y, /* i : norm of sub-vectors Q0*/ - Word16 B, /* i : number of available bits Q0*/ - Word16 N, /* i : number of sub-vectors Q0*/ - Word16 *R, /* o : bit-allocation indicator Q0*/ - Word16 *Rsubband_fx /* o : sub-band bit-allocation vector Q3*/ +short BitAllocWB ( + short *y, /* i : norm of sub-vectors */ + short B, /* i : number of available bits */ + short N, /* i : number of sub-vectors */ + short *R, /* o : bit-allocation indicator */ + short *Rsubband /* o : sub-band bit-allocation vector (Q3) */ ) { Word16 t_fx; @@ -778,13 +740,13 @@ Word16 BitAllocWB_fx( /* o : t Word16 factor_fx[2];/*Q13 */ Word16 BANDS; Word16 tmp,exp; - Word16 Rsum_sub_fx_tmp=0; /* initialize just to avoid compiler warning */ Word32 L_tmp,L_tmp1; Word32 Rsubband_buf[NB_SFM]; + UWord16 lo; BANDS = N; move16(); - if( sub(BANDS,SFM_N) > 0) + IF( sub(BANDS,SFM_N) > 0) { BANDS = SFM_N; move16(); @@ -797,49 +759,36 @@ Word16 BitAllocWB_fx( /* o : t } /* Calculate the norm sum and average of sub-band */ Rsum_sub_fx[0] = 0; - move16(); FOR ( j = 0; j < SFM_G1; j++ ) { - if ( y[j] > 0 ) + IF ( y[j] > 0 ) { - Rsum_sub_fx_tmp = add(Rsum_sub_fx[0],y[j]); /*Q0 */ - } - if (y[j] > 0) - { - Rsum_sub_fx[0] = Rsum_sub_fx_tmp; - move16(); /*Q0 */ - } - } - Ravg_sub_32_fx[0] = L_mult(Rsum_sub_fx[0], 2048); - move32();/*Q16 0+15+1 //q15 1/16 =2048 */ - - Rsum_sub_fx[1] = 0; - move16(); - FOR ( j = SFM_G1; j < SFM_G1G2; j++ ) - { - if ( y[j] > 0 ) - { - Rsum_sub_fx_tmp = add(Rsum_sub_fx[1],y[j]); /*Q0 */ - } - if ( y[j] > 0 ) - { - Rsum_sub_fx[1] = Rsum_sub_fx_tmp; + Rsum_sub_fx[0] = add(Rsum_sub_fx[0],y[j]); move16();/*Q0 */ } } - Ravg_sub_32_fx[1] = L_mult(Rsum_sub_fx[1], 4096); /*16 0+15+1 //q15 1/8 =4096 */ + Ravg_sub_32_fx[0] = L_mult(Rsum_sub_fx[0], 2048); + move32();/*Q16 0+15+1 , q15 1/16 =2048 */ + + Rsum_sub_fx[1] = 0; + move32(); + FOR ( j = SFM_G1; j < SFM_G1G2; j++ ) + { + IF ( y[j] > 0 ) + { + Rsum_sub_fx[1] = add(Rsum_sub_fx[1],y[j]); + move16();/*Q0 */ + } + } + Ravg_sub_32_fx[1] = L_mult(Rsum_sub_fx[1], 4096); /*16 0+15+1 , q15 1/8 =4096 */ Rsum_sub_fx[2] = 0; move16(); FOR ( j = SFM_G1G2; j < BANDS; j++ ) { - if ( y[j] > 0 ) + IF ( y[j] > 0 ) { - Rsum_sub_fx_tmp = add(Rsum_sub_fx[2],y[j]); /*Q0 */ - } - if ( y[j] > 0 ) - { - Rsum_sub_fx[2] = Rsum_sub_fx_tmp; + Rsum_sub_fx[2] = add(Rsum_sub_fx[2],y[j]); move16();/*Q0 */ } } @@ -859,7 +808,6 @@ Word16 BitAllocWB_fx( /* o : t R_diff_32_fx[1] = L_sub(Ravg_sub_32_fx[1], Ravg_sub_32_fx[2]); move32();/*Q16 */ - test(); IF ( L_sub(R_diff_32_fx[0],393216) < 0 && L_sub(R_diff_32_fx[1],245760) < 0 ) { IF(Rsum_fx == 0) @@ -877,26 +825,23 @@ Word16 BitAllocWB_fx( /* o : t tmp = shl(Rsum_fx,exp);/*Q(exp) */ tmp = div_s(16384,tmp);/*Q(15+14-exp) */ L_tmp1 = L_mult(B,Rsum_sub_fx[0]);/*Q1 */ - L_tmp = Mult_32_16(L_tmp1,tmp);/*Q(15-exp) */ + Mpy_32_16_ss(L_tmp1,tmp,&L_tmp,&lo); B1 = extract_h(L_shl(L_tmp,add(exp,1)));/*Q0 */ - test(); - if(L_sub(L_tmp1,L_mult(B1,Rsum_fx)) > 0 && L_sub(L_tmp1,L_mult(add(B1,1),Rsum_fx)) >= 0) + IF(L_sub(L_tmp1,L_mult(B1,Rsum_fx)) > 0 && L_sub(L_tmp1,L_mult(add(B1,1),Rsum_fx)) >= 0) { B1 = add(B1,1); } L_tmp1 = L_mult(B,Rsum_sub_fx[1]);/*Q1 */ - L_tmp = Mult_32_16(L_tmp1,tmp);/*Q(15-exp) */ + Mpy_32_16_ss(L_tmp1,tmp,&L_tmp,&lo); B2 = extract_h(L_shl(L_tmp,add(exp,1)));/*Q0 */ - test(); - if(L_sub(L_tmp1,L_mult(B2,Rsum_fx)) > 0 && L_sub(L_tmp1,L_mult(add(B2,1),Rsum_fx)) >= 0) + IF(L_sub(L_tmp1,L_mult(B2,Rsum_fx)) > 0 && L_sub(L_tmp1,L_mult(add(B2,1),Rsum_fx)) >= 0) { B2 = add(B2,1); } L_tmp1 = L_mult(B,Rsum_sub_fx[2]);/*Q1 */ - L_tmp = Mult_32_16(L_tmp1,tmp);/*Q(15-exp) */ + Mpy_32_16_ss(L_tmp1,tmp,&L_tmp,&lo); B3 = extract_h(L_shl(L_tmp,add(exp,1)));/*Q0 */ - test(); - if(L_sub(L_tmp1,L_mult(B3,Rsum_fx)) > 0 && L_sub(L_tmp1,L_mult(add(B3,1),Rsum_fx)) >= 0) + IF(L_sub(L_tmp1,L_mult(B3,Rsum_fx)) > 0 && L_sub(L_tmp1,L_mult(add(B3,1),Rsum_fx)) >= 0) { B3 = add(B3,1); } @@ -977,19 +922,17 @@ Word16 BitAllocWB_fx( /* o : t tmp = shl(Rsum_fx,exp);/*Q(exp) */ tmp = div_s(16384,tmp);/*Q(15+14-exp) */ L_tmp1 = L_mult(B,Rsum_sub_fx[0]);/*Q1 */ - L_tmp = Mult_32_16(L_tmp1,tmp);/*Q(15-exp) */ + Mpy_32_16_ss(L_tmp1,tmp,&L_tmp,&lo); B1 = extract_h(L_shl(L_tmp,add(exp,1)));/*Q0 */ - test(); - if(L_sub(L_tmp1,L_mult(B1,Rsum_fx)) > 0 && L_sub(L_tmp1,L_mult(add(B1,1),Rsum_fx)) >= 0) + IF(L_sub(L_tmp1,L_mult(B1,Rsum_fx)) > 0 && L_sub(L_tmp1,L_mult(add(B1,1),Rsum_fx)) >= 0) { B1 = add(B1,1); } - L_tmp1 = Mult_32_16(1975684956,shl(B,5));/*Q(31+5-15=21) */ - L_tmp1 = Mult_32_16(L_tmp1,shl(Rsum_sub_fx[1],7));/*Q(21+7-15=13) */ - L_tmp = Mult_32_16(L_tmp1,tmp);/*Q(27-exp) */ + Mpy_32_16_ss(1975684956,shl(B,5),&L_tmp1,&lo); + Mpy_32_16_ss(L_tmp1,shl(Rsum_sub_fx[1],7),&L_tmp1,&lo); + Mpy_32_16_ss(L_tmp1,tmp,&L_tmp,&lo); B2 = extract_h(L_shl(L_tmp,sub(exp,11)));/*Q0 */ - test(); - if(L_sub(L_tmp1,L_shl(L_mult(B2,Rsum_fx),12)) > 0 && L_sub(L_add(L_tmp1,2),L_shl(L_mult(add(B2,1),Rsum_fx),12)) >= 0) + IF(L_sub(L_tmp1,L_shl(L_mult(B2,Rsum_fx),12)) > 0 && L_sub(L_add(L_tmp1,2),L_shl(L_mult(add(B2,1),Rsum_fx),12)) >= 0) { B2 = add(B2,1); } @@ -1012,11 +955,13 @@ Word16 BitAllocWB_fx( /* o : t Bit_group_fx( y, SFM_G1G2, BANDS, B3, 7, Rsubband_buf, factor_fx); FOR (i = 0; i < BANDS; i++) { - Rsubband_fx[i] = extract_l(L_shr(Rsubband_buf[i], 18)); + Rsubband[i] = extract_l(L_shr(Rsubband_buf[i], 18)); + move16(); } /* Calcuate total used bits and initialize R to be used for Noise Filling */ - L_tmp = L_deposit_l(0); + L_tmp = 0; + move32(); FOR( i = 0; i < N; i++) { L_tmp = L_add(L_tmp,Rsubband_buf[i]);/*Q21 */ @@ -1025,5 +970,4 @@ Word16 BitAllocWB_fx( /* o : t t_fx = extract_h(L_shr(L_tmp, 5)); /*Q0 */ return (Word16)t_fx; - } diff --git a/src/libs/libevs/lib_com/bitallocsum.cpp b/src/libs/libevs/lib_com/bitallocsum.cpp new file mode 100644 index 00000000..e1ed7bf7 --- /dev/null +++ b/src/libs/libevs/lib_com/bitallocsum.cpp @@ -0,0 +1,60 @@ +/*==================================================================================== + EVS Codec 3GPP TS26.443 Nov 13, 2018. Version 12.11.0 / 13.7.0 / 14.3.0 / 15.1.0 + ====================================================================================*/ + +#include "options.h" +#include "cnst.h" +#include "prot.h" + + +/*-------------------------------------------------------------------------- + * bitallocsum() + * + * Calculate the total number of bits allocated over frame + *--------------------------------------------------------------------------*/ + +void bitallocsum( + short *R, /* i : bit-allocation vector */ + const short nb_sfm, /* i : number of sub-vectors */ + short *sum, /* o : total number of bits allocated */ + short *Rsubband, /* o : rate per subband (Q3) */ + const short v, /* i : bit rate */ + const short length, /* i : length of spectrum (32 or 48 kHz samplerate) */ + const short *sfmsize /* i : band length */ +) +{ + short i; + short total, tmp; + short diff; + + total = 0; + for (i = 0; i < nb_sfm; i++) + { + tmp = R[i] * sfmsize[i]; + Rsubband[i] = tmp*8; + total += tmp; + } + *sum = total; + + if ( length <= L_FRAME32k ) + { + diff = v - *sum; + i = 0; + while ( diff > 0 ) + { + if ( R[i] > 0 ) + { + Rsubband[i] += 8; + diff -= 1; + *sum += 1; + } + i++; + if ( i >= nb_sfm ) + { + i = 0; + } + } + } + + return; +} diff --git a/src/libs/libevs/lib_com/bitallocsum_fx.cpp b/src/libs/libevs/lib_com/bitallocsum_fx.cpp deleted file mode 100755 index 5d4fe9e3..00000000 --- a/src/libs/libevs/lib_com/bitallocsum_fx.cpp +++ /dev/null @@ -1,63 +0,0 @@ -/*==================================================================================== - EVS Codec 3GPP TS26.442 Apr 03, 2018. Version 12.11.0 / 13.6.0 / 14.2.0 - ====================================================================================*/ - -#include "options.h" /* Compilation switches */ -#include "cnst_fx.h" /* Common constants */ -#include "prot_fx.h" /* Function prototypes */ -#include "stl.h" /* Common constants */ - -/*-------------------------------------------------------------------------- - * bitallocsum_fx() - * - * Calculate the total number of bits allocated over frame - *--------------------------------------------------------------------------*/ -void bitallocsum_fx( - Word16 *R, /* i : bit-allocation vector Q0 */ - const Word16 nb_sfm, /* i : number of sub-vectors Q0 */ - Word16 *sum, /* o : total number of bits allocated Q0 */ - Word16 *Rsubband, /* o : rate per subband Q3 */ - const Word16 v, /* i : bit rate Q0 */ - const Word16 length, /* i : length of spectrum (32 or 48 kHz samplerate) Q0 */ - const Word16 *sfmsize /* i : band length Q0 */ -) -{ - Word16 i; - Word16 total, tmp; - Word16 diff; - - total = (Word16)0; - move16(); - FOR (i = 0; i < nb_sfm; i++) - { - tmp = extract_l(L_mult0(R[i], sfmsize[i])); - Rsubband[i] = shl(tmp, 3); - move16(); - total = add(total, tmp); - } - *sum = total; - - IF ( sub(length, L_FRAME32k) <= 0 ) - { - diff = sub(v, *sum); - i = (Word16)0; - move16(); - WHILE ( diff > 0 ) - { - IF ( R[i] > 0 ) - { - Rsubband[i] = add(Rsubband[i], 8); - move16(); - diff = sub(diff, 1); - *sum = add(*sum, 1); - } - i = add(i, 1); - if ( sub(i, nb_sfm) >= 0 ) - { - i = (Word16)0; - move16(); - } - } - } - return; -} diff --git a/src/libs/libevs/lib_com/bits_alloc.cpp b/src/libs/libevs/lib_com/bits_alloc.cpp old mode 100755 new mode 100644 index 7d21a0a0..d13a4ff9 --- a/src/libs/libevs/lib_com/bits_alloc.cpp +++ b/src/libs/libevs/lib_com/bits_alloc.cpp @@ -1,384 +1,308 @@ /*==================================================================================== - EVS Codec 3GPP TS26.442 Apr 03, 2018. Version 12.11.0 / 13.6.0 / 14.2.0 + EVS Codec 3GPP TS26.443 Nov 13, 2018. Version 12.11.0 / 13.7.0 / 14.3.0 / 15.1.0 ====================================================================================*/ #include +#include #include #include "options.h" -#include "prot_fx.h" -#include "basop_util.h" -#include "stl.h" -#include "options.h" -#include "rom_com_fx.h" +#include "rom_com.h" +#include "prot.h" + +/*-------------------------------------------------------------------* +* Local function +*--------------------------------------------------------------------*/ + +static int BITS_ALLOC_adjust_acelp_fixed_cdk( int bits_frame, int *fixed_cdk_index, int nb_subfr ); -/* - * function BITS_ALLOC_init_config_acelp() - * - * description: initial configuration for ACELP - * - * return: void - */ +/*-------------------------------------------------------------------* +* BITS_ALLOC_init_config_acelp() +* +* initial configuration for Mode 2 ACELP +*--------------------------------------------------------------------*/ + void BITS_ALLOC_init_config_acelp( - const Word32 bit_rate, - const Word8 narrowBand, - const Word16 nb_subfr, - ACELP_config *pConfigAcelp /*o: configuration structure of ACELP*/ + int bit_rate, + int narrowBand, + int nb_subfr, + ACELP_config *acelp_cfg /*o: configuration structure of ACELP*/ ) { - Word8 rate_mode_index; + short rate_mode_index; + if( bit_rate <= ACELP_9k60 ) + { + rate_mode_index=0; + } + else + { + rate_mode_index=1; + } - move16(); - move16(); - move16(); - rate_mode_index=(bit_rate > ACELP_9k60); - - pConfigAcelp->mode_index=rate_mode_index; - + acelp_cfg->mode_index=rate_mode_index; /*LPC: midLpc should be swithced off?*/ - pConfigAcelp->midLpc_enable = 1; - move16(); + acelp_cfg->midLpc_enable = 1; /*ACELP ICB config*/ - test(); - IF( (rate_mode_index==0) || narrowBand != 0 ) + if( (rate_mode_index==0) || (narrowBand==1) ) { - move16(); - move16(); - move16(); - move16(); - move16(); - move16(); - pConfigAcelp->pre_emphasis = 1; - pConfigAcelp->formant_enh = 1; - pConfigAcelp->formant_enh_num = FORMANT_SHARPENING_G1; - pConfigAcelp->formant_enh_den = FORMANT_SHARPENING_G2; - pConfigAcelp->formant_tilt = 0; - pConfigAcelp->voice_tilt = 0; + acelp_cfg->pre_emphasis = 1; + acelp_cfg->formant_enh = 1; + acelp_cfg->formant_enh_num = FORMANT_SHARPENING_G1; + acelp_cfg->formant_enh_den = FORMANT_SHARPENING_G2; + acelp_cfg->formant_tilt = 0; + acelp_cfg->voice_tilt = 0; } - ELSE + else { - move16(); - move16(); - move16(); - move16(); - move16(); - move16(); - pConfigAcelp->pre_emphasis = 0; - pConfigAcelp->formant_enh = 1; - pConfigAcelp->formant_enh_num = FORMANT_SHARPENING_G1; - pConfigAcelp->formant_enh_den = FORMANT_SHARPENING_G2; - pConfigAcelp->formant_tilt = 1; - pConfigAcelp->voice_tilt = 1; + acelp_cfg->pre_emphasis = 0; + acelp_cfg->formant_enh = 1; + acelp_cfg->formant_enh_num = FORMANT_SHARPENING_G1; + acelp_cfg->formant_enh_den = FORMANT_SHARPENING_G2; + acelp_cfg->formant_tilt = 1; + acelp_cfg->voice_tilt = 1; } /*Wide band @ 16kHz*/ - IF ( sub(nb_subfr,NB_SUBFR16k) == 0 ) + if ( nb_subfr == NB_SUBFR16k ) { - move16(); - move16(); - move16(); - move16(); - move16(); - move16(); - pConfigAcelp->pre_emphasis = 1; - pConfigAcelp->formant_enh = 1; - pConfigAcelp->formant_enh_num = FORMANT_SHARPENING_G1_16k; - pConfigAcelp->formant_enh_den = FORMANT_SHARPENING_G2_16k; - pConfigAcelp->formant_tilt = 0; - pConfigAcelp->voice_tilt = 2; + acelp_cfg->pre_emphasis = 1; + acelp_cfg->formant_enh = 1; + acelp_cfg->formant_enh_num = FORMANT_SHARPENING_G1_16k; + acelp_cfg->formant_enh_den = FORMANT_SHARPENING_G2_16k; + acelp_cfg->formant_tilt = 0; + acelp_cfg->voice_tilt = 2; } + return; } +/*-------------------------------------------------------------------* +* BITS_ALLOC_config_acelp() +* +* configure all Mode 2 ACELP modes and allocate the bits +*--------------------------------------------------------------------*/ -/* - * function BITS_ALLOC_config_acelp() - * - * description: configure all acelp modes and allocate the bits - * - * return: bit demand - */ -Word16 BITS_ALLOC_config_acelp( - const Word16 bits_frame, /*i: remaining bit budget for the frame*/ - const Word16 coder_type, /*i: acelp coder type*/ - ACELP_config *pConfigAcelp, /*i/o: configuration structure of ACELP*/ - const Word16 narrowBand, - const Word16 nb_subfr +int BITS_ALLOC_config_acelp( + const int bits_frame, /* i : remaining bit budget for the frame */ + const short coder_type, /* i : acelp extended mode index */ + ACELP_config *acelp_cfg, /* i/o: configuration structure of ACELP */ + const short narrowBand, /* i : narrowband flag */ + const short nb_subfr /* i : number of subframes */ ) { - Word16 mode_index; - Word16 band_index; - Word16 i; - Word16 remaining_bits, bits; + short mode_index; + short band_index; + short i; + short remaining_bits, bits; + /*Sanity check*/ - - move16(); - move16(); - move16(); - mode_index = pConfigAcelp->mode_index; + mode_index = acelp_cfg->mode_index; band_index = (narrowBand==0); - bits=0; + bits = 0; - IF ( band_index==0 ) + if ( band_index==0 ) { - move16(); - pConfigAcelp->formant_enh = 1; - if(sub(coder_type,INACTIVE) == 0) + if(coder_type == INACTIVE) { - move16(); - pConfigAcelp->formant_enh = 0; + acelp_cfg->formant_enh = 0; + } + else + { + acelp_cfg->formant_enh = 1; } } - IF ( s_and(sub(band_index,1)==0, sub(nb_subfr,4)==0) ) + if( band_index==1 && nb_subfr == NB_SUBFR ) { - IF(sub(coder_type,INACTIVE) == 0) + + if( coder_type == INACTIVE) { - pConfigAcelp->pre_emphasis = 0; - move16(); - pConfigAcelp->formant_enh = 0; - move16(); - pConfigAcelp->formant_enh_num = FORMANT_SHARPENING_G1_16k; - move16(); - pConfigAcelp->voice_tilt = 1; - move16(); - pConfigAcelp->formant_tilt = 1; - move16(); + acelp_cfg->pre_emphasis = 0; + acelp_cfg->formant_enh = 0; + acelp_cfg->formant_enh_num = FORMANT_SHARPENING_G1_16k; + acelp_cfg->formant_tilt = 1; + acelp_cfg->voice_tilt = 1; } - ELSE + else { - pConfigAcelp->pre_emphasis = 1; - move16(); - pConfigAcelp->formant_enh = 1; - move16(); - pConfigAcelp->formant_enh_num = FORMANT_SHARPENING_G1; - move16(); - pConfigAcelp->voice_tilt = 0; - move16(); - pConfigAcelp->formant_tilt = 0; - move16(); + acelp_cfg->pre_emphasis = 1; + acelp_cfg->formant_enh = 1; + acelp_cfg->formant_enh_num = FORMANT_SHARPENING_G1; + acelp_cfg->formant_tilt = 0; + acelp_cfg->voice_tilt = 0; } } - IF (sub(coder_type,UNVOICED) == 0 ) - { - IF(sub(ACELP_GAINS_MODE[mode_index][band_index][coder_type], 6) == 0) - { - pConfigAcelp->pitch_sharpening = 0; - move16(); - pConfigAcelp->phase_scrambling = 1; - move16(); - } - ELSE - { - pConfigAcelp->pitch_sharpening = 0; - move16(); - pConfigAcelp->phase_scrambling = 0; - move16(); - } - } - ELSE - { - pConfigAcelp->pitch_sharpening = 1; - move16(); - pConfigAcelp->phase_scrambling = 0; - move16(); - } - IF(sub(coder_type,ACELP_MODE_MAX) > 0) /* keep pitch sharpening for RF_ALLPRED mode */ + if( coder_type == UNVOICED ) { - pConfigAcelp->pitch_sharpening = 0; - pConfigAcelp->phase_scrambling = 0; + if( ACELP_GAINS_MODE[mode_index][band_index][coder_type]==6 ) + { + acelp_cfg->pitch_sharpening = 0; + acelp_cfg->phase_scrambling = 1; + } + else + { + acelp_cfg->pitch_sharpening = 0; + acelp_cfg->phase_scrambling = 0; + } + } + else + { + acelp_cfg->pitch_sharpening = 1; + acelp_cfg->phase_scrambling = 0; + } + + if( coder_type > ACELP_MODE_MAX ) + { + /* keep pitch sharpening for RF_ALLPRED mode */ + acelp_cfg->pitch_sharpening = 0; + acelp_cfg->phase_scrambling = 0; } /*Allocate bits and different modes*/ - move16(); - pConfigAcelp->bpf_mode=ACELP_BPF_MODE[mode_index][band_index][coder_type]; - bits = add(bits, ACELP_BPF_BITS[pConfigAcelp->bpf_mode]); + acelp_cfg->bpf_mode=ACELP_BPF_MODE[mode_index][band_index][coder_type]; + bits+=ACELP_BPF_BITS[acelp_cfg->bpf_mode]; - move16(); - move16(); - pConfigAcelp->nrg_mode=ACELP_NRG_MODE[mode_index][band_index][coder_type]; - pConfigAcelp->nrg_bits=ACELP_NRG_BITS[pConfigAcelp->nrg_mode]; - bits = add(bits, pConfigAcelp->nrg_bits); + acelp_cfg->nrg_mode=ACELP_NRG_MODE[mode_index][band_index][coder_type]; + acelp_cfg->nrg_bits=ACELP_NRG_BITS[acelp_cfg->nrg_mode]; + bits+=acelp_cfg->nrg_bits; - move16(); - pConfigAcelp->ltp_mode=ACELP_LTP_MODE[mode_index][band_index][coder_type]; + acelp_cfg->ltp_mode=ACELP_LTP_MODE[mode_index][band_index][coder_type]; + acelp_cfg->ltp_bits=0; + acelp_cfg->ltf_mode=ACELP_LTF_MODE[mode_index][band_index][coder_type]; + acelp_cfg->ltf_bits=ACELP_LTF_BITS[acelp_cfg->ltf_mode]; - move16(); - pConfigAcelp->ltp_bits=0; - - move16(); - pConfigAcelp->ltf_mode=ACELP_LTF_MODE[mode_index][band_index][coder_type]; - - move16(); - pConfigAcelp->ltf_bits=ACELP_LTF_BITS[pConfigAcelp->ltf_mode]; - if ( s_and(sub(nb_subfr,5)==0, sub(pConfigAcelp->ltf_bits,4)==0) ) + if( nb_subfr == NB_SUBFR16k && acelp_cfg->ltf_bits == 4 ) { - pConfigAcelp->ltf_bits = add(pConfigAcelp->ltf_bits,1); + acelp_cfg->ltf_bits++; } - bits = add(bits,pConfigAcelp->ltf_bits); + bits+=acelp_cfg->ltf_bits; - FOR ( i=0; igains_mode[i] = ACELP_GAINS_MODE[mode_index][band_index][coder_type]; - move16(); + acelp_cfg->gains_mode[i] = ACELP_GAINS_MODE[mode_index][band_index][coder_type]; /* skip subframe 1, 3 gain encoding, and use from subframe 0, and 3, respectively */ - test(); - test(); - IF(sub(coder_type,ACELP_MODE_MAX) >= 0 && (sub(i,1) == 0 || sub(i,3) == 0)) + if(coder_type >= ACELP_MODE_MAX && (i == 1 || i == 3)) { - pConfigAcelp->gains_mode[i] = 0; + acelp_cfg->gains_mode[i] = 0; } - bits = add(bits, ACELP_GAINS_BITS[pConfigAcelp->gains_mode[i]]); - - move16(); - bits = add(bits, ACELP_LTP_BITS_SFR[pConfigAcelp->ltp_mode][i]); - pConfigAcelp->ltp_bits= add( pConfigAcelp->ltp_bits,ACELP_LTP_BITS_SFR[pConfigAcelp->ltp_mode][i]); + bits += ACELP_GAINS_BITS[acelp_cfg->gains_mode[i]]; + bits += ACELP_LTP_BITS_SFR[acelp_cfg->ltp_mode][i]; + acelp_cfg->ltp_bits += ACELP_LTP_BITS_SFR[acelp_cfg->ltp_mode][i]; } /*Innovation*/ - - if ( sub(bits_frame,bits) < 0) + if( bits_frame < bits ) { - printf("Warning: bits per frame too low\n"); + printf("\nWarning: bits per frame too low\n"); return -1; } - IF( sub(coder_type,RF_ALLPRED) == 0 ) + if( coder_type == RF_ALLPRED ) { - set16_fx(pConfigAcelp->fixed_cdk_index, -1, nb_subfr); + set_i(acelp_cfg->fixed_cdk_index, -1, nb_subfr); } - ELSE IF ( sub(coder_type,RF_GENPRED) == 0 ) + else if ( coder_type == RF_GENPRED ) { - pConfigAcelp->fixed_cdk_index[0] = 0; /* 7 bits */ - pConfigAcelp->fixed_cdk_index[1] = -1; - pConfigAcelp->fixed_cdk_index[2] = 0; /* 7 bits */ - pConfigAcelp->fixed_cdk_index[3] = -1; - pConfigAcelp->fixed_cdk_index[4] = -1; - bits = add(bits,14); + acelp_cfg->fixed_cdk_index[0] = 0; /* 7 bits */ + acelp_cfg->fixed_cdk_index[1] = -1; + acelp_cfg->fixed_cdk_index[2] = 0; /* 7 bits */ + acelp_cfg->fixed_cdk_index[3] = -1; + acelp_cfg->fixed_cdk_index[4] = -1; + bits += 14; } - ELSE IF( sub(coder_type,RF_NOPRED) == 0 ) + else if( coder_type == RF_NOPRED ) { - set16_fx(pConfigAcelp->fixed_cdk_index, 0, nb_subfr); - bits = add(bits,28); + set_i(acelp_cfg->fixed_cdk_index, 0, nb_subfr); + bits += 28; } - ELSE + else { - bits = add(bits, BITS_ALLOC_adjust_acelp_fixed_cdk(sub(bits_frame,bits), pConfigAcelp->fixed_cdk_index, nb_subfr )); + bits += BITS_ALLOC_adjust_acelp_fixed_cdk(bits_frame - bits, acelp_cfg->fixed_cdk_index, nb_subfr ); } - remaining_bits = sub(bits_frame, bits); + remaining_bits = bits_frame-bits; /*Sanity check*/ - if (remaining_bits<0) + if( remaining_bits < 0 ) { - move16(); bits = -1; } - return(bits); + return( bits ); } +/*-------------------------------------------------------------------* +* BITS_ALLOC_adjust_acelp_fixed_cdk() +* +* +*--------------------------------------------------------------------*/ -static -Word16 BITS_ALLOC_adjust_generic( - const Word16 bits_frame, /*i: bit budget*/ - Word16 *fixed_cdk_index, - const Word16 nb_subfr, - const Word16 *pulseconfigbits, - const Word16 pulseconfig_size +static int BITS_ALLOC_adjust_acelp_fixed_cdk( + int bits_frame, /*i: bit budget*/ + int *fixed_cdk_index, + int nb_subfr ) { - Word16 bits_subframe2, inb_subfr; - Word16 sfr, k, bitsused, bits_currsubframe; + int bits_subframe2; + int sfr, k, bitsused, bits_currsubframe; bits_subframe2 = bits_frame; - move16(); - inb_subfr = 8192/*1.0f/NB_SUBFR Q15*/; - move16(); - if ( sub(nb_subfr,NB_SUBFR16k) == 0 ) - { - inb_subfr = 6554/*1.0f/NB_SUBFR16k Q15*/; - move16(); - } - IF ( sub(bits_subframe2, i_mult2(pulseconfigbits[0], nb_subfr)) < 0 ) /* not in final code - not instrumented */ + if( bits_subframe2 < ACELP_FIXED_CDK_BITS(0)*nb_subfr ) { - return add(bits_frame,1); /* Not enough bits for lowest mode. -> trigger alarm*/ + return(bits_frame+1 ); /* Not enough bits for lowest mode. -> trigger alarm*/ } /* search cdk-index for first subframe */ - FOR (k=0; k bits_subframe2) + if (ACELP_FIXED_CDK_BITS(k)*nb_subfr > bits_subframe2) { - k = sub(k,1); /* previous mode did not exceed bit-budget */ - BREAK; + k--; /* previous mode did not exceed bit-budget */ + break; } } - if (i_mult2(pulseconfigbits[k], nb_subfr) > bits_subframe2) + if( ACELP_FIXED_CDK_BITS(k)*nb_subfr > bits_subframe2 ) { - k = sub(k,1); /* previous mode did not exceed bit-budget */ + k--; /* previous mode did not exceed bit-budget */ } - - move16(); fixed_cdk_index[0] = k; - bitsused = i_mult2(pulseconfigbits[k], nb_subfr); + bitsused = ACELP_FIXED_CDK_BITS(k); - FOR (sfr=1; sfr < nb_subfr; sfr++) + for (sfr=1; sfr < nb_subfr; sfr++) { - /*bits_currsubframe = (int)(((float)sfr+1.0f)*bits_subframe) - bitsused;*/ - bits_currsubframe = sub(add(i_mult2(sfr, bits_subframe2), bits_subframe2), bitsused); + bits_currsubframe = (sfr*bits_subframe2 + bits_subframe2) - bitsused*nb_subfr; /* try increasing mode while below threshold */ - WHILE ( (sub(k, pulseconfig_size-1) < 0) && (sub(i_mult2(pulseconfigbits[add(k,1)], nb_subfr),bits_currsubframe) <= 0) ) + while ( (k < ACELP_FIXED_CDK_NB-1) && (ACELP_FIXED_CDK_BITS(k+1)*nb_subfr <= bits_currsubframe) ) { - test(); - k = add(k,1); + k++; } /* try decreasing mode until below threshold */ - WHILE (i_mult2(pulseconfigbits[k], nb_subfr) > bits_currsubframe) + while (ACELP_FIXED_CDK_BITS(k)*nb_subfr > bits_currsubframe) { - k = sub(k,1); - - IF (k == 0) + k--; + if ( k == 0 ) { - BREAK; + break; } } /* store mode */ - move16(); fixed_cdk_index[sfr] = k; - bitsused = add(bitsused, i_mult2(pulseconfigbits[k], nb_subfr)); + bitsused += ACELP_FIXED_CDK_BITS(k); } - return mult_r(bitsused, inb_subfr); -} - -Word16 BITS_ALLOC_adjust_acelp_fixed_cdk( - const Word16 bits_frame, /*i: bit budget*/ - Word16 *fixed_cdk_index, - const Word16 nb_subfr -) -{ - Word16 bitsused; - - - bitsused = BITS_ALLOC_adjust_generic(bits_frame, fixed_cdk_index, nb_subfr, ACELP_CDK_BITS, ACELP_FIXED_CDK_NB); - - return bitsused; } - diff --git a/src/libs/libevs/lib_com/bitstream_fx.cpp b/src/libs/libevs/lib_com/bitstream.cpp old mode 100755 new mode 100644 similarity index 50% rename from src/libs/libevs/lib_com/bitstream_fx.cpp rename to src/libs/libevs/lib_com/bitstream.cpp index 09079ee6..793c72a2 --- a/src/libs/libevs/lib_com/bitstream_fx.cpp +++ b/src/libs/libevs/lib_com/bitstream.cpp @@ -1,17 +1,20 @@ /*==================================================================================== - EVS Codec 3GPP TS26.442 Apr 03, 2018. Version 12.11.0 / 13.6.0 / 14.2.0 + EVS Codec 3GPP TS26.443 Nov 13, 2018. Version 12.11.0 / 13.7.0 / 14.3.0 / 15.1.0 ====================================================================================*/ -#include #include -#include "stl.h" -#include "cnst_fx.h" /* Common constants */ -#include "prot_fx.h" /* Function prototypes */ +#include #include "options.h" -#include "basop_util.h" -#include "rom_com_fx.h" +#include "cnst.h" +#include "prot.h" +#include "stat_enc.h" +#include "stat_dec.h" +#include "rom_com.h" #include "mime.h" + + + /*-------------------------------------------------------------------* * pack_bit() * @@ -60,6 +63,7 @@ static Word16 unpack_bit( *mask = 0x80; (*pt)++; } + return bit; } @@ -68,6 +72,7 @@ static Word16 unpack_bit( * * lookup AMRWB IO mode *-------------------------------------------------------------------*/ + static Word16 rate2AMRWB_IOmode( Word32 rate /* i: bit rate */ ) @@ -112,8 +117,8 @@ static Word16 rate2EVSmode( switch ( rate ) { /* EVS Primary modes */ - case FRAME_NO_DATA : - return NO_DATA_TYPE; + case FRAME__NO_DATA : + return _NO_DATA; case SID_2k40 : return PRIMARY_SID; case PPP_NELP_2k80 : @@ -146,190 +151,169 @@ static Word16 rate2EVSmode( } /*-------------------------------------------------------------------* - * push_indice_fx( ) + * push_indice() * * Push a new indice into the buffer *-------------------------------------------------------------------*/ -void push_indice_fx( - Encoder_State_fx *st_fx, /* i/o: encoder state structure */ - Word16 id, /* i : ID of the indice */ - UWord16 value, /* i : value of the quantized indice */ - Word16 nb_bits /* i : number of bits used to quantize the indice */ +void push_indice( + Encoder_State *st, /* i/o: encoder state structure */ + short id, /* i : ID of the indice */ + unsigned short value, /* i : value of the quantized indice */ + short nb_bits /* i : number of bits used to quantize the indice */ ) { - Word16 i; + short i; - IF ( sub(st_fx->last_ind_fx, id) == 0 ) + if ( st->last_ind == id ) { /* indice with the same name as the previous one */ - i = st_fx->next_ind_fx; + i = st->next_ind; } - ELSE + else { /* new indice - find an empty slot in the list */ i = id; - move16(); - WHILE (sub(st_fx->ind_list_fx[i].nb_bits, -1) != 0) + while (st->ind_list[i].nb_bits != -1) { - i = add(i, 1); + i++; } } - /* store the values in the list */ - st_fx->ind_list_fx[i].value = value; - move16(); - st_fx->ind_list_fx[i].nb_bits = nb_bits; - move16(); + /* store the new indice in the list */ + st->ind_list[i].value = value; + st->ind_list[i].nb_bits = nb_bits; /* updates */ - st_fx->next_ind_fx = add(i, 1); - st_fx->last_ind_fx = id; - move16(); - st_fx->nb_bits_tot_fx = add(st_fx->nb_bits_tot_fx, nb_bits); + st->next_ind = i + 1; + st->last_ind = id; + st->nb_bits_tot += nb_bits; return; } /*-------------------------------------------------------------------* - * push_next_indice_fx() * + * push_next_indice() + * * Push a new indice into the buffer at the next position *-------------------------------------------------------------------*/ -void push_next_indice_fx( - Encoder_State_fx *st_fx, /* i/o: encoder state structure */ - UWord16 value, /* i : value of the quantized indice */ - Word16 nb_bits /* i : number of bits used to quantize the indice */ +void push_next_indice( + Encoder_State *st, /* i/o: encoder state structure */ + unsigned short value, /* i : value of the quantized indice */ + short nb_bits /* i : number of bits used to quantize the indice */ ) { /* store the values in the list */ - st_fx->ind_list_fx[st_fx->next_ind_fx].value = value; - move16(); - st_fx->ind_list_fx[st_fx->next_ind_fx].nb_bits = nb_bits; - move16(); - st_fx->next_ind_fx = add(st_fx->next_ind_fx, 1); - + st->ind_list[st->next_ind].value = value; + st->ind_list[st->next_ind].nb_bits = nb_bits; + st->next_ind++; /* update the total number of bits already written */ - st_fx->nb_bits_tot_fx = add(st_fx->nb_bits_tot_fx, nb_bits); + st->nb_bits_tot += nb_bits; return; } - /*-------------------------------------------------------------------* - * push_next_bits_fx() + * push_next_bits() * Push a bit buffer into the buffer at the next position *-------------------------------------------------------------------*/ -void push_next_bits_fx( - Encoder_State_fx *st_fx, /* i/o: encoder state structure */ - Word16 bits[], /* i : bit buffer to pack, sequence of single bits */ - Word16 nb_bits /* i : number of bits to pack */ +void push_next_bits( + Encoder_State *st, /* i/o: encoder state structure */ + int bits[], /* i : bit buffer to pack, sequence of single bits */ + short nb_bits /* i : number of bits to pack */ ) { - UWord16 code; - Word16 i, nb_bits_m15; - Indice_fx *ptr; + unsigned short code; + int i, nb_bits_m15; + Indice *ptr; - ptr = &st_fx->ind_list_fx[st_fx->next_ind_fx]; - nb_bits_m15 = sub(nb_bits, 15); - i = 0; - move16(); - IF (nb_bits_m15 > 0) - { - FOR (; iind_list[st->next_ind]; + nb_bits_m15 = nb_bits - 15; - ptr->value = code; - move16(); - ptr->nb_bits = 16; - move16(); - ++ptr; - } - } - IF (sub(i, nb_bits) < 0) + for (i=0; ivalue = bits[i]; - move16(); - ptr->nb_bits = 1; - move16(); - ++ptr; - } + code = (unsigned short)((bits[i] << 15) | ((bits[i+1] << 14) | ((bits[i+2] << 13) | ((bits[i+3] << 12) | + ((bits[i+4] << 11) | ((bits[i+5] << 10) | ((bits[i+6] << 9) | ((bits[i+7] << 8) | + ((bits[i+8] << 7) | ((bits[i+9] << 6) | ((bits[i+10] << 5) | ((bits[i+11] << 4) | + ((bits[i+12] << 3) | ((bits[i+13] << 2) | ((bits[i+14] << 1) | bits[i+15]))))))))))))))); + + ptr->value = code; + ptr->nb_bits = 16; + ++ptr; } - st_fx->next_ind_fx = (Word16)(ptr - st_fx->ind_list_fx); - st_fx->nb_bits_tot_fx = add(st_fx->nb_bits_tot_fx, nb_bits); + for (; ivalue = bits[i]; + ptr->nb_bits = 1; + ++ptr; + } + st->next_ind = (int)(ptr - st->ind_list); + st->nb_bits_tot = st->nb_bits_tot + nb_bits; } /*-------------------------------------------------------------------* - * get_next_indice_fx( ) + * get_next_indice() * * Get the next indice from the buffer *-------------------------------------------------------------------*/ -UWord16 get_next_indice_fx( /* o : value of the indice */ - Decoder_State_fx *st_fx, /* i/o: decoder state structure */ - Word16 nb_bits /* i : number of bits that were used to quantize the indice */ +unsigned short get_next_indice( /* o : value of the indice */ + Decoder_State *st, /* i/o: decoder state structure */ + short nb_bits /* i : number of bits that were used to quantize the indice */ ) { - UWord16 value; - Word16 i; + unsigned short value; + short i; assert(nb_bits <= 16); - value = 0; - move16(); /* detect corrupted bitstream */ - IF( sub(add(st_fx->next_bit_pos_fx,nb_bits),st_fx->total_num_bits) > 0 ) + if( st->next_bit_pos + nb_bits > st->total_brate/50 ) { - st_fx->BER_detect = 1; - move16(); + st->BER_detect = 1; return(0); } - FOR (i = 0; i < nb_bits; i++) + value = 0; + for (i = 0; i < nb_bits; i++) { - value = lshl(value, 1); - value = add(value, st_fx->bit_stream_fx[st_fx->next_bit_pos_fx+i]); + value <<= 1; + value += st->bit_stream[st->next_bit_pos+i]; } /* update the position in the bitstream */ - st_fx->next_bit_pos_fx = add(st_fx->next_bit_pos_fx, nb_bits); + st->next_bit_pos += nb_bits; + return value; } /*-------------------------------------------------------------------* - * get_next_indice_1_fx( ) + * get_next_indice_1() * * Get the next 1-bit indice from the buffer *-------------------------------------------------------------------*/ -UWord16 get_next_indice_1_fx( /* o : value of the indice */ - Decoder_State_fx *st_fx /* i/o: decoder state structure */ +unsigned short get_next_indice_1( /* o : value of the indice */ + Decoder_State *st /* i/o: decoder state structure */ ) { + /* detect corrupted bitstream */ - test(); - test(); - test(); - IF(( sub(add(st_fx->next_bit_pos_fx,1),st_fx->total_num_bits) > 0 && sub(st_fx->codec_mode,MODE1) == 0 ) || - ( sub(add(st_fx->next_bit_pos_fx,1),add(st_fx->total_num_bits,2*8)) > 0 && sub(st_fx->codec_mode,MODE2) == 0 ) /* add two zero bytes for arithmetic coder flush */ - ) + if( + ( st->next_bit_pos + 1 > st->total_brate/50 && st->codec_mode == MODE1 ) || + ( (st->next_bit_pos + 1 > st->total_brate/50 + (2*8) ) && st->codec_mode == MODE2 ) /* add two zero bytes for arithmetic coder flush */ + ) { - st_fx->BER_detect = 1; - move16(); + st->BER_detect = 1; return(0); } - return st_fx->bit_stream_fx[st_fx->next_bit_pos_fx++]; + return st->bit_stream[st->next_bit_pos++]; } /*-------------------------------------------------------------------* @@ -338,165 +322,162 @@ UWord16 get_next_indice_1_fx( /* o : value of the indice */ * update the total number of bits and the position in the bitstream *-------------------------------------------------------------------*/ -void get_next_indice_tmp_fx( - Decoder_State_fx *st_fx, /* o : decoder state structure */ - Word16 nb_bits /* i : number of bits that were used to quantize the indice */ +void get_next_indice_tmp( + Decoder_State *st, /* o : decoder state structure */ + short nb_bits /* i : number of bits that were used to quantize the indice */ ) { /* update the position in the bitstream */ - st_fx->next_bit_pos_fx = add(st_fx->next_bit_pos_fx, nb_bits); + st->next_bit_pos += nb_bits; + } /*-------------------------------------------------------------------* - * get_indice_fx( ) + * get_indice() * * Get indice at specific position in the buffer *-------------------------------------------------------------------*/ -UWord16 get_indice_fx( /* o : value of the indice */ - Decoder_State_fx *st_fx, /* i/o: decoder state structure */ - Word16 pos, /* i : absolute position in the bitstream (update after the read) */ - Word16 nb_bits /* i : number of bits that were used to quantize the indice */ +unsigned short get_indice( /* o : value of the indice */ + Decoder_State *st, /* i/o: decoder state structure */ + short pos, /* i : absolute position in the bitstream (update after the read) */ + short nb_bits /* i : number of bits that were used to quantize the indice */ ) { - UWord16 value; - Word16 i; + unsigned short value; + int i; assert(nb_bits <= 16); /* detect corrupted bitstream */ - IF( sub(add(pos,nb_bits),st_fx->total_num_bits) > 0 ) + if( pos + nb_bits > st->total_brate/50 ) { - st_fx->BER_detect = 1; - move16(); + st->BER_detect = 1; return(0); } value = 0; - move16(); - FOR (i = 0; i < nb_bits; i++) + for (i = 0; i < nb_bits; i++) { - value = lshl(value, 1); - value = add(value, st_fx->bit_stream_fx[pos+i]); + value <<= 1; + value += st->bit_stream[pos+i]; } return value; } /*-------------------------------------------------------------------* - * get_indice_1_fx( ) + * get_indice_1() * * Get a 1-bit indice at specific position in the buffer *-------------------------------------------------------------------*/ -UWord16 get_indice_1_fx( /* o : value of the indice */ - Decoder_State_fx *st_fx, /* i/o: decoder state structure */ - Word16 pos /* i : absolute position in the bitstream (update after the read) */ +unsigned short get_indice_1( /* o : value of the indice */ + Decoder_State *st, /* i/o: decoder state structure */ + short pos /* i : absolute position in the bitstream (update after the read) */ ) { /* detect corrupted bitstream */ - IF( sub(add(pos,1),st_fx->total_num_bits) > 0 ) + if( pos+1 > st->total_brate/50 ) { - st_fx->BER_detect = 1; - move16(); + st->BER_detect = 1; return(0); } - return st_fx->bit_stream_fx[pos]; + return st->bit_stream[pos]; } /*-------------------------------------------------------------------* - * reset_indices_enc_fx() + * reset_indices_enc() * - * Reset the buffer of indices + * Reset the buffer of encoder indices *-------------------------------------------------------------------*/ -void reset_indices_enc_fx( - Encoder_State_fx *st_fx +void reset_indices_enc( + Encoder_State *st ) { - Word16 i; + short i; - st_fx->nb_bits_tot_fx = 0; - move16(); - st_fx->next_ind_fx = 0; - move16(); - st_fx->last_ind_fx = -1; - move16(); + st->nb_bits_tot = 0; + st->next_ind = 0; + st->last_ind = -1; - FOR (i=0; iind_list_fx[i].nb_bits = -1; - move16(); + st->ind_list[i].nb_bits = -1; } return; } /*-------------------------------------------------------------------* - * reset_indices_dec_fx() - * - * Reset the buffer of decoder indices - *-------------------------------------------------------------------*/ + * reset_indices_dec() + * + * Reset the buffer of decoder indices + *-------------------------------------------------------------------*/ -void reset_indices_dec_fx( - Decoder_State_fx *st_fx +void reset_indices_dec( + Decoder_State *st ) { - st_fx->next_bit_pos_fx = 0; - move16(); + st->next_bit_pos = 0; return; } - /*-------------------------------------------------------------------* - * write_indices_fx() - * - * Write the buffer of indices to a file - *-------------------------------------------------------------------*/ +* write_indices() +* +* Write the buffer of indices to a file +*-------------------------------------------------------------------*/ -void write_indices_fx( - Encoder_State_fx *st_fx, /* i/o: encoder state structure */ - FILE *file /* i : output bitstream file */ - , UWord8 *pFrame, /* i: byte array with bit packet and byte aligned coded speech data */ - Word16 pFrame_size /* i: size of the binary encoded access unit [bits] */ +void write_indices( + Encoder_State *st, /* i/o: encoder state structure */ + FILE *file, /* i : output bitstream file */ + UWord8 *pFrame, /* i: byte array with bit packet and byte aligned coded speech data */ + Word16 pFrame_size /* i: size of the binary encoded access unit [bits] */ ) { - Word16 i, k; - Word16 stream[2+MAX_BITS_PER_FRAME], *pt_stream; - Word32 mask; + short i, k; + unsigned short stream[2+MAX_BITS_PER_FRAME], *pt_stream; + int mask; + short value, nb_bits; UWord8 header; - if( st_fx->bitstreamformat == G192 ) + if( st->bitstreamformat == G192 ) { /*-----------------------------------------------------------------* - * Encode Sync Header and Frame Length - *-----------------------------------------------------------------*/ + * Encode Sync Header and Frame Length + *-----------------------------------------------------------------*/ + pt_stream = stream; for (i=0; i<(2 + MAX_BITS_PER_FRAME); ++i) { stream[i] = 0; } - *pt_stream++ = (Word16)SYNC_GOOD_FRAME; - *pt_stream++ = st_fx->nb_bits_tot_fx; + *pt_stream++ = SYNC_GOOD_FRAME; + *pt_stream++ = st->nb_bits_tot; /*----------------------------------------------------------------* - * Bitstream packing (conversion of individual indices into a serial stream) - * Writing the serial stream into file - *----------------------------------------------------------------*/ + * Bitstream packing (conversion of individual indices into a serial stream) + * Writing the serial stream into file + * Clearing of indices + *----------------------------------------------------------------*/ for (i=0; iind_list_fx[i].nb_bits != -1) + value = st->ind_list[i].value; + nb_bits = st->ind_list[i].nb_bits; + if (nb_bits != -1) { /* mask from MSB to LSB */ - mask = 1 << (st_fx->ind_list_fx[i].nb_bits - 1); + mask = 1 << (nb_bits - 1); /* write bit by bit */ - for (k=0; k < st_fx->ind_list_fx[i].nb_bits; k++) + for (k=0; k < nb_bits; k++) { - if ( st_fx->ind_list_fx[i].value & mask ) + if ( value & mask ) { *pt_stream++ = G192_BIN1; } @@ -514,30 +495,29 @@ void write_indices_fx( else { /* Create and write ToC header */ - /* qbit always set to 1 on encoder side for AMRWBIO , no qbit in use for EVS, but set to 0(bad) */ - header = (UWord8)(st_fx->Opt_AMR_WB_fx << 5 | st_fx->Opt_AMR_WB_fx << 4 | rate2EVSmode(st_fx->nb_bits_tot_fx * 50)); + /* qbit always set to 1 on encoder side for AMRWBIO , no qbit in use for EVS, but set to 0(bad) */ + header = (UWord8)(st->Opt_AMR_WB << 5 | st->Opt_AMR_WB << 4 | rate2EVSmode(st->nb_bits_tot * 50)); fwrite( &header, sizeof(UWord8), 1, file ); /* Write speech bits */ fwrite( pFrame, sizeof(UWord8), (pFrame_size + 7)>>3, file ); } - /* Clearing of indices */ - FOR (i=0; iind_list_fx[i].nb_bits = -1; - move16(); + st->ind_list[i].nb_bits = -1; } - - if( st_fx->bitstreamformat == G192 ) + if( st->bitstreamformat == G192 ) { /* write the serial stream into file */ fwrite( stream, sizeof(unsigned short), 2+stream[1], file ); } + + /* reset index pointers */ - st_fx->nb_bits_tot_fx = 0; - st_fx->next_ind_fx = 0; - st_fx->last_ind_fx = -1; + st->nb_bits_tot = 0; + st->next_ind = 0; + st->last_ind = -1; return; } @@ -549,42 +529,42 @@ void write_indices_fx( *-------------------------------------------------------------------*/ void indices_to_serial( - const Encoder_State_fx *st_fx, /* i: encoder state structure */ - UWord8 *pFrame, /* o: byte array with bit packet and byte aligned coded speech data */ + const Encoder_State *st, /* i: encoder state structure */ + UWord8 *pFrame, /* o: byte array with bit packet and byte aligned coded speech data */ Word16 *pFrame_size /* o: size of the binary encoded access unit [bits] */ ) { Word16 i, k, j; Word16 cmi = 0, core_mode=0; - Word32 mask; + Word32 mask; Word16 amrwb_bits[(ACELP_23k85 / 50)]; UWord8 omask= 0x80; UWord8 *pt_pFrame=pFrame; - if ( st_fx->Opt_AMR_WB_fx ) + if ( st->Opt_AMR_WB ) { - cmi = rate2EVSmode(st_fx->total_brate_fx); - core_mode = rate2EVSmode(st_fx->nb_bits_tot_fx * 50); + cmi = rate2EVSmode(st->total_brate); + core_mode = rate2EVSmode(st->nb_bits_tot * 50); j=0; for (i=0; iind_list_fx[i].nb_bits != -1) + if (st->ind_list[i].nb_bits != -1) { /* mask from MSB to LSB */ - mask = 1 << (st_fx->ind_list_fx[i].nb_bits - 1); + mask = 1 << (st->ind_list[i].nb_bits - 1); /* temporarily save bit */ - for (k=0; k < st_fx->ind_list_fx[i].nb_bits; k++) + for (k=0; k < st->ind_list[i].nb_bits; k++) { - amrwb_bits[j++] = (st_fx->ind_list_fx[i].value & mask) > 0; + amrwb_bits[j++] = (st->ind_list[i].value & mask) > 0; mask >>= 1; } } } } - *pFrame_size = st_fx->nb_bits_tot_fx; + *pFrame_size = st->nb_bits_tot; /*----------------------------------------------------------------* * Bitstream packing (conversion of individual indices into a serial stream) @@ -592,21 +572,21 @@ void indices_to_serial( j=0; for (i=0; iind_list_fx[i].nb_bits != -1) + if (st->ind_list[i].nb_bits != -1) { /* mask from MSB to LSB */ - mask = 1 << (st_fx->ind_list_fx[i].nb_bits - 1); + mask = 1 << (st->ind_list[i].nb_bits - 1); /* write bit by bit */ - for (k=0; k < st_fx->ind_list_fx[i].nb_bits; k++) + for (k=0; k < st->ind_list[i].nb_bits; k++) { - if (st_fx->Opt_AMR_WB_fx ) + if (st->Opt_AMR_WB ) { pack_bit(amrwb_bits[sort_ptr[core_mode][j++]], &pt_pFrame, &omask); } else { - pack_bit(st_fx->ind_list_fx[i].value & mask, &pt_pFrame, &omask); + pack_bit(st->ind_list[i].value & mask, &pt_pFrame, &omask); j++; } mask >>= 1; @@ -614,7 +594,7 @@ void indices_to_serial( } } - if ( st_fx->Opt_AMR_WB_fx && core_mode == AMRWB_IO_SID) /* SID UPD frame always written now .... */ + if ( st->Opt_AMR_WB && core_mode == AMRWB_IO_SID) /* SID frame */ { /* insert STI bit and CMI */ pack_bit(1, &pt_pFrame, &omask); @@ -623,8 +603,9 @@ void indices_to_serial( pack_bit(cmi & mask, &pt_pFrame, &omask); } } -} + return; +} /*-------------------------------------------------------------------* * indices_to_serial_generic() @@ -633,7 +614,7 @@ void indices_to_serial( *-------------------------------------------------------------------*/ void indices_to_serial_generic( - const Indice_fx *ind_list, /* i: indices list */ + const Indice *ind_list, /* i: indices list */ const Word16 num_indices, /* i: number of indices to write */ UWord8 *pFrame, /* o: byte array with bit packet and byte aligned coded speech data */ Word16 *pFrame_size /* i/o: number of bits in the binary encoded access unit [bits] */ @@ -643,18 +624,15 @@ void indices_to_serial_generic( Word32 mask; UWord8 omask; UWord8 *pt_pFrame = pFrame; - Word16 nb_bits_tot; + Word16 nb_bits_tot = 0; - nb_bits_tot = 0; - move16(); omask = (0x80 >> (*pFrame_size & 0x7)); - pt_pFrame += shr(*pFrame_size, 3); + pt_pFrame += *pFrame_size >> 3; /*----------------------------------------------------------------* - * Bitstream packing (conversion of individual indices into a serial stream) - *----------------------------------------------------------------*/ + * Bitstream packing (conversion of individual indices into a serial stream) + *----------------------------------------------------------------*/ j=0; - move16(); for (i=0; i>= 1; } - nb_bits_tot = add(nb_bits_tot, ind_list[i].nb_bits); + nb_bits_tot += ind_list[i].nb_bits; } } - *pFrame_size = add(*pFrame_size, nb_bits_tot); + *pFrame_size += nb_bits_tot; return; } +/*-------------------------------------------------------------------* + * decoder_selectCodec() + * + * + *-------------------------------------------------------------------*/ static void decoder_selectCodec( - Decoder_State_fx *st, /* i/o: decoder state structure */ - const Word32 total_brate, /* i : total bitrate */ - const Word16 bit0 + Decoder_State *st, /* i/o: decoder state structure */ + const long total_brate, /* i : total bitrate */ + const short bit0 /* i : first bit */ ) { - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - /* check if we are in AMR-WB IO mode */ - IF( L_sub(total_brate, SID_1k75) == 0 || - L_sub(total_brate, ACELP_6k60) == 0 || L_sub(total_brate, ACELP_8k85) == 0 || L_sub(total_brate, ACELP_12k65) == 0 || - L_sub(total_brate, ACELP_14k25) == 0 || L_sub(total_brate, ACELP_15k85) == 0 || L_sub(total_brate, ACELP_18k25) == 0 || - L_sub(total_brate, ACELP_19k85) == 0 || L_sub(total_brate, ACELP_23k05) == 0 || L_sub(total_brate, ACELP_23k85) == 0 ) + /* set the AMR-WB IO flag */ + if( total_brate == SID_1k75 || + total_brate == ACELP_6k60 || total_brate == ACELP_8k85 || total_brate == ACELP_12k65 || + total_brate == ACELP_14k25 || total_brate == ACELP_15k85 || total_brate == ACELP_18k25 || + total_brate == ACELP_19k85 || total_brate == ACELP_23k05 || total_brate == ACELP_23k85 ) { - st->Opt_AMR_WB_fx = 1; - move16(); + st->Opt_AMR_WB = 1; } - ELSE IF ( L_sub(total_brate, FRAME_NO_DATA) != 0 ) + else if ( total_brate != FRAME__NO_DATA ) { - st->Opt_AMR_WB_fx = 0; - move16(); + st->Opt_AMR_WB = 0; } - /* select MODE1 or MODE2 */ - IF (st->Opt_AMR_WB_fx) + if ( st->Opt_AMR_WB ) { st->codec_mode = MODE1; - move16();/**/ } - ELSE + else { - SWITCH ( total_brate ) + switch ( total_brate ) { case 0: st->codec_mode = st->last_codec_mode; - move16(); - BREAK; + break; case 2400: st->codec_mode = st->last_codec_mode; - move16(); - BREAK; + break; case 2800: st->codec_mode = MODE1; - move16(); - BREAK; + break; case 7200: st->codec_mode = MODE1; - move16(); - BREAK; + break; case 8000: st->codec_mode = MODE1; - move16(); - BREAK; + break; case 9600: st->codec_mode = MODE2; - move16(); - BREAK; + break; case 13200: st->codec_mode = MODE1; - move16(); - BREAK; + break; case 16400: st->codec_mode = MODE2; - move16(); - BREAK; + break; case 24400: st->codec_mode = MODE2; - move16(); - BREAK; + break; case 32000: st->codec_mode = MODE1; - move16(); - BREAK; + break; case 48000: st->codec_mode = MODE2; - move16(); - BREAK; + break; case 64000: st->codec_mode = MODE1; - move16(); - BREAK; + break; case 96000: st->codec_mode = MODE2; - move16(); - BREAK; + break; case 128000: st->codec_mode = MODE2; - move16(); - BREAK; - default : - /* validate that total_brate (derived from RTP packet or a file header) is one of the defined bit rates */ + break; + default : /* validate that total_brate (derived from RTP packet or a file header) is one of the defined bit rates */ st->codec_mode = st->last_codec_mode; - st->bfi_fx = 1; - move16(); - move16(); - BREAK; + st->bfi = 1; + break; } } - IF ( st->ini_frame_fx == 0 ) + if( st->ini_frame == 0 ) { - IF(sub(st->codec_mode,-1) == 0 ) + if( st->codec_mode == -1 ) { st->codec_mode = MODE1; - move16(); } st->last_codec_mode = st->codec_mode; - move16(); } /* set SID/CNG type */ - IF ( L_sub(total_brate,SID_2k40) == 0 ) + if( total_brate == SID_2k40 ) { - IF ( bit0 == G192_BIN0 ) + if( bit0 == G192_BIN0 ) { - st->cng_type_fx = LP_CNG; - move16(); + st->cng_type = LP_CNG; /* force MODE1 when selecting LP_CNG */ st->codec_mode = MODE1; - move16(); } - ELSE + else { - st->cng_type_fx = FD_CNG; - test(); - if ( sub(st->last_codec_mode, MODE2) == 0 && L_sub(st->last_total_brate_fx,13200) == 0 ) + st->cng_type = FD_CNG; + if ( st->last_codec_mode == MODE2 && st->last_total_brate == ACELP_13k20 ) { st->codec_mode = MODE1; - move16(); } } - st->last_cng_type_fx = st->cng_type_fx; /* CNG type switching at the first correctly received SID frame */ + st->last_cng_type = st->cng_type; /* CNG type switching at the first correctly received SID frame */ } return; } +/*-------------------------------------------------------------------* + * dec_prm_core() + * + * + *-------------------------------------------------------------------*/ - - -void dec_prm_core(Decoder_State_fx *st) +void dec_prm_core( + Decoder_State *st +) { - Word16 n, frame_size_index, num_bits; - UWord16 lsb; - Word32 L_tmp; + int n, frame_size_index = -1; - frame_size_index = -1; - move16(); - st->core_fx = -1; - move16(); + st->core = -1; - IF (L_sub(st->total_brate_fx, FRAME_NO_DATA) == 0) + if (st->total_brate == FRAME__NO_DATA) { st->m_frame_type = ZERO_FRAME; - move16(); } - ELSE IF (L_sub(st->total_brate_fx, SID_2k40) == 0) + else if (st->total_brate == SID_2k40) { st->m_frame_type = SID_FRAME; - move16(); } - ELSE + else { st->m_frame_type = ACTIVE_FRAME; - move16(); - Mpy_32_16_ss(st->total_brate_fx, 5243, &L_tmp, &lsb); /* 5243 is 1/50 in Q18. (0+18-15=3) */ - num_bits = extract_l(L_shr(L_tmp, 3)); /* Q0 */ - assert(num_bits == st->total_brate_fx/50); - FOR (n=0; ntotal_brate/50) { - frame_size_index = n; - move16(); - BREAK; + frame_size_index = n; + break; } } /* Get bandwidth mode */ - st->bwidth_fx = get_next_indice_fx(st, FrameSizeConfig[frame_size_index].bandwidth_bits); - - st->bwidth_fx = add(st->bwidth_fx, FrameSizeConfig[frame_size_index].bandwidth_min); - - if (sub(st->bwidth_fx, FB) > 0) + st->bwidth = get_next_indice(st, FrameSizeConfig[frame_size_index].bandwidth_bits); + st->bwidth += FrameSizeConfig[frame_size_index].bandwidth_min; + if (st->bwidth > FB) { - st->bwidth_fx = FB; - move16(); + st->bwidth = FB; st->BER_detect = 1; - move16(); } - if (sub(st->bwidth_fx, SWB) > 0 && L_sub(st->total_brate_fx, ACELP_16k40) < 0) + if (st->bwidth > SWB && st->total_brate < ACELP_16k40) { - st->bwidth_fx = SWB; - move16(); + st->bwidth = SWB; st->BER_detect = 1; - move16(); } - /* Skip reserved bit */ - get_next_indice_tmp_fx(st, FrameSizeConfig[frame_size_index].reserved_bits); + get_next_indice_tmp(st, FrameSizeConfig[frame_size_index].reserved_bits); - IF (get_next_indice_1_fx(st) != 0) /* TCX */ + if (get_next_indice_1(st)) /* TCX */ { - st->core_fx = TCX_20_CORE; - move16(); - if (get_next_indice_1_fx(st) != 0) + if (get_next_indice_1(st)) { - st->core_fx = HQ_CORE; - move16(); + st->core = HQ_CORE; + } + else + { + st->core = TCX_20_CORE; } } - ELSE /* ACELP */ + else /* ACELP */ { - st->core_fx = ACELP_CORE; - move16(); + st->core = ACELP_CORE; } } + + return; } /*-----------------------------------------------------------------* @@ -915,32 +850,27 @@ void dec_prm_core(Decoder_State_fx *st) * Set st->core, and st->bwidth if signalled together with the core. *-----------------------------------------------------------------*/ -void decision_matrix_core_dec( - Decoder_State_fx *st /* i/o: decoder state structure */ +static void decision_matrix_core_dec( + Decoder_State *st /* i/o: decoder state structure */ ) { - Word16 start_idx; - Word32 ind; - Word16 nBits; + short start_idx; + long ind; + short nBits; - assert(st->bfi_fx != 1); + assert(st->bfi != 1); - st->core_fx = -1; - move16(); - st->bwidth_fx = -1; - move16(); + st->core = -1; + st->bwidth = -1; - test(); - IF ( L_sub(st->total_brate_fx, FRAME_NO_DATA) == 0 || L_sub(st->total_brate_fx, SID_2k40) == 0 ) + if ( st->total_brate == FRAME__NO_DATA || st->total_brate == SID_2k40 ) { - st->core_fx = ACELP_CORE; - move16(); + st->core = ACELP_CORE; } /* SC-VBR */ - ELSE IF ( st->total_brate_fx == PPP_NELP_2k80 ) + else if ( st->total_brate == PPP_NELP_2k80 ) { - st->core_fx = ACELP_CORE; - move16(); + st->core = ACELP_CORE; return; } @@ -948,53 +878,47 @@ void decision_matrix_core_dec( * ACELP/HQ core selection *---------------------------------------------------------------------*/ - test(); - IF ( L_sub(st->total_brate_fx, ACELP_24k40) < 0 ) + if ( st->total_brate < ACELP_24k40 ) { - st->core_fx = ACELP_CORE; - move16(); + st->core = ACELP_CORE; } - ELSE IF ( L_sub(st->total_brate_fx, ACELP_24k40) >= 0 && L_sub(st->total_brate_fx, ACELP_64k) <= 0 ) + else if ( st->total_brate >= ACELP_24k40 && st->total_brate <= ACELP_64k ) { /* read the ACELP/HQ core selection bit */ - st->core_fx = imult1616(get_next_indice_fx( st, 1 ), HQ_CORE); + st->core = ((short) get_next_indice( st, 1 ))*HQ_CORE; } - ELSE + else { - st->core_fx = HQ_CORE; - move16(); + st->core = HQ_CORE; } /*-----------------------------------------------------------------* * Read ACELP signalling bits from the bitstream *-----------------------------------------------------------------*/ - IF ( sub(st->core_fx, ACELP_CORE) == 0 ) + if ( st->core == ACELP_CORE ) { /* find the section in the ACELP signalling table corresponding to bitrate */ start_idx = 0; - move16(); - WHILE ( L_sub(acelp_sig_tbl[start_idx], st->total_brate_fx) != 0 ) + while ( acelp_sig_tbl[start_idx] != st->total_brate ) { - start_idx = add(start_idx, 1); + start_idx++; } /* skip the bitrate */ - start_idx = add(start_idx, 1); + start_idx += 1; /* retrieve the number of bits */ - nBits = extract_l(acelp_sig_tbl[start_idx]); - start_idx = add(start_idx, 1); + nBits = (short) acelp_sig_tbl[start_idx++]; /* retrieve the signalling indice */ - ind = acelp_sig_tbl[add(start_idx, get_next_indice_fx( st, nBits ))]; - st->bwidth_fx = extract_l(L_and(L_shr(ind, 3), 0x7)); + ind = acelp_sig_tbl[start_idx + get_next_indice( st, nBits )]; + st->bwidth = (ind >> 3) & 0x7; /* convert signalling indice into signalling information */ - if ( L_sub(L_and(ind, 0x7), LR_MDCT) == 0 ) + if ( (ind & 0x7) == LR_MDCT ) { - st->core_fx = HQ_CORE; - move16(); + st->core = HQ_CORE; } } @@ -1003,40 +927,34 @@ void decision_matrix_core_dec( * Set HQ core type *-----------------------------------------------------------------*/ - IF ( sub(st->core_fx, HQ_CORE) == 0 ) + if ( st->core == HQ_CORE ) { /* read the HQ/TCX core switching flag */ - if ( get_next_indice_fx( st, 1 ) != 0 ) + if ( get_next_indice( st, 1 ) ) { - st->core_fx = TCX_20_CORE; - move16(); + st->core = TCX_20_CORE; } /* For TCX: read/set band-width (needed for different I/O sampling rate support) */ - test(); - IF( sub(st->core_fx, TCX_20_CORE) == 0 && L_sub(st->total_brate_fx, ACELP_16k40) > 0 ) + if( st->core == TCX_20_CORE && st->total_brate > ACELP_16k40 ) { - ind = get_next_indice_fx( st, 2 ); + ind = get_next_indice( st, 2 ); - IF( ind == 0 ) + if( ind == 0 ) { - st->bwidth_fx = NB; - move16(); + st->bwidth = NB; } - ELSE IF( L_sub(ind, 1) == 0 ) + else if( ind == 1 ) { - st->bwidth_fx = WB; - move16(); + st->bwidth = WB; } - ELSE IF( L_sub(ind, 2) == 0 ) + else if( ind == 2 ) { - st->bwidth_fx = SWB; - move16(); + st->bwidth = SWB; } - ELSE + else { - st->bwidth_fx = FB; - move16(); + st->bwidth = FB; } } } @@ -1051,351 +969,224 @@ void decision_matrix_core_dec( *-------------------------------------------------------------------*/ static void mdct_switching_dec( - Decoder_State_fx *st /* i/o: decoder state structure */ + Decoder_State *st /* i/o: decoder state structure */ ) { - IF (st->Opt_AMR_WB_fx != 0) + if (st->Opt_AMR_WB) { return; } - test(); - test(); - IF (L_sub(st->total_brate_fx, ACELP_13k20) == 0 || L_sub(st->total_brate_fx, ACELP_32k) == 0) + if (st->total_brate == ACELP_13k20 || st->total_brate == ACELP_32k) { st->mdct_sw_enable = MODE1; - move16(); } - ELSE IF (L_sub(ACELP_16k40, st->total_brate_fx) <= 0 && L_sub(st->total_brate_fx, ACELP_24k40) <= 0) + else if (ACELP_16k40 <= st->total_brate && st->total_brate <= ACELP_24k40) { st->mdct_sw_enable = MODE2; - move16(); } - test(); - test(); - IF ( sub(st->codec_mode, MODE1) == 0 && sub(st->mdct_sw_enable, MODE1) == 0 ) + if ( st->codec_mode == MODE1 && st->mdct_sw_enable == MODE1 ) { /* Read ahead core mode signaling */ - Word16 next_bit_pos_save; - Word16 core_save; - Word16 bwidth_save; - - next_bit_pos_save = st->next_bit_pos_fx; - move16(); - core_save = st->core_fx; - move16(); - bwidth_save = st->bwidth_fx; - move16(); + short next_bit_pos_save = st->next_bit_pos; + short core_save = st->core; + short bwidth_save = st->bwidth; decision_matrix_core_dec(st); /* sets st->core */ - IF (sub(st->core_fx, TCX_20_CORE) == 0) + if (st->core == TCX_20_CORE) { /* Trigger TCX */ st->codec_mode = MODE2; - move16(); st->mdct_sw = MODE1; - move16(); } - ELSE + else { /* Rewind bitstream */ - st->next_bit_pos_fx = next_bit_pos_save; - move16(); - IF (st->bfi_fx != 0) + st->next_bit_pos = next_bit_pos_save; + if (st->bfi) { - st->core_fx = core_save; - move16(); - st->bwidth_fx = bwidth_save; - move16(); + st->core = core_save; + st->bwidth = bwidth_save; } } } - ELSE IF (sub(st->codec_mode, MODE2) == 0 && sub(st->mdct_sw_enable, MODE2) == 0) + else if (st->codec_mode == MODE2 && st->mdct_sw_enable == MODE2) { /* Read ahead core mode signaling */ - Word16 next_bit_pos_save; - Word16 core_save; - Word16 bwidth_save; - - next_bit_pos_save = st->next_bit_pos_fx; - move16(); - core_save = st->core_fx; - move16(); - bwidth_save = st->bwidth_fx; - move16(); + short next_bit_pos_save = st->next_bit_pos; + short core_save = st->core; + short bwidth_save = st->bwidth; dec_prm_core(st); /* sets st->core */ - IF (sub(st->core_fx, HQ_CORE) == 0) + if (st->core == HQ_CORE) { /* Trigger HQ_CORE */ st->codec_mode = MODE1; - move16(); st->mdct_sw = MODE2; - move16(); } - ELSE + else { /* Rewind bitstream */ - st->next_bit_pos_fx = next_bit_pos_save; - move16(); - IF (st->bfi_fx != 0) + st->next_bit_pos = next_bit_pos_save; + if (st->bfi) { - st->core_fx = core_save; - move16(); + st->core = core_save; } + /* always reset bwidth, to not interfere with BER logic */ - st->bwidth_fx = bwidth_save; - move16(); + st->bwidth = bwidth_save; } } -} -/*-------------------------------------------------------------------* - * BRATE2IDX_fx() - * - * Convert Bitrate to Index Value - *-------------------------------------------------------------------*/ - -Word16 BRATE2IDX_fx(Word32 brate) -{ - Word32 L_temp; - Word32 L_idx; -#define START 9 - extern const Word16 bit_rates_div50[]; - - /* This is a Fast Bit Rate Value to Index Value Binary Search */ - L_temp = L_msu0(brate, bit_rates_div50[START], 50); - L_temp = L_min(6, L_max(-6, L_temp)); - L_idx = L_add(L_temp, START); - L_temp = L_msu0(brate, bit_rates_div50[L_idx], 50); - L_temp = L_min(3, L_max(-3, L_temp)); - L_idx = L_add(L_temp, L_idx); - L_temp = L_msu0(brate, bit_rates_div50[L_idx], 50); - L_temp = L_min(1, L_max(-2, L_temp)); - L_idx = L_add(L_temp, L_idx); - L_temp = L_msu0(brate, bit_rates_div50[L_idx], 50); - if (L_temp != 0) L_idx = L_add(L_idx, 1); - return (Word16)L_idx; + return; } -/*-------------------------------------------------------------------* - * BRATE2IDX16k_fx() - * - * Convert Bitrate to Index Value - *-------------------------------------------------------------------*/ - -Word16 BRATE2IDX16k_fx(Word32 brate) -{ - Word32 L_temp, L_idx; -#define START_16K 5 - extern const Word16 bit_rates_16k_div50[]; - - if(L_sub(brate,ACELP_16k40)==0) - { - brate=ACELP_14k80; - } - - /* This is a Fast Bit Rate Value to Index Value Binary Search */ - L_temp = L_msu0(brate, bit_rates_16k_div50[START_16K], 50); - L_temp = L_min(3, L_max(-3, L_temp)); - L_idx = L_add(L_temp, START_16K); - L_temp = L_msu0(brate, bit_rates_16k_div50[L_idx], 50); - L_temp = L_min(2, L_max(-2, L_temp)); - L_idx = L_add(L_temp, L_idx); - L_temp = L_msu0(brate, bit_rates_16k_div50[L_idx], 50); - L_temp = L_min(1, L_max(-1, L_temp)); - L_idx = L_add(L_temp, L_idx); - - return (Word16)L_idx; -} /*-------------------------------------------------------------------* - * BIT_ALLOC_IDX_fx() - *-------------------------------------------------------------------*/ - -Word32 BIT_ALLOC_IDX_fx(Word32 brate, Word16 ctype, Word16 sfrm, Word16 tc) -{ - Word32 L_temp; - Word16 temp; - if (ctype == INACTIVE) /* no sub(ctype, INACTIVE) because it is '0' */ - ctype = GENERIC; - move16(); - L_temp = L_mac0(-1l*256, 1*256, ctype); - - temp = BRATE2IDX_fx(brate); - L_temp = L_mac0(L_temp, 4*256, temp); - if (tc >= 0) - L_temp = L_mac0(L_temp, (10-4)*256, temp); - /* So either 'temp' x 4 when 'tc < 0', 'temp' x 10 otherwise */ - - L_temp = L_mac0(L_temp, 1*256, s_max(0, tc)); - - L_temp = L_mac0(L_temp, s_max(0, sfrm), 1); - if (sfrm < 0) - L_temp = L_shr(L_temp, 2); - L_temp = L_shr(L_temp, 6); - - return L_temp; -} - -/*-------------------------------------------------------------------* - * BIT_ALLOC_IDX_16KHZ_fx() - *-------------------------------------------------------------------*/ - -Word32 BIT_ALLOC_IDX_16KHZ_fx(Word32 brate, Word16 ctype, Word16 sfrm, Word16 tc) -{ - Word32 L_temp; - Word16 temp; - /* 'ctype' = - TRANSITION => 2 - GENERIC => 1 - ALL Other => 0 - */ - L_temp = L_and(shr(0x0240l, shl(ctype, 1)), 3); - - temp = BRATE2IDX16k_fx(brate); - L_temp = L_mac0(L_temp, 3, temp); - if (tc >= 0) - L_temp = L_mac0(L_temp, (7-3), temp); - /* So either 'temp' x 3 when 'tc < 0', 'temp' x 7 otherwise */ - - L_temp = L_mac0(L_temp, 1, s_max(0, tc)); - - IF (sfrm >= 0) - { - /* Mult by 5 */ - L_temp = L_add(L_temp, L_shl(L_temp, 2)); - L_temp = L_mac0(L_temp, shr(sfrm, 6), 1); - } - - return L_temp; -} - - -/*-------------------------------------------------------------------* - * read_indices_fx() + * read_indices() * * Read indices from an ITU-T G.192 bitstream to the buffer * Simulate packet losses by inserting frame erasures *-------------------------------------------------------------------*/ -Word16 read_indices_fx( /* o : 1 = reading OK, 0 = problem */ - Decoder_State_fx *st, /* i/o: decoder state structure */ - FILE *file, /* i : bitstream file */ - Word16 rew_flag /* i : rewind flag (rewind file after reading)*/ +short read_indices( /* o : 1 = reading OK, 0 = problem */ + Decoder_State *st, /* i/o: decoder state structure */ + const char* data, /* i : bitstream file */ + size_t data_size, + size_t* data_processed, + const short rew_flag /* i : rewind flag (rewind file after reading)*/ ) { - Word16 k; - UWord16 utmp, stream[2+MAX_BITS_PER_FRAME], *pt_stream, *bit_stream_ptr; - Word16 num_bits; - Word32 total_brate; - Word32 L_tmp; - Word16 curr_ft_good_sp, curr_ft_bad_sp; - Word16 g192_sid_first,sid_upd_bad, sid_update; - Word16 speech_bad, speech_lost; - Word16 num_bits_read; + short k; + unsigned short utmp, stream[2+MAX_BITS_PER_FRAME], *pt_stream; + unsigned short *bit_stream_ptr; + unsigned short num_bits; + long total_brate; + short curr_ft_good_sp, curr_ft_bad_sp; + short g192_sid_first,sid_upd_bad, sid_update; + short speech_bad, speech_lost; + unsigned short num_bits_read; - st->bfi_fx = 0; + st->bfi = 0; st->BER_detect = 0; st->mdct_sw_enable = 0; st->mdct_sw = 0; - reset_indices_dec_fx( st ); + reset_indices_dec( st ); + +#define INCREASE_DATA_OFFSET(X) (*data_processed = *data_processed + X) /* read the Sync Header field from the bitstream */ /* in case rew_flag is set, read until first good frame is encountered */ do { /* read the Sync header */ - if ( fread( &utmp, sizeof(unsigned short), 1, file ) != 1 ) + if (*data_processed + 2 > data_size) + return 0; + utmp = *(const unsigned short*)data; INCREASE_DATA_OFFSET(2); + + /*if ( fread( &utmp, sizeof(unsigned short), 1, file ) != 1 ) { if( ferror( file ) ) { - /* error during reading */ + // error during reading fprintf(stderr, "\nError reading the bitstream !"); exit(-1); } else { - /* end of file reached */ + // end of file reached return 0; } - } + }*/ /* set the BFI indicator according the value of Sync Header */ - if ( sub(utmp, SYNC_BAD_FRAME) == 0 ) + if ( utmp == SYNC_BAD_FRAME ) { - st->bfi_fx = 1; + st->bfi = 1; } + else { - st->bfi_fx = 0; + st->bfi = 0; } /* read the Frame Length field from the bitstream */ - if ( fread( &num_bits, sizeof(unsigned short), 1, file ) != 1 ) + if (*data_processed + 2 > data_size) + return 0; + num_bits = *(const unsigned short*)(data + *data_processed); INCREASE_DATA_OFFSET(2); + + /*if ( fread( &num_bits, sizeof(unsigned short), 1, file ) != 1 ) { if( ferror( file ) ) { - /* error during reading */ + // error during reading fprintf(stderr, "\nError reading the bitstream !"); exit(-1); } else { - /* end of file reached */ + // end of file reached return 0; } - } + } */ + /* convert the frame length to total bitrate */ - total_brate = (long)(num_bits* 50); + total_brate = (long)(num_bits * 50); /* read ITU-T G.192 serial stream of indices from file to the local buffer */ /* Validate that the G.192 length is within the defined bit rate range to not allow writing past the end of the "stream" buffer */ if( num_bits > MAX_BITS_PER_FRAME ) + return 0; + /* { fprintf(stderr, "\nError, too large G.192 frame (size(%d))! Exiting ! \n", num_bits); exit(-1); - } + }*/ /* verify that a valid num bits value is present in the G.192 file */ /* only AMRWB or EVS bit rates or 0(NO DATA) are allowed in G.192 file frame reading */ if( rate2EVSmode(total_brate) < 0 ) /* negative value means that a valid rate was not found */ + return 0; + /* { - fprintf(stderr, "\nError, illegal bit rate (%d) in the G.192 frame ! Exiting ! \n", total_brate); + fprintf(stderr, "\nError, illegal bit rate (%ld) in the G.192 frame ! Exiting ! \n", total_brate); exit(-1); - } + }*/ pt_stream = stream; - num_bits_read = (Word16) fread( pt_stream, sizeof(unsigned short), num_bits, file ); + if (*data_processed + num_bits * sizeof(short) > data_size) + return 0; + memmove(pt_stream, data + *data_processed, num_bits * sizeof(short)); INCREASE_DATA_OFFSET(num_bits * sizeof(short)); + num_bits_read = num_bits; + /*num_bits_read = (unsigned short) fread( pt_stream, sizeof(unsigned short), num_bits, file ); if( num_bits_read != num_bits ) { fprintf(stderr, "\nError, invalid number of bits read ! Exiting ! \n"); exit(-1); - } + }*/ } - while ( rew_flag && (st->bfi_fx || L_sub(total_brate,2800) < 0) ); + while ( rew_flag && (st->bfi || total_brate < 2800) ); /* G.192 RX DTX handler*/ if( !rew_flag ) { - /* handle SID_FIRST, SID_BAD, SPEECH_LOST, NO_DATA as properly as possible for the ITU-T G.192 format */ - + /* handle SID_FIRST, SID_BAD, SPEECH_LOST, _NO_DATA as properly as possible for the ITU-T G.192 format */ /* (total_brate, bfi , st_CNG) = rx_handler(received frame type, [previous frame type], past CNG state, past core) */ curr_ft_good_sp = 0; curr_ft_bad_sp = 0; if( total_brate > SID_2k40 ) { - if( st->bfi_fx == 0 ) + if( st->bfi == 0 ) { curr_ft_good_sp = 1; } @@ -1404,141 +1195,137 @@ Word16 read_indices_fx( /* o : 1 = reading OK, 0 = problem curr_ft_bad_sp = 1; } } + sid_update = 0; sid_upd_bad = 0; - if( total_brate == SID_1k75 || total_brate == SID_2k40 ) { - if( st->bfi_fx == 0 ) + if( st->bfi == 0 ) { sid_update = 1; } else { - sid_upd_bad = 1; /* may happen in CS , corrupt but detected sid frame */ + sid_upd_bad = 1; /* this frame type may happen in ETSI/3GPP CS cases , a corrupt sid frames */ } } - /* AMRWB 26.173 G.192 file reader (read_serial) does not declare/use SID_BAD ft, - it declares every bad synch marked frame initially as a lost_speech frame, + /* AMRWB 26.173 G.192 file reader (read_serial) does not declare/use SID_BAD ft, + it declares every bad synch marked frame initially as a lost_speech frame, and then the RXDTX handler CNG state decides the decoding mode CNG/SPEECH. - While In the AMRWB ETSI/3GPP format eid a CRC error in a detected SID_UPDATE frame triggers SID_UPD_BAD. + While In the AMRWB ETSI/3GPP format eid a CRC error in a detected SID_UPDATE frames triggers SID_BAD. - Here we inhibit use of the SID-length info, even though it is available in the G.192 file format after STL/EID-XOR . + Here we inhibit use of the SID-length info, even though it is available in the G.192 file format after STL/EID-XOR . */ if ( sid_upd_bad ) { sid_upd_bad = 0; - total_brate = FRAME_NO_DATA ; /* treat SID_BAD as a stolen signaling frame --> SPEECH LOST */ + total_brate = FRAME__NO_DATA ; /* treat SID_BAD as a stolen signaling frame --> SPEECH LOST */ } g192_sid_first = 0; - if( st->core_fx == AMR_WB_CORE && st->prev_ft_speech_fx && total_brate == FRAME_NO_DATA && st->bfi_fx == 0 ) + if( st->core == AMR_WB_CORE && st->prev_ft_speech && total_brate == FRAME__NO_DATA && st->bfi == 0 ) { g192_sid_first = 1; /* SID_FIRST detected for previous AMRWB/AMRWBIO active frames only */ /* It is not possible to perfectly simulate rate switching conditions EVS->AMRWBIO where: the very first SID_FIRST detection is based on a past EVS active frame - and a good length 0 "SID_FIRST"(NO_DATA) frame is sent in AMRWBIO, + and a good length 0 "SID_FIRST"(_NO_DATA) frame is sent in AMRWBIO, , due to the one frame state memory in the AMRWB legacy G.192 SID_FIRST encoding */ } speech_bad = 0; - if( total_brate > SID_2k40 && st->bfi_fx != 0 ) /* CS-type of CRC failure frame */ + if( total_brate > SID_2k40 && st->bfi != 0 ) /* CS-type of CRC failure frame */ { - speech_bad = 1; /* initial assumption, CNG_state decides what to do */ + speech_bad = 1; /* initial ft assumption, CNG_state decides what to do */ } speech_lost = 0; - if( total_brate == 0 && st->bfi_fx != 0 ) /* unsent NO_DATA or stolen NO_DATA/signaling frame */ + if( total_brate == 0 && st->bfi != 0 ) /* unsent _NO_DATA or stolen _NO_DATA/signaling frame */ { - speech_lost = 1; /* initial assumption, CNG_state decides what to do */ + speech_lost = 1; /* initial ft assumption, CNG_state decides what to do */ } /* Do not allow decoder to enter CNG-synthesis for any instantly received GOOD+LENGTH==0 frame as this frame was never transmitted, one can not know it is good and has a a length of zero ) */ - if( st->CNG_fx != 0 ) + if( st->CNG != 0 ) { /* We were in CNG synthesis */ if( curr_ft_good_sp != 0 ) { /* only a good speech frame makes you leave CNG synthesis */ - st->CNG_fx = 0; + st->CNG = 0; } } else { /* We were in SPEECH synthesis */ - /* only a received SID frame can make the decoder enter into CNG synthsis */ + /* only a received/detected SID frame can make the decoder enter into CNG synthsis */ if( g192_sid_first || sid_update || sid_upd_bad ) { - st->CNG_fx = 1; + st->CNG = 1; } } - /* handle the g.192 _simulated_ untransmitted frame, setting for decoder SPEECH synthesis */ - if ( (st->CNG_fx==0) && (total_brate==0 && st->bfi_fx == 0 ) ) + /* set bfi, total_brate pair for proper decoding */ + /* handle the G.192 _simulated_ untransmitted _NO_DATA frame, setting for decoder SPEECH synthesis */ + if ( (st->CNG==0) && (total_brate==0 && st->bfi == 0 ) ) { - st->bfi_fx = 1; - move16(); /* SPEECH PLC code will now become active as in a real system */ + st->bfi= 1; /* SPEECH PLC code will now become active as in a real system */ /* total_brate= 0 */ } - /* handle bad speech frame(and bad sid frame) in the decoders CNG synthesis settings pair (total_brate, bfi) */ - if( ((st->CNG_fx != 0) && ( (speech_bad != 0) || (speech_lost != 0) )) || /* SP_BAD or SPEECH_LOST) --> stay in CNG */ - ( sid_upd_bad != 0 )) /* SID_UPD_BAD --> start CNG */ + /* handle bad/lost speech frame(and CS bad sid frame) in the decoders CNG synthesis settings pair (total_brate, bfi) */ + if( ((st->CNG != 0) && ( (speech_bad != 0) || (speech_lost != 0) )) || /* SP_BAD or SPEECH_LOST) --> stay in CNG */ + ( sid_upd_bad != 0 )) /* SID_UPD_BAD --> start CNG */ { - st->bfi_fx = 0; + st->bfi = 0; /* bfi=0 needed to activate CNG code */ total_brate = 0; } - /* update for next frame's G.192 file format's SID_FIRST detection (primarily for AMRWBIO) */ - st->prev_ft_speech_fx = ((curr_ft_good_sp != 0) || (curr_ft_bad_sp != 0)); + /* update for next frame's G.192 file format's odd SID_FIRST detection (primarily for AMRWBIO) */ + st->prev_ft_speech = ((curr_ft_good_sp != 0) || (curr_ft_bad_sp != 0)); /* st->total brate= total_brate ; updated in a good frame below */ } /* rew_flag */ - /* get total bit-rate */ - if ( st->bfi_fx == 0 && !rew_flag ) + if ( st->bfi == 0 && !rew_flag ) { - /* select MODE1 or MODE2 */ + /* select Mode 1 or Mode 2 */ decoder_selectCodec( st, total_brate, *pt_stream ); } - Mpy_32_16_ss(total_brate, 5243, &L_tmp, &utmp); /* 5243 is 1/50 in Q18. (0+18-15=3) */ - st->total_num_bits = extract_l(L_shr(L_tmp, 3)); /* Q0 */ - /* in case rew_flag is set, rewind the file and return */ /* (used in io_enc() to print out info about technologies and to initialize the codec) */ if ( rew_flag ) { - rewind( file ); - st->total_brate_fx = total_brate; - move16(); + // rewind( file ); + st->total_brate = total_brate; return 1; } /* GOOD frame */ - if ( st->bfi_fx == 0 ) + if ( st->bfi == 0 ) { /* GOOD frame - convert ITU-T G.192 words to short values */ - bit_stream_ptr = st->bit_stream_fx; + bit_stream_ptr = st->bit_stream; - for( k = 0; k< num_bits; ++k) + for ( k = 0; k < (short)num_bits; ++k ) { - *bit_stream_ptr++ = (*pt_stream++ == G192_BIN1 ); + *bit_stream_ptr++ = (*pt_stream++ == G192_BIN1); } - /*add two zero bytes for arithmetic coder flush*/ - for(k=0; k< 2*8; ++k) + /* add two zero bytes for arithmetic coder flush */ + for (k=0; k<8*2; ++k) { *bit_stream_ptr++ = 0; } - /*a change of the total bitrate should not be - known to the decoder, if the received frame was lost*/ - st->total_brate_fx = total_brate ; + /* a change of the total bitrate should not be + known to the decoder, if the received frame was + lost */ + st->total_brate = total_brate; mdct_switching_dec(st); } @@ -1547,17 +1334,19 @@ Word16 read_indices_fx( /* o : 1 = reading OK, 0 = problem } -/*------------------------------------------------------------------------------------------* -* read_indices_mime() -* -* Read indices from MIME formatted bitstream to the buffer -* The magic word and number of channnels should be consumed before calling this function -*-------------------------------------------------------------------------------------------*/ + +/*-------------------------------------------------------------------* + * read_indices_mime() + * + * Read indices from MIME formatted bitstream to the buffer + *-------------------------------------------------------------------*/ Word16 read_indices_mime( /* o : 1 = reading OK, 0 = problem */ - Decoder_State_fx *st, /* i/o: decoder state structure */ - FILE *file, /* i : bitstream file */ - Word16 rew_flag /* i : rewind flag (rewind file after reading) */ + Decoder_State *st, /* i/o: decoder state structure */ + const char* data, /* i : bitstream data */ + size_t data_size, /* i : bitstream data size */ + size_t* data_processed, /* o : processed data size */ + Word16 rew_flag /* i : rewind flag (rewind file after reading)*/ ) { Word16 k, isAMRWB_IOmode, cmi, core_mode = -1, qbit,sti; @@ -1567,35 +1356,39 @@ Word16 read_indices_mime( /* o : 1 = reading OK, 0 = problem UWord16 *bit_stream_ptr; Word16 num_bits; Word32 total_brate; - UWord16 utmp; - Word32 L_tmp; Word16 curr_ft_good_sp; Word16 amrwb_sid_first, sid_upd_bad, sid_update; Word16 speech_bad, speech_lost; - Word16 no_data; + Word16 _NO_DATA; Word16 num_bytes_read; st->BER_detect = 0; - st->bfi_fx = 0; + st->bfi = 0; st->mdct_sw_enable = 0; st->mdct_sw = 0; - reset_indices_dec_fx( st ); + reset_indices_dec( st ); /* read the FT Header field from the bitstream */ - if ( fread( &header, sizeof(UWord8), 1, file ) != 1 ) + /* read the FT header */ + if (*data_processed + 1 > data_size) + return 0; + header = *(UWord8*)data; INCREASE_DATA_OFFSET(1); + + /*if ( fread( &header, sizeof(UWord8), 1, file ) != 1 ) { if( ferror( file ) ) { - /* error during reading */ + // error during reading fprintf(stderr, "\nError reading the bitstream !"); exit(-1); } else { - /* end of file reached */ + // end of file reached return 0; } - } + }*/ + /* init local RXDTX flags */ curr_ft_good_sp = 0; @@ -1606,7 +1399,7 @@ Word16 read_indices_mime( /* o : 1 = reading OK, 0 = problem sid_upd_bad = 0; sti = -1; amrwb_sid_first = 0; /* derived from sti SID_FIRST indicator in AMRWB payload */ - no_data = 0; + _NO_DATA = 0; if( st->amrwb_rfc4867_flag != 0 ) { @@ -1623,7 +1416,7 @@ Word16 read_indices_mime( /* o : 1 = reading OK, 0 = problem isAMRWB_IOmode = 1; qbit = (header>>2)&0x01 ; /* b2 bit (b7 is the F bit ) */ - st->bfi_fx = !qbit; + st->bfi = !qbit; core_mode = ((header>>3) & 0x0F); /* b6..b3 */ total_brate = AMRWB_IOmode2rate[core_mode]; /* get the frame length from the header */ } @@ -1652,12 +1445,9 @@ Word16 read_indices_mime( /* o : 1 = reading OK, 0 = problem qbit = 1; /* assume good q_bit for the unused EVS-mode bit, complete ToC validity checked later */ total_brate = PRIMARYmode2rate[ core_mode ]; } - st->bfi_fx = !qbit; + st->bfi = !qbit; } - - - /* set up RX-DTX-handler input */ if( core_mode == 14 ) { @@ -1666,19 +1456,16 @@ Word16 read_indices_mime( /* o : 1 = reading OK, 0 = problem } if ( core_mode == 15) { - /* NO_DATA unsent CNG frame OR any frame marked or injected as no_data by e.g a signaling layer or dejitter buffer */ - no_data=1; + /* _NO_DATA unsent CNG frame OR any frame marked or injected as _NO_DATA by e.g a signaling layer or dejitter buffer */ + _NO_DATA=1; } - Mpy_32_16_ss(total_brate, 5243, &L_tmp, &utmp); /* 5243 is 1/50 in Q18. (0+18-15=3) */ - num_bits = extract_l(L_shr(L_tmp, 3)); /* Q0 */ - st->total_num_bits = num_bits; - + num_bits = (Word16)(total_brate/50); if( total_brate < 0 ) { /* validate that total_brate (derived from RTP packet or a file header) is one of the defined bit rates */ - fprintf(stderr, "\n Error. Illegal total bit rate (= %d) in MIME ToC header \n", total_brate ); - /* num_bits = -1; not needed as BASOP multiplication preserves sign */ + fprintf(stderr, "\n Error illegal total bit rate (= %d) in MIME ToC header \n", total_brate ); + num_bits = -1; } /* Check correctness of ToC headers */ @@ -1689,55 +1476,64 @@ Word16 read_indices_mime( /* o : 1 = reading OK, 0 = problem { /* incorrect FT header */ fprintf(stderr, "\nError in EVS FT ToC header(%02x) ! ",header); - exit(-1); + return 0; + // exit(-1); } else if( (isAMRWB_IOmode != 0) && ( (num_bits < 0) || ((header & 0x80) > 0) || ((header & 0x40) > 0) ) ) /* AMRWBIO */ { /* incorrect IO FT header */ fprintf(stderr, "\nError in EVS(AMRWBIO) FT ToC header(%02x) ! ",header); - exit(-1); + return 0; + //exit(-1); } } else { - /* legacy AMRWB ToC, is only using Padding bits which MUST be ignored */ + /* legacy AMRWB ToC, is only using Padding bits which MUST be ignored */ if ( num_bits < 0 ) { /* incorrect FT header */ fprintf(stderr, "\nError in AMRWB RFC4867 Toc(FT) header(%02x) !", header); - exit(-1); + return 0;//exit(-1); } } + + /* read serial stream of indices from file to the local buffer */ - num_bytes_read = (Word16) fread( pFrame, sizeof(UWord8), (num_bits + 7)>>3, file ); + num_bytes_read = (num_bits + 7) >> 3; + if (*data_processed + num_bytes_read > data_size) + return 0; + + memmove(pFrame, data + *data_processed, num_bytes_read); INCREASE_DATA_OFFSET(num_bytes_read); + + /*num_bytes_read = (Word16) fread( pFrame, sizeof(UWord8), (num_bits + 7)>>3, file ); if( num_bytes_read != (num_bits + 7)>>3 ) { fprintf(stderr, "\nError, invalid number of bytes read ! Exiting ! \n"); exit(-1); - } + }*/ /* in case rew_flag is set, rewind the file and return */ - /* (used in io_dec() to attempt print out info about technologies and to initialize the codec ) */ if ( rew_flag ) { - st->total_brate_fx = total_brate; /* used for the codec banner output */ - if( st->bfi_fx == 0 && speech_lost == 0 && no_data == 0 ) + + st->total_brate = total_brate; + /* select MODE1 or MODE2 */ + if( st->bfi == 0 && speech_lost == 0 && _NO_DATA == 0 ) { decoder_selectCodec( st, total_brate, unpack_bit(&pt_pFrame,&mask) ? G192_BIN1 : G192_BIN0); } return 1; } - - /* unpack speech data */ - bit_stream_ptr = st->bit_stream_fx; - for (k=0; kbit_stream; + for( k=0; kbit_stream_fx[sort_ptr[core_mode][k]] = unpack_bit(&pt_pFrame,&mask); + st->bit_stream[sort_ptr[core_mode][k]] = unpack_bit(&pt_pFrame,&mask); bit_stream_ptr++; } else @@ -1747,8 +1543,8 @@ Word16 read_indices_mime( /* o : 1 = reading OK, 0 = problem } /* unpack auxiliary bits */ - /* Note: the cmi bits are unpacked for demo purposes; */ - if (isAMRWB_IOmode && total_brate == SID_1k75) + /* Note: these cmi bits are unpacked for demo purposes; they are actually not needed */ + if( isAMRWB_IOmode && total_brate == SID_1k75 ) { sti = unpack_bit(&pt_pFrame,&mask); cmi = unpack_bit(&pt_pFrame,&mask) << 3; @@ -1761,24 +1557,24 @@ Word16 read_indices_mime( /* o : 1 = reading OK, 0 = problem total_brate = 0; /* signal received SID_FIRST as a good frame with no bits */ for(k=0; k<35; k++) { - st->bfi_fx |= st->bit_stream_fx[k] ; /* partity check of 35 zeroes, any single 1 gives BFI */ + st->bfi |= st->bit_stream[k] ; /* partity check of 35 zeroes, any single 1 gives BFI */ } } + } /*add two zero bytes for arithmetic coder flush*/ - for(k=0; k< 2*8; ++k) + for( k=0; k< 2*8; ++k ) { *bit_stream_ptr++ = 0; } - /* MIME RX_DTX handler */ if( !rew_flag ) { - /* keep st->CNG_fx , st_bfi_fx and total_brate updated for proper synthesis in DTX and FER */ + /* keep st->CNG , st_bfi and total_brate updated for proper synthesis in DTX and FER */ if( total_brate > SID_2k40 ) { - if( st->bfi_fx == 0 ) /* so far derived from q bit in AMRWB/AMRWBIO cases */ + if( st->bfi == 0 ) /* so far derived from q bit in AMRWB/AMRWBIO cases */ { curr_ft_good_sp = 1; } @@ -1788,16 +1584,15 @@ Word16 read_indices_mime( /* o : 1 = reading OK, 0 = problem if( speech_lost != 0 ) /* overrides a good q_bit */ { curr_ft_good_sp = 0; - st->bfi_fx = 1; /* override qbit */ + st->bfi = 1; /* override qbit */ } /* now_bfi_fx has been set based on q_bit and ToC fields */ - /* SID_UPDATE check */ if( total_brate == SID_1k75 || total_brate == SID_2k40 ) { - if( st->bfi_fx == 0 ) + if( st->bfi == 0 ) { /* typically from q bit */ sid_update = 1; @@ -1810,7 +1605,7 @@ Word16 read_indices_mime( /* o : 1 = reading OK, 0 = problem if( isAMRWB_IOmode && total_brate == 0 && sti == 0 ) { - if( st->bfi_fx ) + if( st->bfi ) { sid_upd_bad = 1; /* corrupt sid_first, signaled as bad sid */ } @@ -1821,19 +1616,18 @@ Word16 read_indices_mime( /* o : 1 = reading OK, 0 = problem } if ( sid_upd_bad != 0 && ( - (isAMRWB_IOmode != 0 && st->Opt_AMR_WB_fx==0 ) || /* switch to AMRWBIO */ - (isAMRWB_IOmode != 1 && st->Opt_AMR_WB_fx==1) /* switch from AMRWBIO */ + (isAMRWB_IOmode != 0 && st->Opt_AMR_WB==0 ) || /* switch to AMRWBIO */ + (isAMRWB_IOmode != 1 && st->Opt_AMR_WB==1) /* switch from AMRWBIO */ ) ) { /* do not allow a normal start of CNG synthesis if this SID(with BER or FER) is a switch to/from AMRWBIO */ sid_upd_bad = 0; /* revert this detection due to AMRWBIO/EVS mode switch */ total_brate = 0; - no_data = 1; - assert( st->bfi_fx==1); /* bfi_fx stays 1 */ + _NO_DATA = 1; + assert( st->bfi==1); /* bfi stays 1 */ } - - if( total_brate > SID_2k40 && st->bfi_fx ) /* typically from q bit */ + if( total_brate > SID_2k40 && st->bfi ) /* typically from q bit */ { speech_bad = 1; /* initial assumption, CNG synt state decides what to actually do */ } @@ -1841,13 +1635,13 @@ Word16 read_indices_mime( /* o : 1 = reading OK, 0 = problem /* update CNG synthesis state */ /* Decoder can only enter CNG-synthesis for CNG frame types (sid_upd, sid_bad, sid_first) */ - if( st->CNG_fx != 0 ) + if( st->CNG != 0 ) { /* We were in CNG synthesis */ if( curr_ft_good_sp != 0 ) { /* only a good speech frame makes decoder leave CNG synthesis */ - st->CNG_fx = 0; + st->CNG = 0; } } else @@ -1856,67 +1650,63 @@ Word16 read_indices_mime( /* o : 1 = reading OK, 0 = problem /* only a received SID frame can make the decoder enter into CNG synthesis */ if( amrwb_sid_first || sid_update || sid_upd_bad ) { - st->CNG_fx = 1; + st->CNG = 1; } } /* Now modify bfi flag for the decoder's SPEECH/CNG synthesis logic */ - /* in SPEECH synthesis, make sure to activate speech plc for a received no_data frame, - no_data frames may be injected by the network or by the dejitter buffer */ - /* modify bfi_flag to stay/move into the correct decoder PLC section */ - if ( (st->CNG_fx == 0) && ( no_data != 0 ) ) + /* in SPEECH synthesis, make sure to activate speech plc for a received _NO_DATA frame, + bo_data frames may be injected by the network or by the dejitter buffer */ + /* modify bfi_flag to stay/move to the into the correct decoder PLC section */ + if ( (st->CNG == 0) && ( _NO_DATA != 0 ) ) { - /* treat no_data received in speech synthesis as SP_LOST frames, SPEECH PLC code will now become active */ - st->bfi_fx = 1; - /* total_brate= 0 . always zero for no_data */ + /* treat _NO_DATA received in speech synthesis as SP_LOST frames, SPEECH PLC code will now become active */ + st->bfi = 1; + /* total_brate= 0; always zero for _NO_DATA */ } /* in CNG */ /* handle bad speech frame(and bad sid frame) in the decoders CNG synthesis settings pair (total_brate, bfi) */ - if( ( st->CNG_fx != 0 && ( speech_bad || speech_lost || no_data )) || /* SP_BAD or SPEECH_LOST) --> stay in CNG */ - sid_upd_bad ) /* SID_UPD_BAD --> start/stay CNG */ + if( ( st->CNG != 0 && ( speech_bad || speech_lost || _NO_DATA )) || /* SP_BAD or SPEECH_LOST) --> stay in CNG */ + sid_upd_bad ) /* SID_UPD_BAD --> start/stay CNG */ { - - st->bfi_fx = 0; /* mark as good to not start speech PLC */ - total_brate= 0; /* zeroing is needed for speech_bad, sid_bad frames CNG- synthesis in the decoder subfunctions */ - - + st->bfi = 0; /* mark as good to not start speech PLC */ + total_brate = 0; /* this zeroing needed for speech_bad, sid_bad frames */ } } /* now bfi, total_brate are set by RX-DTX handler:: - bfi==0, total_brate!=0 cng or speech pending bitrate - bfi==0, total_brate==0 cng will continue or start(sid_first, evs_sid_bad, amrwb_sid_bad) - bfi==1, total_brate!=0 speech plc - bfi==1, total_brate==0 , speech plc + bfi==0, total_brate!=0 cng or speech pending bitrate + bfi==0, total_brate==0 cng will continue or start(sid_first, sid_bad) + bfi==1, total_brate!=0 speech plc + bfi==1, total_brate==0 , speech plc */ - - /* handle available AMRWB/AMRWBIO ToC rate info at startup */ - if( ( st->bfi_fx != 0 && rew_flag == 0 && st->ini_frame_fx == 0) && /* ini_frame can not be used when rewflag is 1 */ + /* handle available AMRWB/AMRWBIO MIME header ToC rate-info at startup */ + if( ( st->bfi != 0 && rew_flag == 0 && st->ini_frame == 0) && /* ini_frame can not be used when rewflag is 1 */ ( (st->amrwb_rfc4867_flag != 0) || (st->amrwb_rfc4867_flag == 0 && isAMRWB_IOmode != 0 )) ) /*AMRWB ToC */ { Word32 init_rate; - init_rate = total_brate; /* default , may have been be modified */ - if (speech_lost != 0 || no_data != 0 ) + init_rate = total_brate; /* default , may have been modified from original ToC value */ + if (speech_lost !=0 || _NO_DATA != 0 ) { - init_rate = ACELP_12k65; + init_rate = ACELP_12k65; /* make sure the decoder starts up in a selected AMRWB mode */ } - else if( speech_bad != 0 ) + else if( speech_bad !=0 ) { - init_rate = AMRWB_IOmode2rate[core_mode]; /* read info from ToC */ + init_rate = AMRWB_IOmode2rate[core_mode]; /* read from from ToC */ } - st->total_brate_fx = init_rate; /* not updated on bfi as decoderSelectCodec is not called below */ - st->core_brate_fx = init_rate; + st->total_brate = init_rate; /* not updated on bfi as decoderSelectCodec is not called below */ + st->core_brate = init_rate; } - - if( st->bfi_fx == 0 ) + if( st->bfi == 0 ) { /* select MODE1 or MODE2 in MIME */ - decoder_selectCodec( st, total_brate, *st->bit_stream_fx ? G192_BIN1 : G192_BIN0); + + decoder_selectCodec( st, total_brate, *st->bit_stream ? G192_BIN1 : G192_BIN0); /* a change of the total bitrate should not be known to the decoder, if the received frame was truly lost */ - st->total_brate_fx = total_brate; + st->total_brate = total_brate; mdct_switching_dec(st); } /* else{ bfi stay in past synthesis mode(SP,CNG) } */ @@ -1924,6 +1714,176 @@ Word16 read_indices_mime( /* o : 1 = reading OK, 0 = problem return 1; } + + +/*-------------------------------------------------------------------* +* get_rfFrameType() +* +* Extract the rf frame type +*-------------------------------------------------------------------*/ + +static void get_rfFrameType( + Decoder_State *st, /* i : decoder state structure */ + short *rf_frame_type /* o : RF frame type */ +) +{ + short num_bits; + num_bits = st->total_brate/50; + + if( st->rf_flag == 1) + { + /* the last three bits in a packet is the RF frame type */ + *rf_frame_type = get_indice( st, num_bits - 3, 3 ); + } + else + { + *rf_frame_type = 0; + } + + return; +} + +/*-------------------------------------------------------------------* +* get_rfFlag() +* +* Check if rf flag is present in the bitstream +*-------------------------------------------------------------------*/ + +static void get_rfFlag( + Decoder_State *st, /* i: decoder state structure */ + short *rf_flag, /* o : check for the RF flag */ + short *nBits, + long *ind +) +{ + short start_idx, nBits_tmp; + long ind_tmp; + + /* Init */ + *rf_flag = 0; + + /* check for rf_flag in the packet and extract the rf_frame_type and rf_fec_offset */ + if( st->total_brate == ACELP_13k20 && (st->bfi == FRAMEMODE_NORMAL || st->bfi == FRAMEMODE_FUTURE) ) + { + /* find the section in the ACELP signalling table corresponding to bitrate */ + start_idx = 0; + while ( acelp_sig_tbl[start_idx] != st->total_brate ) + { + start_idx++; + assert((start_idx < MAX_ACELP_SIG) && "ERROR: start_idx larger than acelp_sig_tbl[].\n"); + } + + /* skip the bitrate */ + start_idx += 1; + + /* retrieve the number of bits */ + nBits_tmp = (short) acelp_sig_tbl[start_idx++]; + + /* retrieve the signalling indice */ + ind_tmp = acelp_sig_tbl[start_idx + get_indice( st, 0, nBits_tmp )]; + + /* convert signalling indice into RF flag. */ + *rf_flag = (ind_tmp >> 7) & 0x1; + + if( ind ) + { + *ind = ind_tmp; + } + + if( nBits ) + { + *nBits = nBits_tmp; + } + } + + return; +} + +/*-------------------------------------------------------------------* +* get_rf_fec_offset() +* +* Extract the FEC offset +*-------------------------------------------------------------------*/ + +static void get_rf_fec_offset( + Decoder_State *st, /* i : decoder state structure */ + short *rf_fec_offset /* o : RF fec offset */ +) +{ + short num_bits, tmp; + num_bits = st->total_brate/50; + + if( st->rf_flag == 1) + { + /* the two bits before the rf frame type contains the fec offset */ + tmp = get_indice( st, num_bits - 5, 2 ); + + if (tmp == 0) + { + *rf_fec_offset = 2; + } + else + { + *rf_fec_offset = 2*tmp + 1; + } + + } + else + { + *rf_fec_offset = 0; + } + + return; +} + +/*-------------------------------------------------------------------* +* get_rfTargetBits() +* +* Return the number of RF target bits +*-------------------------------------------------------------------*/ + +static void get_rfTargetBits( + short rf_frame_type, /* i : RF frame type */ + short *rf_target_bits /* o : Number of RF target bits */ +) +{ + /* Number of RF bits for different RF coder types */ + + switch (rf_frame_type) + { + case RF__NO_DATA: + *rf_target_bits = 5; + break; + case RF_TCXFD: + *rf_target_bits = 27; + break; + case RF_TCXTD1: + *rf_target_bits = 16; + break; + case RF_TCXTD2: + *rf_target_bits = 16; + break; + case RF_ALLPRED: + /* Es_pred bits 3 bits, LTF: 1, pitch: 8,5,5,5, FCB: 0, gain: 7,0,7,0, Diff GFr: 4*/ + *rf_target_bits = 63; + break; + case RF_NOPRED: + /* Es_pred bits 3 bits, LTF: 0, pitch: 0, FCB: 7,7,7,7, gain: 6,0,6,0, Diff GFr: 2*/ + *rf_target_bits = 66; + break; + case RF_GENPRED: + /* Es_pred bits 3 bits, LTF: 1, pitch: 8,0,8,0, FCB: 6,7,5,5, gain: 5,0,5,0, Diff GFr: 0*/ + *rf_target_bits = 70; + break; + case RF_NELP: + /* gain: 19, Diff GFr: 5 */ + *rf_target_bits = 45; + break; + } + + return; +} + /*-------------------------------------------------------------------* * berCheck() * @@ -1931,48 +1891,42 @@ Word16 read_indices_mime( /* o : 1 = reading OK, 0 = problem *-------------------------------------------------------------------*/ static void berCheck( - Decoder_State_fx *st, /* i/o: decoder state structure */ - Word16 *coder_type /* i/o: coder type */ + Decoder_State *st, /* i/o: decoder state structure */ + short *coder_type /* i/o: coder type */ ) { /* In case of RF flag = 1, and valid RF packet with primary and partial copy */ - if ( ( sub( st->bwidth_fx, NB) == 0 || sub( st->bwidth_fx, FB) == 0 ) - || (sub(*coder_type,TRANSITION) >= 0 ) - ) + if( st->bwidth == NB || st->bwidth == FB || *coder_type >= TRANSITION ) { - if( sub( st->use_partial_copy, 1 ) == 0 ) + if( st->use_partial_copy == 1 ) { st->use_partial_copy = 0; - move16(); } - st->bfi_fx = 1; - move16(); - st->bwidth_fx = st->last_bwidth_fx; - move16(); + st->bfi = 1; + st->bwidth = st->last_bwidth; st->BER_detect = 1; - move16(); *coder_type = GENERIC; - move16(); } return; } /*-------------------------------------------------------------------* -* getPartialCopyInfo() -* -* Check if the frame includes a partial copy for channel aware processing. -*-------------------------------------------------------------------*/ + * getPartialCopyInfo() + * + * Check if the frame includes a partial copy for channel aware processing. + *-------------------------------------------------------------------*/ void getPartialCopyInfo( - Decoder_State_fx *st, /* i/o: decoder state structure */ - Word16 *coder_type, - Word16 *sharpFlag + Decoder_State *st, /* i/o: decoder state structure */ + short *coder_type, + short *sharpFlag ) { - Word16 nBits; - Word16 ind; + short nBits = 0; + long ind = 0; + /* check the rf flag in the packet */ get_rfFlag( st, &(st->rf_flag), &nBits , &ind); @@ -1986,400 +1940,196 @@ void getPartialCopyInfo( st->rf_target_bits = 0; /* Get the number of bits used for RF*/ - IF( sub(st->rf_flag,1) == 0 ) + if( st->rf_flag == 1 ) { - *coder_type = s_and(ind,0x7); - st->bwidth_fx = s_and(shr(ind,3), 0x7); - *sharpFlag = s_and(shr(ind,6), 0x1); + *coder_type = ind & 0x7; + st->bwidth = (ind >> 3) & 0x7; + *sharpFlag = (ind >> 6) & 0x1; st->codec_mode = MODE2; - move16(); get_rfTargetBits( st->rf_frame_type, &(st->rf_target_bits) ); - IF( sub(st->bfi_fx,FRAMEMODE_FUTURE) == 0 ) + if( st->bfi == FRAMEMODE_FUTURE ) { st->use_partial_copy = 1; /* now set the frame mode to normal mode */ - test(); - IF(sub(st->rf_frame_type,RF_TCXFD) >= 0 && sub(st->rf_frame_type, RF_TCXTD2) <= 0) + if(st->rf_frame_type >= RF_TCXFD && st->rf_frame_type <= RF_TCXTD2) { - st->bfi_fx = 1; - st->core_fx = 1; + st->bfi = 1; + st->core = 1; } - ELSE + else { - st->bfi_fx = FRAMEMODE_NORMAL; - st->core_fx = 0; + st->bfi = FRAMEMODE_NORMAL; + st->core = 0; } } /* check for bit errors */ berCheck( st, coder_type ); - get_next_indice_tmp_fx(st, nBits); - + get_next_indice_tmp(st, nBits); } + + return; } /*-------------------------------------------------------------------* -* get_rfFlag() -* -* Check if rf flag is present in the bitstream -*-------------------------------------------------------------------*/ - -void get_rfFlag( - Decoder_State_fx *st, /* i: decoder state structure */ - Word16 *rf_flag, /* o : check for the RF flag */ - Word16 *nBits, - Word16 *ind -) -{ - Word16 start_idx, nBits_tmp; - Word16 ind_tmp; - - /* Init */ - *rf_flag = 0; - - /* check for rf_flag in the packet and extract the rf_frame_type and rf_fec_offset */ - test(); - test(); - IF( L_sub(st->total_brate_fx,ACELP_13k20) == 0 && (sub(st->bfi_fx,FRAMEMODE_NORMAL) == 0 || sub(st->bfi_fx, FRAMEMODE_FUTURE) == 0) ) - { - /* find the section in the ACELP signalling table corresponding to bitrate */ - start_idx = 0; - WHILE ( L_sub(acelp_sig_tbl[start_idx], st->total_brate_fx) != 0 ) - { - start_idx++; - assert((start_idx < MAX_ACELP_SIG) && "ERROR: start_idx larger than acelp_sig_tbl[].\n"); - } - - /* skip the bitrate */ - start_idx = add(start_idx,1); - - /* retrieve the number of bits */ - nBits_tmp = (Word16) acelp_sig_tbl[start_idx++]; - - /* retrieve the signalling indice */ - ind_tmp = (Word16) acelp_sig_tbl[start_idx + get_indice_fx( st, 0, nBits_tmp )]; - - /* convert signalling indice into RF flag. */ - *rf_flag = s_and(shr(ind_tmp, 7), 0x1); - - if( ind ) - { - *ind = ind_tmp; - } - - if( nBits ) - { - *nBits = nBits_tmp; - } - } -} - -/*-------------------------------------------------------------------* -* get_rfFrameType() -* -* Extract the rf frame type -*-------------------------------------------------------------------*/ - -void get_rfFrameType( - Decoder_State_fx *st, /* i : decoder state structure */ - Word16 *rf_frame_type /* o : RF frame type */ -) -{ - Word16 num_bits = 0; - - IF( sub(st->rf_flag, 1)== 0) - { - /*num_bits = st->total_brate_fx/50;*/ - if( L_sub(st->total_brate_fx, ACELP_13k20) == 0 ) - { - num_bits = 264; - move16(); /* @13.2kbps */ - } - else - { - UWord16 lsb; - Word32 L_tmp; - Mpy_32_16_ss(st->total_brate_fx, 5243, &L_tmp, &lsb); /* 5243 is 1/50 in Q18. (0+18-15=3) */ - num_bits = extract_l(L_shr(L_tmp, 3)); /* Q0 */ - } - - /* the last three bits in a packet is the RF frame type */ - *rf_frame_type = get_indice_fx( st, num_bits - 3, 3 ); - } - ELSE - { - *rf_frame_type = 0; - } -} - -/*-------------------------------------------------------------------* -* get_rf_fec_offset() -* -* Extract the FEC offset -*-------------------------------------------------------------------*/ - -void get_rf_fec_offset( - Decoder_State_fx *st, /* i : decoder state structure */ - Word16 *rf_fec_offset /* o : RF fec offset */ -) -{ - Word16 num_bits, tmp; - - IF( sub(st->rf_flag,1)== 0) - { - /*num_bits = st->total_brate_fx/50;*/ - if( L_sub(st->total_brate_fx, ACELP_13k20) == 0 ) - { - num_bits = 264; - move16(); /* @13.2kbps */ - } - else - { - UWord16 lsb; - Word32 L_tmp; - Mpy_32_16_ss(st->total_brate_fx, 5243, &L_tmp, &lsb); /* 5243 is 1/50 in Q18. (0+18-15=3) */ - num_bits = extract_l(L_shr(L_tmp, 3)); /* Q0 */ - } - - /* the two bits before the rf frame type contain the fec offset */ - tmp = get_indice_fx( st, num_bits - 5, 2 ); - - if( tmp == 0 ) - { - *rf_fec_offset = 2; - move16(); - } - else - { - *rf_fec_offset = add(shl(tmp, 1), 1); - } - } - ELSE - { - *rf_fec_offset = 0; - move16(); - } -} - -/*-------------------------------------------------------------------* -* get_rfTargetBits() -* -* Return the number of RF target bits -*-------------------------------------------------------------------*/ - -void get_rfTargetBits( - Word16 rf_frame_type, /* i : RF frame type */ - Word16 *rf_target_bits /* o : Number of RF target bits */ -) -{ - - /* Number of RF bits for different RF coder types */ - - SWITCH (rf_frame_type) - { - case RF_NO_DATA: - *rf_target_bits = 5; - BREAK; - case RF_TCXFD: - *rf_target_bits = 27; - BREAK; - case RF_TCXTD1: - *rf_target_bits = 16; - BREAK; - case RF_TCXTD2: - *rf_target_bits = 16; - BREAK; - case RF_ALLPRED: - /* Es_pred bits 3 bits, LTF: 1, pitch: 8,5,5,5, FCB: 0, gain: 7,0,7,0, Diff GFr: 4*/ - *rf_target_bits = 63; - BREAK; - case RF_NOPRED: - /* Es_pred bits 3 bits, LTF: 0, pitch: 0, FCB: 7,7,7,7, gain: 6,0,6,0, Diff GFr: 2*/ - *rf_target_bits = 66; - BREAK; - case RF_GENPRED: - /* Es_pred bits 3 bits, LTF: 1, pitch: 8,0,8,0, FCB: 6,7,5,5, gain: 5,0,5,0, Diff GFr: 0*/ - *rf_target_bits = 70; - BREAK; - case RF_NELP: - /* gain: 19, Diff GFr: 5 */ - *rf_target_bits = 45; - BREAK; - } -} - - -/*-------------------------------------------------------------------* - * get_NextCoderType_fx() + * get_NextCoderType() * * Extract the coder type of next frame *-------------------------------------------------------------------*/ -void get_NextCoderType_fx( - UWord8 *bitsteam, /* i : bitstream */ - Word16 *next_coder_type /* o : next coder type */ +void get_NextCoderType( + unsigned char *bitsteam, /* i : bitstream */ + short *next_coder_type /* o : next coder type */ ) { - Word16 k; - Word16 start_idx; - Word16 nBits_tmp; - Word8 bit_stream[ACELP_13k20/50]; - UWord16 tmp; + short k; + short start_idx; + char bit_stream[ACELP_13k20/50]; + long tmp; + short nBits_tmp; - FOR( k = 0; k < ACELP_13k20/50; k++ ) + for( k = 0; k < ACELP_13k20/50; k++ ) { bit_stream[k] = (bitsteam[k / 8] >> (7 - (k % 8))) & 0x1; } start_idx = 0; - WHILE ( L_sub(acelp_sig_tbl[start_idx], ACELP_13k20) != 0 ) + while ( acelp_sig_tbl[start_idx] != ACELP_13k20 ) { - start_idx = add(start_idx,1); + start_idx++; assert((start_idx < MAX_ACELP_SIG) && "ERROR: start_idx larger than acelp_sig_tbl[].\n"); } /* skip the bitrate */ - start_idx = add(start_idx,1); + start_idx += 1; tmp = 0; - move16(); - nBits_tmp = (Word16) acelp_sig_tbl[start_idx++]; - FOR (k = 0; k < nBits_tmp; k++) + nBits_tmp = (short) acelp_sig_tbl[start_idx++]; + for (k = 0; k < nBits_tmp; k++) { - tmp = lshl(tmp, 1); - tmp = add(tmp, bit_stream[k]); + tmp <<= 1; + tmp += bit_stream[k]; } + /* retrieve the signalling indice */ - *next_coder_type = s_and((Word16)acelp_sig_tbl[start_idx + tmp],0x7); + *next_coder_type = acelp_sig_tbl[start_idx + tmp] & 0x7; + + return; } /*-------------------------------------------------------------------* - * read_indices_from_djb_fx() + * read_indices_from_djb() * * Read indices from the de-jitter buffer payload (works also for AMR-WB IO mode) *-------------------------------------------------------------------*/ -void read_indices_from_djb_fx( /* o : 1 = reading OK, 0 = problem */ - Decoder_State_fx *st, /* i/o: decoder state structure */ - UWord8 *pt_stream, /* i : bitstream file */ - Word16 num_bits /* i : input frame length in bits */ - ,Word16 partialframe /* i : partial frame information */ - ,Word16 next_coder_type /* i : next coder type information */ +void read_indices_from_djb( + Decoder_State *st, /* i/o: decoder state structure */ + unsigned char *pt_stream, /* i : bitstream file */ + int num_bits, /* i : input frame length in bits */ + short partialframe, /* i : partial frame information */ + short next_coder_type /* i : next coder type information */ ) { - Word16 k; - UWord16 *bit_stream_ptr; - Word32 total_brate; - Word32 L_tmp; - UWord16 utmp; - Word16 bit0; + int k; + unsigned short *bit_stream_ptr; + long total_brate; + short bit0; st->BER_detect = 0; bit0 = 0; - /* There is no FRAME_NO_DATA or BAD frame indicator in RTP, frames are just missing. - * In case of comfort noise handle missing frame as FRAME_NO_DATA, otherwise use PLC. */ - IF(num_bits != 0) + /* There is no FRAME__NO_DATA or BAD frame indicator in RTP, frames are just missing. + * In case of comfort noise handle missing frame as FRAME__NO_DATA, otherwise use PLC. */ + if(num_bits != 0) { - st->bfi_fx = 0; - bit0 = G192_BIN0; - if( (*pt_stream & 0x80) != 0 ) - { - bit0 = G192_BIN1; - } + st->bfi = 0; + bit0 = ((*pt_stream & 0x80) != 0) ? G192_BIN1 : G192_BIN0; } - ELSE IF(L_sub(st->total_brate_fx,SID_1k75) == 0 || - L_sub(st->total_brate_fx,SID_2k40) == 0 || - L_sub(st->total_brate_fx,FRAME_NO_DATA) == 0 ) + else if(st->total_brate == SID_1k75 || st->total_brate == SID_2k40 || + st->total_brate == FRAME__NO_DATA) { - st->bfi_fx = 0; + st->bfi = 0; } - ELSE + else { - st->bfi_fx = 1; + st->bfi = 1; } - IF( sub(partialframe,1) == 0 || sub(st->prev_use_partial_copy,1) == 0 ) + if( partialframe || st->prev_use_partial_copy) { st->next_coder_type = next_coder_type; } - ELSE + else { st->next_coder_type = INACTIVE; } st->mdct_sw_enable = 0; st->mdct_sw = 0; - reset_indices_dec_fx( st ); + reset_indices_dec( st ); total_brate = num_bits * 50; - IF(sub(partialframe,1) == 0) + if(partialframe == 1) { - st->bfi_fx = 2; + st->bfi = 2; } - - Mpy_32_16_ss(total_brate, 5243, &L_tmp, &utmp); /* 5243 is 1/50 in Q18. (0+18-15=3) */ - st->total_num_bits = extract_l(L_shr(L_tmp, 3)); /* Q0 */ - - IF ( st->bfi_fx != 1 ) + if ( st->bfi != 1 ) { - /* select MODE1 or MODE2 */ + /* select Mode 1 or Mode 2 */ decoder_selectCodec( st, total_brate, bit0 ); /* convert bitstream from compact bytes to short values and store it in decoder state */ - bit_stream_ptr = st->bit_stream_fx; - FOR( k = 0; k < num_bits; k++ ) + bit_stream_ptr = st->bit_stream; + for( k = 0; k < num_bits; k++ ) { *bit_stream_ptr++ = (pt_stream[k / 8] >> (7 - (k % 8))) & 0x1; } /* add two zero bytes for arithmetic coder flush */ - FOR( k=0; k < 8*2; ++k ) + for( k=0; k < 8*2; ++k ) { *bit_stream_ptr++ = 0; } - /* a change of the total bitrate should not be - known to the decoder, if the received frame was - lost */ - st->total_brate_fx = total_brate; + /* a change of the total bitrate should not be known to the decoder, if the received frame was lost */ + st->total_brate = total_brate; mdct_switching_dec(st); } + + return; } - - - /*-------------------------------------------------------------------* * get_indice_preview() * * Indices preview to parse for the presence of partial copy *-------------------------------------------------------------------*/ -static UWord16 get_indice_preview( - UWord8 *bitstream, - Word16 bitstreamSize, - Word16 pos, - Word16 nb_bits +static unsigned short get_indice_preview( + unsigned char *bitstream, + int bitstreamSize, + short pos, + short nb_bits ) { - UWord16 value; - Word16 i; - UWord16 bitstreamShort[MAX_BITS_PER_FRAME+16]; - UWord16 *bitstreamShortPtr; + unsigned short value; + int i; + unsigned short bitstreamShort[MAX_BITS_PER_FRAME+16]; + unsigned short *bitstreamShortPtr; /* convert bitstream from compact bytes to short values */ bitstreamShortPtr = bitstreamShort; - FOR( i = 0; i < bitstreamSize; i++ ) + for( i = 0; i < bitstreamSize; i++ ) { *bitstreamShortPtr++ = (bitstream[i / 8] >> (7 - (i % 8))) & 0x1; } assert(nb_bits <= 16); value = 0; - FOR (i = 0; i < nb_bits; i++) + for (i = 0; i < nb_bits; i++) { - value = shl(value,1); - value = add(value,bitstreamShort[pos+i]); + value <<= 1; + value += bitstreamShort[pos+i]; } return value; } @@ -2390,56 +2140,55 @@ static UWord16 get_indice_preview( * Signalling index preview *-------------------------------------------------------------------*/ void evs_dec_previewFrame( - UWord8 *bitstream, - Word16 bitstreamSize, - Word16 *partialCopyFrameType, - Word16 *partialCopyOffset + unsigned char *bitstream, + int bitstreamSize, + short *partialCopyFrameType, + short *partialCopyOffset ) { - Word32 total_brate; - Word16 start_idx, nBits; - Word32 ind; - Word16 rf_flag; + long total_brate; + short start_idx, nBits; + long ind; + short rf_flag; rf_flag = 0; *partialCopyFrameType = 0; *partialCopyOffset = 0; total_brate = bitstreamSize * 50; - IF( L_sub(total_brate,ACELP_13k20) == 0 ) + if( total_brate == ACELP_13k20 ) { /* find the section in the ACELP signalling table corresponding to bitrate */ start_idx = 0; - WHILE ( L_sub(acelp_sig_tbl[start_idx], total_brate) != 0 ) + while ( acelp_sig_tbl[start_idx] != total_brate ) { - start_idx = add(start_idx,1); + start_idx++; assert((start_idx < MAX_ACELP_SIG) && "ERROR: start_idx larger than acelp_sig_tbl[].\n"); } /* skip the bitrate */ - start_idx = add(start_idx,1); + start_idx += 1; /* retrieve the number of bits */ - nBits = (Word16) acelp_sig_tbl[start_idx++]; + nBits = (short) acelp_sig_tbl[start_idx++]; /* retrieve the signalling indice */ ind = acelp_sig_tbl[start_idx + get_indice_preview( bitstream, bitstreamSize, 0, nBits )]; /* convert signalling indice into RF flag. */ - rf_flag = s_and(extract_l(L_shr(ind, 7)), 0x1); - assert(rf_flag == ((ind >> 7) & 0x1)); - IF(rf_flag != 0) + rf_flag = (ind >> 7) & 0x1; + if(rf_flag != 0) { /* read the fec offset at which the partial copy is received */ ind = get_indice_preview( bitstream, bitstreamSize, (bitstreamSize-5), 2 ); - IF(ind== 0) *partialCopyOffset = 2; - ELSE IF(L_sub(ind,1)==0) *partialCopyOffset = 3; - ELSE IF(L_sub(ind,2)==0) *partialCopyOffset = 5; - ELSE IF(L_sub(ind,3)==0) *partialCopyOffset = 7; - + if(ind== 0) *partialCopyOffset = 2; + else if(ind == 1) *partialCopyOffset = 3; + else if(ind == 2) *partialCopyOffset = 5; + else if(ind == 3) *partialCopyOffset = 7; /* the last three bits in a packet is the RF frame type */ *partialCopyFrameType = get_indice_preview( bitstream, bitstreamSize, bitstreamSize - 3, 3 ); } } + + return; } - diff --git a/src/libs/libevs/lib_com/calc_st_com.cpp b/src/libs/libevs/lib_com/calc_st_com.cpp new file mode 100644 index 00000000..cced1191 --- /dev/null +++ b/src/libs/libevs/lib_com/calc_st_com.cpp @@ -0,0 +1,273 @@ +/*==================================================================================== + EVS Codec 3GPP TS26.443 Nov 13, 2018. Version 12.11.0 / 13.7.0 / 14.3.0 / 15.1.0 + ====================================================================================*/ + +#include +#include "options.h" +#include "cnst.h" +#include "prot.h" + + + +/*---------------------------------------------------------------------------- + * calc_rc0_h() + * + * computes 1st parcor from composed filter impulse response + *---------------------------------------------------------------------------*/ + +static void calc_rc0_h( + const float *h, /* i : impulse response of composed filter */ + float *rc0 /* o : 1st parcor */ +) +{ + float acf0, acf1; + float temp, temp2; + const float *ptrs; + int i; + + /* computation of the autocorrelation function acf */ + temp = (float) 0.; + for (i = 0; i < LONG_H_ST; i++) + { + temp += h[i] * h[i]; + } + acf0 = temp; + + temp = (float) 0.; + ptrs = h; + for (i = 0; i < LONG_H_ST - 1; i++) + { + temp2 = *ptrs++; + temp += temp2 * (*ptrs); + } + acf1 = temp; + + /* Initialisation of the calculation */ + if (acf0 == (float) 0.) + { + *rc0 = (float) 0.; + return; + } + + /* Compute 1st parcor */ + if (acf0 < (float) fabs (acf1)) + { + *rc0 = (float) 0.0; + return; + } + *rc0 = -acf1 / acf0; + + return; +} + + +/*---------------------------------------------------------------------------- + * calc_st_filt() + * + * computes impulse response of A(gamma2) / A(gamma1) + * controls gain : computation of energy impulse response as + * SUMn (abs (h[n])) and computes parcor0 + *---------------------------------------------------------------------------- */ + +void calc_st_filt( + const float *apond2, /* i : coefficients of numerator */ + const float *apond1, /* i : coefficients of denominator */ + float *parcor0, /* o : 1st parcor calcul. on composed filter */ + float *sig_ltp_ptr, /* i/o: input of 1/A(gamma1) : scaled by 1/g0 */ + float *mem_zero, /* i/o: All zero memory */ + const short L_subfr, /* i : the length of subframe */ + const short extl /* i : extension layer info */ + +) +{ + float h[LONG_H_ST]; + float g0, temp; + int i; + + /* compute i.r. of composed filter apond2 / apond1 */ + if( extl == SWB_TBE ) + { + syn_filt( apond1, LPC_SHB_ORDER, apond2, h, LONG_H_ST, mem_zero, 0 ); + } + else + { + syn_filt( apond1, M, apond2, h, LONG_H_ST, mem_zero, 0 ); + } + + /* compute 1st parcor */ + calc_rc0_h( h, parcor0 ); + + /* compute g0 */ + g0 = (float) 0.; + for (i = 0; i < LONG_H_ST; i++) + { + g0 += (float) fabs (h[i]); + } + + /* Scale signal input of 1/A(gamma1) */ + if (g0 > (float) 1.) + { + temp = (float) 1. / g0; + + for (i = 0; i < L_subfr; i++) + { + sig_ltp_ptr[i] = sig_ltp_ptr[i] * temp; + } + } + + return; +} + +/*---------------------------------------------------------------------------- + * filt_mu() + * + * tilt filtering with : (1 + mu z-1) * (1/1-|mu|) + * computes y[n] = (1/1-|mu|) (x[n]+mu*x[n-1]) + *---------------------------------------------------------------------------*/ + +void filt_mu( + const float *sig_in, /* i : signal (beginning at sample -1) */ + float *sig_out, /* o : output signal */ + const float parcor0, /* i : parcor0 (mu = parcor0 * gamma3) */ + const short L_subfr, /* i : the length of subframe */ + const short extl /* i : extension layer info */ +) +{ + short n; + float mu, ga, temp; + const float *ptrs; + + if( extl == SWB_TBE ) + { + if(parcor0 > 0.0f) + { + mu = parcor0 * GAMMA3_PLUS_WB; + } + else + { + mu = parcor0 * GAMMA3_MINUS_WB; + } + } + else + { + if (parcor0 > 0.0f) + { + mu = parcor0 * GAMMA3_PLUS; + } + else + { + mu = parcor0 * GAMMA3_MINUS; + } + } + + ga = (float) 1. / ((float) 1. - (float) fabs (mu)); + + ptrs = sig_in; /* points on sig_in(-1) */ + + for (n = 0; n < L_subfr; n++) + { + temp = mu * (*ptrs++); + temp += (*ptrs); + sig_out[n] = ga * temp; + } + + return; +} + + + + +/*---------------------------------------------------------------------------- + * scale_st() + * + * control of the subframe gain + * gain[n] = AGC_FAC_FX * gain[n-1] + (1 - AGC_FAC_FX) g_in/g_out + *---------------------------------------------------------------------------*/ + +void scale_st( + const float *sig_in, /* i : postfilter input signal */ + float *sig_out, /* i/o: postfilter output signal */ + float *gain_prec, /* i/o: last value of gain for subframe */ + const short L_subfr, /* i : the length of subframe */ + const short extl /* i : extension layer info */ +) +{ + int i; + float gain_in, gain_out; + float g0, gain; + float agc_fac1_para = 0.0f; + float agc_fac_para = 0.0f; + + if( extl == SWB_TBE ) + { + agc_fac1_para = AGC_FAC1_WB; + agc_fac_para = AGC_FAC_WB; + } + else + { + agc_fac1_para = AGC_FAC1; + agc_fac_para = AGC_FAC; + } + + /* compute input gain */ + gain_in = (float) 0.; + for (i = 0; i < L_subfr; i++) + { + gain_in += (float) fabs (sig_in[i]); + } + + if ( gain_in == 0.0f ) + { + g0 = 0.0f; + } + else + { + /* Compute output gain */ + gain_out = 0.0f; + for (i = 0; i < L_subfr; i++) + { + gain_out += (float) fabs (sig_out[i]); + } + + if (gain_out == 0.0f) + { + *gain_prec = 0.0f; + return; + } + + g0 = gain_in / gain_out; + g0 *= agc_fac1_para; + } + + /* compute gain(n) = AGC_FAC gain(n-1) + (1-AGC_FAC)gain_in/gain_out */ + /* sig_out(n) = gain(n) sig_out(n) */ + gain = *gain_prec; + for (i = 0; i < L_subfr; i++) + { + gain *= agc_fac_para; + gain += g0; + sig_out[i] *= gain; + } + + *gain_prec = gain; + + return; +} + +void blend_subfr2( float *sigIn1, float *sigIn2, float *sigOut) +{ + + float fac1 = 1.f - (1.f / L_SUBFR); + float fac2 = 0.f + (1.f / L_SUBFR); + float step = 1.f / (L_SUBFR/2); + int i; + + for(i=0; iAbout polyphase filtering - The polyphase implementation of a filterbank requires filtering at the input and output. - This is implemented as part of cplxAnalysisCldfbFiltering() and cplxSynthesisCldfbFiltering(). - -*/ - -#include "stl.h" -#include "cnst_fx.h" -#include "stat_com.h" -#include "rom_com_fx.h" -#include "basop_util.h" -#include "prot_fx.h" +#include +#include +#include "stat_dec.h" +#include "prot.h" +#include "rom_com.h" +#include "string.h" #include -#define STATE_BUFFER_SIZE ( 9+16 ) +#if defined __ICL +#define restrict __restrict +#else +#define restrict +#endif -#define CLDFB_NO_POLY ( 5 ) -#define SYN_FILTER_HEADROOM ( 1 ) - -#define CLDFB_LDCLDFB_PFT_SCALE ( 0 ) -#define CLDFB_CLDFB80_O24_PFT_SCALE ( 1 ) -#define CLDFB_CLDFB80_O5_PFT_SCALE ( 1 ) -#define CLDFB_CLDFB80_PFT_SCALE ( 1 ) +#ifdef _MSC_VER +#pragma warning(disable : 4305) /* disable truncation from double to float warning (VC++)*/ +#endif +/*-------------------------------------------------------------------* + * local prototypes + *--------------------------------------------------------------------*/ -#define SYN_FILTER_HEADROOM_1MS ( 2 ) -#define SYN_FILTER_HEADROOM_2MS ( 2 ) -#define SYN_FILTER_HEADROOM_2_5MS ( 2 ) -#define SYN_FILTER_HEADROOM_8MS ( 1 ) +static void cldfb_init_proto_and_twiddles(HANDLE_CLDFB_FILTER_BANK hs); -#define N8 ( 4 ) -#define N10 ( 5 ) -#define N16 ( 8 ) -#define N20 ( 10 ) -#define N30 ( 15 ) -#define N32 ( 16 ) -#define N40 ( 20 ) -#define N60 ( 30 ) +static float GetEnergyCldfb( float *energyValuesSum, float *energyLookahead, float **realValues, float **imagValues, + int numberBands, int numberCols, HANDLE_TEC_ENC hTecEnc ); -static void -cldfb_init_proto_and_twiddles(HANDLE_CLDFB_FILTER_BANK hs); - -#define cplxMpyS(yr,yi,xr,xi,cr,ci,syr,syi,sxr,sxi,zr,zi) zr = L_sub(Mpy_32_16_1(*xr,*cr), Mpy_32_16_1(*xi,*ci)); \ - zi = L_add(Mpy_32_16_1(*xr,*ci), Mpy_32_16_1(*xi,*cr)); \ - *yr = zr; move32(); \ - *yi = zi; move32(); \ - yr+=syr, yi+=syi, xr+=sxr, xi+=sxi, cr++, ci++ - -#define cplxMpy(ryr,ryi,iyr,iyi,rxr,rxi,ixr,ixi,cr,ci,g,sx,sr) ryr = Mpy_32_16_1(L_sub(Mpy_32_16_1(*rxr,*cr),Mpy_32_16_1(*rxi,*ci)),g); \ - ryi = Mpy_32_16_1(L_add(Mpy_32_16_1(*rxr,*ci),Mpy_32_16_1(*rxi,*cr)),g); \ - iyr = Mpy_32_16_1(L_sub(Mpy_32_16_1(*ixr,*cr),Mpy_32_16_1(*ixi,*ci)),g); \ - iyi = Mpy_32_16_1(L_add(Mpy_32_16_1(*ixr,*ci),Mpy_32_16_1(*ixi,*cr)),g); \ - rxr+=sx, rxi+=sx, ixr+=sx, ixi+=sx, cr+=sr, ci+=sr - -#define add1(y1,y2,y3,y4,rr12,ri12,ir12,ii12,s) *y1 = round_fx(L_shl(L_negate(L_add(rr12,ii12)),s)); \ - *y2 = round_fx(L_shl(L_negate(L_add(ri12,ir12)),s)); \ - *y3 = round_fx(L_shl(L_sub(rr12,ii12),s)); \ - *y4 = round_fx(L_shl(L_sub(ir12,ri12),s)); \ - y1+=2, y2-=2, y3-=2, y4+=2 - - -#define add2(y1,y2,y3,y4,rr12,ri12,ir12,ii12,s) *y1 = round_fx(L_shl(L_add(ri12,ir12),s)); \ - *y2 = round_fx(L_shl(L_add(rr12,ii12),s)); \ - *y3 = round_fx(L_shl(L_sub(ir12,ri12),s)); \ - *y4 = round_fx(L_shl(L_sub(rr12,ii12),s)); \ - y1+=2, y2-=2, y3-=2, y4+=2 - -#define ptrUpdate16(y11,y12,y13,y14,r11,x11,x12,x13,x14,r12,y21,y22,y23,y24,r21,x21,x22,x23,x24,r22) \ - y11 += 2*N8, y12 -= 2*N8, y13 -= 2*N8, y14 += 2*N8, r11 -= 1*N8; \ - x11 -= 2*N8, x12 -= 2*N8, x13 -= 2*N8, x14 -= 2*N8, r12 -= 1*N8; \ - y21 += 2*N8, y22 -= 2*N8, y23 -= 2*N8, y24 += 2*N8, r21 += 1*N8; \ - x21 += 2*N8, x22 += 2*N8, x23 += 2*N8, x24 += 2*N8, r22 += 1*N8 - -#define ptrUpdate20(y11,y12,y13,y14,r11,x11,x12,x13,x14,r12,y21,y22,y23,y24,r21,x21,x22,x23,x24,r22) \ - y11 += 2*N10, y12 -= 2*N10, y13 -= 2*N10, y14 += 2*N10, r11 -= 1*N10; \ - x11 -= 2*N10, x12 -= 2*N10, x13 -= 2*N10, x14 -= 2*N10, r12 -= 1*N10; \ - y21 += 2*N10, y22 -= 2*N10, y23 -= 2*N10, y24 += 2*N10, r21 += 1*N10; \ - x21 += 2*N10, x22 += 2*N10, x23 += 2*N10, x24 += 2*N10, r22 += 1*N10 - - - -static void cplxMult10(Word32 *yr, Word32 *yi, Word32 *xr, Word32 *xi, const Word16 *cr, const Word16 *ci, Word16 syr, Word16 syi, Word16 sxr, Word16 sxi) +/*-------------------------------------------------------------------* + * cplxMult() + * + * Conduct complex multiplication + *--------------------------------------------------------------------*/ +static void cplxMult( + float *yr, /* o : real output */ + float *yi, /* o : imag output */ + float xr, /* i : real input 1*/ + float xi, /* i : imag input 1*/ + float cr, /* i : real input 1*/ + float ci /* i : imag input 1*/ +) { - Word32 zr, zi; + *yr = xr*cr - xi*ci; + *yi = xr*ci + xi*cr; - cplxMpyS(yr,yi,xr,xi,cr,ci,syr,syi,sxr,sxi,zr,zi); - cplxMpyS(yr,yi,xr,xi,cr,ci,syr,syi,sxr,sxi,zr,zi); - cplxMpyS(yr,yi,xr,xi,cr,ci,syr,syi,sxr,sxi,zr,zi); - cplxMpyS(yr,yi,xr,xi,cr,ci,syr,syi,sxr,sxi,zr,zi); - cplxMpyS(yr,yi,xr,xi,cr,ci,syr,syi,sxr,sxi,zr,zi); -} - -static void cplxMult16(Word32 *yr, Word32 *yi, Word32 *xr, Word32 *xi, const Word16 *cr, const Word16 *ci, Word16 syr, Word16 syi, Word16 sxr, Word16 sxi) -{ - Word32 zr, zi; - - cplxMpyS(yr,yi,xr,xi,cr,ci,syr,syi,sxr,sxi,zr,zi); - cplxMpyS(yr,yi,xr,xi,cr,ci,syr,syi,sxr,sxi,zr,zi); - cplxMpyS(yr,yi,xr,xi,cr,ci,syr,syi,sxr,sxi,zr,zi); - cplxMpyS(yr,yi,xr,xi,cr,ci,syr,syi,sxr,sxi,zr,zi); - cplxMpyS(yr,yi,xr,xi,cr,ci,syr,syi,sxr,sxi,zr,zi); - cplxMpyS(yr,yi,xr,xi,cr,ci,syr,syi,sxr,sxi,zr,zi); - cplxMpyS(yr,yi,xr,xi,cr,ci,syr,syi,sxr,sxi,zr,zi); - cplxMpyS(yr,yi,xr,xi,cr,ci,syr,syi,sxr,sxi,zr,zi); -} - -static void cplxMult20(Word32 *yr, Word32 *yi, Word32 *xr, Word32 *xi, const Word16 *cr, const Word16 *ci, Word16 syr, Word16 syi, Word16 sxr, Word16 sxi) -{ - cplxMult10(&yr[0*N10*syr], &yi[0*N10*syi], &xr[0*N10*sxr], &xi[0*N10*sxi], &cr[0*N10], &ci[0*N10], syr, syi, sxr, sxi); - cplxMult10(&yr[1*N10*syr], &yi[1*N10*syi], &xr[1*N10*sxr], &xi[1*N10*sxi], &cr[1*N10], &ci[1*N10], syr, syi, sxr, sxi); -} - -static void cplxMult30(Word32 *yr, Word32 *yi, Word32 *xr, Word32 *xi, const Word16 *cr, const Word16 *ci, Word16 syr, Word16 syi, Word16 sxr, Word16 sxi) -{ - cplxMult10(&yr[0*N10*syr], &yi[0*N10*syi], &xr[0*N10*sxr], &xi[0*N10*sxi], &cr[0*N10], &ci[0*N10], syr, syi, sxr, sxi); - cplxMult10(&yr[1*N10*syr], &yi[1*N10*syi], &xr[1*N10*sxr], &xi[1*N10*sxi], &cr[1*N10], &ci[1*N10], syr, syi, sxr, sxi); - cplxMult10(&yr[2*N10*syr], &yi[2*N10*syi], &xr[2*N10*sxr], &xi[2*N10*sxi], &cr[2*N10], &ci[2*N10], syr, syi, sxr, sxi); -} - -static void cplxMult32(Word32 *yr, Word32 *yi, Word32 *xr, Word32 *xi, const Word16 *cr, const Word16 *ci, Word16 syr, Word16 syi, Word16 sxr, Word16 sxi) -{ - cplxMult16(&yr[0*N16*syr], &yi[0*N16*syi], &xr[0*N16*sxr], &xi[0*N16*sxi], &cr[0*N16], &ci[0*N16], syr, syi, sxr, sxi); - cplxMult16(&yr[1*N16*syr], &yi[1*N16*syi], &xr[1*N16*sxr], &xi[1*N16*sxi], &cr[1*N16], &ci[1*N16], syr, syi, sxr, sxi); -} - -static void cplxMult40(Word32 *yr, Word32 *yi, Word32 *xr, Word32 *xi, const Word16 *cr, const Word16 *ci, Word16 syr, Word16 syi, Word16 sxr, Word16 sxi) -{ - cplxMult20(&yr[0*N20*syr], &yi[0*N20*syi], &xr[0*N20*sxr], &xi[0*N20*sxi], &cr[0*N20], &ci[0*N20], syr, syi, sxr, sxi); - cplxMult20(&yr[1*N20*syr], &yi[1*N20*syi], &xr[1*N20*sxr], &xi[1*N20*sxi], &cr[1*N20], &ci[1*N20], syr, syi, sxr, sxi); -} - -static void cplxMult60(Word32 *yr, Word32 *yi, Word32 *xr, Word32 *xi, const Word16 *cr, const Word16 *ci, Word16 syr, Word16 syi, Word16 sxr, Word16 sxi) -{ - cplxMult30(&yr[0*N30*syr], &yi[0*N30*syi], &xr[0*N30*sxr], &xi[0*N30*sxi], &cr[0*N30], &ci[0*N30], syr, syi, sxr, sxi); - cplxMult30(&yr[1*N30*syr], &yi[1*N30*syi], &xr[1*N30*sxr], &xi[1*N30*sxi], &cr[1*N30], &ci[1*N30], syr, syi, sxr, sxi); -} - -static void cplxMultAdd10_1(Word16 *rY1, Word16 *rY2, Word16 *rY3, Word16 *rY4, - Word32 *rXR, Word32 *rXI, Word32 *iXR, Word32 *iXI, - const Word16 *cr, const Word16 *ci, Word16 gv, Word16 s, - Word16 sx, Word16 sr) -{ - Word32 rr12, ri12, ir12, ii12; - - cplxMpy(rr12, ri12, ir12, ii12, rXR, rXI, iXR, iXI, cr, ci, gv, sx, sr); - add1(rY1, rY2, rY3, rY4, rr12, ri12, ir12, ii12, s); - cplxMpy(rr12, ri12, ir12, ii12, rXR, rXI, iXR, iXI, cr, ci, gv, sx, sr); - add1(rY1, rY2, rY3, rY4, rr12, ri12, ir12, ii12, s); -} - -static void cplxMultAdd10_2(Word16 *rY1, Word16 *rY2, Word16 *rY3, Word16 *rY4, - Word32 *rXR, Word32 *rXI, Word32 *iXR, Word32 *iXI, - const Word16 *cr, const Word16 *ci, Word16 gv, Word16 s, - Word16 sx, Word16 sr) -{ - Word32 rr12, ri12, ir12, ii12; - - cplxMpy(rr12, ri12, ir12, ii12, rXR, rXI, iXR, iXI, cr, ci, gv, sx, sr); - add2(rY1, rY2, rY3, rY4, rr12, ri12, ir12, ii12, s); - cplxMpy(rr12, ri12, ir12, ii12, rXR, rXI, iXR, iXI, cr, ci, gv, sx, sr); - add2(rY1, rY2, rY3, rY4, rr12, ri12, ir12, ii12, s); - cplxMpy(rr12, ri12, ir12, ii12, rXR, rXI, iXR, iXI, cr, ci, gv, sx, sr); - add2(rY1, rY2, rY3, rY4, rr12, ri12, ir12, ii12, s); + return; } -static void cplxMultAdd20_1(Word16 *rY1, Word16 *rY2, Word16 *rY3, Word16 *rY4, - Word32 *rXR, Word32 *rXI, Word32 *iXR, Word32 *iXI, - const Word16 *cr, const Word16 *ci, Word16 gv, Word16 s, - Word16 sx, Word16 sr) +/*-------------------------------------------------------------------* + * cldfbAnalysis() + * + * Conduct multple overlap cmplex low delay MDCT + *--------------------------------------------------------------------*/ +void cldfbAnalysis( + const float *timeIn, /* i : time buffer */ + float **realBuffer, /* o : real value buffer */ + float **imagBuffer, /* o : imag value buffer */ + int samplesToProcess, /* i : samples to process */ + HANDLE_CLDFB_FILTER_BANK h_cldfb /* i : filterbank state */ +) { - Word32 rr12, ri12, ir12, ii12; + short i, k; + short L2, M1, M2, M4; + short no_col = h_cldfb->no_col; - cplxMpy(rr12, ri12, ir12, ii12, rXR, rXI, iXR, iXI, cr, ci, gv, sx, sr); - add1(rY1, rY2, rY3, rY4, rr12, ri12, ir12, ii12, s); - cplxMpy(rr12, ri12, ir12, ii12, rXR, rXI, iXR, iXI, cr, ci, gv, sx, sr); - add1(rY1, rY2, rY3, rY4, rr12, ri12, ir12, ii12, s); - cplxMpy(rr12, ri12, ir12, ii12, rXR, rXI, iXR, iXI, cr, ci, gv, sx, sr); - add1(rY1, rY2, rY3, rY4, rr12, ri12, ir12, ii12, s); - cplxMpy(rr12, ri12, ir12, ii12, rXR, rXI, iXR, iXI, cr, ci, gv, sx, sr); - add1(rY1, rY2, rY3, rY4, rr12, ri12, ir12, ii12, s); - cplxMpy(rr12, ri12, ir12, ii12, rXR, rXI, iXR, iXI, cr, ci, gv, sx, sr); - add1(rY1, rY2, rY3, rY4, rr12, ri12, ir12, ii12, s); -} + float r1, r2, rr12, ir12; + float i1, i2, ri12, ii12; + float rBuffer[2*CLDFB_NO_CHANNELS_MAX]; + float iBuffer[2*CLDFB_NO_CHANNELS_MAX]; + const float *rot_vctr_re; + const float *rot_vctr_im; + const float *ptr_pf; + float *timeBuffer = h_cldfb->cldfb_state; + int offset = h_cldfb->p_filter_length - h_cldfb->no_channels; + int frameSize = h_cldfb->no_channels * h_cldfb->no_col; -static void cplxMultAdd20_2(Word16 *rY1, Word16 *rY2, Word16 *rY3, Word16 *rY4, - Word32 *rXR, Word32 *rXI, Word32 *iXR, Word32 *iXI, - const Word16 *cr, const Word16 *ci, Word16 gv, Word16 s, - Word16 sx, Word16 sr) -{ - Word32 rr12, ri12, ir12, ii12; + /* prepare input buffer */ + mvr2r( timeBuffer + frameSize, timeBuffer, offset ); - cplxMpy(rr12, ri12, ir12, ii12, rXR, rXI, iXR, iXI, cr, ci, gv, sx, sr); - add2(rY1, rY2, rY3, rY4, rr12, ri12, ir12, ii12, s); - cplxMpy(rr12, ri12, ir12, ii12, rXR, rXI, iXR, iXI, cr, ci, gv, sx, sr); - add2(rY1, rY2, rY3, rY4, rr12, ri12, ir12, ii12, s); - cplxMpy(rr12, ri12, ir12, ii12, rXR, rXI, iXR, iXI, cr, ci, gv, sx, sr); - add2(rY1, rY2, rY3, rY4, rr12, ri12, ir12, ii12, s); - cplxMpy(rr12, ri12, ir12, ii12, rXR, rXI, iXR, iXI, cr, ci, gv, sx, sr); - add2(rY1, rY2, rY3, rY4, rr12, ri12, ir12, ii12, s); - cplxMpy(rr12, ri12, ir12, ii12, rXR, rXI, iXR, iXI, cr, ci, gv, sx, sr); - add2(rY1, rY2, rY3, rY4, rr12, ri12, ir12, ii12, s); -} - -/* calcModulation - - Parameters: - *rYR O: pointer to real output samples (DST) - *rYI O: pointer to imaginary output samples (DST) - *rXR I: pointer to real input samples (DST) - *rXI I: pointer to imaginary input samples (DST) - srYR I: offset for update of pointer to real output samples (DST) - srYI I: offset for update of pointer to imaginary output samples (DST) - srXR I: offset for update of pointer to real input samples (DST) - srXI I: offset for update of pointer to imaginary input samples (DST) - *iYR O: pointer to real output samples (DCT) - *iYI O: pointer to imaginary output samples (DCT) - *iXR I: pointer to real input samples (DCT) - *iXI I: pointer to imaginary input samples (DCT) - siYR I: offset for update of pointer to real output samples (DCT) - siYI I: offset for update of pointer to imaginary output samples (DCT) - siXR I: offset for update of pointer to real input samples (DCT) - siXI I: offset for update of pointer to imaginary input samples (DCT) - m I: processed cldfb bands - - Function: - The function applies for each cldfb length a unrolled complex modulation - - Returns: - void -*/ -static void calcModulation( Word32 *rYR, - Word32 *rYI, - Word32 *rXR, - Word32 *rXI, - Word16 srYR, - Word16 srYI, - Word16 srXR, - Word16 srXI, - Word32 *iYR, - Word32 *iYI, - Word32 *iXR, - Word32 *iXI, - Word16 siYR, - Word16 siYI, - Word16 siXR, - Word16 siXI, - const Word16 *rRotVctr, - const Word16 *iRotVctr, - Word16 m - ) -{ - - SWITCH (m) + if( samplesToProcess > -1 ) { - case 10: - cplxMult10(rYR, rYI, rXR, rXI, rRotVctr, iRotVctr, srYR, srYI, srXR, srXI); - cplxMult10(iYR, iYI, iXR, iXI, rRotVctr, iRotVctr, siYR, siYI, siXR, siXI); - BREAK; - case 16: - cplxMult16(rYR, rYI, rXR, rXI, rRotVctr, iRotVctr, srYR, srYI, srXR, srXI); - cplxMult16(iYR, iYI, iXR, iXI, rRotVctr, iRotVctr, siYR, siYI, siXR, siXI); - BREAK; - case 20: - cplxMult20(rYR, rYI, rXR, rXI, rRotVctr, iRotVctr, srYR, srYI, srXR, srXI); - cplxMult20(iYR, iYI, iXR, iXI, rRotVctr, iRotVctr, siYR, siYI, siXR, siXI); - BREAK; - case 32: - cplxMult32(rYR, rYI, rXR, rXI, rRotVctr, iRotVctr, srYR, srYI, srXR, srXI); - cplxMult32(iYR, iYI, iXR, iXI, rRotVctr, iRotVctr, siYR, siYI, siXR, siXI); - BREAK; - case 40: - cplxMult40(rYR, rYI, rXR, rXI, rRotVctr, iRotVctr, srYR, srYI, srXR, srXI); - cplxMult40(iYR, iYI, iXR, iXI, rRotVctr, iRotVctr, siYR, siYI, siXR, siXI); - BREAK; - case 60: - cplxMult60(rYR, rYI, rXR, rXI, rRotVctr, iRotVctr, srYR, srYI, srXR, srXI); - cplxMult60(iYR, iYI, iXR, iXI, rRotVctr, iRotVctr, siYR, siYI, siXR, siXI); - BREAK; - default: - assert(0); + mvr2r( timeIn, timeBuffer + offset, samplesToProcess ); + set_f( timeBuffer+offset+samplesToProcess, 0.0f, (frameSize-samplesToProcess) ); + } + else + { + mvr2r( timeIn, timeBuffer + offset, frameSize ); } -} - - -/* calcModulationAndFolding - - Parameters: - *rY O: pointer to folded samples (DST + DCT) - *rX I: pointer to real input samples (DST) - *iX I: pointer to imaginary input samples (DCT) - *rRotVctr I: pointer to real modulation coefficients - *iRotVctr I: pointer to imaginary modulation coefficients - gain I: gain value - scale I: scale factor - m I: processed cldfb bands - m2 I: half of processed cldfb bands - - Function: - The function applies for each cldfb length a unrolled complex modulation with subsequent data folding - - Returns: - void -*/ -static void calcModulationAndFolding( Word16 *rY, - Word32 *rX, - Word32 *iX, - const Word16 *rRotVctr, - const Word16 *iRotVctr, - Word16 gain, - Word16 scale, - Word16 m, - Word16 m2 - ) -{ - Word16 *y11, *y12, *y13, *y14; - Word16 *y21, *y22, *y23, *y24; - Word32 *x11, *x12, *x13, *x14; - Word32 *x21, *x22, *x23, *x24; - const Word16 *r11, *r12, *r21, *r22; - - - - y11 = &rY[m+m2+1]; - y12 = &rY[m2-2]; - y13 = &rY[m+m2-2]; - y14 = &rY[m2+1]; - - y21 = &rY[m+m2]; - y22 = &rY[m2-1]; - y23 = &rY[m+m2-1]; - y24 = &rY[m2]; - - x11 = &rX[m-2]; - x12 = &rX[m-1]; - x13 = &iX[m-2]; - x14 = &iX[m-1]; - x21 = &rX[0]; - x22 = &rX[1]; - x23 = &iX[0]; - x24 = &iX[1]; - - r11 = &rRotVctr[m2-1]; - r12 = &iRotVctr[m2-1]; - r21 = &rRotVctr[0]; - r22 = &iRotVctr[0]; - - SWITCH (m) + /* only process needed cols */ + if( samplesToProcess > -1 ) { - case 10: - cplxMultAdd10_1(y11, y12, y13, y14, x11, x12, x13, x14, r11, r12, gain, scale, -2, -1); - cplxMultAdd10_2(y21, y22, y23, y24, x21, x22, x23, x24, r21, r22, gain, scale, 2, 1); - BREAK; - case 20: - cplxMultAdd20_1(y11, y12, y13, y14, x11, x12, x13, x14, r11, r12, gain, scale, -2, -1); - cplxMultAdd20_2(y21, y22, y23, y24, x21, x22, x23, x24, r21, r22, gain, scale, 2, 1); - BREAK; - case 60: - cplxMultAdd20_1(y11, y12, y13, y14, x11, x12, x13, x14, r11, r12, gain, scale, -2, -1); - cplxMultAdd20_2(y21, y22, y23, y24, x21, x22, x23, x24, r21, r22, gain, scale, 2, 1); - ptrUpdate20(y11,y12,y13,y14,r11,x11,x12,x13,x14,r12,y21,y22,y23,y24,r21,x21,x22,x23,x24,r22); - /* no break */ - case 40: - cplxMultAdd20_1(y11, y12, y13, y14, x11, x12, x13, x14, r11, r12, gain, scale, -2, -1); - cplxMultAdd20_2(y21, y22, y23, y24, x21, x22, x23, x24, r21, r22, gain, scale, 2, 1); - ptrUpdate20(y11,y12,y13,y14,r11,x11,x12,x13,x14,r12,y21,y22,y23,y24,r21,x21,x22,x23,x24,r22); - cplxMultAdd20_1(y11, y12, y13, y14, x11, x12, x13, x14, r11, r12, gain, scale, -2, -1); - cplxMultAdd20_2(y21, y22, y23, y24, x21, x22, x23, x24, r21, r22, gain, scale, 2, 1); - ptrUpdate20(y11,y12,y13,y14,r11,x11,x12,x13,x14,r12,y21,y22,y23,y24,r21,x21,x22,x23,x24,r22); - BREAK; - default: - assert(0); + no_col = min(no_col, (samplesToProcess + h_cldfb->no_channels - 1) / h_cldfb->no_channels); } -} + M1 = h_cldfb->no_channels; + M2 = M1 >> 1; + M4 = M1 >> 2; + L2 = M1 << 1; - -/* cldfbAnalysisFiltering - - Parameters: - cldfbBank I/O: handle to analysis CLDFB filter struct - **rAnalysis O: matrix holding the real part of the subband samples - **iAnalysis O: matrix holding the imaginary part of the subband samples - *scaleFactor O: pointer to cldfb scalefactor struct - *timeIn I: pointer to time domain data - stride I: stride for time domain data - *pWorkBuffer I: pointer to scratch buffer, needed for buffer of size 2*cldfbbands*Word32 - - Function: - Performs complex-valued subband filtering of the time domain data of timeIn and stores the real - part of the subband samples in rAnalysis, and the imaginary part in iAnalysis - - Returns: - void -*/ -void cldfbAnalysisFiltering( HANDLE_CLDFB_FILTER_BANK cldfbBank, - Word32 **rAnalysis, - Word32 **iAnalysis, - CLDFB_SCALE_FACTOR *scaleFactor, - const Word16 *timeIn, - const Word16 timeIn_e, - const Word16 nTimeSlots, - Word32 *pWorkBuffer - ) - -{ - Word16 i,k; - Word16 L2,L3,L4,m,m2,M4; - Word16 M0M2,M2M1,L3M1,L4M1; - Word16 scale; - Word16 offset; - Word16 p_stride; - Word16 nSamples; - Word16 nSamplesUpd; - Word16 stride; - - Word32 r1,r2; - Word32 i1,i2; - Word32 *rBuffer; - Word32 *iBuffer; - Word16 *pStates; - - Word16 *pStates1; - Word16 *pStates2; - Word16 *pStates3; - Word16 *pStates4; - Word16 *pStates6; - Word16 *pStates5; - - const Word16 *rRotVctr; - const Word16 *iRotVctr; - const Word16 *pFilter; - - const Word16 *pFilter1; - const Word16 *pFilter2; - const Word16 *pFilter3; - const Word16 *pFilter4; - const Word16 *pFilter6; - const Word16 *pFilter5; - Word32 workBuffer[2*BASOP_CFFT_MAX_LENGTH]; - - - - stride = 1; /* constant */ - m = cldfbBank->no_channels; - move16(); - L2 = shl(m,1); - m2 = shr(m,1); - M4 = shr(m,2); - M4 = sub(m2,M4); - - L3 = sub(L2,m2); - L4 = add(L2,m2); - - M0M2 = sub(0,m2); - M2M1 = sub(m2,1); - L3M1 = sub(L3,1); - L4M1 = sub(L4,1); - - rBuffer = &pWorkBuffer[0]; - iBuffer = &pWorkBuffer[m]; - - rRotVctr = cldfbBank->rRotVctr; - iRotVctr = cldfbBank->iRotVctr; - - pStates = cldfbBank->FilterStates; - pStates1 = &pStates[L3M1]; - pStates2 = &pStates[L3]; - pStates3 = &pStates[m2]; - pStates4 = &pStates[M2M1]; - pStates5 = &pStates[L4M1]; - pStates6 = &pStates[M0M2]; - - p_stride = CLDFB_NO_POLY; - pFilter = &cldfbBank->p_filter[p_stride - CLDFB_NO_POLY]; - pFilter1 = &pFilter[p_stride*L3M1]; - pFilter2 = &pFilter[p_stride*L3]; - pFilter3 = &pFilter[p_stride*m2]; - pFilter4 = &pFilter[p_stride*M2M1]; - pFilter5 = &pFilter[p_stride*L4M1]; - pFilter6 = &pFilter[p_stride*M0M2]; - - nSamples = i_mult(nTimeSlots, cldfbBank->no_channels); - nSamplesUpd = i_mult(cldfbBank->no_col, cldfbBank->no_channels); - offset = sub(sub(cldfbBank->p_filter_length, cldfbBank->no_channels),cldfbBank->zeros); - - /* Determine states scale */ - scale = -15; - move16(); - k = 0; - move16(); - FOR (i=0; ino_channels) + if( M2 & 1 ) { - cldfbBank->FilterStates_e[k] = cldfbBank->FilterStates_e[k+cldfbBank->no_col]; - move16(); - assert((size_t)k < sizeof(cldfbBank->FilterStates_e)/sizeof(cldfbBank->FilterStates_e[0])); - scale = s_max(scale, cldfbBank->FilterStates_e[k]); - k = add(k,1); - } - FOR (i=0; ino_channels) - { - cldfbBank->FilterStates_e[k] = timeIn_e; - move16(); - assert((size_t)k < sizeof(cldfbBank->FilterStates_e)/sizeof(cldfbBank->FilterStates_e[0])); - scale = s_max(scale, cldfbBank->FilterStates_e[k]); - k = add(k,1); - } - i = s_max(scale, timeIn_e); - scale = sub(cldfbBank->FilterStates_eg, i); - cldfbBank->FilterStates_eg = i; - move16(); - - /* if nTimeSlots==0, make sure we have a value. */ - scaleFactor->lb_scale = add(cldfbBank->anaScalefactor, add(cldfbBank->FilterStates_eg, 5)); - move16(); - - /* move and scale filter states */ - FOR (i=0; iFilterStates_eg); - FOR (i=0; irot_vec_ana_re; + rot_vctr_im = h_cldfb->rot_vec_ana_im; - FOR (k=0; k < nTimeSlots; k++) + ptr_pf = h_cldfb->p_filter; + + for( i = 0; i < no_col; i++ ) { - FOR (i=0; i < M4; i++) + for (k=0; k < M4; k++ ) { /* prototype filter */ - r1 = L_msu0(0 , pFilter1[0 - p_stride * 2 * i], pStates1[0 * L2 - 2 * i]); - r1 = L_msu0(r1, pFilter1[1 - p_stride * 2 * i], pStates1[1 * L2 - 2 * i]); - r1 = L_msu0(r1, pFilter1[2 - p_stride * 2 * i], pStates1[2 * L2 - 2 * i]); - r1 = L_msu0(r1, pFilter1[3 - p_stride * 2 * i], pStates1[3 * L2 - 2 * i]); - r1 = L_msu0(r1, pFilter1[4 - p_stride * 2 * i], pStates1[4 * L2 - 2 * i]); + r1 = 0 - ptr_pf[(L2-M2-1-(2*k) + 0 * L2)] * timeBuffer[L2-M2-1-(2*k) + 0 * L2]; + r1 = r1 - ptr_pf[(L2-M2-1-(2*k) + 1 * L2)] * timeBuffer[L2-M2-1-(2*k) + 1 * L2]; + r1 = r1 - ptr_pf[(L2-M2-1-(2*k) + 2 * L2)] * timeBuffer[L2-M2-1-(2*k) + 2 * L2]; + r1 = r1 - ptr_pf[(L2-M2-1-(2*k) + 3 * L2)] * timeBuffer[L2-M2-1-(2*k) + 3 * L2]; + r1 = r1 - ptr_pf[(L2-M2-1-(2*k) + 4 * L2)] * timeBuffer[L2-M2-1-(2*k) + 4 * L2]; - r2 = L_msu0(0 , pFilter2[0 + p_stride * 2 * i], pStates2[0 * L2 + 2 * i]); - r2 = L_msu0(r2, pFilter2[1 + p_stride * 2 * i], pStates2[1 * L2 + 2 * i]); - r2 = L_msu0(r2, pFilter2[2 + p_stride * 2 * i], pStates2[2 * L2 + 2 * i]); - r2 = L_msu0(r2, pFilter2[3 + p_stride * 2 * i], pStates2[3 * L2 + 2 * i]); - r2 = L_msu0(r2, pFilter2[4 + p_stride * 2 * i], pStates2[4 * L2 + 2 * i]); + r2 = 0 - ptr_pf[(L2-M2+(2*k) + 0 * L2)] * timeBuffer[L2-M2+(2*k) + 0 * L2]; + r2 = r2 - ptr_pf[(L2-M2+(2*k) + 1 * L2)] * timeBuffer[L2-M2+(2*k) + 1 * L2]; + r2 = r2 - ptr_pf[(L2-M2+(2*k) + 2 * L2)] * timeBuffer[L2-M2+(2*k) + 2 * L2]; + r2 = r2 - ptr_pf[(L2-M2+(2*k) + 3 * L2)] * timeBuffer[L2-M2+(2*k) + 3 * L2]; + r2 = r2 - ptr_pf[(L2-M2+(2*k) + 4 * L2)] * timeBuffer[L2-M2+(2*k) + 4 * L2]; - i1 = L_msu0(0 , pFilter3[0 + p_stride * 2 * i], pStates3[0 * L2 + 2 * i]); - i1 = L_msu0(i1, pFilter3[1 + p_stride * 2 * i], pStates3[1 * L2 + 2 * i]); - i1 = L_msu0(i1, pFilter3[2 + p_stride * 2 * i], pStates3[2 * L2 + 2 * i]); - i1 = L_msu0(i1, pFilter3[3 + p_stride * 2 * i], pStates3[3 * L2 + 2 * i]); - i1 = L_msu0(i1, pFilter3[4 + p_stride * 2 * i], pStates3[4 * L2 + 2 * i]); + i1 = 0 - ptr_pf[(L2-3*M2+(2*k) + 0 * L2)] * timeBuffer[L2-3*M2+(2*k) + 0 * L2]; + i1 = i1 - ptr_pf[(L2-3*M2+(2*k) + 1 * L2)] * timeBuffer[L2-3*M2+(2*k) + 1 * L2]; + i1 = i1 - ptr_pf[(L2-3*M2+(2*k) + 2 * L2)] * timeBuffer[L2-3*M2+(2*k) + 2 * L2]; + i1 = i1 - ptr_pf[(L2-3*M2+(2*k) + 3 * L2)] * timeBuffer[L2-3*M2+(2*k) + 3 * L2]; + i1 = i1 - ptr_pf[(L2-3*M2+(2*k) + 4 * L2)] * timeBuffer[L2-3*M2+(2*k) + 4 * L2]; - i2 = L_msu0(0 , pFilter4[0 - p_stride * 2 * i], pStates4[0 * L2 - 2 * i]); - i2 = L_msu0(i2, pFilter4[1 - p_stride * 2 * i], pStates4[1 * L2 - 2 * i]); - i2 = L_msu0(i2, pFilter4[2 - p_stride * 2 * i], pStates4[2 * L2 - 2 * i]); - i2 = L_msu0(i2, pFilter4[3 - p_stride * 2 * i], pStates4[3 * L2 - 2 * i]); - i2 = L_msu0(i2, pFilter4[4 - p_stride * 2 * i], pStates4[4 * L2 - 2 * i]); + i2 = 0 - ptr_pf[(L2-3*M2-1-(2*k) + 0 * L2)] * timeBuffer[L2-3*M2-1-(2*k) + 0 * L2]; + i2 = i2 - ptr_pf[(L2-3*M2-1-(2*k) + 1 * L2)] * timeBuffer[L2-3*M2-1-(2*k) + 1 * L2]; + i2 = i2 - ptr_pf[(L2-3*M2-1-(2*k) + 2 * L2)] * timeBuffer[L2-3*M2-1-(2*k) + 2 * L2]; + i2 = i2 - ptr_pf[(L2-3*M2-1-(2*k) + 3 * L2)] * timeBuffer[L2-3*M2-1-(2*k) + 3 * L2]; + i2 = i2 - ptr_pf[(L2-3*M2-1-(2*k) + 4 * L2)] * timeBuffer[L2-3*M2-1-(2*k) + 4 * L2]; - /* folding */ - rBuffer[2*i] = L_sub(r1,r2); - move32(); - rBuffer[2*i+1] = L_negate(L_add(i1,i2)); - move32(); + /* folding + pre modulation of DST IV */ + rr12 = r1 - r2; + ri12 = -i1 - i2; + cplxMult(&rBuffer[2*k],&rBuffer[2*k+1],rr12,ri12,rot_vctr_re[k],rot_vctr_im[k]); - /* folding */ - iBuffer[2*i] = L_add(r1,r2); - move32(); - iBuffer[2*i+1] = L_sub(i1,i2); - move32(); + /* folding + pre modulation of DCT IV */ + ir12 = r1 + r2; + ii12 = i1 - i2; + cplxMult(&iBuffer[2*k],&iBuffer[2*k+1],ir12,ii12,rot_vctr_re[k],rot_vctr_im[k]); } - FOR (i=M4; i < m2; i++) + for (k=M4; k < M2; k++) { /* prototype filter */ - r1 = L_msu0(0 , pFilter1[0 - p_stride * 2 * i], pStates1[0 * L2 - 2 * i]); - r1 = L_msu0(r1, pFilter1[1 - p_stride * 2 * i], pStates1[1 * L2 - 2 * i]); - r1 = L_msu0(r1, pFilter1[2 - p_stride * 2 * i], pStates1[2 * L2 - 2 * i]); - r1 = L_msu0(r1, pFilter1[3 - p_stride * 2 * i], pStates1[3 * L2 - 2 * i]); - r1 = L_msu0(r1, pFilter1[4 - p_stride * 2 * i], pStates1[4 * L2 - 2 * i]); + r1 = 0 - ptr_pf[(L2-M2-1-(2*k) + 0 * L2)] * timeBuffer[L2-M2-1-(2*k) + 0 * L2]; + r1 = r1 - ptr_pf[(L2-M2-1-(2*k) + 1 * L2)] * timeBuffer[L2-M2-1-(2*k) + 1 * L2]; + r1 = r1 - ptr_pf[(L2-M2-1-(2*k) + 2 * L2)] * timeBuffer[L2-M2-1-(2*k) + 2 * L2]; + r1 = r1 - ptr_pf[(L2-M2-1-(2*k) + 3 * L2)] * timeBuffer[L2-M2-1-(2*k) + 3 * L2]; + r1 = r1 - ptr_pf[(L2-M2-1-(2*k) + 4 * L2)] * timeBuffer[L2-M2-1-(2*k) + 4 * L2]; - r2 = L_msu0(0 , pFilter6[0 + p_stride * 2 * i], pStates6[0 * L2 + 2 * i]); - r2 = L_msu0(r2, pFilter6[1 + p_stride * 2 * i], pStates6[1 * L2 + 2 * i]); - r2 = L_msu0(r2, pFilter6[2 + p_stride * 2 * i], pStates6[2 * L2 + 2 * i]); - r2 = L_msu0(r2, pFilter6[3 + p_stride * 2 * i], pStates6[3 * L2 + 2 * i]); - r2 = L_msu0(r2, pFilter6[4 + p_stride * 2 * i], pStates6[4 * L2 + 2 * i]); + r2 = 0 - ptr_pf[(L2-5*M2+(2*k) + 0 * L2)] * timeBuffer[L2-5*M2+(2*k) + 0 * L2]; + r2 = r2 - ptr_pf[(L2-5*M2+(2*k) + 1 * L2)] * timeBuffer[L2-5*M2+(2*k) + 1 * L2]; + r2 = r2 - ptr_pf[(L2-5*M2+(2*k) + 2 * L2)] * timeBuffer[L2-5*M2+(2*k) + 2 * L2]; + r2 = r2 - ptr_pf[(L2-5*M2+(2*k) + 3 * L2)] * timeBuffer[L2-5*M2+(2*k) + 3 * L2]; + r2 = r2 - ptr_pf[(L2-5*M2+(2*k) + 4 * L2)] * timeBuffer[L2-5*M2+(2*k) + 4 * L2]; - i1 = L_msu0(0 , pFilter5[0 - p_stride * 2 * i], pStates5[0 * L2 - 2 * i]); - i1 = L_msu0(i1, pFilter5[1 - p_stride * 2 * i], pStates5[1 * L2 - 2 * i]); - i1 = L_msu0(i1, pFilter5[2 - p_stride * 2 * i], pStates5[2 * L2 - 2 * i]); - i1 = L_msu0(i1, pFilter5[3 - p_stride * 2 * i], pStates5[3 * L2 - 2 * i]); - i1 = L_msu0(i1, pFilter5[4 - p_stride * 2 * i], pStates5[4 * L2 - 2 * i]); + i1 = 0 - ptr_pf[(L2+M2-1-(2*k) + 0 * L2)] * timeBuffer[L2+M2-1-(2*k) + 0 * L2]; + i1 = i1 - ptr_pf[(L2+M2-1-(2*k) + 1 * L2)] * timeBuffer[L2+M2-1-(2*k) + 1 * L2]; + i1 = i1 - ptr_pf[(L2+M2-1-(2*k) + 2 * L2)] * timeBuffer[L2+M2-1-(2*k) + 2 * L2]; + i1 = i1 - ptr_pf[(L2+M2-1-(2*k) + 3 * L2)] * timeBuffer[L2+M2-1-(2*k) + 3 * L2]; + i1 = i1 - ptr_pf[(L2+M2-1-(2*k) + 4 * L2)] * timeBuffer[L2+M2-1-(2*k) + 4 * L2]; - i2 = L_msu0(0 , pFilter3[0 + p_stride * 2 * i], pStates3[0 * L2 + 2 * i]); - i2 = L_msu0(i2, pFilter3[1 + p_stride * 2 * i], pStates3[1 * L2 + 2 * i]); - i2 = L_msu0(i2, pFilter3[2 + p_stride * 2 * i], pStates3[2 * L2 + 2 * i]); - i2 = L_msu0(i2, pFilter3[3 + p_stride * 2 * i], pStates3[3 * L2 + 2 * i]); - i2 = L_msu0(i2, pFilter3[4 + p_stride * 2 * i], pStates3[4 * L2 + 2 * i]); + i2 = 0 - ptr_pf[(L2-3*M2+(2*k) + 0 * L2)] * timeBuffer[L2-3*M2+(2*k) + 0 * L2]; + i2 = i2 - ptr_pf[(L2-3*M2+(2*k) + 1 * L2)] * timeBuffer[L2-3*M2+(2*k) + 1 * L2]; + i2 = i2 - ptr_pf[(L2-3*M2+(2*k) + 2 * L2)] * timeBuffer[L2-3*M2+(2*k) + 2 * L2]; + i2 = i2 - ptr_pf[(L2-3*M2+(2*k) + 3 * L2)] * timeBuffer[L2-3*M2+(2*k) + 3 * L2]; + i2 = i2 - ptr_pf[(L2-3*M2+(2*k) + 4 * L2)] * timeBuffer[L2-3*M2+(2*k) + 4 * L2]; - /* folding */ - rBuffer[2*i] = L_add(r1,r2); - move32(); - rBuffer[2*i+1] = L_sub(i1,i2); - move32(); + /* folding + pre modulation of DST IV */ + rr12 = r1 + r2; + ri12 = i1 - i2; + cplxMult(&rBuffer[2*k],&rBuffer[2*k+1],rr12,ri12,rot_vctr_re[k],rot_vctr_im[k]); - /* folding */ - iBuffer[2*i] = L_sub(r1,r2); - move32(); - iBuffer[2*i+1] = L_add(i1,i2); - move32(); + /* folding + pre modulation of DCT IV */ + ir12 = r1 - r2; + ii12 = i1 + i2; + cplxMult(&iBuffer[2*k],&iBuffer[2*k+1],ir12,ii12,rot_vctr_re[k],rot_vctr_im[k]); } - /* pre modulation of DST IV and DCT IV */ - calcModulation(&rBuffer[0], &rBuffer[1], &rBuffer[0], &rBuffer[1], 2, 2, 2, 2, - &iBuffer[0], &iBuffer[1], &iBuffer[0], &iBuffer[1], 2, 2, 2, 2, - rRotVctr, iRotVctr, m); - /* FFT of DST IV */ - scale = 0; - move16(); - BASOP_cfft(&rBuffer[0], &rBuffer[1], m2, 2, &scale, workBuffer); + fft_cldfb(rBuffer, M2); - /* store analysis scalefactor for cldfb */ - scaleFactor->lb_scale = add(cldfbBank->anaScalefactor, add(cldfbBank->FilterStates_eg, scale)); - move16(); + /* post modulation of DST IV */ + for (k=0; k < M2; k++) + { + cplxMult(&realBuffer[i][M1-1-(2*k)],&realBuffer[i][2*k],rBuffer[2*k],rBuffer[2*k+1],rot_vctr_re[k],rot_vctr_im[k]); + } /* FFT of DCT IV */ - BASOP_cfft(&iBuffer[0], &iBuffer[1], m2, 2, &scale, workBuffer); + fft_cldfb(iBuffer, M2); - /* post modulation of DST IV and DCT IV */ - calcModulation(&rAnalysis[k][m-1], &rAnalysis[k][0], &rBuffer[0], &rBuffer[1],-2, 2, 2, 2, - &iAnalysis[k][0], &iAnalysis[k][m-1], &iBuffer[0], &iBuffer[1], 2,-2, 2, 2, - rRotVctr, iRotVctr, m); + /* post modulation of DCT IV */ + for (k=0; k < M2; k++) + { + /* do it inplace */ + cplxMult(&imagBuffer[i][2*k],&imagBuffer[i][M1-1-(2*k)],iBuffer[2*k],iBuffer[2*k+1],rot_vctr_re[k],rot_vctr_im[k]); + } - - /* update states pointer */ - pStates1 = &pStates1[cldfbBank->no_channels]; - pStates2 = &pStates2[cldfbBank->no_channels]; - pStates3 = &pStates3[cldfbBank->no_channels]; - pStates5 = &pStates5[cldfbBank->no_channels]; - pStates4 = &pStates4[cldfbBank->no_channels]; - pStates6 = &pStates6[cldfbBank->no_channels]; + timeBuffer += L2 * 5; + timeBuffer += h_cldfb->no_channels - h_cldfb->p_filter_length; } + return; } -/* cldfbSynthesisFiltering - - Parameters: - cldfbBank I/O: handle to analysis CLDFB filter struct - **rAnalysis I: matrix holding the real part of the subband samples - **iAnalysis I: matrix holding the imaginary part of the subband samples - *scaleFactor I: pointer to cldfb scalefactor struct - ov_len I: determines overlapping area in time slots (obsolete) - *timeOut O: pointer to time domain data - stride I: stride for time domain data - *pWorkBuffer I: pointer to scratch buffer, needed for buffer of size 2*cldfbbands*Word32 + 2*cldfbbands*Word16 - - Function: - Performs inverse complex-valued subband filtering of the subband samples in rAnalysis and iAnalysis - and stores the time domain data in timeOut - - Returns: - void -*/ -void -cldfbSynthesisFiltering( HANDLE_CLDFB_FILTER_BANK cldfbBank, - Word32 **rAnalysis, - Word32 **iAnalysis, - const CLDFB_SCALE_FACTOR *scaleFactor, - Word16 *timeOut, - const Word16 timeOut_e, - const Word16 nTimeSlots, - Word32 *pWorkBuffer - ) +/*-------------------------------------------------------------------* + * cldfbSynthesis() + * + * Conduct inverse multple overlap cmplex low delay MDCT + *--------------------------------------------------------------------*/ +void cldfbSynthesis( + float **realBuffer, /* i : real values */ + float **imagBuffer, /* i : imag values */ + float *timeOut, /* o : output time domain samples */ + int samplesToProcess, /* i : number of processed samples */ + HANDLE_CLDFB_FILTER_BANK h_cldfb /* i : filter bank state */ +) { - Word16 i; - Word16 k; - Word16 L2; - Word16 m; - Word16 m2; - Word16 Lz; - Word16 Mz; - Word32 acc; - Word16 offset1; - Word16 offset2; - Word16 channels0; - Word16 channels1; - Word16 channels2; - Word16 channels3; - Word16 channels4; - Word16 statesSizeM1; - Word16 statesSizeM2; - Word16 stride; + int i; + int k; + int L2; + int M1; + int M2; + int M41; + int M42; + int Mz; - Word16 scale, scaleMod; - Word16 outScale; - Word16 scaleLB; - Word16 scaleHB; + float rBuffer[2*CLDFB_NO_CHANNELS_MAX]; + float iBuffer[2*CLDFB_NO_CHANNELS_MAX]; + const float *rot_vctr_re; + const float *rot_vctr_im; + float rr12, ir12; + float ri12, ii12; - Word32 *rAnalysisS; - Word32 *iAnalysisS; + float *synthesisBuffer; + float new_samples[2*CLDFB_NO_CHANNELS_MAX]; - Word32 *rBuffer; - Word32 *iBuffer; - Word16 *nBuffer; + float *ptr_time_out; + const float *p_filter; - Word16 *pStates; - Word16 *pStatesI; - Word16 *pStatesR; + float accu0, accu1, accu2, accu3, accu4; + int no_col = h_cldfb->no_col; - const Word16 *pFilterS; - const Word16 *pFilterM; + M1 = h_cldfb->no_channels; + L2 = M1 << 1; + M2 = M1 >> 1; + M41 = M2>>1; + M42 = M2-M41; + Mz = M1 - h_cldfb->bandsToZero; - const Word16 *rRotVctr; - const Word16 *iRotVctr; - Word32 workBuffer[2*BASOP_CFFT_MAX_LENGTH]; - - m = cldfbBank->no_channels; - move16(); - L2 = shl(m,1); - m2 = shr(m,1); - Lz = s_min(cldfbBank->lsb, sub(m,cldfbBank->bandsToZero)); - Mz = s_min(cldfbBank->usb, sub(m,cldfbBank->bandsToZero)); - stride = 1; /* constant */ - - channels0 = sub(m,cldfbBank->zeros); - channels1 = sub(m,1); - channels2 = shl(m,1); - channels3 = add(m,channels2); - channels4 = shl(channels2,1); - - statesSizeM1 = sub(shl(cldfbBank->p_filter_length,1),m); - statesSizeM2 = sub(statesSizeM1,m); - - offset1 = sub(channels1,cldfbBank->zeros); - offset2 = add(offset1,cldfbBank->no_channels); - - rBuffer = &pWorkBuffer[0]; - iBuffer = &pWorkBuffer[m]; - nBuffer = (Word16*)(&pWorkBuffer[L2]); - - rAnalysisS = &pWorkBuffer[3*m]; - iAnalysisS = &pWorkBuffer[4*m]; - - rRotVctr = cldfbBank->rRotVctr; - iRotVctr = cldfbBank->iRotVctr; - - scale = scaleFactor->lb_scale; - move16(); - if ( sub(Lz, Mz) != 0 ) + /* only process needed cols */ + if(samplesToProcess > -1) { - scale = s_max(scale, scaleFactor->hb_scale); - } - scaleLB = limitScale32(sub(scale, scaleFactor->lb_scale)); - scaleHB = limitScale32(sub(scale, scaleFactor->hb_scale)); - - outScale = cldfbBank->synFilterHeadroom; - move16(); - - scaleMod = sub(add(scale, cldfbBank->outScalefactor), outScale); - - /* Increase CLDFB synthesis states for low level signals */ - IF ( sub(scale, 8) < 0) - { - scaleMod = add(scaleMod, 2); - outScale = sub(outScale, 2); - } - scaleMod = sub(scaleMod, timeOut_e); - scale = add(outScale, timeOut_e); - IF ( sub(scale, cldfbBank->FilterStates_eg) != 0) - { - Scale_sig(cldfbBank->FilterStates, statesSizeM2, sub(cldfbBank->FilterStates_eg, scale)); - cldfbBank->FilterStates_eg = scale; - move16(); + no_col = min(no_col, (samplesToProcess + h_cldfb->no_channels - 1) / h_cldfb->no_channels); } - FOR (k=0; k < nTimeSlots; k++) + rot_vctr_re = h_cldfb->rot_vec_syn_re; + rot_vctr_im = h_cldfb->rot_vec_syn_im; + + synthesisBuffer = h_cldfb->cldfb_state; + p_filter = h_cldfb->p_filter; + ptr_time_out = timeOut; + + mvr2r( synthesisBuffer, synthesisBuffer + M1 * h_cldfb->no_col, h_cldfb->p_filter_length ); + + synthesisBuffer += M1 * h_cldfb->no_col; + + for (k=0; k < no_col; k++) { + for (i=Mz; i < M1; i++) { - FOR (i=0; i < Lz; i+=2) - { - rAnalysisS[i] = L_shr(rAnalysis[k][i],scaleLB); - move32(); - iAnalysisS[i] = L_negate(L_shr(iAnalysis[k][i],scaleLB)); - move32(); - } - - IF ( sub(i,Mz) < 0 ) - { - FOR ( ; i < Mz; i+=2) - { - rAnalysisS[i] = L_shr(rAnalysis[k][i],scaleHB); - move32(); - iAnalysisS[i] = L_negate(L_shr(iAnalysis[k][i],scaleHB)); - move32(); - } - } - - IF ( sub(i,m) < 0 ) - { - FOR ( ; i < m; i+=2) - { - rAnalysisS[i] = L_deposit_l(0); - iAnalysisS[i] = L_deposit_l(0); - } - } - - FOR (i=1; i < Lz; i+=2) - { - rAnalysisS[i] = L_shr(rAnalysis[k][i],scaleLB); - move32(); - iAnalysisS[i] = L_shr(iAnalysis[k][i],scaleLB); - move32(); - } - - IF ( sub(i,Mz) < 0 ) - { - FOR ( ; i < Mz; i+=2) - { - rAnalysisS[i] = L_shr(rAnalysis[k][i],scaleHB); - move32(); - iAnalysisS[i] = L_shr(iAnalysis[k][i],scaleHB); - move32(); - } - } - - IF ( sub(i,m) < 0 ) - { - FOR ( ; i < m; i+=2) - { - rAnalysisS[i] = L_deposit_l(0); - iAnalysisS[i] = L_deposit_l(0); - } - } + realBuffer[k][i] = 0.0f; + imagBuffer[k][i] = 0.0f; } - /* pre modulation */ - calcModulation(&rBuffer[0], &rBuffer[1], &rAnalysisS[0], &rAnalysisS[m-1], 2, 2, 2,-2, - &iBuffer[0], &iBuffer[1], &iAnalysisS[0], &iAnalysisS[m-1], 2, 2, 2,-2, - rRotVctr, iRotVctr, m); + for (i=0; i < M2; i++) + { + /* pre modulation of DST IV */ + cplxMult(&rBuffer[2*i], &rBuffer[2*i+1], realBuffer[k][2*i], realBuffer[k][M1-1-2*i], rot_vctr_re[i], rot_vctr_im[i]); + /* pre modulation of DCT IV */ + cplxMult(&iBuffer[2*i], &iBuffer[2*i+1],-imagBuffer[k][2*i], imagBuffer[k][M1-1-2*i], rot_vctr_re[i], rot_vctr_im[i]); + } /* FFT of DST IV */ - scale = 0; - move16(); - BASOP_cfft(&rBuffer[0], &rBuffer[1], m2, 2, &scale, workBuffer); + fft_cldfb(rBuffer, M2); /* FFT of DCT IV */ - scale = scaleMod; - move16(); - BASOP_cfft(&iBuffer[0], &iBuffer[1], m2, 2, &scale, workBuffer); + fft_cldfb(iBuffer, M2); - /* post modulation and folding */ - calcModulationAndFolding(nBuffer, rBuffer, iBuffer, rRotVctr, iRotVctr, cldfbBank->synGain, scale, m, m2); - - /* prototype filter */ - pStates = &cldfbBank->FilterStates[k*L2]; - pFilterS = &cldfbBank->p_filter[0]; - pFilterM = &cldfbBank->p_filter[shr(cldfbBank->p_filter_length,1)]; - - FOR (i=0; i < channels0; i++) + /* folding */ + for (i=0; ino_channels; i++) + for (i=0; ino_channels; i++) + /* synthesis prototype filter */ + for (i=0; i < L2; i++) { - pStates[statesSizeM1+i] = nBuffer[channels1-i]; - move16(); - pStates[statesSizeM2+i] = nBuffer[channels1+m-i]; - move16(); + accu0 = synthesisBuffer[0 * L2 + i] + p_filter[(0 * L2 + i)] * new_samples[L2 - 1 - i]; + accu1 = synthesisBuffer[1 * L2 + i] + p_filter[(1 * L2 + i)] * new_samples[L2 - 1 - i]; + accu2 = synthesisBuffer[2 * L2 + i] + p_filter[(2 * L2 + i)] * new_samples[L2 - 1 - i]; + accu3 = synthesisBuffer[3 * L2 + i] + p_filter[(3 * L2 + i)] * new_samples[L2 - 1 - i]; + accu4 = synthesisBuffer[4 * L2 + i] + p_filter[(4 * L2 + i)] * new_samples[L2 - 1 - i]; + + synthesisBuffer[0 * L2 + i] = accu0; + synthesisBuffer[1 * L2 + i] = accu1; + synthesisBuffer[2 * L2 + i] = accu2; + synthesisBuffer[3 * L2 + i] = accu3; + synthesisBuffer[4 * L2 + i] = accu4; } - timeOut = &timeOut[m*stride]; + for (i = 0; i < M1; i++) + { + ptr_time_out[M1 - 1 - i] = synthesisBuffer[4 * L2 + M1 + i]; + } + + ptr_time_out += M1; + + synthesisBuffer -= M1; + + set_f( synthesisBuffer, 0, M1 ); } - /* move filter states */ - Copy(&cldfbBank->FilterStates[i_mult(nTimeSlots,L2)], cldfbBank->FilterStates, statesSizeM2); - set16_fx(&cldfbBank->FilterStates[statesSizeM2],0,L2); - + return; } - /*-------------------------------------------------------------------* * configureClfdb() * * configures a CLDFB handle *--------------------------------------------------------------------*/ - -void configureCldfb ( HANDLE_CLDFB_FILTER_BANK h_cldfb, /*!< Returns handle */ - const Word16 no_channels, /*!< Number of channels (bands) */ - const Word16 frameSize /*!< FrameSize */ - ) +static void configureCldfb( + HANDLE_CLDFB_FILTER_BANK h_cldfb, /* i/o : filter bank handle */ + int samplerate /* i : max samplerate to oeprate */ +) { + short k; - h_cldfb->no_channels = no_channels; - move16(); - assert(h_cldfb->no_channels >= 10); - h_cldfb->no_col = div_l(frameSize,shr(h_cldfb->no_channels,1)); + h_cldfb->no_col = CLDFB_NO_COL_MAX; + h_cldfb->bandsToZero = 0; + h_cldfb->nab = 0; - /* was cldfbInitFilterBank()*/ - h_cldfb->anaScalefactor = 0; - move16(); - h_cldfb->synScalefactor = 0; - move16(); - h_cldfb->bandsToZero = 0; - move16(); - h_cldfb->filtermode = 0; - move16(); - h_cldfb->memory = 0; - move16(); - h_cldfb->memory_length = 0; - move16(); - - h_cldfb->p_filter_length = i_mult(10,h_cldfb->no_channels); - move16(); - - h_cldfb->flags = s_or(h_cldfb->flags,CLDFB_FLAG_2_5MS_SETUP); - h_cldfb->filterScale = CLDFB_CLDFB80_PFT_SCALE; - move16(); - - h_cldfb->zeros = 0; - move16(); - h_cldfb->synFilterHeadroom = SYN_FILTER_HEADROOM_2_5MS; - move16(); + h_cldfb->no_channels = samplerate * INV_CLDFB_BANDWIDTH + 0.5f; + h_cldfb->p_filter_length = 10*h_cldfb->no_channels; cldfb_init_proto_and_twiddles (h_cldfb); - h_cldfb->lsb = no_channels; - move16(); - h_cldfb->usb = s_min(no_channels, h_cldfb->no_channels); /* Does this make any sense? in the previous implemenatation lsb, usb and no_channels are all maxCldfbBands */ move16(); + h_cldfb->scale = 0.f; + for ( k=0; kp_filter_length; k++ ) + { + h_cldfb->scale += h_cldfb->p_filter[k] * h_cldfb->p_filter[k]; + } - h_cldfb->FilterStates = (Word16*)h_cldfb->FilterStates; - h_cldfb->outScalefactor = h_cldfb->synScalefactor; - move16(); + h_cldfb->scale *= (float)(6400/h_cldfb->no_channels); + h_cldfb->scale = (float)sqrt( h_cldfb->scale ); return; } @@ -1017,67 +407,48 @@ void configureCldfb ( HANDLE_CLDFB_FILTER_BANK h_cldfb, /*!< Returns han * * open and configures a CLDFB handle *--------------------------------------------------------------------*/ -void openCldfb ( HANDLE_CLDFB_FILTER_BANK *h_cldfb, /*!< Returns handle */ - const Word16 type, /*!< analysis or synthesis */ - const Word16 maxCldfbBands, /*!< number of cldfb bands */ - const Word16 frameSize /*!< FrameSize */ - ) +int openCldfb( + HANDLE_CLDFB_FILTER_BANK *h_cldfb, /* i/o : filter bank handle */ + CLDFB_TYPE type, /* i : analysis or synthesis */ + int samplerate /* i : max samplerate to oeprate */ +) { HANDLE_CLDFB_FILTER_BANK hs; + short buf_len; - hs = (HANDLE_CLDFB_FILTER_BANK) calloc(1, sizeof (struct CLDFB_FILTER_BANK)); - + hs = (HANDLE_CLDFB_FILTER_BANK) calloc(1, sizeof (CLDFB_FILTER_BANK)); + if( hs == NULL ) + { + return (1); + } hs->type = type; - move16(); - - IF (type == CLDFB_ANALYSIS) - { - hs->FilterStates = (Word16 *) calloc(STATE_BUFFER_SIZE*maxCldfbBands, sizeof (Word16)); - } - ELSE - { - hs->FilterStates = (Word16 *) calloc( 2 * STATE_BUFFER_SIZE * maxCldfbBands, sizeof (Word16)); - } - hs->flags &= ~CLDFB_FLAG_KEEP_STATES; - - configureCldfb (hs, maxCldfbBands, frameSize ); + configureCldfb (hs, samplerate); hs->memory = NULL; hs->memory_length = 0; - move16(); - IF( hs->type == CLDFB_ANALYSIS) + if (type == CLDFB_ANALYSIS) { - test(); - IF ( (s_and(hs->flags,CLDFB_FLAG_KEEP_STATES) == 0) && (hs->FilterStates != 0) ) - { - set16_fx(hs->FilterStates, 0, i_mult(STATE_BUFFER_SIZE,hs->no_channels)); - set16_fx(hs->FilterStates_e, 0, sizeof(hs->FilterStates_e)/sizeof(hs->FilterStates_e[0])); - - hs->FilterStates_eg = 0; - move16(); - } + short timeOffset = hs->p_filter_length - hs->no_channels; + buf_len = (hs->no_channels*hs->no_col+timeOffset); } - ELSE IF (hs->type == CLDFB_SYNTHESIS ) + else { - IF ( hs->FilterStates != 0 ) - { - IF ( s_and(hs->flags,CLDFB_FLAG_KEEP_STATES) == 0 ) - { - set16_fx(hs->FilterStates, 0, i_mult( shl(STATE_BUFFER_SIZE,1), hs->no_channels)); - } - } - hs->FilterStates_eg = 0; - move16(); + buf_len = (hs->p_filter_length + hs->no_channels*hs->no_col); } - if (h_cldfb != NULL) + hs->cldfb_state = (float *) calloc( buf_len, sizeof (float)); + if (hs->cldfb_state == NULL) { - *h_cldfb = hs; + return (1); } - return; + set_f(hs->cldfb_state, 0.0f, buf_len); + + *h_cldfb = hs; + + return (0); } @@ -1086,415 +457,158 @@ void openCldfb ( HANDLE_CLDFB_FILTER_BANK *h_cldfb, /*!< Returns handle */ * * Change sample rate of filter bank *--------------------------------------------------------------------*/ -void resampleCldfb (HANDLE_CLDFB_FILTER_BANK hs, - const Word16 newCldfbBands, - const Word16 frameSize, - const Word8 firstFrame - ) - +void resampleCldfb( + HANDLE_CLDFB_FILTER_BANK hs, + int newSamplerate +) { - Word16 timeOffset; - Word16 timeOffsetOld; - Word16 noChannelsOld; + short timeOffset, newframeSize; - noChannelsOld = hs->no_channels; - move16(); - timeOffsetOld = sub(sub(hs->p_filter_length,hs->no_channels),hs->zeros); - - /* change all CLDFB bank parameters that depend on the no of channels */ - hs->flags = s_or(hs->flags,CLDFB_FLAG_KEEP_STATES); - move16(); + /* keep old parameters before switching*/ + int timeOffsetold = hs->p_filter_length - hs->no_channels; + int old_no_channels = hs->no_channels; /* new settings */ - configureCldfb (hs, newCldfbBands, frameSize); + configureCldfb (hs, newSamplerate); + timeOffset = hs->p_filter_length - hs->no_channels; + newframeSize = hs->no_channels * hs->no_col; - /* resample cldfb state buffer */ - timeOffset = sub(sub(hs->p_filter_length,hs->no_channels),hs->zeros); - - IF( firstFrame == 0 ) - { - /*low complexity-resampling only stored previous samples that are needed for next frame modulation */ - lerp(hs->FilterStates+(noChannelsOld*hs->no_col), hs->FilterStates+(noChannelsOld*hs->no_col), timeOffset, timeOffsetOld); - Copy(hs->FilterStates+(noChannelsOld*hs->no_col), hs->FilterStates+frameSize, timeOffset); - } + /*low complexity-resampling only stored previous samples that are needed for next frame modulation */ + lerp(hs->cldfb_state+(old_no_channels*hs->no_col),hs->cldfb_state+(old_no_channels*hs->no_col),timeOffset, timeOffsetold); + mvr2r(hs->cldfb_state+(old_no_channels*hs->no_col),hs->cldfb_state+newframeSize,timeOffset); return; } -/* - AnalysisPostSpectrumScaling_Fx - - Parameters: - cldfbBank I: CLDFB handle - **rSubband32 I: matrix holding real part of the CLDFB subsamples - **iSubband32 I: matrix holding imaginary part of the CLDFB subsamples - **rSubband16 O: matrix holding real part of the CLDFB subsamples - **iSubband16 O: matrix holding imaginary part of the CLDFB subsamples - *cldfbScale O: cldfb lowband scalefactor - - Function: - performs dynamic spectrum scaling for all subband - - Returns: - headroom -*/ -Word16 -AnalysisPostSpectrumScaling_Fx (HANDLE_CLDFB_FILTER_BANK cldfbBank, /*!< Handle of cldfbBank */ - Word32 **rSubband32, /*!< Real bands */ - Word32 **iSubband32, /*!< Imaginary bands */ - Word16 **rSubband16, /*!< Real bands */ - Word16 **iSubband16, /*!< Imaginary bands */ - Word16 *cldfbScale /*!< CLDFB lowband scalefactor */ - ) -{ - Word16 i; - Word16 j; - Word16 headRoom; - - - - headRoom = BASOP_util_norm_l_dim2_cplx ( - (const Word32 * const*) rSubband32, - (const Word32 * const*) iSubband32, - 0, - cldfbBank->no_channels, - 0, - cldfbBank->no_col - ); - - FOR (i=0; i < cldfbBank->no_col; i++) - { - FOR (j=0; j < cldfbBank->no_channels; j++) - { - rSubband16[i][j] = round_fx(L_shl(rSubband32[i][j], headRoom)); - iSubband16[i][j] = round_fx(L_shl(iSubband32[i][j], headRoom)); - } - } - - *cldfbScale = add(*cldfbScale,headRoom); - move16(); - - - return headRoom; -} - - /*-------------------------------------------------------------------* * analysisCLDFBEncoder() * * Encoder CLDFB analysis + energy stage *--------------------------------------------------------------------*/ -void analysisCldfbEncoder_fx( - Encoder_State_fx *st_fx, /* i/o: encoder state structure */ - const Word16 *timeIn, - Word32 realBuffer[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX], - Word32 imagBuffer[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX], - Word16 realBuffer16[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX], - Word16 imagBuffer16[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX], - Word32 enerBuffSum[CLDFB_NO_CHANNELS_MAX], - Word16 *enerBuffSum_exp, - CLDFB_SCALE_FACTOR * scale +void analysisCldfbEncoder( + Encoder_State *st, /* i/o: encoder state structure */ + const float *timeIn, + int samplesToProcess, + float realBuffer[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX], + float imagBuffer[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX], + float *ppBuf_Ener ) { - Word16 i; - CLDFB_SCALE_FACTOR enerScale; - Word32 *ppBuf_Real[CLDFB_NO_COL_MAX]; - Word32 *ppBuf_Imag[CLDFB_NO_COL_MAX]; - Word16 *ppBuf_Real16[CLDFB_NO_COL_MAX]; - Word16 *ppBuf_Imag16[CLDFB_NO_COL_MAX]; - Word32 workBuffer[256]; - Word16 num_slots = 1; + short i; + float *ppBuf_Real[CLDFB_NO_COL_MAX]; + float *ppBuf_Imag[CLDFB_NO_COL_MAX]; - FOR (i=0; icldfbAna_Fx, - ppBuf_Real, - ppBuf_Imag, - scale, - timeIn, - 0, - CLDFB_NO_COL_MAX, - workBuffer - ); + cldfbAnalysis( timeIn,ppBuf_Real,ppBuf_Imag, samplesToProcess, st->cldfbAnaEnc ); - enerScale.lb_scale = negate(scale->lb_scale); - enerScale.lb_scale16 = negate(scale->lb_scale); - - /* get 16bit respresentation */ - AnalysisPostSpectrumScaling_Fx ( - st_fx->cldfbAna_Fx, - ppBuf_Real, - ppBuf_Imag, - ppBuf_Real16, - ppBuf_Imag16, - &enerScale.lb_scale16 - ); - - /* get the energy */ - GetEnergyCldfb( &st_fx->energyCoreLookahead_Fx, - &st_fx->sf_energyCoreLookahead_Fx, - num_slots, - ppBuf_Real16, - ppBuf_Imag16, - enerScale.lb_scale16, - st_fx->cldfbAna_Fx->no_channels, - st_fx->cldfbAna_Fx->no_col, - &st_fx->currEnergyHF_fx, - &st_fx->currEnergyHF_e_fx, - enerBuffSum, - enerBuffSum_exp, - &st_fx->tecEnc - ); + st->currEnergyHF = GetEnergyCldfb( ppBuf_Ener, &st->currEnergyLookAhead, ppBuf_Real, ppBuf_Imag, + st->cldfbAnaEnc->no_channels, st->cldfbAnaEnc->no_col, &(st->tecEnc) ); return; } -void -GetEnergyCldfb( Word32 *energyLookahead, /*!< o: Q(*sf_energyLookahead) | pointer to the result in the core look-ahead slot */ - Word16 *sf_energyLookahead, /*!< o: pointer to the scalefactor of the result in the core look-ahead slot */ - const Word16 numLookahead, /*!< i: Q0 the number of look-ahead time-slots */ - Word16 **realValues, /*!< i: Q(sf_Values) | the real part of the CLDFB subsamples */ - Word16 **imagValues, /*!< i: Q(sf_Values) | the imaginary part of the CLDFB subsamples */ - Word16 sf_Values, /*!< i: scalefactor of the CLDFB subcamples - apply as a negated Exponent */ - Word16 numberBands, /*!< i: Q0 | number of CLDFB bands */ - Word16 numberCols, /*!< i: Q0 | number of CLDFB subsamples */ - Word32 *energyHF, /*!< o: Q31 | pointer to HF energy */ - Word16 *energyHF_Exp, /*!< o: pointer to exponent of HF energy */ - Word32 *energyValuesSum, /*!< o: Q(2*sf_Values-4) | pointer to sum array of energy values, not initialized*/ - Word16 *energyValuesSum_Exp,/*!< o: pointer to exponents of energyValuesSum, not initialized */ - HANDLE_TEC_ENC_FX hTecEnc - ) +/*-------------------------------------------------------------------* +* GetEnergyCldfb() +* +* Conduct energy from complex data +*--------------------------------------------------------------------*/ +static float GetEnergyCldfb( + float *energyValuesSum,/*!< the result of the operation */ + float *energyLookahead, /*!< the result in the core look-ahead slot */ + float **realValues, /*!< the real part of the subsamples */ + float **imagValues, /*!< the imaginary part of the subsamples */ + int numberBands, /*!< number of bands */ + int numberCols, /*!< number of subsamples */ + HANDLE_TEC_ENC hTecEnc +) { - Word16 j; - Word16 k; - Word16 s; - Word16 sm; - Word32 nrg; - Word16 numberColsL; - Word16 numberBandsM; - Word16 numberBandsM20; - Word32 energyValues[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX]; - Word16 energyValuesSumE[CLDFB_NO_CHANNELS_MAX]; - Word16 freqTable[2] = {20, 40}; + short j, k; + float energyValues[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX]; + short numLookahead = 1; - - FOR (k=0; k= 0) + if(numberBands >= freqTable[1]) { - Word32 *tempEnergyValuesArry[CLDFB_NO_COL_MAX]; - Word16 ScaleX2; + float *tempEnergyValuesArry[CLDFB_NO_COL_MAX]; + assert(numberCols == CLDFB_NO_COL_MAX); - FOR (j=0; jloBuffer, - hTecEnc->hiTempEnv, - ScaleX2 - ); + calcHiEnvLoBuff( numberCols, freqTable, 1, tempEnergyValuesArry, hTecEnc->loBuffer, hTecEnc->hiTempEnv ); } - FOR (j=0; j< numberBands; j++) + for (j = 0; j < numberBands; j++) { - energyValuesSum[j] = L_deposit_l(0); - energyValuesSumE[j] = 31; - move16(); - FOR (k=0; k 0 ) - { - *energyValuesSum_Exp = energyValuesSumE[j]; + energyValuesSum[j] += energyValues[k][j]; } } - FOR (j=0; j< numberBands; j++) + + if (numberBands > 20) { - energyValuesSum[j] = L_shr_r( energyValuesSum[j], sub( *energyValuesSum_Exp, energyValuesSumE[j] ) ); - move32(); - } - *energyValuesSum_Exp = sub( *energyValuesSum_Exp, shl( sf_Values, 1 ) ); - move16(); + float energyHF = *energyLookahead; /* energy above 8 kHz */ + numberCols -= numLookahead; + *energyLookahead = 6.1e-5f; /* process look-ahead region */ - IF ( sub(numberBands,20) > 0 ) - { - numberBandsM = s_min(numberBands, 40); - numberBandsM20 = sub(numberBandsM, 20); - - numberColsL = sub(numberCols, numLookahead); - - /* sum up CLDFB energy above 8 kHz */ - s = BASOP_util_norm_s_bands2shift(i_mult(numberColsL, numberBandsM20)); - s = sub(s,4); - nrg = L_deposit_l(0); - - FOR (k=0; k < numberColsL; k++) + for (j = 20; j < min(40, numberBands); j++) { - FOR (j=20; j < numberBandsM; j++) + energyHF += energyValuesSum[j]; + + for (k = numberCols; k < CLDFB_NO_COL_MAX; k++) { - nrg = L_add(nrg, L_shr(energyValues[k][j], s)); + energyHF -= energyValues[k][j]; + *energyLookahead += energyValues[k][j]; } } - s = sub(sub(shl(sf_Values, 1), 1), s); - sm = sub(s_min(s, *sf_energyLookahead), 1); - - *energyHF = L_add(L_shr(nrg, limitScale32(sub(s, sm))), - L_shr(*energyLookahead,sub(*sf_energyLookahead, sm))); - move32(); - - *energyHF_Exp = negate(sm); - move16(); - - /* process look-ahead region */ - s = BASOP_util_norm_s_bands2shift(i_mult(numLookahead, numberBandsM20)); - s = sub(s, 2); - nrg = L_deposit_l(0); - - FOR (k = numberColsL; k < numberCols; k++) - { - FOR (j=20; j < numberBandsM; j++) - { - nrg = L_add(nrg, L_shr(energyValues[k][j], s)); - } - } - - s = sub(shl(sf_Values, 1), s); - sm = sub(s_min(s, 44), 1); - BASOP_SATURATE_WARNING_OFF - /* nrg + 6.1e-5f => value 0x40000000, scale 44 */ - *energyLookahead = L_add(L_shr(nrg, sub(s, sm)), - L_shr(0x40000000, s_max(-31, s_min(31, sub(44, sm))))); - move32(); - BASOP_SATURATE_WARNING_ON - *sf_energyLookahead = sm; - move16(); - - return; + return energyHF * OUTMAX_SQ_INV; } - - - *energyHF = 0x40000000; - move32(); - *energyHF_Exp = 17; - move16(); - - + return 65535.0f; } -Word16 -CLDFB_getNumChannels(Word32 sampleRate) -{ - - Word16 nChannels = 0; - - - SWITCH (sampleRate) - { - case 48000: - move16(); - nChannels = 60; - BREAK; - case 32000: - move16(); - nChannels = 40; - BREAK; - case 25600: - move16(); - nChannels = 32; - BREAK; - case 16000: - move16(); - nChannels = 20; - BREAK; - case 12800: - move16(); - nChannels = 16; - BREAK; - case 8000: - move16(); - nChannels = 10; - BREAK; - } - - return (nChannels); -} - -/*-------------------------------------------------------------------* -* cldfb_get_memory_length() -* -* Return length of filter state for recovery -*--------------------------------------------------------------------*/ -static Word16 -cldfb_get_memory_length (HANDLE_CLDFB_FILTER_BANK hs) -{ - IF (sub(hs->type,CLDFB_ANALYSIS)==0) - { - return (i_mult(hs->no_channels,STATE_BUFFER_SIZE)); - } - ELSE - { - return (i_mult(hs->no_channels,(9*2)) ); - } -} - /*-------------------------------------------------------------------* * GetEnergyCldfb() * * Remove handle *--------------------------------------------------------------------*/ -void -deleteCldfb (HANDLE_CLDFB_FILTER_BANK * h_cldfb) /* i: cldfb handle */ +void deleteCldfb( + HANDLE_CLDFB_FILTER_BANK * h_cldfb +) { - IF ( *h_cldfb != NULL ) + HANDLE_CLDFB_FILTER_BANK hs = *h_cldfb; + + if (hs) { - IF ( (*h_cldfb)->FilterStates != NULL ) + if (hs->cldfb_state) { - free((*h_cldfb)->FilterStates); + free(hs->cldfb_state); } - free(*h_cldfb); + free(hs); + *h_cldfb = NULL; } - *h_cldfb = NULL; + + return; } @@ -1503,148 +617,115 @@ deleteCldfb (HANDLE_CLDFB_FILTER_BANK * h_cldfb) /* i: cldfb handle * * Initializes rom pointer *--------------------------------------------------------------------*/ -static void -cldfb_init_proto_and_twiddles(HANDLE_CLDFB_FILTER_BANK hs) /* i: cldfb handle */ +static void cldfb_init_proto_and_twiddles( + HANDLE_CLDFB_FILTER_BANK hs +) { /*find appropriate set of rotVecs*/ - SWITCH(hs->no_channels) + switch(hs->no_channels) { case 10: - - hs->rRotVctr = rRotVectr_10; - hs->iRotVctr = iRotVectr_10; - hs->synGain = cldfb_synGain[0]; - move16(); - hs->p_filter = cldfb_protoFilter_2_5ms[0]; - hs->scale = cldfb_scale_2_5ms[0]; - move16(); - IF (hs->type == CLDFB_SYNTHESIS ) - { - hs->synScalefactor = add(cldfb_synScale[0],hs->filterScale); - move16(); - } - ELSE - { - hs->anaScalefactor = add(cldfb_anaScale[0],hs->filterScale); - move16(); - } + hs->rot_vec_ana_re = rot_vec_ana_re_L10; + hs->rot_vec_ana_im = rot_vec_ana_im_L10; + hs->rot_vec_syn_re = rot_vec_syn_re_L10; + hs->rot_vec_syn_im = rot_vec_syn_im_L10; + hs->p_filter = CLDFB80_10; break; case 16: - hs->rRotVctr = rRotVectr_16; - hs->iRotVctr = iRotVectr_16; - hs->synGain = cldfb_synGain[1]; - move16(); - hs->p_filter = cldfb_protoFilter_2_5ms[1]; - hs->scale = cldfb_scale_2_5ms[1]; - move16(); - { - hs->anaScalefactor = add(cldfb_anaScale[1],hs->filterScale); - move16(); - } + hs->rot_vec_ana_re = rot_vec_ana_re_L16; + hs->rot_vec_ana_im = rot_vec_ana_im_L16; + hs->rot_vec_syn_re = rot_vec_syn_re_L16; + hs->rot_vec_syn_im = rot_vec_syn_im_L16; + hs->p_filter = CLDFB80_16; break; case 20: - hs->rRotVctr = rRotVectr_20; - hs->iRotVctr = iRotVectr_20; - hs->synGain = cldfb_synGain[2]; - move16(); - hs->p_filter = cldfb_protoFilter_2_5ms[2]; - hs->scale = cldfb_scale_2_5ms[2]; - move16(); - IF (hs->type == CLDFB_SYNTHESIS ) - { - hs->synScalefactor = add(cldfb_synScale[2],hs->filterScale); - move16(); - } - ELSE - { - hs->anaScalefactor = add(cldfb_anaScale[2],hs->filterScale); - move16(); - } + hs->rot_vec_ana_re = rot_vec_ana_re_L20; + hs->rot_vec_ana_im = rot_vec_ana_im_L20; + hs->rot_vec_syn_re = rot_vec_syn_re_L20; + hs->rot_vec_syn_im = rot_vec_syn_im_L20; + hs->p_filter = CLDFB80_20; + break; + + case 30: + hs->rot_vec_ana_re = rot_vec_ana_re_L30; + hs->rot_vec_ana_im = rot_vec_ana_im_L30; + hs->rot_vec_syn_re = rot_vec_syn_re_L30; + hs->rot_vec_syn_im = rot_vec_syn_im_L30; + hs->p_filter = CLDFB80_30; break; case 32: - hs->rRotVctr = rRotVectr_32; - hs->iRotVctr = iRotVectr_32; - hs->synGain = cldfb_synGain[3]; - move16(); - hs->p_filter = cldfb_protoFilter_2_5ms[3]; - hs->scale = cldfb_scale_2_5ms[3]; - move16(); - { - hs->anaScalefactor = add(cldfb_anaScale[3],hs->filterScale); - move16(); - } + hs->rot_vec_ana_re = rot_vec_ana_re_L32; + hs->rot_vec_ana_im = rot_vec_ana_im_L32; + hs->rot_vec_syn_re = rot_vec_syn_re_L32; + hs->rot_vec_syn_im = rot_vec_syn_im_L32; + hs->p_filter = CLDFB80_32; break; case 40: - hs->rRotVctr = rRotVectr_40; - hs->iRotVctr = iRotVectr_40; - hs->synGain = cldfb_synGain[4]; - move16(); - hs->p_filter = cldfb_protoFilter_2_5ms[4]; - hs->scale = cldfb_scale_2_5ms[4]; - move16(); - IF (hs->type == CLDFB_SYNTHESIS ) - { - hs->synScalefactor = add(cldfb_synScale[4],hs->filterScale); - move16(); - } - ELSE - { - hs->anaScalefactor = add(cldfb_anaScale[4],hs->filterScale); - move16(); - } + hs->rot_vec_ana_re = rot_vec_ana_re_L40; + hs->rot_vec_ana_im = rot_vec_ana_im_L40; + hs->rot_vec_syn_re = rot_vec_syn_re_L40; + hs->rot_vec_syn_im = rot_vec_syn_im_L40; + hs->p_filter = CLDFB80_40; break; case 60: - hs->rRotVctr = rRotVectr_60; - hs->iRotVctr = iRotVectr_60; - hs->synGain = cldfb_synGain[5]; - move16(); - hs->p_filter = cldfb_protoFilter_2_5ms[5]; - hs->scale = cldfb_scale_2_5ms[5]; - move16(); - IF (hs->type == CLDFB_SYNTHESIS ) - { - hs->synScalefactor = add(cldfb_synScale[5],hs->filterScale); - move16(); - } - ELSE - { - hs->anaScalefactor = add(cldfb_anaScale[5],hs->filterScale); - move16(); - } + hs->rot_vec_ana_re = rot_vec_ana_re_L60; + hs->rot_vec_ana_im = rot_vec_ana_im_L60; + hs->rot_vec_syn_re = rot_vec_syn_re_L60; + hs->rot_vec_syn_im = rot_vec_syn_im_L60; + hs->p_filter = CLDFB80_60; break; } + + return; } -#define CLDFB_MEM_EXPONENTS (CLDFB_NO_COL_MAX+9) - /*-------------------------------------------------------------------* * cldfb_save_memory() * * Save the memory of filter; to be restored with cldfb_restore_memory() *--------------------------------------------------------------------*/ -void -cldfb_save_memory (HANDLE_CLDFB_FILTER_BANK hs) /* i: cldfb handle */ +int cldfb_save_memory( + HANDLE_CLDFB_FILTER_BANK hs /* i/o: cldfb handle */ +) { + unsigned int offset = hs->p_filter_length - hs->no_channels; + unsigned int frameSize = hs->no_channels * hs->no_col; - hs->memory_length = cldfb_get_memory_length(hs); - hs->memory = (Word16 *) calloc( hs->memory_length + CLDFB_MEM_EXPONENTS + 1, sizeof (Word16)); + if (hs->memory != NULL || hs->memory_length!=0) + { + /* memory already stored; Free memory first */ + return 1; + } + if (hs->type == CLDFB_ANALYSIS) + { + hs->memory_length = offset + frameSize; + } + else + { + hs->memory_length = hs->p_filter_length; + } + + hs->memory = (float *) calloc( hs->memory_length, sizeof (float)); + if (hs->memory == NULL) + { + /* memory cannot be allocated */ + return (1); + } + /* save the memory */ - Copy (hs->FilterStates, hs->memory, hs->memory_length); - Copy (hs->FilterStates_e, hs->memory+hs->memory_length, CLDFB_MEM_EXPONENTS); - hs->memory[hs->memory_length+CLDFB_MEM_EXPONENTS] = hs->FilterStates_eg; - move16(); + mvr2r (hs->cldfb_state, hs->memory, hs->memory_length); - return; + return 0; } @@ -1653,49 +734,70 @@ cldfb_save_memory (HANDLE_CLDFB_FILTER_BANK hs) /* i: cldfb handle */ * * Restores the memory of filter; memory to be save by cldfb_save_memory() *--------------------------------------------------------------------*/ -void -cldfb_restore_memory (HANDLE_CLDFB_FILTER_BANK hs) /* i/o: cldfb handle */ - +int cldfb_restore_memory( + HANDLE_CLDFB_FILTER_BANK hs /* i/o: cldfb handle */ +) { - Word16 size; + unsigned int offset = hs->p_filter_length - hs->no_channels; + unsigned int frameSize = hs->no_channels * hs->no_col; + unsigned int size; + if (hs->memory == NULL || hs->memory_length==0) + { + /* memory not allocated */ + return 1; + } - size = cldfb_get_memory_length(hs); + if ( hs->type == CLDFB_ANALYSIS ) + { + size = offset + frameSize; + } + else + { + size = hs->p_filter_length; + } /* read the memory */ - Copy (hs->memory, hs->FilterStates, hs->memory_length); - Copy (hs->memory+hs->memory_length, hs->FilterStates_e, CLDFB_MEM_EXPONENTS); - hs->FilterStates_eg = hs->memory[hs->memory_length+CLDFB_MEM_EXPONENTS]; - move16(); + mvr2r (hs->memory, hs->cldfb_state, hs->memory_length); /* adjust sample rate if it was changed in the meanwhile */ - IF (sub (hs->memory_length,size) != 0) + if (hs->memory_length != size) { - lerp(hs->FilterStates, hs->FilterStates, size, hs->memory_length); + lerp(hs->cldfb_state, hs->cldfb_state, size, hs->memory_length); } hs->memory_length = 0; free(hs->memory); hs->memory = NULL; - return; + return 0; } + /*-------------------------------------------------------------------* * cldfb_reset_memory() * * Resets the memory of filter. *--------------------------------------------------------------------*/ -void -cldfb_reset_memory (HANDLE_CLDFB_FILTER_BANK hs) /* i/o: cldfb handle */ +int cldfb_reset_memory( + HANDLE_CLDFB_FILTER_BANK hs /* i/o: cldfb handle */ +) { - Word16 length; + unsigned int offset = hs->p_filter_length - hs->no_channels; + unsigned int frameSize = hs->no_channels * hs->no_col; + int memory_length; - length = cldfb_get_memory_length(hs); - /* erase the memory */ - set16_fx (hs->FilterStates, 0, length); - set16_fx (hs->FilterStates_e, 0, sizeof(hs->FilterStates_e)/sizeof(hs->FilterStates_e[0])); - hs->FilterStates_eg = 0; - move16(); + if (hs->type == CLDFB_ANALYSIS) + { + memory_length = offset + frameSize; + } + else + { + memory_length = hs->p_filter_length; + } + + /* save the memory */ + set_f (hs->cldfb_state, 0, memory_length); + + return 0; } - diff --git a/src/libs/libevs/lib_com/cng_exc.cpp b/src/libs/libevs/lib_com/cng_exc.cpp new file mode 100644 index 00000000..512623f4 --- /dev/null +++ b/src/libs/libevs/lib_com/cng_exc.cpp @@ -0,0 +1,557 @@ +/*==================================================================================== + EVS Codec 3GPP TS26.443 Nov 13, 2018. Version 12.11.0 / 13.7.0 / 14.3.0 / 15.1.0 + ====================================================================================*/ + +#include +#include +#include "options.h" +#include "cnst.h" +#include "prot.h" +#include "rom_com.h" + +/*---------------------------------------------------------------------* + * Local constants + *---------------------------------------------------------------------*/ + +#define A2 0.2f +#define GAIN_VAR 0.000011f + +/*-------------------------------------------------------* + * CNG_exc() + * + * Comfort noise generation routine + *-------------------------------------------------------*/ + +void CNG_exc( + const long core_brate, /* i : core bitrate */ + const short L_frame, /* i : length of the frame */ + float *Enew, /* i/o: decoded SID energy */ + short *seed, /* i/o: random generator seed */ + float exc[], /* o : current non-enhanced excitation */ + float exc2[], /* o : current enhanced excitation */ + float *lp_ener, /* i/o: LP filtered E */ + const long last_core_brate, /* i : previous frame core bitrate */ + short *first_CNG, /* i/o: first CNG frame flag for energy init. */ + short *cng_ener_seed, /* i/o: random generator seed for CNG energy */ + float bwe_exc[], /* o : excitation for SWB TBE */ + const short allow_cn_step, /* i : allow CN step */ + short *last_allow_cn_step, /* i/o: last allow step */ + const short num_ho, /* i : number of selected hangover frames */ + float q_env[], + float *lp_env, + float *old_env, + float *exc_mem, + float *exc_mem1, + short *sid_bw, + short *cng_ener_seed1, + float exc3[], + short Opt_AMR_WB +) +{ + float enr; + short i; + float ener_lp; + short i_subfr; + short pit_max; + float ftmp; + float *ptR,*ptI; + float fft_io[L_FRAME16k]; + float itmp[129]; + float env[NUM_ENV_CNG]; + float enr1; + float denv[NUM_ENV_CNG]; + + /*------------------------------------------------------------------* + * Initializations + *------------------------------------------------------------------*/ + + if( L_frame == L_FRAME ) + { + pit_max = PIT_MAX; + } + else /* L_frame == L_FRAME16k */ + { + pit_max = PIT16k_MAX; + } + + /*---------------------------------------------------------------------* + * Initialization of CNG energy for the first CNG frame + *---------------------------------------------------------------------*/ + + if( *first_CNG == 0 ) + { + if( core_brate == FRAME__NO_DATA ) + { + /* needed only in decoder when the very first SID frame was erased and this frame is FRAME__NO_DATA frame */ + *Enew = dotp( exc-pit_max, exc-pit_max, pit_max ) / pit_max; + } + + *lp_ener = *Enew; + } + + /*---------------------------------------------------------------------* + * Update CNG energy + *---------------------------------------------------------------------*/ + + if( last_core_brate != SID_1k75 && last_core_brate != FRAME__NO_DATA && last_core_brate != SID_2k40 ) + { + /* Partially reset CNG energy after active speech period */ + if ( allow_cn_step == 0 && *last_allow_cn_step == 0 ) + { + if( num_ho < 3 || *Enew < 1.5f * *lp_ener ) + { + *lp_ener = 0.8f * *lp_ener + 0.2f * *Enew; + } + else + { + *lp_ener = 0.95f * *lp_ener + 0.05f * *Enew; + } + } + else + { + *lp_ener = *Enew; + *last_allow_cn_step = 0; + } + } + else + { + /* normal CNG update */ + if ( *last_allow_cn_step == 0 ) + { + *lp_ener = (float)(A2 **Enew + (1-A2) **lp_ener); + } + else + { + if ( core_brate == SID_1k75 || core_brate == SID_2k40 ) + { + *last_allow_cn_step = 0; + } + + *lp_ener = *Enew; + + } + } + + if ( allow_cn_step == 1 ) + { + *last_allow_cn_step = 1; + } + + /*---------------------------------------------------------------------* + * Generate white noise vector + *---------------------------------------------------------------------*/ + + for ( i=0; i 1 ) + { + enr = 1; + } + } + + for ( i=0; i 1 ) + { + enr = 1; + } + + ftmp = sqrt(enr); + for (i=0; i ACELP_13k20 ) + { + CNG_mode = 4; + } + else if( last_active_brate > ACELP_9k60 ) + { + CNG_mode = 3; + } + else if( last_active_brate > ACELP_8k00 ) + { + CNG_mode = 2; + } + else if( last_active_brate > ACELP_7k20 ) + { + CNG_mode = 1; + } + else + { + CNG_mode = 0; + } + + att = 1/pow(2,ENR_ATT[CNG_mode]); + + for ( i=0; i HO_HIST_SIZE) + { + *cng_buf_cnt = HO_HIST_SIZE; + } + mvr2r( exc2, &(cng_exc2_buf[(*ho_circ_ptr)*L_FFT]), L_FFT ); + cng_brate_buf[*ho_circ_ptr] = last_active_brate; + } + else + { + + /* calculate the spectrum of residual signal */ + mvr2r(exc2, fft_io, L_frame); + + fft_rel(fft_io, L_FFT, LOG2_L_FFT); + + ptR = &fft_io[1]; + ptI = &fft_io[L_FFT-1]; + for (i=0; i ACELP_13k20 ) + { + CNG_mode = 4; + } + else if( last_active_brate > ACELP_9k60 ) + { + CNG_mode = 3; + } + else if( last_active_brate > ACELP_8k00 ) + { + CNG_mode = 2; + } + else if( last_active_brate > ACELP_7k20 ) + { + CNG_mode = 1; + } + else + { + CNG_mode = 0; + } + + att = 1/pow(2,ENR_ATT[CNG_mode]); + + for ( i=0; i HO_HIST_SIZE ) + { + *ho_circ_size = HO_HIST_SIZE; + } + + return; +} diff --git a/src/libs/libevs/lib_com/cng_exc_fx.cpp b/src/libs/libevs/lib_com/cng_exc_fx.cpp deleted file mode 100755 index 5e471cd4..00000000 --- a/src/libs/libevs/lib_com/cng_exc_fx.cpp +++ /dev/null @@ -1,889 +0,0 @@ -/*==================================================================================== - EVS Codec 3GPP TS26.442 Apr 03, 2018. Version 12.11.0 / 13.6.0 / 14.2.0 - ====================================================================================*/ - -#include "options.h" /* Compilation switches */ -#include "cnst_fx.h" /* Common constants */ -#include "prot_fx.h" /* Function prototypes */ -#include "stl.h" -#include "rom_com_fx.h" - -/*---------------------------------------------------------------------* - * Local constants - *---------------------------------------------------------------------*/ -#define A2 6554 -#define OmA2 (32768-A2) -#define GAIN_VAR 11811 /* in Q31 divided by 2 (Q30) */ - -/*-------------------------------------------------------* - * CNG_exc() - * - * Comfort noise generation routine - *-------------------------------------------------------*/ - -void CNG_exc_fx( - const Word32 core_brate, /* i : core bitrate */ - const Word16 L_frame, /* i : length of the frame */ - Word32 *Enew, /* i/o: decoded SID energy Q6 */ - Word16 *seed, /* i/o: random generator seed */ - Word16 exc[], /* o : current non-enhanced excitation Q_new */ - Word16 exc2[], /* o : current enhanced excitation Q_new */ - Word32 *lp_ener, /* i/o: LP filtered E */ - const Word32 last_core_brate, /* i : previous frame core bitrate */ - Word16 *first_CNG, /* i/o: first CNG frame flag for energy init. */ - Word16 *cng_ener_seed, /* i/o: random generator seed for CNG energy */ - Word16 bwe_exc[], /* o : excitation for SWB TBE */ - const Word16 allow_cn_step, /* i : allow CN step */ - Word16 *last_allow_cn_step, /* i/o: last allow step */ - const Word16 OldQ_exc, /* i : Old excitation scaling */ - const Word16 Q_exc /* i : excitation scaling */ - , const Word16 num_ho /* i : number of selected hangover frames */ - ,Word32 q_env[] - ,Word32 *lp_env - ,Word32 *old_env - ,Word16 *exc_mem - ,Word16 *exc_mem1 - ,Word16 *sid_bw - ,Word16 *cng_ener_seed1 - ,Word16 exc3[] - ,Word16 Opt_AMR_WB -) -{ - Word16 i, tmp, tmp2, exp, exp2, Q_ener; - Word32 L_tmp_ener, L_tmp; - Word16 i_subfr; - Word16 pit_max; - Word16 ftmp,j; - Word16 *ptR,*ptI; - Word16 fft_io[L_FRAME16k]; - Word32 itmp[129]; - Word32 env[NUM_ENV_CNG]; - Word32 enr1; - Word32 denv[NUM_ENV_CNG]; - Word16 fra; - Word16 temp_lo_fx, temp_hi_fx; - Word16 exp_pow; - Word32 L_tmp2; - Word16 *pt_fft_io; - - /*------------------------------------------------------------------* - * Initializations - *------------------------------------------------------------------*/ - - pit_max = PIT16k_MAX; - move16(); - if( sub(L_frame,L_FRAME) == 0 ) - { - pit_max = PIT_MAX; - move16(); - } - - /*---------------------------------------------------------------------* - * Initialization of CNG energy for the first CNG frame - *---------------------------------------------------------------------*/ - - IF(*first_CNG == 0 ) - { - IF(L_sub(core_brate,FRAME_NO_DATA) == 0 ) - { - /* needed only in decoder when the very first SID frame was erased and this frame is FRAME_NO_DATA frame */ - /*fenew = dotp( fexc, fexc, pit_max )/pit_max;*/ - L_tmp_ener = Calc_Energy_Autoscaled(exc-pit_max, OldQ_exc, pit_max, &Q_ener); - L_tmp_ener = Mult_32_16(L_tmp_ener, 9079); /* divide by PIT_MAX (in Q15 + Q6 to get output in Q6)*/ - L_tmp_ener = L_shr(L_tmp_ener, Q_ener); /* -> If we want ener in Q6 */ - - if(sub(L_frame, L_FRAME16k) == 0) - { - L_tmp_ener = Mult_32_16(L_tmp_ener, 26214); /* Compensate for 16kHz */ - } - *Enew = L_tmp_ener; - move32(); - } - - *lp_ener = *Enew; - move32(); - } - - /*---------------------------------------------------------------------* - * Update CNG energy - *---------------------------------------------------------------------*/ - test(); - test(); - IF( L_sub(last_core_brate,SID_1k75) != 0 && L_sub(last_core_brate,FRAME_NO_DATA) != 0 && L_sub(last_core_brate,SID_2k40) != 0 ) - { - /* Partially reset CNG energy after active speech period */ - test(); - IF ( allow_cn_step == 0 && *last_allow_cn_step == 0 ) - { - test(); - IF( sub(num_ho,3) < 0 || L_sub(Mult_32_16(*Enew,21845 /*1/1.5f, Q15*/), *lp_ener) < 0 ) - { - /**lp_ener = 0.8f * *lp_ener + 0.2f * *Enew;*/ - L_tmp_ener = Mult_32_16(*lp_ener, 26214); - L_tmp_ener = Madd_32_16(L_tmp_ener, *Enew, 6554); - - } - ELSE - { - /**lp_ener = 0.95f * *lp_ener + 0.05f * *Enew;*/ - L_tmp_ener = Mult_32_16(*lp_ener, 31130); - L_tmp_ener = Madd_32_16(L_tmp_ener, *Enew, 1638); - } - } - ELSE - { - L_tmp_ener = L_add(0,*Enew); - *last_allow_cn_step = 0; - move16(); - } - } - ELSE - { - /* normal CNG update */ - IF ( *last_allow_cn_step == 0 ) - { - /**lp_ener = (float)(A2 * *Enew + (1-A2) * *lp_ener);*/ - L_tmp_ener = Mult_32_16(*Enew, A2); - L_tmp_ener = Madd_32_16(L_tmp_ener, *lp_ener, OmA2); - } - ELSE - { - test(); - if ( L_sub(core_brate,SID_1k75) == 0 || L_sub(core_brate,SID_2k40) == 0 ) - { - *last_allow_cn_step = 0; - move16(); - } - - L_tmp_ener = *Enew; - move32(); - - } - } - *lp_ener = L_max(L_tmp_ener,1); - move32(); /*To avoid / per 0*/ - - if ( sub(allow_cn_step,1) == 0) - { - *last_allow_cn_step = 1; - move16(); - } - - /*---------------------------------------------------------------------* - * Generate white noise vector - *---------------------------------------------------------------------*/ - - /*for ( i=0; i 0) - { - exp = add(exp, 1); - } - if (sub(tmp, tmp2) > 0) - { - tmp = shr(tmp, 1); - } - tmp = div_s(tmp, tmp2); - - L_tmp = L_deposit_h(tmp); - - L_tmp = Isqrt_lc(L_tmp, &exp); - tmp = extract_h(L_tmp); - - exp = add(exp, 4); /* From Q15 to Q19 */ - exp = add(exp, Q_exc); /* Q_exc+ Q19 */ - - FOR (i=0; i Q_exc +16 */ - exc2[i_subfr+i] = round_fx(L_shl(L_tmp, exp)); - } - } - IF ( sub(Opt_AMR_WB,1) != 0 ) - { - Copy( exc2, exc3, L_FRAME16k); - - /* enr1 = (float)log10( *Enew*L_frame + 0.1f ) / (float)log10( 2.0f ); */ - exp = norm_l(*Enew); - L_tmp = L_shl(*Enew,exp); /* Q(exp+6) */ - L_tmp = Mult_32_16(L_tmp,shl(L_frame,5)); /* Q(exp+6+5-15=exp-4) */ - L_tmp = L_shr(L_tmp,sub(exp,10)); /* Q6 */ - - exp = norm_l(L_tmp); - fra = Log2_norm_lc(L_shl(L_tmp,exp)); - exp = sub(sub(30,exp),6); - L_tmp = L_Comp(exp,fra); - /* enr1 = round_fx(L_shl(L_tmp,8)); */ /*Q8 */ - enr1 = L_shr(L_tmp,10);/* Q6 */ - - - IF ( L_sub(core_brate,SID_2k40) == 0 ) - { - IF ( *sid_bw == 0 ) - { - FOR ( i=0; i 0) - { - exp = add(exp, 1); - } - if (sub(tmp2, tmp) > 0) - { - tmp2 = shr(tmp2, 1); - } - tmp = div_s(tmp2, tmp); - L_tmp = L_deposit_h(tmp); - L_tmp = Isqrt_lc(L_tmp, &exp); /*Q(31-exp)*/ - - L_tmp2 = Mult_32_16(L_tmp,*ptR);/*Q(16-exp)*/ - *ptR = extract_h(L_shl(L_tmp2,add(exp,Q_exc))); /*Q_exc*/ - L_tmp2 = Mult_32_16(L_tmp,*ptI);/*Q(16-exp)*/ - *ptI = extract_h(L_shl(L_tmp2,add(exp,Q_exc))); /*Q_exc*/ - - ptR++; - ptI--; - } - - ifft_rel_fx(fft_io, L_FFT, LOG2_L_FFT); - - IF ( sub(L_frame,L_FRAME16k) == 0 ) - { - modify_Fs_fx( fft_io, L_FFT, 12800, fft_io, 16000, exc_mem, 0 ); - } - - /* enr1 = dotp( fft_io, fft_io, L_frame ) / L_frame; */ - - enr1 = L_deposit_l(1); - pt_fft_io = fft_io; - IF( sub(L_frame, L_FRAME) == 0) - { - FOR (j=0; j<128; j++) - { - L_tmp = L_mult0(*pt_fft_io, *pt_fft_io); - pt_fft_io++; - L_tmp = L_mac0(L_tmp, *pt_fft_io, *pt_fft_io); /* 2*(Q_exc) */ - pt_fft_io++; - enr1 = L_add(enr1, L_shr(L_tmp, 7)); /* 2*(Q_exc)+1, divide by L_frame done here */ - } - } - ELSE /* L_FRAME16k */ - { - FOR (j=0; j<160; j++) - { - L_tmp = L_mult0(*pt_fft_io, *pt_fft_io); - pt_fft_io++; - L_tmp = L_mac0(L_tmp, *pt_fft_io, *pt_fft_io); /* 2*(Q_exc) */ - pt_fft_io++; - enr1 = L_add(enr1, L_shr(Mult_32_16(L_tmp,26214 /* 256/320, Q15 */), 7)); /* 2*(Q_exc)+15+1-16+1, divide by L_frame done here */ - } - } - enr1 = L_shr(enr1,sub(add(Q_exc,Q_exc),5));/*Q6*/ - - /* add time domain randomization */ - FOR ( i_subfr=0; i_subfr 0) - { - exp = add(exp, 1); - } - if (sub(tmp, tmp2) > 0) - { - tmp = shr(tmp, 1); - } - tmp = div_s(tmp, tmp2); - - L_tmp = L_deposit_h(tmp); - L_tmp = Isqrt_lc(L_tmp, &exp);/*Q(31-exp)*/ - test(); - test(); - test(); - IF( L_sub(last_core_brate,SID_2k40) != 0 && L_sub(last_core_brate,SID_1k75) != 0 && L_sub(last_core_brate,FRAME_NO_DATA) != 0 && L_sub(core_brate,SID_2k40) == 0 ) - { - IF ( L_sub(L_tmp,L_shl(1,sub(31,exp))) > 0 ) - { - L_tmp = L_shl(1,sub(31,exp)); - } - } - - tmp = extract_h(L_tmp); - FOR (i=0; i 0) - { - exp = add(exp, 1); - } - if (sub(tmp2, tmp) > 0) - { - tmp2 = shr(tmp2, 1); - } - tmp = div_s(tmp2, tmp); - L_tmp = L_deposit_h(tmp); - L_tmp = Isqrt_lc(L_tmp, &exp); /*Q(31-exp)*/ - - ftmp = extract_h(L_shl(L_tmp,exp));/* Q15 */ - FOR (i=0; i 0 ) - { - CNG_mode = 4; - } - ELSE IF( L_sub(last_active_brate,ACELP_9k60) > 0 ) - { - CNG_mode = 3; - } - ELSE IF( L_sub(last_active_brate,ACELP_8k00) > 0 ) - { - CNG_mode = 2; - } - ELSE IF( L_sub(last_active_brate,ACELP_7k20) > 0 ) - { - CNG_mode = 1; - } - ELSE - { - CNG_mode = 0; - } - - /* att = 1/pow(2,ENR_ATT_fx[CNG_mode]); */ - L_tmp = L_shl(L_deposit_l(ENR_ATT_fx[CNG_mode]), 8);/* 16 */ - temp_lo_fx = L_Extract_lc(L_tmp, &temp_hi_fx); - - exp_pow = sub(14, temp_hi_fx); - L_tmp = Pow2(14, temp_lo_fx); /* Qexp_pow */ - L_tmp = L_shl(L_tmp, sub(13, exp_pow)); /* Q13 */ - tmp = extract_l(L_tmp);/* Q13 */ - - exp1 = norm_s(tmp); - tmp = shl(tmp, exp1);/*Q(exp1+13) */ - tmp = div_s(16384,tmp); /*Q(15+14-exp1-13) */ - tmp = shr(tmp,sub(1,exp1));/* Q15 */ - - FOR ( i=0; i 0 ) - { - *cng_buf_cnt = HO_HIST_SIZE; - move16(); - } - Copy( exc2, &(cng_exc2_buf[(*ho_circ_ptr)*L_FFT]), L_FFT ); - cng_Qexc_buf[*ho_circ_ptr] = Q_exc; - move16(); - cng_brate_buf[*ho_circ_ptr] = last_active_brate; - move16(); - } - ELSE - { - /* calculate the spectrum of residual signal */ - Copy(exc2, fft_io, L_frame); - - fft_rel_fx(fft_io, L_FFT, LOG2_L_FFT); - - ptR = &fft_io[1]; - ptI = &fft_io[L_FFT-1]; - FOR (i=0; i 0 ) - { - CNG_mode = 4; - } - ELSE IF( L_sub(last_active_brate,ACELP_9k60) > 0 ) - { - CNG_mode = 3; - } - ELSE IF( L_sub(last_active_brate,ACELP_8k00) > 0 ) - { - CNG_mode = 2; - } - ELSE IF( L_sub(last_active_brate,ACELP_7k20) > 0 ) - { - CNG_mode = 1; - } - ELSE - { - CNG_mode = 0; - } - - /* att = 1/pow(2,ENR_ATT_fx[CNG_mode]); */ - L_tmp = L_shl(L_deposit_l(ENR_ATT_fx[CNG_mode]), 8);/* 16 */ - temp_lo_fx = L_Extract_lc(L_tmp, &temp_hi_fx); - - exp_pow = sub(14, temp_hi_fx); - L_tmp = Pow2(14, temp_lo_fx); /* Qexp_pow */ - L_tmp = L_shl(L_tmp, sub(13, exp_pow)); /* Q13 */ - tmp = extract_l(L_tmp);/* Q13 */ - - exp1 = norm_s(tmp); - tmp = shl(tmp, exp1);/*Q(exp1+13) */ - tmp = div_s(16384,tmp); /*Q(15+14-exp1-13) */ - tmp = shr(tmp,sub(1,exp1));/* Q15 */ - - FOR ( i=0; i 0 ) - { - *ho_circ_size = HO_HIST_SIZE; - move16(); - } - - return; -} diff --git a/src/libs/libevs/lib_com/cnst_fx.h b/src/libs/libevs/lib_com/cnst.h old mode 100755 new mode 100644 similarity index 60% rename from src/libs/libevs/lib_com/cnst_fx.h rename to src/libs/libevs/lib_com/cnst.h index 7070c76e..2b323db4 --- a/src/libs/libevs/lib_com/cnst_fx.h +++ b/src/libs/libevs/lib_com/cnst.h @@ -1,46 +1,35 @@ /*==================================================================================== - EVS Codec 3GPP TS26.442 Apr 03, 2018. Version 12.11.0 / 13.6.0 / 14.2.0 + EVS Codec 3GPP TS26.443 Nov 13, 2018. Version 12.11.0 / 13.7.0 / 14.3.0 / 15.1.0 ====================================================================================*/ -#ifndef CNST_FX_H -#define CNST_FX_H +#ifndef CNST_H +#define CNST_H -#include "options.h" /* Compilation switches */ - - -#define MODE1 1 -#define MODE2 2 +#include "options.h" /*----------------------------------------------------------------------------------* - * General constants + * General constants *----------------------------------------------------------------------------------*/ -#define LT_UV_THR_FX (100*64) /* in Q6 */ -#define INV_MAX_LT_FX (Word16)((1.0f/MAX_LT)*32768) +#define MODE1 1 +#define MODE2 2 -#define EVS_PI 3.14159265358979323846264338327950288f - -#define LG10 24660 /* 10*log10(2) in Q13 */ - - - -#define EVS_LW_MIN (Word32)0x80000000 -#define EVS_LW_MAX (Word32)0x7fffffff - -#define EVS_SW_MAX (Word16)0x7fff /* largest Ram */ - - -/***************** FROM cnst.h ******************/ +#define EVS_PI 3.14159265358979323846264338327950288f +#define PI2 (2*EVS_PI) #define RANDOM_INITSEED 21845 /* Seed for random generators */ +#ifndef FLT_MIN +#define FLT_MIN (1.175494351e-38F) +#endif +#ifndef FLT_MAX +#define FLT_MAX (3.402823466e+38F) +#endif +#define TRUE 1 +#define FALSE 0 + + #define MAX_FRAME_COUNTER 200 -#define BITS_PER_SHORT 16 -#define BITS_PER_BYTE 8 #define MAX_BITS_PER_FRAME 2560 -#define SYNC_GOOD_FRAME (UWord16) 0x6B21 /* synchronization word of a "good" frame */ -#define SYNC_BAD_FRAME (UWord16) 0x6B20 /* synchronization word of a "bad" frame */ -#define G192_BIN0 (UWord16) 0x007F /* binary "0" according to ITU-T G.192 */ -#define G192_BIN1 (UWord16) 0x0081 /* binary "1" according to ITU-T G.192 */ #define ENC 0 /* Index for "encoder" */ #define DEC 1 /* Index for "decoder" */ @@ -59,14 +48,26 @@ #define L_FRAME8k 160 /* Frame size in samples at 8kHz */ /* Conversion of ns to samples for a given sampling frequency */ -#define NS2SA(fs,x) ((short)((((long)(fs)/100L) * ((x)/100L)) / 100000L)) +#define NS2SA(fs,x) (short)((((long)(fs)/100L) * ((x)/100L)) / 100000L) + +#define SYNC_GOOD_FRAME (unsigned short) 0x6B21 /* synchronization word of a "good" frame */ +#define SYNC_BAD_FRAME (unsigned short) 0x6B20 /* synchronization word of a "bad" frame */ +#define G192_BIN0 (unsigned short) 0x007F /* binary "0" according to ITU-T G.192 */ +#define G192_BIN1 (unsigned short) 0x0081 /* binary "1" according to ITU-T G.192 */ + +#define ACTIVE_FRAME 0xFF +#define SID_FRAME 0xFA +#define ZERO_FRAME 0xF0 +#define FRAME_SIZE_NB 13 + +#define RATE_MODE_MAX 2 /* Number of rate mode */ +#define BANDWIDTH_MODE_MAX 2 /* Number of different bandwidth (NB/WB-FB) */ + +#define MIN_LOG_60dB 0.000001f +#define MIN_LOG_VAL_60dB -60.0f + +#define INV_LOG_2 1.442695040888963f /* 1/log(2) */ -extern const Word16 Idx2Freq_Tbl[]; -#define chk_fs(fs) -/* 'x' is converted to Q6, 'Freq_Tbl'/1000 in Q9 */ -/* only works for 'fs' = [8000,12800,16000,25600,32000,48000] (unpredictable otherwise) */ -/* 15625 is 1000000.0f/Q6 but we use the calculated value to avoid float point code */ -#define NS2SA_fx2(fs,x) (chk_fs(fs) mult((&Idx2Freq_Tbl[-2])[L_and(L_shr(fs,8),7)], (Word16)((x)/15625))) /*----------------------------------------------------------------------------------* * Layers @@ -78,15 +79,16 @@ extern const Word16 Idx2Freq_Tbl[]; #define HQ_CORE 3 /* HQ core layer */ #define AMR_WB_CORE 4 /* AMR-WB IO core */ + #define WB_TBE 5 /* WB TBE layer (16/32/48kHz signals) */ #define WB_BWE 6 /* WB BWE layer optimized for music (16/32/48kHz signals) */ #define SWB_CNG 7 /* SWB CNG layer (32/48kHz signals) */ #define SWB_TBE 8 /* SWB TBE layer optimized for speech (32/48kHz signals) */ #define SWB_BWE 9 /* SWB BWE layer optimized for music (32/48kHz signals) */ -#define SWB_BWE_HIGHRATE 10 /* SWB BWE layer optimized for highrate speech (32/48kHz) */ +#define SWB_BWE_HIGHRATE 10 /* SWB BWE layer optimized for highrate speech (32/48kHz) */ -#define FB_TBE 11 /* FB TBE layer (48kHz signals) */ +#define FB_TBE 11 /* FB TBE layer (48kHz signals) */ #define FB_BWE 12 /* FB BWE layer optimized for music (48kHz) */ #define FB_BWE_HIGHRATE 13 /* FB BWE layer optimized for highrate speech (48kHz) */ @@ -99,11 +101,10 @@ extern const Word16 Idx2Freq_Tbl[]; * Bitrates *----------------------------------------------------------------------------------*/ -#define FRAME_NO_DATA 0 /* Frame with no data */ +#define FRAME__NO_DATA 0 /* Frame with no data */ #define SID_1k75 1750 /* SID at 1.75 kbps (used only in AMR-WB IO mode */ #define SID_2k40 2400 /* SID at 2.40 kbps */ #define PPP_NELP_2k80 2800 /* PPP and NELP at 2.80 kbps (used only for SC-VBR) */ - #define ACELP_5k90 5900 /* ACELP core layer at average bitrate of 5.90 kbps (used only in SC-VBR mode) */ #define ACELP_6k60 6600 /* ACELP core layer at 6.60 kbps (used only in AMR-WB IO mode) */ #define ACELP_7k20 7200 /* ACELP core layer at 7.20 kbps */ @@ -116,12 +117,12 @@ extern const Word16 Idx2Freq_Tbl[]; #define ACELP_12k85 12850 /* ACELP core layer at 12.85 kbps (used for WB BWE) */ #define ACELP_13k20 13200 /* ACELP core layer at 13.20 kbps */ #define ACELP_14k25 14250 /* ACELP core layer at 14.25 kbps (used only in AMR-WB IO mode) */ -#define ACELP_14k80 14800 /* ACELP core layer at 14.80 kbps (used for core switching only) */ +#define ACELP_14k80 14800 /* ACELP core layer at 14.80 kbps (used only in core switching) */ #define ACELP_15k85 15850 /* ACELP core layer at 15.85 kbps (used only in AMR-WB IO mode) */ #define ACELP_16k40 16400 /* ACELP core layer at 16.40 kbps */ #define ACELP_18k25 18250 /* ACELP core layer at 18.25 kbps (used only in AMR-WB IO mode) */ #define ACELP_19k85 19850 /* ACELP core layer at 19.85 kbps (used only in AMR-WB IO mode) */ -#define ACELP_22k60 22600 /* ACELP core layer at 22.60 kbps (used for core switching only) */ +#define ACELP_22k60 22600 /* ACELP core layer at 22.60 kbps (used only in core switching) */ #define ACELP_23k05 23050 /* ACELP core layer at 23.05 kbps (used only in AMR-WB IO mode) */ #define ACELP_23k85 23850 /* ACELP core layer at 23.85 kbps (used only in AMR-WB IO mode) */ #define ACELP_24k40 24400 /* ACELP core layer at 24.40 kbps */ @@ -149,26 +150,66 @@ extern const Word16 Idx2Freq_Tbl[]; #define SWB_BWE_1k6 1600 /* SWB BWE layer */ #define FB_TBE_1k8 1800 /* SWB+FB TBE layer (used only for 48kHz signals) */ #define FB_BWE_1k8 1800 /* SWB+FB BWE layer (used only for 48kHz signals) */ - #define SWB_TBE_2k8 2800 /* SWB TBE layer @32kbps */ #define FB_TBE_3k0 3000 /* SWB+FB TBE layer @32kbps (used only for 48kHz signals) */ - #define SWB_BWE_16k 16000 /* SWB BWE layer for highrate SWB speech */ +#define SIZE_BRATE_TBL 11 + +#define BRATE2IDX(brate) ( brate == ACELP_7k20 ? 0: \ + brate == ACELP_8k00 ? 1 : \ + brate == ACELP_11k60 ? 2 : \ + brate == ACELP_12k15 ? 3 : \ + brate == ACELP_12k85 ? 4 : \ + brate == ACELP_13k20 ? 5 : \ + brate == ACELP_14k80 ? 6 : \ + brate == ACELP_16k40 ? 7 : \ + brate == ACELP_22k60 ? 8 : \ + brate == ACELP_24k40 ? 9 : \ + brate == ACELP_29k00 ? 10 : \ + brate == ACELP_29k20 ? 11 : \ + brate == ACELP_30k20 ? 12 : \ + brate == ACELP_30k40 ? 13 : \ + brate == ACELP_32k ? 14 : \ + brate == ACELP_48k ? 15 : \ + brate == ACELP_64k ? 16 : \ + brate == HQ_96k ? 17 : \ + brate == HQ_128k ? 18 : -1 ) + +#define BRATE2IDX16k( brate ) ( brate == ACELP_8k00 ? 0 : \ + brate == ACELP_14k80 || brate == ACELP_16k40? 1 : \ + brate == ACELP_22k60 ? 2 : \ + brate == ACELP_24k40 ? 3 : \ + brate == ACELP_29k00 ? 4 : \ + brate == ACELP_29k20 ? 5 : \ + brate == ACELP_30k20 ? 6 : \ + brate == ACELP_30k40 ? 7 : \ + brate == ACELP_32k ? 8 : \ + brate == ACELP_48k ? 9 : \ + brate == ACELP_64k ? 10: -1 ) + /* Combine parameters into a single index (used to retrieve number of bits from bit allocation tables) */ -#define LSF_BIT_ALLOC_IDX_fx(brate,ctype) (L_mac0(L_mult0(6, BRATE2IDX_fx(brate)), (ctype), 1)) +#define LSF_BIT_ALLOC_IDX(brate, ctype) ( 6*BRATE2IDX(brate) + (ctype) ) + +#define BIT_ALLOC_IDX(brate, ctype, sfrm, tc) \ + ( ( sfrm != -1 ? NB_SUBFR : 1 ) * \ + ( ( tc == -1 ? 4 : 10 ) * BRATE2IDX(brate) + (ctype == INACTIVE ? GENERIC : ctype) - 1 + (tc == -1 ? 0 : tc) ) + \ + ( sfrm != -1 ? sfrm/L_SUBFR : 0 ) ) + +#define BIT_ALLOC_IDX_16KHZ(brate, ctype, sfrm, tc) \ + ( ( sfrm > -1 ? NB_SUBFR16k : 1 ) * \ + ( ( tc == -1 ? 3 : 7 ) * BRATE2IDX16k(brate) + (ctype == TRANSITION ? 2 : (ctype == GENERIC ? 1 :0) ) + (tc == -1 ? 0 : tc) ) + \ + ( sfrm != -1 ? sfrm/L_SUBFR : 0 ) ) /* Combine coder_type, bandwidth, formant sharpening flag, and channel-aware flag into one indice */ -#define SIG2IND_fx(ctype, bw, sf, ca_rf) L_mac0(L_mac0(L_mac0(L_mult0(ctype, 1), bw, 1<<3), sf, 1<<6), ca_rf, 1<<7) - -#define SIZE_BRATE_TBL 11 +#define SIG2IND(ctype, bw, sf, ca_rf) ( ctype | (bw << 3) | (sf << 6) | (ca_rf << 7) ) #define MAX_ACELP_SIG 100 /*----------------------------------------------------------------------------------* * Bitstream indices *----------------------------------------------------------------------------------*/ - +#define MAX_PVQ_PUSH_IND 320 /* Maximum number of (fwd+reverse) calls to push_indices for the PVQ_range encoder */ enum { IND_CORE, @@ -183,7 +224,6 @@ enum IND_VAD_FLAG, IND_HQ_BWIDTH, IND_TC_SUBFR, - IND_LSF_PREDICTOR_SELECT_BIT = IND_TC_SUBFR + 4, IND_LSF, IND_MID_FRAME_LSF_INDEX = IND_LSF + 17, @@ -276,7 +316,7 @@ enum IND_HQ2_P2A_FLAGS = IND_HQ2_DIFF_ENERGY + 100, IND_HQ2_LAST_BA_MAX_BAND = IND_HQ2_P2A_FLAGS + 60, IND_RC_START = IND_HQ2_LAST_BA_MAX_BAND + 2, - IND_RC_END = IND_RC_START + 320, + IND_RC_END = IND_RC_START + MAX_PVQ_PUSH_IND , IND_HVQ_PVQ_GAIN = IND_RC_END+1, IND_NOISINESS = IND_HVQ_PVQ_GAIN + 8, IND_ENERGY, @@ -345,7 +385,6 @@ enum MAX_NUM_INDICES = IND_UNUSED + 127 }; - /*----------------------------------------------------------------------------------* * Delays *----------------------------------------------------------------------------------*/ @@ -360,19 +399,19 @@ enum #define DELAY_SWB_TBE_16k_NS 1125000L #define MAX_DELAY_TBE_NS 1312500L #define DELAY_BWE_TOTAL_NS 2312500L -#define DELAY_FD_BWE_ENC_12k8_NS (DELAY_BWE_TOTAL_NS - (MAX_DELAY_TBE_NS - DELAY_SWB_TBE_12k8_NS)) -#define DELAY_FD_BWE_ENC_16k_NS (DELAY_BWE_TOTAL_NS - (MAX_DELAY_TBE_NS - DELAY_SWB_TBE_16k_NS)) +#define DELAY_FD_BWE_ENC_12k8_NS (DELAY_BWE_TOTAL_NS - (MAX_DELAY_TBE_NS - DELAY_SWB_TBE_12k8_NS)) +#define DELAY_FD_BWE_ENC_16k_NS (DELAY_BWE_TOTAL_NS - (MAX_DELAY_TBE_NS - DELAY_SWB_TBE_16k_NS)) #define DELAY_FD_BWE_ENC_NS 2250000L -#define L_LOOK_12k8 NS2SA(INT_FS_FX, ACELP_LOOK_NS) /* look-ahead length at 12.8kHz */ -#define L_LOOK_16k NS2SA(INT_FS_16k_FX, ACELP_LOOK_NS) /* look-ahead length at 16kHz */ +#define L_LOOK_12k8 NS2SA(INT_FS_12k8, ACELP_LOOK_NS) /* look-ahead length at 12.8kHz */ +#define L_LOOK_16k NS2SA(INT_FS_16k, ACELP_LOOK_NS) /* look-ahead length at 16kHz */ /* core switching constants @16kHz */ -#define SWITCH_GAP_LENGTH_NS 6250000L /* lenght of ACELP->HQ switching gap in ms */ +#define SWITCH_GAP_LENGTH_NS 6250000L /* lenght of ACELP->HQ switching gap in ms */ #define HQ_DELAY_COMP NS2SA(8000, DELAY_CLDFB_NS) -#define HQ_DELTA_MAX 6 /* maximum multiplication factor (==48kHz/8kHz) for core switching modules */ +#define HQ_DELTA_MAX 6 /* maximum multiplication factor (==48kHz/8kHz) for core switching modules */ -#define N_ZERO_MDCT_NS 5625000L /* Number of zeros in ms for MDCT */ +#define N_ZERO_MDCT_NS 5625000L /* number of zeros in ms for MDCT */ #define NL_BUFF_OFFSET 12 #define N_WS2N_FRAMES 40 /* number of frames for attenuation during the band-width switching */ @@ -390,56 +429,55 @@ enum #define AUDIO 5 /* audio (GSC) */ #define LR_MDCT 6 /* low-rate MDCT core */ - /*--------------------------------------------------* * Partial copy frame types (only for ACELP core ) *--------------------------------------------------*/ +#define ACELP_MODE_MAX 4 +#define RF_MODE_MAX 4 + /* TCX partial copy frame types */ -#define RF_NO_DATA 0 +#define RF__NO_DATA 0 #define RF_TCXFD 1 #define RF_TCXTD1 2 #define RF_TCXTD2 3 + /* ACELP partial copy frame types */ -#define RF_ALLPRED ACELP_MODE_MAX -#define RF_NOPRED ACELP_MODE_MAX + 1 -#define RF_GENPRED ACELP_MODE_MAX + 2 -#define RF_NELP ACELP_MODE_MAX + 3 +#define RF_ALLPRED ACELP_MODE_MAX +#define RF_NOPRED ACELP_MODE_MAX + 1 +#define RF_GENPRED ACELP_MODE_MAX + 2 +#define RF_NELP ACELP_MODE_MAX + 3 /*--------------------------------------------------------------* - * MODE2 Frame length constants + * Frame length constants in mode 2 *---------------------------------------------------------------*/ -#define L_FRAME_MAX 960 /* Max 20ms frame size @48kHz */ -#define L_FRAME_PLUS 1200 /* Max frame size (long TCX frame) */ -#define L_MDCT_OVLP_MAX NS2SA(48000,ACELP_LOOK_NS) /* = Max mdct overlap */ -#define N_TCX10_MAX 480 /* Max size of TCX10 MDCT size */ -#define BITS_TEC 1 /* number of bits for TEC */ -#define BITS_TFA 1 /* number of bits for TTF */ -#define N_TEC_TFA_SUBFR 16 /* number of subframes of TEC/TFA */ -#define L_TEC_TFA_SUBFR16k (L_FRAME16k/N_TEC_TFA_SUBFR) /* TEC/TFA subframe size @ 16kHz*/ -#define MAX_TEC_SMOOTHING_DEG 6 /* max degree of smoothing for TEC */ -#define N_MAX 1200 /* Max size of MDCT spectrum = 25ms @ 48kHz */ -#define N_MAX_TCX 1000 /* Max size of MDCT spectrum = 25ms @ 48kHz */ -#define IGF_START_MN 164 /* MDCT lines not used by IGF*/ -#define IGF_START_MX 800 /* max. MDCT lines used by IGF*/ +#define ACELP_TCX_TRANS_NS 1250000 /* Duration of the ACELP->TCX overlap - 1.25 ms */ +#define L_FRAME_MAX 960 /* Max 20ms frame size @48kHz */ +#define L_FRAME_PLUS 1200 /* Max frame size (long TCX frame) */ +#define L_MDCT_OVLP_MAX NS2SA(48000,ACELP_LOOK_NS) /* = Max mdct overlap */ +#define N_TCX10_MAX 480 /* Max size of TCX10 MDCT spectrum */ +#define BITS_TEC 1 /* number of bits for TEC */ +#define BITS_TFA 1 /* number of bits for TTF */ +#define N_TEC_TFA_SUBFR 16 /* number of subframes of TEC/TFA */ +#define L_TEC_TFA_SUBFR16k (L_FRAME16k/N_TEC_TFA_SUBFR) /* TEC/TFA subframe size @ 16kHz*/ +#define MAX_TEC_SMOOTHING_DEG 6 /* max degree of smoothing for TEC */ +#define N_MAX 1200 /* Max size of MDCT spectrum = 25ms @ 48kHz */ +#define N_MAX_TCX 1000 /* Max size of TCX/IGF coded lines */ +#define IGF_START_MN 164 /* MDCT lines not used by IGF*/ +#define IGF_START_MX 800 /* max. MDCT lines used by IGF*/ -#define L_FRAME_12k8 256 /* Frame size at 12k8Hz: 20ms = 256 samples */ -#define L_FRAME_16k 320 /* Frame size at 16kHz: 20ms = 320 samples */ -#define L_NEXT_MAX_12k8 112 /* maximum encoder lookahead at 12k8Hz */ -#define L_PAST_MAX_12k8 144 /* maximum encoder past samples at 12k8Hz */ -#define L_DIV 256 /* 20ms frame size (ACELP or short TCX frame) */ -#define L_DIV_MAX 320 -#define NB_DIV 2 /* number of division (frame) per 20ms frame */ -#define NB_SUBFR 4 /* number of 5ms subframe per 20ms frame */ +#define NUM_DCT_LENGTH 24 -#define L_NEXT_MAX_16k 140 /* maximum encoder lookahead at 16kHz */ -#define L_NEXT_MAX_32k 280 /* maximum encoder lookahead at 32kHz */ -#define L_PAST_MAX_32k 360 /* maximum encoder past samples at 32kHz */ +#define NB_DIV 2 /* number of division (frame) per 20ms frame */ +#define L_MDCT_HALF_OVLP_MAX (L_MDCT_OVLP_MAX/2) /* Size of the MDCT half overlap @ 48 kHz */ +#define L_MDCT_MIN_OVLP_MAX 60 /* Size of the MDCT minimal overlap @ 48 kHz - 1.25ms */ +#define L_MDCT_TRANS_OVLP_MAX NS2SA(48000, ACELP_TCX_TRANS_NS) /* Size of the ACELP->MDCT transition overlap - 1.25ms */ -#define MIDLSF_NBITS 5 -#define ENDLSF_NBITS 31 +#define L_NEXT_MAX_16k NS2SA(16000, ACELP_LOOK_NS) /* 140 */ /* maximum encoder lookahead at 16kHz */ +#define L_NEXT_MAX_32k NS2SA(32000, ACELP_LOOK_NS) /* 280 */ /* maximum encoder lookahead at 32kHz */ +#define L_PAST_MAX_32k 360 /* maximum encoder past samples at 32kHz */ /*----------------------------------------------------------------------------------* * ACELP core constants @@ -449,64 +487,57 @@ enum #define MOVING_AVERAGE 1 #define AUTO_REGRESSIVE 2 -#define ACELP_MODE_MAX 4 - -#define RF_MODE_MAX 4 - -#define M 16 /* order of the LP filter @ 12.8kHz */ -#define L_FRAME 256 /* frame size at 12.8kHz */ -#define NB_SUBFR 4 /* number of subframes per frame */ -#define L_SUBFR (L_FRAME/NB_SUBFR) /* subframe size */ -#define L_SUBFR_Q6 ((L_FRAME/NB_SUBFR)*64) /* subframe size */ -#define L_SUBFR_Q16 ((L_FRAME/NB_SUBFR)*65536) /* subframe size */ +#define INT_FS_12k8 12800 /* internal sampling frequency */ +#define M 16 /* order of the LP filter @ 12.8kHz */ +#define L_FRAME 256 /* frame size at 12.8kHz */ +#define NB_SUBFR 4 /* number of subframes per frame */ +#define L_SUBFR (L_FRAME/NB_SUBFR) /* subframe size */ #define L_INP_MEM (L_LOOK_16k + ((L_LP_16k - (NS2SA(INT_FS_16k, ACELP_LOOK_NS) + L_SUBFR16k/2)) - 3*L_SUBFR16k/2)) /* length of memory of input signal, given by the Look-Ahead + the past memory (max needed for the LP window at 16 kHz) */ -#define L_INP_12k8 (L_INP_MEM + L_FRAME) /* length of input signal buffer @12.8kHz */ -#define L_INP (L_INP_MEM + L_FRAME32k) /* length of input signal buffer */ +#define L_INP_12k8 (L_INP_MEM + L_FRAME) /* length of input signal buffer @12.8kHz */ +#define L_INP (L_INP_MEM + L_FRAME32k) /* length of input signal buffer @32kHz */ -#define L_EXC_MEM L_FRAME16k /*(PIT16k_MAX + L_INTERPOL)*/ /* length of memory of excitation signal */ +#define L_EXC_MEM L_FRAME16k /* length of memory of excitation signal @16kHz */ #define L_EXC_MEM_12k8 (PIT_MAX + L_INTERPOL) /* length of memory of excitation signal @12.8kHz */ -#define L_EXC_MEM_DEC (3*L_FRAME16k/2) /*Half-frame needed for MODE2 PLC in case of TCX->ACELP*/ -#define L_EXC (L_EXC_MEM + L_FRAME16k + 1) /* length of excitation signal buffer */ +#define L_EXC_MEM_DEC (3*L_FRAME16k/2) /*Half-frame needed for PLC in case of TCX->ACELP*/ +#define L_EXC (L_EXC_MEM + L_FRAME16k + 1) /* length of encoder excitation signal buffer @16kHz*/ #define L_EXC_DEC (L_EXC_MEM_DEC + L_FRAME16k + 1 + L_SUBFR) /* length of decoder excitation signal buffer @16kHz*/ -#define L_SYN_MEM NS2SA(48000,DELAY_CLDFB_NS) /* synthesis memory length, 1.25ms @ 48kHz */ -#define L_SYN (L_SYN_MEM + L_FRAME16k) /* length of synthesis signal buffer */ -#define L_WSP_MEM (PIT_MAX + L_INTERPOL) /* length of memory for weighted input signal */ -#define L_WSP (L_WSP_MEM + L_FRAME + L_LOOK_12k8) /* length of weighted input signal buffer */ +#define L_SYN_MEM NS2SA(48000,DELAY_CLDFB_NS) /* synthesis memory length, 1.25ms @ 48kHz */ +#define L_SYN (L_SYN_MEM + L_FRAME16k) /* length of synthesis signal buffer @16kHz */ +#define L_WSP_MEM (PIT_MAX + L_INTERPOL) /* length of memory for weighted input signal @12.8kHz*/ +#define L_WSP (L_WSP_MEM + L_FRAME + L_LOOK_12k8) /* length of weighted input signal buffer @12.8kHz*/ #define OLD_SYNTH_SIZE_DEC (2*L_FRAME_MAX) /* decoder past synthesis; needed for LTP, PLC and rate switching*/ #define OLD_SYNTH_INTERNAL_DEC (2*L_FRAME32k) /* decoder past synthesis @ internal sampling rate; needed for LTP, PLC and rate switching*/ -#define OLD_SYNTH_SIZE_ENC L_FRAME32k+L_FRAME32k/4 /* Frame size in samples at 25.6 kHz */ -#define OLD_EXC_SIZE_DEC (3*L_FRAME_MAX/2+2*L_FIR_FER2) /*old excitation needed for decoder for PLC*/ +#define OLD_SYNTH_SIZE_ENC L_FRAME32k+L_FRAME32k/4 /* encoder synth memory */ +#define OLD_EXC_SIZE_DEC (3*L_FRAME_MAX/2+2*L_FIR_FER2) /*old excitation needed for decoder for PLC*/ -#define TILT_CODE 9830 /* ACELP code preemphasis factor ~=0.3f (0Q15) (=0.299987792968750) */ +#define TILT_CODE 0.3f /* ACELP code preemphasis factor */ -#define L_SUBFR16k (L_FRAME16k/NB_SUBFR) /* subframe size at 16kHz */ -#define L_HALFR16k (2*L_SUBFR16k) /* half-frame size at 16kHz */ +#define L_SUBFR16k (L_FRAME16k/NB_SUBFR) /* subframe size at 16kHz */ +#define L_HALFR16k (2*L_SUBFR16k) /* half-frame size at 16kHz */ #define L_INTERPOL2 16 /* Length of filter for interpolation */ -#define L_INTERPOL (L_INTERPOL2+1) /* Length of filter for interpolation */ -#define TILT_FAC_FX 22282 /* tilt factor (denominator) fixed-point*/ -#define M16k 20 /* order of the LP filter @ 16kHz */ -#define PIT_SHARP_fx 27853 /* pitch sharpening factor */ -#define F_PIT_SHARP 0.85F /* pitch sharpening factor */ -#define PIT_UP_SAMP 4 -#define UP_SAMP 4 /* upsampling factor for 1/4 interpolation filter */ +#define L_INTERPOL (L_INTERPOL2+1) /* Length of filter for interpolation */ +#define TILT_FAC 0.68f /* tilt factor (denominator) */ +#define M16k 20 /* order of the LP filter @ 16kHz */ +#define PIT_SHARP 0.85f /* pitch sharpening factor */ +#define PIT_UP_SAMP 4 /* upsampling factor for 1/4 interpolation filter */ #define PIT_L_INTERPOL2 16 #define PIT_FIR_SIZE2 (PIT_UP_SAMP*PIT_L_INTERPOL2+1) #define PIT_UP_SAMP6 6 #define PIT_L_INTERPOL6_2 17 #define PIT_FIR_SIZE6_2 (PIT_UP_SAMP6*PIT_L_INTERPOL6_2+1) -#define E_MIN_FX 1 /* QSCALE (Q7)*/ -#define STEP_DELTA_FX 11 -#define FORMANT_SHARPENING_NOISE_THRESHOLD_FX 5376 /* 21 (!8)lp_noise level above which formant sharpening is deactivated - at this level most of 20 dB SNR office noisy speech still uses sharpening */ -#define LP_NOISE_THRESH 167772160l/*20.f Q23*/ -#define LFAC 160 /* FAC maximum frame length */ +#define E_MIN 0.0035f /* minimum allowable energy */ +#define STEP_DELTA 0.0625f /* quantization step for tilt compensation of gaussian cb. excitation */ +#define GAMMA_EV 0.92f /* weighting factor for core synthesis error weighting */ +#define FORMANT_SHARPENING_NOISE_THRESHOLD 21.0f /* lp_noise level above which formant sharpening is deactivated */ +#define BWD_N_BINS_MAX 13 +#define LP_NOISE_THRESH 20.f #define L_FILT_UP8k 24 /* Resampling - delay of filter for 8 kHz output signals (at 12.8 kHz sampling rate) */ #define LEN_WIN_SSS 120 -#define L_FILT 12 /* Delay of the low-pass filter in the BPF */ -#define L_FILT8k 16 /* Resampling - delay of filter for 8 kHz input signals (at 8kHz sampling rate) */ +#define L_FILT 12 /* Resampling - delay of the resampling low-pass filter @12.8kHz */ #define L_FILT16k 15 /* Resampling - delay of filter for 16 kHz input signals (at 16kHz sampling rate) */ #define L_FILT32k 30 /* Resampling - delay of filter for 32 kHz input signals (at 32kHz sampling rate) */ #define L_FILT48k 45 /* Resampling - delay of filter for 48 kHz input signals (at 48kHz sampling rate) */ @@ -519,38 +550,35 @@ enum #define CLDFB_NO_CHANNELS_MAX 60 /* CLDFB resampling - max number of CLDFB channels */ #define CLDFB_NO_COL_MAX 16 /* CLDFB resampling - max number of CLDFB col. */ #define CLDFB_NO_COL_MAX_SWITCH 6 /* CLDFB resampling - max number of CLDFB col. for switching */ -#define CLDFB_NO_COL_MAX_SWITCH_BFI 8 /* CLDFB resampling - max number of CLDFB col. for switching */ +#define CLDFB_NO_COL_MAX_SWITCH_BFI 8 /* CLDFB resampling - max number of CLDFB col. for switching, BFI */ +#define INV_CLDFB_BANDWIDTH (1.f/800.f) -#define CLDFB_ANALYSIS 0 -#define CLDFB_SYNTHESIS 1 +typedef enum +{ + CLDFB_ANALYSIS, + CLDFB_SYNTHESIS +} CLDFB_TYPE; #define L_FFT 256 /* Spectral analysis - length of the FFT */ #define LOG2_L_FFT 8 /* Spectral analysis - log2 of L_FFT */ - -#define BIN (INT_FS_FX/L_FFT)/* Spectral analysis - Width of one frequency bin in Hz */ +#define BIN (INT_FS_12k8/L_FFT)/* Spectral analysis - Width of one frequency bin in Hz */ #define NB_BANDS 20 /* Spectral analysis - number of frequency bands */ #define VOIC_BINS 74 /* Spectral analysis - max number of frequency bins considered as voiced (related to VOIC_BAND and L_FFT) */ #define VOIC_BAND 17 /* Spectral analysis - number of critical bands considered as voiced (related to VOIC_BINS) */ #define VOIC_BINS_8k 115 /* Spectral analysis - max number of frequency bins considered as voiced in NB (related to VOIC_BAND_8k and L_FFT) */ #define VOIC_BAND_8k 17 /* Spectral analysis - number of critical bands considered as voiced in NB (related to VOIC_BINS_8k) */ -#define N_SPEC (L_FFT/2) /* number of spectral bins */ -#define M_GAMMA_FX 32440 /* Q15 - forgetting factor of active speech decision predictor */ -#define M_ALPHA_FX 29491 /* Q15 - forgetting factor of LT correlation map */ -#define ONE_MINUS_M_ALPHA 3277 /* Q15 - one minus forgetting factor of LT correlation map */ -#define THR_CORR_INIT_FX (56<<9 ) /* Q9 - starting threshold of multi-harm. correlation */ -#define THR_NCHAR_WB_FX 2048 /* Q11 threshold for noise character (WB) */ -#define THR_NCHAR_NB_FX 2048 /* Q11 threshold for noise character (NB) */ +#define M_ALPHA 0.9f /* Multi-harm analysis - forgetting factor of LT correlation map */ +#define M_GAMMA 0.99f /* Multi-harm analysis - forgetting factor of active speech decision predictor */ +#define THR_CORR 56 /* Multi-harm analysis - starting threshold of multi-harm. correlation */ #define L_LP 320 /* LP analysis - LP window size */ #define L_LP_16k 400 /* LP analysis @16kHz - LP window size for 16kHz */ #define L_LP_AMR_WB 384 /* LP analysis - windows size (only for AMR-WB IO mode) */ -#define GRID100_POINTS 100 /* LP analysis - number of points to evaluate Chebyshev polynomials */ -#define GRID80_POINTS 80 /* LP analysis - number of points to evaluate Chebyshev polynomials used in the LP coefs. conversion */ - #define GRID50_POINTS 51 /* LP analysis - half-number of points to evaluate Chebyshev polynomials used in the LP coefs. conversion */ #define GRID40_POINTS 41 /* LP analysis - half-number of points to evaluate Chebyshev polynomials used in the LP coefs. conversion */ +#define GRID100_POINTS 100 /* LP analysis - number of points to evaluate Chebyshev polynomials */ #define PIT_MIN 34 /* OL pitch analysis - Minimum pitch lag */ #define PIT_MAX 231 /* OL pitch analysis - Maximum pitch lag */ @@ -558,9 +586,9 @@ enum #define PIT_MIN_DOUBLEEXTEND 17 /* OL pitch analysis - Minimum pitch lag of double-extended range */ #define OPL_DECIM 2 /* OL pitch analysis - decimation factor */ #define L_INTERPOL1 4 /* OL pitch analysis - interval to compute normalized correlation */ -#define FIR_SIZE1 (UP_SAMP*L_INTERPOL1+1) /* OL pitch analysis - total length of the 1/4 interpolation filter */ +#define FIR_SIZE1 (PIT_UP_SAMP*L_INTERPOL1+1) /* OL pitch analysis - total length of the 1/4 interpolation filter */ -#define PIT_MIN_SHORTER 29 /* OL pitch analysis - minimum for wider pitch, MODE2 specific constant */ +#define PIT_MIN_SHORTER 29 /* OL pitch analysis - minimum for wider pitch */ #define PIT_MIN_12k8 29 /* Minimum pitch lag with resolution 1/4 */ #define PIT_FR2_12k8 121 /* Minimum pitch lag with resolution 1/2 */ @@ -582,7 +610,6 @@ enum #define PIT_MAX_32k 577 #define PIT_FR1_8b_32k 75 #define PIT_MAX_MAX PIT_MAX_32k -#define PIT_MAX_16k 289 #define PIT_FR1_8b 92 /* Pitch encoding - Minimum pitch lag with resolution 1 */ #define PIT_FR2_9b 128 /* Pitch encoding - Minimum pitch lag with resolution 1/2 */ @@ -604,50 +631,38 @@ enum #define NB_POS_FCB_4T 16 /* Algebraic codebook - number of positions in algebraic fixed codebook search with 4 tracks */ #define NB_PULSE_MAX 36 #define NPMAXPT ((NB_PULSE_MAX+NB_TRACK_FCB_4T-1)/NB_TRACK_FCB_4T) +#define MAX_IDX_LEN 9 #define GAIN_PRED_ORDER 4 /* Gain quantization - prediction order for gain quantizer (only for AMR-WB IO mode) */ #define MEAN_ENER 30 /* Gain quantization - average innovation energy */ #define DTX_HIST_SIZE 8 /* CNG & DTX - number of last signal frames used for CNG averaging */ -#define CNG_ISF_FACT_FX 29491 /* Q15(0.9), CNG & DTX - CNG spectral envelope smoothing factor*/ -#define STEP_AMR_WB_SID_FX 10752 /* Q12 */ +#define CNG_ISF_FACT 0.9f /* CNG & DTX - CNG spectral envelope smoothing factor */ +#define STEP_AMR_WB_SID 2.625f /* CNG & DTX - CNG energy quantization step */ #define HO_HIST_SIZE 8 /* CNG & DTX - maximal number of hangover frames used for averaging */ - #define NUM_ENV_CNG 20 -#define BUF_L_NRG_FX 22938 /* Q15(0.7), CNG & DTX - lower threshold offset for hangover updates */ -#define ONE_OVER_BUF_H_NRG_FX 31814 /* Q15(1/1.03), CNG & DTX - inverse of higher threshold offset for hangover updates */ -#define HO_ATT_FAC_FX 3277 /* Q15(0.1), CNG & DTX - Hangover frame attenuation rate factor */ +#define BUF_L_NRG 0.7f /* CNG & DTX - lower threshold factor for hangover updates */ +#define BUF_H_NRG 1.03f /* CNG & DTX - higher threshold factor for hangover updates */ #define BUF_DEC_RATE 25 /* CNG & DTX - buffer size decrease rate for active frames */ -#define STEP_SID_FX 21504 /* Q12 */ -#define ISTEP_SID_FX 6242 /* Inverse of CNG & DTX - CNG energy quantization step in Q15(1/5.25 in Q15)*/ -#define ISTEP_AMR_WB_SID_FX 12483 /* Q15(1/2.625) Inverse of CNG & DTX - CNG energy quantization step */ +#define STEP_SID 5.25f /* CNG & DTX - CNG energy quantization step */ #define MIN_ACT_CNG_UPD 20 /* DTX - Minimum number of consecutive active frames for CNG mode update */ #define FIXED_SID_RATE 8 /* DTX SID rate */ #define TOTALNOISE_HIST_SIZE 4 -/************************************************************************/ - -/************************************************************************/ -#define SUBFFT_QIN 10 -#define DATAFFT_Q 5 -#define SUBFFT_QOUT SUBFFT_QIN-DATAFFT_Q -#define SPECAMP_Q SUBFFT_QIN - -#define CLDFBVAD_NB_ID 1 -#define CLDFBVAD_WB_ID 2 -#define CLDFBVAD_SWB_ID 3 -#define CLDFBVAD_FB_ID 4 -#define SP_CENTER_NUM 4 -#define TONA_NUM 3 -#define PRE_SNR_NUM 32 -#define PRE_FLAG_NUM 64 -#define POWER_NUM 56 -#define PRE_SPEC_DIF_NUM 56 -#define CLDFBVAD_VAD_ON 1 -#define COM_VAD_ON 2 +#define UNKNOWN_NOISE 0 /* unknown noisy type */ +#define SILENCE 1 /* speech with high SNR */ +#define CLDFBVAD_NB_ID 1 +#define CLDFBVAD_WB_ID 2 +#define CLDFBVAD_SWB_ID 3 +#define CLDFBVAD_FB_ID 4 +#define SP_CENTER_NUM 4 /* number of spectral centroid */ +#define TONA_NUM 3 /* number of tonal */ +#define PRE_SNR_NUM 32 /* number of snr to calculate average SNR of all sub-bands */ +#define POWER_NUM 56 /* number of energy of several frames*/ +#define PRE_SPEC_DIF_NUM 56 /* number of energy of several frames*/ #define MAX_SUBBAND_NUM 12 /* max number of sub-band divided non-uniformly*/ #define BG_ENG_NUM MAX_SUBBAND_NUM /* number of energy of sub-band divided non-uniformly*/ @@ -658,19 +673,15 @@ enum #define SFM_NUM 3 /* number of spectral flatness */ - -#define MAX_CORR_SHIFT_FX 16384 /* corrshift limit, 0.5 in Q15 */ - - #define START_NG 5 /* Stationary noise UV modification */ #define FULL_NG 10 /* Stationary noise UV modification */ -#define ISP_SMOOTHING_QUANT_A1_FX 29491 /* 0.9f in Q15 */ /* Stationary noise UV modification */ +#define ISP_SMOOTHING_QUANT_A1 0.9f /* Stationary noise UV modification */ -#define KP559016994_FX 18318 /* EDCT & EMDCT constants */ -#define KP951056516_FX 31164 /* EDCT & EMDCT constants */ -#define KP587785252_FX 19261 /* EDCT & EMDCT constants */ -#define KP866025403_FX 28378 /* EDCT & EMDCT constants */ -#define KP250000000_FX 8192 /* EDCT & EMDCT constants */ +#define KP559016994 0.55901699f /* EDCT & EMDCT constants */ +#define KP951056516 0.95105652f /* EDCT & EMDCT constants */ +#define KP587785252 0.58778525f /* EDCT & EMDCT constants */ +#define KP866025403 0.86602540f /* EDCT & EMDCT constants */ +#define KP250000000 0.25000000f /* EDCT & EMDCT constants */ #define FEC_BITS_CLS 2 /* FEC - number of bits for clas information */ #define FEC_BITS_ENR 5 /* FEC - number of bits for energy information */ @@ -679,43 +690,65 @@ enum #define FEC_BITS_POS 8 /* FEC - number of bits for glottal pulse position */ #define L_SYN_MEM_CLAS_ESTIM (2*PIT16k_MAX - L_FRAME16k) /* FEC - memory of the synthesis signal for frame class estimation */ #define L_SYN_CLAS_ESTIM (L_SYN_MEM_CLAS_ESTIM + L_FRAME16k) /* FEC - length of the synthesis signal buffer for frame class estimation */ -#define FRAME_COUNT 100 /* threshold of frame counter */ + +#define FRAME_COUNT_HF_SYNTH 100 /* Threshold of frame counter in HF synthesis */ #define AUDIO_COUNTER_INI 200 /* Counter initialization */ #define AUDIO_COUNTER_STEP 10 /* Counter increase on each audio frame */ -#define AUDIO_COUNTER_MAX 1000 /* Counter saturation */ +#define AUDIO_COUNTER_MAX 1000 /* Counter saturation */ #define BWD_TOTAL_WIDTH 320 /* BWD width */ #define BWD_COUNT_MAX 100 /* maximum value of BWD counter */ -#define PREEMPH_FAC 22282 /* preemphasis factor at 12.8kHz (0.68f in 0Q15) */ -#define PREEMPH_FAC_16k 23593 /* preemphasis factor at 16kHz (0.72f in 0Q15) */ -#define PREEMPH_FAC_SWB 29491 /* preemphasis factor for super wide band (0.9f in 0Q15) */ -#define GAMMA1 30147 /* weighting factor (numerator) default:0.92 (0Q15format) */ -#define GAMMA1_INV 17809 /* weighting factor (numerator) default:0.92 (1Q14format) */ -#define GAMMA16k 30802 /* weighting factor (numerator) default:0.94 (0Q15format) */ -#define GAMMA16k_INV 17430 /* weighting factor (numerator) default:0.94 (1Q14format) */ +#define PREEMPH_FAC 0.68f /* preemphasis factor at 12.8kHz */ -#define FORMANT_SHARPENING_G1 24576 /* Formant sharpening numerator weighting at 12.8kHz (0.75f) */ -#define FORMANT_SHARPENING_G2 29491 /* Formant sharpening denominator weighting at 12.8kHz (0.9f) */ -#define FORMANT_SHARPENING_G1_16k 26214 /* Formant sharpening numerator weighting at 16kHz (0.8f) */ -#define FORMANT_SHARPENING_G2_16k 30147 /* Formant sharpening denominator weighting at 16kHz (0.92f) */ +#define PREEMPH_FAC_16k 0.72f -#define LD_FSCALE_DENOM 9 -#define FSCALE_DENOM (1 << LD_FSCALE_DENOM) -#define FSCALE_DENOM_HALF FSCALE_DENOM/2 -#define FSCALE_E 2 + +#define PREEMPH_FAC_SWB 0.9f /* preemphasis factor for super wide band */ + + +#define GAMMA1 0.92f /* weighting factor (numerator) default:0.92 */ +#define GAMMA16k 0.94f + +#define FORMANT_SHARPENING_G1 0.75f /* Formant sharpening numerator weighting at 12.8kHz */ +#define FORMANT_SHARPENING_G2 0.9f /* Formant sharpening denominator weighting at 12.8kHz */ +#define FORMANT_SHARPENING_G1_16k 0.8f /* Formant sharpening numerator weighting at 16kHz */ +#define FORMANT_SHARPENING_G2_16k 0.92f /* Formant sharpening denominator weighting at 16kHz */ + +#define FSCALE_DENOM 512 #define ACELP_FIXED_CDK_NB 41 +#define ACELP_FIXED_CDK_BITS(n) PulseConfTable[n].bits #define L_FIR 31 +enum TRACKPOS +{ + TRACKPOS_FIXED_FIRST =0, /* Fill tracks from left */ + TRACKPOS_FIXED_EVEN =1, /* Even tracks */ + TRACKPOS_FIXED_FIRST_TWO =2, /* One track of 32 */ + TRACKPOS_FIXED_TWO =3, /* Two tracks of 32 instead of four of 16 */ + TRACKPOS_FREE_ONE =4, /* One freely moving track with extra pulse */ + TRACKPOS_FREE_THREE =6, /* Three freely moving tracks with single extra pulses */ + TRACKPOS_GRADIENT =7 +}; + +enum +{ + LAGW_WEAK, /* weak lag window */ + LAGW_MEDIUM, /* medium strength lag window */ + LAGW_STRONG, /* strong lag window */ + + NUM_LAGW_STRENGTHS +}; + /*----------------------------------------------------------------------------------* * ACELP@16kHz core constants *----------------------------------------------------------------------------------*/ -#define NB_SUBFR16k 5 /* number of subframes per frame @16kHz */ -#define INT_FS_16k 16000 /* CELP core internal sampling frequency @16kHz */ +#define NB_SUBFR16k 5 /* number of subframes per frame @16kHz */ +#define INT_FS_16k 16000 /* CELP core internal sampling frequency @16kHz */ #define PIT16k_MIN 42 /* Minimum pitch lag @16kHz */ #define PIT16k_MAX 289 /* Maximum pitch lag @16kHz */ @@ -726,52 +759,40 @@ enum #define PIT16k_FR2_EXTEND_10b 264 /* Minimum 10 bit pitch lag with resolution 1/2 of extended range @16kHz */ #define WIDTH_BAND 8 /* sub-band width in AVQ coding */ -#define G_AVQ_MIN_FX 6554 /* Q13 */ -#define G_AVQ_MIN_DIV10_FX 655 /* Q13 */ -#define G_AVQ_MAX_FX 6144 /* Q6 */ -#define FAC_PRE_AVQ_FX 9830 /* preemhasis factor in ACELP pre-quantizer (0.3 in Q15) */ +#define G_AVQ_MIN 0.80f /* lower limit for gain Q in higher-rate ACELP contribution */ +#define G_AVQ_MAX 96.0f /* upper limit for gain Q in higher-rate ACELP contribution */ +#define FAC_PRE_AVQ 0.3f /* preemhasis factor in ACELP pre-quantizer */ - -#define G_AVQ_MIN_INACT_Q12 2867 /* lower limit for gain Q in higher-rate ACELP contribution, inactive segments (0.7 in Q12) */ -#define G_AVQ_MIN_INACT_48k_Q12 1434 /* lower limit for gain Q in higher-rate ACELP contribution, inactive segments, 48 kbit/s (0.35 in Q12) */ -#define G_AVQ_MIN_INACT_64k_Q12 1024 /* lower limit for gain Q in higher-rate ACELP contribution, inactive segments, 64 kbit/s (0.25 in Q12 )*/ -#define G_AVQ_DELTA_INACT_Q12 221 /* (4.1 - 0.7) / ((1 << G_AVQ_BITS) - 1) in Q12 */ -#define G_AVQ_DELTA_INACT_48k_Q12 159 /* (2.8 - 0.35) / ((1 << G_AVQ_BITS) - 1) */ -#define G_AVQ_DELTA_INACT_64k_Q12 81 /*(1.5 - 0.25) / ((1 << G_AVQ_BITS) - 1) */ +#define G_AVQ_MIN_INACT 0.70f /* lower limit for gain Q in higher-rate ACELP contribution, inactive segments */ +#define G_AVQ_MAX_INACT 4.1f /* upper limit for gain Q in higher-rate ACELP contribution, inactive segments */ +#define G_AVQ_MIN_INACT_48k 0.35f /* lower limit for gain Q in higher-rate ACELP contribution, inactive segments, 48 kbit/s */ +#define G_AVQ_MAX_INACT_48k 2.8f /* upper limit for gain Q in higher-rate ACELP contribution, inactive segments, 48 kbit/s */ +#define G_AVQ_MIN_INACT_64k 0.25f /* lower limit for gain Q in higher-rate ACELP contribution, inactive segments, 64 kbit/s */ +#define G_AVQ_MAX_INACT_64k 1.5f /* upper limit for gain Q in higher-rate ACELP contribution, inactive segments, 64 kbit/s */ +#define G_AVQ_DELTA_INACT_48k (G_AVQ_MAX_INACT_48k - G_AVQ_MIN_INACT_48k) / ((1 << G_AVQ_BITS) - 1) +#define G_AVQ_DELTA_INACT_64k (G_AVQ_MAX_INACT_64k - G_AVQ_MIN_INACT_64k) / ((1 << G_AVQ_BITS) - 1) #define G_AVQ_BITS 6 /* number of bits to quantize the AVQ gain in higher-rate ACELP contribtuion */ +#define G_AVQ_DELTA (G_AVQ_MAX - G_AVQ_MIN) / ((1 << G_AVQ_BITS) - 1) +#define G_AVQ_DELTA_INACT (G_AVQ_MAX_INACT - G_AVQ_MIN_INACT) / ((1 << G_AVQ_BITS) - 1) -#define G_PITCH_MIN_Q14 0 -#define G_PITCH_MAX_Q13 9994/*1.22 */ -#define G_PITCH_MAX_Q14 19988 /* 1.22 in Q14 */ - -#define G_CODE_MIN_FX 164 /* Q13 */ -#define G_CODE_MAX_FX 320 /* Q6 */ - -#define G_PITCH_MIN_TC192_Q14 1638 -#define G_PITCH_MAX_TC192_Q14 15565 /* 0.95 in Q14 */ -#define G_PITCH_MAX_MINUS_MIN_TC192_Q13 6963/*(G_PITCH_MAX_TC192 - G_PITCH_MIN_TC192) */ -#define G_CODE_MIN_TC192_Q15 19661 -#define G_CODE_MIN_TC192_FX 4915 /* Q13 */ -#define G_CODE_MAX_TC192_Q0 41 - -/*--------------------------------------------------------------* - * ACELP constants - *---------------------------------------------------------------*/ - -#define MODE_MAX 15 - -#define NB_PULSES_MAX 15 -#define ACELP_GAINS_CONST 0.8f /* ACELP - adaptive codebook gain constraint */ +#define G_PITCH_MIN 0.00f /* SQ of gains: pitch gain lower limit */ +#define G_PITCH_MAX 1.22f /* SQ of gains: pitch gain upper limit */ +#define G_CODE_MIN 0.02f /* SQ of gains: code gain lower limit */ +#define G_CODE_MAX 5.00f /* SQ of gains: code gain upper limit */ +#define G_PITCH_MIN_TC192 0.1f +#define G_PITCH_MAX_TC192 0.95f +#define G_CODE_MIN_TC192 0.6f +#define G_CODE_MAX_TC192 41.0f /*--------------------------------------------------------------* * TCX constants *---------------------------------------------------------------*/ -#define NOISE_FILL_RANGES 1 /* CURRENTLY BROKEN for NOISE_FILL_RANGES > 1! For dividing spectrum into multiple ranges, define NOISE_FILL_RANGES > 1. For each region one noise filling level will be transmited */ +#define NOISE_FILL_RANGES 1 #define NBITS_NOISE_FILL_LEVEL 3 /* Number of bits used for coding noise filling level for each range */ #define MIN_NOISE_FILLING_HOLE 8 -#define HOLE_SIZE_FROM_LTP(gain) (add(4, extract_h(L_shr(L_mult0(gain, 0x6666), 10)))) /* 0x6666 -> 2.0*(4.0/0.625) (4Q11) */ +#define HOLE_SIZE_FROM_LTP(gain) (4+(int)(2.0f*gain*(4.0f/0.625f))) #define FDNS_NPTS 64 #define AVG_TCX20_LSF_BITS 40 #define AVG_TCX10_LSF_BITS 59 @@ -781,32 +802,29 @@ enum #define TCXLTP_LTP_ORDER 24 #define TCX_RES_Q_BITS_GAIN 3 +/* Use arithmetic coder with LPC shaping also at high (i.e. TCX-only) bitrates */ #define LPC_SHAPED_ARI_MAX_RATE ACELP_9k60 - #define N_MAX_ARI 800 -#define SPEC_EXP_DEC 20 /* initial decoder spectrum exponent */ - /*----------------------------------------------------------------------------------* * TNS constants *----------------------------------------------------------------------------------*/ -#define R1_48 690 -#define R2_48 420 -#define R1_16 230 -#define R2_16 140 -#define R1_25 368 -#define R2_25 224 - -#define TNS_MAX_NUM_OF_FILTERS 2 /* TNS maximum number of filters */ -#define TNS_MAX_FILTER_ORDER 8 /* TNS maximum filter order */ -#define ITF_MAX_FILTER_ORDER 16 /* ITF maximum filter order */ -#define NPRM_TNS (2+TNS_MAX_NUM_OF_FILTERS*(3+TNS_MAX_FILTER_ORDER)) /* TNS total number of quantized parameters */ -#define NPRM_RESQ 100 /* Maximum number of parameter for residual Q in TCX */ -#define NPRM_CTX_HM 3 /* Number of Parameters for Context HM : flag+index */ -#define NPRM_DIV (2+NPRM_TNS+N_MAX/2+NPRM_RESQ+NPRM_CTX_HM) /* Total number of quantized parameter in 1 division */ -#define DEC_NPRM_DIV NPRM_DIV /* Total number of quantized parameter in 1 division (decoder side) */ -#define NPRM_LPC_NEW 2*(4+2*NB_SPHERE) /* LPC total number of quantized parameters */ +#define R1_48 690 +#define R2_48 420 +#define R1_16 230 +#define R2_16 140 +#define R1_25 368 +#define R2_25 224 +#define TNS_MAX_NUM_OF_FILTERS 2 /* TNS maximum number of filters */ +#define TNS_MAX_FILTER_ORDER 8 /* TNS maximum filter order */ +#define ITF_MAX_FILTER_ORDER 16 /* ITF maximum filter order */ +#define NPRM_TNS (2+TNS_MAX_NUM_OF_FILTERS*(3+TNS_MAX_FILTER_ORDER)) /* TNS total number of quantized parameters */ +#define NPRM_RESQ 100 /* Maximum number of parameter for residual Q in TCX */ +#define NPRM_CTX_HM 3 /* Number of Parameters for Context HM : flag+index*/ +#define NPRM_DIV (2+NPRM_TNS+N_MAX/2+NPRM_RESQ+NPRM_CTX_HM) /* Total number of quantized parameter in 1 division */ +#define DEC_NPRM_DIV NPRM_DIV /* Total number of quantized parameter in 1 division (decoder side) */ +#define NPRM_LPC_NEW 2*(4+2*NB_SPHERE) /* LPC total number of quantized parameters */ #define BITBUFSIZE (128000/50) @@ -817,26 +835,28 @@ enum * LSF quantization constants *----------------------------------------------------------------------------------*/ -#define GENERIC_MA_LIMIT 9600 +#define GENERIC_MA_LIMIT ACELP_9k60 /* crossover limit, for Generic WB mode, < use SN/AR, >= use MA-predictor */ -#define SPC_FX 770 /* q15 */ -#define SPC_PLUS_FX 771 - -#define LSF_GAP_FX 128 /*50.0f x 2.56*/ -#define MODE1_LSF_GAP_FX 179 /* MODE1_LSF_GAP*2.56 */ /* Minimum LSF separation for end-frame ISFs */ -#define FREQ_MAX 16384 /*6400Hz in 14Q1*1.28 */ -#define FREQ_DIV 800 /*400.0f in 14Q1 */ +#define NC16k (M16k/2) +#define NO_ITER 4 /* number of iterations for tracking the root */ +#define SPC 0.0234952f +#define SPC_plus SPC * 1.001f +#define ALPHA_SQ ((0.5f / PI2) * (0.5f / PI2)) +#define NC M/2 +#define LSF_GAP 50.0f #define LSF_BITS_CNG 29 -#define ISF_GAP_FX 128 /* Minimum ISF separation for end-frame ISFs (only in AMR-WB IO mode) */ -#define LSF_GAP_MID_FX 205 /* 80.0 * 2.56 */ /* Minimum LSF separation for mid-frame LSFs */ -#define PREFERSFNET_FX 1638 /* 0.05 in Q16*/ -#define SFNETLOWLIMIT_WB 3670016 /* 2.56x2.56*Q4 LSF quantizer - new sampling rate dependent thresholds used in LSF codebook decision logic, WB case */ -#define SFNETLOWLIMIT_NB 3984589 /* 2.56x2.56*Q4 LSF quantizer - new sampling rate dependent thresholds used in LSF codebook decision logic, NB case */ +#define MU_MA (1.0f/3.0f) /* original prediction factor (only for AMR-WB IO mode) */ +#define ISF_GAP 50 /* Minimum ISF separation for end-frame ISFs (only in AMR-WB IO mode) */ +#define LSF_GAP_MID 80.0f /* Minimum LSF separation for mid-frame LSFs */ +#define MODE1_LSF_GAP 70.0f /* Minimum LSF separation for end-frame ISFs */ +#define PREFERSFNET 1.05 +#define SFNETLOWLIMIT_WB 35000 /* new sampling rate dependent thresholds used in LSF codebook decision logic, WB case */ +#define SFNETLOWLIMIT_NB 38000 /* new sampling rate dependent thresholds used in LSF codebook decision logic, NB case */ #define LSFMBEST 2 /* number of survivors from one stage to another */ -#define STREAKLEN 3 /* Allow this many predictive frames, before starting limiting, For voiced +3 frames allowed */ -#define STREAKMULT_FX 26214 /* Exponential limiting multiplier */ +#define STREAKLEN 3 /* Allow this many predictive frames, before starting limiting */ +#define STREAKMULT 0.8f /* Exponential limiting multiplier */ #define LSFMBEST_MAX 16 @@ -844,11 +864,13 @@ enum #define TCXLPC_NUMBITS 13 #define TCXLPC_IND_NUMSTAGES 1 #define TCXLPC_IND_NUMBITS 2 -#define TCXLPC_LSF_GAP 204 /* 80 in 14Q1*1.28 */ -#define kMaxC 8 +#define TCXLPC_LSF_GAP 80.0f -#define MAX_VQ_STAGES 4 /* Maximum number of LSF VQ (3 trained and 1 LVQ) stages allowed */ -#define MAX_VQ_STAGES_USED 9 /*this is the maximum number of stages currently used and changing this will affect the memory allocated MAX_VQ_STAGES is also used as offset for addressing some arrays, so this should NOT be changed*/ +#define MAX_VQ_STAGES 4 +#define MAX_VQ_STAGES_USED 9 /* this is the maximum number of stages currently used and changing this will affect the memory allocated + MAX_VQ_STAGES is also used as offset for addressing some arrays, so this should NOT be changed*/ +#define MIDLSF_NBITS 5 +#define ENDLSF_NBITS 31 #define LEN_INDICE 15 #define LATTICE_DIM 8 @@ -856,17 +878,20 @@ enum #define MAX_NO_BR_LVQ 28 #define MAX_NO_SCALES 3 #define MAX_NO_VALS 4 +#define WB_LIMIT_LSF 6350 #define CNG_LVQ_MODES 16 -#define MAX_NO_MODES 128 -#define START_CNG 112 -#define MAX_NO_MODES_p 145 -#define NO_CODING_MODES 6 + +#define MAX_NO_MODES 128 +#define START_CNG 112 +#define MAX_NO_MODES_p 145 +#define NO_CODING_MODES 6 #define LVQ_COD_MODES 18 -/* BC-TCQ */ + +/* BC-TCVQ */ #define N_STAGE_VQ 8 #define N_DIM 2 #define NUM_SUBSET 8 -#define OP_LOOP_THR_HVO 1550146 /* 80% : Open-loop Threshold 2.56*2.56/16 */ +#define OP_LOOP_THR_HVO 3784536.3f /* 80% : Open-loop Threshold */ #define NUM_STATE 16 /* BC-TCQ - Number of state of the Trellis */ #define N_STAGE 16 /* BC-TCQ - Smaple number in a frame */ @@ -889,7 +914,7 @@ enum * Transient detection *----------------------------------------------------------------------------------*/ -#define NSUBBLOCKS 8 /* Number of subblocks per frame, one transient per a sub-block can be found */ +#define NSUBBLOCKS 8 /* Number of subblocks per frame, one transient per a sub-block can be found */ #define MAX_TD_DELAY 2*NSUBBLOCKS /* Maximum allowed delay (in number of subblocks) of the transient detection, affects required memory */ #define NO_TCX 0 @@ -903,6 +928,10 @@ enum #define NOT_SUPPORTED 1 #define MIN_OVERLAP 2 #define HALF_OVERLAP 3 +#define ALDO_WINDOW 4 + +#define SWITCH_OVERLAP_8k 15 /* == NS2SA(8000, SWITCH_GAP_LENGTH_NS) - NS2SA(8000, 10000000.0f - N_ZERO_MDCT_NS) */ +#define SWITCH_GAP_LENGTH_8k 50 /*----------------------------------------------------------------------------------* * FEC constants @@ -912,39 +941,52 @@ enum #define UNVOICED_TRANSITION 1 /* Transition from unvoiced to voiced components - possible onset, but too small */ #define VOICED_TRANSITION 2 /* Transition from voiced - still voiced, but with very weak voiced characteristics */ #define VOICED_CLAS 3 /* Voiced frame, previous frame was also voiced or ONSET */ -#define ONSET 4 /* Voiced onset sufficiently well built to follow with a voiced concealment */ +#define ONSET 4 /* Voiced onset sufficiently well built to follow with a voiced concealments */ #define SIN_ONSET 5 /* Artificial harmonic+noise onset (used only in decoder) */ #define INACTIVE_CLAS 6 /* Inactive frame (used only in decoder) */ #define AUDIO_CLAS 7 /* Audio frame (used only in AMR-WB IO mode) */ -#define BETA_FEC_FX 24576 /* FEC - weighting factor for LSF estimation in FER */ -#define STAB_FAC_LIMIT_FX 8192 /* FEC - limit at which safety net is forced for next frame */ +#define BETA_FEC 0.75f /* FEC - weighting factor for LSF estimation in FER */ +#define STAB_FAC_LIMIT 0.25f /* FEC - limit at which safety net is forced for next frame */ #define MODE1_L_FIR_FER 5 /* FEC - impulse response length for low- and high-pass filters in FEC */ -#define L_FIR_FER 3 /* FEC - impulse response length for low- & high-pass filters in FER concealment*/ -#define L_FIR_FER2 11 /* FEC - new filter tuning: 11*/ +#define L_FIR_FER 3 /* impulse response length for low- & high-pass filters in FER concealment */ +#define L_FIR_FER2 11 /* new filter tuning: 11*/ #define MAX_UPD_CNT 5 /* FEC - maximum number of frames since last pitch update */ +#define ALPHA_S 0.6f /* FEC - damping factor for SIN_ONSET frames */ +#define ALPHA_V 1.0f /* FEC - damping factor for VOICED_CLAS frames */ +#define ALPHA_VT 0.4f /* FEC - damping factor for VOICED_TRANSITION frames */ +#define ALPHA_UT 0.8f /* FEC - damping factor for UNVOICED_TRANSITION frames */ +#define ALPHA_U 0.4f /* FEC - damping factor for UNVOICED_CLAS frames */ +#define ALPHA_UU 1.0f /* FEC - damping factor for UNVOICED_CLAS frames */ -/* attenuation strategy in case of FER */ -#define _ALPHA_S_FX 19661 -#define _ALPHA_V_FX 32767 -#define _ALPHA_VT_FX 13107 -#define _ALPHA_UT_FX 26214 -#define _ALPHA_U_FX 13107 -#define _ALPHA_U_FX_X_2 26214 -#define _ALPHA_UU_FX 32767 +#define AGC 0.98f -#define PLC_MIN_CNG_LEV 328/*0.01f Q15*/ -#define PLC_MIN_STAT_BUFF_SIZE 50 /* buffer size for minimum statistics */ +#define PLC_MIN_CNG_LEV 0.01f /* minimum background level */ +#define PLC_MIN_STAT_BUFF_SIZE 50 /* buffer size for minimum statistics */ +#define PLC_MIN_CNG_LEV 0.01f #define G_LPC_RECOVERY_BITS 1 /*----------------------------------------------------------------------------------* * Transition mode (TC) constants *----------------------------------------------------------------------------------*/ -/* Conversion of tc_subfr to index */ -#define TC_SUBFR2IDX_16KHZ_fx(x) mac_r(1024L, (x), 512) /* -1 => 0, 0 => 0, 64 => 1, 128 => 2, 192 => 3, 256 => 4 */ -#define TC_SUBFR2IDX_fx(x) add(s_min(3, s_max(0, sub((x), 1))), TC_SUBFR2IDX_16KHZ_fx(x)) +/* Conversion of tc_subfr to index */ +#define TC_SUBFR2IDX(x) ( x == 0 ? 0 : \ + x == 1 ? 0 : \ + x == 2 ? 1 : \ + x == 3 ? 2 : \ + x == 4 ? 3 : \ + x == 64 ? 4 : \ + x == 128 ? 5 : \ + x == 192 ? 6 : \ + x == 256 ? 7 : 0 ) + +#define TC_SUBFR2IDX_16KHZ(x) ( x == 0 ? 0 : \ + x == 64 ? 1 : \ + x == 128 ? 2 : \ + x == 192 ? 3 : \ + x == 256 ? 4 : 0 ) #define L_IMPULSE 17 /* TC - length of one prototype impulse */ #define L_IMPULSE2 8 /* TC - half-length of one prototype impulse == floor(L_IMPULSE/2) */ @@ -962,15 +1004,17 @@ enum *----------------------------------------------------------------------------------*/ #define NB_LDQ3 9 /* RE8 constants */ -#define NB_LDQ4 27 #define NB_SPHERE 32 #define NB_LEADER 36 +#define NB_LDQ4 27 +#define FAC_LOG2 3.321928095f #define NSV_MAX 34 /* maximal number of sub-vectors used by the AVQ */ /*----------------------------------------------------------------------------------* * Arithmetic coder *----------------------------------------------------------------------------------*/ + #define A_THRES_SHIFT 2 #define A_THRES (1<0 */ -#define GAMMA3_MINUS_FX 29491 /* NB post-filter - tilt weighting factor when k1<0 */ -#define GAMMA3_PLUS_WB_FX 21299 /* WB post-filter */ -#define GAMMA3_MINUS_WB_FX 27853 /* WB post-filter */ -#define AGC_FAC_WB_FX 27853 /* WB post-filter - gain adjustment factor */ -#define AGC_FAC1_WB_FX (Word16)(32768L-AGC_FAC_WB_FX) /* WB post-filter - gain adjustment factor complement */ - -/* SWB TBE, FX only constants */ -#define NOISE_QFAC 6 -#define NOISE_QADJ (15-NOISE_QFAC) +#define GAMMA0 0.65f /* Mean value of gamma1/gamma2 for formant PF */ +#define GAMMA_SHARP 0.15f /* Largest sharpening for gamma1/gamma2 (0.83/0.67)*/ +#define SWB_NOISE_MIX_FAC 0.15f /* Noise mixing adjustment factor for active PF */ +#define SWB_TILT_LOW 1.0f /* Lower threshold for PF tilt adaptation */ +#define SWB_TILT_HIGH 2.0f /* Higher threshold for PF tilt adaptation */ +#define SWB_TILT_DELTA (1.0f/(SWB_TILT_HIGH-SWB_TILT_LOW)) /* Inclination between thresholds */ +#define GAMMA3_PLUS_WB 0.65f /* WB post-filter */ +#define GAMMA3_MINUS_WB 0.85f /* WB post-filter */ +#define AGC_FAC_WB 0.85f /* WB post-filter - gain adjustment factor */ +#define AGC_FAC1_WB (1.0f-AGC_FAC_WB) /* WB post-filter - gain adjustment factor complement */ /*----------------------------------------------------------------------------------* * SWB BWE constants *----------------------------------------------------------------------------------*/ -#define INV_L_SUBFR16k_FX 410 /*Q15 */ +#define INV_L_SUBFR16k 0.0125f #define SWB_L_SUBFR 160 #define FB_L_SUBFR 240 #define SWB_FENV 14 -#define WB_FENV 2 -#define FB_GAIN_QLOW_FX 0 -#define FB_GAIN_QDELTA_FX 512 /*Q14 */ +#define FB_GAIN_QLOW 0.0f +#define FB_GAIN_QDELTA 0.03125f +#define FB_MAX_GAIN_VAR 0.5f -#define NUM_BITS_FB_FRAMEGAIN 4 /* Number of bits for framegain for FB */ + +#define NUM_BITS_FB_FRAMEGAIN 4 /* Number of bits for framegain for FB */ #define FB_BAND_BEGIN 620 #define FB_BAND_END 800 #define FB_BAND_WIDTH 180 @@ -1198,23 +1223,23 @@ enum #define NBITS_THRESH_BWE_HR 400 /* BWE HR number of bits threshold */ #define NBITS_HF_GAIN_BWE_HR 2 /* number of bits for HF (noncoded) energy estimation */ -#define BWE_HR_TRANS_EN_LIMIT1_FX_Q16 6554 -#define BWE_HR_TRANS_EN_LIMIT2_FX_Q16 19661 -#define BWE_HR_TRANS_EN_LIMIT3_FX_Q16 32767 -#define BWE_HR_NONTRANS_EN_LIMIT1_FX_Q15 16384 /* 0.5 */ -#define BWE_HR_NONTRANS_EN_LIMIT2_FX_Q14 19661 /* 1.2 */ -#define BWE_HR_NONTRANS_EN_LIMIT2_FX_Q15 16384 -#define BWE_HR_NONTRANS_EN_LIMIT3_FX_Q15 26214 /* 0.8 */ +#define BWE_HR_TRANS_EN_LIMIT1 0.1f /* HF (noncoded) energy equalization limit 1, transient frames */ +#define BWE_HR_TRANS_EN_LIMIT2 0.3f /* HF (noncoded) energy equalization limit 2, transient frames */ +#define BWE_HR_TRANS_EN_LIMIT3 0.5f /* HF (noncoded) energy equalization limit 3, transient frames */ +#define BWE_HR_NONTRANS_EN_LIMIT1 0.5f /* HF (noncoded) energy equalization limit 1, non-transient frames */ +#define BWE_HR_NONTRANS_EN_LIMIT2 1.2f /* HF (noncoded) energy equalization limit 2, non-transient frames */ +#define BWE_HR_NONTRANS_EN_LIMIT3 0.8f /* HF (noncoded) energy equalization limit 3, non-transient frames */ /*----------------------------------------------------------------------------------* * FD CNG *----------------------------------------------------------------------------------*/ -#define DELTA 1e-20f -#define DELTA_MANTISSA_W16 0x5e73 -#define DELTA_MANTISSA_W32 0x5e728433 -#define DELTA_EXPONENT (-66) -#define CLDFB_SCALING 24576/*1.5 Q14*/ /* Q 2.14 */ +#define OUTMAX_INV 0.000030517578125f /* 1/2^15 */ +#define OUTMAX_SQ 1073741824.f /* 2^30 */ +#define OUTMAX_SQ_INV 0.00000000093132257461547852f /* 1/2^30 */ +#define DELTA (1e-20f) + +#define CLDFB_SCALING (1.5f) #define FFTLEN 640 #define FFTLEN2 (FFTLEN/2) @@ -1229,40 +1254,27 @@ enum #define MSSUBFRLEN 12 #define MSNUMSUBFR 6 #define MSBUFLEN 5 +#define MSALPHACORALPHA 0.7f +#define MSALPHACORMAX 0.3f +#define MSALPHAMAX 0.96f +#define MSALPHAHATMIN 0.05f /* It is used for all bands except the first one to get a stable bass */ +#define MSQEQINVMAX (1.f/5.f) +#define MSAV 2.12f +#define MSBETAMAX 0.8f +#define MSSNREXP (-0.02f/0.064f) -#define NOISE_HEADROOM 5 /* headroom of noise in generate_masking_noise */ +#define NB_LAST_BAND_SCALE 0.8f +#define SWB_13k2_LAST_BAND_SCALE 0.8f -#define MSALPHACORALPHA 22938/*0.7f Q15*/ -#define MSALPHACORALPHA2 9830/*0.3f Q15*/ -#define MSALPHACORMAX 9830/*0.3f Q15*/ -#define MSALPHAMAX 31457/*0.96f Q15*/ -#define MSALPHAHATMIN 107374184l/*0.05f Q31*/ -#define MSQEQINVMAX 6554/*1.f/5.f Q15*/ -#define MSAV 17367/*2.12f Q13*/ -#define MSAV_EXP 2 -#define MSBETAMAX 1717986944l/*0.8f Q31*/ -#define MSBETAMAX_SQRT 1920767767l/*0.894427191 Q31*/ /* sqrt(MSBETAMAX) */ -#define MSSNREXP -10240/*-0.02f/0.064f Q15*/ - -#define NB_LAST_BAND_SCALE 26214/*0.8f Q15*/ -#define SWB_13k2_LAST_BAND_SCALE 26214/*0.8f Q15*/ +#define CNG_LOG_SCALING 512.f /*2^9*/ #define M_MAX 32 -#define NSTAGES_MAX 9 -#define MBEST_MAX 8 #define N_GAIN_MIN 4 #define N_GAIN_MAX 17 -#define numSlots_inv_EXP (-3) -#define PREEMPH_COMPENSATION_EXP 4 +#define CHEAP_NORM_SIZE 161 -#define CLDFBscalingFactor_EXP (-15) -#define CLDFBinvScalingFactor_EXP ( 16) - -#define CNG_NORM_RECIPROCAL_RANGE_SHIFT 2 -#define CNG_RAND_GAUSS_SHIFT 2 - -#define CNA_MAX_BRATE 13200 +#define CNA_MAX_BRATE ACELP_13k20 /*----------------------------------------------------------------------------------* * Bass post-filter constants @@ -1275,18 +1287,20 @@ enum * NB post-filter constants *----------------------------------------------------------------------------------*/ +#define THRESCRIT 0.5f /* NB post-filter - threshold LT pst switch off */ +#define AGC_FAC 0.9875f /* NB post-filter - gain adjustment factor */ +#define AGC_FAC1 (1.0f-AGC_FAC) /* NB post-filter - gain adjustment factor complement */ #define LONG_H_ST 20 /* NB post-filter - impulse response length */ -#define GAMMA1_PST12K_FX 24576 /* denominator weighting factor 12K (0.75 in Q15) */ -#define GAMMA2_PST12K_FX 22938 /* numerator weighting factor 12K (0.7 in Q15) */ -#define POST_G1_FX GAMMA1_PST12K_FX /* 12 kbps default */ -#define POST_G2_FX GAMMA2_PST12K_FX /* 12 kbps default */ -#define GAMMA1_PST12K_MIN_FX 21299 /* 0.65 in Q15 */ -#define GAMMA2_PST12K_MIN_FX 18022 /* 0.55 in Q15 */ -#define GAMMA1_PST12K_NOIS_FX 4915 /* 0.15 in Q15 */ -#define GAMMA2_PST12K_NOIS_FX 3277 /* 0.10 in Q15 */ +#define POST_G1 0.75f /* NB post-filter - denominator weighting factor 12kbps */ +#define POST_G2 0.7f /* NB post-filter - numerator weighting factor 12kbps */ +#define GAMMA1_PST 0.7f /* denominator weighting factor */ +#define GAMMA2_PST 0.55f /* numerator weighting factor */ +#define GAMMA3_PLUS 0.2f /* NB post-filter - tilt weighting factor when k1>0 */ +#define GAMMA3_MINUS 0.9f /* NB post-filter - tilt weighting factor when k1<0 */ #define F_UP_PST 8 /* NB post-filter - resolution for fractionnal delay */ #define LH2_S 4 /* NB post-filter - length of INT16 interp. subfilters */ #define LH2_L 16 /* NB post-filter - length of long interp. subfilters */ +#define MIN_GPLT (1.0f/1.5f) /* NB post-filter - LT gain minimum */ #define LH_UP_S (LH2_S/2) #define LH_UP_L (LH2_L/2) #define LH2_L_P1 (LH2_L + 1) @@ -1295,13 +1309,17 @@ enum #define SIZ_Y_UP ((F_UP_PST-1) * (L_SUBFR+1)) #define SIZ_TAB_HUP_L ((F_UP_PST-1) * LH2_L) #define SIZ_TAB_HUP_S ((F_UP_PST-1) * LH2_S) -#define BG1_FX -328 /* -0.01 in Q15 */ -#define BG2_FX -1638 /* -0.05 in Q15 */ -#define CG1_FX 29491 /* 0.9 in Q15 */ -#define CG2_FX 47514L /* 1.45 in Q15 */ -#define C_LP_NOISE_FX 819 /* 0.1/4.0 in Q15 */ -#define CK_LP_NOISE_FX 6291456L /* 15.0 * 0.1/4 in Q8 * 65536 */ -#define LP_NOISE_THR_FX 6400 /* 25.0 in Q8 */ +#define POST_G1_MIN 0.65f +#define POST_G2_MIN 0.55f +#define POST_G1_NOIS 0.15f +#define POST_G2_NOIS 0.10f +#define BG1 (-0.01f) +#define BG2 (-0.05f) +#define CG1 0.9f +#define CG2 1.45f +#define C_LP_NOISE (0.1f/4.0f) +#define K_LP_NOISE 15.0f +#define LP_NOISE_THR 25.0f /*----------------------------------------------------------------------------------* * Stability estimation @@ -1309,11 +1327,12 @@ enum #define NB_BFI_THR 2 /* threshold for counter of last bad frames */ #define MAX_LT 40 +#define INV_MAX_LT (1.0f/MAX_LT) -#define TH_0_MIN_FX 5120 /* 2.5f in Q11 */ -#define TH_1_MIN_FX 3840 /* 1.875f in Q11 */ -#define TH_2_MIN_FX 3200 /* 1.5625f in Q11 */ -#define TH_3_MIN_FX 2688 /* 1.3125f in Q11 */ +#define TH_0_MIN 2.5f +#define TH_1_MIN 1.875f +#define TH_2_MIN 1.5625f +#define TH_3_MIN 1.3125f /*----------------------------------------------------------------------------------* * Speech/music classifier constants @@ -1324,7 +1343,7 @@ enum #define M_LSP_SPMUS 6 /* number of LSPs used in speech/music classifier */ #define NB_BANDS_SPMUS 15 #define START_BAND_SPMUS 2 -#define N_OLD_BIN_E 42 +#define N_OLD_BIN_E 42 /* == (L_FFT/2-2)/3 */ #define LOWEST_FBIN 3 /* lowest frequency bin for feature vector preparation */ #define HIGHEST_FBIN 70 /* highest frequency bin for feature vector preparation */ @@ -1333,22 +1352,20 @@ enum #define BUF_LEN 60 #define L_OVR 8 -#define N_FEATURES_2 3 /* number of features */ - /*----------------------------------------------------------------------------------* * LD music post-filter constants *----------------------------------------------------------------------------------*/ -#define TH_0_MIN2_FX 3840 /* Q11 -> 1.875 */ -#define TH_1_MIN2_FX 2560 /* Q11 -> 1.25 */ -#define TH_2_MIN2_FX 1920 /* Q11 -> 0.9375 */ -#define TH_3_MIN2_FX 1280 /* Q11 -> 0.625 */ +#define TH_0_MIN2 1.875f +#define TH_1_MIN2 1.25f +#define TH_2_MIN2 0.9375f +#define TH_3_MIN2 0.625f #define DCT_L_POST 640 #define OFFSET2 192 #define VOIC_BINS_HR 640 -#define BIN_16kdct (6400/DCT_L_POST) +#define BIN_16kdct (6400.0f/DCT_L_POST) #define NB_LIMIT_BAND 16 #define MBANDS_GN_LD 20 /* number of bands for gain coding in the postfilter */ @@ -1373,11 +1390,11 @@ enum #define SSF 32 /* Sub-subframe length for energy estimation in UC decision */ #define NB_SSF (L_FRAME / SSF) /* number of sub-subframes per frame */ - #define MBANDS_GN 16 /* Number of band for gain coding in GSC */ #define BAND1k2 3 #define MBANDS_LOC (MBANDS_GN-1) +#define BIN_SIZE 25.0f #define SWNB_SUBFR 1 #define VAR_COR_LEN 10 @@ -1390,13 +1407,11 @@ enum #define PIT_EXC_L_SUBFR L_FRAME #define LOCAL_CT VOICED -#define Q_PVQ_OUT 10 - /*----------------------------------------------------------------------------------* - * Core Switching constants + * Core switching constants *----------------------------------------------------------------------------------*/ -#define SWITCH_MAX_GAP 360 /* 6.25 + 1.25 of filter mem max */ +#define SWITCH_MAX_GAP 360 /* 6.25 + 1.25 of filter mem max == NS2SA(48000, SWITCH_GAP_LENGTH_NS+DELAY_CLDFB_NS) */ /*----------------------------------------------------------------------------------* * HQ core constants @@ -1410,19 +1425,12 @@ enum #define HQ_GEN_FB 5 #define PREECHO_SMOOTH_LEN 20 +#define INV_PREECHO_SMOOTH_LENP1 (1 / (PREECHO_SMOOTH_LEN + 1.0)); #define MAX16B 32767 #define MIN16B (-32768) -#define ALDO_WINDOW 4 -#define WINDECAY48 1230 -#define WINDECAY48_256 656 -#define WINDECAY16 410 -#define N16_CORE_SW 90 -#define N_ZERO_8 45 - -#define SWITCH_OVERLAP_8k 15 -#define SWITCH_GAP_LENGTH_8k 50 +#define EPSILON 0.000000000000001f #define MAX_SEGMENT_LENGTH 480 #define NUM_TIME_SWITCHING_BLOCKS 4 @@ -1483,12 +1491,12 @@ enum #define HUFF_THR 10 #define NOSUPERPOSITION 40 -#define MAXVALUEOFFIRSTGAIN_FX 20480 /*2.5f in Q13 */ -#define MINVALUEOFFIRSTGAIN_FX -20480 +#define MAXVALUEOFFIRSTGAIN 2.5f +#define MINVALUEOFFIRSTGAIN -2.5f #define NOOFGAINBITS1 6 #define AUDIODELAYBITS 6 -#define DELTAOFFIRSTGAIN_FX 2601 /*Q15 */ +#define DELTAOFFIRSTGAIN (float)(MAXVALUEOFFIRSTGAIN - MINVALUEOFFIRSTGAIN) / (float)((1 << NOOFGAINBITS1) - 1) #define MAX_D1M_16k ((L_FRAME16k>>1) - NS2SA(16000,SWITCH_GAP_LENGTH_NS) - 16) #define MAX_D1M_12k8 ((L_FRAME16k>>1) - NS2SA(16000,SWITCH_GAP_LENGTH_NS) - 20) @@ -1500,23 +1508,25 @@ enum #define ENV_ADJ_START 6 /* Number of consecutive bands for which the attenuation is maximum */ #define ENV_ADJ_INCL 5 /* Inclination for mapping between attenuation region width and attenuation limit */ +#define ENV_SMOOTH_FAC 0.1f /* Smoothing factor for envelope stability measure */ #define L_STAB_TBL 10 /* Number of elements in stability transition table */ -#define LUMPED_ENV_SMOOTH_FAC_FX ((Word16)10089) /* Q19 (no typo error), 0.1/sqrt(27) */ -#define CMPLMNT_ENV_SMOOTH_FAC_FX ((Word16)29491) /* Q15 0.9 */ #define M_STAB_TBL_FX ((Word16)21068) /* Q13, 2.571756 */ -#define HALF_D_STAB_TBL_FX ((Word16) 422) /* Q13 0.1013138/2.0 */ #define D_STAB_TBL_FX ((Word16) 845) /* Q13 0.1013138 */ -#define NUM_ENV_STAB_PLC_STATES 2 /* Number of states of markov model */ -#define INV_NUM_ENV_STAB_PLC_STATES 16384 /* Q15 */ -#define INV_STAB_TRANS_FX 16497 /* Q14. Equal to 1.0f/(1-2*stab_trans_fx[L_STAB_TBL-1]) */ +#define HALF_D_STAB_TBL_FX ((Word16) 422) /* Q13 0.1013138/2.0 */ +#define NUM_ENV_STAB_PLC_STATES 2 /* Number of states of markov model */ #define ATT_LIM_HANGOVER 150 /* Number of hangover frames for disabling stability dependent attenuation */ +#define DELTA_TH 5.0f /* Delta energy threshold for transient detection for envelope stability */ +#define ENERGY_TH 100.0f /* Energy threshold for transient detection */ +#define ENERGY_LT_BETA 0.93f /* Smoothing factor for long-term energy measure */ #define START_EXC 60 #define L_HARMONIC_EXC 202 #define HQ_GENERIC_OFFSET 2 #define HQ_GENERIC_END_FREQ 560 +#define HQ_GENERIC_END_FREQ_14P2KHZ 568 +#define HQ_GENERIC_END_FREQ_16P0KHZ 640 #define HQ_GENERIC_FOFFSET_24K4 80 #define HQ_GENERIC_FOFFSET_32K 144 @@ -1536,6 +1546,7 @@ enum #define HQ_GENERIC_EXC1 1 #define HQ_GENERIC_SP_EXC 2 +#define LF_EMP_FAC 1.2f #define DIM_FB 3 #define HQ_FB_FENV SWB_FENV + DIM_FB @@ -1552,11 +1563,10 @@ enum #define HVQ_MAX_PEAKS HVQ_MAX_PEAKS_32k + 1 #define HVQ_NUM_SFM_24k (SFM_N_HARMONIC - 1 - HVQ_THRES_SFM_24k) #define HVQ_NUM_SFM_32k (SFM_N_HARMONIC - 1 - HVQ_THRES_SFM_32k) +#define HVQ_E_PEAK_SMOOTH_FAC (0.3f) #define HVQ_MAX_RATE 32000 - - #define NUMNRMIBITS_SWB_HVQ_24k 35 #define NUMNRMIBITS_SWB_HVQ_32k 25 @@ -1570,32 +1580,29 @@ enum #define HVQ_NEW_BAND_BIT_THR 30 #define HVQ_NF_GROUPS 2 -#define HVQ_NF_WEIGHT1_FX 31385 /* Q15 0.9578 - HVQ Classifier - Noise floor estimate weight 1 */ -#define HVQ_NF_WEIGHT1B 1383 /* Q15, 1 - HVQ_NF_WEIGHT1_FX */ -#define HVQ_NF_WEIGHT2_FX 21207 /* Q15 0.6472 - HVQ Classifier - Noise floor estimate weight 2 */ -#define HVQ_NF_WEIGHT2B 11561 /* Q15 1 - HVQ_NF_WEIGHT2_FX */ -#define HVQ_PE_WEIGHT1_FX 13840 /* Q15 0.42237 - HVQ Classifier - Peak envelope estimate weight 1 */ -#define HVQ_PE_WEIGHT1B 18928 /* Q15, 1 - HVQ_PE_WEIGHT1_FX */ -#define HVQ_PE_WEIGHT2_FX 26308 /* Q15 0.80285 - HVQ Classifier - Peak envelope estimate weight 2 */ -#define HVQ_PE_WEIGHT2B 6460 /* Q15, 1 - HVQ_PE_WEIGHT2_FX */ -#define HVQ_SHARP_THRES_FX 576 /*9 in Q6 */ +#define HVQ_NF_WEIGHT1 0.9578f /* HVQ Classifier - Noise floor estimate weight 1 */ +#define HVQ_NF_WEIGHT2 0.6472f /* HVQ Classifier - Noise floor estimate weight 2 */ +#define HVQ_PE_WEIGHT1 0.42237f /* HVQ Classifier - Peak envelope estimate weight 1 */ +#define HVQ_PE_WEIGHT2 0.80285f /* HVQ Classifier - Peak envelope estimate weight 2 */ +#define HVQ_THR_POW 0.88f /* HVQ Classifier power factor for threshold calc */ +#define HVQ_SHARP_THRES 9 /* HVQ Classifier - Sharpness threshold */ -#define HVQ_PA_FAC_FX 23170 /* Q15 0.7071 - HVQ Classifier peak allocation factor */ +#define HVQ_PA_FAC 0.7071f /* HVQ Classifier peak allocation factor */ #define HVQ_PA_PEAKS_SHARP1 9 /* HVQ Classifier - Maximum number of peaks for band with high sharpness */ #define HVQ_PA_PEAKS_SHARP2 3 /* HVQ Classifier - Maximum number of peaks for band with medium sharpness */ #define HVQ_PA_PEAKS_SHARP3 2 /* HVQ Classifier - Maximum number of peaks for band with low sharpness */ -#define HVQ_PA_SHARP_THRES2_FX 1024 /* Q6 16.0 - HVQ Classifier - Sharpness threshold for band with medium sharpness */ -#define HVQ_PA_SHARP_THRES3_FX 768 /* Q6 12.0 - HVQ Classifier - Sharpness threshold for band with low sharpness */ +#define HVQ_PA_SHARP_THRES2 16.0f /* HVQ Classifier - Sharpness threshold for band with medium sharpness */ +#define HVQ_PA_SHARP_THRES3 12.0f /* HVQ Classifier - Sharpness threshold for band with low sharpness */ #define HVQ_BW 32 /* HVQ Classifier subband bandwidth */ #define HVQ_NSUB_32k 10 #define HVQ_NSUB_24k 7 /* HVQ Classifier number of subbands */ #define HVQ_BWE_NOISE_BANDS 2 /* Number of BWE noise bands */ -#define HVQ_BWE_WEIGHT1_FX ((Word16)31130) /* 0.95 in Q15 */ -#define HVQ_BWE_WEIGHT2_FX ((Word16)6554) /* 0.2 in Q15 */ -#define HVQ_NFPE_FACTOR_CUBE_FX ((Word16)16777) /* 6.4^3 in Q6 */ -#define HVQ_LB_NFPE_FACTOR_CUBE_FX ((Word16)16777) /* 3.2^3 in Q9 */ +#define HVQ_BWE_WEIGHT1 0.95f +#define HVQ_BWE_WEIGHT2 0.2f +#define HVQ_NFPE_FACTOR 6.4f +#define HVQ_LB_NFPE_FACTOR 3.2f #define HVQ_VQ_DIM 5 /* HVQ peak VQ dimension */ #define HVQ_PVQ_GAIN_BITS 5 /* Number of bits to encode PVQ gains in HVQ */ @@ -1617,23 +1624,22 @@ enum #define HVQ_CP_SPARSE 1 /* HVQ Code Pos - Use Sparse coding */ #define MAX_SPLITS 10 /* Maximum number of PVQ band splits */ - #define QUANTAQ3OFFSET 1 enum QuantaMode { NEAREST = 0, CONS }; +#define DS_INDEX_LINEAR_END 21 #define PYR_OFFSET 1 #define RCF_INIT_SHIFT 14 - #define THR_ADD_SPLIT 7 /* Threshold for using additional split */ #define PVQ_MAX_BAND_SIZE 64 /* Maxiumum supported band size for PVQ search */ #define MIN_BAND_SIZE 1 /* Minimum supported band size for PVQ search */ #define RC_BITS_RESERVED 1 #define MAX_PVQ_BITS_PER_COEFFICIENT 80 /* Maximum bits per coefficient allocated per PVQ band. Q3. */ +#define MAX_SRT_LEN NB_SFM_MAX /* Maximum length of input for srt_vec_ind() */ /* index_pvq constants */ -#define KMAX_FX 512 - -#define KMAX_NON_DIRECT_FX 96 /* max K for non-direct indexing recursion rows is 1+KMAX_NON_DIRECT +1 */ -#define ODD_DIV_SIZE_FX 48 /* ind0=1/1 ind1 =1/3 ... ind47=1/95 */ +#define KMAX 512 +#define KMAX_NON_DIRECT 96 /* max K for non-direct indexing recursion rows */ +#define ODD_DIV_SIZE 48 /* ind0=1/1 ind1 =1/3 ... ind47=1/95 */ /* TCQ */ @@ -1644,6 +1650,7 @@ enum QuantaMode { NEAREST = 0, CONS }; #define STATES_LSB 4 #define TCQ_LSB_SIZE 24 #define TCQ_AMP 10 +#define QTCQ (0.2f) #define AR_TOP ( ( 1 << AR_BITS ) - 1 ) #define AR_FIRST ( AR_TOP / 4 + 1 ) @@ -1655,28 +1662,21 @@ enum QuantaMode { NEAREST = 0, CONS }; /*----------------------------------------------------------------------------------* * SWB BWE for LR MDCT core *----------------------------------------------------------------------------------*/ -/* Q value */ -#define SWB_BWE_LR_Qs 12 /* Q value of spectra (Word32) */ -#define SWB_BWE_LR_Qbe 14 /* Q value of band_energy (Word32) */ -#define SWB_BWE_LR_QRk 16 /* Q value of Rk, Rcalc (Word32) */ -#define SWB_BWE_LR_QsEn 4 /* Q value of smoothed sqrt band energy */ #define G1_RANGE 4 -#define G1G2_RANGE 15 -#define GRP_SB 4 /*Maximum subband groups*/ +#define G1G2_RANGE 15 +#define GRP_SB 4 /*Maximum subband groups*/ #define THR1 4 /* Bit allocation threshold value */ #define THR2 5 /* Bit allocation threshold value */ #define THR3 6 /* Bit allocation threshold value */ #define NB_SWB_SUBBANDS 4 /* maximum number of subbands in normal2 subband coding */ - #define SWB_SB_LEN0_12KBPS 55/* length of subband number X in lowest bit rate operation */ #define SWB_SB_LEN1_12KBPS 68 #define SWB_SB_LEN2_12KBPS 84 #define SWB_SB_LEN3_12KBPS 105 - #define SWB_HIGHBAND_12KBPS (SWB_SB_LEN0_12KBPS+SWB_SB_LEN1_12KBPS+SWB_SB_LEN2_12KBPS+SWB_SB_LEN3_12KBPS) -#define SWB_LOWBAND_12KBPS (HQ_GENERIC_END_FREQ - SWB_HIGHBAND_12KBPS) +#define SWB_LOWBAND_12KBPS (HQ_GENERIC_END_FREQ_14P2KHZ - SWB_HIGHBAND_12KBPS) #define SWB_HIGHBAND_MAX SWB_HIGHBAND_12KBPS #define SWB_LOWBAND_MAX SWB_LOWBAND_12KBPS @@ -1691,9 +1691,8 @@ enum QuantaMode { NEAREST = 0, CONS }; #define SWB_SB_LEN1_16KBPS 74 #define SWB_SB_LEN2_16KBPS 92 #define SWB_SB_LEN3_16KBPS 115 - #define SWB_HIGHBAND_16KBPS (SWB_SB_LEN0_16KBPS+SWB_SB_LEN1_16KBPS+SWB_SB_LEN2_16KBPS+SWB_SB_LEN3_16KBPS) -#define SWB_LOWBAND_16KBPS (HQ_GENERIC_END_FREQ - SWB_HIGHBAND_16KBPS) +#define SWB_LOWBAND_16KBPS (HQ_GENERIC_END_FREQ_16P0KHZ - SWB_HIGHBAND_16KBPS) #define SWB_SB_OFF0_16KBPS 0 /* subband offsets are based on the subband lengths */ #define SWB_SB_OFF1_16KBPS (SWB_SB_OFF0_16KBPS + SWB_SB_LEN0_16KBPS) @@ -1707,14 +1706,12 @@ enum QuantaMode { NEAREST = 0, CONS }; /* SpectrumSmoothing for NSS */ #define L_SB_NSS 8 #define L_SB_NSS_HALF (L_SB_NSS/2) -#define NUM_SUBBAND_SMOOTH_MAX (L_FRAME32k/L_SB_NSS+1) +#define NUM_SUBBAND_SMOOTH_MAX (SWB_HIGHBAND_12KBPS/L_SB_NSS+1) #define MA_LEN 7 /* Harmonic mode */ #define NB_SWB_SUBBANDS_HAR_SEARCH_SB 2 /* search number of subbands in harmonic subband coding */ #define NB_SWB_SUBBANDS_HAR 4 /* maximum number of subbands in harmonic subband coding */ - - #define N_NBIGGEST_PULSEARCH 18 #define N_NBIGGEST_SEARCH_LRG_B 32 @@ -1749,6 +1746,12 @@ enum QuantaMode { NEAREST = 0, CONS }; #define SWB_HAR_RAN3 200 #define SPT_SHORTEN_SBNUM 4 +/* LRMDCT fix precision */ +#define SWB_BWE_LR_Qs 12 +#define SWB_BWE_LR_Qbe 14 +#define SWB_BWE_LR_QRk 16 + + /*----------------------------------------------------------------------------------* * FEC for HQ core *----------------------------------------------------------------------------------*/ @@ -1756,84 +1759,95 @@ enum QuantaMode { NEAREST = 0, CONS }; #define MAX_PGF 7 #define MAX_ROW 2 +#define MAX_SB_NB 3 + +#define NELP_LP_ORDER 8 +#define NUM_NELP_GAINS 10 + #define MINIMUM_RATE_TO_ENCODE_VOICING_FLAG 45000 +#define FRAC_BWE_SMOOTH 2.0f /* >= 1 */ #define FRAMECTTOSTART_MDCT 3 /*----------------------------------------------------------------------------------* - * Channel-aware mode (FEC) + * Channel aware mode (FEC) *----------------------------------------------------------------------------------*/ #define FEC_OFFSET 3 #define MAX_RF_FEC_OFFSET 9 + /*----------------------------------------------------------------------------------* * HQ FEC *----------------------------------------------------------------------------------*/ +#define POST_HQ_DELAY_NS DELAY_BWE_TOTAL_NS /* delay of post processing after core HQ coding */ +#define PH_ECU_ALDO_OLP2_NS (ACELP_LOOK_NS/2) /* half length of ALDO WINDOW overlap */ +#define PH_ECU_LOOKAHEAD_NS (11*ACELP_LOOK_NS/(7*2)) /* Number of nanoseconds look-ahead ahead from the end of the past synthesized frame */ +#define PH_ECU_MEM_NS ((L_PROT48k/48 - 20)*1000000-PH_ECU_LOOKAHEAD_NS) /* Number of nanoseconds memory for Phase ECU before the old_synthFB_fx pointer */ + +#define N_LEAD_NB 70 /* (N_LEAD_MDCT*(L_FRAME8k/20)) */ +#define N_ZERO_NB 45 /* (N_ZERO_MDCT*(L_FRAME8k/20)) */ +#define N_LEAD_O_NB 90 /* (20.f-N_LEAD_MDCT)*(L_FRAME8k/20) */ +#define N_ZERO_O_NB 35 /* (10.f-N_ZERO_MDCT)*(L_FRAME8k/20) */ +#define N_Z_L_NB 115 /* (N_Z_L_MDCT*(float)(L/20)) = N_ZERO_NB + N_LEAD_NB*/ +#define N_Z_L_O_NB 205 /* (N_Z_L_O_MDCT*(float)(L/20)) = N_ZERO_NB + N_LEAD_NB + N_LEAD_O_NB */ + +#define L_PROT32k 1024 /* HQ phase ECU prototype frame length */ +#define MAX_PLOCS L_PROT48k/4+1 /* maximum number of spectral peaks to be searched */ +#define QUOT_LPR_LTR 4 +#define LGW_MAX 9 /* maximum number frequency group widths */ +#define BETA_MUTE_FAC_INI 0.5f /* initial noise attenuation factor */ +#define L_TRANA32k (L_PROT32k/QUOT_LPR_LTR) /* transient analysis frame length */ +#define L_TRANA16k (L_TRANA32k/2) +#define L_TRANA8k (L_TRANA32k/4) +#define L_PROT_HAMM_LEN2_48k NS2SA(48000,6000000L) +#define L_PROT_HAMM_LEN2_32k NS2SA(32000,6000000L) +#define L_PROT_HAMM_LEN2_16k NS2SA(16000,6000000L) +#define L_PROT48k L_PROT32k * 3/2 /* HQ phase ECU prototype frame length */ +#define L_PROT48k_2 L_PROT48k/2 +#define L_TRANA48k (L_PROT48k/QUOT_LPR_LTR) /* transient analysis frame length */ +#define PH_ECU_SPEC_SIZE L_PROT48k +#define T_SIN_PI_2 (PH_ECU_SPEC_SIZE/4) +#define HQ_FEC_SIGN_SFM 16 +#define OFF_FRAMES_LIMIT 30 /* HQ phase ECU, burst length for muting to zero */ +#define PH_ECU_MUTE_START 15 /* HQ phase ECU, burst length to start steep muting */ + +#define SCALE_DOWN_3dB 0.7071f +#define MAX_TILT 0.f +#define ED_THRES 1.0f + +#define ED_THRES_12P 0.032209f +#define ED_THRES_50P 0.159063f +#define ED_THRES_90P 0.532669 #define MAXDELAY_FEC 224 -#define PH_ECU_ALDO_OLP2_NS (ACELP_LOOK_NS/2) /* half the aldo window overlap */ -#define PH_ECU_LOOKAHEAD_NS (11*ACELP_LOOK_NS/(7*2)) /* Number of nanoseconds look-ahead ahead from the end of the past synthesized frame */ -#define PH_ECU_MEM_NS ((Lprot48k/48 - 20)*1000000-PH_ECU_LOOKAHEAD_NS) /* Number of nanoseconds memory for Phase ECU before the old_synthFB_fx pointer */ -#define POST_HQ_DELAY_NS DELAY_BWE_TOTAL_NS /* delay of post processing after core HQ coding */ -#define MAX_PLOCS Lprot48k/4+1 /* maximum number of spectral peaks to be searched */ -#define Lprot32k 1024 /* HQ phase ECU prototype frame length */ -#define Lprot32k_2 Lprot32k/2 -#define Quot_Lpr_Ltr 4 -#define Lgw_max 9 /* maximum number frequency group widths */ -#define BETA_MUTE_FAC_INI 16384 /* Q15, initial noise attenuation factor */ -#define Ltrana32k (Lprot32k/Quot_Lpr_Ltr) /* transient analysis frame length */ -#define Ltrana16k Ltrana32k/2 -#define pfind_sens 0.9f /* peakfinder sensitivity - tuning parameter */ -#define Lprot_hamm_len2_48k NS2SA(48000,6000000L) -#define Lprot_hamm_len2_32k NS2SA(32000,6000000L) -#define Lprot_hamm_len2_16k NS2SA(16000,6000000L) -#define Lprot48k Lprot32k * 3/2 /* HQ phase ECU prototype frame length */ -#define Lprot48k_2 Lprot48k/2 -#define Ltrana48k (Lprot48k/Quot_Lpr_Ltr) /* transient analysis frame length */ -#define PH_ECU_SPEC_SIZE Lprot48k -#define T_SIN_PI_2 PH_ECU_SPEC_SIZE/4 #define RANDOM_START 1 -#define HQ_FEC_SIGN_SFM 16 #define HQ_FEC_SIGN_THRES 6 #define HQ_FEC_SIGN_THRES_TRANS 3 #define HQ_FEC_BAND_SIZE 4 + /*--------------------------------------------------------------* - * Tonal MDCT PLC constants + * Tonal MDCT PLC *---------------------------------------------------------------*/ -#define SPEC_EXP_DEC 20 #define MAX_NUMBER_OF_IDX 30 #define GROUP_LENGTH 7 #define MAX_PEAKS_FROM_PITCH 10 -#define LAST_HARMONIC_POS_TO_CHECK 128 /* 128 because we check harmonics only up to 3.2 kHz */ -#define FILTLEN 15 -#define ALLOWED_SIDE_LOBE_FLUCTUATION 24576/*3.0f Q13*/ /* 4.8 dB */ -#define ALLOWED_SIDE_LOBE_FLUCTUATION_EXP 2 -#define LEVEL_ABOVE_ENVELOPE 7.59f /* 8.8 dB */ -#define UNREACHABLE_THRESHOLD 16384/*16.0f Q10*/ /* 12 dB Increase of LEVEL_ABOVE_ENVELOPE so that the threshold is not reached */ -#define SMALL_THRESHOLD 1126/*1.10f Q10*/ /* 0.41 dB Increase of LEVEL_ABOVE_ENVELOPE for the peak detection at a definitive peak in the estimated spectrum */ -#define BIG_THRESHOLD 1536/*1.5f Q10*/ /* 1.76 dB Increase of LEVEL_ABOVE_ENVELOPE for the peak detection at a probable peak in the estimated spectrum */ +#define LAST_HARMONIC_POS_TO_CHECK 128 /* 128 because we check harmonics only up to 3.2 kHz */ +#define ALLOWED_SIDE_LOBE_FLUCTUATION 3.0f /* 4.8 dB */ +#define LEVEL_ABOVE_ENVELOPE 7.59f /* 8.8 dB */ +#define UNREACHABLE_THRESHOLD 16.0f /* 12 dB Increase of LEVEL_ABOVE_ENVELOPE so that the threshold is not reached */ +#define SMALL_THRESHOLD 1.10f /* 0.41 dB Increase of LEVEL_ABOVE_ENVELOPE for the peak detection at a definitive peak in the estimated spectrum */ +#define BIG_THRESHOLD 1.5f /* 1.76 dB Increase of LEVEL_ABOVE_ENVELOPE for the peak detection at a probable peak in the estimated spectrum */ #define kSmallerLagsTargetBitsThreshold 150 +#define kCtxHmOlRSThr 2.6f -#define kLtpHmGainThr 0x3AE1 /* 0.46f */ -#define kCtxHmOlRSThr 0x5333 /* 2.6f (2Q13) */ - -#define kTcxHmSnrOffsetGc 8/*0.03125f Q8*/ -#define kTcxHmSnrOffsetVc 0 #define kTcxHmNumGainBits 2 /* Number of bits for the gain index */ #define kTcxHmParabolaHalfWidth 4 /* Parabola half width */ -#define kLtpHmGainThr 0x3AE1 /* 0.46f */ /* Use the LTP pitch lag in the harmonic model? */ - -#define kSmallerLagsTargetBitsThreshold 150 - -#define TCX_LPC_OFFSET_SNR - -#define kTcxSnrOffsetGc 0x08 /* 0.03125f (7Q8) */ -#define kTcxSnrOffsetVc 0x20 /* 0.125f (7Q8) */ +#define kLtpHmGainThr 0.46f /* Use the LTP pitch lag in the harmonic model? */ #define LOWRATE_TCXLPC_MAX_BR ACELP_9k60 @@ -1851,17 +1865,17 @@ enum QuantaMode { NEAREST = 0, CONS }; /*---------------------------------------------------------------* * IGF * *---------------------------------------------------------------*/ -#define IGF_MAX_TILES 5 -#define IGF_MAX_GRANULE_LEN 1200 -#define IGF_TRANS_FAK 2 -#define IGF_MAX_SFB 23 -#define IGF_NOF_GRIDS 3 -#define IGF_MAX_SUBFRAMES 2 -#define IGF_MODE_WB 1 -#define IGF_MODE_SWB 2 -#define IGF_MODE_FB 3 +#define IGF_MAX_TILES 5 +#define IGF_MAX_GRANULE_LEN 1200 +#define IGF_TRANS_FAK 2 +#define IGF_MAX_SFB 23 +#define IGF_NOF_GRIDS 3 +#define IGF_MAX_SUBFRAMES 2 +#define IGF_MODE_WB 1 +#define IGF_MODE_SWB 2 +#define IGF_MODE_FB 3 #define IGF_BITRATE_WB_9600 0 #define IGF_BITRATE_RF_WB_13200 1 @@ -1880,21 +1894,20 @@ enum QuantaMode { NEAREST = 0, CONS }; #define IGF_BITRATE_FB_128000 14 #define IGF_BITRATE_UNKNOWN 15 +#define IGF_WHITENING_OFF 0 +#define IGF_WHITENING_MID 1 +#define IGF_WHITENING_STRONG 2 -#define IGF_WHITENING_OFF 0 -#define IGF_WHITENING_MID 1 -#define IGF_WHITENING_STRONG 2 - -#define IGF_GRID_LB_NORM 0 -#define IGF_GRID_LB_TRAN 1 -#define IGF_GRID_LB_SHORT 2 +#define IGF_GRID_LB_NORM 0 +#define IGF_GRID_LB_TRAN 1 +#define IGF_GRID_LB_SHORT 2 /* constants for IGFSCFDecoder and IGFSCFEncoder */ -#define IGF_CTX_OFFSET 3 /* offset added to make the context values nonnegative, for array indexing */ -#define IGF_CTX_COUNT (2 * IGF_CTX_OFFSET + 1) /* number of contexts for the AC statistical model */ -#define IGF_MIN_ENC_SEPARATE -12 /* minimum residual value coded separately, without escape coding */ -#define IGF_MAX_ENC_SEPARATE +12 /* maximum residual value coded separately, without escape coding */ -#define IGF_SYMBOLS_IN_TABLE (1 + (IGF_MAX_ENC_SEPARATE - IGF_MIN_ENC_SEPARATE + 1) + 1) /* alphabet size */ +#define IGF_CTX_OFFSET 3 /* offset added to make the context values nonnegative, for array indexing */ +#define IGF_CTX_COUNT (2 * IGF_CTX_OFFSET + 1) /* number of contexts for the AC statistical model */ +#define IGF_MIN_ENC_SEPARATE -12 /* minimum residual value coded separately, without escape coding */ +#define IGF_MAX_ENC_SEPARATE +12 /* maximum residual value coded separately, without escape coding */ +#define IGF_SYMBOLS_IN_TABLE (1 + (IGF_MAX_ENC_SEPARATE - IGF_MIN_ENC_SEPARATE + 1) + 1) /* alphabet size */ /*----------------------------------------------------------------------------------* * SC-VBR @@ -1904,33 +1917,14 @@ enum QuantaMode { NEAREST = 0, CONS }; #define UVG2_CBSIZE 64 /* NELP unvoiced gain-2 codebook size */ /* PPP constants */ - #define NUM_ERB_WB 24 /* Number of ERB bands in wideband */ #define NUM_ERB_NB 22 /* Number of ERB bands in narrowband */ -#define MAXLAG 180 - -#define PPP_LAG_THRLD_Q6 180*64 -#define PPP_LAG_THRLD 180 -#define SNR_THLD_FX_Q8 17152 /* Threshold is upscaled to Q8 to compared with st->vadsnr*/ +#define VBR_ADR_MAX_TARGET 6.15f /* max target ADR for VBR. This rate is used in the closed loop rate control */ +#define PPP_LAG_THRLD 180 /* max lag allowed for PPP coding */ #define MAXLAG_WI (PPP_LAG_THRLD/2 + 12) /* Maximum lag used in waveform interpolation */ -#define MAX_LAG_PIT (PPP_LAG_THRLD + 21) - -#define WI_FX_phase_fx 512 - -#define VBR_ADR_MAX_TARGET_x10_Q1 123 /* VBR_ADR_MAX_TARGET(6.15f)*10 in Q1 */ - -#define Q_SCALE 7 - -#define CONST_1_16_Q14 19005 /* 1.16*16384 */ -#define CONST_1_37_Q14 22446 /* 1.37*16384 */ -#define SCALE_DOWN_ERAS_Q15 26214 /* 0.8*32768 */ -#define SHAPE1_COEF_QF 15 /* shape1 num and den coeffcient Q format */ -#define SHAPE2_COEF_QF 15 /* shape2 num and den coeffcient Q format */ -#define SHAPE3_COEF_QF 15 /* shape3 num and den coeffcient Q format */ -#define BP1_COEF_WB_QF 14 /* wb num and den coeffcient Q format */ -#define BP1_COEF_NB_QF_ORDER7 13 /* nb num and den coeffcient Q format */ +#define MAX_LAG_PIT (PPP_LAG_THRLD + 21) /* Max possible pitch lag after adding delta lag */ /*----------------------------------------------------------------------------------* * JBM @@ -1939,389 +1933,25 @@ enum QuantaMode { NEAREST = 0, CONS }; #define MAX_JBM_SLOTS 100 /* every primary copy and partial copy stored in JBM needs one slot */ #define MAX_AU_SIZE (128000/50/8) /* max frame size in bytes */ -#define ACTIVE 4 -#define BACKGROUND 1 -#define LOST 14 -#define SIZE_UNDERFLOW_ARRAY 10000 -#define TIME_WARP_SPACING 4 -#define FLAG_DECREASING_BUFFER_DEPTH 1 -#define TIME_WARP_SPACING_EXPAND 1 -#define PREALLOCATE_OUTPUT_SIZE 1000 - -#define TSM_LOST 1 -#define TSM_AUDIO 2 -#define TSM_ONSET 3 -#define TSM_UNVOICED 4 -#define TSM_VOICED 5 -#define TSM_TRANSITION 6 -#define TSM_GENERIC 7 -#define TSM_BACKGROUND 8 - -/*------------------------------------------------------------------------------------* -FEC_clas_estim constants -*-------------------------------------------------------------------------------------*/ -#define Q_MAX 12 -#define LG10 24660 /* 10*log10(2) in Q13 */ -#define L_Q_MEM 5 - -#define GE_SHIFT 6 -#define LSF_1_OVER_256SQ 5000 -#define LSF_1_OVER_256SQSQ 763 - -#define G_CODE_MIN_TC_Q15 655 /*0.02 Q15*/ -#define G_CODE_MAX_TC_Q0 5 - -#define G_PITCH_MIN_Q14 0 /* SQ of gains: pitch gain lower limit (0.0 in Q13) */ -#define G_PITCH_MAX_MINUS_MIN_Q13 9994 /* SQ of gains: pitch gain upper limit (1.22-0 in Q13) */ - -/* higher ACELP constants */ -#define G_AVQ_MIN_32kbps_Q15 2621 /* lower limit for gain Q in higher-rate ACELP contribtuion @32kbps (0.08 in Q15) */ -#define G_AVQ_MIN_Q15 26214 /* lower limit for gain Q in higher-rate ACELP contribtuion (0.8 in Q15) */ -#define G_AVQ_MAX_Q0 96 /* upper limit for gain Q in higher-rate ACELP contribtuion */ - -#define LG10_G_AVQ_MIN_32kbps_Q14 (-17972) /* log10(0.08) lower limit for gain Q in higher-rate ACELP contribtuion @32kbps (0.08 in Q15) */ -#define LG10_G_AVQ_MIN_Q14 (-1588) /* log10(0.8) lower limit for gain Q in higher-rate ACELP contribtuion (0.8 in Q15) */ -#define LG10_G_AVQ_MAX_Q13 16239 /* log10(96) upper limit for gain Q in higher-rate ACELP contribtuion */ -#define LG10_G_CODE_MIN_TC192_Q14 (-3635) /* log10(0.6) */ -#define LG10_G_CODE_MAX_TC192_Q13 13212 /* log10(41) */ -#define LG10_G_CODE_MAX_Q13 5726 /* log10(5) SQ of gains: code gain upper limit */ -#define LG10_G_CODE_MIN_Q14 (-27836) /* log10(0.02) SQ of gains: code gain lower limit */ -#define LG10_G_CODE_MIN_TC_Q14 LG10_G_CODE_MIN_Q14 /* log10(0.02) Q15*/ -#define LG10_G_CODE_MAX_TC_Q13 LG10_G_CODE_MAX_Q13 - - -/* AVQ (RE8) related consatnts */ -#define QR 32768 -#define Q_AVQ_OUT 6 /* AVQ_output scaling currently Q9, but may change */ -#define Q_AVQ_OUT_DEC 10 - - -#define PIT_DECODE_2XL_SUBFR (2*L_SUBFR) -#define PIT_FR1_8b_MINUS_PIT_MIN_X2 ((PIT_FR1_8b-PIT_MIN)*2) -#define PIT_FR1_8b_MINUS_PIT_FR1_8b_MINUS_PIT_MIN_X2 (PIT_FR1_8b-PIT_FR1_8b_MINUS_PIT_MIN_X2) -#define PIT_FR2_9b_MINUS_PIT_MIN_X4 ((PIT_FR2_9b-PIT_MIN)*4) -#define PIT_FR1_EXT8b_MINUS_PIT_MIN_EXT_X2 ((PIT_FR1_EXTEND_8b-PIT_MIN_EXTEND)*2) -#define PIT_FR2_EXT9b_MINUS_PIT_MIN_EXT_X4 ((PIT_FR2_EXTEND_9b-PIT_MIN_EXTEND)*4) -#define PIT_FR1_EXT9b_MINUS_PIT_FR2_EXT9b_X2 ((PIT_FR1_EXTEND_9b-PIT_FR2_EXTEND_9b)*2) -#define PIT_FR1_DEXT8b_MINUS_PIT_MIN_DEXT_X2 ((PIT_FR1_DOUBLEEXTEND_8b-PIT_MIN_DOUBLEEXTEND)*2 ) -#define PIT_FR2_DEXT9b_MINUS_PIT_MIN_DEXT_X4 ((PIT_FR2_DOUBLEEXTEND_9b-PIT_MIN_DOUBLEEXTEND)*4 ) - -#define PIT_DECODE_1 ((PIT_FR2_9b-PIT_MIN)*4 + (PIT_FR1_9b-PIT_FR2_9b)*2) -#define PIT_DECODE_2 ((PIT_FR2_9b-PIT_MIN)*4) -#define PIT_DECODE_3 (PIT_FR1_9b - ((PIT_FR2_9b-PIT_MIN)*4) - ((PIT_FR1_9b-PIT_FR2_9b)*2)) -#define PIT_DECODE_7 (PIT_FR1_EXTEND_9b - (PIT_FR2_EXT9b_MINUS_PIT_MIN_EXT_X4) - (PIT_FR1_EXT9b_MINUS_PIT_FR2_EXT9b_X2)) -#define PIT_DECODE_8 (PIT_FR1_DOUBLEEXTEND_8b - ((PIT_FR1_DOUBLEEXTEND_8b-PIT_MIN_DOUBLEEXTEND)*2)) -#define PIT_DECODE_9 (( (PIT_FR2_DOUBLEEXTEND_9b-PIT_MIN_DOUBLEEXTEND)*4 + (PIT_FR1_DOUBLEEXTEND_9b-PIT_FR2_DOUBLEEXTEND_9b)*2)) -#define PIT_DECODE_10 (PIT_FR1_DOUBLEEXTEND_9b - ((PIT_FR2_DOUBLEEXTEND_9b-PIT_MIN_DOUBLEEXTEND)*4) - ((PIT_FR1_DOUBLEEXTEND_9b-PIT_FR2_DOUBLEEXTEND_9b)*2)) - -#define BIN4_FX 800 -#define TH_COR_FX 19661 /* Q15 Minimum correlation for per bin processing */ -#define TH_D_FX 800 /* 50 (Q4) Difference limit between nearest harmonic and a frequency bin */ -#define TH_PIT_FX 128 /* (Fs / (2.0f * TH_D)) Maximum pitch for per bin processing */ - -#define GUESS_TBL_SZ 256 -#define INT_FS_FX 12800 /* internal sampling frequency */ -#define INT_FS_16k_FX 16000 /* CELP core internal sampling frequency @16kHz */ - -#define WB_LIMIT_LSF_FX 16256 -#define Fs_2 16384 /* lsf max value (Use in reorder_fx.c) */ -#define Fs_2_16k 20480 /* lsf max value (Use in reorder_fx.c) */ - -#define LG10 24660 /* 10*log10(2) in Q13 */ -#define LG10_s3_0 16440 /* 10*log10(2)/1.55 = 1.00343331 in Q14 */ - -#define MU_MA_FX 10923 /* original prediction factor for the AMR WB tables (Q15) */ - -#define E_MIN_FXQ15 115 /* Q15*/ - -#define MAX_DYNAMIC_FX (82*128) -#define MIN_DYNAMIC_FX (50*128) -#define DYNAMIC_RANGE_FX (MAX_DYNAMIC_FX-MIN_DYNAMIC_FX) -#define MAX_GSC_NF_BITS 3 -#define GSC_NF_STEPS (1 << MAX_GSC_NF_BITS) -#define GSF_NF_DELTA_FX (DYNAMIC_RANGE_FX/GSC_NF_STEPS) - /*----------------------------------------------------------------------------------* - * DTC/iDCT constants + * TEC/TFA *----------------------------------------------------------------------------------*/ - -/* DCT related */ -#define KP559016994_16FX 1200479845 /* EDCT & EMDCT constants */ -#define KP951056516_16FX 2042378325 /* EDCT & EMDCT constants */ -#define KP587785252_16FX 1262259213 /* EDCT & EMDCT constants */ - -/*----------------------------------------------------------------------------------* - * AVQ constants - *----------------------------------------------------------------------------------*/ - -#define MIN_GLOB_GAIN_BWE_HR_FX 24576 /* Q13 */ -#define MAX_GLOB_GAIN_BWE_HR_FX 32000 /* Q6 */ - -#define LG10_MIN_GLOB_GAIN_BWE_HR_Q14 7817 -#define LG10_MAX_GLOB_GAIN_BWE_HR_Q13 22110 +#define DELAY_TEMP_ENV_BUFF_TEC 9 +#define EXT_DELAY_HI_TEMP_ENV 2 /*----------------------------------------------------------------------------------* - * LD music post-filter constants + * BASOP ROM Tables *----------------------------------------------------------------------------------*/ -#define BIN_16kdct_fx (6400/DCT_L_POST) -#define E_MIN_Q15 14680 /* 0.0035 -> Q22 */ +#define LD_INT_TAB_LEN 120 +#define INV_TABLE_SIZE 256 +#define SQRT_TABLE_SIZE 256 -#define QSCALE 7 -#define MODE2_E_MIN 4/*0.03f Q0*/ /* 0.03f in QSCALE */ -#define MODE2_E_MIN_Q15 983/*0.03f Q15*/ /* 0.03f in Q15*/ - -/* long term pst parameters : */ -#define L2_LH2_L 4 /* log2(LH2_L) */ -#define MIN_GPLT_FX 21845 /* LT gain minimum 1/1.5 (Q15) */ - -#define AGC_FAC_FX 32358 /* gain adjustment factor 0.9875 (Q15) */ -#define AGC_FAC1_FX (Word16)(32768L - AGC_FAC_FX) - -#define DOWNMIX_12k8_FX 1850 /*----------------------------------------------------------------------------------* - * HQ Constants + * Decoder modes *----------------------------------------------------------------------------------*/ - -#define INV2POWHALF 23170 /* Q15, sqrt(2)/2 */ -#define EPSILLON_FX (Word16) 1 -#define MAX_SFM_LEN_FX 96 -#define MAX_P_ATT_FX (Word16) 40 /* Maximum number of pulses for gain attenuation factor */ -#define MAX_PHG_FX (Word16) 10 /* Q0, Maximum number of pulses for which to apply pulse height dependent gain */ -#define PHG_START_FX (Word16) 3277 /* Q15, 0.1f */ -#define PHG_DELTA_FX (Word16) 2621 /* Q15, ((PHG_END-PHG_START)/MAX_PHG) */ -#define ENV_ADJ_START_FX (Word16) 6 /* Q0, Number of consecutive bands for which the attenuation is maximum */ -#define ENV_ADJ_INV_INCL_FX (Word16) 6554 /* Q15, 1/5.0f, Inverse inclination for mapping between attenuation region width and attenuation limit */ - -#define INV_HVQ_THRES_BIN_24k 9362 /* 1/224 in Q21 */ -#define INV_HVQ_THRES_BIN_32k 6554 /* 1/320 in Q21 */ -#define INV_BANDS_PER_SUBFRAMES 14564 /* 1/9 in Q17 */ -#define NUM_SUBFRAMES 4 -#define BANDS_PER_SUBFRAMES 9 -#define ENERGY_TH_NUM_SUBFRAMES 1638400L /* 400 in Q12 */ -#define INV_SFM_N_ENV_STAB 19418 /* 1/27 in Q19 */ -#define ENERGY_TH_FX 819200L /* 100 in Q13 */ -#define ENERGY_LT_BETA_FX 30474 /* 0.93 in Q15 - Smoothing factor for long-term energy measure */ -#define ENERGY_LT_BETA_1_FX 2294 /* 0.07 i Q15 - (1 - ENERGY_LT_BETA_FX) */ -#define INV_DELTA_TH 13107 /* 1/5 in Q16 - Inverse Delta energy threshold for transient detection for envelope stability */ - -#define ONE_OVER_HVQ_BAND_MAX_BITS_24k_FX ((Word16) 410) /* Q15, 1/80 = 0.0125 */ -#define ONE_OVER_HVQ_BAND_MAX_BITS_32k_FX ((Word16) 345) /* Q15, 1/95 = 0.010526315 */ - -#define INV_PREECHO_SMOOTH_LENP1_FX 1560 /*(32768 / (PREECHO_SMOOTH_LEN + 1.0));*/ - -#define INV_HVQ_BW 1024 /* Q15 1/32 */ - -#define ACELP_48k_BITS 960 /* Q0 - ACELP_48k / 50 */ - - -/*-------------------------------------- - * FEC_HQ_phase_ecu - *-------------------------------------*/ - -#define OFF_FRAMES_LIMIT 30 /* Hard limit the variable "time_offs" to 30 */ - -/*----------------------------------------------------------------------------------* - * FEC for HQ core - *----------------------------------------------------------------------------------*/ - - -#define MAX_SB_NB 3 - - -#define NELP_LP_ORDER 8 -#define NUM_NELP_GAINS 10 - -#define N_LEAD_NB 70 /* (N_LEAD_MDCT*(L_FRAME8k/20)) */ -#define N_ZERO_NB 45 /* (N_ZERO_MDCT*(L_FRAME8k/20)) */ -#define N_LEAD_O_NB 90 /* (20.f-N_LEAD_MDCT)*(L_FRAME8k/20) */ -#define N_ZERO_O_NB 35 /* (10.f-N_ZERO_MDCT)*(L_FRAME8k/20) */ -#define N_Z_L_NB 115 /* (N_Z_L_MDCT*(float)(L/20)) = N_ZERO_NB + N_LEAD_NB*/ -#define N_Z_L_O_NB 205 /* (N_Z_L_O_MDCT*(float)(L/20)) = N_ZERO_NB + N_LEAD_NB + N_LEAD_O_NB */ - -#define ED_THRES_12P_fx 66 -#define ED_THRES_50P_fx 326 -#define ED_THRES_90P_fx 1091 - -/*----------------------------------------------------------------------------------* - * ISF quantizer constants - *----------------------------------------------------------------------------------*/ - -/*qlpc_avq, lsf_msvq_ma*/ -#define W_MODE0 0x1333 /*60.0f/FREQ_DIV in 0Q15*/ -#define W_MODE1 0x14CD /*65.0f/FREQ_DIV in 0Q15*/ -#define W_MODE2 0x147B /*64.0f/FREQ_DIV in 0Q15*/ -#define W_MODE_ELSE 0x1429 /*60.0f/FREQ_DIV in 0Q15*/ - - -enum TRACKPOS -{ - TRACKPOS_FIXED_FIRST =0, /* Fill tracks from left */ - TRACKPOS_FIXED_EVEN =1, /* Even tracks */ - TRACKPOS_FIXED_FIRST_TWO =2, /* One track of 32 */ - TRACKPOS_FIXED_TWO =3, /* Two tracks of 32 instead of four of 16 */ - TRACKPOS_FREE_ONE =4, /* One freely moving track with extra pulse */ - TRACKPOS_FREE_THREE =5 /* Three freely moving tracks with single extra pulses */ -}; - -#define ALP_E 2 - -/* Lag window strengths */ -enum -{ - LAGW_WEAK, /* weak lag window */ - LAGW_MEDIUM, /* medium strength lag window */ - LAGW_STRONG, /* strong lag window */ - - NUM_LAGW_STRENGTHS -}; - -/* qmc_cng_common.h */ -/* codec side */ -#define SCALE_TABLE_SHIFT_FACTOR (31-23) - -/* parameter_bitmapping.h */ -#define NPARAMS_MAX 10 - -/*tns_tables.h*/ - -#define TRUE 1 -#define FALSE 0 - -#define PRED_GAIN_E 8 - -/* Flags for CLDFB intialization */ -/* Flag indicating that the states should be kept. */ -#define CLDFB_FLAG_KEEP_STATES 8 -/* Flag indicating 2.5 ms setup */ -#define CLDFB_FLAG_2_5MS_SETUP 128 - - -/* bits_alloc.h */ -#define RATE_MODE_MAX 2 /*Number of rate mode*/ -#define BANDWIDTH_MODE_MAX 2 /*Number of different bandwidth modes (NB/WB-FB)*/ - - -typedef enum SIGNAL_CLASSIFER_MODE -{ - CLASSIFIER_ACELP, - CLASSIFIER_TCX -} SIGNAL_CLASSIFIER_MODE; - - -#define NRG_CHANGE_E 8 -#define AVG_FLAT_E 8 - -#define FRAME_SIZE_NB 13 - -/* RTP Payload Header Info */ -#define ACTIVE_FRAME 0xFF -#define SID_FRAME 0xFA -#define ZERO_FRAME 0xF0 - - -/************************************************************************/ - -/************************************************************************/ -#define UNKNOWN_NOISE 0 -#define SILENCE 1 - -#define CNT0P1 1717986918 /* 0.1*2^34 */ -#define CNT0P001 1099511627 /* 0.001*2^40 */ -#define CNT0P0001 1759218604 /* 0.0001*2^44 */ - -#define CNT0P05 1717986918 /* 0.05*2^35 */ - -#define CNT1DIV28 1227133513 /* (1/28)*2^35 */ -#define CNT1DIV14 1227133513 /* (1/14)*2^34 */ -#define CNT1DIV8 1073741824 /* (1/8)*2^33 */ - -#define SP_CENTER_Q 10 -#define ITD_STABLE_RATE_Q 15 -#define SPEC_AMP_Q 14 -#define SFM_Q 15 -#define TONA_Q 14 -#define lt_bg_highf_eng_Q 16 - -/************************************************************************/ -/* TEC/TFA */ -/************************************************************************/ -#define DELAY_TEMP_ENV_BUFF_TEC 9 -#define EXT_DELAY_HI_TEMP_ENV 2 - - -/************************************************************************/ -/* CLDFB */ -/************************************************************************/ - -#define SCALE_MODULATION ( 1 ) - -#define SCALE_GAIN_ANA_10 ( 4 ) -#define SCALE_GAIN_ANA_16 ( 3 ) -#define SCALE_GAIN_ANA_20 ( 3 ) -#define SCALE_GAIN_ANA_32 ( 2 ) -#define SCALE_GAIN_ANA_40 ( 2 ) -#define SCALE_GAIN_ANA_60 ( 1 ) - -#define SCALE_GAIN_SYN (-6 ) - -#define SCALE_CLDFB_ANA_10 ( SCALE_MODULATION + SCALE_GAIN_ANA_10 ) -#define SCALE_CLDFB_ANA_16 ( SCALE_MODULATION + SCALE_GAIN_ANA_16 ) -#define SCALE_CLDFB_ANA_20 ( SCALE_MODULATION + SCALE_GAIN_ANA_20 ) -#define SCALE_CLDFB_ANA_32 ( SCALE_MODULATION + SCALE_GAIN_ANA_32 ) -#define SCALE_CLDFB_ANA_40 ( SCALE_MODULATION + SCALE_GAIN_ANA_40 ) -#define SCALE_CLDFB_ANA_60 ( SCALE_MODULATION + SCALE_GAIN_ANA_60 ) - -#define SCALE_CLDFB_SYN_10 ( SCALE_MODULATION + SCALE_GAIN_SYN ) -#define SCALE_CLDFB_SYN_16 ( SCALE_MODULATION + SCALE_GAIN_SYN ) -#define SCALE_CLDFB_SYN_20 ( SCALE_MODULATION + SCALE_GAIN_SYN ) -#define SCALE_CLDFB_SYN_32 ( SCALE_MODULATION + SCALE_GAIN_SYN ) -#define SCALE_CLDFB_SYN_40 ( SCALE_MODULATION + SCALE_GAIN_SYN ) -#define SCALE_CLDFB_SYN_60 ( SCALE_MODULATION + SCALE_GAIN_SYN ) - -/************************************************************************/ -/* FFT */ -/************************************************************************/ - -#define SCALEFACTORN2 ( 3) -#define SCALEFACTOR2 ( 2) -#define SCALEFACTOR3 ( 3) -#define SCALEFACTOR4 ( 3) -#define SCALEFACTOR5 ( 4) -#define SCALEFACTOR8 ( 4) -#define SCALEFACTOR10 ( 5) -#define SCALEFACTOR12 ( 5) -#define SCALEFACTOR15 ( 5) -#define SCALEFACTOR16 ( 5) -#define SCALEFACTOR20 ( 5) -#define SCALEFACTOR24 ( 6) -#define SCALEFACTOR30 ( 6) -#define SCALEFACTOR30_1 ( 5) -#define SCALEFACTOR30_2 ( 1) -#define SCALEFACTOR32 ( 6) -#define SCALEFACTOR32_1 ( 5) -#define SCALEFACTOR32_2 ( 1) -#define SCALEFACTOR40 ( 7) -#define SCALEFACTOR60 ( 7) -#define SCALEFACTOR64 ( 7) -#define SCALEFACTOR80 ( 8) -#define SCALEFACTOR100 (10) -#define SCALEFACTOR120 ( 8) -#define SCALEFACTOR128 ( 8) -#define SCALEFACTOR160 ( 8) -#define SCALEFACTOR192 (10) -#define SCALEFACTOR200 (10) -#define SCALEFACTOR240 ( 9) -#define SCALEFACTOR256 ( 9) -#define SCALEFACTOR320 (10) -#define SCALEFACTOR400 (10) -#define SCALEFACTOR480 (11) -#define SCALEFACTOR600 (10) - -#define BASOP_CFFT_MAX_LENGTH 600 - enum { PRIMARY_2800, @@ -2339,7 +1969,7 @@ enum PRIMARY_SID, PRIMARY_FUT1, SPEECH_LOST, - NO_DATA_TYPE + _NO_DATA }; enum @@ -2353,13 +1983,13 @@ enum AMRWB_IO_1985, AMRWB_IO_2305, AMRWB_IO_2385, - AMRWB_IO_SID - /*, AMRWB_IO_FUT1, - AMRWB_IO_FUT2, - AMRWB_IO_FUT3, - AMRWB_IO_FUT4, - SPEECH_LOST, - NO_DATA_TYPE */ + AMRWB_IO_SID/*, + AMRWB_IO_FUT1, + AMRWB_IO_FUT2, + AMRWB_IO_FUT3, + AMRWB_IO_FUT4, + SPEECH_LOST, + _NO_DATA */ }; enum @@ -2368,4 +1998,4 @@ enum MIME }; -#endif /* CNST_FX_H */ +#endif /* CNST_H */ diff --git a/src/libs/libevs/lib_com/codec_tcx_common.cpp b/src/libs/libevs/lib_com/codec_tcx_common.cpp old mode 100755 new mode 100644 index 595806d0..3430c895 --- a/src/libs/libevs/lib_com/codec_tcx_common.cpp +++ b/src/libs/libevs/lib_com/codec_tcx_common.cpp @@ -1,288 +1,173 @@ /*==================================================================================== - EVS Codec 3GPP TS26.442 Apr 03, 2018. Version 12.11.0 / 13.6.0 / 14.2.0 + EVS Codec 3GPP TS26.443 Nov 13, 2018. Version 12.11.0 / 13.7.0 / 14.3.0 / 15.1.0 ====================================================================================*/ -#include -#include "prot_fx.h" +#include +#include "prot.h" #include "options.h" -#include "stl.h" -#include "prot_fx.h" -#include "basop_util.h" -#include "rom_basop_util.h" -#define inv_int InvIntTable +/*-------------------------------------------------------------------* + * tcxGetNoiseFillingTilt() + * + * + *-------------------------------------------------------------------*/ - - -Word16 tcxGetNoiseFillingTilt(Word16 A[], Word16 lpcorder, Word16 L_frame, Word16 mode, Word16 *noiseTiltFactor) +int tcxGetNoiseFillingTilt( + float A[], + int L_frame, + int mode, + float *noiseTiltFactor +) { - Word16 firstLine; - Word32 tmp; - Word16 As[M+1]; + int firstLine; - - IF (mode != 0) + if (mode) { - firstLine = idiv1616U(L_frame, 6); - *noiseTiltFactor = 18432/*0.5625f Q15*/; - move16(); + firstLine = L_frame / 6; + *noiseTiltFactor = 0.5625f; } - ELSE + else { - firstLine = shr(L_frame, 3); - - Copy_Scale_sig( A, As, lpcorder+1, sub(norm_s(A[0]),2) ); - tmp = get_gain(As+1, As, lpcorder); - BASOP_SATURATE_WARNING_OFF; - *noiseTiltFactor = add(round_fx(L_shl(tmp, 15)), 3072/*0.09375f Q15*/); - move16(); - BASOP_SATURATE_WARNING_ON; + firstLine = L_frame / 8; + *noiseTiltFactor = get_gain( A+1, A, M, NULL ); + *noiseTiltFactor = min(1.0f, (*noiseTiltFactor) + 0.09375f); } - return firstLine; } +/*-------------------------------------------------------------------* + * tcxFormantEnhancement() + * + * + *-------------------------------------------------------------------*/ void tcxFormantEnhancement( - Word16 xn_buf[], - Word16 gainlpc[], Word16 gainlpc_e[], - Word32 spectrum[], Word16 *spectrum_e, - Word16 L_frame, - Word16 L_frameTCX + float xn_buf[], + float gainlpc[], + float spectrum[], + int L_frame ) { - Word16 i, j, k, l, n; - Word16 fac, fac0, fac1, fac_e, d, tmp; - Word16 xn_buf_e, xn_one, m, e; + int k; + int i, j, l = 0; + float fac, step; - - k = shr(L_frame, 6); /* FDNS_NPTS = 64 */ - l = 0; - move16(); - - /* get exponent */ - xn_buf_e = 0; - move16(); - FOR (i = 0; i < FDNS_NPTS; i++) - { - xn_buf_e = s_max(xn_buf_e, gainlpc_e[i]); - } - xn_buf_e = shr(add(xn_buf_e, 1), 1); /* max exponent after sqrt */ - xn_one = shr(0x4000, sub(xn_buf_e, 1)); /* 1.0 scaled to xn_buf_e */ + k = L_frame / FDNS_NPTS; /* Formant enhancement via square root of the LPC gains */ - e = gainlpc_e[0]; - move16(); - m = Sqrt16(gainlpc[0], &e); - xn_buf[0] = shl(m, sub(e, xn_buf_e)); - move16(); + xn_buf[0] = (float)sqrt(gainlpc[0]); + xn_buf[1] = (float)sqrt(gainlpc[1]); + fac = 1.0f / min(xn_buf[0], xn_buf[1]); - e = gainlpc_e[1]; - move16(); - m = Sqrt16(gainlpc[1], &e); - xn_buf[1] = shl(m, sub(e, xn_buf_e)); - move16(); - - fac0 = s_min(xn_buf[0], xn_buf[1]); - fac_e = xn_buf_e; - move16(); - fac0 = Inv16(fac0, &fac_e); - - FOR (i = 1; i < FDNS_NPTS-1; i++) + for (i = 1; i < FDNS_NPTS - 1; i++) { - e = gainlpc_e[i+1]; - move16(); - m = Sqrt16(gainlpc[i+1], &e); - xn_buf[i+1] = shl(m, sub(e, xn_buf_e)); - move16(); + xn_buf[i+1] = (float)sqrt(gainlpc[i+1]); - test(); - IF ((sub(xn_buf[i-1], xn_buf[i]) <= 0) && (sub(xn_buf[i+1], xn_buf[i]) <= 0)) + if ((xn_buf[i-1] <= xn_buf[i]) && (xn_buf[i+1] <= xn_buf[i])) { - m = s_max(xn_buf[i-1], xn_buf[i+1]); - e = xn_buf_e; - move16(); - m = Inv16(m, &e); - - fac1 = m; - move16(); - tmp = sub(e, fac_e); - - if (tmp > 0) fac0 = shr(fac0, tmp); - if (tmp < 0) fac1 = shl(fac1, tmp); - - if (tmp > 0) + step = max(xn_buf[i-1], xn_buf[i+1]); + step = (1.0f / step - fac) / (float)(i - l); + xn_buf[l] = 1.0f; + fac += step; + for (j = l + 1; j < i; j++) { - fac_e = e; - move16(); + xn_buf[j] = min(1.0f, xn_buf[j] * fac); + fac += step; } - - d = sub(fac1, fac0); - n = sub(i, l); - assert(n <= 64); - - xn_buf[l] = xn_one; - move16(); - FOR (j = 1; j < n; j++) - { - fac = add(fac0, mult(d, extract_l(L_mult0(j, inv_int[n])))); - BASOP_SATURATE_WARNING_OFF; - xn_buf[l+j] = s_min(xn_one, shl(mult(xn_buf[l+j], fac), fac_e)); - move16(); - BASOP_SATURATE_WARNING_ON; - } - l = i; - move16(); - - fac0 = m; - move16(); - fac_e = e; - move16(); } } - /* i = FDNS_NPTS - 1; Completing changes to gains */ - m = s_min(xn_buf[i-1], xn_buf[i]); - e = xn_buf_e; - move16(); - m = Inv16(m, &e); - fac1 = m; - move16(); - tmp = sub(e, fac_e); - - if (tmp > 0) fac0 = shr(fac0, tmp); - if (tmp < 0) fac1 = shl(fac1, tmp); - - if (tmp > 0) + /* i = tcx_cfg->fdns_npts - 1; Completing changes to gains */ + step = min(xn_buf[i-1], xn_buf[i]); + step = (1.0f / step - fac) / (float)(i - l); + xn_buf[l] = 1.0f; + fac += step; + for (j = l + 1; j < i; j++) { - fac_e = e; - move16(); + xn_buf[j] = min(1.0f, xn_buf[j] * fac); + fac += step; } - - d = sub(fac1, fac0); - n = sub(i, l); - assert(n <= 64); - - xn_buf[l] = xn_one; - move16(); - FOR (j = 1; j < n; j++) - { - fac = add(fac0, mult(d, extract_l(L_mult0(j, inv_int[n])))); - BASOP_SATURATE_WARNING_OFF; - xn_buf[l+j] = s_min(xn_one, shl(mult(xn_buf[l+j], fac), fac_e)); - move16(); - BASOP_SATURATE_WARNING_ON; - } - - xn_buf[i] = xn_one; - move16(); + xn_buf[i] = 1.0f; /* Application of changed gains onto decoded MDCT lines */ - FOR (i = 0; i < L_frame; i += k) + for (i = j = 0; i < L_frame; j++) { - FOR (l = 0; l < k; l++) + for (l = 0; l < k; i++, l++) { - *spectrum = Mpy_32_16_1(*spectrum, *xn_buf); - move32(); - spectrum++; + spectrum[i] *= xn_buf[j]; } - xn_buf++; } - tmp = sub(L_frameTCX, L_frame); - FOR (i = 0; i < tmp; i++) - { - spectrum[i] = L_shr(spectrum[i], xn_buf_e); - move32(); - } - *spectrum_e = add(*spectrum_e, xn_buf_e); - move16(); - + return; } -void tcxInvertWindowGrouping(TCX_config *tcx_cfg, - Word32 xn_buf[], - Word32 spectrum[], - Word16 L_frame, - Word8 fUseTns, - Word16 last_core, - Word16 index, - Word16 frame_cnt, - Word16 bfi) +/*-------------------------------------------------------------------* + * tcxGetNoiseFillingTilt() + * + * + *-------------------------------------------------------------------*/ + +void tcxInvertWindowGrouping( + TCX_config *tcx_cfg, + float xn_buf[], + float spectrum[], + int L_frame, + int fUseTns, + int last_core, + int index, + int frame_cnt, + int bfi +) { - Word16 i, L_win, L_spec; - Word32 *p; + short i, w, t_integer; + int L_win, L_spec; - - L_win = shr(L_frame, 1); - L_spec = tcx_cfg->tnsConfig[0][0].iFilterBorders[0]; - move16(); - - test(); - test(); - if ((frame_cnt != 0) && (bfi == 0) && (last_core != ACELP_CORE)) /* fix sub-window overlap */ + if (frame_cnt && !bfi && last_core!=0) { + /* fix sub-window overlap */ tcx_cfg->tcx_last_overlap_mode = tcx_cfg->tcx_curr_overlap_mode; - move16(); } - test(); - test(); - test(); - test(); - test(); - test(); - test(); - IF (((bfi==0) &&((tcx_cfg->tcx_last_overlap_mode != FULL_OVERLAP) || - ((tcx_cfg->tcx_curr_overlap_mode == FULL_OVERLAP) && (frame_cnt == 0) && (index == 0)))) - || - ((bfi!=0) &&((tcx_cfg->tcx_last_overlap_mode != FULL_OVERLAP) && - !(tcx_cfg->tcx_curr_overlap_mode == FULL_OVERLAP)))) + + if (((!bfi) &&((tcx_cfg->tcx_last_overlap_mode != FULL_OVERLAP) || + ((tcx_cfg->tcx_curr_overlap_mode == FULL_OVERLAP) && (frame_cnt == 0) && (index == 0)))) + || + ((bfi) &&((tcx_cfg->tcx_last_overlap_mode != FULL_OVERLAP) && + !(tcx_cfg->tcx_curr_overlap_mode == FULL_OVERLAP)))) { + /* ungroup sub-windows: deinterleave MDCT bins into separate windows */ - p = xn_buf; - FOR (i = 1; i < L_win; i += 2) + for (t_integer = w = 0; w < 2; w++) { - *p++ = spectrum[i]; - move32(); - } - - p = spectrum; - FOR (i = 0; i < L_frame; i += 2) - { - *p++ = spectrum[i]; - move32(); - } - - p = spectrum + L_frame - 1; - FOR (i = sub(L_frame, 1); i > L_win; i -= 2) - { - *p-- = spectrum[i]; - move32(); - } - Copy32(xn_buf, spectrum + L_win, shr(L_win, 1)); - - test(); - test(); - IF ((tcx_cfg->fIsTNSAllowed != 0) && (bfi == 0) && (fUseTns != 0)) - { - /* rearrange LF sub-window lines prior to TNS synthesis filtering */ - IF (sub(L_spec, L_frame) < 0) + for (i = w; i < L_frame; i += 2) { - Copy32(spectrum+8, spectrum+16, sub(shr(L_spec,1),8)); - Copy32(spectrum+L_frame/2, spectrum+8, 8); - Copy32(spectrum+L_frame/2+8, spectrum+L_spec/2+8, sub(shr(L_spec,1),8)); + xn_buf[t_integer++] = spectrum[i]; } - ELSE + } + + mvr2r( xn_buf, spectrum, L_frame ); + + if( tcx_cfg->fIsTNSAllowed && !bfi && fUseTns ) + { + L_win = L_frame >> 1; + L_spec = tcx_cfg->tnsConfig[0][0].iFilterBorders[0]; + + /* rearrange LF sub-window lines prior to TNS synthesis filtering */ + if( L_spec < L_frame ) { - Copy32(spectrum+L_win, xn_buf, 8); - Copy32(spectrum+8, spectrum+16, sub(L_win, 8)); - Copy32(xn_buf, spectrum+8, 8); + mvr2r( spectrum+8, spectrum+16, L_spec/2-8 ); + mvr2r( spectrum+L_frame/2, spectrum+8, 8 ); + mvr2r( spectrum+L_frame/2+8, spectrum+L_spec/2+8, L_spec/2-8 ); + } + else + { + mvr2r( spectrum+8, xn_buf, L_win ); + mvr2r( xn_buf, spectrum+16, L_win-8 ); + mvr2r( xn_buf+L_win-8, spectrum+8, 8); } } } + return; } - - diff --git a/src/libs/libevs/lib_com/control.h b/src/libs/libevs/lib_com/control.h new file mode 100644 index 00000000..30baac63 --- /dev/null +++ b/src/libs/libevs/lib_com/control.h @@ -0,0 +1,42 @@ +/*==================================================================================== + EVS Codec 3GPP TS26.443 Nov 13, 2018. Version 12.11.0 / 13.7.0 / 14.3.0 / 15.1.0 + ====================================================================================*/ + +#ifndef _CONTROL_H +#define _CONTROL_H + +/* BASOP -> FLC brigde: flow control instructions */ + +#include "stl.h" + +#define FOR( a) if( incrFor(), 0); else for( a) +static __inline void incrFor( void) +{ +} + +#define WHILE( a) if (incrFlcWhile(), 0); else while(a) +static __inline void incrFlcWhile(void) +{ +} + +#define DO do + +#define IF( a) if( incrIf(), a) +static __inline void incrIf( void) +{ +} + +#define ELSE else + +#define SWITCH( a) switch( incrSwitch(), a) +static __inline void incrSwitch( void) +{ +} + +#define CONTINUE continue + +#define BREAK break + +#define GOTO goto + +#endif /* _CONTROL_H */ diff --git a/src/libs/libevs/lib_com/core_com_config.cpp b/src/libs/libevs/lib_com/core_com_config.cpp new file mode 100644 index 00000000..42f5adc8 --- /dev/null +++ b/src/libs/libevs/lib_com/core_com_config.cpp @@ -0,0 +1,419 @@ +/*==================================================================================== + EVS Codec 3GPP TS26.443 Nov 13, 2018. Version 12.11.0 / 13.7.0 / 14.3.0 / 15.1.0 + ====================================================================================*/ + +#include +#include +#include +#include + +#include "options.h" +#include "rom_com.h" +#include "prot.h" + +/*-------------------------------------------------------------------* + * getTcxonly() + * + * + *-------------------------------------------------------------------*/ + +short getTcxonly( + const int bitrate +) +{ + short tcxonly = 0; + + if( bitrate > ACELP_32k ) + { + tcxonly = 1; + } + + return tcxonly; +} + + +/*-------------------------------------------------------------------* + * getCtxHm() + * + * + *-------------------------------------------------------------------*/ + +short getCtxHm( + const int bitrate, + const short rf_flag +) +{ + short ctx_hm = 0; + if( (bitrate > LPC_SHAPED_ARI_MAX_RATE) && (bitrate <= 64000) && !rf_flag) + { + ctx_hm = 1; + } + + return ctx_hm; +} + +/*-------------------------------------------------------------------* + * getResq() + * + * + *-------------------------------------------------------------------*/ + +short getResq( + const int bitrate +) +{ + short resq = 0; + + if(bitrate <= HQ_64k) + { + resq = 1; + } + + return resq; +} + +/*-------------------------------------------------------------------* + * getTnsAllowed() + * + * + *-------------------------------------------------------------------*/ + +short getTnsAllowed( + const int bitrate, + const short igf +) +{ + short tnsAllowed = 0; + + if( igf ) + { + if( bitrate > HQ_16k40 ) + { + tnsAllowed = 1; + } + } + else if( bitrate > HQ_32k ) + { + tnsAllowed = 1; + } + + return tnsAllowed; +} + +/*-------------------------------------------------------------------* + * getRestrictedMode() + * + * + *-------------------------------------------------------------------*/ + +short getRestrictedMode( + const int bitrate, + const short Opt_AMR_WB +) +{ + short restrictedMode = 3; + + if ( !Opt_AMR_WB && (bitrate > HQ_32k) ) + { + restrictedMode = 6; + } + else if ( Opt_AMR_WB ) + { + restrictedMode = 1; + } + + return restrictedMode; +} + +/*-------------------------------------------------------------------* + * getMdctWindowLength() + * + * + *-------------------------------------------------------------------*/ + +short getMdctWindowLength( + const float fscale +) +{ + + short mdctWindowLength; + + mdctWindowLength = (L_LOOK_12k8 * fscale)/FSCALE_DENOM; + + return mdctWindowLength; +} + +/*-------------------------------------------------------------------* + * sr2fscale() + * + * + *-------------------------------------------------------------------*/ + +short sr2fscale( + const int sr +) +{ + + return (FSCALE_DENOM*sr)/12800; +} + +/*-------------------------------------------------------------------* + * getCoreSamplerateMode2() + * + * + *-------------------------------------------------------------------*/ + +int getCoreSamplerateMode2( + const int bitrate, + const int bandwidth, + const short rf_mode +) +{ + int sr_core = 0; + + if( bandwidth == NB ) + { + sr_core = 12800; + } + else if( (bandwidth == WB && bitrate < ACELP_13k20) || + (bandwidth == SWB && bitrate <= ACELP_13k20) || (rf_mode == 1) ) + { + sr_core = 12800; + } + else if( bandwidth == WB || (bandwidth == SWB && bitrate <= ACELP_32k) + || (bandwidth == FB && bitrate <= ACELP_32k) ) + { + sr_core = 16000; + } + else if( (bandwidth == SWB || bandwidth == FB) && bitrate <= HQ_64k) + { + sr_core = 25600; + } + else if( bandwidth == SWB || bandwidth == FB ) + { + sr_core = 32000; + } + + return sr_core; +} + +/*-------------------------------------------------------------------* + * getTcxBandwidth() + * + * + *-------------------------------------------------------------------*/ + +float getTcxBandwidth( + const int bandwidth +) +{ + float tcxBandwidth = 0.5f; + + if( bandwidth == NB ) + { + tcxBandwidth = 0.3125f; + } + + return tcxBandwidth; +} + +/*-------------------------------------------------------------------* + * getIgfPresent() + * + * + *-------------------------------------------------------------------*/ + +short getIgfPresent( + const int bitrate, + const int bandwidth, + const short rf_mode +) +{ + short igfPresent = 0; + + if( bandwidth == SWB && bitrate >= ACELP_9k60 && bitrate < HQ_96k ) + { + igfPresent = 1; + } + else if( bandwidth == FB && bitrate >= ACELP_16k40 ) + { + igfPresent = 1; + } + else if( bandwidth == WB && bitrate == ACELP_9k60 ) + { + igfPresent = 1; + } + if( ((bandwidth == WB) || (bandwidth == SWB)) && (rf_mode == 1) && (bitrate == ACELP_13k20) ) + { + igfPresent = 1; + } + + return igfPresent; +} + +/*-------------------------------------------------------------------* + * getCnaPresent() + * + * + *-------------------------------------------------------------------*/ + +short getCnaPresent( + const int bitrate, + const int bandwidth +) +{ + short flag_cna = 0; + + if( bandwidth == NB && bitrate <= ACELP_13k20 ) + { + flag_cna = 1; + } + + if( bandwidth == WB && bitrate <= ACELP_13k20 ) + { + flag_cna = 1; + } + + if( bandwidth == SWB && bitrate <= ACELP_13k20 ) + { + flag_cna = 1; + } + + return flag_cna; +} + +/*-------------------------------------------------------------------* + * getTcxLtp() + * + * + *-------------------------------------------------------------------*/ +short getTcxLtp( + const int sr_core +) +{ + short tcxltp = 0; + + if ( (sr_core <= 25600) ) + { + tcxltp = 1; + } + + return tcxltp; +} + +/*-------------------------------------------------------------------* + * initPitchLagParameters() + * + * + *-------------------------------------------------------------------*/ + +short initPitchLagParameters( + const int sr_core, + int *pit_min, + int *pit_fr1, + int *pit_fr1b, + int *pit_fr2, + int *pit_max +) +{ + + short pit_res_max; + + + if (sr_core==12800) + { + *pit_min = PIT_MIN_12k8; + *pit_max = PIT_MAX_12k8; + *pit_fr2 = PIT_FR2_12k8; + *pit_fr1 = PIT_FR1_12k8; + *pit_fr1b = PIT_FR1_8b_12k8; + pit_res_max = 4; + } + else if (sr_core==16000) + { + *pit_min = PIT_MIN_16k; + *pit_max = PIT16k_MAX; + *pit_fr2 = PIT_FR2_16k; + *pit_fr1 = PIT_FR1_16k; + *pit_fr1b = PIT_FR1_8b_16k; + pit_res_max = 6; + } + else if (sr_core==25600) + { + *pit_min = PIT_MIN_25k6; + *pit_max = PIT_MAX_25k6; + *pit_fr2 = PIT_FR2_25k6; + *pit_fr1 = PIT_FR1_25k6; + *pit_fr1b = PIT_FR1_8b_25k6; + pit_res_max = 4; + } + else /* sr_core==32000 */ + { + *pit_min = PIT_MIN_32k; + *pit_max = PIT_MAX_32k; + *pit_fr2 = PIT_FR2_32k; + *pit_fr1 = PIT_FR1_32k; + *pit_fr1b = PIT_FR1_8b_32k; + pit_res_max = 6; + } + + return pit_res_max; +} + +/*-------------------------------------------------------------------* + * getNumTcxCodedLines() + * + * + *-------------------------------------------------------------------*/ + +short getNumTcxCodedLines( + const short bwidth +) +{ + short tcx_coded_lines; + + switch (bwidth) + { + case NB: + tcx_coded_lines = 160; + break; + case WB: + tcx_coded_lines = 320; + break; + case SWB: + tcx_coded_lines = 640; + break; + case FB: + tcx_coded_lines = 960; + break; + default: + tcx_coded_lines = 0; + break; + } + + return tcx_coded_lines; +} + +/*-------------------------------------------------------------------* + * getTcxLpcShapedAri() + * + * + *-------------------------------------------------------------------*/ + +short getTcxLpcShapedAri( + const int total_brate, + const short bwidth, + const short rf_mode +) +{ + short tcx_lpc_shaped_ari = 0; + + (void) bwidth; + + if( total_brate <= LPC_SHAPED_ARI_MAX_RATE || rf_mode ) + { + tcx_lpc_shaped_ari = 1; + } + + return tcx_lpc_shaped_ari; +} diff --git a/src/libs/libevs/lib_com/core_com_config_fx.cpp b/src/libs/libevs/lib_com/core_com_config_fx.cpp deleted file mode 100755 index 039432be..00000000 --- a/src/libs/libevs/lib_com/core_com_config_fx.cpp +++ /dev/null @@ -1,471 +0,0 @@ -/*==================================================================================== - EVS Codec 3GPP TS26.442 Apr 03, 2018. Version 12.11.0 / 13.6.0 / 14.2.0 - ====================================================================================*/ - -#include -#include -#include -#include - -#include "options.h" -#include "stl.h" -#include "basop_util.h" -#include "prot_fx.h" -#include "rom_com_fx.h" - - -Word8 getTcxonly(const Word32 bitrate) -{ - - Word8 tcxonly; - - tcxonly = 0; - move16(); - if( L_sub(bitrate,32000) > 0 ) - { - tcxonly = 1; - move16(); - } - - return tcxonly; -} - -Word8 getCtxHm(const Word32 bitrate, const Word16 rf_flag) -{ - - Word8 ctx_hm; - - ctx_hm = 0; - move16(); - test(); - if( (bitrate > LPC_SHAPED_ARI_MAX_RATE) && (bitrate <= 64000) && !rf_flag) - { - - ctx_hm = 1; - move16(); - } - - - return ctx_hm; -} - - -Word8 getResq(const Word32 bitrate) -{ - - Word8 resq; - - resq = 0; - move16(); - if (L_sub(bitrate,64000) <= 0) - { - resq = 1; - move16(); - } - - return resq; -} - - -Word8 getTnsAllowed(const Word32 bitrate - ,const Word16 igf - ) -{ - Word8 tnsAllowed; - - tnsAllowed = 0; - move16(); - IF ( igf != 0 ) - { - if( L_sub(bitrate, HQ_16k40) > 0 ) - { - tnsAllowed = 1; - move16(); - } - } - ELSE - { - if( L_sub(bitrate, HQ_32k) > 0) - { - tnsAllowed = 1; - move16(); - } - } - - return tnsAllowed; -} - - -Word8 getRestrictedMode(const Word32 bitrate, const Word16 Opt_AMR_WB) -{ - - Word8 restrictedMode; - - restrictedMode = 3; - move16(); - - test(); - IF ( (Opt_AMR_WB == 0) && (L_sub(bitrate,32000) > 0 ) ) - { - restrictedMode = 6; - move16(); - } - ELSE IF( Opt_AMR_WB ) - { - restrictedMode = 1; - move16(); - } - - return restrictedMode; -} - - -Word16 sr2fscale(const Word32 sr) -{ - Word16 fscale; - - SWITCH(sr) - { - case 8000: - fscale = (FSCALE_DENOM*8000)/12800; - move16(); - BREAK; - - case 12800: - fscale = FSCALE_DENOM; - move16(); - BREAK; - - case 16000: - fscale = (FSCALE_DENOM*16000)/12800; - move16(); - BREAK; - - case 25600: - fscale = (FSCALE_DENOM*25600)/12800; - move16(); - BREAK; - - case 32000: - fscale = (FSCALE_DENOM*32000)/12800; - move16(); - BREAK; - - case 48000: - fscale = (FSCALE_DENOM*48000)/12800; - move16(); - BREAK; - - default: - assert(0); - fscale = 0; /* just to avoid compiler warning */ - BREAK; - } - return fscale; -} - -Word32 getCoreSamplerateMode2(const Word32 bitrate, const Word16 bandwidth, const Word16 rf_mode) -{ - - Word32 sr_core; - sr_core = -1; /* to suppress MSVC warning */ move32(); - - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - - IF( L_sub( bandwidth,NB) == 0 ) - { - sr_core = 12800; - move32(); - } - - ELSE IF ( L_and(L_sub(bandwidth,WB)==0, L_sub(bitrate,13200)<0) || - L_and(L_sub(bandwidth,SWB)==0, L_sub(bitrate,13200)<=0) || sub(rf_mode,1) == 0 ) - - { - sr_core = 12800; - move32(); - } - ELSE IF (L_sub(bandwidth,WB)==0 || ( (L_sub(bitrate,32000)<=0) && ((L_sub(bandwidth,SWB)==0) || (L_sub(bandwidth,FB)==0)) ) ) - { - sr_core = 16000; - move32(); - } - ELSE IF ( ((L_sub(bandwidth,SWB)==0) || (L_sub(bandwidth,FB)==0)) && (L_sub(bitrate,64000)<=0) ) - { - sr_core = 25600; - move32(); - } - ELSE IF (L_sub(bandwidth,SWB)==0 || L_sub(bandwidth,FB)==0) - { - sr_core = 32000; - move32(); - } - ELSE - { - assert(0); - } - - return sr_core; -} - -Word16 getTcxBandwidth(const Word16 bandwidth) -{ - - Word16 tcxBandwidth; - - tcxBandwidth = 16384/*0.5f Q15*/; - move16(); - if(sub(bandwidth, NB) == 0) - { - tcxBandwidth = 10240/*0.3125f Q15*/; - move16(); - - } - - return tcxBandwidth; -} - - -Word8 getIgfPresent( - const Word32 bitrate, - const Word16 bandwidth - ,const Word16 rf_mode -) -{ - Word8 igfPresent; - - igfPresent = 0; - move16(); - - test(); - test(); - if( (sub(bandwidth, SWB) == 0) && (L_sub(bitrate, ACELP_9k60) >= 0) && (L_sub(bitrate, HQ_96k) < 0) ) - { - igfPresent = 1; - move16(); - } - - test(); - if( sub(bandwidth, FB) == 0 && (L_sub(bitrate, ACELP_16k40) >= 0)) - { - igfPresent = 1; - move16(); - } - - test(); - if( (sub(bandwidth, WB) == 0) && (L_sub(bitrate, ACELP_9k60) == 0) ) - { - igfPresent = 1; - move16(); - } - - test(); - test(); - test(); - if( ((sub(bandwidth, WB) == 0) || (sub(bandwidth, SWB) == 0)) && (sub(rf_mode, 1) == 0) && (L_sub(bitrate, ACELP_13k20) == 0) ) - { - igfPresent = 1; - move16(); - } - - return igfPresent; -} - - -Word8 getCnaPresent( - const Word32 bitrate, - const Word16 bandwidth -) -{ - Word8 flag_cna = 0; - - flag_cna = 0; - move16(); - test(); - if( sub(bandwidth, NB) == 0 && (L_sub(bitrate, ACELP_13k20) <= 0) ) - { - flag_cna = 1; - move16(); - } - - test(); - if( (sub(bandwidth, WB) == 0) && (L_sub(bitrate, ACELP_13k20) <= 0) ) - { - flag_cna = 1; - move16(); - } - - test(); - if( (sub(bandwidth, SWB) == 0) && (L_sub(bitrate, ACELP_13k20) <= 0) ) - { - flag_cna = 1; - move16(); - } - - return flag_cna; -} - -Word8 getTcxLtp(const Word32 sr_core) -{ - - Word8 tcxltp = 0; - - tcxltp = 0; - move16(); - test(); - if ( (L_sub(sr_core, 25600) <= 0) ) - { - tcxltp = 1; - move16(); - } - - return tcxltp; -} - - -Word16 initPitchLagParameters( - const Word32 sr_core, - Word16 *pit_min, - Word16 *pit_fr1, - Word16 *pit_fr1b, - Word16 *pit_fr2, - Word16 *pit_max -) -{ - - Word16 pit_res_max; - - IF (L_sub(sr_core, 12800) == 0) - { - - *pit_min = PIT_MIN_12k8; - move16(); - *pit_max = PIT_MAX_12k8; - move16(); - *pit_fr2 = PIT_FR2_12k8; - move16(); - *pit_fr1 = PIT_FR1_12k8; - move16(); - *pit_fr1b = PIT_FR1_8b_12k8; - move16(); - pit_res_max = 4; - move16(); - - } - ELSE IF (L_sub(sr_core, 16000) == 0) - { - - *pit_min = PIT_MIN_16k; - move16(); - *pit_max = PIT_MAX_16k; - move16(); - *pit_fr2 = PIT_FR2_16k; - move16(); - *pit_fr1 = PIT_FR1_16k; - move16(); - *pit_fr1b = PIT_FR1_8b_16k; - move16(); - pit_res_max = 6; - move16(); - - } - ELSE IF (L_sub(sr_core, 25600) == 0) - { - - *pit_min = PIT_MIN_25k6; - move16(); - *pit_max = PIT_MAX_25k6; - move16(); - *pit_fr2 = PIT_FR2_25k6; - move16(); - *pit_fr1 = PIT_FR1_25k6; - move16(); - *pit_fr1b = PIT_FR1_8b_25k6; - move16(); - pit_res_max = 4; - move16(); - } - ELSE /* sr_core==32000 */ - { - - *pit_min = PIT_MIN_32k; - move16(); - *pit_max = PIT_MAX_32k; - move16(); - *pit_fr2 = PIT_FR2_32k; - move16(); - *pit_fr1 = PIT_FR1_32k; - move16(); - *pit_fr1b = PIT_FR1_8b_32k; - move16(); - pit_res_max = 6; - move16(); - - } - - return pit_res_max; -} - -Word16 getNumTcxCodedLines(const Word16 bwidth) -{ - - Word16 tcx_coded_lines; - - tcx_coded_lines = 0; - move16(); - - if(sub(bwidth, NB) == 0) - { - tcx_coded_lines = 160; - move16(); - } - - if(sub(bwidth, WB) == 0) - { - tcx_coded_lines = 320; - move16(); - } - - if(sub(bwidth, SWB) == 0) - { - tcx_coded_lines = 640; - move16(); - } - - if(sub(bwidth, FB) == 0) - { - tcx_coded_lines = 960; - move16(); - } - - return tcx_coded_lines; -} - -Word16 getTcxLpcShapedAri( - const Word32 total_brate, - const Word16 bwidth - ,const Word16 rf_mode -) -{ - Word16 tcx_lpc_shaped_ari = 0; - move16(); - - (void) bwidth; - - test(); - if( (L_sub(total_brate, LPC_SHAPED_ARI_MAX_RATE) <= 0) || rf_mode ) - { - tcx_lpc_shaped_ari = 1; - move16(); - } - - - return tcx_lpc_shaped_ari; -} diff --git a/src/libs/libevs/lib_com/deemph.cpp b/src/libs/libevs/lib_com/deemph.cpp new file mode 100644 index 00000000..cdf6f290 --- /dev/null +++ b/src/libs/libevs/lib_com/deemph.cpp @@ -0,0 +1,37 @@ +/*==================================================================================== + EVS Codec 3GPP TS26.443 Nov 13, 2018. Version 12.11.0 / 13.7.0 / 14.3.0 / 15.1.0 + ====================================================================================*/ + +#include "options.h" +#include "prot.h" + +/*-------------------------------------------------------------------* + * deemph() + * + * Deemphasis: filtering through 1/(1-mu z^-1) + *-------------------------------------------------------------------*/ + +void deemph( + float *signal, /* i/o: signal */ + const float mu, /* i : deemphasis factor */ + const short L, /* i : vector size */ + float *mem /* i/o: memory (y[-1]) */ +) +{ + short i; + + signal[0] = signal[0] + mu * (*mem); + for (i=1; i -1e-10) ) + { + *mem = 0; + } + + return; +} diff --git a/src/libs/libevs/lib_com/deemph_fx.cpp b/src/libs/libevs/lib_com/deemph_fx.cpp deleted file mode 100755 index efd0e73f..00000000 --- a/src/libs/libevs/lib_com/deemph_fx.cpp +++ /dev/null @@ -1,136 +0,0 @@ -/*==================================================================================== - EVS Codec 3GPP TS26.442 Apr 03, 2018. Version 12.11.0 / 13.6.0 / 14.2.0 - ====================================================================================*/ - -#include "options.h" /* Compilation switches */ -#include "prot_fx.h" /* Function prototypes */ -#include "stl.h" -#include "basop_util.h" - -/*========================================================================*/ -/* FUNCTION : deemph_fx() */ -/*------------------------------------------------------------------------*/ -/* PURPOSE : Deemphasis: filtering through 1/(1-mu z^-1) */ -/*------------------------------------------------------------------------*/ -/* INPUT ARGUMENTS : */ -/* _ (Word16) mu : deemphasis factor Q15 */ -/* _ (Word16) L : vector size */ -/*------------------------------------------------------------------------*/ -/* INPUT/OUTPUT ARGUMENTS : */ -/* _ (Word16*) signal : signal Q_syn2-1 */ -/* _ (Word16*) mem : memory (y[-1]) Q_syn2-1 */ -/*------------------------------------------------------------------------*/ -/* OUTPUT ARGUMENTS : */ -/*------------------------------------------------------------------------*/ - -/*------------------------------------------------------------------------*/ -/* RETURN ARGUMENTS : */ -/* _ None */ -/*========================================================================*/ -void deemph_fx( - Word16 *signal, /* i/o: signal Qx */ - const Word16 mu, /* i : deemphasis factor Q15 */ - const Word16 L, /* i : vector size Q0 */ - Word16 *mem /* i/o: memory (y[-1]) Qx */ -) -{ - Word16 i; - Word32 L_tmp; - - L_tmp = L_deposit_h(signal[0]); - L_tmp = L_mac(L_tmp, *mem, mu); - signal[0] = round_fx(L_tmp); - - FOR (i = 1; i < L; i++) - { - L_tmp = L_deposit_h(signal[i]); - L_tmp = L_mac(L_tmp, signal[i - 1], mu); - signal[i] = round_fx(L_tmp); - } - - *mem = signal[L - 1]; - move16(); -} - -/*-------------------------------------------------------------------* - * Deeemph2 : - * - * Deemphasis: filtering through 1/(1-mu z^-1) - * Output divided by 2 - *-------------------------------------------------------------------*/ -void Deemph2( - Word16 x[], /* i/o: input signal overwritten by the output Qx/Qx-1 */ - const Word16 mu, /* i : deemphasis factor Q15 */ - const Word16 L, /* i : vector size Q0 */ - Word16 *mem /* i/o: memory (y[-1]) Qx-1 */ -) -{ - Word16 i; - Word32 L_tmp; - - /* saturation can occur in L_mac() */ - - L_tmp = L_mult(x[0], 16384); - x[0] = mac_r(L_tmp, *mem, mu); - move16(); - - FOR (i = 1; i < L; i++) - { - L_tmp = L_mult(x[i], 16384); - x[i] = mac_r(L_tmp, x[i - 1], mu); - move16(); - } - - *mem = x[L - 1]; - move16(); -} - - -/* - * E_UTIL_deemph2 - * - * Parameters: - * shift I: scale output - * x I/O: signal Qx/Qx-shift - * mu I: deemphasis factor Qx - * L I: vector size - * mem I/O: memory (signal[-1]) Qx - * - * Function: - * Filtering through 1/(1-mu z^-1) - * Signal is divided by 2. - * - * Returns: - * void - */ -void E_UTIL_deemph2(Word16 shift, Word16 *x, const Word16 mu, const Word16 L, Word16 *mem) -{ - Word16 i; - Word32 L_tmp; - - /* signal[0] = signal[0] + mu * (*mem); */ - L_tmp = L_deposit_h(*mem); - IF(shift >= 0) - { - shift = shr(-32768, shift); - FOR (i = 0; i < L; i++) - { - L_tmp = L_msu(Mpy_32_16_1(L_tmp, mu), x[i],shift); - x[i] = round_fx(L_tmp); - } - - } - ELSE - { - FOR (i = 0; i < L; i++) - { - L_tmp = L_msu(Mpy_32_16_1(L_tmp, mu), shr(x[i],shift),-32768); - x[i] = round_fx(L_tmp); - } - } - - *mem = x[L - 1]; - move16(); - - return; -} diff --git a/src/libs/libevs/lib_com/delay_comp.cpp b/src/libs/libevs/lib_com/delay_comp.cpp old mode 100755 new mode 100644 index fd3a8cf8..3ad7cba5 --- a/src/libs/libevs/lib_com/delay_comp.cpp +++ b/src/libs/libevs/lib_com/delay_comp.cpp @@ -1,41 +1,37 @@ /*==================================================================================== - EVS Codec 3GPP TS26.442 Apr 03, 2018. Version 12.11.0 / 13.6.0 / 14.2.0 + EVS Codec 3GPP TS26.443 Nov 13, 2018. Version 12.11.0 / 13.7.0 / 14.3.0 / 15.1.0 ====================================================================================*/ -#include "options.h" /* Compilation switches */ -#include "stl.h" -#include "prot_fx.h" +#include "options.h" +#include "prot.h" /*-------------------------------------------------------------------------- -* get_delay_fx() -* -* Function returns various types of delays in the codec in ms. -*--------------------------------------------------------------------------*/ + * get_delay() + * + * Function returns various types of delays in the codec in ms. + *--------------------------------------------------------------------------*/ -Word32 get_delay_fx( /* o : delay value in ms */ - const Word16 what_delay, /* i : what delay? (ENC or DEC) */ - const Word32 io_fs /* i : input/output sampling frequency */ +float get_delay( /* o : delay value in ms */ + const short what_delay, /* i : what delay? (ENC or DEC) */ + const int io_fs /* i : input/output sampling frequency */ ) { - Word32 delay = 0; + float delay = 0; - IF( sub(what_delay,ENC) == 0 ) + if( what_delay == ENC ) { delay = (DELAY_FIR_RESAMPL_NS + ACELP_LOOK_NS); - move32(); } - ELSE + else { - IF( L_sub(io_fs,8000) == 0 ) + if( io_fs == 8000 ) { delay = DELAY_CLDFB_NS; - move32(); } - ELSE + else { delay = DELAY_BWE_TOTAL_NS; - move32(); } } diff --git a/src/libs/libevs/lib_com/disclaimer.cpp b/src/libs/libevs/lib_com/disclaimer.cpp old mode 100755 new mode 100644 index 0e3fdf43..fd2892d0 --- a/src/libs/libevs/lib_com/disclaimer.cpp +++ b/src/libs/libevs/lib_com/disclaimer.cpp @@ -1,18 +1,17 @@ /*==================================================================================== - EVS Codec 3GPP TS26.442 Apr 03, 2018. Version 12.11.0 / 13.6.0 / 14.2.0 + EVS Codec 3GPP TS26.443 Nov 13, 2018. Version 12.11.0 / 13.7.0 / 14.3.0 / 15.1.0 ====================================================================================*/ -#include "disclaimer.h" -#include "options.h" -#include "stl.h" -/* WMC_TOOL_SKIP_FILE */ +#include "options.h" +#include "prot.h" int print_disclaimer(FILE *fPtr) { - fprintf(fPtr, "\n==============================================================================\n"); - fprintf(fPtr, " EVS Codec 3GPP TS26.442 Apr 03, 2018. Version 12.11.0 / 13.6.0 / 14.2.0\n"); - fprintf(fPtr, "==============================================================================\n\n\n"); + fprintf(fPtr, "\n===================================================================================================\n"); + fprintf(fPtr, " EVS Codec (Floating Point) 3GPP TS26.443 Nov 13, 2018. Version 12.11.0 / 13.7.0 / 14.3.0 / 15.1.0\n"); + fprintf(fPtr, "===================================================================================================\n\n\n"); + return 0; } diff --git a/src/libs/libevs/lib_com/disclaimer.h b/src/libs/libevs/lib_com/disclaimer.h deleted file mode 100755 index b8ab5e92..00000000 --- a/src/libs/libevs/lib_com/disclaimer.h +++ /dev/null @@ -1,15 +0,0 @@ -/*==================================================================================== - EVS Codec 3GPP TS26.442 Apr 03, 2018. Version 12.11.0 / 13.6.0 / 14.2.0 - ====================================================================================*/ - -#ifndef __INCLUDED_DISCLAIMER_H -#define __INCLUDED_DISCLAIMER_H - -#include - -int print_disclaimer(FILE *fPtr); - - - - -#endif /* __INCLUDED_DISCLAIMER_H */ diff --git a/src/libs/libevs/lib_com/dlpc_bfi.cpp b/src/libs/libevs/lib_com/dlpc_bfi.cpp old mode 100755 new mode 100644 index 7114df30..17868618 --- a/src/libs/libevs/lib_com/dlpc_bfi.cpp +++ b/src/libs/libevs/lib_com/dlpc_bfi.cpp @@ -1,55 +1,48 @@ /*==================================================================================== - EVS Codec 3GPP TS26.442 Apr 03, 2018. Version 12.11.0 / 13.6.0 / 14.2.0 + EVS Codec 3GPP TS26.443 Nov 13, 2018. Version 12.11.0 / 13.7.0 / 14.3.0 / 15.1.0 ====================================================================================*/ - -/* Header files */ #include #include #include -#include "prot_fx.h" -#include "stl.h" -#include "prot_fx.h" +#include "options.h" +#include "prot.h" +#include "rom_com.h" + + +/*---------------------------------------------------------------------* +* routine: dlpc_bfi() +* +* +*---------------------------------------------------------------------*/ void dlpc_bfi( - const Word16 L_frame, - Word16 *lsf_q, /* o : quantized LSFs */ - const Word16 *lsfold, /* i : past quantized LSF */ - const Word16 last_good, /* i : last good received frame */ - const Word16 nbLostCmpt, /* i : counter of consecutive bad frames */ - Word16 mem_MA[], /* i/o: quantizer memory for MA model */ - Word16 mem_AR[], /* i/o: quantizer memory for AR model */ - Word16 *stab_fac, /* i : LSF stability factor */ - Word16 *lsf_adaptive_mean,/* i : LSF adaptive mean, updated when BFI==0 */ - Word16 numlpc, /* i : Number of division per superframe */ - Word16 lsf_cng[], - Word8 plcBackgroundNoiseUpdated, - Word16 *lsf_q_cng, /* o : quantized LSFs */ - Word16 *old_lsf_q_cng, /* o : old quantized LSFs for background noise */ - const Word16* lsfBase, /* i : base for differential LSF coding */ - Word8 tcxonly + int L_frame, + float *lsf_q, /* o : quantized lsfs */ + const float *lsfold, /* i : past quantized lsf */ + const short last_good, /* i : last good received frame */ + const short nbLostCmpt, /* i : counter of consecutive bad frames */ + float mem_MA[], /* i/o: quantizer memory for MA model */ + float *mem_AR, /* i/o: quantizer memory for AR model */ + float *stab_fac, /* i : lsf stability factor */ + float *lsf_adaptive_mean,/* i : lsf adaptive mean, updated when BFI==0 */ + int numlpc, /* i : Number of division per superframe */ + float lsf_cng[], + int plcBackgroundNoiseUpdated, + float *lsf_q_cng, /* o : quantized lsfs of background noise */ + float *old_lsf_q_cng, /* o : old quantized lsfs for background noise */ + const float lsfBase[] /* i : base for differential lsf coding */ ) { + lsf_dec_bfi( MODE2, &lsf_q[0], lsfold, lsf_adaptive_mean, lsfBase, mem_MA, mem_AR, *stab_fac, 0, L_frame, last_good, + nbLostCmpt, plcBackgroundNoiseUpdated, lsf_q_cng, lsf_cng, old_lsf_q_cng, 0, 0, 0 ); - lsf_dec_bfi( - MODE2, - &lsf_q[0], lsfold, lsf_adaptive_mean, lsfBase, mem_MA, mem_AR, *stab_fac, - 0, L_frame, last_good, nbLostCmpt, - plcBackgroundNoiseUpdated, lsf_q_cng, lsf_cng, old_lsf_q_cng, 0, 0, tcxonly - ,0 - - ); - IF ( sub(numlpc,2)==0 ) + if( numlpc == 2 ) { /* Decode the second LPC */ - lsf_dec_bfi( - MODE2, - &lsf_q[M], &lsf_q[0], lsf_adaptive_mean, lsfBase, mem_MA, mem_AR, *stab_fac, - 0, L_frame, last_good, nbLostCmpt+1, - plcBackgroundNoiseUpdated, lsf_q_cng, lsf_cng, old_lsf_q_cng, 0, 0, tcxonly - ,0 - ); + lsf_dec_bfi( MODE2, &lsf_q[M], &lsf_q[0], lsf_adaptive_mean, lsfBase, mem_MA, mem_AR, *stab_fac, 0, L_frame, last_good, + nbLostCmpt+1, plcBackgroundNoiseUpdated, lsf_q_cng, lsf_cng, old_lsf_q_cng, 0, 0, 0 ); } - /**/ /*No local variabvles defined*/ -} + return; +} diff --git a/src/libs/libevs/lib_com/edct.cpp b/src/libs/libevs/lib_com/edct.cpp new file mode 100644 index 00000000..d159398c --- /dev/null +++ b/src/libs/libevs/lib_com/edct.cpp @@ -0,0 +1,193 @@ +/*==================================================================================== + EVS Codec 3GPP TS26.443 Nov 13, 2018. Version 12.11.0 / 13.7.0 / 14.3.0 / 15.1.0 + ====================================================================================*/ + +#include +#include +#include "options.h" +#include "cnst.h" +#include "rom_com.h" +#include "prot.h" + +static float const * get_edct_table(short length) +{ + float const * edct_table = NULL; + switch (length) + { + case 1200: + edct_table = edct_table_600; + break; + case 960: + edct_table = edct_table_480; + break; + case 640: + edct_table = edct_table_320; + break; + case 320: + edct_table = edct_table_160; + break; + case 256: + edct_table = edct_table_128; + break; + case 240: + edct_table = edct_table_120; + break; + case 200: + edct_table = edct_table_100; + break; + case 160: + edct_table = edct_table_80; + break; + case 40: + edct_table = edct_table_20; + break; + case 800: + edct_table = edct_table_400; + break; + case 512: + edct_table = edct_table_256; + break; + case 480: + edct_table = edct_table_240; + break; + case 400: + edct_table = edct_table_200; + break; + case 128: + edct_table = edct_table_64; + break; + case 80: + edct_table = edct_table_40; + break; + default: + fprintf(stderr, "edct/edst(): length is not in table!"); + exit(-1); + break; + } + return edct_table; +} + +/*-----------------------------------------------------------------* + * edct() + * + * DCT transform + *-----------------------------------------------------------------*/ + +void edct( + const float *x, /* i : input signal */ + float *y, /* o : output transform */ + short length /* i : length */ +) +{ + short i; + float re[L_FRAME_PLUS/2]; + float im[L_FRAME_PLUS/2]; + const float *edct_table = 0; + float local; + + edct_table = get_edct_table(length); + + /* Twiddling and Pre-rotate */ + for (i = 0; i < length/2; i++) + { + re[i] = x[2*i] * edct_table[i] + x[length-1-2*i] * edct_table[length/2-1-i]; + im[i] = x[length-1-2*i] * edct_table[i] - x[2*i] * edct_table[length/2-1-i]; + } + + DoFFT(re, im, length/2); + + local = (0.75f * EVS_PI)/ length; + + for (i = 0; i < length/2; i++) + { + float tmp; + tmp = re[i] - im[i] * local; /* 3*pi/(4*length) is a constant */ + im[i] = im[i] + re[i] * local; + re[i] = tmp; + } + + /* Post-rotate and obtain the output data */ + for (i = 0; i < length/2; i++) + { + y[2*i] = re[i] * edct_table[i] + im[i] * edct_table[length/2-1-i]; + y[length-1-2*i] = re[i] * edct_table[length/2-1-i] - im[i] * edct_table[i]; + } + + return; +} + +/*-------------------------------------------------------------------------* + * FUNCTION : edst() + * + * PURPOSE : DST_IV transform + *-------------------------------------------------------------------------*/ +void edst( + const float *x, /* i : input signal */ + float *y, /* o : output transform */ + short length /* i : length */ +) +{ + short i; + float re[L_FRAME_PLUS/2]; + float im[L_FRAME_PLUS/2]; + const float *edct_table = 0; + float local; + + edct_table = get_edct_table(length); + + /* Twiddling and Pre-rotate */ + for (i = 0; i < length/2; i++) + { + re[i] = x[length-1-2*i] * edct_table[i] + x[2*i] *edct_table[length/2-1-i]; + im[i] = x[2*i] * edct_table[i] - x[length-1-2*i] * edct_table[length/2-1-i]; + } + + DoFFT(re, im, length/2); + + local = (0.75f * EVS_PI)/ length; + + for (i = 0; i < length/2; i++) + { + float tmp; + tmp = re[i] - im[i] * local; /* 3*pi/(4*length) is a constant */ + im[i] = im[i] + re[i] * local; + re[i] = tmp; + } + + /* Post-rotate and obtain the output data */ + for (i = 0; i < length/2; i++) + { + y[2*i] = re[i] * edct_table[i] + im[i] * edct_table[length/2-1-i]; + y[length-1-2*i] = im[i] * edct_table[i] - re[i] * edct_table[length/2-1-i]; + } + + return; +} + +/*-----------------------------------------------------------------* + * iedct_short() + * + * Inverse EDCT for short frames + *-----------------------------------------------------------------*/ + +void iedct_short( + const float *in, /* i : input vector */ + float *out, /* o : output vector */ + const short segment_length /* i : length */ +) +{ + float alias[MAX_SEGMENT_LENGTH]; + short i; + + edct(in, alias, segment_length/2); + + for (i = 0; i < segment_length/4; i++) + { + out[i] = alias[segment_length/4 + i]; + out[segment_length/4 + i] = -alias[segment_length/2 - 1 - i]; + out[segment_length/2 + i] = -alias[segment_length/4 - 1 - i]; + out[3*segment_length/4 + i] = -alias[i]; + } + + return; +} diff --git a/src/libs/libevs/lib_com/edct_fx.cpp b/src/libs/libevs/lib_com/edct_fx.cpp deleted file mode 100755 index fb6dc3be..00000000 --- a/src/libs/libevs/lib_com/edct_fx.cpp +++ /dev/null @@ -1,426 +0,0 @@ -/*==================================================================================== - EVS Codec 3GPP TS26.442 Apr 03, 2018. Version 12.11.0 / 13.6.0 / 14.2.0 - ====================================================================================*/ - -#include -#include -#include "options.h" /* Compilation switches */ -#include "cnst_fx.h" /* Common constants */ -#include "rom_com_fx.h" /* Static table prototypes */ -#include "prot_fx.h" /* Function prototypes */ -#include "stl.h" - - -#include "math_32.h" - -static Word16 const * get_edct_table(Word16 length, Word16 *q) -{ - Word16 const * edct_table = NULL; - SWITCH (length) - { - case 1200: - edct_table = edct_table_600_fx; - move16(); - *q = add(*q, 2); - BREAK; - case 960 : - edct_table = edct_table_480_fx; - move16(); - BREAK; - case 640 : - edct_table = edct_table_320_fx; - move16(); - BREAK; - case 320 : - edct_table = edct_table_160_fx; - move16(); - BREAK; - case 256 : - edct_table = edct_table_128_fx; - move16(); - BREAK; - case 240 : - edct_table = edct_table_120_fx; - move16(); - BREAK; - case 200 : - edct_table = edct_table_100_fx; - move16(); - BREAK; - case 160 : - edct_table = edct_table_80_fx ; - move16(); - BREAK; - case 40 : - edct_table = edct_table_20_fx ; - move16(); - BREAK; - case 800 : - edct_table = edct_table_400_fx; - move16(); - *q = add(*q, 2); - BREAK; - case 512 : - edct_table = edct_table_256_fx; - move16(); - BREAK; - case 480 : - edct_table = edct_table_240_fx; - move16(); - BREAK; - case 400 : - edct_table = edct_table_200_fx; - move16(); - BREAK; - case 128 : - edct_table = edct_table_64_fx ; - move16(); - BREAK; - case 80 : - edct_table = edct_table_40_fx ; - move16(); - BREAK; - default: - BREAK; - } - return edct_table; -} - -/*-------------------------------------------------------------------------* - * FUNCTION : edct_fx() - * - * PURPOSE : DCT transform - * - * INPUT ARGUMENTS : - * _ (Word16) length : length - * _ (Word16*) x : input signal Qx - * _ (Word16*) edct_table_128_fx : edct table Q16 - * - * OUTPUT ARGUMENTS : - * _ (Word16[]) y : output transform Qx - *-------------------------------------------------------------------------*/ -void edct_fx( - const Word32 *x, /* i : input signal Qq */ - Word32 *y, /* o : output transform Qq */ - Word16 length, /* i : length */ - Word16 *q /* i : Q value of input signal */ -) -{ - Word16 i; - Word32 re; - Word32 im; - const Word16 *edct_table = 0; /*Q16 */ - Word32 re2[L_FRAME48k/2+240]; - Word32 im2[L_FRAME48k/2+240]; - Word32 L_tmp; - Word16 tmp; - Word16 len1; - - edct_table = get_edct_table(length, q); - len1 = shr(length, 1); - /* Twiddling and Pre-rotate */ - FOR (i = 0; i < len1; i++) - { - L_tmp = Mult_32_16(x[2*i], edct_table[i]); /*Q(q+1) */ - re2[i] = Madd_32_16(L_tmp, x[length-1-2*i], edct_table[len1-1-i]); /*Q(q+1) */ move32(); - - L_tmp = Mult_32_16(x[length-1-2*i], edct_table[i]); /*Q(q+1) */ - - im2[i] = Msub_32_16(L_tmp, x[2*i], edct_table[len1-1-i]); /*Q(q+1) */ move32(); - } - - *q = sub(15, *q); - BASOP_cfft(re2, im2, len1, 1, q, y); - - tmp = div_s(1, length); /*Q15 */ - tmp = round_fx(L_shl(L_mult(tmp, 19302), 2)); /*Q15 */ - FOR (i = 0; i < len1; i++) - { - re = Msub_32_16(re2[i], im2[i], tmp); - im = Madd_32_16(im2[i], re2[i], tmp); - y[2 * i] = L_add(Mult_32_16(re, edct_table[i]), Mult_32_16(im, edct_table[len1 - 1 - i])); - move32(); - y[length - 1 - 2 * i] = L_sub(Mult_32_16(re, edct_table[len1 - 1 - i]), Mult_32_16(im, edct_table[i])); - move32(); - } /*Q(q-2) */ - - *q = sub(15+2, *q); - return; -} - -/*-------------------------------------------------------------------------* - * FUNCTION : edst_fx() - * - * PURPOSE : DST_IV transform - * - * INPUT ARGUMENTS : - * _ (Word16) length : length - * _ (Word16*) x : input signal Qx - * _ (Word16*) edct_table_128_fx : edct table Q16 - * - * OUTPUT ARGUMENTS : - * _ (Word16[]) y : output transform Qx - *-------------------------------------------------------------------------*/ -void edst_fx( - const Word32 *x, /* i : input signal Qq */ - Word32 *y, /* o : output transform Qq */ - Word16 length, /* i : length */ - Word16 *q /* i : Q value of input signal */ -) -{ - Word16 i; - Word32 re; - Word32 im; - const Word16 *edct_table = 0; /*Q16 */ - Word32 re2[L_FRAME48k/2+240]; - Word32 im2[L_FRAME48k/2+240]; - Word32 L_tmp; - Word16 tmp; - Word16 len1; - - edct_table = get_edct_table(length, q); - len1 = shr(length, 1); - /* Twiddling and Pre-rotate */ - FOR (i = 0; i < len1; i++) - { - L_tmp = Mult_32_16(x[length-1-2*i], edct_table[i]); - re2[i] = Madd_32_16(L_tmp, x[2*i], edct_table[len1-1-i]); - move32(); - - L_tmp = Mult_32_16(x[2*i], edct_table[i]); - im2[i] = Msub_32_16(L_tmp, x[length-1-2*i], edct_table[len1-1-i]); - move32(); - } - - *q = sub(15, *q); - BASOP_cfft(re2, im2, len1, 1, q, y); - - tmp = div_s(1, length); /*Q15 */ - tmp = round_fx(L_shl(L_mult(tmp, 19302), 2)); /*Q15 */ - FOR (i = 0; i < len1; i++) - { - re = Msub_32_16(re2[i], im2[i], tmp); - im = Madd_32_16(im2[i], re2[i], tmp); - y[2 * i] = L_add(Mult_32_16(re, edct_table[i]), Mult_32_16(im, edct_table[len1 - 1 - i])); - move32(); - y[length - 1 - 2 * i] = L_sub(Mult_32_16(im, edct_table[i]), Mult_32_16(re, edct_table[len1 - 1 - i])); - move32(); - } /*Q(q) */ - - *q = sub(15+2, *q); - - return; -} - -/*========================================================================*/ -/* FUNCTION : edct_fx() */ -/*------------------------------------------------------------------------*/ -/* PURPOSE : DCT transform */ -/*------------------------------------------------------------------------*/ -/* INPUT ARGUMENTS : */ -/* _ (Word16) length : length */ -/* _ (Word16*) x : input signal Qx */ -/* _ (Word16*) edct_table_128_fx : edct table Q15 */ -/*------------------------------------------------------------------------*/ -/* INPUT/OUTPUT ARGUMENTS : */ -/*------------------------------------------------------------------------*/ -/* OUTPUT ARGUMENTS : */ -/* _ (Word16[]) y : output transform Qx */ -/*------------------------------------------------------------------------*/ - -/*------------------------------------------------------------------------*/ -/* RETURN ARGUMENTS : */ -/* _ None */ -/*========================================================================*/ -void edct_16fx( - const Word16 *x, /* i : input signal Qx */ - Word16 *y, /* o : output transform Qx */ - Word16 length, /* i : length */ - Word16 bh /* bit-headroom */ -) -{ - Word16 i; - Word16 re[L_FRAME48k/2]; - Word16 im[L_FRAME48k/2]; - const Word16 *edct_table = 0; - Word16 re2[L_FRAME48k/2]; - Word16 im2[L_FRAME48k/2]; - - Word32 L_tmp, Lacc, Lmax; - Word16 tmp, fact; - Word16 Q_edct; - Word16 Len2, i2; - const Word16 *px, *pt; - Word16 *py; - - /*COMPLETE: some eDCT sub function are missing */ - - IF (sub(length,L_FRAME32k) == 0) - { - edct_table = &edct_table_320_16fx[0]; - move16(); - } - ELSE IF (sub(length,L_FRAME) == 0) - { - edct_table = &edct_table_128_16fx[0]; - move16(); - } - ELSE IF (sub(length,L_FRAME16k) == 0) - { - edct_table = &edct_table_160_16fx[0]; - move16(); - } - ELSE - { - } - - /* Twiddling and Pre-rotate */ - Lmax = L_deposit_l(0); - Len2 = shr(length,1); - px = x + length - 1; - pt = edct_table + Len2 - 1; - FOR (i = 0; i < Len2; i++) - { - i2 = shl(i,1); - L_tmp = L_mult(x[i2],edct_table[i]);/*Q(Qx+16) */ - - Lacc = L_mac(L_tmp,*px,*pt);/*Q(Qx+16) */ - - Lmax = L_max(Lmax, Lacc); - - L_tmp = L_mult(*px,edct_table[i]);/*Q(Qx+16) */ - Lacc = L_msu(L_tmp,x[i2],*pt);/*Q(Qx+16) */ - Lmax = L_max(Lmax, Lacc); - - px -= 2; - pt--; - } - - tmp = 31; - if( Lmax != 0 ) - { - tmp = norm_l(Lmax); - } - Q_edct = sub(tmp,bh); /*creating a bit-headroom */ - - px = x + length - 1; - pt = edct_table + Len2 - 1; - FOR (i = 0; i < Len2; i++) - { - i2 = shl(i,1); - - L_tmp = L_mult(x[i2],edct_table[i]);/*Q(Qx+16) */ - Lacc = L_mac(L_tmp,*px,*pt);/*Q(Qx+16) */ - re2[i] = round_fx(L_shl(Lacc, Q_edct)); /* Q(Qx+Q_edct) */ - - L_tmp = L_mult(*px,edct_table[i]);/*Q(Qx+16) */ - Lacc = L_msu(L_tmp,x[i2],*pt);/*Q(Qx+16) */ - im2[i] = round_fx(L_shl(Lacc, Q_edct)); /* Q(Qx+Q_edct) */ - - px -= 2; - pt--; - } - IF (sub(length,L_FRAME32k) == 0) - { - DoRTFT320_16fx(re2, im2); - } - ELSE IF (sub(length,L_FRAME )== 0) - { - DoRTFT128_16fx(re2, im2); - } - ELSE IF (sub(length,L_FRAME16k) == 0) - { - DoRTFT160_16fx(re2, im2); - } - ELSE - { - } - tmp = div_s(1,length); /*Q15 */ - L_tmp = L_mult(tmp,19302); /*Q29, (3*PI/4) in Q13 */ - fact = round_fx(L_shl(L_tmp,2)); /*Q15 */ - FOR (i = 0; i < length/2; i++) - { - tmp = mult_r(im2[i],fact); /*Q(Qx+Q_edct) */ - re[i] = sub(re2[i],tmp); /*Q(Qx+Q_edct) */ move16(); - - tmp = mult_r(re2[i],fact); /*Q(Qx+Q_edct) */ - im[i] = add(im2[i],tmp); /*Q(Qx+Q_edct) */ move16(); - } - - /* Post-rotate and obtain the output data */ - py = y + length - 1; - pt = edct_table + Len2 - 1; - FOR (i = 0; i < Len2; i++) - { - i2 = shl(i,1); - - L_tmp = L_mult(re[i],edct_table[i]);/*Q(Qx+Q_edct+16) */ - Lacc = L_mac(L_tmp,im[i],*pt);/*Q(Qx+Q_edct+16) */ - y[i2] = round_fx(L_shr(Lacc,Q_edct)); /* Q(Qx) */ - - L_tmp = L_mult(re[i],edct_table[length/2-1-i]);/*Q(Qx+Q_edct+16) */ - Lacc = L_msu(L_tmp,im[i],edct_table[i]);/*Q(Qx+Q_edct+16) */ - *py = round_fx(L_shr(Lacc,Q_edct)); /* Q(Qx) */ - - py -= 2; - pt--; - } - return; -} - - -/*-----------------------------------------------------------------* - * iedct_short_fx() - * - * Inverse EDCT for short frames - *-----------------------------------------------------------------*/ - -void iedct_short_fx( - const Word32 *in, /* i : input vector */ - Word16 *Q, /* i/o: Q value of input */ - Word32 *out, /* o : output vector */ - const Word16 segment_length /* i : length */ -) -{ - Word32 alias[MAX_SEGMENT_LENGTH]; - Word16 seg_len_div2, seg_len_div4, seg_len_3mul_div4; - Word16 i; - Word16 qtmp, tmp; - - qtmp = *Q; - move16(); - tmp = 0; - move16(); - seg_len_div2 = shr(segment_length, 1); - seg_len_div4 = shr(segment_length, 2); - seg_len_3mul_div4 = add(seg_len_div2, seg_len_div4); - - edct_fx(in, alias, seg_len_div2, Q); - FOR (i = 0; i < seg_len_div2; i++) - { - IF (alias[i] != 0) - { - tmp = 1; - move16(); - BREAK; - } - } - if (tmp == 0) - { - *Q = qtmp; - move16(); - } - FOR (i = 0; i < seg_len_div4; i++) - { - out[i] = alias[seg_len_div4 + i]; - move32(); - out[seg_len_div4 + i] = L_negate(alias[seg_len_div2 - 1 - i]); - move32(); - out[seg_len_div2 + i] = L_negate(alias[seg_len_div4 - 1 - i]); - move32(); - out[seg_len_3mul_div4 + i] = L_negate(alias[i]); - move32(); - } - - return; -} diff --git a/src/libs/libevs/basic_op/enh1632.cpp b/src/libs/libevs/lib_com/enh1632.cpp old mode 100755 new mode 100644 similarity index 64% rename from src/libs/libevs/basic_op/enh1632.cpp rename to src/libs/libevs/lib_com/enh1632.cpp index 083ddab2..d1a86253 --- a/src/libs/libevs/basic_op/enh1632.cpp +++ b/src/libs/libevs/lib_com/enh1632.cpp @@ -1,3 +1,4 @@ + /* =========================================================================== File: ENH1632.C v.2.3 - 30.Nov.2009 @@ -9,7 +10,7 @@ History: 07 Nov 04 v2.0 Incorporation of new 32-bit / 40-bit / control - operators for the ITU-T Standard Tool Library as + operators for the ITU-T Standard Tool Library as described in Geneva, 20-30 January 2004 WP 3/16 Q10/16 TD 11 document and subsequent discussions on the wp3audio@yahoogroups.com email reflector. @@ -18,33 +19,33 @@ */ - /***************************************************************************** - * - * Enhanced 16/32 bit operators : - * s_max() - * s_min() - * L_max() - * L_min() - * shl_r() - * L_shl_r() - * L_mac0() - * L_mult0() - * L_msu0() - * s_and() - * s_or() - * s_xor() - * L_and() - * L_or() - * lshl() - * lshr() - * L_lshl() - * L_lshr() - * rotr() - * rotl() - * L_rotr() - * L_rotl() - * - *****************************************************************************/ +/***************************************************************************** +* +* Enhanced 16/32 bit operators : +* s_max() +* s_min() +* L_max() +* L_min() +* shl_r() +* L_shl_r() +* L_mac0() +* L_mult0() +* L_msu0() +* s_and() +* s_or() +* s_xor() +* L_and() +* L_or() +* lshl() +* lshr() +* L_lshl() +* L_lshr() +* rotr() +* rotl() +* L_rotr() +* L_rotl() +* +*****************************************************************************/ /***************************************************************************** @@ -52,17 +53,11 @@ * Include-Files * *****************************************************************************/ + #include #include #include "stl.h" -#if (WMOPS) -extern BASIC_OP multiCounter[MAXCOUNTERS]; -extern int currCounter; -#endif /* if WMOPS */ - - - /***************************************************************************** * * Constants and Globals @@ -93,10 +88,10 @@ extern int currCounter; * * Inputs : * - * var1 16 bit short signed integer (Word16) whose value falls in + * var1 16 bit short signed integer (Word16) whose value falls in * the range 0xffff 8000 <= var1 <= 0x0000 7fff. * - * var2 16 bit short signed integer (Word16) whose value falls in + * var2 16 bit short signed integer (Word16) whose value falls in * the range 0xffff 8000 <= var2 <= 0x0000 7fff. * * Outputs : @@ -105,37 +100,39 @@ extern int currCounter; * * Return Value: * - * var_out 16 bit short signed integer (Word16) whose value falls in + * var_out 16 bit short signed integer (Word16) whose value falls in * the range 0xffff 8000 <= var_out <= 0x0000 7fff. * *****************************************************************************/ -Word16 lshl( Word16 var1, Word16 var2) { - Word16 var_out=0; +Word16 lshl( Word16 var1, Word16 var2) +{ + Word16 var_out=0; - if( var2 < 0) { - var2 = -var2; - var_out = lshr( var1, var2); + if( var2 < 0) + { + var2 = -var2; + var_out = lshr( var1, var2); + } + else + { + if( var2 == 0 || var1 == 0) + { + var_out = var1; + } + else if( var2 >= 16) + { + var_out = 0; + } + else + { + var_out = var1 << var2; + } + } - #if (WMOPS) - multiCounter[currCounter].lshr--; - #endif /* if WMOPS */ + BASOP_CHECK(); - } else { - if( var2 == 0 || var1 == 0) { - var_out = var1; - } else if( var2 >= 16) { - var_out = 0; - } else { - var_out = var1 << var2; - } - } - #if (WMOPS) - multiCounter[currCounter].lshl++; - #endif /* if WMOPS */ - BASOP_CHECK(); - - return( var_out); + return( var_out); } /***************************************************************************** @@ -154,10 +151,10 @@ Word16 lshl( Word16 var1, Word16 var2) { * * Inputs : * - * var1 16 bit short signed integer (Word16) whose value falls in + * var1 16 bit short signed integer (Word16) whose value falls in * the range 0xffff 8000 <= var1 <= 0x0000 7fff. * - * var2 16 bit short signed integer (Word16) whose value falls in + * var2 16 bit short signed integer (Word16) whose value falls in * the range 0xffff 8000 <= var2 <= 0x0000 7fff. * * Outputs : @@ -166,39 +163,41 @@ Word16 lshl( Word16 var1, Word16 var2) { * * Return Value: * - * var_out 16 bit short signed integer (Word16) whose value falls in + * var_out 16 bit short signed integer (Word16) whose value falls in * the range 0xffff 8000 <= var_out <= 0x0000 7fff. * *****************************************************************************/ -Word16 lshr( Word16 var1, Word16 var2) { - Word16 var_out; +Word16 lshr( Word16 var1, Word16 var2) +{ + Word16 var_out; - if( var2 < 0) { - var2 = -var2; - var_out = lshl( var1, var2); + if( var2 < 0) + { + var2 = -var2; + var_out = lshl( var1, var2); + } + else + { + if( var2 == 0 || var1 == 0) + { + var_out = var1; + } + else if( var2 >= 16) + { + var_out = 0; + } + else + { + var_out = var1 >> 1; + var_out = var_out & 0x7fff; + var_out = var_out >> ( var2-1); + } + } - #if (WMOPS) - multiCounter[currCounter].lshl--; - #endif /* if WMOPS */ + BASOP_CHECK(); - } else { - if( var2 == 0 || var1 == 0) { - var_out = var1; - } else if( var2 >= 16) { - var_out = 0; - } else { - var_out = var1 >> 1; - var_out = var_out & 0x7fff; - var_out = var_out >> ( var2-1); - } - } - #if (WMOPS) - multiCounter[currCounter].lshr++; - #endif /* if WMOPS */ - BASOP_CHECK(); - - return( var_out); + return( var_out); } @@ -218,10 +217,10 @@ Word16 lshr( Word16 var1, Word16 var2) { * * Inputs : * - * L_var1 32 bit long signed integer (Word32) whose value falls in + * L_var1 32 bit long signed integer (Word32) whose value falls in * the range 0x8000 0000 <= L_var1 <= 0x7fff ffff. * - * var2 16 bit short signed integer (Word16) whose value falls in + * var2 16 bit short signed integer (Word16) whose value falls in * the range 0xffff 8000 <= var2 <= 0x0000 7fff. * * Outputs : @@ -230,37 +229,39 @@ Word16 lshr( Word16 var1, Word16 var2) { * * Return Value: * - * L_var_out 32 bit long signed integer (Word32) whose value falls in + * L_var_out 32 bit long signed integer (Word32) whose value falls in * the range 0x8000 0000 <= L_var_out <= 0x7fff ffff. * *****************************************************************************/ -Word32 L_lshl( Word32 L_var1, Word16 var2) { - Word32 L_var_out=0; +Word32 L_lshl( Word32 L_var1, Word16 var2) +{ + Word32 L_var_out=0; - if( var2 < 0) { - var2 = -var2; - L_var_out = L_lshr( L_var1, var2); + if( var2 < 0) + { + var2 = -var2; + L_var_out = L_lshr( L_var1, var2); + } + else + { + if( var2 == 0 || L_var1 == 0) + { + L_var_out = L_var1; + } + else if( var2 >= 32) + { + L_var_out = 0; + } + else + { + L_var_out = L_var1 << var2; + } + } - #if (WMOPS) - multiCounter[currCounter].L_lshr--; - #endif /* if WMOPS */ + BASOP_CHECK(); - } else { - if( var2 == 0 || L_var1 == 0) { - L_var_out = L_var1; - } else if( var2 >= 32) { - L_var_out = 0; - } else { - L_var_out = L_var1 << var2; - } - } - #if (WMOPS) - multiCounter[currCounter].L_lshl++; - #endif /* if WMOPS */ - BASOP_CHECK(); - - return( L_var_out); + return( L_var_out); } @@ -280,10 +281,10 @@ Word32 L_lshl( Word32 L_var1, Word16 var2) { * * Inputs : * - * L_var1 32 bit long signed integer (Word32) whose value falls in + * L_var1 32 bit long signed integer (Word32) whose value falls in * the range 0x8000 0000 <= L_var1 <= 0x7fff ffff. * - * var2 16 bit short signed integer (Word16) whose value falls in + * var2 16 bit short signed integer (Word16) whose value falls in * the range 0xffff 8000 <= var2 <= 0x0000 7fff. * * Outputs : @@ -292,39 +293,41 @@ Word32 L_lshl( Word32 L_var1, Word16 var2) { * * Return Value: * - * L_var_out 32 bit long signed integer (Word32) whose value falls in + * L_var_out 32 bit long signed integer (Word32) whose value falls in * the range 0x8000 0000 <= L_var_out <= 0x7fff ffff. * *****************************************************************************/ -Word32 L_lshr( Word32 L_var1, Word16 var2) { - Word32 L_var_out; +Word32 L_lshr( Word32 L_var1, Word16 var2) +{ + Word32 L_var_out; - if( var2 < 0) { - var2 = -var2; - L_var_out = L_lshl( L_var1, var2); + if( var2 < 0) + { + var2 = -var2; + L_var_out = L_lshl( L_var1, var2); + } + else + { + if( var2 == 0 || L_var1 == 0) + { + L_var_out = L_var1; + } + else if( var2 >= 32) + { + L_var_out = 0; + } + else + { + L_var_out = L_var1 >> 1; + L_var_out = L_var_out & 0x7fffffff; + L_var_out = L_var_out >> (var2 - 1); + } + } - #if (WMOPS) - multiCounter[currCounter].L_lshl--; - #endif /* if WMOPS */ + BASOP_CHECK(); - } else { - if( var2 == 0 || L_var1 == 0) { - L_var_out = L_var1; - } else if( var2 >= 32) { - L_var_out = 0; - } else { - L_var_out = L_var1 >> 1; - L_var_out = L_var_out & 0x7fffffff; - L_var_out = L_var_out >> (var2 - 1); - } - } - #if (WMOPS) - multiCounter[currCounter].L_lshr++; - #endif /* if WMOPS */ - BASOP_CHECK(); - - return( L_var_out); + return( L_var_out); } @@ -341,10 +344,10 @@ Word32 L_lshr( Word32 L_var1, Word16 var2) { * * Inputs : * - * var1 16 bit short signed integer (Word16) whose value falls in + * var1 16 bit short signed integer (Word16) whose value falls in * the range : 0xffff 8000 <= var1 <= 0x0000 7fff. * - * var2 16 bit short signed integer (Word16) whose value falls in + * var2 16 bit short signed integer (Word16) whose value falls in * the range : 0xffff 8000 <= var2 <= 0x0000 7fff. * * Outputs : @@ -353,34 +356,26 @@ Word32 L_lshr( Word32 L_var1, Word16 var2) { * * Return Value : * - * var_out 16 bit short signed integer (Word16) whose value falls in + * var_out 16 bit short signed integer (Word16) whose value falls in * the range : 0xffff 8000 <= var_out <= 0x0000 7fff. * *****************************************************************************/ -Word16 shl_r( Word16 var1, Word16 var2){ - Word16 var_out; +Word16 shl_r( Word16 var1, Word16 var2) +{ + Word16 var_out; - if( var2 >= 0) { - var_out = shl( var1, var2); + if( var2 >= 0) + { + var_out = shl( var1, var2); + } + else + { + var2 = -var2; + var_out = shr_r( var1, var2); + } - #if (WMOPS) - multiCounter[currCounter].shl--; - #endif /* if WMOPS */ - } else { - var2 = -var2; - var_out = shr_r( var1, var2); - - #if (WMOPS) - multiCounter[currCounter].shr_r--; - #endif /* if WMOPS */ - } - - #if (WMOPS) - multiCounter[currCounter].shl_r++; - #endif /* if WMOPS */ - - return( var_out); + return( var_out); } @@ -397,10 +392,10 @@ Word16 shl_r( Word16 var1, Word16 var2){ * * Inputs : * - * L_var1 32 bit long signed integer (Word32) whose value falls in + * L_var1 32 bit long signed integer (Word32) whose value falls in * the range : 0x8000 0000 <= L_var1 <= 0x7fff ffff. * - * var2 16 bit short signed integer (Word16) whose value falls in + * var2 16 bit short signed integer (Word16) whose value falls in * the range : 0xffff 8000 <= var2 <= 0x0000 7fff. * * Outputs : @@ -409,34 +404,26 @@ Word16 shl_r( Word16 var1, Word16 var2){ * * Return Value : * - * L_var_out 32 bit long signed integer (Word32) whose value falls in + * L_var_out 32 bit long signed integer (Word32) whose value falls in * the range : 0x8000 0000 <= var_out <= 0x7fff ffff. * *****************************************************************************/ -Word32 L_shl_r( Word32 L_var1, Word16 var2) { - Word32 var_out; +Word32 L_shl_r( Word32 L_var1, Word16 var2) +{ + Word32 var_out; - if( var2 >= 0) { - var_out = L_shl( L_var1, var2); + if( var2 >= 0) + { + var_out = L_shl( L_var1, var2); + } + else + { + var2 = -var2; + var_out = L_shr_r( L_var1, var2); + } - #if (WMOPS) - multiCounter[currCounter].L_shl--; - #endif /* if WMOPS */ - } else { - var2 = -var2; - var_out = L_shr_r( L_var1, var2); - - #if (WMOPS) - multiCounter[currCounter].L_shr_r--; - #endif /* if WMOPS */ - } - - #if (WMOPS) - multiCounter[currCounter].L_shl_r++; - #endif /* if WMOPS */ - - return( var_out); + return( var_out); } @@ -461,7 +448,7 @@ Word32 L_shl_r( Word32 L_var1, Word16 var2) { * * Outputs : * - * *var3 Points on a 16 bit short signed integer (Word16) whose + * *var3 Points on a 16 bit short signed integer (Word16) whose * value will be 0 or 1. * * Return Value : @@ -470,22 +457,16 @@ Word32 L_shl_r( Word32 L_var1, Word16 var2) { * the range : 0xffff 8000 <= var_out <= 0x0000 7fff. * *****************************************************************************/ -Word16 rotr( Word16 var1, Word16 var2, Word16 *var3) { - Word16 var_out; +Word16 rotr( Word16 var1, Word16 var2, Word16 *var3) +{ + Word16 var_out; - *var3 = s_and( var1, 0x1); - var_out = s_or( lshr( var1, 1), - lshl( var2, 15)); + *var3 = s_and( var1, 0x1); + var_out = s_or( lshr( var1, 1), + lshl( var2, 15)); - #if (WMOPS) - multiCounter[currCounter].s_and--; - multiCounter[currCounter].lshl--; - multiCounter[currCounter].lshr--; - multiCounter[currCounter].s_or--; - multiCounter[currCounter].rotr++; - #endif /* if WMOPS */ - return( var_out); + return( var_out); } @@ -510,7 +491,7 @@ Word16 rotr( Word16 var1, Word16 var2, Word16 *var3) { * * Outputs : * - * *var3 Points on a 16 bit short signed integer (Word16) whose + * *var3 Points on a 16 bit short signed integer (Word16) whose * value will be 0 or 1. * * Return Value : @@ -519,23 +500,17 @@ Word16 rotr( Word16 var1, Word16 var2, Word16 *var3) { * the range : 0xffff 8000 <= var_out <= 0x0000 7fff. * *****************************************************************************/ -Word16 rotl( Word16 var1, Word16 var2, Word16 *var3) { - Word16 var_out; +Word16 rotl( Word16 var1, Word16 var2, Word16 *var3) +{ + Word16 var_out; - *var3 = lshr( var1, 15); + *var3 = lshr( var1, 15); - var_out = s_or( lshl( var1, 1), - s_and( var2, 0x1)); + var_out = s_or( lshl( var1, 1), + s_and( var2, 0x1)); - #if (WMOPS) - multiCounter[currCounter].lshr--; - multiCounter[currCounter].s_and--; - multiCounter[currCounter].lshl--; - multiCounter[currCounter].s_or--; - multiCounter[currCounter].rotl++; - #endif /* if WMOPS */ - return( var_out); + return( var_out); } @@ -560,7 +535,7 @@ Word16 rotl( Word16 var1, Word16 var2, Word16 *var3) { * * Outputs : * - * *var3 Points on a 16 bit short signed integer (Word16) whose + * *var3 Points on a 16 bit short signed integer (Word16) whose * value will be 0 or 1. * * Return Value : @@ -569,25 +544,17 @@ Word16 rotl( Word16 var1, Word16 var2, Word16 *var3) { * the range : 0x8000 0000 <= L_var_out <= 0x7fff ffff. * *****************************************************************************/ -Word32 L_rotr( Word32 L_var1, Word16 var2, Word16 *var3) { - Word32 L_var_out; +Word32 L_rotr( Word32 L_var1, Word16 var2, Word16 *var3) +{ + Word32 L_var_out; - *var3 = s_and( extract_l( L_var1), 0x1); + *var3 = s_and( extract_l( L_var1), 0x1); - L_var_out = L_or( L_lshr( L_var1, 1), - L_lshl( L_deposit_l( var2), 31)); + L_var_out = L_or( L_lshr( L_var1, 1), + L_lshl( L_deposit_l( var2), 31)); - #if (WMOPS) - multiCounter[currCounter].extract_l--; - multiCounter[currCounter].s_and--; - multiCounter[currCounter].L_deposit_l--; - multiCounter[currCounter].L_lshl--; - multiCounter[currCounter].L_lshr--; - multiCounter[currCounter].L_or--; - multiCounter[currCounter].L_rotr++; - #endif /* if WMOPS */ - return( L_var_out); + return( L_var_out); } @@ -612,7 +579,7 @@ Word32 L_rotr( Word32 L_var1, Word16 var2, Word16 *var3) { * * Outputs : * - * *var3 Points on a 16 bit short signed integer (Word16) whose + * *var3 Points on a 16 bit short signed integer (Word16) whose * value will be 0 or 1. * * Return Value : @@ -621,25 +588,17 @@ Word32 L_rotr( Word32 L_var1, Word16 var2, Word16 *var3) { * the range : 0x8000 0000 <= L_var_out <= 0x7fff ffff. * *****************************************************************************/ -Word32 L_rotl( Word32 L_var1, Word16 var2, Word16 *var3) { - Word32 L_var_out; +Word32 L_rotl( Word32 L_var1, Word16 var2, Word16 *var3) +{ + Word32 L_var_out; - *var3 = extract_l( L_lshr( L_var1, 31)); + *var3 = extract_l( L_lshr( L_var1, 31)); - L_var_out = L_or( L_lshl( L_var1, 1), - L_deposit_l( s_and( var2, 0x1))); + L_var_out = L_or( L_lshl( L_var1, 1), + L_deposit_l( s_and( var2, 0x1))); - #if (WMOPS) - multiCounter[currCounter].L_lshr--; - multiCounter[currCounter].extract_l--; - multiCounter[currCounter].s_and--; - multiCounter[currCounter].L_deposit_l--; - multiCounter[currCounter].L_lshl--; - multiCounter[currCounter].L_or--; - multiCounter[currCounter].L_rotl++; - #endif /* if WMOPS */ - return( L_var_out); + return( L_var_out); } diff --git a/src/libs/libevs/basic_op/enh1632.h b/src/libs/libevs/lib_com/enh1632.h old mode 100755 new mode 100644 similarity index 80% rename from src/libs/libevs/basic_op/enh1632.h rename to src/libs/libevs/lib_com/enh1632.h index 2254fde8..33a77270 --- a/src/libs/libevs/basic_op/enh1632.h +++ b/src/libs/libevs/lib_com/enh1632.h @@ -9,13 +9,13 @@ History: 07 Nov 04 v2.0 Incorporation of new 32-bit / 40-bit / control - operators for the ITU-T Standard Tool Library as + operators for the ITU-T Standard Tool Library as described in Geneva, 20-30 January 2004 WP 3/16 Q10/16 TD 11 document and subsequent discussions on the wp3audio@yahoogroups.com email reflector. March 06 v2.1 Changed to improve portability. - Some counters incrementations were missing (s_and, - s_or, s_xor). + Some counters incrementations were missing (s_and, + s_or, s_xor). 30 Nov 09 v2.3 saturate() removed ============================================================================ @@ -36,13 +36,6 @@ #include "stl.h" -#if (WMOPS) -#include "count.h" -extern BASIC_OP multiCounter[MAXCOUNTERS]; -extern int currCounter; -#endif /* if WMOPS */ - - /***************************************************************************** * * Prototypes for enhanced 16/32 bit arithmetic operators @@ -82,7 +75,7 @@ Word32 L_rotl( Word32 var1, Word16 var2, Word16 *var3); * * Inputs : * - * var1 16 bit short signed integer (Word16) whose value falls in + * var1 16 bit short signed integer (Word16) whose value falls in * the range : 0x8000 <= var1 <= 0x7fff. * * var2 16 bit short signed integer (Word16) whose value falls in @@ -98,19 +91,17 @@ Word32 L_rotl( Word32 var1, Word16 var2, Word16 *var3); * the range : 0x8000 <= L_var_out <= 0x7fff. * *****************************************************************************/ -static __inline Word16 s_max( Word16 var1, Word16 var2) { - Word16 var_out; +static __inline Word16 s_max( Word16 var1, Word16 var2) +{ + Word16 var_out; - if( var1 >= var2) - var_out = var1; - else - var_out = var2; + if( var1 >= var2) + var_out = var1; + else + var_out = var2; - #if (WMOPS) - multiCounter[currCounter].s_max++; - #endif /* if WMOPS */ - return( var_out); + return( var_out); } @@ -126,10 +117,10 @@ static __inline Word16 s_max( Word16 var1, Word16 var2) { * * Inputs : * - * var1 16 bit short signed integer (Word16) whose value falls in + * var1 16 bit short signed integer (Word16) whose value falls in * the range : 0x8000 <= var1 <= 0x7fff. * - * var2 16 bit short signed integer (Word16) whose value falls in + * var2 16 bit short signed integer (Word16) whose value falls in * the range : 0x8000 <= var2 <= 0x7fff. * * Outputs : @@ -138,23 +129,21 @@ static __inline Word16 s_max( Word16 var1, Word16 var2) { * * Return Value : * - * var_out 16 bit short signed integer (Word16) whose value falls in + * var_out 16 bit short signed integer (Word16) whose value falls in * the range : 0x8000 <= var_out <= 0x7fff. * *****************************************************************************/ -static __inline Word16 s_min( Word16 var1, Word16 var2) { - Word16 var_out; +static __inline Word16 s_min( Word16 var1, Word16 var2) +{ + Word16 var_out; - if( var1 <= var2) - var_out = var1; - else - var_out = var2; + if( var1 <= var2) + var_out = var1; + else + var_out = var2; - #if (WMOPS) - multiCounter[currCounter].s_min++; - #endif /* if WMOPS */ - return( var_out); + return( var_out); } @@ -186,19 +175,17 @@ static __inline Word16 s_min( Word16 var1, Word16 var2) { * range : 0x8000 0000 <= L_var_out <= 0x7fff ffff. * *****************************************************************************/ -static __inline Word32 L_max( Word32 L_var1, Word32 L_var2) { - Word32 L_var_out; +static __inline Word32 L_max( Word32 L_var1, Word32 L_var2) +{ + Word32 L_var_out; - if( L_var1 >= L_var2) - L_var_out = L_var1; - else - L_var_out = L_var2; + if( L_var1 >= L_var2) + L_var_out = L_var1; + else + L_var_out = L_var2; - #if (WMOPS) - multiCounter[currCounter].L_max++; - #endif /* if WMOPS */ - return( L_var_out); + return( L_var_out); } @@ -230,19 +217,17 @@ static __inline Word32 L_max( Word32 L_var1, Word32 L_var2) { * range : 0x8000 0000 <= L_var_out <= 0x7fff ffff. * *****************************************************************************/ -static __inline Word32 L_min( Word32 L_var1, Word32 L_var2) { - Word32 L_var_out; +static __inline Word32 L_min( Word32 L_var1, Word32 L_var2) +{ + Word32 L_var_out; - if( L_var1 <= L_var2) - L_var_out = L_var1; - else - L_var_out = L_var2; + if( L_var1 <= L_var2) + L_var_out = L_var1; + else + L_var_out = L_var2; - #if (WMOPS) - multiCounter[currCounter].L_min++; - #endif /* if WMOPS */ - return( L_var_out); + return( L_var_out); } @@ -283,16 +268,14 @@ static __inline Word32 L_min( Word32 L_var1, Word32 L_var2) { * falls in the range 0xffff 8000 <= var_out <= 0x0000 7fff. * *****************************************************************************/ -static __inline Word16 s_and( Word16 var1, Word16 var2) { - Word16 var_out; +static __inline Word16 s_and( Word16 var1, Word16 var2) +{ + Word16 var_out; - var_out = var1 & var2; + var_out = var1 & var2; - #if (WMOPS) - multiCounter[currCounter].s_and++; - #endif /* if WMOPS */ - return( var_out); + return( var_out); } @@ -325,16 +308,14 @@ static __inline Word16 s_and( Word16 var1, Word16 var2) { * falls in the range 0x8000 0000 <= L_var_out <= 0x7fff ffff. * *****************************************************************************/ -static __inline Word32 L_and( Word32 L_var1, Word32 L_var2) { - Word32 L_var_out; +static __inline Word32 L_and( Word32 L_var1, Word32 L_var2) +{ + Word32 L_var_out; - L_var_out = L_var1 & L_var2; + L_var_out = L_var1 & L_var2; - #if (WMOPS) - multiCounter[currCounter].L_and++; - #endif /* if WMOPS */ - return( L_var_out); + return( L_var_out); } @@ -367,16 +348,14 @@ static __inline Word32 L_and( Word32 L_var1, Word32 L_var2) { * falls in the range 0xffff 8000 <= var_out <= 0x0000 7fff. * *****************************************************************************/ -static __inline Word16 s_or( Word16 var1, Word16 var2) { - Word16 var_out; +static __inline Word16 s_or( Word16 var1, Word16 var2) +{ + Word16 var_out; - var_out = var1 | var2; + var_out = var1 | var2; - #if (WMOPS) - multiCounter[currCounter].s_or++; - #endif /* if WMOPS */ - return( var_out); + return( var_out); } @@ -409,17 +388,15 @@ static __inline Word16 s_or( Word16 var1, Word16 var2) { * falls in the range 0x8000 0000 <= L_var_out <= 0x7fff ffff. * *****************************************************************************/ -static __inline Word32 L_or( Word32 L_var1, Word32 L_var2) { +static __inline Word32 L_or( Word32 L_var1, Word32 L_var2) +{ - Word32 L_var_out; + Word32 L_var_out; - L_var_out = L_var1 | L_var2; + L_var_out = L_var1 | L_var2; - #if (WMOPS) - multiCounter[currCounter].L_or++; - #endif /* if WMOPS */ - return( L_var_out); + return( L_var_out); } @@ -452,16 +429,14 @@ static __inline Word32 L_or( Word32 L_var1, Word32 L_var2) { * falls in the range 0xffff 8000 <= var_out <= 0x0000 7fff. * *****************************************************************************/ -static __inline Word16 s_xor( Word16 var1, Word16 var2) { - Word16 var_out; +static __inline Word16 s_xor( Word16 var1, Word16 var2) +{ + Word16 var_out; - var_out = var1 ^ var2; + var_out = var1 ^ var2; - #if (WMOPS) - multiCounter[currCounter].s_xor++; - #endif /* if WMOPS */ - return( var_out); + return( var_out); } @@ -494,16 +469,14 @@ static __inline Word16 s_xor( Word16 var1, Word16 var2) { * falls in the range 0x8000 0000 <= L_var_out <= 0x7fff ffff. * *****************************************************************************/ -static __inline Word32 L_xor( Word32 L_var1, Word32 L_var2) { - Word32 L_var_out; +static __inline Word32 L_xor( Word32 L_var1, Word32 L_var2) +{ + Word32 L_var_out; - L_var_out = L_var1 ^ L_var2; + L_var_out = L_var1 ^ L_var2; - #if (WMOPS) - multiCounter[currCounter].L_xor++; - #endif /* if WMOPS */ - return( L_var_out); + return( L_var_out); } diff --git a/src/libs/libevs/lib_com/enh40.cpp b/src/libs/libevs/lib_com/enh40.cpp new file mode 100644 index 00000000..6f32c984 --- /dev/null +++ b/src/libs/libevs/lib_com/enh40.cpp @@ -0,0 +1,1069 @@ + +/* + =========================================================================== + File: ENH40.C v.2.3 - 30.Nov.2009 + =========================================================================== + + ITU-T STL BASIC OPERATORS + + 40-BIT ARITHMETIC OPERATORS + + History: + 07 Nov 04 v2.0 Incorporation of new 32-bit / 40-bit / control + operators for the ITU-T Standard Tool Library as + described in Geneva, 20-30 January 2004 WP 3/16 Q10/16 + TD 11 document and subsequent discussions on the + wp3audio@yahoogroups.com email reflector. + + ============================================================================ +*/ + + +/***************************************************************************** + * + * Enhanced 40 bit operators : + * + * L40_add() + * L40_sub() + * L40_abs() + * L40_negate() + * L40_max() + * L40_min() + * L40_shr() + * L40_shr_r() + * L40_shl() + * L40_shl_r() + * norm_L40() + * L40_mult() + * L40_mac() + * L40_msu() + * mac_r40() + * msu_r40() + * Mpy_32_16_ss() + * Mpy_32_32_ss() + * L40_lshl() + * L40_lshr() + * L40_round() + * L_saturate40() + * L40_set() + * Extract40_H() + * Extract40_L() + * L_Extract40() + * L40_deposit_h() + * L40_deposit_l() + * L40_deposit32() + * + *****************************************************************************/ + + +/***************************************************************************** + * + * Include-Files + * + *****************************************************************************/ +#include +#include +#include "stl.h" + +/***************************************************************************** + * + * Local Functions + * + *****************************************************************************/ + + +/***************************************************************************** + * + * Constants and Globals + * + *****************************************************************************/ + + +/***************************************************************************** + * + * Functions + * + *****************************************************************************/ + +/***************************************************************************** + * + * Function Name : L40_shl + * + * Purpose : + * + * Arithmetically shifts left L40_var1 by var2 positions. + * - If var2 is negative, L40_var1 is shifted to the LSBits by (-var2) + * positions with extension of the sign bit. + * - If var2 is positive, L40_var1 is shifted to the MSBits by (var2) + * positions. + * Calls the macro L40_UNDERFLOW_OCCURED() in case of underflow on 40-bit. + * Calls the macro L40_OVERFLOW_OCCURED() in case of overflow on 40-bit. + * + * Complexity weight : 1 + * + * Inputs : + * + * L40_var1 40 bit long signed integer (Word40) whose value falls in the + * range : MIN_40 <= L40_var1 <= MAX_40. + * + * var2 16 bit short signed integer (Word16) whose value falls in + * the range : MIN_16 <= var2 <= MAX_16. + * + * Outputs : + * + * none + * + * Return Value : + * + * L40_var_out 40 bit long signed integer (Word40) whose value falls in + * the range : MIN_40 <= L40_var_out <= MAX_40. + * + *****************************************************************************/ +Word40 L40_shl( Word40 L40_var1, Word16 var2) +{ + + Word40 L40_var_out; + Word40 L40_constant; + +#if defined(_MSC_VER) && (_MSC_VER <= 1200) + L40_constant = L40_set( 0xc000000000); +#else + L40_constant = L40_set( 0xc000000000LL); +#endif + + if( var2 < 0) + { + var2 = -var2; + L40_var_out = L40_shr( L40_var1, var2); + } + + else + { + L40_var_out = L40_var1; + + for ( ; var2 > 0; var2--) + { +#if defined(_MSC_VER) && (_MSC_VER <= 1200) + if( L40_var_out > 0x003fffffffff) + { +#else + if( L40_var_out > 0x003fffffffffLL) + { +#endif + Overflow = 1; + exit(1); + /* L40_var_out = L40_OVERFLOW_OCCURED( L40_var_out); */ + break; + } + + else if ( L40_var_out < L40_constant) + { + Overflow = 1; + exit(2); + /* L40_var_out = L40_UNDERFLOW_OCCURED( L40_var_out); */ + break; + } + + else + { + L40_var_out = L40_var_out << 1; + } + } + } + + BASOP_CHECK(); + + + return( L40_var_out); +} + + +/***************************************************************************** + * + * Function Name : L40_shr + * + * Purpose : + * + * Arithmetically shifts right L40_var1 by var2 positions. + * - If var2 is positive, L40_var1 is shifted to the LSBits by (var2) + * positions with extension of the sign bit. + * - If var2 is negative, L40_var1 is shifted to the MSBits by (-var2) + * positions. + * Calls the macro L40_UNDERFLOW_OCCURED() in case of underflow on 40-bit. + * Calls the macro L40_OVERFLOW_OCCURED() in case of overflow on 40-bit. + * + * Complexity weight : 1 + * + * Inputs : + * + * L40_var1 40 bit long signed integer (Word40) whose value falls in the + * range : MIN_40 <= L40_var1 <= MAX_40. + * + * var2 16 bit short signed integer (Word16) whose value falls in + * the range : MIN_16 <= var2 <= MAX_16. + * + * Outputs : + * + * none + * + * Return Value : + * + * L40_var_out 40 bit long signed integer (Word40) whose value falls in + * the range : MIN_40 <= L40_var_out <= MAX_40. + * + *****************************************************************************/ +Word40 L40_shr( Word40 L40_var1, Word16 var2) +{ + Word40 L40_var_out; + + if( var2 < 0) + { + var2 = -var2; + L40_var_out = L40_shl ( L40_var1, var2); + } + else + { + L40_var_out = L40_var1 >> var2; + + } + + + return( L40_var_out); +} + + +/***************************************************************************** + * + * Function Name : L40_negate + * + * Purpose : + * + * Negates L40_var1. + * Calls the macro L40_UNDERFLOW_OCCURED() in case of underflow on 40-bit. + * Calls the macro L40_OVERFLOW_OCCURED() in case of overflow on 40-bit. + * + * Complexity weight : 1 + * + * Inputs : + * + * L40_var1 40 bit long signed integer (Word40) whose value falls in the + * range : MIN_40 <= L40_var1 <= MAX_40. + * + * Outputs : + * + * none + * + * Return Value : + * + * L40_var_out 40 bit long signed integer (Word40) whose value falls in + * the range : MIN_40 <= L40_var_out <= MAX_40. + * + *****************************************************************************/ +Word40 L40_negate( Word40 L40_var1) +{ + Word40 L40_var_out; + + L40_var_out = L40_add( ~L40_var1, 0x01); + + return( L40_var_out); +} + + +/***************************************************************************** + * + * Function Name : L40_add + * + * Purpose : + * + * Adds L40_var1 and L40_var2 and returns the 40-bit result. + * Calls the macro L40_UNDERFLOW_OCCURED() in case of underflow on 40-bit. + * Calls the macro L40_OVERFLOW_OCCURED() in case of overflow on 40-bit. + * + * Complexity weight : 1 + * + * Inputs : + * + * L40_var1 40 bit long signed integer (Word40) whose value falls in the + * range : MIN_40 <= L40_var1 <= MAX_40. + * + * L40_var2 40 bit long signed integer (Word40) whose value falls in the + * range : MIN_40 <= L40_var2 <= MAX_40. + * + * Outputs : + * + * none + * + * Return Value : + * + * L40_var_out 40 bit long signed integer (Word40) whose value falls in + * the range : MIN_40 <= L40_var_out <= MAX_40. + * + *****************************************************************************/ +Word40 L40_add( Word40 L40_var1, Word40 L40_var2) +{ + Word40 L40_var_out; + + L40_var_out = L40_var1 + L40_var2; + +#if defined(_MSC_VER) && (_MSC_VER <= 1200) + if( ((( L40_var1 & 0x8000000000) >> 39) != 0) + && ((( L40_var2 & 0x8000000000) >> 39) != 0) + && ((( L40_var_out & 0x8000000000) >> 39) == 0)) + { + Overflow = 1; + exit(2); + /* L40_var_out = L40_UNDERFLOW_OCCURED( L40_var_out); */ + + } + else if( (((L40_var1 & 0x8000000000) >> 39) == 0) + && (((L40_var2 & 0x8000000000) >> 39) == 0) + && (((L40_var_out & 0x8000000000) >> 39) != 0)) + { + Overflow = 1; + exit(1); + /* L40_var_out = L40_OVERFLOW_OCCURED( L40_var_out); */ + } +#else + if( ((( L40_var1 & 0x8000000000LL) >> 39) != 0) + && ((( L40_var2 & 0x8000000000LL) >> 39) != 0) + && ((( L40_var_out & 0x8000000000LL) >> 39) == 0)) + { + Overflow = 1; + exit(2); + /* L40_var_out = L40_UNDERFLOW_OCCURED( L40_var_out); */ + + } + else if( (((L40_var1 & 0x8000000000LL) >> 39) == 0) + && (((L40_var2 & 0x8000000000LL) >> 39) == 0) + && (((L40_var_out & 0x8000000000LL) >> 39) != 0)) + { + Overflow = 1; + exit(1); + /* L40_var_out = L40_OVERFLOW_OCCURED( L40_var_out); */ + } +#endif + + BASOP_CHECK(); + + + return( L40_var_out); +} + + +/***************************************************************************** + * + * Function Name : L40_sub + * + * Purpose : + * + * Subtracts L40_var2 from L40_var1. + * Calls the macro L40_UNDERFLOW_OCCURED() in case of underflow on 40-bit. + * Calls the macro L40_OVERFLOW_OCCURED() in case of overflow on 40-bit. + * + * Complexity weight : 1 + * + * Inputs : + * + * L40_var1 40 bit long signed integer (Word40) whose value falls in the + * range : MIN_40 <= L40_var1 <= MAX_40. + * + * L40_var2 40 bit long signed integer (Word40) whose value falls in the + * range : MIN_40 <= L40_var2 <= MAX_40. + * + * Outputs : + * + * none + * + * Return Value : + * + * L40_var_out 40 bit long signed integer (Word40) whose value falls in + * the range : MIN_40 <= L40_var_out <= MAX_40. + * + *****************************************************************************/ +Word40 L40_sub( Word40 L40_var1, Word40 L40_var2) +{ + Word40 L40_var_out; + + L40_var_out = L40_var1 - L40_var2; + +#if defined(_MSC_VER) && (_MSC_VER <= 1200) + if( (((L40_var1 & 0x8000000000) >> 39) != 0) + && (((L40_var2 & 0x8000000000) >> 39) == 0) + && (((L40_var_out & 0x8000000000) >> 39) == 0)) + { + Overflow = 1; + exit(2); + /* L40_var_out = L40_UNDERFLOW_OCCURED( L40_var_out); */ + + } + else if( (((L40_var1 & 0x8000000000) >> 39) == 0) + && (((L40_var2 & 0x8000000000) >> 39) != 0) + && (((L40_var_out & 0x8000000000) >> 39) != 0)) + { + Overflow = 1; + exit(1); + /* L40_var_out = L40_OVERFLOW_OCCURED( L40_var_out); */ + } +#else + if( (((L40_var1 & 0x8000000000LL) >> 39) != 0) + && (((L40_var2 & 0x8000000000LL) >> 39) == 0) + && (((L40_var_out & 0x8000000000LL) >> 39) == 0)) + { + Overflow = 1; + exit(2); + /* L40_var_out = L40_UNDERFLOW_OCCURED( L40_var_out); */ + + } + else if( (((L40_var1 & 0x8000000000LL) >> 39) == 0) + && (((L40_var2 & 0x8000000000LL) >> 39) != 0) + && (((L40_var_out & 0x8000000000LL) >> 39) != 0)) + { + Overflow = 1; + exit(1); + /* L40_var_out = L40_OVERFLOW_OCCURED( L40_var_out); */ + } +#endif + + BASOP_CHECK(); + + + return( L40_var_out); +} + + +/***************************************************************************** + * + * Function Name : L40_abs + * + * Purpose : + * + * Returns the absolute value of L40_var1. + * Calls the macro L40_UNDERFLOW_OCCURED() in case of underflow on 40-bit. + * Calls the macro L40_OVERFLOW_OCCURED() in case of overflow on 40-bit. + * + * Complexity weight : 1 + * + * Inputs : + * + * L40_var1 40 bit long signed integer (Word40) whose value falls in the + * range : MIN_40 <= L40_var1 <= MAX_40. + * + * Outputs : + * + * none + * + * Return Value : + * + * L40_var_out 40 bit long signed integer (Word40) whose value falls in + * the range : 0x00 0000 0000 <= L40_var_out <= MAX_40. + * + *****************************************************************************/ +Word40 L40_abs( Word40 L40_var1) +{ + Word40 L40_var_out; + + if( L40_var1 < 0) + { + L40_var_out = L40_negate ( L40_var1); + } + else + { + L40_var_out = L40_var1; + } + + + return( L40_var_out); +} + + +/***************************************************************************** + * + * Function Name : L40_max + * + * Purpose : + * + * Compares L40_var1 and L40_var2 and returns the maximum value. + * + * + * Complexity weight : 1 + * + * Inputs : + * + * L40_var1 40 bit long signed integer (Word40) whose value falls in the + * range : MIN_40 <= L40_var1 <= MAX_40. + * + * L40_var2 40 bit long signed integer (Word40) whose value falls in the + * range : MIN_40 <= L40_var2 <= MAX_40. + * + * Outputs : + * + * none + * + * Return Value : + * + * L40_var_out 40 bit long signed integer (Word40) whose value falls in + * the range : MIN_40 <= L40_var_out <= MAX_40. + * + *****************************************************************************/ +Word40 L40_max( Word40 L40_var1, Word40 L40_var2) +{ + Word40 L40_var_out; + + if( L40_var1 < L40_var2) + L40_var_out = L40_var2; + else + L40_var_out = L40_var1; + + + return( L40_var_out); +} + + +/***************************************************************************** + * + * Function Name : L40_min + * + * Purpose : + * + * Compares L40_var1 and L40_var2 and returns the minimum value. + * + * + * Complexity weight : 1 + * + * Inputs : + * + * L40_var1 40 bit long signed integer (Word40) whose value falls in the + * range : MIN_40 <= L40_var1 <= MAX_40. + * + * L40_var2 40 bit long signed integer (Word40) whose value falls in the + * range : MIN_40 <= L40_var2 <= MAX_40. + * + * Outputs : + * + * none + * + * Return Value : + * + * L40_var_out 40 bit long signed integer (Word40) whose value falls in + * the range : MIN_40 <= L40_var_out <= MAX_40. + * + *****************************************************************************/ +Word40 L40_min( Word40 L40_var1, Word40 L40_var2) +{ + Word40 L40_var_out; + + if( L40_var1 < L40_var2) + L40_var_out = L40_var1; + else + L40_var_out = L40_var2; + + + return( L40_var_out); +} + + +/***************************************************************************** + * + * Function Name : L_saturate40 + * + * Purpose : + * + * If L40_var1 is greater than MAX_32, returns MAX_32. + * If L40_var1 is lower than MIN_32, returns MIN_32. + * If not, returns L_Extract40( L40_var1). + * + * Complexity weight : 1 + * + * Inputs : + * + * L40_var1 40 bit long signed integer (Word40) whose value falls in the + * range : MIN_40 <= L40_var1 <= MAX_40. + * + * Outputs : + * + * none + * + * Return Value : + * + * L_var_out 32 bit long signed integer (Word32) whose value falls in + * the range : 0x8000 0000 <= L_var_out <= 0x7fff ffff. + * + *****************************************************************************/ +Word32 L_saturate40( Word40 L40_var1) +{ + Word32 L_var_out; + + Word40 UNDER_L40_var2 = ( Word40) ~(((( Word40) 1) << 31) - ( Word40) 1 ); + Word40 OVER_L40_var2 = ( Word40) (((( Word40) 1) << 31) - ( Word40) 1 ); + + if( L40_var1 < UNDER_L40_var2) + { + L40_var1 = UNDER_L40_var2; + Overflow = 1; + } + + if( L40_var1 > OVER_L40_var2) + { + L40_var1 = OVER_L40_var2; + Overflow = 1; + } + + L_var_out = L_Extract40( L40_var1); + + BASOP_CHECK(); + + + return( L_var_out); +} + + +/***************************************************************************** + * + * Function Name : Mpy_32_16_ss + * + * Purpose : + * + * Multiplies the 2 signed values L_var1 and var2 with saturation control + * on 48-bit. The operation is performed in fractional mode : + * - L_var1 is supposed to be in 1Q31 format. + * - var2 is supposed to be in 1Q15 format. + * - The result is produced in 1Q47 format : L_varout_h points to the + * 32 MSBits while varout_l points to the 16 LSBits. + * + * Complexity weight : 2 + * + * Inputs : + * + * L_var1 32 bit long signed integer (Word32) whose value falls in + * the range : 0x8000 0000 <= L_var1 <= 0x7fff ffff. + * + * var2 16 bit short signed integer (Word16) whose value falls in + * the range : 0xffff 8000 <= var2 <= 0x0000 7fff. + * + * Outputs : + * + * *L_varout_h 32 bit long signed integer (Word32) whose value falls in + * the range : 0x8000 0000 <= L_varout_h <= 0x7fff ffff. + * + * *varout_l 16 bit short unsigned integer (UWord16) whose value falls in + * the range : 0x0000 0000 <= varout_l <= 0x0000 ffff. + * + * Return Value : + * + * none + * + *****************************************************************************/ +void Mpy_32_16_ss( Word32 L_var1, Word16 var2, Word32 *L_varout_h, UWord16 *varout_l) +{ + Word16 var1_h; + UWord16 uvar1_l; + Word40 L40_var1; + + if( (L_var1 == ( Word32) 0x80000000) + && (var2 == ( Word16) 0x8000)) + { + *L_varout_h = 0x7fffffff; + *varout_l = ( UWord16) 0xffff; + + } + else + { + uvar1_l = extract_l( L_var1); + var1_h = extract_h( L_var1); + + /* Below line can not overflow, so we can use << instead of L40_shl. */ + L40_var1 = (( Word40) (( Word32) var2 * ( Word32) uvar1_l)) << 1; + + *varout_l = Extract40_L( L40_var1); + + L40_var1 = L40_shr( L40_var1, 16); + L40_var1 = L40_mac( L40_var1, var2, var1_h); + + *L_varout_h = L_Extract40( L40_var1); + } + + + return; +} + + +/***************************************************************************** + * + * Function Name : Mpy_32_32_ss + * + * Purpose : + * + * Multiplies the 2 signed values L_var1 and L_var2 with saturation control + * on 64-bit. The operation is performed in fractional mode : + * - L_var1 and L_var2 are supposed to be in 1Q31 format. + * - The result is produced in 1Q63 format : L_varout_h points to the + * 32 MSBits while L_varout_l points to the 32 LSBits. + * + * Complexity weight : 4 + * + * Inputs : + * + * L_var1 32 bit long signed integer (Word32) whose value falls in the + * range : 0x8000 0000 <= L_var1 <= 0x7fff ffff. + * + * L_var2 32 bit long signed integer (Word32) whose value falls in the + * range : 0x8000 0000 <= L_var2 <= 0x7fff ffff. + * + * Outputs : + * + * *L_varout_h 32 bit long signed integer (Word32) whose value falls in + * the range : 0x8000 0000 <= L_varout_h <= 0x7fff ffff. + * + * *L_varout_l 32 bit short unsigned integer (UWord32) whose value falls in + * the range : 0x0000 0000 <= L_varout_l <= 0xffff ffff. + * + * + * Return Value : + * + * none + * + *****************************************************************************/ +void Mpy_32_32_ss( Word32 L_var1, Word32 L_var2, Word32 *L_varout_h, UWord32 *L_varout_l) +{ + UWord16 uvar1_l, uvar2_l; + Word16 var1_h, var2_h; + Word40 L40_var1; + + if( (L_var1 == ( Word32)0x80000000) + && (L_var2 == ( Word32)0x80000000)) + { + *L_varout_h = 0x7fffffff; + *L_varout_l = ( UWord32)0xffffffff; + + } + else + { + + uvar1_l = extract_l( L_var1); + var1_h = extract_h( L_var1); + uvar2_l = extract_l( L_var2); + var2_h = extract_h( L_var2); + + /* Below line can not overflow, so we can use << instead of L40_shl. */ + L40_var1 = (( Word40) (( UWord32) uvar2_l * ( UWord32) uvar1_l)) << 1; + + *L_varout_l = 0x0000ffff & L_Extract40( L40_var1); + + L40_var1 = L40_shr( L40_var1, 16); + L40_var1 = L40_add( L40_var1, (( Word40) (( Word32) var2_h * ( Word32) uvar1_l)) << 1); + L40_var1 = L40_add( L40_var1, (( Word40) (( Word32) var1_h * ( Word32) uvar2_l)) << 1); + *L_varout_l |= (L_Extract40( L40_var1)) << 16; + + L40_var1 = L40_shr( L40_var1, 16); + L40_var1 = L40_mac( L40_var1, var1_h, var2_h); + + *L_varout_h = L_Extract40( L40_var1); + } + + + return; +} + + +/***************************************************************************** + * + * Function Name : L40_lshl + * + * Purpose : + * + * Logically shifts left L40_var1 by var2 positions. + * - If var2 is negative, L40_var1 is shifted to the LSBits by (-var2) + * positions with insertion of 0 at the MSBit. + * - If var2 is positive, L40_var1 is shifted to the MSBits by (var2) + * positions. + * + * Complexity weight : 1 + * + * Inputs : + * + * L40_var1 40 bit long signed integer (Word40) whose value falls in the + * range : MIN_40 <= L40_var1 <= MAX_40. + * + * var2 16 bit short signed integer (Word16) whose value falls in + * the range : MIN_16 <= var2 <= MAX_16. + * + * Outputs : + * + * none + * + * Return Value : + * + * L40_var_out 40 bit long signed integer (Word40) whose value falls in + * the range : MIN_40 <= L40_var_out <= MAX_40. + * + *****************************************************************************/ +Word40 L40_lshl( Word40 L40_var1, Word16 var2) +{ + Word40 L40_var_out; + + if( var2 <= 0) + { + var2 = -var2; + L40_var_out = L40_lshr ( L40_var1, var2); + } + else + { + if( var2 >= 40) + L40_var_out = 0x0000000000; + else + { + L40_var_out = L40_var1 << var2; + } + L40_var_out = L40_set( L40_var_out); + } + + BASOP_CHECK(); + + + return( L40_var_out); +} + + +/***************************************************************************** + * + * Function Name : L40_lshr + * + * Purpose : + * + * Logically shifts right L40_var1 by var2 positions. + * - If var2 is positive, L40_var1 is shifted to the LSBits by (var2) + * positions with insertion of 0 at the MSBit. + * - If var2 is negative, L40_var1 is shifted to the MSBits by (-var2) + * positions. + * + * Complexity weight : 1 + * + * Inputs : + * + * L40_var1 40 bit long signed integer (Word40) whose value falls in the + * range : MIN_40 <= L40_var1 <= MAX_40. + * + * var2 16 bit short signed integer (Word16) whose value falls in + * the range : MIN_16 <= var2 <= MAX_16. +* + * Outputs : + * + * none + * + * Return Value : + * + * L40_var_out 40 bit long signed integer (Word40) whose value falls in + * the range : MIN_40 <= L40_var_out <= MAX_40. + * + *****************************************************************************/ +Word40 L40_lshr( Word40 L40_var1, Word16 var2) +{ + Word40 L40_var_out; + + if( var2 < 0) + { + var2 = -var2; + L40_var_out = L40_lshl ( L40_var1, var2); + } + else + { + if( var2 >= 40) + L40_var_out = 0x0000000000; + else + { +#if defined(_MSC_VER) && (_MSC_VER <= 1200) + L40_var_out = (L40_var1 & 0xffffffffff) >> var2; +#else + L40_var_out = (L40_var1 & 0xffffffffffLL) >> var2; +#endif + } + } + + BASOP_CHECK(); + + + return( L40_var_out); +} + + +/***************************************************************************** + * + * Function Name : norm_L40 + * + * Purpose : + * + * Produces the number of left shifts needed to normalize in 32 bit format + * the 40 bit variable L40_var1. This returned value can be used to scale + * L_40_var1 into the following intervals : + * - [(MAX_32+1)/2 .. MAX_32 ] for positive values. + * - [ MIN_32 .. (MIN_32/2)+1 ] for negative values. + * - [ 0 .. 0 ] for null values. + * In order to normalize the result, the following operation must be done : + * normelized_L40_var1 = L40_shl( L40_var1, norm_L40( L40_var1)) + * + * Complexity weight : 1 + * + * Inputs : + * + * L40_var1 40 bit long signed integer (Word40) whose value falls in the + * range : MIN_40 <= L40_var1 <= MAX_40. + * + * Outputs : + * + * none + * + * Return Value : + * + * var_out 16 bit short signed integer (Word16) whose value falls in + * the range : -8 <= var_out <= 31. + * + *****************************************************************************/ +Word16 norm_L40( Word40 L40_var1) +{ + Word16 var_out; + + var_out = 0; + + if( L40_var1 != 0) + { + while( (L40_var1 > ( Word32)0x80000000L) + && (L40_var1 < ( Word32)0x7fffffffL)) + { + + L40_var1 = L40_shl( L40_var1, 1); + var_out++; + } + + while( (L40_var1 < ( Word32)0x80000000L) + || (L40_var1 > ( Word32)0x7fffffffL)) + { + + L40_var1 = L40_shl( L40_var1, -1); + var_out--; + } + } + + + return( var_out); +} + + + + + + +/***************************************************************************** + * + * Function Name : L40_shr_r + * + * Purpose : + * + * Arithmetically shifts right L40_var1 by var2 positions and rounds the + * result. It is equivalent to L40_shr( L40_var1, var2) except that if the + * last bit shifted out to the LSBit is 1, then the shifted result is + * incremented by 1. + * Calls the macro L40_UNDERFLOW_OCCURED() in case of underflow on 40-bit. + * Calls the macro L40_OVERFLOW_OCCURED() in case of overflow on 40-bit. + * + * Complexity weight : 3 + * + * Inputs : + * + * L40_var1 40 bit long signed integer (Word40) whose value falls in the + * range : MIN_40 <= L40_var1 <= MAX_40. + * + * var2 16 bit short signed integer (Word16) whose value falls in + * the range : 0xffff 8000 <= var2 <= 0x0000 7fff. + * + * Outputs : + * + * none + * + * Return Value : + * + * L40_var_out 40 bit long signed integer (Word40) whose value falls in + * the range : MIN_40 <= L40_var_out <= MAX_40. + * + *****************************************************************************/ +Word40 L40_shr_r( Word40 L40_var1, Word16 var2) +{ + Word40 L40_var_out; + + if( var2 > 39) + { + L40_var_out = 0; + } + else + { + L40_var_out = L40_shr( L40_var1, var2); + + if( var2 > 0) + { + if( ( L40_var1 & (( Word40) 1 << (var2 - 1))) != 0) + { + /* below line can not generate overflows on 40-bit */ + L40_var_out++; + } + } + } + + BASOP_CHECK(); + + + return( L40_var_out); +} + + +/***************************************************************************** + * + * Function Name : L40_shl_r + * + * Purpose : + * + * Arithmetically shifts left L40_var1 by var2 positions and rounds the + * result. It is equivalent to L40_shl( L40_var1, var2) except if var2 is + * negative. In that case, it does the same as + * L40_shr_r( L40_var1, (-var2)). + * Calls the macro L40_UNDERFLOW_OCCURED() in case of underflow on 40-bit. + * Calls the macro L40_OVERFLOW_OCCURED() in case of overflow on 40-bit. + * + * Complexity weight : 3 + * + * Inputs : + * + * L40_var1 40 bit long signed integer (Word40) whose value falls in the + * range : MIN_40 <= L40_var1 <= MAX_40. + * + * var2 16 bit short signed integer (Word16) whose value falls in + * the range : 0xffff 8000 <= var2 <= 0x0000 7fff. + * + * Outputs : + * + * none + * + * Return Value : + * + * L40_var_out 40 bit long signed integer (Word40) whose value falls in + * the range : MIN_40 <= L40_var_out <= MAX_40. + * + *****************************************************************************/ +Word40 L40_shl_r( Word40 L40_var1, Word16 var2) +{ + Word40 L40_var_out; + + if( var2 >= 0) + { + L40_var_out = L40_shl( L40_var1, var2); + } + else + { + var2 = -var2; + L40_var_out = L40_shr_r ( L40_var1, var2); + } + + + return( L40_var_out); +} + + +/* end of file */ diff --git a/src/libs/libevs/lib_com/enh40.h b/src/libs/libevs/lib_com/enh40.h new file mode 100644 index 00000000..bc13eda0 --- /dev/null +++ b/src/libs/libevs/lib_com/enh40.h @@ -0,0 +1,383 @@ +/* + =========================================================================== + File: ENH40.H v.2.3 - 30.Nov.2009 + =========================================================================== + + ITU-T STL BASIC OPERATORS + + 40-BIT ARITHMETIC OPERATORS + + History: + 07 Nov 04 v2.0 Incorporation of new 32-bit / 40-bit / control + operators for the ITU-T Standard Tool Library as + described in Geneva, 20-30 January 2004 WP 3/16 Q10/16 + TD 11 document and subsequent discussions on the + wp3audio@yahoogroups.com email reflector. + March 06 v2.1 Changed to improve portability. + + ============================================================================ +*/ + + +#ifndef _ENH40_H +#define _ENH40_H + + +#include "stl.h" + + +#ifdef _MSC_VER +#define MAX_40 (0x0000007fffffffff) +#define MIN_40 (0xffffff8000000000) +#endif /* ifdef _MSC_VER */ + + + +#define L40_OVERFLOW_OCCURED( L40_var1) (Overflow = 1, exit(1), L40_var1) +#define L40_UNDERFLOW_OCCURED( L40_var1) (Overflow = 1, exit(2), L40_var1) + + + +/***************************************************************************** +* +* Prototypes for enhanced 40 bit arithmetic operators +* +*****************************************************************************/ +Word40 L40_shr( Word40 L40_var1, Word16 var2); +Word40 L40_shr_r( Word40 L40_var1, Word16 var2); +Word40 L40_shl( Word40 L40_var1, Word16 var2); +Word40 L40_shl_r( Word40 L40_var1, Word16 var2); + +static __inline Word40 L40_mult( Word16 var1, Word16 var2); + +static __inline Word40 L40_mac( Word40 L40_var1, Word16 var1, Word16 var2); +static __inline Word16 mac_r40( Word40 L40_var1, Word16 var1, Word16 var2); + +static __inline Word40 L40_msu( Word40 L40_var1, Word16 var1, Word16 var2); +static __inline Word16 msu_r40( Word40 L40_var1, Word16 var1, Word16 var2); + + +void Mpy_32_16_ss( Word32 L_var1, Word16 var2, Word32 *L_varout_h, UWord16 *varout_l); +void Mpy_32_32_ss( Word32 L_var1, Word32 L_var2, Word32 *L_varout_h, UWord32 *L_varout_l); + + +Word40 L40_lshl( Word40 L40_var1, Word16 var2); +Word40 L40_lshr( Word40 L40_var1, Word16 var2); + +static __inline Word40 L40_set( Word40 L40_var1); +static __inline UWord16 Extract40_H( Word40 L40_var1); +static __inline UWord16 Extract40_L( Word40 L40_var1); +static __inline UWord32 L_Extract40( Word40 L40_var1); + +static __inline Word40 L40_deposit_h( Word16 var1); +static __inline Word40 L40_deposit_l( Word16 var1); +static __inline Word40 L40_deposit32( Word32 L_var1); + +static __inline Word40 L40_round( Word40 L40_var1); +static __inline Word16 round40( Word40 L40_var1); + + +Word40 L40_add( Word40 L40_var1, Word40 L40_var2); +Word40 L40_sub( Word40 L40_var1, Word40 L40_var2); +Word40 L40_abs( Word40 L40_var1); +Word40 L40_negate( Word40 L40_var1); +Word40 L40_max( Word40 L40_var1, Word40 L40_var2); +Word40 L40_min( Word40 L40_var1, Word40 L40_var2); +Word32 L_saturate40( Word40 L40_var1); +Word16 norm_L40( Word40 L40_var1); + + + +/*#ifdef _MSC_VER*/ +static __inline Word40 L40_set( Word40 L40_var1) +{ + Word40 L40_var_out; + +#if defined(_MSC_VER) && (_MSC_VER <= 1200) + L40_var_out = L40_var1 & 0x000000ffffffffff; + + if( L40_var1 & 0x8000000000) + L40_var_out = L40_var_out | 0xffffff0000000000; +#else + L40_var_out = L40_var1 & 0x000000ffffffffffLL; + + if( L40_var1 & 0x8000000000LL) + L40_var_out = L40_var_out | 0xffffff0000000000LL; +#endif + + + return( L40_var_out); +} +/*#endif*/ /* ifdef _MSC_VER */ + + + +static __inline UWord16 Extract40_H( Word40 L40_var1) +{ + UWord16 var_out; + + var_out = ( UWord16)( L40_var1 >> 16); + + + return( var_out); +} + + +static __inline UWord16 Extract40_L( Word40 L40_var1) +{ + UWord16 var_out; + + var_out = ( UWord16)( L40_var1); + + + return( var_out); +} + + +static __inline UWord32 L_Extract40( Word40 L40_var1) +{ + UWord32 L_var_out; + + L_var_out = ( UWord32) L40_var1; + + + return(L_var_out); +} + + +static __inline Word40 L40_deposit_h( Word16 var1) +{ + Word40 L40_var_out; + + L40_var_out = (( Word40) var1) << 16; + +#if defined(_MSC_VER) && (_MSC_VER <= 1200) + if( var1 & 0x8000) + { + L40_var_out = L40_set( L40_var_out | 0xff00000000); +#else + if( var1 & 0x8000) + { + L40_var_out = L40_set( L40_var_out | 0xff00000000LL); +#endif + } + + + return( L40_var_out); +} + + +static __inline Word40 L40_deposit_l( Word16 var1) +{ + Word40 L40_var_out; + + L40_var_out = var1; + +#if defined(_MSC_VER) && (_MSC_VER <= 1200) + if( var1 & 0x8000) + { + L40_var_out = L40_set( L40_var_out | 0xffffff0000); +#else + if( var1 & 0x8000) + { + L40_var_out = L40_set( L40_var_out | 0xffffff0000LL); +#endif + } + + + return( L40_var_out); +} + + +static __inline Word40 L40_deposit32( Word32 L_var1) +{ + Word40 L40_var_out; + + L40_var_out = ( Word40) L_var1; + +#if defined(_MSC_VER) && (_MSC_VER <= 1200) + if( L_var1 & 0x80000000) + { + L40_var_out = L40_set( L40_var_out | 0xff00000000); +#else + if( L_var1 & 0x80000000) + { + L40_var_out = L40_set( L40_var_out | 0xff00000000LL); +#endif + } + + + return( L40_var_out); +} + + + + + + + + +static __inline Word40 L40_round( Word40 L40_var1) +{ + Word40 L40_var_out; + Word40 L40_constant; + +#if defined(_MSC_VER) && (_MSC_VER <= 1200) + L40_constant = L40_set( 0xffffff0000); +#else + L40_constant = L40_set( 0xffffff0000LL); +#endif + + L40_var_out = L40_add( 0x8000, L40_var1); + L40_var_out = L40_var_out & L40_constant; + + + return( L40_var_out); +} + + +static __inline Word16 round40( Word40 L40_var1) +{ + Word16 var_out; + + var_out = extract_h( L_saturate40( L40_round( L40_var1))); + + + return( var_out); +} + + +static __inline Word40 L40_mult( Word16 var1, Word16 var2) +{ + Word32 L_var_out; + Word40 L40_var_out; + + L_var_out = ( Word32) var1 * ( Word32) var2; + L40_var_out = ( Word40) L_var_out; + + /* Below line can not overflow, so we can use << instead of L40_shl. */ + L40_var_out = L40_var_out << 1; + + + return( L40_var_out); +} + + + + + + + + + + + + +static __inline Word40 L40_mac( Word40 L40_var1, Word16 var2, Word16 var3) +{ + Word40 L40_var_out; + + L40_var_out = L40_mult( var2, var3); + L40_var_out = L40_add( L40_var1, L40_var_out); + + + return( L40_var_out); +} + + + + + + +static __inline Word16 mac_r40( Word40 L40_var1, Word16 var2, Word16 var3) +{ + Word40 L40_var_out; + Word16 var_out; + + L40_var_out = L40_mac( L40_var1, var2, var3); + var_out = round40( L40_var_out); + + + return( var_out); +} + + + + + + +static __inline Word40 L40_msu( Word40 L40_var1, Word16 var2, Word16 var3) +{ + Word40 L40_var_out; + + L40_var_out = L40_mult( var2, var3); + L40_var_out = L40_sub( L40_var1, L40_var_out); + + + return( L40_var_out); +} + + + + + + +static __inline Word16 msu_r40( Word40 L40_var1, Word16 var2, Word16 var3) +{ + Word40 L40_var_out; + Word16 var_out; + + L40_var_out = L40_msu( L40_var1, var2, var3); + var_out = round40( L40_var_out); + + + return( var_out); +} + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +#endif /*_ENH40_H*/ + + +/* end of file */ + + diff --git a/src/libs/libevs/lib_com/enhancer.cpp b/src/libs/libevs/lib_com/enhancer.cpp new file mode 100644 index 00000000..407a0c54 --- /dev/null +++ b/src/libs/libevs/lib_com/enhancer.cpp @@ -0,0 +1,243 @@ +/*==================================================================================== + EVS Codec 3GPP TS26.443 Nov 13, 2018. Version 12.11.0 / 13.7.0 / 14.3.0 / 15.1.0 + ====================================================================================*/ + +#include +#include "options.h" +#include "cnst.h" +#include "prot.h" +#include "rom_com.h" + +/*---------------------------------------------------------------------* + * Local functions + *---------------------------------------------------------------------*/ + +static void agc2( const float *sig_in, float *sig_out,const short l_trm ); + +/*---------------------------------------------------------------------* + * enhancer() + * + * Enhancement of the excitation signal before synthesis + *---------------------------------------------------------------------*/ + +void enhancer( + const short codec_mode, /* i : flag indicating Codec Mode */ + const long core_brate, /* i : core bitrate */ + const short cbk_index, /* i : */ + const short Opt_AMR_WB, /* i : flag indicating AMR-WB IO mode */ + const short coder_type, /* i : coding type */ + const short L_frame, /* i : frame size */ + const float voice_fac, /* i : subframe voicing estimation */ + const float stab_fac, /* i : LP filter stablility measure */ + const float norm_gain_code, /* i : normalized innovative cb. gain */ + const float gain_inov, /* i : gain of the unscaled innovation */ + float *gc_threshold, /* i/o: code threshold */ + float *code, /* i/o: innovation */ + float *pt_exc2, /* i/o: adapt. excitation/total exc. */ + const float gain_pit, /* i : Quantized pitch gain */ + float *dispMem /* i/o: Phase dispersion algorithm memory */ +) +{ + float tmp, gain_code, new_norm_gain_code, fac; + short i; + float pit_sharp; + float excp[L_SUBFR]; + + pit_sharp = gain_pit; + + /*-----------------------------------------------------------------* + * Phase dispersion + * + * Enhance noise at low bit rates + *-----------------------------------------------------------------*/ + + i = 2; /* no dispersion */ + if( Opt_AMR_WB ) + { + if ( core_brate <= ACELP_6k60 ) + { + i = 0; /* high dispersion */ + } + else if ( core_brate <= ACELP_8k85 ) + { + i = 1; /* low dispersion */ + } + } + else if( codec_mode == MODE1 && coder_type != UNVOICED ) + { + if ( core_brate <= ACELP_7k20 ) + { + i = 0; /* high dispersion */ + } + else if ( ( coder_type == GENERIC || coder_type == TRANSITION || coder_type == AUDIO || coder_type == INACTIVE ) && core_brate <= ACELP_9k60 ) + { + i = 1; /* low dispersion */ + } + } + else if( codec_mode == MODE2 ) + { + if( ((coder_type!=VOICED) && cbk_index<=2) || ((coder_type==UNVOICED) && L_frame==L_FRAME && cbk_index<=10) || ((coder_type==UNVOICED) && L_frame==L_FRAME16k && cbk_index<=14)) + { + i = 0; /* high dispersion */ + } + else if( (coder_type!=VOICED) && (cbk_index<=7) ) + { + i = 1; /* low dispersion */ + } + } + + phase_dispersion( norm_gain_code, gain_pit, code, i, dispMem ); + + /*------------------------------------------------------------ + * Noise enhancer + * + * Enhance excitation on noise (modify code gain). If signal is noisy and LPC filter is stable, + * move code gain 1.5 dB towards its threshold. This decreases by 3 dB noise energy variation. + *-----------------------------------------------------------*/ + + if ( norm_gain_code < *gc_threshold ) + { + new_norm_gain_code = (float)(norm_gain_code * 1.19f); + if ( new_norm_gain_code > *gc_threshold ) + { + new_norm_gain_code = *gc_threshold; + } + } + else + { + new_norm_gain_code = (float)(norm_gain_code / 1.19f); + if ( new_norm_gain_code < *gc_threshold ) + { + new_norm_gain_code = *gc_threshold; + } + } + *gc_threshold = new_norm_gain_code; + + /* calculate new code gain */ + fac = stab_fac * (0.5f * (1.0f - voice_fac)); /* 1 = unvoiced, 0 = voiced */ + gain_code = fac * new_norm_gain_code + (1.0f - fac) * norm_gain_code; + gain_code *= gain_inov; + + for (i=0; i 1.0 ) + { + pit_sharp = 1.0; + } + + if ( pit_sharp > 0.5 ) + { + for (i = 0; i < L_SUBFR; i++) + { + excp[i] = pt_exc2[i] * pit_sharp * 0.25f; + } + } + } + + /*----------------------------------------------------------------- + * Do a simple noncasual "sharpening": effectively an FIR + * filter with coefs [-tmp 1.0 -tmp] where tmp = 0 ... 0.25 + * This is applied to code and added to exc2 + *-----------------------------------------------------------------*/ + if( L_frame == L_FRAME16k ) + { + tmp = (float)(0.150f*(1.0f+voice_fac)); /* 0.30=voiced, 0=unvoiced */ + } + else + { + tmp = (float)(0.125f * (1.0f + voice_fac)); /* 0.25=voiced, 0=unvoiced */ + } + pt_exc2[0] += code[0] - (tmp * code[1]); + for ( i=1; i 0.5f ) + { + for (i = 0; i < L_SUBFR; i++) + { + excp[i] += pt_exc2[i]; + } + + agc2( pt_exc2, excp, L_SUBFR ); + mvr2r( excp, pt_exc2, L_SUBFR ); + } + } + } + + return; +} + +/*-----------------------------------------------------------------------* + * agc2() + * + * Adaptive gain control + *-----------------------------------------------------------------------*/ + +static void agc2( + const float *sig_in, /* i : postfilter input signal */ + float *sig_out, /* i/o: postfilter output signal */ + const short l_trm /* i : subframe size */ +) +{ + short i; + float gain_in, gain_out; + float g0, gain; + + + gain_out = 0.0f; + for(i=0; iQ0,a[1]->Q16,a[2-7]->Q14) */ -/*--------------------------------------------------------------------------------------*/ - -/* _ None */ -/*--------------------------------------------------------------------------------------*/ -/* RETURN ARGUMENTS : */ -/* _ None */ -/*======================================================================================*/ -void enhancer_fx( - const Word32 core_brate, /* i : decoder bitrate */ - const Word16 Opt_AMR_WB, /* i : flag indicating AMR-WB IO mode */ - const Word16 coder_type, /* i : coder type */ - const Word16 i_subfr, /* i : subframe number */ - const Word16 L_frame, /* i : frame size */ - const Word16 voice_fac, /* i : subframe voicing estimation Q15 */ - const Word16 stab_fac, /* i : LP filter stablility measure Q15 */ - Word32 norm_gain_code, /* i : normalised innovative cb. gain Q16 */ - const Word16 gain_inov, /* i : gain of the unscaled innovation Q12 */ - Word32 *gc_threshold,/* i/o: gain code threshold Q16 */ - Word16 *code, /* i/o: innovation Q12 */ - Word16 *exc2, /* i/o: adapt. excitation/total exc. Q_exc*/ - const Word16 gain_pit, /* i : quantized pitch gain Q14 */ - struct dispMem_fx *dm_fx, /* i/o: phase dispersion algorithm memory */ - const Word16 Q_exc /* i : Q of the excitation */ -) -{ - Word16 tmp, fac, *pt_exc2; - Word16 i; - Word32 L_tmp; - Word16 gain_code_hi; - Word16 pit_sharp, tmp16; - Word16 excp[L_SUBFR], sc; - - pit_sharp = gain_pit; - move16(); /* to remove gcc warning */ - pt_exc2 = exc2 + i_subfr; - move16(); - - /*------------------------------------------------------------* - * Phase dispersion to enhance noise at low bit rate - *------------------------------------------------------------*/ - - i = 2; - move16(); /* no dispersion */ - IF (Opt_AMR_WB) - { - IF ( L_sub(core_brate,ACELP_6k60) <= 0) - { - i = 0; - move16(); /* high dispersion */ - } - ELSE if ( L_sub(core_brate,ACELP_8k85) <= 0) - { - i = 1; - move16(); /* low dispersion */ - } - } - ELSE IF( sub(coder_type,UNVOICED) != 0) - - { - test(); - test(); - test(); - test(); - IF ( L_sub(core_brate,ACELP_7k20) <= 0 ) - { - i = 0; - move16(); /* high dispersion */ - } - ELSE if ( ( sub(coder_type,GENERIC) == 0 || sub(coder_type,TRANSITION) == 0 || sub(coder_type,AUDIO) == 0 || sub(coder_type,INACTIVE) == 0 ) && L_sub(core_brate,ACELP_9k60) <= 0 ) - { - i = 1; - move16(); /* low dispersion */ - } - } - phase_dispersion_fx(norm_gain_code, gain_pit, code, i, dm_fx); - - /*------------------------------------------------------------ - * noise enhancer - * - * - Enhance excitation on noise. (modify gain of code) - * If signal is noisy and LPC filter is stable, move gain - * of code 1.5 dB toward gain of code threshold. - * This decreases by 3 dB noise energy variation. - *-----------------------------------------------------------*/ - - /* tmp = 0.5f * (1.0f - voice_fac) */ - tmp = msu_r(0x40000000, voice_fac, 16384); /*Q15 */ /* 1=unvoiced, 0=voiced */ - /* fac = stab_fac * tmp */ - fac = mult(stab_fac, tmp); /*Q15*/ - - IF (L_sub(norm_gain_code, *gc_threshold) < 0) - { - L_tmp = Madd_32_16(norm_gain_code, norm_gain_code, 6226);/*Q16 */ - L_tmp = L_min(L_tmp, *gc_threshold);/*Q16 */ - } - ELSE - { - L_tmp = Mult_32_16(norm_gain_code, 27536);/*Q16 */ - L_tmp = L_max(L_tmp, *gc_threshold); /*Q16 */ - } - *gc_threshold = L_tmp; - move32(); /*Q16 */ - - /* gain_code = (fac * tmp) + (1.0 - fac) * gain_code ==> fac * (tmp - gain_code) + gain_code */ - L_tmp = L_sub(L_tmp, norm_gain_code); /*Q16 */ - norm_gain_code = Madd_32_16(norm_gain_code, L_tmp, fac);/*Q16 */ - - /* gain_code *= gain_inov - Inverse the normalization */ - L_tmp = Mult_32_16(norm_gain_code, gain_inov); /*Q13*/ /* gain_inov in Q12 */ - - sc = 6; - move16(); - - gain_code_hi = round_fx(L_shl(L_tmp, add(Q_exc, 3))); /* in Q_exc */ - - /*------------------------------------------------------------* - * pitch enhancer - * - * - Enhance excitation on voiced. (HP filtering of code) - * On voiced signal, filtering of code by a smooth fir HP - * filter to decrease energy of code at low frequency. - *------------------------------------------------------------*/ - test(); - IF( !Opt_AMR_WB && sub(coder_type,UNVOICED) == 0 ) - { - /* Copy(code, exc2, L_SUBFR) */ - FOR (i = 0; i < L_SUBFR; i++) - { - pt_exc2[i] = round_fx(L_shl(L_mult(gain_code_hi, code[i]), sc)); /*Q0 */ /* code in Q12 (Q9 for encoder) */ - } - } - ELSE - { - test(); - test(); - IF ( Opt_AMR_WB && ( L_sub(core_brate,ACELP_8k85) == 0|| L_sub(core_brate,ACELP_6k60) == 0 ) ) - { - pit_sharp = shl(gain_pit, 1); /* saturation can occur here Q14 -> Q15 */ - - /* saturation takes care of "if (pit_sharp > 1.0) { pit_sharp=1.0; }" */ - IF (sub(pit_sharp, 16384) > 0) - { - tmp16 = mult(pit_sharp, 8192); - FOR (i = 0; i < L_SUBFR; i++) - { - /* excp[i] = pt_exc2[i] * pit_sharp * 0.25 */ - excp[i] = mult_r(pt_exc2[i], tmp16); - move16(); - } - } - } - - IF ( sub(L_frame, L_FRAME16k) == 0 ) - { - /* tmp = 0.150 * (1.0 + voice_fac) */ - /* 0.30=voiced, 0=unvoiced */ - tmp = mac_r(0x10000000L, voice_fac, 4915);/*Q15 */ - } - ELSE - { - /* tmp = 0.125 * (1.0 + voice_fac) */ - /* 0.25=voiced, 0=unvoiced */ - tmp = mac_r(0x10000000L, voice_fac, 4096);/*Q15 */ - } - - /*----------------------------------------------------------------- - * Do a simple noncasual "sharpening": effectively an FIR - * filter with coefs [-tmp 1.0 -tmp] where tmp=0...0.25. - * This is applied to code and add_fxed to exc2 - *-----------------------------------------------------------------*/ - /* pt_exc2[0] += code[0] - tmp * code[1] */ - L_tmp = L_deposit_h(code[0]); /* if Enc :Q9 * Q15 -> Q25 */ - L_tmp = L_msu(L_tmp, code[1], tmp); /* Q12 * Q15 -> Q28 */ - L_tmp = L_shl(L_mult(gain_code_hi, extract_h(L_tmp)), sc); - pt_exc2[0] = msu_r(L_tmp, -32768, pt_exc2[0]); - move16();/* in Q_exc */ - - FOR (i = 1; i < L_SUBFR-1; i++) - { - /* pt_exc2[i] += code[i] - tmp * code[i-1] - tmp * code[i+1] */ - L_tmp = L_msu(-32768, code[i], -32768); - L_tmp = L_msu(L_tmp, code[i + 1], tmp); - tmp16 = msu_r(L_tmp, code[i - 1], tmp); - L_tmp = L_shl(L_mult(gain_code_hi, tmp16), sc); - pt_exc2[i] = msu_r(L_tmp, -32768, pt_exc2[i]); - move16(); /* in Q_exc */ - } - - /* pt_exc2[L_SUBFR-1] += code[L_SUBFR-1] - tmp * code[L_SUBFR-2] */ - L_tmp = L_deposit_h(code[L_SUBFR - 1]);/*Q28 */ - L_tmp = L_msu(L_tmp, code[L_SUBFR - 2], tmp);/*Q28 */ - L_tmp = L_shl(L_mult(gain_code_hi, extract_h(L_tmp)), sc); - pt_exc2[L_SUBFR - 1] = msu_r(L_tmp, -32768, pt_exc2[L_SUBFR - 1]); - move16();/* in Q_exc */ - test(); - test(); - IF ( Opt_AMR_WB && ( L_sub(core_brate,ACELP_8k85) == 0 || L_sub(core_brate,ACELP_6k60) == 0 ) ) - { - IF (sub(pit_sharp, 16384) > 0) - { - FOR (i = 0; i < L_SUBFR; i++) - { - /* excp[i] += pt_exc2[i] */ - excp[i] = add(excp[i], pt_exc2[i]); - move16(); - } - agc2_fx(pt_exc2, excp, L_SUBFR); - Copy(excp, pt_exc2, L_SUBFR); - } - } - } -} - -/*---------------------------------------------------------* - * Enhancement of the excitation signal before synthesis - *---------------------------------------------------------*/ - -Word16 E_UTIL_enhancer( - Word16 voice_fac, /* i : subframe voicing estimation Q15 */ - Word16 stab_fac, /* i : LP filter stability measure Q15 */ - Word32 gain_code, /* i : innovative cb. gain 15Q16 */ - Word16 gain_inov, /* i : gain of the unscaled innovation Q11 */ - Word32 *gc_threshold, /* i/o: gain code threshold 15Q16 */ - Word16 *code, /* i/o: innovation(in: Q9) code_exp */ - Word16 *exc2, /* i/o: adapt. excitation/total exc. */ - Word16 gain_pit, /* i : Quantized pitch gain 1Q14 */ - Word32 *prev_gain_code, /* i/o: previous codebook gain 15Q16 */ - Word16 prev_gain_pit[], /* i/o: previous pitch gain, size=6 1Q14 */ - Word16 *prev_state, /* i/o: Phase dispersion algorithm memory Q0 */ - Word16 coder_type, /* i : coder type */ - Word16 cdk_index, /* i : */ - Word16 L_subfr, /* i : length of subframe */ - Word16 L_frame, /* i : frame size */ - Word16 Q_new -) -{ - Word16 disp_mode, i; - Word16 tmp, fac, gain; - Word32 L_tmp; - Word16 code_exp, exc2_exp; - Word16 max_cdk_index_uv; - - move16(); - code_exp = 15-9; - exc2_exp = 15-Q_new; - gain_inov = shr(gain_inov,1); - /*-----------------------------------------------------------------* - * Phase dispersion to enhance noise at low bit rates - *-----------------------------------------------------------------*/ - - max_cdk_index_uv = 10; - move16(); - if ( sub(L_frame, L_FRAME16k) == 0 ) - { - max_cdk_index_uv = 14; - move16(); - } - disp_mode = 2; /* any=off */ move16(); - test(); - test(); - test(); - test(); - IF ( ( (sub(coder_type, VOICED) != 0) && (sub(cdk_index, 2) <= 0) ) || ( (sub(coder_type, UNVOICED) == 0) && (sub(cdk_index, max_cdk_index_uv) <= 0) ) ) - { - disp_mode = 0; /* high */ move16(); - } - ELSE IF ( (sub(coder_type, VOICED) != 0) && (sub(cdk_index, 7) <= 0) ) - { - disp_mode = 1; /* low */ move16(); - } - - phase_dispersion(gain_code, gain_pit,code, &code_exp, disp_mode, prev_gain_code, prev_gain_pit, prev_state, L_subfr); - - /*------------------------------------------------------------* - * noise enhancer * - * ~~~~~~~~~~~~~~ * - * - Enhance excitation on noise. (modify gain of code) * - * If signal is noisy and LPC filter is stable, move gain * - * of code 1.5 dB toward gain of code threshold. * - * This decrease by 3 dB noise energy variation. * - *------------------------------------------------------------*/ - fac = 0; - move16(); - - /* if gain_code is computed function of energy, noise enhancer is by-passed.*/ - BASOP_SATURATE_WARNING_OFF - tmp = msu_r(1073741824l/*0.5f Q31*/, 16384/*0.5f Q15*/, voice_fac); /* 1=unvoiced, 0=voiced */ - BASOP_SATURATE_WARNING_ON - fac = mult_r(stab_fac, tmp); /* fac in Q15 */ - - L_tmp = L_add(0,gain_code); /* L_tmp in 15Q16 */ - - IF (L_sub(L_tmp,*gc_threshold) < 0) - { - L_tmp = L_shl(Mpy_32_32(L_tmp, 1277752832l/*1.19f/2.0f Q31*/),1); - L_tmp = L_min(L_tmp, *gc_threshold); - } - ELSE - { - L_tmp = Mpy_32_32(L_tmp, 1804608000l/*1.0f/1.19f Q31*/); - L_tmp = L_max(L_tmp, *gc_threshold); - } - move32(); - *gc_threshold = L_tmp; /* in 15Q16 */ - - /* gain = ( (fac * L_tmp) + (gain_code - fac*gain_code) ) * gain_inov */ - /* exponent of L_tmp: 31-16 + 15-11 */ - L_tmp = Mpy_32_16_1(L_add(Mpy_32_16_1(L_tmp, fac), L_sub(gain_code, Mpy_32_16_1(gain_code, fac))), gain_inov); - - /* exponent gain: 31-16 + 15-11 - tmp */ - tmp = norm_l(L_tmp); - - /* exponent of code: 31-16 + 15-11 - tmp + code_exp */ - move16(); - code_exp = sub(add(31-16 + 15-11, code_exp), tmp); - - L_tmp = L_shl(L_tmp, tmp); - gain = round_fx(L_tmp); - - FOR (i=0; iQ0,a[1]->Q16,a[2-7]->Q14) */ -/*--------------------------------------------------------------------------------------*/ - -/* _ None */ -/*--------------------------------------------------------------------------------------*/ -/* RETURN ARGUMENTS : */ -/* _ None */ -/*======================================================================================*/ -static void phase_dispersion_fx( - Word32 gain_code, /* i : gain of code Q16 */ - Word16 gain_pit, /* i : gain of pitch Q14 */ - Word16 code[], /* i/o: code vector */ - Word16 mode, /* i : level, 0=hi, 1=lo, 2=off */ - struct dispMem_fx *dm_fx /* i/o: static memory (size = 8) */ -) -{ - Word16 i, j, state; - Word16 *prev_gain_pit, *prev_state; - Word32 *prev_gain_code; - Word16 *code2_real, *code2_imag; - Word16 *code_real, *code_imag; - const Word16 *h_real, *h_imag; - - Word16 code2[2 * L_SUBFR]; - - prev_state = &(dm_fx->prev_state); - prev_gain_code = &(dm_fx->prev_gain_code); - prev_gain_pit = dm_fx->prev_gain_pit; - - state = 2; - move16(); - if (sub(gain_pit, pitch_0_9) < 0) - { - state = 1; - move16(); - } - - if (sub(gain_pit, pitch_0_6) < 0) - { - state = 0; - move16(); - } - - FOR (i = 5; i > 0; i--) - { - prev_gain_pit[i] = prev_gain_pit[i - 1]; - move16(); - } - prev_gain_pit[0] = gain_pit; - move16(); - - IF (L_sub(L_sub(gain_code, *prev_gain_code), L_shl(*prev_gain_code, 1)) > 0) - { - state = s_min(add(state, 1), 2); - } - ELSE - { - j = 0; - move16(); - - FOR (i = 0; i < 6; i++) - { - j = sub(j, shr(sub(prev_gain_pit[i], pitch_0_6), 15)); - } - - if (sub(j, 2) > 0) - { - state = 0; - move16(); - } - - if (sub(sub(state, *prev_state), 1) > 0) - { - state = sub(state, 1); - } - } - - *prev_gain_code = gain_code; - move32(); - *prev_state = state; - move16(); - - /*-----------------------------------------------------------------* - * circular convolution - *-----------------------------------------------------------------*/ - - state = add(state, mode); /* level of dispersion */ - - IF (sub(state, 2) < 0) - { - r_fft_fx_lc(phs_tbl_dec, SIZE, SIZE2, NUM_STAGES, code, code2, 1); - - h_real = Mid_H_phasedisp; - move16(); - if (state == 0) - { - h_real = Low_H_phasedisp; - move16(); - } - - /* FFT Coefs are in code2 */ - code2_real = code2; - move16(); - code2_imag = code2 + L_SUBFR - 1; - move16(); - - code_real = code; - move16(); - code_imag = code + L_SUBFR - 1; - move16(); - - h_imag = h_real + L_SUBFR - 1; - move16(); - - *code_real++ = mult(*code2_real++, *h_real++); - move16(); /* DC */ - - FOR (i=1; i +#include "options.h" +#include "cnst.h" +#include "rom_com.h" +#include "prot.h" + + +/*--------------------------------------------------------------------------* + * env_adj() + * + * Adjust the band energies of noise-fill and low resolution bands + *--------------------------------------------------------------------------*/ + +void env_adj ( + const short *pulses, /* i : number of pulses per band */ + const short length, /* i : length of spectrum */ + const short last_sfm, /* i : index of the last band */ + float *adj, /* o : adjustment factors for the envelope */ + const float env_stab, /* i : Envelope stability parameter */ + const short *sfmsize /* i : Band widths */ +) +{ + short i, j, group; + int npul; + short att_state; + short start, len; + float tmp; + float gain_adj; + short idx; + + att_state = 0; + len = 0; + start = 0; + + /* Find attenuation levels */ + for( i = 0; i <= last_sfm ; i++ ) + { + group = (sfmsize[i] >> 3) - 1; + npul = pulses[i]; + + if( length == L_FRAME32k ) + { + if( npul == 0 ) + { + /* Noise filled band */ + if ( group <= 1 ) + { + if ( i > 0 && pulses[i-1] != 0 && pulses[i+1] != 0 ) + { + adj[i] = 0.36f; + } + else if ( i > 0 && ( pulses[i-1] == 0 || pulses[i+1] == 0) ) + { + adj[i] = 0.54f; + } + else + { + adj[i] = 0.72f; + } + } + else if (i < last_sfm) + { + if ( pulses[i-1] != 0 && pulses[i+1] != 0 ) + { + adj[i] = 0.54f; + } + else + { + adj[i] = 0.72f; + } + } + else + { + adj[i] = 0.72f; + } + + if( att_state == 0 ) + { + start = i; + } + + len++; + att_state = 1; + } + else + { + adj[i] = 1.0f; + if(att_state == 1) /* End of attenuation region found */ + { + tmp = min(1, max(0, len-ENV_ADJ_START)*(1.0f/ENV_ADJ_INCL)); + for( j = start; j < i ; j++ ) + { + adj[j] = max(tmp + (1-tmp)*adj[j],env_stab); + } + len = 0; + att_state = 0; + } + } + } + /* length == L_FRAME16k */ + else + { + /* Calculate low accuracy band attenuation */ + gain_adj = 1.0f; + if( npul > 0 && npul < MAX_P_ATT ) + { + idx = (short)(npul * att_step[group] + 0.5f) - 1; + if( idx < MAX_P_ATT ) + { + gain_adj = gain_att[idx]; + } + } + adj[i] = gain_adj; + } + } + + /* Check if the sequence ended with an attenuation region */ + if( att_state == 1 ) + { + tmp = min(1, max(0, len-ENV_ADJ_START)*(1.0f/ENV_ADJ_INCL)); + + for( j = start; j < i ; j++ ) + { + adj[j] = max(tmp + (1-tmp)*adj[j],env_stab); + } + } + + return; +} diff --git a/src/libs/libevs/lib_com/env_adj_fx.cpp b/src/libs/libevs/lib_com/env_adj_fx.cpp deleted file mode 100755 index e557ef7c..00000000 --- a/src/libs/libevs/lib_com/env_adj_fx.cpp +++ /dev/null @@ -1,158 +0,0 @@ -/*==================================================================================== - EVS Codec 3GPP TS26.442 Apr 03, 2018. Version 12.11.0 / 13.6.0 / 14.2.0 - ====================================================================================*/ - -#include "options.h" /* Compilation switches */ -#include "cnst_fx.h" /* Common constants */ -#include "rom_com_fx.h" /* Static table prototypes */ -#include "prot_fx.h" /* Function prototypes */ -#include "stl.h" /* required by wmc_tool */ - -/*--------------------------------------------------------------------------* - * env_adj() - * - * Adjust the band energies of noise-fill and low resolution bands - *--------------------------------------------------------------------------*/ -void env_adj_fx -( - const Word16 *pulses, /* i : number of pulses per band Q0 */ - const Word16 length, /* i : length of spectrum Q0 */ - const Word16 last_sfm, /* i : index of the last band Q0 */ - Word16 *adj, /* o : adjustment factors for the envelope Q15 */ - const Word16 env_stab, /* i : envelope stability Q15 */ - const Word16 *sfmsize /* i : subband sizes Q0 */ -) -{ - Word16 i, j, group; - Word16 npul; - Word16 att_state; - Word16 start, len; - Word16 tmp, tmp_diff; - Word16 gain_adj; - Word16 idx; - - att_state = 0; - move16(); - len = 0; - move16(); - start = 0; - move16(); - - /* Find attenuation levels */ - FOR( i = 0; i <= last_sfm ; i++ ) - { - group = sub(shr(sfmsize[i],3),1); - npul = pulses[i]; - move16(); - - IF( sub(length, L_FRAME32k) == 0 ) - { - - IF( npul == 0 ) - { - /* Noise filled band */ - IF ( sub(group,1) <= 0 ) - { - test(); - test(); - test(); - test(); - IF ( i > 0 && pulses[i-1] != 0 && pulses[i+1] != 0 ) - { - adj[i] = 11796; /* Q15, 0.36f */ move16(); - } - ELSE IF ( i > 0 && ( pulses[i-1] == 0 || pulses[i+1] == 0) ) - { - adj[i] = 17695; /* Q15, 0.54f */ move16(); - } - ELSE - { - adj[i] = 23593; /* Q15, 0.72f */ move16(); - } - } - ELSE IF ( sub(i,last_sfm) < 0 ) - { - test(); - IF ( pulses[i-1] != 0 && pulses[i+1] != 0 ) - { - adj[i] = 17695; /* Q15, 0.54f */ move16(); - } - ELSE - { - adj[i] = 23593; /* Q15, 0.72f */ move16(); - } - } - ELSE - { - adj[i] = 23593; /* Q15, 0.72f */ move16(); - } - - if( att_state == 0 ) - { - start = i; - move16(); - } - - len = add(len,1); - move16(); - att_state = 1; - move16(); - } - ELSE - { - adj[i] = MAX_16; /* Q15, 1.0f (saturated) */ - IF( sub(att_state, 1) == 0 ) /* End of attenuation region found */ - { - /* tmp = min(1, max(0, len-ENV_ADJ_START)*(1.0f/ENV_ADJ_INCL)); */ - tmp = round_fx(L_shl(L_mult0(s_max( 0, sub(len, ENV_ADJ_START_FX)), ENV_ADJ_INV_INCL_FX),16)); /* Q15 (15+16-16) */ - tmp_diff = sub(MAX_16, tmp); /* Q15 */ move16(); - FOR( j = start; j < i ; j++ ) - { - /* adj[j] = max(tmp + (1-tmp)*adj[j],env_stab); */ - adj[j] = s_max(add(tmp, mult(tmp_diff, adj[j])), env_stab); /* Q15 (15+15-15) */ move16(); - } - len = 0; - move16(); - att_state = 0; - move16(); - } - } - } - /* length == L_FRAME16k */ - ELSE - { - - /* Calculate low accuracy band attenuation */ - gain_adj = 32767; /* Q15, 1.0f (saturated) */ move16(); - - test(); - IF( npul > 0 && sub(npul, MAX_P_ATT) < 0 ) - { - /*idx = (short)(npul * att_step[group] + 0.5f) - 1; */ - idx = sub(mult_r(shl(npul,2),att_step_fx[group]), 1); /* Q0 (2+13+1-16) */ - if( sub(idx, MAX_P_ATT) < 0 ) - { - gain_adj = gain_att_fx[idx]; /* Q15 */ move16(); - } - } - adj[i] = gain_adj; - move16(); - } - } - - /* Check if the sequence ended with an attenuation region */ - IF( sub(att_state, 1) == 0 ) - { - /* tmp = min(1, max(0, len-ENV_ADJ_START)*(1.0f/ENV_ADJ_INCL)); */ - tmp = round_fx(L_shl(L_mult0(s_max( 0, sub(len, ENV_ADJ_START_FX)), ENV_ADJ_INV_INCL_FX),16)); /* Q15 (15+16-16) */ - tmp_diff = sub(MAX_16, tmp); /* Q15 */ move16(); - FOR( j = start; j < i ; j++ ) - { - - /* adj[j] = max(tmp + (1-tmp)*adj[j],env_stab); */ - adj[j] = s_max(add(tmp, mult(tmp_diff, adj[j])), env_stab); /* Q15 (15+15-15) */ move16(); - } - } - - return; -} diff --git a/src/libs/libevs/lib_com/env_stab_fx.cpp b/src/libs/libevs/lib_com/env_stab.cpp old mode 100755 new mode 100644 similarity index 51% rename from src/libs/libevs/lib_com/env_stab_fx.cpp rename to src/libs/libevs/lib_com/env_stab.cpp index 2d536f32..57bd43fb --- a/src/libs/libevs/lib_com/env_stab_fx.cpp +++ b/src/libs/libevs/lib_com/env_stab.cpp @@ -1,30 +1,31 @@ /*==================================================================================== - EVS Codec 3GPP TS26.442 Apr 03, 2018. Version 12.11.0 / 13.6.0 / 14.2.0 + EVS Codec 3GPP TS26.443 Nov 13, 2018. Version 12.11.0 / 13.7.0 / 14.3.0 / 15.1.0 ====================================================================================*/ -#include "options.h" /* Compilation switches */ -#include "cnst_fx.h" /* Common constants */ -#include "prot_fx.h" /* Function prototypes */ -#include "rom_com_fx.h" /* Static table prototypes */ -#include "stl.h" /* required by wmc_tool */ +#include "options.h" +#include "cnst.h" +#include "prot.h" +#include "rom_com.h" +#include /*--------------------------------------------------------------------------* * Local constants *--------------------------------------------------------------------------*/ + #define ENV_STAB_SMO_HO 10 /* number of hangover frames when switching from music to speech state */ /*--------------------------------------------------------------------------*/ -/* Function env_stability_fx */ -/* ~~~~~~~~~~~~~~~~~~~~~ */ +/* Function env_stability() */ +/* ~~~~~~~~~~~~~~~~~~~~~~~~~ */ /* */ /* Envelope stability measure */ /*--------------------------------------------------------------------------*/ -Word16 env_stability_fx( /* in Q15 */ - const Word16 *ynrm, /*i: Norm vector for current frame */ - const Word16 nb_sfm, /*i: Number of sub-bands */ - Word16 *mem_norm, /*i/o: Norm vector memory from past frame */ - Word16 *mem_env_delta /*i/o: Envelope stability memory for smoothing in Q12 */ +float env_stability( + const short *ynrm, /*i : Norm vector for current frame */ + const short nb_sfm, /*i : Number of sub-bands */ + short *mem_norm, /*i/o: Norm vector memory from past frame */ + float *mem_env_delta /*i/o: Envelope stability memory for smoothing*/ ) { Word16 env_delta; @@ -35,21 +36,21 @@ Word16 env_stability_fx( /* in Q15 */ Word16 exp, exp2; Word32 L_tmp, L_env_delta; Word16 inv_nb_sfm; + float env_stab_f; /* Calculate envelope stability parameter */ L_env_delta = L_deposit_l(0); - FOR (i = 0; i < nb_sfm; i++) + for (i = 0; i < nb_sfm; i++) { tmp = sub(mem_norm[i],ynrm[i]); L_env_delta = L_mac0(L_env_delta, tmp, tmp); mem_norm[i] = ynrm[i]; - move16(); } - inv_nb_sfm = 19418; /* Q19 */ move16(); + inv_nb_sfm = 19418; /* Q19 */ if (nb_sfm == 26) { - inv_nb_sfm = 20165; /* Q19 */ move16(); + inv_nb_sfm = 20165; /* Q19 */ } exp = norm_l(L_env_delta); L_env_delta = Mult_32_16(L_shl(L_env_delta, exp), inv_nb_sfm); /* 0+exp+19-15 */ @@ -70,12 +71,13 @@ Word16 env_stability_fx( /* in Q15 */ *mem_env_delta = round_fx(L_tmp); /* Q12 */ Overflow = 0; - move16(); env_delta = round_fx(L_shl(L_tmp, 1)); /* Q13 */ - IF (Overflow != 0) /* Saturated due to the above up-shifting operation. */ + if (Overflow != 0) /* Saturated due to the above up-shifting operation. */ { - return stab_trans_fx[L_STAB_TBL-1]; /* The highest quantized index. */ + env_stab = stab_trans_fx[L_STAB_TBL-1]; /* The highest quantized index. */ + env_stab_f = ((float)env_stab)/32768.0f; /* Convert env_stab(Q15) to float */ + return env_stab_f; } /* If tmp_stab > (D_STAB_TBL*L_STAB_TBL + M_STAB_TBL), i.e., 0.103138*10+2.51757=3.603137, @@ -91,26 +93,27 @@ Word16 env_stability_fx( /* in Q15 */ #error env_stability_fx: Use more efficient usquant() #endif tmp_stab = sub(tmp_stab, HALF_D_STAB_TBL_FX); /* in Q13 */ - FOR (i = 0; i < L_STAB_TBL-1; i++) + for (i = 0; i < L_STAB_TBL-1; i++) { - IF (tmp_stab < 0) + if (tmp_stab < 0) { - BREAK; + break; } - ELSE + else { tmp_stab = sub(tmp_stab, D_STAB_TBL_FX); /* in Q13 */ } } env_stab = stab_trans_fx[i]; - move16(); if(sub(env_delta, M_STAB_TBL_FX) < 0) { env_stab = sub(0x7FFF,stab_trans_fx[i]); } - return env_stab; + env_stab_f = ((float)env_stab)/32768.0f; /* Convert env_stab(Q15) to float */ + + return env_stab_f; } /*--------------------------------------------------------------------------* @@ -118,70 +121,47 @@ Word16 env_stability_fx( /* in Q15 */ * * *--------------------------------------------------------------------------*/ -Word16 env_stab_smo_fx( /* Q0 */ - Word16 env_stab, /*i : env_stab value Q15 */ - Word16 *env_stab_state_p, /*i/o: env_stab state probabilities Q15 */ - Word16 *ho_cnt /*i/o: hangover counter for speech state */ + +float env_stab_smo( + float env_stab, /*i : env_stab value */ + float *env_stab_state_p, /*i/o: env_stab state probabilities */ + short *ho_cnt /*i/o: hangover counter for speech state */ ) { - Word16 state, prev_state; - Word16 maxval, pp[NUM_ENV_STAB_PLC_STATES], pa[NUM_ENV_STAB_PLC_STATES]; - Word16 i; - Word16 tmp, sum, exp; - + short state, prev_state; + float maxval, pp[NUM_ENV_STAB_PLC_STATES], pa[NUM_ENV_STAB_PLC_STATES]; /* get previous state */ - prev_state = maximum_fx(env_stab_state_p, NUM_ENV_STAB_PLC_STATES, &maxval); + prev_state = maximum(env_stab_state_p,NUM_ENV_STAB_PLC_STATES,&maxval); /* assume two states: speech(0), music(1) */ /* set a posteriori likelihoods for the two states according to env_stab */ - /* re-scale. Unclear if needed */ - /* env_stab = (env_stab - stab_trans_fx[L_STAB_TBL-1])/(1-2*stab_trans_fx[L_STAB_TBL-1]); */ - tmp = sub(env_stab, stab_trans_fx[L_STAB_TBL-1]); - tmp = round_fx(L_shl(L_mult(tmp, INV_STAB_TRANS_FX), 1)); /* Q15 */ - - pp[0] = sub(32767, tmp); - move16(); /* 1 in Q15 */ - pp[1] = tmp; - move16(); + env_stab = (env_stab - stab_trans[L_STAB_TBL-1])/(1-2*stab_trans[L_STAB_TBL-1]); + pp[0] = 1.0f-env_stab; + pp[1] = env_stab; /* calculate a priori likelihoods */ - pa[0] = round_fx(Dot_product(env_stab_tp_fx[0], env_stab_state_p, NUM_ENV_STAB_PLC_STATES)); /* Q15*/ - pa[1] = round_fx(Dot_product(env_stab_tp_fx[1], env_stab_state_p, NUM_ENV_STAB_PLC_STATES)); + pa[0] = dotp(env_stab_tp[0],env_stab_state_p,NUM_ENV_STAB_PLC_STATES); + pa[1] = dotp(env_stab_tp[1],env_stab_state_p,NUM_ENV_STAB_PLC_STATES); /* multiply elementwise with a posteriori likelihoods */ - sum = 0; - move16(); - FOR (i = 0; i < NUM_ENV_STAB_PLC_STATES; i++) - { - env_stab_state_p[i] = mult_r(pa[i], pp[i]); - move16(); /* Q15 */ - sum = add(sum, env_stab_state_p[i]); - } + v_mult(pa,pp,env_stab_state_p,NUM_ENV_STAB_PLC_STATES); /* renormalize state probabilities */ - exp = norm_s(sum); - tmp = div_s(16384, shl(sum, exp)); /* Q(14-exp) */ - /*tmp = shl(tmp, add(exp, 1));*/ /* Q15 */ - FOR (i = 0; i < NUM_ENV_STAB_PLC_STATES; i++) - { - env_stab_state_p[i] = round_fx(L_shl(L_mult(env_stab_state_p[i], tmp), add(exp, 1))); /* Q15 */ - } + v_multc(env_stab_state_p,1.0f/sum_f(env_stab_state_p,NUM_ENV_STAB_PLC_STATES),env_stab_state_p,NUM_ENV_STAB_PLC_STATES); /* find maximum index as return value */ - state = maximum_fx(env_stab_state_p, NUM_ENV_STAB_PLC_STATES, &maxval); + state = maximum(env_stab_state_p,NUM_ENV_STAB_PLC_STATES,&maxval); /* apply some hangover for speech */ - test(); - if (state == 0 && sub(prev_state, 1) == 0) + if (state==0 && prev_state==1) { - *ho_cnt = ENV_STAB_SMO_HO; - move16(); + *ho_cnt=ENV_STAB_SMO_HO; } - - IF (*ho_cnt > 0) + if (*ho_cnt>0) { - *ho_cnt = sub(*ho_cnt, 1); - move16(); + pp[0]=1; + pp[1]=0; + (*ho_cnt)--; } return state; diff --git a/src/libs/libevs/lib_com/env_stab_trans.cpp b/src/libs/libevs/lib_com/env_stab_trans.cpp new file mode 100644 index 00000000..875d97cd --- /dev/null +++ b/src/libs/libevs/lib_com/env_stab_trans.cpp @@ -0,0 +1,123 @@ +/*==================================================================================== + EVS Codec 3GPP TS26.443 Nov 13, 2018. Version 12.11.0 / 13.7.0 / 14.3.0 / 15.1.0 + ====================================================================================*/ + +#include "options.h" +#include "cnst.h" +#include "prot.h" +#include "rom_com.h" +#include + + +/*--------------------------------------------------------------------------* + * env_stab_transient_detect() + * + * Transient detector for envelope stability measure + *--------------------------------------------------------------------------*/ + +void env_stab_transient_detect( + const short is_transient, /* i: Transient flag */ + const short length, /* i : Length of spectrum (32 or 48 kHz) */ + const short norm[], /* i : quantization indices for norms */ + short *no_att_hangover, /* i/o: Frame counter for attenuation hangover */ + float *energy_lt, /* i/o: Long-term energy measure for transient detection */ + const short HQ_mode, /* i : HQ coding mode */ + const short bin_th, /* i : HVQ cross-over frequency bin */ + const float *coeff /* i : Coded spectral coefficients */ +) +{ + float d_max; + float e_frame; + short blk; + short i; + float E_sub[4]; + float delta_e_sub; + short norm_ind; + + short num_subframes = 4; + short bands_per_subframe = 9; + + if( HQ_mode == HQ_HVQ ) + { + e_frame = 0.0f; + + for (i = 0; i < bin_th; i++) + { + e_frame += coeff[i]*coeff[i]; + } + + e_frame = (float)sqrt(e_frame / bin_th); + + if (e_frame > ENERGY_TH) + { + *energy_lt = ENERGY_LT_BETA*(*energy_lt) + (1-ENERGY_LT_BETA)*e_frame; + } + + if (*no_att_hangover > 0) + { + (*no_att_hangover)--; + } + } + else + { + d_max = 0.0f; + e_frame = 0.0f; + if (is_transient && length == L_FRAME32k) + { + /* Measure subframe energies */ + for (blk = 0; blk < num_subframes; blk++) + { + E_sub[blk] = 0.0f; + for (i=0; i ENERGY_TH * num_subframes) + { + for (blk = 0; blk < num_subframes-1; blk++) + { + delta_e_sub = (E_sub[blk+1]-E_sub[blk]) / *energy_lt; + if (delta_e_sub > d_max) + { + d_max = delta_e_sub; + } + } + } + } + else + { + /* Update long-term energy measure */ + e_frame = 0.0f; + + for (i = 0; i < SFM_N_ENV_STAB; i++) + { + e_frame += dicn[norm[i]]; + } + + e_frame = e_frame / SFM_N_ENV_STAB; + + if (e_frame > ENERGY_TH) + { + *energy_lt = ENERGY_LT_BETA*(*energy_lt) + (1-ENERGY_LT_BETA)*e_frame; + } + } + + /* Add hang-over for conservative application of stability-dependent attenuation */ + if(d_max > DELTA_TH) + { + *no_att_hangover = ATT_LIM_HANGOVER; + } + else if (*no_att_hangover > 0) + { + (*no_att_hangover)--; + } + + } + + return; +} diff --git a/src/libs/libevs/lib_com/env_stab_trans_fx.cpp b/src/libs/libevs/lib_com/env_stab_trans_fx.cpp deleted file mode 100755 index 393d222f..00000000 --- a/src/libs/libevs/lib_com/env_stab_trans_fx.cpp +++ /dev/null @@ -1,160 +0,0 @@ -/*==================================================================================== - EVS Codec 3GPP TS26.442 Apr 03, 2018. Version 12.11.0 / 13.6.0 / 14.2.0 - ====================================================================================*/ - -#include "options.h" /* Compilation switches */ -#include "cnst_fx.h" /* Common constants */ -#include "prot_fx.h" /* Function prototypes */ -#include "rom_com_fx.h" /* Static table prototypes */ -#include "math_op.h" /* WMOPS macros */ -#include "stl.h" /* required by wmc_tool */ - -/*--------------------------------------------------------------------------* - * env_stab_transient_detect() - * - * Transient detector for envelope stability measure - *--------------------------------------------------------------------------*/ - -void env_stab_transient_detect_fx( - const Word16 is_transient, /* i: Transient flag */ - const Word16 length, /* i : Length of spectrum (32 or 48 kHz) */ - const Word16 norm[], /* i : quantization indices for norms */ - Word16 *no_att_hangover, /* i/o: Frame counter for attenuation hangover (Q0) */ - Word32 *L_energy_lt, /* i/o: Long-term energy measure for transient detection (Q13) */ - const Word16 HQ_mode, /* i : HQ coding mode */ - const Word16 bin_th, /* i : HVQ cross-over frequency bin */ - const Word32 *L_coeff, /* i : Coded spectral coefficients */ - const Word16 Qcoeff /* i : Q of coded spectral coefficients */ -) -{ - Word16 i, blk, norm_ind, sqrt_exp, bin_th_1, temp, sh; - Word32 L_e_frame, L_temp, L_d_max; - Word32 L_energy_lt_local; - Word32 L_E_sub[4]; - Word32 L_delta_e_sub; - - L_energy_lt_local = *L_energy_lt; - move32(); - - L_d_max = L_deposit_l(0); - L_e_frame = L_deposit_l(0); - temp = 32; - move16(); - - IF( sub(HQ_mode,HQ_HVQ) == 0 ) - { - FOR (i = 0; i < bin_th; i++) /* find adaptive shift */ - { - temp = s_min(temp,norm_l(L_coeff[i])); - } - sh = sub(temp,2); /* scale such that 2 msbs are not used, the resulting adaptive Qcoeff will be: Qcoeff+sh-16 */ - FOR (i = 0; i < bin_th; i++) /* Maximum number of loop runs 320 */ - { - temp = extract_h(L_shl(L_coeff[i],sh)); - L_e_frame = L_mac(L_e_frame,temp,temp); /* Q(2*(Qcoeff+sh-16)+1)=Q(2*(Qcoeff+sh)-31 */ - } - - bin_th_1 = INV_HVQ_THRES_BIN_24k; - move16(); - if (sub(bin_th, HVQ_THRES_BIN_32k) == 0) - { - bin_th_1 = INV_HVQ_THRES_BIN_32k; - move16(); - } - L_temp = Mult_32_16(L_e_frame,bin_th_1); /* Q(2*(Qcoeff-16+sh)+1+21-15) -> Q(2*(Qcoeff+sh)-25) */ - L_e_frame = Sqrt_l(L_temp,&sqrt_exp); - L_e_frame = L_shr(L_e_frame, add(sub(add(sh,Qcoeff),10),shr(sqrt_exp,1))); /* Adjust by (Qcoeff+sh-10) to fixed Q13: Qcoeff+sh+(-25+31)/2 - (Qcoeff+sh-10) -> Q13 */ - - IF ( L_sub(L_e_frame, ENERGY_TH_FX) > 0 ) - { - L_energy_lt_local = Mult_32_16(*L_energy_lt, ENERGY_LT_BETA_FX); - L_temp = Mult_32_16(L_e_frame, ENERGY_LT_BETA_1_FX); - *L_energy_lt = L_add(L_energy_lt_local,L_temp); - move32(); - } - - IF (*no_att_hangover > 0) - { - (*no_att_hangover) = sub((*no_att_hangover), 1); - move16(); - } - } - ELSE - { - L_e_frame = L_deposit_l(0); - - test(); - IF (is_transient && sub(length,L_FRAME32k) == 0) - { - /* Measure subframe energies */ - FOR (blk = 0; blk < NUM_SUBFRAMES; blk++) - { - L_E_sub[blk] = L_deposit_l(0); /* Q9 */ - - FOR (i=0; i < 2^4 */ - { - norm_ind = subf_norm_groups_fx[blk][i]; - move16(); - L_E_sub[blk] = L_add(L_E_sub[blk],L_shr(dicn_fx[norm[norm_ind]],4)); - move32(); ; /* Q10 */ - } - - L_E_sub[blk] = Mult_32_16(L_E_sub[blk], INV_BANDS_PER_SUBFRAMES); - move32(); /* Q(10+17-15) -> Q12 */ - - L_e_frame = L_add(L_e_frame,L_E_sub[blk]); /* Q12 */ - } - - /* Test for transient */ - /* if (e_frame > ENERGY_TH * NUM_SUBFRAMES) */ - IF (L_sub(L_e_frame, ENERGY_TH_NUM_SUBFRAMES) > 0) - { - FOR (blk = 0; blk < NUM_SUBFRAMES-1; blk++) - { - L_delta_e_sub = L_sub(L_E_sub[blk+1],L_E_sub[blk]); /* Q12 */ - if (L_sub(L_delta_e_sub,L_d_max)>0) - { - L_d_max = L_add(L_delta_e_sub,0); /* L_d_max is NOT normalized with *energy_lt */ - } - } - } - } - ELSE - { - /* Update long-term energy measure */ - L_e_frame = L_deposit_l(0); /* Q9 */ - FOR (i = 0; i < SFM_N_ENV_STAB; i++) /* 27 times -> < 2^5 */ - { - L_e_frame = L_add(L_e_frame,L_shr(dicn_fx[norm[i]],5)); - /* Q9 */ - } - - L_e_frame = Mult_32_16(L_e_frame, INV_SFM_N_ENV_STAB); /* Q(9+19-15) -> Q13 */ - - IF ( L_sub(L_e_frame, ENERGY_TH_FX) > 0 ) - { - L_energy_lt_local = Mult_32_16(*L_energy_lt, ENERGY_LT_BETA_FX); - L_temp = Mult_32_16(L_e_frame, ENERGY_LT_BETA_1_FX); - *L_energy_lt = L_add(L_energy_lt_local,L_temp); - move32(); - } - } - - /* Add hang-over for conservative application of stability dependent attenuation */ - /* -> Note: L_d_max not normalized with *energy_lt */ - /* Hence, we compare L_d_max/DELTA_TH with *energy_lt */ - IF (L_sub(Mult_32_16(L_d_max, INV_DELTA_TH),L_energy_lt_local) > 0) /* Q13 = Q(12 + 16 -15) */ - { - *no_att_hangover = ATT_LIM_HANGOVER; - move16(); - } - ELSE if (*no_att_hangover > 0) - { - *no_att_hangover = sub(*no_att_hangover,1); - move16(); - } - } - - return; -} - diff --git a/src/libs/libevs/lib_com/est_tilt.cpp b/src/libs/libevs/lib_com/est_tilt.cpp new file mode 100644 index 00000000..da6759d0 --- /dev/null +++ b/src/libs/libevs/lib_com/est_tilt.cpp @@ -0,0 +1,57 @@ +/*==================================================================================== + EVS Codec 3GPP TS26.443 Nov 13, 2018. Version 12.11.0 / 13.7.0 / 14.3.0 / 15.1.0 + ====================================================================================*/ + +#include "options.h" +#include "cnst.h" +#include "prot.h" + + +/*-------------------------------------------------------------------* + * est_tilt() + * + * Estimate spectral tilt based on the relative E of adaptive + * and innovative excitations + *-------------------------------------------------------------------*/ + +float est_tilt( /* o : tilt of the code */ + const float *adpt_exc, /* i : adaptive excitation vector */ + const float gain_pit, /* i : adaptive gain */ + const float *fixe_exc, /* i : algebraic exctitation vector */ + const float gain_code, /* i : algebraic code gain */ + float *voice_fac, /* o : voicing factor */ + const short L_subfr, /* i : subframe size */ + const short flag_tilt /* i : flag for special tilt */ +) +{ + float ener, tmp, tilt_code; + + ener = dotp( adpt_exc, adpt_exc, L_subfr ); + ener *= gain_pit * gain_pit; /* energy of pitch excitation */ + + tmp = dotp( fixe_exc, fixe_exc, L_subfr ); + tmp *= gain_code * gain_code; /* energy of innovative code excitation */ + + /* find voice factor (1=voiced, -1=unvoiced) */ + *voice_fac = (float)((ener - tmp) / (ener + tmp + 0.01f)); + + /* find tilt of code for next subframe */ + if (flag_tilt==0) + { + /*Between 0 (=unvoiced) and 0.5 (=voiced)*/ + tilt_code = (float)(0.25f*(1.0f + *voice_fac)); + } + else if (flag_tilt==1) + { + /*Between 0.25 (=unvoiced) and 0.5 (=voiced)*/ + tilt_code = (float)(0.25f + (*voice_fac+1.0f)*0.125f); + } + else + { + /*Between 0.28 (=unvoiced) and 0.56 (=voiced)*/ + tilt_code = (float)(0.28f + (*voice_fac+1.0f)*0.14f); + } + + return tilt_code; +} + diff --git a/src/libs/libevs/lib_com/est_tilt_fx.cpp b/src/libs/libevs/lib_com/est_tilt_fx.cpp deleted file mode 100755 index a389e3b2..00000000 --- a/src/libs/libevs/lib_com/est_tilt_fx.cpp +++ /dev/null @@ -1,265 +0,0 @@ -/*==================================================================================== - EVS Codec 3GPP TS26.442 Apr 03, 2018. Version 12.11.0 / 13.6.0 / 14.2.0 - ====================================================================================*/ - -#include "options.h" /* Compilation switches */ -#include "cnst_fx.h" /* Common constants */ -#include "prot_fx.h" /* Function prototypes */ -#include "stl.h" -#include "basop_mpy.h" -#include "basop_util.h" - - -/*======================================================================*/ -/* FUNCTION : est_tilt_fx() */ -/*-----------------------------------------------------------------------*/ -/* PURPOSE : Estimate spectral tilt based on the relative E of adaptive */ -/* and innovative excitations */ -/* */ -/*-----------------------------------------------------------------------*/ -/* INPUT ARGUMENTS : */ -/* _ (Word16 *) exc : adaptive excitation vector Q0 */ -/* _ (Word16) gain_pit : adaptive gain Q14 */ -/* _ (Word16 *) code : algebraic exctitation vector Q12 */ -/* _ (Word32) gain_code : algebraic code gain Q16 */ -/* _ (Word16) Q_exc : Scaling factor of excitation Q0 */ -/*-----------------------------------------------------------------------*/ -/* OUTPUT ARGUMENTS : */ -/* _ (Word16 *) voice_fac : voicing factor Q15 */ -/*-----------------------------------------------------------------------*/ -/* INPUT OUTPUT ARGUMENTS */ -/*-----------------------------------------------------------------------*/ - -/*-----------------------------------------------------------------------*/ -/* RETURN ARGUMENTS : */ -/* _ (Word16) tolt_code : tilt of the code Q15 */ -/*=======================================================================*/ -Word16 est_tilt_fx( /* o : tilt of the code Q15 */ - const Word16 *exc, /* i : adaptive excitation vector Qx */ - const Word16 gain_pit, /* i : adaptive gain Q14 */ - const Word16 *code, /* i : algebraic exctitation vector Q9 */ - const Word32 gain_code, /* i : algebraic code gain Q16 */ - Word16 *voice_fac, /* o : voicing factor Q15 */ - const Word16 Q_exc /* i : Scaling factor of excitation Q0 */ -) -{ - Word16 i, tmp, exp, ener1, exp1, ener2, exp2; - Word32 L_tmp; - Word16 tilt_code; - - ener1 = extract_h(Dot_product12(exc, exc, L_SUBFR, &exp1)); - exp1 = sub(exp1, add(Q_exc, Q_exc)); - L_tmp = L_mult(gain_pit, gain_pit); /* energy of pitch excitation */ - exp = norm_l(L_tmp); - tmp = extract_h(L_shl(L_tmp, exp)); - ener1 = mult(ener1, tmp); - exp1 = sub(sub(exp1, exp), 10); /* 10 -> gain_pit Q14 to Q9 */ - - ener2 = extract_h(Dot_product12(code, code, L_SUBFR, &exp2)); - - exp = norm_l(gain_code); - tmp = extract_h(L_shl(gain_code, exp)); - tmp = mult(tmp, tmp); /* energy of innovative code excitation */ - ener2 = mult(ener2, tmp); - exp2 = sub(exp2, add(exp, exp)); - - i = sub(exp1, exp2); - BASOP_SATURATE_WARNING_OFF - ener1 = shr(ener1, sub(1, s_min(i, 0))); - ener2 = shr(ener2, add(s_max(0, i), 1)); - BASOP_SATURATE_WARNING_ON - tmp = sub(ener1, ener2); - ener1 = add(add(ener1, ener2), 1); - - /* find voice factor (1=voiced, -1=unvoiced) */ - exp = div_s(abs_s(tmp), ener1); - if (tmp < 0) - { - exp = negate(exp); - } - *voice_fac = exp; - move16(); - - /* tilt of code for next subframe: 0.5=voiced, 0=unvoiced */ - - /* tilt_code = (float)(0.25*(1.0 + *voice_fac)) */ - tilt_code = mac_r(8192L*65536-0x8000, *voice_fac, 8192); /*Q15 */ - - return tilt_code; -} -/*-------------------------------------------------------------------* - * Est_tilt2: - * - * Estimate spectral tilt based on the relative E of adaptive - * and innovative excitations - *-------------------------------------------------------------------*/ -Word16 Est_tilt2( /* o : tilt of the code */ - const Word16 *exc, /* i : adaptive excitation vector Qx */ - const Word16 gain_pit, /* i : adaptive gain Q14 */ - const Word16 *code, /* i : algebraic exctitation vector Q9 */ - const Word32 gain_code, /* i : algebraic code gain Q16 */ - Word16 *voice_fac, /* o : voicing factor Q15 */ - const Word16 Q_exc /* i : Scaling factor of excitation Q0 */ -) -{ - Word16 i, tmp, exp, ener1, exp1, ener2, exp2; - Word32 L_tmp; - Word16 tilt_code; - - /* Scale exc to avoid overflow */ - ener1 = extract_h(Energy_scale(exc, L_SUBFR, Q_exc, &exp1)); - - exp1 = sub(exp1, add(Q_exc, Q_exc)); - L_tmp = L_mult(gain_pit, gain_pit); /* energy of pitch excitation */ - exp = norm_l(L_tmp); - tmp = extract_h(L_shl(L_tmp, exp)); - ener1 = mult(ener1, tmp); - exp1 = sub(sub(exp1, exp), 10); /* 10 -> gain_pit Q14 to Q9 */ - - ener2 = extract_h(Dot_product12(code, code, L_SUBFR, &exp2)); - - exp = norm_l(gain_code); - tmp = extract_h(L_shl(gain_code, exp)); - tmp = mult(tmp, tmp); /* energy of innovative code excitation */ - ener2 = mult(ener2, tmp); - exp2 = sub(exp2, add(exp, exp)); - - i = sub(exp1, exp2); - ener1 = shr(ener1, sub(1, s_min(i, 0))); - ener2 = shr(ener2, add(s_max(0, i), 1)); - - tmp = sub(ener1, ener2); - ener1 = add(add(ener1, ener2), 1); - - /* find voice factor (1=voiced, -1=unvoiced) */ - exp = div_s(abs_s(tmp), ener1); - if (tmp < 0) - { - exp = negate(exp); - } - *voice_fac = exp; - move16(); - - /* tilt of code for next subframe: 0.5=voiced, 0=unvoiced */ - - /* tilt_code = (float)(0.25*(1.0 + *voice_fac)) */ - tilt_code = mac_r(8192L*65536-0x8000, *voice_fac, 8192); - - return tilt_code; -} - -/*---------------------------------------------------------* - * Find voice factor and tilt code * - *---------------------------------------------------------*/ -void E_UTIL_voice_factor( Word16 *exc, /* i : pointer to the excitation frame Q_new */ - Word16 i_subfr, /* i : subframe index */ - Word16 *code, /* i : innovative codebook Q9 */ - Word16 gain_pit, /* i : adaptive codebook gain 1Q14 */ - Word32 gain_code, /* i : innovative cb. gain 15Q16 */ - Word16 *voice_fac, /* o : subframe voicing estimation Q15 */ - Word16 *tilt_code, /* o : tilt factor Q15 */ - Word16 L_subfr, /* i : subframe length */ - Word16 flag_tilt, /* i : Flag for triggering new voice factor tilt*/ - Word16 Q_new, /* i : excitation buffer format */ - Word16 shift /* i : scaling to get 12bit */ - ) -{ - Word16 i, e, e2, stmp, exp_ener, fac; - Word32 ener, tmp, num; - - BASOP_SATURATE_ERROR_ON; - - IF(shift != 0) - { - fac = shl(0x4000,add(1,shift)); - /* energy of pitch excitation */ - stmp = mult_r(exc[0+i_subfr], fac); /* remove fac bits */ - ener = L_mac0(0L,stmp, stmp); - FOR (i=1; i exponent = (15-Q_new)*2+1 */ - } - } - - /* exponent of ener: (2*(15-Q_new+shift)+1+2-exp_ener-2*e2) */ - exp_ener = norm_l(ener); - if(ener == 0) - { - exp_ener = 31; - move16(); - } - ener = L_shl(ener,exp_ener); - e2 = norm_s(gain_pit); - gain_pit = shl(gain_pit,e2); - ener = Mpy_32_16_1(ener, mult_r(gain_pit, gain_pit)); - - - /* energy of innovative code excitation */ - tmp = L_deposit_l(1); - - FOR (i=0; i 13Q18 */ - } - /* exponent of tmp: 2*(15-9)+1+2*(15-e)) */ - e = norm_l(gain_code); - gain_code = L_shl(gain_code, e); - tmp = Mpy_32_32(tmp, Mpy_32_32(gain_code,gain_code)); - - /* find voice factor (1=voiced, -1=unvoiced) */ - /*i = (2*(15-Q_new+shift)+1+2-exp_ener-2*e2) - (2*(15-9)+1 + 2*(15-e));*/ - i = sub(sub(sub(sub(sub(33,add(shift,shift)),add(Q_new,Q_new)),exp_ener),add(e2,e2)),sub(43,add(e,e))); - IF(i >= 0) - { - ener = L_shr(ener,1); - tmp = L_shr(tmp, add(1,i)); - } - ELSE - { - tmp = L_shr(tmp,1); - BASOP_SATURATE_WARNING_OFF - ener = L_shr(ener, sub(1,i)); - BASOP_SATURATE_WARNING_ON - } - - *voice_fac = 0; - move16(); - num = L_sub(ener, tmp); - IF(num != 0) - { - BASOP_SATURATE_WARNING_OFF /* Allow saturating the voice factor because if has a limited range by definition. */ - *voice_fac = divide3232(num, L_add(ener, tmp)); - move16(); - BASOP_SATURATE_WARNING_ON - } - - /* find tilt of code for next subframe */ - IF (flag_tilt==0) - { - /*Between 0 (=unvoiced) and 0.5 (=voiced)*/ - move16(); - *tilt_code = add(8192/*0.25f Q15*/, mult_r(8192/*0.25f Q15*/, *voice_fac)); - } - ELSE IF (flag_tilt==1) - { - /*Between 0.25 (=unvoiced) and 0.5 (=voiced)*/ - move16(); - *tilt_code = add(mult_r(4096/*0.125f Q15*/, *voice_fac), 12288/*0.125f+0.25f Q15*/); - } - ELSE - { - /*Between 0.28 (=unvoiced) and 0.56 (=voiced)*/ - move16(); - *tilt_code = add(mult_r(4588/*0.14f Q15*/, *voice_fac), 13763/*0.14f+0.28f Q15*/); - } - BASOP_SATURATE_ERROR_OFF; -} diff --git a/src/libs/libevs/lib_com/fd_cng_com.cpp b/src/libs/libevs/lib_com/fd_cng_com.cpp old mode 100755 new mode 100644 index c72ee995..c41f86e4 --- a/src/libs/libevs/lib_com/fd_cng_com.cpp +++ b/src/libs/libevs/lib_com/fd_cng_com.cpp @@ -1,1809 +1,1074 @@ /*==================================================================================== - EVS Codec 3GPP TS26.442 Apr 03, 2018. Version 12.11.0 / 13.6.0 / 14.2.0 + EVS Codec 3GPP TS26.443 Nov 13, 2018. Version 12.11.0 / 13.7.0 / 14.3.0 / 15.1.0 ====================================================================================*/ #include -#include "stl.h" -#include "basop_util.h" +#include #include "options.h" -#include "stl.h" -#include "rom_basop_util.h" -#include "rom_com_fx.h" -#include "prot_fx.h" - -#define DELTA_SHIFT 2 -#define DELTA_SHIFT_LD64 67108864l/*DELTA_SHIFT/64.0 Q31*/ +#include "prot.h" +#include "rom_com.h" -/***************************************** -* Create an instance of type FD_CNG_COM * -*****************************************/ -void createFdCngCom(HANDLE_FD_CNG_COM * hFdCngCom) +/*------------------------------------------------------------------- + * Local functions + *-------------------------------------------------------------------*/ + +static void mhvals( int d, float * m ); + + +/*------------------------------------------------------------------- + * createFdCngCom() + * + * Create an instance of type FD_CNG_COM + *-------------------------------------------------------------------*/ + +void createFdCngCom( + HANDLE_FD_CNG_COM * hFdCngCom +) { HANDLE_FD_CNG_COM hs; /* Allocate memory */ hs = (HANDLE_FD_CNG_COM) calloc(1, sizeof (FD_CNG_COM)); - move16(); - *hFdCngCom = hs; - move16(); + return; } -void initFdCngCom(HANDLE_FD_CNG_COM hs, Word16 scale) + +/*------------------------------------------------------------------- + * initFdCngCom() + * + * + *-------------------------------------------------------------------*/ + +void initFdCngCom( + HANDLE_FD_CNG_COM hs, /* i/o: Contains the variables related to the FD-based CNG process */ + float scale +) { - /* Calculate CLDFB scaling factor */ - /* shl(i_mult2(scale, scale), 3) does not fit in 16 bit */ - /*hs->scalingFactor = div_s(1, shl(i_mult2(scale, scale), 3));*/ - assert(2048/*1.0/(1<<4) Q15*/ < mult(scale, scale)); - /* Exponent invScalingFactor: -16 = -(2*7 (scale) + 2 (8.0) */ - hs->invScalingFactor = shl(mult(scale,scale),1); - /* Exponent scalingFactor: -15 = -(2*7 (scale) + 2 (8.0) - 1 (1.0)) */ - hs->scalingFactor = div_s(0x4000,hs->invScalingFactor); + + /* Calculate FFT scaling factor */ + hs->scalingFactor = 1 / (scale*scale*8.f); /* Initialize the overlap-add */ - set16_fx( hs->timeDomainBuffer, 0, L_FRAME16k ); - hs->olapBufferAna = NULL; - move16(); - set16_fx( hs->olapBufferSynth, 0, FFTLEN ); - hs->olapBufferSynth2 = NULL; - move16(); + set_f( hs->timeDomainBuffer, 0.0f, L_FRAME16k ); + set_f( hs->olapBufferAna, 0.0f, FFTLEN ); + set_f( hs->olapBufferSynth, 0.0f, FFTLEN ); + set_f( hs->olapBufferSynth2, 0.0f, FFTLEN ); /* Initialize the comfort noise generation */ - set32_fx( hs->fftBuffer, 0, FFTLEN ); - set32_fx( hs->cngNoiseLevel, 0, FFTCLDFBLEN ); + set_f( hs->fftBuffer, 0.0f, FFTLEN ); + set_f( hs->cngNoiseLevel, 0.0f, FFTCLDFBLEN ); /* Initialize quantizer */ - set32_fx( hs->sidNoiseEst, 0, NPART ); - set16_fx( hs->A_cng, 0, M+1 ); - hs->A_cng[0] = 4096/*1.f Q12*/; /* 3Q12 */ move16(); + set_f( hs->sidNoiseEst, 0.0f, NPART ); + set_f( hs->A_cng, 0.0f, M+1 ); + hs->A_cng[0] = 1.f; /* Set some counters and flags */ - hs->inactive_frame_counter = 0; /* Either SID or zero frames */ move16(); + hs->inactive_frame_counter = 0; /* Either SID or zero frames */ hs->active_frame_counter = 0; - move16(); hs->frame_type_previous = ACTIVE_FRAME; - move16(); hs->flag_noisy_speech = 0; - move16(); - hs->likelihood_noisy_speech = 0; - move16(); + hs->likelihood_noisy_speech = 0.f; /* Initialize noise estimation algorithm */ - set32_fx( hs->periodog, 0, PERIODOGLEN ); + set_f( hs->periodog, 0.0f, PERIODOGLEN ); mhvals(MSNUMSUBFR*MSSUBFRLEN, &(hs->msM_win)); mhvals(MSSUBFRLEN, &(hs->msM_subwin)); - set32_fx( hs->msPeriodogSum, 0, 2 ); - hs->msPeriodogSum_exp[0] = 0; - move16(); - hs->msPeriodogSum_exp[1] = 0; - move16(); - set32_fx( hs->msPsdSum, 0, 2 ); - set16_fx( hs->msSlope, 0, 2 ); - set32_fx( hs->msQeqInvAv, 0, 2 ); - hs->msQeqInvAv_exp[0] = 0; - move16(); - hs->msQeqInvAv_exp[1] = 0; - move16(); + set_f( hs->msPeriodogSum, 0.0f, 2 ); + set_f( hs->msPsdSum, 0.0f, 2 ); + set_f( hs->msSlope, 0.0f, 2 ); + set_f( hs->msQeqInvAv, 0.0f, 2 ); hs->msFrCnt_init_counter = 0; - move16(); hs->msFrCnt_init_thresh = 1; - move16(); hs->init_old = 0; - move16(); hs->offsetflag = 0; - move16(); hs->msFrCnt = MSSUBFRLEN; - move16(); hs->msMinBufferPtr = 0; - move16(); - hs->msAlphaCor[0] = 644245120l/*0.3f Q31*/; - move16(); - hs->msAlphaCor[1] = 644245120l/*0.3f Q31*/; - move16(); - - /* Initialize exponents */ - hs->exp_cldfb_periodog = 0; - move16(); + set_f( hs->msAlphaCor, 0.3f, 2 ); return; } -/***************************************** -* Delete an instance of type FD_CNG_COM * -*****************************************/ -void deleteFdCngCom(HANDLE_FD_CNG_COM * hFdCngCom) /* i/o: Contains the variables related to the CLDFB-based CNG process */ + +/*------------------------------------------------------------------- + * deleteFdCngCom() + * + * Delete an instance of type FD_CNG_COM + *-------------------------------------------------------------------*/ + +void deleteFdCngCom( + HANDLE_FD_CNG_COM * hFdCngCom /* i/o: Contains the variables related to the FD-based CNG process */ +) { - HANDLE_FD_CNG_COM hsCom; - hsCom = *hFdCngCom; - move16(); - IF (hsCom != NULL) + HANDLE_FD_CNG_COM hsCom = *hFdCngCom; + if (hsCom != NULL) { free(hsCom); *hFdCngCom = NULL; - move16(); } + + return; } -/*************************************** -* Initialize the spectral partitioning * -****************************************/ -void initPartitions( const Word16* part_in, - Word16 npart_in, - Word16 startBand, - Word16 stopBand, - Word16* part_out, - Word16* npart_out, - Word16* midband, - Word16* psize, - Word16* psize_norm, - Word16* psize_norm_exp, - Word16* psize_inv, - Word16 stopBandFR - ) + +/*------------------------------------------------------------------- + * initPartitions() + * + * Initialize the spectral partitioning + *-------------------------------------------------------------------*/ + +void initPartitions( + const int * part_in, + int npart_in, + int startBand, + int stopBand, + int * part_out, + int * npart_out, + int * midband, + float * psize, + float * psize_inv, + int stopBandFR +) { - Word16 i, j, len_out, tmp16; + int i, j, len_out; - - IF (part_in != NULL) + if (part_in != NULL) { - len_out = 0; - move16(); - IF (sub(stopBandFR, startBand) > 0) + if (stopBandFR > startBand) { - len_out = sub(stopBandFR, startBand); - FOR(i = 0 ; i < len_out; i++) + len_out = stopBandFR - startBand; /*part_out*/ + for(i = 0 ; i < len_out ; i++) { part_out[i] = i; - move16(); } } - FOR(j=0 ; j < npart_in; j++) + else { - IF (sub(part_in[j], stopBand) >= 0) + len_out = 0; + } /*npart_in,part_out*/ + for(j=0 ; j= stopBandFR && part_in[j] >= startBand) { - BREAK; - } - tmp16 = sub(part_in[j],startBand); - test(); - if (sub(part_in[j],stopBandFR) >= 0 && tmp16 >= 0) - { - part_out[len_out++] = tmp16; - move16(); + part_out[len_out++] = part_in[j] - startBand; } } } - ELSE + else { - len_out = sub(stopBand, startBand); - FOR (i = 0 ; i < len_out; i++) + len_out = stopBand - startBand; /*part_out*/ + for (i = 0 ; i < len_out ; i++) { part_out[i] = i; - move16(); } } - *npart_out = len_out; - move16(); - getmidbands(part_out, len_out, midband, psize, psize_norm, psize_norm_exp, psize_inv); + getmidbands(part_out, len_out, midband, psize, psize_inv); + return; } -#define CNG_HS 4 /* 4 bit headroom for dot product */ -#define CNG_S 6 /* 1 sign bit, 6 bit integer part, 9 bit frational part for input and output data */ +/*------------------------------------------------------------------- + * compress_range() + * + * Apply some dynamic range compression based on the log + *-------------------------------------------------------------------*/ - - -/******************************************************** -* Apply some dynamic range compression based on the log * -********************************************************/ void compress_range( - Word32 *in, - Word16 in_exp, - Word16 *out, - Word16 len + float* in, + float* out, + int len ) { - Word16 i; - Word32 in_s; - Word32 one_s; - Word32 in_exp32; - Word32 L_tmp; - + float* ptrIn = in; + float* ptrOut = out; + int i; /* out = log2( 1 + in ) */ - IF ( in_exp >= 0 ) + for(i = 0 ; i < len ; i++) { - one_s = L_shr(1073741824l/*0.5 Q31*/,in_exp); - in_exp32 = L_shl(L_deposit_l(add(in_exp,1)),WORD32_BITS-1-LD_DATA_SCALE); - FOR (i=0; i < len; i++) - { - in_s = L_add(L_shr(in[i],1),one_s); - L_tmp = L_add(BASOP_Util_Log2(in_s),in_exp32); - if (in_s == 0) - { - out[i] = 0; - move16(); - } - if (in_s != 0) - { - out[i] = extract_h(L_tmp); - } - if(out[i] == 0) - { - out[i] = 1; - } - } - } - ELSE - { - in_exp = sub(in_exp,1); - in_exp32 = L_shl(L_deposit_l(1),WORD32_BITS-1-LD_DATA_SCALE); - FOR (i=0; i < len; i++) - { - L_tmp = L_add(BASOP_Util_Log2(L_add(L_shl(in[i],in_exp),1073741824l/*0.5 Q31*/)),in_exp32); - if (in[i] == 0) - { - out[i] = 0; - move16(); - } - if (in[i] != 0) - { - out[i] = extract_h(L_tmp); - } - if (out[i] == 0) - { - out[i] = 1; - } - } + *ptrOut = (float)log10(*ptrIn + 1.f); + ptrIn++; + ptrOut++; } + v_multc(out, 1.f/(float)log10(2.f), out, len); + /* Quantize to simulate a fixed-point representation 6Q9 */ + v_multc(out, CNG_LOG_SCALING, out, len); + for(ptrOut = out ; ptrOut < out + len ; ptrOut++) + { + *ptrOut = (float)((int)(*ptrOut+0.5f)); + if ( *ptrOut == 0.f ) + { + *ptrOut = 1.f; + } + } + v_multc(out, 1./CNG_LOG_SCALING, out, len); + + return; } -/************************************************************* -* Apply some dynamic range expansion to undo the compression * -*************************************************************/ + +/*------------------------------------------------------------------- + * expand_range() + * + * Apply some dynamic range expansion to undo the compression + *-------------------------------------------------------------------*/ + void expand_range( - Word16 *in, - Word32 *out, - Word16 *out_exp, - Word16 len + float* in, + float* out, + int len ) { - Word16 i; - Word16 s; - Word16 tmp; - Word32 one_s, tmp32; - Word16 maxVal; - Word16 maxVal2; + float* ptrIn = in; + float* ptrOut = out; + int i; - - maxVal = 0; - move16(); - FOR (i=0; i < len; i++) - { - maxVal = s_max(maxVal,in[i]); - } - - maxVal2 = maxVal; - move16(); - s = 0; - move16(); - WHILE ( maxVal >= 0 ) - { - maxVal = sub(maxVal,512/*0.015625 Q15*/); - s = add(s,1); - } - tmp = sub(maxVal2,maxVal); - - one_s = L_shr(1073741824l/*0.5 Q31*/,sub(s,1)); - tmp32 = L_shr(726941l/*0.0003385080526823181 Q31*/,s); /* out = (2^(in) - 1) */ - FOR (i=0; i < len; i++) + for(i = 0 ; i < len ; i++) { - out[i] = L_sub(BASOP_Util_InvLog2(L_deposit_h(sub(in[i],tmp))),one_s); - move32(); - if ( out[i] == 0 ) + *ptrOut = (float)pow(2.f,*ptrIn) - 1.f; + if ( *ptrOut < 0.0003385080526823181f ) { - out[i] = tmp32; - move32(); + *ptrOut = 0.0003385080526823181f; } + ptrIn++; + ptrOut++; } - *out_exp = s; - move16(); + return; } -/************************************************* -* Noise estimation using Minimum Statistics (MS) * -*************************************************/ -void minimum_statistics ( - Word16 len, /* i : Total number of partitions (CLDFB or FFT) */ - Word16 lenFFT, /* i : Number of FFT partitions */ - Word16 *psize, /* i : Partition sizes, fractional */ - Word16 *msPeriodog, /* i : Periodogram (energies) */ - Word16 *msNoiseFloor, /* i/o: Noise floors (energies) */ - Word16 *msNoiseEst, /* i/o: Noise estimates (energies) */ - Word32 *msAlpha, /* i/o: Forgetting factors */ - Word16 *msPsd, /* i/o: Power Spectral Density (smoothed periodogram => energies) */ - Word16 *msPsdFirstMoment, /* i/o: PSD statistics of 1st order (energy means) */ - Word32 *msPsdSecondMoment, /* i/o: PSD statistics of 2nd order (energy variances) */ - Word32 *msMinBuf, /* i/o: Buffer of minima (energies) */ - Word32 *msBminWin, /* o : Bias correction factors */ - Word32 *msBminSubWin, /* o : Bias correction factors */ - Word32 *msCurrentMin, /* i/o: Local minima (energies) */ - Word32 *msCurrentMinOut, /* i/o: Local minima (energies) */ - Word32 *msCurrentMinSubWindow, /* i/o: Local minima (energies) */ - Word16 *msLocalMinFlag, /* i : Binary flag */ - Word16 *msNewMinFlag, /* i : Binary flag */ - Word16 *msPeriodogBuf, /* i/o: Buffer of periodograms (energies) */ - Word16 *msPeriodogBufPtr, /* i/o: Counter */ - HANDLE_FD_CNG_COM st /* i/o: FD_CNG structure containing buffers and variables */ + +/*------------------------------------------------------------------- + * minimum_statistics() + * + * Noise estimation using Minimum Statistics (MS) + *-------------------------------------------------------------------*/ + +void minimum_statistics( + int len, /* i : Vector length */ + int lenFFT, /* i : Length of the FFT part of the vectors */ + float * psize, + float * msPeriodog, /* i : Periodograms */ + float * msNoiseFloor, + float * msNoiseEst, /* o : Noise estimates */ + float * msAlpha, + float * msPsd, + float * msPsdFirstMoment, + float * msPsdSecondMoment, + float * msMinBuf, + float * msBminWin, + float * msBminSubWin, + float * msCurrentMin, + float * msCurrentMinOut, + float * msCurrentMinSubWindow, + int * msLocalMinFlag, + int * msNewMinFlag, + float * msPeriodogBuf, + int * msPeriodogBufPtr, + HANDLE_FD_CNG_COM st /* i/o: FD_CNG structure containing all buffers and variables */ ) { - Word16 i,j,k,s,s1,s2,s3; - Word16 len2; - Word16 current_len; - Word16 start, stop, cnt; - Word16 totsize; - Word16 inv_totsize; + float msM_win = st->msM_win; + float msM_subwin = st->msM_subwin; + float * msPsdSum = st->msPsdSum; + float * msPeriodogSum = st->msPeriodogSum; + float slope; + float * ptr; + float msAlphaCorAlpha = MSALPHACORALPHA; + float msAlphaCorAlpha2 = 1.f-MSALPHACORALPHA; - Word32 tmp, tmp0, tmp1; - Word32 scalar, scalar2, scalar3; - Word32 snr; - Word32 msAlphaHatMin2; - Word32 BminCorr; - Word32 QeqInvAv; - Word32 *ptr; - Word32 *msPsdSum; - Word32 *msPeriodogSum; - - Word16 tmp16, tmp16_1; - Word16 beta; - Word16 slope; - Word16 QeqInv; - Word16 scalar16; - Word16 scalar216; - Word16 scalar316; - Word16 msM_win; - Word16 msM_subwin; - Word16 msAlphaCorAlpha; - Word16 msAlphaCorAlpha2; - Word16 msPeriodogSum16; - Word16 msNoiseFloor16; - - - len2 = i_mult(MSNUMSUBFR,len); - - msM_win = st->msM_win; - move16(); - msM_subwin = st->msM_subwin; - move16(); - - msAlphaCorAlpha = MSALPHACORALPHA; - move16(); - msAlphaCorAlpha2 = MSALPHACORALPHA2; - move16(); - - msPsdSum = st->msPsdSum; - msPeriodogSum = st->msPeriodogSum; + short i,j,k; + float scalar, scalar2, scalar3; + float snr, BminCorr, QeqInv, QeqInvAv; + float beta; + float msAlphaHatMin2; + int len2 = MSNUMSUBFR*len; + int current_len; + short start, stop, cnt; + int totsize; /* No minimum statistics at initialization */ - IF ( sub(st->msFrCnt_init_counter,st->msFrCnt_init_thresh) < 0 ) + if (st->msFrCnt_init_counter < st->msFrCnt_init_thresh) { - Copy(msPeriodog, msPsd, len); /* 6Q9 */ - Copy(msPeriodog, msNoiseFloor, len); /* 6Q9 */ - Copy(msPeriodog, msNoiseEst, len); /* 6Q9 */ - Copy(msPeriodog, msPsdFirstMoment, len); /* 6Q9 */ - - set32_fx(msPsdSecondMoment, 0l/*0.0 Q31*/, len); - msPeriodogSum[0] = dotp_s_fx(msPeriodog, psize, lenFFT, CNG_HS); - move32(); - msPsdSum[0] = msPeriodogSum[0]; /* 16Q15 */ move32(); - - IF ( sub(lenFFT,len) < 0 ) + mvr2r(msPeriodog, msPsd, len); + mvr2r(msPeriodog, msNoiseFloor, len); + mvr2r(msPeriodog, msNoiseEst, len); + mvr2r(msPeriodog, msPsdFirstMoment, len); + set_f( msPsdSecondMoment, 0.0f, len); + msPeriodogSum[0] = dotp(msPeriodog, psize, lenFFT); + msPsdSum[0] = msPeriodogSum[0]; + if (lenFFT ignore them */ - IF ( sub(msPeriodog[0],st->init_old) < 0 ) + if (msPeriodog[0]init_old) { - set32_fx(msCurrentMinOut, 2147483647l/*1.0 Q31*/, len); /* 16Q15 */ - set32_fx(msCurrentMin, 2147483647l/*1.0 Q31*/, len); /* 16Q15 */ - set32_fx(msMinBuf, 2147483647l/*1.0 Q31*/, len2); /* 16Q15 */ - set32_fx(msCurrentMinSubWindow, 2147483647l/*1.0 Q31*/, len); /* 16Q15 */ - - st->msFrCnt_init_counter = add(st->msFrCnt_init_counter,1); - move16(); + set_f(msCurrentMinOut, FLT_MAX, len); + set_f(msCurrentMin, FLT_MAX, len); + set_f(msMinBuf, FLT_MAX, len2); + set_f(msCurrentMinSubWindow, FLT_MAX, len); + st->msFrCnt_init_counter++; } - st->init_old = msPeriodog[0]; /* 6Q9 */ move16(); + st->init_old = msPeriodog[0]; } - ELSE + + else { + /* Consider the FFT and CLDFB bands separately - first iteration for FFT bins, - second one for CLDFB bands in SWB mode */ - cnt = 0; - move16(); start = 0; - move16(); - stop = lenFFT; - move16(); - totsize = sub(st->stopFFTbin,st->startBand); - WHILE ( sub(stop,start) > 0 ) + stop = lenFFT; + totsize = st->stopFFTbin-st->startBand; + cnt = 0; /*msAlphaCor*/ + while (stop > start) { - current_len = sub(stop,start); + current_len = stop-start; /* Compute smoothed correction factor for PSD smoothing */ - - /* msPeriodogSum[cnt] with format 16Q15 */ - msPeriodogSum[cnt] = dotp_s_fx(msPeriodog+start, psize+start, current_len, CNG_HS); - move32(); - - IF ( msPeriodogSum[cnt] == 0 ) - { - st->msAlphaCor[cnt] = Mpy_32_16_1(st->msAlphaCor[cnt], msAlphaCorAlpha); - move32(); - } - ELSE - { - /* calculate scalar with normalized msPeriodogSum[cnt], exponent -2*s1 */ - s1 = norm_l(msPeriodogSum[cnt]); - msPeriodogSum16 = round_fx(L_shl(msPeriodogSum[cnt],s1)); - scalar = L_mult(msPeriodogSum16, msPeriodogSum16); - - /* calculate difference, both elements in 16Q15 format, use absolute value - to avoid -1.0 x -1.0 multiplications later */ - scalar2 = L_abs(L_sub(msPsdSum[cnt], msPeriodogSum[cnt])); - - s2 = WORD32_BITS-1; - move16(); - if ( scalar2 != 0 ) - { - /* use absolute value to avoid -1.0 x -1.0 multiplications */ - s2 = norm_l(scalar2); - } - scalar216 = round_fx(L_shl(scalar2,s2)); - scalar2 = L_mult(scalar216, scalar216); - - /* find common exponent */ - tmp16_1 = sub(s1,s2); - tmp16 = s_min(shl(abs_s(tmp16_1),1),WORD32_BITS-1); - if ( tmp16_1 < 0 ) - { - scalar2 = L_shr(scalar2,tmp16); - } - if(tmp16_1 > 0) - { - scalar = L_shr(scalar,tmp16); - } - - - /* add scalar and scalar2, avoid overflows */ - scalar = L_shr(scalar,1); - scalar2 = L_shr(scalar2,1); - scalar3 = L_add(scalar,scalar2); - - /* calculate division */ - scalar16 = BASOP_Util_Divide3232_uu_1616_Scale(scalar, scalar3, &s3); - s3 = s_max(s3,-(WORD16_BITS-1)); - scalar16 = shl(scalar16,s3); - scalar16 = s_max(scalar16, MSALPHACORMAX); - - st->msAlphaCor[cnt] = L_add(Mpy_32_16_1(st->msAlphaCor[cnt], msAlphaCorAlpha), - L_mult(scalar16, msAlphaCorAlpha2)); - move32(); - } + msPeriodogSum[cnt] = dotp(msPeriodog+start, psize+start, current_len); + scalar = msPeriodogSum[cnt]*msPeriodogSum[cnt] + DELTA; + scalar2 = msPsdSum[cnt] - msPeriodogSum[cnt]; + scalar = max(scalar / (scalar + scalar2*scalar2) , MSALPHACORMAX); + st->msAlphaCor[cnt] = msAlphaCorAlpha*st->msAlphaCor[cnt] + msAlphaCorAlpha2*scalar; /* Compute SNR */ - - /* msPeriodogSum[cnt] with format 16Q15 */ - snr = dotp_s_fx(msNoiseFloor+start, psize+start, current_len, CNG_HS); - - IF ( L_sub(L_shr(Mpy_32_16_1(msPsdSum[cnt],18431/*0.56246299817 Q15*/),13),snr) > 0 ) + snr = dotp(msNoiseFloor+start, psize+start, current_len); + snr = (msPsdSum[cnt] + DELTA) / (snr + DELTA); + snr = (float)pow(snr, MSSNREXP); + msAlphaHatMin2 = min( MSALPHAHATMIN, snr ); + scalar = MSALPHAMAX * st->msAlphaCor[cnt]; /*msAlpha,msPsd,msPeriodog,msNoiseFloor*/ + for(j=start ; jmsAlphaCor[cnt], MSALPHAMAX); - - FOR (j=start; j 0) - { - scalar2 = L_shr(scalar2,tmp16); - } - - /* add scalar2 and scalar3, avoid overflows */ - scalar2 = L_shr(scalar2,1); - scalar3 = L_shr(scalar3,1); - scalar3 = L_add(scalar2,scalar3); - - /* calculate division */ - tmp16 = BASOP_Util_Divide3232_uu_1616_Scale(scalar2, scalar3, &s3); - scalar2 = Mpy_32_16_1(scalar, tmp16); - s3 = s_max(s3,-(WORD32_BITS-1)); - scalar2 = L_shl(scalar2,s3); - msAlpha[j] = L_max(scalar2, msAlphaHatMin2); - move32(); - } + /* Compute optimal smoothing parameter for PSD estimation */ + scalar2 = msNoiseFloor[j] + DELTA; + scalar2 *= scalar2; + scalar3 = msPsd[j] - msNoiseFloor[j]; + msAlpha[j] = max( (scalar*scalar2) / (scalar2 + scalar3*scalar3) , msAlphaHatMin2); /* Compute the PSD (smoothed periodogram) in each band */ - msPsd[j] = round_fx(L_add(Mpy_32_16_1(msAlpha[j], msPsd[j]), - Mpy_32_16_1(L_sub(2147483647l/*1.0 Q31*/,msAlpha[j]), msPeriodog[j]))); + msPsd[j] = msAlpha[j] * msPsd[j] + (1.f-msAlpha[j]) * msPeriodog[j]; } - msPsdSum[cnt] = dotp_s_fx(msPsd+start, psize+start, current_len, CNG_HS); - move32(); - - QeqInvAv = 0l/*0.0 Q31*/; - move32(); - - /* scalar: 7Q24 format */ - tmp = 1191182336l/*(float)(MSNUMSUBFR*MSSUBFRLEN)-1.0 Q24*/; - move32(); - scalar = L_sub(tmp, L_mult(round_fx(tmp), msM_win)); - - /* scalar2: 4Q27 format */ - tmp = 1476395008l/*(float)MSSUBFRLEN-1.0 Q27*/; - move32(); - scalar2 = L_sub(tmp, L_mult(round_fx(tmp), msM_subwin)); - - FOR (j=start; jmsQeqInvAv[cnt] = QeqInvAv; - move32(); /* New minimum? */ - - /* exponent QeqInvAv: CNG_S, exponent MSAV: (4>>1) */ - s = CNG_S+2*MSAV_EXP; - move16(); - BminCorr = Mpy_32_16_1(Sqrt32(QeqInvAv, &s), MSAV); - BminCorr = L_shl(BminCorr,sub(s,1)); - - /* exponent BminCorr: 1 */ - BminCorr = L_add(BminCorr, 1073741824l/*0.5 Q31*/); - - FOR (j=start; jmsFrCnt,MSSUBFRLEN) >= 0 ) + if (st->msFrCnt >= MSSUBFRLEN) { - FOR ( i = 0; i < 3; i++ ) + i = 0; + while (i < 3) { - IF ( L_sub(st->msQeqInvAv[cnt],L_shr(L_deposit_h(msQeqInvAv_thresh[i]),CNG_S)) < 0l/*0.0 Q31*/ ) + if (st->msQeqInvAv[cnt] < msQeqInvAv_thresh[i]) { - BREAK; + break; + } + else + { + i++; } } - /* format 1Q30 */ st->msSlope[cnt] = msNoiseSlopeMax[i]; - move32(); } /* Consider the FFT and CLDFB bands separately */ start = stop; - move16(); stop = len; - move16(); - totsize = sub(st->stopBand,st->stopFFTbin); - cnt = add(cnt,1); + totsize = st->stopBand - st->stopFFTbin; + cnt++; } /*while (stop > start)*/ /* Update minimum between sub windows */ - test(); - IF ( sub(st->msFrCnt,1) > 0 && sub(st->msFrCnt,MSSUBFRLEN) < 0 ) + if( st->msFrCnt > 1 && st->msFrCnt < MSSUBFRLEN ) { - FOR (j=0; j 0 ) + if (msNewMinFlag[j] > 0) { msLocalMinFlag[j] = 1; - move16(); } - if ( L_sub(msCurrentMinSubWindow[j],msCurrentMinOut[j]) < 0l/*0.0 Q31*/ ) + if (msCurrentMinSubWindow[j] < msCurrentMinOut[j]) { - /* msCurrentMinOut[j] scaled with CNG_S */ msCurrentMinOut[j] = msCurrentMinSubWindow[j]; - move32(); } } /* Get the current noise floor */ - Copy_Scale_sig_32_16(msCurrentMinOut, msNoiseFloor, len, -16); + mvr2r(msCurrentMinOut, msNoiseFloor, len); } - ELSE /* sub window complete */ + + /* sub window complete */ + else { - IF ( sub(st->msFrCnt,MSSUBFRLEN) >= 0 ) + if (st->msFrCnt >= MSSUBFRLEN) { /* Collect buffers */ - Copy32(msCurrentMinSubWindow, msMinBuf+len*st->msMinBufferPtr, len); + mvr2r(msCurrentMinSubWindow, msMinBuf+len*st->msMinBufferPtr, len); /* Compute minimum among all buffers */ - Copy32(msMinBuf, msCurrentMinOut, len); + mvr2r(msMinBuf, msCurrentMinOut, len); ptr = msMinBuf + len; - FOR (i=1; imsSlope[0]; - move16(); - FOR (j=0; jmsSlope[0]; /*msLocalMinFlag,msNewMinFlag,msCurrentMinSubWindow,msCurrentMinOut*/ + for(j=0 ; jmsSlope[1]; - move16(); } - test(); - test(); - test(); - IF ( ( msLocalMinFlag[j] != 0 ) - && ( msNewMinFlag[j] == 0 ) - && ( L_sub(L_shr(msCurrentMinSubWindow[j],1),Mpy_32_16_1(msCurrentMinOut[j],slope)) < 0l/*0.0 Q31*/ ) - && ( L_sub(msCurrentMinSubWindow[j],msCurrentMinOut[j]) > 0l/*0.0 Q31*/ ) - ) + if ( msLocalMinFlag[j] && !msNewMinFlag[j] && + msCurrentMinSubWindow[j]msCurrentMinOut[j] ) { msCurrentMinOut[j] = msCurrentMinSubWindow[j]; - move32(); i = j; - move16(); - FOR (k=0; k 0l/*0.0 Q31*/ ) + if (msPsdSum[0]>50.f*msPeriodogSum[0]) { - IF ( st->offsetflag > 0 ) + if (st->offsetflag>0) { - Copy(msPeriodog, msPsd, len); - FOR (j=0; j < len; j++) + mvr2r(msPeriodog, msPsd, len); + mvr2r(msPeriodog, msCurrentMinOut, len); + set_f( st->msAlphaCor, 1.0f, cnt); + set_f( msAlpha, 0.0f, len); + mvr2r(msPeriodog, msPsdFirstMoment, len); + set_f( msPsdSecondMoment, 0.0f, len); + msPsdSum[0] = dotp(msPeriodog, psize, lenFFT); + if (lenFFTmsAlphaCor, 2147483647l/*1.0 Q31*/, cnt); - set32_fx(msAlpha, 0l/*0.0 Q31*/, len); - Copy(msPeriodog, msPsdFirstMoment, len); - set32_fx(msPsdSecondMoment, 0l/*0.0 Q31*/, len); - - msPsdSum[0] = dotp_s_fx(msPeriodog, psize, lenFFT, CNG_HS); - move32(); - IF ( sub(lenFFT,len) < 0 ) - { - msPsdSum[1] = dotp_s_fx(msPeriodog+lenFFT, psize+lenFFT, sub(len,lenFFT), CNG_HS); - move32(); + msPsdSum[1] = dotp(msPeriodog+lenFFT, psize+lenFFT, len-lenFFT); } } st->offsetflag = 1; - move16(); } - ELSE + else { st->offsetflag = 0; - move16(); } /* Increment frame counter */ - IF ( sub(st->msFrCnt,MSSUBFRLEN) == 0) + if (st->msFrCnt == MSSUBFRLEN) { st->msFrCnt = 1; - move16(); - st->msMinBufferPtr = add(st->msMinBufferPtr,1); - move16(); - if ( sub(st->msMinBufferPtr,MSNUMSUBFR) == 0 ) + st->msMinBufferPtr++; + if (st->msMinBufferPtr==MSNUMSUBFR) { st->msMinBufferPtr = 0; - move16(); } } - ELSE + else { - st->msFrCnt = add(st->msFrCnt,1); + (st->msFrCnt)++; } - /* Smooth noise estimate during CNG phases */ - FOR (j=0; j 0/*0.0 Q15*/ ) - { - msNoiseEst[j] = scalar16; - move16(); + (*msPeriodogBufPtr) = 0; } - assert(msNoiseEst[j] >= 0/*0.0 Q15*/); + /* Upper limit the noise floors with the averaged input energy */ /*msNoiseEst*/ + for(j=0 ; jscalar) + { + msNoiseEst[j] = scalar; + } + assert(msNoiseEst[j] >= 0); + } } + return; } -/*********************************** -* Apply bitrate-dependant scale * -***********************************/ -void apply_scale(Word32 *scale, Word16 bwmode, Word32 bitrate) +/*------------------------------------------------------------------- + * apply_scale() + * + * Apply bitrate-dependent scale + *-------------------------------------------------------------------*/ + +void apply_scale( + float *scale, + int bandwidth, + int bitrate +) { - Word16 i; - Word16 scaleTableSize = sizeof (scaleTable) / sizeof (scaleTable[0]); + int i; + int scaleTableSize = sizeof (scaleTable) / sizeof (scaleTable[0]); - - - FOR (i=0; i < scaleTableSize; i++) + for (i = 0 ; i < scaleTableSize ; i++) { - cast16(); - IF ( s_and( sub(bwmode, (Word16)scaleTable[i].bwmode) == 0, - s_and( L_sub(bitrate,scaleTable[i].bitrateFrom) >= 0, - L_sub(bitrate,scaleTable[i].bitrateTo) < 0)) - ) + if ( (bandwidth == scaleTable[i].bwmode) && + (bitrate >= scaleTable[i].bitrateFrom) && + (bitrate < scaleTable[i].bitrateTo) ) { - BREAK; + break; } } - { - *scale = L_add(*scale, L_deposit_h(scaleTable[i].scale)); - } + *scale += scaleTable[i].scale; + return; } -/*************************************** -* Compute the power for each partition * -***************************************/ -void bandcombinepow(Word32* bandpow, /* i : Power for each band */ - Word16 exp_bandpow, /* i : exponent of bandpow */ - Word16 nband, /* i : Number of bands */ - Word16* part, /* i : Partition upper boundaries (band indices starting from 0) */ - Word16 npart, /* i : Number of partitions */ - Word16* psize_inv, /* i : Inverse partition sizes */ - Word32* partpow, /* o : Power for each partition */ - Word16* exp_partpow) +/*------------------------------------------------------------------- + * bandcombinepow() + * + * Compute the power for each partition + *-------------------------------------------------------------------*/ + +void bandcombinepow( + float* bandpow, /* i : Power for each band */ + int nband, /* i : Number of bands */ + int* part, /* i : Partition upper boundaries (band indices starting from 0) */ + int npart, /* i : Number of partitions */ + float* psize_inv, /* i : Inverse partition sizes */ + float* partpow /* o : Power for each partition */ +) { - Word16 i, p; - Word32 temp; - Word16 smin, len, prev_part; - Word16 facTabExp[NPART_SHAPING]; + int i, p; + float temp; - - - IF (sub(nband, npart) == 0) + if (nband == npart) { - Copy32(bandpow, partpow, nband); - smin = 0; - move16(); + mvr2r(bandpow, partpow, nband); } - ELSE + else { /* Compute the power in each partition */ - prev_part = -1; - move16(); - FOR (p=0; p < npart; p++) - { - len = sub(part[p],prev_part); - facTabExp[p] = getScaleFactor32 (&bandpow[prev_part+1], len); - move16(); - prev_part = part[p]; - move16(); - } - - smin = WORD32_BITS-1; - move16(); - FOR (p=0; p < npart; p++) - { - smin = s_min(smin,facTabExp[p]); - } - - i = 0; - move16(); - FOR (p = 0; p < npart; p++) + i = 0; /*part,partpow,psize_inv*/ + for (p = 0; p < npart; p++) { /* Arithmetic averaging of power for all bins in partition */ - temp = L_add(0,0); - FOR ( ; i <= part[p]; i++) + temp = 0; + for ( ; i <= part[p]; i++) { - temp = L_add(temp, Mpy_32_16_1(L_shl(bandpow[i],facTabExp[p]),psize_inv[p])); + temp += bandpow[i]; } - partpow[p] = L_shr(temp,sub(facTabExp[p],smin)); - move32(); + partpow[p] = temp*psize_inv[p]; } - } - *exp_partpow = sub(exp_bandpow,smin); - move16(); + return; } -/************************************ -* Scale partitions (with smoothing) * -************************************/ -void scalebands (Word32 *partpow, /* i : Power for each partition */ - Word16 *part, /* i : Partition upper boundaries (band indices starting from 0) */ - Word16 npart, /* i : Number of partitions */ - Word16 *midband, /* i : Central band of each partition */ - Word16 nFFTpart, /* i : Number of FFT partitions */ - Word16 nband, /* i : Number of bands */ - Word32 *bandpow, /* o : Power for each band */ - Word16 flag_fft_en - ) +/*------------------------------------------------------------------- + * scalebands() + * + * Scale partitions (with smoothing) + *-------------------------------------------------------------------*/ + +void scalebands( + float* partpow, /* i : Power for each partition */ + int* part, /* i : Partition upper boundaries (band indices starting from 0) */ + int npart, /* i : Number of partitions */ + int* midband, /* i : Central band of each partition */ + int nFFTpart, /* i : Number of FFT partitions */ + int nband, /* i : Number of bands */ + float* bandpow, /* o : Power for each band */ + short flag_fft_en +) { - Word16 i, j, s, s1, nint, delta, delta_cmp, delta_s; - Word16 startBand, startPart, stopPart, stopPartM1; - Word32 tmp, val, partpowLD64, partpowLD64M1; + int i, j=0, nint, startBand, startPart, stopPart; + float val, delta = 0.f; - - j = 0; - move16(); - delta = 0; - move16(); - partpowLD64M1 = 0L; /* to avoid compilation warnings */ - /* Interpolate the bin/band-wise levels from the partition levels */ - IF ( sub(nband, npart) == 0 ) + if (nband == npart) { - Copy32(partpow, bandpow, npart); + mvr2r(partpow, bandpow, npart); } - ELSE + else { - startBand = 0; - move16(); - startPart = 0; - move16(); - stopPart = nFFTpart; - move16(); - - WHILE ( sub(startBand,nband) < 0 ) + startBand = 0; + startPart = 0; + stopPart = nFFTpart; + while (startBand < nband) { - stopPartM1 = sub(stopPart, 1); - test(); - IF ( (flag_fft_en != 0) || (sub(startPart,nFFTpart) >= 0) ) + if (flag_fft_en || startPart>=nFFTpart) { + /* first half partition */ j = startPart; - move16(); - - FOR (i=startBand; i <= midband[j]; i++) + val = partpow[j]; + for (i = startBand; i <= midband[j]; i++) { - bandpow[i] = partpow[j]; - move32(); + bandpow[i] = val; } - j = add(j, 1); + j++; + delta = 1; /* inner partitions */ - IF (j < stopPart) + for ( ; j < stopPart ; j++) { - partpowLD64M1 = BASOP_Util_Log2(partpow[j-1]); - } - - /* Debug values to check this variable is set. */ - delta = 0x4000; - move16(); - delta_cmp = 0x4000; - move16(); - s1 = 1; - move16(); - s = 1; - move16(); - - FOR ( ; j < stopPart; j++) - { - nint = sub(midband[j], midband[j-1]); - - /* log-linear interpolation */ - partpowLD64 = BASOP_Util_Log2(partpow[j]); - tmp = L_sub(partpowLD64, partpowLD64M1); - tmp = Mpy_32_16_1(tmp, getNormReciprocalWord16(nint)); - - /* scale logarithmic value */ - tmp = L_sub(tmp, DELTA_SHIFT_LD64); - delta_s = DELTA_SHIFT; - move16(); - - WHILE (tmp > 0) + nint = midband[j] - midband[j-1]; + /* log-linear interpolation */ /* Only one new LOG needs to be computed per loop iteration */ + delta = (float)exp( (log(partpow[j]+DELTA) - log(partpow[j-1]+DELTA)) * normReciprocal[nint] ); + val = partpow[j-1]; + for ( ; i < midband[j]; i++) { - tmp = L_sub(tmp,33554432l/*0.015625 Q31*/); - delta_s = add(delta_s,1); + val *= delta; + bandpow[i] = val; } - delta_cmp = shl(1, s_max(-15, sub(WORD16_BITS-1,delta_s))); - - tmp = BASOP_Util_InvLog2(tmp); - s = norm_l(tmp); - s1 = sub(delta_s, s); - - delta = round_fx(L_shl(tmp, s)); - - /* Choose scale such that the interpolation start and end point both are representable and add 1 additional bit hr. */ - delta_s = sub(s_min(norm_l(partpow[j-1]), norm_l(partpow[j])), 1); - val = L_shl(partpow[j-1], delta_s); - FOR ( ; i < midband[j]; i++) - { - val = L_shl(Mpy_32_16_1(val, delta), s1); - bandpow[i] = L_shr(val, delta_s); - move32(); - } - bandpow[i++] = partpow[j]; - move32(); - partpowLD64M1 = L_add(0,partpowLD64); + bandpow[i++] = partpow[j]; } - - IF ( sub(shr(delta, s), delta_cmp) > 0 ) + if ( delta>1.f ) { - delta = 0x4000; - move16(); - s1 = 1; - move16(); + delta = 1.f; } /* last half partition */ - val = L_add(0,partpow[stopPartM1]); - FOR ( ; i <= part[stopPartM1]; i++) + val = partpow[stopPart-1]; + for ( ; i <= part[stopPart-1]; i++) { - val = L_shl(Mpy_32_16_1(val,delta), s1); + val *= delta; bandpow[i] = val; - move32(); } - } - startBand = add(part[stopPartM1], 1); + startBand = part[stopPart-1]+1; startPart = stopPart; - move16(); stopPart = npart; - move16(); } } + return; } -/************************************** -* Get central band for each partition * -**************************************/ -void getmidbands(Word16* part, /* i : Partition upper boundaries (band indices starting from 0) */ - Word16 npart, /* i : Number of partitions */ - Word16* midband, /* o : Central band of each partition */ - Word16* psize, /* o : Partition sizes */ - Word16* psize_norm, /* o : Partition sizes, fractional values */ - Word16* psize_norm_exp, /* o : Exponent for fractional partition sizes */ - Word16* psize_inv) /* o : Inverse of partition sizes */ +/*------------------------------------------------------------------- + * getmidbands() + * + * Get central band for each partition + *-------------------------------------------------------------------*/ + +void getmidbands( + int* part, /* i : Partition upper boundaries (band indices starting from 0) */ + int npart, /* i : Number of partitions */ + int* midband, /* o : Central band of each partition */ + float* psize, /* o : Partition sizes */ + float* psize_inv /* o : Inverse of partition sizes */ +) { - Word16 j, max_psize, shift; + int j; - max_psize = psize[0]; - move16(); - /* first half partition */ move16(); + /* first half partition */ midband[0] = part[0]; - psize[0] = add(part[0], 1); - move16(); - psize_inv[0] = getNormReciprocalWord16(psize[0]); - move16(); - /* inner partitions */ - FOR (j = 1; j < npart; j++) + psize[0] = (float)part[0] + 1.f; + psize_inv[0] = normReciprocal[part[0] + 1]; + /* inner partitions */ /*part,midband,psize_inv*/ + for (j = 1; j < npart; j++) { - midband[j] = shr(add(add(part[j-1], 1), part[j]), 1); - move16(); - psize[j] = sub(part[j], part[j-1]); - move16(); - psize_inv[j] = getNormReciprocalWord16(psize[j]); - move16(); - if(sub(psize[j], max_psize) > 0) - { - max_psize = psize[j]; - move16(); - } + midband[j] = (part[j-1]+1 + part[j]) >> 1; + psize[j] = (float)(part[j] - part[j-1]); + psize_inv[j] = normReciprocal[part[j] - part[j-1]]; } - shift = 9; - move16(); - *psize_norm_exp = sub(15, shift); - move16(); - FOR(j=0; j < npart; j++) - { - psize_norm[j] = shl(psize[j], shift); - move16(); - } - /* minimum_statistics needs fixed exponent of 6 */ - assert(norm_s(-max_psize) >= 9 ); + return; } -/* - AnalysisSTFT +/*------------------------------------------------------------------- + * AnalysisSTFT() + * + * STFT analysis filterbank + *-------------------------------------------------------------------*/ - Parameters: - - timeDomainInput, i : pointer to time signal - fftBuffer, o : FFT bins - fftBufferExp, i : exponent of FFT bins - st i/o: FD_CNG structure containing all buffers and variables - - Function: - STFT analysis filterbank - - Returns: - void -*/ -void AnalysisSTFT (const Word16 *timeDomainInput, /* i : pointer to time signal */ - Word16 Q, - Word32 *fftBuffer, /* o : FFT bins */ - Word16 *fftBuffer_exp, /* i : exponent of FFT bins */ - HANDLE_FD_CNG_COM st /* i/o: FD_CNG structure containing all buffers and variables */ - ) +void AnalysisSTFT( + const float * timeDomainInput, + float * fftBuffer, /* o : FFT bins */ + HANDLE_FD_CNG_COM st /* i/o: FD_CNG structure containing all buffers and variables */ +) { - Word16 i, len; - Word16 len2; - const PWord16 *olapWin; - Word16 *olapBuffer; + float *olapBuffer = st->olapBufferAna; + const float *olapWin = st->olapWinAna; - - - assert( (st->fftlen>>1) == st->frameSize); - - /* pointer inititialization */ - assert(st->olapBufferAna != NULL); - olapBuffer = st->olapBufferAna; - olapWin = st->olapWinAna; - - /* olapWin factor is scaled with one bit */ - *fftBuffer_exp = 1; - move16(); - len = sub(st->fftlen,st->frameSize); - assert(len <= 320); /* see size of olapBuffer */ + /* Shift and cascade for overlap-add */ + mvr2r(olapBuffer+st->frameSize, olapBuffer, st->fftlen-st->frameSize); + mvr2r(timeDomainInput, olapBuffer+st->fftlen-st->frameSize, st->frameSize); /* Window the signal */ - len2 = shr(len,1); - FOR (i=0; i < len2; i++) - { - move32(); - move32(); - fftBuffer[i] = L_mult(olapBuffer[i], mult_r(olapWin[i].v.im, 23170/*1.4142135623730950488016887242097 Q14*/)); - fftBuffer[i+len2] = L_mult(olapBuffer[i+len2], mult_r(olapWin[len2-1-i].v.re, 23170/*1.4142135623730950488016887242097 Q14*/)); - } - len2 = shr(st->frameSize,1); - FOR (i=0; i fftlen); + /* Perform FFT */ - BASOP_rfft(fftBuffer, st->fftlen, fftBuffer_exp, -1); - - FOR (i=0; i frameSize,len)+i], Q ); - move16(); - } + RFFTN(fftBuffer, st->fftSineTab, st->fftlen, -1); + return; } -/* - SynthesisSTFT +/*------------------------------------------------------------------- + * SynthesisSTFT() + * + * STFT synthesis filterbank + *-------------------------------------------------------------------*/ - Parameters: - - fftBuffer i : pointer to FFT bins - fftBufferExp i : exponent of FFT bins - timeDomainOutput o : pointer to time domain signal - timeDomainOutputExp o : pointer to exponent of time domain output - olapBuffer i/o : pointer to overlap buffer - olapWin i : pointer to overlap window - st i/o : pointer to FD_CNG structure containing all buffers and variables - - Function: - STFT synthesis filterbank - - Returns: - void -*/ -void -SynthesisSTFT (Word32 *fftBuffer, /* i : pointer to FFT bins */ - Word16 fftBufferExp, /* i : exponent of FFT bins */ - Word16 *timeDomainOutput, /* o : pointer to time domain signal */ - Word16 *olapBuffer, /* i/o : pointer to overlap buffer */ - const PWord16 *olapWin, /* i : pointer to overlap window */ - Word16 tcx_transition, - HANDLE_FD_CNG_COM st, /* i/o : pointer to FD_CNG structure containing all buffers and variables */ - Word16 gen_exc, - Word16 *Q_new - ) +void SynthesisSTFT( + float * fftBuffer, /* i : FFT bins */ + float * timeDomainOutput, + float * olapBuffer, + const float * olapWin, + int tcx_transition, + HANDLE_FD_CNG_COM st /* i/o: FD_CNG structure containing all buffers and variables */ +) { - Word16 i, len, scale, tmp; - Word16 len2, len3, len4; - Word16 buf[M+1+L_FRAME16k]; - + short i; + float buf[M+1+320], tmp; /* Perform IFFT */ - scale = 0; - BASOP_rfft(fftBuffer, st->fftlen, &scale, 1); - fftBufferExp = add(fftBufferExp, scale); - fftBufferExp = add(fftBufferExp, st->fftlenShift); + RFFTN(fftBuffer, st->fftSineTab, st->fftlen, 1); /* Perform overlap-add */ - Copy(olapBuffer+st->frameSize, olapBuffer, st->frameSize); - set16_fx(olapBuffer+st->frameSize, 0, st->frameSize); - - len2 = shr(st->fftlen,2); - len4 = shr(st->fftlen,3); - len3 = add(len2,len4); - len = add(st->frameSize,len4); - IF ( tcx_transition ) + mvr2r(olapBuffer+st->frameSize, olapBuffer, st->frameSize); + set_f( olapBuffer+st->frameSize, 0.0f, st->frameSize); /*olapBuffer, fftBuffer, olapWin*/ + if ( tcx_transition ) { - FOR (i=0; i < len; i++) + for (i=0 ; i<5*st->frameSize/4 ; i++) { - olapBuffer[i] = round_fx(L_shl(fftBuffer[i],fftBufferExp-15)); + olapBuffer[i] = fftBuffer[i]; } } - ELSE + else { - FOR (i=0; i < len4; i++) + for (i=st->frameSize/4 ; i<3*st->frameSize/4 ; i++) { - olapBuffer[i+1*len4] = add(olapBuffer[i+1*len4], mult_r(round_fx(L_shl(fftBuffer[i+1*len4],fftBufferExp-15)),olapWin[i].v.im)); - move16(); - olapBuffer[i+2*len4] = add(olapBuffer[i+2*len4], mult_r(round_fx(L_shl(fftBuffer[i+2*len4],fftBufferExp-15)),olapWin[len4-1-i].v.re)); - move16(); + olapBuffer[i] += fftBuffer[i] * olapWin[i-st->frameSize/4]; } - FOR (i=len3; i < len; i++) + for ( ; i<5*st->frameSize/4 ; i++) { - olapBuffer[i] = round_fx(L_shl(fftBuffer[i],fftBufferExp-15)); + olapBuffer[i] = fftBuffer[i]; } } - - FOR (i=0; i < len4; i++) + for ( ; i<7*st->frameSize/4 ; i++) { - olapBuffer[i+5*len4] = mult_r(round_fx(L_shl(fftBuffer[i+5*len4],fftBufferExp-15)),olapWin[i].v.re); - move16(); - olapBuffer[i+6*len4] = mult_r(round_fx(L_shl(fftBuffer[i+6*len4],fftBufferExp-15)),olapWin[len4-1-i].v.im); - move16(); + olapBuffer[i] = fftBuffer[i] * olapWin[i-3*st->frameSize/4]; } - len = add( len, len2 ); - FOR (i=len; i < st->fftlen ; i++) + for ( ; ifftlen ; i++) { olapBuffer[i] = 0; - move16(); } /* Get time-domain signal */ - FOR (i=0; i < st->frameSize; i++) - { - timeDomainOutput[i] = mult_r( olapBuffer[i+len4], st->fftlenFac ); - move16(); - } + v_multc( olapBuffer+st->frameSize/4, (float)(st->fftlen/2), timeDomainOutput, st->frameSize); - /* Generate excitation */ - IF ( sub( gen_exc, 1 ) == 0 ) - { - FOR (i=0; i < M+1+st->frameSize; i++) - { - buf[i] = mult_r( olapBuffer[i+len4-M-1], st->fftlenFac ); - move16(); - } - tmp = buf[0]; - E_UTIL_f_preemph2( *Q_new-1, buf+1, PREEMPH_FAC, M+st->frameSize, &tmp ); - Residu3_fx( st->A_cng, buf+1+M, st->exc_cng, st->frameSize, 1 ); - } - IF ( sub( gen_exc, 2 ) == 0 ) - { - FOR (i=0; i < M+1+st->frameSize; i++) - { - buf[i] = mult_r( olapBuffer[i+len4-M-1], st->fftlenFac ); - move16(); - } - tmp = buf[0]; - *Q_new = E_UTIL_f_preemph3( buf+1, PREEMPH_FAC, M+st->frameSize, &tmp, 1 ); - Residu3_fx( st->A_cng, buf+1+M, st->exc_cng, st->frameSize, 1 ); - } + /* Get excitation */ + v_multc( olapBuffer+st->frameSize/4-(M+1), (float)(st->fftlen/2), buf, M+1+st->frameSize ); + tmp = buf[0]; + preemph( buf+1, PREEMPH_FAC, M+st->frameSize, &tmp ); + residu( st->A_cng, M, buf+1+M, st->exc_cng, st->frameSize ); + return; } -/************************************************************************************** -* Compute some values used in the bias correction of the minimum statistics algorithm * -**************************************************************************************/ -void mhvals(Word16 d, - Word16 * m /*, float * h*/ - ) +/*------------------------------------------------------------------- + * mhvals() + * + * Compute some values used in the bias correction of the minimum statistics algorithm + *-------------------------------------------------------------------*/ + +static void mhvals( + int d, + float * m +) { - Word16 i, j; - Word16 len = sizeof(d_array)/sizeof(Word16); + int i, j; + float qi, qj, q; + int len = sizeof(d_array)/sizeof(int); - - assert( d==72 || d==12); /* function only tested for d==72 and d==12) */ i = 0; - move16(); - FOR (i=0 ; i < len ; i++) + for (i=0 ; iA_cng, Aq+i*(M+1), M+1 ); + mvr2r( hs->A_cng, Aq+i*(M+1), M+1 ); } - - E_LPC_a_lsp_conversion( Aq, lsp_new, lsp_old, M ); - - IF( first_CNG == 0 ) + a2lsp_stab( Aq, lsp_new, lsp_old ); + if( first_CNG == 0 ) { - Copy( lsp_old, lspCNG, M ); + mvr2r( lsp_old, lspCNG, M ); } - FOR( i=0; iexc_cng, exc, L_frame ); + mvr2r( hs->exc_cng, exc2, L_frame ); + if( L_frame == L_FRAME ) + { + interp_code_5over2( exc2, bwe_exc, L_frame ); + } + else + { + interp_code_4over2( exc2, bwe_exc, L_frame ); } - IF(sub(L_frame, L_FRAME16k)== 0) - { - lsp2lsf_fx( lsp_new, lsf_new, M, INT_FS_16k_FX ); - } - ELSE - { - E_LPC_lsp_lsf_conversion( lsp_new, lsf_new, M ); - } - Copy( hs->exc_cng, exc, L_frame ); - Copy( hs->exc_cng, exc2, L_frame ); - - IF( sub(L_frame,L_FRAME) == 0 ) - { - interp_code_5over2_fx( exc2, bwe_exc, L_frame ); - } - ELSE - { - interp_code_4over2_fx( exc2, bwe_exc, L_frame ); - } + return; } - diff --git a/src/libs/libevs/lib_com/fft.cpp b/src/libs/libevs/lib_com/fft.cpp old mode 100755 new mode 100644 index 1e4f5317..04adbaf9 --- a/src/libs/libevs/lib_com/fft.cpp +++ b/src/libs/libevs/lib_com/fft.cpp @@ -1,264 +1,3325 @@ /*==================================================================================== - EVS Codec 3GPP TS26.442 Apr 03, 2018. Version 12.11.0 / 13.6.0 / 14.2.0 + EVS Codec 3GPP TS26.443 Nov 13, 2018. Version 12.11.0 / 13.7.0 / 14.3.0 / 15.1.0 ====================================================================================*/ +#include #include -#include "prot_fx.h" -#include "basop_util.h" -#include "rom_basop_util.h" #include "options.h" -#include "stl.h" +#include "cnst.h" +#include "prot.h" +#include "rom_com.h" +/*-----------------------------------------------------------------* + * Local functions + *-----------------------------------------------------------------*/ -/** - * \brief Profiling / Precision results - * - * Profiling / Precision of complex valued FFTs: BASOP_cfft() - * - * WOPS BASOP Precision BASOP - * FFT5 87 16.96 - * FFT8 108 17.04 - * FFT10 194 16.70 - * FFT15 354 16.97 - * FFT16 288 16.62 - * FFT20 368 16.06 - * FFT30 828 16.80 - * FFT32 752 15.45 (cplx mult mit 3 mult und 3 add) - * FFT32 824 16.07 (cplx mult mit 4 mult und 2 add) - * FFT64 ( 8x 8) 3.129 15.16 - * FFT80 (10x 8) 4.385 15.55 - * FFT100 (20x 5) 6.518 15.65 - * FFT120 (15x 8) 7.029 15.38 - * FFT128 (16x 8) 6.777 15.28 - * FFT160 (20x 8) 9.033 14.95 - * FFT240 (30x 8) 14.961 15.49 - * FFT256 (32x 8) 14.905 14.61 (cplx mult mit 3 mult und 3 add) - * FFT256 (32x 8) 15.265 15.04 (cplx mult mit 4 mult und 2 add) - * FFT320 (20x16) 21.517 15.21 - * - * - * Profiling / Precision of real valued FFTs / iFFTs: BASOP_rfft() - * - * WOPS BASOP Precision BASOP - * rFFT40 955 15.68 - * rFFT64 1635 16.17 - * - * irFFT40 1116 15.36 - * irFFT64 1759 15.18 - * - */ +static void cdftForw( short n, float *a, const short *ip, const float *w ); +static void bitrv2_SR( short n, const short *ip, float *a ); +static void cftfsub( short n, float *a, const float *w ); +static void cft1st(short n, float *a, const float *w); +static void cftmdl(short n, short l, float *a, const float *w); +static void fft16( float *x, float *y, const short *Idx ); +static void fft5_shift1( int n1, float *zRe, float *zIm, const short *Idx ); +static void fft8( float *x, float *y, const short *Idx ); +static void fft15_shift2( int n1, float *zRe, float *zIm, const short *Idx ); +static void fft15_shift8( int n1, float *zRe, float *zIm, const short *Idx ); +static void fft5_shift4( int n1, float *zRe, float *zIm, const short *Idx ); +static void fft5_32( float *zRe, float *zIm, const short *Idx ); +static void fft64( float *x, float *y, const short *Idx ); +static void fft32_15( float *x, float *y, const short *Idx ); +static void fft32_5( float *x, float *y, const short *Idx ); +static void fft8_5( float *x, float *y, const short *Idx ); +static void fft5_8( int n1, float *zRe, float *zIm, const short *Idx ); +static void fft4_5( float *x, float *y, const short *Idx ); +static void fft5_4( int n1, float *zRe, float *zIm, const short *Idx ); - -#define Mpy_32_xx Mpy_32_16_1 - -#define FFTC(x) WORD322WORD16((Word32)x) - -#define C31 (FFTC(0x91261468)) /* FL2WORD32( -0.86602540) -sqrt(3)/2 */ - -#define C51 (FFTC(0x79bc3854)) /* FL2WORD32( 0.95105652) */ -#define C52 (FFTC(0x9d839db0)) /* FL2WORD32(-1.53884180/2) */ -#define C53 (FFTC(0xd18053ce)) /* FL2WORD32(-0.36327126) */ -#define C54 (FFTC(0x478dde64)) /* FL2WORD32( 0.55901699) */ -#define C55 (FFTC(0xb0000001)) /* FL2WORD32(-1.25/2) */ - -#define C81 (FFTC(0x5a82799a)) /* FL2WORD32( 7.071067811865475e-1) */ -#define C82 (FFTC(0xa57d8666)) /* FL2WORD32(-7.071067811865475e-1) */ - -#define C161 (FFTC(0x5a82799a)) /* FL2WORD32( 7.071067811865475e-1) INV_SQRT2 */ -#define C162 (FFTC(0xa57d8666)) /* FL2WORD32(-7.071067811865475e-1) -INV_SQRT2 */ - -#define C163 (FFTC(0x7641af3d)) /* FL2WORD32( 9.238795325112867e-1) COS_PI_DIV8 */ -#define C164 (FFTC(0x89be50c3)) /* FL2WORD32(-9.238795325112867e-1) -COS_PI_DIV8 */ - -#define C165 (FFTC(0x30fbc54d)) /* FL2WORD32( 3.826834323650898e-1) COS_3PI_DIV8 */ -#define C166 (FFTC(0xcf043ab3)) /* FL2WORD32(-3.826834323650898e-1) -COS_3PI_DIV8 */ - - - -#define cplxMpy3_0(a,b,c,d) as = L_shr(a,1); \ - bs = L_shr(b,1); \ - a = L_sub(Mpy_32_xx(as,c),Mpy_32_xx(bs,d)); \ - b = L_add(Mpy_32_xx(as,d),Mpy_32_xx(bs,c)); - - -#define cplxMpy4_4_0(re,im,a,b,c,d) re = L_shr(L_sub(Mpy_32_xx(a,c),Mpy_32_xx(b,d)),SCALEFACTOR60-SCALEFACTOR15); \ - im = L_shr(L_add(Mpy_32_xx(a,d),Mpy_32_xx(b,c)),SCALEFACTOR60-SCALEFACTOR15); - -#define cplxMpy4_4_1(re,im,a,b) re = L_shr(a,SCALEFACTOR60-SCALEFACTOR15); \ - im = L_shr(b,SCALEFACTOR60-SCALEFACTOR15); - -#define cplxMpy4_8_0(re,im,a,b,c,d) re = L_shr(L_sub(Mpy_32_xx(a,c),Mpy_32_xx(b,d)),1); \ - im = L_shr(L_add(Mpy_32_xx(a,d),Mpy_32_xx(b,c)),1); - -#define cplxMpy4_8_1(re,im,a,b) re = L_shr(a,1); \ - im = L_shr(b,1); -/* -re = a*c - b*d -im = a*d + b*c -*/ -#if (SCALEFACTOR20 == SCALEFACTOR10) -#define cplxMpy4_10_0(re,im,a,b,c,d) re = L_sub(Mpy_32_xx(a,c),Mpy_32_xx(b,d)); move32(); \ - im = L_add(Mpy_32_xx(a,d),Mpy_32_xx(b,c)); move32(); - -#define cplxMpy4_10_1(re,im,a,b) re = (a); move32(); \ - im = (b); move32(); -#else -#define cplxMpy4_10_0(re,im,a,b,c,d) re = L_shr(L_sub(Mpy_32_xx(a,c),Mpy_32_xx(b,d)),SCALEFACTOR20-SCALEFACTOR10); move32(); \ - im = L_shr(L_add(Mpy_32_xx(a,d),Mpy_32_xx(b,c)),SCALEFACTOR20-SCALEFACTOR10); move32(); - -#define cplxMpy4_10_1(re,im,a,b) re = L_shr(a,SCALEFACTOR20-SCALEFACTOR10); move32(); \ - im = L_shr(b,SCALEFACTOR20-SCALEFACTOR10); move32(); -#endif - - -#if (SCALEFACTOR20 == SCALEFACTOR30) -#define cplxMpy4_20_30_0(re,im,a,b,c,d) re = L_sub(Mpy_32_xx(a,c),Mpy_32_xx(b,d)); move32(); \ - im = L_add(Mpy_32_xx(a,d),Mpy_32_xx(b,c)); move32(); - -#define cplxMpy4_20_30_1(re,im,a,b) re = (a); move32(); \ - im = (b); move32(); -#else -#define cplxMpy4_20_30_0(re,im,a,b,c,d) re = L_shr(L_sub(Mpy_32_xx(a,c),Mpy_32_xx(b,d)),SCALEFACTOR20-SCALEFACTOR30); move32(); \ - im = L_shr(L_add(Mpy_32_xx(a,d),Mpy_32_xx(b,c)),SCALEFACTOR20-SCALEFACTOR30); move32(); - -#define cplxMpy4_20_30_1(re,im,a,b) re = L_shr(a,SCALEFACTOR20-SCALEFACTOR30); move32(); \ - im = L_shr(b,SCALEFACTOR20-SCALEFACTOR30); move32(); -#endif - - -#define cplxMpy4_12_0(re,im,a,b,c,d) re = L_shr(L_sub(Mpy_32_xx(a,c),Mpy_32_xx(b,d)),SCALEFACTOR16-SCALEFACTOR12); move32(); \ - im = L_shr(L_add(Mpy_32_xx(a,d),Mpy_32_xx(b,c)),SCALEFACTOR16-SCALEFACTOR12); move32(); - -#define cplxMpy4_12_1(re,im,a,b) re = L_shr(a,SCALEFACTOR16-SCALEFACTOR12); move32(); \ - im = L_shr(b,SCALEFACTOR16-SCALEFACTOR12); move32(); - -#define cplxMpy4_16_0(re,im,a,b,c,d) re = L_shr(L_sub(Mpy_32_xx(a,c),Mpy_32_xx(b,d)),SCALEFACTOR16); move32(); \ - im = L_shr(L_add(Mpy_32_xx(a,d),Mpy_32_xx(b,c)),SCALEFACTOR16); move32(); - -#define cplxMpy4_16_1(re,im,a,b) re = L_shr(a,SCALEFACTOR16); move32(); \ - im = L_shr(b,SCALEFACTOR16); move32(); - - -#define cplxMpy4_5_0(re,im,a,b,c,d) re = L_shr(L_sub(Mpy_32_xx(a,c),Mpy_32_xx(b,d)),SCALEFACTORN2); \ - im = L_shr(L_add(Mpy_32_xx(a,d),Mpy_32_xx(b,c)),SCALEFACTORN2); - -#define cplxMpy4_5_1(re,im,a,b) re = L_shr(a,SCALEFACTORN2); \ - im = L_shr(b,SCALEFACTORN2); - - - -/** - * \brief Function performs a complex 5-point FFT - * The FFT is performed inplace. The result of the FFT - * is scaled by SCALEFACTOR5 bits. - * - * WOPS with 32x16 bit multiplications: 88 cycles - * - * \param [i/o] re real input / output - * \param [i/o] im imag input / output - * \param [i ] s stride real and imag input / output - * - * \return void - */ -static void fft5(Word32 *re, Word32 *im, Word16 s) +static float fmac(float a, float b, float c) { - Word32 x0,x1,x2,x3,x4; - Word32 r1,r2,r3,r4; - Word32 s1,s2,s3,s4; - Word32 t; + return (((a) * (b)) + (c)); +} +static float fnms(float a, float b, float c) +{ + return ((c) - ((a) * (b))); +} - /* */ +/*-----------------------------------------------------------------* + * fft15_shift2() + * 15-point FFT with 2-point circular shift + *-----------------------------------------------------------------*/ - /* real part */ - x0 = L_shr(re[s*0],SCALEFACTOR5); - x1 = L_shr(re[s*1],SCALEFACTOR5); - x2 = L_shr(re[s*2],SCALEFACTOR5); - x3 = L_shr(re[s*3],SCALEFACTOR5); - x4 = L_shr(re[s*4],SCALEFACTOR5); +static void fft15_shift2( + int n1, /* i : length of data */ + float *zRe, /* i/o : real part of input and output data */ + float *zIm, /* i/o : imaginary part of input and output data */ + const short *Idx /* i : pointer of the address table */ +) +{ + float T5, T2l, Tx, TV, T1C, T20, Tl, Tq, Tr, TN, TS, TT, T2c, T2d, T2n; + float T1O, T1P, T22, T1l, T1q, T1w, TZ, T10, T11, Ta, Tf, Tg, TC, TH, TI; + float T2f, T2g, T2m, T1R, T1S, T21, T1a, T1f, T1v, TW, TX, TY; + short i0,i1,i2,i3,i4,i5,i6,i7,i8,i9,i10,i11,i12,i13,i14; + float T1, T1z, T4, T1y, Tw, T1A, Tt, T1B; + float T2, T3, Tu, Tv; + float Th, Tk, TJ, T1h, T1i, T1j, TM, T1k, Tm, Tp, TO, T1m, T1n, T1o, TR; + float T1p; + float Ti, Tj, TK, TL; + float Tn, To, TP, TQ; + float T6, T9, Ty, T16, T17, T18, TB, T19, Tb, Te, TD, T1b, T1c, T1d, TG; + float T1e; + float T7, T8, Tz, TA; + float T2a, Ts, T29, T2i, T2k, T2e, T2h, T2j, T2b; + float T2q, T2o, T2p, T2u, T2w, T2s, T2t, T2v, T2r; + float Tc, Td, TE, TF; + float T1M, TU, T1L, T1U, T1W, T1Q, T1T, T1V, T1N; + float T25, T23, T24, T1Z, T28, T1X, T1Y, T27, T26; + float T1x, T1D, T1E, T1I, T1J, T1G, T1H, T1K, T1F; + float T13, T12, T14, T1s, T1u, T1g, T1r, T1t, T15; - r1 = L_add(x1,x4); - r4 = L_sub(x1,x4); - r3 = L_add(x2,x3); - r2 = L_sub(x2,x3); - t = Mpy_32_xx(L_sub(r1,r3),C54); - r1 = L_add(r1,r3); - re[0] = L_add(x0,r1); - move32(); - /* Bit shift left because of the constant C55 which was scaled with the factor 0.5 because of the representation of - the values as fracts */ - r1 = L_add(re[0],(L_shl(Mpy_32_xx(r1,C55),1))); - r3 = L_sub(r1,t); - r1 = L_add(r1,t); - t = Mpy_32_xx(L_add(r4,r2),C51); - /* Bit shift left because of the constant C55 which was scaled with the factor 0.5 because of the representation of - the values as fracts */ - r4 = L_add(t,L_shl(Mpy_32_xx(r4, C52),1)); - r2 = L_add(t,Mpy_32_xx(r2,C53)); + i0 = Idx[0]; + i1 = Idx[n1]; + i2 = Idx[n1*2]; + i3 = Idx[n1*3]; + i4 = Idx[n1*4]; + i5 = Idx[n1*5]; + i6 = Idx[n1*6]; + i7 = Idx[n1*7]; + i8 = Idx[n1*8]; + i9 = Idx[n1*9]; + i10 = Idx[n1*10]; + i11 = Idx[n1*11]; + i12 = Idx[n1*12]; + i13 = Idx[n1*13]; + i14 = Idx[n1*14]; - /* imaginary part */ - x0 = L_shr(im[s*0],SCALEFACTOR5); - x1 = L_shr(im[s*1],SCALEFACTOR5); - x2 = L_shr(im[s*2],SCALEFACTOR5); - x3 = L_shr(im[s*3],SCALEFACTOR5); - x4 = L_shr(im[s*4],SCALEFACTOR5); + T1 = zRe[i0]; + T1z = zIm[i0]; - s1 = L_add(x1,x4); - s4 = L_sub(x1,x4); - s3 = L_add(x2,x3); - s2 = L_sub(x2,x3); - t = Mpy_32_xx(L_sub(s1,s3),C54); - s1 = L_add(s1,s3); - im[0] = L_add(x0,s1); - move32(); - /* Bit shift left because of the constant C55 which was scaled with the factor 0.5 because of the representation of - the values as fracts */ - s1 = L_add(im[0],L_shl(Mpy_32_xx(s1,C55),1)); - s3 = L_sub(s1,t); - s1 = L_add(s1,t); - t = Mpy_32_xx(L_add(s4,s2),C51); - /* Bit shift left because of the constant C55 which was scaled with the factor 0.5 because of the representation of - the values as fracts */ - s4 = L_add(t,L_shl(Mpy_32_xx(s4,C52),1)); - s2 = L_add(t,Mpy_32_xx(s2,C53)); + T2 = zRe[i5]; + T3 = zRe[i10]; + T4 = T2 + T3; + T1y = KP866025403 * (T3 - T2); + Tu = zIm[i5]; + Tv = zIm[i10]; + Tw = KP866025403 * (Tu - Tv); + T1A = Tu + Tv; - /* combination */ - re[s*1] = L_add(r1,s2); - move32(); - re[s*4] = L_sub(r1,s2); - move32(); - re[s*2] = L_sub(r3,s4); - move32(); - re[s*3] = L_add(r3,s4); - move32(); + T5 = T1 + T4; + T2l = T1z + T1A; + Tt = fnms(0.5, T4, T1); + Tx = Tt - Tw; + TV = Tt + Tw; + T1B = fnms(0.5, T1A, T1z); + T1C = T1y + T1B; + T20 = T1B - T1y; - im[s*1] = L_sub(s1,r2); - move32(); - im[s*4] = L_add(s1,r2); - move32(); - im[s*2] = L_add(s3,r4); - move32(); - im[s*3] = L_sub(s3,r4); - move32(); + Th = zRe[i6]; + Ti = zRe[i11]; + Tj = zRe[i1]; + Tk = Ti + Tj; + TJ = fnms(0.5, Tk, Th); + T1h = KP866025403 * (Tj - Ti); + T1i = zIm[i6]; + TK = zIm[i11]; + TL = zIm[i1]; + T1j = TK + TL; + TM = KP866025403 * (TK - TL); + T1k = fnms(0.5, T1j, T1i); + Tm = zRe[i9]; + Tn = zRe[i14]; + To = zRe[i4]; + Tp = Tn + To; + TO = fnms(0.5, Tp, Tm); + T1m = KP866025403 * (To - Tn); + T1n = zIm[i9]; + TP = zIm[i14]; + TQ = zIm[i4]; + T1o = TP + TQ; + TR = KP866025403 * (TP - TQ); + T1p = fnms(0.5, T1o, T1n); + Tl = Th + Tk; + Tq = Tm + Tp; + Tr = Tl + Tq; + TN = TJ - TM; + TS = TO - TR; + TT = TN + TS; + T2c = T1i + T1j; + T2d = T1n + T1o; + T2n = T2c + T2d; + T1O = T1k - T1h; + T1P = T1p - T1m; + T22 = T1O + T1P; + T1l = T1h + T1k; + T1q = T1m + T1p; + T1w = T1l + T1q; + TZ = TJ + TM; + T10 = TO + TR; + T11 = TZ + T10; - /* */ + T6 = zRe[i3]; + T7 = zRe[i8]; + T8 = zRe[i13]; + T9 = T7 + T8; + Ty = fnms(0.5, T9, T6); + T16 = KP866025403 * (T8 - T7); + T17 = zIm[i3]; + Tz = zIm[i8]; + TA = zIm[i13]; + T18 = Tz + TA; + TB = KP866025403 * (Tz - TA); + T19 = fnms(0.5, T18, T17); + Tb = zRe[i12]; + Tc = zRe[i2]; + Td = zRe[i7]; + Te = Tc + Td; + TD = fnms(0.5, Te, Tb); + T1b = KP866025403 * (Td - Tc); + T1c = zIm[i12]; + TE = zIm[i2]; + TF = zIm[i7]; + T1d = TE + TF; + TG = KP866025403 * (TE - TF); + T1e = fnms(0.5, T1d, T1c); + Ta = T6 + T9; + Tf = Tb + Te; + Tg = Ta + Tf; + TC = Ty - TB; + TH = TD - TG; + TI = TC + TH; + T2f = T17 + T18; + T2g = T1c + T1d; + T2m = T2f + T2g; + T1R = T19 - T16; + T1S = T1e - T1b; + T21 = T1R + T1S; + T1a = T16 + T19; + T1f = T1b + T1e; + T1v = T1a + T1f; + TW = Ty + TB; + TX = TD + TG; + TY = TW + TX; + + T2a = KP559016994 * (Tg - Tr); + Ts = Tg + Tr; + T29 = fnms(KP250000000, Ts, T5); + T2e = T2c - T2d; + T2h = T2f - T2g; + T2i = fnms(KP587785252, T2h, KP951056516 * T2e); + T2k = fmac(KP951056516, T2h, KP587785252 * T2e); + zRe[i0] = T5 + Ts; + T2j = T2a + T29; + zRe[i12] = T2j - T2k; + zRe[i3] = T2j + T2k; + T2b = T29 - T2a; + zRe[i6] = T2b - T2i; + zRe[i9] = T2b + T2i; + + T2q = KP559016994 * (T2m - T2n); + T2o = T2m + T2n; + T2p = fnms(KP250000000, T2o, T2l); + T2s = Tl - Tq; + T2t = Ta - Tf; + T2u = fnms(KP587785252, T2t, KP951056516 * T2s); + T2w = fmac(KP951056516, T2t, KP587785252 * T2s); + zIm[i0] = T2l + T2o; + T2v = T2q + T2p; + zIm[i3] = T2v - T2w; + zIm[i12] = T2w + T2v; + T2r = T2p - T2q; + zIm[i9] = T2r - T2u; + zIm[i6] = T2u + T2r; + + T1M = KP559016994 * (TI - TT); + TU = TI + TT; + T1L = fnms(KP250000000, TU, Tx); + T1Q = T1O - T1P; + T1T = T1R - T1S; + T1U = fnms(KP587785252, T1T, KP951056516 * T1Q); + T1W = fmac(KP951056516, T1T, KP587785252 * T1Q); + zRe[i10] = Tx + TU; + T1V = T1M + T1L; + zRe[i7] = T1V - T1W; + zRe[i13] = T1V + T1W; + T1N = T1L - T1M; + zRe[i1] = T1N - T1U; + zRe[i4] = T1N + T1U; + + T25 = KP559016994 * (T21 - T22); + T23 = T21 + T22; + T24 = fnms(KP250000000, T23, T20); + T1X = TN - TS; + T1Y = TC - TH; + T1Z = fnms(KP587785252, T1Y, KP951056516 * T1X); + T28 = fmac(KP951056516, T1Y, KP587785252 * T1X); + zIm[i10] = T20 + T23; + T27 = T25 + T24; + zIm[i13] = T27 - T28; + zIm[i7] = T28 + T27; + T26 = T24 - T25; + zIm[i1] = T1Z + T26; + zIm[i4] = T26 - T1Z; + + T1x = KP559016994 * (T1v - T1w); + T1D = T1v + T1w; + T1E = fnms(KP250000000, T1D, T1C); + T1G = TW - TX; + T1H = TZ - T10; + T1I = fmac(KP951056516, T1G, KP587785252 * T1H); + T1J = fnms(KP587785252, T1G, KP951056516 * T1H); + zIm[i5] = T1C + T1D; + T1K = T1E - T1x; + zIm[i11] = T1J + T1K; + zIm[i14] = T1K - T1J; + T1F = T1x + T1E; + zIm[i8] = T1F - T1I; + zIm[i2] = T1I + T1F; + + T13 = KP559016994 * (TY - T11); + T12 = TY + T11; + T14 = fnms(KP250000000, T12, TV); + T1g = T1a - T1f; + T1r = T1l - T1q; + T1s = fmac(KP951056516, T1g, KP587785252 * T1r); + T1u = fnms(KP587785252, T1g, KP951056516 * T1r); + zRe[i5] = TV + T12; + T1t = T14 - T13; + zRe[i11] = T1t - T1u; + zRe[i14] = T1t + T1u; + T15 = T13 + T14; + zRe[i2] = T15 - T1s; + zRe[i8] = T15 + T1s; + + return; +} + +/*-----------------------------------------------------------------* + * fft15_shift8() + * 15-point FFT with 8-point circular shift + *-----------------------------------------------------------------*/ + +static void fft15_shift8( + int n1, /* i : length of data */ + float *zRe, /* i/o : real part of input and output data */ + float *zIm, /* i/o : imaginary part of input and output data */ + const short *Idx /* i : pointer of the address table */ +) +{ + float T5, T2l, Tx, TV, T1C, T20, Tl, Tq, Tr, TN, TS, TT, T2c, T2d, T2n; + float T1O, T1P, T22, T1l, T1q, T1w, TZ, T10, T11, Ta, Tf, Tg, TC, TH, TI; + float T2f, T2g, T2m, T1R, T1S, T21, T1a, T1f, T1v, TW, TX, TY; + short i0,i1,i2,i3,i4,i5,i6,i7,i8,i9,i10,i11,i12,i13,i14; + float T1, T1z, T4, T1y, Tw, T1A, Tt, T1B; + float T2, T3, Tu, Tv; + float Th, Tk, TJ, T1h, T1i, T1j, TM, T1k, Tm, Tp, TO, T1m, T1n, T1o, TR; + float T1p; + float Ti, Tj, TK, TL; + float Tn, To, TP, TQ; + float T6, T9, Ty, T16, T17, T18, TB, T19, Tb, Te, TD, T1b, T1c, T1d, TG; + float T1e; + float T7, T8, Tz, TA; + float Tc, Td, TE, TF; + float T2a, Ts, T29, T2i, T2k, T2e, T2h, T2j, T2b; + float T2q, T2o, T2p, T2u, T2w, T2s, T2t, T2v, T2r; + float T1M, TU, T1L, T1U, T1W, T1Q, T1T, T1V, T1N; + float T25, T23, T24, T1Z, T28, T1X, T1Y, T27, T26; + float T1x, T1D, T1E, T1I, T1J, T1G, T1H, T1K, T1F; + float T13, T12, T14, T1s, T1u, T1g, T1r, T1t, T15; + + i0 = Idx[0] ; + i1 = Idx[n1]; + i2 = Idx[n1*2]; + i3 = Idx[n1*3]; + i4 = Idx[n1*4]; + i5 = Idx[n1*5]; + i6 = Idx[n1*6]; + i7 = Idx[n1*7]; + i8 = Idx[n1*8]; + i9 = Idx[n1*9]; + i10 = Idx[n1*10]; + i11 = Idx[n1*11]; + i12 = Idx[n1*12]; + i13 = Idx[n1*13]; + i14 = Idx[n1*14]; + + T1 = zRe[i0]; + T1z = zIm[i0]; + + T2 = zRe[i5]; + T3 = zRe[i10]; + T4 = T2 + T3; + T1y = KP866025403 * (T3 - T2); + Tu = zIm[i5]; + Tv = zIm[i10]; + Tw = KP866025403 * (Tu - Tv); + T1A = Tu + Tv; + + T5 = T1 + T4; + T2l = T1z + T1A; + Tt = fnms(0.5, T4, T1); + Tx = Tt - Tw; + TV = Tt + Tw; + T1B = fnms(0.5, T1A, T1z); + T1C = T1y + T1B; + T20 = T1B - T1y; + + Th = zRe[i6]; + Ti = zRe[i11]; + Tj = zRe[i1]; + Tk = Ti + Tj; + TJ = fnms(0.5, Tk, Th); + T1h = KP866025403 * (Tj - Ti); + T1i = zIm[i6]; + TK = zIm[i11]; + TL = zIm[i1]; + T1j = TK + TL; + TM = KP866025403 * (TK - TL); + T1k = fnms(0.5, T1j, T1i); + Tm = zRe[i9]; + Tn = zRe[i14]; + To = zRe[i4]; + Tp = Tn + To; + TO = fnms(0.5, Tp, Tm); + T1m = KP866025403 * (To - Tn); + T1n = zIm[i9]; + TP = zIm[i14]; + TQ = zIm[i4]; + T1o = TP + TQ; + TR = KP866025403 * (TP - TQ); + T1p = fnms(0.5, T1o, T1n); + Tl = Th + Tk; + Tq = Tm + Tp; + Tr = Tl + Tq; + TN = TJ - TM; + TS = TO - TR; + TT = TN + TS; + T2c = T1i + T1j; + T2d = T1n + T1o; + T2n = T2c + T2d; + T1O = T1k - T1h; + T1P = T1p - T1m; + T22 = T1O + T1P; + T1l = T1h + T1k; + T1q = T1m + T1p; + T1w = T1l + T1q; + TZ = TJ + TM; + T10 = TO + TR; + T11 = TZ + T10; + + T6 = zRe[i3]; + T7 = zRe[i8]; + T8 = zRe[i13]; + T9 = T7 + T8; + Ty = fnms(0.5, T9, T6); + T16 = KP866025403 * (T8 - T7); + T17 = zIm[i3]; + Tz = zIm[i8]; + TA = zIm[i13]; + T18 = Tz + TA; + TB = KP866025403 * (Tz - TA); + T19 = fnms(0.5, T18, T17); + Tb = zRe[i12]; + Tc = zRe[i2]; + Td = zRe[i7]; + Te = Tc + Td; + TD = fnms(0.5, Te, Tb); + T1b = KP866025403 * (Td - Tc); + T1c = zIm[i12]; + TE = zIm[i2]; + TF = zIm[i7]; + T1d = TE + TF; + TG = KP866025403 * (TE - TF); + T1e = fnms(0.5, T1d, T1c); + Ta = T6 + T9; + Tf = Tb + Te; + Tg = Ta + Tf; + TC = Ty - TB; + TH = TD - TG; + TI = TC + TH; + T2f = T17 + T18; + T2g = T1c + T1d; + T2m = T2f + T2g; + T1R = T19 - T16; + T1S = T1e - T1b; + T21 = T1R + T1S; + T1a = T16 + T19; + T1f = T1b + T1e; + T1v = T1a + T1f; + TW = Ty + TB; + TX = TD + TG; + TY = TW + TX; + + T2a = KP559016994 * (Tg - Tr); + Ts = Tg + Tr; + T29 = fnms(KP250000000, Ts, T5); + T2e = T2c - T2d; + T2h = T2f - T2g; + T2i = fnms(KP587785252, T2h, KP951056516 * T2e); + T2k = fmac(KP951056516, T2h, KP587785252 * T2e); + zRe[i0] = T5 + Ts; + T2j = T2a + T29; + zRe[i3] = T2j - T2k; + zRe[i12] = T2j + T2k; + T2b = T29 - T2a; + zRe[i9] = T2b - T2i; + zRe[i6] = T2b + T2i; + + T2q = KP559016994 * (T2m - T2n); + T2o = T2m + T2n; + T2p = fnms(KP250000000, T2o, T2l); + T2s = Tl - Tq; + T2t = Ta - Tf; + T2u = fnms(KP587785252, T2t, KP951056516 * T2s); + T2w = fmac(KP951056516, T2t, KP587785252 * T2s); + zIm[i0] = T2l + T2o; + T2v = T2q + T2p; + zIm[i12] = T2v - T2w; + zIm[i3] = T2w + T2v; + T2r = T2p - T2q; + zIm[i6] = T2r - T2u; + zIm[i9] = T2u + T2r; + + T1M = KP559016994 * (TI - TT); + TU = TI + TT; + T1L = fnms(KP250000000, TU, Tx); + T1Q = T1O - T1P; + T1T = T1R - T1S; + T1U = fnms(KP587785252, T1T, KP951056516 * T1Q); + T1W = fmac(KP951056516, T1T, KP587785252 * T1Q); + zRe[i10] = Tx + TU; + T1V = T1M + T1L; + zRe[i13] = T1V - T1W; + zRe[i7] = T1V + T1W; + T1N = T1L - T1M; + zRe[i4] = T1N - T1U; + zRe[i1] = T1N + T1U; + + T25 = KP559016994 * (T21 - T22); + T23 = T21 + T22; + T24 = fnms(KP250000000, T23, T20); + T1X = TN - TS; + T1Y = TC - TH; + T1Z = fnms(KP587785252, T1Y, KP951056516 * T1X); + T28 = fmac(KP951056516, T1Y, KP587785252 * T1X); + zIm[i10] = T20 + T23; + T27 = T25 + T24; + zIm[i7] = T27 - T28; + zIm[i13] = T28 + T27; + T26 = T24 - T25; + zIm[i4] = T1Z + T26; + zIm[i1] = T26 - T1Z; + + T1x = KP559016994 * (T1v - T1w); + T1D = T1v + T1w; + T1E = fnms(KP250000000, T1D, T1C); + T1G = TW - TX; + T1H = TZ - T10; + T1I = fmac(KP951056516, T1G, KP587785252 * T1H); + T1J = fnms(KP587785252, T1G, KP951056516 * T1H); + zIm[i5] = T1C + T1D; + T1K = T1E - T1x; + zIm[i14] = T1J + T1K; + zIm[i11] = T1K - T1J; + T1F = T1x + T1E; + zIm[i2] = T1F - T1I; + zIm[i8] = T1I + T1F; + + T13 = KP559016994 * (TY - T11); + T12 = TY + T11; + T14 = fnms(KP250000000, T12, TV); + T1g = T1a - T1f; + T1r = T1l - T1q; + T1s = fmac(KP951056516, T1g, KP587785252 * T1r); + T1u = fnms(KP587785252, T1g, KP951056516 * T1r); + zRe[i5] = TV + T12; + T1t = T14 - T13; + zRe[i14] = T1t - T1u; + zRe[i11] = T1t + T1u; + T15 = T13 + T14; + zRe[i8] = T15 - T1s; + zRe[i2] = T15 + T1s; + + return; +} + +/*-----------------------------------------------------------------* + * fft5_shift1() + * 5-point FFT with 1-point circular shift + *-----------------------------------------------------------------*/ + +static void fft5_shift1( + int n1, /* i : length of data */ + float *zRe, /* i/o : real part of input and output data */ + float *zIm, /* i/o : imaginary part of input and output data */ + const short *Idx /* i : pointer of the address table */ +) +{ + float T1, To, T8, Tt, T9, Ts, Te, Tp, Th, Tn,T2, T3, T4, T5, T6, T7; + short i0,i1,i2,i3,i4; + + i0 = Idx[0]; + i1 = Idx[n1]; + i2 = Idx[n1*2]; + i3 = Idx[n1*3]; + i4 = Idx[n1*4]; + + T1 = zRe[i0]; + To = zIm[i0]; + + T2 = zRe[i1]; + T3 = zRe[i4]; + T4 = T2 + T3; + T5 = zRe[i2]; + T6 = zRe[i3]; + T7 = T5 + T6; + T8 = T4 + T7; + Tt = T5 - T6; + T9 = KP559016994 * (T4 - T7); + Ts = T2 - T3; + + T2 = zIm[i1]; + T3 = zIm[i4]; + T4 = T2 + T3; + T5 = zIm[i2]; + T6 = zIm[i3]; + T7 = T5 + T6; + Te = T2 - T3; + Tp = T4 + T7; + Th = T5 - T6; + Tn = KP559016994 * (T4 - T7); + + zRe[i0] = T1 + T8; + zIm[i0] = To + Tp; + + T2 = KP951056516*Te + KP587785252*Th; + T3 = KP951056516*Th - KP587785252*Te; + T6 = T1-T8/4; + T4 = T9 + T6; + T5 = T6 - T9; + + zRe[i4] = T4 - T2; + zRe[i3] = T5 + T3; + zRe[i1] = T4 + T2; + zRe[i2] = T5 - T3; + + T2 = KP951056516 * Ts + KP587785252 * Tt; + T3 = KP951056516 * Tt - KP587785252 * Ts; + T6 = To-Tp/4; + T4 = Tn + T6; + T5 = T6 - Tn; + + zIm[i1] = T4 - T2; + zIm[i3] = T5 - T3; + zIm[i4] = T2 + T4; + zIm[i2] = T3 + T5; + + return; +} + +/*-----------------------------------------------------------------* + * fft5_shift4() + * 5-point FFT with 4-point circular shift + *-----------------------------------------------------------------*/ + +static void fft5_shift4( + int n1, /* i : length of data */ + float *zRe, /* i/o : real part of input and output data */ + float *zIm, /* i/o : imaginary part of input and output data */ + const short *Idx /* i : pointer of the address table */ +) +{ + float T1, To, T8, Tt, T9, Ts, Te, Tp, Th, Tn,T2, T3, T4, T5, T6, T7; + short i0,i1,i2,i3,i4; + + i0 = Idx[0]; + i1 = Idx[n1]; + i2 = Idx[n1*2]; + i3 = Idx[n1*3]; + i4 = Idx[n1*4]; + + T1 = zRe[i0]; + To = zIm[i0]; + + T2 = zRe[i1]; + T3 = zRe[i4]; + T4 = T2 + T3; + T5 = zRe[i2]; + T6 = zRe[i3]; + T7 = T5 + T6; + T8 = T4 + T7; + Tt = T5 - T6; + T9 = KP559016994 * (T4 - T7); + Ts = T2 - T3; + + T2 = zIm[i1]; + T3 = zIm[i4]; + T4 = T2 + T3; + T5 = zIm[i2]; + T6 = zIm[i3]; + T7 = T5 + T6; + Te = T2 - T3; + Tp = T4 + T7; + Th = T5 - T6; + Tn = KP559016994 * (T4 - T7); + + zRe[i0] = T1 + T8; + zIm[i0] = To + Tp; + + T2 = KP951056516*Te + KP587785252*Th; + T3 = KP951056516*Th - KP587785252*Te; + T6 = T1-T8/4; + T4 = T9 + T6; + T5 = T6 - T9; + zRe[i1] = T4 - T2; + zRe[i2] = T5 + T3; + zRe[i4] = T4 + T2; + zRe[i3] = T5 - T3; + + T2 = KP951056516 * Ts + KP587785252 * Tt; + T3 = KP951056516 * Tt - KP587785252 * Ts; + T6 = To-Tp/4; + T4 = Tn + T6; + T5 = T6 - Tn; + zIm[i4] = T4 - T2; + zIm[i2] = T5 - T3; + zIm[i1] = T2 + T4; + zIm[i3] = T3 + T5; + + return; +} + +/*-----------------------------------------------------------------* + * fft5_32() + * 5-point FFT called for 32 times + *-----------------------------------------------------------------*/ + +static void fft5_32( + float *zRe, /* i/o : real part of input and output data */ + float *zIm, /* i/o : imaginary part of input and output data */ + const short *Idx /* i : pointer of the address table */ +) +{ + float T1, To, T8, Tt, T9, Ts, Te, Tp, Th, Tn,T2, T3, T4, T5, T6, T7; + short i0,i1,i2,i3,i4; + + i0 = Idx[0]; + i1 = Idx[32]; + i2 = Idx[64]; + i3 = Idx[96]; + i4 = Idx[128]; + + T1 = zRe[i0]; + To = zIm[i0]; + + T2 = zRe[i1]; + T3 = zRe[i4]; + T4 = T2 + T3; + T5 = zRe[i2]; + T6 = zRe[i3]; + T7 = T5 + T6; + T8 = T4 + T7; + Tt = T5 - T6; + T9 = KP559016994 * (T4 - T7); + Ts = T2 - T3; + + T2 = zIm[i1]; + T3 = zIm[i4]; + T4 = T2 + T3; + T5 = zIm[i2]; + T6 = zIm[i3]; + T7 = T5 + T6; + Te = T2 - T3; + Tp = T4 + T7; + Th = T5 - T6; + Tn = KP559016994 * (T4 - T7); + + zRe[i0] = T1 + T8; + zIm[i0] = To + Tp; + + T2 = KP951056516*Te + KP587785252*Th; + T3 = KP951056516*Th - KP587785252*Te; + T6 = T1-T8/4; + T4 = T9 + T6; + T5 = T6 - T9; + zRe[i3] = T4 - T2; + zRe[i1] = T5 + T3; + zRe[i2] = T4 + T2; + zRe[i4] = T5 - T3; + + T2 = KP951056516 * Ts + KP587785252 * Tt; + T3 = KP951056516 * Tt - KP587785252 * Ts; + T6 = To-Tp/4; + T4 = Tn + T6; + T5 = T6 - Tn; + zIm[i2] = T4 - T2; + zIm[i1] = T5 - T3; + zIm[i3] = T2 + T4; + zIm[i4] = T3 + T5; + + return; +} + +/*-----------------------------------------------------------------* + * fft64() + * 64-point FFT + *-----------------------------------------------------------------*/ + +static void fft64( + float *x, /* i/o : real part of input and output data */ + float *y, /* i/o : imaginary part of input and output data */ + const short *Idx /* i : pointer of the address table */ +) +{ + short i,id,jd; + float z[128]; + for ( i=0; i<64; i++ ) + { + id = Idx[i]; + z[2*i] = x[id]; + z[2*i+1] = y[id]; + } + + cdftForw(128,z,Ip_fft64,w_fft64); + + for( i=0; i<64 ; i++) + { + jd = Odx_fft64[i]; + id = Idx[jd]; + x[id]=z[2*i]; + y[id]=z[2*i+1]; + } + + return; } +/*-----------------------------------------------------------------* + * fft32_15() + * 32-point FFT called for 15 times + *-----------------------------------------------------------------*/ + +static void fft32_15( + float *x, /* i/o : real part of input and output data */ + float *y, /* i/o : imaginary part of input and output data */ + const short *Idx /* i : pointer of the address table */ +) +{ + short i,id,jd; + float z[64]; + + for( i=0; i<32; i++ ) + { + id = Idx[i]; + z[2*i] = x[id]; + z[2*i+1] = y[id]; + } + + cdftForw(64,z,Ip_fft32,w_fft32); + + for( i=0; i<32; i++ ) + { + jd = Odx_fft32_15[i]; + id = Idx[jd]; + x[id]=z[2*i]; + y[id]=z[2*i+1]; + } + + return; +} + +/*-----------------------------------------------------------------* + * fft32_5() + * 32-point FFT called for 5 times + *-----------------------------------------------------------------*/ + +static void fft32_5( + float *x, /* i/o : real part of input and output data */ + float *y, /* i/o : imaginary part of input and output data */ + const short *Idx /* i : pointer of the address table */ +) +{ + short i,id,jd; + float z[64]; + + for( i=0; i<32; i++ ) + { + id = Idx[i]; + z[2*i] = x[id]; + z[2*i+1] = y[id]; + } + + cdftForw(64,z,Ip_fft32,w_fft32); + + for( i=0; i<32; i++ ) + { + jd = Odx_fft32_5[i]; + id = Idx[jd]; + x[id]=z[2*i]; + y[id]=z[2*i+1]; + } + + return; +} + +/*-----------------------------------------------------------------* + * fft16() + * 16-point FFT + *-----------------------------------------------------------------*/ + +static void fft16( + float *x, /* i/o : real part of input and output data */ + float *y, /* i/o : imaginary part of input and output data */ + const short *Idx /* i : pointer of the address table */ +) +{ + short i,id,jd; + float z[32]; + + for(i=0; i<16 ; i++) + { + id = Idx[i]; + z[2*i] = x[id]; + z[2*i+1] = y[id]; + } + + cdftForw(32,z,Ip_fft16,w_fft16); + + for(i=0; i<16; i++) + { + jd = Odx_fft16[i]; + id = Idx[jd]; + x[id]=z[2*i]; + y[id]=z[2*i+1]; + } + + return; +} + +/*-----------------------------------------------------------------* + * fft8() + * 8-point FFT + *-----------------------------------------------------------------*/ + +static void fft8( + float *x, /* i/o : real part of input and output data */ + float *y, /* i/o : imaginary part of input and output data */ + const short *Idx /* i : pointer of the address table */ +) +{ + short i,id; + float z[16]; + + for(i=0; i<8; i++) + { + id = Idx[i]; + z[2*i] = x[id]; + z[2*i+1] = y[id]; + } + + cdftForw(16,z,Ip_fft8,w_fft8); + + for(i=0; i<8; i++) + { + id = Idx[i]; + x[id]=z[2*i]; + y[id]=z[2*i+1]; + } + + return; +} + +/*-----------------------------------------------------------------* + * fft8_5() + * 8-point FFT with shift 5 + *-----------------------------------------------------------------*/ + +static void fft8_5( + float *x, /* i/o : real part of input and output data */ + float *y, /* i/o : imaginary part of input and output data */ + const short *Idx /* i : pointer of the address table */ +) +{ + short i,id,jd; + float z[16]; + + for(i=0; i<8; i++) + { + id = Idx[i]; + z[2*i] = x[id]; + z[2*i+1] = y[id]; + } + + cdftForw(16,z,Ip_fft8,w_fft8); + + for(i=0; i<8; i++) + { + jd = Odx_fft8_5[i]; + id = Idx[jd]; + x[id]=z[2*i]; + y[id]=z[2*i+1]; + } + return; +} + +/*-----------------------------------------------------------------* +* fft5_8() +* 5-point FFT with shift 2 +*-----------------------------------------------------------------*/ + +static void fft5_8( + int n1, /* i : length of data */ + float *zRe, /* i/o : real part of input and output data */ + float *zIm, /* i/o : imaginary part of input and output data */ + const short *Idx /* i : pointer of the address table */ +) +{ + float T1, To, T8, Tt, T9, Ts, Te, Tp, Th, Tn,T2, T3, T4, T5, T6, T7; + short i0,i1,i2,i3,i4; + + i0 = Idx[0]; + i1 = Idx[n1]; + i2 = Idx[n1*2]; + i3 = Idx[n1*3]; + i4 = Idx[n1*4]; + + T1 = zRe[i0]; + To = zIm[i0]; + + T2 = zRe[i1]; + T3 = zRe[i4]; + T4 = T2 + T3; + T5 = zRe[i2]; + T6 = zRe[i3]; + T7 = T5 + T6; + T8 = T4 + T7; + Tt = T5 - T6; + T9 = KP559016994 * (T4 - T7); + Ts = T2 - T3; + + T2 = zIm[i1]; + T3 = zIm[i4]; + T4 = T2 + T3; + T5 = zIm[i2]; + T6 = zIm[i3]; + T7 = T5 + T6; + Te = T2 - T3; + Tp = T4 + T7; + Th = T5 - T6; + Tn = KP559016994 * (T4 - T7); + + zRe[i0] = T1 + T8; + zIm[i0] = To + Tp; + + T2 = KP951056516*Te + KP587785252*Th; + T3 = KP951056516*Th - KP587785252*Te; + T6 = T1-T8/4; + T4 = T9 + T6; + T5 = T6 - T9; + + zRe[i2] = T4 - T2; + zRe[i4] = T5 + T3; + zRe[i3] = T4 + T2; + zRe[i1] = T5 - T3; + + T2 = KP951056516 * Ts + KP587785252 * Tt; + T3 = KP951056516 * Tt - KP587785252 * Ts; + T6 = To-Tp/4; + T4 = Tn + T6; + T5 = T6 - Tn; + + zIm[i3] = T4 - T2; + zIm[i4] = T5 - T3; + zIm[i2] = T2 + T4; + zIm[i1] = T3 + T5; + + return; +} + +/*-----------------------------------------------------------------* + * fft4_5() + * 8-point FFT with shift 1 + *-----------------------------------------------------------------*/ + +static void fft4_5( + float *x, /* i/o : real part of input and output data */ + float *y, /* i/o : imaginary part of input and output data */ + const short *Idx /* i : pointer of the address table */ +) +{ + short i,id,jd; + float z[8]; + + for(i=0; i<4; i++) + { + id = Idx[i]; + z[2*i] = x[id]; + z[2*i+1] = y[id]; + } + + cdftForw(8,z,Ip_fft4,w_fft4); + + for(i=0; i<4; i++) + { + jd = Odx_fft4_5[i]; + id = Idx[jd]; + x[id]=z[2*i]; + y[id]=z[2*i+1]; + } + return; +} + +/*-----------------------------------------------------------------* + * fft5_4() + * 5-point FFT with shift 4 + *-----------------------------------------------------------------*/ + +static void fft5_4( int n1, float *zRe, float *zIm, const short *Idx ) +{ + float T1, To, T8, Tt, T9, Ts, Te, Tp, Th, Tn,T2, T3, T4, T5, T6, T7; + short i0,i1,i2,i3,i4; + + i0 = Idx[0]; + i1 = Idx[n1]; + i2 = Idx[n1*2]; + i3 = Idx[n1*3]; + i4 = Idx[n1*4]; + + T1 = zRe[i0]; + To = zIm[i0]; + + T2 = zRe[i1]; + T3 = zRe[i4]; + T4 = T2 + T3; + T5 = zRe[i2]; + T6 = zRe[i3]; + T7 = T5 + T6; + T8 = T4 + T7; + Tt = T5 - T6; + T9 = KP559016994 * (T4 - T7); + Ts = T2 - T3; + + T2 = zIm[i1]; + T3 = zIm[i4]; + T4 = T2 + T3; + T5 = zIm[i2]; + T6 = zIm[i3]; + T7 = T5 + T6; + Te = T2 - T3; + Tp = T4 + T7; + Th = T5 - T6; + Tn = KP559016994 * (T4 - T7); + + zRe[i0] = T1 + T8; + zIm[i0] = To + Tp; + + T2 = KP951056516*Te + KP587785252*Th; + T3 = KP951056516*Th - KP587785252*Te; + T6 = T1-T8/4; + T4 = T9 + T6; + T5 = T6 - T9; + + zRe[i1] = T4 - T2; + zRe[i2] = T5 + T3; + zRe[i4] = T4 + T2; + zRe[i3] = T5 - T3; + + T2 = KP951056516 * Ts + KP587785252 * Tt; + T3 = KP951056516 * Tt - KP587785252 * Ts; + T6 = To-Tp/4; + T4 = Tn + T6; + T5 = T6 - Tn; + + zIm[i4] = T4 - T2; + zIm[i2] = T5 - T3; + zIm[i1] = T2 + T4; + zIm[i3] = T3 + T5; + + return; + +} + + +/*-----------------------------------------------------------------* + * DoRTFT80() + * a low complexity 2-dimensional DFT of 80 points + *-----------------------------------------------------------------*/ + +void DoRTFT80( + float *x, /* i/o : real part of input and output data */ + float *y /* i/o : imaginary part of input and output data */ +) +{ + short j; + + /* Applying 16-point FFT for 5 times based on the address table Idx_dortft80 */ + for(j=0; j<5; j++) + { + fft16(x,y,Idx_dortft80+16*j); + } + + /* Applying 5-point FFT for 16 times based on the address table Idx_dortft80 */ + for(j=0; j<16; j++) + { + fft5_shift1(16,x,y,Idx_dortft80+j); + } + + return; +} + +/*-----------------------------------------------------------------* + * DoRTFT120() + * a low complexity 2-dimensional DFT of 120 points + *-----------------------------------------------------------------*/ + +void DoRTFT120( + float *x, /* i/o : real part of input and output data */ + float *y /* i/o : imaginary part of input and output data */ +) +{ + short j; + + /* Applying 8-point FFT for 15 times based on the address table Idx_dortft120 */ + for(j=0; j<15; j++) + { + fft8(x,y,Idx_dortft120+8*j); + } + + /* Applying 15-point FFT for 8 times based on the address table Idx_dortft120 */ + for(j=0; j<8; j++) + { + fft15_shift2(8,x,y,Idx_dortft120+j); + } + + return; +} + +/*-----------------------------------------------------------------* + * DoRTFT160() + * a low complexity 2-dimensional DFT of 160 points + *-----------------------------------------------------------------*/ + +void DoRTFT160( + float x[], /* i/o : real part of input and output data */ + float y[] /* i/o : imaginary part of input and output data */ +) +{ + short j; + + /* Applying 32-point FFT for 5 times based on the address table Idx_dortft160 */ + for(j=0; j<5; j++) + { + fft32_5(x,y,Idx_dortft160+32*j); + } + + /* Applying 5-point FFT for 32 times based on the address table Idx_dortft160 */ + for(j=0; j<32; j++) + { + fft5_32(x,y,Idx_dortft160+j); + } + + return; +} + +/*-----------------------------------------------------------------* + * DoRTFT320() + * a low complexity 2-dimensional DFT of 320 points + *-----------------------------------------------------------------*/ + +void DoRTFT320( + float *x, /* i/o : real part of input and output data */ + float *y /* i/o : imaginary part of input and output data */ +) +{ + short j; + + /* Applying 64-point FFT for 5 times based on the address table Idx_dortft160 */ + for(j=0; j<5; j++) + { + fft64(x,y,Idx_dortft320+64*j); + } + + /* Applying 5-point FFT for 64 times based on the address table Idx_dortft160 */ + for(j=0; j<64; j++) + { + fft5_shift4(64,x,y,Idx_dortft320+j); + } + + return; +} + +/*-----------------------------------------------------------------* + * DoRTFT480() + * a low complexity 2-dimensional DFT of 480 points + *-----------------------------------------------------------------*/ + +void DoRTFT480( + float *x, /* i/o : real part of input and output data */ + float *y /* i/o : imaginary part of input and output data */ +) +{ + short j; + + /* Applying 32-point FFT for 15 times based on the address table Idx_dortft160 */ + for(j=0; j<15; j++) + { + fft32_15(x,y,Idx_dortft480+32*j); + } + + /* Applying 5-point FFT for 32 times based on the address table Idx_dortft160 */ + for(j=0; j<32; j++) + { + fft15_shift8(32,x,y,Idx_dortft480+j); + } + + return; +} + +/*-----------------------------------------------------------------* + * DoRTFT40() + * a low complexity 2-dimensional DFT of 40 points + *-----------------------------------------------------------------*/ + +void DoRTFT40( + float *x, /* i/o : real part of input and output data */ + float *y /* i/o : imaginary part of input and output data */ +) +{ + short j; + /* Applying 8-point FFT for 5 times based on the address table Idx_dortft40 */ + for(j=0; j<5; j++) + { + fft8_5(x,y,Idx_dortft40+8*j); + } + + /* Applying 5-point FFT for 8 times based on the address table Idx_dortft40 */ + for(j=0; j<8; j++) + { + fft5_8(8,x,y,Idx_dortft40+j); + } + + return; +} + +/*-----------------------------------------------------------------* + * DoRTFT20() + * a low complexity 2-dimensional DFT of 20 points + *-----------------------------------------------------------------*/ + +void DoRTFT20( + float *x, /* i/o : real part of input and output data */ + float *y /* i/o : imaginary part of input and output data */ +) +{ + short j; + + /* Applying 4-point FFT for 5 times based on the address table Idx_dortft20 */ + for(j=0; j<5; j++) + { + fft4_5(x,y,Idx_dortft20+4*j); + } + + /* Applying 5-point FFT for 4 times based on the address table Idx_dortft20 */ + for(j=0; j<4; j++) + { + fft5_4(4,x,y,Idx_dortft20+j); + } + + return; +} + +/*-----------------------------------------------------------------* + * DoRTFT128() + * FFT with 128 points + *-----------------------------------------------------------------*/ + +void DoRTFT128( + float *x, /* i/o : real part of input and output data */ + float *y /* i/o : imaginary part of input and output data */ +) +{ + + int i; + float z[256]; + + for ( i=0; i<128; i++ ) + { + z[2*i] = x[i]; + z[2*i+1] = y[i]; + } + + cdftForw(256,z,Ip_fft128,w_fft128); + + x[0]=z[0]; + y[0]=z[1]; + for( i=1; i<128 ; i++) + { + x[128-i]=z[2*i]; + y[128-i]=z[2*i+1]; + } + + return; +} + +/*-----------------------------------------------------------------* + * cdftForw() + * Main fuction of Complex Discrete Fourier Transform + *-----------------------------------------------------------------*/ + +static void cdftForw( + short n, /* i : data length of real and imag */ + float *a, /* i/o : input/output data */ + const short *ip, /* i : work area for bit reversal */ + const float *w /* i : cos/sin table */ +) +{ + /* bit reversal */ + bitrv2_SR(n, ip + 2, a); + + /* Do FFT */ + cftfsub(n, a, w); +} + +/*-----------------------------------------------------------------* + * bitrv2_SR() + * Bit reversal + *-----------------------------------------------------------------*/ + +static void bitrv2_SR( + short n, /* i : data length of real and imag */ + const short *ip, /* i/o : work area for bit reversal */ + float *a /* i/o : input/output data */ +) +{ + short j, j1, k, k1, m, m2; + short l; + float xr, xi, yr, yi; + + if (n == 64) + { + m = 4; + l = -1; + } + else if (n == 256) + { + m = 8; + l = -1; + } + else if (n == 16) + { + m = 2; + l = -1; + } + else + { + l = n; + m = 1; + + while ((m << 3) < l) + { + l >>= 1; + m <<= 1; + } + l -= m * 8; + } + + m2 = 2 * m; + + if (l == 0) + { + for (k = 0; k < m; k++) + { + for (j = 0; j < k; j++) + { + j1 = 2 * j + ip[k]; + k1 = 2 * k + ip[j]; + xr = a[j1]; + xi = a[j1 + 1]; + yr = a[k1]; + yi = a[k1 + 1]; + a[j1] = yr; + a[j1 + 1] = yi; + a[k1] = xr; + a[k1 + 1] = xi; + j1 += m2; + k1 += 2 * m2; + xr = a[j1]; + xi = a[j1 + 1]; + yr = a[k1]; + yi = a[k1 + 1]; + a[j1] = yr; + a[j1 + 1] = yi; + a[k1] = xr; + a[k1 + 1] = xi; + j1 += m2; + k1 -= m2; + xr = a[j1]; + xi = a[j1 + 1]; + yr = a[k1]; + yi = a[k1 + 1]; + a[j1] = yr; + a[j1 + 1] = yi; + a[k1] = xr; + a[k1 + 1] = xi; + j1 += m2; + k1 += 2 * m2; + xr = a[j1]; + xi = a[j1 + 1]; + yr = a[k1]; + yi = a[k1 + 1]; + a[j1] = yr; + a[j1 + 1] = yi; + a[k1] = xr; + a[k1 + 1] = xi; + } + + j1 = 2 * k + m2 + ip[k]; + k1 = j1 + m2; + xr = a[j1]; + xi = a[j1 + 1]; + yr = a[k1]; + yi = a[k1 + 1]; + a[j1] = yr; + a[j1 + 1] = yi; + a[k1] = xr; + a[k1 + 1] = xi; + } + } + else + { + for (k = 1; k < m; k++) + { + for (j = 0; j < k; j++) + { + j1 = 2 * j + ip[k]; + k1 = 2 * k + ip[j]; + xr = a[j1]; + xi = a[j1 + 1]; + yr = a[k1]; + yi = a[k1 + 1]; + a[j1] = yr; + a[j1 + 1] = yi; + a[k1] = xr; + a[k1 + 1] = xi; + j1 += m2; + k1 += m2; + xr = a[j1]; + xi = a[j1 + 1]; + yr = a[k1]; + yi = a[k1 + 1]; + a[j1] = yr; + a[j1 + 1] = yi; + a[k1] = xr; + a[k1 + 1] = xi; + } + } + } + + return; +} + +/*-----------------------------------------------------------------* + * cftfsub() + * Complex Discrete Fourier Transform + *-----------------------------------------------------------------*/ + +static void cftfsub( + short n, /* i : data length of real and imag */ + float *a, /* i/o : input/output data */ + const float *w /* i : cos/sin table */ +) +{ + short j, j1, j2, j3, l; + float x0r, x0i, x1r, x1i, x2r, x2i, x3r, x3i; + + l = 2; + if (n > 8) + { + cft1st(n, a, w); + + l = 8; + while ((l << 2) < n) + { + cftmdl(n, l, a, w); + l <<= 2; + } + } + + if ((l << 2) == n) + { + for (j = 0; j < l; j += 2) + { + j1 = j + l; + j2 = j1 + l; + j3 = j2 + l; + x0r = a[j] + a[j1]; + x0i = a[j + 1] + a[j1 + 1]; + x1r = a[j] - a[j1]; + x1i = a[j + 1] - a[j1 + 1]; + x2r = a[j2] + a[j3]; + x2i = a[j2 + 1] + a[j3 + 1]; + x3r = a[j2] - a[j3]; + x3i = a[j2 + 1] - a[j3 + 1]; + a[j] = x0r + x2r; + a[j + 1] = x0i + x2i; + a[j2] = x0r - x2r; + a[j2 + 1] = x0i - x2i; + a[j1] = x1r - x3i; + a[j1 + 1] = x1i + x3r; + a[j3] = x1r + x3i; + a[j3 + 1] = x1i - x3r; + } + } + else + { + for (j = 0; j < l; j += 2) + { + j1 = j + l; + x0r = a[j] - a[j1]; + x0i = a[j + 1] - a[j1 + 1]; + a[j] += a[j1]; + a[j + 1] += a[j1 + 1]; + a[j1] = x0r; + a[j1 + 1] = x0i; + } + } + + return; +} + +/*-----------------------------------------------------------------* + * cft1st() + * Subfunction of Complex Discrete Fourier Transform + *-----------------------------------------------------------------*/ + +static void cft1st( + short n, /* i : data length of real and imag */ + float *a, /* i/o : input/output data */ + const float *w /* i : cos/sin table */ +) +{ + short j, k1, k2; + float wk1r, wk1i, wk2r, wk2i, wk3r, wk3i; + float x0r, x0i, x1r, x1i, x2r, x2i, x3r, x3i; + + x0r = a[0] + a[2]; + x0i = a[1] + a[3]; + x1r = a[0] - a[2]; + x1i = a[1] - a[3]; + x2r = a[4] + a[6]; + x2i = a[5] + a[7]; + x3r = a[4] - a[6]; + x3i = a[5] - a[7]; + a[0] = x0r + x2r; + a[1] = x0i + x2i; + a[4] = x0r - x2r; + a[5] = x0i - x2i; + a[2] = x1r - x3i; + a[3] = x1i + x3r; + a[6] = x1r + x3i; + a[7] = x1i - x3r; + wk1r = w[2]; + x0r = a[8] + a[10]; + x0i = a[9] + a[11]; + x1r = a[8] - a[10]; + x1i = a[9] - a[11]; + x2r = a[12] + a[14]; + x2i = a[13] + a[15]; + x3r = a[12] - a[14]; + x3i = a[13] - a[15]; + a[8] = x0r + x2r; + a[9] = x0i + x2i; + a[12] = x2i - x0i; + a[13] = x0r - x2r; + x0r = x1r - x3i; + x0i = x1i + x3r; + a[10] = wk1r * (x0r - x0i); + a[11] = wk1r * (x0r + x0i); + x0r = x3i + x1r; + x0i = x3r - x1i; + a[14] = wk1r * (x0i - x0r); + a[15] = wk1r * (x0i + x0r); + k1 = 0; + + for (j = 16; j < n; j += 16) + { + k1 += 2; + k2 = 2 * k1; + wk2r = w[k1]; + wk2i = w[k1 + 1]; + wk1r = w[k2]; + wk1i = w[k2 + 1]; + wk3r = wk1r - 2 * wk2i * wk1i; + wk3i = 2 * wk2i * wk1r - wk1i; + x0r = a[j] + a[j + 2]; + x0i = a[j + 1] + a[j + 3]; + x1r = a[j] - a[j + 2]; + x1i = a[j + 1] - a[j + 3]; + x2r = a[j + 4] + a[j + 6]; + x2i = a[j + 5] + a[j + 7]; + x3r = a[j + 4] - a[j + 6]; + x3i = a[j + 5] - a[j + 7]; + a[j] = x0r + x2r; + a[j + 1] = x0i + x2i; + x0r -= x2r; + x0i -= x2i; + a[j + 4] = wk2r * x0r - wk2i * x0i; + a[j + 5] = wk2r * x0i + wk2i * x0r; + x0r = x1r - x3i; + x0i = x1i + x3r; + a[j + 2] = wk1r * x0r - wk1i * x0i; + a[j + 3] = wk1r * x0i + wk1i * x0r; + x0r = x1r + x3i; + x0i = x1i - x3r; + a[j + 6] = wk3r * x0r - wk3i * x0i; + a[j + 7] = wk3r * x0i + wk3i * x0r; + wk1r = w[k2 + 2]; + wk1i = w[k2 + 3]; + wk3r = wk1r - 2 * wk2r * wk1i; + wk3i = 2 * wk2r * wk1r - wk1i; + x0r = a[j + 8] + a[j + 10]; + x0i = a[j + 9] + a[j + 11]; + x1r = a[j + 8] - a[j + 10]; + x1i = a[j + 9] - a[j + 11]; + x2r = a[j + 12] + a[j + 14]; + x2i = a[j + 13] + a[j + 15]; + x3r = a[j + 12] - a[j + 14]; + x3i = a[j + 13] - a[j + 15]; + a[j + 8] = x0r + x2r; + a[j + 9] = x0i + x2i; + x0r -= x2r; + x0i -= x2i; + a[j + 12] = -wk2i * x0r - wk2r * x0i; + a[j + 13] = -wk2i * x0i + wk2r * x0r; + x0r = x1r - x3i; + x0i = x1i + x3r; + a[j + 10] = wk1r * x0r - wk1i * x0i; + a[j + 11] = wk1r * x0i + wk1i * x0r; + x0r = x1r + x3i; + x0i = x1i - x3r; + a[j + 14] = wk3r * x0r - wk3i * x0i; + a[j + 15] = wk3r * x0i + wk3i * x0r; + } + + return; +} + +/*-----------------------------------------------------------------* + * cftmdl() + * Subfunction of Complex Discrete Fourier Transform + *-----------------------------------------------------------------*/ + +static void cftmdl( + short n, /* i : data length of real and imag */ + short l, /* i : initial shift for processing */ + float *a, /* i/o : input/output data */ + const float *w /* i : cos/sin table */ +) +{ + short j, j1, j2, j3, k, k1, k2, m, m2; + float wk1r, wk1i, wk2r, wk2i, wk3r, wk3i; + float x0r, x0i, x1r, x1i, x2r, x2i, x3r, x3i; + + m = l << 2; + for (j = 0; j < l; j += 2) + { + j1 = j + l; + j2 = j1 + l; + j3 = j2 + l; + x0r = a[j] + a[j1]; + x0i = a[j + 1] + a[j1 + 1]; + x1r = a[j] - a[j1]; + x1i = a[j + 1] - a[j1 + 1]; + x2r = a[j2] + a[j3]; + x2i = a[j2 + 1] + a[j3 + 1]; + x3r = a[j2] - a[j3]; + x3i = a[j2 + 1] - a[j3 + 1]; + a[j] = x0r + x2r; + a[j + 1] = x0i + x2i; + a[j2] = x0r - x2r; + a[j2 + 1] = x0i - x2i; + a[j1] = x1r - x3i; + a[j1 + 1] = x1i + x3r; + a[j3] = x1r + x3i; + a[j3 + 1] = x1i - x3r; + } + + wk1r = w[2]; + for (j = m; j < l + m; j += 2) + { + j1 = j + l; + j2 = j1 + l; + j3 = j2 + l; + x0r = a[j] + a[j1]; + x0i = a[j + 1] + a[j1 + 1]; + x1r = a[j] - a[j1]; + x1i = a[j + 1] - a[j1 + 1]; + x2r = a[j2] + a[j3]; + x2i = a[j2 + 1] + a[j3 + 1]; + x3r = a[j2] - a[j3]; + x3i = a[j2 + 1] - a[j3 + 1]; + a[j] = x0r + x2r; + a[j + 1] = x0i + x2i; + a[j2] = x2i - x0i; + a[j2 + 1] = x0r - x2r; + x0r = x1r - x3i; + x0i = x1i + x3r; + a[j1] = wk1r * (x0r - x0i); + a[j1 + 1] = wk1r * (x0r + x0i); + x0r = x3i + x1r; + x0i = x3r - x1i; + a[j3] = wk1r * (x0i - x0r); + a[j3 + 1] = wk1r * (x0i + x0r); + } + + k1 = 0; + m2 = 2 * m; + for (k = m2; k < n; k += m2) + { + k1 += 2; + k2 = 2 * k1; + wk2r = w[k1]; + wk2i = w[k1 + 1]; + wk1r = w[k2]; + wk1i = w[k2 + 1]; + wk3r = wk1r - 2 * wk2i * wk1i; + wk3i = 2 * wk2i * wk1r - wk1i; + for (j = k; j < l + k; j += 2) + { + j1 = j + l; + j2 = j1 + l; + j3 = j2 + l; + x0r = a[j] + a[j1]; + x0i = a[j + 1] + a[j1 + 1]; + x1r = a[j] - a[j1]; + x1i = a[j + 1] - a[j1 + 1]; + x2r = a[j2] + a[j3]; + x2i = a[j2 + 1] + a[j3 + 1]; + x3r = a[j2] - a[j3]; + x3i = a[j2 + 1] - a[j3 + 1]; + a[j] = x0r + x2r; + a[j + 1] = x0i + x2i; + x0r -= x2r; + x0i -= x2i; + a[j2] = wk2r * x0r - wk2i * x0i; + a[j2 + 1] = wk2r * x0i + wk2i * x0r; + x0r = x1r - x3i; + x0i = x1i + x3r; + a[j1] = wk1r * x0r - wk1i * x0i; + a[j1 + 1] = wk1r * x0i + wk1i * x0r; + x0r = x1r + x3i; + x0i = x1i - x3r; + a[j3] = wk3r * x0r - wk3i * x0i; + a[j3 + 1] = wk3r * x0i + wk3i * x0r; + } + + wk1r = w[k2 + 2]; + wk1i = w[k2 + 3]; + wk3r = wk1r - 2 * wk2r * wk1i; + wk3i = 2 * wk2r * wk1r - wk1i; + for (j = k + m; j < l + (k + m); j += 2) + { + j1 = j + l; + j2 = j1 + l; + j3 = j2 + l; + x0r = a[j] + a[j1]; + x0i = a[j + 1] + a[j1 + 1]; + x1r = a[j] - a[j1]; + x1i = a[j + 1] - a[j1 + 1]; + x2r = a[j2] + a[j3]; + x2i = a[j2 + 1] + a[j3 + 1]; + x3r = a[j2] - a[j3]; + x3i = a[j2 + 1] - a[j3 + 1]; + a[j] = x0r + x2r; + a[j + 1] = x0i + x2i; + x0r -= x2r; + x0i -= x2i; + a[j2] = -wk2i * x0r - wk2r * x0i; + a[j2 + 1] = -wk2i * x0i + wk2r * x0r; + x0r = x1r - x3i; + x0i = x1i + x3r; + a[j1] = wk1r * x0r - wk1i * x0i; + a[j1 + 1] = wk1r * x0i + wk1i * x0r; + x0r = x1r + x3i; + x0i = x1i - x3r; + a[j3] = wk3r * x0r - wk3i * x0i; + a[j3 + 1] = wk3r * x0i + wk3i * x0r; + } + } + + return; +} + +static +void cftbsub( + short n, + float *a, + const float *w /* i : cos/sin table */ +) +{ + short j, j1, j2, j3, l; + float x0r, x0i, x1r, x1i, x2r, x2i, x3r, x3i; + + l = 2; + if (n > 8) + { + cft1st(n, a, w); + l = 8; + + while ((l << 2) < n) + { + cftmdl(n, l, a, w); + l <<= 2; + } + } + + if ((l << 2) == n) + { + for (j = 0; j < l; j += 2) + { + j1 = j + l; + j2 = j1 + l; + j3 = j2 + l; + x0r = a[j] + a[j1]; + x0i = -a[j + 1] - a[j1 + 1]; + x1r = a[j] - a[j1]; + x1i = -a[j + 1] + a[j1 + 1]; + x2r = a[j2] + a[j3]; + x2i = a[j2 + 1] + a[j3 + 1]; + x3r = a[j2] - a[j3]; + x3i = a[j2 + 1] - a[j3 + 1]; + a[j] = x0r + x2r; + a[j + 1] = x0i - x2i; + a[j2] = x0r - x2r; + a[j2 + 1] = x0i + x2i; + a[j1] = x1r - x3i; + a[j1 + 1] = x1i - x3r; + a[j3] = x1r + x3i; + a[j3 + 1] = x1i + x3r; + } + } + else + { + for (j = 0; j < l; j += 2) + { + j1 = j + l; + x0r = a[j] - a[j1]; + x0i = -a[j + 1] + a[j1 + 1]; + a[j] += a[j1]; + a[j + 1] = -a[j + 1] - a[j1 + 1]; + a[j1] = x0r; + a[j1 + 1] = x0i; + } + } +} + +static +void rftfsub( + short n, + float *a, + short nc, + const float *c +) +{ + short j, k, kk, ks, m; + float wkr, wki, xr, xi, yr, yi; + + m = n >> 1; + ks = 2 * nc / m; + kk = 0; + for (j = 2; j < m; j += 2) + { + k = n - j; + kk += ks; + wkr = 0.5f - c[nc - kk]; + wki = c[kk]; + xr = a[j] - a[k]; + xi = a[j + 1] + a[k + 1]; + yr = wkr * xr - wki * xi; + yi = wkr * xi + wki * xr; + a[j] -= yr; + a[j + 1] -= yi; + a[k] += yr; + a[k + 1] -= yi; + } +} + + +static +void rftbsub( + short n, + float *a, + short nc, + const float *c +) +{ + short j, k, kk, ks, m; + float wkr, wki, xr, xi, yr, yi; + + a[1] = -a[1]; + m = n >> 1; + ks = 2 * nc / m; + kk = 0; + for (j = 2; j < m; j += 2) + { + k = n - j; + kk += ks; + wkr = 0.5f - c[nc - kk]; + wki = c[kk]; + xr = a[j] - a[k]; + xi = a[j + 1] + a[k + 1]; + yr = wkr * xr + wki * xi; + yi = wkr * xi - wki * xr; + a[j] -= yr; + a[j + 1] = yi - a[j + 1]; + a[k] += yr; + a[k + 1] = yi - a[k + 1]; + } + a[m + 1] = -a[m + 1]; +} + + +static +void dctsub( + short n, + float *a, + short nc, + const float *c +) +{ + short j, k, kk, ks, m; + float wkr, wki, xr; + + m = n >> 1; + ks = nc / n; + kk = 0; + for (j = 1; j < m; j++) + { + k = n - j; + kk += ks; + wkr = c[kk] - c[nc - kk]; + wki = c[kk] + c[nc - kk]; + xr = wki * a[j] - wkr * a[k]; + a[j] = wkr * a[j] + wki * a[k]; + a[k] = xr; + } + a[m] *= c[0]; +} + + +/*-----------------------------------------------------------------* + * edct2() + * + * Transformation of the signal to DCT domain + * OR Inverse EDCT-II for short frames + *-----------------------------------------------------------------*/ + +void edct2( + short n, + short isgn, + float *in, + float *a, + const short *ip, + const float *w +) +{ + short j, nw, nc; + float xr; + + mvr2r(in, a, n); + + nw = ip[0]; + if (n > (nw << 2)) + { + nw = n >> 2; + } + + nc = ip[1]; + if (n > nc) + { + nc = n; + } + + if (isgn < 0) + { + xr = a[n - 1]; + for (j = n - 2; j >= 2; j -= 2) + { + a[j + 1] = a[j] - a[j - 1]; + a[j] += a[j - 1]; + } + a[1] = a[0] - xr; + a[0] += xr; + + if (n > 4) + { + rftbsub(n, a, nc, w + nw); + bitrv2_SR(n, ip + 2, a); + cftbsub(n, a, w); + } + else if (n == 4) + { + cftfsub(n, a, w); + } + } + + if (isgn >= 0) + { + a[0] *= 0.5f; + } + + dctsub(n, a, nc, w + nw); + + if (isgn >= 0) + { + if (n > 4) + { + bitrv2_SR(n, ip + 2, a); + cftfsub(n, a, w); + rftfsub(n, a, nc, w + nw); + } + else if (n == 4) + { + cftfsub(n, a, w); + } + xr = a[0] - a[1]; + a[0] += a[1]; + for (j = 2; j < n; j += 2) + { + a[j - 1] = a[j] - a[j + 1]; + a[j] += a[j + 1]; + } + a[n - 1] = xr; + + for (j = 0; j < n; j ++) + { + a[j] /= 32.0f; + } + } +} + + +void DoRTFTn( + float *x, /* i/o : real part of input and output data */ + float *y, /* i/o : imaginary part of input and output data */ + const short n /* i : size of the FFT up to 1024 */ +) +{ + + int i; + float z[2048]; + + for ( i=0; i 0); + + if (len == 640) + { + float x[320], y[320]; + int i; + + if (sign != -1) + { + rfft_pre(sine_table, data, len); + } + + for (i = 0; i < 320; i++) + { + x[i] = data[2*i]; + y[i] = data[2*i+1]; + } + DoRTFT320(x, y); + for (i = 0; i < 320; i++) + { + data[2*i] = x[i]; + data[2*i+1] = y[i]; + } + + if (sign == -1) + { + rfft_post(sine_table, data, len); + } + } + else + { + if (len == 512) + { + int i; + int const log2 = 9; + float reordered_data[512]; + + if (sign == -1) + { + fft_rel(data, len, log2); + reordered_data[0] = data[0]; + reordered_data[1] = data[len/2]; + for (i = 1; i < len/2; i++) + { + reordered_data[2*i] = data[i]; + reordered_data[2*i+1] = data[len-i]; + } + } + else + { + reordered_data[0] = data[0]; + reordered_data[len/2] = data[1]; + for (i = 1; i < len/2; i++) + { + reordered_data[i] = data[2*i]; + reordered_data[len-i] = data[2*i+1]; + } + ifft_rel(reordered_data, len, log2); + } + mvr2r(reordered_data, data, len); + } + else + { + assert(!"Not supported FFT length!"); + } + } + + return 0; +} + +static void butterfly(const float a, const float b, float *aPlusb, float *aMinusb) +{ + *aPlusb = a + b; + *aMinusb = a - b; +} + +static void fft2(float *pInOut) +{ + /* FFT MATRIX: + 1.0000 1.0000 + 1.0000 -1.0000 + */ + float re1, im1; + float re2, im2; + + re1 = pInOut[0]; + im1 = pInOut[1]; + re2 = pInOut[2]; + im2 = pInOut[3]; + pInOut[0] = re1 + re2; + pInOut[1] = im1 + im2; + + pInOut[2] = re1 - re2; + pInOut[3] = im1 - im2; + +} + +static const float C31 = 0.5f; /* cos(PI/3); sin(2*PI/3) */ +static const float C32 = 0.866025403784439f; /* cos(PI/3); sin(2*PI/3) */ + +static void fft3_2(float *pInOut) +{ + float re1, im1; + float re2, im2; + float re3, im3; + + float tmp1, tmp2; + float tmp3, tmp4; + + re1 = pInOut[0]; + im1 = pInOut[1]; + re2 = pInOut[2]; + im2 = pInOut[3]; + re3 = pInOut[4]; + im3 = pInOut[5]; + + /* FFT MATRIX: + 1.0000 1.0000 1.0000 + C31 C32 + 1.0000 -0.5000 - 0.8660i -0.5000 + 0.8660i + 1.0000 -0.5000 + 0.8660i -0.5000 - 0.8660i + */ + tmp1 = re2 + re3; + tmp3 = im2 + im3; + tmp2 = re2 - re3; + tmp4 = im2 - im3; + pInOut[0] = re1 + tmp1; + pInOut[1] = im1 + tmp3; + pInOut[2] = re1 - C31 * tmp1 + C32 * tmp4; + pInOut[4] = re1 - C31 * tmp1 - C32 * tmp4; + + pInOut[3] = im1 - C32 * tmp2 - C31 * tmp3; + pInOut[5] = im1 + C32 * tmp2 - C31 * tmp3; + +} + + +static void fft4(float *pInOut) +{ + float re1, im1; + float re2, im2; + float re3, im3; + float re4, im4; + + float tmp1, tmp2; + float tmp3, tmp4; + float tmp5, tmp6; + float tmp7, tmp8; + + re1 = pInOut[0]; + im1 = pInOut[1]; + re2 = pInOut[2]; + im2 = pInOut[3]; + re3 = pInOut[4]; + im3 = pInOut[5]; + re4 = pInOut[6]; + im4 = pInOut[7]; + + /* + 1.0000 1.0000 1.0000 1.0000 + 1.0000 -1.0000i -1.0000 1.0000i + 1.0000 -1.0000 1.0000 -1.0000 + 1.0000 1.0000i -1.0000 -1.0000i + */ + tmp1 = re1 + re3; + tmp3 = re2 + re4; + tmp5 = im1 + im3; + tmp7 = im2 + im4; + pInOut[0] = tmp1 + tmp3; + pInOut[4] = tmp1 - tmp3; + + pInOut[1] = tmp5 + tmp7; + pInOut[5] = tmp5 - tmp7; + tmp2 = re1 - re3; + tmp4 = re2 - re4; + tmp6 = im1 - im3; + tmp8 = im2 - im4; + pInOut[2] = tmp2 + tmp8; + pInOut[6] = tmp2 - tmp8; + + pInOut[3] = -tmp4 + tmp6; + pInOut[7] = tmp4 + tmp6; + +} + +static const float C51 = 0.309016994374947f; /* cos(2*PI/5); */ +static const float C52 = 0.951056516295154f; /* sin(2*PI/5); */ +static const float C53 = 0.809016994374947f; /* cos( PI/5); */ +static const float C54 = 0.587785252292473f; /* sin( PI/5); */ + +static void fft5(float *pInOut) +{ + float re1, im1; + float re2, im2; + float re3, im3; + float re4, im4; + float re5, im5; + + float tmp1, tmp2; + float tmp3, tmp4; + float tmp5, tmp6; + float tmp7, tmp8; + + + re1 = pInOut[0]; + im1 = pInOut[1]; + re2 = pInOut[2]; + im2 = pInOut[3]; + re3 = pInOut[4]; + im3 = pInOut[5]; + re4 = pInOut[6]; + im4 = pInOut[7]; + re5 = pInOut[8]; + im5 = pInOut[9]; + + /* + 1.0000 1.0000 1.0000 1.0000 1.0000 + C51 C52 C53 C54 + 1.0000 0.3090 - 0.9511i -0.8090 - 0.5878i -0.8090 + 0.5878i 0.3090 + 0.9511i + 1.0000 -0.8090 - 0.5878i 0.3090 + 0.9511i 0.3090 - 0.9511i -0.8090 + 0.5878i + 1.0000 -0.8090 + 0.5878i 0.3090 - 0.9511i 0.3090 + 0.9511i -0.8090 - 0.5878i + 1.0000 0.3090 + 0.9511i -0.8090 + 0.5878i -0.8090 - 0.5878i 0.3090 - 0.9511i + */ + tmp1 = re2 + re5; + tmp2 = re2 - re5; + tmp3 = im2 + im5; + tmp4 = im2 - im5; + tmp5 = re3 + re4; + tmp6 = re3 - re4; + tmp7 = im3 + im4; + tmp8 = im3 - im4; + + + pInOut[0] = re1 + tmp1 + tmp5; + pInOut[1] = im1 + tmp3 + tmp7; + + pInOut[2] = re1 + C51 * tmp1 - C53 * tmp5 + C52 * tmp4 + C54 * tmp8; + pInOut[8] = re1 + C51 * tmp1 - C53 * tmp5 - C52 * tmp4 - C54 * tmp8; + pInOut[3] = im1 - C52 * tmp2 - C54 * tmp6 + C51 * tmp3 - C53 * tmp7; + pInOut[9] = im1 + C52 * tmp2 + C54 * tmp6 + C51 * tmp3 - C53 * tmp7; + pInOut[4] = re1 - C53 * tmp1 + C51 * tmp5 + C54 * tmp4 - C52 * tmp8; + pInOut[6] = re1 - C53 * tmp1 + C51 * tmp5 - C54 * tmp4 + C52 * tmp8; + pInOut[5] = im1 - C54 * tmp2 + C52 * tmp6 - C53 * tmp3 + C51 * tmp7; + pInOut[7] = im1 + C54 * tmp2 - C52 * tmp6 - C53 * tmp3 + C51 * tmp7; + + +} + +static const float C81 = 0.707106781186548f; /* cos(PI/4); */ + +static void fft8_2(float *pInOut) +{ + float re0, im0, re4, im4; + + float re1_7p, re1_7m; + float im1_7p, im1_7m; + float re2_6p, re2_6m; + float im2_6p, im2_6m; + float re3_5p, re3_5m; + float im3_5p, im3_5m; + + re0 = pInOut[0]; + im0 = pInOut[1]; + re4 = pInOut[8]; + im4 = pInOut[9]; + butterfly(pInOut[1*2 ], pInOut[7*2 ],&re1_7p, &re1_7m); + butterfly(pInOut[1*2+1], pInOut[7*2+1],&im1_7p, &im1_7m); + butterfly(pInOut[2*2 ], pInOut[6*2 ],&re2_6p, &re2_6m); + butterfly(pInOut[2*2+1], pInOut[6*2+1],&im2_6p, &im2_6m); + butterfly(pInOut[3*2 ], pInOut[5*2 ],&re3_5p, &re3_5m); + butterfly(pInOut[3*2+1], pInOut[5*2+1],&im3_5p, &im3_5m); + + /* + 0: 1 + 0i 1 + 0i 1 + 0i 1 + 0i 1 + 0i 1 + 0i 1 + 0i 1 + 0i + 1: 1 + 0i C81 - C81i 0 - 1i -C81 - C81i -1 - 0i -C81 + C81i - 0 + 1i C81 + C81i + 2: 1 + 0i 0 - 1i -1 - 0i - 0 + 1i 1 + 0i 0 - 1i - 1 - 0i - 0 + 1i + 3: 1 + 0i -C81 - C81i -0 + 1i C81 - C81i -1 - 0i C81 + C81i 0 - 1i -C81 + C81i + 4: 1 + 0i - 1 - 0i 1 + 0i - 1 - 0i 1 + 0i - 1 - 0i 1 + 0i - 1 - 0i + 5: 1 + 0i -C81 + C81i 0 - 1i C81 + C81i -1 - 0i C81 - C81i - 0 + 1i -C81 - C81i + 6: 1 + 0i - 0 + 1i -1 - 0i 0 - 1i 1 + 0i - 0 + 1i - 1 - 0i - 0 - 1i + 7: 1 + 0i C81 + C81i -0 + 1i -C81 + C81i -1 - 0i -C81 - C81i - 0 - 1i C81 - C81i + */ + pInOut[ 0] = re0 + re4 + re1_7p + re2_6p + re3_5p; + pInOut[ 1] = im0 + im4 + im1_7p + im2_6p + im3_5p; + + pInOut[ 2] = re0 + C81*(re1_7p - re3_5p) - re4 + C81*( im1_7m + im3_5m) + im2_6m; + pInOut[ 3] = im0 + C81*(im1_7p - im3_5p) - im4 - C81* (re1_7m + re3_5m) - re2_6m; + + pInOut[ 4] = re0 - re2_6p + re4 + im1_7m - im3_5m; + pInOut[ 5] = im0 - im2_6p + im4 - re1_7m + re3_5m; + + pInOut[ 6] = re0 + C81*(-re1_7p + re3_5p) - re4 + C81*( im1_7m + im3_5m) - im2_6m; + pInOut[ 7] = im0 + C81*(-im1_7p + im3_5p) - im4 - C81* (re1_7m + re3_5m) + re2_6m; + + pInOut[ 8] = re0 - re1_7p + re2_6p - re3_5p + re4; + pInOut[ 9] = im0 - im1_7p + im2_6p - im3_5p + im4; + + pInOut[10] = re0 + C81*(-re1_7p + re3_5p) - re4 - C81*( im1_7m + im3_5m) + im2_6m; + pInOut[11] = im0 + C81*(-im1_7p + im3_5p) - im4 + C81* (re1_7m + re3_5m) - re2_6m; + + pInOut[12] = re0 - re2_6p + re4 - im1_7m + im3_5m; + pInOut[13] = im0 - im2_6p + im4 + re1_7m - re3_5m; + + pInOut[14] = re0 + C81*(re1_7p - re3_5p) - re4 - C81*( im1_7m + im3_5m) - im2_6m; + pInOut[15] = im0 + C81*(im1_7p - im3_5p) - im4 + C81* (re1_7m + re3_5m) + re2_6m; + +} + +static void nextFFT(float *x, int length) +{ + switch(length) + { + case 2: + fft2(x); + break; + case 3: + fft3_2(x); + break; + case 4: + fft4(x); + break; + case 5: + fft5(x); + break; + case 8: + fft8_2(x); + break; + default: + assert(!"length not supported"); + break; + } +} + +static const int CTFFTfactors[] = {9,8,7,5,4,3,2,0}; + +static __inline int findFactor(const int length) +{ + int i = 0; + int factor = 0; + + while(CTFFTfactors[i]!=0) + { + if(0==(length%CTFFTfactors[i])) + { + factor = CTFFTfactors[i]; + break; + } + i++; + } + return factor; +} + +static __inline void twiddle(float *x, const int length, const int n1, const int n2) +{ + int i, ii; + double pi = 4. * atan(1.); + float sinValOrg, cosValOrg; + float sinVal=0.f, cosVal=1.f; + float twReal=0.f, twImag=1.f; + + cosValOrg = (float) cos(-2*pi*1./(double)length); + sinValOrg = (float) sin(-2*pi*1./(double)length); + for(i=1; i0&&(length/factor>1)) + { + n1 = factor; + n2 = length/factor; + + /* DATA Resorting for stage1 */ + dest = scratch; + for (i=0; i<2*n1; i+=2) + { + src = x+i; + for(ii=0; ii1) + { + float *tmp = scratch1; + int n1_inv=1, n2_inv=1; + int n2 = factor[0/*idx*/]; + int n1 = length/n2; + int idx, incr; + + while(((n1_inv*n1)%n2)!=1) + { + n1_inv++; + } + while(((n2_inv*n2)%n1)!=1) + { + n2_inv++; + } + idx = 0; + incr = n1*n1_inv; + cnt = 0; + for(i=0; ilength) + { + idx -= length; + } + } + tmp[cnt++] = x[2*idx ]; + tmp[cnt++] = x[2*idx+1]; + idx++; + } + for(cnt=0; cntlength) + { + idx -= length; + } + } + } + for(cnt=0; cnt +#include +#include "prot.h" + + + +#if defined __ICL +#define restrict __restrict +#else +#define restrict +#endif + +#ifdef _MSC_VER +#pragma warning(disable : 4305) /* disable truncation from double to float warning (VC++)*/ +#endif + +static void fft8(float *vec); +static void fft10(float *vec); +static void fft16(float *vec); +static void fft20(float *vec); +static void fft30(float *vec); +static void fft5s(float *x, int stride); + + +static const float INV_SQRT2 = 7.071067811865475e-1; +static const float COS_PI_DIV8 = 9.238795325112867e-1; +static const float COS_3PI_DIV8 = 3.826834323650898e-1; +static const float SQRT2PLUS1 = 2.414213562373095; +static const float SQRT2MINUS1 = 4.142135623730952e-1; + + +#ifdef _MSC_VER +#pragma warning(default : 4305) +#endif + +/******************************************************************************* + Functionname: fft8 + ******************************************************************************* + + Description: 8-point FFT. Complex-valued input takes 52 real additions + and 4 real multiplications. + + Arguments: vec - pointer to data (interleaved real / imaginary parts) + + Return: none + +*******************************************************************************/ +static void fft8(float * restrict vec) +{ + float temp1[16]; + float temp2[16]; + + + /* Pre-additions */ + temp1[0] = vec[0] + vec[8]; + temp1[2] = vec[0] - vec[8]; + temp1[1] = vec[1] + vec[9]; + temp1[3] = vec[1] - vec[9]; + temp1[4] = vec[2] + vec[10]; + temp1[6] = vec[2] - vec[10]; + temp1[5] = vec[3] + vec[11]; + temp1[7] = vec[3] - vec[11]; + temp1[8] = vec[4] + vec[12]; + temp1[10] = vec[4] - vec[12]; + temp1[9] = vec[5] + vec[13]; + temp1[11] = vec[5] - vec[13]; + temp1[12] = vec[6] + vec[14]; + temp1[14] = vec[6] - vec[14]; + temp1[13] = vec[7] + vec[15]; + temp1[15] = vec[7] - vec[15]; + + /* Pre-additions and core multiplications */ + temp2[0] = temp1[0] + temp1[8]; + temp2[4] = temp1[0] - temp1[8]; + temp2[1] = temp1[1] + temp1[9]; + temp2[5] = temp1[1] - temp1[9]; + temp2[8] = temp1[2] - temp1[11]; + temp2[10] = temp1[2] + temp1[11]; + temp2[9] = temp1[3] + temp1[10]; + temp2[11] = temp1[3] - temp1[10]; + temp2[2] = temp1[4] + temp1[12]; + temp2[7] = temp1[4] - temp1[12]; + temp2[3] = temp1[5] + temp1[13]; + temp2[6] = temp1[13]- temp1[5]; + + temp1[1] = temp1[6] + temp1[14]; + temp1[2] = temp1[6] - temp1[14]; + temp1[0] = temp1[7] + temp1[15]; + temp1[3] = temp1[7] - temp1[15]; + + temp2[12] = (temp1[0] + temp1[2]) * INV_SQRT2; + temp2[14] = (temp1[0] - temp1[2]) * INV_SQRT2; + temp2[13] = (temp1[3] - temp1[1]) * INV_SQRT2; + temp2[15] = (temp1[1] + temp1[3]) * -INV_SQRT2; + + /* Post-additions */ + vec[0] = temp2[0] + temp2[2]; + vec[8] = temp2[0] - temp2[2]; + vec[1] = temp2[1] + temp2[3]; + vec[9] = temp2[1] - temp2[3]; + vec[4] = temp2[4] - temp2[6]; + vec[12] = temp2[4] + temp2[6]; + vec[5] = temp2[5] - temp2[7]; + vec[13] = temp2[5] + temp2[7]; + vec[6] = temp2[8] + temp2[14]; + vec[14] = temp2[8] - temp2[14]; + vec[7] = temp2[9] + temp2[15]; + vec[15] = temp2[9] - temp2[15]; + vec[2] = temp2[10]+ temp2[12]; + vec[10] = temp2[10]- temp2[12]; + vec[3] = temp2[11]+ temp2[13]; + vec[11] = temp2[11]- temp2[13]; + +} + + + +/******************************************************************************* + Functionname: fft16 + ******************************************************************************* + + Description: 16-point FFT. Complex-valued input takes 144 real additions and + 24 real multiplications. + + Arguments: vec - pointer to data (interleaved real / imaginary parts) + + Return: none + +*******************************************************************************/ +/* fast implementation, completely unrolled and inlined */ +static void fft16(float * restrict vec) +{ + float temp10, temp11, temp12, temp13, temp14, temp15, temp16, temp17, + temp18, temp19, temp110, temp111, temp112, temp113, temp114, temp115; + float temp20, temp21, temp22, temp23, temp24, temp25, temp26, temp27, + temp28, temp29, temp210, temp211, temp212, temp213, temp214, temp215; + float vec0, vec1, vec2, vec3, vec4, vec5, vec6, vec7, + vec8, vec9, vec10, vec11, vec12, vec13, vec14, vec15; + + + /* even */ + vec0 = vec[0] + vec[16]; + vec1 = vec[1] + vec[17]; + vec2 = vec[2] + vec[18]; + vec3 = vec[3] + vec[19]; + vec4 = vec[4] + vec[20]; + vec5 = vec[5] + vec[21]; + vec6 = vec[6] + vec[22]; + vec7 = vec[7] + vec[23]; + vec8 = vec[8] + vec[24]; + vec9 = vec[9] + vec[25]; + vec10 = vec[10] + vec[26]; + vec11 = vec[11] + vec[27]; + vec12 = vec[12] + vec[28]; + vec13 = vec[13] + vec[29]; + vec14 = vec[14] + vec[30]; + vec15 = vec[15] + vec[31]; + + /* Pre-additions */ + temp10 = vec0 + vec8; + temp12 = vec0 - vec8; + temp11 = vec1 + vec9; + temp13 = vec1 - vec9; + temp14 = vec2 + vec10; + temp16 = vec2 - vec10; + temp15 = vec3 + vec11; + temp17 = vec3 - vec11; + temp18 = vec4 + vec12; + temp110 = vec4 - vec12; + temp19 = vec5 + vec13; + temp111 = vec5 - vec13; + temp112 = vec6 + vec14; + temp114 = vec6 - vec14; + temp113 = vec7 + vec15; + temp115 = vec7 - vec15; + + /* Pre-additions and core multiplications */ + temp20 = temp10 + temp18; + temp24 = temp10 - temp18; + temp21 = temp11 + temp19; + temp25 = temp11 - temp19; + temp28 = temp12 - temp111; + temp210 = temp12 + temp111; + temp29 = temp13 + temp110; + temp211 = temp13 - temp110; + temp22 = temp14 + temp112; + temp27 = temp14 - temp112; + temp23 = temp15 + temp113; + temp26 = temp113- temp15; + + temp11 = temp16 + temp114; + temp12 = temp16 - temp114; + temp10 = temp17 + temp115; + temp13 = temp17 - temp115; + + temp212 = (temp10 + temp12) * INV_SQRT2; + temp214 = (temp10 - temp12) * INV_SQRT2; + temp213 = (temp13 - temp11) * INV_SQRT2; + temp215 = (temp11 + temp13) * -INV_SQRT2; + + + + /* odd */ + vec0 = vec[0] - vec[16]; + vec1 = vec[1] - vec[17]; + vec2 = vec[2] - vec[18]; + vec3 = vec[3] - vec[19]; + vec4 = vec[4] - vec[20]; + vec5 = vec[5] - vec[21]; + vec6 = vec[6] - vec[22]; + vec7 = vec[7] - vec[23]; + vec8 = vec[8] - vec[24]; + vec9 = vec[9] - vec[25]; + vec10 = vec[10] - vec[26]; + vec11 = vec[11] - vec[27]; + vec12 = vec[12] - vec[28]; + vec13 = vec[13] - vec[29]; + vec14 = vec[14] - vec[30]; + vec15 = vec[15] - vec[31]; + + /* Pre-additions and core multiplications */ + temp19 = (vec2 + vec14) * -COS_3PI_DIV8; + temp110 = (vec2 - vec14) * COS_PI_DIV8; + temp18 = (vec3 + vec15) * COS_3PI_DIV8; + temp111 = (vec3 - vec15) * COS_PI_DIV8; + temp15 = (vec4 + vec12) * -INV_SQRT2; + temp16 = (vec4 - vec12) * INV_SQRT2; + temp14 = (vec5 + vec13) * INV_SQRT2; + temp17 = (vec5 - vec13) * INV_SQRT2; + temp113 = (vec6 + vec10) * -COS_PI_DIV8; + temp114 = (vec6 - vec10) * COS_3PI_DIV8; + temp112 = (vec7 + vec11) * COS_PI_DIV8; + temp115 = (vec7 - vec11) * COS_3PI_DIV8; + + /* Core multiplications */ + vec2 = temp18 * SQRT2PLUS1 - temp112 * SQRT2MINUS1; + vec3 = temp19 * SQRT2PLUS1 - temp113 * SQRT2MINUS1; + vec4 = temp110 * SQRT2MINUS1 - temp114 * SQRT2PLUS1; + vec5 = temp111 * SQRT2MINUS1 - temp115 * SQRT2PLUS1; + + /* Post-additions */ + temp18 += temp112; + temp19 += temp113; + temp110+= temp114; + temp111+= temp115; + + vec6 = vec0 + temp14; + vec10 = vec0 - temp14; + vec7 = vec1 + temp15; + vec11 = vec1 - temp15; + + vec12 = temp16 - vec9; + vec14 = temp16 + vec9; + vec13 = vec8 + temp17; + vec15 = vec8 - temp17; + + temp10 = vec6 - vec14; + temp12 = vec6 + vec14; + temp11 = vec7 + vec15; + temp13 = vec7 - vec15; + temp14 = vec10 + vec12; + temp16 = vec10 - vec12; + temp15 = vec11 + vec13; + temp17 = vec11 - vec13; + + vec10 = temp18 + temp110; + temp110 = temp18 - temp110; + vec11 = temp19 + temp111; + temp111 = temp19 - temp111; + + temp112 = vec2 + vec4; + temp114 = vec2 - vec4; + temp113 = vec3 + vec5; + temp115 = vec3 - vec5; + + + /* Post-additions */ + *vec++ = temp20 + temp22; + *vec++ = temp21 + temp23; + *vec++ = temp12 + vec10; + *vec++ = temp13 + vec11; + *vec++ = temp210+ temp212; + *vec++ = temp211+ temp213; + *vec++ = temp10 + temp112; + *vec++ = temp11 + temp113; + *vec++ = temp24 - temp26; + *vec++ = temp25 - temp27; + *vec++ = temp16 + temp114; + *vec++ = temp17 + temp115; + *vec++ = temp28 + temp214; + *vec++ = temp29 + temp215; + *vec++ = temp14 + temp110; + *vec++ = temp15 + temp111; + *vec++ = temp20 - temp22; + *vec++ = temp21 - temp23; + *vec++ = temp12 - vec10; + *vec++ = temp13 - vec11; + *vec++ = temp210- temp212; + *vec++ = temp211- temp213; + *vec++ = temp10 - temp112; + *vec++ = temp11 - temp113; + *vec++ = temp24 + temp26; + *vec++ = temp25 + temp27; + *vec++ = temp16 - temp114; + *vec++ = temp17 - temp115; + *vec++ = temp28 - temp214; + *vec++ = temp29 - temp215; + *vec++ = temp14 - temp110; + *vec++ = temp15 - temp111; + +} + + +/******************************************************************************* + Functionname: fft15 + ******************************************************************************* + + Description: 15-point FFT. Complex-valued input takes 176 real additions + and 34 real multiplications. + + Arguments: vec - pointer to data (interleaved real / imaginary parts) + + Return: none + +*******************************************************************************/ +static void fft15(float * restrict vec) +{ + + float r0, r1, r2, r3, r4, r5, r6, r7, r8, r9, r10, r11, r12, r13, r14, r15, r16, r17; + float i0, i1, i2, i3, i4, i5, i6, i7, i8, i9, i10, i11, i12, i13, i14, i15, i16, i17; + float tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7, tmp8, tmp9, + tmp10, tmp11, tmp12, tmp13, tmp14, tmp15, tmp16, tmp17, tmp18, tmp19, + tmp20, tmp21, tmp22, tmp23, tmp24, tmp25, tmp26, tmp27, tmp28, tmp29; + + + /* Pre-additions real part */ + r1 = vec[2] + vec[8]; + r2 = vec[2] - vec[8]; + r3 = vec[4] + vec[16]; + r4 = vec[4] - vec[16]; + r5 = vec[6] + vec[24]; + r6 = vec[6] - vec[24]; + r7 = vec[10] + vec[20]; + r8 = vec[10] - vec[20]; + r9 = vec[12] + vec[18]; + r10 = vec[12] - vec[18]; + r11 = vec[14] + vec[26]; + r12 = vec[14] - vec[26]; + r13 = vec[22] + vec[28]; + r14 = vec[22] - vec[28]; + + tmp2 = r1 + r3; + tmp4 = r1 - r3; + tmp6 = r2 + r14; + tmp8 = r2 - r14; + tmp10 = r4 + r12; + tmp12 = r4 - r12; + tmp14 = r5 + r9; + tmp16 = r5 - r9; + tmp18 = r11 + r13; + tmp20 = r11 - r13; + + /* Pre-additions imaginary part */ + i1 = vec[3] + vec[9]; + i2 = vec[3] - vec[9]; + i3 = vec[5] + vec[17]; + i4 = vec[5] - vec[17]; + i5 = vec[7] + vec[25]; + i6 = vec[7] - vec[25]; + i7 = vec[11] + vec[21]; + i8 = vec[11] - vec[21]; + i9 = vec[13] + vec[19]; + i10 = vec[13] - vec[19]; + i11 = vec[15] + vec[27]; + i12 = vec[15] - vec[27]; + i13 = vec[23] + vec[29]; + i14 = vec[23] - vec[29]; + + tmp3 = i1 + i3; + tmp5 = i1 - i3; + tmp7 = i2 + i14; + tmp9 = i2 - i14; + tmp11 = i4 + i12; + tmp13 = i4 - i12; + tmp15 = i5 + i9; + tmp17 = i5 - i9; + tmp19 = i11 + i13; + tmp21 = i11 - i13; + + + /* Pre-additions and core multiplications */ + tmp28= tmp4 + tmp20; + tmp29= tmp5 + tmp21; + r4 = tmp2 + tmp18; + i4 = tmp3 + tmp19; + r3 = (r4 + tmp14) * -1.25f; + i3 = (i4 + tmp15) * -1.25f; + r2 = (tmp29 - i8) * -8.660254037844387e-1f; + i2 = (tmp28 - r8) * 8.660254037844387e-1f; + r1 = r4 + r7; + i1 = i4 + i7; + r0 = r1 + vec[0] + tmp14; + i0 = i1 + vec[1] + tmp15; + r7 = tmp4 - tmp20; + i7 = tmp5 - tmp21; + r8 = (tmp3 - tmp19) * -4.841229182759272e-1f; + i8 = (tmp2 - tmp18) * 4.841229182759272e-1f; + tmp0 = tmp6 + r10; + tmp1 = tmp7 + i10; + tmp2 = r6 - tmp10; + tmp3 = i6 - tmp11; + r10 = tmp7 * -2.308262652881440f; + i10 = tmp6 * 2.308262652881440f; + r11 = tmp8 * 1.332676064001459f; + i11 = tmp9 * 1.332676064001459f; + r6 = (r7 - tmp16) * 5.590169943749475e-1f; + i6 = (i7 - tmp17) * 5.590169943749475e-1f; + r12 = (tmp1 + tmp3) * 5.877852522924733e-1f; + i12 = (tmp0 + tmp2) * -5.877852522924733e-1f; + r13 = (tmp7 - tmp11) * -8.816778784387098e-1f; + i13 = (tmp6 - tmp10) * 8.816778784387098e-1f; + r14 = (tmp8 + tmp12) * 5.090369604551274e-1f; + i14 = (tmp9 + tmp13) * 5.090369604551274e-1f; + r16 = tmp11 * 5.449068960040204e-1f; + i16 = tmp10 * -5.449068960040204e-1f; + r17 = tmp12 * 3.146021430912046e-1f; + i17 = tmp13 * 3.146021430912046e-1f; + + r4 *= 1.875f; + i4 *= 1.875f; + r1 *= -1.5f; + i1 *= -1.5f; + r7 *= -8.385254915624212e-1f; + i7 *= -8.385254915624212e-1f; + r5 = tmp29 * 1.082531754730548f; + i5 = tmp28 * -1.082531754730548f; + r9 = tmp1 * 1.538841768587627f; + i9 = tmp0 * -1.538841768587627f; + r15 = tmp3 * 3.632712640026803e-1f; + i15 = tmp2 * -3.632712640026803e-1f; + + + /* Post-additions real part */ + tmp2 = r0 + r1; + tmp4 = r3 + r6; + tmp6 = r3 - r6; + tmp8 = r4 + r5; + tmp10 = r4 - r5; + tmp12 = r7 + r8; + tmp14 = r7 - r8; + tmp16 = r13 + r16; + tmp18 = r14 + r17; + tmp20 = r10 - r13; + tmp22 = r11 - r14; + tmp24 = r12 + r15; + tmp26 = r12 - r9; + + r1 = tmp2 + r2; + r2 = tmp2 - r2; + r3 = tmp4 + tmp26; + r4 = tmp4 - tmp26; + r5 = tmp6 + tmp24; + r6 = tmp6 - tmp24; + r7 = tmp16 + tmp18; + r8 = tmp16 - tmp18; + r9 = tmp20 - tmp22; + r10 = tmp20 + tmp22; + r11 = r1 + tmp8; + r12 = r2 + tmp10; + r13 = r11 - tmp12; + r14 = r12 - tmp14; + r15 = r12 + tmp14; + r16 = r11 + tmp12; + + /* Post-additions imaginary part */ + tmp3 = i0 + i1; + tmp5 = i3 + i6; + tmp7 = i3 - i6; + tmp9 = i4 + i5; + tmp11 = i4 - i5; + tmp13 = i7 + i8; + tmp15 = i7 - i8; + tmp17 = i13 + i16; + tmp19 = i14 + i17; + tmp21 = i10 - i13; + tmp23 = i11 - i14; + tmp25 = i12 + i15; + tmp27 = i12 - i9; + + i1 = tmp3 + i2; + i2 = tmp3 - i2; + i3 = tmp5 + tmp27; + i4 = tmp5 - tmp27; + i5 = tmp7 + tmp25; + i6 = tmp7 - tmp25; + i7 = tmp17 + tmp19; + i8 = tmp17 - tmp19; + i9 = tmp21 - tmp23; + i10 = tmp21 + tmp23; + i11 = i1 + tmp9; + i12 = i2 + tmp11; + i13 = i11 - tmp13; + i14 = i12 - tmp15; + i15 = i12 + tmp15; + i16 = i11 + tmp13; + + *vec++ = r0; + *vec++ = i0; + *vec++ = r13 + r5 + r7; + *vec++ = i13 + i5 + i7; + *vec++ = r15 + r3 - r9; + *vec++ = i15 + i3 - i9; + *vec++ = r0 + r4; + *vec++ = i0 + i4; + *vec++ = r13 + r6 - r7; + *vec++ = i13 + i6 - i7; + *vec++ = r2; + *vec++ = i2; + *vec++ = r0 + r5; + *vec++ = i0 + i5; + *vec++ = r16 + r3 - r10; + *vec++ = i16 + i3 - i10; + *vec++ = r15 + r4 + r9; + *vec++ = i15 + i4 + i9; + *vec++ = r0 + r6; + *vec++ = i0 + i6; + *vec++ = r1; + *vec++ = i1; + *vec++ = r14 + r5 + r8; + *vec++ = i14 + i5 + i8; + *vec++ = r0 + r3; + *vec++ = i0 + i3; + *vec++ = r16 + r4 + r10; + *vec++ = i16 + i4 + i10; + *vec++ = r14 + r6 - r8; + *vec++ = i14 + i6 - i8; + + +} + +/******************************************************************************* + Functionname: fft5s + ******************************************************************************* + + Description: 5-point FFT. + + Arguments: x - pointer to input data (interleaved real / imaginary parts) + stride - stride for input data + + Return: none + +*******************************************************************************/ +static const float C51 = 0.9510565162951535f; +static const float C52 = -1.5388417685876270f; +static const float C53 = -0.3632712640026803f; +static const float C54 = 0.5590169943749475f; +static const float C55 = -1.25f; + +static void fft5s(float *x, int stride) +{ + float r1,r2,r3,r4; + float s1,s2,s3,s4; + float t; + /* real part */ + r1 = x[1*stride] + x[4*stride]; + r4 = x[1*stride] - x[4*stride]; + r3 = x[2*stride] + x[3*stride]; + r2 = x[2*stride] - x[3*stride]; + t = (r1-r3) * C54; + r1 = r1 + r3; + x[0] = x[0] + r1; + r1 = x[0] + (r1 * C55); + r3 = r1 - t; + r1 = r1 + t; + t = (r4 + r2) * C51; + r4 = t + (r4 * C52); + r2 = t + (r2 * C53); + + /* imaginary part */ + s1 = x[1*stride+1] + x[4*stride+1]; + s4 = x[1*stride+1] - x[4*stride+1]; + s3 = x[2*stride+1] + x[3*stride+1]; + s2 = x[2*stride+1] - x[3*stride+1]; + t = (s1 - s3) * C54; + s1 = s1 + s3; + x[1] = x[1] + s1; + s1 = x[1] + (s1 * C55); + s3 = s1 - t; + s1 = s1 + t; + t = (s4 + s2) * C51; + s4 = t + (s4 * C52); + s2 = t + (s2 * C53); + + /* combination */ + x[1*stride] = r1 + s2; + x[4*stride] = r1 - s2; + x[2*stride] = r3 - s4; + x[3*stride] = r3 + s4; + + x[1*stride+1] = s1 - r2; + x[4*stride+1] = s1 + r2; + x[2*stride+1] = s3 + r4; + x[3*stride+1] = s3 - r4; +} + + +/** + * \brief Function performs a complex 10-point FFT + * The FFT is performed inplace. The result of the FFT + * is scaled by SCALEFACTOR10 bits. + * + * WOPS FLC version: 1093 cycles + * WOPS with 32x16 bit multiplications: 196 cycles + * + * \param [i/o] re real input / output + * \param [i/o] im imag input / output + * \param [i ] s stride real and imag input / output + * + * \return void + */ +static void fft10(float * restrict vec) +{ + float t; + float r1,r2,r3,r4; + float s1,s2,s3,s4; + float y00,y01,y02,y03,y04,y05,y06,y07,y08,y09; + float y10,y11,y12,y13,y14,y15,y16,y17,y18,y19; + + /* 2 fft5 stages */ + + /* real part */ + r1 = vec[12] + vec[8]; + r4 = vec[12] - vec[8]; + r3 = vec[4] + vec[16]; + r2 = vec[4] - vec[16]; + t = (r1 - r3) * C54; + r1 = r1 + r3; + y00 = vec[0] + r1; + r1 = y00 + (r1 * C55); + r3 = r1 - t; + r1 = r1 + t; + t = (r4 + r2) * C51; + r4 = t + (r4 * C52); + r2 = t + (r2 * C53); + + /* imaginary part */ + s1 = vec[13] + vec[9]; + s4 = vec[13] - vec[9]; + s3 = vec[5] + vec[17]; + s2 = vec[5] - vec[17]; + t = (s1 - s3) * C54; + s1 = s1 + s3; + y01 = vec[1] + s1; + s1 = y01 + (s1 * C55); + s3 = s1 - t; + s1 = s1 + t; + t = (s4 + s2) * C51; + s4 = t + (s4 * C52); + s2 = t + (s2 * C53); + + /* combination */ + y04 = r1 + s2; + y16 = r1 - s2; + y08 = r3 - s4; + y12 = r3 + s4; + y05 = s1 - r2; + y17 = s1 + r2; + y09 = s3 + r4; + y13 = s3 - r4; + + /* real part */ + r1 = vec[2] + vec[18]; + r4 = vec[2] - vec[18]; + r3 = vec[14] + vec[6]; + r2 = vec[14] - vec[6]; + t = (r1 - r3) * C54; + r1 = r1 + r3; + y02 = vec[10] + r1; + r1 = y02 + (r1 * C55); + r3 = r1 - t; + r1 = r1 + t; + t = (r4 + r2) * C51; + r4 = t + (r4 * C52); + r2 = t + (r2 * C53); + + /* imaginary part */ + s1 = vec[3] + vec[19]; + s4 = vec[3] - vec[19]; + s3 = vec[15] + vec[7]; + s2 = vec[15] - vec[7]; + t = (s1 - s3) * C54; + s1 = s1 + s3; + y03 = vec[11] + s1; + s1 = y03 + (s1 * C55); + s3 = s1 - t; + s1 = s1 + t; + t = (s4 + s2) * C51; + s4 = t + (s4 * C52); + s2 = t + (s2 * C53); + + /* combination */ + y06 = r1 + s2; + y18 = r1 - s2; + y10 = r3 - s4; + y14 = r3 + s4; + y07 = s1 - r2; + y19 = s1 + r2; + y11 = s3 + r4; + y15 = s3 - r4; + + /* 5 fft2 stages */ + vec[0] = y00 + y02; + vec[1] = y01 + y03; + vec[2] = y12 - y14; + vec[3] = y13 - y15; + vec[4] = y04 + y06; + vec[5] = y05 + y07; + vec[6] = y16 - y18; + vec[7] = y17 - y19; + vec[8] = y08 + y10; + vec[9] = y09 + y11; + vec[10] = y00 - y02; + vec[11] = y01 - y03; + vec[12] = y12 + y14; + vec[13] = y13 + y15; + vec[14] = y04 - y06; + vec[15] = y05 - y07; + vec[16] = y16 + y18; + vec[17] = y17 + y19; + vec[18] = y08 - y10; + vec[19] = y09 - y11; +} + +/** + * \brief Function performs a complex 20-point FFT + * The FFT is performed inplace. The result of the FFT + * is scaled by SCALEFACTOR20 bits. + * + * WOPS FLC version: 1509 cycles + * WOPS with 32x16 bit multiplications: 432 cycles + * + * \param [i/o] re real input / output + * \param [i/o] im imag input / output + * \param [i ] s stride real and imag input / output + * + * \return void + */ +static void fft20(float *signal) +{ + const int s = 2; + float *re = signal, *im = signal+1; + float r1,r2,r3,r4; + float s1,s2,s3,s4; + float x0,x1,x2,x3,x4; + float t,t0,t1,t2,t3,t4,t5,t6,t7; + float y00,y01,y02,y03,y04,y05,y06,y07,y08,y09; + float y10,y11,y12,y13,y14,y15,y16,y17,y18,y19; + float y20,y21,y22,y23,y24,y25,y26,y27,y28,y29; + float y30,y31,y32,y33,y34,y35,y36,y37,y38,y39; + + /* */ + + /* 1. FFT5 stage */ + + /* real part */ + x0 = re[s* 0]; + x1 = re[s*16]; + x2 = re[s*12]; + x3 = re[s* 8]; + x4 = re[s* 4]; + r1 = x1 + x4; + r4 = x1 - x4; + r3 = x2 + x3; + r2 = x2 - x3; + t = (r1 - r3) * C54; + r1 = r1 + r3; + y00 = x0 + r1; + r1 = y00 + (r1 * C55); + r3 = r1 - t; + r1 = r1 + t; + t = (r4 + r2) * C51; + r4 = t + (r4 * C52); + r2 = t + (r2 * C53); + + /* imaginary part */ + x0 = im[s* 0]; + x1 = im[s*16]; + x2 = im[s*12]; + x3 = im[s* 8]; + x4 = im[s* 4]; + s1 = x1 + x4; + s4 = x1 - x4; + s3 = x2 + x3; + s2 = x2 - x3; + t = (s1 - s3) * C54; + s1 = (s1 + s3); + y01 = (x0 + s1); + s1 = y01 + (s1 * C55); + s3 = (s1 - t); + s1 = (s1 + t); + t = (s4 + s2) * C51; + s4 = t + (s4 * C52); + s2 = t + (s2 * C53); + + /* combination */ + y08 = (r1 + s2); + y32 = (r1 - s2); + y16 = (r3 - s4); + y24 = (r3 + s4); + + y09 = (s1 - r2); + y33 = (s1 + r2); + y17 = (s3 + r4); + y25 = (s3 - r4); + + /* 2. FFT5 stage */ + + /* real part */ + x0 = re[s* 5]; + x1 = re[s* 1]; + x2 = re[s*17]; + x3 = re[s*13]; + x4 = re[s* 9]; + r1 = (x1 + x4); + r4 = (x1 - x4); + r3 = (x2 + x3); + r2 = (x2 - x3); + t = (r1 - r3) * C54; + r1 = (r1 + r3); + y02 = (x0 + r1); + r1 = y02 + (r1 * C55); + r3 = (r1 - t); + r1 = (r1 + t); + t = (r4 + r2) * C51; + r4 = t + (r4 * C52); + r2 = t + (r2 * C53); + + /* imaginary part */ + x0 = im[s* 5]; + x1 = im[s* 1]; + x2 = im[s*17]; + x3 = im[s*13]; + x4 = im[s* 9]; + s1 = (x1 + x4); + s4 = (x1 - x4); + s3 = (x2 + x3); + s2 = (x2 - x3); + t = (s1 - s3) * C54; + s1 = (s1 + s3); + y03 = (x0 + s1); + s1 = y03 + (s1 * C55); + s3 = (s1 - t); + s1 = (s1 + t); + t = (s4 + s2) * C51; + s4 = t + (s4 * C52); + s2 = t + (s2 * C53); + + /* combination */ + y10 = (r1 + s2); + y34 = (r1 - s2); + y18 = (r3 - s4); + y26 = (r3 + s4); + + y11 = (s1 - r2); + y35 = (s1 + r2); + y19 = (s3 + r4); + y27 = (s3 - r4); + + /* 3. FFT5 stage */ + + /* real part */ + x0 = re[s*10]; + x1 = re[s* 6]; + x2 = re[s* 2]; + x3 = re[s*18]; + x4 = re[s*14]; + r1 = (x1 + x4); + r4 = (x1 - x4); + r3 = (x2 + x3); + r2 = (x2 - x3); + t = (r1 - r3) * C54; + r1 = (r1 + r3); + y04 = (x0 + r1); + r1 = y04 + (r1 * C55); + r3 = (r1 - t); + r1 = (r1 + t); + t = (r4 + r2) * C51; + r4 = t + (r4 * C52); + r2 = t + (r2 * C53); + + /* imaginary part */ + x0 = im[s*10]; + x1 = im[s* 6]; + x2 = im[s* 2]; + x3 = im[s*18]; + x4 = im[s*14]; + s1 = (x1 + x4); + s4 = (x1 - x4); + s3 = (x2 + x3); + s2 = (x2 - x3); + t = (s1 - s3) * C54; + s1 = (s1 + s3); + y05 = (x0 + s1); + s1 = y05 + (s1 * C55); + s3 = (s1 - t); + s1 = (s1 + t); + t = (s4 + s2) * C51; + s4 = t + (s4 * C52); + s2 = t + (s2 * C53); + + /* combination */ + y12 = (r1 + s2); + y36 = (r1 - s2); + y20 = (r3 - s4); + y28 = (r3 + s4); + + y13 = (s1 - r2); + y37 = (s1 + r2); + y21 = (s3 + r4); + y29 = (s3 - r4); + + /* 4. FFT5 stage */ + + /* real part */ + x0 = re[s*15]; + x1 = re[s*11]; + x2 = re[s* 7]; + x3 = re[s* 3]; + x4 = re[s*19]; + r1 = (x1 + x4); + r4 = (x1 - x4); + r3 = (x2 + x3); + r2 = (x2 - x3); + t = (r1 - r3) * C54; + r1 = (r1 + r3); + y06 = (x0 + r1); + r1 = y06 + (r1 * C55); + r3 = (r1 - t); + r1 = (r1 + t); + t = (r4 + r2) * C51; + r4 = t + (r4 * C52); + r2 = t + (r2 * C53); + + /* imaginary part */ + x0 = im[s*15]; + x1 = im[s*11]; + x2 = im[s* 7]; + x3 = im[s* 3]; + x4 = im[s*19]; + s1 = (x1 + x4); + s4 = (x1 - x4); + s3 = (x2 + x3); + s2 = (x2 - x3); + t = (s1 - s3) * C54; + s1 = (s1 + s3); + y07 = (x0 + s1); + s1 = y07 + (s1 * C55); + s3 = (s1 - t); + s1 = (s1 + t); + t = (s4 + s2) * C51; + s4 = t + (s4 * C52); + s2 = t + (s2 * C53); + + /* combination */ + y14 = (r1 + s2); + y38 = (r1 - s2); + y22 = (r3 - s4); + y30 = (r3 + s4); + + y15 = (s1 - r2); + y39 = (s1 + r2); + y23 = (s3 + r4); + y31 = (s3 - r4); + + + /* 1. FFT4 stage */ + + /* Pre-additions */ + t0 = (y00 + y04); + t2 = (y00 - y04); + t1 = (y01 + y05); + t3 = (y01 - y05); + t4 = (y02 + y06); + t7 = (y02 - y06); + t5 = (y07 + y03); + t6 = (y07 - y03); + + /* Post-additions */ + re[s* 0] = (t0 + t4); + im[s* 0] = (t1 + t5); + re[s* 5] = (t2 - t6); + im[s* 5] = (t3 - t7); + re[s*10] = (t0 - t4); + im[s*10] = (t1 - t5); + re[s*15] = (t2 + t6); + im[s*15] = (t3 + t7); + + /* 2. FFT4 stage */ + + /* Pre-additions */ + t0 = (y08 + y12); + t2 = (y08 - y12); + t1 = (y09 + y13); + t3 = (y09 - y13); + t4 = (y10 + y14); + t7 = (y10 - y14); + t5 = (y15 + y11); + t6 = (y15 - y11); + + /* Post-additions */ + re[s* 4] = (t0 + t4); + im[s* 4] = (t1 + t5); + re[s* 9] = (t2 - t6); + im[s* 9] = (t3 - t7); + re[s*14] = (t0 - t4); + im[s*14] = (t1 - t5); + re[s*19] = (t2 + t6); + im[s*19] = (t3 + t7); + + + /* 3. FFT4 stage */ + + /* Pre-additions */ + t0 = (y16 + y20); + t2 = (y16 - y20); + t1 = (y17 + y21); + t3 = (y17 - y21); + t4 = (y18 + y22); + t7 = (y18 - y22); + t5 = (y23 + y19); + t6 = (y23 - y19); + + /* Post-additions */ + re[s* 8] = (t0 + t4); + im[s* 8] = (t1 + t5); + re[s*13] = (t2 - t6); + im[s*13] = (t3 - t7); + re[s*18] = (t0 - t4); + im[s*18] = (t1 - t5); + re[s* 3] = (t2 + t6); + im[s* 3] = (t3 + t7); + + /* 4. FFT4 stage */ + + /* Pre-additions */ + t0 = (y24 + y28); + t2 = (y24 - y28); + t1 = (y25 + y29); + t3 = (y25 - y29); + t4 = (y26 + y30); + t7 = (y26 - y30); + t5 = (y31 + y27); + t6 = (y31 - y27); + + /* Post-additions */ + re[s*12] = (t0 + t4); + im[s*12] = (t1 + t5); + re[s*17] = (t2 - t6); + im[s*17] = (t3 - t7); + re[s* 2] = (t0 - t4); + im[s* 2] = (t1 - t5); + re[s* 7] = (t2 + t6); + im[s* 7] = (t3 + t7); + + /* 5. FFT4 stage */ + + /* Pre-additions */ + t0 = (y32 + y36); + t2 = (y32 - y36); + t1 = (y33 + y37); + t3 = (y33 - y37); + t4 = (y34 + y38); + t7 = (y34 - y38); + t5 = (y39 + y35); + t6 = (y39 - y35); + + /* Post-additions */ + re[s*16] = (t0 + t4); + im[s*16] = (t1 + t5); + re[s* 1] = (t2 - t6); + im[s* 1] = (t3 - t7); + re[s* 6] = (t0 - t4); + im[s* 6] = (t1 - t5); + re[s*11] = (t2 + t6); + im[s*11] = (t3 + t7); + + /* */ + /* */ +} + +/******************************************************************************* + Functionname: fft30 + ******************************************************************************* + + Description: 30-point FFT. + + Arguments: in - pointer to data (interleaved real / imaginary parts) + + Return: none + +*******************************************************************************/ + +static void fft30(float * restrict in) +{ + int i; + float temp[60]; + float * temp_l = temp; + float * temp_lu = temp + 2*8; + float * temp_h = temp + 2*15; + float * temp_hu = temp + 2*15 + 2*8; + float *in_l = in + 2*0; + float *in_h = in + 2*15; + for(i=0; i<7; i++) + { + *temp_l++ = *in_l++; + *temp_l++ = *in_l++; + *temp_h++ = *in_h++; + *temp_h++ = *in_h++; + *temp_l++ = *in_h++; + *temp_l++ = *in_h++; + *temp_h++ = *in_l++; + *temp_h++ = *in_l++; + } + *temp_l++ = *in_l++; + *temp_l++ = *in_l++; + *temp_h++ = *in_h++; + *temp_h++ = *in_h++; + temp_l = temp; + temp_h = temp + 30; + fft15(temp_l); + fft15(temp_h); + + in_l = in + 2*0; + in_h = in + 2*15; + for(i=0; i<7; i++) + { + *in_l++ = *temp_l + *temp_h; + *in_h++ = *temp_l++ - *temp_h++; + *in_l++ = *temp_l + *temp_h; + *in_h++ = *temp_l++ - *temp_h++; + + *in_h++ = *temp_lu + *temp_hu; + *in_l++ = *temp_lu++ - *temp_hu++; + *in_h++ = *temp_lu + *temp_hu; + *in_l++ = *temp_lu++ - *temp_hu++; + } + *in_l++ = *temp_l + *temp_h; + *in_h++ = *temp_l++ - *temp_h++; + *in_l++ = *temp_l + *temp_h; + *in_h++ = *temp_l++ - *temp_h++; +} + +/*-------------------------------------------------------------------* + * fft_cldfb() + * + * Interface functions FFT subroutines + *--------------------------------------------------------------------*/ +void fft_cldfb ( + float *data, /* i/o: input/output vector */ + int size /* size of fft operation */ +) +{ + + switch(size) + { + case 5: + fft5s(data,2); + break; + case 8: + fft8(data); + break; + case 10: + fft10(data); + break; + case 16: + fft16(data); + break; + case 20: + fft20(data); + break; + case 30: + fft30(data); + break; + + default: + assert(0); + break; + } +} + diff --git a/src/libs/libevs/lib_com/fft_fx.cpp b/src/libs/libevs/lib_com/fft_fx.cpp deleted file mode 100755 index 9d386cf9..00000000 --- a/src/libs/libevs/lib_com/fft_fx.cpp +++ /dev/null @@ -1,2832 +0,0 @@ -/*==================================================================================== - EVS Codec 3GPP TS26.442 Apr 03, 2018. Version 12.11.0 / 13.6.0 / 14.2.0 - ====================================================================================*/ - -#include "options.h" /* Compilation switches */ -#include "cnst_fx.h" /* Common constants */ -#include "prot_fx.h" /* Function prototypes */ -#include "rom_com_fx.h" /* Static table prototypes */ -#include "stl.h" -#include - -/*-----------------------------------------------------------------* -* Local functions -*-----------------------------------------------------------------*/ - -#define FFT3_ONE_THIRD 21845 /* 1/3 in Q16 */ - -static void fft5_shift4_16fx( Word16 n1, Word16 *zRe, Word16 *zIm, const Word16 *Idx ); -static void fft64_16fx( Word16 *x, Word16 *y, const Word16 *Idx ); -static void fft32_5_16fx( Word16 *x, Word16 *y, const Word16 *Idx ); -static void cftmdl_16fx(Word16 n, Word16 l, Word16 *a, const Word32 *w); -static void cftfsub_16fx( Word16 n, Word16 *a, const Word32 *w ); -static void cft1st_16fx(Word16 n, Word16 *a, const Word32 *w); -static void cftmdl_16fx(Word16 n, Word16 l, Word16 *a, const Word32 *w); -static void fft5_shift4_16fx( Word16 n1, Word16 *zRe, Word16 *zIm, const Word16 *Idx ); -static void bitrv2_SR_16fx( Word16 n, const Word16 *ip, Word16 *a ); -static void fft64_16fx( Word16 *x, Word16 *y, const Word16 *Idx ); -static void fft5_32_16fx( Word16 *zRe, Word16 *zIm, const Word16 *Idx ); -static void cdftForw_16fx( Word16 n, Word16 *a, const Word16 *ip, const Word32 *w ); - -#include "math_32.h" - -/*-----------------------------------------------------------------* -* Local functions -*-----------------------------------------------------------------*/ -static void cdftForw_fx( Word16 n, Word32 *a, const Word16 *ip, const Word16 *w ); -static void bitrv2_SR_fx( Word16 n, const Word16 *ip, Word32 *a ); -static void cftfsub_fx( Word16 n, Word32 *a, const Word16 *w ); -static void cft1st_fx( Word16 n, Word32 *a, const Word16 *w ); -static void cftmdl_fx( Word16 n, Word16 l, Word32 *a, const Word16 *w ); - - -void DoRTFTn_fx( - Word32 *x, /* i/o : real part of input and output data */ - Word32 *y, /* i/o : imaginary part of input and output data */ - const Word16 n /* i : size of the FFT up to 1024 */ -) -{ - - Word16 i; - Word32 z[2048], *pt; - - pt = z; - FOR ( i=0; i=1 ; i--) - { - x[i]=*pt++; - move16(); - y[i]=*pt++; - move16(); - } - - return; -} - -/*-----------------------------------------------------------------* - * cdftForw_fx() - * Main fuction of Complex Discrete Fourier Transform - *-----------------------------------------------------------------*/ -static void cdftForw_fx( - Word16 n, /* i : data length of real and imag */ - Word32 *a, /* i/o : input/output data Q(q)*/ - const Word16 *ip, /* i : work area for bit reversal */ - const Word16 *w /* i : cos/sin table Q14*/ -) -{ - /* bit reversal */ - bitrv2_SR_fx(n, ip + 2, a); - - /* Do FFT */ - cftfsub_fx(n, a, w); -} - -/*-----------------------------------------------------------------* - * bitrv2_SR_fx() - * Bit reversal - *-----------------------------------------------------------------*/ -static void bitrv2_SR_fx( - Word16 n, /* i : data length of real and imag */ - const Word16 *ip, /* i/o : work area for bit reversal */ - Word32 *a /* i/o : input/output data Q(q)*/ -) -{ - Word16 j, j1, k, k1, m, m2; - Word16 l; - Word32 xr, xi, yr, yi; - - l = n; - move16(); - m = 1; - move16(); - - WHILE (shl(m, 3) < l) - { - l = shr(l, 1); - m = shl(m, 1); - } - - m2 = shl(m, 1); - IF (shl(m, 3) == l) - { - FOR (k = 0; k < m; k++) - { - FOR (j = 0; j < k; j++) - { - j1 = add(shl(j, 1), ip[k]); - k1 = add(shl(k, 1), ip[j]); - xr = L_add(0,a[j1]); - xi = L_add(0,a[j1 + 1]); - yr = L_add(0,a[k1]); - yi = L_add(0,a[k1 + 1]); - a[j1] = yr; - move32(); - a[j1 + 1] = yi; - move32(); - a[k1] = xr; - move32(); - a[k1 + 1] = xi; - move32(); - j1 = add(j1, m2); - k1 = add(k1, shl(m2, 1)); - xr = L_add(0,a[j1]); - xi = L_add(0,a[j1 + 1]); - yr = L_add(0,a[k1]); - yi = L_add(0,a[k1 + 1]); - a[j1] = yr; - move32(); - a[j1 + 1] = yi; - move32(); - a[k1] = xr; - move32(); - a[k1 + 1] = xi; - move32(); - j1 = add(j1, m2); - k1 = sub(k1, m2); - xr = L_add(0,a[j1]); - xi = L_add(0,a[j1 + 1]); - xi = L_add(0,a[j1 + 1]); - yr = L_add(0,a[k1]); - yi = L_add(0,a[k1 + 1]); - a[j1] = yr; - move32(); - a[j1 + 1] = yi; - move32(); - a[k1] = xr; - move32(); - a[k1 + 1] = xi; - move32(); - j1 = add(j1, m2); - k1 = add(k1, shl(m2, 1)); - xr = L_add(0,a[j1]); - xi = L_add(0,a[j1 + 1]); - yr = L_add(0,a[k1]); - yi = L_add(0,a[k1 + 1]); - a[j1] = yr; - move32(); - a[j1 + 1] = yi; - move32(); - a[k1] = xr; - move32(); - a[k1 + 1] = xi; - move32(); - } - - j1 = add(add(shl(k, 1), m2), ip[k]); - k1 = add(j1, m2); - xr = L_add(0,a[j1]); - xi = L_add(0,a[j1 + 1]); - yr = L_add(0,a[k1]); - yi = L_add(0,a[k1 + 1]); - a[j1] = yr; - move32(); - a[j1 + 1] = yi; - move32(); - a[k1] = xr; - move32(); - a[k1 + 1] = xi; - move32(); - } - } - ELSE - { - FOR (k = 1; k < m; k++) - { - FOR (j = 0; j < k; j++) - { - j1 = add(shl(j, 1), ip[k]); - k1 = add(shl(k, 1), ip[j]); - xr = L_add(0,a[j1]); - xi = L_add(0,a[j1 + 1]); - yr = L_add(0,a[k1]); - yi = L_add(0,a[k1 + 1]); - a[j1] = yr; - move32(); - a[j1 + 1] = yi; - move32(); - a[k1] = xr; - move32(); - a[k1 + 1] = xi; - move32(); - j1 = add(j1, m2); - k1 = add(k1, m2); - xr = L_add(0,a[j1]); - xi = L_add(0,a[j1 + 1]); - yr = L_add(0,a[k1]); - yi = L_add(0,a[k1 + 1]); - a[j1] = yr; - move32(); - a[j1 + 1] = yi; - move32(); - a[k1] = xr; - move32(); - a[k1 + 1] = xi; - move32(); - } - } - } - - return; -} - -/*-----------------------------------------------------------------* - * cftfsub_fx() - * Complex Discrete Fourier Transform - *-----------------------------------------------------------------*/ -static void cftfsub_fx( - Word16 n, /* i : data length of real and imag */ - Word32 *a, /* i/o : input/output data Q(q)*/ - const Word16 *w /* i : cos/sin table Q14*/ -) -{ - Word16 j, j1, j2, j3, l; - Word32 x0r, x0i, x1r, x1i, x2r, x2i, x3r, x3i; - - l = 2; - move16(); - - IF (n > 8) - { - cft1st_fx(n, a, w); - l = 8; - move16(); - WHILE ((shl(l, 2) < n)) - { - cftmdl_fx(n, l, a, w); - l = shl(l, 2); - } - } - IF (shl(l, 2) == n) - { - FOR (j = 0; j < l; j += 2) - { - j1 = add(j, l); - j2 = add(j1, l); - j3 = add(j2, l); - x0r = L_add(a[j], a[j1]); - x0i = L_add(a[j + 1], a[j1 + 1]); - x1r = L_sub(a[j], a[j1]); - x1i = L_sub(a[j + 1], a[j1 + 1]); - x2r = L_add(a[j2], a[j3]); - x2i = L_add(a[j2 + 1], a[j3 + 1]); - x3r = L_sub(a[j2], a[j3]); - x3i = L_sub(a[j2 + 1], a[j3 + 1]); - a[j] = L_add(x0r, x2r); - move32(); - a[j2] = L_sub(x0r, x2r); - move32(); - a[j + 1] = L_add(x0i, x2i); - move32(); - a[j2 + 1] = L_sub(x0i, x2i); - move32(); - a[j1] = L_sub(x1r, x3i); - move32(); - a[j1 + 1] = L_add(x1i, x3r); - move32(); - a[j3] = L_add(x1r, x3i); - move32(); - a[j3 + 1] = L_sub(x1i, x3r); - move32(); - } - } - ELSE - { - FOR (j = 0; j < l; j += 2) - { - j1 = add(j, l); - x0r = L_sub(a[j], a[j1]); - x0i = L_sub(a[j + 1], a[j1 + 1]); - a[j] = L_add(a[j], a[j1]); - move32(); - a[j + 1] = L_add(a[j + 1], a[j1 + 1]); - move32(); - a[j1] = x0r; - move32(); - move32(); - a[j1 + 1] = x0i; - move32(); - move32(); - } - } - - return; -} - -/*-----------------------------------------------------------------* - * cft1st_fx() - * Subfunction of Complex Discrete Fourier Transform - *-----------------------------------------------------------------*/ -static void cft1st_fx( - Word16 n, /* i : data length of real and imag */ - Word32 *a, /* i/o : input/output data Q(q)*/ - const Word16 *w /* i : cos/sin table Q14*/ -) -{ - Word16 j, k1, k2; - Word16 wk1r, wk1i, wk2r, wk2i, wk3r, wk3i; - Word32 x0r, x0i, x1r, x1i, x2r, x2i, x3r, x3i; - - x0r = L_add(a[0], a[2]); - x0i = L_add(a[1], a[3]); - x1r = L_sub(a[0], a[2]); - x1i = L_sub(a[1], a[3]); - x2r = L_add(a[4], a[6]); - x2i = L_add(a[5], a[7]); - x3r = L_sub(a[4], a[6]); - x3i = L_sub(a[5], a[7]); - a[0] = L_add(x0r, x2r); - move32(); - a[1] = L_add(x0i, x2i); - move32(); - a[4] = L_sub(x0r, x2r); - move32(); - a[5] = L_sub(x0i, x2i); - move32(); - a[2] = L_sub(x1r, x3i); - move32(); - a[3] = L_add(x1i, x3r); - move32(); - a[6] = L_add(x1r, x3i); - move32(); - a[7] = L_sub(x1i, x3r); - move32(); - - wk1r = w[2]; - move16(); - x0r = L_add(a[8], a[10]); - x0i = L_add(a[9], a[11]); - x1r = L_sub(a[8], a[10]); - x1i = L_sub(a[9], a[11]); - x2r = L_add(a[12], a[14]); - x2i = L_add(a[13], a[15]); - x3r = L_sub(a[12], a[14]); - x3i = L_sub(a[13], a[15]); - a[8] = L_add(x0r, x2r); - move32(); - a[9] = L_add(x0i, x2i); - move32(); - a[12] = L_sub(x2i, x0i); - move32(); - a[13] = L_sub(x0r, x2r); - move32(); - - x0r = L_sub(x1r, x3i); - x0i = L_add(x1i ,x3r); - a[10] = Mult_32_16(L_shl(L_sub(x0r, x0i), 1), wk1r); - move32(); - a[11] = Mult_32_16(L_shl(L_add(x0r, x0i), 1), wk1r); - move32(); - x0r = L_add(x3i, x1r); - x0i = L_sub(x3r,x1i); - a[14] = Mult_32_16(L_shl(L_sub(x0i, x0r), 1), wk1r); - move32(); - a[15] = Mult_32_16(L_shl(L_add(x0i, x0r), 1), wk1r); - move32(); - - k1 = 0; - move16(); - FOR (j = 16; j < n; j += 16) - { - k1 = add(k1, 2); - k2 = shl(k1, 1); - wk2r = w[k1]; - move16(); - wk2i = w[k1 + 1]; - move16(); - wk1r = w[k2]; - move16(); - wk1i = w[k2 + 1]; - move16(); - wk3r = extract_l(L_sub(L_deposit_l(wk1r), L_shr(L_mult(wk2i, wk1i), 14))); - wk3i = extract_l(L_msu0(L_shr(L_mult(wk2i, wk1r), 14), wk1i, 1)); - x0r = L_add(a[j], a[j + 2]); - x0i = L_add(a[j + 1], a[j + 3]); - x1r = L_sub(a[j], a[j + 2]); - x1i = L_sub(a[j + 1], a[j + 3]); - x2r = L_add(a[j + 4], a[j + 6]); - x2i = L_add(a[j + 5], a[j + 7]); - x3r = L_sub(a[j + 4], a[j + 6]); - x3i = L_sub(a[j + 5], a[j + 7]); - a[j] = L_add(x0r, x2r); - move32(); - a[j + 1] = L_add(x0i, x2i); - move32(); - x0r = L_sub(x0r, x2r); - x0i = L_sub(x0i, x2i); - a[j + 4] = L_sub(Mult_32_16(L_shl(x0r, 1), wk2r), Mult_32_16(L_shl(x0i, 1), wk2i)); - move32(); - a[j + 5] = L_add(Mult_32_16(L_shl(x0i, 1), wk2r), Mult_32_16(L_shl(x0r, 1), wk2i)); - move32(); - x0r = L_sub(x1r, x3i); - x0i = L_add(x1i, x3r); - a[j + 2] = L_sub(Mult_32_16(L_shl(x0r, 1), wk1r), Mult_32_16(L_shl(x0i, 1), wk1i)); - move32(); - a[j + 3] = L_add(Mult_32_16(L_shl(x0i, 1), wk1r), Mult_32_16(L_shl(x0r, 1), wk1i)); - move32(); - x0r = L_add(x1r, x3i); - x0i = L_sub(x1i, x3r); - a[j + 6] = L_sub(Mult_32_16(L_shl(x0r, 1), wk3r), Mult_32_16(L_shl(x0i, 1), wk3i)); - move32(); - a[j + 7] = L_add(Mult_32_16(L_shl(x0i, 1), wk3r), Mult_32_16(L_shl(x0r, 1), wk3i)); - move32(); - - wk1r = w[k2 + 2]; - move16(); - wk1i = w[k2 + 3]; - move16(); - wk3r = extract_l(L_sub(L_deposit_l(wk1r), L_shr(L_mult(wk2r, wk1i), 14))); - wk3i = extract_l(L_msu0(L_shr(L_mult(wk2r, wk1r), 14), wk1i, 1)); - x0r = L_add(a[j + 8], a[j + 10]); - x0i = L_add(a[j + 9], a[j + 11]); - x1r = L_sub(a[j + 8], a[j + 10]); - x1i = L_sub(a[j + 9], a[j + 11]); - x2r = L_add(a[j + 12], a[j + 14]); - x2i = L_add(a[j + 13], a[j + 15]); - x3r = L_sub(a[j + 12], a[j + 14]); - x3i = L_sub(a[j + 13], a[j + 15]); - a[j + 8] = L_add(x0r, x2r); - move32(); - a[j + 9] = L_add(x0i, x2i); - move32(); - x0r = L_sub(x0r, x2r); - x0i = L_sub(x0i, x2i); - a[j + 12] = L_negate(L_add(Mult_32_16(L_shl(x0r, 1), wk2i), Mult_32_16(L_shl(x0i, 1), wk2r))); - move32(); - a[j + 13] = L_sub(Mult_32_16(L_shl(x0r, 1), wk2r), Mult_32_16(L_shl(x0i, 1), wk2i)); - move32(); - x0r = L_sub(x1r, x3i); - x0i = L_add(x1i, x3r); - a[j + 10] = L_sub(Mult_32_16(L_shl(x0r, 1), wk1r), Mult_32_16(L_shl(x0i, 1), wk1i)); - move32(); - a[j + 11] = L_add(Mult_32_16(L_shl(x0i, 1), wk1r), Mult_32_16(L_shl(x0r, 1), wk1i)); - move32(); - x0r =L_add(x1r, x3i); - x0i =L_sub(x1i, x3r); - a[j + 14] = L_sub(Mult_32_16(L_shl(x0r, 1), wk3r), Mult_32_16(L_shl(x0i, 1), wk3i)); - move32(); - a[j + 15] = L_add(Mult_32_16(L_shl(x0i, 1), wk3r), Mult_32_16(L_shl(x0r, 1), wk3i)); - move32(); - } - - return; -} - -/*-----------------------------------------------------------------* - * cftmdl_fx() - * Subfunction of Complex Discrete Fourier Transform - *-----------------------------------------------------------------*/ -static void cftmdl_fx( - Word16 n, /* i : data length of real and imag */ - Word16 l, /* i : initial shift for processing */ - Word32 *a, /* i/o : input/output data Q(Qx+Q_edct)*/ - const Word16 *w /* i : cos/sin table Q30*/ -) -{ - Word16 j, j1, j2, j3, k, k1, k2, m, m2; - Word16 wk1r, wk1i, wk2r, wk2i, wk3r, wk3i; - Word32 x0r, x0i, x1r, x1i, x2r, x2i, x3r, x3i; - Word16 tmp; - - m = shl(l, 2); - FOR (j = 0; j < l; j += 2) - { - j1 = add(j, l); - j2 = add(j1, l); - j3 = add(j2, l); - x0r = L_add(a[j], a[j1]); - x0i = L_add(a[j + 1], a[j1 + 1]); - x1r = L_sub(a[j], a[j1]); - x1i = L_sub(a[j + 1], a[j1 + 1]); - x2r = L_add(a[j2], a[j3]); - x2i = L_add(a[j2 + 1], a[j3 + 1]); - x3r = L_sub(a[j2], a[j3]); - x3i = L_sub(a[j2 + 1], a[j3 + 1]); - a[j] = L_add(x0r, x2r); - move32(); - a[j + 1] = L_add(x0i, x2i); - move32(); - a[j2] = L_sub(x0r, x2r); - move32(); - a[j2 + 1] =L_sub(x0i, x2i); - move32(); - a[j1] = L_sub(x1r, x3i); - move32(); - a[j1 + 1] = L_add(x1i, x3r); - move32(); - a[j3] = L_add(x1r, x3i); - move32(); - a[j3 + 1] = L_sub(x1i, x3r); - move32(); - } - - wk1r = w[2]; - move16(); - tmp = add(l, m); - FOR (j = m; j < tmp; j += 2) - { - j1 = add(j, l); - j2 = add(j1, l); - j3 = add(j2, l); - x0r = L_add(a[j], a[j1]); - x0i = L_add(a[j + 1], a[j1 + 1]); - x1r = L_sub(a[j], a[j1]); - x1i = L_sub(a[j + 1], a[j1 + 1]); - x2r = L_add(a[j2], a[j3]); - x2i = L_add(a[j2 + 1], a[j3 + 1]); - x3r = L_sub(a[j2], a[j3]); - x3i = L_sub(a[j2 + 1], a[j3 + 1]); - a[j] = L_add(x0r, x2r); - move32(); - a[j + 1] = L_add(x0i, x2i); - move32(); - a[j2] = L_sub(x2i, x0i); - move32(); - a[j2 + 1] = L_sub(x0r, x2r); - move32(); - x0r = L_sub(x1r, x3i); - x0i = L_add(x1i, x3r); - a[j1] = Mult_32_16(L_shl(L_sub(x0r, x0i), 1), wk1r); - move32(); - a[j1 + 1] = Mult_32_16(L_shl(L_add(x0r, x0i), 1), wk1r); - move32(); - x0r = L_add(x3i, x1r); - x0i = L_sub(x3r, x1i); - a[j3] = Mult_32_16(L_shl(L_sub(x0i, x0r), 1), wk1r); - move32(); - a[j3 + 1] = Mult_32_16(L_shl(L_add(x0r, x0i), 1), wk1r); - move32(); - } - - k1 = 0; - move16(); - m2 = shl(m, 1); - FOR (k = m2; k < n; k += m2) - { - k1 = add(k1, 2); - k2 = shl(k1, 1); - wk2r = w[k1]; - move16(); - wk2i = w[k1 + 1]; - move16(); - wk1r = w[k2]; - move16(); - wk1i = w[k2 + 1]; - move16(); - wk3r = extract_l(L_sub(L_deposit_l(wk1r), L_shr(L_mult(wk2i, wk1i), 14))); - wk3i = extract_l(L_msu0(L_shr(L_mult(wk2i, wk1r), 14), wk1i, 1)); - - tmp = add(l, k) ; - FOR (j = k; j < tmp; j += 2) - { - j1 = add(j, l); - j2 = add(j1, l); - j3 = add(j2, l); - x0r = L_add(a[j], a[j1]); - x0i = L_add(a[j + 1], a[j1 + 1]); - x1r = L_sub(a[j], a[j1]); - x1i = L_sub(a[j + 1], a[j1 + 1]); - x2r = L_add(a[j2], a[j3]); - x2i = L_add(a[j2 + 1], a[j3 + 1]); - x3r = L_sub(a[j2], a[j3]); - x3i = L_sub(a[j2 + 1], a[j3 + 1]); - a[j] = L_add(x0r, x2r); - move32(); - a[j + 1] = L_add(x0i, x2i); - move32(); - x0r = L_sub(x0r, x2r); - x0i = L_sub(x0i, x2i); - a[j2] = L_sub(Mult_32_16(L_shl(x0r, 1), wk2r), Mult_32_16(L_shl(x0i, 1), wk2i)); - move32(); - a[j2 + 1] = L_add(Mult_32_16(L_shl(x0i, 1), wk2r), Mult_32_16(L_shl(x0r, 1), wk2i)); - move32(); - x0r = L_sub(x1r, x3i); - x0i = L_add(x1i, x3r); - a[j1] = L_sub(Mult_32_16(L_shl(x0r, 1), wk1r), Mult_32_16(L_shl(x0i, 1), wk1i)); - move32(); - a[j1 + 1] = L_add(Mult_32_16(L_shl(x0i, 1), wk1r), Mult_32_16(L_shl(x0r, 1), wk1i)); - move32(); - x0r = L_add(x1r, x3i); - x0i = L_sub(x1i, x3r); - a[j3] = L_sub(Mult_32_16(L_shl(x0r, 1), wk3r), Mult_32_16(L_shl(x0i, 1), wk3i)); - move32(); - a[j3 + 1] = L_add(Mult_32_16(L_shl(x0i, 1), wk3r), Mult_32_16(L_shl(x0r, 1), wk3i)); - move32(); - } - - wk1r = w[k2 + 2]; - move16(); - wk1i = w[k2 + 3]; - move16(); - wk3r = extract_l(L_sub(L_deposit_l(wk1r), L_shr(L_mult(wk2r, wk1i), 14))); - wk3i = extract_l(L_msu0(L_shr(L_mult(wk2r, wk1r), 14), wk1i, 1)); - - tmp = add(l, add(k, m)); - FOR (j = add(k, m); j < tmp; j += 2) - { - j1 = add(j, l); - j2 = add(j1, l); - j3 = add(j2, l); - x0r = L_add(a[j], a[j1]); - x0i = L_add(a[j + 1], a[j1 + 1]); - x1r = L_sub(a[j], a[j1]); - x1i = L_sub(a[j + 1], a[j1 + 1]); - x2r = L_add(a[j2], a[j3]); - x2i = L_add(a[j2 + 1], a[j3 + 1]); - x3r = L_sub(a[j2], a[j3]); - x3i = L_sub(a[j2 + 1], a[j3 + 1]); - a[j] = L_add(x0r, x2r); - move32(); - a[j + 1] = L_add(x0i, x2i); - move32(); - x0r= L_sub(x0r, x2r); - x0i=L_sub(x0i, x2i); - a[j2] = L_negate(L_add(Mult_32_16(L_shl(x0r, 1), wk2i), Mult_32_16(L_shl(x0i, 1), wk2r))); - move32(); - a[j2 + 1] = L_sub(Mult_32_16(L_shl(x0r, 1), wk2r), Mult_32_16(L_shl(x0i, 1), wk2i)); - move32(); - x0r = L_sub(x1r, x3i); - x0i = L_add(x1i, x3r); - a[j1] = L_sub(Mult_32_16(L_shl(x0r, 1), wk1r), Mult_32_16(L_shl(x0i, 1), wk1i)); - move32(); - a[j1 + 1] = L_add(Mult_32_16(L_shl(x0i, 1), wk1r), Mult_32_16(L_shl(x0r, 1), wk1i)); - move32(); - x0r = L_add(x1r, x3i); - x0i = L_sub(x1i, x3r); - a[j3] = L_sub(Mult_32_16(L_shl(x0r, 1), wk3r), Mult_32_16(L_shl(x0i, 1), wk3i)); - move32(); - a[j3 + 1] = L_add(Mult_32_16(L_shl(x0i, 1), wk3r), Mult_32_16(L_shl(x0r, 1), wk3i)); - move32(); - } - } - - return; -} - - -static void cftbsub_fx( - Word16 n, - Word32 *a, - const Word16 *w /* i : cos/sin table */ -) -{ - Word16 j, j1, j2, j3, l; - Word32 x0r, x0i, x1r, x1i, x2r, x2i, x3r, x3i; - - l = 2; - move16(); - IF (n > 8) - { - cft1st_fx(n, a, w); - l = 8; - move16(); - - WHILE (sub(shl(l, 2), n) < 0) - { - cftmdl_fx(n, l, a, w); - l = shl(l, 2); - } - } - - IF (sub(shl(l, 2), n) == 0) - { - FOR (j = 0; j < l; j += 2) - { - j1 = add(j, l); - j2 = add(j1, l); - j3 = add(j2, l); - x0r = L_add(a[j], a[j1]); - x0i = L_negate(L_add(a[j + 1], a[j1 + 1])); - x1r = L_sub(a[j], a[j1]); - x1i = L_sub(a[j1 + 1], a[j + 1]); - x2r = L_add(a[j2], a[j3]); - x2i = L_add(a[j2 + 1], a[j3 + 1]); - x3r = L_sub(a[j2], a[j3]); - x3i = L_sub(a[j2 + 1], a[j3 + 1]); - a[j] = L_add(x0r, x2r); - move32(); - a[j + 1] = L_sub(x0i, x2i); - move32(); - a[j2] = L_sub(x0r, x2r); - move32(); - a[j2 + 1] = L_add(x0i, x2i); - move32(); - a[j1] = L_sub(x1r, x3i); - move32(); - a[j1 + 1] = L_sub(x1i, x3r); - move32(); - a[j3] = L_add(x1r, x3i); - move32(); - a[j3 + 1] = L_add(x1i, x3r); - move32(); - } - } - ELSE - { - FOR (j = 0; j < l; j += 2) - { - j1 = add(j, l); - x0r = L_sub(a[j], a[j1]); - x0i = L_sub(a[j1 + 1], a[j + 1]); - a[j] = L_add(a[j], a[j1]); - move32(); - a[j + 1] = L_negate(L_add(a[j + 1], a[j1 + 1])); - move32(); - a[j1] = x0r; - move32(); - move32(); - a[j1 + 1] = x0i; - move32(); - move32(); - } - } -} - -static void rftfsub_fx( - Word16 n, - Word32 *a, - Word16 nc, - const Word16 *c -) -{ - Word16 j, k, kk, ks, m, tmp; - Word32 xr, xi, yr, yi; - Word16 wkr, wki; - - m = shr(n, 1); - /*ks = 2 * nc / m; */ - tmp = shl(nc, 1); - ks = 0; - move16(); - WHILE (sub(tmp, m) >= 0) - { - ks = add(ks, 1); - tmp = sub(tmp, m); - } - kk = 0; - move16(); - FOR (j = 2; j < m; j += 2) - { - k = sub(n, j); - kk = add(kk, ks); - wkr = sub(8192, c[nc - kk]); - wki = c[kk]; - move16(); - xr = L_sub(a[j], a[k]); - xi = L_add(a[j + 1], a[k + 1]); - yr = L_sub(Mult_32_16(L_shl(xr, 1), wkr), Mult_32_16(L_shl(xi, 1), wki)); - yi = L_add(Mult_32_16(L_shl(xi, 1), wkr), Mult_32_16(L_shl(xr, 1), wki)); - a[j] = L_sub(a[j], yr); - move32(); - a[j + 1] = L_sub(a[j + 1], yi); - move32(); - a[k] = L_add(a[k], yr); - move32(); - a[k + 1] = L_sub(a[k + 1], yi); - move32(); - } -} - - -static void rftbsub_fx( - Word16 n, - Word32 *a, - Word16 nc, - const Word16 *c -) -{ - Word16 j, k, kk, ks, m, tmp; - Word32 xr, xi, yr, yi; - Word16 wkr, wki; - - a[1] = L_negate(a[1]); - m = shr(n, 1); - /*ks = 2 * nc / m; */ - tmp = shl(nc, 1); - ks = 0; - move16(); - WHILE (sub(tmp, m) >= 0) - { - ks = add(ks, 1); - tmp = sub(tmp, m); - } - kk = 0; - move16(); - FOR (j = 2; j < m; j += 2) - { - k = sub(n, j); - kk = add(kk, ks); - wkr = sub(8192, c[nc - kk]); - wki = c[kk]; - move16(); - xr = L_sub(a[j], a[k]); - xi = L_add(a[j + 1], a[k + 1]); - yr = L_add(Mult_32_16(L_shl(xr, 1), wkr), Mult_32_16(L_shl(xi, 1), wki)); - yi = L_sub(Mult_32_16(L_shl(xi, 1), wkr), Mult_32_16(L_shl(xr, 1), wki)); - a[j] = L_sub(a[j], yr); - move32(); - a[j + 1] = L_sub(yi, a[j + 1]); - move32(); - a[k] = L_add(a[k], yr); - move32(); - a[k + 1] = L_sub(yi, a[k + 1]); - move32(); - } - a[m + 1] = L_negate(a[m + 1]); - move32(); -} - - -static void dctsub_fx( - Word16 n, - Word32 *a, - Word16 nc, - const Word16 *c -) -{ - Word16 j, k, kk, ks, m, tmp; - Word16 wkr, wki; - Word32 xr; - - m = shr(n, 1); - /*ks = nc / n; */ - tmp = nc; - move16(); - ks = 0; - move16(); - WHILE (sub(tmp, n) >= 0) - { - ks = add(ks, 1); - tmp = sub(tmp, n); - } - kk = 0; - move16(); - FOR (j = 1; j < m; j++) - { - k = sub(n, j); - kk = add(kk, ks); - wkr = sub(c[kk], c[nc - kk]); - wki = add(c[kk], c[nc - kk]); - xr = L_sub(Mult_32_16(L_shl(a[j], 1), wki), Mult_32_16(L_shl(a[k], 1), wkr)); - a[j] = L_add(Mult_32_16(L_shl(a[j], 1), wkr), Mult_32_16(L_shl(a[k], 1), wki)); - move32(); - a[k] = xr; - move32(); - } - a[m] = Mult_32_16(L_shl(a[m], 1), c[0]); -} - -/*-----------------------------------------------------------------* - * edct2_fx() - * - * Transformation of the signal to DCT domain - * OR Inverse EDCT-II for short frames - *-----------------------------------------------------------------*/ - -void edct2_fx( - Word16 n, - Word16 isgn, - Word16 *in, - Word32 *a, - Word16 *q, - const Word16 *ip, - const Word16 *w -) -{ - Word16 j, nw, nc; - Word32 xr; - - *q = Exp16Array(n, in); - *q = add(*q, 6); - FOR (j = 0; j < n; j++) - { - a[j] = L_shl((Word32) in[j], *q); - move32(); - } - - nw = ip[0]; - move16(); - if (sub(n, shl(nw, 2)) > 0) - { - nw = shr(n, 2); - } - - nc = ip[1]; - move16(); - if (n > nc) - { - nc = n; - move16(); - } - - IF (isgn < 0) - { - xr = a[n - 1]; - move32(); - FOR (j = n - 2; j >= 2; j -= 2) - { - a[j + 1] = L_sub(a[j], a[j - 1]); - move32(); - a[j] = L_add(a[j], a[j - 1]); - move32(); - } - a[1] = L_sub(a[0], xr); - move32(); - a[0] = L_add(a[0], xr); - move32(); - - IF (n > 4) - { - rftbsub_fx(n, a, nc, w + nw); - bitrv2_SR_fx(n, ip + 2, a); - cftbsub_fx(n, a, w); - } - ELSE IF (n == 4) - { - cftfsub_fx(n, a, w); - } - } - - IF (isgn >= 0) - { - a[0] = L_shr(a[0], 1); - move32(); - } - - dctsub_fx(n, a, nc, w + nw); - - IF (isgn >= 0) - { - IF (n > 4) - { - bitrv2_SR_fx(n, ip + 2, a); - cftfsub_fx(n, a, w); - rftfsub_fx(n, a, nc, w + nw); - } - ELSE IF (n == 4) - { - cftfsub_fx(n, a, w); - } - xr = L_sub(a[0], a[1]); - a[0] = L_add(a[0], a[1]); - move32(); - FOR (j = 2; j < n; j += 2) - { - a[j - 1] = L_sub(a[j], a[j + 1]); - move32(); - a[j] = L_add(a[j], a[j + 1]); - move32(); - } - a[n - 1] = xr; - move32(); - - FOR (j = 0; j < n; j ++) - { - a[j] = L_shr(a[j], 5); - move32(); - } - } -} - - -/*-----------------------------------------------------------------* -* fft5_shift4() -* 5-point FFT with 4-point circular shift -*-----------------------------------------------------------------*/ - -static void fft5_shift4_16fx( - Word16 n1, /* i : length of data */ - Word16 *zRe, /* i/o : real part of input and output data */ - Word16 *zIm, /* i/o : imaginary part of input and output data */ - const Word16 *Idx /* i : pointer of the address table */ -) -{ - Word16 T1, To, T8, Tt, T9, Ts, Te, Tp, Th, Tn,T2, T3, T4, T5, T6, T7; - Word16 i0,i1,i2,i3,i4; - Word32 L_tmp; - - i0 = Idx[0]; - move16(); - i1 = Idx[n1]; - move16(); - i2 = Idx[n1*2]; - move16(); - i3 = Idx[n1*3]; - move16(); - i4 = Idx[n1*4]; - move16(); - - T1 = zRe[i0]; - move16(); - To = zIm[i0]; - move16(); - - T2 = zRe[i1]; - move16(); - T3 = zRe[i4]; - move16(); - T4 = add(T2,T3); - T5 = zRe[i2]; - move16(); - T6 = zRe[i3]; - move16(); - T7 = add(T5,T6); - T8 = add(T4,T7); - Tt = sub(T5,T6); - /* T9 = KP559016994 * (T4 - T7); */ - L_tmp = Mult_32_16(KP559016994_16FX,sub(T4,T7)); - T9 = round_fx(L_tmp); - Ts = sub(T2,T3); - - T2 = zIm[i1]; - move16(); - T3 = zIm[i4]; - move16(); - T4 = add(T2,T3); - T5 = zIm[i2]; - move16(); - T6 = zIm[i3]; - move16(); - T7 = add(T5,T6); - Te = sub(T2,T3); - Tp = add(T4,T7); - Th = sub(T5,T6); - /* Tn = KP559016994 * (T4 - T7); */ - L_tmp = Mult_32_16(KP559016994_16FX,sub(T4,T7)); - Tn = round_fx(L_tmp); - - zRe[i0] = add(T1,T8); - move16(); - zIm[i0] = add(To,Tp); - move16(); - - /* T2 = KP951056516*Te + KP587785252*Th; */ - L_tmp = Mult_32_16(KP951056516_16FX,Te); - L_tmp = Madd_32_16(L_tmp,KP587785252_16FX,Th); - T2 = round_fx(L_tmp); - - /*T3 = KP951056516*Th - KP587785252*Te; */ - L_tmp = Mult_32_16(KP951056516_16FX,Th); - L_tmp = Msub_32_16(L_tmp,KP587785252_16FX,Te); - T3 = round_fx(L_tmp); - - T6 = sub(T1,shr(T8,2)); - T4 = add(T9,T6); - T5 = sub(T6,T9); - zRe[i1] = sub(T4,T2); - move16(); - zRe[i2] = add(T5,T3); - move16(); - zRe[i4] = add(T4,T2); - move16(); - zRe[i3] = sub(T5,T3); - move16(); - - /* T2 = KP951056516 * Ts + KP587785252 * Tt; */ - L_tmp = Mult_32_16(KP951056516_16FX,Ts); - L_tmp = Madd_32_16(L_tmp,KP587785252_16FX,Tt); - T2 = round_fx(L_tmp); - - /* T3 = KP951056516 * Tt - KP587785252 * Ts; */ - L_tmp = Mult_32_16(KP951056516_16FX,Tt); - L_tmp = Msub_32_16(L_tmp,KP587785252_16FX,Ts); - T3 = round_fx(L_tmp); - - T6 = sub(To,shr(Tp,2)); - T4 = add(Tn,T6); - T5 = sub(T6,Tn); - zIm[i4] = sub(T4,T2); - move16(); - zIm[i2] = sub(T5,T3); - move16(); - zIm[i1] = add(T2,T4); - move16(); - zIm[i3] = add(T3,T5); - move16(); - - return; -} - -/*-----------------------------------------------------------------* -* fft5_32() -* 5-point FFT called for 32 times -*-----------------------------------------------------------------*/ -static void fft5_32_16fx( - Word16 *zRe, /* i/o : real part of input and output data */ - Word16 *zIm, /* i/o : imaginary part of input and output data */ - const Word16 *Idx /* i : pointer of the address table */ -) -{ - Word16 T1, To, T8, Tt, T9, Ts, Te, Tp, Th, Tn,T2, T3, T4, T5, T6, T7; - Word16 i0,i1,i2,i3,i4; - Word32 L_tmp; - - i0 = Idx[0]; - move16(); - i1 = Idx[32]; - move16(); - i2 = Idx[64]; - move16(); - i3 = Idx[96]; - move16(); - i4 = Idx[128]; - move16(); - - T1 = zRe[i0]; - move16(); - To = zIm[i0]; - move16(); - - T2 = zRe[i1]; - move16(); - T3 = zRe[i4]; - move16(); - T4 = add(T2, T3); - T5 = zRe[i2]; - move16(); - T6 = zRe[i3]; - move16(); - T7 = add(T5,T6); - T8 = add(T4,T7); - Tt = sub(T5,T6); - /* T9 = KP559016994 * (T4 - T7); */ - L_tmp = Mult_32_16(KP559016994_16FX,sub(T4,T7)); - T9 = round_fx(L_tmp); - Ts = sub(T2,T3); - - T2 = zIm[i1]; - move16(); - T3 = zIm[i4]; - move16(); - T4 = add(T2,T3); - T5 = zIm[i2]; - move16(); - T6 = zIm[i3]; - move16(); - T7 = add(T5,T6); - Te = sub(T2,T3); - Tp = add(T4,T7); - Th = sub(T5,T6); - L_tmp = Mult_32_16(KP559016994_16FX,sub(T4,T7)); - Tn = round_fx(L_tmp); - - - - zRe[i0] = add(T1,T8); - move16(); - zIm[i0] = add(To,Tp); - move32(); - - - - /*T2 = KP951056516*Te + KP587785252*Th; */ - L_tmp = Mult_32_16(KP951056516_16FX,Te); - L_tmp = Madd_32_16(L_tmp,KP587785252_16FX,Th); - T2 = round_fx(L_tmp); - - /*T3 = KP951056516*Th - KP587785252*Te; */ - L_tmp = Mult_32_16(KP951056516_16FX,Th); - L_tmp = Msub_32_16(L_tmp,KP587785252_16FX,Te); - T3 = round_fx(L_tmp); - - - - T6 = sub(T1,shr(T8,2)); - T4 = add(T9,T6); - T5 = sub(T6,T9); - zRe[i3] = sub(T4,T2); - move32(); - zRe[i1] = add(T5,T3); - move32(); - zRe[i2] = add(T4,T2); - move32(); - zRe[i4] = sub(T5,T3); - move32(); - - /* T2 = KP951056516 * Ts + KP587785252 * Tt; */ - L_tmp = Mult_32_16(KP951056516_16FX,Ts); - L_tmp = Madd_32_16(L_tmp,KP587785252_16FX,Tt); - T2 = round_fx(L_tmp); - - /* T3 = KP951056516 * Tt - KP587785252 * Ts; */ - L_tmp = Mult_32_16(KP951056516_16FX,Tt); - L_tmp = Msub_32_16(L_tmp,KP587785252_16FX,Ts); - T3 = round_fx(L_tmp); - - T6 = sub(To,shr(Tp,2)); - T4 = add(Tn,T6); - T5 = sub(T6,Tn); - zIm[i2] = sub(T4,T2); - move16(); - zIm[i1] = sub(T5,T3); - move16(); - zIm[i3] = add(T2,T4); - move16(); - zIm[i4] = add(T3,T5); - move16(); - - - return; -} - -/*-----------------------------------------------------------------* -* fft64() -* 64-point FFT -*-----------------------------------------------------------------*/ -static void fft64_16fx( - Word16 *x, /* i/o : real part of input and output data */ - Word16 *y, /* i/o : imaginary part of input and output data */ - const Word16 *Idx /* i : pointer of the address table */ -) -{ - Word16 i,id,jd; - Word16 z[128]; - move16();/*penalty for 1 ptr init */ - FOR ( i=0; i<64; i++ ) - { - id = Idx[i]; - move16(); - z[2*i] = x[id]; - move16(); - z[2*i+1] = y[id]; - move16(); - } - - cdftForw_16fx(128,z,Ip_fft64_16fx,w_fft64_16fx); - - move16();/*penalty for 1 ptr init */ - FOR( i=0; i<64 ; i++) - { - jd = Odx_fft64_16fx[i]; - move16(); - id = Idx[jd]; - move16(); - x[id]=z[2*i]; - move16(); - y[id]=z[2*i+1]; - move16(); - } - - return; -} - - -/*-----------------------------------------------------------------* -* fft32_5() -* 32-point FFT called for 5 times -*-----------------------------------------------------------------*/ -static void fft32_5_16fx( - Word16 *x, /* i/o : real part of input and output data */ - Word16 *y, /* i/o : imaginary part of input and output data */ - const Word16 *Idx /* i : pointer of the address table */ -) -{ - Word16 i,id,jd; - Word16 z[64]; - - move16();/*penalty for 1 ptr init */ - FOR( i=0; i<32; i++ ) - { - id = Idx[i]; - move16(); - z[2*i] = x[id]; - move16(); - z[2*i+1] = y[id]; - move16(); - } - - cdftForw_16fx(64,z,Ip_fft32_16fx,w_fft32_16fx); - - move16();/*penalty for 1 ptr init */ - FOR( i=0; i<32; i++ ) - { - jd = Odx_fft32_5[i]; - move16(); - id = Idx[jd]; - move16(); - x[id]=z[2*i]; - move16(); - y[id]=z[2*i+1]; - move16(); - } - - return; -} - - - -/*-----------------------------------------------------------------* -* DoRTFT160() -* a low complexity 2-dimensional DFT of 160 points -*-----------------------------------------------------------------*/ -void DoRTFT160_16fx( - Word16 x[], /* i/o : real part of input and output data */ - Word16 y[] /* i/o : imaginary part of input and output data */ -) -{ - Word16 j; - - /* Applying 32-point FFT for 5 times based on the address table Idx_dortft160 */ - FOR(j=0; j<5; j++) - { - fft32_5_16fx(x,y,Idx_dortft160+shl(j,5)/*32*j*/); - } - - /* Applying 5-point FFT for 32 times based on the address table Idx_dortft160 */ - FOR(j=0; j<32; j++) - { - fft5_32_16fx(x,y,Idx_dortft160+j); - } - - return; -} - -/*-----------------------------------------------------------------* -* DoRTFT320() -* a low complexity 2-dimensional DFT of 320 points -*-----------------------------------------------------------------*/ -void DoRTFT320_16fx( - Word16 *x, /* i/o : real part of input and output data */ - Word16 *y /* i/o : imaginary part of input and output data */ -) -{ - Word16 j; - - /* Applying 64-point FFT for 5 times based on the address table Idx_dortft160 */ - FOR(j=0; j<5; j++) - { - fft64_16fx(x,y,Idx_dortft320_16fx+shl(j,6)/*64*j*/); - } - - /* Applying 5-point FFT for 64 times based on the address table Idx_dortft160 */ - FOR(j=0; j<64; j++) - { - fft5_shift4_16fx(64,x,y,Idx_dortft320_16fx+j); - } - - return; -} - -/*-----------------------------------------------------------------* -* DoRTFT128() -* FFT with 128 points -*-----------------------------------------------------------------*/ -void DoRTFT128_16fx( - Word16 *x, /* i/o : real part of input and output data Q(Qx+Q_edct)*/ - Word16 *y /* i/o : imaginary part of input and output data Q(Qx+Q_edct)*/ -) -{ - - Word16 i; - Word16 z[256]; - - move16();/*penalty for 1 ptr init */ - FOR ( i=0; i<128; i++ ) - { - z[2*i] = x[i]; - move16(); - z[2*i+1] = y[i]; - move16(); - } - - cdftForw_16fx(256,z,Ip_fft128_16fx,w_fft128_16fx); - - x[0]=z[0]; - move16(); - y[0]=z[1]; - move16(); - move16();/*penalty for 1 ptr init */ - move16();/*penalty for 1 ptr init */ - FOR( i=1; i<128 ; i++) - { - x[128-i]=z[2*i]; - move16(); - y[128-i]=z[2*i+1]; - move16(); - } - - return; -} -/*-----------------------------------------------------------------* -* cdftForw() -* Main fuction of Complex Discrete Fourier Transform -*-----------------------------------------------------------------*/ -static void cdftForw_16fx( - Word16 n, /* i : data length of real and imag */ - Word16 *a, /* i/o : input/output data Q(Qx+Q_edct)*/ - const Word16 *ip, /* i : work area for bit reversal */ - const Word32 *w /* i : cos/sin table Q30*/ -) -{ - /* bit reversal */ - bitrv2_SR_16fx(n, ip + 2, a); - - /* Do FFT */ - cftfsub_16fx(n, a, w); -} - -/*-----------------------------------------------------------------* -* bitrv2_SR() -* Bit reversal -*-----------------------------------------------------------------*/ -static void bitrv2_SR_16fx( - Word16 n, /* i : data length of real and imag */ - const Word16 *ip, /* i/o : work area for bit reversal */ - Word16 *a /* i/o : input/output data Q(Qx+Q_edct)*/ -) -{ - Word16 j, j1, k, k1, m, m2; - Word16 l; - Word16 xr, xi, yr, yi; - - l = n; - move16(); - m = 1; - move16(); - - WHILE (sub(shl(m,3),l) < 0) - { - l = shr(l,1); - m = shl(m,1); - } - - m2 = shl(m,1); - IF (sub(shl(m, 3),l) == 0) - { - FOR (k = 0; k < m; k++) - { - FOR (j = 0; j < k; j++) - { - j1 = add(shl(j,1),ip[k]); - k1 = add(shl(k,1),ip[j]); - xr = a[j1]; - move16(); - xi = a[j1 + 1]; - move16(); - yr = a[k1]; - move16(); - yi = a[k1 + 1]; - move16(); - a[j1] = yr; - move16(); - a[j1 + 1] = yi; - move16(); - a[k1] = xr; - move16(); - a[k1 + 1] = xi; - move16(); - j1 = add(j1,m2); - k1 = add(k1,shl(m2,1)); - xr = a[j1]; - move16(); - xi = a[j1 + 1]; - move16(); - yr = a[k1]; - move16(); - yi = a[k1 + 1]; - move16(); - a[j1] = yr; - move16(); - a[j1 + 1] = yi; - move16(); - a[k1] = xr; - move16(); - a[k1 + 1] = xi; - move16(); - j1 = add(j1,m2); - k1 = sub(k1,m2); - xr = a[j1]; - move16(); - xi = a[j1 + 1]; - move16(); - xi = a[j1 + 1]; - move16(); - yr = a[k1]; - move16(); - yi = a[k1 + 1]; - move16(); - a[j1] = yr; - move16(); - a[j1 + 1] = yi; - move16(); - a[k1] = xr; - move16(); - a[k1 + 1] = xi; - move16(); - j1 = add(j1,m2); - k1 = add(k1,shl(m2,1)); - xr = a[j1]; - move16(); - xi = a[j1 + 1]; - move16(); - yr = a[k1]; - move16(); - yi = a[k1 + 1]; - move16(); - a[j1] = yr; - move16(); - a[j1 + 1] = yi; - move16(); - a[k1] = xr; - move16(); - a[k1 + 1] = xi; - move16(); - } - - j1 = add(add(shl(k,1),m2),ip[k]); - k1 = add(j1,m2); - xr = a[j1]; - move16(); - xi = a[j1 + 1]; - move16(); - yr = a[k1]; - move16(); - yi = a[k1 + 1]; - move16(); - a[j1] = yr; - move16(); - a[j1 + 1] = yi; - move16(); - a[k1] = xr; - move16(); - a[k1 + 1] = xi; - move16(); - } - } - ELSE - { - FOR (k = 1; k < m; k++) - { - FOR (j = 0; j < k; j++) - { - j1 = add(shl(j,1),ip[k]); - k1 = add(shl(k,1),ip[j]); - xr = a[j1]; - move16(); - xi = a[j1 + 1]; - move16(); - yr = a[k1]; - move16(); - yi = a[k1 + 1]; - move16(); - a[j1] = yr; - move16(); - a[j1 + 1] = yi; - move16(); - a[k1] = xr; - move16(); - a[k1 + 1] = xi; - move16(); - j1 = add(j1,m2); - k1 = add(k1,m2); - xr = a[j1]; - move16(); - xi = a[j1 + 1]; - move16(); - yr = a[k1]; - move16(); - yi = a[k1 + 1]; - move16(); - a[j1] = yr; - move16(); - a[j1 + 1] = yi; - move16(); - a[k1] = xr; - move16(); - a[k1 + 1] = xi; - move16(); - } - } - } - - return; -} - -/*-----------------------------------------------------------------* -* cftfsub() -* Complex Discrete Fourier Transform -*-----------------------------------------------------------------*/ -static void cftfsub_16fx( - Word16 n, /* i : data length of real and imag */ - Word16 *a, /* i/o : input/output data Q(Qx+Q_edct)*/ - const Word32 *w /* i : cos/sin table Q30*/ -) -{ - Word16 j, j1, j2, j3, l; - Word16 x0r, x0i, x1r, x1i, x2r, x2i, x3r, x3i; - - l = 2; - move16(); - IF (sub(n,8) > 0) - { - cft1st_16fx(n, a, w); - l = 8; - move16(); - WHILE (sub(shl(l, 2),n) < 0) - { - cftmdl_16fx(n, l, a, w); - l = shl(l,2); - } - } - - IF (sub(shl(l,2),n) == 0) - { - FOR (j = 0; j < l; j += 2) - { - j1 = add(j,l); - j2 = add(j1,l); - j3 = add(j2,l); - x0r = add(a[j],a[j1]); - x0i = add(a[j + 1],a[j1 + 1]); - x1r = sub(a[j],a[j1]); - x1i = sub(a[j + 1],a[j1 + 1]); - x2r = add(a[j2],a[j3]); - x2i = add(a[j2 + 1],a[j3 + 1]); - x3r = sub(a[j2],a[j3]); - x3i = sub(a[j2 + 1],a[j3 + 1]); - a[j] = add(x0r,x2r); - move16(); - a[j + 1] = add(x0i,x2i); - move16(); - a[j2] = sub(x0r,x2r); - move16(); - a[j2 + 1] = sub(x0i,x2i); - move16(); - a[j1] = sub(x1r,x3i); - move16(); - a[j1 + 1] = add(x1i,x3r); - move16(); - a[j3] = add(x1r,x3i); - move16(); - a[j3 + 1] = sub(x1i,x3r); - move16(); - } - } - ELSE - { - FOR (j = 0; j < l; j += 2) - { - j1 = add(j,l); - x0r = sub(a[j],a[j1]); - x0i = sub(a[j + 1],a[j1 + 1]); - a[j] = add(a[j],a[j1]); - move16(); - a[j + 1] = add(a[j + 1],a[j1 + 1]); - move16(); - a[j1] = x0r; - move16(); - a[j1 + 1] = x0i; - move16(); - } - } - return; -} - -/*-----------------------------------------------------------------* -* cft1st() -* Subfunction of Complex Discrete Fourier Transform -*-----------------------------------------------------------------*/ -static void cft1st_16fx( - Word16 n, /* i : data length of real and imag */ - Word16 *a, /* i/o : input/output data Q(Qx+Q_edct)*/ - const Word32 *w /* i : cos/sin table Q30*/ -) -{ - Word16 j, k1, k2; - Word32 wk1r, wk1i, wk2r, wk2i, wk3r, wk3i; - Word16 x0r, x0i, x1r, x1i, x2r, x2i, x3r, x3i; - Word16 tmp; - Word32 L_tmp; - - x0r = add(a[0],a[2]); - x0i = add(a[1],a[3]); - x1r = sub(a[0],a[2]); - x1i = sub(a[1],a[3]); - x2r = add(a[4],a[6]); - x2i = add(a[5],a[7]); - x3r = sub(a[4],a[6]); - x3i = sub(a[5],a[7]); - a[0] = add(x0r,x2r); - move16(); - a[1] = add(x0i,x2i); - move16(); - a[4] = sub(x0r,x2r); - move16(); - a[5] = sub(x0i,x2i); - move16(); - a[2] = sub(x1r,x3i); - move16(); - a[3] = add(x1i,x3r); - move16(); - a[6] = add(x1r,x3i); - move16(); - a[7] = sub(x1i,x3r); - move16(); - - wk1r = w[2]; - move32(); - - x0r = add(a[8],a[10]); - x0i = add(a[9],a[11]); - x1r = sub(a[8],a[10]); - x1i = sub(a[9],a[11]); - x2r = add(a[12],a[14]); - x2i = add(a[13],a[15]); - x3r = sub(a[12],a[14]); - x3i = sub(a[13],a[15]); - a[8] = add(x0r,x2r); - move16(); - a[9] = add(x0i,x2i); - move16(); - a[12] = sub(x2i,x0i); - move16(); - a[13] = sub(x0r,x2r); - move16(); - - x0r = sub(x1r,x3i); - x0i = add(x1i,x3r); - tmp = sub(x0r,x0i); - L_tmp = Mult_32_16(wk1r,tmp); /*Q(15+Qx+Q_edct) */ - - a[10] = round_fx(L_shl(L_tmp,1)); /*Q(Qx+Q_edct) */ - - tmp = add(x0r,x0i); - L_tmp = Mult_32_16(wk1r,tmp); /*Q(15+Qx+Q_edct) */ - a[11] = round_fx(L_shl(L_tmp,1)); /* Q(Qx+Q_edct) */ - - x0r = add(x3i,x1r); - x0i = sub(x3r,x1i); - tmp = sub(x0i,x0r); - L_tmp = Mult_32_16(wk1r,tmp); /*Q(15+Qx+Q_edct) */ - a[14] = round_fx(L_shl(L_tmp,1)); /*Q(Qx+Q_edct) */ - - tmp = add(x0i,x0r); - L_tmp = Mult_32_16(wk1r,tmp); /*Q(15+Qx+Q_edct) */ - a[15] = round_fx(L_shl(L_tmp,1)); /*Q(Qx+Q_edct) */ - - k1 = 0; - move16(); - - FOR (j = 16; j < n; j += 16) - { - k1 = add(k1,2); - k2 = shl(k1,1); - - wk2r = L_add(0,w[k1]); - wk2i = L_add(0,w[k1 + 1]); - wk1r = L_add(0,w[k2]); - wk1i = L_add(0,w[k2 + 1]); - - L_tmp = L_shl(Mult_32_32(wk2i,wk1i),1);/*Q29 */ - wk3r = L_sub(wk1r,L_shl(L_tmp,1));/*Q30 */ - - L_tmp = L_shl(Mult_32_32(wk2i,wk1r),1);/*Q29 */ - wk3i = L_sub(L_shl(L_tmp,1),wk1i);/*Q30 */ - - x0r = add(a[j],a[j + 2]); - x0i = add(a[j + 1],a[j + 3]); - x1r = sub(a[j],a[j + 2]); - x1i = sub(a[j + 1],a[j + 3]); - x2r = add(a[j + 4],a[j + 6]); - x2i = add(a[j + 5],a[j + 7]); - x3r = sub(a[j + 4],a[j + 6]); - x3i = sub(a[j + 5],a[j + 7]); - a[j] = add(x0r,x2r); - move16(); - a[j + 1] = add(x0i,x2i); - move16(); - - x0r = sub(x0r,x2r); - x0i = sub(x0i,x2i); - L_tmp = Mult_32_16(wk2r,x0r);/*Q(15+Qx+Q_edct) */ - L_tmp = Msub_32_16(L_tmp,wk2i,x0i); /*Q(15+Qx+Q_edct) */ - a[j + 4] = round_fx(L_shl(L_tmp,1)); /*Q(Qx+Q_edct) */ - - L_tmp = Mult_32_16(wk2r,x0i);/*Q(15+Qx+Q_edct) */ - L_tmp = Madd_32_16(L_tmp,wk2i,x0r); /*Q(15+Qx+Q_edct) */ - a[j + 5] = round_fx(L_shl(L_tmp,1)); /*Q(Qx+Q_edct) */ - - x0r = sub(x1r,x3i); - x0i = add(x1i,x3r); - L_tmp = Mult_32_16(wk1r,x0r);/*Q(15+Qx+Q_edct) */ - L_tmp = Msub_32_16(L_tmp,wk1i,x0i); /*Q(15+Qx+Q_edct) */ - a[j + 2] = round_fx(L_shl(L_tmp,1)); /*Q(Qx+Q_edct) */ - - L_tmp = Mult_32_16(wk1r,x0i);/*Q(15+Qx+Q_edct) */ - L_tmp = Madd_32_16(L_tmp,wk1i,x0r); /*Q(15+Qx+Q_edct) */ - a[j + 3] = round_fx(L_shl(L_tmp,1)); /*Q(Qx+Q_edct) */ - - x0r = add(x1r,x3i); - x0i = sub(x1i,x3r); - L_tmp = Mult_32_16(wk3r,x0r); /*Q(15+Qx+Q_edct) */ - L_tmp = Msub_32_16(L_tmp,wk3i,x0i); /*Q(15+Qx+Q_edct) */ - a[j + 6] = round_fx(L_shl(L_tmp,1)); /*Q(Qx+Q_edct) */ - - L_tmp = Mult_32_16(wk3r,x0i); /*Q(15+Qx+Q_edct) */ - L_tmp = Madd_32_16(L_tmp,wk3i,x0r); /*Q(15+Qx+Q_edct) */ - a[j + 7] = round_fx(L_shl(L_tmp,1)); /*Q(Qx+Q_edct) */ - - wk1r = L_add(0,w[k2 + 2]); - wk1i = L_add(0,w[k2 + 3]); - L_tmp = L_shl(Mult_32_32(wk2r,wk1i),1);/*Q29 */ - wk3r = L_sub(wk1r,L_shl(L_tmp,1)); /*Q30 */ - - L_tmp = L_shl(Mult_32_32(wk2r,wk1r),1);/*Q29 */ - wk3i = L_sub(L_shl(L_tmp,1),wk1i); /*Q30 */ - - x0r = add(a[j + 8],a[j + 10]); - x0i = add(a[j + 9],a[j + 11]); - x1r = sub(a[j + 8],a[j + 10]); - x1i = sub(a[j + 9],a[j + 11]); - x2r = add(a[j + 12],a[j + 14]); - x2i = add(a[j + 13],a[j + 15]); - x3r = sub(a[j + 12],a[j + 14]); - x3i = sub(a[j + 13],a[j + 15]); - a[j + 8] = add(x0r,x2r); - move16(); - a[j + 9] = add(x0i,x2i); - move16(); - - x0r = sub(x0r,x2r); - x0i = sub(x0i,x2i); - tmp = negate(x0r); - L_tmp = Mult_32_16(wk2i,tmp);/*Q(15+Qx+Q_edct) */ - L_tmp = Msub_32_16(L_tmp,wk2r,x0i); /*Q(15+Qx+Q_edct) */ - a[j + 12] = round_fx(L_shl(L_tmp,1)); /*Q(Qx+Q_edct) */ - - tmp = negate(x0i); - L_tmp = Mult_32_16(wk2i,tmp);/*Q(15+Qx+Q_edct) */ - L_tmp = Madd_32_16(L_tmp,wk2r,x0r); /*Q(15+Qx+Q_edct) */ - a[j + 13] = round_fx(L_shl(L_tmp,1)); /*Q(Qx+Q_edct) */ - - x0r = sub(x1r,x3i); - x0i = add(x1i,x3r); - L_tmp = Mult_32_16(wk1r,x0r);/*Q(15+Qx+Q_edct) */ - L_tmp = Msub_32_16(L_tmp,wk1i,x0i); /*Q(15+Qx+Q_edct) */ - a[j + 10] = round_fx(L_shl(L_tmp,1)); /*Q(Qx+Q_edct) */ - - L_tmp = Mult_32_16(wk1r,x0i);/*Q(15+Qx+Q_edct) */ - L_tmp = Madd_32_16(L_tmp,wk1i,x0r); /*Q(15+Qx+Q_edct) */ - a[j + 11] = round_fx(L_shl(L_tmp,1)); /*Q(Qx+Q_edct) */ - - x0r = add(x1r,x3i); - x0i = sub(x1i,x3r); - - L_tmp = Mult_32_16(wk3r,x0r); /*Q(15+Qx+Q_edct) */ - L_tmp = Msub_32_16(L_tmp,wk3i,x0i); /*Q(15+Qx+Q_edct) */ - a[j + 14] = round_fx(L_shl(L_tmp,1)); /*Q(Qx+Q_edct) */ - - L_tmp = Mult_32_16(wk3r,x0i); /*Q(15+Qx+Q_edct) */ - L_tmp = Madd_32_16(L_tmp,wk3i,x0r); /*Q(15+Qx+Q_edct) */ - a[j + 15] = round_fx(L_shl(L_tmp,1)); /*Q(Qx+Q_edct) */ - } - - return; -} - -/*-----------------------------------------------------------------* -* cftmdl() -* Subfunction of Complex Discrete Fourier Transform -*-----------------------------------------------------------------*/ -static void cftmdl_16fx( - Word16 n, /* i : data length of real and imag */ - Word16 l, /* i : initial shift for processing */ - Word16 *a, /* i/o : input/output data Q(Qx+Q_edct)*/ - const Word32 *w /* i : cos/sin table Q30*/ -) -{ - Word16 j, j1, j2, j3, k, k1, k2, m, m2; - Word32 wk1r, wk1i, wk2r, wk2i, wk3r, wk3i; - Word16 x0r, x0i, x1r, x1i, x2r, x2i, x3r, x3i; - Word16 tmp, tmp2; - Word32 L_tmp; - Word32 L_x0r, L_x0i; - - m = shl(l, 2); - move16(); - FOR (j = 0; j < l; j += 2) - { - j1 = add(j,l); - j2 = add(j1,l); - j3 = add(j2,l); - x0r = add(a[j],a[j1]); - x0i = add(a[j + 1],a[j1 + 1]); - x1r = sub(a[j],a[j1]); - x1i = sub(a[j + 1],a[j1 + 1]); - x2r = add(a[j2],a[j3]); - x2i = add(a[j2 + 1],a[j3 + 1]); - x3r = sub(a[j2],a[j3]); - x3i = sub(a[j2 + 1],a[j3 + 1]); - a[j] = add(x0r,x2r); - move16(); - a[j + 1] = add(x0i,x2i); - move16(); - a[j2] = sub(x0r,x2r); - move16(); - a[j2 + 1] = sub(x0i,x2i); - move16(); - a[j1] = sub(x1r,x3i); - move16(); - a[j1 + 1] = add(x1i,x3r); - move16(); - a[j3] = add(x1r,x3i); - move16(); - a[j3 + 1] = sub(x1i,x3r); - move16(); - } - - wk1r = w[2]; - move32(); - tmp2 = add(l,m); - FOR (j = m; j < tmp2; j += 2) - { - j1 = add(j,l); - j2 = add(j1,l); - j3 = add(j2,l); - x0r = add(a[j],a[j1]); - x0i = add(a[j + 1],a[j1 + 1]); - x1r = sub(a[j],a[j1]); - x1i = sub(a[j + 1],a[j1 + 1]); - x2r = add(a[j2],a[j3]); - x2i = add(a[j2 + 1],a[j3 + 1]); - x3r = sub(a[j2],a[j3]); - x3i = sub(a[j2 + 1],a[j3 + 1]); - a[j] = add(x0r,x2r); - move16(); - a[j + 1] = add(x0i,x2i); - move16(); - a[j2] = sub(x2i,x0i); - move16(); - a[j2 + 1] = sub(x0r,x2r); - move16(); - - x0r = sub(x1r,x3i); - x0i = add(x1i,x3r); - tmp = sub(x0r,x0i); - L_tmp = Mult_32_16(wk1r,tmp);/*Q(15+Qx+Q_edct) */ - a[j1] = round_fx(L_shl(L_tmp,1)); /*Q(Qx+Q_edct) */ - - tmp = add(x0r,x0i); - L_tmp = Mult_32_16(wk1r,tmp); /*Q(15+Qx+Q_edct) */ - a[j1 + 1] = round_fx(L_shl(L_tmp,1)); /*Q(Qx+Q_edct) */ - - x0r = add(x3i,x1r); - x0i = sub(x3r,x1i); - tmp = sub(x0i,x0r); - L_tmp = Mult_32_16(wk1r,tmp);/*Q(15+Qx+Q_edct) */ - a[j3] = round_fx(L_shl(L_tmp,1)); /*Q(Qx+Q_edct) */ - - tmp = add(x0i,x0r); - L_tmp = Mult_32_16(wk1r,tmp); /*Q(15+Qx+Q_edct) */ - a[j3 + 1] = round_fx(L_shl(L_tmp,1)); /*Q(Qx+Q_edct) */ - } - - k1 = 0; - move16(); - m2 = shl(m,1); - FOR (k = m2; k < n; k += m2) - { - k1 = add(k1,2); - k2 = shl(k1,1); - wk2r = L_add(0,w[k1]); - wk2i = L_add(0,w[k1 + 1]); - wk1r = L_add(0,w[k2]); - wk1i = L_add(0,w[k2 + 1]); - L_tmp = L_shl(Mult_32_32(wk2i,wk1i),1);/*Q29 */ - wk3r = L_sub(wk1r,L_shl(L_tmp,1));/*Q30 */ - - L_tmp = L_shl(Mult_32_32(wk2i,wk1r),1);/*Q29 */ - wk3i = L_sub(L_shl(L_tmp,1),wk1i);/*Q30 */ - - tmp2 = add(l,k); - FOR (j = k; j < tmp2; j += 2) - { - j1 = add(j,l); - j2 = add(j1,l); - j3 = add(j2,l); - x0r = add(a[j],a[j1]); - x0i = add(a[j + 1],a[j1 + 1]); - x1r = sub(a[j],a[j1]); - x1i = sub(a[j + 1],a[j1 + 1]); - x2r = add(a[j2],a[j3]); - x2i = add(a[j2 + 1],a[j3 + 1]); - x3r = sub(a[j2],a[j3]); - x3i = sub(a[j2 + 1],a[j3 + 1]); - a[j] = add(x0r,x2r); - move16(); - a[j + 1] = add(x0i,x2i); - move16(); - - x0r = sub(x0r,x2r); - x0i = sub(x0i,x2i); - - L_tmp = Mult_32_16(wk2r,x0r); /*Q(15+Qx+Q_edct) */ - L_tmp = Msub_32_16(L_tmp,wk2i,x0i); /*Q(15+Qx+Q_edct) */ - a[j2] = round_fx(L_shl(L_tmp,1)); /*Q(Qx+Q_edct) */ - - L_tmp = Mult_32_16(wk2r,x0i); /*Q(15+Qx+Q_edct) */ - L_tmp = Madd_32_16(L_tmp,wk2i,x0r); /*Q(15+Qx+Q_edct) */ - a[j2 + 1] = round_fx(L_shl(L_tmp,1)); /*Q(Qx+Q_edct) */ - - x0r = sub(x1r,x3i); - x0i = add(x1i,x3r); - - L_tmp = Mult_32_16(wk1r,x0r); /*Q(15+Qx+Q_edct) */ - L_tmp = Msub_32_16(L_tmp,wk1i,x0i); /*Q(15+Qx+Q_edct) */ - a[j1] = round_fx(L_shl(L_tmp,1)); /*Q(Qx+Q_edct) */ - - L_tmp = Mult_32_16(wk1r,x0i); /*Q(15+Qx+Q_edct) */ - L_tmp = Madd_32_16(L_tmp,wk1i,x0r); /*Q(15+Qx+Q_edct) */ - a[j1 + 1] = round_fx(L_shl(L_tmp,1)); /*Q(Qx+Q_edct) */ - - L_x0r = L_add((Word32) x1r, (Word32) x3i); - L_x0i = L_sub((Word32) x1i, (Word32) x3r); - x0r = extract_l(L_x0r); - x0i = extract_l(L_x0i); - L_tmp = Mult_32_16(wk3r,x0r); /*Q(15+Qx+Q_edct) */ - L_tmp = Msub_32_16(L_tmp,wk3i,x0i); /*Q(15+Qx+Q_edct) */ - a[j3] = round_fx(L_shl(L_tmp,1)); /*Q(Qx+Q_edct) */ - - L_tmp = Mult_32_16(wk3r,x0i); /*Q(15+Qx+Q_edct) */ - L_tmp = Madd_32_16(L_tmp,wk3i,x0r); /*Q(15+Qx+Q_edct) */ - a[j3 + 1] = round_fx(L_shl(L_tmp,1)); /*Q(Qx+Q_edct) */ - } - - wk1r = w[k2 + 2]; - move32(); - wk1i = w[k2 + 3]; - move32(); - L_tmp = L_shl(Mult_32_32(wk2r,wk1i),1);/*Q29 */ - wk3r = L_sub(wk1r,L_shl(L_tmp,1)); /*Q30 */ - - L_tmp = L_shl(Mult_32_32(wk2r,wk1r),1);/*Q29 */ - wk3i = L_sub(L_shl(L_tmp,1),wk1i); /*Q30 */ - - tmp2 = add(l,add(k,m)); - FOR (j = add(k,m); j < tmp2; j += 2) - { - j1 = add(j,l); - j2 = add(j1,l); - j3 = add(j2,l); - x0r = add(a[j],a[j1]); - x0i = add(a[j + 1],a[j1 + 1]); - x1r = sub(a[j],a[j1]); - x1i = sub(a[j + 1],a[j1 + 1]); - x2r = add(a[j2],a[j3]); - x2i = add(a[j2 + 1],a[j3 + 1]); - x3r = sub(a[j2],a[j3]); - x3i = sub(a[j2 + 1],a[j3 + 1]); - a[j] = add(x0r,x2r); - move16(); - a[j + 1] = add(x0i,x2i); - move16(); - - x0r = sub(x0r,x2r); - x0i = sub(x0i,x2i); - - tmp = negate(x0r); - L_tmp = Mult_32_16(wk2i,tmp);/*Q(15+Qx+Q_edct) */ - L_tmp = Msub_32_16(L_tmp,wk2r,x0i); /*Q(15+Qx+Q_edct) */ - a[j2] = round_fx(L_shl(L_tmp,1)); /*Q(Qx+Q_edct) */ - - tmp = negate(x0i); - L_tmp = Mult_32_16(wk2i,tmp);/*Q(15+Qx+Q_edct) */ - L_tmp = Madd_32_16(L_tmp,wk2r,x0r); /*Q(15+Qx+Q_edct) */ - a[j2 + 1] = round_fx(L_shl(L_tmp,1)); /*Q(Qx+Q_edct) */ - - x0r = sub(x1r,x3i); - x0i = add(x1i,x3r); - - L_tmp = Mult_32_16(wk1r,x0r);/*Q(15+Qx+Q_edct) */ - L_tmp = Msub_32_16(L_tmp,wk1i,x0i); /*Q(15+Qx+Q_edct) */ - a[j1] = round_fx(L_shl(L_tmp,1)); /*Q(Qx+Q_edct) */ - - L_tmp = Mult_32_16(wk1r,x0i);/*Q(15+Qx+Q_edct) */ - L_tmp = Madd_32_16(L_tmp,wk1i,x0r); /*Q(15+Qx+Q_edct) */ - a[j1 + 1] = round_fx(L_shl(L_tmp,1)); /*Q(Qx+Q_edct) */ - - x0r = add(x1r,x3i); - x0i = sub(x1i,x3r); - - L_tmp = Mult_32_16(wk3r,x0r); /*Q(15+Qx+Q_edct) */ - L_tmp = Msub_32_16(L_tmp,wk3i,x0i); /*Q(15+Qx+Q_edct) */ - a[j3] = round_fx(L_shl(L_tmp,1)); /*Q(Qx+Q_edct) */ - - L_tmp = Mult_32_16(wk3r,x0i); /*Q(15+Qx+Q_edct) */ - L_tmp = Madd_32_16(L_tmp,wk3i,x0r); /*Q(15+Qx+Q_edct) */ - a[j3 + 1] = round_fx(L_shl(L_tmp,1)); /*Q(Qx+Q_edct) */ - } - } - - return; -} - -void fft3_fx(const Word16 X[], Word16 Y[], const Word16 n) -{ - Word16 Z[PH_ECU_SPEC_SIZE]; - Word16 *Z0, *Z1, *Z2; - Word16 *z0, *z1, *z2; - const Word16 *x; - const Word16 *t_sin = sincos_t_rad3_fx; - Word16 m, mMinus1, step; - Word16 i, l; - Word16 c1_ind, s1_ind, c2_ind, s2_ind; - Word16 c1_step, s1_step, c2_step, s2_step; - Word16 *RY, *IY, *RZ0, *IZ0, *RZ1, *IZ1, *RZ2, *IZ2; - Word32 acc; - Word16 mBy2, orderMinus1; - const Word16 *pPhaseTbl; - - /* Determine the order of the transform, the length of decimated */ - /* transforms m, and the step for the sine and cosine tables. */ - SWITCH(n) - { - case 1536: - orderMinus1 = 9-1; - move16(); - m = 512; - move16(); - step = 1; - move16(); - pPhaseTbl = FFT_W256; - BREAK; - case 384: - orderMinus1 = 7-1; - move16(); - m = 128; - move16(); - step = 4; - move16(); - pPhaseTbl = FFT_W64; - BREAK; - default: - orderMinus1 = 7-1; - move16(); - m = 128; - move16(); - step = 4; - move16(); - pPhaseTbl = FFT_W64; - BREAK; - } - - /* Compose decimated sequences X[3i], X[3i+1],X[3i+2] */ - /* compute their FFT of length m. */ - Z0 = &Z[0]; - z0 = &Z0[0]; - Z1 = &Z0[m]; - z1 = &Z1[0]; /* Z1 = &Z[ m]; */ - Z2 = &Z1[m]; - z2 = &Z2[0]; /* Z2 = &Z[2m]; */ - x = &X[0]; - FOR (i = 0; i < m; i++) - { - *z0++ = *x++; /* Z0[i] = X[3i]; */ move16(); - *z1++ = *x++; /* Z1[i] = X[3i+1]; */ move16(); - *z2++ = *x++; /* Z2[i] = X[3i+2]; */ move16(); - } - mBy2 = shr(m,1); - r_fft_fx_lc(pPhaseTbl, m, mBy2, orderMinus1, Z0, Z0, 1); - r_fft_fx_lc(pPhaseTbl, m, mBy2, orderMinus1, Z1, Z1, 1); - r_fft_fx_lc(pPhaseTbl, m, mBy2, orderMinus1, Z2, Z2, 1); - - /* Butterflies of order 3. */ - /* pointer initialization */ - mMinus1 = sub(m,1); - RY = &Y[0]; - IY = &Y[n]; - IY--; /* Decrement the address counter.*/ - RZ0 = &Z0[0]; - IZ0 = &Z0[mMinus1]; - RZ1 = &Z1[0]; - IZ1 = &Z1[mMinus1]; - RZ2 = &Z2[0]; - IZ2 = &Z2[mMinus1]; - - c1_step = negate(step); - s1_step = step; - move16(); - c2_step = shl(c1_step,1); - s2_step = shl(s1_step,1); - c1_ind = add(T_SIN_PI_2, c1_step); - s1_ind = s1_step; - move16(); - c2_ind = add(T_SIN_PI_2, c2_step); - s2_ind = s2_step; - move16(); - - /* special case: i = 0 */ - acc = L_mult(*RZ0++, 0x4000); - acc = L_mac(acc, *RZ1++, 0x4000); - *RY++ = mac_r(acc, *RZ2++, 0x4000); - move16(); - - /* first 3/12-- from 1 to (3*m/8)-1 */ - l = sub(shr(n, 3),1); /* (3*m/8) - 1 = (n/8) - 1 */ - FOR (i = 0; i < l; i++) - { - acc = L_shl(*RZ0++, 15); /* Align with the following non-fractional mode so as to gain 1 more bit headroom. */ - acc = L_mac0(acc, *RZ1, t_sin[c1_ind]); /* Non-fractional mode gains 1 more bit headroom. */ - acc = L_mac0(acc, *IZ1, t_sin[s1_ind]); - acc = L_mac0(acc, *RZ2, t_sin[c2_ind]); - acc = L_mac0(acc, *IZ2, t_sin[s2_ind]); - *RY++ = round_fx(acc); /* bit growth = 1 (compensated by non-fractional mode MAC). */ - - acc = L_shl(*IZ0--, 15); - acc = L_msu0(acc, *RZ1++, t_sin[s1_ind]); - acc = L_mac0(acc, *IZ1--, t_sin[c1_ind]); - acc = L_msu0(acc, *RZ2++, t_sin[s2_ind]); - acc = L_mac0(acc, *IZ2--, t_sin[c2_ind]); - *IY-- = round_fx(acc); - - c1_ind = add(c1_ind, c1_step); - s1_ind = add(s1_ind, s1_step); - c2_ind = add(c2_ind, c2_step); - s2_ind = add(s2_ind, s2_step); - } - - /* next 1/12-- from (3*m/8) to (4*m/8)-1 */ - l = shr(m,3); /* (4*m/8) - (3*m/8) = m/8 */ - FOR (i = 0; i < l; i++) - { - acc = L_shl(*RZ0++, 15); - acc = L_mac0(acc, *RZ1, t_sin[c1_ind]); /* Non-fractional mode gains 1 more bit headroom. */ - acc = L_mac0(acc, *IZ1, t_sin[s1_ind]); - acc = L_msu0(acc, *RZ2, t_sin[c2_ind]); - acc = L_mac0(acc, *IZ2, t_sin[s2_ind]); - *RY++ = round_fx(acc); - - acc = L_shl(*IZ0--, 15); - acc = L_msu0(acc, *RZ1++, t_sin[s1_ind]); - acc = L_mac0(acc, *IZ1--, t_sin[c1_ind]); - acc = L_msu0(acc, *RZ2++, t_sin[s2_ind]); - acc = L_msu0(acc, *IZ2--, t_sin[c2_ind]); - *IY-- = round_fx(acc); - - c1_ind = add(c1_ind, c1_step); - s1_ind = add(s1_ind, s1_step); - c2_ind = sub(c2_ind, c2_step); - s2_ind = sub(s2_ind, s2_step); - } - - /* special case: i = m/2 i.e. 1/3 */ - acc = L_shl(*RZ0--, 15); - acc = L_mac0(acc, *RZ1, t_sin[c1_ind]); - acc = L_msu0(acc, *RZ2, t_sin[c2_ind]); - *RY++ = round_fx(acc); - - acc = 0; - acc = L_msu0(acc, *RZ1--, t_sin[s1_ind]); - acc = L_msu0(acc, *RZ2--, t_sin[s2_ind]); - *IY-- = round_fx(acc); - IZ0++; - IZ1++; - IZ2++; - - c1_ind = add(c1_ind, c1_step); - s1_ind = add(s1_ind, s1_step); - c2_ind = sub(c2_ind, c2_step); - s2_ind = sub(s2_ind, s2_step); - - /* next 2/12-- from ((m/2)+1) to (6*m/8)-1 */ - l = sub(shr(m,2), 1); /* (6*m/8) - ((m/2)+1) = m/4 - 1 */ - FOR (i = 0; i < l; i++) - { - acc = L_shl(*RZ0--, 15); - acc = L_mac0(acc, *RZ1, t_sin[c1_ind]); /* Non-fractional mode gains 1 more bit headroom. */ - acc = L_msu0(acc, *IZ1, t_sin[s1_ind]); - acc = L_msu0(acc, *RZ2, t_sin[c2_ind]); - acc = L_msu0(acc, *IZ2, t_sin[s2_ind]); - *RY++ = round_fx(acc); - - acc = L_mult0(*IZ0++, -32768); - acc = L_msu0(acc, *RZ1--, t_sin[s1_ind]); - acc = L_msu0(acc, *IZ1++, t_sin[c1_ind]); - acc = L_msu0(acc, *RZ2--, t_sin[s2_ind]); - acc = L_mac0(acc, *IZ2++, t_sin[c2_ind]); - *IY-- = round_fx(acc); - - c1_ind = add(c1_ind, c1_step); - s1_ind = add(s1_ind, s1_step); - c2_ind = sub(c2_ind, c2_step); - s2_ind = sub(s2_ind, s2_step); - } - - /*--------------------------half--------------------------// */ - /* next 2/12-- from (6*m/8) to (8*m/8) - 1 */ - l = shr(m,2); - FOR (i = 0; i < l; i++) - { - acc = L_shl(*RZ0--, 15); - acc = L_msu0(acc, *RZ1, t_sin[c1_ind]); /* Non-fractional mode gains 1 more bit headroom. */ - acc = L_msu0(acc, *IZ1, t_sin[s1_ind]); - acc = L_msu0(acc, *RZ2, t_sin[c2_ind]); - acc = L_mac0(acc, *IZ2, t_sin[s2_ind]); - *RY++ = round_fx(acc); - - acc = L_mult0(*IZ0++, -32768); - acc = L_msu0(acc, *RZ1--, t_sin[s1_ind]); - acc = L_mac0(acc, *IZ1++, t_sin[c1_ind]); - acc = L_mac0(acc, *RZ2--, t_sin[s2_ind]); - acc = L_mac0(acc, *IZ2++, t_sin[c2_ind]); - *IY-- = round_fx(acc); - - c1_ind = sub(c1_ind, c1_step); - s1_ind = sub(s1_ind, s1_step); - c2_ind = add(c2_ind, c2_step); - s2_ind = add(s2_ind, s2_step); - } - - /* special case: i = m, i.e 2/3 */ - acc = L_shl(*RZ0++, 15); - acc = L_msu0(acc, *RZ1, t_sin[c1_ind]); - acc = L_msu0(acc, *RZ2, t_sin[c2_ind]); - *RY++ = round_fx(acc); - - acc = L_deposit_l(0); - acc = L_msu0(acc, *RZ1++, t_sin[s1_ind]); - acc = L_mac0(acc, *RZ2++, t_sin[s2_ind]); - *IY-- = round_fx(acc); - IZ0--; /* Just decrement the address counter */ - IZ1--; - IZ2--; - - c1_ind = sub(c1_ind, c1_step); - s1_ind = sub(s1_ind, s1_step); - c2_ind = add(c2_ind, c2_step); - s2_ind = add(s2_ind, s2_step); - - /* next 1/12-- from (m + 1) to (9*m/8) - 1 */ - l = sub(shr(m, 3), 1); /* (9*m/8) - (m +1) = m/8 - 1 */ - FOR (i = 0; i < l; i++) - { - acc = L_shl(*RZ0++, 15); - acc = L_msu0(acc, *RZ1, t_sin[c1_ind]); /* Non-fractional mode gains 1 more bit headroom. */ - acc = L_mac0(acc, *IZ1, t_sin[s1_ind]); - acc = L_msu0(acc, *RZ2, t_sin[c2_ind]); - acc = L_msu0(acc, *IZ2, t_sin[s2_ind]); - *RY++ = round_fx(acc); - - acc = L_shl(*IZ0--, 15); - acc = L_msu0(acc, *RZ1++, t_sin[s1_ind]); - acc = L_msu0(acc, *IZ1--, t_sin[c1_ind]); - acc = L_mac0(acc, *RZ2++, t_sin[s2_ind]); - acc = L_msu0(acc, *IZ2--, t_sin[c2_ind]); - *IY-- = round_fx(acc); - - c1_ind = sub(c1_ind, c1_step); - s1_ind = sub(s1_ind, s1_step); - c2_ind = add(c2_ind, c2_step); - s2_ind = add(s2_ind, s2_step); - } - - /* last 3/12-- from (9*m/8) to (12*m/8) - 1 */ - l = shr(n,3); /* (12*m/8) - (9*m/8) = 3*m/8 = n/8 */ - FOR (i = 0; i < l; i++) - { - acc = L_shl(*RZ0++, 15); - acc = L_msu0(acc, *RZ1, t_sin[c1_ind]); /* Non-fractional mode gains 1 more bit headroom. */ - acc = L_mac0(acc, *IZ1, t_sin[s1_ind]); - acc = L_mac0(acc, *RZ2, t_sin[c2_ind]); - acc = L_msu0(acc, *IZ2, t_sin[s2_ind]); - *RY++ = round_fx(acc); - - acc = L_shl(*IZ0--, 15); - acc = L_msu0(acc, *RZ1++, t_sin[s1_ind]); - acc = L_msu0(acc, *IZ1--, t_sin[c1_ind]); - acc = L_mac0(acc, *RZ2++, t_sin[s2_ind]); - acc = L_mac0(acc, *IZ2--, t_sin[c2_ind]); - *IY-- = round_fx(acc); - - c1_ind = sub(c1_ind, c1_step); - s1_ind = sub(s1_ind, s1_step); - c2_ind = sub(c2_ind, c2_step); - s2_ind = sub(s2_ind, s2_step); - } - - /* special case: i = 3*m/2 */ - acc = L_shl(*RZ0, 15); - acc = L_msu0(acc, *RZ1, t_sin[c1_ind]); - acc = L_mac0(acc, *RZ2, t_sin[c2_ind]); - *RY = round_fx(acc); - - return; -} - - -void ifft3_fx(const Word16 Z[], Word16 X[], const Word16 n) -{ - Word16 Y[PH_ECU_SPEC_SIZE]; - const Word16 *t_sin = sincos_t_rad3_fx; - Word16 m, mMinus1, step, step2; - Word16 i, l; - Word16 c0_ind, s0_ind, c1_ind, s1_ind, c2_ind, s2_ind; - const Word16 *RZ0, *IZ0, *RZ1, *IZ1, *RZ2, *IZ2; - const Word16 *RZ00, *IZ00, *RZ10, *IZ10, *RZ20, *IZ20; - Word16 *RY0, *IY0, *RY1, *IY1, *RY2, *IY2, *y0, *y1, *y2, *pX; - Word32 acc; - Word16 mBy2, orderMinus1, nMinusMBy2; - const Word16 *pPhaseTbl; - - /* Determine the order of the transform, the length of decimated */ - /* transforms m, and the step for the sine and cosine tables. */ - SWITCH(n) - { - case 1536: - orderMinus1 = 9-1; - move16(); - m = 512; - move16(); - step = 1; - move16(); - pPhaseTbl = FFT_W256; - BREAK; - case 384: - orderMinus1 = 7-1; - move16(); - m = 128; - move16(); - step = 4; - move16(); - pPhaseTbl = FFT_W64; - BREAK; - default: - orderMinus1 = 7-1; - move16(); - m = 128; - move16(); - step = 4; - move16(); - pPhaseTbl = FFT_W64; - BREAK; - } - - nMinusMBy2 = shr(sub(n, m),1); - mMinus1 = sub(m,1); - /* pointer initialization */ - RY0 = &Y[0]; - IY0 = &Y[m]; - RY1 = &RY0[m]; - IY1 = &RY1[mMinus1]; - RY2 = &RY1[m]; - IY2 = &RY2[mMinus1]; - - RZ00 = &Z[0]; /* The zero positions of the pointers */ - RZ10 = &RZ00[m]; - RZ20 = &RZ00[nMinusMBy2]; - IZ00 = &Z[n]; - IZ10 = &IZ00[-m]; - IZ20 = &IZ00[-nMinusMBy2]; - - RZ0 = RZ00; /* Reset the pointers to zero positions. */ - RZ1 = RZ10; - RZ2 = RZ20; - IZ0 = IZ00; - IZ1 = IZ10; - IZ2 = IZ20; - - /* Inverse butterflies of order 3. */ - - /* Construction of Y0 */ - acc = L_mult(*RZ0++, 0x4000); - acc = L_mac(acc, *RZ1++, 0x4000); - *RY0++ = mac_r(acc, *RZ2--, 0x4000); - move16(); - IZ0--; - IZ1--; - IZ2++; - IY0--; - - l = sub(shr(m, 1), 1); - FOR (i = 0; i < l; i++) - { - acc = L_mult(*RZ0++, 0x4000); - acc = L_mac(acc, *RZ1++, 0x4000); - *RY0++ = mac_r(acc, *RZ2--, 0x4000); - move16(); - - acc = L_mult(*IZ0--, 0x4000); - acc = L_mac(acc, *IZ1--, 0x4000); - *IY0-- = msu_r(acc, *IZ2++, 0x4000); - move16(); - } - - /* m/2 */ - acc = L_mult(*RZ0, 0x4000); - acc = L_mac(acc, *RZ1, 0x4000); - *RY0++ = mac_r(acc, *RZ2, 0x4000); - move16(); - - - /* Construction of Y1 */ - c0_ind=T_SIN_PI_2; - s0_ind=0; - c1_ind=T_SIN_PI_2*1/3; - s1_ind=T_SIN_PI_2*2/3; - c2_ind=T_SIN_PI_2*1/3; - s2_ind=T_SIN_PI_2*2/3; - - RZ0 = RZ00; /* Reset pointers to zero positions. */ - RZ1 = RZ10; - RZ2 = RZ20; - IZ0 = IZ00; - IZ1 = IZ10; - IZ2 = IZ20; - acc = L_mult0(*RZ0++, t_sin[c0_ind]); - acc = L_msu0(acc, *RZ1++, t_sin[c1_ind]); - acc = L_msu0(acc, *RZ2--, t_sin[c2_ind]); - IZ0--; - acc = L_msu0(acc, *IZ1--, t_sin[s1_ind]); - acc = L_msu0(acc, *IZ2++, t_sin[s2_ind]); - *RY1++ = round_fx(acc); - - c0_ind=sub(c0_ind,step); - s0_ind=add(s0_ind,step); - c1_ind=add(c1_ind,step); - s1_ind=sub(s1_ind,step); - c2_ind=sub(c2_ind,step); - s2_ind=add(s2_ind,step); - - /* From 1 to (m/4) - 1. */ - l = sub(shr(m,2),1); - FOR (i = 0; i < l; i++) - { - acc = L_mult0(*RZ0, t_sin[c0_ind]); - acc = L_msu0(acc, *RZ1, t_sin[c1_ind]); - acc = L_msu0(acc, *RZ2, t_sin[c2_ind]); - acc = L_msu0(acc, *IZ0, t_sin[s0_ind]); - acc = L_msu0(acc, *IZ1, t_sin[s1_ind]); - acc = L_msu0(acc, *IZ2, t_sin[s2_ind]); - *RY1++ = round_fx(acc); - - acc = L_mult0(*IZ0--, t_sin[c0_ind]); - acc = L_msu0(acc, *IZ1--, t_sin[c1_ind]); - acc = L_mac0(acc, *IZ2++, t_sin[c2_ind]); - acc = L_mac0(acc, *RZ0++, t_sin[s0_ind]); - acc = L_mac0(acc, *RZ1++, t_sin[s1_ind]); - acc = L_msu0(acc, *RZ2--, t_sin[s2_ind]); - *IY1-- = round_fx(acc); - - c0_ind=sub(c0_ind,step); - s0_ind=add(s0_ind,step); - c1_ind=add(c1_ind,step); - s1_ind=sub(s1_ind,step); - c2_ind=sub(c2_ind,step); - s2_ind=add(s2_ind,step); - } - - /* From m/4 to m/2 -1. */ - l = shr(m, 2); /* m/2 - m/4 = m/4 */ - FOR (i = 0; i < l; i++) - { - acc = L_mult0(*RZ0, t_sin[c0_ind]); - acc = L_msu0(acc, *RZ1, t_sin[c1_ind]); - acc = L_mac0(acc, *RZ2, t_sin[c2_ind]); - acc = L_msu0(acc, *IZ0, t_sin[s0_ind]); - acc = L_msu0(acc, *IZ1, t_sin[s1_ind]); - acc = L_msu0(acc, *IZ2, t_sin[s2_ind]); - *RY1++ = round_fx(acc); - - acc = L_mult0(*IZ0--, t_sin[c0_ind]); - acc = L_msu0(acc, *IZ1--, t_sin[c1_ind]); - acc = L_msu0(acc, *IZ2++, t_sin[c2_ind]); - acc = L_mac0(acc, *RZ0++, t_sin[s0_ind]); - acc = L_mac0(acc, *RZ1++, t_sin[s1_ind]); - acc = L_msu0(acc, *RZ2--, t_sin[s2_ind]); - *IY1-- = round_fx(acc); - - c0_ind=sub(c0_ind,step); - s0_ind=add(s0_ind,step); - c1_ind=add(c1_ind,step); - s1_ind=sub(s1_ind,step); - c2_ind=add(c2_ind,step); - s2_ind=sub(s2_ind,step); - } - - /* m/2 */ - acc = L_mult0(*RZ0, t_sin[c0_ind]); - acc = L_msu0(acc, *RZ1, t_sin[c1_ind]); - acc = L_mac0(acc, *RZ2, t_sin[c2_ind]); - acc = L_msu0(acc, *IZ0, t_sin[s0_ind]); - acc = L_msu0(acc, *IZ1, t_sin[s1_ind]); - acc = L_msu0(acc, *IZ2, t_sin[s2_ind]); - *RY1++ = round_fx(acc); - - /* Construction of Y2 */ - c0_ind=T_SIN_PI_2; - s0_ind=0; - c1_ind=T_SIN_PI_2*1/3; - s1_ind=T_SIN_PI_2*2/3; - c2_ind=T_SIN_PI_2*1/3; - s2_ind=T_SIN_PI_2*2/3; - step2 = shl(step,1); - - RZ0 = RZ00; /* Reset pointers to zero positions. */ - RZ1 = RZ10; - RZ2 = RZ20; - IZ0 = IZ00; - IZ1 = IZ10; - IZ2 = IZ20; - acc = L_mult0(*RZ0++, t_sin[c0_ind]); - acc = L_msu0(acc, *RZ1++, t_sin[c1_ind]); - acc = L_msu0(acc, *RZ2--, t_sin[c2_ind]); - IZ0--; - acc = L_mac0(acc, *IZ1--, t_sin[s1_ind]); - acc = L_mac0(acc, *IZ2++, t_sin[s2_ind]); - *RY2++ = round_fx(acc); - - c0_ind=sub(c0_ind,step2); - s0_ind=add(s0_ind,step2); - c1_ind=sub(c1_ind,step2); - s1_ind=add(s1_ind,step2); - c2_ind=add(c2_ind,step2); - s2_ind=sub(s2_ind,step2); - - /* From 1 to (m/8) - 1. */ - l = sub(shr(m, 3),1); /* m/8 - 1. */ - FOR (i = 0; i < l; i++) - { - acc = L_mult0(*RZ0, t_sin[c0_ind]); - acc = L_msu0(acc, *RZ1, t_sin[c1_ind]); - acc = L_msu0(acc, *RZ2, t_sin[c2_ind]); - acc = L_msu0(acc, *IZ0, t_sin[s0_ind]); - acc = L_mac0(acc, *IZ1, t_sin[s1_ind]); - acc = L_mac0(acc, *IZ2, t_sin[s2_ind]); - *RY2++ = round_fx(acc); - - acc = L_mult0(*IZ0--, t_sin[c0_ind]); - acc = L_msu0(acc, *IZ1--, t_sin[c1_ind]); - acc = L_mac0(acc, *IZ2++, t_sin[c2_ind]); - acc = L_mac0(acc, *RZ0++, t_sin[s0_ind]); - acc = L_msu0(acc, *RZ1++, t_sin[s1_ind]); - acc = L_mac0(acc, *RZ2--, t_sin[s2_ind]); - *IY2-- = round_fx(acc); - - c0_ind=sub(c0_ind,step2); - s0_ind=add(s0_ind,step2); - c1_ind=sub(c1_ind,step2); - s1_ind=add(s1_ind,step2); - c2_ind=add(c2_ind,step2); - s2_ind=sub(s2_ind,step2); - } - - /* From (m/8) to (m/4) - 1. */ - l = shr(m, 3); /* m/4 - m/8 = m/8 */ - FOR (i = 0; i < l; i++) - { - acc = L_mult0(*RZ0, t_sin[c0_ind]); - acc = L_mac0(acc, *RZ1, t_sin[c1_ind]); - acc = L_msu0(acc, *RZ2, t_sin[c2_ind]); - acc = L_msu0(acc, *IZ0, t_sin[s0_ind]); - acc = L_mac0(acc, *IZ1, t_sin[s1_ind]); - acc = L_mac0(acc, *IZ2, t_sin[s2_ind]); - *RY2++ = round_fx(acc); - - acc = L_mult0(*IZ0--, t_sin[c0_ind]); - acc = L_mac0(acc, *IZ1--, t_sin[c1_ind]); - acc = L_mac0(acc, *IZ2++, t_sin[c2_ind]); - acc = L_mac0(acc, *RZ0++, t_sin[s0_ind]); - acc = L_msu0(acc, *RZ1++, t_sin[s1_ind]); - acc = L_mac0(acc, *RZ2--, t_sin[s2_ind]); - *IY2-- = round_fx(acc); - - c0_ind=sub(c0_ind,step2); - s0_ind=add(s0_ind,step2); - c1_ind=add(c1_ind,step2); - s1_ind=sub(s1_ind,step2); - c2_ind=add(c2_ind,step2); - s2_ind=sub(s2_ind,step2); - } - - /* From m/4 to 3*m/8 - 1. */ - l = shr(m, 3); /* 3*m/8 - m/4 = m/8 */ - FOR (i = 0; i < l; i++) - { - acc = L_mult0(*RZ0, t_sin[c0_ind]); - acc = L_mac0(acc, *RZ1, t_sin[c1_ind]); - acc = L_msu0(acc, *RZ2, t_sin[c2_ind]); - acc = L_msu0(acc, *IZ0, t_sin[s0_ind]); - acc = L_mac0(acc, *IZ1, t_sin[s1_ind]); - acc = L_msu0(acc, *IZ2, t_sin[s2_ind]); - *RY2++ = round_fx(acc); - - acc = L_mult0(*IZ0--, t_sin[c0_ind]); - acc = L_mac0(acc, *IZ1--, t_sin[c1_ind]); - acc = L_mac0(acc, *IZ2++, t_sin[c2_ind]); - acc = L_mac0(acc, *RZ0++, t_sin[s0_ind]); - acc = L_msu0(acc, *RZ1++, t_sin[s1_ind]); - acc = L_msu0(acc, *RZ2--, t_sin[s2_ind]); - *IY2-- = round_fx(acc); - - c0_ind=sub(c0_ind,step2); - s0_ind=add(s0_ind,step2); - c1_ind=add(c1_ind,step2); - s1_ind=sub(s1_ind,step2); - c2_ind=sub(c2_ind,step2); - s2_ind=add(s2_ind,step2); - } - - /* From 3*m/8 to m/2 - 1*/ - l = shr(m, 3); /* m/2 - 3*m/8 = m/8 */ - FOR (i = 0; i < l; i++) - { - acc = L_mult0(*RZ1, t_sin[c1_ind]); - acc = L_msu0(acc, *RZ0, t_sin[c0_ind]); - acc = L_msu0(acc, *RZ2, t_sin[c2_ind]); - acc = L_msu0(acc, *IZ0, t_sin[s0_ind]); - acc = L_mac0(acc, *IZ1, t_sin[s1_ind]); - acc = L_msu0(acc, *IZ2, t_sin[s2_ind]); - *RY2++ = round_fx(acc); - - acc = L_mult0(*IZ1--, t_sin[c1_ind]); - acc = L_msu0(acc, *IZ0--, t_sin[c0_ind]); - acc = L_mac0(acc, *IZ2++, t_sin[c2_ind]); - acc = L_mac0(acc, *RZ0++, t_sin[s0_ind]); - acc = L_msu0(acc, *RZ1++, t_sin[s1_ind]); - acc = L_msu0(acc, *RZ2--, t_sin[s2_ind]); - *IY2-- = round_fx(acc); - - c0_ind=add(c0_ind,step2); - s0_ind=sub(s0_ind,step2); - c1_ind=add(c1_ind,step2); - s1_ind=sub(s1_ind,step2); - c2_ind=sub(c2_ind,step2); - s2_ind=add(s2_ind,step2); - } - - /* m/2 */ - acc = L_mult0(*RZ1, t_sin[c1_ind]); - acc = L_msu0(acc, *RZ0, t_sin[c0_ind]); - acc = L_msu0(acc, *RZ2, t_sin[c2_ind]); - acc = L_msu0(acc, *IZ0, t_sin[s0_ind]); - acc = L_mac0(acc, *IZ1, t_sin[s1_ind]); - acc = L_msu0(acc, *IZ2, t_sin[s2_ind]); - *RY2++ = round_fx(acc); - - /* Compute the inverse FFT for all 3 blocks. */ - RY0 = &Y[0]; /* Rewind the pointers. */ - RY1 = &Y[m]; - RY2 = &RY1[m]; - mBy2 = shr(m,1); - r_fft_fx_lc(pPhaseTbl, m, mBy2, orderMinus1, RY0, RY0, 0); /* inverse FFT */ - r_fft_fx_lc(pPhaseTbl, m, mBy2, orderMinus1, RY1, RY1, 0); /* inverse FFT */ - r_fft_fx_lc(pPhaseTbl, m, mBy2, orderMinus1, RY2, RY2, 0); /* inverse FFT */ - - y0 = RY0; - y1 = RY1; - y2 = RY2; - - /* Interlacing and scaling, scale = 1/3 */ - pX = X; - FOR (i = 0; i < m; i++) - { - *pX++ = shl(mult_r(*y0++, FFT3_ONE_THIRD), 1); - move16(); - *pX++ = shl(mult_r(*y1++, FFT3_ONE_THIRD), 1); - move16(); - *pX++ = shl(mult_r(*y2++, FFT3_ONE_THIRD), 1); - move16(); - } - - return; -} diff --git a/src/libs/libevs/lib_com/fft_rel.cpp b/src/libs/libevs/lib_com/fft_rel.cpp new file mode 100644 index 00000000..02a9d574 --- /dev/null +++ b/src/libs/libevs/lib_com/fft_rel.cpp @@ -0,0 +1,266 @@ +/*==================================================================================== + EVS Codec 3GPP TS26.443 Nov 13, 2018. Version 12.11.0 / 13.7.0 / 14.3.0 / 15.1.0 + ====================================================================================*/ + +#include "options.h" +#include "prot.h" +#include "rom_com.h" + +/*---------------------------------------------------------------------* + * Local constants + *---------------------------------------------------------------------*/ + +#define N_MAX_FFT 1024 +#define N_MAX_DIV2 (N_MAX_FFT>>1) +#define N_MAX_DIV4 (N_MAX_DIV2>>1) + +/*---------------------------------------------------------------------* + * fft_rel() + * + * Computes the split-radix FFT in place for the real-valued + * signal x of length n. The algorithm has been ported from + * the Fortran code of [1]. + * + * The function needs sine and cosine tables t_sin and t_cos, + * and the constant N_MAX_FFT. The table entries are defined as + * sin(2*pi*i) and cos(2*pi*i) for i = 0, 1, ..., N_MAX_FFT-1. The + * implementation assumes that any entry will not be needed + * outside the tables. Therefore, N_MAX_FFT and n must be properly + * set. The function has been tested with the values n = 16, + * 32, 64, 128, 256, and N_MAX_FFT = 1280. + * + * References + * [1] H.V. Sorensen, D.L. Jones, M.T. Heideman, C.S. Burrus, + * "Real-valued fast Fourier transform algorithm," IEEE + * Trans. on Signal Processing, Vol.35, No.6, pp 849-863, + * 1987. + * + * OUTPUT + * x[0:n-1] Transform coeffients in the order re[0], re[1], + * ..., re[n/2], im[n/2-1], ..., im[1]. + *---------------------------------------------------------------------*/ + +void fft_rel( + float x[], /* i/o: input/output vector */ + const short n, /* i : vector length */ + const short m /* i : log2 of vector length */ +) +{ + short i, j, k, n1, n2, n4; + short step; + float xt, t1, t2; + float *x0, *x1, *x2; + float *xi2, *xi3, *xi4, *xi1; + const float *s, *c; + const short *idx; + + /* !!!! NMAX = 256 is hardcoded here (similar optimizations should be done for NMAX > 256) !!! */ + + float *x2even, *x2odd; + float temp[512]; + + if ( n == 128 || n == 256 || n == 512 ) + { + idx = fft256_read_indexes; + + /* Combined Digit reverse counter & Length two butterflies */ + if (n == 128) + { + x2 = temp; + for (i = 0; i < 64; i++) + { + j = *idx++; + k = *idx++; + + *x2++ = x[j>>1] + x[k>>1]; + *x2++ = x[j>>1] - x[k>>1]; + } + } + else if (n == 256) + { + x2 = temp; + for (i = 0; i < 128; i++) + { + j = *idx++; + k = *idx++; + + *x2++ = x[j] + x[k]; + *x2++ = x[j] - x[k]; + } + } + else if (n == 512) + { + x2even = temp; + x2odd = temp + 256; + + for (i = 0; i < 128; i++) + { + j = 2 * *idx++; + k = 2 * *idx++; + + *x2even++ = x[j] + x[k]; + *x2even++ = x[j] - x[k]; + *x2odd++ = x[++j] + x[++k]; + *x2odd++ = x[j] - x[k]; + } + } + + /*-----------------------------------------------------------------* + * 1st Stage Loop has been Unrolled because n4 is '1' and that + * allows the elimination of the 'for_ (j = 1; j < n4; j++)' loop + * and the associated pointers initialization. + * Also, it allows to Put the Data from 'temp' back into 'x' due + * to the previous Combined Digit Reverse and Length two butterflies + *-----------------------------------------------------------------*/ + + /*for_ (k = 2; k < 3; k++)*/ + { + x0 = temp; + x1 = x0 + 2; + x2 = x; + + for (i = 0; i < n; i += 4) + { + *x2++ = *x0++ + *x1; /* x[i] = xt + x[i+n2]; */ + *x2++ = *x0; + *x2++ = *--x0 - *x1++; /* x[i+n2] = xt - x[i+n2]; */ + *x2++ = -*x1; /* x[i+n2+n4] = -x[i+n2+n4]; */ + + x0 += 4; + x1 += 3; /* x1 has already advanced */ + } + } + } + else + { + /*-----------------------------------------------------------------* + * Digit reverse counter + *-----------------------------------------------------------------*/ + + j = 0; + x0 = &x[0]; + for (i = 0; i < n-1; i++) + { + if (i < j) + { + xt = x[j]; + x[j] = *x0; + *x0 = xt; + } + x0++; + k = n/2; + while (k <= j) + { + j -= k; + k = k>>1; + } + j += k; + } + + /*-----------------------------------------------------------------* + * Length two butterflies + *-----------------------------------------------------------------*/ + + x0 = &x[0]; + x1 = &x[1]; + for (i = 0; i < n/2; i++) + { + *x1 = *x0 - *x1; + *x0 = *x0*2 - *x1; + + x0++; + x0++; + x1++; + x1++; + } + + /*-----------------------------------------------------------------* + * 1st Stage Loop has been Unrolled because n4 is '1' and that + * allows the elimination of the 'for_ (j = 1; j < n4; j++)' loop + * and the associated pointers initialization. + *-----------------------------------------------------------------*/ + + /* for_ (k = 2; k < 3; k++) */ + { + x0 = x; + x1 = x0 + 2; + + for (i = 0; i < n; i += 4) + { + *x1 = *x0 - *x1; /* x[i+n2] = xt - x[i+n2]; */ + *x0 = *x0*2 - *x1++; /* x[i] = xt + x[i+n2]; */ + *x1 = -*x1; /* x[i+n2+n4] = -x[i+n2+n4]; */ + + x0 += 4; + x1 += 3; /* x1 has already advanced */ + } + } + } + + /*-----------------------------------------------------------------* + * Other butterflies + * + * The implementation described in [1] has been changed by using + * table lookup for evaluating sine and cosine functions. The + * variable ind and its increment step are needed to access table + * entries. Note that this implementation assumes n4 to be so + * small that ind will never exceed the table. Thus the input + * argument n and the constant N_MAX_FFT must be set properly. + *-----------------------------------------------------------------*/ + + n4 = 1; + n2 = 2; + n1 = 4; + + step = N_MAX_DIV4; + + for (k = 3; k <= m; k++) + { + step >>= 1; + n4 <<= 1; + n2 <<= 1; + n1 <<= 1; + + x0 = x; + x1 = x0 + n2; + x2 = x1 + n4; + + for (i = 0; i < n; i += n1) + { + *x1 = *x0 - *x1; /* x[i+n2] = xt - x[i+n2]; */ + *x0 = *x0*2 - *x1; /* x[i] = xt + x[i+n2]; */ + *x2 = -*x2; /* x[i+n2+n4] = -x[i+n2+n4]; */ + + s = sincos_t_ext; + c = s + N_MAX_FFT/4; /* 1024/4 = 256, 256/4=64 */ + xi1 = x0; + xi3 = xi1 + n2; + xi2 = xi3; + x0 += n1; + xi4 = x0; + + for (j = 1; j < n4; j++) + { + xi3++; + xi1++; + xi4--; + xi2--; + c += step; + s+= step; /* autoincrement by ar0 */ + + t1 = *xi3**c + *xi4**s; /* t1 = *xi3**(pt_c+ind) + *xi4**(pt_s+ind); */ + t2 = *xi3**s - *xi4**c; /* t2 = *xi3**(pt_s+ind) - *xi4**(pt_c+ind); */ + + *xi4 = *xi2 - t2; + *xi2 = *xi1 - t1; + *xi1 = *xi1*2 - *xi2; + *xi3 = -2*t2 - *xi4; + } + + x1 += n1; + x2 += n1; + } + } + + return; +} diff --git a/src/libs/libevs/lib_com/fft_rel_fx.cpp b/src/libs/libevs/lib_com/fft_rel_fx.cpp deleted file mode 100755 index afb8644c..00000000 --- a/src/libs/libevs/lib_com/fft_rel_fx.cpp +++ /dev/null @@ -1,431 +0,0 @@ -/*==================================================================================== - EVS Codec 3GPP TS26.442 Apr 03, 2018. Version 12.11.0 / 13.6.0 / 14.2.0 - ====================================================================================*/ - -#include "options.h" /* Compilation switches */ -#include "prot_fx.h" /* Function prototypes */ -#include "rom_com_fx.h" /* Static table prototypes */ -#include "stl.h" - -/*------------------------------------------------------------------ - * - * This is an implementation of decimation-in-time FFT algorithm for - * real sequences. The techniques used here can be found in several - * books, e.g., i) Proakis and Manolakis, "Digital Signal Processing", - * 2nd Edition, Chapter 9, and ii) W.H. Press et. al., "Numerical - * Recipes in C", 2nd Edition, Chapter 12. - * - * Input - There are two inputs to this function: - * - * 1) An integer pointer to the input data array - * 2) An integer value which should be set as +1 for FFT - * and some other value, e.g., -1 for ifFT - * - * Output - There is no return value. - * The input data are replaced with transformed data. if the - * input is a real time domain sequence, it is replaced with - * the complex FFT for positive frequencies. The FFT value - * for DC and the foldover frequency are combined to form the - * first complex number in the array. The remaining complex - * numbers correspond to increasing frequencies. if the input - * is a complex frequency domain sequence arranged as above, - * it is replaced with the corresponding time domain sequence. - * - * Notes: - * - * 1) This function is designed to be a part of a noise supp- - * ression algorithm that requires 128-point FFT of real - * sequences. This is achieved here through a 64-point - * complex FFT. Consequently, the FFT size information is - * not transmitted explicitly. However, some flexibility - * is provided in the function to change the size of the - * FFT by specifying the size information through "define" - * statements. - * - * 2) The values of the complex sinusoids used in the FFT - * algorithm are computed once (i.e., the first time the - * r_fft function is called) and stored in a table. To - * further speed up the algorithm, these values can be - * precomputed and stored in a ROM table in actual DSP - * based implementations. - * - * 3) In the c_fft function, the FFT values are divided by - * 2 after each stage of computation thus dividing the - * final FFT values by 64. No multiplying factor is used - * for the ifFT. This is somewhat different from the usual - * definition of FFT where the factor 1/N, i.e., 1/64, is - * used for the ifFT and not the FFT. No factor is used in - * the r_fft function. - * - * 4) Much of the code for the FFT and ifFT parts in r_fft - * and c_fft functions are similar and can be combined. - * They are, however, kept separate here to speed up the - * execution. - *------------------------------------------------------------------------*/ -/*------------------------------------------------------------------------* - * c_fft_fx: - * - * Computes the complex part of the split-radix FFT - *------------------------------------------------------------------------*/ - -static void c_fft_fx( - const Word16 *phs_tbl, /* i : Table of phases */ - Word16 SIZE, /* i : Size of the FFT */ - Word16 NUM_STAGE, /* i : Number of stages */ - const Word16 *in_ptr, /* i : coefficients in the order re[0], re[n/2], re[1], im[1], ..., re[n/2-1], im[n/2-1] */ - Word16 *out_ptr, /* o : coefficients in the order re[0], re[n/2], re[1], im[1], ..., re[n/2-1], im[n/2-1] */ - /* in_ptr & out_ptr must not overlap! */ - const Word16 isign) /* i : 1=fft, otherwise it is ifft*/ -{ - Word16 i, j, k, ii, jj, kk, ji, kj; - Word32 L_tmp1, L_tmp2; - Word16 tmp1,tmp2,tmp3,tmp4; - const Word16 *table_ptr; - const Word16 *input_ptr1,*input_ptr2,*input_ptr3,*input_ptr4; - - /* Setup Reorder Variables */ - table_ptr = NULL; - SWITCH (SIZE) - { - case 1024: - table_ptr = FFT_REORDER_1024; - BREAK; - case 512: - table_ptr = FFT_REORDER_512; - BREAK; - case 256: - table_ptr = FFT_reorder_256; - BREAK; - case 128: - table_ptr = FFT_REORDER_128; - BREAK; - case 64: - table_ptr = FFT_reorder_64; - BREAK; - } - /* The FFT part */ - IF (isign != 0) - { - /* Unrolled 1st/2nd Stage - * 1) to take advantage of Table Values (0 & +/- 16384) - * 2) to perform reordering of Input Values - */ - FOR (k = 0; k < SIZE; k += 8) - { - /* - * This loop use: - * 4 Word16 (tmp1...tmp4) - * 2 Word32 (L_tmp1 & L_tmp2) - * 4 Pointers (table_ptr, input_ptr1, input_ptr2, input_ptr3) - * - * The addition of 'in_ptr' + and index value from 'reorder_ptr' - * is counted as a move16() - */ - - input_ptr1 = in_ptr + *table_ptr++; - - L_tmp1 = L_mult(*input_ptr1++, 16384); - L_tmp2 = L_mult(*input_ptr1, 16384); - - input_ptr1 = in_ptr + *table_ptr++; - - tmp1 = msu_r(L_tmp1, *input_ptr1, 16384); - tmp3 = mac_r(L_tmp1, *input_ptr1++, 16384); - - input_ptr2 = in_ptr + *table_ptr++; - input_ptr3 = in_ptr + *table_ptr++; - - L_tmp1 = L_mult(*input_ptr2++, 16384); - tmp2 = mac_r(L_tmp1, *input_ptr3, 16384); - tmp4 = msu_r(L_tmp1, *input_ptr3++, 16384); - - L_tmp1 = L_mult(tmp3, 16384); - out_ptr[k] = mac_r(L_tmp1, tmp2, 16384); - move16(); - out_ptr[k+4] = msu_r(L_tmp1, tmp2, 16384); - move16(); - - tmp2 = mac_r(L_tmp2, *input_ptr1, 16384); - tmp3 = msu_r(L_tmp2, *input_ptr1, 16384); - - L_tmp2 = L_mult(*input_ptr2, 16384); - - L_tmp1 = L_mult(tmp1, 16384); - tmp1 = msu_r(L_tmp2, *input_ptr3, 16384); - out_ptr[k+2] = mac_r(L_tmp1, tmp1, 16384); - move16(); - out_ptr[k+6] = msu_r(L_tmp1, tmp1, 16384); - move16(); - - L_tmp1 = L_mult(tmp2, 16384); - tmp2 = mac_r(L_tmp2, *input_ptr3, 16384); - out_ptr[k+1] = mac_r(L_tmp1, tmp2, 16384); - move16(); - out_ptr[k+5] = msu_r(L_tmp1, tmp2, 16384); - move16(); - - L_tmp1 = L_mult(tmp3, 16384); - out_ptr[k+3] = msu_r(L_tmp1, tmp4, 16384); - move16(); - out_ptr[k+7] = mac_r(L_tmp1, tmp4, 16384); - move16(); - } - - /* Remaining Stages */ - FOR (i = 2; i < NUM_STAGE; i++) - { - /* i is stage counter */ - jj = shl(2, i); /* FFT size */ - kk = shl(jj, 1); /* 2 * FFT size */ - ii = shr(SIZE, i); - ji = 0; - move16(); /* ji is phase table index */ - - FOR (j = 0; j < jj; j += 2) - { - /* j is sample counter */ - FOR (k = j; k < SIZE; k += kk) - { - /* k is butterfly top */ - kj = add(k, jj); /* kj is butterfly bottom */ - - /* Butterfly computations */ - L_tmp1 = L_msu(L_mult(*(out_ptr + kj), phs_tbl[ji]), - *(out_ptr + kj + 1), phs_tbl[ji + 1]); - L_tmp2 = L_mac(L_mult(*(out_ptr + kj + 1), phs_tbl[ji]), - *(out_ptr + kj), phs_tbl[ji + 1]); - - out_ptr[kj] = mac_r(L_negate(L_tmp1), out_ptr[k], 16384); - move16(); - out_ptr[kj+1] = mac_r(L_negate(L_tmp2), out_ptr[k+1], 16384); - move16(); - out_ptr[k] = mac_r(L_tmp1, out_ptr[k], 16384); - move16(); - out_ptr[k+1] = mac_r(L_tmp2, out_ptr[k+1], 16384); - move16(); - } - ji = add(ji, ii); - } - } - } - ELSE /* The ifFT part */ - { - /* Unrolled 1st/2nd Stage - * 1) to take advantage of Table Values (0 & +/- 16384) - * 2) to perform reordering of Input Values - */ - FOR (k = 0; k < SIZE; k += 8) - { - /* - * This loop use: - * 4 Word16 (tmp1...tmp4) - * 2 Word32 (L_tmp1 & L_tmp2) - * 5 Pointers (reorder_ptr, input_ptr1...input_ptr4) - * - * The addition of 'in_ptr' + and index value from 'reorder_ptr' - * is counted as a move16() - */ - - input_ptr1 = in_ptr + *table_ptr++; - input_ptr2 = in_ptr + *table_ptr++; - - input_ptr3 = in_ptr + *table_ptr++; - input_ptr4 = in_ptr + *table_ptr++; - - tmp3 = sub(*input_ptr1, *input_ptr2); - tmp4 = add(*input_ptr1++, *input_ptr2++); - - tmp2 = sub(input_ptr3[0], input_ptr4[0]); - tmp1 = sub(input_ptr3[1], input_ptr4[1]); - - out_ptr[k+2] = sub(tmp3, tmp1); - move16(); - out_ptr[k+6] = add(tmp3, tmp1); - move16(); - - tmp1 = sub(*input_ptr1, *input_ptr2); - out_ptr[k+3] = add(tmp1, tmp2); - move16(); - out_ptr[k+7] = sub(tmp1, tmp2); - move16(); - - tmp1 = add(input_ptr3[0], input_ptr4[0]); - tmp3 = add(input_ptr3[1], input_ptr4[1]); - - out_ptr[k] = add(tmp4, tmp1); - move16(); - out_ptr[k+4] = sub(tmp4, tmp1); - move16(); - - tmp4 = add(*input_ptr1, *input_ptr2); - out_ptr[k+1] = add(tmp4, tmp3); - move16(); - out_ptr[k+5] = sub(tmp4, tmp3); - move16(); - } - - table_ptr = phs_tbl + SIZE; /* access part of table that is scaled by 2 */ - - /* Remaining Stages */ - FOR (i = 2; i < NUM_STAGE; i++) - { - /* i is stage counter */ - jj = shl(2, i); /* FFT size */ - kk = shl(jj, 1); /* 2 * FFT size */ - ii = shr(SIZE, i); - ji = 0; - move16(); /* ji is phase table index */ - - FOR (j = 0; j < jj; j += 2) - { - /* j is sample counter */ - /* This can be computed by successive add_fxitions of ii to ji, starting from 0 - hence line-count it as a one-line add (still need to increment op count!!) */ - - FOR (k = j; k < SIZE; k += kk) - { - /* k is butterfly top */ - kj = add(k, jj); /* kj is butterfly bottom */ - - /* Butterfly computations */ - tmp1 = mac_r(L_mult(out_ptr[kj], table_ptr[ji]), - out_ptr[kj+1], table_ptr[ji + 1]); - - tmp2 = msu_r(L_mult(out_ptr[kj+1], table_ptr[ji]), - out_ptr[kj], table_ptr[ji+1]); - - out_ptr[kj] = sub(out_ptr[k], tmp1); - move16(); - out_ptr[kj+1] = sub(out_ptr[k+1], tmp2); - move16(); - out_ptr[k] = add(out_ptr[k], tmp1); - move16(); - out_ptr[k+1] = add(out_ptr[k+1], tmp2); - move16(); - } - ji = add(ji, ii); - } - } - } -} - -/*--------------------------------------------------------------------------------* - * r_fft_fx: - * - * Perform FFT fixed-point for real-valued sequences of length 32, 64 or 128 - *--------------------------------------------------------------------------------*/ -void r_fft_fx_lc( - const Word16 *phs_tbl, /* i : Table of phase */ - const Word16 SIZE, /* i : Size of the FFT */ - const Word16 SIZE2, /* i : Size / 2 */ - const Word16 NUM_STAGE, /* i : Number of stage */ - const Word16 *in_ptr, /* i : coefficients in the order re[0], re[1], ... re[n/2], im[n/2-1], im[n/2-2], ..., im[1] */ - Word16 *out_ptr, /* o : coefficients in the order re[0], re[1], ... re[n/2], im[n/2-1], im[n/2-2], ..., im[1] */ - const Word16 isign /* i : 1=fft, otherwize it's ifft */ -) -{ - Word16 tmp2_real, tmp2_imag; - Word32 Ltmp1_real, Ltmp1_imag; - Word16 i; - Word32 Ltmp1; - const Word16 *phstbl_ptrDn; - Word16 *ptrDn; - Word16 temp[1024]; /* Accommodates real input FFT size up to 1024. */ - - /* Setup Pointers */ - phstbl_ptrDn = &phs_tbl[SIZE-1]; - - /* The FFT part */ - IF (isign != 0) - { - Word16 *ptRealUp, *ptRealDn, *ptImaUp, *ptImaDn; - - /* Perform the complex FFT */ - c_fft_fx(phs_tbl, SIZE, NUM_STAGE, in_ptr, temp, isign); - - /* First, handle the DC and foldover frequencies */ - out_ptr[SIZE2] = sub(temp[0], temp[1]); - move16(); - out_ptr[0] = sub(add(temp[0], temp[1]), shr(NUM_STAGE, 1)); - move16();/* DC have a small offset */ - - ptrDn = &temp[SIZE-1]; - - ptImaDn = &out_ptr[SIZE-1]; - ptRealUp = &out_ptr[1]; - ptImaUp = &out_ptr[SIZE2+1]; - ptRealDn = &out_ptr[SIZE2-1]; - - /* Now, handle the remaining positive frequencies */ - FOR (i = 2; i <= SIZE2; i += 2) - { - Ltmp1_imag = L_mult(temp[i+1], 16384); - Ltmp1_imag = L_msu(Ltmp1_imag, *ptrDn, 16384); - tmp2_real = add(temp[i+1], *ptrDn--); - - Ltmp1_real = L_mult(temp[i], 16384); - Ltmp1_real = L_mac(Ltmp1_real, *ptrDn, 16384); - tmp2_imag = sub(*ptrDn--, temp[i]); - - - *ptRealUp++ = msu_r(L_mac(Ltmp1_real, tmp2_real, phs_tbl[i]), tmp2_imag, phs_tbl[i+1]); - move16(); - *ptImaDn-- = mac_r(L_mac(Ltmp1_imag, tmp2_imag, phs_tbl[i]), tmp2_real, phs_tbl[i+1]); - move16(); - Ltmp1 = L_mac(L_negate(Ltmp1_imag), tmp2_real, *phstbl_ptrDn); - Ltmp1_real = L_mac(Ltmp1_real, tmp2_imag, *phstbl_ptrDn--); - *ptImaUp++ = msu_r(Ltmp1, tmp2_imag, *phstbl_ptrDn); - move16(); - *ptRealDn-- = mac_r(Ltmp1_real, tmp2_real, *phstbl_ptrDn--); - move16(); - } - } - ELSE /* The ifFT part */ - { - const Word16 *ptRealUp, *ptRealDn, *ptImaUp, *ptImaDn; - - /* First, handle the DC and foldover frequencies */ - Ltmp1 = L_mult(in_ptr[0], 16384); - temp[0] = mac_r(Ltmp1, in_ptr[SIZE2], 16384); - move16(); - temp[1] = msu_r(Ltmp1, in_ptr[SIZE2], 16384); - move16(); - - ptrDn = &temp[SIZE-1]; - - /* Here we cast to Word16 * from a const Word16 *. */ - /* This is ok because we use these pointers for */ - /* reading only. This is just to avoid declaring a */ - /* bunch of 4 other pointer with const Word16 *. */ - ptImaDn = &in_ptr[SIZE-1]; - ptRealUp = &in_ptr[1]; - ptImaUp = &in_ptr[SIZE2+1]; - ptRealDn = &in_ptr[SIZE2-1]; - - /* Now, handle the remaining positive frequencies */ - FOR (i = 2; i <= SIZE2; i += 2) - { - Ltmp1_imag = L_mult(*ptImaDn, 16384); - Ltmp1_imag = L_msu(Ltmp1_imag, *ptImaUp, 16384); - tmp2_real = add(*ptImaDn--, *ptImaUp++); - Ltmp1_real = L_mult(*ptRealUp, 16384); - Ltmp1_real = L_mac(Ltmp1_real, *ptRealDn, 16384); - tmp2_imag = sub(*ptRealUp++, *ptRealDn--); - - - temp[i] = mac_r(L_msu(Ltmp1_real, tmp2_real, phs_tbl[i]), tmp2_imag, phs_tbl[i+1]); - move16(); - temp[i+1] = mac_r(L_mac(Ltmp1_imag, tmp2_imag, phs_tbl[i]), tmp2_real, phs_tbl[i+1]); - move16(); - Ltmp1 = L_mac(L_negate(Ltmp1_imag), tmp2_real, *phstbl_ptrDn); - Ltmp1_real = L_msu(Ltmp1_real, tmp2_imag, *phstbl_ptrDn--); - *ptrDn-- = msu_r(Ltmp1, tmp2_imag, *phstbl_ptrDn); - move16(); - *ptrDn-- = msu_r(Ltmp1_real, tmp2_real, *phstbl_ptrDn--); - move16(); - } - - /* Perform the complex ifFT */ - c_fft_fx(phs_tbl, SIZE, NUM_STAGE, temp, out_ptr, isign); - } -} diff --git a/src/libs/libevs/lib_com/fft_rel_sas_fx.cpp b/src/libs/libevs/lib_com/fft_rel_sas_fx.cpp deleted file mode 100755 index 43caf3f6..00000000 --- a/src/libs/libevs/lib_com/fft_rel_sas_fx.cpp +++ /dev/null @@ -1,456 +0,0 @@ -/*==================================================================================== - EVS Codec 3GPP TS26.442 Apr 03, 2018. Version 12.11.0 / 13.6.0 / 14.2.0 - ====================================================================================*/ - -#include "options.h" /* Compilation switches */ -#include "prot_fx.h" /* Function prototypes */ -#include "rom_com_fx.h" /* Static table prototypes */ -#include "prot_fx.h" /* Function prototypes */ -#include "stl.h" - -/*---------------------------------------------------------------------* - * Local constants - *---------------------------------------------------------------------*/ - -#define INV_SQR2_FX 23170 -#define N_MAX_SAS 256 - -/*---------------------------------------------------------------------* - * fft_rel_fx() - * - * Computes the split-radix FFT in place for the real-valued - * signal x of length n. The algorithm has been ported from - * the fortran code of [1]. - * - * The function needs sine and cosine tables t_sin and t_cos, - * and the constant N_MAX_SAS. The table entries are defined as - * sin(2*pi*i) and cos(2*pi*i) for i = 0, 1, ..., N_MAX_SAS-1. The - * implementation assumes that any entry will not be needed - * outside the tables. Therefore, N_MAX_SAS and n must be properly - * set. The function has been tested with the values n = 16, - * 32, 64, 128, 256, and N_MAX_SAS = 1280. - * - * References - * [1] H.V. Sorensen, D.L. Jones, M.T. Heideman, C.S. Burrus, - * "Real-valued fast Fourier transform algorithm," IEEE - * Trans. on Signal Processing, Vol.35, No.6, pp 849-863, - * 1987. - * - * OUTPUT - * x[0:n-1] Transform coeffients in the order re[0], re[1], - * ..., re[n/2], im[n/2-1], ..., im[1]. - *---------------------------------------------------------------------*/ -/*MERGE fft_rel_fx and fft_rel_fx_lc */ -void fft_rel_fx( - Word16 x[], /* i/o: input/output vector */ - const Word16 n, /* i : vector length */ - const Word16 m /* i : log2 of vector length */ -) -{ - Word16 i, j, k, n1, n2, n4; - Word16 step; - Word16 xt, t1, t2; - Word16 *x0, *x1, *x2; - const Word16 *s, *c; - Word16 *xi2, *xi3, *xi4, *xi1; - - - /*-----------------------------------------------------------------* - * Digit reverse counter - *-----------------------------------------------------------------*/ - - j = 0; - move16(); - x0 = &x[0]; - move16(); - FOR (i = 0; i < n-1; i++) - { - IF (sub(i,j) < 0) - { - xt = x[j]; - move16(); - x[j] = *x0; - move16(); - *x0 = xt; - move16(); - } - x0++; - k = shr(n,1); - WHILE (sub(k,j) <= 0) - { - j = sub(j,k); - k = shr(k,1); - } - j = add(j,k); - } - - /*-----------------------------------------------------------------* - * Length two butterflies - *-----------------------------------------------------------------*/ - - x0 = &x[0]; - move16(); - x1 = &x[1]; - move16(); - FOR (i = 0; i < n/2; i++) - { - xt = *x0; - move16(); - *x0 = add(xt,*x1); - move16(); - *x1 = sub(xt,*x1); - move16(); - x0++; - x0++; - x1++; - x1++; - } - - /*-----------------------------------------------------------------* - * Other butterflies - * - * The implementation described in [1] has been changed by using - * table lookup for evaluating sine and cosine functions. The - * variable ind and its increment step are needed to access table - * entries. Note that this implementation assumes n4 to be so - * small that ind will never exceed the table. Thus the input - * argument n and the constant N_MAX_SAS must be set properly. - *-----------------------------------------------------------------*/ - - n2 = 1; - move16(); - /* step = N_MAX_SAS/4; */ - FOR (k = 2; k <= m; k++) - { - n4 = n2; - move16(); - n2 = shl(n4,1); - n1 = shl(n2,1); - - step = N_MAX_SAS/n1; - - x0 = x; - x1 = x + n2; - x2 = x + add(n2, n4); - FOR (i = 0; i < n; i += n1) - { - xt = *x0; - move16(); /* xt = x[i]; */ - *x0 = add(xt,*x1); - move16(); /* x[i] = xt + x[i+n2]; */ - *x1 = sub(xt,*x1); - move16(); /* x[i+n2] = xt - x[i+n2]; */ - *x2 = negate(*x2); - move16(); /* x[i+n2+n4] = -x[i+n2+n4]; */ - - - s = sincos_t_fx + step; - c = s + 64; - xi1 = x + add(i, 1); - xi3 = xi1 + n2; - xi2 = xi3 - 2; - xi4 = xi1 + sub(n1, 2); - - FOR (j = 1; j < n4; j++) - { - t1 = add(mult_r(*xi3,*c),mult_r(*xi4,*s)); /* t1 = *xi3**(pt_c+ind) + *xi4**(pt_s+ind); */ - t2 = sub(mult_r(*xi3,*s),mult_r(*xi4,*c)); /* t2 = *xi3**(pt_s+ind) - *xi4**(pt_c+ind); */ - *xi4 = sub(*xi2,t2); - move16(); - *xi3 = negate(add(*xi2,t2)); - move16(); - *xi2 = sub(*xi1,t1); - move16(); - *xi1 = add(*xi1,t1); - move16(); - - xi4--; - xi2--; - xi3++; - xi1++; - c += step; - s += step; /* autoincrement by ar0 */ - } - - x0 += n1; - x1 += n1; - x2 += n1; - } - /* step = shr(step, 1); */ - } - - return; -} - -void ifft_rel_fx( - Word16 io[], /* i/o: input/output vector */ - const Word16 n, /* i : vector length */ - const Word16 m /* i : log2 of vector length */ -) -{ - Word16 i, j, k; - Word16 step; - Word16 n2, n4, n8, i0; - Word16 is, id; - Word16 *x,*xi0, *xi1, *xi2, *xi3, *xi4, *xup1, *xdn6, *xup3, *xdn8; - Word16 xt; - Word16 r1; - Word16 t1, t2, t3, t4, t5; - const Word16 *s, *c, *s3, *c3; - - Word16 cc1, cc3, ss1, ss3; - Word16 tmp; - - - /*-----------------------------------------------------------------* - * ifft - *-----------------------------------------------------------------*/ - - x = &io[-1]; - move16(); - n2 = shl(n,1); - FOR (k=1; k +#include +#include "options.h" +#include "cnst.h" +#include "rom_com.h" +#include "prot.h" + +/*--------------------------------------------------------------------------* + * fill_spectrum() + * + * Apply spectral filling by + * - filling zero-bit bands below BWE region + * - applying BWE above transition frequency + *--------------------------------------------------------------------------*/ + +void fill_spectrum( + float *coeff, /* i/o: normalized MLT spectrum / nf spectrum */ + short *R, /* i : number of pulses per band */ + const short is_transient, /* i : transient flag */ + short norm[], /* i : quantization indices for norms */ + const float *hq_generic_fenv, /* i : HQ GENERIC envelope */ + const short hq_generic_offset, /* i : HQ GENERIC offset */ + const short nf_idx, /* i : noise fill index */ + const short length, /* i : Length of spectrum (32 or 48 kHz) */ + const float env_stab, /* i : Envelope stability measure [0..1] */ + short *no_att_hangover, /* i/o: Frame counter for attenuation hangover */ + float *energy_lt, /* i/o: Long-term energy measure for transient detection */ + short *bwe_seed, /* i/o: random seed for generating BWE input */ + const short hq_generic_exc_clas, /* i : HQ generic hf excitation class */ + const short core_sfm, /* i : index of the end band for core */ + short HQ_mode, /* i : HQ mode */ + float noise_level[], /* i : noise levels for harmonic modes */ + long core_brate, /* i : target bit-rate */ + float prev_noise_level[], /* i/o: noise factor in previous frame */ + short *prev_R, /* i/o: bit allocation info. in previous frame */ + float *prev_coeff_out, /* i/o: decoded spectrum in previous frame */ + const short *peak_idx, /* i : HVQ peak indices */ + const short Npeaks, /* i : Number of HVQ peaks */ + const short *npulses, /* i : Number of assigned pulses per band */ + short prev_is_transient, /* i : previous transient flag */ + float *prev_normq, /* i : previous norms */ + float *prev_env, /* i : previous noise envelopes */ + short prev_bfi, /* i : previous bad frame indicator */ + const short *sfmsize, /* i : Length of bands */ + const short *sfm_start, /* i : Start of bands */ + const short *sfm_end, /* i : End of bands */ + short *prev_L_swb_norm, /* i/o: last normalize length for harmonic mode */ + short prev_hq_mode, /* i : previous HQ mode */ + const short num_sfm, /* i : Number of bands */ + const short num_env_bands /* i : Number of envelope bands */ +) +{ + float CodeBook[FREQ_LENGTH]; + short cb_size = 0; + short last_sfm; + float CodeBook_mod[FREQ_LENGTH]; + float norm_adj[NB_SFM]; + short high_sfm = 23; + short flag_32K_env_hangover; + short bin_th = 0; + short peak_pos[L_HARMONIC_EXC]; + short bwe_peaks[L_FRAME48k]; + float normq_v[NB_SFM]; + float coeff_fine[L_FRAME48k]; + float coeff_out[L_FRAME48k]; + + set_s( peak_pos, 0, L_HARMONIC_EXC ); + set_s( bwe_peaks, 0, L_FRAME48k ); + set_f( norm_adj, 1.0f, num_sfm ); + set_f( coeff_out, 0.0f, L_FRAME48k ); + + if ( HQ_mode == HQ_TRANSIENT ) + { + last_sfm = num_sfm-1; + } + else if (HQ_mode == HQ_GEN_SWB || HQ_mode == HQ_GEN_FB) + { + last_sfm = max(core_sfm,num_env_bands-1); + } + else + { + last_sfm = core_sfm; + } + + if ( HQ_mode == HQ_HARMONIC ) + { + high_sfm = (core_brate == HQ_24k40) ? HVQ_THRES_SFM_24k-1 : HVQ_THRES_SFM_32k-1; + if( last_sfm < high_sfm ) + { + last_sfm = high_sfm; + } + } + else if ( HQ_mode == HQ_HVQ ) + { + bin_th = sfm_end[last_sfm]; + } + + /* Transient analysis for envelope stability measure */ + if( length == L_FRAME32k ) + { + env_stab_transient_detect( is_transient, length, norm, no_att_hangover, energy_lt, HQ_mode, bin_th, coeff ); + } + + if ( length == L_FRAME16k || ((length == L_FRAME32k && HQ_mode != HQ_HARMONIC && HQ_mode != HQ_HVQ) && *no_att_hangover == 0) ) + { + /* Norm adjustment function */ + env_adj( npulses, length, last_sfm, norm_adj, env_stab, sfmsize ); + } + + flag_32K_env_hangover = ( length == L_FRAME32k && ( (env_stab < 0.5f && *no_att_hangover == 0) || HQ_mode == HQ_HVQ ) ); + + /*----------------------------------------------------------------* + * Build noise-fill codebook + *----------------------------------------------------------------*/ + + if ( HQ_mode != HQ_HVQ ) + { + cb_size = build_nf_codebook( flag_32K_env_hangover, coeff, sfm_start, sfmsize, sfm_end, last_sfm, R, CodeBook, CodeBook_mod ); + } + + /*----------------------------------------------------------------* + * Prepare fine structure for Harmonic and HVQ + *----------------------------------------------------------------*/ + + if ( HQ_mode == HQ_HARMONIC ) + { + harm_bwe_fine( R, last_sfm, high_sfm, num_sfm, norm, sfm_start, sfm_end, prev_L_swb_norm, coeff, coeff_out, coeff_fine ); + } + else if ( HQ_mode == HQ_HVQ ) + { + hvq_bwe_fine( last_sfm, num_sfm, sfm_end, peak_idx, Npeaks, peak_pos, prev_L_swb_norm, coeff, bwe_peaks, coeff_fine ); + } + + /*----------------------------------------------------------------* + * Apply noise-fill + *----------------------------------------------------------------*/ + + if( HQ_mode != HQ_HVQ && cb_size > 0 ) + { + apply_noisefill_HQ( R, length, flag_32K_env_hangover, core_brate, last_sfm, CodeBook, CodeBook_mod, cb_size, sfm_start, sfm_end, sfmsize, coeff ); + } + + /*----------------------------------------------------------------* + * Normal mode BWE + *----------------------------------------------------------------*/ + + if ( HQ_mode == HQ_NORMAL ) + { + hq_fold_bwe( last_sfm, sfm_end, num_sfm, coeff ); + } + + /*----------------------------------------------------------------* + * Apply noise-fill adjustment + *----------------------------------------------------------------*/ + + if( (length >= L_FRAME32k || core_brate > HQ_32k || core_brate < HQ_24k40) && HQ_mode != HQ_HVQ ) + { + apply_nf_gain( nf_idx, last_sfm, R, sfm_start, sfm_end, coeff ); + } + + /*----------------------------------------------------------------* + * Prepare fine strucutre for HQ GENERIC + *----------------------------------------------------------------*/ + if ( HQ_mode == HQ_GEN_SWB || HQ_mode == HQ_GEN_FB ) + { + hq_generic_fine( coeff, last_sfm, sfm_start, sfm_end, bwe_seed, coeff_fine ); + } + + /*----------------------------------------------------------------* + * Apply envelope + *----------------------------------------------------------------*/ + + if ( HQ_mode != HQ_HARMONIC && HQ_mode != HQ_HVQ ) + { + apply_envelope( coeff, norm, norm_adj, num_sfm, last_sfm, HQ_mode, length, sfm_start, sfm_end, normq_v, coeff_out, coeff_fine ); + } + + /*----------------------------------------------------------------* + * Harmonic BWE, HVQ BWE and HQ SWB BWE + *----------------------------------------------------------------*/ + + if( HQ_mode == HQ_HARMONIC ) + { + harm_bwe( coeff_fine, coeff, num_sfm, sfm_start, sfm_end, last_sfm, high_sfm, R, prev_hq_mode, norm, noise_level, prev_noise_level, bwe_seed, coeff_out ); + } + else if ( HQ_mode == HQ_HVQ ) + { + hvq_bwe( coeff, coeff_fine, sfm_start, sfm_end, sfmsize, last_sfm, + prev_hq_mode, bwe_peaks, bin_th, num_sfm, core_brate, R, norm, + noise_level, prev_noise_level, bwe_seed, coeff_out ); + } + else if ( HQ_mode == HQ_GEN_SWB || HQ_mode == HQ_GEN_FB ) + { + hq_generic_bwe( HQ_mode, coeff_fine, hq_generic_fenv, coeff_out, hq_generic_offset, prev_L_swb_norm, + hq_generic_exc_clas, sfm_end, num_sfm, num_env_bands, R ); + } + + /*----------------------------------------------------------------* + * HQ WB BWE refinements + *----------------------------------------------------------------*/ + + if( length == L_FRAME16k && core_brate == HQ_32k ) + { + hq_wb_nf_bwe( coeff, is_transient, prev_bfi, normq_v, num_sfm, sfm_start, sfm_end, sfmsize, last_sfm, R, + prev_is_transient, prev_normq, prev_env, bwe_seed, prev_coeff_out, prev_R, coeff_out ); + } + + /*----------------------------------------------------------------* + * Update memories + *----------------------------------------------------------------*/ + + if ( HQ_mode != HQ_HARMONIC && HQ_mode != HQ_HVQ ) + { + prev_noise_level[0] = 0.1f; + prev_noise_level[1] = 0.1f; + } + if ( !(length == L_FRAME16k && core_brate == HQ_32k ) ) + { + set_f( prev_env, 0, SFM_N_WB ); + set_f( prev_normq, 0, SFM_N_WB ); + } + + if ( length == L_FRAME32k && core_brate <= HQ_32k ) + { + *prev_R = R[SFM_N_WB-1]; + mvr2r( coeff_out + L_FRAME16k - L_HQ_WB_BWE, prev_coeff_out, L_HQ_WB_BWE ); + } + + mvr2r( coeff_out, coeff, L_FRAME48k ); + + return; +} diff --git a/src/libs/libevs/lib_com/fill_spectrum_fx.cpp b/src/libs/libevs/lib_com/fill_spectrum_fx.cpp deleted file mode 100755 index e8bc22a7..00000000 --- a/src/libs/libevs/lib_com/fill_spectrum_fx.cpp +++ /dev/null @@ -1,278 +0,0 @@ -/*==================================================================================== - EVS Codec 3GPP TS26.442 Apr 03, 2018. Version 12.11.0 / 13.6.0 / 14.2.0 - ====================================================================================*/ - -#include -#include "options.h" /* Compilation switches */ -#include "cnst_fx.h" /* Common constants */ -#include "prot_fx.h" /* Function prototypes */ -#include "stl.h" /* required for wmc_tool */ - -/*--------------------------------------------------------------------------* - * fill_spectrum() - * - * Apply spectral filling by - * - filling zero-bit bands below BWE region - * - applying BWE above transition frequency - *--------------------------------------------------------------------------*/ - -void fill_spectrum_fx( - Word16 *coeff, /* i/o: normalized MLT spectrum / nf spectrum Q12 */ - Word32 *L_coeff_out, /* i/o: Noisefilled MLT spectrum Q12 */ - const Word16 *R, /* i : number of pulses per band Q0 */ - const Word16 is_transient, /* i : transient flag Q0 */ - Word16 norm[], /* i : quantization indices for norms Q0 */ - const Word16 *hq_generic_fenv, /* i : HQ GENERIC envelope Q1 */ - const Word16 hq_generic_offset, /* i : HQ GENERIC offset Q0 */ - const Word16 nf_idx, /* i : noise fill index Q0 */ - const Word16 length, /* i : Length of spectrum (32 or 48 kHz) Q0 */ - const Word16 env_stab, /* i : Envelope stability measure [0..1] Q15 */ - Word16 *no_att_hangover, /* i/o: Frame counter for attenuation hangover Q0 */ - Word32 *L_energy_lt, /* i/o: Long-term energy measure for transient detection Q13 */ - Word16 *bwe_seed, /* i/o: random seed for generating BWE input Q0 */ - const Word16 hq_generic_exc_clas, /* i : BWE excitation class Q0 */ - const Word16 core_sfm, /* i : index of the end band for core Q0 */ - const Word16 HQ_mode, /* i : HQ mode Q0 */ - Word16 noise_level[], /* i : noise levels for harmonic modes Q15 */ - const Word32 L_core_brate, /* i : target bit-rate Q0 */ - Word16 prev_noise_level[], /* i/o: noise factor in previous frame Q15 */ - Word16 *prev_R, /* i/o: bit allocation info. in previous frame Q0 */ - Word32 *prev_coeff_out, /* i/o: decoded spectrum in previous frame Q12 */ - const Word16 *peak_idx, /* i : peak indices for hvq Q0 */ - const Word16 Npeaks, /* i : number of peaks in hvq Q0 */ - const Word16 *npulses, /* i : number of pulses per band Q0 */ - const Word16 prev_is_transient, /* i : previous transient flag Q0 */ - Word32 *prev_normq, /* i/o: previous norms Q14 */ - Word32 *prev_env, /* i/o: previous noise envelopes Q(prev_env_Q) */ - const Word16 prev_bfi, /* i : previous bad frame indicator Q0 */ - const Word16 *sfmsize, /* i : Length of bands Q0 */ - const Word16 *sfm_start, /* i : Start of bands Q0 */ - const Word16 *sfm_end, /* i : End of bands Q0 */ - Word16 *prev_L_swb_norm, /* i/o: HVQ/Harmonic mode normalization length Q0 */ - const Word16 prev_hq_mode, /* i : Previous HQ mode Q0 */ - const Word16 num_sfm /* i : Total number of bands Q0 */ - ,Word16 *prev_env_Q - ,const Word16 num_env_bands /* i : Number sub bands to be encoded for HQ_GEN Q0 */ -) -{ - Word16 CodeBook[FREQ_LENGTH]; /* Q12 */ - Word16 cb_size; - Word16 last_sfm; - Word16 CodeBook_mod[FREQ_LENGTH]; /*Q12 */ - Word16 norm_adj[NB_SFM]; /*Q15 */ - Word16 high_sfm; - Word16 flag_32K_env_hangover; - Word16 bin_th; - Word16 peak_pos[L_HARMONIC_EXC]; - Word16 bwe_peaks[L_FRAME48k]; - Word32 L_normq_v[NB_SFM]; /*Q14 */ - Word16 coeff_fine[L_FRAME48k]; /*Q15 */ - Word32 L_coeff_out1[L_FRAME48k]; /*Q12 */ - - set16_fx( peak_pos, 0, L_HARMONIC_EXC ); - set16_fx( bwe_peaks, 0, L_FRAME48k ); - set16_fx(norm_adj, 32767, num_sfm); /* 1.0, Q15 */ - cb_size = 0; - move16(); - bin_th = 0; - move16(); - high_sfm = 23; - move16(); - - test(); - IF ( sub(HQ_mode, HQ_TRANSIENT) == 0 ) - { - last_sfm = sub(num_sfm, 1); - } - ELSE IF ( sub(HQ_mode,HQ_GEN_SWB) == 0 || sub(HQ_mode,HQ_GEN_FB) == 0 ) - { - last_sfm = s_max(core_sfm,sub(num_env_bands,1)); - } - ELSE - { - last_sfm = core_sfm; - move16(); - } - - IF ( sub(HQ_mode, HQ_HARMONIC) == 0 ) - { - /*high_sfm = (core_brate == HQ_24k40) ? HVQ_THRES_SFM_24k-1 : HVQ_THRES_SFM_32k-3; */ - high_sfm = sub(HVQ_THRES_SFM_32k, 1); - if (L_sub(L_core_brate, HQ_24k40) == 0) - { - high_sfm = sub(HVQ_THRES_SFM_24k, 1); - } - - if( sub(last_sfm, high_sfm) < 0 ) - { - last_sfm = high_sfm; - move16(); - } - } - ELSE if ( sub(HQ_mode, HQ_HVQ) == 0 ) - { - bin_th = sfm_end[last_sfm]; - move16(); - } - - /* Transient analysis for envelope stability measure */ - IF ( sub(length, L_FRAME32k) == 0 ) - { - env_stab_transient_detect_fx( is_transient, length, norm, no_att_hangover, L_energy_lt, HQ_mode, bin_th, L_coeff_out, 12 ); - } - - test(); - test(); - test(); - test(); - IF ( sub(length, L_FRAME16k) == 0 || - ((sub(length, L_FRAME32k) == 0 && sub(HQ_mode, HQ_HARMONIC) != 0 && sub(HQ_mode, HQ_HVQ) != 0) && *no_att_hangover == 0) ) - { - /* Norm adjustment function */ - env_adj_fx( npulses, length, last_sfm, norm_adj, env_stab, sfmsize ); - } - - /*flag_32K_env_hangover = ( length == L_FRAME32k && ( (env_stab < 0.5f && *no_att_hangover == 0) || HQ_mode == HQ_HVQ ) ); */ - flag_32K_env_hangover = 0; - move16(); - test(); - test(); - test(); - if ( sub(length, L_FRAME32k) == 0 && ( (sub(env_stab, 16384) < 0 && *no_att_hangover == 0) || sub(HQ_mode, HQ_HVQ) == 0 ) ) - { - flag_32K_env_hangover = 1; - move16(); - } - - - /*----------------------------------------------------------------* - * Build noise-fill codebook - *----------------------------------------------------------------*/ - - IF ( sub(HQ_mode, HQ_HVQ) != 0 ) - { - cb_size = build_nf_codebook_fx(flag_32K_env_hangover, coeff, sfm_start, sfmsize, sfm_end, last_sfm, R, CodeBook, CodeBook_mod); - } - /*----------------------------------------------------------------* - * Prepare fine structure for Harmonic and HVQ - *----------------------------------------------------------------*/ - - IF ( sub(HQ_mode, HQ_HARMONIC) == 0 ) - { - harm_bwe_fine_fx( R, last_sfm, high_sfm, num_sfm, norm, sfm_start, sfm_end, prev_L_swb_norm, coeff, L_coeff_out, coeff_fine ); - } - ELSE IF ( sub(HQ_mode, HQ_HVQ) == 0 ) - { - hvq_bwe_fine_fx( last_sfm, num_sfm, sfm_end, peak_idx, Npeaks, peak_pos, prev_L_swb_norm, L_coeff_out, bwe_peaks, coeff_fine ); - } - - /*----------------------------------------------------------------* - * Apply noise-fill - *----------------------------------------------------------------*/ - - test(); - IF ( sub(HQ_mode, HQ_HVQ) != 0 && cb_size > 0 ) - { - apply_noisefill_HQ_fx( R, length, flag_32K_env_hangover, L_core_brate, last_sfm, CodeBook, - CodeBook_mod, cb_size, sfm_start, sfm_end, sfmsize, coeff ); - } - - /*----------------------------------------------------------------* - * Normal mode BWE - *----------------------------------------------------------------*/ - - IF ( HQ_mode == HQ_NORMAL ) - { - hq_fold_bwe_fx(last_sfm, sfm_end, num_sfm, coeff); - } - - /*----------------------------------------------------------------* - * Apply noise-fill adjustment - *----------------------------------------------------------------*/ - - test(); - test(); - test(); - IF( (sub(length, L_FRAME32k) >= 0 || L_sub(L_core_brate, HQ_32k) > 0 || L_sub(L_core_brate, HQ_24k40) < 0) - && sub(HQ_mode, HQ_HVQ) != 0 ) - { - apply_nf_gain_fx(nf_idx, last_sfm, R, sfm_start, sfm_end, coeff); - } - - /*----------------------------------------------------------------* - * Prepare fine strucutre for HQ GENERIC - *----------------------------------------------------------------*/ - test(); - IF ( sub(HQ_mode, HQ_GEN_SWB) == 0 || sub(HQ_mode, HQ_GEN_FB) == 0 ) - { - hq_generic_fine_fx( coeff, last_sfm, sfm_start, sfm_end, bwe_seed, coeff_fine ); - } - - /*----------------------------------------------------------------* - * Apply envelope - *----------------------------------------------------------------*/ - - test(); - IF ( sub(HQ_mode, HQ_HARMONIC) != 0 && sub(HQ_mode, HQ_HVQ) != 0 ) - { - apply_envelope_fx( coeff, norm, norm_adj, num_sfm, last_sfm, HQ_mode, length, sfm_start, sfm_end, - L_normq_v, L_coeff_out, coeff_fine, L_coeff_out1 ); - } - - /*----------------------------------------------------------------* - * Harmonic BWE, HVQ BWE and HQ SWB BWE - *----------------------------------------------------------------*/ - test(); - IF ( sub(HQ_mode, HQ_HARMONIC) == 0 ) - { - harm_bwe_fx( coeff_fine, coeff, num_sfm, sfm_start, sfm_end, last_sfm, R, prev_hq_mode, norm, noise_level, prev_noise_level, bwe_seed, L_coeff_out ); - } - ELSE IF ( sub(HQ_mode, HQ_HVQ) == 0 ) - { - hvq_bwe_fx( L_coeff_out, coeff_fine, sfm_start, sfm_end, sfmsize, last_sfm, - prev_hq_mode, bwe_peaks, bin_th, num_sfm, L_core_brate, R, norm, - noise_level, prev_noise_level, bwe_seed, L_coeff_out, 15, 12 ); - } - ELSE IF ( sub(HQ_mode, HQ_GEN_SWB) == 0 || sub(HQ_mode, HQ_GEN_FB) == 0 ) - { - hq_bwe_fx( HQ_mode, L_coeff_out1, hq_generic_fenv, L_coeff_out, hq_generic_offset, prev_L_swb_norm, hq_generic_exc_clas, sfm_end, num_sfm, num_env_bands, R ); - } - - /*----------------------------------------------------------------* - * HQ WB BWE refinements - *----------------------------------------------------------------*/ - test(); - IF ( sub(length, L_FRAME16k) == 0 && L_sub(L_core_brate, HQ_32k) == 0 ) - { - hq_wb_nf_bwe_fx( coeff, is_transient, prev_bfi, L_normq_v, num_sfm, sfm_start, sfm_end, sfmsize, last_sfm, R, - prev_is_transient, prev_normq, prev_env, bwe_seed, prev_coeff_out, prev_R, L_coeff_out, prev_env_Q ); - } - - /*----------------------------------------------------------------* - * Update memories - *----------------------------------------------------------------*/ - - test(); - IF ( sub(HQ_mode, HQ_HARMONIC) != 0 && sub(HQ_mode, HQ_HVQ) != 0 ) - { - prev_noise_level[0] = 3277; - move16();/* 0.1 in Q15 */ - prev_noise_level[1] = 3277; - move16();/* 0.1 in Q15 */ - } - test(); - IF ( !(sub(length, L_FRAME16k) == 0 && L_sub(L_core_brate, HQ_32k) == 0) ) - { - set32_fx( prev_env, 0, SFM_N_WB ); - set32_fx( prev_normq, 0, SFM_N_WB ); - } - - test(); - IF ( sub(length, L_FRAME32k) == 0 && L_sub(L_core_brate, HQ_32k) <= 0 ) - { - *prev_R = R[SFM_N_WB-1]; - Copy32( L_coeff_out + L_FRAME16k - L_HQ_WB_BWE, prev_coeff_out, L_HQ_WB_BWE ); - } - - return; -} diff --git a/src/libs/libevs/lib_com/findpulse.cpp b/src/libs/libevs/lib_com/findpulse.cpp new file mode 100644 index 00000000..9d410796 --- /dev/null +++ b/src/libs/libevs/lib_com/findpulse.cpp @@ -0,0 +1,106 @@ +/*==================================================================================== + EVS Codec 3GPP TS26.443 Nov 13, 2018. Version 12.11.0 / 13.7.0 / 14.3.0 / 15.1.0 + ====================================================================================*/ + +#include +#include "options.h" +#include "prot.h" +#include "cnst.h" + + +/*----------------------------------------------------------------------------------* + * findpulse() + * + * Find first pitch pulse in a frame + *----------------------------------------------------------------------------------*/ + +short findpulse( /* o : pulse position */ + const short L_frame, /* i : length of the frame */ + const float res[], /* i : residual signal */ + const short T0, /* i : integer pitch */ + const short enc_dec, /* i : flag enc/dec, 0 - enc, 1 - dec */ + short *sign /* i/o: sign of the maximum */ +) +{ + const float *ptr; + float val, maxval; + short i, maxi; + float resf[L_FRAME16k]; /* Low pass filtered residual */ + + if ( enc_dec == ENC ) + { + /*-----------------------------------------------------------------* + * Very simple LP filter + *-----------------------------------------------------------------*/ + + resf[0] = 0.50f * res[0] + 0.25f * res[1]; + for (i=1; imaxval) + { + maxval = val; + maxi = i; + if(*ptr >= 0) + { + *sign = 0; + } + else + { + *sign = 1; + } + } + ptr--; + } + } + else + { + /*-----------------------------------------------------------------* + * Find "biggest" pulse in the last pitch section according to the sign + *-----------------------------------------------------------------*/ + + ptr = res; + maxval = 0; + maxi = 0; + + if( *sign == 0 ) + { + for (i=1; i<=T0; i++) + { + val = *ptr++; + if ( val >= maxval ) + { + maxval = val; + maxi = i; + } + } + } + else + { + for (i=1; i<=T0; i++) + { + val = *ptr++; + if (val<=maxval) + { + maxval = val; + maxi = i; + } + } + } + } + + return(maxi); +} diff --git a/src/libs/libevs/lib_com/findpulse_fx.cpp b/src/libs/libevs/lib_com/findpulse_fx.cpp deleted file mode 100755 index 6c60ddf4..00000000 --- a/src/libs/libevs/lib_com/findpulse_fx.cpp +++ /dev/null @@ -1,117 +0,0 @@ -/*==================================================================================== - EVS Codec 3GPP TS26.442 Apr 03, 2018. Version 12.11.0 / 13.6.0 / 14.2.0 - ====================================================================================*/ - -#include "options.h" /* Compilation switches */ -#include "cnst_fx.h" /* Common constants */ -#include "prot_fx.h" /* Function prototypes */ -#include "stl.h" - -/*----------------------------------------------------------------------------------* - * findpulse() - * - * Find first pitch pulse in a frame - *----------------------------------------------------------------------------------*/ -Word16 findpulse_fx( /* o : pulse position */ - const Word16 L_frame, /* i : length of the frame */ - const Word16 res[], /* i : Residual signal <12 bits */ - const Word16 T0, /* i : Pitch estimation Q0 */ - const Word16 enc, /* i : enc = 1 -> encoder side; enc = 0 -> decoder side */ - Word16 *sign /* i/o: sign of the maximum */ -) -{ - const Word16 *ptr; - Word16 maxval; - Word16 i, maxi; - Word32 Ltmp; - Word16 resf[L_FRAME16k]; /* Low pass filtered residual */ - - IF (enc != DEC) - { - /*------------------------------------------------------------------------* - * 1. Very simple LP filter - *------------------------------------------------------------------------*/ - - /* resf[0] = 0.50f * res[0] + 0.25f * res[1] */ - Ltmp = L_mult(res[0], 16384); - resf[0] = mac_r(Ltmp, res[1], 8192); - move16(); - FOR (i=1; i= 0) - { - *sign = 0; move16(); - }*/ - *sign = negate(shr(ptr[-maxi], 15)); - move16(); - } - ELSE - { - /*-----------------------------------------------------------------* - * 2. Find "biggest" pulse in the last pitch section according to the sign - *-----------------------------------------------------------------*/ - - maxval = 0; - move16(); - maxi = 0; - move16(); - - IF (*sign == 0) - { - FOR (i = 0; i < T0; i++) - { - if (sub(res[i], maxval) >= 0) - { - maxi = add(i, 1); - } - maxval = s_max(res[i], maxval); - } - } - ELSE - { - FOR (i = 0; i < T0; i++) - { - if (sub(res[i], maxval) <= 0) - { - maxi = add(i, 1); - } - maxval = s_min(res[i], maxval); - } - } - } - - return maxi; -} diff --git a/src/libs/libevs/lib_com/fine_gain_bits.cpp b/src/libs/libevs/lib_com/fine_gain_bits.cpp new file mode 100644 index 00000000..03ecaead --- /dev/null +++ b/src/libs/libevs/lib_com/fine_gain_bits.cpp @@ -0,0 +1,100 @@ +/*==================================================================================== + EVS Codec 3GPP TS26.443 Nov 13, 2018. Version 12.11.0 / 13.7.0 / 14.3.0 / 15.1.0 + ====================================================================================*/ + +#include "options.h" +#include "rom_com.h" +#include "prot.h" + + +/*-------------------------------------------------------------------------- + * subband_gain_bits() + * + * HQ core encoder + *--------------------------------------------------------------------------*/ + +void subband_gain_bits( + const short *Rk, /* i : bit allocation per band (Q3)*/ + const short N, /* i : number of bands */ + short *bits, /* o : gain bits per band */ + const short *sfmsize /* i : Size of bands */ +) +{ + short i,b,tot; + short bps; + + tot = 0; + + for ( i = 0; i < N; i++ ) + { + bps = (short)(((int) Rk[i]*(int)fg_inv_tbl_fx[sfmsize[i]>>3])>>18) ; + if (((sfmsize[i]*(bps+1)) << 3) - Rk[i] == 0) + { + /* correct approx. division result, to obtain exact integer division output */ + bps++; + } + bps = min(7, bps); + + + + b = fine_gain_bits[bps]; + + bits[i] = b; + tot += b; + } + + if ( tot == 0) + { + /* If no gain bits were assigned, use one bit anyway for potential PVQ overage */ + bits[0] = 1; + } + + return; +} + +/*--------------------------------------------------------------------------* + * assign_gain_bits() + * + * Assign gain adjustment bits and update bit budget + *--------------------------------------------------------------------------*/ + +short assign_gain_bits( /* o : Number of assigned gain bits */ + const short core, /* i : HQ core */ + const short BANDS, /* i : Number of bands */ + const short *band_width, /* i : Sub band bandwidth */ + short *Rk, /* i/o: Bit allocation/Adjusted bit alloc. (Q3)*/ + short *gain_bits_array, /* o : Assigned gain bits */ + short *Rcalc /* o : Bit budget for shape quantizer (Q3)*/ +) +{ + short subband_cnt; + short gain_bits_tot; + short i; + + /* Allocate gain bits for every subband used, based on bit rate and bandwidth */ + if( core == HQ_CORE ) + { + subband_gain_bits(Rk, BANDS, gain_bits_array, band_width); + } + else + { + set_s( gain_bits_array, 0, BANDS ); + } + + /* Re-adjust bit budget for gain quantization */ + subband_cnt = 0; + gain_bits_tot = 0; + *Rcalc = 0.0f; + for (i = 0; i < BANDS; i++) + { + if (Rk[i] > 0) + { + subband_cnt++; + Rk[i] -= gain_bits_array[i] * 8; + gain_bits_tot += gain_bits_array[i]; + *Rcalc += Rk[i]; + } + } + + return gain_bits_tot; +} diff --git a/src/libs/libevs/lib_com/fine_gain_bits_fx.cpp b/src/libs/libevs/lib_com/fine_gain_bits_fx.cpp deleted file mode 100755 index 18d544b5..00000000 --- a/src/libs/libevs/lib_com/fine_gain_bits_fx.cpp +++ /dev/null @@ -1,107 +0,0 @@ -/*==================================================================================== - EVS Codec 3GPP TS26.442 Apr 03, 2018. Version 12.11.0 / 13.6.0 / 14.2.0 - ====================================================================================*/ - -#include "options.h" /* Compilation switches */ -#include "rom_com_fx.h" /* Static table prototypes */ -#include "prot_fx.h" /* Function prototypes */ -#include "stl.h" /* required for wmc_tool */ - - -/*-------------------------------------------------------------------------- - * subband_gain_bits() - * - * HQ core encoder - *--------------------------------------------------------------------------*/ - -void subband_gain_bits_fx( - const Word16 *Rk, /* i : bit allocation per band Q3 */ - const Word16 N, /* i : number of bands */ - Word16 *bits, /* o : gain bits per band */ - const Word16 *sfmsize /* i : Size of bands */ -) -{ - Word16 i,b,tot; - Word16 bps; - - tot = 0; - move16(); - - FOR ( i = 0; i < N; i++ ) - { - /*bps = (short)(Rk[i]*((word16)min(32767, ceil(32767.0f/sfmsize[i]); inexact C-integer division approx. */ - bps = extract_l(L_shr(L_mult0(Rk[i], inv_tbl_fx[sfmsize[i]]), 18)); /* 3+15 */ - if (L_sub(L_shl(L_mult0(sfmsize[i], add(bps, 1)), 3), Rk[i]) == 0) - { - bps = add(bps, 1); - } - - bps = s_min(7, bps); - b = fine_gain_bits[bps]; - move16(); - bits[i] = b; - move16(); - tot = add(tot, b); - } - - if ( tot == 0) - { - /* If no gain bits were assigned, use one bit anyway for potential PVQ overage */ - bits[0] = 1; - move16(); - } - - return; -} - -/*--------------------------------------------------------------------------* - * assign_gain_bits() - * - * Assign gain adjustment bits and update bit budget - *--------------------------------------------------------------------------*/ - -Word16 assign_gain_bits_fx( /* o : Number of assigned gain bits */ - const Word16 core, /* i : HQ core */ - const Word16 BANDS, /* i : Number of bands */ - const Word16 *band_width, /* i : Sub band bandwidth */ - Word16 *Rk, /* i/o: Bit allocation/Adjusted bit alloc. Q3 */ - Word16 *gain_bits_array, /* o : Assigned gain bits */ - Word16 *Rcalc /* o : Bit budget for shape quantizer Q3 */ -) -{ - Word16 subband_cnt; - Word16 gain_bits_tot; - Word16 i; - - /* Allocate gain bits for every subband used, based on bit rate and bandwidth */ - IF( sub(core, HQ_CORE) == 0 ) - { - subband_gain_bits_fx(Rk, BANDS, gain_bits_array, band_width); - } - ELSE - { - set16_fx( gain_bits_array, 0, BANDS ); - } - - /* Re-adjust bit budget for gain quantization */ - subband_cnt = 0; - move16(); - gain_bits_tot = 0; - move16(); - *Rcalc = 0; - move16(); - FOR (i = 0; i < BANDS; i++) - { - IF (Rk[i] > 0) - { - subband_cnt = add(subband_cnt, 1); - Rk[i] = sub(Rk[i], shl(gain_bits_array[i], 3)); - move16(); - gain_bits_tot = add(gain_bits_tot, gain_bits_array[i]); - *Rcalc = add(*Rcalc, Rk[i]); - move16(); - } - } - - return gain_bits_tot; -} diff --git a/src/libs/libevs/lib_com/frame_ener.cpp b/src/libs/libevs/lib_com/frame_ener.cpp new file mode 100644 index 00000000..aadd7544 --- /dev/null +++ b/src/libs/libevs/lib_com/frame_ener.cpp @@ -0,0 +1,96 @@ +/*==================================================================================== + EVS Codec 3GPP TS26.443 Nov 13, 2018. Version 12.11.0 / 13.7.0 / 14.3.0 / 15.1.0 + ====================================================================================*/ + +#include +#include "options.h" +#include "cnst.h" +#include "prot.h" + + +/*----------------------------------------------------------------------------------* +* fer_energy() +* +* Estimation of pitch-synchronous (voiced sounds) or half-frame energy +*----------------------------------------------------------------------------------*/ + +void fer_energy( + const int L_frame, /* i : frame length */ + const short clas, /* i : frame classification */ + const float *synth, /* i : synthesized speech at Fs = 12k8 Hz */ + const float pitch, /* i : pitch period */ + float *enr, /* o : pitch-synchronous or half_frame energy */ + const short offset /* i : speech pointer offset (0 or L_frame) */ +) +{ + short len; + const float *pt_synth; + + if( clas == VOICED_CLAS || clas == ONSET || clas == SIN_ONSET ) /* Voiced or Onset current frame */ + { + len = (short)( pitch + 0.5f ); /* pitch value */ + + pt_synth = synth; + if( offset != 0 ) + { + pt_synth = synth + L_frame - len; + } + + emaximum( pt_synth, len, enr ); /* pitch synchronous E */ + } + else + { + pt_synth = synth; + if( offset != 0 ) + { + pt_synth = synth + L_frame/2; + } + + *enr = dotp( pt_synth, pt_synth, L_frame/2 ); + *enr /= (float)(L_frame/2); + + } + return; +} + + +/*------------------------------------------------------------------------* + * frame_energy() + * + * Compute pitch-synchronous energy at the frame end + *------------------------------------------------------------------------*/ + +float frame_energy( + const short L_frame, /* i: length of the frame */ + const float *pitch, /* i: pitch values for each subframe */ + const float *speech, /* i: pointer to speech signal for E computation */ + const float lp_speech, /* i: long-term active speech energy average */ + float *frame_ener /* o: pitch-synchronous energy at frame end */ +) +{ + float enern; + const float *pt1; + short len; + float dotProd; + + len = (short)( 0.5f * (pitch[2] + pitch[3]) + 0.5f ); + if( len < L_SUBFR ) + { + len *= 2; + } + + pt1 = speech + L_frame - len; + + dotProd = dotp( pt1, pt1, len ); + if ( 0 == dotProd ) + { + *frame_ener = MIN_LOG_VAL_60dB; + } + else + { + *frame_ener = 10.0f * (float) log10( dotProd / (float) len ); + } + enern = *frame_ener - lp_speech; + + return enern; +} diff --git a/src/libs/libevs/lib_com/frame_ener_fx.cpp b/src/libs/libevs/lib_com/frame_ener_fx.cpp deleted file mode 100755 index a4e2f675..00000000 --- a/src/libs/libevs/lib_com/frame_ener_fx.cpp +++ /dev/null @@ -1,196 +0,0 @@ -/*==================================================================================== - EVS Codec 3GPP TS26.442 Apr 03, 2018. Version 12.11.0 / 13.6.0 / 14.2.0 - ====================================================================================*/ - -#include -#include "options.h" /* Compilation switches */ -#include "cnst_fx.h" /* Common constants */ -#include "prot_fx.h" /* Function prototypes */ -#include "stl.h" - -/*----------------------------------------------------------------------------------* - * frame_ener() - * - * Estimation of pitch-synchronous (voiced) or mean half-frame (unvoiced) energy - *----------------------------------------------------------------------------------*/ -Word16 frame_ener_fx( - const Word16 L_frame, /* i : length of the frame */ - const Word16 clas, /* i : frame classification */ - const Word16 *synth, /* i : synthesized speech at Fs = 12k8 Hz Q_new */ - const Word16 pitch, /* i : pitch period Q0 */ - Word32 *enr_q, /* o : pitch-synchronous or half_frame energy Q0 */ - const Word16 offset, /* i : speech pointer offset (0 or L_FRAME) */ - const Word16 Q_new, /* i : Scaling factor */ - Word16 shift, /* i : Shift need to obtain 12 bits vectors */ - const Word16 enc /* i : Encoder/decoder */ -) -{ - Word16 len, exp_enrq, exp_tmp, pos; - Word16 i; - const Word16 *pt_synth; - Word32 Ltmp; - - exp_enrq = 0; - move16(); - test(); - test(); - IF( (sub(clas, VOICED_CLAS) == 0) || (sub(clas, ONSET) == 0) || (sub(clas, SIN_ONSET) == 0) ) /* current frame is voiced */ - { - /* current frame is voiced */ - len = pitch; - move16(); /* pitch value at the end of frame */ - pt_synth = synth; - move16(); - if (offset != 0) - { - pt_synth = synth + sub(L_frame, len); - } - emaximum_fx(Q_new, pt_synth, len, enr_q); - move16();/* pitch synchronous E */ - IF (enc != 0) - { - exp_enrq = norm_l(*enr_q); - *enr_q = L_shl(*enr_q, exp_enrq); - move32(); - exp_enrq = sub(exp_enrq, 2); - } - } - ELSE - { - /* current frame is unvoiced */ - Word16 L_frame2, exp2, enr_q_tmp; - - L_frame2 = shr(L_frame,1); - pos = 0; - move16(); - - if (offset != 0) - { - pos = sub(L_frame, L_frame2); - } - Ltmp = L_mult(synth[pos], synth[pos]); - FOR (i = 1; i < L_frame2; i++) - { - Ltmp = L_mac(Ltmp, synth[pos+i], synth[pos+i]); - } - test(); - IF (L_sub(Ltmp, MAX_32) == 0 || enc != 0) - { - /* scale down when overflow occurs */ - *enr_q = Energy_scale(synth+pos, L_frame2, shift, &exp_enrq); - move32(); - } - ELSE - { - shift = 0; - move16(); - /* Normalize acc in Q31 (energy already calculated) */ - pos = norm_l(Ltmp); - Ltmp = L_shl(Ltmp, pos); - exp_enrq = sub(30, pos); /* exponent = 0..30 */ - *enr_q = Ltmp; - move32(); - } - - /* enr2 = 1.0f/L_FRAME2 * dot_product(synth, synth, L_FRAME2) */ - exp_enrq = sub(exp_enrq, shl(shift, 1)); - - IF (enc != 0) - { - assert(L_frame == 256 || L_frame == 320); - - exp_tmp = add(shl(Q_new, 1), -2+7); /* L_subfr == L_SUBFR */ - exp_enrq = sub(exp_enrq, exp_tmp); - exp_enrq = sub(31, exp_enrq); - - IF(sub(L_frame, 320) == 0) - { - *enr_q = Mult_32_16(*enr_q, 26214); /*x 0.8 to get /160*/ - i = norm_l(*enr_q); - *enr_q = L_shl(*enr_q, i); - exp_enrq = add(i, exp_enrq); - } - } - ELSE - { - exp_enrq = sub(exp_enrq, add(Q_new, Q_new)); - enr_q_tmp /*Q30 exp2+exp_enrq*/ = BASOP_Util_Divide3216_Scale(*enr_q /*Q31*/, L_frame2 /*Q0*/, &exp2); - *enr_q = L_shr(L_deposit_l(enr_q_tmp),sub(30,add(exp2,exp_enrq))); /*Q0*/ - *enr_q = L_add(*enr_q, 1); - move32(); - exp_enrq = 0; - move16(); - } - - - - - - - } - - return exp_enrq; -} - -/*------------------------------------------------------------------------* - * frame_energy() - * - * Compute pitch-synchronous energy at the frame end - *------------------------------------------------------------------------*/ -Word16 frame_energy_fx( /* o : Frame energy in Q8 */ - Word16 L_frame, - const Word16 *pitch, /* i : pitch values for each subframe Q6 */ - const Word16 *speech, /* i : pointer to speech signal for E computation Q_syn*/ - const Word16 lp_speech, /* i : long term active speech energy average Q8 */ - Word16 *frame_ener, /* o : pitch-synchronous energy at frame end Q8 */ - const Word16 Q_syn /* i : Synthesis scaling */ -) -{ - Word32 Ltmp; - const Word16 *pt1; - Word16 tmp16, exp1, exp2, tmp1, tmp2; - Word16 len, enern; - - /* len = (0.5f * (pitch[2]/64.0 + pitch[3]/64.0) + 0.5f) */ - len = mult_r(add(pitch[2], pitch[3]), 256); - - if(sub(len,L_SUBFR) < 0 ) - { - len = shl(len, 1); - } - pt1 = speech + sub(L_frame,len); - - /* *frame_ener = 10.0f * log10(dot_product(pt1, pt1, len) / (float)len) */ - - tmp1 = norm_s(len); - tmp2 = shl(len, tmp1); - tmp1 = sub(15, tmp1); - - Ltmp = Dot_productSq16HQ( 0, pt1, len, &exp1); - exp1 = sub(exp1, shl(Q_syn, 1)); - exp1 = sub(exp1, 1); /* compensation of leftshift caused by mac operation in dot_productSq16HQ */ - tmp16 = BASOP_Util_Divide3216_Scale( Ltmp, len, &exp2); - - exp1 = add(exp1, exp2); - exp1 = add(exp1, 1); /* compensate result of division Q-1 */ - - - tmp2 = norm_s(tmp16); - Ltmp = L_shl(L_deposit_h(tmp16),tmp2); /*Q16, (exp1-tmp2) = Q31, exp1-tmp2+15*/ - - Ltmp = BASOP_Util_Log2(Ltmp);/*Q(31-6) = Q25*/ - exp1 = sub(15+exp1,tmp2); - - /*add ld(2^exp1)=exp1 but check format, first*/ - tmp16=sub(sub(15,norm_s(exp1)),5); /*factor to shift Ltmp and exp1 with (shr) to avoid overflows when adding*/ - Ltmp= L_shr(Ltmp,tmp16); /*Q25, tmp16*/ - exp2 = shr(exp1,tmp16); /*Q0 , tmp16*/ - Ltmp = L_add(Ltmp,L_shl(L_deposit_l(exp2),25)); /*Q25, tmp16, normalized*/ - - /*make 10*log10 out of log2*/ - Ltmp = Mpy_32_16_1(Ltmp,LG10); /*Q25,tmp16 * Q13 = Q23, tmp16*/ - *frame_ener = extract_h(L_shl(Ltmp,add(tmp16,1)));/*Q8*/ move16(); - enern = sub( *frame_ener ,lp_speech); /*Q8*/ - - return enern; -} diff --git a/src/libs/libevs/lib_com/g192.cpp b/src/libs/libevs/lib_com/g192.cpp old mode 100755 new mode 100644 index 4ea137be..97c2b6fd --- a/src/libs/libevs/lib_com/g192.cpp +++ b/src/libs/libevs/lib_com/g192.cpp @@ -1,17 +1,18 @@ /*==================================================================================== - EVS Codec 3GPP TS26.442 Apr 03, 2018. Version 12.11.0 / 13.6.0 / 14.2.0 + EVS Codec 3GPP TS26.443 Nov 13, 2018. Version 12.11.0 / 13.7.0 / 14.3.0 / 15.1.0 ====================================================================================*/ + #include #include #include #include - #ifndef _WIN32 #include #include #else #include + typedef unsigned short uint16_t; typedef signed short int16_t; typedef unsigned int uint32_t; @@ -20,7 +21,6 @@ typedef unsigned __int64 uint64_t; typedef signed __int64 int64_t; #endif #include "options.h" -#include "stl.h" #include "g192.h" @@ -28,12 +28,15 @@ typedef signed __int64 int64_t; #pragma warning( disable : 4996 ) #endif -#define G192_SYNC_GOOD_FRAME (Word16)0x6B21 -#define G192_SYNC_BAD_FRAME (Word16)0x6B20 -#define G192_BIT0 (Word16)0x007F -#define G192_BIT1 (Word16)0x0081 -#define MAX_BITS_PER_FRAME 2560 -#define RTP_HEADER_PART1 (Word16)22 /* magic number by network simulator */ +#define G192_SYNC_GOOD_FRAME (unsigned short) 0x6B21 +#define G192_SYNC_BAD_FRAME (unsigned short) 0x6B20 +#define G192_BIT0 (unsigned short) 0x007F +#define G192_BIT1 (unsigned short) 0x0081 +#define RTP_HEADER_PART1 (short)22 /* magic number by network simulator */ + +#ifndef MAX_BITS_PER_FRAME +#define MAX_BITS_PER_FRAME 2560 +#endif /* * Structures @@ -58,7 +61,6 @@ G192_Reader_Open(G192_HANDLE* phG192, FILE * filename) { return G192_MEMORY_ERROR; } - memset(*phG192, 0, sizeof(struct __G192)); /* associate file stream */ @@ -68,27 +70,24 @@ G192_Reader_Open(G192_HANDLE* phG192, FILE * filename) G192_Reader_Close(phG192); return G192_FILE_NOT_FOUND; } - return G192_NO_ERROR; } G192_ERROR G192_ReadVoipFrame_compact(G192_HANDLE const hG192, unsigned char * const serial, - Word16 * const num_bits, - Word16 *rtpSequenceNumber, - Word32 *rtpTimeStamp, - Word32 *rcvTime_ms) + short * const num_bits, + unsigned short * const rtpSequenceNumber, + unsigned int * const rtpTimeStamp, + unsigned int * const rcvTime_ms) { - Word16 short_serial [MAX_BITS_PER_FRAME]; + short short_serial [MAX_BITS_PER_FRAME]; G192_ERROR err; - Word16 i; + short i; err = G192_ReadVoipFrame_short(hG192, short_serial, num_bits, rtpSequenceNumber, rtpTimeStamp, rcvTime_ms); if(err != G192_NO_ERROR) - { return err; - } for(i=0; i<*num_bits; i++) { @@ -98,23 +97,22 @@ G192_ReadVoipFrame_compact(G192_HANDLE const hG192, serial[i>>3] = 0; serial[i>>3] |= bitinbyte; } - return G192_NO_ERROR; } G192_ERROR G192_ReadVoipFrame_short(G192_HANDLE const hG192, - Word16 * const serial, - Word16 *num_bits, - Word16 *rtpSequenceNumber, - Word32 *rtpTimeStamp, - Word32 *rcvTime_ms) + short * const serial, + short * const num_bits, + unsigned short * const rtpSequenceNumber, + unsigned int * const rtpTimeStamp, + unsigned int * const rcvTime_ms) { - Word32 rtpPacketSize; - Word16 rtpPacketHeaderPart1; - Word32 ssrc; - Word16 rtpPayloadG192[2]; - Word16 rtpPayloadSize; + uint32_t rtpPacketSize; + uint16_t rtpPacketHeaderPart1; + uint32_t ssrc; + uint16_t rtpPayloadG192[2]; + uint16_t rtpPayloadSize; /* RTP packet size */ if(fread(&rtpPacketSize, sizeof(rtpPacketSize), 1, hG192->file) != 1) @@ -124,12 +122,13 @@ G192_ReadVoipFrame_short(G192_HANDLE const hG192, return G192_EOF; } fprintf(stderr, "RTP Packet Size could't be read\n"); + return G192_READ_ERROR; } if(rtpPacketSize <= 12) { - fprintf(stderr, "RTP Packet size too small: %d\n", rtpPacketSize); + fprintf(stderr, "RTP Packet size too small: %ud\n", rtpPacketSize); return G192_INVALID_DATA; } @@ -141,6 +140,7 @@ G192_ReadVoipFrame_short(G192_HANDLE const hG192, return G192_EOF; } fprintf(stderr, "Reception Time in ms could't be read\n"); + return G192_READ_ERROR; } @@ -152,6 +152,7 @@ G192_ReadVoipFrame_short(G192_HANDLE const hG192, return G192_EOF; } fprintf(stderr, "RTP Header couldn't be read\n"); + return G192_READ_ERROR; } @@ -169,10 +170,11 @@ G192_ReadVoipFrame_short(G192_HANDLE const hG192, return G192_EOF; } fprintf(stderr, "RTP Sequence Number be read\n"); + return G192_READ_ERROR; } - *rtpSequenceNumber = ntohs(*rtpSequenceNumber); + /* RTP timestamp */ if(fread(rtpTimeStamp, sizeof(*rtpTimeStamp), 1, hG192->file) != 1) { @@ -181,10 +183,11 @@ G192_ReadVoipFrame_short(G192_HANDLE const hG192, return G192_EOF; } fprintf(stderr, "RTP Timestamp could't be read\n"); + return G192_READ_ERROR; } - *rtpTimeStamp = ntohl(*rtpTimeStamp); + /* RTP ssrc */ if(fread(&ssrc, sizeof(ssrc), 1, hG192->file) != 1) { @@ -193,18 +196,20 @@ G192_ReadVoipFrame_short(G192_HANDLE const hG192, return G192_EOF; } fprintf(stderr, "RTP SSRC could't be read\n"); + return G192_READ_ERROR; } /* RTP payload size */ - rtpPayloadSize = (Word16)(rtpPacketSize - 12); + rtpPayloadSize = rtpPacketSize - 12; if(rtpPayloadSize <= 2) { - fprintf(stderr, "RTP payload size too small: %d\n", rtpPayloadSize); + fprintf(stderr, "RTP payload size too small: %u\n", rtpPayloadSize); return G192_INVALID_DATA; } + /* RTP payload */ - if(fread(rtpPayloadG192, sizeof(Word16), 2, hG192->file) != 2) + if(fread(rtpPayloadG192, sizeof(short), 2, hG192->file) != 2) { if(feof( hG192->file) != 0) { @@ -219,18 +224,14 @@ G192_ReadVoipFrame_short(G192_HANDLE const hG192, return G192_INVALID_DATA; } *num_bits = rtpPayloadG192[1]; - if(*num_bits == 0 || *num_bits + 2 != rtpPayloadSize || *num_bits > MAX_BITS_PER_FRAME) + if(*num_bits == 0u || *num_bits + 2u != rtpPayloadSize || *num_bits > MAX_BITS_PER_FRAME) { fprintf(stderr, "error in parsing RTP payload: rtpPayloadSize=%u nBits=%d", rtpPayloadSize, *num_bits); return G192_INVALID_DATA; } - if( (Word16)fread(serial, sizeof(Word16), *num_bits, hG192->file) != *num_bits) + if( fread(serial, sizeof(short), *num_bits, hG192->file) != (unsigned short)*num_bits) { - if(feof( hG192->file) != 0) - { - return G192_EOF; - } fprintf(stderr, "Premature end of file, cannot read G.192 payload\n"); return G192_READ_ERROR; } @@ -242,13 +243,11 @@ G192_ERROR G192_Reader_Close(G192_HANDLE* phG192) { if(phG192 == NULL || *phG192 == NULL) - { return G192_NO_ERROR; - } free( *phG192 ); *phG192 = NULL; phG192 = NULL; - return G192_NO_ERROR; } + diff --git a/src/libs/libevs/lib_com/g192.h b/src/libs/libevs/lib_com/g192.h old mode 100755 new mode 100644 index f3712978..767e4c2e --- a/src/libs/libevs/lib_com/g192.h +++ b/src/libs/libevs/lib_com/g192.h @@ -1,10 +1,12 @@ /*==================================================================================== - EVS Codec 3GPP TS26.442 Apr 03, 2018. Version 12.11.0 / 13.6.0 / 14.2.0 + EVS Codec 3GPP TS26.443 Nov 13, 2018. Version 12.11.0 / 13.7.0 / 14.3.0 / 15.1.0 ====================================================================================*/ #ifndef G192_H #define G192_H G192_H +#include + /* * ENUMS */ @@ -45,18 +47,18 @@ G192_Reader_Open(G192_HANDLE* phG192, FILE * filename); G192_ERROR G192_ReadVoipFrame_compact(G192_HANDLE const hG192, unsigned char * const serial, - Word16 * const num_bits, - Word16 *rtpSequenceNumber, - Word32 *rtpTimeStamp, - Word32 *rcvTime_ms); + short * const num_bits, + unsigned short * const rtpSequenceNumber, + unsigned int * const rtpTimeStamp, + unsigned int * const rcvTime_ms); G192_ERROR G192_ReadVoipFrame_short(G192_HANDLE const hG192, - Word16 * const serial, - Word16 *num_bits, - Word16 *rtpSequenceNumber, - Word32 *rtpTimeStamp, - Word32 *rcvTime_ms); + short * const serial, + short * const num_bits, + unsigned short * const rtpSequenceNumber, + unsigned int * const rtpTimeStamp, + unsigned int * const rcvTime_ms); G192_ERROR G192_Reader_Close(G192_HANDLE* phG192); diff --git a/src/libs/libevs/lib_com/gain_inov.cpp b/src/libs/libevs/lib_com/gain_inov.cpp deleted file mode 100755 index b14777b5..00000000 --- a/src/libs/libevs/lib_com/gain_inov.cpp +++ /dev/null @@ -1,54 +0,0 @@ -/*==================================================================================== - EVS Codec 3GPP TS26.442 Apr 03, 2018. Version 12.11.0 / 13.6.0 / 14.2.0 - ====================================================================================*/ - -#include -#include "prot_fx.h" -#include "stl.h" -#include "basop_util.h" -#include "rom_com_fx.h" - - -Word32 calc_gain_inov( /* returns innovation gain Q16 */ - const Word16 *code, /* i : algebraic excitation Q9 */ - Word16 lcode, /* i : Subframe size Q0 */ - Word32 *dotp, /* o : intermediate result Q31-e */ - Word16 *dotp_e /* o : intermediate result exponent Q0 */ -) -{ - Word32 L_tmp; - Word16 exp_L_tmp, i; - - /* L_tmp = dot_product(code, code, lcode) + 0.01 */ - L_tmp = Dot_product12_offs(code, code, lcode, &exp_L_tmp, 2621l/*0.01f/2.0f Q19*/); - exp_L_tmp = sub(exp_L_tmp, 18); - - /* gain_inov = 1.0f / sqrt((dot_product(code, code, lcode) + 0.01) / lcode) */ - /* Note: lcode is in range: 32,40,64,80 */ - assert((lcode == 32) || (lcode == 40) || (lcode == 64) || (lcode == 80)); - if (s_and(lcode, sub(lcode, 1)) != 0) - { - L_tmp = Mpy_32_32(L_tmp, 1717986918l/*64.0/80.0 Q31*/); - } - exp_L_tmp = sub(exp_L_tmp, sub(14, norm_s(lcode))); - - i = norm_l(L_tmp); - L_tmp = L_shl(L_tmp, i); - exp_L_tmp = sub(exp_L_tmp, i); - - if (dotp != NULL) - { - *dotp = L_tmp; - move32(); - } - if (dotp_e != NULL) - { - *dotp_e = exp_L_tmp; - move16(); - } - - L_tmp = ISqrt32norm(L_tmp, &exp_L_tmp); - - return L_shl(L_tmp, sub(exp_L_tmp, 15)); /* 15Q16 */ -} - diff --git a/src/libs/libevs/lib_com/get_gain.cpp b/src/libs/libevs/lib_com/get_gain.cpp old mode 100755 new mode 100644 index ca9d775f..39087d96 --- a/src/libs/libevs/lib_com/get_gain.cpp +++ b/src/libs/libevs/lib_com/get_gain.cpp @@ -1,97 +1,37 @@ /*==================================================================================== - EVS Codec 3GPP TS26.442 Apr 03, 2018. Version 12.11.0 / 13.6.0 / 14.2.0 + EVS Codec 3GPP TS26.443 Nov 13, 2018. Version 12.11.0 / 13.7.0 / 14.3.0 / 15.1.0 ====================================================================================*/ #include "options.h" -#include "prot_fx.h" -#include "stl.h" -#include "basop_util.h" +#include "prot.h" -Word32 get_gain( /* output: codebook gain (adaptive or fixed) Q16 */ - Word16 x[], /* input : target signal */ - Word16 y[], /* input : filtered codebook excitation */ - Word16 n /* input : segment length */ + +/*----------------------------------------------------------------------------------* +* get_gain() +* +* +*----------------------------------------------------------------------------------*/ + +float get_gain( /* output: codebook gain (adaptive or fixed) */ + float x[], /* input : target signal */ + float y[], /* input : filtered codebook excitation */ + int n, /* input : segment length */ + float *en_y /* output: energy of y (sum of y[]^2, optional) */ ) { - Word32 tcorr, tener, Lgain; - Word16 exp_c, exp_e, exp, tmp; + float corr = 0.0f, ener = 1e-6f; + short i; + for (i = 0; i < n; i++) + { + corr += x[i]*y[i]; + ener += y[i]*y[i]; + } - tcorr = L_deposit_l(0); - tener = L_deposit_l(0); + if (en_y) + { + *en_y = ener; + } - - - /*----------------------------------------------------------------* - * Find gain based on inter-correlation product - *----------------------------------------------------------------*/ - - tcorr = Dot_product16HQ( 0, x, y, n, &exp_c ); - tener = Dot_productSq16HQ( 0, y, n, &exp_e ); - - BASOP_Util_Divide_MantExp(round_fx(tcorr), exp_c, s_max(round_fx(tener),1), exp_e, &tmp,&exp); - Lgain = L_shl(L_deposit_l(tmp)/*Q15*/,add(1,exp))/*Q16*/; - - return Lgain; -} - -Word32 get_gain2( /* output: codebook gain (adaptive or fixed) Q16 */ - Word16 x[], /* input : target signal */ - Word16 y[], /* input : filtered codebook excitation */ - Word16 n /* input : segment length */ -) -{ - Word32 tcorr, tener, Lgain; - Word16 m_corr, m_ener, negative, Q_corr, Q_ener; - - negative = 0; - move16(); - - /*----------------------------------------------------------------* - * Find gain based on inter-correlation product - *----------------------------------------------------------------*/ - tcorr = Dot_product16HQ(0, x, y, n, &Q_corr); - tener = Dot_productSq16HQ(0, y, n, &Q_ener); - - tener = L_max(tener, 1); - - if (tcorr <= 0) - { - negative = 1; - move16(); - } - BASOP_SATURATE_WARNING_OFF /*tcorr max be negative maxvall - not critical*/ - tcorr = L_abs(tcorr); - BASOP_SATURATE_WARNING_ON - - m_corr = extract_h(tcorr); - - m_ener = extract_h(tener); - - IF (sub(m_corr, m_ener) > 0) - { - m_corr = shr(m_corr, 1); - Q_corr = add(Q_corr,1); - } - if (m_ener==0) - { - move16(); - m_corr = 0x7FFF; - } - if (m_ener != 0) - { - m_corr = div_s(m_corr, m_ener); - } - - Q_corr = sub(Q_corr,Q_ener); - - Lgain = L_shl(L_deposit_l(m_corr), add(Q_corr, 1)); /* Lgain in Q16 */ - - if (negative != 0) - { - Lgain = L_negate(Lgain); /* Lgain in Q16 */ - } - - - return Lgain; + return(corr/ener); } diff --git a/src/libs/libevs/lib_com/gs_bitallocation.cpp b/src/libs/libevs/lib_com/gs_bitallocation.cpp new file mode 100644 index 00000000..a605083a --- /dev/null +++ b/src/libs/libevs/lib_com/gs_bitallocation.cpp @@ -0,0 +1,451 @@ +/*==================================================================================== + EVS Codec 3GPP TS26.443 Nov 13, 2018. Version 12.11.0 / 13.7.0 / 14.3.0 / 15.1.0 + ====================================================================================*/ + +#include +#include "options.h" +#include "cnst.h" +#include "rom_com.h" +#include "prot.h" + + +/*-------------------------------------------------------------------* + * Local functions + *-------------------------------------------------------------------*/ + +static float Find_bit_frac( const short nb_band, const short remaining_bits ); + +/*-------------------------------------------------------------------* + * bands_and_bit_alloc() + * + * AC mode (GSC) bands and bits allocation + *-------------------------------------------------------------------*/ + +void bands_and_bit_alloc( + const short cor_strong_limit, /* i : HF correlation */ + const short noise_lev, /* i : dwn scaling factor */ + const long core_brate, /* i : core bit rate */ + const short Diff_len, /* i : Lenght of the difference signal (before pure spectral)*/ + const short bits_used, /* i : Number of bit used before frequency Q */ + short *bit, /* i/o: Number of bit allowed for frequency quantization */ + float *Ener_per_bd_iQ, /* i/o: Quantized energy vector */ + short *max_ener_band, /* o : Sorted order */ + short *bits_per_bands_s,/* i/o: Number of bit allowed per allowed subband (Q3) */ + short *nb_subbands, /* o : Number of subband allowed */ + const float *exc_diff, /* i : Difference signal to quantize (encoder side only) */ + float *concat_in, /* o : Concatened PVQ's input vector (encoder side only) */ + short *pvq_len, /* o : Number of bin covered with the PVQ */ + const short coder_type, /* i : coding type */ + const short bwidth, /* i : input signal bandwidth */ + const short GSC_noisy_speech /* i : GSC noisy speech flag */ +) +{ + short bandoffset, i, j, nb_bands_max, bit_new_bands, bit_tmp, st_band, nb_bands; + float bit_fracf, etmp; + float sum_bit; + float ener_vec[MBANDS_GN]; + short nb_tot_bands; + short bit_index, bit_index_mem, imax; + short pos, band; + float SWB_bit_budget; + float bits_per_bands[MBANDS_GN]; + + /* initializations */ + nb_tot_bands = 16; + set_f( bits_per_bands, 0.0f, MBANDS_GN ); + + /* To adapt current energy band to PVQ freq band for sorting*/ + ener_vec[0] = Ener_per_bd_iQ[0] + Ener_per_bd_iQ[1]; + mvr2r( Ener_per_bd_iQ + 1, ener_vec, 15 ); + ener_vec[15] = ener_vec[14]; + + for(i = 0; i < MBANDS_GN; i++) + { + ener_vec[i] = (float)((short)(ener_vec[i]*4096.f+0.5f)); + } + + /*------------------------------------------------------------------------ + * Determination of the number of bits available to the frequency domain + * Allocation of a maximum number of band to be encoded + *-----------------------------------------------------------------------*/ + + nb_bands_max = nb_tot_bands; + bit_new_bands = 5; + + bit_index = BRATE2IDX(core_brate)*17; + bit_index_mem = bit_index; + + if( (coder_type == AUDIO || coder_type == INACTIVE) && bwidth == NB ) + { + if(core_brate >= ACELP_9k60) + { + *bit = (short)(core_brate*(1.0f/50) + 0.5f) - bits_used - 25; + } + else + { + *bit = (short)(core_brate*(1.0f/50) + 0.5f) - bits_used - 21; + } + + nb_tot_bands = 10; + } + else + { + *bit = (short)(core_brate*(1.0f/50) + 0.5f) - bits_used - GSC_freq_bits[bit_index]; + } + + if( GSC_noisy_speech ) + { + SWB_bit_budget = *bit; + nb_bands = 5; + st_band = nb_bands; + + set_f( bits_per_bands, 0, MBANDS_GN ); + + bit_fracf = Find_bit_frac(nb_bands, SWB_bit_budget); /* Supplementary bits distributed only on first bands */ + + nb_tot_bands = nb_bands_max - 6; + + if( nb_tot_bands > 16 ) + { + nb_tot_bands = 16; + } + + for(j = 0; j < 2; j++) + { + i = j; + max_ener_band[j] = i; + ener_vec[i] = 0; + } + + for(; j < nb_bands; j++) + { + i = maximum(ener_vec, nb_tot_bands, &etmp); + max_ener_band[j] = i; + ener_vec[i] = 0; + } + + set_f( bits_per_bands, bit_fracf, nb_bands ); + } + else + { + bit_index++; + bit_tmp = *bit - GSC_freq_bits[bit_index]; + bit_index++; + nb_bands_max += GSC_freq_bits[bit_index]; + bit_index++; + + *pvq_len = 112; + st_band = 7; + + if( core_brate <= ACELP_9k60 ) + { + *pvq_len = 80; + st_band = 5; + if( Diff_len == 0 ) + { + nb_bands_max += 2; + bit_tmp -= 13; + } + } + else if( Diff_len == 0 ) + { + nb_bands_max += 2; + bit_tmp -= 17; + } + + nb_bands = *pvq_len/16; + + /*------------------------------------------------------------------------ + * Adjustement of the maximum number of bands in function of the + * dynamics of the spectrum (more or less speech like) + *-----------------------------------------------------------------------*/ + + if( coder_type == INACTIVE || noise_lev >= NOISE_LEVEL_SP3 ) + { + /* Probably classification error -> concentrate bits on LF */ + if( core_brate >= ACELP_8k00 ) + { + nb_bands_max = nb_bands+1; + } + else + { + nb_bands_max = nb_bands; + } + } + else if( noise_lev >= NOISE_LEVEL_SP2 || + (core_brate <= ACELP_13k20 && core_brate >= ACELP_9k60 && cor_strong_limit == 0) ) /* Very low dynamic, tend to speech, do not try to code HF at all */ + { + nb_bands_max -= 2; + } + else if( noise_lev >= NOISE_LEVEL_SP1) /* Very low dynamic, tend to speech, code less HF */ + { + nb_bands_max -= 1; + } + + if( bwidth == NB && nb_bands_max > 10 ) + { + nb_bands_max = 10; + } + + /*------------------------------------------------------------------------ + * Find extra number of band to code according to bit rate availables + *-----------------------------------------------------------------------*/ + + while ( bit_tmp >= bit_new_bands && nb_bands <= nb_bands_max - 1 ) + { + bit_tmp -= bit_new_bands; + nb_bands++; + } + + /*------------------------------------------------------------------------ + * Fractional bits to distribute on the first x bands + *-----------------------------------------------------------------------*/ + + bit_fracf = Find_bit_frac(st_band, bit_tmp); /* Supplementary bits distributed only on first bands */ + + /*------------------------------------------------------------------------ + * Complete the bit allocation per frequency band + *-----------------------------------------------------------------------*/ + + imax = 5; + if( core_brate > ACELP_9k60 ) + { + imax = 7; + } + + for(i = 0; i < imax; i++) + { + bits_per_bands[i] = GSC_freq_bits[bit_index] + bit_fracf; + bit_index++; + } + + if( Diff_len == 0 ) + { + bit_index = bit_index_mem+10; + for( i = 0; i < 7; i++ ) + { + bits_per_bands[i] += GSC_freq_bits[bit_index]; + bit_index++; + } + } + + /*-------------------------------------------------------------------------- + * Complete the bit allocation per frequency band for 16kHz high brate mode + *--------------------------------------------------------------------------*/ + + for( j = st_band; j < nb_bands; j++ ) + { + bits_per_bands[j] = bit_new_bands; + } + + /*-------------------------------------------------------------------------- + * Compute a maximum band (band offset) for the search on maximal energy + * This is function of the spectral dynamic and the bitrate + *--------------------------------------------------------------------------*/ + + bandoffset = nb_tot_bands - (nb_bands + 2); + + if( noise_lev <= NOISE_LEVEL_SP1a ) + { + bandoffset--; + } + else if ( (core_brate <= ACELP_13k20 && (coder_type == INACTIVE || noise_lev >= NOISE_LEVEL_SP3)) || + (core_brate <= ACELP_13k20 && core_brate >= ACELP_9k60 && cor_strong_limit == 0) ) + { + bandoffset++; + } + + if( bandoffset < 0 ) + { + bandoffset = 0; + } + + /*-------------------------------------------------------------------------- + * Initiazed sorted vector + * For the first x bands to be included in th final sorted vector + * Sort the remaining bands in decrease energy order + *--------------------------------------------------------------------------*/ + + for(j = 0; j < nb_tot_bands; j++) + { + max_ener_band[j] = -10; + } + + for(j = 0; j < st_band; j++) + { + max_ener_band[j] = j; + ener_vec[j] = -10; + } + + pos = st_band; + for(; j < nb_bands; j++) + { + i = maximum(ener_vec, nb_tot_bands-bandoffset, &etmp); + if(i > pos) + { + pos = i; + } + max_ener_band[j] = i; + ener_vec[i] = -10; + } + + /* re-allocate bits to the frames such that the highest band with allocated bits is higher than the threshold */ + if( nb_tot_bands - bandoffset > nb_bands && ( pos > 7 && core_brate == ACELP_8k00 ) && bwidth == WB ) + { + band = nb_tot_bands-bandoffset-nb_bands; + for( j=0; j 0 ) + { + bits_per_bands[j] -= 1; + + if ( j == st_band - 1 - i ) + { + j = 0; + } + else + { + ++j; + } + + if( j == 0 && i < st_band - 1) + { + i++; + } + + bit_tmp -= 1; + } + } + + /*-------------------------------------------------------------------------- + * Bit sum verification for GSC inactive at very high rate + * The maximum number of bits per band of length 16 is 112 + * Redistribute the overage bits if needed + *--------------------------------------------------------------------------*/ + + sum_bit = 0; + j = 0; + for( i = 0; i < nb_bands; i++ ) + { + if( bits_per_bands[i] > 112 ) + { + sum_bit += bits_per_bands[i] - 112; + bits_per_bands[i] = 112; + j = i+1; + } + + /* safety check for overage bit reallocation */ + else if( bits_per_bands[i] + sum_bit/3 > 112 ) + { + j = i+1; + } + } + + if( sum_bit != 0 ) + { + sum_bit /= (nb_bands - j); + for( i = j; i < nb_bands; i++ ) + { + bits_per_bands[i] += sum_bit; + } + } + } + + /*-------------------------------------------------------------------------- + * second step of bit sum verification, normally sum_bit == *bit + *--------------------------------------------------------------------------*/ + + sum_bit = 0.00f; + for( i = 0; i < nb_bands; i++ ) + { + bits_per_bands[i] = (float)floor(bits_per_bands[i]); + sum_bit += bits_per_bands[i]; + } + + if( *bit > sum_bit ) + { + i = nb_bands-1; + while(*bit > sum_bit) + { + bits_per_bands[i]++; + sum_bit++; + i--; + if(i==0) + { + i = nb_bands-1; + } + } + } + + /*-------------------------------------------------------------------------- + * Recompute the real number/length of frequency bands to encode + *--------------------------------------------------------------------------*/ + + *nb_subbands = nb_bands; + *pvq_len = *nb_subbands*16; + + /*-------------------------------------------------------------------------- + * Concatenate bands (encoder only) + *--------------------------------------------------------------------------*/ + + if( exc_diff != NULL ) + { + for( j = 0; j < nb_bands; j++ ) + { + mvr2r( exc_diff + max_ener_band[j]*16, concat_in+j*16, 16 ); + } + } + for( j = 0; j < nb_bands; j++ ) + { + bits_per_bands_s[j] = ((short)bits_per_bands[j]) << 3; + } + + return; +} + + +/*-------------------------------------------------------------------* + * Find_bit_frac() + * + * Computes the fraction of the remaining bit budget to allocate to the bands + *-------------------------------------------------------------------*/ + +static float Find_bit_frac( + const short nb_band, + const short remaining_bits +) +{ + float var_out; + short inv_bandQ15; + int L_num; + + inv_bandQ15 = 6553; + if (nb_band == 7) + { + inv_bandQ15 = 4681; + } + L_num = inv_bandQ15*remaining_bits; + L_num *= 8; + var_out = L_num/262144.0f; + + return (var_out); +} diff --git a/src/libs/libevs/lib_com/gs_bitallocation_fx.cpp b/src/libs/libevs/lib_com/gs_bitallocation_fx.cpp deleted file mode 100755 index 662b6dc4..00000000 --- a/src/libs/libevs/lib_com/gs_bitallocation_fx.cpp +++ /dev/null @@ -1,481 +0,0 @@ -/*==================================================================================== - EVS Codec 3GPP TS26.442 Apr 03, 2018. Version 12.11.0 / 13.6.0 / 14.2.0 - ====================================================================================*/ - -#include "options.h" /* Compilation switches */ -#include "cnst_fx.h" /* Common constants */ -#include "rom_com_fx.h" /* Static table prototypes */ -#include "prot_fx.h" /* Function prototypes */ -#include "assert.h" /* Debug prototypes */ -#include "stl.h" - -/*==================================================================================*/ -/* FUNCTION : void bands_and_bit_alloc_fx(); */ -/*----------------------------------------------------------------------------------*/ -/* PURPOSE : AC mode (GSC) bands and bits allocation */ -/*----------------------------------------------------------------------------------*/ -/* INPUT ARGUMENTS : */ -/* _ (Word16) cor_strong_limit : HF correlation */ -/* _ (Word16) noise_lev : dwn scaling factor Q0 */ -/* _ (Word32) core_brate : core codec used Q0 */ -/* _ (Word16) Diff_len : Lenght of the difference signal Q0 */ -/* _ (Word16) bits_used : Number of bit used before frequency Q0 */ -/* _ (Word16) idx : Energy band 14 Q0 */ -/* _ (Word16*) exc_diff : Difference signal to quantize (Encoder only) */ -/* _ (Word16) coder_type : coding type Q0 */ -/* _ (Word16) bwidth : input signal bandwidth Q0 */ -/*----------------------------------------------------------------------------------*/ -/* OUTPUT ARGUMENTS : */ -/* _ (Word16*) max_ener_band : Sorted order */ -/* _ (Word16*) nb_subbands : Number of subband allowed Q0 */ -/* _ (Word16*) concat_in : Concatened PVQ's input vector (Encoder Only) */ -/* _ (Word16*) pvq_len : Number of bin covered with the PVQ Q0 */ -/*----------------------------------------------------------------------------------*/ -/* INPUT/OUTPUT ARGUMENTS : */ -/* _ (Word16*) bit :Number of bit allowed for frequency quantization */ -/* _ (Word16*) Ener_per_bd_iQ : Quantized energy vector Q13 */ -/* _ (Word32*) bits_per_bands : Number of bit allowed per allowed subband Q18 */ -/*----------------------------------------------------------------------------------*/ -/* RETURN ARGUMENTS : */ -/* _ None */ -/*==================================================================================*/ -void bands_and_bit_alloc_fx( - const Word16 cor_strong_limit, /* i : HF correlation */ - const Word16 noise_lev, /* i : dwn scaling factor */ - const Word32 core_brate, /* i : core bit rate */ - const Word16 Diff_len, /* i : Lenght of the difference signal (before pure spectral)*/ - const Word16 bits_used, /* i : Number of bit used before frequency Q */ - Word16 *bit, /* i/o: Number of bit allowed for frequency quantization */ - const Word16 *Ener_per_bd_iQ, /* i/o: Quantized energy vector */ - Word16 *max_ener_band, /* o : Sorted order */ - Word16 *out_bits_per_bands, /* i/o: Number of bit allowed per allowed subband Q3 */ - Word16 *nb_subbands, /* o : Number of subband allowed */ - const Word16 *exc_diff, /* i : Difference signal to quantize (encoder side only) */ - Word16 *concat_in, /* o : Concatened PVQ's input vector (encoder side only) */ - Word16 *pvq_len, /* o : Number of bin covered with the PVQ */ - const Word16 coder_type, /* i : coding type */ - const Word16 bwidth, /* i : input signal bandwidth */ - const Word16 GSC_noisy_speech -) -{ - - Word16 bandoffset, i, j, nb_bands_max, bit_new_bands, bit_tmp, st_band, nb_bands; - Word16 ener_vec[MBANDS_GN]; /*Q12 */ - Word16 nb_tot_bands = 16; - Word16 bit_index, bit_index_mem, imax; - Word32 L_tmp; - Word32 sum_bit, bit_fracf; - Word16 etmp; - Word16 tmp; - Word16 Ener_per_bd_iQ_tmp[MBANDS_GN]; - Word16 pos, band; - Word16 SWB_bit_budget; - Word32 bits_per_bands[MBANDS_GN]; - Word16 w_sum_bit; - - Copy( Ener_per_bd_iQ, Ener_per_bd_iQ_tmp, MBANDS_GN ); - - set32_fx( bits_per_bands, 0, MBANDS_GN ); - set16_fx( out_bits_per_bands, 0, MBANDS_GN ); - - /* To adapt current energy band to PVQ freq band for sorting*/ - ener_vec[0] = add(Ener_per_bd_iQ[0],Ener_per_bd_iQ[1]); /*Q12 */ - Copy( Ener_per_bd_iQ_tmp+1, ener_vec, 15 ); /*Q12 */ - ener_vec[15] = ener_vec[14]; - move16(); - - /*------------------------------------------------------------------------ - * Determination of the number of bits available to the frequency domain - * Allocation of a maximum number of band to be encoded - *-----------------------------------------------------------------------*/ - - nb_bands_max = nb_tot_bands; - move16(); - bit_new_bands = 5; - move16(); - - bit_index = i_mult2(BRATE2IDX_fx(core_brate),17); - bit_index_mem = bit_index; - move16(); - - test(); - test(); - IF( (sub(coder_type,AUDIO) == 0 || sub(coder_type,INACTIVE) == 0) && sub(bwidth,NB) == 0 ) - { - IF(L_sub(core_brate,ACELP_9k60) >= 0) - { - /* *bit = (short)(core_brate*(1.0f/50) + 0.5f) - bits_used - 25; */ - L_tmp = Mult_32_16(core_brate,20971); - tmp = extract_l(L_shr_r(L_tmp,5)); - *bit = sub(sub(tmp,bits_used), 25); - move16(); - } - ELSE - { - L_tmp = Mult_32_16(core_brate,20971); - tmp = extract_l(L_shr_r(L_tmp,5)); - *bit = sub(sub(tmp,bits_used), 21); - move16(); - } - nb_tot_bands = 10; - move16(); - } - ELSE - { - /* *bit = (short)(core_brate*(1.0f/50) + 0.5f) - bits_used - GSC_freq_bits[bit_index]; */ - - L_tmp = Mult_32_16(core_brate,20971); - tmp = extract_l(L_shr_r(L_tmp,5)); - *bit = sub(sub(tmp,bits_used),GSC_freq_bits[bit_index]); - move16(); - } - - IF( sub(GSC_noisy_speech,1) == 0 ) - { - SWB_bit_budget = *bit; - move16(); - nb_bands = 5; - move16(); - st_band = nb_bands; - move16(); - - set32_fx( bits_per_bands, 0, MBANDS_GN ); - /*bit_fracf = (1.0f/nb_bands)*(SWB_bit_budget); */ - bit_fracf = L_mult(div_s(1,nb_bands),shl(SWB_bit_budget,2)); /* Q18 */ - - nb_tot_bands = sub(nb_bands_max,6); - nb_tot_bands = s_min(nb_tot_bands, 16); - - FOR(j = 0; j < 2; j++) - { - i = j; - move16(); - max_ener_band[j] = i; - move16(); - ener_vec[i] = 0; - move16(); - } - - FOR(; j < nb_bands; j++) - { - i = maximum_fx(ener_vec, nb_tot_bands, &etmp); - max_ener_band[j] = i; - move16(); - ener_vec[i] = 0; - move16(); - } - - set32_fx(bits_per_bands, bit_fracf, nb_bands); - } - ELSE - { - bit_index++; - bit_tmp = sub(*bit,GSC_freq_bits[bit_index]); - bit_index++; - nb_bands_max = add(nb_bands_max,GSC_freq_bits[bit_index]); - bit_index++; - - *pvq_len = 112; - move16(); - st_band = 7; - move16(); - - IF( L_sub(core_brate,ACELP_9k60) <= 0 ) - { - *pvq_len = 80; - move16(); - st_band = 5; - move16(); - - IF( Diff_len == 0 ) - { - nb_bands_max = add(nb_bands_max,2); - bit_tmp = sub(bit_tmp,13); - } - } - - ELSE IF( Diff_len == 0 ) - { - nb_bands_max = add(nb_bands_max,2); - bit_tmp = sub(bit_tmp,17); - } - - nb_bands = shr(*pvq_len,4); - - /*------------------------------------------------------------------------ - * Ajustement of the maximum number of bands in function of the - * dynamics of the spectrum (more or less speech like) - *-----------------------------------------------------------------------*/ - test(); - test(); - test(); - test(); - IF( sub(coder_type,INACTIVE) == 0 || sub(noise_lev,NOISE_LEVEL_SP3) >= 0 ) - { - /* Probably classification error -> concentrate bits on LF */ - nb_bands_max = nb_bands; - move16(); - if( L_sub(core_brate,ACELP_8k00) >= 0 ) - { - nb_bands_max = add(nb_bands,1); - } - } - ELSE IF( sub(noise_lev,NOISE_LEVEL_SP2) >= 0 || - (L_sub(core_brate,ACELP_13k20) <= 0 && L_sub(core_brate,ACELP_9k60) >= 0 && cor_strong_limit == 0) ) /* Very low dynamic, tend to speech, do not try to code HF at all */ - { - nb_bands_max = sub(nb_bands_max,2); - } - ELSE if( sub(noise_lev,NOISE_LEVEL_SP1) >= 0) /* Very low dynamic, tend to speech, code less HF */ - { - nb_bands_max = sub(nb_bands_max,1); - } - - test(); - if( sub(bwidth,NB) == 0 && sub(nb_bands_max,10) > 0 ) - { - nb_bands_max = 10; - move16(); - } - - /*------------------------------------------------------------------------ - * Find extra number of band to code according to bit rate availables - *-----------------------------------------------------------------------*/ - WHILE ( sub(bit_tmp,bit_new_bands) >= 0 && sub(nb_bands,sub(nb_bands_max, 1)) <= 0 ) - { - bit_tmp = sub(bit_tmp,bit_new_bands); - nb_bands = add(nb_bands,1); - } - - /*------------------------------------------------------------------------ - * Fractional bits to distribute on the first x bands - *-----------------------------------------------------------------------*/ - - bit_fracf = L_mult(div_s(1,st_band),shl(bit_tmp,2)); /* Q18 */ - - /*------------------------------------------------------------------------ - * Complete the bit allocation per frequency band - *-----------------------------------------------------------------------*/ - imax = 5; - move16(); - - if( L_sub(core_brate,ACELP_9k60) > 0 ) - { - imax = 7; - move16(); - } - FOR(i = 0; i < imax; i++) - { - bits_per_bands[i] = L_add(GSC_freq_bits_fx[bit_index],bit_fracf); - move32();/* Q18 */ - bit_index = add(bit_index,1); - } - - IF( Diff_len == 0 ) - { - bit_index = add(bit_index_mem,10); - FOR( i = 0; i < 7; i++ ) - { - bits_per_bands[i] = L_add(bits_per_bands[i],GSC_freq_bits_fx[bit_index]); - move32();/*chk Q18 */ - bit_index = add(bit_index,1); - } - } - - /*-------------------------------------------------------------------------- - * Complete the bit allocation per frequency band for 16kHz high brate mode - *--------------------------------------------------------------------------*/ - - FOR( j = st_band; j < nb_bands; j++ ) - { - bits_per_bands[j] = L_shl(bit_new_bands,18); - move32(); /*chk Q18 */ - } - - /*-------------------------------------------------------------------------- - * Compute a maximum band (band offset) for the search on maximal energy - * This is function of the spectral dynamic and the bitrate - *--------------------------------------------------------------------------*/ - - bandoffset = sub(nb_tot_bands,add(nb_bands,2)); - - test(); - test(); - test(); - test(); - test(); - IF( sub(noise_lev,NOISE_LEVEL_SP1a) <= 0 ) - { - bandoffset = sub(bandoffset,1); - } - ELSE if ( (L_sub(core_brate,ACELP_13k20) <= 0 && (sub(coder_type,INACTIVE) == 0 || sub(noise_lev,NOISE_LEVEL_SP3) >= 0)) || - (L_sub(core_brate,ACELP_13k20) <= 0 && L_sub(core_brate,ACELP_9k60) >= 0 && cor_strong_limit == 0) ) - { - bandoffset = add(bandoffset,1); - } - - bandoffset = s_max(bandoffset ,0); - - /*-------------------------------------------------------------------------- - * Initiazed sorted vector - * For the first x bands to be included in th final sorted vector - * Sort the remaining bands in decrease energy order - *--------------------------------------------------------------------------*/ - FOR(j = 0; j < nb_tot_bands; j++) - { - max_ener_band[j] = -10; - move16(); - } - FOR(j = 0; j < st_band; j++) - { - max_ener_band[j] = j; - move16(); - ener_vec[j] = -10; - move16(); - } - pos = st_band; - move16(); - FOR(; j < nb_bands; j++) - { - i = maximum_fx(ener_vec, sub(nb_tot_bands,bandoffset), &etmp); - pos = s_max(pos,i); - max_ener_band[j] = i; - move16(); - ener_vec[i] = -10; - move16(); - } - - /* re-allocate bits to the frames such that the highest band with allocated bits is higher than the threshold */ - test(); - test(); - test(); - IF( sub(sub(nb_tot_bands, bandoffset),nb_bands) > 0 && ( sub(pos,7) > 0 && L_sub(core_brate,ACELP_8k00) == 0 ) && sub(bwidth,WB) == 0 ) - { - band = sub(nb_tot_bands, add(bandoffset,nb_bands)); - FOR(j=0; j 0; bit_tmp--) - { - bits_per_bands[j] = L_sub(bits_per_bands[j],262144); /*Q18 */ - j = add(j,1); - if ( sub(j,sub(st_band, i)) == 0 ) - { - j = 0; - move16(); - } - test(); - if( j == 0 && sub(i,sub(st_band, 1)) < 0) - { - i = add(i,1); - } - } - } - } - /*-------------------------------------------------------------------------- - * Bit sum verification for GSC inactive at very high rate - * The maximum number of bits per band of length 16 is 112 - * Redistribute the overage bits if needed - *--------------------------------------------------------------------------*/ - sum_bit = 0; - move16(); - j = 0; - move16(); - FOR( i = 0; i < nb_bands; i++ ) - { - L_tmp = Mult_32_16(sum_bit,10923); - - IF( L_sub(bits_per_bands[i],29360128) > 0) /* 112 in Q18 */ - { - sum_bit = L_add(sum_bit,L_sub(bits_per_bands[i],29360128)); /* Q18 */ - bits_per_bands[i] = 29360128; - move32(); - j = add(i,1); - } - ELSE if( L_sub(L_add(bits_per_bands[i],L_tmp),29360128 ) > 0) /* Q18 */ - { - j = add(i,1); - } - } - - IF( sum_bit != 0 ) - { - tmp = sub(nb_bands,j); - sum_bit = Mult_32_16(sum_bit,div_s(1,tmp)); /* Q18 */ - FOR( i = j; i < nb_bands; i++ ) - { - bits_per_bands[i] = L_add(bits_per_bands[i],sum_bit); - move32();/* Q18 */ - } - } - /*-------------------------------------------------------------------------- - * second step of bit sum verification, normally sum_bit == *bit - *--------------------------------------------------------------------------*/ - w_sum_bit = 0; - move16(); - FOR( i = 0; i < nb_bands; i++ ) - { - out_bits_per_bands[i] = shl(extract_l(L_shr(bits_per_bands[i],18)),3); - move16(); - w_sum_bit = add(w_sum_bit,out_bits_per_bands[i]); /* Q3 */ - } - tmp = shl(*bit,3); - - IF( sub(tmp,w_sum_bit)>0 ) - { - i = sub(nb_bands,1); - move16(); - FOR( ; tmp > w_sum_bit; w_sum_bit += (1<<3) ) - { - out_bits_per_bands[i] = add(out_bits_per_bands[i],1<<3); - move16(); - i = sub(i, 1); - if(i==0) - { - i = sub(nb_bands,1); - } - } - } - /*-------------------------------------------------------------------------- - * Recompute the real number/length of frequency bands to encode - *--------------------------------------------------------------------------*/ - *nb_subbands = nb_bands; - move16(); - *pvq_len = shl(*nb_subbands,4); - - /*-------------------------------------------------------------------------- - * Concatenate bands (encoder only) - *--------------------------------------------------------------------------*/ - IF( exc_diff != NULL ) - { - FOR( j = 0; j < nb_bands; j++ ) - { - Copy( exc_diff + shl(max_ener_band[j],4), concat_in+shl(j,4), 16 ); - } - } - - return; -} diff --git a/src/libs/libevs/lib_com/gs_gains.cpp b/src/libs/libevs/lib_com/gs_gains.cpp new file mode 100644 index 00000000..0b29acba --- /dev/null +++ b/src/libs/libevs/lib_com/gs_gains.cpp @@ -0,0 +1,571 @@ +/*==================================================================================== + EVS Codec 3GPP TS26.443 Nov 13, 2018. Version 12.11.0 / 13.7.0 / 14.3.0 / 15.1.0 + ====================================================================================*/ + +#include +#include "options.h" +#include "cnst.h" +#include "rom_com.h" +#include "prot.h" + + +/*-------------------------------------------------------------------* + * Local functions + *-------------------------------------------------------------------*/ + +static short VDQ_vec( float *Qvec_out, const float *mean_dic, const float *dic, + const short index, const short vec_en ); + +/*-------------------------------------------------------------------* + * Comp_and_apply_gain() + * + * Compute and apply the quantized per band gain + *-------------------------------------------------------------------*/ + +void Comp_and_apply_gain( + float exc_diffQ[], /* i/o: Quantized excitation */ + float Ener_per_bd_iQ[], /* o : Target ener per band */ + float Ener_per_bd_yQ[], /* o : Ener per band for norm vector */ + short Mbands_gn, /* i : number of bands */ + const short ReUseGain /* i : Reuse the gain in Ener_per_bd_yQ */ +) +{ + short i, i_band; + short StartBin, NB_Qbins; + float y_gain; + + /* Recreate excitation for local synthesis and decoder */ + StartBin = 0; + NB_Qbins = 0; + for( i_band = 0; i_band < Mbands_gn; i_band++ ) + { + StartBin += NB_Qbins; + NB_Qbins = mfreq_bindiv_loc[i_band]; + if( ReUseGain == 1 ) + { + y_gain = Ener_per_bd_yQ[i_band]; + } + else + { + y_gain = (float)pow(10, (Ener_per_bd_iQ[i_band]-Ener_per_bd_yQ[i_band])); + Ener_per_bd_yQ[i_band] = y_gain; + } + + for(i = StartBin ; i < NB_Qbins + StartBin ; i++) + { + exc_diffQ[i] *= y_gain; + } + } + + return; +} + +/*------------------------------------------------------------------* + * Ener_per_band_comp() + * + * Compute the energy per band in log domain for quantization purposes + * Loops are decomposed to accomodate the PVQ quantization + *------------------------------------------------------------------*/ + +void Ener_per_band_comp( + const float exc_diff[], /* i : target signal */ + float y_gain4[], /* o : Energy per band to quantize */ + const short Mband, /* i : Max band */ + const short Eflag /* i : flag of highest band */ +) +{ + float etmp; + const float *pt; + short i,j; + + pt = exc_diff; + for(j = 0; j < 2; j++) + { + y_gain4[j] = 0; + etmp = 0.02f; + + pt = exc_diff + j*8; + for(i = 0; i < 8; i++) + { + etmp += (*pt **pt); + pt++; + } + + /* normalized to 16 bins to easy the quantization */ + y_gain4[j] = (float)log10(sqrt(2*etmp)); + } + + for(j = 1; j < Mband-2; j++) + { + etmp = 0.01f; + + pt = exc_diff + j*16; + for(i = 0; i < 16; i++) + { + etmp += (*pt **pt); + pt++; + } + + y_gain4[j+1] = (float)log10(sqrt(etmp)); + } + + if( Eflag == 1 ) + { + etmp = 0.01f; + + pt = exc_diff + j*16; + for(i = 0; i < 32; i++) + { + etmp += (*pt **pt); + pt++; + } + + y_gain4[j+1] = (float)log10(sqrt(etmp/2)); + } + + return; +} + +/*-------------------------------------------------------------------* + * gsc_gainQ() + * + * Quantization of the energy per band + *-------------------------------------------------------------------*/ + +float gsc_gainQ( + Encoder_State *st, /* i/o: encoder state structure */ + const float y_gain4[], /* i : Energy per band */ + float y_gainQ[], /* o : quantized energy per band */ + const long core_brate, /* i : Core rate */ + const short coder_type, /* i : coding type */ + const short bwidth /* i : input signal bandwidth */ +) +{ + float y_gain_tmp[MBANDS_GN], y_gain_tmp2[MBANDS_GN]; + short i, idx_g = 0; + float mean_4g[1], ftmp1; + float Gain_off = 0.0f; + short Mbands_gn = MBANDS_GN; + float y_gain_tmp3[MBANDS_GN]; + + mean_4g[0] = 0; + + if( (coder_type == AUDIO || coder_type == INACTIVE) && bwidth == NB ) + { + ftmp1 = mean(y_gain4, 10) - 0.6f; + for(i = 0; i < Mbands_gn; i++) + { + if(y_gain4[i] < ftmp1) + { + y_gain_tmp2[i] = ftmp1; + } + else + { + y_gain_tmp2[i] = y_gain4[i]; + } + } + + /* Quantized mean gain without clipping */ + mean_4g[0] = mean(y_gain_tmp2, 10); + idx_g = (short)vquant(mean_4g, Gain_meanNB, mean_4g, Gain_mean_dicNB, 1, 64); + push_indice( st, IND_MEAN_GAIN2, idx_g, 6 ); + + for(i = 0; i < Mbands_gn; i++) + { + y_gain_tmp[i] = y_gain_tmp2[i] - mean_4g[0]; + } + + if( y_gain_tmp[9] < -0.3f ) + { + y_gain_tmp[9] = -0.3f; + } + + set_f(y_gain_tmp+10, 0.0f, MBANDS_GN-10); + idx_g = (short)vquant(y_gain_tmp, Mean_dic_NB, y_gain_tmp, Gain_dic1_NB, 3, 64); + push_indice( st, IND_Y_GAIN_TMP, idx_g, 6 ); + + if(core_brate < ACELP_9k60) + { + idx_g = (short)vquant(y_gain_tmp+3, Mean_dic_NB+3, y_gain_tmp+3, Gain_dic2_NB, 3, 32); + push_indice( st, IND_Y_GAIN_TMP, idx_g, 5 ); + + idx_g = (short)vquant(y_gain_tmp+6, Mean_dic_NB+6, y_gain_tmp+6, Gain_dic3_NB, 4, 16); + push_indice( st, IND_Y_GAIN_TMP, idx_g, 4 ); + } + else + { + idx_g = (short)vquant(y_gain_tmp+3, Mean_dic_NB+3, y_gain_tmp+3, Gain_dic2_NBHR, 3, 64); + push_indice( st, IND_Y_GAIN_TMP, idx_g, 6 ); + + idx_g = (short)vquant(y_gain_tmp+6, Mean_dic_NB+6, y_gain_tmp+6, Gain_dic3_NBHR, 4, 128); + push_indice( st, IND_Y_GAIN_TMP, idx_g, 7 ); + } + + if( core_brate <= ACELP_9k60 && coder_type == INACTIVE ) + { + /* Some energy is needed in high band for stat_noise_uv_enc() to be functional in inactive speech */ + y_gain_tmp[10] = mean(y_gain_tmp+6, 3); + y_gain_tmp[11] = mean(y_gain_tmp+7, 3); + y_gain_tmp[12] = mean(y_gain_tmp+8, 3); + y_gain_tmp[13] = mean(y_gain_tmp+9, 3); + y_gain_tmp[14] = mean(y_gain_tmp+10, 3); + y_gain_tmp[15] = mean(y_gain_tmp+11, 3); + } + else + { + set_f( y_gain_tmp + 10, 0, MBANDS_GN - 10 ); + } + } + else + { + ftmp1 = mean(y_gain4, 16); + for(i = 0; i < Mbands_gn; i++) + { + if(y_gain4[i] < ftmp1-0.6f) + { + y_gain_tmp2[i] = ftmp1-.6f; + } + else if(y_gain4[i] > ftmp1+0.6f) + { + y_gain_tmp2[i] = ftmp1+0.6f; + } + else + { + y_gain_tmp2[i] = y_gain4[i]; + } + } + + mean_4g[0] = mean(y_gain_tmp2, 16); + idx_g = (short)vquant(mean_4g, mean_m, mean_4g, mean_gain_dic, 1, 64); + push_indice( st, IND_MEAN_GAIN2, idx_g, 6 ); + + /* Subtraction of the average gain */ + for(i = 0; i < Mbands_gn; i++) + { + y_gain_tmp[i] = y_gain_tmp2[i] - mean_4g[0]; + } + + if( core_brate < ACELP_9k60 ) + { + /* prediction and quantization of the average gain */ + + /*--------------------------------------------------------------------------------------* + * Quantization of the first 8 bands + * Keep only 4 bands out of the last 8 bands + *--------------------------------------------------------------------------------------*/ + + mvr2r(y_gain_tmp, y_gain_tmp2, 8); + + y_gain_tmp2[8] = y_gain_tmp[8]; + y_gain_tmp2[9] = y_gain_tmp[10]; + y_gain_tmp2[10] = y_gain_tmp[12]; + y_gain_tmp2[11] = y_gain_tmp[14]; + + idx_g = 0; + idx_g = (short)vquant(y_gain_tmp2, YGain_mean_LR, y_gain_tmp2, YGain_dic1_LR, 3, 32); + push_indice( st, IND_Y_GAIN_TMP, idx_g, 5 ); + + idx_g = (short)vquant(y_gain_tmp2+3, YGain_mean_LR+3, y_gain_tmp2+3, YGain_dic2_LR, 4, 32); + push_indice( st, IND_Y_GAIN_TMP, idx_g, 5 ); + + /*----------------------------------------------------------------------* + * Vector quantization of the first 8 bands + quantization of the 4 bands out of the last 8 + * Interpolation of the last 4 bands Q to create bands 8-16 + *----------------------------------------------------------------------*/ + + idx_g = (short)vquant(y_gain_tmp2+7, YGain_mean_LR+7, y_gain_tmp2+7, YGain_dic3_LR, 5, 32); + push_indice( st, IND_Y_GAIN_TMP, idx_g, 5 ); + + set_f(y_gain_tmp2+12, 0, MBANDS_GN-12); + + /* Update to quantized vector */ + mvr2r(y_gain_tmp2, y_gain_tmp, 8); + + mvr2r(y_gain_tmp2+8, y_gain_tmp3, 4); + set_f(y_gain_tmp+8, 0,8); + fft_rel(y_gain_tmp2+8, 4, 2); + + mvr2r(y_gain_tmp2+8, y_gain_tmp+8, 3); + y_gain_tmp[15] = y_gain_tmp2[11]; + ifft_rel(y_gain_tmp+8, 8, 3); + + for(i = 8; i < 16; i++) + { + y_gain_tmp[i] *= 1.41f; + } + + y_gain_tmp[8] = y_gain_tmp3[0]; + y_gain_tmp[10]= y_gain_tmp3[1]; + y_gain_tmp[12]= y_gain_tmp3[2]; + y_gain_tmp[14]= y_gain_tmp3[3]; + } + else + { + idx_g = (short)vquant(y_gain_tmp, YG_mean16, y_gain_tmp, YG_dicMR_1, 4, 64); + push_indice( st, IND_Y_GAIN_TMP, idx_g, 6 ); + + idx_g = (short)vquant(y_gain_tmp+4, YG_mean16+4, y_gain_tmp+4, YG_dicMR_2, 4, 32); + push_indice( st, IND_Y_GAIN_TMP, idx_g, 5 ); + + idx_g = (short)vquant(y_gain_tmp+8, YG_mean16+8, y_gain_tmp+8, YG_dicMR_3, 4, 32); + push_indice( st, IND_Y_GAIN_TMP, idx_g, 5 ); + + idx_g = (short)vquant(y_gain_tmp+12, YG_mean16+12, y_gain_tmp+12, YG_dicMR_4, 4, 16); + push_indice( st, IND_Y_GAIN_TMP, idx_g, 4 ); + } + } + + /* Gain adjustment to fit ACELP generic inactive coding gain at low rate */ + if( coder_type == INACTIVE ) + { + Gain_off = 0.0f; + { + if(core_brate <= ACELP_7k20 ) + { + Gain_off = 8.f; /* 0 dB */ + } + else if (core_brate <= ACELP_8k00 ) + { + Gain_off = 6.6f; /* ~-3.3 dB */ + } + else if (core_brate <= ACELP_9k60 ) + { + Gain_off = 4.8f; /* ~-2.4 dB */ + } + else if (core_brate <= ACELP_11k60 ) + { + Gain_off = 3.5f; /* ~-2.4 dB */ + } + else if (core_brate <= ACELP_13k20 ) + { + Gain_off = 3.0f; /* ~-2.4 dB */ + } + } + + } + + if( coder_type != INACTIVE ) + { + for( i = 0; i < Mbands_gn; i++ ) + { + y_gainQ[i] = y_gain_tmp[i] + mean_4g[0]; + } + } + else + { + /*mimic ACELP decay of energy for low rates*/ + for( i = 0; i < Mbands_gn; i++ ) + { + y_gainQ[i] = y_gain_tmp[i]+mean_4g[0]-(i*(Gain_off/20.f)/((float) Mbands_gn)); + } + } + + return mean_4g[0]; +} + +/*-------------------------------------------------------------------* + * gsc_gaindec() + * + * Generic signal frequency band decoding and application + *-------------------------------------------------------------------*/ + +float gsc_gaindec( /* o : average frequency gain */ + Decoder_State *st, /* i/o: decoder state structure */ + float y_gainQ[], /* o : quantized gain per band */ + const long core_brate, /* i : core used */ + float old_y_gain[], /* i/o: AR gain quantizer for low rate */ + const short coder_type, /* i : coding type */ + const short bwidth /* i : input signal bandwidth */ +) +{ + short idx_g, i; + float mean_4g; + float Gain_off = 0.0; + short Mbands_gn = MBANDS_GN; + float y_gain_tmp3[MBANDS_GN]; + + if( (coder_type == AUDIO || coder_type == INACTIVE) && bwidth == NB ) + { + idx_g = (short) get_next_indice( st, 6 ); + VDQ_vec(&mean_4g, Gain_meanNB, Gain_mean_dicNB, idx_g, 1 ); + + idx_g = (short) get_next_indice( st, 6 ); + VDQ_vec(y_gainQ, Mean_dic_NB, Gain_dic1_NB, idx_g, 3 ); + + if(core_brate < ACELP_9k60) + { + idx_g = (short) get_next_indice( st, 5 ); + VDQ_vec(y_gainQ+3, Mean_dic_NB+3, Gain_dic2_NB, idx_g, 3 ); + + idx_g = (short) get_next_indice( st, 4 ); + VDQ_vec(y_gainQ+6, Mean_dic_NB+6, Gain_dic3_NB, idx_g, 4 ); + } + else + { + idx_g = (short) get_next_indice( st, 6 ); + VDQ_vec(y_gainQ+3, Mean_dic_NB+3, Gain_dic2_NBHR, idx_g, 3 ); + + idx_g = (short) get_next_indice( st, 7 ); + VDQ_vec(y_gainQ+6, Mean_dic_NB+6, Gain_dic3_NBHR, idx_g, 4 ); + } + + if( core_brate <= ACELP_9k60 && coder_type == INACTIVE ) + { + /* Some energy is needed in high band for stat_noise_uv_enc + to be functional in inactive speech */ + y_gainQ[10] = mean(y_gainQ+6, 3); + y_gainQ[11] = mean(y_gainQ+7, 3); + y_gainQ[12] = mean(y_gainQ+8, 3); + y_gainQ[13] = mean(y_gainQ+9, 3); + y_gainQ[14] = mean(y_gainQ+10, 3); + y_gainQ[15] = mean(y_gainQ+11, 3); + } + else + { + set_f( y_gainQ + 10, 0, MBANDS_GN-10 ); + } + } + else + { + idx_g = (short) get_next_indice( st, 6 ); + VDQ_vec(&mean_4g, mean_m, mean_gain_dic, idx_g, 1 ); + + if( core_brate < ACELP_9k60 ) + { + /*--------------------------------------------------------------------------------------* + * UQ of the first 8 bands and half of the last 8 bands + *--------------------------------------------------------------------------------------*/ + + idx_g = (short) get_next_indice( st, 5 ); + VDQ_vec(y_gainQ, YGain_mean_LR, YGain_dic1_LR, idx_g, 3 ); + + idx_g = (short) get_next_indice( st, 5 ); + VDQ_vec(y_gainQ+3, YGain_mean_LR+3, YGain_dic2_LR, idx_g, 4 ); + + /*----------------------------------------------------------------------* + * Interpolation of the last 4 Q bands to create bands 8-16 + * And scaling + *----------------------------------------------------------------------*/ + + idx_g = (short) get_next_indice( st, 5 ); + VDQ_vec(y_gainQ+7, YGain_mean_LR+7, YGain_dic3_LR, idx_g, 5 ); + + mvr2r(y_gainQ + 8, y_gain_tmp3, 4); + set_f(y_gainQ + 12, 0.0f, 4); + + fft_rel(y_gainQ + 8, 4, 2); + + y_gainQ[15] = y_gainQ[11]; + y_gainQ[11] = 0.0f; + + ifft_rel(y_gainQ + 8, 8, 3); + + for(i = 8; i < 16; i++) + { + y_gainQ[i] *= 1.41f; + } + + /*----------------------------------------------------------------------* + * Copy the true Q values in the specific bands + *----------------------------------------------------------------------*/ + + y_gainQ[8] = y_gain_tmp3[0]; + y_gainQ[10]= y_gain_tmp3[1]; + y_gainQ[12]= y_gain_tmp3[2]; + y_gainQ[14]= y_gain_tmp3[3]; + } + else + { + idx_g = (short) get_next_indice( st, 6 ); + VDQ_vec(y_gainQ, YG_mean16, YG_dicMR_1, idx_g, 4 ); + + idx_g = (short) get_next_indice( st, 5 ); + VDQ_vec(y_gainQ+4, YG_mean16+4, YG_dicMR_2, idx_g, 4 ); + + idx_g = (short) get_next_indice( st, 5 ); + VDQ_vec(y_gainQ+8, YG_mean16+8, YG_dicMR_3, idx_g, 4 ); + + idx_g = (short) get_next_indice( st, 4 ); + VDQ_vec(y_gainQ+12, YG_mean16+12, YG_dicMR_4, idx_g, 4); + } + } + + /* Gain adjustment to fit ACELP generic inactive coding gain at low rate */ + if( coder_type == INACTIVE ) + { + Gain_off = 0.0f; + { + if(core_brate <= ACELP_7k20 ) + { + Gain_off = 8.f; /* 0 dB */ + } + else if (core_brate <= ACELP_8k00 ) + { + Gain_off = 6.6f; /* ~-3.3 dB */ + } + else if (core_brate <= ACELP_9k60 ) + { + Gain_off = 4.8f; /* ~-2.4 dB */ + } + else if (core_brate <= ACELP_11k60 ) + { + Gain_off = 3.5f; /* ~-2.4 dB */ + } + else if (core_brate <= ACELP_13k20 ) + { + Gain_off = 3.0f; /* ~-2.4 dB */ + } + } + + } + + if( coder_type != INACTIVE ) + { + for( i = 0; i < Mbands_gn; i++ ) + { + old_y_gain[i] = y_gainQ[i]; + y_gainQ[i] += mean_4g; + } + } + else + { + /*mimic ACELP decay of energy for low rates*/ + for( i = 0; i < Mbands_gn; i++ ) + { + old_y_gain[i] = y_gainQ[i]; + y_gainQ[i] += mean_4g-i*(Gain_off/20.f)/((float) Mbands_gn); + } + } + + return mean_4g; +} + +/*-------------------------------------------------------------------* + * VDQ_vec() + * + * Return the dequantized vector of index + *-------------------------------------------------------------------*/ + +static short VDQ_vec( + float *Qvec_out, /* o: Quanitzed vector */ + const float *mean_dic, /* i: average codebook */ + const float *dic, /* i: codebook */ + const short index, /* i: index of codebook*/ + const short vec_en /* i: vector length */ +) +{ + short i, j; + + j = index*vec_en; + for ( i = 0; i < vec_en; i++) + { + Qvec_out[i] = dic[j++]; + } + + for(i = 0; i < vec_en; i++) + { + Qvec_out[i] += mean_dic[i]; + } + + return index; +} diff --git a/src/libs/libevs/lib_com/gs_gains_fx.cpp b/src/libs/libevs/lib_com/gs_gains_fx.cpp deleted file mode 100755 index ed98b108..00000000 --- a/src/libs/libevs/lib_com/gs_gains_fx.cpp +++ /dev/null @@ -1,673 +0,0 @@ -/*==================================================================================== - EVS Codec 3GPP TS26.442 Apr 03, 2018. Version 12.11.0 / 13.6.0 / 14.2.0 - ====================================================================================*/ - -#include "options.h" /* Compilation switches */ -#include "cnst_fx.h" /* Common constants */ -#include "rom_com_fx.h" /* Static table prototypes */ -#include "prot_fx.h" /* Function prototypes */ -#include "stl.h" - - -/*-------------------------------------------------------------------* - * Local constants - *-------------------------------------------------------------------*/ - -static Word16 VDQ_vec_fx( Word16 *Qvec_out_fx, const Word16 *mean_dic_fx, const Word16 *dic_fx, - const Word16 index_fx, const Word16 vec_en_fx ); - -/*========================================================================*/ -/* FUNCTION : void Comp_and_apply_gain_enc_fx */ -/*------------------------------------------------------------------------*/ -/* PURPOSE : Compute and apply the quantized per band gain */ -/*------------------------------------------------------------------------*/ -/* INPUT ARGUMENTS : */ -/* _ (Word16[]) Ener_per_bd_iQ : Target ener per band Q12 */ -/*------------------------------------------------------------------------*/ -/* INPUT/OUTPUT ARGUMENTS : */ -/* _ (Word16[]) exc_diffQ : Quantized excitation Qexc */ -/* _ (Word16[]) Ener_per_bd_yQ : Ener per band for norm vectori->Q12/o->Q2*/ -/*------------------------------------------------------------------------*/ -/* OUTPUT ARGUMENTS : */ -/* _ None */ -/*------------------------------------------------------------------------*/ - -/*------------------------------------------------------------------------*/ -/* RETURN ARGUMENTS : */ -/* _ None */ -/*========================================================================*/ -void Comp_and_apply_gain_fx( - Word16 exc_diffQ[], /* i/o: Quantized excitation */ - Word16 Ener_per_bd_iQ[], /* i : Target ener per band Q13 */ - Word16 Ener_per_bd_yQ[], /* i/o : Ener per band for norm vector i->Q13/o->Q13 */ - Word16 Mbands_gn, /* i : number of bands */ - const Word16 ReUseGain, /* i : Reuse the gain in Ener_per_bd_yQ */ - Word16 Qexc_diff, - Word16 Q_exc -) -{ - Word16 i, i_band; - Word16 StartBin, NB_Qbins; - Word16 y_gain; - Word16 L16, frac, exp1, tmp_exp; - Word32 L32; - - /* Recreate excitation for local synthesis and decoder */ - StartBin = 0; - move16(); - NB_Qbins = 0; - move16(); - - tmp_exp = add(14,sub(Q_exc,Qexc_diff)); /* In case of reuse, it can be computed outside the loop*/ - FOR( i_band = 0; i_band < Mbands_gn; i_band++ ) - { - StartBin = add(StartBin, NB_Qbins); - NB_Qbins = mfreq_bindiv_loc[i_band]; - move16(); - IF( sub(ReUseGain,1) == 0 ) - { - y_gain = Ener_per_bd_yQ[i_band]; - move16(); - - FOR(i = StartBin ; i < NB_Qbins + StartBin ; i++) - { - L32 = L_shl(L_mult(exc_diffQ[i], y_gain),tmp_exp); /*Q_exc+16 */ - exc_diffQ[i] = round_fx(L32);/*Q_exc */ - } - } - ELSE - { - /*-----------------------------------------------------------------* - * y_gain = pow(10.0, (Ener_per_bd_iQ[i_band]-Ener_per_bd_yQ[i_band])) - * = pow(2, 3.321928*(Ener_per_bd_iQ[i_band]-Ener_per_bd_yQ[i_band])) - *-----------------------------------------------------------------*/ - L16 = sub(Ener_per_bd_iQ[i_band], Ener_per_bd_yQ[i_band]);/*Q12 */ - L32 = L_mult(L16, 27213); /* 3.321928 in Q13 -> Q26 */ - L32 = L_shr(L32, 10); /* From Q26 to Q16 */ - frac = L_Extract_lc(L32, &exp1); /* Extract exponent of gcode0 */ - y_gain = extract_l(Pow2(14, frac));/* Put 14 as exponent so that */ - /* output of Pow2() will be: */ - /* 16384 < Pow2() <= 32767 */ - Ener_per_bd_yQ[i_band] = shl(y_gain, sub(exp1, 13)); - move16();/*Q1 */ - tmp_exp = add(add(exp1,1),sub(Q_exc,Qexc_diff)); - - FOR(i = StartBin ; i < NB_Qbins + StartBin ; i++) - { - L32 = L_mult(exc_diffQ[i], y_gain); /*Qexc_diff+15 */ - exc_diffQ[i] = round_fx(L_shl(L32,tmp_exp)); /*Q_exc */ - } - } - } - - return; -} - - -/*========================================================================*/ -/* FUNCTION : Ener_per_band_comp_fx() */ -/*------------------------------------------------------------------------*/ -/* PURPOSE : Compute the energy per band in log domain for quantization */ -/* purposes. */ -/* Loops are decomposed to accomodate the PVQ quantization */ -/*------------------------------------------------------------------------*/ -/* INPUT ARGUMENTS : */ -/* _ (Word16*) edct_table_128_fx : edct table Q15 */ -/* _ (Word16*) Q_exc_diff : input format of exc_diff */ -/*------------------------------------------------------------------------*/ -/* INPUT/OUTPUT ARGUMENTS : */ -/*------------------------------------------------------------------------*/ -/* OUTPUT ARGUMENTS : */ -/* _ (Word16[]) y_gain4 : Energy per band to quantize Q12 */ -/* _ (Word32*) etmp14 : Energy band 14 Q_exc_diff*2+1 */ -/* _ (Word32*) etmp15 : Energy band 15 Q_exc_diff*2+1 */ -/*------------------------------------------------------------------------*/ - -/*------------------------------------------------------------------------*/ -/* RETURN ARGUMENTS : */ -/* _ None */ -/*========================================================================*/ -static Word16 Comp_band_log_ener( /* o : Band gain Q12 */ - const Word16 *pt_fx, /* i : Dct input Q_sc */ - const Word16 Len, /* i : Lenght en energy accumulation */ - const Word16 Q_sc, /* i : scaling of input */ - const Word16 E_sc /* i : Additional scaling factor for energy */ -) -{ - Word32 L_tmp; - Word16 e_tmp, f_tmp, tmp16, ener_exp; - - /*for(i = 0; i < 8; i++){etmp += (*pt * *pt);pt++;}*/ - L_tmp = Calc_Energy_Autoscaled(pt_fx, Q_sc, Len, &ener_exp); - - /*y_gain4[j] = (float)log10(sqrt(etmp< Q12 */ - } - ELSE IF (L_sub(core_brate,ACELP_8k00) <= 0) - { - Gain_off = 27034; - move16(); /* 6.6f -> Q12 */ - } - ELSE IF (L_sub(core_brate,ACELP_9k60) <= 0) - { - Gain_off = 19661; - move16(); /*4.8f-> Q12 */ - } - ELSE IF (L_sub(core_brate,ACELP_11k60) <= 0) - { - Gain_off = 14336; - move16(); /* 3.5f -> Q12 */ - } - ELSE IF (L_sub(core_brate,ACELP_13k20) <= 0) - { - Gain_off = 12288; - move16(); /* 3.0f -> Q12 dB */ - } - - /*mimic ACELP decay of energy for low rates*/ - FOR( i = 0; i < MBANDS_GN; i++ ) - { - old_y_gain[i] = y_gain_tmp[i]; - move16(); - /*y_gainQ[i] = y_gain_tmp[i]+mean_4g[0]-(i*(Gain_off/20.f)/((float) Mbands_gn));*/ - y_gainQ[i] = add(y_gain_tmp[i], sub(mean_g, i_mult2(i, mult_r(Gain_off, 102)))); - move16(); - } - } - - return; -} -/*==========================================================================*/ -/* FUNCTION : Word16 gsc_gaindec_fx () */ -/*--------------------------------------------------------------------------*/ -/* PURPOSE : Generic signal frequency band decoding and application */ -/*--------------------------------------------------------------------------*/ -/* INPUT ARGUMENTS : */ -/* _ (Word16) pvq_bits_fx : core used Q0 */ -/* _ (Word16) coder_type_fx : coding type Q0 */ -/* _ (Word16) core_fx : core used Q0 */ -/* _ (Word16) bwidth_fx : input signal bandwidth Q0 */ -/*--------------------------------------------------------------------------*/ -/* OUTPUT ARGUMENTS : */ -/* _ (Word16[]) y_gainQ_fx : quantized gain per band */ -/*--------------------------------------------------------------------------*/ -/* INPUT/OUTPUT ARGUMENTS : */ -/* _ (Word16[]) old_y_gain_fx : AR gain quantizer for low rate */ -/*--------------------------------------------------------------------------*/ -/* RETURN ARGUMENTS : */ -/* _ (Word16) : average frequency gain */ -/*==========================================================================*/ - -Word16 gsc_gaindec_fx( /* o : average frequency gain */ - Decoder_State_fx *st_fx, /* i/o: decoder state structure */ - Word16 y_gainQ_fx[], /* o : quantized gain per band */ - const Word32 core_brate_fx, /* i : core used */ - Word16 old_y_gain_fx[], /* i/o: AR gain quantizer for low rate */ - const Word16 coder_type_fx, /* i : coding type */ - const Word16 bwidth_fx /* i : input signal bandwidth */ -) -{ - Word16 idx_g_fx, i; - Word16 mean_4g_fx; - Word16 y_gain_tmp3_fx[MBANDS_GN]; - - test(); - test(); - IF( (sub(coder_type_fx,AUDIO) == 0 || sub(coder_type_fx,INACTIVE) == 0) && sub(bwidth_fx,NB) == 0 ) - { - idx_g_fx = (Word16) get_next_indice_fx( st_fx, 6 ); - VDQ_vec_fx(&mean_4g_fx, Gain_meanNB_fx, Gain_mean_dicNB_fx, idx_g_fx, 1 ); - - idx_g_fx = (Word16) get_next_indice_fx( st_fx, 6 ); - move16(); - VDQ_vec_fx(y_gainQ_fx, Mean_dic_NB_fx, Gain_dic1_NB_fx, idx_g_fx, 3 ); - - IF(L_sub(core_brate_fx,ACELP_9k60) < 0) - { - idx_g_fx = (Word16) get_next_indice_fx( st_fx, 5 ); - VDQ_vec_fx(y_gainQ_fx+3, Mean_dic_NB_fx+3, Gain_dic2_NB_fx, idx_g_fx, 3 ); - - idx_g_fx = (Word16) get_next_indice_fx( st_fx, 4 ); - VDQ_vec_fx(y_gainQ_fx+6, Mean_dic_NB_fx+6, Gain_dic3_NB_fx, idx_g_fx, 4 ); - } - ELSE - { - idx_g_fx = (Word16) get_next_indice_fx( st_fx, 6 ); - VDQ_vec_fx(y_gainQ_fx+3, Mean_dic_NB_fx+3, Gain_dic2_NBHR_fx, idx_g_fx, 3 ); - - idx_g_fx = (Word16) get_next_indice_fx( st_fx, 7 ); - VDQ_vec_fx(y_gainQ_fx+6, Mean_dic_NB_fx+6, Gain_dic3_NBHR_fx, idx_g_fx, 4 ); - } - test(); - IF( L_sub(core_brate_fx,ACELP_9k60) <= 0 && sub(coder_type_fx,INACTIVE) == 0 ) - { - /* Some energy is needed in high band for stat_noise_uv_enc - to be functional in inactive speech */ - y_gainQ_fx[10] = mean_fx(y_gainQ_fx+6, 3); - move16(); - y_gainQ_fx[11] = mean_fx(y_gainQ_fx+7, 3); - move16(); - y_gainQ_fx[12] = mean_fx(y_gainQ_fx+8, 3); - move16(); - y_gainQ_fx[13] = mean_fx(y_gainQ_fx+9, 3); - move16(); - y_gainQ_fx[14] = mean_fx(y_gainQ_fx+10, 3); - move16(); - y_gainQ_fx[15] = mean_fx(y_gainQ_fx+11, 3); - move16(); - } - ELSE - { - set16_fx( y_gainQ_fx + 10, 0, MBANDS_GN - 10 ); - } - } - ELSE - { - idx_g_fx = (Word16) get_next_indice_fx( st_fx, 6 ); - - VDQ_vec_fx(&mean_4g_fx, mean_m_fx, mean_gain_dic_fx, idx_g_fx, 1 ); - - IF(L_sub(core_brate_fx,ACELP_9k60) <= 0) - { - /*--------------------------------------------------------------------------------------* - * UQ of the first 8 bands and half of the last 8 bands - *--------------------------------------------------------------------------------------*/ - idx_g_fx = (Word16) get_next_indice_fx( st_fx, 5 ); - VDQ_vec_fx(y_gainQ_fx, YGain_mean_LR_fx, YGain_dic1_LR_fx, idx_g_fx, 3 ); - - idx_g_fx = (Word16) get_next_indice_fx( st_fx, 5 ); - VDQ_vec_fx(y_gainQ_fx+3, YGain_mean_LR_fx+3, YGain_dic2_LR_fx, idx_g_fx, 4 ); - - /*----------------------------------------------------------------------* - * Interpolation of the last 4 Q bands to create bands 8-16 - * And scaling - *----------------------------------------------------------------------*/ - - idx_g_fx = (Word16) get_next_indice_fx( st_fx, 5 ); - - VDQ_vec_fx(y_gainQ_fx+7, YGain_mean_LR_fx+7, YGain_dic3_LR_fx, idx_g_fx, 5 ); - - Copy(y_gainQ_fx+8, y_gain_tmp3_fx, 4); - set16_fx(y_gainQ_fx+12, 0, 4); - - fft_rel_fx(y_gainQ_fx+8, 4, 2); - - y_gainQ_fx[15] = y_gainQ_fx[11]; - move16(); - y_gainQ_fx[11] = 0; - move16(); - ifft_rel_fx(y_gainQ_fx+8, 8, 3); - FOR(i = 8; i < 16; i++) - { - /*y_gainQ_fx[i] *= 1.41f;*/ - y_gainQ_fx[i] = round_fx(L_shl(L_mult(y_gainQ_fx[i] , 23101),1));/*Q12 */ - } - /*----------------------------------------------------------------------* - * Copy the true Q values in the specific bands - *----------------------------------------------------------------------*/ - y_gainQ_fx[8] = y_gain_tmp3_fx[0]; - move16(); - y_gainQ_fx[10]= y_gain_tmp3_fx[1]; - move16(); - y_gainQ_fx[12]= y_gain_tmp3_fx[2]; - move16(); - y_gainQ_fx[14]= y_gain_tmp3_fx[3]; - move16(); - } - ELSE - { - idx_g_fx = (Word16) get_next_indice_fx( st_fx, 6 ); - VDQ_vec_fx(y_gainQ_fx, YG_mean16_fx, YG_dicMR_1_fx, idx_g_fx, 4 ); - - idx_g_fx = (Word16) get_next_indice_fx( st_fx, 5 ); - VDQ_vec_fx(y_gainQ_fx+4, YG_mean16_fx+4, YG_dicMR_2_fx, idx_g_fx, 4 ); - - idx_g_fx = (Word16) get_next_indice_fx( st_fx, 5 ); - VDQ_vec_fx(y_gainQ_fx+8, YG_mean16_fx+8, YG_dicMR_3_fx, idx_g_fx, 4 ); - - idx_g_fx = (Word16) get_next_indice_fx( st_fx, 4 ); - VDQ_vec_fx(y_gainQ_fx+12, YG_mean16_fx+12, YG_dicMR_4_fx, idx_g_fx, 4 ); - } - } - - /* Gain adjustment to fit ACELP generic inactive coding gain at low rate */ - GSC_gain_adj(coder_type_fx, core_brate_fx, mean_4g_fx, old_y_gain_fx, y_gainQ_fx, y_gainQ_fx); - - return mean_4g_fx; - -} - -/*-------------------------------------------------------------------* - * gsc_gainQ() - * - * Quantization of the energy per band - *-------------------------------------------------------------------*/ -Word16 gsc_gainQ_fx( /*Q12*/ - Encoder_State_fx *st_fx, /* i/o: decoder state structure */ - const Word16 y_gain4[], /* i : Energy per band Q12 */ - Word16 y_gainQ[], /* o : quantized energy per band Q12 */ - const Word32 core_brate, /* i : Core rate */ - const Word16 coder_type, /* i : coding type */ - const Word16 bwidth /* i : input signal bandwidth */ -) -{ - Word16 y_gain_tmp[MBANDS_GN], y_gain_tmp2[MBANDS_GN]; - Word16 i, idx_g = 0; - Word16 mean_4g[1] = {0}, tmp16,tmp1, tmp2; - Word16 Mbands_gn = MBANDS_GN; - Word16 y_gain_tmp3[MBANDS_GN]; - Word16 cnt; - Word32 L_tmp; - - mean_4g[0] = 0; - - test(); - test(); - IF( (sub(coder_type,AUDIO) == 0 || sub(coder_type,INACTIVE) == 0) && sub(bwidth,NB) == 0 ) - { - - /*ftmp1 = mean(y_gain4, 10)-0.6f;*/ - L_tmp = L_deposit_l(0); - FOR(cnt = 0 ; cnt < 10 ; cnt++) - { - L_tmp = L_mac(L_tmp,y_gain4[cnt], 3277); - } - tmp16 = sub(round_fx(L_tmp), 4915); - - FOR(i = 0; i < Mbands_gn; i++) - { - y_gain_tmp2[i] = y_gain4[i]; - move16(); - /*if(y_gain4[i] < ftmp1-0.6f)*/ - y_gain_tmp2[i] = s_max(y_gain_tmp2[i], tmp16); - move16(); - } - - L_tmp = L_deposit_l(0); - FOR(i = 0; i < 10; i++) - { - L_tmp = L_mac(L_tmp,y_gain_tmp2[i], 3277); - } - - /* Quantized mean gain without clipping */ - mean_4g[0] = round_fx(L_tmp); - idx_g = vquant_fx(mean_4g, Gain_meanNB_fx, mean_4g, Gain_mean_dicNB_fx, 1, 64); - push_indice_fx( st_fx, IND_MEAN_GAIN2, idx_g, 6 ); - - FOR(i = 0; i < Mbands_gn; i++) - { - y_gain_tmp[i] = sub(y_gain_tmp2[i],mean_4g[0]); - move16(); - } - /*if(y_gain_tmp[9] < -0.3f){y_gain_tmp[9] = -0.3f;}*/ - y_gain_tmp[9] = s_max(y_gain_tmp[9], -1229); - move16(); - set16_fx(y_gain_tmp+10, 0, MBANDS_GN-10); - idx_g = vquant_fx(y_gain_tmp, Mean_dic_NB_fx, y_gain_tmp, Gain_dic1_NB_fx, 3, 64); - push_indice_fx( st_fx, IND_Y_GAIN_TMP, idx_g, 6 ); - - IF(L_sub(core_brate,ACELP_9k60) < 0) - { - idx_g = vquant_fx(y_gain_tmp+3, Mean_dic_NB_fx+3, y_gain_tmp+3, Gain_dic2_NB_fx, 3, 32); - push_indice_fx( st_fx, IND_Y_GAIN_TMP, idx_g, 5 ); - idx_g = vquant_fx(y_gain_tmp+6, Mean_dic_NB_fx+6, y_gain_tmp+6, Gain_dic3_NB_fx, 4, 16); - push_indice_fx( st_fx, IND_Y_GAIN_TMP, idx_g, 4 ); - } - ELSE - { - idx_g = vquant_fx(y_gain_tmp+3, Mean_dic_NB_fx+3, y_gain_tmp+3, Gain_dic2_NBHR_fx, 3, 64); - push_indice_fx( st_fx, IND_Y_GAIN_TMP, idx_g, 6 ); - idx_g = vquant_fx(y_gain_tmp+6, Mean_dic_NB_fx+6, y_gain_tmp+6, Gain_dic3_NBHR_fx, 4, 128); - push_indice_fx( st_fx, IND_Y_GAIN_TMP, idx_g, 7 ); - }/*add end */ - - test(); - IF( L_sub(core_brate,ACELP_9k60) <= 0 && sub(coder_type,INACTIVE) == 0 ) - { - /* Some energy is needed in high band for stat_noise_uv_enc - to be functional in inactive speech */ - y_gain_tmp[10] = round_fx(L_mac(L_mac(L_mult(y_gain_tmp[6],8192),y_gain_tmp[7],8192),y_gain_tmp[8],8192)); - y_gain_tmp[11] = round_fx(L_mac(L_mac(L_mult(y_gain_tmp[7],8192),y_gain_tmp[8],8192),y_gain_tmp[9],8192)); - - y_gain_tmp[12] = round_fx(L_mac(L_mac(L_mult(y_gain_tmp[8],8192),y_gain_tmp[9],8192),y_gain_tmp[10],8192)); - y_gain_tmp[13] = round_fx(L_mac(L_mac(L_mult(y_gain_tmp[9],8192),y_gain_tmp[10],8192),y_gain_tmp[11],8192)); - y_gain_tmp[14] = round_fx(L_mac(L_mac(L_mult(y_gain_tmp[10],8192),y_gain_tmp[11],8192),y_gain_tmp[12],8192)); - y_gain_tmp[15] = round_fx(L_mac(L_mac(L_mult(y_gain_tmp[11],8192),y_gain_tmp[12],8192),y_gain_tmp[13],8192)); - } - ELSE - { - set16_fx( y_gain_tmp + 10, 0, MBANDS_GN - 10 ); - } - } - ELSE - { - /*ftmp1 = mean(y_gain4, 16);*/ - - L_tmp =0; - FOR(cnt = 0 ; cnt < 16 ; cnt++) - { - L_tmp = L_mac(L_tmp,y_gain4[cnt], 2048); - } - tmp16 = round_fx(L_tmp); - - tmp1 = sub(tmp16,4915); - tmp2 = add(tmp16,4915); - L_tmp =0; - FOR(i = 0; i < 16; i++) - { - y_gain_tmp2[i] = y_gain4[i]; - move16(); - /*if(y_gain4[i] < ftmp1-0.6f)*/ - y_gain_tmp2[i] = s_max(y_gain_tmp2[i], tmp1); - move16(); - /*else if(y_gain4[i] > ftmp1+0.6f)*/ - y_gain_tmp2[i] = s_min(y_gain_tmp2[i], tmp2); - move16(); - L_tmp = L_mac(L_tmp,y_gain_tmp2[i], 2048); - } - FOR(; i < Mbands_gn; i++) - { - y_gain_tmp2[i] = y_gain4[i]; - /*if(y_gain4[i] < ftmp1-0.6f)*/ - y_gain_tmp2[i] = s_max(y_gain_tmp2[i], tmp1); /* Just the last move is needed, because s_max and s_min could be done in 1 line*/ - /*else if(y_gain4[i] > ftmp1+0.6f)*/ - y_gain_tmp2[i] = s_min(y_gain_tmp2[i], tmp2); - move16(); - } - - /* Quantized mean gain without clipping */ - mean_4g[0] = round_fx(L_tmp); - - - /*idx_g = (short)vquant(mean_4g, mean_m, mean_4g, mean_gain_dic, 1, 64);*/ - idx_g = vquant_fx(mean_4g, mean_m_fx, mean_4g, mean_gain_dic_fx, 1, 64); - push_indice_fx( st_fx, IND_MEAN_GAIN2, idx_g, 6 ); - - FOR(i = 0; i < Mbands_gn; i++) - { - y_gain_tmp[i] = sub(y_gain_tmp2[i],mean_4g[0]); - move16(); - } - - IF( L_sub(core_brate,ACELP_9k60) < 0 ) - { - /*mvr2r(y_gain_tmp, y_gain_tmp2, 8); */ - Copy(y_gain_tmp, y_gain_tmp2, 8); - - y_gain_tmp2[8] = y_gain_tmp[8]; - move16(); - y_gain_tmp2[9] = y_gain_tmp[10]; - move16(); - y_gain_tmp2[10] =y_gain_tmp[12]; - move16(); - y_gain_tmp2[11] =y_gain_tmp[14]; - move16(); - - idx_g = 0; - - /*idx_g = (short)vquant(y_gain_tmp2, YGain_mean_LR, y_gain_tmp2, YGain_dic1_LR, 3, 32);*/ - idx_g = vquant_fx(y_gain_tmp2, YGain_mean_LR_fx, y_gain_tmp2, YGain_dic1_LR_fx, 3, 32 ); - push_indice_fx( st_fx, IND_Y_GAIN_TMP, idx_g, 5 ); - /*idx_g = (short)vquant(y_gain_tmp2+3, YGain_mean_LR+3, y_gain_tmp2+3, YGain_dic2_LR, 4, 32);*/ - idx_g = vquant_fx(y_gain_tmp2+3, YGain_mean_LR_fx+3, y_gain_tmp2+3, YGain_dic2_LR_fx, 4, 32 ); - push_indice_fx( st_fx, IND_Y_GAIN_TMP, idx_g, 5 ); - /*idx_g = (short)vquant(y_gain_tmp2+7, YGain_mean_LR+7, y_gain_tmp2+7, YGain_dic3_LR, 5, 32);*/ - idx_g = vquant_fx(y_gain_tmp2+7, YGain_mean_LR_fx+7, y_gain_tmp2+7, YGain_dic3_LR_fx, 5, 32); - push_indice_fx( st_fx, IND_Y_GAIN_TMP, idx_g, 5 ); - /*set_f(y_gain_tmp2+12, 0, MBANDS_GN-12);*/ - set16_fx(y_gain_tmp2+12, 0, MBANDS_GN-12); - - /* Update to quantized vector */ - Copy(y_gain_tmp2, y_gain_tmp, 8); - - Copy(y_gain_tmp2+8, y_gain_tmp3, 4); - set16_fx(y_gain_tmp+8, 0,8); - fft_rel_fx(y_gain_tmp2+8, 4, 2); - - Copy(y_gain_tmp2+8, y_gain_tmp+8, 3); - y_gain_tmp[15] = y_gain_tmp2[11]; - ifft_rel_fx(y_gain_tmp+8, 8, 3); - - FOR(i = 8; i < 16; i++) - { - /*y_gain_tmp[i] *= 1.41f;*/ - y_gain_tmp[i] = shl( mult_r(y_gain_tmp[i] , 23101),1) ; - move16(); - } - - y_gain_tmp[8] = y_gain_tmp3[0]; - move16(); - y_gain_tmp[10]= y_gain_tmp3[1]; - move16(); - y_gain_tmp[12]= y_gain_tmp3[2]; - move16(); - y_gain_tmp[14]= y_gain_tmp3[3]; - move16(); - } - ELSE - { - idx_g = vquant_fx(y_gain_tmp, YG_mean16_fx, y_gain_tmp, YG_dicMR_1_fx, 4, 64); - push_indice_fx( st_fx, IND_Y_GAIN_TMP, idx_g, 6 ); - idx_g = vquant_fx(y_gain_tmp+4, YG_mean16_fx+4, y_gain_tmp+4, YG_dicMR_2_fx, 4, 32); - push_indice_fx( st_fx, IND_Y_GAIN_TMP, idx_g, 5 ); - idx_g = vquant_fx(y_gain_tmp+8, YG_mean16_fx+8, y_gain_tmp+8, YG_dicMR_3_fx, 4, 32); - push_indice_fx( st_fx, IND_Y_GAIN_TMP, idx_g, 5 ); - idx_g = vquant_fx(y_gain_tmp+12, YG_mean16_fx+12, y_gain_tmp+12, YG_dicMR_4_fx, 4, 16); - push_indice_fx( st_fx, IND_Y_GAIN_TMP, idx_g, 4 ); - } - } - - /* Gain adjustment to fit ACELP generic inactive coding gain at low rate */ - GSC_gain_adj(coder_type, core_brate, mean_4g[0], y_gain_tmp2 /* dummy buffer */, y_gain_tmp, y_gainQ); - - return mean_4g[0]; /*Q12*/ -} -/*-------------------------------------------------------------------* - * VDQ_vec() - * - * Return the dequantized vector of index - *-------------------------------------------------------------------*/ -static Word16 VDQ_vec_fx( - Word16 *Qvec_out_fx, /* o: Quanitzed vector */ - const Word16 *mean_dic_fx, /* i: average codebook */ - const Word16 *dic_fx, /* i: codebook */ - const Word16 index_fx, /* i: index of codebook*/ - const Word16 vec_en_fx /* i: vector length */ -) -{ - Word16 i, j; - - /*j = shr_r(extract_l(L_mult(index_fx,vec_en_fx)),1);*/ - j = i_mult2(index_fx,vec_en_fx); - FOR ( i = 0; i < vec_en_fx; i++) - { - Qvec_out_fx[i] = dic_fx[j++]; - move16(); - } - - FOR(i = 0; i < vec_en_fx; i++) - { - Qvec_out_fx[i] = add(Qvec_out_fx[i],mean_dic_fx[i]); - move16(); - } - - return index_fx; -} diff --git a/src/libs/libevs/lib_com/gs_inact_switching.cpp b/src/libs/libevs/lib_com/gs_inact_switching.cpp new file mode 100644 index 00000000..6aae8b21 --- /dev/null +++ b/src/libs/libevs/lib_com/gs_inact_switching.cpp @@ -0,0 +1,107 @@ +/*==================================================================================== + EVS Codec 3GPP TS26.443 Nov 13, 2018. Version 12.11.0 / 13.7.0 / 14.3.0 / 15.1.0 + ====================================================================================*/ + +#include +#include "options.h" +#include "cnst.h" +#include "rom_com.h" +#include "prot.h" + +/*-------------------------------------------------------------------* + * Local constants + *-------------------------------------------------------------------*/ + +#define ALPHA0 0.5f +#define BETA0 (1.0f-ALPHA0) + +/*-------------------------------------------------------------------* + * inact_switch_ematch() + * + * Apply energy matching when swithcing to INACTIVE frame coded by the GSC technology + *-------------------------------------------------------------------*/ + +void inact_switch_ematch( + float exc2[], /* i/o: CELP/GSC excitation buffer */ + float dct_exc_tmp[], /* i : GSC excitation in DCT domain */ + float lt_ener_per_band[], /* i/o: Long term energy per band */ + const short coder_type, /* i : Coding mode */ + const short L_frame, /* i : Frame lenght */ + const long core_brate, /* i : Core bit rate */ + const short bfi /* i : frame lost indicator */ + ,const short last_core, /* i : Last core used */ + const short last_codec_mode /* i : Last codec mode */ +) +{ + float Ener_per_bd[MBANDS_GN]; + float ftmp; + float *pt_exc; + short j, i; + + + /*-------------------------------------------------------------------------- + * average energy per band + *--------------------------------------------------------------------------*/ + + if( coder_type == AUDIO && bfi == 0) + { + Ener_per_band_comp( dct_exc_tmp, Ener_per_bd, MBANDS_GN, 1 ); + + /* reset long-term energy per band */ + for( i = 0; i < MBANDS_GN; i++ ) + { + lt_ener_per_band[i] = Ener_per_bd[i]; + } + } + else if( coder_type == VOICED || coder_type == GENERIC || coder_type == TRANSITION || last_core != ACELP_CORE || last_codec_mode != MODE1 ) + { + /* Find spectrum and energy per band for GC and VC frames */ + edct( exc2, dct_exc_tmp, L_frame ); + Ener_per_band_comp( dct_exc_tmp, Ener_per_bd, MBANDS_GN, 1 ); + + /* reset long-term energy per band */ + for(i = 0; i < MBANDS_GN; i++) + { + lt_ener_per_band[i] = Ener_per_bd[i]; + } + } + else if( coder_type == INACTIVE && core_brate <= ACELP_24k40 ) + { + /* Find spectrum and energy per band for inactive frames */ + edct( exc2, dct_exc_tmp, L_frame ); + Ener_per_band_comp( dct_exc_tmp, Ener_per_bd, MBANDS_GN, 1 ); + + /* More agressive smoothing in the first 50 frames */ + pt_exc = dct_exc_tmp; + for( i = 0; i < MBANDS_GN; i++ ) + { + /* Compute smoothing gain to apply with gain limitation */ + lt_ener_per_band[i] = ALPHA0*lt_ener_per_band[i] + BETA0*Ener_per_bd[i]; + + ftmp = lt_ener_per_band[i] - Ener_per_bd[i]; + ftmp = (float)pow(10, ftmp); + + if( i < 2 ) + { + for (j = 0; j < 8; j ++) + { + *pt_exc *= ftmp; + pt_exc++; + } + } + else + { + for (j = 0; j < 16; j ++) + { + *pt_exc *= ftmp; + pt_exc++; + } + } + } + + /* Going back to time */ + edct( dct_exc_tmp, exc2, L_frame ); + } + + return; +} diff --git a/src/libs/libevs/lib_com/gs_inact_switching_fx.cpp b/src/libs/libevs/lib_com/gs_inact_switching_fx.cpp deleted file mode 100755 index 3aa807dc..00000000 --- a/src/libs/libevs/lib_com/gs_inact_switching_fx.cpp +++ /dev/null @@ -1,153 +0,0 @@ -/*==================================================================================== - EVS Codec 3GPP TS26.442 Apr 03, 2018. Version 12.11.0 / 13.6.0 / 14.2.0 - ====================================================================================*/ - -#include "options.h" /* Compilation switches */ -#include "cnst_fx.h" /* Common constants */ -#include "rom_com_fx.h" /* Static table prototypes */ -#include "prot_fx.h" /* Function prototypes */ -#include "stl.h" - -/*-------------------------------------------------------------------* - * Local constants - *-------------------------------------------------------------------*/ - -#define ALPHA0_FX 13107 -#define BETA0_FX (32768-ALPHA0_FX) - -/*========================================================================*/ -/* FUNCTION : Inac_swtch_ematch_fx() */ -/*------------------------------------------------------------------------*/ -/* PURPOSE : Apply energy matching when swithcing to INACTIVE frame coded */ -/* by the GSC technology */ -/*------------------------------------------------------------------------*/ -/* INPUT ARGUMENTS : */ -/* _ (Word16) coder_type : Coding mode */ -/* _ (Word16) L_frame : Frame lenght */ -/* _ (Word32) core_brate : core bitrate */ -/*------------------------------------------------------------------------*/ -/* INPUT/OUTPUT ARGUMENTS : */ -/* _ (Word16[]) exc2 : CELP/GSC excitation buffer Q_exc */ -/* _ (Word16[]) lt_ener_per_band : Long term energy per band Q12 */ -/* _ (Word16*) Q_exc : input and output format of exc2 */ -/*------------------------------------------------------------------------*/ -/* OUTPUT ARGUMENTS : */ -/*------------------------------------------------------------------------*/ - -/*------------------------------------------------------------------------*/ -/* RETURN ARGUMENTS : */ -/* _ None */ -/*========================================================================*/ -void Inac_swtch_ematch_fx( - Word16 exc2[], /* i/o: CELP/GSC excitation buffer Q_exc*/ - Word16 dct_exc_tmp[], /* i : GSC excitation in DCT domain */ - Word16 lt_ener_per_band[], /* i/o: Long term energy per band Q12 */ - const Word16 coder_type, /* i : Coding mode */ - const Word16 L_frame, /* i : Frame lenght */ - const Word32 core_brate, /* i : Core bit rate */ - const Word16 Q_exc /* i : input and output format of exc2 */ - ,const Word16 bfi /* i : frame lost indicator */ - ,const Word16 last_core, /* i : Last core used */ - const Word16 last_codec_mode /* i : Last codec mode */ -) -{ - Word16 Ener_per_bd[MBANDS_GN]; - Word16 ftmp; - Word16 *pt_exc; - Word16 j, i; - - Word16 exp,frac; - Word32 L_tmp; - - /*-------------------------------------------------------------------------- - * average energy per band - *--------------------------------------------------------------------------*/ - - test(); - test(); - test(); - test(); - test(); - test(); - IF(sub(coder_type,AUDIO) == 0 && bfi == 0) - { - Ener_per_band_comp_fx( dct_exc_tmp, Ener_per_bd, Q_exc, MBANDS_GN, 1); - - /* reset long-term energy per band */ - FOR(i = 0; i < MBANDS_GN; i++) - { - lt_ener_per_band[i] = Ener_per_bd[i]; - move16(); - } - - } - ELSE IF( sub(coder_type,VOICED) == 0 || sub(coder_type,GENERIC) == 0 || sub(coder_type,TRANSITION) == 0 || sub(last_core,ACELP_CORE) != 0 || sub(last_codec_mode,MODE1) != 0 ) - { - /* Find spectrum and energy per band for GC and VC frames */ - edct_16fx( exc2, dct_exc_tmp, L_frame, 5 ); - - Ener_per_band_comp_fx( dct_exc_tmp, Ener_per_bd, Q_exc, MBANDS_GN, 1); - - /* reset long-term energy per band */ - FOR(i = 0; i < MBANDS_GN; i++) - { - lt_ener_per_band[i] = Ener_per_bd[i]; - move16(); - } - } - ELSE IF( sub(coder_type,INACTIVE) == 0 && L_sub(core_brate,ACELP_24k40) <= 0) - { - /* Find spectrum and energy per band for inactive frames */ - edct_16fx( exc2, dct_exc_tmp, L_frame, 5 ); - Ener_per_band_comp_fx( dct_exc_tmp, Ener_per_bd, Q_exc, MBANDS_GN, 1 ); - - /* More agressive smoothing in the first 50 frames */ - pt_exc = dct_exc_tmp; - move16(); - FOR(i = 0; i < MBANDS_GN; i++) - { - /* Compute smoothing gain to apply with gain limitation */ - L_tmp = L_mult(ALPHA0_FX,lt_ener_per_band[i]); /*Q(15+12+1)=Q(28) */ - L_tmp = L_mac(L_tmp,BETA0_FX,Ener_per_bd[i]); /*Q28 */ - lt_ener_per_band[i] = round_fx(L_tmp); /*Q12 */ - - ftmp = sub(lt_ener_per_band[i],Ener_per_bd[i]); /*Q12 */ - - /* ftmp = (float)pow(10, ftmp);= pow(2,3.321928*ftmp);*/ - - L_tmp = L_mult(27213,ftmp); /*Q(13+12+1)=Q26 ; 27213=3.321928 in Q13 */ - L_tmp = L_shr(L_tmp, 10); /* From Q26 to Q16 */ - frac = L_Extract_lc(L_tmp, &exp); /* Extract exponent of ftmp */ - ftmp = extract_l(Pow2(14, frac));/* Put 14 as exponent so that */ - /* output of Pow2() will be: */ - /* 16384 < Pow2() <= 32767 */ - - exp = sub(exp,14); - IF( sub(i,2) < 0 ) - { - FOR (j = 0; j < 8; j ++) - { - L_tmp = L_mult(*pt_exc,ftmp); /* Q_exc*Q0 -> Q(Q_exc+1) */ - L_tmp = L_shl(L_tmp, add(exp,15)); /* Q(Q_exc+1) -> Q(16+Q_exc)*/ - *pt_exc = round_fx(L_tmp); - pt_exc++; - } - } - ELSE - { - FOR (j = 0; j < 16; j ++) - { - L_tmp = L_mult(*pt_exc,ftmp); /* Q_exc*Q0 -> Q(Q_exc+1) */ - L_tmp = L_shl(L_tmp, add(exp,15)); /* Q(Q_exc+1) -> Q(16+Q_exc)*/ - *pt_exc = round_fx(L_tmp); /*Q_exc*/ - pt_exc++; - } - } - } - - /* Going back to time */ - edct_16fx( dct_exc_tmp, exc2, L_frame, 5 ); - } - - return; -} diff --git a/src/libs/libevs/lib_com/gs_noisefill.cpp b/src/libs/libevs/lib_com/gs_noisefill.cpp new file mode 100644 index 00000000..fd91976d --- /dev/null +++ b/src/libs/libevs/lib_com/gs_noisefill.cpp @@ -0,0 +1,686 @@ +/*==================================================================================== + EVS Codec 3GPP TS26.443 Nov 13, 2018. Version 12.11.0 / 13.7.0 / 14.3.0 / 15.1.0 + ====================================================================================*/ + +#include +#include "options.h" +#include "cnst.h" +#include "rom_com.h" +#include "prot.h" + + +/*-------------------------------------------------------------------* + * gs_noisf() + * + * Noise fill-in function + *-------------------------------------------------------------------*/ + +static void gs_noisf( + const short Start_BIN, /* i : First bin for noise fill */ + const short NB_Qbins, /* i : Number of bin per band */ + const float Noise_fac, /* i : Noise level */ + const float *y_norm, /* i : Quantized pulses */ + float *exc_diffQ, /* o : Quantized pulses with noise added */ + short *seed_tcx, /* i : Random generator seed */ + const short coder_type /* i : coder type */ +) +{ + float ftmp; + short i, k; + short NB_zer = NB_Qbins/2; + + if( coder_type == INACTIVE ) + { + NB_zer = 2; + } + + /*----------------------------------------------* + * noise fill-in on unquantized subvector * + * injected only from 1066Hz to 6400Hz. * + *----------------------------------------------*/ + + for( k=Start_BIN; k ACELP_24k40 ) + { + noise_offset = .2f; + } + else if( bitrate >= ACELP_22k60 ) + { + noise_offset = .3f; + } + else if( bitrate >= ACELP_9k60 ) + { + noise_offset = 0.35f; + } + else + { + noise_offset = .4f; + } + + set_f( noisepb + i_band, noise_offset, Mbands_gn - i_band ); + + for( i = i_band; i < 5; i++ ) + { + if( noisepb[i] > 0.2f ) + { + noisepb[i] = 0.2f; + } + } + + return; +} + + +/*-------------------------------------------------------------------* + * EstimateNoiseLevel() + * + * + *-------------------------------------------------------------------*/ + +static void EstimateNoiseLevel( + float *noisepb, /* o : Noise per band */ + const long bitrate, /* i : Bitrate of the codec */ + const short Diff_len, /* i : number of bin before cut-off frequency */ + const short Mbands_gn, /* i : number of bands */ + const short coder_type, /* i : coder type */ + const short noise_lev, /* i : pulses dynamic */ + const short pit_band_idx, /* i : bin position of the cut-off frequency */ + short last_bin, /* i : the last bin of bit allocation */ + short bwidth +) +{ + short i_band; + + i_band = 0; + + if( Diff_len < L_FRAME ) + { + EstimateNoiseLevel_inner(noisepb, bitrate, i_band, Mbands_gn); + + if( coder_type != INACTIVE ) + { + if( (bitrate == ACELP_8k00 && last_bin > 8) && bwidth != NB) + { + while(Mbands_gn > i_band ) + { + noisepb[i_band] *= 2.0f; + i_band++; + } + } + else + { + while(pit_band_idx > i_band ) + { + noisepb[i_band] /= 2.0f; + i_band++; + } + } + } + } + + if ( (coder_type == INACTIVE || noise_lev >= NOISE_LEVEL_SP3) ) + { + for( i_band = 9; i_band < Mbands_gn; i_band++ ) + { + noisepb[i_band] *= 1.15f; + } + } + + return; +} + + +/*-------------------------------------------------------------------* + * Apply_NoiseFill() + * + * + *-------------------------------------------------------------------*/ + +static void Apply_NoiseFill( + float *exc_diffQ, /* i/o: Noise per band */ + short *seed_tcx, /* i : Seed for noise */ + const float *noisepb, /* i : Noise per band */ + const short Diff_len, /* i : number of bin before cut-off frequency */ + const short Mbands_gn, /* i : number of bands */ + const short coder_type, /* i : coder type */ + const short *freq_nsbin_per_band /* i : bin per bands tables */ +) +{ + short StartBin, NB_Qbins, i_band; + StartBin = 0; + NB_Qbins = 0; + + for( i_band = 0; i_band < Mbands_gn; i_band++ ) + { + StartBin += NB_Qbins; + NB_Qbins = freq_nsbin_per_band[i_band]; + + if( Diff_len < L_FRAME ) + { + gs_noisf( StartBin, NB_Qbins, noisepb[i_band], exc_diffQ, exc_diffQ, seed_tcx, coder_type ); + } + } + + return; +} + + +/*-------------------------------------------------------------------* + * freq_dnw_scaling() + * + * + *-------------------------------------------------------------------*/ + +void freq_dnw_scaling( + const short cor_strong_limit, /* i : HF correlation */ + const short coder_type, /* i : coder type */ + const short noise_lev, /* i : Noise level */ + const long core_brate, /* i : Core bitrate */ + float fy_norm[] /* i/o: Frequency quantized parameter */ +) +{ + float sc_dyn; + short start_sc, i; + + sc_dyn = 1.0f; + start_sc = L_FRAME; + + if( core_brate <= ACELP_8k00 && coder_type == INACTIVE ) + { + sc_dyn *= .15f; + start_sc = 64; + } + else if( coder_type == INACTIVE ) + { + sc_dyn *= .25f; + start_sc = 80; + } + else + { + sc_dyn = (float)(NOISE_LEVEL_SP3 - noise_lev)/10.0f + 0.4f; + start_sc = 112 + (NOISE_LEVEL_SP3 - noise_lev) * 16; + + if( noise_lev == NOISE_LEVEL_SP0 ) + { + start_sc = L_FRAME; + } + } + + for(i = start_sc; i < L_FRAME; i++) + { + fy_norm[i] *= sc_dyn; + } + + if( (core_brate < ACELP_13k20 && cor_strong_limit == 0) || core_brate < ACELP_9k60) + { + for(i = 160; i < L_FRAME; i++) + { + if( fy_norm[i] > 1.0f ) + { + fy_norm[i] = 1.0f; + } + + if( fy_norm[i] < -1.0f ) + { + fy_norm[i] = -1.0f; + } + } + } + else if( core_brate < ACELP_22k60 ) + { + for(i = 160; i < L_FRAME; i++) + { + if( fy_norm[i] > 1.5f ) + { + fy_norm[i] = 1.5f; + } + + if( fy_norm[i] < -1.5f ) + { + fy_norm[i] = -1.5f; + } + } + } + + return; +} + + +/*-------------------------------------------------------------------* + * Decreas_freqPeak() + * + * + *-------------------------------------------------------------------*/ + +static void Decreas_freqPeak( + float *lsf_new, /* i : ISFs at the end of the frame */ + float *exc_diffQ, /* i/o: frequency coefficients of per band */ + float thr_rat /* i : threshold of ratio between consecutive lsf_new_diff */ +) +{ + short i, j, k; + short last_bin = 0; + short pos = 0; + float *src; + float avrg, max; + float lsf_new_diff[M]; + lsf_new_diff[0] = 0; /* prevent unitialized value */ + for(j=1; j<(M-1); j++) + { + lsf_new_diff[j] = lsf_new[j] - lsf_new[j-1]; + } + + avrg = 0.0f; + /* This is to prevent a possible div by 0 in the '*(src) = (*src > 0) ?...' + loop. The value of 'max' is not important because it will be mutiplied + by 'avrg' and the result will be close to 0. The 'fabs(*src)/max' + div by 0 error will be avoided. */ + max = 0.001f; + for(i=160; i max) + { + max = (float)fabs(exc_diffQ[i]); + pos = i; + } + avrg += (float)fabs(exc_diffQ[i]); + } + avrg /= 96; + last_bin = M-1; /* When the search is false, should equate the end of the vector, not the beginning */ + for(i=0; i<(M-1); i++) + { + if(lsf_new[i] > 4000) + { + last_bin = i; + break; + } + } + + for(i=last_bin; i<14; i++) + { + if( lsf_new_diff[i] < thr_rat*lsf_new_diff[i-1] ) + { + src = &exc_diffQ[(i-1)*16]; + for(j=0; j<2; j++) + { + for(k=0; k<16; k++) + { + if(fabs(*src) > 2.0f*avrg) + { + *(src) = (*src > 0) ? (float)(avrg*(2.0f-fabs(*src)/max)) : (float)(-avrg*(2.0f-fabs(*src)/max)); + } + src++; + } + } + } + } + + if(fabs(exc_diffQ[pos]) == max && max > 4.0f*avrg) + { + for(i=pos-1; i 8 || Diff_len != 0) && last_coder_type == AUDIO) + { + MAX_Bin = 10; + bwe_flag = 1; + } + else + { + MAX_Bin = 15; + } + + last_bin_tmp = last_bin; + if(last_bin < MAX_Bin) + { + last_bin = MAX_Bin; + } + last_bin += 1; + } + else + { + last_bin = MBANDS_GN; + last_bin_tmp = last_bin; + } + + if( bfi ) + { + set_f( noisepb, 0.4f, MBANDS_GN ); + } + else + { + EstimateNoiseLevel( noisepb, core_brate, Diff_len, last_bin, coder_type, noise_lev, pit_band_idx, last_bin_tmp, bwidth ); + } + + if( exc_wo_nf != NULL ) + { + mvr2r( exc_diffQ, exc_wo_nf, L_FRAME ); + } + + if( GSC_noisy_speech && !bfi ) + { + set_f( noisepb, 0.1f, MBANDS_GN ); + } + + Apply_NoiseFill( exc_diffQ, seed_tcx, noisepb, Diff_len, last_bin, coder_type, mfreq_bindiv ); + + /*--------------------------------------------------------------------------------------* + * Quantize average gain + * Substract Q averaged gain + * VQ of remaining gain per band + *--------------------------------------------------------------------------------------*/ + + if( core_brate == ACELP_8k00 && bwidth != NB ) + { + Ener_per_band_comp( exc_diffQ, Ener_per_bd_yQ, last_bin+1, 0 ); + } + else + { + Ener_per_band_comp( exc_diffQ, Ener_per_bd_yQ, MBANDS_GN, 1 ); + + if( nb_subfr < 4 ) + { + for( i = L_FRAME-16; i < L_FRAME; i++ ) + { + exc_diffQ[i] *= (0.067f * i - 15.0f); + } + } + } + /*--------------------------------------------------------------------------------------* + * Check potential energy excitation overshoot + *--------------------------------------------------------------------------------------*/ + if( bfi ) + { + if (GSC_noisy_speech == 0 && coder_type > UNVOICED) /* Here coder_type == last_coder_type because of the bfi */ + { + for( i=0; i end) + { + *src-- = *dst--; + } + + if( (bitallocation_exc[0] != 0 || bitallocation_exc[1] != 0) && core_brate == ACELP_8k00 ) + { + exc_diffQ[160] = 0.0f; + } + + envelop_modify(exc_diffQ, seed_tcx, last_bin, Ener_per_bd_iQ); + + mvr2r( &exc_diffQ[last_bin*16], &exc_dct_in[last_bin*16], L_FRAME-last_bin*16 ); + } + + if( nb_subfr < 4 ) + { + for( i = L_FRAME-16; i < L_FRAME; i++ ) + { + exc_dct_in[i] *= (0.067f*i-15.f); + } + } + + if( ener < 2*(*last_ener) && ener > 0.5f*(*last_ener) ) + { + length_bin = 6; + if(last_coder_type != AUDIO) + { + set_s( last_bitallocation_band, 0, 6 ); + mvr2r( &exc_dct_in[(4+length_bin)*16], &last_exc_dct_in[(4+length_bin)*16], length_bin*16 ); + } + + for(i=4; i<(4+length_bin); i++) + { + if( !(bitallocation_band[i] == 0 && last_bitallocation_band[i-4] == 0)) + { + src = &exc_dct_in[(i+length_bin)*16]; + dst = &last_exc_dct_in[(i+length_bin)*16]; + for(j=0; j<16; j++) + { + if(fabs(*src) > 3.0f*fabs(*dst)) + { + *src = (*src > 0) ? (float)(0.5f*(*src + fabs(*dst))) : (float)(0.5f*(*src - fabs(*dst))); + } + else if(fabs(*dst) > 3.0f*fabs(*src)) + { + *src = (*src > 0) ? (float)(0.7f*(*src) + 0.3f*fabs(*dst)) : (float)(0.7f*(*src) - 0.3f*fabs(*dst)); + } + src++; + dst++; + } + } + } + } + + if( bwe_flag == 1 ) + { + Decreas_freqPeak( lsf_new, exc_dct_in, 0.3f ); + } + else + { + Decreas_freqPeak( lsf_new, exc_dct_in, 0.5f ); + } + } + + mvr2r( &exc_dct_in[64], &last_exc_dct_in[64], L_FRAME-64 ); + mvs2s( &bitallocation_band[4], last_bitallocation_band, 6 ); + *last_ener = ener; + + return; +} diff --git a/src/libs/libevs/lib_com/gs_noisefill_fx.cpp b/src/libs/libevs/lib_com/gs_noisefill_fx.cpp deleted file mode 100755 index 403432dc..00000000 --- a/src/libs/libevs/lib_com/gs_noisefill_fx.cpp +++ /dev/null @@ -1,921 +0,0 @@ -/*==================================================================================== - EVS Codec 3GPP TS26.442 Apr 03, 2018. Version 12.11.0 / 13.6.0 / 14.2.0 - ====================================================================================*/ - -#include "options.h" -#include "rom_com_fx.h" -#include "prot_fx.h" -#include "stl.h" - -/*-------------------------------------------------------------------* - * gs_noisf() - * - * Noise fill-in function - *-------------------------------------------------------------------*/ - -static void gs_noisf_fx( - const Word16 Start_BIN, /* i : First bin for noise fill */ - const Word16 NB_Qbins, /* i : Number of bin per band */ - const Word16 Noise_fac, /* i : Noise level Q15 */ - const Word16 *y_norm, /* i : Quantized pulses Qn */ - Word16 *exc_diffQ, /* o : Quantized pulses with noise added Qn */ - Word16 *seed_tcx, /* i : Random generator seed */ - const Word16 coder_type, /* i : coder type */ - Word16 qNoise_fac -) -{ - Word32 ftmp; - Word16 i, k; - Word16 NB_zer; - Word32 const_1=1; - Word16 tmp; - - NB_zer = shr(NB_Qbins,1); - - const_1 = L_shl(const_1, add(qNoise_fac, qNoise_fac)); - if( sub(coder_type,INACTIVE) == 0 ) - { - NB_zer = 2; - move16(); - } - - /*----------------------------------------------* - * noise fill-in on unquantized subvector * - * injected only from 1066Hz to 6400Hz. * - *----------------------------------------------*/ - - FOR( k=Start_BIN; k ACELP_24k40 ) - { - noise_offset = 6554; - move16(); /*.2f * 32768 */ - } - ELSE IF ( bitrate >= ACELP_22k60 ) - { - noise_offset = 9830; - move16();/*.3f * 32768 */ - } - ELSE IF ( bitrate >= ACELP_9k60 ) - { - noise_offset = 11469; - move16(); /*0.35f * 32768 */ - } - ELSE - { - noise_offset = 13107; - move16(); /*.4f * 32768 */ - } - - set16_fx( noisepb + i_band, noise_offset, sub(Mbands_gn, i_band) ); - - FOR( i = i_band; i < 5; i++ ) - { - noisepb[i] = s_min(noisepb[i], 6554); - move16(); - } - - return; -} -/*==========================================================================*/ -/* FUNCTION : void EstimateNoiseLevel_fx() */ -/*--------------------------------------------------------------------------*/ -/* PURPOSE : */ -/*--------------------------------------------------------------------------*/ -/* INPUT ARGUMENTS : */ -/* _ (Word32) bitrate : Bitrate of the codec Q0 */ -/* _ (Word16) Diff_len : number of bin before cut-off frequency */ -/* _ (Word16) Mbands_gn : number of bands Q0 */ -/* _ (Word16) coder_type : coder type Q0 */ -/* _ (Word16) noise_lev : pulses dynamic Q0 */ -/* _ (Word16) pit_band_idx : bin position of the cut-off frequency */ -/* _ (Word16*) freq_nsbin_per_band : bin per bands tables Q0 */ -/*--------------------------------------------------------------------------*/ -/* OUTPUT ARGUMENTS : */ -/* _ (Word16*) noisepb : Noise per band Q15 */ -/*--------------------------------------------------------------------------*/ -/* INPUT/OUTPUT ARGUMENTS : */ -/* None */ -/*--------------------------------------------------------------------------*/ -/* RETURN ARGUMENTS : */ -/* _ None */ -/*==========================================================================*/ -static void EstimateNoiseLevel_fx( - Word16 *noisepb, /* o : Noise per band */ - const Word32 bitrate, /* i : Bitrate of the codec */ - const Word16 Diff_len, /* i : number of bin before cut-off frequency */ - const Word16 Mbands_gn, /* i : number of bands */ - const Word16 coder_type, /* i : coder type */ - const Word16 noise_lev, /* i : pulses dynamic */ - const Word16 pit_band_idx, /* i : bin position of the cut-off frequency */ - Word16 last_bin, /* i : the last bin of bit allocation */ - Word16 bwidth -) -{ - Word16 i_band; - - i_band = 0; - move16(); - - IF( sub(Diff_len,L_FRAME) < 0) - { - EstimateNoiseLevel_inner_fx(noisepb, bitrate, i_band, MBANDS_GN); - IF( coder_type != INACTIVE ) - { - test(); - test(); - IF( (L_sub(bitrate,ACELP_8k00) == 0 && sub(last_bin,8) > 0) && sub(bwidth,NB) != 0) - { - FOR( ; Mbands_gn > i_band; i_band++) - { - noisepb[i_band] = add(noisepb[i_band],noisepb[i_band]); - move16(); - } - } - ELSE - { - FOR( ; pit_band_idx > i_band; i_band++ ) - { - noisepb[i_band] = mult_r(noisepb[i_band], 16384); - move16();/* 1/2=0.5 in Q15 */ - } - } - } - } - test(); - IF ( (sub(coder_type,INACTIVE) == 0 || sub(noise_lev,NOISE_LEVEL_SP3) >= 0) ) - { - FOR( i_band = 9; i_band < Mbands_gn; i_band++ ) - { - noisepb[i_band] = add(noisepb[i_band], mult_r(noisepb[i_band], 4915)); - move16();/*noisepb[i_band]*1.15=noisepb[i_band] *(1 + 0.15) */ - } - } - - return; -} - -/*============================================================================*/ -/* FUNCTION : void Appy_NoiseFill_fx() */ -/*----------------------------------------------------------------------------*/ -/* PURPOSE : */ -/*----------------------------------------------------------------------------*/ -/* INPUT ARGUMENTS : */ -/* _ (Word16*) seed_tcx : Seed for noise Q0 */ -/* _ (Word16*) noisepb : Noise per band Q15 */ -/* _ (Word16) Diff_len : number of bin before cut-off frequency Q0 */ -/* _ (Word16) Mbands_gn : number of bands Q0 */ -/* _ (Word16) coder_type : pulses dynamic Q0 */ -/* _ (Word16*) freq_nsbin_per_band: bin per bands tables Q0 */ -/* _ (Word16) qexc_diffQ : Q format of exc_diffQ */ -/*----------------------------------------------------------------------------*/ -/* OUTPUT ARGUMENTS : */ -/* _ (Word16*) exc_diffQ : Noise per band qexc_diffQ */ -/*----------------------------------------------------------------------------*/ -/* INPUT/OUTPUT ARGUMENTS : */ -/* None */ -/*----------------------------------------------------------------------------*/ -/* RETURN ARGUMENTS : */ -/* _ None */ -/*============================================================================*/ -static void Apply_NoiseFill_fx( - Word16 *exc_diffQ, /* i/o: Noise per band qexc_diffQ */ - Word16 *seed_tcx, /* i : Seed for noise */ - const Word16 *noisepb, /* i : Noise per band Q15 */ - const Word16 Diff_len, /* i : number of bin before cut-off frequency */ - const Word16 Mbands_gn, /* i : number of bands */ - const Word16 coder_type, /* i : coder type */ - const Word16 *freq_nsbin_per_band, /* i : bin per bands tables */ - Word16 qexc_diffQ -) -{ - Word16 StartBin, NB_Qbins, i_band; - StartBin = 0; - move16(); - NB_Qbins = 0; - move16(); - - FOR( i_band = 0; i_band < Mbands_gn; i_band++ ) - { - StartBin += NB_Qbins; - move16(); - NB_Qbins = freq_nsbin_per_band[i_band]; - move16(); - - IF( sub(Diff_len,L_FRAME) < 0 ) - { - gs_noisf_fx( StartBin , NB_Qbins, noisepb[i_band], exc_diffQ, exc_diffQ, seed_tcx, coder_type, qexc_diffQ); - } - } - - return; -} -/*==========================================================================*/ -/* FUNCTION :void freq_dnw_scaling_fx () */ -/*--------------------------------------------------------------------------*/ -/* PURPOSE : */ -/*--------------------------------------------------------------------------*/ -/* INPUT ARGUMENTS : */ -/* _ (Word16) cor_strong_limit : HF correlation Q0 */ -/* _ (Word16) coder_type : coder type Q0 */ -/* _ (Word16) noise_lev : Noise level Q0 */ -/* _ (Word32) core_brate : Core bitrate Q0 */ -/* _ (Word16) Qx : Q format of fy_norm */ -/*--------------------------------------------------------------------------*/ -/* OUTPUT ARGUMENTS : */ -/* _ None */ -/*--------------------------------------------------------------------------*/ -/* INPUT/OUTPUT ARGUMENTS : */ -/* _ (Word16[]) fy_norm : Frequency quantized parameter Qx */ -/*--------------------------------------------------------------------------*/ -/* RETURN ARGUMENTS : */ -/* _None */ -/*==========================================================================*/ -void freq_dnw_scaling_fx( - const Word16 cor_strong_limit, /* i : HF correlation */ - const Word16 coder_type, /* i : coder type */ - const Word16 noise_lev, /* i : Noise level */ - const Word32 core_brate, /* i : Core bitrate */ - Word16 fy_norm[], /* i/o: Frequency quantized parameter */ - Word16 Qx /* Q format of fy_norm*/ -) -{ - Word16 sc_dyn; - Word16 start_sc, i; - - sc_dyn = 32767; - move16(); /*Q15 */ - start_sc = L_FRAME; - move16(); - test(); - IF( L_sub(core_brate,ACELP_8k00) <= 0 && sub(coder_type,INACTIVE) == 0 ) - { - sc_dyn = mult_r(sc_dyn,4915); /*Q15 (0.15 in Q15) */ - start_sc = 64; - move16(); - } - ELSE IF ( sub(coder_type,INACTIVE) == 0 ) - { - sc_dyn = mult_r(sc_dyn,8192); /*Q15 (0.25 in Q15) */ - start_sc = 80; - move16(); - } - ELSE - { - /*sc_dyn = (float)(NOISE_LEVEL_SP3 - noise_lev)/10.0f + 0.4f;*/ - sc_dyn = extract_l(L_mac(13107, sub(NOISE_LEVEL_SP3, noise_lev), 1638)); /*Q0*Q14x2+Q15 =Q15*/ - start_sc = add(112, shl(sub(NOISE_LEVEL_SP3, noise_lev), 4)); - if( sub(noise_lev,NOISE_LEVEL_SP0) == 0) - { - start_sc = L_FRAME; - move16(); - } - } - - FOR(i = start_sc; i < L_FRAME; i++) - { - fy_norm[i] = mult_r(fy_norm[i],sc_dyn); - move16();/*Qx */ - } - - test(); - test(); - IF( (L_sub(core_brate,ACELP_13k20) < 0 && cor_strong_limit == 0) || L_sub(core_brate,ACELP_9k60) < 0) - { - FOR(i = 160; i < L_FRAME; i++) - { - fy_norm[i] = s_min(fy_norm[i],shl(1,Qx)); - move16(); - fy_norm[i] = s_max(fy_norm[i],shl(-1,Qx)); - move16(); - } - } - ELSE IF ( L_sub(core_brate,ACELP_22k60) < 0 ) - { - FOR(i = 160; i < L_FRAME; i++) - { - fy_norm[i] = s_min(fy_norm[i],shr_r(1536,sub(10,Qx))); - move16(); - fy_norm[i] = s_max(fy_norm[i],shr_r(-1536,sub(10,Qx))); - move16(); - } - } - - return; - -} - -static void Decreas_freqPeak_fx( - Word16 *lsf_new, /* i : ISFs at the end of the frame */ - Word16 *exc_diffQ, /* i/o: frequency coefficients of per band */ - Word16 rat /* i : threshold of ratio between consecutive lsf_new_diff */ -) -{ - Word16 i, j, k; - Word16 last_bin = 0; - Word16 pos = 0; - Word16 *src, max,avrg; - Word32 L_avrg,L_tmp; - Word16 lsf_new_diff[M]; - Word16 tmp,tmp1,exp; - Word16 tmp2; - - move16(); /*ptr init*/ - lsf_new_diff[0] = 0; /* prevent unitialized value */ - FOR(j=1; j<(M-1); j++) - { - lsf_new_diff[j] =sub( lsf_new[j] , lsf_new[j-1]);/*Qx2.56 */ - } - - avrg = 0; - move16(); - L_avrg = L_deposit_l(0); - max = 1; - move16(); - FOR(i=160; i 0) - { - max = abs_s(exc_diffQ[i]); - pos = i; - move16(); - } - L_avrg = L_add(L_avrg,abs_s(exc_diffQ[i])); - } - /* avrg /= 96; */ - L_avrg = Mult_32_16(L_avrg,21845);/*Q_exc+21 -15 ->Q_exc + 6 */ - avrg = round_fx(L_shl(L_avrg,10));/*Q_exc */ - last_bin = M-1; - move16(); /* When the search is false, should equate the end of the vector, not the beginning */ - FOR(i=0; i<(M-1); i++) - { - if(sub(lsf_new[i],10240) > 0) - { - last_bin = i; - move16(); - BREAK; - } - } - - FOR(i=last_bin; i<14; i++) - { - tmp = mult_r(rat,lsf_new_diff[i-1] );/*Qx2.56 */ - IF(sub(tmp , lsf_new_diff[i])>0) - { - src = &exc_diffQ[shl(sub(i,1),4)]; - move16(); - FOR(j=0; j<2; j++) - { - FOR(k=0; k<16; k++) - { - tmp = mult_r(16384,abs_s(*src)); - IF(sub(tmp,avrg)>0) - { - tmp = abs_s(*src) ; - exp = norm_s(max); - tmp1 = div_s(shl(1,sub(14,exp)),max);/*Q(29 - exp - Q_exc) */ - L_tmp = L_mult(tmp,tmp1);/*Q(30 - exp) */ - tmp = round_fx(L_shl(L_tmp,exp));/*Q14 */ - tmp = sub(32767,tmp);/*Q14 */ - L_tmp = L_mult(avrg,tmp);/*Q_exc +15 */ - - tmp = round_fx(L_shl(L_tmp,1)); - tmp1 = negate(tmp); - - tmp2 = *src; - *(src) = tmp1; - move16(); - if( tmp2 > 0 ) - { - *(src) = tmp; - move16(); - } - - } - src++; - } - } - } - } - - tmp = mult_r(8192,max);/*Q_exc */ - test(); - IF(sub(abs_s(exc_diffQ[pos]),max) == 0 && sub(tmp ,avrg)>0) - { - FOR(i=pos-1; iQ(2*Q_exc-7) */ - - exp1 = norm_l(Ener_fx); - Ener_fx = L_shl(Ener_fx, exp1); - exp1 = 31-exp1-sub(shl(Q_exc,1),7); - move16(); - Ener_fx = Isqrt_lc(Ener_fx, &exp1); /*Q(31-exp1) */ - - weight_fx = 16384; /*Q15 */ - src_fx = &exc_diffQ_fx[start_band]; /*Q_exc */ - FOR(i=last_bin; i Q16 */ - - frac = L_Extract_lc(L_tmp, &exp); /* Extract exponent of L_tmp */ - tmp = extract_l(Pow2(14, frac));/* Put 14 as exponent so that */ - /* output of Pow2() will be: */ - /* 16384 < Pow2() <= 32767 */ - exp = sub(exp, 14); - Ener1_fx = mult_r(13107, shl(tmp, exp)); /*Q0 */ - - FOR(j=0; j<16; j++) - { - /**src = Ener1*(weight*(*src)*Ener + (1.0f-weight)*own_random(seed_tcx)/32768.0f); */ - L_tmp = Mult_32_16(Ener_fx, *src_fx); /*Q(31-exp+Q_exc-15) -> Q(16-exp+Q_exc) */ - tmp = extract_l(L_shr(L_tmp, add(4, sub(Q_exc, exp1)))); /*Q12 */ - tmp = mult_r(weight_fx, tmp); /*Q12 */ - - L_tmp = L_mult0(sub(32767, weight_fx), Random(seed_tcx)); /*Q30 */ - tmp1 = round_fx(L_shr(L_tmp, 2)); - - L_exc_diffQ_fx[16*i+j] = L_mult0(Ener1_fx, add(tmp, tmp1)); /*Q12 */ move32(); - src_fx++; - } - } - - /*Ener1 = (float)(0.4f*pow(10, Ener_per_bd_iQ[15])); */ - L_tmp = L_shr(L_mult0(Ener_per_bd_iQ_fx[15], 27213), 9); /* 3.321928 in Q13 -> Q16 */ - - frac = L_Extract_lc(L_tmp, &exp); /* Extract exponent of L_tmp */ - tmp = extract_l(Pow2(14, frac));/* Put 14 as exponent so that */ - /* output of Pow2() will be: */ - /* 16384 < Pow2() <= 32767 */ - exp = sub(exp, 14); - Ener1_fx = mult_r(13107, shl(tmp, exp)); /*Q0 */ - - src_fx = &exc_diffQ_fx[224]; - FOR(j=0; j<32; j++) - { - /**src = Ener1*(weight*(*src)*Ener + (1.0f-weight)*own_random(seed_tcx)/32768.0f); */ - L_tmp = Mult_32_16(Ener_fx, *src_fx); /*Q(31-exp+Q_exc-15) -> Q(16-exp+Q_exc) */ - tmp = extract_l(L_shr(L_tmp, add(4, sub(Q_exc, exp1)))); /*Q12 */ - tmp = mult_r(weight_fx, tmp); /*Q12 */ - - L_tmp = L_mult0(sub(32767, weight_fx), Random(seed_tcx)); /*Q30 */ - tmp1 = round_fx(L_shr(L_tmp, 2)); /*Q12 */ - - L_exc_diffQ_fx[16*i+j] = L_mult0(Ener1_fx, add(tmp, tmp1)); /*Q12 */ move32(); - src_fx++; - } - - exc_diffQ_max = 0; - move16(); - FOR(i=start_band; i 0) - { - exc_diffQ_max = L_abs(L_exc_diffQ_fx[i]); - } - } - exp = norm_l(exc_diffQ_max); - - IF(sub(exp,16) > 0) - { - *Q_hb_exc = 12; - move16(); - FOR(i=start_band; i Q27 */ - L_tmp = L_shr(L_tmp, 10); /* From Q27 to Q16 */ - - frac = L_Extract_lc(L_tmp, &exp); /* Extract exponent of L_tmp */ - tmp = extract_l(Pow2(14, frac));/* Put 14 as exponent so that */ - /* output of Pow2() will be: */ - /* 16384 < Pow2() <= 32767 */ - exp = sub(exp, 14); - tmp1 = shl(tmp,add(exp,0)); - ener = add (tmp1,ener);/*Q0 */ - } - - test(); - IF( L_sub(core_brate,ACELP_8k00) == 0 && sub(bwidth,NB) != 0 ) - { - if(sub(last_coder_type,AUDIO) != 0) - { - *last_ener = ener; - move16(); - } - test(); - test(); - IF((sub(last_bin,8) > 0 || Diff_len != 0) && sub(last_coder_type,AUDIO) == 0) - { - MAX_Bin = 10; - move16(); - bwe_flag = 1; - move16(); - } - ELSE - { - MAX_Bin = 15; - move16(); - } - - last_bin_tmp = last_bin; - move16(); - last_bin = s_max(last_bin , MAX_Bin); - last_bin = add(last_bin, 1); - } - ELSE - { - last_bin = MBANDS_GN; - move16(); - last_bin_tmp = last_bin; - move16(); - } - IF( bfi ) - { - set16_fx( noisepb, 13107, MBANDS_GN ); /*0.4 in Q15 */ - } - ELSE - { - EstimateNoiseLevel_fx( noisepb, core_brate, Diff_len, last_bin, coder_type, noise_lev, pit_band_idx, - last_bin_tmp, bwidth ); - } - - IF( exc_wo_nf != NULL ) - { - Copy( exc_diffQ, exc_wo_nf, L_FRAME ); - } - - test(); - IF( GSC_noisy_speech && !bfi ) - { - set16_fx( noisepb, 3277, MBANDS_GN ); - } - Apply_NoiseFill_fx( exc_diffQ, seed_tcx, noisepb, Diff_len, last_bin, coder_type, mfreq_bindiv, Qexc_diffQ ); - - /*--------------------------------------------------------------------------------------* - * Quantize average gain - * Substract Q averaged gain - * VQ of remaining gain per band - *--------------------------------------------------------------------------------------*/ - test(); - IF( L_sub(core_brate,ACELP_8k00) == 0 && sub(bwidth,NB) != 0 ) - { - Ener_per_band_comp_fx(exc_diffQ, Ener_per_bd_yQ, Qexc_diffQ, add(last_bin,1), 0); - } - ELSE - { - Ener_per_band_comp_fx(exc_diffQ, Ener_per_bd_yQ, Qexc_diffQ, MBANDS_GN, 1 ); - - IF( sub(nb_subfr, 4) < 0 ) - { - FOR(i = L_FRAME-16; i < L_FRAME; i++) - { - /*exc_diffQ[i] *= 0.067f * i - 15.0f; = -15 - (-0.067f * i) */ - tmp = msu_r(-7680*65536, -17564, shl(i,6));/*-15 in Q9; -0.067 in Q18 and i in Q6= Q9 */ - L_tmp = L_mult(exc_diffQ[i],tmp); /*Q(Qexc_diffQ+10) */ - exc_diffQ[i] = round_fx(L_shl(L_tmp,16-10));/*Qexc_diffQ */ - } - } - } - /*--------------------------------------------------------------------------------------* - * Check potential energy excitation overshoot - *--------------------------------------------------------------------------------------*/ - IF( bfi ) - { - test(); - IF (GSC_noisy_speech == 0 && sub(coder_type,UNVOICED) > 0 ) /* Here coder_type == last_coder_type because of the bfi */ - { - FOR( i=0; i end) - { - *src-- = *dst--; - move16(); - } - test(); - test(); - if( (bitallocation_exc[0] != 0 || bitallocation_exc[1] != 0) && L_sub(core_brate, ACELP_8k00) == 0 ) - { - exc_diffQ[160] = 0; - move16(); - } - - Q_hb_exc = 0; - move16(); - envelop_modify_fx( exc_diffQ, seed_tcx, last_bin, Ener_per_bd_iQ, Q_exc, &Q_hb_exc); - Copy_Scale_sig( &exc_diffQ[tmp1], &exc_dct_in[tmp1], sub(L_FRAME,tmp1), sub(Q_exc, Q_hb_exc)); /* from Q_hb_exc -> Q_exc as expected */ - } - - IF( sub(nb_subfr,4) < 0 ) - { - FOR( i = sub(L_FRAME,16); i < L_FRAME; i++ ) - { - /*exc_dct_in[i] *= (0.067f*i-15.f); */ - tmp = mult_r(17564,shl(i,6)); /*0.067 in Q18 and i in Q6= Q9 */ - tmp = sub(tmp,7680); /*15 in Q9 = Q9 */ - L_tmp = L_mult(exc_dct_in[i],tmp);/*Q(Q_exc+10) */ - exc_dct_in[i] = round_fx(L_shl(L_tmp,6));/*Q_exc */ - } - } - - tmp1 = mult_r(ener,16384); - tmp1 = sub(*last_ener,tmp1); - tmp = mult_r(*last_ener,16384); - tmp = sub(ener,tmp); - test(); - IF( tmp>0 && tmp1>0 ) - { - length_bin = 6; - move16(); - IF(last_coder_type != AUDIO) - { - set16_fx( last_bitallocation_band, 0, 6 ); - Copy( &exc_dct_in[(4+length_bin)*16], &last_exc_dct_in[(4+length_bin)*16], length_bin*16 ); - } - - FOR(i=4; i<(4+length_bin); i++) - { - test(); - IF( !(bitallocation_band[i] == 0 && last_bitallocation_band[i-4] == 0)) - { - k = shl(add(i,length_bin),4); - src = &exc_dct_in[k]; /*(i+length_bin)*16*/ - dst = &last_exc_dct_in[k]; - FOR(j=0; j<16; j++) - { - tmp= mult_r(10923,abs_s(*src)); - tmp1 =mult_r(10923,abs_s(*dst)); - - IF(sub(tmp,abs_s(*dst)) >0) - { - tmp2 = *src; - *src = mult_r(16384,sub(*src , abs_s(*dst))); /*Q_exc */ move16(); - tmp = mult_r(16384,add(tmp2 , abs_s(*dst))); /*Q_exc */ - if( tmp2 > 0 ) - { - *src = tmp; - move16(); - } - } - ELSE IF (sub(tmp1,abs_s(*src)) >0) - { - tmp = mult_r(*src,22938); - tmp1 = mult_r(9830,abs_s(*dst)); - tmp2 = *src; - *src = sub(tmp,tmp1); /*Q_exc */ move16(); - if( tmp2 > 0 ) - { - *src = add(tmp,tmp1); /*Q_exc */ move16(); - } - } - src++; - dst++; - } - } - } - } - IF(sub(bwe_flag,1) == 0) - { - Decreas_freqPeak_fx( lsf_new, exc_dct_in, 9830 ); - } - ELSE - { - Decreas_freqPeak_fx( lsf_new, exc_dct_in, 16384 ); - } - } - - Copy( &exc_dct_in[64], &last_exc_dct_in[64], L_FRAME-64 ); - Copy(&bitallocation_band[4], last_bitallocation_band, 6); - *last_ener = ener; - move16(); - - return; -} diff --git a/src/libs/libevs/lib_com/gs_preech.cpp b/src/libs/libevs/lib_com/gs_preech.cpp new file mode 100644 index 00000000..73fb5962 --- /dev/null +++ b/src/libs/libevs/lib_com/gs_preech.cpp @@ -0,0 +1,94 @@ +/*==================================================================================== + EVS Codec 3GPP TS26.443 Nov 13, 2018. Version 12.11.0 / 13.7.0 / 14.3.0 / 15.1.0 + ====================================================================================*/ + +#include +#include "options.h" +#include "cnst.h" +#include "rom_com.h" +#include "prot.h" + + +/*-------------------------------------------------------------------* + * Local constants + *-------------------------------------------------------------------*/ + +#define ATT_LENGHT 64 +#define ATT_SEG_LEN (L_FRAME/ATT_LENGHT) +#define INV_ATT_SEG_LEN (1.0f/ATT_SEG_LEN) +#define INV_L_FRAME (1.0f/L_FRAME) + + +/*-------------------------------------------------------------------* + * pre_echo_att() + * + * Attenuation of the pre-echo when encoder specifies an attack + *-------------------------------------------------------------------*/ + +void pre_echo_att( + float *Last_frame_ener, /* i/o: Energy of the last frame */ + float *exc, /* i/o: Excitation of the current frame */ + const short attack_flag, /* i : flag signalling attack encoded by AC mode (GSC) */ + const short last_coder_type /* i : Last coder type */ +) +{ + float etmp; + float etmp1; + float finc[ATT_LENGHT], ratio; + short attack_pos, i; + + if ( attack_flag == 1 && last_coder_type == AUDIO) + { + /*-------------------------------------------------------------------------* + * Find where the onset (attack) occurs by computing the energy per section + * The inverse weighting aims to favor the first maxima in case of + * gradual onset + *-------------------------------------------------------------------------*/ + + for(i = 0; i < ATT_LENGHT; i++) + { + finc[i] = sum2_f( exc + i*ATT_SEG_LEN, ATT_SEG_LEN )*((float)(ATT_LENGHT-i)/(ATT_LENGHT)); + } + + etmp = -1; + attack_pos = maximum(finc, ATT_LENGHT, &etmp); + + /* Scaled the maximum energy and allowed 6 dB increase*/ + etmp *= INV_ATT_SEG_LEN; + etmp1 = etmp; + *Last_frame_ener *= 4.0f; + + /* If the maximum normalized energy > last frame energy + 6dB */ + if( etmp > *Last_frame_ener && attack_pos > 0 ) + { + /* Find the average energy before the attack */ + etmp = sum_f( finc, attack_pos ) + 0.01f; + etmp /= (attack_pos*ATT_SEG_LEN); + + /* Find the correction factor and apply it before the attack */ + ratio = (float)sqrt(*Last_frame_ener/etmp); + + + /* Pre-echo atttenuation should never increase the energy */ + ratio = min(ratio, 1.0f); + for(i = 0; i < attack_pos*ATT_SEG_LEN; i++) + { + exc[i] *= ratio; + } + } + *Last_frame_ener = etmp1; + } + else + { + /*-------------------------------------------------------* + * In normal cases, just compute the energy of the frame + *-------------------------------------------------------*/ + + etmp = sum2_f( exc, L_FRAME ) + 0.01f; + + etmp *= INV_L_FRAME; + *Last_frame_ener = etmp; + } + + return; +} diff --git a/src/libs/libevs/lib_com/gs_preech_fx.cpp b/src/libs/libevs/lib_com/gs_preech_fx.cpp deleted file mode 100755 index fc9d1f7b..00000000 --- a/src/libs/libevs/lib_com/gs_preech_fx.cpp +++ /dev/null @@ -1,139 +0,0 @@ -/*==================================================================================== - EVS Codec 3GPP TS26.442 Apr 03, 2018. Version 12.11.0 / 13.6.0 / 14.2.0 - ====================================================================================*/ - -#include "options.h" /* Compilation switches */ -#include "cnst_fx.h" /* Common constants */ -#include "rom_com_fx.h" /* Static table prototypes */ -#include "prot_fx.h" /* Function prototypes */ -#include "stl.h" - - -/*-------------------------------------------------------------------* - * Local constants - *-------------------------------------------------------------------*/ - -#define ATT_LENGHT 64 -#define ATT_SEG_LEN (L_FRAME/ATT_LENGHT) -#define INV_ATT_SEG_LEN (1.0f/ATT_SEG_LEN) -#define INV_L_FRAME (1.0f/L_FRAME) - -/*==========================================================================*/ -/* FUNCTION : void pre_echo_att_fx(); */ -/*--------------------------------------------------------------------------*/ -/* PURPOSE : Attenuation of the pre-echo when encoder specifies an attack */ -/*--------------------------------------------------------------------------*/ -/* INPUT ARGUMENTS : */ -/* _ (Word16) L_frame_fx : length of the frame Q0 */ -/* _ (Word16) gsc_attack_flag_fx : LP filter coefficient Q0 */ -/* _ (Word16) core_fx : core codec used Q0 */ -/*--------------------------------------------------------------------------*/ -/* OUTPUT ARGUMENTS : */ -/* _ None */ -/*--------------------------------------------------------------------------*/ -/* INPUT/OUTPUT ARGUMENTS : */ -/* _ (Word16*) exc_fx : adapt. excitation exc Q_exc */ -/* _ (Word32*) Last_frame_ener_fx : Energy of the last frame Q1 */ -/*--------------------------------------------------------------------------*/ -/* RETURN ARGUMENTS : */ -/* _ None */ -/*==========================================================================*/ -void pre_echo_att_fx( - Word32 *Last_frame_ener_fx, /* i/o: Energy of the last frame 2*Q_new+1*/ - Word16 *exc_fx, /* i/o: Excitation of the current frame Q_new*/ - const Word16 gsc_attack_flag_fx /* i : flag signalling attack encoded by AC mode (GSC) */ - ,const Word16 Q_new - ,const Word16 last_coder_type_fx /* i : Last coding mode */ -) -{ - Word32 etmp_fx; - Word32 finc_fx[ATT_LENGHT] = {0}; - Word16 ratio_fx; - Word16 attack_pos_fx, i; - Word32 L_tmp, L_tmp1; - Word16 tmp, n1, n2, exp, frac1, frac2; - Word32 etmp1_fx; - test(); - IF ( sub(gsc_attack_flag_fx,1) == 0 && sub(last_coder_type_fx, AUDIO) == 0) /*gsc_attack_flag_fx does not get set for all the test cases */ - { - /*-------------------------------------------------------------------------* - * Find where the onset (attack) occurs by computing the energy per section - * The inverse weighting aims to favor the first maxima in case of - * gradual onset - *-------------------------------------------------------------------------*/ - FOR(i = 0; i < ATT_LENGHT; i++) - { - L_tmp = sum2_fx(&exc_fx[shl(i,2)], ATT_SEG_LEN ); /*2*Q_new+1, //ATT_SEG_LEN=(L_FRAME/ATT_LENGHT)=4(=shl(x,2))*/ - tmp = div_s(sub(ATT_LENGHT,i),ATT_LENGHT); /*Q15 */ - L_tmp = Mult_32_16(L_tmp, tmp); /*2*Q_new+1 */ - finc_fx[i] = L_tmp; - move32(); /*2*Q_new+1 */ - } - - attack_pos_fx = maximum_32_fx(finc_fx, ATT_LENGHT, &etmp_fx); - - /* Scaled the maximum energy and allowed 6 dB increase*/ - etmp_fx = L_shr(etmp_fx,add(2+1-4, shl(Q_new,1)));/*2*Q_new+1 //INV_ATT_SEG_LEN=1/4(=shr(x,2)) -> Q4 */ - etmp1_fx = etmp_fx; - move32(); - *Last_frame_ener_fx = L_shl(*Last_frame_ener_fx,2); - move32(); /*2*Q_new+1 */ - - /* If the maximum normalized energy > last frame energy + 6dB */ - test(); - IF( L_sub(etmp_fx,*Last_frame_ener_fx) > 0 && attack_pos_fx > 0 ) - { - /* Find the average energy before the attack */ - L_tmp = sum32_fx( finc_fx, attack_pos_fx); /*Q1 */ - L_tmp1 = L_shr(L_mult(attack_pos_fx,attack_pos_fx),1); /*Q0 */ - tmp = round_fx(Isqrt(L_tmp1)); /*Q15 */ - L_tmp = L_shr(L_tmp,2); /*Q1 ; ATT_SEG_LEN=4 */ - etmp_fx = Mult_32_16(L_tmp,tmp); /*Q1 */ - - etmp_fx = L_shr(etmp_fx,add(1-4, shl(Q_new,1))); /* makes etmp i nQ4 as *Last_frame_ener_fx */ - /* Find the correction factor and apply it before the attack */ - /* ratio = (float)sqrt(*Last_frame_ener/etmp);*/ - /* = isqrt(etmp/(*Last_frame_ener)) */ - etmp_fx = L_max(etmp_fx,1); - *Last_frame_ener_fx = L_max(*Last_frame_ener_fx,1); - n1 = norm_l(etmp_fx); - n2 = norm_l(*Last_frame_ener_fx); - - n1 = sub(n1,1); - exp = sub(n1,n2); - - frac1 = round_fx(L_shl(etmp_fx,n1)); - frac2 = round_fx(L_shl(*Last_frame_ener_fx,n2)); - - L_tmp = L_mult0(128, div_s(frac1, frac2)); /* s = gain_out / gain_in */ - L_tmp = L_shr(L_tmp, exp); /* add exponent */ - - L_tmp = Isqrt(L_tmp); - ratio_fx = round_fx(L_shl(L_tmp, 9)); - - /* Pre-echo atttenuation should never increase the energy */ - ratio_fx = s_min(ratio_fx, 8192); - FOR(i = 0; i < attack_pos_fx*ATT_SEG_LEN; i++) - { - /*exc_fx[i] *= ratio_fx;*/ - exc_fx[i] = round_fx(L_shl(L_mac(-8192, exc_fx[i], ratio_fx), 2)); - } - } - *Last_frame_ener_fx = etmp1_fx; - move32(); - } - ELSE - { - /*-------------------------------------------------------* - * In normal cases, just compute the energy of the frame - *-------------------------------------------------------*/ - - etmp_fx = sum2_fx( exc_fx, L_FRAME ); /*2*Q_new+1 */ - - etmp_fx = L_shr(etmp_fx,add(8+1-4, shl(Q_new,1))); /*2*Q_new+1 //INV_L_FRAME = 1/256 -> Q4*/ - *Last_frame_ener_fx = etmp_fx; - move32(); /*2*Q_new+1*/ - } - - return; -} diff --git a/src/libs/libevs/lib_com/guided_plc_util.cpp b/src/libs/libevs/lib_com/guided_plc_util.cpp old mode 100755 new mode 100644 index db4b26f2..8991692b --- a/src/libs/libevs/lib_com/guided_plc_util.cpp +++ b/src/libs/libevs/lib_com/guided_plc_util.cpp @@ -1,324 +1,301 @@ /*==================================================================================== - EVS Codec 3GPP TS26.442 Apr 03, 2018. Version 12.11.0 / 13.6.0 / 14.2.0 + EVS Codec 3GPP TS26.443 Nov 13, 2018. Version 12.11.0 / 13.7.0 / 14.3.0 / 15.1.0 ====================================================================================*/ -#include "prot_fx.h" -#include "stl.h" -#include "rom_com_fx.h" +#include "prot.h" +#include "rom_com.h" -#include "basop_util.h" -#include "rom_basop_util.h" -void getLookAheadResSig( Word16 *speechLookAhead, Word16 *A_3Q12, Word16 *res, Word16 L_frame, Word16 numSubFrame ) +/*-------------------------------------------------------------------* + * Local function + *-------------------------------------------------------------------*/ + +static void reorder_lsfs( float *lsf, float min_dist, const short n, int sr_core ); + + +/*-------------------------------------------------------------------* + * getLookAheadResSig() + * + * + *-------------------------------------------------------------------*/ + +void getLookAheadResSig( + float *speechLookAhead, + const float *A, + float *res, + int L_frame, + int L_subfr, + int m, + int numSubFrame +) { - Word16 *p_A; - Word16 i_subfr; - Word16 subfr_len[2] = { L_SUBFR, L_SUBFR }; + const float *p_A; + short i_subfr; + short subfr_len[2] = { 0 }; - if( sub( L_FRAME16k, L_frame )>0 ) + subfr_len[0] = L_subfr; + subfr_len[1] = L_frame < L_FRAME16k ? (short)(0.75*L_subfr) : L_subfr; + + p_A = A; + for (i_subfr=0; i_subfrlsf_adaptive_mean[i] = ( decState->lsfoldbfi1[i]+ decState->lsfoldbfi0[i]+lsf[i])/3; + decState->lsfoldbfi1[i] = decState->lsfoldbfi0[i]; + decState->lsfoldbfi0[i] = lsf[i]; } return; } -void updateLSFForConcealment( HANDLE_PLC_ENC_EVS decState, Word16 *lsf_14Q1, Word16 m ) -{ - Word16 i; - Word32 L_tmp = 0; - const Word16 divide_by_3_Q15 = 10923; +/*-------------------------------------------------------------------* + * getConcealedLP() + * + * + *-------------------------------------------------------------------*/ - FOR (i=0; ilsf_con; + float lsp[(NB_DIV+1)*M]; + short k; + + dlpc_bfi( L_frame, &lsf[0], memDecState->lsfold, last_good, + 1 /* assumes packet loss */ , memDecState->mem_MA, memDecState->mem_AR, &(memDecState->stab_fac), memDecState->lsf_adaptive_mean, + 1, NULL, 0, NULL, NULL, lsfBase); + + mvr2r( memDecState->lspold, lsp, M ); + + for ( k=0; k<1; k++ ) { - L_tmp = L_mult( divide_by_3_Q15, decState->lsfoldbfi1_14Q1[i] ); - L_tmp = L_mac( L_tmp, divide_by_3_Q15, decState->lsfoldbfi0_14Q1[i] ); - decState->lsf_adaptive_mean_14Q1[i] = mac_r( L_tmp, divide_by_3_Q15, lsf_14Q1[i] ); - decState->lsfoldbfi1_14Q1[i] = decState->lsfoldbfi0_14Q1[i]; - move16(); - decState->lsfoldbfi0_14Q1[i] = lsf_14Q1[i]; - move16(); + lsf2lsp(&lsf[k*M], &lsp[(k+1)*M], M, sr_core); } + int_lsp( L_FRAME, &lsp[0], &lsp[M], AqCon, M, interpol_frac_12k8, 0 ); + return; } -void getConcealedLP( HANDLE_PLC_ENC_EVS memDecState, Word16 *AqCon, const Word16 lsfBase[], Word16 last_good, Word16 L_frame) +/*-------------------------------------------------------------------* + * RecLpcSpecPowDiffuseLc() + * + * + *-------------------------------------------------------------------*/ + +void RecLpcSpecPowDiffuseLc( + float *lspq, + float *lsp_old, + float *lsfq, + Decoder_State *st + , int reset_q +) { - Word16 *lsf; - Word16 lsp[(NB_DIV+1)*M]; - Word32 int_fs; - - move16(); - lsf = memDecState->lsf_con; + const float *means; + float lsf_old[M]; + short i; - dlpc_bfi( L_frame, &lsf[0], memDecState->lsfold_14Q1, last_good, - 1, memDecState->mem_MA_14Q1, memDecState->mem_AR, &(memDecState->stab_fac_Q15), memDecState->lsf_adaptive_mean_14Q1, - 1, - NULL, - 0, - NULL, - NULL, - lsfBase, - 0 - ); - Copy( memDecState->lspold_Q15, lsp, M ); + means = PlcGetlsfBase ( st->lpcQuantization, st->narrowBand, st->sr_core ); - int_fs = INT_FS_FX; - move32(); - if( sub(L_frame,L_FRAME_16k) == 0 ) + mvr2r( st->lsf_old, lsf_old, M ); + + modify_lsf( lsf_old, M, st->sr_core + , reset_q + ); + + lsf2lsp(lsf_old, lsp_old, M, st->sr_core); + + if (reset_q) { - int_fs = INT_FS_16k_FX; - move32(); - } - lsf2lsp_fx( lsf, &lsp[M], M, int_fs ); - - int_lsp_fx( L_frame, &lsp[0], &lsp[M], AqCon, M, interpol_frac_fx, 0 ); - - return; -} - -void getConcealedLSF( HANDLE_PLC_ENC_EVS memDecState, const Word16 lsfBase[], Word16 last_good, Word16 L_frame) -{ - Word16 *lsf = memDecState->lsf_con; - - - dlpc_bfi( L_frame, &lsf[0], memDecState->lsfold_14Q1, last_good, - 1, memDecState->mem_MA_14Q1, memDecState->mem_AR, &(memDecState->stab_fac_Q15), memDecState->lsf_adaptive_mean_14Q1, - 1, - NULL, - 0, - NULL, - NULL, - lsfBase, - 0 - ); - - return; -} - -static void reorder_lsfs(Word16 *lsf, const Word16 min_dist, const Word16 n, const Word32 sr_core); - -void RecLpcSpecPowDiffuseLc( Word16 *lspq, Word16 *lsp_old, Word16 *lsfq, Decoder_State_fx *st, Word16 reset_q ) -{ - const Word16 *means; - Word16 lsf_old[M]; - Word16 i; - - means = PlcGetLsfBase ( st->lpcQuantization, - st->narrowBand, - st->sr_core ); - - Copy( st->lsf_old_fx, lsf_old, M ); - - modify_lsf( lsf_old, M, st->sr_core, reset_q ); - - lsf2lsp_fx( lsf_old, lsp_old, M, st->sr_core ); - - IF( reset_q ) - { - FOR ( i=0; imem_MA_fx[i], means[i]); - move16(); + lsfq[i] = st->mem_MA[i] + means[i]; } - sort_fx( lsfq, 0, sub(M, 1) ); - reorder_lsfs( lsfq, LSF_GAP_FX, M, st->sr_core ); - lsf2lsp_fx( lsfq, lspq, M, st->sr_core ); + v_sort( lsfq, 0, M - 1 ); + + reorder_lsfs( lsfq, LSF_GAP, M, st->sr_core); + + lsf2lsp(lsfq, lspq, M, st->sr_core); } - ELSE + else { modify_lsf( lsfq, M, st->sr_core, reset_q ); - lsf2lsp_fx(lsfq, lspq, M, st->sr_core); + + lsf2lsp(lsfq, lspq, M, st->sr_core); + } + + + return; +} + + +/*-------------------------------------------------------------------* + * modify_lsf() + * + * + *-------------------------------------------------------------------*/ + +void modify_lsf( + float *lsf, + const short n, + const int sr_core + , int reset_q +) +{ + short i, k; + float gap; + float th; + + th = 1900; + + if (reset_q==0) + { + th = 800; + } + + if(sr_core == 16000) + { + th *= 1.25; + } + + + i = 1; + + while(lsf[i] < th && i < n) + { + i++; + } + gap = lsf[i - 1] / i; + + for(k = 0; k < i - 1; k++) + { + lsf[k] = gap * (k + 1); } return; } -void modify_lsf( - Word16 *lsf, - const Word16 n, - const Word32 sr_core - , Word16 reset_q -) -{ - Word16 i, k, th_x1p28_Q14; - Word16 gap, gap_sum; - - - th_x1p28_Q14 = 4864/*1900.0f*1.28f Q1*/; - move16(); - if( L_sub( sr_core, 16000 ) == 0 ) - { - th_x1p28_Q14 = 6080/*2375.0f*1.28f Q1*/; - move16(); - } - - IF( reset_q == 0 ) - { - th_x1p28_Q14 = 2048; /* 800.0f*1.28f Q1*/ move16(); - if( L_sub( sr_core, 16000 ) == 0 ) - { - th_x1p28_Q14 = 2560; /*1000.0f*1.28f Q1*/ move16(); - } - } - - FOR ( i=1; i= 0 ) - { - BREAK; - } - } - - gap = mult_r(lsf[i - 1], InvIntTable[i]); - - move16(); - gap_sum = gap; - i = sub(i,1); - FOR(k = 0; k < i; k++) - { - move16(); - lsf[k] = gap_sum; - gap_sum = add(gap_sum, gap); - } - -} +/*-------------------------------------------------------------------* + * reorder_lsfs() + * + * + *-------------------------------------------------------------------*/ static void reorder_lsfs( - Word16 *lsf, /* i/o: vector of lsfs in the frequency domain (0..0.5)*/ - const Word16 min_dist0, /* i : minimum required distance */ - const Word16 n, /* i : LPC order */ - const Word32 sr_core /* i : input sampling frequency */ + float *lsf, /* i/o: vector of lsfs in the frequency domain (0..0.5)*/ + float min_dist, /* i : minimum required distance */ + const short n, /* i : LPC order */ + int sr_core ) { - Word16 i; - Word16 curr_min_dist; - Word16 min_dist_fac2; - Word16 min_dist_fac3; - Word16 lsf_min; - Word16 lsf_max; - Word16 fs2; - Word16 th1, th2; - Word16 min_dist; + short i; + float lsf_min; + float lsf_max; + float fac; + float th1, th2; + + th1 = 1000.0f; + th2 = 1900.0f; - fs2 = 16384/*6400.0 * 1.28 Q1*/; - move16(); - - if(L_sub(sr_core, 16000) == 0) + if(sr_core == 16000) { - fs2 = 20480/*8000.0 * 1.28 Q1*/; - move16(); + min_dist *= 1.25; + th1 *= 1.25; + th2 *= 1.25; } /*-----------------------------------------------------------------* * Verify the LSF ordering and minimum GAP *-----------------------------------------------------------------*/ - IF( L_sub( sr_core, 16000 )==0 ) - { - th1 = 3200; - move16(); - th2 = 6080; - move16(); - min_dist = add( min_dist0, shr(min_dist0,2) ); - } - ELSE - { - th1 = 2560; - move16(); - th2 = 4864; - move16(); - min_dist = min_dist0; - move16(); - } - min_dist_fac2 = shl(min_dist, 1); - min_dist_fac3 = add(min_dist, min_dist_fac2); - curr_min_dist = min_dist_fac3; - move16(); + fac = 3.0; - lsf_min = curr_min_dist; - move16(); - - FOR (i = 0; i < n; i++) + lsf_min = min_dist * fac; + for (i = 0; i < n; i++) { - IF (sub(lsf[i], th1) > 0) + + if (lsf[i] > th1) { - curr_min_dist = min_dist_fac2; - move16(); + fac = 2.0; } - ELSE + else { - if (sub(lsf[i], th2) > 0) + if (lsf[i] > 1900.0) { - curr_min_dist = min_dist; - move16(); + fac = 1.0; } } - if (sub(lsf[i], lsf_min) < 0) + if (lsf[i] < lsf_min) { lsf[i] = lsf_min; - move16(); } - lsf_min = add(lsf[i], curr_min_dist); - + lsf_min = lsf[i] + min_dist * fac; } /*------------------------------------------------------------------------------------------* * Reverify the LSF ordering and minimum GAP in the reverse order (security) *------------------------------------------------------------------------------------------*/ - lsf_max = sub(fs2, curr_min_dist); + lsf_max = (float)(sr_core)/2.0f - min_dist * fac; - IF (sub(lsf[n-1], lsf_max) > 0) /* If danger of unstable filter in case of resonance in HF */ + if( lsf[n-1] > lsf_max ) /* If danger of unstable filter in case of resonance in HF */ { - FOR (i = sub(n, 1); i >= 0; i--) /* Reverify the minimum ISF gap in the reverse direction */ + for (i = n-1; i >=0; i--) /* Reverify the minimum LSF gap in the reverse sens */ { - IF (sub(lsf[i], th2) <= 0) + + if (lsf[i] <= th2) { - curr_min_dist = min_dist_fac2; - move16(); + fac = 2.0; } - ELSE + else { - if (sub(lsf[i], th1) <= 0) + if (lsf[i] <= th1) { - curr_min_dist = min_dist_fac3; - move16(); + fac = 3.0; } } - if (sub(lsf[i], lsf_max) > 0) + if (lsf[i] > lsf_max) { lsf[i] = lsf_max; - move16(); } - lsf_max = sub(lsf[i], curr_min_dist); + + lsf_max = lsf[i] - min_dist * fac; } } return; } - diff --git a/src/libs/libevs/lib_com/hp50.cpp b/src/libs/libevs/lib_com/hp50.cpp old mode 100755 new mode 100644 index 0a1b80d4..daa72a29 --- a/src/libs/libevs/lib_com/hp50.cpp +++ b/src/libs/libevs/lib_com/hp50.cpp @@ -1,16 +1,14 @@ /*==================================================================================== - EVS Codec 3GPP TS26.442 Apr 03, 2018. Version 12.11.0 / 13.6.0 / 14.2.0 + EVS Codec 3GPP TS26.443 Nov 13, 2018. Version 12.11.0 / 13.7.0 / 14.3.0 / 15.1.0 ====================================================================================*/ - #include -#include "stl.h" -#include "prot_fx.h" -#include "basop_util.h" +#include "typedef.h" #include "options.h" +#include "prot.h" + -#define HP20_COEFF_SCALE (2) /* * hp20 @@ -22,229 +20,86 @@ * void */ -static Word32 HP50_Mode2_Mpy_32_16_fix(Word32 a, Word16 b) +void hp20(Float32 signal[], Word32 lg, Float32 mem[], Word32 fs) { - Word32 result = Mpy_32_16_1(a,b); - /* perform rounding towards lower value for negative results */ - if (result < 0) result = L_add(result,1); - return result; -} - -static Word32 HP50_Mpy_32_32_fix(Word32 a, Word32 b) -{ - Word32 result = Mpy_32_32(a,b); - /* perform rounding towards lower value for negative results */ - if (result < 0) result = L_add(result,1); - return result; -} - - -static void filter_2nd_order( - Word16 signal[], - const Word16 stride, - const Word16 prescale, - const Word16 lg, - Word32 mem[4], - Word32 a1, - Word32 a2, - Word32 b1, - Word32 b2 -) -{ - Word16 i; - Word16 x2, x1; - Word32 L_sum, L_y1, L_y2; + Float32 x0, x1, x2, y0, y1, y2; + Float32 a1, a2, b1, b2; - /* - * Saturation: The states of the filter, namely L_y1 and L_y2 shall - * never saturate, because that causes error in the filter feedback. - * The final output written into signal[] might saturate because of - * unavoidable filter overshoot. - */ - /* Execute first 2 iterations with 32-bit x anx y memory values */ - BASOP_SATURATE_ERROR_ON - L_sum = HP50_Mpy_32_32_fix(b2,mem[2]); /* b2*x2 */ - L_sum = L_add(L_sum,HP50_Mpy_32_32_fix(b1,mem[3])); /* b1*x1 */ - x2 = shr(signal[0*stride], prescale); - L_sum = L_add(L_sum,HP50_Mode2_Mpy_32_16_fix(b2,x2)); /* b2*x0 */ - L_sum = L_add(L_sum, HP50_Mpy_32_32_fix(mem[0],a2)); /* y2*a2 */ - L_sum = L_add(L_sum, HP50_Mpy_32_32_fix(mem[1],a1)); /* y1*a1 */ + y1 = mem[0]; + y2 = mem[1]; + x0 = mem[2]; + x1 = mem[3]; - L_y2 = L_shl(L_sum, HP20_COEFF_SCALE); - BASOP_SATURATE_ERROR_OFF - BASOP_SATURATE_WARNING_OFF - signal[0*stride] = round_fx(L_shl(L_y2, prescale)); - BASOP_SATURATE_WARNING_ON - - BASOP_SATURATE_ERROR_ON - L_sum = HP50_Mpy_32_32_fix(b2,mem[3]); /* b2*x2 */ - L_sum = L_add(L_sum,HP50_Mode2_Mpy_32_16_fix(b1,x2)); /* b1*x1 */ - x1 = shr(signal[1*stride], prescale); - L_sum = L_add(L_sum,HP50_Mode2_Mpy_32_16_fix(b2,x1)); /* b2*x0 */ - L_sum = L_add(L_sum, HP50_Mpy_32_32_fix(mem[1],a2)); /* y2*a2 */ - L_sum = L_add(L_sum, HP50_Mpy_32_32_fix(L_y2, a1)); /* y1*a1 */ - - L_y1 = L_shl(L_sum, HP20_COEFF_SCALE); - BASOP_SATURATE_ERROR_OFF - BASOP_SATURATE_WARNING_OFF - signal[1*stride] = round_fx(L_shl(L_y1, prescale)); - BASOP_SATURATE_WARNING_ON - - /* New we use a trick and toggle x1/x2 and L_y1/L_y2 to save a few cycles unrolling the loop by 2 */ - FOR (i = 2; i < lg; i+=2) + if (fs == 8000) { - /* y[i+0] = b2*x[i-2] + b1*x[i-1] + b2*x[i-0] + a2*y[i-2] + a1*y[i-1]; */ - BASOP_SATURATE_ERROR_ON - L_sum = HP50_Mode2_Mpy_32_16_fix(b2,x2); - L_sum = L_add(L_sum,HP50_Mode2_Mpy_32_16_fix(b1,x1)); - x2 = shr(signal[i*stride], prescale); - L_sum = L_add(L_sum,HP50_Mode2_Mpy_32_16_fix(b2,x2)); - L_sum = L_add(L_sum, HP50_Mpy_32_32_fix(L_y2,a2)); - L_sum = L_add(L_sum, HP50_Mpy_32_32_fix(L_y1,a1)); - - L_y2 = L_shl(L_sum, HP20_COEFF_SCALE); - BASOP_SATURATE_ERROR_OFF - BASOP_SATURATE_WARNING_OFF - signal[i*stride] = round_fx(L_shl(L_y2, prescale)); - BASOP_SATURATE_WARNING_ON - /* y[i+1] = b2*x[i-1] + b1*x[i-0] + b2*x[i+1] + a2*y[i-1] + a1*y[i+0]; */ - BASOP_SATURATE_ERROR_ON - L_sum = HP50_Mode2_Mpy_32_16_fix(b2,x1); - L_sum = L_add(L_sum,HP50_Mode2_Mpy_32_16_fix(b1,x2)); - x1 = shr(signal[(i+1)*stride], prescale); - L_sum = L_add(L_sum,HP50_Mode2_Mpy_32_16_fix(b2,x1)); - L_sum = L_add(L_sum, HP50_Mpy_32_32_fix(L_y1,a2)); - L_sum = L_add(L_sum, HP50_Mpy_32_32_fix(L_y2,a1)); - - L_y1 = L_shl(L_sum, HP20_COEFF_SCALE); - BASOP_SATURATE_ERROR_OFF - BASOP_SATURATE_WARNING_OFF - signal[(i+1)*stride] = round_fx(L_shl(L_y1, prescale)); - BASOP_SATURATE_WARNING_ON - } - /* update static filter memory from variables */ - mem[0] = L_y2; - move32(); - mem[1] = L_y1; - move32(); - mem[2] = L_deposit_h(x2); - mem[3] = L_deposit_h(x1); - - - return; -} - - -void hp20(Word16 signal[], /* i/o: signal to filter any */ - const Word16 stride, /* i : stride to be applied accessing signal */ - const Word16 lg, /* i : length of signal (integer) Q0 */ - Word32 mem[5], /* i/o: static filter memory with this layout: */ - /* mem[0]: y[-2] (32-bit) */ - /* mem[1]; y[-1] (32-bit) */ - /* mem[2]: x[-2] << 16 */ - /* mem[3]: x[-1] << 16 */ - /* Note: mem[0..3] need to be scaled per frame */ - /* mem[4]: states scale */ - const Word32 sFreq) /* i : input sampling rate Q0 */ -{ - Word32 a1, b1, a2, b2; - Word16 prescale, prescaleOld, diff; - - - - prescale = getScaleFactor16(signal, lg); - prescaleOld = extract_l(mem[4]); - diff = norm_l(L_shl(mem[2], prescaleOld)); - if (mem[2] != 0) - { - prescale = s_min(prescale, diff); - } - diff = norm_l(L_shl(mem[3], prescaleOld)); - if (mem[3] != 0) - { - prescale = s_min(prescale, diff); - } - /* Take into account the left shift performed into the loop + 1 bit headroom*/ - prescale = s_max(-12, sub(1+HP20_COEFF_SCALE, prescale)); - IF (prescale != prescaleOld) - { - diff = sub(prescale, prescaleOld); - mem[0] = L_shr(mem[0], diff); - move32(); - mem[1] = L_shr(mem[1], diff); - move32(); - mem[2] = L_shr(mem[2], diff); - move32(); - mem[3] = L_shr(mem[3], diff); - move32(); - mem[4] = L_deposit_l(prescale); - } - - IF ( L_sub(sFreq,8000) == 0 ) - { - /* hp filter 20Hz at 3dB for 8000 Hz input sampling rate + /* hp filter 20Hz at 3dB for 8000KHz input sampling rate [b,a] = butter(2, 20.0/4000.0, 'high'); b = [0.988954248067140 -1.977908496134280 0.988954248067140] - a = [1.000000000000000 -1.977786483776764 0.978030508491796]*/ - a1 = L_add(0,1061816033l/* 1.977786483776764 Q29*/); - a2 = L_add(0,-525076131l/*-0.978030508491796 Q29*/); - b1 = L_add(0,-1061881538l/*-1.977908496134280 Q29*/); - b2 = L_add(0,530940769l/* 0.988954248067140 Q29*/); + a =[1.000000000000000 -1.977786483776764 0.978030508491796]*/ + a1 = 1.977786483776764f; + a2 = -0.978030508491796f; + b1 = -1.977908496134280f; + b2 = 0.988954248067140f; } - ELSE IF ( L_sub(sFreq,16000) == 0 ) + else if (fs==16000) { /* hp filter 20Hz at 3dB for 16000KHz sampling rate [b,a] = butter(2, 20.0/8000.0, 'high'); - b = [0.994461788958195 -1.988923577916390 0.994461788958195] - a = [1.000000000000000 -1.988892905899653 0.988954249933127] */ - a1 = L_add(0,1067778748l/* 1.988892905899653 Q29*/); - a2 = L_add(0,-530940770l/*-0.988954249933127 Q29*/); - b1 = L_add(0,-1067795215l/*-1.988923577916390 Q29*/); - b2 = L_add(0,533897608l/* 0.994461788958195 Q29*/); + b =[ 0.994461788958195 -1.988923577916390 0.994461788958195] + a =[1.000000000000000 -1.988892905899653 0.988954249933127] */ + a1 = 1.988892905899653f; + a2 = -0.988954249933127f; + b1 = -1.988923577916390f; + b2 = 0.994461788958195f; } - ELSE IF ( L_sub(sFreq,32000) == 0 ) + else if (fs==32000) { /* hp filter 20Hz at 3dB for 32000KHz sampling rate [b,a] = butter(2, 20.0/16000.0, 'high'); - b = [0.997227049904470 -1.994454099808940 0.997227049904470] - a = [1.000000000000000 -1.994446410541927 0.994461789075954]*/ - a1 = L_add(0,1070760263l/* 1.994446410541927 Q29*/); - a2 = L_add(0,-533897608l/*-0.994461789075954 Q29*/); - b1 = L_add(0,-1070764392l/*-1.994454099808940 Q29*/); - b2 = L_add(0,535382196l/* 0.997227049904470 Q29*/); + b =[0.997227049904470 -1.994454099808940 0.997227049904470] + a =[1.000000000000000 -1.994446410541927 0.994461789075954]*/ + a1 = 1.994446410541927f; + a2 = -0.994461789075954f; + b1 = -1.994454099808940f; + b2 = 0.997227049904470f; + + } - ELSE + else { - assert (sFreq == 48000); /* hp filter 20Hz at 3dB for 48000KHz sampling rate [b,a] = butter(2, 20.0/24000.0, 'high'); - b =[0.998150511190452 -1.996301022380904 0.998150511190452] + b =[ 0.998150511190452 -1.996301022380904 0.998150511190452] a =[1.000000000000000 -1.996297601769122 0.996304442992686]*/ - a1 = L_add(0,1071754114l/* 1.996297601769122 Q29*/); - a2 = L_add(0,-534886875l/*-0.996304442992686 Q29*/); - b1 = L_add(0,-1071755951l/*-1.996301022380904 Q29*/); - b2 = L_add(0,535877975l/* 0.998150511190452 Q29*/); + a1 = 1.996297601769122f; + a2 = -0.996304442992686f; + b1 = -1.996301022380904f; + b2 = 0.998150511190452f; + } + for(i = 0; i < lg; i++) + { + x2 = x1; + x1 = x0; + x0 = signal[i]; + y0 = (y1*a1) + (y2*a2) + (x0*b2) + (x1*b1) + (x2*b2); + signal[i] = y0; + y2 = y1; + y1 = y0; + } + + mem[0] = ((y1 > 1e-10) | (y1 < -1e-10)) ? y1 : 0; + mem[1] = ((y2 > 1e-10) | (y2 < -1e-10)) ? y2 : 0; + mem[2] = ((x0 > 1e-10) | (x0 < -1e-10)) ? x0 : 0; + mem[3] = ((x1 > 1e-10) | (x1 < -1e-10)) ? x1 : 0; - filter_2nd_order(signal, - stride, - prescale, - lg, - mem, - a1, - a2, - b1, - b2); return; } - - - diff --git a/src/libs/libevs/lib_com/hq2_bit_alloc_fx.cpp b/src/libs/libevs/lib_com/hq2_bit_alloc.cpp old mode 100755 new mode 100644 similarity index 77% rename from src/libs/libevs/lib_com/hq2_bit_alloc_fx.cpp rename to src/libs/libevs/lib_com/hq2_bit_alloc.cpp index 227fe39b..3d68ecfe --- a/src/libs/libevs/lib_com/hq2_bit_alloc_fx.cpp +++ b/src/libs/libevs/lib_com/hq2_bit_alloc.cpp @@ -1,28 +1,73 @@ /*==================================================================================== - EVS Codec 3GPP TS26.442 Apr 03, 2018. Version 12.11.0 / 13.6.0 / 14.2.0 + EVS Codec 3GPP TS26.443 Nov 13, 2018. Version 12.11.0 / 13.7.0 / 14.3.0 / 15.1.0 ====================================================================================*/ +#include #include "options.h" -#include "prot_fx.h" -#include "stl.h" /* required for wmc_tool */ +#include "prot.h" +#include "rom_com.h" +#include "basop_util.h" +#include "basop_mpy.h" +#include "stl.h" -#define MIN_BITS_FIX 0 /* QRk=18 */ -#define HQ_16k40_BIT (HQ_16k40/50) /* 16400/50=328 */ -#define Qbf 14 /* Q value for bits_fact */ + +/*------------------------------------------------------------------- + * Local constants + *-------------------------------------------------------------------*/ + +#define MIN_BITS_FIX 0 +#define HQ_16k40_BIT (HQ_16k40/50) /* 16400/50=328 , FOR FIX TMP */ #define C1_QRk (1< 0 ) { be_sum_fx = add(be_sum_fx, y_index_fx[k]); @@ -132,19 +181,22 @@ void Bits2indvsb_fx ( th_5_fx = shl(5, QRavg); FOR (j = 0; j < be_cnt_fx; j++) { - if( sub(abs_s(sub(Ravg_fx, shl(y_index_fx[j], QRavg))), th_5_fx) > 0 ) + IF( sub(abs_s(sub(Ravg_fx, shl(y_index_fx[j], QRavg))), th_5_fx) > 0 ) { enr_diffcnt_fx = add(enr_diffcnt_fx, 1); } } - scale_fact_fx = 19661; - move16(); /* 0.60f 19660.8(Q15) */ - if( enr_diffcnt_fx > 0 ) + IF( enr_diffcnt_fx > 0 ) { scale_fact_fx = 11468; move16(); /* 0.35f 11468.8(Q15) */ } + ELSE + { + scale_fact_fx = 19661; + move16(); /* 0.60f 19660.8(Q15) */ + } /* Bits allocation to individual SB's in a group based on Band Energies */ FOR (j = 0; j < be_cnt_fx; j++) @@ -159,6 +211,7 @@ void Bits2indvsb_fx ( Ravg_fx = shr(Ravg_fx, 2); /* safe shift */ QRavg = add(sub(exp_normn, exp_normd), 15-2); + test(); if(be_sum_fx <= 0) { be_sum_fx = 1; @@ -192,7 +245,8 @@ void Bits2indvsb_fx ( } IF ( L_sub(L_R_temp[i], L_Bits_needed) < 0 ) { - L_R_temp[i] = L_deposit_l(0); + L_R_temp[i] = 0x0L; + move32(); p2aflags_fx_ptr[index_fx[i]] = 0; move16(); @@ -226,15 +280,15 @@ void Bits2indvsb_fx ( * Bit allocation mechanism for HQ_HARMONIC mode *-------------------------------------------------------------------*/ -void hq2_bit_alloc_har_fx ( - const Word32 *L_y, /* i : Qbe band energy of sub-vectors */ - Word16 B_fx, /* i : Q0 number of available bits */ - const Word16 N_fx, /* i : Q0 number of sub-vectors */ - Word32 *L_Rsubband, /* o : QRk sub-band bit-allocation vector */ - Word16 p2a_bands_fx, /* i : highfreq bands */ - const Word32 L_core_brate, /* i : Q0 core bit rate */ - Word16 p2a_flags_fx[], /* i/o: Q0 p2a_flags */ - const Word16 band_width_fx[] /* i : Q0 table of band_width */ +void hq2_bit_alloc_har ( + float *y, /* i : band energy of sub-vectors */ + int B_fx, /* i : number of available bits */ + short N_fx, /* i : number of sub-vectors */ + Word32 *L_Rsubband, + short p2a_bands_fx, + long L_core_brate, /* i : core bit rate */ + short p2a_flags_fx[], + short band_width_fx[] ) { Word16 i, j, k; @@ -281,11 +335,17 @@ void hq2_bit_alloc_har_fx ( Word16 exp_shift; + Word32 L_y[BANDS_MAX]; + for(i=0; i= 0x0L && sub(j_fx, grp_rngmax_fx[i]) < 0x0 ) { test(); @@ -357,12 +418,10 @@ void hq2_bit_alloc_har_fx ( } gmax_range_fx[i] = add(gmax_range_fx[i], temp_fx); - move16(); } ELSE { gmax_range_fx[i] = add(gmax_range_fx[i], temp_fx); - move16(); } } @@ -381,7 +440,8 @@ void hq2_bit_alloc_har_fx ( FOR(i=0; i 0x0L ) @@ -402,7 +462,8 @@ void hq2_bit_alloc_har_fx ( G1_BE_DIFF_POS_fx = 0; move16(); - L_G1_BE_DIFF_VAL = L_deposit_l(0); + L_G1_BE_DIFF_VAL = 0x0L; + move32(); FOR(j=1; j< harmonic_band_fx; j++) { @@ -410,7 +471,8 @@ void hq2_bit_alloc_har_fx ( { G1_BE_DIFF_POS_fx = j; move16(); - L_G1_BE_DIFF_VAL = L_add(0,L_temp_band_energydiff[j]); + L_G1_BE_DIFF_VAL = L_temp_band_energydiff[j]; + move32(); } } @@ -468,15 +530,15 @@ void hq2_bit_alloc_har_fx ( } } - j = sub(N_fx, harmonic_band_fx); - FOR ( i = 0; i < j; i++ ) + FOR ( i = 0; i < sub(N_fx, harmonic_band_fx); i++ ) { y_index_fx[i] = extract_h(L_shl(L_temp_band_energy[harmonic_band_fx+i], sub(16, SWB_BWE_LR_Qbe))); + move16(); index_fx[i] = add(harmonic_band_fx, i); move16(); } - reordvct_fx(y_index_fx, sub(N_fx, harmonic_band_fx), index_fx); + reordvct(y_index_fx, sub(N_fx, harmonic_band_fx), index_fx); /* Log2 */ L_temp = L_deposit_l(band_width_fx[index_fx[0]]); @@ -500,10 +562,12 @@ void hq2_bit_alloc_har_fx ( L_grp_thr[3] = L_shl(L_deposit_l(esthf_bits_fx), SWB_BWE_LR_QRk); move16(); - L_norm_sum = L_deposit_l(1); + L_norm_sum = 1; + move32(); FOR(i=0; i<3; i++) { L_norm_sum = L_add( L_norm_sum, L_Ravg_sub[i]); + move32(); } /*reserve bits for HF coding */ @@ -528,11 +592,11 @@ void hq2_bit_alloc_har_fx ( Inv_p2a_bands_fx = div_s(0x3fff, shl(p2a_bands_fx, exp_normd)); /* 14-exp_normd+15 */ QIpb = sub(29, exp_normd); - L_temp = L_shl(Mult_32_16(L_Ravg_sub[GRP_SB-1], Inv_p2a_bands_fx), sub(SWB_BWE_LR_Qbe, sub(QIpb,1))); + L_temp = L_shl(Mpy_32_16(L_Ravg_sub[GRP_SB-1], Inv_p2a_bands_fx), sub(SWB_BWE_LR_Qbe, sub(QIpb,1))); L_norm_diff = L_sub(L_temp, L_norm_sum_avg); /* Qbe */ - L_temp = Mult_32_16(L_Ravg_sub[GRP_SB-1], sub(GRP_SB, 1)); /* Qbe+0+1 */ - L_temp = Mult_32_16(L_temp, Inv_norm_sum_fx); /* Qbe+1+QIpb+1 */ + L_temp = Mpy_32_16(L_Ravg_sub[GRP_SB-1], sub(GRP_SB, 1)); /* Qbe+0+1 */ + L_temp = Mpy_32_16(L_temp, Inv_norm_sum_fx); /* Qbe+1+QIpb+1 */ lf_hf_ge_r_fx = round_fx(L_shl(L_temp, sub(15+16, sub(add(SWB_BWE_LR_Qbe, QIns),30)))); exp_normn = norm_s(norm_sum_fx); @@ -542,12 +606,11 @@ void hq2_bit_alloc_har_fx ( div_fx = div_s(shl(norm_sum_fx, exp_normn), shl(harmonic_band_fx, exp_normd)); L_avg_enhf_en_diff = L_sub(L_temp_band_energy[index_fx[0]], L_shl(L_deposit_h(div_fx), sub(sub(SWB_BWE_LR_Qbe, (add(Qns,sub(exp_normn,exp_normd)))),31))); /* Qbe - (Qns+exp_normn-(exp_normd)+15) -16 */ - test(); IF( sub(lf_hf_ge_r_fx , 26214) > 0x0 && L_sub(L_avg_enhf_en_diff, (Word32)(8< 0x0L) /* 0.8=26214.4(Q15) 8.0f=131072(Qbe) */ { bits_allocweigh_fx = 6554; move16(); /* 0.2 6553.6(Q15) */ - if(L_norm_diff < 0x0L) + IF(L_norm_diff < 0x0L) { bits_allocweigh_fx = 13107; move16(); /* 0.4 13107.2(Q15) */ @@ -556,15 +619,15 @@ void hq2_bit_alloc_har_fx ( /*allocate bits*/ /*Bits_grp[GRP_SB-1] = (short)min((grp_bit_avg/p2a_bands + bits_allocweigh*norm_diff),10);*/ L_temp = L_mult(grp_bit_avg_fx, Inv_p2a_bands_fx); /* Q0+QIpb+1 */ - L_temp2 = Mult_32_16(L_norm_diff, bits_allocweigh_fx); /* Qbe+Q15-15 */ + L_temp2 = Mpy_32_16(L_norm_diff, bits_allocweigh_fx); /* Qbe+Q15-15 */ L_temp = L_shr(L_temp, add(QIpb, 1)); L_temp = L_add(L_shl(L_temp,SWB_BWE_LR_Qbe), L_temp2); Bits_grp_fx[GRP_SB-1] = extract_h(L_shl(L_temp, sub(16, SWB_BWE_LR_Qbe))); Bits_grp_fx[GRP_SB-1] = s_min(Bits_grp_fx[GRP_SB-1], 10); - move16(); + test(); if( sub(Bits_grp_fx[GRP_SB-1], esthf_bits_fx) < 0 ) { Bits_grp_fx[GRP_SB-1] = 0; @@ -580,29 +643,27 @@ void hq2_bit_alloc_har_fx ( IF( sub(final_gr_fact_pos_fx, 1) == 0 ) { - L_temp = Mult_32_16(L_Ravg_sub[1], extract_h(L_mult(bits_fact_fx, B_norm_fx))); - L_temp = Mult_32_16(L_temp, Inv_norm_sum_fx); + L_temp = Mpy_32_16(L_Ravg_sub[1], extract_h(L_mult(bits_fact_fx, B_norm_fx))); + L_temp = Mpy_32_16(L_temp, Inv_norm_sum_fx); Bits_grp_fx[1] = extract_h(L_shr(L_temp, exp_shift)); - L_temp = Mult_32_16(L_Ravg_sub[2], extract_h(L_mult(bits_fact1_fx, B_norm_fx))); - L_temp = Mult_32_16(L_temp, Inv_norm_sum_fx); + L_temp = Mpy_32_16(L_Ravg_sub[2], extract_h(L_mult(bits_fact1_fx, B_norm_fx))); + L_temp = Mpy_32_16(L_temp, Inv_norm_sum_fx); Bits_grp_fx[2] = extract_h(L_shr(L_temp, exp_shift)); Bits_grp_fx[0] = sub(sub(B_fx, Bits_grp_fx[1]), Bits_grp_fx[2]); - move16(); } ELSE { - L_temp = Mult_32_16(L_Ravg_sub[0], extract_h(L_mult(bits_fact_fx, B_norm_fx))); - L_temp = Mult_32_16(L_temp, Inv_norm_sum_fx); + L_temp = Mpy_32_16(L_Ravg_sub[0], extract_h(L_mult(bits_fact_fx, B_norm_fx))); + L_temp = Mpy_32_16(L_temp, Inv_norm_sum_fx); Bits_grp_fx[0] = extract_h(L_shr(L_temp, exp_shift)); - L_temp = Mult_32_16(L_Ravg_sub[2], extract_h(L_mult(bits_fact1_fx, B_norm_fx))); - L_temp = Mult_32_16(L_temp, Inv_norm_sum_fx); + L_temp = Mpy_32_16(L_Ravg_sub[2], extract_h(L_mult(bits_fact1_fx, B_norm_fx))); + L_temp = Mpy_32_16(L_temp, Inv_norm_sum_fx); Bits_grp_fx[2] = extract_h(L_shr(L_temp, exp_shift)); Bits_grp_fx[1] = sub(sub(B_fx, Bits_grp_fx[0]), Bits_grp_fx[2]); - move16(); } IF( sub(Bits_grp_fx[2], THR2 ) < 0 ) @@ -621,35 +682,28 @@ void hq2_bit_alloc_har_fx ( } ELSE { - set32_fx(L_Rsubband+grp_bound_fx[i], 0x0L, sub(grp_bound_fx[i+1], grp_bound_fx[i])); + set_val_Word32(L_Rsubband+grp_bound_fx[i], 0x0L, sub(grp_bound_fx[i+1], grp_bound_fx[i])); IF( sub(i, GRP_SB-1) == 0 ) { - set16_fx(p2a_flags_fx+grp_bound_fx[i], 0, sub(grp_bound_fx[i+1], grp_bound_fx[i])); + set_val_Word16(p2a_flags_fx+grp_bound_fx[i], 0, sub(grp_bound_fx[i+1], grp_bound_fx[i])); } } } - return; } -/*--------------------------------------------------------------------------* - * hq2_bit_alloc() - * - * HQ2 bit-allocation - *--------------------------------------------------------------------------*/ - -Word32 hq2_bit_alloc_fx ( - const Word32 L_band_energy[], /* i : band energy of each subband */ - const Word16 bands, /* i : total number of subbands in a frame */ - Word32 L_Rk[], /* i/o: Bit allocation/Adjusted bit alloc. */ - Word16 *bit_budget_fx, /* i/o: bit bugdet */ - Word16 *p2a_flags, /* i : HF tonal indicator */ - const Word16 weight_fx, /* i : weight */ - const Word16 band_width[], /* i : Sub band bandwidth */ - const Word16 num_bits, /* i : available bits */ - const Word16 hqswb_clas, /* i : HQ2 class information */ - const Word16 bwidth, /* i : input bandwidth */ - const Word16 is_transient /* i : indicator HQ_TRANSIENT or not */ +void hq2_bit_alloc ( + const float band_energy[], /* i : band energy of each subband */ + const short bands, /* i : total number of subbands in a frame */ + Word32 L_Rk[], /* i/o: Bit allocation/Adjusted bit alloc. */ + short *bit_budget_fx, /* i/o: bit bugdet */ + short *p2a_flags, /* i : HF tonal indicator */ + const Word16 weight_fx, /* i : weight (Q13) */ + const short band_width[], /* i : Sub band bandwidth */ + const short num_bits, /* i : available bits */ + const short hqswb_clas, /* i : HQ2 class information */ + const short bwidth, /* i : input bandwidth */ + const short is_transient /* i : indicator HQ_TRANSIENT or not */ ) { Word16 j, k; @@ -678,6 +732,13 @@ Word32 hq2_bit_alloc_fx ( Word32 L_THR1, L_THR2, L_THR3; + Word32 L_band_energy[BANDS_MAX]; + + for(k=0; k 0) { /*Rk[k] = ((float) *bit_budget / Rcnt + weight * (band_energy[k] - Ravg)); */ - L_tmp = Mult_32_16(L_sub(L_shl(L_band_energy[k], sub(SWB_BWE_LR_QRk, SWB_BWE_LR_Qbe)), L_Ravg), weight_fx); /* SWB_BWE_LR_QRk + Q13 - 15 */ + L_tmp = Mpy_32_16(L_sub(L_shl(L_band_energy[k], sub(SWB_BWE_LR_QRk, SWB_BWE_LR_Qbe)), L_Ravg), weight_fx); /* SWB_BWE_LR_QRk + Q13 - 15 */ L_tmp = L_shl(L_tmp, 2); /* -> SWB_BWE_LR_QRk */ L_Rk[k] = L_add(L_shr(L_deposit_l(div_fx), sub(Qdiv, SWB_BWE_LR_QRk)) , L_tmp); - move32(); } } negflag = 0; move16(); - L_Rcalc = L_deposit_l(0); + L_Rcalc = 0; + move32(); FOR (k = 0; k < bands; k++) { IF ( L_sub(L_Rk[k], MIN_BITS_FIX) < 0 ) { - L_Rk[k] = L_deposit_l(0); + L_Rk[k] = 0x0L; + move32(); negflag = 1; move16(); } @@ -790,33 +865,38 @@ Word32 hq2_bit_alloc_fx ( } /* prune noiselike bands with low allocation */ - test(); IF ( sub(num_bits, HQ_16k40_BIT) <= 0 && negflag == 0) { - L_maxxy = L_deposit_l(0); + L_maxxy = 0; + move32(); maxdex_fx = -1; move16(); - L_Rcalc = L_deposit_l(0); + L_Rcalc = 0; + move32(); /* find worst under-allocation */ FOR (k = sub(bands, 1); k >= 0; k--) { + /* dummy = ((float) min (band_width[k], max (12, band_width[k] / 4))) - Rk[k]; */ tmp_fx = s_min( band_width[k], s_max(12, shr( band_width[k], 2))); L_dummy = L_sub(L_shl(L_deposit_l(tmp_fx), SWB_BWE_LR_QRk), L_Rk[k]) ; /*SWB_BWE_LR_QRk */ test(); test(); + test(); IF ( p2a_flags[k] == 0 && L_sub(L_dummy, L_maxxy) > 0 && L_Rk[k] > 0 ) { maxdex_fx = k; move16(); - L_maxxy = L_add(0,L_dummy); /*SWB_BWE_LR_QRk */ + L_maxxy = L_dummy; + move32();/*SWB_BWE_LR_QRk */ } } /* prune worst allocation and recalculate total allocation */ - if ( sub(maxdex_fx, -1) > 0) + IF ( sub(maxdex_fx, -1) > 0) { - L_Rk[maxdex_fx] = L_deposit_l(0); + L_Rk[maxdex_fx] = 0; + move32(); } FOR (k = 0; k < bands; k++) { @@ -824,15 +904,14 @@ Word32 hq2_bit_alloc_fx ( } } test(); - test(); IF ( L_sub(L_Rcalc, L_Rcalc1) == 0 && sub(bwidth, SWB) == 0 ) { /* Reallocate bits to individual subbands for HQ_NORMAL mode */ /* if bits allocated to subbands areless than predefined threshold */ - test(); IF( sub(hqswb_clas, HQ_NORMAL) == 0 && sub(num_bits, HQ_16k40_BIT) < 0 ) { - L_dummy = L_deposit_l(0); + L_dummy = 0x0L; + move32(); FOR( k = 0; k < bands; k++ ) { test(); @@ -842,15 +921,18 @@ Word32 hq2_bit_alloc_fx ( test(); IF( sub(k, 11) < 0 && L_sub(L_Rk[k], L_THR1) < 0 ) { - L_Rk[k] = L_deposit_l(0); + L_Rk[k] = 0x0L; + move32(); } ELSE IF( sub(k, 11) >= 0 && sub(k, 16) < 0 && L_sub(L_Rk[k], L_THR2) < 0 ) { - L_Rk[k] = L_deposit_l(0); + L_Rk[k] = 0x0L; + move32(); } - ELSE if( sub(k, 16) >= 0 && sub(k, bands ) < 0 && L_sub(L_Rk[k], L_THR3) < 0 ) + ELSE IF( sub(k, 16) >= 0 && sub(k, bands ) < 0 && L_sub(L_Rk[k], L_THR3) < 0 ) { - L_Rk[k] = L_deposit_l(0); + L_Rk[k] = 0x0L; + move32(); } L_dummy = L_add(L_dummy, L_Rk[k]); @@ -865,12 +947,11 @@ Word32 hq2_bit_alloc_fx ( move16(); FOR( k=0; k +#include +#include "options.h" +#include "cnst.h" +#include "rom_com.h" +#include "prot.h" +#include "basop_util.h" +#include "basop_proto_func.h" + +/*--------------------------------------------------------------------------* + * mdct_spectrum_denorm() + * + * + *--------------------------------------------------------------------------*/ + +void mdct_spectrum_denorm( + const int inp_vector[], + float y2[], + const short band_start[], + const short band_end[], + const short band_width[], + const float band_energy[], + const int npulses[], + const short bands, + const float ld_slope, + const float pd_thresh +) +{ + short i, k; + float Eyy, gamma, pd, gain_tweak; + + for (k = 0; k < bands; k++) + { + Eyy = 0; + for (i = band_start[k]; i <= band_end[k]; i++) + { + Eyy += (float) inp_vector[i] * inp_vector[i]; + } + + if (Eyy > 0.0f) + { + /* Set gamma to be pulse gain which results in perfect quantized subband energy */ + gamma = (float) sqrt (pow (2.0f, band_energy[k]) / Eyy); + + /* Adjust gamma based on pulse density (0 bit MSE gain estimator) */ + pd = (float) npulses[k] / band_width[k]; + if (pd < pd_thresh) + { + gain_tweak = (float) pow (2.0f, (ld_slope * log2_f (pd / pd_thresh))); + gamma *= gain_tweak; + } + + for (i = band_start[k]; i <= band_end[k]; i++) + { + y2[i] = gamma * inp_vector[i]; + } + } + } + + return; +} +/*--------------------------------------------------------------------------* + * hq2_core_configure() + * + * + *--------------------------------------------------------------------------*/ + +void hq2_core_configure( + const short frame_length, /* i : frame length */ + const short num_bits, /* i : number of bits */ + const short is_transient, /* i : transient flag */ + short *bands, + short *length, + short band_width[], + short band_start[], + short band_end[], + Word32 *L_qint, + Word16 *eref_fx, + Word16 *bit_alloc_weight_fx, + short *gqlevs, + short *Ngq, + short *p2a_bands, + float *p2a_th, + float *pd_thresh, + float *ld_slope, + float *ni_coef, + float *ni_pd_th, + long bwe_br +) +{ + const Xcore_Config *xcore_config; + + short i, k; + short bands_sh; + + if( frame_length == L_FRAME8k ) + { + if( is_transient ) + { + if (num_bits <= ACELP_7k20 / 50) + { + xcore_config = &xcore_config_8kHz_007200bps_short; + } + else if (num_bits <= ACELP_8k00 / 50) + { + xcore_config = &xcore_config_8kHz_008000bps_short; + } + else if (num_bits <= ACELP_13k20 / 50) + { + xcore_config = &xcore_config_8kHz_013200bps_short; + } + else + { + xcore_config = &xcore_config_8kHz_016400bps_short; + } + } + else + { + if (num_bits <= ACELP_7k20 / 50) + { + xcore_config = &xcore_config_8kHz_007200bps_long; + } + else if (num_bits <= ACELP_8k00 / 50) + { + xcore_config = &xcore_config_8kHz_008000bps_long; + } + else if (num_bits <= ACELP_13k20 / 50) + { + xcore_config = &xcore_config_8kHz_013200bps_long; + } + else + { + xcore_config = &xcore_config_8kHz_016400bps_long; + } + } + } + else if( frame_length == L_FRAME16k ) + { + if( is_transient ) + { + if (num_bits <= ACELP_13k20 / 50) + { + xcore_config = &xcore_config_16kHz_013200bps_short; + } + else + { + xcore_config = &xcore_config_16kHz_016400bps_short; + } + } + else + { + if (num_bits <= ACELP_13k20 / 50) + { + xcore_config = &xcore_config_16kHz_013200bps_long; + } + else + { + xcore_config = &xcore_config_16kHz_016400bps_long; + } + } + } + else /* (bwidth == SWB) */ + { + if( is_transient ) + { + if (bwe_br == ACELP_13k20) + { + xcore_config = &xcore_config_32kHz_013200bps_short; + } + else + { + xcore_config = &xcore_config_32kHz_016400bps_short; + } + } + else + { + if (bwe_br == ACELP_13k20) + { + xcore_config = &xcore_config_32kHz_013200bps_long; + } + else + { + xcore_config = &xcore_config_32kHz_016400bps_long; + } + } + } + + *bands = xcore_config->bands; + *length = xcore_config->bw; + *L_qint = xcore_config->L_qint; + *eref_fx = xcore_config->eref_fx; + *bit_alloc_weight_fx = xcore_config->bit_alloc_weight_fx; + *gqlevs = xcore_config->gqlevs; + *Ngq = xcore_config->Ngq; + + *p2a_bands = xcore_config->p2a_bands; + *p2a_th = xcore_config->p2a_th; + + *pd_thresh = xcore_config->pd_thresh; + *ld_slope = xcore_config->ld_slope; + *ni_coef = xcore_config->ni_coef; + *ni_pd_th = xcore_config->ni_pd_th; + + mvs2s (xcore_config->band_width, band_width, *bands); + + /* Expand band_width[] table for short windows */ + if( is_transient ) + { + bands_sh = *bands; + *bands = NUM_TIME_SWITCHING_BLOCKS * bands_sh; + *length *= NUM_TIME_SWITCHING_BLOCKS; + + for( i = 1; i <= 3; i++ ) + { + for( k = 0; k < bands_sh; k++ ) + { + band_width[i * bands_sh + k] = band_width[k]; + } + } + } + + /* Formulate band_start and band_end tables from band_width table */ + band_start[0] = 0; + band_end[0] = band_width[0] - 1; + for( k = 1; k < *bands; k++ ) + { + band_start[k] = band_start[k - 1] + band_width[k - 1]; + band_end[k] = band_start[k] + band_width[k] - 1; + } + + + return; +} + +/*--------------------------------------------------------------------------* + * reverse_transient_frame_energies() + * + * + *--------------------------------------------------------------------------*/ + +void reverse_transient_frame_energies( + float band_energy[], /* o : band energies */ + const short bands /* i : number of bands */ +) +{ + short k, k1, k2; + float be; + + k1 = bands/4; + k2 = bands/2-1; + for( k = 0; k < bands/8; k++ ) + { + be = band_energy[k1]; + band_energy[k1] = band_energy[k2]; + band_energy[k2] = be; + k1++, k2--; + } + + k1 = 3*bands/4; + k2 = bands-1; + for( k = 0; k < bands/8; k++ ) + { + be = band_energy[k1]; + band_energy[k1] = band_energy[k2]; + band_energy[k2] = be; + k1++, k2--; + } + + return; +} + +void bit_allocation_second_fx( + Word32 *Rk, + Word32 *Rk_sort, + Word16 BANDS, + const Word16 *band_width, + Word16 *k_sort, + Word16 *k_num, + const Word16 *p2a_flags, + const Word16 p2a_bands, + const Word16 *last_bitalloc, + const Word16 input_frame +) +{ + Word16 k, k2 = 0; + Word16 ever_bits[BANDS_MAX], ever_sort[BANDS_MAX];/*Q12 */ + Word16 class_flag = 0; + Word16 rk_temp = 32767, ever_temp = 32767;/*Q12 */ + Word16 exp; + Word16 tmp; + Word32 L_tmp; + + for (k = 0; k < BANDS; k++) + { + if((( sub(k_sort[k],sub(BANDS,p2a_bands)) >= 0 )&&( sub(p2a_flags[k_sort[k]],1) == 0 )) || + (( sub(k_sort[k],sub(BANDS,2)) >= 0 )&&( sub(last_bitalloc[sub(k_sort[k], sub(BANDS,2))], 1) == 0 ))) + { + exp = norm_s(band_width[k_sort[k]]); + tmp = shl(band_width[k_sort[k]],exp);/*Q(exp) */ + tmp = div_s(16384,tmp);/*Q(15+14-exp = 29-exp) */ + L_tmp = Mult_32_16(Rk_sort[k],tmp);/* Q(16+29-exp-15 = 30-exp) */ + tmp = sub(18,exp); + ever_bits[k] = extract_l(L_shr(L_tmp,tmp));/*Q12 */ + if( sub(ever_bits[k],rk_temp) < 0 ) + { + rk_temp = ever_bits[k]; + k2 = k; + } + class_flag = 1; + } + } + if( class_flag ==0 || sub(input_frame,L_FRAME8k) == 0) + { + for(k = 0; k < BANDS; k++) + { + if( sub(k_sort[k],sub(BANDS,p2a_bands)) < 0 && Rk_sort[k] > 0 ) + { + exp = norm_s(band_width[k_sort[k]]); + tmp = shl(band_width[k_sort[k]],exp);/*Q(exp) */ + tmp = div_s(16384,tmp);/*Q(15+14-exp = 29-exp) */ + L_tmp = Mult_32_16(Rk_sort[k],tmp);/* Q(16+29-exp-15 = 30-exp) */ + tmp = sub(18,exp); + ever_sort[k] = extract_l(L_shr(L_tmp,tmp));/*Q12 */ + IF(sub(ever_sort[k],ever_temp) < 0) + { + ever_temp = ever_sort[k]; + k2 = k; + } + } + } + } + + k_num[0] = k2; + if(sub(k_sort[k2],sub(BANDS,1)) == 0) + { + for (k = 0; k < BANDS; k++) + { + if(sub(k_sort[k],sub(k_sort[k2],1)) == 0) + { + k_num[1] = k; + } + } + } + else if(k_sort[k2] == 0) + { + for (k = 0; k < BANDS; k++) + { + if(sub(k_sort[k],add(k_sort[k2],1)) == 0) + { + k_num[1] = k; + } + } + } + else + { + if ( L_sub( Rk[sub(k_sort[k2],1)],Rk[add(k_sort[k2],1)] ) < 0 ) + { + for (k = 0; k < BANDS; k++) + { + if(sub(k_sort[k],sub(k_sort[k2],1)) == 0) + { + k_num[1] = k; + } + } + } + else + { + for (k = 0; k < BANDS; k++) + { + if(sub(k_sort[k],add(k_sort[k2],1)) == 0) + { + k_num[1] = k; + } + } + } + } +} + +/*--------------------------------------------------------------------------* + * spt_shorten_domain_pre() + * + * Compute shorten subband if previous frame has spectral peak. + *--------------------------------------------------------------------------*/ + +void spt_shorten_domain_pre( + const short band_start[], /* i: Starting position of sub band */ + const short band_end[], /* i: End position of sub band */ + const short prev_SWB_peak_pos[], /* i: Spectral peak */ + const short BANDS, /* i: total number of bands */ + const long bwe_br, /* i: bitrate information */ + short new_band_start[], /* o: Starting position of new shorten sub band */ + short new_band_end[], /* o: End position of new shorten sub band */ + short new_band_width[] /* o: new sub band bandwidth */ +) +{ + int j; + int k; + int kpos; + + short new_band_width_half; + const short *p_bw_SPT_tbl; /* pointer of bw_SPT_tbl */ + + p_bw_SPT_tbl = bw_SPT_tbl[0]; + if( bwe_br == HQ_16k40 ) + { + p_bw_SPT_tbl = bw_SPT_tbl[1]; + } + + kpos = 0; + j = 0; + for(k=BANDS-SPT_SHORTEN_SBNUM; k band_end[k] ) + { + new_band_end[j] = band_end[k]; + new_band_start[j] = new_band_end[j] - (new_band_width[j] - 1); + } + } + else + { + new_band_width[j] = p_bw_SPT_tbl[j]; + + /*shorten the bandwidth for pulse resolution*/ + new_band_width_half = new_band_width[j]/2; + new_band_start[j] = (band_start[k]+band_end[k])/2 - new_band_width_half; + new_band_end[j] = (band_start[k]+band_end[k])/2 + new_band_width_half; + } + + kpos++; + j++; + } + + return; +} + +/*--------------------------------------------------------------------------* + * spt_shorten_domain_band_save() + * + * Store the original subband information + *--------------------------------------------------------------------------*/ + +void spt_shorten_domain_band_save( + const short bands, /* i: total subband */ + const short band_start[], /* i: starting position of subband */ + const short band_end[], /* i: end position of subband */ + const short band_width[], /* i: band width of subband */ + short org_band_start[], /* o: starting position of subband */ + short org_band_end[], /* o: end position of subband */ + short org_band_width[] /* o: band width of subband */ +) +{ + int k; + int kpos; + + kpos = 0; + for(k=bands-SPT_SHORTEN_SBNUM; k 0x0L ) - { - /* Set gamma to be pulse gain which results in perfect quantized subband energy */ - /*gamma = (float) sqrt (pow (2.0f, band_energy[k]) / Eyy); */ - - /* Pow part (pow(2.0f, band_energy) ) */ - L_temp = L_shr(L_band_energy[k], sub(SWB_BWE_LR_Qbe, 16)); - temp_lo_fx = L_Extract_lc(L_temp, &temp_hi_fx); - Qpow = sub(14, temp_hi_fx); - pow_fx = extract_l(Pow2(14, temp_lo_fx)); /* Qpow */ - - /* Div part ( pow (2.0f, band_energy[i])/Eyy ) */ - exp_normn = norm_s(pow_fx); - exp_normn = sub(exp_normn, 1); - exp_normd = norm_l(L_Eyy); - temp_fx = div_s( shl( pow_fx, exp_normn), extract_h(L_shl(L_Eyy, exp_normd))); - Qdiv = add(sub(add(Qpow, exp_normn) , add(QEyy, exp_normd)), 31); - - exp_norm = norm_s(temp_fx); - temp_fx = shl(temp_fx, exp_norm); - Qdiv = add(Qdiv, exp_norm); - - /* Sqrt part sqrt(pow (2.0f, band_energy[i])/Eyy) */ - Qgamma = add(Qdiv, 16); - IF ( s_and(Qdiv, 1) == 0 ) /* Qdiv % 2 == 0 */ - { - L_temp = Sqrt_l(L_shr(L_deposit_h(temp_fx),1), &exp_norm); - L_temp = L_shr(L_temp, exp_norm); - Qgamma = sub(shr(Qgamma, 1), 1); - gamma_fx = round_fx(L_temp); - } - ELSE - { - L_temp = Sqrt_l(L_deposit_h(temp_fx), &exp_norm); - L_temp = L_shr(L_temp, exp_norm); - Qgamma = shr(Qgamma, 1); - gamma_fx = round_fx(L_temp); - } - - /* Adjust gamma based on pulse density (0 bit MSE gain estimator) */ - /*pd = (float) npulses[k] / band_width[k]; */ - exp_normn = norm_s(npulses[k]); - exp_normn = sub(exp_normn, 1); - exp_normd = norm_s(band_width[k]); - pd_fx = div_s(shl(npulses[k],exp_normn), shl(band_width[k], exp_normd)); - Qpd = add(sub(exp_normn, exp_normd), 15); - - cond_fx = sub(shl(pd_fx, sub(15, Qpd)), pd_thresh_fx/*Q15*/); - Overflow = 0; - move16(); /* allow overflow happen. */ - IF ( cond_fx < 0 ) - { - /*gain_tweak = (float) pow (2.0f, (ld_slope * log2_f (pd / pd_thresh))); */ - /* Div part */ - exp_normn = norm_s(pd_fx); - exp_normn = sub(exp_normn, 1); - exp_normd = norm_s(pd_thresh_fx); - div_pd_fx = div_s(shl(pd_fx, exp_normn), shl(pd_thresh_fx, exp_normd)); /* Qpd+exp_normn - (15 + exp_normd) + 15 */ - Qdivpd = add(sub(add(Qpd, exp_normn), add(15, exp_normd)), 15); - - /* Log2 part */ - exp_norm = norm_s(div_pd_fx); - L_div_pd = L_deposit_h(shl(div_pd_fx, exp_norm)); - Qdivpd = add(add(Qdivpd, exp_norm), 16); - - frac = Log2_norm_lc(L_div_pd); - exp = sub(30, Qdivpd); - L_tmp = L_Comp(exp, frac); /* Q16 */ - - /* Mult part */ - L_tmp = Mpy_32_16_1(L_tmp, ld_slope_fx); - - /* Pow part */ - temp_lo_fx = L_Extract_lc(L_tmp, &temp_hi_fx); - Qtweak = sub(14, temp_hi_fx); - gain_tweak_fx = extract_l(Pow2(14, temp_lo_fx)); - - /*gamma *= gain_tweak; */ - L_tmp = L_mult(gamma_fx, gain_tweak_fx); /* Qgamma+Qtweak+1 */ - exp_norm = norm_l(L_tmp); - gamma_fx = round_fx(L_shl(L_tmp, exp_norm)); - Qgamma = sub(add(add(Qgamma, Qtweak), exp_norm), 15);/*Qgamma+Qtweak+1+exp_norm-16; */ - } - - exp_shift = sub(SWB_BWE_LR_Qs-1, Qgamma); - FOR (i = band_start[k]; i <= band_end[k]; i++) - { - /*y2[i] = gamma * inp_vector[i]; */ - L_tmp = L_mult(gamma_fx, (Word16)inp_vector[i]); /* Qgamma+0+1=Qgamma+1 */ - L_y2[i] = L_shl(L_tmp, exp_shift); - move32(); - } - } - } - - return; -} -/*==========================================================================*/ -/* FUNCTION : void hq2_core_configure_fx() */ -/*--------------------------------------------------------------------------*/ -/* PURPOSE : */ -/*--------------------------------------------------------------------------*/ -/* INPUT ARGUMENTS : */ -/*--------------------------------------------------------------------------*/ -/* OUTPUT ARGUMENTS : */ -/* Word16 *qint o: Q13 */ -/* Word16 *eref o: Q10 */ -/* Word16 *bit_alloc_weight o: Q13 */ -/* Word16 *p2a_th o: Q11 */ -/* Word16 *pd_thresh o: Q15 */ -/* Word16 *ld_slope o: Q15 */ -/* Word16 *ni_coef o: Q14 */ -/*--------------------------------------------------------------------------*/ -/* INPUT/OUTPUT ARGUMENTS : */ -/*--------------------------------------------------------------------------*/ -/* RETURN ARGUMENTS : */ -/* _ None */ -/*--------------------------------------------------------------------------*/ -/* CALLED FROM : */ -/*==========================================================================*/ - -void hq2_core_configure_fx ( - const Word16 frame_length, - const Word16 num_bits, - const Word16 is_transient, - Word16 *bands, - Word16 *length, - Word16 band_width[], - Word16 band_start[], - Word16 band_end[], - Word32 *L_qint, - Word16 *eref, - Word16 *bit_alloc_weight, - Word16 *gqlevs, - Word16 *Ngq, - Word16 *p2a_bands, - Word16 *p2a_th, - Word16 *pd_thresh, - Word16 *ld_slope, - Word16 *ni_coef, - Word32 L_bwe_br -) -{ - const Xcore_Config_fx *xcore_config_fx; - - Word16 i, k; - Word16 bands_sh; - - xcore_config_fx = &xcore_config_32kHz_013200bps_long_fx; /* default set for VC Warning */ - - IF ( sub(frame_length, L_FRAME8k) == 0 ) - { - IF( is_transient ) - { - IF ( sub(num_bits, ACELP_7k20 / 50) <= 0 ) - { - xcore_config_fx = &xcore_config_8kHz_007200bps_short_fx; - } - ELSE IF ( sub(num_bits, ACELP_8k00 / 50) <= 0 ) - { - xcore_config_fx = &xcore_config_8kHz_008000bps_short_fx; - } - ELSE IF ( sub(num_bits, ACELP_13k20 / 50) <= 0 ) - { - xcore_config_fx = &xcore_config_8kHz_013200bps_short_fx; - } - ELSE - { - xcore_config_fx = &xcore_config_8kHz_016400bps_short_fx; - } - } - ELSE - { - IF ( sub(num_bits, ACELP_7k20 / 50) <= 0 ) - { - xcore_config_fx = &xcore_config_8kHz_007200bps_long_fx; - } - ELSE IF ( sub(num_bits, ACELP_8k00 / 50) <= 0 ) - { - xcore_config_fx = &xcore_config_8kHz_008000bps_long_fx; - } - ELSE IF ( sub(num_bits, ACELP_13k20 / 50) <= 0) - { - xcore_config_fx = &xcore_config_8kHz_013200bps_long_fx; - } - ELSE - { - xcore_config_fx = &xcore_config_8kHz_016400bps_long_fx; - } - } - } - ELSE IF ( sub(frame_length, L_FRAME16k) == 0 ) - { - IF (is_transient) - { - IF ( sub(num_bits, ACELP_13k20 / 50) <= 0 ) - { - xcore_config_fx = &xcore_config_16kHz_013200bps_short_fx; - move16(); - } - ELSE if ( sub(num_bits, ACELP_16k40 / 50) <= 0 ) - { - xcore_config_fx = &xcore_config_16kHz_016400bps_short_fx; - move16(); - } - } - ELSE - { - IF ( sub(num_bits, ACELP_13k20 / 50) <= 0 ) - { - xcore_config_fx = &xcore_config_16kHz_013200bps_long_fx; - move16(); - } - ELSE if ( sub(num_bits, ACELP_16k40 / 50) <= 0 ) - { - xcore_config_fx = &xcore_config_16kHz_016400bps_long_fx; - move16(); - } - } - } - ELSE /* (frame_length == SWB) */ - { - IF (is_transient) - { - IF ( L_sub(L_bwe_br, ACELP_13k20) <= 0 ) - { - xcore_config_fx = &xcore_config_32kHz_013200bps_short_fx; - move16(); - } - ELSE if ( L_sub(L_bwe_br, ACELP_16k40) <= 0 ) - { - xcore_config_fx = &xcore_config_32kHz_016400bps_short_fx; - move16(); - } - } - ELSE - { - IF ( L_sub(L_bwe_br, ACELP_13k20) <= 0 ) - { - xcore_config_fx = &xcore_config_32kHz_013200bps_long_fx; - move16(); - } - ELSE if ( L_sub(L_bwe_br, ACELP_16k40) <= 0 ) - { - xcore_config_fx = &xcore_config_32kHz_016400bps_long_fx; - move16(); - } - } - } - - *bands = xcore_config_fx->bands; - move16(); - *length = xcore_config_fx->bw; - move16(); - *L_qint = xcore_config_fx->L_qint; - move32(); - - *eref = xcore_config_fx->eref; - move16(); - *bit_alloc_weight = xcore_config_fx->bit_alloc_weight; - move16(); - *gqlevs = xcore_config_fx->gqlevs; - move16(); - *Ngq = xcore_config_fx->Ngq; - move16(); - - *p2a_bands = xcore_config_fx->p2a_bands; - move16(); - *p2a_th = xcore_config_fx->p2a_th; - move16(); - - *pd_thresh = xcore_config_fx->pd_thresh; - move16(); - *ld_slope = xcore_config_fx->ld_slope; - move16(); - *ni_coef = xcore_config_fx->ni_coef; - move16(); - - /*mvs2s_fx (xcore_config_fx->band_width, band_width, *bands); */ - Copy(xcore_config_fx->band_width, band_width, *bands); - - /* Expand band_width[] table for short windows */ - IF (is_transient) - { - bands_sh = *bands; - move16(); - *bands = shl(bands_sh,2); - *length = shl(*length, 2); - - FOR (i = 1; i <= 3; i++) - { - FOR (k = 0; k < bands_sh; k++) - { - band_width[i * bands_sh + k] = band_width[k]; - move16(); - } - } - } - - /* Formulate band_start and band_end tables from band_width table */ - band_start[0] = 0; - move16(); - band_end[0] = sub(band_width[0], 1); - move16(); - FOR (k = 1; k < *bands; k++) - { - band_start[k] = add( band_start[k - 1] , band_width[k - 1]); - move16(); - band_end[k] = sub(add( band_start[k] , band_width[k]) , 1); - move16(); - } - - - return; -} - -/*--------------------------------------------------------------------------* - * reverse_transient_frame_energies() - * - * - *--------------------------------------------------------------------------*/ - -void reverse_transient_frame_energies_fx( - Word32 L_band_energy[], /* o : Q14 : band energies */ - const Word16 bands /* i : Q0 : number of bands */ -) -{ - Word16 k, k1, k2; - Word32 L_be; - Word16 bands_2, bands_4, bands_8; - Word32 *p_be1, *p_be2; - - bands_2 = shr(bands, 1); - bands_4 = shr(bands, 2); - bands_8 = shr(bands, 3); - - k1 = bands_4; - k2 = sub(bands_2, 1); - p_be1 = &L_band_energy[k1]; - p_be2 = &L_band_energy[k2]; - FOR( k = 0; k < bands_8; k++ ) - { - L_be = *p_be1; - move32(); - *p_be1 = *p_be2; - move32(); - *p_be2 = L_be; - move32(); - p_be1++; - p_be2--; - } - - k1 = sub(bands, bands_4); /* 3*bands/4 */ - k2 = sub(bands, 1); - p_be1 = &L_band_energy[k1]; - p_be2 = &L_band_energy[k2]; - FOR( k = 0; k < bands_8; k++ ) - { - L_be = *p_be1; - move32(); - *p_be1 = *p_be2; - move32(); - *p_be2 = L_be; - move32(); - p_be1++; - p_be2--; - } - - return; -} - - -/*--------------------------------------------------------------------------* - * spt_shorten_domain_pre() - * - * Compute shorten subband if previous frame has spectral peak. - *--------------------------------------------------------------------------*/ - -void spt_shorten_domain_pre_fx( - const Word16 band_start[], /* i: Starting position of sub band */ - const Word16 band_end[], /* i: End position of sub band */ - const Word16 prev_SWB_peak_pos[], /* i: Spectral peak */ - const Word16 BANDS, /* i: total number of bands */ - const Word32 L_bwe_br, /* i: bitrate information */ - Word16 new_band_start[], /* o: Starting position of new shorten sub band */ - Word16 new_band_end[], /* o: End position of new shorten sub band */ - Word16 new_band_width[] /* o: new sub band bandwidth */ -) -{ - Word16 j; - Word16 k; - Word16 kpos; - - Word16 new_band_width_half; - const Word16 *p_bw_SPT_tbl; /* pointer of bw_SPT_tbl */ - - p_bw_SPT_tbl = bw_SPT_tbl[0]; - if( L_sub(L_bwe_br, HQ_16k40) == 0 ) - { - p_bw_SPT_tbl = bw_SPT_tbl[1]; - } - - kpos = 0; - j = 0; - move16(); - FOR(k=sub(BANDS,SPT_SHORTEN_SBNUM); k 0 ) - { - new_band_end[j] = band_end[k]; - move16(); - new_band_start[j] = sub(new_band_end[j], sub(new_band_width[j],1)); - move16(); - } - } - ELSE - { - new_band_width[j] = p_bw_SPT_tbl[j]; - - /*shorten the bandwidth for pulse resolution*/ - new_band_width_half = shr(new_band_width[j], 1); - move16(); - new_band_start[j] = sub(shr(add(band_start[k], band_end[k]), 1), new_band_width_half); - move16(); - new_band_end[j] = add(shr(add(band_start[k], band_end[k]), 1), new_band_width_half); - move16(); - } - - kpos = add(kpos, 1); - j = add(j, 1); - } - - return; -} - -/*--------------------------------------------------------------------------* - * spt_shorten_domain_band_save() - * - * Store the original subband information - *--------------------------------------------------------------------------*/ - -void spt_shorten_domain_band_save_fx( - const Word16 bands, /* i: total subband */ - const Word16 band_start[], /* i: starting position of subband */ - const Word16 band_end[], /* i: end position of subband */ - const Word16 band_width[], /* i: band width of subband */ - Word16 org_band_start[], /* o: starting position of subband */ - Word16 org_band_end[], /* o: end position of subband */ - Word16 org_band_width[] /* o: band width of subband */ -) -{ - Word16 k; - Word16 kpos; - - kpos = 0; - move16(); - FOR(k=sub(bands,SPT_SHORTEN_SBNUM); k= 0 )&&( sub(p2a_flags[k_sort[k]],1) == 0 )) || - (( sub(k_sort[k],sub(BANDS,2)) >= 0 )&&( sub(last_bitalloc[sub(k_sort[k], sub(BANDS,2))], 1) == 0 ))) - { - exp = norm_s(band_width[k_sort[k]]); - tmp = shl(band_width[k_sort[k]],exp);/*Q(exp) */ - tmp = div_s(16384,tmp);/*Q(15+14-exp = 29-exp) */ - L_tmp = Mult_32_16(Rk_sort[k],tmp);/* Q(16+29-exp-15 = 30-exp) */ - tmp = sub(18,exp); - ever_bits[k] = extract_l(L_shr(L_tmp,tmp));/*Q12 */ - IF( sub(ever_bits[k],rk_temp) < 0 ) - { - rk_temp = ever_bits[k]; - move16(); - k2 = k; - move16(); - } - class_flag = 1; - } - } - test(); - IF( class_flag ==0 || sub(input_frame,L_FRAME8k) == 0) - { - FOR(k = 0; k < BANDS; k++) - { - test(); - IF( sub(k_sort[k],sub(BANDS,p2a_bands)) < 0 && Rk_sort[k] > 0 ) - { - exp = norm_s(band_width[k_sort[k]]); - tmp = shl(band_width[k_sort[k]],exp);/*Q(exp) */ - tmp = div_s(16384,tmp);/*Q(15+14-exp = 29-exp) */ - L_tmp = Mult_32_16(Rk_sort[k],tmp);/* Q(16+29-exp-15 = 30-exp) */ - tmp = sub(18,exp); - ever_sort[k] = extract_l(L_shr(L_tmp,tmp));/*Q12 */ - IF(sub(ever_sort[k],ever_temp) < 0) - { - ever_temp = ever_sort[k]; - move16(); - k2 = k; - move16(); - } - } - } - } - - k_num[0] = k2; - IF(sub(k_sort[k2],sub(BANDS,1)) == 0) - { - FOR (k = 0; k < BANDS; k++) - { - if(sub(k_sort[k],sub(k_sort[k2],1)) == 0) - { - k_num[1] = k; - move16(); - } - } - } - ELSE IF(k_sort[k2] == 0) - { - FOR (k = 0; k < BANDS; k++) - { - if(sub(k_sort[k],add(k_sort[k2],1)) == 0) - { - k_num[1] = k; - move16(); - } - } - } - ELSE - { - IF ( L_sub( Rk[sub(k_sort[k2],1)],Rk[add(k_sort[k2],1)] ) < 0 ) - { - FOR (k = 0; k < BANDS; k++) - { - if(sub(k_sort[k],sub(k_sort[k2],1)) == 0) - { - k_num[1] = k; - move16(); - } - } - } - ELSE - { - FOR (k = 0; k < BANDS; k++) - { - if(sub(k_sort[k],add(k_sort[k2],1)) == 0) - { - k_num[1] = k; - move16(); - } - } - } - } -} diff --git a/src/libs/libevs/lib_com/hq2_noise_inject.cpp b/src/libs/libevs/lib_com/hq2_noise_inject.cpp new file mode 100644 index 00000000..8ca37801 --- /dev/null +++ b/src/libs/libevs/lib_com/hq2_noise_inject.cpp @@ -0,0 +1,243 @@ +/*==================================================================================== + EVS Codec 3GPP TS26.443 Nov 13, 2018. Version 12.11.0 / 13.7.0 / 14.3.0 / 15.1.0 + ====================================================================================*/ + +#include +#include "options.h" +#include "prot.h" + +/*--------------------------------------------------------------------------* + * hq2_noise_inject() + * + * HQ2 noise injection for WB signals + *--------------------------------------------------------------------------*/ + +void hq2_noise_inject( + float y2hat[], + const short band_start[], + const short band_end[], + const short band_width[], + float Ep[], + float Rk[], + const int npulses[], + short ni_seed, + const short bands, + const short ni_start_band, + const short bw_low, + const short bw_high, + const float enerL, + const float enerH, + float last_ni_gain[], + float last_env[], + short *last_max_pos_pulse, + short *p2a_flags, + short p2a_bands, + const short hqswb_clas, + const short bwidth, + const long bwe_br +) +{ + short i, j, k, ni_end_band, satur = 0, count[BANDS_MAX], max_pos_pulse, pos; + float ni_gain[BANDS_MAX], pd[BANDS_MAX], rand, peak[BANDS_MAX], fac, env[BANDS_MAX]; + short sb = bands; + + if( (hqswb_clas == HQ_HARMONIC || hqswb_clas == HQ_NORMAL) && (bwe_br == HQ_16k40 || bwe_br == HQ_13k20) && bwidth == SWB ) + { + sb = (bwe_br == HQ_16k40) ? 19 : 17; + } + + /* calculate the envelopes/ the decoded peak coeff./number of the decoded coeff./ the last subbands of the bit-allocated/saturation of bit-allocation */ + ni_end_band = bands; + max_pos_pulse = bands; + for (k = ni_start_band; k < ni_end_band; k++) + { + pd[k] = (float) Rk[k] / band_width[k]; + env[k] = (float)sqrt(Ep[k]/band_width[k]); + + peak[k] = 0.0f; + count[k] = 0; + if(npulses[k] != 0) + { + for (i = band_start[k]; i <= band_end[k]; i++) + { + Ep[k] -= y2hat[i] * y2hat[i]; + if( fabs(y2hat[i]) > peak[k]) + { + peak[k] = (float)fabs(y2hat[i]); + } + + if(y2hat[i] != 0) + { + count[k]++; + } + } + + max_pos_pulse = k; + Ep[k] = Ep[k] > 0 ? (float)sqrt(Ep[k]/band_width[k]) : 0.0f; + } + else + { + Ep[k] = env[k]; + } + } + + for (k = ni_start_band; k < ni_end_band; k++) + { + /* calculate the noise gain */ + satur = (pd[k] >= 0.8f) ? 1 : 0; + if (satur == 0 && Ep[k] > 0) + { + if(npulses[k] != 0) + { + if( bwidth == SWB ) + { + if(hqswb_clas != HQ_TRANSIENT) + { + if(hqswb_clas == HQ_HARMONIC) + { + fac = (k <= sb) ? 6.0f*(1.5f - pd[k])*env[k]*Ep[k]/(peak[k]*peak[k]) : 1.5f*Ep[k]/peak[k]; + } + else + { + fac = (k <= sb) ? 5.0f*(1.5f - pd[k])*Ep[k]/(peak[k]) : 4.0f*Ep[k]/peak[k]; + } + } + else + { + fac = 1.1f; + } + } + else + { + fac = 20.0f*min(1.0f, (1.5f - pd[k]))*env[k]*Ep[k]/(peak[k]*peak[k]); + if(k > 1 && k < ni_end_band-1) + { + if(count[k+1] == 0 && env[k] > 0.5f*env[k+1] && env[k] < 2.0f*env[k-1]) + { + fac = 1.5f*env[k+1]/env[k]; + } + else if(count[k-1] == 0 && peak[k] > 2.0f*env[k]) + { + fac = env[k-1]/env[k]; + } + } + + if(k >= ni_end_band - p2a_bands && bwidth == WB) + { + if(bw_low*enerH > bw_high*enerL && peak[k] < 2.0f*env[k]) + { + fac *= (2.0f - Ep[k]/peak[k]); + } + + if( p2a_flags[k] == 0 && fac > 0 ) + { + fac *= min(1.25f*env[k]/(Ep[k]*fac), 1.5f); + } + } + } + } + else + { + fac = (hqswb_clas == HQ_HARMONIC && bwidth == SWB) ? 0.8f : 1.1f; + } + + ni_gain[k] = fac * Ep[k]; + } + else + { + ni_gain[k] = 0.0; + } + + /* smooth the noise gain between the current frame and the previous frame */ + pos = bwidth == SWB ? ni_end_band-1 : max(max_pos_pulse, *last_max_pos_pulse); + + if(k <= pos) + { + if(k > 0 && k < ni_end_band-1) + { + if( (env[k] > 0.5f*last_env[k] && env[k] < 2.0f*last_env[k]) || + (((env[k]+env[k-1]+env[k+1]) > 0.5f*(last_env[k]+last_env[k-1]+last_env[k+1])) && + ((env[k]+env[k-1]+env[k+1]) < 2.0f*(last_env[k]+last_env[k-1]+last_env[k+1]))) ) + { + if(ni_gain[k] > last_ni_gain[k]) + { + ni_gain[k] = 0.2f*ni_gain[k] + 0.8f*last_ni_gain[k]; + } + else + { + ni_gain[k] = 0.6f*ni_gain[k] + 0.4f*last_ni_gain[k]; + } + } + } + else if (k == ni_end_band-1) + { + if( (env[k] > 0.5f*last_env[k] && env[k] < 2.0f*last_env[k]) || + ((env[k]+env[k-1]) > 0.5f*(last_env[k]+last_env[k-1]) && + (env[k]+env[k-1]) < 2.0f*(last_env[k]+last_env[k-1])) ) + { + if(ni_gain[k] > last_ni_gain[k]) + { + ni_gain[k] = 0.2f*ni_gain[k] + 0.8f*last_ni_gain[k]; + } + else + { + ni_gain[k] = 0.6f*ni_gain[k] + 0.4f*last_ni_gain[k]; + } + } + } + } + + /* inject noise into the non-decoded coeffs */ + if(k >= ni_end_band - p2a_bands && p2a_flags[k] == 0 && bwidth != SWB) + { + for (i = band_start[k]; i <= band_end[k]; i++) + { + if (y2hat[i] != 0) + { + y2hat[i] *= 0.8f; + } + } + } + + if(k == max_pos_pulse && k < bands - p2a_bands && satur != 1 && bwidth != SWB) + { + j = 0; + if(ni_gain[k] < 0.01f) + { + fac = 0.0f; + } + else + { + fac = max(Ep[k]/ni_gain[k], 1.0f); + } + for (i = band_start[k]; i <= band_end[k]; i++) + { + if (y2hat[i] == 0) + { + rand = own_random (&ni_seed) / 32768.0f; + y2hat[i] += (fac - ((fac-1.0f)*j)/band_width[k])*ni_gain[k] * rand; + } + + j++; + } + } + else + { + for (i = band_start[k]; i <= band_end[k]; i++) + { + if (y2hat[i] == 0) + { + rand = own_random (&ni_seed) / 32768.0f; + y2hat[i] += ni_gain[k] * rand; + } + } + } + } + + mvr2r(env, last_env, ni_end_band); + mvr2r(ni_gain, last_ni_gain, ni_end_band); + *last_max_pos_pulse = max_pos_pulse; + + return; +} + diff --git a/src/libs/libevs/lib_com/hq2_noise_inject_fx.cpp b/src/libs/libevs/lib_com/hq2_noise_inject_fx.cpp deleted file mode 100755 index f8eea57e..00000000 --- a/src/libs/libevs/lib_com/hq2_noise_inject_fx.cpp +++ /dev/null @@ -1,615 +0,0 @@ -/*==================================================================================== - EVS Codec 3GPP TS26.442 Apr 03, 2018. Version 12.11.0 / 13.6.0 / 14.2.0 - ====================================================================================*/ - -#include "options.h" -#include "stl.h" -#include "prot_fx.h" -#include "math_op.h" -#include "math_32.h" -#include "oper_32b.h" -#include "move.h" -#include "count.h" - -/*--------------------------------------------------------------------------* - * hq2_noise_inject() - * - * HQ2 noise injection for WB signals - *--------------------------------------------------------------------------*/ -void hq2_noise_inject_fx( - Word32 L_y2[], - const Word16 band_start[], - const Word16 band_end[], - const Word16 band_width[], - Word32 Ep_fx[], - Word32 Rk_fx[], - const Word16 npulses[], - Word16 ni_seed, - const Word16 bands, - const Word16 ni_start_band, - const Word16 bw_low, - const Word16 bw_high, - const Word32 enerL_fx, - const Word32 enerH_fx, - Word32 last_ni_gain_fx[], - Word16 last_env_fx[], - Word16 *last_max_pos_pulse, - Word16 *p2a_flags, - Word16 p2a_bands, - const Word16 hqswb_clas, - const Word16 bwidth, - const Word32 bwe_br -) -{ - Word32 L_tmp,L_tmp2,L_tmp2x,L_tmp3,L_tmp1; - Word16 exp,exp2,Q_speech; - Word16 pd_fx[BANDS_MAX], rand_fx, peak_fx[BANDS_MAX], fac_fx; - - Word16 tmp,tmpx,tmp1,tmp2,tmp3,tmp4,Q_env_fx[BANDS_MAX],Q_Ep_fx[BANDS_MAX]; - - Word16 Qs=SWB_BWE_LR_Qs; - Word32 env_fx[BANDS_MAX]; - Word16 env_fx2[BANDS_MAX]; - Word32 ni_gain_fx[BANDS_MAX]; - Word16 y2hat_fx[L_FRAME48k]; - - Word16 i, j, k, ni_end_band, satur, count[BANDS_MAX], max_pos_pulse, pos; - Word16 sb = bands; - - satur = 0; - move16(); - - FOR(i = 0 ; i < bands; i++) - { - Ep_fx[i] = L_shl(Ep_fx[i], 6);/* Q-6 -> Q0 */ move32(); - } - - tmp = add(band_end[bands-1], 1); - FOR (k = 0; k < tmp; k++) - { - y2hat_fx[k] = (Word16)L_min(L_max(L_shr(L_y2[k],Qs),-32768),32767); - move16(); /* Extract_l or something else is missing here */ - } - - test(); - test(); - test(); - test(); - IF( (sub(hqswb_clas,HQ_HARMONIC) ==0 || sub(hqswb_clas,HQ_NORMAL) ==0 ) && (L_sub(bwe_br,HQ_16k40) ==0 || L_sub(bwe_br,HQ_13k20) ==0 ) && sub(bwidth,SWB) ==0 ) - { - sb = 17; - move16(); - if( L_sub(bwe_br,HQ_16k40) == 0 ) - { - sb = 19; - move16(); - } - } - - /* calculate the envelopes/ the decoded peak coeff./number of the decoded coeff./ the last subbands of the bit-allocated/saturation of bit-allocation */ - ni_end_band = bands; - max_pos_pulse = bands; - FOR (k = ni_start_band; k < ni_end_band; k++) - { - tmp = div_s(1, band_width[k]); /*Q15 */ - L_tmp = Mult_32_16(Rk_fx[k],tmp);/*Q(16+15-15=16) */ - pd_fx[k] = extract_h(L_shl(L_tmp,10)); /*16+10-16 =Q10 */ - - L_tmp2 = L_add(0,Ep_fx[k]);/*Q0 */ - L_tmp = L_max(1, L_tmp2); - exp = norm_l(L_tmp); - tmp = extract_h(L_shl(L_tmp, exp)); - - L_tmp3 = L_add(0,(Word32)band_width[k]); - exp2 = norm_l(L_tmp3); - tmp2 = extract_h(L_shl(L_tmp3, exp2)); - - exp2 = sub(exp, exp2); /* Denormalize and substract */ - - tmp3 = sub(tmp2, tmp); - if (tmp3 > 0) - { - tmp2 = shr(tmp2, 1); - } - if (tmp3 > 0) - { - exp2 = add(exp2, 1); - } - tmp = div_s(tmp2, tmp); - L_tmp = L_deposit_h(tmp); - L_tmp = Isqrt_lc(L_tmp, &exp2); - env_fx[k] = L_tmp; - move32();/*Q(31-exp2) move32(); */ - Q_env_fx[k] = sub(31,exp2); - move16(); - tmp = sub(17,Q_env_fx[k]); - env_fx2[k] = extract_h(L_shl(env_fx[k],tmp));/*Q1 */ - peak_fx[k] = 0; - move16(); - count[k] = 0; - move16(); - - IF(npulses[k] != 0) - { - FOR (i = band_start[k]; i <= band_end[k]; i++) - { - L_tmp =L_mult0(y2hat_fx[i],y2hat_fx[i]); /*0 */ - Ep_fx[k] =L_sub(Ep_fx[k],L_tmp); - move32();/*0 */ - IF(sub(abs_s(y2hat_fx[i]),peak_fx[k]) > 0) - { - peak_fx[k] = abs_s(y2hat_fx[i]); - move16();/*0 */ - } - - IF(y2hat_fx[i] != 0) - { - count[k] = add(count[k],1); - move16(); - } - } - - max_pos_pulse = k; - L_tmp2 = L_add(0,Ep_fx[k]); - L_tmp = L_max(1, L_tmp2); - exp = norm_l(L_tmp); - tmp = extract_h(L_shl(L_tmp, exp)); - - L_tmp3 = (Word32)band_width[k]; - exp2 = norm_l(L_tmp3); - tmp2 = extract_h(L_shl(L_tmp3, exp2)); - - exp2 = sub(exp, exp2); /* Denormalize and substract */ - - tmp3 = sub(tmp2, tmp); - if (tmp3 > 0) - { - tmp2 = shr(tmp2, 1); - } - if (tmp3 > 0) - { - exp2 = add(exp2, 1); - } - tmp = div_s(tmp2, tmp); - L_tmp = L_deposit_h(tmp); - L_tmp = Isqrt_lc(L_tmp, &exp2); - Ep_fx[k] = L_tmp; - move32();/*Q(31-exp2) */ - Q_Ep_fx[k] = sub(31,exp2); - move16(); - } - ELSE - { - Ep_fx[k] = env_fx[k]; - move32();/*Q(Q_env_fx[k]) */ - Q_Ep_fx[k] = Q_env_fx[k]; - move16();/*31-exp2 */ - } - } - - FOR(k = ni_start_band; k < ni_end_band; k++) - { - /* calculate the noise gain */ - satur =0; - move16(); - if(sub(pd_fx[k],819)>= 0) - { - satur =1; - move16(); - } - - test(); - IF (satur == 0 && Ep_fx[k] > 0) - { - IF(npulses[k] != 0) - { - IF( sub(bwidth,SWB) ==0) - { - IF(sub(hqswb_clas,HQ_TRANSIENT) !=0 ) - { - IF(peak_fx[k]!=0) - { - Q_speech = norm_s(peak_fx[k]); - tmp = shl(peak_fx[k],Q_speech);/*Q(Q_speech) */ - tmp = div_s(16384,tmp);/*Q(15+14-Q_speech) */ - } - ELSE - { - tmp = 0x7fff; - move16(); - Q_speech = 0; - move16(); - } - L_tmp2x = Mult_32_16(Ep_fx[k],tmp);/* Q(Q_Ep_fx[k]+29-Q_speech-15 = Q_Ep_fx[k]-Q_speech+14) */ - tmp = sub(Q_Ep_fx[k],Q_speech); - tmpx = add(tmp,1); - tmp2 = extract_l(L_shr(L_tmp2x,s_min(tmpx, 31)));/*Q13 Ep[k]/peak[k] */ - - IF(sub(hqswb_clas,HQ_HARMONIC) == 0 ) - { - tmp = sub(1536,pd_fx[k]); /*Q10 */ - tmp3 = shl(tmp,4); /*Q14 */ - L_tmp = Mult_32_16(env_fx[k],tmp3);/*Q(Q_env_fx[k]+14-15 = Q_env_fx[k]-1) */ - L_tmp = Mult_32_16(L_tmp,6144);/*Q(Q_env_fx[k]-1+10-15 = Q_env_fx[k]-6) */ - - IF(peak_fx[k]!=0) - { - Q_speech = norm_s(peak_fx[k]); - tmp = shl(peak_fx[k],Q_speech);/*Q(Q_speech) */ - tmp = div_s(16384,tmp);/*Q(15+14-Q_speech) */ - } - ELSE - { - tmp = 0x7fff; - move16(); - Q_speech = 0; - move16(); - } - - L_tmp2 = Mult_32_16(Ep_fx[k],tmp);/* Q(Q_Ep_fx[k]+29-Q_speech-15=Q_Ep_fx[k]-Q_speech+14) */ - L_tmp3 = Mult_32_16(L_tmp,tmp);/* Q(Q_env_fx[k]-6+29-Q_speech-15=Q_env_fx[k]-Q_speech+8) */ - L_tmp = Mult_32_32(L_tmp2,L_tmp3); /*Q(Q_Ep_fx[k]-Q_speech+14+Q_env_fx[k]-Q_speech+8-31=Q_Ep_fx[k]+Q_env_fx[k]-2*Q_speech-9) */ - - tmp = add(Q_Ep_fx[k],Q_env_fx[k]); - tmp = sub(tmp,Q_speech); - tmp = sub(tmp,Q_speech); - tmp = sub(37,tmp); - tmp1= extract_h(L_shl(L_tmp,tmp));/*Q12 //6.0f*(1.5f - pd[k])*env[k]*Ep[k]/(peak[k]*peak[k]) */ - - fac_fx = tmp1; - move16();/*Q12 */ - if(sub(k,sb) > 0) - { - fac_fx =mult(24576,tmp2);/*//Q(14+13-15=12) */ - } - } - ELSE - { - IF(sub(k,sb) <= 0) - { - tmp = sub(1536,pd_fx[k]); /*Q10 */ - tmp3 = shl(tmp,4); /*Q14 */ - L_tmp = Mult_32_16(L_tmp2x,tmp3);/*Q(Q_Ep_fx[k]-Q_speech+14+14-15 = Q_Ep_fx[k]-Q_speech+13) */ - L_tmp = Mult_32_16(L_tmp,20480);/*Q(Q_Ep_fx[k]-Q_speech+13+12-15 = Q_Ep_fx[k]-Q_speech+10) */ - fac_fx= extract_h(L_shl(L_tmp,sub(add(18,Q_speech),Q_Ep_fx[k])));/*Q_Ep_fx[k]-Q_speech+10 +18+Q_speech-Q_Ep_fx[k] -16 =12 */ - } - ELSE - { - fac_fx =shl(mult(32767,tmp2),1);/*//Q(13+13-15+1=12) */ - } - } - } - ELSE - { - fac_fx = 4505; - move16();/*Q12 */ - } - } - ELSE - { - tmp = sub(1536,pd_fx[k]); /*Q10 */ - tmp2 = s_min(1024,tmp); /*q10 */ - tmp2 = shl(tmp2,4); /*Q14 */ - L_tmp = Mult_32_16(env_fx[k],tmp2);/*Q(Q_env_fx[k]+14-15 = Q_env_fx[k]-1) */ - L_tmp = Mult_32_16(L_tmp,20480);/*Q(Q_env_fx[k]-1+10-15 = Q_env_fx[k]-6) */ - - IF(peak_fx[k]!=0) - { - Q_speech = norm_s(peak_fx[k]); - tmp = shl(peak_fx[k],Q_speech);/*Q(Q_speech) */ - tmp = div_s(16384,tmp);/*Q(15+14-Q_speech) */ - } - ELSE - { - tmp = 0x7fff; - move16(); - Q_speech = 0; - move16(); - } - - L_tmp2 = Mult_32_16(Ep_fx[k],tmp);/* Q(Q_Ep_fx[k]+29-Q_speech-15=Q_Ep_fx[k]-Q_speech+14) */ - L_tmp3 = Mult_32_16(L_tmp,tmp);/* Q(Q_env_fx[k]-6+29-Q_speech-15=Q_env_fx[k]-Q_speech+8) */ - L_tmp = Mult_32_32(L_tmp2,L_tmp3); /*Q(Q_Ep_fx[k]-Q_speech+14+Q_env_fx[k]-Q_speech+8-31=Q_Ep_fx[k]+Q_env_fx[k]-2*Q_speech-9) */ - - tmp = add(Q_Ep_fx[k],Q_env_fx[k]); - tmp = sub(tmp,Q_speech); - tmp = sub(tmp,Q_speech); - tmp = sub(37,tmp); - - fac_fx = extract_h(L_shl(L_tmp,tmp));/*Q12 */ - - test(); - IF(sub(k,1) > 0 && sub(k,sub(ni_end_band,1)) < 0) - { - IF(env_fx2[k]!=0) - { - Q_speech = norm_s(env_fx2[k]); - tmp = shl(env_fx2[k],Q_speech);/*Q(Q_speech+1) */ - tmp = div_s(16384,tmp);/*Q(15+14-Q_speech-1=28-Q_speech) */ - Q_speech = sub(28,Q_speech); - } - ELSE - { - tmp =0x7fff; - move16(); - Q_speech = 0; - move16(); - } - tmp1 = mult(env_fx2[add(k,1)],16384);/*Q(1+15-15=1) Q1 */ - tmp2 = sub(env_fx2[k],tmp1); - tmp1 = mult(env_fx2[k],16384);/*Q(1+15-15=1) Q1 */ - tmp3 = sub(tmp1,env_fx2[sub(k,1)]); - tmp1 = mult(peak_fx[k],16384);/*Q(0+15-15=0) Q0 */ - tmp4 = sub(tmp1,shr(env_fx2[k],1)); - test(); - test(); - test(); - IF(count[add(k,1)] == 0 && tmp2 > 0 && tmp3 < 0) - { - L_tmp = L_mult(env_fx2[add(k,1)],tmp);/* Q(1+Q_speech+1 = Q_speech+2) */ - L_tmp = Mult_32_16(L_tmp,24576); /*Q(Q_speech+2+14-15=Q_speech+1) */ - fac_fx = extract_h(L_shl(L_tmp,sub(27,Q_speech)));/*Q12 */ - } - ELSE IF(count[sub(k,1)] == 0 && tmp4 > 0) - { - L_tmp = L_mult(env_fx2[sub(k,1)],tmp); /* Q(1+Q_speech+1 = Q_speech+2) */ - fac_fx = extract_h(L_shl(L_tmp,sub(26,Q_speech)));/*Q12 */ - } - } - - test(); - IF(sub(k,sub(ni_end_band,p2a_bands)) >= 0 && sub(bwidth, WB) == 0) - { - L_tmp = Mult_32_16(enerH_fx, bw_low); - L_tmp2= Mult_32_16(enerL_fx, bw_high); - L_tmp = L_sub(L_tmp,L_tmp2); - tmp1 = mult(peak_fx[k],16384);/*Q(0+15-15=0) Q0 */ - tmp4 = sub(tmp1,shr(env_fx2[k],1)); - test(); - IF(L_tmp > 0 && tmp4 < 0) - { - IF(peak_fx[k]!=0) - { - Q_speech = norm_s(peak_fx[k]); - tmp = shl(peak_fx[k],Q_speech);/*Q(Q_speech) */ - tmp = div_s(16384,tmp);/*Q(15+14-Q_speech) */ - } - ELSE - { - tmp = 0x7fff; - move16(); - Q_speech = 0; - move16(); - } - L_tmp2 = Mult_32_16(Ep_fx[k],tmp);/* Q(Q_Ep_fx[k]+29-Q_speech-15 = Q_Ep_fx[k]-Q_speech+14) */ - tmp = sub(Q_Ep_fx[k],Q_speech); - tmp = add(tmp,1); - tmp = extract_l(L_shr(L_tmp2,tmp));/*Q13 */ - tmp = sub(16384,tmp);/*Q13 */ - fac_fx = extract_h(L_shl(L_mult(fac_fx,tmp),2));/*Q12*/ - } - - IF(p2a_flags[k] == 0) - { - L_tmp2 = Mult_32_16(Ep_fx[k],fac_fx);/*Q(Q_Ep_fx[k]+12-15 = Q_Ep_fx[k]-3) */ - Q_speech = norm_l(L_tmp2); - tmp = extract_h(L_shl(L_tmp2,Q_speech));/*Q(Q_Ep_fx[k]-3+Q_speech-16 = Q_Ep_fx[k]+Q_speech-19) */ - IF(tmp != 0) - { - tmp = div_s(16384,tmp);/*Q(15+14-Q_Ep_fx[k]-Q_speech+19 = 48-Q_Ep_fx[k]-Q_speech) */ - L_tmp2 = Mult_32_16(env_fx[k],tmp);/*Q(Q_env_fx[k]+48-Q_Ep_fx[k]-Q_speech-15 = Q_env_fx[k]-Q_Ep_fx[k]-Q_speech+33) */ - L_tmp2 = Mult_32_16(L_tmp2,20480);/*Q(Q_env_fx[k]-Q_Ep_fx[k]-Q_speech+33+14-15 = Q_env_fx[k]-Q_Ep_fx[k]-Q_speech+32) */ - tmp = sub(Q_env_fx[k],Q_Ep_fx[k]); - tmp = sub(tmp,Q_speech); - tmp = add(tmp,25); - L_tmp = L_shr(L_tmp2,tmp);/*Q7 */ - tmp = extract_l(L_min(L_tmp,192));/* */ - fac_fx = extract_h(L_shl(L_mult(fac_fx,tmp),8));/*Q12 */ - } - ELSE - { - tmp = 0x7fff;/*Q0 */ - L_tmp2 = Mult_32_16(env_fx[k],tmp);/*Q(Q_env_fx[k]+0-15 = Q_env_fx[k]-15) */ - L_tmp2 = Mult_32_16(L_tmp2,20480);/*Q(Q_env_fx[k]-15+14-15 = Q_env_fx[k]-16) */ - tmp = sub(Q_env_fx[k],23); - L_tmp = L_shr(L_tmp2,tmp);/*Q7 */ - tmp = extract_l((L_min(L_tmp,192)));/* */ - fac_fx = extract_h(L_shl(L_mult(fac_fx,tmp),8));/*Q12 */ - } - } - } - } - } - ELSE - { - fac_fx = 4505; - move16(); - test(); - if( sub(hqswb_clas,HQ_HARMONIC) == 0 && sub(bwidth,SWB) == 0 ) - { - fac_fx = 3277; - move16(); - } - } - - L_tmp = Mult_32_16(Ep_fx[k],fac_fx);/*Q(Q_Ep_fx[k]+12-15 = Q_Ep_fx[k]-3) */ - ni_gain_fx[k] = L_shr(L_tmp,sub(Q_Ep_fx[k],20)); - move32();/*Q17 */ - } - ELSE - { - ni_gain_fx[k] = L_deposit_l(0); - } - - /* smooth the noise gain between the current frame and the previous frame */ - pos = s_max(max_pos_pulse, *last_max_pos_pulse); - move16(); - if( sub(bwidth,SWB) == 0 ) - { - pos = sub(ni_end_band,1); - move16(); - } - - IF(sub(k,pos) <=0 ) - { - test(); - IF(k > 0 && add(sub(k,ni_end_band),1) < 0) - { - tmp1 = mult(last_env_fx[k],16384);/*Q(1+15-15=1) Q1 */ - tmp2 = sub(env_fx2[k],tmp1);/*>0 */ - tmp1 = mult(env_fx2[k],16384);/*Q(1+15-15=1) Q1 */ - tmp3 = sub(tmp1,last_env_fx[k]);/*<0 */ - L_tmp = L_add((Word32)env_fx2[k],(Word32)env_fx2[sub(k,1)]); - L_tmp = L_add(L_tmp,(Word32)env_fx2[add(k,1)]);/*Q1 */ - L_tmp1 = L_add((Word32)last_env_fx[k],(Word32)last_env_fx[sub(k,1)]); - L_tmp1 = L_add(L_tmp1,(Word32)last_env_fx[add(k,1)]);/*Q1 */ - L_tmp2 = Mult_32_16(L_tmp1,16384);/*Q(1+15-15) Q1 */ - L_tmp2 = L_sub(L_tmp,L_tmp2);/*>0 */ - L_tmp3 = Mult_32_16(L_tmp,16384);/*Q(1+15-15) Q1 */ - L_tmp3 = L_sub(L_tmp3,L_tmp1);/*<0 */ - test(); - test(); - test(); - IF( (tmp2 > 0 && tmp3 < 0) ||(L_tmp2 > 0 && L_tmp3 < 0)) - { - IF( L_sub(ni_gain_fx[k],last_ni_gain_fx[k]) > 0 ) - { - L_tmp = Mult_32_16(ni_gain_fx[k],6554);/*Q(17+15-15 = 17) */ - L_tmp1 = Mult_32_16(last_ni_gain_fx[k],26214);/*Q17 */ - ni_gain_fx[k] = L_add(L_tmp,L_tmp1); - move32(); - } - ELSE - { - L_tmp = Mult_32_16(ni_gain_fx[k],19661);/*Q(17+15-15 = 17) */ - L_tmp1 = Mult_32_16(last_ni_gain_fx[k],13107);/*Q17 */ - ni_gain_fx[k] = L_add(L_tmp,L_tmp1); - move32(); - } - } - } - ELSE IF (add(sub(k,ni_end_band),1) == 0) - { - tmp1 = mult(last_env_fx[k],16384);/*Q(1+15-15=1) Q1 */ - tmp2 = sub(env_fx2[k],tmp1);/*>0 */ - tmp1 = mult(env_fx2[k],16384);/*Q(1+15-15=1) Q1 */ - tmp3 = sub(tmp1,last_env_fx[k]);/*<0 */ - L_tmp = L_add((Word32)env_fx2[k],(Word32)env_fx2[sub(k,1)]);/*Q1 */ - L_tmp1 = L_add((Word32)last_env_fx[k],(Word32)last_env_fx[sub(k,1)]);/*Q1 */ - L_tmp2 = Mult_32_16(L_tmp1,16384);/*Q(1+15-15) Q1 */ - L_tmp2 = L_sub(L_tmp,L_tmp2);/*>0 */ - L_tmp3 = Mult_32_16(L_tmp,16384);/*Q(1+15-15) Q1 */ - L_tmp3 = L_sub(L_tmp3,L_tmp1);/*<0 */ - - test(); - test(); - test(); - IF( (tmp2 > 0 && tmp3 < 0) ||(L_tmp2 > 0 && L_tmp3 < 0)) - { - IF( L_sub(ni_gain_fx[k],last_ni_gain_fx[k]) > 0 ) - { - L_tmp = Mult_32_16(ni_gain_fx[k],6554);/*Q(17+15-15 = 17) */ - L_tmp1 = Mult_32_16(last_ni_gain_fx[k],26214);/*Q17 */ - ni_gain_fx[k] = L_add(L_tmp,L_tmp1); - move32(); - } - ELSE - { - L_tmp = Mult_32_16(ni_gain_fx[k],19661);/*Q(17+15-15 = 17) */ - L_tmp1 = Mult_32_16(last_ni_gain_fx[k],13107);/*Q17 */ - ni_gain_fx[k] = L_add(L_tmp,L_tmp1); - move32(); - } - } - } - } - - /* inject noise into the non-decoded coeffs */ - test(); - test(); - IF(add(sub(k,ni_end_band),p2a_bands) >=0 && p2a_flags[k] == 0 && sub(bwidth,SWB) !=0 ) - { - FOR (i = band_start[k]; i <= band_end[k]; i++) - { - IF (L_y2[i] != 0) - { - L_y2[i] = Mult_32_16(L_y2[i],26215); - move32();/*Q(12+15-15=12) */ - } - } - } - - test(); - test(); - test(); - IF(sub(k,max_pos_pulse) == 0 && add(sub(k,bands),p2a_bands)< 0 && sub(satur,1) != 0 && sub(bwidth,SWB) !=0) - { - j = 0; - Q_speech = norm_l(ni_gain_fx[k]); - tmp = extract_h(L_shl(ni_gain_fx[k],Q_speech));/*Q(Q_speech+1) */ - IF(tmp != 0) - { - tmp = div_s(16384,tmp);/*Q(15+14-Q_speech-1 = 28-Q_speech) */ - L_tmp = Mult_32_16(Ep_fx[k],tmp); /*Q(Q_Ep_fx[k]+28-Q_speech-15 = Q_Ep_fx[k]+13-Q_speech) */ - tmp = sub(Q_Ep_fx[k],Q_speech); - tmp = sub(15,tmp); - tmp = extract_h(L_shl(L_tmp,tmp));/*Q12 */ - } - ELSE - { - tmp = 0x7fff;/*Q0 */ - L_tmp = Mult_32_16(Ep_fx[k],tmp); /*Q(Q_Ep_fx[k]+0-15 = Q_Ep_fx[k]-15) */ - tmp = sub(43,Q_Ep_fx[k]); - tmp = extract_h(L_shl(L_tmp,tmp));/*Q12 */ - } - fac_fx = s_max(tmp,4096);/*Q12 */ - - FOR (i = band_start[k]; i <= band_end[k]; i++) - { - IF (L_y2[i] == 0) - { - rand_fx = Random(&ni_seed); /*Q15 */ - IF(band_width[k] != 0) - { - Q_speech = norm_s(band_width[k]); - tmp = shl(band_width[k],Q_speech);/*Q(Q_speech) */ - tmp = div_s(16384,tmp);/*Q(15+14-Q_speech) */ - } - ELSE - { - tmp = 0x7fff; - Q_speech = 0; - } - tmp1 = sub(fac_fx,4096);/*Q12 */ - L_tmp = L_mult(tmp1,j);/*Q13 */ - L_tmp = Mult_32_16(L_tmp,tmp);/*Q(13+29-Q_speech-15 = 27-Q_speech) */ - tmp = extract_h(L_shl(L_tmp,add(1,Q_speech)));/*Q12 */ - tmp = sub(fac_fx,tmp);/*Q12 */ - L_tmp = Mult_32_16(ni_gain_fx[k],tmp);/*Q(17+12-15=14) */ - L_y2[i] = L_add(L_y2[i],L_shr(Mult_32_16(L_tmp,rand_fx),2)); - move32();/*Q12 */ - } - j=add(j,1); - } - } - ELSE - { - FOR (i = band_start[k]; i <= band_end[k]; i++) - { - IF (L_y2[i] == 0) - { - rand_fx = Random(&ni_seed); /*Q15 */ - L_tmp = Mult_32_16(ni_gain_fx[k],rand_fx);/*Q(17+15-15=17) */ - L_y2[i] = L_add(L_y2[i],L_shr(L_tmp,5)); - move32();/*Q12 */ - } - } - } - } - - Copy(env_fx2,last_env_fx,ni_end_band); - Copy32(ni_gain_fx,last_ni_gain_fx,ni_end_band); - *last_max_pos_pulse = max_pos_pulse; - move16(); - return; -} diff --git a/src/libs/libevs/lib_com/hq_bit_allocation.cpp b/src/libs/libevs/lib_com/hq_bit_allocation.cpp new file mode 100644 index 00000000..c377f00c --- /dev/null +++ b/src/libs/libevs/lib_com/hq_bit_allocation.cpp @@ -0,0 +1,189 @@ +/*==================================================================================== + EVS Codec 3GPP TS26.443 Nov 13, 2018. Version 12.11.0 / 13.7.0 / 14.3.0 / 15.1.0 + ====================================================================================*/ + +#include +#include "options.h" +#include "cnst.h" +#include "prot.h" +#include "rom_com.h" + + +/*--------------------------------------------------------------------------* + * hq_bit_allocation() + * + * Assign bits for HQ fine structure coding with PVQ + *--------------------------------------------------------------------------*/ + +void hq_bit_allocation( + const long core_brate, /* i : Core bit-rate */ + const short length, /* i : Frame length */ + const short hqswb_clas, /* i : HQ class */ + short *num_bits, /* i/o: Remaining bit budget */ + const short *normqlg2, /* i : Quantized norms */ + const short nb_sfm, /* i : Number sub bands to be encoded */ + const short *sfmsize, /* i : Sub band bandwidths */ + float *noise_level, /* o : HVQ noise level */ + short *R, /* o : Bit allocation per sub band */ + short *Rsubband, /* o : Fractional bit allocation (Q3) */ + short *sum, /* o : Sum of allocated shape bits */ + short *core_sfm, /* o : Last coded band in core */ + const short num_env_bands /* i : Number sub bands to be encoded for HQ_SWB_BWE */ +) +{ + short sfm_limit = nb_sfm; + short i; + short idx[NB_SFM]; + short wnorm[NB_SFM]; + short avrg_wnorm; + short E_low; + short E_hb_mean; + short E_max; + short i_max; + + + set_s( R, 0, NB_SFM ); + for( i = 0; i < nb_sfm; i++ ) + { + idx[i] = i; + } + if( hqswb_clas != HQ_TRANSIENT && hqswb_clas != HQ_HVQ && !(length == L_FRAME16k && core_brate == HQ_32k)) + { + /* 'nf_idx' 2-bits index written later */ + *num_bits -= 2; + } + + if ( hqswb_clas == HQ_GEN_SWB || hqswb_clas == HQ_GEN_FB ) + { + if (core_brate == HQ_32k) + { + *num_bits -= HQ_GENERIC_SWB_NBITS2; + } + else + { + *num_bits -= HQ_GENERIC_SWB_NBITS; + } + if (length == L_FRAME48k) + { + *num_bits -= HQ_GENERIC_FB_NBITS; + } + } + + if( (length == L_FRAME48k) && (hqswb_clas != HQ_HARMONIC) && (hqswb_clas != HQ_HVQ) ) + { + map_quant_weight( normqlg2, wnorm, hqswb_clas == HQ_TRANSIENT ); + } + else + { + mvs2s( normqlg2, wnorm, nb_sfm ); + } + + + if( hqswb_clas == HQ_HARMONIC ) + { + /* classification and limit bandwidth for bit allocation */ + sfm_limit -= 2; + limit_band_noise_level_calc( wnorm, &sfm_limit, core_brate, noise_level ); + + /* Detect important band in high frequency region */ + E_low = sum_s(wnorm, SFM_G1); + i_max = 0; + E_max = MIN16B; + E_hb_mean = 0; + for( i = SFM_G1; i < nb_sfm; i++) + { + E_hb_mean += wnorm[i]; + if( wnorm[i] > E_max) + { + E_max = wnorm[i]; + i_max = i; + } + } + E_hb_mean = E_hb_mean >> 4; /* Truncated division by SFM_G1 */ + if ( E_max * 15 < E_low || E_max * 0.67 < E_hb_mean || i_max < sfm_limit ) + { + i_max = 0; + } + + set_s( wnorm + sfm_limit, -20, nb_sfm - sfm_limit ); + if ( i_max > 0) + { + wnorm[i_max] = E_max; + } + + } + + + if( hqswb_clas == HQ_HVQ ) + { + *sum = 0; + } + else if ( hqswb_clas == HQ_GEN_SWB || (hqswb_clas == HQ_TRANSIENT && length == L_FRAME32k && core_brate <= HQ_32k) ) + { + *sum = BitAllocF( wnorm, core_brate, *num_bits, nb_sfm, R, Rsubband, hqswb_clas, num_env_bands ); + } + else if( length == L_FRAME16k && core_brate == HQ_32k ) + { + if( hqswb_clas != HQ_TRANSIENT ) + { + avrg_wnorm = wnorm[10]; + for( i=11; i<18; i++ ) + { + avrg_wnorm += wnorm[i]; + } + + avrg_wnorm /= 8; + for( i=0; i<4; i++ ) + { + if( wnorm[i] < avrg_wnorm ) + { + wnorm[i] = avrg_wnorm; + } + } + + /* Estimate number of bits per band */ + *sum = BitAllocWB( wnorm, *num_bits, nb_sfm, R, Rsubband ); + } + else + { + reordvct(wnorm, nb_sfm, idx); + bitalloc( wnorm, idx, *num_bits, nb_sfm, QBIT_MAX2, R, sfmsize, hqswb_clas ); + bitallocsum( R, nb_sfm, sum, Rsubband, *num_bits, length, sfmsize ); + } + } + else + { + reordvct( wnorm, nb_sfm, idx ); + + /* enlarge the wnorm value so that more bits can be allocated to (sfm_limit/2 ~ sfm_limit) range */ + if( hqswb_clas == HQ_HARMONIC ) + { + for( i=sfm_limit/2; i 0) - { - E_max = wnorm[i]; - move16(); - i_max = i; - move16(); - } - } - E_hb_mean = shr(E_hb_mean, 4); /* Truncated division by SFM_G1 */ - set16_fx( wnorm + sfm_limit, -20, sub(nb_sfm, sfm_limit) ); - IF (L_msu0(L_deposit_l(E_low), E_max, 15) <= 0) - { - IF (L_msu(L_deposit_h(E_hb_mean), E_max, 21955) <= 0) /* 21955 = 0.67 (Q15) */ - { - if (sub(i_max, sfm_limit) >= 0) - { - wnorm[i_max] = E_max; - move16(); - } - } - } - } - test(); - test(); - test(); - test(); - IF( sub(hqswb_clas, HQ_HVQ) == 0 ) - { - *sum = 0; - move16(); - } - ELSE IF ( sub(hqswb_clas, HQ_GEN_SWB) == 0 || (sub(hqswb_clas, HQ_TRANSIENT) == 0 && sub(length, L_FRAME32k) == 0 && L_sub(core_brate, HQ_32k) <= 0) ) - { - *sum = BitAllocF_fx( wnorm, core_brate, *num_bits, nb_sfm, R, Rsubband, hqswb_clas, num_env_bands ); - } - ELSE IF( sub(length, L_FRAME16k) == 0 && L_sub(core_brate, HQ_32k) == 0 ) - { - IF( sub(hqswb_clas, HQ_TRANSIENT) != 0 ) - { - avrg_wnorm = wnorm[10]; - move16(); - FOR( i=11; i<18; i++ ) - { - avrg_wnorm = add(avrg_wnorm, wnorm[i]); - } - - avrg_wnorm = shr(avrg_wnorm, 3); - FOR( i=0; i<4; i++ ) - { - if( sub(wnorm[i], avrg_wnorm) < 0 ) - { - wnorm[i] = avrg_wnorm; - move16(); - } - } - - /* Estimate number of bits per band */ - *sum = BitAllocWB_fx( wnorm, *num_bits, nb_sfm, R, Rsubband ); - } - ELSE - { - reordvct_fx(wnorm, nb_sfm, idx); - bitalloc_fx( wnorm, idx, *num_bits, nb_sfm, QBIT_MAX2, R, sfmsize, hqswb_clas ); - bitallocsum_fx( R, nb_sfm, sum, Rsubband, *num_bits, length, sfmsize ); - } - } - ELSE - { - reordvct_fx(wnorm, nb_sfm, idx); - - /* enlarge the wnorm value so that more bits can be allocated to (sfm_limit/2 ~ sfm_limit) range */ - IF( sub(hqswb_clas, HQ_HARMONIC) == 0 ) - { - tmp = shr(sfm_limit,1); - tmp2 = sub(tmp,1); - FOR( i=tmp; i +#include +#include "options.h" +#include "cnst.h" +#include "rom_com.h" +#include "prot.h" + + +/*--------------------------------------------------------------------------* + * hq_configure() + * + * Configuration routine for HQ mode + *--------------------------------------------------------------------------*/ + +void hq_configure( + const short length, /* i : Frame length */ + const short hqswb_clas, /* i : HQ SWB class */ + const long core_brate, /* i : Codec bitrate */ + short *num_sfm, /* o : Total number of subbands */ + short *nb_sfm, /* o : Total number of coded bands */ + short *start_norm, /* o : First norm to be SDE encoded */ + short *num_env_bands, /* o : Number coded envelope bands */ + short *numnrmibits, /* o : Number of bits in fall-back norm encoding */ + short *hq_generic_offset, /* o : Freq offset for HQ GENERIC */ + short const **sfmsize, /* o : Subband bandwidths */ + short const **sfm_start, /* o : Subband start coefficients */ + short const **sfm_end /* o : Subband end coefficients */ +) +{ + *start_norm = 0; + + if( length == L_FRAME48k ) + { + if ( hqswb_clas == HQ_GEN_FB ) + { + *num_sfm = NB_SFM; + *sfmsize = band_len_HQ; + *sfm_start = band_start_HQ; + *sfm_end = band_end_HQ; + + if( core_brate == HQ_32k ) + { + *hq_generic_offset = HQ_GENERIC_FOFFSET_32K; + } + else if ( core_brate == HQ_16k40 || core_brate == HQ_24k40 ) + { + *hq_generic_offset = HQ_GENERIC_FOFFSET_24K4; + } + + /* setting start frequency of FD BWE */ + if( core_brate == HQ_32k ) + { + *num_env_bands = SFM_N_STA_10k; + } + else if( core_brate == HQ_16k40 || core_brate == HQ_24k40 ) + { + *num_env_bands = SFM_N_STA_8k; + } + + *nb_sfm = *num_sfm; + } + else + { + if(hqswb_clas == HQ_HARMONIC) + { + *num_sfm = SFM_N_HARM_FB; + *nb_sfm = SFM_N_HARM_FB; + *num_env_bands = SFM_N_HARM_FB; + + *sfmsize = band_len_harm; + *sfm_start = band_start_harm; + *sfm_end = band_end_harm; + } + else if(hqswb_clas == HQ_HVQ) + { + if( core_brate == HQ_24k40 ) + { + *num_sfm = SFM_N_HARM_FB; + *nb_sfm = HVQ_THRES_SFM_24k; + *num_env_bands = *num_sfm - *nb_sfm; + + *sfmsize = band_len_harm; + *sfm_start = band_start_harm; + *sfm_end = band_end_harm; + *start_norm = HVQ_THRES_SFM_24k; + } + else + { + *num_sfm = SFM_N_HARM_FB; + *nb_sfm = HVQ_THRES_SFM_32k; + *num_env_bands = *num_sfm - *nb_sfm; + + *sfmsize = band_len_harm; + *sfm_start = band_start_harm; + *start_norm = HVQ_THRES_SFM_32k; + *sfm_end = band_end_harm; + } + } + else + { + *num_sfm = NB_SFM; + *nb_sfm = *num_sfm; + *num_env_bands = NB_SFM; + + *sfmsize = band_len_HQ; + *sfm_start = band_start_HQ; + *sfm_end = band_end_HQ; + } + } + } + else if( length == L_FRAME32k ) + { + if( hqswb_clas == HQ_HARMONIC ) + { + *num_sfm = SFM_N_HARM; + *nb_sfm = SFM_N_HARM; + *num_env_bands = SFM_N_HARM; + + *sfmsize = band_len_harm; + *sfm_start = band_start_harm; + *sfm_end = band_end_harm; + } + else if ( hqswb_clas == HQ_HVQ ) + { + if( core_brate == HQ_24k40 ) + { + *num_sfm = SFM_N_HARM; + *nb_sfm = HVQ_THRES_SFM_24k; + *num_env_bands = *num_sfm - *nb_sfm; + + *sfmsize = band_len_harm; + *sfm_start = band_start_harm; + *sfm_end = band_end_harm; + *start_norm = HVQ_THRES_SFM_24k; + } + else + { + *num_sfm = SFM_N_HARM; + *nb_sfm = HVQ_THRES_SFM_32k; + *num_env_bands = *num_sfm - *nb_sfm; + + *sfmsize = band_len_harm; + *sfm_start = band_start_harm; + *start_norm = HVQ_THRES_SFM_32k; + *sfm_end = band_end_harm; + } + } + else if ( hqswb_clas == HQ_GEN_SWB ) + { + *num_sfm = SFM_N_SWB; + *sfmsize = band_len_HQ; + *sfm_start = band_start_HQ; + *sfm_end = band_end_HQ; + + if( core_brate == HQ_32k ) + { + *hq_generic_offset = HQ_GENERIC_FOFFSET_32K; + } + else if ( core_brate == HQ_24k40 ) + { + *hq_generic_offset = HQ_GENERIC_FOFFSET_24K4; + } + + /* setting start frequency of FD BWE */ + if( core_brate == HQ_32k ) + { + *num_env_bands = SFM_N_STA_10k; + } + else if( core_brate == HQ_24k40 ) + { + *num_env_bands = SFM_N_STA_8k; + } + + *nb_sfm = *num_sfm; + } + else + { + /* HQ_NORMAL and HQ_TRANSIENT */ + *num_sfm = SFM_N_SWB; + *nb_sfm = *num_sfm; + *num_env_bands = SFM_N_SWB; + + *sfmsize = band_len_HQ; + *sfm_start = band_start_HQ; + *sfm_end = band_end_HQ; + } + } + else + { + *num_sfm = SFM_N_WB; + *nb_sfm = *num_sfm; + *num_env_bands = SFM_N_WB; + + *sfmsize = band_len_wb; + *sfm_start = band_start_wb; + *sfm_end = band_end_wb; + } + + *numnrmibits = (*num_env_bands - 1) * NORMI_BITS; + + return; +} diff --git a/src/libs/libevs/lib_com/hq_conf_fx.cpp b/src/libs/libevs/lib_com/hq_conf_fx.cpp deleted file mode 100755 index e0036b32..00000000 --- a/src/libs/libevs/lib_com/hq_conf_fx.cpp +++ /dev/null @@ -1,279 +0,0 @@ -/*==================================================================================== - EVS Codec 3GPP TS26.442 Apr 03, 2018. Version 12.11.0 / 13.6.0 / 14.2.0 - ====================================================================================*/ - -#include -#include "options.h" -#include "cnst_fx.h" /* Audio core constants */ -#include "rom_com_fx.h" /* Static table prototypes */ -#include "prot_fx.h" /* Function prototypes */ -#include "stl.h" /* required for wmc_tool */ - -/*--------------------------------------------------------------------------* - * hq_configure() - * - * Configuration routine for HQ mode - *--------------------------------------------------------------------------*/ - -void hq_configure_fx( - const Word16 length, /* i : Frame length Q0 */ - const Word16 hqswb_clas, /* i : HQ SWB class Q0 */ - const Word32 core_brate, /* i : Codec bitrate Q0 */ - Word16 *num_sfm, /* o : Total number of subbands Q0 */ - Word16 *nb_sfm, /* o : Total number of coded bands Q0 */ - Word16 *start_norm, /* o : First norm to be SDE encoded Q0 */ - Word16 *num_env_bands, /* o : Number coded envelope bands Q0 */ - Word16 *numnrmibits, /* o : Number of bits in fall-back norm encoding Q0 */ - Word16 *hq_generic_offset, /* o : Freq offset for HQ GENERIC Q0 */ - Word16 const **sfmsize, /* o : Subband bandwidths Q0 */ - Word16 const **sfm_start, /* o : Subband start coefficients Q0 */ - Word16 const **sfm_end /* o : Subband end coefficients Q0 */ -) -{ - *start_norm = 0; - move16(); - - IF ( sub(length, L_FRAME48k) == 0 ) - { - IF ( sub(hqswb_clas, HQ_GEN_FB) == 0 ) - { - *num_sfm = NB_SFM; - move16(); - *sfmsize = band_len_HQ; - move16(); - *sfm_start = band_start_HQ; - move16(); - *sfm_end = band_end_HQ; - move16(); - - test(); - IF ( L_sub(core_brate, HQ_32k) == 0 ) - { - *hq_generic_offset = HQ_GENERIC_FOFFSET_32K; - move16(); - } - ELSE IF ( L_sub(core_brate, HQ_16k40) == 0 || L_sub(core_brate, HQ_24k40) == 0 ) - { - *hq_generic_offset = HQ_GENERIC_FOFFSET_24K4; - move16(); - } - - /* setting start frequency of FD BWE */ - test(); - IF ( L_sub(core_brate, HQ_32k) == 0 ) - { - *num_env_bands = SFM_N_STA_10k; - move16(); - } - ELSE IF ( L_sub(core_brate, HQ_16k40) == 0 || L_sub(core_brate, HQ_24k40) == 0 ) - { - *num_env_bands = SFM_N_STA_8k; - move16(); - } - *nb_sfm = *num_sfm; - move16(); - } - ELSE - { - IF(sub(hqswb_clas, HQ_HARMONIC) == 0) - { - *num_sfm = SFM_N_HARM_FB; - move16(); - *nb_sfm = SFM_N_HARM_FB; - move16(); - *num_env_bands = SFM_N_HARM_FB; - move16(); - - *sfmsize = band_len_harm; - move16(); - *sfm_start = band_start_harm; - move16(); - *sfm_end = band_end_harm; - move16(); - } - ELSE IF ( sub(hqswb_clas, HQ_HVQ) == 0 ) - { - IF ( L_sub(core_brate, HQ_24k40) == 0 ) - { - *num_sfm = SFM_N_HARM_FB; - move16(); - *nb_sfm = HVQ_THRES_SFM_24k; - move16(); - *num_env_bands = sub(*num_sfm, *nb_sfm); - - *sfmsize = band_len_harm; - move16(); - *sfm_start = band_start_harm; - move16(); - *sfm_end = band_end_harm; - move16(); - *start_norm = HVQ_THRES_SFM_24k; - move16(); - } - ELSE - { - *num_sfm = SFM_N_HARM_FB; - move16(); - *nb_sfm = HVQ_THRES_SFM_32k; - move16(); - *num_env_bands = sub(*num_sfm, *nb_sfm); - - *sfmsize = band_len_harm; - move16(); - *sfm_start = band_start_harm; - move16(); - *start_norm = HVQ_THRES_SFM_32k; - move16(); - *sfm_end = band_end_harm; - move16(); - } - } - ELSE - { - *num_sfm = NB_SFM; - move16(); - *nb_sfm = *num_sfm; - move16(); - *num_env_bands = NB_SFM; - move16(); - - *sfmsize = band_len_HQ; - move16(); - *sfm_start = band_start_HQ; - move16(); - *sfm_end = band_end_HQ; - move16(); - } - } - } - ELSE IF( sub(length, L_FRAME32k) == 0 ) - { - IF ( sub(hqswb_clas, HQ_HARMONIC) == 0 ) - { - *num_sfm = SFM_N_HARM; - move16(); - *nb_sfm = SFM_N_HARM; - move16(); - *num_env_bands = SFM_N_HARM; - move16(); - - *sfmsize = band_len_harm; - move16(); - *sfm_start = band_start_harm; - move16(); - *sfm_end = band_end_harm; - move16(); - } - ELSE IF ( sub(hqswb_clas, HQ_HVQ) == 0 ) - { - IF ( L_sub(core_brate, HQ_24k40) == 0 ) - { - *num_sfm = SFM_N_HARM; - move16(); - *nb_sfm = HVQ_THRES_SFM_24k; - move16(); - *num_env_bands = sub(*num_sfm, *nb_sfm); - - *sfmsize = band_len_harm; - move16(); - *sfm_start = band_start_harm; - move16(); - *sfm_end = band_end_harm; - move16(); - *start_norm = HVQ_THRES_SFM_24k; - move16(); - } - ELSE - { - *num_sfm = SFM_N_HARM; - move16(); - *nb_sfm = HVQ_THRES_SFM_32k; - move16(); - *num_env_bands = sub(*num_sfm, *nb_sfm); - - *sfmsize = band_len_harm; - move16(); - *sfm_start = band_start_harm; - move16(); - *start_norm = HVQ_THRES_SFM_32k; - move16(); - *sfm_end = band_end_harm; - move16(); - } - } - ELSE IF ( sub(hqswb_clas, HQ_GEN_SWB) == 0 ) - { - *num_sfm = SFM_N_SWB; - move16(); - *sfmsize = band_len_HQ; - move16(); - *sfm_start = band_start_HQ; - move16(); - *sfm_end = band_end_HQ; - move16(); - - IF ( L_sub(core_brate, HQ_32k) == 0 ) - { - *hq_generic_offset = HQ_GENERIC_FOFFSET_32K; - move16(); - } - ELSE if ( L_sub(core_brate, HQ_24k40) == 0 ) - { - *hq_generic_offset = HQ_GENERIC_FOFFSET_24K4; - move16(); - } - - /* setting start frequency of HQ Generic */ - IF ( L_sub(core_brate, HQ_32k) == 0 ) - { - *num_env_bands = SFM_N_STA_10k; - move16(); - } - ELSE if( L_sub(core_brate, HQ_24k40) == 0 ) - { - *num_env_bands = SFM_N_STA_8k; - move16(); - } - - *nb_sfm = *num_sfm; - move16(); - } - ELSE - { - /* HQ_NORMAL and HQ_TRANSIENT */ - *num_sfm = SFM_N_SWB; - move16(); - *nb_sfm = *num_sfm; - move16(); - *num_env_bands = SFM_N_SWB; - move16(); - - *sfmsize = band_len_HQ; - move16(); - *sfm_start = band_start_HQ; - move16(); - *sfm_end = band_end_HQ; - move16(); - } - } - ELSE - { - *num_sfm = SFM_N_WB; - move16(); - *nb_sfm = *num_sfm; - move16(); - *num_env_bands = SFM_N_WB; - move16(); - - *sfmsize = band_len_wb; - move16(); - *sfm_start = band_start_wb; - move16(); - *sfm_end = band_end_wb; - move16(); - } - - *numnrmibits = extract_l(L_mult0(sub(*num_env_bands, 1), NORMI_BITS)); - - return; -} diff --git a/src/libs/libevs/lib_com/hq_tools.cpp b/src/libs/libevs/lib_com/hq_tools.cpp new file mode 100644 index 00000000..9e8cf301 --- /dev/null +++ b/src/libs/libevs/lib_com/hq_tools.cpp @@ -0,0 +1,1731 @@ +/*==================================================================================== + EVS Codec 3GPP TS26.443 Nov 13, 2018. Version 12.11.0 / 13.7.0 / 14.3.0 / 15.1.0 + ====================================================================================*/ + +#include +#include +#include "options.h" +#include "prot.h" +#include "rom_com.h" + +/*--------------------------------------------------------------------------* + * Local functions + *--------------------------------------------------------------------------*/ + +static void overlap_hq_bwe( const float *hq_swb_overlap_buf, float *coeff_out1, const short n_swb_overlap_offset, const short n_swb_overlap, + const short *R, const short num_env_bands, const short num_sfm, const short *sfm_end ); + +/*--------------------------------------------------------------------------* + * hq_swb_harmonic_calc_norm_envelop() + * + * Calculate normalization envelop + *--------------------------------------------------------------------------*/ + +void hq_swb_harmonic_calc_norm_envelop( + float *SWB_signal, /* i : input signal */ + float *envelope, /* o : output envelope */ + int L_swb_norm, /* i : length of normaliztion */ + int SWB_flength /* i : length of input signal */ +) +{ + int lookback; + int env_index; + int n_freq; + int n_lag_now; + int n_lag; + int i; + + lookback = L_swb_norm/2; + env_index = 0; + for (n_freq = 0; n_freq < lookback; n_freq++) + { + n_lag_now = lookback+n_freq; + + /* Apply MA filter */ + envelope[env_index] = EPSILON; + for (n_lag=0; n_lag 0.0f) + { + CodeBook_mod[cb_size] = 1.0f; + E_cb_vec++; + } + else if (coeff[j] < 0.0f) + { + CodeBook_mod[cb_size] = -1.0f; + E_cb_vec++; + } + else + { + CodeBook_mod[cb_size] = 0.0f; + } + cb_size++; + } + + if (E_cb_vec < 2) + { + cb_size -= 8; + } + } + } + else + { + for (j = sfm_start[sfm]; j < sfm_end[sfm]; j++) + { + CodeBook[cb_size] = coeff[j]; + cb_size++; + } + } + } + } + + if (flag_32K_env_ho) + { + for (j = 0; j < cb_size; j++) + { + if (CodeBook_mod[j] != 0.0f) + { + /* Densify codebook */ + CodeBook[j] = sign(CodeBook_mod[j])*(CodeBook_mod[j]*CodeBook_mod[j] + CodeBook_mod[cb_size-j-1]*CodeBook_mod[cb_size-j-1]); + } + else + { + CodeBook[j] = CodeBook_mod[cb_size-j-1]; + } + } + } + + return cb_size; +} + +/*--------------------------------------------------------------------------* + * find_last_band() + * + * Find the last band which has bits allocated + *--------------------------------------------------------------------------*/ + +short find_last_band( /* o : index of last band */ + const short *bitalloc, /* i : bit allocation */ + const short nb_sfm /* i : number of possibly coded bands */ +) +{ + short sfm, core_sfm; + + core_sfm = nb_sfm-1; + + for (sfm = nb_sfm-1; sfm >= 0; sfm--) + { + if ( bitalloc[sfm] != 0 ) + { + core_sfm = sfm; + break; + } + } + + return core_sfm; +} + +/*--------------------------------------------------------------------------* + * apply_noisefill_HQ() + * + * Inject noise in non-coded bands + *--------------------------------------------------------------------------*/ + +void apply_noisefill_HQ( + const short *R, /* i : bit allocation */ + const short length, /* i : input frame length */ + const short flag_32K_env_ho,/* i : envelope stability hangover flag*/ + const long core_brate, /* i : core bit rate */ + const short last_sfm, /* i : last coded subband */ + const float *CodeBook, /* i : Noise-fill codebook */ + const float *CodeBook_mod, /* i : Densified noise-fill codebook */ + const short cb_size, /* i : Codebook length */ + const short *sfm_start, /* i : Subband start coefficient */ + const short *sfm_end, /* i : Subband end coefficient */ + const short *sfmsize, /* i : Subband band width */ + float *coeff /* i/o: coded/noisefilled spectrum */ +) +{ + short sfm; + short cb_pos; + float E_cb_vec; + float E_corr; + float cb_buff[64]; + short i,j; + + if( length >= L_FRAME32k || core_brate > HQ_32k || core_brate < HQ_24k40 ) + { + /* Read from codebook */ + cb_pos = 0; + + for (sfm = 0; sfm <= last_sfm; sfm++) + { + if (R[sfm] == 0) + { + if (flag_32K_env_ho) + { + E_cb_vec = 0.0f; + if (sfm < 20) + { + for (i = 0; i < sfmsize[sfm]; i++) + { + cb_buff[i] = CodeBook_mod[cb_pos]; + E_cb_vec += cb_buff[i]*cb_buff[i]; + cb_pos++; + if(cb_pos >= cb_size) + { + cb_pos = 0; + } + } + } + else + { + for (i = 0; i < sfmsize[sfm]; i++) + { + cb_buff[i] = CodeBook[cb_pos]; + E_cb_vec += cb_buff[i]*cb_buff[i]; + cb_pos++; + if(cb_pos >= cb_size) + { + cb_pos = 0; + } + } + } + + E_corr = E_cb_vec / ((float) sfmsize[sfm]); + E_corr = 1.0f / (float)sqrt(E_corr); + + for (j = sfm_start[sfm]; j < sfm_end[sfm]; j++) + { + coeff[j] = cb_buff[j - sfm_start[sfm]] * E_corr; + } + } + else + { + for (j = sfm_start[sfm]; j < sfm_end[sfm]; j++) + { + coeff[j] = CodeBook[cb_pos]; + cb_pos++; + cb_pos = (cb_pos>=cb_size) ? 0 : cb_pos; + } + } + } + } + } + + return; +} + + +/*--------------------------------------------------------------------------* + * harm_bwe_fine() + * + * Prepare harmonic BWE fine structure + *--------------------------------------------------------------------------*/ + +void harm_bwe_fine( + const short *R, /* i : bit allocation */ + const short last_sfm, /* i : last coded subband */ + const short high_sfm, /* i : higher transition band to BWE */ + const short num_sfm, /* i : total number of bands */ + const short *norm, /* i : quantization indices for norms */ + const short *sfm_start, /* i : Subband start coefficient */ + const short *sfm_end, /* i : Subband end coefficient */ + short *prev_L_swb_norm, /* i/o: last normalize length */ + float *coeff, /* i/o: coded/noisefilled normalized spectrum */ + float *coeff_out, /* o : coded/noisefilled spectrum */ + float *coeff_fine /* o : BWE fine structure */ +) +{ + short sfm; + short i; + float normq; + float SWB_signal[L_HARMONIC_EXC]; + float envelope[L_HARMONIC_EXC]; + float *src, *dst, *end; + + short norm_width = 64; + + /* shape the spectrum */ + for (sfm = 0; sfm <= last_sfm; sfm++) + { + if( R[sfm] != 0 ) + { + normq = dicn[norm[sfm]]; + for (i = sfm_start[sfm]; i < sfm_end[sfm]; i++) + { + coeff_out[i] = coeff[i]*normq; + } + } + else + { + for (i = sfm_start[sfm]; i < sfm_end[sfm]; i++) + { + coeff_out[i] = 0.0f; + } + } + } + + /* excitation replication */ + mvr2r( coeff_out, SWB_signal, L_HARMONIC_EXC ); + calc_normal_length( HQ_CORE, coeff_out, HQ_HARMONIC, -1, &norm_width, prev_L_swb_norm ); + hq_swb_harmonic_calc_norm_envelop( SWB_signal, envelope, norm_width, L_HARMONIC_EXC ); + + /* Normalize with envelope */ + for (i = 0; i < L_HARMONIC_EXC; i++) + { + SWB_signal[i] = SWB_signal[i] / envelope[i]; + } + + dst = coeff_fine + sfm_end[last_sfm]; + end = coeff_fine + sfm_end[num_sfm-1]; + + if ( (sfm_end[last_sfm] - sfm_end[high_sfm]) <= L_HARMONIC_EXC - START_EXC ) + { + src = SWB_signal + START_EXC + (sfm_end[last_sfm] - sfm_end[high_sfm]); + } + else + { + src = SWB_signal + L_HARMONIC_EXC - 1; + } + + while (dst < end) + { + while (dst < end && src < &SWB_signal[L_HARMONIC_EXC]) + { + *dst++ = *src++; + } + src --; + + while (dst < end && src >= &SWB_signal[START_EXC]) + { + *dst++ = *src--; + } + src++; + } + + return; +} + +/*--------------------------------------------------------------------------* + * hvq_bwe_fine() + * + * Prepare HVQ BWE fine structure + *--------------------------------------------------------------------------*/ + +void hvq_bwe_fine( + const short last_sfm, /* i : last coded subband */ + const short num_sfm, /* i : total number of bands */ + const short *sfm_end, /* i : Subband end coefficient */ + const short *peak_idx, /* i : Peak index */ + const short Npeaks, /* i : Number of peaks */ + short *peak_pos, /* i/o: Peak positions */ + short *prev_L_swb_norm, /* i/o: last normalize length */ + float *coeff, /* i/o: coded/noisefilled normalized spectrum */ + short *bwe_peaks, /* o : Positions of peaks in BWE */ + float *coeff_fine /* o : HVQ BWE fine structure */ +) +{ + short i, j; + float SWB_signal[L_HARMONIC_EXC]; + float envelope[L_HARMONIC_EXC]; + float *src, *dst, *end; + short *peak_dst, *peak_src; + short norm_width = 64; + + /* excitation replication */ + mvr2r( coeff, SWB_signal, L_HARMONIC_EXC ); + calc_normal_length( HQ_CORE, coeff, HQ_HVQ, -1, &norm_width, prev_L_swb_norm ); + + hq_swb_harmonic_calc_norm_envelop( SWB_signal, envelope, norm_width, L_HARMONIC_EXC ); + + /* Normalize with envelope */ + for (i = 0; i < L_HARMONIC_EXC; i++) + { + SWB_signal[i] = SWB_signal[i] / envelope[i]; + } + + dst = coeff_fine; + end = coeff_fine + sfm_end[num_sfm-1] - sfm_end[last_sfm]; + + src = SWB_signal + START_EXC; + peak_src = peak_pos + START_EXC; + + for(i = 0; i < Npeaks; i++) + { + if ( peak_idx[i] < L_HARMONIC_EXC ) + { + peak_pos[peak_idx[i]] = 1; + } + } + + i = L_HARMONIC_EXC-1; + while( i-- > 0 ) + { + if( peak_pos[i] == 1 ) + { + break; + } + } + + if( i < 180 ) + { + i = 180; + } + + for( j = L_HARMONIC_EXC-1; j > i+1; j-- ) + { + SWB_signal[j] = 0.0f; + } + + peak_dst = bwe_peaks + sfm_end[last_sfm]; + while ( dst < end ) + { + while ( dst < end && src < &SWB_signal[L_HARMONIC_EXC] ) + { + *dst++ = *src++; + *peak_dst++ = *peak_src++; + } + peak_src--; + src --; + + while (dst < end && src >= &SWB_signal[START_EXC]) + { + *dst++ = *src--; + *peak_dst++ = *peak_src--; + } + peak_src++; + src++; + } + + return; +} + +/*--------------------------------------------------------------------------* + * hq_fold_bwe() + * + * HQ mode folding BWE + *--------------------------------------------------------------------------*/ + +void hq_fold_bwe( + const short last_sfm, /* i : last coded subband */ + const short *sfm_end, /* i : Subband end coefficient */ + const short num_sfm, /* i : Number of subbands */ + float *coeff /* i/o: coded/noisefilled normalized spectrum */ +) +{ + short low_coeff; + short first_coeff; + float *src, *dst, *end; + + /* Find replication range for BWE */ + low_coeff = sfm_end[last_sfm] >> 1; + src = coeff + sfm_end[last_sfm] - 1; + + first_coeff = sfm_end[last_sfm]; + dst = coeff + sfm_end[last_sfm]; + end = coeff + sfm_end[num_sfm-1]; + + /* Generate BWE with spectral folding */ + while (dst < end) + { + while (dst < end && src >= &coeff[low_coeff]) + { + *dst++ = *src--; + } + + src++; + + while (dst < end && src < &coeff[first_coeff]) + { + *dst++ = *src++; + } + } + + return; +} + +/*--------------------------------------------------------------------------* + * apply_nf_gain() + * + * Apply noise fill gain + *--------------------------------------------------------------------------*/ + +void apply_nf_gain( + const short nf_idx, /* i : noise fill gain index */ + const short last_sfm, /* i : last coded subband */ + const short *R, /* i : bit allocation */ + const short *sfm_start, /* i : Subband start coefficient */ + const short *sfm_end, /* i : Subband end coefficient */ + float *coeff /* i/o: coded/noisefilled normalized spectrum */ +) +{ + short sfm; + short j; + float nf_scale; + + nf_scale = 1.0f / (1 << nf_idx); + for (sfm = 0; sfm <= last_sfm; sfm++) + { + if (R[sfm] == 0) + { + for (j = sfm_start[sfm]; j < sfm_end[sfm]; j++) + { + /* Scale NoiseFill */ + coeff[j] = coeff[j] * nf_scale; + } + } + } + + return; +} + +/*--------------------------------------------------------------------------* + * hq_generic_fine() + * + * Prepare HQ SWB BWE fine structure + *--------------------------------------------------------------------------*/ + +void hq_generic_fine( + float *coeff, /* i : coded/noisefilled normalized spectrum */ + const short last_sfm, /* i : Last coded band */ + const short *sfm_start, /* i : Subband start coefficient */ + const short *sfm_end, /* i : Subband end coefficient */ + short *bwe_seed, /* i/o: random seed for generating BWE input */ + float *coeff_out1 /* o : HQ SWB BWE input */ +) +{ + short sfm; + short i; + float multi; + + multi = 1.0f; + for (sfm = 0; sfm <= last_sfm; sfm++) + { + for (i = sfm_start[sfm]; i < sfm_end[sfm]; i++) + { + if (coeff[i]==0.f) + { + coeff_out1[i] = (float)multi*( own_random(bwe_seed)>0 ? 1.0f: -1.0f)*0.5f; + } + else + { + coeff_out1[i] = coeff[i]; + } + } + } + + return; +} + +/*--------------------------------------------------------------------------* + * harm_bwe() + * + * HQ Harmonic BWE + *--------------------------------------------------------------------------*/ + +void harm_bwe( + const float *coeff_fine, /* i : fine structure for BWE */ + const float *coeff, /* i : coded/noisefilled normalized spectrum */ + const short num_sfm, /* i : Number of subbands */ + const short *sfm_start, /* i : Subband start coefficient */ + const short *sfm_end, /* i : Subband end coefficient */ + const short last_sfm, /* i : last coded subband */ + const short high_sfm, /* i : higher transition band to BWE */ + const short *R, /* i : bit allocation */ + const short prev_hq_mode, /* i : previous hq mode */ + short *norm, /* i/o: quantization indices for norms */ + float *noise_level, /* i/o: noise levels for harmonic modes */ + float *prev_noise_level, /* i/o: noise factor in previous frame */ + short *bwe_seed, /* i/o: random seed for generating BWE input */ + float *coeff_out /* o : coded/noisefilled spectrum */ +) +{ + short i, j; + short sfm; + float normq; + float norm_adj; + float E_L; + + float alfa = 0.5f; + float alpha, beta; + short idx; + float fac; + float *src, *dst; + + for (sfm = 0; sfm <= last_sfm; sfm++) + { + if (R[sfm] == 0) + { + normq = dicn[norm[sfm]]; + for (i = sfm_start[sfm]; i < sfm_end[sfm]; i++) + { + coeff_out[i] = coeff[i]*normq; + } + } + } + noise_level[1] = noise_level[0]; + + /* shaping the BWE spectrum further by envelopes and noise factors */ + noise_level[0] = 0.9f*prev_noise_level[0] + 0.1f*noise_level[0]; + noise_level[1] = 0.9f*prev_noise_level[1] + 0.1f*noise_level[1]; + + if( prev_hq_mode == HQ_NORMAL || prev_hq_mode == HQ_GEN_SWB) + { + if( noise_level[0] < 0.25f ) + { + noise_level[0] *= 4.0f; + } + + if( noise_level[1] < 0.25f ) + { + noise_level[1] *= 4.0f; + } + } + + E_L = EPSILON; + for( i=last_sfm+1; i < num_sfm; i++ ) + { + E_L = EPSILON; + for (j = sfm_start[i]; j < sfm_end[i]; j++) + { + E_L += coeff_fine[j] * coeff_fine[j]; + } + E_L = (float)sqrt((sfm_end[i] - sfm_start[i])/E_L); + + normq = dicn[norm[i]]; + norm_adj = normq*E_L; + alfa = (i > 27) ? noise_level[1] : noise_level[0]; + beta = (float)sqrt(1.0f - alfa); + alpha = (float)sqrt(alfa) * 0.5f; + + for(sfm = sfm_start[i]; sfm < sfm_end[i]; sfm++) + { + coeff_out[sfm] = (beta*coeff_fine[sfm]*norm_adj + alpha*own_random(bwe_seed)/32768.0f*normq); + } + } + + prev_noise_level[0] = noise_level[0]; + prev_noise_level[1] = noise_level[1]; + idx = 16; + src = &coeff_out[sfm_end[high_sfm] + L_HARMONIC_EXC - START_EXC]; + dst = src-1; + + for( i = 0; i < idx; i++ ) + { + fac = i / (2.0f * idx); + *src++ *= 0.5f + fac; + *dst-- *= 0.5f + fac; + } + if( num_sfm ==33 ) + { + set_f(&coeff_out[800], 0, 160); + } + return; +} + +/*--------------------------------------------------------------------------* + * HVQ_bwe() + * + * HQ HVQ BWE + *--------------------------------------------------------------------------*/ + +void hvq_bwe( + const float *coeff, /* i : coded/noisefilled spectrum */ + const float *coeff_fine, /* i : BWE fine structure */ + const short *sfm_start, /* i : Subband start coefficient */ + const short *sfm_end, /* i : Subband end coefficient */ + const short *sfm_len, /* i : Subband length */ + const short last_sfm, /* i : last coded subband */ + const short prev_hq_mode, /* i : previous hq mode */ + const short *bwe_peaks, /* i : HVQ bwe peaks */ + const short bin_th, /* i : HVQ transition bin */ + const short num_sfm, /* i : Number of bands */ + const long core_brate, /* i : Core bit-rate */ + const short *R, /* i : Bit allocation */ + short *norm, /* i/o: quantization indices for norms */ + float *noise_level, /* i/o: noise levels for harmonic modes */ + float *prev_noise_level, /* i/o: noise factor in previous frame */ + short *bwe_seed, /* i/o: random seed for generating BWE input */ + float *coeff_out /* o : coded/noisefilled spectrum */ +) +{ + short i, j; + short N; + float normq; + float E_L; + + short bwe_noise_th = 0; + short peak_band, low, high, sel_norm; + short norm_ind; + float tmp_norm = 0; + short idx; + float fac; + float *src, *dst; + short istart, iend; + short offset = sfm_end[last_sfm]; + + mvr2r( coeff, coeff_out, L_FRAME48k ); + + bwe_noise_th = bin_th+(sfm_end[num_sfm-1] - bin_th)/HVQ_BWE_NOISE_BANDS; + logqnorm(&coeff_out[sfm_start[last_sfm]], &norm[last_sfm], 40, sfm_len[last_sfm], thren_HQ); + + /* shaping the BWE spectrum further by envelopes and noise factors */ + noise_level[0] = 0.9f*prev_noise_level[0] + 0.1f*noise_level[0]; + noise_level[1] = 0.9f*prev_noise_level[1] + 0.1f*noise_level[1]; + + if( prev_hq_mode == HQ_NORMAL || prev_hq_mode == HQ_GEN_SWB) + { + if( noise_level[0] < 0.25f ) + { + noise_level[0] *= 4.0f; + } + + if( noise_level[1] < 0.25f ) + { + noise_level[1] *= 4.0f; + } + } + + norm_ind = last_sfm+1; + if (core_brate == HQ_24k40) + { + peak_band = 0; + E_L = EPSILON; + for (i = sfm_start[norm_ind]; i < sfm_end[norm_ind+1]; i++) + { + if (bwe_peaks[i]) + { + peak_band = 1; + } + E_L += coeff_fine[i-offset] * coeff_fine[i-offset]; + } + E_L = (float)sqrt((sfm_end[norm_ind+1] - sfm_start[norm_ind])/E_L); + + normq = 0.1f*dicn[norm[norm_ind-1]] + 0.8f*dicn[norm[norm_ind]] + 0.1f*dicn[norm[norm_ind+1]]; + tmp_norm = 0.1f*dicn[norm[norm_ind]] + 0.8f*dicn[norm[norm_ind+1]] + 0.1f*dicn[norm[norm_ind+2]]; + + istart = sfm_start[norm_ind]; + iend = istart + sfm_len[norm_ind]/2; + for (i = istart; i < iend; i++) + { + coeff_out[i] = ((1.0f - noise_level[i/bwe_noise_th])*coeff_fine[i-offset]*E_L + noise_level[i/bwe_noise_th]*own_random(bwe_seed)/32768.0f)*normq; + } + + j = 0; + N = sfm_len[norm_ind]/2+sfm_len[norm_ind+1]/2-1; + istart = iend; + iend = sfm_start[norm_ind+1] + sfm_len[norm_ind+1]/2; + for (i = istart; i < iend; i++) + { + coeff_out[i] = ((float)(N-j)/N*normq + (float)j/N*tmp_norm)*((1.0f - noise_level[i/bwe_noise_th])*coeff_fine[i-offset]*E_L + noise_level[i/bwe_noise_th]*own_random(bwe_seed)/32768.0f); + j++; + } + + istart = iend; + iend = sfm_end[norm_ind+1]; + for (i = istart; i < iend; i++) + { + coeff_out[i] = ((1.0f - noise_level[i/bwe_noise_th])*coeff_fine[i-offset]*E_L + noise_level[i/bwe_noise_th]*own_random(bwe_seed)/32768.0f)*tmp_norm; + } + + norm_ind += 2; + } + + for ( ; norm_ind < num_sfm; norm_ind++) + { + if ( R[norm_ind] == 0 ) + { + peak_band = 0; + E_L = EPSILON; + + for (i = sfm_start[norm_ind]; i < sfm_end[norm_ind]; i++) + { + if (bwe_peaks[i]) + { + peak_band = 1; + break; + } + } + + istart = sfm_start[norm_ind]; + iend = sfm_end[norm_ind]; + + if ( peak_band == 1 && norm_ind > last_sfm+1 && norm_ind < num_sfm-1 ) + { + istart -= sfm_len[norm_ind-1]/2; + iend += sfm_len[norm_ind+1]/2; + } + + for (i = istart; i < iend; i++) + { + E_L += coeff_fine[i-offset] * coeff_fine[i-offset]; + } + E_L = (float)sqrt((iend - istart)/E_L); + + if ( peak_band ) + { + if ( norm_ind+1 > num_sfm-1 ) + { + normq = 0.15f*dicn[norm[norm_ind-1]] + 0.85f*dicn[norm[norm_ind]]; + } + else + { + normq = 0.1f*dicn[norm[norm_ind-1]] + 0.8f*dicn[norm[norm_ind]] + 0.1f*dicn[norm[norm_ind+1]]; + } + } + else + { + low = norm_ind; + high = min(norm_ind+1, num_sfm-1); + sel_norm = norm[norm_ind-1]; + for (j = low; j <= high; j++) + { + if (norm[j] > sel_norm) + { + sel_norm = norm[j]; + } + } + normq = dicn[sel_norm]; + } + + for (i = sfm_start[norm_ind]; i < sfm_end[norm_ind]; i++) + { + coeff_out[i] = ((1.0f - noise_level[i/bwe_noise_th])*coeff_fine[i-offset]*E_L + noise_level[i/bwe_noise_th]*own_random(bwe_seed)/32768.0f)*normq; + } + } + else /* R[norm_ind] > 0 */ + { + for (i = sfm_start[norm_ind]; i < sfm_end[norm_ind]; i++) + { + coeff_out[i] = coeff[i]; /* Scaling already applied */ + } + } + + } + + prev_noise_level[0] = noise_level[0]; + prev_noise_level[1] = noise_level[1]; + idx = 16; + src = &coeff_out[sfm_end[last_sfm] + L_HARMONIC_EXC - START_EXC]; + dst = src-1; + + for( i = 0; i < idx; i++ ) + { + fac = i/(2.0f * idx); + *src++ *= 0.5f + fac; + *dst-- *= 0.5f + fac; + } + + return; +} +/*-------------------------------------------------------------------* +* hvq_concat_bands() +* +* Compute the band limits for concatenated bands for PVQ target signal in HVQ +*--------------------------------------------------------------------------*/ +void hvq_concat_bands +( + const short pvq_bands, /* i : Number of bands in concatenated PVQ target */ + const short *sel_bnds, /* i : Array of selected high bands */ + const short n_sel_bnds, /* i : Number of selected high bands */ + short *hvq_band_start, /* i : Band start indices */ + short *hvq_band_width, /* i : Band widths */ + short *hvq_band_end /* i : Band end indices */ +) +{ + short k; + short s; + + s = 0; + + for (k = 0; k < pvq_bands; k++) + { + + if( k >= pvq_bands - n_sel_bnds) + { + hvq_band_start[k] = hvq_band_end[k-1]; + hvq_band_width[k] = band_len_harm[sel_bnds[s]]; + hvq_band_end[k] = hvq_band_end[k-1] + band_len_harm[sel_bnds[s]]; + s++; + } + else + { + hvq_band_start[k] = k * HVQ_PVQ_COEFS; + hvq_band_width[k] = HVQ_PVQ_COEFS; + hvq_band_end[k] = (k + 1) * HVQ_PVQ_COEFS; + } + } + + return; +} + + +/*--------------------------------------------------------------------------* + * map_hq_generic_fenv_norm() + * + * mapping high frequency envelope to high band norm + *--------------------------------------------------------------------------*/ +void map_hq_generic_fenv_norm( + const short hqswb_clas, + const float *hq_generic_fenv, + short *ynrm, + short *normqlg2, + const short num_env_bands, + const short nb_sfm, + const short hq_generic_offset) +{ + float env_fl[17]; + short i; + + set_f( env_fl, 0, 17 ); + if (hq_generic_offset == 144) + { + env_fl[0] = hq_generic_fenv[1]; + env_fl[1] = hq_generic_fenv[2]*0.6640625f+hq_generic_fenv[3]*0.3359375f; + env_fl[2] = hq_generic_fenv[3]*0.6640625f+hq_generic_fenv[4]*0.3359375f; + env_fl[3] = hq_generic_fenv[4]*0.3359375f+hq_generic_fenv[5]*0.6640625f; + env_fl[4] = hq_generic_fenv[5]*0.3359375f+hq_generic_fenv[6]*0.6640625f; + env_fl[5] = hq_generic_fenv[7]; + env_fl[6] = hq_generic_fenv[8]*0.75f+hq_generic_fenv[9]*0.25f; + env_fl[7] = hq_generic_fenv[9]*0.75f+hq_generic_fenv[10]*0.25f; + env_fl[8] = hq_generic_fenv[10]*0.25f+hq_generic_fenv[11]*0.75f; + } + else + { + env_fl[0] = hq_generic_fenv[0]*0.3359375f+hq_generic_fenv[1]*0.6640625f; + env_fl[1] = hq_generic_fenv[1]*0.3359375f+hq_generic_fenv[2]*0.6640625f; + env_fl[2] = hq_generic_fenv[3]; + env_fl[3] = hq_generic_fenv[4]*0.6640625f+hq_generic_fenv[5]*0.3359375f; + env_fl[4] = hq_generic_fenv[5]*0.6640625f+hq_generic_fenv[6]*0.3359375f; + env_fl[5] = hq_generic_fenv[6]*0.3359375f+hq_generic_fenv[7]*0.6640625f; + env_fl[6] = hq_generic_fenv[7]*0.3359375f+hq_generic_fenv[8]*0.6640625f; + env_fl[7] = hq_generic_fenv[8]*0.3359375f+hq_generic_fenv[9]*0.6640625f; + env_fl[8] = hq_generic_fenv[9]*0.3359375f+hq_generic_fenv[10]*0.6640625f; + env_fl[9] = hq_generic_fenv[10]*0.25f+hq_generic_fenv[11]*0.75f; + env_fl[10] = hq_generic_fenv[12]; + env_fl[11] = hq_generic_fenv[13]; + } + + if (hqswb_clas == HQ_GEN_FB) + { + if (hq_generic_offset == 144) + { + env_fl[9] = hq_generic_fenv[12]; + env_fl[10] = hq_generic_fenv[12]*0.25f+hq_generic_fenv[13]*0.75f; + env_fl[11] = hq_generic_fenv[13]*0.5f+hq_generic_fenv[14]*0.5f; + env_fl[12] = hq_generic_fenv[14]; + env_fl[13] = hq_generic_fenv[14]; + } + else + { + env_fl[12] = hq_generic_fenv[14]; + env_fl[13] = hq_generic_fenv[14]*0.25f+hq_generic_fenv[15]*0.75f; + env_fl[14] = hq_generic_fenv[15]*0.5f+hq_generic_fenv[16]*0.5f; + env_fl[15] = hq_generic_fenv[16]; + env_fl[16] = hq_generic_fenv[16]; + } + } + + logqnorm_2( env_fl,40, num_env_bands, nb_sfm, ynrm+num_env_bands, normqlg2+num_env_bands, thren_HQ); + + for(i=num_env_bands; i0) + { + i=nb_sfm-1; + while(b_add_bits_denv>0 && i>=0) + { + if (Rsubband[i]>24) + { + Rsubband[i] -= 8; + b_add_bits_denv--; + } + i--; + } + } + + return; +} + +short get_nor_delta_hf( + Decoder_State *st, + short *ynrm, + short *Rsubband, + const short num_env_bands, + const short nb_sfm, + const short core_sfm +) +{ + short i; + short delta,bitsforDelta,add_bits_denv; + + add_bits_denv = 0; + if (core_sfm >= num_env_bands) + { + bitsforDelta = (short)get_next_indice(st,2); + bitsforDelta += 2; + add_bits_denv += 2; + + for(i=num_env_bands; i 39 ) + { + ynrm[i] = 39; + st->BER_detect = 1; + } + add_bits_denv += bitsforDelta; + } + } + + update_rsubband(nb_sfm, Rsubband,add_bits_denv); + } + return add_bits_denv; +} + +short calc_nor_delta_hf( + Encoder_State *st, + const float *t_audio, + short *ynrm, + short *Rsubband, + const short num_env_bands, + const short nb_sfm, + const short *sfmsize, + const short *sfm_start, + const short core_sfm +) +{ + short i; + short ynrm_t[44],normqlg2_t[44]; + short delta,max_delta,min_delta,bitsforDelta,add_bits_denv; + + + short temp_num=0; + + max_delta=-100; + calc_norm( t_audio, ynrm_t, normqlg2_t, 0, nb_sfm, sfmsize, sfm_start ); + add_bits_denv = 0; + for(i=num_env_bands; i 0) + { + delta += 1; + } + else + { + delta = -delta; + } + if (delta>max_delta) + { + max_delta = delta; + } + } + } + if (core_sfm >= num_env_bands) + { + if (max_delta < 16) + { + bitsforDelta = 2; + while(max_delta>=2) + { + bitsforDelta++; + max_delta >>= 1; + } + } + else + { + bitsforDelta = 5; + } + max_delta = (1<<(bitsforDelta-1))-1; + min_delta = (max_delta+1)*(-1); + + /* updating norm & storing delta norm */ + add_bits_denv = 2; + push_indice( st, IND_DELTA_ENV_HQ, bitsforDelta-2 , 2 ); + for(i=num_env_bands; i max_delta) + { + delta = max_delta; + } + else if (delta < min_delta) + { + delta = min_delta; + } + push_indice( st, IND_DELTA_ENV_HQ, delta - min_delta , bitsforDelta ); + ynrm[i] += delta; + add_bits_denv += bitsforDelta; + + + temp_num++; + } + } + + /* updating bit allocation */ + update_rsubband(nb_sfm, Rsubband,add_bits_denv); + + } + + return add_bits_denv; +} + +/*-------------------------------------------------------------------* +* hq_generic_bwe() +* +* HQ GENERIC BWE +*--------------------------------------------------------------------------*/ +void hq_generic_bwe( + const short HQ_mode, /* i : HQ mode */ + float *coeff_out1, /* i/o: BWE input & temporary buffer */ + const float *hq_generic_fenv, /* i : SWB frequency envelopes */ + float *coeff_out, /* o : SWB signal in MDCT domain */ + const short hq_generic_offset, /* i : frequency offset for representing hq generic*/ + short *prev_L_swb_norm, /* i/o: last normalize length */ + const short hq_generic_exc_clas, /* i : hq generic hf excitation class */ + const short *sfm_end, /* i : End of bands */ + const short num_sfm, /* i : Number of bands */ + const short num_env_bands, /* i : Number of coded envelope bands */ + const short *R /* i : Bit allocation */ +) +{ + short n_swb_overlap_offset, n_swb_overlap; + float hq_swb_overlap_buf[640]; + + n_swb_overlap_offset = swb_bwe_subband[0] + hq_generic_offset; + + n_swb_overlap = sfm_end[num_env_bands-1] - n_swb_overlap_offset; + mvr2r( &coeff_out[n_swb_overlap_offset], hq_swb_overlap_buf, n_swb_overlap + sfm_end[num_sfm-1] - sfm_end[num_env_bands-1] ); + + hq_generic_hf_decoding( HQ_mode, coeff_out1, hq_generic_fenv, coeff_out, hq_generic_offset, prev_L_swb_norm, hq_generic_exc_clas, R ); + + overlap_hq_bwe( hq_swb_overlap_buf, coeff_out, n_swb_overlap_offset, n_swb_overlap, R, num_env_bands, num_sfm, sfm_end ); + + return; +} + + +/*--------------------------------------------------------------------------* + * hq_wb_nf_bwe() + * + * HQ WB noisefill and BWE + *--------------------------------------------------------------------------*/ + +void hq_wb_nf_bwe( + const float *coeff, /* i : coded/noisefilled normalized spectrum */ + const short is_transient, /* i : is transient flag */ + const short prev_bfi, /* i : previous bad frame indicator */ + const float *normq_v, /* i : norms */ + const short num_sfm, /* i : Number of subbands */ + const short *sfm_start, /* i : Subband start coefficient */ + const short *sfm_end, /* i : Subband end coefficient */ + const short *sfmsize, /* i : Subband band width */ + const short last_sfm, /* i : last coded subband */ + const short *R, /* i : bit allocation */ + const short prev_is_transient, /* i : previous transient flag */ + float *prev_normq, /* i/o: previous norms */ + float *prev_env, /* i/o: previous noise envelopes */ + short *bwe_seed, /* i/o: random seed for generating BWE input */ + float *prev_coeff_out, /* i/o: decoded spectrum in previous frame */ + short *prev_R, /* i/o: bit allocation info. in previous frame */ + float *coeff_out /* o : coded/noisefilled spectrum */ +) +{ + short i; + short sfm; + short total_bit; + short num; + + float bitalloc_var; + float sharp; + float mean; + float peak; + float fabs_coeff_out; + float harm_para; + float alfa = 0.5; + float env; + float step; + float min_coef; + float avrg_norm; + float prev_avrg_norm; + + if( is_transient == 0 ) + { + if( prev_bfi == 1 ) + { + mvr2r(normq_v, prev_normq, SFM_N_WB); + } + + /* the variance of bit allocation */ + total_bit = 0; + bitalloc_var = 0.0f; + for (sfm = 8; sfm <= last_sfm; sfm++) + { + bitalloc_var += (float)abs(R[sfm] - R[sfm-1]); + total_bit += R[sfm]; + } + bitalloc_var = (last_sfm > 8 && total_bit > 0) ? (bitalloc_var / total_bit) : 0; + + /* calculate the peak-average ratio of saturable subbands */ + num = 0; + sharp = EPSILON; + for(sfm = last_sfm; sfm >= 8; sfm--) + { + if(R[sfm] >= rat[sfm]*sfmsize[sfm]) + { + peak = 0.0f; + mean = EPSILON; + for (i = sfm_start[sfm]; i < sfm_end[sfm]; i++) + { + fabs_coeff_out = (float)fabs(coeff_out[i]); + mean += fabs_coeff_out; + if(fabs_coeff_out > peak) + { + peak = fabs_coeff_out; + } + } + sharp += sfmsize[sfm]*peak/mean; + num ++; + } + } + + sharp = (num != 0) ? 2.0f*num/sharp : 1.0f; + harm_para = sharp; + if( last_sfm == 0 ) + { + step = 0; + } + else + { + step = 5.0f * sharp / last_sfm; + } + alfa = 2.5f; + + /* fill noise for the insaturable subbands */ + for( sfm = 0; sfm < num_sfm; sfm++ ) + { + env = 0.0f; + if(R[sfm] != 0 && R[sfm] < 1.5f*sfmsize[sfm]) + { + /* calculate the energy of the undecoded coefficients */ + peak = 0.0f; + min_coef = FLT_MAX; + env = normq_v[sfm]*normq_v[sfm]*sfmsize[sfm]; + for (i = sfm_start[sfm]; i < sfm_end[sfm]; i++) + { + fabs_coeff_out = (float)fabs(coeff_out[i]); + if(fabs_coeff_out < min_coef && coeff_out[i] != 0) + { + min_coef = fabs_coeff_out; + } + if(fabs_coeff_out > peak) + { + peak = fabs_coeff_out; + } + env -= coeff_out[i]*coeff_out[i]; + } + + if (env > 0 ) + { + if(sfm == 0) + { + avrg_norm = normq_v[0] + normq_v[1] + normq_v[2]; + prev_avrg_norm = prev_normq[0] + prev_normq[1] + prev_normq[2]; + } + else if (sfm == 25) + { + avrg_norm = normq_v[23] + normq_v[24] + normq_v[25]; + prev_avrg_norm = prev_normq[23] + prev_normq[24] + prev_normq[25]; + } + else + { + avrg_norm = normq_v[sfm-1] + normq_v[sfm] + normq_v[sfm+1]; + prev_avrg_norm = prev_normq[sfm-1] + prev_normq[sfm] + prev_normq[sfm+1]; + } + + if(bitalloc_var > 0.3f || 4.0f*normq_v[sfm] < peak) + { + /* calculate the noise magnitude of harmonic signal */ + env = (float)(avrg_norm*harm_para *sqrt(env/sfmsize[sfm])/peak); + } + else + { + /* calculate the noise magnitude of normal signal */ + env = sharp *(float)sqrt(env/sfmsize[sfm]); + if(alfa*normq_v[sfm] < peak) + { + env *= env/peak; + } + sharp += step; + } + if(env > 0.5f*min_coef) + { + env = 0.5f*min_coef; + } + + if(prev_bfi == 1) + { + prev_env[sfm] = env; + } + /* smooth the noise magnitudes between inter-frame */ + if(prev_avrg_norm > 0.5f*avrg_norm && prev_avrg_norm < 2.0f*avrg_norm && prev_is_transient == 0) + { + env = 0.5f*env + 0.5f*prev_env[sfm]; + } + + for (i = sfm_start[sfm]; i < sfm_end[sfm]; i++) + { + if (coeff[i] == 0) + { + coeff_out[i] = (float)( own_random(bwe_seed))/32768.0f; + coeff_out[i] *= env; + } + } + } + else + { + env = 0.0f; + } + } + else if(R[sfm] == 0) + { + /* fill random noise for 0 bit subbands */ + for (i = sfm_start[sfm]; i < sfm_end[sfm]; i++) + { + if(coeff[i] == 0) + { + coeff_out[i] = (float)( own_random(bwe_seed))/32768.0f; + coeff_out[i] *= normq_v[sfm]; + } + } + + env = normq_v[sfm]; + } + if(sfm == SFM_N_WB-1 && prev_is_transient == 0 && prev_normq[sfm] > 0.5f*normq_v[sfm] && prev_normq[sfm] < 2.0f*normq_v[sfm] && bitalloc_var <= 0.3f ) + { + float *p_prev_coeff_out = prev_coeff_out; + for (i = sfm_start[sfm]+12; i < sfm_end[sfm]; i++) + { + if( fabs(coeff_out[i]) > 4.0f * fabs(*p_prev_coeff_out) || + fabs(coeff_out[i]) < 0.25f * fabs(*p_prev_coeff_out) || + (R[sfm] * (*prev_R) == 0 && R[sfm] + (*prev_R) != 0) ) + { + coeff_out[i] = (coeff_out[i] > 0) ? (float)(0.5f*(fabs(coeff_out[i]) + fabs(*p_prev_coeff_out))) : (float)(-0.5f*(fabs(coeff_out[i]) + fabs(*p_prev_coeff_out))); + } + p_prev_coeff_out++; + } + } + + prev_env[sfm] = env; + } + } + else + { + /* fill random noise for 0 bit subbands of transient frame */ + for(sfm = 0; sfm < num_sfm; sfm++) + { + if( R[sfm] == 0 ) + { + for (i = sfm_start[sfm]; i < sfm_end[sfm]; i++) + { + coeff_out[i] = (float)( own_random(bwe_seed))/32768.0f; + coeff_out[i] *= normq_v[sfm]; + } + } + } + + set_f( prev_env, 0, SFM_N_WB ); + } + + mvr2r(normq_v, prev_normq, SFM_N_WB); + mvr2r( coeff_out + L_FRAME16k - L_HQ_WB_BWE, prev_coeff_out, L_HQ_WB_BWE ); + *prev_R = R[SFM_N_WB-1]; + + return; +} + + +/*--------------------------------------------------------------------------* + * enforce_zero_for_min_envelope() + * + * Detect minimum level of envelope and set corresponding bands to zero + *--------------------------------------------------------------------------*/ + +void enforce_zero_for_min_envelope( + const short hqswb_clas, /* i : HQ coding mode */ + const short *ynrm, /* i : Envelope indices */ + float *coefsq, /* i/o: Quantized spectrum/zeroed spectrum */ + short nb_sfm, /* i : Number of coded sub bands */ + const short *sfm_start, /* i : Sub band start indices */ + const short *sfm_end /* i : Sub band end indices */ +) +{ + short i, j; + + /* prevent non-zero output for all-zero input */ + if( hqswb_clas != HQ_HVQ ) + { + if( ynrm[0] == 31 ) + { + for( j = sfm_start[0]; j < sfm_end[0]; j++ ) + { + coefsq[j] = 0.0f; + } + } + + for( i = 1; i < nb_sfm; i++ ) + { + if( ynrm[i] == 39 ) + { + for( j = sfm_start[i]; j < sfm_end[i]; j++ ) + { + coefsq[j] = 0.0f; + } + } + } + } + + return; +} + + +/*--------------------------------------------------------------------------* + * overlap_hq_bwe() + * + * Overlapping at the boundary between HQ core and BWE + *--------------------------------------------------------------------------*/ + +static void overlap_hq_bwe( + const float *hq_swb_overlap_buf, /* i : spectrum from HQ core */ + float *coeff_out, /* i/o: spectrum from BWE, overlapped output */ + const short n_swb_overlap_offset, /* i : starting offset of overlapping */ + const short n_swb_overlap, /* i : length of overlapping */ + const short *R, /* i : Bit allocation */ + const short num_env_bands, /* i : Number of coded envelope bands */ + const short num_sfm, /* i : Number of bands */ + const short *sfm_end /* i : Band end indices */ +) +{ + short i; + float step; + float weighting; + short n_band; + + if (R[num_env_bands-1] != 0) + { + mvr2r( hq_swb_overlap_buf, &coeff_out[n_swb_overlap_offset], n_swb_overlap ); + } + else + { + /*weighting = 0.8f;*/ + step = 1.0f / (float)n_swb_overlap; + weighting = 1.0f; + for (i = 0; i < n_swb_overlap; i++) + { + coeff_out[n_swb_overlap_offset+i] = hq_swb_overlap_buf[i] * weighting + coeff_out[n_swb_overlap_offset+i] * (1.0f - weighting); + weighting -= step; + } + } + + + for (n_band = num_env_bands; n_band < num_sfm; n_band++) + { + if (R[n_band] !=0 ) + { + for(i=sfm_end[n_band-1]; i> 1; + accY = my >> 1; + align = *ex - ey; + if (align < 0) + { + if( align > -32) /* If align < -32, (accY >> (-align) = 0 */ + { + accX = accX + (accY >> (-align)); + } + } + else + { + if( align < 32) /* If align > 32, (accX >> align) = 0 */ + { + accX = accY + (accX >> align); + } + else + { + accX = accY; + } + *ex = ey; + } + + expo = norm_l(accX); /* aligned to BASOP */ + *mx = accX << expo; + *ex = *ex + expo - 1; + + return; +} + diff --git a/src/libs/libevs/lib_com/hq_tools_fx.cpp b/src/libs/libevs/lib_com/hq_tools_fx.cpp deleted file mode 100755 index b876c32a..00000000 --- a/src/libs/libevs/lib_com/hq_tools_fx.cpp +++ /dev/null @@ -1,2329 +0,0 @@ -/*==================================================================================== - EVS Codec 3GPP TS26.442 Apr 03, 2018. Version 12.11.0 / 13.6.0 / 14.2.0 - ====================================================================================*/ - -#include -#include "options.h" /* Compilation switches */ -#include "rom_com_fx.h" /* Static table prototypes FIP version */ -#include "stl.h" /* required for wmc_tool */ -#include "prot_fx.h" - -/*--------------------------------------------------------------------------* - * Local functions - *--------------------------------------------------------------------------*/ - -static void overlap_hq_bwe_fx( const Word32 *hq_swb_overlap_buf, Word32 *coeff_out, const Word16 n_swb_overlap_offset, - const Word16 n_swb_overlap, const Word16 *R, const Word16 num_env_bands, const Word16 num_sfm, const Word16 *sfm_end); - -/*--------------------------------------------------------------------------* -* hq_swb_harmonic_calc_norm_envelop() -* -* Calculate normalization envelop -*--------------------------------------------------------------------------*/ - -void hq_swb_harmonic_calc_norm_envelop_fx( - Word32 *L_SWB_signal, /* i : input signal Q=12*/ - Word32 *L_envelope, /* o : output envelope Q=12*/ - Word16 L_swb_norm, /* i : length of normaliztion */ - Word16 SWB_flength /* i : length of input signal */ -) -{ - - Word16 lookback; - Word16 env_index; - Word16 n_freq; - Word16 n_lag_now; - Word16 n_lag; - Word16 i; - Word32 L_tmp; - - lookback = shr(L_swb_norm,1); - env_index = 0; - move16(); - FOR (n_freq = 0; n_freq < lookback; n_freq++) - { - n_lag_now = add(lookback,n_freq); - - /* Apply MA filter */ - L_envelope[env_index] = EPSILLON_FX; - move16(); - - FOR (n_lag=0; n_lag= 0) - { - *noise_level = 0; - move16(); - } - ELSE - { - IF(ener_sum !=0) - { - *noise_level = sub(8192, div_s(*noise_level, ener_sum)); - } - ELSE - { - *noise_level = 8192; - } - move16(); - } - - return; -} - -/*--------------------------------------------------------------------------* - * build_nf_codebook_fx() - * - * Build noise-fill codebook for HQ mode - * NOTE: Q values preliminary - *--------------------------------------------------------------------------*/ - -Word16 build_nf_codebook_fx( /* o : Number of coefficients in nf codebook Q=0*/ - const Word16 flag_32K_env_ho, /* i : Envelope attenuation hangover flag Q=0*/ - const Word16 *coeff, /* i : Coded spectral coefficients Q=12*/ - const Word16 *sfm_start, /* i : Subband start indices Q=0*/ - const Word16 *sfmsize, /* i : Subband widths Q=0*/ - const Word16 *sfm_end, /* i : Subband end indices Q=0*/ - const Word16 last_sfm, /* i : Last coded band Q=0*/ - const Word16 *R, /* i : Per-band bit allocation Q=0*/ - Word16 *CodeBook, /* o : Noise-fill codebook Q=12*/ - Word16 *CodeBook_mod /* o : Densified noise-fill codebook Q=12*/ -) -{ - Word16 sfm_base; - Word16 sfm; - Word16 E_cb_vec; - Word16 i,j; - Word16 cb_size; - - /* Build codebook */ - - cb_size = 0; - move16(); - - FOR ( sfm = 0; sfm <= last_sfm; sfm++ ) - { - IF (R[sfm] != 0) - { - IF (flag_32K_env_ho) - { - /* Build compressed (+/- 1) noise-fill codebook */ - sfm_base = sfm_start[sfm]; - move16(); - FOR (i = 0; i < sfmsize[sfm]/8; i++) - { - E_cb_vec = 0; - move16(); - FOR (j = sfm_base+i*8; j < sfm_base+(i+1)*8; j++) - { - IF (coeff[j] > 0) - { - CodeBook_mod[cb_size] = 1<<12; - move16(); /* set to 1, Q value 12 */ - E_cb_vec = add(E_cb_vec,1); - } - ELSE IF (coeff[j] < 0) - { - CodeBook_mod[cb_size] = -1 * (1<<12); - move16(); /* set to -1, Q value 12 */ - E_cb_vec = add(E_cb_vec,1); - } - ELSE - { - CodeBook_mod[cb_size] = 0; - move16(); - } - cb_size = add(cb_size,1); - } - - if (E_cb_vec < 2) - { - cb_size = sub(cb_size,8); - } - } - } - ELSE - { - FOR (j = sfm_start[sfm]; j < sfm_end[sfm]; j++) - { - CodeBook[cb_size] = coeff[j]; - move16(); - cb_size = add(cb_size,1); - } - } - } - } - - IF (flag_32K_env_ho) - { - FOR (j = 0; j < cb_size; j++) - { - IF (CodeBook_mod[j] != 0) - { - /* Densify codebook */ - CodeBook[j] = -4096; - move16(); /* -1 in Q12 */ - if (CodeBook_mod[j] > 0) - { - CodeBook[j] = 4096; - move16(); /* 1 in Q12 */ - } - - IF (CodeBook_mod[cb_size-j-1] != 0) - { - CodeBook[j] = shl(CodeBook[j], 1); - move16(); /* Mult by 2 */ - } - } - ELSE - { - CodeBook[j] = CodeBook_mod[cb_size-j-1]; - move16(); - } - } - } - - return cb_size; -} - - -/*--------------------------------------------------------------------------* -* find_last_band() -* -* Find the last band which has bits allocated -*--------------------------------------------------------------------------*/ - -Word16 find_last_band_fx( /* o : index of last band */ - const Word16 *bitalloc, /* i : bit allocation */ - const Word16 nb_sfm /* i : number of possibly coded bands */ -) -{ - Word16 sfm, core_sfm; - - core_sfm = sub(nb_sfm,1); - - FOR (sfm = nb_sfm-1; sfm >= 0; sfm--) - { - IF ( bitalloc[sfm] != 0 ) - { - core_sfm = sfm; - move16(); - BREAK; - } - } - - return core_sfm; -} - -/*--------------------------------------------------------------------------* - * apply_noisefill_HQ() - * - * Inject noise in non-coded bands - *--------------------------------------------------------------------------*/ - -void apply_noisefill_HQ_fx( - const Word16 *R, /* i : bit allocation Q0 */ - const Word16 length, /* i : input frame length Q0 */ - const Word16 flag_32K_env_ho,/* i : envelope stability hangover flag Q0 */ - const Word32 L_core_brate, /* i : core bit rate Q0 */ - const Word16 last_sfm, /* i : last coded subband Q0 */ - const Word16 *CodeBook, /* i : Noise-fill codebook Q12 */ - const Word16 *CodeBook_mod, /* i : Densified noise-fill codebook Q12 */ - const Word16 cb_size, /* i : Codebook length Q0 */ - const Word16 *sfm_start, /* i : Subband start coefficient Q0 */ - const Word16 *sfm_end, /* i : Subband end coefficient Q0 */ - const Word16 *sfmsize, /* i : Subband band width Q0 */ - Word16 *coeff /* i/o: coded/noisefilled spectrum Q12 */ -) -{ - Word16 sfm; - Word16 cb_pos; - Word16 E_corr; - Word16 cb_buff[PVQ_MAX_BAND_SIZE]; - Word16 i, j; - Word16 istart; - UWord16 lsb; - Word32 L_E_cb_vec; - Word32 L_E_corr; - - test(); - test(); - IF ( (sub(length, L_FRAME32k) >= 0) || (L_sub(L_core_brate, HQ_32k) > 0) || (L_sub(L_core_brate, HQ_24k40) < 0) ) - { - /* Read from codebook */ - cb_pos = 0; - move16(); - - FOR (sfm = 0; sfm <= last_sfm; sfm++) - { - IF (R[sfm] == 0) - { - IF (sub(flag_32K_env_ho, 1) == 0) - { - L_E_cb_vec = L_deposit_l(0); - IF (sub(sfm, 20) < 0) - { - FOR (i = 0; i < sfmsize[sfm]; i++) - { - cb_buff[i] = CodeBook_mod[cb_pos++]; - move16(); - L_E_cb_vec = L_mac0(L_E_cb_vec, cb_buff[i], cb_buff[i]); /*Q24 (12+12) */ - - if (sub(cb_pos, cb_size) >= 0) - { - cb_pos = 0; - move16(); - } - } - } - ELSE - { - FOR (i = 0; i < sfmsize[sfm]; i++) - { - cb_buff[i] = CodeBook[cb_pos++]; - move16(); - L_E_cb_vec = L_mac0(L_E_cb_vec, cb_buff[i], cb_buff[i]); /*Q24 (12+12) */ - - if (sub(cb_pos, cb_size) >= 0) - { - cb_pos = 0; - move16(); - } - } - } - - /*E_corr = E_cb_vec / ((float) sfmsize[sfm]); */ - Mpy_32_16_ss(L_E_cb_vec, inv_tbl_fx[sfmsize[sfm]], &L_E_corr, &lsb); /*Q24 (24+15+1-16) */ - move16(); - - /*E_corr = 1.0f / (float)sqrt(E_corr); */ - L_E_corr = Isqrt(L_E_corr); /*Q19 (31-24/2) */ - E_corr = extract_h(L_shl(L_E_corr, 10)); /*Q13 (13-(19-16)) */ - - istart = sfm_start[sfm]; - move16(); - FOR(j = istart; j < sfm_end[sfm]; j++) - { - /*coeff[j] = cb_buff[j - istart] * E_corr; */ - coeff[j] = extract_h(L_shl(L_mult(cb_buff[j - istart], E_corr), 2)); /*Q12 (12+13+1+2-16) */ - } - } - ELSE - { - FOR (j = sfm_start[sfm]; j < sfm_end[sfm]; j++) - { - coeff[j] = CodeBook[cb_pos++]; - move16(); - if (sub(cb_pos, cb_size) >= 0) - { - cb_pos = 0; - move16(); - } - } - } - } - } - } - - return; -} - -/*--------------------------------------------------------------------------* - * harm_bwe_fine_fx() - * - * Prepare harmonic BWE fine structure - *--------------------------------------------------------------------------*/ - -void harm_bwe_fine_fx( - const Word16 *R, /* i : bit allocation */ - const Word16 last_sfm, /* i : last coded subband */ - const Word16 high_sfm, /* i : higher transition band to BWE */ - const Word16 num_sfm, /* i : total number of bands */ - const Word16 *norm, /* i : quantization indices for norms */ - const Word16 *sfm_start, /* i : Subband start coefficient */ - const Word16 *sfm_end, /* i : Subband end coefficient */ - Word16 *prev_L_swb_norm, /* i/o: last normalize length */ - Word16 *coeff, /* i/o: coded/noisefilled normalized spectrum */ - Word32 *coeff_out /* o : coded/noisefilled spectrum */ - , Word16 *coeff_fine /* o : BWE fine structure */ -) -{ - Word16 sfm; - Word16 i; - Word32 normq; - Word16 SWB_signal[L_HARMONIC_EXC]; - Word32 envelope[L_HARMONIC_EXC], L_signal[L_HARMONIC_EXC]; - Word16 enve_lo[L_HARMONIC_EXC], enve_hi[L_HARMONIC_EXC]; - Word16 *src, *dst, *end; - Word16 norm_signal; - - Word16 norm_width = 64; - move16(); - - /* shape the spectrum */ - FOR (sfm = 0; sfm <= last_sfm; sfm++) - { - IF( R[sfm] != 0 ) - { - normq = L_add(0,dicn_fx[norm[sfm]]); - - FOR (i = sfm_start[sfm]; i < sfm_end[sfm]; i++) - { - coeff_out[i] = L_shl(Mult_32_16(normq, coeff[i]),1); /*12 14+12+1+1-16 */ - move32(); - } - } - ELSE - { - FOR (i = sfm_start[sfm]; i < sfm_end[sfm]; i++) - { - coeff_out[i] = L_deposit_l(0); - } - } - } - - /* excitation replication */ - Copy32(coeff_out, L_signal, L_HARMONIC_EXC); - calc_normal_length_fx_32( HQ_CORE, coeff_out, HQ_HARMONIC, -1, &norm_width, prev_L_swb_norm ); - hq_swb_harmonic_calc_norm_envelop_fx( L_signal, envelope, norm_width, L_HARMONIC_EXC ); - - /* Normalize with envelope */ - FOR (i = 0; i < L_HARMONIC_EXC; i++) - { - IF (L_signal[i] > 0) - { - norm_signal = norm_l(envelope[i]); - enve_lo[i] = L_Extract_lc(L_shl(envelope[i], norm_signal), &enve_hi[i]); - L_signal[i] = Div_32(L_signal[i], enve_hi[i], enve_lo[i]); - SWB_signal[i] = round_fx(L_shl(L_signal[i], norm_signal)); - move16(); - move16(); - move32(); - - } - ELSE - { - norm_signal = norm_l(envelope[i]); - enve_lo[i] = L_Extract_lc(L_shl(envelope[i], norm_signal), &enve_hi[i]); - L_signal[i] = L_negate(Div_32(L_negate(L_signal[i]), enve_hi[i], enve_lo[i])); - SWB_signal[i] = round_fx(L_shl(L_signal[i], norm_signal)); - move16(); - move16(); - move32(); - - } - } - - dst = coeff_fine + sfm_end[last_sfm]; - end = coeff_fine + sfm_end[num_sfm-1]; - - IF (sub(sfm_end[last_sfm], sfm_end[high_sfm]) <= L_HARMONIC_EXC - START_EXC ) - { - src = SWB_signal + START_EXC + sub(sfm_end[last_sfm], sfm_end[high_sfm]); - } - ELSE - { - src = SWB_signal + L_HARMONIC_EXC - 1; - } - - WHILE (dst < end) - { - logic32(); - WHILE (dst < end && src < &SWB_signal[L_HARMONIC_EXC]) - { - *dst++ = *src++; - move16(); - } - src --; - - logic32(); - WHILE (dst < end && src >= &SWB_signal[START_EXC]) - { - *dst++ = *src--; - move16(); - } - src++; - } - - return; -} - -/*--------------------------------------------------------------------------* - * hvq_bwe_fine() - * - * Prepare HVQ BWE fine structure - *--------------------------------------------------------------------------*/ - -void hvq_bwe_fine_fx( - const Word16 last_sfm, /* i : last coded subband Q0 */ - const Word16 num_sfm, /* i : total number of bands Q0 */ - const Word16 *sfm_end, /* i : Subband end coefficient Q0 */ - const Word16 *peak_idx, /* i : Peak index Q0 */ - const Word16 Npeaks, /* i : Number of peaks Q0 */ - Word16 *peak_pos, /* o : Peak positions Q0 */ - Word16 *prev_L_swb_norm, /* i/o: last normalize length Q0 */ - Word32 *L_coeff, /* i : coded/noisefilled normalized spectrum Q12 */ - Word16 *bwe_peaks, /* o : Positions of peaks in BWE Q0 */ - Word16 *coeff_fine /* o : HVQ BWE fine structure Q15 */ -) -{ - Word16 i, j; - Word16 SWB_signal[L_HARMONIC_EXC]; - Word32 L_envelope[L_HARMONIC_EXC]; - Word16 *src, *dst, *end; - Word16 *peak_dst, *peak_src; - Word16 norm_width = 64; - Word16 tmp; - Word16 shift, shift2; - Word32 L_tmp; - UWord16 lsb; - - calc_normal_length_fx_32( HQ_CORE, L_coeff, HQ_HVQ, -1, &norm_width, prev_L_swb_norm ); - - hq_swb_harmonic_calc_norm_envelop_fx(L_coeff, L_envelope, norm_width, L_HARMONIC_EXC); - - /* Normalize with envelope */ - FOR (i = 0; i < L_HARMONIC_EXC; i++) - { - /*SWB_signal[i] = SWB_signal[i] / envelope[i]; */ - - shift = norm_l(L_envelope[i]); - tmp = round_fx(L_shl(L_envelope[i], shift)); /* 12+s-16=Q(-4+s) */ - - /* Avoid division by zero */ - if (tmp == 0) - { - tmp = 1<<14; - move16(); - } - - tmp = div_s(1<<14, tmp); /* 15+14-(-4+s)=Q(33-s) */ - Mpy_32_16_ss(L_coeff[i], tmp, &L_tmp, &lsb); /* 12+33-s+1-16=Q(30-s) */ - shift2 = add(shift, 1); - tmp = round_fx(L_shl(L_tmp, shift2)); /* 30-s+s+1-16=Q(15) */ - SWB_signal[i] = add(tmp, lshr(lsb, sub(32, shift2))); - move16(); /* Q15 */ - /*SWB_signal[i] = round_fx(L_shl(L_tmp, add(shift, 1))); // 30-s+s+1-16=Q(15) */ - - } - - dst = coeff_fine; - end = coeff_fine + sfm_end[num_sfm-1] - sfm_end[last_sfm]; - - src = SWB_signal + START_EXC; - peak_src = peak_pos + START_EXC; - - FOR (i = 0; i < Npeaks; i++) - { - if ( sub(peak_idx[i], L_HARMONIC_EXC) < 0 ) - { - peak_pos[peak_idx[i]] = 1; - move16(); - } - } - - i = sub(L_HARMONIC_EXC, 1); - WHILE ( i-- > 0 ) - { - IF ( sub(peak_pos[i], 1) == 0 ) - { - BREAK; - } - } - - if ( sub(i, 180) < 0 ) - { - i = 180; - move16(); - } - - FOR ( j = L_HARMONIC_EXC-1; j > i+1; j-- ) - { - SWB_signal[j] = 0; - move16(); - } - - peak_dst = bwe_peaks + sfm_end[last_sfm]; - WHILE ( dst < end ) - { - test(); - WHILE ( dst < end && src < &SWB_signal[L_HARMONIC_EXC] ) - { - *dst++ = *src++; - move16(); - *peak_dst++ = *peak_src++; - move16(); - } - peak_src--; - src --; - - test(); - WHILE ( dst < end && src >= &SWB_signal[START_EXC] ) - { - *dst++ = *src--; - move16(); - *peak_dst++ = *peak_src--; - move16(); - } - peak_src++; - src++; - } - - return; -} - -/*--------------------------------------------------------------------------* - * hq_fold_bwe_fx() - * - * HQ mode folding BWE - *--------------------------------------------------------------------------*/ - -void hq_fold_bwe_fx( - const Word16 last_sfm, /* i : last coded subband Q0 */ - const Word16 *sfm_end, /* i : Subband end coefficient Q0 */ - const Word16 num_sfm, /* i : Number of subbands Q0 */ - Word16 *coeff /* i/o: coded/noisefilled normalized spectrum Q12 */ -) -{ - Word16 low_coeff; - Word16 first_coeff; - Word16 *src, *dst, *end; - - low_coeff = shr(sfm_end[last_sfm], 1); - src = coeff + sfm_end[last_sfm] - 1; - - first_coeff = sfm_end[last_sfm]; - dst = coeff + sfm_end[last_sfm]; - end = coeff + sfm_end[num_sfm-1]; - - WHILE(dst < end) - { - WHILE(dst < end && src >= &coeff[low_coeff]) - { - *dst++ = *src--; - move16(); - } - - src++; - - WHILE(dst < end && src < &coeff[first_coeff]) - { - *dst++ = *src++; - move16(); - } - } - return; -} - -/*--------------------------------------------------------------------------* - * apply_nf_gain() - * - * Apply noise fill gain - *--------------------------------------------------------------------------*/ - -void apply_nf_gain_fx( - const Word16 nf_idx, /* i : noise fill gain index Q0 */ - const Word16 last_sfm, /* i : last coded subband Q0 */ - const Word16 *R, /* i : bit allocation Q0 */ - const Word16 *sfm_start, /* i : Subband start coefficient Q0 */ - const Word16 *sfm_end, /* i : Subband end coefficient Q0 */ - Word16 *coeff /* i/o: coded/noisefilled normalized spectrum Q12 */ -) -{ - Word16 sfm; - Word16 j; - - FOR (sfm = 0; sfm <= last_sfm; sfm++) - { - IF (R[sfm] == 0) - { - FOR (j = sfm_start[sfm]; j < sfm_end[sfm]; j++) - { - /* Scale NoiseFill */ - coeff[j] = shr(coeff[j], nf_idx); - move16(); - } - } - } - - return; -} - - -/*--------------------------------------------------------------------------* - * harm_bwe_fx() - * - * HQ Harmonic BWE - *--------------------------------------------------------------------------*/ - -void harm_bwe_fx( - const Word16 *coeff_fine, /* i : fine structure for BWE */ - const Word16 *coeff, /* i : coded/noisefilled normalized spectrum */ - const Word16 num_sfm, /* i : Number of subbands */ - const Word16 *sfm_start, /* i : Subband start coefficient */ - const Word16 *sfm_end, /* i : Subband end coefficient */ - const Word16 last_sfm, /* i : last coded subband */ - const Word16 *R, /* i : bit allocation */ - const Word16 prev_hq_mode, /* i : previous hq mode */ - Word16 *norm, /* i/o: quantization indices for norms */ - Word16 *noise_level, /* i/o: noise levels for harmonic modes */ - Word16 *prev_noise_level, /* i/o: noise factor in previous frame */ - Word16 *bwe_seed, /* i/o: random seed for generating BWE input */ - Word32 *coeff_out /* o : coded/noisefilled spectrum */ -) -{ - Word16 i, j; - Word16 sfm, band_width; - Word32 normq, L_tmp,L_tmp2; - Word32 E_L; - Word16 alfa = 16384; - Word16 tmp, tmp1, exp1; - Word16 beta; - Word32 *src, *dst; - - move16(); /* alfa */ - - FOR (sfm = 0; sfm <= last_sfm; sfm++) - { - IF (R[sfm] == 0) - { - normq = dicn_fx[norm[sfm]]; /*Q14 */ move16(); - - FOR (i = sfm_start[sfm]; i < sfm_end[sfm]; i++) - { - coeff_out[i] = L_shl(Mult_32_16(normq, coeff[i]),1); - move32(); /*12 Q(14 +12+1-16 +1) */ - - } - } - } - noise_level[1] = noise_level[0]; - move16(); - - /* shaping the BWE spectrum further by envelopes and noise factors */ - L_tmp = L_mult(29491, prev_noise_level[0]); /* 15 +1 +15 */ - noise_level[0] = round_fx(L_mac(L_tmp, 3277, noise_level[0])); /*15 */ - - L_tmp = L_mult(29491, prev_noise_level[1]); - noise_level[1] = round_fx(L_mac(L_tmp, 3277, noise_level[1])); - - test(); - IF (prev_hq_mode == HQ_NORMAL || sub(prev_hq_mode, HQ_GEN_SWB) == 0) - { - IF (sub(noise_level[0], 8192) < 0) - { - noise_level[0] = shl(noise_level[0], 2); - move16(); - } - - IF (sub(noise_level[1], 8192) < 0) - { - noise_level[1] = shl(noise_level[1], 2); - move16(); - } - } - - FOR (i = add(last_sfm, 1); i < num_sfm; i++) - { - E_L = L_add(0,1); - FOR (j = sfm_start[i]; j < sfm_end[i]; j++) - { - L_tmp =L_mult0(coeff_fine[j], coeff_fine[j]);/*Q30 */ - E_L =L_add(E_L,L_shr(L_tmp,6));/*Q24 */ - } - - normq = L_add(0,dicn_fx[norm[i]]); - - alfa = noise_level[0]; - move16(); - if (sub(i, 27) > 0) - { - alfa = noise_level[1]; - move16(); - } - - band_width = sub(sfm_end[i], sfm_start[i]); /* */ - exp1 =norm_l(E_L); - IF(exp1 ==0) - { - E_L = Mult_32_16(E_L, inv_tbl_fx[band_width]); /* Q24 (24+15+1-16) *//*24+15+1-16 */ - tmp = div_l(E_L,sub(32767,alfa)); /*Q24-15-1 =8 */ - tmp = s_max(1,tmp); - L_tmp =L_deposit_h(tmp); /*24 */ - E_L = Isqrt(L_tmp); /* Q19 (31-24/2) */ - } - ELSE - { - exp1 =sub(exp1,1); - E_L = Mult_32_16(L_shl(E_L,exp1), inv_tbl_fx[band_width]); /* Q24+exp1 (24+exp1+15+1-16) */ - tmp = div_l(E_L,sub(32767,alfa)); /*Q24+exp1-15-1 =8+exp1 */ - tmp = s_max(1,tmp); - L_tmp =L_shl(L_deposit_l(tmp),sub(16,exp1)); /*24 8+exp1+16-exp1 */ - E_L = Isqrt(L_tmp); /* Q19 (31-24/2) */ - } - - exp1 = norm_s(alfa); - tmp1 = shl(alfa, exp1); - exp1 = add(1, exp1); - tmp1 = s_max(tmp1, 16384); - tmp1 = div_s(16384, tmp1); - L_tmp2 = L_deposit_h(tmp1); - L_tmp2 = Isqrt_lc(L_tmp2, &exp1); - beta = round_fx(L_shl(L_tmp2, exp1)); - beta =shr(beta,1); /*Q15 */ - - - FOR(sfm = sfm_start[i]; sfm < sfm_end[i]; sfm++) - { - L_tmp = Mult_32_16(E_L,coeff_fine[sfm]); /*Q19 19 + 15 +1-16 */ - L_tmp = L_shl(L_tmp,9);/*Q28 */ - tmp = Random(bwe_seed); /*Q15 */ - L_tmp2 =L_shr(L_mult(beta,tmp),3);/* Q28 31-3 15+15 +1-3 */ - L_tmp =L_add(L_tmp,L_tmp2);/*Q28 */ - coeff_out[sfm] = L_shl(Mult_32_32(L_tmp, normq),1);/*Q12 28 +14 +1 -31 */ move32(); - } - } - - prev_noise_level[0] = noise_level[0]; - move16(); - prev_noise_level[1] = noise_level[1]; - move16(); - - src = &coeff_out[add(sfm_end[last_sfm], L_HARMONIC_EXC - START_EXC)]; /*Q12 */ - - dst = src-1; - FOR( i = 0; i < 16; i++ ) - { - *src = Mult_32_16(*src, hvq_bwe_fac_fx[i]); /* Q12 (12+15+1-16) */ move32(); - src++; - *dst = Mult_32_16(*dst, hvq_bwe_fac_fx[i]); /* Q12 (12+15+1-16) */ move32(); - dst--; - } - IF(sub(num_sfm, 33) == 0) - { - set32_fx(&coeff_out[800], 0, 160); - } - return; -} - -/*--------------------------------------------------------------------------* - * HVQ_bwe_fx() - * - * HQ HVQ BWE - *--------------------------------------------------------------------------*/ - -void hvq_bwe_fx( - const Word32 *L_coeff, /* i : coded/noisefilled normalized spectrum Q12 */ - const Word16 *coeff_fine, /* i : coded/noisefilled normalized spectrum Qin */ - const Word16 *sfm_start, /* i : Subband start coefficient Q0 */ - const Word16 *sfm_end, /* i : Subband end coefficient Q0 */ - const Word16 *sfm_len, /* i : Subband length Q0 */ - const Word16 last_sfm, /* i : last coded subband Q0 */ - const Word16 prev_hq_mode, /* i : previous hq mode Q0 */ - const Word16 *bwe_peaks, /* i : HVQ bwe peaks Q0 */ - const Word16 bin_th, /* i : HVQ transition bin Q0 */ - const Word16 num_sfm, /* i : Number of bands Q0 */ - const Word32 core_brate, /* i : Core bit-rate Q0 */ - const Word16 *R, /* i : Bit allocation */ - Word16 *norm, /* i/o: quantization indices for norms Q0 */ - Word16 *noise_level, /* i/o: noise levels for harmonic modes Q15 */ - Word16 *prev_noise_level, /* i/o: noise factor in previous frame Q15 */ - Word16 *bwe_seed, /* i/o: random seed for generating BWE input Q0 */ - Word32 *L_coeff_out, /* o : coded/noisefilled spectrum Qout*/ - const Word16 qin, - const Word16 qout -) -{ - Word16 i, j; - Word16 N; - Word32 L_normq; - Word32 L_E; - Word32 L_tmp_norm = 0; - Word16 bwe_noise_th = 0; - Word16 peak_band, low, high, sel_norm; - Word16 norm_ind; - Word32 *L_src, *L_dst; - Word16 istart, iend; - Word16 offset = sfm_end[last_sfm]; - - /* Fx specific variables */ - Word32 L_tmp0, L_tmp1; - Word16 tmp, tmp2, band_size; - Word16 last_norm_ind; - Word16 shift, power_shift; - Word16 coeff_s[L_FRAME48k]; - Word16 j_N; - Word16 n_c; - UWord16 lsb; - - move32(); /* L_tmp_norm */ - move16(); /* bwe_noise_th */ - - bwe_noise_th = add(bin_th, shr(sub(sfm_end[sub(num_sfm,1)], bin_th),1)); - logqnorm_fx(&L_coeff_out[sfm_start[last_sfm]], qout, &norm[last_sfm], 40, sfm_len[last_sfm], 0); - move16(); - - /* shaping the BWE spectrum further by envelopes and noise factors */ - noise_level[0] = round_fx(L_mac(L_mult(29491,prev_noise_level[0]),3277,noise_level[0])); /* Q15 (15+15+1-16) */ - noise_level[1] = round_fx(L_mac(L_mult(29491,prev_noise_level[1]),3277,noise_level[1])); /* Q15 (15+15+1-16) */ - - test(); - IF (prev_hq_mode == HQ_NORMAL || sub(prev_hq_mode, HQ_GEN_SWB) == 0) - { - IF( sub(noise_level[0], 8192 /* 0.25f */) < 0 ) - { - noise_level[0] = shl(noise_level[0], 2); - move16(); - } - - IF( sub(noise_level[1], 8192 /* 0.25f */) < 0 ) - { - noise_level[1] = shl(noise_level[1], 2); - move16(); - } - } - - norm_ind = add(last_sfm, 1); - IF ( L_sub(core_brate, HQ_24k40) == 0 ) - { - peak_band = 0; - move16(); - - tmp = 1; - move16(); - FOR (i = sfm_start[norm_ind]; i < sfm_end[norm_ind+1]; i++) - { - tmp2 = abs_s(coeff_fine[i-offset]); - tmp = s_max(tmp, tmp2); - } - band_size = sub(sfm_end[norm_ind+1], sfm_start[norm_ind]); - - /* Headroom for square and accumulate */ - shift = sub(norm_s(tmp), sqac_headroom_fx[band_size]); - L_E = L_deposit_l(1); - FOR (i = sfm_start[norm_ind]; i < sfm_end[norm_ind+1]; i++) - { - if (bwe_peaks[i]) - { - peak_band = 1; - move16(); - } - /* E_L += coeff_fine[i-offset] * coeff_fine[i-offset]; */ - coeff_s[i] = shl(coeff_fine[i-offset], shift); - move16();/* Q15 + shift */ - L_E = L_mac0(L_E, coeff_s[i], coeff_s[i]); /* Q2*(qin + shift) */ - } - power_shift = shl(shift, 1); - - L_E = L_shr(L_E,sub(power_shift,28-2*qin)); /* Q28 */ - - /* E_L = (float)sqrt((sfm_end[norm_ind+1] - sfm_start[norm_ind])/E_L); */ - L_E = Mult_32_16(L_E, inv_tbl_fx[band_size]); /* Q28 (28+15+1-16) */ - /* To avoid overflow in Isqrt() */ - if( L_E == 0 ) - { - L_E = L_deposit_l(1); - } - L_E = Isqrt(L_E); /* Q17 (31-28/2) */ - - /* normq = 0.1f*dicn[norm[norm_ind-1]] + 0.8f*dicn[norm[norm_ind]] + 0.1f*dicn[norm[norm_ind+1]]; */ - /* tmp_norm = 0.1f*dicn[norm[norm_ind]] + 0.8f*dicn[norm[norm_ind+1]] + 0.1f*dicn[norm[norm_ind+2]]; */ - L_tmp0 = L_add(dicn_fx[norm[norm_ind]], 0); - L_tmp1 = L_add(dicn_fx[norm[norm_ind+1]], 0); - L_normq = Madd_32_16(Madd_32_16(Mult_32_16(L_tmp0, 26214 /* Q15, 0.8f */), dicn_fx[norm[norm_ind-1]], 3277 /* Q15, 0.1f */), L_tmp1, 3277 /* Q15, 0.1f */); /* Q14 (14+15+1-16) */ move16(); - L_tmp_norm = Madd_32_16(Madd_32_16(Mult_32_16(L_tmp1, 26214 /* Q15, 0.8f */), dicn_fx[norm[norm_ind+2]], 3277 /* Q15, 0.1f */), L_tmp0, 3277 /* Q15, 0.1f */); /* Q14 (14+15+1-16) */ move16(); - - istart = sfm_start[norm_ind]; - move16(); - /* iend = istart + sfm_len[norm_ind]/2; */ - iend = 240; - move16(); - - noise_mix_fx( &coeff_fine[-offset], L_E, L_normq, bwe_seed, istart, iend, noise_level[0], L_coeff_out, qin, qout); - - j = 0; - move16(); - /* N = sfm_len[norm_ind]/2+sfm_len[norm_ind+1]/2-1; */ - N = 31; - move16(); - j_N = N; - move16(); - - istart = iend; - move16(); - /* iend = sfm_start[norm_ind+1] + sfm_len[norm_ind+1]/2; */ - iend = 272; - move16(); - - /* special case that is not handled by noise_mix_fx() */ - n_c = sub(MAX_16,noise_level[0]); /* Q15 */ - FOR (i = istart; i < iend; i++) - { - /* coeff_out[i] = ((float)(N-j)/N*normq + (float)j/N*tmp_norm)*((1.0f - noise_level[i/bwe_noise_th])*coeff_fine[i-offset]*E_L + noise_level[i/bwe_noise_th]*own_random(bwe_seed)/32768.0f); */ - L_tmp1 = Madd_32_16(Mult_32_16(L_normq, inv_N_fx[j_N] ), L_tmp_norm, inv_N_fx[j]); /* Q14 (14+15+1-16) */ - j = add(j,1); - j_N = sub(j_N,1); - - Mpy_32_16_ss(L_E, coeff_fine[i-offset], &L_tmp0, &lsb); /* Qin+2 (17+qin+1-16) */ - Mpy_32_16_ss(L_tmp0, n_c, &L_tmp0, &lsb); /* Qin+2-15 (qin+2+15+1-16) */ - - IF(L_tmp0 != 0) - { - /* Normalize with 1 bit headroom for addition */ - tmp = 30-(qin+2); /* Assuming fixed Q values */ - tmp = s_min(norm_l(L_tmp0), tmp); - tmp = sub(tmp,1); - - L_tmp0 = L_add(L_shl(L_tmp0,tmp), L_deposit_l(lshr(lsb, sub(16,tmp)))); /* Qin+2+tmp */ - - L_tmp0 = L_add(L_tmp0, L_shr(L_mult0(noise_level[0], Random(bwe_seed)), sub(30-(qin+2), tmp))); /* Qin+2+tmp */ - tmp = round_fx(L_shl(L_tmp0,27-(qin+2)-tmp)); /* Q11 (Qin+2+tmp+27-qin-2-tmp-16) */ - - Mpy_32_16_ss(L_tmp1, tmp, &L_tmp0, &lsb); /* Q10 (14+11+1-16) */ - L_coeff_out[i] = L_add(L_shl(L_tmp0,qout-10), L_deposit_l(lshr(lsb, 10+16-qout))); - move32(); /* Qout (10+qout-10) */ - } - ELSE - { - L_tmp0 = L_mult0(noise_level[0], Random(bwe_seed)); /* Q30 (15+15) */ - tmp = round_fx(L_tmp0); /* Q14 (30-16) */ - Mpy_32_16_ss(L_tmp1, tmp, &L_tmp0, &lsb); /* Q13 (14+14+1-16) */ - L_coeff_out[i] = L_shr(L_tmp0,13-qout); - move32();/* Qout (13-(13-qout)) */ - } - } - - istart = iend; - move16(); - iend = sfm_end[norm_ind+1]; - move16(); - - noise_mix_fx( &coeff_fine[-offset], L_E, L_tmp_norm, bwe_seed, istart, iend, noise_level[0], L_coeff_out, qin, qout); - - norm_ind = add(norm_ind, 2); - } - - FOR ( ; norm_ind < num_sfm; norm_ind++) - { - IF ( R[norm_ind] == 0 ) - { - peak_band = 0; - move16(); - - FOR (i = sfm_start[norm_ind]; i < sfm_end[norm_ind]; i++) - { - if (bwe_peaks[i]) - { - peak_band = 1; - move16(); - } - } - - istart = sfm_start[norm_ind]; - move16(); - iend = sfm_end[norm_ind]; - move16(); - - last_norm_ind = sub(num_sfm, 1); - test(); - test(); - IF ( sub(peak_band, 1) == 0 && sub(norm_ind,add(last_sfm, 1)) > 0 && sub(norm_ind, last_norm_ind) < 0 ) - { - istart = sub(istart, shr(sfm_len[norm_ind-1],1)); - iend = add(iend, shr(sfm_len[norm_ind+1],1)); - } - - tmp = 1; - move16(); - FOR (i = istart; i < iend; i++) - { - tmp2 = abs_s(coeff_fine[i-offset]); - tmp = s_max(tmp, tmp2); - } - band_size = sub(iend, istart); - /* Headroom for square and accumulate */ - shift = sub(norm_s(tmp), sqac_headroom_fx[band_size]); - - L_E = L_add(0,1L); - FOR (i = istart; i < iend; i++) - { - /* E_L += coeff_fine[i-offset] * coeff_fine[i-offset]; */ - coeff_s[i] = shl(coeff_fine[i-offset], shift); - move16();/* Q15 + shift */ - L_E = L_mac0(L_E, coeff_s[i], coeff_s[i]); /* Q2*(15 + shift) */ - } - power_shift = shl(shift, 1); - - L_E = L_shr(L_E,sub(power_shift,28-2*qin)); /* Q28 */ - - /* E_L = (float)sqrt((iend - istart)/E_L); */ - L_E = Mult_32_16(L_E, inv_tbl_fx[band_size]); /* Q28 (28+15+1-16) */ - /* To avoid overflow in Isqrt() */ - if( L_E == 0 ) - { - L_E = L_add(1L,0); - } - L_E = Isqrt(L_E); /* Q17 (31-28/2) */ - - IF ( peak_band ) - { - IF ( sub(add(norm_ind,2), num_sfm) > 0 ) - { - /* normq = 0.15f*dicn[norm[norm_ind-1]] + 0.85f*dicn[norm[norm_ind]]; */ - L_normq = Madd_32_16(Mult_32_16(dicn_fx[norm[norm_ind]], 27853 /* Q15, 0.85f */), dicn_fx[norm[norm_ind-1]], 4915 /* Q15, 0.1f */); /* Q14 (14+15+1-16) */ move16(); - move16(); - } - ELSE - { - /* normq = 0.1f*dicn[norm[norm_ind-1]] + 0.8f*dicn[norm[norm_ind]] + 0.1f*dicn[norm[norm_ind+1]]; */ - L_normq = Madd_32_16(Madd_32_16(Mult_32_16(dicn_fx[norm[norm_ind]], 26214 /* Q15, 0.8f */), dicn_fx[norm[norm_ind+1]], 3277 /* Q15, 0.1f */), dicn_fx[norm[norm_ind-1]], 3277 /* Q15, 0.1f */); /* Q14 (14+15+1-16) */ move16(); - move16(); - move16(); - } - } - ELSE - { - low = norm_ind; - move16(); - high = s_min(add(norm_ind,1), last_norm_ind); - move16(); - sel_norm = norm[norm_ind-1]; - move16(); - FOR (j = low; j <= high; j++) - { - if ( sub(norm[j], sel_norm) > 0 ) - { - sel_norm = norm[j]; - move16(); - } - } - L_normq = dicn_fx[sel_norm]; - move16(); - } - - iend = s_min(sfm_end[norm_ind], bwe_noise_th); - move16(); - IF( sub(iend, sfm_start[norm_ind]) > 0 ) - { - noise_mix_fx( &coeff_fine[-offset], L_E, L_normq, bwe_seed, sfm_start[norm_ind], iend, noise_level[0], L_coeff_out, qin, qout); - } - ELSE - { - iend = sfm_end[norm_ind]; - move16(); - noise_mix_fx( &coeff_fine[-offset], L_E, L_normq, bwe_seed, sfm_start[norm_ind], iend, noise_level[1], L_coeff_out, qin, qout); - } - /* Noisemix up to threshold done */ - IF( sub(iend, bwe_noise_th) == 0 ) - { - noise_mix_fx( &coeff_fine[-offset], L_E, L_normq, bwe_seed, iend, sfm_end[norm_ind], noise_level[1], L_coeff_out, qin, qout); - } - - } - ELSE /* R[norm_ind] > 0 */ - { - FOR (i = sfm_start[norm_ind]; i < sfm_end[norm_ind]; i++) - { - L_coeff_out[i] = L_coeff[i]; /* Scaling already applied */ move32(); - } - } - } - - prev_noise_level[0] = noise_level[0]; - move16(); - prev_noise_level[1] = noise_level[1]; - move16(); - L_src = &L_coeff_out[add(sfm_end[last_sfm], L_HARMONIC_EXC - START_EXC)]; /* Address initialization */ - L_dst = L_src - 1 ; /* Address computation */ - - FOR( i = 0; i < 16; i++ ) - { - *L_src = Mult_32_16(*L_src, hvq_bwe_fac_fx[i]); - L_src++; /* Qout (Qout+15+1-16) */ move32(); - *L_dst = Mult_32_16(*L_dst, hvq_bwe_fac_fx[i]); - L_dst--; /* Qout (Qout+15+1-16) */ move32(); - } - - return; -} - -/*-------------------------------------------------------------------* -* hvq_concat_bands_fx() -* -* Compute the band limits for concatenated bands for PVQ target signal in HVQ -*--------------------------------------------------------------------------*/ -void hvq_concat_bands_fx -( - const Word16 pvq_bands, /* i : Number of bands in concatenated PVQ target */ - const Word16 *sel_bnds, /* i : Array of selected high bands */ - const Word16 n_sel_bnds, /* i : Number of selected high bands */ - Word16 *hvq_band_start, /* i : Band start indices */ - Word16 *hvq_band_width, /* i : Band widths */ - Word16 *hvq_band_end /* i : Band end indices */ -) -{ - Word16 k, k_1; - const Word16 *pSelBnds; - - pSelBnds = sel_bnds; - FOR (k = 0; k < pvq_bands; k++) - { - - IF( sub(k, sub(pvq_bands, n_sel_bnds)) >= 0) - { - k_1 = sub(k, 1); - hvq_band_start[k] = hvq_band_end[k_1]; - move16(); - hvq_band_width[k] = band_len_harm[*pSelBnds++]; - move16(); - move16(); - hvq_band_end[k] = add(hvq_band_end[k_1], hvq_band_width[k]); - move16(); - } - ELSE - { - hvq_band_start[k] = extract_l(L_mult0(k, HVQ_PVQ_COEFS)); - hvq_band_width[k] = HVQ_PVQ_COEFS; - move16(); - hvq_band_end[k] = add(hvq_band_start[k], HVQ_PVQ_COEFS); - move16(); - } - } - - return; -} -/*--------------------------------------------------------------------------* - * noise_mix_fx() - *--------------------------------------------------------------------------*/ - -void noise_mix_fx( - const Word16 *coeff_fine, /* i : normalized fine structure spectrum Qin */ - const Word32 L_E, /* i : normalization factor Q17 */ - const Word32 L_normq, /* i : quantized norm Q14 */ - Word16 *seed, /* i/o: random seed Q0 */ - const Word16 istart, /* i : start coefficient Q0 */ - const Word16 iend, /* i : end coefficient Q0 */ - const Word16 noise_level, /* i : noise_level Q0 */ - Word32 *L_coeff_out, /* o : noise mixed spectrum Qout */ - const Word16 qin, - const Word16 qout -) -{ - Word16 i, tmp, n_c; - Word32 L_tmp0; - UWord16 lsb; - - n_c = sub(MAX_16,noise_level); /* Q15 */ - FOR (i = istart; i < iend; i++) - { - /* L_coeff_out[i] = ((1.0f - noise_level)*coeff_fine[i]*L_E + noise_level*own_random(seed)/32768.0f)*normq; */ - Mpy_32_16_ss(L_E, coeff_fine[i], &L_tmp0, &lsb); /* Qin+qL_E-15 (qL_E+qin+1-16) */ - Mpy_32_16_ss(L_tmp0, n_c, &L_tmp0, &lsb); /* Qin+qL_E-15 (qin+qL_E-15+15+1-16) */ - - IF(L_tmp0 != 0) - { - /* Normalize with 1 bit headroom for addition */ - tmp = 30-(qin+2); /* Assuming fixed Q values */ - tmp = s_min(norm_l(L_tmp0), tmp); - tmp = sub(tmp,1); - - L_tmp0 = L_add(L_shl(L_tmp0,tmp), L_deposit_l(lshr(lsb, sub(16,tmp)))); /* Qin+2+tmp */ - L_tmp0 = L_add(L_tmp0, L_shr(L_mult0(noise_level, Random(seed)), sub(30-(qin+2), tmp))); /* Qin+2+tmp */ - - tmp = round_fx(L_shl(L_tmp0,27-(qin+2)-tmp)); /* Q11 (Qin+2+tmp+27-qin-2-tmp-16) */ - Mpy_32_16_ss(L_normq, tmp, &L_tmp0, &lsb); /* Q10 (14+11+1-16) */ - L_coeff_out[i] = L_add(L_shl(L_tmp0,qout-10), L_deposit_l(lshr(lsb, 10+16-qout))); - move32();/* Qout (10+qout-10) */ - } - ELSE - { - L_tmp0 = L_mult0(noise_level, Random(seed)); /* Q30 (15+15) */ - tmp = round_fx(L_tmp0); /* Q14 (30-16) */ - Mpy_32_16_ss(L_normq, tmp, &L_tmp0, &lsb); /* Q13 (14+14+1-16) */ - L_coeff_out[i] = L_shr(L_tmp0,13-qout); - move32();/* Qout (13-(13-qout)) */ - } - } -} - - -/*--------------------------------------------------------------------------* - * hq_generic_fine_fx() - * - * Prepare HQ GENERIC HF fine structure - *--------------------------------------------------------------------------*/ -void hq_generic_fine_fx( - Word16 *coeff, /* i : coded/noisefilled normalized spectrum */ - const Word16 last_sfm, /* i : Last coded band */ - const Word16 *sfm_start, /* i : Subband start coefficient */ - const Word16 *sfm_end, /* i : Subband end coefficient */ - Word16 *bwe_seed, /* i/o: random seed for generating BWE input */ - Word16 *coeff_out1 /* o : HQ GENERIC input */ -) -{ - Word16 sfm; - Word16 i; - - FOR (sfm = 0; sfm <= last_sfm; sfm++) - { - FOR (i = sfm_start[sfm]; i < sfm_end[sfm]; i++) - { - IF (coeff[i]==0) - { - coeff_out1[i] = -2048; - move16(); - if (Random(bwe_seed) > 0) - { - coeff_out1[i] = 2048; - move16(); - } - } - ELSE - { - coeff_out1[i] = coeff[i]; - move16(); - } - } - } - - return; -} - -/*--------------------------------------------------------------------------* - * overlap_hq_bwe_fx() - * - * Overlapping at the boundary between HQ core and BWE - *--------------------------------------------------------------------------*/ -static void overlap_hq_bwe_fx( - const Word32 *hq_swb_overlap_buf, /* i : spectrum from HQ core */ - Word32 *coeff_out, /* i/o: spectrum from BWE, overlapped output */ - const Word16 n_swb_overlap_offset, /* i : starting offset of overlapping */ - const Word16 n_swb_overlap, /* i : length of overlapping */ - const Word16 *R, - const Word16 num_env_bands, - const Word16 num_sfm, - const Word16 *sfm_end -) -{ - Word16 i; - Word16 weighting; - Word16 step; - Word16 exp, tmp, n_band; - - IF ( R[sub(num_env_bands,1)] != 0) - { - Copy32( hq_swb_overlap_buf, &coeff_out[n_swb_overlap_offset], n_swb_overlap ); - } - ELSE - { - exp = norm_s(n_swb_overlap); - tmp = div_s(16384, shl(n_swb_overlap, exp));/*15 + 14 - exp */ - tmp = shr(tmp, sub(14, exp));/*15 */ - step = mult_r(tmp, 32767);/*15 */ - weighting = 32767; - move16(); - FOR (i = 0; i < n_swb_overlap; i++) - { - coeff_out[add(n_swb_overlap_offset,i)] = L_add(coeff_out[add(n_swb_overlap_offset,i)], - Mult_32_16(L_sub(hq_swb_overlap_buf[i], coeff_out[add(n_swb_overlap_offset,i)]), weighting)); - move32(); - weighting = sub(weighting, step); - } - } - - FOR (n_band = num_env_bands; n_band < num_sfm; n_band++) - { - IF (R[n_band] !=0 ) - { - FOR(i=sfm_end[sub(n_band,1)]; i0) - { - i=sub(nb_sfm,1); - WHILE(b_add_bits_denv>0 && i>=0) - { - IF ( sub(Rsubband[i], 24)>0) - { - Rsubband[i] = sub(Rsubband[i] , 8); - move16(); - b_add_bits_denv = sub(b_add_bits_denv,1); - } - i = sub(i,1); - } - } - - return; -} - -Word16 get_nor_delta_hf_fx( - Decoder_State_fx *st, - Word16 *ynrm, - Word16 *Rsubband, /* Q3 */ - const Word16 num_env_bands, - const Word16 nb_sfm, - const Word16 core_sfm -) -{ - Word16 i; - Word16 delta,bitsforDelta,add_bits_denv; - - add_bits_denv = 0; - move16(); - IF (sub(core_sfm ,num_env_bands) >= 0) - { - bitsforDelta = (Word16)get_next_indice_fx(st,2); - bitsforDelta = add(bitsforDelta, 2); - add_bits_denv = add(add_bits_denv,2); - - FOR(i=num_env_bands; i 0 ) - { - ynrm[i] = 39; - move16(); - st->BER_detect = 1; - move16(); - } - /*ynrm[i] += delta - (1<<(bitsforDelta-1));*/ - add_bits_denv = add(add_bits_denv,bitsforDelta); - } - } - update_rsubband_fx(nb_sfm, Rsubband,add_bits_denv); - } - return add_bits_denv; -} - -Word16 calc_nor_delta_hf_fx( - Encoder_State_fx *st, - const Word32 *t_audio, - Word16 *ynrm, - Word16 *Rsubband, - const Word16 num_env_bands, - const Word16 nb_sfm, - const Word16 *sfmsize, - const Word16 *sfm_start, - const Word16 core_sfm -) -{ - Word16 i; - Word16 ynrm_t[44],normqlg2_t[44]; - Word16 delta,max_delta,min_delta,bitsforDelta,add_bits_denv; - Word16 temp_num; - - temp_num=0; - move16(); - - max_delta=-100; - move16(); - calc_norm_fx( t_audio, 12, ynrm_t, normqlg2_t, 0, nb_sfm, sfmsize, sfm_start ); - add_bits_denv = 0; - move16(); - FOR(i=num_env_bands; i 0) - { - delta = add(delta,1); - } - ELSE - { - delta = negate(delta); - } - if (sub(delta,max_delta)>0) - { - max_delta = delta; - move16(); - } - } - } - IF (sub(core_sfm ,num_env_bands)>= 0) - { - IF (sub(max_delta, 16) < 0) - { - bitsforDelta = 2; - move16(); - FOR( ; max_delta >= 2; max_delta >>= 1 ) - { - bitsforDelta = add(bitsforDelta,1); - } - } - ELSE - { - bitsforDelta = 5; - move16(); - } - max_delta = sub( shl(1, sub(bitsforDelta,1)), 1); - min_delta = negate(add(max_delta,1)); - - /* updating norm & storing delta norm */ - add_bits_denv = 2; - move16(); - push_indice_fx( st, IND_DELTA_ENV_HQ, sub(bitsforDelta,2) , 2 ); - FOR(i=num_env_bands; i 0) - { - delta = max_delta; - move16(); - } - ELSE if (sub(delta , min_delta) < 0) - { - delta = min_delta; - move16(); - } - push_indice_fx( st, IND_DELTA_ENV_HQ, delta - min_delta , bitsforDelta ); - ynrm[i] = add(ynrm[i], delta); - move16(); - add_bits_denv = add(add_bits_denv, bitsforDelta); - - - temp_num = add(temp_num,1); - } - } - - /* updating bit allocation */ - update_rsubband_fx(nb_sfm, Rsubband,add_bits_denv); - } - return add_bits_denv; -} - - -/*-------------------------------------------------------------------* -* hq_bwe_fx() -* -* HQ GENERIC -*--------------------------------------------------------------------------*/ -void hq_bwe_fx( - const Word16 HQ_mode, /* i : HQ mode */ - Word32 *coeff_out1, /* i/o: BWE input & temporary buffer */ - const Word16 *hq_generic_fenv, /* i : SWB frequency envelopes */ - Word32 *coeff_out, /* o : SWB signal in MDCT domain */ - const Word16 hq_generic_offset, /* i : frequency offset for representing hq swb bwe*/ - Word16 *prev_L_swb_norm, /*i/o : last normalize length */ - const Word16 hq_generic_exc_clas, /* i : bwe excitation class */ - const Word16 *sfm_end, /* i : End of bands */ - const Word16 num_sfm, - const Word16 num_env_bands, - const Word16 *R -) -{ - Word16 n_swb_overlap_offset, n_swb_overlap; - Word32 hq_swb_overlap_buf_fx[L_FRAME32k]; - - n_swb_overlap_offset = add(swb_bwe_subband_fx[0] , hq_generic_offset); - n_swb_overlap = sub(sfm_end[sub(num_env_bands,1)] , n_swb_overlap_offset); - - - Copy32(&coeff_out[n_swb_overlap_offset], hq_swb_overlap_buf_fx, sub(add(n_swb_overlap , sfm_end[sub(num_sfm,1)]) , sfm_end[sub(num_env_bands,1)] )); - - hq_generic_decoding_fx(HQ_mode, coeff_out1, hq_generic_fenv, coeff_out, hq_generic_offset, prev_L_swb_norm, hq_generic_exc_clas, R); - - overlap_hq_bwe_fx( hq_swb_overlap_buf_fx, coeff_out, n_swb_overlap_offset, n_swb_overlap, R, num_env_bands, num_sfm, sfm_end ); - - return; -} - -/*--------------------------------------------------------------------------* - * hq_wb_nf_bwe() - * - * HQ WB noisefill and BWE - *--------------------------------------------------------------------------*/ - -void hq_wb_nf_bwe_fx( - const Word16 *coeff_fx, /* i : coded/noisefilled normalized spectrum */ - const Word16 is_transient, - const Word16 prev_bfi, /* i : previous bad frame indicator */ - const Word32 *L_normq_v, - const Word16 num_sfm, /* i : Number of subbands */ - const Word16 *sfm_start, /* i : Subband start coefficient */ - const Word16 *sfm_end, /* i : Subband end coefficient */ - const Word16 *sfmsize, /* i : Subband band width */ - const Word16 last_sfm, /* i : last coded subband */ - const Word16 *R, /* i : bit allocation */ - const Word16 prev_is_transient, /* i : previous transient flag */ - Word32 *prev_normq_fx, /* i/o: previous norms */ - Word32 *prev_env_fx, /* i/o: previous noise envelopes */ - Word16 *bwe_seed, /* i/o: random seed for generating BWE input */ - Word32 *prev_coeff_out_fx, /* i/o: decoded spectrum in previous frame */ - Word16 *prev_R, /* i/o: bit allocation info. in previous frame */ - Word32 *L_coeff_out, /* o : coded/noisefilled spectrum */ - Word16 *prev_env_Q -) -{ - Word16 i; - Word16 sfm; - Word16 total_bit; - Word16 num; - Word32 env_fx,peak_fx,fabs_coeff_out_fx,min_coef_fx; - Word32 L_tmp1,L_tmp2=0,L_tmp3,L_tmp4; - Word16 tmp1,exp=0,exp1,exp2,exp3,harm_para_fx,sharp_fx,step_fx,alfa_fx = 4096; - Word32 avrg_norm_fx,prev_avrg_norm_fx; - Word16 bitalloc_var_fx; - Word16 tmp; - Word32 L_tmp; - Word32 mean_fx; - - IF( is_transient == 0 ) - { - IF( sub(prev_bfi, 1) == 0) - { - Copy32(L_normq_v,prev_normq_fx,SFM_N_WB); - } - - /* the variance of bit allocation */ - total_bit = 0; - bitalloc_var_fx = 0; - FOR (sfm = 8; sfm <= last_sfm; sfm++) - { - tmp = abs_s(sub(R[sfm],R[sub(sfm,1)])); - bitalloc_var_fx = add(bitalloc_var_fx,tmp); - total_bit = add(total_bit,R[sfm]); - } - test(); - IF(sub(last_sfm,8) > 0 && total_bit > 0) - { - exp = norm_s(total_bit); - tmp = shl(total_bit,exp);/*Q(exp) */ - tmp = div_s(16384,tmp);/*Q(15+14-exp) */ - L_tmp = L_mult(tmp, bitalloc_var_fx); /*Q(29-exp+1) */ - bitalloc_var_fx = round_fx(L_shl(L_tmp,exp));/*Q14 */ - } - ELSE - { - bitalloc_var_fx = 0; /*Q14 */ - } - /* calculate the peak-average ratio of saturable subbands */ - num = 0; - sharp_fx = 0; - FOR(sfm = last_sfm; sfm >= 8; sfm--) - { - tmp = shl(sfmsize[sfm], 9);/*Q9 */ - tmp = mult( rat_fx[sfm],tmp );/*Q(14+9-15=8) */ - IF(sub(shl(R[sfm],8),tmp) >= 0) - { - peak_fx = 0; - move16(); - mean_fx = 0; - move16(); - FOR( i = sfm_start[sfm]; i < sfm_end[sfm]; i++ ) - { - fabs_coeff_out_fx = L_abs(L_coeff_out[i]); - mean_fx = L_add(mean_fx, fabs_coeff_out_fx);/*Q12 */ - if(L_sub(fabs_coeff_out_fx, peak_fx) > 0) - { - peak_fx = L_add(fabs_coeff_out_fx,0);/*Q12 */ - } - } - - IF(mean_fx != 0) - { - exp = norm_l(mean_fx); - mean_fx = L_shl(mean_fx, exp);/*Q(exp+12) */ - tmp = round_fx(mean_fx);/*Q(exp-4) */ - tmp = div_s(16384,tmp); /*Q(15+14-exp+4 = 33-exp) */ - L_tmp = Mult_32_16(peak_fx, tmp);/*Q(12+33-exp-15 = 30-exp) */ - tmp = shl(sfmsize[sfm], 9);/*Q9 */ - L_tmp = Mult_32_16(L_tmp, tmp);/*Q(30-exp+9-15 = 24-exp) */ - tmp = round_fx(L_shl(L_tmp,exp));/*Q8 */ - sharp_fx = add(sharp_fx,tmp); - } - num = add(num,1); - } - } - test(); - IF(num != 0 && sharp_fx != 0) - { - num = add(num,num); - exp = norm_s(sharp_fx); - sharp_fx = shl(sharp_fx,exp);/*Q(8+exp) */ - tmp = div_s(16384,sharp_fx);/*Q(21-exp) */ - L_tmp = L_mult(num,tmp);/*Q(22-exp) */ - sharp_fx = round_fx(L_shl(L_tmp,add(8,exp)));/*Q14 */ - } - ELSE - { - sharp_fx = 16384; - move16();/*Q14 = 1 */ - } - harm_para_fx = sharp_fx; - move16();/*Q14 */ - - IF(last_sfm == 0) - { - tmp = 0; - move16(); - } - ELSE - { - tmp = div_s(1,last_sfm);/*Q15 */ - } - - L_tmp = L_mult(5,sharp_fx);/*Q15 */ - L_tmp = Mult_32_16(L_tmp,tmp);/*Q15 */ - step_fx = round_fx(L_shl(L_tmp,16));/*Q15 */ - alfa_fx = 20480; - move16();/*Q13 = 2.5 */ - /* fill noise for the insaturable subbands */ - FOR( sfm = 0; sfm < num_sfm; sfm++ ) - { - env_fx = L_deposit_l(0); - L_tmp2 =L_deposit_l(0); - exp = 0; - move16(); - test(); - IF(R[sfm] != 0 && sub(R[sfm], shl(mult(24756,sfmsize[sfm]),1)) < 0) - { - /* calculate the energy of the undecoded coefficients */ - env_fx =L_deposit_l(0); - exp1=norm_l(L_normq_v[sfm]); - L_tmp4 = L_shl(L_normq_v[sfm],exp1); /*14+exp1 */ - L_tmp1 = Mult_32_32(L_tmp4,L_tmp4); /*2*exp1-3 14+exp1+14+exp1 -31 */ - L_tmp2 =L_deposit_l(0); - peak_fx = L_deposit_l(0); - min_coef_fx = L_add(0,0x7fffffff); - - FOR (i = sfm_start[sfm]; i < sfm_end[sfm]; i++) - { - fabs_coeff_out_fx = L_abs(L_coeff_out[i]); - test(); - if(L_sub(fabs_coeff_out_fx, min_coef_fx)<0 && L_coeff_out[i] != 0) - { - min_coef_fx = L_add(0,fabs_coeff_out_fx); - } - if(L_sub(fabs_coeff_out_fx,peak_fx) > 0) - { - peak_fx = L_add(0,fabs_coeff_out_fx); - } - } - - exp2 =norm_l(peak_fx); - FOR (i = sfm_start[sfm]; i < sfm_end[sfm]; i++) - { - L_tmp4 = L_shl(L_coeff_out[i],exp2); /*12+exp2 */ - L_tmp3 = L_shr(Mult_32_32(L_tmp4,L_tmp4),4);/*2*exp2-7-4 12+exp2+12+exp2-31-4 */ - L_tmp2 = L_add(L_tmp2 ,L_tmp3); /*2*exp2-11 */ - } - - tmp1 =div_s(1,sfmsize[sfm]); /*15 */ - L_tmp4 = Mult_32_16(L_tmp2,tmp1);/*2*exp2-11 2*exp2-7+15+1-16 */ - - exp =norm_l(L_tmp1); - L_tmp1 = L_shl(L_tmp1,exp);/*exp + 2*exp1 - 3 */ - exp1 =sub(add(exp,shl(exp1,1)),3); - - exp =norm_l(L_tmp4); - L_tmp4 = L_shl(L_tmp4,exp);/*exp + 2*exp1 - 3 */ - exp2 =sub(add(exp,shl(exp2,1)),11); - exp = s_min(exp1,exp2); - - L_tmp1 = L_shl(L_tmp1,sub(exp,exp1)); - L_tmp4 = L_shl(L_tmp4,sub(exp,exp2)); - env_fx= L_sub(L_tmp1,L_tmp4); /*exp */ - exp1 = norm_l(env_fx); - env_fx = L_shl(env_fx,exp1);/*exp + exp1 */ - exp =add(exp,exp1); - - IF (env_fx > 0 ) - { - IF(sfm == 0) - { - avrg_norm_fx = L_add(L_shr(L_normq_v[0],1),L_shr(L_normq_v[1],1));/*13 */ - avrg_norm_fx = L_add(avrg_norm_fx,L_shr(L_normq_v[2],1));/*13 */ - prev_avrg_norm_fx = L_add(L_shr(prev_normq_fx[0],1),L_shr(prev_normq_fx[1],1));/*13 */ - prev_avrg_norm_fx = L_add(prev_avrg_norm_fx,L_shr(prev_normq_fx[2],1));/*13 */ - } - ELSE IF (sub(sfm,25) == 0) - { - avrg_norm_fx = L_add(L_shr(L_normq_v[23],1),L_shr(L_normq_v[24],1));/*13 */ - avrg_norm_fx = L_add(avrg_norm_fx,L_shr(L_normq_v[25],1));/*13 */ - prev_avrg_norm_fx = L_add(L_shr(prev_normq_fx[23],1),L_shr(prev_normq_fx[24],1));/*13 */ - prev_avrg_norm_fx = L_add(prev_avrg_norm_fx,L_shr(prev_normq_fx[25],1));/*13 */ - } - ELSE - { - avrg_norm_fx = L_add(L_shr(L_normq_v[sub(sfm,1)],1),L_shr(L_normq_v[sfm],1));/*13 */ - avrg_norm_fx = L_add(avrg_norm_fx,L_shr(L_normq_v[sfm+1],1));/*13 */ - prev_avrg_norm_fx = L_add(L_shr(prev_normq_fx[sub(sfm,1)],1),L_shr(prev_normq_fx[sfm],1));/*13 */ - prev_avrg_norm_fx = L_add(prev_avrg_norm_fx,L_shr(prev_normq_fx[add(sfm,1)],1));/*13 */ - } - - test(); - test(); - IF((sub(bitalloc_var_fx,4915) > 0 || L_sub(L_normq_v[sfm], peak_fx)<0) && peak_fx != 0) - { - Word16 exp_p; - exp_p =norm_l(peak_fx); - exp =sub(31,exp); - env_fx = Isqrt_lc(env_fx, &exp); - L_tmp1 = Mult_32_32(env_fx, L_shl(peak_fx, exp_p));/*12+exp2-exp 31-exp+12+exp1-31 */ - L_tmp2 = Mult_32_16(avrg_norm_fx,harm_para_fx);/*12 13 + 14 + 1 -16 */ - exp1 = norm_l(L_tmp1); - L_tmp1 = L_shl(L_tmp1,exp1);/* 12+exp2-exp+exp1 */ - exp = add(sub(12,exp), add(exp1, exp_p)); - L_tmp2 = Div_32(L_tmp2, extract_h(L_tmp1), extract_l(L_tmp1)); - exp=sub(43,exp); - } - ELSE - { - L_tmp1 = Mult_32_16(L_normq_v[sfm],alfa_fx);/*12 13 + 14 + 1 -16 */ - IF(L_sub(L_tmp1,peak_fx)<0) - { - exp=sub(31,exp); - env_fx = Isqrt_lc(env_fx,&exp); - exp1 = norm_l(env_fx); - env_fx = L_shl(env_fx,exp1);/* 31-exp+exp1 */ - exp = add(sub(31,exp),exp1); - L_tmp1 = (Word32)sharp_fx; - L_tmp2 = Div_32(L_tmp1, extract_h(env_fx), extract_l(env_fx)); /* 45-exp 14 - exp + 31 //39-exp 8 - exp + 31 */ - exp = sub(45,exp); - exp1 = norm_l(peak_fx); - L_tmp1 = L_shl(peak_fx,exp1); /*12 + exp1 */ - L_tmp1 = Div_32(L_tmp2,extract_h(L_tmp1), extract_l(L_tmp1)); /* exp - (12 + exp1) +31 */ - L_tmp2 = Mult_32_32(L_tmp2,L_tmp1);/*2*exp+exp1-12 exp +exp - (12 + exp1) +31 - 31 */ - exp = sub(add(shl(exp,1),exp1),12); - } - ELSE - { - exp = sub(31,exp); - env_fx = Isqrt_lc(env_fx,&exp); - exp1 = norm_l(env_fx); - env_fx =L_shl(env_fx,exp1);/* 31-exp+exp1 */ - exp = add(sub(31,exp),exp1); - L_tmp1=(Word32)(sharp_fx); - L_tmp2 = Div_32(L_tmp1, extract_h(env_fx), extract_l(env_fx)); /* 45-exp 14 - exp + 31 //39-exp 8 - exp + 31 */ - exp =sub(45,exp); - } - - sharp_fx = add(sharp_fx,shr(step_fx,1)); - } - - IF(L_sub(L_tmp2,L_shl(min_coef_fx,sub(exp,13)))>0)/*exp */ - { - L_tmp2 = L_shr(min_coef_fx,1); - exp = 12; - move16(); - } - - IF(sub(prev_bfi,1) == 0) - { - prev_env_Q[sfm] = exp; - move16(); - prev_env_fx[sfm] = L_tmp2; - move32(); - } - /* smooth the noise magnitudes between inter-frame */ - test(); - test(); - IF(L_sub(prev_avrg_norm_fx,L_shr(avrg_norm_fx,1))>0 && L_sub(prev_avrg_norm_fx,L_shl(avrg_norm_fx,1))<0 && prev_is_transient == 0) - { - exp1 =norm_l(prev_env_fx[sfm]); - L_tmp1 = L_shl(prev_env_fx[sfm],exp1);/* prev_env_Q[sfm] +exp1 */ - - exp2= norm_l(L_tmp2); - L_tmp3 = L_shl(L_tmp2,exp2);/* exp +exp2 */ - exp3 = s_min(add(prev_env_Q[sfm],exp1),add(exp,exp2)); - - L_tmp1 = L_shl(L_tmp1,sub(sub(exp3,prev_env_Q[sfm]),exp1)); /*exp3 */ - L_tmp3 = L_shl(L_tmp3,sub(sub(exp3,exp),exp2)); /*exp3 */ - L_tmp2 = L_add(L_shr(L_tmp1,1),L_shr(L_tmp3,1));/*exp3 */ - exp = exp3; - move16(); - } - FOR (i = sfm_start[sfm]; i < sfm_end[sfm]; i++) - { - IF (coeff_fx[i] == 0) - { - tmp1 = Random(bwe_seed);/*Q15 */ - L_tmp1= Mult_32_16(L_tmp2,tmp1);/*exp exp+15+1 -16 */ - L_tmp1 = L_shl(L_tmp1,sub(12,exp)); - L_coeff_out[i] = L_tmp1; - move32(); - } - } - } - ELSE - { - exp =0; - move16(); - L_tmp2 =L_deposit_l(0); - } - } - ELSE IF(R[sfm] == 0) - { - /* fill random noise for 0 bit subbands */ - FOR (i = sfm_start[sfm]; i < sfm_end[sfm]; i++) - { - IF(coeff_fx[i] == 0) - { - tmp1 =Random(bwe_seed);/*Q15 */ - L_tmp1= Mult_32_16(L_normq_v[sfm],tmp1);/*14 14+15+1 -16 */ - L_tmp1 = L_shr(L_tmp1,2);/* */ - L_coeff_out[i] = L_tmp1; - move32(); - } - } - L_tmp2 = L_add(0,L_normq_v[sfm]); - exp = 14; - move16(); - } - - test(); - test(); - test(); - test(); - IF(sub(sfm,sub(SFM_N_WB,1))==0 && prev_is_transient == 0 && L_sub(prev_normq_fx[sfm],L_shr(L_normq_v[sfm],1))>0 - && L_sub(prev_normq_fx[sfm],L_shl(L_normq_v[sfm],1)) < 0 && sub(bitalloc_var_fx,4915) <= 0) - { - Word32 *p_prev_coeff_out = prev_coeff_out_fx; - FOR (i = add(sfm_start[sfm],12); i < sfm_end[sfm]; i++) - { - test(); - test(); - test(); - test(); - IF(L_sub(L_abs(L_coeff_out[i]),L_shl(L_abs(*p_prev_coeff_out),2)) >0 - || L_sub(L_abs(L_coeff_out[i]),L_shr(L_abs(*p_prev_coeff_out),2)) <0 - || ((R[sfm] == 0 || *prev_R == 0) && add(R[sfm], *prev_R) != 0)) - { - L_tmp = L_add(L_shr(L_abs(L_coeff_out[i]),1),L_shr(L_abs(*p_prev_coeff_out),1)); - - if(L_coeff_out[i] <= 0 ) - { - L_tmp = L_negate(L_tmp); - } - L_coeff_out[i] = L_tmp; - move32(); - } - p_prev_coeff_out++; - } - } - prev_env_Q[sfm] = exp; - move16(); - prev_env_fx[sfm] = L_tmp2; - move32(); - } - } - ELSE - { - /* fill random noise for 0 bit subbands of transient frame */ - FOR(sfm = 0; sfm < num_sfm; sfm++) - { - IF( R[sfm] == 0 ) - { - FOR (i = sfm_start[sfm]; i < sfm_end[sfm]; i++) - { - tmp1 =Random(bwe_seed);/*Q15 */ - L_tmp1= Mult_32_16(L_normq_v[sfm],tmp1);/*14 14+15+1 -16 */ - L_tmp1 =L_shr(L_tmp1,2);/* */ - L_coeff_out[i] = L_tmp1; - move32(); - } - } - } - set16_fx( prev_env_Q, 0, SFM_N_WB ); - set32_fx( prev_env_fx, 0, SFM_N_WB ); - } - - Copy32(L_normq_v,prev_normq_fx,SFM_N_WB); - Copy32( L_coeff_out + L_FRAME16k - L_HQ_WB_BWE, prev_coeff_out_fx, L_HQ_WB_BWE ); - *prev_R = R[SFM_N_WB-1]; - - return; -} - -/*--------------------------------------------------------------------------* - * enforce_zero_for_min_envelope_fx() - * - * Detect minimum level of envelope and set corresponding bands to zero - *--------------------------------------------------------------------------*/ - -void enforce_zero_for_min_envelope_fx( - const Word16 hqswb_clas, /* i : HQ coding mode Q0 */ - const Word16 *ynrm, /* i : Envelope indices Q0 */ - Word32 *L_coefsq, /* i/o: Quantized spectrum/zeroed spectrum Q12 */ - const Word16 nb_sfm, /* i : Number of coded sub bands Q0 */ - const Word16 *sfm_start, /* i : Sub band start indices Q0 */ - const Word16 *sfm_end /* i : Sub band end indices Q0 */ -) -{ - Word16 i, j; - - /* prevent non-zero output for all-zero input */ - IF( sub(hqswb_clas,HQ_HVQ) != 0 ) - { - IF( sub(ynrm[0], 31) == 0 ) - { - FOR( j = sfm_start[0]; j < sfm_end[0]; j++ ) - { - L_coefsq[j] = L_deposit_l(0); - } - } - - FOR( i = 1; i < nb_sfm; i++ ) - { - IF( sub(ynrm[i], 39) == 0 ) - { - FOR( j = sfm_start[i]; j < sfm_end[i]; j++ ) - { - L_coefsq[j] = L_deposit_l(0); - } - } - } - } - - return; -} - -/*--------------------------------------------------------------------------* - * apply_envelope() - * - * Apply spectral envelope with envelope adjustments - *--------------------------------------------------------------------------*/ - -void apply_envelope_fx( - const Word16 *coeff, /* i/o: Coded/noisefilled normalized spectrum Q12 */ - const Word16 *norm, /* i : Envelope Q0 */ - const Word16 *norm_adj, /* i : Envelope adjustment Q15 */ - const Word16 num_sfm, /* i : Total number of bands Q0 */ - const Word16 last_sfm, /* i : Last coded band Q0 */ - const Word16 HQ_mode, /* i : HQ mode Q0 */ - const Word16 length, /* i : Frame length Q0 */ - const Word16 *sfm_start, /* i : Sub band start indices Q0 */ - const Word16 *sfm_end, /* i : Sub band end indices Q0 */ - Word32 *normq_v, /* o : Envelope with adjustment Q14 */ - Word32 *coeff_out, /* o : coded/noisefilled spectrum Q12 */ - const Word16 *coeff1, /* i : coded/noisefilled spectrum Q12 */ - Word32 *coeff_out1 /* o : coded/noisefilled spectrum Q12 */ -) -{ - Word16 i; - Word16 sfm; - UWord16 lsb; - Word32 normq; - Word32 L_tmp; - Word16 len; - - len = num_sfm; - move16(); - test(); - if( sub(HQ_mode, HQ_GEN_SWB) == 0 || sub(HQ_mode, HQ_GEN_FB) == 0 ) - { - len = add(last_sfm, 1); - } - - IF( sub(length, L_FRAME16k) == 0 ) - { - FOR (sfm = 0; sfm < num_sfm; sfm++) - { - normq_v[sfm] = dicn_fx[norm[sfm]]; - move16(); - move32(); - /*normq = normq_v[sfm] * norm_adj[sfm]; */ - Mpy_32_16_ss(normq_v[sfm], norm_adj[sfm], &normq, &lsb); /* Q14 (14+15+1-16) */ - - FOR (i = sfm_start[sfm]; i < sfm_end[sfm]; i++) - { - /*coeff_out[i] = coeff[i]*normq; */ - Mpy_32_16_ss(normq, coeff[i], &L_tmp, &lsb); - coeff_out[i] = L_add(L_shl(L_tmp, 1), lshr(lsb, 15)); - move32(); /* Q12 (14+12+1-16)+1 */ - } - } - } - ELSE - { - FOR (sfm = 0; sfm < len; sfm++) - { - normq_v[sfm] = dicn_fx[norm[sfm]]; - move16(); - move32(); - /*normq_v[sfm] *= norm_adj[sfm]; */ - Mpy_32_16_ss(normq_v[sfm], norm_adj[sfm], &normq_v[sfm], &lsb); - move32(); /* Q14 (14+15+1-16) */ - - normq = L_add(0,normq_v[sfm]); - FOR (i = sfm_start[sfm]; i < sfm_end[sfm]; i++) - { - /*coeff_out[i] = coeff[i]*normq; */ - Mpy_32_16_ss(normq, coeff[i], &L_tmp, &lsb); - coeff_out[i] = L_add(L_shl(L_tmp, 1), lshr(lsb, 15)); - move32(); /* Q12 (14+12+1-16)+1 */ - } - } - - test(); - IF ( sub(HQ_mode, HQ_GEN_SWB) == 0 || sub(HQ_mode, HQ_GEN_FB) == 0 ) - { - FOR (sfm = 0; sfm <= last_sfm; sfm++) - { - normq = L_add(0,normq_v[sfm]); - FOR (i = sfm_start[sfm]; i < sfm_end[sfm]; i++) - { - /*coeff_out1[i] = coeff_out1[i]*normq; */ - Mpy_32_16_ss(normq, coeff1[i], &L_tmp, &lsb); - coeff_out1[i] = L_add(L_shl(L_tmp, 1), lshr(lsb, 15)); - move32(); /* Q12 (14+12+1-16)+1 */ - } - } - } - } - - - return; -} - - diff --git a/src/libs/libevs/lib_com/hvq_pvq_bitalloc.cpp b/src/libs/libevs/lib_com/hvq_pvq_bitalloc.cpp new file mode 100644 index 00000000..a0086656 --- /dev/null +++ b/src/libs/libevs/lib_com/hvq_pvq_bitalloc.cpp @@ -0,0 +1,157 @@ +/*==================================================================================== + EVS Codec 3GPP TS26.443 Nov 13, 2018. Version 12.11.0 / 13.7.0 / 14.3.0 / 15.1.0 + ====================================================================================*/ + +#include +#include "options.h" +#include "cnst.h" +#include "prot.h" +#include "rom_com.h" + +/*--------------------------------------------------------------------------*/ +/* Function hvq_pvq_bitalloc */ +/* ~~~~~~~~~~~~~~~~~~~~~~~~ */ +/* */ +/* Calculate the number of PVQ bands to code and allocate bits based on */ +/* the number of available bits. */ +/*--------------------------------------------------------------------------*/ + +short hvq_pvq_bitalloc( + short num_bits, /* i/o: Number of available bits (including gain bits) */ + const short brate, /* i : bitrate */ + const short bwidth, /* i : Encoded bandwidth */ + const short *ynrm, /* i : Envelope coefficients */ + const int manE_peak, /* i : Peak energy mantissa */ + const short expE_peak, /* i : Peak energy exponent */ + short *Rk, /* o : bit allocation for concatenated vector */ + short *R, /* i/o: Global bit allocation */ + short *sel_bands, /* o : Selected bands for encoding */ + short *n_sel_bands /* o : No. of selected bands for encoding */ +) +{ + short num_bands, k, band_max_bits; + short k_max; + short k_start; + float E_max; + int E_max5; + short expo; + short align; + int acc; + float tmp; + int env_mean; + short reciprocal; + short num_sfm; + short bit_cost; + + if (bwidth == FB) + { + num_sfm = SFM_N_HARM_FB; + } + else + { + num_sfm = SFM_N_HARM; + } + + if (brate == HQ_24k40) + { + band_max_bits = HVQ_BAND_MAX_BITS_24k; + k_start = HVQ_THRES_SFM_24k; + if (bwidth == FB) + { + reciprocal = 2731; + } + else + { + reciprocal = 3277; + } + } + else + { + band_max_bits = HVQ_BAND_MAX_BITS_32k; + k_start = HVQ_THRES_SFM_32k; + if (bwidth == FB) + { + reciprocal = 3641; + } + else + { + reciprocal = 4681; + } + } + + num_bands = num_bits / band_max_bits; + num_bits = num_bits - num_bands*band_max_bits; + + if (num_bits >= HVQ_NEW_BAND_BIT_THR) + { + num_bands++; + } + else + { + num_bits += band_max_bits; + } + + /* safety check in case of bit errors */ + if (num_bands < 1) + { + return 0; + } + + *n_sel_bands = 0; + env_mean = 0; + E_max = 0; + k_max = k_start; + for ( k = k_start; k < num_sfm; k++ ) + { + tmp = dicn[ynrm[k]]; + env_mean += ynrm[k]; + if( tmp > E_max ) + { + E_max = tmp; + k_max = k; + } + } + env_mean = 2*((int)env_mean * (int)reciprocal); + + if(band_len_harm[k_max] == 96) + { + bit_cost = 61; + } + else + { + QuantaPerDsDirac(band_len_harm[k_max], 1, hBitsN, &bit_cost); + } + + + expo = max(0, ynrm[k_max]-1) >> 1; + E_max5 = E_max5_tbl[ynrm[k_max]]; + align = expo - expE_peak; + align = align + (19 - 14) - (31 - 2*12); + if (align < 0) + { + acc = E_max5 - (manE_peak >> -align); + } + else + { + acc = (E_max5 >> align) - manE_peak; + } + if ( acc > 0 + && ((env_mean - (ynrm[k_max]<<16)) > 0x30000L) + && num_bands > 1 + && (num_bits - HVQ_PVQ_GAIN_BITS)<<3 >= bit_cost ) + { + sel_bands[*n_sel_bands] = k_max; + (*n_sel_bands)++; + R[k_max] = 1; /* Mark that the band has been encoded for fill_spectrum */ + } + + /* Allocate bits */ + for (k = 0; k < num_bands-1; k++) + { + Rk[k] = band_max_bits-HVQ_PVQ_GAIN_BITS; + } + Rk[num_bands-1] = num_bits-HVQ_PVQ_GAIN_BITS; + + return num_bands; +} + diff --git a/src/libs/libevs/lib_com/hvq_pvq_bitalloc_fx.cpp b/src/libs/libevs/lib_com/hvq_pvq_bitalloc_fx.cpp deleted file mode 100755 index ae669f1f..00000000 --- a/src/libs/libevs/lib_com/hvq_pvq_bitalloc_fx.cpp +++ /dev/null @@ -1,189 +0,0 @@ -/*==================================================================================== - EVS Codec 3GPP TS26.442 Apr 03, 2018. Version 12.11.0 / 13.6.0 / 14.2.0 - ====================================================================================*/ - -#include "options.h" /* Compilation switches */ -#include "stl.h" /* required by wmc_tool */ - -#include "rom_com_fx.h" - -#include "prot_fx.h" /* Function prototypes */ -#include "cnst_fx.h" /* Common constants */ - -/*--------------------------------------------------------------------------*/ -/* Function hvq_pvq_bitalloc */ -/* ~~~~~~~~~~~~~~~~~~~~~~~~ */ -/* */ -/* Calculate the number of PVQ bands to code and allocate bits based on */ -/* the number of available bits. */ -/*--------------------------------------------------------------------------*/ - -Word16 hvq_pvq_bitalloc_fx( - Word16 num_bits, /* i/o: Number of available bits (including gain bits) */ - const Word32 brate, /* i : bitrate */ - const Word16 bwidth_fx, /* i : Encoded bandwidth */ - const Word16 *ynrm, /* i : Envelope coefficients */ - const Word32 manE_peak, /* i : Peak energy mantissa */ - const Word16 expE_peak, /* i : Peak energy exponent */ - Word16 *Rk, /* o : bit allocation for concatenated vector */ - Word16 *R, /* i/o: Global bit allocation */ - Word16 *sel_bands, /* o : Selected bands for encoding */ - Word16 *n_sel_bands /* o : No. of selected bands for encoding */ -) -{ - Word16 num_bands, band_max_bits; - Word16 one_over_band_max_bits; - Word16 k; - Word16 reciprocal, envSum, expo, align, m, n, indx; - Word16 k_max; - Word16 k_start; - Word32 E_max, E_max5; - Word32 tmp, acc; - Word32 env_mean; - UWord16 lsb; - Word16 num_sfm; - - IF (sub(bwidth_fx, FB) == 0) - { - num_sfm = SFM_N_HARM_FB; - } - ELSE - { - num_sfm = SFM_N_HARM; - } - - IF ( L_sub(brate, HQ_24k40) == 0 ) - { - band_max_bits = HVQ_BAND_MAX_BITS_24k; - move16(); - one_over_band_max_bits = ONE_OVER_HVQ_BAND_MAX_BITS_24k_FX; - move16(); - k_start = HVQ_THRES_SFM_24k; - move16(); - IF (sub(bwidth_fx, FB) == 0) - { - reciprocal = 2731; /* Q15, 1/(SFM_N_HARM_FB + 1 - k_start) */ move16(); - } - ELSE - { - reciprocal = 3277; /* Q15, 1/(SFM_N_HARM + 1 - k_start) */ move16(); - } - } - ELSE - { - band_max_bits = HVQ_BAND_MAX_BITS_32k; - move16(); - one_over_band_max_bits = ONE_OVER_HVQ_BAND_MAX_BITS_32k_FX; - move16(); - k_start = HVQ_THRES_SFM_32k; - move16(); - IF (sub(bwidth_fx, FB) == 0) - { - reciprocal = 3641; /* Q15, 1/(SFM_N_HARM_FB + 1 - k_start) */ move16(); - } - ELSE - { - reciprocal = 4681; /* Q15, 1/(SFM_N_HARM + 1 - k_start) */ move16(); - } - } - - num_bands = mult( num_bits, one_over_band_max_bits ); /* Q0 */ - num_bits = sub( num_bits, i_mult(num_bands, band_max_bits) ); /* Q0 */ - - IF ( sub(num_bits, HVQ_NEW_BAND_BIT_THR) >= 0 ) - { - num_bands = add(num_bands, 1); - } - ELSE - { - num_bits = add(num_bits, band_max_bits); - } - - /* safety check in case of bit errors */ - if (sub(num_bands, 1) < 0) - { - return 0; - } - - *n_sel_bands = 0; - move16(); - envSum = 0; - move16(); - E_max = L_deposit_l(0); - k_max = k_start; - move16(); - FOR ( k = k_start; k < num_sfm; k++ ) - { - indx = ynrm[k]; - move16(); - tmp = L_add(0,dicn_fx[indx]); /* Q14 */ - envSum = add(envSum, indx); /* Since the size of dicn_fx = 40, ynrm[k] must be less than 41. 16 bits are enough for envSum.*/ - IF (L_sub(tmp, E_max) > 0) - { - E_max = L_add(0,tmp); - k_max = k; - move16(); - } - } - env_mean = L_mult(envSum, reciprocal); /* env_mean in Q16 */ - IF (L_sub(L_sub(env_mean, L_deposit_h(ynrm[k_max])), 0x30000L) > 0) /* condition: env_mean - ynrm[k_max] > 3 */ - { - expo = norm_l(E_max); - E_max = L_shl(E_max, expo); - Mpy_32_16_ss(E_max, 0x7a12, &E_max5, &lsb); /* NB: 5.0e5 = 0x7a12(Q15) x 2^19. */ - /* True floating point value of E_max*5e5 = E_max5 x 2^(19 - expo - 14). - * In this context, the 32-bit E_max5 is in Q0, and - * -14 is due to Emax in Q14. - * True floating point value of E_peak = manE_peak x 2^(31 - expE_peak - 2*12). See peak_vq_enc_fx(). - */ - - /* Align the Q-points of the floating point Emax*5e5 and E_peak. */ - align = sub(expo, expE_peak); - align = add(align, (19 - 14) - (31 - 2*12)); - IF (align < 0) - { - acc = L_sub(E_max5, L_shl(manE_peak, align)); - } - ELSE - { - acc = L_sub(L_shr(E_max5, align), manE_peak); - } - - IF (acc > 0) /* condition: E_max*5.e5 > E_peak */ - { - IF ( sub(band_len_harm[k_max], 96) == 0 ) - { - n = 61; - } - ELSE - { - QuantaPerDsDirac_fx(band_len_harm[k_max], 1, hBitsN, &n); - } - m = shl(sub(num_bits, HVQ_PVQ_GAIN_BITS), 3); - IF (sub(m, n) >= 0) - { - IF (sub(num_bands, 1) > 0) /* condition: num_bands > 1 */ - { - sel_bands[*n_sel_bands] = k_max; - move16(); - *n_sel_bands = add(*n_sel_bands, 1); - R[k_max] = 1; /* Mark that the band has been encoded for fill_spectrum */ move16(); - } - } - } - } - - /* Allocate bits */ - tmp = sub(num_bands,1); - FOR (k = 0; k < tmp; k++) - { - Rk[k] = shl(sub(band_max_bits, HVQ_PVQ_GAIN_BITS), 3); - move16(); - } - /* NB: When it exits the above loop, k = num_bands - 1. */ - Rk[k] = shl(sub(num_bits, HVQ_PVQ_GAIN_BITS), 3); - move16(); - - return num_bands; -} - diff --git a/src/libs/libevs/lib_com/ifft_rel.cpp b/src/libs/libevs/lib_com/ifft_rel.cpp new file mode 100644 index 00000000..6b840d0b --- /dev/null +++ b/src/libs/libevs/lib_com/ifft_rel.cpp @@ -0,0 +1,255 @@ +/*==================================================================================== + EVS Codec 3GPP TS26.443 Nov 13, 2018. Version 12.11.0 / 13.7.0 / 14.3.0 / 15.1.0 + ====================================================================================*/ + +#include "options.h" +#include "prot.h" +#include "rom_com.h" + + +/*-----------------------------------------------------------------* + * Local constants + *-----------------------------------------------------------------*/ + +#define N_MAX_FFT 1024 +#define INV_SQR2 0.70710676908493f + +/*---------------------------------------------------------------------* + * ifft_rel() + * + * Calculate the inverse FFT of a real signal + * + * Based on the FORTRAN code from the article "Real-valued Fast Fourier Transform Algorithms" + * by Sorensen, ... in IEEE Trans. on ASSP, Vol. ASSP-35, No. June 6th 1987. + * + * Input: the io[] signal containing the spectrum in the following order : + * + * Re[0], Re[1], .. Re[n/2], Im[n/2-1], .. Im[1] + *---------------------------------------------------------------------*/ + +void ifft_rel( + float io[], /* i/o: input/output vector */ + const short n, /* i : vector length */ + const short m /* i : log2 of vector length */ +) +{ + short i, j, k; + short step; + short n2, n4, n8, i0; + short is, id; + float *x,*xi0, *xi1, *xi2, *xi3, *xi4, *xup1, *xdn6, *xup3, *xdn8; + float xt; + float r1; + float t1, t2, t3, t4, t5; + float cc1, cc3, ss1, ss3; + const float *s, *s3, *c, *c3; + const short *idx; + float temp[512]; + float n_inv; + + n_inv = 1.0f/n; + + /*-----------------------------------------------------------------* + * IFFT + *-----------------------------------------------------------------*/ + + x = &io[-1]; + n2 = 2*n; + for (k=1; k> 1; + n4 = n2 >> 2; + n8 = n4 >> 1; + while (is < n-1) + { + xi1 = x + is + 1; + xi2 = xi1 + n4; + xi3 = xi2 + n4; + xi4 = xi3 + n4; + + for (i=is; i>1)]; + } + } + else if (n == 256) + { + for (i=0; i> 1; + while (k < j) + { + j = j - k; + k = k >> 1; + } + j = j + k; + } + } + + /*-----------------------------------------------------------------* + * Normalization + *-----------------------------------------------------------------*/ + + for (i=1; i<=n; i++) + { + x[i] = xi0[i] * n_inv; + } + + return; +} diff --git a/src/libs/libevs/lib_com/igf_base.cpp b/src/libs/libevs/lib_com/igf_base.cpp old mode 100755 new mode 100644 index 6daca10e..d8ce1806 --- a/src/libs/libevs/lib_com/igf_base.cpp +++ b/src/libs/libevs/lib_com/igf_base.cpp @@ -1,54 +1,48 @@ /*==================================================================================== - EVS Codec 3GPP TS26.442 Apr 03, 2018. Version 12.11.0 / 13.6.0 / 14.2.0 + EVS Codec 3GPP TS26.443 Nov 13, 2018. Version 12.11.0 / 13.7.0 / 14.3.0 / 15.1.0 ====================================================================================*/ -#include -#include -#include #include #include "options.h" -#include "stl.h" -#include "prot_fx.h" -#include "rom_com_fx.h" -#include "basop_util.h" +#include "prot.h" +#include "rom_com.h" -/**********************************************************************/ /* -returns an int val, multiplied with transFac -**************************************************************************/ -static Word16 IGF_ApplyTransFac( /**< out: Q0 | multiplication factor */ - const Word16 val, /**< in: Q15 | input value for multiplication, Q15 */ - const Word16 transFac /**< in: Q14 | multiplicator for variable val, Q14: 1.25f=0x5000, 1.0f=0x4000, 0.5f=0x2000 */ +/*---------------------------------------------------------------------* + * IGF_ApplyTransFac() + * + * + *---------------------------------------------------------------------*/ + +static int IGF_ApplyTransFac( /**< out: | multiplication factor */ + const int val, /**< in: Q15 | input value for multiplication, Q15 */ + const float transFac /**< in: Q14 | multiplicator for variable val, Q14: 1.25f=0x5000, 1.0f=0x4000, 0.5f=0x2000 */ ) { - Word16 ret; + int ret = val; - if(sub(transFac, 0x4000) == 0) + if (transFac!=1.f) { - return val; + ret = round_f(val*transFac); + ret +=(ret & 1); } - ret = shl(val, 1); - ret = mac_r(0x00000000, ret, transFac); - ret = add(ret, s_and(ret, 1)); - - return ret; } -/**********************************************************************/ /* -maps a given bitrate to the IGF_BITRATE index -**************************************************************************/ -static Word16 IGF_MapBitRateToIndex( /**< out: Q0 | return bit rate index */ - Word32 bitRate, /**< in: | bitrate */ - Word16 mode /**< in: | bandwidth mode */ - , Word16 rf_mode /**< in: | flag to signal the RF mode */ + +/*---------------------------------------------------------------------* + * IGF_MapBitRateToIndex() + * + * maps a given bitrate to the IGF_BITRATE index + *---------------------------------------------------------------------*/ + +static short IGF_MapBitRateToIndex( /**< out: Q0 | return bit rate index */ + int bitRate, /**< in: | bitrate */ + int mode, /**< in: | bandwidth mode */ + int rf_mode /**< in: | flag to signal the RF mode */ ) { - Word16 bitRateIndex; - - - bitRateIndex = IGF_BITRATE_UNKNOWN; - move16(); + short bitRateIndex = IGF_BITRATE_UNKNOWN; switch (mode) { @@ -56,7 +50,7 @@ static Word16 IGF_MapBitRateToIndex( switch (bitRate) { case 13200: - if (sub(rf_mode,1) == 0) + if (rf_mode == 1) { bitRateIndex = IGF_BITRATE_RF_WB_13200; } @@ -76,7 +70,7 @@ static Word16 IGF_MapBitRateToIndex( break; case 13200: bitRateIndex = IGF_BITRATE_SWB_13200; - if (sub(rf_mode,1) == 0) + if (rf_mode == 1) { bitRateIndex = IGF_BITRATE_RF_SWB_13200; } @@ -129,38 +123,38 @@ static Word16 IGF_MapBitRateToIndex( return bitRateIndex; } -/**********************************************************************/ /* -IGF grid setup -**************************************************************************/ -static void IGF_gridSetUp(H_IGF_GRID hGrid, /**< out: | IGF grid handle */ - Word16 bitRateIndex, /**< in: Q0 | IGF bitrate index */ - Word32 sampleRate, /**< in: | sample rate */ - Word16 frameLength, /**< in: | frame length */ - Word16 transFac, /**< in: | transFac */ - Word16 igfMinFq /**< in: | IGF minimum frequency indicating lower start frequency for copy up */ - ) + +/*---------------------------------------------------------------------* + * IGF_gridSetUp() + * + * IGF grid setup + *---------------------------------------------------------------------*/ + +static void IGF_gridSetUp( + H_IGF_GRID hGrid, /**< out: | IGF grid handle */ + short bitRateIndex, /**< in: | IGF bitrate index */ + int sampleRate, /**< in: | sample rate */ + int frameLength, /**< in: | frame length */ + float transFac, /**< in: | transFac */ + int igfMinFq /**< in: | IGF minimum frequency indicating lower start frequency for copy up */ +) { - Word16 t; - Word16 sfb; - const Word16 *swb_offset; - Word16 swb_offset_len; - Word16 bandwidth; - Word16 wrp_sfb; - Word16 tmp1; - Word16 tmp2; - Word32 L_tmp1; - Word32 L_tmp2; + int t; + int sfb; + int swb_offset_len; + int wrp_sfb; + const int *swb_offset; + float bandwidth; + /* inits */ swb_offset = NULL; - move16(); swb_offset_len = 0; - move16(); - SWITCH (bitRateIndex) + switch (bitRateIndex) { case IGF_BITRATE_WB_9600: - case IGF_BITRATE_SWB_9600: case IGF_BITRATE_RF_WB_13200: + case IGF_BITRATE_SWB_9600: case IGF_BITRATE_RF_SWB_13200: case IGF_BITRATE_SWB_13200: case IGF_BITRATE_SWB_16400: @@ -169,113 +163,68 @@ static void IGF_gridSetUp(H_IGF_GRID hGrid, case IGF_BITRATE_SWB_48000: swb_offset = &swb_offset_LB_new[bitRateIndex][1]; swb_offset_len = swb_offset_LB_new[bitRateIndex][0]; - move16(); - Copy(&igf_whitening_TH[bitRateIndex][0][0], &hGrid->whiteningThreshold[0][0], IGF_MAX_TILES * 2); - BREAK; + mvr2r(&igf_whitening_TH[(int)bitRateIndex][0][0], &hGrid->whiteningThreshold[0][0], IGF_MAX_TILES * 2); + break; case IGF_BITRATE_FB_16400: case IGF_BITRATE_FB_24400: case IGF_BITRATE_FB_32000: swb_offset = &swb_offset_LB_new[bitRateIndex][1]; swb_offset_len = swb_offset_LB_new[bitRateIndex][0]; - move16(); - Copy(&igf_whitening_TH[bitRateIndex][0][0], &hGrid->whiteningThreshold[0][0], IGF_MAX_TILES * 2); - BREAK; + mvr2r(&igf_whitening_TH[(int)bitRateIndex][0][0], &hGrid->whiteningThreshold[0][0], IGF_MAX_TILES * 2); + break; case IGF_BITRATE_FB_48000: case IGF_BITRATE_FB_96000: case IGF_BITRATE_FB_128000: swb_offset = &swb_offset_LB_new[bitRateIndex][1]; swb_offset_len = swb_offset_LB_new[bitRateIndex][0]; - move16(); - Copy(&igf_whitening_TH[bitRateIndex][0][0], &hGrid->whiteningThreshold[0][0], IGF_MAX_TILES * 2); - BREAK; + mvr2r(&igf_whitening_TH[(int)bitRateIndex][0][0], &hGrid->whiteningThreshold[0][0], IGF_MAX_TILES * 2); + break; case IGF_BITRATE_UNKNOWN: default: assert(0); } - FOR(sfb = 0; sfb < swb_offset_len; sfb++) + for(sfb = 0; sfb < swb_offset_len; sfb++) { hGrid->swb_offset[sfb] = IGF_ApplyTransFac(swb_offset[sfb], transFac); - move16(); } hGrid->infoIsRefined = 0; - move16(); frameLength = IGF_ApplyTransFac(frameLength, transFac); - tmp2 = norm_s(frameLength); - bandwidth = shl(frameLength,tmp2); - hGrid->swb_offset_len = extract_l(L_shr(sampleRate, 2)); - tmp1 = sub(norm_s(hGrid->swb_offset_len), 1); - hGrid->swb_offset_len = shl(hGrid->swb_offset_len, tmp1); - bandwidth = div_s(hGrid->swb_offset_len, bandwidth); - tmp2 = sub(add(tmp2, 1), tmp1); - bandwidth = shr(bandwidth, sub(15, tmp2)); - - + bandwidth = (float)sampleRate / 2.0f / (float)frameLength; hGrid->swb_offset_len = swb_offset_len; - move16(); hGrid->startSfb = 0; - move16(); - hGrid->stopSfb = sub(hGrid->swb_offset_len, 1); + hGrid->stopSfb = hGrid->swb_offset_len-1; hGrid->startLine = hGrid->swb_offset[ hGrid->startSfb ]; - move16(); hGrid->stopLine = hGrid->swb_offset[ hGrid->stopSfb ]; - move16(); - hGrid->startFrequency = imult1616(bandwidth, hGrid->startLine); - hGrid->stopFrequency = imult1616(bandwidth, hGrid->stopLine); - - L_tmp1 = L_mult0(igfMinFq, frameLength); - tmp1 = sub(norm_l(L_tmp1), 1); - L_tmp1 = L_shl(L_tmp1, tmp1); - - tmp2 = norm_l(sampleRate); - L_tmp2 = L_shl(sampleRate, tmp2); - tmp1 = add(WORD16_BITS-1, sub(tmp1, add(tmp2, 1))); /* takes into account sampleRate >> 1 */ - - hGrid->minSrcSubband = div_s(extract_h(L_tmp1), extract_h(L_tmp2)); - hGrid->minSrcSubband = shr(hGrid->minSrcSubband, tmp1); - - - hGrid->minSrcSubband = add(hGrid->minSrcSubband, s_and(hGrid->minSrcSubband, 1)); - hGrid->minSrcFrequency = imult1616(bandwidth, hGrid->minSrcSubband); + hGrid->startFrequency = round_f(bandwidth * hGrid->startLine); + hGrid->stopFrequency = round_f(bandwidth * hGrid->stopLine); + hGrid->minSrcSubband = round_f((igfMinFq * (frameLength)) / (sampleRate >> 1)); + hGrid->minSrcSubband += hGrid->minSrcSubband % 2; + hGrid->minSrcFrequency = round_f(bandwidth * hGrid->minSrcSubband); hGrid->infoGranuleLen = frameLength; - move16(); hGrid->infoTransFac = transFac; - move16(); - hGrid->sfbWrap[0] = 0; - move16(); hGrid->tile[0] = hGrid->startLine; - move16(); - - /*************************************************************************/ - SWITCH (bitRateIndex) + switch (bitRateIndex) { - /* SWB 13200 */ + /* SWB 13200 */ case IGF_BITRATE_WB_9600: hGrid->nTiles = 2; - move16(); wrp_sfb = 2; - move16(); /*1st*/ hGrid->sfbWrap[0+1] = wrp_sfb; - move16(); hGrid->sbWrap[0] = hGrid->minSrcSubband; - move16(); hGrid->tile[0+1] = hGrid->swb_offset[wrp_sfb]; - move16(); /*2nd*/ hGrid->sfbWrap[1+1] = hGrid->stopSfb; - move16(); hGrid->sbWrap[1] = hGrid->minSrcSubband; - move16(); hGrid->tile[1+1] = hGrid->swb_offset[hGrid->stopSfb]; - move16(); - BREAK; + break; case IGF_BITRATE_RF_WB_13200: hGrid->nTiles = 2; wrp_sfb = 2; @@ -290,7 +239,7 @@ static void IGF_gridSetUp(H_IGF_GRID hGrid, hGrid->sbWrap[1] = hGrid->minSrcSubband; hGrid->tile[1+1] = hGrid->swb_offset[hGrid->stopSfb]; - BREAK; + break; case IGF_BITRATE_SWB_9600: hGrid->nTiles = 3; wrp_sfb = 1; @@ -311,7 +260,7 @@ static void IGF_gridSetUp(H_IGF_GRID hGrid, hGrid->sbWrap[2] = hGrid->minSrcSubband + IGF_ApplyTransFac(46, transFac); hGrid->tile[2+1] = hGrid->swb_offset[hGrid->stopSfb]; - BREAK; + break; case IGF_BITRATE_RF_SWB_13200: hGrid->nTiles = 3; wrp_sfb = 1; @@ -331,486 +280,297 @@ static void IGF_gridSetUp(H_IGF_GRID hGrid, hGrid->sfbWrap[2+1] = hGrid->stopSfb; hGrid->sbWrap[2] = hGrid->minSrcSubband + IGF_ApplyTransFac(46, transFac); hGrid->tile[2+1] = hGrid->swb_offset[hGrid->stopSfb]; - - BREAK; - + break; case IGF_BITRATE_SWB_13200: hGrid->nTiles = 2; - move16(); wrp_sfb = 4; - move16(); /*1st*/ hGrid->sfbWrap[0+1] = wrp_sfb; - move16(); hGrid->sbWrap[0] = hGrid->minSrcSubband; - move16(); hGrid->tile[0+1] = hGrid->swb_offset[wrp_sfb]; - move16(); /*2nd*/ hGrid->sfbWrap[1+1] = hGrid->stopSfb; - move16(); - hGrid->sbWrap[1] = add(hGrid->minSrcSubband, IGF_ApplyTransFac(32, transFac)); - move16(); + hGrid->sbWrap[1] = hGrid->minSrcSubband + IGF_ApplyTransFac(32, transFac); hGrid->tile[1+1] = hGrid->swb_offset[hGrid->stopSfb]; - move16(); - BREAK; + break; case IGF_BITRATE_SWB_16400: hGrid->nTiles = 3; - move16(); wrp_sfb = 4; - move16(); /*1st*/ hGrid->sfbWrap[0+1] = wrp_sfb; - move16(); hGrid->sbWrap[0] = hGrid->minSrcSubband; - move16(); hGrid->tile[0+1] = hGrid->swb_offset[wrp_sfb]; - move16(); /*2nd*/ hGrid->sfbWrap[1+1] = 6; - move16(); - hGrid->sbWrap[1] = add(hGrid->minSrcSubband, IGF_ApplyTransFac(48, transFac)); - move16(); + hGrid->sbWrap[1] = hGrid->minSrcSubband + IGF_ApplyTransFac(48, transFac); hGrid->tile[1+1] = hGrid->swb_offset[6]; - move16(); /*3nd*/ hGrid->sfbWrap[2+1] = hGrid->stopSfb; - move16(); - hGrid->sbWrap[2] = add(hGrid->minSrcSubband, IGF_ApplyTransFac(64, transFac)); - move16(); + hGrid->sbWrap[2] = hGrid->minSrcSubband + IGF_ApplyTransFac(64, transFac); hGrid->tile[2+1] = hGrid->swb_offset[hGrid->stopSfb]; - move16(); - BREAK; + break; case IGF_BITRATE_SWB_24400: case IGF_BITRATE_SWB_32000: hGrid->nTiles = 3; - move16(); wrp_sfb = 4; - move16(); /*1st*/ hGrid->sfbWrap[0+1] = wrp_sfb; - move16(); hGrid->sbWrap[0] = hGrid->minSrcSubband; - move16(); hGrid->tile[0+1] = hGrid->swb_offset[wrp_sfb]; - move16(); /*2nd*/ hGrid->sfbWrap[1+1] = 7; - move16(); - hGrid->sbWrap[1] = add(hGrid->minSrcSubband, IGF_ApplyTransFac(32, transFac)); - move16(); + hGrid->sbWrap[1] = hGrid->minSrcSubband + IGF_ApplyTransFac(32, transFac); hGrid->tile[1+1] = hGrid->swb_offset[7]; - move16(); /*3nd*/ hGrid->sfbWrap[2+1] = hGrid->stopSfb; - move16(); - hGrid->sbWrap[2] = add(hGrid->minSrcSubband, IGF_ApplyTransFac(64, transFac)); - move16(); + hGrid->sbWrap[2] = hGrid->minSrcSubband + IGF_ApplyTransFac(64, transFac); hGrid->tile[2+1] = hGrid->swb_offset[hGrid->stopSfb]; - move16(); - BREAK; + break; case IGF_BITRATE_SWB_48000: hGrid->nTiles = 1; - move16(); wrp_sfb = hGrid->stopSfb; - move16(); /*1st*/ hGrid->sfbWrap[0+1] = hGrid->stopSfb; - move16(); - hGrid->sbWrap[0] = sub(shl(hGrid->startLine, 1), hGrid->stopLine); - move16(); + hGrid->sbWrap[0] = 2*hGrid->startLine - hGrid->stopLine; hGrid->tile[0+1] = hGrid->swb_offset[hGrid->stopSfb]; - move16(); - BREAK; + break; case IGF_BITRATE_FB_16400: hGrid->nTiles = 3; - move16(); wrp_sfb = 4; - move16(); /*1st*/ hGrid->sfbWrap[0+1] = wrp_sfb; - move16(); hGrid->sbWrap[0] = hGrid->minSrcSubband; - move16(); hGrid->tile[0+1] = hGrid->swb_offset[wrp_sfb]; - move16(); wrp_sfb = 7; - move16(); /*2nd*/ hGrid->sfbWrap[1+1] = wrp_sfb; - move16(); hGrid->sbWrap[1] = hGrid->minSrcSubband; - move16(); hGrid->tile[1+1] = hGrid->swb_offset[wrp_sfb]; - move16(); /*3nd*/ hGrid->sfbWrap[2+1] = hGrid->stopSfb; - move16(); hGrid->sbWrap[2] = hGrid->minSrcSubband; - move16(); hGrid->tile[2+1] = hGrid->swb_offset[hGrid->stopSfb]; - move16(); - - BREAK; + break; case IGF_BITRATE_FB_24400: case IGF_BITRATE_FB_32000: hGrid->nTiles = 4; - move16(); wrp_sfb = 4; - move16(); /*1st*/ hGrid->sfbWrap[0+1] = wrp_sfb; - move16(); hGrid->sbWrap[0] = hGrid->minSrcSubband; - move16(); hGrid->tile[0+1] = hGrid->swb_offset[wrp_sfb]; - move16(); wrp_sfb = 6; - move16(); /*2nd*/ hGrid->sfbWrap[1+1] = wrp_sfb; - move16(); - hGrid->sbWrap[1] = add(hGrid->minSrcSubband, IGF_ApplyTransFac(32, transFac)); - move16(); + hGrid->sbWrap[1] = hGrid->minSrcSubband + IGF_ApplyTransFac(32, transFac); hGrid->tile[1+1] = hGrid->swb_offset[wrp_sfb]; - move16(); wrp_sfb = 9; - move16(); /*3nd*/ hGrid->sfbWrap[2+1] = wrp_sfb; - move16(); hGrid->sbWrap[2] = hGrid->minSrcSubband; - move16(); hGrid->tile[2+1] = hGrid->swb_offset[wrp_sfb]; - move16(); /*4nd*/ hGrid->sfbWrap[3+1] = hGrid->stopSfb; - move16(); - hGrid->sbWrap[3] = add(hGrid->minSrcSubband, sub(hGrid->swb_offset[9], hGrid->swb_offset[8])); - move16(); + hGrid->sbWrap[3] = hGrid->minSrcSubband + (hGrid->swb_offset[9] - hGrid->swb_offset[8]); hGrid->tile[3+1] = hGrid->swb_offset[hGrid->stopSfb]; - move16(); - BREAK; + break; case IGF_BITRATE_FB_48000: case IGF_BITRATE_FB_96000: case IGF_BITRATE_FB_128000: hGrid->nTiles = 1; - move16(); /*1st*/ hGrid->sfbWrap[0+1] = hGrid->stopSfb; - move16(); - hGrid->sbWrap[0] = sub(shl(hGrid->startLine, 1), hGrid->stopLine); - move16(); + hGrid->sbWrap[0] = 2*hGrid->startLine - hGrid->stopLine; hGrid->tile[0+1] = hGrid->swb_offset[hGrid->stopSfb]; - move16(); - BREAK; + break; default: assert(0); }/*switch*/ - /*************************************************************************/ - /*************************************************************************/ - /* adapt level envelope: */ - SWITCH (bitRateIndex) + switch(bitRateIndex) { case IGF_BITRATE_RF_WB_13200: case IGF_BITRATE_WB_9600: - hGrid->gFactor = 13107/*0.80f Q14*/; - move16(); - hGrid->fFactor = 11469/*0.70f Q14*/; - move16(); - hGrid->lFactor = 9830/*0.60f Q14*/; - move16(); - BREAK; + hGrid->gFactor = 0.800f; + hGrid->fFactor = 0.70f; + hGrid->lFactor = 0.60f; + break; case IGF_BITRATE_SWB_13200: case IGF_BITRATE_FB_16400: case IGF_BITRATE_SWB_16400: - hGrid->gFactor = 15237/*0.93f Q14*/; - move16(); - hGrid->fFactor = 3277/*0.20f Q14*/; - move16(); - hGrid->lFactor = 13926/*0.85f Q14*/; - move16(); - BREAK; + hGrid->gFactor = 0.930f; + hGrid->fFactor = 0.20f; + hGrid->lFactor = 0.85f; + break; case IGF_BITRATE_FB_24400: case IGF_BITRATE_SWB_24400: case IGF_BITRATE_FB_32000: case IGF_BITRATE_SWB_32000: - hGrid->gFactor = 15811/*0.965f Q14*/; - move16(); - hGrid->fFactor = 3277/*0.20f Q14*/; - move16(); - hGrid->lFactor = 13926/*0.85f Q14*/; - move16(); - BREAK; + hGrid->gFactor = 0.965f; + hGrid->fFactor = 0.20f; + hGrid->lFactor = 0.85f; + break; case IGF_BITRATE_FB_48000: case IGF_BITRATE_SWB_48000: - hGrid->gFactor = 16384/*1.00f Q14*/; - move16(); - hGrid->fFactor = 3277/*0.20f Q14*/; - move16(); - hGrid->lFactor = 16384/*1.00f Q14*/; - move16(); - BREAK; + hGrid->gFactor = 1.000f; + hGrid->fFactor = 0.20f; + hGrid->lFactor = 1.000f; + break; case IGF_BITRATE_SWB_9600: case IGF_BITRATE_RF_SWB_13200: default: - hGrid->gFactor = 16384/*1.00f Q14*/; - move16(); - hGrid->fFactor = 0/*0.00f Q14*/; - move16(); - hGrid->lFactor = 16384/*1.00f Q14*/; - move16(); + hGrid->gFactor = 1.000f; + hGrid->fFactor = 0.00f; + hGrid->lFactor = 1.000f; } - FOR (t = add(hGrid->nTiles, 1); t < IGF_MAX_TILES; t++) + for ( t = hGrid->nTiles+1; t < IGF_MAX_TILES; t++) { - hGrid->tile[t] = 0; - move16(); + hGrid->tile[t] = 0; hGrid->sbWrap[t - 1] = 0; - move16(); hGrid->sfbWrap[t] = 0; - move16(); } -} - -/**********************************************************************/ /* -calculates energy per sfb via power spectrum -**************************************************************************/ -void IGFCommonFuncsCalcSfbEnergyPowerSpec(const Word16 startSfb, /**< in: Q0 | start sfb index */ - const Word16 stopSfb, /**< in: Q0 | stop sfb index */ - const Word16 *swb_offset, /**< in: Q0 | IGF swb offset table */ - Word32 *pPowerSpectrum, /**< in: Q31 | power spectrum */ - Word16 *pPowerSpectrum_exp, /**< in: | Exponent of PowerSpectrum */ - Word32 *sfbEnergy, /**< out:Q31 | SFB energies , will be initialized inside this function */ - Word16 *sfbEnergy_exp /**< out: | Exponent of PowerSpectrum */ - ) -{ - Word16/*Q0*/ sfb; - Word16/*Q0*/ line; - Word32 L_c; - - - FOR (sfb = startSfb; sfb < stopSfb; sfb++) - { - sfbEnergy[sfb] = L_deposit_l(0); - } - IF (NULL == pPowerSpectrum) - { - return; - } - - FOR (sfb = startSfb; sfb < stopSfb; sfb++) - { - L_c = L_deposit_l(0); - FOR (line = swb_offset[sfb]; line < swb_offset[sfb+1]; line++) - { - Carry = 0; - sfbEnergy[sfb] = L_add_c(sfbEnergy[sfb], pPowerSpectrum[line]); - move32(); - Overflow = 0; - L_c = L_macNs(L_c,0,0); - } - sfbEnergy[sfb] = norm_llQ31(L_c,sfbEnergy[sfb],&(sfbEnergy_exp[sfb])); - move32(); - sfbEnergy_exp[sfb] = add(sfbEnergy_exp[sfb],*pPowerSpectrum_exp); - move16(); - } -} - -/**********************************************************************/ /* -calculate the MDCT square spectrum in the IGF range -**************************************************************************/ -void IGFCommonFuncsMDCTSquareSpec(const Word16 sqrtBgn, /**< in: Q0 | start MDCT subband index */ - const Word16 sqrtEnd, /**< in: Q0 | stop MDCT subband index */ - const Word32 *mdctSpec, /**< in: Q31 | MDCT spectrum to square */ - const Word16 mdctSpec_e, /**< in: | exponent of mdctSpectrum */ - Word32 *mdctSquareSpec, /**< out:Q31 | MDCT square spectrum */ - Word16 *mdctSquareSpec_e, /**< out: | exponent of mdctSquareSpec */ - Word16 indexOffset /**< in: Q0 | index offset */ - ) -{ - Word16 i; - Word16 j; - Word16 s1; - Word16 tmp; - - - /* get headroom, only in IGF range */ - s1 = getScaleFactor32(mdctSpec + sqrtBgn, sub(sqrtEnd, sqrtBgn)); - - /* set new exponent */ - *mdctSquareSpec_e = add(shl(sub(mdctSpec_e, s1), 1), 1); - move16(); - - /* MDCT square spectrum: MDCT^2 */ - j = add(sqrtBgn, indexOffset); /* handle indexOffset with care, otherwise memory overruns may occur! */ - - - FOR (i = sqrtBgn; i < sqrtEnd; i++) - { - tmp = round_fx(L_shl(mdctSpec[i], s1)); - mdctSquareSpec[j++] = L_mult0(tmp, tmp); - move32(); - } - - -} - -/**********************************************************************/ /* -write bits to stream -**************************************************************************/ -void IGFCommonFuncsWriteSerialBit(void *st, /**< in: | encoder/decoder state structure */ - Word16 *pBitOffset, /**< out: Q0 | bit offset */ - Word16 bit /**< in: Q0 | value of bit */ - ) -{ - - IF (st) - { - push_next_indice_fx((Encoder_State_fx*)st, bit, 1); - } - *pBitOffset = add(*pBitOffset, 1); - move16(); - return; } -/**********************************************************************/ /* -changes the IGF configuration -**************************************************************************/ -Word16 IGFCommonFuncsIGFConfiguration( /**< out: | error value: 0 -> error, 1 -> ok */ - Word32 bitRate, /**< in: Q0 | bitrate in bs e.g. 9600 for 9.6kbs */ - Word16 mode, /**< in: Q0 | bandwidth mode */ - H_IGF_INFO hIGFInfo /**< out: | IGF info handle */ - ,Word16 rf_mode /**< in: flag to signal the RF mode */ + +/*---------------------------------------------------------------------* + * IGFCommonFuncsWriteSerialBit() + * + * write bits to bitstream + *---------------------------------------------------------------------*/ + +void IGFCommonFuncsWriteSerialBit( + void *st, /**< in: | encoder/decoder state structure */ + int *pBitOffset, /**< out: | bit offset */ + int bit /**< in: | value of bit */ +) +{ + if (st) + { + push_next_indice((Encoder_State*)st, bit, 1); + } + (*pBitOffset)++; + + return; +} + + +/*---------------------------------------------------------------------* + * IGFCommonFuncsIGFConfiguration() + * + * changes the IGF configuration + *---------------------------------------------------------------------*/ + +int IGFCommonFuncsIGFConfiguration( /**< out: | error value: 0 -> error, 1 -> ok */ + int bitRate, /**< in: | bitrate in bs e.g. 9600 for 9.6kbs */ + int mode, /**< in: | bandwidth mode */ + H_IGF_INFO hIGFInfo, /**< out: | IGF info handle */ + int rf_mode /**< in: flag to signal the RF mode */ ) { H_IGF_GRID hGrid; - Word16 retValue; - Word32 sampleRate; - Word16 frameLength; - Word16 igfMinFq; - Word16 maxHopsize; + int retValue; + int sampleRate; + int frameLength; + int igfMinFq; + int maxHopsize; - retValue = 0; /* bitrate index is unknown -> error! */ move16(); + retValue = 0; /* bitrate index is unknown -> error! */ /* interface call for reading in settings */ - hIGFInfo->bitRateIndex = IGF_MapBitRateToIndex(bitRate, mode - ,rf_mode - ); + hIGFInfo->bitRateIndex = IGF_MapBitRateToIndex( bitRate, mode, rf_mode ); - IF (sub(hIGFInfo->bitRateIndex, IGF_BITRATE_UNKNOWN) != 0) + if (hIGFInfo->bitRateIndex != IGF_BITRATE_UNKNOWN) { - retValue = 1; /* no error */ move16(); + retValue = 1; /* no error */ /* mapping to local values */ - sampleRate = igfMode[hIGFInfo->bitRateIndex].sampleRate; - move32(); - frameLength = igfMode[hIGFInfo->bitRateIndex].frameLength; - move16(); - igfMinFq = igfMode[hIGFInfo->bitRateIndex].igfMinFq; - move16(); - maxHopsize = igfMode[hIGFInfo->bitRateIndex].maxHopsize; - move16(); + sampleRate = igfMode[(int)hIGFInfo->bitRateIndex].sampleRate; + frameLength = igfMode[(int)hIGFInfo->bitRateIndex].frameLength; + igfMinFq = igfMode[(int)hIGFInfo->bitRateIndex].igfMinFq; + maxHopsize = igfMode[(int)hIGFInfo->bitRateIndex].maxHopsize; /* basic information */ hIGFInfo->sampleRate = sampleRate; - move32(); hIGFInfo->frameLength = frameLength; - move16(); hIGFInfo->maxHopsize = maxHopsize; - move16(); hIGFInfo->nfSeed = 0; - move16(); /* set up regular IGF grid for TCX 20 (transfac = 1.f) */ hGrid = &hIGFInfo->grid[IGF_GRID_LB_NORM]; - IGF_gridSetUp(hGrid, - hIGFInfo->bitRateIndex, - sampleRate, - frameLength, - 16384/*1 Q14*/, - igfMinFq); + IGF_gridSetUp(hGrid, hIGFInfo->bitRateIndex, sampleRate, frameLength, 1.00f, igfMinFq ); /* set up IGF grid for CELP->TCX 20 transitions (transfac = 1.25) */ hGrid = &hIGFInfo->grid[IGF_GRID_LB_TRAN]; - IGF_gridSetUp(hGrid, - hIGFInfo->bitRateIndex, - sampleRate, - frameLength, - 20480/*1.25 Q14*/, - igfMinFq); + IGF_gridSetUp( hGrid, hIGFInfo->bitRateIndex, sampleRate, frameLength, 1.25f, igfMinFq ); + /* set up IGF grid for TCX 10 (transfac = 0.5) */ hGrid = &hIGFInfo->grid[IGF_GRID_LB_SHORT]; - IGF_gridSetUp(hGrid, - hIGFInfo->bitRateIndex, - sampleRate, - frameLength, - 8192/*0.50f Q14*/, - igfMinFq); + IGF_gridSetUp( hGrid, hIGFInfo->bitRateIndex, sampleRate, frameLength, 0.50f, igfMinFq ); } return retValue; } -/**********************************************************************/ /* -selects cumulative frequency tables and offsets for the IGF SCF arithmetic coder -**************************************************************************/ -Word16 IGFCommonFuncsIGFGetCFTables( /**< out: | error value: 0 -> error, 1 -> ok */ - Word32 bitRate, /**< in: Q0 | bitrate in bs e.g. 9600 for 9.6kbs */ - Word16 mode, /**< in: Q0 | bandwidth mode */ - Word16 rf_mode, /**< in: | flag to signal the RF mode */ - const Word16 **cf_se00, /**< out: | CF table for t == 0 and f == 0 */ - const Word16 **cf_se01, /**< out: | CF table for t == 0 and f == 1 */ - Word16 *cf_off_se01, /**< out: | offset for CF table above */ - const Word16 **cf_se02, /**< out: | CF tables for t == 0 and f >= 2 */ - const Word16 **cf_off_se02, /**< out: | offsets for CF tables above */ - const Word16 **cf_se10, /**< out: | CF table for t == 1 and f == 0 */ - Word16 *cf_off_se10, /**< out: | offset for CF table above */ - const Word16 **cf_se11, /**< out: | CF tables for t == 1 and f >= 1 */ - const Word16 **cf_off_se11 /**< out: | offsets for CF tables above */ + +/*---------------------------------------------------------------------* + * IGFCommonFuncsIGFGetCFTables() + * + * selects cumulative frequency tables and offsets for the IGF SCF arithmetic coder + *---------------------------------------------------------------------*/ + +int IGFCommonFuncsIGFGetCFTables( /**< out: | error value: 0 -> error, 1 -> ok */ + int bitRate, /**< in: | bitrate in bs e.g. 9600 for 9.6kbs */ + int mode, /**< in: | bandwidth mode */ + int rf_mode, /**< in: | flag to signal the RF mode */ + const unsigned short **cf_se00, /**< out: | CF table for t == 0 and f == 0 */ + const unsigned short **cf_se01, /**< out: | CF table for t == 0 and f == 1 */ + short *cf_off_se01, /**< out: | offset for CF table above */ + const unsigned short **cf_se02, /**< out: | CF tables for t == 0 and f >= 2 */ + const short **cf_off_se02, /**< out: | offsets for CF tables above */ + const unsigned short **cf_se10, /**< out: | CF table for t == 1 and f == 0 */ + short *cf_off_se10, /**< out: | offset for CF table above */ + const unsigned short **cf_se11, /**< out: | CF tables for t == 1 and f >= 1 */ + const short **cf_off_se11 /**< out: | offsets for CF tables above */ ) { - Word16 retValue; - Word16 bitRateIndex; + int retValue; + short bitRateIndex; + retValue = 0; /* bitrate index is unknown -> error! */ + bitRateIndex = IGF_MapBitRateToIndex( bitRate, mode, rf_mode ); - retValue = 0; /* bitrate index is unknown -> error! */ move16(); - bitRateIndex = IGF_MapBitRateToIndex(bitRate, mode - ,rf_mode - ); - - - IF (sub(bitRateIndex, IGF_BITRATE_UNKNOWN) != 0) + if(bitRateIndex != IGF_BITRATE_UNKNOWN) { - retValue = 1; /* no error */ move16(); - SWITCH(bitRateIndex) + retValue = 1; /* no error */ + + switch(bitRateIndex) { case IGF_BITRATE_WB_9600: case IGF_BITRATE_RF_WB_13200: @@ -825,77 +585,56 @@ Word16 IGFCommonFuncsIGFGetCFTables( *cf_se01 = cf_se01_tab[bitRateIndex]; *cf_off_se01 = cf_off_se01_tab[bitRateIndex]; *cf_se02 = &cf_se02_tab[bitRateIndex][0][0]; - move16(); *cf_off_se02 = &cf_off_se02_tab[bitRateIndex][0]; - move16(); *cf_se10 = &cf_se10_tab[0]; - move16(); *cf_off_se10 = cf_off_se10_tab; *cf_se11 = &cf_se11_tab[0][0][0]; - move16(); *cf_off_se11 = &cf_off_se11_tab[0][0]; - move16(); - BREAK; + break; case IGF_BITRATE_FB_16400: case IGF_BITRATE_FB_24400: case IGF_BITRATE_FB_32000: - bitRateIndex = add(sub(bitRateIndex, IGF_BITRATE_FB_16400), IGF_BITRATE_SWB_16400); + bitRateIndex = bitRateIndex-IGF_BITRATE_FB_16400+IGF_BITRATE_SWB_16400; *cf_se00 = cf_se00_tab; *cf_se01 = cf_se01_tab[bitRateIndex]; *cf_off_se01 = cf_off_se01_tab[bitRateIndex]; *cf_se02 = &cf_se02_tab[bitRateIndex][0][0]; - move16(); *cf_off_se02 = &cf_off_se02_tab[bitRateIndex][0]; - move16(); *cf_se10 = &cf_se10_tab[0]; - move16(); *cf_off_se10 = cf_off_se10_tab; *cf_se11 = &cf_se11_tab[0][0][0]; - move16(); *cf_off_se11 = &cf_off_se11_tab[0][0]; - move16(); - BREAK; + break; case IGF_BITRATE_FB_48000: - bitRateIndex = add(sub(bitRateIndex, IGF_BITRATE_FB_48000), IGF_BITRATE_SWB_48000); + bitRateIndex = bitRateIndex-IGF_BITRATE_FB_48000+IGF_BITRATE_SWB_48000; *cf_se00 = cf_se00_tab; *cf_se01 = cf_se01_tab[bitRateIndex]; *cf_off_se01 = cf_off_se01_tab[bitRateIndex]; *cf_se02 = &cf_se02_tab[bitRateIndex][0][0]; - move16(); *cf_off_se02 = &cf_off_se02_tab[bitRateIndex][0]; - move16(); *cf_se10 = &cf_se10_tab[0]; - move16(); *cf_off_se10 = cf_off_se10_tab; *cf_se11 = &cf_se11_tab[0][0][0]; - move16(); *cf_off_se11 = &cf_off_se11_tab[0][0]; - move16(); - BREAK; + break; case IGF_BITRATE_FB_96000: case IGF_BITRATE_FB_128000: bitRateIndex = IGF_BITRATE_SWB_48000; - move16(); *cf_se00 = cf_se00_tab; *cf_se01 = cf_se01_tab[bitRateIndex]; *cf_off_se01 = cf_off_se01_tab[bitRateIndex]; *cf_se02 = &cf_se02_tab[bitRateIndex][0][0]; - move16(); *cf_off_se02 = &cf_off_se02_tab[bitRateIndex][0]; - move16(); *cf_se10 = &cf_se10_tab[0]; - move16(); *cf_off_se10 = cf_off_se10_tab; *cf_se11 = &cf_se11_tab[0][0][0]; - move16(); *cf_off_se11 = &cf_off_se11_tab[0][0]; - move16(); - BREAK; + break; case IGF_BITRATE_UNKNOWN: default: assert(0); } } + return retValue; } - diff --git a/src/libs/libevs/lib_com/index_pvq_opt.cpp b/src/libs/libevs/lib_com/index_pvq_opt.cpp new file mode 100644 index 00000000..95fbf046 --- /dev/null +++ b/src/libs/libevs/lib_com/index_pvq_opt.cpp @@ -0,0 +1,1159 @@ +/*==================================================================================== + EVS Codec 3GPP TS26.443 Nov 13, 2018. Version 12.11.0 / 13.7.0 / 14.3.0 / 15.1.0 + ====================================================================================*/ + +#include +#include +#include +#include "options.h" +#include "cnst.h" +#include "rom_com.h" +#include "prot.h" + + +/*-------------------------------------------------------------------* + * LOCAL DEFINITIONS + *-------------------------------------------------------------------*/ + +#define N_OPT 5 /* complexity setting, direct functional calculation limit */ +#define TABLE_LIM_OPT 96 /* odd divisor table recursion limit setting, due to dim 6 */ + +/* local typedefs for optimized pvq indexing, used only in this c-file to vectorize common function calls for c-code clarity */ +typedef void (*VEC2INDFUNCM) (const short* , short* , unsigned int*, unsigned int*); +typedef unsigned int (*NFUNCM) (short); +typedef unsigned int (*H_FUNCM) ( unsigned int ); +typedef void (*IND2VECFUNCM) ( short, short, unsigned int, short* ) ; +typedef void (*NDIM_FUNCM) ( short, short, unsigned int, short* ); + +typedef unsigned long long ui64; /* Basop Mpy32_32_uu simulation */ + +/* local constants for indexing functions c-code clarity */ +#ifndef ONE_U + +#define ZERO 0 +#define ONE 1 +#define ONE_U 1u +#define TWO 2 +#define SIGNBIT 0x80000000u + +#define MAXBIT 0x40000000L /* if Word32 */ +#define MINNEG 0xffffffffL + +#define UDIVBY3 2863311531U + + +/*-------------------------------------------------------------------* + * local_norm_l_opt + * + * rewritten version of STL norm_l for "int" fixed point normalization + * in floating point c-code. + *-------------------------------------------------------------------*/ +static +short local_norm_l_opt ( /* o : shifts needed for normalization */ + int l32var /* i : signed 32bit input value */ +) +{ + short l32res; + + + if (l32var == (int)MINNEG ) + { + return (32-ONE); + } + else + { + if (l32var == ZERO) + { + return ZERO; + } + else + { + if (l32var < ZERO) + { + l32var = ~l32var; + } + + for (l32res = ZERO; l32var < (int)MAXBIT; l32res++) + { + l32var <<= ONE; + } + } + } + + return (l32res); +} + + + +/*-------------------------------------------------------------------* + * floor_sqrt_exact() + * returns x = floor(sqrt(input)); where (x*x) <= input + *-------------------------------------------------------------------*/ +unsigned int floor_sqrt_exact( /* o : floor(sqrt(input)) */ + unsigned int input /* i : unsigned input [0.. UINT_MAX/4] */ +) +{ + double _tmp; + unsigned int x; + if (input == ZERO) + { + return ZERO; + } + + _tmp = (double) input ; + x = (unsigned int)(sqrt( _tmp )); /* floor is a part of the cast */ + return x; +} + +/*-------------------------------------------------------------------* + * f_odd_exact_div_opt() + * + * find 1/(den1*2+1) * ( num1p*num2p - num3) , + * if the result is known a priori to be exactly a 32bit unsigned integer + *-------------------------------------------------------------------*/ +static +unsigned int f_odd_exact_div_opt( /* o : see Eq. */ + unsigned int num1p, /* i : see Eq. */ + unsigned int num2p, /* i : see Eq. */ + unsigned int num3, /* i : see Eq. */ + unsigned int den1 /* i : see Eq. */ +) +{ + unsigned int tmp; + tmp = exactdivodd[den1] * (num1p*num2p - num3); + + return (tmp); +} + +/*---------------------------------------------------------------------------* + * f_even_exact_div_opt() + * + * returns (num1p*num2p - num3 )/ den1 + * if the result is known a priori to be exactly a 32bit unsigned integer + *--------------------------------------------------------------------------*/ +static +unsigned int f_even_exact_div_opt( /* o : see Eq. */ + unsigned int num1p, /* i : see Eq. */ + unsigned int num2p, /* i : see Eq. range should be larger than num1p */ + unsigned int num3, /* i : see Eq. */ + int den1 /* i : see Eq. */ +) +{ + unsigned int tmp1, oddfactor, UL_tmp; + int den1_m1; + short even_sh; + unsigned int UL_tmp_h; + ui64 ULL_tmp; + + den1_m1 = den1 - ONE; /* remove top bit */ + even_sh = (31) - local_norm_l_opt((den1_m1)^den1); /* NB STL operation defined for signed positive 32 bit variable */ + oddfactor = exactdivodd[den1_m1>>even_sh]; + even_sh -= ONE; + + ULL_tmp = (ui64)num1p*(ui64)num2p; /* use STL Mpy_32_32_uu functionality */ + UL_tmp_h = (unsigned int)(ULL_tmp>>32); /* high output from basicop */ + UL_tmp = (unsigned int) (ULL_tmp); /* low output from basicop */ + + if(num3 > UL_tmp) + { + UL_tmp_h = UL_tmp_h - ONE_U; + } + UL_tmp = (UL_tmp - num3); /* can and should underflow */ + UL_tmp = (UL_tmp_h<<(32-even_sh))|(UL_tmp>>even_sh); /* bitwise OR */ + + /* use tabled modular multiplicative inverse for the odd part division */ + tmp1 = UL_tmp*oddfactor; + + + return tmp1; +} + +/*-------------------------------------------------------------------* + * a_three() + *-------------------------------------------------------------------*/ +static +unsigned int a_three( /* o: offset for dim 3 */ + unsigned int k_val /* i: nb unit pulses */ +) /* k_val may be higher than 16 bit signed */ +{ + if( k_val ) + { + return (ONE_U + k_val*((k_val - ONE_U) << ONE)); + } + else + { + return ZERO; + } +} + +/*-------------------------------------------------------------------* + * a_four() + *-------------------------------------------------------------------*/ +static +unsigned int a_four( /* o: offset for dim 4 */ + unsigned int k_val /* i: nb unit pulses */ +) +{ + if(k_val) + { + return UDIVBY3*((k_val<0,k=0) */ + h_mem[1] = ONE_U; /* % A(*,k=1) */ + + if(dim_in==2) + { + for( k_val = TWO; k_val <= k_val_in; k_val++) + { + h_mem[k_val] = (unsigned int)((k_val<>1 ; + } + return; +} + + +/*-------------------------------------------------------------------* + * a_fwd() + * + * create offsets for A(n,k) from lower A(n-1,k) + *-------------------------------------------------------------------*/ +static +void a_fwd( + unsigned int *a_in, /* i/o: offsets */ + short n_items /* i : items, k's */ +) +{ + unsigned int a_1; + short i,i_prev; + unsigned int a_in0 ; /* i : start column value */ + + a_in0 = ONE_U; + i_prev=ZERO; + for(i=ONE; i <= n_items; i++) /*basic A fwd row recursion */ + { + a_1 = a_in0 + a_in[i_prev] + a_in[i] ; /* a_in addressed in at least two locations */ + a_in[i_prev] = a_in0; + a_in0 = a_1; + i_prev = i; /* no real need to count as it is a ptr update */ + } + a_in[i_prev] = a_in0; + + return; +} + +/*-------------------------------------------------------------------* + * a_bwd() + * + * create offsets for A(n,k) from higher A(n+1,k) + *-------------------------------------------------------------------*/ +static +void a_bwd( + unsigned int *a_in, /* i/o: offsets */ + short n_items /* i: n_items */ +) +{ + unsigned int a_1; + unsigned int a_in0; + short i; + short i_prev; + + a_in0 = ZERO; + i_prev = ZERO; + for(i=ONE; i<=n_items; i++) /*basic A reverse row recursion */ + { + a_1 = a_in[i] - a_in0 - a_in[i_prev]; + a_in[i_prev] = a_in0; + a_in0 = a_1; + i_prev = i; + } + a_in[i_prev] = a_in0; + return; +} + +static +unsigned int direct_row_A2U_rec_calc(short dim_in , short k_val_in, unsigned int a_km2, unsigned int a_km1) +{ + + /* U(n,k) = (A(n,k-2)-1)/2 + ((2*n-1)*A(n,k-1) - A(n,k-2) )/2*(k-1) */ + /* U(n,k) = floor(A(n,k-2)/2) + (n*A(n,k-1) - floor(A(n,k-1)/2) - floor(A(n,k-2)/2) +1 )/(k-1) */ + /* U(n,k) = floor(A(n,k-2)/2) + (n*A(n,k-1) - (floor(A(n,k-1)/2) + floor(A(n,k-2)/2) +1) ) /(k-1) */ + + unsigned int divisor, km2_size, result; + + divisor = (unsigned int)(k_val_in-ONE); + km2_size = (a_km1>>ONE) + (a_km2>>ONE) + ONE_U ; + + if(divisor&ONE_U) + { + /* odd */ + result = ( (a_km2>>ONE ) + f_odd_exact_div_opt((unsigned int)(dim_in), a_km1, km2_size , divisor>>ONE) ); + } + else + { + /* even divisor */ + result = ( (a_km2>>ONE) + f_even_exact_div_opt((unsigned int)dim_in,a_km1, km2_size, divisor ) ); + } + return result; +} + +static +void a_u_fwd( + unsigned int *a_u_in, + short k_val_in, + short mem_size_m1 +) +{ + unsigned int u_kp1_prev; + unsigned int a_k_prev ; + + /* mem_size_m1 = 1 + k_val_in */ + u_kp1_prev = a_u_in[mem_size_m1]; /* previous n U (n,k+1) value*/ + a_k_prev = a_u_in[k_val_in]; /* previous n A(n,k) value*/ + + a_fwd(&a_u_in[ONE], k_val_in); /* a_u_in[k==ZERO] = zero if n>0 */ + + /* low dynamic last offset entry mixed recursion */ + /* used for size calculation */ + /* U(n,k+1) = 1 + U(n-1,k+1) + U(n-1,k) + U(n,k) */ + /* U(n,k+1) = 1 + U(n-1,k+1) + (A(n-1,k)-1)/2 + (A(n,k)-1)/2 */ + /* Note, A(n,k) always odd for k>0 , subtracted one always shifted out */ + /* assert(a_k_prev>0, a_k-curr>0) */ + + a_u_in[mem_size_m1] = ONE_U + u_kp1_prev + (a_k_prev>>ONE) + (a_u_in[k_val_in] >>ONE); + + return; +} + +/*-------------------------------------------------------------------* + * nm_h_prep_opt() + * + * find and return N_MPVQ(n,k) and also offsets A(n, 0 to k ) and U(n,k+1). + *-------------------------------------------------------------------*/ +static +unsigned int nm_h_prep_opt( /* o: msize for dim */ + short dim_in, /* i: dimension */ + short k_val_in, /* i: nb unit pulses */ + unsigned int *h /* o: A/U offsets array */ +) +{ + short mem_size_m1, k_val ; + short dim_tmp, d_start; + unsigned int h_saveA, h_saveB; /* registers for alternating A(n,k-1), A(n,k-2)*/ + unsigned int numDsub1; /* k_val_curr, k_val_prev*/; + + mem_size_m1 = k_val_in + ONE; + + if( k_val_in > TABLE_LIM_OPT ) + { + if( dim_in >= 3 ) + { + d_start = 3; + } + else + { + d_start = 2; + } + initOffsets(d_start, h, k_val_in); + + for(dim_tmp = d_start; dim_tmp < dim_in; dim_tmp++) + { + a_u_fwd(h, k_val_in, mem_size_m1); + } + } + else + { + h[ZERO] = ZERO; + h[ONE] = ONE_U; + numDsub1=(unsigned int) ((dim_in << ONE) - ONE); + h[TWO] = numDsub1; + + /* interleaved odd even calls */ + h_saveA = numDsub1 ; + h_saveB = ONE_U; + for (k_val = 3; k_val < (mem_size_m1); k_val++ ) + { + /* A(n,k) = A(n,k-2) + ((2*n-1)*A(n,k-1)-A(n,k-2)) /(k-1) */ + /* first odd k, even divisor */ + h_saveB += f_even_exact_div_opt(numDsub1, h_saveA, h_saveB, k_val - ONE); + h[k_val] = h_saveB; + + k_val++; /* next even k, odd divisor */ + if( k_val >= (mem_size_m1)) + { + break; + } + h_saveA += f_odd_exact_div_opt(numDsub1, h_saveB, h_saveA, (k_val - ONE)>>ONE); + h[k_val] = h_saveA; + } + /* always do the last (k+1) recursion based on U(n,k+1) = func( A(n-2,k+1), A(n-1,k+1) ) */ + h[mem_size_m1] = direct_row_A2U_rec_calc(dim_in, mem_size_m1 , h[mem_size_m1-2], h[k_val_in]); + } + + /* N_MPVQ(n,k) = 1 + U(n,k+1) + U(n,k) = 1 + U(n,k+1) + (A(n,k)-1)/2 ; */ /* A(n,k) always odd */ + return ( ONE + h[mem_size_m1] + (h[k_val_in]>>ONE) ); +} + + +/* + find_amp_split_offset_func_mem() + find first offset in range 0..k_val_in that is less than ind_in + using a tree search with direct function calls or memory iteration +*/ +static +short find_amp_split_offset_func_mem( + unsigned int ind_in, + short k_val_in, + H_FUNCM h_func_ptr, /* i: offset function pointer */ + unsigned int *h_mem , + short k_test, /* o: k_value */ + unsigned int *tmp_offset /* o: offset found */ +) +{ + short not_ready, low,high ; + + low = 0; + high = k_val_in; + /* split over A(n,k)= h_mem(k), or use direct function */ + not_ready = ONE ; + while(not_ready) + { + k_test = (low+high)>>ONE; /*% split range in half */ + + if(h_mem) + { + *tmp_offset = h_mem[k_test]; /* memory search */ + } + else + { + *tmp_offset = (*h_func_ptr)((unsigned int)k_test); /* function search. NB only line difference to the memory search*/ + } + + if(ind_in > *tmp_offset ) + { + if(k_test < high) + { + low = 1 + k_test ; + } + else + { + not_ready=0; + } + } + else + { + if (*tmp_offset == ind_in ) + { + not_ready=0; + } + else + { + high = k_test - 1; + } + } + } + return k_test; +} + + +/* + get_lead_sign() + update index and return leading sign +*/ +static +short get_lead_sign(unsigned int *ind) +{ + short leading_sign; + + if( (*ind)&ONE_U) /* leading sign stored in LSB */ + { + leading_sign = -1; + } + else + { + leading_sign = 1; + } + (*ind) = (*ind)>>ONE; + + return leading_sign; +} + + +/*-------------------------------------------------------------------* + * mind2vec_one() + *-------------------------------------------------------------------*/ +static +void mind2vec_one( + short k_val_in, /* i: nb unit pulses */ + short leading_sign, /* i: leading sign */ + unsigned int ind, /* i: index */ + short *vec_out /* o: pulse train */ +) +{ + ind = 0; /* to avoid compiler warings */ + + vec_out[ind] = (leading_sign*k_val_in); /* NB input k_val_in can be zero */ +} + +/*-------------------------------------------------------------------* + * mind2vec_two() + *-------------------------------------------------------------------*/ +static +void mind2vec_two( + short k_val_in, /* i: nb unit pulses */ + short leading_sign, /* i: leading sign */ + unsigned int ind_in, /* i: index */ + short *vec_out /* o: pulse train */ +) +{ + unsigned int ind_tmp; + short val1; + + if(k_val_in > 0) /* k_val_in check */ + { + if (ind_in==0) + { + vec_out[0] = (leading_sign*k_val_in); + vec_out[1] = 0; + } + else if (ind_in == ( (unsigned int)(k_val_in<>ONE)); + vec_out[0] = leading_sign*(k_val_in - val1) ; + + if(ind_tmp&ONE_U) + { + vec_out[1] = -val1 ; + } + else + { + vec_out[1] = val1; + } + } + } +} + +static +short setval_update_sign( + short k_delta, + short k_max_local, + short *leading_sign, + unsigned int *ind_in, + short *vec_out +) +{ + if(k_delta != 0 ) + { + *vec_out = (*leading_sign)*k_delta; + *leading_sign = get_lead_sign(ind_in); + k_max_local = k_max_local-k_delta ; + } + return k_max_local; +} + +/*-------------------------------------------------------------------* + * mind2vec_three() + *-------------------------------------------------------------------*/ +static +void mind2vec_three( + short k_max_local, /* i: nb unit pulses */ + short leading_sign, /* i: leading sign */ + unsigned int ind_in, /* i: index */ + short *vec_out /* o: pulse train */ +) +{ + short k_delta ; + unsigned int acc_val; + + /* + use direct calculation of first amplitude + (to find amplitudes faster than using split or linear iteration) + */ + if(ind_in==0) + { + vec_out[0] = leading_sign*k_max_local; + } + else + { + acc_val = ((ONE_U + floor_sqrt_exact((ind_in<>ONE ); /* in BASOP use approximation + search for exact sqrt )*/ + + k_delta = k_max_local - (short)acc_val; + ind_in -= a_three(acc_val); /* remove amplitude offset A(n,k_acc) */ + + k_max_local = setval_update_sign( k_delta, k_max_local, &leading_sign,&ind_in,vec_out); + + mind2vec_two( k_max_local, leading_sign, ind_in ,&vec_out[1] ); + } + return; +} + +/*-------------------------------------------------------------------* + * mind2vec_direct , + general function for direct decoding using direct functions + (no memory recursion) + *-------------------------------------------------------------------*/ +static +void mind2vec_direct( + short k_max_local, /* i: nb unit pulses */ + short leading_sign, /* i: leading sign */ + unsigned int ind, /* i: index */ + H_FUNCM h_func_ptr, /* i : offset function */ + NDIM_FUNCM nd_func_ptr, /* i : next dimension function */ + short *vec_out /* o: pulse train */ +) +{ + short k_delta, k_test=0; + unsigned int tmp_offset; + + if(ind==0) + { + vec_out[0] = leading_sign*k_max_local; + } + else + { + k_test = find_amp_split_offset_func_mem(ind,k_max_local, h_func_ptr , NULL, k_test, &tmp_offset); + + k_delta = k_max_local - k_test; + ind = ind - tmp_offset; /* % remove amplitude offset A(n,k_acc) */ + k_max_local = setval_update_sign( k_delta, k_max_local, &leading_sign, &ind,vec_out); + (*nd_func_ptr)( k_max_local, leading_sign, ind , &vec_out[1] ); + } + return; +} + +/*-------------------------------------------------------------------* + * mind2vec_four() + *-------------------------------------------------------------------*/ +static +void mind2vec_four( + short k_val_in, /* i: nb unit pulses */ + short leading_sign, /* i: leading sign */ + unsigned int ind_in, /* i: index */ + short *vec_out /* o: pulse train */ +) +{ + mind2vec_direct(k_val_in,leading_sign, ind_in, a_four, mind2vec_three, vec_out); + return; +} + +/*-------------------------------------------------------------------* + * mind2vec_five() + *-------------------------------------------------------------------*/ +static +void mind2vec_five( + short k_val_in , /* i: nb unit pulses */ + short leading_sign, /* i: leading sign */ + unsigned int ind_in, /* i: index */ + short *vec_out /* o: pulse train */ +) +{ + mind2vec_direct(k_val_in,leading_sign, ind_in, a_five, mind2vec_four, vec_out); + return; +} + + +/*-------------------------------------------------------------------* + * mind2vec() + *-------------------------------------------------------------------*/ +static +void mind2vec( + short dim_in, /* i: dimension */ + short k_max_local, /* i: nb unit pulses */ + short leading_sign, /* i: leading sign */ + unsigned int ind, /* i: index */ + short *vec_out, /* o: pulse train */ + unsigned int *h_in /* i: offset vector A=1+2U */ +) +{ + short pos; + short k_acc, k_delta; + unsigned int tmp_offset; + + k_acc = k_max_local; + + pos = ZERO; + while (pos < dim_in) /* first to last position decoding */ + { + if(ind == 0) + { + vec_out[pos] = leading_sign*k_max_local; + break; /* "fast" recursion exit */ + } + else + { + { + /* linear magnitude search */ + k_acc = k_max_local; + tmp_offset = h_in[k_acc]; + while(tmp_offset > ind) + { + k_acc = k_acc - 1; + tmp_offset = h_in[k_acc]; + } + } + k_delta = k_max_local - k_acc; /* amplitude decoding */ + } + ind = ind - tmp_offset; /* remove amplitude index offset A(n,k_acc) */ + + k_max_local = setval_update_sign( k_delta, k_max_local, &leading_sign, &ind, &vec_out[pos]); + + /* move from A(n,kmax) to A(n-1, k_max_local), */ + a_bwd( h_in,k_max_local + 1 ); /* [0..k_max_local], no need to calculate U(n,k_max_local+1) in index decoding */ + pos = pos + 1; + } + return; +} + + +/*-------------------------------------------------------------------* + * vec2mind_one() + *-------------------------------------------------------------------*/ +static +void vec2mind_one( + const short *vec_in, /* i : PVQ abs pulse train */ + short *k_val_out_ptr , /* o : number of unit pulses */ + unsigned int *next_sign_ind, /* i/o: next sign ind */ + unsigned int *ind /* o : MPVQ index */ +) +{ + *k_val_out_ptr = -1; /* just to avoid compiler warnings */ + + *ind = ZERO; + /* *k_val_out_ptr = (short)abs(*vec_in); */ /* dim==1, function not called recursively */ + *next_sign_ind = (unsigned int)(*vec_in < ZERO); /* single sign always pushed out of MPVQ */ + return; +} + +/*-------------------------------------------------------------------* +* vec2mind_two() +*-------------------------------------------------------------------*/ +static +void vec2mind_two( + const short *vec_in, /* i : PVQ pulse train */ + short *k_val_out_ptr, /* o : number of unit pulses */ + unsigned int *next_sign_ind, /* i/o: next sign ind */ + unsigned int *ind /* o: MPVQ index */ +) +{ + unsigned int lead_sign_ind; + short abs0,abs1,abs01; + + abs0 = (short) abs(vec_in[0]); + abs1 = (short) abs(vec_in[1]); + + abs01 = abs0+abs1; + *k_val_out_ptr = abs01; + + if(abs01==0) /* zeroes can happen in a recursive encoding call */ + { + *next_sign_ind = SIGNBIT; + *ind = ZERO; + } + else + { + *next_sign_ind=0; + if(abs1 == 0) + { + *ind = ZERO; + } + else if(abs0 == 0) + { + *ind = (unsigned int)(abs1< 0 ) + { + *k_val_out_ptr += tmp_val; + } + else + { + *k_val_out_ptr -= tmp_val; + } + return ; +} + + +/*-------------------------------------------------------------------* + * vec2mind_three() + *-------------------------------------------------------------------*/ +static +void vec2mind_three( + const short *vec_in, /* i : PVQ pulse train */ + short *k_val_out_ptr, /* o : number of unit pulses */ + unsigned int *next_sign_ind, /* i/o: next sign ind */ + unsigned int *index /* o: MPVQ index */ +) +{ + + + vec2mind_gen345(vec_in,k_val_out_ptr, next_sign_ind, index, vec2mind_two, a_three); + + return ; +} + +/*-------------------------------------------------------------------* + * vec2mind_four() + *-------------------------------------------------------------------*/ +static +void vec2mind_four( + const short *vec_in, /* i : PVQ pulse train */ + short *k_val_out_ptr, /* o : number of unit pulses */ + unsigned int *next_sign_ind, /* i/o: next sign ind */ + unsigned int *index /* o: MPVQ index */ +) +{ + + vec2mind_gen345(vec_in,k_val_out_ptr, next_sign_ind, index, vec2mind_three, a_four); + + return ; +} + +/*-------------------------------------------------------------------* + * vec2mind_five() + *-------------------------------------------------------------------*/ +static +void vec2mind_five( + const short *vec_in, /* i : PVQ abs pulse train */ + short *k_val_out_ptr, /* o : number of unit pulses */ + unsigned int *next_sign_ind, /* i/o: next sign ind */ + unsigned int *index /* o: MPVQ index */ +) +{ + + vec2mind_gen345(vec_in,k_val_out_ptr, next_sign_ind, index, vec2mind_four, a_five); + + return ; +} + + + +/*-------------------------------------------------------------------* + * vec2mind() + *-------------------------------------------------------------------*/ +static +void vec2mind( + short dim_in, /* i : dim */ + short k_val_in, /* i : number of unit pulses */ + const short *vec_in, /* i : PVQ pulse train */ + unsigned int *next_sign_ind, /* o : pushed leading sign */ + unsigned int *index , /* o : MPVQ index */ + unsigned int *N_MPVQ_ptr, /* o : size(N_MPVQ(dim,K_val_in))*/ + unsigned int *h_mem /* o : offsets */ +) +{ + short pos, mem_size_m1 ; + short k_val_acc ; + short tmp_val; + + + mem_size_m1 = k_val_in + ONE; + + *next_sign_ind = SIGNBIT; /* % should always be 0 or 1 out, highest bit set signals no sign found yet*/ + + + pos = dim_in - 2; /* % address 2nd last sample */ + vec2mind_two(&vec_in[pos],&k_val_acc,next_sign_ind ,index); + initOffsets( 3, h_mem, k_val_in) ; + + + for (pos--; pos>=0; pos--) + { + /* + % Check if the leading sign 'bit' is to be added + */ + tmp_val = vec_in[pos]; + if( ((*next_sign_ind&SIGNBIT)==0 && (tmp_val != 0)) ) + { + *index = (*index<0 */ + + k_val_acc += (short)abs(tmp_val);/*% now increase acc k value for next N */ + + + if(pos) + { + a_u_fwd(h_mem, k_val_in ,mem_size_m1); + /*% update A(n,k=1:k_val_in) and U(n,k_val_in+1) , NB here (k_val_in + 2 elements always has to be updated */ + } + } + + /* size is needed for the subseqent arithmetic encoding/transmission of the index. */ + /* use relation N_MPVQ(n,K) = 1 + (A(n, K)-1)/2 + U(n, 1 + K) */ + /* = N_MPVQ(n,K) = 1 + (A(n, K)>>1) + U(n, 1 + K) , as A(n,K) is odd) */ + + *N_MPVQ_ptr = ONE_U + (h_mem[k_val_acc]>>ONE) + h_mem[ mem_size_m1 ] ; /* total size size */ + + return; +} + +/*--------------------------------------------------------------------------* + * mpvq_encode_vec() + * + * returns struct with leading sign index, MPVQ-index , dim and N_MPVQ + *-------------------------------------------------------------------------*/ + +PvqEntry mpvq_encode_vec( /* o : leading_sign_index, index, size, k_val */ + const short *vec_in, /* i : signed pulse train */ + short dim_in, /* i : dimension */ + short k_val_local /* i : nb unit pulses */ +) +{ + PvqEntry result; + unsigned int h_mem[1+KMAX_NON_DIRECT+1]; /* allocate max offset memory for dim 6 */ + /* OPT: actually only 1+k_val_in+1 needed ) */ + unsigned int lead_sign_ind; + + VEC2INDFUNCM vec2mind_f[1+N_OPT] = { (VEC2INDFUNCM)NULL, vec2mind_one, vec2mind_two, vec2mind_three, vec2mind_four, vec2mind_five }; + /* VEC2INDFUNCM can be a static global */ + + + result.k_val = k_val_local; + result.dim = dim_in; + + /* NB, k_val_local may be changed in some sub encoding routines */ + if( dim_in > N_OPT) /* use the generic dimension function */ + { + vec2mind(dim_in, k_val_local, vec_in, &lead_sign_ind, &result.index, &result.size, h_mem); + } + else /* if (dim_in<=N_OPT) */ + { + (vec2mind_f[dim_in])(vec_in, &k_val_local, &lead_sign_ind, &result.index); + result.size = direct_msize(dim_in, k_val_local); /* k_val_local not used for dim==1 */ + } + result.lead_sign_ind=(short)lead_sign_ind; + + return result; +} + +/*-------------------------------------------------------------------* + * get_size_mpvq_calc_offset() + * + * unsigned int h_mem[1 + KMAX +1 ]; + * example using fixed size of offset vector input help variable + *-------------------------------------------------------------------*/ + +PvqEntry get_size_mpvq_calc_offset( /* o : size, dim, k_val */ + short dim_in, /* i : dimension */ + short k_val_in, /* i : nb unit pulses */ + unsigned int* h_mem /* o : offsets */ +) +{ + PvqEntry entry; + + entry.dim = dim_in; + entry.k_val = k_val_in; + entry.index = 0U; /* avoid gcc warning in struct passing */ + entry.lead_sign_ind = 0; /* avoid gcc warning in struct passing */ + if(dim_in > N_OPT ) /* non-direct solutions, use A+U relation */ + { + entry.size = nm_h_prep_opt(entry.dim, entry.k_val, h_mem); + } + else + { + entry.size = direct_msize(dim_in, entry.k_val); /* ues equations, h_mem is not used */ + } + + + return entry; +} + +/*-------------------------------------------------------------------* + * mpvq_decode_vec() + *-------------------------------------------------------------------*/ + +void mpvq_decode_vec( /* o : void */ + const PvqEntry *entry, /* i : sign_ind, index, dim, k_val */ + unsigned int *h_mem, /* i : A/U offsets */ + short *vec_out /* o : pulse train */ +) +{ + short i, leading_sign; + IND2VECFUNCM mind2vec_f[N_OPT+1] = { (IND2VECFUNCM)NULL, mind2vec_one, mind2vec_two, mind2vec_three, mind2vec_four, mind2vec_five }; + /*IND2VECFUNCM vector can be static global */ + + + for(i=0; idim; i++) + { + vec_out[i]=ZERO; /* set all of short output vector to zero */ + } + + leading_sign = 1; + if(entry->lead_sign_ind) + { + leading_sign = -1; + } + + if(entry->k_val != 0) + { + if(entry->dim > N_OPT ) /* N_OPT */ + { + /* generic */ + mind2vec(entry->dim, entry->k_val, leading_sign, entry->index, vec_out, h_mem); + } + else + { + /* specialized functions */ + (mind2vec_f[entry->dim])(entry->k_val, leading_sign, entry->index, vec_out); + } + } + return; +} + +#ifdef ONE_U +#undef ZERO +#undef ONE +#undef ONE_U +#undef TWO +#undef MAXBIT +#undef MINNEG +#undef SIGNBIT +#undef UDIVBY3 +#endif + + + +#endif diff --git a/src/libs/libevs/lib_com/index_pvq_opt_fx.cpp b/src/libs/libevs/lib_com/index_pvq_opt_fx.cpp deleted file mode 100755 index 2e2dacc3..00000000 --- a/src/libs/libevs/lib_com/index_pvq_opt_fx.cpp +++ /dev/null @@ -1,1187 +0,0 @@ -/*==================================================================================== - EVS Codec 3GPP TS26.442 Apr 03, 2018. Version 12.11.0 / 13.6.0 / 14.2.0 - ====================================================================================*/ - -#include "options.h" -#include "cnst_fx.h" /* Common constants */ -#include "rom_com_fx.h" /* Static table prototypes */ -#include "prot_fx.h" /* Function prototypes */ -#include "stl.h" /* required for wmc_tool */ -#include "basop_util.h" -#include - -#define N_OPT_FX 5 /* complexity setting, direct functional calculation limit & low dim recursion limit */ -#define TABLE_LIM_OPT_FX 96 /* odd divisor table , N-row_recursion limit setting, due to dim */ - - -/* local typedefs for optimized pvq indexing, used locally c-file to vectorize common function calls */ -typedef void (*VEC2INDFUNCM) (const Word16* , Word16* , UWord32*, UWord32*); -typedef UWord32 (*NFUNCM) (Word16); -typedef UWord32 (*H_FUNCM) ( UWord32 ); -typedef void (*IND2VECFUNCM) ( Word16, Word16, UWord32, Word16* ) ; -typedef void (*NDIM_FUNCM) ( Word16, Word16, UWord32, Word16* ); - -/* local constants for indexing functions */ -#define SIGNBIT_FX 0x80000000u -#define SIGNBIT_SHRT_FX 0x8000 -#define UDIVBY3_FX 2863311531U - -/*-------------------------------------------------------------------* - * f_odd_exact_div_opt_fx() - * - * find 1/(den1*2+1) * ( num1p*num2p - num3) , - * if the result is known a priori to be exactly a 32bit UWord32 - *-------------------------------------------------------------------*/ -static -UWord32 f_odd_exact_div_opt_fx( /* o : see Eq. */ - UWord32 num1p, /* i : see Eq. */ /* (2n-1) or n , i.e can be short also */ - UWord32 num2p, /* i : see Eq. */ - UWord32 num3, /* i : see Eq. */ - Word16 den1 /* i : see Eq. */ /*range [0..127] can be made to short */ -) -{ - UWord32 UL_tmp; - UL_tmp = UL_Mpy_32_32(exactdivodd_fx[den1],UL_subNsD(UL_Mpy_32_32(num1p,num2p),num3)); - - return (UL_tmp); -} - -/*---------------------------------------------------------------------------* - * f_even_exact_div_opt_fx() - * - * returns (num1p*num2p - num3 )/ den1 - * if the result is known a priori to be exactly a 32bit unsigned integer - *--------------------------------------------------------------------------*/ -static -UWord32 f_even_exact_div_opt_fx( /* o : see Eq. */ - UWord32 UL_num1p, /* i : see Eq. 2n-1 or n can be short input */ - UWord32 UL_num2p, /* i : see Eq. range should be larger than num1p */ - UWord32 UL_num3, /* i : see Eq. */ - Word16 den1 /* i : see Eq. */ -) -{ - UWord32 UL_tmp, UL_oddfactor; - Word16 den1_m1, even_sh; - UWord32 UL_tmp_h; - UWord16 sgn; - - den1_m1 = sub(den1,1); /* remove top bit */ - even_sh = sub(15, norm_s(s_xor(den1_m1, den1))); /* STL signed ops ok as den1 <= 127 */ - - UL_oddfactor = exactdivodd_fx[lshr(den1_m1,even_sh)]; - move32(); - even_sh = sub(even_sh,1); - - - Mpy_32_32_uu(UL_num1p, UL_num2p, &UL_tmp_h, &UL_tmp); /* cost ~4 */ - UL_tmp = UL_subNs(UL_tmp,UL_num3,&sgn); /* may wrap for underflow */ - if(sgn) /* underflow */ - { - UL_tmp_h = UL_subNsD(UL_tmp_h,1U); /* single basicop -> if */ - } - UL_tmp = UL_or(UL_lshl(UL_tmp_h,sub(32,even_sh)), UL_lshr(UL_tmp,even_sh)); - /* total cost 9-11 , old solution had 15-16*/ - - /* now use tabled modular multiplicative inverse for the odd part division */ - return UL_Mpy_32_32(UL_tmp, UL_oddfactor); -} - -/* direct calculation functions for smaller dimensions to speed up indexing - -N_MPVQ(1,k) = 1; -N_MPVQ(2,k) = k*2; -N_MPVQ(3,k) = 1+2*(k^2); -N_MPVQ(4,k) = k/3 * 4*(k^2+2); -N_MPVQ(5,k) = 1 + 2*(k*k*(5+k*k))/3; -N_MPVQ(*,k) = iterations = 1 + A(n,k) + A(n+1,k); - -N_PVQ(n,k) = 2*N_MPVQ(n,k); - - -A(1,k) = 1; -A(2,k) = -1 + 2k; -A(3,k) = 1+2(k-1)k; -A(4,k) = 1/3*(((4k-6)k+8)*k-3), -A(5,k) = 1/3*(3+ k(10+2(k-2)k)k-8); -A(*,k) = recursive iterations; - - -U(n,k) = (A(n,k)-1)/2; -U(1,k) = 0; -U(2,k) = k-1; -U(3,k) = k*(k-1) -U(4,k) = (1/3)*((k - 1)*(2*k^2 - k + 3)) -U(5,k) = (1/3)*(k*(k - 1)*(k^2 - k + 4)) -U(*,k) = recursive iterations; - -U(n,k) = U(k,n); -U(n,k) = func(n, U(n,k-1), U(n,k-2) , 1/(k-1) ); -U(n,k) = 1 + U(n-1,k-1) + U(n-1,k) + U(n,k-1); -U(n,k) = 1 + A(n-1,k-1)>>1 + A(n-1,k)>>1 + A(n,k-1)>>1; A(n,k) is always odd if k>0 -*/ - -/*-------------------------------------------------------------------* - * a_three_fx() - *-------------------------------------------------------------------*/ -static -UWord32 a_three_fx( /* o: offset for dim 3 */ - UWord32 k_val /* i: nb unit pulses */ -) /* k_val may be higher than 16 bit signed */ -{ - IF( k_val ) - { - /* return (ONE_U + k_val*((k_val - ONE_U) << ONE)); */ - return UL_addNsD(1U,UL_Mpy_32_32(k_val,UL_lshl(UL_subNsD(k_val,1U),1))); - } - ELSE - { - return 0; - } -} - -/*-------------------------------------------------------------------* - * a_four_fx() - *-------------------------------------------------------------------*/ -static -UWord32 a_four_fx( /* o: offset for dim 4 */ - UWord32 k_val /* i: nb unit pulses */ -) -{ - UWord32 UL_2k; - IF(k_val) - { - /* return UDIVBY3*((k_val<0,k=0) */ - h_mem[1] = UL_deposit_l(1); /* A(*,k=1) */ - - UL_k_val_in = UL_deposit_l(k_val_in); - IF(sub(dim_in,2)==0) - { - FOR( k_val = 2 ; k_val <= UL_k_val_in ; k_val++ ) - { - h_mem[k_val] = UL_subNsD(UL_lshl(k_val,1),1U); - move32(); /* A(2, 2 .. k ) */ - } - h_mem[k_val] = UL_k_val_in; - move32(); /* U(2,k+1) */ - } - ELSE - { - k_val_prev = UL_deposit_l(1U); - FOR(k_val_curr = 2; k_val_curr<=UL_k_val_in; k_val_curr++) - { - h_mem[k_val_curr] = UL_addNsD(1U , UL_Mpy_32_32(k_val_curr, UL_lshl(k_val_prev,1))); - move32(); - k_val_prev = UL_addNsD(k_val_curr, 0U); /* 1 op*/ - } - h_mem[k_val_curr] = UL_Mpy_32_32(k_val_curr,k_val_prev); - move32(); /* % U(3,k_val_in+1) u_three(k+1) */ - } - - return; -} - -/*-------------------------------------------------------------------* - * a_fwd_fx() - * - * create offsets for A(n,k) from lower A(n-1,k) - *-------------------------------------------------------------------*/ -static -void a_fwd_fx( - UWord32 *a_in, /* i/o: offsets */ - Word16 n_items /* i : items, k's */ -) -{ - UWord32 a_1, a_in0 ; - Word16 i ; - UWord32* a_in_prev_ptr; - - a_in0 = UL_deposit_l(1); - - a_in_prev_ptr=&(a_in[-1]); /* single loop ptr setup not counted; */ - FOR(i=1; i<=n_items; i++) /* basic A fwd row recursion */ - { - a_1 = UL_addNsD(a_in0, UL_addNsD(a_in_prev_ptr[i], a_in[i])) ; - a_in_prev_ptr[i] = a_in0; - move32(); - a_in0 = UL_addNsD(a_1, 0U); - } - a_in_prev_ptr[i] = a_in0; - move32(); - return; -} - -/*-------------------------------------------------------------------* - * a_bwd_fx() - * - * create offsets for A(n,k) from higher A(n+1,k) - *-------------------------------------------------------------------*/ -static -void a_bwd_fx( - UWord32 *a_in, /* i/o: offsets */ - Word16 n_items /* i: n_items */ -) -{ - UWord32 a_1, a_in0; - Word16 i; - UWord32* a_in_prev_ptr; - - a_in0 = UL_deposit_l(0); - a_in_prev_ptr = &(a_in[-1]); - - FOR(i = 1; i<=n_items; i++) /*basic A reverse row recursion */ - { - /* 2x[i] ptr memory access below are treated as ptr access */ - a_1 = UL_subNsD(UL_subNsD(a_in[i], a_in0), a_in_prev_ptr[i]); - a_in_prev_ptr[i] = a_in0; - move32(); - a_in0 = UL_addNsD(a_1, 0U); - - } - a_in_prev_ptr[i] = a_in0; - move32(); - return; -} - -static -UWord32 direct_row_A2U_rec_calc_fx(Word16 dim_in , Word16 k_val_in, UWord32 a_km2, UWord32 a_km1) -{ - /* U(n,k) = (A(n,k-2)-1)/2 + ((2*n-1)*A(n,k-1) - A(n,k-2) )/2*(k-1) */ - /* U(n,k) = floor(A(n,k-2)/2) + (n*A(n,k-1) - floor(A(n,k-1)/2) - floor(A(n,k-2)/2) +1 )/(k-1) */ - /* U(n,k) = floor(A(n,k-2)/2) + (n*A(n,k-1) - (floor(A(n,k-1)/2) + floor(A(n,k-2)/2) +1) )/(k-1) */ - - UWord32 km2_size, UL_um2, UL_dim ; - Word16 divisor; - - divisor = sub(k_val_in,1); - UL_um2 = UL_lshr(a_km2,1U); - UL_dim = UL_deposit_l(dim_in); - km2_size = UL_addNsD(UL_addNsD(UL_lshr(a_km1,1), UL_um2), 1U); - IF(s_and(divisor,0x1) != 0) - { - /* odd */ - return UL_addNsD(UL_um2, f_odd_exact_div_opt_fx( UL_dim, a_km1, km2_size, shr(divisor,1))); - } - ELSE - { - /* even divisor, */ - return UL_addNsD(UL_um2, f_even_exact_div_opt_fx(UL_dim, a_km1, km2_size, divisor)); - } -} - -static -void a_u_fwd_fx(UWord32 *a_u_in, - Word16 k_val_in, - Word16 mem_size_m1) -{ - UWord32 u_kp1_prev, u_kp1; - UWord32 u_k_prev ; - - u_kp1_prev = a_u_in[mem_size_m1]; - move32(); /* previous n U (n,k+1) value*/ - u_k_prev = UL_lshr(a_u_in[k_val_in],1); /* previous n A(n,k) value*/ - - a_fwd_fx(&a_u_in[1], k_val_in); /* a_u_in[k==ZERO] = zero if n>0 */ - - /* low dynamic last offset entry mixed recursion */ - /* used for size calculation */ - /* U(n,k+1) = 1 + U(n-1,k+1) + U(n-1,k) + U(n,k) */ - /* U(n,k+1) = 1 + U(n-1,k+1) + (A(n-1,k)-1)/2 + (A(n,k)-1)/2 */ - /* Note, A(n,k) always odd for k>0 , subtracted one always shifted out */ - - u_kp1 = UL_lshr(a_u_in[k_val_in],1); - a_u_in[mem_size_m1] = UL_addNsD(1U, UL_addNsD(u_kp1_prev, UL_addNsD(u_k_prev,u_kp1))); - return; -} - -/*-------------------------------------------------------------------* - * nm_h_prep_opt_fx() - * - * find and return N_MPVQ(n,k) and also offsets A(n, 0 to k ) and U(n,k+1). - *-------------------------------------------------------------------*/ -static -UWord32 nm_h_prep_opt_fx( /* o: msize for dim */ - Word16 dim_in, /* i: dimension */ - Word16 k_val_in, /* i: nb unit pulses */ - UWord32 *h /* o: A/U offsets array */ -) -{ - Word16 mem_size_m1, k_val,tmp ; - Word16 dim_tmp, d_start; - UWord32 h_saveA, h_saveB, u_kp1,a_k; /* registers for alternating A(n,k-1), A(n,k-2)*/ - UWord32 numDsub1; - Word16 end_loop, add_last_odd ; - - h[0] = UL_deposit_l(0); /* % A(=>0,k=0) */ - h[1] = UL_deposit_l(1); /* % A(*,k=1) */ - - mem_size_m1 = add(k_val_in,1); - - assert(dim_in > N_OPT_FX); /* code now optimized with direct functions for dim <= N_OPT_FX ) */ - IF( (sub(k_val_in, TABLE_LIM_OPT_FX) > 0) ) - { - d_start = 2; - move16(); - if( sub(dim_in,3) >= 0 ) - { - /* start from A(3), U(3) */ - d_start = 3; - move16(); /* single op */ - } - initOffsets_fx(d_start, h, k_val_in); - FOR(dim_tmp = d_start; dim_tmp < dim_in; dim_tmp++) - { - a_u_fwd_fx(h, k_val_in, mem_size_m1); - } - a_k = h[k_val_in]; - move32(); - u_kp1 = h[mem_size_m1]; - move32(); - } - ELSE - { - numDsub1 = UL_deposit_l(sub(shl(dim_in,1),1)); - h[2] = numDsub1; - move32(); - - /* interleaved " odd, even [odd]" divisor calls */ - h_saveA = numDsub1; - move32(); - h_saveB = UL_deposit_l(1); - - /* OPT: makes sure that the STL FOR loop is not broken */ - tmp = sub(k_val_in,3); - add_last_odd = 0; - move16() ; /*k_val_in=0 1 2*/ - if(tmp == 0) - { - add_last_odd = 1; - move16(); /*k_val_in =3 */ - } - k_val = 3; - move16(); - IF( tmp > 0 ) - { - /* k_val_in = 3,4, 5,6, 7 ... */ - end_loop = mem_size_m1; - move16(); - add_last_odd = s_and(k_val_in,0x1) ; - move16(); /* odd -> 0x00100*/ - /* even loop limits, and odd tail exists , and */ - if(add_last_odd != 0 ) - { - end_loop = sub(end_loop,1); /* make initial loop to even number of (odd-even )pairs *//* one basicop */ - } - FOR(k_val = 3; k_val < end_loop ; k_val++ ) - { - /* the optimized non broken loop k=(3,4)(5,6)...(odd,even)*/ - /* A(n,k) = A(n,k-2) + ((2*n-1)*A(n,k-1)-A(n,k-2)) /(k-1) */ - /* first odd k, even divisor */ - h_saveB = UL_addNsD(h_saveB, f_even_exact_div_opt_fx(numDsub1, h_saveA, h_saveB, sub(k_val,1))); - h[k_val] = h_saveB; - move32(); - - /* next even k, odd divisor */ - /*k_val++; */ - h_saveA = UL_addNsD(h_saveA, f_odd_exact_div_opt_fx(numDsub1, h_saveB, h_saveA,shr(k_val,1))); - k_val++; /* ptr incr */ - h[k_val] = h_saveA; - move32(); - } - } - - IF( add_last_odd != 0 ) - { - /* add a last odd call as needed , not to be called if k_val_in is [0,1,2] */ - h_saveB = UL_addNsD(h_saveB,f_even_exact_div_opt_fx(numDsub1, h_saveA, h_saveB, sub(k_val,1))); - h[k_val_in] = h_saveB; - move32(); - } - - /* always do the last (k+1) recursion based on U(n,k+1) = func( A(n-2,k+1), A(n-1,k+1) ) */ - a_k = h[k_val_in] ; - move32(); - u_kp1 = direct_row_A2U_rec_calc_fx(dim_in, mem_size_m1 , h[sub(mem_size_m1,2)], a_k ); - h[mem_size_m1] = u_kp1; - move32(); - } - - /* N_MPVQ(n,k) = 1 + U(n,k+1) + U(n,k) = 1 + U(n,k+1) + floor(A(n,k))/2) ; */ /* as A(n,k) always odd */ - return ( UL_addNsD(1U, UL_addNsD(u_kp1, UL_lshr(a_k,1)))); -} - -/* - find_amp_split_offset_func_mem_fx() - find first offset in range 0..k_val_in that is less than ind_in - using a tree search with direct function calls [ or memory iteration] -*/ -static -Word16 find_amp_split_offset_func_mem_fx( /* o: found k_value */ - UWord32 ind_in, - Word16 high, /* i: k_val_in (high bound) */ - H_FUNCM h_func_ptr, /* i: offset function pointer */ - UWord32 *UL_tmp_offset) /* o: offset found */ -{ - Word16 not_ready, low, k_test=0; - UWord16 sgn ; - UWord32 UL_tmp; - /* split over A(n,k) = h_mem(k), or use direct A function evaluation */ - - low = 0; - move16(); - move32(); /* account for adaptive function ptr setup */ - not_ready = 1 ; - move16(); - - WHILE( not_ready != 0) - { - k_test = shr(add(low,high),1); /*% split range in half */ - *UL_tmp_offset = (*h_func_ptr)(UL_deposit_l(k_test)); /* call direct A offset-function */ - - UL_tmp = UL_subNs(*UL_tmp_offset, ind_in, &sgn ); - IF ( sgn ) - { - /* (*tmp_offset < ind_in) */ - low = add(1, k_test) ; - if( sub(k_test ,high) >= 0) - { - not_ready = 0; - move16(); /* single basicop */ - } - } - ELSE - { - /* (ind_in <= *tmp_offset ) */ - high = sub(k_test,1); - if( UL_tmp == 0) - { - /* (*tmp_offset == ind_in) */ - not_ready = 0; - move16(); /* single basicop */ - } - } - } - return k_test; -} - -/* - get_lead_sign_fx() - updated index and return leading sign -*/ -static -Word16 get_lead_sign_fx(UWord32 *ind) -{ - Word16 leading_sign; - - leading_sign = 1; - move16(); - if( UL_and(*ind,1) != 0 ) - { - /* leading sign stored in LSB */ - leading_sign = -1; - move16(); - } - (*ind) = UL_lshr(*ind,1); - - return leading_sign; -} - -/*-------------------------------------------------------------------* - * mind2vec_one_fx() - *-------------------------------------------------------------------*/ -static -void mind2vec_one_fx( - Word16 k_val_in, /* i: nb unit pulses */ - Word16 leading_sign, /* i: leading sign -1, 0, 1*/ - UWord32 ind, /* i: index */ /* parameter needed as it is used in a function array */ - Word16* vec_out /* o: pulse train */ -) -{ - /* NB input k_val_in can be zero */ - /* *vec_out = leading_sign*k_val_in; */ - *vec_out = (Word16)ind; /* dummy assignment to avoid gcc "unused parameter" warning for ind, i.e no move16() needed */ - - /* *vec_out = extract_l(L_mult0(leading_sign,k_val_in)); move16(); // 3 ops */ - if( leading_sign < 0 ) - { - k_val_in = negate(k_val_in); /* single basicop --> if */ - } - *vec_out = k_val_in; - move16(); /* 1 op */ -} - -static -void mind2vec_two_fx( - Word16 k_val_in, /* i: nb unit pulses */ - Word16 leading_sign, /* i: leading sign -1,0, 1 */ - UWord32 ind_in, /* i: index */ - Word16 *vec_out /* o: pulse train */ -) -{ - UWord32 UL_ind_tmp; - Word16 val1; - - IF (ind_in == 0) - { - /* ind_in == 0 */ - mind2vec_one_fx( k_val_in,leading_sign,ind_in,vec_out); - } - ELSE IF ( sub((Word16)u_extract_l(ind_in), sub(shl(k_val_in,1),1)) == 0 ) - { - /* signed ops fine as 2*KMAX << 32767) */ - /* (ind_in == ( (unsigned int)(k_val_in< 0 ) /* non-direct solutions, use A+U relation */ - { - entry.size = nm_h_prep_opt_fx(entry.dim, entry.k_val, h_mem); - } - ELSE - { - entry.size = direct_msize_fx(dim_in, entry.k_val); - } - - return entry; -} - -/*-------------------------------------------------------------------* - * mpvq_decode_vec_fx() - *-------------------------------------------------------------------*/ -void mpvq_decode_vec_fx( /* o : void */ - const PvqEntry_fx* entry, /* i : sign_ind, index, dim, k_val */ - UWord32* h_mem, /* i : A/U offsets */ - Word16* vec_out /* o : pulse train */ -) -{ - Word16 i, leading_sign; - IND2VECFUNCM mind2vec_f_fx[N_OPT_FX+1] = { (IND2VECFUNCM)NULL, mind2vec_one_fx, mind2vec_two_fx, mind2vec_three_fx, mind2vec_four_fx, mind2vec_five_fx }; - - FOR(i=0; idim; i++) - { - vec_out[i]=0; - move16(); /* set all of short vector to zero , required for fast/early exit logic */ - } - - leading_sign = 1; - move16(); - if(entry->lead_sign_ind != 0) - { - leading_sign = -1; - move16(); - } - - IF(entry->k_val != 0) - { - IF(sub(entry->dim,N_OPT_FX)> 0 ) /* N_OPT_FX */ - { - /* generic */ - mind2vec_fx(entry->dim, entry->k_val, leading_sign, entry->index, vec_out, h_mem); - } - ELSE - { - /* specialized functions, with direct offset calculations */ - (mind2vec_f_fx[entry->dim])(entry->k_val, leading_sign, entry->index, vec_out); - } - } - - return; -} - -/*-------------------------------------------------------------------* -* vec2mind_one_fx() -*-------------------------------------------------------------------*/ -static -void vec2mind_one_fx( - const Word16* vec_in, /* i : PVQ pulse train */ - Word16 *k_val_out_ptr , /* o : number of unit pulses */ /* parameter needed as it is used in a function array */ - UWord32 *next_sign_ind, /* i/o: next sign ind */ - UWord32* ind /* o: MPVQ index */ -) -{ - *ind = (Word32)(*k_val_out_ptr) ; /* dummy assignment to avoid gcc "unused parameter" warning for *k_val_out_ptr, i.e no move32 needed() */ - *ind = UL_deposit_l(0); - - *next_sign_ind = UL_deposit_l(0); - if( *vec_in < 0 ) - { - *next_sign_ind = UL_deposit_l(1); /*single basicop */ - } - return ; -} - -/*-------------------------------------------------------------------* -* vec2mind_two_fx() -*-------------------------------------------------------------------*/ -static -void vec2mind_two_fx( - const Word16* vec_in, /* i : PVQ pulse train */ - Word16 *k_val_out_ptr , /* o : number of unit pulses */ - UWord32 *next_sign_ind, /* i/o: next sign ind */ - UWord32* ind /* o: MPVQ index */ -) -{ - UWord32 lead_sign_ind_add; - Word16 abs0,abs1,abs01,sptr; - - abs0 = abs_s(vec_in[0]); - abs1 = abs_s(vec_in[1]); - abs01 = add(abs0, abs1); - *k_val_out_ptr = abs01; - move16(); /* can be zero */ - *ind = UL_deposit_l(0); /* [KMAX 0 ] , and dual zeros */ - - *next_sign_ind = UL_deposit_h(SIGNBIT_SHRT_FX); /* "unset" sign flag set */ /* dual zeroes can happen in a recursive encoding call */ - - - IF( abs01 != 0 ) - { - sptr = 0; - move16(); /*used as ptr to vec0 or vec1 value */ - *next_sign_ind = UL_deposit_l(sptr); - - test(); - IF(abs0 != 0 && abs1 != 0 ) - { - /* likely most frequent/common case */ - /* [ KMAX-1 1],[ KMAX-1 -1] ... [ 1 +(KMAX-1) ],[ 1 -(KMAX-1)] */ - /* sign always shifted to first pos */ - lead_sign_ind_add = UL_deposit_l(1) ; - if( vec_in[1] < 0) - { - lead_sign_ind_add = UL_deposit_l(2); /* single op */ - } - *ind = UL_addNsD(UL_deposit_l((UWord16)lshl(sub(abs1,1),1)),lead_sign_ind_add); - } - ELSE - { - /* one value is a zero */ - IF( abs0 == 0 ) - { - /* [ 0 KMAX]*/ - *ind = UL_deposit_l((UWord16) sub(lshl(abs1,1),1)); - sptr = 1; - move16(); - } - } - - /* *next_sign_ind= (unsigned int)(vec_in[*next_sign_ind]<0); */ - if( vec_in[sptr] < 0 ) - { - *next_sign_ind = UL_deposit_l(1); /*single instruction */ - } - } - return; -} - -static -void enc_push_sign(Word16 val, UWord32* next_sign_ind, UWord32 *index) -{ - /* - % Check if the leading sign 'bit' is to be added - % here the leading sign bit is put in LSB as it saves about 3 cycles in sign-decoding - % (one can also put it in the MSB , but then one needs to access h_mem twice and shift the sign bit into position ) - */ - test(); - IF( (UL_and(*next_sign_ind,SIGNBIT_FX) == 0) && (val != 0)) - { - *index = UL_addNsD(UL_lshl(*index,1),*next_sign_ind); - } - - /* push sign to next non_zero position */ - /* *next_sign_ind = *next_sign_ind ;*/ /* default is to keep stored sign index */ - if( val < 0 ) - { - *next_sign_ind = UL_deposit_l(1); /* single basicop */ - } - if( val > 0) - { - *next_sign_ind = UL_deposit_l(0); /* single basicop */ - } -} - -/*-------------------------------------------------------------------* - * vec2mind_gen345_fx( vec_in kval, next_dim_func , offset_func,....) - * generic call saves PROM , - *-------------------------------------------------------------------*/ - -static -void vec2mind_gen345_fx( - const Word16* vec_in, /* i : PVQ abs pulse train */ - Word16 *k_val_out_ptr, /* o : number of unit pulses */ - UWord32 *next_sign_ind , /* i/o: next sign ind */ - UWord32* index , /* o: MPVQ index */ - VEC2INDFUNCM vec2indfunc_ptr, /* i: */ - H_FUNCM a_func_ptr /*i: offset function */ -) -{ - Word16 tmp_val; - - tmp_val = vec_in[0]; - move16(); - move32(); /* adaptive function call setup */ - (*vec2indfunc_ptr)(&vec_in[1], k_val_out_ptr, next_sign_ind, index); - - enc_push_sign(tmp_val, next_sign_ind, index); - - move32(); /* adaptive function call setup */ - *index = UL_addNsD(*index,(*a_func_ptr)(UL_deposit_l(*k_val_out_ptr))); - - *k_val_out_ptr = add(*k_val_out_ptr, abs_s(tmp_val)); - - return ; -} - -/*-------------------------------------------------------------------* - * vec2mind_three_fx() - *-------------------------------------------------------------------*/ -static -void vec2mind_three_fx( - const Word16* vec_in, /* i : PVQ pulse train */ - Word16* k_val_out_ptr, /* o : number of unit pulses */ - UWord32 *next_sign_ind, /* i/o: next sign ind */ - UWord32 *index /* o: MPVQ index */ -) -{ - vec2mind_gen345_fx(vec_in,k_val_out_ptr, next_sign_ind, index, vec2mind_two_fx, a_three_fx); - return ; -} - - -/*-------------------------------------------------------------------* - * vec2mind_four_fx() - *-------------------------------------------------------------------*/ -static -void vec2mind_four_fx( - const Word16* vec_in, /* i : PVQ pulse train */ - Word16* k_val_out_ptr, /* o : number of unit pulses */ - UWord32* next_sign_ind , /* i/o: next sign ind */ - UWord32* index /* o: MPVQ index */ -) -{ - vec2mind_gen345_fx(vec_in, k_val_out_ptr, next_sign_ind, index, vec2mind_three_fx, a_four_fx); - return ; -} - -/*-------------------------------------------------------------------* - * vec2mind_five_fx() - *-------------------------------------------------------------------*/ -static -void vec2mind_five_fx( - const Word16* vec_in, /* i : PVQ abs pulse train */ - Word16 *k_val_out_ptr, /* o : number of unit pulses */ - UWord32 *next_sign_ind , /* i/o: next sign ind */ - UWord32* index /* o: MPVQ index */ -) -{ - vec2mind_gen345_fx(vec_in,k_val_out_ptr, next_sign_ind, index, vec2mind_four_fx, a_five_fx); - return ; -} - -/*-------------------------------------------------------------------* -* vec2mind_fx() -*-------------------------------------------------------------------*/ -static -void vec2mind_fx(Word16 dim_in, /* i : dim */ - Word16 k_val_in, /* i : number of unit pulses */ - const Word16* vec_in, /* i : PVQ pulse train */ - UWord32 *next_sign_ind, /* o : pushed leading sign */ - UWord32 *index , /* o : MPVQ index */ - UWord32 *N_MPVQ_ptr, /* o : size(N_MPVQ(dim,K_val_in))*/ - UWord32* h_mem) /* o : offsets */ -{ - Word16 pos, mem_size_m1, k_val_acc, tmp_val; - UWord32 tmp_h; - - /* - %% main steps - % quick encode two rightmost pos - % for every position from dim-3 to 0 (right to left) - % check if an sign is to be encoded , - % add its offset - % check(and add) amplitude offset(for accumulated pulse sum) up to this point - % update total pulse sum - % update offset vector recursively (except for pos==0 ) - % end - % calculate size - */ - - mem_size_m1 = add(k_val_in,1); - *next_sign_ind = UL_deposit_h(SIGNBIT_SHRT_FX); /* highest bit set signals no sign found yet, should always be 0 or 1 out, */ - - pos = sub(dim_in,2); /* adress 2nd last sample */ - vec2mind_two_fx(&vec_in[pos],&k_val_acc,next_sign_ind ,index); - initOffsets_fx( 3, h_mem, k_val_in) ; /* start recursions at 3rd sample */ - - tmp_h = h_mem[k_val_acc]; - move32(); - FOR (pos--; pos>=0; pos--) - { - tmp_val = vec_in[pos]; - move16(); - enc_push_sign(tmp_val, next_sign_ind, index); - - /* now add indexing offset up to this reverse (r_l) accumulated amplitude point */ - *index = UL_addNsD(*index, tmp_h); /* k_val_acc==0 ==>0 */ - - /* k_val_acc = k_val_acc + vec_abs[pos];*/ /* now increase acc k value for next N */ - k_val_acc = add(k_val_acc, abs_s(tmp_val)); - - IF( pos != 0 ) - { - a_u_fwd_fx(h_mem, k_val_in ,mem_size_m1); - /* update A(n,k=1:k_val_in) and U(n,k_val_in+1) */ - /* NB here (k_val_in + 2 elements always has to be updated */ - } - tmp_h = UL_addNsD(h_mem[k_val_acc], 0U); - } - - /* size is needed for the subseqent arithmetic encoding/transmission of the index. - use relation N_MPVQ(n,K) = 1 + (A(n, K)-1)/2 + U(n, 1 + K) - = N_MPVQ(n,K) = 1 + (A(n, K)>>1) + U(n, 1 + K) , as A(n,K) is odd) */ - *N_MPVQ_ptr = UL_addNsD(1U,UL_addNsD(UL_lshr(tmp_h,1),h_mem[ mem_size_m1])); - move32();/* calc total size */ - - return; -} - -/*--------------------------------------------------------------------------* - * mpvq_encode_vec_fx() - * - * returns struct with lead sign index, MPVQ-index, dim and N_MPVQ size - *-------------------------------------------------------------------------*/ - -PvqEntry_fx mpvq_encode_vec_fx( /* o : leading_sign_index, index, size, k_val */ - const Word16* vec_in, /* i : signed pulse train */ - Word16 dim_in, /* i : dimension */ - Word16 k_val_local /* i : nb unit pulses */ -) -{ - PvqEntry_fx result; - UWord32 h_mem[ 1 + KMAX_NON_DIRECT_FX + 1 ] ; /* now always assign max offset buffer for dim 6 , - actually only 1+k_val_in+1 needed ) */ - UWord32 lead_sign_ind; - - VEC2INDFUNCM vec2mind_f[1+N_OPT_FX] = { (VEC2INDFUNCM)NULL, vec2mind_one_fx, vec2mind_two_fx, vec2mind_three_fx, vec2mind_four_fx, vec2mind_five_fx }; - - result.k_val = k_val_local; - move16(); - result.dim = dim_in; - move16(); - /* NB , k_val_local may be changed in some sub encoding routines */ - IF( sub(dim_in, N_OPT_FX) > 0 ) - { - /* use the generic dimension function */ - vec2mind_fx(dim_in, k_val_local, vec_in, &lead_sign_ind, &result.index, &result.size, h_mem); - } - ELSE /* if (dim_in<=N_OPT), h_mem not used */ - { - move32(); /* adaptive function ptr setup */ - (vec2mind_f[dim_in])(vec_in, &k_val_local, &lead_sign_ind, &result.index); - result.size = direct_msize_fx(dim_in, k_val_local); - } - result.lead_sign_ind = u_extract_l(lead_sign_ind); - - return result; -} - - diff --git a/src/libs/libevs/lib_com/int_lsp.cpp b/src/libs/libevs/lib_com/int_lsp.cpp new file mode 100644 index 00000000..2de94211 --- /dev/null +++ b/src/libs/libevs/lib_com/int_lsp.cpp @@ -0,0 +1,139 @@ +/*==================================================================================== + EVS Codec 3GPP TS26.443 Nov 13, 2018. Version 12.11.0 / 13.7.0 / 14.3.0 / 15.1.0 + ====================================================================================*/ + +#include "options.h" +#include "cnst.h" +#include "prot.h" +#include "rom_com.h" + +/*---------------------------------------------------------------------* + * int_lsp() + * + * Find the interpolated LSP parameters for all subframes + *---------------------------------------------------------------------*/ + +void int_lsp( + const short L_frame, /* i : length of the frame */ + const float lsp_old[], /* i : LSPs from past frame */ + const float lsp_new[], /* i : LSPs from present frame */ + float *Aq, /* o : LP coefficients in both subframes */ + const short m, /* i : order of LP filter */ + const float *int_coeffs, /* i : interpolation coefficients */ + const short Opt_AMR_WB /* i : flag indicating AMR-WB IO mode */ +) +{ + float lsp[M], fnew, fold; + short i, k; + const float *pt_int_coeffs; + + if( L_frame == L_FRAME ) + { + pt_int_coeffs = int_coeffs; + } + else /* L_frame == L_FRAME16k */ + { + pt_int_coeffs = interpol_frac_16k; + } + + for( k=0; kcore_brate == SID_1k75 ) + { + indice[0] = (short)get_next_indice( st, 6 ); + indice[1] = (short)get_next_indice( st, 6 ); + indice[2] = (short)get_next_indice( st, 6 ); + indice[3] = (short)get_next_indice( st, 5 ); + indice[4] = (short)get_next_indice( st, 5 ); + + disf_ns_28b( indice, isf_new ); + + reorder_isf( isf_new, ISF_GAP, M, INT_FS_12k8 ); + + isf2isp( isf_new, isp_new, M, INT_FS_12k8 ); + + /* return if SID frame (conversion to A(z) done in the calling function) */ + return; + } + + /*-----------------------------------------------------------------* + * ISF de-quantization of all other frames + *-----------------------------------------------------------------*/ + + if( st->core_brate == ACELP_6k60 ) + { + indice[0] = (short)get_next_indice( st, 8 ); + indice[1] = (short)get_next_indice( st, 8 ); + indice[2] = (short)get_next_indice( st, 7 ); + indice[3] = (short)get_next_indice( st, 7 ); + indice[4] = (short)get_next_indice( st, 6 ); + + disf_2s_36b( indice, isf_new, st->mem_AR, st->mem_MA ); + } + else + { + indice[0] = (short)get_next_indice( st, 8 ); + indice[1] = (short)get_next_indice( st, 8 ); + indice[2] = (short)get_next_indice( st, 6 ); + indice[3] = (short)get_next_indice( st, 7 ); + indice[4] = (short)get_next_indice( st, 7 ); + indice[5] = (short)get_next_indice( st, 5 ); + indice[6] = (short)get_next_indice( st, 5 ); + + disf_2s_46b( indice, isf_new, st->mem_AR, st->mem_MA); + } + + reorder_isf( isf_new, ISF_GAP, M, INT_FS_12k8 ); + + /* convert quantized ISFs to ISPs */ + isf2isp( isf_new, isp_new, M, INT_FS_12k8 ); + + /*-------------------------------------------------------------------------------------* + * FEC - update adaptive mean ISF vector + *-------------------------------------------------------------------------------------*/ + + for ( i=0; ilsf_adaptive_mean[i] = (st->lsfoldbfi1[i] + st->lsfoldbfi0[i] + isf_new[i]) / 3; + } + + /*-------------------------------------------------------------------------------------* + * ISP interpolation + * A(z) calculation + *-------------------------------------------------------------------------------------*/ + + if( st->rate_switching_reset ) + { + /*extrapolation instead of interpolation*/ + mvr2r( isp_new, st->lsp_old, M ); + mvr2r( isf_new, st->lsf_old, M ); + } + + /* ISP interpolation and A(z) calculation */ + int_lsp( L_FRAME, st->lsp_old, isp_new, Aq, M, interpol_isp_amr_wb, 1 ); + + /*------------------------------------------------------------------* + * Check ISF stability : distance between old ISF and current ISF + *------------------------------------------------------------------*/ + + st->stab_fac = lsf_stab( isf_new, st->lsf_old, 1, st->L_frame ); + + return; +} + +/*-------------------------------------------------------------------* + * disf_ns_28b() + * + * ISF de-quantizer for SID_1k75 frames (only for AMR-WB IO mode) + *-------------------------------------------------------------------*/ + +void disf_ns_28b( + short *indice, /* i : quantized indices (use indice[0] = -1 in the decoder) */ + float *isf_q /* o : ISF in the frequency domain (0..6400) */ +) +{ + short i; + + for (i = 0; i < 2; i++) + { + isf_q[i] = dico1_ns_28b[indice[0]*2+i]; + } + + for (i = 0; i < 3; i++) + { + isf_q[i+2] = dico2_ns_28b[indice[1]*3+i]; + isf_q[i+5] = dico3_ns_28b[indice[2]*3+i]; + } + + for (i = 0; i < 4; i++) + { + isf_q[i+8] = dico4_ns_28b[indice[3]*4+i]; + isf_q[i+12] = dico5_ns_28b[indice[4]*4+i]; + } + + for (i=0; icore_brate_fx,SID_1k75) == 0 ) - { - - indice[0] = (Word16)get_next_indice_fx( st, 6 ); - move16(); - indice[1] = (Word16)get_next_indice_fx( st, 6 ); - move16(); - indice[2] = (Word16)get_next_indice_fx( st, 6 ); - move16(); - indice[3] = (Word16)get_next_indice_fx( st, 5 ); - move16(); - indice[4] = (Word16)get_next_indice_fx( st, 5 ); - move16(); - - disf_ns_28b_fx( indice, isf_new ); - - reorder_isf_fx( isf_new, ISF_GAP_FX, M, Fs_2); - - E_LPC_isf_isp_conversion( isf_new, isp_new, M); - /* return if SID frame (conversion to A(z) done in the calling function) */ - return; - } - - /*-----------------------------------------------------------------* - * ISF de-quantization of all other frames - *-----------------------------------------------------------------*/ - - IF( L_sub(st->core_brate_fx,ACELP_6k60) == 0 ) - { - indice[0] = (Word16)get_next_indice_fx( st, 8 ); - move16(); - indice[1] = (Word16)get_next_indice_fx( st, 8 ); - move16(); - indice[2] = (Word16)get_next_indice_fx( st, 7 ); - move16(); - indice[3] = (Word16)get_next_indice_fx( st, 7 ); - move16(); - indice[4] = (Word16)get_next_indice_fx( st, 6 ); - move16(); - - disf_2s_36b_fx( indice, isf_new, st->mem_AR_fx, st->mem_MA_fx, 1 ); - } - ELSE - { - indice[0] = (Word16)get_next_indice_fx( st, 8 ); - move16(); - indice[1] = (Word16)get_next_indice_fx( st, 8 ); - move16(); - indice[2] = (Word16)get_next_indice_fx( st, 6 ); - move16(); - indice[3] = (Word16)get_next_indice_fx( st, 7 ); - move16(); - indice[4] = (Word16)get_next_indice_fx( st, 7 ); - move16(); - indice[5] = (Word16)get_next_indice_fx( st, 5 ); - move16(); - indice[6] = (Word16)get_next_indice_fx( st, 5 ); - move16(); - - disf_2s_46b_fx( indice, isf_new, st->mem_AR_fx, st->mem_MA_fx,1 ); - } - reorder_isf_fx( isf_new, ISF_GAP_FX, M, Fs_2 ); - /* convert quantized ISFs to ISPs */ - E_LPC_isf_isp_conversion( isf_new, isp_new, M); - - /*-------------------------------------------------------------------------------------* - * FEC - update adaptive mean ISF vector - *-------------------------------------------------------------------------------------*/ - - FOR ( i=0; ilsf_adaptive_mean[i] = (st->lsfoldbfi1[i] + st->lsfoldbfi0[i] + isf_new[i]) / 3;*/ - L_tmp = L_mult(st->lsfoldbfi1_fx[i], 10923); - L_tmp = L_mac(L_tmp, st->lsfoldbfi0_fx[i], 10923); - st->lsf_adaptive_mean_fx[i] = round_fx(L_mac(L_tmp, isf_new[i], 10923)); - } - - /*-------------------------------------------------------------------------------------* - * ISP interpolation - * A(z) calculation - *-------------------------------------------------------------------------------------*/ - - if(st->rate_switching_reset) - { - /*extrapolation instead of interpolation*/ - Copy(isp_new, st->lsp_old_fx, M); - Copy(isf_new, st->lsf_old_fx, M); - } - - /* ISP interpolation and A(z) calculation */ - int_lsp_fx( L_FRAME, st->lsp_old_fx, isp_new, Aq, M, interpol_isp_amr_wb_fx, 1 ); - - /*------------------------------------------------------------------* - * Check ISF stability : distance between old ISF and current ISF - *------------------------------------------------------------------*/ - - st->stab_fac_fx = lsf_stab_fx( isf_new, st->lsf_old_fx, 1, st->L_frame_fx ); - - return; -} - -/*-------------------------------------------------------------------* - * disf_ns_28b() - * - * ISF de-quantizer for SID_1k75 frames (only for AMR-WB IO mode) - *-------------------------------------------------------------------*/ - -void disf_ns_28b_fx( - Word16 *indice, /* i : quantized indices (use indice[0] = -1 in the decoder) */ - Word16 *isf_q /* o : ISF in the frequency domain (0..6400) */ -) -{ - Word16 i; - - FOR (i = 0; i < 2; i++) - { - isf_q[i] = dico1_ns_28b_fx[indice[0]*2+i]; - move16(); - } - - FOR (i = 0; i < 3; i++) - { - isf_q[i+2] = dico2_ns_28b_fx[indice[1]*3+i]; - move16(); - isf_q[i+5] = dico3_ns_28b_fx[indice[2]*3+i]; - move16(); - } - - FOR (i = 0; i < 4; i++) - { - isf_q[i+8] = dico4_ns_28b_fx[indice[3]*4+i]; - move16(); - isf_q[i+12] = dico5_ns_28b_fx[indice[4]*4+i]; - move16(); - } - - FOR (i=0; i -#include "prot_fx.h" -#include "rom_com_fx.h" -#include "basop_util.h" -#include "stl.h" +#include "options.h" +#include "prot.h" +#include "cnst.h" +#include "rom_com.h" /*-------------------------------------------------------------------* * Local constants *-------------------------------------------------------------------*/ -#define kLagWinThGain1 19661 /* 0.6f in Q15 */ -#define kLagWinThGain2 9830 /* 0.3f in Q15 */ +#define kLagWinThGain1 0.6f +#define kLagWinThGain2 0.3f + /*-------------------------------------------------------------* - * procedure lag_wind: * + * procedure lag_wind() * * ~~~~~~~~~ * * lag windowing of the autocorrelations * *-------------------------------------------------------------*/ void lag_wind( - Word16 r_h[], /* in/out: autocorrelations */ - Word16 r_l[], /* in/out: autocorrelations */ - Word16 m, /* input : order of LP filter */ - Word32 sr, /* input : sampling rate */ - Word16 strength /* input : LAGW_WEAK, LAGW_MEDIUM, or LAGW_STRONG */ + float r[], /* i/o: autocorrelations */ + const short m, /* i : order of LP filter */ + const int sr, /* i : sampling rate */ + const short strength /* i : LAGW_WEAK, LAGW_MEDIUM, or LAGW_STRONG */ ) { - Word16 i; - Word32 tmp; - const Word16 *wnd_h, *wnd_l; - + short i; + const float *wnd; assert(0 <= strength && strength <= NUM_LAGW_STRENGTHS); - SWITCH (sr) + + switch (sr) { case 8000: assert(m <= 16); assert(strength == LAGW_STRONG); - wnd_h = lag_window_8k[0]; - wnd_l = lag_window_8k[1]; - BREAK; + wnd = lag_window_8k; + break; case 12800: assert(m <= 16); - wnd_h = lag_window_12k8[strength][0]; - wnd_l = lag_window_12k8[strength][1]; - BREAK; + wnd = lag_window_12k8[strength]; + break; case 16000: assert(m <= 16); - wnd_h = lag_window_16k[strength][0]; - wnd_l = lag_window_16k[strength][1]; - BREAK; + wnd = lag_window_16k[strength]; + break; case 24000: case 25600: assert(m <= 16); - wnd_h = lag_window_25k6[strength][0]; - wnd_l = lag_window_25k6[strength][1]; - BREAK; + wnd = lag_window_25k6[strength]; + break; case 32000: assert(m <= 16); - wnd_h = lag_window_32k[strength][0]; - wnd_l = lag_window_32k[strength][1]; - BREAK; + wnd = lag_window_32k[strength]; + break; case 48000: assert(m <= 16); assert(strength == LAGW_STRONG); - wnd_h = lag_window_48k[0]; - wnd_l = lag_window_48k[1]; - BREAK; + wnd = lag_window_48k; + break; default: assert(!"Lag window not implemented for this sampling rate"); return; } - FOR (i = 1; i <= m; i++) + for( i=0; i<=m; ++i ) { - tmp = Mpy_32(r_h[i], r_l[i], wnd_h[i-1], wnd_l[i-1]); - L_Extract(tmp, &r_h[i], &r_l[i]); + r[i] *= wnd[i]; } + return; } +/*-------------------------------------------------------------* + * procedure adapt_lag_wind() + * + * + *-------------------------------------------------------------*/ + void adapt_lag_wind( - Word16 r_h[], /* in/out: autocorrelations */ - Word16 r_l[], /* in/out: autocorrelations */ - Word16 m, /* input : order of LP filter */ - const Word16 Top, /* input : open loop pitch lag */ - const Word16 Tnc, /* input : open loop pitch gain */ - Word32 sr /* input : sampling rate */ + float r[], /* i/o: autocorrelations */ + int m, /* i : order of LP filter */ + const int Top, /* i : open loop pitch lags from curr. frame (or NULL if n/a) */ + const float Tnc, /* i : open loop pitch gains from curr. frame (NULL if n/a) */ + int sr /* i : sampling rate */ ) { - Word16 strength, pitch_lag; - Word16 pitch_gain; + short strength; + short pitch_lag; + float pitch_gain; - pitch_lag = Top; - move16(); - pitch_gain = Tnc; - move16(); + pitch_lag = (short)Top; + pitch_gain = (float)Tnc; - IF (sub(pitch_lag, 80) < 0) + if (pitch_lag < 80) { - strength = LAGW_STRONG; - move16(); - if (sub(pitch_gain, kLagWinThGain1) <= 0) + if (pitch_gain > kLagWinThGain1) + { + strength = LAGW_STRONG; + } + else { strength = LAGW_MEDIUM; - move16(); } } - ELSE IF (sub(pitch_lag, 160) < 0) + else if (pitch_lag < 160) { - strength = LAGW_MEDIUM; - move16(); - if (sub(pitch_gain, kLagWinThGain2) <= 0) + if (pitch_gain > kLagWinThGain2) + { + strength = LAGW_MEDIUM; + } + else { strength = LAGW_WEAK; - move16(); } } - ELSE + else { strength = LAGW_WEAK; - move16(); } - lag_wind(r_h, r_l, m, sr, strength); + lag_wind( r, m, sr, strength ); + + return; } diff --git a/src/libs/libevs/lib_com/lerp.cpp b/src/libs/libevs/lib_com/lerp.cpp old mode 100755 new mode 100644 index 4189115a..17a0bd95 --- a/src/libs/libevs/lib_com/lerp.cpp +++ b/src/libs/libevs/lib_com/lerp.cpp @@ -1,43 +1,43 @@ /*==================================================================================== - EVS Codec 3GPP TS26.442 Apr 03, 2018. Version 12.11.0 / 13.6.0 / 14.2.0 + EVS Codec 3GPP TS26.443 Nov 13, 2018. Version 12.11.0 / 13.7.0 / 14.3.0 / 15.1.0 ====================================================================================*/ -#include "options.h" -#include "basop_util.h" -#include "prot_fx.h" -#include -#include "stl.h" +#include +#include +#include "prot.h" +/*-------------------------------------------------------------* + * procedure lerp() * + * * + * * + *-------------------------------------------------------------*/ -#define shift_e (16-1) -#define pos_e (16-1) - -static void lerp_proc(Word16 *f, Word16 *f_out, Word16 bufferNewSize, Word16 bufferOldSize); +static void lerp_proc( + float *f, + float *f_out, + int bufferNewSize, + int bufferOldSize +); -void lerp(Word16 *f, Word16 *f_out, Word16 bufferNewSize, Word16 bufferOldSize) +void lerp( + float *f, + float *f_out, + int bufferNewSize, + int bufferOldSize +) { - Word16 tmp1, tmp2, tmpexp; - BASOP_Util_Divide_MantExp(bufferNewSize, 0, bufferOldSize, 0, &tmp1, &tmpexp); - tmp1 = shr(tmp1,3); /*Q12*/ - tmp1 = shl(tmp1,tmpexp); + float maxFac; - BASOP_Util_Divide_MantExp(bufferOldSize, 0, bufferNewSize, 0, &tmp2, &tmpexp); - tmp2 = shr(tmp2,3); /*Q12*/ - tmp2 = shl(tmp2,tmpexp); - test(); - test(); - IF(sub(tmp1,16224 /*3,9609375 in Q12*/) > 0) + maxFac = 507.0/128.0; + + if( (float)bufferNewSize / bufferOldSize > maxFac ) { - Word16 tmpNewSize = shl(bufferOldSize,1); - WHILE(sub(bufferNewSize, bufferOldSize) > 0) + int tmpNewSize = bufferOldSize*2; + while(bufferNewSize > bufferOldSize) { - BASOP_Util_Divide_MantExp(bufferNewSize, 0, bufferOldSize, 0, &tmp1, &tmpexp); - tmp1 = shr(tmp1,3); /*Q12*/ - tmp1 = shl(tmp1,tmpexp); - test(); - IF(sub(tmp1,16224 /*3,9609375 in Q12*/) <= 0) + if( (float)bufferNewSize / bufferOldSize <= maxFac ) { tmpNewSize = bufferNewSize; } @@ -46,19 +46,15 @@ void lerp(Word16 *f, Word16 *f_out, Word16 bufferNewSize, Word16 bufferOldSize) f = f_out; bufferOldSize = tmpNewSize; - tmpNewSize = shl(tmpNewSize,1); + tmpNewSize *= 2; } } - ELSE IF(sub(tmp2,16224 /*3,9609375 in Q12*/) > 0) + else if( (float)bufferOldSize / bufferNewSize > maxFac ) { - Word16 tmpNewSize = shr(bufferOldSize,1); - WHILE(sub(bufferNewSize, bufferOldSize) < 0) + int tmpNewSize = bufferOldSize/2; + while(bufferNewSize < bufferOldSize) { - BASOP_Util_Divide_MantExp(bufferOldSize, 0, bufferNewSize, 0, &tmp2, &tmpexp); - tmp2 = shr(tmp2,3); /*Q12*/ - tmp2 = shl(tmp2,tmpexp); - test(); - IF(sub(tmp2,16224 /*3,9609375 in Q12*/) <= 0) + if( (float)bufferOldSize / bufferNewSize <= maxFac ) { tmpNewSize = bufferNewSize; } @@ -67,7 +63,7 @@ void lerp(Word16 *f, Word16 *f_out, Word16 bufferNewSize, Word16 bufferOldSize) f = f_out; bufferOldSize = tmpNewSize; - tmpNewSize = shr(tmpNewSize,1); + tmpNewSize /= 2; } } else @@ -76,104 +72,71 @@ void lerp(Word16 *f, Word16 *f_out, Word16 bufferNewSize, Word16 bufferOldSize) } } -void lerp_proc(Word16 *f, Word16 *f_out, Word16 bufferNewSize, Word16 bufferOldSize) +void lerp_proc( + float *f, + float *f_out, + int bufferNewSize, + int bufferOldSize +) { - - Word16 i, idx, n; - Word16 diff; - Word32 pos, shift; - Word16 buf[2*L_FRAME_MAX]; - Word16 *ptr; + int i, idx; + float pos, shift, diff; + float buf[2*L_FRAME_MAX]; - ptr = f_out; - test(); - test(); - test(); - if ( ((f <= f_out) && (f + bufferOldSize >= f_out)) || ((f_out <= f) && (f_out + bufferNewSize >= f)) ) + if( bufferNewSize == bufferOldSize ) { - ptr = buf; - move16(); - } - - IF( sub(bufferNewSize, bufferOldSize) == 0 ) - { - Copy(f, f_out, bufferNewSize); + mvr2r( f, buf, bufferNewSize ); + mvr2r( buf, f_out, bufferNewSize ); return; } - shift = L_shl(L_deposit_l(div_s( bufferOldSize, shl(bufferNewSize, 4))), 4-shift_e+16); + /* Using the basop code to avoid reading beyond end of input for bufferOldSize=320, bufferNewSize=640 */ + shift = (float)(L_shl(L_deposit_l(div_s( bufferOldSize, shl(bufferNewSize, 4))), 4-15+16))/65536.0f; + pos = 0.5f * shift - 0.5f; - pos = L_sub(L_shr(shift, 1), 32768l/*1.0f Q15*/); - - /* Adjust interpolation shift to avoid accessing beyond end of input buffer. */ - if ( L_sub(shift, 19661l/*0.3f Q16*/) < 0) + if (shift < 0.3f) { - pos = L_sub(pos, 8520l/*0.13f Q16*/); + pos = pos - 0.13f; } - assert(pos_e == shift_e); - /* first point of interpolation */ - IF (pos<0) + if( pos<0 ) { - - diff = shr(extract_l(pos), 1); - /*buf[0]=f[0]+pos*(f[1]-f[0]);*/ - move16(); - *ptr++ = add(f[0], msu_r(L_mult(diff, f[1]),diff, f[0])); + buf[0]=f[0]+pos*(f[1]-f[0]); } - ELSE + else { - - idx=extract_h(pos); - - diff = lshr(extract_l(pos), 1); - - move16(); - *ptr++ = add(f[idx], msu_r(L_mult(diff, f[idx+1]), diff, f[idx])); + idx=(int)pos; + diff = pos - idx; + buf[0] = f[idx] + diff * (f[idx+1]-f[idx]); } - pos = L_add(pos, shift); - idx = s_max(0, extract_h(pos)); + pos += shift; - n = sub(bufferNewSize, 1); - FOR ( i=1; i 0 ) + if( pos > bufferOldSize-1 ) { - idx = sub(bufferOldSize,2); - } - assert(idx <= 2*L_FRAME_MAX); - - /* diff = t - point;*/ - diff = lshr(extract_l(L_shr(L_sub(pos, L_deposit_h(idx)), 1)), 1); - - move16(); - *ptr++ = add(f[idx], shl(msu_r(L_mult(diff, f[idx+1]), diff, f[idx]), 1)); - - test(); - test(); - test(); - IF ( ((f <= f_out) && (f + bufferOldSize >= f_out)) || ((f_out <= f) && (f_out + bufferNewSize >= f)) ) - { - Copy( buf, f_out, bufferNewSize ); + idx=bufferOldSize-2; } + diff = pos - idx; + + buf[bufferNewSize-1] = f[idx]+diff*(f[idx+1]-f[idx]); + + mvr2r( buf, f_out, bufferNewSize ); + + return; } diff --git a/src/libs/libevs/lib_com/limit_t0.cpp b/src/libs/libevs/lib_com/limit_t0.cpp new file mode 100644 index 00000000..876723bb --- /dev/null +++ b/src/libs/libevs/lib_com/limit_t0.cpp @@ -0,0 +1,200 @@ +/*==================================================================================== + EVS Codec 3GPP TS26.443 Nov 13, 2018. Version 12.11.0 / 13.7.0 / 14.3.0 / 15.1.0 + ====================================================================================*/ + +#include "options.h" +#include "cnst.h" +#include "prot.h" + +/*-------------------------------------------------* + * Local constants + *-------------------------------------------------*/ + +#define LIMIT_PIT_REL_LOWER 2 /* delta interval to extend pitch coding in relative Q */ +#define LIMIT_PIT_REL_UPPER 0 + +/*-------------------------------------------------* + * limit_T0() + * + * Close-loop pitch lag search limitation + *-------------------------------------------------*/ + +void limit_T0( + const short L_frame, /* i : length of the frame */ + const short delta, /* i : Half the close-loop searched interval */ + const short pit_flag, /* i : selecting absolute(0) or delta(1) pitch quantization */ + const short limit_flag, /* i : flag for Q limits (0=restrained, 1=extended) */ + const short T0, /* i : rough pitch estimate around which the search is done */ + const short T0_frac, /* i : pitch estimate fractional part */ + short *T0_min, /* o : lower pitch limit */ + short *T0_max /* o : higher pitch limit */ +) +{ + short delta2, T1; + short pit_min, pit_max; + + if( limit_flag == 0 ) /* restrained Q limits */ + { + /* set limits */ + if( L_frame == L_FRAME ) + { + pit_max = PIT_MAX; + pit_min = PIT_MIN; + } + else /* L_frame == L_FRAME16k */ + { + pit_max = PIT16k_MAX; + pit_min = PIT16k_MIN; + } + + delta2 = 2 * delta - 1; + + T1 = T0; + if( T0_frac >= 2 ) + { + T1++; + } + *T0_min = T1 - delta; + + if( *T0_min < pit_min ) + { + *T0_min = pit_min; + } + *T0_max = *T0_min + delta2; + + if( *T0_max > pit_max ) + { + *T0_max = pit_max; + *T0_min = *T0_max - delta2; + } + } + else /* extended Q limits */ + { + + /* set limits */ + if( L_frame == L_FRAME ) + { + pit_max = PIT_MAX; + pit_min = PIT_MIN_EXTEND; + + if( limit_flag == 2 ) + { + pit_min = PIT_MIN_DOUBLEEXTEND; + } + } + else /* L_frame == L_FRAME16k */ + { + pit_max = PIT16k_MAX; + pit_min = PIT16k_MIN_EXTEND; + } + + delta2 = 2 * delta - 1; + + T1 = T0; + if( T0_frac >= 2 ) + { + T1++; + } + *T0_min = T1 - delta; + + if( pit_flag == 0 ) + { + /* subframes with absolute search: keep Q range */ + if( *T0_min < pit_min ) + { + *T0_min = pit_min; + } + *T0_max = *T0_min + delta2; + + if( *T0_max > pit_max ) + { + *T0_max = pit_max; + *T0_min = *T0_max - delta2; + } + } + else + { + /* subframes with relative search: extend Q range */ + if( *T0_min < pit_min - LIMIT_PIT_REL_LOWER ) + { + *T0_min = pit_min - LIMIT_PIT_REL_LOWER; + } + + if( *T0_min < L_INTERPOL ) + { + *T0_min = L_INTERPOL ; + } + *T0_max = *T0_min + delta2; + + if( *T0_max > pit_max + LIMIT_PIT_REL_UPPER ) + { + *T0_max = pit_max + LIMIT_PIT_REL_UPPER; + *T0_min = *T0_max - delta2; + } + } + } + + return; +} + + + +/*-------------------------------------------------* +* Routine limit_T0_voiced() +* +* Close-loop pitch lag search limitation +*-------------------------------------------------*/ + +void limit_T0_voiced( + int nbits, + int res, + int T0, /* i : rough pitch estimate around which the search is done */ + int T0_frac, /* i : pitch estimate fractional part */ + int T0_res, /* i : pitch resolution */ + int *T0_min, /* o : lower pitch limit */ + int *T0_min_frac, /* o : lower pitch limit */ + int *T0_max, /* o : higher pitch limit */ + int *T0_max_frac, /* o : higher pitch limit */ + int pit_min, /* i : Minimum pitch lag */ + int pit_max /* i : Maximum pitch lag */ +) +{ + short T1, temp1, temp2; + + + /* Mid-point */ + T1 = T0; + if( (T0_res > 1) && (T0_frac >= (T0_res>>1)) ) + { + T1++; + } + + /* Lower-bound */ + temp1 = (T1*res) - (1<<(nbits-1)); + temp2 = temp1 / res; + *T0_min = temp2; + *T0_min_frac = temp1 - temp2*res; + if ( *T0_min < pit_min) + { + *T0_min = pit_min; + *T0_min_frac = 0; + } + + /* Higher-bound */ + temp1 = (*T0_min*res) + *T0_min_frac + (1< pit_max) + { + *T0_max = pit_max; + *T0_max_frac = res - 1; + temp1 = (*T0_max*res) + *T0_max_frac - (1< -#include "options.h" /* Compilation switches */ -#include "cnst_fx.h" /* Common constants */ -#include "prot_fx.h" /* Function prototypes */ -#include "stl.h" -#include "rom_basop_util.h" - - -/*-------------------------------------------------* - * Local constants - *-------------------------------------------------*/ - -#define LIMIT_PIT_REL_LOWER 2 /* delta interval to extend pitch coding in relative Q */ -#define LIMIT_PIT_REL_UPPER 0 - -/*-------------------------------------------------* - * limit_T0() - * - * Close-loop pitch lag search limitation - *-------------------------------------------------*/ - - -void limit_T0_fx( - const Word16 L_frame, /* i : length of the frame */ - const Word16 delta, /* i : Half the close-loop searched interval */ - const Word16 pit_flag, /* i : selecting absolute(0) or delta(1) pitch quantization */ - const Word16 limit_flag, /* i : flag for Q limits (0=restrained, 1=extended) */ - const Word16 T0, /* i : rough pitch estimate around which the search is done */ - const Word16 T0_frac, /* i : pitch estimate fractional part */ - Word16 *T0_min, /* o : lower pitch limit */ - Word16 *T0_max /* o : higher pitch limit */ -) -{ - - Word16 delta2,T1; - Word16 pit_min, pit_max; - - IF( limit_flag == 0 ) /* restrained Q limits */ - { - /* set limits */ - IF( sub(L_frame,L_FRAME) == 0) - { - pit_max = PIT_MAX; - move16(); - pit_min = PIT_MIN; - move16(); - } - ELSE /* L_frame == L_FRAME16k */ - { - pit_max = PIT16k_MAX; - move16(); - pit_min = PIT16k_MIN; - move16(); - } - - delta2 = sub(shl(delta,1),1); - T1 = T0; - move16(); - - if( sub(T0_frac,2) >= 0 ) - { - T1 = add(T1,1); - } - - *T0_min = sub(T1,delta); - move16(); - - *T0_min = s_max(*T0_min,pit_min); - - *T0_max = add(*T0_min,delta2); - move16(); - - IF( sub(*T0_max,pit_max) > 0) - { - *T0_max = pit_max; - move16(); - *T0_min = sub(*T0_max,delta2); - move16(); - } - } - ELSE /* extended Q limits */ - { - /* set limits */ - IF( sub(L_frame, L_FRAME) == 0) - { - pit_max = PIT_MAX; - move16(); - pit_min = PIT_MIN_EXTEND; - move16(); - if( sub(limit_flag, 2) == 0 ) - { - pit_min = PIT_MIN_DOUBLEEXTEND; - move16(); - } - } - ELSE /* L_frame == L_FRAME16k */ - { - pit_max = PIT16k_MAX; - move16(); - pit_min = PIT16k_MIN_EXTEND; - move16(); - } - - delta2 = sub(shl(delta,1),1) ; - move16(); - T1 = T0; - move16(); - if( sub(T0_frac,2) >= 0 ) - { - T1 = add(T1,1); - } - *T0_min = sub(T1, delta); - move16(); - IF( pit_flag == 0 ) - { - /* subframes with absolute search: keep Q range */ - *T0_min = s_max(*T0_min,pit_min); - - *T0_max = add(*T0_min, delta2); - move16(); - IF( sub(*T0_max,pit_max) > 0) - { - *T0_max = pit_max; - move16(); - *T0_min = sub(*T0_max, delta2); - move16(); - } - } - ELSE - { - /* subframes with relative search: extend Q range */ - *T0_min = s_max(*T0_min,sub(pit_min, LIMIT_PIT_REL_LOWER)); - move16(); - - *T0_min = s_max(*T0_min,L_INTERPOL); - *T0_max = *T0_min + delta2; - move16(); - - IF( sub(*T0_max, add(pit_max, LIMIT_PIT_REL_UPPER)) > 0 ) - { - *T0_max = add(pit_max, LIMIT_PIT_REL_UPPER); - move16(); - *T0_min = sub(*T0_max, delta2); - move16(); - } - } - } - return; -} - - -#define inv_T0_res InvIntTable - -/*-------------------------------------------------* -* Routine limit_T0_voiced() -* -* Close-loop pitch lag search limitation -*-------------------------------------------------*/ -void limit_T0_voiced( - const Word16 nbits, - const Word16 res, - const Word16 T0, /* i : rough pitch estimate around which the search is done */ - const Word16 T0_frac, /* i : pitch estimate fractional part */ - const Word16 T0_res, /* i : pitch resolution */ - Word16 *T0_min, /* o : lower pitch limit */ - Word16 *T0_min_frac, /* o : lower pitch limit */ - Word16 *T0_max, /* o : higher pitch limit */ - Word16 *T0_max_frac, /* o : higher pitch limit */ - const Word16 pit_min, /* i : Minimum pitch lag */ - const Word16 pit_max /* i : Maximum pitch lag */ -) -{ - Word16 T1, temp1, temp2, res2; - - - assert(res > 1 && res<=6); - - res2 = res; - move16(); - if(sub(res,6) == 0) - { - res2 = shr(res2,1); - } - - /* Mid-point */ - T1 = T0; - test(); - if( sub(T0_res,1) > 0 && sub(T0_frac,(shr(T0_res,1))) >= 0 ) - { - T1 = add(T1,1); - } - - /* Lower-bound */ - temp1 = sub(i_mult(T1,res),shl(1,sub(nbits,1))); - - temp2 = mult(temp1,inv_T0_res[res2]); - if(sub(res,6) == 0) - { - temp2 = shr(temp2,1); - } - - *T0_min = temp2; - move16(); - - *T0_min_frac = sub(temp1,i_mult(temp2,res)); - move16(); - - IF ( sub(*T0_min,pit_min) < 0) - { - *T0_min = pit_min; - move16(); - *T0_min_frac = 0; - move16(); - } - - /* Higher-bound */ - temp1 = add(i_mult(*T0_min,res),add(*T0_min_frac,sub(shl(1,nbits),1))); - - temp2 = mult(temp1,inv_T0_res[res2]); - if(sub(res,6) == 0) - { - temp2 = shr(temp2,1); - } - - *T0_max = temp2; - move16(); - - *T0_max_frac = sub(temp1,i_mult(temp2,res)); - move16(); - - IF ( sub(*T0_max,pit_max) > 0) - { - *T0_max = pit_max; - move16(); - - *T0_max_frac = sub(res,1); - move16(); - - temp1 = add(i_mult(*T0_max,res),sub(*T0_max_frac,sub(shl(1,nbits),1))); - - temp2 = mult(temp1,inv_T0_res[res2]); - if(sub(res,6) == 0) - { - temp2 = shr(temp2,1); - } - move16(); - *T0_min = temp2; - - *T0_min_frac = sub(temp1, i_mult(temp2,res)); - move16(); - } - - - return; -} diff --git a/src/libs/libevs/lib_com/logqnorm.cpp b/src/libs/libevs/lib_com/logqnorm.cpp new file mode 100644 index 00000000..40c0c677 --- /dev/null +++ b/src/libs/libevs/lib_com/logqnorm.cpp @@ -0,0 +1,163 @@ +/*==================================================================================== + EVS Codec 3GPP TS26.443 Nov 13, 2018. Version 12.11.0 / 13.7.0 / 14.3.0 / 15.1.0 + ====================================================================================*/ + +#include +#include "options.h" +#include "cnst.h" +#include "prot.h" +#include "rom_com.h" +#include "prot.h" /* Function prototypes */ + +/*-------------------------------------------------------------------------- + * logqnorm() + * + * Log quantization for norms of sub-vectors + *--------------------------------------------------------------------------*/ + +void logqnorm( + const float *x, /* i : coefficient vector */ + short *k, /* o : index */ + const short L, /* i : codebook length */ + const short N, /* i : sub-vector size */ + const float *thren /* i : quantization thresholds */ +) +{ + short i, j, j1, j2; + float temp, power; + + + temp = 0.0; + for (i=0; i 0) + { + *k = L - 1; + } + else + { + power = (float)sqrt(temp); + + j1 = 0; + j2 = L - 1; + while ((j2-j1)>1) + { + j = (j1 + j2) >> 1; + if ( power >= thren[j] ) + { + j2 = j; + } + else + { + j1 = j; + } + } + + *k = j2; + } + + return; +} + + +/*-------------------------------------------------------------------------- + * logqnorm_2() + * + * + *--------------------------------------------------------------------------*/ + +void logqnorm_2( + const float *env_fl, /* o : index */ + const short L, /* i : codebook length */ + const short n_env_band, /* i : sub-vector size */ + const short nb_sfm, /* i : sub-vector size */ + short *ynrm, + short *normqlg2, + const float *thren /* i : quantization thresholds */ +) +{ + short i, j, j1, j2; + float temp, power; + + for(i=n_env_band; i 0) + { + *ynrm = L - 1; + } + else + { + power = temp; + j1 = 0; + j2 = L - 1; + while ((j2-j1)>1) + { + j = (j1 + j2) >> 1; + if ( power >= thren[j] ) + { + j2 = j; + } + else + { + j1 = j; + } + } + *ynrm = j2; + } + *normqlg2 = dicnlg2[*ynrm]; + normqlg2++; + ynrm++; + } + + return; +} + +/*-------------------------------------------------------------------------- + * calc_norm() + * + * Calculate the norms for the spectral envelope + *--------------------------------------------------------------------------*/ + +void calc_norm( + const float *x, /* i : Input vector. */ + short *norm, /* o : Quantization indices for norms */ + short *normlg, /* o : Quantized norms in log2 */ + const short start_band, /* i : Indice of band to start coding */ + const short num_bands, /* i : Number of bands */ + const short *band_len, /* i : Length of bands */ + const short *band_start /* i : Start of bands */ +) +{ + short nrm; + short band; + + set_s(norm, 0, start_band); + + logqnorm(&x[band_start[start_band]], &nrm, 32, band_len[start_band], thren_HQ); + norm[start_band] = nrm; + normlg[start_band] = dicnlg2[nrm]; + + for (band = start_band + 1; band < start_band + num_bands; band++) + { + logqnorm( &x[band_start[band]], &nrm, 40, band_len[band], thren_HQ ); + norm[band] = nrm; + normlg[band] = dicnlg2[nrm]; + } + + return; +} diff --git a/src/libs/libevs/lib_com/logqnorm_fx.cpp b/src/libs/libevs/lib_com/logqnorm_fx.cpp deleted file mode 100755 index e2ceac70..00000000 --- a/src/libs/libevs/lib_com/logqnorm_fx.cpp +++ /dev/null @@ -1,195 +0,0 @@ -/*==================================================================================== - EVS Codec 3GPP TS26.442 Apr 03, 2018. Version 12.11.0 / 13.6.0 / 14.2.0 - ====================================================================================*/ - -#include "options.h" /* Compilation switches */ -#include "prot_fx.h" /* Function prototypes */ -#include "stl.h" /* required for wmc_tool */ -#include "rom_com_fx.h" /* Static table prototypes */ -#include "cnst_fx.h" /* Common constants */ - -/* Local constants */ -#define THREN2POW 1518500250L - -/*--------------------------------------------------------------------------* - * logqnorm_fx - * - * Log quantization for norms of sub-vectors - *--------------------------------------------------------------------------*/ - -void logqnorm_fx( - const Word32 *L_x, /* i : coefficient vector Qx */ - const Word16 qx, /* i : Q value of input */ - Word16 *k, /* o : index Q0 */ - const Word16 L, /* i : codebook length Q0 */ - const Word16 N, /* i : sub-vector size Q0 */ - const Word16 hvq_flag /* i : HVQ flag Q0 */ -) -{ - Word16 i, m; - Word16 coefs_shift, power_shift, temp_shift; - Word32 L_temp, L_temp1, L_temp2; - Word16 coefs16[MAX_SFM_LEN_FX]; - UWord16 lsb; - - Word16 offset = add(3,shl(qx,1)); /* 3 + 2*qx */ - - lsb = 0U; /* to avoid compilation warnings */ - - L_temp1 = L_deposit_l(1); - FOR (i=0; i 0 ) - { - Mpy_32_16_ss(L_temp, inv_tbl_fx[N], &L_temp, &lsb); - } - power_shift = shl(sub(coefs_shift, 16), 1); - - temp_shift = norm_l(L_temp); - m = add(temp_shift, power_shift); - - L_temp1 = L_add(L_shl(L_temp, temp_shift), lshr(lsb, sub(16, temp_shift))); - - m = add(offset, m); - test(); - IF( m < 5 && hvq_flag ) - { - m = shl(m, 1); - IF( L_sub(L_temp1, 1276901417L /* 2^0.25 Q30 */) < 0 ) - { - m = add(m, 2); - } - ELSE if( L_sub(L_temp1, 1805811301L /* 2^0.75 Q30 */) < 0 ) - { - m = add(m, 1); - } - } - ELSE - { - if ( L_sub(L_temp1, THREN2POW /* 2^0.5 Q30 */) < 0 ) - { - m = add(m, 1); - } - if ( hvq_flag ) - { - m = add(m, 5); /* offset, 5 extra levels in HVQ codebook */ - } - } - *k = s_max(m, 0); - i = sub(L, 1); - *k = s_min(*k, i); - - return; -} - -void logqnorm_2_fx( - const Word32 *env_fl, /* o, Q10 : index */ - const Word16 L, /* i : codebook length */ - const Word16 n_env_band, /* i : sub-vector size */ - const Word16 nb_sfm, /* i : sub-vector size */ - Word16 *ynrm, - Word16 *normqlg2, - const Word32 *thren /* i, Q10 : quantization thresholds */ -) -{ - Word16 i, j, j1, j2; - Word32 temp, power; - - FOR( i=n_env_band; i < nb_sfm; i++ ) - { - temp = env_fl[ sub(i,n_env_band) ]; - IF ( L_sub(thren[0], temp) <= 0 ) - { - *ynrm = 0; - move16(); - } - ELSE IF ( L_sub(thren[sub(L,2)], temp) > 0) - { - *ynrm = sub(L, 1); - } - ELSE - { - power = temp; - move16(); - j1 = 0; - move16(); - j2 = sub(L, 1); - WHILE ( sub(sub(j2,j1),1) > 0 ) - { - j = shr(add(j1 , j2), 1); - IF ( L_sub(power,thren[j]) >= 0 ) - { - j2 = j; - move16(); - } - ELSE - { - j1 = j; - move16(); - } - } - *ynrm = j2; - move16(); - } - *normqlg2 = dicnlg2[*ynrm]; - move16(); - normqlg2++; - ynrm++; - } - - return; -} - -/*-------------------------------------------------------------------------- - * calc_norm_fx() - * - * Calculate the norms for the spectral envelope - *--------------------------------------------------------------------------*/ - -void calc_norm_fx( - const Word32 *L_x, /* i : Input vector. Qx */ - const Word16 qx, /* i : Q value of input */ - Word16 *norm, /* o : Quantization indices for norms Q0 */ - Word16 *normlg, /* o : Quantized norms in log2 Q0 */ - const Word16 start_band, /* i : Indice of band to start coding Q0 */ - const Word16 num_bands, /* i : Number of bands Q0 */ - const Word16 *band_len, /* i : Length of bands Q0 */ - const Word16 *band_start /* i : Start of bands Q0 */ -) -{ - Word16 nrm; - Word16 band; - Word16 tmp; - - set16_fx(norm, 0, start_band); - logqnorm_fx(&L_x[band_start[start_band]], qx, &nrm, 32, band_len[start_band], 0); - norm[start_band] = nrm; - move16(); - normlg[start_band] = dicnlg2[nrm]; - move16(); - - tmp = add(start_band, num_bands); - FOR (band = add(start_band, 1); band < tmp; band++) - { - logqnorm_fx(&L_x[band_start[band]], qx, &nrm, 40, band_len[band], 0); - - norm[band] = nrm; - move16(); - normlg[band] = dicnlg2[nrm]; - move16(); - } - - return; -} diff --git a/src/libs/libevs/lib_com/longarith.cpp b/src/libs/libevs/lib_com/longarith.cpp old mode 100755 new mode 100644 index 4a51b599..96a45166 --- a/src/libs/libevs/lib_com/longarith.cpp +++ b/src/libs/libevs/lib_com/longarith.cpp @@ -1,47 +1,162 @@ /*==================================================================================== - EVS Codec 3GPP TS26.442 Apr 03, 2018. Version 12.11.0 / 13.6.0 / 14.2.0 + EVS Codec 3GPP TS26.443 Nov 13, 2018. Version 12.11.0 / 13.7.0 / 14.3.0 / 15.1.0 ====================================================================================*/ #include #include -#include "prot_fx.h" -#include "stl.h" +#include "prot.h" + + /** - * \brief inplace long shift right: a[] = a[] >> bits - * Logical shift right of UWord32 vector a[] by 'bits' positions. - * BASOP cycles: FLC cycles - * len = 1: 8 lena = 2: 24 - * len = 2: 13 lena = 4: 34 - * len = 3: 18 lena = 6: 44 - * len = 4: 23 lena = 8: 54 - * \param UWord32 a[] - * Input: vector of the length len - * \param Word16 bits - * Input: number of bit positions to shift right in range 1..31 - * Note: 'bits' must not be 0, this would cause a shift-overflow - * \param Word16 len - * Input: length of vector a[] in units of 'UWord32' + * \brief long addition: a[] = a[] + b[] + * Addition of unsigned vectors a[] and b[] without saturation. + * All words of b[] are added with carry to the corresponding words in a. + * An assertion failure occurs, if lenb exceeds lena or if overflow occurs. + * + * \param unsigned short a[] + * Input/Output: vector of the length lena + * \param unsigned short b[] + * Input: vector of the length lenb + * \param int lena + * Input: length of vector a[] in units of 'unsigned short' + * Note: lena must be greater/equal lenb + * \param int lenb + * Input: length of vector b[] in units of 'unsigned short' * * \return void */ -void longshr(UWord32 a[], Word16 bits, Word16 len) +void longadd(unsigned short a[], unsigned short b[], int lena, int lenb) { - Word16 fracb_u, k; + int h; + long carry = 0; - assert ((bits > 0) && (bits < 32)); - - fracb_u = sub(32,bits); - len = sub(len,1); - FOR (k=0; k < len; k++) + assert(lena >= lenb); + for (h=0; h < lenb; h++) { - a[k] = L_or(L_lshr(a[k],bits),L_lshl(a[k+1],fracb_u)); - move32(); + carry += ((unsigned long)a[h]) + ((unsigned long)b[h]); + a[h] = (unsigned short) carry; + carry = carry >> 16; + } + for (; h < lena; h++) + { + carry = ((unsigned long)a[h]) + carry; + a[h] = (unsigned short) carry; + carry = carry >> 16; } - a[k] = L_lshr(a[k],bits); - move32(); + assert(carry == 0); /* carry != 0 indicates addition overflow */ + return; +} + +/** + * \brief long shift right: d[] = a[] >> b + * Logical shift right of unsigned vectors a[] by b bit-positions. + * Vector d[] is filled with leading zeroes, where lend exceeds lena. + * It is allowed to overlay d[] with a[]. + * + * \param unsigned short a[] + * Input: vector of the length lena + * \param int b + * Input: number of bit positions to shift right + * \param unsigned short d[] + * Output: vector of the length lend + * Note: vector d[] can be overlaid with vector a[], i.e. a[] = a[] >> b + * \param int lena + * Input: length of vector a[] in units of 'unsigned short' + * \param int lend + * Input: length of vector d[] in units of 'unsigned short' + * + * \return void + */ + +void longshiftright(unsigned short a[], int b, unsigned short d[], int lena, int lend) +{ + int intb, fracb, fracb_u, k; + + + intb = b >> 4; + + a += intb; + lena -= intb; + + fracb = b & 0xF; + if (fracb) + { + fracb_u = 16-fracb; + for (k=0; k < lena-1; k++) + { + d[k] = ((a[k] >> fracb) | (a[k+1] << fracb_u)) & 0xFFFF; + } + d[k] = (a[k] >> fracb); + k++; + } + else + { + for (k=0; k < lena; k++) + { + d[k] = a[k]; + } + } + /* fill remaining upper bits with zero */ + for (; k < lend; k++) + { + d[k] = 0; + } + return; +} + +/** + * \brief long shift left: d[] = a[] << b + * Logical shift left of unsigned vectors a[] by b bit-positions. + * It is allowed to overlay d[] with a[]. + * + * \param unsigned short a[] + * Input: vector of the length len + * \param int b + * Input: number of bit positions to shift left + * \param unsigned short d[] + * Output: vector of the length len + * Note: vector d[] can be overlaid with vector a[], i.e. a[] = a[] << b + * \param int len + * Input: length of vector a[] and d[] in units of 'unsigned short' + * + * \return void + */ + +void longshiftleft(unsigned short a[], int b, unsigned short d[], int len) +{ + int intb; /* integer part of b */ + int fracb; /* shift left value for all upper words a[k] */ + int fracb_l; /* shift right value for all lower words a[k-1] */ + int k = len - 1; + + + intb = b >> 4; + fracb = b & 0xF; + + if (fracb) + { + fracb_l = 16-fracb; + for (; k >intb; k--) + { + d[k] = (a[k-intb] << fracb) | (a[k-intb-1] >> fracb_l); + } + d[k] = (a[k-intb] << fracb); + k--; + } + else + { + for (; k >= intb; k--) + { + d[k] = a[k-intb]; + } + } + for ( ; k >= 0; k--) + { + d[k] = 0; + } return; } diff --git a/src/libs/libevs/lib_com/low_rate_band_att.cpp b/src/libs/libevs/lib_com/low_rate_band_att.cpp new file mode 100644 index 00000000..3ac6ef87 --- /dev/null +++ b/src/libs/libevs/lib_com/low_rate_band_att.cpp @@ -0,0 +1,163 @@ +/*==================================================================================== + EVS Codec 3GPP TS26.443 Nov 13, 2018. Version 12.11.0 / 13.7.0 / 14.3.0 / 15.1.0 + ====================================================================================*/ + +#include +#include +#include "options.h" +#include "rom_com.h" +#include "prot.h" + + +/*--------------------------------------------------------------------------* + * fine_gain_pred() + * + * Fine gain prediction + *--------------------------------------------------------------------------*/ + +void fine_gain_pred( + const short *sfm_start, /* i : Sub band start indices */ + const short *sfm_end, /* i : Sub band end indices */ + const short *sfm_size, /* i : Sub band bandwidths */ + const short *i_sort, /* i : Energy sorting indices */ + const short *K, /* i : Number of pulses per band */ + const short *maxpulse, /* i : Maximum pulse per band */ + const short *R, /* i : Bits per sub band (Q3) */ + const short num_sfm, /* i : Number of sub bands */ + float *xq, /* i/o: Quantized vector /quantized vector with finegain adj */ + short *y, /* i/o: Quantized vector (int) */ + float *fg_pred, /* o : Predicted fine gains */ + const short core /* i : Core */ +) +{ + short i, band; + float gp; + float xx; + float accuracy; + short k, bw; + float att; + + for( band = 0; band < num_sfm; band++) + { + + k = K[i_sort[band]]; + if(k > 0) + { + bw = sfm_size[i_sort[band]]; + xx = 0; + for(i = sfm_start[i_sort[band]]; i < sfm_end[i_sort[band]]; i++) + { + xx += xq[i] * xq[i]; + } + + if ( xx > 0) + { + /* Normalize synthesis to RMS=1.0 */ + gp = (float) sqrt(bw / xx); + + if (core == HQ_CORE && R != NULL && R[i_sort[band]] <= 256) + { + accuracy = ((float)k/(float)bw)*maxpulse[i_sort[band]]; + att = 1.0f - 0.05f / accuracy; + att = max( 0.840896f, att); /* Limit attenuation to norm quantizer error, 2^-0.25 */ + gp *= att; + } + + fg_pred[band] = gp; + } + else + { + fg_pred[band] = 0; + } + } + else + { + fg_pred[band] = 0; + for(i = sfm_start[i_sort[band]]; i < sfm_end[i_sort[band]]; i++) + { + y[i] = 0; + xq[i] = 0; + } + } + } + return; +} + +/*--------------------------------------------------------------------------* + * get_max_pulses() + * + * Find the maximum pulse height (in unit pulses) in each band + *--------------------------------------------------------------------------*/ + +void get_max_pulses( + const short *band_start, /* i : Sub band start indices */ + const short *band_end, /* i : Sub band end indices */ + const short *k_sort, /* i : Indices for sorting by energy */ + const short *npulses, /* i : Pulses per sub band */ + const short BANDS, /* i : Number of bands */ + short *inp_vector, /* i/o: Encoded shape vectors (int)*/ + short *maxpulse /* o : Maximum pulse height per band */ +) +{ + short i, k; + int npul; + int maxp; + + for (k = 0; k < BANDS; k++) + { + npul = npulses[k_sort[k]]; + maxp = 0; + if (npul > 0) + { + for (i = band_start[k_sort[k]]; i < band_end[k_sort[k]]; i++) + { + if (abs(inp_vector[i]) > maxp) + { + maxp = abs(inp_vector[i]); + } + } + } + maxpulse[k_sort[k]] = maxp; + } + + return; +} + +/*--------------------------------------------------------------------------* + * fine_gain_dec() + * + * Fine gain decoder. Decodes fine gain adjustments and applies correction to + * predicted fine gains + *--------------------------------------------------------------------------*/ + +void fine_gain_dec +( + Decoder_State *st, /* i/o: Decoder state struct */ + const short *ord, /* i : Indices for energy order */ + const short num_sfm, /* i : Number of bands */ + const short *gain_bits, /* i : Gain adjustment bits per sub band */ + float *fg_pred /* i/o: Predicted gains / Corrected gains */ +) +{ + short band; + short gbits; + short idx; + float gain_dbq; + + for ( band = 0; band < num_sfm; band++) + { + gbits = gain_bits[ord[band]]; + if ( fg_pred[band] != 0 && gbits > 0 ) + { + idx = (short)get_next_indice( st, (short)gbits ); + gain_dbq = finegain[gbits-1][idx]; + + /* Update prediced gain with quantized correction */ + fg_pred[band] *= (float)pow(10, gain_dbq * 0.05f); + } + } + + return; +} + + diff --git a/src/libs/libevs/lib_com/low_rate_band_att_fx.cpp b/src/libs/libevs/lib_com/low_rate_band_att_fx.cpp deleted file mode 100755 index c46e334e..00000000 --- a/src/libs/libevs/lib_com/low_rate_band_att_fx.cpp +++ /dev/null @@ -1,219 +0,0 @@ -/*==================================================================================== - EVS Codec 3GPP TS26.442 Apr 03, 2018. Version 12.11.0 / 13.6.0 / 14.2.0 - ====================================================================================*/ - -#include -#include "options.h" /* Compilation switches */ -#include "rom_com_fx.h" /* Static table prototypes */ -#include "prot_fx.h" -#include "stl.h" /* required for wmc_tool */ - - -/*--------------------------------------------------------------------------* - * fine_gain_pred() - * - * Fine gain prediction - *--------------------------------------------------------------------------*/ - -void fine_gain_pred_fx( - const Word16 *sfm_start, /* i : Sub band start indices */ - const Word16 *sfm_end, /* i : Sub band end indices */ - const Word16 *sfm_size, /* i : Sub band bandwidths */ - const Word16 *i_sort, /* i : Energy sorting indices */ - const Word16 *K, /* i : Number of pulses per band */ - const Word16 *maxpulse, /* i : Maximum pulse per band */ - const Word16 *R, /* i : Bits per sub band Q3 */ - const Word16 num_sfm, /* i : Number of sub bands */ - Word16 *xq, /* i/o: Quantized vector /quantized vector with finegain adj Q15*/ - Word16 *y, /* i/o: Quantized vector (int) */ - Word16 *fg_pred, /* o : Predicted fine gains Q12 */ - const Word16 core /* i : Core */ -) -{ - Word16 i, band; - Word16 gp; - Word32 xx; - Word16 accuracy; - Word16 k, bw; - - Word16 shift, bw_idx; - Word16 tmp, exp, exp2; - Word32 L_tmp; - UWord16 lsb; - - FOR( band = 0; band < num_sfm; band++) - { - k = K[i_sort[band]]; - move16(); - - IF( k > 0) - { - /* bw, bw_idx only used if k>0 */ - bw = sfm_size[i_sort[band]]; - move16(); /* allowed. 8, 16, 24,32,48,64,80,96 */ - bw_idx = band_len_idx[ shr(bw,3) ]; - move16(); /* bw_idx= 0: 7 */ - xx = L_deposit_l(0); - shift = band_len_ener_shift[bw_idx]; - FOR(i = sfm_start[i_sort[band]]; i < sfm_end[i_sort[band]]; i++) - { - /*xx += xq[i] * xq[i]; */ - tmp = shr(xq[i], shift); /*15-shift */ - xx = L_mac0(xx, tmp, tmp); /*30-2*shift */ - } - - IF ( xx > 0) - { - /* Normalize synthesis to RMS=1.0 */ - /*gp = (float) sqrt(bw / xx); */ - exp = norm_l(xx); - L_tmp = L_shl(xx, exp); /*2*(15-shift)+exp */ - exp = sub(31, add(exp, sub(30, shl(shift,1)))); - L_tmp = Isqrt_lc(L_tmp, &exp); /*31 - exp */ - Mpy_32_16_ss(L_tmp, fine_gain_pred_sqrt_bw[bw_idx], &L_tmp, &lsb); /*31-exp+11-15=27-exp */ - gp = round_fx(L_shl(L_tmp, add(1, exp))); /*27-exp+1+exp-16=12 */ - - test(); - test(); - IF (sub(core, HQ_CORE) == 0 && R != NULL && sub(R[i_sort[band]], 256) <= 0) /* 256 is 32 in Q3 */ - { - /*accuracy = ((float)k/(float)bw)*maxpulse[i_sort[band]]; */ - L_tmp = L_mult(k, inv_tbl_fx[bw]); /*0+15+1 */ - exp2 = norm_l(L_tmp); - tmp = round_fx(L_shl(L_tmp, exp2)); /*16+exp2-16 */ - L_tmp = L_mult0(maxpulse[i_sort[band]], tmp); /*0+exp2 */ - exp = norm_l(L_tmp); - accuracy = round_fx(L_shl(L_tmp, exp)); /*exp2+exp-16=exp-16 */ - exp = add(exp, exp2); - - /*gp *= 1.0f - 0.05f / accuracy; */ - tmp = div_s(13107, accuracy); /* 0.05 in Q18 */ - tmp = shr(tmp, sub(34, exp)); /*15+18-exp+16-15=34-exp */ - tmp = sub(32767, tmp); - tmp = s_max(27554, tmp); /* Limit attenuation to norm quantizer error, 2^-0.25 in Q15 */ - gp = mult_r(tmp, gp); /*15+12+1-16=12 */ - } - - fg_pred[band] = gp; - move16(); - } - ELSE - { - fg_pred[band] = 0; - move16(); - } - } - ELSE - { - fg_pred[band] = 0; - move16(); - FOR(i = sfm_start[i_sort[band]]; i < sfm_end[i_sort[band]]; i++) - { - y[i] = 0; - move16(); - xq[i] = 0; - move16(); - } - } - } - - return; -} - -/*--------------------------------------------------------------------------* - * get_max_pulses() - * - * Find the maximum pulse height (in unit pulses) in each band - *--------------------------------------------------------------------------*/ - -void get_max_pulses_fx( - const Word16 *band_start, /* i : Sub band start indices */ - const Word16 *band_end, /* i : Sub band end indices */ - const Word16 *k_sort, /* i : Indices for sorting by energy */ - const Word16 *npulses, /* i : Pulses per sub band */ - const Word16 BANDS, /* i : Number of bands */ - Word16 *inp_vector, /* i/o: Encoded shape vectors (int)*/ - Word16 *maxpulse /* o : Maximum pulse height per band */ -) -{ - Word16 i, k; - Word16 npul; - Word16 maxp; - Word16 tmp; - - FOR (k = 0; k < BANDS; k++) - { - npul = npulses[k_sort[k]]; - move16(); - maxp = 0; - move16(); - IF (npul > 0) - { - FOR (i = band_start[k_sort[k]]; i < band_end[k_sort[k]]; i++) - { - tmp = abs_s(inp_vector[i]); - if (sub(tmp, maxp) > 0) - { - maxp = tmp; - move16(); - } - } - } - maxpulse[k_sort[k]] = maxp; - move16(); - } - - return; -} - -/*--------------------------------------------------------------------------* - * fine_gain_dec() - * - * Fine gain decoder. Decodes fine gain adjustments and applies correction to - * predicted fine gains - *--------------------------------------------------------------------------*/ - -void fine_gain_dec_fx -( - Decoder_State_fx *st, - const Word16 *ord, /* i : Indices for energy order */ - const Word16 num_sfm, /* i : Number of bands */ - const Word16 *gain_bits, /* i : Gain adjustment bits per sub band */ - Word16 *fg_pred /* i/o: Predicted gains / Corrected gains */ -) -{ - Word16 band; - Word16 gbits; - Word16 idx, tmp1, exp1; - Word16 gain_dbq; - Word32 L_tmp; - - - FOR ( band = 0; band < num_sfm; band++) - { - gbits = gain_bits[ord[band]]; - IF (gbits > 0) - { - IF (fg_pred[band] != 0) - { - idx = get_next_indice_fx( st, gbits ); - gain_dbq = finegain_fx[gbits-1][idx]; - - /* Update predicted gain with quantized correction */ - L_tmp = L_mult0(gain_dbq, 21771); /* 21771=0.05*log2(10) */ /* 14+17=31 */ - L_tmp = L_shr(L_tmp, 15); - tmp1 = L_Extract_lc(L_tmp, &exp1); - tmp1 = abs_s(tmp1); - tmp1 = extract_l(Pow2(14, tmp1)); - exp1 = sub(14, exp1); - - L_tmp = L_mult0(fg_pred[band], tmp1); /*12+exp1 */ - fg_pred[band] = round_fx(L_shl(L_tmp, sub(16, exp1))); /*12+exp1+16-exp1-16=12 */ - } - } - } - - return; -} - - diff --git a/src/libs/libevs/lib_com/lpc_tools.cpp b/src/libs/libevs/lib_com/lpc_tools.cpp new file mode 100644 index 00000000..cf59f077 --- /dev/null +++ b/src/libs/libevs/lib_com/lpc_tools.cpp @@ -0,0 +1,300 @@ +/*==================================================================================== + EVS Codec 3GPP TS26.443 Nov 13, 2018. Version 12.11.0 / 13.7.0 / 14.3.0 / 15.1.0 + ====================================================================================*/ + +#include +#include +#include "options.h" +#include "cnst.h" +#include "prot.h" +#include "rom_com.h" + + +/*-----------------------------------------------------------------* + * Local constants + *-----------------------------------------------------------------*/ + +#define MAX_LEN_LP 960 +#define SCALE1_LPC 2037.1832275390625f /* LSP to LSF conversion factor */ + + +/*---------------------------------------------------------------------* + * autocorr() + * + * Compute autocorrelations of input signal + *---------------------------------------------------------------------*/ + +void autocorr( + const float *x, /* i : input signal */ + float *r, /* o : autocorrelations vector */ + const short m, /* i : order of LP filter */ + const short len, /* i : window size */ + const float *wind, /* i : window */ + const short rev_flag, /* i : flag to reverse window */ + const short sym_flag, /* i : symmetric window flag */ + const short no_thr /* i : flag to avoid thresholding */ +) +{ + float t[MAX_LEN_LP]; + float s; + short i, j; + + /* Windowing of signal */ + if (rev_flag == 1) + { + /* time reversed window */ + for (i = 0; i < len; i++) + { + t[i] = x[i] * wind[len-i-1]; + } + } + else if( sym_flag == 1 ) + { + /* symmetric window of even length */ + for( i=0; i 0.99945f) + { + flag=1;/* Test for unstable filter. If unstable keep old A(z) */ + } + + for ( j = 1; j <= i/2; j++ ) + { + l = i-j; + at = a[j] + rc[i-1] * a[l]; + a[l] += rc[i-1] * a[j]; + a[j] = at; + } + + a[i] = rc[i-1]; + + err += rc[i-1] * s; + if ( err <= 0.0f ) + { + err = 0.01f; + } + + if ( epsP != NULL) + { + epsP[i] = err; + } + } + + return (flag); +} + + +/*---------------------------------------------------------------------* + * E_LPC_int_lpc_tcx() + * + * + *---------------------------------------------------------------------*/ + +void E_LPC_int_lpc_tcx( + const float lsf_old[], /* input : LSFs from past frame */ + const float lsf_new[], /* input : LSFs from present frame */ + float a[] /* output: interpolated LP coefficients */ +) +{ + int i; + float lsf[M]; + + for (i = 0; i < M; i++) + { + lsf[i] = lsf_old[i]*0.125f + lsf_new[i]*0.875f; + } + + lsp2a_stab(lsf, a, M); + + return; +} + +/*---------------------------------------------------------------------* + * lsp_reorder() + * + * + *---------------------------------------------------------------------*/ + +static void lsp_reorder( + float *lsp, /* (I/O): lsp vector (acos() domain) */ + float min_dist, /* (I): minimum required distance */ + int lpcorder /* (I): LPC order */ +) +{ + short i; + float lsp_min, lsp_max; + + /* Verify the LSF ordering and minimum GAP */ + lsp_min = min_dist; + + for (i=0; i lsp_max) + { + /* Reverify the minimum LSF gap in the reverse sense */ + for (i = lpcorder-1; i>=0; --i) + { + if (lsp[i] > lsp_max) + { + lsp[i] = lsp_max; + } + lsp_max = lsp[i] - min_dist; + } + } + + return; +} + + +/*---------------------------------------------------------------------* + * E_LPC_lsp_unweight() + * + * Approximate unweighting + *---------------------------------------------------------------------*/ + +int E_LPC_lsp_unweight( + float lsp_w[], /* (I): weighted lsp */ + float lsp_uw[], /* (O): unweighted lsp */ + float lsf_uw[], /* (O): unweighted lsf */ + float inv_gamma /* (I): inverse weighting factor */ +) +{ + float lsp_w_orig[M], lsp_w_diff[M], mean, step; + const lsp_unw_triplet *unw_coeffs = NULL; + short i; + + /* Table selection */ + if ((float)fabs(inv_gamma - 1.0f / 0.94f) < 0.0001f) + { + unw_coeffs = p16_gamma0_94to1; + } + else if ((float)fabs(inv_gamma - 1.0f / 0.92f) < 0.0001f) + { + unw_coeffs = p16_gamma0_92to1; + } + else + { + assert(0); + } + + step = EVS_PI/(float)(M+1); + mean = step; + + /* Apply acos() and get mean removed version */ + for (i=0; i -#include "options.h" /* Compilation switches */ -#include "cnst_fx.h" /* Common constants */ -#include "prot_fx.h" /* Function prototypes */ -#include "rom_com_fx.h" -#include "stl.h" -#include "basop_mpy.h" -#include "basop_util.h" - - -/*-----------------------------------------------------------------* - * Local constants - *-----------------------------------------------------------------*/ - -#define MAX_LEN_LP 960 /* maximum length in samples of the LP analysis window */ - -/*---------------------------------------------------------------------* - * autocorr() - * - * Compute autocorrelations of input signal - *---------------------------------------------------------------------*/ -void autocorr_fx( - const Word16 x[], /* i : Input signal */ - const Word16 m, /* i : LPC order Q0 */ - Word16 r_h[], /* o : Autocorrelations (msb) Q15 */ - Word16 r_l[], /* o : Autocorrelations (lsb) */ - Word16 *Q_r, /* o : normalisation shift of r Q0 */ - const Word16 len, /* i : Frame lenght */ - const Word16* wind, /* i : Window used */ - Word16 rev_flag, - const Word16 sym_flag /* i : symmetric window flag */ -) -{ - Word16 i, j, norm, shift, y[MAX_LEN_LP]; - Word16 fact; - Word32 L_sum, L_tmp; - - IF(sub(rev_flag,1) == 0) - { - /* Windowing of signal */ - FOR (i = 0; i < len; i++) - { - y[i] = mult_r(x[i], wind[len-i-1]); - move16(); - } - } - ELSE IF( sub(sym_flag,1) == 0 ) - { - /* symmetric window of even length */ - FOR( i=0; i 0) - { - fact = lshr(-32768, shift); - FOR (i = 0; i < len; i++) - { - y[i] = mult_r(y[i], fact); - move16(); - } - } - ELSE - { - shift = 0; - move16(); - } - - /* Compute and normalize r[0] */ - L_sum = L_mac(1, y[0], y[0]); - FOR (i = 1; i < len; i++) - { - L_sum = L_mac(L_sum, y[i], y[i]); - } - norm = norm_l(L_sum); - L_sum = L_shl(L_sum, norm); - L_Extract(L_sum, &r_h[0], &r_l[0]); /* Put in DPF format (see oper_32b) */ - - /* Compute r[1] to r[m] */ - FOR (i = 1; i <= m; i++) - { - L_sum = L_mult(y[0],y[i]); - FOR (j = 1; j < len - i; j++) - { - L_sum = L_mac(L_sum, y[j], y[j + i]); - } - - L_sum = L_shl(L_sum, norm); - L_Extract(L_sum, &r_h[i], &r_l[i]); /* Put in DPF format (see oper_32b) */ - } - - *Q_r = sub(norm, shl(shift, 1)); - move16(); -} - -/***************************************************************************** - * * - * Function Name : Div_32_opt * - * * - * Purpose : * - * Fractional integer division of two 32 bit numbers. * - * L_num / L_denom. * - * L_num and L_denom must be positive and L_num < L_denom. * - * L_denom = denom_hi<<16 + denom_lo<<1 * - * denom_hi is a normalize number. * - * * - * Inputs : * - * * - * L_num * - * 32 bit long signed integer (Word32) whose value falls in the * - * range : 0x0000 0000 < L_num < L_denom * - * * - * L_denom = denom_hi<<16 + denom_lo<<1 (DPF) * - * * - * denom_hi * - * 16 bit positive normalized integer whose value falls in the * - * range : 0x4000 < hi < 0x7fff * - * denom_lo * - * 16 bit positive integer whose value falls in the * - * range : 0 < lo < 0x7fff * - * * - * Return Value : * - * * - * L_div * - * 32 bit long signed integer (Word32) whose value falls in the * - * range : 0x0000 0000 <= L_div <= 0x7fff ffff. * - * * - * Algorithm: * - * * - * - find = 1/L_denom. * - * First approximation: approx = 1 / denom_hi * - * 1/L_denom = approx * (2.0 - L_denom * approx ) * - * * - * - result = L_num * (1/L_denom) * - ***************************************************************************** -*/ -static -Word32 Div_32_opt (Word32 L_num, Word16 denom_hi, Word16 denom_lo) -{ - Word16 approx /*, hi, lo, n_hi , n_lo*/; - Word32 L_32; - - /* First approximation: 1 / L_denom = 1/denom_hi */ - - approx = div_s ((Word16) 0x3fff, denom_hi); - - /* 1/L_denom = approx * (2.0 - L_denom * approx) */ - - L_32 = Msu_32_16 ((Word32) 0x7fffffffL, denom_hi, denom_lo, approx); - - L_32 = Mpy_32_16_1(L_32, approx); - - /* L_num * (1/L_denom) */ - - L_32 = Mpy_32_32(L_num, L_32); - - L_32 = L_shl (L_32, 2); - - return (L_32); -} - -/* - * E_LPC_lev_dur - * - * Parameters: - * Rh I: Rh[m+1] Vector of autocorrelations (msb) - * Rl I: Rl[m+1] Vector of autocorrelations (lsb) - * A O: A[m] LPC coefficients (m = 16) Qx (A[0] is always 1, so the format can be deduced in the caller with norm_s(A[0])) - * epsP O: error vector, msb - * order I: LPC order Q0 - * - * Function: - * Levinson-Durbin algorithm to compute - * the LPC parameters from the autocorrelations of speech. - * - * Returns: - * void - */ -Word16 E_LPC_lev_dur(const Word16 Rh[], const Word16 Rl[], Word16 A[], - Word32 epsP[], const Word16 order - ,Word16 *mem - ) -{ - return(E_LPC_lev_dur_stab(Rh, Rl, A, epsP, order, mem, 32750)); /* 0.99945 in Q15 */ -} - -Word16 E_LPC_lev_dur_stab(const Word16 Rh[], const Word16 Rl[], Word16 A[], - Word32 epsP[], const Word16 order, - Word16 *mem, Word16 k_max - ) -{ - Word16 i, j, k; - Word16 hi, lo; - Word16 Kh, Kl; /* reflection coefficient; hi and lo */ - Word16 alp_h, alp_l, alp_exp; /* Prediction gain; hi lo and exponent */ - Word32 t0, t1, t2; /* temporary variables */ - Word16 flag; - Word16 Ah[TCXLTP_LTP_ORDER + 1], Al[TCXLTP_LTP_ORDER + 1]; /* LPC coef. in double prec. */ - - - BASOP_SATURATE_WARNING_OFF - if(epsP!=NULL) - { - epsP[0] = L_Comp(Rh[0], Rl[0]); - move32(); - } - - flag=0; - move16(); - - /* K = A[1] = -R[1] / R[0] */ - t1 = L_Comp(Rh[1], Rl[1]); /* R[1] in Q31 */ - t2 = L_abs(t1); /* abs R[1] */ - t0 = L_deposit_l(0); - IF (Rh[0] != 0) - { - t0 = Div_32_opt(t2, Rh[0], Rl[0]); /* R[1]/R[0] in Q31 */ - /* Cause a difference in MODE1 due to different implementation of div32*/ - } - if (t1 > 0) - { - t0 = L_negate(t0); /* -R[1]/R[0] */ - } - Kl = L_Extract_lc(t0, &Kh); /* K in DPF */ - t0 = L_shr(t0, 4); /* A[1] in Q27 */ - L_Extract(t0, &Ah[1], &Al[1]); /* A[1] in DPF */ - - /* Alpha = R[0] * (1-K**2) */ - t0 = Sqr_32(Kh, Kl); /* K*K in Q31 */ - t0 = L_abs(t0); /* Some case <0 !! */ - t0 = L_sub((Word32) 0x7fffffffL, t0); /* 1 - K*K in Q31 */ - lo = L_Extract_lc(t0, &hi); /* DPF format */ - t0 = Mpy_32(Rh[0], Rl[0], hi, lo); /* Alpha in Q31 */ - if(epsP!=NULL) - { - epsP[1] = t0; - move32(); - } - - /* Normalize Alpha */ - alp_exp = norm_l(t0); - t0 = L_shl(t0, alp_exp); - alp_l = L_Extract_lc(t0, &alp_h); - /* DPF format */ - - /*--------------------------------------* - * ITERATIONS I=2 to m - *--------------------------------------*/ - - FOR (i = 2; i <= order; i++) - { - /* t0 = SUM(R[j]*A[i-j], j=1, i-1) + R[i] */ - t0 = L_deposit_l(0); - FOR (j = 1; j < i; j++) - { - t0 = Mac_32(t0, Rh[j], Rl[j], Ah[i - j], Al[i - j]); - } - - t0 = L_shl(t0, 4); /* result in Q27 -> convert to Q31 */ - /* No overflow possible */ - - /* Compose and add R[i] in Q3 */ - t0 = L_mac(t0, Rl[i], 1); - t0 = L_msu(t0, Rh[i], -32768); - - /* K = -t0 / Alpha */ - t1 = L_abs(t0); - t2 = L_deposit_l(0); - IF (alp_h != 0) - { - t2 = Div_32_opt(t1, alp_h, alp_l); /* abs(t0)/Alpha */ - /* Cause a difference in MODE1 due to different implementation of div32*/ - } - - if (t0 > 0) - { - t2 = L_negate(t2); /* K =-t0/Alpha */ - } - t2 = L_shl(t2, alp_exp); /* denormalize; compare to Alpha */ - test(); - if ((mem!=NULL) && ((sub(abs_s(extract_h(t2)), k_max) > 0))) - { - flag=1; - move16();/* Test for unstable filter. If unstable keep old A(z) */ - } - if ((mem!=NULL) && ((L_sub(L_abs(t2), 5) < 0))) - { - flag=1; - move16(); /*R matrix not reliable (R saturated for many coeff), keep old A(z) */ - } - Kl = L_Extract_lc(t2, &Kh); /* K in DPF */ - - /*------------------------------------------* - * Compute new LPC coeff. -> An[i] - * An[j]= A[j] + K*A[i-j] , j=1 to i-1 - * An[i]= K - *------------------------------------------*/ - - k = mult_r(i, 16384); - FOR (j = 1; j < k; j++) - { - /* Do two Iterations Together to Allow Direct Update of Ah & Al */ - t0 = Mac_32(L_Comp(Ah[j], Al[j]), Kh, Kl, Ah[i-j], Al[i-j]); - t1 = Mac_32(L_Comp(Ah[i-j], Al[i-j]), Kh, Kl, Ah[j], Al[j]); - L_Extract(t0, &Ah[j], &Al[j]); - L_Extract(t1, &Ah[i-j], &Al[i-j]); - } - IF (s_and(i, 1) == 0) - { - t0 = Mac_32(L_Comp(Ah[j], Al[j]), Kh, Kl, Ah[i-j], Al[i-j]); - L_Extract(t0, &Ah[j], &Al[j]); - } - t2 = L_shr(t2, 4); /* t2 = K in Q31 ->convert to Q27 */ - L_Extract(t2, &Ah[i], &Al[i]); /* An[i] in Q27 */ - - /* Alpha = Alpha * (1-K**2) */ - t1 = L_mult(Kh, Kh); /* K*K in Q31 */ - t0 = L_mac(t1, mult(Kh, Kl), 2); - t0 = L_abs(t0); /* Some case <0 !! */ - t0 = L_sub((Word32) 0x7fffffffL, t0); /* 1 - K*K in Q31 */ - lo = L_Extract_lc(t0, &hi); /* DPF format */ - t0 = Mpy_32(alp_h, alp_l, hi, lo); /* Alpha in Q31 */ - - - /* store denormalized alpha in epsP */ - t1 = L_shr(t0, alp_exp); - if(epsP!=NULL) - { - epsP[i] = t1; - move32(); - } - - /* Normalize Alpha */ - j = norm_l(t0); - t0 = L_shl(t0, j); - alp_l = L_Extract_lc(t0, &alp_h);/* DPF format */ - alp_exp = add(alp_exp, j); /* Add normalization to alp_exp */ - } - - /* Adaptive scaling */ - t1 = L_deposit_l(0); - FOR (i = 1; i <= order; i++) - { - t0 = L_Comp(Ah[i], Al[i]); - t1 = L_max( t1, L_abs(t0) ); - } - k = s_min( norm_l( t1 ), 3 ); - A[0] = shl( 2048, k ); - move16(); - FOR (i = 1; i <= order; i++) - { - t0 = L_Comp(Ah[i], Al[i]); - A[i] = round_fx(L_shl(t0, k)); - } - - BASOP_SATURATE_WARNING_ON - IF (mem != NULL) - { - /* Enforce stable LPC filter - parcorr[0] and parcorr[1] are not LPC coeffiecients */ - IF(flag) - { - Copy(mem, A, order + 1); - } - ELSE /* If stable LPC filter, store into memories */ - { - Copy(A, mem, order + 1); - } - } - - - return(flag); -} - -/* - * E_LPC_a_add_tilt - * - * Parameters: - * a I: LP filter coefficients (m+1 coeffs) - * ap O: modified LP filter coefficients (m+2 coeffs) - * gamma I: tilt factor - * m I: order of LP filter - * - * Function: - * Modified LP filter by adding 1st order pre-premphasis, Ap(z)=A(z).(1-gamma.z^(-1)) - * - * Returns: - * void - */ -void E_LPC_a_add_tilt(const Word16 *a, Word16 *ap, Word16 gamma, Word16 m) -{ - Word16 i; - Word32 Amax, Atmp[M+2]; - Word16 shift; - - - - - Amax = L_mult( 16384, a[0] ); - FOR (i = 1; i <= m; i++) - { - Atmp[i] = L_sub( L_mult(16384, a[i]), L_mult0(gamma, a[i-1]) ); - move32(); - Amax = L_max( Amax, L_abs( Atmp[i] ) ); - } - Atmp[m+1] = L_negate( L_mult0(gamma, a[m]) ); - move32(); - Amax = L_max( Amax, L_abs( Atmp[m+1] ) ); - shift = norm_l( Amax ); - ap[0] = shl( a[0], sub(shift,1) ); - move16(); - FOR (i = 1; i <= m; i++) - { - ap[i] = round_fx( L_shl( Atmp[i], shift ) ); - } - ap[m+1] = round_fx( L_shl( Atmp[m+1], shift ) ); - -} - -void E_LPC_int_lpc_tcx(const Word16 lsp_old[], /* input : LSPs from past frame Q15 */ - const Word16 lsp_new[], /* input : LSPs from present frame Q15 */ - Word16 a[] /* output: interpolated LP coefficients Q12 */ - ) -{ - Word16 i, lsp[M]; - - - - FOR (i = 0; i < M; i++) - { - /*lsp[i] = lsp_old[i]*0.125f + lsp_new[i]*0.875f;*/ - lsp[i] = round_fx(L_mac(L_mult(lsp_old[i],4096),lsp_new[i],28672)); - } - E_LPC_f_lsp_a_conversion(lsp, a, M); - - - return; -} - -static void lsp_reorder( - Word16 *lsp, /* (I/O): LSP vector (acos() domain) Q13*1.2732 */ - Word16 min_dist, /* (I): minimum required distance Q13*1.2732 */ - Word16 lpcorder /* (I): LPC order Q0 */ -) -{ - Word16 i; - Word16 lsp_min, lsp_max; - - - /* Verify the LSF ordering and minimum GAP */ - lsp_min = min_dist; - move16(); - FOR (i=0; i 0) - { - /* Reverify the minimum LSF gap in the reverse sense */ - FOR (i = lpcorder; i>=0; --i) - { - lsp[i] = s_min(lsp[i], lsp_max); - move16(); - lsp_max = sub(lsp[i], min_dist); - } - } - -} - -/* Approximate unweighting */ -Word16 E_LPC_lsp_unweight( - /* const */ Word16 lsp_w[], /* (I): weighted xSP Q15 */ - Word16 lsp_uw[], /* (O): unweighted xSP Q15 */ - Word16 lsf_uw[], /* (O): unweighted LSF Q1*1.28 */ - Word16 inv_gamma, /* (I): inverse weighting factor Q14 */ - Word16 lpcorder /* (I): prediction order Q0 */ -) -{ - Word16 lsp_w_orig[M], lsp_w_diff[M], mean, step; /* Q13*1.2732 */ - const lsp_unw_triplet *unw_coeffs = NULL; - Word16 i; - - step = 0; /* to avoid compilation warnings */ - - - assert(lpcorder == 16); - - /* Table selection */ - IF (sub(inv_gamma, GAMMA16k_INV) == 0) - { - unw_coeffs = p16_gamma0_94to1; - move16(); - } - ELSE IF (sub(inv_gamma, GAMMA1_INV) == 0) - { - unw_coeffs = p16_gamma0_92to1; - move16(); - } - ELSE - { - assert(0); - } - - /* step = M_PI/(float)(lpcorder+1); */ - step = 1927; - move16(); - mean = 0; - move16(); - - /* Apply acos() and get mean removed version */ - FOR (i=0; i 0.01f*2^27/2^30 */ - Word32 tmp_epsP; - - - - mM1 = sub(m,1); - - s = getScaleFactor32(r,add(m,1)); - IF (s!=0) - { - scale_sig32(r,add(m,1),s); /* scale in-place */ - } - - g1 = r; - Copy32(r+1,g0,m); - - /* compute g0[0]/g1[0], where g0[0] < g1[0] */ - temp16 = negate(divide3232(g0[0], g1[0])); - reflCoeff[0] = temp16; - move16(); - move32(); - epsP[0] = r[0]; - - - FOR (i=0; i= 0; specix++);*/ - WHILE (mult(s,spec_r[specix]) >= 0) specix = add(specix, 1); - - tmp = divide1616(spec_r[specix-1], sub(spec_r[specix-1],spec_r[specix] ) ); - move16(); - /*lsf[lsfix] = L_add(L_deposit_h(sub(specix,1)) , L_shl(L_deposit_l(tmp),1));*/ /*Q16*/ - lsf[lsfix] = add(shl(sub(specix,1),7) , shr((tmp),8)); /*7Q8*/ - - lsfix++; - - /*check for the next zero crossing*/ - /*for (; s*spec_i[specix] >= 0; specix++);*/ - - WHILE (mult(s,spec_i[specix]) >= 0) specix = add(specix, 1); - - tmp = divide1616(spec_i[specix-1], sub(spec_i[specix-1],spec_i[specix]) ); - move16(); - /*lsf[lsfix] = L_add(L_deposit_h(sub(specix,1)) , L_shl(L_deposit_l(tmp),1));*/ /*Q16*/ - lsf[lsfix] = add(shl(sub(specix,1),7) , shr((tmp),8)); /*7Q8*/ - - lsfix++; - - spec_r[speclen] = s; - move16(); - spec_i[speclen] = s; - move16(); - - s = negate(s); - } - - IF (sub(lsfix,16) < 0) - { - FOR(i=0; i<16; i++) - { - lsf[i] = old_lsf[i]; - move16(); - } - } - - return; -} - -void E_LPC_a_lsf_isf_conversion(Word16 *lpcCoeffs, Word16 *lsf, const Word16 *old_lsf, Word16 lpcOrder, Word8 lpcRep) -{ - Word32 RealFFT[128]; - Word32 ImagFFT[128]; - Word16 RealOut[130]; - Word16 ImagOut[130]; - Word32 *ptrReal; - Word32 *ptrImag; - Word16 n, i, j, step, scale; - const PWord16 *ptwiddle, *pwn17, *pwn17i; - PWord16 *pwn15, *pwn15i, tmpw15; - Word16 N = 256; - Word16 s[4]; - Word32 L_tmp, L_tmp1, L_tmp3; - Word16 lpc[19]; - - - /* half length FFT */ - scale = add(norm_s(lpcCoeffs[0]),1)+5; - move16(); - - /*s = [sum(a) ((-1).^(1:length(a)))*a];*/ - L_tmp = L_deposit_h(0); - FOR(j=0; j<=lpcOrder; j++) - { - L_tmp = L_mac(L_tmp, lpcCoeffs[j], 0x800); - } - /*s[1] = round_fx(L_tmp); move16();*/ - - L_tmp1 = L_deposit_h(0); - FOR(j=0; jv.re), lpc[2*j+1],ptwiddle->v.im),scale); - move32(); - ptrImag[j*8] = L_shl(L_mac(L_mult(lpc[2*j+1],ptwiddle->v.re), lpc[2*j],ptwiddle->v.im),scale); - move32(); - ptwiddle++; - } - - ptrReal[j*8] = L_shl(L_mac(0,lpc[2*j],ptwiddle->v.re),scale); - move32(); - ptrImag[j*8] = L_shl(L_mac(0, lpc[2*j],ptwiddle->v.im),scale); - move32(); - ptwiddle++; - j++; - FOR(; j<16; j++) - { - ptrReal[j*8] = L_deposit_h(0); - ptrImag[j*8] = L_deposit_h(0); - ptwiddle++; - } - - fft16(ptrReal, ptrImag, 8, 0); - - ptrReal++; - ptrImag++; - - } - - /* pre-twiddle */ - BASOP_getTables(NULL, &ptwiddle, &step, 128); - IF (lpcRep != 0) - { - pwn17i = &w19N[126]; - pwn17 = w19N; - } - ELSE - { - pwn17i = &w18N[126]; - pwn17 = w18N; - } - - pwn15 = &tmpw15; - pwn15i = &tmpw15; - - RealOut[0] = round_fx(2*L_add(RealFFT[0], ImagFFT[0])); - ImagOut[0] = 0; - move16(); - - RealOut[128] = 0; - move16(); - ImagOut[128] = round_fx(L_sub(L_add(RealFFT[0],RealFFT[0]), L_add(ImagFFT[0], ImagFFT[0]))); - - ptwiddle += 8; - FOR(i=1; i<=N/2/4; i++) - { - Word16 ReAr = extract_h(L_add(RealFFT[i],RealFFT[N/2-i])); - Word16 ReBr = extract_h(L_sub(RealFFT[N/2-i], RealFFT[i])); - Word16 ImAr = extract_h(L_sub(ImagFFT[i], ImagFFT[N/2-i])); - Word16 ImBr = extract_h(L_add(ImagFFT[i], ImagFFT[N/2-i])); - BASOP_SATURATE_WARNING_OFF - tmpw15.v.re = mac_r(L_mult(ptwiddle->v.re, pwn17->v.re), ptwiddle->v.im, pwn17->v.im); - tmpw15.v.im = msu_r(L_mult(ptwiddle->v.re, pwn17->v.im), ptwiddle->v.im, pwn17->v.re); - BASOP_SATURATE_WARNING_ON - RealOut[i] = mac_r(L_msu(L_msu(L_mult(ReAr, pwn17->v.re),ImAr, pwn17->v.im), ReBr, pwn15->v.im), ImBr, pwn15->v.re); - move16(); - ImagOut[i] = mac_r(L_mac(L_mac(L_mult(ReAr, pwn17->v.im), ImAr, pwn17->v.re), ReBr, pwn15->v.re), ImBr, pwn15->v.im); - move16(); - BASOP_SATURATE_WARNING_OFF - tmpw15.v.re = msu_r(L_mult(ptwiddle->v.im, pwn17i->v.im), ptwiddle->v.re, pwn17i->v.re); - tmpw15.v.im = mac_r(L_mult(ptwiddle->v.re, pwn17i->v.im), ptwiddle->v.im, pwn17i->v.re); - BASOP_SATURATE_WARNING_ON - RealOut[N/2-i] = msu_r(L_mac(L_mac(L_mult(ReAr, pwn17i->v.re), ImAr, pwn17i->v.im), ImBr, pwn15i->v.re), ReBr, pwn15i->v.im); - move16(); - ImagOut[N/2-i] = msu_r(L_msu(L_msu(L_mult(ReAr, pwn17i->v.im), ImAr, pwn17i->v.re), ReBr, pwn15i->v.re), ImBr, pwn15i->v.im); - move16(); - - ptwiddle += 8; - pwn17++; - pwn17i--; - } - - ptwiddle -= 16; - /*change real with imaginary for ptwiddle*/ - FOR(; iv.im, pwn17->v.re), ptwiddle->v.re, pwn17->v.im); - tmpw15.v.im = msu_r(L_mult(ptwiddle->v.im, pwn17->v.im), ptwiddle->v.re, pwn17->v.re); - BASOP_SATURATE_WARNING_ON - RealOut[i] = mac_r(L_msu(L_msu(L_mult(ReAr, pwn17->v.re),ImAr, pwn17->v.im), ReBr, pwn15->v.im), ImBr, pwn15->v.re); - move16(); - ImagOut[i] = mac_r(L_mac(L_mac(L_mult(ReAr, pwn17->v.im), ImAr, pwn17->v.re), ReBr, pwn15->v.re), ImBr, pwn15->v.im); - move16(); - BASOP_SATURATE_WARNING_OFF - tmpw15.v.re = msu_r(L_mult(ptwiddle->v.re, pwn17i->v.im), ptwiddle->v.im, pwn17i->v.re); - tmpw15.v.im = mac_r(L_mult(ptwiddle->v.im, pwn17i->v.im), ptwiddle->v.re, pwn17i->v.re); - BASOP_SATURATE_WARNING_ON - RealOut[N/2-i] = msu_r(L_mac(L_mac(L_mult(ReAr, pwn17i->v.re), ImAr, pwn17i->v.im), ImBr, pwn15i->v.re), ReBr, pwn15i->v.im); - move16(); - ImagOut[N/2-i] = msu_r(L_msu(L_msu(L_mult(ReAr, pwn17i->v.im), ImAr, pwn17i->v.re), ReBr, pwn15i->v.re), ImBr, pwn15i->v.im); - move16(); - - ptwiddle -= 8; - pwn17++; - pwn17i--; - } - ptwiddle += 0; - { - Word16 ReAr = extract_h(L_add(RealFFT[i],RealFFT[N/2-i])); - Word16 ReBr = extract_h(L_sub(RealFFT[N/2-i], RealFFT[i])); - Word16 ImAr = extract_h(L_sub(ImagFFT[i], ImagFFT[N/2-i])); - Word16 ImBr = extract_h((L_negate(L_add(ImagFFT[i], ImagFFT[N/2-i])))); - BASOP_SATURATE_WARNING_OFF - tmpw15.v.re = mac_r(L_mult(ptwiddle->v.im, pwn17->v.re), ptwiddle->v.re, pwn17->v.im); - tmpw15.v.im = msu_r(L_mult(ptwiddle->v.im, pwn17->v.im), ptwiddle->v.re, pwn17->v.re); - BASOP_SATURATE_WARNING_ON - RealOut[i] = msu_r(L_msu(L_msu(L_mult(ReAr, pwn17->v.re), ImAr, pwn17->v.im), ReBr, pwn15->v.im), ImBr, pwn15->v.re); - move16(); - ImagOut[i] = msu_r(L_mac(L_mac(L_mult(ReAr, pwn17->v.im), ImAr, pwn17->v.re), ReBr, pwn15->v.re), ImBr, pwn15->v.im); - move16(); - } - - spec2isf(RealOut, ImagOut, 128, lsf, old_lsf); - IF (lpcRep == 0) - { - lsf[lpcOrder - 1] = shl(lpcCoeffs[lpcOrder], add(norm_s(lpcCoeffs[0]),1)); - move16(); /* From Qx to Q15 with saturation */ - lsf[lpcOrder - 1] = xsp_to_xsf(lsf[lpcOrder - 1]); - move16(); - lsf[lpcOrder - 1] = shr(lsf[lpcOrder - 1], 1); - move16(); - } - -} - diff --git a/src/libs/libevs/lib_com/lsf_dec_bfi.cpp b/src/libs/libevs/lib_com/lsf_dec_bfi.cpp new file mode 100644 index 00000000..3313936e --- /dev/null +++ b/src/libs/libevs/lib_com/lsf_dec_bfi.cpp @@ -0,0 +1,267 @@ +/*==================================================================================== + EVS Codec 3GPP TS26.443 Nov 13, 2018. Version 12.11.0 / 13.7.0 / 14.3.0 / 15.1.0 + ====================================================================================*/ + +#include +#include +#include +#include +#include "cnst.h" +#include "prot.h" +#include "rom_com.h" + +/*---------------------------------------------------------------------* +* routine: lsf_dec_bfi() +* +* Estimate the lsfs in case of FER +* Bad frame, all active speech coders +*---------------------------------------------------------------------*/ + +void lsf_dec_bfi( + short codec_mode, /* i: : codec mode: MODE1 | MODE2 */ + float *lsf, /* o : estimated LSF vector */ + const float *lsfold, /* i : past quantized lsf */ + float *lsf_adaptive_mean, /* i : lsf adaptive mean, updated when BFI==0 */ + const float lsfBase[], /* i : base for differential lsf coding */ + float *mem_MA, /* i/o: quantizer memory for MA model */ + float *mem_AR, /* o : quantizer memory for AR model */ + float stab_fac, /* i : lsf stability factor */ + short last_coder_type, /* i : last coder type */ + short L_frame, /* i : frame length */ + const short last_good, /* i : last good received frame */ + const short nbLostCmpt, /* i : counter of consecutive bad frames */ + int plcBackgroundNoiseUpdated, /* i : background noise alreadyupdated? */ + float *lsf_q_cng, /* o : quantized lsfs of background noise */ + float *lsf_cng, /* i : long term target for fading to bg noise*/ + float *old_lsf_q_cng, /* i : old quantized lsfs for background noise*/ + short Last_GSC_pit_band_idx, /* i : AC mode (GSC) - Last pitch band index */ + short Opt_AMR_WB, /* i : IO flag */ + const short MODE1_bwidth /* i : coded bandwidth */ +) +{ + short i; + float alpha, tmp; + float lsf_mean[M]; + const float* pt_meansForFading; + const float* pt_meansForMemUpdate; + float beta; + + /* init vectors */ + if (codec_mode == MODE1) + { + pt_meansForMemUpdate = &lsf_mean[0]; + + if( Opt_AMR_WB ) + { + pt_meansForFading = mean_isf_amr_wb; + } + else + { + if( L_frame == L_FRAME ) + { + if( MODE1_bwidth == NB ) + { + pt_meansForFading = GENB_Ave; + } + else + { + pt_meansForFading = GEWB_Ave; + } + } + else + { + pt_meansForFading = GEWB2_Ave; + } + } + } + else + { + pt_meansForFading = pt_meansForMemUpdate = lsfBase; + if (lsf_cng != NULL && plcBackgroundNoiseUpdated) + { + pt_meansForFading = lsf_cng; + } + } + + /*----------------------------------------------------------------------* + * Initialize the alpha factor + *----------------------------------------------------------------------*/ + + if( nbLostCmpt <= 3 ) + { + if(last_coder_type == UNVOICED) + { + /* clearly unvoiced */ + alpha = ALPHA_UU; + } + else if( last_coder_type == AUDIO || last_good == INACTIVE_CLAS ) + { + if( Last_GSC_pit_band_idx > 0 && nbLostCmpt > 1 ) + { + alpha = 0.8f; + } + else + { + alpha = 0.995f; + } + } + else if(last_good == UNVOICED_CLAS ) + { + if( nbLostCmpt <= 1 ) + { + /* if stable, do not flatten the spectrum in the 1st erased frame */ + alpha = stab_fac * (1.0f - 2.0f*ALPHA_U) + 2.0f*ALPHA_U; /* [0.8, 1.0] */ + } + else if( nbLostCmpt == 2 ) + { + alpha = ALPHA_U*1.5f; /* 0.6 */ + } + else + { + /* go rapidly to CNG spectrum */ + alpha = ALPHA_U; + } + } + else if(last_good == UNVOICED_TRANSITION ) + { + alpha = ALPHA_UT; + } + else if(last_good == VOICED_CLAS || last_good == ONSET ) + { + /* clearly voiced - mild convergence to the CNG spectrum for the first 3 erased frames */ + alpha = ALPHA_V; + } + else if(last_good == SIN_ONSET) + { + alpha = ALPHA_S; + } + else + { + alpha = ALPHA_VT; + } + } + else + { + alpha = 1.f/nbLostCmpt; + } + + if( codec_mode == MODE1 ) + { + beta = BETA_FEC; + } + else + { + if( plcBackgroundNoiseUpdated ) + { + beta = 0.f; + } + else + { + beta = 0.25f; + } + } + + for( i=0; i L_FRAME */ + { + reorder_lsf( lsf, MODE1_LSF_GAP, M, L_frame * 50 ); + if(lsf_q_cng!=NULL) + { + reorder_lsf(lsf_q_cng, MODE1_LSF_GAP, M, L_frame * 50); + } + } + } + /* update the AR memory to be used in the next frame */ + mvr2r( lsf, mem_AR, M ); + + for(i=0; i -#include -#include -#include "stl.h" -#include "basop_util.h" -#include "rom_com_fx.h" -#include "cnst_fx.h" -#include "prot_fx.h" - - -/*---------------------------------------------------------------------* -* routine: lsf_dec_bfi() -* -* Estimate the LSFs in case of FER -* Bad frame, all active speech coders -*---------------------------------------------------------------------*/ -void lsf_dec_bfi( - const Word16 codec_mode, /* i: : codec mode: MODE1 | MODE2 */ - Word16*lsf, /*!< o : 14Q1*1.28 quantized ISFs */ - const Word16*lsfold, /*!< i : 14Q1*1.28 past quantized ISF */ - Word16*lsf_adaptive_mean, /*!< i : 14Q1*1.28 ISF adaptive mean, updated when BFI==0 */ - const Word16 lsfBase[], /* i : base for differential lsf coding */ - Word16*mem_MA, /*!< i/o: 14Q1*1.28 quantizer memory for MA model */ - Word16*mem_AR, /*!< i/o: 14Q1*1.28 quantizer memory for MA model */ - Word16 stab_fac, /*!< i : ISF stability factor (shifted right by 1) */ - const Word16 last_coder_type, /*!< i : coding type in last good received fr. */ - Word16 L_frame, - const Word16 last_good, /*!< i : last good received frame */ - const Word16 nbLostCmpt, /*!< i : counter of consecutive bad frames */ - Word8 plcBackgroundNoiseUpdated, - Word16 *lsf_q_cng, /* o : quantized ISFs for background noise (14Q1*1.28) */ - Word16 *lsf_cng, - Word16 *old_lsf_q_cng, /* o : old quantized ISFs for background noise */ - const Word16 Last_GSC_pit_band_idx, - const Word16 Opt_AMR_WB /* i : IO flag */ - , const Word8 tcxonly - ,const short MODE1_bwidth /* i: coded bandwidth */ -) -{ - Word16 i; - Word16 alpha; - Word32 tmp; - Word16 lsf_mean[M]; - const Word16* pt_meansForFading; - const Word16* pt_meansForMemUpdate; - Word16 beta; - Word16 gap; - - IF (sub(codec_mode,MODE1) == 0) - { - pt_meansForMemUpdate = lsf_mean; - /* Update inital guess to something stable, with proper sampling frequency and format (ISF/LSF)*/ - IF ( Opt_AMR_WB) - { - pt_meansForFading = Mean_isf_wb; - } - ELSE - { - /* 12.8kHz ACELP sampling */ - IF( sub(L_frame,L_FRAME) == 0 ) - { - pt_meansForFading = GEWB_Ave_fx; - - if (sub(MODE1_bwidth,NB)==0) - { - pt_meansForFading = GENB_Ave_fx; - } - } - /* 16kHz ACELP sampling */ - ELSE - { - pt_meansForFading = GEWB2_Ave_fx; - } - } - } - ELSE - { - pt_meansForFading = pt_meansForMemUpdate = lsfBase; - test(); - if (lsf_cng != NULL && plcBackgroundNoiseUpdated) - { - pt_meansForFading = lsf_cng; - } - } - IF( sub(nbLostCmpt, 3) <= 0 ) - { - test(); - test(); - IF( (sub(last_coder_type, UNVOICED) == 0) ) /* Clear unvoiced last good frame */ - { - move16(); - alpha = _ALPHA_UU_FX; - } - ELSE IF( sub(last_coder_type,AUDIO) == 0 || sub(last_good,INACTIVE_CLAS) == 0 ) - { - alpha = 32604/*0.995f Q15*/; - move16(); - test(); - if( Last_GSC_pit_band_idx > 0 && sub(nbLostCmpt, 1) > 0 ) - { - alpha = 26214/*0.8f Q15*/; - move16(); - } - } - ELSE IF( sub(last_good,UNVOICED_CLAS) == 0 ) - { - IF( sub(nbLostCmpt,1) <= 0 ) - { - /* If stable, do not flatten the spectrum in the 1st erased frame */ - alpha = add(mult(stab_fac, 32768 - _ALPHA_U_FX_X_2), _ALPHA_U_FX_X_2); - } - ELSE IF(sub(nbLostCmpt,2) == 0) - { - alpha = sub(_ALPHA_U_FX_X_2,shr(_ALPHA_U_FX,1)); /* 0.6 */ - } - ELSE - { - alpha = _ALPHA_U_FX; - move16(); /* go rapidly to CNG spectrum */ - } - } - ELSE IF( sub(last_good ,UNVOICED_TRANSITION) == 0 ) - { - alpha = _ALPHA_UT_FX; - move16(); - } - ELSE IF( (sub(last_good,VOICED_CLAS) == 0) || (sub(last_good,ONSET) == 0) ) - { - /* clearly voiced - mild convergence to the CNG spectrum for the first 3 erased frames */ - move16(); - alpha = _ALPHA_V_FX; - } - ELSE IF( sub(last_good ,SIN_ONSET) == 0 ) - { - alpha = _ALPHA_S_FX; - move16(); - } - ELSE - { - alpha = _ALPHA_VT_FX; /* rapid convergence to the CNG spectrum (long erasure, ONSETS) */ - } - } - ELSE - { - Word16 exp = 15; - alpha = Inv16(nbLostCmpt, &exp); /*1.f/bfi_cnt;*/ - alpha = shl(alpha,exp); - } - IF(sub(codec_mode,MODE1) == 0) - { - beta = BETA_FEC_FX; - move16(); - } - ELSE - { - beta = 8192/*0.25f Q15*/; - move16(); - if (plcBackgroundNoiseUpdated) - { - beta = 0/*0.f Q15*/; - move16(); - } - } - FOR (i=0; i #include #include -#include "cnst_fx.h" -#include "rom_com_fx.h" -#include "prot_fx.h" -#include "stl.h" -#include "basop_util.h" -#include "prot_fx.h" #include "options.h" +#include "cnst.h" +#include "prot.h" +#include "rom_com.h" +#include "stl.h" +#include "basop_proto_func.h" -#define swap(x,y,type) {type u__p; u__p=x; x=y; y=u__p;} - -extern const Word16 tbl_mid_gen_wb_5b_fx[]; -extern const Word16 tbl_mid_unv_wb_5b_fx[]; - - - +/*---------------------------------------------------------------------* + * midlsf_dec() + * + * + *---------------------------------------------------------------------*/ void midlsf_dec( - const Word16 qlsf0[], /* i: quantized lsf coefficients (3Q12) */ - const Word16 qlsf1[], /* i: quantized lsf coefficients (3Q12) */ - Word16 idx, /* i: codebook index */ - Word16 qlsf[], /* o: decoded lsf coefficients (3Q12) */ - Word16 coder_type, - Word16 *mid_lsf_int, - Word16 prev_bfi, - Word16 safety_net) + float qlsf0[], + float qlsf1[], + short idx, + float qlsf[], + int N, + int coder_type, + short *mid_lsf_int, + short prev_bfi, + short safety_net +) { - const Word16 *ratio=NULL; - Word16 j; - Word32 L_tmp; - Word16 bad_spacing = 0; - - move16(); + const float *ratio=NULL; + int j; + short bad_spacing = 0; /* Select codebook */ - IF ( sub(coder_type, UNVOICED) == 0 ) + if ( coder_type == UNVOICED ) { - ratio = tbl_mid_unv_wb_5b_fx; + ratio = tbl_mid_unv_wb_5b; } - ELSE + else { - ratio = tbl_mid_gen_wb_5b_fx; - } - FOR (j=0; jQ(x2.56+14)*/ - L_tmp = L_mac(L_tmp, ratio[idx*M+j], qlsf1[j]); /*Q(x2.56+14)*/ - qlsf[j] = round_fx(L_shl(L_tmp,2)); /*Q(x2.56)*/ + ratio = tbl_mid_gen_wb_5b; } + for (j=0; j 0 && sub(j, M) <0 && sub(qlsf[j], add( qlsf[j-1], LSF_GAP_MID_FX))<0 ) + if ( j > 0 && j < N && qlsf[j] < qlsf[j-1] + LSF_GAP_MID ) { - qlsf[j] = add(qlsf[j-1], LSF_GAP_MID_FX); - move16(); + qlsf[j] = qlsf[j-1] + LSF_GAP_MID; } } } - ELSE + else { /* otherwise, use regular LSF spacing and ordering as in the encoder */ - FOR (j=0; j 0 && sub(j, M) < 0 && sub(qlsf[j], add( qlsf[j-1],LSF_GAP_MID_FX))<0 ) + if ( j > 0 && j < N && qlsf[j] < qlsf[j-1] + LSF_GAP_MID ) { - qlsf[j] = add(qlsf[j-1], LSF_GAP_MID_FX); - move16(); + qlsf[j] = qlsf[j-1] + LSF_GAP_MID; } + } } if ( prev_bfi ) { /* continue redoing mid-LSF interpolation with 0.4 in order not to propagate the error */ *mid_lsf_int = 1; - move16(); } if ( safety_net ) { /* safety-net encountered -> stop redoing mid-LSF interpolation with 0.4 */ *mid_lsf_int = 0; - move16(); } } - ELSE + else { /* use regular LSF spacing */ - FOR (j=0; j 0 && sub(j, M) <0 && sub(qlsf[j], add(qlsf[j-1], LSF_GAP_MID_FX))<0 ) + if ( j > 0 && j < N && qlsf[j] < qlsf[j-1] + LSF_GAP_MID ) { - qlsf[j] = add(qlsf[j-1], LSF_GAP_MID_FX); - move16(); + qlsf[j] = qlsf[j-1] + LSF_GAP_MID; } } } return; } -Word16 lsf_ind_is_active( + + +/*---------------------------------------------------------------------* + * lsf_ind_is_active() + * + * + *---------------------------------------------------------------------*/ + +int lsf_ind_is_active( const Word16 lsf_q_ind[], - const Word16 means[], - Word16 narrowband, - Word16 cdk + const float means[], + int narrowband, + int cdk ) { Word16 lsf[2], min_distance; - lsf[0] = add(lsf_q_ind[0], means[0]); + lsf[0] = add(lsf_q_ind[0], LSFM(means[0])); move16(); - lsf[1] = add(lsf_q_ind[1], means[1]); + lsf[1] = add(lsf_q_ind[1], LSFM(means[1])); move16(); min_distance = lsf[0]; - move16(); min_distance = s_min(min_distance, sub(lsf[1], lsf[0])); assert(narrowband == 0 || narrowband == 1); @@ -156,4 +145,3 @@ Word16 lsf_ind_is_active( return sub(min_distance, min_distance_thr[narrowband][cdk]) < 0; } - diff --git a/src/libs/libevs/lib_com/lsf_tools.cpp b/src/libs/libevs/lib_com/lsf_tools.cpp new file mode 100644 index 00000000..8b887c2d --- /dev/null +++ b/src/libs/libevs/lib_com/lsf_tools.cpp @@ -0,0 +1,2314 @@ +/*==================================================================================== + EVS Codec 3GPP TS26.443 Nov 13, 2018. Version 12.11.0 / 13.7.0 / 14.3.0 / 15.1.0 + ====================================================================================*/ + +#include +#include "options.h" +#include "cnst.h" +#include "prot.h" +#include "rom_com.h" +#include "basop_proto_func.h" + +/*-------------------------------------------------------------------* + * Local functions + *-------------------------------------------------------------------*/ + +static float chebps2(const float x, const float *f, const short n); +static float LPC_chebyshev (float x, float f[], int n); +static void get_isppol( const float *isp, float f[], const short n ); + +/*---------------------------------------------------------------------* + * a2isp() + * + * Compute the ISPs from the LPC coefficients a[] using Chebyshev + * polynomials. The found ISPs are in the cosine domain with values + * in the range from 1 down to -1. + * The table grid[] contains the points (in the cosine domain) at + * which the polynomials are evaluated. + * + * The ISPs are the roots of the two polynomials F1(z) and F2(z) + * defined as + * F1(z) = [A(z) + z^-M A(z^-1)] + * and F2(z) = [A(z) - z^-M A(z^-1)]/ (1-z^-2) + * + * For an even order M=2N, F1(z) has M/2 conjugate roots on the unit circle + * and F2(z) has M/2-1 conjugate roots on the unit circle in addition to two + * roots at 0 and pi. + * + * For a 16th order LP analysis (M=16), F1(z) and F2(z) can be written as + * + * F1(z) = (1 + a[16]) * PRODUCT (1 - 2 cos(w_i) z^-1 + z^-2 ) + * i=0,2,...,14 + * + * F2(z) = (1 - a[16]) * PRODUCT (1 - 2 cos(w_i) z^-1 + z^-2 ) + * i=1,3,...,13 + * + * The ISPs are frequencies w_i, i=0...M-2 plus the last predictor + * coefficient a[M]. + *---------------------------------------------------------------------*/ + +void a2isp( + const float *a, /* i: LP filter coefficients */ + float *isp, /* o: Immittance spectral pairs */ + const float *old_isp /* i: ISP vector from past frame */ +) +{ + short j, i, nf, ip, order; + float xlow,ylow,xhigh,yhigh,xmid,ymid,xint; + float f1[NC+1], f2[NC]; + float *coef; + + /*-------------------------------------------------------------* + * find the sum and diff polynomials F1(z) and F2(z) + * F1(z) = [A(z) + z^M A(z^-1)] + * F2(z) = [A(z) - z^M A(z^-1)]/(1-z^-2) + * + * for (i=0; i 1.0f) || (a[M] < -1.0f) ) + { + for( i=0; i 1; i--) + { + f2[i] -= f2[i-2]; + } + + /*-----------------------------------------------------------------* + * Scale F1(z) by (1+isp[m-1]) and F2(z) by (1-isp[m-1]) * + *-----------------------------------------------------------------*/ + + for (i = 0; i < nc; i++) + { + f1[i] *= (1.0f + isp[m-1]); + f2[i] *= (1.0f - isp[m-1]); + } + + /*-----------------------------------------------------------------* + * A(z) = (F1(z)+F2(z))/2 * + * F1(z) is symmetric and F2(z) is asymmetric * + *-----------------------------------------------------------------*/ + + a[0] = 1.0f; + for (i=1, j=m-1; i= 4) + { + temp2 = LPC_chebyshev (temp, q + offset, order_by_2); + } + else + { + temp2 = temp + q[0 + offset]; + } + + if ((temp2 * prev[iswitch]) <= 0.0 || frequency >= 0.5) + { + if (STEPindex == STEPSNUM - 1) + { + if (fabs (temp2) < fabs (prev[iswitch])) + { + freq[lspnumber] = frequency; + } + else + { + freq[lspnumber] = frequency - STEP; + } + if ((prev[iswitch]) < 0.0) + { + prev[iswitch] = 9e9f; + } + else + { + prev[iswitch] = -9e9f; + } + root = 0; + frequency = LastFreq; + STEPindex = 0; + } + else + { + if (STEPindex == 0) + { + LastFreq = frequency; + } + frequency -= STEPS[++STEPindex]; /* Go back one grid step */ + STEP = STEPS[STEPindex]; + } + } + else + { + prev[iswitch] = temp2; + frequency += STEP; + } + } /* while(root) */ + + lspnumber++; + if (lspnumber > order - 1) + { + notlast = 0; + } + iswitch = 1 - iswitch; + } /* while (notlast) */ + + /* stability check */ + space_min = 1; + for( i=1; i < order; i++ ) + { + space_min = ((freq[i] - freq[i-1]) < space_min)?(freq[i] - freq[i-1]):space_min; + } + + if( space_min <= 0 ) + { + return 0; + } + + return 1; +} + +/*-------------------------------------------------------------------* + * lsp2a() + * + * Convert LSPs to predictor coefficients a[] + *-------------------------------------------------------------------*/ + +void lsp2a ( + float *pc_in, /* i/o: predictor coefficients */ + float *freq, /* i/o: LSP coefficients */ + const short order /* i : order of LP analysis */ +) +{ + float p[LPC_SHB_ORDER], q[LPC_SHB_ORDER]; + float a[LPC_SHB_ORDER], a1[LPC_SHB_ORDER], a2[LPC_SHB_ORDER]; + float b[LPC_SHB_ORDER], b1[LPC_SHB_ORDER], b2[LPC_SHB_ORDER]; + + float xx; + int i, k; + int lspflag; + float *pc; + int order_by_2; + + lspflag = 1; + pc = &(pc_in[1]); + + order_by_2 = order / 2; + + /* check input for ill-conditioned cases */ + if ((freq[0] <= 0.0) || (freq[order - 1] >= 0.5)) + { + lspflag = 0; + + if (freq[0] <= 0) + { + freq[0] = 0.022f; + } + + if (freq[order - 1] >= 0.5) + { + freq[order - 1] = 0.499f; + } + } + + if (!lspflag) + { + xx = (freq[order - 1] - freq[0]) * recip_order[order]; + for (i = 1; i < order; i++) + { + freq[i] = freq[i - 1] + xx; + } + } + + for (i = 0; i <= order_by_2; i++) + { + a[i] = 0.; + a1[i] = 0.; + a2[i] = 0.; + b[i] = 0.; + b1[i] = 0.; + b2[i] = 0.; + } + + for (i = 0; i < order_by_2; i++) + { + p[i] = (float)cos (6.2832 * freq[2 * i]); + q[i] = (float)cos (6.2832 * freq[2 * i + 1]); + } + + a[0] = 0.25f; + b[0] = 0.25f; + + for (i = 0; i < order_by_2; i++) + { + a[i + 1] = a[i] - 2 * p[i] * a1[i] + a2[i]; + b[i + 1] = b[i] - 2 * q[i] * b1[i] + b2[i]; + a2[i] = a1[i]; + a1[i] = a[i]; + b2[i] = b1[i]; + b1[i] = b[i]; + } + a[0] = 0.25f; + b[0] = -0.25f; + + for (i = 0; i < order_by_2; i++) + { + a[i + 1] = a[i] - 2 * p[i] * a1[i] + a2[i]; + b[i + 1] = b[i] - 2 * q[i] * b1[i] + b2[i]; + a2[i] = a1[i]; + a1[i] = a[i]; + b2[i] = b1[i]; + b1[i] = b[i]; + } + + pc[0] = 2 * (a[order_by_2] + b[order_by_2]); + + for (k = 2; k <= order; k++) + { + a[0] = 0.0f; + b[0] = 0.0f; + + for (i = 0; i < order_by_2; i++) + { + a[i + 1] = a[i] - 2 * p[i] * a1[i] + a2[i]; + b[i + 1] = b[i] - 2 * q[i] * b1[i] + b2[i]; + a2[i] = a1[i]; + a1[i] = a[i]; + b2[i] = b1[i]; + b1[i] = b[i]; + } + pc[k - 1] = 2 * (a[order_by_2] + b[order_by_2]); + } + + return; +} + +/*-----------------------------------------------------------* + * get_lsppol() + * + * Find the polynomial F1(z) or F2(z) from the LSPs. + * This is performed by expanding the product polynomials: + * + * F1(z) = product ( 1 - 2 LSF_i z^-1 + z^-2 ) + * i=0,2,4,..,n-2 + * F2(z) = product ( 1 - 2 LSF_i z^-1 + z^-2 ) + * i=1,3,5,..,n-1 + * + * where LSP_i are the LSPs in the cosine domain. + *-----------------------------------------------------------*/ + +static void get_lsppol( + const float lsp[], /* i : line spectral freq. (cosine domain) */ + float f[], /* o : the coefficients of F1 or F2 */ + const short n, /* i : no of coefficients (m/2) */ + short flag /* i : 1 ---> F1(z) ; 2 ---> F2(z) */ +) +{ + float b; + const float *plsp; + int i,j; + + plsp = lsp + flag - 1; + + f[0] = 1.0f; + b = -2.0f * *plsp; + f[1] = b; + + for (i = 2; i <= n; i++) + { + plsp += 2; + b = -2.0f * *plsp; + f[i] = b*f[i-1] + 2.0f*f[i-2]; + + for (j = i-1; j > 1; j--) + { + f[j] += b*f[j-1] + f[j-2]; + } + + f[1] += b; + } + + return; +} + +/*---------------------------------------------------------------------* + * a2lsp_stab() + * + * Compute the LSPs from the LPC coefficients a[] using Chebyshev + * polynomials. The found LSPs are in the cosine domain with values + * in the range from 1 down to -1. + * The table grid[] contains the points (in the cosine domain) at + * which the polynomials are evaluated. + * + * The ISPs are the roots of the two polynomials F1(z) and F2(z) + * defined as + * F1(z) = [A(z) + z^-M A(z^-1)]/ (1+z^-1) + * and F2(z) = [A(z) - z^-M A(z^-1)]/ (1-z^-1) + *---------------------------------------------------------------------*/ + +void a2lsp_stab( + const float *a, /* i: LP filter coefficients */ + float *lsp, /* o: LSP vector */ + const float *old_lsp /* i: LSP vector from past frame */ +) +{ + short j, i, nf, ip; + float xlow, ylow, xhigh, yhigh, xmid, ymid, xint; + float *pf1, *pf2; + const float *pa1, *pa2; + float f1[NC+1], f2[NC+1]; + + /*-------------------------------------------------------------* + * find the sum and diff polynomials F1(z) and F2(z) * + * F1(z) = [A(z) + z^11 A(z^-1)]/(1+z^-1) * + * F2(z) = [A(z) - z^11 A(z^-1)]/(1-z^-1) * + *-------------------------------------------------------------*/ + + pf1 = f1; /* Equivalent code using indices */ + pf2 = f2; + *pf1++ = 1.0f; /* f1[0] = 1.0; */ + *pf2++ = 1.0f; /* f2[0] = 1.0; */ + pa1 = a + 1; + pa2 = a + M; + + for( i=0; i<=NC-1; i++ ) /* for (i=1, j=M; i<=NC; i++, j--) */ + { + *pf1 = *pa1 + *pa2 - *(pf1-1); /* f1[i] = a[i]+a[j]-f1[i-1]; */ + *pf2 = *pa1++ - *pa2-- + *(pf2-1);/* f2[i] = a[i]-a[j]+f2[i-1]; */ + pf1++; + pf2++; + } + + /*---------------------------------------------------------------------* + * Find the LSPs (roots of F1(z) and F2(z) ) using the * + * Chebyshev polynomial evaluation. * + * The roots of F1(z) and F2(z) are alternatively searched. * + * We start by finding the first root of F1(z) then we switch * + * to F2(z) then back to F1(z) and so on until all roots are found. * + * * + * - Evaluate Chebyshev pol. at grid points and check for sign change.* + * - If sign change track the root by subdividing the interval * + * 4 times and ckecking sign change. * + *---------------------------------------------------------------------*/ + + nf=0; /* number of found frequencies */ + ip=0; /* flag to first polynomial */ + + pf1 = f1; /* start with F1(z) */ + + xlow = grid100[0]; + ylow = chebps2( xlow, pf1, NC ); + + j = 0; + while( (nf < M) && (j < GRID100_POINTS) ) + { + j++; + xhigh = xlow; + yhigh = ylow; + xlow = grid100[j]; + ylow = chebps2( xlow, pf1, NC ); + + if( ylow*yhigh <= 0.0 ) /* if sign change new root exists */ + { + j--; + /* divide the interval of sign change by NO_ITER */ + for (i = 0; i < NO_ITER; i++) + { + xmid = 0.5f * ( xlow + xhigh ); + ymid = chebps2( xmid, pf1, NC ); + if( ylow*ymid <= 0.0 ) + { + yhigh = ymid; + xhigh = xmid; + } + else + { + ylow = ymid; + xlow = xmid; + } + } + + /* linear interpolation for evaluating the root */ + xint = xlow - ylow*(xhigh-xlow)/(yhigh-ylow); + lsp[nf] = xint; /* new root */ + nf++; + ip = 1 - ip; /* flag to other polynomial */ + pf1 = ip ? f2 : f1; /* pointer to other polynomial */ + xlow = xint; + ylow = chebps2( xlow, pf1, NC ); + } + } + + /* Check if M roots found */ + /* if not use the LSPs from previous frame */ + if( nf < M ) + { + + for( i=0; i 0; i--) */ + { + *pf1-- += *pf1_1--; /* f1[i] += f1[i-1]; */ + *pf2-- -= *pf2_1--; /* f2[i] -= f2[i-1]; */ + } + + /*-----------------------------------------------------* + * A(z) = (F1(z)+F2(z))/2 * + * F1(z) is symmetric and F2(z) is antisymmetric * + *-----------------------------------------------------*/ + + pa1 = a; + *pa1++ = 1.0; /* a[0] = 1.0; */ + pa2 = a + m; + pf1 = f1 + 1; + pf2 = f2 + 1; + for (i = 0; i <= k; i++) /* for (i=1, j=M; i<=NC; i++, j--) */ + { + *pa1++ = 0.5f*(*pf1 + *pf2); /* a[i] = 0.5*(f1[i] + f2[i]); */ + *pa2-- = 0.5f*(*pf1++ - *pf2++);/* a[j] = 0.5*(f1[i] - f2[i]); */ + } + + return; +} + +/*--------------------------------------------------------------------------- + * reorder_lsf() + * + * To make sure that the LSFs are properly ordered and to keep a certain + * minimum distance between consecutive LSFs. + *--------------------------------------------------------------------------*/ + +void reorder_lsf( + float *lsf, /* i/o: LSF vector */ + const float min_dist, /* i : minimum required distance */ + const short n, /* i : LPC order */ + const float fs /* i : sampling frequency */ +) +{ + short i; + float lsf_min; + float lsf_max; + + /*-----------------------------------------------------------------* + * Verify the LSF ordering and minimum GAP + *-----------------------------------------------------------------*/ + + lsf_min = min_dist; + for (i = 0; i < n; i++) + { + if (lsf[i] < lsf_min) + { + lsf[i] = lsf_min; + } + lsf_min = lsf[i] + min_dist; + } + + /*------------------------------------------------------------------------------------------* + * Reverify the LSF ordering and minimum GAP in the reverse order (security) + *------------------------------------------------------------------------------------------*/ + + lsf_max = fs/2.0f - min_dist; + + if( lsf[n-1] > lsf_max ) /* If danger of unstable filter in case of resonance in HF */ + { + for (i = n-1; i >=0; i--) /* Reverify the minimum LSF gap in the reverse sens */ + { + if (lsf[i] > lsf_max) + { + lsf[i] = lsf_max; + } + + lsf_max = lsf[i] - min_dist; + } + } + + return; +} + +/*-------------------------------------------------------------------* + * space_lsfs() + * + *-------------------------------------------------------------------*/ + +void space_lsfs ( + float *lsfs, /* i/o: Line spectral frequencies */ + const short order /* i : order of LP analysis */ +) +{ + float delta; + short i, flag = 1; + + while (flag == 1) + { + flag = 0; + for (i = 0; i <= order; i++) + { + delta = (float)( i == 0 ? lsfs[0] : (i == order ? 0.5f - lsfs[i - 1] : (lsfs[i] - lsfs[i -1]))); + if (delta < SPC) + { + flag = 1; + delta -= SPC_plus; + if (i == order) + { + lsfs[i - 1] += delta; + } + else + { + if (i == 0) + { + lsfs[i] -= delta; + } + else + { + delta *= 0.5f; + lsfs[i - 1] += delta; + lsfs[i] -= delta; + } + } + } + } + } + + return; +} + +/*-------------------------------------------------------------------* + * lsp_weights() + * + *-------------------------------------------------------------------*/ + +void lsp_weights ( + const float *lsps, /* i : Line spectral pairs */ + float *weight, /* o : weights */ + const short order /* i : order of LP analysis */ +) +{ + short i; + float delta1, delta2; + + for (i = 0; i < order; i++) + { + delta1 = (float)((i == 0) ? lsps[i] : lsps[i] - lsps[i - 1]); + delta2 = (float)((i == order - 1) ? 0.5f - lsps[i] : lsps[i + 1] - lsps[i]); + + weight[i] = 250 * root_a_over_b(ALPHA_SQ, delta1 * delta2); + } + + if (order != LPC_SHB_ORDER_WB) + { + weight[3] *= 1.1f; + weight[4] *= 1.1f; + } + + return; +} + + +/*-----------------------------------------------------------------------* + * isf2isp() + * + * Transformation of ISF to ISP + * + * ISP are immitance spectral pairs in cosine domain (-1 to 1). + * ISF are immitance spectral pairs in frequency domain (0 to fs/2). + *-----------------------------------------------------------------------*/ + +void isf2isp( + const float isf[], /* i : isf[m] normalized (range: 0<=val<=fs/2) */ + float isp[], /* o : isp[m] (range: -1<=val<1) */ + const short m, /* i : LPC order */ + const float fs /* i : sampling frequency */ +) +{ + short i; + + for(i=0; i= 0; m--) + { + km = f[m]; + if (km <= -1.0 || km >= 1.0) + { + for ( j = 0; j < lpcorder; j++ ) + { + refl[j] = 0.f; + } + + return; + } + + refl[m] = -km; + denom = 1.0f / (1.0f - km * km); + + for (j = 0; j < m / 2; j++) + { + n = m - 1 - j; + x = denom * f[j] + km * denom * f[n]; + f[n] = denom * f[n] + km * denom * f[j]; + f[j] = x; + } + + if (m & 1) + { + f[j] = denom * f[j] + km * denom * f[j]; + } + } + + return; +} + + +/*----------------------------------------------------------------------------------* + * vq_dec_lvq() + * + * Multi-stage VQ decoder for LSF parameters, last stage LVQ + *----------------------------------------------------------------------------------*/ + +short vq_dec_lvq ( + short sf_flag, /* i : safety net flag */ + float x[], /* o : Decoded vector */ + short indices[], /* i : Indices */ + short stages, /* i : Number of stages */ + short N, /* i : Vector dimension */ + short mode, /* (i): mode_lvq, or mode_lvq_p */ + short no_bits, /* (i): no. bits for lattice */ + unsigned int *p_offset_scale1, + unsigned int *p_offset_scale2, + unsigned int *p_offset_scale1_p, + unsigned int *p_offset_scale2_p, + short *p_no_scales, + short *p_no_scales_p +) +{ + float x_lvq[16]; + short i; + short ber_flag; + /* clear vector */ + set_f(x, 0, N); + + /*-----------------------------------------------* + * add contribution of each stage + *-----------------------------------------------*/ + + if (sf_flag == 1) + { + for(i=0; i -1) + { + if (nbits0>0) /* */ + { + n_stages = 2; + levels0[0] = CBsizes[nbits0]; + bits0[0] = nbits0; + bits0[1] = cumleft-nbits0; + + if ( bits0[1] == 0 ) + { + n_stages--; + } + else + { + levels0[1] = CBsizes[cumleft-nbits0]; + } + } + else /* no bits for VQ stage */ + { + n_stages = 0; + } + + *stages0 = n_stages; + if(bits_lvq > 0) + { + bits0[n_stages] = bits_lvq; + levels0[n_stages] = bits_lvq; /* this is number of bits, not levels */ + *stages0 = n_stages+1; + } + } + else + { + *stages0 = 0; + } + + /*---------------------------------------------------* + * Calculate bit allocation for predictive quantizer + *---------------------------------------------------*/ + + if ( framemode_p > -1 ) + { + cumleft = BitsVQ_p[framemode_p]; + bits_lvq = nBits - cumleft; + nbits0 = CBbits_p[framemode_p]; + + if (nbits0 > -1) + { + if ( nbits0 > 0 ) + { + if ( framemode_p == 7 ) + { + /* for UNVOICED_WB only */ + n_stages = 3; + for( i=0; i0) + { + levels1[1] = CBsizes[nbits0]; + bits1[1] = nbits0; + n_stages = 2; + } + + levels1[n_stages] = bits_lvq; /* this is number of bits, not levels */ + bits1[n_stages] = bits_lvq; + *stages1 = n_stages+1; + } + } + else + { + *stages1 = 1; + bits1[0] = bits_lvq; + levels1[0] = bits_lvq; + } + } + else + { + fprintf(stderr, "lsf_allocate(): invalid number of bits in used predictive mode\n"); + exit(-1); + } + } + + return; +} + +/*----------------------------------------------------------------------------------* + * find_pred_mode() + * + * + *----------------------------------------------------------------------------------*/ + +short find_pred_mode( + const short coder_type, + const short bwidth, + const float int_fs, + short * p_mode_lvq, + short * p_mode_lvq_p, + short core_brate +) +{ + short idx, predmode; + + idx = bwidth; + if (idx>1) + { + idx = 1; + } + if ((int_fs == INT_FS_16k)) + { + idx = 2; + } + else + { + if ((core_brate>=GENERIC_MA_LIMIT)&&(coder_type==GENERIC) + &&(idx==1) + ) + { + idx = 3; + } + } + + predmode = predmode_tab[idx][coder_type]; + + if (idx<=2) + { + *p_mode_lvq = NO_CODING_MODES*idx + coder_type; + if (predmode>0) + { + *p_mode_lvq_p = *p_mode_lvq; + } + else + { + *p_mode_lvq_p = -1; + } + } + else /* WB 12.8 with MA pred in GENERIC*/ + { + *p_mode_lvq = NO_CODING_MODES + coder_type; + if (coder_type == GENERIC) + { + *p_mode_lvq_p = 18; + } + else + { + if (predmode>0) + { + *p_mode_lvq_p = *p_mode_lvq; + } + else + { + *p_mode_lvq_p = -1; + } + } + } + + + if (predmode==-1) + { + fprintf (stderr, "find_pred_mode(): incorrect coder_type specification: %d\n", coder_type); + exit(-1); + } + + return predmode; +} + + +/*--------------------------------------------------------------------------- + * reorder_isf() + * + * To make sure that the ISFs are properly ordered and to keep a certain + * minimum distance between consecutive ISFs. + *--------------------------------------------------------------------------*/ + +void reorder_isf( + float *isf, /* i/o: ISF vector */ + const float min_dist, /* i : minimum required distance */ + const short n, /* i : LPC order */ + const float fs /* i : sampling frequency */ +) +{ + short i; + float isf_min; + float isf_max; + + /*-----------------------------------------------------------------* + * Verify the ISF ordering and minimum GAP + *-----------------------------------------------------------------*/ + + isf_min = min_dist; + for (i = 0; i < n-1; i++) + { + if (isf[i] < isf_min) + { + isf[i] = isf_min; + } + + isf_min = isf[i] + min_dist; + } + + /*------------------------------------------------------------------------------------------* + * Reverify the ISF ordering and minimum GAP in the reverse order (security) + *------------------------------------------------------------------------------------------*/ + + isf_max = fs/2.0f - min_dist; + + if( isf[n-2] > isf_max ) /* If danger of unstable filter in case of resonance in HF */ + { + for (i = n-2; i >=0; i--) /* Reverify the minimum ISF gap in the reverse sens */ + { + if (isf[i] > isf_max) + { + isf[i] = isf_max; + } + + isf_max = isf[i] - min_dist; + } + } + + return; +} + +/*----------------------------------------------------------------------------------* + * lsf_stab() + * + * Check LSF stability (distance between old LSFs and current LSFs) + *----------------------------------------------------------------------------------*/ + +float lsf_stab( /* o : LP filter stability */ + const float *lsf, /* i : LSF vector */ + const float *lsfold, /* i : old LSF vector */ + const short Opt_AMR_WB, /* i : flag indicating AMR-WB IO mode */ + const short L_frame /* i : frame length */ +) +{ + short i, m; + float scale, stab_fac, tmp; + + tmp = 0.0f; + if ( Opt_AMR_WB ) + { + m = M-1; + } + else + { + m = M; + } + + for (i=0; i 1.0f) + { + stab_fac = 1.0f; + } + + if (stab_fac < 0.0f) + { + stab_fac = 0.0f; + } + return stab_fac; +} + + +/*--------------------------------------------------------------------- + * get_isppol() + * + * Find the polynomial F1(z) or F2(z) from the ISPs. + * This is performed by expanding the product polynomials: + * + * F1(z) = PRODUCT ( 1 - 2 isp_i z^-1 + z^-2 ) + * i=0,2,...,14 + * F2(z) = PRODUCT ( 1 - 2 isp_i z^-1 + z^-2 ) + * i=1,3,...,13 + * + * where isp_i are the ISPs in the cosine domain. + *---------------------------------------------------------------------*/ + +static void get_isppol( + const float *isp, /* i : Immitance spectral pairs (cosine domaine) */ + float f[], /* o : the coefficients of F1 or F2 */ + const short n /* i : nb. of coefficients (m/2) */ +) +{ + float b; + short i,j; + + f[0] = 1.0f; + b = (float)(-2.0f * *isp); + f[1] = b; + for (i = 2; i <= n; i++) + { + isp += 2; + b = (float)(-2.0f * *isp); + f[i] = (float)(b * f[i-1] + 2.0f * f[i-2]); + + for (j = i-1; j > 1; j--) + { + f[j] += b*f[j-1] + f[j-2]; + } + f[1] += b; + } + + return; +} + + +/*--------------------------------------------------------------------- + * chebps2() + * + * Evaluates the Chebyshev polynomial series + * + * The polynomial order is + * n = m/2 (m is the prediction order) + * The polynomial is given by + * C(x) = f(0)T_n(x) + f(1)T_n-1(x) + ... +f(n-1)T_1(x) + f(n)/2 + *---------------------------------------------------------------------*/ + +static float chebps2( /* o: the value of the polynomial C(x) */ + const float x, /* i: value of evaluation; x=cos(freq) */ + const float *f, /* i: coefficients of sum or diff polyn. */ + const short n /* i: order of polynomial */ +) +{ + float b1, b2, b0, x2; + short i; + + + x2 = (float)(2.0f * x); + b2 = f[0]; + + b1 = x2*b2 + f[1]; + + for (i=2; i A */ + lsp2a_stab( lsp, a, m ); + + /* A --> ISP */ + a2isp( a, isp, stable_isp ); + + /* Update to latest stable ISP */ + mvr2r( isp, stable_isp, M ); +} + +/*-------------------------------------------------------------------* + * isp2lsp() + * + * Convert ISPs to LSPs via predictor coefficients A[] + *-------------------------------------------------------------------*/ + +void isp2lsp( + const float *isp, /* i : LSP vector */ + float *lsp, /* o : ISP filter coefficients */ + float *stable_lsp, /* i/o: stable LSP filter coefficients */ + const short m /* i : order of LP analysis */ +) +{ + float a[M+1]; + + /* ISP --> A */ + isp2a( isp, a, m ); + + /* A --> LSP */ + a2lsp_stab( a, lsp, stable_lsp ); + + /* Update to latest stable LSP */ + mvr2r( lsp, stable_lsp, M ); +} + + +/*-------------------------------------------------------------------* + * lsf2isf() + * + * Convert LSPs to ISPs + *-------------------------------------------------------------------*/ + +void lsf2isf( + const float *lsf, /* i : LSF vector */ + float *isf, /* o : ISF vector */ + float *stable_isp, /* i/o: stable ISP filter coefficients */ + const short m, /* i : order of LP analysis */ + const float int_fs +) +{ + float tmp_lsp[M]; + float tmp_isp[M]; + + /* LSF --> LSP */ + lsf2lsp( lsf, tmp_lsp, m, int_fs ); + + /* LSP --> ISP */ + lsp2isp( tmp_lsp, tmp_isp, stable_isp, m ); + + /* ISP --> ISF */ + isp2isf( tmp_isp, isf, m, int_fs ); + + return; +} + +/*-------------------------------------------------------------------* + * isf2lsf() + * + * Convert ISFs to LSFs + *-------------------------------------------------------------------*/ + +void isf2lsf( + const float *isf, /* i : ISF vector */ + float *lsf, /* o : LSF vector */ + float *stable_lsp, /* i/o: stable LSP filter coefficients */ + const short m, /* i : order of LP analysis */ + const float int_fs +) +{ + float tmp_isp[M]; + float tmp_lsp[M]; + + /* ISF --> ISP */ + isf2isp( isf, tmp_isp, m, int_fs ); + + /* ISP --> LSP */ + isp2lsp( tmp_isp, tmp_lsp, stable_lsp, m ); + + /* LSP --> LSF */ + lsp2lsf( tmp_lsp, lsf, m, int_fs ); + + return; +} + +/*-----------------------------------------------------------------------* + * lsp2lsf() + * + * Transformation of LSPs to LSFs + * + * LSP are line spectral pair in cosine domain (-1 to 1). + * LSF are line spectral frequencies (0 to fs/2). + *-----------------------------------------------------------------------*/ + +void lsp2lsf( + const float lsp[], /* i : isp[m] (range: -1<=val<1) */ + float lsf[], /* o : isf[m] normalized (range: 0<=val<=fs/2) */ + const short m, /* i : LPC order */ + const float fs /* i : sampling frequency */ +) +{ + short i; + + /* convert LSPs to LSFs */ + for( i=0; i> 4; + branch[1] = index[2] >> 4; + + for(stage = 2; stage < N_STAGE_VQ-4; stage++) + { + branch[stage] = index[stage+1] >> 3; + } + + branch[4] = fins & 0x1; + branch[5] = (fins >> 1) & 0x1; + branch[6] = (fins >> 2) & 0x1; + branch[7] = (fins >> 3) & 0x1; + + /* Decode Codeword info */ + for(stage = 0; stage < 2; stage++) + { + codeword[stage] = (index[stage+1] & 15) << 3; + } + + for(stage = 2; stage < N_STAGE_VQ-4; stage++) + { + codeword[stage] = (index[stage+1] & 7) << 3; + } + + for(stage = N_STAGE_VQ-4; stage < N_STAGE_VQ; stage++) + { + codeword[stage] = (index[stage+1] & 3) << 3; + } + + state = (fins >> 2) << 2; + + /* stage #1 */ + iwd = NTRANS2[branch[0]+2][state] + codeword[0]; + D[0][0] = TCVQ_CB_SUB1[0][iwd][0]; + D[0][1] = TCVQ_CB_SUB1[0][iwd][1]; + state = NTRANS2[branch[0]][state]; + + /* stage #2 */ + pred[0] = IntraCoeff[0][0][0] * D[0][0] + IntraCoeff[0][0][1]*D[0][1]; + pred[1] = IntraCoeff[0][1][0] * D[0][0] + IntraCoeff[0][1][1]*D[0][1]; + + iwd = NTRANS2[branch[1]+2][state] + codeword[1]; + D[1][0] = TCVQ_CB_SUB1[1][iwd][0] + pred[0]; + D[1][1] = TCVQ_CB_SUB1[1][iwd][1] + pred[1]; + state = NTRANS2[branch[1]][state]; + + /* stage #3 - #4 */ + for(stage = 2; stage < N_STAGE_VQ-4; stage++) + { + pred[0] = IntraCoeff[stage-1][0][0] * D[stage-1][0] + IntraCoeff[stage-1][0][1]*D[stage-1][1]; + pred[1] = IntraCoeff[stage-1][1][0] * D[stage-1][0] + IntraCoeff[stage-1][1][1]*D[stage-1][1]; + + iwd = NTRANS2[branch[stage]+2][state] + codeword[stage]; + D[stage][0] = TCVQ_CB_SUB2[stage-2][iwd][0] + pred[0]; + D[stage][1] = TCVQ_CB_SUB2[stage-2][iwd][1] + pred[1]; + state = NTRANS2[branch[stage]][state]; + } + + /* stage #5 - #8 */ + for(stage = N_STAGE_VQ-4; stage < N_STAGE_VQ; stage++) + { + pred[0] = IntraCoeff[stage-1][0][0] * D[stage-1][0] + IntraCoeff[stage-1][0][1]*D[stage-1][1]; + pred[1] = IntraCoeff[stage-1][1][0] * D[stage-1][0] + IntraCoeff[stage-1][1][1]*D[stage-1][1]; + + iwd = NTRANS2[branch[stage]+2][state] + codeword[stage]; + D[stage][0] = TCVQ_CB_SUB3[stage-4][iwd][0] + pred[0]; + D[stage][1] = TCVQ_CB_SUB3[stage-4][iwd][1] + pred[1]; + state = NTRANS2[branch[stage]][state]; + } + + for(stage = 0; stage < N_STAGE_VQ; stage++) + { + for(i = 0; i < N_DIM; i++) + { + d_out[(N_DIM*stage) + i] = D[stage][i]; + } + } + return; +} + +/*--------------------------------------------------------------------------- + * qlsf_ARSN_tcvq_Dec_16k() + * + * Predictive BC-TCQ encoder for LSF quantization + *--------------------------------------------------------------------------*/ + +short qlsf_ARSN_tcvq_Dec_16k ( + float *y, /* o : Quantized LSF vector */ + short *indice, /* i : Indices */ + const short nBits /* i : number of bits */ +) +{ + short i; + float error_svq_q[M]; + short safety_net; + + /* Select Mode */ + safety_net = indice[0]; + + + if(safety_net == 1) + { + tcvq_Dec(&indice[1], y, safety_net); + + if(nBits>30) + { + for(i = 0; i < 8; i++) + { + error_svq_q[i] = AR_SVQ_CB1[indice[10]][i]; + error_svq_q[i+8] = AR_SVQ_CB2[indice[11]][i]; + } + + for(i = 0; i < M; i++) + { + y[i] = y[i] + error_svq_q[i] * scale_ARSN[i]; + } + } + } + else + { + tcvq_Dec(&indice[1], y, safety_net); + + if(nBits>30) + { + for(i = 0; i < 8; i++) + { + error_svq_q[i] = AR_SVQ_CB1[indice[10]][i]; + error_svq_q[i+8] = AR_SVQ_CB2[indice[11]][i]; + } + + for(i = 0; i < M; i++) + { + y[i] = y[i] + error_svq_q[i]; + } + } + } + + return safety_net; +} + + +/*-------------------------------------------------------------------* + * lsf_syn_mem_backup() + * + * back-up synthesis filter memory and LSF qunatizer memories (used in SC-VBR) + *-------------------------------------------------------------------*/ + +void lsf_syn_mem_backup( + Encoder_State *st, /* i: state structure */ + LPD_state* LPDmem, /* i: LPD state memory structure */ + float *btilt_code, /* i: tilt code */ + float *bgc_threshold, /* i: */ + float *clip_var_bck, /* o: */ + short *next_force_sf_bck, /* 0: */ + + float *lsp_new, /* i: LSP vector to quantize */ + float *lsp_mid, /* i: mid-frame LSP vector */ + float *clip_var, /* o: pitch clipping state var */ + float *mem_AR, /* o: quantizer memory for AR model */ + float *mem_MA, /* o: quantizer memory for AR model */ + float *lsp_new_bck, /* o: LSP vector to quantize- backup */ + float *lsp_mid_bck, /* o: mid-frame LSP vector - backup */ + short *mCb1, /* o: counter for stationary frame after a transition frame */ + float *Bin_E, /* o: FFT Bin energy 128 *2 sets */ + float *Bin_E_old, /* o: FFT Bin energy 128 sets */ + float *mem_syn_bck, /* o: synthesis filter memory */ + float *mem_w0_bck, /* o: memory of the weighting filter */ + float *streaklimit, + short *pstreaklen +) +{ + short i; + + *clip_var = st->clip_var[0]; + + for(i=0; imem_AR[i]; + mem_MA[i] = st->mem_MA[i]; + lsp_new_bck[i] = lsp_new[i]; + lsp_mid_bck[i] = lsp_mid[i]; + } + + *mCb1 = st->mCb1; + *streaklimit = st->streaklimit; + *pstreaklen = st->pstreaklen; + + for(i=0; iBin_E[i]; + } + + for(i=0; i<(L_FFT/2); i++) + { + Bin_E_old[i]=st->Bin_E_old[i]; + } + + /* back-up memories */ + for(i=0; iLPDmem.mem_syn[i]; + } + + *mem_w0_bck = st->LPDmem.mem_w0; + + *btilt_code = LPDmem->tilt_code; + *bgc_threshold = LPDmem->gc_threshold; + mvr2r( st->clip_var, clip_var_bck, 6 ); + *next_force_sf_bck = st->next_force_safety_net; + + + return; +} + + +/*-------------------------------------------------------------------* + * lsf_syn_mem_restore() + * + * restore synthesis filter memory and LSF quantizer memories + *-------------------------------------------------------------------*/ + +void lsf_syn_mem_restore( + Encoder_State *st, /* o: state structure */ + LPD_state* LPDmem, /* o: LPD_state vewctor */ + float btilt_code, /* i: */ + float gc_threshold, /* i: */ + float *clip_var_bck, /* i: */ + short next_force_sf_bck, /* i: */ + + float *lsp_new, /* o: LSP vector to quantize */ + float *lsp_mid, /* o: mid-frame LSP vector */ + float clip_var, /* i: pitch clipping state var */ + float *mem_AR, /* i: quantizer memory for AR model */ + float *mem_MA, /* i: quantizer memory for AR model */ + float *lsp_new_bck, /* i: LSP vector to quantize- backup */ + float *lsp_mid_bck, /* i: mid-frame LSP vector - backup */ + short mCb1, /* i: counter for stationary frame after a transition frame */ + float *Bin_E, /* i: FFT Bin energy 128 *2 sets */ + float *Bin_E_old, /* i: FFT Bin energy 128 sets */ + float *mem_syn_bck, /* i: synthesis filter memory */ + float mem_w0_bck, /* i: memory of the weighting filter */ + float streaklimit, + short pstreaklen +) +{ + short i; + + /* restore lsf memories */ + st->clip_var[0] = clip_var; + + for(i=0; imem_AR[i] = mem_AR[i]; + st->mem_MA[i] = mem_MA[i]; + lsp_new[i] = lsp_new_bck[i]; + lsp_mid[i] = lsp_mid_bck[i]; + } + + st->mCb1 = mCb1; + st->streaklimit = streaklimit; + st->pstreaklen = pstreaklen; + + for(i=0; iBin_E[i] = Bin_E[i]; + } + + for(i=0; i<(L_FFT/2); i++) + { + st->Bin_E_old[i]=Bin_E_old[i]; + } + + /* restoring memories */ + st->LPDmem.mem_w0 = mem_w0_bck; + + for(i=0; iLPDmem.mem_syn[i] = mem_syn_bck[i]; + } + + LPDmem->tilt_code = btilt_code; + LPDmem->gc_threshold = gc_threshold; + mvr2r( clip_var_bck, st->clip_var, 6 ); + st->next_force_safety_net = next_force_sf_bck; + + + return; +} + +/*--------------------------------------------------------------------------* + * lsf_update_memory() + * + * + *--------------------------------------------------------------------------*/ + +void lsf_update_memory( + int narrowband, /* i : narrowband flag */ + const float qlsf[], /* i : quantized lsf coefficients */ + float old_mem_MA[], /* i : MA memory */ + float mem_MA[] /* o : updated MA memory */ +) +{ + int i; + + for (i=0; i= 0; specix++); + + lsf[lsfix++] = (specix-1 + spec_r[specix-1]/(spec_r[specix-1]-spec_r[specix]))*(12800/256); + + /*check for the next zero crossing*/ + for (; s*spec_i[specix] >= 0; specix++); + + lsf[lsfix++] = (specix-1 + spec_i[specix-1]/(spec_i[specix-1]-spec_i[specix]))*(12800/256); + + spec_r[speclen] = s; + spec_i[speclen] = s; + + s =-s; + } + + if (lsfix < 16) + { + for(i=0; i<16; i++) + { + lsf[i] = old_lsf[i]; + } + } + + return; +} + +/*--------------------------------------------------------------------------* + * a2isf() + * + * + *--------------------------------------------------------------------------*/ + +#define SCALE1_HALF 1018.59161376953f + +typedef struct +{ + float re; + float im; +} Pfloat; + +void a2isf( + float *a, + float *isf, + const float *old_isf, + short lpcOrder +) +{ + float RealFFT[128]; + float ImagFFT[128]; + float RealOut[130]; + float ImagOut[130]; + float *ptrReal; + float *ptrImag; + int n, i, j; + const Pfloat *ptwiddle; + Pfloat *pwn17, pwn[128], *pwn15, tmpw15; + int N = 256; + float s[4]; + float L_tmp, L_tmp1; + float lpc[19], fftTmpRe[16], fftTmpIm[16]; + Pfloat twid[128]; + float c; + + set_zero(fftTmpRe, 16); + set_zero(fftTmpIm, 16); + + /* half length FFT */ + /*c = [sum(a) ((-1).^(1:length(a)))*a];*/ + + L_tmp = 0; + for(j=0; j<=lpcOrder; j++) + { + L_tmp += a[j]; + } + + L_tmp1 = 0; + for(j=0; jre) - (lpc[2*j+1] * ptwiddle->im); + fftTmpIm[j] = (lpc[2*j+1] * ptwiddle->re) + (lpc[2*j] * ptwiddle->im); + ptwiddle++; + } + + fftTmpRe[j] = lpc[2*j]*ptwiddle->re; + fftTmpIm[j] = lpc[2*j]*ptwiddle->im; + ptwiddle++; + j++; + for(; j<16; j++) + { + fftTmpRe[j] = 0; + fftTmpIm[j] = 0; + ptwiddle++; + } + + DoRTFTn(fftTmpRe, fftTmpIm, 16); + + for(j=0; j<16; j++) + { + ptrReal[j*8] = fftTmpRe[j]; + ptrImag[j*8] = fftTmpIm[j]; + } + + ptrReal++; + ptrImag++; + + } + + c = EVS_PI / ( 2.0f * (float)128 ); + + for ( i = 1 ; i < 128 ; i++ ) + { + twid[i-1].im = (float)sin( c * ( 2.0f * (float)i ) ); + twid[i-1].re = (float)cos( c * ( 2.0f * (float)i ) ); + } + ptwiddle = twid; + + /* pre-twiddle */ + for ( i = 1 ; i < 128 ; i++ ) + { + pwn[i-1].im = (float)sin( c * ( 18.0f * (float)i ) ); + pwn[i-1].re = (float)cos( c * ( 18.0f * (float)i ) ); + } + + pwn17 = pwn; + pwn15 = &tmpw15; + + /*Y(1) = real(X(1)) + imag(X(1));*/ + RealOut[0] = (RealFFT[0] + ImagFFT[0]); + ImagOut[0] = 0; + + /*Y(N/2+1) = 0.5*(X(1) + conj(X(1))).*exp(pi*i*128*(18)/N) - i*0.5*(X(1) - conj(X(1))).*exp(pi*i*128*(16)/N);*/ + RealOut[128] = 0; + ImagOut[128] = (RealFFT[0] + RealFFT[0]) - (ImagFFT[0] + ImagFFT[0]); + + /*Y(2:N/2) = (0.5*(X(2:N/2) + conj(X(N/2:-1:2))) - i*0.5*(X(2:N/2) - conj(X(N/2:-1:2))).*exp(-pi*i*r*(2)/N)).*exp(pi*i*r*(18)/N);*/ + for(i=1; ire * pwn17->re) + (ptwiddle->im * pwn17->im); + tmpw15.im = (ptwiddle->re * pwn17->im) - (ptwiddle->im * pwn17->re); + + /*RealOut[i] = mac_r(L_msu(L_msu(L_mult(ReAr, pwn17->re),ImAr, pwn17->im), ReBr, pwn15->v.im), ImBr, pwn15->re); move16();*/ + RealOut[i] = (ReAr * pwn17->re) - (ImAr * pwn17->im) - ((ReBr * pwn15->im) + (ImBr * pwn15->re)); + ImagOut[i] = (ReAr * pwn17->im) + (ImAr * pwn17->re) + (ReBr * pwn15->re) - (ImBr * pwn15->im); + + ptwiddle++; + pwn17++; + } + + spec2isf(RealOut, ImagOut, 128, isf, old_isf); + + isf[lpcOrder - 1] = (Float32)(acos(a[lpcOrder]) * SCALE1_HALF); + + return; +} + diff --git a/src/libs/libevs/lib_com/lsf_tools_fx.cpp b/src/libs/libevs/lib_com/lsf_tools_fx.cpp deleted file mode 100755 index 8e6d0836..00000000 --- a/src/libs/libevs/lib_com/lsf_tools_fx.cpp +++ /dev/null @@ -1,3420 +0,0 @@ -/*==================================================================================== - EVS Codec 3GPP TS26.442 Apr 03, 2018. Version 12.11.0 / 13.6.0 / 14.2.0 - ====================================================================================*/ - -#include -#include -#include -#include "options.h" /* Compilation switches */ -#include "stl.h" -#include "basop_util.h" -#include "rom_com_fx.h" -#include "cnst_fx.h" -#include "prot_fx.h" -#include "rom_com_fx.h" /* Static table prototypes */ - - - -#define NC_MAX 8 -#define GUESS_TBL_SZ 256 - -#define depack_4_values(cbp, val0, val1, val2, val3) \ - val0 = shr((cbp)[0], 4); \ - val1 = shr((cbp)[1], 4); \ - val2 = shr((cbp)[2], 4); \ - val3 = add(add(shr(lshl((cbp)[2],12),4),lshr(lshl((cbp)[1],12),8)),s_and((cbp)[0],0xF)); - -/*-------------------------------------------------------------------* - * Local constants - *-------------------------------------------------------------------*/ - -#define NC ( M/2) -#define NC16k ( M16k/2) - -#define SPC 0.0234952f -#define SPC_plus SPC * 1.001f -#define ALPHA_SQ ( ( 0.5f / PI2) * ( 0.5f / PI2)) - -/*-------------------------------------------------------------------* - * Local functions - *-------------------------------------------------------------------*/ -Word16 root_search_fx( Word16 low, Word16 high, Word32 *v_low, Word32 *coef,Word16 order); -Word32 calc_weight( Word16 delta1,Word16 delta2,Word16 *n1 ); -Word32 polynomial_eval_fx( Word16 f, Word32 *coef,Word16 order); -void E_LPC_isf_isp_conversion(const Word16 isf[], Word16 isp[], const Word16 m); -void E_LPC_lsp_lsf_conversion(const Word16 lsp[],Word16 lsf[],const Word16 m); -Word16 E_LPC_f_lsp_pol_get(const Word16 lsp[], Word32 f[], const Word16 n, const Word16 past_Ovf, const Word16 isMODE1); - -static Word16 chebyshev(Word16 x, Word32 *f, Word16 n, Word16 shift) -{ - - Word16 cheb; - Word32 t0, b1, b2; - - cheb = norm_s(x); - if (cheb) - { - x = shl(x,1); - } - t0 = Mpy_32_16_1(*f++, x); /* t0 = x*b2 */ - if (!cheb) - t0 = L_shl(t0, 1); /* t0 = 2*x*b2 */ - b1 = L_add(t0, *f++); /* b1 = 2*x*b2 + f[1] */ - - /* i = 2 */ - t0 = Mpy_32_16_1(b1, x); /* t0 = x*b1 */ - if (!cheb) - t0 = L_shl(t0, 1); /* t0 = 2*x*b1 */ - b2 = L_add(t0, *f++); /* b0 = 2*x*b1 - b2 + f[i] */ - - /* i = 3 */ - t0 = Mpy_32_16_1(b2, x); /* t0 = x*b1 */ - if (!cheb) - t0 = L_shl(t0, 1); /* t0 = 2*x*b1 */ - t0 = L_sub(t0, b1); /* t0 = 2*x*b1 - b2 */ - b1 = L_add(t0, *f++); /* b0 = 2*x*b1 - b2 + f[i] */ - - /* i = 4 */ - t0 = Mpy_32_16_1(b1, x); /* t0 = x*b1 */ - if (!cheb) - t0 = L_shl(t0, 1); /* t0 = 2*x*b1 */ - t0 = L_sub(t0, b2); /* t0 = 2*x*b1 - b2 */ - - /* If the LP order is greater than 10 */ - IF(sub(n, 5) > 0) - { - b2 = L_add(t0, *f++); /* b0 = 2*x*b1 - b2 + f[i] */ - /* i = 5 */ - t0 = Mpy_32_16_1(b2, x); /* t0 = x*b1 */ - if (!cheb) - t0 = L_shl(t0, 1); /* t0 = 2*x*b1 */ - t0 = L_sub(t0, b1); /* t0 = 2*x*b1 - b2 */ - b1 = L_add(t0, *f++); /* b0 = 2*x*b1 - b2 + f[i] */ - - /* i = 6 */ - t0 = Mpy_32_16_1(b1, x); /* t0 = x*b1 */ - if (!cheb) - t0 = L_shl(t0, 1); /* t0 = 2*x*b1 */ - t0 = L_sub(t0, b2); /* t0 = 2*x*b1 - b2 */ - } - /* IF (sub(n,8) == 0) */ - IF (n == 8) - { - b2 = L_add(t0, *f++); /* b0 = 2*x*b1 - b2 + f[i] */ - /* i = 7 */ - t0 = Mpy_32_16_1(b2, x); /* t0 = x*b1 */ - if (!cheb) - t0 = L_shl(t0, 1); /* t0 = 2*x*b1 */ - t0 = L_sub(t0, b1); /* t0 = 2*x*b1 - b2 */ - /*b1 = L_add(b2,0);*/ - } - ELSE - b2 = L_add(b1,0); - - t0/*b2*/ = L_add(t0, *f++); /* b0 = 2*x*b1 - b2 + f[i] */ - - t0 = Mpy_32_16_1(t0/*b2*/, x);/* t0 = x*b1 */ - if (cheb) - t0 = L_shr(t0,1); - t0 = L_sub(t0, /*b1*/b2); /* t0 = x*b1 - b2 */ - t0 = L_add(t0, *f++); /* t0 = x*b1 - b2 + 0.5*f[n] */ - - - BASOP_SATURATE_WARNING_OFF - t0 = L_shl(t0, shift); /* Qx to Q30 with saturation */ - cheb = round_fx(t0); /* Result in Q14 */ - cheb = s_max(-32767,cheb); /* to avoid saturation */ - BASOP_SATURATE_WARNING_ON - return (cheb); -} - -void E_LPC_a_isp_conversion(const Word16 a[], Word16 isp[], const Word16 old_isp[], const Word16 m) -{ - Word16 i, nf, ip, order, nc; - Word16 xlow, ylow, xhigh, yhigh; - Word16 x, y, tmp, exp; - Word32 f[2][NC_MAX+1]; - Word32 t0, t1; - Word16 scale=1024; - - - /*-------------------------------------------------------------* - * find the sum and diff polynomials F1(z) and F2(z) - * F1(z) = [A(z) + z^M A(z^-1)] - * F2(z) = [A(z) - z^M A(z^-1)]/(1-z^-2) - * - * for (i=0; i= 0) - { - BREAK; - } - - ip = s_xor(ip, 1); - order = sub(nc, ip); - ylow = chebyshev(xlow, f[ip], order, 7); - } - } - - /*----------------------------------------------------------------* - * Check if m-1 roots found, if not use the ISPs from previous frame - *----------------------------------------------------------------*/ - - isp[m - 1] = shl(a[m], add(norm_s(a[0]),1)); - move16(); /* From Qx to Q15 with saturation */ - - IF (s_min(sub(nf, m - 1), sub(8192, abs_s(a[m]))) < 0) - { - FOR (i = 0; i < m; i++) - { - isp[i] = old_isp[i]; - move16(); - } - } - - -} - -/* -* E_LPC_f_isp_a_conversion -* -* Parameters: -* isp I: Immittance spectral pairs Q15 -* a O: Predictor coefficients (order = m) Q12 -* m I: order of LP filter -* -* Function: -* Convert ISPs to predictor coefficients a[] -* -* Returns: -* void -*/ -void E_LPC_f_isp_a_conversion(const Word16 *isp, Word16 *a, const Word16 m) -{ - Word16 i, j; - Word32 f1[NC_MAX+1], f2[NC_MAX+1]; /* Q23 */ - Word16 nc, q; - Word32 t0, tmax, t0p, t0n; - - - - /*-----------------------------------------------------* - * Find the polynomials F1(z) and F2(z) * - *-----------------------------------------------------*/ - - nc = shr(m, 1); - - E_LPC_f_lsp_pol_get(&isp[0], f1, nc, 0, 0); - E_LPC_f_lsp_pol_get(&isp[1], f2, sub(nc, 1), 0, 0); - /*-----------------------------------------------------* - * Multiply F2(z) by (1 - z^-2) * - *-----------------------------------------------------*/ - - FOR (i = sub(nc, 1); i > 1; i--) - { - /* f2[i] -= f2[i-2]; */ - f2[i] = L_sub(f2[i], f2[i - 2]); - move32(); - } - - /*----------------------------------------------------------* - * Scale F1(z) by (1+isp[m-1]) and F2(z) by (1-isp[m-1]) * - *----------------------------------------------------------*/ - - FOR (i = 0; i < nc; i++) - { - /* f1[i] *= (1.0 + isp[m-1]); */ - f1[i] = Madd_32_16(f1[i], f1[i], isp[m - 1]); - move32(); - - /* f2[i] *= (1.0 - isp[m-1]); */ - f2[i] = Msub_32_16(f2[i], f2[i], isp[m - 1]); - move32(); - } - - /*-----------------------------------------------------* - * A(z) = (F1(z)+F2(z))/2 * - * F1(z) is symmetric and F2(z) is antisymmetric * - *-----------------------------------------------------*/ - - /* Maximum LPC */ - tmax = L_deposit_l(1); - FOR (i = 1; i < nc; i++) - { - t0 = L_add(f1[i], f2[i]); - tmax = L_max( tmax, L_abs(t0) ); - t0 = L_sub(f1[i], f2[i]); - tmax = L_max( tmax, L_abs(t0) ); - } - q = s_min( norm_l(tmax), 6 ); - - DO - { - - /* a[0] = 1.0 */ - a[0] = shl(256,q); - move16(); - j = sub(m, 1); - FOR (i = 1; i < nc; i++) - { - /* a[i] = 0.5*(f1[i] + f2[i]) */ - t0 = L_add(f1[i], f2[i]); /* f1[i] + f2[i] */ - t0 = L_shl(t0, q); - a[i] = round_fx(t0); /* from Q23 to Q12 and * 0.5 */ - - /* a[j] = 0.5*(f1[i] - f2[i]) */ - t0 = L_sub(f1[i], f2[i]); /* f1[i] - f2[i] */ - t0 = L_shl(t0, q); - a[j] = round_fx(t0); /* from Q23 to Q12 and * 0.5 */ - - j = sub(j,1); - } - - /* a[NC] = 0.5*f1[NC]*(1.0 + isp[m-1]) */ - t0 = Madd_32_16(f1[nc], f1[nc], isp[m - 1]); - - BASOP_SATURATE_WARNING_OFF /*overflow handling in loop expression*/ - t0 = L_shl(t0, q); - t0n = L_sub(t0 , 0x7FFFFFFF); /*check for positive overflow*/ - t0p = L_sub(t0, 0x80000000); /*check for negative overflow*/ - BASOP_SATURATE_WARNING_ON - - q = sub(q,1); /*decrease q in case of overflow*/ - } WHILE(t0n == 0 || t0p == 0); /*in case of overflow, recalculate coefficients*/ - - a[nc] = round_fx(t0); /* from Q23 to Q12 and * 0.5 */ - - /* a[m] = isp[m-1] */ - t0 = L_mult(a[0], isp[m - 1]); /* from Q15 to Q12 */ - a[m] = round_fx(t0); - - - return; -} - -/*===================================================================*/ -/* FUNCTION : lpc2lsp_fx () */ -/*-------------------------------------------------------------------*/ -/* PURPOSE : Convert LPC coefficients to LSP coefficients */ -/*-------------------------------------------------------------------*/ -/* INPUT ARGUMENTS : */ -/* */ -/* _ (Word32 []) a : LPC coefficients, Q27 */ -/* _ (Word16 []) old_freq: Previous frame LSP coefficients, Q15 */ -/* _ (Word16 []) order: LPC order */ -/*-------------------------------------------------------------------*/ -/* OUTPUT ARGUMENTS : */ -/* _ (Word16 []) freq: LSP coefficients, Q15 */ -/*-------------------------------------------------------------------*/ -/* INPUT/OUTPUT ARGUMENTS : */ -/* _ None */ -/*-------------------------------------------------------------------*/ -/* RETURN ARGUMENTS : */ -/* _ (Word16) flag: 1 means all 10 LSPs are found, 0 otherwise */ -/*===================================================================*/ -Word16 lpc2lsp_fx( - Word32* a, - Word16* freq, - Word16* old_freq, - Word16 order -) -{ - Word16 i; - Word16 rt, low, high, prev_rt, rc; - Word32 p[11], q[11]; /* Q26 */ - Word32 Ltemp, v_low; - Word32 Lacc; - Word16 tfreq[21]; - - /* First construct the P,Q polynomial */ - /* p[0] = q[0] = 1 */ - /* p[i] = -lpcCoeff[i] - lpcCoeff[11-i] - p[i-1] ( 1<=i<=5)*/ - /* q[i] = -lpcCoeff[i] + lpcCoeff[11-i] + q[i-1] ( 1<=i<=5)*/ - Ltemp = L_deposit_h( 0x400 ); /* Ltemp is 1.0 in Q26 */ - - p[0] = Ltemp; - move32(); - q[0] = Ltemp; - move32(); - - FOR ( i = 1; i < ( order / 2 ) + 1; i++ ) - { - Lacc = a[order - i]; - move32();/* Q27 */ - Lacc = L_sub( Lacc, a[i - 1] ); /* Lacc=-lpcCoeff[i-1] + lpcCoeff[order-i]//Q27 */ - q[i] = L_add( L_shr( Lacc, 1 ), q[i - 1] ); - move32();/* Q26 */ - - Lacc = L_add( Lacc, L_shl( a[i - 1], 1 ) );/* Lacc=lpcCoeff[i-1] + lpcCoeff[order-i]//Q27 */ - - p[i] = L_sub( L_negate( L_shr( Lacc, 1 ) ), p[i - 1] ); - move32();/* Q26 */ - } - - /* Search roots of the P and Q polynomials */ - - v_low = polynomial_eval_fx( 0, p, order ); /* Q25 */ - move16(); - move16(); - move16(); - move16(); - move16(); - move16(); - low = 0; - high = 8; - prev_rt = 0; - rc = 0; /* root counter */ - FOR ( i = 0; i < 32; i++ ) - { - rt = root_search_fx( low, high, &v_low, p, order ); - low = high; - move16(); - high = add( high, 8 ); - - IF( sub( rt, prev_rt ) >= 0 ) - { - tfreq[rc] = rt; - move16(); - rc = add( rc, 2 ); - } - prev_rt = add( rt, 6 ); - } /* End for P roots */ - - tfreq[rc] = 0x3f80; - move16(); /* Set a high enough value as fake root for Q search */ - - IF ( sub( rc, order ) < 0 ) - { - /* lost P root */ - /* copy from previous LSP and return */ - FOR ( i = 0; i < order; i++ ) - { - move16(); - freq[i] = old_freq[i]; - } - return ( 0 ); - } - ELSE - { - /* Search for Q roots between P roots */ - v_low = L_deposit_h( 0x800 ); /* Init a positive value for v_low */ - rc = 1; - move16(); - FOR ( i = 0; i < order / 2; i++ ) - { - low = shr( tfreq[rc - 1], 6 ); - high = add( shr( tfreq[rc + 1], 6 ), 1 ); - rt = root_search_fx( low, high, &v_low, q, order ); - - IF ( rt < 0 ) - { - /* No Q root in this interval */ - /* copy from previous LSP and return */ - FOR ( i = 0; i < order; i++ ) - { - move16(); - freq[i] = old_freq[i]; - } - return ( 0 ); - } - ELSE - { - move16(); - tfreq[rc] = rt; - rc = add( rc, 2 ); - } /* end else, find Q root */ - } /* end for */ - } /* end else */ - - FOR ( i = 0; i < order; i++ ) - { - freq[i] = tfreq[i]; - move16(); - } - - return ( 1 ); -} - -/*===================================================================*/ -/* FUNCTION : lsp2lpc_fx () */ -/*-------------------------------------------------------------------*/ -/* PURPOSE : Convert LSP coefficients to LPC coefficients */ -/*-------------------------------------------------------------------*/ -/* INPUT ARGUMENTS : */ -/* */ -/* _ (Word16 []) freq: LSP coefficients, Q15 */ -/* _ (Word16 []) prev_a : previous frame LPC coefficients, Q12 */ -/* _ (Word16 []) order : LPC order */ -/*-------------------------------------------------------------------*/ -/* OUTPUT ARGUMENTS : */ -/* _ (Word16 []) a : LPC coefficients, Q12 */ -/*-------------------------------------------------------------------*/ -/* INPUT/OUTPUT ARGUMENTS : */ -/* _ None */ -/*-------------------------------------------------------------------*/ -/* RETURN ARGUMENTS : */ -/* _ None */ -/*===================================================================*/ -void lsp2lpc_fx( - Word16 *a, - Word16 *freq, - Word16 *prev_a, - Word16 order -) -{ - Word16 i; - Word32 pq[ LPC_SHB_ORDER ] ; - Word32 p[ LPC_SHB_ORDER ], q[ LPC_SHB_ORDER ]; - Word32 Ltemp; - Word32 Lacc; - Word16 tmp_pci[M+1]; - Word16 giOverflow; - - - FOR ( i = 0; i < order; i++ ) - { - tmp_pci[i]=prev_a[i]; - move16(); - } - - compute_poly_product_fx( freq, pq, order ); - /*This change is to get funtionality if L_sub_sat*/ - giOverflow = 0 ; - move16(); /* clear overflow flag */ - Overflow = 0; - move16(); - FOR ( i=0; i < order/2; i++ ) - { - Ltemp = L_add( pq[ i ], pq[ i + 1 ] ); - giOverflow = ( Word16 )Overflow; - move16(); - IF ( sub(giOverflow,1) == 0 ) - { - BREAK; - } - - p[ i ] = Ltemp ; - move32(); - } - - IF ( sub(giOverflow,1) == 0 ) - { - FOR (i=0; i < order; i++ ) - { - a[i] = mult_r( prev_a[i], pwAlpha[i] ); - move16(); - } - return; - } - - compute_poly_product_fx( freq+1, pq, order ); - - - giOverflow = 0; - move16(); - Overflow = 0; - move16(); - - FOR ( i=0; i < order/2; i++ ) - { - Ltemp = L_sub( pq[ i+1 ], pq[i] ); - giOverflow = ( Word16 ) Overflow; - move16(); - IF ( sub(giOverflow,1) == 0 ) - { - BREAK; - } - - q[i] = Ltemp; - move32(); - } - - IF ( sub(giOverflow,1) == 0 ) - { - FOR (i = 0; i < order; i++ ) - { - a[i] = mult_r( prev_a[i], pwAlpha[i] ); - move16(); - } - } - ELSE - { - FOR (i = 0; i < order/2; i++ ) - { - Overflow = 0; - move16(); - Lacc = L_add( p[i], q[i] ); /* p[i], q[i] in Q24 */ - if ( Overflow ) - { - giOverflow = 1; - move16(); - } - - Lacc = L_negate( Lacc ); /* Lacc=-(p[i]-q[i])/2 in Q25 */ - Overflow = 0; - move16(); - Lacc = L_add( L_shl( Lacc, 3 ), 0x08000 ); /* rounding */ - if ( Overflow ) - { - giOverflow = 1; - move16(); - } - - a[i] = extract_h( Lacc ); /* a[i] in Q12 */ - - IF ( sub(giOverflow,1) == 0 ) - { - BREAK; - } - - } - FOR ( i=0; i < order/2; i++ ) - { - Overflow = 0; - move16(); - Lacc = L_sub( q[i], p[i] ); /* p[i], q[i] in Q24 */ - if( Overflow ) - { - giOverflow = 1; - move16(); - } - Overflow = 0; - move16(); - Lacc = L_add( L_shl( Lacc, 3 ), 0x08000); /* rounding */ - if ( Overflow ) - { - giOverflow = 1; - move16(); - } - - a[ order-1-i ] = extract_h( Lacc ); - - - IF ( sub(giOverflow,1) == 0 ) - { - BREAK; - } - - } - } - - - IF ( sub(giOverflow,1) == 0 ) - { - FOR ( i = 0; i < order; i++ ) - { - a[i] = mult_r( tmp_pci[i], pwAlpha[i] ); - move16(); - } - } - -} - -/* - * E_LPC_f_lsp_pol_get - * - * Parameters: - * lsp/isp I: Line spectral pairs (cosine domaine) Q15 - * f O: the coefficients of F1 or F2 Q23 - * n I: no of coefficients (m/2) - * == NC for F1(z); == NC-1 for F2(z) - * fact I: scaling factor - * - *-----------------------------------------------------------* - * procedure E_LPC_f_lsp_pol_get: * - * ~~~~~~~~~~~ * - * Find the polynomial F1(z) or F2(z) from the LSPs. * - * This is performed by expanding the product polynomials: * - * * - * F1(z) = product ( 1 - 2 LSF_i z^-1 + z^-2 ) * - * i=0,2,4,6,8 * - * F2(z) = product ( 1 - 2 LSF_i z^-1 + z^-2 ) * - * i=1,3,5,7,9 * - * * - * where LSP_i are the LSPs in the cosine domain. * - * * - *-----------------------------------------------------------* - * R.A.Salami October 1990 * - *-----------------------------------------------------------* - */ -Word16 E_LPC_f_lsp_pol_get(const Word16 lsp[], Word32 f[], const Word16 n, const Word16 past_Ovf, const Word16 isMODE1) -{ - /* All computation in Q23 */ - const Word16 *plsp; - Word16 i, j; - Word16 b; - Word32 b32; - Word16 Ovf = 0; - Word16 Q_out; - Word16 m2; - - - Q_out = 31-23; - move16(); - Ovf = past_Ovf; - move16(); - - test(); - if(past_Ovf && isMODE1) /* Currently this feature is implemented only in MODE1 */ - { - /* In some NB cases, overflow where detectected - in f1 or f2 polynomial computation when it - happen we reduce the precision of the computing - to limit the risk of saturation*/ - Q_out = add(Q_out, past_Ovf); - } - Overflow = 0; - move16(); - plsp = lsp; - f[0] = L_shl(1, sub(31, Q_out)); - move32(); - /*b = -2.0f * *plsp;*/ - b = *plsp; - move16(); - m2 = shl(-2, sub(15, Q_out)); - f[1] = L_mult(b, m2); - move32(); - - FOR (i = 2; i <= n; i++) - { - plsp += 2; - /*b = 2.0f * *plsp;*/ - move16(); - b = *plsp; - b32 = L_mult(b, m2); - - /*f[i] = -b*f[i-1] + 2.0f*f[i-2];*/ - move32(); - f[i] = L_shl(L_sub(f[i-2], Mpy_32_16_1(f[i-1], b)),1); - - FOR (j = i-1; j > 1; j--) - { - /*f[j] += b*f[j-1] + f[j-2];*/ - move32(); - f[j] = L_add(f[j], L_sub(f[j-2], L_shl(Mpy_32_16_1(f[j-1], b),1))); - } - move32(); - f[1] = L_add(f[1], b32); - } - - - test(); - IF (Overflow>0 && isMODE1) - { - /* If an overflow is detected, redo the computation with 1 bit less */ - Ovf = add(Ovf,1); - Ovf = E_LPC_f_lsp_pol_get(lsp, f, n ,Ovf, isMODE1); - } - return Ovf; -} - -void E_LPC_a_lsp_conversion( - const Word16 *a, /* input : LP filter coefficients (Qx) */ - Word16 *lsp, /* output: Line spectral pairs (in the cosine domain)(0Q15) */ - const Word16 *old_lsp, /* input : LSP vector from past frame (0Q15) */ - const Word16 m /* input : length of the LP filter coefficients */ -) -{ - Word16 i, nf, ip, nc; - Word16 xlow, ylow, xhigh, yhigh; - Word16 x, y, tmp, exp; - Word32 f[2][NC_MAX+1]; - Word32 t0, t1; - Word32 sum, diff; - Word16 scale; - - - - nc = shr(m, 1); - - scale = shl( 128, norm_s(a[0]) ); - - /*-------------------------------------------------------------* - * find the sum and diff polynomials F1(z) and F2(z) * - * F1(z) = [A(z) + z^11 A(z^-1)]/(1+z^-1) * - * F2(z) = [A(z) - z^11 A(z^-1)]/(1-z^-1) * - *-------------------------------------------------------------*/ - - f[0][0] = L_mult(a[0],scale); /*1.0f in Q23*/ move32(); - f[1][0] = L_mult(a[0],scale); /*1.0f in Q23*/ move32(); - FOR (i = 1; i < nc; i++) - { - t0 = L_mult(a[i],scale); /*Q23*/ - sum = L_mac(t0, a[m+1-i],scale); - diff = L_msu(t0, a[m+1-i],scale); - f[0][i] = L_sub(sum,f[0][i-1]); - move32(); /*Q23*/ - f[1][i] = L_add(diff,f[1][i-1]); - move32(); /*Q23*/ - } - t1 = L_mult0(a[i],scale); /*Q23-1*/ - sum = L_mac0(t1, a[m+1-i],scale); - diff = L_msu0(t1, a[m+1-i],scale); - f[0][nc] = L_sub(sum, L_shr(f[0][i-1],1)); - move32(); /*Q23-1*/ - f[1][nc] = L_add(diff,L_shr(f[1][i-1],1)); - move32(); /*Q23-1*/ - - /* Precalculate difference to index 0 for index 2 */ - f[0][2] = L_sub(f[0][2], f[0][0]); - move32(); - f[1][2] = L_sub(f[1][2], f[1][0]); - move32(); - - /*---------------------------------------------------------------------* - * Find the LSPs (roots of F1(z) and F2(z) ) using the * - * Chebyshev polynomial evaluation. * - * The roots of F1(z) and F2(z) are alternatively searched. * - * We start by finding the first root of F1(z) then we switch * - * to F2(z) then back to F1(z) and so on until all roots are found. * - * * - * - Evaluate Chebyshev pol. at grid points and check for sign change.* - * - If sign change track the root by subdividing the interval * - * 4 times and ckecking sign change. * - *---------------------------------------------------------------------*/ - nf = 0; - move16(); /* number of found frequencies */ - ip = 0; - move16(); /* indicator for f1 or f2 */ - - xlow = Grid[0]; - move16(); - ylow = chebyshev(xlow, f[ip], nc, 8); - - FOR (i = 1; i <= GRID100_POINTS; i++) - { - xhigh = xlow; - move16(); - yhigh = ylow; - move16(); - xlow = Grid[i]; - move16(); - ylow = chebyshev(xlow, f[ip], nc, 8); - - IF (L_mult(ylow, yhigh) <= 0) - { - t0 = L_mult(xhigh, 0x4000); - /* divide 2 times the interval */ - x = mac_r(t0, xlow, 0x4000); /* xmid = (xlow + xhigh)/2 */ - y = chebyshev(x, f[ip], nc, 8); - - IF (L_mult(ylow, y) <= 0) - { - yhigh = y; - move16(); - xhigh = x; - move16(); - y = ylow; - move16(); - x = xlow; - move16(); - /* 'xhigh' has changed, update 't0' */ - t0 = L_mult(xhigh, 0x4000); - } - xlow = mac_r(t0, x, 0x4000); /* xmid = (xlow + xhigh)/2 */ - ylow = chebyshev(xlow, f[ip], nc, 8); - - IF (L_mult(y, ylow) <= 0) - { - yhigh = ylow; - move16(); - xhigh = xlow; - move16(); - ylow = y; - move16(); - xlow = x; - move16(); - } - - /*--------------------------------------------------------* - * Linear interpolation - * xint = xlow - ylow*(xhigh-xlow)/(yhigh-ylow) - *--------------------------------------------------------*/ - y = msu_r(L_mult(yhigh,0x4000), ylow,0x4000); - - IF (y != 0) - { - x = sub(xhigh, xlow); - BASOP_SATURATE_WARNING_OFF - tmp = abs_s(y); - BASOP_SATURATE_WARNING_ON - exp = norm_s(tmp); - if (exp) - tmp = shl(tmp, exp); - tmp = div_s((Word16) 16383/2, tmp); - t0 = L_mult(x, tmp); - t0 = L_shr(t0, sub(20, exp)); - tmp = extract_l(t0); /* y = (xhigh-xlow)/(yhigh-ylow) in Q11 */ - - /* Restore Sign */ - if (y < 0) - tmp = negate(tmp); - - t0 = L_mult(ylow, tmp); /* result in Q26 */ - t0 = L_shr(t0, 11); /* result in Q15 */ - xlow = sub(xlow, extract_l(t0));/* xint = xlow - ylow*y */ - } - lsp[nf++] = xlow; - move16(); - - IF (sub(nf,m) >= 0) - { - BREAK; - } - - ip = s_xor(ip, 1); - ylow = chebyshev(xlow, f[ip], nc, 8); - } - } - - /* Check if m roots found */ - /* if not use the LSPs from previous frame */ - - IF (sub(nf,m) < 0) - { - FOR(i=0; i 0) /* If danger of unstable filter in case of resonance in HF */ - { - FOR (i = n_m_1; i >= 0; i--) /* Reverify the minimum LSF gap in the reverse direction */ - { - if (sub(lsf[i], lsf_max) > 0) - { - lsf[i] = lsf_max; - move16(); - } - lsf_max = sub(lsf[i], min_dist); - } - } -} - -void space_lsfs_fx ( - Word16* lsfs, /* i/o: Line spectral frequencies */ - const Word16 order /* i : order of LP analysis */ -) -{ - Word16 delta; /* Q1.15 */ - Word16 i, flag=1; - - WHILE ( flag == 1 ) - { - flag = 0; - move16(); - FOR ( i = 0; i <= order; i++ ) - { - IF( i == 0 ) - { - delta = lsfs[0]; - move16(); - } - ELSE - { - IF( sub(i,order) == 0 ) - { - delta = sub( HALF_POINT_FX, lsfs[i-1] ); - move16(); - } - ELSE - { - delta = sub( lsfs[i], lsfs[i-1] ); - move16(); - } - } - IF ( sub( delta, SPC_FX ) < 0 ) - { - flag = 1; - move16(); - delta = sub( delta, SPC_PLUS_FX ); - - IF ( i == order ) - { - lsfs[i - 1] = add( lsfs[i - 1], delta ); - move16(); - } - ELSE - { - IF ( i == 0 ) - { - lsfs[i] = sub( lsfs[i], delta ); - move16(); - } - ELSE - { - delta = mult_r( delta, HALF_POINT_FX ); - lsfs[i - 1] = add( lsfs[i - 1], delta ); - move16(); - lsfs[i] = sub( lsfs[i], delta ); - move16(); - } - } - } - } - } - - return; -} - -/*=================================================================== */ -/* FUNCTION : lsp_weights_fx () */ -/*------------------------------------------------------------------- */ -/* PURPOSE : This function computes the weights for the */ -/* given unquantized lsp vector */ -/*------------------------------------------------------------------- */ -/* INPUT ARGUMENTS : -_ (Word16 []) lsp_nq_fx: input unquantized lsp vector */ -/* _(Word16 Order) FilterOrder */ -/*------------------------------------------------------------------- */ -/* OUTPUT ARGUMENTS : */ -/* _ (Word16 []) w: weight vector Q(9-n_max) */ - -/*------------------------------------------------------------------- */ -/* INPUT/OUTPUT ARGUMENTS : */ -/* _ None. */ -/*------------------------------------------------------------------- */ -/* RETURN ARGUMENTS : */ -/* _ None. */ -/*=================================================================== */ - -void lsp_weights_fx( - Word16 lsp_nq_fx[], - Word16 w[], - Word16 Order, - Word16* Qout -) -{ - Word16 lpcOrder =Order; - - Word16 i, n1, tmp_loop; - Word16 norm[20]; - Word32 Lsum1[20]; - Word16 delta1, delta2, temp; - Word16 n_max =-32768; - move16(); - - temp = 0; - move16(); - - tmp_loop = sub( lpcOrder, 1 ); - FOR ( i = 0; i < tmp_loop; i++ ) - { - delta1 = sub( lsp_nq_fx[i], temp ); - delta2 = sub( lsp_nq_fx[i + 1], lsp_nq_fx[i] ); - Lsum1[i] = calc_weight( delta1, delta2, &n1 ); - move32();/* Q( 26-n1) */ - norm[i] = n1; - move16(); - - if (sub(norm[i],n_max) > 0 ) - { - n_max = norm[i]; - move16(); - } - temp = lsp_nq_fx[i]; - move16(); - } - delta1 = sub( lsp_nq_fx[i], temp ); - delta2 = sub( 16384, lsp_nq_fx[i] ); - - Lsum1[i] = calc_weight( delta1, delta2, &n1 ); - move32(); /* Q( 26-n1) */ - norm[i] = n1; - move16(); - - if ( sub(norm[i], n_max) > 0 ) - { - n_max = norm[i]; - move16(); - } - FOR ( i = 0; i < lpcOrder; i++ ) - { - w[i] = round_fx( L_shl( Lsum1[i], sub( norm[i], n_max + 1 ) ) ); /* Q( 9-n_max) */ - } - - IF ( lpcOrder != LPC_SHB_ORDER_WB ) - { - w[3] = round_fx( L_shl( L_mult( w[3], 18022 ), 1 ) ); /* Q( 9-n_max) */ - w[4] = round_fx( L_shl( L_mult( w[4], 18022 ), 1 ) ); /* Q( 9-n_max) */ - } - - *Qout = 9 - n_max; - move16(); -} - -/* - * E_LPC_isf_isp_conversion - * - * Parameters: - * isf I: isf[m] normalized (range: 0 <= val <= 0.5) 14Q1*1.28 - * isp O: isp[m] (range: -1 <= val < 1) Q15 - * m I: LPC order - * - * Function: - * Transformation isf to isp - * - * ISF are immitance spectral pair in frequency domain (0 to 6400). - * ISP are immitance spectral pair in cosine domain (-1 to 1). - * - * Returns: - * void - */ -void E_LPC_isf_isp_conversion(const Word16 isf[], Word16 isp[], const Word16 m) -{ - Word16 i; - - assert( m==16 || m==10 ); - - - FOR (i = 1; i < m; i++) - { - *isp++ = xsf_to_xsp(*isf++); - move16(); - } - *isp = xsf_to_xsp(shl(*isf, 1)); - move16(); - - - return; -} - -/* - * E_LPC_isp_isf_conversion - * - * Parameters: - * isp I: isp[m] (range: -1 <= val < 1) Q15 - * isf O: isf[m] normalized (range: 0 <= val <= 6400) x1.28 - * m I: LPC order - * - * Function: - * Transformation isp to isf - * - * ISP are immitance spectral pair in cosine domain (-1 to 1). - * ISF are immitance spectral pair in frequency domain (0 to 6400). - * - * Returns: - * energy of prediction error - */ -void E_LPC_isp_isf_conversion(const Word16 isp[], Word16 isf[], const Word16 m) -{ - Word16 i; - - assert( m==16 || m==10 ); - - - - FOR (i = 0; i < m; i++) - { - isf[i] = xsp_to_xsf(isp[i]); - move16(); - } - - isf[m - 1] = shr(isf[m - 1], 1); - move16(); - - - return; -} - - -Word16 xsf_to_xsp(Word16 lsf) -{ - /* lsp = cos(lsf * 3.1415/6400); */ - return getCosWord16R2(lsf); -} - -Word16 xsp_to_xsf(Word16 lsp) -{ - Word16 ind, tmp; - Word32 L_tmp; - - - /*------------------------------------------------------* - * find value in table that is just greater than lsp - *------------------------------------------------------*/ - - /* Retrieve Index Guess */ - /* Based on lsp */ - ind = mac_r(GUESS_TBL_SZ/2*65536-0x8000, lsp, GUESS_TBL_SZ/2); - ind = Ind_Guess[ind]; - move16(); - - /* Correct Index so that */ - /* cos_table_129[ind] > isp[i] */ - tmp = sub(lsp, cos_table_129[ind]); - /* - 69%: (Final Index - Index Guess) is <= 1 - 28%: (Final Index - Index Guess) is 2 - 2%: (Final Index - Index Guess) is >= 3 - <1%: ... - */ - IF (tmp > 0) /* possible range 0 to -5 (-1-2-2) */ - { - ind = sub(ind, 1); - tmp = sub(lsp, cos_table_129[ind]); - - IF (tmp > 0) - { - ind = sub(ind, 2); - tmp = sub(lsp, cos_table_129[ind]); - if (tmp > 0) - { - ind = sub(ind, 2); - } - tmp = sub(lsp, cos_table_129[ind+1]); - if (tmp <= 0) - { - ind = add(ind, 1); - } - tmp = sub(lsp, cos_table_129[ind]); - } - } - - /* acos(lsp)= ind*128 + (lsp-cos_table_129[ind]) * acos_slope[ind] / 2048 */ - L_tmp = L_mac(1L<<11, tmp, acos_slope[ind]); - L_tmp = L_shr(L_tmp, 12); /* (lsp-cos_table_129[ind]) * acos_slope[ind]) >> 11 */ - L_tmp = L_mac0(L_tmp, ind, 128); - - - return extract_l(L_tmp); -} - -/*-------------------------------------------------------------------* - * a2rc() - * - * Convert from LPC to reflection coeff - *-------------------------------------------------------------------*/ - -void a2rc_fx( const Word16* a, /* i: can be any Q */ - Word16* refl, /* o: Q15 */ - Word16 lpcorder - ) - -{ - Word16 f_fx[M]; - Word16 km_fx; - Word32 L_tmp1, L_tmp2; - Word16 tmp; - Word16 denom_mant, exp; - Word32 new_mant; - Word16 temp; - Word16 m, j, n; - Word16 q, q_a, q_a2, One_Qx; - Word32 One_Qx2; - q = add( norm_s(a[-1]), 1 ); - q_a = sub(15, q); - q_a2 = add(shl(q_a,1),1); - /* copy into internal vars so they can be changed */ - - FOR ( m = 0; m < lpcorder; m++ ) - { - /* f_fx[m] = p_fx[m]; */ - f_fx[m] = negate(a[m]); - move16(); - } - One_Qx = shl(1,q_a); - One_Qx2 = L_shl(1, q_a2); - FOR ( m = lpcorder - 1; m >= 0; m-- ) - { - km_fx = f_fx[m]; - move16(); - - test(); - IF ( sub( km_fx, negate(One_Qx)) <= 0 || sub( km_fx, One_Qx) >= 0 ) - { - FOR ( j = 0; j < lpcorder; j++ ) - { - refl[j] = 0; - move16(); - } - - return; - } - - refl[m] = negate( km_fx ); - move16(); - L_tmp1 = L_add(0,One_Qx2); /* 1 in 2xq_a+1 */ - L_tmp1 = L_msu( L_tmp1, km_fx, km_fx ); /* 1-km*km in Q25 */ - - /* new_mant = invert_dp(L_tmp1,4, &tmp_denom_exp,1); sum in Q61-Q25-n=Q36-n */ - exp = norm_l( L_tmp1 ); - tmp = extract_h( L_shl( L_tmp1, exp ) ); - exp = sub( sub( 30, exp ), q_a2 ); - IF ( tmp ) - { - tmp = div_s( 16384, tmp ); /* 15+exp */ - } - ELSE - { - tmp = 0; - } - new_mant = L_deposit_h( tmp ); - temp = round_fx( L_shl( new_mant, 0 ) ); /* in Q14 */ - denom_mant = temp; - move16(); - L_tmp1 = L_mult( km_fx, denom_mant ); /* km*denom. Q12*Q14 = Q27 */ - L_tmp1 = L_shl( L_tmp1, q ); /* change to Q31. simulation showed no overflow */ - tmp = round_fx( L_tmp1 ); /* extract in Q15 */ - - FOR ( j = 0; j < m / 2; j++ ) - { - n = sub( sub( m, ( Word16 )1 ), j ); - L_tmp1 = L_mult( denom_mant, f_fx[j] ); /* denom*f[j]. Q15*Q12 = Q28 (floating with exp) */ - L_tmp1 = L_mac( L_tmp1, tmp, f_fx[n] ); /* denom*f[j]+km*denom*f[n] in Q28 (floating with exp) */ - L_tmp2 = L_mult( denom_mant,f_fx[n] ); /* denom*f[n]. Q15*Q12 = Q28 (floating with exp) */ - L_tmp2 = L_mac( L_tmp2, tmp,f_fx[j] ); /* denom*f[n]+km*denom*f[j] in Q28 (floating with exp) */ - L_tmp1 = L_shr( L_tmp1, exp ); /* bringing to true Q28 */ - L_tmp2 = L_shr( L_tmp2, exp ); /* bringing to true Q28 */ - f_fx[j] = round_fx( L_tmp1 ); /* extracting in q_a */ - f_fx[n] = round_fx( L_tmp2 ); /* extracting in q_a */ - } - - IF ( m & 1 ) - { - L_tmp1 = L_mult( denom_mant, f_fx[ j] ); /* denom*f[j]. Q15*Q12 = Q28 (floating with exp) */ - L_tmp1 = L_mac( L_tmp1, tmp,f_fx[j] ); /* denom*f[j]+km*denom*f[j] in Q28 (floating with exp) */ - L_tmp1 = L_shr( L_tmp1, exp ); /* bringing to true Q28 */ - f_fx[j] = round_fx( L_tmp1 ); /* extracting in q_a */ - } - } - - FOR ( j = 0; j < lpcorder; j++ ) - { - refl[j] = shl( refl[j], q ); - move16(); - } - - - return; -} -Word16 vq_dec_lvq_fx ( - Word16 sf_flag, /* i : safety net flag */ - Word16 x[], /* o : Decoded vector Q(x2.56)*/ - Word16 indices[], /* i : Indices */ - Word16 stages, /* i : Number of stages */ - Word16 N, /* i : Vector dimension */ - Word16 mode, /* (i): mode_lvq, or mode_lvq_p */ - Word16 no_bits, /* (i): no. bits for lattice */ - Word32 *p_offset_scale1, - Word32 *p_offset_scale2, - Word32 *p_offset_scale1_p, - Word32 *p_offset_scale2_p, - Word16 *p_no_scales, - Word16 *p_no_scales_p -) -{ - Word16 x_lvq[M]; - Word16 i, stagesm1; - Word16 pt_fx; - Word16 ber_flag; - - /* clear vector */ - set16_fx(x, 0, N); - - /*-----------------------------------------------* - * add contribution of each stage - *-----------------------------------------------*/ - stagesm1 = sub(stages,1); - IF (sub(sf_flag,1) == 0) - { - FOR(i=0; i0) - { - IF (nbits0>0) - { - n_stages = 2; - move16(); - levels0[0] = CBsizes_fx[nbits0]; - move16(); - bits0[0] = nbits0; - move16(); - bits0[1] = sub(cumleft,nbits0); - - IF ( bits0[1] == 0 ) - { - n_stages = sub(n_stages,1); - } - ELSE - { - levels0[1] = CBsizes_fx[sub(cumleft,nbits0)]; - move16(); - } - } - ELSE /* no bits for VQ stage */ - { - n_stages = 0; - move16(); - } - - *stages0 = n_stages; - move16(); - IF (bits_lvq > 0) - { - bits0[n_stages] = bits_lvq; - move16(); - levels0[n_stages] = bits_lvq; - move16();/* this is number of bits, not levels */ - *stages0 = add(n_stages,1); - move16(); - } - } - ELSE - { - *stages0 = 0; - move16(); - } - - /*---------------------------------------------------* - * Calculate bit allocation for predictive quantizer - *---------------------------------------------------*/ - IF ( sub(framemode_p, -1)>0 ) - { - cumleft = BitsVQ_p_fx[framemode_p]; - move16(); - bits_lvq = sub(nBits, cumleft); - nbits0 = CBbits_p_fx[framemode_p]; - move16(); - - IF (sub(nbits0,-1) > 0) - { - IF ( nbits0 > 0 ) - { - IF ( sub(framemode_p, 7) == 0 ) - { - /* for UNVOICED_WB only */ - n_stages = 3; - move16(); - FOR( i=0; i0) - { - levels1[1] = CBsizes_fx[nbits0]; - move16(); - bits1[1] = nbits0; - move16(); - n_stages = 2; - move16(); - } - - levels1[n_stages] = bits_lvq; - move16();/* this is number of bits, not levels */ - bits1[n_stages] = bits_lvq; - move16(); - *stages1 = add(n_stages ,1); - } - } - ELSE - { - *stages1 = 1; - move16(); - bits1[0] = bits_lvq; - move16(); - levels1[0] = bits_lvq; - move16(); - } - } - ELSE - { - } - } - - return; -} - -Word16 find_pred_mode( - const Word16 coder_type, /* i: coding type */ - const Word16 bwidth, /* i: bandwidth index */ - const Word32 int_fs, /* i: sampling frequency */ - Word16 * p_mode_lvq, /* o: index of LSF codebooks in safety net mode */ - Word16 * p_mode_lvq_p, /* o: index of LSF codebooks in predictive mode (AR or MA) */ - Word32 core_brate) /* i: core bit rate */ -{ - Word16 idx, predmode; - - /* bwidth = 0(NB), 1 (WB), 2(WB2); line index in predmode_tab[][] */ - idx = bwidth; - move16(); - if (sub(idx, 1) >0) - { - idx = 1; - } - IF (L_sub(int_fs, INT_FS_16k) == 0) - { - /* WB2 is actually used if sampling frequency is 16kHz */ - idx = 2; - move16(); - } - ELSE - { - test(); - test(); - if ((L_sub(core_brate, GENERIC_MA_LIMIT) >= 0)&&(sub(coder_type, GENERIC) == 0)&&(sub(idx,1) == 0)) - { - idx = 3; - move16(); - } - } - predmode = predmode_tab[idx][coder_type]; - move16(); - IF (sub(idx, 2) <= 0) - { - *p_mode_lvq = add(i_mult2(NO_CODING_MODES, idx), coder_type); - IF (predmode>0) - { - *p_mode_lvq_p = *p_mode_lvq; - move16(); - } - ELSE - { - *p_mode_lvq_p = -1; - move16(); - } - } - ELSE /* WB 12.8 with MA pred in GENERIC*/ - { - *p_mode_lvq = add(NO_CODING_MODES, coder_type); - IF (sub(coder_type, GENERIC) == 0) - { - *p_mode_lvq_p = 18; - move16(); - } - ELSE - { - IF (predmode>0) - { - *p_mode_lvq_p = *p_mode_lvq; - } - ELSE - { - *p_mode_lvq_p = -1; - } - } - } - - - - return predmode; -} - -/*---------------------------------------------------------------------------* - * reorder_isf - * - * To make sure that the isfs are properly ordered and to keep a certain - * minimum distance between consecutive isfs. - *--------------------------------------------------------------------------*/ -void reorder_isf_fx( - Word16 *isf, /* i/o: ISFs in the frequency domain (0..0.5) */ - const Word16 min_dist, /* i : minimum required distance */ - const Word16 n, /* i : LPC order */ - const Word16 fs /* i : sampling frequency */ -) -{ - Word16 i, isf_min; - Word16 isf_max; - - isf_min = min_dist; - move16(); - - /*-----------------------------------------------------------------------* - * Verify the ISF ordering and minimum GAP - *-----------------------------------------------------------------------*/ - - FOR (i = 0; i < n - 1; i++) - { - if (sub(isf[i], isf_min) < 0) - { - isf[i] = isf_min; - move16(); - } - isf_min = add(isf[i], min_dist); - } - - /*-----------------------------------------------------------------------* - * Reverify the ISF ordering and minimum GAP in the reverse order (security) - *-----------------------------------------------------------------------*/ - - /*isf_max = sub(shr(fs,1), min_dist);*/ - isf_max = sub(fs, min_dist); /* Fs already divide per 2 */ - - IF (sub(isf[n-2], isf_max) > 0) /* If danger of unstable filter in case of resonance in HF */ - { - FOR (i = sub(n, 2); i >= 0; i--) /* Reverify the minimum ISF gap in the reverse direction */ - { - if (sub(isf[i], isf_max) > 0) - { - isf[i] = isf_max; - move16(); - } - isf_max = sub(isf[i], min_dist); - } - } -} - -/*========================================================================*/ -/* FUNCTION : lsf_stab_fx() */ -/*------------------------------------------------------------------------*/ -/* PURPOSE : Check LSF stability (distance between old LSFs and */ -/* current LSFs) */ -/*------------------------------------------------------------------------*/ -/* INPUT ARGUMENTS : */ -/* _ (Word16) Opt_AMR_WB : flag indicating AMR-WB IO mode */ -/* _ (Word16*) lsf : LSPs from past frame Q(x2.56) */ -/* _ (Word16*) lsfold : LSPs from past frame Q(x2.56) */ -/*------------------------------------------------------------------------*/ -/* INPUT/OUTPUT ARGUMENTS : */ -/*------------------------------------------------------------------------*/ -/* OUTPUT ARGUMENTS : */ -/*------------------------------------------------------------------------*/ - -/*------------------------------------------------------------------------*/ -/* RETURN ARGUMENTS : */ -/* _ (Word16) stab_fac_fx : LP filter stability Q15 */ -/*========================================================================*/ -Word16 lsf_stab_fx( /* o : LP filter stability Q15*/ - const Word16 *lsf, /* i : LSF vector Q(x2.56)*/ - const Word16 *lsfold, /* i : old LSF vector Q(x2.56)*/ - const Word16 Opt_AMR_WB, /* i : flag indicating AMR-WB IO mode */ - const Word16 L_frame /* i : frame length */ -) -{ - Word16 i, m; - Word32 L_tmp; - Word16 tmp, e; - - /*-------------------------------------------------------------------* - * Check stability on lsf: distance between old lsf and current lsf - *-------------------------------------------------------------------*/ - IF ( Opt_AMR_WB ) - { - m = M-1; - move16(); - tmp = sub(lsf[0], lsfold[0]); - L_tmp = L_mult(tmp, tmp); /* Q1 */ - FOR (i = 1; i < m; i++) - { - tmp = sub(lsf[i], lsfold[i]); - L_tmp = L_mac(L_tmp, tmp, tmp); /* Q1 */ - } - } - ELSE - { - m = M; - move16(); - L_tmp = 0; - move32(); - FOR (i = 0; i < m; i++) - { - tmp = sub(lsf[i], lsfold[i]); - L_tmp = L_mac(L_tmp, tmp, tmp); /* Q1 */ - } - } - - e = norm_l(L_tmp); - L_tmp = L_shl(L_tmp, e); /*Q(1+e)*/ - - IF( L_frame == L_FRAME16k) - { - /*stab_fac = (float)(1.25f - (tmp/625000.0f));*/ - L_tmp = Mpy_32_16_1(L_tmp, 16777); /* 30-eQ(1+e)*-21Q36 = 30-21-eQ31-9+e */ - } - ELSE - { - /* stab_fac = (float)(1.25f - (tmp1/400000.0f*2.56=1024000)) */ - L_tmp = Mpy_32_16_1(L_tmp, 26214); /* 30-eQ(1+e)*-21Q36 = 30-21-eQ31-9+e */ - } - - e = sub(30-21-1,e); - tmp = round_fx(L_shl(L_tmp, e)); /*Q14*/ - - tmp = sub(20480, tmp); /* 1.25 - tmp in Q14 */ - tmp = shl(tmp, 1); /* Q14 -> Q15 with saturation */ - - tmp = s_max(tmp, 0); - - return tmp; -} -/*-------------------------------------------------------------------* - * lsp2isp() - * - * Convert LSPs to ISPs via predictor coefficients A[] - *-------------------------------------------------------------------*/ - -void lsp2isp_fx( - const Word16 *lsp, /* i : LSP vector */ - Word16 *isp, /* o : ISP filter coefficients */ - Word16 *stable_isp, /* i/o: ISP filter coefficients */ - const Word16 m /* i : order of LP analysis */ -) -{ - Word16 a[M+1]; - - /* LSP --> A */ - /*lsp2a_stab( lsp, a, m );*/ - E_LPC_f_lsp_a_conversion(lsp, a, m ); - - /* A --> ISP */ - /*a2isp( a, isp, stable_isp, grid );*/ - E_LPC_a_isp_conversion( a, isp, stable_isp, m); - - /* Update to latest stable ISP */ - Copy( isp, stable_isp, M ); -} -/*-------------------------------------------------------------------* - * isp2lsp() - * - * Convert ISPs to LSPs via predictor coefficients A[] - *-------------------------------------------------------------------*/ - -void isp2lsp_fx( - const Word16 *isp, /* i : LSP vector */ - Word16 *lsp, /* o : ISP filter coefficients */ - Word16 *stable_lsp, /* i/o: stable LSP filter coefficients */ - const Word16 m /* i : order of LP analysis */ -) -{ - Word16 a[M+1]; - - /* ISP --> A */ - /*isp2a( isp, a, m );*/ - E_LPC_f_isp_a_conversion(isp, a, m ); - /* A --> LSP */ - /*a2lsp_stab( a, lsp, stable_lsp, grid );*/ - E_LPC_a_lsp_conversion(a, lsp, stable_lsp, m ); - /* Update to latest stable LSP */ - Copy( lsp, stable_lsp, M ); -} - -/*-------------------------------------------------------------------* - * lsf2isf() - * - * Convert LSPs to ISPs - *-------------------------------------------------------------------*/ - -void lsf2isf_fx( - const Word16 *lsf, /* i : LSF vector */ - Word16 *isf, /* o : ISF vector */ - Word16 *stable_isp, /* i/o: stable ISP filter coefficients */ - const Word16 m /* i : order of LP analysis */ -) -{ - Word16 tmp_lsp[M]; - Word16 tmp_isp[M]; - - /* LSF --> LSP */ - /*lsf2lsp( lsf, tmp_lsp, m, int_fs );*/ - E_LPC_lsf_lsp_conversion(lsf, tmp_lsp, m); - - /* LSP --> ISP */ - lsp2isp_fx( tmp_lsp, tmp_isp, stable_isp, m ); - - /* ISP --> ISF */ - /*isp2isf( tmp_isp, isf, m, int_fs );*/ - E_LPC_isp_isf_conversion(tmp_isp, isf, m); - - return; -} -/*-------------------------------------------------------------------* - * isf2lsf() - * - * Convert ISFs to LSFs - *-------------------------------------------------------------------*/ - -void isf2lsf_fx( - const Word16 *isf, /* i : ISF vector */ - Word16 *lsf, /* o : LSF vector */ - Word16 *stable_lsp /* i/o: stable LSP filter coefficients */ -) -{ - Word16 tmp_isp[M]; - Word16 tmp_lsp[M]; - - /* ISF --> ISP */ - /*isf2isp( isf, tmp_isp, m, int_fs );*/ - E_LPC_isf_isp_conversion(isf, tmp_isp, M); - /* ISP --> LSP */ - isp2lsp_fx( tmp_isp, tmp_lsp, stable_lsp, M); - - /* LSP --> LSF */ - /*lsp2lsf( tmp_lsp, lsf, m, int_fs );*/ - E_LPC_lsp_lsf_conversion(tmp_lsp, lsf, M); - return; -} -/*==========================================================================*/ -/* FUNCTION : void lsp2lsf_fx () */ -/*--------------------------------------------------------------------------*/ -/* PURPOSE : */ -/* * Transformation of LSPs to LSFs */ -/* * LSP are line spectral pair in cosine domain (-1 to 1). */ -/* * LSF are line spectral frequencies (0 to fs/2). */ -/*--------------------------------------------------------------------------*/ -/* INPUT ARGUMENTS : */ -/* Word16 lsp[] i : lsp[m] (range: -1<=val<1) Q15 */ -/* Word16 m i : LPC order Q0 */ -/*--------------------------------------------------------------------------*/ -/* OUTPUT ARGUMENTS : */ -/* Word16 lsf[] o : lsf[m] normalized (range: 0.0<=val<=0.5) Q(x2.56)*/ -/*--------------------------------------------------------------------------*/ -/* INPUT/OUTPUT ARGUMENTS : */ -/*--------------------------------------------------------------------------*/ -/* RETURN ARGUMENTS : */ -/* _ None */ -/*--------------------------------------------------------------------------*/ -/* CALLED FROM : */ -/*==========================================================================*/ -void lsp2lsf_fx( - const Word16 lsp[], /* i : lsp[m] (range: -1<=val<1) Q15*/ - Word16 lsf[], /* o : lsf[m] normalized (range: 0.0<=val<=0.5) Q(x2.56)*/ - const Word16 m /* i : LPC order Q0*/ - ,Word32 int_fs -) -{ - Word16 i; - Word32 L_tmp; - - FOR (i = 0; i < m; i++) - { - /*------------------------------------------------------* - * find value in table that is just greater than lsp[i] - *------------------------------------------------------*/ - - /* Retrieve Index Guess */ - /* Based on lsp[i] */ - L_tmp = sub_lsp2lsf_fx(lsp[i]); - IF(L_sub(int_fs, INT_FS_16k_FX) ==0) - { - L_tmp = L_shr(L_mult0(extract_l(L_tmp),5),2); - } - lsf[i] = extract_l(L_tmp); - } -} -/*===========================================================================*/ -/* FUNCTION : lsf2lsp_fx() */ -/*---------------------------------------------------------------------------*/ -/* PURPOSE : Transformation of LSFs to LSPs */ -/* LSP are line spectral pairs in cosine domain (-1 to 1). */ -/* LSF are line spectral frequencies (0 to fs/2). */ -/*---------------------------------------------------------------------------*/ -/* INPUT ARGUMENTS : */ -/* _ (Word16[]) lsf : lsf[m] normalized (range: 0.0<=val<=0.5) Q(x2.56) */ -/* _ (Word16) m : LPC order */ -/*---------------------------------------------------------------------------*/ -/* OUTPUT ARGUMENTS : */ -/* _ (Word16*) lsp : lsp[m] (range: -1<=val<1) Q15 */ -/*---------------------------------------------------------------------------*/ - -/*---------------------------------------------------------------------------*/ -/* RETURN ARGUMENTS : */ -/* _ None */ -/*===========================================================================*/ -void lsf2lsp_fx( - const Word16 lsf[], /* i : lsf[m] normalized (range: 0.0<=val<=0.5) x2.56 */ - Word16 lsp[], /* o : lsp[m] (range: -1<=val<1) Q15 */ - const Word16 m /* i : LPC order Q0 */ - , Word32 int_fs -) -{ - Word16 i, ind, offset; - Word32 L_tmp; - Word16 c, ind2; - Word16 const add_prec = 4; - Word16 lsf_tmp; - - - /* 0.75 = (1< 0) - { - FOR (i = 0; i < 8; i++) - { - error_svq_q_fx[i] = AR_SVQ_CB1_fx[indice[10]][i]; - move16(); - error_svq_q_fx[i+8] = AR_SVQ_CB2_fx[indice[11]][i]; - move16(); - } - - FOR (i = 0; i < M; i++) - { - y_fx[i] = add(y_fx[i], extract_h(L_shl(L_mult0(error_svq_q_fx[i], scale_ARSN_fx[i]), 2))); - move16(); - } - } - } - ELSE - { - tcvq_Dec_fx(&indice[1], /*y, */y_fx, safety_net); - - IF (sub(nBits, 30) > 0) - { - FOR (i = 0; i < 8; i++) - { - error_svq_q_fx[i] = AR_SVQ_CB1_fx[indice[10]][i]; - move16(); - error_svq_q_fx[i+8] = AR_SVQ_CB2_fx[indice[11]][i]; - move16(); - } - - FOR (i = 0; i < M; i++) - { - y_fx[i] = add(y_fx[i], error_svq_q_fx[i]); - move16(); - } - } - } - - return safety_net; -} - -/*======================================================================*/ -/* FUNCTION : lsf_syn_mem_backup_fx */ -/*----------------------------------------------------------------------*/ -/* PURPOSE : back-up synthesis filter memory and LSF qunatizer memories */ -/*----------------------------------------------------------------------*/ -/* INPUT ARGUMENTS : */ -/* _ (Word16*) lsp_new : LSP vector to quantize */ -/* _ (Word16*) lsf_new : quantized LSF vector */ -/* _ (Word16*) lsp_mid : mid-frame LSP vector */ -/* _ (Encoder_State_fx) st_fx : Encoder state Structure */ -/*-----------------------------------------------------------------------*/ -/* INPUT/OUTPUT ARGUMENTS : */ -/* _None */ -/*-----------------------------------------------------------------------*/ -/* OUTPUT ARGUMENTS : */ -/* _ (Word16) clip_var : pitch clipping state var */ -/* _ (Word16*) mem_AR : quantizer memory for AR model */ -/* _ (Word16*) mem_MA : quantizer memory for MA model */ -/* _ (Word16*) lsp_new_bck : LSP vector to quantize- backup */ -/* _ (Word16*) lsf_new_bck : quantized LSF vector - backup */ -/* _ (Word16*) lsp_mid_bck : mid-frame LSP vector - backup */ -/* _ (Word16) mCb1 :counter for stationary frame after a transition frame */ -/* _ (Word32*) Bin_E : FFT Bin energy 128 *2 sets */ -/* _ (Word32*) Bin_E_old : FFT Bin energy 128 *2 sets */ -/* _ (Word16*) mem_syn_bck : synthesis filter memory */ -/* _ (Word16) mem_w0_bck : memory of the weighting filter */ -/* _ (Word16) streaklimit : LSF quantizer */ -/* _ (Word16) pstreaklen : LSF quantizer */ -/*-----------------------------------------------------------------------*/ - -/* _ None */ -/*-----------------------------------------------------------------------*/ -/* RETURN ARGUMENTS : */ -/* _ None */ -/*=======================================================================*/ - -void lsf_syn_mem_backup_fx( - Encoder_State_fx *st_fx, /* i: state structure */ - LPD_state* LPDmem, /* i: LPD state memory structure */ - Word16 *btilt_code_fx, /* i: tilt code */ - Word32 *gc_threshold_fx, /* i: */ - Word16 *clip_var_bck_fx, /* o: */ - Word16 *next_force_sf_bck_fx, /* o: */ - - Word16 *lsp_new, /* i: LSP vector to quantize */ - Word16 *lsf_new, /* i: quantized LSF vector */ - Word16 *lsp_mid, /* i: mid-frame LSP vector */ - Word16 *clip_var, /* o: pitch clipping state var */ - Word16 *mem_AR, /* o: quantizer memory for AR model */ - Word16 *mem_MA, /* o: quantizer memory for AR model */ - Word16 *lsp_new_bck, /* o: LSP vector to quantize- backup */ - Word16 *lsf_new_bck, /* o: quantized LSF vector - backup */ - Word16 *lsp_mid_bck, /* o: mid-frame LSP vector - backup */ - Word16 *mCb1, /* o: counter for stationary frame after a transition frame */ - Word32 *Bin_E, /* o: FFT Bin energy 128 *2 sets */ - Word32 *Bin_E_old, /* o: FFT Bin energy 128 sets */ - Word16 *mem_syn_bck, /* o: synthesis filter memory */ - Word16 *mem_w0_bck, /* o: memory of the weighting filter */ - Word16 *streaklimit, - Word16 *pstreaklen -) -{ - Word16 i; - - *clip_var = st_fx->clip_var_fx[0]; - move16(); - - FOR(i=0; imem_AR_fx[i]; - move16(); - mem_MA[i] = st_fx->mem_MA_fx[i]; - move16(); - lsp_new_bck[i] = lsp_new[i]; - move16(); - lsf_new_bck[i] = lsf_new[i]; - move16(); - lsp_mid_bck[i] = lsp_mid[i]; - move16(); - } - - *mCb1 = st_fx->mCb1_fx; - move16(); - *streaklimit = st_fx->streaklimit_fx; - move16(); - *pstreaklen = st_fx->pstreaklen_fx; - move16(); - - FOR(i=0; iBin_E_fx[i]; - move32(); - } - - FOR(i=0; i<(L_FFT/2); i++) - { - Bin_E_old[i]=st_fx->Bin_E_old_fx[i]; - move32(); - } - - /* back-up memories */ - FOR(i=0; iLPDmem.mem_syn[i]; - move16(); - } - - *mem_w0_bck = st_fx->LPDmem.mem_w0; - move16(); - - - *btilt_code_fx = LPDmem->tilt_code; - *gc_threshold_fx = LPDmem->gc_threshold; - Copy( st_fx->clip_var_fx, clip_var_bck_fx, 6 ); - *next_force_sf_bck_fx = st_fx->next_force_safety_net_fx; - - - return; -} - -void lsf_update_memory( - Word16 narrowband, /* i : narrowband flag */ - const Word16 qlsf[], /* i : quantized lsf coefficients */ - Word16 old_mem_MA[], /* i : MA memory */ - Word16 mem_MA[], /* o : updated MA memory */ - Word16 lpcorder /* i : LPC order */ -) -{ - Word16 i; - - FOR (i=0; iclip_var_fx[0] = clip_var; - move16(); - - FOR(i=0; imem_AR_fx[i] = mem_AR[i]; - move16(); - st_fx->mem_MA_fx[i] = mem_MA[i]; - move16(); - lsp_new[i] = lsp_new_bck[i]; - move16(); - lsf_new[i] = lsf_new_bck[i]; - move16(); - lsp_mid[i] = lsp_mid_bck[i]; - move16(); - } - - st_fx->mCb1_fx = mCb1; - move16(); - st_fx->streaklimit_fx = streaklimit; - move16(); - st_fx->pstreaklen_fx = pstreaklen; - move16(); - - FOR(i=0; iBin_E_fx[i] = Bin_E[i]; - move16(); - } - - FOR(i=0; i<(L_FFT/2); i++) - { - st_fx->Bin_E_old_fx[i]=Bin_E_old[i]; - move32(); - } - - /* restoring memories */ - st_fx->LPDmem.mem_w0 = mem_w0_bck; - move16(); - - FOR(i=0; iLPDmem.mem_syn[i] = mem_syn_bck[i]; - move16(); - } - - move16(); - move32(); - move16(); - LPDmem->tilt_code = btilt_code_fx; - LPDmem->gc_threshold = gc_threshold_fx; - Copy( clip_var_bck_fx, st_fx->clip_var_fx, 6 ); - st_fx->next_force_safety_net_fx = next_force_sf_bck_fx; - - return; -} - -/* Returns: codebook index */ -Word16 tcxlpc_get_cdk( - Word16 acelp_ext_mode /* (I) GC/VC indicator */ -) -{ - Word16 cdk; - - move16(); - cdk = 0; - if ( sub(acelp_ext_mode, VOICED) == 0 ) - { - cdk = 1; - move16(); - } - - return cdk; -} - -void msvq_dec -( - const Word16 *const*cb, /* i : Codebook (indexed cb[*stages][levels][p]) (14Q1*1.28)*/ - const Word16 dims[], /* i : Dimension of each codebook stage (NULL: full dim.) */ - const Word16 offs[], /* i : Starting dimension of each codebook stage (NULL: 0) */ - const Word16 stages,/* i : Number of stages */ - const Word16 N, /* i : Vector dimension */ - const Word16 maxN, /* i : Codebook dimension */ - const Word16 Idx[], /* i : Indices */ - Word16 *uq /* o : quantized vector (14Q1*1.28)*/ -) -{ - Word16 i,j,offset; - Word16 N34; - Word16 n, maxn, start; - - - - set16_fx(uq, 0, N); - - FOR ( i=0; i lsp[i] */ - tmp = sub(lsp_i, cos_table_129[ind]); - /* - 69%: (Final Index - Index Guess) is <= 1 - 28%: (Final Index - Index Guess) is 2 - 2%: (Final Index - Index Guess) is >= 3 - <1%: ... - */ - IF (tmp > 0) /* possible range 0 to -5 (-1-2-2) */ - { - ind = sub(ind, 1); - tmp = sub(lsp_i, cos_table_129[ind]); - IF (tmp > 0) - { - ind = sub(ind, 2); - tmp = sub(lsp_i, cos_table_129[ind]); - if (tmp > 0) - { - ind = sub(ind, 2); - } - tmp = sub(lsp_i, cos_table_129[ind+1]); - if (tmp <= 0) - { - ind = add(ind, 1); - } - tmp = sub(lsp_i, cos_table_129[ind]); - } - } - - /* acos(lsp[i])= ind*128 + (lsp[i]-table[ind]) * acos_slope[ind] / 2048 */ - L_tmp = L_mac(1L<<11, tmp, acos_slope[ind]); - L_tmp = L_shr(L_tmp, 12); /* (lsp[i]-table[ind]) * acos_slope[ind]) >> 11 */ - L_tmp = L_mac0(L_tmp, ind, 128); - - return L_tmp; -} - -/*===================================================================*/ -/* FUNCTION : compute_poly_product_fx () */ -/*-------------------------------------------------------------------*/ -/* PURPOSE : Compute polynomial product for P(z) for LSP */ -/* to LPC conversion */ -/*-------------------------------------------------------------------*/ -/* INPUT ARGUMENTS : */ -/* _ (Word16[]) coef : LSP coefficients, Q15 */ -/* _ (Word16 []) order: LPC order */ -/*-------------------------------------------------------------------*/ -/* OUTPUT ARGUMENTS : */ -/* _ (Word32[]) p : output sequence, Q24 */ -/* 1st entry is always 1.0, Q24 */ -/*-------------------------------------------------------------------*/ -/* INPUT/OUTPUT ARGUMENTS : */ -/* _ None */ -/*-------------------------------------------------------------------*/ -/* RETURN ARGUMENTS : */ -/* _ None */ -/*===================================================================*/ -/* NOTE: */ -/* P(z)=(1+z^-1)*PI(j=1to(order/2)) (1 - 2*z^-1*cos(2*pi*w(2j-1)) + z^-2) */ -/* Q(z)=(1-z^-1)*PI(j=1to(order/2)) (1 - 2*z^-1*cos(2*pi*w(2j)) + z^-2) */ -/*===================================================================*/ -void compute_poly_product_fx( - Word16* coef, /* i : LSP coefficients, Q15 */ - Word32* p, /* o : output sequence, Q24 */ - Word16 order /* i : order */ -) -{ - Word16 i, len; - Word32 lspcos[LPC_SHB_ORDER]; - Word32 p2[LPC_SHB_ORDER]; /* intermediate product, Q24*/ - Word32* p_in, *p_out, *p_temp; - - FOR ( i = 0; i < order / 2; i++ ) - { - lspcos[i] = poscos_fx( coef[i * 2] ); - move32(); /* lspcos =-cos(lsp) in Q30*/ - } - - /* Set up first polynomial for convolution (1 -2cos(w5) 1) */ - /* First element of output is 1, all in Q24 */ - p[0] = L_deposit_h( 0x100 ); /* 1.0 in Q24 */ - p[2] = L_deposit_h( 0x100 ); /* 1.0 in Q24 */ - p[1] = L_shr( lspcos[order / 2 - 1], 5 ); /* p2[1]=-2cos(w5), Q24 */ - p2[0] = L_deposit_h( 0x100 ); /* 1.0 in Q24 */ - - len = 1; - move16(); - - len = 1; - p_in = p + 1; /* 2nd entry of input sequence */ - p_out = p2 + 1; /* 2nd entry of output sequence */ - FOR ( i = 0; i < ( order / 2 - 1 ); i++ ) - { - lsp_convolve_fx( L_shr( lspcos[i], 5 ), p_in, p_out, len ); - - p_temp = p_in; - p_in = p_out; - p_out = p_temp; /* swap input/output buffer */ - len = add( len, 1 ); - } - - /* if((order/2 - 1)%2 != 0) */ - IF ( s_and( ( order / 2 - 1 ), 1 ) != 0 ) - { - FOR ( i = 1; i <= order / 2; i++ ) - { - p[i] = p_in[i - 1]; - move32(); - } - } - -} - -/*===================================================================*/ -/* FUNCTION : lsp_convolve_fx ( ) */ -/*-------------------------------------------------------------------*/ -/* PURPOSE : Convolution of LSP polynomial for LSP to LPC */ -/*-------------------------------------------------------------------*/ -/* INPUT ARGUMENTS : */ -/* _ ( Word32[]) p1 : 2nd entry of input sequence, Q24 */ -/* 1st entry is 1.0, Q24 */ -/* _ ( Word32) x : -2cos( w) in Q24 */ -/* _ ( Word16) len: length of output-2 */ -/*-------------------------------------------------------------------*/ -/* OUTPUT ARGUMENTS : */ -/* _ ( Word32[]) p2 : 2nd entry of output sequence, Q24 */ -/* 1st entry is 1.0, Q24 */ -/*-------------------------------------------------------------------*/ -/* INPUT/OUTPUT ARGUMENTS : */ -/* _ None */ -/*-------------------------------------------------------------------*/ -/* RETURN ARGUMENTS : */ -/* _ None */ -/*===================================================================*/ -/* NOTE: Convolves ( 1 S 1) where S is the -2cos( w) value) with the */ -/* long sequence where the input long sequence on consecutive calls */ -/* is ( 1 X1 1), ( 1 X1 X2 X1), ( 1 X1 X2 X3 X2), ( 1 X1 X2 X3 X4 X3). */ -/* ( Since the sequence is symmetric, we only need to output one */ -/* entry beyond the center point for the next iteration). */ -/* The 1st entry of the convolution is 1, the 2nd is X1+S1, and */ -/* the rest have the form X( i-1) + X( i)*S + X( i+1). */ -/* Final output sequence is ( 1 X1 X2 X3 X4 X5 X4) */ -/*===================================================================*/ -void lsp_convolve_fx( - Word32 x, - Word32* p1, - Word32* p2, - Word16 len -) -{ - Word16 i, d1h, d1l, d2h, d2l; - Word32 Ltemp; - Word32 Lacc; - - d1h = extract_h( x ); /* d1h in Q8 */ - d1l = extract_l( x ); /* d1l in Q24 */ - - Ltemp = L_add( x, p1[0] ); /* first output is p1[0]+x, Q24 */ - - p2[0] = Ltemp; - move32(); - Ltemp = L_deposit_h( 0x100 ); /* Ltemp=1.0, Q24 */ - FOR ( i = 0; i < len; i++ ) - { - Ltemp = L_add( Ltemp, p1[i + 1] ); /* Ltemp2=p1[i-1]+p1[i+1], Q24 */ - d2h = extract_h( p1[i] ); - d2l = extract_l( p1[i] ); - - /* Lacc=L_mult_su( d1h,d2l); */ - Lacc = L_mult0( d1h, ( UWord16 )d2l ); - Lacc = L_mac0( Lacc, d2h, d1l ); - Lacc = L_add( L_shr( Lacc, 16 ), L_shr( L_mult( d1h, d2h ), 1 ) ); - /* Lacc=p1[i]* x, Q16 */ - Lacc = L_add( L_shl( Lacc, 8 ), Ltemp ); /* Lacc=p1[i-1]+p1[i+1]+p1[i]*x, Q24 */ - - p2[i + 1] = Lacc; - move32(); - - Ltemp = L_add(0,p1[i]); - } /* end for */ - - p2[i + 1] = p2[i - 1]; - move32(); -} - - - -/*===================================================================*/ -/* FUNCTION : poscos_fx ( ) */ -/*-------------------------------------------------------------------*/ -/* PURPOSE : Compute cosine by approximation */ -/*-------------------------------------------------------------------*/ -/* INPUT ARGUMENTS : */ -/* */ -/* _ ( Word16) w: angle in radians/pi, Q14 ( 0<=w<=16384) */ -/*-------------------------------------------------------------------*/ -/* OUTPUT ARGUMENTS : */ -/* _ None */ -/*-------------------------------------------------------------------*/ -/* INPUT/OUTPUT ARGUMENTS : */ -/* _ None */ -/*-------------------------------------------------------------------*/ -/* RETURN ARGUMENTS : */ -/* _ ( Word32) : -cos( w) in Q30 */ -/*===================================================================*/ -/* NOTE: This function uses 4 coefficients in the approx formula */ -/* Approx Formula: cos( w) = z + c1*z^3 + c2*z^5 + c3*z^7 + c4*z^9 */ -/* where z = pi/2 - w, c1=-.1666665668, c2=.8333025139E-2, */ -/* c3=-.198074182E-3, and c4=.2601903036E-5 */ -/*===================================================================*/ - - -Word32 poscos_fx( Word16 w ) -{ - Word16 a, z, z2, z3, z5, z7, z9; - Word32 Ltemp; - Word32 Lacc; - - IF ( w == 0 ) - { - return ( 0xc0000004 ); /* -1.0 in Q30 */ - } - ELSE - { - z = 0x2000; - move16(); /* z=0.5 in Q14 */ - z = shl( sub( z, w ), 2 ); /* z = 0.5-w in Q16 */ - - a = 0x6488; - move16(); /* a=pi in Q13 */ - z = mult_r( z, a ); /* z=pi*( 0.5-w), Q14 */ - z2 = mult_r( z, z ); /* z2=z^2, Q13 */ - z3 = round_fx( L_shl( L_mult0( z, z2 ), 0 ) ); /* z3=z^3, Q11 */ - z5 = mult_r( z2, z3 ); /* z5=z^5, Q9 */ - z7 = round_fx( L_shl( L_mult0( z2, z5 ), 0 ) ); /* z7=z^7, Q6 */ - z9 = round_fx( L_shl( L_mult0( z2, z7 ), 0 ) ); /* z9=z^9, Q3 */ - - Lacc = L_mult( z9, cos_coef_new[0] ); /* Lacc=c4*z^9, Q31, c4 in Q28 */ - Lacc = L_mac0( Lacc, z7, cos_coef_new[1] ); /* c3 in Q25 */ - Ltemp = L_shl( L_mult( z3, cos_coef_new[3] ), 1 ); /* Ltemp=c1*z^3, Q31, c1 in Q17 */ - Lacc = L_add( L_shr( Lacc, 1 ), Ltemp ); /* Lacc=c1*z^3+c3*z^7+c4*^z9, Q30 */ - Lacc = L_add( Lacc, L_deposit_h( z ) ); - Ltemp = L_mult( z5, cos_coef_new[2] ); /* Ltemp=-c2*z^5, Q29, cos_coef[2]=-c2 in Q19 */ - Lacc = L_sub( Lacc, L_shl( Ltemp, 1 ) ); /* Lacc=cos( w) in Q30 */ - - return L_negate( Lacc ); /* return -cos( w), Q30 */ - } /* end else */ -} -/*===================================================================*/ -/* FUNCTION : root_search_fx ( ) */ -/*-------------------------------------------------------------------*/ -/* PURPOSE : Search root of the P or Q polynomial in a given */ -/* interval using binary search */ -/*-------------------------------------------------------------------*/ -/* INPUT ARGUMENTS : */ -/* _ ( Word16) low : Low index of the interval, Q9 ( 0-511) */ -/* _ ( Word16) high : High index of the interval, Q9 ( 0-511) */ -/* _ ( Word32 []) coef: polynomial coefficients, Q26 */ -/* _ ( Word16) order : LPC order */ -/*-------------------------------------------------------------------*/ -/* OUTPUT ARGUMENTS : */ -/* _ None */ -/*-------------------------------------------------------------------*/ -/* INPUT/OUTPUT ARGUMENTS : */ -/* _ ( Word32) v_low: Polynomial value at low index, Q25 */ -/*-------------------------------------------------------------------*/ -/* RETURN ARGUMENTS : */ -/* _ ( Word16) root in Q15, or 0xffff if no root is found */ -/*===================================================================*/ - -Word16 root_search_fx( Word16 low, - Word16 high, - Word32* v_low, - Word32* coef, - Word16 order - ) -{ - Word16 f; - Word32 v_high, vh; - Word32 Ltemp, L_tmp1, L_tmp, Ltmp; - Word16 exp1, tmp; - - v_high = polynomial_eval_fx( high, coef, order ); /* v_high has the value at high index */ - - IF ( v_high != 0 ) - { - /* No exact root found */ - test(); - IF ( ( v_high ^ ( *v_low ) ) >= 0 ) - { - /* No root in this interval ( low high] */ - *v_low = v_high; - move32(); - return ( -1 ); - } - ELSE - { - /* there is a root in this interval */ - /* Do binary search for root */ - vh = v_high; - move16(); - - WHILE ( sub( sub( high, low ), 2 ) >= 0 ) - { - /* high-low>=2 */ - f = shr( add( high, low ), 1 ); /* f=( high+low)/2 */ - Ltemp = polynomial_eval_fx( f, coef, order ); - IF ( Ltemp == 0 ) - { - *v_low = v_high; - move32();/* Set low value for next root search call */ - return ( shl( f, 6 ) ); - } - ELSE - { - test(); - IF ( ( Ltemp ^ ( *v_low ) ) < 0 ) - { - /* root between f & low */ - high = f; - move16(); - vh = L_add(0,Ltemp); - } - ELSE - { - *v_low = Ltemp; - move32(); - low = f; - move16(); - } - } - } /* end while */ - - /* do interpolation for root in between high and low */ - /* Lacc=divide_dp( *v_low, L_sub( *v_low,vh),2,1); // Lacc in Q31 */ - L_tmp = L_sub( *v_low, vh ); - - if ( L_sub( *v_low, vh ) < 0 ) - { - L_tmp = L_negate( L_tmp ); - } - - exp1 = norm_l( L_tmp ); - L_tmp1 = L_shl( L_tmp, exp1 ); - tmp = extract_h( L_tmp1 ); - exp1 = sub(30 - 25, exp1); - tmp = div_s( 16384, tmp ); /* 15+exp1 */ - Ltmp = Mult_32_16( *v_low, tmp ); /* 15+exp1+25-15 */ - Ltemp = L_shl( Ltmp, ( 6 - exp1 ) ); /* Q31 */ - if ( L_sub( *v_low, vh ) < 0 ) - { - Ltemp = L_negate( Ltemp ); - } - Ltemp = L_shr( Ltemp, 9 ); /* Ltemp =quotient*1.0 in Q31 */ - - *v_low = v_high; - move16(); - return ( add( round_fx( Ltemp ), shl( low, 6 ) ) ); - } /* end else ( root in interval) */ - } /* end else ( exact root at high) */ - - /* find the exact root */ - *v_low = v_high; - move32(); /* Set low value for next root search call */ - return ( shl( high, 6 ) ); /* return exact root at high in Q15 */ -} - -/*===================================================================*/ -/* FUNCTION : calc_weight( ) */ -/*-------------------------------------------------------------------*/ -/* PURPOSE : This function computes the weight given delta1 -and delta2 */ -/*-------------------------------------------------------------------*/ -/* INPUT ARGUMENTS : */ -/* _ (Word16) delta1: (Q15) */ -/* _ (Word16) delta2: (Q15) */ -/*-------------------------------------------------------------------*/ -/* OUTPUT ARGUMENTS : */ -/* _ (Word16 *) n1: o/p weight is Q(31-n1) */ -/*-------------------------------------------------------------------*/ -/* INPUT/OUTPUT ARGUMENTS : */ -/* _ None. */ -/*-------------------------------------------------------------------*/ -/* RETURN ARGUMENTS : */ -/* _ (Word32) Lsum1: computed weight Q(31-n1) */ -/* (alpha/(sqrt(delta1*delta2)) */ -/*===================================================================*/ - -Word32 calc_weight( - Word16 delta1, - Word16 delta2, - Word16* n1 -) -{ - Word16 n; - Word32 L_tmp; - Word16 alpha=0x4F94; - move16(); /* ( 0.5*250/( 2*pi)) in Q10*/ - - L_tmp = L_mult0( delta1, delta2 ); /* Q30 */ - n = norm_l( L_tmp ); - L_tmp = L_shl( L_tmp, n ); - n = sub(1, n); - L_tmp = Isqrt_lc( L_tmp, &n ); /* Q( 31-n)*/ - - L_tmp = Mult_32_16( L_tmp, alpha ); /* Q( 26-n) */ - - *n1 = n; - move16(); - - return L_tmp; -} - -/*===================================================================*/ -/* FUNCTION : polynomial_eval_fx ( ) */ -/*-------------------------------------------------------------------*/ -/* PURPOSE : Evaluate P or Q polynomial at given frequency */ -/*-------------------------------------------------------------------*/ -/* INPUT ARGUMENTS : */ -/* _ (Word16) f : frequency used as index for cosine table lookup */ -/* Q9 */ -/* _ (Word32 []) coef: polynomial coefficients, Q26 */ -/* _ (Word16 []) order: LPC order */ -/*-------------------------------------------------------------------*/ -/* OUTPUT ARGUMENTS : */ -/* _ None */ -/*-------------------------------------------------------------------*/ -/* INPUT/OUTPUT ARGUMENTS : */ -/* _ None */ -/*-------------------------------------------------------------------*/ -/* RETURN ARGUMENTS : */ -/* _ (Word32) polynomial value at given frequency f, Q25 */ -/*===================================================================*/ -/* Note: This function uses 512 entry cosine table cos_table[], Q15 */ -/*===================================================================*/ -/* if (K = order/2) */ -/* P(w)=cos(Kw)+p[1]*cos((K-1)w)+p[2]*cos((K-2)w)+...+p[(K-1)]*cos(w)+p[K]/2 */ -/* Q(w)=cos(Kw)+q[1]*cos((K-1)w)+q[2]*cos((K-2)w)+...+q[(K-1)]*cos(w)+q[K]/2 */ -/*===================================================================*/ - -/* 40-32 bit conversion */ -Word32 polynomial_eval_fx( Word16 f, - Word32* coef, - Word16 order - ) -{ - Word16 i, idx; - Word16 dh, dl, coslut; - Word32 Ltemp, L_tmp1, L_tmp; - Word32 Lacc; - idx = f; - move16(); - dh = extract_h( coef[order / 2] ); /* Q10 */ - dl = extract_l( coef[order / 2] ); /* Q16 */ - - coslut = 0x4000; - move16(); /* coslut=0.5 in Q15 */ - Ltemp = L_mult0( coslut, dh ); /* Ltemp=MSW, coef[5]/2 in Q25 */ - - Lacc = L_mult0( coslut, dl ); /* Lacc=LSW, coef[5]/2 in Q41 //Q31 */ - Lacc = L_shr( Lacc, 1 ); /* Q30 */ - FOR ( i = ( order / 2 ) - 1; i > 0; i-- ) - { - coslut = cos_table[idx]; - move16(); /* coslut=cos( ( ( order/2)-i)f), Q15 */ - dh = extract_h( coef[i] );/* Q10 */ - dl = extract_l( coef[i] );/* Q16 */ - - Ltemp = L_add( Ltemp, L_mult0( dh, coslut ) ); /* Q25 */ - IF ( dl < 0 ) - { - L_tmp1 = L_shl( L_add( 65536, dl ), 14 ); - L_tmp = Mult_32_16( L_tmp1, coslut ); - Lacc = L_add( Lacc, L_tmp ); - } - ELSE - { - Lacc = L_add( Lacc, L_shr( L_mult0( coslut, dl ), 1 ) );/* Q30 */ - } - - idx += f; - if ( sub(idx, 512) >= 0 ) idx = sub(idx, 512); /* modulo of 512 */ - } - - coslut = cos_table[idx]; - move16(); /* coslut=cos( 5f), Q15 */ - Ltemp = L_add( Ltemp, L_mult0( 0x400, coslut ) ); /* coef[0]=1.0, Q25 */ - - return ( L_add( Ltemp, L_shr( Lacc, 15 ) ) ); /* Q25 */ -} - -/*----------------------------------------------------------------------------------* -* v_sort: -* -* This is very fast with almost ordered vectors. The first 15 ISF values -* are almost always sorted. -*----------------------------------------------------------------------------------*/ -void v_sort( - Word16 *r, /* i/o: Vector to be sorted in place */ - const Word16 lo, /* i : Low limit of sorting range */ - const Word16 up /* I : High limit of sorting range */ -) -{ - Word16 i, j; - Word16 tempr; - - - FOR (i=sub(up, 1); i>=lo; i--) - { - tempr = r[i]; - move16(); - FOR (j=i; j +#include "options.h" +#include "cnst.h" +#include "rom_com.h" +#include "prot.h" + + +/*-------------------------------------------------------------------* + * Local constants + *-------------------------------------------------------------------*/ + +/* The conversion modes. */ +#define DOWNCONV 0 +#define UPCONV 1 +/* The cap of the inverse power spectrum. */ +#define MAXPOWERSPECT 1e-5f +#define N50 GRID50_POINTS +#define N40 GRID40_POINTS + + +/*-------------------------------------------------------------------* + * Local functions + *-------------------------------------------------------------------*/ + +static void powerspect( const float x[], const short N, float R[], float S[], float G[], const short mode ); + +static void spectautocorr( const float x[], const short N, const float G[], float r[] ); + +static void zeros2poly( float x[], float R[], float S[] ); + +static void polydecomp( float A[], float P[], float Q[] ); + +static void cheb2poly( float P[] ); + + +/*---------------------------------------------------------------------* + * lsp_convert_poly() + * + * Converts the LP filter estimated at 16.0 kHz sampling rate down + * 12.8 kHz frequency scale or alternatively from 12.8 kHz up to + * 16.0 kHz. The former is called down conversation and latter up + * conversion. The resulting LP filter is characterized with its + * line spectrum pairs. The original Lp filter can be either in + * its immittance, used for the AMR-WB IO mode, or line spectrum + * pair representation. + * + * The conversion is based the autocorrelation computed from the + * power spectrum of the LP filter that is truncated or extrapolated + * to the desired frequency scale. + *---------------------------------------------------------------------*/ + +short lsp_convert_poly( + float w[], /* i/o: LSP or ISP parameters */ + const short L_frame, /* i : flag for up or down conversion */ + const short Opt_AMRWB /* i : flag for the AMR-WB IO mode */ +) +{ + float epsP[M+1]; + float G[GRID50_POINTS], r[M+1], A[M+1], A_old[M+1], R[NC+1], S[NC+1]; + short i; + short flag; + + /*---------------------------------------------------------------------* + * Because AMR-WB IO uses immittance spectrum frequency representation + * instead of line spectrum frequency representation, the input + * parameters do not give the zeros of the polynomials R(x) and S(x). + * Hence R(x) and S(x) are formed via the polynomial A(z) of the linear + * prediction filter. + *---------------------------------------------------------------------*/ + + if( Opt_AMRWB ) + { + isp2a( w, A_old, M ); + polydecomp( A_old, R, S ); + } + + /*---------------------------------------------------------------------* + * Form the polynomials R(x) and S(x) from their zeros that are the + * line spectrum pairs of A(z). The polynomial coefficients can be + * scaled for convenience, because scaling will not affect the + * resulting LP coefficients. Scaling by 128 gives the correct offset + * to the power spectrum for n = 16. + *---------------------------------------------------------------------*/ + + else + { + zeros2poly( w, R, S ); + for (i = 0; i <= NC; i++) + { + R[i] *= 128.0f; + S[i] *= 128.0f; + } + lsp2a_stab( w, A_old, M ); + } + + /*---------------------------------------------------------------------* + * Conversion from 16.0 kHz down to 12.8 kHz. The power spectrum + * needs to be computed only up to 6.4 kHz, because the upper band + * is omitted. + *---------------------------------------------------------------------*/ + + if( L_frame == L_FRAME ) + { + powerspect( grid50, N50, R, S, G, DOWNCONV ); + spectautocorr( grid40, N40, G, r ); + } + + /*---------------------------------------------------------------------* + * Conversion from 12.8 kHz up to 16.0 kHz. + * Compute the power spectrum of the LP filter, extrapolate the + * power spectrum from 6.4 kHz to 8.0 kHz, and compute auto- + * correlation on this power spectrum. + *---------------------------------------------------------------------*/ + + else + { + powerspect( grid40, N40, R, S, G, UPCONV ); + for (i = N40; i < N50; i++) + { + G[i] = G[N40-1]; + } + + spectautocorr( grid50, N50, G, r ); + } + + /*---------------------------------------------------------------------* + * Compute the linear prediction coefficients from the autocorrelation + * and convert to line spectrum pairs. + *---------------------------------------------------------------------*/ + + flag = lev_dur( A, r, M, epsP ); + a2lsp_stab( A, w, stable_LSP ); + + return(flag); +} + + +/*---------------------------------------------------------------------* + * powerspect() + * + * Computes the power spectrum G(w) = 1/|A(w)|^2 at N points on + * the real axis x = cos w by utilizing the line spectrum frequency + * decomposition + * + * A(z) = (P(z) + Q(z))/2, + * + * where assuming A(z) of an even degree n, + * + * P(z) = [A(z) + z^(n+1) A(1/z)]/(1/z + 1), + * Q(z) = [A(z) - z^(n+1) A(1/z)]/(1/z - 1). + * + * The zeros of these polynomials give the line spectrum frequencies + * of A(z). It can be shown that for an even n, + * + * |A(x)|^2 = 2 (1 + x) R(x)^2 + 2 (1 - x) S(x)^2, + * + * where x = cos w, and R(x) and S(x) are the direct polynomials + * resulting from the Chebyshev series representation of P(z) + * and Q(z). + * + * This routine assumes the grid X = 1, x[0], x[1], .., x[m-1], + * -, ..., -x[1], -x[0], -1 such that x[i] = cos((i+1)*pi/N) for + * evaluating the power spectrum. Only m = (N-1)/2 - 1 grid points + * need to be stored, because cos(0) and cos(pi/2) are trivial, + * and the points above pi/2 are obtained readily using the symmetry + * of cosine. + * + * The power spectrum can be scaled as a*G[], where a is chosen + * for convenience. This is because the scaling has no impact on + * the LP coefficients to be determined based on the power spectrum. + *---------------------------------------------------------------------*/ + +static void powerspect( + const float x[], /* i: Grid points x[0:N-1] */ + const short N, /* i: Number of grid points */ + float R[], /* i: Coefficients of R(x) in R[0:NC] */ + float S[], /* i: Coefficients of S(x) in S[0:NC] */ + float G[], /* o: Power spectrum G[0:N] */ + const short mode /* i: Flag for up or down conversion */ +) +{ + float re, ro, se, so; + float s0, s1, r0, r1, x0, x1, x2; + Word16 i, j; + Word16 iuni, imid; + + /* init buffer */ + for(i=0; i cos(pi/2) = 0. + *---------------------------------------------------------------------*/ + + for (i = 1; i <= iuni; i++) + { + x0 = x[i-1]; + r0 = R[0]; + s0 = S[0]; + + for (j = 1; j <= NC; j++) + { + r0 = x0*r0 + R[j]; + s0 = x0*s0 + S[j]; + } + r0 = (1.0f + x0)*r0*r0; + s0 = (1.0f - x0)*s0*s0; + + G[i] = 2.0f*(r0 + s0); + } + + /*---------------------------------------------------------------------* + * Power spectrum at points other than x = -1, 0, and 1 and unique + * points is computed using the anti-symmetry of the grid relative + * to the midpoint x = 0 in order to reduce looping. + *---------------------------------------------------------------------*/ + + for ( ; i < imid; i++) + { + x0 = x[i-1]; + x2 = x0*x0; + + re = R[0]; + se = S[0]; + ro = R[1]; + so = S[1]; + + for (j = 2; j < NC; j+=2) + { + re = x2*re + R[j]; + ro = x2*ro + R[j+1]; + se = x2*se + S[j]; + so = x2*so + S[j+1]; + } + + re = x2*re + R[j]; + ro *= x0; + se = x2*se + S[j]; + so *= x0; + + r0 = re + ro; + s0 = se + so; + r1 = re - ro; + s1 = se - so; + + x1 = 1.0f + x0; + x2 = 1.0f - x0; + + r0 = x1*r0*r0; + s0 = x2*s0*s0; + r1 = x2*r1*r1; + s1 = x1*s1*s1; + + G[i] = 2.0f*(r0 + s0); + G[N-i-1] = 2.0f*(r1 + s1); + } + + /*---------------------------------------------------------------------* + * Compute the power spectrum 1/|A(x)|^2 from |A(x)|^2 with logic + * to prevent division by small number and upper bound the spectrum. + * This upper bound is implicit in fixed point arithmetic, but is + * needed explicitly in floating point implementations to avoid numeric + * problems. + *---------------------------------------------------------------------*/ + + for(i=0; i 0; j--) + { + R[j] += xr*R[j-1]; + S[j] += xs*S[j-1]; + } + } + + return; +} + +/*---------------------------------------------------------------------* + * polydecomp() + * + * Computes the coefficients of the symmetric and antisymmetric + * polynomials P(z) and Q(z) that define the line spectrum pair + * decomposition of a given polynomial A(z) of order n. For even n, + * + * P(z) = [A(z) + z^(n+1) A(1/z)]/(1/z + 1), + * Q(z) = [A(z) - z^(n+1) A(1/z)]/(1/z - 1), + * + * These polynomials are then expressed in their direct form, + * respectively, R(x) and S(x), on the real axis x = cos w using + * explicit Chebyshev polynomials of the first kind. + * + * The coefficients of the polynomials R(x) and S(x) are returned + * in R[0:n/2] and S[0:n/2] for the given linear prediction + * coefficients A[0:n/2]. Note that R(x) and S(x) are formed in + * place such that P(z) is stored in the same array than R(x), + * and Q(z) is stored in the same array than S(x). + * + * The routines assumes n = 16. + *---------------------------------------------------------------------*/ + +static void polydecomp( + float A[], /* i: linear prediction coefficients */ + float R[], /* o: coefficients of R(x) */ + float S[] /* o: coefficients of S(x) */ +) +{ + float *P = &R[0], *Q = &S[0]; + Word16 i, j; + + P[0] = A[0]; + Q[0] = A[0]; + for (i = 1, j = M; i <= NC; i++, j--) + { + P[i] = A[i] + A[j] - P[i-1]; + Q[i] = A[i] - A[j] + Q[i-1]; + } + + cheb2poly(P); + cheb2poly(Q); + + return; +} + +/*---------------------------------------------------------------------* + * cheb2poly() + * + * Computes the coefficients of the explicit Chebyshev polynomial + * P(x) = P[0]*x^n + P[1]*x^(n-1) + ... + P[n] given the coefficients + * of the series + * + * C(x) = C[0]*T_n(x) + C[1]*T_n-1(x) + ... + C[n]*T_0(x), + * + * where T_n(x) is the nth Chebyshev polynomial of the first kind. + * This implementation assumes C[0] = 1. Only the value n = 8 is + * supported. + * + * The conversion from C(x) to P(x) is done in place such that the + * coefficients of C(x) are given in P[0:8] and those of P(x) are + * returned in the same array. + *---------------------------------------------------------------------*/ + +static void cheb2poly( + float P[] /* i/o: The coefficients of C(x) and P(x) */ +) +{ + float c1, c2, c3, c4, c5, c6, c7, c8; + + c1 = P[1]; + c2 = P[2]; + c3 = P[3]; + c4 = P[4]; + c5 = P[5]; + c6 = P[6]; + c7 = P[7]; + c8 = P[8]; + + P[0] = 128.0f; + P[1] = 64.0f*c1; + P[2] = 32.0f*c2 - 256.0f; + P[3] = 16.0f*c3 - 112.0f*c1; + P[4] = 160.0f - 48.0f*c2 + 8.0f*c4; + P[5] = 56.0f*c1 - 20.0f*c3 + 4.0f*c5; + P[6] = 18.0f*c2 - 32.0f - 8.0f*c4 + 2.0f*c6; + P[7] = 5.0f*c3 - 7.0f*c1 - 3.0f*c5 + c7; + P[8] = 1.0f - c2 + c4 - c6 + 0.5f*c8; + + return; +} diff --git a/src/libs/libevs/lib_com/lsp_conv_poly_fx.cpp b/src/libs/libevs/lib_com/lsp_conv_poly_fx.cpp deleted file mode 100755 index 8a56e58d..00000000 --- a/src/libs/libevs/lib_com/lsp_conv_poly_fx.cpp +++ /dev/null @@ -1,858 +0,0 @@ -/*==================================================================================== - EVS Codec 3GPP TS26.442 Apr 03, 2018. Version 12.11.0 / 13.6.0 / 14.2.0 - ====================================================================================*/ - -#include "options.h" - -#include "cnst_fx.h" /* Common constants */ -#include "prot_fx.h" /* Function prototypes */ -#include "rom_com_fx.h" /* Static table prototypes */ -#include "stl.h" - -/*-------------------------------------------------------------------* - * Local constants - *-------------------------------------------------------------------*/ - -/* The conversion modes. */ -#define DOWNCONV 0 -#define UPCONV 1 -#define NC (M/2) - -/*-------------------------------------------------------------------* - * Local functions - *-------------------------------------------------------------------*/ -static void powerspect_fx( - const Word16 x[], /* i: Q15 Grid points x[0:m-1] */ - Word16 N, /* i: Number of grid points */ - Word32 R[], /* i: Q20 Coefficients of R(x) in R[0:NC] */ - Word32 S[], /* i: Q20 Coefficients of S(x) in S[0:NC] */ - Word32 G[], /* o: Q15 Power spectrum G[0:N] */ - Word16 mode /* i: Flag for up or down conversion */ -); - -static void spectautocorr_fx( - const Word16 x[], /* i: Grid points x[0:m-1] */ - const Word16 N, /* i: Number of grid points */ - const Word32 G[], /* i: Power spectrum G[0:N-1] */ - Word16 rh[], /* o: Autocorrelation r[0:M] */ - Word16 rl[] /* o: Autocorrelation r[0:M] */ -); - -static Word32 b_inv_sq( - const Word32 in32, /* i : Input not normalized to inverse */ - const Word16 exp_in /* I : input current exponent */ -); - -static Word32 inv_pow( - const Word32 re, - const Word32 se, - const Word16 x - -); - -static void zeros2poly_fx( Word16 x[], Word32 R[], Word32 S[] ); - -static void polydecomp_fx( - Word16 A[], /* i: Q12 linear prediction coefficients */ - Word32 P[], /* o: Q22 coefficients of R(x) */ - Word32 Q[] /* o: Q22 coefficients of S(x) */ -); - -static void cheb2poly_fx( - Word32 L_P[] /* i/o Q22: The coefficients of C(x) and P(x) */ -); - -/*---------------------------------------------------------------------* - * lsp_convert_poly() - * - * Converts the LP filter estimated at 16.0 kHz sampling rate down - * 12.8 kHz frequency scale or alternatively from 12.8 kHz up to - * 16.0 kHz. The former is called down conversation and latter up - * conversion. The resulting LP filter is characterized with its - * line spectrum pairs. The original Lp filter can be either in - * its immittance, used for the AMR-WB IO mode, or line spectrum - * pair representation. - * - * The conversion is based the autocorrelation computed from the - * power spectrum of the LP filter that is truncated or extrapolated - * to the desired frequency scale. - *---------------------------------------------------------------------*/ - -Word16 lsp_convert_poly_fx( - Word16 w[], /* i/o: LSP or ISP parameters */ - const Word16 L_frame, /* i : flag for up or down conversion */ - const Word16 Opt_AMRWB /* i : flag for the AMR-WB IO mode */ -) -{ - const Word16 N50 = GRID50_POINTS; - const Word16 N40 = GRID40_POINTS; - Word16 flag; - - Word32 G[GRID50_POINTS]; - Word16 i; - Word16 A[M+1]; - Word32 R[NC+1], S[NC+1]; - Word32 epsP[M+1]; - Word16 rh[M+1], rl[M+1]; - Word16 oldA[M+3]; - - /*---------------------------------------------------------------------* - * Because AMR-WB IO mode uses immittance spectrum frequency representation - * instead of line spectrum frequency representation, the input - * parameters do not give the zeros of the polynomials R(x) and S(x). - * Hence R(x) and S(x) are formed via the polynomial A(z) of the linear - * prediction filter. - *---------------------------------------------------------------------*/ - - IF( Opt_AMRWB ) - { - E_LPC_f_isp_a_conversion( w, oldA, M ); - - polydecomp_fx( oldA, R, S ); - } - - /*---------------------------------------------------------------------* - * Form the polynomials R(x) and S(x) from their zeros that are the - * line spectrum pairs of A(z). The polynomial coefficients can be - * scaled for convenience, because scaling will not affect the - * resulting LP coefficients. Scaling by 128 gives the correct offset - * to the power spectrum for n = 16. - *---------------------------------------------------------------------*/ - - ELSE - { - E_LPC_f_lsp_a_conversion( w, oldA, M ); - - zeros2poly_fx(w, R, S); - } - - /*---------------------------------------------------------------------* - * Conversion from 16.0 kHz down to 12.8 kHz. The power spectrum - * needs to be computed only up to 6.4 kHz, because the upper band - * is omitted. - *---------------------------------------------------------------------*/ - - IF (sub(L_frame,L_FRAME) == 0) - { - powerspect_fx(grid50_fx, N50, R, S, G, DOWNCONV); - spectautocorr_fx(grid40_fx, N40, G, rh, rl); - } - /*---------------------------------------------------------------------* - * Conversion from 12.8 kHz up to 16.0 kHz. - * Compute the power spectrum of the LP filter, extrapolate the - * power spectrum from 6.4 kHz to 8.0 kHz, and compute auto- - * correlation on this power spectrum. - *---------------------------------------------------------------------*/ - - ELSE - { - powerspect_fx(grid40_fx, N40, R, S, G, UPCONV); - - FOR (i = N40; i < N50; i++) - { - G[i] = G[N40-1]; - move32(); - } - - spectautocorr_fx(grid50_fx, N50, G, rh, rl); - } - - - /*---------------------------------------------------------------------* - * Compute the linear prediction coefficients from the autocorrelation - * and convert to line spectrum pairs. - *---------------------------------------------------------------------*/ - flag=E_LPC_lev_dur(rh, rl, A, epsP, M, oldA); - E_LPC_a_lsp_conversion(A, w, stable_LSP_fx, M ); - - - return(flag); -} - -/*---------------------------------------------------------------------* - * powerspect() - * - * Computes the power spectrum G(w) = 1/|A(w)|^2 at N points on - * the real axis x = cos w by utilizing the line spectrum frequency - * decomposition - * - * A(z) = (P(z) + Q(z))/2, - * - * where assuming A(z) of an even degree n, - * - * P(z) = [A(z) + z^(n+1) A(1/z)]/(1/z + 1), - * Q(z) = [A(z) - z^(n+1) A(1/z)]/(1/z - 1). - * - * The zeros of these polynomials give the line spectrum frequencies - * of A(z). It can be shown that for an even n, - * - * |A(x)|^2 = 2 (1 + x) R(x)^2 + 2 (1 - x) S(x)^2, - * - * where x = cos w, and R(x) and S(x) are the direct polynomials - * resulting from the Chebyshev series representation of P(z) - * and Q(z). - * - * This routine assumes the grid X = 1, x[0], x[1], .., x[m-1], - * -, ..., -x[1], -x[0], -1 such that x[i] = cos((i+1)*pi/N) for - * evaluating the power spectrum. Only m = (N-1)/2 - 1 grid points - * need to be stored, because cos(0) and cos(pi/2) are trivial, - * and the points above pi/2 are obtained readily using the symmetry - * of cosine. - * - * The power spectrum can be scaled as a*G[], where a is chosen - * for convenience. This is because the scaling has no impact on - * the LP coefficients to be determined based on the power spectrum. - *---------------------------------------------------------------------*/ - -void powerspect_fx( - const Word16 x[], /* i: Q15 Grid points x[0:m-1] */ - Word16 N, /* i: Number of grid points */ - Word32 R[], /* i: Q20 Coefficients of R(x) in R[0:NC] */ - Word32 S[], /* i: Q20 Coefficients of S(x) in S[0:NC] */ - Word32 G[], /* o: Q15 Power spectrum G[0:N] */ - Word16 mode /* i: Flag for up or down conversion */ -) -{ - Word32 s0, se, so, r0, re, ro; - Word16 i, j; - Word16 iuni, imid; - Word32 L_tmp; - Word16 x2; - Word32 mh; - UWord16 ml; - - /*---------------------------------------------------------------------* - * Down conversion yields iuni unique grid points that do not have - * symmetric counterparts above x = cos(pi/2) = 0. - * Set the mid point of the frequency grid. - *---------------------------------------------------------------------*/ - - IF (mode == DOWNCONV) - { - iuni = (GRID50_POINTS - 1)/5 - 1; - move16(); - imid = (GRID50_POINTS - 1)/2; - move16(); - } - - /*---------------------------------------------------------------------* - * Power spectrum x = cos(pi) = -1 that is not needed in down - * conversion. Set the mid point of the frequency grid. - *---------------------------------------------------------------------*/ - - ELSE - { - iuni = 0; - move16(); - imid = (GRID40_POINTS - 1)/2; - move16(); - - G[N-1] = S[0]; - move32(); - - FOR (j = 1; j <= NC; j++) - { - G[N-1] = L_sub(S[j], G[N-1]); - move32(); - } - G[N-1] = b_inv_sq(G[N-1], 19); - move32(); - } - - /*---------------------------------------------------------------------* - * Power spectrum x = cos(0) = 1. - *---------------------------------------------------------------------*/ - - G[0] = R[0]; - move32(); - FOR (j = 1; j <= NC; j++) - { - G[0] = L_add(R[j], G[0]); - move32(); - } - - G[0] = b_inv_sq(L_max(G[0],1), 19); - move32(); - - /*---------------------------------------------------------------------* - * Power spectrum at x = cos(pi/2) = 0. - *---------------------------------------------------------------------*/ - G[imid] = inv_pow(R[NC], S[NC], 0); - move32(); - - /*---------------------------------------------------------------------* - * Power spectrum at unique points that do not have symmetric - * counterparts at x > cos(pi/2) = 0. - *---------------------------------------------------------------------*/ - - FOR (i = 1; i <= iuni; i++) - { - Mpy_32_16_ss(R[0], x[i-1], &mh, &ml); - r0 = L_add(R[1], mh); - - Mpy_32_16_ss(S[0], x[i-1], &mh, &ml); - s0 = L_add(S[1], mh); - - - FOR (j = 2; j <= NC; j++) - { - Mpy_32_16_ss(r0, x[i-1], &mh, &ml); - r0 = L_add(R[j], mh); - - Mpy_32_16_ss(s0, x[i-1], &mh, &ml); - s0 = L_add(S[j], mh); - } - - G[i] = inv_pow(r0, s0, x[i-1]); - move32(); - } - - /*---------------------------------------------------------------------* - * Power spectrum at points other than x = -1, 0, and 1 and unique - * points is computed using the anti-symmetry of the grid relative - * to the midpoint x = 0 in order to reduce looping. - *---------------------------------------------------------------------*/ - - FOR ( ; i < imid; i++) - { - x2 = mult_r(x[i-1], x[i-1]); - - Mpy_32_16_ss(R[0], x2, &mh, &ml); - re = L_add(R[2], mh); - Mpy_32_16_ss(R[1], x2, &mh, &ml); - ro = L_add(R[3], mh); - - Mpy_32_16_ss(S[0], x2, &mh, &ml); - se = L_add(S[2], mh); - Mpy_32_16_ss(S[1], x2, &mh, &ml); - so = L_add(S[3], mh); - - FOR (j = 4; j < NC; j+=2) - { - Mpy_32_16_ss(re, x2, &mh, &ml); - re = L_add(R[j], mh); - Mpy_32_16_ss(ro, x2, &mh, &ml); - ro = L_add(R[j+1], mh); - Mpy_32_16_ss(se, x2, &mh, &ml); - se = L_add(S[j], mh); - Mpy_32_16_ss(so, x2, &mh, &ml); - so = L_add(S[j+1], mh); - } - - Mpy_32_16_ss(re, x2, &mh, &ml); - L_tmp = L_add(R[j], mh); - Mpy_32_16_ss(ro, x[i-1], &mh, &ml); - re = L_add(L_tmp, mh); - ro = L_sub(L_tmp, mh); - - Mpy_32_16_ss(se, x2, &mh, &ml); - L_tmp = L_add(S[j], mh); - Mpy_32_16_ss(so, x[i-1], &mh, &ml); - se = L_add(L_tmp, mh); - so = L_sub(L_tmp, mh); - - G[i] = inv_pow(re, se, x[i-1]); - move32(); - G[N-i-1] = inv_pow(so, ro, x[i-1]); - move32(); - } - - return; -} - -static Word32 b_inv_sq( - const Word32 in32, /* i : Input not normalized to inverse */ - const Word16 exp_in /* i : input current exponent */ -) -{ - Word16 m_den, exp_den; - Word16 div_out; - Word32 Ltmp; - - exp_den = norm_l(in32); - m_den = extract_h(L_shl(in32, exp_den)); - exp_den = add(sub(30,exp_den),sub(16,exp_in)); - - m_den = mult_r(m_den, m_den); - exp_den = shl(exp_den,1); - - div_out = div_s(8192,m_den); - Ltmp = L_shl(div_out, add(sub(30-13, exp_den),15)); /*Q15*/ - - return Ltmp; -} - -static Word32 inv_pow( - const Word32 re, - const Word32 se, - const Word16 x -) -{ - Word16 exp1, exp2; - Word16 tmp; - Word32 L_tmp; - Word32 mh; - UWord16 ml; - Word32 r0, s0; - - IF(re==0) - { - exp1 = 30; - move16(); - r0 = L_deposit_l(0); - } - ELSE - { - exp1 = norm_l(re); - tmp = extract_h(L_shl(re, exp1)); - L_tmp = L_shr(L_mult(tmp, tmp), 1); - Mpy_32_16_ss(L_tmp, x, &mh, &ml); - r0 = L_add(L_tmp, mh); - } - - IF(se==0) - { - exp2 = 30; - move16(); - s0 = L_deposit_l(0); - } - ELSE - { - exp2 = norm_l(se); - tmp = extract_h(L_shl(se, exp2)); - L_tmp = L_shr(L_mult(tmp, tmp), 1); - Mpy_32_16_ss(L_tmp, x, &mh, &ml); - s0 = L_sub(L_tmp, mh); - } - - IF(exp1 > exp2) - { - exp1 = shl(sub(exp1, exp2), 1); - r0 = L_shr(r0, exp1); - - exp2 = add(add(exp2, exp2), 8); - } - ELSE - { - exp2 = shl(sub(exp2, exp1), 1); - s0 = L_shr(s0, exp2); - - exp2 = add(add(exp1, exp1), 8); - } - - r0 = L_add(r0, s0); - exp1 = norm_l(r0); - L_tmp = L_shl(r0, exp1); - tmp = extract_h(L_tmp); - IF(tmp==0) - { - return MAX_32; - } - tmp = div_s((Word16)((1<<14)-1), tmp); - exp1 = add(exp1, exp2); - L_tmp = L_shr(tmp, sub(31, exp1)); /* result in Q15 */ - - return(L_tmp); -} - - -/*---------------------------------------------------------------------* - * spectautocorr() - * - * Computes the autocorrelation r[j] for j = 0, 1, ..., M from - * the power spectrum P(w) by using rectangle rule to approximate - * the integral - * - * 1 pi - * r[j] = --- I P(w) cos(j*w) dw. - * 2*pi -pi - * - * It is sufficient to evaluate the integrand only from w = 0 to - * w = pi due to the symmetry P(-w) = P(w). We can further - * employ the relation - * - * cos(j*(pi - w)) = (-1)^j cos(j*w) - * - * to use symmetries relative to w = pi/2. - * - * When applying the rectangle rule, it is useful to separate w = 0, - * w = pi/2, and w = pi. By using a frequency grid of N points, we - * can express the rectangle rule as - * - * r[j] = G[0] + 2*a*G[(N-1)/2] + b*G[N-1] - * - * M - * + 2 sum (G[i] - G[N-i-1]) cos(j*x[i]) - * i=1 - * - * where G[i] is the power spectrum at the grid point cos(i*pi/N) - * and M = (N-1)/2 - 1 is the number of the grid points in the - * interval(0, pi/2). - * - * The coefficients - * - * b = (-1)^j - * a = (1 + (-1)^(j+1))(-1)^floor(j/2) - * - * follow from the properties of cosine. The computation further - * uses the recursion - * - * cos(j*w) = 2*cos(w)*cos((j-1)*w) - cos((j-2)*w) - * - * Note that the autocorrelation can be scaled for convenience, - * because this scaling has no impact on the LP coefficients to be - * calculated from the autocorrelation. The expression of r[j] thus - * omits the division by N. - * - * See the powerspect function on the definition of the grid. - * - * References - * J. Makhoul, "Spectral linear prediction: properties and - * applications," IEEE Trans. on Acoustics, Speech and Signal - * Processing, Vol. 23, No. 3, pp.283-296, June 1975 - *---------------------------------------------------------------------*/ - -static void spectautocorr_fx( - const Word16 x[], /* i: Grid points x[0:m-1] */ - const Word16 N, /* i: Number of grid points */ - const Word32 G[], /* i: Power spectrum G[0:N-1] */ - Word16 rh[], /* o: Autocorrelation r[0:M] */ - Word16 rl[] /* o: Autocorrelation r[0:M] */ -) -{ - Word16 c[M+1]; /* c[j] = cos(j*w) */ - Word32 gp, gn; - Word16 i, j; - Word16 imid; - Word32 mh; - UWord16 ml; - Word32 r[M+1]; - Word16 exp0; - - /*---------------------------------------------------------------------* - * The mid point of the cosine table x of m entries assuming an odd m. - * Only the entries x[0] = cos(pi/m), x[1] = cos(2*pi/m), ..., - * x[imid-1] = cos((imid-1)*pi/m) need to be stored due to trivial - * cos(0), cos(pi/2), cos(pi), and symmetry relative to pi/2. - * Here m = 51. - *---------------------------------------------------------------------*/ - - imid = (N - 1)/2; - move16(); - - /*---------------------------------------------------------------------* - * Autocorrelation r[j] at zero lag j = 0 for the upper half of the - * unit circle, but excluding the points x = cos(0) and x = cos(pi). - *---------------------------------------------------------------------*/ - - r[0] = G[1]; - move32(); - FOR (i = 2; i < N-1; i++) - { - r[0] = L_add(r[0], G[i]); - move32(); - } - - /*---------------------------------------------------------------------* - * Initialize the autocorrelation r[j] at lags greater than zero - * by adding the midpoint x = cos(pi/2) = 0. - *---------------------------------------------------------------------*/ - - r[1] = L_deposit_l(0); - r[2] = -G[imid]; - move32(); - - FOR (i = 3; i < M; i+=2) - { - r[i] = L_deposit_l(0); - r[i+1] = -r[i-1]; - move32(); - } - - /*---------------------------------------------------------------------* - * Autocorrelation r[j] at lags j = 1, 2, ..., M. The computation - * employes the relation cos(j*(pi - w)) = (-1)^j cos(j*w) and - * cos(j*w) = 2*cos(w)*cos((j-1)*w) - cos((j-2)*w) for obtaining - * the cosine c[j] = cos(j*w). - *---------------------------------------------------------------------*/ - - c[0] = (Word16)32767; - move16(); /* 1.0 in Q15 */ - FOR (i = 1; i < imid; i++) - { - gp = L_add(G[i], G[N-i-1]); - gn = L_sub(G[i], G[N-i-1]); - - /*r[1] = L_mac(r[1], x[i-1], gn);*/ - Mpy_32_16_ss(gn, x[i-1], &mh, &ml); - r[1] = L_add(r[1], mh); - move32(); - c[1] = x[i-1]; - move16(); - - FOR (j = 2; j < M; j+=2) - { - c[j] = mult_r(c[j-1], x[i-1]); - move16(); - c[j] = add(c[j], sub(c[j], c[j-2])); - move16(); - - /*r[j] = L_mac(r[j], c[j], gp);*/ - Mpy_32_16_ss(gp, c[j], &mh, &ml); - r[j] = L_add(r[j], mh); - move32(); - - c[j+1] = mult_r(c[j], x[i-1]); - move16(); - c[j+1] = add(c[j+1], sub(c[j+1], c[j-1])); - move16(); - - /*r[j+1] = L_mac(r[j+1], c[j+1], gn);*/ - Mpy_32_16_ss(gn, c[j+1], &mh, &ml); - r[j+1] = L_add(r[j+1], mh); - move32(); - } - c[j] = mult_r(c[j-1], x[i-1]); - move16(); - c[j] = add(c[j], sub(c[j], c[j-2])); - move16(); - - Mpy_32_16_ss(gp, c[j], &mh, &ml); - r[j] = L_add(r[j], mh); - move32(); - } - - /*---------------------------------------------------------------------* - * Add the endpoints x = cos(0) = 1 and x = cos(pi) = -1 as - * well as the lower half of the unit circle. - *---------------------------------------------------------------------*/ - gp = L_shr(L_add(G[0], G[N-1]), 1); - gn = L_shr(L_sub(G[0], G[N-1]), 1); - - r[0]= L_add(r[0], gp); - move32(); - exp0 = norm_l(r[0]); - L_Extract(L_shl(r[0], exp0), &rh[0], &rl[0]); - - FOR (j = 1; j < M; j+=2) - { - L_Extract(L_shl(L_add(r[j], gn), exp0), &rh[j], &rl[j]); - L_Extract(L_shl(L_add(r[j+1], gp), exp0), &rh[j+1], &rl[j+1]); - } - - return; -} - -/*---------------------------------------------------------------------* - * zeros2poly() - * - * Computes the coefficients of the polynomials - * - * R(x) = prod (x - x[i]), - * i = 0,2,4,... - * - * S(x) = prod (x - x[i]), - * i = 1,3,5,... - * - * when their zeros x[i] are given for i = 0, 1, ..., n-1. The - * routine assumes n = 1 or even n greater than or equal to 4. - * - * The polynomial coefficients are returned in R[0:n/2-1] and - * S[0:n/2-1]. The leading coefficients are in R[0] and S[0]. - *---------------------------------------------------------------------*/ -static void zeros2poly_fx( - Word16 x[], /* i: Q15 Zeros of R(x) and S(x) */ - Word32 R[], /* o: Q22 Coefficients of R(x) */ - Word32 S[] /* o: Q22 Coefficients of S(x) */ -) -{ - Word16 xr, xs; - Word16 i, j; - Word32 mh; - UWord16 ml; - - R[0] = (1<<27)-1; - move32(); - S[0] = (1<<27)-1; - move32(); - R[1] = L_msu(0, x[0], 1<<11); - move32(); - S[1] = L_msu(0, x[1], 1<<11); - move32(); - - FOR (i = 2; i <= NC; i++) - { - xr = negate(x[2*i-2]); - xs = negate(x[2*i-1]); - - Mpy_32_16_ss(R[i-1], xr, &R[i], &ml); - Mpy_32_16_ss(S[i-1], xs, &S[i], &ml); - - FOR (j = i-1; j > 0; j--) - { - Mpy_32_16_ss(R[j-1], xr, &mh, &ml); - R[j] = L_add(R[j], mh); - Mpy_32_16_ss(S[j-1], xs, &mh, &ml); - S[j] = L_add(S[j], mh); - } - } - - return; -} - -/*---------------------------------------------------------------------* - * polydecomp() - * - * Computes the coefficients of the symmetric and antisymmetric - * polynomials P(z) and Q(z) that define the line spectrum pair - * decomposition of a given polynomial A(z) of order n. For even n, - * - * P(z) = [A(z) + z^(n+1) A(1/z)]/(1/z + 1), - * Q(z) = [A(z) - z^(n+1) A(1/z)]/(1/z - 1), - * - * These polynomials are then expressed in their direct form, - * respectively, R(x) and S(x), on the real axis x = cos w using - * explicit Chebyshev polynomials of the first kind. - * - * The coefficients of the polynomials R(x) and S(x) are returned - * in R[0:n/2] and S[0:n/2] for the given linear prediction - * coefficients A[0:n/2]. Note that R(x) and S(x) are formed in - * place such that P(z) is stored in the same array than R(x), - * and Q(z) is stored in the same array than S(x). - * - * The routines assumes n = 16. - *---------------------------------------------------------------------*/ - -static void polydecomp_fx( - Word16 A[], /* i: Q12 linear prediction coefficients */ - Word32 R[], /* o: Q20 coefficients of R(x) */ - Word32 S[] /* o: Q20 coefficients of S(x) */ -) -{ - Word16 scale; - Word16 i; - Word32 Ltmp1, Ltmp2; - - scale = shl((1<<5), norm_s(A[0])); - - R[0] = (1<<20)-1; - move32(); /* Q20 */ - S[0] = (1<<20)-1; - move32(); - - FOR(i=0; i +#include "options.h" +#include "cnst.h" +#include "prot.h" +#include "rom_com.h" + + +/*-------------------------------------------------------------------* + * modify_Fs() + * + * Function for resampling of signals + *-------------------------------------------------------------------*/ + +short modify_Fs( /* o : length of output */ + const float sigIn[], /* i : signal to decimate */ + short lg, /* i : length of input + 0 delay signaling */ + const int fin, /* i : frequency of input */ + float sigOut[], /* o : decimated signal */ + const int fout, /* i : frequency of output */ + float mem[] /* i/o: filter memory */ + ,int nblp /* i : flag indicating if NB low-pass is applied */ +) +{ + short i; + short lg_out, fac_num, fac_den, filt_len, frac, mem_len; + float num_den; + short datastep, fracstep; + float *sigIn_ptr; + float signal_tab[3*L_FILT_MAX + L_FRAME48k], *signal, *signal_ana; /* 3* as 2* for memory and 1* for future prediction */ + float A[M+1], r[M+1], epsP[M+1], val; + short mem_len_ana; + short plus_sample_in; + short j; + float mu_preemph; + float mem_preemph; + const Resampling_cfg *cfg_ptr; + short flag_low_order = 0; + short filt_len_tmp; + + /*-------------------------------------------------------------------* + * IIR filters for resampling to/from 8 kHz + *-------------------------------------------------------------------*/ + + /*-------------------------------------------------------------------* + * Find the resampling configuration + *-------------------------------------------------------------------*/ + + if ( fin == fout ) + { + /* just copy the signal and quit */ + for (i = 0; i < lg; i++) + { + sigOut[i] = sigIn[i]; + } + + return lg; + } + else + { + /* find the resampling configuration in the lookup table */ + for (cfg_ptr = &resampling_cfg_tbl[0]; (cfg_ptr->fin != 0) && !(cfg_ptr->fin == fin && cfg_ptr->fout == fout); cfg_ptr++) + { + } + + + /* find config with NB 4kHz low-pass */ + if (nblp && (fin > 8000) && (fout == 12800)) + { + flag_low_order = 1; + for (cfg_ptr++; (cfg_ptr->fin != 0) && !(cfg_ptr->fin == fin && cfg_ptr->fout == fout); cfg_ptr++) + { + } + } + + /* Retrieve and/or calculate the resampling parameters */ + fac_num = cfg_ptr->fac_num; + fac_den = (short)((cfg_ptr->fin * fac_num) / cfg_ptr->fout); + lg_out = (lg * fac_num) / fac_den; + filt_len = cfg_ptr->filt_len; + + mem_len = 2*filt_len; + plus_sample_in = 0; /* default, regular delay */ + frac = 0; + + if ( fin == 8000 && fout == 12800 ) + { + plus_sample_in = 7; + frac = 4; + } + + signal = signal_tab+2*L_FILT_MAX + L_FRAME48k - mem_len - lg; + signal_ana = signal; + mem_len_ana = mem_len; + + } + + /*-------------------------------------------------------------------* + * FIR filters for resampling to/from 12.8, 16, 32, 48 kHz + *-------------------------------------------------------------------*/ + + /* append filter memory */ + for (i=0; i<2*filt_len; i++) + { + signal[i] = mem[i]; + } + + for (i=0; i 0 ) + { + + autocorr( signal_ana+mem_len_ana+lg-LEN_WIN_SSS, r, 1, LEN_WIN_SSS, wind_sss, 0, 0, 0 ); + + mu_preemph = r[1] / r[0]; + mem_preemph = signal_ana[mem_len_ana+lg-LEN_WIN_SSS - 1]; + preemph( signal_ana+mem_len_ana+lg-LEN_WIN_SSS, mu_preemph, LEN_WIN_SSS, &mem_preemph ); + + /* Autocorrelations */ + autocorr( signal_ana+mem_len_ana+lg-LEN_WIN_SSS, r, M, LEN_WIN_SSS, wind_sss, 0, 0, 0 ); + + lag_wind( r, M, fin, LAGW_STRONG ); + + /* Levinson-Durbin */ + lev_dur( A, r, M, epsP ); + + for (i=0; i> 1; + } + + for(i=0; ifilter, frac, fac_num, filt_len_tmp ); + + frac = frac + fracstep; + if ( frac >= fac_num ) + { + frac = frac - fac_num; + sigIn_ptr++; + } + + sigIn_ptr += datastep; + } + + /* rescaling */ + if ( (fac_num > fac_den) == ((cfg_ptr->flags & RS_INV_FAC) != 0) ) + { + num_den = (float)fac_num / fac_den; + + for( i=0; i 0.25 ) */ + k3d = fk1 - 1; /* to compurte index in cu with respect to the last sample with - sign (ex 1.25 -> -0.75 ) */ + + kk = 0; + for(i = 0; i < lg-ct2[cind][11];) + { + sigOut[j++] = sigIn[i]; + for(k = 0; k < ct2[cind][10]; k++) + { + cc[kk][0] = sigIn[i+1]/3; + cc[kk][2] =(sigIn[i]+sigIn[i+2])/2-sigIn[i+1]; + cc[kk][3] = (sigIn[i]+sigIn[i+3]-sigIn[i+1]-sigIn[i+2]-4*cc[kk][2]) / 6; + cc[kk][1] = sigIn[i+2]-sigIn[i+1]-cc[kk][3]-cc[kk][2]; + i++; + + i2 = kk-2; + i1 = kk-1; + if( i1 < 0 ) + { + i1 += 4; + } + + if( i2 < 0 ) + { + i2 += 4; + } + + for(k1 = ct2[cind][k]; k1 < fk1; k1 += ct2[cind][8]) + { + k2 = k1 - k2d; + k3 = k3d - k1; + vv = (float)( cu[k1][2]*cc[i2][3] + cu[k1][1]*cc[i2][2] + cu[k1][0]*cc[i2][1] + cc[i2][0]); + vv += (float)( cu[k2][2]*cc[i1][3] + cu[k2][1]*cc[i1][2] + cu[k2][0]*cc[i1][1] + cc[i1][0]); + vv += (float)(-cu[k3][2]*cc[kk][3] + cu[k3][1]*cc[kk][2] - cu[k3][0]*cc[kk][1] + cc[kk][0]); + sigOut[j++] = vv; + } + + kk++; + if( kk == 4 ) + { + kk = 0; + } + } + } + + sigOut[j++] = sigIn[i]; + + for(k = 0; k < ct2[cind][11]-3; k++) + { + cc[kk][0] = sigIn[i+1]/3; + cc[kk][2] =(sigIn[i]+sigIn[i+2])/2-sigIn[i+1]; + cc[kk][3] = (sigIn[i]+sigIn[i+3]-sigIn[i+1]-sigIn[i+2]-4*cc[kk][2]) / 6; + cc[kk][1] = sigIn[i+2]-sigIn[i+1]-cc[kk][3]-cc[kk][2]; + i++; + + i2 = kk-2; + i1 = kk-1; + if( i1 < 0 ) + { + i1 += 4; + } + + if( i2 < 0 ) + { + i2 += 4; + } + + for(k1 = ct2[cind][k]; k1 < fk1; k1 += ct2[cind][8]) + { + k2 = k1 - k2d; + k3 = k3d - k1; + vv = (float)( cu[k1][2]*cc[i2][3] + cu[k1][1]*cc[i2][2] + cu[k1][0]*cc[i2][1] + cc[i2][0]); + vv += (float)( cu[k2][2]*cc[i1][3] + cu[k2][1]*cc[i1][2] + cu[k2][0]*cc[i1][1] + cc[i1][0]); + vv += (float)(-cu[k3][2]*cc[kk][3] + cu[k3][1]*cc[kk][2] - cu[k3][0]*cc[kk][1] + cc[kk][0]); + sigOut[j++] = vv; + } + + kk++; + + if( kk == 4 ) + { + kk = 0; + } + } + + kk--; + if( kk == -1 ) + { + kk = 3; + } + + if( ct2[cind][10] == 1 ) + { + sigOut[j++] = sigIn[i]; + } + + for(k1 = ct2[cind][k]; k1 < fk1; k1 += ct2[cind][8]) + { + k2 = k1 - k2d; + vv = (float)( cu[k2][2]*cc[kk][3] + cu[k2][1]*cc[kk][2] + cu[k2][0]*cc[kk][1] + cc[kk][0]); + sigOut[j++] = vv*3; + } + + if( ct2[cind][10] < 3 ) + { + sigOut[j++] = sigIn[i+1]; + } + + for( k1 = ct2[cind][k+1]; k1 < fk1; k1 += ct2[cind][8] ) + { + vv = (float)( cu[k1][2]*cc[kk][3] + cu[k1][1]*cc[kk][2] + cu[k1][0]*cc[kk][1] + cc[kk][0]); + sigOut[j++] = vv*3; + } + + if( ct2[cind][10] == 1 ) + { + sigOut[j++] = sigIn[i+2]; + } + } + + return lg_out; +} + +/*-------------------------------------------------------------------* + * Interpolate_allpass_steep() + * + * Interpolation by a factor 2 + *-------------------------------------------------------------------*/ + +void Interpolate_allpass_steep( + const float *in, /* i : input array of size N */ + float *state, /* i/o: memory */ + const short N, /* i : number of input samples */ + float *out /* o : output array of size 2*N */ +) +{ + short n, k; + float temp[ALLPASSSECTIONS_STEEP - 1]; + + /* upper allpass filter chain */ + for (k = 0; k < N; k++) + { + temp[0] = state[0] + AP2_STEEP[0] * in[k]; + state[0] = in[k] - AP2_STEEP[0] * temp[0]; + + /* for better performance, unroll this loop */ + for (n = 1; n < ALLPASSSECTIONS_STEEP - 1; n++) + { + temp[n] = state[n] + AP2_STEEP[n] * temp[n - 1]; + state[n] = temp[n - 1] - AP2_STEEP[n] * temp[n]; + } + + out[2 * k + 1] = state[ALLPASSSECTIONS_STEEP - 1] + AP2_STEEP[ALLPASSSECTIONS_STEEP - 1] * temp[ALLPASSSECTIONS_STEEP - 2]; + state[ALLPASSSECTIONS_STEEP - 1] = temp[ALLPASSSECTIONS_STEEP - 2] - AP2_STEEP[ALLPASSSECTIONS_STEEP - 1] * out[2 * k + 1]; + } + + /* lower allpass filter chain */ + for (k = 0; k < N; k++) + { + temp[0] = state[ALLPASSSECTIONS_STEEP] + AP1_STEEP[0] * in[k]; + state[ALLPASSSECTIONS_STEEP] = in[k] - AP1_STEEP[0] * temp[0]; + + /* for better performance, unroll this loop */ + for (n = 1; n < ALLPASSSECTIONS_STEEP - 1; n++) + { + temp[n] = state[ALLPASSSECTIONS_STEEP + n] + AP1_STEEP[n] * temp[n - 1]; + state[ALLPASSSECTIONS_STEEP + n] = temp[n - 1] - AP1_STEEP[n] * temp[n]; + } + + out[2 * k] = state[2 * ALLPASSSECTIONS_STEEP - 1] + AP1_STEEP[ALLPASSSECTIONS_STEEP - 1] * temp[ALLPASSSECTIONS_STEEP - 2]; + state[2 * ALLPASSSECTIONS_STEEP - 1] = temp[ALLPASSSECTIONS_STEEP - 2] - AP1_STEEP[ALLPASSSECTIONS_STEEP - 1] * out[2 * k]; + } + + return; +} + +/*-------------------------------------------------------------------* + * Decimate_allpass_steep() + * + * Decimation by a factor 2 + *-------------------------------------------------------------------*/ + +void Decimate_allpass_steep ( + const float *in, /* i : input array of size N */ + float *state, /* i/o: memory */ + const short N, /* i : number of input samples */ + float *out /* o : output array of size N/2 */ +) +{ + short n, k; + float temp[ALLPASSSECTIONS_STEEP]; + + /* upper allpass filter chain */ + for (k = 0; k < N / 2; k++) + { + temp[0] = state[0] + AP1_STEEP[0] * in[2 * k]; + state[0] = in[2 * k] - AP1_STEEP[0] * temp[0]; + + /* for better performance, unroll this loop */ + for (n = 1; n < ALLPASSSECTIONS_STEEP - 1; n++) + { + temp[n] = state[n] + AP1_STEEP[n] * temp[n - 1]; + if( fabs(temp[n]) < 1e-12 ) + { + temp[n] = sign(temp[n])*1e-12; + } + state[n] = temp[n - 1] - AP1_STEEP[n] * temp[n]; + } + + out[k] = state[ALLPASSSECTIONS_STEEP - 1] + AP1_STEEP[ALLPASSSECTIONS_STEEP - 1] * temp[ALLPASSSECTIONS_STEEP - 2]; + state[ALLPASSSECTIONS_STEEP - 1] = temp[ALLPASSSECTIONS_STEEP - 2] - AP1_STEEP[ALLPASSSECTIONS_STEEP - 1] * out[k]; + } + + /* lower allpass filter chain */ + temp[0] = state[ALLPASSSECTIONS_STEEP] + AP2_STEEP[0] * state[2 * ALLPASSSECTIONS_STEEP]; + state[ALLPASSSECTIONS_STEEP] = state[2 * ALLPASSSECTIONS_STEEP] - AP2_STEEP[0] * temp[0]; + + /* for better performance, unroll this loop */ + for (n = 1; n < ALLPASSSECTIONS_STEEP - 1; n++) + { + temp[n] = state[ALLPASSSECTIONS_STEEP + n] + AP2_STEEP[n] * temp[n - 1]; + if( fabs(temp[n]) < 1e-12 ) + { + temp[n] = sign(temp[n])*1e-12; + } + state[ALLPASSSECTIONS_STEEP + n] = temp[n - 1] - AP2_STEEP[n] * temp[n]; + } + + temp[ALLPASSSECTIONS_STEEP - 1] = state[2 * ALLPASSSECTIONS_STEEP - 1] + AP2_STEEP[ALLPASSSECTIONS_STEEP - 1] * + temp[ALLPASSSECTIONS_STEEP -2]; + + state[2 * ALLPASSSECTIONS_STEEP - 1] = temp[ALLPASSSECTIONS_STEEP - 2] - AP2_STEEP[ALLPASSSECTIONS_STEEP - 1] * + temp[ALLPASSSECTIONS_STEEP - 1]; + out[0] = (float)((out[0] + temp[ALLPASSSECTIONS_STEEP - 1]) * 0.5); + + for (k = 1; k < N / 2; k++) + { + temp[0] = state[ALLPASSSECTIONS_STEEP] + AP2_STEEP[0] * in[2 * k - 1]; + state[ALLPASSSECTIONS_STEEP] = in[2 * k - 1] - AP2_STEEP[0] * temp[0]; + + /* for better performance, unroll this loop */ + for (n = 1; n < ALLPASSSECTIONS_STEEP - 1; n++) + { + temp[n] = state[ALLPASSSECTIONS_STEEP + n] + AP2_STEEP[n] * temp[n - 1]; + if( fabs(temp[n]) < 1e-12 ) + { + temp[n] = sign(temp[n])*1e-12; + } + state[ALLPASSSECTIONS_STEEP + n] = temp[n - 1] - AP2_STEEP[n] * temp[n]; + } + + temp[ALLPASSSECTIONS_STEEP - 1] = state[2 * ALLPASSSECTIONS_STEEP - 1] + AP2_STEEP[ALLPASSSECTIONS_STEEP - 1] * + temp[ALLPASSSECTIONS_STEEP - 2]; + state[2 * ALLPASSSECTIONS_STEEP - 1] = temp[ALLPASSSECTIONS_STEEP - 2] - AP2_STEEP[ALLPASSSECTIONS_STEEP - 1] * + temp[ALLPASSSECTIONS_STEEP - 1]; + out[k] = (float)((out[k] + temp[ALLPASSSECTIONS_STEEP - 1]) * 0.5); + } + + /* z^(-1) */ + state[2 * ALLPASSSECTIONS_STEEP] = in[N - 1]; + + return; +} + +/*-------------------------------------------------------------------* + * interpolate_3_over_2_allpass() + * + * Interpolate 3/2 using allpass iir polyphase filter. Delay 4 samples @48k + *-------------------------------------------------------------------*/ + +void interpolate_3_over_2_allpass( + const float *input, /* i : input signal */ + const short len, /* i : number of input samples */ + float *out, /* o : output signal */ + float *mem, /* i/o: memory */ + const float *filt_coeff /* i : filter coefficients */ +) +{ + short i, loop_len; + float Vu[2], Vm[2], Vl[2]; /* Outputs of three cascaded allpass stages (upper, middle, and lower) */ + float out1_buff[L_FRAME32k*3]; + float * out1; + float mem_temp; + + out1 = out1_buff; + + for (i = 0; i < len; i++ ) + { + /* Upper branch */ + Vu[0] = mem[0] + filt_coeff[0] * ( input[i] - mem[1] ); + Vu[1] = mem[1] + filt_coeff[1] * ( Vu[0] - mem[2] ); + mem[3] = mem[2] + filt_coeff[2] * ( Vu[1] - mem[3] ); + + mem[1] = Vu[0]; + mem[2] = Vu[1]; + *out1++ = mem[3]; + + /* Middle branch */ + Vm[0] = mem[0] + filt_coeff[3] * (input[i]-mem[4]); + Vm[1] = mem[4] + filt_coeff[4] * (Vm[0]-mem[5]); + mem[6] = mem[5] + filt_coeff[5] * (Vm[1]-mem[6]); + + mem[4] = Vm[0]; + mem[5] = Vm[1]; + *out1++ = mem[6]; + + /* Lower branch */ + Vl[0] = mem[0] + filt_coeff[6] * (input[i]-mem[7]); + Vl[1] = mem[7] + filt_coeff[7] * (Vl[0]-mem[8]); + mem[9] = mem[8] + filt_coeff[8] * (Vl[1]-mem[9]); + + mem[0] = input[i]; + mem[7] = Vl[0]; + mem[8] = Vl[1]; + *out1++ = mem[9]; + } + + loop_len = len*3/2; + + /*decimate by 2 and LPF*/ + for(i = 0; i < loop_len; i++) + { + mem_temp = out1_buff[2*i]; + out[i] = (((0.0473147f)*(mem_temp+mem[10]))+((-0.151521f)*(mem[11]+mem[14]))); + out[i] = (out[i]+((0.614152f)*(mem[12]+mem[13]))); + mem[10] = mem[11]; + mem[11] = mem[12]; + mem[12] = mem[13]; + mem[13] = mem[14]; + mem[14] = mem_temp; + } + return; +} + +/*-------------------------------------------------------------------* +* decimate_2_over_3_allpass() +* +* Decimate 2/3 using allpass iir polyphase filter. +*-------------------------------------------------------------------*/ + +void decimate_2_over_3_allpass( + const float *input, /* i : input signal */ + const short len, /* i : number of input samples */ + float *out, /* o : output signal */ + float *mem, /* i/o: memory */ + const float *filt_coeff, /* i : filter coefficients */ + const float *lp_num, + const float *lp_den, + float *lp_mem +) +{ + short i, loop_len; + float Vu[2], Vm[2], Vl[2]; /* Outputs of three cascaded allpass stages (upper, middle, and lower) */ + float * out1; + float *in; + float out1_buff[L_FRAME48k*2]; + float tmp; + + /* Combine the 2nd order iir lpf with the decimation by 2 to improve the efficiency*/ + out1 = out1_buff; + + *out1++ = lp_num[0] * ( input[0] + lp_mem[0] ) - lp_den[2] * lp_mem[2]; + *out1++ = lp_num[1] * input[0] - lp_den[2] * lp_mem[1]; + + for (i=1; i < len; i++) + { + tmp = lp_num[0] * ( input[i] + input[i-1] ) - lp_den[2] * out1[-2]; + *out1++ = tmp; + tmp = lp_num[1] * input[i] - lp_den[2] * out1[-2]; + *out1++ = tmp; + } + lp_mem[0] = input[len-1]; + lp_mem[1] = out1[-1]; + lp_mem[2] = out1[-2]; + + /* do the all pass polyphase filter with pi/3 cutoff */ + out1 = out; + in = out1_buff; + loop_len = (short) len*2/3; + + for (i = 0; i < loop_len; i++ ) + { + /* Lower branch */ + Vl[0] = mem[8] + filt_coeff[6] * (*in - mem[9]); + Vl[1] = mem[9] + filt_coeff[7] * (Vl[0] - mem[10]); + mem[11] = mem[10] + filt_coeff[8] * (Vl[1] - mem[11]); + + mem[8] = *in++; + mem[9] = Vl[0]; + mem[10] = Vl[1]; + *out1 = mem[11]; + + /* Middle branch */ + Vm[0] = mem[4] + filt_coeff[3] * (*in - mem[5]); + Vm[1] = mem[5] + filt_coeff[4] * (Vm[0]-mem[6]); + mem[7] = mem[6] + filt_coeff[5] * (Vm[1]-mem[7]); + + mem[4] = *in++; + mem[5] = Vm[0]; + mem[6] = Vm[1]; + *out1 += mem[7]; + + /* Upper branch */ + Vu[0] = mem[0] + filt_coeff[0] * ( *in - mem[1] ); + Vu[1] = mem[1] + filt_coeff[1] * ( Vu[0] - mem[2] ); + mem[3] = mem[2] + filt_coeff[2] * ( Vu[1] - mem[3] ); + + mem[0] = *in++; + mem[1] = Vu[0]; + mem[2] = Vu[1]; + *out1++ += mem[3]; + } + + return; +} + +/*-------------------------------------------------------------------* + * interpolate_3_over_1_allpass() + * + * Interpolate 3/1 using allpass iir polyphase filter. Delay 4 samples @48k + *-------------------------------------------------------------------*/ + +void interpolate_3_over_1_allpass( + const float *input, /* i : input signal */ + const short len, /* i : number of input samples */ + float *out, /* o : output signal */ + float *mem, /* i/o: memory */ + const float *filt_coeff /* i : filter coefficients */ +) +{ + short i; + float Vu[2], Vm[2], Vl[2]; /* Outputs of three cascaded allpass stages (upper, middle, and lower) */ + float * out1; + float mem_temp; + out1 = &out[0]; + + for (i = 0; i < len; i++ ) + { + /* Upper branch */ + Vu[0] = mem[0] + filt_coeff[0] * ( input[i] - mem[1] ); + Vu[1] = mem[1] + filt_coeff[1] * ( Vu[0] - mem[2] ); + mem[3] = mem[2] + filt_coeff[2] * ( Vu[1] - mem[3] ); + + mem[1] = Vu[0]; + mem[2] = Vu[1]; + *out1++ = mem[3]; + + /* Middle branch */ + Vm[0] = mem[0] + filt_coeff[3] * (input[i]-mem[4]); + Vm[1] = mem[4] + filt_coeff[4] * (Vm[0]-mem[5]); + mem[6] = mem[5] + filt_coeff[5] * (Vm[1]-mem[6]); + + mem[4] = Vm[0]; + mem[5] = Vm[1]; + *out1++ = mem[6]; + + /* Lower branch */ + Vl[0] = mem[0] + filt_coeff[6] * (input[i]-mem[7]); + Vl[1] = mem[7] + filt_coeff[7] * (Vl[0]-mem[8]); + mem[9] = mem[8] + filt_coeff[8] * (Vl[1]-mem[9]); + + mem[0] = input[i]; + mem[7] = Vl[0]; + mem[8] = Vl[1]; + *out1++ = mem[9]; + } + + /*LPF*/ + for(i = 0; i < len*3; i++) + { + mem_temp = out[i]; + out[i] = (((0.572769f)*(mem[12]+mem[11]))-((0.074005f)*(mem_temp+mem[10]))); + mem[10] = mem[11]; + mem[11] = mem[12]; + mem[12] = mem_temp; + } + + return; +} + + +/*-------------------------------------------------------------------* + * retro_interp4_5() + * + * + *-------------------------------------------------------------------*/ + +void retro_interp4_5( + const float *syn, + float *pst_old_syn +) +{ + float *pf5, *pf4; + short c; + + /* resample st->pst_old_syn in a reverse way to preserve time-alignment */ + pf4 = (float*) &pst_old_syn[58]; + pf5 = (float*) pst_old_syn; + for (c=0; c<57; c++) + { + *pf5++ = pf4[0]; + *pf5++ = 0.2f * pf4[0] + 0.8f * pf4[1]; + *pf5++ = 0.4f * pf4[1] + 0.6f * pf4[2]; + *pf5++ = 0.6f * pf4[2] + 0.4f * pf4[3]; + *pf5++ = 0.8f * pf4[3] + 0.2f * pf4[4]; + pf4+=4; + } + *pf5++ = pf4[0]; + *pf5++ = 0.2f * pf4[0] + 0.8f * pf4[1]; + *pf5++ = 0.4f * pf4[1] + 0.6f * pf4[2]; + *pf5++ = 0.6f * pf4[2] + 0.4f * pf4[3]; + *pf5++ = 0.8f * pf4[3] + 0.2f * syn[0]; + /* all samples processed: NBPSF_PIT_MAX = 290 = (58*5) */ + + return; +} + + +/*-------------------------------------------------------------------* + * retro_interp5_4() + * + * + *-------------------------------------------------------------------*/ + +void retro_interp5_4( float *pst_old_syn ) +{ + float *pf5, *pf4; + short c; + + /* resample st->pst_old_syn in a reverse way to preserve time-alignment */ + pf4 = (float*) &pst_old_syn[NBPSF_PIT_MAX-1]; + pf5 = pf4; + for (c=0; c<58; c++) + { + *pf4-- = 0.75f * pf5[0] + 0.25f * pf5[-1]; + *pf4-- = 0.50f * pf5[-1] + 0.50f * pf5[-2]; + *pf4-- = 0.25f * pf5[-2] + 0.75f * pf5[-3]; + *pf4-- = pf5[-4]; + pf5-=5; + } + /* all samples processed: NBPSF_PIT_MAX = 290 = (58*5) */ + + return; +} + diff --git a/src/libs/libevs/lib_com/modif_fs_fx.cpp b/src/libs/libevs/lib_com/modif_fs_fx.cpp deleted file mode 100755 index 8a253909..00000000 --- a/src/libs/libevs/lib_com/modif_fs_fx.cpp +++ /dev/null @@ -1,1297 +0,0 @@ -/*==================================================================================== - EVS Codec 3GPP TS26.442 Apr 03, 2018. Version 12.11.0 / 13.6.0 / 14.2.0 - ====================================================================================*/ - -#include -#include "options.h" /* Compilation switches */ -#include "cnst_fx.h" /* Common constants */ -#include "prot_fx.h" /* Function prototypes */ -#include "rom_com_fx.h" /* Static table prototypes */ -#include -#include "rom_enc_fx.h" /* prototypes */ -#include "stl.h" - -#include "basop_util.h" - -/*-----------------------------------------------------------------* - * Local functions - *-----------------------------------------------------------------*/ - - - -/*==============================================================================*/ -/* FUNCTION : modify_Fs_fx ( ) */ -/*------------------------------------------------------------------------------*/ -/* PURPOSE : Modify sampling freq by interpolation */ -/*------------------------------------------------------------------------------*/ -/* INPUT ARGUMENTS : */ -/* const Word16 sigIn_fx[] signal to decimate Q_syn2-1 */ -/* const Word16 lg length of input */ -/* const Word16 fin frequency of input Q0 */ -/* const Word16 fout frequency of output Q0 */ -/*------------------------------------------------------------------------------*/ -/* OUTPUT ARGUMENTS : */ -/* Word16 sigOut_fx[] decimated signal Q_syn2-1 */ -/*------------------------------------------------------------------------------*/ -/* INPUT/OUTPUT ARGUMENTS : */ -/* Word16 mem_fx[] filter memory Q_syn2-1 */ -/*------------------------------------------------------------------------------*/ -/* RETURN ARGUMENTS : */ -/* _ None. */ -/*------------------------------------------------------------------------------*/ -/* CALLED FROM : TX/RX */ -/*==============================================================================*/ -Word16 modify_Fs_fx( /* o : length of output Q0 */ - const Word16 sigIn_fx[], /* i : signal to decimate Q0 */ - Word16 lg, /* i : length of input Q0 */ - const Word32 fin, /* i : frequency of input Q0 */ - Word16 sigOut_fx[], /* o : decimated signal Q0 */ - const Word32 fout, /* i : frequency of output Q0 */ - Word16 mem_fx[] /* i/o: filter memory Q0 */ - ,const Word16 nblp /* i : flag indicating if NB low-pass is applied */ -) -{ - Word16 i; - - Word16 lg_out, fac_num, fac_den, filt_len, frac, temp_n, mem_len; - Word16 num_den; - Word16 datastep, fracstep; - Word16 *sigIn_ptr, *sigPtr; - Word16 signal_tab_fx[3*L_FILT_MAX + L_FRAME48k], *signal_fx, *signal_ana_fx; /* 3* as 2* for memory and 1* for future prediction */ - Word16 A_fx[M+1], r_fx_h[M+1], r_fx_l[M+1]; - Word16 mem_len_ana; - Word16 plus_sample_in; - Word16 j; - Word16 mu_preemph_fx; - Word16 mem_preemph_fx; - Word16 Q_r; - Word16 mem_lev_fx[18]; - Word32 t0, t1, t2, L_tmp; /* temporary variables */ - Word32 LepsP[M+1]; - Word16 flag_low_order = 0; - Word16 filt_len_tmp; - - const Resampling_cfg_fx *cfg_ptr_fx; - - /*-------------------------------------------------------------------* - * Find the resampling configuration - *-------------------------------------------------------------------*/ - - /* check if fin and fout are the same */ - IF (L_sub(fin,fout) == 0) - { - /* just copy the signal_fx and quit */ - Copy(sigIn_fx, sigOut_fx, lg); - - return lg; - } - ELSE - { - /* find the resampling configuration in the lookup table */ - cfg_ptr_fx = &resampling_cfg_tbl_fx[0]; - WHILE ( (cfg_ptr_fx->fin_fx != 0) && !(L_sub(cfg_ptr_fx->fin_fx,fin) == 0 && L_sub(cfg_ptr_fx->fout_fx,fout) == 0) ) - { - test(); - test(); - cfg_ptr_fx++; - } - - - /* find config with NB 4kHz low-pass */ - test(); - test(); - IF ( nblp && (L_sub(fin, 8000) > 0) && (L_sub(fout, 12800) == 0) ) - { - flag_low_order = 1; - move16(); - cfg_ptr_fx++; - WHILE ( (cfg_ptr_fx->fin_fx != 0) && !( (L_sub(cfg_ptr_fx->fin_fx, fin) == 0) && (L_sub(cfg_ptr_fx->fout_fx, fout) == 0)) ) - { - test(); - test(); - cfg_ptr_fx++; - } - } - - /*-------------------------------------------------------------------* - * Retrieve and/or calculate the resampling parameters - *-------------------------------------------------------------------*/ - fac_num = cfg_ptr_fx->fac_num_fx; - move16();/*Q0*/ - fac_den = cfg_ptr_fx->fac_den_fx; - move16(); - - IF(sub(lg,L_FRAME)>=0) - { - lg_out = cfg_ptr_fx->lg_out ; - move16(); - } - ELSE - { - lg_out = idiv1616(i_mult2(lg, fac_num), fac_den); - } - filt_len = cfg_ptr_fx->filt_len_fx; - move16(); - plus_sample_in = 0; - move16();/*default, regular delay*/ - frac = 0; - move16(); - - test(); - IF ( (L_sub(fin, 8000) == 0) && (L_sub(fout, 12800) == 0) ) - { - plus_sample_in = 7; - move16(); - frac = 4; - move16(); - } - - mem_len = shl(filt_len,1); - signal_fx = signal_tab_fx+2*L_FILT_MAX + sub(L_FRAME48k, add(mem_len, lg)); - signal_ana_fx = signal_fx; - mem_len_ana = mem_len; - move16(); - } - - - /*-------------------------------------------------------------------* - * Resample - *-------------------------------------------------------------------*/ - /* append filter memory */ - Copy(mem_fx, signal_fx, mem_len); - - sigPtr = signal_fx + mem_len; - Copy(sigIn_fx, sigPtr, lg); - - IF(plus_sample_in > 0) - { - autocorr_fx( signal_ana_fx+mem_len_ana+lg-LEN_WIN_SSS, 1, r_fx_h, r_fx_l, &Q_r, LEN_WIN_SSS, wind_sss_fx, 0, 0 ); - - - t1 = L_Comp(r_fx_h[1], r_fx_l[1]); /* R[1] in Q31 */ - t2 = L_abs(t1); /* abs R[1] */ - t0 = L_deposit_l(0); - IF (r_fx_h[0] != 0) - { - t0 = Div_32(t2, r_fx_h[0], r_fx_l[0]); /* R[1]/R[0] in Q31 */ - } - if (t1 < 0) - { - t0 = L_negate(t0); /* R[1]/R[0] */ - } - - - - mu_preemph_fx = extract_h(t0); /*r_fx[1] / r_fx[0]; */ - mem_preemph_fx = signal_ana_fx[mem_len_ana+lg-LEN_WIN_SSS - 1]; - move16(); - preemph_fx(signal_ana_fx+mem_len_ana+lg-LEN_WIN_SSS, mu_preemph_fx, LEN_WIN_SSS, &mem_preemph_fx); - - - /* Autocorrelations */ - autocorr_fx( signal_ana_fx+mem_len_ana+lg-LEN_WIN_SSS, M, r_fx_h, r_fx_l, &Q_r, - LEN_WIN_SSS, wind_sss_fx, 0, 0 ); - - /* Lag windowing */ - lag_wind( r_fx_h, r_fx_l, M, fin, LAGW_STRONG ); - - /* Levinson-Durbin */ - set16_fx(mem_lev_fx, 0, 18 ); - E_LPC_lev_dur(r_fx_h, r_fx_l, A_fx, LepsP, M, NULL); - - Copy_Scale_sig( A_fx, A_fx, M+1, sub(norm_s(A_fx[0]),2) ); - - FOR (i=0; ifilter_fx, frac, fac_num, filt_len_tmp )); - - frac = add(frac,fracstep); - - j = sub(fac_num, frac); - if (j < 0) - { - frac = sub(frac,fac_num); - } - sigIn_ptr += add(lshr(j, 15), datastep); - } - /* rescaling */ - test(); - IF ((sub(fac_num,fac_den) > 0) == ((cfg_ptr_fx->flags_fx & RS_INV_FAC) != 0)) - { - IF(sub(fac_num, fac_den) < 0) - { - num_den = div_s(fac_num,fac_den);/*Q15*/ - test(); - IF( L_sub(fin, 16000) > 0 && sub(lg_out, 512) == 0 ) - { - - FOR( i=0; i 0 && ( sub(lg_out, L_FRAME) == 0 || sub(lg_out, L_FRAME16k) == 0 || sub(lg_out, 512) == 0) ) - { - num_den = shl(num_den, 1); - } - FOR( i=0; iflags_fx & RS_INV_FAC) != 0)) - { - FOR( i=0; i Q(-QSR) */ - } - - /* length of the interpolated signal */ - /*lg_out = (short)(lg * fout / fin); */ - - /* cc[x][3]*s*s*s + cc[x][2]*s*s + cc[x][1]*s + cc[x][0]; indexes relatives of s : -1 0 1 2 */ - /* d : cc[x][0] = s[0] */ - /* b : cc[x][2] =(s[-1]+s[1])/2-s[0] */ - /* a : cc[x][3] = (s[-1]+s[2]-s[0]-s[1]-4*cc[x][2]) / 6 */ - /* c : cc[x][1] = s[1]-s[0]-cc[x][3]-cc[x][2] */ - - /* coef inits using memory (indexes < 0) */ - /* cc[2][] : indexes -2 -1 0 1 */ - cptr = &(cc[2][0]); - cptr[0] = mult_r(sigin_sr[-1], 10923); - move16(); /* sigIn[-1]/3 */ - cptr[2] = sub(shr(add(sigin_sr[-2], sigin_sr[0]), 1), sigin_sr[-1]); - move16(); /* (sigIn[-2]+sigIn[0])/2-sigIn[-1]; */ - cptr[3] = sub(mult_r(sub(add(sigin_sr[-2], sigin_sr[1]), add(sigin_sr[-1], sigin_sr[0])), 5461), mult_r(cptr[2],21845)); - move16(); /*(sigIn[-2]+sigIn[1]-sigIn[-1]-sigIn[0]) / 6 - 4/6*cc[2][2]);*/ - cptr[1] = sub(sub(sigin_sr[0], sigin_sr[-1]), add(cptr[3], cptr[2])); - move16(); - - /* cc[3][] : indexes -1 0 1 2 */ - cptr = &(cc[3][0]); - cptr[0] = mult_r(sigin_sr[0], 10923); - move16();/* sigIn[-1]/3 */ - cptr[2] = sub(shr(add(sigin_sr[-1], sigin_sr[1]), 1), sigin_sr[0]); - move16(); /* (sigIn[-1]+sigIn[1])/2-sigIn[0]; */ - cptr[3] = sub(mult_r(sub(add(sigin_sr[-1], sigin_sr[2]), add(sigin_sr[0], sigin_sr[1])), 5461), mult_r(cptr[2],21845)); - move16(); /*(sigIn[-2]+sigIn[1]-sigIn[-1]-sigIn[0]) / 6 - 4/6*cc[2][2]);*/ - cptr[1] = sub(sub(sigin_sr[1], sigin_sr[0]), add(cptr[3], cptr[2])); - move16(); - - sigOutptr = sigOut; - cind = -1; - move16(); - move16(); /* for the move */ - IF( L_sub(fin, 12800) == 0 ) - { - if( L_sub(fout, 8000) == 0 ) - { - cind = 0; - move16(); - } - if( L_sub(fout, 16000) == 0 ) - { - cind = 1; - move16(); - } - if( L_sub(fout, 32000) == 0 ) - { - cind = 2; - move16(); - } - if( L_sub(fout, 48000) == 0 ) - { - cind = 3; - move16(); - } - } - IF( L_sub(fin, 16000) == 0) - { - if( L_sub(fout, 12800) == 0 ) - { - cind = 4; - move16(); - } - if( L_sub(fout, 32000) == 0 ) - { - cind = 5; - move16(); - } - if( L_sub(fout, 48000) == 0 ) - { - cind = 6; - move16(); - } - - } - ctptr = &(ct2_fx[cind][0]); - lg_out = mult_r(shl(lg,2),ctptr[13]); - *delayout = ctptr[9]; - move16(); - - if( sub(ctptr[12], 15) == 0 ) - { - cu = cu15_fx; - move16();/*pointer*/ - } - - if( sub(ctptr[12],4) == 0 ) - { - cu = cu4_fx; - move16();/*pointer*/ - } - - k2d = sub(ctptr[12], 1); /* shift of index in cu with respect to the next sample (ex 1.25 -> 0.25 ) */ - fk1 = shl(k2d, 1); - k3d = sub(fk1, 1); /* to compurte index in cu with respect to the last sample with - sign (ex 1.25 -> -0.75 ) */ - - kk = 0; - move16(); - i = 0; - move16(); - - lim = sub(lg, ctptr[11]); - lim2 = sub(lg, 3); - lim3 = ctptr[10]; - move16(); - WHILE(sub(i, lim2) < 0) - { - if(sub(i, lim) >= 0) - { - lim3 = sub(ctptr[11], 3); /* last, incomplete period*/ - } - *sigOutptr++ = sigIn[i]; - move16(); - FOR(k = 0; k < lim3; k++) - { - cptr = &(cc[kk][0]); - cptr[0] = mult_r(sigin_sr[i+1], 10923); - move16();/* sigIn[-1]/3 */ - cptr[2] = sub(shr(add(sigin_sr[i], sigin_sr[i+2]), 1), sigin_sr[i+1]); - move16(); /* (sigIn[-1]+sigIn[1])/2-sigIn[0]; */ - cptr[3] = sub(mult_r(sub(add(sigin_sr[i], sigin_sr[i+3]), add(sigin_sr[i+1], sigin_sr[i+2])), 5461), mult_r(cptr[2],21845)); - move16(); /*(sigIn[-1]+sigIn[1]-sigIn[0]-sigIn[1]) / 6 - 4/6*cc[3][2]);*/ - cptr[1] = sub(sub(sigin_sr[i+2], sigin_sr[i+1]), add(cptr[3], cptr[2])); - move16(); - i = add(i,1); - - i2 = sub(kk, 2); - i1 = sub(kk, 1); - if( i1 < 0 ) - { - i1 = add(i1, 4); - } - - if( i2 < 0 ) - { - i2 = add(i2, 4); - } - inc = ctptr[8]; - move16(); - FOR(k1 = ctptr[k]; k1 < fk1; k1 += inc) - { - k2 = sub(k1, k2d); - k3 = sub(k3d, k1); - cptr = &(cc[i2][0]); - uptr = &(cu[k1][0]); - vv32 = L_mult( 8192, *cptr++); - vv32 = L_mac(vv32, *uptr++, *cptr++); - vv32 = L_mac(vv32, *uptr++, *cptr++); - vv32 = L_mac(vv32, *uptr++, *cptr++); /* Q13*Q(-QSR) -> Q(13-QSR+1) 32 bits*/ - cptr = &(cc[i1][0]); - uptr = &(cu[k2][0]); - vv32 = L_mac(vv32, 8192, *cptr++); - vv32 = L_mac(vv32, *uptr++, *cptr++); - vv32 = L_mac(vv32, *uptr++, *cptr++); - vv32 = L_mac(vv32, *uptr++, *cptr++); - cptr = &(cc[kk][0]); - uptr = &(cu[k3][0]); - vv32 = L_mac(vv32, 8192, *cptr++); - vv32 = L_msu(vv32, *uptr++, *cptr++); - vv32 = L_mac(vv32, *uptr++, *cptr++); - vv32 = L_msu(vv32, *uptr++, *cptr++); - vv32 = L_shl(vv32, (QSR+2)); /* Q(13-QSR+1) -> Q16 */ - *sigOutptr++ = round_fx(vv32); /* Q16 -> Q0*/ - } - - kk = add(kk, 1); - if( sub(kk, 4) == 0 ) - { - kk = 0; - move16(); - } - } - } - - - kk = sub(kk, 1); - if( kk < 0 ) - { - kk = 3; - move16(); - } - - if( sub(ctptr[10], 1) == 0 ) - { - *sigOutptr++ = sigIn[i]; - move16(); - } - - FOR(k1 = ctptr[k]; k1 < fk1; k1 += inc) - { - k2 = sub(k1, k2d); - - cptr = &(cc[kk][0]); - uptr = &(cu[k2][0]); - vv32 = L_mult( 8192, *cptr++); - vv32 = L_mac(vv32, *uptr++, *cptr++); - vv32 = L_mac(vv32, *uptr++, *cptr++); - vv32 = L_mac(vv32, *uptr++, *cptr++); /* Q13*Q(-QSR) -> Q(13-QSR+1) 32 bits*/ - vv32 = L_shl(vv32, (QSR+2)); /* Q(13-QSR+1) -> Q16 */ - *sigOutptr++ = i_mult(round_fx(vv32), 3); - move16();/* Q16 -> Q0*/ - } - - if( sub(ctptr[10], 3) < 0 ) - { - *sigOutptr++ = sigIn[add(i, 1)]; - move16(); - } - - FOR( k1 = ctptr[add(k, 1)]; k1 < fk1; k1 += inc ) - { - cptr = &(cc[kk][0]); - uptr = &(cu[k1][0]); - vv32 = L_mult( 8192, *cptr++); - vv32 = L_mac(vv32, *uptr++, *cptr++); - vv32 = L_mac(vv32, *uptr++, *cptr++); - vv32 = L_mac(vv32, *uptr++, *cptr++); /* Q13*Q(-QSR) -> Q(13-QSR+1) 32 bits*/ - vv32 = L_shl(vv32, (QSR+2)); /* Q(13-QSR+1) -> Q16 */ - *sigOutptr++ = i_mult(round_fx(vv32), 3); - move16();/* Q16 -> Q0*/ - } - - if( sub(ctptr[10], 1) == 0 ) - { - *sigOutptr = sigIn[add(i, 2)]; - move16(); - } - } - - free(sigin_sr_tab); - - return lg_out; -} - -/*====================================================================*/ -/* FUNCTION : Decimate_allpass_steep_fx1 () */ -/*-------------------------------------------------------------------*/ -/* PURPOSE : decimation by a factor 2 */ -/*-------------------------------------------------------------------*/ -/* INPUT ARGUMENTS : */ -/* _ (const Word16 *) in_fx : input speech, Q0 */ -/* _ (Word16 []) state_fx: Stateinfo, Q0 */ -/* Size: 2*ALLPASSSECTIONS_STEEP+1 */ -/* _ (Word16) N: Number of Input samples */ -/* _ (Word16 []) out_fx :Output arry of size N/2 Q0 */ -/*-------------------------------------------------------------------*/ -/* OUTPUT ARGUMENTS : */ -/* _ (Word16 []) out_fx : output-signal, Q0 */ -/* _ (Word16 []) state_fx:gets updated, Q0 */ -/*-------------------------------------------------------------------*/ -/* INPUT/OUTPUT ARGUMENTS : */ -/*-------------------------------------------------------------------*/ -/* RETURN ARGUMENTS : _ None. */ -/*===================================================================*/ - - -void Decimate_allpass_steep_fx( const Word16 *in_fx, - Word16 state_fx[], /* array of size: 2*ALLPASSSECTIONS_STEEP+1 */ - Word16 N, /* number of input samples */ - Word16 out_fx[]) /* array of size N/2 */ -{ - - Word16 k; - Word16 temp[ ALLPASSSECTIONS_STEEP ]; - Word32 Lacc, Lacc1; - Word16 temp1, temp2; - Word16 sum = 0; - move16(); - - /*upper allpass filter chain */ - - - FOR ( k = 0; k < N/2; k++ ) - { - - Lacc = L_deposit_h( state_fx[0] ); /* Q(16+x) */ - Lacc = L_mac( Lacc, AP1_STEEP_FX[0], in_fx[2*k] ); /* Q(16+x) */ - Lacc1 = L_deposit_h( in_fx[2*k] ); /* Q16+Qx */ - temp1 = extract_h( Lacc ); /* Qx */ - Lacc1 = L_msu( Lacc1, AP1_STEEP_FX[0], temp1 ); /* Q16+Qx */ - - state_fx[0] = extract_h( Lacc1 ); /* Qx */ - temp[0] = temp1; - move16(); - - Lacc1 = L_deposit_h( state_fx[1] ); /* Q16+Qx */ - Lacc1 = ( L_mac( Lacc1, AP1_STEEP_FX[1], temp1 )); /* Q16+Qx */ - - temp2 = extract_h( Lacc1 ); /* Qx */ - Lacc = L_msu( Lacc, AP1_STEEP_FX[1], temp2 ); /* Q16+Qx */ - state_fx[1] = extract_h(Lacc); /* Qx */ - temp[1] = temp2; - move16(); - - - Lacc = L_deposit_h( state_fx[ ALLPASSSECTIONS_STEEP-1 ] ); /* Q(16+x) */ - out_fx[ k ] = extract_h( L_mac( Lacc, AP1_STEEP_FX[ ALLPASSSECTIONS_STEEP-1 ], temp2 )); /* Qx format */ - state_fx[ ALLPASSSECTIONS_STEEP-1 ] = extract_h( L_msu ( Lacc1, AP1_STEEP_FX[ ALLPASSSECTIONS_STEEP-1 ], out_fx[k] )); /* Qx */ - - } - - /* lower allpass filter chain */ - - Lacc = L_deposit_h( state_fx[ ALLPASSSECTIONS_STEEP ] ); /* Q(16+x) */ - Lacc = L_mac( Lacc, AP2_STEEP_FX[0], state_fx[2*ALLPASSSECTIONS_STEEP] ); /*Q(16+x) */ - Lacc1 = L_deposit_h( state_fx[2*ALLPASSSECTIONS_STEEP] ); /* Q(16+x) */ - temp1 = extract_h( Lacc ); /* Qx */ - Lacc1 = L_msu( Lacc1, AP2_STEEP_FX[0], temp1 ); /* Q(16+x) */ - - state_fx[ ALLPASSSECTIONS_STEEP ] = extract_h( Lacc1 ); - temp[0] = temp1; - move16(); - - Lacc1 = L_deposit_h( state_fx[ ALLPASSSECTIONS_STEEP+1 ] ); /* Q(16+x) */ - Lacc1 = L_mac( Lacc1, AP2_STEEP_FX[1], temp1 ); /* Q(16+x) */ - temp2 = extract_h( Lacc1 ); /* Qx */ - temp[1] = temp2; - move16(); - Lacc = L_msu( Lacc, AP2_STEEP_FX[1], temp2 ); /* Q(16+x) */ - state_fx[ALLPASSSECTIONS_STEEP+1] = extract_h( Lacc ); /* Qx */ - - - Lacc = L_deposit_h( state_fx[2*ALLPASSSECTIONS_STEEP-1] ); /* Q(16+x) */ - Lacc = L_mac( Lacc, AP2_STEEP_FX[ALLPASSSECTIONS_STEEP-1], temp2 ); /* Q(16+x) temp[ALLPASSSECTIONS_STEEP-1] */ - temp[2] = extract_h( Lacc ); /* temp[2] in Qx */ - Lacc1 = L_msu( Lacc1, AP2_STEEP_FX[ALLPASSSECTIONS_STEEP-1], temp[2] ); /* Q(16+x) */ - state_fx[ 2*ALLPASSSECTIONS_STEEP-1 ] = extract_h( Lacc1 ); /* Qx */ - - sum = mult_r( out_fx[0], 16384 ); /* Qx */ - out_fx[0] = add( sum, mult_r(temp[ALLPASSSECTIONS_STEEP-1], 16384 )); /* Qx */ move16(); - - - FOR ( k = 1; k < N/2; k++) - { - - - Lacc = L_deposit_h( state_fx[ ALLPASSSECTIONS_STEEP ] ); /* Q(16+x) */ - Lacc = L_mac(Lacc, AP2_STEEP_FX[0], in_fx[2*k-1] ); /* Q(16+x):temp[0] */ - Lacc1 = L_deposit_h( in_fx[ 2*k-1 ] ); /* Q(16+x) */ - temp1 = extract_h( Lacc ); /* Qx */ - Lacc1 = L_msu( Lacc1, AP2_STEEP_FX[0], temp1 ); /* Q(16+x) */ - - state_fx[ALLPASSSECTIONS_STEEP] = extract_h( Lacc1 ); /* Qx */ - temp[0] = temp1; - move16(); - - - Lacc1 = L_deposit_h( state_fx[ ALLPASSSECTIONS_STEEP+1 ] ); /* Q(16+x) */ - Lacc1 = L_mac(Lacc1,AP2_STEEP_FX[1],temp1); /* Q(16+x) */ - temp2 = extract_h( Lacc1 ); /* Qx */ - temp[1] = temp2; - move16(); - Lacc = L_msu(Lacc,AP2_STEEP_FX[1],temp2); /* Q(16+x) */ - state_fx[ALLPASSSECTIONS_STEEP+1]= extract_h(Lacc); /* Qx */ - - - Lacc = L_deposit_h( state_fx[2*ALLPASSSECTIONS_STEEP-1] ); /* Q(16+x) */ - Lacc = L_mac( Lacc, AP2_STEEP_FX[ALLPASSSECTIONS_STEEP-1], temp[1] ); /* Q(16+x) temp[ALLPASSSECTIONS_STEEP-1] */ - temp[2] = extract_h( Lacc ); /*temp[2] in Qx */ - Lacc1 = L_msu( Lacc1, AP2_STEEP_FX[ALLPASSSECTIONS_STEEP-1], temp[2] ); /* Q(16+x) */ - state_fx[2*ALLPASSSECTIONS_STEEP-1] = extract_h( Lacc1 ); /* Qx */ - - - - sum = mult_r( out_fx[k], 16384 ); /* Qx */ - out_fx[k] = add( sum, mult_r( temp[ALLPASSSECTIONS_STEEP-1], 16384 ) ); - move16(); /* Qx */ - - } - - /* z^(-1) */ - - state_fx[ 2*ALLPASSSECTIONS_STEEP ] = in_fx[ N-1 ]; - move16(); /* Qx */ - -} - - - -void Interpolate_allpass_steep_fx(const Word16 *in_fx, - Word16 state_fx[], /* array of size: 2*ALLPASSSECTIONS_STEEP+1 */ - Word16 N, /* number of input samples */ - Word16 out_fx[]) /* array of size 2*N */ - - -{ - - Word16 k; - Word32 Lacc=0, Lacc1=0; - Word16 temp1, temp2; - - /*** State in Q0,in_fx Q0, AP1_STEEP in Q15 AP2_STEEP in Q15 OP in Q0 ************/ - /*upper allpass filter chain */ - - FOR (k=0; k 0); - - mem_fx_11 = mem_fx[11]; - move16(); - mem_fx_7 = mem_fx[7]; - move16(); - mem_fx_3 = mem_fx[3]; - move16(); - FOR (i = 0; i < loop_len; i++ ) - { - /* Lower branch */ - /*Vl0 = mem[8] + filt_coeff[6] * (*in - mem[9]); - Vl1 = mem[9] + filt_coeff[7] * (Vl0 - mem[10]); - mem[11] = mem[10] + filt_coeff[8] * (Vl1 - mem[11]); */ - tmp = mult_r(filt_coeff_fx[6], sub(*in++, mem_fx[9])); - if (i == 0) - { - Vl0 = add(mem_fx[8] , tmp); - } - if (i != 0) - { - Vl0 = add(*(in-4) , tmp); - } - Vl1 = add(mem_fx[9] , mult_r(filt_coeff_fx[7], sub(Vl0, mem_fx[10]))); - mem_fx_11 = add(mem_fx[10], mult_r(filt_coeff_fx[8], sub(Vl1, mem_fx_11))); - - /* mem[8] = *in++; - mem[9] = Vl0; - mem[10] = Vl1; - *out1 = mem[11]; */ - - mem_fx[9] = Vl0; - move16(); - mem_fx[10] = Vl1; - move16(); - - /* Middle branch */ - /* Vm0 = mem[4] + filt_coeff[3] * (*in - mem[5]); - Vm1 = mem[5] + filt_coeff[4] * (Vm0-mem[6]); - mem[7] = mem[6] + filt_coeff[5] * (Vm1-mem[7]); */ - tmp = mult_r(filt_coeff_fx[3], sub(*in++, mem_fx[5])); - if (i == 0) - { - Vm0 = add(mem_fx[4] , tmp); - } - if (i != 0) - { - Vm0 = add(*(in-4), tmp); - } - Vm1 = add(mem_fx[5] , mult_r(filt_coeff_fx[4], sub(Vm0, mem_fx[6]))); - mem_fx_7 = add(mem_fx[6], mult_r(filt_coeff_fx[5], sub(Vm1, mem_fx_7))); - - mem_fx[5] = Vm0; - move16(); - mem_fx[6] = Vm1; - move16(); - out = add(mem_fx_11, mem_fx_7); - - /* Upper branch */ - /* Vu0 = mem[0] + filt_coeff[0] * ( *in - mem[1] ); - Vu1 = mem[1] + filt_coeff[1] * ( Vu0 - mem[2] ); - mem[3] = mem[2] + filt_coeff[2] * ( Vu1 - mem[3] ); */ - tmp = mult_r(filt_coeff_fx[0], sub(*in++, mem_fx[1])); - if (i == 0) - { - Vu0 = add(mem_fx[0] , tmp); - } - if (i != 0) - { - Vu0 = add(*(in-4), tmp); - } - Vu1 = add(mem_fx[1] , mult_r(filt_coeff_fx[1], sub(Vu0, mem_fx[2]))); - mem_fx_3 = add(mem_fx[2] , mult_r(filt_coeff_fx[2], sub(Vu1, mem_fx_3))); - - mem_fx[1] = Vu0; - move16(); - mem_fx[2] = Vu1; - move16(); - *out1++ = add(out, mem_fx_3); - move16(); - } - mem_fx[8] = *(in-3); - move16(); - mem_fx[4] = *(in-2); - move16(); - mem_fx[0] = *(in-1); - move16(); - mem_fx[11] = mem_fx_11; - move16(); - mem_fx[7] = mem_fx_7; - move16(); - mem_fx[3] = mem_fx_3; - move16(); - - Scale_sig(mem_fx, 12, negate(sc)); - Scale_sig(out_fx, loop_len, negate(sc)); - Scale_sig(lp_mem_fx, 6, negate(sc)); - return; -} - - -/*-------------------------------------------------------------------* - * retro_interp4_5_fx() - * - * - *-------------------------------------------------------------------*/ - -void retro_interp4_5_fx( - const Word16 *syn_fx, - Word16 *pst_old_syn_fx -) -{ - Word16 *pf5, *pf4; - Word16 c; - - /* resample st->pst_old_syn in a reverse way to preserve time-alignment */ - pf4 = (Word16*) &pst_old_syn_fx[58]; - pf5 = (Word16*) pst_old_syn_fx; - FOR (c=0; c<57; c++) - { - *pf5++ = pf4[0]; - move16(); - /* *pf5++ = 0.2f * pf4[0] + 0.8f * pf4[1]; */ - *pf5++ = mac_r(L_mult(6554, pf4[0]), 26214, pf4[1]); - move16(); - /* *pf5++ = 0.4f * pf4[1] + 0.6f * pf4[2]; */ - *pf5++ = mac_r(L_mult(13107, pf4[1]), 19661, pf4[2]); - move16(); - /* *pf5++ = 0.6f * pf4[2] + 0.4f * pf4[3]; */ - *pf5++ = mac_r(L_mult(19661, pf4[2]), 13107, pf4[3]); - move16(); - /* *pf5++ = 0.8f * pf4[3] + 0.2f * pf4[4]; */ - *pf5++ = mac_r(L_mult(26214, pf4[3]), 6554, pf4[4]); - move16(); - pf4+=4; - } - *pf5++ = pf4[0]; - move16(); - /* *pf5++ = 0.2f * pf4[0] + 0.8f * pf4[1]; */ - *pf5++ = mac_r(L_mult(6554, pf4[0]), 26214, pf4[1]); - move16(); - /* *pf5++ = 0.4f * pf4[1] + 0.6f * pf4[2]; */ - *pf5++ = mac_r(L_mult(13107, pf4[1]), 19661, pf4[2]); - move16(); - /* *pf5++ = 0.6f * pf4[2] + 0.4f * pf4[3]; */ - *pf5++ = mac_r(L_mult(19661, pf4[2]), 13107, pf4[3]); - move16(); - /* *pf5++ = 0.8f * pf4[3] + 0.2f * syn[0]; */ - *pf5++ = mac_r(L_mult(26214, pf4[3]), 6554, syn_fx[0]); - move16(); - /* all samples processed: NBPSF_PIT_MAX = 290 = (58*5) */ - - return; -} - - -/*-------------------------------------------------------------------* - * retro_interp5_4_fx() - * - * - *-------------------------------------------------------------------*/ - -void retro_interp5_4_fx( Word16 *pst_old_syn_fx ) -{ - Word16 *pf5, *pf4; - Word16 c; - - /* resample st->pst_old_syn in a reverse way to preserve time-alignment */ - pf4 = (Word16*) &pst_old_syn_fx[NBPSF_PIT_MAX-1]; - pf5 = pf4; - FOR (c=0; c<58; c++) - { - /* *pf4-- = 0.75f * pf5[0] + 0.25f * pf5[-1]; */ - *pf4-- = mac_r(L_mult(24576, pf5[0]), 8192, pf5[-1]); - move16(); - /* *pf4-- = 0.50f * pf5[-1] + 0.50f * pf5[-2]; */ - *pf4-- = mac_r(L_mult(16384, pf5[-1]), 16384, pf5[-2]); - move16(); - /* *pf4-- = 0.25f * pf5[-2] + 0.75f * pf5[-3]; */ - *pf4-- = mac_r(L_mult(8192, pf5[-2]), 24576, pf5[-3]); - move16(); - *pf4-- = pf5[-4]; - move16(); - pf5-=5; - } - /* all samples processed: NBPSF_PIT_MAX = 290 = (58*5) */ - - return; -} - diff --git a/src/libs/libevs/lib_com/move.h b/src/libs/libevs/lib_com/move.h new file mode 100644 index 00000000..dd7e8af0 --- /dev/null +++ b/src/libs/libevs/lib_com/move.h @@ -0,0 +1,42 @@ +/*==================================================================================== + EVS Codec 3GPP TS26.443 Nov 13, 2018. Version 12.11.0 / 13.7.0 / 14.3.0 / 15.1.0 + ====================================================================================*/ + +#ifndef _MOVE_H +#define _MOVE_H + +/* BASOP -> FLC brigde: data move counting */ + +#include "stl.h" + +static __inline void move16( void) +{ +} + +static __inline void move32( void) +{ +} + +static __inline void test( void) +{ +} + +static __inline void logic16( void) +{ +} + +static __inline void logic32( void) +{ +} + + +/*-------- legacy ----------*/ +#define data_move() move16() +#define L_data_move() move32() +#define data_move_external() move16() +#define compare_zero() test() +/*-------- end legacy ----------*/ + +#define cast16 move16 + +#endif /* _MOVE_H */ diff --git a/src/libs/libevs/lib_com/mslvq_com.cpp b/src/libs/libevs/lib_com/mslvq_com.cpp new file mode 100644 index 00000000..ac7497af --- /dev/null +++ b/src/libs/libevs/lib_com/mslvq_com.cpp @@ -0,0 +1,733 @@ +/*==================================================================================== + EVS Codec 3GPP TS26.443 Nov 13, 2018. Version 12.11.0 / 13.7.0 / 14.3.0 / 15.1.0 + ====================================================================================*/ + +#include +#include "cnst.h" +#include "rom_com.h" +#include "prot.h" + +/*-----------------------------------------------------------------* + * Local functions + *-----------------------------------------------------------------*/ + +static void make_offset_scale(int j, const unsigned int tab_no_cv[], const int no_ld[], short no_scl, unsigned int offset_scale[][MAX_NO_SCALES+1]); +static void init_offset( unsigned int offset_scale1[][MAX_NO_SCALES+1], unsigned int offset_scale2[][MAX_NO_SCALES+1], unsigned int offset_scale1_p[][MAX_NO_SCALES+1], + unsigned int offset_scale2_p[][MAX_NO_SCALES+1], short no_scales[][2], short no_scales_p[][2]); +static void decode_comb( int index, float *cv, int idx_lead ); +static void decode_sign_pc1( float *c, int idx_sign, int parity ); +static void put_value( float *cv, int *p, float val, int dim, int no_new_val ); +static void decode_leaders( int index, int idx_lead, float *cv ); +static void idx2c( int n, int *p, int k, int val ); +static void divide_64_32( short *x, unsigned int y, unsigned int *result, unsigned int *rem ); +static short decode_indexes( short *index, int no_bits, const float *p_scales, short *p_no_scales, + unsigned int *p_offset_scale1, unsigned int *p_offset_scale2, float *x_lvq, short mode_glb ); + +/*-----------------------------------------------------------------* + * permute() + * used in CNG-LP coding + *-----------------------------------------------------------------*/ + +void permute( + float *pTmp1, /* i/o: vector whose components are to be permuted */ + const short *perm /* i : permutation info (indexes that should be interchanged), max two perms */ +) +{ + int p1, p2; + float tmp; + + p1 = perm[0]; + p2 = perm[1]; + tmp = pTmp1[p1]; + pTmp1[p1] = pTmp1[p2]; + pTmp1[p2] = tmp; + p1 = perm[2]; + + if ( p1 > -1 ) + { + p2 = perm[3]; + tmp = pTmp1[p1]; + pTmp1[p1] = pTmp1[p2]; + pTmp1[p2] = tmp; + } + + return; +} + +/*-----------------------------------------------------------------* + * init_lvq() + * + *-----------------------------------------------------------------*/ + +void init_lvq( + unsigned int offset_scale1[][MAX_NO_SCALES+1], + unsigned int offset_scale2[][MAX_NO_SCALES+1], + unsigned int offset_scale1_p[][MAX_NO_SCALES+1], + unsigned int offset_scale2_p[][MAX_NO_SCALES+1], + short no_scales[][2], + short no_scales_p[][2] +) +{ + short i, j; + /* safety-net mode */ + for(i=0; i0 )) + { + j++; + } + no_scales[i][0] = j; + j = MAX_NO_SCALES; + while ((j0 )) + { + j++; + } + no_scales[i][1] = j-MAX_NO_SCALES; + } + /* predictive mode */ + for(i=0; i0 )) + { + j++; + } + no_scales_p[i][0] = j; + j = MAX_NO_SCALES; + while ((j0 )) + { + j++; + } + no_scales_p[i][1] = j-MAX_NO_SCALES; + } + /* index offsets for each truncation */ + init_offset( offset_scale1, offset_scale2, offset_scale1_p, offset_scale2_p, no_scales, no_scales_p ); +} + +/*-----------------------------------------------------------------* + * make_offset_scale() + * + *-----------------------------------------------------------------*/ +static +void make_offset_scale( + int j, + const unsigned int tab_no_cv[], + const int no_ld[], + short no_scl, + unsigned int offset_scale[][MAX_NO_SCALES+1] +) +{ + int i; + + offset_scale[j][0] = 1; + for( i=1; i<=no_scl; i++ ) + { + offset_scale[j][i] = offset_scale[j][i-1] + tab_no_cv[no_ld[i-1]]; + } + + return; +} + +/*-----------------------------------------------------------------* + * init_offset() + * + *-----------------------------------------------------------------*/ +static +void init_offset( + unsigned int offset_scale1[][MAX_NO_SCALES+1], + unsigned int offset_scale2[][MAX_NO_SCALES+1], + unsigned int offset_scale1_p[][MAX_NO_SCALES+1], + unsigned int offset_scale2_p[][MAX_NO_SCALES+1], + short no_scales[][2], + short no_scales_p[][2] +) +{ + int j; + /* safety-net */ + for( j=0; j 0 ) + { + divide_64_32( index, (unsigned int)p_offset_scale2[mode_glb*no_modes+p_no_scales[mode_glb*2+1]], &index1, &index2 ); + } + else + { + index1 = (unsigned int)(index[0]); /* this is for very low bitrates, so there is no loss in truncation */ + index2 = 0; + } + + if ( index1 == 0 ) + { + for( i=0; i= p_offset_scale1[mode_glb*no_modes+p_no_scales[mode_glb*2]] ) + { + /* safety check in case of bit errors */ + set_f( x_lvq, 0.0f, 2*LATTICE_DIM ); + return 1; + } + + /* find idx_scale */ + i = 1; + while( (short)i <= p_no_scales[mode_glb*2] && index1 >= p_offset_scale1[mode_glb*no_modes +i] ) + { + i++; + } + + idx_scale = i-1; + index1 -= p_offset_scale1[mode_glb*no_modes+idx_scale]; + + /* find idx_leader */ + i = 1; + while( index1 >= table_no_cv[i] ) + { + i++; + } + decode_comb(index1-table_no_cv[i-1], x_lvq, i-1 ); + scale = p_scales[mode_glb*len_scales+idx_scale]; + for( i=0; i= p_offset_scale2[mode_glb*no_modes+i] ) + { + i++; + } + + idx_scale = i-1; + index2 -= p_offset_scale2[mode_glb*no_modes+idx_scale]; + /* find the index of the leader vector */ + i = 1; + while ( index2 >= table_no_cv[i] ) + { + i++; + } + + decode_comb( index2-table_no_cv[i-1], &x_lvq[LATTICE_DIM], i-1 ); + + scale = p_scales[mode_glb*len_scales+MAX_NO_SCALES+idx_scale]; + for( i=LATTICE_DIM; i<2*LATTICE_DIM; i++ ) + { + x_lvq[i] *= scale; + } + } + + return 0; +} + +/*-----------------------------------------------------------------* + * deindex_lvq() + * + *-----------------------------------------------------------------*/ + +short deindex_lvq( + short *index, /* i : index to be decoded, as an array of 3 short */ + float *x_lvq, /* o : decoded codevector */ + short mode, /* i : LVQ coding mode (select scales & no_lead ), or idx_cv */ + short sf_flag, /* i : safety net flag */ + short no_bits, /* i : number of bits for lattice */ + unsigned int *p_offset_scale1, /* i : offset for first subvector */ + unsigned int *p_offset_scale2, /* i : offset for the second subvector */ + short *p_no_scales +) +{ + int i; + const float * p_scales; + short mode_glb; + short ber_flag; + + if ( sf_flag == 1 ) + { + mode_glb = offset_lvq_modes_SN[mode] + offset_in_lvq_mode_SN[mode][no_bits-min_lat_bits_SN[mode]]; + p_scales = &scales[0][0]; + } + else + { + mode_glb = offset_lvq_modes_pred[mode] + offset_in_lvq_mode_pred[mode][no_bits-min_lat_bits_pred[mode]]; + p_scales = &scales_p[0][0]; + } + + /* decode the lattice index into the lattice codevectors for the two subvectors */ + ber_flag = decode_indexes( index, no_bits, p_scales, p_no_scales, p_offset_scale1, p_offset_scale2, x_lvq, mode_glb ); + + if ( sf_flag == 1 ) + { + for( i=0; i<2*LATTICE_DIM; i++ ) + { + x_lvq[i] *= sigma_MSLVQ[mode][i]; + } + } + else + { + for( i=0; i<2*LATTICE_DIM; i++ ) + { + x_lvq[i] *= sigma_p[mode][i]; + } + } + + return ber_flag; +} + +/*------------------------------------------------------------------------------------------------------------* + * deindex_lvq_cng() + * + * Note: + * The sampling frequency for the LVQ CNG decoder frame can be determined by checking the fully decoded + * value of the highest order LSF coefficient. Thus sampling rate information, nor extra codebooks are + * not needed for deindex_lvq_cng(), since it is embedded inside the LSF codebooks. + *------------------------------------------------------------------------------------------------------------*/ + +short deindex_lvq_cng( + short *index, /* i : index to be decoded, as an array of 3 short */ + float *x_lvq, /* o : decoded codevector */ + short idx_cv, /* i : relative mode_lvq, wrt START_CNG */ + int no_bits, /* i : number of bits for lattice */ + unsigned int * p_offset_scale1, + unsigned int * p_offset_scale2, + short * p_no_scales +) +{ + int i; + const float *p_scales; + short mode_glb, mode; + short ber_flag; + + mode_glb = START_CNG + idx_cv; + mode = LVQ_COD_MODES + idx_cv; + + p_scales = &scales[0][0]; + ber_flag = decode_indexes( index, no_bits, p_scales, p_no_scales, p_offset_scale1, p_offset_scale2, x_lvq, mode_glb ); + + for( i=0; i<2*LATTICE_DIM; i++ ) + { + x_lvq[i] *= sigma_MSLVQ[mode][i]; + } + + /* check if permutting needed */ + if ( cng_sort[idx_cv] ) + { + permute( x_lvq, perm_MSLVQ[idx_cv] ); + } + + return ber_flag; +} + + + +/*-----------------------------------------------------------------* + * decode_comb() + * + * combinatorial deindexing of a codevector including the signs +* + *-----------------------------------------------------------------*/ +static void decode_comb( + int index, /* i : index to be decoded */ + float *cv, /* o : decoded codevector */ + int idx_lead /* i : leader class index */ +) +{ + int idx_sign; + + idx_sign = (int)(index/pi0[idx_lead]); + index -= idx_sign*pi0[idx_lead]; + decode_leaders((int)index, idx_lead, cv); + decode_sign_pc1(cv, idx_sign, pl_par[idx_lead]); + + return; +} + +/*-----------------------------------------------------------------* + * decode_leaders() + * + * decode index of a codevector from the leader class idx_lead +*-----------------------------------------------------------------*/ + +static void decode_leaders( + int index, /* i : index to be decoded */ + int idx_lead, /* i : leader class index */ + float *cv /* o : decoded codevector */ +) +{ + int i, no_vals_loc, no_vals_last, p[LATTICE_DIM], index1, dim_loc, n_crt; + float val_crt; + + no_vals_loc = no_vals[idx_lead]; + val_crt = vals[idx_lead][no_vals_loc-1]; + no_vals_last = no_vals_ind[idx_lead][no_vals_loc-1]; + + for( i=0; i 0) + { + if (idx_sign % 2) + { + c[i] = -c[i]; + cnt_neg = -cnt_neg; + } + idx_sign >>= 1; + } + } + + if ( len < LATTICE_DIM ) + { + if (cnt_neg != parity) + { + c[len] = -c[len]; + } + } + + return; +} + +/*-----------------------------------------------------------------* + * extract_low() + * + * (!!!!! function for int64 !!!!) + *-----------------------------------------------------------------*/ + +static unsigned int extract_low( + unsigned int x +) +{ + return (x&(0xffff)); +} + +/*-----------------------------------------------------------------* + * extract_high() + * + * (!!!!! function for int64 !!!!) + *-----------------------------------------------------------------*/ + +static unsigned int extract_high( + unsigned int x +) +{ + return (x>>16); +} + +/*-----------------------------------------------------------------* + * multiply32_32_64() + * + * (!!!!! function for int64 !!!!) + *-----------------------------------------------------------------*/ + +void multiply32_32_64( + unsigned int x, + unsigned int y, + unsigned int *res +) +{ + unsigned int tmp, x_tmp[2], y_tmp[2]; + unsigned int high = 0; + + x_tmp[0] = extract_low(x); /* lowest 16 bits */ + x_tmp[1] = extract_high(x); + y_tmp[0] = extract_low(y); + y_tmp[1] = extract_high(y); + tmp = x_tmp[0]*y_tmp[0]; + high = extract_high(tmp); + res[0] = extract_low(tmp); + tmp = x_tmp[1]*y_tmp[0]+ x_tmp[0]*y_tmp[1] + high; /* x and y are not using all 32 bits */ + high = extract_high(tmp); + res[0] += (extract_low(tmp)<<16); + tmp = x_tmp[1]*y_tmp[1]+high; + res[1] = tmp; + + return; +} + +/*-----------------------------------------------------------------* + * get_no_bits() + * + * (!!!!! function for int64 !!!!) + *-----------------------------------------------------------------*/ + +static int get_no_bits( + unsigned int x +) +{ + int nb = 0; + + while( x > 0 ) + { + x >>= 1; + nb++; + } + + return nb; +} + +/*-----------------------------------------------------------------* + * divide_64_32() + * + * (!!!!! function for int64 !!!!) + *-----------------------------------------------------------------*/ + +static void divide_64_32( + short *xs, /* i : denominator as array of two int32 */ + unsigned int y, /* i : nominator on 32 bits */ + unsigned int *result, /* o : integer division result on 32 bits */ + unsigned int *rem /* o : integer division reminder on 32 bits */ +) +{ + int nb_x1; + unsigned int r, q, q1, x_tmp, x[2]; + + x[0] = (((unsigned int)xs[2]&((1<<2)-1))<<(LEN_INDICE*2)) + (xs[1]<>2; + + /* find number of bits of x[0] and x[1] */ + nb_x1 = get_no_bits(x[1]); + + /* take the first 32 bits */ + if ( nb_x1 > 0 ) + { + x_tmp = (x[1]<<(32-nb_x1)) + (x[0]>>nb_x1); + q = (unsigned int)(x_tmp/y+0.5); + r = x_tmp-q*y; /* this is the first reminder */ + r = (r< -#include "prot_fx.h" -#include "rom_com_fx.h" -#include "cnst_fx.h" -#include "stl.h" - -/*-----------------------------------------------------------------* - * Local functions - *-----------------------------------------------------------------*/ - -static void make_offset_scale_fx( Word16 j, const Word32 tab_no_cv[], const Word16 no_ld[], - Word16 no_scl, Word32 offset_scale[][MAX_NO_SCALES+1]); -static void init_offset_fx( Word32 offset_scale1[][MAX_NO_SCALES+1], Word32 offset_scale2[][MAX_NO_SCALES+1], - Word32 offset_scale1_p[][MAX_NO_SCALES+1], Word32 offset_scale2_p[][MAX_NO_SCALES+1], - Word16 no_scales[][2], Word16 no_scales_p[][2]); -static void decode_comb_fx(Word32 index,Word16 *cv,Word16 idx_lead); -static void decode_sign_pc1_fx( Word16 *c, Word16 idx_sign, Word16 parity ); -static void put_value_fx(Word16 *cv, Word16 *p, Word16 val, Word16 dim, Word16 no_new_val); -static void decode_leaders_fx(Word16 index, Word16 idx_lead, Word16 *cv ); -static void idx2c_fx(Word16 n, Word16 *p, Word16 k, Word16 val ); -static void divide_64_32_fx(Word16 *xs,Word32 y, Word32 *result, Word32 *rem); -static Word16 -decode_indexes_fx(Word16 * index,Word16 no_bits,const Word16 * p_scales, Word16 * p_no_scales, - Word32 * p_offset_scale1, Word32 * p_offset_scale2,Word16 * x_lvq,Word16 mode_glb, Word16 *scales); -static Word32 divide_32_32_fx(Word32 y, Word32 x, Word32 * rem); -static Word16 divide_16_16_fx(Word16 y, Word16 x, Word16 *rem); - -/* used in CNG-LP coding */ -void permute_fx( - Word16 *pTmp1, /* i/o: vector whose components are to be permuted */ - const Word16 *perm /* i : permutation info (indexes that should be interchanged), max two perms */ -) -{ - Word16 p1, p2; - Word16 tmp; - - p1 = perm[0]; - move16(); - p2 = perm[1]; - move16(); - tmp = pTmp1[p1]; - move16(); - pTmp1[p1] = pTmp1[p2]; - move16(); - move16(); - pTmp1[p2] = tmp; - move16(); - p1 = perm[2]; - move16(); - - IF ( add(p1, 1) > 0 ) - { - p2 = perm[3]; - move16(); - tmp = pTmp1[p1]; - move16(); - pTmp1[p1] = pTmp1[p2]; - move16(); - move16(); - pTmp1[p2] = tmp; - move16(); - } - - return; -} - - -void init_lvq_fx( - Word32 offset_scale1[][MAX_NO_SCALES+1], /* o: lattice truncation index offset for the first LSF subvector - safety net structures*/ - Word32 offset_scale2[][MAX_NO_SCALES+1], /* o: lattice truncation index offset for the second LSF subvector - safety net structures*/ - Word32 offset_scale1_p[][MAX_NO_SCALES+1], /* o: lattice truncation index offset for the first LSF subvector - predictive structures*/ - Word32 offset_scale2_p[][MAX_NO_SCALES+1], /* o: lattice truncation index offset for the second LSF subvector - predictive structures*/ - Word16 no_scales[][2], /* o: number of truncations for each LSF subvector at each MSLVQ structure - safety net */ - Word16 no_scales_p[][2] /* o: number of truncations for each LSF subvector at each MSLVQ structure - predictive */ -) -{ - Word16 i, j; - /* safety-net mode */ - FOR(i=0; i0 )) - { - j++; - } - no_scales[i][0] = j; - move16(); - j = MAX_NO_SCALES; - move16(); - test(); - WHILE ((sub(j,shl(MAX_NO_SCALES,1))<0) && (no_lead_fx[i][j] >0 )) - { - j++; - } - no_scales[i][1] = sub(j, MAX_NO_SCALES); - move16(); - } - /* predictive mode */ - FOR(i=0; i0 )) - { - j++; - } - no_scales_p[i][0] = j; - move16(); - j = MAX_NO_SCALES; - move16(); - WHILE ((sub(j, shl(MAX_NO_SCALES,1))<0) && (no_lead_p_fx[i][j] >0 )) - { - j++; - } - no_scales_p[i][1] = sub(j,MAX_NO_SCALES); - move16(); - } - /* index offsets for each truncation */ - init_offset_fx( offset_scale1, offset_scale2, offset_scale1_p, offset_scale2_p, no_scales, no_scales_p ); -} - -/* make_offset_scale_fx() - calculates scale offset values for a particular MSLVQ structure */ -static -void make_offset_scale_fx( - Word16 j, /* i: MSLVQ structure index */ - const Word32 tab_no_cv[], /* i: cummulated number of codevectors in each leader class */ - const Word16 no_ld[], /* i: number of leaders in each truncation for the MSLVQ structure j*/ - Word16 no_scl, /* i: number of truncations in the MSLVQ structure j */ - Word32 offset_scale[][MAX_NO_SCALES+1]/* o: offset values */ -) -{ - Word16 i; - - offset_scale[j][0] = L_deposit_l(1); - FOR( i=1; i<=no_scl; i++ ) - { - offset_scale[j][i] = L_add(offset_scale[j][sub(i,1)], tab_no_cv[no_ld[sub(i,1)]]); - move32(); - } - - return; -} - -void init_offset_fx( - Word32 offset_scale1[][MAX_NO_SCALES+1], /* o: lattice truncation index offset for the first LSF subvector - safety net structures*/ - Word32 offset_scale2[][MAX_NO_SCALES+1], /* o: lattice truncation index offset for the second LSF subvector - safety net structures*/ - Word32 offset_scale1_p[][MAX_NO_SCALES+1],/* o: lattice truncation index offset for the first LSF subvector - predictive structures*/ - Word32 offset_scale2_p[][MAX_NO_SCALES+1],/* o: lattice truncation index offset for the second LSF subvector - predictive structures*/ - Word16 no_scales[][2], /* i: number of truncations for each LSF subvector at each MSLVQ structure - safety net */ - Word16 no_scales_p[][2] /* i: number of truncations for each LSF subvector at each MSLVQ structure - predictive */ -) -{ - Word16 j; - /* safety-net */ - FOR( j=0; j 0 ) - { - divide_64_32_fx( index, p_offset_scale2[tmp+ p_no_scales[add(shl(mode_glb,1),1)]], &index1, &index2 ); - } - ELSE - { - index1 = L_deposit_l(index[0]); /* this is for very low bitrates, so there is no loss in truncation */ - index2 = L_deposit_l(0); - } - IF ( index1 == 0 ) - { - FOR( i=0; i= 0 ) - { - /* safety check in case of bit errors */ - set16_fx( x_lvq, 0, 2*LATTICE_DIM ); - scales[0] = 0; - scales[1] = 0; - return 1; - } - - /* find idx_scale */ - i = 1; - move16(); - WHILE( sub(i, p_no_scales[mode_glb*2]) <= 0 && L_sub(index1, p_offset_scale1[mode_glb*no_modes +i])>= 0 ) - { - i = add(i,1); - } - idx_scale = sub(i,1); - move16(); - index1 = L_sub(index1, p_offset_scale1[tmp+idx_scale]); - - /* find idx_leader */ - i = 1; - move16(); - - WHILE( L_sub(index1, table_no_cv_fx[i]) >= 0 ) - { - i = add(i, 1); - } - im1 = sub(i,1); - decode_comb_fx(L_sub(index1,table_no_cv_fx[im1]), x_lvq, im1 ); - scales[0] = p_scales[mode_glb*len_scales+idx_scale]; - } - - /* second subvector */ - IF ( index2 == 0 ) - { - FOR( i=LATTICE_DIM; i<2*LATTICE_DIM; i++ ) - { - x_lvq[i] = 0; - move16(); - } - scales[1] = 0; - move16(); - } - ELSE - { - /* find the index for the scale/truncation */ - i = 1; - move16(); - WHILE( L_sub(index2, p_offset_scale2[tmp+i]) >= 0 ) - { - i = add(i, 1); - } - - idx_scale = sub(i,1); - index2 = L_sub(index2, p_offset_scale2[add(tmp,idx_scale)]); - /* find the index of the leader vector */ - i = 1; - move16(); - WHILE ( L_sub(index2, table_no_cv_fx[i]) >= 0 ) - { - i = add(i, 1); - } - im1 = sub(i,1); - decode_comb_fx( index2-table_no_cv_fx[im1], &x_lvq[LATTICE_DIM], im1 ); - scales[1] = p_scales[add(i_mult2(mode_glb,len_scales),add(MAX_NO_SCALES,idx_scale))]; - move16(); - } - - return 0; -} - -Word16 deindex_lvq_fx( - Word16 *index, /* i : index to be decoded, as an array of 3 Word16 */ - Word16 *x_lvq, /* o : decoded codevector Q(x2.56) */ - Word16 mode, /* i : LVQ coding mode/MSLVQ structure index (select scales & no_lead ), or idx_cv for CNG case */ - Word16 sf_flag, /* i : safety net flag */ - Word16 no_bits, /* i : number of bits for lattice */ - Word32 *p_offset_scale1, /* i : offset for first subvector */ - Word32 *p_offset_scale2, /* i : offset for the second subvector */ - Word16 *p_no_scales /* i : number of scales for each truncation and each MSLVQ structure */ -) -{ - Word16 i; - const Word16 * p_scales; - Word16 mode_glb; - Word32 L_tmp; - Word16 scales[2]; - Word16 ber_flag; - - IF ( sub(sf_flag,1) == 0 ) - { - mode_glb = add(offset_lvq_modes_SN_fx[mode], offset_in_lvq_mode_SN_fx[mode][sub(no_bits,min_lat_bits_SN_fx[mode])]); - p_scales = &scales_fx[0][0]; - move16(); - } - ELSE - { - mode_glb = add(offset_lvq_modes_pred_fx[mode], offset_in_lvq_mode_pred_fx[mode][sub(no_bits,min_lat_bits_pred_fx[mode])]); - p_scales = &scales_p_fx[0][0]; - move16(); - } - - /* decode the lattice index into the lattice codevectors for the two subvectors */ - ber_flag = - decode_indexes_fx( index, no_bits, p_scales, p_no_scales, p_offset_scale1, - p_offset_scale2, x_lvq, mode_glb, scales ); /* x_lvq is here Q1 */ - - - IF ( sub(sf_flag,1) == 0 ) - { - /* safety-net case*/ - IF(scales[0]) - { - FOR( i=0; i 0) - { - /*if (idx_sign % 2) */ - IF(s_and(idx_sign,1)) - { - c[i] = negate(c[i]); - move16(); - cnt_neg = negate(cnt_neg); - move16(); - } - idx_sign = shr(idx_sign,1); /* >>= 1; */ - } - } - - IF ( sub(len, LATTICE_DIM)<0 ) - { - IF (sub(cnt_neg, parity) != 0) - { - c[len] = negate(c[len]); - move16(); - } - } - - return; -} - - -/*-----------------------------------------------------------------* - * multiply32_32_64_fx() - * - * (function for int64 ) - *-----------------------------------------------------------------*/ - -void multiply32_32_64_fx( - Word32 x, /* i: first factor */ - Word32 y, /* i: second factor */ - Word32 *res /* o: multiplication result as array of 2 Word32*/ -) -{ - Word32 tmp, high; - Word16 x_tmp[2], y_tmp[2]; - - x_tmp[0] = extract_l(L_and(x, 0x7fff)); /*extract_l(x); */ /* lowest 16 bits */ - x_tmp[1] = extract_l(L_and(L_shr(x,15),0x7fff)); /*extract_h(x); */ - y_tmp[0] = extract_l(L_and(y, 0x7fff)); /*extract_l(y); */ - y_tmp[1] = extract_l(L_and(L_shr(y,15),0x7fff)); /*extract_h(y); */ - tmp = L_mult0(x_tmp[0], y_tmp[0]); - high = L_shr(tmp,15); /*extract_h(tmp); */ - res[0] = L_and(tmp, 0x7fff); /* extract_l(tmp); */ - tmp = L_mac0(L_mac0(high, x_tmp[1], y_tmp[0]), x_tmp[0],y_tmp[1]); /* x and y are not using all 32 bits, so this is valid */ - high = L_shr(tmp,15);/*extract_h(tmp); */ - res[0] = L_add(res[0], L_shl(L_and(tmp,0x7fff), 15)); - move32(); - res[1] = L_mac0(high, x_tmp[1], y_tmp[1]); - move32(); - - return; -} - -static void decode_leaders_fx( - Word16 index, /* i : index to be decoded */ - Word16 idx_lead, /* i : leader class index */ - Word16 *cv /* o : decoded codevector Q1*/ -) -{ - Word16 i, no_vals_loc, no_vals_last, p[LATTICE_DIM], dim_loc, n_crt; - Word16 index1; - Word16 val_crt; - - no_vals_loc = no_vals_fx[idx_lead]; - move16(); - val_crt = vals_fx[idx_lead][no_vals_loc-1]; - move16(); /*Q1 */ - no_vals_last = no_vals_ind_fx[idx_lead][no_vals_loc-1]; - move16(); - - FOR( i=0; i= 0) - { - result = L_add(result,1); - t = L_add(L_tmp, 0); - } - } - *rem = t; - move32(); - } - return result; -} - -/* divide_32_32_fx() :Division reminder for Word16 - rem is the reminder of the division between y and x. */ -static Word16 divide_16_16_fx(Word16 y, /* i */ - Word16 x, /* i */ - Word16 *rem /* o */ - ) -{ - Word16 result, t, tmp; - Word16 i, ny, nx, nyx; - - - IF (L_sub(y, x) < 0) - { - result = 0; - move16(); - *rem = y; - move16(); - } - ELSE - { - - result = 0; - move16(); - IF (y==0) - { - ny = 0; - move16(); - } - ELSE - { - ny = sub(15, norm_s(y)); - } - IF (x==0) - { - nx = 0; - move16(); - } - ELSE - { - nx = sub(15, norm_s(x)); - } - - nyx = sub(ny,nx); - - t = s_and(shr(y, add(nyx,1)),sub(shl(1,sub(nx,1)),1)); - FOR(i=0; i<=nyx; i++) - { - t = add(shl(t,1), s_and(shr(y,sub(nyx,i)),1)); /* L_and(y,L_shl(1, sub(nyx,i)))); */ - result = shl(result,1); - tmp = sub(t,x); - IF(tmp >= 0) - { - result = add(result,1); - t = tmp; - move16(); - } - } - *rem = t; - move16(); - } - return result; -} - -static void divide_64_32_fx( - Word16 *xs, /* i : denominator as array of two int32 */ - Word32 y, /* i : nominator on 32 bits */ - Word32 *result, /* o : integer division result on 32 bits */ - Word32 *rem /* o : integer division reminder on 32 bits */ -) -{ - Word16 nb_x1; - Word32 r, x_tmp, x[2], q, q1; - - x[0] = L_add(L_add(L_shl(L_deposit_l(s_and(xs[2],1)),2*LEN_INDICE),L_shl(L_deposit_l(xs[1]), LEN_INDICE)),L_deposit_l(xs[0])); - move32(); - x[1] = L_shr(L_deposit_l(xs[2]),1); - move32(); - - /*x[0] = (((xs[2])&(1)<<(LEN_INDICE*2)) + (xs[1]<>1; */ - - IF (x[1] ==0) - { - nb_x1 = 0; - move16(); - } - ELSE - { - nb_x1 = sub(31, norm_l(x[1])); /*get_no_bits_fx(x[1]); */ - } - /* take the first 31 bits */ - IF ( nb_x1 > 0 ) - { - x_tmp = L_add(L_shl(x[1],sub(31,nb_x1)),L_shr(x[0], nb_x1)); - /* x_tmp = (x[1]<<(32-nb_x1)) + (x[0]>>nb_x1); */ - - q = divide_32_32_fx(x_tmp,y, &r); /* q = x_tmp/y, reminder r */ - r = L_add(L_shl(r, nb_x1), L_and(x[0],L_deposit_l(sub(shl(1,nb_x1),1)))); /* this is the first reminder */ - /* r = (r< +#include "math.h" +#include "rom_com.h" +#include "prot.h" + +/*-------------------------------------------------------------------* + * dequantize_uvg() + * + * Dequantize unvoiced gains + *--------------------------------------------------------------------*/ + +float dequantize_uvg( + int iG1, /* i: gain 1 index */ + int *iG2, /* i: gain 2 index */ + float *G, /* o: quantized gain */ + short bwidth +) +{ + short i, k; + const float (*UVG1CB)[2] = NULL; + const float (*UVG2CB1)[5] = NULL; + const float (*UVG2CB2)[5] = NULL; + + if ( bwidth == NB ) + { + UVG1CB = UVG1CB_NB; + UVG2CB1 = UVG2CB1_NB; + UVG2CB2 = UVG2CB2_NB; + } + + else if ( bwidth == WB || bwidth == SWB ) + { + UVG1CB = UVG1CB_WB; + UVG2CB1 = UVG2CB1_WB; + UVG2CB2 = UVG2CB2_WB; + } + + for( i=0; i<2; i++) + { + for (k=0; k<5; k++) + { + if(i==0) + { + G[i*5+k] = (float) pow(10.0, UVG1CB[iG1][i]) * UVG2CB1[iG2[i]][k]; + } + else if (i==1) + { + G[i*5+k] = (float) pow(10.0, UVG1CB[iG1][i]) * UVG2CB2[iG2[i]][k]; + } + } + } + return(0.0); +} + +/*-------------------------------------------------------------------* + * generate_nelp_excitation() + * + * Generate excitation for NELP coding. + *--------------------------------------------------------------------*/ + +void generate_nelp_excitation( + short *seed, /* i/o: random number seed */ + float *Gains, /* i : excitation gains */ + float *output, /* o : excitation output */ + float gain_fac /* i : gain factor */ +) +{ + short i,len,j; + float tmp[31], tmp1[31], tmpf; + short k1,k2, I[31], tmpi; + + for (i=0; i<10; i++) + { + if (i==9) + { + len=31; + } + else + { + len=25; + } + + for (j=0; jtmp1[k1]) + { + tmpi=I[k2]; + tmpf=tmp1[k2]; + tmp1[k2]=tmp1[k1]; + I[k2]=I[k1]; + tmp1[k1]=tmpf; + I[k1]=tmpi; + } + } + } + + /*using a factor of 1.37 to compensate for the ~ 2.5 ( or 2.73) dB diff between this scheme and EVS-UV */ + for (j=0; j<(short) rint_new(len/4.0f); j++) + { + output[i*25+I[j]]=(float) (Gains[i]*sqrt(3.0f)*tmp[I[j]]*gain_fac); + } + for (; jQ27 */ - L_tmp = L_shr_r(L_tmp,11); /* Q16 */ - frac = L_Extract_lc(L_tmp,&exp); - frac = extract_l(Pow2(14,frac)); - G[i*5+k] = round_fx(L_shl(L_mult(frac,UVG2CB1[iG2[i]][k]),exp-sc)); /* Q0 */ - } - ELSE IF (sub(i,1)==0) - { - L_tmp = L_mult(UVG1CB[iG1][i],27213); /* Q(13+13+1)->Q27 */ - L_tmp = L_shr_r(L_tmp,11); /* Q16 */ - frac = L_Extract_lc(L_tmp,&exp); - frac = extract_l(Pow2(14,frac)); - G[i*5+k] = round_fx(L_shl(L_mult(frac,UVG2CB2[iG2[i]][k]),exp-sc)); /* Q0 */ - } - } - } - return Q_gain; -} - -/*===================================================================*/ -/* FUNCTION : generate_nelp_excitation_fx */ -/*-------------------------------------------------------------------*/ -/* PURPOSE : This function computes the random - excitation scaled by gain */ -/*-------------------------------------------------------------------*/ -/* INPUT ARGUMENTS : */ - -/* _ (Word16*) Gains : Gain vector (Q_exc) */ -/* _ (Word16) gain_fac : gain factor (Q14) */ -/*-------------------------------------------------------------------*/ -/* OUTPUT ARGUMENTS : */ -/* _ (Word16*) seed : Random seed (Q0) */ -/* _ (Word16*) output : excitation output (Q_exc) */ -/*-------------------------------------------------------------------*/ -/* INPUT/OUTPUT ARGUMENTS : */ -/* _ None. */ -/*-------------------------------------------------------------------*/ -/* RETURN ARGUMENTS : */ -/* _ None. */ -/*===================================================================*/ -void generate_nelp_excitation_fx( - Word16 *seed, /* i/o: random number seed */ - Word16 *Gains, /* i : excitation gains Q_exc*/ - Word16 *output, /* o : excitation output */ - Word16 gain_fac /* i : gain factor */ -) -{ - Word16 i, len, j; - Word16 tmp[31], tmp1[31], tmpf, L16; - Word16 k1, k2, I[31], tmpi; - Word32 L32; - Word16 cnt; - - FOR (i=0; i<10; i++) - { - IF (sub(i,9)==0) - { - len=31; - move16(); - cnt=8; - move16(); - } - ELSE - { - len=25; - move16(); - cnt=6; - move16(); - } - - FOR (j=0; j0) - { - tmpi = I[k2]; - move16(); - tmpf = tmp1[k2]; - move16(); - tmp1[k2] = tmp1[k1]; - move16(); - I[k2] = I[k1]; - move16(); - tmp1[k1] = tmpf; - move16(); - I[k1] = tmpi; - move16(); - } - } - } - - /*using a factor of 1.37 to compensate for the ~ 2.5 ( or 2.73) dB diff between this scheme and EVS-UV */ - FOR (j=0; j -#include "prot_fx.h" + + + /********************************/ /* Helper functions */ /********************************/ /** Put nBits long encoded value from *pStream into bitstream. Using the function EncodeValue for encoding. */ -static Word16 PutIntoBitstream(Word16 const ** pStream, TEncodeValue EncodeValue, Word16 index, Encoder_State_fx *st_fx, Word16 nBits) +static int PutIntoBitstream(int const ** pStream, TEncodeValue EncodeValue, int index, Encoder_State *st, int nBits) { - Word16 value; - Word16 codedValue; - - move16(); - value = *(*pStream)++; - codedValue = EncodeValue(value, index); - - push_next_indice_fx(st_fx, codedValue, nBits); + int const value = *(*pStream)++; + int const codedValue = EncodeValue(value, index); + /* Variable initialization */ + push_next_indice(st, codedValue, nBits); return value; } - /** Get nBits long value from bitstream into *pStream. */ -static Word16 GetFromBitstream(Decoder_State_fx *st, TDecodeValue DecodeValue, Word16 index, Word16 nFixedBits, Word16 ** pStream) +static int GetFromBitstream(Decoder_State *st, TDecodeValue DecodeValue, int index, int nFixedBits, int ** pStream) { - Word16 value; - - move16(); - move16(); - value = 0; - - IF (DecodeValue != NULL) + int value = 0; + if (DecodeValue != NULL) { DecodeValue(st, index, &value); } - ELSE + else { - value = get_next_indice_fx(st, nFixedBits); + value = get_next_indice(st, nFixedBits); } - move16(); *(*pStream)++ = value; return value; } -static Word16 FixedWidthEncoding(Word16 value, Word16 index) +static int FixedWidthEncoding(int value, int index) { (void)index; return value; @@ -60,217 +51,121 @@ static Word16 FixedWidthEncoding(Word16 value, Word16 index) /* Interface functions */ /********************************/ -void GetParameters(ParamsBitMap const * paramsBitMap, Word16 nArrayLength, void const * pParameter, Word16 ** pStream, Word16 * pnSize, Word16 * pnBits) +void GetParameters(ParamsBitMap const * paramsBitMap, int nArrayLength, void const * pParameter, int ** pStream, int * pnSize, int * pnBits) { - Word16 index; - Word16 iParam, nParams; - Word16 value; + int index; + int iParam, nParams; + int value; void const * pSubStruct; assert((paramsBitMap != NULL) && (nArrayLength > 0) && (pParameter != NULL) && (pStream != NULL) && (pnSize != NULL) && (pnBits != NULL)); - - move16(); nParams = paramsBitMap->nParams; - - FOR (index = 0; index < nArrayLength; index++) + for (index = 0; index < nArrayLength; index++) { - - FOR (iParam = 0; iParam < nParams; iParam++) + for (iParam = 0; iParam < nParams; iParam++) { - ParamBitMap const * param; - - move16(); - param = & paramsBitMap->params[iParam]; + ParamBitMap const * const param = & paramsBitMap->params[iParam]; /* WMOPS: Just a shortcut */ pSubStruct = param->GetParamValue(pParameter, index, &value); /* If a function for encoding/decoding value is defined than it should take care of 0 */ - IF ( s_or(param->fZeroAllowed != 0, param->EncodeValue != NULL) ) + if (param->fZeroAllowed || (param->EncodeValue != NULL)) { - move16(); *(*pStream)++ = value; } - ELSE + else { - move16(); - *(*pStream)++ = sub(value, 1); + *(*pStream)++ = value - 1; } - - move16(); - *pnSize = add(*pnSize, 1); - - IF (param->nBits != 0) + ++*pnSize; + *pnBits += (param->nBits != 0) ? param->nBits : param->GetNumberOfBits(value, index); + if ((param->pSubParamBitMap != NULL) && (value > 0)) { - move16(); - *pnBits = add(*pnBits, param->nBits); - } - ELSE - { - move16(); - *pnBits = add(*pnBits, param->GetNumberOfBits(value, index)); - } - - IF ( s_and(param->pSubParamBitMap != NULL, value > 0) ) - { - const void *pointer; - - move16(); - pointer = pParameter; - if (pSubStruct != NULL) - { - move16(); - pointer = pSubStruct; - } - GetParameters(param->pSubParamBitMap, value, pointer, pStream, pnSize, pnBits); + GetParameters(param->pSubParamBitMap, value, (pSubStruct != NULL) ? pSubStruct : pParameter, pStream, pnSize, pnBits); } } } - } -void SetParameters(ParamsBitMap const * paramsBitMap, Word16 nArrayLength, void * pParameter, Word16 const ** pStream, Word16 * pnSize) +void SetParameters(ParamsBitMap const * paramsBitMap, int nArrayLength, void * pParameter, int const ** pStream, int * pnSize) { - Word16 index; - Word16 iParam, nParams; - Word16 value; + int index; + int iParam, nParams; + int value; void * pSubStruct; - void * pTmp; assert((paramsBitMap != NULL) && (nArrayLength > 0) && (pParameter != NULL) && (pStream != NULL) && (pnSize != NULL)); nParams = paramsBitMap->nParams; - - FOR (index = 0; index < nArrayLength; index++) + for (index = 0; index < nArrayLength; index++) { - FOR (iParam = 0; iParam < nParams; iParam++) + for (iParam = 0; iParam < nParams; iParam++) { - ParamBitMap const *param; + ParamBitMap const * const param = & paramsBitMap->params[iParam]; /* WMOPS: Just a shortcut */ /* If a function for encoding/decoding value is defined than it should take care of 0 */ - move16(); - param = ¶msBitMap->params[iParam]; - - move16(); - value = 1; - if ( s_or(param->fZeroAllowed!=0, param->EncodeValue != NULL) ) - { - move16(); - value = 0; - } - value = add(value, *(*pStream)++); - + value = *(*pStream)++ + (param->fZeroAllowed || (param->EncodeValue != NULL) ? 0 : 1); pSubStruct = param->SetParamValue(pParameter, index, value); - move16(); - *pnSize = add(*pnSize, 1); - - IF ( s_and(param->pSubParamBitMap != NULL, value > 0) ) + ++*pnSize; + if ((param->pSubParamBitMap != NULL) && (value > 0)) { - pTmp = pParameter; - if(pSubStruct != NULL) pTmp = pSubStruct; - SetParameters(param->pSubParamBitMap, value, pTmp, pStream, pnSize); + SetParameters(param->pSubParamBitMap, value, (pSubStruct != NULL) ? pSubStruct : pParameter, pStream, pnSize); } } } - } -void WriteToBitstream(ParamsBitMap const * paramsBitMap, Word16 nArrayLength, Word16 const ** pStream, Word16 * pnSize, Encoder_State_fx *st, Word16 * pnBits) +void WriteToBitstream(ParamsBitMap const * paramsBitMap, int nArrayLength, int const ** pStream, int * pnSize, Encoder_State *st, int * pnBits) { - Word16 index; - Word16 iParam, nParams; + int index; + int iParam, nParams; assert((paramsBitMap != NULL) && (nArrayLength > 0) && (pStream != NULL) && (pnSize != NULL) && (st != NULL) && (pnBits != NULL)); nParams = paramsBitMap->nParams; - - FOR (index = 0; index < nArrayLength; index++) + for (index = 0; index < nArrayLength; index++) { - - FOR (iParam = 0; iParam < nParams; iParam++) + for (iParam = 0; iParam < nParams; iParam++) { - ParamBitMap const *param; - Word16 nBits; + ParamBitMap const * const param = & paramsBitMap->params[iParam]; /* WMOPS: Just a shortcut */ + int nBits; /* If a function for encoding/decoding value is defined than it should take care of 0 */ - Word16 fShiftValue; + int fShiftValue; TEncodeValue EncodeValue; - Word16 value; + int value; - move16(); - param = ¶msBitMap->params[iParam]; - - move16(); - nBits = param->nBits; - IF (param->nBits == 0) - { - nBits = param->GetNumberOfBits(**pStream, index); - } - - test(); - test(); - fShiftValue = s_and(param->fZeroAllowed==0, param->EncodeValue == NULL); - move16(); - EncodeValue = param->EncodeValue; - if (param->EncodeValue == NULL) - { - move16(); - EncodeValue = &FixedWidthEncoding; - } - value = PutIntoBitstream(pStream, EncodeValue, index, st, nBits); - if (fShiftValue) - { - value = add(value, 1); - } - - move16(); - *pnSize = add(*pnSize, 1); - move16(); - *pnBits = add(*pnBits, nBits); - - IF ((param->pSubParamBitMap != NULL) && (value > 0)) + nBits = (param->nBits != 0) ? param->nBits : param->GetNumberOfBits(**pStream, index); + fShiftValue = !param->fZeroAllowed && (param->EncodeValue == NULL); + EncodeValue = (param->EncodeValue == NULL) ? &FixedWidthEncoding : param->EncodeValue; + value = PutIntoBitstream(pStream, EncodeValue, index, st, nBits) + (fShiftValue ? 1 : 0); + ++*pnSize; + *pnBits += nBits; + if ((param->pSubParamBitMap != NULL) && (value > 0)) { WriteToBitstream(param->pSubParamBitMap, value, pStream, pnSize, st, pnBits); } - } } } -void ReadFromBitstream(ParamsBitMap const * paramsBitMap, Word16 nArrayLength, Decoder_State_fx *st, Word16 ** pStream, Word16 * pnSize) +void ReadFromBitstream(ParamsBitMap const * paramsBitMap, int nArrayLength, Decoder_State *st, int ** pStream, int * pnSize) { - Word16 index; - Word16 iParam, nParams; - Word16 fShiftValue; - Word16 value; + int index; + int iParam, nParams; + int fShiftValue; + int value; assert((paramsBitMap != NULL) && (nArrayLength > 0) && (pStream != NULL) && (pnSize != NULL) && (st != NULL)); - move16(); nParams = paramsBitMap->nParams; - - FOR (index = 0; index < nArrayLength; index++) + for (index = 0; index < nArrayLength; index++) { - - FOR (iParam = 0; iParam < nParams; iParam++) + for (iParam = 0; iParam < nParams; iParam++) { - ParamBitMap const * param; - - + ParamBitMap const * param = & paramsBitMap->params[iParam]; /* WMOPS: Just a shortcut */ /* If a function for encoding/decoding value is defined than it should take care of 0 */ - move16(); - param = & paramsBitMap->params[iParam]; - test(); - test(); - fShiftValue = s_and(param->fZeroAllowed==0, param->EncodeValue == NULL); - value = GetFromBitstream(st, param->DecodeValue, index, param->nBits, pStream); - if (fShiftValue) + fShiftValue = !param->fZeroAllowed && (param->EncodeValue == NULL); + value = GetFromBitstream(st, param->DecodeValue, index, param->nBits, pStream) + (fShiftValue ? 1 : 0); + if ((param->pSubParamBitMap != NULL) && (value > 0)) { - move16(); - value = add(value, 1); - } - - IF ((param->pSubParamBitMap != NULL) && (value > 0)) - { - ReadFromBitstream(param->pSubParamBitMap, value, st, pStream, pnSize); } } } - move16(); - *pnSize = add(*pnSize, i_mult(nParams, nArrayLength)); - + *pnSize += nParams*nArrayLength; } diff --git a/src/libs/libevs/lib_com/phase_dispersion.cpp b/src/libs/libevs/lib_com/phase_dispersion.cpp old mode 100755 new mode 100644 index 7dc01edc..48a9e11d --- a/src/libs/libevs/lib_com/phase_dispersion.cpp +++ b/src/libs/libevs/lib_com/phase_dispersion.cpp @@ -1,177 +1,123 @@ /*==================================================================================== - EVS Codec 3GPP TS26.442 Apr 03, 2018. Version 12.11.0 / 13.6.0 / 14.2.0 + EVS Codec 3GPP TS26.443 Nov 13, 2018. Version 12.11.0 / 13.7.0 / 14.3.0 / 15.1.0 ====================================================================================*/ +#include +#include "options.h" +#include "cnst.h" +#include "prot.h" +#include "rom_com.h" -#include -#include "options.h" /* EV-VBR compilation switches */ -#include "prot_fx.h" -#include "basop_util.h" -#include "stl.h" /* Weighted mops computation related code */ /*-----------------------------------------------------------------------* - * phase_dispersion: + * phase_dispersion() * - * post-processing to enhance noise at low bit rate. + * Post-processing to enhance noise at low bitrate *-----------------------------------------------------------------------*/ void phase_dispersion( - const Word32 gain_code, /* i : gain of code 15Q16 */ - const Word16 gain_pit, /* i : gain of pitch Q14 */ - Word16 code[], /* i/o: code vector */ - Word16 *code_exp, /* i/o: exponent of code */ - const Word16 mode, /* i : level, 0=hi, 1=lo, 2=off */ - Word32 *prev_gain_code, /* i/o: static memory 15Q16 */ - Word16 prev_gain_pit[], /* i/o: static memory Q14, size=6 */ - Word16 *prev_state, /* i/o: static memory Q0 */ - Word16 L_subfr /* i : subframe length [40,64,80]*/ + const float gain_code, /* i : gain of code */ + const float gain_pit, /* i : gain of pitch */ + float code[], /* i/o: code vector */ + const short mode, /* i : level, 0=hi, 1=lo, 2=off */ + float disp_mem[] /* i/o: static memory (size = 8) */ ) { - Word16 i, j, state, scale2; - Word32 x32[2*L_SUBFR]; - Word16 *code_real, *code_imag; - const Word16 *h_real, *h_imag; + short i, j, state; + float *prev_gain_pit, *prev_gain_code, *prev_state; + float code2[2*L_SUBFR]; + float h_disp[L_SUBFR], *code2_real, *code2_imag, *code_real, *code_imag, *h_real, *h_imag; + prev_state = disp_mem; + prev_gain_code = disp_mem+1; + prev_gain_pit = disp_mem+2; - - move16(); state = 2; - - if ( sub(gain_pit,14746/*0.9f Q14*/) < 0) + if (gain_pit < 0.6f) { - move16(); - state = 1; - } - if ( sub(gain_pit, 9830/*0.6f Q14*/) < 0 ) - { - move16(); state = 0; } - - FOR (i=5; i>0; i--) + else if (gain_pit < 0.9f) + { + state = 1; + } + + for (i=5; i>0; i--) { - move16(); prev_gain_pit[i] = prev_gain_pit[i-1]; } - move16(); prev_gain_pit[0] = gain_pit; - - IF ( L_sub(gain_code, L_add(*prev_gain_code, L_shl(*prev_gain_code,1))) > 0 ) + if (gain_code - 3.0f * *prev_gain_code > 0.0f) { - if (sub(state,2) < 0) + if (state < 2) { - state = add(state, 1); + state++; } } - ELSE + else { j=0; - FOR (i=0; i<6; i++) + for (i=0; i<6; i++) { - - if ( L_sub(prev_gain_pit[i], 9830/*0.6f Q14*/) < 0 ) + if (prev_gain_pit[i] < 0.6f) { - j = add(j,1); + j++; } } - if (sub(j,2) > 0) + if (j > 2) { - move16(); state = 0; } - if ( sub(sub(state, *prev_state),1) > 0 ) + if ((state - (short)*prev_state) > 1) { - state = sub(state,1); + state--; } } - move32(); - move16(); *prev_gain_code = gain_code; - *prev_state = state; + *prev_state = (float)state; /*-----------------------------------------------------------------* - * circular convolution + * Circular convolution *-----------------------------------------------------------------*/ - state = add(state, mode); /* level of dispersion */ - j = *code_exp; - move16(); - IF( sub(state,2) < 0 ) + state += mode; /* level of dispersion */ + if( state < 2 ) { - FOR(i=0; i +#include "cnst.h" +#include "options.h" +#include "prot.h" +#include "rom_com.h" + + +/*-------------------------------------------------------------------* + * Interpol_delay() + * + * Interpolation of pitch lag + *--------------------------------------------------------------------*/ + +void Interpol_delay( + float *out, /* o : pitch interpolation output */ + float *last, /* i : last frame pitch lag */ + float *current, /* i : current frame pitch lag */ + short SubNum, /* i : subframe number */ + const float *frac /* i : interpolation constant */ +) +{ + out[0] = (1.0f - frac[SubNum]) **last + frac[SubNum] **current; + out[1] = (1.0f - frac[SubNum + 1]) **last + frac[SubNum + 1] **current; + out[2] = (1.0f - frac[SubNum + 2]) **last + frac[SubNum + 2] **current; + + return; +} + + +/*-------------------------------------------------------------------* + * deemph_lpc() + * + * De-emphasis of LP coefficients + * convolve LPC with [1 -PREEMPH_FAC] to de-emphasise LPC + *--------------------------------------------------------------------*/ + +void deemph_lpc( + float *p_Aq_curr, /* i : LP coefficients current frame */ + float *p_Aq_old, /* i : LP coefficients previous frame */ + float *LPC_de_curr, /* o : De-emphasized LP coefficients current frame */ + float *LPC_de_old /* o : De-emphasized LP coefficients previous frame */ + ,short deemph_old + +) +{ + short k; + float b[M+2]; + float a[2] = {-PREEMPH_FAC,1.0}; + + b[0] = 1.0; + for(k = 0; k < M; k++) + { + b[k+1] = p_Aq_curr[k]; + } + b[M+1] = 0.0; + + for(k = 0; k <= M; k++) + { + LPC_de_curr[k] = a[0]*b[k] + a[1]*b[k+1]; + } + + if ( deemph_old == 1) + { + /* ignoring the 1st value which is 1.0 in this case */ + b[0] = 1.0; + for(k = 0; k < M; k++) + { + b[k+1] = p_Aq_old[k+1]; + } + b[M+1] = 0.0; + + for(k = 0; k <= M; k++) + { + LPC_de_old[k] = a[0]*b[k] + a[1]*b[k+1]; + } + } + + return; +} diff --git a/src/libs/libevs/lib_com/ppp_fx.cpp b/src/libs/libevs/lib_com/ppp_fx.cpp deleted file mode 100755 index a3c791d5..00000000 --- a/src/libs/libevs/lib_com/ppp_fx.cpp +++ /dev/null @@ -1,115 +0,0 @@ -/*==================================================================================== - EVS Codec 3GPP TS26.442 Apr 03, 2018. Version 12.11.0 / 13.6.0 / 14.2.0 - ====================================================================================*/ - -#include "options.h" -#include "cnst_fx.h" -#include "prot_fx.h" -#include "stl.h" - -/*===================================================================*/ -/* FUNCTION : Interpol_delay_fx () */ -/*-------------------------------------------------------------------*/ -/* PURPOSE : Interpolate pitch lag for a subframe */ -/*-------------------------------------------------------------------*/ -/* INPUT ARGUMENTS : */ -/* _ (Word16) last_fx: previous frame delay, Q0 */ -/* _ (Word16) current_fx: current frame delay, Q0 */ -/* _ (Word16) SubNum : subframe number */ -/*-------------------------------------------------------------------*/ -/* OUTPUT ARGUMENTS : */ -/* */ -/* _ (Word16 []) out_fx : 3 Intepolated delays, Q4 */ -/*-------------------------------------------------------------------*/ -/* INPUT/OUTPUT ARGUMENTS : */ -/* _ None */ -/*-------------------------------------------------------------------*/ -/* RETURN ARGUMENTS : _ None. */ -/*===================================================================*/ -/* NOTE: this function uses a 5 entry table frac_fx (Q4 unsigned) */ -/*===================================================================*/ - -void Interpol_delay_fx(Word16 *out_fx, Word16 last_fx, Word16 current_fx, - Word16 SubNum, const Word16* frac_fx) -{ - Word16 i,temp; - Word32 L_add1,L_add2; - - FOR (i=0; i<3; i++) - { - temp= sub(16,frac_fx[SubNum+i]);/* Q4 */ - L_add1 = L_shr(L_mult(last_fx,temp),1);/* Q4 */ - L_add2 = L_shr(L_mult(current_fx,frac_fx[SubNum+i]),1);/* Q4 */ - out_fx[i] = (Word16)L_add(L_add1,L_add2); - move16();/* Q4 */ - - } - return; -} - -/*-------------------------------------------------------------------* - * deemph_lpc() - * - * De-emphasis of LP coefficients - * convolve LPC with [1 -PREEMPH_FAC] to de-emphasise LPC - *--------------------------------------------------------------------*/ - -void deemph_lpc_fx( - Word16 *p_Aq_curr_fx, /* i : LP coefficients current frame */ - Word16 *p_Aq_old_fx, /* i : LP coefficients previous frame */ - Word16 *LPC_de_curr_fx, /* o : De-emphasized LP coefficients current frame in Q12 */ - Word16 *LPC_de_old_fx, /* o : De-emphasized LP coefficients previous frame in Q12 */ - Word16 deemph_old - -) -{ - Word16 k,temp; - Word16 b_fx[M+2];/* Q12 */ - Word16 a_fx[2] = {-22282, 32767};/* Q15 {-PREEMPH_FAC,1.0} */ - - b_fx[0] = 4096; - move16();/* 1 in Q12 */ - FOR(k = 0; k < M; k++) - { - b_fx[k+1] = p_Aq_curr_fx[k]; - move16();/* Q12 */ - } - b_fx[M+1] = 0; - move16(); - - FOR(k = 0; k <= M; k++) - { - /* LPC_de_curr[k] = a[0]*b[k] + a[1]*b[k+1]; */ - temp = mult(a_fx[0],b_fx[k]);/* Q12 */ - LPC_de_curr_fx[k] = add(temp,b_fx[k+1]); - move16();/* Q12 */ - } - - IF ( sub( deemph_old, 1) == 0) - { - - /* ignoring the 1st value which is 1.0 in this case */ - b_fx[0] = 4096; - move16();/* 1 in Q12 */ - FOR(k = 0; k < M; k++) - { - b_fx[k+1] = p_Aq_old_fx[k+1]; - move16(); - } - b_fx[M+1] = 0; - move16(); - - FOR(k = 0; k <= M; k++) - { - /* LPC_de_old[k] = a[0]*b[k] + a[1]*b[k+1]; */ - temp = mult(a_fx[0],b_fx[k]);/* Q12 */ - LPC_de_old_fx[k] = add(temp,b_fx[k+1]); - move16();/* Q12 */ - } - } - - - return; /* both outputs LPC_de_curr_fx and LPC_de_old_fx are in Q12 */ -} - - diff --git a/src/libs/libevs/lib_com/pred_lt4.cpp b/src/libs/libevs/lib_com/pred_lt4.cpp new file mode 100644 index 00000000..1a54b03f --- /dev/null +++ b/src/libs/libevs/lib_com/pred_lt4.cpp @@ -0,0 +1,125 @@ +/*==================================================================================== + EVS Codec 3GPP TS26.443 Nov 13, 2018. Version 12.11.0 / 13.7.0 / 14.3.0 / 15.1.0 + ====================================================================================*/ + +#include "options.h" +#include "cnst.h" +#include "rom_com.h" +#include "prot.h" + + +/*-------------------------------------------------------------------* + * pred_lt4() + * + * Compute the result of long term prediction with fractionnal + * interpolation of resolution 1/4. + * + * On return, exc[0..L_subfr-1] contains the interpolated signal + * (adaptive codebook excitation) + *-------------------------------------------------------------------*/ + +void pred_lt4( + const float excI[], /* i : input excitation buffer */ + float excO[], /* o : output excitation buffer */ + const short T0, /* i : integer pitch lag */ + short frac, /* i : fraction of lag */ + const short L_subfr, /* i : subframe size */ + const float *win, /* i : interpolation window */ + const short nb_coef, /* i : nb of filter coef */ + const short up_sample /* i : up_sample */ +) +{ + short i, j; + float s; + const float *x1, *x2, *x0, *c1, *c2; + + x0 = &excI[-T0]; + frac = -frac; + + if (frac < 0) + { + frac += up_sample; + x0--; + } + + for (j=0; j 0) - { - frac = sub(frac,UP_SAMP); - x0--; - } - - l = add(UP_SAMP-1, frac); - FOR (j = T0; j < L_SUBFR+1; j++) - { - k = l; - move16(); - L_sum = L_mult(x0[0], win[k]); - FOR (i = 1; i < 2 * L_INTERPOL2; i++) - { - /* - * Here, additions with UP_SAMP are not counted - ki* because, the window could easily be modified - * so that the values needed are contiguous. - */ - k += UP_SAMP; - L_sum = L_mac(L_sum, x0[i], win[k]); /*Q1 */ - } - L_sum = L_shl(L_sum, 1); /*Q0h */ - - excO[j] = round_fx(L_sum); - - x0++; - } - FOR (i = T0; i < L_SUBFR; i++) - { - exc[i+i_subfr] = add(exc[i+i_subfr], mult_r(PIT_SHARP_fx, excO[i])); - move16(); - } - } - - return; - -} diff --git a/src/libs/libevs/lib_com/preemph.cpp b/src/libs/libevs/lib_com/preemph.cpp new file mode 100644 index 00000000..be8ab9cc --- /dev/null +++ b/src/libs/libevs/lib_com/preemph.cpp @@ -0,0 +1,35 @@ +/*==================================================================================== + EVS Codec 3GPP TS26.443 Nov 13, 2018. Version 12.11.0 / 13.7.0 / 14.3.0 / 15.1.0 + ====================================================================================*/ + +#include "options.h" +#include "prot.h" + + +/*-------------------------------------------------------------* + * preemph() + * + * Preemphasis: filtering through 1 - mu z^-1 + *-------------------------------------------------------------*/ + +void preemph( + float *signal, /* i/o: signal */ + const float mu, /* i : preemphasis factor */ + const short L, /* i : vector size */ + float *mem /* i/o: memory (x[-1]) */ +) +{ + short i; + float temp; + + temp = signal[L-1]; + for (i=L-1; i>0; i--) + { + signal[i] = signal[i] - mu*signal[i-1]; + } + + signal[0] = signal[0] - mu*(*mem); + *mem = temp; + + return; +} diff --git a/src/libs/libevs/lib_com/preemph_fx.cpp b/src/libs/libevs/lib_com/preemph_fx.cpp deleted file mode 100755 index d4da3d0c..00000000 --- a/src/libs/libevs/lib_com/preemph_fx.cpp +++ /dev/null @@ -1,136 +0,0 @@ -/*==================================================================================== - EVS Codec 3GPP TS26.442 Apr 03, 2018. Version 12.11.0 / 13.6.0 / 14.2.0 - ====================================================================================*/ - -#include "options.h" /* Compilation switches */ -#include "prot_fx.h" /* Function prototypes */ -#include "stl.h" - -/*-------------------------------------------------------------* - * preemph_copy_fx() - * - * Preemphasis: filtering through 1 - mu z^-1 - *-------------------------------------------------------------*/ -void preemph_copy_fx( - const Word16 x[], /* i : input signal Qx */ - Word16 y[], /* o : output signal Qx */ - const Word16 mu, /* i : preemphasis coefficient Q15 */ - const Word16 lg, /* i : vector size Q0 */ - Word16 *mem /* i/o: memory (x[-1]) Qx */ -) -{ - Word16 i, temp; - - temp = x[lg - 1]; - move16(); - FOR (i = sub(lg, 1); i > 0; i--) - { - y[i] = msu_r(L_deposit_h(x[i]), x[i - 1], mu); - move16(); - } - y[0] = msu_r(L_deposit_h(x[0]), *mem, mu); - move16(); - - *mem = temp; - move16(); -} - -/* - * E_UTIL_f_preemph2 - * - * Parameters: - * shift I: scale output - * signal I/O: signal Qx/Qx+shift - * mu I: preemphasis factor Q15 - * L I: vector size - * mem I/O: memory (x[-1]) - * - * Function: - * Filtering through 1 - mu z^-1 - * - * Returns: - * void - */ -void E_UTIL_f_preemph2(Word16 shift, Word16 *signal, const Word16 mu, const Word16 lg, Word16 *mem) -{ - Word16 i, temp; - Word32 L_tmp; - - temp = signal[lg - 1]; - move16(); - - FOR (i = sub(lg, 1); i > 0; i--) - { - L_tmp = L_mult(signal[i], 16384); - L_tmp = L_msu0(L_tmp, signal[i - 1], mu); - L_tmp = L_shl(L_tmp, add(shift,1)); - signal[i] = round_fx(L_tmp); - } - - L_tmp = L_mult(signal[0], 16384); - L_tmp = L_msu0(L_tmp, *mem, mu); - L_tmp = L_shl(L_tmp, add(shift,1)); - signal[0] = round_fx(L_tmp); - - *mem = temp; - move16(); - - return; -} - - -Word16 E_UTIL_f_preemph3(Word16 *signal, const Word16 mu, const Word16 lg, Word16 *mem, Word16 bits) -{ - Word16 i, QVal, mus, tmp_fixed, Q_new; - Word32 L_tmp, L_maxloc; - - - - QVal = shl(1, sub(15,bits)); - mus = shr(mu, bits); - - L_tmp = L_mult(signal[0], QVal); - L_tmp = L_msu(L_tmp, *mem, mus); - L_maxloc = L_abs(L_tmp); - - FOR (i = 1; i < lg; i++) - { - L_tmp = L_mult(signal[i], QVal); - L_tmp = L_msu(L_tmp, signal[i - 1], mus); - L_tmp = L_abs(L_tmp); - L_maxloc = L_max(L_tmp, L_maxloc); - } - - tmp_fixed = extract_h(L_maxloc); - - Q_new = Q_MAX; - move16(); - IF (tmp_fixed != 0) - { - Q_new = sub(norm_s(tmp_fixed), bits); - Q_new = s_max(Q_new, 0); - Q_new = s_min(Q_new, Q_MAX); - } - - tmp_fixed = signal[lg - 1]; - move16(); - - FOR (i = sub(lg,1); i > 0; i--) - { - L_tmp = L_mult(signal[i], QVal); - L_tmp = L_msu(L_tmp, signal[i - 1], mus); - L_tmp = L_shl(L_tmp, Q_new); - signal[i] = round_fx(L_tmp); - } - - L_tmp = L_mult(signal[0], QVal); - L_tmp = L_msu(L_tmp, *mem, mus); - L_tmp = L_shl(L_tmp, Q_new); - signal[0] = round_fx(L_tmp); - - *mem = tmp_fixed; - move16(); - - return Q_new; -} - diff --git a/src/libs/libevs/lib_com/prot.h b/src/libs/libevs/lib_com/prot.h new file mode 100644 index 00000000..4cd26dcd --- /dev/null +++ b/src/libs/libevs/lib_com/prot.h @@ -0,0 +1,9776 @@ +/*==================================================================================== + EVS Codec 3GPP TS26.443 Nov 13, 2018. Version 12.11.0 / 13.7.0 / 14.3.0 / 15.1.0 + ====================================================================================*/ + +#ifndef PROT_H +#define PROT_H + +#include +#include +#include "options.h" +#include "typedef.h" +#include "stat_enc.h" +#include "stat_dec.h" +#include "stat_com.h" +#include "cnst.h" +#include "stl.h" + + +/*----------------------------------------------------------------------------------* + * Prototypes of global macros + *----------------------------------------------------------------------------------*/ + +#ifndef min +#define min(x,y) ((x)<(y)?(x):(y)) +#endif + +#ifndef max +#define max(x,y) ((x)>(y)?(x):(y)) +#endif + +#define log_base_2(x) ((double)log((double)(x))*1.4426950408889634074f) +#define round_f(x) (((x)>0)?(int)((x)+0.5f):(-(int)((-x)+0.5f))) + +#ifndef ABSVAL +#define ABSVAL(a) ((a)>=0?(a):(-(a))) +#endif + +#ifndef SQR +#define SQR(a) ((a)*(a)) +#endif + +#ifndef SWAP +#define SWAP(a,b) {tempr=(a); (a)=(b); (b)=tempr;} +#endif + +#ifndef swap +#define swap(x,y,type) {type u__p; u__p=x; x=y; y=u__p;} +#endif + +#define set_max(a, b) { if ((b) > *a) { *a = (b); } } /* If the first argument is already the highes or lowest, nothing is done. */ +#define set_min(a, b) { if ((b) < *a) { *a = (b); } } /* Otherwise, the 2nd arg is stored at the address of the first arg. */ + +static __inline Word16 L_Extract_lc(const Word32 L_32, Word16 *p_hi) +{ + *p_hi = extract_h(L_32); + return lshr(extract_l(L_32), 1); +} + +/*----------------------------------------------------------------------------------* + * MODE1 prototypes + *----------------------------------------------------------------------------------*/ + +float inv_sqrt( /* o : inverse square root of input value */ + const float x /* i : input value */ +); + +short own_random( /* o : output random value */ + short *seed /* i/o: random seed */ +); + +float sign( /* o : sign of x (+1/-1) */ + const float x /* i : input value of x */ +); + +float log2_f( /* o : logarithm2 of x */ + const float x /* i : input value of x */ +); + +short norm_ul( + unsigned int UL_var1 +); +short sum_s( /* o : sum of all vector elements */ + const short *vec, /* i : input vector */ + const short lvec /* i : length of input vector */ +); + +float sum_f( /* o : sum of all vector elements */ + const float *vec, /* i : input vector */ + const short lvec /* i : length of input vector */ +); + +float sum2_f( /* o : sum of all squared vector elements */ + const float *vec, /* i : input vector */ + const short lvec /* i : length of input vector */ +); + +void set_c( + char y[], /* i/o: Vector to set */ + const char a, /* i : Value to set the vector to */ + const short N /* i : Lenght of the vector */ +); + +void set_s( + short y[], /* i/o: Vector to set */ + const short a, /* i : Value to set the vector to */ + const short N /* i : Lenght of the vector */ +); + +void set_i( + int y[], /* i/o: Vector to set */ + const int a, /* i : Value to set the vector to */ + const short N /* i : Lenght of the vector */ +); + +void set_f( + float y[], /* i/o: Vector to set */ + const float a, /* i : Value to set the vector to */ + const short N /* i : Lenght of the vector */ +); + +void set_zero( + float *vec, /* o : input vector */ + int lvec /* i : length of the vector */ +); + +void mvr2r( + const float x[], /* i : input vector */ + float y[], /* o : output vector */ + const short n /* i : vector size */ +); + +void mvs2s( + const short x[], /* i : input vector */ + short y[], /* o : output vector */ + const short n /* i : vector size */ +); + +unsigned int mvr2s( + const float x[], /* i : input vector */ + short y[], /* o : output vector */ + const short n /* i : vector size */ +); + +void mvs2r( + const short x[], /* i : input vector */ + float y[], /* o : output vector */ + const short n /* i : vector size */ +); + +void mvi2i( + const int x[], /* i : input vector */ + int y[], /* o : output vector */ + const int n /* i : vector size */ +); +void AGC_dec( + float x[], + float mem[], + const short n +); + +short maximum( /* o : index of the maximum value in the input vector */ + const float *vec, /* i : input vector */ + const short lvec, /* i : length of input vector */ + float *max /* o : maximum value in the input vector */ +); + +short minimum( /* o : index of the minimum value in the input vector */ + const float *vec, /* i : input vector */ + const short lvec, /* i : length of input vector */ + float *min /* o : minimum value in the input vector */ +); + +short emaximum( /* o : return index with max energy value in vector */ + const float *vec, /* i : input vector */ + const short lvec, /* i : length of input vector */ + float *ener_max /* o : maximum energy value */ +); + +float mean( /* o : vector mean */ + const float *vec, /* i : input vector */ + const short lvec /* i : length of input vector */ +); + +float dotp( /* o : dot product of x[] and y[] */ + const float x[], /* i : vector x[] */ + const float y[], /* i : vector y[] */ + const short n /* i : vector length */ +); + +void conv( + const float x[], /* i : input vector */ + const float h[], /* i : impulse response (or second input vector) */ + float y[], /* o : output vetor (result of convolution) */ + const short L /* i : vector size */ +); + +void fir( + const float x[], /* i : input vector */ + const float h[], /* i : impulse response of the FIR filter */ + float y[], /* o : output vector (result of filtering) */ + float mem[], /* i/o: memory of the input signal (M samples) */ + const short L, /* i : input vector size */ + const short K, /* i : order of the FIR filter (M+1 coefs.) */ + const short upd /* i : 1 = update the memory, 0 = not */ +); + +void v_add( + const float x1[], /* i : Input vector 1 */ + const float x2[], /* i : Input vector 2 */ + float y[], /* o : Output vector that contains vector 1 + vector 2 */ + const short N /* i : Vector lenght */ +); + +void v_sub( + const float x1[], /* i : Input vector 1 */ + const float x2[], /* i : Input vector 2 */ + float y[], /* o : Output vector that contains vector 1 - vector 2 */ + const short N /* i : Vector lenght */ +); + +void v_mult( + const float x1[], /* i : Input vector 1 */ + const float x2[], /* i : Input vector 2 */ + float y[], /* o : Output vector that contains vector 1 .* vector 2 */ + const short N /* i : Vector lenght */ +); + +void v_multc( + const float x[], /* i : Input vector */ + const float c, /* i : Constant */ + float y[], /* o : Output vector that contains c*x */ + const short N /* i : Vector lenght */ +); + +int squant( /* o: index of the winning codeword */ + const float x, /* i: scalar value to quantize */ + float *xq, /* o: quantized value */ + const float cb[], /* i: codebook */ + const int cbsize /* i: codebook size */ +); + +int vquant( /* o: index of the winning codevector */ + float x[], /* i: vector to quantize */ + const float x_mean[], /* i: vector mean to subtract (0 if none) */ + float xq[], /* o: quantized vector */ + const float cb[], /* i: codebook */ + const int dim, /* i: dimension of codebook vectors */ + const int cbsize /* i: codebook size */ +); + +int w_vquant( /* o: index of the winning codevector */ + float x[], /* i: vector to quantize */ + const float x_mean[], /* i: vector mean to subtract (0 if none) */ + const short weights[], /* i: error weights */ + float xq[], /* o: quantized vector */ + const float cb[], /* i: codebook */ + const int dim, /* i: dimension of codebook vectors */ + const int cbsize, /* i: codebook size */ + const short reverse /* i: reverse codebook vectors */ +); + +short usquant( /* o: index of the winning codeword */ + const float x, /* i: scalar value to quantize */ + float *xq, /* o: quantized value */ + const float qlow, /* i: lowest codebook entry (index 0) */ + const float delta, /* i: quantization step */ + const short cbsize /* i: codebook size */ +); + +float usdequant( /* o: dequanzited gain */ + const int idx, /* i: quantizer index */ + const float qlow, /* i: lowest codebook entry (index 0) */ + const float delta /* i: quantization step */ +); + +void v_sort( + float *r, /* i/o: Vector to be sorted in place */ + const short lo, /* i : Low limit of sorting range */ + const short up /* i : High limit of sorting range */ +); + +float var( /* o: variance of vector */ + const float *x, /* i: input vector */ + const int len /* i: length of inputvector */ +); + +float std_dev( /* o: standard deviation */ + const float *x, /* i: input vector */ + const int len /* i: length of the input vector */ +); + +float dot_product_mat( /* o : the dot product x'*A*x */ + const float *x, /* i : vector x */ + const float *A, /* i : matrix A */ + const short m /* i : vector length */ +); + +float root_a( + float a +); + +float root_a_over_b( + float a, + float b +); + +void polezero_filter ( + const float *in, /* i : input vector */ + float *out, /* o : output vector */ + const short N, /* i : input vector size */ + const float *b, /* i : numerator coefficients */ + const float *a, /* i : denominator coefficients */ + const short order, /* i : filter order */ + float *mem /* i/o: filter memory */ +); + +double rint_new( + double x /* i/o: Round to the nearest integer with mid point exception */ +); + +double anint( + double x /* i/o: Round to the nearest integer */ +); +short is_numeric_float( /* o : Output either 1 if Numeric, 0 if NaN or Inf */ + float x /* i : Input value which is checked if numeric or not */ +); + +void push_indice( + Encoder_State *st, /* i/o: encoder state structure */ + short id, /* i : ID of the indice */ + unsigned short value, /* i : value of the quantized indice */ + short nb_bits /* i : number of bits used to quantize the indice */ +); + +void push_next_indice( + Encoder_State *st, /* i/o: encoder state structure */ + unsigned short value, /* i : value of the quantized indice */ + short nb_bits /* i : number of bits used to quantize the indice */ +); + +void push_next_bits( + Encoder_State *st, /* i/o: encoder state structure */ + int bits[], /* i : bit buffer to pack, sequence of single bits */ + short nb_bits /* i : number of bits to pack */ +); + +unsigned short get_next_indice( /* o : value of the indice */ + Decoder_State *st, /* i/o: decoder state structure */ + short nb_bits /* i : number of bits that were used to quantize the indice */ +); + +unsigned short get_next_indice_1( /* o : value of the indice */ + Decoder_State *st /* i/o: decoder state structure */ +); + +void get_next_indice_tmp( + Decoder_State *st, /* o : decoder state structure */ + short nb_bits /* i : number of bits that were used to quantize the indice */ +); + +unsigned short get_indice( /* o : value of the indice */ + Decoder_State *st, /* i/o: decoder state structure */ + short pos, /* i : absolute position in the bitstream */ + short nb_bits /* i : number of bits that were used to quantize the indice */ +); + +unsigned short get_indice_1( /* o : value of the indice */ + Decoder_State *st, /* i/o: decoder state structure */ + short pos /* i : absolute position in the bitstream */ +); + +void reset_indices_enc( + Encoder_State *st /* i/o: encoder state structure */ +); + +void reset_indices_dec( + Decoder_State *st /* i/o: decoder state structure */ +); + +void write_indices( + Encoder_State *st, /* i/o: encoder state structure */ + FILE *file /* i : output bitstream file */ + , UWord8 *pFrame, /* i : byte array with bit packet and byte aligned coded speech data */ + Word16 pFrame_size /* i : size of the binary encoded access unit [bits] */ +); + +short read_indices( /* o : 1 = OK, 0 = something wrong */ + Decoder_State *st, /* i/o: decoder state structure */ + const char *data, /* i : bitstream buffer */ + size_t data_size, /* i : bitstream buffer size */ + size_t* data_processed, /* o : processed data size */ + const short rew_flag /* i : rewind flag (rewind file after reading) */ +); + +Word16 read_indices_mime( /* o : 1 = reading OK, 0 = problem */ + Decoder_State *st, /* i/o: decoder state structure */ + const char* data, /* i : bitstream data */ + size_t data_size, /* i : bitstream data size */ + size_t* data_processed, /* o : processed data size */ + Word16 rew_flag /* i : rewind flag (rewind file after reading)*/ +); + +void indices_to_serial( + const Encoder_State *st, /* i: encoder state structure */ + UWord8 *pFrame, /* o: byte array with bit packet and byte aligned coded speech data */ + Word16 *pFrame_size +); + +void indices_to_serial_generic( + const Indice *ind_list, /* i: indices list */ + const Word16 num_indices, /* i: number of indices to write */ + UWord8 *pFrame, /* o: byte array with bit packet and byte aligned coded speech data */ + Word16 *pFrame_size /* o: size of the binary encoded access unit [bits] */ +); + +void evs_dec_previewFrame( + unsigned char *bitstream, /* i : bitstream pointer */ + int bitstreamSize, /* i : bitstream size */ + short *partialCopyFrameType, /* o : frame type of the partial copy */ + short *partialCopyOffset /* o : offset of the partial copy relative to the primary copy */ +); + +void read_indices_from_djb( + Decoder_State *st, /* i/o: decoder state structure */ + unsigned char *pt_stream, /* i : bitstream file */ + int nbits /* i : number of bits */ + ,short partialframe /* i : partial frame information */ + ,short next_coder_type /* i : next coder type information */ +); + +void getPartialCopyInfo( + Decoder_State *st, /* i : decoder state structure */ + short *coder_type, + short *sharpFlag +); + +void get_NextCoderType( + unsigned char *bitsteam, /* i : bitstream */ + short *next_coder_type /* o : next coder type */ +); + +int print_disclaimer ( + FILE *fPtr +); + +void autocorr( + const float *x, /* i : input signal */ + float *r, /* o : autocorrelations vector */ + const short m, /* i : order of LP filter */ + const short len, /* i : window size */ + const float *wind, /* i : window */ + const short rev_flag, /* i : flag to reverse window */ + const short sym_flag, /* i : symmetric window flag */ + const short no_thr /* i : flag to avoid thresholding */ +); + +short lev_dur( /* o: energy of prediction error */ + float *a, /* o: LP coefficients (a[0] = 1.0) */ + const float *r, /* i: vector of autocorrelations */ + const short m, /* i: order of LP filter */ + float epsP[] /* o: prediction error energy */ +); + +float get_delay( /* o : delay value in ms */ + const short what_delay, /* i : what delay? (ENC or DEC) */ + const int io_fs /* i : input/output sampling frequency */ +); + +void decision_matrix_enc( + Encoder_State *st, /* i/o: encoder state structure */ + const short sp_aud_decision1, /* i : 1st stage speech/music classification */ + const short sp_aud_decision2, /* i : 2nd stage speech/music classification */ + const short coder_type, /* i : coder type */ + const short vad_flag, + short *hq_core_type /* o : HQ core type */ +); + +void signalling_enc( + Encoder_State *st, /* i : encoder state structure */ + const short coder_type, /* i : coder type */ + const short sharpFlag /* i : formant sharpening flag */ +); + +short signalling_mode1_tcx20_enc( + Encoder_State *st, /* i/o: encoder state structure */ + const short push /* i : flag to push indice */ +); + +void decision_matrix_dec( + Decoder_State *st, /* i/o: decoder state structure */ + short *coder_type, /* o : coder type */ + short *sharpFlag, /* o : formant sharpening flag */ + short *hq_core_type, /* o : HQ core type */ + short *core_switching_flag /* o : ACELP->HQ switching frame flag */ +); + +float lsf_stab( /* o : LP filter stability */ + const float *lsf, /* i : LSF vector */ + const float *lsfold, /* i : old LSF vector */ + const short Opt_AMR_WB, /* i : flag indicating AMR-WB IO mode */ + const short L_frame /* i : frame lenght */ +); + +void hf_synth_amr_wb_init( + float *prev_r, /* o : 1 sample memory for preemphasis/deemphasis*/ + float *fmerit_w_sm, /* o : 1 sample memory fmerit_w param*/ + float mem_syn_hf[], /* o : HF LPC synthesis filter initialization */ + short *frame_count, /* o : frame counter initialization */ + float *ne_min, /* o : minimum Noise gate - short-term energy initialization*/ + float *fmerit_m_sm, /* o : 1 sample memory fmerit_m param */ + float *voice_fac, /* o : voice factor initialization */ + float *unvoicing, /* o : unvoiced parameter */ + float *unvoicing_sm, /* o : smoothed unvoiced parameter */ + short *unvoicing_flag, /* o : unvoiced flag */ + short *voicing_flag, /* o : voiced flag */ + short *start_band_old, /* o : previous start point for copying frequency band */ + float *OptCrit_old /* o : previous criterion value for deciding the start point */ +); + +void hf_synth_amr_wb_reset( + short *seed2, /* i/o: random seed for HF noise gen */ + float mem_syn_hf[], /* o : HF synthesis memory */ + float mem_hp_interp[], /* o : interpol. memory */ + float *prev_r, /* o : 1 sample memory for deemphasis */ + float *fmerit_w_sm, /* o : 1 sample memory fmerit_w param */ + float delay_syn_hf[], /* o : HF synthesis memory */ + short *frame_count, /* o : frame counter memory */ + float *ne_min, /* o : minimum Noise gate - short-term energy memory */ + float *fmerit_m_sm, /* o : 1 sample memory fmerit_m param */ + float *voice_fac, /* o : voice factor memory */ + float *unvoicing, /* o : unvoiced parameter */ + float *unvoicing_sm, /* o : smoothed unvoiced parameter */ + short *unvoicing_flag, /* o : unvoiced flag */ + short *voicing_flag, /* o : voiced flag */ + short *start_band_old, /* o : previous start point for copying frequency band */ + float *OptCrit_old /* o : previous criterion value for deciding the start point */ +); + +void hf_synth_amr_wb( + const long core_brate, /* i : core bitrate */ + const short output_frame, /* i : output frame length */ + const float *Aq, /* i : quantized Az */ + const float *exc, /* i : excitation at 12.8 kHz */ + float *synth, /* i/o: synthesis signal at 12.8 kHz */ + float *mem_syn_hf, /* i/o: HF synthesis memory */ + float *delay_syn_hf, /* i/o: HF synthesis memory */ + float *prev_r, /* i/o: preemphasis/deemphasis filter memory */ + float *fmerit_w_sm, /* i/o: smoothed fmerit_w */ + short *amr_io_class, /* i : signal class (determined by FEC algorithm) */ + float *mem_hp_interp, /* i/o: interpol. memory */ + float *synth_out, /* i/o: synthesis signal at output Fs */ + float fmerit, /* i : classify parameter from FEC */ + const short *hf_gain, /* i : decoded HF gain */ + const float *voice_factors, /* i : voicing factors */ + const float pitch_buf[], /* i : pitch buffer */ + const float ng_ener_ST, /* i : Noise gate - short-term energy */ + const float *lsf_new, /* i : ISF vector */ + short *frame_count, /* i/o: frame counter */ + float *ne_min, /* i/o: minimum Noise gate */ + float *fmerit_m_sm, /* i/o: smoothed fmerit_m */ + float *voice_facor_sm, /* i/o: voice factor memory */ + float *unvoicing, /* i/o: unvoiced parameter */ + float *unvoicing_sm, /* i/o: smoothed unvoiced parameter */ + short *unvoicing_flag, /* i/o: unvoiced flag */ + short *voicing_flag, /* i/o: voiced flag */ + short *start_band_old, /* i/o: previous start point for copying frequency band */ + float *OptCrit_old /* i/o: previous criterion value for deciding the start point */ +); + +void hf_cod_init( + float *mem_hp400_enc, /* o: memory of hp 400 Hz filter */ + float *mem_hf1_enc, /* o: HF band-pass filter memory */ + float *mem_syn_hf_enc, /* o: HF synthesis memory */ + float *mem_hf2_enc, /* o: HF band-pass filter memory */ + float *gain_alpha /* o: smoothing gain for transitions between active and inactive frames */ +); + +void hf_cod( + const long core_brate, /* i : core bitrate */ + const float *speech16k, /* i : original speech at 16 kHz */ + const float Aq[], /* i : quantized Aq */ + const float exc[], /* i : excitation at 12.8 kHz */ + float synth[], /* i : 12.8kHz synthesis signal */ + short *seed2_enc, /* i/o: random seed for HF noise gen */ + float *mem_hp400_enc, /* i/o: memory of hp 400 Hz filter */ + float *mem_syn_hf_enc, /* i/o: HF synthesis memory */ + float *mem_hf1_enc, /* i/o: HF band-pass filter memory */ + float *mem_hf2_enc, /* i/o: HF band-pass filter memory */ + const short *dtxHangoverCount, + float *gain_alpha, /* i/o: smoothing gain for transitions between active and inactive frames */ + short *hf_gain /* o : HF gain to be transmitted to decoder */ +); + +void hf_synth_init( + float mem_hp400[], /* o: 400 Hz high pass filter memory initialization */ + float mem_hf[] /* o: band pass 6kHz to 7kHz FIR filter initialization */ +); + +void hf_synth_reset( + short *seed2, /* i/o: random seed for HF noise gen */ + float mem_hf[], /* o : HF band-pass filter memory */ + float mem_syn_hf[], /* o : HF synthesis memory */ + float mem_hp400[], /* o : memory of hp 400 Hz filter */ + float mem_hp_interp[], /* o : interpol. memory */ + float delay_syn_hf[] /* o : HF synthesis memory */ +); + +void hf_synth( + const long core_brate, /* i : core bitrate */ + const short output_frame, /* i : output frame length */ + const float *Aq, /* i : quantized Az */ + const float *exc, /* i : excitation at 12.8 kHz */ + float *synth, /* i/o: 12.8kHz synthesis signal */ + float *synth16k, /* i/o: 16kHz synthesis signal */ + short *seed2, /* i/o: random seed for HF noise gen */ + float *mem_hp400, /* i/o: memory of hp 400 Hz filter */ + float *mem_syn_hf, /* i/o: HF synthesis memory */ + float *mem_hf, /* i/o: HF band-pass filter memory */ + float *delay_syn_hf, /* i/o: HF synthesis memory */ + float *mem_hp_interp /* i/o: interpol. memory */ +); + +short lsp_convert_poly( + float w[], /* i/o: LSP or ISP parameters */ + const short L_frame, /* i : flag for up or down conversion */ + const short Opt_AMRWB /* i : flag for the AMR-WB IO mode */ +); + +short findpulse( /* o : pulse position */ + const short L_frame, /* i : length of the frame */ + const float res[], /* i : residual signal */ + const short T0, /* i : integer pitch */ + const short enc_dec, /* i : flag enc/dec, 0 - enc, 1 - dec */ + short *sign /* i/o: sign of the maximum */ +); + +void fft_rel( + float x[], /* i/o: input/output vector */ + const short n, /* i : vector length */ + const short m /* i : log2 of vector length */ +); + +void ifft_rel( + float io[], /* i/o: input/output vector */ + const short n, /* i : vector length */ + const short m /* i : log2 of vector length */ +); + +void preemph( + float *signal, /* i/o: signal */ + const float mu, /* i : preemphasis factor */ + const short L, /* i : vector size */ + float *mem /* i/o: memory (x[-1]) */ +); + +void cb_shape( + const short preemphFlag, /* i : flag for pre-emphasis */ + const short pitchFlag, /* i : flag for pitch sharpening */ + const short scramblingFlag, /* i : flag for phase scrambling */ + const short formantFlag, /* i : flag for formant sharpening */ + const short formantTiltFlag, /* i : flag for formant tilt */ + const float g1, /* i : formant sharpening numerator weighting */ + const float g2, /* i : formant sharpening denominator weighting */ + const float *p_Aq, /* i : LP filter coefficients */ + float *code, /* i/o: signal to shape */ + const float tilt_code, /* i : tilt of code */ + const float pt_pitch /* i : pointer to current subframe fractional pitch*/ +); + +void isp2a( + const float *isp, /* i : ISP vector (in the cosine domain) */ + float *a, /* o : LP filter coefficients */ + const short m /* i : order of LP analysis */ +); + +void isp2isf( + const float isp[], /* i : isp[m] (range: -1<=val<1) */ + float isf[], /* o : isf[m] normalized (range: 0<=val<=fs/2) */ + const short m, /* i : LPC order */ + const float fs /* i : sampling frequency */ +); + +void isf2isp( + const float isf[], /* i : isf[m] normalized (range: 0<=val<=fs/2) */ + float isp[], /* o : isp[m] (range: -1<=val<1) */ + const short m, /* i : LPC order */ + const float fs /* i : sampling frequency */ +); + +void reorder_isf( + float *isf, /* i/o: vector of isfs in the frequency domain (0..0.5)*/ + const float min_dist, /* i : minimum required distance */ + const short n, /* i : LPC order */ + const float fs /* i : sampling frequency */ +); + +void lsp2lsf( + const float lsp[], /* i : isp[m] (range: -1<=val<1) */ + float lsf[], /* o : isf[m] normalized (range: 0<=val<=fs/2) */ + const short m, /* i : LPC order */ + const float fs /* i : sampling frequency */ +); + +void lsf2lsp( + const float lsf[], /* i : isf[m] normalized (range: 0<=val<=fs/2) */ + float lsp[], /* o : isp[m] (range: -1<=val<1) */ + const short m, /* i : LPC order */ + const float fs /* i : sampling frequency */ +); + +void lsp2isp( + const float *lsp, /* i : LSP vector */ + float *isp, /* o : ISP filter coefficients */ + float *stable_isp, /* i/o: ISP filter coefficients */ + const short m /* i : order of LP analysis */ +); + +void isp2lsp( + const float *isp, /* i : LSP vector */ + float *lsp, /* o : ISP filter coefficients */ + float *stable_lsp, /* i/o: stable LSP filter coefficients */ + const short m /* i : order of LP analysis */ +); + +void reorder_lsf( + float *lsf, /* i/o: vector of lsfs in the frequency domain (0..0.5)*/ + const float min_dist, /* i : minimum required distance */ + const short n, /* i : LPC order */ + const float fs /* i : sampling frequency */ +); + +void CNG_exc( + const long core_brate, /* i : core bitrate */ + const short L_frame, /* i : length of the frame */ + float *Enew, /* i/o: decoded SID energy */ + short *seed, /* i/o: random generator seed */ + float exc[], /* o : current non-enhanced excitation */ + float exc2[], /* o : current enhanced excitation */ + float *lp_ener, /* i/o: LP filtered E */ + const long last_core_brate, /* i : previous frame core bitrate */ + short *first_CNG, /* i/o: first CNG frame flag for energy init. */ + short *cng_ener_seed, /* i/o: random generator seed for CNG energy */ + float bwe_exc[], /* o : excitation for SWB TBE */ + const short allow_cn_step, /* i : allow CN step */ + short *last_allow_cn_step, /* i/o: last CN_step */ + const short num_ho, /* i : number of selected hangover frames */ + float q_env[], + float *lp_env, + float *old_env, + float *exc_mem, + float *exc_mem1, + short *sid_bw, + short *cng_ener_seed1, + float exc3[], + short Opt_AMR_WB +); + +void cng_params_upd( + const float lsp_new[], /* i : LSP aprameters */ + const float exc2[], /* i : current enhanced excitation */ + const short L_frame, /* i : frame length */ + short *ho_circ_ptr, /* i/o: pointer for CNG averaging buffers */ + float ho_ener_circ[], /* o : energy buffer for CNG averaging */ + short *ho_circ_size, /* i/o: size of DTX hangover history buffer for averaging */ + float ho_lsp_circ[], /* o : old LSP buffer for CNG averaging */ + const short enc_dec_flag, /* i : Flag indicating encoder or decoder (ENC,DEC) */ + float ho_env_circ[], /* i/o: Envelope buffer */ + short *cng_buf_cnt, /* i/o: Counter of postponed FFT-processing instances */ + float cng_exc2_buf[], /* i/o: Excitation buffer */ + long cng_brate_buf[], /* i/o: last_active_brate buffer */ + const long last_active_brate /* i : Last active bit rate */ +); + +void cng_params_postupd( + const short ho_circ_ptr, /* i : pointer for CNG averaging buffers */ + short *cng_buf_cnt, /* i/o: counter for CNG store buffers */ + const float *const cng_exc2_buf, /* i : Excitation buffer */ + const long *const cng_brate_buf, /* i : bit rate buffer */ + float ho_env_circ[] /* i/o: Envelope buffer */ +); + +void disf_ns_28b( + short *indice, /* i : quantized indices (use indice[0] = -1 in the decoder) */ + float *isf_q /* o : ISF in the frequency domain (0..6400) */ +); + +void limit_T0( + const short L_frame, /* i : length of the frame */ + const short delta, /* i : Half the close-loop searched interval */ + const short pit_flag, /* i : selecting absolute(0) or delta(1) pitch quantization */ + const short limit_flag, /* i : flag for limits (0=restrained, 1=extended) */ + const short T0, /* i : rough pitch estimate around which the search is done */ + const short T0_frac, /* i : pitch estimate fractional part */ + short *T0_min, /* o : lower pitch limit */ + short *T0_max /* o : higher pitch limit */ +); + +float interpolation( /* o : interpolated value */ + const float *x, /* i : input vector */ + const float *win, /* i : interpolation window */ + const short frac, /* i : fraction */ + const short up_samp, /* i : upsampling factor */ + const short nb_coef /* i : nb of filter coef */ +); + +void deemph( + float *signal, /* i/o: signal */ + const float mu, /* i : deemphasis factor */ + const short L, /* i : vector size */ + float *mem /* i/o: memory (y[-1]) */ +); + +float est_tilt( /* o : tilt of the code */ + const float *adpt_exc, /* i : adaptive excitation vector */ + const float gain_pit, /* i : adaptive gain */ + const float *fixe_exc, /* i : algebraic exctitation vector */ + const float gain_code, /* i : algebraic code gain */ + float *voice_fac, /* o : voicing factor */ + const short L_subfr, /* i : subframe size */ + const short flag_tilt /* i : flag for special tilt */ +); + +void weight_a( + const float *a, /* i : LP filter coefficients */ + float *ap, /* o : weighted LP filter coefficients */ + const float gamma, /* i : weighting factor */ + const short m /* i : order of LP filter */ +); + +void weight_a_subfr( + const short nb_subfr, /* i : number of subframes */ + const float *a, /* i : LP filter coefficients */ + float *ap, /* o : weighted LP filter coefficients */ + const float gamma, /* i : weighting factor */ + const short m /* i : order of LP filter */ +); + +void syn_12k8( + const short L_frame, /* i : length of the frame */ + const float *Aq, /* i : LP filter coefficients */ + const float *exc, /* i : input signal */ + float *synth, /* o : output signal */ + float *mem, /* i/o: initial filter states */ + const short update_m /* i : update memory flag: 0 --> no memory update */ +); /* 1 --> update of memory */ + +void syn_filt( + const float a[], /* i : LP filter coefficients */ + const short m, /* i : order of LP filter */ + const float x[], /* i : input signal */ + float y[], /* o : output signal */ + const short l, /* i : size of filtering */ + float mem[], /* i/o: initial filter states */ + const short update_m /* i : update memory flag: 0 --> no memory update */ +); /* 1 --> update of memory */ +void synth_mem_updt2( + const short L_frame, /* i : frame length */ + const short last_L_frame, /* i : frame length */ + float old_exc[], /* i/o : excitation buffer */ + float mem_syn_r[], /* i/o: synthesis filter memory */ + float mem_syn2[], /* o : synthesis filter memory for find_target */ + float mem_syn[], /* o : synthesis filter memory for find_target */ + const short dec /* i: flag for decoder indication */ +); + +void int_lsp( + const short L_frame, /* i : length of the frame */ + const float lsp_old[], /* i : LSPs from past frame */ + const float lsp_new[], /* i : LSPs from present frame */ + float *Aq, /* o : LP coefficients in both subframes */ + const short m, /* i : order of LP filter */ + const float *int_coeffs, /* i : interpolation coefficients */ + const short Opt_AMR_WB /* i : flag indicating AMR-WB IO mode */ +); + +void int_lsp4( + const short L_frame, /* i : length of the frame */ + const float lsp_old[], /* i : previous end-frame LSPs */ + const float lsp_mid[], /* i : current mid-frame LSPs */ + const float lsp_new[], /* i : current end-frame LSPs */ + float *Aq, /* o : LP coefficients in both subframes */ + const short m, /* i : order of LP filter */ + short relax_prev_lsf_interp /* i : relax prev frame lsf interp after erasure */ +); + +short modify_Fs( /* o : length of output */ + const float sigIn[], /* i : signal to decimate */ + short lg, /* i : length of input */ + const int fin, /* i : frequency of input */ + float sigOut[], /* o : decimated signal */ + const int fout, /* i : frequency of output */ + float mem[] /* i/o: filter memory */ + ,int nblp /* i : flag indicating if NB low-pass is applied */ +); + +void pred_lt4( + const float excI[], /* i : input excitation buffer */ + float excO[], /* o : output excitation buffer */ + const short T0, /* i: integer pitch lag */ + short frac, /* i: fraction of lag */ + const short L_subfr, /* i: subframe size */ + const float *win, /* i: interpolation window */ + const short nb_coef, /* i : nb of filter coef */ + const short up_sample /* i : up_sample */ +); + +void pred_lt4_tc( + float exc[], /* i: excitation buffer */ + const short T0, /* i: integer pitch lag */ + short frac, /* i: fraction of lag */ + const float *win, /* i : interpolation window */ + const short imp_pos, /* i: glottal impulse position */ + const short i_subfr /* i: subframe index */ +); + +void residu( + const float *a, /* i : LP filter coefficients */ + const short m, /* i : order of LP filter */ + const float *x, /* i : input signal (usually speech) */ + float *y, /* o : output signal (usually residual) */ + const short l /* i : size of filtering */ +); + +void calc_residu( + const float *speech, /* i : weighted speech signal */ + float *res, /* o : residual signal */ + const float *p_Aq, /* i : quantized LP filter coefficients */ + const short L_frame /* i : size of frame */ +); + +float enr_1_Az( /* o : impulse response energy */ + const float Aq[], /* i : LP filter coefs */ + const short len /* i : impulse response length */ +); + + +void Es_pred_enc( + float *Es_pred, /* o : predicited scaled innovation energy */ + int *Es_pred_indice, /* o : indice corresponding to above parameter */ + const short L_frame, /* i : length of the frame */ + const short L_subfr, /* i : length of the subframe */ + const float *res, /* i : residual signal */ + const float *voicing, /* i : normal. correlattion in three 1/2frames */ + const short nb_bits, /* i : allocated number of bits */ + const short no_ltp /* i : no_ltp flag */ +); + +void init_lvq( + unsigned int offset_scale1[][MAX_NO_SCALES+1], + unsigned int offset_scale2[][MAX_NO_SCALES+1], + unsigned int offset_scale1_p[][MAX_NO_SCALES+1], + unsigned int offset_scale2_p[][MAX_NO_SCALES+1], + short no_scales[][2], + short no_scales_p[][2] +); + +float mslvq ( + float *pTmp, /* i : M-dimensional input vector */ + float *quant, /* o : quantized vector */ + float *cv_out, /* o : corresponding 8-dim lattice codevectors (without the scaling) */ + int *idx_lead, /* o : leader index for each 8-dim subvector */ + int *idx_scale, /* o : scale index for each subvector */ + float *w, /* i : weights for LSF quantization */ + short mode, /* i : number indicating the coding type (V/UV/G...)*/ + short mode_glb, /* i : LVQ coding mode */ + int pred_flag, /* i : prediction flag (0: safety net, 1 - predictive )*/ + short no_scales[][2] +); + +void permute( + float *pTmp1, /* (i/o): vector whose components are to be permuted */ + const short *perm /* (i) : permutation info (indexes that should be interchanged), max two perms */ +); + +float mslvq_cng( + short idx_cv, /* (i): index of cv from previous stage */ + float *pTmp, /* (i): 16 dimensional input vector */ + float *quant, /* (o): quantized vector */ + float *cv_out, /* (o): corresponding 8-dim lattice codevectors (without the scaling) */ + int *idx_lead, /* (o): leader index for each 8-dim subvector */ + int *idx_scale, /* (o): scale index for each subvector */ + const float *w, /* (i): weights for LSF quantization */ + short * no_scales +); + +short deindex_lvq_cng( + short *index, /* i : index to be decoded, as an array of 3 short */ + float *x_lvq, /* o : decoded codevector */ + short idx_cv, /* i : relative mode_lvq, wrt START_CNG */ + int no_bits, /* i : number of bits for lattice */ + unsigned int * p_offset_scale1, + unsigned int * p_offset_scale2, + short * p_no_scales +); + +void multiply32_32_64( + unsigned int x, /* (i): operand 1 */ + unsigned int y, /* (i): operand 2 */ + unsigned int *res /* (o): result as array of two uint32 */ +); + +short deindex_lvq( + short *index, /* (i): index to be decoded, as an array of 3 short */ + float *x_lvq, /* (o): decoded codevector */ + short mode, /* (i): LVQ coding mode (select scales & no_lead ), or idx_cv */ + short sf_flag, /* (i): safety net flag */ + short no_bits, /* (i): number of bits for lattice */ + unsigned int *p_offset_scale1, /* i : offset for first subvector */ + unsigned int *p_offset_scale2, /* i : offset for the second subvector */ + short * p_no_scales +); +short vq_dec_lvq ( + short sf_flag, /* i : safety net flag */ + float x[], /* o : Decoded vector */ + short indices[], /* i : Indices */ + short stages, /* i : Number of stages */ + short N, /* i : Vector dimension */ + short mode, /* i : lvq coding type */ + short no_bits, /* i : no. bits for lattice */ + unsigned int * p_offset_scale1, + unsigned int * p_offset_scale2, + unsigned int * p_offset_scale1_p, + unsigned int * p_offset_scale2_p, + short * p_no_scales, + short * p_no_scales_p +); + +void index_lvq ( + float *quant, /* i : codevector to be indexed (2 8-dim subvectors)*/ + int *idx_lead, /* i : leader class index for each subvector */ + int *idx_scale, /* i : scale index for each subvector */ + int mode, /* i : integer signalling the quantizer structure for the current bitrate */ + short *index, /* o : encoded index (represented on 3 short each with 15 bits ) */ + unsigned int * p_offset_scale1, + unsigned int * p_offset_scale2, + short * p_no_scales +); + +short qlsf_ARSN_tcvq_Dec_16k ( + float *y, /* o : Quantized LSF vector */ + short *indice, /* i : Indices */ + const short nBits /* i : number of bits */ +); + +int lsf_bctcvq_encprm( + Encoder_State *st, + int *param_lpc, + short *bits_param_lpc, + short no_indices +); + +int lsf_bctcvq_decprm( + Decoder_State *st, + int *param_lpc +); + +void lsf_allocate( + const short nBits, /* i : Number of bits to use for quantization */ + const short framemode, /* i : ISF quantizer mode */ + const short framemode_p, /* i : ISF quantizer mode */ + short *stages0, /* o : Number of stages for safety-net quantizer */ + short *stages1, /* o : Number of stages for predictive quantizer */ + short levels0[], /* o : Number of vectors for each stage for SFNET */ + short levels1[], /* o : Number of vectors for each stage for pred */ + short bits0[], /* o : Number of bits for each stage safety net */ + short bits1[] /* o : Number of bits for each stage predictive */ +); + +void disf_2s_36b( + short *indice, /* i : quantized indices (use indice[0] = -1 in the decoder) */ + float *isf_q, /* o : quantized ISFs in the cosine domain */ + float *mem_AR, /* i/o: quantizer memory for AR model */ + float *mem_MA /* i/o: quantizer memory for MA model */ +); + +void disf_2s_46b( + short *indice, /* i : quantized indices (use indice[0] = -1 in the decoder) */ + float *isf_q, /* o : quantized ISFs in the cosine domain */ + float *mem_AR, /* o : quantizer memory for AR model */ + float *mem_MA /* i/o: quantizer memory for MA model */ +); + +void re8_k2y( + const int *k, /* i : Voronoi index k[0..7] */ + const int m, /* i : Voronoi modulo (m = 2^r = 1<=2) */ + int *y /* o : 8-dimensional point y[0..7] in RE8 */ +); + +void re8_PPV( + float x[], /* i : point in R^8 */ + int y[] /* o : point in RE8 (8-dimensional integer vector) */ +); + +void enhancer( + const short codec_mode, /* i : flag indicating Codec Mode */ + const long core_brate, /* i : core bitrate */ + const short cbk_index, /* i : */ + const short Opt_AMR_WB, /* i : flag indicating AMR-WB IO mode */ + const short coder_type, /* i : coding type */ + const short L_frame, /* i : frame size */ + const float voice_fac, /* i : subframe voicing estimation */ + const float stab_fac, /* i : LP filter stablility measure */ + const float norm_gain_code, /* i : normalized innovative cb. gain */ + const float gain_inov, /* i : gain of the unscaled innovation */ + float *gc_threshold, /* i/o: code threshold */ + float *code, /* i/o: innovation */ + float *exc2, /* i/o: adapt. excitation/total exc. */ + const float gain_pit, /* i : Quantized pitch gain */ + float *dispMem /* i/o: Phase dispersion algorithm memory */ +); + +void phase_dispersion( + const float gain_code, /* i : gain of code */ + const float gain_pit, /* i : gain of pitch */ + float code[], /* i/o: code vector */ + const short mode, /* i : level, 0=hi, 1=lo, 2=off */ + float disp_mem[] /* i/o: static memory (size = 8) */ +); + +void re8_vor( + int y[], /* i : point in RE8 (8-dimensional integer vector) */ + int *n, /* o : codebook number n=0,2,3,4,... (scalar integer) */ + int k[], /* o : Voronoi index (integer vector of dimension 8) used only if n>4 */ + int c[], /* o : codevector in Q0, Q2, Q3, or Q4 if n<=4, y=c */ + int *ka /* o : identifier of absolute leader (needed to index c)*/ +); + +void edct( + const float *x, /* i : input signal */ + float *y, /* o : output transform */ + short length /* i : length */ +); + +void edst( + const float *x, /* i : input signal */ + float *y, /* o : output transform */ + short length /* i : length */ +); + +void iedct_short( + const float *in, /* i : input vector */ + float *out, /* o : output vector */ + const short segment_length /* i : length */ +); + + +void DoRTFT480( + float *x, /* i/o : real part of input and output data */ + float *y /* i/o : imaginary part of input and output data */ +); + +void DoRTFT320( + float *x, /* i/o : real part of input and output data */ + float *y /* i/o : imaginary part of input and output data */ +); + +void DoRTFT160( + float *x, /* i/o : real part of input and output data */ + float *y /* i/o : imaginary part of input and output data */ +); + +void DoRTFT128( + float *x, /* i/o : real part of input and output data */ + float *y /* i/o : imaginary part of input and output data */ +); + +void DoRTFT120( + float *x, /* i/o : real part of input and output data */ + float *y /* i/o : imaginary part of input and output data */ +); + +void DoRTFT80( + float *x, /* i/o : real part of input and output data */ + float *y /* i/o : imaginary part of input and output data */ +); + +void DoRTFT20( + float *x, /* i/o : real part of input and output data */ + float *y /* i/o : imaginary part of input and output data */ +); + +void DoRTFT40( + float *x, /* i/o : real part of input and output data */ + float *y /* i/o : imaginary part of input and output data */ +); + +void DoRTFTn( + float *x, /* i/o : real part of input and output data */ + float *y, /* i/o : imaginary part of input and output data */ + const short n /* i : size of the FFT n=(2^k) up to 1024 */ +); + +void BASOP_cfft( + Word32 *re, /* i/o: real part */ + Word32 *im, /* i/o: imag part */ + Word16 s, /* i : stride real and imag part */ + Word16 *scale /* i : scalefactor */ +); + +void sinq( + const float tmp, /* i : sinus factor cos(tmp*i+phi) */ + const float phi, /* i : sinus phase cos(tmp*i+phi) */ + const short N, /* i : size of output */ + float x[] /* o : output vector */ +); + +void edct2( + short n, + short isgn, + float *in, + float *a, + const short *ip, + const float *w +); + +void stat_noise_uv_mod( + const short coder_type, /* i : coding type */ + float noisiness, /* i : noisiness parameter */ + const float *isp_old, /* i : old ISP vector at 4th sfr */ + const float *isp_new, /* i : ISP vector at 4th sfr */ + const float *isp_mid, /* i : ISP vector at 2nd sfr */ + float *Aq, /* o : A(z) quantized for the 4 subframes */ + float *exc2, /* o : excitation buffer */ + const short bfi, /* i : bad frame indicator */ + float *ge_sm, /* i/o: ???? */ + short *uv_count, /* i/o: unvoiced counter */ + short *act_count, /* i/o: activation counter */ + float lspold_s[], /* i/o: old LSP */ + short *noimix_seed, /* i/o: mixture seed */ + float *st_min_alpha, /* i/o: minimum alpha */ + float *exc_pe, /* i/o: scale Q_stat_noise */ + const long bitrate, /* i : core bitrate */ + const short bwidth /* i : Bandwidth */ +); + +void SWB_TBE_describe_envelope( /* Function to represent energies in MDCT frequency bands */ + const float *yos, /* i : MDCT coefficients of weighted original */ + float *SWB_env_gain /* i/o: energy of SWB envelope */ +); + +void dct2( + const float in[], /* i : time domain input */ + float out[] /* o : transform domain output */ +); + +void idct2( + const float in[], /* i : transform domain input */ + float out[] /* o : time domain output */ +); + +void pre_echo_att( + float *Last_frame_ener, /* i/o: Energy of the last frame */ + float *exc, /* i/o: Excitation of the current frame */ + const short attack_flag, /* i : flag signalling attack encoded by AC mode (GSC) */ + const short last_coder_type /* i : Last coder type */ +); + +void hq_swb_harmonic_calc_norm_envelop( + float *SWB_signal, /* i : input signal */ + float *envelope, /* o : output envelope */ + int L_swb_norm, /* i : length of normaliztion */ + int SWB_flength /* i : length of input signal */ +); + +void limit_band_noise_level_calc( + short *wnorm, /* i : reordered norm of sub-vectors */ + short *limit, /* o : highest band of bit allocation */ + long core_brate, /* o : bit rate */ + float *noise_level /* o : noise level */ +); + +short peak_avrg_ratio( + const long total_brate, + const float *input_hi, /* i : input signal */ + const short N, /* i : number of coefficients */ + short *mode_count, /* i/o: HQ_HARMONIC mode count */ + short *mode_count1 /* i/o: HQ_NORMAL mode count */ +); + +short build_nf_codebook( /* o : Number of coefficients in nf codebook */ + const short flag_32K_env_ho, /* i : Envelope attenuation hangover flag */ + const float *coeff, /* i : Coded spectral coefficients */ + const short *sfm_start, /* i : Subband start indices */ + const short *sfmsize, /* i : Subband widths */ + const short *sfm_end, /* i : Subband end indices */ + const short nb_sfm, /* i : Number of subbands */ + const short *R, /* i : Per-band bit allocation */ + float *CodeBook, /* o : Noise-fill codebook */ + float *CodeBook_mod /* o : Densified noise-fill codebook */ +); + +void apply_noisefill_HQ( + const short *R, /* i : bit allocation */ + const short length, /* i : input frame length */ + const short flag_32K_env_ho, /* i : envelope stability hangover flag */ + const long core_brate, /* i : core bit rate */ + const short last_sfm, /* i : last coded subband */ + const float *CodeBook, /* i : Noise-fill codebook */ + const float *CodeBook_mod, /* i : Densified noise-fill codebook */ + const short cb_size, /* i : Codebook length */ + const short *sfm_start, /* i : Subband start coefficient */ + const short *sfm_end, /* i : Subband end coefficient */ + const short *sfmsize, /* i : Subband band width */ + float *coeff /* i/o: coded/noisefilled spectrum */ +); + +void harm_bwe_fine( + const short *R, /* i : bit allocation */ + const short last_sfm, /* i : last coded subband */ + const short high_sfm, /* i : higher transition band to BWE */ + const short num_sfm, /* i : total number of bands */ + const short *norm, /* i : quantization indices for norms */ + const short *sfm_start, /* i : Subband start coefficient */ + const short *sfm_end, /* i : Subband end coefficient */ + short *prev_L_swb_norm, /* i/o: last normalize length */ + float *coeff, /* i/o: coded/noisefilled normalized spectrum */ + float *coeff_out, /* o : coded/noisefilled spectrum */ + float *coeff_fine /* o : BWE fine structure */ +); + +void hvq_bwe_fine( + const short last_sfm, /* i : last coded subband */ + const short num_sfm, /* i : total number of bands */ + const short *sfm_end, /* i : Subband end coefficient */ + const short *peak_idx, /* i : Peak index */ + const short Npeaks, /* i : Number of peaks */ + short *peak_pos, /* i/o: Peak positions */ + short *prev_L_swb_norm, /* i/o: last normalize length */ + float *coeff, /* i/o: coded/noisefilled normalized spectrum */ + short *bwe_peaks, /* o : Positions of peaks in BWE */ + float *coeff_fine /* o : HVQ BWE fine structure */ +); + +void hq_fold_bwe( + const short last_sfm, /* i : last coded subband */ + const short *sfm_end, /* i : Subband end coefficient */ + const short num_sfm, /* i : Number of subbands */ + float *coeff /* i/o: coded/noisefilled normalized spectrum */ +); + +void apply_nf_gain( + const short nf_idx, + const short last_sfm, /* i : last coded subband */ + const short *R, /* i : bit allocation */ + const short *sfm_start, /* i : Subband start coefficient */ + const short *sfm_end, /* i : Subband end coefficient */ + float *coeff /* i/o: coded/noisefilled normalized spectrum */ + +); + +void hq_generic_fine( + float *coeff, /* i : coded/noisefilled normalized spectrum */ + const short last_sfm, /* i : Last coded band */ + const short *sfm_start, /* i : Subband start coefficient */ + const short *sfm_end, /* i : Subband end coefficient */ + short *bwe_seed, /* i/o: random seed for generating BWE input */ + float *coeff_out1 /* o : HQ GENERIC input */ +); + +void harm_bwe( + const float *coeff_fine, /* i : fine structure for BWE */ + const float *coeff, /* i : coded/noisefilled normalized spectrum */ + const short num_sfm, /* i : Number of subbands */ + const short *sfm_start, /* i : Subband start coefficient */ + const short *sfm_end, /* i : Subband end coefficient */ + const short last_sfm, /* i : last coded subband */ + const short high_sfm, /* i : */ + const short *R, /* i : bit allocation */ + const short prev_hq_mode, /* i : previous hq mode */ + short *norm, /* i/o: quantization indices for norms */ + float *noise_level, /* i/o: noise levels for harmonic modes */ + float *prev_noise_level, /* i/o: noise factor in previous frame */ + short *bwe_seed, /* i/o: random seed for generating BWE input */ + float *coeff_out /* o : coded/noisefilled spectrum */ +); + +void hvq_bwe( + const float *coeff, /* i : coded/noisefilled spectrum */ + const float *coeff_fine, /* i : BWE fine structure */ + const short *sfm_start, /* i : Subband start coefficient */ + const short *sfm_end, /* i : Subband end coefficient */ + const short *sfm_len, /* i : Subband length */ + const short last_sfm, /* i : last coded subband */ + const short prev_hq_mode, /* i : previous hq mode */ + const short *bwe_peaks, /* i : HVQ bwe peaks */ + const short bin_th, /* i : HVQ transition bin */ + const short num_sfm, /* i : Number of bands */ + const long core_brate, /* i : Core bit-rate */ + const short *R, /* i : Bit allocation */ + short *norm, /* i/o: quantization indices for norms */ + float *noise_level, /* i/o: noise levels for harmonic modes */ + float *prev_noise_level, /* i/o: noise factor in previous frame */ + short *bwe_seed, /* i/o: random seed for generating BWE input */ + float *coeff_out /* o : coded/noisefilled spectrum */ +); + +void hvq_concat_bands +( + const short pvq_bands, /* i : Number of bands in concatenated PVQ target */ + const short *sel_bnds, /* i : Array of selected high bands */ + const short n_sel_bnds, /* i : Number of selected high bands */ + short *hvq_band_start, /* i : Band start indices */ + short *hvq_band_width, /* i : Band widths */ + short *hvq_band_end /* i : Band end indices */ +); + +void hq_generic_bwe( + const short HQ_mode, /* i : HQ mode */ + float *coeff_out1, /* i/o: BWE input & temporary buffer */ + const float *hq_generic_fenv, /* i : SWB frequency envelopes */ + float *coeff_out, /* o : SWB signal in MDCT domain */ + const short hq_generic_offset, /* i : frequency offset for representing hq generic*/ + short *prev_L_swb_norm, /* i/o: last normalize length */ + const short hq_generic_exc_clas, /* i : hf excitation class */ + const short *sfm_end, /* i : End of bands */ + const short num_sfm, + const short num_env_bands, + const short *R +); + +void logqnorm_2( + const float *env_fl, /* o : index */ + const short L, /* i : codebook length */ + const short n_env_band, /* i : sub-vector size */ + const short nb_sfm, /* i : sub-vector size */ + short *ynrm, + short *normqlg2, + const float *thren /* i : quantization thresholds */ +); + +void map_hq_generic_fenv_norm( + const short hqswb_clas, + const float *hq_generic_fenv, + short *ynrm, + short *normqlg2, + const short num_env_bands, + const short nb_sfm, + const short hq_generic_offset +); + +short calc_nor_delta_hf( + Encoder_State *st, + const float *t_audio, + short *ynrm, + short *Rsubband, + const short num_env_bands, + const short nb_sfm, + const short *sfmsize, + const short *sfm_start, + const short core_sfm +); + +short get_nor_delta_hf( + Decoder_State *st, + short *ynrm, + short *Rsubband, + const short num_env_bands, + const short nb_sfm, + const short core_sfm +); + +void hq_wb_nf_bwe( + const float *coeff, /* i : coded/noisefilled normal. spectrum */ + const short is_transient, + const short prev_bfi, /* i : previous bad frame indicator */ + const float *normq_v, + const short num_sfm, /* i : Number of subbands */ + const short *sfm_start, /* i : Subband start coefficient */ + const short *sfm_end, /* i : Subband end coefficient */ + const short *sfmsize, /* i : Subband band width */ + const short last_sfm, /* i : last coded subband */ + const short *R, /* i : bit allocation */ + const short prev_is_transient, /* i : previous transient flag */ + float *prev_normq, /* i/o: previous norms */ + float *prev_env, /* i/o: previous noise envelopes */ + short *bwe_seed, /* i/o: random seed for generating BWE input*/ + float *prev_coeff_out, /* i/o: decoded spectrum in previous frame */ + short *prev_R, /* i/o: previous frame bit allocation info. */ + float *coeff_out /* o : coded/noisefilled spectrum */ +); + +short encode_envelope_indices( /* o : Number of bits */ + Encoder_State *st, /* i/o: encoder state structure */ + const short num_sfm, /* i : Number of subbands */ + const short numnrmibits, /* i : Bitrate of fall-back coding mode */ + short *difidx, /* i/o: Diff indices/encoded diff indices */ + short *LCmode, /* o : Coding mode */ + const short flag_pack, /* i : indicator of packing or estimating bits */ + const short flag_HQ2 /* i : indicator of HQ2 core */ + ,const short is_transient +); + +void diff_envelope_coding( + const short is_transient, /* i : transient indicator */ + const short num_env_bands, /* i : number of envelope bands to code */ + const short start_norm, /* i : start of envelope coding */ + short *ynrm, /* i/o: quantization indices for norms */ + short *normqlg2, /* i/o: quantized norms */ + short *difidx /* o : differential code */ +); + +short decode_envelope_indices( /* o : Number of bits */ + Decoder_State *st, /* i/o: decoder state structure */ + const short start_norm, /* i : First SDE encoded norm */ + const short num_sfm, /* i : Number of norms */ + const short numnrmibits, /* i : Bitrate of fall-back coding mode */ + short *ynrm, /* o : Decoded norm indices */ + const short flag_HQ2 /* i : indicator of HQ2 core */ + ,const short is_transient +); + +void dequantize_norms( /* o : Number of bits */ + Decoder_State *st, /* i/o: decoder state structure */ + const short start_norm, /* i : First SDE encoded norm */ + const short num_sfm, /* i : Number of norms */ + const short is_transient, /* i : Transient flag */ + short *ynrm, /* o : Decoded norm indices */ + short *normqlg2 /* o : Log2 of decoded norms */ +); + +void hq_configure( + const short length, /* i : Frame length */ + const short hqswb_clas, /* i : HQ SWB class */ + const long brate, /* i : Codec bitrate */ + short *num_sfm, /* o : Total number of subbands */ + short *nb_sfm, /* o : Total number of coded bands */ + short *start_norm, /* o : First norm to be SDE encoded */ + short *num_sde_norm, /* o : Number of norms for SDE encoding */ + short *numnrmibits, /* o : Number of bits in fall-back norm encoding */ + short *hq_generic_offset, /* o : Freq offset for HQ GENERIC */ + short const **sfmsize, /* o : Subband bandwidths */ + short const **sfm_start, /* o : Subband start coefficients */ + short const **sfm_end /* o : Subband end coefficients */ +); + +short hvq_enc( /* o : Consumed bits */ + Encoder_State *st, /* i/o: encoder state structure */ + const long brate, /* i : Total bit rate */ + const short hvq_bits, /* i : HVQ bit budget */ + const short Npeaks, /* i : Number of peaks */ + const short *ynrm, /* i : Envelope coefficients */ + short *R, /* i/o: Bit allocation/updated bit allocation */ + short *peaks, /* i : Peak pos. / Encoded peak pos. */ + float *nf_gains, /* i/o: Noise fill gains / Quant. nf gains */ + float *noise_level, /* o : Quantized noise level */ + const float *pe_gains, /* i : Peak gains */ + const float *coefs, /* i : spectrum coefficients */ + float *coefs_out /* o : encoded spectrum coefficients */ +); + +short hq_classifier_enc( /* o : Consumed bits */ + Encoder_State *st, /* i/o: encoder state structure */ + const short length, /* i : Frame length */ + const float *coefs, /* i : Spectral coefficients */ + const short is_transient, /* i : Transient flag */ + short *Npeaks, /* o : Number of identified peaks */ + short *peaks, /* o : Peak indices */ + float *pe_gains, /* o : Peak gains */ + float *nf_gains, /* o : Noise-fill gains */ + short *hqswb_clas /* o : HQ class */ +); + +short hq_classifier_dec( /* o : Consumed bits */ + Decoder_State *st, /* i/o: decoder state structure */ + const long core_brate, /* i : Core bit rate */ + const short length, /* i : Frame length */ + short *is_transient, /* o : Transient flag */ + short *hqswb_clas /* o : HQ class */ +); + + +void hq_bit_allocation( + const long core_brate, /* i : Core bit-rate */ + const short length, /* i : Frame length */ + const short hqswb_clas, /* i : HQ class */ + short *num_bits, /* i/o: Remaining bit budget */ + const short *normqlg2, /* i : Quantized norms */ + const short nb_sfm, /* i : Number sub bands to be encoded */ + const short *sfmsize, /* i : Sub band bandwidths */ + float *noise_level, /* o : HVQ noise level */ + short *R, /* o : Bit allocation per sub band */ + short *Rsubband, /* o : Fractional bit allocation (Q3) */ + short *sum, /* o : Sum of allocated shape bits */ + short *core_sfm, /* o : Last coded band in core */ + const short num_env_bands +); + +void enforce_zero_for_min_envelope( + const short hqswb_clas, /* i : HQ coding mode */ + const short *ynrm, /* i : Envelope indices */ + float *coefsq, /* i/o: Quantized spectrum/zeroed spectrum */ + short nb_sfm, /* i : Number of coded sub bands */ + const short *sfm_start, /* i : Sub band start indices */ + const short *sfm_end /* i : Sub band end indices */ +); + +short assign_gain_bits( /* o : Number of assigned gain bits */ + const short core, /* i : HQ core */ + const short BANDS, /* i : Number of bands */ + const short *band_width, /* i : Sub band bandwidth */ + short *Rk, /* i/o: Bit allocation/Adjusted bit alloc. (Q3)*/ + short *gain_bits_array, /* o : Assigned gain bits */ + short *Rcalc /* o : Bit budget for shape quantizer (Q3)*/ +); + +void apply_envelope( + const float *coeff, /* i/o: Coded/noisefilled normalized spectrum */ + const short *norm, /* i : Envelope */ + const float *norm_adj, /* i : Envelope adjustment */ + const short num_sfm, /* i : Total number of bands */ + const short last_sfm, /* i : Last coded band */ + const short HQ_mode, /* i : HQ mode */ + const short length, /* i : Frame length */ + const short *sfm_start, /* i : Sub band start indices */ + const short *sfm_end, /* i : Sub band end indices */ + float *normq_v, /* o : Envelope with adjustment */ + float *coeff_out, /* o : coded/noisefilled spectrum */ + float *coeff_out1 /* o : noisefilled spectrum for HQ SWB BWE */ +); + +PvqEntry mpvq_encode_vec( /* o : Leading_sign_index, index, size, k_val */ + const short* vec_in, /* i : Signed pulse train */ + short dim_in, /* i : Dimension */ + short k_val_local /* i : Num unit pulses */ +); + +PvqEntry get_size_mpvq_calc_offset( /* o : Size, dim, k_val */ + short dim_in, /* i : Dimension */ + short k_val_in, /* i : Num unit pulses */ + unsigned int* h_mem /* o : Offsets */ +); + +void mpvq_decode_vec( + const PvqEntry* entry, /* i : Sign_ind, index, dim, k_val */ + unsigned int* h_mem, /* i : A/U offsets */ + short* vec_out /* o : Pulse train */ +); + +unsigned int UMult_32_32( + unsigned int UL_var1, + unsigned int UL_var2 +); + +unsigned int UL_inverse( + const unsigned int UL_val, + short *exp +); + +Word16 ratio( + const Word32 numer, + const Word32 denom, + Word16 *expo +); + +Word16 atan2_fx( /* o: Angle between 0 and EVS_PI/2 radian (Q14) */ + const Word32 y, /* i: Argument must be positive (Q15) */ + const Word32 x /* i: Q15 */ +); + +void encode_energies( + Encoder_State *st, + const float *coefs, + short Np, + short *dim_part, + float *E_part, + short *bits_part, + short *g_part, + short qband, + short *bits_left, + float enr, + short n, + const short strict_bits +); + +void decode_energies( + Decoder_State *st, + short Np, + short *dim_part, + short *bits_part, + short *g_part, + short qband, + short *bits_left, + short n, + const short strict_bits +); + +void pvq_encode_frame( + Encoder_State *st, + const float *coefs_norm, /* i : normalized coefficients to encode */ + float *coefs_quant, /* o : quantized coefficients */ + float *gopt, /* o : optimal shape gains */ + short *npulses, /* o : number of pulses per band */ + short *pulse_vector, /* o : non-normalized pulse shapes */ + const short *sfm_start, /* i : indices of first coefficients in the bands */ + const short *sfm_end, /* i : indices of last coefficients in the bands */ + const short *sfmsize, /* i : band sizes */ + const short nb_sfm, /* i : total number of bands */ + const short *R, /* i : bitallocation per band (Q3)*/ + const short pvq_bits, /* i : number of bits avaiable */ + const short core /* i : core */ +); + +void pvq_decode_frame( + Decoder_State *st, + float *coefs_quant, /* o : quantized coefficients */ + short *npulses, /* o : number of pulses per band */ + short *pulse_vector, /* o : non-normalized pulse shapes */ + const short *sfm_start, /* i : indices of first coefficients in the bands */ + const short *sfm_end, /* i : indices of last coefficients in the bands */ + const short *sfmsize, /* i : band sizes */ + const short nb_sfm, /* i : total number of bands */ + const short *R, /* i : bitallocation per band (Q3) */ + const short pvq_bits, /* i : number of bits avaiable */ + const short core /* i : core */ +); + + + +void srt_vec_ind ( + const short *linear, /* linear input */ + short *srt, /* sorted output*/ + short *I, /* index for sorted output */ + short length +); +void srt_vec_ind_f( + const float *linear, /* linear input */ + float *srt, /* sorted output*/ + short *I, /* index for sorted output */ + short length /* length of vector */ +); + + +unsigned int floor_sqrt_exact( + unsigned int input +); + + + + +void fine_gain_quant( + Encoder_State *st, + const short *ord, /* i : Indices for energy order */ + const short num_sfm, /* i : Number of bands */ + const short *gain_bits, /* i : Gain adjustment bits per sub band */ + float *fg_pred, /* i/o: Predicted gains / Corrected gains */ + const float *gopt /* i : Optimal gains */ +); + +void apply_gain( + const short *ord, /* i : Indices for energy order */ + const short *band_start, /* i : Sub band start indices */ + const short *band_end, /* i : Sub band end indices */ + const short num_sfm, /* i : Number of bands */ + const float *gains, /* i : Band gain vector */ + float *xq /* i/o: Float synthesis / Gain adjusted synth */ +); + +void fine_gain_pred( + const short *sfm_start, /* i : Sub band start indices */ + const short *sfm_end, /* i : Sub band end indices */ + const short *sfm_size, /* i : Sub band bandwidths */ + const short *i_sort, /* i : Energy sorting indices */ + const short *K, /* i : Number of pulses per band */ + const short *maxpulse, /* i : Maximum pulse per band */ + const short *R, /* i : Bits per sub band (Q3) */ + const short num_sfm, /* i : Number of sub bands */ + float *xq, /* i/o: Quantized vector /quantized vector with finegain adj */ + short *y, /* i/o: Quantized vector (int) */ + float *fg_pred, /* o : Predicted fine gains */ + const short core /* i : Core */ +); + +void fine_gain_dec( + Decoder_State *st, + const short *ord, /* i : Indices for energy order */ + const short num_sfm, /* i : Number of bands */ + const short *gain_bits, /* i : Gain adjustment bits per sub band */ + float *fg_pred /* i/o: Predicted gains / Corrected gains */ +); + +void get_max_pulses( + const short *band_start, /* i : Sub band start indices */ + const short *band_end, /* i : Sub band end indices */ + const short *k_sort, /* i : Indices for sorting by energy */ + const short *npulses, /* i : Pulses per sub band */ + const short BANDS, /* i : Number of bands */ + short *inp_vector, /* i/o: Encoded shape vectors (int)*/ + short *maxpulse /* o : Maximum pulse height per band */ +); + +Word32 ar_div( + Word32 num, + Word32 denum +); + +void ar_encoder_start( + PARCODEC arInst, + PBITSTREAM bsInst, + int max_bits +); + +void ar_decoder_start( + PARCODEC arInst, + PBITSTREAM bsInst +); + +void ar_encoder_done( + PARCODEC arInst +); + +void ar_decoder_done( + PARCODEC arInst +); + +float GetISCScale( + float *quants, + int size, + Word32 bits_fx, + float *magn, + float *qscale, + Word32 *surplus_fx, + float *pulses, + int* savedstates, + int noTCQ, + int *nzpout, + short *bcount, + float *abuffer, + float *mbuffer, + float *sbuffer +); + +Word32 Mult_32_16( + Word32 a, + Word16 b +); + +Word32 Mult_32_32( + Word32 a, + Word32 b +); + +void decode_position_ari_fx( + PARCODEC pardec, + Word16 size, + Word16 npulses, + Word16 *nz, + Word32 *position +); + +void decode_magnitude_usq_fx( + ARCODEC *pardec, + Word16 size, + Word16 npulses, + Word16 nzpos, + Word32 *positions, + Word32 *out +); + +void decode_mangitude_tcq_fx( + ARCODEC *pardec, + Word16 size, + Word16 npulses, + Word16 nzpos, + Word32 *positions, + Word32 *out, + Word32 *surplus_fx +); + +void decode_signs_fx( + ARCODEC *pardec, + Word16 size, + Word32 *out +); + +void srt_vec_ind_fx( + const Word32 *linear, + Word32 *srt, + Word16 *I, + Word16 length +); + +Word16 GetScale_fx( + Word16 blen, + Word32 bits_fx/*Q16*/, + Word32 *surplus_fx/*Q16*/ +); + +void bit_allocation_second_fx( + Word32 *Rk, + Word32 *Rk_sort, + Word16 BANDS, + const Word16 *band_width, + Word16 *k_sort, + Word16 *k_num, + const Word16 *p2a_flags, + const Word16 p2a_bands, + const Word16 *last_bitalloc, + const Word16 input_frame +); + +Word32 encode_position_ari_fx( + PARCODEC parenc, + float *quants, + Word16 size, + Word32 *est_bits_frame_fx +); + +Word32 encode_magnitude_tcq_fx( + ARCODEC *parenc, + float *magn_fx, + Word16 size, + Word16 npulses, + Word16 nzpos, + Word32 *savedstates, + Word32 *est_frame_bits_fx +); + +Word32 encode_signs_fx( + ARCODEC *parenc, + float *magn, + Word16 size, + Word16 npos, + Word32 *est_frame_bits_fx +); + +Word32 encode_magnitude_usq_fx( + ARCODEC *parenc, + float *magn_fx, + Word16 size, + Word16 npulses, + Word16 nzpos, + Word32 *est_frame_bits_fx +); + +void tcq_core_LR_enc( + Encoder_State *st, + int inp_vector[], + const float coefs_norm[], + float coefs_quant[], + const short bit_budget, /* number of bits */ + const short nb_sfm, + const short *sfm_start, + const short *sfm_end, + const short *sfmsize, + Word32 *Rk_fx, + int *npulses, + short *k_sort, + const short *p2a_flags, + const short p2a_bands, + const short *last_bitalloc, + const short input_frame, + const short adjustFlag, + const short is_transient +); + +void tcq_core_LR_dec( + Decoder_State *st, + int *inp_vector, + const short bit_budget, + const short bands, + const short *band_start, + const short *band_width, + Word32 *Rk_fx, + int *npulses, + short *k_sort, + const short *p2a_flags, + const short p2a_bands, + const short *last_bitalloc, + const short input_frame, + const short adjustFlag, + const short *is_transient +); + +void InitLSBTCQ( + short *bcount +); + +void TCQLSB( + short bcount, + float *abuffer, + float *mbuffer, + float *sbuffer, + short *dpath +); + +void RestoreTCQ( + float * magn, + int size, + short *bcount, + float *mbuffer +); + +void SaveTCQdata( + PARCODEC arInst, + short *dpath, + short bcount +); + +void LoadTCQdata( + PARCODEC arInst, + short *dpath, + short bcount +); + +void RestoreTCQdec( + int * magn, + int size, + short *bcount, + float *mbuffer +); + +void TCQLSBdec( + short *dpath, + float *mbuffer, + short bcount +); + +void bit_allocation_second_fx( + Word32 *Rk, + Word32 *Rk_sort, + Word16 BANDS, + const Word16 *band_width, + Word16 *k_sort, + Word16 *k_num, + const Word16 *p2a_flags, + const Word16 p2a_bands, + const Word16 *last_bitalloc, + const Word16 input_frame +); + +void io_ini_enc( + const int argc, /* i : command line arguments number */ + char *argv[], /* i : command line arguments */ + FILE **f_input, /* o : input signal file */ + FILE **f_stream, /* o : output bitstream file */ + FILE **f_rate, /* o : bitrate switching profile (0 if N/A) */ + FILE **f_bwidth, /* o : bandwidth switching profile (0 if N/A) */ + FILE **f_rf, /* o : channel aware configuration file */ + short *quietMode, /* o : limit printouts */ + short *noDelayCmp, /* o : turn off delay compensation */ + Encoder_State *st /* o : state structure */ +); + +void read_next_rfparam( + short *rf_fec_offset, /* o: rf offset */ + short *rf_fec_indicator, /* o: rf FEC indicator */ + FILE *f_rf /* i: file pointer to read parameters */ +); + +void read_next_brate( + long *total_brate, /* i/o: total bitrate */ + const int last_total_brate, /* i : last total bitrate */ + FILE *f_rate, /* i : bitrate switching profile (0 if N/A) */ + int input_Fs, /* i : input sampling frequency */ + short *Opt_AMR_WB, /* i : flag indicating AMR-WB IO mode */ + short *Opt_SC_VBR, /* i/o: SC-VBR flag */ + short *codec_mode /* i/o: Mode 1 or 2 */ +); + +void read_next_bwidth( + short *max_bwidth, /* i/o: maximum encoded bandwidth */ + FILE *f_bwidth, /* i : bandwidth switching profile (0 if N/A) */ + long *bwidth_profile_cnt, /* i/o: counter of frames for bandwidth switching profile file */ + int input_Fs /* i : input sampling rate */ +); + + +void init_encoder( + Encoder_State *st /* i/o: state structure */ +); + +void destroy_encoder( + Encoder_State *st /* i/o: state structure */ +); + +void evs_enc( + Encoder_State *st, /* i/o: state structure */ + const short *data, /* i : input signal */ + const short n_samples /* i : number of input samples */ +); + +void amr_wb_enc( + Encoder_State *st, /* i/o: encoder state structure */ + const short *data, /* i : input signal */ + const short n_samples /* i : number of input samples */ +); + +void pre_proc( + Encoder_State *st, /* i/o: encoder state structure */ + const short input_frame, /* i : frame length */ + const float signal_in[], /* i : new samples */ + float old_inp_12k8[], /* i/o: buffer of old input signal */ + float old_inp_16k[], /* i/o: buffer of old input signal @ 16kHz */ + float **inp, /* o : ptr. to inp. signal in the current frame */ + short *sp_aud_decision1, /* o : 1st stage speech/music classification */ + short *sp_aud_decision2, /* o : 2nd stage speech/music classification */ + float fr_bands[2*NB_BANDS], /* o : energy in frequency bands */ + short *vad_flag, + short *localVAD, + float *Etot, /* o : total energy, correlation shift */ + float *ener, /* o : residual energy from Levinson-Durbin */ + short pitch[3], /* o : open-loop pitch values for quantiz. */ + float voicing[3], /* o : OL maximum normalized correlation */ + float A[NB_SUBFR16k*(M+1)], /* o : A(z) unquantized for the 4 subframes */ + float Aw[NB_SUBFR16k*(M+1)], /* o : weighted A(z) unquantized for subframes */ + float epsP[M+1], /* o : LP prediction errors */ + float lsp_new[M], /* o : LSPs at the end of the frame */ + float lsp_mid[M], /* o : LSPs in the middle of the frame */ + short *coder_type, /* o : coder type */ + short *sharpFlag, /* o : formant sharpening flag */ + short *vad_hover_flag, + short *attack_flag, /* o : flag signalling attack encoded by AC mode (GSC) */ + float *new_inp_resamp16k, /* o : new input signal @16kHz, non pre-emphasised, used by the WB TBE/BWE */ + short *Voicing_flag, /* o : voicing flag for HQ FEC */ + float realBuffer[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX], /* i/o : real buffer */ + float imagBuffer[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX], /* i/o : imag buffer */ + short *hq_core_type /* o : HQ core type */ +); + +short mdct_classifier( /* o: Class decision, 0 = Mode 1, 1 = Mode 2 */ + const float *Y, /* i: FFT spectrum from fft_rel */ + Encoder_State *st, /* i/o: Encoder state variable */ + short vadflag + ,float *cldfbBuf_Ener +); + +void MDCT_selector( + Encoder_State *st, /* i/o: Encoder State */ + float sp_floor, /* i : Noise floor estimate */ + float Etot, /* i : Total energy */ + float cor_map_sum, /* i : harmonicity factor */ + const float voicing[], /* i : voicing factors */ + const float enerBuffer[], /* i : CLDFB buffers */ + short vadflag +); + +void MDCT_selector_reset( + Encoder_State *st /* i/o: Encoder State */ +); + +void acelp_core_enc( + Encoder_State *st, /* i/o: encoder state structure */ + LPD_state *mem, /* i/o: acelp memories */ + const float inp[], /* i : input signal of the current frame */ + const short vad_flag, + const float ener, /* i : residual energy from Levinson-Durbin*/ + const short pitch[3], /* i : open-loop pitch values for quantiz. */ + const float voicing[3], /* i : Open-loop pitch gains */ + float A[NB_SUBFR16k*(M+1)], /* i : A(z) unquantized for the 4 subframes*/ + float Aw[NB_SUBFR16k*(M+1)], /* i : weighted A(z) unquant. for subframes*/ + const float epsP[M+1], /* i : LP prediction errors */ + float lsp_new[M], /* i : LSPs at the end of the frame */ + float lsp_mid[M], /* i : LSPs in the middle of the frame */ + short coder_type, /* i : coding type */ + const short sharpFlag, /* i : formant sharpening flag */ + short vad_hover_flag, + const short attack_flag, /* i : flag signalling attack encoded by AC mode (GSC) */ + float bwe_exc_extended[], /* i/o: bandwidth extended excitation */ + float *voice_factors, /* o : voicing factors */ + float old_syn_12k8_16k[], /* o : ACELP core synthesis at 12.8kHz or 16kHz to be used by SWB BWE */ + float pitch_buf[NB_SUBFR16k], /* o : floating pitch for each subframe */ + short *unbits /* o : number of unused bits */ +); + +void acelp_core_switch_dec_bfi( + Decoder_State *st, /* i/o: decoder state structure */ + float synth_out[], /* o : synthesis */ + const short coder_type /* i : coder type */ +); + +void acelp_core_switch_enc( + Encoder_State *st, /* i/o: encoder state structure */ + LPD_state *mem, /* i/o: encoder memories */ + const float inp12k8[], /* i : input signal @12.8 kHz */ + const float inp16k[], /* i : input signal @16 kHz */ + const short T_op[2], /* i : open-loop pitch values for quantiz. */ + const float voicing[3], /* i : Open-loop pitch gains */ + const float A[NB_SUBFR16k*(M+1)] /* i : A(z) unquantized for the 4 subframes */ +); + +short modify_Fs_intcub3m_sup( /* o : length of output */ + const float sigIn[], /* i : signal to decimate with memory of 2 samples (indexes -2 & -1) */ + const short lg, /* i : length of input */ + const int fin, /* i : frequency of input */ + float sigOut[], /* o : decimated signal */ + const int fout, /* i : frequency of output */ + short *delayout /* o : delay of output */ +); + +void core_switching_OLA( + const float *mem_over_hp, /* i : upsampling filter memory */ + const short last_L_frame, /* i : last L_frame lengthture */ + const int output_Fs, /* i : output sampling rate */ + float *synth, /* i/o: synthesized signal from HQ core */ + const float *synth_subfr_out, /* i : synthesized signal from ACELP core */ + float *synth_subfr_bwe, /* i : synthesized BWE from ACELP core */ + const short output_frame, /* i : output frame length */ + const short bwidth /* i : output bandwidth */ +); + +void retro_interp4_5( + const float *syn, + float *pst_old_syn +); + +void retro_interp5_4( + float *pst_old_syn +); + +void core_switching_hq_prepare_enc( + Encoder_State *st, /* i/o: encoder state structure */ + short *num_bits, /* i/o: bit budget update */ + const short input_frame, /* i : input frame length */ + float *wtda_audio, + const float *audio +); + +void core_switching_hq_prepare_dec( + Decoder_State *st, /* i/o: encoder state structure */ + short *num_bits, /* i/o: bit budget update */ + const short input_frame /* i : input frame length */ +); + +void acelp_core_switch_dec( + Decoder_State *st, /* i/o: decoder structure */ + float *synth_subfr_out, /* o : synthesized ACELP subframe */ + float *tmp_synth_bwe, /* o : synthesized ACELP subframe BWE */ + const short output_frame, /* i : input frame length */ + const short core_switching_flag, /* i : core switching flag */ + float *mem_synth /* o : synthesis to overlap */ +); + +void space_lsfs( + float *lsfs, + const short order +); + +void lsp2a( + float *pc_in, + float *freq, + const short order +); + +void lsp_weights( + const float *lsps, + float *weight, + const short order +); + +void a2lsp_stab( + const float *a, /* i: LP filter coefficients */ + float *lsp, /* o: Line spectral pairs */ + const float *old_lsp /* i: LSP vector from past frame */ +); + +void lsp2a_stab( + const float *lsp, /* i : LSF vector (in the cosine domain) */ + float *a, /* o : LP filter coefficients */ + const short m /* i : order of LP analysis */ +); + +void isf2lsf( + const float *isf, /* i : ISF vector */ + float *lsf, /* o : LSF vector */ + float *stable_lsp, /* i/o: LSF vector */ + const short m, /* i : order of LP analysis */ + const float int_fs +); + +void lsf2isf( + const float *lsf, /* i : LSF vector */ + float *isf, /* o : ISF vector */ + float *stable_isp, /* i/o: ISP vector */ + const short m, /* i : order of LP analysis */ + const float int_fs +); + +short a2lsp( + float *freq, /* o : LSP vector */ + const float *a, /* i : predictor coefficients */ + const short order /* i : order of LP analysis */ +); + +void ResetSHBbuffer_Enc( + Encoder_State *st /* i/o: encoder state structure */ +); + +void ResetSHBbuffer_Dec( + Decoder_State *st /* i/o: decoder state structure */ +); + +void calc_st_filt( + const float *apond2, /* i : coefficients of numerator */ + const float *apond1, /* i : coefficients of denominator */ + float *parcor0, /* o : 1st parcor calcul. on composed filter */ + float *sig_ltp_ptr, /* i/o: input of 1/A(gamma1) : scaled by 1/g0 */ + float *mem_zero, /* i/o: All zero memory */ + const short L_subfr, /* i : the length of subframe */ + const short extl /* i : extension layer info */ +); + +void scale_st( + const float *sig_in, /* i : postfilter input signal */ + float *sig_out, /* i/o: postfilter output signal */ + float *gain_prec, /* i/o: last value of gain for subframe */ + const short L_subfr, /* i : the length of subframe */ + const short extl /* i : extension layer info */ +); + +void filt_mu( + const float *sig_in, /* i : signal (beginning at sample -1) */ + float *sig_out, /* o : output signal */ + const float parcor0, /* i : parcor0 (mu = parcor0 * gamma3) */ + const short L_subfr, /* i : the length of subframe */ + const short extl /* i : extension layer info */ +); + +void PostShortTerm( + float *sig_in, /* i : input signal (ptr. to current subframe */ + float *lpccoeff, /* i : LPC coefficients for current subframe */ + float *sig_out, /* o : postfiltered output */ + float *mem_stp, /* i/o: postfilter memory */ + float *ptr_mem_stp, /* i/o: pointer to postfilter memory */ + float *ptr_gain_prec, /* i/o: for gain adjustment */ + float *mem_zero, /* i/o: null memory to compute h_st */ + const float formant_fac /* i : Strength of post-filter [0,1] */ +); + +float swb_formant_fac( /* o : Formant filter strength [0,1] */ + const float lpc_shb2, /* i : 2nd HB LPC coefficient */ + float *tilt_mem /* i/o: Tilt smoothing memory */ +); + +void GenShapedSHBExcitation( + float *excSHB, /* o : synthesized shaped shb exctiation */ + const float *lpc_shb, /* i : lpc coefficients */ + float *exc16kWhtnd, /* o : whitened synthesized shb excitation */ + float *mem_csfilt, /* i/o: memory */ + float *mem_genSHBexc_filt_down_shb,/* i/o: memory */ + float *state_lpc_syn, /* i/o: memory */ + const short coder_type, /* i : coding type */ + const float *bwe_exc_extended, /* i : bandwidth extended excitation */ + short bwe_seed[], /* i/o: random number generator seed */ + float voice_factors[], /* i : voicing factor */ + const short extl, /* i : extension layer */ + float *tbe_demph, /* i/o: de-emphasis memory */ + float *tbe_premph, /* i/o: pre-emphasis memory */ + float *lpc_shb_sf, /* i : LP coefficients */ + float *shb_ener_sf, /* i : SHB subframe energies */ + float *shb_res_gshape, /* i : SHB LP residual gain shape */ + float *shb_res, /* i : SHB residual used in encoder only */ + short *vf_ind, /* i/o: Mixing factor index */ + const float formant_fac, /* i : Formant sharpening factor [0..1] */ + float fb_state_lpc_syn[], /* i/o: memory */ + float *fb_tbe_demph, /* i/o: fb de-emphasis memory */ + const long bitrate, /* i : overall bitrate */ + const short prev_bfi /* i : previous frame was lost flag */ +); + +void GenSHBSynth( + const float *shb_target_speech, /* i : input synthesized speech */ + float *shb_syn_speech_32k, /* o : output highband component */ + float Hilbert_Mem[], /* i/o: memory */ + float state_lsyn_filt_shb_local[],/* i/o: memory */ + const short L_frame, /* i : ACELP Frame length */ + short *syn_dm_phase +); + +void ScaleShapedSHB( + const short length, /* i : SHB overlap length */ + float *synSHB, /* i/o: synthesized shb signal */ + float *overlap, /* i/o: buffer for overlap-add */ + const float *subgain, /* i : subframe gain */ + const float frame_gain, /* i : frame gain */ + const float *win, /* i : window */ + const float *subwin /* i : subframes window */ +); + +void Interpolate_allpass_steep ( + const float *in, /* i : input array of size N */ + float *state, /* i/o: memory */ + const short N, /* i : number of input samples */ + float *out /* o : output array of size 2*N */ +); + +void Decimate_allpass_steep ( + const float *in, /* i : input array of size N */ + float *state, /* i/o: memory */ + const short N, /* i : number of input samples */ + float *out /* o : output array of size N/2 */ +); + +void interpolate_3_over_2_allpass( + const float *input, /* i : input signal */ + const short len, /* i : number of input samples */ + float *out, /* o : output signal */ + float *mem, /* i/o: memory */ + const float *filt_coeff /* i : filter coefficients */ +); + +void decimate_2_over_3_allpass( + const float *input, /* i : input signal */ + const short len, /* i : number of input samples */ + float *out, /* o : output signal */ + float *mem, /* i/o: memory */ + const float *filt_coeff, /* i : filter coefficients */ + const float *lp_num, + const float *lp_den, + float *lp_mem +); + +void interpolate_3_over_1_allpass( + const float *input, /* i : input signal */ + const short len, /* i : number of input samples */ + float *out, /* o : output signal */ + float *mem, /* i/o: memory */ + const float *filt_coeff /* i : filter coefficients */ +); + +void InitSWBencBuffer( + Encoder_State *st /* i/o: encoder state structure */ +); + +void swb_tbe_enc( + Encoder_State *st, /* i/o: encoder state structure */ + const short coder_type, /* i : coding type */ + float *new_speech, /* i : original input signal */ + const float *bwe_exc_extended, /* i : bandwidth extended exciatation */ + const float voice_factors[], /* i : voicing factors */ + float *White_exc16k, /* o : shaped white excitation for the FB TBE */ + const float voicing[], /* i : OL maximum normalized correlation */ + const float pitch_buf[] /* i : pitch for each subframe */ +); + +void InitSWBdecBuffer( + Decoder_State *swb_dnc /* i/o: SHB decoder structure */ +); + +void swb_tbe_dec( + Decoder_State *st, /* i/o: decoder state structure */ + const short coder_type, /* i : coding type */ + const float *bwe_exc_extended, /* i : bandwidth extended exciatation */ + const float voice_factors[], /* i : voicing factors */ + const float old_syn_12k8_16k[], + float *White_exc16k, /* o : shaped white excitation for the FB TBE */ + float *synth, /* i/o: ACELP core synthesis/final synthesis */ + float *pitch_buf +); + +void flip_and_downmix_generic( + float input[], /* i : input spectrum */ + float output[], /* o : output spectrum */ + const short length, /* i : length of spectra */ + float mem1_ext[HILBERT_ORDER1], /* i/o: Hilbert filter memory */ + float mem2_ext[2*HILBERT_ORDER2], /* i/o: memory */ + float mem3_ext[2*HILBERT_ORDER2], /* i/o: memory */ + short *phase_state /* i/o: Phase state in case frequency isn't multiple of 50 Hz */ +); + +void non_linearity( + const float input[], /* i : input signal */ + float output[], /* i : output signal */ + float old_bwe_exc_extended[], /* i/o: memory bugffer */ + const short length, /* i : input length */ + float *prev_scale /* i/o: memory */ + ,short coder_type, /* i : Coder Type */ + float *voice_factors, /* i : Voice Factors */ + const short L_frame /* i : ACELP frame length */ +); + +void interp_code_5over2( + const float inp_code[], /* i : input vector */ + float interp_code[], /* o : output vector */ + const short inp_length /* i : length of the input vector */ +); + +void interp_code_4over2( + const float inp_code[], /* i : input vector */ + float interp_code[], /* o : output vector */ + const short inp_length /* i : length of the input vector */ +); + +void flip_spectrum_and_decimby4( + const float input[], /* i : input spectrum */ + float output[], /* o : output spectrum */ + const short length, /* i : vector length */ + float mem1[], /* i/o: memory */ + float mem2[], /* i/o: memory */ + const short ramp_flag /* i : flag to trigger slow ramp-up of output */ +); + +void GenShapedWBExcitation( + float *excSHB, /* o : synthesized shaped shb exctiation */ + const float *lpc_shb, /* i : lpc coefficients */ + float *exc4kWhtnd, /* o : whitened synthesized shb excitation */ + float *mem_csfilt, /* i/o : memory */ + float *mem_genSHBexc_filt_down1, /* i/o : memory */ + float *mem_genSHBexc_filt_down2, /* i/o : memory */ + float *mem_genSHBexc_filt_down3, /* i/o : memory */ + float *state_lpc_syn, /* i/o : memory */ + const short coder_type, /* i : coding type */ + const float *bwe_exc_extended, /* i : bandwidth extended exciatation */ + short bwe_seed[], /* i/o : random number generator seed */ + const float voice_factors[], /* i : voicing factor */ + const short uv_flag, /* i : unvoiced flag */ + const short igf_flag +); + +void GenWBSynth( + const float *input_synspeech, /* i : input synthesized speech */ + float *shb_syn_speech_16k, /* o : output highband compnent */ + float *state_lsyn_filt_shb1, /* i/o: memory */ + float *state_lsyn_filt_shb2 /* i/o: memory */ +); + +void wb_tbe_enc( + Encoder_State *st, /* i/o: encoder state structure */ + const short coder_type, /* i : coding type */ + const float *hb_speech, /* i : HB target signal (6-8kHz) at 16kHz */ + const float *bwe_exc_extended, /* i : bandwidth extended exciatation */ + const float voice_factors[], /* i : voicing factors */ + const float pitch_buf[], /* i : pitch for each subframe */ + const float voicing[] /* o : OL maximum normalized correlation */ +); + +void wb_tbe_dec( + Decoder_State *st, /* i/o: decoder state structure */ + const short coder_type, /* i : coding type */ + const float *bwe_exc_extended, /* i : bandwidth extended exciatation */ + const float voice_factors[], /* i : voicing factors */ + float *synth /* i/o: ACELP core synthesis/final synthesis */ +); + +void tbe_write_bitstream( + Encoder_State *st /* i/o: encoder state structure */ +); + +void tbe_read_bitstream( + Decoder_State *st /* i/o: decoder state structure */ +); + +void GenTransition( + const float *input, /* i : gain shape overlap buffer */ + const float *old_hb_synth, /* i : synthesized HB from previous frame */ + short length, /* i : targeted length of transition signal */ + float *output, /* o : synthesized transitions signal */ + float Hilbert_Mem[], /* i/o: memory */ + float state_lsyn_filt_shb_local[],/* i/o: memory */ + short *syn_dm_phase, + int output_Fs, + float *up_mem, + int rf_flag + , int bitrate +); + +void GenTransition_WB( + const float *input, /* i : gain shape overlap buffer */ + const float *old_hb_synth, /* i : synthesized HB from previous frame */ + short length, /* i : targeted length of transition signal */ + float *output, /* o : synthesized transitions signal */ + float state_lsyn_filt_shb1[], + float state_lsyn_filt_shb2[], + int output_Fs, + float *up_mem +); + +void TBEreset_enc( + Encoder_State *st, /* i/o: encoder state structure */ + short bandwidth /* i : bandwidth mode */ +); + +void TBEreset_dec( + Decoder_State *st, /* i/o: decoder state structure */ + short bandwidth /* i : bandwidth mode */ +); + +short get_tbe_bits( /* o : TBE bit consumption per frame */ + short bitrate, /* i : overall bitrate */ + short bandwidth, /* i : bandwidht mode */ + short rf_mode /* i : channel aware mode */ +); + +void fb_tbe_enc( + Encoder_State *st, /* i/o: encoder state structure */ + const float new_input[], /* i : input speech at 48 kHz sample rate */ + const float fb_exc[] /* i : FB excitation from the SWB part */ +); + +void fb_tbe_dec( + Decoder_State *st, /* i/o: decoder state structure */ + const float fb_exc[], /* i : FB excitation from the SWB part */ + float *hb_synth /* i/o: high-band synthesis */ +); + +void calc_tilt_bwe( + const float *sp, /* i : input signal */ + float *tilt, /* o : signal tilt */ + const short N /* i : signal length */ +); + +void wtda_BWE( + const float *new_audio, /* i : input audio */ + float *old_wtda, /* i/o: windowed audio from previous frame */ + const short L /* i : length */ +); + +void swb_pre_proc( + Encoder_State *st, /* i/o: encoder state structure */ + const float *input, /* i : original input signal */ + float *new_swb_speech, /* o : original input signal at 32kHz */ + float *shb_speech, /* o : SHB target signal (6-14kHz) at 16kHz */ + float realBuffer[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX], /* i : real buffer */ + float imagBuffer[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX] /* i : imag buffer */ +); + +void wb_pre_proc( + Encoder_State *st, /* i/o: encoder state structure */ + const float *new_inp_resamp16k, /* i : original input signal */ + float *hb_speech /* o : HB target signal (6-8kHz) at 16kHz */ +); + +void wb_bwe_enc( + Encoder_State *st, /* i/o: encoder state structure */ + const float *new_wb_speech, /* i : original input signal at 16kHz */ + short coder_type /* i : coding type */ +); + +void wb_bwe_dec( + float *synth, /* i/o: ACELP core synthesis/final synthesis */ + float *hb_synth, /* o : SHB synthesis/final synthesis */ + const short output_frame, /* i : frame length */ + Decoder_State *st, /* i/o: decoder state structure */ + short coder_type, /* i : coding type */ + float *voice_factors, /* i : voicing factors */ + const float pitch_buf[] /* i : pitch buffer */ +); + +void swb_bwe_enc( + Encoder_State *st, /* i/o: encoder state structure */ + const float *old_input_12k8, /* i : input signal @12.8kHz for SWB BWE */ + const float *old_input_16k, /* i : input signal @16kHz for SWB BWE */ + const float *old_syn_12k8_16k, /* i : ACELP core synthesis at 12.8kHz or 16kHz*/ + const float *new_swb_speech, /* i : original input signal at 32kHz */ + const float *shb_speech, /* i : SHB target signal (6-14kHz) at 16kHz */ + const short coder_type /* i : coding type */ +); + +void swb_bwe_enc_hr( + Encoder_State *st, /* i/o: encoder state structure */ + const float *new_input, /* i : input signal */ + const short input_frame, /* i : frame length */ + const short coder_type, /* i : coding type */ + const short unbits /* i : number of core unused bits */ +); + +void swb_bwe_dec( + Decoder_State *st, /* i/o: decoder state structure */ + const float *synth, /* i : ACELP core synthesis/final synthesis */ + float *hb_synth, /* o : SHB synthesis/final synthesis */ + const short output_frame /* i : frame length */ + ,short coder_type /* i : coding type */ +); + +void swb_bwe_dec_hr( + Decoder_State *st, /* i/o: decoder state structure */ + const float *syn_12k8_16k, /* i : ACELP core synthesis @16kHz */ + float *hb_synth, /* o : SHB synthesis */ + const short output_frame, /* i : frame length */ + const short unbits, /* i : number of core unused bits */ + const float pitch_buf[] /* i : pitch buffer */ +); + +void swb_hr_noise_fill( + const short is_transient, /* i : transient flag */ + const short spect_start, /* i : spectrum start point */ + const short spect_end, /* i : spectrum end point */ + const float tilt_wb, /* i : tilt of wideband signal */ + const float pitch, /* i : pitch value */ + const short nq[], /* i : AVQ nq index */ + short Nsv, /* i : number of subband */ + short *bwe_highrate_seed, /* i/o: seed of random noise */ + float *t_audio /* i/o: mdct spectrum */ +); + +float td_postprocess( /* o : gain */ + float hb_synth[], /* i/o: high-band synthesis */ + const short input_frame, /* i : frame length */ + const short last_extl /* i : last extension layer */ +); + +void calc_normal_length( + const short core, /* i : core */ + const float *sp, /* i : input signal */ + const short mode, /* i : input mode */ + const short extl, /* i : extension layer */ + short *L_swb_norm, /* o : normalize length */ + short *prev_L_swb_norm /* i/o: last normalize length */ +); + +void calc_norm_envelop( + const float SWB_signal[], /* i : SWB spectrum */ + float *envelope, /* o : normalized envelope */ + const short L_swb_norm, /* i : length of envelope */ + const short SWB_flength, /* i : Length of input/output */ + const short st_offset /* i : offset */ +); + +void time_envelop_shaping( + float werr[], /* i/o: SHB synthesis */ + float SWB_tenv[], /* i/o: frequency envelope */ + const short L /* i : frame length */ +); + +void time_reduce_pre_echo( + const float *synth, /* i : ACELP core synthesis */ + float *error, /* o : SHB BWE synthesis */ + float prev_td_energy, /* o : last td energy */ + const short L /* i : subframe length */ +); + +short WB_BWE_gain_pred( + float *WB_fenv, /* o : WB frequency envelopes */ + const float *core_dec_freq, /* i : Frequency domain core decoded signal */ + const short coder_type, /* i : coding type */ + short prev_code_type, /* i : coding type of last frame */ + float prev_WB_fenv, /* i : envelope for last frame */ + float *voice_factors, /* i : voicing factors */ + const float pitch_buf[], /* i : pitch buffer */ + long last_core_brate, /* i : previous frame core bitrate */ + float last_wb_bwe_ener /* i : previous frame wb bwe signal energy */ + ,short last_extl /* i : extl. layer for last frame */ + ,float tilt +); + +void WB_BWE_decoding( + const float *core_dec_freq, /* i : Frequency domain core decoded signal */ + float *WB_fenv, /* i : WB frequency envelopes */ + float *WB_signal, /* o : WB signal in MDCT domain */ + const short WB_flength, /* i : Length of input/output */ + const short mode, /* i : classification for WB signal */ + const short last_extl, /* i : extl. layer for last frame */ + float *prev_Energy, /* i/o: energy for last frame */ + float *prev_WB_fenv, /* i/o: envelope for last frame */ + short *prev_L_wb_norm, /* i/o: length for last frame wb norm */ + const short extl, /* i : extension layer */ + const short coder_type, /* i : coding type */ + const long total_brate, /* i : core layer bitrate */ + short *Seed, /* i/o: random generator seed */ + short *prev_flag, /* i/o: attenu flag of last frame */ + short prev_coder_type /* i : coding type of last frame */ +); + +void SWB_BWE_decoding( + const float *core_dec_freq, /* i : Frequency domain core decoded signal */ + float *SWB_fenv, /* i/o: SWB frequency envelopes */ + float *SWB_signal, /* o : SWB signal in MDCT domain */ + const short SWB_flength, /* i : Length of input/output */ + const short mode, /* i : classification for SWB signal */ + short *frica_flag, /* o : fricative signal flag */ + float *prev_Energy, /* i/o: energy for last frame */ + float *prev_SWB_fenv, /* i/o: envelope for last frame */ + short *prev_L_swb_norm, /* i/o: length for last frame wb norm */ + const float tilt_nb, /* i : tilt of synthesis wb signal */ + short *Seed, /* i/o: random generator seed */ + const short st_offset, /* i : offset value due to different core */ + float *prev_weight, /* i/o: excitation weight value of last frame */ + const short extl /* i : extension layer */ + ,const short last_extl /* i : extension layer of last frame */ +); + +void CNG_reset_enc( + Encoder_State *st, /* i/o: encoder state structure */ + LPD_state *mem, /* i/o: encoder memories */ + float *pitch_buf, /* o : floating pitch for each subframe */ + float *voice_factors /* o : voicing factors */ + ,short VBR_cng_reset_flag +); + +void a2isp( + const float *a, /* i : LP filter coefficients */ + float *isp, /* o : Immittance spectral pairs */ + const float *old_isp /* i : ISP vector from past frame */ +); + +void a2isf( + float *a, + float *isf, + const float *old_isf, + short lpcOrder); + +void a2rc ( + const float *a, /* i : LPC coefficients */ + float *refl, /* o : Reflection co-efficients */ + const short lpcorder /* i : LPC order */ +); + +short lp_filt_exc_enc( + const short codec_mode, /* i : codec mode */ + const long core_brate, /* i : core bitrate */ + const short Opt_AMR_WB, /* i : flag indicating AMR-WB IO mode */ + const short coder_type, /* i : coding type */ + const short i_subfr, /* i : subframe index */ + float *exc, /* i/o: pointer to excitation signal frame */ + const float *h1, /* i : weighted filter input response */ + const float *xn, /* i : target vector */ + float *y1, /* o : zero-memory filtered adaptive excitation */ + float *xn2, /* o : target vector for innovation search */ + const short L_subfr, /* i : length of vectors for gain quantization */ + const short L_frame, /* i : frame size */ + float *g_corr, /* o : ACELP correlation values */ + const short clip_gain, /* i : adaptive gain clipping flag */ + float *gain_pit, /* o : adaptive excitation gain */ + short *lp_flag /* i/o : mode selection */ +); + +void updt_tar( + const float *x, /* i : old target (for pitch search) */ + float *x2, /* o : new target (for codebook search) */ + const float *y, /* i : filtered adaptive codebook vector */ + const float gain, /* i : adaptive codebook gain */ + const short L /* i : subframe size */ +); + +void analy_sp( + float *speech, /* i : speech buffer */ + float *Bin_E, /* o : per bin log energy spectrum */ + float *Bin_E_old, /* o : per bin log energy spectrum for mid-frame */ + float *fr_bands, /* o : per band energy spectrum (2 analyses) */ + float lf_E[], /* o : per bin E for first VOIC_BINS bins (without DC) */ + float *Etot, /* o : total input energy */ + const short min_band, /* i : minimum critical band */ + const short max_band, /* i : maximum critical band */ + float *band_ener, /* o: energy in critical frequency bands without minimum noise floor E_MIN */ + float *PS /* o : Per bin energy spectrum */ + ,float *fft_buff /* o : FFT coefficients */ +); + +void CNG_enc( + Encoder_State *st, /* i/o: State structure */ + const short L_frame, /* i : length of the frame */ + float Aq[], /* o : LP coefficients */ + const float *speech, /* i : pointer to current frame input speech buffer */ + float enr, /* i : frame energy output from Levinson recursion */ + float *lsp_new, /* i/o: current frame LSPs */ + float *lsf_new, /* i/o: current frame LSFs */ + short *allow_cn_step, /* o : allow CN step */ + short burst_ho_cnt, /* i : hangover frames at end of speech burst */ + float *q_env, + short *sid_bw, + float *exc_mem2 +); + +void swb_CNG_enc( + Encoder_State *st, /* i/o: State structure */ + const float *shb_speech, /* i : SHB target signal (6-14kHz) at 16kHz */ + const float *syn_12k8_16k /* i : ACELP core synthesis at 12.8kHz or 16kHz */ +); + +void lsf_enc( + Encoder_State *st, /* i/o: state structure */ + const short L_frame, /* i : length of the frame */ + const short coder_type, /* i : coding type */ + float *lsf_new, /* o : quantized LSF vector */ + float *lsp_new, /* i/o: LSP vector to quantize/quantized */ + float *lsp_mid, /* i : mid-frame LSP vector */ + float *Aq, /* o : quantized A(z) for 4 subframes */ + float *stab_fac, /* o : ISF stability factor */ + const short Nb_ACELP_frames +); + +void isf_enc_amr_wb( + Encoder_State *st, /* i/o: state structure */ + float *isf_new, /* o : quantized ISF vector */ + float *isp_new, /* i/o: ISP vector to quantize/quantized */ + float *Aq, /* o : quantized A(z) for 4 subframes */ + float *stab_fac /* o : ISF stability factor */ +); + +void find_targets( + const float *speech, /* i : pointer to the speech frame */ + const float *mem_syn, /* i : memory of the synthesis filter */ + const short i_subfr, /* i : subframe index */ + float *mem_w0, /* i/o: weighting filter denominator memory */ + const float *p_Aq, /* i : interpolated quantized A(z) filter */ + const float *res, /* i : residual signal */ + const short L_subfr, /* i : length of vectors for gain quantization */ + const float *Ap, /* i : unquantized A(z) filter with bandwidth expansion */ + const float tilt_fac, /* i : tilt factor */ + float *xn, /* o : Close-loop Pitch search target vector */ + float *cn, /* o : target vector in residual domain */ + float *h1 /* o : impulse response of weighted synthesis filter */ +); + +void inov_encode( + Encoder_State *st, /* i/o: encoder state structure */ + const long core_brate, /* i : core bitrate */ + const short Opt_AMR_WB, /* i : flag indicating AMR-WB IO mode */ + const short L_frame, /* i : length of the frame */ + const short last_L_frame, /* i : length of the last frame */ + const short coder_type, /* i : coding type */ + const short bwidth, /* i : input signal bandwidth */ + const short sharpFlag, /* i : formant sharpening flag */ + const short i_subfr, /* i : subframe index */ + short const tc_subfr, /* i : TC subframe index */ + const float *p_Aq, /* i : LP filter coefficients */ + const float gain_pit, /* i : adaptive excitation gain */ + float *cn, /* i/o: target vector in residual domain */ + const float *exc, /* i : pointer to excitation signal frame */ + float *h1, /* i/o: weighted filter input response */ + const float tilt_code, /* i : tilt of of the excitation of previous subframe */ + const float pt_pitch, /* i : pointer to current subframe fractional pitch */ + const float *xn2, /* i : target vector for innovation search */ + float *code, /* o : algebraic excitation */ + float *y2, /* o : zero-memory filtered algebraic excitation */ + short *unbits /* o : number of unused bits for EVS_PI */ +); + +void acelp_1t64( + Encoder_State *st, /* i/o: encoder state structure */ + const float dn[], /* i : corr. between target and h[]. */ + const float h[], /* i : impulse response of weighted synthesis filter */ + float code[], /* o : algebraic (fixed) codebook excitation */ + float y[] /* o : filtered fixed codebook excitation */ +); + +void acelp_2t32( + Encoder_State *st, /* i/o: encoder state structure */ + const float dn[], /* i : corr. between target and h[]. */ + const float h[], /* i : impulse response of weighted synthesis filter */ + float code[], /* o : algebraic (fixed) codebook excitation */ + float y[] /* o : filtered fixed codebook excitation */ +); + +short acelp_4t64( + Encoder_State *st, /* i/o: encoder state structure */ + float dn[], /* i : corr. between target and h[]. */ + const float cn[], /* i : residual after long term prediction */ + const float H[], /* i : impulse response of weighted synthesis filter */ + float R[], /* i : autocorrelation values */ + const short acelpautoc, /* i : autocorrealtion flag */ + float code[], /* o : algebraic (fixed) codebook excitation */ + float y[], /* o : filtered fixed codebook excitation */ + short nbbits, /* i : number of bits per codebook */ + const short cmpl_flag, /* i : coomplexity reduction flag */ + const short Opt_AMR_WB /* i : flag indicating AMR-WB IO mode */ +); + +void corr_xh( + const float *x, /* i : target signal */ + float *y, /* o : correlation between x[] and h[] */ + const float *h, /* i : impulse response of weighted synthesis filter */ + const int L_subfr /* i : length of the subframe */ +); + +void find_tilt( + const float fr_bands[], /* i : energy in frequency bands */ + const float bckr[], /* i : per band background noise energy estimate */ + float ee[2], /* o : lf/hf E ration for present frame */ + const short pitch[3], /* i : open loop pitch values for 3 half-frames */ + const float voicing[3], /* i : normalized correlation for 3 half-frames */ + const float *lf_E, /* i : per bin energy for low frequencies */ + const float corr_shift, /* i : normalized correlation correction */ + const short bwidth, /* i : input signal bandwidth */ + const short max_band, /* i : maximum critical band */ + float hp_E[], /* o : energy in HF */ + const short codec_mode, /* i : Mode 1 or 2 */ + float *bckr_tilt_lt, /* i/o: lf/hf E ratio of background noise */ + short Opt_vbr_mode +); + +void init_gp_clip( + float mem[] /* o : memory of gain of pitch clipping algorithm */ +); + +short gp_clip( + const long core_brate, /* i : core bitrate */ + const float *voicing, /* i : normalized correlations (from OL pitch) */ + const short i_subfr, /* i : subframe index */ + const short coder_type, /* i : coding type */ + const float xn[], /* i : target vector */ + float mem[] /* i/o: memory of gain of pitch clipping algorithm */ +); + +void gp_clip_test_lsf( + const long core_brate, /* i : core bitrate */ + const float lsf[], /* i : LSF vector */ + float mem[], /* i/o: memory of gain of pitch clipping algorithm */ + const short Opt_AMR_WB /* i : flag indicating AMR-WB IO mode */ +); + +void gp_clip_test_gain_pit( + const long core_brate, /* i : core bitrate */ + const float gain_pit, /* i : gain of quantized pitch */ + float mem[] /* i/o: memory of gain of pitch clipping algorithm */ +); + +void analy_lp( + const float speech[], /* i : pointer to the denoised speech frame */ + const short L_frame, /* i : length of the frame */ + const short L_look, /* i : look-ahead length */ + float *ener, /* o : residual signal energy */ + float A[], /* o : A(z) filter coefficients */ + float epsP[], /* o : LP analysis residual energies for each iteration */ + float lsp_new[], /* o : current frame ISPs */ + float lsp_mid[], /* o : current mid-frame ISPs */ + float lsp_old[], /* i/o: previous frame unquantized ISPs */ + const short Top[2], /* i : open loop pitch lag */ + const float Tnc[2], /* i : open loop pitch gain */ + const float sr_core /* i : internal sampling rate */ +); + +void analy_lp_AMR_WB( + const float speech[], /* i : pointer to the speech frame */ + float *ener, /* o : residual energy from Levinson-Durbin */ + float A[], /* o : A(z) filter coefficients */ + float epsP[], /* o : LP analysis residual energies for each iteration */ + float isp_new[], /* o : current frame ISPs */ + float isp_old[], /* i/o: previous frame unquantized ISPs */ + float isf_new[], /* o : current frame ISFs */ + const int Top, /* i : open loop pitch lag */ + const float Tnc /* i : open loop pitch gain */ +); + +void noise_est_init( + float *totalNoise, /* o : noise estimate over all critical bands */ + short *first_noise_updt, /* o : noise update initialization flag */ + float bckr[], /* o : per band background noise energy estimate */ + float enrO[], /* o : per band old input energy */ + float ave_enr[], /* o : per band long-term average energies */ + short *pitO, /* o : open-loop pitch values from preceed. frame */ + short *aEn, /* o : noise adaptation hangover counter */ + short *st_harm_cor_cnt, /* o : harm and correlation timer */ + short *bg_cnt, /* o : pause length counter */ + float *lt_tn_track, + float *lt_tn_dist, + float *lt_Ellp_dist, + float *lt_haco_ev, + short *low_tn_track_cnt + ,float *Etot_st_est, + float *Etot_sq_st_est + +); + +void long_enr( + Encoder_State *st, /* i/o: encoder state structure */ + const float Etot, /* i : total channel energy */ + const short localVAD_HE_SAD, /* i : HE-SAD flag without hangover */ + short high_lpn_flag +); + +void noise_est_pre( + const float Etot, /* i : Energy of current frame */ + const short ini_frame, /* i : Frame number (init) */ + float *Etot_l, /* i/o: Track energy from below */ + float *Etot_h, /* i/o: Track energy from above */ + float *Etot_l_lp, /* i/o: Smoothed low energy */ + float *Etot_last, /* i/o: Energy of last frame */ + float *Etot_v_h2, /* i/o: Energy variations */ + float *sign_dyn_lp, /* i/o: Smoother signal dynamics */ + short harm_cor_cnt, + float *Etot_lp +); + +void noise_est_down( + const float fr_bands[], /* i : per band input energy (contains 2 vectors) */ + float bckr[], /* i/o: per band background noise energy estimate */ + float tmpN[], /* o : temporary noise update */ + float enr[], /* o : averaged energy over both subframes */ + const short min_band, /* i : minimum critical band */ + const short max_band, /* i : maximum critical band */ + float *totalNoise, /* o : noise estimate over all critical bands */ + const float Etot, /* i : Energy of current frame */ + float *Etot_last, /* i/o: Energy of last frame */ + float *Etot_v_h2 /* i/o: Energy variaions of noise frames */ +); + +void noise_est( + Encoder_State *st, /* i/o: encoder state structure */ + const float tmpN[], /* i : temporary noise update */ + const short *pitch, /* i : open-loop pitch values for each half-frame */ + const float *voicing, /* i : normalized correlation for all half-frames */ + const float *epsP, /* i : LP prediction error energies */ + const float Etot, /* i : total channel E */ + const float relE, /* i : relative frame energy */ + const float corr_shift, /* i : normalized correlation correction */ + const float enr[], /* i : averaged energy over both subframes */ + float fr_bands[], /* i : spectrum per critical bands of the current frame */ + float *cor_map_sum, /* o : sum of correlation map from mult-harm analysis */ + float *sp_div, /* o : soectral diversity feature */ + float *non_staX, /* o : non-stationarity for sp/mus classifier */ + short *loc_harm, /* o : multi-harmonicity flag for UV classifier */ + const float *lf_E, /* i : per bin energy for low frequencies */ + short *st_harm_cor_cnt, /* i : 1st harm correlation timer */ + const float Etot_l_lp, /* i : Smoothed low energy */ + float *sp_floor /* o : noise floor estimate */ +); + +void vad_param_updt( + Encoder_State *st, /* i/o: encoder state structure */ + const short pitch[3], /* i : open loop pitch lag for each half-frame */ + const float voicing[3], /* i : maximum normalized correlation for each half-frame */ + const float corr_shift, /* i : correlation shift */ + const float A[] /* i : A(z) unquantized for the 4 subframes */ +); + +short multi_harm( /* o : frame multi-harmonicity (1-harmonic, 0-not) */ + const float Bin_E[], /* i : log energy spectrum of the current frame */ + float old_S[], /* i/o: prev. log-energy spectrum w. subtracted floor */ + float cor_map_LT[], /* i/o: LT correlation map */ + float *multi_harm_limit, /* i/o: multi harminic threshold */ + const long total_brate, /* i : total bitrate */ + const short bwidth, /* i : input signal bandwidth */ + short *cor_strong_limit, /* i/o: HF correlation indicator */ + float *st_mean_avr_dyn, /* i/o: long term average dynamic */ + float *st_last_sw_dyn, /* i/o: last dynamic */ + float *cor_map_sum, + float *sp_floor /* o : noise floor estimate */ +); + +void lp_gain_updt( + const short i_subfr, /* i : subframe number */ + const float gain_pit, /* i : Decoded gain pitch */ + const float norm_gain_code, /* i : Normalised gain code */ + float *lp_gainp, /* i/o: LP-filtered pitch gain(FEC) */ + float *lp_gainc, /* i/o: LP-filtered code gain (FEC) */ + const short L_frame /* i : length of the frame */ +); + +void enc_pit_exc( + Encoder_State *st, /* i/o: state structure */ + LPD_state *mem, /* i/o: encoder memories */ + const float *speech, /* i : Input speech */ + const float Aw[], /* i : weighted A(z) unquantized for subframes */ + const float *Aq, /* i : 12k8 Lp coefficient */ + const float Es_pred, /* i : predicted scaled innov. energy */ + const short *T_op, /* i : open loop pitch */ + const float *voicing, /* i : voicing */ + const float *res, /* i : residual signal */ + float *synth, /* i/o: core synthesis */ + float *exc, /* i/o: current non-enhanced excitation */ + short *T0, /* i/o: close loop integer pitch */ + short *T0_frac, /* i/o: close-loop pitch period - fractional part */ + float *pitch_buf, /* i/o: Fractionnal per subframe pitch */ + const short nb_subfr, /* i : Number of subframe considered */ + float *gpit /* o : pitch gain per subframe */ +); + +void encod_audio( + Encoder_State *st, /* i/o: state structure */ + LPD_state *mem, /* i/o: encoder memories */ + const float speech[], /* i : input speech */ + const float Aw[], /* i : weighted A(z) unquantized for subframes */ + const float Aq[], /* i : 12k8 Lp coefficient */ + const short T_op[], /* i : open loop pitch */ + const float voicing[], /* i : voicing */ + const float *res, /* i : residual signal */ + float *synth, /* i/o: core synthesis */ + float *exc, /* i/o: current non-enhanced excitation */ + float *pitch_buf, /* i/o: floating pitch values for each subframe */ + float *voice_factors, /* o : voicing factors */ + float *bwe_exc, /* o : excitation for SWB TBE */ + const short attack_flag, /* i : Flag that point to an attack coded with AC mode (GSC) */ + const short coder_type, /* i : core coding type */ + float *lsf_new, /* i : current frame ISF vector */ + float *tmp_noise /* o : long-term noise energy */ +); + +short Pit_exc_contribution_len( /* o : index of the last band where pitch contribution is significant */ + Encoder_State *st, /* i/o: state structure */ + const float *dct_res, /* i : DCT of residual */ + float *dct_pitex, /* i/o: DCT of pitch contribution */ + float *pitch_buf, /* i/o: Pitch per subframe */ + short *hangover, /* i : Hangover for the time contribution switching */ + const short coder_type /* i : coding type */ +); + +short stab_est( + float etot, /* i : Total energy of the current frame */ + float *lt_diff_etot, /* i/o: Long term total energy variation */ + float *mem_etot, /* i/o: Total energy memory */ + short *nb_thr_3, /* i/o: Number of consecutives frames of level 3 */ + short *nb_thr_1, /* i/o: Number of consecutives frames of level 1 */ + float *thresh, /* i/o: Detection thresold */ + short *last_music_flag, /* i/o: Previous music detection ouptut */ + short vad_flag +); + +float gsc_gainQ( + Encoder_State *st, /* i/o: encoder state structure */ + const float y_gain4[], /* i : gain per band */ + float y_gainQ[], /* o : quantized gain per band */ + const long core_brate, /* i : Core rate */ + const short coder_type, /* i : coding type */ + const short bwidth /* i : input signal bandwidth */ +); + +void Ener_per_band_comp( + const float exc_diff[], /* i : gain per band */ + float y_gain4[], /* o : gain per band to quantize */ + const short Mband, /* i : Max band */ + const short Eflag /* i : flag of highest band */ +); + +void Comp_and_apply_gain( + float exc_diffQ[], /* i/o: gain per band */ + float Ener_per_bd_iQ[], /* o : Quant Ener per band */ + float Ener_per_bd_yQ[], /* o : Ener per band for quantize y */ + short Mbands_gn, /* i : number of bands */ + const short ReUseGain /* i : Reuse the gain in Ener_per_bd_yQ */ +); + +void bands_and_bit_alloc( + const short cor_strong_limit, /* i : HF correlation */ + const short noise_lev, /* i : dwn scaling factor */ + const long core_brate, /* i : core bit rate */ + const short Diff_len, /* i : Lenght of the difference signal (before pure spectral)*/ + const short bits_used, /* i : Number of bit used before frequency Q */ + short *bit, /* i/o: Number of bit allowed for frequency quantization */ + float *ener_vec, /* i/o: Quantized energy vector */ + short *max_ener_band, /* o : Sorted order */ + short *bits_per_bands_s, /* i/o: Number of bit allowed per allowed subband (Q3) */ + short *nb_subbands, /* o : Number of subband allowed */ + const float *exc_diff, /* i : Difference signal to quantize (encoder side only) */ + float *concat_in, /* o : Concatened PVQ's input vector (encoder side only) */ + short *pvq_len, /* o : Number of bin covered with the PVQ */ + const short coder_type, /* i : coding type */ + const short bwidth, /* i : input signal bandwidth */ + const short GSC_noisy_speech /* i : GSC noisy speech flag */ +); + +float gsc_gaindec( /* o : average frequency gain */ + Decoder_State *st, /* i/o: decoder state structure */ + float y_gainQ[], /* o : quantized gain per band */ + const long core_brate, /* i : core used */ + float old_y_gain[], /* i/o: AR gain quantizer for low rate */ + const short coder_type, /* i : coding type */ + const short bwidth /* i : input signal bandwidth */ +); + +void freq_dnw_scaling( + const short cor_strong_limit, /* i : HF correlation */ + const short coder_type, /* i : coder type */ + const short noise_lev, /* i : Noise level */ + const long core_brate, /* i : Core bitrate */ + float fy_norm[] /* i/o: Frequency quantized parameter */ +); + +void decod_audio( + Decoder_State *st, /* i/o: decoder static memory */ + float dct_epit[], /* o : GSC excitation in DCT domain */ + const float *Aq, /* i : LP filter coefficient */ + const short coder_type, /* i : coding type */ + float *tmp_noise, /* o : long term temporary noise energy */ + float *pitch_buf, /* o : floating pitch values for each subframe */ + float *voice_factors, /* o : voicing factors */ + float *exc_dct_in, /* i/o: adapt. excitation exc */ + float *exc2, /* i/o: adapt. excitation/total exc */ + float *bwe_exc, /* o : excitation for SWB TBE */ + float *lsf_new, /* i : current frame ISF vector */ + float *gain_buf +); + +void gsc_dec( + Decoder_State *st, /* i/o: State structure */ + float exc_dct_in[], /* i/o: dct of pitch-only/total excitation */ + const short pit_band_idx, /* i : pitch band index */ + const short Diff_len, /* i : */ + const short bits_used, /* i : total number of bits used */ + const short nb_subfr, /* i : Number of subframe considered */ + const short coder_type, /* i : coding type */ + short *last_bin, /* i : last bin of bit allocation */ + float *lsf_new, /* i : ISFs at the end of the frame */ + float *exc_wo_nf, /* o : excitation (in f domain) without noisefill*/ + float *tmp_noise /* o : long-term noise energy */ +); + +void dec_pit_exc( + Decoder_State *st, /* i/o: decoder static memory */ + const short L_frame, /* i : length of the frame */ + const float *Aq, /* i : LP filter coefficient */ + const float Es_pred, /* i : predicted scaled innov. energy */ + float *pitch_buf, /* o : floating pitch values for each subframe */ + float *code, /* o : innovation */ + float *exc, /* i/o: adapt. excitation exc */ + const short nb_subfr, /* i : Number of subframe considered */ + float *gain_buf +); + +void highband_exc_dct_in( + const long core_brate, /* i : core bitrate */ + const short *mfreq_bindiv_loc, /* i : bin per bands tables */ + short last_bin, /* i : last bin of bit allocation */ + short Diff_len, /* i : number of bin before cut-off frequency */ + short noise_lev, /* i : pulses dynamic */ + short pit_band_idx, /* i : bin position of the cut-off frequency */ + float *exc_diffQ, /* i : frequency coefficients of per band */ + short *seed_tcx, /* i : Seed for noise */ + float *Ener_per_bd_iQ, /* i : Quantized energy of targeted vector */ + short nb_subfr, /* i : Number of subframe considered */ + float *exc_dct_in, /* o : dct of residual signal */ + short last_coder_type, /* i : coding type of last frame */ + short *bitallocation_band, /* i : bit allocation flag of each band */ + float *lsf_new, /* i : ISFs at the end of the frame */ + float *last_exc_dct_in, /* i : dct of residual signal of last frame */ + float *last_ener, /* i : frequency energy of last frame */ + short *last_bitallocation_band, /* i : bit allocation flag of each band of last frame */ + short *bitallocation_exc, /* i : flag of decoded coefficients */ + short bfi, /* i : bad frame indicator */ + const short coder_type, /* i : coder type */ + short bwidth, + float *exc_wo_nf, /* o : excitation (in f domain) without noisefill */ + const short GSC_noisy_speech + ,float *lt_ener_per_band_fx /* i/o: Average per band energy */ +); + +void inact_switch_ematch( + float exc2[], /* i/o: CELP/GSC excitation buffer */ + float dct_exc_tmp[], /* i : GSC excitation in DCT domain */ + float lt_ener_per_band[], /* i/o: long-term energy per band */ + const short coder_type, /* i : coding mode */ + const short L_frame, /* i : frame lenght */ + const long core_brate /* i : core bit rate */ + ,const short bfi, /* i : frame lost indicator */ + const short last_core, /* i : Last core used */ + const short last_codec_mode /* i : Last codec mode */ +); + +void LD_music_post_filter( + const float dtc_in[], /* i : input synthesis */ + float dtc_out[], /* o : output synthesis */ + const long core_brate, /* i : core bitrate */ + short *last_music_flag, /* i/o: Previous music detection ouptut */ + float *thresh, /* i/o: Detection thresold */ + short *nb_thr_1, /* i/o: Number of consecutives frames of level 1 */ + short *nb_thr_3, /* i/o: Number of consecutives frames of level 3 */ + float *lt_diff_etot, /* i/o: Long term total energy variation */ + float *mem_etot, /* i/o: Total energy memory */ + const float min_ns_gain, /* i : minimum gain for inter-harm noise red. */ + float bckr[], /* i/o: per band bckgnd. noise energy estimate */ + float lf_EO[], /* i/o: old per bin E for previous half frame */ + float lp_gbin[], /* i/o: smoothed suppression gain, per FFT bin */ + float *filt_lfE, /* i : post filter weighting coefficient */ + short *last_nonfull_music, /* i : Coder type : -1 in case of IO */ + const short coder_type /* i : Coder type : -1 in case of IO */ + ,const short Last_coder_type /* i : last Coder type */ +); + +void Post_music_postP( + float dct_buffer_in[], /* i/o: excitation buffer */ + float exc_buffer_out[], /* o : DCT output buffer */ + float *exc2, /* i/o: Current excitation to be overwriten */ + const float *mem_tmp, /* i : previous frame synthesis memory */ + float *st_mem_syn2, /* i/o: current frame synthesis memory */ + const float *Aq, /* i : LPC filter coefficients */ + float *syn /* i/o: 12k8 synthesis */ +); + +void Prep_music_postP( + float exc_buffer_in[], /* i/o: excitation buffer */ + float dct_buffer_out[], /* o : DCT output buffer */ + float filt_lfE[], /* i/o: long term spectrum energy */ + const short last_core, /* i : last core */ + const float *pitch_buf, /* i : current frame pitch information */ + float *LDm_enh_lp_gbin /* o : smoothed suppression gain, per bin FFT */ +); + +void speech_music_classif( + Encoder_State *st, /* i/o: encoder state structure */ + short *sp_aud_decision0, /* o : 1st stage speech/music decision */ + short *sp_aud_decision1, /* o : 1st stage speech/music decision */ + short *sp_aud_decision2, /* o : 2nd stage speech/music decision */ + const float *new_inp, /* i : new input signal */ + const float *inp, /* i : input signal to locate attach position */ + const short vad_flag, + const short localVAD, + const short localVAD_HE_SAD, /* i : HE-SAD flag without hangover */ + const short pitch[3], /* i : open-loop pitch estimate in three subframes */ + const float voicing[3], /* i : voicing estimate in three subframes */ + const float lsp_new[M], /* i : LSPs in current frame */ + const float cor_map_sum, /* i : correlation map sum (from multi-harmonic anal.) */ + const float epsP[M+1], /* i : LP prediciton error */ + const float PS[], /* i : energy spectrum */ + const float Etot, /* i : total frame energy */ + const float old_cor, /* i : max correlation from previous frame */ + short *coder_type, /* i/o: coding type */ + short *attack_flag, /* o : flag to indicate if attack is to be treated by TC or GSC */ + const float non_staX, /* i : unbound non-stationarity for sp/mus classifier */ + const float relE, /* i : relative frame energy */ + short *high_lpn_flag, + const short flag_spitch /* i : flag to indicate very short stable pitch */ +); + +void find_wsp( + const short L_frame, /* i : length of the frame */ + const short L_subfr, /* i : length of subframe */ + const short nb_subfr, /* i : number of subframes */ + const float *A, /* i : A(z) filter coefficients */ + float *Aw, /* o : weighted A(z) filter coefficients */ + const float *speech, /* i : pointer to the denoised speech frame */ + const float tilt_fact, /* i : tilt factor */ + float *wsp, /* o : poitnter to the weighted speech frame */ + float *mem_wsp, /* i/o: W(Z) denominator memory */ + const float gamma, /* i : weighting factor */ + const short L_look /* i : look-ahead */ +); + +void pitch_ol_init( + float *old_thres, /* o : threshold for reinforcement of past pitch influence */ + short *old_pitch, /* o : pitch of the 2nd half-frame of previous frame */ + short *delta_pit, /* o : pitch evolution extrapolation */ + float *old_corr /* o : correlation */ +); + +void pitch_ol( + short pitch[3], /* o : open loop pitch lag for each half-frame */ + float voicing[3], /* o : maximum normalized correlation for each half-frame */ + short *old_pitch, /* i/o: OL pitch of the 2nd half-frame of the last frame */ + float *old_corr, /* i/o: correlation */ + float corr_shift, /* i : normalized correlation correction */ + float *old_thres, /* i/o: maximum correlation weighting with respect to past frame pitch */ + short *delta_pit, /* i/o: old pitch extrapolation correction (added to old pitch) */ + float *st_old_wsp2, /* i/o: weighted speech memory */ + const float *wsp, /* i : weighted speech for current frame and look-ahead */ + float mem_decim2[3], /* i/o: wsp decimation filter memory */ + const float relE, /* i : relative frame energy */ + const short L_look, /* i : look-ahead */ + const short last_class, /* i : frame classification of last frame */ + const short bwidth, /* i : bandwidth */ + const short Opt_SC_VBR /* i : SC-VBR flag */ +); + +void pitch_ol2( + const short pit_min, /* i : pit_min value */ + const short pitch_ol, /* i : pitch to be improved */ + float *pitch_fr, /* o : adjusted 1/4 fractional pitch */ + float *voicing_fr, /* o : adjusted 1/4 fractional voicing */ + const short pos, /* i : position in frame where to calculate the improv. */ + const float *wsp, /* i : weighted speech for current frame and look-ahead */ + const short delta /* i : delta for pitch search */ +); + +void StableHighPitchDetect( + short *flag_spitch, /* o : flag to indicate very short stable pitch */ + short pitch[], /* i/o: OL pitch buffer */ + const float voicing[], /* i : OL pitch gains */ + const float Bin_E[], /* i : per bin log energy spectrum */ + const float wsp[], /* i : weighted speech */ + const short localVAD, + float *voicing_sm, /* i/o: smoothed open-loop pitch gains */ + float *voicing0_sm, /* i/o: smoothed high pitch gains */ + float *LF_EnergyRatio_sm, /* i/o: smoothed [0, 300Hz] relative peak energy */ + short *predecision_flag, /* i/o: predecision flag */ + float *diff_sm, /* i/o: smoothed pitch frequency difference */ + float *energy_sm /* i/o: smoothed energy around pitch frequency */ +); + +void pitchDoubling_det( + float *wspeech, + short *pitch_ol, + float *pitch_fr, + float *voicing_fr +); + +void gain_enc_amr_wb( + Encoder_State *st, /* i/o: encoder state structure */ + const float *xn, /* i : target vector */ + const float *y1, /* i : zero-memory filtered adaptive excitation */ + const float *y2, /* i : zero-memory filtered algebraic codebook excitation */ + const float *code, /* i : algebraic excitation */ + const long core_brate, /* i : core bitrate */ + float *gain_pit, /* i/o: Pitch gain / Quantized pitch gain */ + float *gain_code, /* o : Quantized codebook gain */ + float *gain_inov, /* o : innovation gain */ + float *norm_gain_code, /* o : norm. gain of the codebook excitation */ + float *coeff, /* i/o: correlations , -2,, -2 and 2 */ + const short clip_gain, /* i : gain pitch clipping flag (1 = clipping) */ + float *past_qua_en /* i/o: gain quantization memory (4 words) */ + +); + +void gain_enc_lbr( + Encoder_State *st, /* i/o: encoder state structure */ + const long core_brate, /* i : core bitrate */ + const short coder_type, /* i : coding type */ + const short i_subfr, /* i : subframe index */ + const float *xn, /* i : target vector */ + const float *y1, /* i : zero-memory filtered adaptive excitation */ + const float *y2, /* i : zero-memory filtered algebraic codebook excitation */ + const float *code, /* i : algebraic excitation */ + float *gain_pit, /* o : quantized pitch gain */ + float *gain_code, /* o : quantized codebook gain */ + float *gain_inov, /* o : gain of the innovation (used for normalization) */ + float *norm_gain_code, /* o : norm. gain of the codebook excitation */ + float *g_corr, /* i/o: correlations , -2,, -2 and 2 */ + float gains_mem[], /* i/o: pitch gain and code gain from previous subframes */ + const short clip_gain /* i : gain pitch clipping flag (1 = clipping) */ +); + +void gain_enc_mless( + Encoder_State *st, /* i/o: encoder state structure */ + const long core_brate, /* i : core bitrate */ + const short L_frame, /* i : length of the frame */ + const short coder_type, /* i : coding type */ + const short i_subfr, /* i : subframe index */ + const short tc_subfr, /* i : TC subframe index */ + const float *xn, /* i : target vector */ + const float *y1, /* i : zero-memory filtered adaptive excitation */ + const float *y2, /* i : zero-memory filtered algebraic codebook excitation */ + const float *code, /* i : algebraic excitation */ + const float Es_pred, /* i : predicted scaled innovation energy */ + float *gain_pit, /* o : quantized pitch gain */ + float *gain_code, /* o : quantized codebook gain */ + float *gain_inov, /* o : innovation gain */ + float *norm_gain_code, /* o : norm. gain of the codebook excitation */ + float *coeff, /* i/o: correlations , -2,, -2 and 2 */ + const short clip_gain /* i : gain pitch clipping flag (1 = clipping) */ +); + +void gain_enc_SQ( + Encoder_State *st, /* i/o: encoder state structure */ + const long core_brate, /* i : core bitrate */ + const short coder_type, /* i : coding type */ + const short i_subfr, /* i : subframe index */ + const short tc_subfr, /* i : TC subframe index */ + const float *xn, /* i : target vector */ + const float *yy1, /* i : zero-memory filtered adaptive excitation */ + const float *y2, /* i : zero-memory filtered algebraic codebook excitation */ + const float *code, /* i : algebraic excitation */ + const float Es_pred, /* i : predicted scaled innovation energy */ + float *gain_pit, /* o : quantized pitch gain */ + float *gain_code, /* o : quantized codebook gain */ + float *gain_inov, /* o : gain of the innovation (used for normalization) */ + float *norm_gain_code, /* o : norm. gain of the codebook excitation */ + float *g_corr, /* i/o: correlations , -2,, -2 and 2 */ + const short clip_gain /* i : gain pitch clipping flag (1 = clipping) */ +); + +short gain_enc_gaus( /* o : Return index of quantization */ + float *gain, /* i/o: Code gain to quantize */ + const short bits, /* i : number of bits to quantize */ + const float lowBound, /* i : lower bound of quantizer (dB) */ + const float topBound /* i : upper bound of quantizer (dB) */ +); + +void E_corr_xy2( + const float xn[], /* i : target vector */ + const float y1[], /* i : filtered excitation components 1 */ + const float y2[], /* i : filtered excitation components 2 */ + float g_corr[], /* o : correlations between x, y1, y2, y3, y4 */ + const short L_subfr /* i : subframe size */ +); + +float pit_encode( /* o : Floating pitch for each subframe */ + Encoder_State *st, /* i/o: encoder state structure */ + const long core_brate, /* i : core bitrate */ + const short Opt_AMR_WB, /* i : flag indicating AMR-WB IO mode */ + const short L_frame, /* i : length of the frame */ + const short coder_type, /* i : coding type */ + short *limit_flag, /* i/o: restrained(0) or extended(1) Q limits */ + const short i_subfr, /* i : subframe index */ + float *exc, /* i/o: pointer to excitation signal frame */ + const short L_subfr, /* i : subframe length */ + const short *T_op, /* i : open loop pitch estimates in current frame */ + short *T0_min, /* i/o: lower limit for close-loop search */ + short *T0_max, /* i/o: higher limit for close-loop search */ + short *T0, /* i/o: close loop integer pitch */ + short *T0_frac, /* i/o: close loop fractional part of the pitch */ + const float *h1, /* i : weighted filter input response */ + const float *xn /* i : target vector */ +); + +short find_uv( /* o : coding type */ + Encoder_State *st, /* i/o: encoder state structure */ + const float *pitch_fr, /* i : pointer to adjusted fractional pitch (4 val.) */ + const float *voicing_fr, /* i : refined correlation for each subframes */ + const float *voicing, /* i : correlation for 3 half-frames */ + const float *speech, /* i : pointer to speech signal for E computation */ + const short localVAD, /* i : vad without hangover */ + const float *ee, /* i : lf/hf Energy ratio for present frame */ + const float corr_shift, /* i : normalized correlation correction in noise */ + const float relE, /* i : relative frame energy */ + const float Etot, /* i : total energy */ + const float hp_E[], /* i : energy in HF */ + short *flag_spitch, /* i/o: flag to indicate very short stable pitch and high correlation */ + float voicing_sm /* i/o: smoothed open-loop pitch gains */ + , const short last_core_orig /* i : original last core */ +); + +short signal_clas( /* o : classification for current frames */ + Encoder_State *st, /* i/o: encoder state structure */ + short *coder_type, /* i/o: coder type */ + const float voicing[3], /* i : normalized correlation for 3 half-frames */ + const float *speech, /* i : pointer to speech signal for E computation */ + const short localVAD, /* i : vad without hangover */ + const short pit[3], /* i : open loop pitch values for 3 half-frames */ + const float *ee, /* i : lf/hf E ration for 2 half-frames */ + const float relE, /* i : frame relative E to the long term average */ + const short L_look, /* i : look-ahead */ + short *uc_clas /* o : flag for unvoiced class used in sp/mus classifier */ +); + +void wb_vad_init( + short *nb_active_frames, /* o : nb of consecutive active speech frames */ + short *hangover_cnt, + float *lp_speech, /* o : long-term active speech level */ + short *nb_active_frames_he, /* o : nb of consecutive active speech frames */ + short *hangover_cnt_he, + float *bcg_flux, /* o : background noise fluctuation */ + short *soft_hangover, /* o : soft hangover counter */ + short *voiced_burst, /* o : consecutive voiced speech counter */ + short *bcg_flux_init, /* o : initialization period for noise fluctuation estimation */ + short *nb_active_frames_he1, /* o : nb of consecutive active speech frames 1 */ + short *hangover_cnt_he1, + long *vad_flag_reg_H, + long *vad_flag_reg_L, /* o : lower 31 bits */ + long *vad_prim_reg, + short *vad_flag_cnt_50, + short *vad_prim_cnt_16, + short *hangover_cnt_dtx, + short *flag_noisy_speech_snr + ,short *hangover_cnt_music /* o : counter of VAD DTX Music hangover frames */ +); + +short dtx_hangover_addition( + Encoder_State *st, /* i/o: encoder state structure */ + const short localVAD, /* i : Primary vad decision */ + const short vad_flag, + const float snr, /* i : input single SNR estimate */ + const short cldfb_subtraction, /* i : */ + short *vad_hover_flag +); + +short wb_vad( + Encoder_State *st, /* i/o: encoder state structure */ + const float fr_bands[], /* i : per band input energy (contains 2 vectors) */ + short *localVAD, + short *noisy_speech_HO, /* o : SC-VBR noisy speech HO flag */ + short *clean_speech_HO, /* o : SC-VBR clean speech HO flag */ + short *NB_speech_HO, /* o : SC-VBR NB speech HO flag */ + float *snr_sum_he, /* i : voicing metric from SAD */ + short *localVAD_HE_SAD, /* o : HE_SAD decision without hangovers */ + short *flag_noisy_speech_snr /* o : */ +); + +void bw_detect( + Encoder_State *st, /* i/o: Encoder State */ + const float signal_in[], /* i : input signal */ + const short localVAD, + float *enerBuffer +); + +float gaus_encode( + Encoder_State *st, /* i/o: encoder state structure */ + const short i_subfr, /* i : subframe index */ + const float *h1, /* i : weighted filter input response */ + const float *xn, /* i : target vector */ + float *exc, /* o : pointer to excitation signal frame */ + float *mem_w0, /* o : weighting filter denominator memory */ + float *gp_clip_mem, /* o : memory of gain of pitch clipping algorithm */ + float *tilt_code, /* o : synthesis excitation spectrum tilt */ + float *code, /* o : algebraic excitation */ + float *gain_code, /* o : Code gain. */ + float *y2, /* o : zero-memory filtered adaptive excitation */ + float *gain_inov, /* o : innovation gain */ + float *voice_fac, /* o : voicing factor */ + float *gain_pit, /* o : adaptive excitation gain */ + float *norm_gain_code, /* o : normalized innovative cb. gain */ + const long core_brate /* i : core bitrate */ +); + +void dtx( + Encoder_State *st, /* i/o: encoder state structure */ + const short vad, /* i : vad flag */ + const float speech[] /* i : Pointer to the speech frame */ +); + +void dtx_hangover_control( + Encoder_State *st, /* i/o: encoder state structure */ + const float lsp_new[M] /* i : current frame LSPs */ +); + +void updt_enc( + Encoder_State *st, /* i/o: state structure */ + const short L_frame, /* i : length of the frame */ + const short coder_type, /* i : coding type */ + const float *old_exc, /* i : buffer of excitation */ + const float *pitch_buf, /* i : Floating pitch for each subframe */ + const float Es_pred, /* i : predicited scaled innovation energy */ + const float *Aq, /* i : A(z) quantized for all subframes */ + const float *lsf_new, /* i : current frame LSF vector */ + const float *lsp_new, /* i : current frame LSP vector */ + const float *old_bwe_exc /* o : buffer of excitation for SWB TBE */ +); + +void updt_IO_switch_enc( + Encoder_State *st, /* i/o: state structure */ + const short input_frame /* i : input frame length */ +); + +void transition_enc( + Encoder_State *st, /* i/o: encoder state structure */ + const long core_brate, /* i : core bitrate */ + const short L_frame, /* i : length of the frame */ + const short coder_type, /* i : coding type */ + const short i_subfr, /* i : subframe index */ + short *tc_subfr, /* i/o: TC subframe index */ + short *Jopt_flag, /* i : joint optimization flag */ + short *position, /* i/o: maximum of residual signal index */ + const float voicing[], /* i : normalized correlations (from OL pitch) */ + const short T_op[], /* i : open loop pitch estimates in current frame */ + short *T0, /* i/o: close loop integer pitch */ + short *T0_frac, /* i/o: close loop fractional part of the pitch */ + short *T0_min, /* i/o: lower limit for close-loop search */ + short *T0_max, /* i/o: higher limit for close-loop search */ + float *exc, /* i/o: pointer to excitation signal frame */ + float *y1, /* o : zero-memory filtered adaptive excitation */ + const float *res, /* i : pointer to the LP residual signal frame */ + const float *h1, /* i : weighted filter input response */ + const float *xn, /* i : target vector */ + float *xn2, /* o : target vector for innovation search */ + float *gp_cl, /* i/o: memory of gain of pitch clipping algorithm */ + float *gain_pit, /* o : adaptive excitation gain */ + float *g_corr, /* o : ACELP correlation values */ + short *clip_gain, /* i/o: adaptive gain clipping flag */ + float **pt_pitch, /* o: floating pitch values */ + float *bwe_exc /* i/o: excitation for SWB TBE */ +); + +void set_impulse( + const float xn[], /* i : target signal */ + const float h_orig[], /* i : impulse response of weighted synthesis filter */ + float exc[], /* o : adaptive codebook excitation */ + float y1[], /* o : filtered adaptive codebook excitation */ + short *imp_shape, /* o : adaptive codebook index */ + short *imp_pos, /* o : position of the glotal impulse center index */ + float *gain_trans /* o : transition gain */ +); + +void gain_enc_tc( + Encoder_State *st, /* i/o: encoder state structure */ + const long core_brate, /* i : core bitrate */ + const short L_frame, /* i : length of the frame */ + const short i_subfr, /* i : subframe index */ + const short tc_subfr, /* i : TC subframe index */ + const float xn[], /* i : target vector */ + const float y2[], /* i : zero-memory filtered algebraic codebook excitation */ + const float code[], /* i : algebraic excitation */ + const float Es_pred, /* i : predicted scaled innovation energy */ + float *gain_pit, /* o : pitch gain / Quantized pitch gain */ + float *gain_code, /* o : quantized codebook gain */ + float *gain_inov, /* o : innovation gain */ + float *norm_gain_code /* o : norm. gain of the codebook excitation */ +); + +float corr_xy1( /* o : pitch gain (0..GAIN_PIT_MAX) */ + const float xn[], /* i : target signal */ + const float y1[], /* i : filtered adaptive codebook excitation */ + float g_corr[], /* o : correlations and -2 */ + const short L_subfr, + const short norm_flag /* i : flag for constraining pitch contribution */ +); + +void norm_corr( + const float exc[], /* i : excitation buffer */ + const float xn[], /* i : target signal */ + const float h[], /* i : weighted synthesis filter impulse response */ + const short t_min, /* i : minimum value of searched range */ + const short t_max, /* i : maximum value of searched range */ + float corr_norm[], /* o : normalized correlation */ + const short L_subfr /* i : subframe size */ +); + +short pitch_fr4( /* o : chosen integer pitch lag */ + const float exc[], /* i : excitation buffer */ + const float xn[], /* i : target signal */ + const float h[], /* i : weighted synthesis filter impulse response */ + const short t0_min, /* i : minimum value in the searched range. */ + const short t0_max, /* i : maximum value in the searched range. */ + short *pit_frac, /* o : chosen fraction (0, 1, 2 or 3) */ + const short i_subfr, /* i : flag to first subframe */ + const short limit_flag, /* i : flag for limits (0=restrained, 1=extended) */ + const short t0_fr2, /* i : minimum value for resolution 1/2 */ + const short t0_fr1, /* i : minimum value for resolution 1 */ + const short L_frame, /* i : length of the frame */ + const short L_subfr /* i : size of subframe */ +); + +void pit_Q_enc( + Encoder_State *st, /* i/o: encoder state structure */ + const short Opt_AMR_WB, /* i : flag indicating AMR-WB IO mode */ + const short nBits, /* i : # of Q bits */ + const short delta, /* i : Half the CL searched interval */ + const short pit_flag, /* i : absolute(0) or delta(1) pitch Q */ + const short limit_flag, /* i : restrained(0) or extended(1) Q limits */ + const short T0, /* i : integer pitch lag */ + const short T0_frac, /* i : pitch fraction */ + short *T0_min, /* i/o: delta search min */ + short *T0_max /* o : delta search max */ +); + +void pit16k_Q_enc( + Encoder_State *st, /* i/o: encoder state structure */ + const short nBits, /* i : # of Q bits */ + const short limit_flag, /* i : restrained(0) or extended(1) Q limits */ + const short T0, /* i : integer pitch lag */ + const short T0_frac, /* i : pitch fraction */ + short *T0_min, /* i/o: delta search min */ + short *T0_max /* o : delta search max */ +); + +short abs_pit_enc( /* o : pitch index */ + const short fr_steps, /* i : fractional resolution step */ + const short limit_flag, /* i : restrained(0) or extended(1) limits */ + const short T0, /* i : integer pitch lag */ + const short T0_frac /* i : pitch fraction */ +); + +short delta_pit_enc( /* o : pitch index */ + const short fr_steps, /* i : fractional resolution steps (2 or 4) */ + const short T0, /* i : integer pitch lag */ + const short T0_frac, /* i : pitch fraction */ + const short T0_min /* i : delta search min */ +); + +float AVQ_cod( /* o: comfort noise gain factor */ + const float xri[], /* i: vector to quantize */ + int xriq[], /* o: quantized normalized vector (assuming the bit budget is enough) */ + const short nb_bits, /* i: number of allocated bits */ + const short Nsv /* i: number of subvectors (lg=Nsv*8) */ +); + +void AVQ_encmux( + Encoder_State *st, /* i/o: encoder state structure */ + const short extl, /* i : extension layer */ + int xriq[], /* i/o: rounded subvectors [0..8*Nsv-1] followed */ + /* by rounded bit allocations [8*Nsv..8*Nsv+Nsv-1] */ + short *nb_bits, /* i/o: number of allocated bits */ + const short Nsv, /* i: number of subvectors */ + short nq[] /* o : AVQ nq index */ +); + +void re8_cod( + int x[], /* i : point in RE8 (8-dimensional integer vector) */ + int *n, /* i : codebook number (*n is an integer defined in {0,2,3,4,..,n_max}) */ + long *I, /* o : index of c (pointer to unsigned 16-bit word) */ + int k[] /* o : index of v (8-dimensional vector of binary indices) = Voronoi index */ +); + +void pre_exc( + const short Opt_AMR_WB, /* i : flag indicating AMR-WB IO mode */ + const short L_frame, /* i : frame length */ + const float *speech, /* i : input speech */ + const float *p_Aq, /* i : 12k8 Lp coefficient */ + const float *p_A, /* i : unquantized A(q) filter with bandwidth expansion */ + const short coder_type, /* i : coding type */ + const short i_subfr, /* i : current sub frame indicator */ + float *Ap, /* o : weighted LP filter coefficients */ + const float *res, /* i : residual signal */ + float *h1, /* o : impulse response of weighted synthesis filter */ + float *xn, /* o : close-loop Pitch search target vector */ + float *cn, /* o : target vector in residual domain */ + float *mem_syn, /* i/o: memory of the synthesis filter */ + float *mem_w0, /* i/o: weighting filter denominator memory */ + const short L_subfr /* i : subframe length */ +); + +void encod_unvoiced( + Encoder_State *st, /* i/o: state structure */ + LPD_state *mem, /* i/o: encoder memories */ + const float *speech, /* i : input speech */ + const float Aw[], /* i : weighted A(z) unquantized for subframes */ + const float *Aq, /* i : LP coefficients */ + const short vad_flag, + const float *res, /* i : residual signal */ + float *syn, /* o : core synthesis */ + float *tmp_noise, /* o : long-term noise energy */ + float *exc, /* i/o: current non-enhanced excitation */ + float *pitch_buf, /* o : floating pitch values for each subframe */ + float *voice_factors, /* o : voicing factors */ + float *bwe_exc /* i/o: excitation for SWB TBE */ +); + +void encod_gen_voic( + Encoder_State *st, /* i/o: state structure */ + LPD_state *mem, /* i/o: encoder memories */ + const short L_frame, /* i : length of the frame */ + const short sharpFlag, /* i : formant sharpening flag */ + const float speech[], /* i : input speech */ + const float Aw[], /* i : weighted A(z) unquantized for subframes */ + const float Aq[], /* i : LP coefficients */ + const short coder_type, /* i : coding type */ + const float Es_pred, /* i : predicted scaled innov. energy */ + const short T_op[], /* i : open loop pitch */ + const float voicing[], /* i : voicing */ + const float *res, /* i : residual signal */ + float *syn, /* o : core synthesis */ + float *exc, /* i/o: current non-enhanced excitation */ + float *exc2, /* i/o: current enhanced excitation */ + float *pitch_buf, /* o : floating pitch values for each subframe */ + float *voice_factors, /* o : voicing factors */ + float *bwe_exc, /* i/o: excitation for SWB TBE */ + short *unbits /* i/o: number of unused bits */ +); + +short encod_tran( + Encoder_State *st, /* i/o: state structure */ + LPD_state *mem, /* i/o: encoder memories */ + const short L_frame, /* i : length of the frame */ + const float speech[], /* i : input speech */ + const float Aw[], /* i : weighted A(z) unquantized for subframes */ + const float Aq[], /* i : LP coefficients */ + const short coder_type, /* i : coding type */ + const float Es_pred, /* i : predicted scaled innov. energy */ + const short T_op[], /* i : open loop pitch */ + const float voicing[], /* i : voicing */ + const float *res, /* i : residual signal */ + float *syn, /* o : synthesis */ + float *exc, /* i/o: current non-enhanced excitation */ + float *exc2, /* i/o: current enhanced excitation */ + float *pitch_buf, /* o : floating pitch values for each subframe */ + float *voice_factors, /* o : voicing factors */ + float *bwe_exc, /* i/o: excitation for SWB TBE */ + const short attack_flag, /* i : Flag to indicate when attack is deal with TM */ + short *unbits, /* i/o: number of unused bits */ + const short sharpFlag /* i : formant sharpening flag */ +); + +void encod_amr_wb( + Encoder_State *st, /* i/o: state structure */ + LPD_state *mem, /* i/o: encoder state structure */ + const float speech[], /* i : input speech */ + const float Aw[], /* i : weighted A(z) unquantized for subframes */ + const float Aq[], /* i : 12k8 Lp coefficient */ + const short pitch[3], /* i : open-loop pitch values for quantiz. */ + const float voicing[], /* i : voicing */ + const float *res, /* i : residual signal */ + float *syn, /* i/o: core synthesis */ + float *exc, /* i/o: current non-enhanced excitation */ + float *exc2, /* i/o: current enhanced excitation */ + float *pitch_buf, /* i/o: floating pitch values for each subframe */ + short *hf_gain, /* o : decoded HF gain */ + const float *speech16k /* i : input speech @16kHz */ +); + +void stat_noise_uv_enc( + Encoder_State *st, /* i/o: state structure */ + const short coder_type, /* i : coding type */ + const float *epsP, /* i : LP prediction errors */ + float *lsp_new, /* i : end-frame LSP vector */ + float *lsp_mid, /* i : mid-frame LSP vector */ + float *Aq, /* i : A(z) quantized for the 4 subframes */ + float *exc2 /* i/o: excitation buffer */ +); + +void re8_compute_base_index( + const int *x, /* i : Elemen of Q2, Q3 or Q4 */ + const int ka, /* i : Identifier of the absolute leader related to x */ + long *I /* o : index */ +); + +void transf_cdbk_enc( + Encoder_State *st, /* i/o: encoder state structure */ + const long core_brate, /* i : core bitrate */ + const short extl, /* i : extension layer */ + const short coder_type, /* i : coding type */ + const short harm_flag_acelp, /* i : harmonic flag for higher rates ACELP */ + const short i_subfr, /* i : subframe index */ + const short tc_subfr, /* i : TC subframe index */ + float cn[], /* i/o: target vector in residual domain */ + float exc[], /* i/o: pointer to excitation signal frame */ + const float *p_Aq, /* i : 12k8 Lp coefficient */ + const float Ap[], /* i : weighted LP filter coefficients */ + const float h1[], /* i : weighted filter input response */ + float xn[], /* i/o: target vector */ + float xn2[], /* i/o: target vector for innovation search */ + float y1[], /* i/o: zero-memory filtered adaptive excitation */ + const float y2[], /* i : zero-memory filtered innovative excitation */ + const float Es_pred, /* i : predicited scaled innovation energy */ + float *gain_pit, /* i/o: adaptive excitation gain */ + const float gain_code, /* i : innovative excitation gain */ + float g_corr[], /* o : ACELP correlation values */ + const short clip_gain, /* i : adaptive gain clipping flag */ + float *mem_deemp, /* i/o: prequantizer deemhasis memory */ + float *mem_preemp, /* i/o: prequantizer preemhasis memory */ + float *gain_preQ, /* o : prequantizer excitation gain */ + float code_preQ[], /* o : prequantizer excitation */ + short *unbits /* i/o: number of AVQ unused bits */ +); + +short gain_quant( /* o: quantization index */ + float *gain, /* i/o: quantized gain */ + const float min, /* i: value of lower limit */ + const float max, /* i: value of upper limit */ + const short bits /* i: number of bits to quantize */ +); + +void deemph_lpc( + float *p_Aq_cuerr, /* i : LP coefficients current frame */ + float *p_Aq_old, /* i : LP coefficients previous frame */ + float *LPC_de_curr, /* o : De-emphasized LP coefficients current frame */ + float *LPC_de_old /* o : De-emphasized LP coefficients previous frame */ + ,short deemph_old +); + +void Interpol_delay( + float *out, /* o : pitch interpolation output */ + float *last, /* i : last frame pitch lag */ + float *current, /* i : current frame pitch lag */ + short SubNum, /* i : subframe number */ + const float *frac /* i : interpolation constant */ +); + +float dequantize_uvg( + int iG1, /* i: gain 1 index */ + int *iG2, /* i: gain 2 index */ + float *G, /* o: quantized gain */ + short bwidth +); + +void generate_nelp_excitation( + short *seed, /* i/o: random number seed */ + float *Gains, /* i : excitation gains */ + float *output, /* o : excitation output */ + float gain_fac /* i : gain factor */ +); + +void nelp_encoder( + Encoder_State *st, /* i/o: encoder state */ + float *in, /* i : residual signal */ + float *exc /* o : NELP quantized excitation signal */ + ,short reduce_gains +); + +void encod_nelp( + Encoder_State *st, /* i/o: state structure */ + LPD_state *mem, /* i/o: encoder memories */ + const float *speech, /* i : input speech */ + const float Aw[], /* i : weighted A(z) unquantized for subframes */ + const float *Aq, /* i : 12k8 Lp coefficient */ + float *res, /* o : residual signal */ + float *synth, /* o : core synthesis */ + float *tmp_noise, /* o : long-term noise energy */ + float *exc, /* i/o: current non-enhanced excitation */ + float *exc2, /* i/o: current enhanced excitation */ + float *pitch_buf, /* o : floating pitch values for each subframe */ + float *voice_factors, /* o : voicing factors */ + float *bwe_exc /* o : excitation for SWB TBE */ +); + +void realft( + float *data, /* i/o: data array .......... */ + short n, /* i : length of data array */ + short isign /* i : sign +1 or -1 */ +); + +DTFS_STRUCTURE *DTFS_new( + void +); + +void DTFS_copy( + DTFS_STRUCTURE *Xout, /* o: DTFS */ + DTFS_STRUCTURE Xinp /* i: DTFS */ +); + +DTFS_STRUCTURE DTFS_sub( + DTFS_STRUCTURE X1, /* i: X1 DTFS */ + DTFS_STRUCTURE X2 /* i: X2 DTFS */ + /* o: X1 - X2 */ +); + +void DTFS_to_fs( + const float *x, /* i: Time domain signal */ + int N, /* i: Length of input vector */ + DTFS_STRUCTURE *X, /* o: DTFS structure with a, b, lag */ + short Fs, + short FR_flag /* i: FR flag */ +); + +void DTFS_fs_inv( + DTFS_STRUCTURE *X, /* i : DTFS */ + float *x, /* o : time domain sig */ + int N, /* i : Output length */ + float ph0 /* i : Input phase */ +); + +void DTFS_fast_fs_inv( + DTFS_STRUCTURE *X1_DTFS, /* i : X1 DTFS */ + float *out, /* o : time domain */ + int N /* i : Number of output samples */ +); + +void DTFS_car2pol( + DTFS_STRUCTURE *X /* i/o : DTFS structure a, b, lag */ + /* input in Cartesion, output in Polar */ +); + +void DTFS_pol2car( + DTFS_STRUCTURE *X /* i/o : DTFS structure a, b, lag */ + /* input in Polar, output in Cartesian */ +); + +float DTFS_setEngyHarm( + float f1, /* i : lower band freq of input to control energy */ + float f2, /* i : upper band freq of input to control energy */ + float g1, /* i : lower band freq of output to control energy */ + float g2, /* i : upper band freq of output to control energy */ + float en2, /* i : Target Energy to set the DTFS to */ + DTFS_STRUCTURE *X /* i/o: DTFS to adjust the energy of */ + /* o : Return Input RMS between f1/f2 b4 scaling */ +); + +void DTFS_to_erb( + DTFS_STRUCTURE X, /* i : DTFS input */ + float *out /* o : ERB output */ +); + +void DTFS_zeroPadd( + int N, /* i : Target lag */ + DTFS_STRUCTURE *X /* i/o: DTFS */ +); + +float DTFS_getEngy( + DTFS_STRUCTURE X /* i : DTFS to compute energy of */ + /* o : Energy */ +); + +float DTFS_getEngy_band( + DTFS_STRUCTURE X, /* i : DTFS to compute energy of */ + float lband, /* i : low end of band of interest */ + float hband /* i : high end of band of interest */ +); + +float DTFS_getEngy_band_wb( + DTFS_STRUCTURE X, /* i : DTFS to compute energy of */ + float lband, /* i : low end of band of interest */ + float hband /* i : high end of band of interest */ +); + +double DTFS_freq_corr( + DTFS_STRUCTURE X1, /* i : X1 DTFS */ + DTFS_STRUCTURE X2, /* i : X2 DTFS */ + float lband, /* i : low cutoff */ + float hband /* i : high cutoff */ + /* o : Correlation */ +); + +float DTFS_setEngy( + DTFS_STRUCTURE *X_DTFS, /* i/o: DTFS structure to set engy */ + float en2 /* i : Energy to set to */ +); + +void DTFS_adjustLag( + DTFS_STRUCTURE *X_DTFS, /* i/o: DTFS to adjust lag for */ + int N /* i : Target lag */ +); + +void DTFS_poleFilter( + DTFS_STRUCTURE *X, /* i/o: DTFS to poleFilter inplace */ + const float *LPC, /* i : LPCs */ + int N /* i : LPCORDER */ +); + +void DTFS_zeroFilter( + DTFS_STRUCTURE *X, /* i/o: DTFS to zeroFilter inplace */ + const float *LPC, /* i : LPCs */ + int N /* i : LPCORDER */ +); + +float DTFS_alignment_full( + DTFS_STRUCTURE X1_DTFS, /* i : reference DTFS */ + DTFS_STRUCTURE X2_DTFS, /* i : DTFS to shift */ + int num_steps /* i : resolution */ +); + +float DTFS_alignment_extract( + DTFS_STRUCTURE refX1_DTFS, /* i : X1 the reference DTFS to keep fixed */ + DTFS_STRUCTURE X2_DTFS, /* i : X2 the test DTFS to shift to find best match */ + float Eshift, /* i : Expected shift - coarse value */ + const float *LPC2 /* i : LPC to filter to find correlation in speech */ + /* o : shift value to shift X2 by */ +); + +float DTFS_alignment_weight( + DTFS_STRUCTURE refX1_DTFS, /* i : X1 the reference DTFS to keep fixed */ + DTFS_STRUCTURE X2_DTFS, /* i : X2 the test DTFS to shift to find best match */ + float Eshift, /* i : Expected shift - coarse value */ + const float *LPC1, /* i : LPC to filter to find correlation in spch */ + const float *LPC2 /* i : LPC to filter to find correlation in spch */ + /* o : shift value to shift X2 by */ +); + +float DTFS_alignment_fine_new( + DTFS_STRUCTURE X1_DTFS, /* i : X1 the reference DTFS to keep fixed */ + DTFS_STRUCTURE X2_DTFS, /* i : X2 the test DTFS to shift to find best match */ + float Eshift /* i : Expected shift - coarse value */ + /* o : shift value to shift X2 by */ +); + +void DTFS_phaseShift( + DTFS_STRUCTURE *X, /* i : DTFS to shift */ + float ph /* i : phase to shift */ +); + +void DTFS_erb_inv( + float *in, /* i : ERB inpt */ + int *slot, /* i : ERB slots filled based on lag */ + float *mfreq, /* i : erb frequence edges */ + DTFS_STRUCTURE * X, /* o : DTFS after erb-inv */ + short num_erb /* i : Number of ERB bands */ +); + +short DTFS_quant_cw( + DTFS_STRUCTURE *X, /* i/o: DTFS unquant inp, quant out */ + int pl, /* i : Previous lag */ + const float *curr_lpc, /* i : LPC */ + int *POWER_IDX, /* o : Power index */ + int *AMP_IDX, /* o : Amplitude index */ + float *lastLgainE, /* i/o: last frame lowband gain */ + float *lastHgainE, /* i/o: last frame highband gain */ + float *lasterbE /* i/o: last frame ERB vector */ + /* Flag - amp quant performance pass/fail */ +); + +void DTFS_dequant_cw( + int pl, /* i : Previous lag */ + int POWER_IDX, /* i : POWER index */ + const int *AMP_IDX, /* i : Amp Shape index */ + float *lastLgainD, /* i/o: low band last gain */ + float *lastHgainD, /* i/o: high band last gain */ + float *lasterbD, /* i/o: last frame ERB vector */ + DTFS_STRUCTURE *X, /* o : DTFS structure dequantized */ + short num_erb /* i : Number of ERB bands */ +); + +void DTFS_transform( + DTFS_STRUCTURE X, /* i : Starting DTFS to use in WI */ + DTFS_STRUCTURE X2, /* i : Ending DTFS to use in WI */ + const float *phase, /* i : Phase contour */ + float *out, /* o : Output time domain waveform */ + int N, /* i : Number of samples to generate */ + short FR_flag /* i : Flag to indicate called in FR context */ +); + +float DTFS_getSpEngyFromResAmp( + DTFS_STRUCTURE X, /* i : DTFS */ + float lband, /* i : Low band end to get energy from */ + float hband, /* i : High band end to get energy from */ + const float *curr_lsp /* i : LPCs */ + /* o : speech energy */ +); + +void DTFS_peaktoaverage( + DTFS_STRUCTURE X, /* i : DTFS */ + float *pos, /* o : positive peak to ave */ + float *neg /* o : negative peak to ave */ +); + +short ppp_extract_pitch_period( + const float *in, /* i : input residual */ + float *out, /* o : output residual */ + int l, /* i : lag */ + short *out_of_bound /* o : out of bound flag */ +); + +short ppp_quarter_encoder( + Encoder_State *st, /* i/o: encoder state structure */ + DTFS_STRUCTURE *CURRCW_Q, /* o : Quantized (amp/phase) DTFS */ + DTFS_STRUCTURE *TARGETCW, /* o : DTFS with quant phase but unquant Amp */ + int prevCW_lag, /* i : previous lag */ + DTFS_STRUCTURE vCURRCW_NQ, /* i : Unquantized DTFS */ + const float *curr_lpc, /* i : LPCS */ + float *lastLgainE, /* i/o: last low band gain */ + float *lastHgainE, /* i/o: last high band gain */ + float *lasterbE, /* i/o: last ERB vector */ + DTFS_STRUCTURE PREV_CW_E /* i : past DTFS */ +); + +void WIsyn( + DTFS_STRUCTURE PREVCW, /* i : Prev frame DTFS */ + DTFS_STRUCTURE *CURR_CW_DTFS, /* i/o: Curr frame DTFS */ + const float *curr_lpc, /* i : LPC */ + float *ph_offset, /* i/o: Phase offset to line up at end of frame */ + float *out, /* o : Waveform Interpolated time domain signal */ + int N, /* i : Number of samples of output to generate */ + int FR_flag /* i : called for post-smoothing in FR */ +); + +void set_ppp_mode( + Encoder_State *st, /* i/o: encoder state structure */ + short *coder_type, /* i/o: coder type */ + const short noisy_speech_HO, /* i : SC-VBR noisy speech HO flag */ + const short clean_speech_HO, /* i : SC-VBR clean speech HO flag */ + const short NB_speech_HO, /* i : SC-VBR NB speech HO flag */ + const short localVAD, + const short localVAD_he, /* i : HE-SAD flag without hangover */ + short *vad_flag, + short T_op[], /* i :open loop pitch lag */ + short sp_aud_decision1 /* i : Speech Audio Decision */ +); + +void lsf_syn_mem_backup( + Encoder_State *st, /* i: state structure */ + LPD_state* LPDmem, /* i: LPD state memory structure */ + float *btilt_code, /* i: tilt code */ + float *bgc_threshold, /* i: */ + float *clip_var_bck, /* o: */ + short *next_force_sf_bck, /* o: */ + float *lsp_new, /* i: LSP vector to quantize */ + float *lsp_mid, /* i: mid-frame LSP vector */ + float *clip_var, /* o: pitch clipping state var */ + float *mem_AR, /* o: quantizer memory for AR model */ + float *mem_MA, /* o: quantizer memory for AR model */ + float *lsp_new_bck, /* o: LSP vector to quantize- backup */ + float *lsp_mid_bck, /* o: mid-frame LSP vector - backup */ + short *mCb1, /* o: counter for stationary frame after a transition frame */ + float *Bin_E, /* o: FFT Bin energy 128 *2 sets */ + float *Bin_E_old, /* o: FFT Bin energy 128 sets */ + float *mem_syn_bck, /* o: synthesis filter memory */ + float *mem_w0_bck, /* o: memory of the weighting filter */ + float *streaklimit, + short *pstreaklen +); + +void lsf_syn_mem_restore( + Encoder_State *st, /* o: state structure */ + LPD_state* LPDmem, /* o: LPD_state vewctor */ + float btilt_code, /* i: */ + float gc_threshold, /* i: */ + float *clip_var_bck, /* i: */ + short next_force_sf_bck, /* i: */ + float *lsp_new, /* o: LSP vector to quantize */ + float *lsp_mid, /* o: mid-frame LSP vector */ + float clip_var, /* i: pitch clipping state var */ + float *mem_AR, /* i: quantizer memory for AR model */ + float *mem_MA, /* i: quantizer memory for AR model */ + float *lsp_new_bck, /* i: LSP vector to quantize- backup */ + float *lsp_mid_bck, /* i: mid-frame LSP vector - backup */ + short mCb1, /* i: counter for stationary frame after a transition frame */ + float *Bin_E, /* i: FFT Bin energy 128 *2 sets */ + float *Bin_E_old, /* i: FFT Bin energy 128 sets */ + float *mem_syn_bck, /* i: synthesis filter memory */ + float mem_w0_bck, /* i: memory of the weighting filter */ + float streaklimit, + short pstreaklen +); +void ppp_voiced_encoder( + Encoder_State *st, /* i/o: state structure */ + float *in, /* i : residual signal */ + float *out, /* o : Quantized residual signal */ + short delay, /* i : open loop pitch */ + float *lpc1, /* i : prev frame de-emphasized LPC */ + float *lpc2, /* i : current frame de-emphasized LPC */ + float *exc, /* i : previous frame quantized excitation */ + float *pitch, /* o : floating pitch values for each subframe */ + float vadsnr /* i : current frame SNR */ +); + +void encod_ppp( + Encoder_State *st, /* i/o: state structure */ + LPD_state *mem, /* i/o: encoder memories */ + const float speech[], /* i : input speech */ + const float Aw[], /* i : weighted A(z) unquantized for subframes */ + const float Aq[], /* i : 12k8 Lp coefficient */ + short *coder_type, /* i/o: coding type */ + const short sharpFlag, /* i : formant sharpening flag */ + const short T_op[], /* i : open loop pitch */ + const float voicing[], /* i : voicing */ + float *res, /* i/o: residual signal */ + float *synth, /* i/o: core synthesis */ + float *exc, /* i/o: current non-enhanced excitation */ + float *exc2, /* i/o: current enhanced excitation */ + float *pitch_buf, /* i/o: floating pitch values for each subframe */ + float *voice_factors, /* o : voicing factors */ + float *bwe_exc /* o : excitation for SWB TBE */ +); + +void reset_rf_indices( + Encoder_State *st /* i: state structure - contains partial RF indices */ +); + +void signalling_enc_rf( + Encoder_State *st /* i/o: encoder state structure */ +); + +void acelp_core_dec( + Decoder_State *st, /* i/o: Decoder state structure */ + float synth_out[], /* o : synthesis */ + float bwe_exc_extended[], /* i/o: bandwidth extended excitation */ + float *voice_factors, /* o : voicing factors */ + float old_syn_12k8_16k[], /* o : intermediate ACELP synthesis at 12.8kHz or 16kHz to be used by SWB BWE */ + short coder_type, /* i : coder type */ + short sharpFlag, /* i : formant sharpening flag */ + float pitch_buf[NB_SUBFR16k], /* o : floating pitch for each subframe */ + short *unbits, /* o : number of unused bits */ + short *sid_bw /* o : 0-NB/WB, 1-SWB SID */ +); + +void bass_psfilter_init( + float old_syn[], /* o : Old synthesis buffer 1 */ + float *mem_deemph_err, /* o : Error deemphasis memory */ + float *lp_ener /* o : long_term error signal energy */ +); + +void bass_psfilter( + const short Opt_AMR_WB, /* i : AMR-WB IO flag */ + const float synth_in[], /* i : synthesis (at 16kHz) */ + const short L_frame, /* i : length of the last frame */ + const float pitch_buf[], /* i : pitch for every subfr [0,1,2,3] */ + float old_syn[], /* i/o: NBPSF_PIT_MAX */ + float *mem_deemph_err, /* o : Error deemphasis memory */ + float *lp_ener, /* o : long_term error signal energy */ + const short bpf_off, /* i : do not use BPF when set to 1 */ + float v_stab, /* i : stability factor */ + float *v_stab_smooth, /* i : smoothed stability factor */ + float *mem_mean_pit, /* i/o: average pitch memory */ + short *Track_on_hist, /* i/o: History of half frame usage */ + short *vibrato_hist, /* i/o: History of frames declared as vibrato*/ + float *psf_att, /* i/o: Post filter attenuation factor */ + const short coder_type, /* i : coder_type */ + float bpf_noise_buf[] /* o : BPF error signal (at int_fs) */ +); + +void CNG_reset_dec( + Decoder_State *st, /* i/o: decoder state structure */ + float *pitch_buf, /* o : floating pitch for each subframe */ + float *voice_factors /* o : voicing factors */ +); + +void updt_dec( + Decoder_State *st, /* i/o: state structure */ + const short L_frame, /* i : length of the frame */ + const short coder_type, /* i : coding type */ + const float *old_exc, /* i : buffer of excitation */ + const float *pitch_buf, /* i : floating pitch values for each subframe */ + const float Es_pred, /* i : predicited scaled innovation energy */ + const float *Aq, /* i : A(z) quantized for all subframes */ + const float *lsf_new, /* i : current frame LSF vector */ + const float *lsp_new, /* i : current frame LSP vector */ + const float voice_factors[], /* i : voicing factors */ + const float *old_bwe_exc, /* i : buffer of excitation */ + const float *gain_buf +); + +void updt_IO_switch_dec( + const short output_frame, /* i : output frame length */ + Decoder_State *st /* i/o: state structure */ +); + +void updt_dec_common( + Decoder_State *st, /* i/o: decoder state structure */ + const short hq_core_type, /* i : HQ core type */ + const float *synth /* i : decoded synthesis */ +); + +void CNG_dec( + Decoder_State *st, /* i/o: State structure */ + const short L_frame, /* i : length of the frame */ + float Aq[], /* o : LP coefficients */ + const long core_brate, /* i : core bitrate */ + float *lsp_new, /* i/o: current frame LSPs */ + float *lsf_new, /* i/o: current frame LSFs */ + short *allow_cn_step, /* o : allow cn step */ + short *sid_bw, /* o : 0-NB/WB, 1-SWB SID */ + float *q_env +); + +void swb_CNG_dec( + Decoder_State *st, /* i/o: State structure */ + const float *synth, /* i : ACELP core synthesis at 32kHz */ + float *shb_synth, /* o : high-band CNG synthesis */ + const short sid_bw /* i : 0-NB/WB, 1-SWB SID */ +); + +void lsf_dec( + Decoder_State *st, /* i/o: State structure */ + const short tc_subfr, /* i : TC subframe index */ + const short L_frame, /* i : length of the frame */ + const short coder_type, /* i : coding type */ + const short bwidth, /* i : input signal bandwidth */ + float *Aq, /* o : quantized A(z) for 4 subframes */ + short *LSF_Q_prediction, /* o : LSF prediction mode */ + float *lsf_new, /* o : de-quantized LSF vector */ + float *lsp_new, /* o : de-quantized LSP vector */ + float *lsp_mid /* o : de-quantized mid-frame LSP vector */ +); + +void isf_dec_amr_wb( + Decoder_State *st, /* i/o: State structure */ + float *Aq, /* o : quantized A(z) for 4 subframes */ + float *isf_new, /* o : de-quantized ISF vector */ + float *isp_new /* o : de-quantized ISP vector */ +); + +void Es_pred_dec( + float *Es_pred, /* o : predicited scaled innovation energy */ + const int enr_idx, /* i : indice */ + const short nb_bits, /* i : number of bits */ + const short no_ltp /* i : no LTP flag */ +); + +void gaus_dec( + Decoder_State *st, /* i/o: decoder state structure */ + const long core_brate, /* i : core bitrate */ + const short i_subfr, /* i : subframe index */ + float *code, /* o : gaussian excitation */ + float *norm_gain_code, /* o : gain of the normalized gaussian excitation */ + float *lp_gainp, /* i/o: lp filtered pitch gain(FER) */ + float *lp_gainc, /* i/o: lp filtered code gain (FER) */ + float *gain_inov, /* o : unscaled innovation gain */ + float *tilt_code, /* o : synthesis excitation spectrum tilt */ + float *voice_fac, /* o : estimated voicing factor */ + float *gain_pit, /* o : reset pitch gain */ + float *pt_pitch, /* o : reset floating pitch buffer */ + float *exc, /* o : excitation signal frame */ + float *gain_code, /* o : gain of the gaussian excitation */ + float *exc2 /* o : scaled excitation signal frame */ +); + +void gain_dec_amr_wb( + Decoder_State *st, /* i/o: decoder state structure */ + const long core_brate, /* i : core bitrate */ + float *gain_pit, /* o : Quantized pitch gain */ + float *gain_code, /* o : Quantized codeebook gain */ + float *past_qua_en, /* i/o: gain quantization memory (4 words) */ + float *gain_inov, /* o : unscaled innovation gain */ + const float *code, /* i : algebraic code excitation */ + float *norm_gain_code /* o : norm. gain of the codebook excitation */ +); + +void gain_dec_lbr( + Decoder_State *st, /* i/o: decoder state structure */ + const long core_brate, /* i : core bitrate */ + const short coder_type, /* i : coding type */ + const short i_subfr, /* i : subframe index */ + const float *code, /* i : algebraic excitation */ + float *gain_pit, /* o : quantized pitch gain */ + float *gain_code, /* o : quantized codebook gain */ + float *gain_inov, /* o : gain of the innovation (used for normalization) */ + float *norm_gain_code, /* o : norm. gain of the codebook excitation */ + float gains_mem[] /* i/o: pitch gain and code gain from previous subframes */ +); + +void gain_dec_mless( + Decoder_State *st, /* i/o: decoder state structure */ + const long core_brate, /* i : core bitrate */ + const short L_frame, /* i : length of the frame */ + const short coder_type, /* i : coding type */ + const short i_subfr, /* i : subframe number */ + const short tc_subfr, /* i : TC subframe index */ + const float *code, /* i : algebraic code excitation */ + const float Es_pred, /* i : predicted scaled innov. energy */ + float *gain_pit, /* o : Quantized pitch gain */ + float *gain_code, /* o : Quantized codeebook gain */ + float *gain_inov, /* o : unscaled innovation gain */ + float *norm_gain_code /* o : norm. gain of the codebook excitation */ +); + +void gain_dec_SQ( + Decoder_State *st, /* i/o: decoder state structure */ + const long core_brate, /* i : core bitrate */ + const short coder_type, /* i : coding type */ + const short i_subfr, /* i : subframe number */ + const short tc_subfr, /* i : TC subframe index */ + const float *code, /* i : algebraic code excitation */ + const float Es_pred, /* i : predicted scaled innov. energy */ + float *gain_pit, /* o : Quantized pitch gain */ + float *gain_code, /* o : Quantized codeebook gain */ + float *gain_inov, /* o : unscaled innovation gain */ + float *norm_gain_code /* o : norm. gain of the codebook excitation */ +); + +float gain_dec_gaus( /* o : quantized codebook gain */ + const short index, /* i : quantization index */ + const short bits, /* i : number of bits to quantize */ + const float lowBound, /* i : lower bound of quantizer (dB) */ + const float topBound, /* i : upper bound of quantizer (dB) */ + const float gain_inov, /* i : unscaled innovation gain */ + float *norm_gain_code /* o : gain of normalized gaus. excit. */ +); + +float pit_decode( /* o : floating pitch value */ + Decoder_State *st, /* i/o: decoder state structure */ + const long core_brate, /* i : core bitrate */ + const short Opt_AMR_WB, /* i : flag indicating AMR-WB IO mode */ + const short L_frame, /* i : length of the frame */ + short i_subfr, /* i : subframe index */ + const short coder_type, /* i : coding type */ + short *limit_flag, /* i/o: restrained(0) or extended(1) Q limits */ + short *T0, /* o : close loop integer pitch */ + short *T0_frac, /* o : close loop fractional part of the pitch */ + short *T0_min, /* i/o: delta search min for sf 2 & 4 */ + short *T0_max, /* i/o: delta search max for sf 2 & 4 */ + const short L_subfr /* i : subframe length */ +); + +void abs_pit_dec( + const short fr_steps, /* i : fractional resolution steps (0, 2, 4) */ + short pitch_index, /* i : pitch index */ + const short limit_flag, /* i : restrained(0) or extended(1) Q limits */ + short *T0, /* o : integer pitch lag */ + short *T0_frac /* o : pitch fraction */ +); + +void delta_pit_dec( + const short fr_steps, /* i : fractional resolution steps (0, 2, 4) */ + const short pitch_index, /* i : pitch index */ + short *T0, /* o : integer pitch lag */ + short *T0_frac, /* o : pitch fraction */ + const short T0_min /* i : delta search min */ +); + +void pit_Q_dec( + const short Opt_AMR_WB, /* i : flag indicating AMR-WB IO mode */ + const short pitch_index, /* i : pitch index */ + const short nBits, /* i : # of Q bits */ + const short delta, /* i : Half the CL searched interval */ + const short pit_flag, /* i : absolute(0) or delta(1) pitch Q */ + const short limit_flag, /* i : restrained(0) or extended(1) Q limits */ + short *T0, /* o : integer pitch lag */ + short *T0_frac, /* o : pitch fraction */ + short *T0_min, /* i/o: delta search min */ + short *T0_max /* i/o: delta search max */ + ,short *BER_detect /* o : BER detect flag */ +); + +void pit16k_Q_dec( + const short pitch_index, /* i : pitch index */ + const short nBits, /* i : # of Q bits */ + const short limit_flag, /* i : restrained(0) or extended(1) Q limits */ + short *T0, /* o : integer pitch lag */ + short *T0_frac, /* o : pitch fraction */ + short *T0_min, /* i/o: delta search min */ + short *T0_max /* i/o: delta search max */ + ,short *BER_detect /* o : BER detect flag */ +); + +void lp_filt_exc_dec( + Decoder_State *st, /* i/o: decoder state structure */ + const short codec_mode, /* i : codec mode */ + const long core_brate, /* i : core bitrate */ + const short Opt_AMR_WB, /* i : flag indicating AMR-WB IO mode */ + const short coder_type, /* i : coding type */ + const short i_subfr, /* i : subframe index */ + const short L_subfr, /* i : subframe size */ + const short L_Frame, /* i : frame size */ + short lp_flag, /* i : operation mode signalling */ + float *exc /* i/o: pointer to the excitation signal frame */ +); + +void inov_decode( + Decoder_State *st, /* i/o: decoder state structure */ + const long core_brate, /* i : core bitrate */ + const short Opt_AMR_WB, /* i : flag indicating AMR-WB IO mode */ + const short L_frame, /* i : length of the frame */ + const short coder_type, /* i : coding type */ + const short sharpFlag, /* i : formant sharpening flag */ + const short i_subfr, /* i : subframe index */ + const short tc_subfr, /* i : TC subframe index */ + const float *p_Aq, /* i : LP filter coefficients */ + const float tilt_code, /* i : tilt of of the excitation of previous subframe */ + const float pt_pitch, /* i : pointer to current subframe fractional pitch */ + float *code /* o : algebraic excitation */ +); + +void dec_acelp_1t64( + Decoder_State *st, /* i/o: decoder state structure */ + float code[] /* o : algebraic (fixed) codebook excitation */ +); + +void dec_acelp_2t32( + Decoder_State *st, /* i/o: decoder state structure */ + float code[] /* o : algebraic (fixed) codebook excitation */ +); + +void dec_acelp_4t64( + Decoder_State *st, /* i/o: decoder state structure */ + short nbbits, /* i : number of bits per codebook */ + float code[], /* o : algebraic (fixed) codebook excitation */ + const short Opt_AMR_WB /* i : flag indicating AMR-WB IO mode */ +); + +unsigned int syn_output( + float *synth, /* i/o: float synthesis signal */ + const short output_frame, /* i : output frame length */ + short *synth_out /* o : integer 16 bits synthesis signal */ +); + +void FEC_exc_estim( + Decoder_State *st, /* i/o: Decoder static memory */ + const short L_frame, /* i : length of the frame */ + float *old_exc, /* i/o: excitation buffer */ + float *exc2, /* o : excitation buffer (for synthesis) */ + float *exc_dct_in, /* o : GSC excitation in DCT domain */ + float *pitch_buf, /* o : Floating pitch for each subframe */ + float *tmp_tc, /* o : FEC pitch */ + float *voice_factors, /* o : voicing factors */ + float *bwe_exc, /* i/o: excitation for SWB TBE */ + float *lsf_new, /* i : ISFs at the end of the frame */ + float *tmp_noise /* o : long-term noise energy */ +); + +void FEC_lsf2lsp_interp( + Decoder_State *st, /* i/o: Decoder static memory */ + const short L_frame, /* i : length of the frame */ + float *Aq, /* o : calculated A(z) for 4 subframes */ + float *lsf, /* o : estimated LSF vector */ + float *lsp /* o : estimated LSP vector */ +); + +void FEC_lsf_estim_enc( + Encoder_State *st, /* i : Encoder static memory */ + const short L_frame, /* i : length of the frame */ + float *lsf /* o : estimated LSF vector */ +); + +float frame_energy( + const short L_frame, /* i : length of the frame */ + const float *pitch, /* i : pitch values for each subframe */ + const float *speech, /* i : pointer to speech signal for E computation */ + const float lp_speech, /* i : long term active speech energy average */ + float *frame_ener /* o : pitch-synchronous energy at frame end */ +); + +void FEC_SinOnset( + float *exc, /* i/o : exc vector to modify */ + short puls_pos, /* i : Last pulse position desired */ + short T0, /* i : decoded first frame pitch */ + float enr_q, /* i : energy provide by the encoder */ + float *Aq, /* i : Lsp coefficient */ + const short L_frame /* i : Frame lenght */ +); + +short FEC_enhACB( + const short L_frame, /* i : Frame lenght */ + const short last_L_frame, /* i : frame length of last frame */ + float *exc_io, /* i/o : Adaptive codebook memory */ + const short new_pit, /* i : decoded first frame pitch */ + const short puls_pos, /* i : decoder position of the last glottal pulses decoded in the previous frame */ + const float bfi_pitch /* i : Pitch used for concealment */ +); + +void FEC_scale_syn( + const short L_frame, /* i : length of the frame */ + short clas, /* i/o: frame classification */ + const short last_good, /* i : last good frame classification */ + float *synth, /* i/o: synthesized speech at Fs = 12k8 Hz */ + const float *pitch, /* i : pitch values for each subframe */ + float enr_old, /* i : energy at the end of prvious frame */ + float enr_q, /* i : transmitted energy for current frame */ + const short coder_type, /* i : coding type */ + const short LSF_Q_prediction, /* i : LSF prediction mode */ + short *scaling_flag, /* i/o: flag to indicate energy control of syn */ + float *lp_ener_FEC_av, /* i/o: averaged voiced signal energy */ + float *lp_ener_FEC_max, /* i/o: averaged voiced signal energy */ + const short bfi, /* i: current frame BFI */ + const long total_brate, /* i: total bitrate */ + const short prev_bfi, /* i : previous frame BFI */ + const long last_core_brate, /* i : previous frame core bitrate */ + float *exc, /* i/o: excitation signal without enhancement */ + float *exc2, /* i/o: excitation signal with enhancement */ + const float Aq[], /* i : LP filter coefs */ + float *old_enr_LP, /* i/o: LP filter E of last good voiced frame */ + const float *mem_tmp, /* i : temp. initial synthesis filter states */ + float *mem_syn /* o : initial synthesis filter states */ + , int avoid_lpc_burst_on_recovery /* i : if true the excitation energy is limited if LP has big gain */ + , short force_scaling /* i: force scaling */ +); + +void FEC_pitch_estim( + const short Opt_AMR_WB, /* i : flag indicating AMR-WB IO mode */ + const short last_core, /* i : last core */ + const short L_frame, /* i : length of the frame */ + const short clas, /* i : current frame classification */ + const short last_good, /* i : last good clas information */ + const float pitch_buf[], /* i : Floating pitch for each subframe */ + const float old_pitch_buf[], /* i : buffer of old subframe pitch values */ + float *bfi_pitch, /* i/o: update of the estimated pitch for FEC */ + short *bfi_pitch_frame, /* o : frame length when pitch was updated */ + short *upd_cnt, /* i/o: update counter */ + const short coder_type +); + +void FEC_encode( + Encoder_State *st, /* i/o: encoder state structure */ + const float *synth, /* i : pointer to synthesized speech for E computation */ + const short coder_type, /* i : type of coder */ + short clas, /* i : signal clas for current frame */ + const float *fpit, /* i : close loop fractional pitch buffer */ + const float *res, /* i : LP residual signal frame */ + short *last_pulse_pos, /* i/o: Position of the last pulse */ + const short L_frame, /* i : Frame length */ + const long total_brate, /* i : total codec bitrate */ + const long core_brate /* i : core codec bitrate */ +); + +short FEC_pos_dec( + Decoder_State *st, /* i/o: decoder state structure */ + const short coder_type, /* i : coder type */ + const short last_good, /* i : Last good classfication */ + short *last_pulse_pos, /* o : Last glotal pulse position in the lost ACB */ + short *clas, /* o : Decoded classification */ + float *enr_q, /* o : Decoded energy */ + const long core_brate /* i : Decoded bitrate */ +); + +void improv_amr_wb_gs( + const short clas, /* i : bitrate allocated to the core */ + const short coder_type, /* i : coder_type */ + const long core_brate, /* i : bitrate allocated to the core */ + short *seed_tcx, /* i/o: Seed used for noise generation */ + float *old_Aq, /* i/o: old LPC filter coefficient */ + float *mem_syn2, /* i/o: synthesis memory */ + const float lt_voice_fac, /* i/o: long term voice factor */ + const short locattack, /* i : Flag for a detected attack */ + float *Aq, /* i/o: Decoded LP filter coefficient */ + float *exc2, /* i/o: Decoded complete excitation */ + float *mem_tmp, /* i/o: synthesis temporary memory */ + float *syn, /* i/o: Decoded synthesis to be updated */ + const float *pitch_buf, /* i : Decoded pitch buffer */ + const float Last_ener /* i : Last energy */ + ,const short rate_switching_reset /* i : rate switching reset flag */ + ,const short last_coder_type /* i : Last coder_type */ +); + +short tc_classif( + Decoder_State *st, /* i/o: decoder state structure */ + const short L_frame /* i : length of the frame */ +); + +void transition_dec( + Decoder_State *st, /* i/o: decoder state structure */ + const long core_brate, /* i : core bitrate */ + const short Opt_AMR_WB, /* i : flag indicating AMR-WB IO mode */ + const short L_frame, /* i : length of the frame */ + const short i_subfr, /* i : subframe index */ + const short coder_type, /* i : coding type */ + const short tc_subfr, /* i : TC subframe index */ + short *Jopt_flag, /* i : joint optimization flag */ + float *exc, /* i/o: current frame excitation signal */ + short *T0, /* o : close loop integer pitch */ + short *T0_frac, /* o : close loop fractional part of the pitch */ + short *T0_min, /* i/o: delta search min for sf 2 & 4 */ + short *T0_max, /* i/o: delta search max for sf 2 & 4 */ + float **pt_pitch, /* o : floating pitch values */ + short *position, /* i/o: first glottal impulse position in frame */ + float *bwe_exc /* i/o: excitation for SWB TBE */ +); + +void gain_dec_tc( + Decoder_State *st, /* i/o: decoder state structure */ + const long core_brate, /* i : core bitrate */ + const short L_frame, /* i : length of the frame */ + const short i_subfr, /* i : subframe number */ + const short tc_subfr, /* i : TC subframe index */ + const float Es_pred, /* i : predicted scaled innov. energy */ + const float *code, /* i : algebraic code excitation */ + float *gain_pit, /* o : pitch gain */ + float *gain_code, /* o : Quantized codeebook gain */ + float *gain_inov, /* o : unscaled innovation gain */ + float *norm_gain_code /* o : norm. gain of the codebook excit. */ +); + +void stat_noise_uv_dec( + Decoder_State *st, /* i/o: decoder static memory */ + const short coder_type, /* i : coding type */ + float *lsp_new, /* i : end-frame LSP vector */ + float *lsp_mid, /* i : mid-frame LSP vector */ + float *Aq, /* o : A(z) quantized for the 4 subframes */ + float *exc2 /* i/o: excitation buffer */ +); + +void decod_nelp( + Decoder_State *st, /* i/o: decoder static memory */ + const short coder_type, /* i : coding type */ + float *tmp_noise, /* o : long term temporary noise energy */ + float *pitch_buf, /* o : floating pitch values for each subframe */ + float *exc, /* o : adapt. excitation exc */ + float *exc2, /* o : adapt. excitation/total exc */ + float *voice_factors, /* o : voicing factors */ + float *bwe_exc, /* o : excitation for SWB TBE */ + const short bfi, /* i : bad frame indicator */ + float *gain_buf +); + +void nelp_decoder( + Decoder_State *st, /* i/o: decoder static memory */ + float *exc_nelp, /* o : adapt. excitation/total exc */ + float *exc, /* o : adapt. excitation exc */ + short bfi, /* i : frame error rate */ + const short coder_type, /* i : coding type */ + float *gain_buf +); + +void decod_ppp( + Decoder_State *st, /* i/o: state structure */ + const float Aq[], /* i : 12k8 Lp coefficient */ + float *pitch_buf, /* i/o: floating pitch values for each subframe */ + float *exc, /* i/o: current non-enhanced excitation */ + float *exc2, /* i/o: current enhanced excitation */ + float *voice_factors, /* o : voicing factors */ + float *bwe_exc, /* o : excitation for SWB TBE */ + float *gain_buf + , short bfi +); + +void ppp_quarter_decoder( + Decoder_State *st, /* i/o: decoder state structure */ + DTFS_STRUCTURE *CURRCW_Q_DTFS, /* i/o: Current CW DTFS */ + int prevCW_lag, /* i : Previous lag */ + float *lastLgainD, /* i/o: Last gain lowband */ + float *lastHgainD, /* i/o: Last gain highwband */ + float *lasterbD, /* i/o: Last ERB vector */ + short bfi, /* i : FER flag */ + DTFS_STRUCTURE PREV_CW_D /* i : Previous DTFS */ +); + +void ppp_voiced_decoder( + Decoder_State *st, /* i/o: state structure */ + float *out, /* o : residual signal */ + const float *lpc2, /* i : current frame LPC */ + float *exc, /* i : previous frame excitation */ + float *pitch /* o : floating pitch values for each subframe */ + ,short bfi +); + +void AVQ_demuxdec( + Decoder_State *st, /* i/o: decoder state structure */ + int xriq[], /* o: decoded subvectors [0..8*Nsv-1] */ + short *nb_bits, /* i/o: number of allocated bits */ + const short Nsv, /* i: number of subvectors */ + short nq_out[] /* i/o: AVQ nq index */ +); + +void re8_dec( + int nq, + long I, + int kv[], + int y[] +); + +void re8_decode_base_index( + int n, /* i : codebook number (*n is an integer defined in {0,2,3,4,..,n_max}) */ + long I, /* i : index of c (pointer to unsigned 16-bit word) */ + int *x /* o : point in RE8 (8-dimensional integer vector) */ +); + +void Init_post_filter( + PFSTAT *pfstat /* i : post-filter state memories */ +); + +void nb_post_filt( + const short L_frame, /* i : frame length */ + const short L_subfr, /* i : sub-frame length */ + PFSTAT *pfstat, /* i/o: Post filter related memories */ + float *lp_noise, /* i/o: long term noise energy */ + const float tmp_noise, /* i : noise energy */ + float *synth, /* i/o: synthesis */ + const float *Aq, /* i : LP filter coefficient */ + const float *pitch_buf, /* i : Floating pitch for each subframe */ + const short coder_type, /* i : coder_type -> deactivated in AUDIO */ + const short BER_detect, /* i : BER detect flag */ + const short disable_hpf /* i : flag to diabled HPF */ +); + +void decod_unvoiced( + Decoder_State *st, /* i/o: decoder static memory */ + const float *Aq, /* i : LP filter coefficient */ + const short coder_type, /* i : coding type */ + float *tmp_noise, /* o : long term temporary noise energy */ + float *pitch_buf, /* o : floating pitch values for each subframe */ + float *voice_factors, /* o : voicing factors */ + float *exc, /* o : adapt. excitation exc */ + float *exc2, /* o : adapt. excitation/total exc */ + float *bwe_exc, /* i/o: excitation for SWB TBE */ + float *gain_buf +); + +void decod_tran( + Decoder_State *st, /* i/o: decoder static memory */ + const short L_frame, /* i : length of the frame */ + const short tc_subfr, /* i : TC subframe index */ + const float *Aq, /* i : LP filter coefficient */ + const short coder_type, /* i : coding type */ + const float Es_pred, /* i : predicted scaled innov. energy */ + float *pitch_buf, /* o : floating pitch values for each subframe */ + float *voice_factors, /* o : voicing factors */ + float *exc, /* i/o: adapt. excitation exc */ + float *exc2, /* i/o: adapt. excitation/total exc */ + float *bwe_exc, /* i/o: excitation for SWB TBE */ + short *unbits, /* i/o: number of unused bits */ + const short sharpFlag, /* i : formant sharpening flag */ + float *gain_buf +); + +void decod_gen_voic( + Decoder_State *st, /* i/o: decoder static memory */ + const short L_frame, /* i : length of the frame */ + const short sharpFlag, /* i : formant sharpening flag */ + const float *Aq, /* i : LP filter coefficient */ + const short coder_type, /* i : coding type */ + const float Es_pred, /* i : predicted scaled innov. energy */ + const short do_WI, /* i : FEC fast recovery flag */ + float *pitch_buf, /* o : floating pitch for each subframe */ + float *voice_factors, /* o : voicing factors */ + float *exc, /* i/o: adapt. excitation exc */ + float *exc2, /* i/o: adapt. excitation/total exc */ + float *bwe_exc, /* i/o: excitation for SWB TBE */ + short *unbits, /* i/o: number of unused bits */ + float *gain_buf +); + +void decod_amr_wb( + Decoder_State *st, /* i/o: decoder static memory */ + const float *Aq, /* i : LP filter coefficients */ + float *pitch_buf, /* o : floating pitch values for each subframe */ + float *exc, /* i/o: adapt. excitation exc */ + float *exc2, /* i/o: adapt. excitation/total exc */ + short *hf_gain, /* o : decoded HF gain */ + float *voice_factors, /* o : voicing factors */ + float *gain_buf +); + +void io_ini_dec( + const int argc, /* i : command line arguments number */ + char *argv[], /* i : command line arguments */ + FILE **f_stream, /* o : input bitstream file */ + FILE **f_synth, /* o : output synthesis file */ + short *quietMode, /* o : limited printouts */ + short *noDelayCmp, /* o : turn off delay compensation */ + Decoder_State *st, /* o : Decoder static variables structure */ +#ifdef SUPPORT_JBM_TRACEFILE + char **jbmTraceFileName, /* o : VOIP tracefilename */ +#endif + char **jbmFECoffsetFileName /* o : Output file for Optimum FEC offset */ +); + +void init_decoder( + Decoder_State *st /* o : Decoder static variables structure */ +); + +void destroy_decoder( + Decoder_State *st /* o : Decoder static variables structure */ +); + +void evs_dec( + Decoder_State *st, /* i/o: Decoder state structure */ + float *output, /* o : output synthesis signal */ + frameMode frameMode /* i : Decoder frame mode */ +); + +int decodeVoip( + Decoder_State *st, + FILE *f_stream, + FILE *f_synth, +#ifdef SUPPORT_JBM_TRACEFILE + const char *jbmTraceFileName, +#endif + const char *jbmFECoffsetFileName, /* : Output file for Optimum FEC offset */ + const short quietMode +); + +void get_next_frame_parameters( + Decoder_State *st /* i/o: Decoder state structure */ +); + +void amr_wb_dec( + Decoder_State *st, /* i/o: decoder state structure */ + float *output_sp /* o : synthesis output */ +); + +void transf_cdbk_dec( + Decoder_State *st, /* i/o: decoder state structure */ + const long core_brate, /* i : core bitrate */ + const short coder_type, /* i : coding type */ + const short harm_flag_acelp, /* i : harmonic flag for higher rates ACELP */ + const short i_subfr, /* i : subframe index */ + const short tc_subfr, /* i : TC subframe index */ + const float Es_pred, /* i : predicited scaled innovation energy */ + const float gain_code, /* i : innovative excitation gain */ + float *mem_preemp_preQ, /* i/o: prequantizer preemhasis memory */ + float *gain_preQ, /* o : prequantizer excitation gain */ + float *norm_gain_preQ, /* o : normalized prequantizer excitation gain */ + float code_preQ[], /* o : prequantizer excitation */ + short *unbits /* o : number of AVQ unused bits */ +); + +float gain_dequant( /* o: decoded gain */ + short index, /* i: quantization index */ + const float min, /* i: value of lower limit */ + const float max, /* i: value of upper limit */ + const short bits /* i: number of bits to dequantize */ +); + +void hq_core_enc( + Encoder_State *st, /* i/o: encoder state structure */ + const float *audio, /* i : input audio signal */ + const short input_frame, /* i : frame length */ + const short hq_core_type, /* i : HQ core type */ + const short Voicing_flag +); + +short detect_transient( + const float *in, /* i : input signal */ + Encoder_State *st, /* i/o: encoder state structure */ + const short L, /* i : length */ + const short coder_type /* i : coding type */ +); + +void wtda( + const float *new_audio, /* i : input audio */ + float *wtda_audio, /* o : windowed audio */ + float *old_wtda, /* i/o: windowed audio from previous frame */ + const short left_mode, + const short right_mode, /* window overlap of current frame (0: full, 2: none, or 3: half) */ + const short L /* i : length */ +); + + +void tcx_get_windows_mode1( + const short left_mode, /* i: overlap mode of left window half */ + const short right_mode, /* i: overlap mode of right window half */ + float *left_win, /* o: left overlap window */ + float *right_win, /* o: right overlap window */ + float *left_win_int, /* o: left overlap window */ + float *right_win_int, /* o: right overlap window */ + short const L +); + +void direct_transform( + const float *in32, /* i : input signal */ + float *out32, /* o : output transformation */ + const short is_transient, /* i : transient flag */ + const short L /* i : length */ +); + +short noise_adjust( /* o : index of noise attenuation */ + const float *coeffs_norm, /* i : normalized coefficients */ + const short *bitalloc, /* i : bit allocation */ + const short *sfm_start, /* i : Start of bands */ + const short *sfm_end, /* i : End of bands */ + const short core_sfm /* i : index of the end band for core */ +); + +void interleave_spectrum( + float *coefs, /* i/o: input and output coefficients */ + const short length /* i : length of spectrum */ +); + +void hq_hr_enc( + Encoder_State *st, /* i/o: encoder state structure */ + float *coefs, /* i/o: transform-domain coefficients */ + const short length, /* i : length of spectrum */ + short *num_bits, /* i : number of available bits */ + const short is_transient /* i : transient flag */ +); + +void logqnorm( + const float *x, /* i : coefficient vector */ + short *k, /* o : index */ + const short L, /* i : codebook length */ + const short N, /* i : sub-vector size */ + const float *thren +); + +void huff_dec( + Decoder_State *st, /* i/o: decoder state structure */ + const short N, /* i : Number of codewords to decode */ + const short buffer_len, /* i : Number of bits to read */ + const short num_lengths, /* i : Number of different huffman codeword lengths */ + const short *thres, /* i : Threshold of first codeword of each length */ + const short *offset, /* i : Offset for first codeword */ + const short *huff_tab, /* i : Huffman table order by codeword lengths */ + short *index /* o : Decoded index */ +); + +void calc_norm( + const float *x, /* i : Input vector. */ + short *norm, /* o : Quantization indices for norms */ + short *normlg, /* o : Quantized norms in log2 */ + const short start_band, /* i : Indice of band to start coding */ + const short num_bands, /* i : Number of bands */ + const short *band_len, /* i : Length of bands */ + const short *band_start /* i : Start of bands */ +); + +void reordernorm( + const short *ynrm, /* i : quantization indices for norms */ + const short *normqlg2, /* i : quantized norms */ + short *idxbuf, /* o : reordered quantization indices */ + short *normbuf, /* o : reordered quantized norms */ + const short nb_sfm /* i : number of bands */ +); + +void diffcod( + const short N, /* i : number of sub-vectors */ + short *y, /* i/o: indices of quantized norms */ + short *difidx /* o : differential code */ +); + +void diffcod_lrmdct( + const short N, + const int be_ref, + int *y, + int *difidx, + const short is_transient +); + +void normalizecoefs( + float *coefs, /* i/o: MDCT coefficients */ + const short *ynrm, /* i : quantization indices for norms */ + const short num_bands, /* i : Number of bands */ + const short *band_start, /* i : Start of bands */ + const short *band_end /* i : End of bands */ +); + +void bitallocsum( + short *R, /* i : bit-allocation vector */ + const short nb_sfm, /* i : number of sub-vectors */ + short *sum, /* o : total number of bits allocated */ + short *Rsubband, /* o : rate per subband (Q3) */ + const short v, /* i : bit rate */ + const short length, /* i : length of spectrum */ + const short *sfmsize /* i : Length of bands */ +); + +void hq_generic_hf_encoding( + const float *coefs, /* i : MDCT coefficients of weighted original */ + float *hq_generic_fenv, /* i/o: energy of SWB envelope */ + const short hq_generic_offset, /* i : frequency offset for extracting energy */ + Encoder_State *st, /* i/o: encoder state structure */ + short *hq_generic_clas /* o : bwe excitation class */ +); + +short swb_bwe_gain_deq( /* o : BWE class */ + Decoder_State *st, /* i/o: decoder state structure */ + const short core, /* i : core */ + float *SWB_tenv, /* o : time-domain BWE envelope */ + float *SWB_fenv, /* o : frequency-domain BWE envelope */ + const short hr_flag, /* i : high rate flag */ + const short hqswb_clas /* i : HQ BWE class */ +); + +void save_old_syn( + const short L_frame, /* i : frame length */ + const float syn[], /* i : ACELP synthesis */ + float old_syn[], /* o : old synthesis buffer */ + float old_syn_12k8_16k[], /* i/o: old synthesis buffer */ + const float preemph_fac, /* i : preemphasis factor */ + float *mem_deemph /* i/o: deemphasis filter memory */ +); + +void hq_generic_hf_decoding( + const short HQ_mode, /* i : HQ mode */ + float *coeff_out1, /* i/o : BWE input & temporary buffer */ + const float *hq_generic_fenv, /* i : SWB frequency envelopes */ + float *coeff_out, /* o : SWB signal in MDCT domain */ + const short hq_generic_offset, /* i : frequency offset for representing hq swb bwe*/ + short *prev_L_swb_norm, /* i/o: last normalize length */ + const short hq_swb_bwe_exc_clas, /* i : bwe excitation class */ + const short *R +); + +void hq_core_dec( + Decoder_State *st, /* i/o: decoder state structure */ + float out[], /* o : output synthesis */ + const short output_frame, /* i : output frame length */ + const short hq_core_type, /* i : HQ core type */ + const short core_switching_flag /* i : ACELP->HQ switching frame flag */ +); + +void hq_hr_dec( + Decoder_State *st, /* i/o: decoder state structure */ + float *coefsq, /* o : transform-domain coefficients */ + const short length, /* i : frame length */ + short num_bits, /* i : number of available bits */ + short *ynrm, /* o : norm quantization index vector */ + short *is_transient, /* o : transient flag */ + short *hqswb_clas, /* o : HQ SWB class */ + float *SWB_fenv /* o : SWB frequency envelopes */ +); + +void hdecnrm_context( + Decoder_State *st, /* i/o: decoder state structure */ + const short N, /* i : number of norms */ + short *index, /* o : indices of quantized norms */ + short *n_length /* o : decoded stream length */ +); + +void hdecnrm_tran( + Decoder_State *st, /* i/o: decoder state structure */ + const short N, + short *index +); + +void hdecnrm_resize( + Decoder_State *st, /* i/o: decoder state structure */ + const short N, /* i :number of SFMs */ + short *index /* o : norm quantization index vector */ +); + +void hdecnrm( + Decoder_State *st, /* i/o: decoder state structure */ + const short N, /* i : number of norms */ + short *index /* o : indices of quantized norms */ +); + +short find_last_band( /* o : index of last band */ + const short *bitalloc, /* i : bit allocation */ + const short nb_sfm /* i : number of possibly coded bands */ +); + +void fill_spectrum( + float *coeff, /* i/o: normalized MLT spectrum / nf spectrum */ + short *R, /* i : number of pulses per band */ + const short is_transient, /* i : transient flag */ + short norm[], /* i : quantization indices for norms */ + const float *hq_generic_fenv, /* i : HQ GENERIC envelope */ + const short hq_generic_offset, /* i : HQ GENERIC offset */ + const short nf_idx, /* i : noise fill index */ + const short length, /* i : Length of spectrum (32 or 48 kHz) */ + const float env_stab, /* i : Envelope stability measure [0..1] */ + short *no_att_hangover, /* i/o: Frame counter for attenuation hangover */ + float *energy_lt, /* i/o: Long-term energy measure for transient detection */ + short *bwe_seed, /* i/o: random seed for generating BWE input */ + const short hq_generic_exc_clas, /* i : HF excitation class */ + const short core_sfm, /* i : index of the end band for core */ + short HQ_mode, /* i : HQ mode */ + float noise_level[], /* i : noise level for harmonic modes */ + long core_brate, /* i : target bit-rate */ + float prev_noise_level[], /* i/o: noise factor in previous frame */ + short *prev_R, /* i/o: bit allocation info. in previous frame */ + float *prev_coeff_out, /* i/o: decoded spectrum in previous frame */ + const short *peak_idx, /* i : peak positions */ + const short Npeaks, /* i : number of peaks */ + const short *npulses, /* i : Number of assigned pulses per band */ + short prev_is_transient, + float *prev_normq, + float *prev_env, + short prev_bfi, + const short *sfmsize, /* i : Length of bands */ + const short *sfm_start, /* i : Start of bands */ + const short *sfm_end, /* i : End of bands */ + short *prev_L_swb_norm, + short prev_hq_mode, + const short num_sfm, + const short num_env_bands +); + +void env_stab_transient_detect( + const short is_transient, /* i: Transient flag */ + const short length, /* i : Length of spectrum (32 or 48 kHz) */ + const short norm[], /* i : quantization indices for norms */ + short *no_att_hangover, /* i/o: Frame counter for attenuation hangover */ + float *energy_lt, /* i/o: Long-term energy measure for transient detection */ + const short HQ_mode, /* i : HQ coding mode */ + const short bin_th, /* i : HVQ cross-over frequency bin */ + const float *coeff /* i : Coded spectral coefficients */ +); + +void de_interleave_spectrum( + float *coefs, /* i/o: input and output coefficients */ + short length /* i : length of spectrum */ +); + +void inverse_transform( + const float *InMDCT, /* i : input MDCT vector */ + float *Out, /* o : output vector */ + const short IsTransient, /* i : transient flag */ + const short L, /* i : output frame length */ + const short L_inner /* i : length of the transform */ +); + +void window_ola( + const float *ImdctOut, /* i : input */ + float *auOut, /* o : output audio */ + float *OldauOut, /* i/o: audio from previous frame */ + const short L, /* i : length */ + const short left_mode, + const short right_mode, /* window overlap of current frame (0: full, 2: none, or 3: half) */ + const short use_bfi_win, /* i : use BFI windowing */ + const short oldHqVoicing, /* i : previous HqVoicing */ + float *oldgapsynth /* i : previous gapsynth */ +); + +void map_quant_weight( + const short normqlg2[], /* i : quantized norms */ + short wnorm[], /* o : weighted norm */ + const short is_transient /* i : transient flag */ +); + +void recovernorm( + short *idxbuf, /* i : reordered quantization indices */ + short *ynrm, /* o : recovered quantization indices */ + short *normqlg2, /* o : recovered quantized norms */ + short nb_sfm /* i : number of SFMs */ +); + +void reordvct( + short *y, /* i/o: vector to rearrange */ + short N, /* i : dimensions */ + short *idx /* o : reordered vector index */ +); + +void bitalloc( + short *y, /* i : reordered norm of sub-vectors */ + short *idx, /* i : reordered sub-vector indices */ + short sum, /* i : number of available bits */ + short N, /* i : number of norms */ + short K, /* i : maximum number of bits per dimension */ + short *r, /* o : bit-allacation vector */ + const short *sfmsize, /* i : Length of bands */ + const short hqswb_clas /* i : signal classification flag */ +); + +short BitAllocF( + short *y, /* i : norm of sub-vectors */ + long bit_rate, /* i : bitrate */ + short B, /* i : number of available bits */ + short N, /* i : number of sub-vectors */ + short *R, /* o : bit-allocation indicator */ + short *Rsubband, /* o : sub-band bit-allocation vector (Q3) */ + const short hqswb_clas, /* i : hq swb class */ + const short num_env_bands /* i : Number sub bands to be encoded for HQ_SWB_BWE */ +); + +short BitAllocWB( + short *y, + short B, + short N, + short *R, + short *Rsubband +); + +short hvq_pvq_bitalloc( + short num_bits, /* i/o: Number of available bits (including gain bits) */ + const short brate, /* i : bitrate */ + const short bwidth, /* i : Encoded bandwidth */ + const short *ynrm, /* i : Envelope coefficients */ + const int manE_peak, /* i : Peak energy mantissa */ + const short expE_peak, /* i : Peak energy exponent */ + short *Rk, /* o : bit allocation for concatenated vector */ + short *R, /* i/o: Global bit allocation */ + short *sel_bands, /* o : Selected bands for encoding */ + short *n_sel_bands /* o : No. of selected bands for encoding */ +); + +void floating_point_add( + int *mx, /* io: mantissa of the addend Q31 */ + short *ex, /* io: exponent of the addend Q0 */ + const int my, /* i: mantissa of the adder Q31 */ + const short ey /* i: exponent of the adder Q0 */ +); + +short rc_get_bits2( /* o: Number of bits needed */ + const short N, /* i: Number of bits currently used */ + const unsigned int range /* i: Range of range coder */ +); + + + +void rc_enc_init( + Encoder_State *st, /* i/o: Encoder state */ + short tot_bits /* i : Total bit budget */ +); + +void rc_encode( + Encoder_State *st, /* i/o: Encoder state */ + unsigned int cum_freq, /* i : Cumulative frequency up to symbol */ + unsigned int sym_freq, /* i : Symbol probability */ + unsigned int tot /* i : Total cumulative frequency */ +); + +void rc_enc_finish( + Encoder_State *st /* i/o: Encoder state */ +); + +void rc_enc_bits( + Encoder_State *st, /* i/o: Encoder state */ + unsigned int value, /* i : Value to encode */ + short bits /* i : Number of bits used */ +); + +void rc_enc_uniform( + Encoder_State *st, /* i/o: Encoder state */ + unsigned int value, /* i : Value to encode */ + unsigned int tot /* i : Maximum value */ +); + +void rc_dec_init( + Decoder_State *st, /* i/o: Decoder State */ + short tot_bits /* i : Total bit budget */ +); + +unsigned int rc_decode( /* o : Decoded cumulative frequency */ + Decoder_State *st, /* i/o: Decoder State */ + unsigned int tot /* i : Total cumulative frequency */ +); + +void rc_dec_update( + Decoder_State *st, /* i/o: Decoder State */ + unsigned int cum_freq, /* i : Cumulative frequency */ + unsigned int sym_freq /* i : Symbol frequency */ +); + +unsigned int rc_dec_bits( /* i : Decoded value */ + Decoder_State *st, /* i/o: Decoder State */ + short bits /* i : Number of bits */ +); + +unsigned int rc_dec_uniform( /* i : Decoded value */ + Decoder_State *st, /* i/o: Decoder State */ + unsigned int tot /* i : Maximum value */ +); + +void rc_dec_finish( + Decoder_State *st /* i/o: deocder state structure */ +); + +short pvq_core_enc ( + Encoder_State *st, + float coefs_norm[], + float coefs_quant[], + short bit_budget, /* number of bits */ + short nb_sfm, + const short *sfm_start, + const short *sfm_end, + const short *sfmsize, + short *R, + short *Rs, + short *npulses, + short *maxpulse, + const short core +); + +short pvq_core_dec ( + Decoder_State *st, + const short *band_start, + const short *band_end, + const short *band_width, + float coefs_quant[], /* o : output MDCT */ + short bits_tot, + short nb_sfm, + short *R, + short *Rs, + short *npulses, + short *maxpulse, + const short core +); + +void pvq_encode( + Encoder_State *st, + const float *x, /* i: vector to quantize */ + short *y, /* o: quantized vector (non-scaled int)*/ + float *xq, /* o: quantized vector (scaled float) */ + const short pulses, /* i: number of allocated pulses */ + const short N, /* i: Length of vector */ + const float gain /* i: Gain */ +); + +void pvq_decode( + Decoder_State *st, + float *xq, /* o: decoded vector (scaled float) */ + short *y, /* o: decoded vector (non-scaled short)*/ + const short K, /* i: number of allocated pulses */ + const short N, /* i: Length of vector */ + const float gain /* i: Gain */ +); + + +void rangeCoderFinalizationFBits( + short Brc, + unsigned int INTrc, + short *FBits +); + +void bandBitsAdjustment( + short Brc, + unsigned int INTrc, + short Bavail, + short Nbands, + short D, + short L, + short Bband, + short Breserv, + short *Bband_adj, /* o */ + short *Brem, /* o */ + short *Breservplus /* o */ +) ; +void conservativeL1Norm( + short L, + short Qvec, + short Fcons, + short Qavail, + short Qreserv, + short Dspec, + short *Dvec, /*o*/ + short *Qspare, /*o*/ + short *Qreservplus, /*o*/ + short *Dspecplus /*o*/ +); + +void NearOppSplitAdjustment( + short qband, + short qzero, + const short Qac, + const unsigned int INTac, + short qglobal, + short FlagCons, + short Np, + short Nhead, + short Ntail, + short Nnear, + short Nopp, + short oppRQ3, + short *qnear, + short *qopp, + short *qglobalupd +) ; +void dsDirac2Dirac( + short dsDiracIndex, + short *diracs +); +int intLimCDivPos( + int NUM, + short DEN +) ; + +int intLimCDivSigned( + int NUM, + short DEN +) ; + + +short shrtCDivSignedApprox( + const short num, + const short den +); + +void dsDiracPerQuanta(short td, + short t_quanta, + short dsm, + const unsigned char* const *frQuanta, + short *DsIdx + ); +void QuantaPerDsDirac( + short td, + short dsDiracIndex, + const unsigned char* const* dimFrQuanta, + short *Quanta +) ; + +void Ratio_rQ3( + short opp, + short near, + short *result +); + +void obtainEnergyQuantizerDensity( + short L, + short R, + short *Density +) ; + +void densityAngle2RmsProjDec( + short D, /* i: density */ + short indexphi, /* i: decoded index from AR dec */ + short *oppQ15, /* o: proj*/ + short *nearQ15, /* o: */ + short *oppRatioQ3 /* o: */ +) ; + +void densityAngle2RmsProjEnc ( + short D, + short phiQ14uq, + short *indexphi, /* o: index to send to AR */ + short *oppQ15, /* o: proj*/ + short *nearQ15, + short *oppRatioQ3 +) ; + + +void subband_gain_bits( + const short *Rk, /* i : bit allocation per band (Q3)*/ + const short N, /* i : number of bands */ + short *bits, /* o : gain bits per band */ + const short *sfmsize /* i : Size of bands */ +); + +void env_adj( + const short *pulses, /* i : number of pulses per band */ + const short length, /* i : length of spectrum */ + const short last_sfm, /* i : Index of last band */ + float *adj, /* o : Adjustment factors for the envelope */ + const float env_stab, + const short *sfmsize /* i : Length of bands */ +); + +float env_stability( + const short *ynrm, /*i : Norm vector for current frame */ + const short nb_sfm, /*i : Number of sub-bands */ + short *mem_norm, /*i/o: Norm vector memory from past frame */ + float *mem_env_delta /*i/o: Envelope stability memory for smoothing*/ +); + +float env_stab_smo( + float env_stab, /*i : env_stab value */ + float *env_stab_state_p, /*i/o: env_stab state probabilities */ + short *ho_cnt /*i/o: hangover counter for speech state */ +); + +void core_switching_pre_enc( + Encoder_State *st, /* i/o: encoder state structure */ + LPD_state *mem, /* i/o: encoder state structure */ + const float *old_inp_12k8, /* i : old input signal @12.8kHz */ + const float *old_inp_16k /* i : old input signal @16kHz */ +); + +void core_switching_post_enc( + Encoder_State *st, /* i/o: encoder state structure */ + const float *old_inp_12k8, /* i : old input signal @12.8kHz */ + const float *old_inp_16k, /* i : old input signal @16kHz */ + const short pitch[3], /* i : open-loop pitch values for quantiz. */ + const float voicing[3], /* i : Open-loop pitch gains */ + const float A[] /* i : unquant LP filter coefs. */ +); + +void core_switching_post_dec( + Decoder_State *st, /* i/o: decoder state structure */ + float *synth, /* i/o: output synthesis */ + const short output_frame, /* i : frame length */ + const short core_switching_flag, /* i : ACELP->HQ switching frame flag */ + const short coder_type +); + +void core_switching_pre_dec( + Decoder_State *st, /* i/o: decoder state structure */ + const short output_frame /* i : frame length */ +); + +void bandwidth_switching_detect( + Decoder_State *st /* i/o: encoder state structure */ +); + +void bw_switching_pre_proc( + Decoder_State *st, /* i/o: decoder state structure */ + const float *old_syn_12k8_16k /* i : ACELP core synthesis @ 12.8kHz or 16kHz */ +); + +void updt_bw_switching( + Decoder_State *st, /* i/o: decoder state structure */ + const float *synth /* i : float synthesis signal */ +); + +void swb_tbe_reset( + float mem_csfilt[], + float mem_genSHBexc_filt_down_shb[], + float state_lpc_syn[], + float syn_overlap[], + float state_syn_shbexc[], + float *tbe_demph, + float *tbe_premph, + float mem_stp_swb[], + float *gain_prec_swb +); + +void swb_tbe_reset_synth( + float genSHBsynth_Hilbert_Mem[], + float genSHBsynth_state_lsyn_filt_shb_local[] +); + + +void fb_tbe_reset_enc( + float elliptic_bpf_2_48k_mem[][4], + float *prev_fb_energy +); + +void fb_tbe_reset_synth( + float fbbwe_hpf_mem[][4], + float *prev_fbbwe_ratio +); + +void wb_tbe_extras_reset( + float mem_genSHBexc_filt_down_wb2[], + float mem_genSHBexc_filt_down_wb3[] +); + +void wb_tbe_extras_reset_synth( + float state_lsyn_filt_shb[], + float state_lsyn_filt_dwn_shb[], + float mem_resamp_HB[] +); + +void prep_tbe_exc( + const short L_frame, /* i : length of the frame */ + const short i_subfr, /* i : subframe index */ + const float gain_pit, /* i : Pitch gain */ + const float gain_code, /* i : algebraic codebook gain */ + const float code[], /* i : algebraic excitation */ + const float voice_fac, /* i : voicing factor */ + float *voice_factors, /* o : TBE voicing factor */ + float bwe_exc[], /* i/o: excitation for TBE */ + const float gain_preQ, /* i : prequantizer excitation gain */ + const float code_preQ[], /* i : prequantizer excitation */ + const short T0, /* i : integer pitch variables */ + const short coder_type, /* i : coding type */ + const long core_brate /* i : core bitrate */ +); + +void synthesise_fb_high_band( + const float excitation_in[], /* i : full band excitation */ + float output[], /* o : high band speech - 14.0 to 20 kHz */ + const float fb_exc_energy, /* i : full band excitation energy */ + const float ratio, /* i : energy ratio */ + const short L_frame, /* i : ACELP frame length */ + const short bfi, /* i : fec flag */ + float *prev_fbbwe_ratio, /* o : previous frame energy for FEC */ + float bpf_memory[][4] /* i/o: memory for elliptic bpf 48k */ +); + +void elliptic_bpf_48k_generic( + const float input[], /* i : input signal */ + float output[], /* o : output signal */ + float memory[][4], /* i/o: 4 arrays for memory */ + const float full_band_bpf[][5] /* i : filter coefficients b0,b1,b2,a0,a1,a2 */ +); + +void HQ_FEC_processing( + Decoder_State *st, /* i/o: decoder state structure */ + float *t_audio_q, /* o : MDCT coeffs. (for synthesis) */ + short is_transient, /* i : Old flag for transient */ + float ynrm_values[][MAX_PGF], /* i : Old average Norm values for each group of bands */ + float r_p_values[][MAX_ROW], /* i : Computed y-intercept and slope by Regression */ + short num_Sb, /* i : Number of sub-band group */ + short nb_sfm, /* i : Number of sub-band */ + short *Num_bands_p, /* i : Number of coeffs. for each sub-band */ + short output_frame, /* i : Frame size */ + const short *sfm_start, /* i : Start of bands */ + const short *sfm_end /* i : End of bands */ +); + +void HQ_FEC_Mem_update( + Decoder_State *st, /* i/o: decoder state structure */ + float *t_audio_q, + float *normq, + short *ynrm, + short *Num_bands_p, + short is_transient, + short hqswb_clas, + short c_switching_flag, + short nb_sfm, + short num_Sb, + float *mean_en_high, + short hq_core_type, /* i : normal or low-rate MDCT(HQ) core */ + short output_frame +); + +void time_domain_FEC_HQ( + Decoder_State *st, /* i : Decoder State */ + float *wtda_audio, /* i : input */ + float *out, /* o : output audio */ + float mean_en_high, /* i : transient flag */ + const short output_frame +); + +void Next_good_after_burst_erasures( + const float *ImdctOut, /* i : input */ + float *auOut, /* o : output audio */ + float *OldauOut, /* i/o: audio from previous frame */ + const short ol_size /* i : overlap size */ +); + +void update_average_rate( + Encoder_State *st /* i/o: encoder state structure */ +); + +void reset_preecho_dec( + Decoder_State *st /* i/o: decoder state structure */ +); + +void preecho_sb( + const long brate, /* i : core bit-rate */ + const float wtda_audio[], /* i : imdct signal */ + float *rec_sig, /* i : reconstructed signal, output of the imdct transform */ + const short output_frame, /* i : output frame length */ + float *memfilt_lb, /* i/o: memory */ + float *mean_prev_hb, /* i/o: memory */ + float *smoothmem, /* i/o: memory */ + float *mean_prev, /* i/o: memory */ + float *mean_prev_nc, /* i/o: memory */ + float *wmold_hb, /* i/o: memory */ + short *prevflag, /* i/o: flag */ + short *pastpre, /* i/o: flag */ + const short bwidth +); + +void hq2_core_configure( + const short frame_length, /* i : frame length */ + const short num_bits, /* i : number of bits */ + const short is_transient, /* i : transient flag */ + short *bands, + short *length, + short band_width[], + short band_start[], + short band_end[], + Word32 *L_qint, /* o : Q29 */ + Word16 *eref_fx, /* o : Q10 */ + Word16 *bit_alloc_weight_fx, /* o : Q13 */ + short *gqlevs, + short *Ngq, + short *p2a_bands, + float *p2a_th, + float *pd_thresh, + float *ld_slope, + float *ni_coef, + float *ni_pd_th, + long bwe_br +); + +void hq_lr_enc( + Encoder_State *st, /* i/o: encoder state structure */ + float t_audio[], /* i/o: transform-domain coefs. */ + const short inner_frame, /* i : inner frame length */ + short *num_bits, /* i/o: number of available bits */ + const short is_transient /* i : transient flag */ +); + +void hq_lr_dec( + Decoder_State *st, /* i/o: decoder state structure */ + float yout[], /* o : transform-domain output coefs. */ + const short inner_frame, /* i : inner frame length */ + short num_bits, /* i : number of available bits */ + short *is_transient /* o : transient flag */ +); + +void hq2_bit_alloc ( + const float band_energy[], /* i : band energy of each subband */ + const short bands, /* i : total number of subbands in a frame */ + Word32 L_Rk[], /* i/o: Bit allocation/Adjusted bit alloc. */ + short *bit_budget, /* i/o: bit bugdet */ + short *p2a_flags, /* i : HF tonal indicator */ + const Word16 weight_fx, /* i : weight (Q13) */ + const short band_width[], /* i : Sub band bandwidth */ + const short num_bits, /* i : available bits */ + const short hqswb_clas, /* i : HQ2 class information */ + const short bwidth, /* i : input bandwidth */ + const short is_transient /* i : indicator HQ_TRANSIENT or not */ +); + +void hq2_noise_inject( + float y2hat[], + const short band_start[], + const short band_end[], + const short band_width[], + float Ep[], + float Rk[], + const int npulses[], + short ni_seed, + const short bands, + const short ni_start_band, + const short bw_low, + const short bw_high, + const float enerL, + const float enerH, + float last_ni_gain[], + float last_env[], + short *last_max_pos_pulse, + short *p2a_flags, + short p2a_bands, + const short hqswb_clas, + const short bwidth, + const long bwe_br +); + +void mdct_spectrum_denorm( + const int inp_vector[], + float y2[], + const short band_start[], + const short band_end[], + const short band_width[], + const float band_energy[], + const int npulses[], + const short bands, + const float ld_slope, + const float pd_thresh +); + +void reverse_transient_frame_energies( + float band_energy[], /* o : band energies */ + const short bands /* i : number of bands */ +); + +short peak_vq_enc( + Encoder_State *st, /* i/o: encoder state structure */ + const float *coefs, /* i : Input coefficient vector */ + float *coefs_out, /* o : Quantized output vector */ + const short brate, /* i : Core bitrate */ + const short num_bits, /* i : Number of bits for HVQ */ + const short vq_peaks, /* i : Number of identified peaks */ + const short *ynrm, /* i : Envelope coefficients */ + short *R, /* i/o: Bit allocation/updated bit allocation */ + short *vq_peak_idx, /* i : Peak index vector */ + float *nf_gains /* i : Estimated noise floor gains */ +); + +void hvq_dec( + Decoder_State *st, /* i/o: decoder state structure */ + const short num_bits, /* i : Number of available bits */ + const long core_brate, /* i : Core bit-rate */ + const short *ynrm, /* i : Envelope coefficients */ + short *R, /* i/o: Bit allocation/updated bit allocation */ + float *noise_level, /* o : Noise level */ + short *peak_idx, /* o : Peak position vector */ + short *Npeaks, /* o : Total number of peaks */ + float *coefsq_norm, /* o : Output vector */ + const short core +); + +void hq_configure_bfi( + short *nb_sfm, /* o : Number of sub bands */ + short *num_Sb, /* o : Number of FEC sub bands ? */ + short *num_bands_p, /* o : FEC sub bands */ + short const **sfmsize, /* o : Subband bandwidths */ + short const **sfm_start, /* o : Subband start coefficients */ + short const **sfm_end /* o : Subband end coefficients */ +); + +void peak_vq_dec( + Decoder_State *st, /* i/o: decoder state structure */ + float *coefs_out, /* o : Output coefficient vetor */ + const short brate, /* i : Core bitrate */ + const short num_bits, /* i : Number of bits for HVQ */ + const short *ynrm, /* i : Envelope coefficients */ + short *R, /* i/o: Bit allocation/updated bit allocation */ + short *vq_peak_idx, /* o : Peak position vector */ + short *Npeaks, /* o : Number of peaks */ + const short core /* i : Core type */ +); + +void swb_bwe_enc_lr( + Encoder_State *st, /* i/o: encoder state structure */ + const float m_core[], /* i : core synthesis (MDCT) */ + const float m_orig[], /* i/o: scaled orig signal (MDCT) */ + float m[], /* o : output, SWB part (MDCT) */ + const long total_brate, /* i : total bitrate for selecting subband pattern */ + short BANDS, + short *band_start, + short *band_end, + float *band_energy, + short *p2a_flags, + const short hqswb_clas, + short lowlength, + short highlength, + short *prev_frm_index, + const short har_bands, + short *prev_frm_hfe2, + short *prev_stab_hfe2, + short band_width[], + const float y2_ni[], + short *ni_seed +); + +void swb_bwe_dec_lr( + Decoder_State *st, /* i/o: decoder state structure */ + const float m_core[], /* i : lowband synthesis */ + float m[], /* o : highband synthesis with lowband zeroed */ + const long total_brate, /* i : total bitrate for selecting subband pattern */ + short BANDS, + short *band_start, + short *band_end, + float *band_energy, + short *p2a_flags, + const short hqswb_clas, + short lowlength, + short highlength, + const short har_bands, + short *prev_frm_hfe2, + short *prev_stab_hfe2, + short band_width[], + const float y2_ni[], + short *ni_seed +); + +int get_usebit_npswb( + short hqswb_clas +); + +void GetPredictedSignal( + const float *predBuf, /* i : prediction buffer */ + float *outBuf, /* o : output buffer */ + const short lag, /* i : prediction buffer offset */ + const short fLen, /* i : length of loop (output) */ + const float gain /* i : gain to be applied */ +); + +void convert_lagIndices_pls2smp( + short lagIndices_in[], + short nBands_search, + short lagIndices_out[], + const float sspectra[], + const short sbWidth[], + const short fLenLow +); + +void FindNBiggest2_simple( + const float *inBuf, /* i : input buffer (searched) */ + GainItem *g, /* o : N biggest components found */ + const short nIdx, /* i : search length */ + short *n, /* i : number of components searched (N biggest) */ + short N_NBIGGESTSEARCH +); + +void updat_prev_frm( + float y2[], + float t_audio[], + long bwe_br, + short length, + const short inner_frame, + short bands, + short bwidth, + const short is_transient, + short hqswb_clas, + short *prev_hqswb_clas, + short *prev_SWB_peak_pos, + short prev_SWB_peak_pos_tmp[], + short *prev_frm_hfe2, + short *prev_stab_hfe2, + short bws_cnt +); + +void hf_parinitiz( + const long total_brate, + const short hqswb_clas, + short lowlength, + short highlength, + short wBands[], + const short **subband_search_offset, + const short **subband_offsets, + short *nBands, + short *nBands_search, + short *swb_lowband, + short *swb_highband +); + +float spectrumsmooth_noiseton( + float spectra[], + const float spectra_ni[], + float sspectra[], + float sspectra_diff[], + float sspectra_ni[], + const short fLenLow, + short *ni_seed +); + +void noiseinj_hf( + float xSynth_har[], + float th_g[], + float band_energy[], + float *prev_En_sb, + const short p2a_flags[], + short BANDS, + short band_start[], + short band_end[], + const short fLenLow +); + +void noise_extr_corcod( + float spectra[], + const float spectra_ni[], + float sspectra[], + float sspectra_diff[], + float sspectra_ni[], + const short fLenLow, + short prev_hqswb_clas, + float *prev_ni_ratio +); + +void genhf_noise( + float noise_flr[], + float xSynth_har[], + float *predBuf, + short bands, /* i : total number of subbands in a frame */ + short harmonic_band, /* i : Number of LF harmonic frames */ + short har_freq_est2, + short pos_max_hfe2, + short *pul_res, + GainItem pk_sf[], + const short fLenLow, + const short fLenHigh, + const short sbWidth[], + const short lagIndices[], + const short subband_offsets[], + const short subband_search_offset[] +); + +void ton_ene_est( + float xSynth_har[], + float be_tonal[], + float band_energy[], + short band_start[], + short band_end[], + short band_width[], + const short fLenLow, + const short fLenHigh, + short bands, + short har_bands, + float ni_lvl, + GainItem pk_sf[], + short *pul_res +); + +void Gettonl_scalfact( + float *outBuf, /* o : synthesized spectrum */ + const float *codbuf, /* i : core coder */ + const short fLenLow, /* i : lowband length */ + const short fLenHigh, /* i : highband length */ + short harmonic_band, /* i : Number of LF harmonic frames */ + short bands, /* i : total number of subbands in a frame */ + float *band_energy, /* i : band energy of each subband */ + short *band_start, /* i : subband start indices */ + short *band_end, /* i : subband end indices */ + const short p2aflags[], + float be_tonal[], + GainItem *pk_sf, + short *pul_res +); + +void SpectrumSmoothing_nss( + float *inBuf, + float *outBuf, + int fLen +); + +void SpectrumSmoothing( + float *inBuf, + float *outBuf, + const short fLen, + const float th_cut +); + +void hq2_bit_alloc_har ( + float *y, /* i : band energy of sub-vectors */ + int B, /* i : number of available bits */ + short N, /* i : number of sub-vectors */ + Word32 *L_Rsubband, + short p2a_bands, + long core_brate, /* i : core bit rate */ + short p2a_flags[], + short band_width[] +); + +void GetSynthesizedSpecThinOut( + const float *predBuf, + float *outBuf, + const short nBands, + const short *sbWidth, + const short *lagIndices, + const float *lagGains, + const short predBufLen +); + +void return_bits_normal2( + short *bit_budget, + const short p2a_flags[], + const short bands, + const short bits_lagIndices[] +); + +void GetlagGains( + const float *predBuf, + const float *band_energy, + const short nBands, + const short *sbWidth, + const short *lagIndices, + const short predBufLen, + float *lagGains +); + +void preset_hq2_swb( + const short hqswb_clas, + const short band_end[], + short *har_bands, + short p2a_bands, + const short length, + const short bands, + short *lowlength, + short *highlength, + float m[] +); + +void post_hq2_swb( + const float m[], + const short lowlength, + const short highlength, + const short hqswb_clas, + const short har_bands, + const short bands, + const short p2a_flags[], + const short band_start[], + const short band_end[], + float y2[], + int npulses[] +); + +void har_denorm_pulcnt( + float spectra[], /* i/o: MDCT domain spectrum */ + short band_start[], /* i : Number subbands/Frame */ + short band_end[], /* i : Band Start of each SB */ + float band_energy[], /* i : Band end of each SB */ + short band_width[], + int npulses[], + const short har_bands /* i: No. of harmonic bands */ +); + +short har_est( + float spectra[], + short N, + short *har_freq_est1, + short *har_freq_est2, + short *flag_dis, + short *prev_frm_hfe2, + const short subband_search_offset[], + const short sbWidth[], + short *prev_stab_hfe2 +); + +void spt_shorten_domain_pre( + const short band_start[], + const short band_end[], + const short prev_SWB_peak_pos[], + const short BANDS, + const long bwe_br, + short new_band_start[], + short new_band_end[], + short new_band_width[] +); + +void spt_shorten_domain_band_save( + const short bands, + const short band_start[], + const short band_end[], + const short band_width[], + short org_band_start[], + short org_band_end[], + short org_band_width[] +); + +void spt_shorten_domain_band_restore( + const short bands, + short band_start[], + short band_end[], + short band_width[], + const short org_band_start[], + const short org_band_end[], + const short org_band_width[] +); + +void spt_swb_peakpos_tmp_save( + const float y2[], + const short bands, + const short band_start[], + const short band_end[], + short prev_SWB_peak_pos_tmp[] +); + +void hq_ecu( + const float *prevsynth, /* i : buffer of previously synthesized signal */ + float *ecu_rec, /* o : reconstructed frame in tda domain */ + short *time_offs, /* i/o: Sample offset for consecutive frame losses*/ + float *X_sav, /* i/o: Stored spectrum of prototype frame */ + short *num_p, /* i/o: Number of identified peaks */ + short *plocs, /* i/o: Peak locations */ + float *plocsi, /* i/o: Interpolated peak locations */ + const float env_stab, /* i : Envelope stability parameter */ + short *last_fec, /* i/o: Flag for usage of pitch dependent ECU */ + const short ph_ecu_HqVoicing, /* i : HQ Voicing flag */ + short *ph_ecu_active, /* i : Phase ECU active flag */ + float *gapsynth, /* o : Gap synthesis */ + const short prev_bfi, /* i : indicating burst frame error */ + const short old_is_transient[2], /* i : flags indicating previous transient frames*/ + float *mag_chg_1st, /* i/o: per band magnitude modifier for transients*/ + float Xavg[LGW_MAX], /* i/o: Frequency group average gain to fade to */ + float *beta_mute, /* o : Factor for long-term mute */ + const short output_frame, /* i : frame length */ + Decoder_State *st /* i/o: decoder state structure */ +); + +void hq_timedomain_conc( + float *ecu_rec, /* o : reconstructed frame in tda domain */ + float *gapsynth, /* o : Gap synthesis */ + const short output_frame, /* i : frame length */ + const float *prevsynth, /* i : buffer of previously synthesized signal */ + Decoder_State *st /* i/o: decoder state structure */ +); + +void fft3( + const float X[], /* i : input frame */ + float Y[], /* o : DFT of input frame */ + const short n /* i : block length (must be radix 3) */ +); + +void ifft3( + const float X[], /* i : input frame */ + float Y[], /* o : iDFT of input frame */ + const short n /* i : block length (must be radix 3) */ +); + +void minimumStatistics( /* return: updated estimate of background noise */ + float* noiseLevelMemory, /* internal state */ + int* noiseLevelIndex, /* internal state */ + int* currLevelIndex, /* internal state (circular buffer) */ + float* noiseEstimate, /* previous estimate of background noise */ + float* lastFrameLevel, /* level of the last frame */ + float currentFrameLevel, /* level of the current frame */ + float const minLev, /* minimum level */ + int const buffSize /* buffer size */ +); + +void E_LPC_int_lpc_tcx( + const float lsf_old[], /* input : LSFs from past frame */ + const float lsf_new[], /* input : LSFs from present frame */ + float a[] /* output: interpolated LP coefficients */ +); + +Word32 E_GAIN_closed_loop_search( + Float32 exc[], + Float32 xn[], + Float32 h[], + Word32 t0_min, + Word32 t0_min_frac, + Word32 t0_max, + Word32 t0_max_frac, + Word32 t0_min_max_res, + Word32 *pit_frac, + Word32 *pit_res, + Word32 pit_res_max, + Word32 i_subfr, + Word32 pit_min, + Word32 pit_fr2, + Word32 pit_fr1, + Word32 L_subfr +); + +void E_ACELP_toeplitz_mul( + float R[], + float c[], + float d[] +); + +void acelp_pulsesign( + const float cn[], + float dn[], + float dn2[], + float sign[], + float vec[], + float alp +); + +void E_ACELP_4tsearch( + Float32 dn[], + const Float32 cn[], + const Float32 H[], + float code[], + PulseConfig *config, + Word16 ind[], + Float32 y[] +); + +void E_ACELP_4tsearchx( + Float32 dn[], + const Float32 cn[], + Float32 Rw[], + float code[], + PulseConfig *config, + Word16 ind[] +); + +short E_ACELP_indexing( + Float32 code[], + PulseConfig config, + int num_tracks, + int prm[] +); + +void acelp_findcandidates( + float dn2[], + short dn2_pos[], + short pos_max[], + int L_subfr, + int tracks +); + +void E_ACELP_innovative_codebook( + float *exc, /* i : pointer to the excitation frame */ + int T0, /* i : integer pitch lag */ + int T0_frac, /* i : fraction of lag */ + int T0_res, /* i : pitch resolution */ + float pitch_gain, /* i : adaptive codebook gain */ + float tilt_code, /* i : tilt factor */ + int mode, /* i : innovative codebook mode */ + int pre_emphasis,/* i : use pre_emphasis */ + int pitch_sharpening, /* i : use pitch sharpening */ + int phase_scrambling, /* i : use phase scrambling */ + int formant_enh, /* i : use formant enhancement */ + int formant_tilt,/* i : use tilt of formant enhancement */ + float formant_enh_num, /* i : formant enhancement numerator weighting factor*/ + float formant_enh_den, /* i : formant enhancement denominator weighting factor*/ + const short i_subfr, /* i : subframe index */ + const float *Aq, /* i : quantized LPC coefficients */ + float *h1, /* i : impulse response of weighted synthesis filter */ + float *xn, /* i : Close-loop Pitch search target vector */ + float *cn, /* i : Innovative codebook search target vector */ + float *y1, /* i : zero-memory filtered adaptive excitation */ + float *y2, /* o : zero-memory filtered algebraic excitation */ + int acelpautoc, /* i : autocorrelation mode enabled */ + int **pt_indice, /* i/o: quantization indices pointer */ + float *code /* o : innovative codebook */ + ,const short L_frame, /* i : length of the frame */ + const short last_L_frame,/* i : length of the last frame */ + const long total_brate /* i : total bit-rate */ +); + +short E_ACELP_code43bit( + const float code[], + long unsigned *ps, + int *p, + unsigned short idxs[] +); + +void fcb_pulse_track_joint( + unsigned short *idxs, + int wordcnt, + unsigned long *index_n, + int *pulse_num, + int track_num +); + +void D_ACELP_indexing( + Float32 code[], + PulseConfig config, + int num_tracks, + int prm[], + short *BER_detect +); + +void D_ACELP_decode_43bit( + unsigned short idxs[], + float code[], + int *pulsestrack +); + +void fcb_pulse_track_joint_decode( + unsigned short *idxs, + int wordcnt, + long unsigned *index_n, + int *pulse_num, + int track_num +); + +void lag_wind( + float r[], /* i/o: autocorrelations */ + const short m, /* i : order of LP filter */ + const int sr, /* i : sampling rate */ + const short strength /* i : LAGW_WEAK, LAGW_MEDIUM, or LAGW_STRONG */ +); + +void adapt_lag_wind( + float r[], /* i/o: autocorrelations */ + int m, /* i : order of LP filter */ + const int Top, /* i : open loop pitch lags from curr. frame (or NULL if n/a) */ + const float Tnc, /* i : open loop pitch gains from curr. frame (NULL if n/a) */ + int sr /* i : sampling rate */ +); + +void hp20( + Float32 signal[], + Word32 lg, + Float32 mem[], + Word32 fs +); + +void ham_cos_window( + float *fh, + int n1, + int n2 +); + +float correlation_shift( /* o : noise dependent voicing correction */ + const float totalNoise /* i : noise estimate over all critical bands */ +); + +void init_coder_ace_plus( + Encoder_State *st /* i/o: encoder state structure */ +); + +void core_coder_reconfig( + Encoder_State *st /* i/o: encoder state structure */ +); + +void core_coder_mode_switch( + Encoder_State *st, /* i/o: encoder state structure */ + int bandwidth_in, /* i : bandwidth */ + int bitrate /* i : bitrate */ +); + +void enc_acelp_tcx_main( + const float new_samples[], /* i : new samples */ + Encoder_State *st, /* i/o: encoder state structure */ + const short coder_type, /* i : coding type */ + const short pitch[3], /* i : open-loop pitch values for quantiz. */ + const float voicing[3], /* i : open-loop pitch gains */ + float Aw[NB_SUBFR16k*(M+1)], /* i : weighted A(z) unquant. for subframes*/ + const float lsp_new[M], /* i : LSPs at the end of the frame */ + const float lsp_mid[M], /* i : LSPs at the middle of the frame */ + HANDLE_FD_CNG_ENC hFdCngEnc, /* i/o: CNG handle */ + float bwe_exc_extended[], /* i/o: bandwidth extended excitation */ + float *voice_factors, /* o : voicing factors */ + float pitch_buf[], /* o : floating pitch for each subframe */ + short vad_hover_flag +); + +void pitch_pred_linear_fit( + const short nbLostCmpt, /* i: bfi counter */ + const short last_good, /* i: last classification type */ + float *old_pitch_buf, /* i: pitch lag buffer */ + float *old_fpitch, /* i/o: pitch used for initial ACB generation */ + float *T0_out, /* o: estimated close loop pitch */ + int pit_min, /* i: Minimum pitch lag */ + int pit_max, /* i: Maximum pitch lag */ + float *mem_pitch_gain, /* i: lag pitch gain [0] is the most recent subfr lag */ + int limitation, + short plc_use_future_lag, /* i: number of subframes to predict */ + short *extrapolationFailed /* o: flag if extrap decides not to change the pitch */ + ,int nb_subfr /* i: number of ACELP subframes */ +); + +void get_subframe_pitch( + int nSubframes, /* i: number of subframes */ + float pitchStart, /* i: starting pitch lag (in subframe -1) */ + float pitchEnd, /* i: ending pitch lag (in subframe nSubframes-1) */ + float *pitchBuf /* o: interpolated pitch lag per subframe */ +); + + +void core_encode_openloop( + Encoder_State *st, /* i/o: encoder state structure */ + const short coder_type, /* i : coding type */ + const short pitch[3], /* i : open-loop pitch values for quantiz. */ + const float voicing[3], /* i : open-loop pitch gains */ + const float Aw[NB_SUBFR16k*(M+1)], /* i : weighted A(z) unquant. for subframes*/ + const float lsp_new[M], /* i : LSPs at the end of the frame */ + const float lsp_mid[M], /* i : LSPs at the middle of the frame */ + float *pitch_buf, /* i/o: floating pitch values for each subfr*/ + float *voice_factors, /* o : voicing factors */ + float *bwe_exc, /* o : excitation for SWB TBE */ + const short vad_hover_flag +); + +void core_acelp_tcx20_switching( + Encoder_State *st, /* i/o: encoder state structure */ + const short vad_flag, + short sp_aud_decision0, + float non_staX, + short *pitch, /* i : open-loop pitch values for quantiz. */ + float *pitch_fr, /* i/o: fraction pitch values */ + float *voicing_fr, /* i/o: fractional voicing values */ + const float currTempFlatness, /* i : flatness */ + const float lsp_mid[M], /* i : LSPs at the middle of the frame */ + const float stab_fac /* i : LP filter stability */ +); + +void core_encode_twodiv( + const float new_samples[], /* i : new samples */ + Encoder_State *st, /* i/o: encoder state structure */ + const short coder_type, /* i : coding type */ + const short pitch[3], /* i : open-loop pitch values for quantiz. */ + const float voicing[3], /* i : open-loop pitch gains */ + float Aw[NB_SUBFR16k*(M+1)] /* i : weighted A(z) unquant. for subframes*/ +); + +void core_encode_update( + Encoder_State *st /* i/o: encoder state structure */ +); + +void core_encode_update_cng( + Encoder_State *st, /* i/o: encoder state structure */ + float *timeDomainBuffer, + float *A, + const float Aw[] /* i : weighted A(z) unquant. for subframes*/ +); + +void core_signal_analysis_high_bitrate( + const float *new_samples, + const short T_op[3], /* i : open-loop pitch values for quantiz. */ + const float voicing[3], /* i : open-loop pitch gains */ + const short pitch_12k8[2], /* i : open-loop pitch @12.8kHz for adapt. lag windowing */ + float lsp[], + float lsp_mid[], + Encoder_State *st, + int pTnsSize[], + int pTnsBits[], + int param_core[], + int *ltpBits, + int L_frame + ,int L_frameTCX +); + + +float get_gain( /* output: codebook gain (adaptive or fixed) */ + float x[], /* input : target signal */ + float y[], /* input : filtered codebook excitation */ + int n, /* input : segment length */ + float *en_y /* output: energy of y (sum of y[]^2, optional) */ +); + +void encode_acelp_gains( + float *code, + int gains_mode, + float mean_ener_code, + short clip_gain, + ACELP_CbkCorr *g_corr, + float *gain_pit, + float *gain_code, + int **pt_indice, + float *past_gcode, + float *gain_inov, + int L_subfr, + float *code2, + float *gain_code2, + short noisy_speech_flag +); + +int Mode2_gain_enc_mless( + const float *code, /* i : algebraic excitation */ + int lcode, /* i : Subframe size */ + float *gain_pit, /* o : quantized pitch gain */ + float *gain_code, /* o : quantized codebook gain */ + ACELP_CbkCorr *coeff, /* i/o: correlations , -2,, -2 and 2 */ + float mean_ener, /* i : mean_ener defined in open-loop (3 bits) */ + const short clip_gain, /* i : gain pitch clipping flag (1 = clipping) */ + float *past_gcode, /* i/o: past gain of code */ + float *gain_inov, /* o : unscaled innovation gain */ + const short coder_type /* i : type of coder */ +); + +void decode_acelp_gains( + float *code, + int gains_mode, + float mean_ener_code, + float *gain_pit, + float *gain_code, + int **pt_indice, + float *past_gpit, + float *past_gcode, + float *gain_inov, + int L_subfr, + float *code2, + float *gain_code2 +); + +void Es_pred_dec( + float *Es_pred, /* o : predicited scaled innovation energy */ + const int enr_idx, /* i : indice */ + const short nb_bits, /* i : number of bits */ + const short no_ltp /* i : no LTP flag */ +); + +void Mode2_pit_encode( + short coder_type, /* i : coding model */ + short i_subfr, /* i : subframe index */ + int **pt_indice, /* i/o: quantization indices pointer */ + float *exc, /* i/o: pointer to excitation signal frame */ + const short *T_op, /* i : open loop pitch estimates in current frame */ + int *T0_min, /* i/o: lower limit for close-loop search */ + int *T0_min_frac, /* i/o: lower limit for close-loop search */ + int *T0_max, /* i/o: higher limit for close-loop search */ + int *T0_max_frac, /* i/o: higher limit for close-loop search */ + int *T0, /* i/o: close loop integer pitch */ + int *T0_frac, /* i/o: close loop fractional part of the pitch */ + int *T0_res, /* i/o: close loop pitch resolution */ + float *h1, /* i : weighted filter impulse response */ + float *xn, /* i : target vector */ + int pit_min, + int pit_fr1, + int pit_fr1b, + int pit_fr2, + int pit_max, + int pit_res_max +); + +void limit_T0_voiced( + int nbits, + int res, + int T0, /* i : rough pitch estimate around which the search is done */ + int T0_frac, /* i : pitch estimate fractional part */ + int T0_res, /* i : pitch resolution */ + int *T0_min, /* o : lower pitch limit */ + int *T0_min_frac, /* o : lower pitch limit */ + int *T0_max, /* o : higher pitch limit */ + int *T0_max_frac, /* o : higher pitch limit */ + int pit_min, /* i : Minimum pitch lag */ + int pit_max /* i : Maximum pitch lag */ +); + +void Mode2_abs_pit_enc( + short T0, /* i : integer pitch lag */ + int T0_frac, /* i : pitch fraction */ + int **pt_indice, /* i/o: pointer to Vector of Q indexes */ + short pit_min, + short pit_fr1, + short pit_fr2, + short pit_res_max +); + +void Mode2_delta_pit_enc( + short T0, /* i : integer pitch lag */ + int T0_frac, /* i : pitch fraction */ + int T0_res, /* i : pitch resolution */ + short T0_min, /* i/o: delta search min */ + short T0_min_frac, /* i/o: delta search min */ + int **pt_indice /* i/o: pointer to Vector of Q indexes */ +); + +float Mode2_pit_decode( /* o: floating pitch value */ + const short coder_type, /* i: coding model */ + short i_subfr, /* i: subframe index */ + int L_subfr, + int **pt_indice, /* i/o: quantization indices pointer */ + int *T0, /* o: close loop integer pitch */ + int *T0_frac, /* o: close loop fractional part of the pitch */ + int *T0_res, /* i/o: pitch resolution */ + int *T0_min, /* i/o: lower limit for close-loop search */ + int *T0_min_frac, /* i/o: lower limit for close-loop search */ + int *T0_max, /* i/o: higher limit for close-loop search */ + int *T0_max_frac, /* i/o: higher limit for close-loop search */ + int pit_min, + int pit_fr1, + int pit_fr1b, + int pit_fr2, + int pit_max, + int pit_res_max +); + +void Mode2_abs_pit_dec( + int *T0, /* o: integer pitch lag */ + int *T0_frac, /* o: pitch fraction */ + int *T0_res, /* o: pitch resolution */ + int **pt_indice, /* i/o: pointer to Vector of Q indexes */ + int pit_min, + int pit_fr1, + int pit_fr2, + int pit_res_max +); + +void Mode2_delta_pit_dec( + int *T0, /* o: integer pitch lag */ + int *T0_frac, /* o: pitch fraction */ + int T0_res, /* i: pitch resolution */ + int *T0_min, /* i: delta search min */ + int *T0_min_frac, /* i: delta search min */ + int **pt_indice /* i/o: pointer to Vector of Q indexes */ +); + +void formant_post_filt( + PFSTAT *pfstat, /* i/o: Post filter related memories */ + float *synth_in, /* i : 12k8 synthesis */ + const float *Aq, /* i : LP filter coefficient */ + float *synth_out, /* i/o: input signal */ + const short L_frame, /* i : frame length */ + const short L_subfr, /* i : sub-frame length */ + const float lp_noise, /* i : background noise energy */ + const long rate, /* i : bit-rate */ + const short off_flag /* i : Off flag */ +); + +void qlpc_avq( + const float *lsp, /* (i) Input LSF vectors */ + const float *lspmid, + float *lsf_q, /* (o) Quantized LFS vectors */ + float *lsfmid_q, + int *index, /* (o) Quantization indices */ + int *nb_indices, /* (o) Number of quantization indices */ + int *nbbits, /* (o) Number of quantization bits */ + int core, + float sr_core +); + +int encode_lpc_avq( + Encoder_State *st, + int numlpc, + int *param_lpc, + int mode +); + +int dlpc_avq( + int *index, /* (i) Quantization indices */ + float *LSF_Q, /* (o) Quantized LSF vectors */ + int numlpc, /* (i) Number of sets of lpc */ + float sr_core +); + +int decode_lpc_avq( Decoder_State *st, int numlpc, int *param_lpc ); + +int vlpc_1st_cod( /* output: codebook index */ + const float *lsf, /* input: vector to quantize */ + float *lsfq, /* i/o: i:prediction o:quantized lsf */ + float sr_core + ,float *w /* o: lsf weights */ +); + +int vlpc_2st_cod( /* output: number of allocated bits */ + const float *lsf, /* input: normalized vector to quantize */ + float *lsfq, /* i/o: i:1st stage o:1st+2nd stage */ + int *indx, /* output: index[] (4 bits per words) */ + int mode, /* input: 0=abs, >0=rel */ + float sr_core +); + +void vlpc_2st_dec( + float *lsfq, /* i/o: i:1st stage o:1st+2nd stage */ + int *indx, /* input: index[] (4 bits per words) */ + int mode, /* input: 0=abs, >0=rel */ + float sr_core +); + +void lsf_weight_2st( + const float *lsfq, + float *w, + int mode, + float sr_core +); + +void mdct_window_sine( + float *window, + int n +); + +void mdct_window_aldo( + float *window1, + float *window2, + int n +); + +void AVQ_cod_lpc( + const float nvec[], /* i: vector to quantize */ + int nvecq[], /* o: quantized normalized vector (assuming the bit budget is enough) */ + int *indx, /* o: index[] (4 bits per words) */ + const short Nsv /* i: number of subvectors (lg=Nsv*8) */ +); + +void AVQ_dec_lpc( + const int indx[], /* i : index[] (4 bits per words) */ + int nvecq[], /* o : vector quantized */ + const short Nsv /* i : number of subvectors (lg=Nsv*8) */ +); + +void vlpc_1st_dec( + int index, /* input: codebook index */ + float *lsfq, /* i/o: i:prediction o:quantized lsf */ + float sr_core +); + +void WindowSignal( + TCX_config const *tcx_cfg, /* input: configuration of TCX */ + int offset, /* input: left folding point offset relative to the input signal pointer */ + const short left_overlap_mode, /* input: overlap mode of left window half */ + const short right_overlap_mode, /* input: overlap mode of right window half */ + int * left_overlap_length, /* output: TCX window left overlap length */ + int * right_overlap_length, /* output: TCX window right overlap length */ + float const in[], /* input: input signal */ + int * L_frame, /* input/output: frame length */ + float out[], /* output: output windowed signal */ + int fullband /* input: fullband flag */ +); + +void HBAutocorrelation( + TCX_config *tcx_cfg, /* input: configuration of TCX */ + int left_mode, /* input: overlap mode of left window half */ + int right_mode, /* input: overlap mode of right window half */ + float speech[], /* input: speech */ + int L_frame_glob, /* input: frame length */ + float *r, /* output: autocorrelations vector */ + int m /* input : order of LP filter */ +); + +void TNSAnalysis( + TCX_config *tcx_cfg, /* input: configuration of TCX */ + int L_frame, /* input: frame length */ + int L_spec, + const short tcxMode, /* input: TCX mode for the frame/subframe - TCX20 | TCX10 | TCX 5 (meaning 2 x TCX 5) */ + int isAfterACELP, /* input: Flag indicating if the last frame was ACELP. For the second TCX subframe it should be 0 */ + float spectrum[], /* input: MDCT spectrum of the subframe */ + STnsData * pTnsData, /* output: Tns data */ + int * pfUseTns, /* output: Flag indicating if TNS is used */ + float* predictionGain +); + +void ShapeSpectrum( + TCX_config *tcx_cfg,/*input: configuration of TCX*/ + float A[], /* input: quantized coefficients NxAz_q[M+1] */ + float gainlpc[], /* output: MDCT gains for the previous frame */ + int L_frame_glob, /* input: frame length */ + int L_spec, + float spectrum[], /* i/o: MDCT spectrum */ + int fUseTns, /* output: Flag indicating if TNS is used */ + Encoder_State *st +); + +void QuantizeSpectrum( + TCX_config *tcx_cfg,/*input: configuration of TCX*/ + float A[], /* input: quantized coefficients NxAz_q[M+1] */ + Word16 Aqind[], /* input: frame-independent quantized coefficients (M+1) */ + float gainlpc[], /* input: MDCT gains of the previous frame */ + float synth[], + int L_frame_glob, /* input: frame length */ + int L_frameTCX_glob, + int L_spec, + int nb_bits, /*input: bit budget*/ + int tcxonly, /*input: only TCX flag*/ + float spectrum[], /* i/o: MDCT spectrum, input is shaped MDCT spectrum */ + STnsData * pTnsData,/* input: Tns data */ + int fUseTns, /* input: Flag indicating if TNS is used */ + int tnsSize, /* input: number of tns parameters put into prm */ + LPD_state *LPDmem, /*i/o: memories*/ + int prm[], /* output: tcx parameters */ + int frame_cnt, /* input: frame counter in the super_frame */ + Encoder_State *st, + CONTEXT_HM_CONFIG *hm_cfg +); + +/* Returns: index of next coefficient */ +int get_next_coeff_mapped( + int ii[2], /* i/o: coefficient indexes */ + int *pp, /* o : peak(1)/hole(0) indicator */ + int *idx, /* o : index in unmapped domain */ + CONTEXT_HM_CONFIG *hm_cfg /* i : HM configuration */ +); + +/* Returns: index of next coefficient */ +int get_next_coeff_unmapped( + int *ii, /* i/o: coefficient index */ + int *idx /* o : index in unmapped domain */ +); + +int update_mixed_context( + int ctx, + int a +); + +void ACcontextMapping_encode2_no_mem_s17_LC( + Encoder_State *st, + int *x, + int nt, + int lastnz, + int nbbits, + int resQMaxBits, + CONTEXT_HM_CONFIG *hm_cfg +); + +long ACcontextMapping_decode2_no_mem_s17_LC( + Decoder_State *st, /* i/o: decoder state */ + int *x, /* o: decoded spectrum */ + long nt, /* i: size of spectrum */ + int nbbits, /* i: bit budget */ + int resQMaxBits, /* i: residual coding maximum bits */ + CONTEXT_HM_CONFIG *hm_cfg /* i: context-based harmonic model configuration*/ +); + +int ACcontextMapping_encode2_estimate_no_mem_s17_LC( + const int *x, + int nt, + int *lastnz, + int *nEncoded, + int target, + int *stop, + CONTEXT_HM_CONFIG *hm_cfg +); + +void tcx_windowing_analysis( + float const *signal, /* i: signal vector */ + int L_frame, /* i: frame length */ + int left_overlap, /* i: left overlap length */ + float const *left_win, /* i: left overlap window */ + int right_overlap, /* i: right overlap length */ + float const *right_win, /* i: right overlap window */ + float *output /* o: windowed signal vector */ +); + +void tcx_windowing_synthesis_current_frame( + float *signal, /* i/o: signal vector */ + float *window, /* i: TCX window vector */ + float *window_half, /* i: TCX window vector for half-overlap window */ + float *window_min, /* i: TCX minimum overlap window */ + int window_length, /* i: TCX window length */ + int window_half_length, /* i: TCX half window length */ + int window_min_length, /* i: TCX minimum overlap length */ + int left_rect, /* i: left part is rectangular */ + int left_mode, /* i: overlap mode of left window half */ + float *acelp_zir, /* i: acelp ZIR */ + float *old_syn, /* i: old synthesis */ + float *syn_overl, /* i: overlap synthesis */ + float *A_zir, + float *window_trans, /* i: window for transition from ACELP */ + int acelp_zir_len, + int acelp_mem_len, + int last_core_bfi, /* i : last mode */ + int last_is_cng, + int fullbandScale +); + +void tcx_windowing_synthesis_past_frame( + float *signal, /* i/o: signal vector */ + float *window, /* i: TCX window vector */ + float *window_half, /* i: TCX window vector for half-overlap window */ + float *window_min, /* i: TCX minimum overlap window */ + int window_length, /* i: TCX window length */ + int window_half_length, /* i: TCX half window length */ + int window_min_length, /* i: TCX minimum overlap length */ + int right_mode /* i: overlap mode (left_mode of current frame) */ +); + +/* tcx_utils_enc.c */ +void ProcessIGF( + IGF_ENC_INSTANCE_HANDLE const hInstance, /**< in: instance handle of IGF Encoder */ + Encoder_State *st, /**< in: Encoder state */ + float *pMDCTSpectrum, /**< in: MDCT spectrum */ + float *pPowerSpectrum, /**< in: MDCT^2 + MDST^2 spectrum, or estimate */ + int isTCX20, /**< in: flag indicating if the input is TCX20 or TCX10/2xTCX5 */ + int isTNSActive, /**< in: flag indicating if the TNS is active */ + int isTransition, /**< in: flag indicating if the input is the transition from from ACELP to TCX20/TCX10 */ + int frameno /**< in: flag indicating index of current subframe */ +); + +/* tcx_utils_enc.c */ +void AnalyzePowerSpectrum( + Encoder_State *st, /* i/o: encoder states */ + int L_frame, /* input: frame length */ + int L_frameTCX, /* input: full band frame length */ + int left_overlap, /* input: left overlap length */ + int right_overlap, /* input: right overlap length */ + float const mdctSpectrum[], /* input: MDCT spectrum */ + float const signal[], /* input: windowed signal corresponding to mdctSpectrum */ + float powerSpec[] /* output: Power spectrum */ +); + +void lpc2mdct( + float *lpcCoeffs, + int lpcOrder, + float *mdct_gains +); + +void mdct_preShaping( + float x[], + int lg, + const float gains[] +); + +void mdct_noiseShaping( + float x[], + int lg, + const float gains[] +); + +void mdct_noiseShaping_interp( + float x[], + int lg, + const float gains[] +); + +void AdaptLowFreqEmph( + float x[], + int xq[], + float invGain, + short tcx_lpc_shaped_ari, + const float lpcGains[], + const int lg +); + +void PsychAdaptLowFreqEmph( + float x[], + const float lpcGains[] +); + +void PsychAdaptLowFreqDeemph( + float x[], + const float lpcGains[], + float lf_deemph_factors[] +); + +void AdaptLowFreqDeemph( + float x[], + short tcx_lpc_shaped_ari, + const float lpcGains[], + const int lg, + float lf_deemph_factors[] +); + +float SQ_gain( /* output: SQ gain */ + float x[], /* input: vector to quantize */ + int nbitsSQ, /* input: number of bits targeted */ + int lg /* input: vector size (2048 max) */ +); + +void tcx_scalar_quantization( + float *x, /* i: input coefficients */ + int *xq, /* o: quantized coefficients */ + int L_frame, /* i: frame length */ + float gain, /* i: quantization gain */ + float offset, /* i: rounding offset (deadzone) */ + int *memQuantZeros, /* o: coefficients set to 0 */ + const int alfe_flag +); + +int tcx_scalar_quantization_rateloop( + float *x, /* i : input coefficients */ + int *xq, /* o : quantized coefficients */ + int L_frame, /* i : frame length */ + float *gain, /* i/o: quantization gain */ + float offset, /* i : rounding offset (deadzone) */ + int *memQuantZeros, /* o : coefficients set to 0 */ + int *lastnz_out, /* i/o: last nonzero coeff index */ + int target, /* i : target number of bits */ + int *nEncoded, /* o : number of encoded coeff */ + int *stop, /* i/o: stop param */ + int sqBits_in_noStop, /* i : number of sqBits as determined in prev. quant. stage, w/o using stop mechanism (ie might exceed target bits) */ + int sqBits_in, /* i : number of sqBits as determined in prev. quant. stage, using stop mechanism (ie always <= target bits) */ + int tcxRateLoopOpt, /* i : turns on/off rateloop optimization */ + const int tcxonly, + CONTEXT_HM_CONFIG *hm_cfg +); + +void QuantizeGain( + int n, + float * pGain, + int * pQuantizedGain +); + +void tcx_noise_factor( + float *x_orig, /* i: unquantized mdct coefficients */ + float *sqQ, /* i: quantized mdct coefficients */ + int iFirstLine, /* i: first coefficient to be considered */ + int lowpassLine, /* i: last nonzero coefficients after low-pass */ + int nMinHoleSize, /* i: minimum size of hole to be checked */ + int L_frame, /* i: frame length */ + float gain_tcx, /* i: tcx gain */ + float tiltCompFactor, /* i: LPC tilt compensation factor */ + float *fac_ns, /* o: noise factor */ + int *quantized_fac_ns /* o: quantized noise factor */ +); + +void tcx_noise_filling( + float *Q, + const int noiseFillSeed, + const int iFirstLine, + const int lowpassLine, + const int nTransWidth, + const int L_frame, + float tiltCompFactor, + float fac_ns, + unsigned char *infoTCXNoise +); + +void tcx_encoder_memory_update( + const float *wsig, /* i : target weighted signal */ + float *xn_buf, /* i/o: mdct output buffer/TD weigthed synthesis */ + int L_frame_glob, /* i: global frame length */ + const float *Ai, /* i: Unquantized (interpolated) LPC coefficients */ + float *A, /* i: Quantized LPC coefficients */ + float preemph, /* i: preemphasis factor*/ + LPD_state *LPDmem, /* i/o: coder memory state */ + Encoder_State *st, + int m, + float *synth +); + +void tcx_decoder_memory_update( + float *xn_buf, /* i: mdct output buffer */ + float *synth, /* i/o: synth */ + int L_frame_glob, /* i: global frame length */ + float *A, /* i: Quantized LPC coefficients */ + Decoder_State *st, /* i/o : decoder memory state */ + float *syn /* o: st->syn */ +); + + + +int tcx_ari_res_Q_spec( /* Returns: number of bits used (including "bits") */ + const float x_orig[], /* i: original spectrum */ + const int signs[], /* i: signs (x_orig[.]<0) */ + float x_Q[], /* i/o: quantized spectrum */ + int L_frame, /* i: number of lines */ + float gain, /* i: TCX gain */ + int prm[], /* o: bit-stream */ + int target_bits, /* i: number of bits available */ + int bits, /* i: number of bits used so far */ + float deadzone, /* i: quantizer deadzone */ + const float x_fac[] /* i: spectrum post-quantization factors */ +); + +int tcx_ari_res_invQ_spec(/* Returns: number of bits used (including "bits") */ + float x_Q[], /* i/o: quantized spectrum */ + int L_frame, /* i: number of lines */ + const int prm[], /* i: bit-stream */ + int target_bits, /* i: number of bits available */ + int bits, /* i: number of bits used so far */ + float deadzone, /* i: quantizer deadzone */ + const float x_fac[] /* i: spectrum post-quantization factors */ +); + +int tcx_res_Q_gain( + float sqGain, + float *gain_tcx, + int *prm, + int sqTargetBits +); + +int tcx_res_Q_spec( + float *x_orig, + float *x_Q, + int L_frame, + float sqGain, + int *prm, + int sqTargetBits, + int bits, + float sq_round, + const float lf_deemph_factors[] +); + +int tcx_res_invQ_gain( + float *gain_tcx, + const int *prm, + int resQBits +); + +int tcx_res_invQ_spec( + float *x, + int L_frame, + const int *prm, + int resQBits, + int bits, + float sq_round, + const float lf_deemph_factors[] +); + +void InitTnsConfigs( + int nSampleRate, + int L_frame, + STnsConfig tnsConfig[2][2], + int igfStopFreq, + int bitrate +); + +void SetTnsConfig( + TCX_config * tcx_cfg, + int isTCX20, + int isAfterACELP +); + +void ari_copy_states( + Tastat *source, + Tastat *dest +); + +long mul_sbc_14bits( + long r, + long c +); + +void ari_start_encoding_14bits( + Tastat *s +); + +long ari_encode_14bits( + short *ptr, + long bp, + Tastat *s, + long symbol, + unsigned short *cum_freq +); + +long ari_encode_14bits_ext( + int *ptr, + long bp, + Tastat *s, + long symbol, + const unsigned short *cum_freq +); + +long ari_done_encoding_14bits( + int *ptr, + long bp, + Tastat *s +); + +short ari_encode_check_budget_14bits( + long bp, + Tastat *s, + long nb_bits +); + +void ari_start_decoding_14bits( + Decoder_State *st, + Tastat *s +); + +long ari_start_decoding_14bits_prm( + const int *ptr, + long bp, + Tastat *s +); + +void ari_decode_14bits_s17_ext( + Decoder_State *st, + int *res, + Tastat *s, + const unsigned short *cum_freq +); + +void ari_decode_14bits_s27_ext( + Decoder_State *st, + int *res, + Tastat *s, + const unsigned short *cum_freq +); + +void ari_decode_14bits_bit_ext( + Decoder_State *st, + int *res, + Tastat *s +); + +Word16 expfp( /* o: Q15 */ + Word16 x, /* i: mantissa Q15-e */ + Word16 x_e /* i: exponent Q0 */ +); + +void powfp_odd2( + Word16 base, /* Q15 */ + Word16 exp, /* Q0 */ + Word16 *pout1, /* Q15 */ + Word16 *pout2 /* Q15 */ +); + +void tcx_arith_scale_envelope( + Word16 L_spec_core, /* i: number of lines to scale Q0 */ + Word16 L_frame, /* i: number of lines Q0 */ + Word32 env[], /* i: unscaled envelope Q16 */ + Word16 target_bits, /* i: number of available bits Q0 */ + Word16 low_complexity, /* i: low-complexity flag Q0 */ + Word16 s_env[], /* o: scaled envelope Q15-e */ + Word16 *s_env_e /* o: scaled envelope exponent Q0 */ +); + +void tcx_arith_render_envelope( + const Word16 A_ind[], /* i: LPC coefficients of signal envelope */ + Word16 L_frame, /* i: number of spectral lines */ + Word16 L_spec, + Word16 preemph_fac, /* i: pre-emphasis factor */ + Word16 gamma_w, /* i: A_ind -> weighted envelope factor */ + Word16 gamma_uw, /* i: A_ind -> non-weighted envelope factor */ + Word32 env[] /* o: shaped signal envelope */ +); + +long ari_encode_14bits_range( + int *ptr, + long bp, + long bits, + Tastat *s, + unsigned short cum_freq_low, + unsigned short cum_freq_high +); + +long ari_encode_14bits_sign( + int *ptr, + long bp, + long bits, + Tastat *s, + long sign +); + +long ari_done_cbr_encoding_14bits( + int *ptr, + long bp, + long bits, + Tastat *s +); + +long ari_decode_14bits_pow( + const int *ptr, + long bp, + long bits, + int *res, + Tastat *s, + unsigned base +); + +long ari_decode_14bits_sign( + const int *ptr, + long bp, + long bits, + int *res, + Tastat *s +); + +void tcx_arith_encode_envelope( + float spectrum[], /* i/o: MDCT coefficients */ + int signs[], /* o: signs (spectrum[.]<0) */ + int L_frame, /* i: frame or MDCT length */ + int L_frame_orig, /* i: length w/o BW limitation */ + Encoder_State *st, /* i/o: coder state */ + const Word16 A_ind[], /* i: quantised LPC coefficients */ + int target_bits, /* i: number of available bits */ + int prm[], /* o: bitstream parameters */ + int use_hm, /* i: use HM in current frame? */ + int prm_hm[], /* o: HM parameter area */ + short tcxltp_pitch, /* i: TCX LTP pitch in FD, -1 if n/a*/ + int *arith_bits, /* o: bits used for ari. coding */ + int *signaling_bits /* o: bits used for signaling */ + ,int low_complexity /* i: low-complexity flag */ +); + +void tcx_arith_decode_envelope( + float q_spectrum[], /* o: quantised MDCT coefficients */ + int L_frame, /* i: frame or MDCT length */ + int L_frame_orig, /* i: length w/o BW limitation */ + Decoder_State *st, /* i/o: coder state */ + const short coder_type, /* i : coder type */ + const Word16 A_ind[], /* i: quantised LPC coefficients */ + float tcxltp_gain, /* i: TCX LTP gain */ + int target_bits, /* i: number of available bits */ + const int prm[], /* i: bitstream parameters */ + int use_hm, /* i: use HM in current frame? */ + const int prm_hm[], /* i: HM parameter area */ + short tcxltp_pitch, /* i: TCX LTP pitch in FD, -1 if n/a*/ + int *arith_bits, /* o: bits used for ari. coding */ + int *signaling_bits /* o: bits used for signaling */ + ,int low_complexity /* i: low-complexity flag */ +); + +void UnmapIndex( + int PeriodicityIndex, + int Bandwidth, + short LtpPitchLag, + int SmallerLags, + int *FractionalResolution, + int *Lag +); + +int SearchPeriodicityIndex( /* Returns: PeriodicityIndex */ + const float Mdct[], /* (I) Coefficients, Mdct[0..NumCoeffs-1] */ + const float UnfilteredMdct[], /* (I) Unfiltered coefficients, UnfilteredMdct[0..NumCoeffs-1] */ + int NumCoeffs, /* (I) Number of coefficients */ + int TargetBits, /* (I) Target bit budget (excl. Done flag) */ + short LtpPitchLag, + float LtpGain, /* (I) LTP gain */ + float *RelativeScore /* (O) Energy concentration factor */ +); + +void ConfigureContextHm( + int NumCoeffs, /* (I) Number of coefficients */ + int TargetBits, /* (I) Target bit budget (excl. Done flag) */ + int PeriodicityIndex, /* (I) Pitch related index */ + short LtpPitchLag, /* (I) TCX-LTP pitch in F.D. */ + CONTEXT_HM_CONFIG *hm_cfg /* (O) Context-based harmonic model configuration */ +); + +int EncodeIndex( + int Bandwidth, /* 0: NB, 1: (S)WB */ + int PeriodicityIndex, + Encoder_State *st +); + +int CountIndexBits( + int Bandwidth, /* 0: NB, 1: (S)WB */ + int PeriodicityIndex +); + +int DecodeIndex( + Decoder_State *st, + int Bandwidth, /* 0: NB, 1: (S)WB */ + int *PeriodicityIndex +); + + +#define GET_ADJ(T,L) GET_ADJ2(T,L,*FractionalResolution) +#define GET_ADJ2(T,L,F) (((L) << (F)) - (T)) + +int tcx_hm_render( + int lag, /* i: pitch lag */ + int fract_res, /* i: fractional resolution of the lag */ + float LtpGain, /* i: LTP gain */ + Word16 p[] /* o: harmonic model (Q13) */ +); + +void tcx_hm_modify_envelope( + Word16 gain, /* i: HM gain (Q11) */ + int lag, + int fract_res, + Word16 p[], /* i: harmonic model (Q13) */ + Word32 env[], /* i/o: envelope (Q16) */ + int L_frame /* i: number of spectral lines */ +); + +void tcx_hm_analyse( + const float abs_spectrum[], /* i: absolute spectrum */ + int L_frame, /* i: number of spectral lines */ + Word32 env[], /* i/o: envelope shape (Q16) */ + int targetBits, /* i: target bit budget */ + int coder_type, /* i: GC/VC mode */ + int prm_hm[], /* o: HM parameters */ + short LtpPitchLag, /* i: LTP pitch lag or -1 if none */ + float LtpGain, /* i: LTP gain */ + int *hm_bits /* o: bit consumption */ +); + +void tcx_hm_decode( + int L_frame, /* i: number of spectral lines */ + Word32 env[], /* i/o: envelope shape (Q16) */ + int targetBits, /* i: target bit budget */ + int coder_type, /* i: GC/VC mode */ + const int prm_hm[], /* i: HM parameters */ + short LtpPitchLag, /* i: LTP pitch lag or -1 if none */ + float LtpGain , /* i: LTP gain */ + int *hm_bits /* o: bit consumption */ +); + +void coder_tcx( + int n, + TCX_config *tcx_cfg, /* input: configuration of TCX */ + float A[], /* input: quantized coefficients NxAz_q[M+1] */ + Word16 Aqind[], /* input: frame-independent quantized coefficients (M+1) */ + float synth[], + int L_frame_glob, /* input: frame length */ + int L_frameTCX_glob, + int L_spec, + int nb_bits, /* input: bit budget */ + int tcxonly, /* input: only TCX flag */ + float spectrum[], /* i/o: MDCT spectrum */ + LPD_state *LPDmem, /* i/o: memories */ + int prm[], /* output: tcx parameters */ + Encoder_State *st, + CONTEXT_HM_CONFIG *hm_cfg +); + +void coder_tcx_post( + Encoder_State *st, + LPD_state *LPDmem, + TCX_config *tcx_cfg, + float *synth, + float *A, + const float *Ai, + float *wsig +); + +void decoder_tcx( + TCX_config *tcx_cfg, /* input: configuration of TCX */ + int prm[], /* input: parameters */ + float A[], /* input: coefficients NxAz[M+1] */ + Word16 Aind[], /* input: frame-independent coefficients Az[M+1] */ + int L_frame, /* input: frame length */ + int L_frameTCX, + int L_spec, + float synth[], /* in/out: synth[-M..lg] */ + float synthFB[], + Decoder_State *st, /* i/o : coder memory state */ + const short coder_type, + int bfi, /* input: Bad frame indicator */ + int frame_cnt, /* input: frame counter in the super_frame */ + float stab_fac /* input: stability of isf */ +); + +void decoder_tcx_post( + Decoder_State *st, + float *synth, + float *synthFB, + float *A, + int bfi +); + +void coder_acelp( + ACELP_config *acelp_cfg, /* i/o: configuration of the ACELP */ + const short coder_type, /* i : coding type */ + const float A[], /* i : coefficients 4xAz[M+1] */ + const float Aq[], /* i : coefficients 4xAz_q[M+1] */ + const float speech[], /* i : speech[-M..lg] */ + float synth[], /* o : synthesis */ + LPD_state *LPDmem, /* i/o: ACELP memories */ + const float voicing[], /* i : open-loop LTP gain */ + const short T_op[], /* i : open-loop LTP lag */ + int *prm, /* o : acelp parameters */ + const float stab_fac, + Encoder_State *st, /* i/o : coder memory state */ + HANDLE_PLC_ENC_EVS hPlc_Ext, + const short target_bits, + float *gain_pitch_buf,/* o : gain pitch values */ + float *gain_code_buf, /* o : gain code values */ + float *pitch_buf, /* o : pitch values for each subfr.*/ + float *voice_factors, /* o : voicing factors */ + float *bwe_exc /* o : excitation for SWB TBE */ +); + +void coder_acelp_rf( + const short target_bits, /* i: target bits */ + const float speech[], /* i : speech[-M..lg] */ + const short coder_type, /* i : coding type */ + const short rf_frame_type, /* i : rf_frame_type */ + const float A[], /* i : coefficients 4xAz[M+1] */ + const float Aq[], /* i : coefficients 4xAz_q[M+1] */ + const float voicing[], /* i : open-loop LTP gain */ + const short T_op[], /* i : open-loop LTP lag */ + const float stab_fac, /* i : LP stability factor */ + Encoder_State *st, /* i/o: coder memory state */ + ACELP_config *acelp_cfg, /* i/o: configuration of the ACELP */ + float *exc_rf, /* i/o: pointer to RF excitation */ + float *syn_rf /* i/o: pointer to RF synthesis */ +); + +void decoder_acelp( + Decoder_State *st, /* i/o: coder memory state */ + const short coder_type, /* i : coder type */ + int prm[], /* i : parameters */ + const float A[], /* i : coefficients NxAz[M+1] */ + ACELP_config acelp_cfg, /* i : ACELP config */ + float synth[], /* i/o: synthesis */ + int *pT, /* o : pitch for all subframe */ + float *pgainT, /* o : pitch gain for all subfr */ + const float stab_fac /* i : stability of isf */ + ,float *pitch_buffer /* o : pitch values for each subfr.*/ + ,float *voice_factors /* o : voicing factors */ + ,const short LSF_Q_prediction/* i : LSF prediction mode */ + ,float *bwe_exc /* o : excitation for SWB TBE */ +); + +void enc_prm( + const short coder_type, /* i : coding type */ + int param[], /* i : parameters */ + int param_lpc[], /* i : LPC parameters */ + Encoder_State *st, /* i/o: quantization Analysis values*/ + const short L_Frame, /* i : frame length */ + CONTEXT_HM_CONFIG hm_cfg[], + short * bits_param_lpc, + short no_param_lpc +); + +void enc_prm_rf( + Encoder_State *st, + const short rf_frame_type, + const short fec_offset +); + +void dec_prm( + short *core, /* (0) : current frame mode */ + short *last_core, /* (0) : last frame mode */ + short *coder_type, /* o : coder type */ + int param[], /* (o) : decoded parameters */ + int param_lpc[], /* (i) : LPC parameters */ + Word16 *total_nbbits, /* i/o : number of bits / decoded bits */ + Decoder_State *st, /* i/o: decoder memory state */ + const int L_frame, + short * bitsRead +); + +void dec_prm_core( + Decoder_State *st +); + +void gauss_L2( + const float h[], /* i : weighted LP filter impulse response */ + float code[], /* o : gaussian excitation */ + float y2[], /* i : zero-memory filtered code. excitation */ + float y11[], /* o : zero-memory filtered gauss. excitation */ + float *gain, /* o : excitation gain */ + float g_corr[], /* i/o : correlation structure for gain coding */ + float gain_pit, /* i : unquantized gain of code */ + float tilt_code, /* i : tilt of code */ + const float *Aq, /* i : quantized LPCs */ + float formant_enh_num, /* i: formant enhancement factor */ + short *seed_acelp /*i/o: random seed */ +); + +void gaus_L2_dec( + float *code, /* o: decoded gaussian codevector */ + float tilt_code, + const float *A, + float formant_enh_num, + short *seed_acelp /*i/o: random seed */ +); + +float interpolation( /* o: interpolated value */ + const float *x, /* i: input vector */ + const float *win, /* i: interpolation window */ + const short frac, /* i: fraction */ + const short up_samp, /* i: upsampling factor */ + const short nb_coef /* i: nb of filter coef */ +); + +void predict_signal( + const float excI[], /* i : input excitation buffer */ + float excO[], /* o : output excitation buffer */ + const short T0, /* i : integer pitch lag */ + short frac, /* i : fraction of lag */ + const short frac_max,/* i : max fraction */ + const short L_subfr /* i : subframe size */ +); + +void tcx_ltp_encode( + int tcxltp_on, + int tcxOnly, + int tcxMode, + int L_frame, + int L_subfr, + float *speech, + float *speech_ltp, + float *wsp, + int Top, + int *ltp_param, + int *ltp_bits, + int *pitch_int, + int *pitch_fr, + float *gain, + int *pitch_int_past, + int *pitch_fr_past, + float *gain_past, + float *norm_corr_past, + int last_core, + int pitmin, + int pitfr1, + int pitfr2, + int pitmax, + int pitres, + struct TransientDetection const * pTransientDetection, + int SideInfoOnly, + float *A, + int lpcorder +); + +void tcx_ltp_post( int tcxltp_on, + short core, + int L_frame, + int L_frame_core, + int delay, + float *sig, + float *tcx_buf, + short tcx_buf_len, + int bfi, + int pitch_int, + int pitch_fr, + float gain, + int *pitch_int_past, + int *pitch_fr_past, + float *gain_past, + int *filtIdx_past, + int pitres, + int *pitres_past, + float damping, + int SideInfoOnly, + float *mem_in, + float *mem_out, + int bitrate + ); + +int tcx_ltp_decode_params( + int *ltp_param, + int *pitch_int, + int *pitch_fr, + float *gain, + int pitmin, + int pitfr1, + int pitfr2, + int pitmax, + int pitres +); + + +int enc_lsf_tcxlpc( + int **indices, /* i : Ptr to VQ indices */ + Encoder_State *st /* i/o: Encoder state */ +); + +void msvq_enc +( + const float *const *cb, /* i : Codebook (indexed cb[*stages][levels][p]) */ + const int dims[], /* i : Dimension of each codebook stage (NULL: full dim.) */ + const int offs[], /* i : Starting dimension of each codebook stage (NULL: 0) */ + float u[], /* i : Vector to be encoded (prediction and mean removed) */ + const int *levels, /* i : Number of levels in each stage */ + int maxC, /* i : Tree search size (number of candidates kept from */ + /* one stage to the next == M-best) */ + int stages, /* i : Number of stages */ + float w[], /* i : Weights */ + int N, /* i : Vector dimension */ + int maxN, /* i : Codebook dimension */ + int Idx[] /* o : Indices */ +); + +void msvq_dec +( + const float *const *cb, /* i : Codebook (indexed cb[*stages][levels][p]) */ + const int dims[], /* i : Dimension of each codebook stage (NULL: full dim.) */ + const int offs[], /* i : Starting dimension of each codebook stage (NULL: 0) */ + int stages, /* i : Number of stages */ + int N, /* i : Vector dimension */ + int maxN, /* i : Codebook dimension */ + const int Idx[], /* i : Indices */ + float *uq, /* o : quantized vector */ + Word16 *uq_ind /* o : quantized vector (fixed point) */ +); + + +void PulseResynchronization( + float const * src_exc, + float * dst_exc, + int nFrameLength, + int nSubframes, + float pitchStart, + float pitchEnd +); + + +void con_acelp( + float A[], /* i : coefficients NxAz[M+1] */ + int coder_type, /* i : ACELP coder type */ + float synth[], /* i/o: synthesis */ + int *pT, /* o : pitch for all subframe */ + float *pgainT, /* o : pitch gain for all subfr */ + float stab_fac, /* i : stability of isf */ + Decoder_State *st, /* i/o: coder memory state */ + float pitch_buffer[], /* i/o: floating pitch values for each subframe */ + float *voice_factors, /* o : voicing factors */ + float *bwe_exc /* o : excitation for SWB TBE */ +); + +void con_tcx( + Decoder_State* st, /* i/o: coder memory state */ + float synth[] /* i/o: synth[] */ +); + +int tcxlpc_get_cdk( /* o : codebook index */ + int coder_type /* (I) GC/VC indicator */ +); + +int lsf_msvq_ma_encprm( + Encoder_State *st, + int *param_lpc, + int core, + int acelp_mode, + int acelp_midLpc, + short * bits_param_lpc, + short no_indices +); + +int lsf_msvq_ma_decprm( + Decoder_State *st, + int *param_lpc, + int core, + int acelp_mode, + int acelp_midLpc, + int narrowBand, + int sr_core +); + +int dec_lsf_tcxlpc( + Decoder_State *st, /* (I/O) Decoder state */ + int **indices, /* (O) Ptr to VQ indices */ + int narrowband, /* (I) narrowband flag */ + int cdk /* (I) codebook selector */ +); + +int D_lsf_tcxlpc( + const int indices[], /* (I) VQ indices */ + float lsf_q[], /* (O) quantized lsf */ + Word16 lsp_q_ind[], /* (O) quantized lsp (w/o MA prediction) */ + int narrowband, /* (I) narrowband flag */ + int cdk, /* (I) codebook selector */ + float mem_MA[] /* (I) MA memory */ +); + +void lsf_update_memory( + int narrowband, /* i : narrowband flag */ + const float qlsf[], /* i : quantized lsf coefficients */ + float old_mem_MA[], /* i : MA memory */ + float mem_MA[] /* o : updated MA memory */ +); + +int Q_lsf_tcxlpc( + /* const */ float lsf[], /* (I) original lsf */ + float lsf_q[], /* (O) quantized lsf */ + Word16 lsp_q_ind[], /* (O) quantized lsp (w/o MA prediction) */ + int indices[], /* (O) VQ indices */ + int narrowband, /* (I) narrowband flag */ + int cdk, /* (I) codebook selector */ + float mem_MA[], /* (I) MA memory */ + int coder_type, /* (I) acelp extended mode*/ + float *Bin_Ener /* (I) Spectrum energy*/ +); + +int E_LPC_lsp_unweight( + /* const */ float lsp_w[], /* (I): weighted lsp */ + float lsp_uw[], /* (O): unweighted lsp */ + float lsf_uw[], /* (O): unweighted lsf */ + float inv_gamma /* (I): inverse weighting factor */ +); + +int lsf_ind_is_active( + const Word16 lsf_q_ind[], + const float means[], + int bandwidth, + int cdk +); + +void midlsf_enc( + float qlsf0[], + float qlsf1[], + const float lsf[], + short *idx, + int N, + float *Bin_Ener, + int narrowBand, + int sr_core, + int coder_type +); + +void midlsf_dec( + float qlsf0[], + float qlsf1[], + short idx, + float qlsf[], + int N, + int coder_type, + short *mid_lsf_int, + short prev_bfi, + short safety_net +); + +void lsf_end_enc( + Encoder_State *st, + const float *lsf, + float *qlsf, + float *mem_AR, + float *mem_MA, + const short nBits, + const short coder_type_org, + const short bwidth, + float *Bin_Ener, + const float int_fs, + long core_brate, + float *streaklimit, + short *pstreaklen, + short force_sf, + short rf_flag, + short mode2_flag, + int * lpc_param, + short * no_stages, + short * bits_param_lpc, + short coder_type_raw +); + +void lsf_end_dec( + Decoder_State *st, + const short coder_type_org, + const short bwidth, + const short nBits, + float *qlsf, + float *mem_AR, + float *mem_MA, + const float int_fs, + long core_brate, + unsigned int *p_offset_scale1, + unsigned int *p_offset_scale2, + unsigned int *p_offset_scale1_p, + unsigned int *p_offset_scale2_p, + short *p_no_scales, + short *p_no_scales_p, + short *safety_net, + int *lpc_param, + short *LSF_Q_prediction, /* o : LSF prediction mode */ + int * nb_indices +); + +short find_pred_mode( + const short coder_type, + const short bwidth, + const float int_fs, + short * p_mode_lvq, + short * p_mode_lvq_p, + short core_brate +); + +void lpc_quantization( + Encoder_State * st, + int core, + int lpcQuantization, + float lsf_old[], + const float lsp[], + const float lspmid[], + float lsp_q[], + float lsf_q[], + float lspmid_q[], + float mem_MA[], + float mem_AR[], + int narrowBand, + short coder_type, + int acelp_midLpc, + int param_lpc[], + int nbits_lpc[], + short *seed_acelp, + int sr_core, + float *Bin_Ener, + float *Bin_Ener_old, + short * bits_param_lpc, + short * no_param_lpc +); + +void lpc_unquantize( + Decoder_State * st, + float *lsfold, + float *lspold, + float *lsf, + float *lsp, + int lpcQuantization, + int *param_lpc, + int numlpc, + int core, + float *mem_MA, + float *lspmid, + float *lsfmid, + short coder_type, + int acelp_midLpc, + int narrow_band, + short *seed_acelp, + int sr_core, + short *mid_lsf_int, + short prev_bfi, + short *LSF_Q_prediction, /* o : LSF prediction mode */ + short *safety_net +); + +void dlpc_bfi( + int L_frame, + float *lsf_q, /* o : quantized lsfs */ + const float *lsfold, /* i : past quantized lsf */ + const short last_good, /* i : last good received frame */ + const short nbLostCmpt, /* i : counter of consecutive bad frames */ + float mem_MA[], /* i/o: quantizer memory for MA model */ + float mem_AR[], /* i/o: quantizer memory for MA model */ + float *stab_fac, /* i : lsf stability factor */ + float *lsf_adaptive_mean,/* i : lsf adaptive mean, updated when BFI==0 */ + int numlpc, /* i : Number of division per superframe */ + float lsf_cng[], + int plcBackgroundNoiseUpdated, + float *lsf_q_cng, /* o : quantized lsfs of background noise */ + float *old_lsf_q_cng, /* o : old quantized lsfs for background noise */ + const float lsfBase[] /* i : base for differential lsf coding */ +); + +int decode_lpc_stoch(short *ptr, + int numlpc, + int *param_lpc, + int mode, + int lpc_quant_type, + short *isf_model, + int *isf_end_nbits, + int *isf_mid_nbits + ); + +void lsfi_enc( + float qisf0[], + float qisf1[], + float isf[], + short *idx +); + +void lsfi_dec( + float qisf0[], + float qisf1[], + short idx, + float qisf[] +); + +void lsf_dec_bfi( + short codec_mode, /* i: : codec_mode: MODE1 | MODE2 */ + float *lsf, /* o : estimated LSF vector */ + const float *lsfold, /* i : past quantized lsf */ + float *lsf_adaptive_mean, /* i : lsf adaptive mean, updated when BFI==0 */ + const float lsfBase[], /* i : base for differential lsf coding */ + float *mem_MA, /* i/o: quantizer memory for MA model */ + float *mem_AR, /* o : quantizer memory for AR model */ + float stab_fac, /* i : lsf stability factor */ + short last_coder_type, /* i : last coder type */ + short L_frame, /* i : frame length */ + const short last_good, /* i : last good received frame */ + const short nbLostCmpt, /* i : counter of consecutive bad frames */ + int plcBackgroundNoiseUpdated, /* i : background noise already updated? */ + float *lsf_q_cng, /* o : quantized lsfs of background noise */ + float *lsf_cng, /* i : long term target for fading to bg noise*/ + float *old_lsf_q_cng, /* o : old quantized lsfs for background noise*/ + short Last_GSC_pit_band_idx, /* i : AC mode (GSC) - Last pitch band index */ + short Opt_AMR_WB, /* i : IO flag */ + const short MODE1_bwidth /* i : coded bandwidth */ +); + +float const * PlcGetlsfBase( + int const lpcQuantization, + int const narrowBand, + int const sr_core +); + +void Unified_weighting( + float Bin_Ener_128[], /* i : FFT Bin energy 128 bins in two sets */ + const float lsf[], /* i : LSF vector */ + float w[], /* o : LP weighting filter (numerator) */ + const short narrowBand, /* i : flag for Narrowband */ + const short unvoiced, /* i : flag for Unvoiced frame */ + const short sr_core, /* i : sampling rate of core-coder */ + const int order /* i : LP order */ +); + +short vad_init( + T_CldfbVadState *st +); + +short vad_proc( + float realValues[16][60], /* CLDFB real values */ + float imagValues[16][60], /* CLDFB imag values */ + float *sb_power, /* Energy of CLDFB data */ + int numBands, /* number of input bands */ + T_CldfbVadState *vad_st, /* VAD state */ + short *cldfb_addition, + short vada_flag +); + +void subband_FFT( + float Sr[16][60], /*(i) real part */ + float Si[16][60], /*(i) imag part */ + float *spec_amp /*(o) spectral amplitude*/ +); + +int update_decision( + T_CldfbVadState *st, + float snr, /*(i) frequency domain SNR */ + float tsnr, /*(i) time domain SNR */ + float frame_energy, /*(i) current frame energy */ + float high_eng, /*(i) current frame high frequency energy*/ + int vad_flag, + int music_backgound_f /*(i) background music flag */ +); + +void frame_spec_dif_cor_rate( + float spec_amp[], /*(i) spectral amplitude */ + float pre_spec_low_dif[], /*(io) low spectrum different*/ + float f_tonality_rate[] /*(o) tonality rate*/ +); + +void ltd_stable( + float frames_power[], /*(io) energy of several frames*/ + float ltd_stable_rate[], /*(o) time-domain stable rate*/ + float frame_energy, /*(i) current frame energy*/ + int frameloop /*(i) number of frames*/ +); + +void SNR_calc( + float frame_sb_energy[], /*(i) energy of sub-band divided non-uniformly*/ + float sb_bg_energy[], /*(i) sub-band background energy*/ + float t_bg_energy, /*(i) time background energy of several frames*/ + float *snr, /*(o) frequency domain SNR */ + float *tsnr, /*(o) time domain SNR */ + float frame_energy, /*(i) current frame energy */ + int bandwidth /*(i) band width*/ +); + + + + +void background_update( + T_CldfbVadState *st, + float frame_energy, /*(i) current frame energy 2*/ + int update_flag, /*(i) current frame update flag*/ + int music_backgound_f /*(i) background music flag*/ + , float snr +); + +void bg_music_decision( + T_CldfbVadState *st, + int *music_backgound_f, /*(i) background music flag*/ + float frame_energy /*(i) current frame energy 1*/ +); + +void est_energy( + float sb_power[], /*(o) energy of sub-band divided uniformly*/ + float frame_sb_energy[], /*(o) energy of sub-band divided non-uniformly*/ + float *p_frame_energy, /*(o) frame energy 1*/ + float *p_frame_energy2, /*(o) frame energy 2*/ + float *p_high_energy, /*(o) high frequency energy*/ + int bw /*(i) band width*/ +); + +void spec_center( + float spec_power[], /*(i) energy of sub-band divided uniformly*/ + float sp_center[], /*(o) spectral center*/ + int bandwidth /*(i) band width*/ +); + +void spec_flatness( + float spec_amp[], /*(i) spectral amplitude*/ + float smooth_spec_amp[], /*(i) smoothed spectral amplitude*/ + float sSFM[] /*(o) spectral flatness rate*/ +); + +int vad_decision( + T_CldfbVadState *st, + float snr , /*(i) frequency domain SNR */ + float tsnr, /*(i) time domain SNR */ + float snr_flux, /*(i) average tsnr of several frames*/ + float lt_snr, /*(i)long time SNR calculated by fg_energy and bg_energy*/ + float lt_snr_org, /*(i)original long time SNR*/ + float lf_snr, /*(i) long time frequency domain SNR calculated by l_speech_snr and l_silence_snr*/ + float frame_energy, /*(i) current frame energy */ + int music_backgound_f /*(i) background music flag*/ +); + +int comvad_decision( + T_CldfbVadState *st, + float snr, /*(i) frequency domain SNR */ + float tsnr, /*(i) time domain SNR */ + float snr_flux, /*(i) average tsnr of several frames*/ + float lt_snr, /*(i) long time SNR calculated by fg_energy and bg_energy*/ + float lt_snr_org, /*(i) original long time SNR*/ + float lf_snr, /*(i) long time frequency domain + SNR calculated by l_speech_snr and l_silence_snr*/ + float frame_energy, /*(i) current frame energy */ + int music_backgound_f, /*(i) background music flag*/ + short *cldfb_addition, + short vada_flag +); + +void calc_snr_flux( + float tsnr, /*(i) time-domain SNR*/ + float pre_snr[], /*(io) time-domain SNR storage*/ + float *snr_flux /*(o) average tsnr*/ +); + +void calc_lt_snr( + float *lt_snr_org, /*(o)original long time SNR*/ + float *lt_snr, /*(o)long time SNR calculated by fg_energy and bg_energy*/ + float fg_energy, /*(i)foreground energy sum */ + int fg_energy_count, /*(i) number of the foreground energy frame */ + float bg_energy, /*(i)background energy sum */ + int bg_energy_count, /*(i) number of the background energy frame */ + int bw_index, /*(i) band width index*/ + float lt_noise_sp_center0 /*(i)long time noise spectral center by 0*/ +); + +void calc_lf_snr( + float *lf_snr_smooth, /*(o) smoothed lf_snr*/ + float *lf_snr, /*(o) long time frequency domain SNR calculated by l_speech_snr and l_silence_snr*/ + float l_speech_snr, /*(i) sum of active frames snr */ + int l_speech_snr_count, /*(i) number of the active frame */ + float l_silence_snr, /*(i) sum of the nonactive frames snr*/ + int l_silence_snr_count, /*(i) number of the nonactive frame */ + int fg_energy_count, /*(i) number of the foreground energy frame */ + int bg_energy_count, /*(i) number of the background energy frame */ + int bw_index /*(i) band width index*/ +); + +float construct_snr_thresh( + float sp_center[], /*(i) spectral center*/ + float snr_flux, /*(i) snr flux*/ + float lt_snr, /*(i) long time time domain snr*/ + float lf_snr, /*(i) long time frequency domain snr*/ + int continuous_speech_num, /*(i) continuous speech number*/ + int continuous_noise_num, /*(i) continuous noise number*/ + int fg_energy_est_start, /*(i) whether if estimated energy*/ + int bw_index /*(i) band width index*/ +); + +void createFdCngCom( + HANDLE_FD_CNG_COM* hFdCngCom +); + +void deleteFdCngCom( + HANDLE_FD_CNG_COM * hFdCngCom +); + +void initFdCngCom( + HANDLE_FD_CNG_COM hs, /* i/o: Contains the variables related to the FD-based CNG process */ + float scale +); + +void initPartitions( + const int * part_in, + int npart_in, + int startBand, + int stopBand, + int * part_out, + int * npart_out, + int * midband, + float * psize, + float * psize_inv, + int stopBandFR +); + +void minimum_statistics( + int len, /* i : Vector length */ + int lenFFT, /* i : Length of the FFT part of the vectors */ + float * psize, + float * msPeriodog, /* i : Periodograms */ + float * msNoiseFloor, + float * msNoiseEst, /* o : Noise estimates */ + float * msAlpha, + float * msPsd, + float * msPsdFirstMoment, + float * msPsdSecondMoment, + float * msMinBuf, + float * msBminWin, + float * msBminSubWin, + float * msCurrentMin, + float * msCurrentMinOut, + float * msCurrentMinSubWindow, + int * msLocalMinFlag, + int * msNewMinFlag, + float * msPeriodogBuf, + int * msPeriodogBufPtr, + HANDLE_FD_CNG_COM st /* i/o: FD_CNG structure containing all buffers and variables */ +); + +void generate_comfort_noise_enc( + Encoder_State *stcod +); + +void generate_comfort_noise_dec( + float ** bufferReal, /* o : Real part of input bands */ + float ** bufferImag, /* o : Imaginary part of input bands */ + Decoder_State *stdec +); + +void generate_comfort_noise_dec_hf( + float ** bufferReal, /* o : Real part of input bands */ + float ** bufferImag, /* o : Imaginary part of input bands */ + Decoder_State *stdec +); + +void generate_masking_noise( + float * timeDomainBuffer, /* i/o: time-domain signal */ + HANDLE_FD_CNG_COM st, /* i/o: FD_CNG structure containing all buffers and variables */ + short length, + short core +); + +void generate_masking_noise_update_seed( + HANDLE_FD_CNG_COM st /* i/o: FD_CNG structure containing all buffers and variables */ +); + +void generate_masking_noise_mdct( + float * mdctBuffer, /* i/o: time-domain signal */ + HANDLE_FD_CNG_COM st /* i/o: FD_CNG structure containing all buffers and variables */ +); + +void apply_scale( + float *scale, + int bandwidth, + int bitrate +); + +void compress_range( + float* in, + float* out, + int len +); + +/* Apply some dynamic range expansion to undo the compression */ +void expand_range( + float* in, + float* out, + int len +); + +void bandcombinepow( + float* bandpow, /* i : Power for each band */ + int nband, /* i : Number of bands */ + int* part, /* i : Partition upper boundaries (band indices starting from 0) */ + int npart, /* i : Number of partitions */ + float* psize_inv, /* i : Inverse partition sizes */ + float* partpow /* o : Power for each partition */ +); + +void scalebands( + float* partpow, /* i : Power for each partition */ + int* part, /* i : Partition upper boundaries (band indices starting from 0) */ + int npart, /* i : Number of partitions */ + int* midband, /* i : Central band of each partition */ + int nFFTpart, /* i : Number of FFT partitions */ + int nband, /* i : Number of bands */ + float* bandpow, /* o : Power for each band */ + short flag_fft_en +); + +void getmidbands( + int* part, /* i : Partition upper boundaries (band indices starting from 0) */ + int npart, /* i : Number of partitions */ + int* midband, /* o : Central band of each partition */ + float* psize, /* o : Partition sizes */ + float* psize_inv /* o : Inverse of partition sizes */ +); + +void AnalysisSTFT( + const float * timeDomainInput, + float * fftBuffer, /* o : FFT bins */ + HANDLE_FD_CNG_COM st /* i/o: FD_CNG structure containing all buffers and variables */ +); + +void SynthesisSTFT( + float * fftBuffer, + float * timeDomainOutput, + float * olapBuffer, + const float * olapWin, + int tcx_transition, HANDLE_FD_CNG_COM st +); + +void rand_gauss( + float *x, + short *seed +); + +void lpc_from_spectrum( + float* powspec, + int start, + int stop, + int fftlen, + const float *fftSineTab, + float *A, + float preemph_fac +); + +void createFdCngDec( + HANDLE_FD_CNG_DEC* hFdCngDec +); + +void deleteFdCngDec( + HANDLE_FD_CNG_DEC * hFdCngDec +); + +void initFdCngDec( + HANDLE_FD_CNG_DEC hs, /* i/o: Contains the variables related to the FD-based CNG process */ + float scale /* i: scaling factor */ +); +void configureFdCngDec( + HANDLE_FD_CNG_DEC hs, /* i/o: Contains the variables related to the FD-based CNG process */ + short bandwidth, + int bitrate, + short L_frame +); + +void configure_noise_estimation_dec( + HANDLE_FD_CNG_DEC st /* i/o: FD_CNG structure containing all buffers and variables */ +); + +void ApplyFdCng( + float * timeDomainInput, + float ** realBuffer, /* i/o: Real part of the buffer */ + float ** imagBuffer, /* i/o: Imaginary part of the buffer */ + HANDLE_FD_CNG_DEC st, /* i/o: FD_CNG structure containing all buffers and variables */ + unsigned char m_frame_type, /* i : Type of frame at the decoder side */ + Decoder_State *stdec, + const int concealWholeFrame, /* i : binary flag indicating frame loss */ + short is_music +); + +void perform_noise_estimation_dec( + const float * timeDomainInput, + HANDLE_FD_CNG_DEC st /* i/o: FD_CNG structure containing all buffers and variables */ +); + +void FdCng_decodeSID( + Decoder_State *st /* i/o: decoder state structure */ +); + +void FdCng_exc( + HANDLE_FD_CNG_COM hs, + short *CNG_mode, + short L_frame, + float *lsp_old, + short first_CNG, + float *lsp_CNG, + float *Aq, /* o: LPC coeffs */ + float *lsp_new, /* o: lsp */ + float *lsf_new, /* o: lsf */ + float *exc, /* o: LP excitation */ + float *exc2, /* o: LP excitation */ + float *bwe_exc /* o: LP excitation for BWE */ +); + +void noisy_speech_detection( + const short vad, + const float * ftimeInPtr, /* i : input time-domain frame */ + const int frameSize, /* i : frame size */ + const float * msNoiseEst, /* i : noise estimate over all critical bands */ + const float * psize, /* i : partition sizes */ + const int nFFTpart, /* i : Number of partitions taken into account */ + float *lp_noise, /* i/o: long term total Noise energy average */ + float *lp_speech, /* i/o: long term active speech energy average */ + short *flag_noisy_speech +); + + +void createFdCngEnc( + HANDLE_FD_CNG_ENC* hFdCngEnc +); + +void deleteFdCngEnc( + HANDLE_FD_CNG_ENC * hFdCngEnc +); + +void configureFdCngEnc( + HANDLE_FD_CNG_ENC hs, /* i/o: Contains the variables related to the FD-based CNG process */ + short bandwidth, + int bitrate +); + +void initFdCngEnc( + HANDLE_FD_CNG_ENC hs, /* i/o: Contains the variables related to the FD-based CNG process */ + int input_Fs, /* i: input signal sampling frequency in Hz */ + float scale /* i: scaling factor */ +); + +void resetFdCngEnc( + Encoder_State * st +); + +void perform_noise_estimation_enc( + float *band_energies, /* i: energy in critical bands without minimum noise floor E_MIN */ + float *enerBuffer, + HANDLE_FD_CNG_ENC st +); + +void AdjustFirstSID( + int npart, + float * msPeriodog, + float * energy_ho, + float * msNoiseEst, + float * msNoiseEst_old, + short * active_frame_counter, + Encoder_State *stcod +); + +void FdCng_encodeSID( + HANDLE_FD_CNG_ENC st, /* i/o: FD_CNG structure containing all buffers and variables */ + Encoder_State *corest, + float preemph_fac +); + +void GetParameters( + ParamsBitMap const * paramsBitMap, + int nParams, + void const * pParameter, + int ** pStream, + int * pnSize, + int * pnBits +); + +void SetParameters( + ParamsBitMap const * paramsBitMap, + int nParams, + void * pParameter, + int const ** pStream, + int * pnSize +); + +void WriteToBitstream( + ParamsBitMap const * paramsBitMap, + int nParams, + int const ** pStream, + int * pnSize, Encoder_State *st, + int * pnBits +); + +void ReadFromBitstream( + ParamsBitMap const * paramsBitMap, + int nArrayLength, + Decoder_State *st, + int ** pStream, + int * pnSize +); + +void const * GetTnsFilterOrder(void const * p, int index, int * pValue); +void * SetTnsFilterOrder(void * p, int index, int value); +void const * GetNumOfTnsFilters(void const * p, int index, int * pValue); +void * SetNumOfTnsFilters(void * p, int index, int value); +void const * GetTnsEnabled(void const * p, int index, int * pValue); +void * SetTnsEnabled(void * p, int index, int value); +void const * GetTnsEnabledSingleFilter(void const * p, int index, int * pValue); +void * SetTnsEnabledSingleFilter(void * p, int index, int value); +void const * GetTnsFilterCoeff(void const * p, int index, int * pValue); +void * SetTnsFilterCoeff(void * p, int index, int value); + +int GetSWBTCX10TnsFilterCoeffBits(int value, int index); +int EncodeSWBTCX10TnsFilterCoeff(int value, int index); +int DecodeSWBTCX10TnsFilterCoeff(Decoder_State *st, int index, int * pValue); +int GetSWBTCX20TnsFilterCoeffBits(int value, int index); +int EncodeSWBTCX20TnsFilterCoeff(int value, int index); +int DecodeSWBTCX20TnsFilterCoeff(Decoder_State *st, int index, int * pValue); + +int GetWBTCX20TnsFilterCoeffBits(int value, int index); +int EncodeWBTCX20TnsFilterCoeff(int value, int index); +int DecodeWBTCX20TnsFilterCoeff(Decoder_State *st, int index, int * pValue); + +int GetTnsFilterOrderBitsSWBTCX10(int value, int index); +int EncodeTnsFilterOrderSWBTCX10(int value, int index); +int DecodeTnsFilterOrderSWBTCX10(Decoder_State *st, int index, int * pValue); +int GetTnsFilterOrderBitsSWBTCX20(int value, int index); +int EncodeTnsFilterOrderSWBTCX20(int value, int index); +int DecodeTnsFilterOrderSWBTCX20(Decoder_State *st, int index, int * pValue); +int GetTnsFilterOrderBits(int value, int index); +int EncodeTnsFilterOrder(int value, int index); +int DecodeTnsFilterOrder(Decoder_State *st, int index, int * pValue); + +void ResetTnsData( + STnsData * pTnsData +); + +void ClearTnsFilterCoefficients( + STnsFilter * pTnsFilter +); + +TNS_ERROR InitTnsConfiguration( + int nSampleRate, + int frameLength, + STnsConfig * pTnsConfig, + int igfStopFreq, + int bitrate +); + +int DetectTnsFilt( + STnsConfig const * pTnsConfig, + float const pSpectrum[], + STnsData * pTnsData, + float* predictionGain +); + +TNS_ERROR ApplyTnsFilter( + STnsConfig const * pTnsConfig, + STnsData const * pTnsData, + float spectrum[], + int fIsAnalysis +); + +int ITF_Detect( + float const pSpectrum[], + short int startLine, + short int stopLine, + int maxOrder, + float* A, + float* predictionGain, + int* curr_order +); + +TNS_ERROR ITF_Apply( + float spectrum[], + short int startLine, + short int stopLine, + const float* A, + int curr_order +); + +TNS_ERROR EncodeTnsData( + STnsConfig const * pTnsConfig, + STnsData const * pTnsData, + int * stream, + int * pnSize, + int * pnBits +); + +int DecodeTnsData( + STnsConfig const * pTnsConfig, + int const * stream, + int * pnSize, + STnsData * pTnsData +); + +TNS_ERROR WriteTnsData( + STnsConfig const * pTnsConfig, + int const * stream, + int * pnSize, + Encoder_State *st, + int * pnBits +); + +TNS_ERROR ReadTnsData( + STnsConfig const * pTnsConfig, + Decoder_State * st, + int * pnBits, + int * stream, + int * pnSize +); + +void cldfbAnalysis ( + const float *timeIn, /* i : time buffer */ + float **realBuffer, /* o : real value buffer */ + float **imagBuffer, /* o : imag value buffer */ + int samplesToProcess, /* i : number of input samples */ + HANDLE_CLDFB_FILTER_BANK h_cldfb /* i : filterbank state */ +); + +void cldfbSynthesis ( + float **realBuffer, /* i : real values */ + float **imagBuffer, /* i : imag values */ + float *timeOut, /* o : synthesized output */ + int samplesToProcess, /* i : number of samples */ + HANDLE_CLDFB_FILTER_BANK h_cldfb /* i : filter bank state */ +); + +void analysisCldfbEncoder ( + Encoder_State *st, /* i/o: encoder state structure */ + const float *timeIn, + int samplesToProcess, + float realBuffer[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX], + float imagBuffer[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX], + float *ppBuf_Ener +); + +int openCldfb ( + HANDLE_CLDFB_FILTER_BANK *h_cldfb, /* i/o : filter bank handle */ + CLDFB_TYPE type, /* i : analysis or synthesis */ + int samplerate /* i : max samplerate to oeprate */ +); + +void resampleCldfb ( + HANDLE_CLDFB_FILTER_BANK hs, /* i/o : filter bank handle */ + int newSamplerate /* i : new samplerate to operate */ +); + +int cldfb_save_memory( + HANDLE_CLDFB_FILTER_BANK hs /* i/o : filter bank handle */ +); + +int cldfb_restore_memory( + HANDLE_CLDFB_FILTER_BANK hs /* i/o : filter bank handle */ +); + +int cldfb_reset_memory ( + HANDLE_CLDFB_FILTER_BANK hs /* i/o : filter bank handle */ +); + +void deleteCldfb( + HANDLE_CLDFB_FILTER_BANK *h_cldfb /* i/o : filter bank handle */ +); + +void fft_cldfb ( + float *data, /* i/o: input/output vector */ + int size /* size of fft operation */ +); + +void BITS_ALLOC_init_config_acelp( + int bit_rate, + int narrowBand, + int nb_subfr, + ACELP_config *acelp_cfg /*o: configuration structure of ACELP*/ +); + +int BITS_ALLOC_config_acelp( + const int bits_frame, /* i : remaining bit budget for the frame */ + const short coder_type, /* i : acelp extended mode index */ + ACELP_config *acelp_cfg, /* i/o: configuration structure of ACELP */ + const short narrowband, /* i : narrowband flag */ + const short nb_subfr /* i : number of subframes */ +); + +void FEC_clas_estim( + const float *syn, + const float *pitch, /* i : pitch values for each subframe */ + const short L_frame, /* i : length of the frame */ + const short coder_type, /* i : coder type */ + const short codec_mode, /* i : codec mode */ + float *mem_syn_clas_estim, /* i/o: memory of the synthesis signal for frame class estimation */ + short *clas, /* i/o: frame classification */ + float *lp_speech, /* i/o: long term active speech energy average */ + long const bitrate, /* i : Decoded bitrate */ + short const Opt_AMR_WB, /* i : flag indicating AMR-WB IO mode */ + short *decision_hyst, /* i/o: hysteresis of the music/speech decision */ + short *locattack, /* i/o: detection of attack (mainly to localized speech burst) */ + short *UV_cnt, /* i/o: number of consecutives frames classified as UV */ + float *LT_UV_cnt, /* i/o: long term consecutives frames classified as UV */ + float *Last_ener, /* i/o: last_energy frame */ + short *amr_io_class, /* i/o: classification for AMR-WB IO mode */ + float *lt_diff_etot, /* i/o: long-term total energy variation */ + float *class_para, /* o : classification para. fmerit1 */ + const float LTP_Gain, /* i : */ + const int narrowBand, /* i : */ + const SIGNAL_CLASSIFIER_MODE mode,/* i : */ + const int bfi, /* i : */ + const float preemph_fac, /* i : */ + const int tcxonly, /* i : */ + const int last_core_brate /* i : last core bitrate */ +); + +void InitTransientDetection( + int nFrameLength, + int nTCXDelay, + struct TransientDetection * pTransientDetection +); + +void RunTransientDetection( + float const * input, + int nSamplesAvailable, + struct TransientDetection * pTransientDetection +); + +float GetTCXAvgTemporalFlatnessMeasure( + struct TransientDetection const * pTransientDetection, + int nCurrentSubblocks, + int nPrevSubblocks +); + +float GetTCXMaxenergyChange( + struct TransientDetection const * pTransientDetection, + const int isTCX10, + const int nCurrentSubblocks, + const int nPrevSubblocks +); + +void SetTCXModeInfo( + Encoder_State *st, /* i/o: encoder state structure */ + struct TransientDetection const * pTransientDetection, + short * tcxModeOverlap +); + +void TCX_MDCT( + float const *x, + float *y, + int l, + int m, + int r +); + +void TCX_MDST( + float const *x, + float *y, + int l, + int m, + int r +); + +void TCX_MDCT_Inverse( + float *x, + float *y, + int l, + int m, + int r +); + +void post_decoder( + Decoder_State *st, + const short coder_type, /* i : coder type */ + float synth_buf[], + const float pit_gain[], + const int pitch[], + float signal_out[], + float bpf_noise_buf[] +); + +float bass_pf_enc( + const float *orig, /* (i) : 12.8kHz original signal */ + const float *syn, /* (i) : 12.8kHz synthesis to postfilter */ + const float pitch_buf[],/* (i) : Pitch gain for all subframes (gainT_sf[16]) */ + const float gainT_sf[], /* (i) : Pitch gain for all subframes (gainT_sf[16]) */ + const short l_frame, /* (i) : frame length (should be multiple of l_subfr)*/ + const short l_subfr_in, /* (i) : sub-frame length (60/64) */ + float mem_bpf[], /* i/o : memory state [2*L_FILT] */ + float mem_error_bpf[], /* i/o : memory state [2*L_FILT] */ + int *gain_factor_param, /* (o) : quantized gain factor */ + const short mode, /* (i) : coding mode of adapt bpf */ + float *mem_deemph_err, /* i/o : Error deemphasis memory */ + float *lp_ener /* i/o : long_term error signal energy */ +); + +void cldfb_synth_set_bandsToZero( + Decoder_State *st, + float **rAnalysis, + float **iAnalysis, + const short nTimeSlots +); + +void longadd( + unsigned short a[], + unsigned short b[], + int lena, + int lenb +); + +void longshiftright( + unsigned short a[], + int b, + unsigned short d[], + int lena, + int lend +); + +void longshiftleft( + unsigned short a[], + int b, + unsigned short d[], + int len +); + +void open_decoder_LPD( + Decoder_State *st, + const int bit_rate, + const int bandwidth +); + +void update_decoder_LPD_cng( + Decoder_State *st, + const short coder_type, /* i : coder type */ + float *timeDomainBuffer, + float *A, + float *bpf_noise_buf +); + +void reconfig_decoder_LPD( + Decoder_State *st, + int bits_frame, + int bandwidth, + int bitrate, + int L_frame_old +); + +void mode_switch_decoder_LPD( + Decoder_State *st, + int bandwidth_in, + int bitrate, + int frame_size_index +); + +void dec_acelp_tcx_frame( + Decoder_State *st, /* i/o: encoder state structure */ + short *coder_type, /* o : coder type */ + short *concealWholeFrame, /* i/o: concealment flag */ + float *output, /* o : synthesis */ + float *bpf_noise_buf, /* i/o: BPF noise buffer */ + float * pcmbufFB, + float bwe_exc_extended[], /* i/o: bandwidth extended excitation */ + float *voice_factors, /* o : voicing factors */ + float pitch_buf[] /* o : floating pitch for each subframe */ +); + +void decoder_LPD( + float signal_out[], /* output: signal with LPD delay (7 subfrs) */ + float signal_outFB[], + short *total_nbbits, /* i/o: number of bits / decoded bits */ + Decoder_State *st, /* i/o: decoder memory state pointer */ + float *bpf_noise_buf, /* i/o: BPF noise buffer */ + short bfi, /* i : BFI flag */ + short *bitsRead, /* o : number of read bits */ + short *coder_type, /* o : coder type */ + int param[], /* o : buffer of parameters */ + float *pitch_buf, /* i/o: floating pitch values for each subfr*/ + float *voice_factors, /* o : voicing factors */ + float *ptr_bwe_exc /* o : excitation for SWB TBE */ +); + + +int tcxGetNoiseFillingTilt( + float A[], + int L_frame, + int mode, + float *noiseTiltFactor +); + +void tcxFormantEnhancement( + float xn_buf[], + float gainlpc[], + float spectrum[], + int L_frame +); + +void tcxInvertWindowGrouping( + TCX_config *tcx_cfg, + float xn_buf[], + float spectrum[], + int L_frame, + int fUseTns, + int last_core, + int index, + int frame_cnt, + int bfi +); + +void lerp( + float *f, + float *f_out, + int bufferNewSize, + int bufferOldSize +); + +void coderLookAheadInnovation( + const float A[], /* input: coefficients NxAz[M+1] */ + int *pT, /* out: pitch */ + HANDLE_PLC_ENC_EVS hPlc_Ext, + float *speechLookAhead, + float *old_exc, + int L_subfr, + int L_frame +); + +void encoderSideLossSimulation( + Encoder_State *st, + HANDLE_PLC_ENC_EVS hPlc_Ext, + float *isf_q, + float stab_fac, + int calcOnlyISF, + int L_frame +); + +void enc_prm_side_Info( + HANDLE_PLC_ENC_EVS hPlc_Ext, + Encoder_State *st +); + +void GplcTcxEncSetup( + Encoder_State *st, + HANDLE_PLC_ENC_EVS hPlc_Ext +); + +short encSideSpecPowDiffuseDetector( + float *isf_ref, + float *isf_con, + int sr_core, + float *prev_isf4_mean, + short sw + ,short coder_type +); + +void updateSpecPowDiffuseIdx( + Encoder_State *st, + const float gain_pitch_buf[], /* i : gain pitch values */ + const float gain_code_buf[] /* i : gain pitch values */ +); + +void getLookAheadResSig( + float *speechLookAhead, + const float *A, + float *res, + int L_frame, + int L_subfr, + int m, + int numSubFrame +); + +void updatelsfForConcealment( + HANDLE_PLC_ENC_EVS decState, + float *lsf +); + +void getConcealedLP( + HANDLE_PLC_ENC_EVS memDecState, + float *AqCon, + const float xsfBase[], + const float sr_core, + int last_good, + int L_frame +); + + +void getConcealedlsf( + HANDLE_PLC_ENC_EVS memDecState, + const float lsfBase[], + int L_frame, int last_good +); + +void RecLpcSpecPowDiffuseLc( + float *ispq, + float *isp_old, + float *isfq, + Decoder_State *st + , int reset_q +); + +void modify_lsf( + float *lsf, + const short n, + const int sr_core + , int reset_q +); + +void open_PLC_ENC_EVS( + HANDLE_PLC_ENC_EVS hPlcExt, + int sampleRate +); + +void gPLC_encInfo( + HANDLE_PLC_ENC_EVS self, + const int brate, + const int bwidth, + const short last_clas, + const int coder_type +); + +void resetTecDec( + HANDLE_TEC_DEC hTecDec +); + +void updateTecBuf( + float** pCldfbRealSrc, + float** pCldfbImagSrc, + float** pCldfbRealTgt, + float** pCldfbImagTgt, + int noCols, + int lowSubband +); + +void calcGainTemp_TBE( + float** pCldfbRealSrc, + float** pCldfbImagSrc, + float* loBuffer, + int startPos, /*!< Start position of the current envelope. */ + int stopPos, /*!< Stop position of the current envelope. */ + int lowSubband, /* lowSubband */ + float* pGainTemp, + short code +); + +void procTecTfa_TBE( + float *hb_synth, + float *gain, + short flat_flag, + short last_core, + int L_subfr, + short code +); + +void resetTecEnc( + HANDLE_TEC_ENC hTecEnc, + int flag +); + +void calcHiEnvLoBuff( + int noCols, + const int* pFreqBandTable, /*!< freqbandTable. */ + int nSfb, /*!< Number of scalefactors. */ + float** pYBuf, + float* loBuf, + float* hiTempEnv +); + +void calcLoEnvCheckCorrHiLo( + int noCols, + const int* pFreqBandTable, /*!< freqbandTable. */ + float* loBuf, + float* loTempEnv, + float* loTempEnv_ns, + float* hiTempEnv, + int* corr_flag /* 0 for original, 1 for TEC */ +); + +void tfaCalcEnv( + const float* shb_speech, + float* enr +); + +short tfaEnc_TBE( + float* enr, + short last_core, + float* voicing, + float* pitch_buf +); + +void tecEnc_TBE( + int* corrFlag, + const float* voicing, + short coder_type +); + +void set_TEC_TFA_code( + const short corrFlag, + short* tec_flag, + short* tfa_flag +); + +float Damping_fact( + const short coder_type,/* i : ACELP core coding mode */ + int nbLostCmpt, /* i : compt for number of consecutive lost frame */ + short last_good, /* i : class of last good received frame */ + float stab_fac, /* i : LSF stability factor */ + float *lp_gainp, /* i/o: low passed pitch gain used for concealment */ + int core /* i : current core: ACELP = 0, TCX20 = 1, TCX10 = 2 */ +); + +void fer_energy( + const int L_frame, /* i : frame length */ + const short clas, /* i : frame classification */ + const float synth[], /* i : synthesized speech at Fs = 12k8 Hz */ + const float pitch, /* i : pitch period */ + float *enr, /* o : pitch-synchronous or half_frame energy */ + const short useOffset /* i : speech pointer offset (0 or L_FRAME) */ +); + +float getLevelSynDeemph( + float const h1Init[], /* i: input value or vector to be processed */ + float const A[], /* i: LPC coefficients */ + int const lenLpcExc, /* i: length of the LPC excitation buffer */ + float const preemph_fac, /* i: preemphasis factor */ + int const numLoops /* i: number of loops */ +); + +void genPlcFiltBWAdap( + int const sr_core, /* i: core sampling rate */ + float* lpFiltAdapt, /* o: filter coefficients for filtering codebooks in case of flc */ + int const type, /* i: type of filter, either 0 : lowpass or 1 : highpass */ + float const alpha /* i: fade out factor [0 1) used decrease filter tilt */ +); + +void highPassFiltering( + const short last_good, /* i: last classification type */ + const int L_buffer, /* i: buffer length */ + float exc2[], /* i/o: unvoiced excitation before the high pass filtering */ + const float hp_filt[], /* i: high pass filter coefficients */ + const int l_fir_fer /* i: high pass filter length */ +); + +int GetPLCModeDecision( + Decoder_State *st /* i/o: decoder memory state pointer */ +); + +void addBassPostFilter ( + const float *harm_timeIn, + int samplesToProcess, + float **rAnalysis, + float **iAnalysis, + HANDLE_CLDFB_FILTER_BANK cldfb +); + +TONALMDCTCONCEAL_ERROR TonalMDCTConceal_Init( + TonalMDCTConcealPtr self, + unsigned int samplesPerBlock, + unsigned int nSamplesCore, + unsigned int nScaleFactors, + TCX_config * tcx_cfg +); + +TONALMDCTCONCEAL_ERROR TonalMDCTConceal_SaveFreqSignal( + TonalMDCTConcealPtr self, + float const * mdctSpectrum, + unsigned int numSamples, + unsigned int nNewSamplesCore, + float const *scaleFactors +); + +TONALMDCTCONCEAL_ERROR TonalMDCTConceal_UpdateState( + TonalMDCTConcealPtr self, + int numSamples, + float pitchLag, + int badBlock, + int tonalConcealmentActive +); + +TONALMDCTCONCEAL_ERROR TonalMDCTConceal_SaveTimeSignal( + TonalMDCTConcealPtr self, + float* timeSignal, + unsigned int numSamples +); + +TONALMDCTCONCEAL_ERROR TonalMDCTConceal_Detect( + TonalMDCTConcealPtr const self, /*IN */ + float const pitchLag, /*IN */ + int * const umIndices /*OUT*/ +); + +TONALMDCTCONCEAL_ERROR TonalMDCTConceal_Apply( + TonalMDCTConcealPtr self, /*IN */ + float* mdctSpectrum /*OUT*/ +); + +TONALMDCTCONCEAL_ERROR TonalMDCTConceal_InsertNoise( + TonalMDCTConcealPtr self, /*IN */ + float* mdctSpectrum, /*OUT*/ + int tonalConcealmentActive, + short * pSeed, /*IN/OUT*/ + float tiltCompFactor, + float crossfadeGain, + int crossOverFreq +); + +void DetectTonalComponents( + unsigned short int indexOfTonalPeak[], + unsigned short int lowerIndex[], + unsigned short int upperIndex[], + unsigned int * pNumIndexes, + float lastPitchLag, + float currentPitchLag, + float const lastMDCTSpectrum[], + float const scaleFactors[], + float const secondLastPowerSpectrum[], + unsigned int nSamples, + unsigned int nSamplesCore, + float floorPowerSpectrum +); + +void RefineTonalComponents( + unsigned short int indexOfTonalPeak[], + unsigned short int lowerIndex[], + unsigned short int upperIndex[], + float phaseDiff[], + float phases[], + unsigned int * pNumIndexes, + float lastPitchLag, + float currentPitchLag, + float const lastMDCTSpectrum[], + float const scaleFactors[], + float const secondLastPowerSpectrum[], + unsigned int nSamples, + unsigned int nSamplesCore, + float floorPowerSpectrum +); + +void concealment_init( + int N, + void *_plcInfo +); + +void concealment_decode( + int pre_transient, + float *invkoef, + void *_plcInfo +); + +void concealment_update( + int bfi, + int core, + int harmonic, + float *invkoef, + void *_plcInfo +); + +void concealment_update2( + float *outx_new, + void *_plcInfo, + int FrameSize +); + +void concealment_signal_tuning( + int bfi, + int curr_mode, + float *outx_new, + void *_plcInfo, + int nbLostCmpt, + int pre_bfi, + float *OverlapBuf, + int past_core_mode, + float *outdata2, + Decoder_State *st +); + +void waveform_adj2( + float *overlapbuf, + float *outx_new, + float *data_noise, + float *outx_new_n1, + float *nsapp_gain, + float *nsapp_gain_n, + float *recovery_gain, + float step_concealgain, + int pitch, + int Framesize, + int delay, + int bfi_cnt, + int bfi +); + + +float SFM_Cal( + float const fcoef[], + int n +); + +void set_state( + int *state, + int num, + int N +); + +void Shellsort_float( + float *in, + int n +); + +int RFFTN( + float *afftData, + const float* trigPtr, + int len, + int isign +); + + +void DoFFT( + float * re2, + float * im2, + short length +); + + +short getTcxonly( + const int bitrate +); + +short getTnsAllowed( + const int bitrate, + const short igf +); + +short getCtxHm( + const int bitrate, + const short rf_flag +); + +short getResq( + const int bitrate +); + +short getRestrictedMode( + const int bitrate, + const short Opt_AMR_WB +); + +short getMdctWindowLength( + const float fscale +); + +short sr2fscale( + const int sr +); + +int getCoreSamplerateMode2( + const int bitrate, + const int bandwidth, + const short rf_mode +); + +float getTcxBandwidth( + const int bandwidth +); + +short getIgfPresent( + const int bitrate, + const int bandwidth, + const short rf_mode +); + +short getCnaPresent( + const int bitrate, + const int bandwidth +); + +short getTcxLtp( + const int sr_core +); + +short initPitchLagParameters( + const int sr_core, + int *pit_min, + int *pit_fr1, + int *pit_fr1b, + int *pit_fr2, + int *pit_max +); + +void attenuateNbSpectrum( + int L_frame, + float *spectrum +); + +void SetModeIndex( + Encoder_State *st, + const long total_brate, + const short bwidth +); + +short getNumTcxCodedLines( + const short bwidth +); + +short getTcxLpcShapedAri( + const int total_brate, + const short bwidth, + const short rf_mode +); + +void IGFEncApplyMono( + const IGF_ENC_INSTANCE_HANDLE hInstance, /**< in: | instance handle of IGF Encoder */ + const int igfGridIdx, /**< in: | IGF grid index */ + Encoder_State *st, /**< in: | Encoder state */ + float *pMDCTSpectrum, /**< in: | MDCT spectrum */ + float *pPowerSpectrum, /**< in: | MDCT^2 + MDST^2 spectrum, or estimate */ + int isTCX20, /**< in: | flag indicating if the input is TCX20 or TCX10/2xTCX5 */ + int isTNSActive, /**< in: | flag indicating if the TNS is active */ + int last_core_acelp /**< in: | indictaor if last frame was acelp coded */ +); + +void IGFEncConcatenateBitstream( + const IGF_ENC_INSTANCE_HANDLE hInstance, /**< in: | instance handle of IGF Encoder */ + short bsBits, /**< in: | number of IGF bits written to list of indices */ + short *next_ind, /**< in/out: | pointer to actual bit indice */ + short *nb_bits, /**< in/out: | total number of bits already written */ + Indice *ind_list /**< in: | pointer to list of indices */ +); + +void IGFEncResetTCX10BitCounter( + const IGF_ENC_INSTANCE_HANDLE hInstance /**< in: | instance handle of IGF Encoder */ +); + +void IGFEncSetMode( + const IGF_ENC_INSTANCE_HANDLE hInstance, /**< in: | instance handle of IGF Encoder */ + const int bitRate, /**< in: | encoder bitrate */ + const int mode /**< in: | encoder bandwidth mode */ + , const int f_mode /**< in: | flag to signal the RF mode */ +); + +int IGFEncWriteBitstream( /**< out: | number of bits written per frame */ + const IGF_ENC_INSTANCE_HANDLE hInstance, /**< in: | instance handle of IGF Encoder */ + void *st, /**< in: | encoder state */ + int *pBitOffset, /**< in: | ptr to bitOffset counter */ + const int igfGridIdx, /**< in: | igf grid index see declaration of IGF_GRID_IDX for details */ + const int isIndepFlag /**< in: | if 1 frame is independent, 0 = frame is coded with data from previous frame */ +); + +int IGFEncWriteConcatenatedBitstream( /**< out: | total number of bits written */ + const IGF_ENC_INSTANCE_HANDLE hInstance, /**< in: | instance handle of IGF Encoder */ + void *st /**< in: | encoder state */ +); + +void IGFDecApplyMono( + const IGF_DEC_INSTANCE_HANDLE hInstance, /**< in: | instance handle of IGF Decoder */ + float *spectrum, /**< in/out: | MDCT spectrum */ + const int igfGridIdx, /**< in: | in case of CELP->TCX switching, use 1.25 framelength */ + int bfi /**< in: | frame loss == 1, frame good == 0 */ +); + +void IGFDecCopyLPCFlatSpectrum( + const IGF_DEC_INSTANCE_HANDLE hInstance, /**< in: | instance handle of IGF Decoder */ + const float *pSpectrumFlat, /**< in: | LPC flattend spectrum from TCX dec */ + const int igfGridIdx /**< in: | IGF grid index */ +); + +void IGFDecReadData( + const IGF_DEC_INSTANCE_HANDLE hInstance, /**< in: | instance handle of IGF Deccoder */ + Decoder_State *st, /**< in: | decoder state */ + const int igfGridIdx, /**< in: | in case of CELP->TCX switching, use 1.25 framelength */ + const int isIndepFrame /**< in: | if 1: arith dec force reset, if 0: no reset */ +); + +int IGFDecReadLevel( /**< out: | return igfAllZero flag indicating if no envelope is transmitted */ + const IGF_DEC_INSTANCE_HANDLE hInstance, /**< in: | instance handle of IGF Deccoder */ + Decoder_State *st, /**< in: | decoder state */ + const int igfGridIdx, /**< in: | in case of CELP->TCX switching, use 1.25 framelength */ + const int isIndepFrame /**< in: | if 1: arith dec force reset, if 0: no reset */ +); + +void IGFDecRestoreTCX10SubFrameData( + const IGF_DEC_INSTANCE_HANDLE hInstance, /**< in: | instance handle of IGF Decoder */ + const int subFrameIdx /**< in: | index of subframe */ +); + +void IGFDecSetMode( + const IGF_DEC_INSTANCE_HANDLE hInstance, /**< in: | instance handle of IGF Decoder */ + const int bitRate, /**< in: | bitrate */ + const int mode, /**< in: | bandwidth mode */ + const int defaultStartLine, /**< in: | default start subband index */ + const int defaultStopLine, /**< in: | default stop subband index */ + const int rf_mode /**< in: | flag to signal the RF mode */ +); + +void IGFDecStoreTCX10SubFrameData( + const IGF_DEC_INSTANCE_HANDLE hInstance, /**< in: | instance handle of IGF Decoder */ + const int subFrameIdx /**< in: | index of subframe */ +); + +void IGFDecUpdateInfo( + const IGF_DEC_INSTANCE_HANDLE hInstance, /**< in: | instance handle of IGF Decoder */ + const int igfGridIdx /**< in: | IGF grid index */ +); + +int IGFCommonFuncsIGFConfiguration( /**< out: | error value: 0 -> error, 1 -> ok */ + int bitRate, /**< in: | bitrate in bs e.g. 9600 for 9.6kbs */ + int mode, /**< in: | bandwidth mode */ + H_IGF_INFO hIGFInfo, /**< out: | IGF info handle */ + int rf_mode /**< in: | flag to signal the RF mode */ +); + +int IGFCommonFuncsIGFGetCFTables( /**< out: | error value: 0 -> error, 1 -> ok */ + int bitRate, /**< in: | bitrate in bs e.g. 9600 for 9.6kbs */ + int mode, /**< in: | bandwidth mode */ + int rf_mode, /**< in: | flag to signal the RF mode */ + const unsigned short **cf_se00, /**< out: | CF table for t == 0 and f == 0 */ + const unsigned short **cf_se01, /**< out: | CF table for t == 0 and f == 1 */ + short *cf_off_se01, /**< out: | offset for CF table above */ + const unsigned short **cf_se02, /**< out: | CF tables for t == 0 and f >= 2 */ + const short **cf_off_se02, /**< out: | offsets for CF tables above */ + const unsigned short **cf_se10, /**< out: | CF table for t == 1 and f == 0 */ + short *cf_off_se10, /**< out: | offset for CF table above */ + const unsigned short **cf_se11, /**< out: | CF tables for t == 1 and f >= 1 */ + const short **cf_off_se11 /**< out: | offsets for CF tables above */ +); + +void IGFCommonFuncsWriteSerialBit( + void *st, /**< in: | encoder/decoder state structure */ + int *pBitOffset, /**< out: | bit offset */ + int bit /**< in: | value of bit */ +); + +void IGFCommonFuncsWriteSerialBit( + void *st, /**< in: | encoder/decoder state structure */ + int *pBitOffset, /**< out: | bit offset */ + int bit /**< in: | value of bit */ +); + +void IGFSCFEncoderOpen( + IGFSCFENC_INSTANCE_HANDLE hPublicData, /**< inout: handle to public data */ + int scfCountLongBlock, + int bitRate, + int mode + , int rf_mode +); + +int IGFSCFEncoderReset( + IGFSCFENC_INSTANCE_HANDLE hPublicData /**< inout: handle to public data or NULL in case there was no instance created */ +); + +int IGFSCFEncoderEncode( + IGFSCFENC_INSTANCE_HANDLE hPublicData, /**< inout: handle to public data or NULL in case there was no instance created */ + Encoder_State *st, + int bitCount, /**< in: offset to the first bit in bitbuffer which should be readed by iisArithDecoderDecode function */ + int *sfe, /**< in: ptr to an array which contain quantized scalefactor energies */ + int indepFlag, /**< in: if 1 on input the encoder will be forced to reset, + if 0 on input the encodder will be forced to encode without a reset */ + int doRealEncoding /**< in: whether the real encoding is needed, otherwise only the number of bits is used */ +); + +void IGFSCFEncoderSaveContextState( + IGFSCFENC_INSTANCE_HANDLE hPublicData /**< inout: handle to public data or NULL in case there was no instance created */ +); + +void IGFSCFEncoderRestoreContextState( + IGFSCFENC_INSTANCE_HANDLE hPublicData /**< inout: handle to public data or NULL in case there was no instance created */ +); + +void IGFSCFDecoderOpen( + IGFSCFDEC_INSTANCE_HANDLE hPublicData, /**< inout: handle to public data */ + int scfCountLongBlock, + int bitRate, + int mode, + int rf_mode +); + +void IGFSCFDecoderReset( + IGFSCFDEC_INSTANCE_HANDLE hPublicData /**< inout: handle to public data or NULL in case there was no instance created */ +); + +void IGFSCFDecoderDecode( + IGFSCFDEC_INSTANCE_HANDLE hPublicData, /**< inout: handle to public data or NULL in case there was no instance created */ + Decoder_State *st, /**< inout: pointer to decoder state */ + int *sfe, /**< out: ptr to an array which will contain the decoded quantized coefficients */ + int indepFlag /**< in: if 1 on input the encoder will be forced to reset, + if 0 on input the encodder will be forced to encode without a reset */ +); + +short tbe_celp_exc_offset( + const short T0, /* i : Integer pitch */ + const short T0_frac /* i : Fractional part of the pitch */ +); + +void blend_subfr2( + float *sigIn1, /* i : input signal for fade-out */ + float *sigIn2, /* i : input signal for fade-in */ + float *sigOut /* o : output signal */ +); + + + +#endif diff --git a/src/libs/libevs/lib_com/prot_fx.h b/src/libs/libevs/lib_com/prot_fx.h deleted file mode 100755 index 85b89439..00000000 --- a/src/libs/libevs/lib_com/prot_fx.h +++ /dev/null @@ -1,11078 +0,0 @@ -/*==================================================================================== - EVS Codec 3GPP TS26.442 Apr 03, 2018. Version 12.11.0 / 13.6.0 / 14.2.0 - ====================================================================================*/ - -#ifndef PROT_COM_FX_H -#define PROT_COM_FX_H -#include -#include "options.h" /* Compilation switches */ -#include "rom_com_fx.h" /* Compilation switches */ -#include "typedefs.h" -#include "stat_dec_fx.h" -#include "stat_enc_fx.h" -#include "stat_com.h" -#include "cnst_fx.h" -#include "basop_util.h" - -/*----------------------------------------------------------------------------------* - * Prototypes of global macros - *----------------------------------------------------------------------------------*/ - -void reset_preecho_dec_fx ( - Decoder_State_fx *st_fx /* i/o: decoder state structure */ -); - -void preecho_sb_fx( - const Word32 brate, /* i Q0 : core bit-rate */ - Word32 *wtda_audio_fx, /* i q_sig32 : imdct signal */ - Word16 q_sig32, /* i Q value for wtda_audio_fx */ - Word16 *rec_sig_fx, /* i q_sig16 : reconstructed signal, output of the imdct transform */ - Word16 q_sig16, /* i Q value for rec_sig_fx and imdct_mem_fx */ - const Word16 framelength, /* i Q0 : frame length */ - Word16 *memfilt_lb_fx, /* i/o Q0 : memory */ - Word32 *mean_prev_hb_fx, /* i/o Q0 : memory */ - Word16 *smoothmem_fx, /* i/o Q15 : memory */ - Word32 *mean_prev_fx, /* i/o Q0 : memory */ - Word32 *mean_prev_nc_fx, /* i/o Q0 : memory */ - Word16 *wmold_hb_fx, /* i/o Q15 : memory */ - Word16 *prevflag, /* i/o Q0 : flag */ - Word16 *pastpre, /* i/o Q0 : flag */ - const Word16 bwidth /* i Q0 : bandwidth */ -); - -void calc_normal_length_fx_32( - const Word16 core, /* i : core : Q0 */ - const Word32 *sp, /* i : input signal : Q12 */ - const Word16 mode, /* i : input mode : Q0 */ - const Word16 extl, /* i : extension layer : Q0 */ - Word16 *L_swb_norm, /* o : normalize length : Q0 */ - Word16 *prev_L_swb_norm /*i/o : last normalize length : Q0 */ -); - -void calc_norm_envelop_fx_32( - const Word32 SWB_signal_fx[], /* i : SWB spectrum : Q12 */ - Word32 *envelope_fx, /* o : normalized envelope : Q16 */ - const Word16 L_swb_norm, /* i : length of envelope : Q0 */ - const Word16 SWB_flength, /* i : Length of input/output : Q0 */ - const Word16 st_offset /* i : offset : Q0 */ -); - -void push_indice_fx( - Encoder_State_fx *st_fx, /* i/o: encoder state structure */ - Word16 id, /* i : ID of the indice */ - UWord16 value, /* i : value of the quantized indice */ - Word16 nb_bits /* i : number of bits used to quantize the indice */ -); - -void push_next_indice_fx( - Encoder_State_fx *st_fx, /* i/o: encoder state structure */ - UWord16 value, /* i : value of the quantized indice */ - Word16 nb_bits /* i : number of bits used to quantize the indice */ -); - -void push_next_bits_fx( - Encoder_State_fx *st_fx, /* i/o: encoder state structure */ - Word16 bits[], /* i : bit buffer to pack, sequence of single bits */ - Word16 nb_bits /* i : number of bits to pack */ -); -void get_NextCoderType_fx( - UWord8 *bitsteam, /* i : bitstream */ - Word16 *next_coder_type /* o : next coder type */ -); -void evs_enc_fx( - Encoder_State_fx *st_fx, /* i/o: encoder state structure */ - const Word16 input_sp[], /* i : input signal */ - const Word16 n_samples /* i : number of input samples */ -); - -void io_ini_enc_fx( - const int argc, /* i : command line arguments number */ - char *argv[], /* i : command line arguments */ - FILE **f_input, /* o : input signal file */ - FILE **f_stream, /* o : output bitstream file */ - FILE **f_rate, /* o : bitrate switching profile (0 if N/A) */ - FILE **f_bwidth, /* o : bandwidth switching profile (0 if N/A) */ - FILE **f_rf, /* o : channel aware config profile (0 if N/A) */ - Word16 *quietMode, /* o : limit printouts */ - Word16 *noDelayCmp, /* o : turn off delay compensation */ - Encoder_State_fx *st /* o : state structure */ -); - -void read_next_rfparam_fx( - Word16* rf_fec_offset, /* o: rf offset */ - Word16* rf_fec_indicator, /* o: rf FEC indicator */ - FILE* f_rf /* i: file pointer to read parameters */ -); - -void read_next_brate_fx( - Word32 *total_brate, /* i/o: total bitrate */ - const Word32 last_total_brate, /* i : last total bitrate */ - FILE *f_rate, /* i : bitrate switching profile (0 if N/A) */ - Word32 input_Fs, /* i : input sampling frequency */ - Word16 *Opt_AMR_WB, /* i : flag indicating AMR-WB IO mode */ - Word16 *Opt_SC_VBR, /* i/o: SC-VBR flag */ - Word16 *codec_mode /* i/o: MODE1 or MODE2 */ -); - - -void read_next_bwidth_fx( - Word16 *max_bwidth, /* i/o: maximum encoded bandwidth */ - FILE *f_bwidth, /* i : bandwidth switching profile (0 if N/A) */ - Word32 *bwidth_profile_cnt, /* i/o: counter of frames for bandwidth switching profile file */ - Word32 input_Fs /* i : input sampling frequency */ -); - -UWord16 get_next_indice_fx( /* o : value of the indice */ - Decoder_State_fx *st_fx, /* i/o: decoder state structure */ - Word16 nb_bits /* i : number of bits that were used to quantize the indice */ -); - -UWord16 get_next_indice_1_fx( /* o : value of the indice */ - Decoder_State_fx *st_fx /* i/o: decoder state structure */ -); - -void get_next_indice_tmp_fx( - Decoder_State_fx *st_fx, /* i/o: decoder state structure */ - Word16 nb_bits /* i : number of bits that were used to quantize the indice */ -); - - -UWord16 get_indice_fx( /* o : value of the indice */ - Decoder_State_fx *st_fx, /* i/o: decoder state structure */ - Word16 pos, /* i : absolute position in the bitstream */ - Word16 nb_bits /* i : number of bits that were used to quantize the indice */ -); - -UWord16 get_indice_1_fx( /* o : value of the indice */ - Decoder_State_fx *st_fx, /* i/o: decoder state structure */ - Word16 pos /* i : absolute position in the bitstream */ -); - -void reset_indices_enc_fx( - Encoder_State_fx *st_fx /* i/o: encoder state structure */ -); - - -void reset_indices_dec_fx( - Decoder_State_fx *st_fx /* i/o: decoder state structure */ -); - -void write_indices_fx( - Encoder_State_fx *st_fx, /* i/o: encoder state structure */ - FILE *file /* i : output bitstream file */ - , UWord8 *pFrame, /* i: byte array with bit packet and byte aligned coded speech data */ - Word16 pFrame_size /* i: size of the binary encoded access unit [bits] */ -); - -Word16 read_indices_fx( /* o : 1 = OK, 0 = something wrong */ - Decoder_State_fx *st_fx, /* i/o: decoder state structure */ - FILE *file, /* i : bitstream file */ - Word16 rew_flag /* i : rewind flag (rewind file after reading) */ -); - -Word16 read_indices_mime( /* o : 1 = reading OK, 0 = problem */ - Decoder_State_fx *st, /* i/o: decoder state structure */ - FILE *file, /* i : bitstream file */ - Word16 rew_flag /* i : rewind flag (rewind file after reading)*/ -); - -void indices_to_serial( - const Encoder_State_fx *st_fx, /* i: encoder state structure */ - UWord8 *pFrame, /* o: byte array with bit packet and byte aligned coded speech data */ - Word16 *pFrame_size /* i: size of the binary encoded access unit [bits] */ -); - -void indices_to_serial_generic( - const Indice_fx *ind_list, /* i: indices list */ - const Word16 num_indices, /* i: number of indices to write */ - UWord8 *pFrame, /* o: byte array with bit packet and byte aligned coded speech data */ - Word16 *pFrame_size /* i/o: number of bits in the binary encoded access unit [bits] */ -); - -void evs_dec_previewFrame( - UWord8 *bitstream, /* i : bitstream pointer */ - Word16 bitstreamSize, /* i : bitstream size */ - Word16 *partialCopyFrameType, /* o : frame type of the partial copy */ - Word16 *partialCopyOffset /* o : offset of the partial copy relative to the primary copy */ -); - -void read_indices_from_djb_fx( - Decoder_State_fx *st, /* i/o: decoder state structure */ - UWord8 *pt_stream, /* i : bitstream file */ - Word16 nbits /* i : number of bits */ - ,Word16 partialframe /* i : partial frame information */ - ,Word16 next_coder_type /* i : next coder type information */ -); - -void reset_rf_indices( - Encoder_State_fx *st /* i: state structure - contains partial RF indices */ -); - -void getPartialCopyInfo( - Decoder_State_fx *st, /* i : decoder state structure */ - Word16 *coder_type, - Word16 *sharpFlag -); - -void get_rfFlag( - Decoder_State_fx *st, /* i : decoder state structure */ - Word16 *rf_flag, /* o : check for the RF flag */ - Word16 *nBits, - Word16 *ind -); - -void get_rfFrameType( - Decoder_State_fx *st, /* i : decoder state structure */ - Word16 *rf_frame_type /* o : RF frame type */ -); - -void get_rf_fec_offset( - Decoder_State_fx *st, /* i : decoder state structure */ - Word16 *rf_fec_offset /* o : RF fec offset */ -); - -void get_rfTargetBits( - Word16 rf_frame_type, /* i : RF frame type */ - Word16 *rf_target_bits /* o : Number of RF target bits */ -); - - -Word16 BRATE2IDX_fx(Word32 brate); -Word16 BRATE2IDX16k_fx(Word32 brate); - -Word32 BIT_ALLOC_IDX_fx(Word32 brate, Word16 ctype, Word16 sfrm, Word16 tc); -Word32 BIT_ALLOC_IDX_16KHZ_fx(Word32 brate, Word16 ctype, Word16 sfrm, Word16 tc); - -void save_old_syn_fx( - const Word16 L_frame, /* i : frame length */ - const Word16 syn[], /* i : ACELP synthesis */ - Word16 old_syn[], /* o : old synthesis buffer */ - Word16 old_syn_mem[], /* i/o: old synthesis buffer memory */ - const Word16 preemph_fac, /* i : preemphasis factor */ - Word16 *mem_deemph /* i/o: deemphasis filter memory */ -); - -void evs_dec_fx( - Decoder_State_fx *st_fx, /* i/o : Decoder state structure */ - Word16 output_sp[], /* o : output synthesis signal */ - frameMode_fx frameMode /* i : Decoder frame mode */ -); - -Word16 decodeVoip( - Decoder_State_fx *st_fx, - FILE *f_stream, - FILE *f_synth, -#ifdef SUPPORT_JBM_TRACEFILE - const char *jbmTraceFileName, -#endif - const char *jbmFECoffsetFileName, /* : Output file for Optimum FEC offset */ - const Word16 quietMode -); - - -void io_ini_dec_fx( - const int argc, /* i : command line arguments number */ - char *argv[], /* i : command line arguments */ - FILE **f_stream, /* o : input bitstream file */ - FILE **f_synth, /* o : output synthesis file */ - Word16 *quietMode, /* o : limited printouts */ - Word16 *noDelayCmp, /* o : turn off delay compensation */ - Decoder_State_fx *st_fx, /* o : Decoder static variables structure */ -#ifdef SUPPORT_JBM_TRACEFILE - char **jbmTraceFileName, /* o : VOIP tracefilename */ -#endif - char **jbmFECoffsetFileName /* o : Output file for Optimum FEC offset */ -); -Word16 deindex_lvq_cng_fx( - Word16 *index, /* i : index to be decoded, as an array of 3 short */ - Word16 *x_lvq, /* o : decoded codevector Q9*/ - Word16 idx_cv, /* i : relative mode_lvq, wrt START_CNG */ - Word16 no_bits, /* i : number of bits for lattice */ - Word32 * p_offset_scale1, - Word32 * p_offset_scale2, - Word16 * p_no_scales -); - -void CNG_dec_fx( - Decoder_State_fx *st_fx, /* i/o: State structure */ - const Word16 L_frame, /* i : length of the frame Q0 */ - Word16 Aq[], /* o : LP coefficients Q12 */ - const Word32 core_brate, /* i : core bitrate Q0 */ - Word16 *lsp_new, /* i/o: current frame LSPs Q15 */ - Word16 *lsf_new, /* i/o: current frame LSFs Qlog2(2.56) */ - Word16 *allow_cn_step /* o : allow CN step Q0 */ - ,Word16 *sid_bw /* o : 0-NB/WB, 1-SWB SID */ - ,Word32 *q_env -); - -void swb_CNG_dec_fx( - Decoder_State_fx *st_fx, /* i/o: State structure */ - const Word16 *synth_fx, /* i : ACELP core synthesis at 32kHz */ - Word16 *shb_synth_fx, /* o : high-band CNG synthesis */ - const Word16 sid_bw, /* i : 0-NB/WB, 1-SWB SID */ - const Word16 Qsyn /* i : Q value of ACELP core synthesis */ -); - -void CNG_reset_enc_fx( - Encoder_State_fx *st_fx, /* i/o: encoder state structure */ - LPD_state *mem, /* i/o: acelp memories */ - Word16 *pitch_buf, /* o : floating pitch for each subframe */ - Word16 *voice_factors /* o : voicing factors */ - ,Word16 VBR_cng_reset_flag -); - -void CNG_reset_dec_fx( - Decoder_State_fx *st_fx, /* i/o: decoder state structure */ - Word16 *pitch_buf, /* o : floating pitch for each subframe */ - Word16 *voice_factors /* o : voicing factors */ -); - -void CNG_exc_fx( - const Word32 core_brate, /* i : core bitrate */ - const Word16 L_frame, /* i : length of the frame */ - Word32 *Enew, /* i/o: decoded SID energy Q6 */ - Word16 *seed, /* i/o: random generator seed */ - Word16 exc[], /* o : current non-enhanced excitation Q_new */ - Word16 exc2[], /* o : current enhanced excitation Q_new */ - Word32 *lp_ener, /* i/o: LP filtered E */ - const Word32 last_core_brate, /* i : previous frame core bitrate */ - Word16 *first_CNG, /* i/o: first CNG frame flag for energy init. */ - Word16 *cng_ener_seed, /* i/o: random generator seed for CNG energy */ - Word16 bwe_exc[], /* o : excitation for SWB TBE */ - const Word16 allow_cn_step, /* i : allow CN step */ - Word16 *last_allow_cn_step, /* i/o: last allow step */ - const Word16 OldQ_exc, /* i : Old excitation scaling */ - const Word16 Q_exc, /* i : excitation scaling */ - const Word16 num_ho /* i : number of selected hangover frames */ - ,Word32 q_env[] - ,Word32 *lp_env - ,Word32 *old_env - ,Word16 *exc_mem - ,Word16 *exc_mem1 - ,Word16 *sid_bw - ,Word16 *cng_ener_seed1 - ,Word16 exc3[] - ,Word16 Opt_AMR_WB -); - -void CNG_enc_fx( - Encoder_State_fx *st_fx, /* i/o: State structure */ - const Word16 L_frame, /* i : length of the frame Q0 */ - Word16 Aq[], /* o : LP coefficients Q12 */ - const Word16 *speech, /* i : pointer to current frame input speech buffer Q_new */ - Word32 L_enr, /* i : residual energy from Levinson-Durbin Q6 */ - Word16 *lsp_new, /* i/o: current frame ISPs Q15 */ - Word16 *lsf_new, /* i/o: current frame ISFs Qlog2(2.56) */ - Word16 *allow_cn_step, /* o : allow CN step Q0 */ - Word16 burst_ho_cnt, /* i : hangover frames at end of speech burst Q0 */ - Word16 Q_new /* i : Q value of speech */ - ,Word32 *q_env - ,Word16 *sid_bw - ,Word16 *exc_mem2 -); - -void swb_CNG_enc_fx( - Encoder_State_fx *st_fx, /* i/o: State structure */ - const Word16 *shb_speech_fx, /* i : SHB target signal (6-14kHz) at 16kHz */ - const Word16 *syn_12k8_16k_fx /* i : ACELP core synthesis at 12.8kHz or 16kHz */ -); - -void cng_params_upd_fx( - const Word16 lsp_new[], /* i : LSP parameters Q15 */ - const Word16 exc2[], /* i : current enhanced excitation Q_exc */ - const Word16 L_frame, /* i : frame length Q0 */ - Word16 *ho_circ_ptr, /* i/o: pointer for CNG averaging buffers Q0 */ - Word32 ho_ener_circ[], /* o : energy buffer for CNG averaging Q6 */ - Word16 *ho_circ_size, /* i/o: size of DTX hangover history buffer for averaging Q0 */ - Word16 ho_lsp_circ[], /* o : old LSP buffer for CNG averaging Q15 */ - const Word16 Q_exc, /* i : Q value of excitation */ - const Word16 enc_dec_flag, /* i : Flag indicating encoder or decoder (ENC,DEC) */ - Word32 ho_env_circ[], /* i/o: Envelope buffer */ - Word16 *cng_buf_cnt, /* i/o: Counter of postponed FFT-processing instances */ - Word16 cng_exc2_buf[], /* i/o: Excitation buffer Q_exc */ - Word16 cng_Qexc_buf[], /* i/o: Q_exc buffer Q0 */ - Word32 cng_brate_buf[], /* i/o: last_active_brate buffer Q0 */ - const Word32 last_active_brate /* i : Last active bit rate Q0 */ -); - -void cng_params_postupd_fx( - const Word16 ho_circ_ptr, /* i : pointer for CNG averaging buffers Q0 */ - Word16 *cng_buf_cnt, /* i/o: counter for CNG store buffers Q0 */ - const Word16 *const cng_exc2_buf, /* i : Excitation buffer Q_exc */ - const Word16 *const cng_Qexc_buf, /* i : Q_exc buffer Q0 */ - const Word32 *const cng_brate_buf, /* i : bit rate buffer Q0 */ - Word32 ho_env_circ[] /* i/o: Envelope buffer */ -); -Word32 get_delay_fx( /* o : delay value in ms */ - const Word16 what_delay, /* i : what delay? (ENC or DEC) */ - const Word32 io_fs /* i : input/output sampling frequency */ -); - - -void signalling_enc_fx( - Encoder_State_fx *st_fx, /* i : encoder state structure */ - const Word16 coder_type, /* i : coder type */ - const Word16 sharpFlag /* i : formant sharpening flag */ -); - -Word16 signalling_mode1_tcx20_enc( - Encoder_State_fx *st, /* i : encoder state structure */ - Word16 push -); - -void signalling_enc_rf( - Encoder_State_fx *st /* i : encoder state structure */ -); - -void decision_matrix_core_dec( - Decoder_State_fx *st /* i/o: decoder state structure */ -); - -void decision_matrix_enc_fx( - Encoder_State_fx *st_fx, /* i : encoder state structure */ - const Word16 sp_aud_decision1, /* i : 1st stage speech/music classification */ - const Word16 sp_aud_decision2, /* i : 2nd stage speech/music classification */ - const Word16 coder_type, /* i : coder type */ - const Word16 vad_flag, - Word16 *hq_core_type /* o : HQ core_fx type */ -); - -void decision_matrix_dec_fx( - Decoder_State_fx *st, /* i/o: decoder state structure */ - Word16 *coder_type, /* o : coder type */ - Word16 *sharpFlag, /* o : formant sharpening flag */ - Word16 *hq_core_type, /* o : HQ core type */ - Word16 *core_switching_flag /* o : ACELP->HQ switching frame flag */ -); - -void init_gp_clip_fx( - Word16 mem[] /* o : memory of gain of pitch clipping algorithm */ -); - -void gp_clip_test_isf_fx( - const Word32 core_brate, /* i : core bitrate */ - const Word16 isf[], /* i : isf values (in frequency domain) */ - Word16 mem[], /* i/o: memory of gain of pitch clipping algorithm */ - const Word16 Opt_AMR_WB /* i : flag indicating AMR-WB IO mode */ -); - -void pitch_ol_init_fx( - Word16 *old_thres, /* o : threshold for reinforcement of past pitch influence */ - Word16 *old_pitch, /* o : pitch of the 2nd half-frame of previous frame */ - Word16 *delta_pit, /* o : pitch evolution extrapolation */ - Word16 *old_corr /* o : correlation */ -); - -void noise_est_down_fx( - const Word32 fr_bands[], /* i : per band input energy (contains 2 vectors) */ - Word32 bckr[], /* i/o: per band background noise energy estimate */ - Word32 tmpN[], /* o : temporary noise update */ - Word32 enr[], /* o : averaged energy over both subframes */ - const Word16 min_band, /* i : minimum critical band */ - const Word16 max_band, /* i : maximum critical band */ - Word16 *totalNoise, /* o : noise estimate over all critical bands */ - Word16 Etot, /* i : Energy of current frame */ - Word16 *Etot_last, /* i/o: Energy of last frame Q8 */ - Word16 *Etot_v_h2, /* i/o: Energy variations of noise frames Q8 */ - Word16 Q_new, - const Word32 e_min /* i : minimum energy scaled Q_new + QSCALE */ -); - -void wb_vad_init_fx( - Word16 *nb_active_frames, /* o : nb of consecutive active speech frames */ - Word16 *hangover_cnt, - Word16 *lp_speech, /* o : long-term active speech level */ - Word16 *nb_active_frames_he, /* o : nb of consecutive active speech frames */ - Word16 *hangover_cnt_he, - Word16 *bcg_flux, /* o : background noise fluctuation */ - Word16 *soft_hangover, /* o : soft hangover counter */ - Word16 *voiced_burst, /* o : consecutive voiced speech counter */ - Word16 *bcg_flux_init, /* o : initialization period for noise fluctuation estimation */ - Word16 *nb_active_frames_he1, /* o : nb of consecutive active speech frames 1 */ - Word16 *hangover_cnt_he1, - Word32 *L_vad_flag_reg_H, - Word32 *L_vad_flag_reg_L, - Word32 *L_vad_prim_reg, - Word16 *vad_flag_cnt_50, - Word16 *vad_prim_cnt_16, - Word16 *hangover_cnt_dtx, - Word16 *hangover_cnt_music -); - -Word16 wb_vad_fx( - Encoder_State_fx *st_fx, /* i/o: encoder state structure */ - const Word32 fr_bands[], /* i : per band input energy (contains 2 vectors) Q_new+QSCALE*/ - Word16 *localVAD, - Word16 *noisy_speech_HO, /* o : SC-VBR noisy speech HO flag */ - Word16 *clean_speech_HO, /* o : SC-VBR clean speech HO flag */ - Word16 *NB_speech_HO, /* o : SC-VBR NB speech HO flag */ - Word16 *snr_sum_he, /* o : Output snr_sum as weighted spectral measure */ - Word16 *localVAD_HE_SAD, /* o : HE_SAD decision without hangovers */ - Word8 *flag_noisy_speech_snr, /* o : */ - const Word16 Q_new /* i : scaling factor Q0 */ -); - - -void dtx_fx( - Encoder_State_fx *st_fx, /* i/o: encoder state structure */ - const Word16 vad, /* i : vad flag */ - const Word16 speech[], /* i : Pointer to the speech frame */ - Word16 Q_speech /* i : Q factor for speech */ - -); - -void dtx_hangover_control_fx( - Encoder_State_fx *st_fx, /* i/o: encoder state structure */ - const Word16 lsp_new_fx[M] /* i : current frame LSPs */ -); - -Word16 dtx_hangover_addition_fx( - Encoder_State_fx *st_fx, /* i/o: encoder state structure */ - const Word16 localVAD, /* i Q0 */ - const Word16 vad_flag, /* i Q0 */ - const Word16 lp_snr, /* i Q8 */ - const Word16 cldfb_subtraction, /* i Q0 */ - Word16 *vad_hover_flag_ptr -); - -void noise_est_init_fx( - Word16 *totalNoise, /* o : noise estimate over all critical bands */ - Word16 *first_noise_updt, /* o : noise update initialization flag */ - Word32 bckr[], /* o : per band background noise energy estimate */ - Word32 enrO[], /* o : per band old input energy */ - Word32 ave_enr[], /* o : per band long-term average energies */ - Word16 *pitO, /* o : open-loop pitch values from preceed. frame */ - Word16 *aEn, /* o : noise adaptation hangover counter */ - Word16 *st_harm_cor_cnt, /* i/o: 1st harm correlation timer */ - Word16 *bg_cnt, /* i/o: pause burst length counter */ - Word16 *lt_tn_track, /* Q15 */ - Word16 *lt_tn_dist, /* Q8 */ - Word16 *lt_Ellp_dist, /* Etot low lp same domain as *Etot_l_lp, Q8 */ - Word16 *lt_haco_ev, /* Q15 */ - Word16 *low_tn_track_cnt /* Q0 */ - ,Word16 *Etot_st_est, /* Q8: Short term Etot Estimate for variance calc */ - Word16 *Etot_sq_st_est /* Q2 : Short term Etot^2 Estimate for variance calc */ - -); - - -void noise_est_pre_fx( - const Word16 Etot, /* i : Energy of current frame */ - const Word16 ini_frame_fx, /* i : Frame number (init) */ - Word16 *Etot_l, /* i/o: Track energy from below */ /*Q8 */ - Word16 *Etot_h, /* i/o: Track energy from above */ /*Q8 */ - Word16 *Etot_l_lp, /* i/o: Smoothed low energy */ /*Q8 */ - Word16 *Etot_last, /* i/o: Energy of last frame */ /*Q8 */ - Word16 *Etot_v_h2, /* i/o: Energy variations */ /*Q8*/ - Word16 *sign_dyn_lp, /* i/o: Smoother signal dynamics */ /*Q8*/ - Word16 harm_cor_cnt, /* i : correlation counter */ - Word16 *Etot_lp /* i/o: Smoothed energy */ -); - -void Preemph_scaled( - Word16 new_speech[], /* i : Speech to scale already on 14 bits*/ - Word16 *Q_new, /* o : Scaling factor */ - Word16 *mem_preemph, /* i/o: Preemph memory */ - Word16 *Q_max, /* i/o: Q_new limitation */ - const Word16 Preemph_factor, /* i : Preemphasis factor Q15 */ - const Word16 bits, /* i : Bit to remove from the output to (15-bits)*/ - const Word16 bit1, /* i : Limit the output scaling to ((15-bits)-bit1) bits */ - const Word16 L_Q_mem, /* i : Number of old scaling to take into account */ - const Word16 Lframe, /* i : Frame length */ - const Word16 last_coder_type, /* i : coder_type */ - const Word16 Search_scaling /* i : enable the search of a proper scaling factor*/ -); -Word32 Scale_mem_pre_proc( /* o : Min energy scaled */ - Word16 ini_frame_fx, /* i : Frame number */ - Word16 Q_exp, /* i : Diff scaling factor */ - Word16 *Q_new, /* i/o: Absolute scaling factor */ - Word16 *old_speech, /* i/o: Speech memory */ - Word16 *mem_wsp, /* i/o: wsp vector memory */ - Word32 *enrO, /* i/o: Enr mem */ - Word32 *bckr, /* i/o: Back ground_fx ener mem */ - Word32 *ave_enr, /* i/o: Ave_enr mem */ - Word32 *ave_enr2, /* i/o: Ave_enr2 mem */ - Word32 *st_fr_bands1, /* i/o: spectrum per critical bands of the previous frame */ - Word32 *st_fr_bands2, /* i/o: spectrum per critical bands 2 frames ago */ - Word32 *st_Bin_E_old -); -void Scale_mem_enc( - Word16 Q_exp, /* i : Diff scaling factor */ - Word16 *old_speech16k, /* i/o: Speech memory */ - Word16 *old_exc, /* i/o: excitation memory */ - Word16 *old_bwe_exc, /* i/o: BWE excitation memory */ - Word16 *mem_w0, /* i/o: target vector memory */ - Word16 *mem_syn, /* i/o: synthesis memory */ - Word16 *mem_syn2, /* i/o: synthesis memory */ - Word16 *mem_deemp_preQ_fx, /*i/o: deemphasis memory for the high rate celp codec */ - Word16 *last_exc_dct_in, - Word16 *old_input_lp -); - -void SetModeIndex( - Encoder_State_fx *st, - Word32 total_brate, - Word16 bwidth, - const Word16 shift -); - -void init_encoder_fx( - Encoder_State_fx *st_fx /* i/o: Encoder static variables structure */ -); - -void destroy_encoder_fx( Encoder_State_fx *st_fx ); - -void analysisCldfbEncoder_fx( - Encoder_State_fx *st_fx, /* i/o: encoder state structure */ - const Word16 *timeIn, - Word32 realBuffer[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX], - Word32 imagBuffer[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX], - Word16 realBuffer16[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX], - Word16 imagBuffer16[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX], - Word32 enerBuffSum[CLDFB_NO_CHANNELS_MAX], - Word16 *enerBuffSum_exp, - CLDFB_SCALE_FACTOR * scale -); - -void cldfb_save_memory (HANDLE_CLDFB_FILTER_BANK hs); /* i/o: cldfb handle */ -void cldfb_restore_memory (HANDLE_CLDFB_FILTER_BANK hs); /* i/o: cldfb handle */ -void cldfb_reset_memory (HANDLE_CLDFB_FILTER_BANK hs); /* i/o: cldfb handle */ - -Word16 gp_clip_fx( - const Word32 core_brate, /* i : core bitrate */ - const Word16 *voicing, /* i : normalized correlations (from OL pitch) */ - const Word16 i_subfr, /* i : subframe index */ - const Word16 coder_type, /* i : type of coder */ - const Word16 xn[], /* i : target vector */ - Word16 mem[], /* i/o: memory of gain of pitch clipping algorithm */ - const Word16 Q_new /* i : scaling factor */ -); - -void init_decoder_fx( - Decoder_State_fx *st_fx /* o: Decoder static variables structure */ -); - -void destroy_decoder( - Decoder_State_fx *st_fx /* o: Decoder static variables structure */ -); -Word16 Enr_1_Az_fx( /* o : impulse response energy Q3 */ - const Word16 Aq[], /* i : LP filter coefs Qx based on the fact that Aq[0] == 1.0 */ - const Word16 len /* i : impulse response length Q0 */ -); -void FEC_scale_syn_fx( - const Word16 L_frame, /* i : length of the frame */ - Word16 *update_flg, /* o: flag indicating re-synthesis after scaling*/ - Word16 clas, /* i/o: frame classification */ - const Word16 last_good, /* i: last good frame classification */ - Word16 *synth, /* i/o: synthesized speech at Fs = 12k8 Hz */ - const Word16 *pitch, /* i: pitch values for each subframe */ - Word32 L_enr_old, /* i: energy at the end of previous frame */ - Word32 L_enr_q, /* i: transmitted energy for current frame */ - const Word16 coder_type, /* i: coder type */ - const Word16 LSF_Q_prediction, /* i : LSF prediction mode */ - Word16 *scaling_flag, /* i/o: flag to indicate energy control of syn */ - Word32 *lp_ener_FEC_av, /* i/o: averaged voiced signal energy */ - Word32 *lp_ener_FEC_max, /* i/o: averaged voiced signal energy */ - const Word16 bfi, /* i: current frame BFI */ - const Word32 total_brate, /* i: total bitrate */ - const Word16 prev_bfi, /* i: previous frame BFI */ - const Word32 last_core_brate, /* i: previous frame core bitrate */ - Word16 *exc, /* i/o: excitation signal without enhancement */ - Word16 *exc2, /* i/o: excitation signal with enhancement */ - Word16 Aq[], /* i/o: LP filter coefs (can be modified if BR) */ - Word16 *old_enr_LP, /* i/o: LP filter E of last good voiced frame */ - const Word16 *mem_tmp, /* i: temp. initial synthesis filter states */ - Word16 *mem_syn, /* o: initial synthesis filter states */ - Word16 Q_exc, - Word16 Q_syn - , Word16 avoid_lpc_burst_on_recovery /* i : if true the excitation energy is limited if LP has big gain */ - , Word16 force_scaling /* i: force scaling */ -); - -void improv_amr_wb_gs_fx( - const Word16 clas, /* i : signal frame class */ - const Word16 coder_type, /* i : coder type */ - const Word32 core_brate, /* i : bitrate allocated to the core */ - Word16 *seed_tcx, /* i/o: Seed used for noise generation */ - Word16 *old_Aq_fx, /* i/o: old LPC filter coefficient */ - Word16 *mem_syn2_fx, /* i/o: synthesis memory */ - const Word16 lt_voice_fac_fx, /* i/o: long term voice factor Q15 */ - const Word16 locattack, /* i : Flag for a detected attack */ - Word16 *Aq_fx, /* i/o: Decoded LP filter coefficient */ - Word16 *exc2_fx, /* i/o: Decoded complete excitation */ - const Word16 Q_exc2, /* i : Exponent of Exc2 */ - Word16 *mem_tmp_fx, /* i/o: synthesis temporary memory */ - Word16 *syn_fx, /* o: Decoded synthesis to be updated */ - const Word16 Q_syn, /* i : Synthesis scaling Q0 */ - const Word16 *pitch_buf_fx, /* i : Decoded pitch buffer */ - const Word16 Last_ener_fx, /* i : Last energy (Q8) */ - const Word16 rate_switching_reset, /* i : rate switching reset flag */ - const Word16 last_coder_type_fx /* i : Last coder_type */ -); - -void FEC_pitch_estim_fx( - const Word16 Opt_AMR_WB, /* i : flag indicating AMR-WB IO mode */ - const Word16 last_core, /* i : last core */ - const Word16 L_frame, /* i : length of the frame */ - const Word16 clas, /* i : current frame classification */ - const Word16 last_good, /* i : last good clas information */ - const Word16 pitch_buf[], /* i : Floating pitch for each subframe */ - const Word32 old_pitch_buf[], /* i : buffer of old subframe pitch values 15Q16 */ - Word16 *bfi_pitch, /* i/o: update of the estimated pitch for FEC */ - Word16 *bfi_pitch_frame, /* o : frame length when pitch was updated */ - Word16 *upd_cnt, /* i/o: update counter */ - const Word16 coder_type /* i : coder_type */ -); - -Word16 div_s_ss( /* o: result of division (Word16 Q0) */ - const Word16 n, /* i: numerator (Word16 Q0 */ - const Word16 d /* i: denominator (Word16 Q0) */ -); - -Word16 detect_transient_fx( - const Word16 *in_fx, /*Q_new */ - /*Encoder_State *st, */ - const Word16 L, - const Word16 coder_type, /* i : coder type */ - Word16 Q_new, - Encoder_State_fx *st_fx -); - -Word16 detect_transient_fx32( /* o : transient flag */ - const Word32* in_fx, /* i : input signal */ - Encoder_State_fx *st_fx, /* i/o: Encoder state structure */ - const Word16 L, /* i : length (32 or 48kHz) */ - const Word16 coder_type /* i : coder type */ -); - -void ar_encoder_start_fx( PARCODEC_FX arInst, PBITSTREAM_FX bsInst, Word32 max_bits ); -void ar_encoder_done_fx( PARCODEC_FX arInst ); -void ar_decoder_start_fx( PARCODEC_FX arInst, PBITSTREAM_FX bsInst ); -void ar_decoder_done_fx( PARCODEC_FX arInst ); - -void srt_vec_ind_fx (const Word32 *linear, Word32 *srt, Word16 *I, Word16 length); -Word32 ar_div(Word32 num, Word32 denum); - -Word16 GetScale_fx( Word16 blen, Word32 bits_fx, Word32 *surplus_fx); -Word32 encode_position_ari_fx(PARCODEC_FX parenc, Word16* quants, Word16 size, Word32* est_bits_frame_fx); -Word32 encode_magnitude_usq_fx(ARCODEC_FX* parenc, Word16* magn, Word16 size, Word16 npulses, Word16 nzpos, Word32* est_frame_bits_fx); -Word32 encode_magnitude_tcq_fx(ARCODEC_FX* parenc, Word16* magn, Word16 size, Word16 npulses, Word16 nzpos, Word32* savedstates, Word32* est_frame_bits_fx); -Word32 GetISCScale_fx( Word32 *quants_fx, Word16 size, Word32 bits_fx, Word16 *magn_fx, Word32 *qscale_fx, Word32 *surplus_fx, Word16 *pulses, Word32* savedstates, Word32 noTCQ, Word16 *nzpout - , Word16 *bcount, Word32 *abuffer, Word16 *mbuffer, Word32 *sbuffer ); -Word32 encode_signs_fx(ARCODEC_FX* parenc, Word16* magn, Word16 size, Word16 npos, Word32* est_frame_bits_fx); - -void decode_position_ari_fx(PARCODEC_FX pardec, Word16 size, Word16 npulses, Word16* nz, Word16* position); -void decode_magnitude_usq_fx(ARCODEC_FX* pardec, Word16 size, Word16 npulses, Word16 nzpos, Word16* positions, Word16* out); -void decode_mangitude_tcq_fx(ARCODEC_FX* pardec, Word16 size, Word16 npulses, Word16 nzpos, Word16* positions, Word16* out, Word32* surplus_fx); -void decode_signs_fx(ARCODEC_FX* pardec, Word16 size, Word16* out); - -void tcq_core_LR_enc_fx( - Encoder_State_fx* st_fx, - Word16 inp_vector_fx[], - const Word32 coefs_norm_fx[], - Word32 coefs_quant_fx[], - const Word16 bit_budget, /* number of bits */ - const Word16 nb_sfm, - const Word16 *sfm_start, - const Word16 *sfm_end, - const Word16 *sfmsize, - Word32 *R_fx, - Word16 *npulses, - Word16 *k_sort, - const Word16 *p2a_flags, - const Word16 p2a_bands, - const Word16 *last_bitalloc, - const Word16 input_frame, - const Word16 adjustFlag, - const Word16 is_transient -); - -void tcq_core_LR_dec_fx( - Decoder_State_fx *st_fx, - Word16 *inp_vector_fx, - const Word16 bit_budget, - const Word16 bands, - const Word16 *band_start, - const Word16 *band_width, - Word32 *Rk_fx, - Word16 *npulses, - Word16 *k_sort, - const Word16 *p2a_flags, - const Word16 p2a_bands, - const Word16 *last_bitalloc, - const Word16 input_frame, - const Word16 adjustFlag, - const Word16 *is_transient -); - -void TCQLSB_fx( - Word16 bcount, - Word32 *abuffer_fx, - Word16 *mbuffer_fx, - Word32 *sbuffer_fx, - Word16 *dpath -); - -void TCQLSBdec_fx( - Word16 *dpath, - Word16 *mbuffer, - Word16 bcount -); - -void RestoreTCQ_fx( - Word16 * magn, - Word16 size, - Word16 *bcount, - Word16 *mbuffer -); - -void RestoreTCQdec_fx( - Word16 * magn, - Word16 size, - Word16 *bcount, - Word16 *mbuffer -); - -void InitLSBTCQ_fx( - Word16 *bcount -); - -void SaveTCQdata_fx( - PARCODEC_FX arInst, - Word16 *dpath, - Word16 bcount -); - -void LoadTCQdata_fx( - PARCODEC_FX arInst, - Word16 *dpath, - Word16 bcount -); - -void bit_allocation_second_fx( - Word32 *Rk, - Word32 *Rk_sort, - Word16 BANDS, - const Word16 *band_width, - Word16 *k_sort, - Word16 *k_num, - const Word16 *p2a_flags, - const Word16 p2a_bands, - const Word16 *last_bitalloc, - const Word16 input_frame -); - -void window_ola_fx( - Word32 *ImdctOut, - Word16 *auOut, - Word16 *Q_sig, - Word16 *OldauOut, - Word16 *Q_old, - const Word16 L, - const Word16 right_mode, - const Word16 left_mode, - const Word16 old_bfi, - const Word16 oldHqVoicing, - Word16 *oldgapsynth -); - -void tcx_get_windows_mode1( - Word16 left_mode, /* i: overlap mode of left window half */ - Word16 right_mode, /* i: overlap mode of right window half */ - Word16 *left_win, /* o: left overlap window */ - Word16 *right_win, /* o: right overlap window */ - Word16 *left_win_int, /* o: left overlap window */ - Word16 *right_win_int, /* o: right overlap window */ - Word16 const L -); - -void sinq_fx( - const Word16 tmp, /* i : sinus factor cos(tmp*i+phi) Q15*/ - const Word16 phi, /* i : sinus phase cos(tmp*i+phi) Q15*/ - const Word16 N, /* i : size of output */ - Word16 x[] /* o : output vector Q15*/ -); - -Word16 FEC_phase_matching_fx( - Decoder_State_fx *st_fx, /* i : Decoder State */ - Word32 *ImdctOut_fx, /* i : input */ - Word16 *auOut_fx, /* o : output audio */ - Word16 *OldauOut_fx, - Word16 OldauOut_pha_fx[2][N_LEAD_NB] -); - -void FEC_phase_matching_nextgood_fx( - const Word32 *ImdctOut_fx, /* i : input */ - Word16 *auOut_fx, /* o : output audio */ - Word16 *OldauOut_fx, /* i/o: audio from previous frame */ - Word16 OldauOut_pha_fx[2][N_LEAD_NB], - Word16 mean_en_high_fx /* Q5 */ -); - -void FEC_phase_matching_burst_fx( - const Word32 *ImdctOut_fx, /* i : input */ - Word16 *auOut_fx, /* o : output audio */ - Word16 *OldauOut_fx, /* i/o: audio from previous frame */ - Word16 OldauOut_pha_fx[2][N_LEAD_NB], - Word16 *prev_oldauOut_fx /* i : OldauOut from previous frame */ -); - -void Repetition_smoothing_nextgood_fx( - const Word32 *ImdctOut_fx, /* i : input */ - Word16 *auOut_fx, /* o : output audio */ - Word32 *OldImdctOut_fx, /* i : input */ - Word16 *OldauOut_fx, /* i/o: audio from previous frame */ - Word16 cur_data_use_flag, /* i : current imdct data use flag */ - Word16 overlap_time -); - -Word16 Repetition_smoothing_fx( - const Word32 *ImdctOut_fx, /* i : input */ - Word16 *auOut_fx, /* o : output audio */ - Word32 *OldImdctOut_fx, /* i/o: audio from previous frame */ - Word16 *OldauOut_fx, /* i/o: audio from previous frame */ - const Word16 L, /* i : length */ - Word16 *prev_oldauOut_fx, /* i/o: IMDCT output from previous old frame */ - Word16 overlap_time /* i : overlapping time */ -); - -void time_domain_FEC_HQ_fx( - Decoder_State_fx *st_fx, /* i : Decoder State */ - Word32 *wtda_audio_fx, /* i : input */ - Word16 *out_fx, /* o : output audio */ - Word16 mean_en_high_fx, /* i : transient flag */ - const Word16 output_frame, - Word16 *Q_synth -); - -void common_overlapping_fx( - Word16 *auOut_fx, /* i : Input */ - Word16 *ImdctOutWin_fx, /* o : Output */ - Word16 *OldauOut_fx, /* i : Window */ - Word16 end1, /* i : Decay */ - Word16 offset1, - Word16 start2, - Word16 end2, - Word16 offset_i2, - Word16 offset2 -); - -void Smoothing_vector_scaledown_NB_fx( - const Word16 OldauOutnoWin_fx[], /* i : Input vector 1 */ - const Word16 ImdctOutWin_fx[], /* i : Input vector 2 */ - const Word16 SmoothingWin_fx[], /* i : Smoothing window */ - Word16 auOut_fx[], /* o : Output vector that contains vector 1 .* vector 2*/ - const Word16 ol_size /* i : Overlap size */ -); - -void Scaledown_fx( - Word16 x[], /* i : Input vector */ - Word16 y[], /* o : Output vector that contains vector 1 .* vector 2*/ - Word16 scale_v, - const Word16 N /* i : Overlap size */ -); - -void Smoothing_vector_NB_fx( - const Word16 OldauOutnoWin_fx[], /* i : Input vector 1 */ - const Word16 ImdctOutWin_fx[], /* i : Input vector 2 */ - const Word16 SmoothingWin_fx[], /* i : Smoothing window */ - Word16 auOut_fx[], /* o : Output vector that contains vector 1 .* vector 2 */ - const Word16 ol_size /* i : Overlap size */ -); - -void Windowing_1st_NB_fx( - Word16 *ImdctOutWin_fx, /* o : Output */ - const Word32 *ImdctOut_fx, /* i : Input */ - const Word16 *win_fx, /* i : Window */ - const Word16 *smoothingWin_fx, /* i : Smoothing Window */ - Word16 smoothing_flag /* i : 1=Smoothing window, 0=Original window */ -); - -void Windowing_2nd_NB_fx( - Word16 *ImdctOutWin_fx, /* o : Output */ - const Word32 *ImdctOut_fx, /* i : Input */ - const Word16 *win_fx /* i : Window */ -); - -void Next_good_after_burst_erasures_fx( - const Word32 *ImdctOut_fx, - Word16 *auOut_fx, - Word16 *OldauOut_fx, - const Word16 ol_size -); - -void subband_gain_bits_fx( - const Word16 *Rk, /* i : bit allocation per band Q3 */ - const Word16 N, /* i : number of bands */ - Word16 *bits, /* o : gain bits per band */ - const Word16 *sfmsize /* i : Size of bands */ -); - -Word16 assign_gain_bits_fx( /* o : Number of assigned gain bits */ - const Word16 core, /* i : HQ core */ - const Word16 BANDS, /* i : Number of bands */ - const Word16 *band_width, /* i : Sub band bandwidth */ - Word16 *Rk, /* i/o: Bit allocation/Adjusted bit alloc. Q3 */ - Word16 *gain_bits_array, /* o : Assigned gain bits */ - Word16 *Rcalc /* o : Bit budget for shape quantizer Q3 */ -); - -void apply_gain_fx( - const Word16 *ord, /* i : Indices for energy order */ - const Word16 *band_start, /* i : Sub band start indices */ - const Word16 *band_end, /* i : Sub band end indices */ - const Word16 num_sfm, /* i : Number of bands */ - const Word16 *gains, /* i : Band gain vector Q12 */ - Word16 *xq /* i/o: Float synthesis / Gain adjusted synth Q15/Q12 */ -); - -void fine_gain_pred_fx( - const Word16 *sfm_start, /* i : Sub band start indices */ - const Word16 *sfm_end, /* i : Sub band end indices */ - const Word16 *sfm_size, /* i : Sub band bandwidths */ - const Word16 *i_sort, /* i : Energy sorting indices */ - const Word16 *K, /* i : Number of pulses per band */ - const Word16 *maxpulse, /* i : Maximum pulse per band */ - const Word16 *R, /* i : Bits per sub band Q3 */ - const Word16 num_sfm, /* i : Number of sub bands */ - Word16 *xq, /* i/o: Quantized vector /quantized vector with finegain adj Q15*/ - Word16 *y, /* i/o: Quantized vector (int) */ - Word16 *fg_pred, /* o : Predicted fine gains Q12 */ - const Word16 core /* i : Core */ -); - -void fine_gain_quant_fx( - Encoder_State_fx *st_fx, - const Word16 *ord, /* i : Indices for energy order */ - const Word16 num_sfm, /* i : Number of bands */ - const Word16 *gain_bits, /* i : Gain adjustment bits per sub band */ - Word16 *fg_pred, /* i/o: Predicted gains / Corrected gains Q12 */ - const Word16 *gopt /* i : Optimal gains Q12 */ -); - -void fine_gain_dec_fx -( - Decoder_State_fx *st, - const Word16 *ord, /* i : Indices for energy order */ - const Word16 num_sfm, /* i : Number of bands */ - const Word16 *gain_bits, /* i : Gain adjustment bits per sub band */ - Word16 *fg_pred /* i/o: Predicted gains / Corrected gains */ -); - -void get_max_pulses_fx( - const Word16 *band_start, /* i : Sub band start indices */ - const Word16 *band_end, /* i : Sub band end indices */ - const Word16 *k_sort, /* i : Indices for sorting by energy */ - const Word16 *npulses, /* i : Pulses per sub band */ - const Word16 BANDS, /* i : Number of bands */ - Word16 *inp_vector, /* i/o: Encoded shape vectors (int)*/ - Word16 *maxpulse /* o : Maximum pulse height per band */ -); - -Word16 pvq_core_enc_fx( - Encoder_State_fx *st_fx, - Word16 coefs_norm[], - Word16 coefs_quant[], - Word16 *Q_coefs, - Word16 bits_tot, /* total number of bits */ - Word16 nb_sfm, - const Word16 *sfm_start, - const Word16 *sfm_end, - const Word16 *sfmsize, - Word16 *R, /* Q3 */ - Word16 *Rs, - Word16 *npulses, - Word16 *maxpulse, - const Word16 core -); - -void pvq_encode_frame_fx( - Encoder_State_fx *st_fx, - const Word16 *coefs_norm, /* i : normalized coefficients to encode */ - Word16 Q_coefs, - Word16 *coefs_quant, /* o : quantized coefficients */ - Word16 *gopt, /* o : optimal shape gains */ - Word16 *npulses, /* o : number of pulses per band */ - Word16 *pulse_vector, /* o : non-normalized pulse shapes */ - const Word16 *sfm_start, /* i : indices of first coefficients in the bands */ - const Word16 *sfm_end, /* i : indices of last coefficients in the bands */ - const Word16 *sfmsize, /* i : band sizes */ - const Word16 nb_sfm, /* i : total number of bands */ - const Word16 *R, /* i : bitallocation per band */ - const Word16 pvq_bits, /* i : number of bits avaiable */ - const Word16 core /* i : core */ -); - - -void encode_energies_fx( - Encoder_State_fx *st_fx, - const Word16 *coefs, - const Word16 Q_coefs, - Word16 Np, - Word16 *dim_part, - Word32 *E_part, /* 32-bit Q15 */ - Word16 *bits_part, - Word16 *g_part, /* Q15 */ - Word16 qband, - Word16 *bits_left, - Word32 enr, /* 32-bit Q15 */ - Word16 dim, - const Word16 strict_bits -); - -Word16 pvq_core_dec_fx( - Decoder_State_fx *st_fx, - const Word16 *sfm_start, - const Word16 *sfm_end, - const Word16 *sfmsize, - Word16 coefs_quant[], /* o : output MDCT */ - Word16 *Q_coefs, - Word16 bits_tot, - Word16 nb_sfm, - Word16 *R, - Word16 *Rs, - Word16 *npulses, - Word16 *maxpulse, - const Word16 core -); - -void pvq_decode_frame_fx( - Decoder_State_fx *st_fx, - Word16 *coefs_quant, /* o : quantized coefficients */ - Word16 *npulses, /* o : number of pulses per band */ - Word16 *pulse_vector, /* o : non-normalized pulse shapes */ - const Word16 *sfm_start, /* i : indices of first coefficients in the bands */ - const Word16 *sfm_end, /* i : indices of last coefficients in the bands */ - const Word16 *sfmsize, /* i : band sizes */ - const Word16 nb_sfm, /* i : total number of bands */ - const Word16 *R, /* i : bitallocation per band */ - const Word16 pvq_bits, /* i : number of bits avaiable */ - const Word16 core /* i : core */ -); - -void decode_energies_fx( - Decoder_State_fx *st_fx, - Word16 Np, - Word16 *dim_part, - Word16 *bits_part, - Word16 *g_part, /* Q15 */ - Word16 qband, - Word16 *bits_left, - Word16 dim, - const Word16 strict_bits -); - -Word16 atan2_fx( - const Word32, - const Word32 -); - -void srt_vec_ind16_fx ( - const Word16 *linear, /* linear input */ - Word16 *srt, /* sorted output*/ - Word16 *I, /* index for sorted output */ - Word16 length -); - - -PvqEntry_fx mpvq_encode_vec_fx( /* o : leading_sign_index, index, size, k_val */ - const Word16* vec_in, /* i : signed pulse train */ - Word16 dim_in, /* i : dimension */ - Word16 k_val_local /* i : nb unit pulses */ -); - -PvqEntry_fx get_size_mpvq_calc_offset_fx( /* o : size, dim, k_val */ - Word16 dim_in, /* i : dimension */ - Word16 k_val_in, /* i : nb unit pulses */ - UWord32* h_mem /* o : offsets */ -); - -void mpvq_decode_vec_fx( /* o : void */ - const PvqEntry_fx* entry, /* i : sign_ind, index, dim, k_val */ - UWord32* h_mem, /* i : A/U offsets */ - Word16* vec_out /* o : pulse train */ -); - -void rc_enc_init_fx( - Encoder_State_fx *st_fx, /* i/o: Encoder state */ - Word16 tot_bits /* i : Total bit budget */ -); - -void rc_encode_fx( - Encoder_State_fx *st_fx, /* i/o: Encoder state */ - UWord32 cum_freq, /* i : Cumulative frequency up to symbol */ - UWord32 sym_freq, /* i : Symbol probability */ - UWord32 tot /* i : Total cumulative frequency */ -); - -void rc_enc_uniform_fx( - Encoder_State_fx *st_fx, /* i/o: Encoder state */ - UWord32 value, /* i : Value to encode */ - UWord32 tot /* i : Maximum value */ -); - -void rc_enc_bits_fx( - Encoder_State_fx *st_fx, /* i/o: Encoder state */ - UWord32 value, /* i : Value to encode */ - Word16 bits /* i : Number of bits used */ -); - -void rc_enc_finish_fx( - Encoder_State_fx *st_fx /* i/o: Encoder state */ -); - -Word16 rc_get_bits2_fx( /* o: Number of bits needed */ - const Word16 N, /* i: Number of bits currently used */ - const UWord32 range /* i: Range of range coder */ -); - - -void rangeCoderFinalizationFBits_fx( - Word16 Brc, - UWord32 INTrc, - Word16 *FBits -); - -void conservativeL1Norm_fx( - Word16 L, - Word16 Qvec, - Word16 Fcons, - Word16 Qavail, - Word16 Qreserv, - Word16 Dspec, - Word16 *Dvec, - Word16 *Qspare, - Word16 *Qreservplus, - Word16 *Dspecplus -); - -void bandBitsAdjustment_fx( - Word16 Brc, - UWord32 INTrc, - Word16 Bavail, - Word16 Nbands, - Word16 D, - Word16 L, - Word16 Bband, - Word16 Breserv, - Word16 *Bband_adj, - Word16 *Brem, - Word16 *Breservplus -); - - -UWord32 rc_decode_fx( /* o : Decoded cumulative frequency */ - Decoder_State_fx *st_fx, /* i/o: Decoder State */ - UWord32 tot /* i : Total cumulative frequency */ -); - -void rc_dec_update_fx( - Decoder_State_fx *st_fx, /* i/o: Decoder State */ - UWord32 cum_freq, /* i : Cumulative frequency */ - UWord32 sym_freq /* i : Symbol frequency */ -); - -UWord32 rc_dec_uniform_fx( /* i : Decoded value */ - Decoder_State_fx *st_fx, /* i/o: Decoder State */ - UWord32 tot /* i : Maximum value */ -); - -void rc_dec_init_fx( - Decoder_State_fx *st_fx, /* i/o: Decoder State */ - Word16 tot_bits /* i : Total bit budget */ -); - -Word32 rc_dec_bits_fx( /* i : Decoded value */ - Decoder_State_fx *st_fx, /* i/o: Decoder State */ - Word16 bits /* i : Number of bits */ -); - -void rc_dec_finish_fx( - Decoder_State_fx *st_fx -); - -UWord32 UL_inverse( - const UWord32 UL_val, - Word16 *exp -); - -UWord32 UL_div( - const UWord32 UL_num, - const UWord32 UL_den -); - -void hq_core_enc_fx( - Encoder_State_fx *st_fx, - const Word16 *audio, /* i : input audio signal Q0 */ - const Word16 input_frame_orig,/* i : frame length */ - const Word16 hq_core_type, /* i : HQ core type */ - const Word16 Voicing_flag -); - -void normalizecoefs_fx( - Word32 *coefs, /* i : Input vector (Q12) */ - const Word16 *ynrm, /* i : quantization indices for norms */ - const Word16 num_bands, /* i : Number of bands */ - const Word16 *band_start, /* i : Start of bands */ - const Word16 *band_end, /* i : End of bands */ - Word16 *coefs_norm /* o : Normalized output vector (Q12) */ -); - -void calc_norm_fx( - const Word32 *L_x, /* i : Input vector. Qx */ - const Word16 qx, /* i : Q value of input */ - Word16 *norm, /* o : Quantization indices for norms Q0 */ - Word16 *normlg, /* o : Quantized norms in log2 Q0 */ - const Word16 start_band, /* i : Indice of band to start coding Q0 */ - const Word16 num_bands, /* i : Number of bands Q0 */ - const Word16 *band_len, /* i : Length of bands Q0 */ - const Word16 *band_start /* i : Start of bands Q0 */ -); - -void diff_envelope_coding_fx( - const Word16 is_transient, /* i : transient indicator Q0 */ - const Word16 num_env_bands, /* i : number of envelope bands to code Q0 */ - const Word16 start_norm, /* i : start of envelope coding Q0 */ - Word16 *ynrm, /* i/o: quantization indices for norms Q0 */ - Word16 *normqlg2, /* i/o: quantized norms Q0 */ - Word16 *difidx /* o : differential code Q0 */ -); - -void reordernorm_fx( - const Word16 *ynrm, /* i : quantization indices for norms Q0 */ - const Word16 *normqlg2, /* i : quantized norms Q0 */ - Word16 *idxbuf, /* o : reordered quantization indices Q0 */ - Word16 *normbuf, /* o : reordered quantized norms Q0 */ - const Word16 nb_sfm /* i : number of bands Q0 */ -); - -void hq_hr_enc_fx( - Encoder_State_fx *st_fx, /* i/o: encoder state structure fx */ - Word32 *t_audio, /* i/o: transform-domain coefficients Q12? */ - const Word16 length, /* i : length of spectrum Q0 */ - Word16 *num_bits, /* i : number of available bits Q0 */ - const Word16 is_transient /* i : transient flag Q0 */ -); - -Word16 hq_classifier_enc_fx( /* o : Consumed bits Q0 */ - Encoder_State_fx *st_fx, /* i/o: encoder state structure */ - const Word16 length, /* i : Frame length Q0 */ - const Word32 *coefs, /* i : Spectral coefficients Q12 */ - const Word16 is_transient, /* i : Transient flag Q0 */ - Word16 *Npeaks, /* o : Number of identified peaks Q0 */ - Word16 *peaks, /* o : Peak indices Q0 */ - Word32 *pe_gains, /* o : Peak gains Q12 */ - Word32 *nf_gains, /* o : Noise-fill gains Q12 */ - Word16 *hqswb_clas /* o : HQ class Q0 */ -); - -void hvq_classifier_fx( - const Word32 *input, /* i : input signal Q12 */ - Word16 *prev_Npeaks, /* i/o: Peak number memory Q0 */ - Word16 *prev_peaks, /* i/o: Peak indices memory Q0 */ - Word16 *hqswb_clas, /* i/o: HQ class Q0 */ - Word16 *Npeaks, /* o : Number of peaks Q0 */ - Word16 *peaks, /* o : Peak indices Q0 */ - const Word32 L_core_brate, /* i : Core bit-rate Q0 */ - const Word16 last_core, /* i : Last core used Q0 */ - Word32 *L_nf_gains, /* o : Noisefloor gains Q12 */ - Word16 *hvq_hangover, /* i/o: Mode-switch hangover Q0 */ - Word32 *L_pe_gains /* o : peak gains Q12 */ -); - -void limit_band_noise_level_calc_fx( - const Word16 *wnorm, /* i : reordered norm of sub-vectors */ - Word16 *limit, /* o : highest band of bit allocation */ - const Word32 core_brate, /* i : bit rate */ - Word16 *noise_level /* o : noise level Q15 */ -); - -Word16 BitAllocWB_fx( /* o : t Q0*/ - Word16 *y, /* i : norm of sub-vectors Q0*/ - Word16 B, /* i : number of available bits Q0*/ - Word16 N, /* i : number of sub-vectors Q0*/ - Word16 *R, /* o : bit-allocation indicator Q0*/ - Word16 *Rsubband_fx /* o : sub-band bit-allocation vector Q3*/ -); - -void hq_wb_nf_bwe_fx( - const Word16 *coeff_fx, /* i : coded/noisefilled normalized spectrum */ - const Word16 is_transient, - const Word16 prev_bfi, /* i : previous bad frame indicator */ - const Word32 *L_normq_v, - const Word16 num_sfm, /* i : Number of subbands */ - const Word16 *sfm_start, /* i : Subband start coefficient */ - const Word16 *sfm_end, /* i : Subband end coefficient */ - const Word16 *sfmsize, /* i : Subband band width */ - const Word16 last_sfm, /* i : last coded subband */ - const Word16 *R, /* i : bit allocation */ - const Word16 prev_is_transient, /* i : previous transient flag */ - Word32 *prev_normq_fx, /* i/o: previous norms */ - Word32 *prev_env_fx, /* i/o: previous noise envelopes */ - Word16 *bwe_seed, /* i/o: random seed for generating BWE input */ - Word32 *prev_coeff_out_fx, /* i/o: decoded spectrum in previous frame */ - Word16 *prev_R, /* i/o: bit allocation info. in previous frame */ - Word32 *L_coeff_out, /* o : coded/noisefilled spectrum */ - Word16 *prev_env_Q -); - -void harm_bwe_fine_fx( - const Word16 *R, /* i : bit allocation */ - const Word16 last_sfm, /* i : last coded subband */ - const Word16 high_sfm, /* i : higher transition band to BWE */ - const Word16 num_sfm, /* i : total number of bands */ - const Word16 *norm, /* i : quantization indices for norms */ - const Word16 *sfm_start, /* i : Subband start coefficient */ - const Word16 *sfm_end, /* i : Subband end coefficient */ - Word16 *prev_L_swb_norm, /* i/o: last normalize length */ - Word16 *coeff, /* i/o: coded/noisefilled normalized spectrum */ - Word32 *coeff_out, /* o : coded/noisefilled spectrum */ - Word16 *coeff_fine /* o : BWE fine structure */ -); - -void harm_bwe_fx( - const Word16 *coeff_fine, /* i : fine structure for BWE */ - const Word16 *coeff, /* i : coded/noisefilled normalized spectrum */ - const Word16 num_sfm, /* i : Number of subbands */ - const Word16 *sfm_start, /* i : Subband start coefficient */ - const Word16 *sfm_end, /* i : Subband end coefficient */ - const Word16 last_sfm, /* i : last coded subband */ - const Word16 *R, /* i : bit allocation */ - const Word16 prev_hq_mode, /* i : previous hq mode */ - Word16 *norm, /* i/o: quantization indices for norms */ - Word16 *noise_level, /* i/o: noise levels for harmonic modes */ - Word16 *prev_noise_level, /* i/o: noise factor in previous frame */ - Word16 *bwe_seed, /* i/o: random seed for generating BWE input */ - Word32 *coeff_out /* o : coded/noisefilled spectrum */ -); - -void hq_generic_encoding_fx( - const Word32 *coefs_fx, /* i : MDCT coefficients of weighted original */ - Word16 *hq_generic_fenv_fx, /* i/o: energy of SWB envelope */ - const Word16 hq_generic_offset, /* i : frequency offset for extracting energy */ - Encoder_State_fx *st_fx, /* i/o: encoder state structure */ - Word16 *hq_generic_exc_clas /* o : bwe excitation class */ -); - -void hq_generic_fine_fx( - Word16 *coeff, /* i : coded/noisefilled normalized spectrum */ - const Word16 last_sfm, /* i : Last coded band */ - const Word16 *sfm_start, /* i : Subband start coefficient */ - const Word16 *sfm_end, /* i : Subband end coefficient */ - Word16 *bwe_seed, /* i/o: random seed for generating BWE input */ - Word16 *coeff_out1 /* o : HQ Generic input */ -); - -void hq_bwe_fx( - const Word16 HQ_mode, /* i : HQ mode */ - Word32 *coeff_out1, /* i/o: BWE input & temporary buffer */ - const Word16 *hq_generic_fenv, /* i : SWB frequency envelopes */ - Word32 *coeff_out, /* o : SWB signal in MDCT domain */ - const Word16 hq_generic_offset, /* i : frequency offset for representing hq generic bwe*/ - Word16 *prev_L_swb_norm, /*i/o : last normalize length */ - const Word16 hq_generic_exc_clas,/* i : bwe excitation class */ - const Word16 *sfm_end, /* i : End of bands */ - const Word16 num_sfm, - const Word16 num_env_bands, - const Word16 *R -); - -void hq_generic_decoding_fx( - const Word16 HQ_mode, /* i : HQ mode */ - Word32 *coeff_out1_fx, /* i/o: BWE input & temporary buffer */ - const Word16 *hq_generic_fenv_fx, /* i : SWB frequency envelopes */ - Word32 *coeff_out_fx, /* o : SWB signal in MDCT domain */ - const Word16 hq_generic_offset, /* i : frequency offset for representing hq generic*/ - Word16 *prev_L_swb_norm, /* i/o: last normalize length */ - const Word16 hq_generic_exc_clas, /* i : bwe excitation class */ - const Word16 *R -); - - -void map_hq_generic_fenv_norm_fx( - const Word16 hqswb_clas, - const Word16 *hq_generic_fenv, /* Q1, frequency-domain BWE envelope */ - Word16 *ynrm, - Word16 *normqlg2, - const Word16 num_env_bands, - const Word16 nb_sfm, - const Word16 hq_generic_offset -); - -Word16 get_nor_delta_hf_fx( - Decoder_State_fx *st, - Word16 *ynrm, - Word16 *Rsubband, /* Q3 */ - const Word16 num_env_bands, - const Word16 nb_sfm, - const Word16 core_sfm -); - -Word16 calc_nor_delta_hf_fx( - Encoder_State_fx *st, - const Word32 *t_audio, - Word16 *ynrm, - Word16 *Rsubband, - const Word16 num_env_bands, - const Word16 nb_sfm, - const Word16 *sfmsize, - const Word16 *sfm_start, - const Word16 core_sfm -); - -void HQ_FEC_processing_fx( - Decoder_State_fx *st_fx, /* i/o: decoder state structure */ - Word32 *t_audio_q_fx, /* o : MDCT coeffs. (for synthesis) Q12 */ - Word16 is_transient, /* i : Old flag for transient */ - Word32 ynrm_values_fx[][MAX_PGF], /* i : Old average Norm values for each group of bands Q12 */ - Word32 r_p_values_fx[][MAX_ROW], /* i : Computed y-intercept and slope by Regression Q5 */ - Word16 num_Sb, /* i : Number of sub-band group */ - Word16 nb_sfm, /* i : Number of sub-band */ - Word16 *Num_bands_p, /* i : Number of coeffs. for each sub-band */ - Word16 output_frame, /* i : Frame size */ - const Word16 *sfm_start, /* i : Start of bands */ - const Word16 *sfm_end /* i : End of bands */ -); - -void HQ_FEC_Mem_update_fx( - Decoder_State_fx *st_fx, /* i/o: decoder state structure */ - Word32 *t_audio_q_fx, /*Q12*/ - Word32 *normq_fx, /*Q14*/ - Word16 *ynrm, - Word16 *Num_bands_p, - Word16 is_transient, - Word16 hqswb_clas, - Word16 c_switching_flag, - Word16 nb_sfm, - Word16 num_Sb, - Word16 *mean_en_high_fx, /*Q5*/ - Word16 hq_core_type, /* i : normal or low-rate MDCT(HQ) core */ - Word16 output_frame -); - -Word16 BitAllocF_fx ( - Word16 *y, /* i : norm of sub-vectors :Q0 */ - Word32 bit_rate, /* i : bitrate :Q0 */ - Word16 B, /* i : number of available bits :Q0 */ - Word16 N, /* i : number of sub-vectors :Q0 */ - Word16 *R, /* o : bit-allocation indicator :Q0 */ - Word16 *Rsubband_fx, /* o : sub-band bit-allocation vector :Q3 */ - const Word16 hqswb_clas, /* i : hq swb class */ - const Word16 num_env_bands /* i : Number sub bands to be encoded for HQ_SWB_BWE */ -); - -void hq_bit_allocation_fx( - const Word32 core_brate, /* i : Core bit-rate */ - const Word16 length, /* i : Frame length */ - const Word16 hqswb_clas, /* i : HQ class */ - Word16 *num_bits, /* i/o: Remaining bit budget */ - const Word16 *normqlg2, /* i : Quantized norms */ - const Word16 nb_sfm, /* i : Number sub bands to be encoded */ - const Word16 *sfmsize, /* i : Sub band bandwidths */ - Word16 *noise_level, /* o : HVQ noise level */ - Word16 *R, /* o : Bit allocation per sub band */ - Word16 *Rsubband, /* o : Fractional bit allocation */ - Word16 *sum, /* o : Sum of allocated shape bits */ - Word16 *core_sfm, /* o : Last coded band in core */ - const Word16 num_env_bands /* i : Number sub bands to be encoded for HQ_SWB_BWE */ -); - -void hvq_dec_fx( - Decoder_State_fx *st_fx, /* i/o: decoder state structure */ - const Word16 num_bits, /* i : Number of available bits */ - const Word32 core_brate, /* i : Core bit-rate */ - const Word16 *ynrm, /* i : Envelope coefficients */ - Word16 *R, /* i/o: Bit allocation/updated bit allocation */ - Word16 *noise_level, /* o : Noise level in Q15 */ - Word16 *peak_idx, /* o : Peak position vector */ - Word16 *Npeaks, /* o : Total number of peaks */ - Word32 *coefsq_norm, /* o : Output vector in Q12 */ - const Word16 core -); - -void peak_vq_dec_fx( - Decoder_State_fx *st_fx, /* i/o: decoder state structure */ - Word32 *coefs_out, /* o : Output coefficient vector Q12 */ - const Word16 brate, /* i : Core bitrate */ - const Word16 num_bits, /* i : Number of bits for HVQ */ - const Word16 *ynrm, /* i : Envelope coefficients */ - Word16 *R, /* i/o: Bit allocation/updated bit allocation */ - Word16 *vq_peak_idx, /* o : Peak position vector */ - Word16 *Npeaks, /* o : Number of peaks */ - const Word16 core -); - -void hq_pred_hb_bws_fx( - Decoder_State_fx *st_fx, /* i/o: decoder state structure */ - const Word16 *ynrm, /* i : norm quantization index vector */ - const Word16 length, /* i : frame length */ - const Word16 hqswb_clas, /* i : HQ SWB class */ - const Word16 *SWB_fenv /* i : SWB frequency envelopes Q1 */ -); -void hq_core_dec_fx( - Decoder_State_fx *st_fx, /* i/o: decoder state structure fx */ - Word16 synth[], /* o : output synthesis */ - Word16 *Q_synth, /* o : Q value of synth */ - const Word16 output_frame, /* i : output frame length */ - const Word16 hq_core_type, /* i : HQ core type */ - const Word16 core_switching_flag /* i : ACELP->HQ switching frame flag */ -); - -void hq_hr_dec_fx( - Decoder_State_fx *st_fx, /* i/o: decoder state structure fx */ - Word32 *L_coefsq, /* o : transform-domain coefficients Q12 */ - const Word16 length, /* i : frame length Q0 */ - Word16 num_bits, /* i : number of available bits Q0 */ - Word16 *ynrm, /* o : norm quantization index vector Q0 */ - Word16 *is_transient, /* o : transient flag Q0 */ - Word16 *hqswb_clas, /* o : HQ SWB class Q0 */ - Word16 *SWB_fenv /* o : SWB frequency envelopes Q1 */ -); - -void dequantize_norms_fx( - Decoder_State_fx *st_fx, /* i/o: decoder state structure */ - const Word16 start_norm, /* i : First SDE encoded norm */ - const Word16 num_sfm, /* i : Number of norms */ - const Word16 is_transient, /* i : Transient flag */ - Word16 *ynrm, /* o : Decoded norm indices */ - Word16 *normqlg2 /* o : Log2 of decoded norms */ -); - -void huff_dec_fx( - Decoder_State_fx *st_fx, /* i/o: decoder state structure */ - const Word16 N, /* i : Number of codewords to decode */ - const Word16 buffer_len, /* i : Number of bits to read */ - const Word16 num_lengths, /* i : Number of different huffman codeword lengths */ - const Word16 *thres, /* i : Threshold of first codeword of each length */ - const Word16 *offset, /* i : Offset for first codeword */ - const Word16 *huff_tab, /* i : Huffman table order by codeword lengths */ - Word16 *index /* o : Decoded index */ -); - -Word16 hq_classifier_dec_fx( /* o : Consumed bits Q0 */ - Decoder_State_fx *st_fx, /* i/o: decoder state structure */ - const Word32 core_brate, /* i : Core bit rate Q0 */ - const Word16 length, /* i : Frame length Q0 */ - Word16 *is_transient, /* o : Transient flag Q0 */ - Word16 *hqswb_clas /* o : HQ class Q0 */ -); - -void hq_configure_bfi_fx( - Word16 *nb_sfm, /* o : Number of sub bands Q0 */ - Word16 *num_Sb, /* o : Number of FEC sub bands ? Q0 */ - Word16 *num_bands_p, /* o : FEC sub bands Q0 */ - Word16 const **sfmsize, /* o : Subband bandwidths */ - Word16 const **sfm_start, /* o : Subband start coefficients */ - Word16 const **sfm_end /* o : Subband end coefficients */ -); - -void hq_swb_harmonic_calc_norm_envelop_fx( - Word32 *L_SWB_signal, /* i : input signal Q=12*/ - Word32 *L_envelope, /* o : output envelope Q=12*/ - Word16 L_swb_norm, /* i : length of normaliztion */ - Word16 SWB_flength /* i : length of input signal */ -); - -Word16 build_nf_codebook_fx( /* o : Number of coefficients in nf codebook */ - const Word16 flag_32K_env_ho, /* i : Envelope attenuation hangover flag */ - const Word16 *coeff, /* i : Coded spectral coefficients */ - const Word16 *sfm_start, /* i : Subband start indices */ - const Word16 *sfmsize, /* i : Subband widths */ - const Word16 *sfm_end, /* i : Subband end indices */ - const Word16 last_sfm, /* i : Last coded band */ - const Word16 *R, /* i : Per-band bit allocation */ - Word16 *CodeBook, /* o : Noise-fill codebook */ - Word16 *CodeBook_mod /* o : Densified noise-fill codebook */ -); - -Word16 find_last_band_fx( /* o : index of last band */ - const Word16 *bitalloc, /* i : bit allocation */ - const Word16 nb_sfm /* i : number of possibly coded bands */ -); - -void apply_noisefill_HQ_fx( - const Word16 *R, /* i : bit allocation */ - const Word16 length, /* i : input frame length */ - const Word16 flag_32K_env_ho,/* i : envelope stability hangover flag*/ - const Word32 L_core_brate, /* i : core bit rate */ - const Word16 last_sfm, /* i : last coded subband */ - const Word16 *CodeBook, /* i : Noise-fill codebook */ - const Word16 *CodeBook_mod, /* i : Densified noise-fill codebook */ - const Word16 cb_size, /* i : Codebook length */ - const Word16 *sfm_start, /* i : Subband start coefficient */ - const Word16 *sfm_end, /* i : Subband end coefficient */ - const Word16 *sfmsize, /* i : Subband band width */ - Word16 *coeff /* i/o: coded/noisefilled spectrum */ -); - -void hvq_bwe_fine_fx( - const Word16 last_sfm, /* i : last coded subband */ - const Word16 num_sfm, /* i : total number of bands */ - const Word16 *sfm_end, /* i : Subband end coefficient */ - const Word16 *peak_idx, /* i : Peak index */ - const Word16 Npeaks, /* i : Number of peaks */ - Word16 *peak_pos, /* o : Peak positions */ - Word16 *prev_L_swb_norm, /* i/o: last normalize length */ - Word32 *L_coeff, /* i/o: coded/noisefilled normalized spectrum */ - Word16 *bwe_peaks, /* o : Positions of peaks in BWE */ - Word16 *coeff_fine /* o : HVQ BWE fine structure */ -); - -void hq_fold_bwe_fx( - const Word16 last_sfm, /* i : last coded subband Q0 */ - const Word16 *sfm_end, /* i : Subband end coefficient Q0 */ - const Word16 num_sfm, /* i : Number of subbands Q0 */ - Word16 *coeff /* i/o: coded/noisefilled normalized spectrum Q12 */ -); - -void apply_nf_gain_fx( - const Word16 nf_idx, /* i : noise fill gain index Q0 */ - const Word16 last_sfm, /* i : last coded subband Q0 */ - const Word16 *R, /* i : bit allocation Q0 */ - const Word16 *sfm_start, /* i : Subband start coefficient Q0 */ - const Word16 *sfm_end, /* i : Subband end coefficient Q0 */ - Word16 *coeff /* i/o: coded/noisefilled normalized spectrum Q12 */ -); - -void logqnorm_fx( - const Word32 *x, /* i : coefficient vector Qx */ - const Word16 qx, /* i : Q value of input */ - Word16 *k, /* o : index Q0 */ - const Word16 L, /* i : codebook length Q0 */ - const Word16 N, /* i : sub-vector size Q0 */ - const Word16 hvq_flag /* i : HVQ flag Q0 */ -); - -void logqnorm_2_fx( - const Word32 *env_fl, /* o : index */ - const Word16 L, /* i : codebook length */ - const Word16 n_env_band, /* i : sub-vector size */ - const Word16 nb_sfm, /* i : sub-vector size */ - Word16 *ynrm, - Word16 *normqlg2, - const Word32 *thren /* i : quantization thresholds */ -); - -void hvq_bwe_fx( - const Word32 *coeff, - const Word16 *coeff_fine, /* i : coded/noisefilled normalized spectrum Qin */ - const Word16 *sfm_start, /* i : Subband start coefficient Q0 */ - const Word16 *sfm_end, /* i : Subband end coefficient Q0 */ - const Word16 *sfm_len, /* i : Subband length Q0 */ - const Word16 last_sfm, /* i : last coded subband Q0 */ - const Word16 prev_hq_mode, /* i : previous hq mode Q0 */ - const Word16 *bwe_peaks, /* i : HVQ bwe peaks Q0 */ - const Word16 bin_th, /* i : HVQ transition bin Q0 */ - const Word16 num_sfm, /* i : Number of bands Q0 */ - const Word32 core_brate, /* i : Core bit-rate Q0 */ - const Word16 *R, /* i : Bit allocation */ - Word16 *norm, /* i/o: quantization indices for norms Q0 */ - Word16 *noise_level, /* i/o: noise levels for harmonic modes Q15 */ - Word16 *prev_noise_level, /* i/o: noise factor in previous frame Q15 */ - Word16 *bwe_seed, /* i/o: random seed for generating BWE input Q0 */ - Word32 *L_coeff_out, /* o : coded/noisefilled spectrum Qout*/ - const Word16 qin, - const Word16 qout -); - -void hvq_concat_bands_fx -( - const Word16 pvq_bands, /* i : Number of bands in concatenated PVQ target */ - const Word16 *sel_bnds, /* i : Array of selected high bands */ - const Word16 n_sel_bnds, /* i : Number of selected high bands */ - Word16 *hvq_band_start, /* i : Band start indices */ - Word16 *hvq_band_width, /* i : Band widths */ - Word16 *hvq_band_end /* i : Band end indices */ -); - -void noise_mix_fx( - const Word16 *coeff_fine, /* i : normalized fine structure spectrum Qin */ - const Word32 L_E, /* i : normalization factor Q17 */ - const Word32 L_normq, /* i : quantized norm Q14 */ - Word16 *seed, /* i/o: random seed Q0 */ - const Word16 istart, /* i : start coefficient Q0 */ - const Word16 iend, /* i : end coefficient Q0 */ - const Word16 noise_level, /* i : noise_level Q0 */ - Word32 *L_coeff_out, /* o : noisemixed spectrum Qout */ - const Word16 qin, - const Word16 qout -); - -Word16 noise_adjust_fx( /* o : index of noise attenuation Q0 */ - const Word16 *coeffs_norm, /* i : normalized coefficients Qx */ - const Word16 qx, /* i : Q value of coeffs_norm */ - const Word16 *bitalloc, /* i : bit allocation Q0 */ - const Word16 *sfm_start, /* i : band start Q0 */ - const Word16 *sfm_end, /* i : band end Q0 */ - const Word16 core_sfm /* i : index of the end band for core Q0 */ -); - -Word16 peak_vq_enc_fx( - Encoder_State_fx *st_fx, /* i/o: encoder state structure */ - const Word32 *coefs, /* i : Input coefficient vector Q14 */ - Word32 *coefs_out, /* o : Quantized output vector Q14 */ - const Word32 brate, /* i : Core bitrate */ - const Word16 num_bits, /* i : Number of bits for HVQ */ - const Word16 vq_peaks, /* i : Number of identified peaks */ - const Word16 *ynrm, /* i : Envelope coefficients */ - Word16 *R, /* i/o: Bit allocation/updated bit allocation */ - Word16 *vq_peak_idx, /* i : Peak index vector */ - Word32 *nf_gains /* i : Estimated noise floor gains Q14 */ -); - -Word16 hvq_enc_fx( /* o : Consumed bits */ - Encoder_State_fx *st_fx, /* i/o: encoder state structure */ - const Word32 brate, /* i : Total bit rate */ - const Word16 hvq_bits, /* i : HVQ bit budget */ - const Word16 Npeaks, /* i : Number of peaks */ - const Word16 *ynrm, /* i : Envelope coefficients */ - Word16 *R, /* i/o: Bit allocation/updated bit allocation */ - Word16 *peaks, /* i : Peak pos. / Encoded peak pos. */ - Word32 *nf_gains, /* i/o: Noise fill gains / Quant. nf gains */ - Word16 *noise_level, /* o : Quantized noise level */ - const Word32 *pe_gains, /* i : Peak gains */ - const Word32 *coefs, /* i : spectrum coefficients in Q14 */ - Word32 *coefs_out /* o : encoded spectrum coefficients in Q14 */ -); - -void enforce_zero_for_min_envelope_fx( - const Word16 hqswb_clas, /* i : HQ coding mode Q0 */ - const Word16 *ynrm, /* i : Envelope indices Q0 */ - Word32 *L_coefsq, /* i/o: Quantized spectrum/zeroed spectrum Q12 */ - const Word16 nb_sfm, /* i : Number of coded sub bands Q0 */ - const Word16 *sfm_start, /* i : Sub band start indices Q0 */ - const Word16 *sfm_end /* i : Sub band end indices Q0 */ -); - -void apply_envelope_fx( - const Word16 *coeff, /* i : Coded/noisefilled normalized spectrum Q12 */ - const Word16 *norm, /* i : Envelope */ - const Word16 *norm_adj, /* i : Envelope adjustment Q15 */ - const Word16 num_sfm, /* i : Total number of bands */ - const Word16 last_sfm, /* i : Last coded band */ - const Word16 HQ_mode, /* i : HQ mode */ - const Word16 length, /* i : Frame length */ - const Word16 *sfm_start, /* i : Sub band start indices */ - const Word16 *sfm_end, /* i : Sub band end indices */ - Word32 *normq_v, /* o : Envelope with adjustment Q14 */ - Word32 *coeff_out, /* o : coded/noisefilled spectrum */ - const Word16 *coeff1, /* i : coded/noisefilled spectrum Q12 */ - Word32 *coeff_out1 /* o : coded/noisefilled spectrum Q12 */ -); - -void bitalloc_fx ( - Word16 *y, /* i : reordered norm of sub-vectors Q0 */ - Word16 *idx, /* i : reordered sub-vector indices Q0 */ - Word16 sum, /* i : number of available bits Q0 */ - Word16 N, /* i : number of norms Q0 */ - Word16 K, /* i : maximum number of bits per dimension Q0 */ - Word16 *r, /* o : bit-allacation vector Q0 */ - const Word16 *sfmsize, /* i : band length Q0 */ - const Word16 hqswb_clas /* i : signal classification flag Q0 */ -); - -void bitallocsum_fx( - Word16 *R, /* i : bit-allocation vector Q0 */ - const Word16 nb_sfm, /* i : number of sub-vectors Q0 */ - Word16 *sum, /* o : total number of bits allocated Q0 */ - Word16 *Rsubband, /* o : rate per subband Q3 */ - const Word16 v, /* i : bit rate Q0 */ - const Word16 length, /* i : length of spectrum (32 or 48 kHz samplerate) Q0 */ - const Word16 *sfmsize /* i : band length Q0 */ -); - -void env_adj_fx -( - const Word16 *pulses, /* i : number of pulses per band Q0 */ - const Word16 length, /* i : length of spectrum Q0 */ - const Word16 last_sfm, /* i : index of the last band Q0 */ - Word16 *adj, /* o : adjustment factors for the envelope Q15 */ - const Word16 env_stab, /* i : envelope stability Q15 */ - const Word16 *sfmsize /* i : subband sizes Q0 */ -); - -Word16 env_stability_fx( /* in Q15 */ - const Word16 *ynrm, /*i: Norm vector for current frame */ - const Word16 nb_sfm, /*i: Number of sub-bands */ - Word16 *mem_norm, /*i/o: Norm vector memory from past frame */ - Word16 *mem_env_delta /*i/o: Envelope stability memory for smoothing in Q11 */ -); - -Word16 env_stab_smo_fx( /* Q0 */ - Word16 env_stab, /*i : env_stab value Q15 */ - Word16 *env_stab_state_p, /*i/o: env_stab state probabilities Q15 */ - Word16 *ho_cnt /*i/o: hangover counter for speech state */ -); - -void env_stab_transient_detect_fx( - const Word16 is_transient, /* i: Transient flag */ - const Word16 length, /* i : Length of spectrum (32 or 48 kHz) */ - const Word16 norm[], /* i : quantization indices for norms */ - Word16 *no_att_hangover, /* i/o: Frame counter for attenuation hangover (Q0) */ - Word32 *L_energy_lt, /* i/o: Long-term energy measure for transient detection (Q13) */ - const Word16 HQ_mode, /* i : HQ coding mode */ - const Word16 bin_th, /* i : HVQ cross-over frequency bin */ - const Word32 *L_coeff, /* i : Coded spectral coefficients */ - const Word16 Qcoeff /* i : Q of coded spectral coefficients */ -); - -void hq_configure_fx( - const Word16 length, /* i : Frame length Q0 */ - const Word16 hqswb_clas, /* i : HQ SWB class Q0 */ - const Word32 core_brate, /* i : Codec bitrate Q0 */ - Word16 *num_sfm, /* o : Total number of subbands Q0 */ - Word16 *nb_sfm, /* o : Total number of coded bands Q0 */ - Word16 *start_norm, /* o : First norm to be SDE encoded Q0 */ - Word16 *num_env_bands, /* o : Number coded envelope bands Q0 */ - Word16 *numnrmibits, /* o : Number of bits in fall-back norm encoding Q0 */ - Word16 *hq_generic_offset, /* o : Freq offset for HQ GENERIC Q0 */ - Word16 const **sfmsize, /* o : Subband bandwidths Q0 */ - Word16 const **sfm_start, /* o : Subband start coefficients Q0 */ - Word16 const **sfm_end /* o : Subband end coefficients Q0 */ -); - -Word16 hvq_pvq_bitalloc_fx( - Word16 num_bits, /* i/o: Number of available bits (including gain bits) */ - const Word32 brate, /* i : bitrate */ - const Word16 bwidth_fx, /* i : Encoded bandwidth */ - const Word16 *ynrm, /* i : Envelope coefficients */ - const Word32 manE_peak, /* i : Peak energy mantissa */ - const Word16 expE_peak, /* i : Peak energy exponent */ - Word16 *Rk, /* o : bit allocation for concatenated vector */ - Word16 *R, /* i/o: Global bit allocation */ - Word16 *sel_bands, /* o : Selected bands for encoding */ - Word16 *n_sel_bands /* o : No. of selected bands for encoding */ -); - -void disf_ns_28b_fx( - Word16 *indice, - Word16 *isf_q -); - -void isf_enc_amr_wb_fx( - Encoder_State_fx *st, /* i/o: state structure */ - Word16 *isf_new, /* o : quantized ISF vector */ - Word16 *isp_new, /* i/o: ISP vector to quantize/quantized */ - Word16 *Aq, /* o : quantized A(z) for 4 subframes */ - Word16 *stab_fac /* o : ISF stability factor */ -); - -void pvq_encode_fx( - Encoder_State_fx *st_fx, - const Word16 *x, /* i: vector to quantize Q15-3=>Q12 */ - Word16 *y, /* o: raw pulses (non-scaled short) Q0 */ - Word16 *xq, /* o: quantized vector Q15 */ - Word32 *L_xq, /* o: quantized vector Q31 */ - const Word16 pulses, /* i: number of allocated pulses */ - const Word16 dim, /* i: Length of vector */ - const Word16 neg_gain /* i: - Gain use - negative gain in Q15 0 ..1 */ -); - -void pvq_decode_fx( - Decoder_State_fx *st_fx, - Word16 *xq, /* o: decoded vector (Q15) */ - Word16 *y, /* o: decoded vector (non-scaled int) */ - const Word16 k_val, /* i: number of allocated pulses */ - const Word16 dim, /* i: Length of vector */ - const Word16 neg_gain /* i: Gain (negated to fit 1.0 in Q15 as -1.0) */ -); - -UWord32 intLimCDivPos_fx( - UWord32 NUM, - Word16 DEN -); - -Word32 intLimCDivSigned_fx( - Word32 NUM, - Word16 DEN -); - -Word16 shrtCDivSignedApprox( - const Word16 num, - const Word16 den -); -void de_interleave_spectrum_fx( - Word32 *coefs, /* i/o: input and output coefficients Q? */ - const Word16 length /* i : length of spectrum Q0 */ -); - -void interleave_spectrum_fx( - Word32 *coefs, /* i/o: input and output coefficients Q? */ - const Word16 length /* i : length of spectrum Q0 */ -); - -void recovernorm_fx( - Word16 *idxbuf, /* i : reordered quantization indices */ - Word16 *ynrm, /* o : recovered quantization indices */ - Word16 *normqlg2, /* o : recovered quantized norms */ - Word16 nb_sfm /* i : number of SFMs */ -); - -void map_quant_weight_fx( - const Word16 normqlg2[], /* i : quantized norms */ - Word16 wnorm[], /* o : weighted norm */ - const Word16 is_transient /* i : transient flag */ -); - -void fill_spectrum_fx( - Word16 *coeff, /* i/o: normalized MLT spectrum / nf spectrum Q12 */ - Word32 *L_coeff_out, /* i/o: Noisefilled MLT spectrum Q12 */ - const Word16 *R, /* i : number of pulses per band Q0 */ - const Word16 is_transient, /* i : transient flag Q0 */ - Word16 norm[], /* i : quantization indices for norms Q0 */ - const Word16 *hq_generic_fenv, /* i : HQ GENERIC envelope Q1 */ - const Word16 hq_generic_offset, /* i : HQ GENERIC offset Q0 */ - const Word16 nf_idx, /* i : noise fill index Q0 */ - const Word16 length, /* i : Length of spectrum (32 or 48 kHz) Q0 */ - const Word16 env_stab, /* i : Envelope stability measure [0..1] Q15 */ - Word16 *no_att_hangover, /* i/o: Frame counter for attenuation hangover Q0 */ - Word32 *L_energy_lt, /* i/o: Long-term energy measure for transient detection Q13 */ - Word16 *bwe_seed, /* i/o: random seed for generating BWE input Q0 */ - const Word16 hq_generic_exc_clas, /* i : BWE excitation class Q0 */ - const Word16 core_sfm, /* i : index of the end band for core Q0 */ - const Word16 HQ_mode, /* i : HQ mode Q0 */ - Word16 noise_level[], /* i : noise levels for harmonic modes Q15 */ - const Word32 L_core_brate, /* i : target bit-rate Q0 */ - Word16 prev_noise_level[], /* i/o: noise factor in previous frame Q15 */ - Word16 *prev_R, /* i/o: bit allocation info. in previous frame Q0 */ - Word32 *prev_coeff_out, /* i/o: decoded spectrum in previous frame Q12 */ - const Word16 *peak_idx, /* i : peak indices for hvq Q0 */ - const Word16 Npeaks, /* i : number of peaks in hvq Q0 */ - const Word16 *npulses, /* i : number of pulses per band Q0 */ - const Word16 prev_is_transient, /* i : previous transient flag Q0 */ - Word32 *prev_normq, /* i/o: previous norms Q14 */ - Word32 *prev_env, /* i/o: previous noise envelopes Q(prev_env_Q) */ - const Word16 prev_bfi, /* i : previous bad frame indicator Q0 */ - const Word16 *sfmsize, /* i : Length of bands Q0 */ - const Word16 *sfm_start, /* i : Start of bands Q0 */ - const Word16 *sfm_end, /* i : End of bands Q0 */ - Word16 *prev_L_swb_norm, /* i/o: HVQ/Harmonic mode normalization length Q0 */ - const Word16 prev_hq_mode, /* i : Previous HQ mode Q0 */ - const Word16 num_sfm, /* i : Total number of bands Q0 */ - Word16 *prev_env_Q, - const Word16 num_env_bands -); - -Word16 FEC_pos_dec_fx( - Decoder_State_fx *st_fx, /* i/o: decoder state structure */ - const Word16 coder_type, /* i : coder type */ - const Word16 last_good, /* i : last good classfication */ - Word16 *last_pulse_pos, /* o : last glotal pulse position in the lost ACB */ - Word16 *clas, /* o : decoded classification */ - Word32 *enr_q, /* o : decoded energy in Q0 */ - const Word32 core_brate /* i : decoded bitrate */ -); - -void pit16k_Q_dec_fx( - const Word16 pitch_index, /* i : pitch index */ - const Word16 nBits, /* i : # of Q bits */ - const Word16 limit_flag, /* i : restrained(0) or extended(1) limits */ - Word16 *T0, /* o : integer pitch lag */ - Word16 *T0_frac, /* o : pitch fraction */ - Word16 *T0_min, /* i/o: delta search min */ - Word16 *T0_max /* i/o: delta search max */ - ,Word16 *BER_detect /* o : BER detect flag */ -); - -Word16 frame_ener_fx( - const Word16 L_frame, /* i : length of the frame */ - const Word16 clas, /* i : frame classification */ - const Word16 *synth, /* i : synthesized speech at Fs = 12k8 Hz Q_new */ - const Word16 pitch, /* i : pitch period Q0 */ - Word32 *enr_q, /* o : pitch-synchronous or half_frame energy Q0 */ - const Word16 offset, /* i : speech pointer offset (0 or L_FRAME) */ - const Word16 Q_new, /* i : Scaling factor */ - Word16 shift, /* i : Shift need to obtain 12 bits vectors */ - const Word16 enc /* i : Encoder/decoder */ -); - -Word16 frame_energy_fx( /* o : Frame erergy in Q8 */ - Word16 L_frame, - const Word16 *pitch, /* i : pitch values for each subframe Q6 */ - const Word16 *speech, /* i : pointer to speech signal for E computation Q_syn*/ - const Word16 lp_speech, /* i : long term active speech energy average Q8 */ - Word16 *frame_ener, /* o : pitch-synchronous energy at frame end Q8 */ - const Word16 Q_syn /* i : Synthesis scaling */ -); - -void int_lsp_fx( - const Word16 L_frame, /* i : length of the frame */ - const Word16 lsp_old[], /* i : LSPs from past frame */ - const Word16 lsp_new[], /* i : LSPs from present frame */ - Word16 *Aq, /* o : LP coefficients in both subframes */ - const Word16 m, /* i : order of LP filter */ - const Word16 *int_coeffs, /* i : interpolation coefficients */ - const Word16 Opt_AMR_WB /* i : flag indicating AMR-WB IO mode */ -); - -void reorder_isf_fx( - Word16 *isf, /* i/o: ISFs in the frequency domain (0..0.5) */ - const Word16 min_dist, /* i : minimum required distance */ - const Word16 n, /* i : LPC order */ - const Word16 fs /* i : sampling frequency */ -); - -void reorder_lsf_fx( - Word16 *lsf, /* i/o: LSFs in the frequency domain (0..0.5) Q(x2.56)*/ - const Word16 min_dist, /* i : minimum required distance x2.56*/ - const Word16 n, /* i : LPC order */ - const Word32 fs /* i : sampling frequency */ -); - -Word16 FEC_synchro_exc_fx( /* o : do_WI flag */ - const Word16 L_frame, /* i : length of the frame */ - Word16 *exc, /* i/o: exc vector to modify */ - const Word16 desire_puls_pos, /* i : Pulse position send by the encoder */ - const Word16 true_puls_pos, /* i : Present pulse location */ - const Word16 Old_pitch /* i : Pitch use to create temporary adaptive codebook */ -); - -Word16 findpulse_fx( /* o : pulse position */ - const Word16 L_frame, /* i : length of the frame */ - const Word16 res[], /* i : Residual signal <12 bits */ - const Word16 T0, /* i : Pitch estimation Q0 */ - const Word16 enc, /* i : enc = 1 -> encoder side; enc = 0 -> decoder side */ - Word16 *sign /* i/o: sign of the maximum */ -); - -void FEC_exc_estim_fx( - Decoder_State_fx *st_fx, /* i/o: Decoder static memory */ - const Word16 L_frame, /* i : length of the frame */ - Word16 *exc, /* o : pointer to excitation buffer (with past) */ - Word16 *exc2, /* o : total excitation (for synthesis) */ - Word16 dct_exc_tmp[], /* o : GSC excitation in DCT domain */ - Word16 *pitch_buf, /* o : Floating pitch for each subframe */ - Word16 *voice_factors, /* o : voicing factors */ - Word16 *tmp_tc, /* o : FEC pitch Q6 */ - Word16 *bwe_exc, /* o : excitation for SWB TBE */ - Word16 *lsf_new, /* i : ISFs at the end of the frame */ - Word16 *Q_exc, - Word16 *tmp_noise /* o : long-term noise energy Q0 */ -); - -void FEC_lsf2lsp_interp( - Decoder_State_fx *st, /* i/o: Decoder static memory */ - const Word16 L_frame, /* i : length of the frame */ - Word16 *Aq, /* o : calculated A(z) for 4 subframes */ - Word16 *lsf, /* o : estimated LSF vector */ - Word16 *lsp /* o : estimated LSP vector */ -); -void FEC_lsf_estim_enc_fx( - Encoder_State_fx *st_fx, /* i : Encoder static memory */ - const Word16 L_frame, /* i : length of the frame */ - Word16 *lsf /* o : estimated LSF vector */ -); - -void FEC_clas_estim_fx( - Decoder_State_fx *st_fx, /* i/o: decoder state handle */ - const Word16 Opt_AMR_WB, /* i : flag indicating AMR-WB IO mode */ /*A*/ - const Word16 L_frame, /* i : length of the frame */ - Word16 *clas, /* i/o: frame classification */ - const Word16 coder_type, /* i : coder type */ - const Word16 *pitch, /* i : pitch values for each subframe (Q6) */ - Word16 *syn, /* i : synthesis buffer */ - Word16 *lp_speech, /* i/o: long term active speech energy average Q8 */ - Word16 *decision_hyst, /* i/o: hysteresis of the music/speech decision */ /*A*/ - Word16 *UV_cnt, /* i/o: number of consecutives frames classified as UV */ /*A*/ - Word16 *LT_UV_cnt, /* i/o: long term consecutives frames classified as UV */ /*A*/ - Word16 *Last_ener, /* i/o: last_energy frame */ /*A*/ - Word16 *locattack, /* i/o: detection of attack (mainly to localized speech burst) */ /*A*/ - Word16 *lt_diff_etot, /* i/o: long-term total energy variation */ /*A*/ - Word16 *amr_io_class, /* i/o: classification for AMR-WB IO mode */ /*A*/ - const Word32 bitrate, /* i : Decoded bitrate */ /*A*/ - Word16 Q_syn, /* i : Synthesis scaling */ - Word16 *class_para, /* o : classification para. fmerit1 */ /*A*/ - Word16 *mem_syn_clas_estim, /* i/o: memory of the synthesis signal for frame class estimation */ - Word16 *Q_mem_syn, /*i/o : exponent for memory of synthesis signal for frame class estimation */ /*B*/ - Word16 LTP_Gain, /* i : LTP gain is 0..0.6 or negative Q15*/ /*B*/ - Word16 mode, /* i : signal classifier mode *//*B*/ - Word16 bfi, /* i : bad frame indicator *//*B*/ - Word32 last_core_brate /* i : bitrate of previous frame */ -); - -void non_linearity_fx( - const Word16 input[], /* i : input signal Q_inp */ - Word32 output[], /* o : output signal 2*Q_inp */ - const Word16 length, /* i : input length */ - Word32 *prev_scale, /* i/o: memory Q30 */ - Word16 Q_inp, - Word16 coder_type, /* i : Coder Type */ - Word16 *voice_factors, /* i : Voice Factors */ - const Word16 L_frame /* i : ACELP frame length */ -); - -void stat_noise_uv_dec_fx( - Decoder_State_fx *st_fx, /* i/o: Decoder static memory */ - const Word16 coder_type, /* i : coding type */ - Word16 *lsp_new, /* i : end-frame LSP vector */ - Word16 *lsp_mid, /* i : mid-frame LSP vector */ - Word16 *Aq, /* o : A(z) quantized for the 4 subframes */ - Word16 *exc2 /* i/o: excitation buffer */ -); - -void stat_noise_uv_mod_fx( - const Word16 coder_type, /* i : Coder type */ - Word16 noisiness, /* i : noisiness parameter */ - const Word16 *lsp_old, /* i : old LSP vector at 4th sfr */ - const Word16 *lsp_new, /* i : LSP vector at 4th sfr */ - const Word16 *lsp_mid, /* i : LSP vector at 2nd sfr */ - Word16 *Aq, /* o : A(z) quantized for the 4 subframes */ - Word16 *exc2, /* i/o: excitation buffer */ - Word16 Q_exc, /* i : Q of exc2 excitation buffer [11..-1] expected */ - const Word16 bfi , /* i : Bad frame indicator */ - Word32 *ge_sm, /* i/o: smoothed excitation gain */ - Word16 *uv_count, /* i/o: unvoiced counter */ - Word16 *act_count, /* i/o: activation counter */ - Word16 lspold_s[], /* i/o: old LSP */ - Word16 *noimix_seed, /* i/o: mixture seed */ - Word16 *st_min_alpha, /* i/o: minimum alpha */ - Word16 *exc_pe, /* i/o: scale Q_stat_noise */ - const Word32 bitrate, /* i : core bitrate */ - const Word16 bwidth_fx, /* i : input bandwidth */ - Word16 *Q_stat_noise, /* i/o: noise scaling */ - Word16 *Q_stat_noise_ge /* i/o: noise scaling */ -); - -/* Just call preemph_copy_fx(), it does the same thing and that saves PROM */ -#define preemph_fx(signal,mu,L,mem) preemph_copy_fx((signal),(signal),(mu),(L),(mem)) - -void preemph_copy_fx( - const Word16 x[], /* i : input signal Qx */ - Word16 y[], /* o : output signal Qx */ - const Word16 mu, /* i : preemphasis coefficient Q15 */ - const Word16 lg, /* i : vector size Q0 */ - Word16 *mem /* i/o: memory (x[-1]) Qx */ -); - -Word16 vquant_fx( /* o: index of the winning codevector */ - Word16 x[], /* i: vector to quantize Q13 */ - const Word16 x_mean[], /* i: vector mean to subtract (0 if none)Q13*/ - Word16 xq[], /* o: quantized vector Q13 */ - const Word16 cb[], /* i: codebook Q13 */ - const Word16 dim, /* i: dimension of codebook vectors */ - const Word16 cbsize /* i: codebook size */ -); - -Word16 w_vquant_fx( - Word16 x[], /* i: vector to quantize in Q10 */ - Word16 Qx, - const Word16 weights[], /* i: error weights in Q0 */ - Word16 xq[], /* o: quantized vector in Q15 */ - const Word16 cb[], /* i: codebook in Q15 */ - const Word16 cbsize, /* i: codebook size */ - const Word16 rev_vect /* i: reverse codebook vectors */ -); - -void Vr_subt( - const Word16 x1[], /* i : Input vector 1 */ - const Word16 x2[], /* i : Input vector 2 */ - Word16 y[], /* o : Output vector that contains vector 1 - vector 2 */ - Word16 N /* i : Vector lenght */ -); - -Word16 gsc_gainQ_fx( - Encoder_State_fx *st_fx, /* i/o: encoder state structure */ - const Word16 y_gain4[], /* i : Energy per band Q13 */ - Word16 y_gainQ[], /* o : quantized energy per band Q13 */ - const Word32 core_brate, /* i : Core rate */ - const Word16 coder_type, /* i : coding type */ - const Word16 bwidth /* i : input signal bandwidth */ -); - -Word16 emaximum_fx( /* o : return index with max energy value in vector Q0 */ - const Word16 Qvec, /* i : Q of input vector Q0 */ - const Word16 *vec, /* i : input vector Qx */ - const Word16 lvec, /* i : length of input vector Q0 */ - Word32 *ener_max /* o : maximum energy value Q0 */ -); - -void set16_fx( - Word16 y[], /* i/o: Vector to set */ - const Word16 a, /* i : Value to set the vector to */ - const Word16 N /* i : Lenght of the vector */ -); - -void set32_fx( - Word32 y[], /* i/o: Vector to set */ - const Word32 a, /* i : Value to set the vector to */ - const Word16 N /* i : Lenght of the vector */ -); - -void Copy( - const Word16 x[], /* i : input vector */ - Word16 y[], /* o : output vector */ - const Word16 L /* i : vector length */ -); - -void Copy32( - const Word32 x[], /* i : input vector */ - Word32 y[], /* o : output vector */ - const Word16 L /* i : vector length */ -); - -void Scale_sig32( - Word32 x[], /* i/o: signal to scale Qx */ - const Word16 lg, /* i : size of x[] Q0 */ - const Word16 exp0 /* i : exponent: x = round(x << exp) Qx ?exp */ -); - -void Copy_Scale_sig( - const Word16 x[], /* i : signal to scale input Qx */ - Word16 y[], /* o : scaled signal output Qx */ - const Word16 lg, /* i : size of x[] Q0 */ - const Word16 exp0 /* i : exponent: x = round(x << exp) Qx ?exp */ -); - -void Copy_Scale_sig_16_32( - const Word16 x[], /* i : signal to scale input Qx */ - Word32 y[], /* o : scaled signal output Qx */ - const Word16 lg, /* i : size of x[] Q0 */ - const Word16 exp0 /* i : exponent: x = round(x << exp) Qx ?exp */ -); - -void Copy_Scale_sig_32_16( - const Word32 x[], /* i : signal to scale input Qx */ - Word16 y[], /* o : scaled signal output Qx */ - const Word16 lg, /* i : size of x[] Q0 */ - const Word16 exp0 /* i : exponent: x = round(x << exp) Qx ?exp */ -); - -void init_lvq_fx( - Word32 offset_scale1[][MAX_NO_SCALES+1], - Word32 offset_scale2[][MAX_NO_SCALES+1], - Word32 offset_scale1_p[][MAX_NO_SCALES+1], - Word32 offset_scale2_p[][MAX_NO_SCALES+1], - Word16 no_scales[][2], - Word16 no_scales_p[][2] -); - -void hf_synth_reset_fx( - Word16 *seed2, /* i/o: random seed for HF noise gen */ - Word16 mem_hf[], /* o : HF band-pass filter memory */ - Word16 mem_syn_hf[], /* o : HF synthesis memory */ - Word16 mem_hp400[], /* o : memory of hp 400 Hz filter */ - Word16 mem_hp_interp[], /* o : interpol. memory */ - Word16 delay_syn_hf[] /* o : HF synthesis memory */ -); - -void hf_synth_init_fx( - Word16 mem_hp400[], /* o : 400 Hz high pass filter memory initialization */ - Word16 mem_hf[] /* o : band pass 6kHz to 7kHz FIR filter initialization */ -); - -Word16 Random( /* o : output random value */ - Word16 *seed /* i/o: random seed */ -); - -Word16 own_random2_fx( /* o : output random value */ - Word16 seed /* i : random seed */ -); - -void Random_Fill( - Word16 *seed, /* i/o: random seed */ - Word16 n, /* i : number of values */ - Word16 *y, /* o : output values */ - Word16 scaling /* i : scaling of values */ -); - -void iDiv_and_mod_32( - const Word32 Numer, /* i : 32 bits numerator */ - const Word16 Denom, /* i : 16 bits denominator */ - Word32 * Int_quotient, /* o : integer result of the division (int)(num/den) */ - Word32 * Int_mod, /* o : modulo result of the division num-((int)(num/den)*den)*/ - const Word16 rshift /* i : 0 if no right shift / 1 if the denom is right shifted by 1*/ -); - -void lsf2lsp_fx( - const Word16 lsf[], /* i : lsf[m] normalized (range: 0.0<=val<=0.5) x2.56 */ - Word16 lsp[], /* o : lsp[m] (range: -1<=val<1) Q15 */ - const Word16 m, /* i : LPC order Q0 */ - Word32 int_fs -); - -void bass_psfilter_init_fx( - Word16 old_syn[], /* o : Old synthesis buffer 1 */ - Word16 *mem_deemph_err, /* o : Error deemphasis memory */ - Word16 *lp_ener /* o : long_term error signal energy */ -); - -void decod_gen_voic_fx( - Decoder_State_fx *st_fx, /* i/o: decoder static memory */ - const Word16 L_frame_fx, /* i : length of the frame */ - const Word16 sharpFlag_fx, /* i : formant sharpening flag */ - const Word16 *Aq_fx, /* i : LP filter coefficient */ - const Word16 coder_type_fx, /* i : coding type */ - const Word16 Es_pred_fx, /* i : predicted scaled innov. energy */ - const Word16 do_WI_fx, /* i : do interpolation after a FER */ - Word16 *pitch_buf_fx, /* o : floating pitch values for each subframe */ - Word16 *voice_factors_fx, /* o : voicing factors */ - Word16 *exc_fx, /* i/o: adapt. excitation exc */ - Word16 *exc2_fx, /* i/o: adapt. excitation/total exc */ - Word16 *bwe_exc_fx, /* o : excitation for SWB TBE */ - Word16 *unbits, /* number of unused bits */ - Word16* gain_buf /*Q14*/ -); - -Word16 tc_classif_fx( - Decoder_State_fx *st_fx, /* i/o: decoder state structure */ - const Word16 L_frame /* i : length of the frame */ -); - -void transition_dec_fx( - Decoder_State_fx *st_fx, /* i/o: decoder state structure */ - const Word32 core_brate, /* i : core bitrate */ - const Word16 Opt_AMR_WB, /* i : flag indicating AMR-WB IO mode */ - const Word16 L_frame, /* i : length of the frame */ - const Word16 i_subfr, /* i : subframe index */ - const Word16 coder_type, /* i : coder type */ - const Word16 tc_subfr, /* i : TC subframe index */ - Word16 *Jopt_flag, /* i : joint optimization flag */ - Word16 *exc, /* o : excitation signal */ - Word16 *T0, /* o : close loop integer pitch */ - Word16 *T0_frac, /* o : close loop fractional part of the pitch */ - Word16 *T0_min, /* i/o: delta search min for sf 2 & 4 */ - Word16 *T0_max, /* i/o: delta search max for sf 2 & 4 */ - Word16 **pt_pitch, /* o : floating pitch values */ - Word16 *position, /* i/o: first glottal impulse position in frame */ - Word16 *bwe_exc, /* o : excitation for SWB TBE */ - Word16 *Q_exc /*i/o : scaling of excitation */ -); - -void decod_tran_fx( - Decoder_State_fx *st_fx, /* i/o: decoder static memory */ - const Word16 L_frame_fx, /* i : length of the frame */ - const Word16 tc_subfr_fx, /* i : TC subframe index */ - const Word16 *Aq_fx, /* i : LP filter coefficient */ - const Word16 coder_type_fx, /* i : coding type */ - const Word16 Es_pred_fx, /* i : predicted scaled innov. energy */ - Word16 *pitch_buf_fx, /* o : floating pitch values for each subframe */ - Word16 *voice_factors_fx, /* o : voicing factors */ - Word16 *exc_fx, /* i/o: adapt. excitation exc */ - Word16 *exc2_fx, /* i/o: adapt. excitation/total exc */ - Word16 *bwe_exc_fx, /* i/o: excitation for SWB TBE */ - Word16 *unbits, /* i/o: number of unused bits */ - const Word16 sharpFlag, /* i : formant sharpening flag */ - Word16 *gain_buf /*Q14*/ -); - -void interp_code_4over2_fx( - const Word16 inp_code_fx[], /* i : input vector Qx */ - Word16 interp_code_fx[], /* o : output vector Qx */ - const Word16 inp_length /* i : length of input vector */ -); - -void pred_lt4_tc_fx( - Word16 exc[], /* i/o: excitation buffer */ - const Word16 T0, /* i : integer pitch lag */ - Word16 frac, /* i: fraction of lag */ - const Word16 *win, /* i : interpolation window */ - const Word16 imp_pos, /* i : glottal impulse position */ - const Word16 i_subfr /* i : subframe index */ -); - -void gaus_dec_fx( - Decoder_State_fx *st_fx, /* i/o: decoder static memory */ - const Word32 core_brate, /* i */ /*1 : core bitrate */ - const Word16 i_subfr, /* i */ /*2 : subframe index */ - Word16 *code, /* o */ /*3 : unvoiced excitation Q12 */ - Word32 *L_norm_gain_code, /* o */ /*4 : gain of normalized gaussian excitation Q16 */ - Word16 *lp_gainp, /* i/o */ /*5 : lp filtered pitch gain(FER) Q14 */ - Word16 *lp_gainc, /* i/o */ /*6 : lp filtered code gain (FER) Q3 */ - Word16 *inv_gain_inov, /* o */ /*7 : unscaled innovation gain Q12 */ - Word16 *tilt_code, /* o */ /*8 : synthesis excitation spectrum tilt Q15 */ - Word16 *voice_fac, /* o */ /*9 : estimated voicing factor Q15 */ - Word16 *gain_pit, /* o */ /*10 : pitch gain Q14 */ - Word16 *pt_pitch_1, /* o */ /*11 : floating pitch buffer Q6 */ - Word16 *exc, /* o */ /*12 : excitation signal frame */ - Word32 *L_gain_code, /* o */ /*13 : gain of the gaussian excitation Q16 */ - Word16 *exc2, /* o */ /*14 : Scaled excitation signal frame */ - Word16 *bwe_exc_fx, - Word16 *sQ_exc, /* i/o */ /*15 : Excitation scaling factor (Decoder state) */ - Word16 *sQsubfr /* i/o */ /*16 : Past excitation scaling factors (Decoder State) */ -); - -void decod_unvoiced_fx( - Decoder_State_fx *st_fx, /* i/o: decoder static memory */ - const Word16 *Aq_fx, /* Q12 i : LP filter coefficient */ - const Word16 coder_type_fx, /* Q0 i : coding type */ - Word16 *tmp_noise_fx, /* Q5 o : long term temporary noise energy */ - Word16 *pitch_buf_fx, /* Q6 o : floating pitch values for each subframe */ - Word16 *voice_factors_fx, /* Q15 o : voicing factors */ - Word16 *exc_fx, /* Q_X o : adapt. excitation exc */ - Word16 *exc2_fx, /* Q_X o : adapt. excitation/total exc */ - Word16 *bwe_exc_fx, /* Q_X i/o: excitation for SWB TBE */ - Word16 *gain_buf -); - -Word32 gain_dec_gaus_fx( /* o : quantized codebook gain Q16 */ - Word16 index, /* i : quantization index */ - const Word16 bits, /* i : number of bits to quantize */ - const Word16 lowBound, /* i : lower bound of quantizer (dB) */ - const Word16 topBound, /* i : upper bound of quantizer (dB) */ - const Word16 inv_gain_inov, /* o : unscaled innovation gain Q12 */ - Word32 *L_norm_gain_code /* o : gain of normalized gaussian excitation Q16 */ -); - -void AVQ_demuxdec_fx( - Decoder_State_fx *st_fx, /* i/o: decoder state structure */ - Word16 xriq[], /* o: decoded subvectors [0..8*Nsv-1] */ - Word16 *nb_bits, /* i/o: number of allocated bits */ - const Word16 Nsv, /* i: number of subvectors */ - Word16 nq_out[] /* i/o: AVQ nq index */ -); - -void re8_decode_base_index_fx(Word16 n, UWord16 I, Word16 *x); - -void re8_k2y_fx( - const Word16 *k, /* i : Voronoi index k[0..7] */ - const Word16 m, /* i : Voronoi modulo (m = 2^r = 1<=2) */ - Word16 *y /* o : 8-dimensional point y[0..7] in RE8 */ -); - -void re8_vor_fx( - const Word16 y[], /* i : point in RE8 (8-dimensional integer vector) */ - Word16 *n, /* o : codebook number n=0,2,3,4,... (scalar integer) */ - Word16 k[], /* o : Voronoi index (integer vector of dimension 8) used only if n>4*/ - Word16 c[], /* o : codevector in Q0, Q2, Q3, or Q4 if n<=4, y=c */ - Word16 *ka /* o : identifier of absolute leader (to index c) */ -); - -void re8_cod_fx( - Word16 x[], /* i : point in RE8 (8-dimensional integer vector) */ - Word16 *n, /* i : codebook number (*n is an integer defined in {0,2,3,4,..,n_max}) */ - UWord16 *I, /* o : index of c (pointer to unsigned 16-bit word) */ - Word16 k[] /* o : index of v (8-dimensional vector of binary indices) = Voronoi index */ -); - -void re8_PPV_fx( - const Word32 x[], /* i : point in R^8Q15 */ - Word16 y[] /* o : point in RE8 (8-dimensional integer vector) */ -); - -void re8_dec_fx( - Word16 n, /* i : codebook number (*n is an integer defined in {0,2,3,4,..,n_max}) */ - const UWord16 I, /* i : index of c (pointer to unsigned 16-bit word) */ - const Word16 k[], /* i : index of v (8-dimensional vector of binary indices) = Voronoi index */ - Word16 y[] /* o : point in RE8 (8-dimensional integer vector) */ -); - -void gain_dec_SQ_fx( - Decoder_State_fx *st_fx, /* i/o: decoder state structure */ - const Word32 core_brate, /* i : core bitrate */ - const Word16 coder_type, /* i : coding type */ - const Word16 i_subfr, /* i : subframe number */ - const Word16 tc_subfr, /* i : TC subframe index */ - const Word16 *code, /* i : algebraic code excitation Q12*/ - const Word16 Es_pred, /* i : predicted scaled innov. energy Q8 */ - Word16 *gain_pit, /* o : Quantized pitch gain Q14*/ - Word32 *gain_code, /* o : Quantized codeebook gain Q16*/ - Word16 *gain_inov, /* o : unscaled innovation gain Q12*/ - Word32 *norm_gain_code /* o : norm. gain of the codebook excitation Q16*/ -); - -void gain_dec_amr_wb_fx( - Decoder_State_fx *st_fx, /* i/o: decoder state structure */ - const Word32 core_brate, /* i : core bitrate */ - Word16 *gain_pit, /* o : Quantized pitch gain */ - Word32 *gain_code, /* o : Quantized codeebook gain */ - Word16 *past_qua_en, /* i/o: gain quantization memory (4 words) */ - Word16 *gain_inov, /* o : unscaled innovation gain */ - const Word16 *code, /* i : algebraic code excitation */ - Word32 *norm_gain_code /* o : norm. gain of the codebook excitation */ -); - -void isf_dec_amr_wb_fx( - Decoder_State_fx *st, /* i/o: State structure */ - Word16 *Aq, /* o : quantized A(z) for 4 subframes */ - Word16 *isf_new, /* o : de-quantized ISF vector */ - Word16 *isp_new /* o : de-quantized ISP vector */ -); - -void syn_output_fx( - const Word16 codec_mode, /* i : MODE1 or MODE2 */ - Word16 *synth, /* i/o: float synthesis signal */ - const Word16 output_frame, /* i : output frame length */ - Word16 *synth_out, /* o : integer 16 bits synthesis signal */ - const Word16 Q_syn2 /* i : Synthesis scaling factor */ -); - -void amr_wb_dec_fx( - Word16 output_sp[], /* o : synthesis output */ - Decoder_State_fx *st_fx /* o : Decoder static variables structure */ -); - -void decod_amr_wb_fx( - Decoder_State_fx *st_fx, /* i/o: decoder static memory */ - const Word16 *Aq_fx, /* i : LP filter coefficients */ - Word16 *pitch_buf_fx, /* o : floating pitch values for each subframe */ - Word16 *exc_fx, /* i/o: adapt. excitation exc */ - Word16 *exc2_fx, /* i/o: adapt. excitation/total exc */ - Word16 hf_gain_fx[NB_SUBFR], /* o : decoded HF gain */ - Word16 *voice_factors_fx, /* o : voicing factors */ - Word16 *gain_buf /*Q14*/ -); - -void disf_2s_46b_fx( - Word16 *indice, /* i : quantized indices (use indice[0] = -1 in the decoder) */ - Word16 *isf_q, /* o : quantized ISFs in the cosine domain */ - Word16 *mem_AR, /* o : quantizer memory for AR model */ - Word16 *mem_MA, /* i/o: quantizer memory for MA model */ - const Word16 enc_dec /* i : encoder (0), decoder (1) G722.2 FER */ -); - -void disf_2s_36b_fx( - Word16 *indice, /* i : quantized indices (use indice[0] = -1 in the decoder) */ - Word16 *isf_q, /* o : quantized ISFs in the cosine domain */ - Word16 *mem_AR, /* i/o: quantizer memory for AR model */ - Word16 *mem_MA, /* i/o: quantizer memory for MA model */ - const Word16 enc_dec /* i : encoder (0), decoder (1) G722.2 FER */ -); - -void transf_cdbk_dec_fx( - Decoder_State_fx *st_fx, /* i/o: decoder state structure */ - const Word32 core_brate, /* i : core bitrate */ - const Word16 coder_type, /* i : coding type */ - const Word16 harm_flag_acelp,/* i : harmonic flag for higher rates ACELP */ - const Word16 i_subfr, /* i : subframe index */ - const Word16 tc_subfr, /* i : TC subframe index */ - const Word16 Es_pred, /* i : predicited scaled innovation energy (Q8) */ - const Word32 gain_code, /* i : innovative excitation gain (Q16) */ - Word16 *mem_preemp, /* i/o: dequantizer preemhasis memory */ - Word16 *gain_preQ, /* o : prequantizer excitation gain (Q2) */ - Word32 *norm_gain_preQ,/* o : normalized prequantizer excitation gain (Q16) */ - Word16 code_preQ[], /* o : prequantizer excitation (Q8) */ - Word16 *unbits /* o : number of AVQ unused bits */ -); - -void gain_enc_SQ_fx( - Encoder_State_fx *st_fx, /* i/o: encoder state structure */ - const Word32 core_brate, /* i : core bitrate */ - const Word16 coder_type, /* i : coding type */ - const Word16 i_subfr, /* i : subframe index */ - const Word16 tc_subfr, /* i : TC subframe index */ - const Word16 *xn, /* i : target vector Q_xn */ - const Word16 *yy1, /* i : zero-memory filtered adaptive excitation Q_xn */ - const Word16 *y2, /* i : zero-memory filtered algebraic codebook excitation Q9 */ - const Word16 *code, /* i : algebraic excitation Q9 */ - const Word16 Es_pred, /* i : predicted scaled innovation energy Q8 */ - Word16 *gain_pit, /* o : quantized pitch gain Q14 */ - Word32 *gain_code, /* o : quantized codebook gain Q16 */ - Word16 *gain_inov, /* o : gain of the innovation (used for normalization) Q12 */ - Word32 *norm_gain_code, /* o : norm. gain of the codebook excitation Q16 */ - Word16 *g_corr, /* i/o: correlations , -2,, -2 and 2 */ - const Word16 clip_gain, /* i : gain pitch clipping flag (1 = clipping) */ - const Word16 Q_xn /* i : xn and y1 scaling */ -); - -void AVQ_cod_fx( /* o: comfort noise gain factor */ - const Word16 xri[], /* i: vector to quantize */ - Word16 xriq[], /* o: quantized normalized vector (assuming the bit budget is enough) */ - const Word16 NB_BITS, /* i: number of allocated bits */ - const Word16 Nsv, /* i: number of subvectors (lg=Nsv*8) */ - const Word16 Q_in /* i: Scaling input */ -); - -void AVQ_encmux_fx( - Encoder_State_fx *st_fx, /* i/o: encoder state structure */ - const Word16 extl, /* i : extension layer */ - Word16 xriq[], /* i/o: rounded subvectors [0..8*Nsv-1] followed - by rounded bit allocations [8*Nsv..8*Nsv+Nsv-1] */ - Word16 *nb_bits, /* i/o: number of allocated bits */ - const Word16 Nsv, /* i: number of subvectors */ - Word16 nq_out[] /* o : AVQ nq index */ -); - -Word32 Dot_product( /* o : Sum */ - const Word16 x[], /* i : 12bits: x vector */ - const Word16 y[], /* i : 12bits: y vector */ - const Word16 lg /* i : vector length */ -); - -Word16 usquant_fx( /* o: index of the winning codeword */ - const Word16 x, /* i: scalar value to quantize Qx*/ - Word16 *xq, /* o: quantized value Qx*/ - const Word16 qlow, /* i: lowest codebook entry (index 0) Qx*/ - const Word16 delta, /* i: quantization step Qx-1*/ - const Word16 cbsize /* i: codebook size */ -); - -Word16 gain_quant_fx( /* o: quantization index */ - Word32 *gain, /* i/o: quantized gain */ - Word16 *gain16, - const Word16 c_min, /* i: log10 of lower limit in Q14 */ - const Word16 c_max, /* i: log10 of upper limit in Q13 */ - const Word16 bits, /* i: number of bits to quantize */ - Word16 *expg -); - -void gain_enc_mless_fx( - Encoder_State_fx *st_fx, /* i/o: encoder state structure */ - const Word32 core_brate, /* i : core bitrate */ - const Word16 L_frame, /* i : length of the frame */ - const Word16 coder_type, /* i : coding type */ - const Word16 i_subfr, /* i : subframe index */ - const Word16 tc_subfr, /* i : TC subframe index */ - const Word16 *xn, /* i : target vector */ - const Word16 *y1, /* i : zero-memory filtered adaptive excitation */ - const Word16 Q_xn, /* i : xn and y1 scaling */ - const Word16 *y2, /* i : zero-memory filtered algebraic codebook excitation */ - const Word16 *code, /* i : algebraic excitation */ - const Word16 Es_pred, /* i : predicted scaled innovation energy */ - Word16 *gain_pit, /* o : quantized pitch gain */ - Word32 *gain_code, /* o : quantized codebook gain */ - Word16 *gain_inov, /* o : gain of the innovation (used for normalization) */ - Word32 *norm_gain_code, /* o : norm. gain of the codebook excitation */ - Word16 *g_corr, /* i/o: correlations , -2,, -2 and 2 */ - const Word16 clip_gain /* i : gain pitch clipping flag (1 = clipping) */ -); - -Word16 gain_enc_gaus_fx( /* o : Return index of quantization */ - Word32 *gain, /* i/o: Code gain to quantize */ - const Word16 bits, /* i : number of bits to quantize */ - const Word16 lowBound, /* i : lower bound of quantizer (dB) Q8 */ - const Word16 stepSize, /* i : Step size choice Q14 */ - const Word16 inv_stepSize /* i : Step size choice Q15 */ -); - -void gain_enc_tc_fx( - Encoder_State_fx *st_fx, /* i/o: encoder state structure */ - const Word32 core_brate, /* i : core bitrate */ - const Word16 L_frame, /* i : length of the frame */ - const Word16 i_subfr, /* i : subframe index */ - const Word16 tc_subfr, /* i : TC subframe index */ - const Word16 xn_fx[], /* i : target vector */ - const Word16 y2_fx[], /* i : zero-memory filtered algebraic codebook excitation */ - const Word16 code_fx[], /* i : algebraic excitation */ - const Word16 Es_pred_fx, /* i : predicted scaled innovation energy */ - Word16 *gain_pit_fx, /* o : Pitch gain / Quantized pitch gain */ - Word32 *gain_code_fx, /* o : quantized codebook gain */ - Word16 *gain_inov_fx, /* o : innovation gain */ - Word32 *norm_gain_code_fx, /* o : norm. gain of the codebook excitation */ - const Word16 Q_xn /* i : xn and y1 scaling Q0 */ -); - -Word16 gaus_encode_fx( - Encoder_State_fx *st_fx, /* i/o: encoder state structure */ - const Word16 i_subfr, /* i : subframe index */ - const Word16 *h1, /* i : weighted filter input response */ - const Word16 *xn, /* i : target vector */ - Word16 *exc, /* o : pointer to excitation signal frame */ - Word16 *mem_w0, /* o : weighting filter denominator memory */ - Word16 *clip_gain, /* o : memory of gain of pitch clipping algorithm */ - Word16 *tilt_code, /* o : synthesis excitation spectrum tilt */ - Word16 *code, /* o : algebraic excitation Q9 */ - Word32 *gain_code, /* o : Code gain. Q16 */ - Word16 *y2, /* o : zero-memory filtered adaptive excitation Q9 */ - Word16 *gain_inov, /* o : innovation gain Q12 */ - Word16 *voice_fac, /* o : voicing factor Q15 */ - Word16 *gain_pit, /* o : adaptive excitation gain Q14 */ - const Word16 Q_new, /* i : scaling factor */ - const Word16 shift, /* i : scaling factor */ - Word32 *norm_gain_code, /* o : normalized innovative cb. gain Q16 */ - const Word32 core_brate /* i : core bitrate */ -); - -void encod_unvoiced_fx( - Encoder_State_fx *st_fx, /* i/o: state structure */ - LPD_state *mem, /* i/o: acelp memories */ - const Word16 *speech_fx, /* i : Input speech */ - const Word16 Aw_fx[], /* i : weighted A(z) unquantized for subframes */ - const Word16 *Aq_fx, /* i : 12k8 Lp coefficient */ - const Word16 vad_flag_fx, - const Word16 *res_fx, /* i : residual signal */ - Word16 *syn_fx, /* o : core synthesis */ - Word16 *tmp_noise_fx, /* o : long-term noise energy */ - Word16 *exc_fx, /* i/o: current non-enhanced excitation */ - Word16 *pitch_buf_fx, /* o : floating pitch values for each subframe */ - Word16 *voice_factors_fx, /* o : voicing factors */ - Word16 *bwe_exc_fx, /* i/o: excitation for SWB TBE */ - const Word16 Q_new, - const Word16 shift -); - -void transf_cdbk_enc_fx( - Encoder_State_fx *st_fx, /* i/o: encoder state structure */ - const Word32 core_brate, /* i : core bitrate */ - const Word16 extl, /* i : extension layer */ - const Word16 coder_type, /* i : coding type */ - const Word16 harm_flag_acelp, /* i : harmonic flag for higher rates ACELP */ - const Word16 i_subfr, /* i : subframe index */ - const Word16 tc_subfr, /* i : TC subframe index */ - Word16 cn[], /* i/o: target vector in residual domain */ - Word16 exc[], /* i/o: pointer to excitation signal frame */ - const Word16 *p_Aq, /* i : 12k8 Lp coefficient */ - const Word16 Ap[], /* i : weighted LP filter coefficients */ - const Word16 h1[], /* i : weighted filter input response */ - Word16 xn[], /* i/o: target vector */ - Word16 xn2[], /* i/o: target vector for innovation search */ - Word16 y1[], /* i/o: zero-memory filtered adaptive excitation */ - const Word16 y2[], /* i : zero-memory filtered innovative excitation */ - const Word16 Es_pred, /* i : predicited scaled innovation energy */ - Word16 *gain_pit, /* i/o: adaptive excitation gain */ - const Word32 gain_code, /* i : innovative excitation gain */ - Word16 g_corr[], /* o : ACELP correlation values */ - const Word16 clip_gain, /* i : adaptive gain clipping flag */ - Word16 *mem_deemp, /* i/o: prequantizer deemhasis memory */ - Word16 *mem_preemp, /* i/o: prequantizer preemhasis memory */ - Word16 *gain_preQ, /* o : prequantizer excitation gain */ - Word16 code_preQ[], /* o : prequantizer excitation */ - Word16 *unbits, /* o : number of AVQ unused bits */ - const Word16 Q_new, /* i : Current frame scaling */ - const Word16 shift /* i : shifting applied to y1, xn,... */ -); - -Word16 encod_tran_fx( - Encoder_State_fx *st_fx, /* i/o: state structure */ - LPD_state *mem, /* i/o: acelp memories */ - const Word16 L_frame_fx, /* i : length of the frame */ - const Word16 speech_fx[], /* i : input speech */ - const Word16 Aw_fx[], /* i : weighted A(z) unquantized for subframes */ - const Word16 Aq_fx[], /* i : 12k8 Lp coefficient */ - const Word16 coder_type, /* i : coding type */ - const Word16 Es_pred_fx, /* i : predicted scaled innov. energy */ - const Word16 T_op_fx[], /* i : open loop pitch */ - const Word16 voicing_fx[], /* i : voicing */ - const Word16 *res_fx, /* i : residual signal */ - Word16 *syn_fx, /* i/o: core synthesis */ - Word16 *exc_fx, /* i/o: current non-enhanced excitation */ - Word16 *exc2_fx, /* i/o: current enhanced excitation */ - Word16 *pitch_buf_fx, /* i/o: floating pitch values for each subframe */ - Word16 *voice_factors, /* o : voicing factors */ - Word16 *bwe_exc_fx, /* i/o: excitation for SWB TBE */ - const Word16 gsc_attack_flag, /* i : Flag to indicate when an audio attack is deal with TM */ - Word16 *unbits, /* i/o: number of unused bits */ - Word16 sharpFlag, /* o : formant sharpening flag */ - const Word16 shift, /* i : Scaling to get 12 bits */ - const Word16 Q_new /* i : Input scaling */ -); - -Word16 est_tilt_fx( /* o : tilt of the code Q15 */ - const Word16 *exc, /* i : adaptive excitation vector Qx */ - const Word16 gain_pit, /* i : adaptive gain Q14 */ - const Word16 *code, /* i : algebraic exctitation vector Q9 */ - const Word32 gain_code, /* i : algebraic code gain Q16 */ - Word16 *voice_fac, /* o : voicing factor Q15 */ - const Word16 Q_exc /* i : Scaling factor of excitation Q0 */ -); - -Word16 Est_tilt2( /* o : tilt of the code */ - const Word16 *exc, /* i : adaptive excitation vector Qx */ - const Word16 gain_pit, /* i : adaptive gain Q14 */ - const Word16 *code, /* i : algebraic exctitation vector Q9 */ - const Word32 gain_code, /* i : algebraic code gain Q16 */ - Word16 *voice_fac, /* o : voicing factor Q15 */ - const Word16 Q_exc /* i : Scaling factor of excitation Q0 */ -); - -void transition_enc_fx( - Encoder_State_fx *st_fx, /* i/o: encoder state structure */ - const Word32 core_brate, /* i : core bitrate */ - const Word16 L_frame, /* i : length of the frame */ - const Word16 coder_type, /* i : coding type */ - const Word16 i_subfr, /* i : subframe index */ - Word16 *tc_subfr, /* i/o: TC subframe index */ - Word16 *Jopt_flag, /* i : joint optimization flag */ - Word16 *position, /* i/o: maximum of residual signal index */ - const Word16 voicing_fx[], /* i : normalized correlations (from OL pitch) Q15*/ - const Word16 T_op_fx[], /* i : open loop pitch estimates in current frame Q0*/ - Word16 *T0, /* i/o: close loop integer pitch Q0*/ - Word16 *T0_frac, /* i/o: close loop fractional part of the pitch Q0*/ - Word16 *T0_min, /* i/o: lower limit for close-loop search Q0*/ - Word16 *T0_max, /* i/o: higher limit for close-loop search Q0*/ - Word16 *exc_fx, /* i/o: pointer to excitation signal frame Q_new*/ - Word16 *y1_fx, /* o : zero-memory filtered adaptive excitation Q_new-1+shift*/ - const Word16 *res_fx, /* i : pointer to the LP residual signal frame Q_new*/ - const Word16 *h1_fx, /* i : weighted filter input response Q(14+shift)*/ - const Word16 *xn_fx, /* i : target vector Q_new-1+shift*/ - Word16 *xn2_fx, /* o : target vector for innovation search Q_new-1+shift*/ - Word16 *gp_cl_fx, /* i/o: memory of gain of pitch clipping algorithm */ - Word16 *gain_pit_fx, /* o : adaptive excitation gain Q14*/ - Word16 *g_corr_fx, /* o : ACELP correlation values */ - Word16 *clip_gain, /* i/o: adaptive gain clipping flag */ - Word16 **pt_pitch_fx, /* o : floating pitch values */ - Word16 *bwe_exc_fx, /* o : excitation for SWB TBE Q_new*/ - Word16 Q_new, /* i : Current scaling */ - Word16 shift /* i : downscaling needs for 12 bits convolutions */ -); - -Word16 abs_pit_enc_fx( /* o : pitch index */ - const Word16 fr_steps, /* i : fractional resolution steps (2 or 4) for shortest pitches*/ - const Word16 limit_flag, /* i : restrained(0) or extended(1) limits */ - const Word16 T0, /* i : integer pitch lag */ - const Word16 T0_frac /* i : pitch fraction */ -); - -Word16 delta_pit_enc_fx( /* o : pitch index */ - const Word16 fr_steps, /* i : fractional resolution steps (2 or 4)*/ - const Word16 T0, /* i : integer pitch lag */ - const Word16 T0_frac, /* i : pitch fraction */ - const Word16 T0_min /* i : delta search min */ -); - -void set_impulse_fx( - const Word16 xn_fx[], /* i : target signal */ - const Word16 h_orig_fx[], /* i : impulse response of weighted synthesis filter */ - Word16 exc_fx[], /* o : adaptive codebook excitation */ - Word16 yy1_fx[], /* o : filtered adaptive codebook excitation */ - Word16 *imp_shape, /* o : adaptive codebook index */ - Word16 *imp_pos, /* o : position of the glotal impulse center index */ - Word32 *gain_trans_fx, /* o : transition gain Q7 */ - Word16 Q_new /* i : Current scaling */ -); - -void pit16k_Q_enc_fx( - Encoder_State_fx *st_fx, /* i/o: encoder state structure */ - const Word16 nBits, /* i : # of Q bits */ - const Word16 limit_flag, /* i : restrained(0) or extended(1) Q limits */ - const Word16 T0, /* i : integer pitch lag */ - const Word16 T0_frac, /* i : pitch fraction */ - Word16 *T0_min, /* i/o: delta search min */ - Word16 *T0_max /* o : delta search max */ -); - -void gain_enc_amr_wb_fx( - Encoder_State_fx *st, /* i/o: encoder state structure */ - const Word16 *xn, /* i : target vector */ - const Word16 Q_xn, /* i : xn and yy1 format Q0 */ - const Word16 *yy1, /* i : zero-memory filtered adaptive excitation */ - const Word16 *y2, /* i : zero-memory filtered algebraic codebook excitation */ - const Word16 *code, /* i : algebraic excitation */ - const Word32 core_brate, /* i : core bitrate */ - Word16 *gain_pit, /* i/o: pitch gain / Quantized pitch gain */ - Word32 *gain_code, /* o : quantized codebook gain */ - Word16 *gain_inov, /* o : gain of the innovation (used for normalization) */ - Word32 *norm_gain_code, /* o : norm. gain of the codebook excitation */ - Word16 *g_coeff, /* i/o: correlations , -2,, -2 and 2 */ - const Word16 clip_gain, /* i : gain pitch clipping flag (1 = clipping) */ - Word16 *past_qua_en /* i/o: gain quantization memory (4 words) */ -); - -void gain_enc_lbr_fx( - Encoder_State_fx *st_fx, /* i/o: encoder state structure */ - const Word32 core_brate, /* i : core bitrate */ - const Word16 coder_type, /* i : coding type */ - const Word16 i_subfr, /* i : subframe index */ - const Word16 *xn, /* i : target vector Q_xn*/ - const Word16 *y1, /* i : zero-memory filtered adaptive excitation Q_xn*/ - const Word16 Q_xn, /* i : xn and y1 format */ - const Word16 *y2, /* i : zero-memory filtered algebraic codebook excitation Q9*/ - const Word16 *code, /* i : algebraic excitation Q9*/ - Word16 *gain_pit, /* o : quantized pitch gain Q14*/ - Word32 *gain_code, /* o : quantized codebook gain Q16*/ - Word16 *gain_inov, /* o : gain of the innovation (used for normalization) Q12*/ - Word32 *norm_gain_code, /* o : norm. gain of the codebook excitation Q16*/ - Word16 *g_corr, /* i/o: correlations , -2,, -2 and 2 mant/exp*/ - Word32 gc_mem[], /* i/o: gain_code from previous subframes */ - Word16 gp_mem[], /* i/o: gain_pitch from previous subframes */ - const Word16 clip_gain /* i : gain pitch clipping flag (1 = clipping) */ -); - -void gp_clip_test_gain_pit_fx( - const Word32 core_brate, /* i : core bitrate */ - const Word16 gain_pit, /* i : gain of quantized pitch Q14 */ - Word16 mem[] /* i/o: memory of gain of pitch clipping algorithm */ -); - -void gp_clip_test_lsf_fx( - const Word16 lsf[], /* i : lsf values (in frequency domain) */ - Word16 mem[], /* i/o: memory of gain of pitch clipping algorithm */ - const Word16 Opt_AMR_WB /* i : flag indicating AMR-WB IO mode */ -); - -Word16 inov_encode_fx( - Encoder_State_fx *st_fx, /* i/o: encoder state structure */ - const Word32 core_brate, /* i : core bitrate */ - const Word16 Opt_AMR_WB, /* i : flag indicating AMR-WB IO mode */ - const Word16 L_frame, /* i : length of the frame */ - const Word16 last_L_frame, /* i : length of the last frame */ - const Word16 coder_type, /* i : coding type */ - const Word16 bwidth, /* i : input signal bandwidth */ - const Word16 sharpFlag, /* i : formant sharpening flag */ - const Word16 i_subfr, /* i : subframe index */ - const Word16 tc_subfr, /* i : TC subframe index */ - const Word16 *p_Aq, /* i : LP filter coefficients Q12*/ - const Word16 gain_pit, /* i : adaptive excitation gain Q14*/ - Word16 *cn, /* i/o: target vector in residual domain Q_new*/ - const Word16 *exc, /* i : pointer to excitation signal frame Q_new*/ - Word16 *h2, /* i/o: weighted filter input response Q12*/ - const Word16 tilt_code, /* i : tilt of the excitation of previous subframe Q15*/ - const Word16 pt_pitch, /* i : pointer to current subframe fractional pitch Q6*/ - const Word16 *xn2, /* i : target vector for innovation search Q_new-1+shift*/ - Word16 *code, /* o : algebraic excitation Q9*/ - Word16 *y2, /* o : zero-memory filtered algebraic excitation Q9*/ - Word16 *unbits, /* o : number of unused bits for PI */ - Word16 shift -); - -Word32 sum2_fx( /* o : sum of all squared vector elements Q(2x+1)*/ - const Word16 *vec, /* i : input vector Qx*/ - const Word16 lvec /* i : length of input vector */ -); - -Word32 sum2_fx_mod( /* o : sum of all squared vector elements Q(2x+1)*/ - const Word16 *vec, /* i : input vector Qx*/ - const Word16 lvec /* i : length of input vector */ -); - -Word16 usdequant_fx( /* Qx*/ - const Word16 idx, /* i: quantizer index Q0*/ - const Word16 qlow, /* i: lowest codebook entry (index 0) Qx*/ - const Word16 delta /* i: quantization step Qy*/ -); - -Word16 gain_dequant_fx( /* o: decoded gain */ - Word16 index, /* i: quantization index */ - const Word16 min, /* i: value of lower limit */ - const Word16 max, /* i: value of upper limit */ - const Word16 bits, /* i: number of bits to dequantize */ - Word16 *expg -); - -void Es_pred_dec_fx( - Decoder_State_fx *st_fx, /* i/o: decoder state structure */ - Word16 *Es_pred, /* o : predicited scaled innovation energy Q8*/ - const Word16 coder_type, /* i : coder type */ - const Word32 core_brate /* i : core bitrate */ -); - -void gain_dec_tc_fx( - Decoder_State_fx *st_fx, /* i/o: decoder state structure */ - const Word32 core_brate_fx, /* i : core bitrate */ - const Word16 *code_fx, /* i : algebraic code excitation */ - const Word16 L_frame_fx, /* i : length of the frame */ - const Word16 i_subfr_fx, /* i : subframe number */ - const Word16 tc_subfr_fx, /* i : TC subframe index */ - const Word16 Es_pred_fx, /* i : predicted scaled innov. energy */ - Word16 *gain_pit_fx, /* o : pitch gain */ - Word32 *gain_code_fx, /* o : Quantized codeebook gain */ - Word16 *gain_inov_fx, /* o : unscaled innovation gain */ - Word32 *norm_gain_code_fx /* o : norm. gain of the codebook excit. */ -); - -void gain_dec_mless_fx( - Decoder_State_fx *st_fx, /* i/o: decoder state structure */ - const Word32 core_brate_fx, /* i : core bitrate */ - const Word16 L_frame_fx, /* i : length of the frame */ - const Word16 coder_type_fx, /* i : coding type */ - const Word16 i_subfr_fx, /* i : subframe number */ - const Word16 tc_subfr_fx, /* i : TC subframe index */ - const Word16 *code_fx, /* i : algebraic code excitation */ - const Word16 Es_pred_fx, /* i : predicted scaled innov. energy */ - Word16 *gain_pit_fx, /* o : Quantized pitch gain Q14*/ - Word32 *gain_code_fx, /* o : Quantized codeebook gain Q16*/ - Word16 *gain_inov_fx, /* o : unscaled innovation gain Q12*/ - Word32 *norm_gain_code_fx /* o : norm. gain of the codebook excitation Q16*/ -); - -void pre_echo_att_fx( - Word32 *Last_frame_ener_fx, /* i/o: Energy of the last frame 2*Q_new+1*/ - Word16 *exc_fx, /* i/o: Excitation of the current frame Q_new*/ - const Word16 gsc_attack_flag_fx, /* i : flag signalling attack encoded by AC mode (GSC) */ - const Word16 Q_new - ,const Word16 last_coder_type_fx /* i : Last coding mode */ -); - -void gain_dec_lbr_fx( - Decoder_State_fx *st_fx, /* i/o: decoder state structure */ - const Word32 core_brate, /* i : core bitrate */ - const Word16 coder_type, /* i : coding type */ - const Word16 i_subfr, /* i : subframe index */ - const Word16 *code_fx, /* i : algebraic excitation Q12*/ - Word16 *gain_pit_fx, /* o : quantized pitch gain Q14*/ - Word32 *gain_code_fx, /* o : quantized codebook gain Q16*/ - Word16 *gain_inov_fx, /* o : gain of the innovation (used for normalization) Q12*/ - Word32 *norm_gain_code_fx, /* o : norm. gain of the codebook excitation Q16*/ - Word32 gc_mem[], /* i/o: gain_code from previous subframes */ - Word16 gp_mem[] /* i/o: gain_pitch from previous subframes */ -); - -void lp_gain_updt_fx( - const Word16 i_subfr, /* i : subframe number Q0 */ - const Word16 gain_pit, /* i : Decoded gain pitch Q14 */ - const Word32 norm_gain_code, /* i : Normalised gain code Q16 */ - Word16 *lp_gainp, /* i/o: LP-filtered pitch gain(FEC) Q14 */ - Word16 *lp_gainc, /* i/o: LP-filtered code gain (FEC) Q3 */ - const Word16 L_frame /* i : length of the frame */ -); - -void pit_Q_dec_fx( - const Word16 Opt_AMR_WB, /* i : flag indicating AMR-WB IO mode */ - const Word16 pitch_index, /* i : pitch index */ - const Word16 nBits, /* i : # of Q bits */ - const Word16 delta, /* i : Half the CL searched interval */ - const Word16 pit_flag, /* i : absolute(0) or delta(1) pitch Q */ - const Word16 limit_flag, /* i : restrained(0) or extended(1) Q limits */ - Word16 *T0, /* o : integer pitch lag */ - Word16 *T0_frac, /* o : pitch fraction */ - Word16 *T0_min, /* i/o: delta search min */ - Word16 *T0_max /* i/o: delta search max */ - ,Word16 *BER_detect /* o : BER detect flag */ -); - -void abs_pit_dec_fx( - const Word16 fr_steps, /* i: fractional resolution steps (0, 2, 4) */ - Word16 pitch_index, /* i: pitch index */ - const Word16 limit_flag, /* i : restrained(0) or extended(1) limits */ - Word16 *T0, /* o: integer pitch lag */ - Word16 *T0_frac /* o: pitch fraction */ -); - -void limit_T0_fx( - const Word16 L_frame, /* i : length of the frame */ - const Word16 delta, /* i : Half the close-loop searched interval */ - const Word16 pit_flag, /* i : selecting absolute(0) or delta(1) pitch quantization */ - const Word16 limit_flag, /* i : flag for Q limits (0=restrained, 1=extended) */ - const Word16 T0, /* i : rough pitch estimate around which the search is done */ - const Word16 T0_frac, /* i : pitch estimate fractional part */ - Word16 *T0_min, /* o : lower pitch limit */ - Word16 *T0_max /* o : higher pitch limit */ -); - -void delta_pit_dec_fx( - const Word16 fr_steps, /* i : fractional resolution steps (0, 2, 4) */ - const Word16 pitch_index, /* i : pitch index */ - Word16 *T0, /* o : integer pitch lag */ - Word16 *T0_frac, /* o : pitch fraction */ - const Word16 T0_min /* i : delta search min */ -); - -Word16 pit_decode_fx( /* o : floating pitch value */ - Decoder_State_fx *st_fx, /* i/o: decoder state structure */ - const Word32 core_brate, /* i : core bitrate */ - const Word16 Opt_AMR_WB, /* i : flag indicating AMR-WB IO mode */ - const Word16 L_frame, /* i : length of the frame */ - Word16 i_subfr, /* i : subframe index */ - const Word16 coder_type, /* i : coding type */ - Word16 *limit_flag, /* i/o: restrained(0) or extended(1) Q limits */ - Word16 *T0, /* o : close loop integer pitch */ - Word16 *T0_frac, /* o : close loop fractional part of the pitch */ - Word16 *T0_min, /* i/o: delta search min for sf 2 & 4 */ - Word16 *T0_max, /* i/o: delta search max for sf 2 & 4 */ - const Word16 L_subfr /* i : subframe length */ -); - -void pred_lt4( - const Word16 excI[], /* in: excitation buffer */ - Word16 excO[], /* out: excitation buffer */ - Word16 T0, /* input : integer pitch lag */ - Word16 frac, /* input : fraction of lag */ - Word16 L_subfr, /* input : subframe size */ - const Word16 *win, /* i : interpolation window */ - const Word16 nb_coef, /* i : nb of filter coef */ - const Word16 up_sample /* i : up_sample */ -); - -void lp_filt_exc_dec_fx( - Decoder_State_fx *st_fx, /* i/o: decoder state structure */ - const Word16 codec_type, /* i : coder type */ - const Word32 core_brate, /* i : core bitrate */ - const Word16 Opt_AMR_WB, /* i : flag indicating AMR-WB IO mode */ - const Word16 coder_type, /* i : coding type */ - const Word16 i_subfr, /* i : subframe index */ - const Word16 L_subfr, /* i : subframe size */ - const Word16 L_frame, /* i : frame size */ - Word16 lp_flag, /* i : operation mode signalling */ - Word16 *exc -); - -void inov_decode_fx( - Decoder_State_fx *st_fx, /* i/o: decoder state structure */ - const Word32 core_brate, /* i : core bitrate */ - const Word16 Opt_AMR_WB, /* i : flag indicating AMR-WB IO mode */ - const Word16 L_frame, /* i : length of the frame */ - const Word16 coder_type, /* i : coding type */ - const Word16 sharpFlag, /* i : formant sharpening flag */ - const Word16 i_subfr, /* i : subframe index */ - const Word16 tc_subfr, /* i : TC subframe index */ - const Word16 *p_Aq, /* i : LP filter coefficients Q12 */ - const Word16 tilt_code, /* i : tilt of the excitation of previous subframe Q15 */ - const Word16 pt_pitch, /* i : pointer to current subframe fractional pitch Q6*/ - Word16 *code /* o : algebraic excitation */ -); - -void dec_acelp_1t64_fx( - Decoder_State_fx *st_fx, /* i/o: decoder state structure */ - Word16 code[] /* o: algebraic (fixed) codebook excitation Q12*/ -); - -void dec_acelp_2t32_fx( - Decoder_State_fx *st_fx, /* i/o: decoder state structure */ - Word16 code[] /* o: algebraic (fixed) codebook excitation */ -); - -void dec_acelp_4t64_fx( - Decoder_State_fx *st_fx, /* i/o: decoder state structure */ - Word16 nbbits, /* i : number of bits per codebook */ - Word16 code[], /* o : algebraic (fixed) codebook excitation Q9*/ - const Word16 Opt_AMR_WB -); - -void weight_a_lc_fx( - const Word16 a[], /* i: LP filter coefficients Q12 */ - Word16 ap[], /* o: weighted LP filter coefficients Q12 */ - const Word16 *gammatbl, /* i: weighting factor Q15 */ - const Word16 m /* i: order of LP filter Q0 */ -); - -void weight_a_fx( - const Word16 a[], /* i: LP filter coefficients Q12 */ - Word16 ap[], /* o: weighted LP filter coefficients Q12 */ - const Word16 gamma, /* i: weighting factor Q15 */ - const Word16 m /* i: order of LP filter Q0 */ -); - -void Residu3_lc_fx( - const Word16 a[], /* i : prediction coefficients Q12 */ - const Word16 m, /* i : order of LP filter Q0 */ - const Word16 x[], /* i : input signal (usually speech) Qx */ - Word16 y[], /* o : output signal (usually residual) Qx */ - const Word16 lg, /* i : vector size Q0 */ - const Word16 shift /* i : 0=residu2, 1=residu */ -); - -void Residu3_10_fx( - const Word16 a[], /* i : prediction coefficients Q12 */ - const Word16 x[], /* i : input signal (usually speech) Qx */ - /* (note that values x[-10..-1] are needed) */ - Word16 y[], /* o : output signal (usually residual) Qx */ - const Word16 lg, /* i : vector size Q0 */ - const Word16 shift /* i : 0=residu2, 1=residu */ -); - -void Residu3_fx( - const Word16 a[], /* i : prediction coefficients Q12 */ - const Word16 x[], /* i : input signal (usually speech) Qx */ - /* (note that values x[-M..-1] are needed) */ - Word16 y[], /* o : output signal (usually residual) Qx */ - const Word16 lg, /* i : vector size Q0 */ - const Word16 shift /* i : 0=residu2, 1=residu */ -); - -void pre_exc_fx( - const Word16 Opt_AMR_WB, /* i : flag indicating AMR-WB IO mode */ - const Word16 *speech, /* i : input speech Q_new-1*/ - const Word16 *p_Aq, /* i : 12k8 Lp coefficient Q12*/ - const Word16 *p_A, /* i : unquantized A(q) filter with bandwidth expansion Q12*/ - const Word16 coder_type, /* i : coding type */ - const Word16 i_subfr, /* i : current sub frame indicator */ - Word16 *Ap, /* o : weighted LP filter coefficients Q12*/ - const Word16 *res, /* i : residual signal Q_new*/ - Word16 *exc, /* o : excitation signal Q_new*/ - Word16 *h1, /* o : impulse response of weighted synthesis filter Q(14+shift)*/ - Word16 *h2, /* o : impulse response of weighted synthesis filter Q(12+shift), for codebook search*/ - Word16 *xn, /* o : close-loop Pitch search target vector Q_new-1+shift*/ - Word16 *cn, /* o : target vector in residual domain Q_new*/ - Word16 *mem_syn, /* i/o: memory of the synthesis filter Q_new-1*/ - Word16 *mem_w0, /* i/o: weighting filter denominator memory Q_new-1*/ - const Word16 L_subfr, /* i : subframe length */ - Word16 shift -); - -void encod_audio_fx( - Encoder_State_fx *st_fx, /* i/o: State structure */ - LPD_state *mem, /* i/o: acelp memories */ - const Word16 speech[], /* i : input speech Q_new */ - const Word16 Aw_fx[], /* i : weighted A(z) unquantized for subframes */ - const Word16 Aq_fx[], /* i : 12k8 Lp coefficient */ - const Word16 T_op[], /* i : open loop pitch */ - const Word16 voicing[], /* i : voicing Q15 */ - const Word16 *res, /* i : residual signal Q_new */ - Word16 *synth, /* i/o: core synthesis Q-1 */ - Word16 *exc, /* i/o: current non-enhanced excitation Q_new */ - Word16 *pitch_buf, /* i/o: floating pitch values for each subframe Q6 */ - Word16 *voice_factors, /* o : voicing factors Q15 */ - Word16 *bwe_exc, /* o : excitation for SWB TBE Q0 */ - const Word16 gsc_attack_flag, /* i : Flag that point to an attack coded with AC mode (GSC) */ - const Word16 coder_type, /* i : coding type */ - Word16 *lsf_new, /* i : current frame ISF vector */ - Word16 *tmp_noise, /* o : noise energy */ - Word16 Q_new, - Word16 shift -); - -Word16 pit_encode_fx( /* o : Fractional pitch for each subframe */ - Encoder_State_fx *st_fx, /* i/o: encoder state structure */ - const Word32 core_brate, /* i : core bitrate */ - const Word16 Opt_AMR_WB, /* i : flag indicating AMR-WB IO mode */ - const Word16 L_frame, /* i : length of the frame */ - const Word16 coder_type, /* i : coding type */ - Word16 *limit_flag, /* i/o: restrained(0) or extended(1) Q limits */ - const Word16 i_subfr, /* i : subframe index */ - Word16 *exc, /* i/o: pointer to excitation signal frame */ - const Word16 L_subfr, /* i : subframe length */ - const Word16 *T_op, /* i : open loop pitch estimates in current frame */ - Word16 *T0_min, /* i/o: lower limit for close-loop search */ - Word16 *T0_max, /* i/o: higher limit for close-loop search */ - Word16 *T0, /* i/o: close loop integer pitch */ - Word16 *T0_frac, /* i/o: close loop fractional part of the pitch */ - const Word16 *h1, /* i : weighted filter input response */ - const Word16 *xn /* i : target vector */ -); - -Word32 dotp_fx( /* o : dot product of x[] and y[] */ - const Word16 x[], /* i : vector x[] */ - const Word16 y[], /* i : vector y[] */ - const Word16 n, /* i : vector length */ - Word16 * exp /* (o) : exponent of result (0..+30) */ -); - -Word32 syn_kern_16( - Word32 L_tmp, - const Word16 a[], - const Word16 y[] -); - -void syn_filt_s_lc_fx( - const Word16 shift, /* i : scaling to apply Q0 */ - const Word16 a[], /* i : LP filter coefficients Q12 */ - const Word16 x[], /* i : input signal Qx */ - Word16 y[], /* o : output signal Qx-s */ - const Word16 lg /* i : size of filtering Q0 */ -); - -void acelp_2t32_fx( - Encoder_State_fx *st_fx, /* i/o: encoder state structure */ - const Word16 dn[], /* i : corr. between target and h[]. */ - const Word16 h[], /* i : impulse response of weighted synthesis filter */ - Word16 code[], /* o : algebraic (fixed) codebook excitation */ - Word16 y[] /* o : filtered fixed codebook excitation */ -); - -Word16 acelp_4t64_fx( - Encoder_State_fx *st_fx, /* i/o: encoder state structure */ - Word16 dn[], /* i : corr. between target and h[]. */ - const Word16 cn[], /* i : residual after long term prediction Q_new*/ - const Word16 H[], /* i : impulse response of weighted synthesis filter Q12*/ - Word16 R[], /* i : autocorrelation values */ - const Word16 acelpautoc, /* i : autocorrealtion flag */ - Word16 code[], /* o : algebraic (fixed) codebook excitation Q9*/ - Word16 y[], /* o : filtered fixed codebook excitation Q9*/ - Word16 nbbits, /* i : number of bits per codebook */ - const Word16 cmpl_flag, /* i : coomplexity reduction flag */ - const Word16 Opt_AMR_WB /* i : flag indicating AMR-WB IO mode */ -); - -void acelp_1t64_fx( - Encoder_State_fx *st_fx, /* i/o: encoder state structure */ - const Word16 dn[], /* i : corr. between target and h[]. */ - const Word16 h[], /* i : impulse response of weighted synthesis filter */ - Word16 code[], /* o : algebraic (fixed) codebook excitation */ - Word16 y[] /* o : filtered fixed codebook excitation */ -); - -void cb_shape_fx( - const Word16 preemphFlag, /* i : flag for pre-emphasis */ - const Word16 pitchFlag, /* i : flag for pitch sharpening */ - const Word16 scramblingFlag, /* i : flag for phase scrambling */ - const Word16 sharpFlag, /* i : flag for formant sharpening */ - const Word16 formantTiltFlag, /* i : flag for formant tilt */ - const Word16 g1, /* i : formant sharpening numerator weighting */ - const Word16 g2, /* i : formant sharpening denominator weighting */ - const Word16 *p_Aq, /* i : LP filter coefficients */ - Word16 *code, /* i/o: signal to shape */ - const Word16 tilt_code, /* i : tilt of code */ - const Word16 pt_pitch, /* i : pointer to current subframe fractional pitch */ - const Word16 shift -); - -void corr_xh_fx( - const Word16 x[], /* i : target signal */ - Word16 dn[], /* o : correlation between x[] and h[] */ - const Word16 h[] /* i : impulse response (of weighted synthesis filter) */ -); - -void corr_xh_jopt_fx( - const Word16 h[], /* i : impulse response of weighted synthesis filter Q12 */ - const Word16 x[], /* i : target vector Q0 */ - Word16 dn[], /* o : correlation between target and h[] Q12 */ - Word16 gain, /* i : Unquantized ACB gain Q14 */ - Word16 clip, /* i : clip Q0 */ - Word16 shift /* i : scaling of x Q0 */ -); - -void enhancer_fx( - const Word32 core_brate, /* i : decoder bitrate */ - const Word16 Opt_AMR_WB, /* i : flag indicating AMR-WB IO mode */ - const Word16 coder_type, /* i : coder type */ - const Word16 i_subfr, /* i : subframe number */ - const Word16 L_frame, /* i : frame size */ - const Word16 voice_fac, /* i : subframe voicing estimation Q15 */ - const Word16 stab_fac, /* i : LP filter stablility measure Q15 */ - Word32 norm_gain_code,/* i : normalised innovative cb. gain Q16 */ - const Word16 gain_inov, /* i : gain of the unscaled innovation Q12 */ - Word32 *gc_threshold, /* i/o: gain code threshold Q16 */ - Word16 *code, /* i/o: innovation Q12 */ - Word16 *exc2, /* i/o: adapt. excitation/total exc. Q_exc*/ - const Word16 gain_pit, /* i : quantized pitch gain Q14 */ - struct dispMem_fx *dm_fx, /* i/o: phase dispersion algorithm memory */ - const Word16 Q_exc /* i : Q of the excitation */ -); - -Word16 Rescale_exc( - Word16 dct_post_old_exc_fx[], /* i/o: Music post processing memory */ - Word16 exc[], /* i/o: excitation to rescale Q_exc */ - Word16 bwe_exc[], - Word16 *last_exc_dct_in, - Word16 lg, /* i : frame size */ - Word16 lg32, - Word32 L_gain_code, /* i : decoded codebook gain Q16 */ - Word16 *sQ_exc, /* i/o: Excitation scaling factor */ - Word16 *sQsubfr, /* i/o: Past excitation scaling factors */ - Word16 exc2[], /* o : local excitation vector */ - Word16 i_subfr, /* i : subframe number */ - const Word16 coder_type -); - -void Prep_music_postP_fx( - Word16 exc_buffer_in[], /* i/o: excitation buffer Q_exc*/ - Word16 dct_buffer_out[], /* o : DCT output buffer (qdct)*/ - Word16 filt_lfE[], /* i/o: long term spectrum energy Q15 */ - const Word16 last_core, /* i : last core */ - const Word16 *pitch_buf, /* i : current frame pitch information Q6*/ - Word16 *LDm_enh_lp_gbin, /* o : smoothed suppression gain, per bin FFT Q15*/ - const Word16 Q_exc, /* i : excitation scaling */ - Word16 *qdct /* o : Scaling factor of dct coefficient */ -); - -void Post_music_postP_fx( - Word16 dct_buffer_in[], /* i/o: excitation buffer */ - Word16 *exc2, /* i/o: Current excitation to be overwriten */ - const Word16 *mem_tmp, /* i : previous frame synthesis memory */ - Word16 *st_mem_syn2, /* i/o: current frame synthesis memory */ - const Word16 *Aq, /* i : LPC filter coefficients */ - Word16 *syn, /* i/o: 12k8 synthesis */ - Word16 *Q_exc, /* i : excitation scaling */ - Word16 *prev_Q_syn, /* i : previsous frame synthesis scaling */ - Word16 *Q_syn, /* i : Current frame synthesis scaling */ - Word16 *mem_syn_clas_estim_fx, /* i : old 12k8 synthesis used for frame classification*/ - const Word16 IsIO, /* i: Flag to indicate IO mode */ - Word16 *mem_deemph, /* i/o: speech deemph filter memory */ - Word16 *st_pst_old_syn_fx, /* i/o: psfiler */ - Word16 *st_pst_mem_deemp_err_fx, /* i/o: psfiler */ - Word16 *mem_agc, - PFSTAT *pf_stat, /* i/o: All memories related to NB post filter */ - const Word16 *tmp_buffer /* tmp_buffer in Q-1 */ - ,Word16 *mem_tmp2 /* Temporary memory used with scale_syn */ -); - -void unscale_AGC( - const Word16 x[], - const Word16 Qx, - Word16 y[], - Word16 mem[], - const Word16 n -); - -void LD_music_post_filter_fx( - const Word16 dtc_in[], /* i : input synthesis Qdct */ - Word16 dtc_out[], /* o : output synthesis Qdct */ - const Word32 core_brate, /* i : core bitrate Q0 */ - Word16 *last_music_flag, /* i/o : Previous music detection ouptut Q0 */ - Word16 *thresh, /* i/o : Detection thresold Q0 */ - Word16 *nb_thr_1, /* i/o : Number of consecutives frames of level 1 Q0 */ - Word16 *nb_thr_3, /* i/o : Number of consecutives frames of level 3 Q0 */ - Word16 *lt_diff_etot, /* i/o : Long term total energy variation Q8 */ - Word16 *mem_etot, /* i/o : Total energy memory Q8 */ - const Word16 min_ns_gain, /* i : minimum gain for inter-harm noise red. Q15 */ - Word32 bckr[], /* i/o : per band bckgnd. noise energy estimate */ - Word32 lf_EO[], /* i/o : old per bin E for previous half frame 2*Qdct+10 */ - Word16 lp_gbin[], /* i/o : smoothed suppression gain, per FFT bin Q15 */ - Word16 *filt_lfE, /* i : post filter weighting coefficient Q15 */ - Word16 *last_nonfull_music, /* i : Number of frames sinces la "speech like" frame Q0*/ - Word16 *Old_ener_Q, /* i/o : Old energy scaling factor */ - const Word16 coder_type, /* i : Coder type : -1 in case of IO Q0 */ - const Word16 Last_coder_type, /* i : input scaling Q0 */ - const Word16 Qdct /* i : input scaling Q0 */ -); - -void Rescale_mem( - const Word16 Q_exc, /* i : current excitation scaling (>=0) */ - Word16 *prev_Q_syn, /* i/o : scaling factor of previous frame */ - Word16 *Q_syn, /* i/o : scaling factor of frame */ - Word16 *mem_syn2, /* i/o : modified synthesis memory */ - Word16 *mem_syn_clas_estim_fx, /* i/o : old 12k8 core memory for classification */ - const Word16 MaxScaling, /* i: Minimal difference between excitation scaling and synthesis scaling */ - Word16 *mem_deemph, /* i/o: speech deemph filter memory */ - Word16 *pst_old_syn, /* i/o: psfiler */ - Word16 *pst_mem_deemp_err, /* i/o: psfiler */ - Word16 *mem_agc, - PFSTAT *pf_stat, /* i/o: All memories related to NB post filter */ - const Word16 Vad_flag, - const Word16 Cna_flag, - const Word16 *tmp_buffer /* tmp_buffer in Q-1 */ -); - -void Scale_sig( - Word16 x[], /* i/o: signal to scale Qx */ - const Word16 lg, /* i : size of x[] Q0 */ - const Word16 exp0 /* i : exponent: x = round(x << exp) Qx ?exp */ -); - -void isf2lsf_fx( - const Word16 *isf, /* i : ISF vector */ - Word16 *lsf, /* o : LSF vector */ - Word16 *stable_lsp /* i/o: stable LSP filter coefficients */ -); - -void isp2lsp_fx( - const Word16 *isp, /* i : LSP vector */ - Word16 *lsp, /* o : ISP filter coefficients */ - Word16 *stable_lsp, /* i/o: stable LSP filter coefficients */ - const Word16 m /* i : order of LP analysis */ -); - -void lsf2isf_fx( - const Word16 *lsf, /* i : LSF vector */ - Word16 *isf, /* o : ISF vector */ - Word16 *stable_isp, /* i/o: stable ISP filter coefficients */ - const Word16 m /* i : order of LP analysis */ -); - -void lsp2isp_fx( - const Word16 *lsp, /* i : LSP vector */ - Word16 *isp, /* o : ISP filter coefficients */ - Word16 *stable_isp, /* i/o: ISP filter coefficients */ - const Word16 m /* i : order of LP analysis */ -); - -void updt_IO_switch_dec_fx( - const Word16 output_frame, /* i : output frame length */ - Decoder_State_fx *st_fx /* o : Decoder static variables structure */ -); - -void prep_tbe_exc_fx( - const Word16 L_frame_fx, /* i : length of the frame */ - const Word16 i_subfr_fx, /* i : subframe index */ - const Word16 gain_pit_fx, /* i : Pitch gain Q14*/ - const Word32 gain_code_fx, /* i : algebraic codebook gain 16+Q_exc*/ - const Word16 code_fx[], /* i : algebraic excitation Q9*/ - const Word16 voice_fac_fx, /* i : voicing factor Q15*/ - Word16 *voice_factors_fx, /* o : TBE voicing factor Q15*/ - Word16 bwe_exc_fx[], /* i/o: excitation for TBE Q_exc*/ - const Word16 gain_preQ_fx, /* i : prequantizer excitation gain */ - const Word16 code_preQ_fx[], /* i : prequantizer excitation */ - const Word16 Q_exc, /* i : Excitation, bwe_exc Q-factor */ - Word16 T0, /* i : integer pitch variables Q0 */ - Word16 T0_frac, /* i : Fractional pitch variables Q0*/ - const Word16 coder_type, /* i : coding type */ - Word32 core_brate /* i :core bitrate */ -); - -void interp_code_5over2_fx( - const Word16 inp_code[], /* i : input vector */ - Word16 interp_code[], /* o : output vector */ - const Word16 inp_length /* i : length of input vector */ -); - -void lsp2lsf_fx( - const Word16 lsp[], /* i : lsp[m] (range: -1<=val<1) Q15*/ - Word16 lsf[], /* o : lsf[m] normalized (range: 0.0<=val<=0.5) Q(x2.56)*/ - const Word16 m, /* i : LPC order Q0*/ - Word32 int_fs -); - -void lsf_enc_fx( - Encoder_State_fx *st_fx, /* i/o: state structure */ - const Word16 L_frame, /* i : length of the frame */ - const Word16 coder_type, /* i : coding type */ - Word16 *lsf_new, /* o : quantized LSF vector */ - Word16 *lsp_new, /* i/o: LSP vector to quantize/quantized */ - Word16 *lsp_mid, /* i/o : mid-frame LSP vector */ - Word16 *Aq, /* o : quantized A(z) for 4 subframes */ - Word16 *stab_fac, /* o : LSF stability factor */ - const Word16 Nb_ACELP_frames, - const Word16 Q_new -); - -void lsf_mid_dec_fx( - Decoder_State_fx *st_fx, /* i/o: decoder state structure */ - const Word16 int_fs, /* i : internal (ACELP) sampling frequency */ - Word16 qlsp0[], /* i : quantized LSPs from frame beginning Q15*/ - Word16 qlsp1[], /* i : quantized LSPs from frame endSQ15*/ - Word16 coder_type, /* i : Coder type */ - Word16 qlsp[], /* o : quantized LSPs Q15*/ - const Word32 core_brate, /* i : core bitrate */ - Word16 ppp_mode, - Word16 nelp_mode, - Word16 prev_bfi, - Word16 *mid_lsf_int, - Word16 safety_net -); - -Word16 lsf_stab_fx( /* o : LP filter stability Q15*/ - const Word16 *lsf, /* i : LSF vector Q(x2.56)*/ - const Word16 *lsfold, /* i : old LSF vector Q(x2.56)*/ - const Word16 Opt_AMR_WB, /* i : flag indicating AMR-WB IO mode */ - const Word16 L_frame /* i : frame length */ -); - -void lsf_allocate_fx( - const Word16 nBits, /* i : Number of bits to use for quantization */ - const Word16 framemode, /* i : ISF quantizer mode */ - const Word16 framemode_p, /* i : ISF quantizer mode predmode (mode_lvq_p) */ - Word16 *stages0, /* o : Number of stages for safety-net quantizer */ - Word16 *stages1, /* o : Number of stages for predictive quantizer */ - Word16 levels0[], /* o : Number of vectors for each stage for SFNET */ - Word16 levels1[], /* o : Number of vectors for each stage for pred */ - Word16 bits0[], /* o : Number of bits for each stage safety net */ - Word16 bits1[] /* o : Number of bits for each stage pred */ -); -Word16 vq_dec_lvq_fx ( - Word16 sf_flag, /* i : safety net flag */ - Word16 x[], /* o : Decoded vector Q(x2.56)*/ - Word16 indices[], /* i : Indices */ - Word16 stages, /* i : Number of stages */ - Word16 N, /* i : Vector dimension */ - Word16 mode, /* (i): mode_lvq, or mode_lvq_p */ - Word16 no_bits, /* (i): no. bits for lattice */ - Word32 *p_offset_scale1, - Word32 *p_offset_scale2, - Word32 *p_offset_scale1_p, - Word32 *p_offset_scale2_p, - Word16 *p_no_scales, - Word16 *p_no_scales_p -); - -Word16 qlsf_ARSN_tcvq_Dec_16k_fx ( - Word16 *y_fx, /* o : Quantized LSF vector */ - Word16 *indice, /* i : Indices */ - const Word16 nBits /* i : number of bits */ -); - -void tcvq_Dec_fx(Word16 *ind, - /*float *d_out, */ - Word16 *d_out_fx, - Word16 safety_net - ); - -Word32 qlsf_ARSN_tcvq_Enc_16k_fx( - const Word16 *x_fx, /* i : Vector to be encoded x2.65 */ - Word16 *y_fx, /* o : Quantized LSF vector x2.65 */ - Word16 *indice, /* o : Indices */ - const Word16 *w_fx, /* i : LSF Weights Q10 */ - const Word16 nBits, /* i : number of bits */ - Word16 safety_net /* i : safety_net flag */ -); - -void Vr_add( - const Word16 *in1, /* i : Input vector 1 */ - const Word16 *in2, /* i : Input vector 2 */ - Word16 *out, /* o : Output vector that contains vector 1 + vector 2 */ - Word16 Len /* i : Vector lenght */ -); - -void Vr_subt( - const Word16 *in1, /* i : Input vector 1 */ - const Word16 *in2, /* i : Input vector 2 */ - Word16 *out, /* o : Output vector that contains vector 1 + vector 2 */ - Word16 Len /* i : Vector lenght */ -); - -void index_lvq_fx ( - Word16 *quant, /* i : codevector to be indexed (2 8-dim subvectors) Q13*/ - Word16 *idx_lead, /* i : leader class index for each subvector */ - Word16 *idx_scale, /* i : scale index for each subvector */ - Word16 mode, /* i : integer signalling the quantizer structure for the current bitrate */ - Word16 *index, /* o : encoded index (represented on 3 short each with 15 bits ) */ - Word32 * p_offset_scale1, - Word32 * p_offset_scale2, - Word16 * p_no_scales -); - -void multiply32_32_64_fx( - Word32 x, - Word32 y, - Word32 *res -); - -void permute_fx( - Word16 *pTmp1, /* i/o: vector whose components are to be permuted */ - const Word16 *perm /* i : permutation info (indexes that should be interchanged), max two perms */ -); - -Word32 mslvq_fx ( - Word16 *pTmp, /* i : M-dimensional input vector */ - Word16 *quant, /* o : quantized vector */ - Word16 *cv_out, /* o : corresponding 8-dim lattice codevectors (without the scaling) */ - Word16 *idx_lead, /* o : leader index for each 8-dim subvector */ - Word16 *idx_scale, /* o : scale index for each subvector */ - Word16 *w, /* i : weights for LSF quantization */ - Word16 mode, /* i : number indicating the coding type (V/UV/G...)*/ - Word16 mode_glb, /* i : LVQ coding mode */ - Word16 pred_flag, /* i : prediction flag (0: safety net, 1 - predictive )*/ - Word16 no_scales[][2] -); - -Word32 mslvq_cng_fx ( - Word16 idx_cv, /* i : index of cv from previous stage */ - Word16 *pTmp, /* i : 16 dimensional input vector x2.56*/ - Word16 *quant, /* o : quantized vector x2.56*/ - Word16 *cv_out, /* o : corresponding 8-dim lattice codevectors (without the scaling) Q13*/ - Word16 *idx_lead, /* o : leader index for each 8-dim subvector */ - Word16 *idx_scale, /* o : scale index for each subvector */ - const Word16 *w, /* i : weights for LSF quantization Q10*/ - Word16 * no_scales -); - -void sort_fx( - Word16 *r, /* i/o: Vector to be sorted in place */ - Word16 lo, /* i : Low limit of sorting range */ - Word16 up /* I : High limit of sorting range */ -); - -void lsf_dec_fx( - Decoder_State_fx *st_fx, /* i/o: State structure */ - const Word16 tc_subfr, /* i : TC subframe index */ - const Word16 L_frame, /* i : length of the frame */ - const Word16 coder_type, /* i : coding type */ - const Word16 bwidth, /* i : input signal bandwidth */ - Word16 *Aq, /* o : quantized A(z) for 4 subframes */ - Word16 *LSF_Q_prediction, /* o : LSF prediction mode */ - Word16 *lsf_new, /* o : de-quantized LSF vector */ - Word16 *lsp_new, /* o : de-quantized LSP vector */ - Word16 *lsp_mid /* o : de-quantized mid-frame LSP vector */ -); - -void lsf_end_enc_fx( - Encoder_State_fx *st, - const Word16 *lsf, - Word16 *qlsf, - Word16 *mem_AR, - Word16 * mem_MA, - const Word16 nBits, - const Word16 coder_type_org, - const Word16 bwidth, - Word32 *Bin_Ener, - Word16 Q_ener, - const Word32 int_fs, - Word32 core_brate, - Word16 *streaklimit, - Word16 *pstreaklen, - Word16 force_sf, - Word16 RF_flag, - Word16 mode2_flag, - Word16 * lpc_param, - Word16 * no_stages, - Word16 * bits_param_lpc, - Word16 coder_type_raw -); - -void lsf_end_dec_fx( - Decoder_State_fx *st, - Word16 mode2_flag, - const Word16 coder_type_org, - const Word16 bwidth, - const Word16 nBits, - Word16 *qlsf, - Word16 *mem_AR, - Word16 *mem_MA, - const Word32 int_fs, - Word32 core_brate, - Word32 *p_offset_scale1, - Word32 *p_offset_scale2, - Word32 *p_offset_scale1_p, - Word32 *p_offset_scale2_p, - Word16 *p_no_scales, - Word16 *p_no_scales_p, - Word16 *safety_net, - Word16 *lpc_param, - Word16 *LSF_Q_prediction, /* o : LSF prediction mode */ - Word16 * nb_indices -); - -Word16 find_pred_mode( - const Word16 coder_type, - const Word16 bwidth, - const Word32 int_fs, - Word16 * p_mode_lvq, - Word16 * p_mode_lvq_p, - Word32 core_brate -); - -Word16 xsf_to_xsp( - Word16 lsf -); - -Word16 xsp_to_xsf( - Word16 lsp -); - -void int_lsp4_fx( - const Word16 L_frame, /* i : length of the frame */ - const Word16 lsp_old[], /* i : LSPs from past frame Q15*/ - const Word16 lsp_mid[], /* i : LSPs from mid-frame Q15*/ - const Word16 lsp_new[], /* i : LSPs from present frame Q15*/ - Word16 *Aq, /* o : LP coefficients in both subframes Q12*/ - const Word16 m, /* i : order of LP filter */ - Word16 relax_prev_lsf_interp /* i : relax prev frame lsf interp after erasure */ -); - -Word16 modify_Fs_fx( /* o : length of output Q0 */ - const Word16 sigIn_fx[], /* i : signal to decimate Q0 */ - Word16 lg, /* i : length of input Q0 */ - const Word32 fin, /* i : frequency of input Q0 */ - Word16 sigOut_fx[], /* o : decimated signal Q0 */ - const Word32 fout, /* i : frequency of output Q0 */ - Word16 mem_fx[], /* i/o: filter memory Q0 */ - const Word16 nblp /* i : flag indicating if NB low-pass is applied */ -); - -void addBassPostFilterFx( - const Word16 *harm_timeIn_Fx, - Word32 **rAnalysis_Fx, - Word32 **iAnalysis_Fx, - HANDLE_CLDFB_FILTER_BANK cldfbBank_bpf_Fx, - Word32 *workBuffer, - const Word16 timeIn_e, - const Word16 nTimeSlots, - const Word16 nTimeSlotsTotal, - const Word16 nBandsTotal, - CLDFB_SCALE_FACTOR *cldfb_scale -); - -void bass_psfilter_fx( - const Word16 Opt_AMR_WB, /* i : AMR-WB IO flag */ - Word16 synth_in_fx[], /* i : input synthesis (at 16kHz) */ - const Word16 L_frame, /* i : length of the last frame */ - Word16 pitch_buf_fx[], /* i : pitch for every subfr [0,1,2,3] */ - Word16 old_syn_fx[], /* i/o: NBPSF_PIT_MAX */ - Word16 *mem_deemph_err, /* o : Error deemphasis memory */ - Word16 *lp_ener, /* o : long_term error signal energy */ - const Word16 bpf_off, /* i : do not use BPF when set to 1 */ - Word16 v_stab_fx, /* i : stability factor */ - Word16 *v_stab_smooth_fx, /* i/o: smoothed stability factor */ - Word16 *mem_mean_pit, /* i/o: average pitch memory */ - Word16 *Track_on_hist, /* i/o: History of half frame usage */ - Word16 *vibrato_hist, /* i/o: History of frames declared as vibrato*/ - Word16 *psf_att, /* i/o: Post filter attenuation factor */ - const Word16 coder_type, /* i : coder_type */ - Word16 Q_syn, - Word16 bpf_noise_buf[] /* o : BPF error signal (at int_fs) */ -); - -void speech_music_classif_fx( - Encoder_State_fx *st, /* i/o: state structure */ - Word16 *sp_aud_decision0, - Word16 *sp_aud_decision1, /* o : 1st stage speech/music */ - Word16 *sp_aud_decision2, /* o : 2nd stage speech/music */ - const Word16 *new_inp, /* i : new input signal */ - const Word16 *inp, /* i : input signal to locate attach position */ - const Word16 vad_flag, - const Word16 localVAD, - const Word16 localVAD_HE_SAD, /* i : HE-SAD flag without hangover */ - const Word16 pitch[3], /* i : open-loop pitch estimate in three subframes */ - const Word16 voicing[3], /* i : voicing estimate in three subframes Q15 */ - const Word16 lsp_new[M], /* i : LSPs in current frame Q15 */ - const Word16 cor_map_sum, /* i : correlation map sum (from multi-harmonic anal.)Q8*/ - const Word32 epsP[M+1], /* i : LP prediciton error Q_esp*/ - const Word32 PS[], /* i : energy spectrum Q_new+QSCALE*/ - const Word16 Etot, /* i : total frame energy Q8 */ - const Word16 old_cor, /* i : max correlation from previous frame Q15 */ - Word16 *coder_type, /* i/o: coding type */ - Word16 *attack_flag, /* o : flag to indicate if attack is to be treated by TC or GSC */ - Word16 non_sta, /* i : unbound non-stationarity for sp/mus classifier */ - Word16 relE, /* i : relative frame energy */ - Word16 Q_esp, /* i : scaling of esP */ - Word16 Q_inp /* i : scaling of input */ - ,Word16 *high_lpn_flag_ptr /* o : noise log prob flag for NOISE_EST */ - ,Word16 flag_spitch /* i: flag to indicate very short stable pitch */ -); - -Word32 sub_lsp2lsf_fx( - const Word16 lsp_i /* i : lsp[m] (range: -1<=val<1) Q15*/ -); -Word16 lsp_convert_poly_fx( - Word16 w[], /* i/o: LSP or ISP parameters */ - const Word16 L_frame, /* i : flag for up or down conversion */ - const Word16 Opt_AMRWB /* i : flag for the AMR-WB IO mode */ -); - -void StableHighPitchDetect_fx( - Word16 *flag_spitch, /* o : flag to indicate very short stable pitch */ - Word16 pitch[], /* i/o: OL pitch buffer */ - const Word16 voicing[], /* i : OL pitch gains */ - const Word16 wsp[], /* i : weighted speech */ - const Word16 localVAD, - Word16 *voicing_sm, /* i/o: smoothed open-loop pitch gains */ - Word16 *voicing0_sm, /* i/o: smoothed high pitch gains */ - Word16 *LF_EnergyRatio_sm, /* i/o: smoothed [0, 300Hz] relative peak energy*/ - Word16 *predecision_flag, /* i/o: predecision flag */ - Word32 *diff_sm, /* i/o: smoothed pitch frequency difference */ - Word32 *energy_sm , /* i/o: smoothed energy around pitch frequency */ - Word16 Q_new, - Word16 EspecdB[] -); - -void Es_pred_enc_fx( - Word16 *Es_pred, /* o : predicited scaled innovation energy Q8 */ - Word16 *indice, /* o : indice of quantization */ - const Word16 L_frame, /* i : length of the frame */ - const Word16 *res, /* i : residual signal */ - const Word16 *voicing, /* i : normalized correlation in three 1/2frames */ - const Word16 nb_bits, /* i : allocated number of bits */ - const Word16 no_ltp, /* i : no_ltp flag */ - Word16 Q_new /* i : Scaling in speech Q0 */ -); - -void calc_residu_fx( - Encoder_State_fx *st, /* i/o: state structure */ - const Word16 *speech, /* i : weighted speech signal */ - Word16 *res, /* o : residual signal */ - const Word16 *p_Aq, /* i : quantized LP filter coefficients */ - const Word16 vad_hover_flag -); -void updt_IO_switch_enc_fx( - Encoder_State_fx *st, /* i/o: state structure */ - const Word16 input_frame /* i : input frame length */ -); -/*-------------------------------------------------------------------* - * pre_proc() - * - * Pre-processing (spectral analysis, LP analysis, VAD, OL pitch calculation, coder mode selection, ...) - *--------------------------------------------------------------------*/ - -void pre_proc_fx( - Encoder_State_fx *st, /* i/o: encoder state structure */ - const Word16 input_frame, /* i : frame length */ - const Word16 signal_in[], /* i : new samples */ - Word16 old_inp_12k8[], /* i/o: buffer of old input signal */ - Word16 old_inp_16k[], /* i/o: buffer of old input signal @ 16kHz */ - Word16 **inp, /* o : ptr. to inp. signal in the current frame */ - Word16 *sp_aud_decision1, /* o : 1st stage speech/music classification */ - Word16 *sp_aud_decision2, /* o : 2nd stage speech/music classification */ - Word32 fr_bands[2*NB_BANDS], /* o : energy in frequency bands */ - Word16 *vad_flag, - Word16 *localVAD, - Word16 *Etot, /* o : total energy */ - Word32 *ener, /* o : residual energy from Levinson-Durbin */ - Word16 pitch[3], /* o : open-loop pitch values for quantiz. */ - Word16 voicing[3], /* o : OL maximum normalized correlation */ - Word16 A[NB_SUBFR16k*(M+1)], /* o : A(z) unquantized for the 4 subframes */ - Word16 Aw[NB_SUBFR16k*(M+1)], /* o : weighted A(z) unquantized for subframes */ - Word16 epsP_h[M+1], /* o : LP prediction errors */ - Word16 epsP_l[M+1], /* o : LP prediction errors */ - Word32 epsP[M+1], /* o : LP prediction errors */ - Word16 lsp_new[M], /* o : LSPs at the end of the frame */ - Word16 lsp_mid[M], /* o : LSPs in the middle of the frame */ - Word16 *coder_type, /* o : coder type */ - Word16 *sharpFlag, /* o : formant sharpening flag */ - Word16 *vad_hover_flag, - Word16 *attack_flag, /* o : flag signalling attack encoded by AC mode (GSC) */ - Word16 *new_inp_resamp16k, /* o : new input signal @16kHz, non pre-emphasised, used by the WB TBE/BWE */ - Word16 *Voicing_flag, /* o : voicing flag for HQ FEC */ - - Word32 realBuffer[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX], /* i/o : cldfb real buffer */ - Word32 imagBuffer[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX], /* i/o : cldfb imag buffer */ - CLDFB_SCALE_FACTOR *cldfbScale, /* o : cldfb scale */ - Word16 *old_exc, /* i/o: static excitation memory */ - Word16 *hq_core_type, /* o : HQ core type */ - Word16 *Q_new, - Word16 *shift, - Word16 *Q_r -); - -Word16 mdct_classifier_fx( /* o: MDCT A/B decision */ - const Word16 *Y, /* i: re[0], re[1], ..., re[n/2], im[n/2 - 1], im[n/2 - 2], ..., im[1] */ - Encoder_State_fx *st_fx, /* i/o: Encoder state variable */ - Word16 vadflag - ,Word32 *cldfbBuf_Ener - ,Word16 enerBuffer_exp -); - -void floating_point_add( - Word32 *mx, /* io: mantissa of the addend Q31 */ - Word16 *ex, /* io: exponent of the addend Q0 */ - const Word32 my, /* i: mantissa of the adder Q31 */ - const Word16 ey /* i: exponent of the adder Q0 */ -); - -void MDCT_selector( - Encoder_State_fx *st /* i/o: Encoder State */ - , Word16 sp_floor /* i : Noise floor estimate Q7 */ - , Word16 Etot /* i : Total energy Q8 */ - , Word16 cor_map_sum /* i : harmonicity factor Q8 */ - , const Word16 voicing[] /* i : voicing factors Q15*/ - , const Word32 enerBuffer[] /* i : CLDFB buffers */ - , Word16 enerBuffer_exp /* i : exponent of enerBuffer */ - , Word16 vadflag -); - -void MDCT_selector_reset( - Encoder_State_fx *st); /* i/o: Encoder State */ - -Word16 minimum_fx( /* o : index of the minimum value in the input vector */ - const Word16 *vec_fx, /* i : input vector */ - const Word16 lvec_fx, /* i : length of input vector */ - Word16 *min_fx /* o : minimum value in the input vector */ -); -Word16 minimum_32_fx( /* o : index of the minimum value in the input vector */ - const Word32 *vec_fx, /* i : input vector */ - const Word16 lvec_fx, /* i : length of input vector */ - Word32 *min_fx /* o : minimum value in the input vector */ -); -Word16 maximum_32_fx( /* o : index of the maximum value in the input vector */ - const Word32 *vec, /* i : input vector */ - const Word16 lvec, /* i : length of input vector */ - Word32 *max /* o : maximum value in the input vector */ -); -Word16 maximum_fx( /* o : index of the maximum value in the input vector */ - const Word16 *vec_fx, /* i : input vector */ - const Word16 lvec_fx, /* i : length of input vector */ - Word16 *max_fx /* o : maximum value in the input vector */ -); -Word16 Exp32Array( - const Word16 n, /* (i): Array size */ - const Word32 *sx /* (i): Data array */ -); -Word16 Exp16Array( - const Word16 n, /* (i): Array size */ - const Word16 *sx /* (i): Data array */ -); - -Word32 sum16_32_fx( /* o : sum of all vector elements Qx*/ - const Word16 *vec, /* i : input vector Qx*/ - const Word16 lvec /* i : length of input vector */ -); -Word32 dot_product_mat_fx( /* o : the dot product x'*A*x */ - const Word16 *x, /* i : vector x Q15 */ - const Word32 *A, /* i : matrix A Q0*/ - const Word16 m /* i : vector & matrix size */ - -); - -Word16 std_fx( /* o: standard deviation */ - const Word16 *x, /* i: input vector */ - const Word16 len /* i: length of the input vector */ -); - -Word16 stab_est_fx( - Word16 etot, /* i : Total energy of the current frame */ - Word16 *lt_diff_etot, /* i/o : Long term total energy variation */ - Word16 *mem_etot, /* i/o : Total energy memory */ - Word16 *nb_thr_3, /* i/o : Number of consecutives frames of level 3 */ - Word16 *nb_thr_1, /* i/o : Number of consecutives frames of level 1 */ - Word16 *thresh, /* i/o : Detection thresold */ - Word16 *last_music_flag,/* i/o : Previous music detection ouptut */ - Word16 vad_flag -); -Word16 var_fx( /* o: variance of vector Qx*/ - const Word16 *x, /* i: input vector Qx*/ - const Word16 Qx, - const Word16 len /* i: length of inputvector */ -); -void conv_fx( - const Word16 x[], /* i : input vector Q_new*/ - const Word16 h[], /* i : impulse response (or second input vector) Q(15)*/ - Word16 y[], /* o : output vetor (result of convolution) 12 bits*/ - const Word16 L /* i : vector size */ -); -void norm_corr_fx( - const Word16 exc[], /* i : excitation buffer Q_new*/ - const Word16 xn[], /* i : target signal Q_new-1+shift*/ - const Word16 h[], /* i : weighted synthesis filter impulse response Q(14+shift)*/ - const Word16 t_min, /* i : minimum value of searched range */ - const Word16 t_max, /* i : maximum value of searched range */ - Word16 ncorr[], /* o : normalized correlation Q15 */ - const Word16 L_subfr /* i : subframe size */ -); -void pit_Q_enc_fx( - Encoder_State_fx *st_fx, /* i/o: encoder state structure */ - const Word16 Opt_AMR_WB, /* i : flag indicating AMR-WB IO mode */ - const Word16 nBits, /* i : # of Q bits */ - const Word16 delta, /* i : Half the CL searched interval */ - const Word16 pit_flag, /* i : absolute(0) or delta(1) pitch Q */ - const Word16 limit_flag, /* i : restrained(0) or extended(1) Q limits */ - const Word16 T0, /* i : integer pitch lag */ - const Word16 T0_frac, /* i : pitch fraction */ - Word16 *T0_min, /* i/o: delta search min */ - Word16 *T0_max /* o : delta search max */ -); -/*void pit16k_Q_enc_fx( */ -/*Encoder_State_fx *st_fx, */ /* i/o: encoder state structure */ -/* const Word16 nBits, */ /* i : # of Q bits */ -/* const Word16 i_subfr, */ /* i : subframe index */ -/* const Word16 limit_flag, */ /* i : restrained(0) or extended(1) Q limits */ -/* const Word16 T0, */ /* i : integer pitch lag */ -/* const Word16 T0_frac, */ /* i : pitch fraction */ -/* Word16 *T0_min, */ /* i/o: delta search min */ -/* Word16 *T0_max */ /* o : delta search max */ -/*); */ - -Word16 pitch_fr4_fx( /* o : chosen integer pitch lag */ - const Word16 exc[], /* i : excitation buffer Q_new*/ - const Word16 xn[], /* i : target signal Q_new-1+shift*/ - const Word16 h[], /* i : weighted synthesis filter impulse response Q(14+shift)*/ - const Word16 t0_min, /* i : minimum value in the searched range. Q0*/ - const Word16 t0_max, /* i : maximum value in the searched range. Q0*/ - Word16 *pit_frac, /* o : chosen fraction (0, 1, 2 or 3) */ - const Word16 i_subfr, /* i : flag to first subframe */ - const Word16 limit_flag, /* i : flag for limits (0=restrained, 1=extended) */ - const Word16 t0_fr2, /* i : minimum value for resolution 1/2 */ - const Word16 t0_fr1, /* i : minimum value for resolution 1 */ - const Word16 L_frame, /* i : length of the frame */ - const Word16 L_subfr /* i : size of subframe */ -); - -Word32 var_fx_32( /* o: variance of vector Qx+16*/ - const Word16 *x, /* i: input vector Qx*/ - const Word16 Qx, - const Word16 len /* i: length of inputvector */ -); - -Word16 sum16_fx( /* o : sum of all vector elements Qx*/ - const Word16 *vec, /* i : input vector Qx*/ - const Word16 lvec /* i : length of input vector */ -); - -Word32 sum32_fx( /* o : sum of all vector elements Qx*/ - const Word32 *vec, /* i : input vector Qx*/ - const Word16 lvec /* i : length of input vector */ -); - -Word32 Mean32( /* o : mean of the elements of the vector */ - const Word32 in[], /* i : input vector */ - const Word16 L /* i : length of input vector */ -); - -void Deemph2( - Word16 x[], /* i/o: input signal overwritten by the output Qx/Qx-1 */ - const Word16 mu, /* i : deemphasis factor Q15 */ - const Word16 L, /* i : vector size Q0 */ - Word16 *mem /* i/o: memory (y[-1]) Qx-1 */ -); - -void deemph_fx( - Word16 *signal, /* i/o: signal Qx */ - const Word16 mu, /* i : deemphasis factor Q15 */ - const Word16 L, /* i : vector size Q0 */ - Word16 *mem /* i/o: memory (y[-1]) Qx */ -); -Word16 deindex_lvq_fx( - Word16 *index, /* i : index to be decoded, as an array of 3 short */ - Word16 *x_lvq, /* o : decoded codevector Q(x2.56)*/ - Word16 mode, /* i : LVQ coding mode (select scales & no_lead ), or idx_cv */ - Word16 sf_flag, /* i : safety net flag */ - Word16 no_bits, /* i : number of bits for lattice */ - Word32 *p_offset_scale1, /* i : offset for first subvector */ - Word32 *p_offset_scale2, /* i : offset for the second subvector */ - Word16 *p_no_scales -); -void Syn_filt_s( - const Word16 shift, /* i : scaling to apply Q0 */ - const Word16 a[], /* i : LP filter coefficients Q12 */ - const Word16 m, /* i : order of LP filter Q0 */ - const Word16 x[], /* i : input signal Qx */ - Word16 y[], /* o : output signal Qx-s */ - const Word16 lg, /* i : size of filtering Q0 */ - Word16 mem[], /* i/o: memory associated with this filtering. Qx-s */ - const Word16 update /* i : 0=no update, 1=update of memory. Q0 */ -); -void hp400_12k8_fx( - Word16 signal[], /* i/o: input signal / output is divided by 16 */ - const Word16 lg, /* i : lenght of signal */ - Word16 mem[] /* i/o: filter memory [6] */ -); -Word16 dot_prod_satcontr(const Word16 *x, const Word16 *y, Word16 qx, Word16 qy, Word16 *qo, Word16 len); -void syn_12k8_fx( - Word16 L_frame, - const Word16 *Aq, /* i : LP filter coefficients Q12 */ - const Word16 *exc, /* i : input signal Q_exc */ - Word16 *synth, /* o : output signal Q_syn */ - Word16 *mem, /* i/o: initial filter states Q_syn */ - const Word16 update_m, /* i : update memory flag: 0 --> no memory update Q0 */ - /* 1 --> update of memory */ - const Word16 Q_exc, /* i : Excitation scaling Q0 */ - const Word16 Q_syn /* i : Synthesis scaling Q0 */ -); -void updt_dec_fx( - Decoder_State_fx *st_fx, /* i/o: state structure */ - const Word16 L_frame, /* i : length of the frame */ - const Word16 coder_type, /* i : coding type */ - const Word16 *old_exc_fx, /* i : buffer of excitation */ - const Word16 *pitch_buf_fx, /* i : floating pitch values for each subframe */ - const Word16 Es_pred, /* i : predicited scaled innovation energy */ - const Word16 *Aq, /* i : A(z) quantized for all subframes */ - const Word16 *lsf_new_fx, /* i : current frame LSF vector */ - const Word16 *lsp_new_fx, /* i : current frame LSP vector */ - const Word16 voice_factors[], /* i : voicing factors */ - const Word16 *old_bwe_exc_fx /* i : buffer of excitation */ - , const Word16 *gain_buf /*Q14*/ -); -Word32 Interpol_lc_fx( /* o : interpolated value Qx+16 */ - const Word16 *x, /* i : input vector Q0 */ - const Word16 *win, /* i : interpolation window Q14 */ - const Word16 frac, /* i : fraction (0..up_samp) Q0 */ - const Word16 up_samp, /* i : upsampling factor Q0 */ - const Word16 nb_coef /* i : number of coefficients Q0 */ -); - -Word16 corr_xy1_fx( /* o : pitch gain (0..GAIN_PIT_MAX) */ - const Word16 xn_1[], /* i : target signal */ - const Word16 y1_1[], /* i : filtered adaptive codebook excitation */ - Word16 g_corr[], /* o : correlations and -2 */ - const Word16 L_subfr, /* i : vector length */ - const Word16 norm_flag /* i : flag for constraining pitch contribution */ -); - -void updt_tar_fx( - const Word16 *x, /* i : old target (for pitch search) */ - Word16 *x2, /* o : new target (for codebook search) */ - const Word16 *y, /* i : filtered adaptive codebook vector */ - const Word16 gain, /* i : adaptive codebook gain */ - const Word16 L /* i : subframe size */ -); -void updt_tar_HR_fx( - const Word16 *x, /* i : old target (for pitch search) */ - Word16 *x2, /* o : new target (for codebook search) */ - const Word16 *y, /* i : filtered adaptive codebook vector */ - const Word16 gain, /* i : adaptive codebook gain */ - const Word16 Qx, /* i : Scaling factor to adapt output to input */ - const Word16 L /* i : subframe size */ -); - -Word16 lp_filt_exc_enc_fx( - const Word16 codec_mode, /* i : MODE1 or MODE2 Q0 */ - const Word32 core_brate, /* i : core bitrate Q0 */ - const Word16 Opt_AMR_WB, /* i : flag indicating AMR-WB IO mode Q0 */ - const Word16 coder_type, /* i : coding type Q0 */ - const Word16 i_subfr, /* i : subframe index Q0 */ - Word16 *exc, /* i/o: pointer to excitation signal frame Q_new */ - const Word16 *h1, /* i : weighted filter input response Q(14+shift) */ - const Word16 *xn, /* i : target vector Q_new-1+shift */ - Word16 *y1, /* o : zero-memory filtered adaptive excitation Q_new-1+shift */ - Word16 *xn2, /* o : target vector for innovation search Q_new-1+shift */ - const Word16 L_subfr, /* i : length of vectors for gain quantization Q0 */ - const Word16 L_frame, /* i : frame size Q0 */ - Word16 *g_corr, /* o : ACELP correlation values mant/exp */ - const Word16 clip_gain, /* i : adaptive gain clipping flag Q0 */ - Word16 *gain_pit, /* o : adaptive excitation gain Q14 */ - Word16 *lp_flag /* i/o: mode selection Q0 */ -); - -Word16 Interpol_4( /* o : interpolated value */ - Word16 * x, /* i : input vector */ - Word16 frac /* i : fraction (-4..+3) */ -); - -void r_fft_fx_lc( - const Word16 *phs_tbl, /* i : Table of phase */ - const Word16 SIZE, /* i : Size of the FFT */ - const Word16 SIZE2, /* i : Size / 2 */ - const Word16 NUM_STAGE, /* i : Number of stage */ - const Word16 *in_ptr, /* i : coeffients in the order re[0], re[1], ... re[n/2], im[1], im[2], ..., im[n/2-1] */ - Word16 *out_ptr, /* o : coeffients in the order re[0], re[1], ... re[n/2], im[1], im[2], ..., im[n/2-1] */ - const Word16 isign /* i : 1=fft, otherwize it's ifft */ -); - -void hf_synth_fx( - const Word32 core_brate, /* i : core bitrate */ - const Word16 output_frame, /* i : output frame length */ - const Word16 *Aq, /* i : quantized Az */ - const Word16 *exc, /* i : excitation at 12.8 kHz */ - Word16 *synth, /* i : 12.8kHz synthesis signal */ - Word16 *synth16k, /* o : 16kHz synthesis signal */ - Word16 *seed2, /* i/o: random seed for HF noise gen */ - Word16 *mem_hp400, /* i/o: memory of hp 400 Hz filter */ - Word16 *mem_syn_hf, /* i/o: HF synthesis memory */ - Word16 *mem_hf, /* i/o: HF band-pass filter memory */ - const Word16 Q_exc, /* i : excitation scaling */ - const Word16 Q_syn2, /* i : synthesis scaling */ - Word16 *delay_syn_hf, /*i/o: HF synthesis memory */ - Word16 *memExp1, /* o : HF excitation exponent */ - Word16 *mem_hp_interp, /* i/o: interpol. memory */ - const Word16 extl, /* i : flag indicating BWE */ - const Word16 CNG_mode /* i : CNG_mode */ -); -void acelp_core_dec_fx( - Decoder_State_fx *st_fx, /* i/o: decoder state structure */ - Word16 synth_out[], /* o : synthesis */ - Word32 bwe_exc_extended[], /* i/o: bandwidth extended excitation */ - Word16 *voice_factors, /* o : voicing factors */ - Word16 old_syn_12k8_16k[], /* o : intermediate ACELP synthesis at 12.8kHz or 16kHz to be used by SWB BWE */ - Word16 coder_type_fx, /* i : coder type */ - Word16 sharpFlag, - Word16 pitch_buf_fx[NB_SUBFR16k], /* o : floating pitch for each subframe */ - Word16 *unbits /* o : number of unused bits */ - ,Word16 *sid_bw /* o : 0-NB/WB, 1-SWB SID */ -); -void Inac_swtch_ematch_fx( - Word16 exc2[], /* i/o: CELP/GSC excitation buffer Q_exc*/ - Word16 dct_exc_tmp[], /* i : GSC excitation in DCT domain */ - Word16 lt_ener_per_band[], /* i/o: Long term energy per band Q12 */ - const Word16 coder_type, /* i : Coding mode */ - const Word16 L_frame, /* i : Frame lenght */ - const Word32 core_brate, /* i : Core bit rate */ - const Word16 Q_exc /* i : input and output format of exc2 */ - ,const Word16 bfi /* i : frame lost indicator */ - ,const short last_core, /* i : Last core used */ - const short last_codec_mode /* i : Last codec mode */ -); -void stat_noise_uv_enc_fx( - Encoder_State_fx *st_fx, /* i/o: state structure */ - const Word16 coder_type, /* i : coding type */ - const Word32 *LepsP, /* i : LP prediction errors */ - Word16 *isp_new, /* i : immittance spectral pairs at 4th sfr */ - Word16 *isp_mid, /* i : immittance spectral pairs at 2nd sfr */ - Word16 *Aq, /* i : A(z) quantized for the 4 subframes */ - Word16 *exc2, /* i/o: excitation buffer */ - Word16 Q_new -); - -void updt_enc_fx( - Encoder_State_fx *st, /* i/o: state structure */ - const Word16 L_frame, /* i : length of the frame */ - const Word16 coder_type, /* i : speech coder type */ - const Word16 *old_exc, /* i : buffer of excitation */ - const Word16 *pitch_buf, /* i : floating pitch for each subframe */ - const Word16 Es_pred, /* i : predicited scaled innovation energy */ - const Word16 *Aq, /* i : A(z) quantized for all subframes */ - const Word16 *lsf_new, /* i : current frame LSF vector */ - const Word16 *lsp_new, /* i : current frame LSP vector */ - const Word16 *old_bwe_exc /* i : buffer of excitation */ -); -void FEC_encode_fx( - Encoder_State_fx *st_fx, /* i/o: encoder state structure */ - const Word16 *synth, /* i : pointer to synthesized speech for E computation */ - const Word16 coder_type, /* i : type of coder */ - Word16 clas, /* i : signal clas for current frame */ - const Word16 *fpit, /* i : close loop fractional pitch buffer */ - const Word16 *res, /* i : LP residual signal frame */ - Word16 *last_pulse_pos, /* i/o: Position of the last pulse */ - const Word16 L_frame, /* i : Frame length */ - const Word32 total_brate, /* i : total codec bitrate */ - const Word32 core_brate, /* i : total codec bitrate */ - const Word16 Q_new, /* i : input scaling */ - const Word16 shift /* i : scaling to get 12bits */ -); -void Ener_per_band_comp_fx( - const Word16 exc_diff[], /* i : target signal Q_exc_diff */ - Word16 y_gain4[], /* o : Energy per band to quantize Q12 */ - const Word16 Q_exc_diff, - const Word16 Mband, /* i : Max band */ - const Word16 Eflag -); -void acelp_core_enc_fx( - Encoder_State_fx *st_fx, /* i/o: encoder state structure */ - LPD_state *mem, /* i/o: acelp memories */ - const Word16 inp_fx[], /* i : input signal of the current frame */ - const Word16 vad_flag_fx, - const Word32 ener_fx, /* i : residual energy from Levinson-Durbin*/ - const Word16 pitch[3], /* i : open-loop pitch values for quantiz. */ - const Word16 voicing_fx[3], /* i : Open-loop pitch gains */ - Word16 A_fx[NB_SUBFR16k*(M+1)], /* i : A(z) unquantized for the 4 subframes*/ - Word16 Aw_fx[NB_SUBFR16k*(M+1)], /* i : weighted A(z) unquant. for subframes*/ - const Word16 epsP_h_fx[M+1], /* i : LP prediction errors */ - const Word16 epsP_l_fx[M+1], /* i : LP prediction errors */ - Word16 lsp_new_fx[M], /* i : LSPs at the end of the frame */ - Word16 lsp_mid_fx[M], /* i : LSPs in the middle of the frame */ - Word16 coder_type_fx, /* i : coding type */ - const Word16 sharpFlag_fx, /* i : formant sharpening flag */ - Word16 vad_hover_flag_fx, - const Word16 gsc_attack_flag_fx, /* i : flag signalling attack encoded by AC mode (GSC) */ - Word32 bwe_exc_extended_fx[], /* i/o: bandwidth extended excitation */ - Word16 *voice_factors_fx, /* o : voicing factors */ - Word16 old_syn_12k8_16k_fx[], /* o : intermediate ACELP synthesis at 12.8kHz or 16kHz to be used by SWB BWE */ - Word16 pitch_buf_fx[NB_SUBFR16k], /* o : floating pitch for each subframe */ - Word16 *unbits_fx, /* o : number of unused bits */ - const Word16 Q_new, - const Word16 shift -); - -#define EDCT_FACTOR_SCALE 2 -void edct_fx( - const Word32 *x, /* i : input signal Qq */ - Word32 *y, /* o : output transform Qq */ - Word16 length, /* i : length */ - Word16 *q /* i : Q value of input signal */ -); - -void edst_fx( - const Word32 *x, /* i : input signal Qq */ - Word32 *y, /* o : output transform Qq */ - Word16 length, /* i : length */ - Word16 *q /* i : Q value of input signal */ -); - -void DoRTFTn_fx( - Word32 *x, /* i/o : real part of input and output data */ - Word32 *y, /* i/o : imaginary part of input and output data */ - const Word16 n /* i : size of the FFT up to 1024 */ -); - -void edct2_fx( - Word16 n, - Word16 isgn, - Word16 *in, - Word32 *a, - Word16 *q, - const Word16 *ip, - const Word16 *w -); -void DoRTFT160_16fx( - Word16 x[], /* i/o : real part of input and output data */ - Word16 y[] /* i/o : imaginary part of input and output data */ -); -void DoRTFT320_16fx( - Word16 *x, /* i/o : real part of input and output data */ - Word16 *y /* i/o : imaginary part of input and output data */ -); -void DoRTFT128_16fx( - Word16 *x, /* i/o : real part of input and output data Q(Qx+Q_edct)*/ - Word16 *y /* i/o : imaginary part of input and output data Q(Qx+Q_edct)*/ -); -void edct_16fx( - const Word16 *x, /* i : input signal Qx */ - Word16 *y, /* o : output transform Qx */ - Word16 length, /* i : length */ - Word16 bh /* bit-headroom */ -); -void highband_exc_dct_in_fx( - const Word32 core_brate, /* i : core bitrate */ - const Word16 *mfreq_bindiv_loc, /* i : bin per bands tables */ - Word16 last_bin, /* i : last bin of bit allocation */ - Word16 Diff_len, /* i : number of bin before cut-off frequency */ - Word16 noise_lev, /* i : pulses dynamic */ - Word16 pit_band_idx, /* i : bin position of the cut-off frequency */ - Word16 *exc_diffQ, /* i : frequency coefficients of per band */ - Word16 *seed_tcx, /* i : Seed for noise */ - Word16 *Ener_per_bd_iQ, /* i : Quantized energy of targeted vector */ - Word16 nb_subfr, /* i : Number of subframe considered */ - Word16 *exc_dct_in, /* o : dct of residual signal */ - Word16 last_coder_type, /* i : coding type of last frame */ - Word16 *bitallocation_band, /* i : bit allocation flag of each band */ - Word16 *lsf_new, /* i : LSFs at the end of the frame */ - Word16 *last_exc_dct_in, /* i : dct of residual signal of last frame */ - Word16 *last_ener, /* i : frequency energy of last frame */ - Word16 *last_bitallocation_band, /* i : bit allocation flag of each band of last frame */ - Word16 *bitallocation_exc, /* i : flag of decoded coefficients */ - Word16 bfi, /* i : bad frame indicator */ - const Word16 coder_type, /* i : coder type */ - Word16 bwidth, - Word16 *exc_wo_nf , /* o : temporal excitation (in f domain) without noisefill */ - Word16 Qexc_diffQ, - Word16 Q_exc, - const Word16 GSC_noisy_speech - ,Word16 *lt_ener_per_band_fx /* i/o: Average per band energy */ -); - - -void long_enr_fx( - Encoder_State_fx *st_fx, /* i/o: state structure */ - const Word16 Etot, /* i : total channel E (see lib_enc\analy_sp.c) */ - const Word16 localVAD_HE_SAD, /* i : HE-SAD flag without hangover */ - Word16 high_lpn_flag -); - -Word16 correlation_shift_fx( /* o : noise dependent voicing correction Q15 */ - Word16 totalNoise_fx /* i/o: noise estimate over all critical bands Q8 */ -); - -void analy_lp_fx( - const Word16 speech[], /* i : pointer to the speech frame */ - const Word16 L_frame, /* i : length of the frame */ - const Word16 L_look, /* i : look-ahead */ - Word32 *ener, /* o : residual energy from Levinson-Durbin */ - Word16 A[], /* o : A(z) filter coefficients */ - Word16 epsP_h[], /* o : LP analysis residual energies for each iteration */ - Word16 epsP_l[], /* o : LP analysis residual energies for each iteration */ - Word16 lsp_new[], /* o : current frame LSPs */ - Word16 lsp_mid[], /* o : current mid-frame LSPs */ - Word16 lsp_old[], /* i/o: previous frame unquantized LSPs */ - const Word16 Top[2], /* i : open loop pitch lag */ - const Word16 Tnc[2], /* i : open loop pitch gain */ - const Word32 Core_sr, /* i : Internal core sampling rate */ - Word16 Q_new, - Word16 *Q_r -); - -void analy_lp_AMR_WB_fx( - const Word16 speech[], /* i : pointer to the speech frame */ - Word32 *ener, /* o : residual energy from Levinson-Durbin */ - Word16 A[], /* o : A(z) filter coefficients */ - Word16 epsP_h[], /* o : LP analysis residual energies for each iteration */ - Word16 epsP_l[], /* o : LP analysis residual energies for each iteration */ - Word16 isp_new[], /* o : current frame ISPs */ - Word16 isp_old[], /* i/o: previous frame unquantized ISPs */ - Word16 isf_new[], /* o : current frame ISPs */ - Word16 Top, /* i : open loop pitch lag */ - Word16 Tnc, /* i : open loop pitch gain */ - Word16 Q_new, - Word16 *Q_r -); - -void a2rc_fx(const Word16 *a, Word16 *refl,Word16 lpcorder); - -Word32 invert_dp(Word40 Linput, Word16 n, Word16 *Qout, Word16 wb_mode_bit); - -void vad_param_updt_fx( - Encoder_State_fx *st_fx, /* i/o: state structure */ - Word16 pitch[3], /* i : open loop pitch lag for each half-frame Q0*/ - Word16 voicing[3], /* i : maximum normalized correlation for each half-frame Q15*/ - Word16 corr_shift, /* i : correlation shift Q15*/ - Word16 vad_flag, /* i : vad flag Q0*/ - const Word16 Az[] /* i: a coeffs */ -); - -void pitch_ol2_fx( - const Word16 pit_min, /* i : minimum pitch value (20 or 29) */ - const Word16 pitch_ol, /* i : pitch to be improved */ - Word16 *pitch_fr_fx, /* o : adjusted 1/4 fractional pitch */ /*Q7 */ - Word16 *voicing_fr_fx, /* o : adjusted 1/4 fractional voicing */ /*Q15 */ - const Word16 pos, /* i : position in frame where to calculate the improv. */ - const Word16 *wsp_fx, /* i : weighted speech for current frame and look-ahead */ /*Q_new-1+shift*/ - const Word16 delta /* i : delta for pitch search (2 or 7) */ -); - -void pitch_ol_fx( - Word16 pitch[3], /* o : open loop pitch lag for each half-frame in range [29,231] Q0 */ - Word16 voicing[3], /* o : maximum normalized correlation for each half-frame in [0,1.0[ Q15 */ - Word16 *old_pitch, /* i/o: pitch of the 2nd half-frame of previous frame (i.e. pitch[1]) Q0 */ - Word16 *old_corr, /* i/o: correlation of old_pitch (i.e. voicing[1] or corr_mean) Q15 */ - Word16 corr_shift, /* i : normalized correlation correction Q15 */ - Word16 *old_thres, /* i/o: maximum correlation weighting with respect to past frame pitch Q15 */ - Word16 *delta_pit, /* i/o: old pitch extrapolation correction in range [-14,+14] Q0 */ - Word16 *st_old_wsp2, /* i/o: weighted speech memory qwsp */ - const Word16 *wsp, /* i : weighted speech for current frame and look-ahead qwsp */ - Word16 mem_decim2[3], /* i/o: wsp decimation filter memory qwsp */ - const Word16 relE, /* i : relative frame energy Q8 */ - const Word16 last_class, /* i : frame classification of last frame */ - const Word16 bwidth, /* i : bandwidth */ - const Word16 Opt_SC_VBR /* i : SC-VBR flag */ -); - -void Scale_wsp( - Word16 *wsp, /* i : Weigthed speech */ - Word16 *old_wsp_max, /* i : Last weigthed speech maximal valu */ - Word16 *shift, /* i/o: Scaling of current frame */ - Word16 *Q_exp, /* i/o: Differential scaling factor */ - Word16 *old_wsp_shift, /* i/o: Last wsp scaling */ - Word16 *old_wsp, /* i/o: Old weighted speech buffer */ - Word16 *mem_decim2, /* i/o: Decimation buffer */ - Word16 *old_wsp12k8, /* i/o: wsp memory @ 12.8 kHz used in pitol2 */ - const Word16 Len_p_look /* i : L_frame + look ahead */ -); - -Word16 multi_harm_fx( /* o : frame multi-harmonicity (1-harmonic, 0-not) */ - const Word16 Bin_E[], /* i : log-energy spectrum of the current frame Q7 */ - Word16 old_S[], /* i/o: prev. log-energy spectrum w. subtracted floor Q7 */ - Word16 cor_map_LT[], /* i/o: LT correlation map Q15 */ - Word16 *multi_harm_limit, /* i/o: multi harminic threshold Q9 */ - const Word32 total_brate, /* i : total bitrate Q0 */ - const Word16 bwidth, /* i : input signal bandwidth Q0 */ - Word16 *cor_strong_limit, /* i/o: HF correlation indicator Q0 */ - Word16 *st_mean_avr_dyn, /* i/o: long term average dynamic Q7 */ - Word16 *st_last_sw_dyn, /* i/o: last dynamic Q7 */ - Word16 *cor_map_sum /* Q8 */ - , Word16 *sp_floor /* o : noise floor estimate Q7 */ -); - -Word16 find_uv_fx( /* o : coding type */ - Encoder_State_fx *st_fx, /* i/o: encoder state structure */ - const Word16 *T_op_fr, /* i : pointer to adjusted fractional pitch (4 val.) Q6 */ - const Word16 *voicing_fr, /* i : refined correlation for each subframes Q15 */ - const Word16 *voicing, /* i : correlation for 3 half-frames Q15 */ - const Word16 *speech, /* i : pointer to speech signal for E computation Q_new*/ - const Word16 localVAD, /* i : vad without hangover */ - const Word32 *ee, /* i : lf/hf Energy ratio for present frame Q6 */ - const Word16 corr_shift, /* i : normalized correlation correction in noise Q15 */ - const Word16 relE, /* i : relative frame energy Q8 */ - const Word16 Etot, /* i : total energy Q8 */ - const Word32 hp_E[], /* i : energy in HF Q_new + Q_SCALE */ - const Word16 Q_new, - Word16 *flag_spitch, /* i/o: flag to indicate very short stable pitch and high correlation */ - const Word16 voicing_sm /* i : smoothed open-loop pitch gains */ - , const Word16 shift - , const Word16 last_core_orig /* i : original last core */ -); - -Word16 signal_clas_fx( /* o : classification for current frames */ - Encoder_State_fx *st, /* i/o: encoder state structure */ - Word16 *coder_type, /* i/o: coder type */ - const Word16 voicing[3], /* i : normalized correlation for 3 half-frames */ - const Word16 *speech, /* i : pointer to speech signal for E computation */ - const Word16 localVAD, /* i : vad without hangover */ - const Word16 pit[3], /* i : open loop pitch values for 3 half-frames */ - const Word32 *ee, /* i : lf/hf E ration for 2 half-frames */ - const Word16 relE, /* i : frame relative E to the long term average */ - const Word16 L_look , /* i : look-ahead */ - Word16 *uc_clas /* o : temporary classification used in music/speech class*/ -); - -void find_tilt_fx( - const Word32 fr_bands[], /* i : energy in frequency bands Q_new + Q_SCALE*/ - const Word32 bckr[], /* i : per band background noise energy estimate Q_new + Q_SCALE*/ - Word32 ee[2], /* o : lf/hf E ration for present frame Q6*/ - const Word16 pitch[3], /* i : open loop pitch values for 3 half-frames Q0*/ - const Word16 voicing[3], /* i : normalized correlation for 3 half-frames Q15*/ - const Word32 *lf_E, /* i : per bin energy for low frequencies Q_new + Q_SCALE - 2*/ - const Word16 corr_shift, /* i : normalized correlation correction Q15*/ - const Word16 bwidth, /* i : input signal bandwidth */ - const Word16 max_band, /* i : maximum critical band */ - Word32 hp_E[], /* o : energy in HF Q_new + Q_SCALE*/ - const Word16 codec_mode, /* i : MODE1 or MODE2 */ - const Word16 Q_new, /* i : scaling factor */ - Word32 *bckr_tilt_lt - ,Word16 Opt_vbr_mode -); -void synth_mem_updt2( - const Word16 L_frame, /* i : frame length */ - const Word16 last_L_frame, /* i : frame length */ - Word16 old_exc[], /* i/o: excitation buffer */ - Word16 mem_syn_r[], /* i/o: synthesis filter memory */ - Word16 mem_syn2[], /* o : synthesis filter memory for find_target */ - Word16 mem_syn[], /* o : synthesis filter memory for find_target */ - const Word16 dec /* i : flag for decoder indication */ -); -void swb_hr_noise_fill_fx( - const Word16 is_transient, /* i : transient flag */ - const Word16 spect_start, /* i : spectrum start point */ - const Word16 spect_end, /* i : spectrum end point */ - const Word16 tilt_wb, /* i : tilt of wideband signal */ - const Word16 pitch, /* i : pitch value */ - const Word16 nq[], /* i : AVQ nq index */ - Word16 Nsv, /* i : number of subband */ - Word16 *bwe_highrate_seed, /* i/o: seed of random noise */ - Word16 *t_audio, /* i/o: mdct spectrum */ - Word16 Q_audio -); -Word16 swb_bwe_dec_hr_fx( - Decoder_State_fx *st_fx, /* i/o: decoder state structure */ - const Word16 *syn_12k8_16k_fx, /* i : ACELP core synthesis @16kHz */ - const Word16 old_syn_exp, /* i : Exponent of core synthesis */ - Word16 *hb_synth_fx, /* o : SHB synthesis */ - const Word16 output_frame, /* i : frame length */ - const Word16 unbits, /* i : number of core unused bits */ - const Word16 pitch_buf[] /* i : pitch buffer */ -); -Word32 calc_tilt_bwe_fx( /* o : Tilt in Q24 */ - const Word16 *sp0, /* i : input signal */ - const Word16 exp, /* i : Exp of inp signal */ - const Word16 N /* i : signal length */ -); -void Inverse_Transform( - const Word32 *in_mdct, /* i : input MDCT vector */ - Word16 *Q, /* i/o: Q value of input */ - Word32 *out, /* o : output vector */ - const Word16 is_transient, /* i : transient flag */ - const Word16 L, /* i : output frame length */ - const Word16 L_inner /* i : length of the transform */ -); -void iedct_short_fx( - const Word32 *in, /* i : input vector */ - Word16 *Q, /* i/o: Q value of input */ - Word32 *out, /* o : output vector */ - const Word16 segment_length /* i : length */ -); - -void swb_bwe_enc_fx( - Encoder_State_fx *st_fx, /* i/o: encoder state structure */ - Word16 *old_input_12k8_fx, /* i : input signal @12.8kHz for SWB BWE */ - Word16 *old_input_16k_fx, /* i : input signal @16kHz for SWB BWE */ - const Word16 *old_syn_12k8_16k_fx, /* i : ACELP core synthesis at 12.8kHz or 16kHz */ - const Word16 *new_swb_speech_fx, /* i : original input signal at 32kHz */ - Word16 *shb_speech_fx, /* i : SHB target signal (6-14kHz) at 16kHz */ - const Word16 coder_type, /* i : coding type */ - Word16 Q_shb_speech, - Word16 Q_slb_speech -); -void wb_bwe_enc_fx( - Encoder_State_fx *st_fx, /* i/o: encoder state structure */ - const Word16 *new_wb_speech_fx, /* i : original input signal at 16kHz */ - Word16 coder_type /* i : coding type */ -); - -Word16 WB_BWE_encoding_fx( /* o : classification of wb signal */ - const Word16 coder_type, /* i : coder type */ - const Word16 *yos_fx, /* i : MDCT coefficients of weighted original */ - Word16 *WB_fenv_fx, /* i/o: energy of WB envelope */ - Encoder_State_fx *st_fx, /* i/o: Encoder structure */ - Word16 Q_synth, - Word16 Q_synth_lf -); - - -Word16 wb_bwe_dec_fx( - Word16 *synth_fx, /* i/o: ACELP core synthesis/final synthesis */ - Word16 *hb_synth_fx, /* o : SHB synthesis/final synthesis */ - const Word16 output_frame, /* i : frame length */ - Word16 coder_type, /* i : coding type */ - Word16 *voice_factors_fx, /* i : voicing factors */ - const Word16 pitch_buf_fx[], /* i : pitch buffer */ - Decoder_State_fx *st_fx /* i/o: decoder state structure */ - ,Word16 * Qpost -); - -Word16 WB_BWE_gain_deq_fx( - Decoder_State_fx *st_fx , /* i/o: decoder state structure */ - Word16 *WB_fenv -); -Word16 swb_bwe_gain_deq_fx( /* o : BWE class */ - Decoder_State_fx *st_fx, /* i/o: decoder state structure */ - const Word16 core, /* i : core */ - Word16 *SWB_tenv, /* o : Q0, time-domain BWE envelope */ - Word16 *SWB_fenv, /* o : Q1, frequency-domain BWE envelope */ - const Word16 hr_flag, /* i : high rate flag */ - const Word16 hqswb_clas /* i : HQ BWE class */ -); - -Word16 swb_bwe_dec_fx( - Decoder_State_fx *st_fx, /* i/o: decoder state structure */ - Word16 *synth_fx, /* i : ACELP core synthesis/final synthesis */ - Word16 *hb_synth, /* o : SHB synthesis/final synthesis */ - const Word16 output_frame /* i : frame length */ - ,Word16 * Qpost - ,Word16 coder_type /* i : coding type */ -); - -Word16 WB_BWE_gain_pred_fx( - Word16 *WB_fenv, /* o : WB frequency envelopes */ - const Word16 *core_dec_freq, /* i : Frequency domain core decoded signal */ - const Word16 coder_type, /* i : coding type */ - Word16 prev_coder_type, /* i : coding type of last frame */ - Word16 prev_WB_fenv, /* i : envelope for last frame */ - Word16 *voice_factors, /* i : voicing factors Q15 */ - const Word16 pitch_buf[], /* i : pitch buffer Q6 */ - Word32 last_core_brate, /* i : previous frame core bitrate */ - Word16 last_wb_bwe_ener , /* i : previous frame wb bwe signal energy */ - Word16 Q_syn - ,Word16 last_extl_fx, - Word16 tilt_wb_fx -); -void calc_normal_length_fx( - const Word16 core, /* i : core */ - const Word16 *sp, /* i : input signal */ - const Word16 mode, /* i : input mode */ - const Word16 extl, /* i : extension layer */ - Word16 *L_swb_norm, /* o : normalize length */ - Word16 *prev_L_swb_norm, /*i/o : last normalize length */ - Word16 Q_syn -); - -void calc_norm_envelop_fx( - const Word16 SWB_signal[], /* i : SWB spectrum Q_syn*/ - Word32 *envelope, /* o : normalized envelope Q_syn*/ - const Word16 L_swb_norm, /* i : length of envelope Q0 */ - const Word16 SWB_flength, /* i : Length of input/output */ - const Word16 st_offset /* i : offset */ -); - -void WB_BWE_decoding_fx( - const Word16 *core_dec_freq, /* i : Frequency domain core decoded signal */ - Word16 *WB_fenv, /* i : WB frequency envelopes */ - Word32 *WB_signal32, /* o : WB signal in MDCT domain */ - const Word16 WB_flength, /* i : Length of input/output */ - const Word16 mode, /* i : classification for WB signal */ - const Word16 last_extl, /* i : extl. layer for last frame */ - Word32 *prev_Energy, /* i/o: energy for last frame */ - Word16 *prev_WB_fenv, /* i/o: envelope for last frame */ - Word16 *prev_L_wb_norm, /* i/o: length for last frame wb norm */ - const Word16 extl, /* i : extension layer */ - const Word16 coder_type, /* i : coding type */ - const Word32 total_brate, /* i : core layer bitrate */ - Word16 *Seed, /* i/o: random generator seed */ - Word16 *prev_flag, /* i/o: attenu flag of last frame */ - Word16 prev_coder_type , /* i : coding type of last frame */ - Word16 Q_syn, - Word16 *Q_syn_hb /*o : Q value of WB_signal_32 */ -); - -void SWB_BWE_decoding_fx( - const Word16 *core_dec_freq, /* i : Frequency domain core decoded signal */ - Word16 *SWB_fenv, /* i/o: SWB frequency envelopes */ - Word32 *SWB_signal, /* o : SWB signal in MDCT domain */ - const Word16 SWB_flength, /* i : Length of input/output */ - const Word16 mode, /* i : classification for SWB signal */ - Word16 *frica_flag, /* o : fricative signal flag */ - Word16 *prev_Energy, /* i/o: energy for last frame */ - Word16 *prev_SWB_fenv, /* i/o: envelope for last frame */ - Word16 *prev_L_swb_norm, /* i/o: length for last frame wb norm */ - const Word16 tilt_nb, /* i : tilt of synthesis wb signal */ - Word16 *Seed, /* i/o: random generator seed */ - const Word16 st_offset, /* i : offset value due to different core */ - Word16 *prev_weight, /* i/o: excitation weight value of last frame */ - const Word16 extl , /* i : extension layer */ - Word16 Q_syn - ,const Word16 last_extl /* i : extension layer of last frame */ -); -void time_envelop_shaping_fx( - Word16 werr[], /* i/o: SHB synthesis Q_synth*/ - Word32 SWB_tenv[], /* i/o: frequency envelope Q15*/ - const Word16 L , /* i : frame length */ - Word16 *Q_synth -); -void time_reduce_pre_echo_fx( - const Word16 *synth, /* i : ACELP core synthesis Q_syn*/ - Word16 *error, /* i/o: SHB BWE synthesis Q0*/ - Word16 prev_td_energy, /* o : last td energy Q0*/ - const Word16 L, /* i : subframe length */ - Word16 Q_syn, - Word16 Q_synth -); -/*Word16 detect_transient_fx( */ -/* const Word16 *in_fx, *//*Q_new */ -/* Encoder_State *st, */ -/* const Word16 L, */ -/* const Word16 coder_type , */ /* i : coder type */ -/* Word16 Q_new, */ -/*Encoder_State_fx *st_fx */ -/*); */ - - -void preset_hq2_swb_fx -( - const Word16 hqswb_clas_fx, /* i : HQ2 class information */ - const Word16 band_end_fx[], /* i : band end of each SB */ - Word16 *har_bands_fx, /* i/o : Number of LF harmonic bands */ - Word16 p2a_bands_fx, /* i : flag for peakness */ - const Word16 length_fx, /* i : processed band length */ - const Word16 bands_fx, /* i : Total number of Subbands in a frame */ - Word16 *lowlength_fx, /* o : lowband length */ - Word16 *highlength_fx, /* o : highband length */ - Word32 L_m[] /* o : MDCT */ -); -void post_hq2_swb_fx -( - const Word32 L_m[], /* i : input_signal */ - const Word16 lowlength_fx, /* i : lowband length */ - const Word16 highlength_fx, /* i : highband length */ - const Word16 hqswb_clas_fx, /* i : HQ2 class information */ - const Word16 har_bands_fx, /* i : Number of LF harmonic bands */ - const Word16 bands_fx, /* i : Total number of Subbands in a frame */ - const Word16 p2a_flags_fx[], /* i : HF tonal indicator */ - const Word16 band_start_fx[], /* i : band start of each SB */ - const Word16 band_end_fx[], /* i : band end of each SB */ - Word32 L_y2[], /* o : output signal */ - Word16 npulses_fx[] /* i/o : Number of coded spectrum */ -); - -void swb_bwe_enc_lr_fx( - Encoder_State_fx *st_fx, /* i/o: encoder state structure */ - const Word32 L_m_core[], /* i : lowband synthesis */ - Word16 QsL, - const Word32 L_m_orig[], /* i/o: scaled orig signal (MDCT) */ - Word32 L_m[], /* o : highband synthesis with lowband zeroed */ - const Word32 L_total_brate, /* i : total bitrate for selecting subband pattern */ - Word16 BANDS_fx, /* i : Total number of Subbands in a frame */ - Word16 *band_start_fx, /* i : band start of each SB */ - Word16 *band_end_fx, /* i : band end of each SB */ - Word32 *L_band_energy, /* i : band_energy of each SB */ - Word16 Qbe, /* i : Q value of band energy */ - Word16 *p2a_flags_fx, /* i : HF tonal indicator */ - const Word16 hqswb_clas_fx, /* i : HQ_NORMAL2 or HQ_HARMONIC mode */ - Word16 lowlength_fx, /* i : lowband length */ - Word16 highlength_fx, /* i : highband length */ - Word16 *prev_frm_index_fx, /* i/o: previous frame lag index for harmonic mode */ - const Word16 har_bands_fx, /* i : Number of LF harmonic bands */ - Word16 *prev_frm_hfe2, /* i/o: */ - Word16 *prev_stab_hfe2, /* i/o: */ - const Word16 band_width_fx[], /* i : band_width information */ - const Word32 L_y2_ni[], /* i : band_width information */ - Word16 *ni_seed_fx /* i/o: random seed for search buffer NI */ -); - -void swb_bwe_dec_lr_fx( - Decoder_State_fx *st_fx, /* i/o: decoder state structure */ - const Word32 L_m_core[], /* i : lowband synthesis */ - const Word16 QsL, /* i : Q value of m_core */ - Word32 L_m[], /* o : highband synthesis with lowband zeroed */ - const Word32 L_total_brate, /* i : total bitrate for selecting subband pattern */ - Word16 BANDS_fx, /* i : Number subbands/Frame */ - Word16 *band_start_fx, /* i : Band Start of each SB */ - Word16 *band_end_fx, /* i : Band end of each SB */ - Word32 *L_band_energy, /* i : Band energy of each SB : Qbe */ - Word16 Qbe, /* i : Q value of band energy */ - Word16 *p2a_flags_fx, /* i : HF tonal Indicator */ - const Word16 hqswb_clas_fx, /* i : class information */ - Word16 lowlength_fx, /* i : Lowband Length */ - Word16 highlength_fx, /* i : Highband Length */ - const Word16 har_bands_fx, /* i : Number of LF harmonic bands */ - Word16 *prev_frm_hfe2_fx, /* i/o: */ - Word16 *prev_stab_hfe2_fx, /* i/o: */ - Word16 band_width_fx[], /* i : subband bandwidth */ - const Word32 L_y2_ni[], /* i/o: Sparse filled corecoder */ - Word16 *ni_seed_fx /* i/o: random seed */ -); - -void GetPredictedSignal_fx( - const Word16 *predBuf_fx, /* i: Q8 */ - Word32 *L_outBuf, /* o: Q9 */ - const Word16 lag_fx, /* i: Q0 */ - const Word16 fLen_fx, /* i: Q0 */ - const Word16 lagGains_fx, /* i: Qgain */ - const Word16 Qgain /* i: Q0 */ -); - -void Get20Log10Spec_fx( - const Word32 *L_inBuf, /* i : input Q_inBuf */ - Word16 *outBuf_fx, /* o : output Q7 */ - const Word16 fLen, /* i : loop length */ - const Word16 Q_inBuf /* i : Qvalue of L_inBuf */ -); - -void convert_lagIndices_pls2smp_fx( - Word16 lagIndices_in_fx[], - Word16 nBands_search_fx, - Word16 lagIndices_out_fx[], - const Word16 sspectra_fx[], - const Word16 sbWidth_fx[], - const Word16 fLenLow_fx -); - -Word16 get_usebit_npswb_fx( - Word16 hqswb_clas_fx -); - -void SpectrumSmoothing_nss_fx( - const Word32 *L_inBuf, /* i : lowband MDCT */ - Word16 *outBuf_fx, /* o : output */ - Word16 *Qss, /* o : Q value for output vector */ - const Word16 fLen /* i : length */ -); - -void SpectrumSmoothing_fx( - const Word32 *L_inBuf, /* i : Qs Low band MDCT */ - Word16 *outBuf_fx, /* o : Qss output */ - Word16 *Qss, /* o : Q0 Q value of output vector */ - const Word16 fLen, /* i : Q0 length */ - const Word16 th_cut_fx /* i : Qss threshold of cut */ -); - -void GetSynthesizedSpecThinOut_fx( - const Word16 *predBuf_fx, /* i : Qss: prediction buffer (i.e., lowband) */ - const Word16 Qss, /* i : Q value of input vector */ - Word32 *L_outBuf, /* o : QsL: synthesized spectrum */ - Word16 QsL, /* o : Q value of synthesized spectrum */ - const Word16 nBands_fx, /* i : Q0: number of subbands calculated */ - const Word16 *sbWidth_fx, /* i : Q0: subband lengths */ - const Word16 *lagIndices_fx, /* i : Q0: lowband index for each subband */ - const Word16 *lagGains_fx, /* i : Qgain: lagGain for each subband */ - const Word16 *QlagGains_fx, /* i : Q0: Q value of lagGains_fx */ - const Word16 predBufLen_fx /* i : Q0: lowband length */ -); - -Word32 hq2_bit_alloc_fx ( - const Word32 L_band_energy[], /* i : band energy of each subband */ - const Word16 bands, /* i : total number of subbands in a frame */ - Word32 L_Rk[], /* i/o: Bit allocation/Adjusted bit alloc. */ - Word16 *bit_budget_fx, /* i/o: bit bugdet */ - Word16 *p2a_flags, /* i : HF tonal indicator */ - const Word16 weight_fx, /* i : weight */ - const Word16 band_width[], /* i : Sub band bandwidth */ - const Word16 num_bits, /* i : available bits */ - const Word16 hqswb_clas, /* i : HQ2 class information */ - const Word16 bwidth, /* i : input bandwidth */ - const Word16 is_transient /* i : indicator HQ_TRANSIENT or not */ -); - -void hq2_noise_inject_fx( - Word32 L_y2[], - const Word16 band_start[], - const Word16 band_end[], - const Word16 band_width[], - Word32 Ep_fx[], - Word32 Rk_fx[], - const Word16 npulses[], - Word16 ni_seed, - const Word16 bands, - const Word16 ni_start_band, - const Word16 bw_low, - const Word16 bw_high, - const Word32 enerL_fx, - const Word32 enerH_fx, - Word32 last_ni_gain_fx[], - Word16 last_env_fx[], - Word16 *last_max_pos_pulse, - Word16 *p2a_flags, - Word16 p2a_bands, - const Word16 hqswb_clas, - const Word16 bwidth, - const Word32 bwe_br -); - -void reordvct_fx( - Word16 *y, /* i/o: vector to rearrange */ - const Word16 N, /* i : dimensions */ - Word16 *idx /* o : reordered vector index */ -); - -void Bits2indvsb_fx ( - const Word32 *L_be, /* i : Q14 Band Energy of sub-band */ - const Word16 start_band, /* i : Q0 start band indices */ - const Word16 end_band, /* i : Q0 end band indices */ - const Word16 Bits, /* i : Q0 Total number of bits allocated to a group */ - const Word32 L_Bits_needed, /* i : Q0 smallest bit number for allocation in group */ - Word32 *L_Rsubband, /* o : Q18 bit allocation of sub-band */ - Word16 *p2aflags_fx /* i/o: Q0 peaky/noise subband flag */ -); - -void hq2_bit_alloc_har_fx ( - const Word32 *L_y, /* i : Q14 band energy of sub-vectors */ - Word16 B_fx, /* i : Q0 number of available bits */ - const Word16 N_fx, /* i : Q0 number of sub-vectors */ - Word32 *L_Rsubband, /* o : Q18 sub-band bit-allocation vector */ - Word16 p2a_bands_fx, /* i : Q0 highfreq bands */ - const Word32 L_core_brate, /* i : Q0 core bit rate */ - Word16 p2a_flags_fx[], /* i/o: Q0 p2a_flags */ - const Word16 band_width_fx[] /* i : Q0 table of band_width */ -); - -void hq2_core_configure_fx ( - const Word16 frame_length, - const Word16 num_bits, - const Word16 is_transient, - Word16 *bands, - Word16 *length, - Word16 band_width[], - Word16 band_start[], - Word16 band_end[], - Word32 *L_qint, - Word16 *eref, - Word16 *bit_alloc_weight, - Word16 *gqlevs, - Word16 *Ngq, - Word16 *p2a_bands, - Word16 *p2a_th, - Word16 *pd_thresh, - Word16 *ld_slope, - Word16 *ni_coef, - Word32 L_bwe_br -); - -void hq_lr_enc_fx( - Encoder_State_fx *st_fx, /* i/o: : encoder state structure */ - Word32 L_t_audio[], /* i/o: Q12 : transform-domain coefs. */ - const Word16 inner_frame_fx, /* i : Q0 : inner frame length */ - Word16 *num_bits_fx, /* i/o: Q0 : number of available bits */ - const Word16 is_transient_fx /* i : Q0 : transient flag */ -); - -void hq_lr_dec_fx( - Decoder_State_fx *st_fx, /* i/o: : decoder state structure */ - Word32 L_yout[], /* o : Q12 : transform-domain output coefs. */ - const Word16 inner_frame, /* i : Q0 : inner frame length */ - Word16 num_bits, /* i : Q0 : number of available bits */ - Word16 *is_transient_fx /* o : Q0 : transient flag */ -); - -void reverse_transient_frame_energies_fx( - Word32 L_band_energy[], /* o : Q14 : band energies */ - const Word16 bands /* i : Q0 : number of bands */ -); - -Word16 har_est_fx( - Word32 L_spectra[], /* i : coded spectrum */ - Word16 N, /* i : length of the desired spectrum */ - Word16 *har_freq_est1, /* i/o: Estimation harmonics 1 */ - Word16 *har_freq_est2, /* o : Estimation harmonics 2 */ - Word16 *flag_dis, /* i/o: flag for BWE reconstruction */ - Word16 *prev_frm_hfe2, /* i/o: Estimated harmonic update */ - const Word16 subband_search_offset[], /* i : Subband Search range */ - const Word16 sbWidth[], /* i : Subband Search range */ - Word16 *prev_stab_hfe2 /* i/o: Estimated harmonic position */ -); - -typedef struct GainItemStr_fx -{ - Word16 nmrValue_fx; - Word16 gainIndex_fx; -} GainItem_fx; - -void genhf_noise_fx( - Word16 noise_flr_fx[], /* i : Qss smoothed non tonal */ /* sspectra_diff_fx:Qss */ - Word16 Qss, /* i : Q0 Q value */ - Word32 L_xSynth_har[], /* o : QsL hf non tonal components */ /* xSynth_har:QsL */ - Word16 QsL, /* i : Q0 Q value */ - Word16 *predBuf_fx, /* i : Qss smoothed tonal compone */ /* sspectra:Qss */ - Word16 bands, /* i : Q0 total number of subbands in a frame */ - Word16 harmonic_band, /* i : Q0 Number of LF harmonic frames */ - Word16 har_freq_est2, /* i : Q0 harmonic signal parameter */ - Word16 pos_max_hfe2, /* i : Q0 last pulse in core coder */ - Word16 *pul_res, /* o : Q0 pulse resolution */ - GainItem_fx pk_sf_fx[], /* o : representative region */ - const Word16 fLenLow, /* i : Q0 low frequency length */ - const Word16 fLenHigh, /* i : Q0 high frequency length */ - const Word16 sbWidth[], /* i : Q0 bandwidth for high bands */ - const Word16 lagIndices[], /* i : Q0 correlation indices for most representative */ - const Word16 subband_offsets[], /* i : Q0 band offsets for HF reconstruction */ - const Word16 subband_search_offset[] /* i : Q0 most representative regions offsets in LF */ -); - -void spt_shorten_domain_pre_fx( - const Word16 band_start[], /* i: Starting position of sub band */ - const Word16 band_end[], /* i: End position of sub band */ - const Word16 prev_SWB_peak_pos[], /* i: Spectral peak */ - const Word16 BANDS, /* i: total number of bands */ - const Word32 L_bwe_br, /* i: bitrate information */ - Word16 new_band_start[], /* o: Starting position of new shorten sub band */ - Word16 new_band_end[], /* o: End position of new shorten sub band */ - Word16 new_band_width[] /* o: new sub band bandwidth */ -); - -void spt_shorten_domain_band_save_fx( - const Word16 bands, /* i: total subband */ - const Word16 band_start[], /* i: starting position of subband */ - const Word16 band_end[], /* i: end position of subband */ - const Word16 band_width[], /* i: band width of subband */ - Word16 org_band_start[], /* o: starting position of subband */ - Word16 org_band_end[], /* o: end position of subband */ - Word16 org_band_width[] /* o: band width of subband */ -); - -void spt_shorten_domain_band_restore_fx( - const Word16 bands, /* i: total subband */ - Word16 band_start[], /* i/o: starting position of subband */ - Word16 band_end[], /* i/o: end position of subband */ - Word16 band_width[], /* i/o: band width of subband */ - const Word16 org_band_start[], /* o: starting position of subband */ - const Word16 org_band_end[], /* o: end position of subband */ - const Word16 org_band_width[] /* o: band width of subband */ -); - -void spt_swb_peakpos_tmp_save_fx( - const Word32 L_y2[], /* i: coded spectral information */ - const Word16 bands, /* i: total number of bands */ - const Word16 band_start[], /* i: starting position of subband */ - const Word16 band_end[], /* i: end position of subband */ - Word16 prev_SWB_peak_pos_tmp[] /* o: spectral peaks */ -); - -Word16 div_s_ss( /* o: result of division (Word16 Q0) */ - const Word16 n, /* i: numerator (Word16 Q0 */ - const Word16 d /* i: denominator (Word16 Q0) */ -); - -void updat_prev_frm_fx( - Word32 L_y2[], /* i/o: core coder buffer */ - Word32 L_t_audio[], /* o: core coder buffer */ - Word32 L_bwe_br, /* i: core bitrate */ - Word16 length_fx, /* i: frame length coded bw */ - const Word16 inner_frame_fx, /* i: input frame length */ - Word16 bands_fx, /* i: sub band resolution */ - Word16 bwidth_fx, /* i: NB/WB/SWB indicator */ - const Word16 is_transient_fx, /* i: signal class information */ - Word16 hqswb_clas_fx, /* i: signal class information */ - Word16 *prev_hqswb_clas_fx, /* o: update signal class information */ - Word16 prev_SWB_peak_pos_fx[], /* o: update core coder last coded peaks*/ - Word16 prev_SWB_peak_pos_tmp_fx[], /* o: update core coder last coded peaks*/ - Word16 *prev_frm_hfe2_fx, /* o: update harmonics */ - Word16 *prev_stab_hfe2_fx, /* o: update harmonics */ - Word16 bws_cnt_fx /* i: band width detector */ -); - -void hf_parinitiz_fx( - const Word32 L_total_brate, - const Word16 hqswb_clas_fx, - Word16 lowlength_fx, - Word16 highlength_fx, - Word16 wBands_fx[], - const Word16 **subband_search_offset_fx, - const Word16 **subband_offsets_fx, - Word16 *nBands_fx, - Word16 *nBands_search_fx, - Word16 *swb_lowband_fx, - Word16 *swb_highband_fx -); - -void GetlagGains_fx( - const Word16 *predBuf_fx, /* i: Qss Low freq. Smoothed Spectrum */ - const Word16 Qss, /* i: Q0 Q value of predBuf */ - const Word32 *L_band_energy, /* i: Qbe Band Energy */ - const Word16 Qbe, /* i: Q0 Q value of band energy */ - const Word16 nBands, /* i: Q0 number of SWB subbands */ - const Word16 *sbWidth, /* i: Q0 width of SWB subbands */ - const Word16 *lagIndices, /* i: Q0 lagIndices */ - const Word16 predBufLen, /* i: Q0 length of predBuf */ - Word16 *lagGains_fx, /* o: QlagGains lagGains */ - Word16 *QlagGains /* o: Q0 Q value of lagGains */ -); - -void noise_extr_corcod_fx( - Word32 L_spectra[], /* i : QsL core coder */ - const Word32 L_spectra_ni[], /* i : QsL core coder with sparse filling */ - Word16 sspectra_fx[], /* o : Qss Smoothed tonal information from core coder */ - Word16 sspectra_diff_fx[], /* o : Qss non tonal infomration for gap filling */ - Word16 sspectra_ni_fx[], /* o : Qss smoothed core coder */ - const Word16 fLenLow_fx, /* i : Q0 low frequency bands width */ - Word16 prev_hqswb_clas_fx, /* i : Q0 classification information */ - Word16 *prev_ni_ratio_fx, /* i : Q15 noise paraemeter */ - Word16 *Qss /* o : Q0 Q value for sspectra_*_fx */ -); - -void ton_ene_est_fx( - Word32 L_xSynth_har[], /* i : QsL buffer with non tonal compoents */ - Word16 QsL, /* i : Q0 Q value for xSynth_har */ - Word32 L_be_tonal[], /* o : QbeL tonal energy of the missing bands */ - Word16 *QbeL, /* o : Q0 Q value for be_tonal */ - Word32 L_band_energy[], /* i : Qbe subband energies */ - Word16 Qbe, /* i : Q0 Q value for band_energy */ - const Word16 band_start[], /* i : Q0 subband start indices */ - const Word16 band_end[], /* i : Q0 subband end indices */ - const Word16 band_width[], /* i : Q0 subband widths */ - const Word16 fLenLow, /* i : Q0 low frequency width */ - const Word16 fLenHigh, /* i : Q0 High frequency width */ - Word16 bands, /* i : Q0 total subbands */ - Word16 har_bands, /* i : Q0 total number of harmonics bands */ - Word16 ni_lvl_fx, /* i : Q11 noise enve for the hf bands */ - GainItem_fx pk_sf_fx[], /* i : */ - Word16 Qss, /* i : Q0 Q value for GainItem_fx->nmrValue */ - Word16 *pul_res /* i : Q0 tonal resolution */ -); - -void Gettonl_scalfact_fx -( - Word32 *L_outBuf, /* i/o: QsL synthesized spectrum */ - Word16 QsL, /* i : Q0 Q value for outBuf */ - const Word32 *L_codbuf, /* i : QsL core coder */ - const Word16 fLenLow, /* i : Q0 lowband length */ - const Word16 fLenHigh, /* i : Q0 highband length */ - const Word16 harmonic_band, /* i : Q0 total number of Low frequency bands */ - const Word16 bands, /* i : Q0 total number of subbands in a frame */ - Word32 *L_band_energy, /* i : Qbe band energy of each subband */ - Word16 Qbe, /* i : Q0 Q value for band_energy */ - const Word16 *band_start, /* i : Q0 subband start indices */ - const Word16 *band_end, /* i : Q0 subband end indices */ - const Word16 p2aflags[], /* i : Q0 missing bands in the core coder */ - Word32 L_be_tonal[], /* i : QbeL tonal energy */ - Word16 QbeL, /* i : Q0 Q value for be_tonal */ - GainItem_fx *pk_sf_fx, /* i : toanl information for Sparse filling */ - Word16 Qss, /* i : Q0 Q value for pk_sf.nmrValue */ - Word16 *pul_res_pk /* i : Q0 pulse resolution information */ -); - - -void get_sigma_fx_har( - const Word32 L_x_abs[], /* i: Qi absolute input */ - const Word16 Qi, /* i: Q0 Q value of x_abs */ - const Word16 avg_fx, /* i: Qavg average of x_abs */ - const Word16 Qavg, /* i: Q0 Q value of avg */ - const Word16 length_fx, /* i: Q0 length */ - Word16 *sigma_fx, /* o: Qsigma sigma */ - Word16 *Qsigma /* o: Q0 Q value of sigma */ -); - -void FindNBiggest2_simple_fx_har( - const Word32 *L_inBuf, /* i : input buffer (searched) */ - const Word16 Qabs_in, /* i : Q value of input buffer */ - GainItem_fx *pk_sf_fx, /* o : N biggest components found */ - const Word16 nIdx_fx, /* i : search length */ - Word16 *n_fx, /* i : number of components searched (N biggest) */ - Word16 n_nbiggestsearch -); - -Word16 spectrumsmooth_noiseton_fx( /* o : Qss ss_min */ - Word32 L_spectra[], /* i : Qs core coder */ - /*Word16 Qs,*/ /* i : Q0 Q value for spectra, spectra_ni */ - const Word32 L_spectra_ni[], /* i : Qs core coder with sparse filling */ - Word16 sspectra_fx[], /* o : Qss Smoothed tonal information from core coder */ - Word16 sspectra_diff_fx[], /* o : Qss non tonal infomration for gap filling */ - Word16 sspectra_ni_fx[], /* o : Qss smoothed core coder */ - Word16 *Qss, /* o : Q0 Q value for sspectra* */ - const Word16 fLenLow_fx, /* i : Q0 low frequency boundaries */ - Word16 *ni_seed_fx /* io : Q0 random seed */ -); - -void noiseinj_hf_fx( - Word32 L_xSynth_har[], /* i/o : Qs gap filled information */ - Word16 Qs, /* i : Q0 Q value for xSynth_har */ - Word32 L_th_g[], /* i : Qs level adjustment information */ - Word32 L_band_energy[], /* i : Qbe subband energies */ - Word16 Qbe, /* i : Q0 Q value for band_energy */ - Word16 *prev_En_sb_fx, /* i/o : QsEn smoothed sqrt band Energies */ - const Word16 p2a_flags_fx[], /* i : Q0 Missing bands in the core coder */ - const Word16 BANDS_fx, /* i : Q0 total bands */ - const Word16 band_start_fx[], /* i : Q0 band start indices */ - const Word16 band_end_fx[], /* i : Q0 band end indices */ - const Word16 fLenLow_fx, /* i : Q0 low frequency bandwidth */ - const Word16 fLenHigh_fx /* i : Q0 SWB frequency bandwidth */ -); - -void sqrt_32n_16_fx( - Word32 L_in, /* i : input vector (Word32) */ - Word16 Qin, /* i : Q value for L_in */ - Word16 *out_fx, /* o : sqrt input vector (Word16) */ - Word16 *Qout /* o : Q value for out_fx */ -); - -void norm_vec_32_16_scale_fx( - Word32 *L_vec_in, /* i : input vector */ - Word16 Qin, /* i : Q value for input vector */ - Word16 length_fx, /* i :vector size */ - Word16 *vec_out_fx, /* o : output vectror */ - Word16 *Qout, /* o : Q value for output vectro */ - Word16 exp_safe /* i : suppress left shift: for prevend overflow on sum */ -); - -void return_bits_normal2_fx( - Word16 *bit_budget_fx, /* i/o : bit budget */ - const Word16 p2a_flags_fx[], /* i : HF tonal indicator */ - const Word16 bands_fx, /* i : Total number of Subbands in a frame */ - const Word16 bits_lagIndices_fx[] /* i : bits for lagIndices */ -); - -Word16 peak_avrg_ratio_fx( - const Word32 total_brate, - const Word32 *input_hi_fx, /* i : input signal */ - const Word16 length, /* i : number of coefficients */ - Word16 *mode_count, /* i/o: HQ_HARMONIC mode count */ - Word16 *mode_count1, /* i/o: HQ_NORMAL mode count */ - Word16 Q_coeff -); - -void diffcod_fx( - const Word16 N, /* (i) number of sub-vectors */ - Word16 *y, /* (i/o) indices of quantized norms */ - Word16 *difidx /* (o) differential code */ -); - -void diffcod_lrmdct_fx( - const Word16 N, /* i : number of sub-vectors */ - const Word16 be_ref, /* i : band energy reference */ - Word16 *y, /* i/o: indices of quantized norms */ - Word16 *difidx, /* o : differential code */ - const Word16 is_transient /* i : transient flag */ -); - -Word16 encode_envelope_indices_fx( /* o : Number of bits if flag_pack=0,0 if flag_pack=1 Q0 */ - Encoder_State_fx *st_fx, /* i/o: encoder state structure */ - const Word16 num_sfm, /* i : Number of subbands Q0 */ - const Word16 numnrmibits, /* i : Bitrate of fall-back coding mode Q0 */ - Word16 *difidx, /* i/o: Diff indices/encoded diff indices Q0 */ - Word16 *LCmode, /* o : Coding mode if flag_pack=0, i : if flag_pack=1 Q0 */ - const Word16 flag_pack, /* i : indicator of packing or estimating bits Q0 */ - const Word16 flag_HQ2 /* i : indicator of HQ2 core Q0 */ - , - const Word16 is_transient /* i : indicator of HQ_TRANSIENT Q0 */ -); -Word16 decode_envelope_indices_fx( /* o : Number of bits */ - Decoder_State_fx *st_fx, /* i/o: decoder state structure */ - const Word16 start_norm, /* i : starting band index */ - const Word16 num_sfm, /* i : Number of subbands */ - const Word16 numnrmibits, /* i : Bitrate of fall-back coding mode */ - Word16 *difidx, /* o : Diff indices/encoded diff indices */ - const Word16 flag_HQ2 /* i : indicator of HQ2 core */ - , - const Word16 is_transient /* i : indicator of HQ_TRANSIENT */ -); - -void hdecnrm_fx( - Decoder_State_fx *st_fx, /* i/o: decoder state structure */ - const Word16 numNorms, /* (i) number of norms */ - Word16 *index); /* (o) indices of quantized norms */ - -Word16 decode_huff_context_fx( - Decoder_State_fx *st_fx, /* i/o: decoder state structure */ - const Word16 *hufftab, - Word16 *rbits -); - -void hdecnrm_context_fx( - Decoder_State_fx *st_fx, /* i/o: decoder state structure */ - const Word16 N, - Word16 *index, - Word16 *n_length -); - -void hdecnrm_resize_fx( - Decoder_State_fx *st_fx, /* i/o: decoder state structure */ - const Word16 N, /* (i) number of SFMs */ - Word16 *index /* (o) norm quantization index vector */ -); - -void hdecnrm_tran_fx( - Decoder_State_fx *st_fx, /* i/o: decoder state structure */ - const Word16 N, /* i : number of norms */ - Word16 *index /* o : indices of quantized norms */ -); - -void mdct_spectrum_denorm_fx( - const Word16 inp_vector[], /* i : Q0 : */ - Word32 L_y2[], /* i/o : Qs : decoded spectrum */ - const Word16 band_start[], /* i : Q0 : table of start freq for every subband */ - const Word16 band_end[], /* i : Q0 : table of end freq for every subband */ - const Word16 band_width[], /* i : Q0 : table of bandwidth for every subband */ - const Word32 L_band_energy[], /* i : Qbe : band energy */ - const Word16 npulses[], /* i : Q0 : number of coded spectrum */ - const Word16 bands, /* i : Q0 : numbers of subbands */ - const Word16 ld_slope_fx, /* i : Q15 : */ - const Word16 pd_thresh_fx /* i : Q15 : */ -); - -/* y(n)(Qx) = alpha(Q15) * x(Qx) + (1.0f-alpha)* y(n-1) (Qx) */ -Word16 noise_est_AR1_Qx( /* o: Qx y(n) */ - Word16 x, /* i : Qx x(n) */ - Word16 y, /* i : Qx y(n-1) */ - Word16 alpha /*i : Q15 scaling of driving x(n) */ -); -void noise_est_fx( - Encoder_State_fx *st_fx, /* i/o: state structure */ - const Word32 tmpN[], /* i : temporary noise update Q_new + QSCALE */ - const Word16 *pit, /* i : open-loop pitch values for each half-frame Q0 */ - const Word16 cor[], /* i : normalized correlation for all half-frames Q15 */ - const Word16 epsP_h[], /* i : msb prediction error energies Q_r-1 */ - const Word16 epsP_l[], /* i : msb prediction error energies Q_r-1 */ - const Word16 Etot, /* i : total channel E (see find_enr_fx.c) Q8 */ - const Word16 relE, /* i : (VA_CHECK addition) relative frame energy Q8? */ - const Word16 corr_shift, /* i : normalized correlation correction Q15 */ - const Word32 enr[], /* i : averaged energy over both subframes Q_new + Q_SCALE */ - Word32 fr_bands[], /* i : spectrum per critical bands of the current frame Q_new + Q_SCALE */ - Word16 *cor_map_sum, /* o : Q8 */ - Word16 *sp_div, /* o : Q_sp_div */ - Word16 *Q_sp_div, /* o : Q factor for sp_div */ - Word16 *non_staX, /* o : non-stationarity for sp/mus classifier */ - Word16 *loc_harm , /* o : multi-harmonicity flag for UV classifier */ - const Word32 *lf_E, /* i : per bin energy for low frequencies Q_new + Q_SCALE -2 */ - Word16 *st_harm_cor_cnt, /* i/o : 1st harm correlation timer Q0 */ - const Word16 Etot_l_lp, /* i : Smoothed low energy Q8 */ - const Word16 Etot_v_h2, /* i : Energy variations Q8 */ - Word16 *bg_cnt, /* i : Background burst length timer Q0 */ - Word16 EspecdB[], /* i/o: log E spectrum (with f=0) of the current frame Q7 */ - Word16 Q_new , /* i : Scaling of current frame */ - - const Word32 Le_min_scaled /*i : Minimum energy value */ - , Word16 *sp_floor /* o : noise floor estimate Q7 */ -); - - -void autocorr_fx( - const Word16 x[], /* i : Input signal */ - const Word16 m, /* i : LPC order Q0 */ - Word16 r_h[], /* o : Autocorrelations (msb) Q15 */ - Word16 r_l[], /* o : Autocorrelations (lsb) */ - Word16 *Q_r, /* o : normailsation shift of r Q0 */ - const Word16 len, /* i : Frame lenght */ - const Word16* wind, /* i : Window used */ - Word16 rev_flag, - const Word16 sym_flag /* i : symmetric window flag */ -); -void freq_dnw_scaling_fx( - const Word16 cor_strong_limit, /* i : HF correlation */ - const Word16 coder_type, /* i : coder type */ - const Word16 noise_lev, /* i : Noise level */ - const Word32 core_brate, /* i : Core bitrate */ - Word16 fy_norm[], /* i/o: Frequency quantized parameter */ - Word16 Qx /* Q format of fy_norm*/ -); -void Comp_and_apply_gain_fx( - Word16 exc_diffQ[], /* i/o: Quantized excitation */ - Word16 Ener_per_bd_iQ[], /* i : Target ener per band Q13 */ - Word16 Ener_per_bd_yQ[], /* i/o : Ener per band for norm vector i->Q13/o->Q13 */ - Word16 Mbands_gn, /* i : number of bands */ - const Word16 ReUseGain , /* i : Reuse the gain in Ener_per_bd_yQ */ - Word16 Qexc_diff, - Word16 Q_exc -); -void dec_pit_exc_fx( - Decoder_State_fx *st_fx, /* i/o: decoder static memory */ - const Word16 *Aq_fx, /* i : LP filter coefficient */ - const Word16 coder_type_fx, /* i : coding type */ - const Word16 Es_pred_fx, /* i : predicted scaled innov. energy */ - Word16 *pitch_buf_fx, /* o : floating pitch values for each subframe */ - Word16 *code_fx, /* o : innovation */ - Word16 *exc_fx, /* i/o: adapt. excitation exc */ - Word16 *bwe_exc_fx, /* o : excitation for SWB TBE */ - const Word16 nb_subfr_fx /* i : Number of subframe considered */ - , Word16 *gain_buf /*Q14*/ -); -Word16 mean_fx( /* o : mean of vector */ - const Word16 *vec_fx, /* i : input vector */ - const Word16 lvec_fx /* i : length of input vector */ -); -void gsc_dec_fx( - Decoder_State_fx *st_fx, /* i/o: State structure */ - Word16 exc_dct_in[], /* i/o: dct of pitch-only excitation / total excitation */ - const Word16 pit_band_idx, /* i : bin position of the cut-off frequency */ - const Word16 Diff_len, /* i : Lenght of the difference signal (before pure spectral)*/ - const Word16 bits_used, /* i : Number of bit used before frequency Q */ - const Word16 nb_subfr, /* i : Number of subframe considered */ - const Word16 coder_type, /* i : coding type */ - Word16 *last_bin, /* i : last bin of bit allocation */ - Word16 *lsf_new, /* i : ISFs at the end of the frame */ - Word16 *exc_wo_nf, /* o : excitation (in f domain) without noisefill */ - Word16 Q_exc -); -void fft_rel_fx( - Word16 x[], /* i/o: input/output vector */ - const Word16 n, /* i : vector length */ - const Word16 m /* i : log2 of vector length */ -); -void ifft_rel_fx( - Word16 io[], /* i/o: input/output vector */ - const Word16 n, /* i : vector length */ - const Word16 m /* i : log2 of vector length */ -); - -Word16 gsc_gaindec_fx( /* o : average frequency gain */ - Decoder_State_fx *st_fx, /* i/o: decoder state structure */ - Word16 y_gainQ_fx[], /* o : quantized gain per band */ - const Word32 core_brate_fx, /* i : core used */ - Word16 old_y_gain_fx[], /* i/o: AR gain quantizer for low rate */ - const Word16 coder_type_fx, /* i : coding type */ - const Word16 bwidth_fx /* i : input signal bandwidth */ -); -void Copy_Scale_sig( - const Word16 x[], /* i : signal to scale input Qx */ - Word16 y[], /* o : scaled signal output Qx */ - const Word16 lg, /* i : size of x[] Q0 */ - const Word16 exp0 /* i : exponent: x = round(x << exp) Qx ?exp */ -); - -void bands_and_bit_alloc_fx( - const Word16 cor_strong_limit, /* i : HF correlation */ - const Word16 noise_lev, /* i : dwn scaling factor */ - const Word32 core_brate, /* i : core bit rate */ - const Word16 Diff_len, /* i : Lenght of the difference signal (before pure spectral)*/ - const Word16 bits_used, /* i : Number of bit used before frequency Q */ - Word16 *bit, /* i/o: Number of bit allowed for frequency quantization */ - const Word16 *Ener_per_bd_iQ, /* i/o: Quantized energy vector */ - Word16 *max_ener_band, /* o : Sorted order */ - Word16 *bits_per_bands, /* i/o: Number of bit allowed per allowed subband Q3 */ - Word16 *nb_subbands, /* o : Number of subband allowed */ - const Word16 *exc_diff, /* i : Difference signal to quantize (encoder side only) */ - Word16 *concat_in, /* o : Concatened PVQ's input vector (encoder side only) */ - Word16 *pvq_len, /* o : Number of bin covered with the PVQ */ - const Word16 coder_type, /* i : coding type */ - const Word16 bwidth, /* i : input signal bandwidth */ - const Word16 GSC_noisy_speech -); - - -void decod_audio_fx( - Decoder_State_fx *st_fx, /* i/o: decoder static memory */ - Word16 dct_epit[], /* o : GSC excitation in DCT domain */ - const Word16 *Aq, /* i : LP filter coefficient */ - const Word16 coder_type, /* i : coding type */ - Word16 *pitch_buf, /* o : floating pitch values for each subframe */ - Word16 *voice_factors, /* o : voicing factors */ - Word16 *exc, /* i/o: adapt. excitation exc */ - Word16 *exc2, /* i/o: adapt. excitation/total exc */ - Word16 *bwe_exc, /* o : excitation for SWB TBE */ - Word16 *lsf_new /* i : ISFs at the end of the frame */ - , Word16 *gain_buf /*Q14*/ -); -Word16 Pit_exc_contribution_len_fx( /* o : bin where pitch contribution is significant */ - Encoder_State_fx *st_fx, /* i/o: state structure */ - const Word16 *dct_res, /* i : DCT of residual */ - Word16 *dct_pitex, /* i/o: DCT of pitch contribution */ - Word16 *pitch_buf, /* i/o: Pitch per subframe */ - const Word16 nb_subfr, /* i : Number of subframe considered */ - Word16 *hangover, /* i : hangover for the time contribution switching */ - const Word16 coder_type, /* i : coding type */ - Word16 Qnew -); -void enc_pit_exc_fx( - Encoder_State_fx *st_fx, /* i/o: State structure */ - LPD_state *mem, /* i/o: acelp memories */ - const Word16 *speech, /* i : Input speech */ - const Word16 Aw[], /* i : weighted A(z) unquantized for subframes */ - const Word16 Aq[], /* i : 12k8 Lp coefficient */ - const Word16 Es_pred, /* i : predicted scaled innov. energy */ - const Word16 *T_op, /* i : open loop pitch */ - const Word16 *voicing, /* i : voicing */ - const Word16 *res, /* i : residual signal */ - Word16 *synth, /* i/o: core synthesis */ - Word16 *exc, /* i/o: current non-enhanced excitation */ - Word16 *T0, /* i/o: close loop integer pitch */ - Word16 *T0_frac, /* i/o: close-loop pitch period - fractional part */ - Word16 *pitch_buf, /* i/o: Fractionnal per subframe pitch */ - const Word16 nb_subfr, /* i : Number of subframe considered */ - Word16 *gpit, /* o : pitch mean gpit */ - Word16 *saved_bit_pos, /* o : saved position in the bitstream before pitch contribution */ - Word16 Q_new, - Word16 shift -); -void encod_amr_wb_fx( - Encoder_State_fx *st, /* i/o: state structure */ - LPD_state *mem, /* i/o: acelp memories */ - const Word16 speech[], /* i : input speech */ - const Word16 Aw[], /* i : weighted A(z) unquantized for subframes */ - const Word16 Aq[], /* i : 12k8 Lp coefficient */ - const Word16 pitch[3], /* i : open-loop pitch values for quantiz. */ - const Word16 voicing[], /* i : voicing */ - const Word16 *res, /* i : residual signal */ - Word16 *syn, /* i/o: core synthesis */ - Word16 *exc, /* i/o: current non-enhanced excitation */ - Word16 *exc2, /* i/o: current enhanced excitation */ - Word16 *pitch_buf, /* i/o: floating pitch values for each subframe */ - Word16 hf_gain_fx[NB_SUBFR], /* o : decoded HF gain */ - const Word16 *speech16k_fx, - Word16 shift, - Word16 Q_new -); -void amr_wb_enc_fx( - Encoder_State_fx *st, /* i/o: encoder state structure */ - const Word16 input_sp[], /* i : input signal */ - const Word16 n_samples /* i : number of input samples */ -); -void encod_gen_voic_fx( - Encoder_State_fx *st_fx, /* i/o: state structure */ - LPD_state *mem, /* i/o: acelp memories */ - const Word16 L_frame_fx, /* i : length of the frame */ - const Word16 sharpFlag_fx, /* o : formant sharpening flag */ - const Word16 speech_fx[], /* i : input speech */ - const Word16 Aq_fx[], /* i : 12k8 Lp coefficient */ - const Word16 A_fx[], /* i : unquantized A(z) filter with bandwidth expansion */ - const Word16 coder_type_fx, /* i : coding type */ - const Word16 Es_pred_fx, /* i : predicted scaled innov. energy */ - const Word16 T_op_fx[], /* i : open loop pitch */ - const Word16 voicing_fx[], /* i : voicing */ - const Word16 *res_fx, /* i : residual signal */ - Word16 *syn_fx, /* i/o: core synthesis */ - Word16 *exc_fx, /* i/o: current non-enhanced excitation */ - Word16 *exc2_fx, /* i/o: current enhanced excitation */ - Word16 *pitch_buf_fx, /* i/o: floating pitch values for each subframe */ - Word16 *voice_factors_fx, /* o : voicing factors */ - Word16 *bwe_exc_fx, /* o : excitation for SWB TBE */ - Word16 *unbits_fx, /* i/o: number of unused bits */ - Word16 shift, - Word16 Q_new -); -void bw_detect_fx( - Encoder_State_fx *st, /* i/o: Encoder State */ - const Word16 signal_in[], /* i : input signal */ - const Word16 localVAD, - Word32 *enerBuffer, /* i : CLDFB Energy */ - Word16 *cldfbBuf_Ener_Exp /* i : CLDFB Energy Exponent */ -); -void hf_synth_amr_wb_init_fx( - Word16 *prev_r, /* o : previous sub-frame gain */ - Word16 *fmerit_w_sm, /* o : 1 sample memory fmerit_w param */ - Word16 mem_syn_hf_fx[], /* o : HF LPC synthesis filter initialization */ - Word16 *frame_count, /* o : frame counter initialization */ - Word16 *ne_min, /* o : minimum Noise gate - short-term energy initialization*/ - Word16 *fmerit_m_sm, /* o : 1 sample memory fmerit_m param */ - Word16 *voice_fac, /* o : voice factor initialization */ - Word16 *unvoicing, /* o : unvoiced parameter */ - Word16 *unvoicing_sm, /* o : smoothed unvoiced parameter */ - Word16 *unvoicing_flag, /* o : unvoiced flag */ - Word16 *voicing_flag, /* o : voiced flag */ - Word16 *start_band_old, /* o : previous start point for copying frequency band */ - Word32 *OptCrit_old /* o : previous criterion value for deciding the start point */ -); - -void hf_synth_amr_wb_reset_fx( - Word16 *seed2, /* i/o: random seed for HF noise gen */ - Word16 mem_syn_hf[], /* o : HF synthesis memory */ - Word16 mem_hp_interp[], /* o : interpol. memory */ - Word16 *prev_r, /* o : previous sub-frame gain */ - Word16 *fmerit_w_sm, /* o : 1 sample memory fmerit_w param */ - Word16 delay_syn_hf[], /* o : HF synthesis memory */ - Word16 *frame_count, /* o : frame counter memory */ - Word16 *ne_min, /* o : minimum Noise gate - short-term energy memory */ - Word16 *fmerit_m_sm, /* o : 1 sample memory fmerit_m param */ - Word16 *voice_fac, /* o : voice factor memory */ - Word16 *unvoicing, /* o : unvoiced parameter */ - Word16 *unvoicing_sm, /* o : smoothed unvoiced parameter */ - Word16 *unvoicing_flag, /* o : unvoiced flag */ - Word16 *voicing_flag, /* o : voiced flag */ - Word16 *start_band_old, /* o : previous start point for copying frequency band */ - Word32 *OptCrit_old /* o : previous criterion value for deciding the start point */ -); - -void hf_synth_amr_wb_fx( - const Word32 core_brate, /* i : core bitrate */ - const Word16 output_frame, /* i : output frame length */ - const Word16 *Aq, /* i : quantized Az : Q12 */ - const Word16 *exc, /* i : excitation at 12.8 kHz : Qexc */ - Word16 *synth, /* i/o: synthesis signal at 12.8k : Qsyn */ - Word16 *mem_syn_hf, /* i/o: HF synthesis memory : Qout */ - Word16 *delay_syn_hf, /* i/o: HF synthesis memory : Qout */ - Word16 *prev_r, /* i/o : previous sub-frame gain : Q10 */ - Word16 *fmerit_w_sm, /* i/o: smoothed fmerit_w : Q14 */ - Word16 *amr_io_class, /* i : signal class (determined by FEC algorithm) */ - Word16 *mem_hp_interp, /* i/o: interpol. memory : Qout */ - Word16 *synth_out, /* i/o: output signal at output Fs : Qout */ - Word16 fmerit, /* i : classify parameter from FEC : Q14 */ - const Word16 *hf_gain, /* i : decoded HF gain */ - const Word16 *voice_factors, /* i : voicing factors : Q15 */ - const Word16 pitch_buf[], /* i : pitch buffer : Q5 */ - const Word16 ng_ener_ST, /* i : Noise gate - short-term energy : Q8 */ - const Word16 *lsf_new, /* i : ISF vector : Q2 */ - Word16 *frame_count, /* i/o: frame counter */ - Word16 *ne_min, /* i/o: minimum Noise gate : Q8 */ - Word16 *fmerit_m_sm, /* i/o: smoothed fmerit_m : Q14 */ - Word16 *voice_facor_sm, /* o : voice factor memory : Q15 */ - Word16 *unvoicing, /* o : unvoiced parameter : Q15 */ - Word16 *unvoicing_sm, /* o : smoothed unvoiced parameter : Q15 */ - Word16 *unvoicing_flag, /* o : unvoiced flag */ - Word16 *voicing_flag, /* o : voiced flag */ - Word16 *start_band_old, /* o : previous start point for copying frequency band */ - Word32 *OptCrit_old, /* o : previous criterion value for deciding the start point */ - const Word16 Q_exc, /* i : exc scaling */ - const Word16 Q_out /* i : synth_out scaling */ -); - -void hf_cod_init_fx( - Word16 *mem_hp400_enc, /* o: memory of hp 400 Hz filter */ - Word16 *mem_hf1_enc, /* o: HF band-pass filter memory */ - Word16 *mem_syn_hf_enc, /* o: HF synthesis memory */ - Word16 *mem_hf2_enc, /* o: HF band-pass filter memory */ - Word16 *gain_alpha_fx /* o: smoothing gain for transitions between active and inactive frames */ -); - -void hf_cod_fx( - const Word32 core_brate_fx, /* i : core bitrate */ - const Word16 *speech16k_fx, /* i : original speech at 16 kHz */ - const Word16 Aq_fx[], /* i : quantized Aq */ - const Word16 exc_fx[], /* i : excitation at 12.8 kHz */ - Word16 synth_fx[], /* i : 12.8kHz synthesis signal */ - Word16 *seed2_enc_fx, /* i/o: random seed for HF noise gen */ - Word16 *mem_hp400_enc_fx, /* i/o: memory of hp 400 Hz filter */ - Word16 *mem_syn_hf_enc_fx, /* i/o: HF synthesis memory */ - Word16 *mem_hf1_enc_fx, /* i/o: HF band-pass filter memory */ - Word16 *mem_hf2_enc_fx, /* i/o: HF band-pass filter memory */ - const Word16 dtxHangoverCount_fx, - Word16 *gain_alpha_fx, /* i/o: smoothing gain for transitions between active and inactive frames */ - Word16 *hf_gain_fx, /* o : HF gain to be transmitted to decoder */ - Word16 Q_exc, - Word16 Q_syn -); - -void re8_compute_base_index_fx( - const Word16 *x, /* i : Elemen of Q2, Q3 or Q4 */ - const Word16 ka, /* i : Identifier of the absolute leader related to x */ - UWord16 *I /* o : index */ -); - -void InitSWBencBuffer_fx( - Encoder_State_fx* st_fx /* i/o: SHB encoder structure */ -); - -void ResetSHBbuffer_Enc_fx( - Encoder_State_fx* st_fx /* i/o: SHB encoder structure */ -); -void wb_tbe_extras_reset_synth_fx( Word16 state_lsyn_filt_shb[], Word16 state_lsyn_filt_dwn_shb[], - Word16 state_32and48k_WB_upsample[] - ,Word16 state_resamp_HB[] - ); - -void pz_filter_sp_fx ( - const Word16 b [], - const Word16 a [], - Word16 x [], - Word16 y [], - Word16 buf [], - Word16 PNR, - Word16 PDR, - Word16 N, - Word16 Qa -); - -void Decimate_allpass_steep_fx( - const Word16 *in_fx, - Word16 state_fx[], /* array of size: 2*ALLPASSSECTIONS_STEEP+1 */ - Word16 N, /* number of input samples */ - Word16 out_fx[] /* array of size N/2 */ -); - -Word32 root_a_fx( - Word32 a, - Word16 Q_a, - Word16 *exp_out -); - -Word32 root_a_over_b_fx( - Word32 a, - Word16 Q_a, - Word32 b, - Word16 Q_b, - Word16 *exp_out -); - - -void fir_fx( - const Word16 x[], /* i : input vector */ - const Word16 h[], /* i : impulse response of the FIR filter */ - Word16 y[], /* o : output vector (result of filtering) */ - Word16 mem[], /* i/o: memory of the input signal (M samples) */ - const Word16 L, /* i : input vector size */ - const Word16 K, /* i : order of the FIR filter (M+1 coefs.) */ - const Word16 upd, /* i : 1 = update the memory, 0 = not */ - Word16 shift /* i : difference between Q15 and scaling of h[] */ -); - - -void Interpolate_allpass_steep_fx( - const Word16 *in_fx, /* i : input signal */ - Word16 state_fx[], /* array of size: 2*ALLPASSSECTIONS_STEEP+1 */ - Word16 N, /* number of input samples */ - Word16 out_fx[] /* o : output signal, size 2*N */ -); - -void interpolate_3_over_2_allpass_fx( - const Word16 *input_fx, - const Word16 len, - Word16 *out_fx, - Word16 *mem_fx, - const Word16 *filt_coeff_fx -); -void interpolate_3_over_1_allpass_fx( - const Word16 *input_fx, - const Word16 len, - Word16 *out_fx, - Word16 *mem_fx, - const Word16 *filt_coeff_fx -); -void decimate_2_over_3_allpass_fx( - const Word16 *input_fx, - const Word16 len, - Word16 *out_fx, - Word16 *mem_fx, - const Word16 *filt_coeff_fx, - const Word16 *lp_num_fx, - const Word16 *lp_den_fx, - Word16 *lp_mem_fx -); - -void retro_interp4_5_fx( - const Word16 *syn_fx, - Word16 *pst_old_syn_fx -); -void retro_interp5_4_fx( - Word16 *pst_old_syn_fx -); - -void lsp2lpc_fx( - Word16 *a, - Word16 *freq, - Word16 *prev_a, - Word16 order -); - -void PostShortTerm_fx( - Word16 *sig_in, /* i : input signal (pointer to current subframe */ - Word16 *lpccoeff, /* i : LPC coefficients for current subframe */ - Word16 *sig_out, /* o : postfiltered output */ - Word16 *mem_stp, /* i/o: postfilter memory*/ - Word16 *ptr_mem_stp, /* i/o: pointer to postfilter memory*/ - Word16 *ptr_gain_prec, /* i/o: for gain adjustment*/ - Word16 *mem_zero, /* i/o: null memory to compute h_st*/ - Word16 formant_fac_fx /* i : Strength of post-filter*/ -); - -void GenShapedWBExcitation_fx( - Word16 *excSHB, /* o : synthesized shaped shb exctiation */ - const Word16 *lpc_shb, /* i : lpc coefficients */ - Word16 *exc4kWhtnd, /* o : whitened synthesized shb excitation */ - Word32 *mem_csfilt, /* i/o : memory */ - Word16 *mem_genSHBexc_filt_down1, /* i/o : memory */ - Word16 *mem_genSHBexc_filt_down2, /* i/o : memory */ - Word16 *mem_genSHBexc_filt_down3, /* i/o : memory */ - Word16 *state_lpc_syn, /* i/o : memory */ - const Word16 coder_type, /* i : coding type */ - const Word16 *bwe_exc_extended, /* i : bandwidth extended exciatation */ - const Word16 Q_bwe_exc, - Word16 bwe_seed[], /* i/o : random number generator seed */ - const Word16 voice_factors[], /* i : voicing factor */ - const Word16 signal_type - , const Word16 igf_flag -); - -void GenWBSynth_fx( - const Word16 *input_synspeech, /* i : input synthesized speech */ - Word16 *shb_syn_speech_16k, /* o : output highband compnent */ - Word16 *state_lsyn_filt_shb1, /* i/o: memory */ - Word16 *state_lsyn_filt_shb2 /* i/o: memory */ -); - -void GenSHBSynth_fx( - const Word16 *shb_target_speech, /* i : input synthesized speech */ - Word16 *shb_syn_speech_32k, /* o : output highband component */ - Word32 Hilbert_Mem[], /* i/o: memory */ - Word16 genSHBsynth_allpass_mem[], /* i/o: memory */ - const Word16 L_frame, /* i : ACELP Frame length */ - Word16 *syn_dm_phase -); - -Word16 swb_formant_fac_fx( /* o : Formant filter strength [0,1] */ - const Word16 lpc_shb2, /* Q12 i : 2nd HB LPC coefficient */ - Word16* tilt_mem /* i/o: Tilt smoothing memory */ -); - -void compute_poly_product_fx(Word16 *coef, Word32 *p,Word16 order); - -void ScaleShapedSHB_fx( - const Word16 length, /* i : SHB overlap length */ - Word16 *synSHB, /* i/o: synthesized shb signal */ - Word16 *overlap, /* i/o: buffer for overlap-add */ - const Word16 *subgain, /* i : subframe gain */ - const Word32 frame_gain, /* i : frame gain */ - const Word16 *win, /* i : window */ - const Word16 *subwin, /* i : subframes window */ - Word16 *Q_bwe_exc - ,Word16 *Qx - ,Word16 n_mem3 - ,Word16 prev_Q_bwe_syn2 -); - -void ScaleShapedWB_fx( - const Word16 length, /* i : SHB overlap length */ - Word16* synSHB, /* i/o : synthesized shb signal */ - Word16* overlap, /* i/o : buffer for overlap-add */ - const Word16* subgain, /* i : subframe gain */ - const Word32 frame_gain, /* i : frame gain */ - const Word16* win, /* i : window */ - const Word16* subwin, /* i : subframes window */ - const Word16 Q_bwe_exc - ,Word16 L_frame /* i : Frame length - determines whether 12.8 or 16kHz core in-use */ - ,Word16 dynQ /* i : indicate whether output is dynamic Q, or Q0 */ - ,Word16* Qx /* o : newly computed Q factor for synSHB */ - ,Word16 prev_Qx /* i : prev_Qx for memory scaling */ - ,Word32* Hilbert_Mem /* i : Hilbert memory used for computing Qx */ -); - -void GenShapedSHBExcitation_fx( - Word16 *excSHB, /* o : synthesized shaped shb excitation Q_bwe_exc*/ - const Word16 *lpc_shb, /* i : lpc coefficients Q12*/ - Word16 *White_exc16k_FB, /* o : white excitation for the Fullband extension Q_bwe_exc */ - Word32 *mem_csfilt, /* i/o: memory */ - Word16 *mem_genSHBexc_filt_down_shb, /* i/o: memory */ - Word16 *state_lpc_syn, /* i/o: memory */ - const Word16 coder_type, /* i : coding type */ - const Word16 *bwe_exc_extended, /* i : bandwidth extended excitation */ - Word16 bwe_seed[], /* i/o: random number generator seed */ - Word16 voice_factors[], /* i : voicing factor*/ - const Word16 extl, /* i : extension layer */ - Word16 *tbe_demph, /* i/o: de-emphasis memory */ - Word16 *tbe_premph, /* i/o: pre-emphasis memory */ - Word16 *lpc_shb_sf, /* i: LP coefficients */ - const Word32 shb_ener_sf_32, - Word16 *shb_res_gshape, - Word16 *shb_res, - Word16 *vf_ind, - const Word16 formant_fac, /* i : Formant sharpening factor [0..1] */ - Word16 fb_state_lpc_syn[], /* i/o: memory */ - Word16 *fb_tbe_demph, /* i/o: fb de-emphasis memory */ - Word16 *Q_bwe_exc, - Word16 *Q_bwe_exc_fb, - const Word16 Q_shb, - Word16 n_mem2, /* i : n_mem2 scale factor to adjust 24.4/32kbps memories */ - Word16 prev_Q_bwe_syn, /* i : st_fx->prev_Q_bwe_syn */ - const Word32 bitrate, - const Word16 prev_bfi -); - - -void space_lsfs_fx ( - Word16 *lsfs, /* i/o: Line spectral frequencies */ - const Word16 order /* i : order of LP analysis */ -); - - -void lsp_weights_fx( - Word16 lsp_nq_fx[], - Word16 w[], - Word16 Order, - Word16 *Qout -); - - -void lsp_convolve_fx(Word32 x, Word32 *p1, Word32 *p2, Word16 len); -Word32 poscos_fx(Word16 w); - -void flip_spectrum_and_decimby4_fx( - const Word16 input[], /* i : input spectrum */ - Word16 output[], /* o : output spectrum */ - const Word16 length, /* i : vector length */ - Word16 mem1[], /* i/o : memory */ - Word16 mem2[], /* i/o : memory */ - const Word16 ramp_flag /* i : flag to trigger slow ramp-up of output following change of core */ -); - - -Word16 lpc2lsp_fx( - Word32 *a, - Word16 *freq, - Word16 *old_freq, - Word16 order -); - -Word16 usquant_fx( /* o: index of the winning codeword */ - const Word16 x, /* i: scalar value to quantize Qx*/ - Word16 *xq, /* o: quantized value Qx*/ - const Word16 qlow, /* i: lowest codebook entry (index 0) Qx*/ - const Word16 delta, /* i: quantization step Qx-1*/ - const Word16 cbsize /* i: codebook size */ -); - -void wb_tbe_enc_fx( - Encoder_State_fx *st_fx, /* i/o: encoder state structure */ - const Word16 coder_type, /* i : coding type */ - const Word16 *hb_speech, /* i : HB target signal (6-8kHz) at 16kHz */ - const Word32 *bwe_exc_extended, /* i : bandwidth extended exciatation */ - const Word16 Q_new, /* i : input HB speech Q factor */ - const Word16 voice_factors[], /* i : voicing factors */ - const Word16 pitch_buf[], /* i : pitch for each subframe */ - const Word16 voicing[] /* i : OL maximum normalized correlation */ -); - -void wb_pre_proc_fx( - Encoder_State_fx *st_fx, /* i/o: encoder state structure */ - const Word16 *new_inp_resamp16k, /* i : original input signal */ - Word16 *hb_speech /* o : HB target signal (6-8kHz) at 16kHz */ -); - - -void pz_filter_dp_fx ( - const Word16 b [], - const Word16 a [], - Word16 x [], - Word16 y [], - Word32 buf [], - Word16 PNR, - Word16 PDR, - Word16 N, - Word16 Qa -); - -void flip_and_downmix_generic_fx( - Word16 input[], /* i : input spectrum */ - Word16 output[], /* o : output spectrum */ - const Word16 length, /* i : length of spectra */ - Word32 mem1_ext[HILBERT_ORDER1], /* i/o: Hilbert filter memory */ - Word32 mem2_ext[2*HILBERT_ORDER2], /* i/o: memory */ - Word32 mem3_ext[2*HILBERT_ORDER2], /* i/o: memory */ - Word16 *phase_state /* i/o: Phase state in case frequency isn't multiple of 50 Hz */ -); - - -void wb_tbe_dec_fx( - Decoder_State_fx *st_fx, /* i/o: decoder state structure */ - const Word16 coder_type, /* i : coding type */ - Word32 *bwe_exc_extended, /* i : bandwidth extended exciatation */ - const Word16 Q_exc, - const Word16 voice_factors[], /* i : voicing factors */ - Word16 *synth, /* i/o: ACELP core synthesis/final synthesis */ - Word16 *Q_synth -); - -void swb_tbe_enc_fx( - Encoder_State_fx *st_fx, /* i/o: encoder state structure */ - const Word16 coder_type_fx, /* i : coding type */ - Word16 *new_speech_fx, /* i : original input signal */ - Word32 *bwe_exc_extended_fx, /* i : bandwidth extended excitation */ - const Word16 voice_factors_fx[], /* i : voicing factors */ - Word16 *White_exc16k_fx, /* o : shaped white excitation for the FB TBE */ - Word16 *Q_white_exc, /* o : generated white noise for FB Q factor */ - Word16 Q_bwe_exc, /* i : bandwidth extended excitation Q factor */ - Word16 Q_shb, /* i : SHB target Q factor */ - Word16 *voicing_fx, /* i : OL maximum normalized correlation */ - const Word16 pitch_buf[] /* i : pitch for each subframe */ -); - -void swb_pre_proc_fx( - Encoder_State_fx *st_fx, /* i/o: encoder state structure */ - const Word16 *input_fx, /* i : original input signal */ - Word16 *new_swb_speech_fx, /* o : original input signal at 32kHz */ - Word16 *shb_speech_fx, /* o : SHB target signal (6-14kHz) at 16kHz */ - Word16 *Q_shb_spch /* o : shb target signal Q factor */ - , Word32 realBuffer[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX] /* i : real buffer */ - , Word32 imagBuffer[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX] /* i : imag buffer */ - ,const CLDFB_SCALE_FACTOR *cldfbScale /* i : scale data of real and imag CLDFB buffers */ -); - -void wb_tbe_extras_reset_fx( - Word16 mem_genSHBexc_filt_down_wb2[], - Word16 mem_genSHBexc_filt_down_wb3[] -); - -void swb_tbe_reset_synth_fx( - Word32 genSHBsynth_Hilbert_Mem[], - Word16 genSHBsynth_state_lsyn_filt_shb_local_fx[] -); - -void swb_tbe_reset_fx( - Word32 mem_csfilt[], - Word16 mem_genSHBexc_filt_down_shb[], - Word16 state_lpc_syn[], - Word16 syn_overlap[], - Word16 state_syn_shbexc[], - Word16 *tbe_demph, - Word16 *tbe_premph, - Word16 mem_stp_swb[], - Word16 *gain_prec_swb -); - -void InitSWBdecBuffer_fx( - Decoder_State_fx *swb_dnc_fx /* i/o: SHB decoder structure */ -); - -void ResetSHBbuffer_Dec_fx( - Decoder_State_fx *st_fx /* i/o: decoder state structure */ -); - -Word16 squant_fx( /* o: index of the winning codeword */ - const Word16 x, /* i: scalar value to quantize */ - Word16* xq, /* o: quantized value */ - const Word16 cb[], /* i: codebook */ - const Word16 cbsize /* i: codebook size */ -); - -void swb_tbe_dec_fx( - Decoder_State_fx* st_fx, /* i/o: decoder state structure */ - const Word16 coder_type, /* i : coding type */ - Word32* bwe_exc_extended, /* i : bandwidth extended exciatation 2*Q_exc*/ - Word16 Q_exc, - const Word16 voice_factors[], /* i : voicing factors */ - const Word16 old_syn_12k8_16k[], /* i : low band synthesis*/ - Word16* White_exc16k, /* o : shaped white excitation for the FB TBE */ - Word16* Q_white_exc, - Word16* synth, /* o : SHB synthesis/final synthesis */ - Word16* Q_synth, - Word16* pitch_buf -); - - -void tbe_write_bitstream_fx( - Encoder_State_fx *st_fx /* i/o: encoder state structure */ -); - -void tbe_read_bitstream_fx( - Decoder_State_fx *st_fx /* i/o: encoder state structure */ -); - -Word16 get_tbe_bits_fx( /* o : TBE bit consumption per frame */ - Word32 bitrate, /* i : overall bitrate */ - Word16 bandwidth /* i : bandwidht mode */ - ,Word16 rf_mode -); - -void GenTransition_fx( - const Word16 *input, /* i : gain shape overlap buffer */ - const Word16 *old_hb_synth, /* i : synthesized HB from previous frame */ - Word16 length, /* i : targeted length of transition signal */ - Word16 *output, /* o : synthesized transitions signal */ - Word32 Hilbert_Mem[], /* i/o: memory */ - Word16 state_lsyn_filt_shb_local[],/* i/o: memory */ - Word16 *syn_dm_phase, - Word32 output_Fs, - Word16 *up_mem, - Word16 rf_flag - , Word32 bitrate -); - -void GenTransition_WB_fx( - const Word16 *input, /* i : gain shape overlap buffer */ - const Word16 *old_hb_synth, /* i : synthesized HB from previous frame */ - const Word16 prev_Qx, /* i : scaling of old_hb_synth */ - Word16 length, /* i : targeted length of transition signal */ - Word16 *output, /* o : synthesized transitions signal */ - Word16 state_lsyn_filt_shb1[], - Word16 state_lsyn_filt_shb2[], - Word32 output_Fs, - Word16 *up_mem -); - -void TBEreset_enc_fx( - Encoder_State_fx *st_fx, /* i/o: encoder state structure */ - Word16 bandwidth /* i : bandwidth mode */ -); - -void TBEreset_dec_fx( - Decoder_State_fx *st_fx, /* i/o: decoder state structure */ - Word16 bandwidth /* i : bandwidth mode */ -); - -void fb_tbe_enc_fx( - Encoder_State_fx *st, /* i/o: encoder state structure */ - const Word16 new_input[], /* i : input speech at 48 kHz sample rate */ - const Word16 fb_exc[], /* i : FB excitation from the SWB part */ - Word16 Q_fb_exc -); - -void fb_tbe_dec_fx( - Decoder_State_fx *st, /* i/o: encoder state structure */ - const Word16 fb_exc[], /* i : FB excitation from the SWB part */ - Word16 Q_fb_exc, - Word16 *hb_synth, /* o : high-band synthesis */ - Word16 hb_synth_exp -); - -void elliptic_bpf_48k_generic_fx( - const Word16 input_fx[], /* i : input signal */ - Word16 *Q_input_fx, - Word16 output_fx[], /* o : output signal */ - Word32 memory_fx[][4], /* i/o: 4 arrays of 4 for memory */ - Word16 memory_fx_Q[], - const Word16 full_band_bpf[][5] /* i : filter coefficients b0,b1,b2,a0,a1,a2 Q13 */ -); -void synthesise_fb_high_band_fx( - const Word16 excitation_in[], /* i : full band excitation */ - Word16 Q_fb_exc, - Word16 output[], /* o : high band speech - 14.0 to 20 kHz */ - const Word32 fb_exc_energy, /* i : full band excitation energy */ - const Word16 ratio, /* i : energy ratio */ - const Word16 L_frame, /* i : ACELP frame length */ - const Word16 bfi, /* i : fec flag */ - Word16 *prev_fbbwe_ratio, /* o : previous frame energy for FEC */ - Word32 bpf_memory[][4], /* i/o: memory for elliptic bpf 48k */ - Word16 bpf_memory_Q[], - Word16 Qout -); - -void lsf_syn_mem_restore_fx( - Encoder_State_fx *st_fx, /* o: state structure */ - LPD_state* LPDmem, /* o: LPD_state vewctor */ - Word16 btilt_code_fx, /* i: */ - Word32 gc_threshold_fx, /* i: */ - Word16 *clip_var_bck_fx, /* i: */ - Word16 next_force_sf_bck_fx, /* i: */ - Word16 *lsp_new, /* o: LSP vector to quantize */ - Word16 *lsf_new, /* o: quantized LSF vector */ - Word16 *lsp_mid, /* o: mid-frame LSP vector */ - Word16 clip_var, /* i: pitch clipping state var */ - Word16 *mem_AR, /* i: quantizer memory for AR model */ - Word16 *mem_MA, /* i: quantizer memory for MA model */ - Word16 *lsp_new_bck, /* i: LSP vector to quantize- backup */ - Word16 *lsf_new_bck, /* i: quantized LSF vector - backup */ - Word16 *lsp_mid_bck, /* i: mid-frame LSP vector - backup */ - Word16 mCb1, /* i: counter for stationary frame after a transition frame */ - Word32 *Bin_E, /* i: FFT Bin energy 128 *2 sets */ - Word32 *Bin_E_old, /* i: FFT Bin energy 128 sets */ - Word16 *mem_syn_bck, /* i: synthesis filter memory */ - Word16 mem_w0_bck, /* i: memory of the weighting filter */ - Word16 streaklimit, /* i:LSF quantizer */ - Word16 pstreaklen /* i:LSF quantizer */ -); - -void encod_nelp_fx( - Encoder_State_fx *st_fx, /* i/o: state structure */ - LPD_state *mem, /* i/o: acelp memories */ - const Word16 *speech_fx, /* i : input speech */ - const Word16 Aw_fx[], /* i : weighted A(z) unquantized for subframes */ - const Word16 Aq_fx[], /* i : 12k8 Lp coefficient */ - Word16 *res_fx, /* o : residual signal */ - Word16 *synth_fx, /* o : core synthesis */ - Word16 *tmp_noise_fx, /* o : long-term noise energy */ - Word16 *exc_fx, /* i/o: current non-enhanced excitation */ - Word16 *exc2_fx, /* i/o: current enhanced excitation */ - Word16 *pitch_buf_fx, /* o : floating pitch values for each subframe */ - Word16* voice_factors_fx, /* o : voicing factors */ - Word16* bwe_exc_fx, /* o : excitation for SWB TBE */ - Word16 Q_new, - Word16 shift -); - -void nelp_encoder_fx( - Encoder_State_fx *st_fx, /* i/o: encoder state */ - Word16 *in_fx, /* i : residual signal */ - Word16 *exc_fx, /* o : NELP quantized excitation signal */ - Word16 *qIn1 - ,Word16 reduce_gains -); - -Word16 dequantize_uvg_fx( - Word16 iG1, /* i: gain 1 index */ - Word16 *iG2, /* i: gain 2 index */ - Word16 *G, /* o: quantized gain */ - Word16 bandwidth /* i: bandwidth */ - ,Word16 do_scale -); - -void quantize_uvg_fx( - Word16 *G, - Word16 *iG1, - Word16 *iG2, - Word16 *quantG, - Word16 bandwidth -); - - -void generate_nelp_excitation_fx( - Word16 *seed, - Word16 *Gains, - Word16 *output, - Word16 gain_fac -); - - -Word16 find_rem( - Word16 n, - Word16 m, - Word16 *r -); - -Word32 find_remd( - Word32 n, - Word32 m, - Word32 *r -); - -void set_ppp_mode_fx( - Encoder_State_fx *st_fx, /* i/o: state structure */ - Word16 *coder_type /* i : coding type */ - ,const Word16 noisy_speech_HO, /* i : SC-VBR noisy speech HO flag */ - const Word16 clean_speech_HO, /* i : SC-VBR clean speech HO flag */ - const Word16 NB_speech_HO, /* i : SC-VBR NB speech HO flag */ - const Word16 localVAD, - const Word16 localVAD_he, /* i : HE-SAD flag without hangover */ - Word16 *vad_flag - ,Word16 T_op_fx[] /* i : open loop pitch lag */ - ,Word16 sp_aud_decision1 /* i : Speech Audio Decision */ -); - -void update_average_rate_fx( - Encoder_State_fx *st_fx /* i/o: encoder state structure */ -); - - -void encod_ppp_fx( - Encoder_State_fx * st_fx, /* i/o: state structure */ - LPD_state *mem, /* i/o: acelp memories */ - const Word16 speech_fx[], /* i : input speech Q_new*/ - const Word16 Aw_fx[], /* i : weighted A(z) unquantized for subframes */ - const Word16 Aq_fx[], /* i : 12k8 Lp coefficient */ - Word16 *coder_type, /* i/o : coding type */ - Word16 sharpFlag_fx, /* i : formant sharpening flag */ - const Word16 T_op_fx[], /* i : open loop pitch */ - const Word16 voicing_fx[], /* i : voicing Q14*/ - Word16 *res_fx, /* i/o: residual signal Q_new*/ - Word16 *synth_fx, /* i/o: core synthesis Q-1*/ - Word16 *exc_fx, /* i/o: current non-enhanced excitation Q_new*/ - Word16 *exc2_fx, /* o: current enhanced excitation Q0*/ - Word16 *pitch_buf_fx, /* o: floating pitch values for each subframe Q6*/ - Word16 *voice_factors, /* o : voicing factors */ - Word16 *bwe_exc, /* o : excitation for SWB TBE */ - Word16 Q_new, - Word16 shift -); - -void ppp_voiced_encoder_fx( - Encoder_State_fx *st_fx, /* i/o: state structure */ - Word16 *in_fx, /* i : residual signal */ - Word16 *out_fx, /* o : Quantized residual signal */ - Word16 delay_fx, /* i : open loop pitch */ - Word16 *lpc1_fx, /* i : prev frame de-emphasized LPC */ - Word16* lpc2_fx, /* i : current frame de-emphasized LPC */ - Word16 *exc_fx, /* i: previous frame quantized excitation */ - Word16 *pitch_fx, /* o: floating pitch values for each subframe */ - Word16 vadsnr_fx, /* i: current frame SNR Q7*/ - Word16 Qres -); - -Word16 rint_new_fx( - Word32 x /* i/o: Round to the nearest integer with mid point exception */ -); - -void decod_nelp_fx( - Decoder_State_fx *st_fx, /* i/o: decoder static memory */ - const Word16 coder_type, /* i : coding type */ - Word16 *tmp_noise_fx, /* o : long term temporary noise energy */ - Word16 *pitch_buf_fx, /* o : floating pitch values for each subframe*/ - Word16 *exc_fx, /* o : adapt. excitation exc */ - Word16 *exc2_fx, /* o : adapt. excitation/total exc */ - Word16 *voice_factors, /* o : Voice factor */ - Word16 *bwe_exc, - Word16 *Q_exc, - Word16 bfi /* i : frame error rate */ - , Word16 *gain_buf /*Q14*/ -); - -void nelp_decoder_fx( - Decoder_State_fx *st, /* i/o: decoder static memory */ - Word16 *exc_nelp, /* o : adapt. excitation/total exc */ - Word16 *exc, /* o : adapt. excitation exc */ - Word16 *Q_exc, - Word16 bfi, /* i : frame error rate */ - const Word16 coder_type /* i : coding type */ - , Word16 *gain_buf /*Q14*/ -); - -void core_switching_pre_dec_fx( - Decoder_State_fx *st_fx, /* i/o: decoder state structure */ - const Word16 output_frame /* i : frame length */ -); - -void fb_tbe_reset_synth_fx( - Word32 fbbwe_hpf_mem_fx[][4], - Word16 fbbwe_hpf_mem_fx_Q[], - Word16 *prev_fbbwe_ratio_fx -); - -void core_switching_post_dec_fx( - Decoder_State_fx *st_fx, /* i/o: decoder state structure */ - Word16 *synth, /* i/o: output synthesis Qsynth */ - const Word16 output_frame, /* i : frame length */ - const Word16 core_switching_flag, /* i : ACELP->HQ switching flag */ - const Word16 coder_type, /* i : ACELP coder type */ - Word16 *Qsynth -); -void acelp_core_switch_dec_bfi_fx( - Decoder_State_fx *st_fx, /* i/o: decoder state structure */ - Word16 synth_out[], /* o : synthesis Q_syn */ - const Word16 coder_type /* i : coder type */ -); -void acelp_core_switch_dec_fx( - Decoder_State_fx *st_fx, /* decoder state structure */ - Word16 *synth_subfr_out, /* o synthesized ACELP subframe Q_syn*/ - Word16 *tmp_synth_bwe, /* o synthesized ACELP subframe BWE Q_syn*/ - const Word16 output_frame, /* i : input frame legth */ - const Word16 core_switching_flag, /* i : core switching flag */ - Word16 *mem_synth, /* o : synthesis to overlap */ - Word16 *Q_syn -); - -void core_switching_hq_prepare_dec_fx( - Decoder_State_fx *st_fx, /* i/o: encoder state structure */ - Word16 *num_bits, /* i/o: bit budget update */ - const Word16 output_frame /* i : output frame length */ -); -void fb_tbe_reset_enc_fx( - Word32 elliptic_bpf_2_48k_mem_fx[][4], - Word32 *prev_fb_energy_fx, - Word16 elliptic_bpf_2_48k_mem_fx_Q[], - Word16 *prev_fb_energy_fx_Q -); - -void core_switching_OLA_fx( - Word16 *mem_over_hp, /* i : upsampling filter memory Q0 */ - const Word16 last_L_frame, /* i : last L_frame lengthture */ - const Word32 output_Fs, /* i : output sampling rate */ - Word16 *synth, /* i/o: synthesized signal from HQ core Q0 */ - Word16 *synth_subfr_out, /* i : synthesized signal from ACELP core Q0 */ - Word16 *synth_subfr_bwe, /* i : synthesized BWE from ACELP core Q0 */ - const Word16 output_frame, /* i : output frame length */ - const Word16 bwidth, /* i : output bandwidth */ - Word16* Qsynth, - Word16* Qsubfr -); - -void acelp_core_switch_enc_fx( - Encoder_State_fx *st_fx, /* i/o: encoder state structure */ - LPD_state *mem, - const Word16 inp12k8[], /* i : input signal @12.8 kHz Q0 */ - const Word16 inp16k[], /* i : input signal @16 kHz Q0 */ - const Word16 T_op_orig[2], /* i : open-loop pitch values for quantiz. Q0*/ - const Word16 voicing[3], /* i : Open-loop pitch gains Q15 */ - const Word16 A[NB_SUBFR16k*(M+1)], /* i : A(z) unquantized for the 4 subframes Q12*/ - Word16 shift, - Word16 Q_new -); - -void core_switching_hq_prepare_enc_fx( - Encoder_State_fx *st_fx, /* i/o: encoder state structure */ - Word16 *num_bits, /* i/o: bit budget update */ - const Word16 input_frame, /* i : frame length */ - Word32 *wtda_audio, /* shall be q_audio + 15, audio allready scalled in wtda function */ - const Word16 *audio -); - -void core_switching_pre_enc_fx( - Encoder_State_fx *st_fx, /* i/o: encoder state structure */ - LPD_state *mem, /* i/o: encoder state structure */ - const Word16 *old_inp_12k8, /* i : old input signal @12.8kHz */ - const Word16 *old_inp_16k /* i : old input signal @16kHz */ -); - -void core_switching_post_enc_fx( /*done */ - Encoder_State_fx *st_fx, /* i/o: encoder state structure */ - const Word16 inp12k8[], /* i : input signal @12.8 kHz */ - const Word16 inp16k[], /* i : input signal @16 kHz */ - const Word16 T_op[2], /* i : open-loop pitch values for quantiz. */ - const Word16 voicing[3], /* i : Open-loop pitch gains */ - const Word16 A[], /* i : unquant. LP filter coefs. (Q12) */ - Word16 Qshift, - Word16 Q_new, - const Word16 Qsp, /* i/o : Q from acelp synthsis */ - Word16 *Qmus /* i/o : Q from mdct synthsis / Q of output synthesis */ -); - -Word16 modify_Fs_intcub3m_sup_fx( /* o : length of output */ - const Word16 sigIn[], /* i : signal to decimate with memory of 2 samples (indexes -2 & -1) */ - const Word16 lg, /* i : length of input (suppose that lg is such that lg_out is integer, ex multiple of 5 in case of 16kHz to 12.8 kHz) */ - const Word32 fin, /* i : frequency of input */ - Word16 sigOut[], /* o : decimated signal */ - const Word32 fout, /* i : frequency of output */ - Word16 *delayout /* o : delay of output */ -); -void add_vec_fx( - const Word16 x1[], /* i : Input vector 1 */ - const Word16 Qx1, /* i : SCaling of iput 1 */ - const Word16 x2[], /* i : Input vector 2 */ - const Word16 Qx2, /* i : SCaling of iput 1 */ - Word16 y[], /* o : Output vector that contains vector 1 + vector 2 */ - const Word16 Qy, /* i : SCaling of output 1 */ - const Word16 N /* i : Vector lenght */ -); - -/******************************* wrappers related functions **************/ -void convert_fl_2_fx(const float *var_fl, Word16 *var_fx, Word16 count, Word16 Q_format); -void convert_fl_2_fx_32(const float *var_fl, Word32 *var_fx, Word16 count, Word16 Q_format); -void convert_fl_2_fx_32_MIN(const float *var_fl, Word32 *var_fx, Word16 count, Word16 Q_format, Word32 MIN_VAL); -void convert_sh_2_fx(const short *var_fl, Word16 *var_fx, Word16 count, Word16 Q_format); -void convert_dl_2_fx_32(double *var_fl, Word32 *var_fx, Word16 count, Word16 Q_format); -void convert_fx_2_fl(float *var_fl, const Word16 *var_fx, Word16 count, Word16 Q_format); -void convert_fx_2_sh(short *var_fl, const Word16 *var_fx, Word16 count, Word16 Q_format); -void convert_fx_2_dl_32(double *var_fl, const Word32 *var_fx, Word16 count, Word16 Q_format); -void convert_fx_2_fl_32(float *var_fl, const Word32 *var_fx, Word16 count, Word16 Q_format); -void convert_fx_2_fl_32_floor(float *var_fl, const Word32 *var_fx, Word16 count, Word16 Q_format); -/* void pre_proc_acelp_core_dec(Decoder_State *st,Decoder_State_fx *st_fx); */ -/* void post_proc_acelp_core_dec(Decoder_State *st,Decoder_State_fx *st_fx); */ - -void convert_fl_2_fx_q(const float *x, Word16 *x_fx, Word16 len, Word16 *q); -/******************************* END OF wrappers related functions **************/ - -/******************************* END of temporary Hybride function related functions **************/ - -void Copy_Scale_sig32_16( - const Word32 *src, /* i : signal to scale Qx */ - Word16 *dst, /* o : scaled signal Qx */ - Word16 len, /* i : size of x[] Q0 */ - Word16 exp0 /* i : exponent: x = round(x << exp) Qx ?exp */ -); -Word32 Add_flt32_flt32(/* o: Result */ - Word32 a, /* i: 1st Value */ - Word16 exp_a, /* i: Exponent of 1st Value (Q of Value) */ - Word32 b, /* i: 2nd Value */ - Word16 exp_b, /* i: Exponent of 2nd Value (Q of Value) */ - Word16 *exp_out /* o: Exponent of Result */ -); -Word32 Mul_flt32_Q15( /* o: Result (Normalized) */ - Word32 value, /* i: Pseudo_float Value */ - Word16 *exp_v, /*i/o: Exponent of Value (Q of Value) */ - Word16 frac /* i: Q15 value */ -); -Word32 Div_flt32_flt32(/* o: Result (Normalized) */ - Word32 a, /* i: 1st Value */ - Word16 exp_a, /* i: Exponent of 1st Value (Q of Value) */ - Word32 b, /* i: 2nd Value */ - Word16 exp_b, /* i: Exponent of 2nd Value (Q of Value) */ - Word16 *exp_out /* o: Exponent of Result */ -); -Word32 Calc_Energy_Autoscaled(/* o: Result (Energy) */ - const Word16 *signal, /* i: Signal */ - Word16 signal_exp, /* i: Exponent of Signal (Q of Signal) */ - Word16 len, /* i: Frame Length */ - Word16 *energy_exp /* o: Exponent of Energy (Q of Energy) */ -); -Word16 Find_Max_Norm16(const Word16 *src, Word16 len); -Word16 Find_Max_Norm32(const Word32 *src, Word16 len); -Word32 Sqrt_Ratio32(Word32 L_val1, Word16 exp1, Word32 L_val2, Word16 exp2, Word16 *exp); -Word16 Invert16( /* result in Q'15 + 'exp' */ - Word16 val, - Word16 *exp); - -void swb_bwe_enc_hr_fx( - Encoder_State_fx *st_fx, /* i/o: encoder state structure */ - Word16 *new_input_fx, /* i : input signal */ - Word16 new_input_fx_exp, /* i : Exponent of input signal */ - const Word16 input_frame, /* i : frame length */ - const Word16 coder_type, /* i : coding type */ - const Word16 unbits /* i : number of core unused bits */ -); - -void wtda_fx( - Word16 *new_audio, /* i : input audio Q0 */ - Word16 *Q, /* i/o : Q of Output Audio (use 15 for 'qout' for backward compatibility - NON SWB ENC HR FX MODULES) */ - Word32 *wtda_audio, /* o : windowed audio Qout */ - Word16 *old_wtda, /* i/o: windowed audio from previous frame Qout */ - Word16 *Qold_wtda, - Word16 left_mode, - Word16 right_mode, /* window overlap of current frame (0: full, 2: none, or 3: half) */ - const Word16 L -); - -void direct_transform_fx( - const Word32 in32_fx[], - Word32 out32_fx[], - const Word16 is_transient, - const Word16 L, - Word16 *Q -); - - -void r_fft_4_fx(Word16 * farray_ptr_fx, Word16 size, Word16 stage, Word16 isign); - -DTFS_STRUCTURE_FX* DTFS_new_fx( - void -); - -void DTFS_copy_fx( - DTFS_STRUCTURE_FX *Xout_fx, /* o: DTFS structure */ - DTFS_STRUCTURE_FX Xinp_fx /* i: DTFS structure */ -); - -DTFS_STRUCTURE_FX DTFS_sub_fx( - DTFS_STRUCTURE_FX X1, /* i: DTFS input 1 */ - DTFS_STRUCTURE_FX X2 /* i: DTFS input 2 */ -); /* o: X1 - X2 */ - - -void DTFS_to_fs_fx( - const Word16 *x, /* i : time domain signal */ - Word16 N, /* i : Length of input vector */ - DTFS_STRUCTURE_FX *X_fx, /* o : DTFS structure with a, b, lag */ - Word16 Fs, /* i : sampling rate */ - Word16 FR_flag, /* i: FR flag */ - Word16 *S_fx, - Word16 *C_fx -); - -void DTFS_fast_fs_inv_fx( DTFS_STRUCTURE_FX *This,Word16 *out_fx, Word16 N_fx, Word16 LOG2N); - -void DTFS_car2pol_fx( - DTFS_STRUCTURE_FX *X_fx /* i/o : DTFS structure a, b, lag */ -); -void copy_phase_fx( DTFS_STRUCTURE_FX *X1_fx, DTFS_STRUCTURE_FX X2_fx, DTFS_STRUCTURE_FX *retX_fx); -Word32 getSpEngyFromResAmp_fx( DTFS_STRUCTURE_FX *X_fx,Word16 lband, Word16 hband, - const Word16 *curr_lpc, Word16 *sin_tab, - Word16 *cos_tab); - -Word32 DTFS_setEngyHarm_fx( - Word16 f1_fx, /* i : lower band freq of input to control energy */ - Word16 f2_fx, /* i : upper band freq of input to control energy */ - Word16 g1_fx, /* i : lower band freq of output to control energy */ - Word16 g2_fx, /* i : upper band freq of output to control energy */ - Word32 en2_fx, /* i : Target Energy to set the DTFS to */ - Word16 Qen2_fx, /* i : Input Q format for en2 */ - Word16 *Qa_fx, /* i : Output Q format for x->a */ - DTFS_STRUCTURE_FX *X_fx /* i/o: DTFS to adjust the energy of */ -); - -void rshiftHarmBand_fx( DTFS_STRUCTURE_FX *X_fx,Word16 lband_fx, Word16 hband_fx, Word16 shift_fx); -void quant_target_fx( DTFS_STRUCTURE_FX *X_fx,const Word16 *curr_lpc, Word16 *w, Word16 *target, - Word16 *sin_tab, Word16 *cos_tab); - -void GetSinCosTab_fx(Word16 L, Word16 *sinTab, Word16 *cosTab); - -void DTFS_to_erb_fx( - const DTFS_STRUCTURE_FX X_fx, /* i : DTFS input */ - Word16 *out_fx /* o : ERB output */ -); - -void DTFS_zeroPadd_fx(Word16 N_fx,DTFS_STRUCTURE_FX *X_fx); - -Word32 DTFS_getEngy_fx( DTFS_STRUCTURE_FX *X_fx); - -Word32 DTFS_getEngy_P2A_fx( DTFS_STRUCTURE_FX *X_fx); - - -Word32 DTFS_getEngy_band_fx( - DTFS_STRUCTURE_FX X_fx, - Word16 lband, - Word16 hband -); - -Word32 DTFS_getEngy_band_wb_fx( - DTFS_STRUCTURE_FX X_fx, - Word16 lband, - Word16 hband -); - -Word32 DTFS_freq_corr_fx( - DTFS_STRUCTURE_FX X1_DTFS_fx, /* i : X1 DTFS */ - DTFS_STRUCTURE_FX X2_DTFS_fx, /* i : X2 DTFS */ - Word16 lband, /* i : low cutoff */ - Word16 hband, /* i : high cutoff */ - Word16 *Qout /* o : Correlation Q format */ -); /* o : Correlation */ - -Word32 DTFS_setEngy_fx( DTFS_STRUCTURE_FX *X_DTFS_FX,Word32 en2_fx); - -void DTFS_adjustLag_fx( - DTFS_STRUCTURE_FX *X_DTFS_FX, /* i/o : DTFS to adjust lag for */ - Word16 N_fx /* i : Target lag */ -); - -void DTFS_poleFilter_fx( DTFS_STRUCTURE_FX *X_fx,Word16 *LPC, Word16 N, Word16 *S_fx, Word16 *C_fx); -void DTFS_poleFilter_fx_9( DTFS_STRUCTURE_FX *X_fx, Word16 *pf_temp1, Word16 *pf_temp2, Word16 *pf_temp, Word16 *pf_n2_temp1); -void poleFilter_setup_fx(const Word16 *LPC, Word16 N, DTFS_STRUCTURE_FX X_fx, Word16 *S_fx, Word16 *C_fx, Word16 *pf_temp1, Word16 *pf_temp2, Word16 *pf_temp, Word16 *pf_n2_temp1); - -void DTFS_zeroFilter_fx( - DTFS_STRUCTURE_FX *X_fx, - Word16 *LPC, - Word16 N, - Word16 *S_fx, - Word16 *C_fx -); - -Word16 DTFS_alignment_full_fx( - DTFS_STRUCTURE_FX X1_DTFS_fx, /* i : reference DTFS */ - DTFS_STRUCTURE_FX X2_DTFS_fx, /* i : DTFS to shift */ - Word16 ph_offset_fx, /* i : resolution */ - Word16 *S_fx, - Word16 *C_fx - , Word16 FR_flag -); - -Word16 DTFS_alignment_extract_td_fx(Word16 *x1, Word16 *x2, Word16 lag); - -Word16 DTFS_alignment_weight_fx( - DTFS_STRUCTURE_FX *X_fx, - DTFS_STRUCTURE_FX X2, - Word16 Eshift, - const Word16 *LPC1, - const Word16 *LPC2, - Word16 *S_fx, - Word16 *C_fx, - Word16 *pf_temp1, - Word16 *pf_temp2, - Word16 *pf_temp, - Word16 *pf_n2 -); - - -Word16 DTFS_alignment_fine_new_fx( DTFS_STRUCTURE_FX X1_fx, DTFS_STRUCTURE_FX X2_fx, Word16 *S_fx, Word16 *C_fx); - - -void DTFS_phaseShift_fx( DTFS_STRUCTURE_FX *X_fx,Word16 ph, Word16 Lag, Word16 *S_fx, Word16 *C_fx); -void Q2phaseShift_fx( DTFS_STRUCTURE_FX *X_fx,Word16 ph, Word16 Lag, Word16 *S_fx, Word16 *C_fx); - - -void DTFS_erb_inv_fx( - Word16 *in_fx, /* i : ERB inpt */ - Word16 *slot_fx, /* i : ERB slots filled based on lag */ - Word16 *mfreq_fx, /* i : erb frequence edges */ - DTFS_STRUCTURE_FX *X_fx, /* o : DTFS after erb-inv */ - Word16 num_erb_fx /* i : Number of ERB bands */ -); - -void erb_add_fx( - Word16 *curr_erb_fx, /* i/o: current ERB */ - Word16 l_fx, /* i : current lag */ - const Word16 *prev_erb_fx, /* i : previous ERB */ - Word16 pl_fx, /* i : previous lag */ - const Word16 *index_fx, /* i : ERB index */ - Word16 num_erb_fx /* i : number of ERBs */ -); - -void LPCPowSpect_fx(Word16 *freq, Word16 Nf, Word16 *LPC, Word16 Np, - Word16 *out); - -void erb_slot_fx( - Word16 lag_fx, /* i : input lag */ - Word16 *out_fx, /* o : ERB slots */ - Word16 *mfreq_fx, /* i : ERB frequencies */ - Word16 num_erb_fx /* i : number of ERBs */ -); - -Word16 DTFS_quant_cw_fx( - DTFS_STRUCTURE_FX *X_fx, /* i/o: DTFS unquant inp, quant out */ - Word16 pl, /* i : Previous lag */ - const Word16 *curr_lpc_fx, /* i : LPC */ - Word16 *POWER_IDX, /* o : Power index */ - Word16 *AMP_IDX, /* o : Amplitude index */ - Word16 *lastLgainE_fx, /* i/o: last frame lowband gain */ - Word16 *lastHgainE_fx, /* i/o: last frame highband gain */ - Word16 *lasterbE_fx, /* i/o: last frame ERB vector */ - Word16 *sin_tab, - Word16 *cos_tab -); - - -void DTFS_dequant_cw_fx( - Word16 pl_fx, /* i : Previous lag */ - Word16 POWER_IDX_fx, /* i : POWER index */ - const Word16 *AMP_IDX_fx, /* i : Amp Shape index */ - Word16 *lastLgainD_fx, /* i/o: low band last gain */ - Word16 *lastHgainD_fx, /* i/o: high band last gain */ - Word16 *lasterbD_fx, /* i/o: last frame ERB vector */ - DTFS_STRUCTURE_FX *X_fx, /* o : DTFS structure dequantized */ - Word16 num_erb_fx -); - -void DTFS_transform_fx( - DTFS_STRUCTURE_FX X_fx, /* i : Starting DTFS to use in WI */ - DTFS_STRUCTURE_FX X2_fx, /* i : Ending DTFS to use in WI */ - const Word32 *phase_fx, /* i : Phase contour */ - Word16 *out_fx, /* o : Output time domain waveform */ - Word16 N, /* i : Number of samples to generate */ - Word16 FR_flag /* i : Flag to indicate called in FR context */ -); - -void DTFS_peaktoaverage_fx( - DTFS_STRUCTURE_FX X_fx, /* i : DTFS */ - Word32 *pos_fx, /* o : positive peak to ave */ - Word16 *Qpos, /* o : positive peak to ave Q format */ - Word32 *neg_fx, /* o : negative peak to ave */ - Word16 *Qneg /* o : negative peak to ave Q format */ -); - - - -Word16 ppp_extract_pitch_period_fx( - const Word16 *in, /* i : input residual */ - Word16 *out, /* o : output residual */ - Word16 l, /* i : lag */ - Word16 *out_of_bound, /* o : out of bound flag */ - Word16 Qres - -); - -void Interpol_delay_fx( - Word16 *out_fx, - Word16 last_fx, - Word16 current_fx, - Word16 SubNum, - const Word16* frac_fx -); - - -Word16 ppp_quarter_encoder_fx( - DTFS_STRUCTURE_FX *CURRCW_Q_FX, /* o : Quantized (amp/phase) DTFS */ - DTFS_STRUCTURE_FX *TARGETCW_FX, /* o : DTFS with quant phase but unquant Amp */ - Word16 prevCW_lag, /* i : previous lag */ - DTFS_STRUCTURE_FX CURRCW_NQ_FX, /* i : Unquantized DTFS */ - const Word16 *curr_lpc_fx, /* i : LPCS */ - Word16 *lastLgainE_fx, /* i/o: last low band gain */ - Word16 *lastHgainE_fx, /* i/o: last high band gain */ - Word16 *lasterbE_fx, /* i/o: last ERB vector */ - DTFS_STRUCTURE_FX PREV_CW_E_FX, /* i : past DTFS */ - Word16 *S_fx, /* i : sin table, Q15 */ - Word16 *C_fx, /* i : cos table, Q15 */ - Encoder_State_fx *st_fx -); - - -void WIsyn_fx( - DTFS_STRUCTURE_FX PREVCW_FX, - DTFS_STRUCTURE_FX *CURR_CW_DTFS_FX, - const Word16 *curr_lpc_fx, - Word16 *ph_offset_fx, - Word16 *out_fx, - Word16 N, - Word16 FR_flag, /* i : called for post-smoothing in FR */ - Word16 *S_fx, - Word16* C_fx, - Word16 *pf_temp1, - Word16 *pf_temp2, - Word16 *pf_temp, - Word16 *pf_n2 -); - -void deemph_lpc_fx( - Word16 *p_Aq_curr_fx, /* i : LP coefficients current frame */ - Word16 *p_Aq_old_fx, /* i : LP coefficients previous frame */ - Word16 *LPC_de_curr_fx, /* o : De-emphasized LP coefficients current frame */ - Word16 *LPC_de_old_fx, /* o : De-emphasized LP coefficients previous frame */ - Word16 deemph_old - -); - -Word16 erb_diff_search_fx(Word16 *prev_erb, const Word16 *curr_erb, Word16 *dif_erb, - Word16 *pow_spec, const Word16 *cb_fx, - Word16 cb_size, Word16 cb_dim, Word16 offset - ); - - -void Acelp_dec_total_exc( - Word16 *exc_fx, /* i/o: adapt. excitation exc */ - Word16 *exc2_fx, /* i/o: adapt. excitation/total exc */ - const Word16 gain_code16, /* i : Gain code Q0 */ - const Word16 gain_pit_fx, /* i ; Pitch gain in Q14 */ - const Word16 i_subfr, /* i ; subfr */ - const Word16 *code_fx /* i : code in Q12 */ -); -void tbe_celp_exc( - const Word16 L_frame_fx, /* i : Frame lenght */ - const Word16 i_subfr_fx, /* i : sub frame */ - const Word16 T0_fx, /* i : Integer pitch */ - const Word16 T0_frac_fx, /* i : Fractional part of the pitch */ - Word16 *error_fx, /* i/o: Error */ - Word16 *bwe_exc_fx /* i/o: bandwitdh extension signal */ -); -Word16 tbe_celp_exc_offset( - const Word16 T0_fx, /* i : Integer pitch */ - const Word16 T0_frac_fx, /* i : Fractional part of the pitch */ - const Word16 L_frame /* i : frame lenght */ -); -void lsf_syn_mem_backup_fx( - Encoder_State_fx *st_fx, /* i: state structure */ - LPD_state* LPDmem, /* i: LPD state memory structure */ - Word16 *btilt_code, /* i: tilt code */ - Word32 *bgc_threshold, /* i: */ - Word16 *clip_var_bck, /* o: */ - Word16 *next_force_sf_bck, /* o: */ - Word16 *lsp_new, /* i: LSP vector to quantize */ - Word16 *lsf_new, /* i: quantized LSF vector */ - Word16 *lsp_mid, /* i: mid-frame LSP vector */ - Word16 *clip_var, /* o: pitch clipping state var */ - Word16 *mem_AR, /* o: quantizer memory for AR model */ - Word16 *mem_MA, /* o: quantizer memory for AR model */ - Word16 *lsp_new_bck, /* o: LSP vector to quantize- backup */ - Word16 *lsf_new_bck, /* o: quantized LSF vector - backup */ - Word16 *lsp_mid_bck, /* o: mid-frame LSP vector - backup */ - Word16 *mCb1, /* o: counter for stationary frame after a transition frame */ - Word32 *Bin_E, /* o: FFT Bin energy 128 *2 sets */ - Word32 *Bin_E_old, /* o: FFT Bin energy 128 sets */ - Word16 *mem_syn_bck, /* o: synthesis filter memory */ - Word16 *mem_w0_bck, /* o: memory of the weighting filter */ - Word16 *streaklimit, - Word16 *pstreaklen -); - -void decod_ppp_fx( - Decoder_State_fx *st_fx, /* i/o: state structure */ - const Word16 Aq_fx[], /* i : 12k8 Lp coefficient */ - Word16 *pitch_buf_fx, /* i/o: fixed pitch values for each subframe */ - Word16 *exc_fx, /* i/o: current non-enhanced excitation */ - Word16 *exc2_fx, /* i/o: current enhanced excitation */ - Word16 bfi /* i : bad frame indicator */ - ,Word16 *gain_buf /*Q14*/ - ,Word16 *voice_factors, /* o : voicing factors */ - Word16 *bwe_exc_fx /* o : excitation for SWB TBE */ -); - -void ppp_quarter_decoder_fx( - DTFS_STRUCTURE_FX *CURRCW_Q_DTFS_FX, /* i/o: Current CW DTFS */ - Word16 prevCW_lag_fx, /* i : Previous lag */ - Word16 *lastLgainD_fx, /* i/o: Last gain lowband Q11 */ - Word16 *lastHgainD_fx, /* i/o: Last gain highwband Q11 */ - Word16 *lasterbD_fx, /* i/o: Last ERB vector Q13 */ - Word16 bfi, /* i : FER flag */ - Word16 *S_fx, /* i : sine table, Q15 */ - Word16 *C_fx, /* i : cosine table, Q15 */ - DTFS_STRUCTURE_FX PREV_CW_D_FX /* i : Previous DTFS */ - ,Decoder_State_fx *st -); - - -void ppp_voiced_decoder_fx( - Decoder_State_fx *st_fx, /* i/o: state structure */ - Word16 *out_fx, /* o : residual signal */ - const Word16 *lpc2_fx, /* i : current frame LPC */ - Word16 *exc_fx, /* i : previous frame excitation */ - Word16 *pitch, /* o : floating pitch values for each subframe */ - Word16 bfi /* i : Frame error rate */ -); - - -void bandwidth_switching_detect_fx( - Decoder_State_fx *st_fx /* i/o: encoder state structure */ -); - -void bw_switching_pre_proc_fx( - const Word16 *old_syn_12k8_16k_fx, /* i : ACELP core synthesis at 12.8kHz or 16kHz */ - Decoder_State_fx *st_fx /* i/o: decoder state structure */ -); - -void updt_bw_switching_fx( - Decoder_State_fx *st_fx, /* i/o: decoder state structure */ - const Word16 *synth, /* i : float synthesis signal */ - const Word16 Qpost -); -void updt_dec_common_fx( - Decoder_State_fx *st_fx, /* i/o: decoder state structure */ - Word16 hq_core_type_fx, /* i : HQ core type */ - const Word16 *synth /* i : decoded synthesis */ -); - -void sort_32_fx( - Word32 *r, /* i/o: Vector to be sorted in place */ - const Word16 lo, /* i : Low limit of sorting range */ - const Word16 up /* I : High limit of sorting range */ -); -Word16 FEC_SinOnset_fx ( - Word16 *exc, /* i/o : exc vector to modify */ - Word16 puls_pos, /* i : last pulse position desired */ - const Word16 T0, /* i : Pitch information of the 1 subfr */ - Word32 enr_q, /* i : energy provide by the encoder */ - Word16 *Aq, /* i : A(z) filter Q12 */ - const Word16 L_frame /* i : frame length */ - ,const Word16 Qold -); -Word16 FEC_enhACB_fx( - const Word16 L_frame, /* i : frame length */ - const Word16 last_L_frame, /* i : frame length of previous frame */ - Word16 *exc_io, /* i/o : adaptive codebook memory */ - const Word16 new_pit, /* i : decoded first frame pitch */ - const Word16 puls_pos, /* i : decoder position of the last glottal pulses decoded in the previous frame */ - const Word16 bfi_pitch /* i : Q6 pitch used for concealment */ -); - - -void fft3_fx(const Word16 [], Word16 [], const Word16); -void ifft3_fx(const Word16 [], Word16 [], const Word16); -void hq_ecu_fx( - const Word16 *prevsynth, /* i : buffer of previously synthesized signal */ - Word32 *ecu_rec, /* o : reconstructed frame in tda domain */ - Word16 *time_offs, - Word16 *X_sav, - Word16 *Q_spec, /* i/o : Q value of stored spectrum */ - Word16 *num_p, - Word16 *plocs, - Word32 *plocsi, /* o : Interpolated positions of the identified peaks (Q16) */ - const Word16 env_stab, - Word16 *last_fec, - const Word16 ph_ecu_HqVoicing, - Word16 *ph_ecu_active, /* i : Phase ECU active flag */ - Word16 *gapsynth, - const Word16 prev_bfi, /* i : indicating burst frame error */ - const Word16 old_is_transient[2], /* i : flags indicating previous transient frames */ - Word16 *mag_chg_1st, /* i/o: per band magnitude modifier for transients*/ - Word16 *Xavg, /* i/o: Frequency group average gain to fade to */ - Word16 *beta_mute, /* o : Factor for long-term mute */ - const Word16 output_frame, /* i : frame length */ - Decoder_State_fx *st_fx /* i/o: decoder state structure */ -); - -void hq_timedomain_conc_fx( - Word32 *ecu_rec, /* o : reconstructed frame in tda domain */ - Word16 *gapsynth, /* o : Gap synthesis */ - const Word16 output_frame, /* i : frame length */ - const Word16 *prevsynth, /* i : buffer of previously synthesized signal */ - Decoder_State_fx *st_fx /* i/o: decoder state structure */ -); - -Word16 ratio(const Word32, const Word32, Word16 *); - - -void nearProjQ15_fx( - Word16 x, - Word16 *result -); - -void Ratio_rQ3_fx( - Word16 opp, - Word16 near, - Word16 *result -); - -void densityAngle2RmsProjDec_fx( - Word16 D, /* i: density */ - Word16 indexphi, /* i: decoded index from AR dec */ - Word16 *oppQ15, /* o: proj*/ - Word16 *nearQ15, /* o: */ - Word16 *oppRatioQ3 /* o: */ -) ; - -void densityAngle2RmsProjEnc_fx ( - Word16 D, - Word16 phiQ14uq, - Word16 *indexphi, /* o: index to send to AR */ - Word16 *oppQ15, /* o: proj*/ - Word16 *nearQ15, - Word16 *oppRatioQ3 -) ; -void dsDiracPerQuanta_fx( - const Word16 td, - const Word16 t_quanta, - const Word16 dsm, - const unsigned char* const *frQuanta, - Word16 *DsIdx -); - -void QuantaPerDsDirac_fx( - Word16 td, - Word16 dsDiracIndex, - const unsigned char* const* dimFrQuanta, - Word16 *Quanta -); - -void obtainEnergyQuantizerDensity_fx( - const Word16 L, - const Word16 R, - Word16 *Density -); - -void dsDirac2Dirac_fx( - const Word16 dsDiracIndex, - Word16 *diracs -); - - -void NearOppSplitAdjustment_fx( - const Word16 qband, - const Word16 qzero, - const Word16 Qac, - const UWord32 INTac, - const Word16 qglobal, - const Word16 FlagCons, - const Word16 Np, - const Word16 Nhead, - const Word16 Ntail, - const Word16 Nnear, - const Word16 Nopp, - Word16 oppRQ3, - Word16 *qnear, - Word16 *qopp, - Word16 *qglobalupd -) ; - - - - -/* IGFEnc.c */ -void IGFEncApplyMono(const IGF_ENC_INSTANCE_HANDLE hInstance, /**< in: | instance handle of IGF Encoder */ - const Word16 igfGridIdx, /**< in: Q0 | IGF grid index */ - Encoder_State_fx *st, /**< in: | Encoder state */ - Word32 *pMDCTSpectrum, /**< in: Q31 | MDCT spectrum */ - Word16 MDCTSpectrum_e, /**< in: | exponent of MDCT spectrum */ - Word32 *pPowerSpectrum, /**< in: Q31 | MDCT^2 + MDST^2 spectrum, or estimate */ - Word16 PowerSpectrum_e, /**< in: | exponent of pPowerSpectrum */ - Word16 isTCX20, /**< in: Q0 | flag indicating if the input is TCX20 or TCX10/2xTCX5 */ - Word16 isTNSActive, /**< in: Q0 | flag indicating if the TNS is active */ - Word16 last_core_acelp /**< in: Q0 | indictaor if last frame was acelp coded */ - ); - -void IGFEncConcatenateBitstream(const IGF_ENC_INSTANCE_HANDLE hInstance, /**< in: | instance handle of IGF Encoder */ - Word16 bsBits, /**< in: Q0 | number of IGF bits written to list of indices */ - Word16 *next_ind, /**< in/out: | pointer to actual bit indice */ - Word16 *nb_bits, /**< in/out: | total number of bits already written */ - Indice_fx *ind_list_fx /**< in: | pointer to list of indices */ - ); - -void IGFEncResetTCX10BitCounter(const IGF_ENC_INSTANCE_HANDLE hInstance /**< in: | instance handle of IGF Encoder */ - ); - -void IGFEncSetMode(const IGF_ENC_INSTANCE_HANDLE hInstance, /**< in: | instance handle of IGF Encoder */ - const Word32 bitRate, /**< in: Q0 | encoder bitrate */ - const Word16 mode /**< in: Q0 | encoder bandwidth mode */ - , const Word16 rf_mode /**< in: | flag to signal the RF mode */ - - ); - -Word16 IGFEncWriteBitstream( /**< out: | number of bits written per frame */ - const IGF_ENC_INSTANCE_HANDLE hInstance, /**< in: | instance handle of IGF Encoder */ - Encoder_State_fx *st, /**< in: | encoder state */ - Word16 *pBitOffset, /**< in: | ptr to bitOffset counter */ - const Word16 igfGridIdx, /**< in: Q0 | igf grid index see declaration of IGF_GRID_IDX for details */ - const Word16 isIndepFlag /**< in: Q0 | if 1 frame is independent, 0 = frame is coded with data from previous frame */ -); - -Word16 IGFEncWriteConcatenatedBitstream( /**< out: Q0 | total number of bits written */ - const IGF_ENC_INSTANCE_HANDLE hInstance, /**< in: | instance handle of IGF Encoder */ - void *st /**< in: | encoder state */ -); - -/* IGFDec.c */ -void IGFDecApplyMono(const IGF_DEC_INSTANCE_HANDLE hInstance, /**< in: | instance handle of IGF Decoder */ - Word32 *spectrum, /**< in/out: | MDCT spectrum */ - Word16 *spectrum_e, /**< in/out: | exponent of spectrum */ - const Word16 igfGridIdx, /**< in: | in case of CELP->TCX switching, use 1.25 framelength */ - Word16 bfi /**< in: | frame loss == 1, frame good == 0 */ - ); - -void IGFDecCopyLPCFlatSpectrum(const IGF_DEC_INSTANCE_HANDLE hInstance, /**< in: | instance handle of IGF Decoder */ - const Word32 *pSpectrumFlat, /**< in: Q31 | LPC flattend spectrum from TCX dec */ - const Word16 pSpectrumFlat_exp, /**< in: | exponent of pSpectrumFlat */ - const Word16 igfGridIdx /**< in: Q0 | IGF grid index */ - ); - -void IGFDecReadData(const IGF_DEC_INSTANCE_HANDLE hInstance, /**< in: | instance handle of IGF Deccoder */ - Decoder_State_fx *st, /**< in: | decoder state */ - const Word16 igfGridIdx, /**< in: Q0 | in case of CELP->TCX switching, use 1.25 framelength */ - const Word16 isIndepFrame /**< in: Q0 | if 1: arith dec force reset, if 0: no reset */ - ); - -void IGFDecReadLevel( const IGF_DEC_INSTANCE_HANDLE hInstance, /**< in: | instance handle of IGF Deccoder */ - Decoder_State_fx *st, /**< in: | decoder state */ - const Word16 igfGridIdx, /**< in: Q0 | in case of CELP->TCX switching, use 1.25 framelength */ - const Word16 isIndepFrame /**< in: Q0 | if 1: arith dec force reset, if 0: no reset */ - ); - -void IGFDecRestoreTCX10SubFrameData(const IGF_DEC_INSTANCE_HANDLE hInstance, /**< in: | instance handle of IGF Decoder */ - const Word16 subFrameIdx /**< in: Q0 | index of subframe */ - ); - -void IGFDecSetMode(const IGF_DEC_INSTANCE_HANDLE hInstance, /**< in: | instance handle of IGF Decoder */ - const Word32 bitRate, /**< in: Q0 | bitrate */ - const Word16 mode, /**< in: Q0 | bandwidth mode */ - const Word16 defaultStartLine, /**< in: Q0 | default start subband index */ - const Word16 defaultStopLine /**< in: Q0 | default stop subband index */ - , const Word16 rf_mode /**< in: | flag to signal the RF mode */ - ); - -void IGFDecStoreTCX10SubFrameData(const IGF_DEC_INSTANCE_HANDLE hInstance, /**< in: | instance handle of IGF Decoder */ - const Word16 subFrameIdx /**< in: Q0 | index of subframe */ - ); - -void IGFDecUpdateInfo(const IGF_DEC_INSTANCE_HANDLE hInstance, /**< in: | instance handle of IGF Decoder */ - const Word16 igfGridIdx /**< in: | IGF grid index */ - ); - -/* iisBaseLib.c */ -void IGFCommonFuncsCalcSfbEnergyPowerSpec(const Word16 startSfb, /**< in: Q0 | start sfb index */ - const Word16 stopSfb, /**< in: Q0 | stop sfb index */ - const Word16 *swb_offset, /**< in: Q0 | IGF swb offset table */ - Word32 *pPowerSpectrum, /**< in: Q31 | power spectrum */ - Word16 *pPowerSpectrum_exp, /**< in: | Exponent of PowerSpectrum */ - Word32 *sfbEnergy, /**< out:Q31 | SFB energies , will be initialized inside this function */ - Word16 *sfbEnergy_exp /**< out: | Exponent of PowerSpectrum */ - ); - -Word16 IGFCommonFuncsIGFConfiguration( /**< out: | error value: 0 -> error, 1 -> ok */ - Word32 bitRate, /**< in: Q0 | bitrate in bs e.g. 9600 for 9.6kbs */ - Word16 mode, /**< in: Q0 | bandwidth mode */ - H_IGF_INFO hIGFInfo /**< out: | IGF info handle */ - ,Word16 rf_mode /**< in: flag to signal the RF mode */ -); - -Word16 IGFCommonFuncsIGFGetCFTables( /**< out: | error value: 0 -> error, 1 -> ok */ - Word32 bitRate, /**< in: Q0 | bitrate in bs e.g. 9600 for 9.6kbs */ - Word16 mode, /**< in: Q0 | bandwidth mode */ - Word16 rf_mode, /**< in: | flag to signal the RF mode */ - const Word16 **cf_se00, /**< out: | CF table for t == 0 and f == 0 */ - const Word16 **cf_se01, /**< out: | CF table for t == 0 and f == 1 */ - Word16 *cf_off_se01, /**< out: | offset for CF table above */ - const Word16 **cf_se02, /**< out: | CF tables for t == 0 and f >= 2 */ - const Word16 **cf_off_se02, /**< out: | offsets for CF tables above */ - const Word16 **cf_se10, /**< out: | CF table for t == 1 and f == 0 */ - Word16 *cf_off_se10, /**< out: | offset for CF table above */ - const Word16 **cf_se11, /**< out: | CF tables for t == 1 and f >= 1 */ - const Word16 **cf_off_se11 /**< out: | offsets for CF tables above */ -); - -void IGFCommonFuncsMDCTSquareSpec(const Word16 sqrtBgn, /**< in: Q0 | start MDCT subband index */ - const Word16 sqrtEnd, /**< in: Q0 | stop MDCT subband index */ - const Word32 *mdctSpec, /**< in: Q31 | MDCT spectrum to square */ - const Word16 mdctSpec_e, /**< in: | exponent of mdctSpectrum */ - Word32 *mdctSquareSpec, /**< out:Q31 | MDCT square spectrum */ - Word16 *mdctSquareSpec_e, /**< out: | exponent of mdctSquareSpec */ - Word16 indexOffset /**< in: Q0 | index offset */ - ); - -void IGFCommonFuncsWriteSerialBit(void *st, /**< in: | encoder/decoder state structure */ - Word16 *pBitOffset, /**< out: Q0 | bit offset */ - Word16 bit /**< in: Q0 | value of bit */ - ); - -/* IGFSCFEncoder.c */ -void IGFSCFEncoderOpen( - IGFSCFENC_INSTANCE_HANDLE hPublicData, /* i/o: handle to public data */ - Word16 scfCountLongBlock, /* i: number of SCFs for a long block */ - Word32 bitRate, /* i: bitrate in bps */ - Word16 mode /* i: operating mode */ - , Word16 rf_mode /**< in: flag to signal the RF mode */ -); - -void IGFSCFEncoderReset( - IGFSCFENC_INSTANCE_HANDLE hPublicData /* i/o: handle to public data */ -); - -Word16 IGFSCFEncoderEncode( - IGFSCFENC_INSTANCE_HANDLE hPublicData, /* i/o: handle to public data */ - Encoder_State_fx *st, /* i/o: pointer to encoder state */ - Word16 bitCount, /* i: offset to the first bit in bitbuffer which should be written by the raw AC functions */ - Word16 *sfe, /* i: pointer to an array which contains the quantized SCF energies to be encoded */ - Word16 indepFlag, /* i: 1 if the block is an independent block, 0 otherwise */ - Word16 doRealEncoding /* i: whether the real encoding is needed, otherwise only the number of bits is used */ -); - -void IGFSCFEncoderSaveContextState( - IGFSCFENC_INSTANCE_HANDLE hPublicData /* i/o: handle to public data */ -); - -void IGFSCFEncoderRestoreContextState( - IGFSCFENC_INSTANCE_HANDLE hPublicData /* i/o: handle to public data */ -); - -/* IGFSCFDecoder.c */ -void IGFSCFDecoderOpen( - IGFSCFDEC_INSTANCE_HANDLE hPublicData, /* i/o: handle to public data */ - Word16 scfCountLongBlock, /* i: number of SCFs for a long block */ - Word32 bitRate, /* i: bitrate in bps */ - Word16 mode /* i: operating mode */ - ,Word16 rf_mode -); - -void IGFSCFDecoderReset( - IGFSCFDEC_INSTANCE_HANDLE hPublicData /* i/o: handle to public data */ -); - -void IGFSCFDecoderDecode( - IGFSCFDEC_INSTANCE_HANDLE hPublicData, /* i/o: handle to public data */ - Decoder_State_fx *st, /* i/o: pointer to decoder state */ - Word16 *sfe, /* o: pointer to an array which will contain the decoded quantized SCFs */ - Word16 indepFlag /* i: 1 if the block is an independent block, 0 otherwise */ -); - -Word32 SFM_Cal(Word32 magn[], Word16 n); - - -void Unified_weighting_fx( - Word32 Bin_Ener_128_fx[], /* i : FFT Bin energy 128 bins in two sets Q_ener */ - Word16 Q_ener, - const Word16 lsf_fx[], /* i : LSF vector x2.56 */ - Word16 w_fx[], /* o : LP weighting filter (numerator) Q8 */ - const Word16 narrowBand, /* i : flag for Narrowband */ - const Word16 unvoiced, /* i : flag for Unvoiced frame */ - const Word32 sr_core, /* i : sampling rate of core-coder */ - const Word16 order /* i : LP order */ -); - -void lsf_dec_bfi( - const Word16 codec_mode, /* i: : codec mode: MODE1 | MODE2 */ - Word16*lsf, /*!< o : 14Q1*1.28 quantized ISFs */ - const Word16*lsfold, /*!< i : 14Q1*1.28 past quantized ISF */ - Word16*lsf_adaptive_mean, /*!< i : 14Q1*1.28 ISF adaptive mean, updated when BFI==0 */ - const Word16 lsfBase[], /* i : base for differential lsf coding */ - Word16*mem_MA, /*!< i/o: 14Q1*1.28 quantizer memory for MA model */ - Word16*mem_AR, /*!< i/o: 14Q1*1.28 quantizer memory for MA model */ - Word16 stab_fac, /*!< i : ISF stability factor (shifted right by 1) */ - const Word16 last_coder_type, /*!< i : coding type in last good received fr. */ - Word16 L_frame, - const Word16 last_good, /*!< i : last good received frame */ - const Word16 nbLostCmpt, /*!< i : counter of consecutive bad frames */ - Word8 plcBackgroundNoiseUpdated, - Word16 *lsf_q_cng, /* o : quantized ISFs for background noise (14Q1*1.28) */ - Word16 *lsf_cng, - Word16 *old_lsf_q_cng, /* o : old quantized ISFs for background noise */ - const Word16 Last_GSC_pit_band_idx, - const Word16 Opt_AMR_WB, /* i : IO flag */ - const Word8 tcxonly - ,const short MODE1_bwidth /* i: coded bandwidth */ -); - - -void lpc_quantization( - Encoder_State_fx * st, - const Word16 core, - const Word16 lpcQuantization, - const Word16 lsfold_q[], - const Word16 lsp[], - const Word16 lspmid[], - Word16 lsp_q[], - Word16 lsf_q[], /* 14Q1*1.28 */ - Word16 lspmid_q[], - Word16 lspq_ind[], - Word16 clip_var[], - Word16 mem_MA[], - Word16 mem_AR[], - const Word8 narrowBand, - const Word16 coder_type, - const Word8 acelp_midLpc, - Word16 param_lpc[], - Word16 nbits_lpc[], - Word16 * bits_param_lpc, - Word16 *no_param_lpc, - Word16 *seed_acelp, - Word32 * Bin_Ener_fx, - Word32 * Bin_Ener_old_fx, - const Word16 Q_ener -); - - - -/* enc_util.c */ -void Scale_sig( - Word16 x[], /* i/o: signal to scale Qx */ - const Word16 lg, /* i : size of x[] Q0 */ - const Word16 exp0 /* i : exponent: x = round(x << exp) Qx xx exp */ -); -void E_UTIL_f_preemph(Word16 *signal, const Word16 mu, const Word16 lg, Word16 *mem); -void E_UTIL_f_preemph2(Word16 shift, Word16 *signal, const Word16 mu, const Word16 lg, Word16 *mem); -Word16 E_UTIL_f_preemph3(Word16 *signal, const Word16 mu, const Word16 lg, Word16 *mem, Word16 bits); -void deemph_fx(Word16 * signal, const Word16 mu, const Word16 L, Word16 * mem); -void E_UTIL_deemph2(Word16 shift, Word16 *x, const Word16 mu, const Word16 L, Word16 *mem); -void E_UTIL_synthesis(const Word16 shift, const Word16 a[], const Word16 x[], Word16 y[], - const Word16 lg, Word16 mem[], const Word16 update, const Word16 m); -void E_UTIL_f_convolve(const Word16 x[], const Word16 h[], Word16 y[], const Word16 size); - -Word16 E_ACELP_hh_corr(Word16 *x, Word16 *y, Word16 L_subfr, Word16 bits); -Word16 E_ACELP_toeplitz_mul(const Word16 R[], const Word16 c[], Word16 d[], const Word16 L_subfr, const Word16 highrate); - -void E_ACELP_weighted_code( - const Word16 code[], /* i: code */ - const Word16 H[], /* i: impulse response */ - Word16 Q, /* i: Q format of H */ - Word16 y[] /* o: weighted code */ -); - -void E_ACELP_conv( - const Word16 xn2[], /* i */ - const Word16 h2[], /* i */ - Word16 cn2[] /* o */ -); - -void E_ACELP_build_code( - Word16 nb_pulse, /* i */ - const Word16 codvec[], /* i */ - const Word16 sign[], /* i */ - Word16 code[], /* o */ - Word16 ind[] /* o */ -); - -void E_ACELP_setup_pulse_search_pos( - const PulseConfig *config, /* i: pulse configuration */ - Word16 k, /* i: interation number */ - UWord8 ipos[] /* o: pulse search positions */ -); - -void find_wsp( - const Word16 Az[], - const Word16 speech[], - Word16 wsp[], - Word16 *mem_wsp, - const Word16 preemph_fac, - const Word16 L_frame, - const Word16 lookahead, - const Word16 L_subfr, - Word16 Aw[], /* o : weighted A(z) filter coefficients */ - const Word16 gamma, /* i : weighting factor */ - const Word16 nb_subfr /* i : number of subframes */ -); - -void init_sig_buffers( Encoder_State_fx *st, const Word16 L_frame_old, const Word16 L_subfr ); - -void E_UTIL_cb_shape( - const Word16 preemphFlag, /* i : flag for pre-emphasis */ - const Word16 pitchFlag, /* i : flag for pitch sharpening */ - const Word16 scramblingFlag, /* i : flag for phase scrambling */ - const Word16 formant_enh, /* i : use formant enhancement Q15 */ - const Word16 formant_tilt, /* i : use tilt of formant enhancement Q0 */ - const Word16 g1, /* i : formant sharpening numerator weighting */ - const Word16 g2, /* i : formant sharpening denominator weighting */ - const Word16 *Aq, /* i : quantized LPC coefficients 3Q12 */ - Word16 *code, /* i/o: <14b */ - const Word16 tilt_code, /* i : tilt factor Q15 */ - const Word16 pitch /* i : pointer to current subframe fractional pitch */ -); - -void E_UTIL_voice_factor( Word16 *exc, /* i : pointer to the excitation frame Q_new */ - Word16 i_subfr, /* i : subframe index */ - Word16 *code, /* i : innovative codebook Q9 */ - Word16 gain_pit, /* i : adaptive codebook gain 1Q14 */ - Word32 gain_code, /* i : innovative cb. gain 15Q16 */ - Word16 *voice_fac, /* o : subframe voicing estimation Q15 */ - Word16 *tilt_code, /* o : tilt factor Q15 */ - Word16 L_subfr, /* i : subframe length */ - Word16 flag_tilt, /* i : Flag for triggering new voice factor tilt*/ - Word16 Q_new, /* i : excitation buffer format */ - Word16 shift /* i : scaling to get 12bit */ - ); - -Word16 E_UTIL_enhancer( - Word16 voice_fac, /* i : subframe voicing estimation Q15 */ - Word16 stab_fac, /* i : LP filter stability measure Q15 */ - Word32 gain_code, /* i : innovative cb. gain 15Q16 */ - Word16 gain_inov, /* i : gain of the unscaled innovation Q12 */ - Word32 *gc_threshold, /* i/o: gain code threshold 15Q16 */ - Word16 *code, /* i/o: innovation(in: Q9) code_exp */ - Word16 *exc2, /* i/o: adapt. excitation/total exc. Q15 */ - Word16 gain_pit, /* i : Quantized pitch gain 1Q14 */ - Word32 *prev_gain_code, /* i/o: previous codebook gain 15Q16 */ - Word16 prev_gain_pit[], /* i/o: previous pitch gain, size=6 1Q14 */ - Word16 *prev_state, /* i/o: Phase dispersion algorithm memory Q0 */ - Word16 coder_type, /* i : coder type */ - Word16 cdk_index, /* i : */ - Word16 L_subfr, /* i : */ - Word16 L_frame, /* i : frame size */ - Word16 Q_new -); - -Word32 E_LPC_schur(Word32 r[], Word16 reflCoeff[], Word32 epsP[], const Word16 m); -Word16 E_LPC_lev_dur_stab(const Word16 Rh[], const Word16 Rl[], Word16 A[], - Word32 epsP[], const Word16 order, Word16 *parcorr, Word16 k_max - ); -Word16 E_LPC_lev_dur(const Word16 Rh[], const Word16 Rl[], Word16 A[], - Word32 epsP[], const Word16 order, Word16 *parcorr - ); - -void E_LPC_a_weight_inv(const Word16 *a, Word16 *ap, const Word16 gamma, const Word16 m); -void E_LPC_a_add_tilt(const Word16 *a, Word16 *ap, Word16 gamma, Word16 m); -void E_LPC_a_lsf_isf_conversion(Word16 *lpcCoeffs, Word16 *lsf, const Word16 *old_lsf, Word16 lpcOrder, Word8 lpcRep); -void E_LPC_a_lsp_conversion( - const Word16 *a, /* input : LP filter coefficients */ - Word16 *lsp, /* output: Line spectral pairs (in the cosine domain) */ - const Word16 *old_lsp, /* input : LSP vector from past frame */ - const Word16 m /* input : LPC order */ -); -void E_LPC_lsp_lsf_conversion( - const Word16 lsp[], /* input: lsp[m] (range: -1<=val<1) */ - Word16 lsf[], /* output : lsf[m] normalized (range: 0<=val<=6400) */ - const Word16 m /* input : LPC order */ -); -void E_LPC_lsf_lsp_conversion( - const Word16 lsf[], /* input : lsf[m] normalized (range: 0<=val<=6400) */ - Word16 lsp[], /* output: lsp[m] (range: -1<=val<1) */ - const Word16 m /* input : LPC order */ -); - -void E_LPC_f_lsp_a_conversion(const Word16 *lsp, Word16 *a, const Word16 m); -void E_LPC_a_isp_conversion( - const Word16 *a, /* input : LP filter coefficients */ - Word16 *isp, /* output: Line spectral pairs (in the cosine domain) */ - const Word16 *old_isp,/* input : LSP vector from past frame */ - const Word16 m /* input : LPC order */ -); -void E_LPC_isp_isf_conversion(const Word16 isp[], Word16 isf[], const Word16 m); -void E_LPC_isf_isp_conversion(const Word16 isf[], Word16 isp[], const Word16 m); -void E_LPC_f_isp_a_conversion(const Word16 *isp, Word16 *a, const Word16 m); -void E_LPC_int_lpc_tcx(const Word16 lsp_old[], /* input : LSPs from past frame (1Q14) */ - const Word16 lsp_new[], /* input : LSPs from present frame (1Q14) */ - Word16 a[] /* output: interpolated LP coefficients (4Q11) */ - ); - -/* enc_gain.c */ - -Word16 E_GAIN_closed_loop_search(Word16 exc[], - Word16 xn[], Word16 h[], - Word16 t0_min, Word16 t0_min_frac, Word16 t0_max, Word16 t0_max_frac, Word16 t0_min_max_res, Word16 *pit_frac, Word16 *pit_res, Word16 pit_res_max, - Word16 i_subfr, Word16 pit_min, Word16 pit_fr2, Word16 pit_fr1, Word16 L_subfr); -void E_GAIN_norm_corr(Word16 exc[], Word16 xn[], Word16 h[], - Word16 t_min, Word16 t_max, Word16 corr_norm[], Word16 L_subfr); - -/* enc_acelp.c */ -void E_ACELP_xy2_corr(Word16 xn[], Word16 y1[], Word16 y2[], ACELP_CbkCorr *g_corr, Word16 L_subfr, Word16 exp_xn); -Word16 E_ACELP_xy1_corr(Word16 xn[], Word16 y1[], ACELP_CbkCorr *g_corr, Word16 norm_flag, Word16 L_subfr, Word16 exp_xn); -void E_ACELP_codebook_target_update(Word16 *x, Word16 *x2, Word16 *y, Word16 gain, Word16 L_subfr); -void E_ACELP_h_vec_corr1(Word16 h[], Word16 vec[], UWord8 track, Word16 sign[], Word16 (*rrixix)[16], Word16 cor[], Word16 dn2_pos[], Word16 nb_pulse); -void E_ACELP_h_vec_corr2(Word16 h[], Word16 vec[], UWord8 track, Word16 sign[], Word16 (*rrixix)[16], Word16 cor[]); -void E_ACELP_4tsearch(Word16 dn[], const Word16 cn[], const Word16 H[], Word16 code[], const PulseConfig *config, Word16 ind[], Word16 y[]); -void E_ACELP_4tsearchx(Word16 dn[], const Word16 cn[], Word16 Rw[], Word16 code[], const PulseConfig *config, Word16 ind[]); -void E_ACELP_pulsesign(const Word16 cn[], Word16 dn[], Word16 dn2[], Word16 sign[], Word16 vec[], const Word16 alp, Word16 const sign_val, const Word16 L_subfr); - -Word16 E_ACELP_indexing(const Word16 code[], const PulseConfig *config, Word16 num_tracks, Word16 prm[]); -void E_ACELP_findcandidates(Word16 dn2[], Word16 dn2_pos[], Word16 pos_max[]); -void E_ACELP_vec_neg(Word16 h[], Word16 h_inv[], Word16 L_subfr); -void E_ACELP_corrmatrix(Word16 h[], Word16 sign[], Word16 vec[], Word16 rrixix[4][16], Word16 rrixiy[4][256]); -void E_ACELP_codearithp(const Word16 v[], UWord32 *n, UWord32 *ps, Word16 *p); - -void find_targets_fx( - const Word16 *speech, /* i : pointer to the speech frame Q_new-1*/ - const Word16 *mem_syn, /* i : memory of the synthesis filter Q_new-1*/ - const Word16 i_subfr, /* i : subframe index */ - Word16 *mem_w0, /* i/o: weighting filter denominator memory Q_new-1*/ - const Word16 *p_Aq, /* i : interpolated quantized A(z) filter Q12*/ - const Word16 *res, /* i : residual signal Q_new*/ - const Word16 L_subfr, /* i : length of vectors for gain quantization */ - const Word16 *Ap, /* i : unquantized A(z) filter with bandwidth expansion Q12*/ - Word16 tilt_fac, /* i : tilt factor Q15 */ - Word16 *xn, /* o : Close-loop Pitch search target vector Q_new-1*/ - Word16 *cn /* o : target vector in residual domain Q_new*/ - ,Word16 *h1 /* Q14 ?*/ -); - -void E_ACELP_adaptive_codebook( - Word16 *exc, /* i : pointer to the excitation frame */ - Word16 T0, /* i : integer pitch lag */ - Word16 T0_frac, /* i : fraction of lag */ - Word16 T0_res, /* i : pitch resolution */ - Word16 T0_res_max, /* i : maximum pitch resolution */ - Word16 mode, /* i : filtering mode (0: no, 1: yes, 2: adaptive) */ - Word16 i_subfr, /* i : subframe index */ - Word16 L_subfr, /* i : subframe length */ - Word16 L_frame, /* i : subframe length */ - Word16 *h1, /* i : impulse response of weighted synthesis filter */ - Word16 clip_gain, - Word16 *xn, /* i : Close-loop Pitch search target vector */ - Word16 *y1, /* o : zero-memory filtered adaptive excitation */ - ACELP_CbkCorr *g_corr, /* o : ACELP correlation values */ - Word16 **pt_indice, /* i/o: quantization indices pointer */ - Word16 *pitch_gain, /* o : adaptive codebook gain */ - Word16 exp_xn - ,Word16 rf_mode - ,Word16 use_prev_sf_pit_gain - ,Word16* lp_select -); - -void E_ACELP_innovative_codebook( - Word16 *exc, /* i : pointer to the excitation frame */ - Word16 T0, /* i : integer pitch lag */ - Word16 T0_frac, /* i : fraction of lag */ - Word16 T0_res, /* i : pitch resolution */ - Word16 gain_pit, /* i : adaptive codebook gain */ - Word16 tilt_code, /* i : tilt factor */ - Word16 mode, /* i : innovative codebook mode */ - Word16 formant_enh, /* i : use formant enhancement Q15 */ - Word16 formant_tilt, /* i : use tilt of formant enhancement */ - const Word16 formant_enh_num, /* i : formant sharpening numerator weighting */ - const Word16 foramnt_enh_den, /* i : formant sharpening denominator weighting */ - Word16 pitch_sharpening,/* i : use pitch sharpening */ - Word16 pre_emphasis, - Word16 phase_scrambling, - Word16 i_subfr, /* i : subframe index */ - const Word16 *Aq, /* i : quantized LPC coefficients */ - Word16 *h1, /* i : impulse response of weighted synthesis filter */ - Word16 *xn, /* i : Close-loop Pitch search target vector */ - Word16 *cn, /* i : Innovative codebook search target vector */ - Word16 *y1, /* i : zero-memory filtered adaptive excitation */ - Word16 *y2, /* o : zero-memory filtered algebraic excitation */ - Word8 acelpautoc, /* i : autocorrelation mode enabled */ - Word16 **pt_indice, /* i/o: quantization indices pointer */ - Word16 *code, /* o : innovative codebook Q9 */ - Word16 shift /* i : Scaling to get 12 bits */ - ,const Word16 L_frame, /* i : length of the frame */ - const Word16 last_L_frame, /* i : length of the last frame */ - const Word32 total_brate /* i : total bit-rate */ -); - -Word16 E_ACELP_code43bit(const Word16 code[], UWord32 *ps, Word16 *p, UWord16 idxs[]); -void fcb_pulse_track_joint(UWord16 *idxs, Word16 wordcnt, UWord32 *index_n, Word16 *pulse_num, Word16 track_num); - -void encode_acelp_gains( - Word16 *code, /* Q9 */ - Word16 gains_mode, - Word16 mean_ener_code, - Word16 clip_gain, - ACELP_CbkCorr *g_corr, - Word16 *gain_pit, /* Q14 */ - Word32 *gain_code, /* 15Q16 */ - Word16 **pt_indice, - Word32 *past_gcode, /* 15Q16 */ - Word16 *gain_inov, /* Q12 */ - Word16 L_subfr, - Word16 *code2, - Word32 *gain_code2, - Word8 noisy_speech_flag /* (i) : noisy speech flag */ -); - -extern const long int pulsestable[6][7]; -extern const PulseConfig PulseConfTable[]; -extern const Word16 ACELP_CDK_BITS[]; - -void D_ACELP_indexing( - Word16 code[], - PulseConfig config, - Word16 num_tracks, - Word16 index[] - ,Word16 *BER_detect -); - -void D_ACELP_decode_43bit(UWord16 idxs[], Word16 code[], Word16 *pulsestrack); -void fcb_pulse_track_joint_decode(UWord16 *idxs, Word16 wordcnt, UWord32 *index_n, Word16 *pulse_num, Word16 track_num); - -/* lag window lag_wind.c */ -void lag_wind( - Word16 r_h[], /* in/out: autocorrelations */ - Word16 r_l[], /* in/out: autocorrelations */ - Word16 m, /* input : order of LP filter */ - Word32 sr, /* input : sampling rate */ - Word16 strength /* input : LAGW_WEAK, LAGW_MEDIUM, or LAGW_STRONG */ -); - -void adapt_lag_wind( - Word16 r_h[], /* in/out: autocorrelations */ - Word16 r_l[], /* in/out: autocorrelations */ - Word16 m, /* input : order of LP filter */ - const Word16 Top, /* input : open loop pitch lag */ - const Word16 Tnc, /* input : open loop pitch gain */ - Word32 sr /* input : sampling rate */ -); - -void hp20(Word16 signal[], /* i/o: signal to filter any */ - const Word16 stride, /* i : stride to be applied accessing signal */ - const Word16 lg, /* i : length of signal (integer) Q0 */ - Word32 mem[5], /* i/o: static filter memory with this layout: */ - /* mem[0]: y[-2] (32-bit) */ - /* mem[1]; y[-1] (32-bit) */ - /* mem[2]: x[-2] << 16 */ - /* mem[3]: x[-1] << 16 */ - /* Note: mem[0..3] need to be scaled per frame */ - /* mem[4]: states scale */ - const Word32 sFreq); /* i : input sampling rate Q0 */ - -/* pit_fr4.c */ -void Mode2_pred_lt4(Word16 exc[], /* in/out: excitation buffer */ - Word16 T0, /* input : integer pitch lag */ - Word16 frac, /* input : fraction of lag */ - Word16 T0_res, /* input : pitch lag resolution */ - Word16 T0_res_max, /* input : maximum resolution */ - Word16 L_subfr); /* input : subframe size */ - - -#define mvr2r_Word32(x,y,n) Copy32(x,y,n) -#define mvr2r_Word16(x,y,n) Copy(x,y,n) -#define vr_intset(val, vector, count) { Word16 i; FOR(i=0; i<(count); i++) { vector[i]=val; } } - -float mean( /* o : the mean of the elements of the vector */ - const float *vec, /* i : input vector */ - const short lvec /* i : length of input vector */ -); - -/* window.c */ -void ham_cos_window(Word16 *fh, const Word16 n1, const Word16 n2); - - -/*---------------------------------------------------------------------* - * main routines * - *---------------------------------------------------------------------*/ - -void init_coder_ace_plus( Encoder_State_fx* st,const Word16 shift); -void core_coder_reconfig( Encoder_State_fx *st); -void core_coder_mode_switch( Encoder_State_fx *st, const Word16 bandwidth_in, const Word32 bitrate, const Word16 shift); - -void enc_acelp_tcx_main( - const Word16 new_samples[], /* i : new samples */ - Encoder_State_fx *st, /* i/o: encoder state structure */ - const Word16 coder_type, /* i : coding type */ - const Word16 pitch[3], /* i : open-loop pitch values for quantiz. */ - const Word16 voicing[3], /* i : open-loop pitch gains */ - Word16 Aw[NB_SUBFR16k*(M+1)], /* i : weighted A(z) unquant. for subframes*/ - const Word16 lsp_new[M], /* i : LSPs at the end of the frame */ - const Word16 lsp_mid[M], /* i : LSPs at the middle of the frame */ - HANDLE_FD_CNG_ENC hFdCngEnc, /* i/o: FD CNG handle */ - Word32 bwe_exc_extended[], /* i/o: bandwidth extended excitation */ - Word16 *voice_factors, /* o : voicing factors */ - Word16 pitch_buf[], /* o : floating pitch for each subframe */ - Word16 vad_hover_flag, - Word16 *Q_new, - Word16 *shift -); - -/*-----------------------------------------------------------------* - * Pitch prediction for frame erasure * - *-----------------------------------------------------------------*/ -void pitch_pred_linear_fit( - const Word16 /*short*/ bfi_cnt, /* i: bfi counter */ /*Q0 */ - const Word16 /*short*/ last_good, /* i: last classification type */ /*Q0 */ - Word32 /*float*/ *old_pitch_buf, /* i: pitch lag buffer */ /*Q16*/ - Word32 /*float*/ *old_fpitch, /* i: */ /*Q16*/ - Word32 /*float*/ *T0_out, /* o: estimated close loop pitch */ /*Q16*/ - Word16 /* int*/ pit_min, /* i: Minimum pitch lag */ /*Q0 */ - Word16 /* int*/ pit_max, /* i: Maximum pitch lag */ /*Q0 */ - Word16 /*float*/ *mem_pitch_gain, /* i: pitch gain [0] is the most recent subfr gain */ /*Q0*/ - Word16 /* int*/ limitation, - Word8 /*short*/ plc_use_future_lag, /* i: */ /*Q0 */ - Word16 /*short*/ *extrapolationFailed, /* o: flag if extrap decides not to change the pitch *//*Q0 */ - Word16 nb_subfr /* i: number of ACELP subframes */ -); - -void get_subframe_pitch( - Word16 nSubframes, /* i: number of subframes */ /* Q0 */ - Word32 pitchStart, /* i: starting pitch lag (in subframe -1) */ /*15Q16*/ - Word32 pitchEnd, /* i: ending pitch lag (in subframe nSubframes-1) */ /*15Q16*/ - Word32 *pitchBuf /* o: interpolated pitch lag per subframe */ /*15Q16*/ -); - -void core_encode_openloop( - Encoder_State_fx *st, /* i/o: encoder state structure */ - const Word16 coder_type, /* i : coding type */ - const Word16 pitch[3], /* i : open-loop pitch values for quantiz. */ - const Word16 voicing[3], /* i : open-loop pitch gains */ - const Word16 Aw[NB_SUBFR16k*(M+1)], /* i : weighted A(z) unquant. for subframes*/ - const Word16 *lsp_new, /* i : LSPs at the end of the frame */ - const Word16 *lsp_mid, /* i : LSPs at the middle of the frame */ - Word16 *pitch_buf, /* i/o: floating pitch values for each subfr*/ - Word16 *voice_factors, /* o : voicing factors */ - Word16 *ptr_bwe_exc, /* o : excitation for SWB TBE */ - const Word16 vad_hover_flag, - Word16 Q_new, - Word16 shift -); - -void core_acelp_tcx20_switching( - Encoder_State_fx *st, /* i/o: encoder state structure */ - const Word16 vad_flag, - Word16 sp_aud_decision0, - Word16 non_staX, - Word16 *pitch, /* i : open-loop pitch values for quantiz. */ - Word16 *pitch_fr, /* i/o: fraction pitch values */ - Word16 *voicing_fr, /* i/o: fractional voicing values */ - const Word16 currFlatness, /* i : flatness */ - const Word16 lsp_mid[M], /* i : LSPs at the middle of the frame */ - const Word16 stab_fac, /* i : LP filter stability */ - Word16 Q_new, - Word16 shift -); - -void core_encode_twodiv( - const Word16 new_samples[], - Encoder_State_fx *st, - const Word16 coder_type, /* i : coding type */ - const Word16 pitch[3], /* i : open-loop pitch values for quantiz. */ - const Word16 voicing[3], /* i : open-loop pitch gains */ - Word16 Aw[NB_SUBFR16k*(M+1)], /* i : weighted A(z) unquant. for subframes*/ - Word16 *Q_new, - Word16 *shift -); - -void core_encode_update( Encoder_State_fx *st); - -void core_encode_update_cng( Encoder_State_fx *st, - Word16 *timeDomainBuffer, - Word16 *A, - Word16 *Aw, - Word16 Q_new, - Word16 shift - ); - -/* core_sig_ana.c */ -void core_signal_analysis_post(const Word16 *new_samples, Encoder_State_fx *st); - -/* ext_sig_ana.c */ -void core_signal_analysis_enc(const Word16 *new_samples, /*, -2,, -2 and 2*/ - Word16 mean_ener, /*, -2,, -2 and 2*/ - Word16 mean_ener, /*syn */ - Word8 fb /* i: fullband flag */ -); - -Word16 tcx_get_segSnr(Word16 *wsig, Word16 wsig_e, - Word32 *X, Word16 X_e, - Word32 *Xq, Word16 Xq_e, - Word8 *memQuantZeros, - const Word16 snrPenalty, /* 1Q14 */ - Word16 gainlpc_reweight[], Word16 gainlpc_reweight_e[], - Word16 fdns_npts, - Word8 narrowBand, - Word16 gain_tcx, Word16 gain_tcx_e, - Word16 L_frame, - Word16 L_frame_glob, - Word16 L_subfr - ); - -/* Returns: number of bits used (including "bits") Q0 */ -Word16 tcx_ari_res_Q_spec( - const Word32 x_orig[], /* i: original spectrum Q31-e */ - Word16 x_orig_e, /* i: original spectrum exponent Q0 */ - const Word16 signs[], /* i: signs (x_orig[.]<0) Q0 */ - Word32 x_Q[], /* i/o: quantized spectrum Q31-e */ - Word16 x_Q_e, /* i: quantized spectrum exponent Q0 */ - Word16 L_frame, /* i: number of lines Q0 */ - Word16 gain, /* i: TCX gain Q15-e */ - Word16 gain_e, /* i: TCX gain exponent Q0 */ - Word16 prm[], /* o: bit-stream Q0 */ - Word16 target_bits, /* i: number of bits available Q0 */ - Word16 bits, /* i: number of bits used so far Q0 */ - Word16 deadzone, /* i: quantizer deadzone Q15 */ - const Word16 x_fac[] /* i: spectrum post-quantization factors Q14 */ -); - -/* Returns: number of bits used (including "bits") */ -Word16 tcx_ari_res_invQ_spec( - Word32 x_Q[], /* i/o: quantized spectrum Q31-e */ - Word16 x_Q_e, /* i: quantized spectrum exponent Q0 */ - Word16 L_frame, /* i: number of lines Q0 */ - const Word16 prm[], /* i: bit-stream Q0 */ - Word16 target_bits, /* i: number of bits available Q0 */ - Word16 bits, /* i: number of bits used so far Q0 */ - Word16 deadzone, /* i: quantizer deadzone Q15 */ - const Word16 x_fac[] /* i: spectrum post-quantization factors Q14 */ -); - -Word16 tcx_res_Q_gain( - Word16 sqGain, - Word16 sqGain_e, - Word16 *gain_tcx, - Word16 *gain_tcx_e, - Word16 *prm, - Word16 sqTargetBits -); - -Word16 tcx_res_Q_spec( - Word32 *x_orig, - Word16 x_orig_e, - Word32 *x_Q, - Word16 x_Q_e, - Word16 L_frame, - Word16 sqGain, - Word16 sqGain_e, - Word16 *prm, - Word16 sqTargetBits, - Word16 bits, - Word16 sq_round, - const Word16 lf_deemph_factors[] -); - -Word16 tcx_res_invQ_gain( - Word16 *gain_tcx, - Word16 *gain_tcx_e, - Word16 *prm, - Word16 resQBits -); - -Word16 tcx_res_invQ_spec( - Word32 *x, - Word16 x_e, - Word16 L_frame, - Word16 *prm, - Word16 resQBits, - Word16 bits, - Word16 sq_round, - const Word16 lf_deemph_factors[] -); - -void InitTnsConfigs( - Word32 nSampleRate, - Word16 L_frame, - STnsConfig tnsConfig[2][2] - ,Word16 igfStopFreq - ,Word32 bitrate -); - -void SetTnsConfig(TCX_config * tcx_cfg, Word8 isTCX20, Word8 isAfterACELP); - - -/* ari.c */ -Word32 L_multi31x16_X2(Word16 xh, Word16 xl, Word16 y); -Word32 mul_sbc_14bits(Word32 r, Word16 c); - -void ari_copy_states( - TastatEnc *source, - TastatEnc *dest -); - -void ari_start_encoding_14bits( - TastatEnc *s -); - -Word16 ari_done_encoding_14bits( - Word16 *ptr, - Word16 bp, - TastatEnc *s -); - -Word16 ari_encode_14bits_ext( - Word16 *ptr, - Word16 bp, - TastatEnc *s, - Word32 symbol, - UWord16 const *cum_freq -); - -void ari_start_decoding_14bits( - Decoder_State_fx *st, - TastatDec *s -); - -Word16 ari_decode_14bits_s17_ext( - Decoder_State_fx *st, - TastatDec *s, - UWord16 const *cum_freq -); - -Word16 ari_decode_14bits_s27_ext( - Decoder_State_fx *st, - TastatDec *s, - UWord16 const *cum_freq -); - -Word16 ari_decode_14bits_bit_ext( - Decoder_State_fx *st, - TastatDec *s -); - - -Word16 ari_encode_overflow(TastatEnc *s); -Word16 ari_encode_14bits_range(Word16 *ptr, Word16 bp, Word16 bits, TastatEnc *s, Word16 cum_freq_low, Word16 cum_freq_high); -Word16 ari_encode_14bits_sign(Word16 *ptr, Word16 bp, Word16 bits, TastatEnc *s, Word16 sign); -Word16 ari_done_cbr_encoding_14bits(Word16 *ptr, Word16 bp, Word16 bits, TastatEnc *s); -Word16 ari_decode_overflow(TastatDec *s); -Word16 ari_decode_14bits_pow(Word16 *ptr, Word16 bp, Word16 bits, Word16 *res, TastatDec *s, Word16 base); -Word16 ari_decode_14bits_sign(Word16 *ptr, Word16 bp, Word16 bits, Word16 *res, TastatDec *s); -Word16 ari_start_decoding_14bits_prm(const Word16 *ptr, Word16 bp, TastatDec *s); - -/*arith_code.c*/ -Word32 expfp( /* o: Q31 */ - Word16 x, /* i: mantissa Q-e */ - Word16 x_e); /* i: exponent Q0 */ - -void powfp_odd2(Word16 base, /* Q15 */ - Word16 exp, /* Q0 */ - Word16 *pout1, /* Q15 */ - Word16 *pout2); /* Q15 */ - -void tcx_arith_scale_envelope( - Word16 L_spec_core, /* i: number of lines to scale Q0 */ - Word16 L_frame, /* i: number of lines Q0 */ - Word32 env[], /* i: unscaled envelope Q16 */ - Word16 target_bits, /* i: number of available bits Q0 */ - Word16 low_complexity, /* i: low-complexity flag Q0 */ - Word16 s_env[], /* o: scaled envelope Q15-e */ - Word16 *s_env_e /* o: scaled envelope exponent Q0 */ -); - -void tcx_arith_render_envelope( - const Word16 A_ind[], /* i: LPC coefficients of signal envelope */ - Word16 L_frame, /* i: number of spectral lines */ - Word16 L_spec, - Word16 preemph_fac, /* i: pre-emphasis factor */ - Word16 gamma_w, /* i: A_ind -> weighted envelope factor */ - Word16 gamma_uw, /* i: A_ind -> non-weighted envelope factor */ - Word32 env[] /* o: shaped signal envelope */ -); - -void tcx_get_gain(Word32 *x, /* i: spectrum 1 */ - Word16 x_e, /* i: spectrum 1 exponent */ - Word32 *y, /* i: spectrum 2 */ - Word16 y_e, /* i: spectrum 2 exponent */ - Word16 n, /* i: length */ - Word16 *gain, /* o: gain */ - Word16 *gain_e, /* o: gain exponent */ - Word32 *en_y, /* o: energy of y (optional) */ - Word16 *en_y_e /* o: energy of y exponent (optional) */ - ); - -void init_TCX_config(TCX_config *tcx_cfg, - Word16 L_frame, - Word16 fscale - ,Word16 L_frameTCX - ,Word16 fscaleFB - ); - -void tcx_arith_encode_envelope( - Word32 spectrum[], /* i/o: MDCT coefficients Q31-e */ - Word16 *spectrum_e, /* i/o: MDCT exponent Q0 */ - Word16 signs[], /* o: signs (spectrum[.]<0) Q0 */ - Word16 L_frame, /* i: frame or MDCT length Q0 */ - Word16 L_frame_orig, /* i: length w/o BW limitation Q0 */ - Encoder_State_fx *st, /* i/o: coder state */ - const Word16 A_ind[], /* i: quantised LPC coefficients Q12 */ - Word16 target_bits, /* i: number of available bits Q0 */ - Word16 prm[], /* o: bitstream parameters Q0 */ - Word8 use_hm, /* i: use HM in current frame? */ - Word16 prm_hm[], /* o: HM parameter area Q0 */ - Word16 tcxltp_pitch, /* i: TCX LTP pitch in FD, -1 if n/a Q0*/ - Word16 *arith_bits, /* o: bits used for ari. coding Q0 */ - Word16 *signaling_bits, /* o: bits used for signaling Q0 */ - Word16 *nf_seed /* o: noise filling seed Q0 */ - ,Word16 low_complexity /* i: low-complexity flag Q0 */ -); -void tcx_arith_decode_envelope( - Word32 q_spectrum[], /* o: quantised MDCT coefficients Q31-e */ - Word16 *q_spectrum_e, /* o: MDCT exponent Q0 */ - Word16 L_frame, /* i: frame or MDCT length */ - Word16 L_frame_orig, /* i: length w/o BW limitation */ - Decoder_State_fx *st, - const Word16 A_ind[], /* i: quantised LPC coefficients */ - Word16 target_bits, /* i: number of available bits */ - Word16 prm[], /* i: bitstream parameters */ - Word8 use_hm, /* i: use HM in current frame? */ - Word16 prm_hm[], /* i: HM parameter area */ - Word16 tcxltp_pitch, /* i: TCX LTP pitch in FD, -1 if n/a*/ - Word16 *arith_bits, /* o: bits used for ari. coding */ - Word16 *signaling_bits, /* o: bits used for signaling */ - Word16 *nf_seed /* o: noise filling seed Q0 */ - ,Word16 low_complexity /* i: low-complexity flag Q0 */ - -); - -# define GET_ADJ2(T,L,F) (((L) << (F)) - (T)) - -int tcx_hm_render( - Word32 lag, /* i: pitch lag Q0 */ - Word16 fract_res, /* i: fractional resolution of the lag Q0 */ - Word16 p[] /* o: harmonic model Q13 */ -); - -void tcx_hm_modify_envelope( - Word16 gain, /* i: HM gain Q11 */ - Word32 lag, /* i: pitch lag Q0 */ - Word16 fract_res, /* i: fractional resolution of the lag Q0 */ - Word16 p[], /* i: harmonic model Q13 */ - Word32 env[], /* i/o: envelope Q16 */ - Word16 L_frame /* i: number of spectral lines Q0 */ -); - -void UnmapIndex( - Word16 PeriodicityIndex, - Word16 Bandwidth, - Word16 LtpPitchLag, - Word8 SmallerLags, - Word16 *FractionalResolution, - Word32 *Lag); - -/* Returns: PeriodicityIndex */ -Word16 SearchPeriodicityIndex( - const Word32 Mdct[], /* (I) Coefficients, Mdct[0..NumCoeffs-1] */ - const Word32 UnfilteredMdct[], /* (I) Unfiltered coefficients, UnfilteredMdct[0..NumCoeffs-1] */ - Word16 NumCoeffs, /* (I) Number of coefficients */ - Word16 TargetBits, /* (I) Target bit budget (excl. Done flag) */ - Word16 LtpPitchLag, - Word16 LtpGain, /* (I) LTP gain */ - Word16 *RelativeScore /* (O) Energy concentration factor */ -); - -void ConfigureContextHm( - Word16 NumCoeffs, /* (I) Number of coefficients */ - Word16 TargetBits, /* (I) Target bit budget (excl. Done flag) */ - Word16 PeriodicityIndex, /* (I) Pitch related index */ - Word16 LtpPitchLag, /* (I) TCX-LTP pitch in F.D. */ - CONTEXT_HM_CONFIG *hm_cfg /* (O) Context-based harmonic model configuration */ -); - -Word16 EncodeIndex( - Word16 Bandwidth, /* 0: NB, 1: (S)WB */ - Word16 PeriodicityIndex, - Encoder_State_fx *st); - -Word16 CountIndexBits( - Word16 Bandwidth, /* 0: NB, 1: (S)WB */ - Word16 PeriodicityIndex); - -Word16 -DecodeIndex( - Decoder_State_fx *st, - Word16 Bandwidth, - Word16 *PeriodicityIndex); - - -void tcx_hm_analyse( - const Word32 abs_spectrum[], /* i: absolute spectrum Q31-e */ - Word16 *spectrum_e, /* i: absolute spectrum exponent Q0 */ - Word16 L_frame, /* i: number of spectral lines Q0 */ - Word32 env[], /* i/o: envelope shape Q16 */ - Word16 targetBits, /* i: target bit budget Q0 */ - Word16 coder_type, /* i: coder type Q0 */ - Word16 prm_hm[], /* o: HM parameters Q0 */ - Word16 LtpPitchLag, /* i: LTP pitch lag or -1 if none Q0 */ - Word16 LtpGain, /* i: LTP gain Q15 */ - Word16 *hm_bits /* o: bit consumption Q0 */ -); - -void tcx_hm_decode( - Word16 L_frame, /* i: number of spectral lines Q0 */ - Word32 env[], /* i/o: envelope shape Q16 */ - Word16 targetBits, /* i: target bit budget Q0 */ - Word16 coder_type, /* i: coder_type Q0 */ - Word16 prm_hm[], /* i: HM parameters Q0 */ - Word16 LtpPitchLag, /* i: LTP pitch lag or -1 if none Q0 */ - Word16 *hm_bits /* o: bit consumption Q0 */ -); - -void coder_tcx( - Word16 n, - TCX_config *tcx_cfg, /*input: configuration of TCX*/ - Word16 A[], /* input: quantized coefficients NxAz_q[M+1] */ - Word16 Aqind[], /* input: frame-independent quantized coefficients (M+1) */ - Word16 synth[], - Word16 L_frame_glob, /* input: frame length */ - Word16 L_frameTCX_glob, - Word16 L_spec, - Word16 nb_bits, /*input: bit budget*/ - Word8 tcxonly, /*input: only TCX flag*/ - Word32 spectrum[], /* i/o: MDCT spectrum */ - Word16 *spectrum_e, /* i/o: MDCT spectrum exponent */ - LPD_state *LPDmem, /*i/o: memories*/ - Word16 prm[], /* output: tcx parameters */ - Encoder_State_fx *st, - CONTEXT_HM_CONFIG *hm_cfg -); - -void coder_tcx_post(Encoder_State_fx *st, - LPD_state *LPDmem, - TCX_config *tcx_cfg, - Word16 *synth, - const Word16 *A, - const Word16 *Ai, - Word16 *wsig, - Word16 Q_new, - Word16 shift - ); - -void decoder_tcx( - TCX_config *tcx_cfg, /* input: configuration of TCX */ - Word16 prm[], /* input: parameters */ - Word16 A[], /* input: coefficients NxAz[M+1] */ - Word16 Aind[], /* input: frame-independent coefficients Az[M+1] */ - Word16 L_frame_glob, /* input: frame length */ - Word16 L_frameTCX, - Word16 L_spec, - Word16 synth[], /* in/out: synth[-M-LFAC..lg] */ - Word16 synthFB[], - Decoder_State_fx*st, - Word16 coder_type, /* input : coder type */ - Word16 bfi, /* input: Bad frame indicator */ - Word16 frame_cnt, /* input: frame counter in the super_frame */ - Word16 stab_fac /* input: stability of isf */ -); - -void decoder_tcx_post(Decoder_State_fx *st_fx, - Word16 *synth, - Word16 *synthFB, - Word16 *A, - Word16 bfi - ); - -/* cod_ace.c */ -Word16 coder_acelp( /* output SEGSNR for CL decision */ - ACELP_config *acelp_cfg, /*input/output: configuration of the ACELP coding*/ - const Word16 coder_type, /* input: coding type */ - const Word16 A[], /* input: coefficients 4xAz[M+1] */ - const Word16 Aq[], /* input: coefficients 4xAz_q[M+1] */ - Word16 speech[], /* input: speech[-M..lg] */ - Word16 synth[], - LPD_state *LPDmem, - const Word16 voicing[], /* input: open-loop LTP gain */ - const Word16 T_op[], /* input: open-loop LTP lag */ - Word16 *prm, /* output: acelp parameters */ - Word16 stab_fac, - Encoder_State_fx *st, - HANDLE_PLC_ENC_EVS hPlc_Ext, - Word16 target_bits, /* i/o : coder memory state */ - Word16 Q_new, - Word16 shift, - Word16 *pitch_buf, /* output : pitch values for each subfr.*/ - Word16 *voice_factors, /* output : voicing factors */ - Word16 *bwe_exc /* output : excitation for SWB TBE */ -); - - -void decoder_acelp( - Decoder_State_fx *st, - Word16 coder_type, /* input: coder type */ - Word16 prm[], /* input: parameters */ - Word16 A[], /* input: coefficients NxAz[M+1] */ - ACELP_config acelp_cfg, /* input: ACELP config */ - Word16 synth[], /* i/o: synth[-2*LFAC..L_DIV] Q0 */ - Word16 *pT, /* out: pitch for all subframe Q0 */ - Word16 *pgainT, /* out: pitch gain for all subfr 1Q14 */ - Word16 stab_fac, /* input: stability of isf */ - Word16 *pitch_buffer, /* out: pitch values for each subfr.*/ - Word16 *voice_factors, /* out: voicing factors */ - const Word16 LSF_Q_prediction,/* i : LSF prediction mode */ - Word16 *bwe_exc /* out: excitation for SWB TBE */ -); - -void enc_prm( - const Word16 coder_type, /* (i) : coding type */ - Word16 param[], /* (i) : parameters */ - Word16 param_lpc[], /* (i) : LPC parameters */ - Encoder_State_fx *st, /* io: quantization Analysis values */ - Word16 L_Frame, - CONTEXT_HM_CONFIG hm_cfg[], - Word16 * bits_param_lpc, - Word16 no_param_lpc -); - -void enc_prm_rf( - Encoder_State_fx *st, - const Word16 rf_frame_type, - const Word16 fec_offset -); - -void dec_prm( - Word16 *core, /* (0) : current frame mode */ - Word16 *last_core, /* (0) : last frame mode */ - Word16 *coder_type, - Word16 param[], /* (o) : decoded parameters */ - Word16 param_lpc[], /* (o) : LPC parameters */ - Word16 *total_nbbits, /* i/o : number of bits / decoded bits */ - Decoder_State_fx *st, - Word16 L_frame, - Word16 *bitsRead -); - -void dec_prm_core( - Decoder_State_fx *st -); - -void analy_sp( /* o: fft0 bin energy Q0 */ - Word16 *speech, /* i: speech buffer Q_new - preemph_bits */ - const Word16 Q_new, /* i: current scaling exp Q0 */ - Word32 *fr_bands, /* o: energy in critical frequency bands Q_new + QSCALE */ - Word32 *lf_E, /* o: per bin E for first... Q_new + QSCALE - 2*/ - Word16 *Etot, /* o: total input energy Q8 */ - const Word16 min_band, /* i: minimum critical band Q0 */ - const Word16 max_band, /* i: maximum critical band Q0 */ - const Word32 e_min_scaled, /* i: minimum energy scaled Q_new + QSCALE */ - Word16 Scale_fac[2], /* o: FFT scales factors (2 values by frame) Q0 */ - Word32 *Bin_E, /* o : per bin log energy spectrum */ - Word32 *Bin_E_old, /* o : per bin log energy spectrum for mid-frame */ - Word32 *PS, /* o : Per bin energy spectrum */ - Word16 *EspecdB, /* o : log E spectrum (with f=0) of the current frame Q7 */ - Word32 *band_energies, /* o : energy in critical frequency bands without minimum noise floor MODE2_E_MIN */ - Word16 *fft_buff /* o : FFT coefficients */ -); - -void E_UTIL_copy_scale_sig( - const Word16 x[], /* i : signal to scale input Qx */ - Word16 y[], /* o : scaled signal output Qx */ - const Word16 lg, /* i : size of x[] Q0 */ - const Word16 exp0 /* i : exponent: x = round(x << exp) Qx xx exp */ -); - -void scale_sig32( - Word32 x[], /* i/o: signal to scale Qx */ - const Word16 lg, /* i : size of x[] Q0 */ - const Word16 exp0 /* i : exponent: x = round(x << exp) Qx xx exp */ -); - - -Word32 scale_mem( /* o : Min energy scaled */ - Word16 ini_frames, /* i : Frame number */ - Word16 Q_exp, /* i : Diff scaling factor */ - Word16 *Q_new, /* i/o: Absolute scaling factor */ - Word16 *old_speech, /* i/o: Speech memory */ - Word16 *old_speech_ns, /* i/o: Speech denoised memory */ - Word16 *mem_wsp, /* i/o: wsp vector memory */ - Word32 *enrO, /* i/o: Enr mem */ - Word32 *bckr, /* i/o: Back ground_fx ener mem */ - Word32 *lf_EO, /* i/o: Energy per low freq bin mem */ - Word32 *ave_enr, /* i/o: Ave_enr mem */ - Word32 *st_fr_bands1, /* i/o: spectrum per critical bands of the previous frame */ - Word32 *st_fr_bands2, /* i/o: spectrum per critical bands 2 frames ago */ - Word32 *ave_enr2 /* i/o: LT average E per crit. band (for non_sta2) Q_new + QSCALE */ -); - -Word16 rescale_exc( - Word16 exc[], /* i/o: excitation to rescale Q_exc */ - Word16 lg, /* i : frame size */ - Word32 L_gain_code, /* i : decoded codebook gain Q16 */ - Word16 *sQ_exc, /* i/o: Excitation scaling factor */ - Word16 *sQsubfr, /* i/o: Past excitation scaling factors */ - Word16 exc2[], /* o : local excitation vector */ - Word16 i_subfr /* i : subframe number */ -); - -Word16 rescale_mem( - const Word16 *Q_exc, /* i : current excitation scaling (>=0) */ - Word16 *prev_Q_syn, /* i/o : scaling factor of previous frame */ - Word16 *Q_syn, /* i/o : scaling factor of frame */ - Word16 *mem_syn2, /* i/o : modified synthesis memory */ - Word16 *syn, /* i/o : synthesis to rescale Q_syn */ - Word16 mem_len, /* i : lenght of modified synthesis memory */ - Word16 i_subfr /* i : subframe number */ -); - -void gauss_L2( - const Word16 h[], /* i : weighted LP filter impulse response Q14+s */ - Word16 code2[], /* o : gaussian excitation Q9 */ - const Word16 y2[], /* i : zero-memory filtered code. excitation Q9 */ - Word16 y11[], /* o : zero-memory filtered gauss. excitation Q9 */ - Word32 *gain, /* o : excitation gain */ - ACELP_CbkCorr *g_corr, /*i/o : correlation structure for gain coding */ - const Word16 gain_pit, /* i : unquantized gain of code */ - const Word16 tilt_code, /* i : tilt of code Q15 */ - const Word16 *Aq, /* i : quantized LPCs Q12 */ - const Word16 formant_enh, /* i : formant enhancement factor Q15 */ - Word16 *seed_acelp, /*i/o : random seed Q0 */ - const Word16 shift -); - -void gaus_L2_dec( - Word16 *code, /* o : decoded gaussian codevector Q9 */ - Word16 tilt_code, /* i : tilt of code Q15 */ - const Word16 *A, /* i : quantized LPCs Q12 */ - Word16 formant_enh, /* i : formant enhancement factor Q15 */ - Word16 *seed_acelp /*i/o : random seed Q0 */ -); - -void tcx_ltp_get_lpc( - Word16 *x, - Word16 L, - Word16 *A, - Word16 order -); - -void predict_signal( - const Word16 excI[], /* i : input excitation buffer */ - Word16 excO[], /* o : output excitation buffer */ - const Word16 T0, /* i : integer pitch lag */ - Word16 frac, /* i : fraction of lag */ - const Word16 frac_max, /* i : max fraction */ - const Word16 L_subfr /* i : subframe size */ -); - -void tcx_ltp_pitch_search( - Word16 pitch_ol, - Word16 *pitch_int, - Word16 *pitch_fr, - Word16 *index, - Word16 *norm_corr, - const Word16 len, - Word16 *wsp, - Word16 pitmin, - Word16 pitfr1, - Word16 pitfr2, - Word16 pitmax, - Word16 pitres -); - -void tcx_ltp_encode( Word8 tcxltp_on, - Word8 tcxOnly, - Word16 tcxMode, - Word16 L_frame, - Word16 L_subfr, - Word16 *speech, - Word16 *speech_ltp, - Word16 *wsp, - Word16 Top, - Word16 *ltp_param, - Word16 *ltp_bits, - Word16 *pitch_int, - Word16 *pitch_fr, - Word16 *gain, - Word16 *pitch_int_past, - Word16 *pitch_fr_past, - Word16 *gain_past, - Word16 *norm_corr_past, - Word16 last_core, - Word16 pitmin, - Word16 pitfr1, - Word16 pitfr2, - Word16 pitmax, - Word16 pitres, - struct TransientDetection const * pTransientDetection, - Word8 SideInfoOnly, - Word16 *A, - Word16 lpcorder - ); - -void tcx_ltp_post( Word8 tcxltp_on, - Word16 core, - Word16 L_frame, - Word16 L_frame_core, - Word16 delay, - Word16 *sig, - Word16 *tcx_buf, - Word16 tcx_buf_len, - Word16 bfi, - Word16 pitch_int, - Word16 pitch_fr, - Word16 gain, - Word16 *pitch_int_past, - Word16 *pitch_fr_past, - Word16 *gain_past, - Word16 *filtIdx_past, - Word16 pitres, - Word16 *pitres_past, - Word16 damping, - Word16 SideInfoOnly, - Word16 *mem_in, - Word16 *mem_out, - Word32 bitrate - ); - -Word16 tcx_ltp_decode_params( Word16 *ltp_param, - Word16 *pitch_int, - Word16 *pitch_fr, - Word16 *gain, - Word16 pitmin, - Word16 pitfr1, - Word16 pitfr2, - Word16 pitmax, - Word16 pitres - ); - -/*isf_msvq_ma.c, lsf_msvq_ma.c*/ -void msvq_enc -( - const Word16 *const*cb, /* i : Codebook (indexed cb[*stages][levels][p]) (0Q15) */ - const Word16 dims[], /* i : Dimension of each codebook stage (NULL: full dim.) */ - const Word16 offs[], /* i : Starting dimension of each codebook stage (NULL: 0) */ - const Word16 u[], /* i : Vector to be encoded (prediction and mean removed)(14Q1*1.28) */ - const Word16 *levels, /* i : Number of levels in each stage */ - const Word16 maxC, /* i : Tree search size (number of candidates kept from */ - /* one stage to the next == M-best) */ - const Word16 stages, /* i : Number of stages */ - const Word16 w[], /* i : Weights Q8 */ - const Word16 N, /* i : Vector dimension */ - const Word16 maxN, /* i : Codebook dimension */ - Word16 Idx[] /* o : Indices */ -); -void msvq_dec -( - const Word16 *const*cb, /* i : Codebook (indexed cb[*stages][levels][p]) (0Q15) */ - const Word16 dims[], /* i : Dimension of each codebook stage (NULL: full dim.) */ - const Word16 offs[], /* i : Starting dimension of each codebook stage (NULL: 0) */ - const Word16 stages, /* i : Number of stages */ - const Word16 N, /* i : Vector dimension */ - const Word16 maxN, /* i : Codebook dimension */ - const Word16 Idx[], /* i : Indices */ - Word16 *uq /* o : quantized vector (3Q12) */ -); - - -/*------------------------------------------------------------------------- -* Recovery tools for resynchronization -*------------------------------------------------------------------------*/ -/*er_sync_exc.c*/ -/** Resynchronize glotal pulse positions of the signal in src_exc and store it in dst_exc. - * src_exc holds on call the harmonic part of the signal with the constant pitch, constructed by repeating the last pitch cycle of length pitchStart. - * dst_exc holds on return the harmonic part of the signal with the pitch changing from pitchStart to pitchEnd. - * src_exc and dst_exc can overlap, but src_exc < dst_exc must be fullfiled. - * @param src_exc Input excitation buffer. - * @param dst_exc Output excitation buffer. - * @param nFrameLength Length of the frame, that is the length of the valid data in the excitation buffer on return. - * @param nSubframes Number of subframes in the excitation buffer. nFrameLength must be divisible by nSubframes. - * @param pitchStart Pitch at the end of the last frame. - * @param pitchEnd Pitch at the end of the current frame. - */ -void PulseResynchronization( - Word16 /*float*/ const * const src_exc, /*i Q15*/ - Word16 /*float*/ * const dst_exc, /*o Q15*/ - Word16 /*int*/ const nFrameLength, /*i Q0 */ - Word16 /*int*/ const nSubframes, /*i Q0 */ - Word32 /*float*/ const pitchStart, /*i Q16*/ - Word32 /*float*/ const pitchEnd /*i Q16*/ -); - -/* er_util.c*/ -/* PLC: [TCX: TD PLC] - * PLC: FindSubframePitchInTCX: function to find the pitch per half a frame for the last TCX */ -/*VERSIONINFO: This port is up to date with trunk rev. 30479*/ -/*VERSIONINFO: This port is up to date with trunk rev. 7611*/ - -void con_acelp( - const Word16 A[], /*mem_syn >rescaling done */ - , Word16 *pitch_buffer - , Word16 *voice_factors - , Word16 *bwe_exc -); - -void con_tcx( - Decoder_State_fx *st, /* i/o: coder memory state */ - Word16 /*float*/ synth[] /* i/o: synth[] *//*Q0 */ -); - - -/* isf_msvq_ma.c */ -void isf_msvq_ma_enc(const Word16 *isf, /* i: isf coefficients (3Q12) */ - Word16 *isfq, /* o: quantized isf */ - Word16 *isfq_ind, - Word16 *indices, /* o: quantizer indices */ - Word16 *nb_indices, /* o: number of bits for the indices */ - Word16 *mem_MA, /* i/o: moving average filter buffer (3Q12) */ - Word16 *parcorr, - const Word16 m, /* i: lpc order */ - const Word16 acelp_mode, /* i: acelp mode */ - const Word8 narrow_band /* i: narrow-band flag */ - ); -void isf_msvq_ma_dec( Word16 *isfq, - Word16 *isfq_ind, - Word16 *indices, - Word16 *nb_indices, - Word16 *mem_MA, - Word16 m, - Word16 acelp_mode, - Word8 narrow_band /* i: narrow-band flag */ - ); -Word16 isf_msvq_ma_encprm( Encoder_State_fx *st, Word16 *param_lpc, Word16 core, Word16 acelp_mode, Word16 acelp_midLpc, Word16 m ); -Word16 isf_msvq_ma_decprm( Decoder_State_fx *st, Word16 *param_lpc, Word16 core, Word16 acelp_mode, Word16 acelp_midLpc, Word16 m ); - -/* Returns: non-zero on conversion error, 0 otherwise */ -Word16 E_LPC_lsp_unweight( - /* const */ Word16 xsp_w[], /* (I): weighted xSP */ - Word16 xsp_uw[], /* (O): unweighted xSP */ - Word16 xsf_uw[], /* (O): unweighted xSF */ - Word16 inv_gamma, /* (I): inverse weighting factor */ - Word16 lpcorder /* (I): prediction order */ -); - -Word16 lsf_ind_is_active( - const Word16 lsf_q_ind[], - const Word16 means[], - Word16 bandwidth, - Word16 cdk); - -void lsf_update_memory( - Word16 narrowband, /* i : narrowband flag */ - const Word16 qisf[], /* i : quantized xSF coefficients */ - Word16 old_mem_MA[], /* i : MA memory */ - Word16 mem_MA[], /* o : updated MA memory */ - Word16 lpcorder /* i : LPC order */ -); - -/* Returns: number of indices */ -Word16 Q_lsf_tcxlpc( - /* const */ Word16 xsf[], /* (I) original xSF */ - Word16 xsf_q[], /* (O) quantized xSF */ - Word16 xsf_q_ind[], /* (O) quantized xSF (w/o MA prediction) */ - Word16 indices[], /* (O) VQ indices */ - Word16 lpcorder, /* (I) LPC order */ - Word16 narrowband, /* (I) narrowband flag */ - Word16 cdk, /* (I) codebook selector */ - Word16 mem_MA[], /* (I) MA memory */ - Word16 coder_type, - Word32 * Bin_Ener, - const Word16 Q_ener -); - -/* Returns: number of indices */ -Word16 D_lsf_tcxlpc( - const Word16 indices[], /* (I) VQ indices */ - Word16 xsf_q[], /* (O) quantized xSF */ - Word16 xsf_q_ind[], /* (O) quantized xSF (w/o MA prediction) */ - Word16 narrowband, /* (I) narrowband flag */ - Word16 cdk, /* (I) codebook selector */ - Word16 mem_MA[] /* (I) MA memory */ -); - -/* Returns: number of bits written */ -Word16 enc_lsf_tcxlpc( - Word16 **indices, /* (I) Ptr to VQ indices */ - Encoder_State_fx *st /* (I/O) Encoder state */ -); - -/* Returns: number of bits read */ -Word16 dec_lsf_tcxlpc( - Decoder_State_fx *st, /* (I/O) Decoder state */ - Word16 **indices, /* (O) Ptr to VQ indices */ - Word16 narrowband, /* (I) narrowband flag */ - Word16 cdk /* (I) codebook selector */ -); - -/* Returns: codebook index */ -Word16 tcxlpc_get_cdk( - Word16 coder_type /* (I) VOICED indicator */ -); - -/* lsf_msvq_ma.c */ -void lsf_msvq_ma_enc( - const Word16 *lsf, /* i: lsf coefficients (14Q1*1.28)*/ - Word16 *lsfq, /* o: quantized lsf */ - Word16 *lsfq_ind, - Word32 * Bin_Ener_128_fx, - const Word16 Q_ener, - Word16 *indices, /* o: quantizer indices */ - Word16 *nb_indices, /* o: number of bits for the indices */ - Word16 *mem_MA, /* i/o: moving average filter buffer (3Q12*1.28)*/ - const Word16 m, /* i: lpc order */ - const Word16 acelp_mode /* i: acelp mode */ -); - -void lsf_msvq_ma_dec( Word16 *lsfq, - Word16 *lsfq_ind, - Word16 *indices, - Word16 *nb_indices, - Word16 *mem_MA, - Word16 m, - Word16 acelp_mode - ); - -Word16 lsf_msvq_ma_encprm( Encoder_State_fx * st, - Word16 *param_lpc, - Word16 core, - Word16 acelp_mode, - Word16 acelp_midLpc, - Word16 * bits_param_lpc, - Word16 no_indices - ); -Word16 lsf_msvq_ma_decprm( Decoder_State_fx *st, Word16 *param_lpc, Word16 core, Word16 acelp_mode, Word16 acelp_midLpc - ,Word16 narrowBand - ,Word32 sr_core - ); - -Word16 lsf_bctcvq_encprm( - Encoder_State_fx *st, - Word16 *param_lpc, - Word16 * bits_param_lpc, - Word16 no_indices -); - -Word16 lsf_bctcvq_decprm( - Decoder_State_fx * st, - Word16 *param_lpc -); -void lpc_unquantize( - Decoder_State_fx * st, - Word16 *lsfold, - Word16 *lspold, - Word16 *lsf, - Word16 *lsp, - const Word16 m, - const Word16 lpcQuantization, - Word16 *param_lpc, - const Word16 numlpc, - const Word16 core, - Word16 *mem_MA, - Word16 *mem_AR, - Word16 *lspmid, - Word16 *lsfmid, - Word16 coder_type, - Word16 acelp_midLpc, - Word8 narrow_band, - Word16 *seed_acelp, - Word32 sr_core, - Word16 *mid_lsf_int, - Word16 prev_bfi, - Word16 *LSF_Q_prediction, /* o : LSF prediction mode */ - Word16 *safety_net -); - -void midlsf_enc(const Word16 qlsf0[], /* i: quantized lsf coefficients (3Q12) */ - const Word16 qlsf1[], /* i: quantized lsf coefficients (3Q12) */ - const Word16 lsf[], /* i: lsf coefficients (3Q12) */ - Word16 *idx, /* o: codebook index */ - const Word16 lpcorder /* i: order of the lpc */ - , Word32 * Bin_Ener_128_fx - ,const Word16 Q_ener - ,Word8 narrowBand - ,Word32 sr_core - ,Word16 coder_type - ); - - -void midlsf_dec( - const Word16 qlsf0[], /* i: quantized lsf coefficients (3Q12) */ - const Word16 qlsf1[], /* i: quantized lsf coefficients (3Q12) */ - Word16 idx, /* i: codebook index */ - Word16 qlsf[], /* o: decoded lsf coefficients (3Q12) */ - Word16 coder_type, - Word16 *mid_lsf_int, - Word16 prev_bfi, - Word16 safety_net); - - -Word16 const * PlcGetLsfBase (Word16 const lpcQuantization, - Word16 const narrowBand, - Word32 const sr_core); - -/* tcx_mdct.h */ -#define MDCT_A_E 1 - -#define TCX_IMDCT_SCALE 15 -#define TCX_IMDCT_HEADROOM 1 - -void TCX_MDCT(const Word16 *x, Word32 *y, Word16 *y_e, Word16 l, Word16 m, Word16 r); - -void TCX_MDST(const Word16 *x, Word32 *y, Word16 *y_e, Word16 l, Word16 m, Word16 r); - -void TCX_MDCT_Inverse(Word32 *x, Word16 x_e, Word16 *y, Word16 l, Word16 m, Word16 r); - - -/* post_dec.h */ -void post_decoder( - Decoder_State_fx *st, - Word16 coder_type, - Word16 synth_buf[], - Word16 pit_gain[], - Word16 pitch[], - Word16 signal_out[], - Word16 * bpf_noise_buf -); - -Word16 bass_pf_enc( - Word16 *orig, /* (i) : 12.8kHz original signal Q0 */ - Word16 *syn, /* (i) : 12.8kHz synthesis to postfilter Q0 */ - Word16 *T_sf, /* (i) : Pitch period for all subframes (T_sf[16]) Q0 */ - Word16 *gainT_sf, /* (i) : Pitch gain for all subframes (gainT_sf[16]) Q14 */ - Word16 l_frame, /* (i) : frame length (should be multiple of l_subfr) Q0 */ - Word16 l_subfr, /* (i) : sub-frame length (60/64) Q0 */ - Word16 *gain_factor_param, /* (o) : quantized gain factor Q0 */ - Word16 mode, /* (i) : coding mode of adapt bpf */ - struct MEM_BPF *mem_bpf /* i/o : memory state */ -); -void cldfb_synth_set_bandsToZero( - Decoder_State_fx *st, - Word32 **rAnalysis, - Word32 **iAnalysis, - const Word16 nTimeSlots, - const CLDFB_SCALE_FACTOR scaleFactor -); -/* fd_cng_common.h */ -/* Create an instance of type FD_CNG */ -void createFdCngCom(HANDLE_FD_CNG_COM* hFdCngCom); - -void initFdCngCom(HANDLE_FD_CNG_COM hFdCngCom, Word16 scale); - -/* Delete the instance of type FD_CNG */ -void deleteFdCngCom(HANDLE_FD_CNG_COM * hFdCngCom); - -void resetFdCngEnc( Encoder_State_fx * st); - -/* Initialize the spectral partitioning */ -void initPartitions( const Word16* part_in, - Word16 npart_in, - Word16 startBand, - Word16 stopBand, - Word16* part_out, - Word16* npart_out, - Word16* midband, - Word16* psize, - Word16* psize_norm, - Word16* psize_norm_exp, - Word16* psize_inv, - Word16 stopBandFR); - -/* Noise estimation using Minimum Statistics (MS) */ -void compress_range(Word32 *in, - Word16 in_exp, - Word16 *out, - Word16 len - ); - -void expand_range(Word16 *in, - Word32 *out, - Word16 *out_exp, - Word16 len - ); - -void minimum_statistics(Word16 len, /* i : Total number of partitions (CLDFB or FFT) */ - Word16 lenFFT, /* i : Number of FFT partitions */ - Word16 *psize, /* i : Partition sizes, fractional */ - Word16 *msPeriodog, /* i : Periodogram (energies) */ - Word16 *msNoiseFloor, /* i/o: Noise floors (energies) */ - Word16 *msNoiseEst, /* i/o: Noise estimates (energies) */ - Word32 *msAlpha, /* i/o: Forgetting factors */ - Word16 *msPsd, /* i/o: Power Spectral Density (smoothed periodogram => energies) */ - Word16 *msPsdFirstMoment, /* i/o: PSD statistics of 1st order (energy means) */ - Word32 *msPsdSecondMoment, /* i/o: PSD statistics of 2nd order (energy variances) */ - Word32 *msMinBuf, /* i/o: Buffer of minima (energies) */ - Word32 *msBminWin, /* o : Bias correction factors */ - Word32 *msBminSubWin, /* o : Bias correction factors */ - Word32 *msCurrentMin, /* i/o: Local minima (energies) */ - Word32 *msCurrentMinOut, /* i/o: Local minima (energies) */ - Word32 *msCurrentMinSubWindow, /* i/o: Local minima (energies) */ - Word16 *msLocalMinFlag, /* i : Binary flag */ - Word16 *msNewMinFlag, /* i : Binary flag */ - Word16 *msPeriodogBuf, /* i/o: Buffer of periodograms (energies) */ - Word16 *msPeriodogBufPtr, /* i/o: Counter */ - HANDLE_FD_CNG_COM st /* i/o: FD_CNG structure containing buffers and variables */ - ); - -/* Generate the comfort noise based on the target noise level */ -void generate_comfort_noise_enc (Encoder_State_fx *stcod, - Word16 Q_new, - Word16 gen_exc - ); -void generate_comfort_noise_dec (Word32 **bufferReal, /* o : matrix to real part of input bands */ - Word32 **bufferImag, /* o : matrix to imaginary part of input bands */ - Word16 *bufferScale, /* o : pointer to scalefactor for real and imaginary part of input bands */ - Decoder_State_fx *stdec, - Word16 *Q_new, - Word16 gen_exc - ); -void -generate_comfort_noise_dec_hf (Word32 **bufferReal, /* o : matrix to real part of input bands */ - Word32 **bufferImag, /* o : matrix to imaginary part of input bands */ - Word16 *bufferScale, /* o : pointer to scalefactor for real and imaginary part of input bands */ - Decoder_State_fx *stdec - ); - -/* Generate the comfort noise based on the target noise level */ -void generate_masking_noise (Word16 *timeDomainBuffer, /* i/o: time-domain signal */ - Word16 Q, - HANDLE_FD_CNG_COM st /* i/o: FD_CNG structure containing all buffers and variables */ - ,Word16 length - ,Word16 core - ); - -void generate_masking_noise_update_seed ( - HANDLE_FD_CNG_COM st /* i/o : pointer to FD_CNG_COM structure */ -); - -void generate_masking_noise_mdct (Word32 *mdctBuffer, /* i/o: time-domain signal */ - Word16 *mdctBuffer_e, /* i/o: exponent time-domain signal */ - HANDLE_FD_CNG_COM st /* i/o: FD_CNG structure containing all buffers and variables */ - ,Word16 L_frame - ); - -/* Apply bitrate-dependant scale */ -void apply_scale(Word32 *scale, - Word16 bwmode, - Word32 bitrate - ); - -/* Compute the power for each partition */ -void bandcombinepow(Word32* bandpow, /* i : Power for each band */ - Word16 exp_bandpow, /* i : exponent of bandpow */ - Word16 nband, /* i : Number of bands */ - Word16* part, /* i : Partition upper boundaries (band indices starting from 0) */ - Word16 npart, /* i : Number of partitions */ - Word16* psize_inv, /* i : Inverse partition sizes */ - Word32* partpow, /* o : Power for each partition */ - Word16* exp_partpow - ); - -/* Scale partitions (with smoothing) */ -void scalebands (Word32 *partpow, /* i : Power for each partition */ - Word16 *part, /* i : Partition upper boundaries (band indices starting from 0) */ - Word16 npart, /* i : Number of partitions */ - Word16 *midband, /* i : Central band of each partition */ - Word16 nFFTpart, /* i : Number of FFT partitions */ - Word16 nband, /* i : Number of bands */ - Word32 *bandpow, /* o : Power for each band */ - Word16 flag_fft_en - ); - -/* Get central band for each partition */ -void getmidbands(Word16* part, /* i : Partition upper boundaries (band indices starting from 0) */ - Word16 npart, /* i : Number of partitions */ - Word16* midband, /* o : Central band of each partition */ - Word16* psize, /* o : Partition sizes */ - Word16* psize_norm, /* o : Partition sizes, fractional values */ - Word16* psize_norm_exp, /* o : Exponent for fractional partition sizes */ - Word16* psize_inv /* o : Inverse of partition sizes */ - ); - -/* STFT analysis filterbank */ -void AnalysisSTFT (const Word16 *timeDomainInput, /* i : pointer to time signal */ - Word16 Q, - Word32 *fftBuffer, /* o : FFT bins */ - Word16 *fftBuffer_exp, /* i : exponent of FFT bins */ - HANDLE_FD_CNG_COM st /* i/o: FD_CNG structure containing all buffers and variables */ - ); - -/* STFT synthesis filterbank */ -void SynthesisSTFT (Word32 *fftBuffer, /* i : pointer to FFT bins */ - Word16 fftBufferExp, /* i : exponent of FFT bins */ - Word16 *timeDomainOutput, /* o : pointer to time domain signal */ - Word16 *olapBuffer, /* i/o : pointer to overlap buffer */ - const PWord16 *olapWin, /* i : pointer to overlap window */ - Word16 tcx_transition, - HANDLE_FD_CNG_COM st, /* i/o : pointer to FD_CNG structure containing all buffers and variables */ - Word16 gen_exc, - Word16 *Q_new - ); - -/* Compute some calues used in the bias correction of the minimum statistics algorithm */ -void mhvals(Word16 d, Word16 * m/*, float * h*/); - -/* Random generator with Gaussian distribution with mean 0 and std 1 */ -Word32 rand_gauss (Word16 *seed); - -void lpc_from_spectrum (Word32 *powspec, - Word16 powspec_exp, - Word16 start, - Word16 stop, - Word16 fftlen, - Word16 *A, - Word16 lpcorder, - Word16 preemph_fac); - -void msvq_decoder(const Word16 *const cb[], /* i : Codebook (indexed cb[*stages][levels][p]) */ - Word16 stages, /* i : Number of stages */ - Word16 N, /* i : Vector dimension */ - Word16 maxN, /* i : Codebook vector dimension */ - Word16 Idx[], /* i : Indices */ - Word16 *uq /* o : quantized vector */ - ); - -/*fd_cng_dec.h*/ -/* Create an instance of type FD_CNG */ -void createFdCngDec(HANDLE_FD_CNG_DEC* hFdCngDec); - -Word16 initFdCngDec(HANDLE_FD_CNG_DEC hFdCngDec, Word16 scale); -extern void E_LPC_isf_isp_conversion(const Word16 isf[], Word16 isp[], const Word16 m); -extern void E_LPC_f_isp_a_conversion(const Word16 *isp, Word16 *a, const Word16 m); - -/* Delete the instance of type FD_CNG */ -void deleteFdCngDec(HANDLE_FD_CNG_DEC * hFdCngDec); - -/* Configure CLDFB-CNG */ -void configureFdCngDec(HANDLE_FD_CNG_DEC hs, /* i/o: Contains the variables related to the CLDFB-based CNG process */ - Word16 bandwidth, - Word32 bitrate, - Word16 cng_type); - - -/* Apply the CLDFB-based CNG */ -Word16 ApplyFdCng (Word16 * timeDomainInput, /* i : pointer to time domain input */ - Word16 Q, - Word32 ** cldfbBufferReal, /* i/o: real part of the CLDFB buffer */ - Word32 ** cldfbBufferImag, /* i/o: imaginary part of the CLDFB buffer */ - Word16 * cldfbBufferScale, /* o : pointer to the scalefactor for real and imaginary part of the CLDFB buffer */ - HANDLE_FD_CNG_DEC st, /* i/o: pointer to FD_CNG structure containing all buffers and variables */ - Word16 m_frame_type, /* i : type of frame at the decoder side */ - Decoder_State_fx *stdec, - const Word16 concealWholeFrame, /* i : binary flag indicating frame loss */ - Word16 is_music - ); - -/* Perform noise estimation */ -void perform_noise_estimation_dec(const Word16 *timeDomainInput, /* i: pointer to time domain input */ - Word16 Q, - HANDLE_FD_CNG_DEC st /* i/o: FD_CNG structure containing all buffers and variables */ - ); - -/* Decode the CLDFB-CNG bitstream */ -void FdCng_decodeSID(HANDLE_FD_CNG_COM st, /* i/o: FD_CNG structure containing all buffers and variables */ - Decoder_State_fx *corest); /* i/o: decoder state structure */ - -void FdCng_exc( - HANDLE_FD_CNG_COM hs, - Word16 *CNG_mode, - Word16 L_frame, - Word16 *lsp_old, - Word16 first_CNG, - Word16 *lsp_CNG, - Word16 *Aq, /* o: LPC coeffs */ - Word16 *lsp_new, /* o: lsp */ - Word16 *lsf_new, /* o: lsf */ - Word16 *exc, /* o: LP excitation */ - Word16 *exc2, /* o: LP excitation */ - Word16 *bwe_exc /* o: LP excitation for BWE */ -); - -void noisy_speech_detection( - const Word16 vad, - const Word16 *ftimeInPtr, /* i : input time-domain frame */ - const Word16 frameSize, /* i : frame size */ - const Word16 Q, - const Word32 *msNoiseEst, /* i : noise estimate over all critical bands */ - const Word16 msNoiseEst_exp, /* i : exponent for noise estimate over all critical bands */ - const Word16 *psize_norm, - const Word16 psize_norm_exp, - const Word16 nFFTpart, /* i : Number of partitions taken into account */ - Word32 *lp_noise, /* i/o: pointer to long term total Noise energy average */ - Word32 *lp_speech, /* i/o: pointer to long term active speech energy average */ - Word16 *flag_noisy_speech -); - -/* Create an instance of type FD_CNG */ -void createFdCngEnc(HANDLE_FD_CNG_ENC* hFdCngEnc); - -void initFdCngEnc(HANDLE_FD_CNG_ENC hsEnc, Word32 input_Fs, Word16 scale); - -/* Delete the instance of type FD_CNG */ -void deleteFdCngEnc(HANDLE_FD_CNG_ENC * hFdCngEnc); - -/* Configure CLDFB-CNG */ -void configureFdCngEnc(HANDLE_FD_CNG_ENC hs, /* i/o: Contains the variables related to the CLDFB-based CNG process */ - Word16 bandwidth, /* i: bandwidth */ - Word32 bitrate); - -/* Perform noise estimation */ -void perform_noise_estimation_enc( - Word32 *band_energies, /* i: energy in critical bands without minimum noise floor MODE2_E_MIN */ - Word16 exp_band_energies, - Word32 *enerBuffer, - Word16 enerBuffer_exp, - HANDLE_FD_CNG_ENC st); /* i/o: FD_CNG structure containing all buffers and variables */ - -/* Adjust the noise estimator at the beginning of each CNG phase (encoder-side) */ -Word16 -AdjustFirstSID(Word16 npart, - Word32 *msPeriodog, - Word16 msPeriodog_exp, - Word32 *energy_ho, - Word16 *energy_ho_exp, - Word32 *msNoiseEst, - Word16 *msNoiseEst_exp, - Word32 *msNoiseEst_old, - Word16 *msNoiseEst_old_exp, - Word16 *active_frame_counter, - Encoder_State_fx *stcod - ); - -/* Generate a bitstream out of the partition levels */ -void FdCng_encodeSID (HANDLE_FD_CNG_ENC st, /* i/o: FD_CNG structure containing all buffers and variables */ - Encoder_State_fx *corest, - Word16 preemph_fac /* i : preemphase factor */ - ); - -/*parameter_bitmaping.h*/ -/** Writes parameters from paramsBitMap into a stream. - * @param paramsBitMap Definition of parameters and mappings to a bitstream. - * @param nParam Size of paramsBitMap. - * @param pParameter A parameter to be used in get and set functions from paramsBitMap. - * @param pStream Pointer to a stream where parameters should be stored. - * @param pnSize Set to the number of elements written to the stream. - * @param pnBits Set to the number of required bits. - */ -void GetParameters(ParamsBitMap const * paramsBitMap, Word16 nParams, void const * pParameter, Word16 ** pStream, Word16 * pnSize, Word16 * pnBits); - -/** Reads parameters from a stream into paramsBitMap. - * @param paramsBitMap Definition of parameters and mappings to a bitstream. - * @param nParam Size of paramsBitMap. - * @param pParameter A parameter to be used in get and set functions from paramsBitMap. - * @param pStream Pointer to a stream from which parameters are read. - * @param pnSize Set to the number of elements read from the stream. - */ -void SetParameters(ParamsBitMap const * paramsBitMap, Word16 nParams, void * pParameter, Word16 const ** pStream, Word16 * pnSize); - -/** Writes parameters from a stream into a bitstream. - * @param paramsBitMap Definition of parameters and mappings to a bitstream. - * @param nParam Size of paramsBitMap. - * @param pStream Pointer to a stream from which parameters are read. - * @param pnSize Set to the number of elements read from the stream. - * @param st Encoder state. - * @param pnBits Set to the number of bits written. - */ -void WriteToBitstream(ParamsBitMap const * paramsBitMap, Word16 nParams, Word16 const ** pStream, Word16 * pnSize, Encoder_State_fx *st, Word16 * pnBits); - -/** Reads parameters from a bitstream into a stream. - * @param paramsBitMap Definition of parameters and mappings to a bitstream. - * @param nArrayLength Size of paramsBitMap. - * @param st Decoder state. - * @param pStream Pointer to a stream where parameters should be stored. - * @param pnSize Set to the number of elements written to the stream. - */ -void ReadFromBitstream(ParamsBitMap const * paramsBitMap, Word16 nArrayLength, Decoder_State_fx *st, Word16 ** pStream, Word16 * pnSize); - -void const * GetTnsFilterOrder(void const * p, Word16 index, Word16 * pValue); -void * SetTnsFilterOrder(void * p, Word16 index, Word16 value); -void const * GetNumOfTnsFilters(void const * p, Word16 index, Word16 * pValue); -void * SetNumOfTnsFilters(void * p, Word16 index, Word16 value); -void const * GetTnsEnabled(void const * p, Word16 index, Word16 * pValue); -void * SetTnsEnabled(void * p, Word16 index, Word16 value); -void const * GetTnsEnabledSingleFilter(void const * p, Word16 index, Word16 * pValue); -void * SetTnsEnabledSingleFilter(void * p, Word16 index, Word16 value); -void const * GetTnsFilterCoeff(void const * p, Word16 index, Word16 * pValue); -void * SetTnsFilterCoeff(void * p, Word16 index, Word16 value); - - -Word16 GetSWBTCX10TnsFilterCoeffBits(Word16 value, Word16 index); -Word16 EncodeSWBTCX10TnsFilterCoeff(Word16 value, Word16 index); -Word16 DecodeSWBTCX10TnsFilterCoeff(Decoder_State_fx *st, Word16 index, Word16 * pValue); -Word16 GetSWBTCX20TnsFilterCoeffBits(Word16 value, Word16 index); -Word16 EncodeSWBTCX20TnsFilterCoeff(Word16 value, Word16 index); -Word16 DecodeSWBTCX20TnsFilterCoeff(Decoder_State_fx *st, Word16 index, Word16 * pValue); - -Word16 GetWBTCX20TnsFilterCoeffBits(Word16 value, Word16 index); -Word16 EncodeWBTCX20TnsFilterCoeff(Word16 value, Word16 index); -Word16 DecodeWBTCX20TnsFilterCoeff(Decoder_State_fx *st, Word16 index, Word16 * pValue); - -Word16 GetTnsFilterOrderBitsSWBTCX10(Word16 value, Word16 index); -Word16 EncodeTnsFilterOrderSWBTCX10(Word16 value, Word16 index); -Word16 DecodeTnsFilterOrderSWBTCX10(Decoder_State_fx *st, Word16 index, Word16 * pValue); -Word16 GetTnsFilterOrderBitsSWBTCX20(Word16 value, Word16 index); -Word16 EncodeTnsFilterOrderSWBTCX20(Word16 value, Word16 index); -Word16 DecodeTnsFilterOrderSWBTCX20(Decoder_State_fx *st, Word16 index, Word16 * pValue); -Word16 GetTnsFilterOrderBits(Word16 value, Word16 index); -Word16 EncodeTnsFilterOrder(Word16 value, Word16 index); -Word16 DecodeTnsFilterOrder(Decoder_State_fx *st, Word16 index, Word16 * pValue); - - -/*tns_base.h*/ -/** Reset TNS data. - * Resets TNS data to the initial state. - * @param pTnsData pointer to a TNS data to be reset. - */ -void ResetTnsData(STnsData * pTnsData); - -/** Clear TNS filter data. - * Resets TNS filter order and all coefficients to 0. - * @param pTnsFilter pointer to a TNS filter to be cleared. - */ -void ClearTnsFilterCoefficients(STnsFilter * pTnsFilter); - -/** Init TNS configuration. - * Fills STnsConfig structure with sensible content. - * @param nSampleRate Sampling rate of the input. - * @param nFrameLength Frame length. - * @param pTnsConfig TNS configuration to be initialized. - * @return 0 on success, otherwise 1. - */ -Word16 InitTnsConfiguration(Word32 nSampleRate, - Word16 frameLength, - STnsConfig * pTnsConfig - ,Word16 igfStopFreq - ,Word32 bitrate - ); - -/** Detect TNS parameters. - * Detects if TNS should be used and fills TNS data in pTnsData. - * @param pTnsConfig TNS configuration. - * @param pSpectrum Spectrum lines. - TNS is tested on the spectrum defined by pSpectrum. - * @param sbCnt Number of active subbands. - * @param pTnsData TNS data is filled with sensible information. - * @return Returns 1 if Tns should be used, otherwise 0. - */ -Word16 DetectTnsFilt(STnsConfig const * pTnsConfig, - Word32 const pSpectrum[], - STnsData * pTnsData, - Word16 *predictionGain); - -/** Modify spectrum using TNS filter. - * Modifies spectrum unsing TNS filter defined by pTnsData. - * If fIsAnalyses is true considers spectrum to be - * an input of encoder and returns residum. - * If fIsAnalyses is false considers spectrum to be - * a residum from decoder and returns output spectrum. - * @param pTnsConfig TNS configuration. - * @param pTnsData TNS data describing filters. - * @param spectrum Input/output spectrum. - * @param fIsAnalysis Defines if TNS filter is applied - * in encoder (TRUE) or in decoder (FALSE). - * @return 0 on success, otherwise 1. - */ -Word16 ApplyTnsFilter(STnsConfig const * pTnsConfig, - STnsData const * pTnsData, - Word32 spectrum[], - Word8 fIsAnalysis); - -Word16 ITF_Detect_fx(Word32 const pSpectrum[], - Word16 startLine, - Word16 stopLine, - Word16 maxOrder, - Word16* A, - Word16* Q_A, - Word16* predictionGain, - Word16* curr_order, - Word16 Q); - -TNS_ERROR ITF_Apply_fx(Word32 spectrum[], - Word16 startLine, Word16 stopLine, const Word16* A, - Word16 Q_A, - Word16 curr_order); - -/** Write TNS data into a stream of integers. - * Writes TNS data into a stream of integers. - * @param pTnsConfig TNS configuration. - * @param pTnsData TNS data to be written to a bitstream. - * @param stream Output stream of integers. - * @param pnSize Set to the number of elements written to the stream. - * @param pnBits Set to the number of required. - * @return 0 on success, otherwise 1. - */ -Word16 EncodeTnsData(STnsConfig const * pTnsConfig, - STnsData const * pTnsData, - Word16 * stream, - Word16 * pnSize, - Word16 * pnBits); - -/** Read TNS data from a stream of integers. - * Reads TNS data from a stream of integers. - * @param pTnsConfig TNS configuration. - * @param stream Input stream of integers. - * @param pnSize Set to the number of elements read from stream. - * @param pTnsData TNS data to be read from the bitstream. - * @return 1 if TNS is active, otherwise 0. - */ -Word16 DecodeTnsData(STnsConfig const * pTnsConfig, - Word16 const * stream, - Word16 * pnSize, - STnsData * pTnsData); - -/** Write TNS data into a bitstream. - * Writes TNS data into a bitstream. - * @param pTnsConfig TNS configuration. - * @param stream Contains TNS data written with EncodeTnsData. - * @param pnSize Set to the number of used elements from stream. - * @param st Encoder state. - * @param pnBits Set to the number of bits written. - * @return 0 on success, otherwise 1. - */ -Word16 WriteTnsData(STnsConfig const * pTnsConfig, - Word16 const * stream, - Word16 * pnSize, - Encoder_State_fx *st, - Word16 * pnBits); - -/** Read TNS data from a bitstream. - * Reads TNS data from a bitstream using bin2int. - * @param pTnsConfig TNS configuration. - * @param st Decoder state. - * @param pnBits Set to the number of bits written. - * @param stream Contains TNS data that can be decoded with DecodeTnsData. - * @param pnSize Set to the number of used elements from stream. - * @return 0 on success, otherwise 1. - */ -Word16 ReadTnsData(STnsConfig const * pTnsConfig, - Decoder_State_fx *st, - Word16 * pnBits, - Word16 * stream, - Word16 * pnSize); - -Word16 -CLDFB_getNumChannels(Word32 sampleRate); - -void -cldfbAnalysisFiltering( HANDLE_CLDFB_FILTER_BANK anaCldfb, /*!< Handle of Cldfb Analysis Bank */ - Word32 **cldfbReal, /*!< Pointer to real subband slots */ - Word32 **cldfbImag, /*!< Pointer to imag subband slots */ - CLDFB_SCALE_FACTOR *scaleFactor, /*!< Scale factors of CLDFB data */ - const Word16 *timeIn, /*!< Time signal */ - const Word16 timeIn_e, /*!< Time signal */ - const Word16 nTimeSlots, /*!< Time slots to be processed */ - Word32 *pWorkBuffer /*!< pointer to temporal working buffer */ - ); - -void -cldfbSynthesisFiltering(HANDLE_CLDFB_FILTER_BANK synCldfb, /*!< Handle of Cldfb Synthesis Bank */ - Word32 **CldfbBufferReal, /*!< Pointer to 32 bit real subband slots */ - Word32 **CldfbBufferImag, /*!< Pointer to 32 bit imag subband slots */ - const CLDFB_SCALE_FACTOR *scaleFactor, /*!< Scale factors of CLDFB data */ - Word16 *timeOut, /*!< Time signal */ - const Word16 timeOut_e, /*!< Target exponent for output signal */ - const Word16 nTimeSlots, /*!< number of time slots to be processed */ - Word32 *pWorkBuffer /*!< pointer to temporal working buffer */ - ); - -Word16 -cldfbInitAnalysisFilterBank(HANDLE_CLDFB_FILTER_BANK h_Cldfb, /*!< CLDFB Handle */ - Word16 *pFilterStates, /*!< Pointer to filter state buffer */ - Word16 frameSize, /*!< FrameSize */ - Word16 lsb, /*!< Number of lower bands */ - Word16 usb, /*!< Number of upper bands */ - Word16 no_channels, /*!< Number of critically sampled bands */ - UWord16 flags /*!< Flags */ - ); - -void -cldfbAnalysisFilteringSlot(HANDLE_CLDFB_FILTER_BANK anaCldfb, /*!< Handle of Cldfb Synthesis Bank */ - Word32 *cldfbReal, /*!< Low and High band, real */ - Word32 *cldfbImag, /*!< Low and High band, imag */ - Word32 *pWorkBuffer /*!< pointer to temporal working buffer */ - ); - -Word16 -cldfbInitSynthesisFilterBank(HANDLE_CLDFB_FILTER_BANK h_Cldfb, /*!< CLDFB Handle */ - Word16 *pFilterStates, /*!< Pointer to filter state buffer */ - Word16 noCols, /*!< Number of time slots */ - Word16 lsb, /*!< Number of lower bands */ - Word16 usb, /*!< Number of upper bands */ - Word16 no_channels, /*!< Number of critically sampled bands */ - UWord16 flags /*!< Flags */ - ); - -void cldfbSynthesisFilteringSlot(HANDLE_CLDFB_FILTER_BANK synCldfb, - const Word32 *realSlot, - const Word32 *imagSlot, - const Word16 scaleFactorLowBand, - const Word16 scaleFactorHighBand, - Word16 *timeOut, - const Word16 stride, - Word32 *pWorkBuffer - ); - - -void configureCldfb ( HANDLE_CLDFB_FILTER_BANK h_cldfb, /*!< CLDFB Handle */ - const Word16 no_channels, /*!< Number of critically sampled bands */ - const Word16 frameSize /*!< FrameSize */ - ); - -void openCldfb ( HANDLE_CLDFB_FILTER_BANK *h_cldfb, /*!< CLDFB Handle */ - const Word16 type, /*!< analysis or synthesis */ - const Word16 maxCldfbBands, /*!< number of cldfb bands */ - const Word16 frameSize /*!< FrameSize */ - ); - -void resampleCldfb ( - HANDLE_CLDFB_FILTER_BANK hs, /*!< CLDFB Handle */ - const Word16 newCldfbBands, /*!< number of cldfb bands */ - const Word16 frameSize, /*!< FrameSize */ - const Word8 firstFrame -); - -void -deleteCldfb (HANDLE_CLDFB_FILTER_BANK * h_cldfb); /*!< CLDFB Handle */ - -Word16 -CreateCldfbAnalysisFilterBank (HANDLE_CLDFB_FILTER_BANK *hAnalysisCldfb, - const Word16 maxCldfbBands, - const Word16 frameSize, - UWord16 flags - ); - -Word16 -DestroyCldfbAnalysisFilterBank (HANDLE_CLDFB_FILTER_BANK *hAnalysisCldfb - ); - -Word16 -CreateCldfbSynthesisFilterBank (HANDLE_CLDFB_FILTER_BANK *hSynthesisCldfb, - const Word16 maxCldfbBands, - const Word16 frameSize, - UWord16 flags - ); - -Word16 -DestroyCldfbSynthesisFilterBank (HANDLE_CLDFB_FILTER_BANK *hSynthesisCldfb - ); - -Word16 -ResampleCldfbAnalysisFilterBank (HANDLE_CLDFB_FILTER_BANK hs, - const Word16 newCldfbBands, - Word16 newFrameSize, - UWord16 flags, - Word8 firstFrame - ); - - - -Word16 -AnalysisPostSpectrumScaling_Fx (HANDLE_CLDFB_FILTER_BANK cldfbBank, - Word32 **rSubband32, - Word32 **iSubband32, - Word16 **rSubband16, - Word16 **iSubband16, - Word16 *cldfbScale - ); - -void -GetEnergyFromCplxCldfbData_Fx(Word32 **energyValues, - Word32 *energyLookahead, - Word16 *sf_energyLookahead, - const Word16 numLookahead, - Word16 **realValues, - Word16 **imagValues, - Word16 sf_Values, - Word16 numberBands, - Word16 numberCols, - Word32 *energyHF, - Word16 *energyHF_Exp - ); - -void -GetEnergyCldfb( Word32 *energyLookahead, /*!< o: Q31 | pointer to the result in the core look-ahead slot */ - Word16 *sf_energyLookahead, /*!< o: pointer to the scalefactor of the result in the core look-ahead slot - apply as negative exponent*/ - const Word16 numLookahead, /*!< i: Q0 the number of look-ahead time-slots */ - Word16 **realValues, /*!< i: Q15 | the real part of the CLDFB subsamples */ - Word16 **imagValues, /*!< i: Q15 | the imaginary part of the CLDFB subsamples */ - Word16 sf_Values, /*!< i: scalefactor of the CLDFB subcamples - apply as a negated Exponent */ - Word16 numberBands, /*!< i: Q0 | number of CLDFB bands */ - Word16 numberCols, /*!< i: Q0 | number of CLDFB subsamples */ - Word32 *energyHF, /*!< o: Q31 | pointer to HF energy */ - Word16 *energyHF_Exp, /*!< o: pointer to exponent of HF energy */ - Word32 *energyValuesSum, /*!< o: Q31 | pointer to sum array of energy values, not initialized*/ - Word16 *energyValuesSum_Exp /*!< o: pointer to exponents of energyValuesSum, not initialized */ - , HANDLE_TEC_ENC_FX hTecEnc - ); - -/*bits_alloc.h*/ -Word16 BITS_ALLOC_get_rate_mode( - const Word16 frame_size_index /*i: frame_size_index*/ -); - -void BITS_ALLOC_init_config_acelp( - const Word32 bit_rate, - const Word8 narrowBand, - const Word16 nb_subfr, - ACELP_config *pConfigAcelp /*o: configuration structure of ACELP*/ -); - -Word16 BITS_ALLOC_config_acelp( - const Word16 bits_frame, /*i: remaining bit budget for the frame */ - const Word16 coder_type, /*i: coder type */ - ACELP_config *pConfigAcelp, /*i/o: configuration structure of ACELP*/ - const Word16 narrowband, - const Word16 nb_subfr -); - -void BITS_ALLOC_ACELP_config_rf(const Word16 coder_type, - Word16 *tilt_code, - Word16 *rf_frame_type, - Word16 *rf_target_bits, - Word16 nb_subfr - , Word16 rf_fec_indicator - , Word16 *pitch_buf - ); -void BITS_ALLOC_TCX_config_rf( - Word16 *rf_frame_type, - Word16 *rf_target_bits, - Word16 PLC_Mode, - Word16 coder_type, - Word16 last_core, - Word16 TD_mode -); - -Word16 BITS_ALLOC_adjust_acelp_fixed_cdk( - const Word16 bits_frame, /*i: bit budget */ - Word16 *fixed_cdk_index, /*o: codebook index */ - const Word16 nb_subfr /*i: number of subframes*/ -); - - - -Word16 BITS_ALLOC_adjust_acelp_fixed_16KHZ_cdk( - const Word16 bits_frame, /*i: bit budget */ - Word16 *fixed_cdk_index, /*o: codebook index */ - const Word16 nb_subfr /*i: number of subframes*/ -); - -/*transient_detection.h*/ -/** Init transient detection. - * Fills TransientDetection structure with sensible content. - * @param nFrameLength Frame length. - * @param nTCXDelay Delay for the TCX Long/Short transient detector. - * Don't include the delay of the MDCT overlap. - * @param pTransientDetection Structure to be initialized. It contains all transient detectors to be used. - */ -void InitTransientDetection(Word16 nFrameLength, - Word16 nTCXDelay, - struct TransientDetection * pTransientDetection); - -/** Runs transient detection. - * Runs all transient detectors defined in pTransientDetection - * and calculates mean zero crossing. - * @param input New input samples. - * @param nSamplesAvailable Number of new input samples available. - * @param pTransientDetection Structure that contains transient detectors to be run. - */ -void RunTransientDetection(Word16 const * input, Word16 nSamplesAvailable, struct TransientDetection * pTransientDetection); - - -/** Get the average temporal flatness measure using subblock energies aligned with the TCX. - * @param pTransientDetection Structure that contains transient detectors to be run. - * @param nCurrentSubblocks Number of the subblocks from the current frame to use for the calculation. - A lookeahead can also be use if it exists. - * @param nPrevSubblocks Number of subblocks from the previous frames to use for the calculation. - * @return average temporal flatness measure with exponent AVG_FLAT_E - */ -Word16 GetTCXAvgTemporalFlatnessMeasure(struct TransientDetection const * pTransientDetection, Word16 nCurrentSubblocks, Word16 nPrevSubblocks); - - -/** Get the maximum energy change using subblock energies aligned with the TCX. - * @param pTransientDetection Structure that contains transient detectors to be run. - * @param nCurrentSubblocks Number of the subblocks from the current frame to use for the calculation. - A lookeahead can also be use if it exists. - * @param nPrevSubblocks Number of subblocks from the previous frames to use for the calculation. - * @param maximum energy change with exponent NRG_CHANGE_E - */ -Word16 GetTCXMaxenergyChange(struct TransientDetection const * pTransientDetection, - const Word8 isTCX10, - const Word16 nCurrentSubblocks, const Word16 nPrevSubblocks); - -/** Set TCX window length and overlap configuration - * @param prevEnergyHF previous HF energy. Exponent must be the same as for currEnergyHF. - * @param currEnergyHF current HF energy. Exponent must be the same as for prevEnergyHF. - */ -void SetTCXModeInfo(Encoder_State_fx *st, - struct TransientDetection const * pTransientDetection, - Word16 * tcxModeOverlap); - -/* Tonal Concealment */ - -TONALMDCTCONCEAL_ERROR TonalMDCTConceal_Init( TonalMDCTConcealPtr self, - Word16 nSamples, - Word16 nSamplesCore, - Word16 nScaleFactors, - TCX_config * tcx_cfg - ); - - -/* Must be called only when a good frame is recieved - concealment is inactive */ -TONALMDCTCONCEAL_ERROR TonalMDCTConceal_SaveFreqSignal( TonalMDCTConcealPtr self, - Word32 const *mdctSpectrum, - Word16 const mdctSpectrum_exp, - Word16 nNewSamples, - Word16 nNewSamplesCore, - Word16 const *scaleFactors, - Word16 const *scaleFactors_exp, - Word16 const gain_tcx_exp - ); - -/* The call to TonalMDCTConceal_UpdateState() should be called after TonalMDCTConceal_Apply. */ -TONALMDCTCONCEAL_ERROR TonalMDCTConceal_UpdateState(TonalMDCTConcealPtr self, - Word16 nNewSamples, - Word32 pitchLag, - Word16 badBlock, - Word8 tonalConcealmentActive - ); - -/* The call to TonalMDCTConceal_SaveTimeSignal() should be at the - * place where the TD signal corresponds to the FD signal stored with TonalMDCTConceal_SaveFreqSignal. */ -TONALMDCTCONCEAL_ERROR TonalMDCTConceal_SaveTimeSignal( TonalMDCTConcealPtr self, - Word16 *timeSignal, - Word16 numSamples - ); - -/* Calculates MDST, power spectrum and performs peak detection. - * Uses the TD signal in pastTimeSignal; if pastTimeSignal is NULL, uses the - * TD signal stored using TonalMDCTConceal_SaveTimeSignal. If the - * second last frame was also lost, it is expected that pastTimeSignal - * could hold a signal somewhat different from the one stored in - * TonalMDCTConceal_SaveTimeSignal (e.g. including fade-out).*/ -TONALMDCTCONCEAL_ERROR TonalMDCTConceal_Detect( TonalMDCTConcealPtr const self, /*IN */ - Word32 const pitchLag, /*IN */ - Word16 * const umIndices /*OUT*/ - ); - -/* Conceals the lost frame using the FD signal previously stored using - * TonalMDCTConceal_SaveFreqSignal. Stores the concealed harmonic part of - * the signal in mdctSpectrum, the rest of the spectrum is unchanged. */ -TONALMDCTCONCEAL_ERROR TonalMDCTConceal_Apply( TonalMDCTConcealPtr self, /*IN */ - Word32 * mdctSpectrum, /*OUT*/ - Word16 * mdctSpectrum_exp /*OUT*/ - ); - -/* Conceals the lost frame using the FD signal previously stored using - * TonalMDCTConceal_SaveFreqSignal. Stores the concealed noise part of - * the signal in mdctSpectrum, the rest of the spectrum is unchanged. */ -TONALMDCTCONCEAL_ERROR TonalMDCTConceal_InsertNoise( TonalMDCTConcealPtr self, /*IN */ - Word32* mdctSpectrum, /*OUT*/ - Word16* mdctSpectrum_exp, /*OUT*/ - Word8 tonalConcealmentActive, - Word16* pSeed, /*IN/OUT*/ - Word16 tiltCompFactor, - Word16 crossfadeGain, - Word16 crossOverFreq); - -/* Detect tonal components in the lastMDCTSpectrum, use - * secondLastPowerSpectrum for the precise location of the peaks and - * store them in indexOfTonalPeak. Updates lowerIndex, upperIndex, - * pNumIndexes accordingly. */ -void DetectTonalComponents(Word16 indexOfTonalPeak[], /* OUT */ - Word16 lowerIndex[], /* OUT */ - Word16 upperIndex[], /* OUT */ - Word16 * pNumIndexes, /* OUT */ - Word32 lastPitchLag, Word32 currentPitchLag, /* IN */ - Word16 const lastMDCTSpectrum[], /* IN */ - Word16 lastMDCTSpectrum_exp, /* IN */ - Word16 const scaleFactors[], /* IN */ - Word16 const scaleFactors_exp[], /* IN */ - Word16 const scaleFactors_max_e, /* IN */ - Word32 const secondLastPowerSpectrum[], /* IN */ - Word16 nSamples /* IN */ - ,Word16 nSamplesCore - ,Word16 floorPowerSpectrum /* IN */ - ); - -/* When called, the tonal components are already stored in - * indexOfTonalPeak. Detect tonal components in the lastMDCTSpectrum, - * use secondLastPowerSpectrum for the precise location of the peaks and - * then keep in indexOfTonalPeak only the tonal components that are - * again detected Updates indexOfTonalPeak, lowerIndex, upperIndex, - * phaseDiff, phases, pNumIndexes accordingly. */ -void RefineTonalComponents(Word16 indexOfTonalPeak[], /* OUT */ - Word16 lowerIndex[], /* OUT */ - Word16 upperIndex[], /* OUT */ - Word16 phaseDiff[], /* OUT */ - Word16 phases[], /* OUT */ - Word16 * pNumIndexes, /* OUT */ - Word32 lastPitchLag, /* IN */ - Word32 currentPitchLag, /* IN */ - Word16 const lastMDCTSpectrum[], /* IN */ - Word16 const lastMDCTSpectrum_exp, /* IN */ - Word16 const scaleFactors[], /* IN */ - Word16 const scaleFactors_exp[], /* IN */ - Word16 const scaleFactors_max_e, /* IN */ - Word32 const secondLastPowerSpectrum[], /* IN */ - Word16 nSamples /* IN */ - ,Word16 nSamplesCore - ,Word16 floorPowerSpectrum /* IN */ - ); - -void set_state(Word16 *state, Word16 num, Word16 N); -void concealment_init_x(Word16 N, void *_plcInfo); -void concealment_update_x(Word16 bfi, Word16 curr_mode, Word16 harmonic, Word32 *invkoef, Word16 *invkoef_scale, void *_plcInfo); - -void waveform_adj2_fix( Word16 *overlapbuf, - Word16 *outx_new, - Word16 *data_noise, - Word16 *outx_new_n1, - Word16 *nsapp_gain, - Word16 *nsapp_gain_n, - Word16 *recovery_gain, - Word16 step_concealgain, - Word16 pitch, - Word16 Framesize, - Word16 delay, - Word16 bfi_cnt, - Word16 bfi - ); - -Word16 ffr_getSfWord16(Word16 *vector, /*!< Pointer to input vector */ - Word16 len); /*!< Length of input vector */ - -void concealment_decode_fix(Word16 curr_mode, Word32 *invkoef, Word16 *invkoef_scale,void *_plcInfo); - -void concealment_signal_tuning_fx(Word16 bfi, - Word16 curr_mode, - Word16 *outx_new_fx, - void *_plcInfo, - Word16 nbLostCmpt, - Word16 pre_bfi, - Word16 *OverlapBuf_fx, - Word16 past_core_mode, - Word16 *outdata2_fx, - Decoder_State_fx *st); - -Word16 Spl_GetScalingSquare_x(Word16 *in_vector, Word16 in_vector_length, Word16 times); -Word32 Spl_Energy_x(Word16* vector, Word16 vector_length, Word16* scale_factor); -void Log10OfEnergy_x(Word16 *s, Word32 *enerlogval, Word16 len); -void concealment_update2_x(Word16 *outx_new, void *_plcInfo, Word16 FrameSize); -Word16 Sqrt_x_fast(Word32 value); - -Word32 dot_w32_accuracy_x(Word16 *s1, Word16 *s2, Word16 nbits, Word16 N); - -Word16 int_div_s_x(Word16 a, Word16 b); - -Word16 GetW32Norm_x(Word32 *s, Word16 N); - -Word16 harmo_x(Word32 *X, Word16 Framesize, Word16 pitch); - - -void LpFilter2_x(Word16 *x, Word16 *y, Word16 N); - -void sig_tilt_x(Word16 *s, Word16 FrameSize, Word32 *enr1, Word32 *enr2) ; - -void get_maxConv_and_pitch_x(Word16 *s_LP, Word16 s, Word16 e, Word16 N, - Word32 *maxConv, Word16 *maxConv_bits, Word16 *pitch); - -Word16 get_voicing_x(Word16 *s_LP, Word16 pitch, Word32 covMax,Word16 maxConv_bits, Word16 Framesize); - -void pitch_modify_x(Word16 *s_LP, Word16 *voicing, Word16 *pitch, Word16 FrameSize); - -Word16 Is_Periodic_x(Word32 *mdct_data, Word16 cov_max, Word16 zp, Word32 ener, - Word32 ener_mean, Word16 pitch, Word16 Framesize); - -Word16 get_conv_relation_x(Word16 *s_LP, Word16 shift, Word16 N); - - - -/* 14Q1*1.28 */ -#define LSF_GAP_VAL(x) (Word16)((x)*2.0f*1.28f) - -/*longarith.h*/ - -/** - * \brief inplace long shift right: a[] = a[] >> bits - * Logical shift right of UWord32 vector a[] by 'bits' positions. - */ - -void longshr (UWord32 a[], Word16 bits, Word16 len); - - -/*qlpc_avq.h*/ -void lsf_weight_2st(const Word16 *lsfq, /* input: quantized lsf coefficients (3Q12) */ - Word16 *w, /* output: weighting function (0Q15) */ - const Word16 mode /* input: operational mode */ - ); - - - -void qlpc_avq( - const Word16 *lsf, /* (i) Input LSF vectors */ - const Word16 *lsfmid, /* (i) Input LSF vectors */ - Word16 *lsf_q, /* (o) Quantized LFS vectors */ - Word16 *lsfmid_q, /* (o) Quantized LFS vectors */ - Word16 *index, /* (o) Quantization indices */ - Word16 *nb_indices, /* (o) Number of quantization indices */ - Word16 *nbbits, /* (o) Number of quantization bits */ - const Word16 core, /* (i) TCX10 or TCX20 */ - Word32 sr_core -); - -Word16 encode_lpc_avq( Encoder_State_fx *st, Word16 numlpc, Word16 *param_lpc, Word16 mode ); - -Word16 dlpc_avq( - Word16 *index, /* (i) Quantization indices */ - Word16 *LSF_Q, /* (o) Quantized LSF vectors */ - Word16 numlpc, /* (i) Number of sets of lpc */ - Word32 sr_core -); - -Word16 decode_lpc_avq( Decoder_State_fx *st, Word16 numlpc, Word16 *param_lpc ); - -Word16 vlpc_1st_cod(const Word16 *lsf, /* input: vector to quantize */ - Word16 *lsfq /* i/o: i:prediction o:quantized lsf */ - ,Word16 *wout /* o: lsf weights */ - ,Word16 rf_mode - ); - -Word16 vlpc_2st_cod( /* output: number of allocated bits */ - const Word16 *lsf, /* input: normalized vector to quantize (3Q12) */ - Word16 *lsfq, /* i/o: i:1st stage o:1st+2nd stage (3Q12) */ - Word16 *indx, /* output: index[] (4 bits per words) */ - Word16 mode, /* input: 0=abs, >0=rel */ - Word32 sr_core -); - -void vlpc_2st_dec( - Word16 *lsfq, /* i/o: i:1st stage o:1st+2nd stage */ - Word16 *indx, /* input: index[] (4 bits per words) */ - Word16 mode, /* input: 0=abs, >0=rel */ - Word32 sr_core); - -void open_decoder_LPD( - Decoder_State_fx *st, - Word32 bitrate, - Word16 bandwidth -); - - -void update_decoder_LPD_cng( - Decoder_State_fx *st, - Word16 coder_type, - Word16 *timeDomainBuffer, - Word16 *A, - Word16 *bpf_noise_buf -); - -void reconfig_decoder_LPD( Decoder_State_fx *st, Word16 bits_frame, Word16 bandwidth_mode, Word32 bitrate, Word16 L_frame_old); - -void mode_switch_decoder_LPD( Decoder_State_fx *st, Word16 bandwidth_in, Word32 bitrate, Word16 frame_size_index - ); - -void decoder_LPD( - Word16 signal_out[], /* output: signal with LPD delay (7 subfrs) */ - Word16 signal_outFB[], - Word16 *total_nbbits, /* i/o: number of bits / decoded bits */ - Decoder_State_fx *st , /* i/o: decoder memory state pointer */ - Word16 *bpf_noise_buf, - Word16 bfi, - Word16 *bitsRead, - Word16 *coder_type, - Word16 param[], - Word16 *pitch_buf, - Word16 *voice_factors, - Word16 *ptr_bwe_exc -); - -Word16 dec_acelp_tcx_frame( - Decoder_State_fx *st, - Word16 *coder_type, - Word16 *concealWholeFrame, - Word16 *pcmBuf, - Word16 * bpf_noise_buf, - Word16 * pcmbufFB, - Word32 bwe_exc_extended[], - Word16 *voice_factors, - Word16 pitch_buf[] -); - - -Word16 tcxGetNoiseFillingTilt(Word16 A[], - Word16 lpcorder, - Word16 L_frame, - Word16 mode, - Word16 *noiseTiltFactor - ); - - -void tcxFormantEnhancement( - Word16 xn_buf[], - Word16 gainlpc[], Word16 gainlpc_e[], - Word32 spectrum[], Word16 *spectrum_e, - Word16 L_frame - ,Word16 L_frameTCX -); - - -void tcxInvertWindowGrouping(TCX_config *tcx_cfg, - Word32 xn_buf[], - Word32 spectrum[], - Word16 L_frame, - Word8 fUseTns, - Word16 last_core, - Word16 index, - Word16 frame_cnt, - Word16 bfi); - -/*lerp.h*/ - -void lerp(Word16 *f, Word16 *f_out, Word16 bufferNewSize, Word16 bufferOldSize); - -void attenuateNbSpectrum(Word16 L_frame, Word32 *spectrum); - -Word8 getTcxonly(const Word32 bitrate); -Word8 getCtxHm(const Word32 bitrate, const Word16 rf_flag); -Word8 getResq(const Word32 bitrate); - -Word8 getTnsAllowed(const Word32 bitrate - ,const Word16 igf - ); - -Word8 getRestrictedMode(const Word32 bitrate, const Word16 Opt_AMR_WB); - -Word16 sr2fscale(const Word32 sr); - -Word32 getCoreSamplerateMode2(const Word32 bitrate, const Word16 bandwidth, const Word16 rf_flag); -Word16 getTcxBandwidth(const Word16 bandwidth); - -Word8 getIgfPresent( - const Word32 bitrate, - const Word16 bandwidth - , const Word16 rf_mode -); - -Word8 getCnaPresent( - const Word32 bitrate, - const Word16 bandwidth -); - -Word8 getTcxLtp( - const Word32 sr_core -); - -Word16 initPitchLagParameters( - const Word32 sr_core, - Word16 *pit_min, - Word16 *pit_fr1, - Word16 *pit_fr1b, - Word16 *pit_fr2, - Word16 *pit_max -); - -Word16 getNumTcxCodedLines(const Word16 bwidth); - -Word16 getTcxLpcShapedAri( - const Word32 total_brate, - const Word16 bwidth - ,const Word16 rf_mode -); - - -Word16 vad_init(T_CldfbVadState *vad_state); - -void subband_FFT( - Word32 ** Sr, /*(i) real part of the CLDFB*/ - Word32 ** Si, /*(i) imag part of the CLDFB*/ - Word32 *spec_amp, /*(o) spectral amplitude*/ - Word32 Offset, /*(i) offset of the CLDFB*/ - Word16 *fftoQ /*(o) the Scaling */ -); - -void UpdateState( T_CldfbVadState *vad_state, - Word16 vad_flag, - Word32 frame_energy, /*(i) current frame energy*/ - Word16 sacle_sbpower, /*(i) the Scaling of current frame energy*/ - Word32 update_flag, /*(i) current frame update flag*/ - Word16 music_backgound_f, /*(i) backgound music flag*/ - Word32 HB_Power, /*(i) current frame high frequency energy*/ - Word16 HB_Power_Q /*(i) the Scaling of current frame high frequency energy*/ - ,Word32 snr - ); - -void calc_snr_flux( Word32 tsnr_fix, /*(i) time-domain SNR*/ - Word32 *pre_snr, /*(io)time-domain SNR storage*/ - Word32 *snr_flux /*(o) average tsnr*/ - ); - -Word16 update_decision( - T_CldfbVadState *st, - Word32 frame_energy, /*(i) current frame energy*/ - Word32 HB_Power, /*(i) current frame high frequency energy*/ - Word16 frameloop, /*(i) amount of frames*/ - Word16 bw, /*(i) band width index*/ - Word16 frame_energy_Q, /*(i) the Scaling of current frame energy*/ - Word16 HB_Power_Q, /*(i) the Scaling of current frame high frequency energy*/ - Word32 snr, /*(i) frequency domain SNR */ - Word32 tsnr, /*(i) time domain SNR */ - Word16 vad_flag, - Word16 music_backgound_f /*(i) background music flag*/ -); - -void frame_spec_dif_cor_rate( T_CldfbVadState *st, /*(io) vad state*/ - Word32 *spec_amp, /*(i) spectral amplitude*/ - Word16 sacle, /*(i) the scaling of spec_amp*/ - Word16 f_tonality_rate[3] /*(o) tonality rate*/ - ); - -void ltd_stable( T_CldfbVadState *st, /*(io) vad state*/ - Word16 *ltd_stable_rate, /*(o) time-domain stable rate*/ - Word32 frame_energy, /*(i) current frame energy*/ - Word16 frameloop, /*(i) amount of frames*/ - Word16 Q_frames_power /*(i) the Scaling of frames_power*/ - ); - -void snr_calc( T_CldfbVadState *st, /*(io) vad state*/ - Word16 sacle_sbpower, /*(i) the Scaling of sbpower*/ - Word32 *snr, /*(o) frequency domain SNR */ - Word32 *tsnr, /*(o) time domain SNR */ - Word32 frame_energy, /*(i) current frame energy */ - Word32 bandwith /*(i) band width*/ - ); - -void bg_music_decision( T_CldfbVadState *st, - Word16 *music_backgound_f, /*(i) background music flag*/ - Word32 frame_energy, /*(i) current frame energy 1*/ - Word16 frame_energy_Q /*(i) the Scaling of current frame energy*/ - ); - -void background_update( T_CldfbVadState *st, - Word16 scale, /*(i) the Scaling of frame energy*/ - Word32 frame_energy, /*(i) current frame energy*/ - Word32 update_flag, /*(i) update flag*/ - Word16 music_backgound_f /*(i) background music flag*/ - ,Word32 snr - ); - -void spec_center( Word32* sb_power, /*(i) energy of sub-band divided uniformly*/ - Word16* sp_center, /*(o) spectral center*/ - Word32 bandwith, /*(i) band width*/ - Word16 Q_sb_p /*(i) the Scaling of sb_power*/ - ); - -void spec_flatness( Word32 *spec_amp, /*(i) spectral amplitude*/ - Word32 smooth_spec_amp[], /*(i) smoothed spectral amplitude*/ - Word16 sSFM[5] /*(o) spectral flatness rate*/ - ); - -void calc_lt_snr( T_CldfbVadState *st, /*(io) vad state*/ - Word32 *lt_snr_org, /*(o) original long time SNR*/ - Word32 *lt_snr, /*(o) long time SNR calculated by fg_energy and bg_energy*/ - Word32 fg_energy, /*(i) foreground energy sum */ - Word16 fg_energy_count, /*(i) amount of the foreground energy frame */ - Word32 bg_energy, /*(i) background energy sum */ - Word16 bg_energy_count, /*(i) amount of the background energy frame */ - Word16 bw_index, /*(i) band width index*/ - Word16 lt_noise_sp_center0 /*(i) long time noise spectral center by 0*/ - ); - -Word16 vad_decision( T_CldfbVadState *st, - Word32 l_snr, /*(i) long time frequency domain*/ - Word32 lt_snr_org, /*(i) original long time SNR*/ - Word32 lt_snr, /*(i) long time SNR calculated by fg_energy and bg_energy*/ - Word32 snr_flux, /*(i) average tsnr of several frames*/ - Word32 snr, /*(i) frequency domain SNR */ - Word32 tsnr, /*(i) time domain SNR */ - Word32 frame_energy, /*(i) current frame energy */ - Word16 music_backgound_f, /*(i) background music flag*/ - Word16 frame_energy_Q /*(i) the scaling of current frame energy*/ - ); - -Word16 comvad_decision( T_CldfbVadState *st, - Word32 l_snr, /*(i) long time frequency domain*/ - Word32 lt_snr_org, /*(i) original long time SNR*/ - Word32 lt_snr, /*(i) long time SNR calculated by fg_energy and bg_energy*/ - Word32 snr_flux, /*(i) average tsnr of several frames*/ - Word32 snr, /*(i) frequency domain SNR */ - Word32 tsnr, /*(i) time domain SNR */ - Word32 frame_energy, /*(i) current frame energy */ - Word16 music_backgound_f, /*(i) background music flag*/ - Word16 frame_energy_Q, /*(i) the Scaling of current frame energy*/ - Word16 *cldfb_addition, /*(o) adjust the harmonized hangover */ - Word16 vada_flag - ); - -void calc_lf_snr( - Word32 *lf_snr_smooth, /*(o) smoothed lf_snr*/ - Word32 *lf_snr, /*(o) long time frequency domain SNR calculated by l_speech_snr and l_silence_snr*/ - Word32 l_speech_snr, /*(i) sum of active frames snr */ - Word32 l_speech_snr_count, /*(i) amount of the active frame */ - Word32 l_silence_snr, /*(i) sum of the nonactive frames snr*/ - Word32 l_silence_snr_count, /*(i) amount of the nonactive frame */ - Word16 fg_energy_count, /*(i) amount of the foreground energy frame */ - Word16 bg_energy_count, /*(i) amount of the background energy frame */ - Word16 bw_index /*(i) band width index*/ -); - -Word32 construct_snr_thresh( Word16 sp_center[], /*(i) spectral center*/ - Word32 snr_flux, /*(i) snr flux*/ - Word32 lt_snr, /*(i) long time time domain snr*/ - Word32 l_snr, /*(i) long time frequency domain snr*/ - Word32 continuous_speech_num, /*(i) amount of continuous speech frames*/ - Word16 continuous_noise_num, /*(i) amount of continuous noise frames*/ - Word32 fg_energy_est_start, /*(i) whether if estimated energy*/ - Word16 bw_index /*(i) band width index*/ - ); - -Word16 vad_proc(T_CldfbVadState *vad_st, - Word32 realBuffer[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX], /* i: real values */ - Word32 imagBuffer[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX], /* i: imag values */ - Word16 riBuffer_exp, /* i: exponent of real & imag Buffer */ - - Word16 *cldfb_addition, /*o: adjust the harmonized hangover */ - Word32 enerBuffer[CLDFB_NO_CHANNELS_MAX], /* i: energy vector per band */ - Word16 enerBuffer_exp, /* i: exponent of energy vector */ - Word16 bandwidth, /* 1: NB; 2:WB;3:SWB;4:FB*/ - Word16 vada_flag - ); - -void est_energy(Word32 enerBuffer[CLDFB_NO_CHANNELS_MAX], /* i: energy vector per band */ - Word16 enerBuffer_exp, /* i: exponent of energy vector */ - Word32 *frame_sb_energy, /*(o) energy of sub-band divided non-uniformly*/ - Word32 *frame_energy2_p, /*(o) frame energy 2*/ - Word32 *HB_Power_p, /*(o) high frequency energy*/ - Word32 *frame_energy_p, /*(o) frame energy 1*/ - Word16 *sb_power_Q, /*(o) the scaling of sb_power*/ - Word16 *frame_energy2_Q, /*(o) the scaling of frame_energy*/ - Word16 *HB_Power_Q, /*(o) the scaling of HB_Power*/ - Word16 *frame_energy_Q, /*(o) the Scaling of frame_energy*/ - Word16 *frame_sb_energy_scale, /*(o) the Scaling of frame_sb_energy[]*/ - Word32 bandwidth /*(i) band width*/ - ); - -/** - * \brief Function performs a complex 16-point FFT - * The FFT is performed inplace. The result of the FFT - * is scaled by SCALEFACTOR16 bits. - * - * WOPS FLC version: 196 cycles - * WOPS with 32x16 bit multiplications (scale on ): 288 cycles - * WOPS with 32x16 bit multiplications (scale off): 256 cycles - * - * \param [i/o] re real input / output - * \param [i/o] im imag input / output - * \param [i ] s stride real and imag input / output - * - * \return void - */ -void fft16(Word32 *re, Word32 *im, Word16 s, Word16 bScale); - - - -void dlpc_bfi( - const Word16 L_frame, - Word16 *lsf_q, /* o : quantized LSFs */ - const Word16 *lsfold, /* i : past quantized LSF */ - const Word16 last_good, /* i : last good received frame */ - const Word16 nbLostCmpt, /* i : counter of consecutive bad frames */ - Word16 mem_MA[], /* i/o: quantizer memory for MA model */ - Word16 mem_AR[], /* i/o: quantizer memory for AR model */ - Word16 *stab_fac, /* i : LSF stability factor */ - Word16 *lsf_adaptive_mean,/* i : LSF adaptive mean, updated when BFI==0 */ - Word16 numlpc, /* i : Number of division per superframe */ - Word16 lsf_cng[], - Word8 plcBackgroundNoiseUpdated, - Word16 *lsf_q_cng, /* o : quantized LSFs */ - Word16 *old_lsf_q_cng, /* o : old quantized LSFs for background noise */ - const Word16* lsfBase, /* i : base for differential LSF coding */ - Word8 tcxonly -); - -void isf_dec_bfi( - const Word16 last_type, /*!< i : coding type in last good received fr. */ - Word16*isf_q, /*!< o : 14Q1*1.28 quantized ISFs */ - const Word16*isfold, /*!< i : 14Q1*1.28 past quantized ISF */ - const Word16 last_good, /*!< i : last good received frame */ - const Word16 bfi_cnt, /*!< i : counter of consecutive bad frames */ - Word16*mem_MA, /*!< i/o: 14Q1*1.28 quantizer memory for MA model */ - Word16 stab_fac, /*!< i : ISF stability factor (shifted right by 1) */ - Word16*isf_adaptive_mean, /*!< i : 14Q1*1.28 ISF adaptive mean, updated when BFI==0 */ - const Word16 coder_type, /*!< i : Coders frame type */ - Word16 lpcorder, /*!< i: : lpc order */ - Word16 *isf_cng, - Word8 plcBackgroundNoiseUpdated, - Word16 *isf_q_cng, /* o : quantized ISFs for background noise */ - Word16 *old_isf_q_cng, /* o : old quantized ISFs for background noise */ - const Word16 xsfBase[] /* i : base for differential XSF coding */ -); - -void tfaCalcEnv_fx(const Word16* shb_speech, Word32* enr); -Word16 tfaEnc_TBE_fx(Word32* enr, - Word16 last_core, - Word16* voicing, /* Q15 */ - Word16* pitch_buf, /* Q6 */ - Word16 Q_enr - ); - -void tecEnc_TBE_fx(Word16* corrFlag, const Word16* voicing, Word16 coder_type); - -void set_TEC_TFA_code_fx(const Word16 corrFlag, Word16* tec_flag, Word16* tfa_flag); - -Word16 procTecTfa_TBE_Fx(Word16 *hb_synth_Fx, - Word16 hb_synth_fx_exp, - Word16 *gain_m, - Word16 *gain_e, - Word16 flat_flag, - Word16 last_core - , Word16 l_subfr - , Word16 code - ); - - -void -calcGainTemp_TBE_Fx( - Word32** pCldfbRealSrc_Fx, - Word32** pCldfbImagSrc_Fx, - Word16 cldfb_exp, - Word16* loBuffer_Fx, - Word16 startPos, /*!< Start position of the current envelope. */ - Word16 stopPos, /*!< Stop position of the current envelope. */ - Word16 lowSubband, /* lowSubband */ - Word16* pGainTemp_m, - Word16* pGainTemp_e - , Word16 code -); - -void resetTecEnc_Fx( - HANDLE_TEC_ENC_FX hTecEnc, - Word16 flag - -); - -void -resetTecDec_Fx( - HANDLE_TEC_DEC_FX hTecDec -); - -void calcHiEnvLoBuff_Fix( - Word16 noCols, - Word16* pFreqBandTable, /*!< freqbandTable. */ - Word16 nSfb, /*!< Number of scalefactors. */ - Word32** pCldfbPow_Fix /*float** pCldfbPow*/, - Word16* loBuffer_Fix /*float* loBuffer Q8*/, - Word16* hiTempEnvOrig_Fix /*float* hiTempEnvOrig*/, - Word16 pCldfbPow_FixScale -); - -void calcLoEnvCheckCorrHiLo_Fix( - Word16 noCols, - Word16* pFreqBandTable, /*!< freqbandTable. */ - Word16* loBuffer_Fix /*float* loBuffer*/, - Word16* loTempEnv_Fix /*float* loTempEnv*/, - Word16* loTempEnv_ns_Fix /* float* loTempEnv_ns*/, - Word16* hiTempEnvOrig_Fix /*float* hiTempEnvOrig*/, - Word16* corrFlag /*int* corrFlag*/ -); - - - -/**************************** Moved from er_util.h: ********************************/ - -/*----------------------------------------------------------------------* - * PLC: [ACELP: Fade-out] - * PLC: getLevelSynDeemph: derive on subframe basis the level of LPC - * synthesis and deeemphasis based on the given input - *----------------------------------------------------------------------*/ - -Word16 getLevelSynDeemph( /*10Q5*/ - Word16 h1Init[], /* i: input value or vector to be processed */ /* Q15 */ - Word16 const A[], /* i: LPC coefficients */ /* Qx */ - Word16 const lpcorder, /* i: LPC order */ /* Q0 */ - Word16 const lenLpcExc, /* i: length of the LPC excitation buffer */ /* Q0 */ - Word16 const preemph_fac, /* i: preemphasis factor */ /* Q15 */ - Word16 const numLoops, /* i: number of loops */ /* Q0 */ - Word16 *Exp /* o: exponent of return value Q15 */ -); - - -/*-----------------------------------------------------------------* - * PLC: [ACELP: general] - * PLC: high pass filtering - *-----------------------------------------------------------------*/ -void highPassFiltering( - const Word16 last_good, /* i: short last classification type */ - const Word16 L_buffer, /* i: int buffer length */ - Word16 exc2[], /* i/o: Qx unvoiced excitation before the high pass filtering */ - const Word16 hp_filt[], /* i: Q15 high pass filter coefficients */ - const Word16 l_fir_fer); /* i: high pass filter length */ - - -/*----------------------------------------------------------------------------------* - * PLC: [Common: mode decision] - * PLC: Decide which Concealment to use. Update pitch lags if needed - *----------------------------------------------------------------------------------*/ -Word16 GetPLCModeDecision( Decoder_State_fx *st - ); - -/* PLC: [Common: Fade-out] - * PLC: and for PLC fade out */ - -void minimumStatistics(Word16* noiseLevelMemory, /* Q15, internal state */ - Word16* noiseLevelIndex, /* Q0, internal state */ - Word16* currLevelIndex, /* Q0, internal state (circular buffer) */ - Word16* noiseEstimate, /* Q15, previous estimate of background noise */ - Word16* lastFrameLevel, /* Q15, level of the last frame */ - Word16 currentFrameLevel, /* Q15, level of the current frame */ - Word16* noiseLevelMemory_e, /* scaling factor for noiseLevelMemory */ - Word16 const noiseEstimate_e, /* exponent of noiseEstimate */ - Word16* new_noiseEstimate_e, /* new exponent of noise Estimate*/ - Word16* const lastFrameLevel_e, /* exponent of lastFrameLevel */ - Word16 currentFrameLevel_e); /* exponent of currentFrameLevel */ - -/*-----------------------------------------------------------------------------------* - * PLC: [ACELP: innovative codebook] - * PLC: genPlcFiltBWAdapt : deriuve filter coefficients for filtering - the first pitch cycle, bitrate dependent - *-----------------------------------------------------------------------------------*/ - -void genPlcFiltBWAdap( - Word32 const sr_core, /*Qold) */ - Word16 *old_exc, /* i: input excitation in Q(st->Qold) */ - Word16 L_frame /* i: input frame length */ -); - -void encoderSideLossSimulation( - Encoder_State_fx *st, - HANDLE_PLC_ENC_EVS hPlc_Ext, - Word16 *isf_q, /* Q1*1.28 */ - Word16 stab_fac, /* Q15 */ - Word8 calcOnlyISF, - const Word16 L_frame -); - -void enc_prm_side_Info( HANDLE_PLC_ENC_EVS hPlc_Ext, Encoder_State_fx *st ); - -void GplcTcxEncSetup(Encoder_State_fx *st, - HANDLE_PLC_ENC_EVS hPlc_Ext, - Word16 Q_new); -Word16 encSideSpecPowDiffuseDetector( - Word16 *isf_ref, - Word16 *isf_con, - Word32 sr_core, - Word16 *prev_isf4_mean, - Word8 sw - , Word16 coder_type -); - -void updateSpecPowDiffuseIdx( Encoder_State_fx *st); - -void blend_subfr2( - Word16 *sigIn1, /* i : input signal for fade-out */ - Word16 *sigIn2, /* i : input signal for fade-in */ - Word16 *sigOut /* o : output signal */ -); - - -void BASOP_cfft(Word32 *re, Word32 *im, Word16 sizeOfFft, Word16 s, Word16 *scale, Word32 workBuffer[2*BASOP_CFFT_MAX_LENGTH]); -void BASOP_cfft16(Word16 *re, Word16 *im, Word16 sizeOfFft, Word16 s, Word16 *scale); -void BASOP_rfft(Word32 *x, Word16 sizeOfFft, Word16 *scale, Word16 isign); -void BASOP_rfft16(Word16 *x, Word16 sizeOfFft, Word16 *scale, Word16 isign); - -void open_PLC_ENC_EVS( - HANDLE_PLC_ENC_EVS hPlcExt, - Word32 sampleRate -); - -void gPLC_encInfo ( - HANDLE_PLC_ENC_EVS self, - Word32 modeBitrate, - Word16 modeBandwidth, - Word16 old_clas, - Word16 acelp_ext_mode -); - -void v_sort(Word16 *r, const Word16 lo, const Word16 up); - -void coder_acelp_rf( - ACELP_config *acelp_cfg_rf, /*input/output: configuration of the ACELP coding*/ - const Word16 coder_type, /* input: coding type */ - const Word16 A[], /* input: coefficients 4xAz[M+1] */ - const Word16 Aq[], /* input: coefficients 4xAz_q[M+1] */ - Word16 speech[], /* input: speech[-M..lg] */ - const Word16 voicing[], /* input: open-loop LTP gain */ - const Word16 T_op[], /* input: open-loop LTP lag */ - Word16 stab_fac, - Encoder_State_fx *st, - Word16 target_bits, /* i/o : coder memory state */ - const Word16 rf_frame_type, /* i : rf_frame_type */ - Word16 *exc_rf, /* i/o: pointer to RF excitation */ - Word16 *syn_rf, /* i/o: pointer to RF synthesis */ - Word16 Q_new, - Word16 shift -); - - -#endif /*PROT_COM_FX_H */ diff --git a/src/libs/libevs/lib_com/pvq_com.cpp b/src/libs/libevs/lib_com/pvq_com.cpp new file mode 100644 index 00000000..b4cb9621 --- /dev/null +++ b/src/libs/libevs/lib_com/pvq_com.cpp @@ -0,0 +1,888 @@ + +/*==================================================================================== + EVS Codec 3GPP TS26.443 Nov 13, 2018. Version 12.11.0 / 13.7.0 / 14.3.0 / 15.1.0 + ====================================================================================*/ + +#include +#include "options.h" +#include "cnst.h" +#include "rom_com.h" +#include "prot.h" +#include "stl.h" + +/*-------------------------------------------------------------------* + * Local definitions + *-------------------------------------------------------------------*/ + + +typedef unsigned long long ui64_t; + + +short shrtCDivSignedApprox( + const short num, + const short den +) +{ + Word16 pool_part; + pool_part = extract_h( L_mult( negate(abs_s(num)), lim_neg_inv_tbl_fx[den] )); + /* neg_in always, positive out always, so that positive truncation(rounding) towards zero is used */ + if ( num < 0 ) + { + pool_part = negate(pool_part); /* make negative, one op */ + } + return pool_part; +} + +int intLimCDivPos( int NUM, + short DEN + ) +{ + int result; + + result = (int )(((ui64_t) (NUM << 1)* intLimCDivInvDQ31[DEN]) >> 32) ; + + return result; +} + +int intLimCDivSigned( int NUM, + short DEN + ) +{ + int result; + int tmp_num; + tmp_num = max(NUM,-NUM); + /* result = (int)sign(NUM)*intLimCDivPos(tmp_num, DEN); */ + result = (int)sign(NUM)*(int)(((ui64_t) (tmp_num << 1)* intLimCDivInvDQ31[DEN]) >> 32) ; + return result; +} + + + + +static void nearProjQ15( + short x, + short *result +) +{ + int NearProjC[4] = {0x00003a77, (int)0xffff9c52, 0x00000d57, 0x00007e5f}; + int P12, P3; + + P12 = ((int)x * NearProjC[0] >> 16) + NearProjC[1]; + P3 = ((int)x * P12 >> 14) + NearProjC[2]; + *result =(short) (((int)x * P3 >> 15) + NearProjC[3]); + + return; +} + + +void obtainEnergyQuantizerDensity( + short L_in, + short R_in, + short *Density +) +{ + int Rnrg; + short den; + int L, R; + L=L_in; + R=R_in; + den = (2*L -1) ; + if( den<=67) + { + Rnrg = (int)(((ui64_t) (R << 1)* intLimCDivInvDQ31[den]) >> 32) ; + } + else + { + Rnrg = (R / den); + } + Rnrg += 28; + + if ((R - 96 < 56) && (R - 96 < Rnrg)) + { + Rnrg = R - 96; + } + else if (56 < Rnrg) + { + Rnrg = 56; + } + + Rnrg = max(0, Rnrg); /* _f table set to 1 for low Rnrg */ + *Density = (short)obtainEnergyQuantizerDensity_f[Rnrg]; + return ; +} + + +void dsDirac2Dirac( + short dsDiracIndex, + short *diracs +) +{ + short dsHighIndex; + dsHighIndex = dsDiracIndex - DS_INDEX_LINEAR_END - 1; + *diracs = dsDiracIndex; + if (dsDiracIndex > DS_INDEX_LINEAR_END) + { + *diracs = dsHighDiracsTab[dsHighIndex]; + } + return ; +} + + +void dsDiracPerQuanta(short td, + short t_quanta, + short dsm, + const unsigned char* const *frQuanta, + short *DsIdx + ) +{ + const unsigned char *sv; + short nsv; + short t_quanta_o; + short dsIndex; + short i; + + sv = frQuanta[td]; + nsv = sv[0]; + + t_quanta_o = t_quanta - QUANTAQ3OFFSET; + if ( t_quanta_o >= sv[nsv] ) + { + *DsIdx = nsv; + return; + } + if ( t_quanta_o <= sv[1] ) + { + *DsIdx = 1; + return ; + } + dsIndex = 1 << frQuanta[0][td]; + ; + if (t_quanta_o > sv[nsv >> 1]) + { + dsIndex = nsv - dsIndex; /*single op*/ + } + for( i = frQuanta[0][td]-1; i >= 0; i--) + { + /* + tmp_diff = (t_quanta_o > sv[dsIndex] ); + dsIndex += ((tmp_diff<<1) - 1) << i; */ /* clang warns for (neg)< sv[dsIndex]); + dsIndex -= (dsIndex > 1); + + if (dsm == CONS) + { + *DsIdx = dsIndex; + return ; + } + *DsIdx = dsIndex + ((sv[dsIndex + 1] + sv[dsIndex]) < (t_quanta_o << 1)) ; + return; +} + +void QuantaPerDsDirac( + short td, + short dsDiracIndex, + const unsigned char* const* dimFrQuanta, + short *Quanta +) +{ + if ( !dsDiracIndex ) + { + *Quanta = 0; + return; + } + *Quanta = ((short) dimFrQuanta[td][dsDiracIndex]) + QUANTAQ3OFFSET ; + return ; +} + + + +void conservativeL1Norm( + short L, + short Qvec, + short Fcons, + short Qavail, + short Qreserv, + short Dspec, + short *Dvec, /*o*/ + short *Qspare, /*o*/ + short *Qreservplus, /*o*/ + short *Dspecplus /*o*/ +) +{ + short Minit, Mprime; + short Qtestminus; + const unsigned char *frQuantaL; + + frQuantaL = hBitsN[L]; + + *Qreservplus = Qreserv + Qvec - QUANTAQ3OFFSET; + + dsDiracPerQuanta(L, Qvec, Fcons, hBitsN, &Minit); + Mprime = Minit; + do + { + Qtestminus = frQuantaL[Mprime]; + *Qspare = Qavail - Qtestminus; + Mprime = Mprime - 1; + } + while ( Mprime >= 0 && *Qspare < QUANTAQ3OFFSET); + + if (Mprime < 0) + { + *Qspare = Qavail + QUANTAQ3OFFSET; + } + + dsDirac2Dirac(Mprime + 1,Dvec); + + *Dspecplus = Dspec + *Dvec; + + *Qreservplus -= frQuantaL[Minit]; + + *Qspare -= QUANTAQ3OFFSET; + + return; +} + + + + +void bandBitsAdjustment( + short Brc, + unsigned int INTrc, + short Bavail, + short Nbands, + short D, + short L, + short Bband, + short Breserv, + short *Bband_adj, /* o */ + short *Brem, /* o */ + short *Breservplus /* o */ +) +{ + int Btemp; + short Bff ; + short Dtmp, tmp_short1 ,tmp_short2; + + rangeCoderFinalizationFBits(Brc, INTrc,&Bff); + + if (D < Nbands) + { + Dtmp = min(D, 3); /* avoid branch cost */ + Btemp = intLimCDivSigned( Breserv-Bff, Dtmp); + + *Breservplus = Bband + Breserv; + } + else + { + Btemp = 0; + *Breservplus = Bband + Bff; + } + + *Bband_adj = Bband; + tmp_short1 = L * 80; + if ( tmp_short1 < Bband ) + { + *Bband_adj = tmp_short1; + } + + tmp_short1 = Bavail - Bff; + tmp_short2 = *Bband_adj + Btemp ; + + *Bband_adj = tmp_short2; + if ( tmp_short1 < tmp_short2 ) + { + *Bband_adj = tmp_short1 ; + } + if (*Bband_adj < 0) + { + *Bband_adj = 0; + } + *Brem = Bavail - Bff; +} + + + +/*-------------------------------------------------------------------* + * local_norm_s() + * + * + *-------------------------------------------------------------------*/ +static +short local_norm_s ( /* o : n shifts needed to normalize */ + short short_var /* i : signed 16 bit variable */ +) +{ + short short_res; + + if (short_var == -1 ) + { + return (16-1); + } + else + { + if (short_var == 0) + { + return 0; + } + + else + { + if (short_var < 0) + { + short_var = ~short_var; + } + + for (short_res = 0; short_var < 0x4000; short_res++) + { + short_var <<= 1; + } + } + } + + return (short_res); +} + + + + +static short Ratio_base2Q11( /* o : , Q11 */ + short opp, /* i : Q15 */ + short near /* i : Q15 */ +) +{ + Word16 mc, nc, ms, ns, d, z; + Word16 result; + Word32 acc; + + ns = local_norm_s(opp ); /* exponent*/ + nc = local_norm_s(near ); /* exponent */ + + ms = opp << ns; /* mantissa */ + mc = near<< nc; /* mantissa */ + + acc = L_mac(538500224L, mc, -2776); /* a0*mc + a1, acc(Q27), a0(Q11), a1(Q27)*/ + z = mac_r(acc, ms, -2776); /* z in Q11, a0 in Q11 */ + d = sub(ms, mc); /* d in Q15 */ + z = mult_r(z, d); /* z in Q11 */ + + result = add(z, shl(sub(nc, ns), 11)); + return result; +} + +void Ratio_rQ3( + short opp, + short near, + short *result +) +{ + short tmp = 128; + tmp += Ratio_base2Q11(opp, near); + *result = (tmp >> 8); + return ; +} + + + + + +void densityAngle2RmsProjDec( + short D, /* i: density */ + short indexphi, /* i: decoded index from AR dec */ + + short *oppQ15, /* o: */ + short *nearQ15, /* o: */ + short *oppRatioQ3 /* o: */ +) +{ + short phiQ14q; + int L_2xPhiQ14q; + short oppTail, nearTail; + phiQ14q = intLimCDivPos( labs(indexphi)<<13,D>>1); + if ( (0xFFFe&D) == 0 ) /* even -> positive, odd -> 0 */ + { + phiQ14q = 1 << 13; /* one op */ + } +#define C_TOP ((1 << 14) - (1 << 6)) +#define C_BOT (1 << 6) +#define C_SHRT_MAXABS (1L << 15) +#define C_SHRT_MAX_POS ((1 << 15) - 1) +#define C_Q14_MAX (1<<14) + + oppTail = phiQ14q >= C_TOP; + nearTail = phiQ14q < C_BOT; + if (!(oppTail || nearTail)) + { + L_2xPhiQ14q = 2*(int)phiQ14q; + nearProjQ15( (short)(C_SHRT_MAXABS - L_2xPhiQ14q ) , oppQ15 ); + nearProjQ15(phiQ14q << 1, nearQ15 ); + Ratio_rQ3(*oppQ15, *nearQ15,oppRatioQ3 ); + } + else + { + *oppRatioQ3 = (1 - 2*nearTail)*C_Q14_MAX ; + *oppQ15 = oppTail * C_SHRT_MAX_POS; + *nearQ15 = nearTail * C_SHRT_MAX_POS; + } +#undef C_TOP +#undef C_BOT +#undef C_SHRT_MAXABS +#undef C_SHRT_MAX_POS +#undef C_Q14_MAX + return; +} + +void densityAngle2RmsProjEnc +( + short D, + short phiQ14uq, + short *indexphi, + short *oppQ15, + short *nearQ15, + short *oppRatioQ3 +) +{ + +#define C_MAX13 (1L << 13) + *indexphi = ((int)D * phiQ14uq + C_MAX13 ) >> 14; +#undef C_MAX13 + + if( (0xFFFE&D) == 0 ) + { + *indexphi = -1; /* one op */ + } + densityAngle2RmsProjDec(D, *indexphi, oppQ15, nearQ15, oppRatioQ3); + return; +} + +void NearOppSplitAdjustment( + short qband, + short qzero, + const short Qac, + const unsigned int INTac, + short qglobal, + short FlagCons, + short Np, + short Nhead, + short Ntail, + short Nnear, + short Nopp, + short oppRQ3, + short *qnear, + short *qopp, + short *qglobalupd +) +{ + short qac, qskew, qboth, QIb; + int QIa, L_QIb, qnum; + short qmin, qavg, Midx; + + rangeCoderFinalizationFBits(Qac, INTac, &qac); + qboth = qband - (qac - qzero); + qskew = 0; /* skew calc code */ + if(Nhead > 1) + { + qavg = intLimCDivSigned(qboth, Np); + dsDiracPerQuanta(Ntail, qavg, FlagCons, hBitsN, &Midx ); + QuantaPerDsDirac( Nhead, Midx, hBitsN, &qmin); + + qskew = qavg - qmin; + qskew = max(0, qskew); + } /* end of skew calc code*/ + + QIa = intLimCDivPos(Nopp, Nnear) + 1; + qnum = qband + qzero - qac - qskew - Nopp * (int)oppRQ3; + L_QIb = 0; + if( qnum > 0 ) + { + L_QIb = intLimCDivPos(qnum, QIa); + } + QIb = (short) min(32767L,L_QIb); /* saturate, L_QIb >= 0 */ + *qnear = QIb; + if( QIb > qboth ) + { + *qnear = qboth; /*single op*/ + } + *qopp = qboth - *qnear; + *qglobalupd = qglobal - (qac - qzero); + return; +} + +/*--------------------------------------------------------------------------* + * apply_gain() + * + * Apply gain + *--------------------------------------------------------------------------*/ + +void apply_gain +( + const short *ord, /* i : Indices for energy order */ + const short *band_start, /* i : Sub band start indices */ + const short *band_end, /* i : Sub band end indices */ + const short num_sfm, /* i : Number of bands */ + const float *gains, /* i : Band gain vector */ + float *xq /* i/o: Float synthesis / Gain adjusted synth */ +) +{ + short band,i; + float g; + + for ( band = 0; band < num_sfm; band++) + { + g = gains[ord[band]]; + + for( i = band_start[band]; i < band_end[band]; i++) + { + xq[i] *= g; + } + } + + return; +} + + +/*--------------------------------------------------------------------------* + * fine_gain_quant() + * + * Fine gain quantization + *--------------------------------------------------------------------------*/ + +void fine_gain_quant +( + Encoder_State *st, + const short *ord, /* i : Indices for energy order */ + const short num_sfm, /* i : Number of bands */ + const short *gain_bits, /* i : Gain adjustment bits per sub band */ + float *fg_pred, /* i/o: Predicted gains / Corrected gains */ + const float *gopt /* i : Optimal gains */ +) +{ + short band; + short gbits; + short idx; + float gain_db,gain_dbq; + float err; + + for ( band = 0; band < num_sfm; band++) + { + gbits = gain_bits[ord[band]]; + if ( fg_pred[band] != 0 && gbits > 0 ) + { + err = gopt[band] / fg_pred[band]; + gain_db = 20.0f*(float)log10(err); + idx = (short) squant(gain_db, &gain_dbq, finegain[gbits-1], gain_cb_size[gbits-1]); + push_indice( st, IND_PVQ_FINE_GAIN, idx, gbits ); + + /* Update prediced gain with quantized correction */ + fg_pred[band] *= (float)pow(10, gain_dbq * 0.05f); + } + } + + return; +} + +/*-------------------------------------------------------------------* + * srt_vec_ind() + * + * sort vector and save sorting indices + *-------------------------------------------------------------------*/ + +void srt_vec_ind ( + const short *linear, /* i: linear input */ + short *srt, /* o: sorted output*/ + short *I, /* o: index for sorted output */ + short length /* i: length of vector */ +) +{ + float linear_f[MAX_SRT_LEN]; + float srt_f[MAX_SRT_LEN]; + + mvs2r(linear, linear_f, length); + srt_vec_ind_f(linear_f, srt_f, I, length); + mvr2s(srt_f, srt, length); + + return; +} + +/*-------------------------------------------------------------------* + * srt_vec_ind_f() + * + * sort vector and save sorting indices, using float input values + *-------------------------------------------------------------------*/ + +void srt_vec_ind_f( + const float *linear, /* i: linear input */ + float *srt, /* o: sorted output*/ + short *I, /* o: index for sorted output */ + short length /* i: length of vector */ +) +{ + short pos,npos; + short idxMem; + float valMem; + + /*initialize */ + for (pos = 0; pos < length; pos++) + { + I[pos] = pos; + } + + mvr2r(linear, srt,length); + + /* now iterate */ + for (pos = 0; pos < (length - 1); pos++) + { + for (npos = (pos + 1); npos < length; npos++) + { + if (srt[npos] < srt[pos]) + { + idxMem = I[pos]; + I[pos] = I[npos]; + I[npos] = idxMem; + + valMem = srt[pos]; + srt[pos] = srt[npos]; + srt[npos] = valMem; + } + } + } + + return; +} + + +unsigned int UMult_32_32(unsigned int UL_var1, unsigned int UL_var2) +{ + ui64_t tmp; + + tmp = (ui64_t)UL_var1 * (ui64_t)UL_var2; + return (unsigned int)(tmp >> 32); +} + +/*-------------------------------------------------------------------* + * UL_div + * + * Calculate UL_num/UL_den. UL_num assumed to be Q31, UL_den assumed + * to be Q32, then result is in Q32. + *-------------------------------------------------------------------*/ +static unsigned int UL_div(const unsigned int UL_num, const unsigned int UL_den) +{ + unsigned int UL_e, UL_Q; + unsigned int UL_msb; + short i; + + UL_e = 0xffffffff - UL_den; + UL_Q = UL_num; + + for (i = 0; i < 5; i++) + { + UL_msb = UMult_32_32(UL_Q, UL_e); + UL_Q = UL_Q + UL_msb; + UL_e = UMult_32_32(UL_e, UL_e); + } + + return UL_Q; +} +/*-------------------------------------------------------------------* + * UL_inverse + * + * Calculate inverse of UL_val. Output in Q_exp. + *-------------------------------------------------------------------*/ +unsigned int UL_inverse(const unsigned int UL_val, short *exp) +{ + unsigned int UL_tmp; + + + *exp = norm_ul(UL_val); /* aligned to BASOP */ + UL_tmp = UL_val << (*exp); /* Q32*/ + + *exp = 32 + 31 - *exp; + + return UL_div(0x80000000, UL_tmp); +} + +/*----------------------------------------------------------------------------- + * ratio() + * + * Divide the numerator by the denominator. + *----------------------------------------------------------------------------*/ +Word16 ratio(const Word32 numer, const Word32 denom, Word16 *expo) +{ + Word16 expNumer, expDenom; + Word16 manNumer, manDenom; + Word16 quotient; + + expDenom = norm_l(denom); /* exponent */ + manDenom = extract_h(L_shl(denom, expDenom)); /* mantissa */ + expNumer = norm_l(numer); /* exponent */ + manNumer = extract_h(L_shl(numer, expNumer)); /* mantissa */ + manNumer = shr(manNumer, 1); /* Ensure the numerator < the denominator */ + quotient = div_s(manNumer, manDenom); /* in Q14 */ + + *expo = sub(expNumer, expDenom); + + return quotient; /* Q14 */ +} + +/*----------------------------------------------------------------------------- + * atan2_fx(): + * + * Approximates arctan piecewise with various 4th to 5th order least square fit + * polynomials for input in 5 segments: + * - 0.0 to 1.0 + * - 1.0 to 2.0 + * - 2.0 to 4.0 + * - 4.0 to 8.0 + * - 8.0 to infinity + *---------------------------------------------------------------------------*/ +Word16 atan2_fx( /* o: Angle between 0 and EVS_PI/2 radian (Q14) */ + const Word32 y, /* i: Argument must be positive (Q15) */ + const Word32 x /* i: Q15 */ +) +{ + Word32 acc, arg; + Word16 man, expo, reciprocal; + Word16 angle, w, z; + + IF (L_sub(x, 0) == 0) + { + return 25736; /* EVS_PI/2 in Q14 */ + } + man = ratio(y, x, &expo); /* man in Q14 */ + expo = sub(expo, (15 - 14)); /* Now, man is considered in Q15 */ + arg = L_shr((Word32)man, expo); + + IF (L_shr(arg, 3+15) != 0) + /*===============================* + * 8.0 <= x < infinity * + *===============================*/ + { + /* atan(x) = EVS_PI/2 - 1/x + 1/(3x^3) - 1/(5x^5) + ... + * ~ EVS_PI/2 - 1/x, for x >= 8. + */ + expo = norm_l(arg); + man = extract_h(L_shl(arg, expo)); + reciprocal = div_s(0x3fff, man); + expo = sub(15 + 1, expo); + reciprocal = shr(reciprocal, expo); /* Q14*/ + angle = sub(25736, reciprocal); /* Q14 (EVS_PI/2 - 1/x) */ + + /* For 8.0 <= x < 10.0, 1/(5x^5) is not completely negligible. + * For more accurate result, add very small correction term. + */ + IF (L_sub(L_shr(arg, 15), 10L) < 0) + { + angle = add(angle, 8); /* Add tiny correction term. */ + } + } + ELSE IF (L_shr(arg, 2+15) != 0) + /*==========================* + * 4.0 <= x < 8.0 * + *==========================*/ + { + /* interval: [3.999, 8.001] + * atan(x) ~ (((a0*x + a1)*x + a2)*x + a3)*x + a4 + * = (((a0*8*y + a1)*8*y + a2)*8*y + a3)*8*y + a4 Substitute 8*y -> x + * = (((a0*8^3*y + a1*8^2)*y + a2*8)*y + a3)*8*y + a4 + * = ((( c0*y + c1)*y + c2)*y + c3)*8*y + c4, + * where y = x/8 + * and a0 = -1.28820869667651e-04, a1 = 3.88263533346295e-03, + * a2 = -4.64216306484597e-02, a3 = 2.75986060068931e-01, + * a4 = 7.49208077809799e-01. + */ + w = extract_l(L_shr(arg, 3)); /* Q15 y = x/8 */ + acc = 533625337L; /* Q31 c1 = a1*8^2 */ move32(); + z = mac_r(acc, w, -2161); /* Q15 c0 = a0*8^3 */ + acc = -797517542L; /* Q31 c2 = a2*8 */ move32(); + z = mac_r(acc, w, z); /* Q15 */ + acc = 592675551L; /* Q31 c3 = a3 */ move32(); + z = mac_r(acc, w, z); /* z (in:Q15, out:Q12) */ + acc = 201114012L; /* Q28 c4 = a4 */ move32(); + acc = L_mac(acc, w, z); /* Q28 */ + angle = extract_l(L_shr(acc, (28 - 14))); /* Q14 result of atan(x), where 4 <= x < 8 */ + } + ELSE IF (L_shr(arg, 1+15) != 0) + /*==========================* + * 2.0 <= x < 4.0 * + *==========================*/ + { + /* interval: [1.999, 4.001] + * atan(x) ~ (((a0*x + a1)*x + a2)*x + a3)*x + a4 + * = (((a0*4*y + a1)*4*y + a2)*4*y + a3)*4*y + a4 Substitute 4*y -> x + * = (((a0*16*y + a1*4)*y + a2)*4*y + a3)*4*y + a4 + * = (((a0*32*y + a1*8)*y + a2*2)*2*y + a3)*4*y + a4 + * = ((( c0*y + c1)*y + c2)*2*y + c3)*4*y + c4, + * where y = x/4 + * and a0 = -0.00262378195660943, a1 = 0.04089687039888652, + * a2 = -0.25631148958325911, a3 = 0.81685854627399479, + * a4 = 0.21358070563097167 + * */ + w = extract_l(L_shr(arg, 2)); /* Q15 y = x/4 */ + acc = 702602883L; /* Q31 c1 = a1*8 */ move32(); + z = mac_r(acc, w, -2751); /* Q15 c0 = a0*32 */ + acc = -1100849465L; /* Q31 c2 = a2*2 */ move32(); + z = mac_r(acc, w, z); /* z (in:Q15, out:Q14) */ + acc = 877095185L; /* Q30 c3 = a3 */ move32(); + z = mac_r(acc, w, z); /* z (in:Q14, out:Q12) */ + acc = 57332634L; /* Q28 c4 = a4 */ move32(); + acc = L_mac(acc, w, z); /* Q28 */ + angle = extract_l(L_shr(acc, (28 - 14))); /* Q14 result of atan(x) where 2 <= x < 4 */ + } + ELSE IF (L_shr(arg, 15) != 0) + /*==========================* + * 1.0 <= x < 2.0 * + *==========================*/ + { + /* interval: [0.999, 2.001] + * atan(x) ~ (((a0*x + 1)*x + a2)*x + a3)*x + a4 + * = (((a0*2*y + a1)*2*y + a2)*2*y + a3)*2*y + a4 Substitute 2*y -> x + * = (((a0*4*y + a1*2)*y + a2)*2*y + a3)*2*y + a4 + * = (((a0*4*y + a1*2)*y + a2)*y + a3/2)*4*y + a4 + * = ((( c0*y + c1)*y + c2)*y + c3)*4*y + c4, + * where y = x/2 + * and a0 = -0.0160706457245251, a1 = 0.1527106504065224, + * a2 = -0.6123208404800871, a3 = 1.3307896976322915, + * a4 = -0.0697089375247448 + */ + w = extract_l(L_shr(arg, 1)); /* Q15 y= x/2 */ + acc = 655887249L; /* Q31 c1 = a1*2 */ move32(); + z = mac_r(acc, w, -2106); /* Q15 c0 = a0*4 */ + acc = -1314948992L; /* Q31 c2 = a2 */ move32(); + z = mac_r(acc, w, z); + acc = 1428924557L; /* Q31 c3 = a3/2 */ move32(); + z = mac_r(acc, w, z); /* z (in:Q15, out:Q13) */ + acc = -37424701L; /* Q29 c4 = a4 */ move32(); + acc = L_mac(acc, w, z); /* Q29 */ + angle = extract_l(L_shr(acc, (29 - 14))); /* Q14 result of atan(x) where 1 <= x < 2 */ + } + ELSE + /*==========================* + * 0.0 <= x < 1.0 * + *==========================*/ + { + /* interval: [-0.001, 1.001] + * atan(x) ~ ((((a0*x + a1)*x + a2)*x + a3)*x + a4)*x + a5 + * = ((((a0*2*x + a1*2)*x/2 + a2)*x + a3)*x + a4)*x + a5 + * = (((( c0*x + c1)*x/2 + c2)*x + c3)*x + c4)*x + c5 + * where + * a0 = -5.41182677118661e-02, a1 = 2.76690449232515e-01, + * a2 = -4.63358392562492e-01, a3 = 2.87188466598566e-02, + * a4 = 9.97438122814383e-01, a5 = 5.36158556179092e-05. + */ + w = extract_l(arg); /* Q15 */ + acc = 1188376431L; /* Q31 c1 = a1*2 */ move32(); + z = mac_r(acc, w, -3547); /* Q15 c0 = a0*2 */ + acc = -995054571L; /* Q31 c2 = a2 */ move32(); + z = extract_h(L_mac0(acc, w, z)); /* Q15 non-fractional mode multiply */ + acc = 61673254L; /* Q31 c3 = a3 */ move32(); + z = mac_r(acc, w, z); + acc = 2141982059L; /* Q31 c4 = a4 */ move32(); + z = mac_r(acc, w, z); + acc = 115139L; /* Q31 c5 = a5 */ move32(); + acc = L_mac(acc, w, z); /* Q31 */ + angle = extract_l(L_shr(acc, 31 - 14)); /* Q14 result of atan(x), where 0 <= x < 1 */ + } + return angle; /* Q14 between 0 and EVS_PI/2 radian. */ +} diff --git a/src/libs/libevs/lib_com/pvq_com_fx.cpp b/src/libs/libevs/lib_com/pvq_com_fx.cpp deleted file mode 100755 index 10cc6b23..00000000 --- a/src/libs/libevs/lib_com/pvq_com_fx.cpp +++ /dev/null @@ -1,753 +0,0 @@ -/*==================================================================================== - EVS Codec 3GPP TS26.442 Apr 03, 2018. Version 12.11.0 / 13.6.0 / 14.2.0 - ====================================================================================*/ - -#include "options.h" /* Compilation switches */ - -#include "prot_fx.h" /* Function prototypes */ -#include "cnst_fx.h" /* Common constants */ -#include "rom_com_fx.h" /* Static table prototypes */ -#include "stl.h" /* required for wmc_tool */ - - -#include "options.h" - - -UWord32 intLimCDivPos_fx( - UWord32 NUM, - Word16 DEN -) -{ - UWord32 UL_ru, UL_rl; - Mpy_32_32_uu(UL_lshl(NUM, 1), intLimCDivInvDQ31[DEN], &UL_ru, &UL_rl); - return UL_ru; -} - - -Word32 intLimCDivSigned_fx( - Word32 NUM, - Word16 DEN) -{ - Word32 L_tmp; - - L_tmp = intLimCDivPos_fx( L_abs(NUM) , DEN); - if (NUM < 0) - { - L_tmp= L_negate(L_tmp); /* one op */ - } - return L_tmp; -} - - -Word16 shrtCDivSignedApprox( const Word16 num, - const Word16 den - ) -{ - Word16 pool_part; - - pool_part = extract_h( L_mult( negate(abs_s(num)), lim_neg_inv_tbl_fx[den] )); - /* neg_in always, positive out always, so that positive truncation(rounding) is used */ - if ( num < 0 ) - { - pool_part = negate(pool_part); /* make negative, one op */ - } - return pool_part; -} - -void nearProjQ15_fx( - Word16 x, - Word16 *result -) -{ - const Word16 a[4] = {14967, -25518, 3415, 32351}; - Word32 b; - UWord16 lsb; - - b = L_deposit_l(a[0]); - b = L_shl((Word32)add(a[1], extract_h(L_mult0((Word16)b, x))), 1); - Mpy_32_16_ss(b, x, &b, &lsb); - b = L_add((Word32)a[2], b); - Mpy_32_16_ss(b, x, &b, &lsb); - b = L_add((Word32)a[3], b); - *result = extract_l(b); - return ; -} - -/*-------------------------------------------------------------------* - * obtainEnergyQuantizerDensity_fx() - * - * - *-------------------------------------------------------------------*/ -void obtainEnergyQuantizerDensity_fx( - const Word16 L, - const Word16 R, - Word16 *Density ) -{ - Word16 Rnrg, den, n; - - den = sub(shl(L, 1), 1); - IF( den <= 67 ) - { - Rnrg = extract_l(intLimCDivPos_fx( L_deposit_l(R) , den)); - } - ELSE - { - n = norm_s(den); - Rnrg = shr(div_s(R, shl(den, n)), sub(15, n)); - } - Rnrg = add(Rnrg, 28); - - Rnrg = s_min(Rnrg, 56); - Rnrg = s_min(Rnrg, sub(R, 96)); - - Rnrg = s_max(Rnrg, 3); - *Density = obtainEnergyQuantizerDensity_f[Rnrg]; - return; -} - - -/*-------------------------------------------------------------------* - * dsDirac2Dirac_fx() - * - * - *-------------------------------------------------------------------*/ -void dsDirac2Dirac_fx( - const Word16 dsDiracIndex, - Word16 *diracs -) -{ - *diracs = dsDiracsTab[dsDiracIndex]; - return; -} - -void dsDiracPerQuanta_fx( - const Word16 td, - const Word16 t_quanta, - const Word16 dsm, - const unsigned char* const *frQuanta, - Word16 *DsIdx -) -{ - const unsigned char *sv; - Word16 nsv; - Word16 t_quanta_o; - Word16 dsIndex; - Word16 i; - - sv = frQuanta[td]; - nsv = sv[0]; - - t_quanta_o = sub(t_quanta, QUANTAQ3OFFSET); - - IF (sub(t_quanta_o, sv[nsv]) >= 0) - { - *DsIdx = nsv; - move16(); - return ; - } - - IF (sub(t_quanta_o, sv[1]) <= 0) - { - *DsIdx = 1; - move16(); - return ; - } - - - dsIndex = shl(1, frQuanta[0][td]); - if (sub(t_quanta_o, sv[shr(nsv, 1) ]) > 0 ) - { - dsIndex = sub(nsv, dsIndex ); - } - FOR (i = sub(frQuanta[0][td], 1); i >= 0; i--) - { - dsIndex = add(dsIndex, shl(sub(shl(lshr(sub(sv[dsIndex], t_quanta_o), 15), 1), 1), i)); - } - - dsIndex = add(dsIndex, lshr(sub(sv[dsIndex], t_quanta_o), 15)); - dsIndex = sub(dsIndex, lshr(sub(1, dsIndex), 15)); - - IF (dsm > 0) - { - *DsIdx=dsIndex; - move16(); - return; - } - *DsIdx = add(dsIndex, lshr(sub(add(sv[add(dsIndex,1)], sv[dsIndex]), shl(t_quanta_o, 1)), 15)); - return; -} - -void QuantaPerDsDirac_fx( - Word16 td, - Word16 dsDiracIndex, - const unsigned char* const* dimFrQuanta, - Word16 *Quanta -) -{ - *Quanta = dimFrQuanta[td][dsDiracIndex]; - move16(); - if(dsDiracIndex == 0) - { - *Quanta = -1; /* single op */ move16(); - } - *Quanta = add(*Quanta, QUANTAQ3OFFSET); - return ; -} - -void conservativeL1Norm_fx( - Word16 L, - Word16 Qvec, - Word16 Fcons, - Word16 Qavail, - Word16 Qreserv, - Word16 Dspec, - Word16 *Dvec, - Word16 *Qspare, - Word16 *Qreservplus, - Word16 *Dspecplus -) -{ - - Word16 Minit, Mprime; - Word16 Qtestminus; - const unsigned char *frQuantaL; - - frQuantaL = hBitsN[L]; - - *Qreservplus = add(Qreserv, sub(Qvec, QUANTAQ3OFFSET)); - - dsDiracPerQuanta_fx(L, Qvec, Fcons, hBitsN, &Minit); - - Mprime = Minit; - move16(); - DO - { - Qtestminus = (short)frQuantaL[Mprime]; - move16(); - *Qspare = sub(Qavail, Qtestminus); - Mprime = sub(Mprime, 1); - } - WHILE ( (Mprime >= 0) && sub(*Qspare, QUANTAQ3OFFSET ) < 0 ); - - if(Mprime < 0) - { - *Qspare = add(Qavail, QUANTAQ3OFFSET); /* single op */ - } - dsDirac2Dirac_fx(add(Mprime, 1), Dvec); - - *Dspecplus = add(Dspec, *Dvec); - *Qreservplus = sub(*Qreservplus, (short)frQuantaL[Minit]); - *Qspare = sub(*Qspare, QUANTAQ3OFFSET); - - return; -} - - - - - -void bandBitsAdjustment_fx( - Word16 Brc, - UWord32 INTrc, - Word16 Bavail, - Word16 Nbands, - Word16 D, - Word16 L, - Word16 Bband, - Word16 Breserv, - Word16 *Bband_adj, - Word16 *Brem, - Word16 *Breservplus) -{ - Word16 Btemp; - Word16 Bff; - Word32 L_tmp; - - rangeCoderFinalizationFBits_fx(Brc, INTrc, &Bff); - - IF(sub(D, Nbands) < 0) - { - L_tmp = L_deposit_l(sub(Breserv, Bff)); - Btemp = extract_l(intLimCDivSigned_fx(L_tmp, s_min(D, 3))); /* result always fits in Word16 */ - *Breservplus = add(Bband, Breserv); - } - ELSE - { - Btemp = 0; - move16(); - *Breservplus = add(Bband, Bff); - } - *Bband_adj = s_min(extract_l(L_mult(L, 40)), Bband); - *Brem = sub(Bavail, Bff); - *Bband_adj = s_min(*Brem, add(*Bband_adj, Btemp)); - *Bband_adj = s_max(0, *Bband_adj); -} - - - -static Word16 Ratio_base2Q11_fx( /* o : Q11 */ - const Word16 opp, /* i : Q15 */ - const Word16 near /* i : Q15 */ -) -{ - Word16 mc, nc, ms, ns, d, z; - Word16 result; - Word32 acc; - - ns = norm_s(opp ); /* exponent */ - nc = norm_s(near ); /* exponent */ - - ms = shl(opp, ns); /* mantissa */ - mc = shl(near, nc); /* mantissa */ - - acc = L_mac(538500224L, mc, -2776); /* a0*mc + a1, acc(Q27), a0(Q11), a1(Q27) */ - z = mac_r(acc, ms, -2776); /* z in Q11, a0 in Q11 */ - d = sub(ms, mc); /* d in Q15 */ - z = mult_r(z, d); /* z in Q11 */ - - result = add(z, shl(sub(nc, ns), 11)); - - return result; -} - -void Ratio_rQ3_fx( - Word16 opp, - Word16 near, - Word16 *result -) -{ - Word16 tmp; - - tmp = add(1<<7 , Ratio_base2Q11_fx(opp, near)); - *result = shr(tmp, 8); - return ; -} - - -void densityAngle2RmsProjDec_fx( - Word16 D, - Word16 indexphi, - Word16 *oppQ15, - Word16 *nearQ15, - Word16 *oppRatioQ3 -) -{ - Word16 phiQ14q; - Word16 oppTail, nearTail; - - phiQ14q = (Word16)intLimCDivPos_fx(L_shl(L_deposit_l(indexphi), 13), shr(D, 1)); - if (indexphi < 0) - { - phiQ14q = 1 << 13; /* one op */ move16(); - } - - oppTail = shr(sub(16320, phiQ14q), 15); - nearTail = shr(sub(phiQ14q, 64), 15); - - IF (s_or(oppTail, nearTail) < 0) - { - *oppQ15 = s_and(oppTail, (1 << 15) - 1); - *nearQ15 = s_and(nearTail, (1 << 15) - 1); - *oppRatioQ3 = shl(add(1, shl(nearTail, 1)), 14); - } - ELSE - { - nearProjQ15_fx( shl(sub(1 << 14, phiQ14q), 1), oppQ15); - nearProjQ15_fx(shl(phiQ14q, 1), nearQ15); - Ratio_rQ3_fx(*oppQ15, *nearQ15, oppRatioQ3); - } - - return; -} - -void densityAngle2RmsProjEnc_fx( - Word16 D, - Word16 phiQ14uq, - Word16 *indexphi, - Word16 *oppQ15, - Word16 *nearQ15, - Word16 *oppRatioQ3 -) -{ - *indexphi = mult_r(shl(D, 1), phiQ14uq); - if (s_and(D, 1) > 0) - { - *indexphi = -1; /* one op */ move16(); - } - densityAngle2RmsProjDec_fx(D, *indexphi, oppQ15, nearQ15, oppRatioQ3); - - return; -} - -void NearOppSplitAdjustment_fx( - const Word16 qband, - const Word16 qzero, - const Word16 Qac, - const UWord32 INTac, - const Word16 qglobal, - const Word16 FlagCons, - const Word16 Np, - const Word16 Nhead, - const Word16 Ntail, - const Word16 Nnear, - const Word16 Nopp, - Word16 oppRQ3, - Word16 *qnear, - Word16 *qopp, - Word16 *qglobalupd -) -{ - - Word16 qac, qboth, qskew, qavg, qmin, Midx; - Word32 L_QIb, L_qnum; - Word16 QIb, QIa; - - rangeCoderFinalizationFBits_fx(Qac, INTac, &qac); - qboth = sub(qband, sub(qac, qzero)); - /* skew calc code */ - qskew = 0 ; - move16(); - IF (sub(Nhead, 1) > 0) - { - qavg = extract_h(L_shl(intLimCDivSigned_fx((Word32)qboth, Np),16)); /* qboth may be negative */ - dsDiracPerQuanta_fx(Ntail, qavg, FlagCons, hBitsN, &Midx ); - QuantaPerDsDirac_fx(Nhead, Midx, hBitsN, &qmin); - qskew = sub(qavg, qmin); - qskew = s_max(0, qskew); - } /* end of skew calc code*/ - - QIa = add(extract_l(intLimCDivPos_fx((UWord32)L_deposit_l(Nopp), Nnear)), 1); /* always positive Word16 out */ - L_qnum = L_sub( L_deposit_l(sub(sub(add(qband, qzero), qac), qskew)), L_mult0(Nopp, oppRQ3)); - - L_QIb = L_deposit_l(0); - IF (L_qnum > 0) - { - L_QIb = (Word32) intLimCDivPos_fx(L_qnum, QIa); - } - *qnear = qboth; - QIb = extract_h(L_shl(L_QIb, 16)); /* may saturate */ - if (sub(QIb, qboth) <= 0) - { - *qnear = QIb; - } - *qopp = sub(qboth, *qnear); - *qglobalupd = sub(qglobal, sub(qac, qzero)); - - return; -} - - -/*--------------------------------------------------------------------------* - * apply_gain() - * - * Apply gain - *--------------------------------------------------------------------------*/ - -void apply_gain_fx( - const Word16 *ord, /* i : Indices for energy order */ - const Word16 *band_start, /* i : Sub band start indices */ - const Word16 *band_end, /* i : Sub band end indices */ - const Word16 num_sfm, /* i : Number of bands */ - const Word16 *gains, /* i : Band gain vector Q12 */ - Word16 *xq /* i/o: Float synthesis / Gain adjusted synth Q15/Q12 */ -) -{ - Word16 band,i; - Word16 g; /* Q12 */ - - FOR ( band = 0; band < num_sfm; band++) - { - g = gains[ord[band]]; - - FOR( i = band_start[band]; i < band_end[band]; i++) - { - /*xq[i] *= g; */ - xq[i] = mult_r(g, xq[i]); - move16(); /*12+15+1-16=12 */ - } - } - - return; -} - -/*--------------------------------------------------------------------------* - * fine_gain_quant() - * - * Fine gain quantization - *--------------------------------------------------------------------------*/ - -void fine_gain_quant_fx( - Encoder_State_fx *st_fx, - const Word16 *ord, /* i : Indices for energy order */ - const Word16 num_sfm, /* i : Number of bands */ - const Word16 *gain_bits, /* i : Gain adjustment bits per sub band */ - Word16 *fg_pred, /* i/o: Predicted gains / Corrected gains Q12 */ - const Word16 *gopt /* i : Optimal gains Q12 */ -) -{ - Word16 band; - Word16 gbits; - Word16 idx; - Word16 gain_db,gain_dbq; - Word16 err; - - Word16 tmp1, tmp2, exp1, exp2; - Word32 L_tmp; - UWord16 lsb; - - FOR ( band = 0; band < num_sfm; band++) - { - gbits = gain_bits[ord[band]]; - test(); - IF ( fg_pred[band] != 0 && gbits > 0 ) - { - exp1 = norm_s(gopt[band]); - exp1 = sub(exp1, 1); - tmp1 = shl(gopt[band], exp1); - exp2 = norm_s(fg_pred[band]); - tmp2 = shl(fg_pred[band], exp2); - exp1 = add(15, sub(exp1, exp2)); - err = div_s(tmp1, tmp2); - tmp1 = norm_s(err); - exp2 = Log2_norm_lc(L_deposit_h(shl(err, tmp1))); - tmp1 = sub(14, tmp1); - tmp1 = sub(tmp1, exp1); - L_tmp = L_Comp(tmp1, exp2); - Mpy_32_16_ss(L_tmp, 24660, &L_tmp, &lsb); /* 24660 = 20*log10(2) in Q12 */ /*16+12-15=13 */ - gain_db = round_fx(L_shl(L_tmp, 17)); - - idx = squant_fx(gain_db, &gain_dbq, finegain_fx[gbits-1], gain_cb_size[gbits-1]); - push_indice_fx( st_fx, IND_PVQ_FINE_GAIN, idx, gbits ); - - L_tmp = L_mult0(gain_dbq, 21771); /* 21771=0.05*log2(10) */ /* 14+17=31 */ - L_tmp = L_shr(L_tmp, 15); - tmp1 = L_Extract_lc(L_tmp, &exp1); - tmp1 = abs_s(tmp1); - tmp1 = extract_l(Pow2(14, tmp1)); - exp1 = sub(14, exp1); - - L_tmp = L_mult0(fg_pred[band], tmp1); /*12+exp1 */ - fg_pred[band] = round_fx(L_shl(L_tmp, sub(16, exp1))); /*12+exp1+16-exp1-16=12 */ - } - } - - return; -} - -/*-------------------------------------------------------------------* - * srt_vec_ind() - * - * sort vector and save sorting indeces - *-------------------------------------------------------------------*/ - -void srt_vec_ind16_fx ( - const Word16 *linear, /* linear input */ - Word16 *srt, /* sorted output*/ - Word16 *I, /* index for sorted output */ - Word16 length -) -{ - Word16 pos,npos; - Word16 idxMem; - Word16 valMem; - - /*initilize */ - FOR (pos = 0; pos < length; pos++) - { - I[pos] = pos; - move16(); - } - - Copy(linear, srt,length); - - /* now iterate */ - FOR (pos = 0; pos < (length - 1); pos++) - { - FOR (npos = (pos + 1); npos < length; npos++) - { - IF (sub(srt[npos], srt[pos]) < 0) - { - idxMem = I[pos]; - move16(); - I[pos] = I[npos]; - move16(); - I[npos] = idxMem; - move16(); - - valMem = srt[pos]; - move16(); - srt[pos] = srt[npos]; - move16(); - srt[npos] = valMem; - move16(); - } - } - } - - return; -} - -/*----------------------------------------------------------------------------- - * atan2_fx(): - * - * Approximates arctan piecewise with various 4th to 5th order least square fit - * polynomials for input in 5 segments: - * - 0.0 to 1.0 - * - 1.0 to 2.0 - * - 2.0 to 4.0 - * - 4.0 to 8.0 - * - 8.0 to infinity - *---------------------------------------------------------------------------*/ -Word16 atan2_fx( /* o: Angle between 0 and PI/2 radian (Q14) */ - const Word32 y, /* i: Argument must be positive (Q15) */ - const Word32 x /* i: Q15 */ -) -{ - Word32 acc, arg; - Word16 man, expo, reciprocal; - Word16 angle, w, z; - - IF (x == 0) - { - return 25736; /* PI/2 in Q14 */ - } - man = ratio(y, x, &expo); /* man in Q14 */ - expo = sub(expo, (15 - 14)); /* Now, man is considered in Q15 */ - arg = L_shr((Word32)man, expo); - - IF (L_shr(arg, 3+15) != 0) - /*===============================* - * 8.0 <= x < infinity * - *===============================*/ - { - /* atan(x) = PI/2 - 1/x + 1/(3x^3) - 1/(5x^5) + ... - * ~ PI/2 - 1/x, for x >= 8. - */ - expo = norm_l(arg); - man = extract_h(L_shl(arg, expo)); - reciprocal = div_s(0x3fff, man); - expo = sub(15 + 1, expo); - reciprocal = shr(reciprocal, expo); /* Q14 */ - angle = sub(25736, reciprocal); /* Q14 (PI/2 - 1/x) */ - - /* For 8.0 <= x < 10.0, 1/(5x^5) is not completely negligible. - * For more accurate result, add very small correction term. - */ - if (L_sub(L_shr(arg, 15), 10L) < 0) - { - angle = add(angle, 8); /* Add tiny correction term. */ - } - } - ELSE IF (L_shr(arg, 2+15) != 0) - /*==========================* - * 4.0 <= x < 8.0 * - *==========================*/ - { - /* interval: [3.999, 8.001] - * atan(x) ~ (((a0*x + a1)*x + a2)*x + a3)*x + a4 - * = (((a0*8*y + a1)*8*y + a2)*8*y + a3)*8*y + a4 Substitute 8*y -> x - * = (((a0*8^3*y + a1*8^2)*y + a2*8)*y + a3)*8*y + a4 - * = ((( c0*y + c1)*y + c2)*y + c3)*8*y + c4, - * where y = x/8 - * and a0 = -1.28820869667651e-04, a1 = 3.88263533346295e-03, - * a2 = -4.64216306484597e-02, a3 = 2.75986060068931e-01, - * a4 = 7.49208077809799e-01. - */ - w = extract_l(L_shr(arg, 3)); /* Q15 y = x/8 */ - acc = L_add(533625337L, 0); /* Q31 c1 = a1*8^2 */ - z = mac_r(acc, w, -2161); /* Q15 c0 = a0*8^3 */ - acc = L_add(-797517542L, 0); /* Q31 c2 = a2*8 */ - z = mac_r(acc, w, z); /* Q15 */ - acc = L_add(592675551L, 0); /* Q31 c3 = a3 */ - z = mac_r(acc, w, z); /* z (in:Q15, out:Q12) */ - acc = L_add(201114012L, 0); /* Q28 c4 = a4 */ - acc = L_mac(acc, w, z); /* Q28 */ - angle = extract_l(L_shr(acc, (28 - 14))); /* Q14 result of atan(x), where 4 <= x < 8 */ - } - ELSE IF (L_shr(arg, 1+15) != 0) - /*==========================* - * 2.0 <= x < 4.0 * - *==========================*/ - { - /* interval: [1.999, 4.001] - * atan(x) ~ (((a0*x + a1)*x + a2)*x + a3)*x + a4 - * = (((a0*4*y + a1)*4*y + a2)*4*y + a3)*4*y + a4 Substitute 4*y -> x - * = (((a0*16*y + a1*4)*y + a2)*4*y + a3)*4*y + a4 - * = (((a0*32*y + a1*8)*y + a2*2)*2*y + a3)*4*y + a4 - * = ((( c0*y + c1)*y + c2)*2*y + c3)*4*y + c4, - * where y = x/4 - * and a0 = -0.00262378195660943, a1 = 0.04089687039888652, - * a2 = -0.25631148958325911, a3 = 0.81685854627399479, - * a4 = 0.21358070563097167 - * */ - w = extract_l(L_shr(arg, 2)); /* Q15 y = x/4 */ - acc = L_add(702602883L, 0); /* Q31 c1 = a1*8 */ - z = mac_r(acc, w, -2751); /* Q15 c0 = a0*32 */ - acc = L_add(-1100849465L, 0); /* Q31 c2 = a2*2 */ - z = mac_r(acc, w, z); /* z (in:Q15, out:Q14) */ - acc = L_add(877095185L, 0); /* Q30 c3 = a3 */ - z = mac_r(acc, w, z); /* z (in:Q14, out:Q12) */ - acc = L_add(57332634L, 0); /* Q28 c4 = a4 */ - acc = L_mac(acc, w, z); /* Q28 */ - angle = extract_l(L_shr(acc, (28 - 14))); /* Q14 result of atan(x) where 2 <= x < 4 */ - } - ELSE IF (L_shr(arg, 15) != 0) - /*==========================* - * 1.0 <= x < 2.0 * - *==========================*/ - { - /* interval: [0.999, 2.001] - * atan(x) ~ (((a0*x + 1)*x + a2)*x + a3)*x + a4 - * = (((a0*2*y + a1)*2*y + a2)*2*y + a3)*2*y + a4 Substitute 2*y -> x - * = (((a0*4*y + a1*2)*y + a2)*2*y + a3)*2*y + a4 - * = (((a0*4*y + a1*2)*y + a2)*y + a3/2)*4*y + a4 - * = ((( c0*y + c1)*y + c2)*y + c3)*4*y + c4, - * where y = x/2 - * and a0 = -0.0160706457245251, a1 = 0.1527106504065224, - * a2 = -0.6123208404800871, a3 = 1.3307896976322915, - * a4 = -0.0697089375247448 - */ - w = extract_l(L_shr(arg, 1)); /* Q15 y= x/2 */ - acc = L_add(655887249L, 0); /* Q31 c1 = a1*2 */ - z = mac_r(acc, w, -2106); /* Q15 c0 = a0*4 */ - acc = L_add(-1314948992L, 0); /* Q31 c2 = a2 */ - z = mac_r(acc, w, z); - acc = L_add(1428924557L, 0); /* Q31 c3 = a3/2 */ - z = mac_r(acc, w, z); /* z (in:Q15, out:Q13) */ - acc = L_add(-37424701L, 0); /* Q29 c4 = a4 */ - acc = L_mac(acc, w, z); /* Q29 */ - angle = extract_l(L_shr(acc, (29 - 14))); /* Q14 result of atan(x) where 1 <= x < 2 */ - } - ELSE - /*==========================* - * 0.0 <= x < 1.0 * - *==========================*/ - { - /* interval: [-0.001, 1.001] - * atan(x) ~ ((((a0*x + a1)*x + a2)*x + a3)*x + a4)*x + a5 - * = ((((a0*2*x + a1*2)*x/2 + a2)*x + a3)*x + a4)*x + a5 - * = (((( c0*x + c1)*x/2 + c2)*x + c3)*x + c4)*x + c5 - * where - * a0 = -5.41182677118661e-02, a1 = 2.76690449232515e-01, - * a2 = -4.63358392562492e-01, a3 = 2.87188466598566e-02, - * a4 = 9.97438122814383e-01, a5 = 5.36158556179092e-05. - */ - w = extract_l(arg); /* Q15 */ - acc = L_add(1188376431L, 0); /* Q31 c1 = a1*2 */ - z = mac_r(acc, w, -3547); /* Q15 c0 = a0*2 */ - acc = L_add(-995054571L, 0); /* Q31 c2 = a2 */ - z = extract_h(L_mac0(acc, w, z)); /* Q15 non-fractional mode multiply */ - acc = L_add(61673254L, 0); /* Q31 c3 = a3 */ - z = mac_r(acc, w, z); - acc = L_add(2141982059L, 0); /* Q31 c4 = a4 */ - z = mac_r(acc, w, z); - acc = L_add(115139L, 0); /* Q31 c5 = a5 */ - acc = L_mac(acc, w, z); /* Q31 */ - angle = extract_l(L_shr(acc, 31 - 14)); /* Q14 result of atan(x), where 0 <= x < 1 */ - } - - return angle; /* Q14 between 0 and PI/2 radian. */ -} - - - diff --git a/src/libs/libevs/lib_com/range_com.cpp b/src/libs/libevs/lib_com/range_com.cpp new file mode 100644 index 00000000..94cccd1d --- /dev/null +++ b/src/libs/libevs/lib_com/range_com.cpp @@ -0,0 +1,72 @@ +/*==================================================================================== + EVS Codec 3GPP TS26.443 Nov 13, 2018. Version 12.11.0 / 13.7.0 / 14.3.0 / 15.1.0 + ====================================================================================*/ + +#include +#include +#include "options.h" +#include "cnst.h" +#include "rom_com.h" +#include "prot.h" + +/*-------------------------------------------------------------------* + * rc_get_bits2() + * + * Get number of bits needed to finalize range coder + *-------------------------------------------------------------------*/ + +short rc_get_bits2( /* o: Number of bits needed */ + const short N, /* i: Number of bits currently used */ + const unsigned int range /* i: Range of range coder */ +) +{ + short tmp; + tmp = N + 2 + norm_ul(range); /* aligned to BASOP */ + return tmp; +} + + +void rangeCoderFinalizationFBits( + short Brc, + unsigned int INTrc, + short *FBits +) +{ + unsigned int Bq15, UL_tmp; + unsigned short Bq15ui16, B, E; + short k; + + B = 30 - norm_ul(INTrc); /* aligned to BASOP */ + + +#define RCF_INIT_SHIFTp1 (RCF_INIT_SHIFT+1) +#define RCF_FINALIZE_LIMIT ((1L << 16) - 1) + *FBits = (Brc + 32) * 8; + + Bq15 = 0; + k = B - RCF_INIT_SHIFT; + if (k >= 0 ) + { + Bq15 = INTrc >> ( k ); /* single op */ + } + + E = 2; + for( k = 1; k < 4; k++) + { + Bq15ui16 = Bq15 >> (E & 1); + UL_tmp = (unsigned int)Bq15ui16; + Bq15 = (UL_tmp * Bq15ui16) >> RCF_INIT_SHIFTp1 ; + E = 2*B; + if( Bq15 > RCF_FINALIZE_LIMIT ) + { + E++; + } + B = E; + } + *FBits -= B; +#undef RCF_INIT_SHIFTp1 +#undef RCF_FINALIZE_LIMIT + + return; +} + diff --git a/src/libs/libevs/lib_com/range_com_fx.cpp b/src/libs/libevs/lib_com/range_com_fx.cpp deleted file mode 100755 index a0929a4b..00000000 --- a/src/libs/libevs/lib_com/range_com_fx.cpp +++ /dev/null @@ -1,62 +0,0 @@ -/*==================================================================================== - EVS Codec 3GPP TS26.442 Apr 03, 2018. Version 12.11.0 / 13.6.0 / 14.2.0 - ====================================================================================*/ - -#include -#include "options.h" /* Compilation switches */ -#include "cnst_fx.h" /* Common constants */ -#include "prot_fx.h" /* Function prototypes */ -#include "stl.h" /* required for wmc_tool */ - - -/*-------------------------------------------------------------------* - * rc_get_bits2() - * - * Get number of bits needed to finalize range coder - *-------------------------------------------------------------------*/ - -Word16 rc_get_bits2_fx( /* o: Number of bits needed */ - const Word16 N, /* i: Number of bits currently used */ - const UWord32 range /* i: Range of range coder */ -) -{ - return add(add(N, 2), norm_ul(range)); -} - -void rangeCoderFinalizationFBits_fx( - Word16 Brc, - UWord32 INTrc, - Word16 *FBits -) -{ - Word32 L_Bq15; - UWord32 h, UL_tmp; - UWord16 Bq15ui16, l; - Word16 B, E, x, k; - *FBits = shl(add(Brc, 32), 3); - - B = sub(30, norm_ul(INTrc)); - x = sub(B, RCF_INIT_SHIFT ); - L_Bq15 = 0; - move16(); - if (x >= 0) - { - L_Bq15 = (Word32)UL_lshr(INTrc, x); - } - - E = 2; - move16(); - FOR(k = 1; k < 4; k++) - { - Bq15ui16 = u_extract_l(L_shr(L_Bq15, s_and(E, 1))); - UL_tmp = UL_lshl(UL_deposit_l(Bq15ui16), 1); - Mpy_32_16_uu(UL_tmp, Bq15ui16, &h , &l); - L_Bq15 = (Word32) h; - E = add(shl(B, 1), extract_l(L_lshr(L_sub(((1L << 16) - 1L), L_Bq15), 31))); - B = E; - move16(); - } - *FBits = sub(*FBits, B); - return; -} - diff --git a/src/libs/libevs/lib_com/re8_ppv.cpp b/src/libs/libevs/lib_com/re8_ppv.cpp new file mode 100644 index 00000000..1efb8738 --- /dev/null +++ b/src/libs/libevs/lib_com/re8_ppv.cpp @@ -0,0 +1,178 @@ +/*==================================================================================== + EVS Codec 3GPP TS26.443 Nov 13, 2018. Version 12.11.0 / 13.7.0 / 14.3.0 / 15.1.0 + ====================================================================================*/ + +#include "options.h" +#include "cnst.h" +#include "prot.h" + +/*-------------------------------------------------------------------* + * Local functions + *-------------------------------------------------------------------*/ + +static void nearest_neighbor_2D8(float x[], int y[]); + +/*--------------------------------------------------------------* + * re8_PPV() + * + * Nearest neighbor search in infinite lattice RE8 + * the algorithm is based on the definition of RE8 as + * RE8 = (2D8) U (2D8+[1,1,1,1,1,1,1,1]) + * it applies the coset decoding of Sloane and Conway + * --------------------------------------------------------------*/ + +void re8_PPV( + float x[], /* i : point in R^8 */ + int y[] /* o : point in RE8 (8-dimensional integer vector) */ +) +{ + int i,y0[8],y1[8]; + float e0,e1,x1[8],tmp; + + + /*--------------------------------------------------------------* + * find the nearest neighbor y0 of x in 2D8 + *--------------------------------------------------------------*/ + + nearest_neighbor_2D8(x, y0); + + /*--------------------------------------------------------------* + * find the nearest neighbor y1 of x in 2D8+(1,...,1) (by coset decoding) + *--------------------------------------------------------------*/ + + for (i=0; i<8; i++) + { + x1[i]=x[i]-1.0f; + } + + nearest_neighbor_2D8(x1, y1); + + for (i=0; i<8; i++) + { + y1[i]+=1; + } + + /*--------------------------------------------------------------* + * compute e0=||x-y0||^2 and e1=||x-y1||^2 + *--------------------------------------------------------------*/ + + e0=e1=0.0; + for (i=0; i<8; i++) + { + tmp = x[i]-y0[i]; + e0+=tmp*tmp; + tmp = x[i]-y1[i]; + e1+=tmp*tmp; + } + + /*--------------------------------------------------------------* + * select best candidate y0 or y1 to minimize distortion + *--------------------------------------------------------------*/ + + if (e0 0) */ + if (x[i] < 0) + { + y[i] = -2*(((int)(1.0-x[i]))>>1); + } + else + { + y[i] = 2*(((int)(1.0+x[i]))>>1); + } + sum += y[i]; + } + + /*--------------------------------------------------------------* + * check if y1+...+y8 is a multiple of 4 + * if not, y is not round xj in the wrong way where j is defined by + * j = arg max_i | xi -yi| + * (this is called the Wagner rule) + *--------------------------------------------------------------*/ + + if (sum%4) + { + /* find j = arg max_i | xi -yi| */ + em=0; + j=0; + for (i=0; i<8; i++) + { + /* compute ei = xi-yi */ + e[i]=x[i]-y[i]; + } + + for (i=0; i<8; i++) + { + /* compute |ei| = | xi-yi | */ + if (e[i]<0) + { + s=-e[i]; + } + else + { + s=e[i]; + } + /* check if |ei| is maximal, if so, set j=i */ + if (em 0) */ - tmp16 = round_fx(L_add(x[i], L_shr(x[i], 31))); - y[i] = shl(tmp16, 1); - move16(); - /* sum += y[i] */ - sum = add(sum, y[i]); - } - - /*--------------------------------------------------------------* - * check if y1+...+y8 is a multiple of 4 - * if not, y is not round xj in the wrong way where j is defined by - * j = arg max_i | xi -yi| - * (this is called the Wagner rule) - *--------------------------------------------------------------*/ - IF( s_and(sum, 2) != 0 ) - { - /* find j = arg max_i | xi -yi| */ - em = L_deposit_l(0); - j = 0; - move16(); - - FOR( i=0; i<8; i++ ) - { - /* compute ei = xi-yi */ - /* e[i]=x[i]-y[i] */ - e = L_msu(x[i], y[i], QR/2); - - /* compute |ei| = | xi-yi | */ - s = L_abs(e); - - /* check if |ei| is maximal, if so, set j=i */ - if( L_sub(em, s) < 0 ) - { - j = i; - move16(); - } - em = L_max(s, em); - } - - /* round xj in the "wrong way" */ - e = L_msu(x[j], y[j], QR/2); - tmp16 = extract_h(e); - tmp16b = add(y[j], 2); - - if( tmp16 < 0 ) - { - tmp16b = sub(tmp16b, 2+2); - } - y[j] = tmp16b; - move16(); - } - - return; -} - - -/*--------------------------------------------------------------* - * Compute_error_2D8(x,y) - * - * Compute mean square error between input vector and - * (quantized) point in 2D8. - --------------------------------------------------------------*/ - -static Word32 compute_error_2D8_fx( /* o : mean squared error */ - const Word32 x[], /* i : input vector */ - const Word16 y[] /* i : point in 2D8 (8-dimensional integer vector) */ -) -{ - Word16 i, hi, lo; - Word32 err, Ltmp; - - err = L_deposit_l(0); - FOR( i=0; i<8; i++ ) - { - /*tmp = x[i]-y[i];*/ - Ltmp = L_msu(x[i], y[i], 16384); - hi = extract_h(L_shl(Ltmp, 1)); - lo = extract_l(L_msu(Ltmp, hi, 16384)); - - Ltmp = L_mult(hi, hi); - Ltmp = L_shl(Ltmp, 14); - Ltmp = L_mac(Ltmp, hi, lo); - Ltmp = L_mac0(Ltmp, mult(lo, lo), 1); - - /* err+=tmp*tmp */ - err = L_add(Ltmp, err); - } - - return( err ); -} diff --git a/src/libs/libevs/lib_com/re8_util.cpp b/src/libs/libevs/lib_com/re8_util.cpp new file mode 100644 index 00000000..b58d1be1 --- /dev/null +++ b/src/libs/libevs/lib_com/re8_util.cpp @@ -0,0 +1,400 @@ +/*==================================================================================== + EVS Codec 3GPP TS26.443 Nov 13, 2018. Version 12.11.0 / 13.7.0 / 14.3.0 / 15.1.0 + ====================================================================================*/ + +#include "options.h" +#include "cnst.h" +#include "rom_com.h" +#include "prot.h" + + +/*-------------------------------------------------------------------* + * Local functions + *-------------------------------------------------------------------*/ + +static int re8_identify_absolute_leader(int y[]); +static void re8_coord(int y[], int k[]); + +/*----------------------------------------------------------------* + * re8_vor() + * + * Multi-rate RE8 indexing by Voronoi extension + *----------------------------------------------------------------*/ + +void re8_vor( + int y[], /* i : point in RE8 (8-dimensional integer vector) */ + int *n, /* o : codebook number n=0,2,3,4,... (scalar integer) */ + int k[], /* o : Voronoi index (integer vector of dimension 8) used only if n>4 */ + int c[], /* o : codevector in Q0, Q2, Q3, or Q4 if n<=4, y=c */ + int *ka /* o : identifier of absolute leader (needed to index c)*/ +) +{ + int i, r, m, v[8], c_tmp[8], k_mod[8], k_tmp[8], iter, ka_tmp, n_tmp, mask; + float sphere; + + + /*----------------------------------------------------------------* + * verify if y is in Q0, Q2, Q3 or Q4 + * (a fast search is used here: + * the codebooks Q0, Q2, Q3 or Q4 are specified in terms of RE8 absolute leaders + * (see FORinstance Xie and Adoul's paper in ICASSP 96) + * - a unique code identifying the absolute leader related to y is computed + * in re8_identify_absolute_leader() + * this code is searched FORin a pre-defined list which specifies Q0, Q2, Q3 or Q4) + * the absolute leader is identified by ka + * - a translation table maps ka to the codebook number n) + *----------------------------------------------------------------*/ + + *ka = re8_identify_absolute_leader( y ); + + /*----------------------------------------------------------------* + * compute codebook number n of Qn (by table look-up) + * at this stage, n=0,2,3,4 or out=100 + *----------------------------------------------------------------*/ + + *n = Da_nq[*ka]; + + /*----------------------------------------------------------------* + * decompose y into : + * (if n<=4:) + * y = c where c is in Q0, Q2, Q3 or Q4 + * or + * (if n>4:) + * y = m c + v where c is in Q3 or Q4, v is a Voronoi codevector + * m=2^r (r integer >=2) + * + * in the latter case (if n>4), as a side-product, compute the (Voronoi) index k[] of v + * and replace n by n = n' + 2r where n' = 3 or 4 (c is in Qn') and r is defined above + *----------------------------------------------------------------*/ + + if( *n <= 4 ) + { + for( i=0; i<8; i++ ) + { + c[i] = y[i]; + } + } + else + { + /*------------------------------------------------------------* + * initialize r and m=2^r based on || y ||^2/8 + *------------------------------------------------------------*/ + + sphere = 0.0; + for( i=0; i<8; i++ ) + { + sphere += (float)y[i]*(float)y[i]; + } + sphere *= 0.125; + r = 1; + sphere *= 0.25; /* not counted, merge 0.125*0.25 */ + while( sphere > 11.0 ) + { + r++; + sphere *= 0.25; + } + /*------------------------------------------------------------* + * compute the coordinates of y in the RE8 basis + *------------------------------------------------------------*/ + + re8_coord( y, k_mod ); + + /*------------------------------------------------------------* + * compute m and the mask needed for modulo m (for Voronoi coding) + *------------------------------------------------------------*/ + + m = 1< 4 ) + { + /*--------------------------------------------------------* + * if c is not in Q2, Q3, or Q4 (i.e. n_tmp>4), use m = 2^(r+1) instead of 2^r + *--------------------------------------------------------*/ + + r++; + m = m<<1; + mask = ((mask<<1)+1); /* mask = m-1; <- this is less complex */ + } + else + { + /*--------------------------------------------------------* + * c is in Q2, Q3, or Q4 -> the decomposition of y as y = m c + v is valid + * + * since Q2 is a subset of Q3, indicate n=3 instead of n=2 (this is because + * for n>4, n=n'+2r with n'=3 or 4, so n'=2 is not valid) + *--------------------------------------------------------*/ + + if( n_tmp < 3 ) + { + n_tmp = 3; + } + + /*--------------------------------------------------------* + * save current values into ka, n, k and c + *--------------------------------------------------------*/ + + *ka = ka_tmp; + *n = n_tmp + 2*r; + for (i=0; i<8; i++) + { + k[i] = k_tmp[i]; + c[i] = c_tmp[i]; + } + + /*--------------------------------------------------------* + * try m = 2^(r-1) instead of 2^r to be sure that m is minimal + *--------------------------------------------------------*/ + + r--; + m = m>>1; + mask = mask>>1; + } + } + } + + return; +} + +/*-----------------------------------------------------------------------* + * re8_identify_absolute_leader() + * + * Identify the absolute leader related to y using a pre-defined table which + * specifies the codebooks Q0, Q2, Q3 and Q4 + -----------------------------------------------------------------------*/ + +static int re8_identify_absolute_leader( /* o : integer indicating if y if in Q0, Q2, Q3 or Q4 (or if y is an outlier) */ + int y[] /* i : point in RE8 (8-dimensional integer vector) */ +) +{ + int i,s,id,C[8],nb,pos,ka; + long tmp; + + + /*-----------------------------------------------------------------------* + * compute the RE8 shell number s = (y1^2+...+y8^2)/8 and C=(y1^2, ..., y8^2) + *-----------------------------------------------------------------------*/ + + s = 0; + for( i=0; i<8; i++ ) + { + C[i] = y[i]*y[i]; + s += C[i]; + } + s >>= 3; + + /*-----------------------------------------------------------------------* + * compute the index 0 <= ka <= NB_LEADER+1 which identifies an absolute leader of Q0, Q2, Q3 or Q4 + * + * by default, ka=index of last element of the table (to indicate an outlier) + *-----------------------------------------------------------------------*/ + + ka = NB_LEADER+1; + if( s == 0 ) + { + /*-------------------------------------------------------------------* + * if s=0, y=0 i.e. y is in Q0 -> ka=index of element indicating Q0 + *-------------------------------------------------------------------*/ + + ka = NB_LEADER; + } + else + { + /*-------------------------------------------------------------------* + * the maximal value of s for y in Q0, Q2, Q3 or Q4 is NB_SPHERE + * if s> NB_SPHERE, y is an outlier (the value of ka is set correctly) + *-------------------------------------------------------------------*/ + + if( s <= NB_SPHERE ) + { + /*---------------------------------------------------------------* + * compute the unique identifier id of the absolute leader related to y: + * s = (y1^4 + ... + y8^4)/8 + *---------------------------------------------------------------*/ + + tmp = 0; + for( i=0; i<8; i++ ) + { + tmp += C[i]*C[i]; + } + id = (int)(tmp >> 3); + + /*---------------------------------------------------------------* + * search for id in table Da_id + * (containing all possible values of id if y is in Q2, Q3 or Q4) + * this search is focused based on the shell number s so that + * only the id's related to the shell of number s are checked + *---------------------------------------------------------------*/ + + nb = Da_nb[s-1]; /* get the number of absolute leaders used on the shell of number s */ + pos = Da_pos[s-1]; /* get the position of the first absolute leader of shell s in Da_id */ + for( i=0; i=1; i-- ) + { + /* apply factor 2/4 from M^-1 */ + k[i] = (y[i]-tmp)>>1; + sum -= y[i]; + } + + /* apply factor 1/4 from M^-1 */ + k[0] = (y[0]+sum)>>2; + + return; +} + + +/*------------------------------------------------------------------------- + * re8_k2y() + * + * Voronoi indexing (index decoding) k -> y + -----------------------------------------------------------------------*/ + +void re8_k2y( + const int *k, /* i : Voronoi index k[0..7] */ + const int m, /* i : Voronoi modulo (m = 2^r = 1<=2) */ + int *y /* o : 8-dimensional point y[0..7] in RE8 */ +) +{ + int i, v[8], tmp, sum, *ptr1, *ptr2; + float z[8]; + int lm=0; + + /*---------------------------------------------------------------* + * compute y = k M and z=(y-a)/m, where + * M = [4 ] + * [2 2 ] + * [| \ ] + * [2 2 ] + * [1 1 _ 1 1] + * a=(2,0,...,0) + *---------------------------------------------------------------*/ + + for (i=0; i<8; i++) + { + y[i] = k[7]; + } + + sum = 0; + for( i=6; i>=1; i-- ) + { + tmp = 2*k[i]; + sum += tmp; + y[i] += tmp; + } + y[0] += (4*k[0] + sum); + + /* find log2(m) */ + for (lm=0; lm<31; lm++) + { + if ((m>>lm)&0x0001) + { + break; + } + } + + z[0] = (float) ldexp(y[0] - 2, -lm); + for (i=1; i<8; i++) + { + z[i] = (float) ldexp(y[i], -lm); + } + + /*---------------------------------------------------------------* + * find nearest neighbor v of z in infinite RE8 + *---------------------------------------------------------------*/ + + re8_PPV( z, v ); + + /*---------------------------------------------------------------* + * compute y -= m v + *---------------------------------------------------------------*/ + + ptr1 = y; + ptr2 = v; + for( i=0; i<8; i++ ) + { + *ptr1++ -= m **ptr2++; + } + + return; +} diff --git a/src/libs/libevs/lib_com/re8_util_fx.cpp b/src/libs/libevs/lib_com/re8_util_fx.cpp deleted file mode 100755 index c6cab9d3..00000000 --- a/src/libs/libevs/lib_com/re8_util_fx.cpp +++ /dev/null @@ -1,387 +0,0 @@ -/*==================================================================================== - EVS Codec 3GPP TS26.442 Apr 03, 2018. Version 12.11.0 / 13.6.0 / 14.2.0 - ====================================================================================*/ - -#include "options.h" /* Compilation switches */ -#include "cnst_fx.h" /* Common constants */ -#include "rom_com_fx.h" /* Static table prototypes */ -#include "prot_fx.h" /* Function prototypes */ -#include "stl.h" - - -/*-------------------------------------------------------------------* - * Prototypes - *-------------------------------------------------------------------*/ - -static Word16 re8_identify_absolute_leader_fx( const Word16 y[] ); -static void re8_coord_fx( const Word16 *y, Word16 *k) ; - - -/*----------------------------------------------------------------* - * re8_vor_fx() - * - * MULTI-RATE RE8 INDEXING BY VORONOI EXTENSION - *----------------------------------------------------------------*/ -void re8_vor_fx( - const Word16 y[], /* i : point in RE8 (8-dimensional integer vector) */ - Word16 *n, /* o : codebook number n=0,2,3,4,... (scalar integer) */ - Word16 k[], /* o : Voronoi index (integer vector of dimension 8) used only if n>4*/ - Word16 c[], /* o : codevector in Q0, Q2, Q3, or Q4 if n<=4, y=c */ - Word16 *ka /* o : identifier of absolute leader (to index c) */ -) -{ - Word16 i, r, iter, ka_tmp, n_tmp, mask; - Word16 k_tmp[8], v[8], c_tmp[8], k_mod[8]; - Word32 Ltmp, Lsphere; - - /*----------------------------------------------------------------* - * verify if y is in Q0, Q2, Q3 or Q4 - * (a fast search is used here: - * the codebooks Q0, Q2, Q3 or Q4 are specified in terms of RE8 absolute leaders - * (see FORinstance Xie and Adoul's paper in ICASSP 96) - * - a unique code identifying the absolute leader related to y is computed - * in re8_identify_absolute_leader() - * this code is searched FORin a pre-defined list which specifies Q0, Q2, Q3 or Q4) - * the absolute leader is identified by ka - * - a translation table maps ka to the codebook number n) - *----------------------------------------------------------------*/ - *ka = re8_identify_absolute_leader_fx( y ); - move16(); - - /*----------------------------------------------------------------* - * compute codebook number n of Qn (by table look-up) - * at this stage, n=0,2,3,4 or out=100 - *----------------------------------------------------------------*/ - *n = Da_nq_fx[*ka]; - move16(); - - /*----------------------------------------------------------------* - * decompose y into : - * (if n<=4:) - * y = c where c is in Q0, Q2, Q3 or Q4 - * or - * (if n>4:) - * y = m c + v where c is in Q3 or Q4, v is a Voronoi codevector - * m=2^r (r integer >=2) - * - * in the latter case (if n>4), as a side-product, compute the (Voronoi) index k[] of v - * and replace n by n = n' + 2r where n' = 3 or 4 (c is in Qn') and r is defined above - *----------------------------------------------------------------*/ - - IF( sub(*n, 4) <= 0 ) - { - Copy( y, c, 8 ); - } - ELSE - { - /*------------------------------------------------------------* - * initialize r and m=2^r based on || y ||^2/8 - *------------------------------------------------------------*/ - Ltmp = L_mult(y[0], y[0]); - FOR( i = 1; i < 8; i++ ) - { - Ltmp = L_mac( Ltmp, y[i], y[i]); - } - - Lsphere = L_shr(Ltmp, 5+1); /* *0.125*0.25 / 2 to remove L_mac effect */ - - r = 1; - move16(); - FOR( ; Lsphere > 11; Lsphere >>= 2 ) - { - r = add(r, 1); - } - /*------------------------------------------------------------* - * compute the coordinates of y in the RE8 basis - *------------------------------------------------------------*/ - re8_coord_fx( y, k_mod ); - - /*------------------------------------------------------------* - * compute m and the mask needed for modulo m (for Voronoi coding) - *------------------------------------------------------------*/ - mask = sub(shl(1, r), 1); /* 0x0..011...1 */ - - /*------------------------------------------------------------* - * find the minimal value of r (or equivalently of m) in 2 iterations - *------------------------------------------------------------*/ - - FOR( iter=0; iter<2; iter++ ) - { - /*--------------------------------------------------------* - * compute v such that y is in m RE_8 +v (by Voronoi coding) - *--------------------------------------------------------*/ - FOR( i=0; i<8; i++ ) - { - k_tmp[i] = s_and( k_mod[i], mask); - move16(); - } - - re8_k2y_fx( k_tmp, r, v ); - - /*--------------------------------------------------------* - * compute c = (y-v)/m - * (y is in RE8, c is also in RE8 by definition of v) - *--------------------------------------------------------*/ - - FOR( i=0; i<8; i++ ) - { - c_tmp[i] = shr(sub(y[i], v[i]), r); - move16(); - } - - /*--------------------------------------------------------* - * verify if c_tmp is in Q2, Q3 or Q4 - *--------------------------------------------------------*/ - ka_tmp = re8_identify_absolute_leader_fx( c_tmp ); - - /*--------------------------------------------------------* - * at this stage, n_tmp=2,3,4 or out = 100 -- n=0 is not possible - *--------------------------------------------------------*/ - n_tmp = Da_nq_fx[ka_tmp]; - move16(); - - IF( sub(n_tmp, 4) > 0 ) - { - /*--------------------------------------------------------* - * if c is not in Q2, Q3, or Q4 (i.e. n_tmp>4), use m = 2^(r+1) instead of 2^r - *--------------------------------------------------------*/ - r = add(r, 1); - mask = add(shl(mask, 1), 1); /* mask = m-1 <- this is less complex */ - } - ELSE - { - /*--------------------------------------------------------* - * c is in Q2, Q3, or Q4 -> the decomposition of y as y = m c + v is valid - * - * since Q2 is a subset of Q3, indicate n=3 instead of n=2 (this is because - * for n>4, n=n'+2r with n'=3 or 4, so n'=2 is not valid) - *--------------------------------------------------------*/ - n_tmp = s_max(n_tmp, 3); - - /*--------------------------------------------------------* - * save current values into ka, n, k and c - *--------------------------------------------------------*/ - *ka = ka_tmp; - move16(); - *n = add(n_tmp, shl(r, 1)); - move16(); - Copy( k_tmp, k, 8 ); - Copy( c_tmp, c, 8 ); - - /*--------------------------------------------------------* - * try m = 2^(r-1) instead of 2^r to be sure that m is minimal - *--------------------------------------------------------*/ - r = sub(r, 1); - mask = shr(mask, 1); - } - } - } - - return; -} - - -/*------------------------------------------------------------------------- - * re8_k2y_fx() - * - * VORONOI INDEXING (INDEX DECODING) k -> y - -------------------------------------------------------------------------*/ -void re8_k2y_fx( - const Word16 *k, /* i : Voronoi index k[0..7] */ - const Word16 m, /* i : Voronoi modulo (m = 2^r = 1<=2) */ - Word16 *y /* o : 8-dimensional point y[0..7] in RE8 */ -) -{ - Word16 i, v[8], *ptr1, *ptr2, m_tmp, mm; - Word32 ytp[8], z[8], Ltmp, Lsum ; - - /*---------------------------------------------------------------* - * compute y = k M and z=(y-a)/m, where - * M = [4 ] - * [2 2 ] - * [| \ ] - * [2 2 ] - * [1 1 _ 1 1] - * a=(2,0,...,0) - *---------------------------------------------------------------*/ - m_tmp = sub(15, m); - - Lsum = L_deposit_l(k[7]); - ytp[7] = Lsum; - move32(); - z[7] = L_shl(Lsum, m_tmp); - move32(); /* (int)(floor(y[7]*QR+0.5))>>m */ - - FOR( i=6; i>=1; i-- ) - { - Ltmp = L_deposit_l( shl(k[i],1) ); - Lsum = L_add (Lsum, Ltmp); - ytp[i] = L_add(ytp[7], Ltmp); - move32(); - z[i] = L_shl(ytp[i], m_tmp); - move32(); /* (int)(floor(y[7]*QR+0.5))>>m */ - } - - Lsum = L_add( Lsum, L_deposit_l(shl(k[0],2) )); - ytp[0] = Lsum; - move32(); - z[0] = L_shl(L_sub(Lsum, 2), m_tmp); - move32(); /* (int)(floor(y[7]*QR+0.5))>>m */ - - /*---------------------------------------------------------------* - * find nearest neighbor v of z in infinite RE8 - *---------------------------------------------------------------*/ - re8_PPV_fx( z, v ); - - /*---------------------------------------------------------------* - * compute y -= m v - *---------------------------------------------------------------*/ - ptr1=y; - ptr2=v; - - mm = shr(shl(1, m), 1); /* shr to remove effect of L_mult in L_msu */ - - FOR( i=0; i<8; i++ ) - { - Ltmp = L_msu(ytp[i], *ptr2++, mm); - *ptr1++ = extract_l(Ltmp); - } - - return; -} - - -/*-----------------------------------------------------------------------* - * re8_identify_absolute_leader: - * - * IDENTIFY THE ABSOLUTE LEADER RELATED TO y USING A PRE-DEFINED TABLE WHICH - * SPECIFIES THE CODEBOOKS Q0, Q2, Q3 and Q4 - -----------------------------------------------------------------------*/ - -static Word16 re8_identify_absolute_leader_fx( /* o : integer indicating if y if in Q0, Q2, Q3 or Q4 (or if y is an outlier) */ - const Word16 y[] /* i : point in RE8 (8-dimensional integer vector) */ -) -{ - Word16 i,s,id,nb,pos,ka, tmp16; - Word32 Ltmp, Ls; - Word32 C; - const Word16 *ptr; - - /*-----------------------------------------------------------------------* - * compute the RE8 shell number s = (y1^2+...+y8^2)/8 and C=(y1^2, ..., y8^2) - *-----------------------------------------------------------------------*/ - Ls = L_mult(y[0], y[0]); - FOR( i = 1; i < 8; i++ ) - { - Ls = L_mac( Ls, y[i], y[i]); - } - s = extract_h(L_shl(Ls, 16-(3+1))); /* s can saturate here */ - - /*-----------------------------------------------------------------------* - * compute the index 0 <= ka <= NB_LEADER+1 which identifies an absolute leader of Q0, Q2, Q3 or Q4 - * - * by default, ka=index of last element of the table (to indicate an outlier) - *-----------------------------------------------------------------------*/ - /*-------------------------------------------------------------------* - * if s=0, y=0 i.e. y is in Q0 -> ka=index of element indicating Q0 - *-------------------------------------------------------------------*/ - ka = NB_LEADER; - move16(); - IF( s != 0 ) - { - ka = NB_LEADER+1; - move16(); - /*-------------------------------------------------------------------* - * the maximal value of s for y in Q0, Q2, Q3 or Q4 is NB_SPHERE - * if s> NB_SPHERE, y is an outlier (the value of ka is set correctly) - *-------------------------------------------------------------------*/ - IF( sub(s, NB_SPHERE) <= 0 ) - { - /*---------------------------------------------------------------* - * compute the unique identifier id of the absolute leader related to y: - * s = (y1^4 + ... + y8^4)/8 - *---------------------------------------------------------------*/ - C = L_mult(y[0], y[0]); - tmp16 = extract_h(L_shl(C, 16-1)); - Ltmp = L_mult(tmp16, tmp16); - FOR( i=1; i<8; i++ ) - { - C = L_mult(y[i], y[i]); - tmp16 = extract_h(L_shl(C, 16-1)); - Ltmp = L_mac(Ltmp, tmp16, tmp16); - } - id = extract_h(L_shl(Ltmp, 16-(3+1))); /* id can saturate to 8192 */ - - /*---------------------------------------------------------------* - * search for id in table Da_id - * (containing all possible values of id if y is in Q2, Q3 or Q4) - * this search is focused based on the shell number s so that - * only the id's related to the shell of number s are checked - *---------------------------------------------------------------*/ - - nb = Da_nb_fx[s - 1]; /* get the number of absolute leaders used on the shell of number s */ - pos = Da_pos_fx[s - 1]; /* get the position of the first absolute leader of shell s in Da_id */ - move16(); - move16(); - - ptr = &Da_id_fx[pos]; - move16(); - FOR( i=0; i=1; i-- ) - { - /* apply factor 2/4 from M^-1 */ - k[i] = shr(sub(y[i], tmp), 1); - move16(); - sum = sub(sum, y[i]); - } - /* apply factor 1/4 from M^-1 */ - k[0]= shr(add(y[0], sum), 2); - move16(); - - return; -} diff --git a/src/libs/libevs/lib_com/realft.cpp b/src/libs/libevs/lib_com/realft.cpp new file mode 100644 index 00000000..13956bd5 --- /dev/null +++ b/src/libs/libevs/lib_com/realft.cpp @@ -0,0 +1,164 @@ +/*==================================================================================== + EVS Codec 3GPP TS26.443 Nov 13, 2018. Version 12.11.0 / 13.7.0 / 14.3.0 / 15.1.0 + ====================================================================================*/ + +#include +#include "cnst.h" +#include "options.h" +#include "prot.h" + +/*-------------------------------------------------------------------* + * four1() + * + * From "numerical recipes in C". + * Replace data by its DFT, if isign is input as 1; or replace data + * by nn times its inverse-DFT, if isign is input as -1. + * data is a complex array of length nn, input as a real + * array data[1...2nn]. nn must be an integer power of 2 + *-------------------------------------------------------------------*/ + +static void four1( + float *data, /* i/o: data array .......... */ + short nn, /* i : length of data array */ + short isign /* i : sign +1 or -1 */ +) +{ + short n,mmax,m,j,istep,i; + float wtemp,wr,wpr,wpi,wi,theta; + float tempr,tempi; + + n=nn << 1; + j=1; + + /* this is the bit-reversal section of the routine */ + for (i=1; i i) + { + /* exchange the two complex numbers */ + SWAP(data[j],data[i]); + SWAP(data[j+1],data[i+1]); + } + m=n >> 1; + while (m >= 2 && j > m) + { + j -= m; + m >>= 1; + } + j += m; + } + mmax=2; + /* here begins the Danielson-Lanczos section of the routine */ + /* Outer loop executed log2(nn) times */ + while (n > mmax) + { + istep=2*mmax; + /* initialization for the trigonometric recurrence */ + theta=(float) (6.28318530717959/(isign*mmax)); + wtemp=(float) (sin(0.5f*theta)); + wpr = -2.0f*wtemp*wtemp; + wpi=(float) sin(theta); + wr=1.0f; + wi=0.0f; + /* here are the two nested loops */ + for (m=1; m 0) - q = add(q, shift); - *y++ = shl(x[0], shift); - move16(); - - FOR (i = 1; i < m; i++) - { - s = L_mult(x[i], a[0]); - /* Stop at i to Avoid Mults with Zeros */ - FOR (j = 1; j <= i; j++) - { - s = L_mac(s, x[i-j], a[j]); - } - - s = L_shl(s, q); - *y++ = round_fx(s); - } - - FOR (; i < lg; i++) - { - s = L_mult(x[i], a[0]); - FOR (j = 1; j <= m; j++) - { - s = L_mac(s, x[i-j], a[j]); - } - - s = L_shl(s, q); - *y++ = round_fx(s); - } -} - -/*--------------------------------------------------------------------* - * Residu3_10_fx: - * - * Compute the LP residual by filtering the input speech through A(z) - * Output is in Qx - *--------------------------------------------------------------------*/ -void Residu3_10_fx( - const Word16 a[], /* i : prediction coefficients Q12 */ - const Word16 x[], /* i : input signal (usually speech) Qx */ - /* (note that values x[-10..-1] are needed) */ - Word16 y[], /* o : output signal (usually residual) Qx */ - const Word16 lg, /* i : vector size Q0 */ - const Word16 shift -) -{ - Word16 i; - Word32 s; - Word16 q; - - q = add( norm_s(a[0]), 1 ); - if (shift != 0) - q = add(q, shift); - FOR (i = 0; i < lg; i++) - { - s = L_mult(x[i], a[0]); - s = L_mac(s, x[i-1], a[1]); - s = L_mac(s, x[i-2], a[2]); - s = L_mac(s, x[i-3], a[3]); - s = L_mac(s, x[i-4], a[4]); - s = L_mac(s, x[i-5], a[5]); - s = L_mac(s, x[i-6], a[6]); - s = L_mac(s, x[i-7], a[7]); - s = L_mac(s, x[i-8], a[8]); - s = L_mac(s, x[i-9], a[9]); - s = L_mac(s, x[i-10], a[10]); - - s = L_shl(s, q); - y[i] = round_fx(s); - } -} - -/*--------------------------------------------------------------------* - * Residu3_fx: - * - * Compute the LP residual by filtering the input speech through A(z) - * Output is in Qx - *--------------------------------------------------------------------*/ -void Residu3_fx( - const Word16 a[], /* i : prediction coefficients Q12 */ - const Word16 x[], /* i : input signal (usually speech) Qx */ - /* (note that values x[-M..-1] are needed) */ - Word16 y[], /* o : output signal (usually residual) Qx */ - const Word16 lg, /* i : vector size Q0 */ - const Word16 shift -) -{ - Word16 i; - Word32 s; - Word16 q; - - q = add( norm_s(a[0]), 1 ); - if (shift != 0) - q = add(q, shift); - FOR (i = 0; i < lg; i++) - { - s = L_mult(x[i], a[0]); - s = L_mac(s, x[i-1], a[1]); - s = L_mac(s, x[i-2], a[2]); - s = L_mac(s, x[i-3], a[3]); - s = L_mac(s, x[i-4], a[4]); - s = L_mac(s, x[i-5], a[5]); - s = L_mac(s, x[i-6], a[6]); - s = L_mac(s, x[i-7], a[7]); - s = L_mac(s, x[i-8], a[8]); - s = L_mac(s, x[i-9], a[9]); - s = L_mac(s, x[i-10], a[10]); - s = L_mac(s, x[i-11], a[11]); - s = L_mac(s, x[i-12], a[12]); - s = L_mac(s, x[i-13], a[13]); - s = L_mac(s, x[i-14], a[14]); - s = L_mac(s, x[i-15], a[15]); - s = L_mac(s, x[i-16], a[16]); - - s = L_shl(s, q); - y[i] = round_fx(s); - } -} - -/*==========================================================================*/ -/* FUNCTION : void calc_residu() */ -/*--------------------------------------------------------------------------*/ -/* PURPOSE : Compute the LP residual by filtering the input through */ -/* A(z) in all subframes */ -/*--------------------------------------------------------------------------*/ -/* INPUT ARGUMENTS : */ -/* Word16 *speech i : weighted speech signal Qx */ -/* Word16 L_frame i : order of LP filter Q0 */ -/* Word16 *p_Aq i : quantized LP filter coefficients Q12 */ -/*--------------------------------------------------------------------------*/ -/* OUTPUT ARGUMENTS : */ -/* Word16 *res o : residual signal Qx+1 */ -/*--------------------------------------------------------------------------*/ -/* INPUT/OUTPUT ARGUMENTS : */ -/*--------------------------------------------------------------------------*/ -/* RETURN ARGUMENTS : */ -/* _ None */ -/*--------------------------------------------------------------------------*/ -/* CALLED FROM : */ -/*==========================================================================*/ - -void calc_residu_fx( - Encoder_State_fx *st, /* i/o: state structure */ - const Word16 *speech, /* i : weighted speech signal */ - Word16 *res, /* o : residual signal */ - const Word16 *p_Aq, /* i : quantized LP filter coefficients */ - const Word16 vad_hover_flag -) -{ - Word16 i_subfr; - Word16 i; - Word16 att; - Word16 offset; - - FOR( i_subfr = 0; i_subfr < st->L_frame_fx; i_subfr += L_SUBFR ) - { - /* calculate the residual signal */ - Residu3_fx( p_Aq, &speech[i_subfr], &res[i_subfr], L_SUBFR, 1 ); - - /* next subframe */ - p_Aq += (M+1); - } - /* smoothing in case of CNG */ - test(); - IF( (st->Opt_DTX_ON_fx != 0 ) && (vad_hover_flag != 0) ) /* corresponds to line 504 in FLT acelp_core_enc.c */ - { - st->burst_ho_cnt_fx = add(st->burst_ho_cnt_fx,1); - st->burst_ho_cnt_fx = s_min(st->burst_ho_cnt_fx, HO_HIST_SIZE); - IF( sub(st->bwidth_fx, NB) != 0) - { - offset = 5; - test(); - if( sub(st->bwidth_fx, WB) == 0 && st->CNG_mode_fx >= 0 ) - { - offset = st->CNG_mode_fx; - move16(); - } - - att = CNG_burst_att_fx[offset][sub(st->burst_ho_cnt_fx,1)]; /*Q15*/ - - FOR( i = 0; i < st->L_frame_fx; i++ ) - { - res[i] = mult_r(res[i], att); - move16(); - } - } - } - ELSE - { - st->burst_ho_cnt_fx = 0; - move16(); - } - - return; -} - diff --git a/src/libs/libevs/lib_com/rom_basop_util.cpp b/src/libs/libevs/lib_com/rom_basop_util.cpp deleted file mode 100755 index 8a1f7d4b..00000000 --- a/src/libs/libevs/lib_com/rom_basop_util.cpp +++ /dev/null @@ -1,991 +0,0 @@ -/*==================================================================================== - EVS Codec 3GPP TS26.442 Apr 03, 2018. Version 12.11.0 / 13.6.0 / 14.2.0 - ====================================================================================*/ - -#include "rom_basop_util.h" -#include "stl.h" -#include -#include -#include "options.h" - - -/** - * \brief Lookup-Table for binary logarithm - */ -const Word16 ldCoeff[7] = -{ - -32768, -16384, -10923, -8192, -6554, -5461, -4681 - /* -4096, -3641, -3277 */ -}; - -/** - \brief Lookup-Table for binary power algorithm - - This table is used for lookup 2^x with - x in range [0...1.0[ in steps of 1/32 -*/ -const UWord32 exp2_tab_long[32] = -{ - 0x40000000,0x4166C34C,0x42D561B4,0x444C0740, - 0x45CAE0F2,0x47521CC6,0x48E1E9BA,0x4A7A77D4, - 0x4C1BF829,0x4DC69CDD,0x4F7A9930,0x51382182, - 0x52FF6B55,0x54D0AD5A,0x56AC1F75,0x5891FAC1, - 0x5A82799A,0x5C7DD7A4,0x5E8451D0,0x60962665, - 0x62B39509,0x64DCDEC3,0x6712460B,0x69540EC9, - 0x6BA27E65,0x6DFDDBCC,0x70666F76,0x72DC8374, - 0x75606374,0x77F25CCE,0x7A92BE8B,0x7D41D96E -}; - -/** - \brief Lookup-Table for binary power algorithm - - This table is used for lookup 2^x with - x in range [0...1/32[ in steps of 1/1024 -*/ -const UWord32 exp2w_tab_long[32] = -{ - 0x40000000,0x400B1818,0x4016321B,0x40214E0C, - 0x402C6BE9,0x40378BB4,0x4042AD6D,0x404DD113, - 0x4058F6A8,0x40641E2B,0x406F479E,0x407A7300, - 0x4085A051,0x4090CF92,0x409C00C4,0x40A733E6, - 0x40B268FA,0x40BD9FFF,0x40C8D8F5,0x40D413DD, - 0x40DF50B8,0x40EA8F86,0x40F5D046,0x410112FA, - 0x410C57A2,0x41179E3D,0x4122E6CD,0x412E3152, - 0x41397DCC,0x4144CC3B,0x41501CA0,0x415B6EFB -}; - -/** - \brief Lookup-Table for binary power algorithm - - This table is used for lookup 2^x with - x in range [0...1/1024[ in steps of 1/32768 -*/ -const UWord32 exp2x_tab_long[32] = -{ - 0x40000000,0x400058B9,0x4000B173,0x40010A2D, - 0x400162E8,0x4001BBA3,0x4002145F,0x40026D1B, - 0x4002C5D8,0x40031E95,0x40037752,0x4003D011, - 0x400428CF,0x4004818E,0x4004DA4E,0x4005330E, - 0x40058BCE,0x4005E48F,0x40063D51,0x40069613, - 0x4006EED5,0x40074798,0x4007A05B,0x4007F91F, - 0x400851E4,0x4008AAA8,0x4009036E,0x40095C33, - 0x4009B4FA,0x400A0DC0,0x400A6688,0x400ABF4F -}; - -/* square root tables */ -const Word32 SqrtTable[32] = /* Q31 */ -{ - 0x5A82D429, 0x5BEA10FE, 0x5D4BE6E5, 0x5EA89270, 0x60004BE2, 0x615347A1, 0x62A1B68C, 0x63EBC651, - 0x6531A1B5, 0x667370D4, 0x67B1595F, 0x68EB7EC8, 0x6A220277, 0x6B5503F0, 0x6C84A0F9, 0x6DB0F5BD, - 0x6EDA1CE9, 0x70002FC7, 0x7123465A, 0x72437773, 0x7360D8C5, 0x747B7EFA, 0x75937DC4, 0x76A8E7EB, - 0x77BBCF60, 0x78CC4545, 0x79DA5A00, 0x7AE61D3E, 0x7BEF9E07, 0x7CF6EAC2, 0x7DFC113F, 0x7EFF1EC0 -}; - -const Word16 SqrtDiffTable[32] = /* Q21 */ -{ - 0x59CF, 0x5875, 0x572B, 0x55EE, 0x54BF, 0x539C, 0x5284, 0x5177, - 0x5074, 0x4F7A, 0x4E89, 0x4DA1, 0x4CC0, 0x4BE7, 0x4B15, 0x4A4A, - 0x4985, 0x48C6, 0x480C, 0x4758, 0x46AA, 0x4600, 0x455B, 0x44BA, - 0x441D, 0x4385, 0x42F1, 0x4260, 0x41D3, 0x414A, 0x40C3, 0x4040 -}; - - -const Word32 ISqrtTable[32] = /* Q31 */ -{ - 0x7FFE7F85, 0x7E0A4E25, 0x7C2C56C7, 0x7A63002C, 0x78ACD922, 0x7708939D, 0x75750088, 0x73F10C2D, - 0x727BBB1A, 0x71142774, 0x6FB97EA5, 0x6E6AFF54, 0x6D27F79D, 0x6BEFC388, 0x6AC1CBA4, 0x699D83DA, - 0x68826A53, 0x6770068E, 0x6665E882, 0x6563A7DF, 0x6468E364, 0x63754043, 0x62886999, 0x61A20FEE, - 0x60C1E8C8, 0x5FE7AE45, 0x5F131EBE, 0x5E43FC76, 0x5D7A0D4F, 0x5CB51A81, 0x5BF4F061, 0x5B395E26 -}; - -const Word16 ISqrtDiffTable[32] = /* Q21 */ -{ - 0x7D0C, 0x777E, 0x7256, 0x6D8A, 0x6911, 0x64E5, 0x60FD, 0x5D54, - 0x59E5, 0x56AA, 0x53A0, 0x50C2, 0x4E0D, 0x4B7E, 0x4912, 0x46C6, - 0x4499, 0x4288, 0x4090, 0x3EB1, 0x3CE9, 0x3B36, 0x3996, 0x380A, - 0x368F, 0x3524, 0x33C9, 0x327C, 0x313D, 0x300B, 0x2EE5, 0x2DCA -}; - -/* 1/x tables */ -const Word32 InvTable[32] = /* Q31 */ -{ - 0x7FFBFE40, 0x7C1B608E, 0x78752176, 0x750440BA, 0x71C44C49, 0x6EB14D0A, 0x6BC7B6B4, 0x69045A19, - 0x6664598A, 0x63E51EE2, 0x61845308, 0x5F3FD698, 0x5D15BB8E, 0x5B043FD0, 0x5909C861, 0x5724DD3C, - 0x555425B2, 0x53966532, 0x51EA787F, 0x504F5331, 0x4EC3FD84, 0x4D479267, 0x4BD93DBE, 0x4A783ADC, - 0x4923D31D, 0x47DB5CAE, 0x469E3974, 0x456BD608, 0x4443A8D9, 0x43253159, 0x420FF746, 0x41038A01 -}; - -/* inverse integer (1/i) */ -const Word16 InvIntTable[65] = -{ - 0x7FFF, - 0x7FFF, 0x4000, 0x2AAB, 0x2000, 0x199A, 0x1555, 0x1249, 0x1000, - 0x0E39, 0x0CCD, 0x0BA3, 0x0AAB, 0x09D9, 0x0925, 0x0889, 0x0800, - 0x0788, 0x071C, 0x06BD, 0x0666, 0x0618, 0x05D1, 0x0591, 0x0555, - 0x051F, 0x04EC, 0x04BE, 0x0492, 0x046A, 0x0444, 0x0421, 0x0400, - 0x03E1, 0x03C4, 0x03A8, 0x038E, 0x0376, 0x035E, 0x0348, 0x0333, - 0x031F, 0x030C, 0x02FA, 0x02E9, 0x02D8, 0x02C8, 0x02B9, 0x02AB, - 0x029D, 0x028F, 0x0283, 0x0276, 0x026A, 0x025F, 0x0254, 0x0249, - 0x023F, 0x0235, 0x022B, 0x0222, 0x0219, 0x0211, 0x0208, 0x0200 -}; - -const Word16 InvDiffTable[32] = /* Q20 */ -{ - 0x7C14, 0x74C8, 0x6E1C, 0x67FF, 0x6260, 0x5D33, 0x586C, 0x5400, - 0x4FE7, 0x4C19, 0x4890, 0x4543, 0x422F, 0x3F4F, 0x3C9D, 0x3A17, - 0x37B8, 0x357E, 0x3365, 0x316B, 0x2F8D, 0x2DCB, 0x2C20, 0x2A8D, - 0x290F, 0x27A4, 0x264C, 0x2506, 0x23CF, 0x22A7, 0x218E, 0x2081 -}; - -const Word32 BASOP_util_normReciprocal[CHEAP_NORM_SIZE] = -{ - 0l/*0.0 Q31*/, 2147483647l/*1.0000000000 Q31*/, 1073741824l/*0.5000000000 Q31*/, 715827883l/*0.3333333333 Q31*/, 536870912l/*0.2500000000 Q31*/, 429496730l/*0.2000000000 Q31*/, - 357913941l/*0.1666666667 Q31*/, 306783378l/*0.1428571429 Q31*/, 268435456l/*0.1250000000 Q31*/, 238609294l/*0.1111111111 Q31*/, 214748365l/*0.1000000000 Q31*/, 195225786l/*0.0909090909 Q31*/, - 178956971l/*0.0833333333 Q31*/, 165191050l/*0.0769230769 Q31*/, 153391689l/*0.0714285714 Q31*/, 143165577l/*0.0666666667 Q31*/, 134217728l/*0.0625000000 Q31*/, 126322568l/*0.0588235294 Q31*/, - 119304647l/*0.0555555556 Q31*/, 113025455l/*0.0526315789 Q31*/, 107374182l/*0.0500000000 Q31*/, 102261126l/*0.0476190476 Q31*/, 97612893l/*0.0454545455 Q31*/, 93368854l/*0.0434782609 Q31*/, - 89478485l/*0.0416666667 Q31*/, 85899346l/*0.0400000000 Q31*/, 82595525l/*0.0384615385 Q31*/, 79536431l/*0.0370370370 Q31*/, 76695845l/*0.0357142857 Q31*/, 74051160l/*0.0344827586 Q31*/, - 71582788l/*0.0333333333 Q31*/, 69273666l/*0.0322580645 Q31*/, 67108864l/*0.0312500000 Q31*/, 65075262l/*0.0303030303 Q31*/, 63161284l/*0.0294117647 Q31*/, 61356676l/*0.0285714286 Q31*/, - 59652324l/*0.0277777778 Q31*/, 58040099l/*0.0270270270 Q31*/, 56512728l/*0.0263157895 Q31*/, 55063683l/*0.0256410256 Q31*/, 53687091l/*0.0250000000 Q31*/, 52377650l/*0.0243902439 Q31*/, - 51130563l/*0.0238095238 Q31*/, 49941480l/*0.0232558140 Q31*/, 48806446l/*0.0227272727 Q31*/, 47721859l/*0.0222222222 Q31*/, 46684427l/*0.0217391304 Q31*/, 45691141l/*0.0212765957 Q31*/, - 44739243l/*0.0208333333 Q31*/, 43826197l/*0.0204081633 Q31*/, 42949673l/*0.0200000000 Q31*/, 42107522l/*0.0196078431 Q31*/, 41297762l/*0.0192307692 Q31*/, 40518559l/*0.0188679245 Q31*/, - 39768216l/*0.0185185185 Q31*/, 39045157l/*0.0181818182 Q31*/, 38347922l/*0.0178571429 Q31*/, 37675152l/*0.0175438596 Q31*/, 37025580l/*0.0172413793 Q31*/, 36398028l/*0.0169491525 Q31*/, - 35791394l/*0.0166666667 Q31*/, 35204650l/*0.0163934426 Q31*/, 34636833l/*0.0161290323 Q31*/, 34087042l/*0.0158730159 Q31*/, 33554432l/*0.0156250000 Q31*/, 33038210l/*0.0153846154 Q31*/, - 32537631l/*0.0151515152 Q31*/, 32051995l/*0.0149253731 Q31*/, 31580642l/*0.0147058824 Q31*/, 31122951l/*0.0144927536 Q31*/, 30678338l/*0.0142857143 Q31*/, 30246248l/*0.0140845070 Q31*/, - 29826162l/*0.0138888889 Q31*/, 29417584l/*0.0136986301 Q31*/, 29020049l/*0.0135135135 Q31*/, 28633115l/*0.0133333333 Q31*/, 28256364l/*0.0131578947 Q31*/, 27889398l/*0.0129870130 Q31*/, - 27531842l/*0.0128205128 Q31*/, 27183337l/*0.0126582278 Q31*/, 26843546l/*0.0125000000 Q31*/, 26512144l/*0.0123456790 Q31*/, 26188825l/*0.0121951220 Q31*/, 25873297l/*0.0120481928 Q31*/, - 25565282l/*0.0119047619 Q31*/, 25264514l/*0.0117647059 Q31*/, 24970740l/*0.0116279070 Q31*/, 24683720l/*0.0114942529 Q31*/, 24403223l/*0.0113636364 Q31*/, 24129030l/*0.0112359551 Q31*/, - 23860929l/*0.0111111111 Q31*/, 23598721l/*0.0109890110 Q31*/, 23342214l/*0.0108695652 Q31*/, 23091222l/*0.0107526882 Q31*/, 22845571l/*0.0106382979 Q31*/, 22605091l/*0.0105263158 Q31*/, - 22369621l/*0.0104166667 Q31*/, 22139007l/*0.0103092784 Q31*/, 21913098l/*0.0102040816 Q31*/, 21691754l/*0.0101010101 Q31*/, 21474836l/*0.0100000000 Q31*/, 21262214l/*0.0099009901 Q31*/, - 21053761l/*0.0098039216 Q31*/, 20849356l/*0.0097087379 Q31*/, 20648881l/*0.0096153846 Q31*/, 20452225l/*0.0095238095 Q31*/, 20259280l/*0.0094339623 Q31*/, 20069941l/*0.0093457944 Q31*/, - 19884108l/*0.0092592593 Q31*/, 19701685l/*0.0091743119 Q31*/, 19522579l/*0.0090909091 Q31*/, 19346700l/*0.0090090090 Q31*/, 19173961l/*0.0089285714 Q31*/, 19004280l/*0.0088495575 Q31*/, - 18837576l/*0.0087719298 Q31*/, 18673771l/*0.0086956522 Q31*/, 18512790l/*0.0086206897 Q31*/, 18354561l/*0.0085470085 Q31*/, 18199014l/*0.0084745763 Q31*/, 18046081l/*0.0084033613 Q31*/, - 17895697l/*0.0083333333 Q31*/, 17747799l/*0.0082644628 Q31*/, 17602325l/*0.0081967213 Q31*/, 17459217l/*0.0081300813 Q31*/, 17318416l/*0.0080645161 Q31*/, 17179869l/*0.0080000000 Q31*/, - 17043521l/*0.0079365079 Q31*/, 16909320l/*0.0078740157 Q31*/, 16777216l/*0.0078125000 Q31*/, 16647160l/*0.0077519380 Q31*/, 16519105l/*0.0076923077 Q31*/, 16393005l/*0.0076335878 Q31*/, - 16268816l/*0.0075757576 Q31*/, 16146494l/*0.0075187970 Q31*/, 16025997l/*0.0074626866 Q31*/, 15907286l/*0.0074074074 Q31*/, 15790321l/*0.0073529412 Q31*/, 15675063l/*0.0072992701 Q31*/, - 15561476l/*0.0072463768 Q31*/, 15449523l/*0.0071942446 Q31*/, 15339169l/*0.0071428571 Q31*/, 15230381l/*0.0070921986 Q31*/, 15123124l/*0.0070422535 Q31*/, 15017368l/*0.0069930070 Q31*/, - 14913081l/*0.0069444444 Q31*/, 14810232l/*0.0068965517 Q31*/, 14708792l/*0.0068493151 Q31*/, 14608732l/*0.0068027211 Q31*/, 14510025l/*0.0067567568 Q31*/, 14412642l/*0.0067114094 Q31*/, - 14316558l/*0.0066666667 Q31*/, 14221746l/*0.0066225166 Q31*/, 14128182l/*0.0065789474 Q31*/, 14035841l/*0.0065359477 Q31*/, 13944699l/*0.0064935065 Q31*/, 13854733l/*0.0064516129 Q31*/, - 13765921l/*0.0064102564 Q31*/, 13678240l/*0.0063694268 Q31*/, 13591669l/*0.0063291139 Q31*/, 13506187l/*0.0062893082 Q31*/, 13421773l/*0.0062500000 Q31*/ -}; - -const Word16 f_atan_expand_range[MAXSFTAB-(MINSFTAB-1)] = -{ - /***************************************************************************** - * - * Table holds fixp_atan() output values which are outside of input range - * of fixp_atan() to improve SNR of fixp_atan2(). - * - * This Table might also be used in fixp_atan() [todo] so there a wider input - * range can be covered, too. - * - * Matlab (generate table): - * for scl = 7:25 % MINSFTAB .. MAXSFTAB - * at=atan(0.5 *(2^scl)); % 0.5 because get in 'middle' area of current scale level 'scl' - * at/2 % div at by ATO_SCALE - * end - * - * Table divided by 2=ATO_SCALE <-- SF=ATO_SF - *****************************************************************************/ - 25480/*7.775862990872099e-001 Q15*/, 25608/*7.814919928673978e-001 Q15*/, 25672/*7.834450483314648e-001 Q15*/, - 25704/*7.844216021392089e-001 Q15*/, 25720/*7.849098823026687e-001 Q15*/, 25728/*7.851540227918509e-001 Q15*/, - 25732/*7.852760930873737e-001 Q15*/, 25734/*7.853371282415015e-001 Q15*/, 25735/*7.853676458193612e-001 Q15*/, - 25735/*7.853829046083906e-001 Q15*/, 25736/*7.853905340029177e-001 Q15*/, 25736/*7.853943487001828e-001 Q15*/, - 25736/*7.853962560488155e-001 Q15*/, 25736/*7.853972097231319e-001 Q15*/, 25736/*7.853976865602901e-001 Q15*/, - 25736/*7.853979249788692e-001 Q15*/, 25736/*7.853980441881587e-001 Q15*/, 25736/*7.853981037928035e-001 Q15*/, - 25736/*7.853981335951259e-001 Q15*/ - /* pi/4 = 0.785398163397448 = pi/2/ATO_SCALE */ -}; - - -/* - Sine tables - */ -#define STC(x) WORD322WORD16(x) - -/* #define STCP(a,b) (((Word32)STC(b)<<16) | STC(a)) */ -#define STCP(a,b) { { STC(a), STC(b) } } - -const PWord16 SineTable512[] = -{ - STCP(0x7fffffff, 0x00000000), STCP(0x7fffd886, 0x006487e3), STCP(0x7fff6216, 0x00c90f88), STCP(0x7ffe9cb2, 0x012d96b1), - STCP(0x7ffd885a, 0x01921d20), STCP(0x7ffc250f, 0x01f6a297), STCP(0x7ffa72d1, 0x025b26d7), STCP(0x7ff871a2, 0x02bfa9a4), - STCP(0x7ff62182, 0x03242abf), STCP(0x7ff38274, 0x0388a9ea), STCP(0x7ff09478, 0x03ed26e6), STCP(0x7fed5791, 0x0451a177), - STCP(0x7fe9cbc0, 0x04b6195d), STCP(0x7fe5f108, 0x051a8e5c), STCP(0x7fe1c76b, 0x057f0035), STCP(0x7fdd4eec, 0x05e36ea9), - STCP(0x7fd8878e, 0x0647d97c), STCP(0x7fd37153, 0x06ac406f), STCP(0x7fce0c3e, 0x0710a345), STCP(0x7fc85854, 0x077501be), - STCP(0x7fc25596, 0x07d95b9e), STCP(0x7fbc040a, 0x083db0a7), STCP(0x7fb563b3, 0x08a2009a), STCP(0x7fae7495, 0x09064b3a), - STCP(0x7fa736b4, 0x096a9049), STCP(0x7f9faa15, 0x09cecf89), STCP(0x7f97cebd, 0x0a3308bd), STCP(0x7f8fa4b0, 0x0a973ba5), - STCP(0x7f872bf3, 0x0afb6805), STCP(0x7f7e648c, 0x0b5f8d9f), STCP(0x7f754e80, 0x0bc3ac35), STCP(0x7f6be9d4, 0x0c27c389), - STCP(0x7f62368f, 0x0c8bd35e), STCP(0x7f5834b7, 0x0cefdb76), STCP(0x7f4de451, 0x0d53db92), STCP(0x7f434563, 0x0db7d376), - STCP(0x7f3857f6, 0x0e1bc2e4), STCP(0x7f2d1c0e, 0x0e7fa99e), STCP(0x7f2191b4, 0x0ee38766), STCP(0x7f15b8ee, 0x0f475bff), - STCP(0x7f0991c4, 0x0fab272b), STCP(0x7efd1c3c, 0x100ee8ad), STCP(0x7ef05860, 0x1072a048), STCP(0x7ee34636, 0x10d64dbd), - STCP(0x7ed5e5c6, 0x1139f0cf), STCP(0x7ec8371a, 0x119d8941), STCP(0x7eba3a39, 0x120116d5), STCP(0x7eabef2c, 0x1264994e), - STCP(0x7e9d55fc, 0x12c8106f), STCP(0x7e8e6eb2, 0x132b7bf9), STCP(0x7e7f3957, 0x138edbb1), STCP(0x7e6fb5f4, 0x13f22f58), - STCP(0x7e5fe493, 0x145576b1), STCP(0x7e4fc53e, 0x14b8b17f), STCP(0x7e3f57ff, 0x151bdf86), STCP(0x7e2e9cdf, 0x157f0086), - STCP(0x7e1d93ea, 0x15e21445), STCP(0x7e0c3d29, 0x16451a83), STCP(0x7dfa98a8, 0x16a81305), STCP(0x7de8a670, 0x170afd8d), - STCP(0x7dd6668f, 0x176dd9de), STCP(0x7dc3d90d, 0x17d0a7bc), STCP(0x7db0fdf8, 0x183366e9), STCP(0x7d9dd55a, 0x18961728), - STCP(0x7d8a5f40, 0x18f8b83c), STCP(0x7d769bb5, 0x195b49ea), STCP(0x7d628ac6, 0x19bdcbf3), STCP(0x7d4e2c7f, 0x1a203e1b), - STCP(0x7d3980ec, 0x1a82a026), STCP(0x7d24881b, 0x1ae4f1d6), STCP(0x7d0f4218, 0x1b4732ef), STCP(0x7cf9aef0, 0x1ba96335), - STCP(0x7ce3ceb2, 0x1c0b826a), STCP(0x7ccda169, 0x1c6d9053), STCP(0x7cb72724, 0x1ccf8cb3), STCP(0x7ca05ff1, 0x1d31774d), - STCP(0x7c894bde, 0x1d934fe5), STCP(0x7c71eaf9, 0x1df5163f), STCP(0x7c5a3d50, 0x1e56ca1e), STCP(0x7c4242f2, 0x1eb86b46), - STCP(0x7c29fbee, 0x1f19f97b), STCP(0x7c116853, 0x1f7b7481), STCP(0x7bf88830, 0x1fdcdc1b), STCP(0x7bdf5b94, 0x203e300d), - STCP(0x7bc5e290, 0x209f701c), STCP(0x7bac1d31, 0x21009c0c), STCP(0x7b920b89, 0x2161b3a0), STCP(0x7b77ada8, 0x21c2b69c), - STCP(0x7b5d039e, 0x2223a4c5), STCP(0x7b420d7a, 0x22847de0), STCP(0x7b26cb4f, 0x22e541af), STCP(0x7b0b3d2c, 0x2345eff8), - STCP(0x7aef6323, 0x23a6887f), STCP(0x7ad33d45, 0x24070b08), STCP(0x7ab6cba4, 0x24677758), STCP(0x7a9a0e50, 0x24c7cd33), - STCP(0x7a7d055b, 0x25280c5e), STCP(0x7a5fb0d8, 0x2588349d), STCP(0x7a4210d8, 0x25e845b6), STCP(0x7a24256f, 0x26483f6c), - STCP(0x7a05eead, 0x26a82186), STCP(0x79e76ca7, 0x2707ebc7), STCP(0x79c89f6e, 0x27679df4), STCP(0x79a98715, 0x27c737d3), - STCP(0x798a23b1, 0x2826b928), STCP(0x796a7554, 0x288621b9), STCP(0x794a7c12, 0x28e5714b), STCP(0x792a37fe, 0x2944a7a2), - STCP(0x7909a92d, 0x29a3c485), STCP(0x78e8cfb2, 0x2a02c7b8), STCP(0x78c7aba2, 0x2a61b101), STCP(0x78a63d11, 0x2ac08026), - STCP(0x78848414, 0x2b1f34eb), STCP(0x786280bf, 0x2b7dcf17), STCP(0x78403329, 0x2bdc4e6f), STCP(0x781d9b65, 0x2c3ab2b9), - STCP(0x77fab989, 0x2c98fbba), STCP(0x77d78daa, 0x2cf72939), STCP(0x77b417df, 0x2d553afc), STCP(0x7790583e, 0x2db330c7), - STCP(0x776c4edb, 0x2e110a62), STCP(0x7747fbce, 0x2e6ec792), STCP(0x77235f2d, 0x2ecc681e), STCP(0x76fe790e, 0x2f29ebcc), - STCP(0x76d94989, 0x2f875262), STCP(0x76b3d0b4, 0x2fe49ba7), STCP(0x768e0ea6, 0x3041c761), STCP(0x76680376, 0x309ed556), - STCP(0x7641af3d, 0x30fbc54d), STCP(0x761b1211, 0x3158970e), STCP(0x75f42c0b, 0x31b54a5e), STCP(0x75ccfd42, 0x3211df04), - STCP(0x75a585cf, 0x326e54c7), STCP(0x757dc5ca, 0x32caab6f), STCP(0x7555bd4c, 0x3326e2c3), STCP(0x752d6c6c, 0x3382fa88), - STCP(0x7504d345, 0x33def287), STCP(0x74dbf1ef, 0x343aca87), STCP(0x74b2c884, 0x34968250), STCP(0x7489571c, 0x34f219a8), - STCP(0x745f9dd1, 0x354d9057), STCP(0x74359cbd, 0x35a8e625), STCP(0x740b53fb, 0x36041ad9), STCP(0x73e0c3a3, 0x365f2e3b), - STCP(0x73b5ebd1, 0x36ba2014), STCP(0x738acc9e, 0x3714f02a), STCP(0x735f6626, 0x376f9e46), STCP(0x7333b883, 0x37ca2a30), - STCP(0x7307c3d0, 0x382493b0), STCP(0x72db8828, 0x387eda8e), STCP(0x72af05a7, 0x38d8fe93), STCP(0x72823c67, 0x3932ff87), - STCP(0x72552c85, 0x398cdd32), STCP(0x7227d61c, 0x39e6975e), STCP(0x71fa3949, 0x3a402dd2), STCP(0x71cc5626, 0x3a99a057), - STCP(0x719e2cd2, 0x3af2eeb7), STCP(0x716fbd68, 0x3b4c18ba), STCP(0x71410805, 0x3ba51e29), STCP(0x71120cc5, 0x3bfdfecd), - STCP(0x70e2cbc6, 0x3c56ba70), STCP(0x70b34525, 0x3caf50da), STCP(0x708378ff, 0x3d07c1d6), STCP(0x70536771, 0x3d600d2c), - STCP(0x7023109a, 0x3db832a6), STCP(0x6ff27497, 0x3e10320d), STCP(0x6fc19385, 0x3e680b2c), STCP(0x6f906d84, 0x3ebfbdcd), - STCP(0x6f5f02b2, 0x3f1749b8), STCP(0x6f2d532c, 0x3f6eaeb8), STCP(0x6efb5f12, 0x3fc5ec98), STCP(0x6ec92683, 0x401d0321), - STCP(0x6e96a99d, 0x4073f21d), STCP(0x6e63e87f, 0x40cab958), STCP(0x6e30e34a, 0x4121589b), STCP(0x6dfd9a1c, 0x4177cfb1), - STCP(0x6dca0d14, 0x41ce1e65), STCP(0x6d963c54, 0x42244481), STCP(0x6d6227fa, 0x427a41d0), STCP(0x6d2dd027, 0x42d0161e), - STCP(0x6cf934fc, 0x4325c135), STCP(0x6cc45698, 0x437b42e1), STCP(0x6c8f351c, 0x43d09aed), STCP(0x6c59d0a9, 0x4425c923), - STCP(0x6c242960, 0x447acd50), STCP(0x6bee3f62, 0x44cfa740), STCP(0x6bb812d1, 0x452456bd), STCP(0x6b81a3cd, 0x4578db93), - STCP(0x6b4af279, 0x45cd358f), STCP(0x6b13fef5, 0x4621647d), STCP(0x6adcc964, 0x46756828), STCP(0x6aa551e9, 0x46c9405c), - STCP(0x6a6d98a4, 0x471cece7), STCP(0x6a359db9, 0x47706d93), STCP(0x69fd614a, 0x47c3c22f), STCP(0x69c4e37a, 0x4816ea86), - STCP(0x698c246c, 0x4869e665), STCP(0x69532442, 0x48bcb599), STCP(0x6919e320, 0x490f57ee), STCP(0x68e06129, 0x4961cd33), - STCP(0x68a69e81, 0x49b41533), STCP(0x686c9b4b, 0x4a062fbd), STCP(0x683257ab, 0x4a581c9e), STCP(0x67f7d3c5, 0x4aa9dba2), - STCP(0x67bd0fbd, 0x4afb6c98), STCP(0x67820bb7, 0x4b4ccf4d), STCP(0x6746c7d8, 0x4b9e0390), STCP(0x670b4444, 0x4bef092d), - STCP(0x66cf8120, 0x4c3fdff4), STCP(0x66937e91, 0x4c9087b1), STCP(0x66573cbb, 0x4ce10034), STCP(0x661abbc5, 0x4d31494b), - STCP(0x65ddfbd3, 0x4d8162c4), STCP(0x65a0fd0b, 0x4dd14c6e), STCP(0x6563bf92, 0x4e210617), STCP(0x6526438f, 0x4e708f8f), - STCP(0x64e88926, 0x4ebfe8a5), STCP(0x64aa907f, 0x4f0f1126), STCP(0x646c59bf, 0x4f5e08e3), STCP(0x642de50d, 0x4faccfab), - STCP(0x63ef3290, 0x4ffb654d), STCP(0x63b0426d, 0x5049c999), STCP(0x637114cc, 0x5097fc5e), STCP(0x6331a9d4, 0x50e5fd6d), - STCP(0x62f201ac, 0x5133cc94), STCP(0x62b21c7b, 0x518169a5), STCP(0x6271fa69, 0x51ced46e), STCP(0x62319b9d, 0x521c0cc2), - STCP(0x61f1003f, 0x5269126e), STCP(0x61b02876, 0x52b5e546), STCP(0x616f146c, 0x53028518), STCP(0x612dc447, 0x534ef1b5), - STCP(0x60ec3830, 0x539b2af0), STCP(0x60aa7050, 0x53e73097), STCP(0x60686ccf, 0x5433027d), STCP(0x60262dd6, 0x547ea073), - STCP(0x5fe3b38d, 0x54ca0a4b), STCP(0x5fa0fe1f, 0x55153fd4), STCP(0x5f5e0db3, 0x556040e2), STCP(0x5f1ae274, 0x55ab0d46), - STCP(0x5ed77c8a, 0x55f5a4d2), STCP(0x5e93dc1f, 0x56400758), STCP(0x5e50015d, 0x568a34a9), STCP(0x5e0bec6e, 0x56d42c99), - STCP(0x5dc79d7c, 0x571deefa), STCP(0x5d8314b1, 0x57677b9d), STCP(0x5d3e5237, 0x57b0d256), STCP(0x5cf95638, 0x57f9f2f8), - STCP(0x5cb420e0, 0x5842dd54), STCP(0x5c6eb258, 0x588b9140), STCP(0x5c290acc, 0x58d40e8c), STCP(0x5be32a67, 0x591c550e), - STCP(0x5b9d1154, 0x59646498), STCP(0x5b56bfbd, 0x59ac3cfd), STCP(0x5b1035cf, 0x59f3de12), STCP(0x5ac973b5, 0x5a3b47ab), - STCP(0x5a82799a, 0x5a82799a), -}; - -const PWord16 SineTable320[] = -{ - STCP(0x7fffffff, 0x00000000), STCP(0x7fff9aef, 0x00a0d951), - STCP(0x7ffe6bbf, 0x0141b1a5), STCP(0x7ffc726f, 0x01e287fc), - STCP(0x7ff9af04, 0x02835b5a), STCP(0x7ff62182, 0x03242abf), - STCP(0x7ff1c9ef, 0x03c4f52f), STCP(0x7feca851, 0x0465b9aa), - STCP(0x7fe6bcb0, 0x05067734), STCP(0x7fe00716, 0x05a72ccf), - STCP(0x7fd8878e, 0x0647d97c), STCP(0x7fd03e23, 0x06e87c3f), - STCP(0x7fc72ae2, 0x07891418), STCP(0x7fbd4dda, 0x0829a00c), - STCP(0x7fb2a71b, 0x08ca1f1b), STCP(0x7fa736b4, 0x096a9049), - STCP(0x7f9afcb9, 0x0a0af299), STCP(0x7f8df93c, 0x0aab450d), - STCP(0x7f802c52, 0x0b4b86a8), STCP(0x7f719611, 0x0bebb66c), - STCP(0x7f62368f, 0x0c8bd35e), STCP(0x7f520de6, 0x0d2bdc80), - STCP(0x7f411c2f, 0x0dcbd0d5), STCP(0x7f2f6183, 0x0e6baf61), - STCP(0x7f1cde01, 0x0f0b7727), STCP(0x7f0991c4, 0x0fab272b), - STCP(0x7ef57cea, 0x104abe71), STCP(0x7ee09f95, 0x10ea3bfd), - STCP(0x7ecaf9e5, 0x11899ed3), STCP(0x7eb48bfb, 0x1228e5f8), - STCP(0x7e9d55fc, 0x12c8106f), STCP(0x7e85580c, 0x13671d3d), - STCP(0x7e6c9251, 0x14060b68), STCP(0x7e5304f2, 0x14a4d9f4), - STCP(0x7e38b017, 0x154387e6), STCP(0x7e1d93ea, 0x15e21445), - STCP(0x7e01b096, 0x16807e15), STCP(0x7de50646, 0x171ec45c), - STCP(0x7dc79529, 0x17bce621), STCP(0x7da95d6c, 0x185ae269), - STCP(0x7d8a5f40, 0x18f8b83c), STCP(0x7d6a9ad5, 0x199666a0), - STCP(0x7d4a105d, 0x1a33ec9c), STCP(0x7d28c00c, 0x1ad14938), - STCP(0x7d06aa16, 0x1b6e7b7a), STCP(0x7ce3ceb2, 0x1c0b826a), - STCP(0x7cc02e15, 0x1ca85d12), STCP(0x7c9bc87a, 0x1d450a78), - STCP(0x7c769e18, 0x1de189a6), STCP(0x7c50af2b, 0x1e7dd9a4), - STCP(0x7c29fbee, 0x1f19f97b), STCP(0x7c02849f, 0x1fb5e836), - STCP(0x7bda497d, 0x2051a4dd), STCP(0x7bb14ac5, 0x20ed2e7b), - STCP(0x7b8788ba, 0x2188841a), STCP(0x7b5d039e, 0x2223a4c5), - STCP(0x7b31bbb2, 0x22be8f87), STCP(0x7b05b13d, 0x2359436c), - STCP(0x7ad8e482, 0x23f3bf7e), STCP(0x7aab55ca, 0x248e02cb), - STCP(0x7a7d055b, 0x25280c5e), STCP(0x7a4df380, 0x25c1db44), - STCP(0x7a1e2082, 0x265b6e8a), STCP(0x79ed8cad, 0x26f4c53e), - STCP(0x79bc384d, 0x278dde6e), STCP(0x798a23b1, 0x2826b928), - STCP(0x79574f28, 0x28bf547b), STCP(0x7923bb01, 0x2957af74), - STCP(0x78ef678f, 0x29efc925), STCP(0x78ba5524, 0x2a87a09d), - STCP(0x78848414, 0x2b1f34eb), STCP(0x784df4b3, 0x2bb68522), - STCP(0x7816a759, 0x2c4d9050), STCP(0x77de9c5b, 0x2ce45589), - STCP(0x77a5d413, 0x2d7ad3de), STCP(0x776c4edb, 0x2e110a62), - STCP(0x77320d0d, 0x2ea6f827), STCP(0x76f70f05, 0x2f3c9c40), - STCP(0x76bb5521, 0x2fd1f5c1), STCP(0x767edfbe, 0x306703bf), - STCP(0x7641af3d, 0x30fbc54d), STCP(0x7603c3fd, 0x31903982), - STCP(0x75c51e61, 0x32245f72), STCP(0x7585becb, 0x32b83634), - STCP(0x7545a5a0, 0x334bbcde), STCP(0x7504d345, 0x33def287), - STCP(0x74c34820, 0x3471d647), STCP(0x74810499, 0x35046736), - STCP(0x743e0918, 0x3596a46c), STCP(0x73fa5607, 0x36288d03), - STCP(0x73b5ebd1, 0x36ba2014), STCP(0x7370cae2, 0x374b5cb9), - STCP(0x732af3a7, 0x37dc420c), STCP(0x72e4668f, 0x386ccf2a), - STCP(0x729d2409, 0x38fd032d), STCP(0x72552c85, 0x398cdd32), - STCP(0x720c8075, 0x3a1c5c57), STCP(0x71c3204c, 0x3aab7fb7), - STCP(0x71790c7e, 0x3b3a4672), STCP(0x712e457f, 0x3bc8afa5), - STCP(0x70e2cbc6, 0x3c56ba70), STCP(0x70969fca, 0x3ce465f3), - STCP(0x7049c203, 0x3d71b14d), STCP(0x6ffc32eb, 0x3dfe9ba1), - STCP(0x6fadf2fc, 0x3e8b240e), STCP(0x6f5f02b2, 0x3f1749b8), - STCP(0x6f0f6289, 0x3fa30bc1), STCP(0x6ebf12ff, 0x402e694c), - STCP(0x6e6e1492, 0x40b9617d), STCP(0x6e1c67c4, 0x4143f379), - STCP(0x6dca0d14, 0x41ce1e65), STCP(0x6d770506, 0x4257e166), - STCP(0x6d23501b, 0x42e13ba4), STCP(0x6cceeed8, 0x436a2c45), - STCP(0x6c79e1c2, 0x43f2b271), STCP(0x6c242960, 0x447acd50), - STCP(0x6bcdc639, 0x45027c0c), STCP(0x6b76b8d6, 0x4589bdcf), - STCP(0x6b1f01c0, 0x461091c2), STCP(0x6ac6a180, 0x4696f710), - STCP(0x6a6d98a4, 0x471cece7), STCP(0x6a13e7b8, 0x47a27271), - STCP(0x69b98f48, 0x482786dc), STCP(0x695e8fe5, 0x48ac2957), - STCP(0x6902ea1d, 0x4930590f), STCP(0x68a69e81, 0x49b41533), - STCP(0x6849ada3, 0x4a375cf5), STCP(0x67ec1817, 0x4aba2f84), - STCP(0x678dde6e, 0x4b3c8c12), STCP(0x672f013f, 0x4bbe71d1), - STCP(0x66cf8120, 0x4c3fdff4), STCP(0x666f5ea6, 0x4cc0d5ae), - STCP(0x660e9a6a, 0x4d415234), STCP(0x65ad3505, 0x4dc154bb), - STCP(0x654b2f10, 0x4e40dc79), STCP(0x64e88926, 0x4ebfe8a5), - STCP(0x648543e4, 0x4f3e7875), STCP(0x64215fe5, 0x4fbc8b22), - STCP(0x63bcddc7, 0x503a1fe5), STCP(0x6357be2a, 0x50b735f8), - STCP(0x62f201ac, 0x5133cc94), STCP(0x628ba8ef, 0x51afe2f6), - STCP(0x6224b495, 0x522b7859), STCP(0x61bd253f, 0x52a68bfb), - STCP(0x6154fb91, 0x53211d18), STCP(0x60ec3830, 0x539b2af0), - STCP(0x6082dbc1, 0x5414b4c1), STCP(0x6018e6eb, 0x548db9cb), - STCP(0x5fae5a55, 0x55063951), STCP(0x5f4336a7, 0x557e3292), - STCP(0x5ed77c8a, 0x55f5a4d2), STCP(0x5e6b2ca8, 0x566c8f55), - STCP(0x5dfe47ad, 0x56e2f15d), STCP(0x5d90ce45, 0x5758ca31), - STCP(0x5d22c11c, 0x57ce1917), STCP(0x5cb420e0, 0x5842dd54), - STCP(0x5c44ee40, 0x58b71632), STCP(0x5bd529eb, 0x592ac2f7), - STCP(0x5b64d492, 0x599de2ee), STCP(0x5af3eee6, 0x5a107561), - STCP(0x5a82799a, 0x5a82799a) -}; - -/* - Sine windows - */ -#define WTC(x) WORD322WORD16(x) - -#define WTCP(a,b) { { WTC(a), WTC(b) } } - -const PWord16 SineWindow10[5] = -{ - WTCP(0x7f9afcb9, 0x0a0af299), WTCP(0x7c769e18, 0x1de189a6), WTCP(0x7641af3d, 0x30fbc54d), WTCP(0x6d23501b, 0x42e13ba4), - WTCP(0x6154fb91, 0x53211d18), -}; - -const PWord16 SineWindow16[8] = -{ - WTCP(0x7fd8878e, 0x0647d97c), WTCP(0x7e9d55fc, 0x12c8106f), WTCP(0x7c29fbee, 0x1f19f97b), WTCP(0x78848414, 0x2b1f34eb), - WTCP(0x73b5ebd1, 0x36ba2014), WTCP(0x6dca0d14, 0x41ce1e65), WTCP(0x66cf8120, 0x4c3fdff4), WTCP(0x5ed77c8a, 0x55f5a4d2), -}; - -const PWord16 SineWindow20[10] = -{ - WTCP(0x7fe6bcb0, 0x05067734), WTCP(0x7f1cde01, 0x0f0b7727), WTCP(0x7d8a5f40, 0x18f8b83c), WTCP(0x7b31bbb2, 0x22be8f87), - WTCP(0x7816a759, 0x2c4d9050), WTCP(0x743e0918, 0x3596a46c), WTCP(0x6fadf2fc, 0x3e8b240e), WTCP(0x6a6d98a4, 0x471cece7), - WTCP(0x648543e4, 0x4f3e7875), WTCP(0x5dfe47ad, 0x56e2f15d), -}; - -const PWord16 SineWindow30[15] = -{ - WTCP(0x7ff4c56f, 0x0359c428), WTCP(0x7f9afcb9, 0x0a0af299), WTCP(0x7ee7aa4c, 0x10b5150f), WTCP(0x7ddb4bfc, 0x17537e63), - WTCP(0x7c769e18, 0x1de189a6), WTCP(0x7aba9ae6, 0x245a9d65), WTCP(0x78a879f4, 0x2aba2ee4), WTCP(0x7641af3d, 0x30fbc54d), - WTCP(0x7387ea23, 0x371afcd5), WTCP(0x707d1443, 0x3d1389cb), WTCP(0x6d23501b, 0x42e13ba4), WTCP(0x697cf78a, 0x487fffe4), - WTCP(0x658c9a2d, 0x4debe4fe), WTCP(0x6154fb91, 0x53211d18), WTCP(0x5cd91140, 0x581c00b3), -}; - -const PWord16 SineWindow32[16] = -{ - WTCP(0x7ff62182, 0x03242abf), WTCP(0x7fa736b4, 0x096a9049), WTCP(0x7f0991c4, 0x0fab272b), WTCP(0x7e1d93ea, 0x15e21445), - WTCP(0x7ce3ceb2, 0x1c0b826a), WTCP(0x7b5d039e, 0x2223a4c5), WTCP(0x798a23b1, 0x2826b928), WTCP(0x776c4edb, 0x2e110a62), - WTCP(0x7504d345, 0x33def287), WTCP(0x72552c85, 0x398cdd32), WTCP(0x6f5f02b2, 0x3f1749b8), WTCP(0x6c242960, 0x447acd50), - WTCP(0x68a69e81, 0x49b41533), WTCP(0x64e88926, 0x4ebfe8a5), WTCP(0x60ec3830, 0x539b2af0), WTCP(0x5cb420e0, 0x5842dd54) -}; - -const PWord16 SineWindow40[20] = -{ - WTCP(0x7ff9af04, 0x02835b5a), WTCP(0x7fc72ae2, 0x07891418), WTCP(0x7f62368f, 0x0c8bd35e), WTCP(0x7ecaf9e5, 0x11899ed3), - WTCP(0x7e01b096, 0x16807e15), WTCP(0x7d06aa16, 0x1b6e7b7a), WTCP(0x7bda497d, 0x2051a4dd), WTCP(0x7a7d055b, 0x25280c5e), - WTCP(0x78ef678f, 0x29efc925), WTCP(0x77320d0d, 0x2ea6f827), WTCP(0x7545a5a0, 0x334bbcde), WTCP(0x732af3a7, 0x37dc420c), - WTCP(0x70e2cbc6, 0x3c56ba70), WTCP(0x6e6e1492, 0x40b9617d), WTCP(0x6bcdc639, 0x45027c0c), WTCP(0x6902ea1d, 0x4930590f), - WTCP(0x660e9a6a, 0x4d415234), WTCP(0x62f201ac, 0x5133cc94), WTCP(0x5fae5a55, 0x55063951), WTCP(0x5c44ee40, 0x58b71632), -}; - -const PWord16 SineWindow48[24] = -{ - WTCP(0x7ffb9d15, 0x02182427), WTCP(0x7fd8878e, 0x0647d97c), WTCP(0x7f92661d, 0x0a75d60e), WTCP(0x7f294bfd, 0x0ea0f48c), - WTCP(0x7e9d55fc, 0x12c8106f), WTCP(0x7deeaa7a, 0x16ea0646), WTCP(0x7d1d7958, 0x1b05b40f), WTCP(0x7c29fbee, 0x1f19f97b), - WTCP(0x7b1474fd, 0x2325b847), WTCP(0x79dd3098, 0x2727d486), WTCP(0x78848414, 0x2b1f34eb), WTCP(0x770acdec, 0x2f0ac320), - WTCP(0x757075ac, 0x32e96c09), WTCP(0x73b5ebd1, 0x36ba2014), WTCP(0x71dba9ab, 0x3a7bd382), WTCP(0x6fe2313c, 0x3e2d7eb1), - WTCP(0x6dca0d14, 0x41ce1e65), WTCP(0x6b93d02e, 0x455cb40c), WTCP(0x694015c3, 0x48d84609), WTCP(0x66cf8120, 0x4c3fdff4), - WTCP(0x6442bd7e, 0x4f9292dc), WTCP(0x619a7dce, 0x52cf758f), WTCP(0x5ed77c8a, 0x55f5a4d2), WTCP(0x5bfa7b82, 0x590443a7) -}; - -const PWord16 SineWindow60[60] = -{ - WTCP(0x7ffd3154, 0x01aceb7c), WTCP(0x7fe6bcb0, 0x05067734), WTCP(0x7fb9d759, 0x085f2137), WTCP(0x7f76892f, 0x0bb65336), - WTCP(0x7f1cde01, 0x0f0b7727), WTCP(0x7eace58a, 0x125df75b), WTCP(0x7e26b371, 0x15ad3e9a), WTCP(0x7d8a5f40, 0x18f8b83c), - WTCP(0x7cd80464, 0x1c3fd045), WTCP(0x7c0fc22a, 0x1f81f37c), WTCP(0x7b31bbb2, 0x22be8f87), WTCP(0x7a3e17f2, 0x25f51307), - WTCP(0x793501a9, 0x2924edac), WTCP(0x7816a759, 0x2c4d9050), WTCP(0x76e33b3f, 0x2f6e6d16), WTCP(0x759af34c, 0x3286f779), - WTCP(0x743e0918, 0x3596a46c), WTCP(0x72ccb9db, 0x389cea72), WTCP(0x71474660, 0x3b9941b1), WTCP(0x6fadf2fc, 0x3e8b240e), - WTCP(0x6e010780, 0x41720d46), WTCP(0x6c40cf2c, 0x444d7aff), WTCP(0x6a6d98a4, 0x471cece7), WTCP(0x6887b5e2, 0x49dfe4c2), - WTCP(0x668f7c25, 0x4c95e688), WTCP(0x648543e4, 0x4f3e7875), WTCP(0x626968be, 0x51d92321), WTCP(0x603c496c, 0x54657194), - WTCP(0x5dfe47ad, 0x56e2f15d), WTCP(0x5bafc837, 0x595132a2), -}; - -const PWord16 SineWindow64[32] = -{ - WTCP(0x7ffd885a, 0x01921d20), WTCP(0x7fe9cbc0, 0x04b6195d), WTCP(0x7fc25596, 0x07d95b9e), WTCP(0x7f872bf3, 0x0afb6805), - WTCP(0x7f3857f6, 0x0e1bc2e4), WTCP(0x7ed5e5c6, 0x1139f0cf), WTCP(0x7e5fe493, 0x145576b1), WTCP(0x7dd6668f, 0x176dd9de), - WTCP(0x7d3980ec, 0x1a82a026), WTCP(0x7c894bde, 0x1d934fe5), WTCP(0x7bc5e290, 0x209f701c), WTCP(0x7aef6323, 0x23a6887f), - WTCP(0x7a05eead, 0x26a82186), WTCP(0x7909a92d, 0x29a3c485), WTCP(0x77fab989, 0x2c98fbba), WTCP(0x76d94989, 0x2f875262), - WTCP(0x75a585cf, 0x326e54c7), WTCP(0x745f9dd1, 0x354d9057), WTCP(0x7307c3d0, 0x382493b0), WTCP(0x719e2cd2, 0x3af2eeb7), - WTCP(0x7023109a, 0x3db832a6), WTCP(0x6e96a99d, 0x4073f21d), WTCP(0x6cf934fc, 0x4325c135), WTCP(0x6b4af279, 0x45cd358f), - WTCP(0x698c246c, 0x4869e665), WTCP(0x67bd0fbd, 0x4afb6c98), WTCP(0x65ddfbd3, 0x4d8162c4), WTCP(0x63ef3290, 0x4ffb654d), - WTCP(0x61f1003f, 0x5269126e), WTCP(0x5fe3b38d, 0x54ca0a4b), WTCP(0x5dc79d7c, 0x571deefa), WTCP(0x5b9d1154, 0x59646498), -}; - -const PWord16 SineWindow80[40] = -{ - WTCP(0x7ffe6bbf, 0x0141b1a5), WTCP(0x7ff1c9ef, 0x03c4f52f), WTCP(0x7fd8878e, 0x0647d97c), WTCP(0x7fb2a71b, 0x08ca1f1b), - WTCP(0x7f802c52, 0x0b4b86a8), WTCP(0x7f411c2f, 0x0dcbd0d5), WTCP(0x7ef57cea, 0x104abe71), WTCP(0x7e9d55fc, 0x12c8106f), - WTCP(0x7e38b017, 0x154387e6), WTCP(0x7dc79529, 0x17bce621), WTCP(0x7d4a105d, 0x1a33ec9c), WTCP(0x7cc02e15, 0x1ca85d12), - WTCP(0x7c29fbee, 0x1f19f97b), WTCP(0x7b8788ba, 0x2188841a), WTCP(0x7ad8e482, 0x23f3bf7e), WTCP(0x7a1e2082, 0x265b6e8a), - WTCP(0x79574f28, 0x28bf547b), WTCP(0x78848414, 0x2b1f34eb), WTCP(0x77a5d413, 0x2d7ad3de), WTCP(0x76bb5521, 0x2fd1f5c1), - WTCP(0x75c51e61, 0x32245f72), WTCP(0x74c34820, 0x3471d647), WTCP(0x73b5ebd1, 0x36ba2014), WTCP(0x729d2409, 0x38fd032d), - WTCP(0x71790c7e, 0x3b3a4672), WTCP(0x7049c203, 0x3d71b14d), WTCP(0x6f0f6289, 0x3fa30bc1), WTCP(0x6dca0d14, 0x41ce1e65), - WTCP(0x6c79e1c2, 0x43f2b271), WTCP(0x6b1f01c0, 0x461091c2), WTCP(0x69b98f48, 0x482786dc), WTCP(0x6849ada3, 0x4a375cf5), - WTCP(0x66cf8120, 0x4c3fdff4), WTCP(0x654b2f10, 0x4e40dc79), WTCP(0x63bcddc7, 0x503a1fe5), WTCP(0x6224b495, 0x522b7859), - WTCP(0x6082dbc1, 0x5414b4c1), WTCP(0x5ed77c8a, 0x55f5a4d2), WTCP(0x5d22c11c, 0x57ce1917), WTCP(0x5b64d492, 0x599de2ee), -}; - -const PWord16 SineWindow70[35] = -{ - WTCP(0x7ffdeffe, 0x016fa5fd), WTCP(0x7fed7058, 0x044ec292), WTCP(0x7fcc732b, 0x072d5101), WTCP(0x7f9afcb9, 0x0a0af299), - WTCP(0x7f591361, 0x0ce748ca), WTCP(0x7f06bfa3, 0x0fc1f52d), WTCP(0x7ea40c1b, 0x129a9991), WTCP(0x7e310583, 0x1570d80b), - WTCP(0x7dadbaaf, 0x184452fd), WTCP(0x7d1a3c8a, 0x1b14ad24), WTCP(0x7c769e18, 0x1de189a6), WTCP(0x7bc2f470, 0x20aa8c19), - WTCP(0x7aff56bc, 0x236f5896), WTCP(0x7a2bde32, 0x262f93be), WTCP(0x7948a614, 0x28eae2cb), WTCP(0x7855cbae, 0x2ba0eb97), - WTCP(0x77536e4c, 0x2e5154ac), WTCP(0x7641af3d, 0x30fbc54d), WTCP(0x7520b1ca, 0x339fe582), WTCP(0x73f09b33, 0x363d5e23), - WTCP(0x72b192ac, 0x38d3d8e3), WTCP(0x7163c154, 0x3b63005e), WTCP(0x70075233, 0x3dea8020), WTCP(0x6e9c7233, 0x406a04b2), - WTCP(0x6d23501b, 0x42e13ba4), WTCP(0x6b9c1c87, 0x454fd398), WTCP(0x6a0709e6, 0x47b57c4e), WTCP(0x68644c6e, 0x4a11e6aa), - WTCP(0x66b41a1a, 0x4c64c4c4), WTCP(0x64f6aa9f, 0x4eadc9ee), WTCP(0x632c3769, 0x50ecaabd), WTCP(0x6154fb91, 0x53211d18), - WTCP(0x5f7133d4, 0x554ad83c), WTCP(0x5d811e90, 0x576994c8), WTCP(0x5b84fbb6, 0x597d0cc7) -}; - -const PWord16 SineWindow96[48] = -{ - WTCP(0x7ffee744, 0x010c1460), WTCP(0x7ff62182, 0x03242abf), WTCP(0x7fe49698, 0x053c0a01), WTCP(0x7fca47b9, 0x07538d6b), - WTCP(0x7fa736b4, 0x096a9049), WTCP(0x7f7b65ef, 0x0b80edf1), WTCP(0x7f46d86c, 0x0d9681c2), WTCP(0x7f0991c4, 0x0fab272b), - WTCP(0x7ec3962a, 0x11beb9aa), WTCP(0x7e74ea6a, 0x13d114d0), WTCP(0x7e1d93ea, 0x15e21445), WTCP(0x7dbd98a4, 0x17f193c5), - WTCP(0x7d54ff2e, 0x19ff6f2a), WTCP(0x7ce3ceb2, 0x1c0b826a), WTCP(0x7c6a0ef2, 0x1e15a99a), WTCP(0x7be7c847, 0x201dc0ef), - WTCP(0x7b5d039e, 0x2223a4c5), WTCP(0x7ac9ca7a, 0x2427319d), WTCP(0x7a2e26f2, 0x26284422), WTCP(0x798a23b1, 0x2826b928), - WTCP(0x78ddcbf5, 0x2a226db5), WTCP(0x78292b8d, 0x2c1b3efb), WTCP(0x776c4edb, 0x2e110a62), WTCP(0x76a742d1, 0x3003ad85), - WTCP(0x75da14ef, 0x31f30638), WTCP(0x7504d345, 0x33def287), WTCP(0x74278c72, 0x35c750bc), WTCP(0x73424fa0, 0x37abff5d), - WTCP(0x72552c85, 0x398cdd32), WTCP(0x71603361, 0x3b69c947), WTCP(0x706374ff, 0x3d42a2ec), WTCP(0x6f5f02b2, 0x3f1749b8), - WTCP(0x6e52ee52, 0x40e79d8c), WTCP(0x6d3f4a40, 0x42b37e96), WTCP(0x6c242960, 0x447acd50), WTCP(0x6b019f1a, 0x463d6a87), - WTCP(0x69d7bf57, 0x47fb3757), WTCP(0x68a69e81, 0x49b41533), WTCP(0x676e5183, 0x4b67e5e4), WTCP(0x662eedc3, 0x4d168b8b), - WTCP(0x64e88926, 0x4ebfe8a5), WTCP(0x639b3a0b, 0x5063e008), WTCP(0x62471749, 0x520254ef), WTCP(0x60ec3830, 0x539b2af0), - WTCP(0x5f8ab487, 0x552e4605), WTCP(0x5e22a487, 0x56bb8a90), WTCP(0x5cb420e0, 0x5842dd54), WTCP(0x5b3f42ae, 0x59c42381) -}; - -const PWord16 SineWindow112[56] = -{ - WTCP(0x7fff31bf, 0x00e5c87e), WTCP(0x7ff8bfc7, 0x02b14de9), WTCP(0x7febdc2a, 0x047cb09e), WTCP(0x7fd8878e, 0x0647d97c), - WTCP(0x7fbec2ec, 0x0812b164), WTCP(0x7f9e8f91, 0x09dd213a), WTCP(0x7f77ef1c, 0x0ba711ea), WTCP(0x7f4ae37e, 0x0d706c64), - WTCP(0x7f176efc, 0x0f3919a0), WTCP(0x7edd942d, 0x110102a0), WTCP(0x7e9d55fc, 0x12c8106f), WTCP(0x7e56b7a4, 0x148e2c22), - WTCP(0x7e09bcb4, 0x16533edc), WTCP(0x7db6690c, 0x181731cd), WTCP(0x7d5cc0df, 0x19d9ee32), WTCP(0x7cfcc8af, 0x1b9b5d5a), - WTCP(0x7c968552, 0x1d5b68a2), WTCP(0x7c29fbee, 0x1f19f97b), WTCP(0x7bb731fb, 0x20d6f969), WTCP(0x7b3e2d40, 0x22925203), - WTCP(0x7abef3d5, 0x244becf6), WTCP(0x7a398c22, 0x2603b406), WTCP(0x79adfcdf, 0x27b9910e), WTCP(0x791c4d13, 0x296d6e00), - WTCP(0x78848414, 0x2b1f34eb), WTCP(0x77e6a986, 0x2ccecff7), WTCP(0x7742c55c, 0x2e7c2969), WTCP(0x7698dfd8, 0x30272ba0), - WTCP(0x75e90186, 0x31cfc11e), WTCP(0x75333343, 0x3375d481), WTCP(0x74777e35, 0x35195088), WTCP(0x73b5ebd1, 0x36ba2014), - WTCP(0x72ee85d5, 0x38582e27), WTCP(0x7221564d, 0x39f365e9), WTCP(0x714e678c, 0x3b8bb2a3), WTCP(0x7075c433, 0x3d20ffc8), - WTCP(0x6f977729, 0x3eb338ef), WTCP(0x6eb38ba1, 0x404249d5), WTCP(0x6dca0d14, 0x41ce1e65), WTCP(0x6cdb0745, 0x4356a2ad), - WTCP(0x6be6863c, 0x44dbc2ec), WTCP(0x6aec9649, 0x465d6b89), WTCP(0x69ed4403, 0x47db8918), WTCP(0x68e89c43, 0x4956085b), - WTCP(0x67deac2c, 0x4accd644), WTCP(0x66cf8120, 0x4c3fdff4), WTCP(0x65bb28c7, 0x4daf12ba), WTCP(0x64a1b10b, 0x4f1a5c1a), - WTCP(0x6383281a, 0x5081a9c9), WTCP(0x625f9c5f, 0x51e4e9ae), WTCP(0x61371c8b, 0x534409e8), WTCP(0x6009b78a, 0x549ef8c6), - WTCP(0x5ed77c8a, 0x55f5a4d2), WTCP(0x5da07af6, 0x5747fcca), WTCP(0x5c64c278, 0x5895efa4), WTCP(0x5b2462f5, 0x59df6c8f) -}; - -const PWord16 SineWindow120[60] = -{ - WTCP(0x7fff4c54, 0x00d676eb), WTCP(0x7ff9af04, 0x02835b5a), WTCP(0x7fee74a2, 0x0430238f), WTCP(0x7fdd9dad, 0x05dcbcbe), - WTCP(0x7fc72ae2, 0x07891418), WTCP(0x7fab1d3d, 0x093516d4), WTCP(0x7f8975f9, 0x0ae0b22c), WTCP(0x7f62368f, 0x0c8bd35e), - WTCP(0x7f3560b9, 0x0e3667ad), WTCP(0x7f02f66f, 0x0fe05c64), WTCP(0x7ecaf9e5, 0x11899ed3), WTCP(0x7e8d6d91, 0x13321c53), - WTCP(0x7e4a5426, 0x14d9c245), WTCP(0x7e01b096, 0x16807e15), WTCP(0x7db3860f, 0x18263d36), WTCP(0x7d5fd801, 0x19caed29), - WTCP(0x7d06aa16, 0x1b6e7b7a), WTCP(0x7ca80038, 0x1d10d5c2), WTCP(0x7c43de8e, 0x1eb1e9a7), WTCP(0x7bda497d, 0x2051a4dd), - WTCP(0x7b6b45a5, 0x21eff528), WTCP(0x7af6d7e6, 0x238cc85d), WTCP(0x7a7d055b, 0x25280c5e), WTCP(0x79fdd35c, 0x26c1af22), - WTCP(0x7979477d, 0x28599eb0), WTCP(0x78ef678f, 0x29efc925), WTCP(0x7860399e, 0x2b841caf), WTCP(0x77cbc3f2, 0x2d168792), - WTCP(0x77320d0d, 0x2ea6f827), WTCP(0x76931bae, 0x30355cdd), WTCP(0x75eef6ce, 0x31c1a43b), WTCP(0x7545a5a0, 0x334bbcde), - WTCP(0x74972f92, 0x34d3957e), WTCP(0x73e39c49, 0x36591cea), WTCP(0x732af3a7, 0x37dc420c), WTCP(0x726d3dc6, 0x395cf3e9), - WTCP(0x71aa82f7, 0x3adb21a1), WTCP(0x70e2cbc6, 0x3c56ba70), WTCP(0x701620f5, 0x3dcfadb0), WTCP(0x6f448b7e, 0x3f45ead8), - WTCP(0x6e6e1492, 0x40b9617d), WTCP(0x6d92c59b, 0x422a0154), WTCP(0x6cb2a837, 0x4397ba32), WTCP(0x6bcdc639, 0x45027c0c), - WTCP(0x6ae429ae, 0x466a36f9), WTCP(0x69f5dcd3, 0x47cedb31), WTCP(0x6902ea1d, 0x4930590f), WTCP(0x680b5c33, 0x4a8ea111), - WTCP(0x670f3df3, 0x4be9a3db), WTCP(0x660e9a6a, 0x4d415234), WTCP(0x65097cdb, 0x4e959d08), WTCP(0x63fff0ba, 0x4fe6756a), - WTCP(0x62f201ac, 0x5133cc94), WTCP(0x61dfbb8a, 0x527d93e6), WTCP(0x60c92a5a, 0x53c3bcea), WTCP(0x5fae5a55, 0x55063951), - WTCP(0x5e8f57e2, 0x5644faf4), WTCP(0x5d6c2f99, 0x577ff3da), WTCP(0x5c44ee40, 0x58b71632), WTCP(0x5b19a0c8, 0x59ea5454), -}; - -const PWord16 SineWindow128[64] = -{ - WTCP(0x7fff6216, 0x00c90f88), WTCP(0x7ffa72d1, 0x025b26d7), WTCP(0x7ff09478, 0x03ed26e6), WTCP(0x7fe1c76b, 0x057f0035), - WTCP(0x7fce0c3e, 0x0710a345), WTCP(0x7fb563b3, 0x08a2009a), WTCP(0x7f97cebd, 0x0a3308bd), WTCP(0x7f754e80, 0x0bc3ac35), - WTCP(0x7f4de451, 0x0d53db92), WTCP(0x7f2191b4, 0x0ee38766), WTCP(0x7ef05860, 0x1072a048), WTCP(0x7eba3a39, 0x120116d5), - WTCP(0x7e7f3957, 0x138edbb1), WTCP(0x7e3f57ff, 0x151bdf86), WTCP(0x7dfa98a8, 0x16a81305), WTCP(0x7db0fdf8, 0x183366e9), - WTCP(0x7d628ac6, 0x19bdcbf3), WTCP(0x7d0f4218, 0x1b4732ef), WTCP(0x7cb72724, 0x1ccf8cb3), WTCP(0x7c5a3d50, 0x1e56ca1e), - WTCP(0x7bf88830, 0x1fdcdc1b), WTCP(0x7b920b89, 0x2161b3a0), WTCP(0x7b26cb4f, 0x22e541af), WTCP(0x7ab6cba4, 0x24677758), - WTCP(0x7a4210d8, 0x25e845b6), WTCP(0x79c89f6e, 0x27679df4), WTCP(0x794a7c12, 0x28e5714b), WTCP(0x78c7aba2, 0x2a61b101), - WTCP(0x78403329, 0x2bdc4e6f), WTCP(0x77b417df, 0x2d553afc), WTCP(0x77235f2d, 0x2ecc681e), WTCP(0x768e0ea6, 0x3041c761), - WTCP(0x75f42c0b, 0x31b54a5e), WTCP(0x7555bd4c, 0x3326e2c3), WTCP(0x74b2c884, 0x34968250), WTCP(0x740b53fb, 0x36041ad9), - WTCP(0x735f6626, 0x376f9e46), WTCP(0x72af05a7, 0x38d8fe93), WTCP(0x71fa3949, 0x3a402dd2), WTCP(0x71410805, 0x3ba51e29), - WTCP(0x708378ff, 0x3d07c1d6), WTCP(0x6fc19385, 0x3e680b2c), WTCP(0x6efb5f12, 0x3fc5ec98), WTCP(0x6e30e34a, 0x4121589b), - WTCP(0x6d6227fa, 0x427a41d0), WTCP(0x6c8f351c, 0x43d09aed), WTCP(0x6bb812d1, 0x452456bd), WTCP(0x6adcc964, 0x46756828), - WTCP(0x69fd614a, 0x47c3c22f), WTCP(0x6919e320, 0x490f57ee), WTCP(0x683257ab, 0x4a581c9e), WTCP(0x6746c7d8, 0x4b9e0390), - WTCP(0x66573cbb, 0x4ce10034), WTCP(0x6563bf92, 0x4e210617), WTCP(0x646c59bf, 0x4f5e08e3), WTCP(0x637114cc, 0x5097fc5e), - WTCP(0x6271fa69, 0x51ced46e), WTCP(0x616f146c, 0x53028518), WTCP(0x60686ccf, 0x5433027d), WTCP(0x5f5e0db3, 0x556040e2), - WTCP(0x5e50015d, 0x568a34a9), WTCP(0x5d3e5237, 0x57b0d256), WTCP(0x5c290acc, 0x58d40e8c), WTCP(0x5b1035cf, 0x59f3de12), -}; - -const PWord16 SineWindow140[70] = -{ - WTCP(0x7fff7bff, 0x00b7d3bc), WTCP(0x7ffb5c00, 0x02277547), WTCP(0x7ff31c25, 0x0397050d), WTCP(0x7fe6bcb0, 0x05067734), - WTCP(0x7fd63e09, 0x0675bfe7), WTCP(0x7fc1a0b6, 0x07e4d34d), WTCP(0x7fa8e564, 0x0953a594), WTCP(0x7f8c0cdc, 0x0ac22ae8), - WTCP(0x7f6b180f, 0x0c30577a), WTCP(0x7f46080a, 0x0d9e1f7d), WTCP(0x7f1cde01, 0x0f0b7727), WTCP(0x7eef9b46, 0x107852b2), - WTCP(0x7ebe414f, 0x11e4a65c), WTCP(0x7e88d1b4, 0x13506668), WTCP(0x7e4f4e2c, 0x14bb871b), WTCP(0x7e11b894, 0x1625fcc3), - WTCP(0x7dd012e6, 0x178fbbb1), WTCP(0x7d8a5f40, 0x18f8b83c), WTCP(0x7d409fe1, 0x1a60e6c3), WTCP(0x7cf2d72b, 0x1bc83baa), - WTCP(0x7ca1079d, 0x1d2eab5d), WTCP(0x7c4b33dc, 0x1e942a4d), WTCP(0x7bf15eac, 0x1ff8acf7), WTCP(0x7b938af1, 0x215c27dc), - WTCP(0x7b31bbb2, 0x22be8f87), WTCP(0x7acbf416, 0x241fd88e), WTCP(0x7a623764, 0x257ff78e), WTCP(0x79f48904, 0x26dee12c), - WTCP(0x7982ec80, 0x283c8a1b), WTCP(0x790d6581, 0x2998e716), WTCP(0x7893f7d1, 0x2af3ece2), WTCP(0x7816a759, 0x2c4d9050), - WTCP(0x77957822, 0x2da5c63e), WTCP(0x77106e58, 0x2efc8393), WTCP(0x76878e43, 0x3051bd43), WTCP(0x75fadc4d, 0x31a56850), - WTCP(0x756a5cff, 0x32f779c7), WTCP(0x74d61500, 0x3447e6c3), WTCP(0x743e0918, 0x3596a46c), WTCP(0x73a23e2d, 0x36e3a7fa), - WTCP(0x7302b945, 0x382ee6b0), WTCP(0x725f7f84, 0x397855e1), WTCP(0x71b8962b, 0x3abfeaf1), WTCP(0x710e029e, 0x3c059b4f), - WTCP(0x705fca59, 0x3d495c7e), WTCP(0x6fadf2fc, 0x3e8b240e), WTCP(0x6ef88241, 0x3fcae7a1), WTCP(0x6e3f7e01, 0x41089ce8), - WTCP(0x6d82ec32, 0x424439a6), WTCP(0x6cc2d2e9, 0x437db3b0), WTCP(0x6bff3855, 0x44b500eb), WTCP(0x6b3822c6, 0x45ea1750), - WTCP(0x6a6d98a4, 0x471cece7), WTCP(0x699fa078, 0x484d77ce), WTCP(0x68ce40e4, 0x497bae33), WTCP(0x67f980a8, 0x4aa7865b), - WTCP(0x6721669f, 0x4bd0f69b), WTCP(0x6645f9c0, 0x4cf7f55d), WTCP(0x6567411d, 0x4e1c791f), WTCP(0x648543e4, 0x4f3e7875), - WTCP(0x63a0095c, 0x505dea05), WTCP(0x62b798ea, 0x517ac48c), WTCP(0x61cbfa0b, 0x5294fedd), WTCP(0x60dd3457, 0x53ac8fde), - WTCP(0x5feb4f7f, 0x54c16e8e), WTCP(0x5ef6534f, 0x55d391ff), WTCP(0x5dfe47ad, 0x56e2f15d), WTCP(0x5d033497, 0x57ef83e9), - WTCP(0x5c052224, 0x58f940fa), WTCP(0x5b041885, 0x5a002001) -}; - -const PWord16 SineWindow160[80] = -{ - WTCP(0x7fff9aef, 0x00a0d951), WTCP(0x7ffc726f, 0x01e287fc), WTCP(0x7ff62182, 0x03242abf), WTCP(0x7feca851, 0x0465b9aa), - WTCP(0x7fe00716, 0x05a72ccf), WTCP(0x7fd03e23, 0x06e87c3f), WTCP(0x7fbd4dda, 0x0829a00c), WTCP(0x7fa736b4, 0x096a9049), - WTCP(0x7f8df93c, 0x0aab450d), WTCP(0x7f719611, 0x0bebb66c), WTCP(0x7f520de6, 0x0d2bdc80), WTCP(0x7f2f6183, 0x0e6baf61), - WTCP(0x7f0991c4, 0x0fab272b), WTCP(0x7ee09f95, 0x10ea3bfd), WTCP(0x7eb48bfb, 0x1228e5f8), WTCP(0x7e85580c, 0x13671d3d), - WTCP(0x7e5304f2, 0x14a4d9f4), WTCP(0x7e1d93ea, 0x15e21445), WTCP(0x7de50646, 0x171ec45c), WTCP(0x7da95d6c, 0x185ae269), - WTCP(0x7d6a9ad5, 0x199666a0), WTCP(0x7d28c00c, 0x1ad14938), WTCP(0x7ce3ceb2, 0x1c0b826a), WTCP(0x7c9bc87a, 0x1d450a78), - WTCP(0x7c50af2b, 0x1e7dd9a4), WTCP(0x7c02849f, 0x1fb5e836), WTCP(0x7bb14ac5, 0x20ed2e7b), WTCP(0x7b5d039e, 0x2223a4c5), - WTCP(0x7b05b13d, 0x2359436c), WTCP(0x7aab55ca, 0x248e02cb), WTCP(0x7a4df380, 0x25c1db44), WTCP(0x79ed8cad, 0x26f4c53e), - WTCP(0x798a23b1, 0x2826b928), WTCP(0x7923bb01, 0x2957af74), WTCP(0x78ba5524, 0x2a87a09d), WTCP(0x784df4b3, 0x2bb68522), - WTCP(0x77de9c5b, 0x2ce45589), WTCP(0x776c4edb, 0x2e110a62), WTCP(0x76f70f05, 0x2f3c9c40), WTCP(0x767edfbe, 0x306703bf), - WTCP(0x7603c3fd, 0x31903982), WTCP(0x7585becb, 0x32b83634), WTCP(0x7504d345, 0x33def287), WTCP(0x74810499, 0x35046736), - WTCP(0x73fa5607, 0x36288d03), WTCP(0x7370cae2, 0x374b5cb9), WTCP(0x72e4668f, 0x386ccf2a), WTCP(0x72552c85, 0x398cdd32), - WTCP(0x71c3204c, 0x3aab7fb7), WTCP(0x712e457f, 0x3bc8afa5), WTCP(0x70969fca, 0x3ce465f3), WTCP(0x6ffc32eb, 0x3dfe9ba1), - WTCP(0x6f5f02b2, 0x3f1749b8), WTCP(0x6ebf12ff, 0x402e694c), WTCP(0x6e1c67c4, 0x4143f379), WTCP(0x6d770506, 0x4257e166), - WTCP(0x6cceeed8, 0x436a2c45), WTCP(0x6c242960, 0x447acd50), WTCP(0x6b76b8d6, 0x4589bdcf), WTCP(0x6ac6a180, 0x4696f710), - WTCP(0x6a13e7b8, 0x47a27271), WTCP(0x695e8fe5, 0x48ac2957), WTCP(0x68a69e81, 0x49b41533), WTCP(0x67ec1817, 0x4aba2f84), - WTCP(0x672f013f, 0x4bbe71d1), WTCP(0x666f5ea6, 0x4cc0d5ae), WTCP(0x65ad3505, 0x4dc154bb), WTCP(0x64e88926, 0x4ebfe8a5), - WTCP(0x64215fe5, 0x4fbc8b22), WTCP(0x6357be2a, 0x50b735f8), WTCP(0x628ba8ef, 0x51afe2f6), WTCP(0x61bd253f, 0x52a68bfb), - WTCP(0x60ec3830, 0x539b2af0), WTCP(0x6018e6eb, 0x548db9cb), WTCP(0x5f4336a7, 0x557e3292), WTCP(0x5e6b2ca8, 0x566c8f55), - WTCP(0x5d90ce45, 0x5758ca31), WTCP(0x5cb420e0, 0x5842dd54), WTCP(0x5bd529eb, 0x592ac2f7), WTCP(0x5af3eee6, 0x5a107561), -}; - -const PWord16 SineWindow180[90] = -{ - WTCP(0x7fffb026, 0x008efa17), WTCP(0x7ffd3154, 0x01aceb7c), WTCP(0x7ff833bd, 0x02cad485), WTCP(0x7ff0b77a, 0x03e8af9e), - WTCP(0x7fe6bcb0, 0x05067734), WTCP(0x7fda4391, 0x062425b6), WTCP(0x7fcb4c5b, 0x0741b592), WTCP(0x7fb9d759, 0x085f2137), - WTCP(0x7fa5e4e1, 0x097c6313), WTCP(0x7f8f7559, 0x0a997598), WTCP(0x7f76892f, 0x0bb65336), WTCP(0x7f5b20df, 0x0cd2f660), - WTCP(0x7f3d3cf4, 0x0def598a), WTCP(0x7f1cde01, 0x0f0b7727), WTCP(0x7efa04a8, 0x102749af), WTCP(0x7ed4b198, 0x1142cb98), - WTCP(0x7eace58a, 0x125df75b), WTCP(0x7e82a146, 0x1378c774), WTCP(0x7e55e59e, 0x1493365f), WTCP(0x7e26b371, 0x15ad3e9a), - WTCP(0x7df50bab, 0x16c6daa6), WTCP(0x7dc0ef44, 0x17e00505), WTCP(0x7d8a5f40, 0x18f8b83c), WTCP(0x7d515caf, 0x1a10eed3), - WTCP(0x7d15e8ad, 0x1b28a351), WTCP(0x7cd80464, 0x1c3fd045), WTCP(0x7c97b109, 0x1d56703c), WTCP(0x7c54efdc, 0x1e6c7dc7), - WTCP(0x7c0fc22a, 0x1f81f37c), WTCP(0x7bc8294d, 0x2096cbf1), WTCP(0x7b7e26aa, 0x21ab01c0), WTCP(0x7b31bbb2, 0x22be8f87), - WTCP(0x7ae2e9e4, 0x23d16fe8), WTCP(0x7a91b2c7, 0x24e39d85), WTCP(0x7a3e17f2, 0x25f51307), WTCP(0x79e81b06, 0x2705cb19), - WTCP(0x798fbdb0, 0x2815c06a), WTCP(0x793501a9, 0x2924edac), WTCP(0x78d7e8b6, 0x2a334d96), WTCP(0x787874a7, 0x2b40dae2), - WTCP(0x7816a759, 0x2c4d9050), WTCP(0x77b282b3, 0x2d5968a3), WTCP(0x774c08ab, 0x2e645ea1), WTCP(0x76e33b3f, 0x2f6e6d16), - WTCP(0x76781c7a, 0x30778ed2), WTCP(0x760aae73, 0x317fbeab), WTCP(0x759af34c, 0x3286f779), WTCP(0x7528ed32, 0x338d341b), - WTCP(0x74b49e5f, 0x34926f74), WTCP(0x743e0918, 0x3596a46c), WTCP(0x73c52fab, 0x3699cdf2), WTCP(0x734a1475, 0x379be6f6), - WTCP(0x72ccb9db, 0x389cea72), WTCP(0x724d224f, 0x399cd362), WTCP(0x71cb504e, 0x3a9b9cca), WTCP(0x71474660, 0x3b9941b1), - WTCP(0x70c10718, 0x3c95bd26), WTCP(0x70389514, 0x3d910a3c), WTCP(0x6fadf2fc, 0x3e8b240e), WTCP(0x6f212385, 0x3f8405bc), - WTCP(0x6e92296e, 0x407baa6a), WTCP(0x6e010780, 0x41720d46), WTCP(0x6d6dc08f, 0x42672981), WTCP(0x6cd8577a, 0x435afa54), - WTCP(0x6c40cf2c, 0x444d7aff), WTCP(0x6ba72a98, 0x453ea6c7), WTCP(0x6b0b6cbd, 0x462e78f9), WTCP(0x6a6d98a4, 0x471cece7), - WTCP(0x69cdb162, 0x4809fdeb), WTCP(0x692bba14, 0x48f5a767), WTCP(0x6887b5e2, 0x49dfe4c2), WTCP(0x67e1a7ff, 0x4ac8b16b), - WTCP(0x673993a9, 0x4bb008d9), WTCP(0x668f7c25, 0x4c95e688), WTCP(0x65e364c4, 0x4d7a45fe), WTCP(0x653550e2, 0x4e5d22c6), - WTCP(0x648543e4, 0x4f3e7875), WTCP(0x63d34137, 0x501e42a5), WTCP(0x631f4c54, 0x50fc7cfb), WTCP(0x626968be, 0x51d92321), - WTCP(0x61b19a00, 0x52b430c9), WTCP(0x60f7e3b0, 0x538da1ae), WTCP(0x603c496c, 0x54657194), WTCP(0x5f7ecedd, 0x553b9c45), - WTCP(0x5ebf77b5, 0x56101d94), WTCP(0x5dfe47ad, 0x56e2f15d), WTCP(0x5d3b428c, 0x57b41384), WTCP(0x5c766c1c, 0x58837ff4), - WTCP(0x5bafc837, 0x595132a2), WTCP(0x5ae75ab9, 0x5a1d278d), -}; - - -const PWord16 SineWindow224[112] = -{ - WTCP(0x7fffcc70, 0x0072e46e), WTCP(0x7ffe2fee, 0x0158abd6), WTCP(0x7ffaf6f1, 0x023e6ee8), WTCP(0x7ff62182, 0x03242abf), - WTCP(0x7fefafb1, 0x0409dc76), WTCP(0x7fe7a192, 0x04ef8129), WTCP(0x7fddf741, 0x05d515f5), WTCP(0x7fd2b0da, 0x06ba97f4), - WTCP(0x7fc5ce84, 0x07a00445), WTCP(0x7fb75068, 0x08855802), WTCP(0x7fa736b4, 0x096a9049), WTCP(0x7f95819c, 0x0a4faa38), - WTCP(0x7f82315a, 0x0b34a2ec), WTCP(0x7f6d462b, 0x0c197784), WTCP(0x7f56c053, 0x0cfe251d), WTCP(0x7f3ea01a, 0x0de2a8d7), - WTCP(0x7f24e5cf, 0x0ec6ffd1), WTCP(0x7f0991c4, 0x0fab272b), WTCP(0x7eeca451, 0x108f1c07), WTCP(0x7ece1dd3, 0x1172db86), - WTCP(0x7eadfeae, 0x125662c9), WTCP(0x7e8c4748, 0x1339aef3), WTCP(0x7e68f80e, 0x141cbd28), WTCP(0x7e441171, 0x14ff8a8c), - WTCP(0x7e1d93ea, 0x15e21445), WTCP(0x7df57ff3, 0x16c45777), WTCP(0x7dcbd60e, 0x17a6514a), WTCP(0x7da096c2, 0x1887fee6), - WTCP(0x7d73c299, 0x19695d74), WTCP(0x7d455a24, 0x1a4a6a1c), WTCP(0x7d155df9, 0x1b2b220b), WTCP(0x7ce3ceb2, 0x1c0b826a), - WTCP(0x7cb0acef, 0x1ceb8869), WTCP(0x7c7bf954, 0x1dcb3134), WTCP(0x7c45b48d, 0x1eaa79fa), WTCP(0x7c0ddf47, 0x1f895fed), - WTCP(0x7bd47a36, 0x2067e03e), WTCP(0x7b998614, 0x2145f81f), WTCP(0x7b5d039e, 0x2223a4c5), WTCP(0x7b1ef397, 0x2300e366), - WTCP(0x7adf56c8, 0x23ddb139), WTCP(0x7a9e2dfd, 0x24ba0b76), WTCP(0x7a5b7a09, 0x2595ef56), WTCP(0x7a173bc2, 0x26715a16), - WTCP(0x79d17405, 0x274c48f2), WTCP(0x798a23b1, 0x2826b928), WTCP(0x79414bae, 0x2900a7f9), WTCP(0x78f6ece5, 0x29da12a7), - WTCP(0x78ab0847, 0x2ab2f674), WTCP(0x785d9ec8, 0x2b8b50a5), WTCP(0x780eb161, 0x2c631e82), WTCP(0x77be4111, 0x2d3a5d53), - WTCP(0x776c4edb, 0x2e110a62), WTCP(0x7718dbc8, 0x2ee722fb), WTCP(0x76c3e8e3, 0x2fbca46d), WTCP(0x766d773f, 0x30918c08), - WTCP(0x761587f3, 0x3165d71c), WTCP(0x75bc1c1a, 0x323982ff), WTCP(0x756134d4, 0x330c8d05), WTCP(0x7504d345, 0x33def287), - WTCP(0x74a6f899, 0x34b0b0df), WTCP(0x7447a5fc, 0x3581c569), WTCP(0x73e6dca3, 0x36522d83), WTCP(0x73849dc5, 0x3721e68d), - WTCP(0x7320ea9f, 0x37f0edea), WTCP(0x72bbc472, 0x38bf40ff), WTCP(0x72552c85, 0x398cdd32), WTCP(0x71ed2421, 0x3a59bfee), - WTCP(0x7183ac96, 0x3b25e69e), WTCP(0x7118c739, 0x3bf14eaf), WTCP(0x70ac7560, 0x3cbbf594), WTCP(0x703eb86a, 0x3d85d8bd), - WTCP(0x6fcf91b9, 0x3e4ef5a1), WTCP(0x6f5f02b2, 0x3f1749b8), WTCP(0x6eed0cc0, 0x3fded27c), WTCP(0x6e79b152, 0x40a58d69), - WTCP(0x6e04f1dd, 0x416b7801), WTCP(0x6d8ecfd8, 0x42308fc4), WTCP(0x6d174cc0, 0x42f4d237), WTCP(0x6c9e6a16, 0x43b83ce3), - WTCP(0x6c242960, 0x447acd50), WTCP(0x6ba88c28, 0x453c810d), WTCP(0x6b2b93fd, 0x45fd55a9), WTCP(0x6aad4270, 0x46bd48b7), - WTCP(0x6a2d9919, 0x477c57cb), WTCP(0x69ac9994, 0x483a807f), WTCP(0x692a4580, 0x48f7c06d), WTCP(0x68a69e81, 0x49b41533), - WTCP(0x6821a640, 0x4a6f7c74), WTCP(0x679b5e68, 0x4b29f3d1), WTCP(0x6713c8ac, 0x4be378f4), WTCP(0x668ae6bf, 0x4c9c0985), - WTCP(0x6600ba5b, 0x4d53a332), WTCP(0x6575453d, 0x4e0a43ab), WTCP(0x64e88926, 0x4ebfe8a5), WTCP(0x645a87dd, 0x4f748fd4), - WTCP(0x63cb432a, 0x502836f4), WTCP(0x633abcdc, 0x50dadbc1), WTCP(0x62a8f6c4, 0x518c7bfb), WTCP(0x6215f2b9, 0x523d1567), - WTCP(0x6181b292, 0x52eca5ca), WTCP(0x60ec3830, 0x539b2af0), WTCP(0x60558573, 0x5448a2a5), WTCP(0x5fbd9c41, 0x54f50abb), - WTCP(0x5f247e83, 0x55a06106), WTCP(0x5e8a2e27, 0x564aa35d), WTCP(0x5deead1f, 0x56f3cf9d), WTCP(0x5d51fd5e, 0x579be3a4), - WTCP(0x5cb420e0, 0x5842dd54), WTCP(0x5c15199f, 0x58e8ba94), WTCP(0x5b74e99d, 0x598d794c), WTCP(0x5ad392de, 0x5a31176a) -}; - - -const PWord16 SineWindow256[128] = -{ - WTCP(0x7fffd886, 0x006487e3), WTCP(0x7ffe9cb2, 0x012d96b1), WTCP(0x7ffc250f, 0x01f6a297), WTCP(0x7ff871a2, 0x02bfa9a4), - WTCP(0x7ff38274, 0x0388a9ea), WTCP(0x7fed5791, 0x0451a177), WTCP(0x7fe5f108, 0x051a8e5c), WTCP(0x7fdd4eec, 0x05e36ea9), - WTCP(0x7fd37153, 0x06ac406f), WTCP(0x7fc85854, 0x077501be), WTCP(0x7fbc040a, 0x083db0a7), WTCP(0x7fae7495, 0x09064b3a), - WTCP(0x7f9faa15, 0x09cecf89), WTCP(0x7f8fa4b0, 0x0a973ba5), WTCP(0x7f7e648c, 0x0b5f8d9f), WTCP(0x7f6be9d4, 0x0c27c389), - WTCP(0x7f5834b7, 0x0cefdb76), WTCP(0x7f434563, 0x0db7d376), WTCP(0x7f2d1c0e, 0x0e7fa99e), WTCP(0x7f15b8ee, 0x0f475bff), - WTCP(0x7efd1c3c, 0x100ee8ad), WTCP(0x7ee34636, 0x10d64dbd), WTCP(0x7ec8371a, 0x119d8941), WTCP(0x7eabef2c, 0x1264994e), - WTCP(0x7e8e6eb2, 0x132b7bf9), WTCP(0x7e6fb5f4, 0x13f22f58), WTCP(0x7e4fc53e, 0x14b8b17f), WTCP(0x7e2e9cdf, 0x157f0086), - WTCP(0x7e0c3d29, 0x16451a83), WTCP(0x7de8a670, 0x170afd8d), WTCP(0x7dc3d90d, 0x17d0a7bc), WTCP(0x7d9dd55a, 0x18961728), - WTCP(0x7d769bb5, 0x195b49ea), WTCP(0x7d4e2c7f, 0x1a203e1b), WTCP(0x7d24881b, 0x1ae4f1d6), WTCP(0x7cf9aef0, 0x1ba96335), - WTCP(0x7ccda169, 0x1c6d9053), WTCP(0x7ca05ff1, 0x1d31774d), WTCP(0x7c71eaf9, 0x1df5163f), WTCP(0x7c4242f2, 0x1eb86b46), - WTCP(0x7c116853, 0x1f7b7481), WTCP(0x7bdf5b94, 0x203e300d), WTCP(0x7bac1d31, 0x21009c0c), WTCP(0x7b77ada8, 0x21c2b69c), - WTCP(0x7b420d7a, 0x22847de0), WTCP(0x7b0b3d2c, 0x2345eff8), WTCP(0x7ad33d45, 0x24070b08), WTCP(0x7a9a0e50, 0x24c7cd33), - WTCP(0x7a5fb0d8, 0x2588349d), WTCP(0x7a24256f, 0x26483f6c), WTCP(0x79e76ca7, 0x2707ebc7), WTCP(0x79a98715, 0x27c737d3), - WTCP(0x796a7554, 0x288621b9), WTCP(0x792a37fe, 0x2944a7a2), WTCP(0x78e8cfb2, 0x2a02c7b8), WTCP(0x78a63d11, 0x2ac08026), - WTCP(0x786280bf, 0x2b7dcf17), WTCP(0x781d9b65, 0x2c3ab2b9), WTCP(0x77d78daa, 0x2cf72939), WTCP(0x7790583e, 0x2db330c7), - WTCP(0x7747fbce, 0x2e6ec792), WTCP(0x76fe790e, 0x2f29ebcc), WTCP(0x76b3d0b4, 0x2fe49ba7), WTCP(0x76680376, 0x309ed556), - WTCP(0x761b1211, 0x3158970e), WTCP(0x75ccfd42, 0x3211df04), WTCP(0x757dc5ca, 0x32caab6f), WTCP(0x752d6c6c, 0x3382fa88), - WTCP(0x74dbf1ef, 0x343aca87), WTCP(0x7489571c, 0x34f219a8), WTCP(0x74359cbd, 0x35a8e625), WTCP(0x73e0c3a3, 0x365f2e3b), - WTCP(0x738acc9e, 0x3714f02a), WTCP(0x7333b883, 0x37ca2a30), WTCP(0x72db8828, 0x387eda8e), WTCP(0x72823c67, 0x3932ff87), - WTCP(0x7227d61c, 0x39e6975e), WTCP(0x71cc5626, 0x3a99a057), WTCP(0x716fbd68, 0x3b4c18ba), WTCP(0x71120cc5, 0x3bfdfecd), - WTCP(0x70b34525, 0x3caf50da), WTCP(0x70536771, 0x3d600d2c), WTCP(0x6ff27497, 0x3e10320d), WTCP(0x6f906d84, 0x3ebfbdcd), - WTCP(0x6f2d532c, 0x3f6eaeb8), WTCP(0x6ec92683, 0x401d0321), WTCP(0x6e63e87f, 0x40cab958), WTCP(0x6dfd9a1c, 0x4177cfb1), - WTCP(0x6d963c54, 0x42244481), WTCP(0x6d2dd027, 0x42d0161e), WTCP(0x6cc45698, 0x437b42e1), WTCP(0x6c59d0a9, 0x4425c923), - WTCP(0x6bee3f62, 0x44cfa740), WTCP(0x6b81a3cd, 0x4578db93), WTCP(0x6b13fef5, 0x4621647d), WTCP(0x6aa551e9, 0x46c9405c), - WTCP(0x6a359db9, 0x47706d93), WTCP(0x69c4e37a, 0x4816ea86), WTCP(0x69532442, 0x48bcb599), WTCP(0x68e06129, 0x4961cd33), - WTCP(0x686c9b4b, 0x4a062fbd), WTCP(0x67f7d3c5, 0x4aa9dba2), WTCP(0x67820bb7, 0x4b4ccf4d), WTCP(0x670b4444, 0x4bef092d), - WTCP(0x66937e91, 0x4c9087b1), WTCP(0x661abbc5, 0x4d31494b), WTCP(0x65a0fd0b, 0x4dd14c6e), WTCP(0x6526438f, 0x4e708f8f), - WTCP(0x64aa907f, 0x4f0f1126), WTCP(0x642de50d, 0x4faccfab), WTCP(0x63b0426d, 0x5049c999), WTCP(0x6331a9d4, 0x50e5fd6d), - WTCP(0x62b21c7b, 0x518169a5), WTCP(0x62319b9d, 0x521c0cc2), WTCP(0x61b02876, 0x52b5e546), WTCP(0x612dc447, 0x534ef1b5), - WTCP(0x60aa7050, 0x53e73097), WTCP(0x60262dd6, 0x547ea073), WTCP(0x5fa0fe1f, 0x55153fd4), WTCP(0x5f1ae274, 0x55ab0d46), - WTCP(0x5e93dc1f, 0x56400758), WTCP(0x5e0bec6e, 0x56d42c99), WTCP(0x5d8314b1, 0x57677b9d), WTCP(0x5cf95638, 0x57f9f2f8), - WTCP(0x5c6eb258, 0x588b9140), WTCP(0x5be32a67, 0x591c550e), WTCP(0x5b56bfbd, 0x59ac3cfd), WTCP(0x5ac973b5, 0x5a3b47ab), -}; - -const PWord16 SineWindow280[140] = -{ - WTCP(0x7fffdf00, 0x005be9f6), WTCP(0x7ffed6ff, 0x0113bd23), WTCP(0x7ffcc6ff, 0x01cb8e18), WTCP(0x7ff9af04, 0x02835b5a), - WTCP(0x7ff58f15, 0x033b236c), WTCP(0x7ff0673a, 0x03f2e4d4), WTCP(0x7fea377e, 0x04aa9e17), WTCP(0x7fe2ffee, 0x05624dba), - WTCP(0x7fdac098, 0x0619f243), WTCP(0x7fd1798e, 0x06d18a36), WTCP(0x7fc72ae2, 0x07891418), WTCP(0x7fbbd4aa, 0x08408e70), - WTCP(0x7faf76fe, 0x08f7f7c3), WTCP(0x7fa211f6, 0x09af4e96), WTCP(0x7f93a5af, 0x0a66916f), WTCP(0x7f843246, 0x0b1dbed5), - WTCP(0x7f73b7da, 0x0bd4d54d), WTCP(0x7f62368f, 0x0c8bd35e), WTCP(0x7f4fae88, 0x0d42b78f), WTCP(0x7f3c1fec, 0x0df98066), - WTCP(0x7f278ae1, 0x0eb02c6a), WTCP(0x7f11ef95, 0x0f66ba22), WTCP(0x7efb4e31, 0x101d2817), WTCP(0x7ee3a6e7, 0x10d374cf), - WTCP(0x7ecaf9e5, 0x11899ed3), WTCP(0x7eb1475f, 0x123fa4ab), WTCP(0x7e968f8b, 0x12f584e0), WTCP(0x7e7ad29e, 0x13ab3dfa), - WTCP(0x7e5e10d3, 0x1460ce82), WTCP(0x7e404a65, 0x15163503), WTCP(0x7e217f90, 0x15cb7006), WTCP(0x7e01b096, 0x16807e15), - WTCP(0x7de0ddb6, 0x17355dba), WTCP(0x7dbf0736, 0x17ea0d81), WTCP(0x7d9c2d5a, 0x189e8bf6), WTCP(0x7d78506a, 0x1952d7a3), - WTCP(0x7d5370b2, 0x1a06ef15), WTCP(0x7d2d8e7b, 0x1abad0d8), WTCP(0x7d06aa16, 0x1b6e7b7a), WTCP(0x7cdec3d2, 0x1c21ed87), - WTCP(0x7cb5dc00, 0x1cd5258f), WTCP(0x7c8bf2f7, 0x1d88221e), WTCP(0x7c61090b, 0x1e3ae1c5), WTCP(0x7c351e96, 0x1eed6311), - WTCP(0x7c0833f3, 0x1f9fa494), WTCP(0x7bda497d, 0x2051a4dd), WTCP(0x7bab5f93, 0x2103627d), WTCP(0x7b7b7697, 0x21b4dc06), - WTCP(0x7b4a8eeb, 0x2266100a), WTCP(0x7b18a8f4, 0x2316fd1b), WTCP(0x7ae5c518, 0x23c7a1cc), WTCP(0x7ab1e3c2, 0x2477fcb1), - WTCP(0x7a7d055b, 0x25280c5e), WTCP(0x7a472a51, 0x25d7cf68), WTCP(0x7a105313, 0x26874464), WTCP(0x79d88013, 0x273669e9), - WTCP(0x799fb1c2, 0x27e53e8e), WTCP(0x7965e897, 0x2893c0e9), WTCP(0x792b2508, 0x2941ef93), WTCP(0x78ef678f, 0x29efc925), - WTCP(0x78b2b0a7, 0x2a9d4c38), WTCP(0x787500ce, 0x2b4a7766), WTCP(0x78365881, 0x2bf7494a), WTCP(0x77f6b844, 0x2ca3c07f), - WTCP(0x77b62098, 0x2d4fdba2), WTCP(0x77749203, 0x2dfb9950), WTCP(0x77320d0d, 0x2ea6f827), WTCP(0x76ee923e, 0x2f51f6c4), - WTCP(0x76aa2222, 0x2ffc93c9), WTCP(0x7664bd46, 0x30a6cdd3), WTCP(0x761e6439, 0x3150a385), WTCP(0x75d7178c, 0x31fa1381), - WTCP(0x758ed7d2, 0x32a31c68), WTCP(0x7545a5a0, 0x334bbcde), WTCP(0x74fb818e, 0x33f3f387), WTCP(0x74b06c33, 0x349bbf09), - WTCP(0x7464662c, 0x35431e09), WTCP(0x74177014, 0x35ea0f2e), WTCP(0x73c98a8a, 0x36909120), WTCP(0x737ab630, 0x3736a287), - WTCP(0x732af3a7, 0x37dc420c), WTCP(0x72da4395, 0x38816e5b), WTCP(0x7288a69f, 0x3926261e), WTCP(0x72361d6e, 0x39ca6802), - WTCP(0x71e2a8ad, 0x3a6e32b4), WTCP(0x718e4907, 0x3b1184e2), WTCP(0x7138ff2a, 0x3bb45d3b), WTCP(0x70e2cbc6, 0x3c56ba70), - WTCP(0x708baf8d, 0x3cf89b31), WTCP(0x7033ab34, 0x3d99fe31), WTCP(0x6fdabf6e, 0x3e3ae223), WTCP(0x6f80ecf4, 0x3edb45ba), - WTCP(0x6f26347f, 0x3f7b27ac), WTCP(0x6eca96ca, 0x401a86b0), WTCP(0x6e6e1492, 0x40b9617d), WTCP(0x6e10ae96, 0x4157b6ca), - WTCP(0x6db26597, 0x41f58552), WTCP(0x6d533a56, 0x4292cbcf), WTCP(0x6cf32d99, 0x432f88fc), WTCP(0x6c924024, 0x43cbbb97), - WTCP(0x6c3072c1, 0x4467625d), WTCP(0x6bcdc639, 0x45027c0c), WTCP(0x6b6a3b58, 0x459d0766), WTCP(0x6b05d2ea, 0x4637032c), - WTCP(0x6aa08dbf, 0x46d06e1f), WTCP(0x6a3a6ca8, 0x47694703), WTCP(0x69d37078, 0x48018c9e), WTCP(0x696b9a02, 0x48993db5), - WTCP(0x6902ea1d, 0x4930590f), WTCP(0x689961a1, 0x49c6dd74), WTCP(0x682f0167, 0x4a5cc9af), WTCP(0x67c3ca4c, 0x4af21c89), - WTCP(0x6757bd2b, 0x4b86d4cf), WTCP(0x66eadae5, 0x4c1af14f), WTCP(0x667d2459, 0x4cae70d6), WTCP(0x660e9a6a, 0x4d415234), - WTCP(0x659f3dfc, 0x4dd3943b), WTCP(0x652f0ff4, 0x4e6535bd), WTCP(0x64be113a, 0x4ef6358d), WTCP(0x644c42b8, 0x4f869280), - WTCP(0x63d9a556, 0x50164b6d), WTCP(0x63663a03, 0x50a55f2c), WTCP(0x62f201ac, 0x5133cc94), WTCP(0x627cfd41, 0x51c19281), - WTCP(0x62072db3, 0x524eafce), WTCP(0x619093f5, 0x52db2357), WTCP(0x611930fc, 0x5366ebfc), WTCP(0x60a105be, 0x53f2089b), - WTCP(0x60281333, 0x547c7817), WTCP(0x5fae5a55, 0x55063951), WTCP(0x5f33dc1d, 0x558f4b2d), WTCP(0x5eb8998a, 0x5617ac90), - WTCP(0x5e3c9399, 0x569f5c62), WTCP(0x5dbfcb4a, 0x5726598b), WTCP(0x5d42419f, 0x57aca2f3), WTCP(0x5cc3f79a, 0x58323787), - WTCP(0x5c44ee40, 0x58b71632), WTCP(0x5bc52696, 0x593b3de2), WTCP(0x5b44a1a5, 0x59bead87), WTCP(0x5ac36076, 0x5a416413) -}; - -const PWord16 SineWindow320[160] = -{ - WTCP(0x7fffe6bc, 0x00506cb9), WTCP(0x7fff1c9b, 0x00f145ab), WTCP(0x7ffd885a, 0x01921d20), WTCP(0x7ffb29fd, 0x0232f21a), - WTCP(0x7ff80186, 0x02d3c39b), WTCP(0x7ff40efa, 0x037490a5), WTCP(0x7fef5260, 0x0415583b), WTCP(0x7fe9cbc0, 0x04b6195d), - WTCP(0x7fe37b22, 0x0556d30f), WTCP(0x7fdc608f, 0x05f78453), WTCP(0x7fd47c14, 0x06982c2b), WTCP(0x7fcbcdbc, 0x0738c998), - WTCP(0x7fc25596, 0x07d95b9e), WTCP(0x7fb813b0, 0x0879e140), WTCP(0x7fad081b, 0x091a597e), WTCP(0x7fa132e8, 0x09bac35d), - WTCP(0x7f949429, 0x0a5b1dde), WTCP(0x7f872bf3, 0x0afb6805), WTCP(0x7f78fa5b, 0x0b9ba0d5), WTCP(0x7f69ff76, 0x0c3bc74f), - WTCP(0x7f5a3b5e, 0x0cdbda79), WTCP(0x7f49ae2a, 0x0d7bd954), WTCP(0x7f3857f6, 0x0e1bc2e4), WTCP(0x7f2638db, 0x0ebb962c), - WTCP(0x7f1350f8, 0x0f5b5231), WTCP(0x7effa069, 0x0ffaf5f6), WTCP(0x7eeb274d, 0x109a807e), WTCP(0x7ed5e5c6, 0x1139f0cf), - WTCP(0x7ebfdbf5, 0x11d945eb), WTCP(0x7ea909fc, 0x12787ed8), WTCP(0x7e917000, 0x13179a9b), WTCP(0x7e790e25, 0x13b69836), - WTCP(0x7e5fe493, 0x145576b1), WTCP(0x7e45f371, 0x14f43510), WTCP(0x7e2b3ae8, 0x1592d257), WTCP(0x7e0fbb22, 0x16314d8e), - WTCP(0x7df3744b, 0x16cfa5b9), WTCP(0x7dd6668f, 0x176dd9de), WTCP(0x7db8921c, 0x180be904), WTCP(0x7d99f721, 0x18a9d231), - WTCP(0x7d7a95cf, 0x1947946c), WTCP(0x7d5a6e57, 0x19e52ebb), WTCP(0x7d3980ec, 0x1a82a026), WTCP(0x7d17cdc2, 0x1b1fe7b3), - WTCP(0x7cf5550e, 0x1bbd046c), WTCP(0x7cd21707, 0x1c59f557), WTCP(0x7cae13e4, 0x1cf6b97c), WTCP(0x7c894bde, 0x1d934fe5), - WTCP(0x7c63bf2f, 0x1e2fb79a), WTCP(0x7c3d6e13, 0x1ecbefa4), WTCP(0x7c1658c5, 0x1f67f70b), WTCP(0x7bee7f85, 0x2003ccdb), - WTCP(0x7bc5e290, 0x209f701c), WTCP(0x7b9c8226, 0x213adfda), WTCP(0x7b725e8a, 0x21d61b1e), WTCP(0x7b4777fe, 0x227120f3), - WTCP(0x7b1bcec4, 0x230bf065), WTCP(0x7aef6323, 0x23a6887f), WTCP(0x7ac23561, 0x2440e84d), WTCP(0x7a9445c5, 0x24db0edb), - WTCP(0x7a659496, 0x2574fb36), WTCP(0x7a362220, 0x260eac6a), WTCP(0x7a05eead, 0x26a82186), WTCP(0x79d4fa89, 0x27415996), - WTCP(0x79a34602, 0x27da53a9), WTCP(0x7970d165, 0x28730ecd), WTCP(0x793d9d03, 0x290b8a12), WTCP(0x7909a92d, 0x29a3c485), - WTCP(0x78d4f634, 0x2a3bbd37), WTCP(0x789f846b, 0x2ad37338), WTCP(0x78695428, 0x2b6ae598), WTCP(0x783265c0, 0x2c021369), - WTCP(0x77fab989, 0x2c98fbba), WTCP(0x77c24fdb, 0x2d2f9d9f), WTCP(0x77892910, 0x2dc5f829), WTCP(0x774f4581, 0x2e5c0a6b), - WTCP(0x7714a58b, 0x2ef1d377), WTCP(0x76d94989, 0x2f875262), WTCP(0x769d31d9, 0x301c863f), WTCP(0x76605edb, 0x30b16e23), - WTCP(0x7622d0ef, 0x31460922), WTCP(0x75e48874, 0x31da5651), WTCP(0x75a585cf, 0x326e54c7), WTCP(0x7565c962, 0x3302039b), - WTCP(0x75255392, 0x339561e1), WTCP(0x74e424c5, 0x34286eb3), WTCP(0x74a23d62, 0x34bb2927), WTCP(0x745f9dd1, 0x354d9057), - WTCP(0x741c467b, 0x35dfa35a), WTCP(0x73d837ca, 0x3671614b), WTCP(0x7393722a, 0x3702c942), WTCP(0x734df607, 0x3793da5b), - WTCP(0x7307c3d0, 0x382493b0), WTCP(0x72c0dbf3, 0x38b4f45d), WTCP(0x72793edf, 0x3944fb7e), WTCP(0x7230ed07, 0x39d4a82f), - WTCP(0x71e7e6dc, 0x3a63f98d), WTCP(0x719e2cd2, 0x3af2eeb7), WTCP(0x7153bf5d, 0x3b8186ca), WTCP(0x71089ef2, 0x3c0fc0e6), - WTCP(0x70bccc09, 0x3c9d9c28), WTCP(0x70704718, 0x3d2b17b3), WTCP(0x7023109a, 0x3db832a6), WTCP(0x6fd52907, 0x3e44ec22), - WTCP(0x6f8690db, 0x3ed14349), WTCP(0x6f374891, 0x3f5d373e), WTCP(0x6ee750a8, 0x3fe8c724), WTCP(0x6e96a99d, 0x4073f21d), - WTCP(0x6e4553ef, 0x40feb74f), WTCP(0x6df35020, 0x418915de), WTCP(0x6da09eb1, 0x42130cf0), WTCP(0x6d4d4023, 0x429c9bab), - WTCP(0x6cf934fc, 0x4325c135), WTCP(0x6ca47dbf, 0x43ae7cb7), WTCP(0x6c4f1af2, 0x4436cd58), WTCP(0x6bf90d1d, 0x44beb240), - WTCP(0x6ba254c7, 0x45462a9a), WTCP(0x6b4af279, 0x45cd358f), WTCP(0x6af2e6bc, 0x4653d24b), WTCP(0x6a9a321d, 0x46d9fff8), - WTCP(0x6a40d527, 0x475fbdc3), WTCP(0x69e6d067, 0x47e50ad8), WTCP(0x698c246c, 0x4869e665), WTCP(0x6930d1c4, 0x48ee4f98), - WTCP(0x68d4d900, 0x497245a1), WTCP(0x68783ab1, 0x49f5c7ae), WTCP(0x681af76a, 0x4a78d4f0), WTCP(0x67bd0fbd, 0x4afb6c98), - WTCP(0x675e843e, 0x4b7d8dd8), WTCP(0x66ff5584, 0x4bff37e2), WTCP(0x669f8425, 0x4c8069ea), WTCP(0x663f10b7, 0x4d012324), - WTCP(0x65ddfbd3, 0x4d8162c4), WTCP(0x657c4613, 0x4e012800), WTCP(0x6519f010, 0x4e80720e), WTCP(0x64b6fa66, 0x4eff4025), - WTCP(0x645365b2, 0x4f7d917c), WTCP(0x63ef3290, 0x4ffb654d), WTCP(0x638a619e, 0x5078bad1), WTCP(0x6324f37d, 0x50f59141), - WTCP(0x62bee8cc, 0x5171e7d9), WTCP(0x6258422c, 0x51edbdd4), WTCP(0x61f1003f, 0x5269126e), WTCP(0x618923a9, 0x52e3e4e6), - WTCP(0x6120ad0d, 0x535e3479), WTCP(0x60b79d10, 0x53d80065), WTCP(0x604df459, 0x545147eb), WTCP(0x5fe3b38d, 0x54ca0a4b), - WTCP(0x5f78db56, 0x554246c6), WTCP(0x5f0d6c5b, 0x55b9fc9e), WTCP(0x5ea16747, 0x56312b17), WTCP(0x5e34ccc3, 0x56a7d174), - WTCP(0x5dc79d7c, 0x571deefa), WTCP(0x5d59da1e, 0x579382ee), WTCP(0x5ceb8355, 0x58088c96), WTCP(0x5c7c99d1, 0x587d0b3b), - WTCP(0x5c0d1e41, 0x58f0fe23), WTCP(0x5b9d1154, 0x59646498), WTCP(0x5b2c73bb, 0x59d73de3), WTCP(0x5abb4629, 0x5a498950), -}; - - -const PWord16 SineWindow420[210] = -{ - WTCP(0x7ffff155, 0x003d46a7), WTCP(0x7fff7bff, 0x00b7d3bc), WTCP(0x7ffe9154, 0x01326029), WTCP(0x7ffd3154, 0x01aceb7c), - WTCP(0x7ffb5c00, 0x02277547), WTCP(0x7ff9115b, 0x02a1fd18), WTCP(0x7ff65166, 0x031c8280), WTCP(0x7ff31c25, 0x0397050d), - WTCP(0x7fef7199, 0x0411844f), WTCP(0x7feb51c6, 0x048bffd7), WTCP(0x7fe6bcb0, 0x05067734), WTCP(0x7fe1b25b, 0x0580e9f6), - WTCP(0x7fdc32cc, 0x05fb57ac), WTCP(0x7fd63e09, 0x0675bfe7), WTCP(0x7fcfd415, 0x06f02235), WTCP(0x7fc8f4f7, 0x076a7e27), - WTCP(0x7fc1a0b6, 0x07e4d34d), WTCP(0x7fb9d759, 0x085f2137), WTCP(0x7fb198e5, 0x08d96773), WTCP(0x7fa8e564, 0x0953a594), - WTCP(0x7f9fbcdc, 0x09cddb27), WTCP(0x7f961f57, 0x0a4807be), WTCP(0x7f8c0cdc, 0x0ac22ae8), WTCP(0x7f818577, 0x0b3c4435), - WTCP(0x7f76892f, 0x0bb65336), WTCP(0x7f6b180f, 0x0c30577a), WTCP(0x7f5f3221, 0x0caa5092), WTCP(0x7f52d771, 0x0d243e0d), - WTCP(0x7f46080a, 0x0d9e1f7d), WTCP(0x7f38c3f7, 0x0e17f471), WTCP(0x7f2b0b45, 0x0e91bc79), WTCP(0x7f1cde01, 0x0f0b7727), - WTCP(0x7f0e3c36, 0x0f85240a), WTCP(0x7eff25f3, 0x0ffec2b3), WTCP(0x7eef9b46, 0x107852b2), WTCP(0x7edf9c3c, 0x10f1d398), - WTCP(0x7ecf28e5, 0x116b44f6), WTCP(0x7ebe414f, 0x11e4a65c), WTCP(0x7eace58a, 0x125df75b), WTCP(0x7e9b15a6, 0x12d73784), - WTCP(0x7e88d1b4, 0x13506668), WTCP(0x7e7619c3, 0x13c98397), WTCP(0x7e62ede5, 0x14428ea2), WTCP(0x7e4f4e2c, 0x14bb871b), - WTCP(0x7e3b3aaa, 0x15346c93), WTCP(0x7e26b371, 0x15ad3e9a), WTCP(0x7e11b894, 0x1625fcc3), WTCP(0x7dfc4a26, 0x169ea69e), - WTCP(0x7de6683a, 0x17173bbd), WTCP(0x7dd012e6, 0x178fbbb1), WTCP(0x7db94a3c, 0x1808260c), WTCP(0x7da20e53, 0x18807a5f), - WTCP(0x7d8a5f40, 0x18f8b83c), WTCP(0x7d723d18, 0x1970df36), WTCP(0x7d59a7f1, 0x19e8eedd), WTCP(0x7d409fe1, 0x1a60e6c3), - WTCP(0x7d272501, 0x1ad8c67c), WTCP(0x7d0d3767, 0x1b508d98), WTCP(0x7cf2d72b, 0x1bc83baa), WTCP(0x7cd80464, 0x1c3fd045), - WTCP(0x7cbcbf2d, 0x1cb74afa), WTCP(0x7ca1079d, 0x1d2eab5d), WTCP(0x7c84ddcf, 0x1da5f0ff), WTCP(0x7c6841db, 0x1e1d1b73), - WTCP(0x7c4b33dc, 0x1e942a4d), WTCP(0x7c2db3ee, 0x1f0b1d1f), WTCP(0x7c0fc22a, 0x1f81f37c), WTCP(0x7bf15eac, 0x1ff8acf7), - WTCP(0x7bd28991, 0x206f4923), WTCP(0x7bb342f3, 0x20e5c793), WTCP(0x7b938af1, 0x215c27dc), WTCP(0x7b7361a7, 0x21d2698f), - WTCP(0x7b52c733, 0x22488c42), WTCP(0x7b31bbb2, 0x22be8f87), WTCP(0x7b103f43, 0x233472f3), WTCP(0x7aee5205, 0x23aa361a), - WTCP(0x7acbf416, 0x241fd88e), WTCP(0x7aa92596, 0x249559e6), WTCP(0x7a85e6a5, 0x250ab9b4), WTCP(0x7a623764, 0x257ff78e), - WTCP(0x7a3e17f2, 0x25f51307), WTCP(0x7a198872, 0x266a0bb5), WTCP(0x79f48904, 0x26dee12c), WTCP(0x79cf19cb, 0x27539302), - WTCP(0x79a93ae9, 0x27c820ca), WTCP(0x7982ec80, 0x283c8a1b), WTCP(0x795c2eb5, 0x28b0ce8a), WTCP(0x793501a9, 0x2924edac), - WTCP(0x790d6581, 0x2998e716), WTCP(0x78e55a62, 0x2a0cba5e), WTCP(0x78bce070, 0x2a80671b), WTCP(0x7893f7d1, 0x2af3ece2), - WTCP(0x786aa0a9, 0x2b674b49), WTCP(0x7840db1f, 0x2bda81e6), WTCP(0x7816a759, 0x2c4d9050), WTCP(0x77ec057d, 0x2cc0761e), - WTCP(0x77c0f5b3, 0x2d3332e5), WTCP(0x77957822, 0x2da5c63e), WTCP(0x77698cf3, 0x2e182fbe), WTCP(0x773d344d, 0x2e8a6efd), - WTCP(0x77106e58, 0x2efc8393), WTCP(0x76e33b3f, 0x2f6e6d16), WTCP(0x76b59b2a, 0x2fe02b1e), WTCP(0x76878e43, 0x3051bd43), - WTCP(0x765914b5, 0x30c3231d), WTCP(0x762a2eaa, 0x31345c44), WTCP(0x75fadc4d, 0x31a56850), WTCP(0x75cb1dca, 0x321646d9), - WTCP(0x759af34c, 0x3286f779), WTCP(0x756a5cff, 0x32f779c7), WTCP(0x75395b10, 0x3367cd5d), WTCP(0x7507edac, 0x33d7f1d3), - WTCP(0x74d61500, 0x3447e6c3), WTCP(0x74a3d13a, 0x34b7abc6), WTCP(0x74712288, 0x35274076), WTCP(0x743e0918, 0x3596a46c), - WTCP(0x740a8519, 0x3605d743), WTCP(0x73d696bb, 0x3674d894), WTCP(0x73a23e2d, 0x36e3a7fa), WTCP(0x736d7b9f, 0x3752450f), - WTCP(0x73384f41, 0x37c0af6d), WTCP(0x7302b945, 0x382ee6b0), WTCP(0x72ccb9db, 0x389cea72), WTCP(0x72965134, 0x390aba4f), - WTCP(0x725f7f84, 0x397855e1), WTCP(0x722844fb, 0x39e5bcc5), WTCP(0x71f0a1cc, 0x3a52ee96), WTCP(0x71b8962b, 0x3abfeaf1), - WTCP(0x7180224b, 0x3b2cb170), WTCP(0x71474660, 0x3b9941b1), WTCP(0x710e029e, 0x3c059b4f), WTCP(0x70d45738, 0x3c71bde8), - WTCP(0x709a4465, 0x3cdda919), WTCP(0x705fca59, 0x3d495c7e), WTCP(0x7024e94b, 0x3db4d7b5), WTCP(0x6fe9a16f, 0x3e201a5b), - WTCP(0x6fadf2fc, 0x3e8b240e), WTCP(0x6f71de2a, 0x3ef5f46c), WTCP(0x6f35632e, 0x3f608b13), WTCP(0x6ef88241, 0x3fcae7a1), - WTCP(0x6ebb3b9a, 0x403509b4), WTCP(0x6e7d8f72, 0x409ef0ed), WTCP(0x6e3f7e01, 0x41089ce8), WTCP(0x6e010780, 0x41720d46), - WTCP(0x6dc22c28, 0x41db41a5), WTCP(0x6d82ec32, 0x424439a6), WTCP(0x6d4347da, 0x42acf4e8), WTCP(0x6d033f58, 0x4315730c), - WTCP(0x6cc2d2e9, 0x437db3b0), WTCP(0x6c8202c6, 0x43e5b676), WTCP(0x6c40cf2c, 0x444d7aff), WTCP(0x6bff3855, 0x44b500eb), - WTCP(0x6bbd3e7f, 0x451c47dc), WTCP(0x6b7ae1e6, 0x45834f72), WTCP(0x6b3822c6, 0x45ea1750), WTCP(0x6af5015c, 0x46509f16), - WTCP(0x6ab17de7, 0x46b6e668), WTCP(0x6a6d98a4, 0x471cece7), WTCP(0x6a2951d2, 0x4782b236), WTCP(0x69e4a9ae, 0x47e835f7), - WTCP(0x699fa078, 0x484d77ce), WTCP(0x695a366f, 0x48b2775d), WTCP(0x69146bd3, 0x49173448), WTCP(0x68ce40e4, 0x497bae33), - WTCP(0x6887b5e2, 0x49dfe4c2), WTCP(0x6840cb0e, 0x4a43d799), WTCP(0x67f980a8, 0x4aa7865b), WTCP(0x67b1d6f3, 0x4b0af0ae), - WTCP(0x6769ce2f, 0x4b6e1637), WTCP(0x6721669f, 0x4bd0f69b), WTCP(0x66d8a085, 0x4c33917f), WTCP(0x668f7c25, 0x4c95e688), - WTCP(0x6645f9c0, 0x4cf7f55d), WTCP(0x65fc199a, 0x4d59bda3), WTCP(0x65b1dbf8, 0x4dbb3f02), WTCP(0x6567411d, 0x4e1c791f), - WTCP(0x651c494d, 0x4e7d6ba2), WTCP(0x64d0f4ce, 0x4ede1631), WTCP(0x648543e4, 0x4f3e7875), WTCP(0x643936d4, 0x4f9e9214), - WTCP(0x63eccde5, 0x4ffe62b6), WTCP(0x63a0095c, 0x505dea05), WTCP(0x6352e980, 0x50bd27a7), WTCP(0x63056e98, 0x511c1b47), - WTCP(0x62b798ea, 0x517ac48c), WTCP(0x626968be, 0x51d92321), WTCP(0x621ade5c, 0x523736ae), WTCP(0x61cbfa0b, 0x5294fedd), - WTCP(0x617cbc14, 0x52f27b58), WTCP(0x612d24c0, 0x534fabcb), WTCP(0x60dd3457, 0x53ac8fde), WTCP(0x608ceb22, 0x5409273e), - WTCP(0x603c496c, 0x54657194), WTCP(0x5feb4f7f, 0x54c16e8e), WTCP(0x5f99fda4, 0x551d1dd5), WTCP(0x5f485426, 0x55787f17), - WTCP(0x5ef6534f, 0x55d391ff), WTCP(0x5ea3fb6c, 0x562e563a), WTCP(0x5e514cc8, 0x5688cb75), WTCP(0x5dfe47ad, 0x56e2f15d), - WTCP(0x5daaec6a, 0x573cc79f), WTCP(0x5d573b49, 0x57964de9), WTCP(0x5d033497, 0x57ef83e9), WTCP(0x5caed8a2, 0x5848694d), - WTCP(0x5c5a27b8, 0x58a0fdc3), WTCP(0x5c052224, 0x58f940fa), WTCP(0x5bafc837, 0x595132a2), WTCP(0x5b5a1a3d, 0x59a8d26a), - WTCP(0x5b041885, 0x5a002001), WTCP(0x5aadc35e, 0x5a571b18) -}; - - - - -/** - * \brief Helper table containing the length, rasterand shape mapping to individual window slope tables. - * [0: sine ][0: radix2 raster ][ceil(log2(length)) length 4 .. 1024 ] - * [1: 640 raster - */ -const PWord16 *const windowSlopes[1][2][8] = -{ - { /* Sine */ - { /* Radix 2 */ - NULL, - NULL, - SineWindow16, - SineWindow32, - SineWindow64, - SineWindow128, - SineWindow256, - NULL - }, - { /* 640 raster */ - NULL, /* 2.5 */ - NULL, /* 5 */ - SineWindow10, - SineWindow20, - SineWindow40, - SineWindow80, - SineWindow160, - SineWindow320 - }, - } -}; - -#define DCTIV_SINETABLE SineTable512 -#define DCTIV_SINETABLE_SIZE_LD 9 - -#define DCTIV_SINETABLE320 SineTable320 -#define DCTIV_SINETABLE320_SIZE_LD 8 - -void BASOP_getTables(const PWord16 **ptwiddle, const PWord16 **sin_twiddle, Word16 *psin_step, Word16 length) -{ - const PWord16 *twiddle; - const PWord16 *sine; - Word16 ld2_length, sin_step; - - /* Get ld2 of length - 2 + 1 - -2: because first table entry is window of size 4 - +1: because we already include +1 because of ceil(log2(length)) */ - ld2_length = sub(16 -1 -1, norm_s(length)); - - /* Extract sort of "eigenvalue" (the 5 left most bits) of length. */ - SWITCH ( (unsigned short)lshl(length, sub(15, ld2_length) ) ) - { - case 0xa000: /* 640 */ - move16(); - move16(); - sine = DCTIV_SINETABLE320; - sin_step = shl(1, sub(DCTIV_SINETABLE320_SIZE_LD+1, ld2_length)); - twiddle = windowSlopes[0][1][sub(ld2_length,1)]; - BREAK; - - case 0x8000: /* radix 2 */ - move16(); - move16(); - sine = DCTIV_SINETABLE; - sin_step = shl(1, sub(DCTIV_SINETABLE_SIZE_LD+1, ld2_length)); - twiddle = windowSlopes[0][0][sub(ld2_length,2)]; - BREAK; - - default: /* not instrumented, probably obsolete */ - sine = NULL; - sin_step = 0; - twiddle = NULL; - BREAK; - } - - if (ptwiddle != NULL) - { - assert(twiddle != NULL || length == 0); - move16(); - *ptwiddle = twiddle; - } - - if (sin_twiddle != NULL) - { - move16(); - *sin_twiddle = sine; - } - if ( psin_step != NULL ) - { - assert(sin_step > 0 || length == 0); - move16(); - *psin_step = sin_step; - } -} - -const PWord16* getSineWindowTable(Word16 length) -{ - const PWord16 *p = NULL; - - switch (length) - { - case 10: - p = SineWindow10; - BREAK; - case 16: - p = SineWindow16; - BREAK; - case 20: - p = SineWindow20; - BREAK; - case 30: - p = SineWindow30; - BREAK; - case 32: - p = SineWindow32; - BREAK; - case 40: - p = SineWindow40; - BREAK; - case 48: - p = SineWindow48; - BREAK; - case 60: - p = SineWindow60; - BREAK; - case 70: - p = SineWindow70; - BREAK; - case 96: - p = SineWindow96; - BREAK; - case 112: - p = SineWindow112; - BREAK; - case 120: - p = SineWindow120; - BREAK; - case 140: - p = SineWindow140; - BREAK; - case 180: - p = SineWindow180; - BREAK; - case 224: - p = SineWindow224; - BREAK; - case 280: - p = SineWindow280; - BREAK; - case 420: - p = SineWindow420; - BREAK; - } - - assert(p != NULL); - - return p; -} - diff --git a/src/libs/libevs/lib_com/rom_basop_util.h b/src/libs/libevs/lib_com/rom_basop_util.h deleted file mode 100755 index 4d2a5e0c..00000000 --- a/src/libs/libevs/lib_com/rom_basop_util.h +++ /dev/null @@ -1,81 +0,0 @@ -/*==================================================================================== - EVS Codec 3GPP TS26.442 Apr 03, 2018. Version 12.11.0 / 13.6.0 / 14.2.0 - ====================================================================================*/ - -#ifndef __BASOP_UTIL_ROM_H__ -#define __BASOP_UTIL_ROM_H__ - -#include "typedef.h" -#include "basop_util.h" - -#define LD_INT_TAB_LEN 120 -#define INV_TABLE_SIZE 256 -#define SQRT_TABLE_SIZE 256 - -#ifndef CHEAP_NORM_SIZE -#define CHEAP_NORM_SIZE 161 -#endif - -#define MINSFTAB 7 -#define MAXSFTAB 25 - -/** - * \brief Lookup-Table for binary logarithm - */ -extern const Word16 ldCoeff[7]; - -/** - \brief Lookup-Table for binary power algorithm -*/ -extern const UWord32 exp2_tab_long[32]; - -/** - \brief Lookup-Table for binary power algorithm -*/ -extern const UWord32 exp2w_tab_long[32]; - -/** - \brief Lookup-Table for binary power algorithm -*/ -extern const UWord32 exp2x_tab_long[32]; - -/** - \brief Lookup-Table for integer binary logarithm -*/ -extern const Word32 ldIntCoeff[LD_INT_TAB_LEN]; - -/** - * \brief Lookup-Table for 1/x -*/ -extern const Word16 invTable[INV_TABLE_SIZE+1]; - -/** - * \brief 1/x, x=[0,1,2,3...] table - */ -extern const Word16 InvIntTable[65]; - -/** - * \brief Lookup-Table for Squareroot -*/ -extern const Word16 sqrtTable[SQRT_TABLE_SIZE+1]; -extern const Word16 invSqrtTable[SQRT_TABLE_SIZE+1]; - -extern const Word32 BASOP_util_normReciprocal[CHEAP_NORM_SIZE]; -extern const Word16 f_atan_expand_range[MAXSFTAB-(MINSFTAB-1)]; - -/** - * \ brief Sine table - */ -extern const PWord16 SineTable512[257]; -extern const PWord16 SineTable480[241]; -extern const PWord16 SineTable400[201]; -extern const PWord16 SineTable384[193]; -extern const PWord16 SineTable320[161]; - -/** - * \ brief Lookup for sine tables and windows. - */ -void BASOP_getTables(const PWord16 **ptwiddle, const PWord16 **sin_twiddle, Word16 *sin_step, Word16 length); -const PWord16* getSineWindowTable(Word16 length); - -#endif diff --git a/src/libs/libevs/lib_com/rom_com.cpp b/src/libs/libevs/lib_com/rom_com.cpp new file mode 100644 index 00000000..303ea428 --- /dev/null +++ b/src/libs/libevs/lib_com/rom_com.cpp @@ -0,0 +1,19156 @@ +/*==================================================================================== + EVS Codec 3GPP TS26.443 Nov 13, 2018. Version 12.11.0 / 13.7.0 / 14.3.0 / 15.1.0 + ====================================================================================*/ + +#include "options.h" +#include "cnst.h" +#include "rom_com.h" +#include "prot.h" +#include "basop_util.h" + +/*----------------------------------------------------------------------------------* + * Table of bitrates + *----------------------------------------------------------------------------------*/ + +const long brate_tbl[SIZE_BRATE_TBL] = +{ + ACELP_7k20, ACELP_8k00, ACELP_9k60, ACELP_13k20, ACELP_16k40, ACELP_24k40, + ACELP_32k, ACELP_48k, ACELP_64k, HQ_96k, HQ_128k +}; + +/*----------------------------------------------------------------------------------* + * Frame size and mode configuration tables + *----------------------------------------------------------------------------------*/ + +const FrameSizeParams FrameSizeConfig[FRAME_SIZE_NB] = +{ + /* bits, net bits, trans_bits, trans_mode, band_bits, band_mode_min, band_mode_max, reserved_bits */ + { FRAME_0, FRAME_0, 0, {0,0}, 0, 0, 0, 0}, /* 0 kbps ZERO_FRAME*/ + { FRAME_2_4, FRAME_2_4-2, 1, {1,1}, 1, NB, WB, 0}, /* 2.4kbps VBR(SID)*/ + { FRAME_7_2, FRAME_7_2-1, 0, {0,1}, 1, NB, WB, 0}, /* 7.2kbps VBR/CBR*/ + { FRAME_8, FRAME_8-1, 0, {0,1}, 1, NB, WB, 0}, /* 8 kbps VBR/CBR*/ + { FRAME_9_6, FRAME_9_6-2, 0, {0,1}, 2, NB, SWB, 0}, /* 9.6kbps CBR*/ + { FRAME_13_2, FRAME_13_2-2, 0, {0,1}, 2, NB, SWB, 0}, /* 13.2kbps CBR*/ + { FRAME_16_4, FRAME_16_4-3, 0, {0,1}, 2, NB, FB, 1}, /* 16.4kbps CBR*/ + { FRAME_24_4, FRAME_24_4-3, 0, {0,1}, 2, NB, FB, 1}, /* 24.4kbps CBR*/ + { FRAME_32, FRAME_32-3, 0, {0,1}, 2, WB, FB, 1}, /* 32 kbps CBR*/ + { FRAME_48, FRAME_48-3, 0, {0,1}, 2, WB, FB, 1}, /* 48 kbps CBR*/ + { FRAME_64, FRAME_64-3, 0, {0,1}, 2, WB, FB, 1}, /* 64 kbps CBR*/ + { FRAME_96, FRAME_96-3, 0, {0,1}, 2, WB, FB, 1}, /* 96 kbps CBR*/ + { FRAME_128, FRAME_128-3, 0, {0,1}, 2, WB, FB, 1} /*128 kbps CBR*/ +}; + + +/*----------------------------------------------------------------------------------* + * Conversion of ACELP signalling parameters (ACELP internal Fs, coder type, bandwidth, sharpening flag) to index + * (to be consulted with the decision matrix) + * + * - in order to retrieve the index, each section in this table starts with the bitrate + * - the second value in each section corresponds to the number of bits + * - the other values represent indices created by combining different parameters into a single value through the macro SIG2IND() + *----------------------------------------------------------------------------------*/ + +const long acelp_sig_tbl[MAX_ACELP_SIG] = +{ + /* GENERIC UNVOICED VOICED TRANSITION AUDIO INACTIVE */ + ACELP_7k20, 4, + SIG2IND(GENERIC, NB, 1, 0), SIG2IND(UNVOICED, NB, 0, 0), SIG2IND(VOICED, NB, 1, 0), SIG2IND(TRANSITION, NB, 1, 0), SIG2IND(AUDIO, NB, 0, 0), SIG2IND(INACTIVE, NB, 0, 0), + SIG2IND(GENERIC, WB, 1, 0), SIG2IND(UNVOICED, WB, 0, 0), SIG2IND(VOICED, WB, 1, 0), SIG2IND(TRANSITION, WB, 1, 0), SIG2IND(AUDIO, WB, 0, 0), SIG2IND(INACTIVE, WB, 0, 0), + SIG2IND(GENERIC, NB, 0, 0), + SIG2IND(GENERIC, WB, 0, 0), + SIG2IND(LR_MDCT, NB, 0, 0), + + ACELP_8k00, 4, + SIG2IND(GENERIC, NB, 1, 0), SIG2IND(UNVOICED, NB, 0, 0), SIG2IND(VOICED, NB, 1, 0), SIG2IND(TRANSITION, NB, 1, 0), SIG2IND(AUDIO, NB, 0, 0), SIG2IND(INACTIVE, NB, 0, 0), + SIG2IND(GENERIC, WB, 1, 0), SIG2IND(UNVOICED, WB, 0, 0), SIG2IND(VOICED, WB, 1, 0), SIG2IND(TRANSITION, WB, 1, 0), SIG2IND(AUDIO, WB, 0, 0), SIG2IND(INACTIVE, WB, 0, 0), + SIG2IND(GENERIC, NB, 0, 0), + SIG2IND(GENERIC, WB, 0, 0), + SIG2IND(LR_MDCT, NB, 0, 0), + + ACELP_13k20, 5, + SIG2IND(GENERIC, NB, 1, 0), SIG2IND(VOICED, NB, 1, 0), SIG2IND(TRANSITION, NB, 0, 0), SIG2IND(AUDIO, NB, 0, 0), SIG2IND(INACTIVE, NB, 0, 0), + SIG2IND(GENERIC, WB, 1, 0), SIG2IND(VOICED, WB, 1, 0), SIG2IND(TRANSITION, WB, 0, 0), SIG2IND(AUDIO, WB, 0, 0), SIG2IND(INACTIVE, WB, 0, 0), + SIG2IND(GENERIC, SWB, 1, 0), SIG2IND(VOICED, SWB, 1, 0), SIG2IND(TRANSITION, SWB, 0, 0), SIG2IND(AUDIO, SWB, 0, 0), SIG2IND(INACTIVE, SWB, 0, 0), + SIG2IND(GENERIC, NB, 0, 0), SIG2IND(VOICED, NB, 0, 0), + SIG2IND(GENERIC, WB, 0, 0), SIG2IND(VOICED, WB, 0, 0), + SIG2IND(GENERIC, SWB, 0, 0), SIG2IND(VOICED, SWB, 0, 0), + SIG2IND(GENERIC, WB, 1, 1), SIG2IND(UNVOICED, WB, 0, 1), SIG2IND(VOICED, WB, 1, 1), SIG2IND(INACTIVE, WB, 0, 1), + SIG2IND(GENERIC, SWB, 1, 1), SIG2IND(UNVOICED, SWB, 0, 1), SIG2IND(VOICED, SWB, 1, 1), SIG2IND(INACTIVE, SWB, 0, 1), + SIG2IND(LR_MDCT, NB, 0, 0), + SIG2IND(LR_MDCT, WB, 0, 0), + SIG2IND(LR_MDCT, SWB, 0, 0), + + ACELP_32k, 4, + SIG2IND(GENERIC, WB, 1, 0), SIG2IND(TRANSITION, WB, 1, 0), SIG2IND(INACTIVE, WB, 0, 0), + SIG2IND(GENERIC, SWB, 1, 0), SIG2IND(TRANSITION, SWB, 1, 0), SIG2IND(INACTIVE, SWB, 0, 0), + SIG2IND(GENERIC, FB, 1, 0), SIG2IND(TRANSITION, FB, 1, 0), SIG2IND(INACTIVE, FB, 0, 0), + SIG2IND(GENERIC, WB, 0, 0), SIG2IND(TRANSITION, WB, 0, 0), + SIG2IND(GENERIC, SWB, 0, 0), SIG2IND(TRANSITION, SWB, 0, 0), + SIG2IND(GENERIC, FB, 0, 0), SIG2IND(TRANSITION, FB, 0, 0), + + ACELP_64k, 4, + SIG2IND(GENERIC, WB, 0, 0), SIG2IND(TRANSITION, WB, 0, 0), SIG2IND(INACTIVE, WB, 0, 0), + SIG2IND(GENERIC, SWB, 1, 0), SIG2IND(TRANSITION, SWB, 1, 0), SIG2IND(INACTIVE, SWB, 0, 0), + SIG2IND(GENERIC, FB, 1, 0), SIG2IND(TRANSITION, FB, 1, 0), SIG2IND(INACTIVE, FB, 0, 0), + SIG2IND(GENERIC, SWB, 0, 0), SIG2IND(TRANSITION, SWB, 0, 0), + SIG2IND(GENERIC, FB, 0, 0), SIG2IND(TRANSITION, FB, 0, 0), +}; + +/*----------------------------------------------------------------------------------* + * ACELP bit allocation tables + *----------------------------------------------------------------------------------*/ + +/* bit allocation table for end-frame LSF quantizer */ +const short LSF_bits_tbl[] = +{ + /* IC UC VC GC TC AC */ + 22, 37, 31, 29, 31, 22, /* ACELP_7k20 */ + 22, 40, 36, 33, 34, 22, /* ACELP_8k00 */ + 31, 0, 37, 37, 40, 31, /* ACELP_11k60 */ + 31, 0, 39, 39, 41, 31, /* ACELP_12k15 */ + 31, 0, 38, 38, 40, 31, /* ACELP_12k85 */ + 31, 0, 38, 38, 40, 31, /* ACELP_13k20 */ + 31, 0, 37, 42, 42, 31, /* ACELP_14k80 */ + 31, 0, 43, 40, 40, 31, /* ACELP_16k40 */ + 31, 0, 42, 40, 40, 0, /* ACELP_22k60 */ + 31, 0, 46, 41, 41, 31, /* ACELP_24k40 */ + 41, 0, 0, 41, 41, 0, /* ACELP_29k00 */ + 41, 0, 0, 41, 41, 0, /* ACELP_29k20 */ + 41, 0, 0, 41, 41, 0, /* ACELP_30k20 */ + 41, 0, 0, 41, 41, 0, /* ACELP_30k40 */ + 41, 0, 0, 41, 41, 0, /* ACELP_32k */ + 41, 0, 0, 41, 41, 0, /* ACELP_48k */ + 41, 0, 0, 41, 41, 0, /* ACELP_64k */ +}; + +/* bit allocation table for mid-frame LSF quantizer */ +const short mid_LSF_bits_tbl[] = +{ + /* IC UC VC GC TC AC */ + 2, 5, 4, 5, 5, 2, /* ACELP_7k20 */ + 2, 5, 4, 5, 5, 2, /* ACELP_8k00 */ + 2, 0, 4, 5, 5, 2, /* ACELP_11k60 */ + 2, 0, 5, 5, 5, 2, /* ACELP_12k15 */ + 2, 0, 5, 5, 5, 2, /* ACELP_12k85 */ + 2, 0, 5, 5, 5, 2, /* ACELP_13k20 */ + 4, 0, 5, 5, 5, 4, /* ACELP_14k80 */ + 4, 0, 5, 5, 5, 4, /* ACELP_16k40 */ + 5, 0, 5, 5, 5, 5, /* ACELP_22k60 */ + 5, 0, 5, 5, 5, 5, /* ACELP_24k40 */ + 5, 0, 0, 5, 5, 5, /* ACELP_29k00 */ + 5, 0, 0, 5, 5, 5, /* ACELP_29k20 */ + 5, 0, 0, 5, 5, 5, /* ACELP_30k20 */ + 5, 0, 0, 5, 5, 5, /* ACELP_30k40 */ + 5, 0, 0, 5, 5, 5, /* ACELP_32k */ + 5, 0, 0, 5, 5, 5, /* ACELP_48k */ + 5, 0, 0, 5, 5, 5, /* ACELP_64k */ +}; + + +/* bit allocation table for scaled innovation energy prediction */ +const short Es_pred_bits_tbl[] = +{ + /* UC VC GC TC */ + 0, 0, 0, 4, /* ACELP_7k20 */ + 0, 0, 0, 4, /* ACELP_8k00 */ + 0, 5, 4, 4, /* ACELP_11k60 */ + 0, 5, 5, 5, /* ACELP_12k15 */ + 0, 5, 4, 5, /* ACELP_12k85 */ + 0, 5, 4, 4, /* ACELP_13k20 */ + 0, 5, 5, 5, /* ACELP_14k80 */ + 0, 5, 5, 5, /* ACELP_16k40 */ + 0, 5, 5, 5, /* ACELP_22k60 */ + 0, 5, 5, 5, /* ACELP_24k40 */ + 0, 0, 5, 5, /* ACELP_29k00 */ + 0, 0, 5, 5, /* ACELP_29k20 */ + 0, 0, 5, 5, /* ACELP_30k20 */ + 0, 0, 5, 5, /* ACELP_30k40 */ + 0, 0, 5, 5, /* ACELP_32k */ + 0, 0, 5, 5, /* ACELP_48k */ + 0, 0, 5, 5, /* ACELP_64k */ +}; + +/* bit allocation table for gain quantizer (ACELP@12.8kHz) */ +/* the 4 values allocated correspond to 4 subframes */ +const short gain_bits_tbl[] = +{ + /* UC VC GC TC0_0 TC0_64 TC0_128 TC0_192 TC64 TC128 TC192 */ + 7,7,7,7, 7,6,6,6, 6,6,6,6, 5,5,5,5, 5,5,6,5, 5,3,6,6, 5,3,3,6, 3,6,6,6, 3,3,6,6, 3,3,3,10, /* ACELP_7k20 */ + 7,7,7,7, 8,7,6,6, 8,7,6,6, 5,5,5,5, 5,6,5,5, 5,3,6,6, 5,3,3,6, 3,5,5,5, 3,3,6,6, 3,3,3,14, /* ACELP_8k00 */ + 0,0,0,0, 6,6,6,6, 6,6,6,6, 6,6,6,6, 6,6,6,6, 6,3,6,6, 6,3,3,6, 3,6,6,6, 3,3,6,6, 3,3,3,13, /* ACELP_11k60 */ + 0,0,0,0, 6,6,6,6, 6,6,6,6, 6,6,6,6, 6,6,6,6, 6,3,6,6, 6,3,3,6, 3,6,6,6, 3,3,6,6, 3,3,3,14, /* ACELP_12k15 */ + 0,0,0,0, 6,6,6,6, 6,6,6,6, 6,6,6,6, 6,6,6,6, 6,3,6,6, 6,3,3,6, 3,6,6,6, 3,3,6,5, 3,3,3,14, /* ACELP_12k85 */ + 0,0,0,0, 6,6,6,6, 6,6,6,6, 6,6,6,6, 6,6,6,6, 6,3,6,6, 6,3,3,6, 3,6,6,6, 3,3,6,6, 3,3,3,15, /* ACELP_13k20 */ + 0,0,0,0, 6,6,6,6, 6,6,6,6, 6,6,6,6, 6,6,6,6, 6,3,6,6, 6,3,3,6, 3,6,6,6, 3,3,6,6, 3,3,3,15, /* ACELP_14k80 */ + 0,0,0,0, 6,6,6,6, 6,6,6,6, 6,6,6,6, 6,6,6,6, 6,3,6,6, 6,3,3,6, 3,6,6,6, 3,3,6,6, 3,3,3,15, /* ACELP_16k40 */ + 0,0,0,0, 6,6,6,6, 6,6,6,6, 6,6,6,6, 6,6,6,6, 6,3,6,6, 6,3,3,6, 3,6,6,6, 3,3,6,6, 3,3,3,14, /* ACELP_22k60 */ + 0,0,0,0, 6,6,6,6, 6,6,6,6, 6,6,6,6, 6,6,6,6, 6,3,6,6, 6,3,3,6, 3,6,6,6, 3,3,6,6, 3,3,3,15, /* ACELP_24k40 */ +}; + +/* bit allocation table for gain gain quantizer (ACELP@16kHz) */ +/* the 5 values allocated correspond to 5 subframes */ +const short gain_bits_16kHz_tbl[] = +{ + /* IC GC TC0 TC64 TC128 TC192 TC256 */ + 0,0,0,0,0, 6,0,0,0,0, 0,0,0,0,0, 0,0,0,0,0, 0,0,0,0,0, 0,0,0,0,0, 0,0,0,0, 0, /* ACELP_8k00 */ + 0,0,0,0,0, 6,0,0,0,0, 0,0,0,0,0, 0,0,0,0,0, 0,0,0,0,0, 0,0,0,0,0, 0,0,0,0, 0, /* ACELP_14k80 */ + 6,6,6,6,6, 6,6,6,6,6, 6,6,6,6,6, 3,6,6,6,6, 3,3,6,6,6, 3,3,3,6,6, 3,3,3,3,15, /* ACELP_22k60 */ + 6,6,6,6,6, 6,6,6,6,6, 6,6,6,6,6, 3,6,6,6,6, 3,3,6,6,6, 3,3,3,6,6, 3,3,3,3,16, /* ACELP_24k40 */ + 6,6,6,6,6, 6,6,6,6,6, 6,6,6,6,6, 3,6,6,6,6, 3,3,6,6,6, 3,3,3,6,6, 3,3,3,3,14, /* ACELP_29k00 */ + 6,6,6,6,6, 6,6,6,6,6, 6,6,6,6,6, 3,6,6,6,6, 3,3,6,6,6, 3,3,3,6,6, 3,3,3,3,14, /* ACELP_29k20 */ + 6,6,6,6,6, 6,6,6,6,6, 6,6,6,6,6, 3,6,6,6,6, 3,3,6,6,6, 3,3,3,6,6, 3,3,3,3,14, /* ACELP_30k20 */ + 6,6,6,6,6, 6,6,6,6,6, 6,6,6,6,6, 3,6,6,6,6, 3,3,6,6,6, 3,3,3,6,6, 3,3,3,3,14, /* ACELP_30k40 */ + 6,6,6,6,6, 6,6,6,6,6, 6,6,6,6,6, 3,6,6,6,6, 3,3,6,6,6, 3,3,3,6,6, 3,3,3,3,14, /* ACELP_32k */ + 12,12,12,12,12, 12,12,12,12,12, 12,12,12,12,12, 6,12,12,12,12, 6,6,12,12,12, 6,6,6,12,12, 6,6,6,6,12, /* ACELP_48k */ + 12,12,12,12,12, 12,12,12,12,12, 12,12,12,12,12, 6,12,12,12,12, 6,6,12,12,12, 6,6,6,12,12, 6,6,6,6,12 /* ACELP_64k */ +}; + +/* bit allocation table for adaptive codebook (pitch) (ACELP@12.8kHz) */ +/* the 4 values correspond to 4 subframes */ +const short ACB_bits_tbl[] = +{ + /* UC VC GC TC0_0 TC0_64 TC0_128 TC0_192 TC64 TC128 TC192 */ + 0,0,0,0, 9,5,5,5, 8,5, 8,5, 6,5,6,6, 0,7,6,6, 0,0,7,6, 0,0,0,7, 0,0,9,6, 0,0,5,9, 0,0,0,8, /* ACELP_7k20 */ + 0,0,0,0, 10,5,5,5, 9,5, 8,5, 6,5,6,6, 0,7,6,6, 0,0,7,5, 0,0,0,7, 0,0,9,6, 0,0,5,9, 0,0,0,9, /* ACELP_8k00 */ + 0,0,0,0, 10,5,5,5, 10,6, 9,6, 6,5,6,6, 0,7,6,6, 0,0,7,6, 0,0,0,7, 0,0,9,6, 0,0,5,9, 0,0,0,9, /* ACELP_11k60 */ + 0,0,0,0, 10,5,5,5, 10,6, 9,6, 6,6,6,6, 0,7,6,6, 0,0,7,6, 0,0,0,7, 0,0,9,6, 0,0,5,9, 0,0,0,9, /* ACELP_12k15 */ + 0,0,0,0, 10,5,5,5, 10,6, 9,6, 6,5,6,6, 0,7,6,6, 0,0,7,6, 0,0,0,7, 0,0,9,6, 0,0,5,9, 0,0,0,9, /* ACELP_12k85 */ + 0,0,0,0, 10,5,5,5, 10,6, 9,6, 6,5,6,6, 0,7,6,6, 0,0,7,6, 0,0,0,7, 0,0,9,6, 0,0,5,9, 0,0,0,9, /* ACELP_13k20 */ + 0,0,0,0, 10,5,5,5, 10,6,10,6, 6,6,6,6, 0,7,6,6, 0,0,7,6, 0,0,0,7, 0,0,9,6, 0,0,5,9, 0,0,0,9, /* ACELP_14k80 */ + 0,0,0,0, 10,5,5,5, 10,6,10,6, 6,6,6,6, 0,7,6,6, 0,0,7,6, 0,0,0,7, 0,0,9,6, 0,0,5,9, 0,0,0,9, /* ACELP_16k40 */ + 0,0,0,0, 10,5,5,5, 10,6,10,6, 6,6,6,6, 0,7,6,6, 0,0,7,6, 0,0,0,7, 0,0,9,6, 0,0,5,9, 0,0,0,9, /* ACELP_22k60 */ + 0,0,0,0, 10,5,5,5, 10,6,10,6, 6,6,6,6, 0,7,6,6, 0,0,7,6, 0,0,0,7, 0,0,9,6, 0,0,5,9, 0,0,0,9, /* ACELP_24k40 */ +}; + +/* bit allocation table for adaptive codebook (pitch) (ACELP@16kHz) */ +/* the 5 values correspond to 5 subframes */ +const short ACB_bits_16kHz_tbl[] = +{ + /* IC GC TC0 TC64 TC128 TC192 TC256 */ + 0,0, 0,0,0, 9,0, 0,0,0, 0,0, 0,0,0, 0,0, 0,0,0, 0,0, 0,0,0, 0,0,0, 0,0, 0,0,0,0, 0, /* ACELP_8k00 */ + 0,0, 0,0,0, 10,0, 0,0,0, 0,0, 0,0,0, 0,0, 0,0,0, 0,0, 0,0,0, 0,0,0, 0,0, 0,0,0,0, 0, /* ACELP_14k80 */ + 10,6,10,6,6, 10,6,10,6,6, 5,8,10,6,6, 0,6,10,6,6, 0,0,10,6,6, 0,0,0,10,6, 0,0,0,0,10, /* ACELP_22k60 */ + 10,6,10,6,6, 10,6,10,6,6, 5,8,10,6,6, 0,6,10,6,6, 0,0,10,6,6, 0,0,0,10,6, 0,0,0,0,10, /* ACELP_24k40 */ + 10,6,10,6,6, 10,6,10,6,6, 6,8,10,6,6, 0,6,10,6,6, 0,0,10,6,6, 0,0,0,10,6, 0,0,0,0,10, /* ACELP_29k00 */ + 10,6,10,6,6, 10,6,10,6,6, 6,8,10,6,6, 0,6,10,6,6, 0,0,10,6,6, 0,0,0,10,6, 0,0,0,0,10, /* ACELP_29k20 */ + 10,6,10,6,6, 10,6,10,6,6, 6,8,10,6,6, 0,6,10,6,6, 0,0,10,6,6, 0,0,0,10,6, 0,0,0,0,10, /* ACELP_30k20 */ + 10,6,10,6,6, 10,6,10,6,6, 6,8,10,6,6, 0,6,10,6,6, 0,0,10,6,6, 0,0,0,10,6, 0,0,0,0,10, /* ACELP_30k40 */ + 10,6,10,6,6, 10,6,10,6,6, 6,8,10,6,6, 0,6,10,6,6, 0,0,10,6,6, 0,0,0,10,6, 0,0,0,0,10, /* ACELP_32k */ + 10,6,10,6,6, 10,6,10,6,6, 6,8,10,6,6, 0,6,10,6,6, 0,0,10,6,6, 0,0,0,10,6, 0,0,0,0,10, /* ACELP_48k */ + 10,6,10,6,6, 10,6,10,6,6, 6,8,10,6,6, 0,6,10,6,6, 0,0,10,6,6, 0,0,0,10,6, 0,0,0,0,10 /* ACELP_64k */ +}; + +/* bit allocation table for algebraic (fixed) codebook (innovation) (ACELP@12.8kHz) */ +/* the 4 values correspond to 4 subframes */ +const short FCB_bits_tbl[] = +{ + /* UC VC GC TC0_0 TC0_64 TC0_128 TC0_192 TC64 TC128 TC192 */ + 13,13,13,13, 12,12,12,20, 12,12,12,20, 12, 7,12,12, 12,12, 7,12, 12,12,12,12, 12,12,20,12, 12,12,12,12, 12,12,12,12, 12,12,12,20, /* ACELP_7k20 */ + 13,13,13,13, 12,20,12,20, 12,20,12,20, 20,12,12,12, 20,12,12,12, 20,12,20,12, 20,12,20,20, 20,12,12,20, 20,12,20,12, 12,20,12,20, /* ACELP_8k00 */ + 0, 0, 0, 0, 28,36,28,36, 28,28,28,36, 28,28,28,28, 28,28,28,28, 28,28,36,28, 28,36,28,36, 28,36,28,28, 28,28,28,36, 28,36,28,36, /* ACELP_11k60 */ + 0, 0, 0, 0, 28,36,36,36, 28,36,28,36, 36,28,28,28, 36,28,28,28, 36,28,36,28, 36,36,28,43, 28,36,28,36, 28,36,28,36, 28,36,36,36, /* ACELP_12k15 */ + 0, 0, 0, 0, 36,36,36,43, 36,36,36,36, 36,36,28,36, 36,28,36,36, 36,36,36,36, 36,36,43,43, 36,36,36,36, 36,36,36,43, 36,36,36,43, /* ACELP_12k85 */ + 0, 0, 0, 0, 36,43,36,43, 36,36,36,43, 36,36,36,36, 36,36,36,36, 36,36,43,36, 36,43,43,43, 36,43,36,36, 43,36,43,36, 36,43,36,43, /* ACELP_13k20 */ + 0, 0, 0, 0, 43,50,43,50, 43,43,43,43, 43,43,43,43, 43,43,43,43, 43,43,50,43, 43,50,50,50, 43,43,43,50, 50,43,50,43, 43,50,43,50, /* ACELP_14k80 */ + 0, 0, 0, 0, 50,56,50,56, 50,50,50,56, 56,50,50,50, 56,50,50,50, 56,50,56,56, 56,56,56,56, 50,56,50,56, 50,56,56,56, 50,56,56,56, /* ACELP_16k40 */ + 0, 0, 0, 0, 83,83,83,87, 78,83,83,83, 83,78,83,83, 83,78,83,87, 83,87,83,87, 83,87,87,92, 87,83,87,83, 87,83,87,87, 83,87,87,87, /* ACELP_22k60 */ + 0, 0, 0, 0, 92,92,92,92, 87,92,92,92, 92,87,92,92, 92,87,92,92, 92,92,92,92, 92,92,92,92, 92,92,92,92, 92,92,92,92, 92,92,92,92, /* ACELP_24k40 */ +}; + +/* bit allocation table for algebraic (fixed) codebook (innovation) (ACELP@16kHz) */ +/* the 5 values correspond to 5 subframes */ +const short FCB_bits_16kHz_tbl[] = +{ + /* IC GC TC0 TC64 TC128 TC192 TC256 */ + 0, 0, 0, 0, 0, 12, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* ACELP_8k00 */ + 0, 0, 0, 0, 0, 36, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* ACELP_14k80 */ + 0, 0, 0, 0, 0, 62,56,56,56,62, 62,56,56,56,56, 56,56,56,56,73, 62,56,62,62,62, 56,62,62,62,73, 62,62,62,62,68, /* ACELP_22k60 */ + 0, 0, 0, 0, 0, 68,68,68,73,73, 68,68,68,68,73, 68,73,68,73,73, 73,73,73,73,73, 73,78,73,73,78, 73,78,73,73,78, /* ACELP_24k40 */ + 12,12,12,12,12, 36,28,28,36,36, 36,28,28,36,36, 36,28,28,36,36, 36,28,28,36,36, 36,28,28,36,36, 36,28,28,36,36, /* ACELP_29k00 */ + 12,12,12,12,12, 36,28,28,36,36, 36,28,28,36,36, 36,28,28,36,36, 36,28,28,36,36, 36,28,28,36,36, 36,28,28,36,36, /* ACELP_29k20 */ + 12,12,12,12,12, 36,36,36,36,36, 36,36,36,36,36, 36,36,36,36,36, 36,36,36,36,36, 36,36,36,36,36, 36,36,36,36,36, /* ACELP_30k20 */ + 12,12,12,12,12, 36,36,36,36,36, 36,36,36,36,36, 36,36,36,36,36, 36,36,36,36,36, 36,36,36,36,36, 36,36,36,36,36, /* ACELP_30k40 */ + 12,12,12,12,12, 36,36,36,36,36, 36,36,36,36,36, 36,36,36,36,36, 36,36,36,36,36, 36,36,36,36,36, 36,36,36,36,36, /* ACELP_32k */ + 12,12,12,12,12, 36,36,36,36,36, 36,36,36,36,36, 36,36,36,36,36, 36,36,36,36,36, 36,36,36,36,36, 36,36,36,36,36, /* ACELP_48k */ + 12,12,12,12,12, 36,36,36,36,36, 36,36,36,36,36, 36,36,36,36,36, 36,36,36,36,36, 36,36,36,36,36, 36,36,36,36,36 /* ACELP_64k */ +}; + +/* bit allocation table for AVQ bits in active segments (ACELP@16kHz) */ +const short AVQ_bits_16kHz_tbl[] = +{ + /* IC GC TC0 TC64 TC128 TC192 TC256 */ + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* ACELP_8k00 */ + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* ACELP_14k80 */ + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* ACELP_22k60 */ + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* ACELP_24k40 */ + 78, 78, 78, 78, 78, 48, 48, 48, 48, 49, 48, 49, 49, 48, 49, 50, 50, 51, 52, 52, 50, 54, 53, 54, 54, 55, 55, 55, 55, 54, 52, 56, 56, 56, 56, /* ACELP_29k00 */ + 79, 79, 79, 79, 78, 49, 49, 49, 49, 49, 50, 49, 49, 50, 49, 52, 52, 51, 52, 52, 54, 54, 53, 54, 54, 56, 55, 55, 56, 56, 56, 56, 56, 56, 56, /* ACELP_29k20 */ + 78, 78, 78, 78, 78, 50, 50, 50, 50, 49, 51, 50, 50, 50, 50, 53, 53, 53, 52, 52, 55, 55, 55, 54, 54, 57, 57, 56, 56, 56, 57, 57, 57, 57, 56, /* ACELP_30k20 */ + 79, 79, 79, 79, 78, 51, 51, 51, 50, 50, 51, 51, 51, 51, 51, 54, 54, 53, 53, 53, 56, 56, 56, 55, 54, 58, 57, 57, 57, 57, 58, 58, 58, 57, 57, /* ACELP_30k40 */ + 86, 85, 85, 85, 85, 57, 57, 57, 57, 57, 58, 58, 57, 57, 57, 60, 60, 60, 60, 59, 62, 62, 62, 62, 61, 64, 64, 64, 63, 63, 64, 64, 64, 64, 64, /* ACELP_32k */ + 143,142,142,142,142, 116,115,115,115,115, 116,116,115,115,115, 119,119,118,118,118, 121,121,121,121,121, 124,124,123,123,123, 126,126,126,126,126, /* ACELP_48k */ + 207,206,206,206,206, 180,179,179,179,179, 180,180,179,179,179, 183,183,182,182,182, 185,185,185,185,185, 188,188,187,187,187, 190,190,190,190,190 /* ACELP_64k */ +}; + +/* bit allocation table for reserved bits (ACELP@12.8kHz) */ +const short reserved_bits_tbl[] = +{ + /* UC VC GC TC0_0 TC0_64 TC0_128 TC0_192 TC64 TC128 TC192 */ + 1, 0, 0, 0, 0, 2, 4, 0, 3, 0, /* ACELP_7k20 */ + 14, 0, 0, 0, 0, 0, 1, 0, 0, 0, /* ACELP_8k00 */ + 0, 0, 0, 0, 1, 3, 6, 2, 6, 0, /* ACELP_11k60 */ + 0, 0, 0, 0, 2, 4, 0, 3, 7, 0, /* ACELP_12k15 */ + 0, 0, 0, 0, 1, 3, 0, 2, 0, 0, /* ACELP_12k85 */ + 0, 0, 0, 0, 1, 4, 1, 3, 0, 0, /* ACELP_13k20 */ + 0, 0, 0, 0, 2, 5, 2, 4, 1, 1, /* ACELP_14k80 */ + 0, 0, 0, 0, 2, 0, 5, 5, 3, 3, /* ACELP_16k40 */ + 0, 0, 2, 2, 0, 1, 3, 0, 0, 1, /* ACELP_22k60 */ + 0, 0, 1, 1, 3, 8, 19, 7, 11, 11, /* ACELP_24k40 */ +}; + +/* NRG mode */ +const unsigned char ACELP_NRG_MODE[RATE_MODE_MAX][BANDWIDTH_MODE_MAX][ACELP_MODE_MAX+RF_MODE_MAX] = +{ + {{0,0,1,1,0,0,0,0},{2,2,1,1,0,0,0,0}}, + {{1,1,1,1,0,0,0,0},{1,1,1,1,1,1,1,0}}, +}; + +/* NRG bits : (0/2/3 bits) */ +const unsigned char ACELP_NRG_BITS[3] = { 0, 3, 4 }; + +/* LTP MODE*/ +const unsigned char ACELP_LTP_MODE[RATE_MODE_MAX][BANDWIDTH_MODE_MAX][ACELP_MODE_MAX+RF_MODE_MAX] = +{ + {{0,0,1,2,0,0,0,0},{0,0,1,2,0,0,0,0}}, + {{4,4,3,4,0,0,0,0},{4,4,3,4,8,0,9,0}}, +}; + +/* LTP bits */ +const unsigned char ACELP_LTP_BITS_SFR[8+RF_MODE_MAX][5] = +{ + {0,0,0,0,0}, + {8,4,4,4,4}, + {8,5,8,5,5}, + {9,6,6,6,6}, + {9,6,9,6,6}, + {8,5,5,5,5}, + {8,5,8,5,5}, + {8,0,0,0,0}, + {8,5,5,5,5}, /* All-pred mode in RF, rf_frame_type = 0 */ + {8,4,4,4,0}, /* Gen-pred mode in RF, rf_frame_type = 2 */ +}; + +/* LTF modes (0 - LOW_PASS (LP filtering), 1 - FULL_BAND (no filtering), 2 - NORMAL_OPERATION (adaptive)) */ +/* Mode 2 ACELP: INACTIVE,UNVOICED,VOICED,GENERIC */ +const unsigned char ACELP_LTF_MODE[RATE_MODE_MAX][BANDWIDTH_MODE_MAX][ACELP_MODE_MAX+RF_MODE_MAX] = +{ + {{1,1,1,0,0,0,0,0},{1,1,1,0,0,0,0,0}}, + {{0,0,2,0,0,0,0,0},{0,0,2,0,1,1,1,0}}, +}; + +/* LTF bits */ +const unsigned char ACELP_LTF_BITS[4] = { 0, 0, 4, 0 }; + +/* GAINS ELEMENT */ +/* 5 modes: (EVS: 5b/subframe), (AMRWB: 7b/subframe),(AMRWB: 6b/subframe),(UC: 5b/subframe) */ +const unsigned char ACELP_GAINS_MODE[RATE_MODE_MAX][BANDWIDTH_MODE_MAX][ACELP_MODE_MAX+RF_MODE_MAX] = +{ + {{6,6,1,1,0,0,0,0},{7,7,1,1,0,0,0,0}}, + {{2,2,3,3,0,0,0,0},{2,2,3,3,3,2,1,0}}, +}; + +/* gains bits */ +const unsigned char ACELP_GAINS_BITS[10] = +{ + 0, /* skip sub-frame wise gain coding*/ + 5, + 6, + 7, + 6, + 7, + 6, /* UC */ + 7, /* GUNVOICED UV (5b ICB/2b Gaussian) */ + 4, /* GNELP UV */ + 5 /* GNELP UV */ +}; + +/* BPF modes (0 - no filtering, 1 - filtering, 2 - adaptive) */ +const unsigned char ACELP_BPF_MODE[RATE_MODE_MAX][BANDWIDTH_MODE_MAX][ACELP_MODE_MAX+RF_MODE_MAX] = +{ + {{1,1,1,1,0,0,0,0},{1,1,1,1,0,0,0,0}}, + {{1,1,2,2,0,0,0,0},{1,1,2,2,1,1,1,1}}, + +}; + +/* BPF bits */ +const unsigned char ACELP_BPF_BITS[3] = { 0, 0, 2 }; + +/*----------------------------------------------------------------------------------* + * Power of 2 table (2^x) + *----------------------------------------------------------------------------------*/ + +const int pow2[] = +{ + 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, 65536, 131072, 262144, 524288, 1048576 +}; + +/*----------------------------------------------------------------------------------* + * Perceptual critical bands + *----------------------------------------------------------------------------------*/ + +const float crit_bands[] = +{ + 100.0f, 200.0f, 300.0f, 400.0f, 510.0f, 630.0f, 770.0f, 920.0f, 1080.0f, 1270.0f, 1480.0f, + 1720.0f, 2000.0f, 2320.0f, 2700.0f, 3150.0f, 3700.0f, 4400.0f, 5300.0f, 6350.0f, 7700.0f, + 9500.0f, 12000.0f, 15500.0f, 40000.0f +}; +const float crit_bins_corr[CRIT_NOIS_BAND] = +{ + 0.9f, 0.9f, 0.85f, 0.8f, 0.775f, 0.75f, 0.725f, 0.7f, 0.675f, 0.65f, 0.625f, + 0.60f, 0.6f, 0.6f, 0.6f, 0.6f, 0.6f, 0.6f, 0.6f, 0.6f, 0.6f, 0.6f, 0.6f +}; +const short crit_bins[CRIT_NOIS_BAND] = +{ + 4, 4, 4, 4, 4, 5, 6, 6, 6, 8, 8, 10, 11, 13, 15, 18, 22, 16, 16, 20, 20, 20, 16 +}; + +const float crit_bands_loc[CRIT_NOIS_BAND] = +{ + 100.0f, 200.0f, 300.0f, 400.0f, 510.0f, 630.0f, 770.0f, 920.0f, 1080.0f, 1270.0f, 1480.0f, + 1720.0f, 2000.0f, 2320.0f, 2700.0f, 3150.0f, 3700.0f, 4100.0f, 4500.0f, 5000.0f, 5500.0f, 6000.0f, 6375.0f +}; + +const float inv_tbl[130] = +{ + 0.0f, /* unused */ + 1.0000000000f, 0.5000000000f, 0.3333333333f, 0.2500000000f, + 0.2000000000f, 0.1666666667f, 0.1428571429f, 0.1250000000f, + 0.1111111111f, 0.1000000000f, 0.0909090909f, 0.0833333333f, + 0.0769230769f, 0.0714285714f, 0.0666666667f, 0.0625000000f, + 0.0588235294f, 0.0555555556f, 0.0526315789f, 0.0500000000f, + 0.0476190476f, 0.0454545455f, 0.0434782609f, 0.0416666667f, + 0.0400000000f, 0.0384615385f, 0.0370370370f, 0.0357142857f, + 0.0344827586f, 0.0333333333f, 0.0322580645f, 0.0312500000f, + 0.0303030303f, 0.0294117647f, 0.0285714286f, 0.0277777778f, + 0.0270270270f, 0.0263157895f, 0.0256410256f, 0.0250000000f, + 0.0243902439f, 0.0238095238f, 0.0232558140f, 0.0227272727f, + 0.0222222222f, 0.0217391304f, 0.0212765957f, 0.0208333333f, + 0.0204081633f, 0.0200000000f, 0.0196078431f, 0.0192307692f, + 0.0188679245f, 0.0185185185f, 0.0181818182f, 0.0178571429f, + 0.0175438596f, 0.0172413793f, 0.0169491525f, 0.0166666667f, + 0.0163934426f, 0.0161290323f, 0.0158730159f, 0.0156250000f, + 0.0153846154f, 0.0151515152f, 0.0149253731f, 0.0147058824f, + 0.0144927536f, 0.0142857143f, 0.0140845070f, 0.0138888889f, + 0.0136986301f, 0.0135135135f, 0.0133333333f, 0.0131578947f, + 0.0129870130f, 0.0128205128f, 0.0126582278f, 0.0125000000f, + 0.0123456790f, 0.0121951220f, 0.0120481928f, 0.0119047619f, + 0.0117647059f, 0.0116279070f, 0.0114942529f, 0.0113636364f, + 0.0112359551f, 0.0111111111f, 0.0109890110f, 0.0108695652f, + 0.0107526882f, 0.0106382979f, 0.0105263158f, 0.0104166667f, + 0.0103092784f, 0.0102040816f, 0.0101010101f, 0.0100000000f, + 0.0099009901f, 0.0098039216f, 0.0097087379f, 0.0096153846f, + 0.0095238095f, 0.0094339623f, 0.0093457944f, 0.0092592593f, + 0.0091743119f, 0.0090909091f, 0.0090090090f, 0.0089285714f, + 0.0088495575f, 0.0087719298f, 0.0086956522f, 0.0086206897f, + 0.0085470085f, 0.0084745763f, 0.0084033613f, 0.0083333333f, + 0.0082644628f, 0.0081967213f, 0.0081300813f, 0.0080645161f, + 0.0080000000f, 0.0079365079f, 0.0078740157f, 0.0078125000f, + 0.0077519380f /* last val = 1/129 */ +}; + + +/*----------------------------------------------------------------------------------* + * LD music post-filter + *----------------------------------------------------------------------------------*/ + +const float mfreq_loc_LD[] = { 100.0f, 200.0f, 300.0f, 400.0f, 510.0f, 630.0f, 770.0f, 920.0f, 1080.0f, 1270.0f, 1480.0f, + 1720.0f, 2000.0f, 2320.0f, 2700.0f, 3150.0f, 3700.0f, 4400.0f, 5300.0f, (6400.0f-BIN_16kdct) + }; + +const short mfreq_bindiv_LD[] = {10, 10, 10, 10, 11, 12, 14, 15, 16, 19, 21, 24, 28, 32, 38, 45, 55, 70, 90, 110}; +const float sc_qnoise[] = {0.1f,0.1f,0.1f,0.1f,0.1f,0.1f,0.09091f,0.09091f,0.09091f,0.09091f,0.09091f,0.09091f,0.09091f,0.09091f,0.09091f,0.06667f,0.06667f,0.06667f,0.06667f,0.06667f}; + +const float post_dct_wind[OFFSET2] = +{ + 1.000000f, 0.999933f, 0.999731f, 0.999395f, 0.998924f, 0.998319f, 0.997580f, 0.996707f, + 0.995700f, 0.994560f, 0.993287f, 0.991881f, 0.990343f, 0.988672f, 0.986870f, 0.984938f, + 0.982874f, 0.980681f, 0.978358f, 0.975907f, 0.973328f, 0.970621f, 0.967787f, 0.964828f, + 0.961743f, 0.958535f, 0.955202f, 0.951748f, 0.948172f, 0.944475f, 0.940658f, 0.936723f, + 0.932671f, 0.928501f, 0.924217f, 0.919819f, 0.915307f, 0.910684f, 0.905950f, 0.901107f, + 0.896156f, 0.891098f, 0.885935f, 0.880669f, 0.875300f, 0.869829f, 0.864260f, 0.858592f, + 0.852828f, 0.846968f, 0.841016f, 0.834971f, 0.828837f, 0.822614f, 0.816304f, 0.809909f, + 0.803431f, 0.796871f, 0.790231f, 0.783513f, 0.776719f, 0.769850f, 0.762908f, 0.755896f, + 0.748815f, 0.741667f, 0.734454f, 0.727178f, 0.719841f, 0.712444f, 0.704991f, 0.697482f, + 0.689920f, 0.682307f, 0.674645f, 0.666936f, 0.659182f, 0.651385f, 0.643547f, 0.635671f, + 0.627758f, 0.619811f, 0.611832f, 0.603822f, 0.595785f, 0.587721f, 0.579635f, 0.571526f, + 0.563399f, 0.555254f, 0.547095f, 0.538923f, 0.530740f, 0.522549f, 0.514353f, 0.506152f, + 0.497949f, 0.489747f, 0.481548f, 0.473354f, 0.465167f, 0.456990f, 0.448824f, 0.440671f, + 0.432535f, 0.424417f, 0.416319f, 0.408244f, 0.400193f, 0.392169f, 0.384175f, 0.376211f, + 0.368281f, 0.360386f, 0.352529f, 0.344712f, 0.336936f, 0.329204f, 0.321518f, 0.313880f, + 0.306293f, 0.298757f, 0.291276f, 0.283850f, 0.276483f, 0.269176f, 0.261931f, 0.254751f, + 0.247636f, 0.240589f, 0.233612f, 0.226707f, 0.219875f, 0.213118f, 0.206439f, 0.199839f, + 0.193320f, 0.186883f, 0.180530f, 0.174264f, 0.168085f, 0.161995f, 0.155996f, 0.150090f, + 0.144278f, 0.138562f, 0.132943f, 0.127423f, 0.122003f, 0.116685f, 0.111470f, 0.106360f, + 0.101355f, 0.096458f, 0.091669f, 0.086991f, 0.082423f, 0.077968f, 0.073626f, 0.069399f, + 0.065289f, 0.061295f, 0.057419f, 0.053662f, 0.050025f, 0.046510f, 0.043116f, 0.039846f, + 0.036699f, 0.033677f, 0.030780f, 0.028010f, 0.025367f, 0.022851f, 0.020464f, 0.018206f, + 0.016078f, 0.014080f, 0.012212f, 0.010476f, 0.008872f, 0.007400f, 0.006060f, 0.004853f, + 0.003780f, 0.002840f, 0.002034f, 0.001362f, 0.000824f, 0.000420f, 0.000151f, 0.000017f +}; + +const float MAX_SNR_SNR1_tab[MBANDS_GN_LD] = { 1.026316f, 1.026316f, 1.026316f, 1.026316f, 1.026316f, 1.026316f, 1.026316f, 1.026316f, 1.026316f, 1.026316f, 1.026316f, 1.026316f, 1.026316f, 1.026316f, 1.026316f, 1.02631627f, 1.043478f, 1.043478f, 1.043478f, 1.043478f}; +const float INV_MAX_SNR_tab[MBANDS_GN_LD] = { .026316f, .026316f, .026316f, .026316f, .026316f, .026316f, .026316f, .026316f, .026316f, .026316f, .026316f, .026316f, .026316f, .026316f, .026316f, .026316f, .043478f, .043478f, .043478f, .043478f}; + +const float wind_sss[LEN_WIN_SSS] = /* window for subsampling */ +{ + 0.080000f, 0.080183f, 0.080730f, 0.081642f, 0.082918f, 0.084557f, 0.086558f, 0.088918f, + 0.091636f, 0.094711f, 0.098139f, 0.101917f, 0.106043f, 0.110514f, 0.115326f, 0.120475f, + 0.125957f, 0.131767f, 0.137902f, 0.144356f, 0.151124f, 0.158200f, 0.165580f, 0.173257f, + 0.181225f, 0.189478f, 0.198009f, 0.206811f, 0.215878f, 0.225203f, 0.234777f, 0.244594f, + 0.254645f, 0.264922f, 0.275418f, 0.286124f, 0.297031f, 0.308132f, 0.319416f, 0.330876f, + 0.342501f, 0.354284f, 0.366213f, 0.378281f, 0.390477f, 0.402792f, 0.415215f, 0.427738f, + 0.440350f, 0.453041f, 0.465801f, 0.478620f, 0.491487f, 0.504393f, 0.517328f, 0.530280f, + 0.543240f, 0.556198f, 0.569142f, 0.582064f, 0.594952f, 0.607796f, 0.620587f, 0.633314f, + 0.645967f, 0.658535f, 0.671009f, 0.683380f, 0.695637f, 0.707770f, 0.719769f, 0.731627f, + 0.743332f, 0.754875f, 0.766248f, 0.777442f, 0.788447f, 0.799255f, 0.809857f, 0.820244f, + 0.830410f, 0.840344f, 0.850041f, 0.859491f, 0.868688f, 0.877623f, 0.886291f, 0.894684f, + 0.902795f, 0.910618f, 0.918147f, 0.925376f, 0.932299f, 0.938911f, 0.945205f, 0.951179f, + 0.956825f, 0.962141f, 0.967122f, 0.971764f, 0.976063f, 0.980016f, 0.983619f, 0.986871f, + 0.989767f, 0.992307f, 0.994488f, 0.996307f, 0.997765f, 0.998859f, 0.999589f, 0.999954f, + 1.000000f, 0.979530f, 0.918958f, 0.820763f, 0.688967f, 0.528964f, 0.347305f, 0.151428f +}; + +/*----------------------------------------------------------------------------------* + * Low-pass FIR filter for low-frequency post-filtering @ 8kHz + * fir1(240,(3900/32000),hanning(241))*5 + *----------------------------------------------------------------------------------*/ + +const float filter5_39s320_120[121] = +{ + 0.609388f, 0.594507f, 0.551181f, 0.483219f, 0.396518f, 0.298448f, 0.197086f, 0.100396f, + 0.015442f, -0.052273f, -0.099277f, -0.124358f, -0.128542f, -0.114820f, -0.087682f, -0.052507f, + -0.014899f, 0.019957f, 0.047847f, 0.065924f, 0.072906f, 0.069076f, 0.056094f, 0.036651f, + 0.014026f, -0.008391f, -0.027559f, -0.041148f, -0.047793f, -0.047188f, -0.040043f, -0.027903f, + -0.012866f, 0.002740f, 0.016701f, 0.027204f, 0.033059f, 0.033817f, 0.029768f, 0.021853f, + 0.011477f, 0.000283f, -0.010097f, -0.018267f, -0.023248f, -0.024581f, -0.022354f, -0.017150f, + -0.009927f, -0.001855f, 0.005864f, 0.012168f, 0.016275f, 0.017775f, 0.016654f, 0.013275f, + 0.008291f, 0.002530f, -0.003131f, -0.007899f, -0.011171f, -0.012604f, -0.012143f, -0.010011f, + -0.006645f, -0.002628f, 0.001417f, 0.004913f, 0.007412f, 0.008646f, 0.008551f, 0.007261f, + 0.005067f, 0.002364f, -0.000416f, -0.002869f, -0.004678f, -0.005647f, -0.005724f, -0.004986f, + -0.003623f, -0.001896f, -0.000090f, 0.001528f, 0.002746f, 0.003436f, 0.003559f, 0.003165f, + 0.002373f, 0.001348f, 0.000266f, -0.000708f, -0.001448f, -0.001877f, -0.001978f, -0.001782f, + -0.001364f, -0.000818f, -0.000247f, 0.000261f, 0.000641f, 0.000858f, 0.000909f, 0.000817f, + 0.000625f, 0.000384f, 0.000142f, -0.000062f, -0.000203f, -0.000274f, -0.000280f, -0.000239f, + -0.000172f, -0.000099f, -0.000038f, 0.000004f, 0.000024f, 0.000027f, 0.000019f, 0.000009f, + 0.000002f +}; + +/*----------------------------------------------------------------------------------* + * LP analysis windows + *----------------------------------------------------------------------------------*/ + +/* LP analysis window (length of the window is 25 ms which is 320 samples at 12.8kHz */ +const float LP_assym_window[L_LP] = +{ + 0.080000f, 0.080065f, 0.080258f, 0.080581f, 0.081033f, 0.081613f, 0.082323f, 0.083160f, + 0.084126f, 0.085220f, 0.086442f, 0.087791f, 0.089267f, 0.090869f, 0.092598f, 0.094452f, + 0.096431f, 0.098535f, 0.100762f, 0.103113f, 0.105587f, 0.108182f, 0.110899f, 0.113736f, + 0.116693f, 0.119769f, 0.122963f, 0.126274f, 0.129701f, 0.133243f, 0.136899f, 0.140668f, + 0.144550f, 0.148543f, 0.152645f, 0.156856f, 0.161175f, 0.165600f, 0.170130f, 0.174764f, + 0.179501f, 0.184339f, 0.189276f, 0.194313f, 0.199446f, 0.204674f, 0.209997f, 0.215413f, + 0.220919f, 0.226516f, 0.232200f, 0.237971f, 0.243826f, 0.249765f, 0.255785f, 0.261884f, + 0.268062f, 0.274317f, 0.280645f, 0.287047f, 0.293520f, 0.300062f, 0.306671f, 0.313345f, + 0.320084f, 0.326884f, 0.333744f, 0.340662f, 0.347635f, 0.354663f, 0.361743f, 0.368873f, + 0.376051f, 0.383274f, 0.390542f, 0.397852f, 0.405202f, 0.412590f, 0.420013f, 0.427470f, + 0.434959f, 0.442477f, 0.450022f, 0.457593f, 0.465187f, 0.472802f, 0.480436f, 0.488086f, + 0.495751f, 0.503429f, 0.511116f, 0.518812f, 0.526514f, 0.534220f, 0.541927f, 0.549634f, + 0.557337f, 0.565037f, 0.572729f, 0.580412f, 0.588083f, 0.595741f, 0.603384f, 0.611008f, + 0.618613f, 0.626195f, 0.633754f, 0.641286f, 0.648790f, 0.656263f, 0.663703f, 0.671109f, + 0.678478f, 0.685808f, 0.693097f, 0.700343f, 0.707544f, 0.714698f, 0.721803f, 0.728857f, + 0.735858f, 0.742804f, 0.749694f, 0.756524f, 0.763293f, 0.770000f, 0.776642f, 0.783218f, + 0.789725f, 0.796163f, 0.802528f, 0.808820f, 0.815036f, 0.821175f, 0.827236f, 0.833215f, + 0.839112f, 0.844925f, 0.850653f, 0.856294f, 0.861845f, 0.867306f, 0.872676f, 0.877952f, + 0.883133f, 0.888218f, 0.893205f, 0.898093f, 0.902880f, 0.907566f, 0.912148f, 0.916626f, + 0.920998f, 0.925263f, 0.929420f, 0.933468f, 0.937405f, 0.941230f, 0.944943f, 0.948543f, + 0.952027f, 0.955396f, 0.958649f, 0.961784f, 0.964800f, 0.967697f, 0.970474f, 0.973131f, + 0.975665f, 0.978078f, 0.980367f, 0.982533f, 0.984574f, 0.986491f, 0.988282f, 0.989948f, + 0.991487f, 0.992900f, 0.994185f, 0.995343f, 0.996373f, 0.997275f, 0.998048f, 0.998693f, + 0.999209f, 0.999597f, 0.999855f, 0.999984f, 0.999967f, 0.999705f, 0.999180f, 0.998393f, + 0.997344f, 0.996035f, 0.994465f, 0.992636f, 0.990548f, 0.988203f, 0.985603f, 0.982748f, + 0.979641f, 0.976282f, 0.972675f, 0.968820f, 0.964721f, 0.960380f, 0.955798f, 0.950980f, + 0.945926f, 0.940641f, 0.935128f, 0.929389f, 0.923427f, 0.917247f, 0.910852f, 0.904245f, + 0.897430f, 0.890410f, 0.883191f, 0.875777f, 0.868170f, 0.860376f, 0.852400f, 0.844245f, + 0.835916f, 0.827419f, 0.818757f, 0.809936f, 0.800962f, 0.791838f, 0.782571f, 0.773165f, + 0.763626f, 0.753960f, 0.744171f, 0.734266f, 0.724250f, 0.714129f, 0.703908f, 0.693594f, + 0.683193f, 0.672709f, 0.662150f, 0.651521f, 0.640828f, 0.630078f, 0.619277f, 0.608430f, + 0.597544f, 0.586626f, 0.575680f, 0.564715f, 0.553735f, 0.542747f, 0.531758f, 0.520774f, + 0.509800f, 0.498844f, 0.487911f, 0.477008f, 0.466141f, 0.455316f, 0.444540f, 0.433818f, + 0.423156f, 0.412561f, 0.402039f, 0.391596f, 0.381237f, 0.370969f, 0.360798f, 0.350728f, + 0.340767f, 0.330920f, 0.321191f, 0.311588f, 0.302115f, 0.292778f, 0.283582f, 0.274532f, + 0.265634f, 0.256892f, 0.248312f, 0.239898f, 0.231656f, 0.223589f, 0.215704f, 0.208003f, + 0.200492f, 0.193174f, 0.186055f, 0.179137f, 0.172426f, 0.165924f, 0.159636f, 0.153564f, + 0.147714f, 0.142087f, 0.136687f, 0.131518f, 0.126582f, 0.121881f, 0.117419f, 0.113199f, + 0.109222f, 0.105491f, 0.102007f, 0.098774f, 0.095793f, 0.093065f, 0.090592f, 0.088376f, + 0.086417f, 0.084718f, 0.083278f, 0.082099f, 0.081181f, 0.080525f, 0.080131f, 0.080000f +}; + +/* LP analysis window (length of the window is 25ms which is 400 samples at 16kHz */ +const float LP_assym_window_16k[L_LP_16k] = +{ + 0.080000f, 0.080041f, 0.080165f, 0.080371f, 0.080660f, 0.081032f, 0.081485f, 0.082021f, + 0.082639f, 0.083340f, 0.084122f, 0.084986f, 0.085932f, 0.086959f, 0.088067f, 0.089257f, + 0.090527f, 0.091879f, 0.093310f, 0.094822f, 0.096414f, 0.098085f, 0.099835f, 0.101665f, + 0.103573f, 0.105560f, 0.107624f, 0.109767f, 0.111986f, 0.114282f, 0.116655f, 0.119103f, + 0.121627f, 0.124227f, 0.126901f, 0.129649f, 0.132470f, 0.135365f, 0.138332f, 0.141372f, + 0.144483f, 0.147665f, 0.150917f, 0.154240f, 0.157631f, 0.161091f, 0.164619f, 0.168215f, + 0.171877f, 0.175605f, 0.179399f, 0.183257f, 0.187180f, 0.191166f, 0.195214f, 0.199324f, + 0.203496f, 0.207727f, 0.212019f, 0.216369f, 0.220777f, 0.225243f, 0.229765f, 0.234343f, + 0.238976f, 0.243663f, 0.248402f, 0.253195f, 0.258038f, 0.262933f, 0.267877f, 0.272870f, + 0.277911f, 0.282998f, 0.288132f, 0.293312f, 0.298535f, 0.303802f, 0.309111f, 0.314462f, + 0.319853f, 0.325283f, 0.330753f, 0.336259f, 0.341803f, 0.347382f, 0.352995f, 0.358642f, + 0.364322f, 0.370033f, 0.375774f, 0.381545f, 0.387345f, 0.393172f, 0.399025f, 0.404903f, + 0.410806f, 0.416732f, 0.422680f, 0.428649f, 0.434639f, 0.440647f, 0.446673f, 0.452715f, + 0.458774f, 0.464846f, 0.470933f, 0.477032f, 0.483142f, 0.489262f, 0.495391f, 0.501529f, + 0.507673f, 0.513823f, 0.519978f, 0.526136f, 0.532297f, 0.538459f, 0.544622f, 0.550784f, + 0.556943f, 0.563100f, 0.569253f, 0.575400f, 0.581541f, 0.587674f, 0.593799f, 0.599915f, + 0.606019f, 0.612112f, 0.618192f, 0.624258f, 0.630308f, 0.636343f, 0.642360f, 0.648358f, + 0.654338f, 0.660296f, 0.666234f, 0.672148f, 0.678039f, 0.683905f, 0.689745f, 0.695558f, + 0.701344f, 0.707100f, 0.712827f, 0.718522f, 0.724186f, 0.729816f, 0.735412f, 0.740973f, + 0.746499f, 0.751987f, 0.757437f, 0.762848f, 0.768219f, 0.773549f, 0.778837f, 0.784082f, + 0.789284f, 0.794440f, 0.799551f, 0.804616f, 0.809633f, 0.814601f, 0.819521f, 0.824390f, + 0.829208f, 0.833974f, 0.838688f, 0.843347f, 0.847953f, 0.852503f, 0.856997f, 0.861434f, + 0.865813f, 0.870134f, 0.874396f, 0.878598f, 0.882739f, 0.886818f, 0.890835f, 0.894789f, + 0.898680f, 0.902506f, 0.906267f, 0.909962f, 0.913591f, 0.917153f, 0.920647f, 0.924073f, + 0.927430f, 0.930718f, 0.933935f, 0.937082f, 0.940157f, 0.943160f, 0.946092f, 0.948950f, + 0.951735f, 0.954446f, 0.957082f, 0.959644f, 0.962130f, 0.964541f, 0.966876f, 0.969133f, + 0.971314f, 0.973418f, 0.975443f, 0.977391f, 0.979260f, 0.981050f, 0.982761f, 0.984392f, + 0.985944f, 0.987416f, 0.988807f, 0.990118f, 0.991348f, 0.992497f, 0.993565f, 0.994551f, + 0.995456f, 0.996279f, 0.997021f, 0.997680f, 0.998257f, 0.998752f, 0.999164f, 0.999494f, + 0.999742f, 0.999907f, 0.999990f, 0.999979f, 0.999811f, 0.999476f, 0.998973f, 0.998302f, + 0.997465f, 0.996460f, 0.995289f, 0.993952f, 0.992450f, 0.990782f, 0.988950f, 0.986955f, + 0.984796f, 0.982475f, 0.979993f, 0.977350f, 0.974548f, 0.971587f, 0.968469f, 0.965194f, + 0.961765f, 0.958182f, 0.954446f, 0.950559f, 0.946522f, 0.942337f, 0.938005f, 0.933528f, + 0.928908f, 0.924146f, 0.919243f, 0.914202f, 0.909025f, 0.903713f, 0.898269f, 0.892694f, + 0.886990f, 0.881160f, 0.875205f, 0.869128f, 0.862931f, 0.856617f, 0.850186f, 0.843643f, + 0.836989f, 0.830226f, 0.823358f, 0.816386f, 0.809314f, 0.802143f, 0.794877f, 0.787518f, + 0.780068f, 0.772531f, 0.764909f, 0.757206f, 0.749422f, 0.741563f, 0.733630f, 0.725626f, + 0.717555f, 0.709419f, 0.701221f, 0.692964f, 0.684652f, 0.676287f, 0.667872f, 0.659410f, + 0.650905f, 0.642360f, 0.633777f, 0.625160f, 0.616512f, 0.607835f, 0.599135f, 0.590412f, + 0.581672f, 0.572916f, 0.564148f, 0.555371f, 0.546589f, 0.537804f, 0.529020f, 0.520240f, + 0.511467f, 0.502705f, 0.493956f, 0.485224f, 0.476512f, 0.467823f, 0.459161f, 0.450528f, + 0.441927f, 0.433363f, 0.424837f, 0.416353f, 0.407915f, 0.399524f, 0.391185f, 0.382900f, + 0.374672f, 0.366505f, 0.358401f, 0.350363f, 0.342395f, 0.334498f, 0.326676f, 0.318932f, + 0.311269f, 0.303689f, 0.296196f, 0.288791f, 0.281478f, 0.274259f, 0.267137f, 0.260115f, + 0.253195f, 0.246379f, 0.239670f, 0.233071f, 0.226584f, 0.220211f, 0.213955f, 0.207818f, + 0.201802f, 0.195909f, 0.190142f, 0.184502f, 0.178992f, 0.173614f, 0.168369f, 0.163260f, + 0.158288f, 0.153456f, 0.148764f, 0.144215f, 0.139811f, 0.135552f, 0.131441f, 0.127479f, + 0.123667f, 0.120008f, 0.116501f, 0.113149f, 0.109952f, 0.106913f, 0.104031f, 0.101309f, + 0.098746f, 0.096344f, 0.094104f, 0.092027f, 0.090113f, 0.088363f, 0.086778f, 0.085358f, + 0.084104f, 0.083017f, 0.082096f, 0.081342f, 0.080755f, 0.080336f, 0.080084f, 0.080000f +}; + +/* LP analysis window for AMR-WB IO mode (length of the window is 30ms which is + * 384 samples at 12.8kHz */ +const float hamcos_window[L_LP_AMR_WB] = +{ + 0.080000f, 0.080035f, 0.080139f, 0.080313f, 0.080556f, 0.080869f, 0.081251f, 0.081703f, + 0.082224f, 0.082814f, 0.083473f, 0.084201f, 0.084998f, 0.085864f, 0.086799f, 0.087802f, + 0.088873f, 0.090013f, 0.091221f, 0.092496f, 0.093839f, 0.095250f, 0.096728f, 0.098273f, + 0.099884f, 0.101563f, 0.103307f, 0.105118f, 0.106994f, 0.108936f, 0.110943f, 0.113015f, + 0.115151f, 0.117351f, 0.119616f, 0.121944f, 0.124335f, 0.126789f, 0.129306f, 0.131884f, + 0.134525f, 0.137226f, 0.139989f, 0.142812f, 0.145695f, 0.148638f, 0.151639f, 0.154700f, + 0.157819f, 0.160995f, 0.164229f, 0.167520f, 0.170867f, 0.174270f, 0.177728f, 0.181241f, + 0.184808f, 0.188429f, 0.192103f, 0.195829f, 0.199608f, 0.203438f, 0.207319f, 0.211250f, + 0.215231f, 0.219261f, 0.223340f, 0.227466f, 0.231640f, 0.235860f, 0.240126f, 0.244438f, + 0.248794f, 0.253195f, 0.257638f, 0.262125f, 0.266653f, 0.271223f, 0.275833f, 0.280483f, + 0.285173f, 0.289901f, 0.294667f, 0.299470f, 0.304309f, 0.309184f, 0.314094f, 0.319038f, + 0.324015f, 0.329025f, 0.334067f, 0.339140f, 0.344244f, 0.349377f, 0.354538f, 0.359728f, + 0.364946f, 0.370189f, 0.375458f, 0.380753f, 0.386071f, 0.391412f, 0.396776f, 0.402162f, + 0.407568f, 0.412995f, 0.418441f, 0.423905f, 0.429386f, 0.434885f, 0.440399f, 0.445928f, + 0.451472f, 0.457029f, 0.462598f, 0.468179f, 0.473771f, 0.479373f, 0.484984f, 0.490604f, + 0.496231f, 0.501865f, 0.507504f, 0.513148f, 0.518797f, 0.524448f, 0.530102f, 0.535757f, + 0.541413f, 0.547069f, 0.552724f, 0.558377f, 0.564027f, 0.569673f, 0.575315f, 0.580952f, + 0.586582f, 0.592205f, 0.597821f, 0.603428f, 0.609025f, 0.614611f, 0.620187f, 0.625750f, + 0.631300f, 0.636837f, 0.642359f, 0.647865f, 0.653355f, 0.658828f, 0.664283f, 0.669719f, + 0.675136f, 0.680532f, 0.685907f, 0.691260f, 0.696590f, 0.701896f, 0.707178f, 0.712435f, + 0.717665f, 0.722869f, 0.728045f, 0.733192f, 0.738311f, 0.743399f, 0.748457f, 0.753483f, + 0.758477f, 0.763438f, 0.768365f, 0.773257f, 0.778115f, 0.782936f, 0.787720f, 0.792467f, + 0.797176f, 0.801846f, 0.806477f, 0.811067f, 0.815616f, 0.820124f, 0.824589f, 0.829011f, + 0.833389f, 0.837723f, 0.842012f, 0.846256f, 0.850453f, 0.854603f, 0.858706f, 0.862760f, + 0.866766f, 0.870722f, 0.874628f, 0.878484f, 0.882288f, 0.886041f, 0.889741f, 0.893389f, + 0.896983f, 0.900523f, 0.904009f, 0.907439f, 0.910814f, 0.914133f, 0.917395f, 0.920601f, + 0.923748f, 0.926838f, 0.929869f, 0.932842f, 0.935755f, 0.938608f, 0.941401f, 0.944133f, + 0.946804f, 0.949413f, 0.951961f, 0.954446f, 0.956869f, 0.959229f, 0.961525f, 0.963758f, + 0.965926f, 0.968030f, 0.970070f, 0.972044f, 0.973953f, 0.975796f, 0.977574f, 0.979285f, + 0.980930f, 0.982509f, 0.984020f, 0.985464f, 0.986841f, 0.988151f, 0.989392f, 0.990566f, + 0.991672f, 0.992709f, 0.993678f, 0.994578f, 0.995409f, 0.996172f, 0.996866f, 0.997490f, + 0.998046f, 0.998532f, 0.998949f, 0.999296f, 0.999574f, 0.999783f, 0.999922f, 0.999991f, + 1.000000f, 0.999924f, 0.999698f, 0.999320f, 0.998791f, 0.998111f, 0.997280f, 0.996298f, + 0.995166f, 0.993883f, 0.992450f, 0.990867f, 0.989134f, 0.987252f, 0.985220f, 0.983039f, + 0.980710f, 0.978233f, 0.975607f, 0.972834f, 0.969914f, 0.966848f, 0.963635f, 0.960277f, + 0.956773f, 0.953125f, 0.949332f, 0.945396f, 0.941317f, 0.937096f, 0.932733f, 0.928229f, + 0.923585f, 0.918801f, 0.913879f, 0.908818f, 0.903619f, 0.898284f, 0.892814f, 0.887208f, + 0.881468f, 0.875595f, 0.869589f, 0.863452f, 0.857185f, 0.850788f, 0.844262f, 0.837609f, + 0.830829f, 0.823923f, 0.816893f, 0.809739f, 0.802463f, 0.795066f, 0.787548f, 0.779911f, + 0.772157f, 0.764285f, 0.756298f, 0.748197f, 0.739983f, 0.731657f, 0.723220f, 0.714674f, + 0.706019f, 0.697258f, 0.688392f, 0.679421f, 0.670348f, 0.661174f, 0.651899f, 0.642526f, + 0.633056f, 0.623490f, 0.613830f, 0.604077f, 0.594233f, 0.584299f, 0.574276f, 0.564167f, + 0.553972f, 0.543694f, 0.533333f, 0.522892f, 0.512372f, 0.501774f, 0.491101f, 0.480353f, + 0.469533f, 0.458641f, 0.447680f, 0.436652f, 0.425558f, 0.414399f, 0.403177f, 0.391895f, + 0.380553f, 0.369154f, 0.357699f, 0.346190f, 0.334629f, 0.323017f, 0.311356f, 0.299648f, + 0.287895f, 0.276098f, 0.264260f, 0.252381f, 0.240465f, 0.228512f, 0.216524f, 0.204504f, + 0.192453f, 0.180373f, 0.168265f, 0.156132f, 0.143976f, 0.131797f, 0.119599f, 0.107383f, + 0.095150f, 0.082903f, 0.070644f, 0.058374f, 0.046095f, 0.033809f, 0.021518f, 0.009223f +}; + + +/* LAGW_STRONG */ +const float lag_window_8k[17] = +{ + 1.0001f, + 0.998890285694f, 0.995568526105f, 0.990056789412f, 0.982391584471f, + 0.972623458067f, 0.960816439805f, 0.947047343167f, 0.931404933402f, + 0.913988974871f, 0.894909172129f, 0.874284020465f, 0.852239582728f, + 0.828908210054f, 0.804427224606f, 0.778937582562f, 0.752582535421f +}; + +const float lag_window_12k8[NUM_LAGW_STRENGTHS][17] = +{ + /* LAGW_WEAK */ + { + 1.0001f, + 0.999951809733f, 0.999807252867f, 0.999566371195f, 0.999229234349f, + 0.998795939769f, 0.998266612656f, 0.997641405905f, 0.996920500042f, + 0.996104103128f, 0.995192450664f, 0.994185805476f, 0.993084457589f, + 0.991888724088f, 0.990598948965f, 0.989215502956f, 0.987738783362f + }, + /* LAGW_MEDIUM */ + { + 1.0001f, + 0.999807252867f, 0.999229234349f, 0.998266612656f, 0.996920500042f, + 0.995192450664f, 0.993084457589f, 0.990598948965f, 0.987738783362f, + 0.984507244288f, 0.980908033914f, 0.976945266001f, 0.972623458067f, + 0.967947522806f, 0.962922758784f, 0.957554840431f, 0.951849807369f + }, + /* LAGW_STRONG */ + { + 1.0001f, + 0.999566371183f, 0.998266612613f, 0.996104103033f, 0.993084457421f, + 0.989215493202f, 0.984507262707f, 0.978971838951f, 0.972623467445f, + 0.965478420258f, 0.957554817200f, 0.948872864246f, 0.939454317093f, + 0.929322779179f, 0.918503403664f, 0.907022833824f, 0.894909143448f + } +}; + +const float lag_window_16k[NUM_LAGW_STRENGTHS][17] = +{ + /* LAGW_WEAK */ + { + 1.0001f, + 0.999969157962f, 0.999876637555f, 0.999722455899f, 0.999506641521f, + 0.999229234349f, 0.998890285694f, 0.998489858239f, 0.998028026020f, + 0.997504874399f, 0.996920500042f, 0.996275010885f, 0.995568526105f, + 0.994801176082f, 0.993973102356f, 0.993084457589f, 0.992135405511f + }, + /* LAGW_MEDIUM */ + { + 1.0001f, + 0.999876637555f, 0.999506641521f, 0.998890285694f, 0.998028026020f, + 0.996920500042f, 0.995568526105f, 0.993973102356f, 0.992135405511f, + 0.990056789412f, 0.987738783362f, 0.985183090250f, 0.982391584471f, + 0.979366309628f, 0.976109476043f, 0.972623458067f, 0.968910791191f + }, + /* LAGW_STRONG */ + { + 1.0001f, + 0.999722455899f, 0.998890285694f, 0.997504874399f, 0.995568526105f, + 0.993084457589f, 0.990056789412f, 0.986490534533f, 0.982391584471f, + 0.977766693093f, 0.972623458067f, 0.966970300068f, 0.960816439805f, + 0.954171872966f, 0.947047343167f, 0.939454313017f, 0.931404933402f + } +}; + +const float lag_window_25k6[NUM_LAGW_STRENGTHS][17] = +{ + /* LAGW_WEAK */ + { + 1.0001f, + 0.999987952216f, 0.999951809733f, 0.999891575166f, 0.999807252867f, + 0.999698848932f, 0.999566371195f, 0.999409829230f, 0.999229234349f, + 0.999024599601f, 0.998795939769f, 0.998543271372f, 0.998266612656f, + 0.997965983599f, 0.997641405905f, 0.997292903003f, 0.996920500042f + }, + /* LAGW_MEDIUM */ + { + 1.0001f, + 0.999951809733f, 0.999807252867f, 0.999566371195f, 0.999229234349f, + 0.998795939769f, 0.998266612656f, 0.997641405905f, 0.996920500042f, + 0.996104103128f, 0.995192450664f, 0.994185805476f, 0.993084457589f, + 0.991888724088f, 0.990598948965f, 0.989215502956f, 0.987738783362f + }, + /* LAGW_STRONG */ + { + 1.0001f, + 0.999891579151f, 0.999566376209f, 0.999024569988f, 0.998266637325f, + 0.997292876244f, 0.996104121208f, 0.994700968266f, 0.993084430695f, + 0.991255581379f, 0.989215493202f, 0.986965596676f, 0.984507262707f, + 0.981842100620f, 0.978971838951f, 0.975898265839f, 0.972623467445f + } +}; + +const float lag_window_32k[NUM_LAGW_STRENGTHS][17] = +{ + /* LAGW_WEAK */ + { + 1.0001f, + 0.999992289401f, 0.999969157962f, 0.999930606752f, 0.999876637555f, + 0.999807252867f, 0.999722455899f, 0.999622250572f, 0.999506641521f, + 0.999375634094f, 0.999229234349f, 0.999067449055f, 0.998890285694f, + 0.998697752455f, 0.998489858239f, 0.998266612656f, 0.998028026020f + }, + /* LAGW_MEDIUM */ + { + 1.0001f, + 0.999969157962f, 0.999876637555f, 0.999722455899f, 0.999506641521f, + 0.999229234349f, 0.998890285694f, 0.998489858239f, 0.998028026020f, + 0.997504874399f, 0.996920500042f, 0.996275010885f, 0.995568526105f, + 0.994801176082f, 0.993973102356f, 0.993084457589f, 0.992135405511f + }, + /* LAGW_STRONG */ + { + 1.0001f, + 0.999930606752f, 0.999722455899f, 0.999375634094f, 0.998890285694f, + 0.998266612656f, 0.997504874399f, 0.996605387628f, 0.995568526105f, + 0.994394720400f, 0.993084457589f, 0.991638280913f, 0.990056789412f, + 0.988340637503f, 0.986490534533f, 0.984507244288f, 0.982391584471f + } +}; + +/* LAGW_STRONG */ +const float lag_window_48k[17] = +{ + 1.0001f, + 0.999969157962f, 0.999876637555f, 0.999722455899f, 0.999506641521f, + 0.999229234349f, 0.998890285694f, 0.998489858239f, 0.998028026020f, + 0.997504874399f, 0.996920500042f, 0.996275010885f, 0.995568526105f, + 0.994801176082f, 0.993973102356f, 0.993084457589f, 0.992135405511f +}; + + +/*----------------------------------------------------------------------------------* + * LP analysis - grid of points for evaluating Chebyshev polynomials + *----------------------------------------------------------------------------------*/ +const float grid50[(GRID50_POINTS-1)/2 - 1] = +{ + 0.9980267284f, 0.9921147013f, 0.9822872507f, 0.9685831611f, 0.9510565163f, + 0.9297764859f, 0.9048270525f, 0.8763066800f, 0.8443279255f, 0.8090169944f, + 0.7705132428f, 0.7289686274f, 0.6845471059f, 0.6374239897f, 0.5877852523f, + 0.5358267950f, 0.4817536741f, 0.4257792916f, 0.3681245527f, 0.3090169944f, + 0.2486898872f, 0.1873813146f, 0.1253332336f, 0.0627905195f +}; + +const float grid40[(GRID40_POINTS-1)/2 - 1] = +{ + 0.9969173337f, 0.9876883406f, 0.9723699204f, 0.9510565163f, 0.9238795325f, + 0.8910065242f, 0.8526401644f, 0.8090169944f, 0.7604059656f, 0.7071067812f, + 0.6494480483f, 0.5877852523f, 0.5224985647f, 0.4539904997f, 0.3826834324f, + 0.3090169944f, 0.2334453639f, 0.1564344650f, 0.0784590957f +}; + +const float grid100[GRID100_POINTS+1] = +{ + 1.0000000000f, 0.9995065331f, 0.9980267286f, 0.9955619574f, 0.9921147227f, + 0.9876883626f, 0.9822872281f, 0.9759167433f, 0.9685831666f, 0.9602936506f, + 0.9510565400f, 0.9408807755f, 0.9297764897f, 0.9177545905f, 0.9048270583f, + 0.8910065293f, 0.8763066530f, 0.8607420325f, 0.8443279266f, 0.8270805478f, + 0.8090170026f, 0.7901549935f, 0.7705132365f, 0.7501110435f, 0.7289685607f, + 0.7071067691f, 0.6845470667f, 0.6613118052f, 0.6374239326f, 0.6129069924f, + 0.5877852440f, 0.5620833635f, 0.5358267426f, 0.5090413690f, 0.4817536175f, + 0.4539904296f, 0.4257791936f, 0.3971477747f, 0.3681245446f, 0.3387379050f, + 0.3090169728f, 0.2789910734f, 0.2486898303f, 0.2181431651f, 0.1873812228f, + 0.1564343721f, 0.1253331155f, 0.0941081867f, 0.0627903789f, 0.0314107276f, + -0.0000000437f, -0.0314108171f, -0.0627905875f, -0.0941083953f, -0.1253333241f, + -0.1564345658f, -0.1873814315f, -0.2181433737f, -0.2486900240f, -0.2789911330f, + -0.3090170324f, -0.3387379944f, -0.3681246340f, -0.3971479833f, -0.4257793725f, + -0.4539906085f, -0.4817537963f, -0.5090415478f, -0.5358269215f, -0.5620835423f, + -0.5877854228f, -0.6129072309f, -0.6374241710f, -0.6613120437f, -0.6845472455f, + -0.7071067691f, -0.7289686203f, -0.7501111031f, -0.7705132961f, -0.7901550531f, + -0.8090170622f, -0.8270806074f, -0.8443279862f, -0.8607420921f, -0.8763067126f, + -0.8910065889f, -0.9048271179f, -0.9177547097f, -0.9297765493f, -0.9408808351f, + -0.9510565996f, -0.9602937698f, -0.9685832262f, -0.9759168029f, -0.9822872877f, + -0.9876883626f, -0.9921147227f, -0.9955619574f, -0.9980267286f, -0.9995065331f, + -1.0000000000f +}; + +/*----------------------------------------------------------------------------------* + * Sinus & Cosinus - table for the FFT and IFFT of 256 points, + * dimension of the table = 161 + *----------------------------------------------------------------------------------*/ + +const float sincos_t[161] = +{ + 0.0f, + 0.0245412290096282960f, 0.0490676760673522950f, 0.0735645666718482970f, 0.0980171412229537960f, 0.1224106773734092700f, + 0.1467304676771163900f, 0.1709618866443634000f, 0.1950903236865997300f, 0.2191012352705001800f, 0.2429801821708679200f, + 0.2667127549648284900f, 0.2902846634387970000f, 0.3136817514896392800f, 0.3368898630142211900f, 0.3598950505256652800f, + 0.3826834261417388900f, 0.4052413105964660600f, 0.4275550842285156300f, 0.4496113359928131100f, 0.4713967442512512200f, + 0.4928981959819793700f, 0.5141027569770813000f, 0.5349976420402526900f, 0.5555702447891235400f, 0.5758081674575805700f, + 0.5956993103027343800f, 0.6152315735816955600f, 0.6343932747840881300f, 0.6531728506088256800f, 0.6715589761734008800f, + 0.6895405650138855000f, 0.7071067690849304200f, 0.7242470979690551800f, 0.7409511208534240700f, 0.7572088241577148400f, + 0.7730104327201843300f, 0.7883464097976684600f, 0.8032075166702270500f, 0.8175848126411438000f, 0.8314695954322814900f, + 0.8448535799980163600f, 0.8577286005020141600f, 0.8700869679450988800f, 0.8819212913513183600f, 0.8932242989540100100f, + 0.9039893150329589800f, 0.9142097830772399900f, 0.9238795042037963900f, 0.9329928159713745100f, 0.9415440559387207000f, + 0.9495281577110290500f, 0.9569403529167175300f, 0.9637760519981384300f, 0.9700312614440918000f, 0.9757021069526672400f, + 0.9807852506637573200f, 0.9852776527404785200f, 0.9891765117645263700f, 0.9924795627593994100f, 0.9951847195625305200f, + 0.9972904324531555200f, 0.9987954497337341300f, 0.9996988177299499500f, 1.0000000000000000000f, 0.9996988177299499500f, + 0.9987954497337341300f, 0.9972904324531555200f, 0.9951847195625305200f, 0.9924795627593994100f, 0.9891765117645263700f, + 0.9852776527404785200f, 0.9807852506637573200f, 0.9757021069526672400f, 0.9700312614440918000f, 0.9637760519981384300f, + 0.9569403529167175300f, 0.9495281577110290500f, 0.9415440559387207000f, 0.9329928159713745100f, 0.9238795042037963900f, + 0.9142097830772399900f, 0.9039893150329589800f, 0.8932242989540100100f, 0.8819212913513183600f, 0.8700869679450988800f, + 0.8577286005020141600f, 0.8448535799980163600f, 0.8314695954322814900f, 0.8175848126411438000f, 0.8032075166702270500f, + 0.7883464097976684600f, 0.7730104327201843300f, 0.7572088241577148400f, 0.7409511208534240700f, 0.7242470979690551800f, + 0.7071067690849304200f, 0.6895405650138855000f, 0.6715589761734008800f, 0.6531728506088256800f, 0.6343932747840881300f, + 0.6152315735816955600f, 0.5956993103027343800f, 0.5758081674575805700f, 0.5555702447891235400f, 0.5349976420402526900f, + 0.5141027569770813000f, 0.4928981959819793700f, 0.4713967442512512200f, 0.4496113359928131100f, 0.4275550842285156300f, + 0.4052413105964660600f, 0.3826834261417388900f, 0.3598950505256652800f, 0.3368898630142211900f, 0.3136817514896392800f, + 0.2902846634387970000f, 0.2667127549648284900f, 0.2429801821708679200f, 0.2191012352705001800f, 0.1950903236865997300f, + 0.1709618866443634000f, 0.1467304676771163900f, 0.1224106773734092700f, 0.0980171412229537960f, 0.0735645666718482970f, + 0.0490676723420619960f, 0.0245412290096282960f, -0.00000000041020686847303978f, -0.0245412290096282960f, -0.0490676760673522950f, + -0.0735645666718482970f, -0.0980171412229537960f, -0.1224106773734092700f, -0.1467304676771163900f, -0.1709618866443634000f, + -0.1950903236865997300f, -0.2191012352705001800f, -0.2429801821708679200f, -0.2667127549648284900f, -0.2902846634387970000f, + -0.3136817514896392800f, -0.3368898630142211900f, -0.3598950505256652800f, -0.3826834261417388900f, -0.4052413105964660600f, + -0.4275550842285156300f, -0.4496113359928131100f, -0.4713967442512512200f, -0.4928981959819793700f, -0.5141027569770813000f, + -0.5349976420402526900f, -0.5555702447891235400f, -0.5758081674575805700f, -0.5956993103027343800f, -0.6152315735816955600f, + -0.6343932747840881300f, -0.6531728506088256800f, -0.6715589761734008800f, -0.6895405650138855000f, -0.7071067690849304200f +}; + +/*----------------------------------------------------------------------------------* + * Sinus & Cosinus - table for the FFT and IFFT of 1024 points, value range [0 ... sin(-5pi/4)] + * dimension of the table = 641=4*256*(5/8)+1 + *----------------------------------------------------------------------------------*/ + +/* every 4th value is identical to sincos_t above but as sincos_t is also used in SWB TBE a separate table has been defined here */ +const float sincos_t_ext[641] = +{ + 0.0f, + 0.006135884649154f, 0.012271538285720f, 0.018406729905805f, 0.024541228522912f, 0.030674803176637f, 0.036807222941359f, 0.042938256934941f, 0.049067674327418f, + 0.055195244349690f, 0.061320736302209f, 0.067443919563664f, 0.073564563599667f, 0.079682437971430f, 0.085797312344440f, 0.091908956497133f, 0.098017140329561f, + 0.104121633872055f, 0.110222207293883f, 0.116318630911905f, 0.122410675199216f, 0.128498110793793f, 0.134580708507126f, 0.140658239332849f, 0.146730474455362f, + 0.152797185258443f, 0.158858143333861f, 0.164913120489970f, 0.170961888760301f, 0.177004220412149f, 0.183039887955141f, 0.189068664149806f, 0.195090322016128f, + 0.201104634842092f, 0.207111376192219f, 0.213110319916091f, 0.219101240156870f, 0.225083911359793f, 0.231058108280671f, 0.237023605994367f, 0.242980179903264f, + 0.248927605745720f, 0.254865659604515f, 0.260794117915276f, 0.266712757474898f, 0.272621355449949f, 0.278519689385053f, 0.284407537211272f, 0.290284677254462f, + 0.296150888243624f, 0.302005949319228f, 0.307849640041535f, 0.313681740398892f, 0.319502030816016f, 0.325310292162263f, 0.331106305759876f, 0.336889853392220f, + 0.342660717311994f, 0.348418680249435f, 0.354163525420490f, 0.359895036534988f, 0.365612997804774f, 0.371317193951837f, 0.377007410216418f, 0.382683432365090f, + 0.388345046698826f, 0.393992040061048f, 0.399624199845647f, 0.405241314004990f, 0.410843171057904f, 0.416429560097637f, 0.422000270799800f, 0.427555093430282f, + 0.433093818853152f, 0.438616238538528f, 0.444122144570429f, 0.449611329654607f, 0.455083587126344f, 0.460538710958240f, 0.465976495767966f, 0.471396736825998f, + 0.476799230063322f, 0.482183772079123f, 0.487550160148436f, 0.492898192229784f, 0.498227666972782f, 0.503538383725718f, 0.508830142543107f, 0.514102744193222f, + 0.519355990165590f, 0.524589682678469f, 0.529803624686295f, 0.534997619887097f, 0.540171472729893f, 0.545324988422046f, 0.550457972936605f, 0.555570233019602f, + 0.560661576197336f, 0.565731810783613f, 0.570780745886967f, 0.575808191417845f, 0.580813958095765f, 0.585797857456439f, 0.590759701858874f, 0.595699304492433f, + 0.600616479383869f, 0.605511041404326f, 0.610382806276309f, 0.615231590580627f, 0.620057211763289f, 0.624859488142386f, 0.629638238914927f, 0.634393284163645f, + 0.639124444863776f, 0.643831542889791f, 0.648514401022112f, 0.653172842953777f, 0.657806693297079f, 0.662415777590172f, 0.666999922303637f, 0.671558954847018f, + 0.676092703575316f, 0.680600997795453f, 0.685083667772700f, 0.689540544737067f, 0.693971460889654f, 0.698376249408973f, 0.702754744457225f, 0.707106781186547f, + 0.711432195745216f, 0.715730825283819f, 0.720002507961382f, 0.724247082951467f, 0.728464390448225f, 0.732654271672413f, 0.736816568877370f, 0.740951125354959f, + 0.745057785441466f, 0.749136394523459f, 0.753186799043613f, 0.757208846506485f, 0.761202385484262f, 0.765167265622459f, 0.769103337645580f, 0.773010453362737f, + 0.776888465673232f, 0.780737228572094f, 0.784556597155575f, 0.788346427626606f, 0.792106577300212f, 0.795836904608884f, 0.799537269107905f, 0.803207531480645f, + 0.806847553543799f, 0.810457198252595f, 0.814036329705948f, 0.817584813151584f, 0.821102514991105f, 0.824589302785025f, 0.828045045257756f, 0.831469612302545f, + 0.834862874986380f, 0.838224705554838f, 0.841554977436898f, 0.844853565249707f, 0.848120344803297f, 0.851355193105265f, 0.854557988365401f, 0.857728610000272f, + 0.860866938637767f, 0.863972856121587f, 0.867046245515693f, 0.870086991108711f, 0.873094978418290f, 0.876070094195407f, 0.879012226428633f, 0.881921264348355f, + 0.884797098430938f, 0.887639620402854f, 0.890448723244758f, 0.893224301195515f, 0.895966249756185f, 0.898674465693954f, 0.901348847046022f, 0.903989293123443f, + 0.906595704514915f, 0.909167983090522f, 0.911706032005430f, 0.914209755703531f, 0.916679059921043f, 0.919113851690058f, 0.921514039342042f, 0.923879532511287f, + 0.926210242138311f, 0.928506080473216f, 0.930766961078984f, 0.932992798834739f, 0.935183509938948f, 0.937339011912575f, 0.939459223602190f, 0.941544065183021f, + 0.943593458161960f, 0.945607325380521f, 0.947585591017741f, 0.949528180593037f, 0.951435020969008f, 0.953306040354194f, 0.955141168305771f, 0.956940335732209f, + 0.958703474895872f, 0.960430519415566f, 0.962121404269042f, 0.963776065795440f, 0.965394441697689f, 0.966976471044852f, 0.968522094274417f, 0.970031253194544f, + 0.971503890986252f, 0.972939952205560f, 0.974339382785576f, 0.975702130038529f, 0.977028142657754f, 0.978317370719628f, 0.979569765685441f, 0.980785280403230f, + 0.981963869109555f, 0.983105487431216f, 0.984210092386929f, 0.985277642388941f, 0.986308097244599f, 0.987301418157858f, 0.988257567730749f, 0.989176509964781f, + 0.990058210262297f, 0.990902635427780f, 0.991709753669100f, 0.992479534598710f, 0.993211949234795f, 0.993906970002356f, 0.994564570734255f, 0.995184726672197f, + 0.995767414467660f, 0.996312612182778f, 0.996820299291166f, 0.997290456678690f, 0.997723066644192f, 0.998118112900149f, 0.998475580573295f, 0.998795456205172f, + 0.999077727752645f, 0.999322384588350f, 0.999529417501093f, 0.999698818696204f, 0.999830581795823f, 0.999924701839145f, 0.999981175282601f, 1.000000000000000f, + 0.999981175282601f, 0.999924701839145f, 0.999830581795823f, 0.999698818696204f, 0.999529417501093f, 0.999322384588350f, 0.999077727752645f, 0.998795456205172f, + 0.998475580573295f, 0.998118112900149f, 0.997723066644192f, 0.997290456678690f, 0.996820299291166f, 0.996312612182778f, 0.995767414467660f, 0.995184726672197f, + 0.994564570734255f, 0.993906970002356f, 0.993211949234795f, 0.992479534598710f, 0.991709753669100f, 0.990902635427780f, 0.990058210262297f, 0.989176509964781f, + 0.988257567730749f, 0.987301418157858f, 0.986308097244599f, 0.985277642388941f, 0.984210092386929f, 0.983105487431216f, 0.981963869109555f, 0.980785280403230f, + 0.979569765685441f, 0.978317370719628f, 0.977028142657754f, 0.975702130038529f, 0.974339382785576f, 0.972939952205560f, 0.971503890986252f, 0.970031253194544f, + 0.968522094274417f, 0.966976471044852f, 0.965394441697689f, 0.963776065795440f, 0.962121404269042f, 0.960430519415566f, 0.958703474895872f, 0.956940335732209f, + 0.955141168305771f, 0.953306040354194f, 0.951435020969008f, 0.949528180593037f, 0.947585591017741f, 0.945607325380521f, 0.943593458161960f, 0.941544065183021f, + 0.939459223602190f, 0.937339011912575f, 0.935183509938948f, 0.932992798834739f, 0.930766961078984f, 0.928506080473216f, 0.926210242138311f, 0.923879532511287f, + 0.921514039342042f, 0.919113851690058f, 0.916679059921043f, 0.914209755703531f, 0.911706032005430f, 0.909167983090522f, 0.906595704514915f, 0.903989293123443f, + 0.901348847046022f, 0.898674465693954f, 0.895966249756185f, 0.893224301195515f, 0.890448723244758f, 0.887639620402854f, 0.884797098430938f, 0.881921264348355f, + 0.879012226428634f, 0.876070094195407f, 0.873094978418290f, 0.870086991108711f, 0.867046245515693f, 0.863972856121587f, 0.860866938637767f, 0.857728610000272f, + 0.854557988365401f, 0.851355193105265f, 0.848120344803297f, 0.844853565249707f, 0.841554977436898f, 0.838224705554838f, 0.834862874986380f, 0.831469612302545f, + 0.828045045257756f, 0.824589302785025f, 0.821102514991105f, 0.817584813151584f, 0.814036329705949f, 0.810457198252595f, 0.806847553543799f, 0.803207531480645f, + 0.799537269107905f, 0.795836904608884f, 0.792106577300212f, 0.788346427626606f, 0.784556597155575f, 0.780737228572095f, 0.776888465673232f, 0.773010453362737f, + 0.769103337645580f, 0.765167265622459f, 0.761202385484262f, 0.757208846506485f, 0.753186799043613f, 0.749136394523459f, 0.745057785441466f, 0.740951125354959f, + 0.736816568877370f, 0.732654271672413f, 0.728464390448225f, 0.724247082951467f, 0.720002507961382f, 0.715730825283819f, 0.711432195745217f, 0.707106781186548f, + 0.702754744457225f, 0.698376249408973f, 0.693971460889654f, 0.689540544737067f, 0.685083667772700f, 0.680600997795453f, 0.676092703575316f, 0.671558954847019f, + 0.666999922303638f, 0.662415777590172f, 0.657806693297079f, 0.653172842953777f, 0.648514401022113f, 0.643831542889791f, 0.639124444863776f, 0.634393284163645f, + 0.629638238914927f, 0.624859488142386f, 0.620057211763289f, 0.615231590580627f, 0.610382806276310f, 0.605511041404326f, 0.600616479383869f, 0.595699304492433f, + 0.590759701858874f, 0.585797857456439f, 0.580813958095765f, 0.575808191417845f, 0.570780745886967f, 0.565731810783613f, 0.560661576197336f, 0.555570233019602f, + 0.550457972936605f, 0.545324988422046f, 0.540171472729893f, 0.534997619887097f, 0.529803624686295f, 0.524589682678469f, 0.519355990165590f, 0.514102744193222f, + 0.508830142543107f, 0.503538383725718f, 0.498227666972782f, 0.492898192229784f, 0.487550160148436f, 0.482183772079123f, 0.476799230063322f, 0.471396736825998f, + 0.465976495767966f, 0.460538710958240f, 0.455083587126344f, 0.449611329654607f, 0.444122144570429f, 0.438616238538528f, 0.433093818853152f, 0.427555093430282f, + 0.422000270799800f, 0.416429560097637f, 0.410843171057904f, 0.405241314004990f, 0.399624199845647f, 0.393992040061048f, 0.388345046698827f, 0.382683432365090f, + 0.377007410216418f, 0.371317193951838f, 0.365612997804774f, 0.359895036534988f, 0.354163525420490f, 0.348418680249435f, 0.342660717311994f, 0.336889853392220f, + 0.331106305759876f, 0.325310292162263f, 0.319502030816016f, 0.313681740398891f, 0.307849640041535f, 0.302005949319228f, 0.296150888243624f, 0.290284677254462f, + 0.284407537211272f, 0.278519689385053f, 0.272621355449949f, 0.266712757474898f, 0.260794117915276f, 0.254865659604515f, 0.248927605745720f, 0.242980179903264f, + 0.237023605994367f, 0.231058108280671f, 0.225083911359793f, 0.219101240156870f, 0.213110319916091f, 0.207111376192219f, 0.201104634842092f, 0.195090322016129f, + 0.189068664149806f, 0.183039887955141f, 0.177004220412149f, 0.170961888760301f, 0.164913120489970f, 0.158858143333861f, 0.152797185258444f, 0.146730474455362f, + 0.140658239332850f, 0.134580708507126f, 0.128498110793793f, 0.122410675199216f, 0.116318630911905f, 0.110222207293883f, 0.104121633872055f, 0.098017140329561f, + 0.091908956497133f, 0.085797312344440f, 0.079682437971430f, 0.073564563599668f, 0.067443919563664f, 0.061320736302208f, 0.055195244349690f, 0.049067674327418f, + 0.042938256934941f, 0.036807222941359f, 0.030674803176637f, 0.024541228522912f, 0.018406729905805f, 0.012271538285720f, 0.006135884649155f, 0.000000000000000f, + -0.006135884649155f, -0.012271538285720f, -0.018406729905805f, -0.024541228522912f, -0.030674803176637f, -0.036807222941359f, -0.042938256934941f, -0.049067674327418f, + -0.055195244349690f, -0.061320736302208f, -0.067443919563664f, -0.073564563599667f, -0.079682437971430f, -0.085797312344440f, -0.091908956497133f, -0.098017140329561f, + -0.104121633872054f, -0.110222207293883f, -0.116318630911904f, -0.122410675199216f, -0.128498110793793f, -0.134580708507126f, -0.140658239332849f, -0.146730474455362f, + -0.152797185258443f, -0.158858143333861f, -0.164913120489970f, -0.170961888760301f, -0.177004220412149f, -0.183039887955141f, -0.189068664149806f, -0.195090322016128f, + -0.201104634842092f, -0.207111376192219f, -0.213110319916091f, -0.219101240156870f, -0.225083911359793f, -0.231058108280671f, -0.237023605994367f, -0.242980179903264f, + -0.248927605745720f, -0.254865659604514f, -0.260794117915276f, -0.266712757474898f, -0.272621355449949f, -0.278519689385053f, -0.284407537211272f, -0.290284677254462f, + -0.296150888243624f, -0.302005949319228f, -0.307849640041535f, -0.313681740398891f, -0.319502030816016f, -0.325310292162263f, -0.331106305759876f, -0.336889853392220f, + -0.342660717311994f, -0.348418680249435f, -0.354163525420490f, -0.359895036534988f, -0.365612997804774f, -0.371317193951837f, -0.377007410216418f, -0.382683432365090f, + -0.388345046698826f, -0.393992040061048f, -0.399624199845647f, -0.405241314004990f, -0.410843171057904f, -0.416429560097637f, -0.422000270799800f, -0.427555093430282f, + -0.433093818853152f, -0.438616238538527f, -0.444122144570429f, -0.449611329654607f, -0.455083587126344f, -0.460538710958240f, -0.465976495767966f, -0.471396736825998f, + -0.476799230063322f, -0.482183772079123f, -0.487550160148436f, -0.492898192229784f, -0.498227666972782f, -0.503538383725717f, -0.508830142543107f, -0.514102744193222f, + -0.519355990165590f, -0.524589682678469f, -0.529803624686295f, -0.534997619887097f, -0.540171472729893f, -0.545324988422046f, -0.550457972936605f, -0.555570233019602f, + -0.560661576197336f, -0.565731810783613f, -0.570780745886967f, -0.575808191417845f, -0.580813958095764f, -0.585797857456439f, -0.590759701858874f, -0.595699304492433f, + -0.600616479383869f, -0.605511041404325f, -0.610382806276309f, -0.615231590580627f, -0.620057211763289f, -0.624859488142386f, -0.629638238914927f, -0.634393284163645f, + -0.639124444863776f, -0.643831542889791f, -0.648514401022112f, -0.653172842953777f, -0.657806693297079f, -0.662415777590172f, -0.666999922303637f, -0.671558954847018f, + -0.676092703575316f, -0.680600997795453f, -0.685083667772700f, -0.689540544737067f, -0.693971460889654f, -0.698376249408973f, -0.702754744457225f, -0.707106781186547f +}; + + +const float Asr_LP32[41] = +{ + 0.00000000f, 0.00074311f, 0.00168152f, 0.00177319f, -0.00000000f, -0.00345938f, -0.00653664f, -0.00604727f, + 0.00000000f, 0.00988729f, 0.01759782f, 0.01556464f, -0.00000000f, -0.02426962f, -0.04321351f, -0.03907450f, + 0.00000000f, 0.07133152f, 0.15563209f, 0.22382514f, 0.25000000f, 0.22382514f, 0.15563209f, 0.07133152f, + 0.00000000f, -0.03907450f, -0.04321351f, -0.02426962f, -0.00000000f, 0.01556464f, 0.01759782f, 0.00988729f, + 0.00000000f, -0.00604727f, -0.00653664f, -0.00345938f, -0.00000000f, 0.00177319f, 0.00168152f, 0.00074311f, + 0.00000000f +}; + + +const float Asr_LP16[21] = +{ + 0.00000000f, 0.00336304f, -0.00000000f, -0.01307328f, 0.00000000f, 0.03519564f, -0.00000000f, -0.08642702f, + 0.00000000f, 0.31126418f, 0.50000000f, 0.31126418f, 0.00000000f, -0.08642702f, -0.00000000f, 0.03519564f, + 0.00000000f, -0.01307328f, -0.00000000f, 0.00336304f, 0.00000000f +}; + + +const float Asr_LP48[61] = +{ + 0.00000000f, 0.00029287f, 0.00071673f, 0.00112101f, 0.00127506f, 0.00094416f, -0.00000000f, -0.00147233f, + -0.00311928f, -0.00435776f, -0.00452368f, -0.00310585f, 0.00000000f, 0.00430863f, 0.00872382f, 0.01173188f, + 0.01180048f, 0.00789952f, -0.00000000f, -0.01061594f, -0.02137287f, -0.02880901f, -0.02932326f, -0.02010347f, + 0.00000000f, 0.02990484f, 0.06622310f, 0.10375473f, 0.13646949f, 0.15876038f, 0.16666667f, 0.15876038f, + 0.13646949f, 0.10375473f, 0.06622310f, 0.02990484f, 0.00000000f, -0.02010347f, -0.02932326f, -0.02880901f, + -0.02137287f, -0.01061594f, -0.00000000f, 0.00789952f, 0.01180048f, 0.01173188f, 0.00872382f, 0.00430863f, + 0.00000000f, -0.00310585f, -0.00452368f, -0.00435776f, -0.00311928f, -0.00147233f, -0.00000000f, 0.00094416f, + 0.00127506f, 0.00112101f, 0.00071673f, 0.00029287f, 0.00000000f +}; + +const short fft256_read_indexes[]= +{ + 0, 128, 64, 192, 32, 160, 96, 224, 16, 144, 80, 208, 48, 176, 112, 240, + 8, 136, 72, 200, 40, 168, 104, 232, 24, 152, 88, 216, 56, 184, 120, 248, + 4, 132, 68, 196, 36, 164, 100, 228, 20, 148, 84, 212, 52, 180, 116, 244, + 12, 140, 76, 204, 44, 172, 108, 236, 28, 156, 92, 220, 60, 188, 124, 252, + 2, 130, 66, 194, 34, 162, 98, 226, 18, 146, 82, 210, 50, 178, 114, 242, + 10, 138, 74, 202, 42, 170, 106, 234, 26, 154, 90, 218, 58, 186, 122, 250, + 6, 134, 70, 198, 38, 166, 102, 230, 22, 150, 86, 214, 54, 182, 118, 246, + 14, 142, 78, 206, 46, 174, 110, 238, 30, 158, 94, 222, 62, 190, 126, 254, + 1, 129, 65, 193, 33, 161, 97, 225, 17, 145, 81, 209, 49, 177, 113, 241, + 9, 137, 73, 201, 41, 169, 105, 233, 25, 153, 89, 217, 57, 185, 121, 249, + 5, 133, 69, 197, 37, 165, 101, 229, 21, 149, 85, 213, 53, 181, 117, 245, + 13, 141, 77, 205, 45, 173, 109, 237, 29, 157, 93, 221, 61, 189, 125, 253, + 3, 131, 67, 195, 35, 163, 99, 227, 19, 147, 83, 211, 51, 179, 115, 243, + 11, 139, 75, 203, 43, 171, 107, 235, 27, 155, 91, 219, 59, 187, 123, 251, + 7, 135, 71, 199, 39, 167, 103, 231, 23, 151, 87, 215, 55, 183, 119, 247, + 15, 143, 79, 207, 47, 175, 111, 239, 31, 159, 95, 223, 63, 191, 127, 255 +}; + + +/*----------------------------------------------------------------------------------* + * Sinus & Cosinus - table for the DCT-IV based 2 + *----------------------------------------------------------------------------------*/ + +const float sin_table256[] = +{ + 0.003067957f, 0.009203755f, 0.015339206f, 0.02147408f, 0.027608146f, 0.033741172f, 0.039872928f, 0.046003182f, 0.052131705f, + 0.058258265f, 0.064382631f, 0.070504573f, 0.076623861f, 0.082740265f, 0.088853553f, 0.094963495f, 0.101069863f, 0.107172425f, + 0.113270952f, 0.119365215f, 0.125454983f, 0.131540029f, 0.137620122f, 0.143695033f, 0.149764535f, 0.155828398f, 0.161886394f, + 0.167938295f, 0.173983873f, 0.180022901f, 0.186055152f, 0.192080397f, 0.198098411f, 0.204108966f, 0.210111837f, 0.216106797f, + 0.222093621f, 0.228072083f, 0.234041959f, 0.240003022f, 0.24595505f, 0.251897818f, 0.257831102f, 0.263754679f, 0.269668326f, + 0.275571819f, 0.281464938f, 0.28734746f, 0.293219163f, 0.299079826f, 0.30492923f, 0.310767153f, 0.316593376f, 0.322407679f, + 0.328209844f, 0.333999651f, 0.339776884f, 0.345541325f, 0.351292756f, 0.357030961f, 0.362755724f, 0.36846683f, 0.374164063f, + 0.379847209f, 0.385516054f, 0.391170384f, 0.396809987f, 0.402434651f, 0.408044163f, 0.413638312f, 0.419216888f, 0.424779681f, + 0.430326481f, 0.43585708f, 0.441371269f, 0.44686884f, 0.452349587f, 0.457813304f, 0.463259784f, 0.468688822f, 0.474100215f, + 0.479493758f, 0.484869248f, 0.490226483f, 0.495565262f, 0.500885383f, 0.506186645f, 0.51146885f, 0.516731799f, 0.521975293f, + 0.527199135f, 0.532403128f, 0.537587076f, 0.542750785f, 0.547894059f, 0.553016706f, 0.558118531f, 0.563199344f, 0.568258953f, + 0.573297167f, 0.578313796f, 0.583308653f, 0.588281548f, 0.593232295f, 0.598160707f, 0.603066599f, 0.607949785f, 0.612810082f, + 0.617647308f, 0.622461279f, 0.627251815f, 0.632018736f, 0.636761861f, 0.641481013f, 0.646176013f, 0.650846685f, 0.655492853f, + 0.660114342f, 0.664710978f, 0.669282588f, 0.673829f, 0.678350043f, 0.682845546f, 0.687315341f, 0.691759258f, 0.696177131f, + 0.700568794f, 0.70493408f, 0.709272826f, 0.713584869f, 0.717870045f, 0.722128194f, 0.726359155f, 0.730562769f, 0.734738878f, + 0.738887324f, 0.743007952f, 0.747100606f, 0.751165132f, 0.755201377f, 0.759209189f, 0.763188417f, 0.767138912f, 0.771060524f, + 0.774953107f, 0.778816512f, 0.782650596f, 0.786455214f, 0.790230221f, 0.793975478f, 0.797690841f, 0.801376172f, 0.805031331f, + 0.808656182f, 0.812250587f, 0.815814411f, 0.81934752f, 0.822849781f, 0.826321063f, 0.829761234f, 0.833170165f, 0.836547727f, + 0.839893794f, 0.84320824f, 0.846490939f, 0.849741768f, 0.852960605f, 0.856147328f, 0.859301818f, 0.862423956f, 0.865513624f, + 0.868570706f, 0.871595087f, 0.874586652f, 0.87754529f, 0.880470889f, 0.883363339f, 0.88622253f, 0.889048356f, 0.891840709f, + 0.894599486f, 0.897324581f, 0.900015892f, 0.902673318f, 0.905296759f, 0.907886116f, 0.910441292f, 0.91296219f, 0.915448716f, + 0.917900776f, 0.920318277f, 0.922701128f, 0.925049241f, 0.927362526f, 0.929640896f, 0.931884266f, 0.93409255f, 0.936265667f, + 0.938403534f, 0.940506071f, 0.942573198f, 0.944604837f, 0.946600913f, 0.94856135f, 0.950486074f, 0.952375013f, 0.954228095f, + 0.956045251f, 0.957826413f, 0.959571513f, 0.961280486f, 0.962953267f, 0.964589793f, 0.966190003f, 0.967753837f, 0.969281235f, + 0.970772141f, 0.972226497f, 0.97364425f, 0.975025345f, 0.976369731f, 0.977677358f, 0.978948175f, 0.980182136f, 0.981379193f, + 0.982539302f, 0.983662419f, 0.984748502f, 0.985797509f, 0.986809402f, 0.987784142f, 0.988721692f, 0.989622017f, 0.990485084f, + 0.99131086f, 0.992099313f, 0.992850414f, 0.993564136f, 0.994240449f, 0.994879331f, 0.995480755f, 0.996044701f, 0.996571146f, + 0.99706007f, 0.997511456f, 0.997925286f, 0.998301545f, 0.998640218f, 0.998941293f, 0.999204759f, 0.999430605f, 0.999618822f, + 0.999769405f, 0.999882347f, 0.999957645f, 0.999995294f +}; + + +/*----------------------------------------------------------------------------------* + * 1/4 resolution interpolation filter (-3 dB at 0.913*fs/2) + *----------------------------------------------------------------------------------*/ + +const float inter4_2[65] = +{ + 0.940000f, + 0.856390f, 0.632268f, 0.337560f, 0.059072f, + -0.131059f, -0.199393f, -0.158569f, -0.056359f, + 0.047606f, 0.106749f, 0.103705f, 0.052062f, + -0.015182f, -0.063705f, -0.073660f, -0.046497f, + -0.000983f, 0.038227f, 0.053143f, 0.040059f, + 0.009308f, -0.021674f, -0.037767f, -0.033186f, + -0.013028f, 0.010702f, 0.025901f, 0.026318f, + 0.013821f, -0.003645f, -0.016813f, -0.019855f, + -0.012766f, -0.000530f, 0.010080f, 0.014122f, + 0.010657f, 0.002594f, -0.005363f, -0.009344f, + -0.008101f, -0.003182f, 0.002330f, 0.005635f, + 0.005562f, 0.002844f, -0.000627f, -0.002993f, + -0.003362f, -0.002044f, -0.000116f, 0.001315f, + 0.001692f, 0.001151f, 0.000259f, -0.000417f, + -0.000618f, -0.000434f, -0.000133f, 0.000063f, + 0.000098f, 0.000048f, 0.000007f, 0.000000f +}; + + +/*----------------------------------------------------------------------------------* + * 1/6 resolution interpolation filter (-3 dB at 0.95*fs/2) + *----------------------------------------------------------------------------------*/ + +const float inter6_2[PIT_FIR_SIZE6_2] = +{ + 0.949986374119862F, 0.911081104469830F, 0.800115099292852F, 0.633320673120883F, 0.434558462154083F, 0.231177017786780F, + 0.049378173063717F, -0.090039611811170F, -0.174782560924477F, -0.202477516286360F, -0.180218293244902F, -0.122429229978978F, + -0.047552067127379F, 0.025733669494145F, 0.081995376731897F, 0.111581381838187F, 0.111781798292302F, 0.086499988914996F, + 0.044629684447068F, -0.002416435594242F, -0.043440027386915F, -0.069857782812169F, -0.077293683967992F, -0.066098268486336F, + -0.040782649068098F, -0.008590773415008F, 0.022397654632128F, 0.045171360007974F, 0.055274128677739F, 0.051578034020076F, + 0.036232016917169F, 0.013869500422767F, -0.009680698856947F, -0.028843394410080F, -0.039560663181280F, -0.040095747151623F, + -0.031231107680685F, -0.015866154815425F, 0.001841532922707F, 0.017553701334759F, 0.027778555138199F, 0.030612329573745F, + 0.026046143652186F, 0.015803012695681F, 0.002782973481834F, -0.009720124055079F, -0.018826488463900F, -0.022710487805852F, + -0.020936374578238F, -0.014436620433404F, -0.005169079181373F, 0.004437651243491F, 0.012100372954920F, 0.016207075406240F, + 0.016135389123271F, 0.012306629559665F, 0.005986734945567F, -0.001094950878591F, -0.007200842219958F, -0.010998212848124F, + -0.011835179448280F, -0.009826566540474F, -0.005747665080695F, -0.000780600030751F, 0.003810613287985F, 0.006990479233404F, + 0.008174249796791F, 0.007317375965949F, 0.004864690818765F, 0.001587005259212F, -0.001642504305841F, -0.004070609517416F, + -0.005230670504649F, -0.005019147682711F, -0.003673879223241F, -0.001671460853812F, 0.000420750005150F, 0.002095384947391F, + 0.003020513665060F, 0.003095468528243F, 0.002441025550729F, 0.001335514431569F, 0.000120805384516F, -0.000893340757369F, + -0.001501610712267F, -0.001636887611783F, -0.001362571776250F, -0.000832126175863F, -0.000232033375863F, 0.000273627139471F, + 0.000582092683087F, 0.000666445711949F, 0.000566088888178F, 0.000360374058147F, 0.000136306914913F, -0.000038864994777F, + -0.000132755824518F, -0.000148377158880F, -0.000112937171810F, -0.000061132514471F, -0.000019974224468F, -0.000000460344975F, + 0.000001976848453F +}; + + +/*----------------------------------------------------------------------------------* + * Low-pass FIR filter for low-frequency post-filtering @ 16kHz + * response : -6dB @ 50Hz, -3dB @ 500Hz, -6dB @ 6.4kHz) + * L_FILT=15 @ 16kHz (1+4x15=61 coef) + * L_FILT=12 @ 12.8kHz (1+5x12=61 coef) + * filter parameters: fs/2=32000, fc=6400, gain=5.0, n=61 + *----------------------------------------------------------------------------------*/ + +static const float filter_LP12_180H[] = /* Sincfilt.m: N=180*2+1, Fmin=0, Fmax=1/12, hann( N )' */ +{ + 1.00000000f, 0.98854064f, 0.95463880f, 0.89969939f, 0.82598609f, 0.73650898f, + 0.63487604f, 0.52511631f, 0.41148461f, 0.29825804f, 0.18953518f, 0.08904855f, + 0.00000000f, -0.07507283f, -0.13439242f, -0.17699551f, -0.20274380f, -0.21229157f, + -0.20701353f, -0.18889782f, -0.16041129f, -0.12434529f, -0.08365114f, -0.04127482f, + -0.00000000f, 0.03769212f, 0.06973903f, 0.09458356f, 0.11122751f, 0.11925054f, + 0.11879487f, 0.11051837f, 0.09552022f, 0.07524478f, 0.05137065f, 0.02569204f, + 0.00000000f, -0.02402919f, -0.04493222f, -0.06153821f, -0.07302535f, -0.07895262f, + -0.07926575f, -0.07427839f, -0.06463103f, -0.05123120f, -0.03517999f, -0.01768990f, + -0.00000000f, 0.01670619f, 0.03137493f, 0.04314423f, 0.05139005f, 0.05575472f, + 0.05615642f, 0.05278011f, 0.04605151f, 0.03659641f, 0.02518906f, 0.01269314f, + 0.00000000f, -0.01203202f, -0.02263294f, -0.03116789f, -0.03717261f, -0.04037571f, + -0.04070711f, -0.03829248f, -0.03343501f, -0.02658610f, -0.01830764f, -0.00922872f, + -0.00000000f, 0.00875109f, 0.01646140f, 0.02266671f, 0.02702792f, 0.02934764f, + 0.02957617f, 0.02780739f, 0.02426498f, 0.01928068f, 0.01326622f, 0.00668131f, + 0.00000000f, -0.00632223f, -0.01187840f, -0.01633509f, -0.01945125f, -0.02108964f, + -0.02122066f, -0.01991853f, -0.01735069f, -0.01376125f, -0.00945018f, -0.00474975f, + -0.00000000f, 0.00447492f, 0.00838805f, 0.01150721f, 0.01366775f, 0.01478001f, + 0.01483115f, 0.01388152f, 0.01205626f, 0.00953282f, 0.00652562f, 0.00326903f, + 0.00000000f, -0.00305850f, -0.00571204f, -0.00780638f, -0.00923565f, -0.00994662f, + -0.00993903f, -0.00926212f, -0.00800799f, -0.00630232f, -0.00429337f, -0.00214002f, + -0.00000000f, 0.00198116f, 0.00367946f, 0.00499962f, 0.00587975f, 0.00629327f, + 0.00624819f, 0.00578397f, 0.00496633f, 0.00388057f, 0.00262394f, 0.00129781f, + 0.00000000f, -0.00118189f, -0.00217597f, -0.00292996f, -0.00341330f, -0.00361747f, + -0.00355476f, -0.00325545f, -0.00276400f, -0.00213446f, -0.00142560f, -0.00069606f, + -0.00000000f, 0.00061651f, 0.00111820f, 0.00148212f, 0.00169815f, 0.00176842f, + 0.00170582f, 0.00153178f, 0.00127370f, 0.00096205f, 0.00062756f, 0.00029879f, + -0.00000000f, -0.00025029f, -0.00044009f, -0.00056414f, -0.00062342f, -0.00062426f, + -0.00057701f, -0.00049453f, -0.00039069f, -0.00027889f, -0.00017088f, -0.00007586f, + -0.00000000f, 0.00005374f, 0.00008534f, 0.00009723f, 0.00009358f, 0.00007948f, + 0.00006013f, 0.00004011f, 0.00002289f, 0.00001046f, 0.00000327f, 0.00000042f, + 0.00000000f +}; + +static const float filter_LP15_180H[] = /* Sincfilt.m: N=180*2+1, Fmin=0, Fmax=1/15, hann( N )' */ +{ + 1.00000000f, 0.99262960f, 0.97071645f, 0.93484826f, 0.88598337f, + 0.82541986f, 0.75475374f, 0.67582786f, 0.59067328f, 0.50144522f, + 0.41035570f, 0.31960540f, 0.23131699f, 0.14747211f, 0.06985439f, + 0.00000000f, -0.06084233f, -0.11174093f, -0.15209937f, -0.18166306f, + -0.20051411f, -0.20905505f, -0.20798222f, -0.19825005f, -0.18102779f, + -0.15765038f, -0.12956550f, -0.09827869f, -0.06529875f, -0.03208525f, + -0.00000000f, 0.02973580f, 0.05607741f, 0.07818439f, 0.09543959f, + 0.10745905f, 0.11409270f, 0.11541631f, 0.11171520f, 0.10346089f, + 0.09128169f, 0.07592875f, 0.05823905f, 0.03909687f, 0.01939543f, + 0.00000000f, -0.01828583f, -0.03474981f, -0.04879543f, -0.05996041f, + -0.06792872f, -0.07253607f, -0.07376881f, -0.07175666f, -0.06675991f, + -0.05915169f, -0.04939656f, -0.03802614f, -0.02561328f, -0.01274565f, + -0.00000000f, 0.01208179f, 0.02301411f, 0.03238554f, 0.03987272f, + 0.04524984f, 0.04839345f, 0.04928266f, 0.04799492f, 0.04469779f, + 0.03963720f, 0.03312292f, 0.02551190f, 0.01719053f, 0.00855630f, + 0.00000000f, -0.00811094f, -0.01544730f, -0.02173055f, -0.02674237f, + -0.03033123f, -0.03241557f, -0.03298387f, -0.03209149f, -0.02985488f, + -0.02644325f, -0.02206842f, -0.01697326f, -0.01141932f, -0.00567433f, + -0.00000000f, 0.00535923f, 0.01018613f, 0.01429886f, 0.01755714f, + 0.01986621f, 0.02117865f, 0.02149380f, 0.02085525f, 0.01934645f, + 0.01708469f, 0.01421394f, 0.01089691f, 0.00730662f, 0.00361802f, + 0.00000000f, -0.00339188f, -0.00642164f, -0.00897788f, -0.01097732f, + -0.01236693f, -0.01312444f, -0.01325748f, -0.01280137f, -0.01181573f, + -0.01038024f, -0.00858967f, -0.00654854f, -0.00436567f, -0.00214887f, + -0.00000000f, 0.00198936f, 0.00374143f, 0.00519494f, 0.00630684f, + 0.00705299f, 0.00742798f, 0.00744401f, 0.00712902f, 0.00652419f, + 0.00568101f, 0.00465798f, 0.00351733f, 0.00232168f, 0.00113102f, + 0.00000000f, -0.00102431f, -0.00190408f, -0.00261180f, -0.00313077f, + -0.00345499f, -0.00358855f, -0.00354447f, -0.00334328f, -0.00301127f, + -0.00257862f, -0.00207746f, -0.00154002f, -0.00099694f, -0.00047581f, + -0.00000000f, 0.00041214f, 0.00074776f, 0.00099963f, 0.00116592f, + 0.00124972f, 0.00125829f, 0.00120217f, 0.00109420f, 0.00094845f, + 0.00077928f, 0.00060035f, 0.00042395f, 0.00026030f, 0.00011724f, + 0.00000000f, -0.00008882f, -0.00014902f, -0.00018252f, -0.00019287f, + -0.00018476f, -0.00016347f, -0.00013434f, -0.00010230f, -0.00007148f, + -0.00004496f, -0.00002456f, -0.00001086f, -0.00000332f, -0.00000042f, + -0.00000000f +}; + +static const float filter_LP24_90H[] = +{ + + 0.62500000f, 0.62302684f, 0.61713239f, 0.60739135f, 0.59392688f, + 0.57690853f, 0.55654955f, 0.53310336f, 0.50685949f, 0.47813890f, + 0.44728886f, 0.41467745f, 0.38068777f, 0.34571201f, 0.31014542f, + 0.27438036f, 0.23880054f, 0.20377540f, 0.16965495f, 0.13676502f, + 0.10540301f, 0.07583422f, 0.04828883f, 0.02295955f, 0.00000000f, + -0.02047625f, -0.03839588f, -0.05372532f, -0.06646962f, -0.07667063f, + -0.08440465f, -0.08977957f, -0.09293151f, -0.09402116f, -0.09322978f, + -0.09075508f, -0.08680689f, -0.08160288f, -0.07536433f, -0.06831205f, + -0.06066245f, -0.05262401f, -0.04439397f, -0.03615555f, -0.02807546f, + -0.02030199f, -0.01296350f, -0.00616748f, -0.00000000f, 0.00547430f, + 0.01021181f, 0.01418909f, 0.01740171f, 0.01986272f, 0.02160081f, + 0.02265833f, 0.02308912f, 0.02295617f, 0.02232938f, 0.02128318f, + 0.01989437f, 0.01823991f, 0.01639502f, 0.01443144f, 0.01241584f, + 0.01040857f, 0.00846270f, 0.00662323f, 0.00492667f, 0.00340087f, + 0.00206511f, 0.00093039f, 0.00000000f, -0.00072977f, -0.00126877f, + -0.00163197f, -0.00183843f, -0.00191018f, -0.00187107f, -0.00174574f, + -0.00155856f, -0.00133271f, -0.00108939f, -0.00084707f, -0.00062106f, + -0.00042304f, -0.00026095f, -0.00013888f, -0.00005723f, -0.00001296f, + -0.00000000f, -0.00000000f, -0.00000000f, -0.00000000f, -0.00000000f, + -0.00000000f, + -0.00000000f +}; + + +static const float filter_LP3_90H[] = /* Sincfilt.m: N=90*2+1, Fmin=0, Fmax=1/3, hann( N )' */ +{ + 1.00000000f, 0.82674145f, 0.41299304f, 0.00000000f, -0.20574231f, -0.16414228f, + -0.00000000f, 0.11638725f, 0.10137190f, 0.00000000f, -0.08020564f, -0.07244401f, + -0.00000000f, 0.06039577f, 0.05561375f, 0.00000000f, -0.04776011f, -0.04448829f, + -0.00000000f, 0.03891245f, 0.03651267f, 0.00000000f, -0.03231551f, -0.03046677f, + -0.00000000f, 0.02717149f, 0.02569502f, 0.00000000f, -0.02302575f, -0.02181436f, + -0.00000000f, 0.01960070f, 0.01858630f, 0.00000000f, -0.01671751f, -0.01585488f, + -0.00000000f, 0.01425599f, 0.01351396f, -0.00000000f, -0.01213249f, -0.01148889f, + -0.00000000f, 0.01028699f, 0.00972562f, 0.00000000f, -0.00867534f, -0.00818410f, + -0.00000000f, 0.00726427f, 0.00683387f, -0.00000000f, -0.00602813f, -0.00565135f, + -0.00000000f, 0.00494677f, 0.00461782f, 0.00000000f, -0.00400399f, -0.00371817f, + -0.00000000f, 0.00318651f, 0.00293988f, -0.00000000f, -0.00248317f, -0.00227240f, + -0.00000000f, 0.00188444f, 0.00170665f, 0.00000000f, -0.00138200f, -0.00123460f, + -0.00000000f, 0.00096839f, 0.00084908f, -0.00000000f, -0.00063685f, -0.00054348f, + 0.00000000f, 0.00038113f, 0.00031171f, 0.00000000f, -0.00019534f, -0.00014798f, + -0.00000000f, 0.00007391f, 0.00004679f, -0.00000000f, -0.00001145f, -0.00000283f, + -0.00000000f +}; + +static const float filter_LP15_360H[] = /* Sincfilt.m: N=360*2+1, Fmin=0, Fmax=1/15, hann( N )' */ +{ + 1.00000000f, 0.99268640f, 0.97093867f, 0.93532989f, 0.88679510f, 0.82660196f, 0.75631099f, 0.67772690f, + 0.59284259f, 0.50377777f, 0.41271428f, 0.32183024f, 0.23323527f, 0.14890901f, 0.07064471f, 0.00000000f, + -0.06174384f, -0.11361280f, -0.15496039f, -0.18547676f, -0.20518652f, -0.21443575f, -0.21386869f, -0.20439528f, + -0.18715077f, -0.16344917f, -0.13473211f, -0.10251518f, -0.06833357f, -0.03368904f, -0.00000000f, 0.03144362f, + 0.05951924f, 0.08330302f, 0.10209294f, 0.11542293f, 0.12306791f, 0.12503981f, 0.12157498f, 0.11311391f, + 0.10027413f, 0.08381753f, 0.06461370f, 0.04360066f, 0.02174455f, 0.00000000f, -0.02072746f, -0.03961549f, + -0.05595444f, -0.06917113f, -0.07884629f, -0.08472521f, -0.08672137f, -0.08491313f, -0.07953401f, -0.07095693f, + -0.05967349f, -0.04626915f, -0.03139548f, -0.01574075f, -0.00000000f, 0.01515402f, 0.02909808f, 0.04128258f, + 0.05125197f, 0.05866038f, 0.06328236f, 0.06501815f, 0.06389360f, 0.06005485f, 0.05375815f, 0.04535547f, + 0.03527650f, 0.02400801f, 0.01207150f, 0.00000000f, -0.01168480f, -0.02249426f, -0.03199250f, -0.03981317f, + -0.04567293f, -0.04938087f, -0.05084386f, -0.05006752f, -0.04715306f, -0.04229010f, -0.03574599f, -0.02785210f, + -0.01898788f, -0.00956319f, -0.00000000f, 0.00928603f, 0.01790311f, 0.02549938f, 0.03177686f, 0.03650265f, + 0.03951708f, 0.04073850f, 0.04016462f, 0.03787037f, 0.03400261f, 0.02877179f, 0.02244121f, 0.01531429f, + 0.00772039f, 0.00000000f, -0.00751019f, -0.01449168f, -0.02065736f, -0.02576304f, -0.02961675f, -0.03208568f, + -0.03310029f, -0.03265561f, -0.03080978f, -0.02767986f, -0.02343523f, -0.01828891f, -0.01248723f, -0.00629832f, + -0.00000000f, 0.00613249f, 0.01183829f, 0.01688181f, 0.02106227f, 0.02422142f, 0.02624931f, 0.02708778f, + 0.02673160f, 0.02522739f, 0.02267018f, 0.01919813f, 0.01498536f, 0.01023356f, 0.00516248f, 0.00000000f, + -0.00502795f, -0.00970715f, -0.01384402f, -0.01727353f, -0.01986554f, -0.02152959f, -0.02221779f, -0.02192576f, + -0.02069173f, -0.01859376f, -0.01574532f, -0.01228947f, -0.00839187f, -0.00423301f, -0.00000000f, 0.00412174f, + 0.00795646f, 0.01134547f, 0.01415358f, 0.01627438f, 0.01763405f, 0.01819377f, 0.01795046f, 0.01693597f, + 0.01521482f, 0.01288044f, 0.01005046f, 0.00686086f, 0.00345963f, 0.00000000f, -0.00336638f, -0.00649597f, + -0.00925939f, -0.01154665f, -0.01327141f, -0.01437412f, -0.01482390f, -0.01461907f, -0.01378646f, -0.01237944f, + -0.01047492f, -0.00816931f, -0.00557380f, -0.00280912f, -0.00000000f, 0.00273035f, 0.00526559f, 0.00750113f, + 0.00934836f, 0.01073805f, 0.01162284f, 0.01197870f, 0.01180528f, 0.01112531f, 0.00998290f, 0.00844105f, + 0.00657831f, 0.00448494f, 0.00225863f, -0.00000000f, -0.00219185f, -0.00422367f, -0.00601190f, -0.00748609f, + -0.00859158f, -0.00929139f, -0.00956735f, -0.00942030f, -0.00886950f, -0.00795125f, -0.00671674f, -0.00522941f, + -0.00356175f, -0.00179189f, -0.00000000f, 0.00173531f, 0.00334034f, 0.00474942f, 0.00590751f, 0.00677226f, + 0.00731550f, 0.00752400f, 0.00739958f, 0.00695854f, 0.00623048f, 0.00525657f, 0.00408738f, 0.00278032f, + 0.00139692f, 0.00000000f, -0.00134916f, -0.00259345f, -0.00368229f, -0.00457361f, -0.00523547f, -0.00564706f, + -0.00579926f, -0.00569462f, -0.00534685f, -0.00477983f, -0.00402617f, -0.00312550f, -0.00212248f, -0.00106459f, + -0.00000000f, 0.00102461f, 0.00196604f, 0.00278637f, 0.00345440f, 0.00394682f, 0.00424892f, 0.00435488f, + 0.00426778f, 0.00399900f, 0.00356752f, 0.00299868f, 0.00232288f, 0.00157398f, 0.00078772f, -0.00000000f, + -0.00075466f, -0.00144465f, -0.00204251f, -0.00252601f, -0.00287889f, -0.00309135f, -0.00316023f, -0.00308882f, + -0.00288648f, -0.00256794f, -0.00215242f, -0.00166255f, -0.00112325f, -0.00056046f, -0.00000000f, 0.00053364f, + 0.00101829f, 0.00143502f, 0.00176882f, 0.00200907f, 0.00214985f, 0.00218995f, 0.00213269f, 0.00198558f, + 0.00175975f, 0.00146927f, 0.00113036f, 0.00076058f, 0.00037792f, 0.00000000f, -0.00035672f, -0.00067764f, + -0.00095057f, -0.00116614f, -0.00131812f, -0.00140347f, -0.00142235f, -0.00137791f, -0.00127596f, -0.00112458f, + -0.00093361f, -0.00071406f, -0.00047757f, -0.00023583f, -0.00000000f, 0.00021973f, 0.00041459f, 0.00057751f, + 0.00070338f, 0.00078915f, 0.00083382f, 0.00083835f, 0.00080551f, 0.00073960f, 0.00064615f, 0.00053157f, + 0.00040275f, 0.00026674f, 0.00013039f, -0.00000000f, -0.00011891f, -0.00022183f, -0.00030537f, -0.00036737f, + -0.00040691f, -0.00042423f, -0.00042061f, -0.00039828f, -0.00036014f, -0.00030964f, -0.00025049f, -0.00018648f, + -0.00012124f, -0.00005812f, -0.00000000f, 0.00005082f, 0.00009265f, 0.00012448f, 0.00014596f, 0.00015731f, + 0.00015929f, 0.00015311f, 0.00014024f, 0.00012237f, 0.00010126f, 0.00007860f, 0.00005596f, 0.00003466f, + 0.00001576f, 0.00000000f, -0.00001220f, -0.00002074f, -0.00002578f, -0.00002769f, -0.00002704f, -0.00002448f, + -0.00002068f, -0.00001629f, -0.00001190f, -0.00000794f, -0.00000472f, -0.00000238f, -0.00000092f, -0.00000021f, + -0.00000000f +}; + +const Resampling_cfg resampling_cfg_tbl[] = +{ + /* fin fout up.fact. filter coefs. filter length/2 */ + { 8000, 12800, 8, filter5_39s320_120, 15, RS_INV_FAC }, + { 12800, 8000, 5, filter5_39s320_120, L_FILT_UP8k, RS_INV_FAC }, + { 16000, 8000, 6, filter_LP12_180H, 180/6, 0 }, + { 12800, 16000, 15, filter_LP15_180H, L_FILT_UP16k, 0 }, + { 12800, 32000, 15, filter_LP15_180H, L_FILT_UP32k, 0 }, + { 12800, 48000, 15, filter_LP15_180H, L_FILT_UP48k, 0 }, + + { 16000, 12800, 12, filter_LP15_180H, L_FILT16k, 0 }, + { 16000, 32000, 12, filter_LP12_180H, L_FILT16k, 0 }, + { 16000, 48000, 12, filter_LP12_180H, L_FILT16k, 0 }, + + { 32000, 12800, 6, filter_LP15_180H, L_FILT32k, 0 }, + { 32000, 16000, 6, filter_LP12_180H, L_FILT32k, 0 }, + { 32000, 25600, 12, filter_LP15_360H, L_FILT32k, 0 }, + { 32000, 48000, 3, filter_LP3_90H, L_FILT32k, 0 }, + + { 48000, 12800, 4, filter_LP15_180H, L_FILT48k, 0 }, + { 48000, 16000, 4, filter_LP12_180H, L_FILT48k, 0 }, + { 48000, 25600, 8, filter_LP15_360H, L_FILT48k, 0 }, + { 48000, 32000, 2, filter_LP3_90H, L_FILT48k, 0 }, + + /* configs with NB 4kHz low-pass */ + { 16000, 12800, 12, filter_LP24_90H, L_FILT16k, 0 }, + { 32000, 12800, 6, filter_LP24_90H, L_FILT32k, 0 }, + { 48000, 12800, 4, filter_LP24_90H, L_FILT48k, 0 }, + + { 0, 0, 0, 0, 0, 0 } /* trailing entry (just to calculate the length of this table) */ +}; + +/*----------------------------------------------------------------------------------* + * LSP interpolation coefficients + *----------------------------------------------------------------------------------*/ + +const float interpol_frac_12k8[NB_SUBFR] = { 0.25f, 0.5f, 0.75f, 1.0f }; +const float interpol_isp_amr_wb[NB_SUBFR] = { 0.45f, 0.8f, 0.96f, 1.0f }; +const float interpol_frac_16k[NB_SUBFR16k] = { 0.2f, 0.4f, 0.6f, 0.8f, 1.0f }; + +const float interpol_frac_mid[NB_SUBFR*3] = { 0.5f, 0.5f, 0.0f, + 0.0f, 1.0f, 0.0f, + 0.0f, 0.5f, 0.5f, + 0.0f, 0.0f, 1.0f + }; + +const float interpol_frac_mid_16k[NB_SUBFR16k*3] = { 0.55f, 0.45f, 0.0f, + 0.15f, 0.85f, 0.0f, + 0.0f, 0.75f, 0.25f, + 0.0f, 0.35f, 0.65f, + 0.0f, 0.0f, 1.0f + }; + +const float interpol_frac_mid_relaxprev_12k8[NB_SUBFR*3] = { 0.0f, 0.7f, 0.3f, + 0.0f, 0.0f, 1.0f, + 0.0f, 0.0f, 1.0f, + 0.0f, 0.0f, 1.0f + }; + +const float interpol_frac_mid_FEC[NB_SUBFR*3] = { 0.25f, 0.55f, 0.20f, + 0.00f, 0.70f, 0.30f, + 0.00f, 0.45f, 0.55f, + 0.00f, 0.00f, 1.00f + }; + +const float interpol_frac_mid_relaxprev_pred_12k8[NB_SUBFR*3] = { 0.15f, 0.70f, 0.15f, + 0.05f, 0.65f, 0.30f, + 0.00f, 0.50f, 0.50f, + 0.00f, 0.0f, 1.00f + }; + +const float interpol_frac_mid_relaxprev_16k[NB_SUBFR16k*3] = { 0.0f, 0.7f, 0.3f, + 0.0f, 0.0f, 1.0f, + 0.0f, 0.0f, 1.0f, + 0.0f, 0.0f, 1.0f, + 0.0f, 0.0f, 1.0f + }; + +const float interpol_frac_mid_16k_FEC[NB_SUBFR16k*3] = { 0.4f, 0.40f, 0.2f, + 0.0f, 0.80f, 0.20f, + 0.0f, 0.65f, 0.35f, + 0.0f, 0.15f, 0.85f, + 0.0f, 0.00f, 1.00f + }; + +const float interpol_frac_mid_relaxprev_pred_16k[NB_SUBFR16k*3] = { 0.15f, 0.70f, 0.15f, + 0.05f, 0.65f, 0.30f, + 0.00f, 0.50f, 0.50f, + 0.00f, 0.15f, 0.85f, + 0.00f, 0.0f, 1.00f + }; + +/*----------------------------------------------------------------------------------* + * Innovative codebook + *----------------------------------------------------------------------------------*/ + +/* Innovative codebook config */ +const PulseConfig PulseConfTable[] = +{ + /* Design rules: + * ---> "fixed" + "tried-pair-pos"*2 = pulses & 0xfe + * ---> tracks with pulses % 3 == 0, have always TRACKPOS_FIXED_FIRST */ + /* bits,iter,alp,pulses,fixed,tried-pair-pos,codetrack */ + { 7, 4, 2.0f, 1, 0, {8}, TRACKPOS_FREE_ONE }, /* 7 bits, 1 pulses, 4 tracks, 1000 free track */ + { 10, 4, 2.0f, 2, 0, {8}, TRACKPOS_FIXED_EVEN }, /* 10 bits, 2 pulses, 4 tracks 1010 (used only even tracks designed for NB) */ + { 12, 4, 2.0f, 2, 0, {8}, TRACKPOS_FIXED_TWO }, /* 12 bits, 2 pulses, 2 tracks 11 used all tracks ala AMR-WB 6.6 */ + { 15, 4, 2.0f, 3, 0, {8}, TRACKPOS_FIXED_FIRST }, /* 15 bits, 3 pulses, 4 tracks 1110 fixed track to first ? */ + { 17, 6, 2.0f, 3, 0, {8}, TRACKPOS_FREE_THREE }, /* 17 bits, 3 pulses, 4 tracks (used all tracks) - 1110, 1101, 1011, 0111 */ + { 20, 4, 2.0f, 4, 0, {4, 8}, TRACKPOS_FIXED_FIRST }, /* 20 bits, 4 pulses, 4 tracks 1111 */ + { 24, 4, 2.0f, 5, 0, {4, 8}, TRACKPOS_FIXED_FIRST }, /* 24 bits, 5 pulses, 4 tracks 2111 fixed track to first */ + { 26, 4, 2.0f, 5, 0, {4, 8}, TRACKPOS_FREE_ONE }, /* 26 bits, 5 pulses, 4 tracks 2111 one free track ? */ + { 28, 4, 1.5f, 6, 0, {4, 8, 8}, TRACKPOS_FIXED_FIRST }, /* 28 bits, 6 pulses, 4 tracks 2211 */ + { 30, 4, 1.5f, 6, 0, {4, 8, 8}, TRACKPOS_FIXED_TWO }, /* 30 bits, 6 pulses, 4 tracks 2211 free consecutive track positions ? */ + { 32, 4, 1.5f, 7, 0, {4, 8, 8}, TRACKPOS_FIXED_FIRST }, /* 32 bits, 6 pulses, 4 tracks 2221 fixed ?*/ + { 34, 4, 1.5f, 7, 0, {4, 8, 8}, TRACKPOS_FREE_THREE }, /* 34 bits, 6 pulses, 4 tracks 2221 free track positions ? */ + { 36, 4, 1.0f, 8, 2, {4, 8, 8}, TRACKPOS_FIXED_FIRST }, /* 36 bits, 8 pulses, 4 tracks 2222 */ + { 40, 4, 1.0f, 9, 2, {4, 8, 8}, TRACKPOS_FIXED_FIRST }, /* 40 bits, 9 pulses, 4 tracks 3222 fixed ?*/ + { 43, 4, 1.0f, 10, 2, {4, 6, 8, 8}, TRACKPOS_FIXED_FIRST }, /* 44 bits, 10 pulses, 4 tracks 3322 */ + { 46, 4, 1.0f, 10, 2, {4, 6, 8, 8}, TRACKPOS_FIXED_TWO }, /* 46 bits, 10 pulses, 4 tracks 3322 free consecutive tracks ? */ + { 47, 4, 1.0f, 11, 2, {4, 6, 8, 8}, TRACKPOS_FIXED_FIRST }, /* 47 bits, 10 pulses, 4 tracks 3332 fixed ? */ + { 49, 4, 1.0f, 11, 2, {4, 6, 8, 8}, TRACKPOS_FREE_THREE }, /* 49 bits, 10 pulses, 4 tracks 3332 free three track positions ? */ + { 50, 4, 1.0f, 12, 4, {4, 6, 8, 8}, TRACKPOS_FIXED_FIRST }, /* 50 bits, 12 pulses, 4 tracks 3333 */ + { 53, 4, 1.0f, 13, 4, {4, 6, 8, 8}, TRACKPOS_FIXED_FIRST }, /* 53 bits, 13 pulses, 4 tracks 4333 fixed ? */ + { 55, 4, 1.0f, 13, 4, {4, 6, 8, 8}, TRACKPOS_FREE_ONE }, /* 55 bits, 13 pulses, 4 tracks 4333 free one ? */ + { 56, 4, 1.0f, 14, 4, {4, 6, 6, 8, 8}, TRACKPOS_FIXED_FIRST }, /* 56 bits, 14 pulses, 4 tracks 4433 fixed ?!?! */ + { 58, 4, 1.0f, 14, 4, {4, 6, 6, 8, 8}, TRACKPOS_FIXED_TWO }, /* 58 bits, 14 pulses, 4 tracks 4433 free consecutive ? */ + { 59, 4, 1.0f, 15, 4, {4, 6, 6, 8, 8}, TRACKPOS_FIXED_FIRST }, /* 59 bits, 15 pulses, 4 tracks 4443 fixed ? */ + { 61, 4, 1.0f, 15, 4, {4, 6, 6, 8, 8}, TRACKPOS_FREE_THREE }, /* 61 bits, 15 pulses, 4 tracks 4443 free ? */ + { 62, 3, 0.8f, 16, 4, {4, 4, 6, 6, 8, 8}, TRACKPOS_FIXED_FIRST }, /* 62 bits, 16 pulses, 4 tracks 4444 */ + { 65, 3, 0.8f, 17, 4, {4, 4, 6, 6, 8, 8}, TRACKPOS_FIXED_FIRST }, /* 65 bits, 17 pulses, 4 tracks 5444 fixed ?*/ + { 68, 3, 0.75f, 18, 4, {2, 3, 4, 5, 6, 7, 8}, TRACKPOS_FIXED_FIRST }, /* 68 bits, 18 pulses, 4 tracks 5544 */ + { 70, 3, 0.75f, 19, 4, {2, 3, 4, 5, 6, 7, 8}, TRACKPOS_FIXED_FIRST }, /* 70 bits, 19 pulses, 4 tracks 5554 fixed ? */ + { 73, 3, 0.75f, 20, 4, {2, 3, 4, 5, 6, 7, 8, 8}, TRACKPOS_FIXED_FIRST }, /* 73 bits, 20 pulses, 4 tracks 5555 fixed ? */ + { 75, 3, 0.75f, 21, 4, {2, 3, 4, 5, 6, 7, 8, 8}, TRACKPOS_FIXED_FIRST }, /* 75 bits, 21 pulses, 4 tracks 6555 fixed ? */ + { 78, 3, 0.75f, 22, 4, {2, 3, 4, 5, 6, 7, 8, 8, 8}, TRACKPOS_FIXED_FIRST }, /* 78 bits, 22 pulses, 4 tracks 6655 fixed ? */ + { 80, 3, 0.75f, 23, 4, {2, 3, 4, 5, 6, 7, 8, 8, 8}, TRACKPOS_FIXED_FIRST }, /* 80 bits, 23 pulses, 4 tracks 6665 fixed ? */ + { 83, 2, 0.30f, 24, 4, {2, 3, 4, 5, 6, 7, 8, 8, 8, 8}, TRACKPOS_FIXED_FIRST}, /* 83 bits, 24 pulses, 4 tracks 6666 */ + { 85, 2, 0.30f, 25, 4, {2, 3, 4, 5, 6, 7, 8, 8, 8, 8}, TRACKPOS_FIXED_FIRST}, /* 85 bits, 25 pulses, 4 tracks 7666 */ + { 87, 2, 0.25f, 26, 4, {2, 3, 4, 5, 6, 7, 8, 8, 8, 8, 8}, TRACKPOS_FIXED_FIRST}, /* 87 bits, 26 pulses, 4 tracks 7766 */ + { 89, 2, 0.25f, 27, 4, {2, 3, 4, 5, 6, 7, 8, 8, 8, 8, 8}, TRACKPOS_FIXED_FIRST}, /* 89 bits, 27 pulses, 4 tracks 7776 */ + { 92, 2, 0.25f, 28, 4, {2, 3, 4, 5, 6, 7, 8, 8, 8, 8, 8, 8}, TRACKPOS_FIXED_FIRST}, /* 92 bits, 28 pulses, 4 tracks 7777 */ + { 94, 2, 0.25f, 29, 4, {2, 3, 4, 5, 6, 7, 8, 8, 8, 8, 8, 8}, TRACKPOS_FIXED_FIRST}, /* 94 bits, 29 pulses, 4 tracks 8777 */ + { 96, 1, 0.20f, 30, 4, {2, 3, 4, 5, 6, 7, 8, 8, 8, 8, 8, 8, 8}, TRACKPOS_FIXED_FIRST}, /* 96 bits, 30 pulses, 4 tracks 8877 */ + { 98, 1, 0.20f, 31, 4, {2, 3, 4, 5, 6, 7, 8, 8, 8, 8, 8, 8, 8}, TRACKPOS_FIXED_FIRST}, /* 98 bits, 31 pulses, 4 tracks 8887 */ +}; + + +/* Number of pulses & positions to the number of unique states that can be achieved with those pulses */ +const long unsigned pulsestostates[17][9] = +{ + { 0, 0, 0, 0, 0, 0, 0, 0, 0}, + { 2, 2, 2, 2, 2, 2, 2, 2, 2}, + { 4, 8, 12, 16, 20, 24, 28, 32, 36}, + { 6, 18, 38, 66, 102, 146, 198, 258, 326}, + { 8, 32, 88, 192, 360, 608, 952, 1408, 1992}, + { 10, 50, 170, 450, 1002, 1970, 3530, 5890, 9290}, + { 12, 72, 292, 912, 2364, 5336, 10836, 20256, 35436}, + { 14, 98, 462, 1666, 4942, 12642, 28814, 59906, 115598}, + { 16, 128, 688, 2816, 9424, 27008, 68464, 157184, 332688}, + { 18, 162, 978, 4482, 16722, 53154, 148626, 374274, 864146}, + { 20, 200, 1340, 6800, 28004, 97880, 299660, 822560, 2060980}, + { 22, 242, 1782, 9922, 44726, 170610, 568150, 1690370, 4573910}, + { 24, 288, 2312, 14016, 68664, 284000, 1022760, 3281280, 9545560}, + { 26, 338, 2938, 19266, 101946, 454610, 1761370, 6065410, 18892250}, + { 28, 392, 3668, 25872, 147084, 703640, 2919620, 10746400, 35704060}, + { 30, 450, 4510, 34050, 207006, 1057730, 4680990, 18347010, 64797470}, + { 32, 512, 5472, 44032, 285088, 1549824, 7288544, 30316544, 113461024}, +}; + +/*----------------------------------------------------------------------------------* + * Gain quantization table for memory-less gain quantizer + *----------------------------------------------------------------------------------*/ + +const float gain_qua_mless_7b[128*2] = +{ + 0.0256f, 0.0555f, + 0.0915f, 1.1847f, + 0.0968f, 0.6282f, + 0.0996f, 0.2821f, + 0.1029f, 0.4465f, + 0.1065f, 0.9677f, + 0.1332f, 0.7997f, + 0.1535f, 1.3985f, + 0.1692f, 1.6101f, + 0.1873f, 2.0886f, + 0.1960f, 1.8291f, + 0.1964f, 0.1732f, + 0.2122f, 2.4304f, + 0.2292f, 0.5306f, + 0.2359f, 1.0716f, + 0.2369f, 0.6796f, + 0.2546f, 0.3544f, + 0.2694f, 1.2247f, + 0.2697f, 0.9217f, + 0.2996f, 2.7903f, + 0.3197f, 0.7881f, + 0.3199f, 3.2249f, + 0.3492f, 0.1667f, + 0.3560f, 0.4883f, + 0.3568f, 1.3541f, + 0.3599f, 0.6346f, + 0.3684f, 1.0620f, + 0.3716f, 1.5223f, + 0.3942f, 3.6890f, + 0.4059f, 0.3064f, + 0.4076f, 0.9021f, + 0.4149f, 1.7170f, + 0.4225f, 1.9400f, + 0.4229f, 2.2074f, + 0.4487f, 1.2106f, + 0.4554f, 0.7548f, + 0.4800f, 0.4531f, + 0.4882f, 0.6140f, + 0.4966f, 1.0464f, + 0.5126f, 1.3905f, + 0.5298f, 0.8967f, + 0.5369f, 2.4926f, + 0.5521f, 1.5735f, + 0.5614f, 0.1682f, + 0.5758f, 0.7770f, + 0.5939f, 1.1468f, + 0.5942f, 0.5222f, + 0.5946f, 0.3409f, + 0.6053f, 1.7908f, + 0.6129f, 0.9937f, + 0.6136f, 1.2784f, + 0.6184f, 2.0111f, + 0.6249f, 0.6626f, + 0.6527f, 3.0463f, + 0.6602f, 0.8724f, + 0.6692f, 1.4121f, + 0.6961f, 2.2440f, + 0.7035f, 1.0724f, + 0.7069f, 0.7548f, + 0.7081f, 1.5445f, + 0.7091f, 0.5579f, + 0.7253f, 1.6832f, + 0.7296f, 1.1850f, + 0.7359f, 0.4175f, + 0.7388f, 0.9680f, + 0.7428f, 2.7283f, + 0.7591f, 1.3040f, + 0.7700f, 0.6550f, + 0.7732f, 1.8595f, + 0.7742f, 0.8500f, + 0.7924f, 0.2178f, + 0.8078f, 1.4486f, + 0.8178f, 1.0725f, + 0.8255f, 0.7421f, + 0.8256f, 0.5278f, + 0.8316f, 2.0390f, + 0.8382f, 0.9422f, + 0.8435f, 1.2053f, + 0.8567f, 1.5952f, + 0.8570f, 2.4549f, + 0.8725f, 0.8299f, + 0.8756f, 1.3365f, + 0.8769f, 0.6222f, + 0.8799f, 0.3881f, + 0.8938f, 1.7540f, + 0.9121f, 1.0122f, + 0.9210f, 0.7117f, + 0.9249f, 1.1285f, + 0.9344f, 0.9022f, + 0.9375f, 3.7762f, + 0.9376f, 1.4769f, + 0.9388f, 0.5124f, + 0.9501f, 2.2014f, + 0.9582f, 1.2478f, + 0.9646f, 0.8003f, + 0.9815f, 0.6165f, + 0.9864f, 1.9390f, + 0.9985f, 1.3694f, + 1.0041f, 1.6163f, + 1.0071f, 1.0599f, + 1.0095f, 0.9596f, + 1.0142f, 3.3774f, + 1.0150f, 0.3827f, + 1.0223f, 0.7201f, + 1.0351f, 2.9891f, + 1.0393f, 0.8629f, + 1.0461f, 1.1773f, + 1.0601f, 1.7548f, + 1.0616f, 0.5225f, + 1.0969f, 1.4899f, + 1.0977f, 2.6574f, + 1.0996f, 0.6500f, + 1.1006f, 1.3029f, + 1.1129f, 0.7923f, + 1.1151f, 0.2047f, + 1.1169f, 1.0829f, + 1.1195f, 0.9526f, + 1.1442f, 2.3570f, + 1.1613f, 2.0960f, + 1.1920f, 0.4212f, + 1.1942f, 1.8806f, + 1.2055f, 1.6309f, + 1.2081f, 1.2005f, + 1.2091f, 0.5825f, + 1.2200f, 1.3871f, + 1.2201f, 0.8762f, + 1.2210f, 0.7314f, + 1.2298f, 1.0376f +}; + +const float gain_qua_mless_6b[64*2] = +{ + 0.1023f, 0.1385f, + 0.1299f, 0.3865f, + 0.1415f, 0.9587f, + 0.1433f, 0.6630f, + 0.1708f, 1.2210f, + 0.1766f, 1.5334f, + 0.2387f, 2.1457f, + 0.2917f, 0.4762f, + 0.2918f, 0.8337f, + 0.3122f, 1.8254f, + 0.3231f, 2.9468f, + 0.3520f, 0.2219f, + 0.3673f, 1.0612f, + 0.3755f, 0.6540f, + 0.3787f, 1.3191f, + 0.3805f, 3.5578f, + 0.4114f, 2.4443f, + 0.4293f, 1.5662f, + 0.4750f, 0.8475f, + 0.4886f, 0.4489f, + 0.5635f, 1.2143f, + 0.5699f, 0.6556f, + 0.5730f, 1.0155f, + 0.5963f, 2.0279f, + 0.6021f, 1.4337f, + 0.6240f, 1.7159f, + 0.6480f, 0.2310f, + 0.6577f, 0.8326f, + 0.7030f, 0.4858f, + 0.7146f, 2.7331f, + 0.7351f, 1.1471f, + 0.7489f, 0.9787f, + 0.7493f, 0.6800f, + 0.7628f, 1.3365f, + 0.7947f, 1.5351f, + 0.7994f, 2.3357f, + 0.8258f, 0.8233f, + 0.8434f, 1.7918f, + 0.8620f, 0.5667f, + 0.8850f, 2.0286f, + 0.8873f, 1.2422f, + 0.8933f, 1.0855f, + 0.8952f, 0.9457f, + 0.9113f, 0.7066f, + 0.9189f, 0.4096f, + 0.9554f, 3.1133f, + 0.9662f, 3.6596f, + 0.9685f, 1.4001f, + 0.9703f, 1.6178f, + 0.9859f, 0.8469f, + 1.0095f, 0.5734f, + 1.0299f, 1.1866f, + 1.0337f, 1.0014f, + 1.0487f, 0.7284f, + 1.0769f, 2.6107f, + 1.0801f, 0.2455f, + 1.1195f, 2.1906f, + 1.1268f, 1.8445f, + 1.1591f, 0.4730f, + 1.1666f, 1.5523f, + 1.1711f, 1.3167f, + 1.1753f, 0.8763f, + 1.1893f, 1.0872f, + 1.1911f, 0.6722f +}; + +const float gain_qua_mless_5b[32*2] = +{ + 0.1645f, 0.2137f, + 0.2102f, 0.5295f, + 0.2154f, 0.8448f, + 0.2615f, 1.5636f, + 0.2664f, 1.1856f, + 0.3012f, 2.1266f, + 0.4209f, 2.7473f, + 0.4713f, 0.6328f, + 0.4830f, 0.2861f, + 0.4938f, 0.9146f, + 0.5523f, 1.7829f, + 0.5798f, 1.1716f, + 0.6039f, 1.4473f, + 0.6068f, 3.5936f, + 0.7267f, 0.7460f, + 0.7329f, 2.1548f, + 0.7537f, 0.4738f, + 0.7586f, 0.9788f, + 0.8354f, 1.2308f, + 0.8529f, 1.7499f, + 0.8856f, 1.4611f, + 0.9253f, 0.6280f, + 0.9414f, 0.8362f, + 0.9570f, 1.0559f, + 0.9663f, 3.0746f, + 0.9765f, 2.5027f, + 1.0512f, 0.4129f, + 1.0815f, 2.0090f, + 1.1099f, 1.2670f, + 1.1250f, 1.5985f, + 1.1376f, 0.6895f, + 1.1529f, 0.9632f +}; + +const short E_ROM_qua_gain5b_const[NB_QUA_GAIN5B * 2]= +{ + 1774,577, + 2090,1805, + 2103,3371, + 3908,1116, + 4834,2500, + 6030,4763, + 6838,1334, + 7490,2033, + 8585,3036, + 9845,1575, + 10437,2320, + 10649,3739, + 11298,945, + 12108,1920, + 12310,5108, + 12391,2758, + 12659,1237, + 13729,1557, + 13798,2201, + 13972,3275, + 14881,993, + 15175,1776, + 15409,16190, + 15551,2395, + 15879,4048, + 16341,1335, + 16988,2918, + 18317,7449, + 18368,2026, + 19114,1364, + 19991,4472, + 20644,2790, +}; + +const Word16 E_ROM_qua_gain6b_const[NB_QUA_GAIN6B * 2] = +{ + 0,2758, + 143,3562, + 397,2146, + 544,4306, + 952,1726, + 1236,724, + 1779,3158, + 1820,5448, + 1975,2473, + 2121,1343, + 3049,3912, + 3081,1885, + 3289,8261, + 3416,2843, + 3495,2204, + 3831,3386, + 4295,4590, + 4300,2476, + 4345,1545, + 4913,1122, + 5198,2080, + 5200,3079, + 5448,3714, + 5482,2689, + 5546,1817, + 5783,17318, + 5934,6236, + 6156,2320, + 6481,4225, + 6828,3351, + 6832,5045, + 6888,2895, + 7186,2559, + 7214,1663, + 7373,2052, + 7906,3819, + 8192,1372, + 8452,3063, + 8464,2354, + 9021,4468, + 9037,2715, + 9175,1874, + 9219,3463, + 9831,2155, + 10523,5383, + 10557,9061, + 10618,3093, + 10633,3949, + 10890,2465, + 11141,1654, + 12132,2790, + 12180,3477, + 12376,2079, + 12494,4560, + 14430,2468, + 14573,3914, + 14576,3111, + 15043,1827, + 15207,1329, + 16073,6155, + 17519,4719, + 18345,2148, + 18554,2784, + 18576,3563, +}; + +const short E_ROM_qua_gain7b_const[NB_QUA_GAIN7B * 2] = +{ + 123,2777, + 369,2102, + 404,4368, + 693,3486, + 1107,719, + 1222,1679, + 1657,1293, + 1667,5547, + 1805,2425, + 2369,3075, + 2489,12063, + 2681,1901, + 2693,3984, + 3031,7547, + 3248,990, + 3466,2672, + 3674,2165, + 3718,1513, + 3844,3456, + 4120,4656, + 4748,2967, + 4821,19622, + 4855,2400, + 4912,1776, + 5245,3860, + 5312,6282, + 5500,1176, + 5713,2056, + 5872,3287, + 5960,2662, + 6170,9756, + 6364,5021, + 6545,1476, + 6788,2283, + 6796,4163, + 7038,2949, + 7216,1831, + 7274,3516, + 7707,2510, + 8123,5762, + 8361,4485, + 8376,2110, + 8594,3135, + 8611,3755, + 8634,1570, + 8636,2748, + 8683,8222, + 9274,335, + 9512,2404, + 9640,5020, + 9690,1893, + 9778,3361, + 9808,15435, + 9936,4029, + 10194,2767, + 10306,6510, + 10325,1252, + 10686,2186, + 10844,32767, + 10913,4453, + 10968,3078, + 11044,1666, + 11076,3609, + 11398,2509, + 11423,5160, + 11848,1994, + 11997,2823, + 12002,3880, + 12084,7573, + 12129,3325, + 12214,5867, + 12331,1496, + 12450,4245, + 12458,2283, + 12768,901, + 12896,4741, + 12898,1811, + 12902,2569, + 12983,2959, + 13173,3331, + 13413,2059, + 13416,3734, + 13429,10641, + 13448,1148, + 13615,5340, + 13674,1425, + 13779,2332, + 13847,4264, + 13909,2657, + 13958,6488, + 14047,3085, + 14130,1648, + 14547,1915, + 14554,3684, + 14749,2739, + 14868,5017, + 14875,2216, + 14898,3197, + 14988,1085, + 15026,4246, + 15375,7971, + 15421,1446, + 15548,2462, + 15722,5920, + 15882,3449, + 15960,1782, + 15994,2863, + 16365,3977, + 16419,4754, + 16472,2162, + 17378,3101, + 17410,2550, + 17743,1339, + 17856,5485, + 17979,1982, + 17996,3628, + 18041,7110, + 18242,4381, + 18602,22207, + 19373,12827, + 19533,2777, + 19640,1678, + 19728,2272, + 19795,8861, + 20065,3275, + 20133,4881, + 20198,3947, + 20290,6128, +}; + +/*----------------------------------------------------------------------------------* + * MA predicition coefficients for gain quantizer + *----------------------------------------------------------------------------------*/ + +const float pred_gain[GAIN_PRED_ORDER] = { 0.5f, 0.4f, 0.3f, 0.2f }; + +/*----------------------------------------------------------------------------------* + * 6-bit gain quantization table (only for AMR-WB IO mode) + *----------------------------------------------------------------------------------*/ + +const float t_qua_gain6b[64*2] = +{ + 0.095577f, 0.650507f, + 0.096232f, 1.737050f, + 0.187418f, 3.168846f, + 0.255896f, 4.962348f, + 0.274392f, 1.237365f, + 0.306340f, 2.191559f, + 0.340913f, 7.624112f, + 0.349443f, 0.694540f, + 0.393850f, 0.283414f, + 0.410411f, 3.335519f, + 0.467326f, 1.722400f, + 0.492699f, 1.024880f, + 0.502447f, 2.596945f, + 0.538748f, 4.284797f, + 0.594507f, 1.400231f, + 0.601562f, 0.715119f, + 0.615667f, 6.097708f, + 0.625075f, 2.174328f, + 0.662782f, 3.231284f, + 0.690967f, 1.751661f, + 0.696845f, 0.878992f, + 0.710639f, 1.185743f, + 0.715220f, 0.482280f, + 0.751490f, 2.486668f, + 0.764345f, 4.108078f, + 0.767472f, 12.8f, /*0.767472f, 13.875360f,*/ + 0.769099f, 1.658386f, + 0.803928f, 0.792686f, + 0.810832f, 1.183175f, + 0.818967f, 2.972155f, + 0.821480f, 6.255056f, + 0.833469f, 1.761157f, + 0.861276f, 2.207579f, + 0.863275f, 0.599961f, + 0.880429f, 0.913681f, + 0.880816f, 3.532393f, + 0.881643f, 1.383632f, + 0.892825f, 4.900598f, + 0.906974f, 8.542764f, + 0.925368f, 1.772085f, + 0.928281f, 2.841080f, + 0.933752f, 1.101603f, + 0.947124f, 2.305683f, + 0.956012f, 0.517399f, + 0.961870f, 3.892433f, + 0.972823f, 5.841643f, + 0.977796f, 1.463091f, + 0.981803f, 0.833284f, + 1.008362f, 2.077002f, + 1.011696f, 3.039251f, + 1.031157f, 1.162086f, + 1.031888f, 0.332692f, + 1.050599f, 4.104371f, + 1.074819f, 1.668828f, + 1.092217f, 2.572842f, + 1.108887f, 5.736302f, + 1.112667f, 0.769072f, + 1.135654f, 15.9999f, /*1.135654f, 28.065996f,*/ + 1.143096f, 10.587959f, + 1.168006f, 1.241697f, + 1.185414f, 3.211269f, + 1.186919f, 2.000422f, + 1.187154f, 4.421983f, + 1.243327f, 7.268204f +}; + +/*----------------------------------------------------------------------------------* + * 7-bit gain quantization table (only for AMR-WB IO mode) + *----------------------------------------------------------------------------------*/ + +const float t_qua_gain7b[128*2] = +{ + 0.012445f, 0.215546f, + 0.028326f, 0.965442f, + 0.053042f, 0.525819f, + 0.065409f, 1.495322f, + 0.078212f, 2.323725f, + 0.100504f, 0.751276f, + 0.112617f, 3.427530f, + 0.113124f, 0.309583f, + 0.121763f, 1.140685f, + 0.143515f, 7.519609f, + 0.162430f, 0.568752f, + 0.164940f, 1.904113f, + 0.165429f, 4.947562f, + 0.194985f, 0.855463f, + 0.213527f, 1.281019f, + 0.223544f, 0.414672f, + 0.243135f, 2.781766f, + 0.257180f, 1.659565f, + 0.269488f, 0.636749f, + 0.286539f, 1.003938f, + 0.328124f, 2.225436f, + 0.328761f, 0.330278f, + 0.336807f, 11.500983f, + 0.339794f, 3.805726f, + 0.344454f, 1.494626f, + 0.346165f, 0.738748f, + 0.363605f, 1.141454f, + 0.398729f, 0.517614f, + 0.415276f, 2.928666f, + 0.416282f, 0.862935f, + 0.423421f, 1.873310f, + 0.444151f, 0.202244f, + 0.445842f, 1.301113f, + 0.455671f, 5.519512f, + 0.484764f, 0.387607f, + 0.488696f, 0.967884f, + 0.488730f, 0.666771f, + 0.508189f, 1.516224f, + 0.508792f, 2.348662f, + 0.531504f, 3.883870f, + 0.548649f, 1.112861f, + 0.551182f, 0.514986f, + 0.564397f, 1.742030f, + 0.566598f, 0.796454f, + 0.589255f, 3.081743f, + 0.598816f, 1.271936f, + 0.617654f, 0.333501f, + 0.619073f, 2.040522f, + 0.625282f, 0.950244f, + 0.630798f, 0.594883f, + 0.638918f, 4.863197f, + 0.650102f, 1.464846f, + 0.668412f, 0.747138f, + 0.669490f, 2.583027f, + 0.683757f, 1.125479f, + 0.691216f, 1.739274f, + 0.718441f, 3.297789f, + 0.722608f, 0.902743f, + 0.728827f, 2.194941f, + 0.729586f, 0.633849f, + 0.730907f, 7.432957f, + 0.731017f, 0.431076f, + 0.731543f, 1.387847f, + 0.759183f, 1.045210f, + 0.768606f, 1.789648f, + 0.771245f, 4.085637f, + 0.772613f, 0.778145f, + 0.786483f, 1.283204f, + 0.792467f, 2.412891f, + 0.802393f, 0.544588f, + 0.807156f, 0.255978f, + 0.814280f, 1.544409f, + 0.817839f, 0.938798f, + 0.826959f, 2.910633f, + 0.830453f, 0.684066f, + 0.833431f, 1.171532f, + 0.841208f, 1.908628f, + 0.846440f, 5.333522f, + 0.868280f, 0.841519f, + 0.868662f, 1.435230f, + 0.871449f, 3.675784f, + 0.881317f, 2.245058f, + 0.882020f, 0.480249f, + 0.882476f, 1.105804f, + 0.902856f, 0.684850f, + 0.904419f, 1.682113f, + 0.909384f, 2.787801f, + 0.916558f, 7.500981f, + 0.918444f, 0.950341f, + 0.919721f, 1.296319f, + 0.940272f, 4.682978f, + 0.940273f, 1.991736f, + 0.950291f, 3.507281f, + 0.957455f, 1.116284f, + 0.957723f, 0.793034f, + 0.958217f, 1.497824f, + 0.962628f, 2.514156f, + 0.968507f, 0.588605f, + 0.974739f, 0.339933f, + 0.991738f, 1.750201f, + 0.997210f, 0.936131f, + 1.002422f, 1.250008f, + 1.006040f, 2.167232f, + 1.008848f, 3.129940f, + 1.014404f, 5.842819f, + 1.027798f, 4.287319f, + 1.039404f, 1.489295f, + 1.039628f, 8.947958f, + 1.043214f, 0.765733f, + 1.045089f, 2.537806f, + 1.058994f, 1.031496f, + 1.060415f, 0.478612f, + 1.072132f, 12.8f, /*1.072132f, 14.961459f,*/ + 1.074778f, 1.910049f, + 1.076570f, 15.9999f, /*1.076570f, 30.500374f,*/ + 1.107853f, 3.843067f, + 1.110673f, 1.228576f, + 1.110969f, 2.758471f, + 1.140058f, 1.603077f, + 1.155384f, 0.668935f, + 1.176229f, 6.717108f, + 1.179008f, 2.011940f, + 1.187735f, 0.963552f, + 1.199569f, 4.891432f, + 1.206311f, 3.316329f, + 1.215323f, 2.507536f, + 1.223150f, 1.387102f, + 1.296012f, 9.684225f +}; + +/*----------------------------------------------------------------------------------* + * Quantization table for scaled innovation energy prediciton + *----------------------------------------------------------------------------------*/ + +const float Es_pred_qua_5b[32] = +{ + -8.0000f, + -2.0519f, + 2.5095f, + 6.5923f, + 9.9507f, + 12.9923f, + 15.7251f, + 18.1521f, + 20.3552f, + 22.4218f, + 24.3014f, + 26.0214f, + 27.6040f, + 29.0898f, + 30.5291f, + 31.9154f, + 33.2749f, + 34.6277f, + 35.9525f, + 37.3081f, + 38.7173f, + 40.1734f, + 41.6751f, + 43.2697f, + 44.9559f, + 46.7826f, + 48.7749f, + 50.9729f, + 53.4967f, + 56.3814f, + 59.9748f, + 65.0000f +}; + + +const float Es_pred_qua_4b[16] = +{ + -8.0000f, + -0.1400f, + 7.1397f, + 12.8276f, + 17.9064f, + 22.4280f, + 26.6441f, + 30.6032f, + 34.2916f, + 37.8937f, + 41.4441f, + 45.0174f, + 48.7769f, + 52.9669f, + 58.0552f, + 65.0000f +}; + +const float Es_pred_qua_3b[8] = +{ + 5.9422f, + 15.2711f, + 23.3857f, + 30.5310f, + 37.0190f, + 43.4539f, + 50.2442f, + 58.7164f +}; + +const float Es_pred_qua_4b_no_ltp[16] = +{ + -5.f, + 0.f, + 5.f, + 10.f, + 15.f, + 20.f, + 25.f, + 30.f, + 35.f, + 40.f, + 45.f, + 50.f, + 55.f, + 60.f, + 65.f, + 70.f +}; + +/*----------------------------------------------------------------------------------* + * Gain estimation constants (for gain quantizer at 7.2 and 8.0 kbps) + *----------------------------------------------------------------------------------*/ + +const float b_1sfr[2] = +{ + 2.36736f, -0.22452f +}; + +const float b_2sfr[4] = +{ + -0.00027f, 0.01703f, 0.91879f, 0.13234f +}; + +const float b_3sfr[6] = +{ + -0.11658f, 0.02674f, 0.13513f, 0.79682f, 0.02241f, 0.17815f +}; + +const float b_4sfr[8] = +{ + -0.09296f, 0.01578f, -0.06606f, 0.20416f, 0.79254f, 0.00829f, 0.03499f, 0.15859f +}; + + +/*----------------------------------------------------------------------------------* + * Gain codebooks (for gain quantizer at 7.2 and 8.0 kbps) + *----------------------------------------------------------------------------------*/ + +const float gp_gamma_1sfr_8b[2*256] = +{ + 0.01864f, 0.29707f, + 0.02030f, 0.07182f, + 0.02151f, 1.08524f, + 0.03500f, 0.16009f, + 0.03977f, 0.02281f, + 0.04234f, 0.40424f, + 0.04933f, 0.76004f, + 0.05586f, 1.51515f, + 0.06020f, 2.12629f, + 0.06027f, 3.09183f, + 0.06439f, 0.11739f, + 0.07339f, 5.42703f, + 0.07352f, 0.03949f, + 0.08217f, 0.24883f, + 0.08739f, 0.64886f, + 0.10306f, 12.80025f, + 0.10466f, 0.50924f, + 0.11107f, 0.09482f, + 0.12457f, 1.36386f, + 0.13298f, 7.87494f, + 0.13422f, 0.19471f, + 0.13866f, 2.54472f, + 0.14144f, 0.90007f, + 0.14280f, 0.34101f, + 0.15640f, 0.05105f, + 0.15712f, 28.93375f, + 0.16220f, 4.10343f, + 0.16674f, 0.12822f, + 0.17199f, 0.01803f, + 0.17309f, 0.57791f, + 0.17880f, 1.83167f, + 0.21237f, 0.25432f, + 0.21425f, 0.42966f, + 0.22283f, 6.15919f, + 0.22382f, 1.40095f, + 0.22706f, 0.74928f, + 0.23090f, 1.03443f, + 0.23261f, 20.98373f, + 0.23699f, 10.51665f, + 0.24053f, 3.14177f, + 0.24195f, 0.09011f, + 0.25145f, 0.15676f, + 0.26865f, 0.02971f, + 0.27099f, 2.30569f, + 0.27377f, 0.33881f, + 0.28928f, 0.60729f, + 0.29592f, 0.06145f, + 0.31283f, 14.92646f, + 0.31414f, 0.21458f, + 0.31534f, 1.77427f, + 0.31962f, 0.49268f, + 0.32489f, 1.21756f, + 0.32814f, 4.91051f, + 0.34121f, 0.01364f, + 0.34148f, 8.74051f, + 0.34386f, 0.12541f, + 0.34508f, 0.89971f, + 0.35532f, 0.04229f, + 0.35970f, 0.27273f, + 0.36044f, 3.53446f, + 0.37703f, 0.71598f, + 0.38255f, 0.39178f, + 0.38772f, 2.13255f, + 0.40080f, 1.46796f, + 0.40443f, 0.09811f, + 0.41099f, 0.18558f, + 0.41248f, 0.57650f, + 0.42003f, 6.02510f, + 0.42491f, 2.66162f, + 0.44395f, 1.05504f, + 0.45244f, 0.32349f, + 0.46599f, 4.14121f, + 0.46643f, 0.07352f, + 0.46821f, 0.76710f, + 0.47180f, 0.44298f, + 0.47973f, 0.14694f, + 0.48709f, 0.22467f, + 0.48898f, 1.86483f, + 0.49391f, 7.20170f, + 0.49561f, 0.03365f, + 0.49719f, 11.52638f, + 0.51590f, 1.31314f, + 0.52029f, 3.12855f, + 0.52386f, 0.11286f, + 0.52972f, 0.53743f, + 0.54158f, 0.64936f, + 0.54442f, 0.88680f, + 0.54741f, 18.96873f, + 0.55717f, 5.01132f, + 0.55900f, 0.38267f, + 0.56108f, 2.20040f, + 0.56269f, 0.27811f, + 0.56764f, 0.01728f, + 0.56774f, 1.61683f, + 0.57428f, 0.17847f, + 0.59426f, 0.05172f, + 0.60253f, 1.12077f, + 0.61435f, 0.47966f, + 0.61837f, 2.64075f, + 0.61974f, 3.85052f, + 0.62233f, 0.77999f, + 0.62488f, 30.82914f, + 0.62591f, 8.30773f, + 0.63483f, 0.13040f, + 0.63717f, 0.08340f, + 0.64151f, 0.22596f, + 0.64277f, 14.45112f, + 0.65342f, 1.94833f, + 0.65906f, 1.41075f, + 0.66195f, 0.33327f, + 0.66208f, 0.59438f, + 0.66380f, 5.82288f, + 0.67561f, 55.08506f, + 0.67985f, 0.98953f, + 0.68848f, 0.02431f, + 0.69743f, 0.75692f, + 0.69940f, 0.41776f, + 0.71088f, 2.29372f, + 0.71473f, 9.88443f, + 0.71666f, 3.15179f, + 0.71976f, 1.57490f, + 0.72121f, 0.15977f, + 0.72569f, 0.25747f, + 0.73215f, 4.49475f, + 0.73242f, 1.17828f, + 0.73611f, 0.10706f, + 0.74660f, 0.50029f, + 0.75066f, 0.06441f, + 0.75918f, 0.66077f, + 0.76003f, 0.89356f, + 0.77072f, 6.95905f, + 0.77186f, 18.53232f, + 0.77303f, 1.82446f, + 0.78131f, 2.59582f, + 0.78137f, 0.37054f, + 0.78595f, 1.33439f, + 0.78988f, 0.20177f, + 0.79579f, 3.69204f, + 0.80621f, 12.12779f, + 0.80699f, 24.75305f, + 0.81287f, 0.04130f, + 0.81630f, 0.55362f, + 0.81694f, 0.29092f, + 0.81734f, 0.74874f, + 0.82110f, 1.06401f, + 0.82787f, 2.07876f, + 0.82981f, 5.00103f, + 0.84050f, 1.58158f, + 0.84438f, 2.89191f, + 0.84678f, 0.13416f, + 0.85616f, 0.44166f, + 0.86019f, 8.65103f, + 0.86346f, 0.01317f, + 0.86494f, 1.18927f, + 0.86577f, 0.09267f, + 0.86811f, 5.95882f, + 0.87117f, 0.84740f, + 0.87406f, 0.61269f, + 0.87981f, 0.23437f, + 0.88151f, 2.44548f, + 0.88504f, 0.33708f, + 0.88847f, 1.82180f, + 0.89206f, 3.31226f, + 0.89352f, 16.07224f, + 0.89868f, 0.17353f, + 0.90558f, 1.37396f, + 0.90956f, 4.04629f, + 0.91046f, 0.71437f, + 0.91555f, 0.95141f, + 0.91607f, 0.05802f, + 0.92133f, 0.50076f, + 0.92397f, 2.18529f, + 0.92943f, 6.99163f, + 0.93816f, 2.70762f, + 0.93915f, 10.79124f, + 0.93979f, 35.02379f, + 0.94373f, 0.29109f, + 0.94428f, 1.54440f, + 0.94915f, 1.11190f, + 0.94935f, 4.81827f, + 0.94963f, 0.39335f, + 0.95314f, 0.02810f, + 0.95605f, 0.62253f, + 0.96422f, 0.78364f, + 0.96502f, 1.90168f, + 0.96887f, 0.08041f, + 0.97223f, 3.22145f, + 0.97319f, 0.15476f, + 0.97937f, 0.21603f, + 0.99027f, 1.26402f, + 0.99060f, 2.42092f, + 0.99469f, 8.02656f, + 0.99661f, 20.50587f, + 0.99674f, 0.54301f, + 0.99823f, 5.86597f, + 0.99991f, 0.88884f, + 1.00124f, 0.33090f, + 1.00312f, 4.24275f, + 1.00328f, 1.65980f, + 1.02202f, 13.84765f, + 1.02395f, 0.69092f, + 1.02548f, 2.07584f, + 1.02556f, 0.12171f, + 1.02613f, 0.43643f, + 1.03316f, 1.03433f, + 1.03462f, 1.40902f, + 1.03999f, 2.82553f, + 1.05031f, 3.58878f, + 1.05184f, 0.26298f, + 1.06027f, 9.06668f, + 1.07241f, 0.79358f, + 1.07471f, 0.52241f, + 1.08008f, 1.76977f, + 1.08043f, 4.93935f, + 1.08062f, 45.38949f, + 1.08090f, 2.36074f, + 1.08304f, 1.15533f, + 1.08642f, 0.18015f, + 1.08996f, 0.06905f, + 1.09008f, 6.56321f, + 1.09044f, 0.01828f, + 1.09727f, 0.36021f, + 1.10075f, 0.62638f, + 1.11422f, 1.47205f, + 1.11535f, 0.93762f, + 1.11816f, 0.03576f, + 1.12340f, 0.10836f, + 1.13413f, 25.42389f, + 1.13994f, 2.96173f, + 1.14294f, 3.90159f, + 1.15382f, 0.04975f, + 1.15439f, 11.91982f, + 1.16090f, 16.73218f, + 1.16103f, 2.17967f, + 1.16117f, 0.68099f, + 1.16863f, 0.46714f, + 1.17332f, 1.18022f, + 1.17498f, 0.31199f, + 1.17616f, 9.51265f, + 1.18152f, 7.40048f, + 1.18372f, 0.24663f, + 1.18372f, 0.20126f, + 1.18610f, 0.14046f, + 1.18676f, 0.08978f, + 1.18699f, 5.55043f, + 1.18951f, 0.84044f, + 1.19478f, 1.59238f, + 1.19799f, 2.55164f, + 1.19820f, 1.89784f, + 1.19857f, 0.39387f, + 1.19888f, 0.56489f, + 1.19998f, 1.02889f, + 1.20345f, 3.31468f, + 1.20431f, 4.41910f, + 1.20567f, 1.32040f, + 1.21177f, 0.74548f +}; + +const float gp_gamma_1sfr_7b[2*128] = +{ + 0.02136f, 0.16576f, + 0.02610f, 0.04700f, + 0.02673f, 1.32916f, + 0.03917f, 0.38038f, + 0.06539f, 3.93015f, + 0.06590f, 0.78428f, + 0.07007f, 2.41347f, + 0.07073f, 0.12201f, + 0.08692f, 0.02273f, + 0.10144f, 0.26162f, + 0.12117f, 0.58428f, + 0.12817f, 0.06582f, + 0.13200f, 6.18738f, + 0.13542f, 1.05113f, + 0.14605f, 12.85127f, + 0.15252f, 1.88832f, + 0.17593f, 0.43086f, + 0.18150f, 24.88791f, + 0.19845f, 0.19059f, + 0.20102f, 0.09975f, + 0.21887f, 3.04712f, + 0.22650f, 0.80244f, + 0.22710f, 1.36678f, + 0.23569f, 0.04128f, + 0.24090f, 0.33017f, + 0.24423f, 4.39312f, + 0.25622f, 9.04696f, + 0.26686f, 0.01465f, + 0.30474f, 0.13696f, + 0.30653f, 0.51721f, + 0.33982f, 2.33214f, + 0.34572f, 0.96726f, + 0.34776f, 0.22391f, + 0.35921f, 1.66824f, + 0.37321f, 5.83958f, + 0.38246f, 0.29909f, + 0.38918f, 0.07567f, + 0.39258f, 0.03099f, + 0.40290f, 0.67440f, + 0.43384f, 3.82188f, + 0.44136f, 1.28810f, + 0.45720f, 0.39518f, + 0.46915f, 0.18114f, + 0.49155f, 7.58133f, + 0.49486f, 18.79692f, + 0.49964f, 2.78200f, + 0.50311f, 0.11426f, + 0.50988f, 1.82600f, + 0.51013f, 12.50225f, + 0.51163f, 0.85831f, + 0.53672f, 0.55661f, + 0.54568f, 0.24221f, + 0.58854f, 0.04842f, + 0.58856f, 1.13464f, + 0.59022f, 5.29180f, + 0.61432f, 0.31344f, + 0.62368f, 0.01799f, + 0.62503f, 3.37535f, + 0.62557f, 0.15698f, + 0.63586f, 2.17291f, + 0.64066f, 0.72903f, + 0.65002f, 0.46018f, + 0.67718f, 0.08632f, + 0.67719f, 1.47658f, + 0.68875f, 9.72347f, + 0.68911f, 32.65981f, + 0.72111f, 4.49107f, + 0.72523f, 0.94174f, + 0.73603f, 0.22351f, + 0.75271f, 16.69924f, + 0.75455f, 2.72292f, + 0.75633f, 0.36255f, + 0.76400f, 0.65651f, + 0.76595f, 6.66691f, + 0.77475f, 1.86222f, + 0.79933f, 1.19851f, + 0.80473f, 0.13963f, + 0.80852f, 0.51193f, + 0.82270f, 3.73825f, + 0.84176f, 0.02816f, + 0.84259f, 0.05841f, + 0.85838f, 0.27004f, + 0.86563f, 0.82004f, + 0.86743f, 2.29536f, + 0.88363f, 1.49460f, + 0.89140f, 5.36064f, + 0.89183f, 12.35149f, + 0.89905f, 8.20030f, + 0.90532f, 0.58773f, + 0.90588f, 0.39700f, + 0.91006f, 24.98023f, + 0.92596f, 0.19474f, + 0.92719f, 3.17426f, + 0.93316f, 1.03857f, + 0.94022f, 0.10069f, + 0.94912f, 1.92355f, + 0.98244f, 0.69665f, + 0.98723f, 4.12701f, + 0.99391f, 0.45338f, + 0.99688f, 1.30750f, + 0.99874f, 44.92089f, + 1.00074f, 0.30398f, + 1.00361f, 2.48072f, + 1.00432f, 6.80059f, + 1.00968f, 0.01556f, + 1.01623f, 10.59523f, + 1.03016f, 0.88271f, + 1.03693f, 0.16444f, + 1.03908f, 18.89908f, + 1.04942f, 1.71141f, + 1.08216f, 0.03947f, + 1.08519f, 2.81718f, + 1.09035f, 0.07394f, + 1.09092f, 0.49594f, + 1.09429f, 1.02772f, + 1.09931f, 4.69322f, + 1.14445f, 13.97163f, + 1.14663f, 0.22834f, + 1.14869f, 8.63215f, + 1.15982f, 0.12298f, + 1.16574f, 0.78265f, + 1.16644f, 0.35763f, + 1.17170f, 1.51544f, + 1.17199f, 5.76835f, + 1.17405f, 2.05383f, + 1.17523f, 0.58874f, + 1.18128f, 3.43730f, + 1.18605f, 1.15776f +}; + +const float gp_gamma_1sfr_6b[2*64] = +{ + 0.02662f, 0.35620f, + 0.02886f, 0.12384f, + 0.05872f, 0.03097f, + 0.06053f, 1.26461f, + 0.07678f, 3.09046f, + 0.08829f, 0.68582f, + 0.10444f, 0.24412f, + 0.11040f, 0.08899f, + 0.15678f, 8.15025f, + 0.15909f, 1.86873f, + 0.17247f, 0.48977f, + 0.17727f, 24.37615f, + 0.19825f, 0.05111f, + 0.21935f, 4.40219f, + 0.22361f, 0.15212f, + 0.22674f, 0.94328f, + 0.25832f, 0.01602f, + 0.28570f, 0.36784f, + 0.30922f, 12.93476f, + 0.31936f, 2.48635f, + 0.38038f, 1.35732f, + 0.38051f, 0.09521f, + 0.38075f, 0.21973f, + 0.38524f, 0.62092f, + 0.42799f, 0.03238f, + 0.44723f, 6.21713f, + 0.48877f, 3.39646f, + 0.53050f, 0.87060f, + 0.53522f, 0.31847f, + 0.54464f, 1.99023f, + 0.55504f, 0.15767f, + 0.63219f, 0.55908f, + 0.64035f, 0.05438f, + 0.64773f, 19.11642f, + 0.65402f, 1.48427f, + 0.67413f, 9.41877f, + 0.69087f, 4.69262f, + 0.71312f, 0.10928f, + 0.75159f, 0.21181f, + 0.76049f, 1.08676f, + 0.76781f, 0.01802f, + 0.77612f, 0.41533f, + 0.78253f, 2.60862f, + 0.86685f, 0.73032f, + 0.87435f, 33.14677f, + 0.89187f, 1.63714f, + 0.89264f, 6.41601f, + 0.89525f, 12.17085f, + 0.91060f, 0.07523f, + 0.92352f, 0.26853f, + 0.94457f, 3.60819f, + 0.97995f, 0.49732f, + 0.99345f, 0.96508f, + 0.99428f, 0.12950f, + 1.01209f, 2.04687f, + 1.02897f, 0.03326f, + 1.05102f, 17.03703f, + 1.06462f, 8.38911f, + 1.10284f, 4.88112f, + 1.11160f, 0.34356f, + 1.12908f, 0.17681f, + 1.13018f, 2.82130f, + 1.13048f, 0.64939f, + 1.13502f, 1.29540f +}; + + +const float gp_gamma_2sfr_7b[2*128] = +{ + 0.00607f, 2.39054f, + 0.00954f, 0.47393f, + 0.01025f, 1.13156f, + 0.01770f, 0.69243f, + 0.02670f, 0.86143f, + 0.02900f, 0.36511f, + 0.04481f, 1.44093f, + 0.05677f, 0.18129f, + 0.06916f, 0.29914f, + 0.06931f, 0.58281f, + 0.09094f, 0.99160f, + 0.11875f, 0.78403f, + 0.12072f, 32.79239f, + 0.12805f, 0.43746f, + 0.12919f, 1.87968f, + 0.14693f, 0.23271f, + 0.16393f, 0.66184f, + 0.17876f, 1.08413f, + 0.20774f, 0.52913f, + 0.21146f, 0.33304f, + 0.21176f, 0.82451f, + 0.22667f, 1.29470f, + 0.27074f, 0.96525f, + 0.27431f, 0.64919f, + 0.27900f, 0.42916f, + 0.27972f, 4.26235f, + 0.30501f, 1.65535f, + 0.32627f, 0.74124f, + 0.33076f, 0.21006f, + 0.33996f, 1.13073f, + 0.35145f, 0.51891f, + 0.35860f, 0.86393f, + 0.36177f, 0.33235f, + 0.37868f, 6.51886f, + 0.39024f, 12.56903f, + 0.39765f, 0.63998f, + 0.40513f, 1.42570f, + 0.40817f, 2.87488f, + 0.43002f, 2.06198f, + 0.43340f, 0.97173f, + 0.43475f, 0.40939f, + 0.43718f, 18.88363f, + 0.44833f, 0.75361f, + 0.46375f, 0.54756f, + 0.47932f, 1.22520f, + 0.51646f, 0.86275f, + 0.52785f, 0.64565f, + 0.53846f, 0.46049f, + 0.54240f, 1.07549f, + 0.54644f, 1.76965f, + 0.56866f, 0.26470f, + 0.58517f, 0.75438f, + 0.58905f, 1.35033f, + 0.59790f, 0.55874f, + 0.60132f, 0.95549f, + 0.61063f, 2.37370f, + 0.61285f, 0.37493f, + 0.64837f, 1.12469f, + 0.65662f, 0.64355f, + 0.66163f, 0.82985f, + 0.66799f, 1.54600f, + 0.67368f, 0.50148f, + 0.68300f, 3.65165f, + 0.70443f, 0.97799f, + 0.71587f, 1.25327f, + 0.72464f, 0.71612f, + 0.73632f, 0.31795f, + 0.75268f, 0.42125f, + 0.75309f, 2.14775f, + 0.75309f, 0.57562f, + 0.76160f, 0.86706f, + 0.76665f, 1.10985f, + 0.77299f, 1.64991f, + 0.80915f, 0.77262f, + 0.81281f, 1.32136f, + 0.81854f, 0.99876f, + 0.83675f, 0.63186f, + 0.83681f, 3.02209f, + 0.83687f, 0.48040f, + 0.85777f, 1.93471f, + 0.86131f, 0.87229f, + 0.86952f, 1.13226f, + 0.87613f, 1.46053f, + 0.87855f, 0.34269f, + 0.88214f, 0.19384f, + 0.89134f, 0.70978f, + 0.90866f, 0.95984f, + 0.92004f, 0.54981f, + 0.92222f, 1.24490f, + 0.93028f, 2.52260f, + 0.93695f, 0.80671f, + 0.94177f, 1.64620f, + 0.95825f, 1.05636f, + 0.96289f, 0.39904f, + 0.97439f, 0.65464f, + 0.97607f, 1.34420f, + 0.98128f, 0.88402f, + 0.99580f, 9.01834f, + 1.00135f, 2.01532f, + 1.01010f, 1.16279f, + 1.01723f, 0.74974f, + 1.02846f, 1.51554f, + 1.02849f, 0.94135f, + 1.03245f, 0.49354f, + 1.05191f, 0.60369f, + 1.05632f, 4.15579f, + 1.06623f, 1.06736f, + 1.07827f, 1.25591f, + 1.08027f, 0.82287f, + 1.08960f, 1.72193f, + 1.09072f, 0.28420f, + 1.10754f, 2.43024f, + 1.12653f, 0.95428f, + 1.12778f, 0.67641f, + 1.13450f, 1.41156f, + 1.14902f, 0.40686f, + 1.16032f, 3.38038f, + 1.16226f, 1.14385f, + 1.17713f, 0.54895f, + 1.18580f, 1.84337f, + 1.18686f, 0.74693f, + 1.19352f, 0.86699f, + 1.20171f, 1.54779f, + 1.20572f, 2.16971f, + 1.20617f, 1.02977f, + 1.20662f, 2.74485f, + 1.20688f, 1.28237f, + 1.20728f, 5.22483f +}; + + +const float gp_gamma_2sfr_6b[2*64] = +{ + 0.01130f, 0.59705f, + 0.02652f, 1.01430f, + 0.02794f, 0.28351f, + 0.06102f, 0.41178f, + 0.07430f, 0.77026f, + 0.07572f, 1.46777f, + 0.10914f, 0.18121f, + 0.12363f, 2.40953f, + 0.13197f, 0.51810f, + 0.14628f, 0.30909f, + 0.15972f, 0.92110f, + 0.20291f, 0.66321f, + 0.20694f, 1.21691f, + 0.23404f, 0.40495f, + 0.27484f, 33.61382f, + 0.28250f, 0.79452f, + 0.30145f, 1.75124f, + 0.31141f, 0.53656f, + 0.32351f, 0.23494f, + 0.33936f, 0.99733f, + 0.38508f, 3.72779f, + 0.40108f, 0.65367f, + 0.41319f, 0.40008f, + 0.42662f, 1.25364f, + 0.43246f, 9.93625f, + 0.45774f, 0.83578f, + 0.51009f, 1.61477f, + 0.51585f, 0.50984f, + 0.55413f, 1.04889f, + 0.56694f, 0.69123f, + 0.60142f, 2.29733f, + 0.60208f, 0.32174f, + 0.63695f, 16.75804f, + 0.64385f, 0.85349f, + 0.64786f, 1.32201f, + 0.67202f, 0.55054f, + 0.72879f, 1.03555f, + 0.74357f, 0.71744f, + 0.76140f, 1.79730f, + 0.78523f, 0.43896f, + 0.81538f, 1.20775f, + 0.81979f, 0.86215f, + 0.82523f, 3.16953f, + 0.86528f, 0.66633f, + 0.87274f, 0.25452f, + 0.88210f, 1.51311f, + 0.90326f, 0.99246f, + 0.93081f, 0.53871f, + 0.95916f, 2.20734f, + 0.96174f, 1.28996f, + 0.96917f, 0.82441f, + 0.99824f, 6.35842f, + 1.00335f, 0.36563f, + 1.02237f, 1.09680f, + 1.03188f, 0.64719f, + 1.04846f, 1.61469f, + 1.09185f, 0.91916f, + 1.11199f, 4.24727f, + 1.14659f, 0.48521f, + 1.15873f, 2.64461f, + 1.16374f, 1.37282f, + 1.17310f, 0.74954f, + 1.18098f, 1.86320f, + 1.18544f, 1.08087f +}; + +const float gp_gamma_3sfr_6b[2*64] = +{ + 0.01192f, 0.29245f, + 0.04985f, 0.56198f, + 0.07032f, 1.20261f, + 0.08337f, 0.36774f, + 0.08405f, 0.80061f, + 0.09313f, 1.76147f, + 0.09580f, 0.19048f, + 0.13781f, 0.46427f, + 0.15191f, 1.01263f, + 0.17911f, 0.66093f, + 0.19176f, 0.31423f, + 0.21095f, 3.33105f, + 0.24351f, 0.84426f, + 0.25383f, 1.38475f, + 0.25558f, 0.52730f, + 0.26697f, 2.41458f, + 0.32244f, 1.02709f, + 0.33147f, 0.25578f, + 0.33614f, 0.69549f, + 0.35169f, 0.41222f, + 0.41458f, 1.21107f, + 0.41759f, 0.87121f, + 0.42537f, 0.59296f, + 0.46820f, 1.57552f, + 0.51038f, 0.47823f, + 0.51562f, 1.03574f, + 0.52553f, 0.74288f, + 0.56848f, 2.12515f, + 0.59985f, 0.33289f, + 0.60551f, 13.69166f, + 0.61194f, 0.89674f, + 0.62213f, 0.60927f, + 0.62628f, 1.28489f, + 0.70519f, 0.76916f, + 0.71649f, 1.72293f, + 0.71964f, 1.05889f, + 0.73148f, 8.45570f, + 0.73217f, 0.48093f, + 0.77896f, 26.25153f, + 0.78396f, 2.95227f, + 0.80147f, 0.90896f, + 0.80167f, 0.66149f, + 0.80656f, 1.44516f, + 0.86294f, 1.18805f, + 0.88649f, 0.81413f, + 0.90213f, 2.01099f, + 0.90474f, 0.55259f, + 0.91649f, 0.33485f, + 0.93167f, 1.03017f, + 0.96578f, 5.28431f, + 0.97308f, 1.36442f, + 0.97409f, 0.70362f, + 0.99790f, 0.92401f, + 1.05048f, 1.12005f, + 1.05996f, 1.76024f, + 1.06915f, 0.46437f, + 1.08636f, 0.80929f, + 1.10286f, 2.76431f, + 1.13708f, 3.74909f, + 1.15280f, 1.23892f, + 1.16077f, 0.62175f, + 1.17824f, 0.96656f, + 1.18408f, 2.17545f, + 1.18487f, 1.49786f +}; + +const float gp_gamma_4sfr_6b[2*64] = +{ + 0.00934f, 0.27565f, + 0.01721f, 0.97811f, + 0.02433f, 0.46654f, + 0.04781f, 0.72086f, + 0.06776f, 1.45241f, + 0.08727f, 0.35723f, + 0.08791f, 3.41441f, + 0.09299f, 2.13125f, + 0.09778f, 0.57872f, + 0.11158f, 0.19319f, + 0.12208f, 0.85691f, + 0.16346f, 0.44503f, + 0.17183f, 1.17256f, + 0.18821f, 0.67810f, + 0.23565f, 0.93068f, + 0.25353f, 0.31870f, + 0.25723f, 0.55721f, + 0.27028f, 1.43169f, + 0.30369f, 0.74972f, + 0.33457f, 1.10643f, + 0.33886f, 0.45699f, + 0.37588f, 1.81394f, + 0.39890f, 0.91791f, + 0.40041f, 0.63732f, + 0.44484f, 0.33746f, + 0.45345f, 1.29581f, + 0.45454f, 20.73460f, + 0.48041f, 0.79572f, + 0.51620f, 0.51876f, + 0.52239f, 1.07372f, + 0.52970f, 2.77458f, + 0.57723f, 0.69551f, + 0.58187f, 1.53270f, + 0.60145f, 0.92017f, + 0.64601f, 11.29119f, + 0.65868f, 7.45030f, + 0.66000f, 0.40154f, + 0.66097f, 0.58966f, + 0.67054f, 1.18310f, + 0.69460f, 0.84554f, + 0.69993f, 2.09527f, + 0.76202f, 0.69518f, + 0.77672f, 1.01521f, + 0.78020f, 1.40843f, + 0.82725f, 0.50517f, + 0.84005f, 0.27186f, + 0.84739f, 0.84066f, + 0.85816f, 5.06160f, + 0.87075f, 1.17031f, + 0.87474f, 1.80610f, + 0.91532f, 0.65903f, + 0.93722f, 0.94775f, + 0.94762f, 1.39061f, + 1.00344f, 1.14608f, + 1.00732f, 0.77084f, + 1.01480f, 0.39878f, + 1.05149f, 2.51385f, + 1.07194f, 1.57173f, + 1.07599f, 1.01017f, + 1.10831f, 3.54277f, + 1.11815f, 0.59230f, + 1.17359f, 0.85449f, + 1.17572f, 1.24171f, + 1.18513f, 1.93190f +}; + + +/*----------------------------------------------------------------------------------* + * Transition coding - gain quantization table + *----------------------------------------------------------------------------------*/ + +const float tbl_gain_code_tc[N_GAIN_CODE_TC] = +{ + 0.36201f, + 0.72382f, + 0.96727f, + 1.1856f, + 1.4119f, + 1.679f, + 2.0743f, + 3.3301f +}; + +/*-----------------------------------------------------------------* + * Transition coding - gain quantization table for g_trans + *-----------------------------------------------------------------*/ + +const float tbl_gain_trans_tc[N_GAIN_TC] = +{ + 35.8449f, + 86.7884f, + 150.0926f, + 233.3001f, + 346.0286f, + 511.5196f, + 819.6746f, + 1500.0f +}; + +/*-----------------------------------------------------------------* + * Transition coding - table of prototype glottal impulses + *-----------------------------------------------------------------*/ + +const float glottal_cdbk[L_IMPULSE*NUM_IMPULSE] = +{ + /* impulse 0 */ + -0.0873f, -0.2063f, -0.3544f, -0.2126f, -0.1581f, -0.5208f, + -0.5973f, 0.2106f, 1.0000f, 0.7095f, -0.0767f, -0.2388f, + 0.0709f, 0.1143f, -0.0099f, 0.1015f, 0.1852f, + /* impulse 1 */ + -0.2646f, -0.1655f, -0.0493f, -0.3314f, -0.5455f, -0.2641f, + -0.2661f, -0.9837f, -1.1157f, 0.1420f, 1.2626f, 0.8151f, + -0.2146f, -0.3466f, 0.0460f, 0.0398f, -0.0598f, + /* impulse 2 */ + 0.0440f, 0.0685f, 0.5108f, 0.3092f, -0.4060f, -0.3111f, + 0.2513f, -0.2578f, -1.1648f, -0.7488f, 0.1596f, 0.0151f, + -0.4176f, -0.1788f, 0.0580f, -0.1082f, -0.1541f, + /* impulse 3 */ + -0.1579f, -0.0873f, -0.0224f, -0.1885f, -0.2000f, -0.0267f, + -0.4276f, -1.1485f, -0.9711f, -0.1718f, -0.0348f, -0.3044f, + 0.0372f, 0.5686f, 0.4015f, 0.0141f, 0.1816f, + /* impulse 4 */ + 0.1022f, 0.3080f, 0.2984f, 0.3270f, 0.7278f, 0.8466f, + -0.1128f, -1.2094f, -0.9235f, 0.0785f, 0.1648f, -0.3146f, + -0.2563f, -0.0338f, -0.1887f, -0.2782f, -0.1077f, + /* impulse 5 */ + -0.0510f, -0.1082f, -0.0058f, -0.0603f, -0.2891f, -0.2515f, + -0.1505f, -0.6434f, -1.2732f, -0.8490f, 0.4029f, 0.9251f, + 0.3172f, -0.2032f, -0.0563f, 0.0897f, -0.0221f, + /* impulse 6 */ + -0.0570f, -0.2277f, -0.1776f, -0.0155f, -0.2296f, -0.4609f, + 0.1004f, 1.0174f, 1.0000f, 0.1053f, -0.3371f, -0.0458f, + 0.0924f, -0.0681f, -0.0348f, 0.0797f, 0.0183f, + /* impulse 7 */ + 0.1327f, 0.0575f, -0.0754f, 0.0862f, 0.1887f, -0.1959f, + -0.3975f, 0.2925f, 0.9839f, 0.6334f, -0.0121f, -0.0045f, + 0.1349f, -0.0815f, -0.1751f, -0.0072f, -0.0099f +}; + +/*----------------------------------------------------------------------------------* + * AMR-WB IO WB BWE - deemphasis + *----------------------------------------------------------------------------------*/ + +const float deem_tab[56] = +{ + 0.630730419421360f, 0.629416164964296f, 0.628129905227103f, 0.626871385453679f, 0.625640357452226f, 0.624436579475560f, 0.623259816105156f, + 0.622109838138814f, 0.620986422481867f, 0.619889352041818f, 0.618818415626335f, 0.617773407844493f, 0.616754129011203f, 0.615760385054730f, + 0.614791987427225f, 0.613848753018209f, 0.612930504070914f, 0.612037068101433f, 0.611168277820597f, 0.610323971058526f, 0.609503990691786f, + 0.608708184573088f, 0.607936405463484f, 0.607188510967000f, 0.606464363467645f, 0.605763830068759f, 0.605086782534647f, 0.604433097234441f, + 0.603802655088168f, 0.603195341514964f, 0.602611046383395f, 0.602049663963857f, 0.601511092883003f, 0.600995236080178f, 0.600502000765808f, + 0.600031298381734f, 0.599583044563439f, 0.599157159104159f, 0.598753565920828f, 0.598372193021851f, 0.598012972476677f, 0.597675840387130f, + 0.597360736860508f, 0.597067605984399f, 0.596796395803217f, 0.596547058296428f, 0.596319549358454f, 0.596113828780239f, 0.595929860232466f, + 0.595767611250409f, 0.595627053220407f, 0.595508161367956f, 0.595410914747406f, 0.595335296233253f, 0.595281292513031f, 0.595248894081778f +}; + +const float filt_hp[56] = +{ + 0.001610570549503f, 0.004682981184545f, 0.008349027644995f, 0.012654118680910f, 0.017642537255539f, 0.023357023549788f, + 0.029838357405517f, 0.037124944278684f, 0.045252408764306f, 0.054253199698241f, 0.064156210737117f, 0.074986420169406f, + 0.086764553520305f, 0.099506772283889f, 0.113224391851657f, 0.127923631411203f, 0.143605398266754f, 0.160265108689438f, + 0.177892547044310f, 0.196471764568281f, 0.215981018793259f, 0.236392754226835f, 0.257673624523579f, 0.279784556007892f, + 0.302680852048711f, 0.326312337440982f, 0.350623541622164f, 0.375553919247241f, 0.401038106365070f, 0.427006210184762f, + 0.453384130194306f, 0.480093908196193f, 0.507054104656542f, 0.534180198625471f, 0.561385008376586f, 0.588579129831778f, + 0.615671389782721f, 0.642569310891142f, 0.669179585444241f, 0.695408554857669f, 0.721162691954086f, 0.746349083098340f, + 0.770875907338563f, 0.794652909783784f, 0.817591866540936f, 0.839607038635485f, 0.860615612448599f, 0.880538124318166f, + 0.899298867069991f, 0.916826276367851f, 0.933053294896263f, 0.947917712517199f, 0.961362480671352f, 0.973335999426038f, + 0.983792375705577f, 0.992691651376520f +}; + +/* table of values exp(-j*w*i) */ +const float exp_tab_q[34] = +{ + 1.000000000000000f, -0.980785280403230f, 0.923879532511287f, -0.831469612302544f, + 0.707106781186547f, -0.555570233019602f, 0.382683432365086f, -0.195090322016125f, + -0.000000000000003f, 0.195090322016130f, -0.382683432365091f, 0.555570233019606f, + -0.707106781186553f, 0.831469612302547f, -0.923879532511289f, 0.980785280403231f, + -1.000000000000000f, 0.000000000000000f, -0.195090322016129f, 0.382683432365090f, + -0.555570233019604f, 0.707106781186549f, -0.831469612302546f, 0.923879532511288f, + -0.980785280403231f, 1.000000000000000f, -0.980785280403230f, 0.923879532511286f, + -0.831469612302543f, 0.707106781186542f, -0.555570233019599f, 0.382683432365084f, + -0.195090322016126f, -0.000000000000005f +}; + +const float exp_tab_p[34] = +{ + 1.000000000000000f, -0.707106781186548f, -0.000000000000000f, 0.707106781186548f, + -1.000000000000000f, 0.707106781186547f, 0.000000000000000f, -0.707106781186547f, + 1.000000000000000f, -0.707106781186546f, -0.000000000000003f, 0.707106781186548f, + -1.000000000000000f, 0.707106781186546f, -0.000000000000000f, -0.707106781186548f, + 1.000000000000000f, 0.000000000000000f, -0.707106781186548f, 1.000000000000000f, + -0.707106781186547f, -0.000000000000000f, 0.707106781186549f, -1.000000000000000f, + 0.707106781186548f, 0.000000000000000f, -0.707106781186549f, 1.000000000000000f, + -0.707106781186548f, 0.000000000000000f, 0.707106781186549f, -1.000000000000000f, + 0.707106781186547f, 0.000000000000000f +}; + +/* gains for 23k85 mode */ +const float HP_gain[16] = +{ + /* values in Q15: 3624, 4673, 5597, 6479, 7425, 8378, 9324, 10264, 11210, 12206, 13391, 14844, 16770, 19655, 24289, 32728 */ + 0.110595703125000f, 0.142608642578125f, 0.170806884765625f, 0.197723388671875f, + 0.226593017578125f, 0.255676269531250f, 0.284545898437500f, 0.313232421875000f, + 0.342102050781250f, 0.372497558593750f, 0.408660888671875f, 0.453002929687500f, + 0.511779785156250f, 0.599822998046875f, 0.741241455078125f, 0.998779296875000f +}; + +/* band-pass 6-8kHz filter */ +const float fir_6k_8k[31]= +{ + 0.001331237773450f, -0.004734562657574f, 0.009865692979275f, -0.014704482109862f, + 0.017170883692091f, -0.018004559024736f, 0.022168155759205f, -0.036012990296002f, + 0.060614595353634f, -0.086000479894051f, 0.092413785317631f, -0.060769441864153f, + -0.012918738234409f, 0.109335430548556f, -0.191677822804549f, 0.224071909378974f, + -0.191677822804549f, 0.109335430548556f, -0.012918738234409f, -0.060769441864153f, + 0.092413785317631f, -0.086000479894051f, 0.060614595353634f, -0.036012990296002f, + 0.022168155759205f, -0.018004559024736f, 0.017170883692091f, -0.014704482109862f, + 0.009865692979275f, -0.004734562657574f, 0.001331237773450f +}; + + +/*----------------------------------------------------------------------------------* + * 2nd order high-pass filter with cut-off frequency at 400 Hz. + * Designed with Chebyshev of 2nd type + * Optimized for fixed-point to get the following frequency response: + * + * frequency: 0Hz 100Hz 200Hz 300Hz 400Hz 630Hz 1.5kHz 3kHz + * dB loss: -infdB -30dB -20dB -10dB -3dB +6dB +1dB 0dB + * + * Algorithm: + * + * y[i] = b[0]*x[i] + b[1]*x[i-1] + b[2]*x[i-2] + * + a[1]*y[i-1] + a[2]*y[i-2]; + * + * short b[3] = {3660, -7320, 3660}; in Q12 + * short a[3] = {4096, 7320, -3540}; in Q12 + *----------------------------------------------------------------------------------*/ + +const float b_hp400[3] = { 0.893554687f, -1.787109375f, 0.893554687f }; +const float a_hp400[3] = { 1.000000000f, 1.787109375f, -0.864257812f }; + +/*----------------------------------------------------------------------------------* + * 15th-order band-pass 6kHz to 7kHz FIR filter. + * + * frequency: 4kHz 5kHz 5.5kHz 6kHz 6.5kHz 7kHz 7.5kHz 8kHz + * dB loss: -60dB -45dB -13dB -3dB 0dB -3dB -13dB -45dB + * + * gain = 4.0 + *----------------------------------------------------------------------------------*/ + +const float fir_6k_7k[31] = +{ + -0.001005f, 0.001428f, 0.000965f, -0.000863f, -0.011296f, + 0.034231f, -0.043397f, -0.000000f, 0.115906f, -0.271028f, + 0.376868f, -0.335243f, 0.108276f, 0.237003f, -0.549363f, + 0.675000f, -0.549363f, 0.237003f, 0.108276f, -0.335243f, + 0.376868f, -0.271028f, 0.115906f, -0.000000f, -0.043397f, + 0.034231f, -0.011296f, -0.000863f, 0.000965f, 0.001428f, + -0.001005f +}; + +/*----------------------------------------------------------------------------------* + * Enhacer - 2.0 - 6.4 kHz impulse response with phase dispersion in freq. domain + *----------------------------------------------------------------------------------*/ + +const float low_H[L_SUBFR] = +{ + 1.000300f, 0.999812f, 1.000125f, 0.999868f, 0.999879f, 0.999935f, 0.999838f, 0.999992f, 1.000076f, 0.626554f, 0.619763f, 0.603882f, 0.857647f, 0.997470f, -0.032403f, + 0.806652f, 0.999300f, 0.946634f, 0.574139f, 0.973425f, 0.288464f, 0.890704f, 0.635021f, 0.597882f, -0.997076f, -0.110774f, -0.648392f, 0.771888f, 0.888411f, -0.774123f, + 0.695109f, 0.498998f, 0.999900f, -0.866525f, 0.719081f, 0.633481f, 0.458722f, 0.636210f, -0.761251f, 0.993932f, -0.073228f, -0.801816f, 0.772627f, -0.454461f, 0.957250f, + -0.229682f, -0.818972f, -0.322274f, 0.031800f, -0.591141f, -0.999439f, -0.074385f, 0.514882f, -0.797032f, -0.784999f, -0.779712f, -0.000028f, 0.000164f, 0.000029f, -0.000135f, + -0.000047f, -0.000033f, -0.000080f, 0.000099f +}; + +/*----------------------------------------------------------------------------------* + * Enhancer - 3.2 - 6.4 kHz impulse response with phase dispersion in freq. domain + *----------------------------------------------------------------------------------*/ + +const float mid_H[L_SUBFR] = +{ + 0.999900f, 0.999848f, 1.000003f, 1.000048f, 1.000107f, 1.000242f, 1.000165f, 0.999909f, 1.000212f, 0.999933f, 1.000099f, 1.000100f, 1.000113f, 1.000018f, 0.999901f, 1.000267f, + 0.906200f, 0.587715f, 0.808629f, 0.884216f, 0.671089f, 0.039238f, 0.843369f, 0.841006f, 0.394788f, 0.528863f, 0.710110f, 0.596973f, -0.893309f, -0.059908f, 0.716925f, -0.044067f, + 1.000100f, -0.998848f, -0.697170f, 0.998190f, 0.449397f, 0.802480f, -0.704198f, -0.848591f, -0.918649f, -0.540881f, 0.537822f, -0.999200f, -0.741318f, 0.467580f, -0.588204f, + -0.808928f, -0.422500f, 0.000219f, -0.000261f, -0.000086f, -0.000313f, 0.000080f, 0.000406f, 0.000351f, -0.000449f, -0.000065f, 0.000214f, -0.000254f, 0.000002f, -0.000090f, + -0.000198f, 0.000193f +}; + +/*-------------------------------------------------------------------* + * Low-pass FIR filter for low-freq post-filtering + * response : 0dB @ 50Hz, -6dB @ 500Hz, -45dB @ 1kHz) + * filter parameters: fs/2=8000, fc=500, gain=1.0, n=16 + *-------------------------------------------------------------------*/ + +const float tab_hup_l[SIZ_TAB_HUP_L] = +{ + -0.001246f, 0.002200f, -0.004791f, 0.009621f, -0.017685f, 0.031212f, -0.057225f, 0.135470f, 0.973955f, -0.103495f, 0.048663f, -0.027090f, 0.015280f, -0.008160f, + 0.003961f, -0.001827f, -0.002388f, 0.004479f, -0.009715f, 0.019261f, -0.035118f, 0.061945f, -0.115187f, 0.294161f, 0.898322f, -0.170283f, 0.083211f, -0.046645f, + 0.026210f, -0.013854f, 0.006641f, -0.003099f, -0.003277f, 0.006456f, -0.013906f, 0.027229f, -0.049283f, 0.086990f, -0.164590f, 0.464041f, 0.780309f, -0.199879f, + 0.100795f, -0.056792f, 0.031761f, -0.016606f, 0.007866f, -0.003740f, -0.003770f, 0.007714f, -0.016462f, 0.031849f, -0.057272f, 0.101294f, -0.195755f, 0.630993f, + 0.630993f, -0.195755f, 0.101294f, -0.057272f, 0.031849f, -0.016462f, 0.007714f, -0.003770f, -0.003740f, 0.007866f, -0.016606f, 0.031761f, -0.056792f, 0.100795f, + -0.199879f, 0.780309f, 0.464041f, -0.164590f, 0.086990f, -0.049283f, 0.027229f, -0.013906f, 0.006456f, -0.003277f, -0.003099f, 0.006641f, -0.013854f, 0.026210f, + -0.046645f, 0.083211f, -0.170283f, 0.898322f, 0.294161f, -0.115187f, 0.061945f, -0.035118f, 0.019261f, -0.009715f, 0.004479f, -0.002388f, -0.001827f, 0.003961f, + -0.008160f, 0.015280f, -0.027090f, 0.048663f, -0.103495f, 0.973955f, 0.135470f, -0.057225f, 0.031212f, -0.017685f, 0.009621f, -0.004791f, 0.002200f, -0.001246f +}; + +const float tab_hup_s[SIZ_TAB_HUP_S] = +{ + -0.005772f, 0.087669f, 0.965882f, -0.048753f, -0.014793f, 0.214886f, 0.868791f, -0.065537f, -0.028507f, 0.374334f, 0.723418f, -0.060834f, -0.045567f, 0.550847f, + 0.550847f, -0.045567f, -0.060834f, 0.723418f, 0.374334f, -0.028507f, -0.065537f, 0.868791f, 0.214886f, -0.014793f, -0.048753f, 0.965882f, 0.087669f, -0.005772f +}; + +/*-------------------------------------------------------------------* + * Bass post-filter + *-------------------------------------------------------------------*/ + +const float filt_lp[1+L_FILT] = +{ + 0.088250f, 0.086410f, 0.081074f, 0.072768f, 0.062294f, 0.050623f, 0.038774f, 0.027692f, + 0.018130f, 0.010578f, 0.005221f, 0.001946f, 0.000385f +}; + +const float filt_lp_16kHz[1+L_FILT16k] = +{ + 0.071410f, 0.070433f, 0.067568f, 0.062999f, 0.057020f, 0.050005f, + 0.042378f, 0.034577f, 0.027022f, 0.020078f, 0.014031f, 0.009070f, + 0.005276f, 0.002625f, 0.000999f, 0.000205f +}; + +/*-------------------------------------------------------------------* + * Pulse indexing tables for ACELP innovation coding + *-------------------------------------------------------------------*/ + +const int PI_select_table[23][8] = +{ + {1, 0, 0, 0, 0, 0, 0, 0}, + {1, 1, 0, 0, 0, 0, 0, 0}, + {1, 2, 1, 0, 0, 0, 0, 0}, + {1, 3, 3, 1, 0, 0, 0, 0}, + {1, 4, 6, 4, 1, 0, 0, 0}, + {1, 5, 10, 10, 5, 1, 0, 0}, + {1, 6, 15, 20, 15, 6, 1, 0}, + {1, 7, 21, 35, 35, 21, 7, 1}, + {1, 8, 28, 56, 70, 56, 28, 8}, + {1, 9, 36, 84, 126, 126, 84, 36}, + {1, 10, 45, 120, 210, 252, 210, 120}, + {1, 11, 55, 165, 330, 462, 462, 330}, + {1, 12, 66, 220, 495, 792, 924, 792}, + {1, 13, 78, 286, 715, 1287, 1716, 1716}, + {1, 14, 91, 364, 1001, 2002, 3003, 3432}, + {1, 15, 105, 455, 1365, 3003, 5005, 6435}, + {1, 16, 120, 560, 1820, 4368, 8008, 11440}, + {1, 17, 136, 680, 2380, 6188, 12376, 19448}, + {1, 18, 153, 816, 3060, 8568, 18564, 31824}, + {1, 19, 171, 969, 3876, 11628, 27132, 50388}, + {1, 20, 190, 1140, 4845, 15504, 38760, 77520}, + {1, 21, 210, 1330, 5985, 20349, 54264, 116280}, + {1, 22, 231, 1540, 7315, 26334, 74613, 1705444} +}; + +const int PI_offset[8][8] = +{ + /* for 0p(0). */ + {0x00000,0x00000,0x00000,0x00000,0x00000,0x00000,0x00000,0x00000}, + /* for 1p(1). */ + {0x00000,0x00000,0x00000,0x00000,0x00000,0x00000,0x00000,0x00000}, + /* for 2p(2,1). */ + {0x00000,0x00000,0x00000,0x00000,0x00000,0x00000,0x00000,0x00000}, + /* for 3p(3,2,1). */ + {0x00000,0x00000,0x01180,0x01540,0x00000,0x00000,0x00000,0x00000}, + /* for 4p(4,3,2,1). */ + {0x00000,0x00000,0x071C0,0x0A640,0x0ABE0,0x00000,0x00000,0x00000}, + /* for 5p(5,4,3,2,1). */ + {0x00000,0x00000,0x22200,0x3E900,0x45200,0x45980,0x00000,0x00000}, + /* for 6p(6,5,4,3,2,1). */ + {0x00000,0x00000,0x07d200,0x127c00,0x16ed80,0x179c80,0x17a5e0,0x00000}, + /* for 7p(7,6,5,4,3,2,1). */ + {0x00000,0x00000,0x165800,0x454400,0x654200,0x6E2500,0x6F2B80,0x6F36C0} +}; + +const short PI_factor[7] = {0,0,120,560,1820,4368,8008}; + +/*------------------------------------------------------------------------------* + * EDCT tables + *------------------------------------------------------------------------------*/ + +const float edct_table_80[80] = +{ + 0.33433591f, 0.33420702f, 0.33394929f, 0.33356281f, 0.33304773f, 0.33240426f, 0.33163264f, 0.33073317f, + 0.32970620f, 0.32855212f, 0.32727137f, 0.32586446f, 0.32433192f, 0.32267434f, 0.32089236f, 0.31898668f, + 0.31695802f, 0.31480717f, 0.31253495f, 0.31014224f, 0.30762997f, 0.30499910f, 0.30225065f, 0.29938568f, + 0.29640528f, 0.29331062f, 0.29010288f, 0.28678330f, 0.28335316f, 0.27981378f, 0.27616653f, 0.27241281f, + 0.26855407f, 0.26459179f, 0.26052751f, 0.25636280f, 0.25209925f, 0.24773851f, 0.24328226f, 0.23873223f, + 0.23409016f, 0.22935784f, 0.22453710f, 0.21962979f, 0.21463782f, 0.20956310f, 0.20440759f, 0.19917327f, + 0.19386217f, 0.18847633f, 0.18301783f, 0.17748878f, 0.17189129f, 0.16622755f, 0.16049971f, 0.15471000f, + 0.14886065f, 0.14295391f, 0.13699206f, 0.13097739f, 0.12491224f, 0.11879892f, 0.11263981f, 0.10643727f, + 0.10019369f, 0.09391149f, 0.08759309f, 0.08124092f, 0.07485742f, 0.06844507f, 0.06200633f, 0.05554369f, + 0.04905963f, 0.04255666f, 0.03603728f, 0.02950402f, 0.02295937f, 0.01640588f, 0.00984606f, 0.00328244f +}; + +const float edct_table_120[120] = +{ + 0.30212379f, 0.30207202f, 0.30196850f, 0.30181323f, 0.30160625f, 0.30134759f, 0.30103730f, 0.30067542f, + 0.30026203f, 0.29979718f, 0.29928097f, 0.29871348f, 0.29809481f, 0.29742505f, 0.29670434f, 0.29593279f, + 0.29511053f, 0.29423770f, 0.29331446f, 0.29234097f, 0.29131738f, 0.29024387f, 0.28912063f, 0.28794786f, + 0.28672574f, 0.28545450f, 0.28413434f, 0.28276550f, 0.28134821f, 0.27988271f, 0.27836926f, 0.27680811f, + 0.27519952f, 0.27354379f, 0.27184118f, 0.27009200f, 0.26829654f, 0.26645510f, 0.26456801f, 0.26263559f, + 0.26065816f, 0.25863608f, 0.25656968f, 0.25445931f, 0.25230535f, 0.25010815f, 0.24786810f, 0.24558558f, + 0.24326098f, 0.24089470f, 0.23848714f, 0.23603872f, 0.23354985f, 0.23102097f, 0.22845250f, 0.22584489f, + 0.22319858f, 0.22051402f, 0.21779168f, 0.21503203f, 0.21223553f, 0.20940267f, 0.20653392f, 0.20362979f, + 0.20069076f, 0.19771735f, 0.19471006f, 0.19166941f, 0.18859591f, 0.18549011f, 0.18235251f, 0.17918368f, + 0.17598414f, 0.17275445f, 0.16949515f, 0.16620682f, 0.16289000f, 0.15954528f, 0.15617322f, 0.15277439f, + 0.14934940f, 0.14589881f, 0.14242322f, 0.13892323f, 0.13539943f, 0.13185244f, 0.12828285f, 0.12469128f, + 0.12107835f, 0.11744467f, 0.11379087f, 0.11011757f, 0.10642540f, 0.10271499f, 0.09898699f, 0.09524203f, + 0.09148074f, 0.08770378f, 0.08391180f, 0.08010544f, 0.07628535f, 0.07245219f, 0.06860661f, 0.06474928f, + 0.06088086f, 0.05700200f, 0.05311338f, 0.04921565f, 0.04530949f, 0.04139557f, 0.03747456f, 0.03354713f, + 0.02961394f, 0.02567569f, 0.02173303f, 0.01778665f, 0.01383722f, 0.00988542f, 0.00593193f, 0.00197742f +}; + +const float edct_table_320[320] = +{ + 0.23643389f, 0.23642819f, 0.23641680f, 0.23639971f, 0.23637692f, 0.23634844f, 0.23631426f, 0.23627439f, + 0.23622882f, 0.23617757f, 0.23612062f, 0.23605798f, 0.23598966f, 0.23591565f, 0.23583595f, 0.23575057f, + 0.23565951f, 0.23556278f, 0.23546036f, 0.23535227f, 0.23523852f, 0.23511909f, 0.23499400f, 0.23486324f, + 0.23472683f, 0.23458476f, 0.23443704f, 0.23428367f, 0.23412465f, 0.23396000f, 0.23378970f, 0.23361377f, + 0.23343222f, 0.23324504f, 0.23305223f, 0.23285382f, 0.23264979f, 0.23244015f, 0.23222492f, 0.23200409f, + 0.23177767f, 0.23154566f, 0.23130808f, 0.23106492f, 0.23081619f, 0.23056191f, 0.23030206f, 0.23003667f, + 0.22976573f, 0.22948926f, 0.22920726f, 0.22891974f, 0.22862670f, 0.22832815f, 0.22802410f, 0.22771455f, + 0.22739952f, 0.22707901f, 0.22675302f, 0.22642158f, 0.22608467f, 0.22574232f, 0.22539453f, 0.22504131f, + 0.22468267f, 0.22431861f, 0.22394915f, 0.22357429f, 0.22319405f, 0.22280842f, 0.22241743f, 0.22202108f, + 0.22161938f, 0.22121233f, 0.22079996f, 0.22038227f, 0.21995927f, 0.21953096f, 0.21909737f, 0.21865850f, + 0.21821436f, 0.21776496f, 0.21731032f, 0.21685044f, 0.21638533f, 0.21591501f, 0.21543948f, 0.21495877f, + 0.21447288f, 0.21398181f, 0.21348560f, 0.21298423f, 0.21247774f, 0.21196612f, 0.21144940f, 0.21092759f, + 0.21040069f, 0.20986872f, 0.20933169f, 0.20878962f, 0.20824252f, 0.20769041f, 0.20713328f, 0.20657117f, + 0.20600408f, 0.20543202f, 0.20485502f, 0.20427308f, 0.20368621f, 0.20309444f, 0.20249778f, 0.20189623f, + 0.20128983f, 0.20067857f, 0.20006247f, 0.19944156f, 0.19881584f, 0.19818532f, 0.19755004f, 0.19690999f, + 0.19626520f, 0.19561568f, 0.19496144f, 0.19430251f, 0.19363890f, 0.19297062f, 0.19229769f, 0.19162012f, + 0.19093794f, 0.19025116f, 0.18955980f, 0.18886386f, 0.18816338f, 0.18745836f, 0.18674883f, 0.18603479f, + 0.18531628f, 0.18459330f, 0.18386586f, 0.18313400f, 0.18239773f, 0.18165706f, 0.18091202f, 0.18016261f, + 0.17940887f, 0.17865080f, 0.17788842f, 0.17712176f, 0.17635084f, 0.17557566f, 0.17479625f, 0.17401263f, + 0.17322482f, 0.17243283f, 0.17163669f, 0.17083642f, 0.17003202f, 0.16922353f, 0.16841096f, 0.16759434f, + 0.16677367f, 0.16594899f, 0.16512031f, 0.16428765f, 0.16345103f, 0.16261047f, 0.16176600f, 0.16091763f, + 0.16006537f, 0.15920927f, 0.15834932f, 0.15748556f, 0.15661801f, 0.15574668f, 0.15487160f, 0.15399279f, + 0.15311027f, 0.15222405f, 0.15133417f, 0.15044065f, 0.14954350f, 0.14864274f, 0.14773840f, 0.14683051f, + 0.14591907f, 0.14500412f, 0.14408568f, 0.14316376f, 0.14223840f, 0.14130960f, 0.14037740f, 0.13944182f, + 0.13850288f, 0.13756060f, 0.13661501f, 0.13566613f, 0.13471397f, 0.13375858f, 0.13279995f, 0.13183813f, + 0.13087313f, 0.12990498f, 0.12893370f, 0.12795931f, 0.12698183f, 0.12600130f, 0.12501773f, 0.12403115f, + 0.12304158f, 0.12204905f, 0.12105357f, 0.12005518f, 0.11905390f, 0.11804974f, 0.11704275f, 0.11603293f, + 0.11502031f, 0.11400493f, 0.11298680f, 0.11196594f, 0.11094239f, 0.10991616f, 0.10888729f, 0.10785579f, + 0.10682169f, 0.10578502f, 0.10474580f, 0.10370406f, 0.10265981f, 0.10161310f, 0.10056393f, 0.09951234f, + 0.09845836f, 0.09740200f, 0.09634329f, 0.09528227f, 0.09421894f, 0.09315335f, 0.09208551f, 0.09101546f, + 0.08994321f, 0.08886879f, 0.08779223f, 0.08671356f, 0.08563280f, 0.08454997f, 0.08346511f, 0.08237823f, + 0.08128937f, 0.08019855f, 0.07910580f, 0.07801115f, 0.07691461f, 0.07581622f, 0.07471600f, 0.07361399f, + 0.07251019f, 0.07140466f, 0.07029740f, 0.06918844f, 0.06807783f, 0.06696557f, 0.06585169f, 0.06473623f, + 0.06361921f, 0.06250066f, 0.06138060f, 0.06025906f, 0.05913607f, 0.05801166f, 0.05688584f, 0.05575866f, + 0.05463013f, 0.05350029f, 0.05236916f, 0.05123676f, 0.05010313f, 0.04896830f, 0.04783228f, 0.04669511f, + 0.04555682f, 0.04441742f, 0.04327696f, 0.04213546f, 0.04099294f, 0.03984943f, 0.03870496f, 0.03755956f, + 0.03641326f, 0.03526607f, 0.03411804f, 0.03296919f, 0.03181954f, 0.03066912f, 0.02951797f, 0.02836610f, + 0.02721355f, 0.02606034f, 0.02490651f, 0.02375208f, 0.02259707f, 0.02144152f, 0.02028545f, 0.01912890f, + 0.01797188f, 0.01681443f, 0.01565658f, 0.01449834f, 0.01333976f, 0.01218086f, 0.01102166f, 0.00986220f, + 0.00870250f, 0.00754259f, 0.00638250f, 0.00522226f, 0.00406188f, 0.00290142f, 0.00174088f, 0.00058030f +}; + +const float edct_table_480[480] = +{ + 0.21364290f, 0.21364061f, 0.21363603f, 0.21362917f, 0.21362002f, 0.21360858f, 0.21359485f, 0.21357884f, + 0.21356053f, 0.21353995f, 0.21351707f, 0.21349191f, 0.21346446f, 0.21343473f, 0.21340271f, 0.21336840f, + 0.21333181f, 0.21329294f, 0.21325178f, 0.21320833f, 0.21316261f, 0.21311460f, 0.21306431f, 0.21301173f, + 0.21295688f, 0.21289974f, 0.21284033f, 0.21277863f, 0.21271466f, 0.21264841f, 0.21257988f, 0.21250908f, + 0.21243600f, 0.21236064f, 0.21228301f, 0.21220311f, 0.21212093f, 0.21203649f, 0.21194977f, 0.21186078f, + 0.21176952f, 0.21167600f, 0.21158021f, 0.21148215f, 0.21138183f, 0.21127924f, 0.21117439f, 0.21106728f, + 0.21095791f, 0.21084628f, 0.21073239f, 0.21061625f, 0.21049785f, 0.21037720f, 0.21025429f, 0.21012913f, + 0.21000172f, 0.20987206f, 0.20974016f, 0.20960601f, 0.20946961f, 0.20933097f, 0.20919009f, 0.20904697f, + 0.20890161f, 0.20875401f, 0.20860417f, 0.20845211f, 0.20829781f, 0.20814128f, 0.20798252f, 0.20782153f, + 0.20765832f, 0.20749288f, 0.20732522f, 0.20715535f, 0.20698325f, 0.20680894f, 0.20663241f, 0.20645367f, + 0.20627271f, 0.20608955f, 0.20590418f, 0.20571661f, 0.20552684f, 0.20533486f, 0.20514068f, 0.20494431f, + 0.20474574f, 0.20454498f, 0.20434203f, 0.20413689f, 0.20392956f, 0.20372005f, 0.20350836f, 0.20329449f, + 0.20307844f, 0.20286022f, 0.20263983f, 0.20241726f, 0.20219253f, 0.20196563f, 0.20173657f, 0.20150535f, + 0.20127197f, 0.20103643f, 0.20079874f, 0.20055891f, 0.20031692f, 0.20007279f, 0.19982652f, 0.19957810f, + 0.19932755f, 0.19907486f, 0.19882005f, 0.19856310f, 0.19830403f, 0.19804283f, 0.19777951f, 0.19751407f, + 0.19724652f, 0.19697686f, 0.19670509f, 0.19643121f, 0.19615522f, 0.19587714f, 0.19559696f, 0.19531468f, + 0.19503031f, 0.19474386f, 0.19445531f, 0.19416469f, 0.19387199f, 0.19357720f, 0.19328035f, 0.19298143f, + 0.19268044f, 0.19237739f, 0.19207227f, 0.19176510f, 0.19145588f, 0.19114460f, 0.19083128f, 0.19051592f, + 0.19019851f, 0.18987907f, 0.18955759f, 0.18923409f, 0.18890856f, 0.18858100f, 0.18825143f, 0.18791983f, + 0.18758623f, 0.18725062f, 0.18691300f, 0.18657338f, 0.18623176f, 0.18588815f, 0.18554255f, 0.18519496f, + 0.18484539f, 0.18449384f, 0.18414031f, 0.18378481f, 0.18342734f, 0.18306791f, 0.18270651f, 0.18234316f, + 0.18197786f, 0.18161061f, 0.18124141f, 0.18087028f, 0.18049720f, 0.18012220f, 0.17974526f, 0.17936640f, + 0.17898562f, 0.17860292f, 0.17821831f, 0.17783179f, 0.17744336f, 0.17705304f, 0.17666082f, 0.17626671f, + 0.17587071f, 0.17547282f, 0.17507306f, 0.17467142f, 0.17426791f, 0.17386254f, 0.17345530f, 0.17304621f, + 0.17263526f, 0.17222246f, 0.17180782f, 0.17139134f, 0.17097303f, 0.17055288f, 0.17013091f, 0.16970711f, + 0.16928150f, 0.16885407f, 0.16842484f, 0.16799380f, 0.16756096f, 0.16712633f, 0.16668991f, 0.16625171f, + 0.16581172f, 0.16536996f, 0.16492642f, 0.16448113f, 0.16403406f, 0.16358525f, 0.16313468f, 0.16268236f, + 0.16222830f, 0.16177251f, 0.16131498f, 0.16085572f, 0.16039474f, 0.15993205f, 0.15946764f, 0.15900152f, + 0.15853370f, 0.15806419f, 0.15759298f, 0.15712008f, 0.15664550f, 0.15616924f, 0.15569131f, 0.15521171f, + 0.15473045f, 0.15424753f, 0.15376297f, 0.15327675f, 0.15278889f, 0.15229940f, 0.15180828f, 0.15131553f, + 0.15082115f, 0.15032517f, 0.14982757f, 0.14932837f, 0.14882757f, 0.14832518f, 0.14782120f, 0.14731564f, + 0.14680849f, 0.14629978f, 0.14578950f, 0.14527766f, 0.14476426f, 0.14424931f, 0.14373282f, 0.14321478f, + 0.14269522f, 0.14217412f, 0.14165151f, 0.14112737f, 0.14060173f, 0.14007458f, 0.13954592f, 0.13901578f, + 0.13848414f, 0.13795103f, 0.13741643f, 0.13688037f, 0.13634283f, 0.13580384f, 0.13526339f, 0.13472150f, + 0.13417816f, 0.13363339f, 0.13308718f, 0.13253955f, 0.13199050f, 0.13144003f, 0.13088816f, 0.13033489f, + 0.12978022f, 0.12922416f, 0.12866672f, 0.12810790f, 0.12754770f, 0.12698614f, 0.12642323f, 0.12585895f, + 0.12529333f, 0.12472637f, 0.12415807f, 0.12358845f, 0.12301749f, 0.12244523f, 0.12187165f, 0.12129676f, + 0.12072058f, 0.12014310f, 0.11956434f, 0.11898429f, 0.11840297f, 0.11782039f, 0.11723654f, 0.11665144f, + 0.11606508f, 0.11547749f, 0.11488866f, 0.11429859f, 0.11370731f, 0.11311480f, 0.11252109f, 0.11192617f, + 0.11133005f, 0.11073273f, 0.11013424f, 0.10953456f, 0.10893371f, 0.10833169f, 0.10772852f, 0.10712419f, + 0.10651871f, 0.10591209f, 0.10530434f, 0.10469546f, 0.10408546f, 0.10347434f, 0.10286212f, 0.10224879f, + 0.10163437f, 0.10101886f, 0.10040227f, 0.09978460f, 0.09916587f, 0.09854607f, 0.09792522f, 0.09730332f, + 0.09668037f, 0.09605639f, 0.09543139f, 0.09480536f, 0.09417831f, 0.09355026f, 0.09292121f, 0.09229116f, + 0.09166012f, 0.09102810f, 0.09039510f, 0.08976114f, 0.08912622f, 0.08849034f, 0.08785351f, 0.08721574f, + 0.08657704f, 0.08593742f, 0.08529687f, 0.08465540f, 0.08401304f, 0.08336977f, 0.08272561f, 0.08208056f, + 0.08143463f, 0.08078784f, 0.08014017f, 0.07949165f, 0.07884228f, 0.07819206f, 0.07754101f, 0.07688912f, + 0.07623641f, 0.07558289f, 0.07492855f, 0.07427342f, 0.07361748f, 0.07296076f, 0.07230326f, 0.07164499f, + 0.07098594f, 0.07032614f, 0.06966558f, 0.06900428f, 0.06834224f, 0.06767946f, 0.06701596f, 0.06635175f, + 0.06568682f, 0.06502119f, 0.06435487f, 0.06368785f, 0.06302015f, 0.06235178f, 0.06168274f, 0.06101304f, + 0.06034268f, 0.05967168f, 0.05900004f, 0.05832777f, 0.05765488f, 0.05698136f, 0.05630724f, 0.05563251f, + 0.05495719f, 0.05428128f, 0.05360479f, 0.05292772f, 0.05225009f, 0.05157189f, 0.05089315f, 0.05021386f, + 0.04953403f, 0.04885367f, 0.04817279f, 0.04749139f, 0.04680949f, 0.04612708f, 0.04544418f, 0.04476079f, + 0.04407692f, 0.04339258f, 0.04270778f, 0.04202252f, 0.04133681f, 0.04065065f, 0.03996406f, 0.03927704f, + 0.03858961f, 0.03790175f, 0.03721350f, 0.03652484f, 0.03583579f, 0.03514636f, 0.03445656f, 0.03376638f, + 0.03307584f, 0.03238495f, 0.03169371f, 0.03100213f, 0.03031022f, 0.02961799f, 0.02892544f, 0.02823258f, + 0.02753941f, 0.02684595f, 0.02615221f, 0.02545818f, 0.02476388f, 0.02406932f, 0.02337449f, 0.02267942f, + 0.02198411f, 0.02128856f, 0.02059278f, 0.01989678f, 0.01920056f, 0.01850415f, 0.01780753f, 0.01711072f, + 0.01641373f, 0.01571657f, 0.01501923f, 0.01432174f, 0.01362409f, 0.01292630f, 0.01222836f, 0.01153030f, + 0.01083211f, 0.01013381f, 0.00943540f, 0.00873688f, 0.00803828f, 0.00733959f, 0.00664081f, 0.00594197f, + 0.00524307f, 0.00454410f, 0.00384509f, 0.00314604f, 0.00244696f, 0.00174784f, 0.00104871f, 0.00034957f +}; + +const float edct_table_128[128] = +{ + 0.29728989f, 0.29724512f, 0.29715558f, 0.29702130f, 0.29684228f, 0.29661856f, 0.29635017f, 0.29603715f, + 0.29567955f, 0.29527743f, 0.29483083f, 0.29433983f, 0.29380451f, 0.29322494f, 0.29260121f, 0.29193342f, + 0.29122167f, 0.29046605f, 0.28966670f, 0.28882372f, 0.28793724f, 0.28700741f, 0.28603435f, 0.28501821f, + 0.28395915f, 0.28285733f, 0.28171292f, 0.28052607f, 0.27929698f, 0.27802583f, 0.27671281f, 0.27535812f, + 0.27396196f, 0.27252454f, 0.27104609f, 0.26952681f, 0.26796694f, 0.26636672f, 0.26472638f, 0.26304618f, + 0.26132636f, 0.25956719f, 0.25776893f, 0.25593185f, 0.25405623f, 0.25214235f, 0.25019049f, 0.24820096f, + 0.24617405f, 0.24411007f, 0.24200932f, 0.23987213f, 0.23769882f, 0.23548971f, 0.23324513f, 0.23096543f, + 0.22865095f, 0.22630203f, 0.22391903f, 0.22150231f, 0.21905224f, 0.21656917f, 0.21405349f, 0.21150558f, + 0.20892581f, 0.20631458f, 0.20367228f, 0.20099931f, 0.19829606f, 0.19556296f, 0.19280040f, 0.19000881f, + 0.18718860f, 0.18434021f, 0.18146405f, 0.17856057f, 0.17563019f, 0.17267337f, 0.16969054f, 0.16668215f, + 0.16364867f, 0.16059054f, 0.15750822f, 0.15440219f, 0.15127290f, 0.14812083f, 0.14494646f, 0.14175026f, + 0.13853271f, 0.13529429f, 0.13203551f, 0.12875684f, 0.12545877f, 0.12214182f, 0.11880647f, 0.11545323f, + 0.11208260f, 0.10869509f, 0.10529122f, 0.10187148f, 0.09843641f, 0.09498651f, 0.09152231f, 0.08804432f, + 0.08455308f, 0.08104910f, 0.07753291f, 0.07400505f, 0.07046605f, 0.06691643f, 0.06335674f, 0.05978750f, + 0.05620926f, 0.05262256f, 0.04902793f, 0.04542591f, 0.04181706f, 0.03820191f, 0.03458100f, 0.03095489f, + 0.02732412f, 0.02368923f, 0.02005077f, 0.01640930f, 0.01276535f, 0.00911948f, 0.00547224f, 0.00182417f +}; + +const float edct_table_160[160] = +{ + 0.28116346f, 0.28113637f, 0.28108217f, 0.28100088f, 0.28089251f, 0.28075707f, 0.28059457f, 0.28040502f, + 0.28018844f, 0.27994487f, 0.27967431f, 0.27937679f, 0.27905235f, 0.27870101f, 0.27832281f, 0.27791778f, + 0.27748597f, 0.27702741f, 0.27654216f, 0.27603024f, 0.27549173f, 0.27492666f, 0.27433510f, 0.27371709f, + 0.27307270f, 0.27240199f, 0.27170503f, 0.27098188f, 0.27023261f, 0.26945730f, 0.26865602f, 0.26782884f, + 0.26697585f, 0.26609713f, 0.26519276f, 0.26426283f, 0.26330743f, 0.26232665f, 0.26132059f, 0.26028934f, + 0.25923300f, 0.25815168f, 0.25704548f, 0.25591450f, 0.25475886f, 0.25357866f, 0.25237403f, 0.25114506f, + 0.24989190f, 0.24861465f, 0.24731343f, 0.24598838f, 0.24463962f, 0.24326728f, 0.24187150f, 0.24045240f, + 0.23901013f, 0.23754482f, 0.23605661f, 0.23454566f, 0.23301210f, 0.23145608f, 0.22987775f, 0.22827726f, + 0.22665478f, 0.22501045f, 0.22334443f, 0.22165688f, 0.21994797f, 0.21821787f, 0.21646673f, 0.21469472f, + 0.21290203f, 0.21108881f, 0.20925525f, 0.20740152f, 0.20552780f, 0.20363427f, 0.20172112f, 0.19978852f, + 0.19783667f, 0.19586574f, 0.19387594f, 0.19186746f, 0.18984048f, 0.18779520f, 0.18573183f, 0.18365055f, + 0.18155157f, 0.17943510f, 0.17730133f, 0.17515047f, 0.17298273f, 0.17079832f, 0.16859744f, 0.16638032f, + 0.16414716f, 0.16189818f, 0.15963359f, 0.15735362f, 0.15505848f, 0.15274840f, 0.15042360f, 0.14808429f, + 0.14573072f, 0.14336310f, 0.14098166f, 0.13858663f, 0.13617825f, 0.13375674f, 0.13132234f, 0.12887528f, + 0.12641580f, 0.12394414f, 0.12146053f, 0.11896521f, 0.11645843f, 0.11394042f, 0.11141144f, 0.10887171f, + 0.10632149f, 0.10376102f, 0.10119055f, 0.09861033f, 0.09602061f, 0.09342163f, 0.09081364f, 0.08819691f, + 0.08557167f, 0.08293818f, 0.08029671f, 0.07764749f, 0.07499079f, 0.07232686f, 0.06965596f, 0.06697834f, + 0.06429427f, 0.06160401f, 0.05890780f, 0.05620592f, 0.05349862f, 0.05078617f, 0.04806882f, 0.04534683f, + 0.04262048f, 0.03989002f, 0.03715571f, 0.03441782f, 0.03167662f, 0.02893236f, 0.02618532f, 0.02343575f, + 0.02068392f, 0.01793009f, 0.01517454f, 0.01241753f, 0.00965932f, 0.00690018f, 0.00414037f, 0.00138017f +}; + +const float edct_table_40[40] = +{ + 0.39747255f, 0.39685967f, 0.39563487f, 0.39380003f, 0.39135797f, 0.38831247f, 0.38466823f, 0.38043085f, + 0.37560687f, 0.37020373f, 0.36422977f, 0.35769419f, 0.35060707f, 0.34297935f, 0.33482277f, 0.32614992f, + 0.31697417f, 0.30730967f, 0.29717132f, 0.28657476f, 0.27553631f, 0.26407301f, 0.25220253f, 0.23994317f, + 0.22731383f, 0.21433400f, 0.20102367f, 0.18740339f, 0.17349414f, 0.15931737f, 0.14489495f, 0.13024911f, + 0.11540244f, 0.10037782f, 0.08519843f, 0.06988767f, 0.05446914f, 0.03896663f, 0.02340404f, 0.00780536f +}; + +const float edct_table_20[20] = +{ + 0.47209725f, 0.46918661f, 0.46338329f, 0.45472305f, 0.44325929f, 0.42906269f, 0.41222077f, 0.39283738f, + 0.37103202f, 0.34693912f, 0.32070722f, 0.29249806f, 0.26248555f, 0.23085473f, 0.19780061f, 0.16352698f, + 0.12824516f, 0.09217267f, 0.05553190f, 0.01854875f +}; + + +const float edct_table_64[64] = +{ + 0.35349683f, 0.35328389f, 0.35285816f, 0.35221987f, 0.35136942f, 0.35030732f, 0.34903420f, 0.34755084f, + 0.34585813f, 0.34395709f, 0.34184886f, 0.33953471f, 0.33701604f, 0.33429436f, 0.33137132f, 0.32824867f, + 0.32492830f, 0.32141220f, 0.31770249f, 0.31380142f, 0.30971132f, 0.30543466f, 0.30097402f, 0.29633209f, + 0.29151165f, 0.28651562f, 0.28134701f, 0.27600892f, 0.27050457f, 0.26483728f, 0.25901046f, 0.25302763f, + 0.24689238f, 0.24060841f, 0.23417951f, 0.22760955f, 0.22090248f, 0.21406235f, 0.20709328f, 0.19999946f, + 0.19278517f, 0.18545475f, 0.17801263f, 0.17046327f, 0.16281123f, 0.15506112f, 0.14721761f, 0.13928542f, + 0.13126933f, 0.12317417f, 0.11500482f, 0.10676618f, 0.09846324f, 0.09010099f, 0.08168446f, 0.07321873f, + 0.06470889f, 0.05616008f, 0.04757744f, 0.03896613f, 0.03033136f, 0.02167832f, 0.01301222f, 0.00433828f +}; + +const float edct_table_100[100] = +{ + 0.31620704f, 0.31612902f, 0.31597300f, 0.31573902f, 0.31542714f, 0.31503742f, 0.31456998f, 0.31402492f, + 0.31340238f, 0.31270252f, 0.31192550f, 0.31107151f, 0.31014078f, 0.30913352f, 0.30804998f, 0.30689044f, + 0.30565518f, 0.30434451f, 0.30295874f, 0.30149822f, 0.29996331f, 0.29835439f, 0.29667186f, 0.29491612f, + 0.29308762f, 0.29118680f, 0.28921414f, 0.28717012f, 0.28505525f, 0.28287004f, 0.28061503f, 0.27829079f, + 0.27589789f, 0.27343691f, 0.27090847f, 0.26831318f, 0.26565169f, 0.26292465f, 0.26013275f, 0.25727665f, + 0.25435708f, 0.25137475f, 0.24833040f, 0.24522478f, 0.24205865f, 0.23883279f, 0.23554801f, 0.23220511f, + 0.22880491f, 0.22534827f, 0.22183602f, 0.21826903f, 0.21464819f, 0.21097439f, 0.20724854f, 0.20347155f, + 0.19964436f, 0.19576790f, 0.19184315f, 0.18787106f, 0.18385261f, 0.17978880f, 0.17568064f, 0.17152912f, + 0.16733529f, 0.16310016f, 0.15882480f, 0.15451024f, 0.15015756f, 0.14576784f, 0.14134215f, 0.13688158f, + 0.13238724f, 0.12786023f, 0.12330168f, 0.11871271f, 0.11409444f, 0.10944803f, 0.10477460f, 0.10007533f, + 0.09535137f, 0.09060388f, 0.08583403f, 0.08104300f, 0.07623198f, 0.07140215f, 0.06655470f, 0.06169084f, + 0.05681175f, 0.05191864f, 0.04701272f, 0.04209520f, 0.03716730f, 0.03223022f, 0.02728520f, 0.02233344f, + 0.01737617f, 0.01241461f, 0.00744999f, 0.00248354f +}; + + +const float edct_table_200[200] = +{ + 0.26591044f, 0.26589403f, 0.26586123f, 0.26581203f, 0.26574643f, 0.26566443f, 0.26556605f, 0.26545129f, + 0.26532015f, 0.26517265f, 0.26500879f, 0.26482859f, 0.26463205f, 0.26441918f, 0.26419000f, 0.26394453f, + 0.26368278f, 0.26340476f, 0.26311049f, 0.26279999f, 0.26247328f, 0.26213038f, 0.26177132f, 0.26139610f, + 0.26100476f, 0.26059732f, 0.26017381f, 0.25973424f, 0.25927866f, 0.25880708f, 0.25831954f, 0.25781606f, + 0.25729668f, 0.25676143f, 0.25621034f, 0.25564344f, 0.25506078f, 0.25446238f, 0.25384829f, 0.25321854f, + 0.25257317f, 0.25191222f, 0.25123573f, 0.25054374f, 0.24983629f, 0.24911344f, 0.24837522f, 0.24762168f, + 0.24685286f, 0.24606882f, 0.24526960f, 0.24445525f, 0.24362582f, 0.24278136f, 0.24192193f, 0.24104757f, + 0.24015834f, 0.23925430f, 0.23833551f, 0.23740201f, 0.23645386f, 0.23549113f, 0.23451388f, 0.23352215f, + 0.23251603f, 0.23149556f, 0.23046081f, 0.22941185f, 0.22834873f, 0.22727153f, 0.22618031f, 0.22507514f, + 0.22395608f, 0.22282321f, 0.22167659f, 0.22051630f, 0.21934241f, 0.21815499f, 0.21695411f, 0.21573985f, + 0.21451228f, 0.21327148f, 0.21201752f, 0.21075048f, 0.20947045f, 0.20817749f, 0.20687169f, 0.20555313f, + 0.20422189f, 0.20287806f, 0.20152171f, 0.20015293f, 0.19877180f, 0.19737841f, 0.19597285f, 0.19455519f, + 0.19312554f, 0.19168397f, 0.19023058f, 0.18876546f, 0.18728869f, 0.18580037f, 0.18430058f, 0.18278943f, + 0.18126701f, 0.17973340f, 0.17818870f, 0.17663302f, 0.17506644f, 0.17348906f, 0.17190097f, 0.17030229f, + 0.16869310f, 0.16707350f, 0.16544360f, 0.16380349f, 0.16215328f, 0.16049306f, 0.15882295f, 0.15714304f, + 0.15545343f, 0.15375424f, 0.15204556f, 0.15032750f, 0.14860017f, 0.14686367f, 0.14511812f, 0.14336361f, + 0.14160026f, 0.13982818f, 0.13804747f, 0.13625824f, 0.13446061f, 0.13265468f, 0.13084058f, 0.12901840f, + 0.12718826f, 0.12535028f, 0.12350456f, 0.12165123f, 0.11979039f, 0.11792217f, 0.11604667f, 0.11416401f, + 0.11227431f, 0.11037768f, 0.10847425f, 0.10656412f, 0.10464742f, 0.10272426f, 0.10079477f, 0.09885906f, + 0.09691726f, 0.09496947f, 0.09301583f, 0.09105645f, 0.08909145f, 0.08712096f, 0.08514509f, 0.08316397f, + 0.08117772f, 0.07918646f, 0.07719032f, 0.07518942f, 0.07318388f, 0.07117382f, 0.06915937f, 0.06714066f, + 0.06511781f, 0.06309094f, 0.06106018f, 0.05902565f, 0.05698748f, 0.05494580f, 0.05290072f, 0.05085238f, + 0.04880091f, 0.04674643f, 0.04468906f, 0.04262893f, 0.04056618f, 0.03850092f, 0.03643329f, 0.03436341f, + 0.03229142f, 0.03021743f, 0.02814157f, 0.02606398f, 0.02398478f, 0.02190411f, 0.01982208f, 0.01773883f, + 0.01565448f, 0.01356917f, 0.01148302f, 0.00939617f, 0.00730873f, 0.00522084f, 0.00313264f, 0.00104423f +}; + +const float edct_table_240[240] = +{ + 0.25406349f, 0.25405260f, 0.25403084f, 0.25399819f, 0.25395466f, 0.25390025f, 0.25383497f, 0.25375881f, + 0.25367179f, 0.25357389f, 0.25346514f, 0.25334553f, 0.25321506f, 0.25307375f, 0.25292160f, 0.25275861f, + 0.25258479f, 0.25240016f, 0.25220471f, 0.25199846f, 0.25178142f, 0.25155358f, 0.25131498f, 0.25106561f, + 0.25080548f, 0.25053461f, 0.25025301f, 0.24996068f, 0.24965766f, 0.24934393f, 0.24901953f, 0.24868445f, + 0.24833873f, 0.24798236f, 0.24761538f, 0.24723778f, 0.24684960f, 0.24645084f, 0.24604153f, 0.24562167f, + 0.24519129f, 0.24475042f, 0.24429905f, 0.24383722f, 0.24336495f, 0.24288225f, 0.24238915f, 0.24188566f, + 0.24137181f, 0.24084762f, 0.24031312f, 0.23976832f, 0.23921325f, 0.23864793f, 0.23807239f, 0.23748665f, + 0.23689074f, 0.23628468f, 0.23566850f, 0.23504223f, 0.23440588f, 0.23375950f, 0.23310310f, 0.23243671f, + 0.23176037f, 0.23107410f, 0.23037794f, 0.22967190f, 0.22895603f, 0.22823035f, 0.22749489f, 0.22674968f, + 0.22599477f, 0.22523017f, 0.22445592f, 0.22367206f, 0.22287862f, 0.22207563f, 0.22126313f, 0.22044115f, + 0.21960972f, 0.21876889f, 0.21791869f, 0.21705915f, 0.21619032f, 0.21531222f, 0.21442490f, 0.21352839f, + 0.21262274f, 0.21170798f, 0.21078415f, 0.20985130f, 0.20890945f, 0.20795865f, 0.20699895f, 0.20603038f, + 0.20505298f, 0.20406680f, 0.20307188f, 0.20206825f, 0.20105598f, 0.20003509f, 0.19900563f, 0.19796764f, + 0.19692118f, 0.19586628f, 0.19480299f, 0.19373136f, 0.19265142f, 0.19156324f, 0.19046685f, 0.18936230f, + 0.18824963f, 0.18712891f, 0.18600017f, 0.18486346f, 0.18371883f, 0.18256633f, 0.18140601f, 0.18023792f, + 0.17906211f, 0.17787863f, 0.17668753f, 0.17548886f, 0.17428267f, 0.17306902f, 0.17184795f, 0.17061952f, + 0.16938379f, 0.16814079f, 0.16689060f, 0.16563326f, 0.16436882f, 0.16309734f, 0.16181887f, 0.16053347f, + 0.15924120f, 0.15794210f, 0.15663624f, 0.15532366f, 0.15400444f, 0.15267862f, 0.15134625f, 0.15000741f, + 0.14866213f, 0.14731049f, 0.14595254f, 0.14458834f, 0.14321795f, 0.14184141f, 0.14045881f, 0.13907018f, + 0.13767560f, 0.13627512f, 0.13486881f, 0.13345671f, 0.13203890f, 0.13061544f, 0.12918637f, 0.12775178f, + 0.12631171f, 0.12486623f, 0.12341540f, 0.12195929f, 0.12049795f, 0.11903145f, 0.11755985f, 0.11608321f, + 0.11460161f, 0.11311509f, 0.11162373f, 0.11012758f, 0.10862672f, 0.10712120f, 0.10561110f, 0.10409647f, + 0.10257739f, 0.10105391f, 0.09952610f, 0.09799402f, 0.09645775f, 0.09491735f, 0.09337288f, 0.09182441f, + 0.09027201f, 0.08871574f, 0.08715567f, 0.08559187f, 0.08402440f, 0.08245333f, 0.08087873f, 0.07930067f, + 0.07771920f, 0.07613441f, 0.07454636f, 0.07295511f, 0.07136074f, 0.06976332f, 0.06816290f, 0.06655956f, + 0.06495338f, 0.06334441f, 0.06173272f, 0.06011839f, 0.05850149f, 0.05688208f, 0.05526024f, 0.05363602f, + 0.05200951f, 0.05038078f, 0.04874988f, 0.04711689f, 0.04548189f, 0.04384494f, 0.04220611f, 0.04056547f, + 0.03892310f, 0.03727906f, 0.03563342f, 0.03398625f, 0.03233763f, 0.03068762f, 0.02903630f, 0.02738373f, + 0.02573000f, 0.02407516f, 0.02241928f, 0.02076245f, 0.01910473f, 0.01744619f, 0.01578690f, 0.01412694f, + 0.01246637f, 0.01080527f, 0.00914370f, 0.00748175f, 0.00581947f, 0.00415694f, 0.00249424f, 0.00083142f +}; + +const float edct_table_256[256] = +{ + 0.24999750f, 0.24998809f, 0.24996926f, 0.24994103f, 0.24990338f, 0.24985633f, 0.24979987f, 0.24973400f, + 0.24965873f, 0.24957406f, 0.24948000f, 0.24937654f, 0.24926370f, 0.24914147f, 0.24900986f, 0.24886887f, + 0.24871852f, 0.24855880f, 0.24838972f, 0.24821129f, 0.24802352f, 0.24782640f, 0.24761996f, 0.24740419f, + 0.24717911f, 0.24694473f, 0.24670104f, 0.24644807f, 0.24618582f, 0.24591430f, 0.24563353f, 0.24534350f, + 0.24504424f, 0.24473575f, 0.24441805f, 0.24409114f, 0.24375505f, 0.24340977f, 0.24305534f, 0.24269175f, + 0.24231903f, 0.24193718f, 0.24154622f, 0.24114617f, 0.24073704f, 0.24031885f, 0.23989161f, 0.23945534f, + 0.23901005f, 0.23855576f, 0.23809249f, 0.23762026f, 0.23713908f, 0.23664898f, 0.23614996f, 0.23564205f, + 0.23512527f, 0.23459964f, 0.23406518f, 0.23352190f, 0.23296983f, 0.23240899f, 0.23183940f, 0.23126109f, + 0.23067406f, 0.23007835f, 0.22947398f, 0.22886097f, 0.22823934f, 0.22760912f, 0.22697033f, 0.22632299f, + 0.22566713f, 0.22500278f, 0.22432996f, 0.22364869f, 0.22295900f, 0.22226091f, 0.22155446f, 0.22083967f, + 0.22011656f, 0.21938516f, 0.21864551f, 0.21789762f, 0.21714153f, 0.21637726f, 0.21560485f, 0.21482432f, + 0.21403570f, 0.21323902f, 0.21243432f, 0.21162161f, 0.21080094f, 0.20997234f, 0.20913582f, 0.20829144f, + 0.20743921f, 0.20657917f, 0.20571136f, 0.20483580f, 0.20395252f, 0.20306157f, 0.20216298f, 0.20125677f, + 0.20034298f, 0.19942165f, 0.19849282f, 0.19755651f, 0.19661276f, 0.19566161f, 0.19470310f, 0.19373725f, + 0.19276411f, 0.19178371f, 0.19079609f, 0.18980129f, 0.18879934f, 0.18779029f, 0.18677416f, 0.18575100f, + 0.18472085f, 0.18368375f, 0.18263973f, 0.18158883f, 0.18053109f, 0.17946656f, 0.17839527f, 0.17731727f, + 0.17623259f, 0.17514127f, 0.17404336f, 0.17293890f, 0.17182793f, 0.17071048f, 0.16958661f, 0.16845636f, + 0.16731976f, 0.16617686f, 0.16502771f, 0.16387235f, 0.16271081f, 0.16154315f, 0.16036940f, 0.15918962f, + 0.15800385f, 0.15681212f, 0.15561450f, 0.15441101f, 0.15320171f, 0.15198664f, 0.15076585f, 0.14953939f, + 0.14830729f, 0.14706961f, 0.14582639f, 0.14457768f, 0.14332353f, 0.14206399f, 0.14079909f, 0.13952889f, + 0.13825344f, 0.13697279f, 0.13568698f, 0.13439606f, 0.13310008f, 0.13179909f, 0.13049313f, 0.12918227f, + 0.12786654f, 0.12654599f, 0.12522068f, 0.12389066f, 0.12255597f, 0.12121667f, 0.11987280f, 0.11852443f, + 0.11717159f, 0.11581433f, 0.11445272f, 0.11308680f, 0.11171662f, 0.11034223f, 0.10896369f, 0.10758105f, + 0.10619436f, 0.10480367f, 0.10340903f, 0.10201050f, 0.10060813f, 0.09920197f, 0.09779208f, 0.09637850f, + 0.09496130f, 0.09354052f, 0.09211622f, 0.09068845f, 0.08925727f, 0.08782272f, 0.08638487f, 0.08494377f, + 0.08349947f, 0.08205203f, 0.08060149f, 0.07914792f, 0.07769138f, 0.07623190f, 0.07476956f, 0.07330440f, + 0.07183648f, 0.07036586f, 0.06889259f, 0.06741672f, 0.06593832f, 0.06445743f, 0.06297412f, 0.06148844f, + 0.06000044f, 0.05851018f, 0.05701772f, 0.05552311f, 0.05402641f, 0.05252768f, 0.05102697f, 0.04952434f, + 0.04801985f, 0.04651354f, 0.04500549f, 0.04349574f, 0.04198435f, 0.04047138f, 0.03895689f, 0.03744094f, + 0.03592357f, 0.03440485f, 0.03288483f, 0.03136358f, 0.02984115f, 0.02831759f, 0.02679296f, 0.02526733f, + 0.02374075f, 0.02221327f, 0.02068496f, 0.01915586f, 0.01762605f, 0.01609557f, 0.01456449f, 0.01303286f, + 0.01150073f, 0.00996818f, 0.00843525f, 0.00690200f, 0.00536849f, 0.00383478f, 0.00230093f, 0.00076699f +}; + +const float edct_table_400[400] = +{ + 0.22360588f, 0.22360243f, 0.22359554f, 0.22358519f, 0.22357140f, 0.22355416f, 0.22353347f, 0.22350934f, + 0.22348175f, 0.22345073f, 0.22341625f, 0.22337833f, 0.22333697f, 0.22329216f, 0.22324391f, 0.22319221f, + 0.22313708f, 0.22307850f, 0.22301648f, 0.22295103f, 0.22288213f, 0.22280980f, 0.22273403f, 0.22265483f, + 0.22257219f, 0.22248612f, 0.22239662f, 0.22230369f, 0.22220734f, 0.22210755f, 0.22200434f, 0.22189771f, + 0.22178765f, 0.22167418f, 0.22155728f, 0.22143697f, 0.22131325f, 0.22118611f, 0.22105556f, 0.22092160f, + 0.22078424f, 0.22064347f, 0.22049930f, 0.22035172f, 0.22020075f, 0.22004639f, 0.21988863f, 0.21972748f, + 0.21956294f, 0.21939501f, 0.21922370f, 0.21904901f, 0.21887095f, 0.21868950f, 0.21850469f, 0.21831650f, + 0.21812495f, 0.21793004f, 0.21773176f, 0.21753013f, 0.21732514f, 0.21711680f, 0.21690511f, 0.21669008f, + 0.21647170f, 0.21624999f, 0.21602494f, 0.21579656f, 0.21556486f, 0.21532983f, 0.21509147f, 0.21484981f, + 0.21460482f, 0.21435653f, 0.21410494f, 0.21385004f, 0.21359184f, 0.21333035f, 0.21306557f, 0.21279750f, + 0.21252616f, 0.21225153f, 0.21197363f, 0.21169247f, 0.21140803f, 0.21112034f, 0.21082939f, 0.21053520f, + 0.21023775f, 0.20993706f, 0.20963314f, 0.20932598f, 0.20901559f, 0.20870198f, 0.20838516f, 0.20806511f, + 0.20774186f, 0.20741541f, 0.20708576f, 0.20675291f, 0.20641688f, 0.20607766f, 0.20573527f, 0.20538970f, + 0.20504096f, 0.20468907f, 0.20433401f, 0.20397581f, 0.20361446f, 0.20324997f, 0.20288234f, 0.20251159f, + 0.20213771f, 0.20176072f, 0.20138061f, 0.20099740f, 0.20061109f, 0.20022169f, 0.19982920f, 0.19943362f, + 0.19903497f, 0.19863326f, 0.19822847f, 0.19782064f, 0.19740975f, 0.19699581f, 0.19657884f, 0.19615884f, + 0.19573581f, 0.19530977f, 0.19488071f, 0.19444865f, 0.19401358f, 0.19357553f, 0.19313449f, 0.19269047f, + 0.19224348f, 0.19179353f, 0.19134062f, 0.19088476f, 0.19042595f, 0.18996421f, 0.18949954f, 0.18903194f, + 0.18856143f, 0.18808802f, 0.18761170f, 0.18713249f, 0.18665039f, 0.18616542f, 0.18567757f, 0.18518686f, + 0.18469330f, 0.18419688f, 0.18369763f, 0.18319554f, 0.18269063f, 0.18218290f, 0.18167236f, 0.18115902f, + 0.18064289f, 0.18012397f, 0.17960227f, 0.17907781f, 0.17855058f, 0.17802060f, 0.17748787f, 0.17695240f, + 0.17641421f, 0.17587330f, 0.17532967f, 0.17478334f, 0.17423432f, 0.17368260f, 0.17312821f, 0.17257115f, + 0.17201143f, 0.17144906f, 0.17088404f, 0.17031639f, 0.16974611f, 0.16917321f, 0.16859770f, 0.16801960f, + 0.16743890f, 0.16685562f, 0.16626977f, 0.16568135f, 0.16509038f, 0.16449686f, 0.16390080f, 0.16330222f, + 0.16270112f, 0.16209751f, 0.16149140f, 0.16088280f, 0.16027172f, 0.15965817f, 0.15904216f, 0.15842369f, + 0.15780278f, 0.15717944f, 0.15655367f, 0.15592549f, 0.15529490f, 0.15466192f, 0.15402655f, 0.15338881f, + 0.15274870f, 0.15210624f, 0.15146143f, 0.15081429f, 0.15016482f, 0.14951304f, 0.14885894f, 0.14820256f, + 0.14754389f, 0.14688294f, 0.14621973f, 0.14555426f, 0.14488655f, 0.14421660f, 0.14354443f, 0.14287005f, + 0.14219346f, 0.14151468f, 0.14083372f, 0.14015058f, 0.13946529f, 0.13877784f, 0.13808825f, 0.13739654f, + 0.13670270f, 0.13600676f, 0.13530872f, 0.13460859f, 0.13390639f, 0.13320212f, 0.13249580f, 0.13178744f, + 0.13107704f, 0.13036462f, 0.12965019f, 0.12893376f, 0.12821535f, 0.12749495f, 0.12677259f, 0.12604828f, + 0.12532202f, 0.12459383f, 0.12386371f, 0.12313169f, 0.12239777f, 0.12166196f, 0.12092427f, 0.12018472f, + 0.11944332f, 0.11870007f, 0.11795500f, 0.11720810f, 0.11645940f, 0.11570890f, 0.11495662f, 0.11420256f, + 0.11344675f, 0.11268918f, 0.11192987f, 0.11116884f, 0.11040610f, 0.10964165f, 0.10887551f, 0.10810770f, + 0.10733821f, 0.10656707f, 0.10579429f, 0.10501988f, 0.10424384f, 0.10346620f, 0.10268696f, 0.10190614f, + 0.10112375f, 0.10033980f, 0.09955430f, 0.09876726f, 0.09797871f, 0.09718864f, 0.09639707f, 0.09560402f, + 0.09480949f, 0.09401350f, 0.09321606f, 0.09241718f, 0.09161688f, 0.09081516f, 0.09001205f, 0.08920754f, + 0.08840166f, 0.08759442f, 0.08678583f, 0.08597589f, 0.08516464f, 0.08435207f, 0.08353819f, 0.08272303f, + 0.08190660f, 0.08108890f, 0.08026995f, 0.07944976f, 0.07862835f, 0.07780572f, 0.07698190f, 0.07615688f, + 0.07533070f, 0.07450335f, 0.07367485f, 0.07284522f, 0.07201446f, 0.07118259f, 0.07034963f, 0.06951558f, + 0.06868046f, 0.06784427f, 0.06700705f, 0.06616879f, 0.06532951f, 0.06448922f, 0.06364793f, 0.06280567f, + 0.06196244f, 0.06111825f, 0.06027312f, 0.05942705f, 0.05858008f, 0.05773220f, 0.05688343f, 0.05603378f, + 0.05518327f, 0.05433190f, 0.05347970f, 0.05262667f, 0.05177284f, 0.05091820f, 0.05006278f, 0.04920659f, + 0.04834964f, 0.04749194f, 0.04663351f, 0.04577436f, 0.04491450f, 0.04405396f, 0.04319273f, 0.04233084f, + 0.04146829f, 0.04060511f, 0.03974129f, 0.03887687f, 0.03801185f, 0.03714624f, 0.03628005f, 0.03541331f, + 0.03454602f, 0.03367820f, 0.03280986f, 0.03194101f, 0.03107167f, 0.03020186f, 0.02933157f, 0.02846084f, + 0.02758966f, 0.02671806f, 0.02584605f, 0.02497364f, 0.02410084f, 0.02322767f, 0.02235414f, 0.02148027f, + 0.02060607f, 0.01973155f, 0.01885673f, 0.01798161f, 0.01710622f, 0.01623056f, 0.01535466f, 0.01447851f, + 0.01360215f, 0.01272557f, 0.01184880f, 0.01097184f, 0.01009472f, 0.00921744f, 0.00834001f, 0.00746246f, + 0.00658480f, 0.00570703f, 0.00482917f, 0.00395124f, 0.00307325f, 0.00219521f, 0.00131714f, 0.00043905f +}; + +const float edct_table_600[600] = +{ + 0.20205118f, 0.20204980f, 0.20204703f, 0.20204287f, 0.20203734f, 0.20203041f, 0.20202210f, 0.20201241f, + 0.20200133f, 0.20198887f, 0.20197502f, 0.20195979f, 0.20194318f, 0.20192518f, 0.20190579f, 0.20188503f, + 0.20186288f, 0.20183934f, 0.20181442f, 0.20178812f, 0.20176044f, 0.20173137f, 0.20170092f, 0.20166909f, + 0.20163587f, 0.20160128f, 0.20156530f, 0.20152794f, 0.20148920f, 0.20144908f, 0.20140758f, 0.20136469f, + 0.20132043f, 0.20127479f, 0.20122777f, 0.20117936f, 0.20112958f, 0.20107842f, 0.20102589f, 0.20097197f, + 0.20091668f, 0.20086001f, 0.20080196f, 0.20074254f, 0.20068174f, 0.20061957f, 0.20055602f, 0.20049110f, + 0.20042480f, 0.20035713f, 0.20028809f, 0.20021767f, 0.20014588f, 0.20007272f, 0.19999819f, 0.19992228f, + 0.19984501f, 0.19976637f, 0.19968635f, 0.19960497f, 0.19952222f, 0.19943811f, 0.19935262f, 0.19926577f, + 0.19917756f, 0.19908798f, 0.19899703f, 0.19890472f, 0.19881105f, 0.19871602f, 0.19861962f, 0.19852186f, + 0.19842274f, 0.19832226f, 0.19822043f, 0.19811723f, 0.19801267f, 0.19790676f, 0.19779949f, 0.19769087f, + 0.19758089f, 0.19746956f, 0.19735687f, 0.19724283f, 0.19712744f, 0.19701070f, 0.19689261f, 0.19677317f, + 0.19665237f, 0.19653024f, 0.19640675f, 0.19628192f, 0.19615574f, 0.19602822f, 0.19589936f, 0.19576915f, + 0.19563760f, 0.19550471f, 0.19537048f, 0.19523491f, 0.19509800f, 0.19495976f, 0.19482018f, 0.19467926f, + 0.19453701f, 0.19439343f, 0.19424851f, 0.19410226f, 0.19395469f, 0.19380578f, 0.19365554f, 0.19350398f, + 0.19335109f, 0.19319688f, 0.19304134f, 0.19288448f, 0.19272630f, 0.19256679f, 0.19240597f, 0.19224383f, + 0.19208036f, 0.19191559f, 0.19174950f, 0.19158209f, 0.19141337f, 0.19124334f, 0.19107200f, 0.19089934f, + 0.19072538f, 0.19055012f, 0.19037354f, 0.19019566f, 0.19001648f, 0.18983600f, 0.18965421f, 0.18947113f, + 0.18928674f, 0.18910106f, 0.18891409f, 0.18872581f, 0.18853625f, 0.18834539f, 0.18815324f, 0.18795980f, + 0.18776508f, 0.18756906f, 0.18737176f, 0.18717318f, 0.18697331f, 0.18677217f, 0.18656974f, 0.18636603f, + 0.18616105f, 0.18595479f, 0.18574726f, 0.18553845f, 0.18532837f, 0.18511702f, 0.18490440f, 0.18469052f, + 0.18447537f, 0.18425895f, 0.18404127f, 0.18382233f, 0.18360213f, 0.18338067f, 0.18315796f, 0.18293399f, + 0.18270877f, 0.18248229f, 0.18225456f, 0.18202559f, 0.18179536f, 0.18156389f, 0.18133118f, 0.18109722f, + 0.18086202f, 0.18062558f, 0.18038791f, 0.18014900f, 0.17990885f, 0.17966747f, 0.17942486f, 0.17918102f, + 0.17893595f, 0.17868965f, 0.17844213f, 0.17819339f, 0.17794342f, 0.17769224f, 0.17743984f, 0.17718622f, + 0.17693139f, 0.17667534f, 0.17641808f, 0.17615962f, 0.17589995f, 0.17563907f, 0.17537698f, 0.17511370f, + 0.17484922f, 0.17458353f, 0.17431665f, 0.17404858f, 0.17377931f, 0.17350885f, 0.17323721f, 0.17296437f, + 0.17269035f, 0.17241515f, 0.17213876f, 0.17186120f, 0.17158245f, 0.17130253f, 0.17102144f, 0.17073917f, + 0.17045574f, 0.17017113f, 0.16988536f, 0.16959843f, 0.16931033f, 0.16902107f, 0.16873066f, 0.16843909f, + 0.16814636f, 0.16785248f, 0.16755745f, 0.16726127f, 0.16696395f, 0.16666548f, 0.16636587f, 0.16606511f, + 0.16576322f, 0.16546020f, 0.16515604f, 0.16485075f, 0.16454433f, 0.16423678f, 0.16392810f, 0.16361830f, + 0.16330738f, 0.16299534f, 0.16268219f, 0.16236791f, 0.16205253f, 0.16173603f, 0.16141843f, 0.16109972f, + 0.16077991f, 0.16045899f, 0.16013697f, 0.15981386f, 0.15948965f, 0.15916435f, 0.15883796f, 0.15851047f, + 0.15818191f, 0.15785225f, 0.15752152f, 0.15718971f, 0.15685682f, 0.15652285f, 0.15618781f, 0.15585170f, + 0.15551452f, 0.15517628f, 0.15483697f, 0.15449661f, 0.15415518f, 0.15381269f, 0.15346916f, 0.15312457f, + 0.15277893f, 0.15243224f, 0.15208451f, 0.15173574f, 0.15138592f, 0.15103507f, 0.15068319f, 0.15033027f, + 0.14997632f, 0.14962134f, 0.14926534f, 0.14890831f, 0.14855026f, 0.14819120f, 0.14783112f, 0.14747003f, + 0.14710792f, 0.14674481f, 0.14638069f, 0.14601557f, 0.14564945f, 0.14528233f, 0.14491421f, 0.14454510f, + 0.14417500f, 0.14380391f, 0.14343184f, 0.14305878f, 0.14268474f, 0.14230973f, 0.14193374f, 0.14155677f, + 0.14117884f, 0.14079994f, 0.14042007f, 0.14003924f, 0.13965745f, 0.13927471f, 0.13889101f, 0.13850635f, + 0.13812075f, 0.13773420f, 0.13734671f, 0.13695828f, 0.13656890f, 0.13617860f, 0.13578735f, 0.13539518f, + 0.13500208f, 0.13460805f, 0.13421311f, 0.13381724f, 0.13342045f, 0.13302275f, 0.13262414f, 0.13222462f, + 0.13182419f, 0.13142286f, 0.13102063f, 0.13061750f, 0.13021348f, 0.12980856f, 0.12940275f, 0.12899606f, + 0.12858848f, 0.12818002f, 0.12777069f, 0.12736047f, 0.12694939f, 0.12653743f, 0.12612461f, 0.12571092f, + 0.12529637f, 0.12488096f, 0.12446470f, 0.12404758f, 0.12362961f, 0.12321080f, 0.12279114f, 0.12237064f, + 0.12194930f, 0.12152712f, 0.12110411f, 0.12068027f, 0.12025561f, 0.11983012f, 0.11940381f, 0.11897668f, + 0.11854873f, 0.11811998f, 0.11769041f, 0.11726004f, 0.11682886f, 0.11639688f, 0.11596410f, 0.11553053f, + 0.11509617f, 0.11466102f, 0.11422508f, 0.11378836f, 0.11335086f, 0.11291258f, 0.11247353f, 0.11203371f, + 0.11159312f, 0.11115177f, 0.11070965f, 0.11026678f, 0.10982315f, 0.10937876f, 0.10893363f, 0.10848775f, + 0.10804113f, 0.10759376f, 0.10714566f, 0.10669683f, 0.10624726f, 0.10579696f, 0.10534594f, 0.10489420f, + 0.10444174f, 0.10398856f, 0.10353467f, 0.10308007f, 0.10262477f, 0.10216876f, 0.10171205f, 0.10125464f, + 0.10079654f, 0.10033775f, 0.09987827f, 0.09941811f, 0.09895726f, 0.09849574f, 0.09803354f, 0.09757067f, + 0.09710713f, 0.09664293f, 0.09617806f, 0.09571253f, 0.09524635f, 0.09477952f, 0.09431203f, 0.09384390f, + 0.09337513f, 0.09290571f, 0.09243566f, 0.09196498f, 0.09149366f, 0.09102172f, 0.09054915f, 0.09007597f, + 0.08960216f, 0.08912774f, 0.08865272f, 0.08817708f, 0.08770084f, 0.08722400f, 0.08674656f, 0.08626852f, + 0.08578990f, 0.08531068f, 0.08483089f, 0.08435051f, 0.08386955f, 0.08338802f, 0.08290591f, 0.08242324f, + 0.08194000f, 0.08145620f, 0.08097185f, 0.08048693f, 0.08000147f, 0.07951546f, 0.07902890f, 0.07854180f, + 0.07805416f, 0.07756599f, 0.07707729f, 0.07658806f, 0.07609830f, 0.07560802f, 0.07511722f, 0.07462591f, + 0.07413409f, 0.07364176f, 0.07314892f, 0.07265559f, 0.07216175f, 0.07166742f, 0.07117260f, 0.07067729f, + 0.07018150f, 0.06968522f, 0.06918847f, 0.06869125f, 0.06819355f, 0.06769539f, 0.06719676f, 0.06669767f, + 0.06619812f, 0.06569812f, 0.06519767f, 0.06469678f, 0.06419544f, 0.06369366f, 0.06319144f, 0.06268879f, + 0.06218571f, 0.06168220f, 0.06117828f, 0.06067393f, 0.06016916f, 0.05966399f, 0.05915840f, 0.05865241f, + 0.05814602f, 0.05763923f, 0.05713204f, 0.05662447f, 0.05611650f, 0.05560815f, 0.05509942f, 0.05459031f, + 0.05408083f, 0.05357097f, 0.05306075f, 0.05255017f, 0.05203922f, 0.05152792f, 0.05101627f, 0.05050426f, + 0.04999191f, 0.04947922f, 0.04896619f, 0.04845282f, 0.04793912f, 0.04742509f, 0.04691074f, 0.04639606f, + 0.04588107f, 0.04536576f, 0.04485014f, 0.04433422f, 0.04381799f, 0.04330146f, 0.04278463f, 0.04226751f, + 0.04175010f, 0.04123240f, 0.04071442f, 0.04019617f, 0.03967763f, 0.03915883f, 0.03863975f, 0.03812042f, + 0.03760082f, 0.03708096f, 0.03656085f, 0.03604049f, 0.03551988f, 0.03499902f, 0.03447793f, 0.03395660f, + 0.03343504f, 0.03291325f, 0.03239124f, 0.03186900f, 0.03134654f, 0.03082387f, 0.03030099f, 0.02977790f, + 0.02925460f, 0.02873111f, 0.02820741f, 0.02768353f, 0.02715945f, 0.02663519f, 0.02611075f, 0.02558613f, + 0.02506133f, 0.02453636f, 0.02401122f, 0.02348592f, 0.02296046f, 0.02243483f, 0.02190906f, 0.02138314f, + 0.02085706f, 0.02033085f, 0.01980450f, 0.01927801f, 0.01875139f, 0.01822464f, 0.01769776f, 0.01717076f, + 0.01664365f, 0.01611642f, 0.01558908f, 0.01506164f, 0.01453409f, 0.01400644f, 0.01347870f, 0.01295086f, + 0.01242294f, 0.01189493f, 0.01136683f, 0.01083866f, 0.01031042f, 0.00978211f, 0.00925372f, 0.00872528f, + 0.00819677f, 0.00766821f, 0.00713960f, 0.00661094f, 0.00608223f, 0.00555348f, 0.00502469f, 0.00449587f, + 0.00396701f, 0.00343813f, 0.00290923f, 0.00238031f, 0.00185137f, 0.00132241f, 0.00079345f, 0.00026448f +}; + +/*----------------------------------------------------------------------------------* + * Mean ISF vector for active signal (only for AMR-WB IO mode) + *----------------------------------------------------------------------------------*/ + +const float mean_isf_amr_wb[M] = +{ + 288.411774f, + 518.149414f, + 912.352051f, + 1397.743652f, + 1795.418823f, + 2211.536133f, + 2621.461182f, + 3019.680176f, + 3417.989746f, + 3809.700928f, + 4181.547363f, + 4581.064941f, + 5012.819824f, + 5457.521484f, + 5876.145020f, + 1576.906494f +}; + +/*----------------------------------------------------------------------------------* + * Mean ISF vector for SID frames (only in AMR-WB IO mode) + *----------------------------------------------------------------------------------*/ + +const float mean_isf_noise_amr_wb[M] = +{ + 186.625259f, + 429.613403f, + 864.525085f, + 1276.010254f, + 1648.228394f, + 2039.998535f, + 2420.943115f, + 2828.022461f, + 3214.584961f, + 3575.200195f, + 3944.685303f, + 4338.971191f, + 4743.657227f, + 5149.993164f, + 5533.081055f, + 1485.457031f +}; + +/*----------------------------------------------------------------------------------* + * Initial LSF memory + *----------------------------------------------------------------------------------*/ + +const float lsf_init[16] = +{ + 375.0, 750.0, 1125.0, 1500.0, 1875.0, 2250.0, 2625.0, 3000.0, + 3375.0, 3750.0, 4125.0, 4500.0, 4875.0, 5250.0, 5625.0, 6000.0 +}; + + +/*----------------------------------------------------------------------------------* + * Gaussian codebook + *----------------------------------------------------------------------------------*/ + +const float gaus_dico[190] = +{ + -0.0973f, -0.0306f, 0.1278f, -0.1138f, 0.0744f, -0.1606f, + -0.1976f, 0.0115f, -0.0344f, -0.0417f, -0.1424f, -0.0633f, + 0.0723f, 0.3257f, -0.0697f, -0.0978f, -0.1168f, -0.1021f, + 0.0342f, -0.1319f, 0.0431f, -0.2658f, 0.0317f, -0.0712f, + 0.0348f, 0.1200f, -0.0758f, -0.2104f, -0.0781f, 0.0947f, + 0.1333f, 0.0204f, -0.2934f, 0.0262f, 0.0264f, 0.0830f, + 0.0584f, -0.0318f, 0.2271f, 0.0835f, 0.0374f, -0.0645f, + -0.1864f, -0.0277f, 0.0945f, -0.1306f, 0.0202f, -0.2090f, + -0.0881f, -0.1029f, 0.0292f, 0.0966f, -0.0896f, 0.1563f, + 0.1994f, 0.0543f, -0.2482f, -0.0201f, -0.0294f, 0.2172f, + 0.0830f, -0.0938f, 0.0115f, 0.0827f, -0.1233f, -0.1051f, + 0.0394f, 0.2390f, 0.2172f, -0.0653f, 0.0253f, 0.1241f, + -0.0366f, -0.0473f, 0.1080f, 0.0470f, 0.1009f, -0.0059f, + 0.0964f, -0.0105f, -0.0531f, 0.0169f, -0.0972f, 0.0408f, + 0.0283f, -0.2285f, -0.0232f, 0.3580f, -0.1063f, 0.1125f, + 0.2105f, -0.0331f, -0.0230f, 0.3200f, -0.0905f, 0.0166f, + 0.0328f, -0.0722f, -0.0380f, -0.1377f, -0.0118f, -0.1189f, + 0.1580f, 0.0769f, 0.1252f, -0.0247f, -0.1672f, -0.0777f, + -0.0841f, -0.1573f, -0.0160f, 0.2078f, 0.1011f, -0.0070f, + 0.1242f, 0.1011f, 0.1225f, 0.0973f, 0.1361f, 0.1584f, + -0.0729f, 0.1831f, 0.1332f, -0.1846f, -0.0029f, -0.0890f, + 0.1447f, -0.1727f, 0.0963f, -0.0321f, -0.0916f, -0.0151f, + -0.2232f, -0.0624f, -0.1036f, 0.0157f, 0.1134f, -0.2782f, + 0.0684f, 0.0222f, -0.0202f, -0.0704f, -0.1342f, 0.0950f, + 0.0128f, -0.2999f, 0.0015f, -0.1051f, 0.0180f, 0.0500f, + -0.1166f, -0.0361f, -0.1446f, 0.0688f, -0.0179f, 0.2959f, + 0.0102f, 0.1416f, -0.0815f, 0.1181f, -0.1867f, 0.1082f, + 0.1585f, 0.0661f, -0.1805f, 0.0915f, 0.1497f, -0.1124f, + -0.0508f, 0.0573f, -0.0294f, -0.0119f, -0.0759f, 0.1477f, + 0.2136f, 0.1271f, 0.0492f, -0.1235f, -0.1337f, -0.2657f, + -0.0106f, -0.0540f, 0.1642f, -0.0598f, -0.0065f, 0.1146f, + 0.0863f, 0.0129f, 0.1816f, 0.0672f +}; + +const float gaus_dico_swb[256] = +{ + 0.02164473f, 0.35885197f, -0.16274954f, -0.08241354f, 0.07313631f, -0.00054929f, -0.13080014f, 0.07226136f, + -0.13965981f, -0.04834007f, -0.02745908f, -0.02867859f, 0.11216793f, 0.16604294f, -0.00134274f, 0.06818508f, + -0.17387933f, 0.09406016f, -0.08150196f, 0.05083200f, -0.01952806f, -0.10203217f, -0.03067050f, -0.05153965f, + 0.06250680f, 0.00859049f, -0.12008808f, -0.11361376f, 0.17176038f, 0.01174004f, -0.02275130f, -0.09895785f, + -0.10167463f, -0.22059087f, -0.05334539f, -0.00629700f, -0.16706355f, 0.07795000f, 0.08731710f, 0.09669208f, + 0.15378080f, 0.01794813f, -0.01549965f, -0.24923822f, 0.19985947f, -0.10477958f, 0.06674605f, -0.11186616f, + -0.17927034f, 0.08443811f, 0.25542912f, 0.03167623f, 0.19633667f, 0.19163096f, 0.01907267f, 0.12298489f, + -0.03147158f, 0.05562247f, 0.30200079f, -0.04257871f, 0.08275045f, -0.03386311f, -0.02265750f, 0.18742503f, + -0.13598505f, -0.32004824f, -0.00438390f, -0.15576170f, 0.06006401f, -0.00952147f, 0.18848655f, 0.06630960f, + 0.07121546f, -0.00733249f, 0.08277771f, 0.22764891f, 0.06772452f, -0.09509693f, -0.00172236f, 0.08452052f, + 0.17020901f, -0.03737585f, 0.02349647f, 0.10855560f, 0.06854416f, 0.07084806f, 0.09390105f, 0.00124924f, + 0.03026483f, -0.15169589f, 0.01347072f, -0.15377805f, 0.14992996f, 0.11630810f, 0.03483583f, -0.03914850f, + -0.20075595f, 0.12728901f, -0.04495851f, -0.11576717f, -0.15281813f, 0.06055827f, -0.03471978f, -0.03617816f, + 0.17230885f, 0.03094525f, -0.15618153f, 0.21792564f, 0.08106838f, -0.22098514f, -0.10796417f, 0.07131225f, + 0.22092983f, -0.01539366f, -0.02876964f, -0.30910203f, 0.02143815f, -0.11630868f, -0.00922897f, 0.07431208f, + 0.15533504f, 0.11425125f, 0.07125455f, -0.11914105f, -0.04275274f, -0.05072749f, -0.22143129f, 0.19787727f, + -0.20946717f, -0.16564523f, 0.05962536f, -0.22325630f, -0.04333350f, -0.04707248f, 0.16608582f, 0.00948954f, + 0.11283893f, -0.04097161f, -0.09076904f, 0.26722300f, 0.00987607f, -0.05807892f, 0.07872546f, 0.08040629f, + 0.12927419f, -0.05647410f, 0.09603068f, -0.02356448f, -0.02160797f, -0.11687102f, 0.07936122f, -0.05764586f, + -0.10510305f, -0.02326054f, 0.12021790f, 0.09782617f, -0.22600858f, -0.02555378f, -0.03561033f, -0.01337216f, + 0.11311363f, -0.03096960f, -0.22801498f, 0.05643769f, 0.13053033f, 0.04452197f, -0.09299882f, -0.11475921f, + 0.02257649f, -0.21770498f, -0.11454470f, -0.09435777f, 0.00638951f, -0.36990553f, 0.04266735f, 0.06915011f, + 0.07644624f, -0.24336053f, -0.03421960f, -0.10622191f, -0.17223521f, 0.04054553f, 0.13831380f, 0.02925055f, + 0.16207848f, -0.12994884f, -0.09751288f, -0.05397306f, -0.09323815f, 0.13425350f, -0.00046960f, 0.31072289f, + 0.13740718f, 0.05835414f, -0.04803475f, 0.15423043f, -0.09652353f, 0.14896898f, -0.16368309f, 0.05875925f, + -0.03678078f, -0.19627908f, 0.07034992f, -0.27213186f, -0.04338680f, 0.01567988f, -0.09158870f, 0.11987700f, + 0.07083926f, 0.01099900f, -0.01084446f, 0.04508050f, -0.10655984f, -0.13945042f, 0.05837287f, 0.08458713f, + -0.04212087f, -0.15749574f, 0.11632511f, 0.07976698f, 0.06725866f, -0.09567240f, 0.03796997f, -0.09355708f, + -0.13569611f, -0.19498724f, 0.14951572f, -0.16023041f, 0.04185898f, 0.06099325f, 0.03425207f, 0.16211477f, + 0.03998571f, -0.03629408f, -0.10099959f, 0.19540504f, 0.11653102f, 0.23601755f, 0.04943547f, -0.26040605f, + 0.02153429f, 0.22880882f, -0.13646534f, 0.03881640f, -0.02896636f, 0.09774253f, -0.13509314f, -0.08713179f, + 0.13485038f, 0.06968338f, 0.19561967f, 0.07884958f, -0.10365590f, -0.10321335f, -0.09081125f, -0.00147976f +}; + +/*----------------------------------------------------------------------------------* + * CLDFB tables + *----------------------------------------------------------------------------------*/ + +const int freqTable[2] = {20, 40}; + +/* SNR: 109.44, PHASE: 3.500000000000000 */ +const float CLDFB80_10[100] = +{ + 0.0000033382f, -0.0000023292f, -0.0000006582f, 0.0000001464f, -0.0000010899f, -0.0000009664f, + -0.0000000104f, -0.0000018105f, -0.0000012856f, 0.0000017112f, 0.0000137155f, -0.0000084710f, + -0.0000015748f, -0.0000002482f, 0.0000036294f, -0.0000043816f, 0.0000003906f, 0.0000043318f, + 0.0000049126f, -0.0000061826f, -0.0002270069f, -0.0000675402f, -0.0000158982f, 0.0000138120f, + -0.0000220086f, -0.0000356560f, 0.0000171849f, -0.0000194504f, -0.0000058158f, -0.0002621811f, + -0.0009969691f, -0.0001427984f, -0.0000188085f, -0.0000040399f, -0.0001954359f, 0.0001806872f, + 0.0000232574f, -0.0000047551f, -0.0000321009f, 0.0010723262f, -0.0020160153f, -0.0007751652f, + 0.0003508478f, 0.0015707671f, 0.0017180828f, 0.0015807568f, 0.0021944824f, 0.0028288425f, + 0.0030257006f, 0.0016570983f, -0.0014279413f, -0.0015962377f, 0.0007765516f, 0.0025625922f, + 0.0022554877f, 0.0002647332f, -0.0032977409f, -0.0065113932f, -0.0095444393f, -0.0136373114f, + 0.0186561662f, 0.0242546518f, 0.0320538418f, 0.0427742450f, 0.0565841171f, 0.0732940277f, + 0.0914110197f, 0.1082620545f, 0.1209072165f, 0.1269811579f, 0.1253574855f, 0.1136768387f, + 0.0887587689f, 0.0497640968f, -0.0031398279f, -0.0698373206f, -0.1494875982f, -0.2406007759f, + -0.3411996303f, -0.4484628681f, 0.5579472269f, 0.6655527761f, 0.7669493517f, 0.8575328375f, + 0.9329386030f, 0.9892971917f, 1.0250167399f, 1.0397966587f, 1.0375221638f, 1.0163053398f, + 0.9610874400f, 0.8748972145f, 0.7783924293f, 0.6777346686f, 0.5724389618f, 0.4648620471f, + 0.3560337451f, 0.2485564060f, 0.1386438276f, 0.0416433203f, +}; + +/* SNR: 292.49, PHASE: 2.000000000000000 */ +const float CLDFB80_16[160] = +{ + 0.0000005510f, -0.0000007674f, -0.0000002340f, 0.0000000964f, 0.0000000593f, -0.0000000017f, + -0.0000000178f, 0.0000021953f, 0.0000030004f, -0.0000000167f, -0.0000000019f, 0.0000000702f, + 0.0000000344f, -0.0000000765f, -0.0000005553f, 0.0000007526f, 0.0000020881f, -0.0000028263f, + -0.0000007033f, 0.0000002370f, 0.0000001175f, -0.0000004048f, 0.0000000996f, -0.0000180207f, + 0.0000246292f, -0.0000000934f, 0.0000004489f, -0.0000001390f, -0.0000000845f, 0.0000002300f, + 0.0000020452f, -0.0000028520f, -0.0003204839f, -0.0001476489f, -0.0000626217f, -0.0000446346f, + -0.0000202236f, 0.0000151160f, 0.0000057995f, 0.0000450017f, 0.0000433006f, 0.0000050745f, + 0.0000167005f, -0.0000314631f, -0.0000244547f, -0.0000125422f, -0.0000911863f, -0.0004371781f, + -0.0012267106f, -0.0005247118f, -0.0001857576f, -0.0001103593f, -0.0000402931f, 0.0000108771f, + -0.0000576360f, 0.0000602621f, -0.0002317927f, 0.0000520316f, 0.0000035090f, 0.0000625950f, + 0.0000603417f, 0.0000368907f, 0.0003220307f, 0.0016733998f, -0.0021551784f, -0.0015444660f, + -0.0007592329f, -0.0001077355f, 0.0007091208f, 0.0015054295f, 0.0017984668f, 0.0011461500f, + 0.0015946160f, 0.0018157551f, 0.0022526599f, 0.0027665136f, 0.0029611644f, 0.0030474884f, + 0.0025509350f, 0.0012885692f, -0.0011048694f, -0.0019476595f, -0.0014849578f, -0.0000191307f, + 0.0014542427f, 0.0025014060f, 0.0026282341f, 0.0020896060f, 0.0009380930f, -0.0012303806f, + -0.0035150110f, -0.0055687066f, -0.0074233361f, -0.0093371234f, -0.0117127490f, -0.0145175090f, + 0.0177813213f, 0.0209221310f, 0.0246700384f, 0.0293186424f, 0.0350939424f, 0.0420166741f, + 0.0501689083f, 0.0594973479f, 0.0699793095f, 0.0811978302f, 0.0925316969f, 0.1033039355f, + 0.1127998301f, 0.1202885467f, 0.1252446307f, 0.1272143872f, 0.1262547749f, 0.1217276780f, + 0.1125292370f, 0.0980647299f, 0.0780704213f, 0.0526074650f, 0.0217182187f, -0.0146037409f, + -0.0563029259f, -0.1031675028f, -0.1548654211f, -0.2110103318f, -0.2711216615f, -0.3346791161f, + -0.4009613796f, -0.4689983890f, 0.5374920358f, 0.6054498150f, 0.6721266919f, 0.7362374318f, + 0.7966023599f, 0.8522654625f, 0.9021245679f, 0.9450253190f, 0.9802630812f, 1.0075496836f, + 1.0265340754f, 1.0372359728f, 1.0407524022f, 1.0381397893f, 1.0284102813f, 1.0099196627f, + 0.9753688495f, 0.9254582964f, 0.8690385973f, 0.8090082031f, 0.7474414548f, 0.6841760105f, + 0.6189218236f, 0.5524001591f, 0.4851748506f, 0.4172433895f, 0.3492691242f, 0.2821066655f, + 0.2146356085f, 0.1455327617f, 0.0796914490f, 0.0278251946f, +}; + +/* SNR: 89.77, PHASE: 1.500000000000000 */ +const float CLDFB80_20[200] = +{ + 0.0000016461f, -0.0000046862f, -0.0000000815f, -0.0000001822f, 0.0000000240f, 0.0000001892f, + -0.0000002365f, -0.0000007031f, -0.0000000079f, 0.0000048656f, 0.0000070490f, 0.0000000032f, + 0.0000001499f, -0.0000000944f, 0.0000004307f, -0.0000000787f, -0.0000001070f, 0.0000015376f, + -0.0000025088f, 0.0000044280f, 0.0000046060f, -0.0000207092f, -0.0000004877f, -0.0000006126f, + 0.0000000605f, 0.0000004365f, -0.0000003741f, -0.0000009508f, 0.0000006700f, -0.0000087189f, + 0.0000114297f, -0.0000007710f, -0.0000002908f, 0.0000001583f, -0.0000010138f, 0.0000001875f, + 0.0000003789f, -0.0000065731f, 0.0000112115f, -0.0000036253f, -0.0003045828f, -0.0002068946f, + -0.0000330428f, -0.0000658559f, -0.0000416668f, -0.0000207558f, -0.0000046097f, 0.0000096778f, + -0.0000064960f, 0.0000515938f, 0.0000257367f, -0.0000068671f, 0.0000029284f, -0.0000209369f, + -0.0000191720f, -0.0000235869f, -0.0000286778f, 0.0000594843f, -0.0001104448f, -0.0004947290f, + -0.0011759540f, -0.0006581582f, -0.0001310136f, -0.0001782524f, -0.0001002354f, -0.0000465158f, + -0.0000188237f, 0.0000285072f, -0.0001359344f, 0.0002814194f, -0.0004814411f, 0.0001302339f, + -0.0000257394f, 0.0000578339f, 0.0000485628f, 0.0000543116f, 0.0000763443f, -0.0001495108f, + 0.0003492618f, 0.0018283780f, -0.0019931487f, -0.0018716309f, -0.0008617653f, -0.0006080124f, + -0.0000337803f, 0.0006187704f, 0.0012478726f, 0.0016757046f, 0.0018115391f, 0.0007745483f, + 0.0016550121f, 0.0017032298f, 0.0019356593f, 0.0024080283f, 0.0027878510f, 0.0029379588f, + 0.0030637651f, 0.0028257202f, 0.0021943273f, 0.0010679683f, -0.0009250455f, -0.0017798333f, + -0.0018826540f, -0.0011010583f, 0.0001463485f, 0.0013293069f, 0.0022974838f, 0.0027746423f, + 0.0025078917f, 0.0020425098f, 0.0011954954f, -0.0005741594f, -0.0024120809f, -0.0041653667f, + -0.0057623702f, -0.0072425386f, -0.0087363677f, -0.0104237699f, -0.0125156239f, -0.0148077168f, + 0.0174398402f, 0.0199230411f, 0.0226649147f, 0.0259599813f, 0.0298434758f, 0.0344649815f, + 0.0398139569f, 0.0459314689f, 0.0528498740f, 0.0604788669f, 0.0688814001f, 0.0777923399f, + 0.0868947517f, 0.0958553537f, 0.1043243835f, 0.1119302041f, 0.1182880738f, 0.1231125873f, + 0.1261745561f, 0.1272284850f, 0.1264656300f, 0.1235525506f, 0.1177556666f, 0.1087635447f, + 0.0963144136f, 0.0803171444f, 0.0608146076f, 0.0378425383f, 0.0113896330f, -0.0185270856f, + -0.0518892622f, -0.0885871716f, -0.1284318249f, -0.1712634880f, -0.2168508609f, -0.2649463144f, + -0.3152867427f, -0.3675395959f, -0.4212350657f, -0.4758650706f, 0.5306725282f, 0.5851445237f, + 0.6390281696f, 0.6916889535f, 0.7424591009f, 0.7907617163f, 0.8361206884f, 0.8779983070f, + 0.9157691951f, 0.9489012228f, 0.9770929872f, 1.0002174168f, 1.0180999340f, 1.0305853696f, + 1.0378851378f, 1.0406826783f, 1.0395784114f, 1.0343061945f, 1.0237762412f, 1.0076524569f, + 0.9800034826f, 0.9411740407f, 0.8979145998f, 0.8512639848f, 0.8029102780f, 0.7536620391f, + 0.7033730373f, 0.6517679660f, 0.5990562278f, 0.5457078369f, 0.4919297136f, 0.4376796414f, + 0.3831842053f, 0.3290362900f, 0.2754121565f, 0.2214602867f, 0.1663238479f, 0.1115465981f, + 0.0622889538f, 0.0233593568f, +}; + +/* SNR: 89.29, PHASE: 0.833333333333333 */ +const float CLDFB80_30[300] = +{ + -0.0000002772f, 0.0000033382f, 0.0000018078f, -0.0000007965f, -0.0000023292f, -0.0000000163f, + 0.0000001004f, -0.0000006582f, 0.0000000287f, 0.0000000140f, 0.0000001464f, 0.0000002826f, + 0.0000000427f, -0.0000010899f, 0.0000048488f, 0.0000070973f, -0.0000009664f, 0.0000000360f, + 0.0000004432f, -0.0000000104f, -0.0000000269f, -0.0000000107f, -0.0000018105f, 0.0000000543f, + -0.0000000029f, -0.0000012856f, -0.0000006144f, 0.0000009806f, 0.0000017112f, -0.0000026992f, + -0.0000120997f, 0.0000137155f, 0.0000075545f, -0.0000032372f, -0.0000084710f, -0.0000000206f, + 0.0000002472f, -0.0000015748f, 0.0000000428f, -0.0000000299f, -0.0000002482f, 0.0000005522f, + 0.0000001959f, 0.0000036294f, 0.0000084418f, -0.0000120850f, -0.0000043816f, -0.0000001651f, + -0.0000010266f, 0.0000003906f, 0.0000001476f, 0.0000000560f, 0.0000043318f, -0.0000001327f, + -0.0000000099f, 0.0000049126f, 0.0000025641f, -0.0000041212f, -0.0000061826f, 0.0000182899f, + -0.0003177625f, -0.0002270069f, -0.0001470513f, -0.0000710867f, -0.0000675402f, -0.0000612052f, + -0.0000458905f, -0.0000158982f, -0.0000198609f, -0.0000044865f, 0.0000138120f, 0.0000259521f, + -0.0000014174f, -0.0000220086f, 0.0000046746f, -0.0000478217f, -0.0000356560f, -0.0000008176f, + 0.0000554471f, 0.0000171849f, -0.0000104782f, -0.0000342931f, -0.0000194504f, -0.0000247231f, + -0.0000266321f, -0.0000058158f, -0.0000154718f, -0.0000860619f, -0.0002621811f, -0.0006329730f, + -0.0010151313f, -0.0009969691f, -0.0006401095f, -0.0002347208f, -0.0001427984f, -0.0001657818f, + -0.0001142242f, -0.0000188085f, -0.0000385187f, -0.0000275046f, -0.0000040399f, 0.0000495378f, + -0.0001045437f, -0.0001954359f, 0.0005754000f, -0.0007487377f, 0.0001806872f, 0.0000995589f, + -0.0000996504f, 0.0000232574f, 0.0000603268f, 0.0000660807f, -0.0000047551f, 0.0000619265f, + 0.0000723872f, -0.0000321009f, 0.0000223561f, 0.0003720504f, 0.0010723262f, 0.0019477029f, + -0.0018122293f, -0.0020160153f, -0.0017426363f, -0.0010556444f, -0.0007751652f, -0.0005221317f, + -0.0001347624f, 0.0003508478f, 0.0007386346f, 0.0011721899f, 0.0015707671f, 0.0017166805f, + 0.0018089705f, 0.0017180828f, 0.0002671723f, 0.0016677326f, 0.0015807568f, 0.0017534327f, + 0.0019075685f, 0.0021944824f, 0.0024875266f, 0.0027574445f, 0.0028288425f, 0.0029688585f, + 0.0030573770f, 0.0030257006f, 0.0027683197f, 0.0023855538f, 0.0016570983f, 0.0007261425f, + -0.0006240877f, -0.0014279413f, -0.0018848796f, -0.0019263976f, -0.0015962377f, -0.0009120500f, + -0.0000736785f, 0.0007765516f, 0.0014961634f, 0.0021524541f, 0.0025625922f, 0.0027460441f, + 0.0025688449f, 0.0022554877f, 0.0019970512f, 0.0015552223f, 0.0002647332f, -0.0008620885f, + -0.0020865380f, -0.0032977409f, -0.0044403210f, -0.0055039505f, -0.0065113932f, -0.0074839181f, + -0.0084786965f, -0.0095444393f, -0.0107566368f, -0.0121559845f, -0.0136373114f, -0.0152125941f, + 0.0169692165f, 0.0186561662f, 0.0203704498f, 0.0221787331f, 0.0242546518f, 0.0265582983f, + 0.0291465321f, 0.0320538418f, 0.0353059968f, 0.0388699993f, 0.0427742450f, 0.0470319574f, + 0.0516455579f, 0.0565841171f, 0.0617960053f, 0.0674208876f, 0.0732940277f, 0.0793036968f, + 0.0853757711f, 0.0914110197f, 0.0973085175f, 0.1029609938f, 0.1082620545f, 0.1130850459f, + 0.1173295323f, 0.1209072165f, 0.1237469292f, 0.1257934619f, 0.1269811579f, 0.1271703366f, + 0.1266559114f, 0.1253574855f, 0.1227915199f, 0.1189360593f, 0.1136768387f, 0.1069333476f, + 0.0986359173f, 0.0887587689f, 0.0773092890f, 0.0643073307f, 0.0497640968f, 0.0336765771f, + 0.0160401582f, -0.0031398279f, -0.0238366387f, -0.0460799881f, -0.0698373206f, -0.0950128018f, + -0.1215783841f, -0.1494875982f, -0.1786760784f, -0.2090721736f, -0.2406007759f, -0.2731879051f, + -0.3067537961f, -0.3411996303f, -0.3764015708f, -0.4122065782f, -0.4484628681f, -0.4850451997f, + 0.5215924710f, 0.5579472269f, 0.5941804962f, 0.6301135607f, 0.6655527761f, 0.7002994797f, + 0.7341550905f, 0.7669493517f, 0.7985389090f, 0.8287866009f, 0.8575328375f, 0.8845952462f, + 0.9097846281f, 0.9329386030f, 0.9539491421f, 0.9727435862f, 0.9892971917f, 1.0035676672f, + 1.0154927835f, 1.0250167399f, 1.0321480823f, 1.0370035227f, 1.0397966587f, 1.0407627030f, + 1.0400314908f, 1.0375221638f, 1.0329480648f, 1.0259438203f, 1.0163053398f, 1.0048344063f, + 0.9863956401f, 0.9610874400f, 0.9342743262f, 0.9054084925f, 0.8748972145f, 0.8432873810f, + 0.8110381808f, 0.7783924293f, 0.7453640666f, 0.7118431392f, 0.6777346686f, 0.6430470493f, + 0.6078972260f, 0.5724389618f, 0.5367746506f, 0.5009238704f, 0.4648620471f, 0.4286003322f, + 0.3922588980f, 0.3560337451f, 0.3200733025f, 0.2843378434f, 0.2485564060f, 0.2123552623f, + 0.1755742394f, 0.1386438276f, 0.1027751331f, 0.0698223020f, 0.0416433203f, 0.0171881989f, +}; + +/* SNR: 85.69, PHASE: 0.750000000000000 */ +const float CLDFB80_32[320] = +{ + -0.0000010182f, 0.0000018812f, -0.0000013969f, 0.0000000702f, -0.0000030351f, -0.0000001862f, + 0.0000000017f, 0.0000000804f, -0.0000002859f, -0.0000000058f, -0.0000003463f, -0.0000003782f, + 0.0000006385f, 0.0000000365f, -0.0000015696f, 0.0000043896f, 0.0000063462f, -0.0000013860f, + 0.0000000439f, 0.0000007243f, -0.0000000373f, -0.0000001214f, 0.0000000228f, -0.0000008123f, + 0.0000002096f, -0.0000000043f, -0.0000001079f, -0.0000005174f, -0.0000001146f, -0.0000006991f, + 0.0000012420f, -0.0000054157f, -0.0000164806f, 0.0000076445f, -0.0000065087f, 0.0000002224f, + -0.0000110942f, -0.0000006228f, 0.0000000012f, 0.0000001914f, -0.0000006876f, 0.0000000004f, + -0.0000005395f, -0.0000007555f, 0.0000015057f, 0.0000005303f, 0.0000035648f, 0.0000094151f, + -0.0000133505f, -0.0000042847f, -0.0000005848f, -0.0000018021f, 0.0000001676f, 0.0000001730f, + -0.0000000645f, 0.0000019429f, -0.0000005012f, 0.0000000132f, 0.0000003799f, 0.0000014190f, + 0.0000005446f, 0.0000033533f, -0.0000041925f, 0.0000243728f, -0.0003249116f, -0.0002555667f, + -0.0001781466f, -0.0000946691f, -0.0000512440f, -0.0000668181f, -0.0000538663f, -0.0000367589f, + -0.0000153566f, -0.0000159763f, -0.0000043008f, 0.0000014360f, 0.0000256407f, -0.0000045056f, + -0.0000224244f, -0.0000056258f, -0.0000573469f, -0.0000427838f, -0.0000040513f, 0.0000493530f, + -0.0000199927f, -0.0000284530f, -0.0000443529f, -0.0000157197f, -0.0000152059f, -0.0000265666f, + -0.0000286606f, 0.0000426372f, -0.0000445737f, -0.0000968212f, -0.0002992176f, -0.0006564777f, + -0.0009923400f, -0.0010465131f, -0.0006586000f, -0.0003460162f, -0.0000803812f, -0.0001828317f, + -0.0001374910f, -0.0000892170f, -0.0000247429f, -0.0000281266f, -0.0000112548f, -0.0000220216f, + 0.0000281030f, -0.0001241423f, -0.0001739019f, 0.0006003709f, -0.0007665771f, 0.0001545192f, + 0.0001183979f, -0.0000725009f, 0.0000709099f, 0.0000556600f, 0.0000787870f, 0.0000127551f, + 0.0000418355f, 0.0000676110f, 0.0000771386f, -0.0001678521f, 0.0001526165f, 0.0003591734f, + 0.0011851563f, 0.0019531880f, -0.0018073091f, -0.0020646655f, -0.0018286838f, -0.0012220764f, + -0.0007555665f, -0.0006377868f, -0.0003093176f, 0.0000756312f, 0.0005274300f, 0.0009274213f, + 0.0012803192f, 0.0016235299f, 0.0017557598f, 0.0018111856f, 0.0016683303f, 0.0002150325f, + 0.0016540635f, 0.0015774318f, 0.0017217761f, 0.0018831036f, 0.0020842542f, 0.0023790930f, + 0.0026699692f, 0.0028034973f, 0.0028981065f, 0.0030135931f, 0.0030635897f, 0.0029615904f, + 0.0027120429f, 0.0022714745f, 0.0016059652f, 0.0006835412f, -0.0005828829f, -0.0013844400f, + -0.0018243580f, -0.0019502151f, -0.0017356111f, -0.0011689841f, -0.0004229350f, 0.0003965073f, + 0.0011294169f, 0.0017707072f, 0.0023448371f, 0.0026728102f, 0.0027087051f, 0.0025324105f, + 0.0022209939f, 0.0019939538f, 0.0015995394f, 0.0003709522f, -0.0006814813f, -0.0018062812f, + -0.0029774326f, -0.0040602444f, -0.0050788762f, -0.0060470476f, -0.0069716019f, -0.0078811278f, + -0.0088339160f, -0.0098593061f, -0.0110571431f, -0.0123801308f, -0.0137829951f, -0.0152658987f, + 0.0169119551f, 0.0185130319f, 0.0200914127f, 0.0217670701f, 0.0236411334f, 0.0257401339f, + 0.0280588687f, 0.0306516429f, 0.0335396415f, 0.0367140220f, 0.0401734073f, 0.0439328404f, + 0.0480118471f, 0.0523958086f, 0.0570643279f, 0.0619617615f, 0.0672386055f, 0.0727386082f, + 0.0783586322f, 0.0840454562f, 0.0897239254f, 0.0953063133f, 0.1006989894f, 0.1058297221f, + 0.1105886458f, 0.1148828316f, 0.1186363019f, 0.1217873693f, 0.1242652074f, 0.1260376844f, + 0.1270428159f, 0.1271553981f, 0.1266717254f, 0.1255342565f, 0.1232765470f, 0.1198938969f, + 0.1153006197f, 0.1094250684f, 0.1021978763f, 0.0935850985f, 0.0835853025f, 0.0722146942f, + 0.0594803881f, 0.0453959671f, 0.0299515180f, 0.0131448092f, -0.0050174243f, -0.0245067664f, + -0.0453599939f, -0.0675506175f, -0.0909864895f, -0.1156500318f, -0.1415054519f, -0.1685034579f, + -0.1965824123f, -0.2256851924f, -0.2557490596f, -0.2867109877f, -0.3185003509f, -0.3510308710f, + -0.3841878257f, -0.4178462189f, -0.4518783777f, -0.4861948985f, 0.5204589154f, 0.5545392477f, + 0.5885349528f, 0.6222881265f, 0.6556472882f, 0.6884462258f, 0.7205203255f, 0.7517187214f, + 0.7819150729f, 0.8109973423f, 0.8388462493f, 0.8653227793f, 0.8902717587f, 0.9135401037f, + 0.9350004724f, 0.9545704608f, 0.9721900670f, 0.9878415249f, 1.0014908046f, 1.0130877123f, + 1.0225821802f, 1.0299620942f, 1.0352930981f, 1.0387279035f, 1.0404656862f, 1.0406699226f, + 1.0393792732f, 1.0364602207f, 1.0316371259f, 1.0246094465f, 1.0152749279f, 1.0045111461f, + 0.9872243762f, 0.9634951727f, 0.9386029698f, 0.9118835665f, 0.8836131513f, 0.8542438147f, + 0.8241955864f, 0.7937396816f, 0.7629631733f, 0.7318123869f, 0.7001870615f, 0.6680338585f, + 0.6353919868f, 0.6023736401f, 0.5691034053f, 0.5356571527f, 0.5020472026f, 0.4682522004f, + 0.4342757821f, 0.4002060880f, 0.3661991567f, 0.3324016480f, 0.2988415427f, 0.2653598332f, + 0.2316572400f, 0.1974745970f, 0.1628547074f, 0.1283770554f, 0.0952404323f, 0.0650740936f, + 0.0392771501f, 0.0163785856f, +}; + +/* SNR: 81.55, PHASE: 0.500000000000000 */ +const float CLDFB80_40[400] = +{ + -0.0000041528f, -0.0000003900f, -0.0000033779f, 0.0000013260f, -0.0000003143f, -0.0000019348f, + 0.0000002820f, 0.0000000171f, 0.0000000756f, 0.0000001478f, -0.0000006625f, 0.0000000082f, + 0.0000000114f, -0.0000002690f, -0.0000007281f, 0.0000005577f, -0.0000000239f, 0.0000002429f, + -0.0000004091f, 0.0000026069f, 0.0000034995f, -0.0000001726f, 0.0000002145f, -0.0000000401f, + 0.0000006351f, -0.0000000199f, -0.0000000701f, -0.0000000269f, -0.0000000511f, -0.0000018158f, + 0.0000003875f, 0.0000000519f, 0.0000000148f, 0.0000002168f, 0.0000008257f, -0.0000004464f, + 0.0000006336f, -0.0000025316f, -0.0000005295f, -0.0000153180f, -0.0000308298f, -0.0000015398f, + -0.0000152958f, 0.0000058438f, -0.0000013050f, -0.0000070187f, 0.0000011695f, 0.0000000763f, + 0.0000001881f, 0.0000003524f, -0.0000015865f, -0.0000000049f, -0.0000000249f, -0.0000006192f, + -0.0000011121f, 0.0000012060f, -0.0000000166f, 0.0000001099f, -0.0000106587f, 0.0000106129f, + -0.0000148286f, 0.0000149412f, 0.0000001626f, 0.0000000725f, -0.0000015409f, 0.0000000950f, + 0.0000003484f, 0.0000001231f, 0.0000001497f, 0.0000043429f, -0.0000009269f, -0.0000001280f, + -0.0000000626f, -0.0000009033f, -0.0000040910f, 0.0000019169f, -0.0000028704f, 0.0000109325f, + -0.0000009252f, 0.0000489011f, -0.0003468893f, -0.0003166165f, -0.0002216732f, -0.0001440458f, + -0.0000849613f, -0.0000369773f, -0.0000635098f, -0.0000591070f, -0.0000486803f, -0.0000341989f, + -0.0000120811f, -0.0000190275f, -0.0000064494f, 0.0000069162f, -0.0000021987f, 0.0000272330f, + 0.0000008567f, -0.0000105879f, 0.0000129785f, -0.0000391934f, -0.0000840231f, 0.0000041534f, + -0.0000069437f, 0.0000002747f, 0.0000564106f, -0.0000335888f, -0.0000091603f, -0.0000220067f, + -0.0000377648f, -0.0000212702f, -0.0000107779f, -0.0000254405f, -0.0000262093f, -0.0000203017f, + 0.0000691479f, -0.0000348713f, -0.0000882526f, -0.0001632241f, -0.0003897623f, -0.0007277920f, + -0.0009273781f, -0.0011866370f, -0.0007657374f, -0.0005999553f, -0.0002985749f, -0.0000739204f, + -0.0001965512f, -0.0001587267f, -0.0001222374f, -0.0000844484f, -0.0000080229f, -0.0000361957f, + -0.0000240334f, 0.0000097698f, -0.0000196647f, 0.0000408240f, -0.0000873313f, -0.0001974888f, + -0.0000745679f, 0.0006405856f, -0.0007833142f, -0.0000263740f, 0.0001825899f, 0.0000836328f, + -0.0000919747f, 0.0000758216f, 0.0000210116f, 0.0000664122f, 0.0000716628f, -0.0000011497f, + 0.0000361513f, 0.0000644816f, 0.0000707314f, 0.0000692091f, -0.0002055217f, 0.0001007125f, + 0.0003613597f, 0.0005722141f, 0.0014928248f, 0.0019595151f, -0.0018123181f, -0.0021841686f, + -0.0019313868f, -0.0016661118f, -0.0011520847f, -0.0007460794f, -0.0007200000f, -0.0004759622f, + -0.0001911740f, 0.0001177745f, 0.0005112609f, 0.0007956582f, 0.0011317990f, 0.0014125904f, + 0.0016338868f, 0.0017396047f, 0.0018056445f, 0.0018052119f, 0.0014209425f, 0.0000970427f, + 0.0015804238f, 0.0015713347f, 0.0016260006f, 0.0017792934f, 0.0018939546f, 0.0020439435f, + 0.0023023017f, 0.0025264800f, 0.0027361034f, 0.0028056985f, 0.0028830887f, 0.0029840440f, + 0.0030499023f, 0.0030582362f, 0.0029323543f, 0.0027372045f, 0.0024602608f, 0.0018918251f, + 0.0014430869f, 0.0005567848f, -0.0004563602f, -0.0012376069f, -0.0015957612f, -0.0019181670f, + -0.0019416943f, -0.0017732047f, -0.0013639015f, -0.0008131398f, -0.0001818974f, 0.0004785653f, + 0.0010577894f, 0.0015807496f, 0.0020750864f, 0.0024484891f, 0.0027097859f, 0.0027252487f, + 0.0025942388f, 0.0023933812f, 0.0021363139f, 0.0019878937f, 0.0017252901f, 0.0007007239f, + -0.0001528669f, -0.0010081819f, -0.0019255759f, -0.0028704299f, -0.0037352063f, -0.0045760650f, + -0.0053741521f, -0.0061399643f, -0.0068807053f, -0.0076055948f, -0.0083505693f, -0.0091327970f, + -0.0099660466f, -0.0109276265f, -0.0119779770f, -0.0130668832f, -0.0142243967f, -0.0154284789f, + 0.0167425678f, 0.0180870259f, 0.0192629868f, 0.0205914974f, 0.0219419942f, 0.0234393525f, + 0.0250925019f, 0.0268648248f, 0.0288064481f, 0.0309261411f, 0.0332359672f, 0.0357337882f, + 0.0384058373f, 0.0412703873f, 0.0443254146f, 0.0475898752f, 0.0510512395f, 0.0546934731f, + 0.0585192825f, 0.0624617968f, 0.0666925081f, 0.0710800609f, 0.0755330962f, 0.0800607977f, + 0.0846155968f, 0.0891603964f, 0.0936468776f, 0.0980290565f, 0.1022710303f, 0.1063242147f, + 0.1101321383f, 0.1136484689f, 0.1168337639f, 0.1196454804f, 0.1220672782f, 0.1240474957f, + 0.1255837620f, 0.1266445580f, 0.1271706795f, 0.1271032514f, 0.1267122859f, 0.1259990302f, + 0.1245431141f, 0.1223810246f, 0.1194917271f, 0.1158164730f, 0.1113281486f, 0.1059821849f, + 0.0997598463f, 0.0926475473f, 0.0846476380f, 0.0757687538f, 0.0660180747f, 0.0553969977f, + 0.0439122033f, 0.0315571111f, 0.0183294511f, 0.0042339687f, -0.0107303776f, -0.0265261206f, + -0.0432087461f, -0.0607651851f, -0.0791119955f, -0.0982585186f, -0.1181828257f, -0.1388675094f, + -0.1602878821f, -0.1824109255f, -0.2052090118f, -0.2286494873f, -0.2527009969f, -0.2773319455f, + -0.3025075323f, -0.3281859857f, -0.3543210024f, -0.3808473827f, -0.4077028160f, -0.4348259057f, + -0.4621422068f, -0.4896449982f, 0.5170583948f, 0.5443118380f, 0.5715622296f, 0.5986919021f, + 0.6256446209f, 0.6523342207f, 0.6786749944f, 0.7045840109f, 0.7299779641f, 0.7547853740f, + 0.7789437691f, 0.8023962911f, 0.8250842263f, 0.8469401272f, 0.8678891784f, 0.8878500705f, + 0.9067442457f, 0.9245026353f, 0.9410725379f, 0.9564213901f, 0.9705164338f, 0.9833542233f, + 0.9949193206f, 1.0051881116f, 1.0141325299f, 1.0217280805f, 1.0279678321f, 1.0328759990f, + 1.0365142018f, 1.0389749476f, 1.0403626832f, 1.0407638661f, 1.0402158247f, 1.0386859218f, + 1.0360693875f, 1.0322135556f, 1.0269616972f, 1.0202228069f, 1.0121135675f, 1.0035354422f, + 0.9897053659f, 0.9706651118f, 0.9512828704f, 0.9307719520f, 0.9091186544f, 0.8864979484f, + 0.8631436896f, 0.8392834698f, 0.8150938957f, 0.7906763160f, 0.7660562253f, 0.7412033356f, + 0.7160643565f, 0.6905965223f, 0.6647900873f, 0.6386753533f, 0.6123109042f, 0.5857635917f, + 0.5590863635f, 0.5323035448f, 0.5054159767f, 0.4784116395f, 0.4512831657f, 0.4240582163f, + 0.3967995814f, 0.3695924504f, 0.3425141525f, 0.3155972383f, 0.2888001961f, 0.2620044852f, + 0.2350467488f, 0.2077866806f, 0.1801971236f, 0.1524510915f, 0.1249766396f, 0.0984509433f, + 0.0737154373f, 0.0515800648f, 0.0323408448f, 0.0138765961f, +}; + + +/* SNR: 85.15, PHASE: 0.166666666666667 */ +const float CLDFB80_60[600] = +{ + -0.0000108386f, 0.0000016461f, -0.0000001140f, 0.0000015161f, -0.0000046862f, -0.0000001825f, + 0.0000001498f, -0.0000000815f, -0.0000033014f, 0.0000001274f, -0.0000001822f, 0.0000000191f, + 0.0000000335f, 0.0000000240f, 0.0000001226f, -0.0000010507f, 0.0000001892f, 0.0000000108f, + -0.0000000274f, -0.0000002365f, -0.0000000901f, -0.0000002666f, -0.0000007031f, 0.0000006413f, + -0.0000000514f, -0.0000000079f, 0.0000002000f, -0.0000014744f, 0.0000048656f, -0.0000001578f, + -0.0000005544f, 0.0000070490f, -0.0000012678f, 0.0000001774f, 0.0000000032f, -0.0000000624f, + 0.0000007343f, 0.0000001499f, -0.0000000401f, -0.0000000182f, -0.0000000944f, -0.0000000302f, + -0.0000000091f, 0.0000004307f, -0.0000028538f, 0.0000002990f, -0.0000000787f, 0.0000000221f, + 0.0000000116f, -0.0000001070f, 0.0000001406f, -0.0000009019f, 0.0000015376f, -0.0000000209f, + -0.0000002404f, -0.0000025088f, -0.0000000262f, 0.0000000630f, 0.0000044280f, -0.0000305498f, + -0.0000482857f, 0.0000046060f, -0.0000005548f, 0.0000056679f, -0.0000207092f, -0.0000003611f, + 0.0000005381f, -0.0000004877f, -0.0000120827f, 0.0000006267f, -0.0000006126f, 0.0000000608f, + 0.0000000850f, 0.0000000605f, 0.0000002921f, -0.0000025140f, 0.0000004365f, 0.0000000116f, + -0.0000000639f, -0.0000003741f, -0.0000004826f, -0.0000006420f, -0.0000009508f, 0.0000015544f, + -0.0000000218f, 0.0000006700f, 0.0000004181f, -0.0000021629f, -0.0000087189f, 0.0000088821f, + -0.0000126345f, 0.0000114297f, 0.0000034734f, -0.0000001464f, -0.0000007710f, 0.0000000568f, + -0.0000018420f, -0.0000002908f, 0.0000001921f, 0.0000004300f, 0.0000001583f, 0.0000000782f, + 0.0000000378f, -0.0000010138f, 0.0000068268f, -0.0000007152f, 0.0000001875f, -0.0000000557f, + -0.0000000384f, 0.0000003789f, -0.0000006147f, 0.0000030092f, -0.0000065731f, 0.0000001500f, + 0.0000007177f, 0.0000112115f, 0.0000001848f, -0.0000012026f, -0.0000036253f, 0.0000992289f, + -0.0003607599f, -0.0003045828f, -0.0002977550f, -0.0001992588f, -0.0002068946f, -0.0001476180f, + -0.0000980857f, -0.0000330428f, -0.0000555832f, -0.0000621497f, -0.0000658559f, -0.0000573785f, + -0.0000513819f, -0.0000416668f, -0.0000295334f, -0.0000092197f, -0.0000207558f, -0.0000179295f, + -0.0000092361f, -0.0000046097f, 0.0000131986f, 0.0000028970f, 0.0000096778f, 0.0000247417f, + 0.0000038052f, -0.0000064960f, -0.0000124163f, -0.0000092122f, 0.0000515938f, -0.0000831154f, + -0.0001125238f, 0.0000257367f, -0.0000286390f, -0.0000087198f, -0.0000068671f, 0.0000026174f, + 0.0000461536f, 0.0000029284f, -0.0000148640f, 0.0000099199f, -0.0000209369f, -0.0000366334f, + -0.0000401223f, -0.0000191720f, -0.0000276997f, -0.0000075415f, -0.0000235869f, -0.0000261427f, + -0.0000261960f, -0.0000286778f, -0.0000147880f, 0.0000339128f, 0.0000594843f, -0.0000475296f, + -0.0000916631f, -0.0001104448f, -0.0001832659f, -0.0003546036f, -0.0004947290f, -0.0008075304f, + -0.0008607843f, -0.0011759540f, -0.0011280060f, -0.0008472242f, -0.0006581582f, -0.0005496107f, + -0.0003610854f, -0.0001310136f, -0.0000843705f, -0.0001929211f, -0.0001782524f, -0.0001519136f, + -0.0001298443f, -0.0001002354f, -0.0000721302f, 0.0000080280f, -0.0000465158f, -0.0000338343f, + -0.0000199728f, -0.0000188237f, 0.0000123819f, -0.0000217824f, 0.0000285072f, 0.0000230642f, + -0.0000681343f, -0.0001359344f, -0.0002126650f, -0.0001268185f, 0.0002814194f, 0.0005796200f, + -0.0006917457f, -0.0004814411f, 0.0000740708f, 0.0001943933f, 0.0001302339f, 0.0000640566f, + -0.0000644259f, -0.0000257394f, 0.0000673956f, 0.0000057778f, 0.0000578339f, 0.0000733133f, + 0.0000756517f, 0.0000485628f, -0.0000143756f, 0.0000258732f, 0.0000543116f, 0.0000662824f, + 0.0000694890f, 0.0000763443f, 0.0000515654f, -0.0001531987f, -0.0001495108f, 0.0001684928f, + 0.0003371435f, 0.0003492618f, 0.0007408282f, 0.0013614773f, 0.0018283780f, 0.0019512654f, + -0.0018468584f, -0.0019931487f, -0.0021435886f, -0.0019354719f, -0.0018716309f, -0.0015855347f, + -0.0012449413f, -0.0008617653f, -0.0007595430f, -0.0007484226f, -0.0006080124f, -0.0004298524f, + -0.0002469285f, -0.0000337803f, 0.0001833366f, 0.0004827171f, 0.0006187704f, 0.0008525160f, + 0.0010861242f, 0.0012478726f, 0.0014766763f, 0.0016195479f, 0.0016757046f, 0.0017606977f, + 0.0018011194f, 0.0018115391f, 0.0017918594f, 0.0015514538f, 0.0007745483f, 0.0000722375f, + 0.0013858425f, 0.0016550121f, 0.0015724609f, 0.0016037139f, 0.0017032298f, 0.0018041572f, + 0.0018793499f, 0.0019356593f, 0.0020977586f, 0.0022698159f, 0.0024080283f, 0.0025652021f, + 0.0027100014f, 0.0027878510f, 0.0028094267f, 0.0028631331f, 0.0029379588f, 0.0029982766f, + 0.0030408094f, 0.0030637651f, 0.0030520617f, 0.0029707674f, 0.0028257202f, 0.0027032586f, + 0.0025230449f, 0.0021943273f, 0.0018058213f, 0.0015201289f, 0.0010679683f, 0.0003894925f, + -0.0002840705f, -0.0009250455f, -0.0013074121f, -0.0015395618f, -0.0017798333f, -0.0019401547f, + -0.0019524700f, -0.0018826540f, -0.0017220928f, -0.0014455464f, -0.0011010583f, -0.0007116751f, + -0.0002892919f, 0.0001463485f, 0.0005842019f, 0.0009616845f, 0.0013293069f, 0.0016655901f, + 0.0019957600f, 0.0022974838f, 0.0024834913f, 0.0026599403f, 0.0027746423f, 0.0027031419f, + 0.0026172855f, 0.0025078917f, 0.0023497345f, 0.0021702568f, 0.0020425098f, 0.0019860915f, + 0.0018636567f, 0.0011954954f, 0.0005514571f, -0.0000141897f, -0.0005741594f, -0.0011558780f, + -0.0017668142f, -0.0024120809f, -0.0030128714f, -0.0035882532f, -0.0041653667f, -0.0047110318f, + -0.0052436287f, -0.0057623702f, -0.0062633358f, -0.0067586961f, -0.0072425386f, -0.0077278117f, + -0.0082234072f, -0.0087363677f, -0.0092686369f, -0.0098240661f, -0.0104237699f, -0.0111004947f, + -0.0118009488f, -0.0125156239f, -0.0132546394f, -0.0140277665f, -0.0148077168f, -0.0156486149f, + 0.0165211147f, 0.0174398402f, 0.0182775949f, 0.0190534138f, 0.0199230411f, 0.0208118290f, + 0.0217092634f, 0.0226649147f, 0.0237088141f, 0.0248100351f, 0.0259599813f, 0.0271764016f, + 0.0284714021f, 0.0298434758f, 0.0312965027f, 0.0328356927f, 0.0344649815f, 0.0361664394f, + 0.0379470806f, 0.0398139569f, 0.0417666458f, 0.0438027210f, 0.0459314689f, 0.0481532079f, + 0.0504618496f, 0.0528498740f, 0.0553180491f, 0.0578703090f, 0.0604788669f, 0.0631374695f, + 0.0659669298f, 0.0688814001f, 0.0718159332f, 0.0747835495f, 0.0777923399f, 0.0808186627f, + 0.0838554308f, 0.0868947517f, 0.0899116089f, 0.0929041126f, 0.0958553537f, 0.0987459119f, + 0.1015756668f, 0.1043243835f, 0.1069774737f, 0.1095164928f, 0.1119302041f, 0.1142027056f, + 0.1163273532f, 0.1182880738f, 0.1200768686f, 0.1216925159f, 0.1231125873f, 0.1243362384f, + 0.1253610086f, 0.1261745561f, 0.1267721689f, 0.1271241769f, 0.1272284850f, 0.1270239254f, + 0.1267589302f, 0.1264656300f, 0.1258046109f, 0.1248336057f, 0.1235525506f, 0.1219504858f, + 0.1200252469f, 0.1177556666f, 0.1151258716f, 0.1121348547f, 0.1087635447f, 0.1050067776f, + 0.1008590143f, 0.0963144136f, 0.0913759079f, 0.0860427416f, 0.0803171444f, 0.0742040884f, + 0.0677045255f, 0.0608146076f, 0.0535432746f, 0.0458874964f, 0.0378425383f, 0.0294132744f, + 0.0205946670f, 0.0113896330f, 0.0018004463f, -0.0081766098f, -0.0185270856f, -0.0292402963f, + -0.0403618604f, -0.0518892622f, -0.0637672152f, -0.0759976007f, -0.0885871716f, -0.1015258403f, + -0.1148084399f, -0.1284318249f, -0.1423873123f, -0.1566679827f, -0.1712634880f, -0.1861645588f, + -0.2013636452f, -0.2168508609f, -0.2326166940f, -0.2486510515f, -0.2649463144f, -0.2814911369f, + -0.2982752192f, -0.3152867427f, -0.3325116487f, -0.3499355632f, -0.3675395959f, -0.3853024154f, + -0.4032065616f, -0.4212350657f, -0.4393672268f, -0.4575772736f, -0.4758650706f, -0.4942431738f, + 0.5125205124f, 0.5306725282f, 0.5488577283f, 0.5670276108f, 0.5851445237f, 0.6031984616f, + 0.6211684103f, 0.6390281696f, 0.6567504157f, 0.6743123793f, 0.6916889535f, 0.7088542063f, + 0.7257845309f, 0.7424591009f, 0.7588584440f, 0.7749648928f, 0.7907617163f, 0.8062324551f, + 0.8213587554f, 0.8361206884f, 0.8504967301f, 0.8644639148f, 0.8779983070f, 0.8910752510f, + 0.9036722755f, 0.9157691951f, 0.9273480313f, 0.9383949141f, 0.9489012228f, 0.9588586337f, + 0.9682545154f, 0.9770929872f, 0.9853708240f, 0.9930809758f, 1.0002174168f, 1.0067717565f, + 1.0127347711f, 1.0180999340f, 1.0228621525f, 1.0270212624f, 1.0305853696f, 1.0335685634f, + 1.0359921286f, 1.0378851378f, 1.0392782898f, 1.0402014380f, 1.0406826783f, 1.0407387739f, + 1.0403729933f, 1.0395784114f, 1.0383296408f, 1.0365863031f, 1.0343061945f, 1.0314399587f, + 1.0279374991f, 1.0237762412f, 1.0189593836f, 1.0135316260f, 1.0076524569f, 1.0021150619f, + 0.9928949328f, 0.9800034826f, 0.9674886109f, 0.9545877700f, 0.9411740407f, 0.9272370892f, + 0.9128016387f, 0.8979145998f, 0.8826491402f, 0.8670774704f, 0.8512639848f, 0.8352705212f, + 0.8191434022f, 0.8029102780f, 0.7865870046f, 0.7701746598f, 0.7536620391f, 0.7370346195f, + 0.7202763550f, 0.7033730373f, 0.6863185156f, 0.6691140098f, 0.6517679660f, 0.6342966925f, + 0.6167195326f, 0.5990562278f, 0.5813252524f, 0.5635402746f, 0.5457078369f, 0.5278295335f, + 0.5099048467f, 0.4919297136f, 0.4738984035f, 0.4558126317f, 0.4376796414f, 0.4195151253f, + 0.4013417258f, 0.3831842053f, 0.3650685616f, 0.3470163688f, 0.3290362900f, 0.3111247009f, + 0.2932627295f, 0.2754121565f, 0.2575267491f, 0.2395585877f, 0.2214602867f, 0.2032086383f, + 0.1848152793f, 0.1663238479f, 0.1478361334f, 0.1295133662f, 0.1115465981f, 0.0941771468f, + 0.0776828916f, 0.0622889538f, 0.0481725935f, 0.0353986404f, 0.0233593568f, 0.0103354077f, +}; + +const float rot_vec_ana_re_L10[5] = +{ + 2.8262465099f,2.6536058227f,2.2212117088f,1.5713899168f,0.7677495312f, +}; + +const float rot_vec_ana_im_L10[5] = +{ + -0.1110435278f,-0.9789668726f,-1.7510621190f,-2.3517512048f,-2.7222344971f, +}; + +const float rot_vec_ana_re_L16[8] = +{ + 2.2353945156f,2.1817362886f,2.0442351594f,1.8281752196f,1.5418595313f,1.1962910459f, + 0.8047497665f,0.3822824048f, +}; + +const float rot_vec_ana_im_L16[8] = +{ + -0.0548758552f,-0.4899252669f,-0.9061471254f,-1.2875462580f,-1.6194657100f,-1.8891500029f, + -2.0862353207f,-2.2031477851f, +}; + +const float rot_vec_ana_re_L20[10] = +{ + 1.9996144810f,1.9688531362f,1.8896120929f,1.7638425287f,1.5946413075f,1.3861747251f, + 1.1435759205f,0.8728184813f,0.5805693545f,0.2740246834f, +}; + +const float rot_vec_ana_im_L20[10] = +{ + -0.0392673849f,-0.3515925599f,-0.6552603591f,-0.9427934737f,-1.2071118839f,-1.4417071934f, + -1.6408028871f,-1.7994965681f,-1.9138806715f,-1.9811386809f, +}; + +const float rot_vec_ana_re_L30[15] = +{ + 1.6328532594f,1.6216739995f,1.5927273399f,1.5463304262f,1.4829915928f,1.4034047932f, + 1.3084419970f,1.1991436365f,1.0767072074f,0.9424741487f,0.7979151461f,0.6446140182f, + 0.4842503641f,0.3185811618f,0.1494215176f, +}; + +const float rot_vec_ana_im_L30[15] = +{ + -0.0213752201f,-0.1919377663f,-0.3603974022f,-0.5249084488f,-0.6836684885f,-0.8349381133f, + -0.9770599813f,-1.1084769757f,-1.2277492644f,-1.3335700753f,-1.4247800133f,-1.5003797633f, + -1.5595410387f,-1.6016156561f,-1.6261426373f, +}; + +const float rot_vec_ana_re_L32[16] = +{ + 1.5810197732f,1.5715049038f,1.5468555830f,1.5073091974f,1.4532466002f,1.3851884438f, + 1.3037901655f,1.2098356752f,1.1042298059f,0.9879896000f,0.8622345142f,0.7281756387f, + 0.5871040336f,0.4403782958f,0.2894114743f,0.1356574621f, +}; + +const float rot_vec_ana_im_L32[16] = +{ + -0.0194030057f,-0.1742766119f,-0.3274718390f,-0.4775133334f,-0.6229561133f,-0.7623994853f, + -0.8945005334f,-1.0179870525f,-1.1316697997f,-1.2344539482f,-1.3253496303f,-1.4034814709f, + -1.4680970178f,-1.5185739878f,-1.5544262602f,-1.5753085580f, +}; + +const float rot_vec_ana_re_L40[20] = +{ + 1.4141454099f,1.4086967623f,1.3945630307f,1.3718313542f,1.3406418813f,1.3011869053f, + 1.2537096794f,1.1985029164f,1.1359069844f,1.0663078081f,0.9901344896f,0.9078566627f, + 0.8199815976f,0.7270510733f,0.6296380373f,0.5283430735f,0.4237906989f,0.3166255137f, + 0.2075082270f,0.0971115830f, +}; + +const float rot_vec_ana_im_L40[20] = +{ + -0.0138837862f,-0.1247935572f,-0.2349339344f,-0.3436258658f,-0.4501992295f,-0.5539969652f, + -0.6543791254f,-0.7507268207f,-0.8424460355f,-0.9289712904f,-1.0097691283f,-1.0843414038f, + -1.1522283539f,-1.2130114331f,-1.2663158934f,-1.3118130952f,-1.3492225330f,-1.3783135652f, + -1.3989068360f,-1.4108753809f, +}; + +const float rot_vec_ana_re_L60[30] = +{ + 1.1546758066f,1.1526978375f,1.1475604038f,1.1392775867f,1.1278720890f,1.1133751723f, + 1.0958265716f,1.0752743865f,1.0517749490f,1.0253926695f,0.9961998600f,0.9642765358f, + 0.9297101968f,0.8925955867f,0.8530344341f,0.8111351735f,0.7670126477f,0.7207877935f, + 0.6725873102f,0.6225433117f,0.5707929653f,0.5174781151f,0.4627448933f,0.4067433200f, + 0.3496268915f,0.2915521599f,0.2326783042f,0.1731666934f,0.1131804447f,0.0528839763f, +}; + +const float rot_vec_ana_im_L60[30] = +{ + -0.0075574434f,-0.0679781487f,-0.1282125306f,-0.1880954908f,-0.2474628944f,-0.3061520194f, + -0.3640020030f,-0.4208542824f,-0.4765530295f,-0.5309455779f,-0.5838828413f,-0.6352197224f, + -0.6848155104f,-0.7325342668f,-0.7782451976f,-0.8218230124f,-0.8631482675f,-0.9021076931f, + -0.9385945043f,-0.9725086932f,-1.0037573034f,-1.0322546845f,-1.0579227273f,-1.0806910775f, + -1.1004973285f,-1.1172871929f,-1.1310146507f,-1.1416420760f,-1.1491403397f,-1.1534888896f, +}; + + + +const float rot_vec_syn_re_L10[5] = +{ + 0.1117172025f,0.1048929802f,0.0878011021f,0.0621146404f,0.0303479649f, +}; + +const float rot_vec_syn_im_L10[5] = +{ + -0.0043893808f,-0.0386970634f,-0.0692168078f,-0.0929611287f,-0.1076057667f, +}; + +const float rot_vec_syn_re_L16[8] = +{ + 0.1117697258f,0.1090868144f,0.1022117580f,0.0914087610f,0.0770929766f,0.0598145523f, + 0.0402374883f,0.0191141202f, +}; + +const float rot_vec_syn_im_L16[8] = +{ + -0.0027437928f,-0.0244962633f,-0.0453073563f,-0.0643773129f,-0.0809732855f,-0.0944575001f, + -0.1043117660f,-0.1101573893f, +}; + +const float rot_vec_syn_re_L20[10] = +{ + 0.1117818477f,0.1100622363f,0.1056325273f,0.0986017949f,0.0891431591f,0.0774895228f, + 0.0639278374f,0.0487920364f,0.0324548136f,0.0153184455f, +}; + +const float rot_vec_syn_im_L20[10] = +{ + -0.0021951135f,-0.0196546216f,-0.0366301676f,-0.0527037574f,-0.0674796057f,-0.0805938822f, + -0.0917236698f,-0.1005949163f,-0.1069891821f,-0.1107490191f, +}; + +const float rot_vec_syn_re_L30[15] = +{ + 0.1117938204f,0.1110284288f,0.1090465865f,0.1058700070f,0.1015334935f,0.0960845578f, + 0.0895828996f,0.0820997524f,0.0737171032f,0.0645267939f,0.0546295156f,0.0441337048f, + 0.0331543560f,0.0218117611f,0.0102301920f, +}; + +const float rot_vec_syn_im_L30[15] = +{ + -0.0014634613f,-0.0131410805f,-0.0246747234f,-0.0359380248f,-0.0468075816f,-0.0571643048f, + -0.0668947240f,-0.0758922305f,-0.0840582459f,-0.0913033015f,-0.0975480191f,-0.1027239802f, + -0.1067744758f,-0.1096551279f,-0.1113343755f, +}; + +const float rot_vec_syn_re_L32[16] = +{ + 0.1117949803f,0.1111221774f,0.1093792072f,0.1065828555f,0.1027600526f,0.0979476142f, + 0.0921918867f,0.0855483010f,0.0780808384f,0.0698614146f,0.0609691872f,0.0514897932f, + 0.0415145243f,0.0311394479f,0.0204644816f,0.0095924311f, +}; + +const float rot_vec_syn_im_L32[16] = +{ + -0.0013719997f,-0.0123232174f,-0.0231557558f,-0.0337652916f,-0.0440496492f,-0.0539097846f, + -0.0632507393f,-0.0719825548f,-0.0800211389f,-0.0872890758f,-0.0937163711f,-0.0992411265f, + -0.1038101357f,-0.1073793965f,-0.1099145349f,-0.1113911364f, +}; + +const float rot_vec_syn_re_L40[20] = +{ + 0.1117980110f,0.1113672575f,0.1102498879f,0.1084527911f,0.1059870468f,0.1028678571f, + 0.0991144528f,0.0947499750f,0.0898013320f,0.0842990340f,0.0782770044f,0.0717723711f, + 0.0648252372f,0.0574784342f,0.0497772575f,0.0417691875f,0.0335035965f,0.0250314447f, + 0.0164049658f,0.0076773447f, +}; + +const float rot_vec_syn_im_L40[20] = +{ + -0.0010976097f,-0.0098657969f,-0.0185731583f,-0.0271660100f,-0.0355913742f,-0.0437973057f, + -0.0517332122f,-0.0593501664f,-0.0666012069f,-0.0734416290f,-0.0798292589f,-0.0857247149f, + -0.0910916496f,-0.0958969739f,-0.1001110615f,-0.1037079311f,-0.1066654069f,-0.1089652549f, + -0.1105932959f,-0.1115394925f, +}; + +const float rot_vec_syn_re_L60[30] = +{ + 0.1118010042f,0.1116094882f,0.1111120583f,0.1103100780f,0.1092057454f,0.1078020875f, + 0.1061029516f,0.1041129948f,0.1018376715f,0.0992832183f,0.0964566367f,0.0933656741f, + 0.0900188027f,0.0864251961f,0.0825947039f,0.0785378255f,0.0742656803f,0.0697899780f, + 0.0651229863f,0.0602774970f,0.0552667912f,0.0501046030f,0.0448050816f,0.0393827526f, + 0.0338524782f,0.0282294165f,0.0225289799f,0.0167667930f,0.0109586494f,0.0051204690f, +}; + +const float rot_vec_syn_im_L60[30] = +{ + -0.0007317463f,-0.0065819559f,-0.0124141249f,-0.0182122676f,-0.0239604917f,-0.0296430418f, + -0.0352443424f,-0.0407490407f,-0.0461420487f,-0.0514085845f,-0.0565342130f,-0.0615048852f, + -0.0663069767f,-0.0709273254f,-0.0753532672f,-0.0795726710f,-0.0835739716f,-0.0873462018f, + -0.0908790221f,-0.0941627493f,-0.0971883830f,-0.0999476301f,-0.1024329276f,-0.1046374636f, + -0.1065551956f,-0.1081808673f,-0.1095100227f,-0.1105390187f,-0.1112650350f,-0.1116860815f, +}; + + +const float bpf_weights_16[CLDFB_NO_COL_MAX] = +{ + 1.000040f, 0.702561f, 0.208838f, 0.001553f, 0.001777f, 0.001370f, 0.000926f, 0.000554f, + 0.000270f, 0.000080f, 0.000030f, 0.000082f, 0.000081f, 0.000052f, 0.000017f, 0.000016f +}; + +/*-------------------------------------------------------------------* + * LP CNG excitation details code book + *-------------------------------------------------------------------*/ +const float CNG_details_codebook[64][NUM_ENV_CNG]= +{ + { + 6.924306f,8.544082f,9.583108f,8.550549f,7.972679f,7.363361f,8.439027f,7.487016f, + 9.149983f,8.352748f,8.823824f,9.544188f,8.314853f,7.809112f,7.218567f,8.612295f, + 7.780142f,7.232745f,6.965988f,7.568601f + }, + { + 9.374340f,7.795641f,7.379285f,8.396346f,9.895033f,10.221931f,10.015446f,10.087706f, + 10.536375f,10.581183f,10.733459f,10.821303f,10.822197f,10.777159f,10.746262f,10.936824f, + 10.820635f,10.881506f,9.992537f,8.925898f + }, + { + 8.260058f,8.387338f,7.832300f,9.092162f,8.387571f,7.401807f,7.888559f,7.678440f, + 8.136854f,8.515383f,8.772667f,9.228788f,8.836490f,9.518608f,8.908790f,9.499302f, + 9.932305f,10.237994f,10.133189f,8.193151f + }, + { + 10.124639f,10.788106f,10.767182f,10.692019f,10.830482f,9.359397f,10.431694f,11.161179f, + 10.356518f,10.541230f,8.185465f,8.116880f,11.338371f,10.284152f,10.511218f,10.880645f, + 10.220743f,11.179196f,11.066867f,10.445066f + }, + { + 9.726912f,9.842380f,10.314793f,10.252558f,10.717097f,10.746290f,9.953682f,10.412869f, + 9.836176f,8.674436f,7.351096f,7.309156f,7.246638f,6.955070f,7.846981f,9.111964f, + 9.612611f,8.519944f,9.454450f,9.249232f + }, + { + 10.298511f,10.439103f,10.451839f,9.763371f,10.337607f,10.939195f,10.938910f,10.824776f, + 10.976114f,10.974276f,10.754051f,10.581675f,10.222703f,9.126027f,8.198234f,7.695039f, + 6.968823f,7.457246f,9.904172f,9.612813f + }, + { + 9.908430f,10.124971f,10.253873f,8.625096f,8.128853f,8.701863f,10.346726f,10.291558f, + 8.935132f,9.638033f,10.793781f,10.670537f,10.681151f,10.410478f,10.512748f,10.861156f, + 10.653567f,10.911621f,10.629312f,9.736268f + }, + { + 11.810060f,11.612185f,11.468822f,11.083865f,11.406177f,11.832067f,11.661546f,11.277926f, + 7.555347f,8.622866f,12.176802f,10.751250f,10.721958f,9.523929f,9.626828f,11.701570f, + 11.848139f,10.849975f,11.640839f,11.392167f + }, + { + 8.572747f,8.869074f,8.680323f,9.760900f,10.671435f,9.673125f,9.516179f,10.428748f, + 10.353197f,10.692994f,11.081258f,10.146167f,10.790188f,10.432859f,9.273769f,7.979839f, + 8.209611f,9.644866f,8.476103f,10.683167f + }, + { + 8.595222f,7.301031f,8.322734f,11.874195f,11.543133f,10.814659f,12.073861f,11.818481f, + 11.602201f,12.035087f,11.952577f,12.363761f,12.167592f,12.254158f,12.108662f,12.373547f, + 11.860260f,9.014181f,10.036099f,8.638621f + }, + { + 10.275646f,10.526311f,10.252750f,10.178793f,10.466885f,9.088381f,9.273152f,8.119694f, + 7.295121f,7.350810f,8.158489f,9.209213f,9.370357f,9.310070f,9.168746f,9.856857f, + 10.187559f,10.613888f,10.080095f,10.451872f + }, + { + 12.318529f,11.945473f,12.303066f,12.451133f,12.272326f,12.478561f,12.303981f,12.279855f, + 12.189694f,10.818603f,10.013278f,8.600300f,7.832378f,8.014066f,11.346451f,11.673646f, + 10.466306f,10.728513f,11.475281f,12.085626f + }, + { + 10.014422f,10.218554f,10.442979f,10.508470f,10.393559f,10.661362f,10.757983f,10.689740f, + 10.897243f,10.382886f,10.379339f,9.271018f,8.495484f,7.720114f,7.161139f,8.396199f, + 9.721141f,10.159747f,9.918998f,9.919149f + }, + { + 11.034192f,11.766760f,11.903868f,11.195253f,11.683506f,11.900399f,12.318353f,12.368064f, + 12.271189f,12.306809f,12.485785f,12.136335f,12.220796f,11.960956f,11.879458f,11.099092f, + 11.004694f,7.854421f,8.103326f,11.485018f + }, + { + 11.692872f,12.115354f,12.250820f,9.919422f,11.204221f,7.870928f,8.415102f,9.997985f, + 11.942008f,12.149603f,10.633919f,11.269428f,12.354749f,12.288899f,12.291698f,12.195188f, + 12.179792f,12.030136f,12.092098f,12.207270f + }, + { + 11.755179f,8.064263f,9.749080f,12.185180f,11.136729f,11.763196f,8.889953f,8.555951f, + 12.034410f,12.245128f,11.697193f,11.559429f,10.780444f,11.789196f,12.130393f,11.689948f, + 11.623942f,11.399507f,11.981954f,10.904933f + }, + { + 7.074471f,7.358261f,8.067513f,8.080610f,8.765159f,10.199254f,10.289200f,9.618623f, + 9.822992f,9.500810f,10.655619f,10.906424f,10.611357f,10.641397f,10.077725f,9.173571f, + 9.274541f,8.160206f,7.797956f,7.321218f + }, + { + 9.641497f,8.341463f,7.913689f,9.615902f,12.212582f,12.373892f,11.788377f,12.044415f, + 11.569188f,12.302634f,12.361569f,12.119579f,12.223657f,12.303328f,12.384604f,12.306796f, + 12.109153f,12.154896f,10.165297f,11.492375f + }, + { + 10.334753f,9.264669f,7.656600f,7.729103f,7.665664f,7.728192f,8.657525f,10.255910f, + 10.287778f,9.540968f,9.808374f,10.307826f,10.623036f,10.579712f,10.909159f,10.597071f, + 10.508566f,10.917792f,10.740663f,10.609496f + }, + { + 12.464439f,12.387059f,12.281745f,12.415715f,12.481938f,12.064619f,12.051270f,10.871007f, + 9.753584f,8.710700f,7.918756f,8.510613f,11.316961f,11.829647f,11.667075f,12.037048f, + 12.184728f,12.269155f,12.388278f,12.256269f + }, + { + 10.985455f,10.863164f,10.984641f,11.150430f,10.892216f,10.949295f,10.885633f,9.861358f, + 9.347205f,7.782274f,7.420996f,7.042737f,7.859407f,9.545682f,10.120652f,10.378402f, + 10.381286f,10.677829f,10.603589f,10.744861f + }, + { + 11.619549f,10.501878f,10.291579f,11.911536f,12.263100f,11.638079f,11.827111f,11.886570f, + 11.885740f,11.982909f,11.279054f,11.820845f,11.897547f,11.508306f,10.922131f,7.355962f, + 9.090330f,12.035433f,11.309077f,11.814055f + }, + { + 12.109969f,11.648486f,8.360036f,10.628968f,8.450899f,8.016151f,10.885192f,11.289871f, + 11.616718f,11.618735f,12.016033f,11.572757f,11.580486f,11.526383f,12.019007f,12.063487f, + 12.178980f,11.612581f,11.149741f,11.315678f + }, + { + 11.982289f,12.039945f,10.895576f,11.808078f,11.972691f,11.752888f,11.100145f,7.459962f, + 9.401170f,12.240148f,11.661579f,11.968470f,10.817088f,11.060538f,12.236608f,12.217974f, + 11.888335f,12.158744f,12.290771f,12.263520f + }, + { + 7.551557f,9.193432f,10.939713f,10.390559f,10.388751f,10.007786f,10.151727f,11.200849f, + 10.927567f,11.044189f,10.805322f,10.912845f,10.931647f,10.806228f,10.434938f,10.151430f, + 9.517872f,9.532900f,8.436217f,7.561033f + }, + { + 7.914798f,9.662442f,12.315506f,11.969525f,11.779161f,10.819254f,11.074059f,12.259423f, + 12.310757f,12.028122f,12.393316f,12.259255f,12.478424f,12.251179f,11.982938f,12.119265f, + 12.321500f,11.854281f,11.885189f,7.733390f + }, + { + 11.074573f,11.119295f,11.026623f,10.587306f,10.326489f,9.440902f,7.861374f,7.502906f, + 10.206084f,10.379787f,10.375632f,9.986627f,9.698876f,10.544230f,10.857472f,10.772952f, + 11.004036f,10.641294f,11.111090f,11.084974f + }, + { + 12.312282f,11.569094f,12.027453f,11.997540f,12.050622f,12.124397f,11.441438f,11.697535f, + 11.553439f,11.941341f,11.153276f,7.695126f,8.494260f,12.226931f,11.163250f,11.056936f, + 11.197067f,8.736544f,11.552220f,11.995921f + }, + { + 11.841222f,12.040383f,12.323356f,12.164479f,12.146215f,12.485503f,12.354469f,12.261094f, + 12.176959f,12.164176f,11.750998f,10.552405f,11.221596f,7.971972f,7.827245f,9.382548f, + 11.354092f,11.724841f,11.744237f,11.836000f + }, + { + 11.863342f,11.946292f,10.565049f,10.276701f,12.088562f,11.987997f,11.516201f,11.701505f, + 12.013391f,12.254663f,12.160517f,11.530292f,11.789889f,12.011831f,12.307916f,11.817711f, + 7.388736f,8.277118f,12.146955f,11.330376f + }, + { + 10.445749f,10.383992f,11.260086f,10.207924f,7.801878f,12.093586f,12.186577f,12.208809f, + 11.981275f,8.760727f,10.776209f,11.675901f,11.273578f,12.169944f,11.829489f,11.361869f, + 11.931891f,11.640718f,12.033961f,11.504183f + }, + { + 11.418176f,11.996329f,11.634505f,12.108740f,12.232028f,12.223016f,11.168437f,11.585357f, + 12.287769f,10.519855f,11.961341f,12.135221f,11.941004f,11.400546f,12.083041f,12.021441f, + 12.087834f,12.196712f,12.153121f,11.933741f + }, + { + 8.696248f,7.886807f,8.518339f,9.431623f,10.314435f,10.492967f,9.433606f,9.312992f, + 9.056099f,9.558634f,9.174564f,8.692657f,8.529263f,9.327991f,8.283659f,7.715106f, + 6.828506f,7.494133f,8.531253f,8.664100f + }, + { + 8.749990f,9.185427f,7.974370f,7.730459f,9.471635f,11.246136f,11.225875f,11.585999f, + 11.810496f,11.799830f,11.983171f,12.095557f,12.123705f,12.150494f,12.057273f,12.058468f, + 12.128398f,12.119547f,11.788305f,9.252466f + }, + { + 10.620537f,10.064924f,9.681692f,9.556549f,8.067345f,7.460412f,7.355683f,7.793144f, + 7.842898f,9.346528f,10.380497f,9.183150f,10.255505f,10.654870f,10.772358f,10.480097f, + 10.444176f,10.506150f,10.650716f,10.807790f + }, + { + 11.832230f,12.163531f,12.210456f,12.488221f,12.106194f,11.716965f,12.486103f,11.839725f, + 12.333147f,12.101274f,7.643279f,9.040410f,12.480962f,11.550027f,12.089822f,11.299880f, + 10.714154f,12.309387f,12.290308f,12.153176f + }, + { + 11.011459f,10.708299f,10.217109f,10.618895f,10.503453f,10.618390f,10.261137f,9.054105f, + 8.967848f,9.665904f,9.986521f,8.089101f,7.524849f,8.521540f,10.395278f,9.179631f, + 8.431019f,9.362102f,9.471244f,10.168259f + }, + { + 11.385670f,11.988930f,11.979943f,12.082343f,12.240467f,12.163774f,12.389517f,12.076717f, + 12.254186f,12.165658f,11.824725f,11.992508f,10.716744f,10.217215f,10.610125f,8.819359f, + 7.553169f,8.576138f,7.663194f,8.161689f + }, + { + 11.335433f,10.824145f,11.164507f,9.187079f,8.159495f,9.823243f,11.259155f,10.102992f, + 10.894949f,10.692467f,9.597807f,11.322961f,11.068228f,10.523948f,11.179681f,11.389847f, + 11.204894f,11.328845f,10.761085f,11.533332f + }, + { + 12.452473f,12.226961f,12.414132f,12.453005f,12.224496f,11.829764f,9.932276f,9.747059f, + 7.944996f,8.074952f,10.982581f,11.711254f,11.656355f,11.826878f,12.063810f,12.048336f, + 12.100821f,12.339723f,12.171370f,12.491159f + }, + { + 8.693851f,9.237082f,10.193584f,10.816728f,11.382530f,11.124274f,10.905251f,10.747824f, + 11.006325f,11.224193f,11.377479f,11.195903f,11.132830f,10.824033f,11.188758f,8.716391f, + 7.654446f,8.441257f,9.691014f,10.598401f + }, + { + 8.319717f,9.639095f,12.133827f,12.102556f,11.919735f,12.334815f,11.993119f,12.259864f, + 12.158967f,12.356464f,12.374672f,12.379640f,12.396713f,12.146963f,12.203291f,11.311678f, + 8.605060f,10.391322f,8.431939f,7.948593f + }, + { + 11.088415f,10.884553f,11.032227f,11.202397f,10.523194f,10.606202f,9.688022f,9.082882f, + 8.526981f,7.401042f,8.779226f,10.680804f,10.619134f,10.539470f,10.309608f,10.253415f, + 10.965061f,10.624226f,10.946682f,11.063556f + }, + { + 12.049884f,12.395158f,12.315166f,12.298508f,12.409452f,12.353070f,12.369121f,12.232027f, + 12.363715f,12.371237f,11.460312f,12.028971f,8.312684f,8.200596f,10.810326f,11.885057f, + 12.140730f,11.769361f,11.470847f,11.374696f + }, + { + 11.318600f,10.855831f,10.592196f,10.190356f,10.852498f,11.480312f,10.896217f,11.130247f, + 11.148643f,11.272378f,10.871895f,11.095495f,8.893303f,9.083083f,8.899607f,8.150163f, + 10.035096f,11.004933f,11.685496f,11.349737f + }, + { + 12.437282f,11.779876f,12.273005f,12.224300f,11.436580f,12.714269f,12.546281f,12.410135f, + 12.488817f,12.347595f,12.661417f,12.587544f,12.405058f,12.452996f,11.808998f,11.644467f, + 11.697278f,7.908151f,11.580981f,12.178329f + }, + { + 12.383582f,11.978909f,12.263449f,12.181010f,11.308676f,10.129762f,7.630591f,11.672964f, + 12.255041f,12.043112f,12.393015f,11.554902f,11.858689f,12.585340f,12.405621f,12.438987f, + 12.422440f,12.429326f,12.518377f,12.596020f + }, + { + 12.294228f,7.930717f,10.000073f,12.115003f,11.276157f,12.374399f,12.087711f,11.020492f, + 12.205840f,12.519583f,12.094537f,12.497026f,12.274739f,12.595242f,12.627252f,12.238583f, + 12.414072f,12.458577f,12.250254f,12.212063f + }, + { + 10.220644f,10.133038f,9.384470f,9.330061f,9.287414f,10.419335f,10.086744f,10.347366f, + 9.606766f,9.729086f,10.175982f,10.490002f,10.450778f,10.530566f,10.662402f,10.198713f, + 9.756838f,7.568992f,7.395587f,10.386068f + }, + { + 12.338935f,11.958341f,7.484207f,8.228665f,11.650372f,11.382147f,12.027068f,11.762714f, + 11.266207f,12.095256f,12.402075f,12.538692f,12.335326f,12.212730f,12.551470f,12.419568f, + 11.941353f,12.565509f,12.164819f,12.121121f + }, + { + 11.530771f,10.926392f,10.037753f,7.947472f,8.046108f,7.827244f,7.274969f,9.599776f, + 10.971369f,9.563985f,10.664629f,11.255960f,10.737041f,11.198854f,11.004945f,11.547729f, + 11.150601f,11.446258f,11.272099f,11.224279f + }, + { + 12.154252f,12.426224f,12.362570f,12.276526f,11.848105f,12.233492f,12.238678f,11.606319f, + 11.630966f,8.226843f,8.663989f,12.324718f,11.910058f,11.977910f,11.282999f,11.276901f, + 12.135061f,12.316558f,12.126414f,12.222776f + }, + { + 10.840468f,10.882261f,10.935246f,10.880699f,11.083740f,11.099067f,10.870871f,10.768135f, + 10.532293f,10.338410f,9.085450f,8.402101f,7.755022f,9.959888f,10.061506f,10.644034f, + 10.614702f,10.481884f,10.760615f,11.004514f + }, + { + 12.122748f,12.306721f,11.587852f,12.430750f,12.175253f,11.815797f,12.308073f,12.320755f, + 12.218995f,12.463879f,12.424328f,12.559034f,12.042230f,11.765315f,8.922847f,9.539627f, + 7.874360f,8.521064f,9.272277f,12.165272f + }, + { + 12.485865f,11.205798f,11.664264f,10.653128f,7.610178f,8.947474f,11.966330f,12.100983f, + 12.107791f,11.909583f,11.112039f,12.535769f,12.489249f,12.444782f,12.346417f,12.296227f, + 12.534035f,12.334972f,12.077379f,12.275601f + }, + { + 12.425206f,12.450086f,12.341137f,12.568719f,12.320243f,12.361140f,12.099853f,11.035367f, + 8.319082f,12.032015f,12.280725f,11.606254f,12.321961f,11.066000f,11.799191f,12.266534f, + 12.556672f,12.545979f,12.602019f,12.030170f + }, + { + 8.871724f,11.287228f,11.532060f,10.621922f,11.143099f,10.988887f,10.820709f,11.695601f, + 10.989671f,11.008445f,11.567303f,11.250048f,11.122625f,9.865336f,9.707122f,11.365924f, + 11.399251f,11.287416f,8.975295f,9.569743f + }, + { + 9.780970f,11.908114f,11.473997f,12.024678f,11.860840f,11.723680f,12.367899f,12.108915f, + 12.340000f,12.381660f,12.315555f,12.282724f,12.359691f,11.991398f,12.220946f,12.155458f, + 12.413619f,11.642963f,7.867479f,8.503173f + }, + { + 12.100057f,12.246774f,12.168076f,11.771790f,10.224229f,8.752139f,8.276130f,8.317601f, + 8.677964f,10.925248f,11.599258f,10.861567f,11.187905f,11.979478f,12.035626f,12.058556f, + 12.150581f,12.192816f,12.171208f,12.225122f + }, + { + 12.205771f,12.205347f,12.351176f,12.237871f,12.382323f,12.461397f,12.301606f,12.369697f, + 11.959662f,11.558475f,10.953750f,8.388442f,8.819866f,12.077829f,11.983337f,11.818386f, + 12.286803f,12.458479f,12.329653f,12.507854f + }, + { + 11.530513f,11.199886f,12.487312f,12.406390f,12.054689f,12.255518f,12.097314f,12.346512f, + 12.310920f,11.682766f,12.332119f,12.015944f,11.992967f,11.917038f,7.877818f,9.167294f, + 12.226696f,11.735081f,12.256387f,11.444395f + }, + { + 12.132508f,12.328980f,11.918468f,12.068428f,12.493188f,12.275755f,12.524507f,12.294735f, + 12.582710f,12.488275f,12.132201f,12.076183f,12.373331f,11.888222f,11.716764f,10.961454f, + 8.318602f,11.632863f,12.609443f,11.484080f + }, + { + 11.948422f,12.164044f,11.930634f,7.560744f,9.486037f,12.354504f,11.826571f,11.874330f, + 10.939306f,10.727631f,12.333044f,12.133337f,12.172671f,12.228312f,12.004416f,12.354714f, + 12.154241f,11.830939f,12.245022f,12.033812f + }, + { + 12.494522f,12.883386f,12.105121f,12.216132f,12.821167f,10.613010f,12.572326f,12.881424f, + 11.754890f,12.876678f,12.439420f,12.258423f,12.945374f,12.765532f,12.874741f,12.539070f, + 12.711823f,12.611643f,11.904738f,12.176199f + } +}; +/*-------------------------------------------------------------------* + * FD CNG + *-------------------------------------------------------------------*/ + +const int d_array[18] = { 1, 2, 5, 8, 10, 15, 20, 30, 40, 60, 80, 120, 140, 160, 180, 220, 260, 300 }; +const float m_array[18] = { 0.000f, 0.260f, 0.480f, 0.580f, 0.610f, 0.668f, 0.705f, 0.762f, 0.800f, 0.841f, 0.865f, 0.890f, 0.900f, 0.910f, 0.920f, 0.930f, 0.935f, 0.940f }; + +const float msQeqInvAv_thresh[3] = { 0.01f, 0.03f, 0.05f }; +const float msNoiseSlopeMax[4] = { 2.f, 1.6f, 1.3f, 1.1f }; + +const SCALE_SETUP scaleTable[20] = +{ + { 0, 0, 8000, -5.5f }, + { 0, 8000, 9600, -5.0f }, + { 0, 9600, 13200, -4.0f }, + { 0, 13200, 16400, -3.0f }, + { 0, 16400, 24400, -1.5f }, + { 0, 24400,128000, -0.5f }, + + { 1, 0, 8000, -5.5f }, + { 1, 8000, 9600, -5.0f }, + + { 1, 9600, 13200, -1.55f}, + { 1, 13200, 16400, -3.0f }, + + { 1, 16400, 24400, -0.6f }, + { 1, 24400, 64000, -0.2f }, + { 1, 32000,128000, 0.0f }, + + + { 2, 0, 8000, -0.9f }, + { 2, 8000, 9600, -0.65f}, + { 2, 9600, 13200, -2.0f }, + { 2, 13200, 16400, -3.0f }, + + { 2, 16400, 24400, -0.8f }, + { 2, 24400, 32000, -0.25f}, + { 2, 32000,128000, 0.0f }, +}; + +const SCALE_SETUP scaleTable_cn_only[18] = +{ + { 0, 0, 8000, -3.5f }, + { 0, 8000, 9600, -3.0f }, + { 0, 9600, 13200, -2.5f }, + { 0, 13200,16400, -2.0f }, + { 0, 16400,128001, 0.0f }, + + { 1, 0, 8000, -3.0f }, + { 1, 8000, 9600, -2.5f }, + { 1, 9600, 13200, -1.5f }, + { 1, 13200, 16400, -2.5f }, + { 1, 16400, 24400, -0.5f }, + { 1, 24400, 128001, 0.0f }, + + { 2, 0, 8000, -2.5f }, + { 2, 8000, 9600, -2.5f }, + { 2, 9600, 13200, -2.0f }, + { 2, 13200, 16400, -1.0f }, + + { 2, 16400, 24400, -0.5f }, + { 2, 24400, 32000, 0.0f }, + { 2, 32000,128001, 0.0f }, +}; +const float scaleTable_cn_only_amrwbio[3][2] = +{ + { ACELP_6k60, -4.0f }, + { ACELP_8k85, -3.0f }, + { ACELP_12k65, -2.0f }, +}; + + +const int sidparts_encoder_noise_est[24] = { 4, 8, 12, 16, 20, 24, 30, 36, 42, 50, 58, 68, 80, 92, 108, 126, 148, 176, 212, 255, 259, 264, 269, 279 }; + +const int sidPartitions_nb[] = { 4, 8, 12, 16, 20, 24, 30, 36, 42, 50, 58, 68, 80, 92, 108, 126, 159 }; +const int sidPartitions_wb1[] = { 4, 8, 12, 16, 20, 24, 30, 36, 42, 50, 58, 68, 80, 92, 108, 126, 148, 176, 212, 255 }; +const int sidPartitions_wb2[] = { 4, 8, 12, 16, 20, 24, 30, 36, 42, 50, 58, 68, 80, 92, 108, 126, 148, 176, 212, 255, 259 }; +const int sidPartitions_wb3[] = { 4, 8, 12, 16, 20, 24, 30, 36, 42, 50, 58, 68, 80, 92, 108, 126, 148, 176, 212, 255, 319 }; +const int sidPartitions_swb1[] = { 4, 8, 12, 16, 20, 24, 30, 36, 42, 50, 58, 68, 80, 92, 108, 126, 148, 176, 212, 255, 259, 264, 269, 274 }; +const int sidPartitions_swb2[] = { 4, 8, 12, 16, 20, 24, 30, 36, 42, 50, 58, 68, 80, 92, 108, 126, 148, 176, 212, 255, 319, 324, 329, 339 }; + +const int shapingPartitions_nb[] = { 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 25, 28, 31, 34, 37, 40, 43, 47, 51, 55, 59, 64, 69, 74, 80, 86, 93, 100, 108, 117, 126, 136, 159 }; +const int shapingPartitions_wb1[] = { 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 25, 28, 31, 34, 37, 40, 43, 47, 51, 55, 59, 64, 69, 74, 80, 86, 93, 100, 108, 117, 126, 135, 148, 162, 176, 192, 212, 232, 255 }; +const int shapingPartitions_wb2[] = { 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 25, 28, 31, 34, 37, 40, 43, 47, 51, 55, 59, 64, 69, 74, 80, 86, 93, 100, 108, 117, 126, 135, 148, 162, 176, 192, 212, 232, 255 }; +const int shapingPartitions_wb3[] = { 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 25, 28, 31, 34, 37, 40, 43, 47, 51, 55, 59, 64, 69, 74, 80, 86, 93, 100, 108, 117, 126, 136, 148, 176, 212, 256, 308, 319 }; +const int shapingPartitions_swb1[] = { 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 25, 28, 31, 34, 37, 40, 43, 47, 51, 55, 59, 64, 69, 74, 80, 86, 93, 100, 108, 117, 126, 135, 148, 162, 176, 192, 212, 232, 255 }; +const int shapingPartitions_swb2[] = { 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 25, 28, 31, 34, 37, 40, 43, 47, 51, 55, 59, 64, 69, 74, 80, 86, 93, 100, 108, 117, 126, 136, 148, 176, 212, 256, 308, 319 }; + +const FD_CNG_SETUP FdCngSetup_nb = { 512, 160, sizeof(sidPartitions_nb)/sizeof(int), sidPartitions_nb, sizeof(shapingPartitions_nb)/sizeof(int), shapingPartitions_nb }; +const FD_CNG_SETUP FdCngSetup_wb1 = { 512, 256, sizeof(sidPartitions_wb1)/sizeof(int), sidPartitions_wb1, sizeof(shapingPartitions_wb1)/sizeof(int), shapingPartitions_wb1 }; +const FD_CNG_SETUP FdCngSetup_wb2 = { 512, 256, sizeof(sidPartitions_wb2)/sizeof(int), sidPartitions_wb2, sizeof(shapingPartitions_wb2)/sizeof(int), shapingPartitions_wb2 }; +const FD_CNG_SETUP FdCngSetup_wb3 = { 640, 320, sizeof(sidPartitions_wb3)/sizeof(int), sidPartitions_wb3, sizeof(shapingPartitions_wb3)/sizeof(int), shapingPartitions_wb3 }; +const FD_CNG_SETUP FdCngSetup_swb1 = { 512, 256, sizeof(sidPartitions_swb1)/sizeof(int), sidPartitions_swb1, sizeof(shapingPartitions_swb1)/sizeof(int), shapingPartitions_swb1 }; +const FD_CNG_SETUP FdCngSetup_swb2 = { 640, 320, sizeof(sidPartitions_swb2)/sizeof(int), sidPartitions_swb2, sizeof(shapingPartitions_swb2)/sizeof(int), shapingPartitions_swb2 }; + + +const short maxN_37bits = 24; +const short maxC_37bits = 8; +const short stages_37bits = 6; +const int levels_37bits[6] = { 128, 64, 64, 64, 64, 64 }; +const short bits_37bits[6] = { 7, 6, 6, 6, 6, 6 }; + +const float cdk_37bits_1[3072] = +{ + 2.95778982f , 10.56049102f , 13.09386355f , 11.08385962f , 10.88871781f , 10.92789554f , 9.47024852f , 7.50377851f , 7.19700973f , 4.42757028f , 1.25511814f , -2.60106001f , -6.04950165f , -7.63603604f , -10.41446639f , -11.12590625f , -13.84344441f , -18.68891181f , -23.55780389f , -29.45805147f , -31.65253302f , -32.27424892f , -35.22751137f , -36.90949842f , + 17.21398978f , 22.50723507f , 17.78339684f , 15.22053850f , 11.61821405f , 7.94613723f , 7.75072026f , 6.23305331f , 5.76430087f , 4.13707869f , 0.16499081f , -2.39493762f , -1.55086212f , -3.50433708f , -8.18443711f , -11.97061123f , -16.00947999f , -20.53183145f , -25.24387497f , -29.42436369f , -32.38843392f , -36.11523183f , -39.31249120f , -40.92553153f , + 16.16413908f , 12.51338319f , 10.81668845f , 7.51107282f , 8.58783122f , 9.70942586f , 8.90484747f , 7.74361213f , 8.38927229f , 6.09180806f , 2.25606211f , -1.80804139f , -5.77866789f , -6.64266134f , -10.11888694f , -12.07031815f , -15.26437992f , -20.26969656f , -25.12160881f , -31.11024903f , -33.35847205f , -33.13640725f , -35.95124987f , -37.90657962f , + 33.31978298f , 27.26394617f , 24.25514764f , 20.23232332f , 16.65548737f , 15.67786748f , 13.12878045f , 12.68415364f , 8.46975797f , 6.86052690f , 1.44223072f , -3.05984201f , -6.92484285f , -10.16404365f , -13.70298321f , -18.48343165f , -22.58372752f , -26.62074680f , -30.39592772f , -34.37439216f , -36.06769058f , -38.82086191f , -40.35157222f , -41.14327920f , + -10.92203045f , 3.01052036f , 7.74241345f , 9.28295437f , 6.38021756f , 11.19483089f , 9.71179193f , 7.58317778f , 0.03720981f , 2.75397106f , -1.50772774f , -2.01443682f , -2.44887133f , -6.15187538f , -8.81821668f , -8.69151269f , -8.02852922f , -11.09910056f , -13.17097763f , -13.93076356f , -13.66079044f , -16.47777711f , -18.46333278f , -20.06869553f , + 33.16037159f , 28.50574364f , 18.84668394f , 16.14503275f , 12.64238398f , 8.82733160f , 8.27164568f , 6.62567905f , 6.59003037f , 4.47312530f , 0.90824775f , -2.49975515f , -1.08141480f , -3.20431000f , -9.25248952f , -13.89338354f , -18.40719472f , -22.60361057f , -27.04357211f , -31.31499557f , -33.93185338f , -37.43894780f , -40.22405388f , -41.64367850f , + 27.31804653f , 14.89045549f , 10.86226202f , 8.23925819f , 7.20277478f , 6.05860544f , 5.52091762f , 4.91558992f , 4.25466169f , 3.41244595f , 1.84809938f , 0.56793582f , -2.09446303f , -5.61345827f , -7.92063692f , -8.33385890f , -9.81872455f , -14.00821261f , -17.95712781f , -19.97458899f , -22.84515408f , -26.34052831f , -31.61432841f , -36.58172847f , + 41.62594036f , 30.53353379f , 27.89510180f , 24.11265594f , 18.43485443f , 15.64729005f , 13.50845997f , 10.26280433f , 8.91720676f , 5.83154831f , 0.58848737f , -2.93497066f , -7.66347118f , -10.65504548f , -14.43162023f , -17.54532056f , -19.96025099f , -21.34714524f , -24.14933678f , -25.76118364f , -25.95869147f , -27.17577493f , -27.71455668f , -28.20012422f , + -2.78784194f , 8.02032552f , 10.68963597f , 6.42169471f , 8.39643500f , 5.92698403f , 3.72431779f , 2.34240994f , 2.84441568f , 2.28173308f , 0.51005528f , -0.63277332f , -1.88760888f , -3.64699895f , -6.19490118f , -6.91564436f , -6.74837856f , -9.01957311f , -13.08326862f , -15.61846381f , -17.51686622f , -20.98788704f , -24.84189318f , -27.88764499f , + 15.22736138f , 21.67028596f , 22.69998521f , 19.32303652f , 16.57824995f , 14.43971050f , 12.86116984f , 12.06004138f , 8.96691160f , 5.75441483f , 0.69857059f , -2.99592995f , -6.37751956f , -10.52101418f , -13.54087476f , -17.17818777f , -20.74546985f , -23.38284886f , -27.16166346f , -32.39741856f , -34.96265685f , -38.29574314f , -40.21463793f , -40.97396233f , + 9.26133859f , 10.07373727f , 10.66915549f , 8.57462295f , 7.07983445f , 6.08004124f , 5.43616008f , 4.66385278f , 4.13923283f , 3.46291473f , 2.00919193f , 0.41431808f , -2.15659988f , -5.73419766f , -7.77729962f , -8.10963302f , -9.50797759f , -13.76609560f , -17.88454433f , -20.18355620f , -22.78079775f , -26.25300986f , -31.65196065f , -36.72266405f , + 26.92737845f , 27.50669000f , 26.91247977f , 21.31279552f , 16.15678270f , 12.72639800f , 8.67528477f , 8.63540827f , 6.12171634f , 5.39466263f , 2.40935018f , -2.03514541f , -5.98268282f , -9.33268447f , -11.64966136f , -14.87079782f , -16.24856435f , -18.12429449f , -20.78266693f , -23.71237445f , -24.73440188f , -27.34821266f , -28.25918906f , -28.93790683f , + 4.90379335f , 9.93686137f , 10.91780723f , 9.09752074f , 8.60650951f , 8.80459898f , 8.14900070f , 8.09228751f , 4.14934489f , 1.56227390f , 0.22948186f , -2.11175133f , -3.74247153f , -6.07379086f , -7.30507236f , -9.28287821f , -11.07748811f , -12.71211521f , -13.84649241f , -14.34403824f , -15.35123200f , -17.12232100f , -20.33875194f , -23.90062854f , + 34.56400510f , 28.64513545f , 19.89686686f , 16.71498339f , 14.13374646f , 9.59301176f , 8.64527668f , 7.89097544f , 7.45460471f , 4.94035649f , 1.12449009f , -1.91803209f , -2.36876539f , -4.85907115f , -10.96920929f , -15.11783181f , -18.54964139f , -22.92691742f , -27.54026485f , -32.37334407f , -34.34801279f , -37.11646404f , -38.85197445f , -40.08034397f , + 21.85246210f , 14.72764339f , 11.27302628f , 9.14638512f , 8.54804115f , 8.77093797f , 8.12903725f , 8.26861602f , 4.19886932f , 1.54799726f , 0.20257140f , -1.95701999f , -3.69888430f , -6.13502639f , -7.32329151f , -9.38507779f , -11.16665977f , -12.74666897f , -13.89635990f , -14.42352149f , -15.69403582f , -17.31656047f , -20.46657786f , -24.00174177f , + 42.72694479f , 31.23947048f , 24.43494280f , 19.72208465f , 15.30350682f , 10.47491489f , 7.32088994f , 10.21936673f , 9.85497717f , 5.26501746f , 1.65994049f , -1.03290160f , -4.60874619f , -8.54769573f , -14.17151340f , -15.71521704f , -16.02262568f , -18.90844987f , -24.28632557f , -26.72718508f , -27.02265332f , -28.78362362f , -30.43253072f , -32.28558858f , + -0.39765072f , 7.11128294f , 8.77607625f , 6.97094061f , 6.49768999f , 5.29876062f , 5.33292418f , 5.12420845f , 5.06120539f , 3.76514540f , 1.86852875f , 0.36828311f , -2.70182085f , -4.67846439f , -6.65927858f , -8.64219681f , -10.63500087f , -13.14101813f , -15.41381490f , -18.10176174f , -22.39767659f , -26.30065166f , -30.06922086f , -34.02575582f , + 24.65122317f , 23.93886440f , 24.33639262f , 20.20634124f , 14.95533543f , 10.67440066f , 7.90685648f , 7.77227130f , 4.69229603f , 3.94984243f , 1.03135714f , -2.78561381f , -5.59708858f , -8.11252879f , -10.03836955f , -12.17557001f , -12.27299654f , -12.23090635f , -14.81077879f , -18.41474220f , -21.95921345f , -26.31237335f , -28.83347746f , -30.57799152f , + 15.48674375f , 10.58586035f , 8.41258222f , 6.11115928f , 7.26712645f , 7.70076576f , 6.51745234f , 4.83537618f , 3.78315908f , 2.87162280f , 1.60923393f , 0.07194700f , -4.00474978f , -3.57899280f , -6.50550572f , -8.00337288f , -12.56429875f , -16.64572160f , -21.77660604f , -29.00324770f , -29.28924218f , -28.45842093f , -31.46000362f , -33.72961920f , + 31.66756941f , 26.50681469f , 23.07696706f , 19.47940753f , 16.43776948f , 14.65422928f , 13.13762571f , 12.13565647f , 9.05541090f , 5.85409354f , 0.53053075f , -3.03585502f , -6.54517878f , -10.70179318f , -13.64861349f , -17.10229453f , -20.77152138f , -23.04102596f , -26.76284884f , -32.09288570f , -34.95454717f , -38.37953105f , -40.31456890f , -41.06305403f , + -4.57998646f , 6.78815016f , 11.60677893f , 12.12189632f , 10.03649399f , 6.73163226f , 5.60997256f , 3.61382681f , 1.07119505f , 1.44124760f , -0.36649688f , -1.93594310f , -2.67098539f , -3.97236341f , -4.49309238f , -7.67841048f , -7.38721745f , -9.04687595f , -10.64729812f , -12.35782845f , -15.80889240f , -18.10394377f , -20.75255913f , -23.16714596f , + 32.06565538f , 26.34062469f , 17.62317465f , 14.54318257f , 11.33965592f , 7.22380894f , 6.69999570f , 5.16548324f , 5.32078994f , 3.68894995f , 0.21139809f , -1.89643313f , -1.43729232f , -3.38299704f , -8.16315990f , -10.90725548f , -13.86285241f , -19.27930679f , -24.24221687f , -29.37957484f , -32.97371289f , -37.01956565f , -40.64301363f , -42.42283871f , + 27.34861464f , 17.35254831f , 14.71216625f , 11.21480476f , 9.71751794f , 8.92216110f , 7.88950008f , 4.72051984f , 2.08541644f , 1.24484417f , -0.29448212f , -3.22367745f , -4.12078688f , -4.51431029f , -5.02457729f , -7.46382757f , -9.93828200f , -11.94075167f , -14.42548881f , -16.83893529f , -20.57517980f , -23.86145012f , -26.35488436f , -28.09220448f , + 43.77568289f , 30.35391726f , 27.63839793f , 23.39292280f , 18.14120263f , 16.09279111f , 13.38540751f , 10.06671431f , 7.94669649f , 4.12623028f , -0.90332148f , -3.32951717f , -7.24035516f , -10.01970377f , -13.39421641f , -16.33052649f , -18.54117920f , -19.77745925f , -22.77363614f , -24.12093907f , -24.21920369f , -25.28960607f , -25.77614399f , -26.25683024f , + 5.79368652f , 12.51991626f , 14.00370768f , 11.32137999f , 9.77109082f , 8.98151357f , 7.49776119f , 4.79998026f , 2.33448317f , 1.18610607f , -0.35969383f , -2.93257557f , -4.07562790f , -4.76160858f , -5.42531466f , -7.40360649f , -9.61250822f , -11.03547938f , -13.14054419f , -15.06085658f , -17.47288279f , -20.42082642f , -22.95063518f , -25.16468847f , + 16.09302292f , 22.55335432f , 23.75600812f , 20.07565839f , 16.86390794f , 15.22041485f , 13.34925505f , 12.47627523f , 8.78929960f , 6.22941075f , 0.65362548f , -3.19021243f , -6.62717988f , -10.64596960f , -13.82088718f , -17.58372103f , -21.71419292f , -24.30895894f , -26.77314588f , -28.87032013f , -30.13179973f , -31.71459259f , -32.84856396f , -33.50577477f , + 16.44441330f , 12.31360615f , 9.71047235f , 7.21837937f , 6.79215980f , 5.58913206f , 5.23450348f , 5.31837117f , 5.47119664f , 3.91860558f , 2.00713858f , 0.29754081f , -2.62407946f , -4.75220497f , -6.96490868f , -9.09693835f , -11.19050998f , -13.60732328f , -15.96794842f , -18.87093112f , -23.15019536f , -27.14449468f , -31.05584505f , -35.00208930f , + 21.56078764f , 25.60904841f , 27.31524375f , 24.74664217f , 19.15754045f , 16.48262030f , 13.62284337f , 10.32185769f , 7.82788054f , 4.56867787f , -0.55500429f , -3.54399244f , -7.74464129f , -10.04653026f , -13.91638701f , -16.89276027f , -19.28210045f , -21.11725885f , -23.80905063f , -25.61468851f , -25.54369860f , -26.75644280f , -27.40565527f , -27.80349551f , + 11.75649526f , 11.59267300f , 11.85607639f , 12.09984636f , 10.17904946f , 6.68242306f , 5.49769393f , 3.62565532f , 1.04153359f , 1.37348105f , -0.36614776f , -1.85988088f , -2.65180489f , -3.95188781f , -4.54582064f , -7.65185164f , -7.37260518f , -8.94498668f , -10.57379044f , -12.29831281f , -15.91573373f , -18.15620068f , -20.77255846f , -23.17991063f , + 35.63174061f , 30.87426279f , 20.05864161f , 16.98958650f , 13.11156738f , 9.37587068f , 8.39373792f , 6.91457513f , 7.06726843f , 4.45504564f , 0.31410924f , -2.55476072f , -1.55052341f , -3.58183174f , -10.02850753f , -13.83773408f , -18.07893844f , -21.87127412f , -26.40618053f , -30.05923316f , -32.16211735f , -34.97392895f , -36.96538585f , -38.31916152f , + 22.45827967f , 18.85001245f , 13.60039332f , 10.10815816f , 9.34790218f , 6.59206524f , 5.06185868f , 4.27885917f , 3.12432252f , 2.43301895f , 0.16458112f , -0.87956151f , -3.52884867f , -4.30776590f , -5.96584396f , -7.24696688f , -9.07355786f , -10.64880142f , -12.04156041f , -13.57831230f , -16.13223545f , -19.28691238f , -20.73379126f , -22.35985284f , + 45.50285910f , 30.56079275f , 25.12585245f , 19.34243209f , 14.67812492f , 11.09479624f , 7.62809337f , 7.36329508f , 5.02791068f , 4.57220923f , 1.95015079f , -1.57507512f , -5.20307171f , -7.99911947f , -9.95812261f , -13.13787688f , -14.44121237f , -16.19333355f , -19.15028237f , -22.75607672f , -25.37417688f , -27.76304019f , -28.42538941f , -29.09271083f , + -0.20862409f , 7.40922209f , 9.52611206f , 7.19556599f , 8.56285670f , 9.23113851f , 8.29119614f , 6.74033461f , 7.39436505f , 4.76996743f , 1.52467647f , -2.37784656f , -6.09813737f , -6.29918182f , -8.30626415f , -10.26550962f , -13.16761101f , -17.25290821f , -21.82832704f , -28.08208094f , -29.69995762f , -30.02997066f , -32.54067640f , -34.86791052f , + 20.15336204f , 23.69787743f , 20.03743258f , 17.32388877f , 13.85816349f , 9.75929930f , 8.81062377f , 7.33399060f , 7.03590133f , 4.83049697f , 0.70944621f , -2.33770508f , -2.40423376f , -4.83395025f , -10.23084612f , -14.36365636f , -18.16750414f , -21.75786888f , -26.07319165f , -30.47064791f , -32.03827614f , -34.62324863f , -36.38403786f , -37.62380175f , + 21.02807550f , 15.43123168f , 13.19159292f , 11.05909310f , 9.93532083f , 10.14330557f , 8.44788836f , 7.05092375f , 6.65547179f , 3.80156734f , 1.01028469f , -2.51036572f , -5.52907299f , -7.16917980f , -9.69618129f , -9.79583611f , -12.34407663f , -16.35321338f , -21.00738251f , -27.34102498f , -30.48319293f , -30.90104975f , -33.93924526f , -35.92883268f , + 33.46103317f , 28.05909534f , 25.27576527f , 21.45366856f , 18.39016725f , 16.16268691f , 14.43168731f , 12.88073327f , 9.27668693f , 6.28692861f , 0.27771848f , -3.24264663f , -7.02703161f , -11.49310707f , -14.63223263f , -18.01065380f , -23.30098657f , -26.04536683f , -29.97889152f , -33.31061266f , -34.90527704f , -37.51005914f , -38.89607504f , -39.43668242f , + -6.19448103f , 7.00670386f , 6.42929262f , 11.44842292f , 10.59782711f , 3.51908910f , 5.03700693f , 11.99440282f , 2.46784279f , 2.52636549f , 0.19509676f , -0.66292825f , -3.57724994f , -4.27935354f , -7.71003982f , -9.31027578f , -10.79777387f , -12.03284160f , -14.50955075f , -15.24259860f , -15.04293408f , -17.84913152f , -19.24800026f , -20.43127990f , + 34.36219386f , 29.15654122f , 17.89907772f , 15.96853719f , 12.24737290f , 8.58997407f , 8.02028124f , 6.73852407f , 6.68229615f , 4.41515543f , 0.31647818f , -2.71422396f , -1.11008623f , -3.15418403f , -8.78373906f , -13.46164937f , -17.78623382f , -22.03141049f , -26.52011865f , -30.42263732f , -32.88924845f , -36.52063092f , -39.44879402f , -41.00582791f , + 28.59389870f , 16.57976885f , 11.69506951f , 9.00946677f , 6.59434708f , 5.58892350f , 5.15576244f , 4.26874238f , 3.83962965f , 3.10490992f , 1.74950191f , 0.21359494f , -2.34614415f , -5.90830965f , -7.32978245f , -6.79210755f , -8.13921426f , -12.39307835f , -16.42105838f , -17.81533132f , -20.43309456f , -23.50336304f , -28.11010949f , -32.19800165f , + 42.18709382f , 31.66042119f , 28.18576191f , 24.02454209f , 17.80243401f , 14.32604318f , 12.38219020f , 9.68299766f , 9.84153789f , 7.22418488f , 1.90320264f , -0.79109427f , -7.30502888f , -10.99217358f , -15.03902326f , -18.25651222f , -20.77870269f , -22.27969332f , -25.21134893f , -26.73864852f , -26.81597564f , -28.06561283f , -28.74871236f , -29.19027505f , + 3.14453423f , 9.82704694f , 10.42102234f , 7.53076819f , 6.65445918f , 5.42078795f , 4.35248487f , 3.38200688f , 3.34653224f , 2.23758939f , 0.98007038f , -0.82512415f , -3.06552968f , -3.74092446f , -5.19946109f , -6.26762478f , -7.27519640f , -9.56355666f , -11.49652218f , -12.93977382f , -15.16570550f , -17.89500321f , -20.88144101f , -24.27090982f , + 16.89397941f , 22.41751392f , 23.75354684f , 20.15652247f , 16.71460178f , 15.68435339f , 13.05195327f , 12.59734003f , 8.36320984f , 6.61926140f , 1.34089883f , -3.04095047f , -6.87072914f , -10.11874127f , -13.60230073f , -18.32905014f , -22.40986754f , -26.40241648f , -30.22653356f , -34.35524827f , -35.82875887f , -38.56697745f , -40.04466299f , -40.77890542f , + 14.06040489f , 12.38456984f , 11.38443857f , 6.43429982f , 8.36024783f , 5.74773204f , 3.64617779f , 2.27891511f , 2.88575114f , 2.28853033f , 0.47176709f , -0.58104559f , -1.80751192f , -3.57542575f , -6.25556579f , -6.84838146f , -6.61115232f , -8.86429480f , -13.12243997f , -15.53130507f , -17.39294606f , -20.82817234f , -24.80352676f , -27.90102832f , + 29.08127657f , 30.25267470f , 28.50445786f , 22.88590940f , 16.95382919f , 12.99666306f , 9.24548766f , 10.17354633f , 7.44385880f , 5.98968070f , 1.98160871f , -1.99320988f , -6.45502374f , -10.08296200f , -12.58332338f , -15.94023376f , -17.72993147f , -19.46222023f , -22.64433239f , -25.73538061f , -25.10103202f , -27.34115443f , -28.00719352f , -28.71283003f , + 10.44191657f , 11.89739900f , 6.63050752f , 11.66862838f , 10.95389970f , 3.62853936f , 5.27338772f , 12.22397146f , 2.38303236f , 2.27598761f , 0.20057759f , -0.69953882f , -3.74592500f , -4.11363308f , -7.73279200f , -9.56396050f , -11.08358715f , -12.21155490f , -14.86254610f , -15.45527754f , -15.28325702f , -17.98672312f , -19.17774681f , -20.23644212f , + 35.53276331f , 29.79176377f , 19.61709874f , 16.86634001f , 13.09981576f , 9.35098387f , 8.47743299f , 7.04997634f , 7.03070014f , 4.96729480f , 0.92976195f , -2.31151272f , -1.83127970f , -4.34635324f , -9.67542557f , -14.26377116f , -18.47764765f , -22.80532113f , -27.40873215f , -31.63558241f , -33.75926234f , -36.57926085f , -38.64751733f , -39.92187198f , + 19.57623370f , 14.52227951f , 10.90006748f , 7.46479458f , 6.57710504f , 5.35248052f , 4.32022732f , 3.44261943f , 3.11088406f , 2.14252838f , 0.91565155f , -0.88167185f , -3.01132437f , -3.66994851f , -5.19376018f , -6.09616750f , -7.00842420f , -9.47621384f , -11.55078876f , -12.93214130f , -15.11703243f , -17.74349778f , -20.81631949f , -24.26610975f , + 45.46539087f , 33.65225910f , 27.04759024f , 20.37287228f , 15.20605258f , 10.95754596f , 8.25353280f , 10.41134779f , 9.16332898f , 5.00593619f , 1.56893245f , -0.96934543f , -4.76115225f , -9.35265480f , -13.96830603f , -15.58493281f , -15.93026458f , -18.72056170f , -22.62999991f , -24.01724401f , -24.13966976f , -25.75662986f , -27.30657872f , -29.31976842f , + 3.35383892f , 10.46089277f , 12.67572651f , 10.67316057f , 8.86420657f , 7.41699857f , 6.40472576f , 5.55584594f , 4.78140149f , 3.39101090f , 1.64891901f , -0.88431535f , -3.41794053f , -5.52966105f , -7.12950981f , -9.73843277f , -11.36318390f , -12.90076410f , -15.02653519f , -17.80793193f , -20.85950171f , -24.60915288f , -28.33117068f , -31.97961671f , + 24.16381226f , 26.61189391f , 24.86498593f , 19.87730202f , 15.18991454f , 10.98879994f , 7.42531150f , 10.49136744f , 9.62334804f , 4.97806393f , 1.38953872f , -1.07543238f , -4.87438861f , -8.84994346f , -14.12865608f , -15.38136709f , -15.77648418f , -18.65254160f , -24.07064465f , -26.65375941f , -26.62799211f , -28.37449714f , -30.00703668f , -31.95561063f , + 16.73297197f , 13.40079340f , 11.36295685f , 8.12888004f , 8.67057438f , 9.98791316f , 7.17503401f , 3.41805962f , 3.84708100f , 3.38229324f , 1.69308513f , -2.44779633f , -7.15056120f , -5.22964233f , -5.71002448f , -7.24979808f , -10.38621901f , -12.40506839f , -16.88434384f , -24.40525376f , -27.96468183f , -28.87188624f , -31.73758135f , -34.45997553f , + 36.82320664f , 30.14889839f , 24.36495733f , 19.95821910f , 17.28215670f , 15.34405446f , 12.71014649f , 11.84061146f , 8.74552404f , 5.19431776f , 0.62656711f , -3.30567052f , -7.09245555f , -11.63075940f , -14.43930927f , -16.55893715f , -18.71623060f , -21.39863923f , -24.41215684f , -27.71989721f , -29.44073312f , -31.13601153f , -33.00550113f , -35.01755294f , + -0.75323250f , -0.49333543f , -0.03686038f , 0.00580498f , -0.02595636f , -0.42521553f , -0.11620129f , 0.04925008f , -0.22349130f , -0.41036697f , -0.08797780f , -0.31029326f , -0.33370732f , -0.04414976f , -0.18188899f , -0.39067975f , -0.19015430f , -0.13924769f , -0.07489774f , -0.24338076f , 0.02616867f , -0.90654191f , -0.36674078f , -0.92659945f , + 32.82257425f , 26.93225108f , 17.97275820f , 15.52062575f , 12.24580971f , 7.87298134f , 7.92790101f , 6.69153001f , 6.20377725f , 4.87524910f , 0.20987746f , -2.32068931f , -1.19022086f , -3.62043573f , -8.66527100f , -13.17653707f , -17.05395098f , -21.30672374f , -26.02442938f , -29.84148775f , -32.77866358f , -36.44067731f , -39.64793075f , -41.28669431f , + 23.66104031f , 18.77341211f , 15.43023272f , 11.20366406f , 8.42366176f , 6.11675293f , 5.33405011f , 5.20406381f , 4.67626106f , 3.65065286f , 1.53469689f , -1.60771292f , -3.81129242f , -4.57130038f , -6.33850722f , -8.60971199f , -10.00167377f , -11.97538710f , -14.16507562f , -16.60464075f , -19.14351164f , -22.49496272f , -25.49215425f , -28.47836779f , + 48.83791360f , 34.21172740f , 28.24854170f , 23.78581370f , 19.15275096f , 16.36583739f , 13.52652252f , 12.00825971f , 7.58820783f , 4.57182675f , -0.44096755f , -5.59444127f , -9.20335237f , -11.60423121f , -13.38376584f , -15.82699559f , -17.15943218f , -18.22349154f , -21.00159236f , -23.41802307f , -24.09185136f , -26.12025700f , -26.38389340f , -26.90015217f , + 5.65030538f , 13.78536254f , 12.93384260f , 10.10554338f , 9.25200312f , 6.70079894f , 4.97946459f , 4.14010675f , 3.20266413f , 2.24703740f , 0.17096077f , -0.76854332f , -3.49746682f , -4.40509828f , -5.92984501f , -7.16813639f , -8.92390949f , -10.44235555f , -11.73970476f , -13.07525739f , -15.58860787f , -18.82754905f , -20.11226045f , -21.89670528f , + 20.00764046f , 25.05163905f , 23.67903478f , 19.61532654f , 16.85580272f , 14.84943508f , 12.32422151f , 11.72685290f , 8.55557474f , 4.89724925f , 0.62350153f , -3.12200178f , -6.95129787f , -11.32051330f , -13.87728564f , -16.20738435f , -18.35417789f , -21.22501359f , -24.26412556f , -27.53754401f , -29.04562197f , -30.52655890f , -32.50623950f , -34.76405591f , + 20.12464864f , 15.20430829f , 13.25055947f , 10.65904743f , 8.91134621f , 7.46363884f , 6.44402323f , 5.71195079f , 4.79807746f , 3.49335087f , 1.75260934f , -0.74115357f , -3.42285816f , -5.45747278f , -7.23479115f , -10.08709890f , -11.63154322f , -13.05708157f , -15.18339592f , -18.14822179f , -21.33849269f , -25.01926113f , -28.92560049f , -32.56657725f , + 26.54656966f , 26.13227118f , 27.82488903f , 24.22335030f , 18.87683777f , 16.59425031f , 13.64047520f , 9.75915298f , 7.28698308f , 4.09515905f , -0.71835272f , -3.26926527f , -7.31384281f , -9.98624418f , -13.59589213f , -16.50790941f , -18.86147233f , -20.11404881f , -22.88197092f , -24.35845023f , -23.98592903f , -25.19061201f , -25.66357488f , -26.11120895f , + 16.92428437f , 15.63926123f , 14.68264077f , 9.17511817f , 11.72199221f , 8.73358423f , 5.74525565f , 3.31019020f , 3.82744364f , 2.82061126f , 0.00479914f , -1.62974092f , -3.21227479f , -5.78430830f , -8.71508730f , -8.80926274f , -8.01316743f , -9.54120965f , -13.35104985f , -15.74348284f , -16.40121304f , -19.46521021f , -22.26957651f , -24.80475300f , + 33.27372786f , 28.98123208f , 18.52554956f , 16.22324845f , 11.82428088f , 8.06497636f , 6.95248523f , 6.23909474f , 5.55428912f , 3.52189864f , 0.54297482f , -2.65061141f , -0.24235908f , -2.49418732f , -8.10730403f , -12.50952978f , -16.69612524f , -20.49938193f , -23.81401973f , -26.29697125f , -27.78204736f , -29.60465452f , -31.26624714f , -32.52437926f , + 27.66207964f , 21.38029622f , 15.28817924f , 11.29865816f , 7.24050384f , 4.07114269f , 2.23434724f , 2.00312407f , 2.12063407f , 2.37092879f , 1.11181974f , -0.06676605f , -1.62128339f , -3.18849566f , -4.50247820f , -5.27330824f , -6.50012921f , -8.95962773f , -11.25753877f , -13.15591465f , -15.55510117f , -17.77008388f , -21.51057093f , -23.68928360f , + 46.17063826f , 35.44350933f , 27.63882719f , 20.58749084f , 15.09358456f , 11.34450671f , 8.36303546f , 10.32329718f , 9.40828446f , 4.81846192f , 1.44590103f , -1.30265822f , -4.80681268f , -9.60995360f , -14.00088486f , -15.02315852f , -16.05368713f , -18.40913671f , -21.04455075f , -21.77101439f , -21.86714844f , -23.34699503f , -24.81999799f , -26.75598881f , + 5.55447222f , 11.08900430f , 12.67418749f , 11.37730706f , 10.35233661f , 9.77194599f , 7.54804411f , 5.59512280f , 5.26611322f , 3.61130922f , 1.29867980f , -1.53794101f , -4.94548169f , -6.44099913f , -9.14750567f , -9.26394627f , -12.10780921f , -16.54821135f , -21.09601890f , -27.26975914f , -29.20341664f , -29.16031453f , -32.31338409f , -33.81412751f , + 18.12507160f , 24.70366354f , 18.80553588f , 16.44619360f , 12.73212014f , 8.73243452f , 8.13965750f , 6.85564846f , 6.54211122f , 4.41684143f , 0.86730242f , -2.56492428f , -1.51931938f , -3.44405406f , -9.13992613f , -13.62181635f , -17.99613747f , -22.23637312f , -26.67002377f , -30.83211183f , -32.97908996f , -36.30619371f , -38.88768859f , -40.31682212f , + 19.30313062f , 15.53926343f , 13.90808840f , 11.50585735f , 11.38433252f , 11.23569306f , 9.65078250f , 7.30888386f , 6.96318572f , 4.35594359f , 1.27768650f , -2.51618855f , -6.09345175f , -7.65932096f , -10.43421302f , -11.30754584f , -14.16597758f , -18.97180923f , -23.84334763f , -29.44331171f , -31.44436223f , -32.10318621f , -34.92490176f , -36.47617953f , + 32.84070800f , 26.98843227f , 23.97706735f , 20.09690811f , 17.17772395f , 15.21303519f , 13.42060419f , 12.43874328f , 9.15968596f , 6.16038922f , 0.71905975f , -2.92001972f , -6.40947412f , -10.83784032f , -13.95928861f , -17.62432172f , -22.53835937f , -25.41550617f , -29.42258267f , -33.41667068f , -35.41334436f , -38.22281954f , -39.80199786f , -40.32675160f , + -9.91625093f , 4.80418237f , 9.08604693f , 11.01664820f , 7.24939971f , 12.00629737f , 10.14522962f , 7.79868426f , 0.03388286f , 3.22894410f , -1.49188110f , -1.77551920f , -5.08350600f , -6.11630690f , -8.19142417f , -8.31829806f , -9.48559967f , -10.78591755f , -12.34898021f , -13.04347069f , -12.86564050f , -16.09519878f , -17.66110352f , -20.13284843f , + 33.93076696f , 29.73735327f , 19.23905822f , 17.23103235f , 12.77046694f , 8.83451844f , 8.23785020f , 7.11377423f , 6.72823159f , 4.05823561f , 1.17653434f , -2.62333502f , -1.84527480f , -3.46714831f , -9.29420158f , -13.72585514f , -17.96342825f , -22.04254130f , -26.29305138f , -30.25871596f , -32.43685342f , -36.04907640f , -39.16814132f , -40.73022661f , + 30.53206150f , 19.40488473f , 12.75598255f , 9.25954864f , 6.70414010f , 5.72747123f , 5.03381227f , 4.01075984f , 3.61146616f , 3.58899760f , 2.32432976f , 0.53033441f , -2.14938224f , -5.59608713f , -7.14094606f , -7.65425973f , -8.99080383f , -12.95963757f , -17.18036927f , -19.46195053f , -21.56000305f , -24.52225545f , -30.08064474f , -35.71887681f , + 43.21595883f , 30.91880384f , 28.28763915f , 25.00936743f , 19.09701763f , 16.45025980f , 13.97496410f , 11.13694940f , 8.55554358f , 4.99105536f , -0.75976252f , -4.26698912f , -8.42682321f , -9.48353121f , -14.21251069f , -17.24378853f , -19.81223810f , -21.34834559f , -23.80150703f , -25.40905846f , -25.28209830f , -26.22742436f , -26.66260243f , -27.01651200f , + -0.14361434f , 11.33097675f , 14.22933286f , 9.09701983f , 11.66148024f , 8.76183273f , 5.66551557f , 3.17860698f , 3.87061452f , 2.88805964f , 0.11657889f , -1.62298350f , -3.19956391f , -5.77861831f , -8.72933989f , -8.83773190f , -7.97439380f , -9.53621475f , -13.35824515f , -15.73862835f , -16.23732929f , -19.37222733f , -22.16495373f , -24.69705224f , + 14.97516906f , 20.24358485f , 21.71690634f , 18.67539860f , 16.12099511f , 13.68136380f , 12.06765212f , 10.76593030f , 7.44448363f , 4.69310947f , 0.32375113f , -2.82379840f , -6.24406445f , -9.85549248f , -12.35464306f , -15.66193154f , -18.15727457f , -19.51476533f , -21.69116638f , -26.65585670f , -30.96969557f , -34.93908838f , -37.17487414f , -38.69523980f , + 11.79211750f , 11.97065541f , 11.42461150f , 9.07103015f , 6.75482034f , 5.60897088f , 5.19878959f , 4.12715904f , 3.68541174f , 3.10916340f , 1.75493030f , 0.12722322f , -2.45721866f , -5.96134122f , -7.29240229f , -6.69634000f , -7.95934523f , -12.27446428f , -16.49521939f , -17.81789512f , -20.15378269f , -23.44933417f , -28.12142909f , -32.19480869f , + 31.52643526f , 28.52259080f , 26.69926841f , 20.98459124f , 15.75207892f , 11.93364546f , 8.26555040f , 7.77743568f , 5.47651258f , 4.83040775f , 1.65268569f , -2.13370539f , -5.16522881f , -8.08709801f , -10.71942352f , -14.02185419f , -15.56110704f , -16.98333790f , -19.99452598f , -22.68342788f , -23.41377838f , -25.94358058f , -26.53240068f , -27.12327850f , + 6.80087128f , 11.58644896f , 12.45313320f , 10.29597723f , 9.18481781f , 8.48775117f , 7.26614653f , 5.90419380f , 4.38057275f , 2.43656205f , 0.69276327f , -1.81218785f , -3.96339389f , -5.75303899f , -7.09187068f , -8.88618164f , -10.84611660f , -12.42796224f , -13.13959174f , -13.43223783f , -14.11628112f , -15.89113608f , -18.99839794f , -22.60584539f , + 36.38520889f , 28.78012839f , 21.05496218f , 17.53636167f , 13.96758507f , 11.67472760f , 10.42791533f , 9.67412184f , 7.27606489f , 5.56430120f , 0.35452150f , -3.04945909f , -3.73479650f , -6.39521181f , -11.23696830f , -15.42073952f , -19.10245341f , -22.52588883f , -26.73438324f , -31.13547298f , -32.74648378f , -35.08411011f , -36.64862406f , -37.83303410f , + 23.44391246f , 16.34449728f , 12.74386848f , 10.37728433f , 9.26531402f , 8.62835052f , 7.30803355f , 5.91607884f , 4.36863155f , 2.42037310f , 0.72270664f , -1.87419199f , -3.98816276f , -5.80775521f , -7.13994994f , -8.93853756f , -10.88091925f , -12.48019720f , -13.11652631f , -13.43063220f , -14.21381571f , -15.91218672f , -19.00174998f , -22.61508378f , + 42.41685465f , 32.92785864f , 26.73527519f , 20.02657328f , 15.25763921f , 11.51912083f , 7.75120808f , 10.47560309f , 9.43865509f , 4.72161580f , 1.23456822f , -1.24509427f , -5.12070011f , -8.97924223f , -14.13085652f , -15.32553884f , -15.59705390f , -18.30233488f , -23.33478017f , -25.58695872f , -25.86117061f , -27.64564989f , -29.28904725f , -31.28074013f , + 1.52342001f , 9.12417569f , 10.32715957f , 8.66545459f , 7.07445753f , 5.84320555f , 5.74305920f , 4.78929426f , 4.24381536f , 2.93093263f , 1.43577760f , -0.53860173f , -3.06985625f , -4.84378216f , -6.19218421f , -7.82485861f , -9.59127476f , -11.55775664f , -13.43280469f , -15.63550289f , -19.62772693f , -22.98849208f , -25.64470241f , -28.78809716f , + 25.56643800f , 24.60767519f , 24.69578809f , 19.70646081f , 15.16249776f , 11.52050408f , 7.81769903f , 7.63275125f , 5.49767989f , 4.82720507f , 1.97596070f , -1.66260544f , -5.25016669f , -8.43401653f , -10.50840106f , -13.66164463f , -14.91737550f , -16.34161902f , -19.45629644f , -23.46159848f , -25.62249781f , -27.82515036f , -28.34414019f , -28.79284328f , + 16.92655154f , 13.22739747f , 11.12354116f , 8.43784353f , 9.39924384f , 10.05896738f , 8.60043956f , 6.03413409f , 6.90507663f , 4.38541942f , 1.33274141f , -3.40564903f , -6.91513167f , -6.87459047f , -7.76883773f , -9.68917237f , -12.06267819f , -15.74184854f , -20.57971046f , -26.94266349f , -28.91713407f , -29.90809627f , -32.33980009f , -34.78712756f , + 31.86686358f , 25.05708453f , 21.93386932f , 18.59721235f , 16.14828273f , 13.65996344f , 12.23768162f , 10.88830652f , 7.52143926f , 4.65925062f , 0.21911333f , -2.95634076f , -6.28361110f , -9.89608579f , -12.31443795f , -15.63623136f , -18.24730809f , -19.62072228f , -21.80325803f , -26.65045940f , -31.07260802f , -34.93098644f , -37.15982288f , -38.71632279f , + -1.13403660f , 8.44528954f , 11.51295187f , 14.00328114f , 13.22245841f , 6.86239877f , 5.34172769f , 2.20794235f , 0.66973127f , 0.80995393f , 0.18013549f , -1.34499371f , -2.89430852f , -4.11662287f , -4.87021345f , -7.99460808f , -8.07372401f , -10.75957729f , -12.01649380f , -13.25826273f , -16.07989264f , -18.05984187f , -19.66161990f , -20.39890287f , + 34.47278093f , 29.24647924f , 19.01794852f , 15.12449850f , 12.02160432f , 7.97153847f , 7.45763494f , 5.89473413f , 5.37914684f , 4.00235938f , 0.64484508f , -2.70552406f , -1.74008061f , -3.83315860f , -8.38542072f , -11.12882737f , -15.57900872f , -20.44309400f , -25.22215650f , -30.01421316f , -32.58722714f , -35.83261388f , -38.09733270f , -39.57915419f , + 26.99752631f , 17.33775755f , 13.92510612f , 10.93298244f , 9.54482419f , 7.98334199f , 6.83019538f , 4.82308161f , 2.24070293f , 0.99075525f , -1.02697127f , -2.29004143f , -3.77731663f , -5.16939314f , -6.16294107f , -6.18510893f , -7.80109455f , -10.31816129f , -12.42321458f , -14.13119051f , -16.75176785f , -19.57160270f , -22.21041760f , -24.43862133f , + 42.61148531f , 31.03862448f , 28.85875173f , 25.19534132f , 19.51936632f , 17.22593169f , 13.88213981f , 9.45821554f , 6.10128356f , 3.64177773f , -0.92329563f , -2.97749460f , -7.09143508f , -9.90051943f , -13.44778189f , -16.62642688f , -18.86184149f , -20.09465179f , -22.86181406f , -24.16906530f , -24.29058326f , -25.46900644f , -25.99854039f , -26.44256368f , + 11.21919787f , 12.93487301f , 14.44441998f , 11.21144561f , 9.65171981f , 8.40946672f , 7.55500249f , 5.20337067f , 2.41664302f , 1.45692356f , -0.41811214f , -3.03866042f , -4.18715822f , -4.62852017f , -5.34679829f , -7.37187974f , -9.70194778f , -11.87551235f , -14.41976938f , -16.77473090f , -20.18921925f , -23.53459021f , -26.08250760f , -28.00378414f , + 20.34283034f , 23.93100647f , 23.37840521f , 19.69998040f , 16.97580649f , 15.22176840f , 12.49942414f , 11.65471077f , 8.40962769f , 5.04811003f , 0.69748903f , -3.16572674f , -7.04148304f , -11.24778876f , -13.98941379f , -16.42484438f , -18.63762955f , -20.97458282f , -23.23612236f , -25.18653947f , -26.21052089f , -27.41104425f , -28.62675281f , -29.47926632f , + 16.10744102f , 12.46174606f , 9.67751113f , 7.41625956f , 6.37054729f , 5.04682742f , 5.17633155f , 4.68688374f , 3.91606026f , 3.15494649f , 1.41414217f , -0.14124367f , -2.67444251f , -4.50662805f , -5.84468690f , -7.56186331f , -9.03680543f , -11.41274706f , -13.28658702f , -15.69552507f , -20.26071976f , -23.69377768f , -26.71593694f , -30.31014067f , + 23.92977739f , 27.36060494f , 28.84534340f , 25.31470096f , 19.06231769f , 15.59405931f , 13.34476843f , 10.49105930f , 10.02936877f , 7.13162822f , 1.31449322f , -2.20667410f , -8.24469533f , -11.78467489f , -15.48551597f , -18.43809063f , -20.80800912f , -22.21620783f , -24.85301893f , -26.38738069f , -25.80522754f , -27.00307256f , -27.56365136f , -28.00697638f , + 14.20627416f , 13.22102035f , 12.02604633f , 14.08327071f , 13.26998454f , 6.88224307f , 5.35679783f , 2.25352772f , 0.65358807f , 0.88975002f , 0.25204959f , -1.26498593f , -2.99170955f , -4.16405714f , -4.90721314f , -8.09596924f , -8.13409888f , -10.82708078f , -12.07413388f , -13.34328963f , -16.41337023f , -18.35676002f , -19.98799588f , -20.75791138f , + 35.53474913f , 29.48558719f , 19.65603645f , 16.46619256f , 12.12345599f , 8.85911530f , 8.44629251f , 7.05107660f , 6.71696658f , 4.07340114f , 1.41090109f , -2.86480122f , -1.47018231f , -3.19146903f , -9.63933408f , -13.43801687f , -18.07739816f , -21.62350791f , -25.40446924f , -28.56460703f , -30.18164019f , -32.53467864f , -34.28547688f , -35.28943834f , + 25.00794399f , 21.33869877f , 16.33988340f , 13.32545569f , 11.45579996f , 9.10207550f , 5.25001638f , 3.47011991f , 4.05816364f , 1.86646664f , -0.86488053f , -3.00452324f , -3.76486650f , -4.79552937f , -6.02719617f , -7.73977293f , -9.00587006f , -9.73374090f , -11.85870497f , -14.34560315f , -16.77881295f , -19.01848975f , -21.05935919f , -22.79963588f , + 43.77792792f , 31.32894231f , 26.45922262f , 21.35876446f , 15.14525981f , 10.71588831f , 8.36941090f , 8.13517319f , 4.60128461f , 4.27211986f , 0.48686102f , -2.99834845f , -5.70951224f , -8.40090526f , -10.59412598f , -12.10770405f , -11.91522373f , -11.91518882f , -14.41049054f , -17.78623890f , -21.49234475f , -25.81448584f , -28.36724870f , -30.21155944f , + 1.50464115f , 9.93376270f , 11.74048494f , 9.30038969f , 9.79598610f , 10.20363220f , 7.85569223f , 4.26334672f , 4.97315307f , 3.54446278f , 1.25546594f , -3.09504089f , -6.84943958f , -5.99780503f , -6.73288678f , -8.33022105f , -10.88645558f , -13.74251357f , -18.59070672f , -25.24686013f , -27.59378675f , -28.40807602f , -30.81519883f , -33.03504083f , + 19.29716892f , 22.72202601f , 17.97653030f , 16.27096251f , 12.41466110f , 8.84546373f , 8.15910118f , 6.66039787f , 6.35335478f , 4.08653893f , 0.72117759f , -2.80728034f , -1.28889621f , -3.09741558f , -8.84182975f , -13.43826617f , -17.76712819f , -21.05170423f , -24.61965449f , -27.56558965f , -28.70738278f , -30.61253475f , -32.09933492f , -32.92557847f , + 22.91112025f , 16.28797584f , 13.32980234f , 11.77954583f , 11.10520613f , 9.60502556f , 6.99639805f , 4.92750381f , 4.37578890f , 3.30304792f , 1.59780404f , -0.85650398f , -4.51942915f , -6.12826489f , -9.01178894f , -9.24740841f , -12.14748862f , -16.76564804f , -21.19272621f , -27.28665412f , -29.08952731f , -28.60120961f , -31.88653060f , -33.18962566f , + 33.45651993f , 27.28201548f , 24.14734641f , 20.06703472f , 17.00409549f , 15.37948573f , 13.16136491f , 12.54752730f , 8.51110832f , 6.15322442f , 1.01576259f , -3.20755791f , -6.86882472f , -10.60714935f , -13.86074399f , -17.81294984f , -21.41525794f , -23.90831312f , -26.23400053f , -28.17563657f , -29.78113366f , -31.33044221f , -32.48533160f , -33.17676836f , + -1.33562639f , 7.12695001f , 9.13702377f , 12.15068677f , 10.08162039f , 4.24738369f , 5.64945952f , 9.32178364f , 3.03127020f , 1.38560225f , -0.47615923f , -1.64981857f , -3.39596649f , -4.05192511f , -6.43198431f , -7.97537953f , -9.73574405f , -10.49517550f , -11.53586670f , -11.55974030f , -11.95164592f , -14.31159626f , -16.17106881f , -17.68912312f , + 35.41108122f , 29.91060467f , 19.58523453f , 16.06777717f , 12.57822747f , 8.35950205f , 8.09246540f , 6.67806922f , 5.88366701f , 4.60628742f , 0.66866287f , -2.63518420f , -1.20919288f , -3.25276235f , -8.81348472f , -13.41243642f , -17.54390333f , -21.59153299f , -26.13142590f , -30.39899536f , -32.82264487f , -35.85023060f , -38.02784458f , -39.40873711f , + 28.20606627f , 15.99154594f , 10.90529614f , 8.27787590f , 6.06401205f , 5.06158745f , 4.71175812f , 3.71857258f , 3.29421131f , 3.15470022f , 1.47961235f , -0.11358400f , -2.36135275f , -5.91849835f , -7.03135770f , -5.55512296f , -6.50513100f , -10.60214350f , -14.97482271f , -15.31088270f , -17.34686348f , -20.99732736f , -25.70312725f , -29.22139957f , + 42.93694373f , 32.74699191f , 30.21736822f , 26.00007059f , 19.54808802f , 16.15153602f , 13.70906743f , 10.84988327f , 10.20654657f , 7.38885117f , 1.18592616f , -2.68553419f , -8.73683094f , -12.15884936f , -15.82753433f , -18.59595794f , -21.03522899f , -22.52642663f , -25.16717079f , -26.41557750f , -26.29502925f , -27.33330821f , -27.87099339f , -28.30239553f , + 6.98493107f , 12.11140261f , 12.92505832f , 10.63602573f , 9.29436222f , 7.80676869f , 6.62557343f , 4.68392090f , 2.17174988f , 1.01311116f , -1.11858724f , -2.22498325f , -3.56605973f , -4.96869680f , -6.04787508f , -6.05424850f , -7.61493730f , -9.33729157f , -10.80071194f , -12.03282608f , -14.46539670f , -17.02917589f , -19.33639362f , -21.15590027f , + 16.58485816f , 23.25532800f , 24.92928523f , 21.35853037f , 18.27283576f , 16.09710359f , 14.23738656f , 12.78815582f , 9.26070976f , 6.16634740f , 0.30018833f , -3.21368036f , -6.95869200f , -11.45995031f , -14.49141925f , -17.86218539f , -23.13676669f , -25.83259792f , -29.74871192f , -33.41994284f , -34.94573093f , -37.66843375f , -39.07414904f , -39.56312642f , + 19.19373953f , 14.21085832f , 10.67306675f , 8.33934581f , 6.82717763f , 6.09582415f , 5.89997396f , 4.53145606f , 4.46589963f , 2.98486276f , 1.45382349f , -0.47196753f , -3.08165487f , -4.80601244f , -6.35558877f , -7.88794845f , -9.65590673f , -11.39978404f , -12.89635391f , -14.32655348f , -17.79398377f , -21.03259304f , -23.41750892f , -26.20513637f , + 29.53404537f , 30.67650669f , 27.35804255f , 20.58387049f , 15.13774878f , 11.44742263f , 8.37085526f , 10.32676908f , 9.44758339f , 4.78688526f , 1.42891547f , -1.32094691f , -4.89316199f , -9.59224642f , -14.04691133f , -15.02972510f , -16.06330505f , -18.39580808f , -21.09539458f , -21.98720102f , -21.73206018f , -23.31133245f , -24.77510819f , -26.73382495f , + 8.21213806f , 10.71817099f , 6.95322984f , 10.27747529f , 8.84487068f , 3.08387427f , 4.45029470f , 10.93157046f , 2.20726443f , 2.60772269f , 0.11878151f , -0.75484803f , -2.80874481f , -3.82230411f , -6.83748866f , -8.27100427f , -9.75013326f , -11.03913114f , -12.78391580f , -13.82412848f , -14.12344338f , -16.73927451f , -18.69924100f , -20.13526564f , + 36.59329684f , 30.98184338f , 20.31505022f , 15.92064718f , 13.03648432f , 8.83096086f , 8.56348539f , 7.43266836f , 6.82375344f , 4.40627973f , 1.13184165f , -3.01500873f , -1.77040231f , -3.69259653f , -9.49579170f , -13.95449102f , -18.29710034f , -22.56971615f , -26.64665710f , -30.91115675f , -33.15396332f , -36.23947175f , -38.66101864f , -40.00954322f , + 21.55198111f , 18.08013792f , 12.86298781f , 10.08865136f , 9.05061804f , 6.54215134f , 4.72951143f , 3.72642094f , 2.85320817f , 1.71125125f , -0.07271721f , -0.95539550f , -3.50605983f , -4.43298306f , -5.50932418f , -6.32571893f , -7.81088376f , -8.89702447f , -9.73519051f , -10.67801247f , -13.58487694f , -16.68643366f , -17.77012871f , -20.05291511f , + 46.89729788f , 35.56958745f , 28.59584038f , 22.30896946f , 16.77464328f , 13.26417085f , 9.50081776f , 9.90989766f , 7.34552811f , 5.94667087f , 1.99541819f , -1.96361481f , -6.27398279f , -10.07653618f , -12.56282109f , -16.11090729f , -17.74907160f , -19.50939014f , -22.57118303f , -25.05439958f , -25.40229780f , -27.63187647f , -28.24619732f , -28.92835915f , + 7.04882350f , 14.81563453f , 15.61978870f , 11.48753791f , 8.54260976f , 6.22345107f , 5.45372753f , 5.28049811f , 4.65171365f , 3.62223181f , 1.43071415f , -1.72597185f , -3.88591530f , -4.61140675f , -6.49788570f , -8.59851355f , -9.88533610f , -11.88847906f , -14.04273862f , -16.54736577f , -19.07821687f , -22.45007228f , -25.58564675f , -28.56726867f , + 26.62300533f , 28.26693809f , 26.50090754f , 20.40002747f , 15.09430263f , 11.11188625f , 8.11413871f , 10.45873727f , 9.34406319f , 4.93078412f , 1.46033398f , -1.08739740f , -4.89307642f , -9.31800578f , -13.94736720f , -15.44189741f , -15.82638440f , -18.64996439f , -23.01530348f , -24.89778906f , -24.73159812f , -26.54494768f , -28.17985037f , -30.12506435f , + 18.67019979f , 15.08336786f , 12.94476580f , 10.08150497f , 10.00925560f , 9.67310787f , 7.30307309f , 4.52404204f , 5.06127062f , 3.29409992f , 1.11564223f , -2.83692116f , -5.88020005f , -6.25987188f , -7.10071550f , -8.19345902f , -10.70954639f , -13.53857613f , -18.30301326f , -24.52520568f , -27.34703702f , -27.97535570f , -30.09726173f , -32.24832937f , + 36.04980859f , 29.26056864f , 23.78078855f , 19.63374982f , 16.81000279f , 14.81984984f , 12.41523810f , 11.85197437f , 8.58759306f , 5.22704793f , 0.47511965f , -3.18839218f , -7.11099580f , -11.31735229f , -13.99002045f , -16.24783283f , -18.33216567f , -20.74910417f , -23.21510782f , -25.78954590f , -27.11200149f , -28.25034071f , -29.54019390f , -30.46288370f , + 0.37670779f , 0.29687493f , -0.01730927f , 0.11726067f , 0.11179207f , 0.33596355f , 0.21138045f , -0.04339771f , -0.02563331f , 0.38427089f , 0.09512665f , -0.07913710f , -0.00292995f , 0.29039347f , 0.10659745f , 0.19430847f , 0.34841833f , 0.11527277f , -0.04865383f , 0.19615645f , 0.02847621f , 0.06718820f , -0.22446622f , 0.20364433f , + 33.05884904f , 28.21806545f , 18.28672366f , 14.90465855f , 11.81838140f , 8.53018928f , 7.36436457f , 6.22819968f , 5.84887442f , 3.66847974f , 0.20260152f , -2.66704796f , -1.47894289f , -2.86302773f , -7.85434089f , -12.24209362f , -16.55564265f , -20.61195764f , -25.12237933f , -29.08693654f , -31.94525806f , -35.55122030f , -38.95909687f , -40.60633258f , + 24.50578368f , 23.21164155f , 17.92457034f , 12.07933488f , 8.98364311f , 6.80371606f , 5.83939766f , 5.41161671f , 4.31883022f , 3.60077410f , 1.63582448f , -1.36979682f , -3.64312460f , -5.15824621f , -7.52882787f , -8.79219701f , -10.10176923f , -12.04124517f , -13.96520976f , -16.84553679f , -20.16579953f , -23.43856366f , -26.82374740f , -29.86100013f , + 48.50819832f , 34.15289137f , 28.24457133f , 23.53440589f , 18.31072957f , 15.88776926f , 12.53987092f , 11.18245335f , 6.24944164f , 4.11493883f , -0.52409240f , -5.30803325f , -9.07637769f , -11.17513219f , -12.30672893f , -14.59517059f , -15.29955284f , -16.17617119f , -18.50798560f , -20.76566614f , -22.52791437f , -25.09691027f , -26.04976551f , -26.89355524f , + 8.09511743f , 16.72934786f , 15.91762640f , 13.38776480f , 11.39996807f , 9.07169312f , 5.27363212f , 3.54887142f , 4.12516542f , 1.95190718f , -0.86304369f , -2.99361979f , -3.82488041f , -4.85774399f , -6.10028496f , -7.73781042f , -8.99385716f , -9.74269129f , -11.87311775f , -14.36412448f , -16.63984465f , -18.98401676f , -21.03949226f , -22.80551374f , + 20.87378295f , 25.56786054f , 24.37761370f , 20.59749879f , 17.50210689f , 15.81599869f , 13.08379347f , 12.05910670f , 8.96864073f , 5.68078325f , 0.54144388f , -3.56427128f , -7.29664065f , -11.97853799f , -15.04589649f , -16.84207789f , -18.92440518f , -21.49140235f , -24.44638942f , -27.80142626f , -29.24580339f , -31.40581424f , -33.20452192f , -34.96038674f , + 19.41104922f , 14.92637618f , 12.34176913f , 10.26196252f , 8.23856507f , 6.94579600f , 6.09672941f , 5.11937634f , 4.33940607f , 3.00270291f , 1.52448177f , -0.93710759f , -3.39576042f , -5.47615969f , -6.39919115f , -8.50931643f , -10.54951473f , -12.31607256f , -14.47860786f , -16.84616423f , -20.24052021f , -23.50168995f , -26.54506826f , -30.16170088f , + 28.94913403f , 28.15793287f , 27.35445852f , 23.88021364f , 19.04664597f , 16.62782585f , 13.23041024f , 11.80165357f , 6.78531707f , 3.80696933f , -0.83387114f , -5.70452993f , -9.22126990f , -11.40351884f , -12.85584125f , -15.17252463f , -16.10728336f , -17.34847712f , -19.92401313f , -22.57735630f , -23.06177883f , -25.40758146f , -25.92714954f , -26.49459925f , + 12.32069177f , 16.71685865f , 15.41594910f , 11.66621173f , 7.27561715f , 4.39258627f , 3.29820147f , 3.32758485f , 3.22734089f , 2.78470278f , 1.44650193f , -0.81598784f , -3.12521932f , -3.93668706f , -4.64477937f , -6.10317000f , -7.12681751f , -8.89530539f , -11.17332758f , -13.38366313f , -16.18909111f , -19.08724858f , -21.72257955f , -24.33222369f , + 35.39248501f , 28.61432228f , 17.95058353f , 16.39813320f , 12.26449602f , 9.14706821f , 8.63032788f , 5.85616320f , 5.28119540f , 2.63526927f , -0.28717841f , -3.14181019f , -2.72478672f , -3.16234838f , -8.13078551f , -11.42272872f , -14.94525653f , -18.82791922f , -23.24088065f , -27.02082853f , -28.42092038f , -30.16472575f , -31.40325103f , -31.84491940f , + 29.17417043f , 22.35669900f , 16.18973605f , 11.81596682f , 7.33020525f , 4.62573743f , 3.88471147f , 3.94864957f , 3.63555026f , 2.84599249f , 1.57602679f , -1.21735288f , -3.89478177f , -4.22974940f , -4.64250760f , -6.47171963f , -7.39065220f , -8.84922447f , -11.09964915f , -13.32068423f , -16.59227278f , -19.66683547f , -21.69504139f , -24.56742611f , + 47.82535148f , 33.38325580f , 27.02560388f , 20.91023436f , 15.90238857f , 12.04933297f , 8.33681708f , 7.94847051f , 5.44070980f , 4.97685841f , 1.92697687f , -2.14584476f , -5.24005039f , -8.46045386f , -10.93596293f , -14.12648623f , -15.67279334f , -17.08482629f , -19.99575822f , -22.16249633f , -23.35032624f , -25.73870364f , -26.42301184f , -27.09098779f +}; + +const float cdk_37bits_2[1536] = +{ + -0.60245706f , -0.36895614f , -0.28565548f , -0.61568604f , -0.21106471f , 0.01679180f , -0.21655981f , -0.14874146f , 0.18445090f , 0.68365367f , 0.72441464f , 0.85147601f , 0.66205855f , 0.18971396f , -0.61367179f , -0.98009038f , -1.14245763f , -1.87659153f , -2.50979179f , -2.95026349f , -3.02743274f , -2.99854930f , -2.88275498f , -2.56850176f , + -5.65082964f , -2.53862673f , 0.40160897f , 2.96821191f , -0.14824038f , -1.30349223f , 2.28641587f , 2.52644085f , -0.74130153f , -0.58139293f , -0.40073314f , -0.35906410f , -1.19626114f , 0.06293193f , 0.64564279f , -0.28942601f , -0.50149314f , 0.15944196f , -0.49731843f , -1.16475251f , -1.23551169f , -1.75642099f , -1.69671673f , -3.27291796f , + -3.65205633f , -1.67292739f , -1.06391729f , -1.37244548f , -1.12591558f , -0.69120125f , -0.80026251f , -0.27722939f , -0.15083351f , -0.13788690f , 0.03718469f , 0.68916477f , 0.75420341f , 0.54895929f , 0.40054739f , 0.43983204f , 0.31332249f , 0.46565374f , 0.40388762f , 0.35105496f , -0.40253674f , -0.51485592f , -0.89858941f , -1.05731152f , + -2.11612178f , -1.68149840f , -1.39421377f , -0.97488811f , -0.68836346f , -0.25122725f , 0.16979554f , 0.57375560f , 1.03704438f , 0.52788495f , 0.50037128f , 0.36855698f , 0.00455631f , -0.09861634f , -0.62955146f , -0.58507783f , -0.92884745f , -1.12052521f , -1.30254994f , -1.47192536f , -1.44028535f , -1.35850941f , -1.34195842f , -1.31721028f , + 0.25982061f , -1.32220193f , -0.47678762f , -0.12979514f , 0.86306107f , 0.97702394f , 0.51749416f , 0.16146949f , 0.02988918f , 0.04663050f , 0.16707804f , 0.08767141f , -0.04519466f , -0.62683764f , -0.72798866f , -0.62087439f , -0.82935248f , -1.03592460f , -1.01752567f , -0.84860483f , -0.97413949f , -0.96705657f , -0.88017027f , -0.73637371f , + -0.26891091f , -0.80936559f , -0.58294544f , -1.02346364f , -0.43822029f , 0.57696314f , 1.16119077f , 2.18526688f , 0.18783659f , -0.57134867f , -0.83284393f , -0.78823212f , -0.76995104f , -1.09940636f , -0.46951794f , 0.39805438f , 0.45964480f , -0.63039899f , -0.74118394f , -0.78835034f , 0.14868248f , 0.93250274f , 0.68897718f , 0.90075101f , + -1.66784004f , -0.50476115f , -0.02030205f , 0.46798248f , 0.49883263f , 1.17082801f , 0.80713467f , 1.16362509f , 0.81774163f , 0.49553337f , 0.11478912f , -0.22236563f , -0.67572086f , -1.30599465f , -1.03213159f , -0.97366307f , -0.85875427f , -0.98596121f , -0.74580950f , -0.40837319f , -0.08418331f , 0.86784028f , 1.43480309f , 1.64139207f , + 2.27287621f , -0.58474310f , -0.69019045f , -0.47070058f , -0.61574738f , -0.51533540f , -0.29508852f , 0.10165453f , 0.36287882f , 0.55457305f , 0.57810155f , 0.47931307f , 0.43968104f , 0.06171771f , -0.25362137f , -0.47864384f , -0.41913420f , -0.68219417f , -0.57749295f , -0.73286321f , -0.88652778f , -1.14118878f , -1.17860702f , -1.07742659f , + -0.26605958f , -1.09199471f , -1.65740224f , -2.14201695f , -2.06186690f , -1.68936539f , -1.00901439f , -0.37549041f , -0.06256679f , 0.35513419f , 0.98053497f , 0.91466430f , 0.86530432f , 0.83552545f , 0.81062242f , 0.38603024f , 0.05045884f , -0.59611788f , -0.82572806f , -1.24150282f , -1.51280469f , -1.59822307f , -1.71808914f , -1.60728998f , + -1.09129709f , 0.06734422f , 0.07681791f , -1.25010854f , 0.11998545f , 0.44876184f , 0.34324970f , 0.19227749f , -0.14778119f , -0.08340870f , -0.08182976f , -0.20398755f , 0.06772352f , -0.09075007f , -0.02123454f , -0.25839401f , -0.28488980f , -0.64962465f , -0.75312989f , -1.01319788f , -1.29428363f , -1.46281777f , -1.48497336f , -1.34472564f , + -0.64660266f , -0.88691293f , -0.84393960f , -0.34552440f , 0.32824730f , -0.29728699f , -1.56066720f , -1.75726505f , -1.37935080f , -0.41983170f , 0.07847383f , 1.10763083f , 1.38831040f , 0.68960638f , 0.33240448f , 0.76690865f , 0.72333401f , 0.09227846f , -0.25578331f , 0.21326173f , 0.72267697f , 1.03823367f , 0.53396722f , 0.85492859f , + -0.66178264f , -0.72781507f , -1.16616398f , -0.61180318f , -0.13929383f , -0.36461939f , -0.18208278f , -0.01288829f , 0.07717647f , -0.10024019f , 0.07436033f , 0.26910493f , 0.35220120f , 0.08875997f , 0.10426474f , -0.03109220f , -0.13636337f , -0.22965524f , -0.32874358f , -0.25961753f , -0.26897008f , -0.21251566f , -0.09802804f , 0.02321489f , + 0.68981472f , -1.15206563f , -2.29258605f , 2.55986100f , 0.37026158f , -2.06518041f , 0.29082193f , 1.93844641f , 0.99052150f , 0.20248720f , -0.02548929f , 0.16880347f , 0.07779328f , 0.02567656f , -0.88067113f , -0.62757477f , -0.46579846f , -0.15896606f , -0.60482751f , -0.61951099f , -0.93517849f , -1.57434405f , -2.41362494f , -3.62613249f , + 0.10916433f , 0.43521512f , 1.56203262f , 2.28014034f , 2.45964989f , 1.28206740f , 0.62678461f , 0.76120906f , 0.64803676f , 0.26869080f , -0.47306419f , -0.43773939f , -0.62382319f , -1.07053542f , -0.92812261f , -1.19576823f , -1.31738270f , -1.36433226f , -1.44943362f , -1.75263554f , -1.79107934f , -1.65086642f , -1.63564703f , -1.48679794f , + -1.03508578f , -1.33591451f , -0.93011319f , -0.44471674f , 0.37500761f , 0.92138871f , 0.47036706f , -0.45250578f , -0.67117578f , -1.17172575f , -0.80474849f , -0.45208178f , 0.34756513f , 0.94484979f , 0.66316845f , 0.02661059f , -0.19689367f , 0.28637288f , 0.19763960f , -0.18457662f , -0.24564459f , -0.27740232f , -0.16466847f , -0.07240464f , + 0.79283938f , 0.04072154f , -0.45284799f , 0.62520205f , 0.40461878f , 0.46378915f , 0.26074483f , -0.00916984f , 0.17535410f , 0.03167535f , -0.07586785f , 0.26470352f , -0.21568977f , -0.76557444f , -0.42590064f , -0.12909543f , 0.02061938f , 0.20821266f , 0.45608502f , 0.64917803f , 0.55163697f , 0.57240961f , 0.62231726f , 0.71731998f , + 0.22967499f , -0.05073000f , 0.51257014f , 0.53635363f , 0.90936842f , -0.47960537f , -0.60503509f , -0.38078624f , 0.72254161f , 0.43714553f , 0.48654362f , 0.43714660f , 0.18700370f , 0.03007471f , -0.39817882f , -0.59285823f , -0.75351375f , -0.75107912f , -0.77902788f , -0.82750373f , -0.72882091f , -0.75427284f , -0.57531634f , -0.37148640f , + -2.32676805f , -0.68486879f , -0.28456416f , -0.36791144f , -0.29071024f , -0.01135526f , 0.16172201f , 0.27899421f , 0.23877415f , 0.01902860f , -0.32670357f , -0.28942004f , -0.25341926f , -0.28159658f , 0.07050306f , 0.26414188f , 0.42045388f , 0.49934376f , 0.55163730f , 0.80964449f , 0.41444864f , 0.21371086f , 0.07501103f , 0.11308696f , + -0.27305539f , -1.16787053f , -1.40565538f , -0.99925137f , -1.11970497f , -0.87627497f , -0.63268066f , -0.40045797f , -0.40525654f , -0.06010181f , 0.13266298f , 0.44378479f , 0.45144645f , 0.18695876f , 0.55290900f , 0.78041480f , 0.94641486f , 1.00887739f , 1.70081287f , 2.26350129f , 2.47817098f , 2.59918260f , 2.79591047f , 2.78437201f , + -0.32246249f , -1.71452730f , -2.64055100f , -2.67577145f , -0.92654110f , 0.26408617f , -0.25926943f , 0.02139616f , 0.33878547f , 0.06917466f , 0.02594366f , 0.24868381f , 0.39107983f , -0.01529301f , -0.20036110f , 0.01057045f , 0.03136854f , 0.09346079f , 0.22821765f , 0.33206417f , 0.01105828f , 0.17529667f , 0.88221791f , 0.89873292f , + 0.93496823f , 0.51731100f , 0.04196463f , -0.75388451f , 0.47715970f , 0.54630853f , 0.18782570f , -0.38877496f , -0.07979449f , -0.12966809f , 0.12211422f , -0.22771599f , 0.03309780f , 0.02166307f , -0.05844436f , -0.17678384f , -0.32696150f , -0.45229639f , -0.40223728f , -0.45381663f , -0.55363514f , -0.44568304f , -0.41742550f , -0.27033009f , + 1.24789723f , -0.16270145f , -0.23526508f , -0.91495192f , 0.09192658f , 0.94791314f , 0.99514796f , 1.48011022f , 1.18575675f , 0.34462249f , 0.08649944f , -0.30288071f , -0.33154349f , -0.62323828f , -1.23683351f , -1.35258474f , -1.28447604f , -1.39540423f , -1.48493397f , -1.22352799f , -0.64023287f , -0.31408935f , 0.05098542f , 0.60709035f , + -1.28296443f , 0.30739631f , 0.06005469f , 0.20911344f , 0.24839533f , 0.32438667f , 0.52129460f , -0.19296009f , 0.56893959f , 0.27689822f , 0.19535841f , -0.28910358f , -0.03222614f , -0.11973675f , -0.43887472f , -0.57077656f , -0.49160952f , -0.12962890f , 0.67632833f , 1.51844798f , 1.92676111f , 2.40049046f , 3.14497224f , 4.02974673f , + 1.80516481f , -0.56393339f , -1.30448044f , -1.40495082f , -0.68191674f , -0.76180008f , -0.59977868f , -0.51019494f , -0.68339140f , -0.49281527f , -0.13376455f , 0.19985525f , 0.65099755f , 0.67547152f , 0.63174636f , 0.88059571f , 0.82474329f , 0.51834518f , 0.45799476f , 0.48269666f , 0.41156043f , 0.45527314f , 0.53753557f , 0.66268670f , + -1.55606025f , -0.20257947f , -0.14962756f , -0.99675497f , -1.37013665f , -1.22741192f , -0.99079753f , -0.49157059f , 1.03655475f , 1.41721212f , 0.93733685f , 0.23984335f , -0.04670573f , -0.46782519f , -0.11250628f , 0.37457349f , 0.70065238f , 0.30049206f , 0.12589128f , 0.00816302f , -0.30417620f , -0.55639550f , -0.97628459f , -1.33776955f , + -0.91978133f , 2.03647597f , 2.08783454f , -0.34357589f , -0.53113823f , -0.79082032f , -0.35484777f , -0.04415842f , -0.05569113f , 0.29670211f , 0.20802391f , 0.20847836f , 0.24786650f , 0.08187504f , 0.25883128f , 0.36261019f , 0.11231239f , 0.00938238f , 0.04224603f , -0.13883262f , -0.17357685f , 0.27783307f , 0.24645533f , 0.26199958f , + -0.61248405f , -0.07406218f , -0.61345974f , -1.32868141f , -1.08503963f , -0.61503512f , -0.40217073f , -0.50619739f , -0.34879559f , -0.33683180f , -0.13424100f , -0.05819325f , 0.01983650f , 0.38272624f , 0.44165965f , 1.08335723f , 1.55918521f , 0.91879734f , 0.66719572f , 0.40972477f , 0.11617552f , 0.02573831f , -0.13026683f , -0.32568351f , + 0.31463364f , -0.03452175f , -0.04820884f , -0.36356998f , -1.78279482f , 0.33915182f , 0.23383962f , 0.10388632f , 0.30795414f , 0.18689800f , 0.20754344f , -0.09819817f , 0.32111428f , 0.28504616f , 0.07722536f , -0.01904677f , -0.16255073f , -0.15042754f , -0.03877674f , 0.01867447f , -0.00999362f , 0.02968441f , 0.12366541f , 0.24417438f , + 1.09843253f , 0.09916156f , -0.26715787f , -0.21319307f , 0.17488666f , -0.03969684f , -0.42084276f , -0.26687268f , -0.54193150f , -0.73872758f , -0.38673483f , -0.31271029f , 0.04756063f , 0.03567565f , 0.10843090f , 1.00179157f , 1.33899024f , 0.51010916f , -0.26441522f , -0.71717032f , -1.14185896f , -1.44276220f , -1.62450955f , -1.61374667f , + -1.17644421f , -0.65722894f , -0.85514146f , -1.00555806f , 0.26053267f , 0.49309357f , -0.37877784f , -0.93210797f , -1.08883971f , -0.98901078f , -0.77758095f , -1.41471701f , -1.75752311f , 0.13457770f , 2.71551042f , 3.08606371f , 0.64870422f , 0.21086401f , -1.21315351f , -2.33440097f , 0.01456974f , 2.06478611f , 0.27046489f , 0.39813046f , + -0.48133789f , 0.05248478f , 0.15702810f , 1.09901110f , 1.05962736f , 1.17102152f , 1.55536593f , 0.44906344f , -0.41703175f , -1.12950682f , -0.93068802f , -1.09338708f , -0.91150200f , -0.48817666f , 0.10937607f , 0.37946930f , 0.24542719f , 0.26431763f , 0.67229593f , 0.65079198f , 0.00926221f , -0.87021868f , -1.26123155f , -1.41977363f , + 1.54426896f , 1.64264747f , 1.49559347f , 0.46249745f , 0.93411099f , 1.07714355f , 0.81133504f , 0.18134510f , 0.47877461f , 0.29451902f , -0.11266912f , -0.50269456f , -0.69526938f , -0.66772091f , -0.81400219f , -0.48607791f , -0.49953687f , -0.35945370f , -0.41495272f , -0.22003468f , 0.19724418f , 0.40213003f , 0.75369682f , 0.99864576f , + 0.09877598f , -0.24834930f , 0.70781761f , -0.02941638f , 0.04788121f , -0.17525416f , 0.24389545f , 1.27018837f , 1.54269729f , 1.25537489f , 1.40965823f , 0.83108228f , -0.00482938f , -0.57803168f , -1.40272349f , -2.04807395f , -2.39183907f , -2.28421278f , -1.59956397f , -1.84523910f , -1.49830221f , -1.32118632f , -1.41289179f , -1.07949145f , + -3.00057476f , -0.33414238f , 0.53147236f , 0.51026648f , 0.64656500f , 0.22188527f , 0.26159611f , -0.05358452f , 0.08996934f , -0.14007857f , -0.16740033f , 0.20548656f , 0.24617443f , -0.14274519f , -0.22696206f , -0.33493349f , -0.60597008f , -0.59551620f , -0.65068169f , -0.58018184f , -0.85498638f , -0.83283956f , -0.68903400f , -0.56704530f , + -1.80644488f , -2.09723761f , -2.47792833f , -2.51218612f , -1.89574511f , -1.52165564f , -1.43122992f , -1.31255781f , -1.17590463f , -0.75299628f , 0.13501040f , 1.04659662f , 0.78957362f , 1.33259798f , 1.48274046f , 1.92412844f , 1.37934388f , 1.51991312f , 1.53887225f , 1.07173430f , 0.52056336f , 0.89063725f , 0.75213286f , 0.48137117f , + -0.83123316f , -1.25502416f , -0.24000076f , -0.86042163f , -1.31788654f , -1.01630239f , -0.29559367f , 0.06110944f , 1.41025494f , 1.14012093f , 1.09233283f , 0.65906473f , 0.66635495f , 0.22542242f , -0.48939739f , -0.90887258f , -1.22778778f , -1.13528888f , -0.64749466f , -0.33117378f , -0.13886376f , 0.32663134f , 0.80397143f , 1.24264775f , + 0.02879094f , -0.40518021f , 1.01153472f , 0.24919166f , 0.21717242f , 0.73565158f , 0.11322127f , 0.18792292f , -0.13373281f , -0.08074408f , -0.11253388f , -0.16098838f , 0.11676604f , -0.16172666f , -0.26254412f , -0.20650902f , -0.25114318f , -0.21747560f , -0.22020914f , -0.32979603f , -0.32478632f , -0.30167186f , -0.14634515f , 0.05782533f , + -0.47454777f , -0.56928151f , -1.15476553f , -0.09623004f , 2.88751281f , -0.14714366f , -0.88522957f , 4.22040983f , 1.39699412f , -1.50292392f , -0.43572570f , -0.83179815f , -0.31636548f , -0.93272549f , -0.76482978f , -1.38859059f , -1.29829764f , -0.15529744f , 0.26864398f , 0.27166310f , 0.10090808f , 0.27140121f , 0.10246642f , -0.11585636f , + -0.83199745f , 1.25871280f , 2.32976268f , 1.04422262f , 0.72052750f , 0.58033767f , 1.01197514f , -0.00356009f , 0.64222581f , 0.17810713f , -0.27271599f , -0.30971603f , -0.36262209f , -0.59621272f , -0.71907027f , -0.37465802f , -0.49493312f , -0.23002788f , 0.22678857f , 0.61676427f , 1.15089995f , 1.45602224f , 1.73714565f , 1.76230856f , + 3.78596594f , 0.70843751f , 0.56143039f , 0.59983620f , 0.91117855f , 1.14938132f , 0.62640275f , 0.25328046f , 0.05444886f , -0.14074779f , -0.18351720f , -0.14467121f , -0.17323666f , -0.19046734f , -0.48709718f , -0.78123776f , -0.89375672f , -0.92818935f , -0.92156607f , -0.91479400f , -0.71603833f , -0.54172884f , -0.35025273f , -0.10097845f , + 1.88294702f , 1.24216466f , -0.99369851f , -0.70762866f , -0.80134642f , -1.57956697f , -1.53644146f , -0.73206309f , -0.05717919f , 0.79275997f , 0.73656524f , 0.59776925f , 0.89457859f , 0.27389259f , 0.55266497f , 0.42166521f , 0.43646218f , 0.18667357f , -0.37565357f , -0.34247443f , -0.46905572f , -0.54608498f , -0.46535569f , -0.51501131f , + -0.47999037f , 1.00431088f , 0.73194666f , 0.53070406f , -0.01938612f , 0.03027495f , 0.40371180f , 0.67811524f , 0.70405966f , 0.58218726f , 0.21637318f , 0.01593260f , -0.21413948f , -0.51479804f , -0.67811458f , -0.52916655f , -0.67532514f , -0.70141319f , -0.64914555f , -0.67794975f , -0.70067665f , -0.79806639f , -0.63846191f , -0.48442451f , + 1.27348348f , 0.96416420f , 0.39017217f , 0.71785608f , 1.03161791f , 0.22200744f , -0.65764394f , -1.59478709f , -0.95580133f , -0.45685571f , 0.24849072f , 0.90500271f , 0.94710102f , 0.11334884f , -0.15646077f , 0.15567420f , 0.19951531f , 0.06661949f , 0.16776497f , 0.92645175f , 1.51329143f , 1.99768327f , 2.23252155f , 2.82502657f , + -0.54469743f , 0.32018638f , 0.18026765f , -0.24717676f , 0.16334731f , 0.24119007f , -0.09150780f , -0.62258235f , -0.36174875f , -0.54007117f , -0.16902754f , 0.05782464f , 0.32844560f , 0.29531844f , 0.39903673f , 0.21807358f , 0.08243945f , 0.19009618f , 0.32130029f , 0.40374798f , 0.59707077f , 0.94425923f , 1.12228590f , 1.33995773f , + -0.11751559f , -0.41810808f , 0.01454897f , 0.64372292f , -0.51236310f , -1.28919088f , -0.27493502f , -0.15853449f , -0.26953216f , -0.08601421f , 0.47049578f , 0.62472064f , 0.47447185f , 0.17523033f , 0.30837586f , 0.34012918f , 0.19798450f , 0.18240973f , 0.24439643f , 0.37610178f , 0.25546586f , 0.34660852f , 0.25152738f , 0.33684884f , + 0.11066744f , 1.19858921f , 0.91132496f , 1.17666312f , 1.24521727f , 0.96210985f , 0.48787188f , -0.08729327f , -0.75696449f , -0.61950811f , -0.12399623f , -0.05243043f , 0.12080690f , 0.07846342f , -0.05639926f , -0.49681521f , -0.70132533f , -0.85192537f , -0.82039718f , -0.85401537f , -0.76376214f , -0.65987739f , -0.48460153f , -0.15410472f , + 0.35003846f , -1.71631424f , -2.46591563f , 0.87758858f , -1.81752528f , 3.13642054f , 1.73032547f , -0.09324163f , -4.01941823f , 1.53280929f , -1.80607033f , 0.38379815f , -0.60599486f , -0.15051943f , -1.06126256f , 0.92416849f , 1.84602853f , 1.75994867f , 0.99060749f , 0.70059849f , 1.55000269f , 0.30898296f , 1.89357287f , 3.39229864f , + 2.30088406f , 0.92343676f , 0.99415615f , 0.95404596f , 0.50656674f , 0.93824653f , 0.48608406f , -0.08446928f , -0.62418615f , -0.92839590f , -0.72113820f , -0.52847345f , -0.12827999f , 0.09174440f , 0.46989097f , 0.23658785f , 0.28508481f , 0.46040256f , 0.61632907f , 0.95774580f , 1.12674250f , 1.33598604f , 1.41647487f , 1.55101744f , + 1.37256353f , 0.97616384f , 0.91935645f , 0.81440269f , 0.66853976f , 0.62246830f , -0.20376912f , 0.03360847f , 0.43571616f , 0.50340338f , 0.23558369f , 0.34148923f , 0.26639247f , -0.42615485f , -0.66797929f , -0.78929117f , -1.01956966f , -1.04967706f , -0.83319766f , -0.38454933f , 0.01908745f , 0.54939284f , 1.31919448f , 1.91397573f , + -1.47177526f , -0.59088313f , -0.29040563f , -0.30391048f , -0.77025357f , -0.91705792f , -1.11779825f , -1.26663583f , -0.88813029f , -0.84447950f , -0.68067351f , -0.12550231f , 0.86719136f , 0.95700684f , 1.32696558f , 1.54042652f , 1.91879305f , 2.53765271f , 2.74382217f , 2.47883719f , 2.13313809f , 1.99482993f , 1.71839367f , 1.55253059f , + -2.18776004f , -2.01842604f , -2.26735458f , -1.91080096f , -2.94652547f , -2.30201691f , -2.55949436f , -2.06940788f , 0.81981691f , 0.88975503f , 1.36019848f , 1.20472608f , 1.42006397f , 0.61493222f , -1.18963425f , 0.41220219f , 4.34572607f , 4.43362932f , 4.07803194f , 5.02807593f , 3.44925570f , -0.33534871f , 0.49574672f , -0.89211792f , + 1.62466606f , 0.12019975f , -0.38782369f , -0.93423193f , 0.16258521f , -0.01564732f , 0.49181187f , 0.20589834f , 0.27352752f , 0.19483395f , 0.32141824f , -0.11470920f , -0.19458687f , -0.27925271f , -0.50960055f , -0.21759523f , -0.31856471f , -0.25540294f , 0.10383356f , 0.63132905f , 1.12834639f , 1.54942785f , 2.10497109f , 2.44084721f , + 1.80221933f , 1.34647425f , 0.68084866f , 0.26131343f , 0.06129242f , -0.20413381f , -0.25012623f , 0.26150026f , 0.34217016f , -0.25077441f , -0.03464205f , 0.00670185f , 0.11970509f , -0.18474450f , -0.02420872f , 0.04947295f , 0.10704821f , 0.12031899f , 0.25733107f , 0.20223825f , 0.14644252f , 0.05014131f , 0.25449839f , 0.53243125f , + 2.46777249f , 2.31564554f , 1.57449051f , -0.02405359f , -0.50178606f , -0.75371618f , 0.14778503f , 0.92907656f , 1.77413761f , 1.44803582f , 0.79871587f , -0.06867376f , -0.36229444f , -0.24911098f , -0.80167236f , -1.29799461f , -1.06250807f , -1.04778427f , -0.99914314f , -1.09969569f , -0.87609022f , -0.93824122f , -0.95461855f , -0.91327026f , + 0.43633316f , 0.85535629f , 0.60581035f , 0.16065427f , -0.07901143f , -0.12715680f , 0.03021654f , 0.07928964f , 0.11271867f , -0.14335296f , -0.24219156f , -0.11821250f , -0.20715557f , -0.14096772f , -0.04794024f , 0.21199596f , 0.67185756f , 1.28693268f , 1.69253449f , 2.02169124f , 2.03489721f , 2.18782692f , 2.32510550f , 2.13471256f , + 5.19702515f , 0.11666770f , -0.23856561f , -0.40839191f , -0.43762919f , -0.47738566f , -0.08391318f , -0.28626545f , 0.00298357f , 0.04540739f , 0.31909785f , 0.21196383f , 0.24548536f , -0.08426235f , 0.13111045f , 0.13639205f , 0.27647873f , 0.33171126f , 0.46017809f , 0.54387048f , 0.61603267f , 0.57095620f , 0.68776632f , 0.65010973f , + 0.58235537f , 0.52562482f , 1.05922702f , 1.60193935f , 0.43144897f , -2.92550999f , -2.57110854f , -1.17753807f , 0.19698968f , 1.02966008f , 0.68834236f , -0.11567313f , -1.07423611f , 1.53722962f , 2.83106005f , 0.31270547f , 0.83691800f , 0.60620087f , 0.21605402f , -0.37564956f , 0.38963810f , -0.55569948f , -0.83510003f , -0.45007941f , + -0.90035383f , 0.70316556f , 1.58896986f , 2.00202833f , 0.66804071f , -0.32729105f , 0.20493044f , -0.45491115f , -0.51617330f , -0.18761885f , -0.13361848f , 0.06806675f , -0.08803656f , -0.27485407f , -0.08086164f , 0.47587476f , 0.64596634f , 1.37554511f , 1.64271082f , 1.13804275f , 0.62642705f , 0.27157260f , 0.15530333f , -0.04178223f , + 2.19562225f , 0.68349947f , 0.14785409f , 0.07266666f , -0.11144618f , -0.52658551f , -0.77916859f , -0.76098098f , -0.55947105f , -0.61767060f , -0.18020839f , -0.26320634f , -0.03154415f , 0.41832030f , 0.98036861f , 1.17153463f , 1.26081153f , 1.58669565f , 1.96844912f , 2.21868662f , 1.28843850f , 0.48905790f , 0.12804274f , -0.25383240f , + 0.96587648f , 1.45558990f , 0.31977941f , -0.95024822f , -1.59243377f , -0.35590271f , -0.57251864f , -0.20900643f , 0.39660737f , 0.51169138f , 0.41734874f , -0.03711820f , 0.43311570f , 0.50214417f , 0.08955252f , 0.09513494f , 0.32141616f , 0.43401876f , 0.86976131f , 1.39503347f , 1.54833843f , 1.52864127f , 1.46114291f , 1.21933526f , + 1.78766271f , 1.61870712f , 2.29243952f , 1.45106025f , -0.02202545f , 0.12396735f , 0.05180173f , -0.74274249f , -0.04132082f , -0.01646827f , 0.04051846f , 0.10680231f , 0.03361298f , -0.26263042f , 0.29610433f , 0.25222625f , 0.18019271f , -0.22323513f , -0.68162437f , -0.96880693f , -1.29349030f , -1.78825246f , -2.63819014f , -3.24193152f , + -5.14372601f , 2.35480301f , 2.57594417f , 3.31674200f , 5.64389287f , 5.57674458f , 3.59322110f , -1.28598587f , -1.68632976f , -2.12796852f , -2.98396833f , -4.09489145f , -4.00821759f , -0.23400052f , 1.27890396f , 0.77129006f , -0.44287462f , -1.47029001f , -2.18546499f , -2.54400987f , -3.37996978f , -1.92988631f , -3.15537156f , -4.51816327f , + -0.35333284f , 0.05714033f , 1.24834935f , 0.52566638f , 0.41396899f , 0.74990328f , 0.95628046f , 0.44418709f , -0.34231956f , -0.14250584f , -0.59768493f , -0.64758317f , -0.22890844f , 1.10009034f , 0.66447430f , -1.03679499f , -1.33177125f , 1.17542516f , 2.21270353f , 1.90162759f , 1.20419817f , 0.83319667f , -0.52929949f , -2.16298435f , + 5.19114552f , 3.69595577f , 2.40462618f , 1.01495594f , 0.03903091f , 0.32991808f , -0.22330707f , -0.60000816f , -0.42237486f , -0.09093864f , 0.19458627f , 0.42022925f , 0.27603710f , 0.12695518f , 0.13428003f , -0.11234558f , -0.07201685f , -0.08582543f , -0.00938781f , 0.00835335f , 0.26546185f , 0.48668790f , 0.55514085f , 0.42743906f +}; + +const float cdk_37bits_3[1536] = +{ + -0.39555686f , -0.03651739f , -0.44779209f , 0.28023722f , 0.00089126f , -0.66214790f , 2.59448215f , -0.79382669f , -0.12742901f , -0.11647842f , 0.01833394f , 0.16500005f , -0.09845495f , -0.28459353f , -0.36237538f , 0.11970795f , -0.45285373f , -0.10504899f , -0.11812969f , 0.38858637f , 0.86990072f , 0.65514891f , 1.11998296f , 1.21258496f , + 0.22127561f , 0.04345828f , -0.01534097f , -0.09898785f , -0.26169093f , -1.42940674f , -0.62833523f , -0.43722472f , -0.03759617f , -0.48777744f , -0.21315437f , -0.50978248f , -0.03448283f , 1.37885110f , 2.31984917f , 0.94767797f , -0.60793975f , -1.49725519f , -0.82404584f , -0.79191239f , -0.41285081f , -0.57794113f , -0.59258055f , -0.52142849f , + -2.04397465f , -0.73672438f , -1.22406020f , -0.60820965f , -0.66350776f , -0.63508874f , 0.11396081f , 0.27852903f , 0.02122066f , -0.36929472f , -0.09692458f , -0.59306388f , -0.03445818f , 0.22347759f , 0.50874437f , 0.79690333f , 0.44886168f , -0.21185937f , -0.22593929f , 0.10528155f , 0.46293555f , 0.91816687f , 0.81749785f , 0.52952675f , + -0.83745738f , -1.08740279f , -0.81741019f , -0.19035650f , 0.26494816f , -0.53562479f , 0.07089504f , 0.57372383f , 0.54761482f , 0.03039794f , -0.04447253f , 0.12483594f , 0.21652272f , -0.29093744f , -0.18196704f , -0.42015965f , -0.35529408f , -0.64256034f , -0.65492788f , -0.67987885f , -0.90903026f , -1.04259245f , -1.11997561f , -1.06502927f , + 0.35909764f , -0.87235994f , -0.84471723f , -0.71941795f , -0.63106065f , -0.13584873f , 0.00035122f , 0.92117956f , 0.23226720f , 0.38257788f , 0.53266968f , 1.00892757f , -0.01254911f , -0.72578637f , -0.87564652f , -0.59001429f , -0.10713772f , 0.64583948f , 2.23457520f , 2.05203337f , -1.05813794f , -0.53728713f , -0.98376127f , -2.32960660f , + -0.37609544f , 0.57819159f , 0.36973473f , -1.59244337f , -1.38928585f , 0.17356612f , 0.05708517f , 0.55433790f , 0.59850517f , 0.28868283f , 0.11861574f , 0.18433235f , -0.05806802f , -0.05763413f , -0.27751060f , -0.18177730f , -0.00964178f , -0.38778247f , -0.57380279f , -0.56566098f , -0.62571613f , -0.59413960f , -0.61423645f , -0.79876589f , + 0.83478463f , -0.27534215f , 0.01524335f , -0.21639948f , -0.24423974f , -0.23618527f , -0.33317320f , -0.47935624f , -0.15249438f , -0.20363495f , 0.10344548f , -0.31742304f , -0.80171882f , -0.52313955f , 0.00839865f , 1.52844134f , 1.65181493f , -1.32088237f , -0.92249349f , -1.06298456f , -0.07484235f , -0.16968152f , -0.27904781f , -0.28263495f , + -0.35596324f , 0.22314830f , 0.17976713f , 0.03198763f , -0.12387166f , 0.15347508f , -0.07824379f , -1.73831583f , 0.24945724f , 0.50825939f , 0.37505775f , 0.09671258f , -0.42450737f , -0.00807859f , 0.43247130f , 0.47374177f , 0.08198413f , -0.17182369f , -0.24951122f , -0.40607268f , -0.34400714f , -0.49624679f , -0.37255649f , -0.39973249f , + -1.17006196f , -0.13172492f , -0.00974038f , 0.34580927f , -0.44057385f , 0.93062397f , 0.69327166f , 0.08607482f , -0.08210773f , -0.04718499f , -0.07694656f , -0.11915558f , -0.27321781f , -0.38372565f , -0.17058554f , -0.11705279f , 0.00039928f , -0.05191028f , -0.21529579f , -0.57393337f , -0.82568921f , -1.24107379f , -1.47599343f , -1.53248379f , + -0.21719645f , -0.19291913f , -0.75004495f , -0.71951649f , 0.47553953f , 1.38096577f , 1.04033311f , -0.03221815f , -0.86572179f , -0.39911324f , 0.01402460f , 0.13262858f , -0.09635214f , 0.32714710f , -0.23837385f , -0.85773163f , -0.88110961f , -0.98073890f , -0.79564795f , -0.61482268f , -0.51303751f , -0.17108237f , 0.13139182f , 0.33062304f , + -0.65971615f , -0.36376531f , -0.48204612f , -0.96580829f , -0.38529047f , -0.02620179f , -0.58558478f , -0.71688128f , -0.19952990f , -0.35258890f , 0.23812036f , 0.76018967f , 0.76511691f , -0.04406894f , 0.27021687f , 0.17352452f , 0.10253468f , 0.11128335f , 0.11180254f , 0.02374565f , 0.06920751f , 0.16750231f , 0.07976935f , 0.01873091f , + -0.56879426f , -0.30163117f , -0.21853853f , -0.53731934f , 1.94762983f , -0.40486765f , -0.45665477f , -0.68446479f , 0.29429121f , 0.03909750f , 0.15870855f , 0.44189594f , 0.50054032f , -0.21856641f , -1.18939515f , -0.79884717f , 0.37048428f , 0.68697692f , -0.60894758f , 0.22049746f , -0.40599348f , -0.85599586f , -1.02469575f , -1.24963523f , + -0.59195437f , -0.70945563f , -0.15260636f , -0.11149946f , -0.27565596f , -0.07645921f , 0.39497828f , 1.24678661f , 1.18358424f , 0.31430952f , -0.55975403f , -1.31101207f , -0.69091358f , 0.28078628f , -0.21792173f , -0.25137229f , -0.03764299f , -0.16055917f , -0.23425462f , -0.30830760f , -0.03132299f , -0.07131420f , 0.12064408f , 0.03452070f , + 0.64730537f , 0.25294955f , 0.59073653f , -0.02889400f , 0.46909137f , 0.64173464f , 0.30648456f , 0.11024926f , 0.62116350f , 0.28226056f , 0.21516616f , -0.18069190f , -0.26872093f , -0.28573023f , -0.55069608f , -0.59818666f , -0.76225667f , -0.64631598f , -0.73617734f , -0.72489209f , -0.60849158f , -0.66871466f , -0.59332250f , -0.53455648f , + -0.07107892f , -0.12362226f , -0.21667130f , 0.08342061f , -0.26377510f , -0.22955671f , 0.28415481f , -0.59587984f , 0.76501116f , 0.53927870f , -0.41773182f , -0.62604889f , 1.72550145f , 0.83771852f , -1.09720899f , -0.92889980f , 0.00835226f , -0.53818200f , -0.40166509f , -0.77584442f , -0.86058879f , -1.07506625f , -0.75645733f , -0.37900991f , + -0.86391437f , -1.56875806f , -0.59737022f , 1.47103303f , 0.58013388f , -0.61125685f , 0.21215056f , -0.82381155f , -1.02435909f , 0.44360022f , 0.46674660f , -0.24399003f , 0.05535292f , -0.13537148f , 0.53716959f , 0.38570703f , 0.15789830f , 0.82344300f , 0.71725375f , -0.08478097f , -0.19045110f , -0.30913951f , -0.71208241f , -0.41211249f , + 0.28300838f , 0.07819052f , -2.59554850f , 0.01513969f , 0.02275068f , -0.41900901f , 0.35308403f , -0.22328483f , -0.08406000f , -0.23448738f , -0.01463282f , 0.10979483f , 0.06169874f , 0.11653196f , 0.19591528f , 0.38801499f , -0.27219161f , -0.03580387f , -0.39412610f , -0.54966348f , -0.43187400f , -0.26346025f , 0.10805189f , 0.47603876f , + -0.44926755f , -0.27303642f , -0.70688129f , -0.60385437f , 2.03834457f , -0.29886385f , -0.37220015f , -0.40157890f , 0.00114372f , -0.55682607f , 0.18940701f , -0.90851567f , -0.11558088f , -0.30509965f , 0.37725906f , 0.36395947f , -0.01158594f , -0.11778388f , -0.08166158f , -0.00099729f , -0.03361890f , 0.17877023f , 0.46953351f , 0.60661120f , + -2.32090231f , 0.31006497f , 0.43589911f , 0.16050441f , 0.04916749f , -0.07132427f , -0.10907864f , -0.15235030f , -0.34310944f , -0.38589894f , -0.22420356f , 0.28262581f , 0.26288112f , 0.10104567f , 0.30661547f , 0.15586639f , 0.12838052f , 0.16339047f , 0.31122445f , 0.21703946f , 0.05094335f , -0.36066770f , -0.52001051f , -0.85195920f , + 0.81157773f , -0.87377611f , 0.35897335f , 0.97922466f , 0.21161336f , 0.61189108f , 0.09975497f , 0.85557541f , 0.44633554f , -0.06799683f , -0.82196168f , 0.18733624f , -0.11555839f , -0.46227977f , -0.84455317f , -0.28718848f , 0.18823232f , 0.02081597f , 0.20496005f , -0.18321698f , -0.53186346f , -0.76751019f , -0.82707771f , -0.93511852f , + -0.62789782f , -1.02899916f , -0.83398776f , 0.34736659f , -0.82847318f , -0.55517102f , 0.73944715f , 0.51603042f , -0.17541205f , -0.51297491f , -0.28031225f , 0.37534747f , 1.33255256f , 0.85299363f , -0.49866574f , -0.70931713f , -0.25347802f , 1.18650471f , 0.96320283f , 0.17951998f , 0.50223738f , 0.94745145f , 0.71031145f , 0.35981922f , + 0.25960499f , 0.20085615f , 0.66071489f , -0.39300998f , -1.04584452f , 0.68763487f , 0.24341422f , -0.44681709f , -0.42478638f , 0.35809846f , 0.23651606f , 0.24690213f , 0.02840220f , 0.15533695f , 0.09128538f , -0.06270472f , -0.06713015f , -0.25335122f , -0.38172369f , -0.13095063f , 1.38549753f , 1.56595584f , -0.79491152f , -1.69456364f , + 0.10124015f , 0.44268052f , 0.41947170f , 0.06998858f , -0.44403538f , -0.53833083f , -0.18012515f , 0.19801548f , 0.02848198f , 0.10328039f , 0.05547373f , -0.08134220f , -0.11347284f , 0.18716972f , 0.15052121f , 0.45578915f , 0.17825613f , -0.62982728f , -1.25893192f , -1.72372974f , -1.52843742f , -1.14720248f , -0.59782030f , 0.41304965f , + -0.65791072f , 0.50448348f , -0.22790188f , 0.65577284f , -0.41604305f , 0.48294798f , -0.01782262f , 0.11258538f , 0.45414723f , 0.46990532f , 0.18373223f , -0.25480101f , -0.03967844f , 0.14242292f , -0.18186310f , -0.44759830f , -0.48848859f , -0.23499694f , -0.00449827f , 0.06947204f , 0.24366262f , 0.18799436f , 0.16493984f , 0.07341900f , + -0.17084500f , -0.52693384f , -0.15426250f , -0.36638752f , -0.08888879f , 0.42508938f , 0.70488045f , 0.35337658f , -0.31440288f , -0.95905412f , -1.39777356f , -0.73044215f , -0.21780251f , 0.16276937f , 1.17947648f , 0.62166831f , 0.26018916f , -0.29948472f , -0.58195133f , 0.45241574f , -0.06192729f , -0.35749657f , -0.32541389f , -0.31290178f , + 1.03333306f , -1.91050021f , -0.13109130f , -0.32248959f , -0.38101335f , 0.00494321f , -0.25107010f , -0.01681079f , 0.21943144f , 0.25121705f , 0.18563785f , 0.03636768f , -0.10100837f , 0.06649688f , -0.00664293f , 0.05595170f , -0.06422094f , -0.11002354f , -0.10109236f , 0.01090687f , 0.06631093f , 0.07976458f , 0.15739108f , 0.10857007f , + -0.33199571f , -0.56448889f , -0.45287501f , -0.05693402f , 0.05942782f , -0.02093585f , -0.20271071f , 0.55906399f , -1.15218041f , 0.70760814f , 0.15200578f , 0.36721991f , -0.31006992f , 0.02414406f , 0.01873367f , -0.06168544f , -0.14084190f , 0.06391549f , -0.04024367f , -0.07702959f , -0.02899824f , -0.00754099f , 0.01931078f , 0.01310811f , + 0.69225346f , 0.84703204f , -0.19222695f , 0.59171381f , 0.90355259f , 1.04460186f , 0.42894358f , -0.70178829f , -0.37391764f , -0.32821766f , -0.50107079f , -0.39470843f , -0.47521936f , -0.30884997f , -0.01935248f , 0.29822241f , 0.42715252f , 0.30438803f , 0.02378992f , -0.17775730f , -0.46267559f , -0.55927080f , -0.39468999f , -0.38547224f , + 0.04236230f , 0.43024591f , 0.23320886f , -0.03322528f , 0.26547627f , 0.40419917f , -1.88256953f , 0.33336965f , 0.43032431f , 0.34945524f , 0.14640688f , 0.26111890f , 0.09050959f , 0.02378679f , 0.10374918f , -0.14167201f , -0.38323030f , -0.20424346f , -0.07877651f , -0.15358523f , -0.29084030f , -0.28534203f , -0.27854188f , -0.38414543f , + -1.35067299f , 0.93458694f , 1.52963743f , -0.47674751f , 0.63038639f , 0.04082455f , 0.01396927f , 0.26394766f , 0.21929233f , 0.30917185f , -0.05098944f , -0.21646126f , -0.06968916f , -0.21403511f , -0.42684368f , -0.24236372f , -0.25734336f , -0.24137196f , -0.18847818f , 0.05790433f , 0.47029098f , 0.74262516f , 1.02334770f , 1.07200952f , + 1.83813338f , 0.07329820f , -0.57353904f , -1.04253446f , -0.37247340f , 0.27885340f , -0.44127016f , -0.52596624f , -0.25949219f , -0.21831662f , -0.08737252f , 0.35876725f , 0.27309909f , 0.22976268f , 0.34570166f , 0.21284816f , 0.20626047f , -0.06110003f , -0.17056277f , -0.33205968f , -0.17877150f , -0.36375995f , -0.42667310f , -0.49148755f , + -0.22303223f , -0.61782734f , 0.07221479f , 1.17445515f , 2.13609068f , 1.76589885f , -0.17154121f , -0.54143140f , 0.11077396f , -0.12473649f , -0.52786787f , -0.05194147f , -0.44717763f , -0.76381778f , -0.72611078f , -0.52076079f , -0.13782787f , 0.23657528f , 0.01943847f , 0.24767381f , 0.39174174f , 0.63263104f , 0.63997347f , 0.76935917f , + 0.38916423f , 0.50423553f , -0.21980701f , -0.78548685f , 0.21972204f , -1.43872473f , -0.00193477f , 0.36744541f , 0.16700668f , 0.15377980f , 0.47950705f , 0.29978828f , -0.11417606f , 0.16176485f , -0.11482538f , -0.05361745f , -0.12586636f , -0.09325236f , -0.14811836f , -0.05048373f , 0.10243041f , 0.21861802f , 0.33250117f , 0.27345191f , + -0.16468513f , -0.37910979f , 0.57141664f , 0.42620144f , 0.44428971f , -0.54448346f , -0.05612505f , -0.02298608f , 0.53916950f , 0.25456592f , -1.10661655f , 0.40146315f , 0.12765698f , 0.17879679f , -0.07731271f , 0.01866167f , -0.15740825f , -0.28894193f , -0.34340439f , -0.43682656f , -0.22326149f , -0.09309579f , 0.16725751f , 0.19673331f , + -0.65757909f , -0.55769769f , 0.11252773f , -0.72975912f , -0.94079760f , -0.62713476f , -0.11981244f , -0.17247533f , -0.14738685f , -0.31158412f , 0.07368734f , 0.03103339f , -0.13215125f , 0.34103810f , 0.63393867f , 0.60552884f , 0.76554800f , 0.90960605f , 0.91659500f , 0.66527593f , 0.30424524f , 0.11961615f , -0.11209393f , -0.30051986f , + -0.82645253f , -0.59100209f , 0.39970568f , 0.22244794f , -1.28440435f , -0.46429652f , -0.43824168f , -0.32298820f , 0.10465933f , 0.69271672f , 0.92760147f , 0.82494517f , 0.34287482f , 0.34953026f , 0.02628626f , -0.35943701f , -0.39877485f , -0.31291814f , -0.37557165f , -0.14676958f , -0.17425675f , -0.18461930f , -0.05110559f , -0.07497296f , + 0.63983165f , -0.34339191f , -1.28647231f , -0.91450456f , -0.67728709f , 0.49126298f , 0.96821534f , 0.31300605f , 0.20917849f , 0.12659990f , -0.36342261f , -0.39963395f , 0.03244120f , -0.41837324f , -0.14271340f , -0.19770449f , 0.05878109f , 0.55231761f , 1.04404725f , 1.05536545f , 0.78016416f , 0.27780151f , 0.09224589f , -0.32156570f , + 1.30003273f , 1.10615566f , 0.93319181f , -0.31410562f , -1.16956697f , 0.45520743f , 0.46104645f , 0.18090068f , 0.31535574f , 0.12164263f , -0.04591607f , -0.26863484f , -0.02921210f , -0.15765476f , -0.25295046f , 0.08951494f , 0.29990800f , 0.46529486f , 0.49388104f , 0.48334578f , 0.56975339f , 0.86976618f , 0.99832143f , 1.00030209f , + -0.55945569f , -0.48562099f , -0.51312465f , 0.17718364f , -0.05557705f , -0.12420531f , -0.24644329f , -0.21879889f , 0.30085953f , 0.00211036f , -0.18180571f , 1.26296385f , 0.36245046f , -1.20467536f , -1.38107334f , 0.51651968f , 0.96691210f , -0.21489415f , -0.08106702f , 0.07733171f , 0.44486220f , 0.65985117f , 0.65337579f , 0.40205936f , + -0.30605618f , 0.02127030f , 0.13771863f , 0.12191376f , 0.08563477f , -0.00381708f , -0.81881216f , -0.82260335f , -0.43603699f , 1.36965455f , 4.16686363f , -1.70970343f , -0.32019699f , -0.11951735f , -0.80947648f , -0.47446757f , -0.10775129f , 0.04114059f , -0.30054633f , 0.64175035f , 0.82115142f , 0.62944370f , 1.08179899f , 1.57667179f , + -0.66788387f , -0.77237720f , 1.52623021f , 0.85040444f , 0.35492746f , 0.85358404f , 0.78207517f , 0.43130368f , -0.54845102f , -0.71654944f , -0.60068901f , -0.12408427f , -0.01179498f , 0.53882278f , 0.31915828f , -0.32987316f , -0.94788725f , -0.40099308f , -0.01063294f , -0.38326806f , -0.01161978f , -0.21941390f , 0.02258487f , 0.25904448f , + 0.79869030f , -0.85517012f , -0.65115608f , -0.04355956f , -0.43731619f , -0.71616470f , -0.30302847f , 0.88809204f , 0.05112801f , 0.10303432f , 0.13671577f , 0.57965072f , 0.32487238f , 0.33649929f , 0.01540811f , -0.25814148f , -0.72026311f , -1.15836561f , -1.20004844f , -0.81812408f , 0.41446837f , 1.03057194f , 1.42461866f , 1.82616342f , + 0.17675536f , -0.27924845f , 0.71723708f , 0.57533161f , -0.11526653f , 0.43395839f , -0.24166179f , -0.76071716f , -1.50945411f , -1.22484500f , -0.26852216f , 1.13903054f , 1.01376035f , 0.64844913f , 0.40121308f , 0.49004723f , -0.00594971f , -0.16285024f , -0.35446584f , -0.43396060f , -0.49929653f , -0.30312166f , -0.52537515f , -0.70337166f , + -0.01631724f , 0.04545139f , 0.53843851f , -1.98110624f , 0.42385228f , 1.10982161f , 0.08204933f , -0.22120343f , 0.22170428f , -0.13084571f , -0.38312127f , -0.33942169f , -0.35304155f , -0.04620752f , -0.20644844f , -0.11783954f , -0.03944293f , 0.22733974f , 0.19411990f , 0.20591734f , 0.35857215f , 0.26680777f , 0.13225980f , 0.03751274f , + 1.65876005f , 0.44487285f , 0.74939639f , 0.18365303f , -0.43020202f , -0.60237220f , -0.25419435f , 0.68333923f , 1.41188058f , 0.97222943f , 0.24472516f , -1.22113362f , -0.78612825f , -0.11991861f , 0.13256744f , -0.36248959f , 0.33181909f , 0.32143886f , 0.23857089f , 0.00232431f , 0.32728111f , 0.18236067f , 0.19458883f , -0.13449373f , + 1.01250205f , 0.78159362f , 0.01261799f , 0.68249798f , 0.04319542f , 0.35059328f , 0.74464616f , 0.84844350f , -0.11329224f , 0.41294739f , 0.18293144f , 0.20984708f , -0.58769014f , -0.80150375f , -0.51500468f , -0.35048400f , -0.42362303f , -0.36779032f , -0.28994050f , -0.23359131f , -0.06578403f , -0.05881381f , 0.08966738f , 0.00019544f , + 0.70403072f , 0.78285193f , 0.28511894f , 0.00755209f , -0.37995087f , -0.72155263f , -0.99707384f , -0.74737344f , -0.22877183f , -0.13565785f , -0.46966212f , 0.04900542f , 0.26640966f , 1.14596859f , 0.60401715f , 0.82513938f , 0.79006003f , 0.37851130f , 0.22098744f , 0.20295618f , 0.31645545f , 0.57600633f , 0.77757957f , 0.75482137f , + -0.31257984f , -0.82866492f , 0.10257062f , 1.11051690f , -0.28919177f , -0.56055958f , -0.92349260f , 0.14536629f , 0.59860128f , 0.38979660f , 0.36223511f , -0.54044378f , -0.36717720f , -0.11683797f , 0.76699709f , 0.24571187f , 0.28893468f , 0.47314073f , 0.42211323f , 0.40023200f , 1.13398057f , 1.09318885f , 0.78306966f , 0.51052587f , + 0.64453179f , 0.37582288f , -1.11900539f , 0.74031316f , 1.04873921f , -0.40828504f , -0.81838582f , -0.17966094f , -0.05226590f , -0.65864031f , -0.31516753f , 0.18237239f , -0.05159927f , 0.21789484f , 0.08749049f , 0.24120803f , 0.70600965f , 0.64124786f , 0.42083380f , -0.09773141f , -0.23606513f , -0.38900548f , -0.47036719f , -0.54328594f , + 0.19215906f , 0.37207957f , 0.52832092f , -0.35006098f , 0.09333668f , -0.08723831f , 0.13342910f , 0.37870962f , 0.31836369f , -1.28479417f , 0.33703877f , 0.14237789f , 0.05993876f , 0.02873350f , 0.23865068f , -0.04501394f , -0.31343410f , -0.18101341f , -0.24548541f , -0.25187640f , -0.07255855f , -0.10957046f , -0.11231929f , -0.28412748f , + -0.68394190f , 1.32649088f , -0.20251428f , 0.26341125f , 0.12047780f , -0.18276225f , 0.16509523f , 0.52338615f , 0.59701878f , -0.23303681f , -0.39329168f , -0.08757063f , -0.16628726f , -0.65649992f , -0.39211601f , 0.17386600f , 0.53243333f , 0.71723255f , 0.49078614f , 0.24827219f , 0.06289971f , -0.05734434f , -0.11833561f , -0.22187979f , + 0.39633308f , 0.04156044f , 1.06101733f , 0.27315319f , 0.59336180f , -0.53703174f , 0.16228868f , 0.13114487f , 0.27822076f , 0.36752801f , 0.19860881f , 0.02973693f , -0.43825412f , -0.58401569f , -0.28187681f , 0.04818616f , 0.03285983f , 0.13037889f , 0.11038839f , 0.02272515f , -0.23535124f , -0.61140662f , -0.80591081f , -1.04033145f , + -0.13968644f , -0.06564459f , 0.18157254f , 0.33968636f , -1.65427724f , -0.73513587f , 1.04378907f , 1.88232308f , -0.37664399f , -0.27362352f , -0.33476530f , 0.38907833f , 0.34755286f , -0.33257534f , -0.02008915f , 0.33980081f , -0.27671777f , -0.19240561f , -0.07016053f , 0.46780800f , 0.13346733f , 0.34947591f , 0.60154010f , 0.24323917f , + -0.39262699f , 0.20645882f , 0.64129296f , -0.83583673f , -0.02829965f , -0.15644726f , 0.05838216f , 0.14551091f , 0.14988963f , 0.11803820f , -0.32326940f , 0.68272158f , 0.31487041f , 0.19785659f , -0.39751586f , -0.35328008f , -0.40849303f , -0.08677978f , 0.86709071f , 2.23822727f , 1.53306955f , 0.78362429f , -0.23530753f , -0.72391215f , + 0.65081318f , -0.18880278f , -0.46498433f , 0.26852197f , -0.77114484f , 0.03361544f , -0.35148506f , 0.22060019f , 0.18248041f , -0.12293613f , -0.11807126f , 0.14429704f , 0.05679295f , 0.22972542f , 0.12354306f , 0.16318102f , 0.20910602f , 0.08354589f , -0.24387542f , -0.29604028f , -0.70475015f , -1.05341049f , 0.01797512f , 4.10874675f , + 0.45835477f , 0.01993812f , -0.04065773f , -0.15665852f , -0.42264630f , -0.36060614f , -0.43907429f , -0.66069837f , -0.24237031f , 0.15215315f , 0.03612217f , 0.24708032f , 0.55884560f , 0.72918318f , 1.75786010f , -0.70099106f , -0.65499421f , 0.89851270f , 1.07676113f , 0.70864260f , -0.27784651f , -0.35596115f , -0.12995875f , 0.20579609f , + 0.41191636f , 0.62621815f , 0.09298962f , 0.55341001f , 0.56857786f , 0.43563939f , 0.36112747f , 0.91004762f , -0.20875537f , -0.76286980f , -0.80355493f , -0.57667740f , -0.12055277f , 0.03202311f , 0.30982039f , 0.02801005f , -0.17407837f , 0.00238884f , -0.00072431f , 0.20627903f , 0.75917669f , 0.94538134f , 1.07598898f , 1.25330200f , + 1.62660683f , -0.09939473f , 0.66227464f , 0.58551798f , 0.70671700f , 0.17084690f , -0.20901679f , -0.40736809f , -0.48424703f , 0.03110675f , 0.17837373f , 0.15654547f , 0.05523718f , -0.00011673f , -0.03885655f , -0.10282160f , -0.05607837f , -0.02472319f , -0.02603773f , 0.16068736f , 0.49195589f , 0.53877406f , 0.64916929f , 0.58349185f , + -0.19541004f , 0.72348145f , 0.18424396f , -0.24664098f , -0.06871482f , 0.69420972f , 0.47406100f , -0.17312110f , -2.04415513f , -0.25411034f , -0.27524224f , 0.06647737f , 0.24326809f , 0.16942888f , 0.40718778f , 0.35988573f , 0.40128652f , 0.49142944f , 0.60191512f , 0.34882977f , 0.16989975f , 0.24984840f , 0.27163863f , 0.15321543f , + -0.44196663f , -0.26819397f , 0.67190611f , -0.18646133f , 0.45381660f , 1.11913414f , -0.16504930f , -0.57004245f , 0.12959909f , 0.01138749f , -0.36040681f , -0.97442716f , -0.87831396f , -0.14292832f , 0.42648657f , 0.25148162f , 0.69831357f , 1.48191698f , 1.27272976f , 0.11336886f , -0.87051097f , -0.59490814f , -0.81852032f , -1.19619968f , + -0.25757408f , 0.54305128f , -0.79688385f , -0.60924273f , -0.12316087f , 0.11158591f , -0.87972153f , -0.44243737f , 0.18336137f , 0.70958050f , 0.65996224f , -0.03788380f , -0.46562482f , -0.32237563f , -0.18491199f , 0.26669422f , 0.52467917f , 0.59451930f , 0.79600063f , 0.90689924f , 1.13895471f , 1.44288125f , 1.66630190f , 1.46406996f , + 0.88003703f , 2.56458597f , 1.71193850f , 1.65285002f , 0.72084892f , 0.38643126f , 0.14318446f , 0.28667315f , -0.19288261f , -0.16566274f , -0.31005972f , -0.49025502f , -0.18453165f , -0.14612403f , -0.04808515f , 0.01128747f , -0.01064585f , -0.12855927f , -0.22958706f , -0.19555403f , 0.02963856f , -0.01023782f , -0.12652262f , -0.10513883f , + 0.66279753f , 2.42221261f , -0.08766251f , -0.72413474f , -0.21245882f , -0.28173391f , -0.45644329f , -0.27322613f , -0.26135706f , -0.00095259f , 0.27722008f , 0.50181970f , 0.53741922f , 0.02301582f , 0.05101261f , 0.08308112f , 0.01205931f , 0.03237543f , -0.19025538f , -0.25886072f , -0.65187116f , -0.67398548f , -1.14025176f , -1.58932661f , + 0.17921058f , 0.08258647f , 0.33959227f , 1.72037280f , 1.38344521f , -0.23430972f , -0.50065409f , 0.00856925f , 0.28114664f , 0.27461748f , 0.31709158f , 0.82901212f , -0.15113492f , -0.25813352f , -0.41877594f , -0.81233724f , -0.71788760f , -0.16907758f , 0.19973863f , 0.33985209f , 0.02718327f , 0.32739235f , 0.74128769f , 0.93245569f +}; + +const float cdk_37bits_4[1536] = +{ + -0.08826527f , -0.68186913f , 0.10838073f , -0.43643363f , -0.41527175f , -0.55730727f , -0.34319791f , -0.40335689f , -0.41236590f , -0.43762241f , -0.34979692f , 0.20670516f , 0.56648629f , 0.45153526f , 0.24057949f , 0.52851143f , 0.92657151f , 0.59941681f , -0.15803439f , -0.97113347f , -0.53306250f , -0.15122053f , -0.25212109f , -0.21018566f , + 0.39520775f , -0.06876283f , -0.05296158f , 0.73104266f , 1.42403499f , 0.45421406f , -0.17043922f , -0.74733849f , -0.66305214f , -0.55365607f , -0.35289753f , -0.04055727f , -0.10593728f , -0.05024752f , 0.12627425f , 0.32227232f , 0.35862945f , -0.33025092f , -0.42097571f , -0.51789189f , -0.43150446f , -0.42237163f , -0.31356874f , -0.35919061f , + -1.66468995f , 0.28333893f , -0.63138470f , 0.25282895f , 0.81464016f , 0.43544261f , 0.16598498f , 0.21343499f , 0.04430694f , 0.04005313f , -0.09506983f , -0.40633891f , -0.37109338f , -0.10155129f , -0.25586130f , -0.50829977f , 0.02467106f , -0.22449907f , 0.00822338f , 0.18455191f , 0.25447269f , 0.12288496f , -0.09567011f , -0.30095943f , + -1.15666522f , -0.30930290f , 0.13432561f , -0.59224171f , -0.36982119f , -0.52250238f , 0.01911206f , -0.29889977f , 0.45230096f , 0.40142558f , 0.43793893f , 0.22627276f , 0.37598261f , 0.32984874f , -0.34803841f , -0.44638526f , -0.25723637f , -0.50369445f , -0.26783820f , -0.30872225f , -0.55499601f , -0.40533391f , -0.26323584f , -0.01148310f , + -0.04584967f , -0.38971238f , -0.56823951f , -0.32006352f , 0.38538708f , 0.18254611f , -0.62235892f , 0.18540613f , 0.48716625f , 0.35551317f , -0.19313758f , 1.16846919f , -0.41238633f , -0.43448740f , -0.28924472f , -0.56314872f , -0.24952920f , -0.08133851f , -0.17676199f , -0.70674324f , -0.52120829f , -0.49147628f , -0.40464508f , -0.25295616f , + -0.12422787f , -0.29459301f , -0.33474318f , 0.11311031f , -0.95766270f , 2.14261486f , -0.53791490f , -0.26163905f , -0.11342229f , -0.12540336f , -0.14724319f , -0.04078408f , -0.08162598f , 0.06846590f , 0.12489534f , -0.11390681f , 0.04214135f , -0.23484961f , -0.25483115f , 0.02702444f , -0.54449830f , 0.02294024f , -0.03270780f , -0.30881716f , + -0.51664184f , 0.87599163f , -0.82321314f , -0.48734917f , -0.18432637f , -0.09096773f , 0.20625230f , -0.20173932f , -0.40150868f , -0.29584636f , -0.57602568f , 0.25241069f , 0.25168301f , 0.41489722f , -0.15401326f , 0.31749293f , 0.46187393f , 0.14218968f , 0.29387424f , 0.35642876f , -0.05757794f , -0.25296762f , -0.36044236f , -0.53221886f , + 0.51447760f , -0.80338660f , -0.87861055f , 0.14544497f , 0.05095110f , -0.51385736f , 0.05449902f , 0.17409103f , 0.19329486f , -0.46366308f , -0.07068299f , 0.20485704f , -0.47646816f , 0.35635013f , 0.34452862f , 0.42683101f , -0.28134904f , -0.21080113f , 0.00849886f , 0.33035851f , 0.26195824f , 0.51184835f , 0.52439902f , 0.46235637f , + 0.32433320f , -0.77116443f , -0.37467928f , -0.05050502f , -0.47203456f , 0.07970732f , 0.03804198f , -0.34236150f , 0.41937760f , 0.42124343f , -0.03903765f , -0.03019702f , -0.13800061f , -0.47850547f , -0.79736222f , 0.61109423f , 0.72782314f , -0.09672306f , -0.16557727f , 0.16492016f , -0.11908040f , -0.37060885f , -0.80248368f , -1.06315439f , + 0.61844207f , -0.52687155f , -0.68500569f , 0.65092780f , 0.43851285f , -0.21063978f , -0.35770140f , 0.29858871f , -0.24062148f , 0.02631244f , -0.33422324f , -0.66271400f , 0.44374236f , 0.53668473f , 0.31036600f , -0.08124190f , -0.16668944f , -0.32551675f , -0.33450272f , -0.55269795f , -0.29912814f , -0.14136754f , 0.00094991f , 0.10863138f , + -1.02908550f , -1.08600196f , -0.00829438f , -0.14868032f , -0.00876750f , 0.35258516f , 0.23126957f , -0.61722565f , 0.07518664f , 0.16350336f , -0.12544307f , -0.06302285f , -0.20747087f , 0.16364178f , 0.11301830f , 0.14409114f , -0.22179807f , 0.02183975f , 0.08651544f , 0.10457808f , 0.28231708f , 0.45543402f , 0.44769940f , 0.39725637f , + -0.54707227f , -0.02419958f , -0.37616905f , -0.46877412f , -0.64214865f , 0.24761536f , 0.28016618f , 0.62399842f , -0.01700123f , -0.06949885f , -0.19266995f , 0.09365999f , 0.49890228f , 0.24080752f , 0.23087678f , -0.34184149f , -0.95236318f , -0.94491904f , -0.91565308f , -0.37099678f , 0.27911164f , 0.41946017f , -0.09527805f , -0.32953030f , + -0.01218671f , 0.22317147f , 0.12463154f , -0.28374239f , -0.37139030f , -0.11082455f , -0.20149460f , 0.02373646f , -0.33497796f , -0.14613409f , 0.84054162f , -0.89918850f , 0.07544184f , 0.26598709f , 0.27674891f , 0.20394454f , 0.37767382f , -0.42106119f , -0.34271983f , -0.11246076f , 0.03134837f , -0.21267097f , -0.66433234f , -0.79249183f , + 0.68565476f , -0.34282863f , -0.68036436f , -0.63475767f , -0.29231604f , -0.10656705f , 0.47040998f , 1.11298872f , 0.05838917f , -0.14239264f , -0.38985619f , -0.25211584f , -0.07283441f , -0.47047779f , -0.10102956f , -0.06816871f , 0.25442684f , 0.17135717f , 0.18068089f , 0.10725115f , -0.11463252f , -0.09624811f , 0.03206543f , 0.07087342f , + -0.29936977f , -0.49951612f , 0.56346184f , 1.11727567f , 0.05118005f , -0.78169038f , -0.22318233f , -0.13012064f , 0.42376494f , 0.27511994f , -0.06809198f , 0.10660060f , -0.13063709f , -0.08794603f , 0.26570905f , 0.03292540f , 0.26637413f , -0.19894586f , -0.46401960f , -0.28512188f , -0.39238542f , -0.32134023f , -0.64138162f , -0.88237115f , + -0.84203625f , 0.64837205f , -0.17913585f , -0.02044868f , 0.01755708f , 0.10928040f , -0.42224314f , -0.62418953f , -0.76712318f , 0.28173569f , 0.49961967f , 0.56539632f , 0.38946613f , -0.52975196f , -0.01398100f , 0.29168654f , 0.20212686f , -0.45414046f , -0.32780637f , -0.17832453f , -0.04055271f , 0.14063062f , 0.09399186f , 0.04073656f , + -0.59723568f , -0.77426417f , 0.23870880f , -1.09302554f , -0.22352372f , -0.10808799f , -0.30228652f , 0.70554939f , 0.06689791f , -0.27543124f , -0.16109074f , 0.39983998f , 0.14600029f , 0.02701649f , -0.30161728f , -0.00219904f , 0.02886825f , -0.00025967f , 0.06332021f , 0.53722019f , 0.26361456f , 0.43646772f , 0.61394343f , 0.42109711f , + -0.43760700f , -0.21770975f , -0.32449972f , 0.91826996f , 0.24783245f , -0.14194616f , 0.59717550f , -0.04725228f , -0.61148813f , 0.06530696f , 0.35852872f , 0.21424802f , 0.01537298f , -0.15430889f , -0.27459726f , -0.13011870f , -0.13872373f , -0.36362740f , -0.43974823f , -0.43751521f , -0.54202762f , -0.19719673f , 0.06386372f , 0.18442456f , + -0.08864543f , -0.55051998f , 0.10076329f , 0.20816090f , 0.53932942f , 0.15080000f , 0.00551145f , 0.12469664f , 0.10528548f , -0.05291477f , 0.52671815f , 0.10465375f , -0.40110729f , -0.11191133f , 0.98775607f , -0.67510753f , -1.30383213f , 1.28526656f , 0.19125450f , -0.16824100f , -0.63934107f , -0.41185818f , -0.34166262f , 0.14722503f , + -0.16958138f , -0.70266121f , -0.61550966f , -0.70951491f , 0.42067433f , -0.58598257f , -0.58567156f , -0.37146356f , -0.36153853f , 0.34830089f , 0.34255947f , 0.14665779f , -0.08274605f , 0.14596150f , 0.21786608f , 0.24560479f , 0.11959326f , 0.23920513f , 0.20309485f , 0.35852167f , 0.22083612f , -0.09433997f , -0.51773984f , -0.76810711f , + 0.09032751f , 0.42679636f , -0.28534103f , 0.21660665f , 0.47417813f , -0.81135171f , -0.99303930f , 1.17719925f , 0.70112272f , 0.00612786f , -0.26326442f , -0.41083270f , 0.28491165f , -0.02087201f , -0.14822163f , 0.12923365f , -0.12446203f , -0.33986599f , -0.41895285f , -0.31072727f , -0.31061808f , -0.24015583f , -0.23486759f , -0.36395849f , + -0.07413177f , -0.34521290f , -0.06577322f , -0.64923405f , 0.33496936f , 0.33223433f , -0.43032623f , -0.15153657f , -0.14532386f , 0.04384948f , -0.14353961f , -0.38067294f , -0.90445571f , 0.05745547f , 0.26321275f , 0.13427661f , 0.99048885f , 0.70150503f , 0.21638320f , -0.53518619f , -0.89368294f , -0.06732509f , 1.44618313f , 1.52346980f , + -0.28620228f , -0.41428071f , 0.03283058f , 0.28330900f , 0.28721719f , 0.17075826f , 0.19511151f , -0.13348216f , -0.35836936f , -0.41912925f , -0.65172261f , -0.20553457f , -0.41361716f , 0.03912969f , 0.74818546f , 0.38929433f , 0.35198685f , -0.18892266f , -0.42973273f , -0.08121690f , 2.93312199f , -0.89377191f , -1.04200958f , -0.38574966f , + -0.45622789f , 0.07453795f , -0.34784213f , -0.29222109f , -0.09713884f , -0.10453434f , 0.40596355f , -0.23133264f , 0.41138969f , -1.10624661f , 0.19522464f , -0.26295831f , 0.14668871f , 0.07972137f , 0.02069833f , 0.17917700f , 0.36376602f , 0.04686613f , 0.14326025f , -0.04095238f , -0.08246401f , 0.10201219f , 0.02758839f , -0.05655397f , + 0.29630435f , 0.03831385f , -0.10935451f , -0.91468053f , -0.14403908f , 0.12338524f , -0.16558686f , -0.53411536f , 0.34582072f , 0.52105737f , -0.73269102f , 0.15549081f , 0.34042874f , -0.08059104f , 0.05497700f , -0.00373706f , 0.11991085f , -0.06473005f , -0.19246960f , -0.28678310f , -0.43241128f , -0.23538086f , -0.03713469f , 0.08379386f , + 0.24034079f , -0.09568759f , -0.02338538f , -0.28961237f , 0.06180378f , 0.64449270f , -0.53964132f , -0.44965638f , 0.57702251f , -0.03990858f , 0.57093562f , -0.24702367f , 0.69686569f , -0.17564347f , -0.35201424f , -0.37152787f , -0.37484725f , -0.30144848f , -0.16064783f , -0.31374403f , -0.12815488f , 0.29541890f , 1.03104505f , 1.30178989f , + -0.18534500f , -0.41427735f , 0.20831804f , 0.44386174f , 0.06978829f , -0.00025745f , 0.37126911f , 0.56198427f , 0.54344631f , 0.75983386f , 0.08924900f , -0.25144457f , -0.16739214f , -0.47225391f , -0.61115204f , -0.61044836f , -0.28294647f , -0.15658827f , 0.07254076f , 0.04689538f , -0.03222463f , 0.00609252f , -0.03612525f , -0.09035452f , + 0.60889737f , 0.57807827f , 0.48410386f , -0.25108080f , -0.40924958f , 0.41713615f , 0.28334831f , 0.28268008f , 0.18075099f , -0.57117890f , -0.14971473f , 0.56189026f , -0.05567028f , 0.08252752f , -0.38305721f , -0.11908417f , -0.11953224f , -0.37400723f , -0.53048221f , -0.67201768f , -0.81958382f , -0.72027064f , -0.69311476f , -0.64712434f , + 0.22806651f , -0.36466423f , 0.42139538f , -0.34809071f , 0.16113471f , 0.17305177f , 0.79041909f , 0.11514622f , 0.04984584f , -0.14552208f , -0.37364685f , -0.61589400f , -0.26900080f , 0.26941075f , 0.20621872f , 0.13740956f , -0.49840209f , -0.54283296f , -0.52674918f , -0.53961784f , -0.37838808f , -0.22626697f , -0.23072639f , -0.20714483f , + 0.22144144f , 0.45530098f , 0.02934419f , -0.39899990f , 0.47181905f , 0.60295507f , -0.31589266f , 0.03503805f , 0.49654681f , -0.28248396f , -0.72402223f , -0.56858893f , 0.36486216f , 0.18158649f , -0.28256161f , -0.05020847f , 0.07122169f , 0.39556004f , 0.21779191f , 0.05943418f , 0.03455314f , -0.20122464f , -0.56175660f , -0.70861941f , + -0.12710089f , -0.34168755f , 0.51452312f , -0.34309463f , -0.18691030f , 0.49423846f , 0.78364805f , -0.16785659f , -0.68812345f , -0.24302951f , 0.18166059f , 0.09288723f , 0.25148875f , -0.56074443f , -0.33594006f , 0.09135379f , 0.28739172f , 0.63070785f , 0.16827578f , -0.09962802f , -0.38532235f , -0.56717197f , -0.69999986f , -0.97131938f , + -0.20318779f , -0.43550878f , 0.28264744f , -0.23992796f , 0.53190281f , -1.67612143f , 0.16592080f , 0.32242290f , 0.02740567f , 0.27409947f , -0.33298480f , -0.17137320f , 0.21066429f , 0.33840225f , -0.04092118f , 0.12976302f , 0.22063896f , 0.16238007f , 0.17740193f , 0.08810713f , -0.07588522f , 0.07136235f , 0.03907713f , 0.05669444f , + 0.74722369f , -0.21436950f , 0.74573008f , -0.38452217f , -0.62996036f , -0.61276966f , -0.34962832f , 0.01277742f , -0.04862746f , -0.36596994f , 0.22701717f , 0.22604413f , 0.19192867f , 0.43170927f , 0.32434957f , 0.29115238f , 0.30256436f , 0.32053789f , 0.47183832f , 0.56834074f , 0.41355131f , 0.30787160f , -0.05129232f , -0.37603415f , + 0.80624702f , -0.27464628f , 0.11826867f , 0.51984849f , 0.30134746f , 0.32731312f , 0.63578587f , -1.05098699f , -0.28256566f , 0.33641143f , 0.13788720f , 0.12207550f , 0.20964871f , -0.01396386f , -0.00315097f , -0.38868646f , -0.33190516f , 0.01254611f , 0.31412245f , 0.37172503f , -0.22028709f , -0.31539130f , -0.40227820f , -0.43477628f , + 0.48923265f , 0.77885034f , 0.09105701f , 0.57339326f , 0.40328303f , 0.76432879f , 0.86958428f , 0.61756568f , 0.03118874f , -0.56167934f , 0.04763708f , -0.27535056f , -0.56173692f , -0.35211845f , -0.21863091f , -0.57438481f , -0.18963688f , -0.01259367f , 0.18407625f , 0.57694011f , 0.26272878f , -0.04854515f , -0.05438820f , -0.03358252f , + -0.32142589f , 0.79436655f , -0.02373648f , 0.14911871f , 0.27451076f , -0.21064653f , -0.58233970f , -0.20841755f , -0.04707995f , 0.10160263f , 0.52370023f , 0.13469981f , 0.48437770f , 1.02370491f , -0.06404425f , -0.46008443f , -0.96962303f , 0.11051949f , 0.15222102f , -0.53779110f , -0.69372709f , -0.56309673f , -0.29040815f , -0.29949982f , + -0.02231366f , 0.22164658f , -0.18303626f , 0.03930299f , 0.85381138f , -0.35733905f , 0.09213505f , 0.01422806f , 0.45077065f , 0.33125549f , 0.13969212f , 0.00376337f , -1.11355683f , -0.42167326f , -0.19924204f , 0.06780255f , 0.13817913f , -0.13055957f , -0.04191829f , -0.08880165f , 0.10967999f , 0.21611496f , 0.31814813f , 0.31439510f , + 0.42170246f , 0.33624593f , -0.22613320f , 0.60027671f , -1.43986794f , 0.19361445f , 0.38787661f , 0.02591482f , 0.79456209f , 0.02551988f , -0.24845033f , -0.02790537f , 0.03271750f , -0.04445081f , 0.20502713f , 0.08570910f , 0.00909955f , -0.01248239f , -0.03298340f , -0.22777710f , -0.18913055f , 0.02764977f , 0.28305459f , 0.38851360f , + 0.25563805f , 0.33212894f , -0.80098121f , 0.09743245f , 0.06159913f , 0.59881048f , -0.33440346f , -0.49422089f , -0.26800689f , -0.34799111f , 0.00914211f , -0.24239391f , -0.35363956f , 0.18782859f , 0.53150753f , 0.27966626f , 0.37170277f , 0.02903349f , 0.11708475f , 0.18129252f , 0.35350094f , 0.51909923f , 0.57702624f , 0.56023430f , + -0.25681505f , 0.10481743f , 0.07691052f , -0.09602954f , -0.12447488f , -0.40272478f , -0.23240515f , -0.09172820f , -0.10406663f , 0.06799629f , 0.27877064f , 0.65360435f , 0.03477472f , -0.16610473f , 0.19640957f , 1.14225362f , -1.25460658f , -0.02280781f , 0.26718410f , 0.23326014f , -0.33868542f , -0.77563600f , -0.57910551f , 0.35682550f , + -0.44901076f , -0.41537996f , -0.76495288f , 0.42209785f , -0.90605030f , -0.39625885f , -0.28278183f , -0.06062198f , 0.12423915f , 0.20756261f , 0.19484825f , 0.03259953f , 0.41379186f , 0.19062025f , -0.02691834f , 0.12202985f , 0.38700297f , 0.61084418f , 0.41389101f , 0.42854542f , 0.07894843f , -0.08730420f , -0.19947308f , -0.20746447f , + 0.35263591f , -0.04388326f , -0.07294209f , -0.12542102f , -0.45217599f , -0.41959012f , -0.16900409f , 0.23194458f , 0.50540516f , 0.34564113f , -0.05519304f , -0.13052083f , -0.52610268f , 1.51200111f , 0.14243612f , -0.89107328f , -0.09550049f , -0.11976748f , 0.61738910f , 0.29385419f , -0.11218523f , -0.32931430f , -0.63743116f , -0.70832695f , + -0.52572193f , -0.16054333f , 0.67450855f , -0.68123993f , -1.06059852f , 0.25289129f , 0.72282093f , -0.17789928f , -0.04826238f , 0.65623860f , 0.30053556f , -0.04214508f , -0.65996229f , -0.19030221f , -0.07583416f , -0.15972053f , 0.48267006f , 0.29268192f , 0.54289151f , 0.30262687f , 0.55040148f , 0.38139609f , 0.22629776f , -0.10333201f , + -0.27722537f , 0.16931190f , -0.18986341f , 0.46255996f , 0.03451865f , 0.64648839f , 0.27927689f , -0.04817246f , -0.29637504f , 0.15848257f , -1.17177626f , 0.76705595f , 0.04986266f , -0.23619169f , 0.02130871f , -0.09247797f , -0.11246955f , -0.06979877f , -0.02858714f , 0.14146741f , 0.19316987f , 0.19281260f , 0.10108870f , 0.10991318f , + 0.57222024f , -0.09056345f , 0.31630312f , 0.09441631f , -0.48881639f , -0.26079169f , 0.28649904f , 0.47374236f , -0.92331796f , 0.56274886f , 0.19988114f , -0.33923171f , 0.45935192f , 0.66439754f , 0.09172813f , -0.58992377f , -0.13650098f , -0.00871775f , 0.05177348f , 0.29646543f , 0.22271673f , 0.29255650f , 0.32416359f , 0.37254208f , + 0.69873728f , 0.67827523f , -0.09873129f , -0.19519793f , -0.20388503f , -1.14639862f , 1.00268628f , -0.34199196f , 0.32858454f , 0.30752466f , -0.20180165f , -0.78353972f , -0.46150042f , 0.07066704f , 0.27017563f , 0.59315620f , 0.56514267f , 0.61730776f , -0.04109619f , -0.10375384f , 0.17107510f , 0.00671267f , -0.14460000f , -0.15704504f , + -1.08061540f , 0.25499966f , 1.21906248f , 0.18773257f , -0.32071123f , 0.34341071f , -0.31815992f , -0.09070897f , 0.28772196f , -0.36343715f , -0.43262838f , -0.03519430f , -0.08578842f , 0.04235681f , 0.22568464f , 0.41761967f , 0.33042161f , -0.16644760f , -0.20508813f , -0.34930117f , -0.25591130f , -0.03775689f , -0.04290093f , -0.14027967f , + 0.08954841f , 0.28400971f , 0.09640325f , 0.28015051f , -0.28901197f , -0.15938324f , -0.08647304f , 0.07096579f , -0.01533652f , 0.16784761f , 0.40365967f , 0.69056044f , -0.07072517f , -1.35839862f , 0.69003689f , 0.27081222f , -0.31318076f , -0.34628327f , -0.20433566f , -0.03988210f , 0.00227372f , 0.31880868f , 0.48586232f , 0.50530210f , + -0.10787652f , -0.54593003f , -0.06872456f , 0.08196332f , 0.32589906f , 0.59080671f , -0.46869291f , 0.51602298f , -0.65588957f , -1.15841782f , 0.46249030f , 0.28794341f , 0.03773606f , -0.22824300f , 0.08237000f , 0.11514488f , 0.09347876f , 0.31037616f , 0.25764090f , 0.16707290f , -0.00830484f , -0.01436382f , 0.04324129f , 0.08340130f , + 0.03635043f , 0.84751295f , 0.19029027f , 0.81160060f , 0.30403111f , -0.74745208f , 0.29141206f , 0.02554821f , -0.18681161f , -0.31641374f , -0.22117775f , 0.29307885f , 0.09884843f , -0.01001690f , 0.22991570f , 0.23960184f , -0.00030044f , -0.15515938f , -0.08622738f , 0.18116527f , 0.27032171f , 0.46691225f , 0.50791118f , 0.39209784f , + -0.58545217f , 0.80964945f , -0.18596625f , 0.05021434f , -0.60299753f , 0.01922541f , -0.09160450f , 0.71858494f , -0.20405914f , 0.12967029f , -0.19928245f , -0.41958358f , -0.73480796f , 0.27037925f , 0.59526072f , 0.43722623f , 0.08228142f , 0.13617314f , 0.16733195f , -0.17519530f , -0.15926519f , -0.04255070f , 0.08047599f , 0.02040241f , + -0.00463376f , 0.49611447f , -1.05764249f , -0.45817246f , 0.34650208f , -0.41315007f , 0.05117591f , -0.11590274f , 0.37210637f , 0.48788495f , 0.24580028f , -0.23874213f , 0.25067272f , 0.14486146f , -0.39195005f , -0.32974271f , -0.40998318f , -0.01004687f , 0.30386464f , 0.58853426f , 0.58687081f , 0.54124172f , 0.43891894f , 0.42482843f , + 0.06344340f , -0.06291464f , 0.30075410f , -0.01321988f , 0.11824609f , -0.36844623f , -0.22861175f , 0.44459133f , -0.10414380f , -0.41394982f , -0.26948513f , 0.10771022f , 2.01283344f , -0.48227800f , -0.85226571f , -0.05678206f , 0.09386327f , -0.32036269f , -0.09589284f , 0.11469854f , -0.02254415f , 0.26286370f , 0.24740398f , 0.30259810f , + 0.33675212f , 0.40803791f , 0.04656053f , 0.26235019f , 0.19124535f , 0.26174937f , -0.25007840f , -0.02874094f , 0.42657886f , 0.23713035f , 0.49137649f , -0.40631813f , -0.19729730f , -0.47353514f , -0.68684985f , -0.22225676f , 0.65537217f , 0.85454345f , 0.28736774f , -0.76858865f , -0.51993839f , -0.41223097f , -0.20210503f , 0.20680273f , + -0.32962876f , 0.99852252f , 0.90359799f , -0.72414673f , 0.40343042f , -0.04753735f , 0.12703283f , -0.50454354f , -0.49092182f , 0.07106628f , 0.04340118f , -0.20701432f , -0.00051299f , 0.41281149f , 0.48992497f , -0.07229812f , -0.22500199f , -0.38166508f , 0.00136486f , 0.19527238f , 0.46266022f , 0.52478433f , 0.49346943f , 0.55712590f , + 0.31231089f , -0.39507041f , 0.09233836f , 0.29644040f , 0.63936696f , -0.05632462f , 0.45315617f , -0.80271529f , 0.87935975f , -0.65177909f , -0.03975780f , 0.24344094f , 0.09139584f , -0.12641456f , -0.28974809f , -0.00440121f , -0.33446897f , 0.27455940f , 0.26598867f , 0.38959619f , 0.56355605f , 0.28858433f , -0.01329721f , -0.28521977f , + 1.21529134f , 0.05567950f , 0.26633834f , 0.01854368f , -0.56750884f , -0.64133765f , 0.12896192f , -0.25287368f , 0.00098562f , 0.46355571f , 0.30342317f , 0.60024559f , 0.45154622f , -0.23111479f , -0.07558175f , 0.04573468f , -0.22655397f , -0.38765071f , -0.39593191f , -0.33701184f , -0.03367326f , -0.00117395f , -0.08805175f , -0.08317989f , + 0.50206060f , -0.26397493f , 0.62403702f , 0.18840209f , -0.03554397f , 0.51126843f , -0.93620939f , 0.11466485f , -0.32354822f , 0.83573095f , 0.44043951f , -0.03326486f , -0.30990227f , -0.17807718f , -0.15678795f , 0.05137581f , 0.01928613f , 0.10898749f , 0.05153834f , 0.41224367f , 0.33750201f , 0.31515600f , 0.18742162f , -0.00543668f , + -0.32506550f , 1.39874024f , 1.05365357f , 0.20758975f , -0.52204159f , 0.23139865f , 0.89916776f , 0.88500307f , 0.58319149f , 0.64447478f , 0.60029914f , -0.39017287f , -0.48396982f , -0.45642499f , -0.41136891f , -0.85726305f , -0.72300890f , -0.76044173f , -0.54961686f , 0.13241207f , -0.38074475f , -0.31668368f , 0.18757575f , 0.89325609f , + 0.91423867f , 0.16949588f , -0.34930052f , -0.67767124f , 0.56381557f , 0.23625492f , 0.19384698f , 0.11556592f , -0.81768557f , -0.12373743f , 0.28726562f , 0.47434410f , 0.01976064f , -0.20909300f , -0.17968366f , -0.16456765f , -0.39581902f , -0.17030977f , -0.12522965f , 0.10547945f , 0.19050607f , 0.32547806f , 0.37610928f , 0.47194674f , + 0.50904911f , -0.87540838f , 0.44606989f , 0.16315214f , 0.04897779f , 0.44593548f , 0.58835263f , 0.23188759f , -0.04829018f , -0.47929534f , 0.01140653f , -0.52090906f , -0.08282465f , -0.47750687f , 0.00555375f , -0.02147925f , 0.29824067f , -0.09639830f , 0.04586002f , 0.81704610f , 1.02414420f , 1.00254358f , 0.93128379f , 0.86145793f , + 1.39640260f , 0.48600888f , 0.05812317f , 0.43032939f , 0.28626623f , -0.02572580f , -0.71026460f , -0.08052560f , -0.00321850f , -0.06166357f , -0.14918683f , 0.02044791f , 0.20449299f , -0.07389050f , 0.20856068f , 0.37499893f , 0.00961555f , 0.34856300f , 0.38826685f , 0.17380148f , 0.08518823f , 0.24834931f , 0.18030421f , 0.02885498f , + -0.14822571f , 0.59831391f , 0.80084782f , 0.65079236f , -0.37659866f , 0.02590007f , -0.43987457f , -0.47916614f , -0.09009334f , 0.00944784f , 0.38989625f , 0.72812391f , -0.25740561f , 0.30660597f , -0.10786678f , -0.04283082f , 0.33341247f , 0.56382527f , 0.36883485f , 0.19482792f , 0.20864518f , 0.30357803f , 0.21469035f , -0.00709814f , + -0.55721230f , -0.02926194f , 0.02222842f , 0.65955295f , 0.85507986f , 0.02606033f , -0.38236616f , 0.08681374f , -0.37079998f , 0.08312060f , -0.32595363f , -0.28424983f , 0.08744855f , 0.15171748f , -0.41262446f , 0.16415023f , 0.32175904f , 0.54372269f , 1.03276331f , 0.88586548f , 0.61435324f , 0.53755072f , 0.50108183f , 0.43471867f +}; + +const float cdk_37bits_5[1536] = +{ + -0.08458486f , 0.28094300f , -0.74427850f , -0.27121451f , 0.26225532f , 0.58828870f , 0.49469996f , 0.00671892f , 0.49956583f , -0.09194914f , -0.14439356f , -0.21589493f , -0.71932281f , -0.31712426f , -0.17322443f , -0.02668573f , -0.16316907f , -0.26011802f , -0.29961334f , -0.04510044f , -0.03045680f , -0.07408609f , -0.04966348f , 0.02019735f , + 0.16785217f , -0.12154415f , -0.11294764f , -0.50188502f , 0.37048745f , 0.01220048f , -0.42438767f , -0.39739743f , -0.09963068f , -0.01937236f , -0.38029066f , -0.09631205f , 0.17779303f , 0.55220057f , -0.27361767f , -0.01993755f , 0.59841836f , -0.81488799f , -0.50629196f , 0.04276219f , 0.50927647f , 0.32204460f , -0.05252335f , 0.00479347f , + -0.70183618f , -0.55990950f , -0.21828823f , 0.06948525f , -0.25175959f , 0.38514843f , 0.03565709f , -0.02286728f , -0.65965565f , -0.11708316f , 0.08641334f , -0.03958833f , -0.28740740f , 0.11907652f , 0.76730012f , 0.00002225f , -0.01526722f , 0.19057067f , -0.00116506f , -0.29043894f , -0.20613074f , -0.36670968f , -0.38149597f , -0.21397652f , + -0.20108924f , 0.01696758f , -0.63540490f , 0.48931316f , -0.10610658f , -0.30699680f , 0.42198382f , -0.11596909f , 0.56113924f , -0.19428230f , -0.31623064f , 0.01575740f , 0.47412599f , 0.01231773f , 0.03554178f , 0.04445166f , -0.52597131f , -0.38112781f , -0.41082892f , 0.02325108f , -0.03762488f , -0.10886600f , -0.30284977f , -0.25935547f , + -0.06153986f , -0.50865639f , 0.00873904f , -0.53985972f , -0.17321488f , -0.20024719f , -0.43903590f , 0.30867295f , 0.15257025f , 0.50412756f , 0.15585453f , 0.18716871f , 0.04465249f , 0.05395055f , 0.02286270f , -0.10569980f , -0.51109990f , -0.62598156f , -0.29411790f , -0.40475676f , -0.34305943f , -0.21692205f , -0.39934499f , -0.51704391f , + -0.73658870f , -0.68665226f , -0.06126038f , 0.66114991f , 0.35329723f , -0.17434640f , -0.20490335f , 0.00027985f , 0.04182559f , -0.12920453f , 0.35128407f , 0.36339554f , 0.47399902f , -0.25062146f , -0.38289190f , -0.23332452f , -0.20826575f , -0.16079639f , -0.14129191f , 0.18519827f , 0.08984042f , 0.01018800f , -0.07526643f , 0.16613248f , + 0.24459641f , -0.54593305f , -0.17413054f , 0.01221675f , -0.28335532f , -0.03597407f , -0.12785960f , -0.20546625f , 0.69946433f , 0.14655906f , -0.07567982f , -0.41903852f , -0.05404835f , -0.57786831f , 0.75099347f , 0.04385018f , 0.13817541f , 0.54561726f , 0.22589567f , 0.09746529f , 0.26583628f , 0.26558035f , 0.21082406f , 0.14352723f , + -0.61059536f , 0.25826720f , 0.08276875f , -0.29062272f , -0.22379136f , 0.27302107f , -0.39399985f , -0.90988239f , 0.68577814f , -0.07398823f , 0.29343711f , -0.02555969f , 0.17350828f , 0.10446548f , 0.05915310f , -0.12814425f , 0.16515519f , 0.23084429f , -0.07631257f , -0.12135962f , -0.32154020f , -0.35925975f , -0.31657161f , -0.17517095f , + -0.31345423f , 0.04713846f , -1.07240463f , 0.55819357f , 0.25919851f , -0.17080554f , -0.44683706f , 0.42549491f , -0.24160926f , 0.39135254f , -0.27273104f , -0.08747624f , -0.17073595f , -0.64858648f , 0.31353107f , 0.40731596f , 0.24294678f , -0.16681178f , 0.01469568f , -0.30776696f , -0.15317629f , -0.18218388f , -0.16911268f , -0.19813229f , + 0.25482069f , -0.02943669f , -0.39498625f , -0.32329009f , 0.10426426f , -0.22095104f , 0.29062234f , -0.15434571f , -0.12708599f , -0.10669553f , 0.33786459f , -0.20904693f , 0.49652844f , -0.62850056f , 0.21568910f , -0.21446226f , 0.21630725f , -0.08720906f , -0.52065307f , -0.35255320f , -0.59625366f , -0.43541450f , -0.28092364f , -0.00125747f , + 0.31917512f , -0.03488145f , -0.21380884f , -0.22835427f , -0.66217994f , -0.29555406f , 0.17821074f , -0.34530315f , -0.20166763f , -0.01021963f , 0.39444938f , -0.06786073f , -0.22698498f , 0.34432475f , 0.51326058f , 0.57986123f , -0.20027416f , -0.13834155f , -0.20880162f , 0.06494356f , -0.27871271f , -0.15747416f , -0.07939462f , 0.08519511f , + -0.57600983f , 0.33019806f , 0.38068317f , 0.13486793f , 0.61770011f , -0.42574210f , -0.17565397f , 0.32588004f , -0.07069465f , -0.12991907f , 0.10503579f , -0.53981949f , 0.27628270f , -0.40433813f , 0.56048034f , -0.11134494f , -0.02721288f , -0.02679116f , -0.03457161f , 0.00691900f , 0.35272657f , 0.02987130f , -0.37220393f , -0.73576355f , + -0.31901782f , -0.23550305f , 0.50511762f , 0.07681936f , -0.20832096f , -0.16180683f , 0.33639474f , 0.24607809f , 0.51978014f , -0.51511613f , 0.53433180f , -0.38461866f , -0.30344206f , 0.21738925f , 0.23262923f , -0.26642016f , -0.24689764f , -0.35119228f , -0.37163953f , -0.19926461f , -0.12294480f , -0.07264335f , -0.14869303f , 0.01600622f , + -0.32318991f , -0.06337691f , -0.16327790f , 0.01679607f , 0.54615398f , -0.13948782f , -0.07235812f , -0.31344026f , 0.21344099f , -0.56249237f , -0.54817142f , -0.38900153f , 0.08560375f , 0.51752999f , 0.09695531f , 0.45163870f , 0.11365917f , -0.03998578f , -0.10961891f , -0.25154202f , -0.53037031f , -0.51729631f , -0.12010728f , 0.27211617f , + -0.21869866f , -0.20612331f , -0.17148894f , -0.69131811f , -0.48874096f , 0.17532938f , 0.65606235f , 0.17337859f , 0.21369284f , -0.02261284f , -0.23113547f , -0.37691677f , 0.06425787f , 0.33138072f , -0.19000900f , -0.50235478f , 0.19744901f , -0.01426938f , 0.25673560f , 0.14800389f , 0.08629656f , -0.05995416f , -0.01856833f , 0.09638624f , + -0.68051548f , 0.42111210f , 0.16966116f , -0.18012337f , -0.66642379f , 0.11078652f , 0.51684818f , 0.04482584f , -0.37389220f , 0.07070225f , -0.22594402f , -0.24882296f , 0.28791258f , 0.16045673f , 0.13211217f , 0.30258098f , -0.11104291f , -0.34144481f , -0.61517912f , -0.45406688f , 0.24175899f , 0.43530490f , 0.33387051f , 0.31684453f , + -0.12348130f , 0.28844356f , -0.15230272f , -0.92611369f , 0.15595514f , 0.40309213f , -0.21089949f , -0.12710732f , -0.20149432f , 0.08709137f , 0.79880608f , 0.16826794f , -0.10477000f , -0.40397699f , -0.33124317f , -0.16915306f , -0.06502590f , 0.05657812f , 0.16028923f , 0.14994150f , 0.07722317f , 0.24695981f , 0.20225272f , 0.10946385f , + -0.31130776f , 0.09164996f , -0.10763487f , 0.00805002f , -0.37620293f , 0.04961005f , 0.18879671f , 0.12802431f , -0.14881133f , 0.00106507f , 0.20381895f , -0.01208542f , -0.02377667f , 0.48285147f , -1.19207093f , 0.60998154f , 0.08913394f , 0.16312199f , -0.15986004f , -0.18489974f , -0.26700574f , -0.10480556f , -0.03699614f , 0.39930124f , + -0.45078318f , -0.11456599f , -0.27898753f , -0.42503588f , 0.17516712f , -0.19617643f , 0.31818611f , -0.08178737f , -0.05417727f , -0.23405407f , -0.39611520f , 0.32937074f , -0.20757027f , -0.46769544f , 0.04745269f , 0.30856677f , 0.45826247f , 0.41349579f , 0.21491292f , 0.22174480f , 0.16553832f , 0.28625395f , 0.24514041f , 0.37926658f , + 0.24936771f , -0.04104704f , 0.27238824f , 0.16392268f , -0.06110497f , -0.02187308f , -0.14403711f , 0.49428075f , 0.66634565f , 0.04308588f , 0.20773125f , -0.07283823f , -0.03584369f , -0.15180729f , -0.21954145f , -0.16147124f , -0.54353183f , 0.31850719f , 0.70992696f , 0.77482366f , -0.73614329f , -0.70442321f , -0.77208369f , -0.52036749f , + -0.40407749f , -0.55580682f , 0.40834797f , 0.13313598f , 0.11194755f , -0.02575282f , 0.56373574f , -0.17680698f , -0.31347570f , 0.88388781f , -0.66229966f , 0.14478038f , -0.15586756f , -0.36242692f , -0.35125580f , -0.05976233f , 0.40268536f , -0.01780960f , -0.30415813f , -0.40711933f , -0.20657081f , -0.11416314f , -0.11392091f , 0.03499209f , + -0.02442649f , 0.00289107f , -0.42318484f , -0.77861141f , -0.21018343f , -0.02530250f , -0.05457845f , 0.29013785f , 0.27545606f , -0.54534532f , -0.28075430f , 0.48908889f , 0.44803264f , -0.23493075f , 0.30537914f , -0.17571639f , -0.28136367f , 0.41087545f , 0.06067306f , -0.07891926f , 0.13675464f , -0.23523981f , -0.64950230f , -0.84513939f , + 0.33320458f , -0.21239429f , 0.16584185f , 0.20947136f , -0.84373112f , -0.18662477f , -0.39277353f , 0.27160507f , 0.33045634f , -0.07972757f , 0.26989965f , -0.31828606f , 0.29166908f , 0.02792893f , -0.23589507f , 0.24680072f , 0.61805079f , 0.29297283f , -0.46279502f , -0.38853021f , -0.06845241f , 0.13809046f , 0.18584514f , 0.19851158f , + -0.01509547f , -0.42006585f , -0.02742765f , 0.01387587f , 0.04496372f , 0.33032099f , -1.33568146f , 0.04497330f , -0.13953978f , 0.17866902f , -0.22504135f , 0.03714148f , 0.42265213f , 0.48557283f , 0.09517080f , 0.08189501f , -0.02136855f , 0.18181835f , 0.26310442f , 0.14522422f , -0.00551997f , -0.08059227f , -0.01368360f , 0.19964321f , + 0.06879672f , -0.16572126f , -0.21275410f , -0.00047311f , 0.38956134f , 0.68791295f , 0.06981244f , 0.44725155f , -0.37536280f , -0.07016804f , -0.31450647f , -0.12757190f , 0.15884699f , -0.28116715f , -0.24072947f , 0.06964482f , -0.41365933f , -0.30556059f , 0.01412066f , 0.09088293f , -0.05730716f , 0.11902320f , 0.49328583f , 0.76218521f , + 0.14607820f , 0.36882839f , 0.31158718f , -0.18015097f , 0.37885733f , 0.09807226f , -0.69643398f , 0.00209062f , 0.07841871f , -0.15108867f , -0.16550965f , 0.49051298f , -0.13918703f , -0.16017141f , 0.15622856f , 0.32246753f , -0.21434589f , -0.12839098f , -0.62492818f , -0.41789280f , -0.33687252f , 0.15910414f , 0.40538907f , 0.45768888f , + -0.18246786f , 0.69660292f , -0.53239726f , -0.39785530f , 0.09269434f , -0.20090783f , 0.24169380f , 0.14920210f , -0.20929912f , 0.37639575f , -0.02298151f , 0.29037766f , -0.30134500f , 0.12924066f , 0.34148084f , -0.65422266f , -0.23263549f , 0.15293804f , -0.12172724f , -0.29655807f , -0.15215394f , -0.01750734f , -0.02878360f , 0.05063806f , + -0.26703187f , -0.12751254f , -0.03617813f , 0.00622364f , 0.22547815f , -0.57779029f , -0.13343456f , 1.59832374f , -0.86975741f , -0.37492672f , -0.39567028f , 0.18249899f , 0.04481957f , 0.29481366f , 0.13046647f , -0.10097157f , -0.02397564f , 0.04106330f , -0.32215387f , -0.06647077f , -0.19483820f , -0.47627356f , -0.28788121f , -0.35042823f , + 0.02227780f , -0.19386416f , -0.30157912f , 0.12610552f , 0.56722223f , -0.09994132f , -0.02285657f , -0.61753835f , 0.08410488f , 0.73128591f , 0.37298647f , -0.77570729f , -0.22843919f , 0.11891633f , -0.03551507f , -0.10041180f , 0.00489754f , -0.03082396f , -0.09347646f , -0.15507942f , -0.14360267f , -0.08927711f , -0.16377833f , -0.01469311f , + 0.56852461f , 0.23796399f , 0.13182028f , -0.25577917f , -0.33910792f , 0.34056262f , -0.02495276f , -0.05880465f , 0.05430314f , -0.53287936f , -0.34110034f , 0.15113928f , 0.54187888f , -0.26468157f , -0.01685372f , 0.57037827f , -0.07951393f , -0.27830922f , -0.20152098f , -0.00077798f , -0.04509011f , -0.12945183f , -0.22631022f , -0.11626274f , + -0.25019709f , 0.07915240f , 0.19342024f , 0.04977732f , -0.10307638f , -0.04911927f , 0.08460541f , 0.35299883f , 0.10558745f , 0.32964006f , 0.16392423f , -0.03030527f , -0.17918726f , -0.50040107f , 0.40349289f , -0.25886676f , -0.31911232f , -0.10072948f , 0.17941945f , 0.11358761f , -0.65821799f , -0.13049456f , 2.00511443f , -1.24662935f , + -0.25357033f , -0.52592150f , 0.49923249f , -0.16543271f , -0.00633755f , -0.23552079f , -0.33411617f , -0.24207035f , -0.05030731f , -0.07071177f , -0.09419244f , 0.02464220f , -0.01943557f , -0.41801617f , 0.03064668f , 1.18121471f , 0.23528827f , -0.79209131f , -0.20405955f , 1.14624028f , 0.39747635f , 0.85849404f , -0.04127540f , -0.50865399f , + 0.42229826f , -0.01473649f , 0.33422709f , 0.02941697f , 0.19965112f , 0.72713450f , 0.30384642f , -0.11286505f , 0.14747407f , 0.14751665f , 0.11932647f , -0.00264711f , -0.31504995f , -0.56415263f , -0.31330112f , 0.01942224f , -0.35638639f , 0.03432383f , -0.11977819f , -0.30638549f , 0.34671321f , 0.83570186f , 0.17469280f , -1.01495899f , + -0.01251236f , -0.01487474f , -0.16676968f , 0.08574318f , 0.11892522f , 0.84392270f , 0.07864696f , -0.91941698f , -0.54281393f , -0.10333463f , -0.18582849f , -0.26050308f , 0.66395133f , 0.42733714f , -0.24646344f , -0.19052737f , 0.31638957f , 0.07897013f , 0.04027109f , -0.25458239f , 0.20940366f , 0.17480388f , 0.16462327f , 0.22726978f , + -0.02974486f , -0.54604962f , 0.16929759f , -0.25102018f , 0.23723617f , -0.34661947f , -0.07598653f , -0.25231308f , -0.73500058f , -0.06708141f , 0.18697737f , 0.14282300f , 0.66886685f , 0.39198866f , 0.20429507f , -0.16054968f , -0.19399421f , 0.25548963f , -0.01871442f , 0.24332515f , 0.11001194f , 0.17128458f , 0.05301268f , 0.13370518f , + 0.06218397f , -0.11075064f , -0.47179494f , 0.44241371f , 0.02355115f , -0.03595332f , 0.06122175f , -0.89128427f , 0.30088747f , -0.16859130f , 0.25866312f , 0.50627502f , -0.10794532f , -0.21779689f , 0.18817072f , 0.03690803f , 0.04519087f , 0.11081125f , -0.16063397f , -0.29465752f , 0.07392634f , 0.19278544f , 0.34698486f , 0.61990484f , + 0.93310946f , -0.16003930f , -0.20232301f , -0.09149716f , -0.07742202f , 0.10544444f , 0.21543944f , -0.23192273f , 0.37584518f , 0.41668097f , 0.03315939f , -0.08464584f , 0.23874101f , 0.46904518f , -0.37717436f , -0.46519362f , -0.61713348f , 0.00253734f , -0.05435577f , -0.08905407f , -0.16726849f , -0.06183335f , -0.05902828f , -0.03528791f , + 0.27678118f , -1.22172710f , 0.33045954f , 0.00746992f , 0.02805380f , 0.37593685f , 0.03388730f , -0.30662300f , 0.20852594f , -0.26058111f , -0.05686500f , 0.26594392f , 0.13317456f , -0.21898256f , -0.24070719f , -0.23323971f , 0.27086818f , 0.15492204f , 0.28738611f , -0.10515406f , -0.17282966f , -0.16200061f , -0.15211483f , -0.08975717f , + 0.59311421f , -0.26642352f , -0.18351175f , 0.27817437f , 0.89836102f , -0.16570591f , -0.42252147f , 0.18559697f , 0.28409112f , -0.18921990f , 0.26375529f , -0.31791665f , -0.33115116f , -0.01469640f , -0.21691511f , -0.04101336f , 0.06816547f , -0.25758291f , 0.10261781f , 0.06210271f , 0.13856623f , 0.09669133f , 0.13691740f , 0.19601167f , + -0.47155089f , 0.72985836f , 0.20031390f , 0.60596157f , 0.37698777f , 0.31374835f , -0.04335831f , -0.19781138f , -0.35092304f , -0.19434376f , 0.20558302f , 0.09649664f , -0.41125462f , -0.31417023f , 0.14557422f , 0.13059497f , 0.24351408f , 0.45606066f , 0.19630429f , 0.04599059f , -0.10842569f , -0.01246157f , 0.09745947f , 0.19255215f , + -0.00592573f , 0.30808529f , -0.82755020f , 0.27196540f , -0.04397044f , 0.35031490f , -0.46245949f , 0.43218639f , 0.08949413f , -0.33531101f , 0.30153585f , -0.06912019f , 0.05157704f , 0.21559056f , -0.09478249f , -0.29283107f , -0.14210772f , 0.16107997f , -0.05714190f , -0.07436813f , -0.17587718f , -0.17911354f , -0.01118712f , 0.30263406f , + 0.59479190f , 0.43737796f , -0.53906079f , -0.09284007f , 0.11222222f , -0.70909913f , -0.32143749f , -0.10079180f , -0.20953687f , -0.04742476f , 0.16795483f , 0.54332818f , 0.27138756f , -0.04876020f , -0.15045069f , 0.12165485f , 0.37118663f , 0.28905161f , 0.48206821f , 0.04496926f , -0.32548961f , -0.26704421f , -0.14151166f , 0.04643725f , + 0.01857789f , 0.22380572f , -0.47831518f , 0.10523282f , -0.02303693f , 0.06579947f , 0.64486948f , -0.30766532f , -0.74577310f , -0.77953682f , 0.57447145f , 0.39403713f , -0.58964771f , 0.62821123f , -0.11929129f , 0.10954929f , 0.14699721f , -0.32854065f , -0.04573394f , -0.09611846f , -0.01925603f , -0.17973013f , -0.39814740f , -0.46576115f , + 0.35954529f , 0.21214434f , 0.29992890f , -0.43470418f , 0.22297513f , -0.74780053f , 0.29579016f , 0.38031695f , 0.70929833f , 0.17791374f , -0.31068973f , 0.03106903f , 0.02159010f , -0.32680013f , -0.05137091f , -0.35753644f , -0.04484695f , -0.12900523f , -0.08431778f , -0.06684064f , -0.13653506f , 0.11526736f , 0.41857603f , 0.60634687f , + -0.39857847f , 0.04884917f , 0.23406115f , 0.05538860f , 0.28382844f , -0.00189639f , 0.13911105f , 0.08498889f , 0.38084943f , -0.04839120f , 0.03137059f , 0.61768252f , -0.60458777f , 0.17599675f , -0.38910593f , -0.29574408f , -0.37344875f , -0.20375998f , -0.20238216f , 0.44496885f , 0.52761883f , 0.49054914f , 0.28209688f , 0.15957444f , + -0.09304443f , -0.24829008f , 0.01258115f , 0.25256399f , -0.33883889f , -0.24896392f , -0.05437653f , 0.19084219f , 0.57863216f , 0.39405103f , -0.77089337f , 0.12169591f , -0.54527825f , 0.19831126f , 0.08552984f , 0.24274638f , 0.14652491f , -0.01698693f , 0.17500050f , -0.05044189f , -0.10649361f , -0.14945507f , -0.17028214f , -0.02330724f , + 0.03708941f , -0.24037606f , 0.02610502f , 0.50618133f , 0.10793551f , -0.09837616f , 0.62190481f , 0.34616106f , -0.28267161f , -0.14290071f , 0.01530348f , -0.83226343f , 0.23366780f , 0.04347097f , -0.00300625f , -0.02718166f , 0.01892830f , 0.11549693f , 0.36192046f , 0.50541829f , 0.06636938f , -0.09251533f , -0.22221864f , -0.12965501f , + -0.47277684f , 0.24188752f , 0.24883904f , -0.02549111f , -0.17021090f , 0.26120838f , -0.17437786f , -0.12898937f , -0.09122841f , 0.58977574f , 0.11843505f , -0.68052107f , 0.69093722f , -0.45942130f , -0.33210729f , 0.59582125f , -0.21973689f , 0.45672258f , 0.17061853f , 0.09529478f , -0.14791095f , 0.22877969f , 0.23364199f , 0.17934426f , + 0.16186852f , 0.95532223f , 0.24207322f , -0.28038649f , -0.16606584f , 0.28705368f , -0.00385633f , 0.10024520f , 0.38606721f , 0.00630603f , -0.08918537f , -0.48762895f , -0.25520072f , -0.07233131f , -0.06791555f , 0.02988899f , 0.33242516f , 0.31840295f , 0.31437593f , 0.28920587f , 0.20710554f , 0.12154078f , 0.09165915f , 0.13540520f , + -0.13814042f , 0.76333362f , 0.47866377f , 0.69056795f , 0.37920652f , -0.08336837f , 0.11207624f , 0.09821375f , 0.10128568f , 0.04094478f , -0.15253392f , -0.11078606f , 0.25057753f , 0.22663675f , -0.61364190f , -0.15546409f , -0.09300050f , -0.16430823f , -0.19195716f , -0.31084762f , -0.10423817f , -0.12525492f , -0.23057864f , -0.28477374f , + 0.19153891f , -0.50596450f , -0.06105779f , 0.12200239f , -0.10106136f , -0.25277965f , 0.30874573f , 0.40660354f , -0.20056468f , 0.17407976f , 0.60265008f , -0.00174689f , -0.44985204f , -0.31371702f , -0.45581285f , 0.36180230f , -0.07689721f , 0.80922589f , 0.34920387f , -0.21634606f , 0.06852205f , 0.36029737f , 0.53860772f , 0.69593094f , + 0.15218961f , 0.07083646f , 0.38471465f , 0.14311856f , 0.51050633f , 0.02631960f , 0.07150340f , -0.05204054f , 0.01036712f , 0.03753337f , 0.12604818f , 0.04316599f , -0.04454527f , 0.25901986f , 0.20620898f , -0.25183978f , -0.94415183f , -0.48608996f , 1.99323108f , -0.11741995f , 0.09381593f , 0.24836984f , -0.11990959f , 0.40198786f , + 0.35937586f , 0.05698778f , 0.55993579f , -0.68942177f , -0.00843969f , 0.47116294f , -0.17925245f , -0.41881521f , -0.20778331f , 0.27187634f , -0.19950871f , 0.56109975f , -0.73314410f , 0.36645381f , 0.13542026f , -0.12859018f , 0.07003305f , 0.17282595f , 0.33447531f , 0.32716011f , -0.39068553f , -0.25495327f , -0.44464316f , -0.44631278f , + -0.24788508f , 0.44993219f , 0.49633852f , 0.14573879f , -0.82145522f , 0.08447045f , 0.24653278f , 0.20233825f , -0.08079227f , -0.31036126f , 0.09619263f , 0.78127448f , 0.27956930f , -0.05376367f , -0.24537081f , -0.24071734f , 0.06264366f , -0.00648643f , 0.14649115f , 0.22075554f , 0.00215430f , -0.16835304f , -0.14400020f , 0.05455559f , + 0.51475177f , -0.19511684f , -0.41661102f , 0.02887458f , -0.64696667f , 0.12493084f , 0.01019607f , 0.19888837f , -0.37880058f , 0.64135459f , 0.11055137f , 0.09557428f , -0.07711050f , 0.13238949f , -0.18005007f , -0.18262300f , 0.15084340f , -0.21503629f , 0.15653282f , 0.45708075f , 0.39918436f , 0.40428185f , 0.37849166f , 0.37443886f , + -0.37551659f , 0.34117536f , 0.04118741f , -0.11257164f , -0.12653529f , -0.87344655f , -0.56010800f , -0.07645484f , 0.14471437f , 0.20262780f , 0.29380185f , -0.02943048f , 0.10854716f , 0.43270966f , 0.25877519f , 0.11175582f , 0.11265276f , 0.12112616f , 0.32109879f , 0.25352173f , 0.28658481f , 0.29681278f , 0.39509407f , 0.43777195f , + 0.17504785f , 0.10160864f , -0.32996848f , 0.33545472f , 0.10088654f , 0.32002010f , -0.06513018f , 0.09378440f , 0.30444515f , 0.06564463f , -0.59311997f , 0.13934191f , 0.17049039f , -0.38526222f , -0.13285144f , -0.34127257f , 0.32308732f , 0.29646451f , -0.08667292f , 1.27873237f , 1.21492697f , -3.11928954f , 0.45762280f , -0.93594879f , + 0.17132808f , 0.08085753f , 0.26151050f , 1.03721715f , -0.25337638f , 0.26779752f , -0.61935064f , 0.10496638f , -0.18282397f , 0.00232460f , 0.17820442f , 0.20638928f , 0.07611441f , 0.12056159f , 0.20529210f , -0.06270324f , -0.04360808f , -0.42305491f , -0.41339045f , -0.00383610f , -0.19449359f , -0.25682704f , -0.37569311f , -0.21433847f , + 0.64365986f , 0.31456070f , -0.39495602f , -0.24863426f , 0.09837217f , -0.36609886f , 0.17111936f , 0.24419541f , -0.24359150f , -0.27882768f , -0.09002564f , -0.30691102f , -0.22673738f , 0.56321328f , 0.22388027f , 0.03208856f , 0.17981274f , 0.06991222f , -0.67356769f , -0.64900669f , 1.15113193f , 0.72776059f , 0.27327753f , 1.08582469f , + 0.41187807f , 0.20392498f , 1.09655483f , -0.34930742f , 0.20771295f , -0.06429869f , 0.08115226f , 0.22625148f , -0.72095719f , -0.02848530f , 0.42792136f , -0.04720602f , -0.22585980f , -0.29439740f , 0.06057192f , 0.13137013f , 0.24620234f , -0.13734663f , -0.12645317f , -0.30625075f , -0.14167838f , -0.11199965f , -0.18411244f , 0.12411211f , + 0.52310170f , 0.17749282f , 0.93116306f , 0.43734813f , -0.11189475f , -0.12583315f , -0.15636518f , -0.45970964f , 0.29811984f , 0.05623999f , 0.26734923f , -0.16388298f , -0.04470326f , 0.13948379f , 0.11499794f , 0.17243067f , 0.01441213f , -0.18039908f , -0.09565125f , 0.16544291f , 0.06548930f , 0.22771091f , 0.45780362f , 0.52809090f , + 0.28956302f , -0.16486587f , 0.29599013f , 0.32685118f , -0.28935868f , -0.00152686f , 0.55430159f , 0.03727197f , 0.10804969f , -0.54544071f , -0.79114628f , 0.10752299f , 0.05522333f , 0.63833259f , 0.49017560f , 0.02881627f , -0.39313059f , 0.50983607f , 0.34015996f , -0.08459223f , -0.28493761f , 0.10604944f , 0.27351683f , 0.32437791f , + -0.25283796f , -0.04532098f , 0.15075344f , 0.11408519f , 0.00916449f , -0.10310231f , 0.19258483f , 0.02635541f , -0.27218167f , 0.12402945f , 0.03511427f , 0.17636894f , -0.54939311f , 0.33454589f , -0.06691437f , -0.76895070f , 0.86149576f , -0.11074096f , 0.14506447f , -0.65269171f , 0.42690885f , 2.34010106f , -0.53713287f , -0.56076371f , + 0.34158378f , 0.24525259f , 0.18233515f , -0.01918052f , -0.38850956f , -0.10382009f , 0.23314099f , -0.44393411f , -0.22817265f , 0.43890661f , -0.35766222f , 0.12772962f , 0.29184572f , -0.35914868f , 0.41036163f , 0.13940763f , 0.24037289f , 0.31034789f , 0.39892172f , 0.45673361f , 0.25700279f , -0.23583305f , -0.56430632f , -0.63542661f +}; + +const float cdk_37bits_6[1536] = +{ + 0.02199370f , -0.29796617f , 0.05716792f , 0.13680255f , 0.26597120f , -0.02744179f , 0.20163618f , 0.55538992f , 0.22634719f , 0.31737301f , 0.16680373f , -0.09734626f , -0.23572572f , -0.44456075f , -0.32174953f , -0.27927807f , -0.32748565f , -0.18735586f , -0.18267408f , -0.46321102f , -0.04612331f , 0.01365363f , 0.19391054f , 0.39090135f , + -0.78693393f , -0.13121488f , -0.28380698f , -0.26404304f , -0.10486512f , 0.28404174f , -0.20661527f , -0.42204880f , -0.30458489f , 0.08583926f , 0.07085793f , 0.33480410f , -0.03611454f , 0.07957323f , -0.24515140f , -0.07119076f , 0.53589973f , -0.22960446f , 0.07406971f , -0.05459778f , -0.34032829f , -0.26754071f , 0.22258555f , 0.30461029f , + -0.40719188f , -0.52149744f , -0.06225098f , -0.58002850f , 0.18087742f , 0.16048132f , 0.33633101f , -0.27793274f , 0.29766130f , 0.23267788f , -0.40627837f , -0.11859464f , -0.33658426f , -0.08944806f , 0.07416164f , 0.12096620f , -0.17419709f , -0.33394555f , -0.01993099f , 0.18415306f , -0.00706952f , -0.18114484f , -0.17223192f , -0.00314600f , + 0.09136000f , 0.34482257f , -0.38038690f , 0.51845639f , 0.22194266f , -0.06195248f , 0.01057897f , -0.25864445f , -0.13813348f , 0.15711108f , 0.37305034f , -0.46508572f , 0.21910366f , 0.14590390f , -0.15011887f , -0.08081632f , 0.02686570f , -0.52447967f , -0.44642803f , -0.09356439f , 0.07841264f , -0.09014590f , -0.08406397f , -0.21549966f , + -0.10973105f , -0.34775792f , -0.20573880f , -0.13604716f , 0.02371719f , -0.25091561f , -0.39884717f , -0.11293660f , 0.35125293f , -0.23847405f , 0.75991690f , -0.00398242f , -0.37499879f , -0.16571879f , -0.17163070f , 0.28161005f , 0.30079809f , 0.08127173f , -0.21076595f , -0.41977393f , -0.20607863f , -0.13121646f , -0.05219850f , -0.20041567f , + -0.23929288f , 0.00328474f , -0.16404527f , 0.13343873f , -0.04468995f , -0.12674227f , 0.28141003f , 0.18544988f , 0.02601550f , -0.21845606f , -0.11057949f , -0.08909572f , -0.13195824f , -0.18487778f , 0.09887948f , 0.53205644f , -0.22134305f , -0.05746605f , -0.44707332f , -0.06333598f , -0.98347835f , 1.60965371f , -0.38440494f , 0.37345285f , + 0.18956874f , -0.63812607f , 0.04131005f , -0.45442314f , -0.54875750f , 0.04287724f , 0.25537551f , 0.08570099f , -0.08813623f , -0.09284444f , 0.03722275f , 0.36512077f , -0.09165936f , -0.03956157f , -0.01444716f , 0.03320064f , 0.05602971f , 0.12944547f , -0.08791108f , -0.21281390f , 0.02256362f , 0.21794416f , 0.49420878f , 0.51874581f , + -0.61939062f , -0.36501718f , 0.13770557f , -0.03873456f , 0.24524354f , -0.22114161f , 0.17262135f , -0.01018526f , 0.00734267f , -0.03028249f , -0.10222293f , -0.56027275f , 0.21981567f , 0.30177736f , -0.00599960f , -0.13637831f , 0.12005585f , 0.21762903f , 0.21013194f , -0.29453710f , 0.06570005f , 0.02671005f , 0.18952852f , 0.33755592f , + 0.14788881f , 0.00059595f , 0.03869057f , -0.08077903f , -0.12203289f , -0.84498958f , 0.47581358f , 0.02514588f , 0.04825696f , -0.01455508f , -0.01746364f , 0.27725910f , 0.12457264f , 0.11218197f , 0.26527797f , -0.25741487f , -0.07216861f , -0.32943112f , -0.08385290f , -0.36172079f , -0.42572896f , -0.53073631f , -0.32133031f , -0.11301412f , + -0.35066897f , -0.11415958f , -0.59117357f , -0.14095716f , -0.42297703f , -0.39599254f , 0.11101885f , 0.54908359f , 0.00983404f , -0.16570627f , 0.35167384f , 0.03659831f , 0.00451556f , 0.13297592f , -0.03455431f , 0.05151250f , -0.22783505f , -0.26878480f , -0.09719185f , 0.26294703f , 0.24726886f , 0.09052345f , -0.07129501f , -0.20450022f , + -0.04472087f , -0.37269265f , 0.03231240f , 0.03463392f , -0.33039098f , 0.03217782f , -0.35545027f , 0.13915732f , 0.21687252f , -0.70171718f , -0.39380045f , 0.29808315f , -0.10154988f , 0.58687688f , 0.36738223f , -0.01455050f , 0.25767865f , -0.13939968f , -0.18503719f , 0.06199296f , 0.11118295f , 0.01396018f , 0.09425776f , -0.03092734f , + -0.25728637f , 0.47463459f , 0.06581158f , -0.61445073f , 0.28805874f , 0.07087341f , 0.22849783f , 0.14652334f , -0.17916038f , -0.45793031f , -0.13375702f , 0.04741016f , 0.34305011f , 0.18609517f , 0.15796519f , -0.32119576f , -0.37724212f , -0.29019392f , -0.16584456f , 0.06247499f , -0.17973441f , -0.11871502f , 0.07256450f , 0.13822121f , + 0.20531600f , -0.09627213f , -0.35132620f , -0.03667359f , -0.25798228f , 0.21115819f , 0.03354110f , -0.02417022f , 0.43198429f , -0.23070254f , -0.12670631f , 0.15840355f , -0.09384404f , -0.11238464f , -0.08953585f , 0.10896049f , -0.00837215f , -0.46861227f , 1.49760729f , -0.67351773f , -0.52192511f , 0.01262532f , 0.20121502f , -0.39083539f , + 0.10656396f , -0.26831105f , -0.81601202f , 0.26397269f , 0.26863321f , -0.04846112f , 0.40399165f , -0.08820703f , 0.14718938f , -0.29278618f , -0.38479467f , 0.02420765f , -0.10191832f , -0.03998542f , 0.09718148f , -0.38999213f , 0.40517232f , 0.29658010f , 0.07025753f , -0.06541290f , -0.17956727f , -0.20362973f , -0.10716584f , -0.04799112f , + -0.08098934f , 0.01809647f , -0.31889640f , 0.20306658f , 0.05187569f , 0.03260165f , -0.28014725f , -0.09888837f , 0.24610335f , 0.17700122f , -0.30915327f , -0.08942879f , -0.50003116f , 0.85468538f , -0.27952271f , 0.40219755f , -0.20697633f , -0.22376407f , -0.24075343f , -0.23806655f , 0.09503069f , 0.19400941f , 0.29979874f , 0.26995405f , + -0.27054449f , 0.39277758f , -0.03760489f , 0.02099845f , -0.35791555f , -0.28760379f , 0.22223327f , -0.11251071f , -0.02563508f , 0.46326287f , -0.14502000f , -0.07375028f , -0.32793294f , -0.56372840f , 0.30213757f , 0.47683337f , 0.42993785f , 0.02200265f , -0.43110723f , -0.31763877f , 0.25984030f , 0.13257308f , 0.23346193f , -0.17362047f , + -0.12926955f , 0.23035254f , 0.14954128f , -0.15270953f , 0.01666258f , 0.25669412f , 0.26953793f , 0.47425752f , -0.09722404f , -0.12678088f , -0.27006791f , 0.06245438f , 0.11482178f , -0.51002017f , -0.55002144f , -0.13134853f , 0.49162370f , -0.20822342f , -0.09189974f , -0.03360844f , 0.08050459f , 0.08539808f , -0.01338071f , -0.32112911f , + -0.07384309f , 0.14700645f , -0.33549907f , -0.17107820f , -0.36567878f , 0.28540929f , -0.11645077f , -0.06093537f , 0.10704230f , 0.60475923f , 0.31110592f , 0.03294181f , 0.24602888f , -0.16878060f , -0.37308097f , -0.38852147f , -0.11457933f , -0.01155936f , -0.20566079f , -0.11646696f , -0.43156667f , -0.48332839f , -0.40869530f , -0.30176313f , + -0.04009388f , -0.48515311f , -0.01564117f , -0.22107208f , 0.26498770f , 0.32028506f , -0.06025879f , 0.53444487f , -0.52361462f , -0.13790355f , -0.00869928f , -0.37067541f , -0.00525305f , 0.34369466f , -0.11140079f , -0.21802883f , -0.02738621f , 0.09487138f , -0.18305111f , 0.21257672f , 0.19224339f , 0.13669179f , -0.07833677f , -0.43596981f , + -0.31269603f , 0.18817889f , -0.14017449f , -0.36643116f , 0.51493670f , -0.26894972f , 0.38067942f , -0.47165660f , -0.03935884f , -0.15393758f , 0.33966349f , -0.07858441f , 0.08218318f , -0.14083074f , -0.39968104f , 0.46984889f , -0.23459315f , -0.01561374f , 0.04443121f , -0.08906745f , -0.05813711f , -0.21827283f , -0.17460819f , -0.22917539f , + -0.32481184f , 0.18110865f , -0.03288883f , -0.13973233f , 0.27902282f , -0.11023560f , -0.16625632f , 0.02743534f , 0.10865317f , -0.10518495f , 0.26027757f , -0.15223339f , -0.35257469f , -0.01938217f , 0.46256528f , -0.27598628f , 0.04443960f , 1.07920395f , -1.13925232f , 0.36635637f , 0.35955458f , 0.25146378f , 0.11693719f , -0.28918251f , + -0.01140797f , -0.00108123f , 0.53664312f , -0.07884630f , 0.06610974f , 0.46994377f , -0.21062843f , -0.06753632f , -0.27422686f , -0.02290268f , -0.18794805f , -0.46650251f , -0.14397198f , -0.00227405f , 0.10488283f , 0.31441692f , 0.42101389f , 0.25235460f , -0.29244026f , -0.56175069f , -0.28002115f , -0.17549467f , -0.12071683f , -0.23331646f , + -0.14210038f , 0.15898131f , 0.34745032f , -0.39617165f , -0.04076848f , 0.18838182f , -0.13777208f , 0.22936475f , 0.41604669f , -0.29976263f , 0.25071099f , -0.15777986f , 0.01895400f , -0.00797168f , -0.55609191f , 0.33651175f , -0.23976909f , -0.55267202f , -0.20759468f , 0.05624592f , 0.01093081f , 0.08073438f , 0.28567820f , 0.30232551f , + 0.28315788f , -0.74308327f , 0.25294543f , 0.19940974f , 0.24760844f , -0.02307767f , 0.00394023f , -0.27240988f , -0.55346147f , 0.06135889f , -0.10476035f , 0.49139353f , 0.02862492f , 0.14164419f , -0.26209567f , 0.29521976f , -0.05334845f , -0.16688330f , -0.02634194f , -0.01985854f , -0.11432133f , -0.12121091f , -0.13386215f , -0.39429955f , + 0.01675275f , -0.07538106f , -0.33922440f , 0.34966904f , 0.15763570f , 0.08306612f , 0.62591343f , -0.03583112f , -0.43789635f , -0.06885643f , -0.00346875f , -0.06640113f , -0.32232724f , -0.18063079f , 0.53312831f , -0.00572204f , -0.27992509f , -0.50312951f , 0.12672777f , 0.16960075f , -0.11581876f , 0.02517662f , 0.13602646f , 0.24387275f , + -0.35732816f , -0.22019513f , -0.26829496f , 0.31166748f , -0.23832104f , 0.56149308f , 0.20096730f , -0.14980617f , 0.04728897f , -0.22598474f , -0.36740325f , 0.14028484f , 0.32691879f , 0.00451707f , -0.11546712f , 0.20652154f , -0.39073278f , 0.05148622f , -0.29347409f , -0.21830651f , 0.40790228f , -0.24466325f , -0.37143514f , -0.35725594f , + -0.34807000f , -0.00324691f , -0.06021802f , 0.27592230f , 0.20065100f , -0.31797201f , -0.48602388f , 0.05361142f , 0.30839620f , 0.41057671f , -0.47412603f , 0.10542789f , 0.20596832f , -0.20747184f , 0.40038595f , -0.20068089f , 0.00240007f , -0.38309980f , -0.05001577f , 0.17124043f , 0.09018175f , 0.07050526f , 0.22914929f , 0.15810766f , + 0.15361042f , 0.16095058f , 0.11590520f , -0.10531069f , -0.54075671f , 0.33490327f , 0.37034921f , -0.22227724f , -0.09516189f , -0.12944095f , 0.61220382f , -0.39342831f , 0.07187587f , 0.14034139f , 0.15782975f , 0.06333909f , -0.37017017f , 0.21683365f , 0.12401762f , -0.25136319f , -0.14144992f , -0.11683977f , 0.08998918f , 0.02907554f , + -0.75114647f , 0.03978493f , 0.76048864f , 0.09830364f , -0.18442047f , -0.01149302f , -0.08377934f , 0.01287934f , -0.10587886f , 0.02074821f , 0.24442453f , 0.25099252f , 0.04656507f , 0.10263959f , -0.00445999f , -0.09991211f , -0.18874159f , -0.04573901f , 0.12928997f , 0.08644625f , -0.19611160f , -0.27382974f , -0.29394396f , -0.47761274f , + 0.14765675f , 0.26358158f , -0.29464188f , 0.01676762f , -0.12098202f , 0.56991418f , -0.43628314f , 0.29279445f , -0.51684512f , -0.06979763f , 0.22084398f , 0.33328609f , -0.44667171f , -0.13234452f , 0.03221020f , 0.34402421f , -0.06995129f , -0.10237066f , -0.03757679f , 0.08387845f , 0.07625326f , -0.18566472f , -0.25481511f , -0.35690924f , + 0.36027465f , -0.14361307f , -0.01060078f , -0.14321892f , 0.47607774f , -0.21917094f , -0.19024330f , 0.35483351f , 0.00343023f , 0.16704908f , 0.09217343f , -0.36458287f , -0.68525894f , -0.06920128f , 0.13485445f , 0.16439202f , 0.13577501f , -0.06075085f , 0.02266803f , 0.26611340f , -0.37850955f , -0.49541492f , -0.48481104f , -0.30493937f , + 0.04767197f , 0.17098898f , -0.03724685f , -0.76939534f , -0.52710450f , -0.26151755f , -0.36749599f , 0.19673299f , 0.11499191f , 0.25563946f , -0.18105024f , -0.11440595f , 0.27962189f , 0.12349943f , 0.04827891f , 0.17421978f , 0.25830670f , 0.15467508f , 0.17983330f , 0.17053327f , 0.01501125f , -0.21006919f , -0.24807426f , -0.27314815f , + -0.24896720f , 0.19371740f , 0.06879568f , 0.44049451f , 0.14914746f , 0.03856987f , 0.06978715f , 0.40612007f , 0.28010982f , -0.56749281f , -0.01993429f , 0.46728351f , -0.36770014f , -0.15189625f , -0.02595528f , -0.16408195f , -0.11358236f , 0.34475368f , 0.37996789f , -0.23334622f , -0.02333946f , -0.29586512f , -0.08357343f , 0.01075083f , + 0.01442941f , -0.19995191f , -0.25851229f , -0.29267926f , 0.50501148f , 0.07809462f , -0.35000787f , 0.00232180f , 0.25576742f , 0.22026677f , -0.28505912f , 0.32678020f , 0.14230208f , -0.25462591f , -0.52430874f , 0.00733528f , -0.12371759f , 0.46221140f , 0.03726347f , 0.06724595f , 0.38257606f , 0.29300802f , 0.20146742f , 0.05769846f , + 0.46566196f , -0.22129182f , 0.48408131f , -0.08771705f , 0.34179928f , -0.03570483f , 0.28260230f , -0.37152490f , 0.24002550f , -0.37004615f , 0.04007914f , 0.14066291f , 0.03156739f , -0.40473859f , 0.24504260f , -0.12061618f , -0.01911784f , -0.09587775f , -0.20311630f , 0.25305578f , -0.02444684f , -0.17360130f , -0.33200194f , -0.56919023f , + 0.40911162f , -0.26402836f , -0.43905076f , -0.53557497f , 0.19016209f , -0.01532019f , -0.46281760f , -0.26868248f , 0.12319043f , -0.03526231f , 0.14611501f , -0.35525234f , 0.34301743f , 0.10756893f , 0.38690216f , 0.01304076f , -0.17233959f , -0.26353334f , -0.32623011f , -0.13634929f , 0.06881118f , -0.03647389f , 0.13860696f , 0.21618306f , + 0.58044419f , -0.31542590f , 0.13749045f , 0.15061296f , -0.24506767f , -0.10488291f , -0.37675292f , -0.04226534f , -0.16466027f , 0.20334112f , 0.62047117f , -0.07748292f , -0.23123208f , 0.22647883f , 0.46423202f , -0.53987978f , 0.26867801f , 0.17570387f , 0.22624788f , -0.06808559f , -0.09873793f , 0.00241821f , 0.05209155f , 0.02604012f , + -0.18720130f , -0.00619393f , 0.08934188f , 0.18479801f , 0.00631687f , 0.35401594f , -0.22430546f , -0.17052726f , -0.27404318f , 0.34842459f , 0.06523245f , -0.22607999f , 0.38438344f , 0.31775172f , 0.00274227f , -0.32430710f , -0.25886046f , -0.22780138f , 0.00599115f , 1.13173049f , -1.16090310f , 0.31502644f , 0.39054668f , -0.12545157f , + 0.08495448f , -0.08111156f , 0.13201128f , 0.10631004f , -0.62508184f , 0.49447676f , 0.05698153f , 0.57661737f , 0.16100334f , 0.29281953f , -0.42535641f , -0.34334011f , -0.21130696f , -0.11053404f , 0.29449021f , -0.00923741f , -0.15178458f , -0.03327836f , 0.04623104f , 0.06728107f , 0.07479295f , -0.09249471f , -0.01129765f , -0.02381652f , + 0.58733539f , 0.15083492f , -0.07170902f , 0.07265805f , 0.25686979f , -0.00362956f , 0.16478015f , 0.10189929f , -0.35758569f , 0.34626172f , -0.76537636f , -0.14748849f , 0.23675893f , 0.10373267f , 0.09933094f , -0.01851098f , -0.01787937f , -0.12160932f , -0.09891368f , -0.10410372f , 0.04554984f , 0.08997877f , 0.12949773f , 0.02665334f , + 0.29472382f , 0.55621057f , -0.25157141f , -0.08071915f , -0.33720618f , -0.07969815f , -0.09542065f , -0.03385662f , 0.57363003f , 0.21066071f , -0.26291676f , 0.64510933f , -0.24141325f , -0.10243829f , -0.10243462f , 0.03275380f , -0.20748095f , -0.21739693f , -0.02629787f , 0.14996425f , -0.18327383f , 0.03844543f , -0.12298422f , -0.48155671f , + -0.03002892f , 0.10542293f , 0.06159204f , 0.27084880f , 0.33088023f , -0.39709374f , 0.40602594f , 0.01355505f , -0.21134955f , 0.38680071f , 0.42354405f , 0.13430508f , 0.04568189f , -0.43410657f , -0.13995521f , -0.32088491f , -0.23742271f , 0.13613850f , 0.22766366f , 0.52067443f , 0.36422193f , -0.09820343f , -0.25055881f , -0.32764668f , + -0.03031539f , 0.33911970f , 0.00121262f , 0.23395660f , 0.10188493f , 0.35700308f , -0.26121354f , 0.04562318f , 0.08861375f , -0.19333300f , -0.17460139f , -0.06438315f , 0.08512698f , -0.28212770f , 0.58969600f , -1.01876488f , 0.72771298f , -0.24186158f , -0.25474736f , -0.05188159f , 0.35800295f , -0.07855298f , -0.01848759f , 0.30122272f , + -0.16488121f , 0.39899154f , -0.43527753f , 0.06350178f , -0.25145471f , -0.13442742f , -0.05695327f , 0.05515276f , -0.53947634f , 0.10452757f , -0.00613783f , 0.09941644f , 0.48768605f , 0.23880974f , 0.15991320f , -0.08188036f , -0.07454521f , 0.46447496f , 0.20306282f , -0.35729603f , -0.19729891f , 1.15029004f , 0.78677730f , -0.96063281f , + 0.31021050f , -0.38542028f , 0.38342353f , 0.13604497f , -0.07567226f , -0.23168737f , -0.02250859f , -0.04684466f , 0.02122357f , 0.36396360f , -0.03570663f , -0.41257090f , 0.57597067f , 0.13936689f , -0.44959133f , -0.14512843f , 0.31888158f , -0.68434472f , 0.36855275f , 0.34229507f , 0.14749025f , -0.13593595f , -0.02198259f , 0.03092032f , + 0.04127156f , -0.30338390f , -0.36945017f , 0.09750128f , 0.03159281f , -0.09756566f , -0.00189927f , -0.12775820f , 0.11355232f , -0.16024788f , 0.32150415f , 0.19535993f , 0.22702237f , 0.26433052f , -0.08518964f , -0.13355330f , -0.54717674f , 0.18386017f , 0.53068186f , 0.35196477f , -0.36756679f , -0.69260204f , 0.19830746f , 0.92671624f , + -0.09461538f , 0.67447380f , 0.12354656f , 0.17963388f , 0.15317263f , 0.19433224f , 0.16035999f , -0.50697166f , 0.22832688f , -0.03638860f , -0.31139766f , -0.15364902f , -0.16277929f , 0.09079846f , 0.36114558f , 0.19448427f , -0.21078568f , -0.04243481f , 0.26104266f , 0.46369813f , 0.26334525f , -0.14251361f , -0.10575649f , -0.10844448f , + -0.04642582f , -0.10287474f , 0.07590817f , 0.04960837f , -0.05287987f , -0.15988848f , -0.08701719f , 0.14028344f , -0.27072892f , -0.02715588f , 0.24338776f , 0.20341433f , 0.43004675f , -1.02991828f , 0.27940707f , 0.21700241f , 0.11492563f , 0.27903919f , 0.26058323f , -0.34700893f , 0.07076686f , -0.10221847f , 0.05257812f , 0.55040312f , + -0.00947855f , 0.16201946f , 0.01530995f , 0.21655645f , -0.39190608f , -0.53475683f , 0.27626723f , -0.10828040f , -0.11491983f , -0.37356045f , 0.23110876f , 0.23915995f , 0.26409657f , 0.05516764f , -0.26520423f , 0.23157479f , 0.49045853f , 0.07154379f , 0.24906795f , 0.48215117f , 0.36682427f , 0.30977279f , 0.41199849f , 0.35374660f , + 0.11035037f , 0.12792077f , 0.34911446f , 0.03095177f , -0.26708115f , 0.01926537f , 0.06581393f , -0.83391569f , 0.11407886f , 0.34947774f , -0.06272482f , 0.45584926f , 0.35208593f , 0.02210972f , 0.03663452f , -0.16326364f , -0.08863411f , -0.12989747f , -0.24846516f , 0.02403637f , 0.24144266f , 0.21460052f , 0.21802777f , 0.17582350f , + 0.17586580f , -0.03883077f , 0.41247141f , 0.20117164f , 0.49169701f , 0.55456607f , -0.33339198f , -0.15935525f , 0.11000758f , 0.03881595f , -0.08086591f , 0.08127779f , -0.21850527f , 0.25204265f , 0.02918388f , -0.46406159f , -0.30149637f , -0.28716264f , -0.01652976f , -0.21430167f , -0.05257479f , -0.11894064f , 0.12104770f , 0.21200677f , + 0.05077562f , 0.64049606f , 0.29166977f , -0.14882998f , 0.23041791f , -0.17570776f , -0.25126896f , 0.15320959f , -0.50542113f , 0.51581805f , 0.29050952f , 0.02906798f , -0.21707118f , 0.08731647f , -0.26192461f , 0.08930377f , 0.01540895f , -0.11515550f , -0.13173228f , 0.04443261f , 0.14861127f , 0.15145403f , 0.38816557f , 0.40757716f , + 0.31175167f , 0.17090647f , 0.17998268f , -0.19899135f , 0.28615557f , -0.13419397f , 0.07062408f , -0.18842182f , -0.15533919f , -0.48813043f , 0.33410690f , 0.14699633f , 0.07321804f , 0.60685754f , -0.42827502f , -0.43054167f , 0.30547944f , 0.50321733f , -0.20117562f , -0.07447133f , -0.00135400f , 0.05786543f , -0.01808385f , -0.10533247f , + 0.05054332f , -0.14047735f , -0.07415119f , 0.44066546f , -0.02324372f , -0.09192828f , -0.18097335f , 0.09834903f , -0.26580813f , -0.02556763f , -0.37105934f , 0.12150755f , -0.11848442f , 0.04784313f , -0.11220379f , 0.39803073f , 0.52224090f , 0.10595610f , 0.18711063f , 0.29425741f , -0.12712275f , -0.75269106f , -0.62164375f , 1.49229636f , + -0.05263376f , 0.01551319f , -0.01862667f , 0.39621319f , 0.00775791f , 0.19443440f , -0.37005598f , 0.09947225f , 0.17067061f , -0.59100529f , -0.09194870f , -0.41824230f , 0.54676965f , 0.01393038f , 0.32793066f , 0.12752974f , -0.01761483f , 0.26099604f , 0.18632115f , 0.17752999f , -0.12037572f , -0.19613144f , -0.11840061f , -0.09740210f , + 0.09912611f , -0.24884033f , 0.19434008f , 0.16192972f , 0.05004326f , -0.59081926f , -0.41278435f , 0.10837713f , 0.06286063f , 0.17897341f , -0.09549655f , -0.11946937f , 0.19636290f , 0.10840741f , 0.12514136f , 0.91209643f , -0.52293308f , 0.24102239f , 0.14117183f , -0.19578756f , 0.29083443f , 0.08063250f , -0.15288813f , -0.30169128f , + 0.01584630f , -0.11259531f , 0.39416192f , 0.56959415f , -0.29736651f , 0.10790402f , 0.64124109f , -0.30225328f , 0.10444127f , 0.04559679f , 0.04662132f , -0.13559913f , -0.47705291f , 0.24948308f , -0.09175683f , -0.12182940f , 0.23087559f , -0.04229615f , -0.10186917f , 0.07827786f , 0.09243493f , 0.11202796f , 0.04243676f , 0.08887602f , + -0.38219650f , -0.11461189f , -0.18648336f , 0.19816038f , -0.09732223f , 0.52544356f , -0.13255010f , -0.13256714f , 0.46163208f , -0.08822080f , 0.30489642f , -0.27441353f , -0.17900853f , -0.37170730f , -0.16593309f , -0.05832152f , 0.20792097f , 0.02230373f , 0.39776652f , 0.32480143f , 0.56771378f , 0.28147085f , 0.12035847f , -0.06198797f , + 0.16289063f , 0.29806667f , 0.12344487f , 0.11272351f , 0.03410954f , -0.30062456f , 0.06877076f , -0.06004153f , 0.62082084f , 0.47068710f , -0.30298966f , -0.26674229f , -0.10333087f , 0.13814787f , -0.18170023f , -0.26286846f , 0.14643367f , 0.69028091f , 0.12706668f , -0.06000300f , -0.15983614f , -0.16308927f , 0.06054026f , 0.24605632f , + 0.71272052f , 0.52242539f , -0.04818476f , 0.31193593f , -0.15987333f , -0.06222937f , -0.05672104f , 0.53241922f , 0.05925126f , -0.20570464f , 0.11569695f , -0.11659635f , 0.17015156f , 0.03835440f , -0.10022938f , 0.00626121f , -0.22082679f , -0.10482121f , -0.03046492f , -0.07362554f , 0.16480680f , -0.02745797f , -0.23714652f , -0.40036483f , + 0.00774041f , 0.02630024f , 0.85679294f , -0.16620543f , 0.13390597f , -0.43418821f , 0.27099640f , 0.29601681f , -0.05468039f , 0.00123578f , -0.34476791f , 0.20548883f , 0.12690026f , -0.12125541f , -0.24822526f , 0.32121761f , -0.15281912f , 0.18448249f , 0.30215241f , 0.12566250f , 0.06993898f , -0.03997524f , 0.17346822f , 0.40869366f , + 0.50810094f , 0.24316475f , -0.32829494f , -0.52128186f , 0.13028426f , 0.29952885f , 0.46293804f , -0.26433277f , -0.37140799f , -0.12921967f , -0.20423017f , -0.11719085f , 0.08305804f , -0.12334944f , -0.23731075f , 0.22837853f , 0.24340316f , 0.43535913f , 0.30959620f , 0.04173569f , -0.57982693f , -0.34522367f , 0.14683522f , 0.05595596f , + 0.02237034f , -0.06316542f , -0.01048143f , -0.27361876f , 0.01327775f , 0.01156603f , -0.02656291f , -0.30384147f , -0.39207165f , 0.02401410f , -0.01835587f , 0.05743541f , -0.37923460f , 0.21265931f , 0.57306648f , 0.29538200f , -0.06625719f , 0.44038905f , 0.54409558f , 0.06943242f , 0.86241612f , 0.52782911f , 0.13063215f , -0.00969728f , + 0.11622122f , 0.02224264f , 0.32680233f , 0.00674035f , -0.18269996f , -0.07149903f , -0.38216845f , 0.11519523f , 0.15289458f , 0.02026007f , 0.31202256f , 0.38286848f , 0.06066707f , -0.11169249f , -0.10677312f , -0.20147411f , 0.01167547f , 0.11246367f , -0.70525138f , -0.69991387f , 1.00946560f , 0.95344512f , -0.75251996f , 0.27342287f +}; + +const float * const cdk_37bits[] = { cdk_37bits_1, cdk_37bits_2, cdk_37bits_3, cdk_37bits_4, cdk_37bits_5, cdk_37bits_6 }; + + +/* Sine tables for FFT */ +/* for (j=0 ; jfftlen/2+1 ; j++) hs->fftSineTab[j] = (float)sin(2.0*EVS_PI*j/hs->fftlen); */ + + +const float fftSineTab640[321] = +{ + 0.0000000000000000000000000f, 0.0098173199221491814000000f, 0.0196336936205625530000000f, 0.0294481739401817320000000f, 0.0392598174512386320000000f, 0.0490676760673522950000000f, 0.0588708035647869110000000f, 0.0686682611703872680000000f, 0.0784590989351272580000000f, 0.0882423743605613710000000f, + 0.0980171412229537960000000f, 0.1077824681997299200000000f, 0.1175374016165733300000000f, 0.1272810101509094200000000f, 0.1370123475790023800000000f, 0.1467304825782775900000000f, 0.1564344763755798300000000f, 0.1661233752965927100000000f, 0.1757962852716445900000000f, 0.1854522377252578700000000f, + 0.1950903236865997300000000f, 0.2047096043825149500000000f, 0.2143091559410095200000000f, 0.2238880544900894200000000f, 0.2334453761577606200000000f, 0.2429801821708679200000000f, 0.2524915933609008800000000f, 0.2619786560535430900000000f, 0.2714404463768005400000000f, 0.2808761000633239700000000f, + 0.2902846932411193800000000f, 0.2996652722358703600000000f, 0.3090170025825500500000000f, 0.3183389306068420400000000f, 0.3276301920413970900000000f, 0.3368898630142211900000000f, 0.3461170792579650900000000f, 0.3553109169006347700000000f, 0.3644705116748809800000000f, 0.3735949695110321000000000f, + 0.3826834559440612800000000f, 0.3917350172996521000000000f, 0.4007488489151001000000000f, 0.4097240269184112500000000f, 0.4186597466468811000000000f, 0.4275551140308380100000000f, 0.4364092648029327400000000f, 0.4452213346958160400000000f, 0.4539905190467834500000000f, 0.4627159237861633300000000f, + 0.4713967442512512200000000f, 0.4800321459770202600000000f, 0.4886212646961212200000000f, 0.4971632659435272200000000f, 0.5056573748588562000000000f, 0.5141027569770813000000000f, 0.5224985480308532700000000f, 0.5308440327644348100000000f, 0.5391383171081543000000000f, 0.5473806858062744100000000f, + 0.5555702447891235400000000f, 0.5637062788009643600000000f, 0.5717879533767700200000000f, 0.5798145532608032200000000f, 0.5877852439880371100000000f, 0.5956993103027343800000000f, 0.6035559773445129400000000f, 0.6113544106483459500000000f, 0.6190939545631408700000000f, 0.6267738342285156300000000f, + 0.6343932747840881300000000f, 0.6419516205787658700000000f, 0.6494480371475219700000000f, 0.6568819284439086900000000f, 0.6642524600028991700000000f, 0.6715589761734008800000000f, 0.6788007616996765100000000f, 0.6859771013259887700000000f, 0.6930873990058898900000000f, 0.7001308202743530300000000f, + 0.7071067690849304200000000f, 0.7140145897865295400000000f, 0.7208536267280578600000000f, 0.7276231050491333000000000f, 0.7343225479125976600000000f, 0.7409511208534240700000000f, 0.7475083470344543500000000f, 0.7539935111999511700000000f, 0.7604059576988220200000000f, 0.7667451500892639200000000f, + 0.7730104923248291000000000f, 0.7792012691497802700000000f, 0.7853169441223144500000000f, 0.7913569211959838900000000f, 0.7973206639289856000000000f, 0.8032075762748718300000000f, 0.8090170025825500500000000f, 0.8147485256195068400000000f, 0.8204014301300048800000000f, 0.8259753584861755400000000f, + 0.8314696550369262700000000f, 0.8368837833404541000000000f, 0.8422172665596008300000000f, 0.8474695682525634800000000f, 0.8526401519775390600000000f, 0.8577286005020141600000000f, 0.8627343773841857900000000f, 0.8676570057868957500000000f, 0.8724960088729858400000000f, 0.8772509098052978500000000f, + 0.8819212913513183600000000f, 0.8865066170692443800000000f, 0.8910065293312072800000000f, 0.8954205513000488300000000f, 0.8997483253479003900000000f, 0.9039893150329589800000000f, 0.9081431627273559600000000f, 0.9122095108032226600000000f, 0.9161879420280456500000000f, 0.9200780987739563000000000f, + 0.9238795638084411600000000f, 0.9275919198989868200000000f, 0.9312149286270141600000000f, 0.9347481727600097700000000f, 0.9381913542747497600000000f, 0.9415440559387207000000000f, 0.9448060393333435100000000f, 0.9479769468307495100000000f, 0.9510565400123596200000000f, 0.9540444016456604000000000f, + 0.9569403529167175300000000f, 0.9597440361976623500000000f, 0.9624552726745605500000000f, 0.9650737047195434600000000f, 0.9675990939140319800000000f, 0.9700312614440918000000000f, 0.9723699092864990200000000f, 0.9746148586273193400000000f, 0.9767658710479736300000000f, 0.9788227677345275900000000f, + 0.9807853102684021000000000f, 0.9826532602310180700000000f, 0.9844265580177307100000000f, 0.9861049652099609400000000f, 0.9876883625984191900000000f, 0.9891765117645263700000000f, 0.9905693531036377000000000f, 0.9918667078018188500000000f, 0.9930684566497802700000000f, 0.9941744804382324200000000f, + 0.9951847195625305200000000f, 0.9960990548133850100000000f, 0.9969173073768615700000000f, 0.9976395368576049800000000f, 0.9982656240463256800000000f, 0.9987954497337341300000000f, 0.9992290139198303200000000f, 0.9995663166046142600000000f, 0.9998072385787963900000000f, 0.9999517798423767100000000f, + 1.0000000000000000000000000f, 0.9999517798423767100000000f, 0.9998072385787963900000000f, 0.9995663166046142600000000f, 0.9992290139198303200000000f, 0.9987954497337341300000000f, 0.9982656240463256800000000f, 0.9976395368576049800000000f, 0.9969173073768615700000000f, 0.9960990548133850100000000f, + 0.9951847195625305200000000f, 0.9941744804382324200000000f, 0.9930684566497802700000000f, 0.9918667078018188500000000f, 0.9905693531036377000000000f, 0.9891765117645263700000000f, 0.9876883625984191900000000f, 0.9861049652099609400000000f, 0.9844265580177307100000000f, 0.9826532602310180700000000f, + 0.9807852506637573200000000f, 0.9788227677345275900000000f, 0.9767658710479736300000000f, 0.9746148586273193400000000f, 0.9723699092864990200000000f, 0.9700312614440918000000000f, 0.9675990939140319800000000f, 0.9650736451148986800000000f, 0.9624552130699157700000000f, 0.9597440361976623500000000f, + 0.9569402933120727500000000f, 0.9540444016456604000000000f, 0.9510564804077148400000000f, 0.9479769468307495100000000f, 0.9448060393333435100000000f, 0.9415440559387207000000000f, 0.9381912946701049800000000f, 0.9347481727600097700000000f, 0.9312149286270141600000000f, 0.9275919198989868200000000f, + 0.9238795042037963900000000f, 0.9200780391693115200000000f, 0.9161879420280456500000000f, 0.9122095108032226600000000f, 0.9081431627273559600000000f, 0.9039892554283142100000000f, 0.8997482657432556200000000f, 0.8954205513000488300000000f, 0.8910064697265625000000000f, 0.8865066170692443800000000f, + 0.8819212317466735800000000f, 0.8772509098052978500000000f, 0.8724959492683410600000000f, 0.8676570057868957500000000f, 0.8627343773841857900000000f, 0.8577286005020141600000000f, 0.8526401519775390600000000f, 0.8474695086479187000000000f, 0.8422172069549560500000000f, 0.8368837237358093300000000f, + 0.8314695954322814900000000f, 0.8259752988815307600000000f, 0.8204014301300048800000000f, 0.8147484660148620600000000f, 0.8090169429779052700000000f, 0.8032075166702270500000000f, 0.7973206043243408200000000f, 0.7913568615913391100000000f, 0.7853168845176696800000000f, 0.7792012095451355000000000f, + 0.7730104327201843300000000f, 0.7667450904846191400000000f, 0.7604058980941772500000000f, 0.7539934515953064000000000f, 0.7475082874298095700000000f, 0.7409510612487793000000000f, 0.7343224883079528800000000f, 0.7276230454444885300000000f, 0.7208535671234130900000000f, 0.7140145301818847700000000f, + 0.7071067094802856400000000f, 0.7001307606697082500000000f, 0.6930873394012451200000000f, 0.6859770417213439900000000f, 0.6788007020950317400000000f, 0.6715589165687561000000000f, 0.6642524003982543900000000f, 0.6568818688392639200000000f, 0.6494479775428772000000000f, 0.6419515609741210900000000f, + 0.6343932151794433600000000f, 0.6267737746238708500000000f, 0.6190938949584960900000000f, 0.6113543510437011700000000f, 0.6035558581352233900000000f, 0.5956992506980896000000000f, 0.5877851843833923300000000f, 0.5798144936561584500000000f, 0.5717878937721252400000000f, 0.5637062191963195800000000f, + 0.5555701851844787600000000f, 0.5473806262016296400000000f, 0.5391382575035095200000000f, 0.5308439731597900400000000f, 0.5224984884262085000000000f, 0.5141026973724365200000000f, 0.5056573152542114300000000f, 0.4971632063388824500000000f, 0.4886211752891540500000000f, 0.4800320565700531000000000f, + 0.4713966846466064500000000f, 0.4627158641815185500000000f, 0.4539904296398162800000000f, 0.4452212452888488800000000f, 0.4364091753959655800000000f, 0.4275550246238708500000000f, 0.4186596572399139400000000f, 0.4097239673137664800000000f, 0.4007487595081329300000000f, 0.3917349278926849400000000f, + 0.3826833665370941200000000f, 0.3735949099063873300000000f, 0.3644704222679138200000000f, 0.3553108274936676000000000f, 0.3461169898509979200000000f, 0.3368897736072540300000000f, 0.3276301026344299300000000f, 0.3183388411998748800000000f, 0.3090169131755828900000000f, 0.2996652126312255900000000f, + 0.2902846038341522200000000f, 0.2808760106563568100000000f, 0.2714403867721557600000000f, 0.2619785666465759300000000f, 0.2524915039539337200000000f, 0.2429801076650619500000000f, 0.2334452867507934600000000f, 0.2238879650831222500000000f, 0.2143090665340423600000000f, 0.2047095298767089800000000f, + 0.1950902342796325700000000f, 0.1854521632194519000000000f, 0.1757961958646774300000000f, 0.1661233007907867400000000f, 0.1564343869686126700000000f, 0.1467303931713104200000000f, 0.1370122581720352200000000f, 0.1272809207439422600000000f, 0.1175373122096061700000000f, 0.1077823787927627600000000f, + 0.0980170592665672300000000f, 0.0882422849535942080000000f, 0.0784590095281600950000000f, 0.0686681717634201050000000f, 0.0588707178831100460000000f, 0.0490675866603851320000000f, 0.0392597280442714690000000f, 0.0294480863958597180000000f, 0.0196336060762405400000000f, 0.0098172323778271675000000f, + -0.0000000874227765734758580f +}; + +/* Analysis windows for overlap-add */ +/* ener = 0.f; + for (j=0 ; jfftlen ; j++) + { + hs->olapWinAna[j] = (float)sin(EVS_PI*((float)j+0.5f)/(float)(hs->fftlen)); + ener += hs->olapWinAna[j]*hs->olapWinAna[j]; + } + ener = (float)sqrt( ener / (float)hs->fftlen ); + for (j=0 ; jfftlen ; j++) + { + hs->olapWinAna[j] /= ener; + } */ +const float olapWinAna512[512] = +{ + 0.0043387459591031075000000f, 0.0130160758271813390000000f, 0.0216929148882627490000000f, 0.0303689353168010710000000f, 0.0390438176691532140000000f, 0.0477172248065471650000000f, 0.0563888400793075560000000f, 0.0650583282113075260000000f, 0.0737253651022911070000000f, 0.0823896303772926330000000f, + 0.0910507962107658390000000f, 0.0997085273265838620000000f, 0.1083625108003616300000000f, 0.1170124113559722900000000f, 0.1256579011678695700000000f, 0.1342986673116684000000000f, 0.1429343819618225100000000f, 0.1515647023916244500000000f, 0.1601893156766891500000000f, 0.1688079088926315300000000f, + 0.1774201542139053300000000f, 0.1860256940126419100000000f, 0.1946242451667785600000000f, 0.2032154798507690400000000f, 0.2117990404367446900000000f, 0.2203746438026428200000000f, 0.2289419323205947900000000f, 0.2375006377696991000000000f, 0.2460503578186035200000000f, 0.2545908391475677500000000f, + 0.2631217241287231400000000f, 0.2716427147388458300000000f, 0.2801534831523895300000000f, 0.2886536717414856000000000f, 0.2971430122852325400000000f, 0.3056211769580841100000000f, 0.3140878379344940200000000f, 0.3225426375865936300000000f, 0.3309853076934814500000000f, 0.3394155502319335900000000f, + 0.3478329777717590300000000f, 0.3562373220920562700000000f, 0.3646282255649566700000000f, 0.3730054795742034900000000f, 0.3813686370849609400000000f, 0.3897174298763275100000000f, 0.3980515301227569600000000f, 0.4063706994056701700000000f, 0.4146745502948761000000000f, 0.4229627549648284900000000f, + 0.4312350451946258500000000f, 0.4394911527633667000000000f, 0.4477306604385376000000000f, 0.4559533298015594500000000f, 0.4641588330268859900000000f, 0.4723468720912933300000000f, 0.4805171191692352300000000f, 0.4886692464351654100000000f, 0.4968029856681823700000000f, 0.5049180388450622600000000f, + 0.5130140781402587900000000f, 0.5210908055305481000000000f, 0.5291479229927063000000000f, 0.5371851325035095200000000f, 0.5452020764350891100000000f, 0.5531984567642211900000000f, 0.5611740946769714400000000f, 0.5691285729408264200000000f, 0.5770615935325622600000000f, 0.5849729180335998500000000f, + 0.5928622484207153300000000f, 0.6007292270660400400000000f, 0.6085735559463501000000000f, 0.6163949966430664100000000f, 0.6241932511329650900000000f, 0.6319679617881774900000000f, 0.6397189497947692900000000f, 0.6474457979202270500000000f, 0.6551482677459716800000000f, 0.6628261208534240700000000f, + 0.6704789996147155800000000f, 0.6781066060066223100000000f, 0.6857087016105651900000000f, 0.6932849884033203100000000f, 0.7008351087570190400000000f, 0.7083588838577270500000000f, 0.7158560752868652300000000f, 0.7233262658119201700000000f, 0.7307691574096679700000000f, 0.7381845116615295400000000f, + 0.7455722093582153300000000f, 0.7529317140579223600000000f, 0.7602629661560058600000000f, 0.7675655484199523900000000f, 0.7748392224311828600000000f, 0.7820837497711181600000000f, 0.7892987728118896500000000f, 0.7964841723442077600000000f, 0.8036395311355590800000000f, 0.8107646703720092800000000f, + 0.8178592920303344700000000f, 0.8249230980873107900000000f, 0.8319557905197143600000000f, 0.8389572501182556200000000f, 0.8459270596504211400000000f, 0.8528650403022766100000000f, 0.8597708344459533700000000f, 0.8666443228721618700000000f, 0.8734852671623230000000000f, 0.8802932500839233400000000f, + 0.8870680332183837900000000f, 0.8938094973564147900000000f, 0.9005173444747924800000000f, 0.9071912169456481900000000f, 0.9138309359550476100000000f, 0.9204362630844116200000000f, 0.9270069003105163600000000f, 0.9335426688194274900000000f, 0.9400433301925659200000000f, 0.9465085864067077600000000f, + 0.9529381394386291500000000f, 0.9593318104743957500000000f, 0.9656894207000732400000000f, 0.9720106720924377400000000f, 0.9782953858375549300000000f, 0.9845431447029113800000000f, 0.9907538890838623000000000f, 0.9969274401664733900000000f, 1.0030633211135864000000000f, 1.0091614723205566000000000f, + 1.0152215957641602000000000f, 1.0212435722351074000000000f, 1.0272270441055298000000000f, 1.0331718921661377000000000f, 1.0390777587890625000000000f, 1.0449445247650146000000000f, 1.0507719516754150000000000f, 1.0565599203109741000000000f, 1.0623079538345337000000000f, 1.0680160522460937000000000f, + 1.0736839771270752000000000f, 1.0793114900588989000000000f, 1.0848982334136963000000000f, 1.0904443264007568000000000f, 1.0959492921829224000000000f, 1.1014128923416138000000000f, 1.1068351268768311000000000f, 1.1122156381607056000000000f, 1.1175543069839478000000000f, 1.1228508949279785000000000f, + 1.1281052827835083000000000f, 1.1333171129226685000000000f, 1.1384862661361694000000000f, 1.1436126232147217000000000f, 1.1486958265304565000000000f, 1.1537358760833740000000000f, 1.1587324142456055000000000f, 1.1636853218078613000000000f, 1.1685944795608521000000000f, 1.1734596490859985000000000f, + 1.1782805919647217000000000f, 1.1830571889877319000000000f, 1.1877892017364502000000000f, 1.1924765110015869000000000f, 1.1971189975738525000000000f, 1.2017163038253784000000000f, 1.2062685489654541000000000f, 1.2107752561569214000000000f, 1.2152363061904907000000000f, 1.2196516990661621000000000f, + 1.2240210771560669000000000f, 1.2283445596694946000000000f, 1.2326216697692871000000000f, 1.2368522882461548000000000f, 1.2410365343093872000000000f, 1.2451739311218262000000000f, 1.2492644786834717000000000f, 1.2533079385757446000000000f, 1.2573043107986450000000000f, 1.2612532377243042000000000f, + 1.2651547193527222000000000f, 1.2690086364746094000000000f, 1.2728147506713867000000000f, 1.2765728235244751000000000f, 1.2802829742431641000000000f, 1.2839449644088745000000000f, 1.2875584363937378000000000f, 1.2911235094070435000000000f, 1.2946400642395020000000000f, 1.2981077432632446000000000f, + 1.3015266656875610000000000f, 1.3048964738845825000000000f, 1.3082171678543091000000000f, 1.3114887475967407000000000f, 1.3147107362747192000000000f, 1.3178833723068237000000000f, 1.3210064172744751000000000f, 1.3240796327590942000000000f, 1.3271030187606812000000000f, 1.3300764560699463000000000f, + 1.3329998254776001000000000f, 1.3358730077743530000000000f, 1.3386958837509155000000000f, 1.3414683341979980000000000f, 1.3441903591156006000000000f, 1.3468616008758545000000000f, 1.3494822978973389000000000f, 1.3520522117614746000000000f, 1.3545711040496826000000000f, 1.3570390939712524000000000f, + 1.3594559431076050000000000f, 1.3618216514587402000000000f, 1.3641359806060791000000000f, 1.3663990497589111000000000f, 1.3686106204986572000000000f, 1.3707706928253174000000000f, 1.3728791475296021000000000f, 1.3749359846115112000000000f, 1.3769409656524658000000000f, 1.3788940906524658000000000f, + 1.3807953596115112000000000f, 1.3826445341110229000000000f, 1.3844418525695801000000000f, 1.3861869573593140000000000f, 1.3878798484802246000000000f, 1.3895204067230225000000000f, 1.3911087512969971000000000f, 1.3926446437835693000000000f, 1.3941282033920288000000000f, 1.3955593109130859000000000f, + 1.3969377279281616000000000f, 1.3982635736465454000000000f, 1.3995368480682373000000000f, 1.4007574319839478000000000f, 1.4019253253936768000000000f, 1.4030404090881348000000000f, 1.4041025638580322000000000f, 1.4051119089126587000000000f, 1.4060683250427246000000000f, 1.4069718122482300000000000f, + 1.4078224897384644000000000f, 1.4086199998855591000000000f, 1.4093644618988037000000000f, 1.4100558757781982000000000f, 1.4106942415237427000000000f, 1.4112794399261475000000000f, 1.4118115901947021000000000f, 1.4122905731201172000000000f, 1.4127163887023926000000000f, 1.4130889177322388000000000f, + 1.4134082794189453000000000f, 1.4136744737625122000000000f, 1.4138875007629395000000000f, 1.4140472412109375000000000f, 1.4141536951065063000000000f, 1.4142069816589355000000000f, 1.4142069816589355000000000f, 1.4141536951065063000000000f, 1.4140472412109375000000000f, 1.4138875007629395000000000f, + 1.4136744737625122000000000f, 1.4134082794189453000000000f, 1.4130889177322388000000000f, 1.4127163887023926000000000f, 1.4122905731201172000000000f, 1.4118115901947021000000000f, 1.4112794399261475000000000f, 1.4106942415237427000000000f, 1.4100558757781982000000000f, 1.4093644618988037000000000f, + 1.4086199998855591000000000f, 1.4078224897384644000000000f, 1.4069718122482300000000000f, 1.4060683250427246000000000f, 1.4051119089126587000000000f, 1.4041025638580322000000000f, 1.4030402898788452000000000f, 1.4019252061843872000000000f, 1.4007574319839478000000000f, 1.3995368480682373000000000f, + 1.3982635736465454000000000f, 1.3969377279281616000000000f, 1.3955591917037964000000000f, 1.3941282033920288000000000f, 1.3926446437835693000000000f, 1.3911087512969971000000000f, 1.3895204067230225000000000f, 1.3878798484802246000000000f, 1.3861868381500244000000000f, 1.3844418525695801000000000f, + 1.3826445341110229000000000f, 1.3807953596115112000000000f, 1.3788940906524658000000000f, 1.3769409656524658000000000f, 1.3749359846115112000000000f, 1.3728791475296021000000000f, 1.3707706928253174000000000f, 1.3686106204986572000000000f, 1.3663990497589111000000000f, 1.3641359806060791000000000f, + 1.3618216514587402000000000f, 1.3594559431076050000000000f, 1.3570389747619629000000000f, 1.3545711040496826000000000f, 1.3520520925521851000000000f, 1.3494822978973389000000000f, 1.3468616008758545000000000f, 1.3441903591156006000000000f, 1.3414683341979980000000000f, 1.3386958837509155000000000f, + 1.3358730077743530000000000f, 1.3329998254776001000000000f, 1.3300764560699463000000000f, 1.3271030187606812000000000f, 1.3240796327590942000000000f, 1.3210062980651855000000000f, 1.3178833723068237000000000f, 1.3147107362747192000000000f, 1.3114886283874512000000000f, 1.3082171678543091000000000f, + 1.3048964738845825000000000f, 1.3015265464782715000000000f, 1.2981077432632446000000000f, 1.2946399450302124000000000f, 1.2911235094070435000000000f, 1.2875584363937378000000000f, 1.2839448451995850000000000f, 1.2802829742431641000000000f, 1.2765728235244751000000000f, 1.2728147506713867000000000f, + 1.2690086364746094000000000f, 1.2651547193527222000000000f, 1.2612532377243042000000000f, 1.2573041915893555000000000f, 1.2533078193664551000000000f, 1.2492643594741821000000000f, 1.2451738119125366000000000f, 1.2410364151000977000000000f, 1.2368522882461548000000000f, 1.2326216697692871000000000f, + 1.2283444404602051000000000f, 1.2240210771560669000000000f, 1.2196515798568726000000000f, 1.2152363061904907000000000f, 1.2107751369476318000000000f, 1.2062684297561646000000000f, 1.2017163038253784000000000f, 1.1971189975738525000000000f, 1.1924765110015869000000000f, 1.1877892017364502000000000f, + 1.1830570697784424000000000f, 1.1782804727554321000000000f, 1.1734595298767090000000000f, 1.1685943603515625000000000f, 1.1636853218078613000000000f, 1.1587324142456055000000000f, 1.1537357568740845000000000f, 1.1486958265304565000000000f, 1.1436125040054321000000000f, 1.1384861469268799000000000f, + 1.1333171129226685000000000f, 1.1281051635742187000000000f, 1.1228507757186890000000000f, 1.1175541877746582000000000f, 1.1122155189514160000000000f, 1.1068350076675415000000000f, 1.1014127731323242000000000f, 1.0959491729736328000000000f, 1.0904442071914673000000000f, 1.0848982334136963000000000f, + 1.0793113708496094000000000f, 1.0736838579177856000000000f, 1.0680160522460937000000000f, 1.0623078346252441000000000f, 1.0565598011016846000000000f, 1.0507718324661255000000000f, 1.0449445247650146000000000f, 1.0390776395797729000000000f, 1.0331717729568481000000000f, 1.0272269248962402000000000f, + 1.0212434530258179000000000f, 1.0152214765548706000000000f, 1.0091613531112671000000000f, 1.0030632019042969000000000f, 0.9969273209571838400000000f, 0.9907538294792175300000000f, 0.9845430850982666000000000f, 0.9782953262329101600000000f, 0.9720106124877929700000000f, 0.9656893610954284700000000f, + 0.9593317508697509800000000f, 0.9529380798339843800000000f, 0.9465084671974182100000000f, 0.9400432705879211400000000f, 0.9335426092147827100000000f, 0.9270067811012268100000000f, 0.9204362034797668500000000f, 0.9138308763504028300000000f, 0.9071910977363586400000000f, 0.9005171656608581500000000f, + 0.8938094377517700200000000f, 0.8870679140090942400000000f, 0.8802930712699890100000000f, 0.8734850883483886700000000f, 0.8666442632675170900000000f, 0.8597707748413085900000000f, 0.8528649210929870600000000f, 0.8459268808364868200000000f, 0.8389570713043212900000000f, 0.8319557309150695800000000f, + 0.8249229192733764600000000f, 0.8178591728210449200000000f, 0.8107645511627197300000000f, 0.8036394119262695300000000f, 0.7964840531349182100000000f, 0.7892987132072448700000000f, 0.7820836901664733900000000f, 0.7748391628265380900000000f, 0.7675654292106628400000000f, 0.7602628469467163100000000f, + 0.7529316544532775900000000f, 0.7455720901489257800000000f, 0.7381844520568847700000000f, 0.7307690382003784200000000f, 0.7233260869979858400000000f, 0.7158559560775756800000000f, 0.7083588242530822800000000f, 0.7008350491523742700000000f, 0.6932848691940307600000000f, 0.6857085824012756300000000f, + 0.6781064867973327600000000f, 0.6704788804054260300000000f, 0.6628260016441345200000000f, 0.6551482081413269000000000f, 0.6474456787109375000000000f, 0.6397188305854797400000000f, 0.6319679021835327100000000f, 0.6241931319236755400000000f, 0.6163948774337768600000000f, 0.6085734367370605500000000f, + 0.6007291078567504900000000f, 0.5928621292114257800000000f, 0.5849727988243103000000000f, 0.5770615339279174800000000f, 0.5691284537315368700000000f, 0.5611739754676818800000000f, 0.5531983971595764200000000f, 0.5452019572257995600000000f, 0.5371850132942199700000000f, 0.5291478037834167500000000f, + 0.5210906863212585400000000f, 0.5130139589309692400000000f, 0.5049179196357727100000000f, 0.4968028664588928200000000f, 0.4886691272258758500000000f, 0.4805169999599456800000000f, 0.4723467230796814000000000f, 0.4641586840152740500000000f, 0.4559532105922699000000000f, 0.4477305412292480500000000f, + 0.4394910335540771500000000f, 0.4312349855899810800000000f, 0.4229626357555389400000000f, 0.4146744310855865500000000f, 0.4063705503940582300000000f, 0.3980514407157897900000000f, 0.3897172808647155800000000f, 0.3813685178756713900000000f, 0.3730053603649139400000000f, 0.3646281659603118900000000f, + 0.3562372326850891100000000f, 0.3478328585624694800000000f, 0.3394154310226440400000000f, 0.3309852182865142800000000f, 0.3225425183773040800000000f, 0.3140876889228820800000000f, 0.3056210577487945600000000f, 0.2971428930759429900000000f, 0.2886535525321960400000000f, 0.2801533639430999800000000f, + 0.2716425955295562700000000f, 0.2631216049194335900000000f, 0.2545907199382782000000000f, 0.2460502535104751600000000f, 0.2375005036592483500000000f, 0.2289418131113052400000000f, 0.2203745096921920800000000f, 0.2117989212274551400000000f, 0.2032153606414794900000000f, 0.1946241259574890100000000f, + 0.1860255748033523600000000f, 0.1774200350046157800000000f, 0.1688077896833419800000000f, 0.1601892113685607900000000f, 0.1515645831823349000000000f, 0.1429342478513717700000000f, 0.1342985481023788500000000f, 0.1256577819585800200000000f, 0.1170122846961021400000000f, 0.1083623841404914900000000f, + 0.0997084006667137150000000f, 0.0910506695508956910000000f, 0.0823895111680030820000000f, 0.0737252458930015560000000f, 0.0650582015514373780000000f, 0.0563887134194374080000000f, 0.0477171018719673160000000f, 0.0390436910092830660000000f, 0.0303688123822212220000000f, 0.0216927900910377500000000f, + 0.0130159519612789150000000f, 0.0043386225588619709000000f +}; + +const float olapWinAna640[640] = +{ + 0.0034709984902292490000000f, 0.0104129118844866750000000f, 0.0173545740544795990000000f, 0.0242958199232816700000000f, 0.0312364790588617320000000f, 0.0381763875484466550000000f, 0.0451153740286827090000000f, 0.0520532727241516110000000f, 0.0589899159967899320000000f, 0.0659251436591148380000000f, + 0.0728587806224823000000000f, 0.0797906517982482910000000f, 0.0867206156253814700000000f, 0.0936484783887863160000000f, 0.1005740910768508900000000f, 0.1074972823262214700000000f, 0.1144178733229637100000000f, 0.1213357225060463000000000f, 0.1282506436109542800000000f, 0.1351624578237533600000000f, + 0.1420710384845733600000000f, 0.1489761769771575900000000f, 0.1558777391910553000000000f, 0.1627755314111709600000000f, 0.1696694195270538300000000f, 0.1765592098236084000000000f, 0.1834447383880615200000000f, 0.1903258562088012700000000f, 0.1972023993730545000000000f, 0.2040741592645645100000000f, + 0.2109410166740417500000000f, 0.2178028076887130700000000f, 0.2246593385934829700000000f, 0.2315104454755783100000000f, 0.2383559793233871500000000f, 0.2451957911252975500000000f, 0.2520296573638916000000000f, 0.2588574886322021500000000f, 0.2656790614128112800000000f, 0.2724942266941070600000000f, + 0.2793028354644775400000000f, 0.2861047089099884000000000f, 0.2928997278213501000000000f, 0.2996876239776611300000000f, 0.3064683377742767300000000f, 0.3132416605949401900000000f, 0.3200074136257171600000000f, 0.3267655074596405000000000f, 0.3335156738758087200000000f, 0.3402578532695770300000000f, + 0.3469918072223663300000000f, 0.3537174165248870800000000f, 0.3604344725608825700000000f, 0.3671428561210632300000000f, 0.3738423883914947500000000f, 0.3805329203605651900000000f, 0.3872142732143402100000000f, 0.3938862979412078900000000f, 0.4005488157272338900000000f, 0.4072017371654510500000000f, + 0.4138447940349578900000000f, 0.4204779267311096200000000f, 0.4271008670330047600000000f, 0.4337135851383209200000000f, 0.4403158128261566200000000f, 0.4469074010848999000000000f, 0.4534882903099060100000000f, 0.4600581824779510500000000f, 0.4666170477867126500000000f, 0.4731646478176116900000000f, + 0.4797008633613586400000000f, 0.4862254858016967800000000f, 0.4927383959293365500000000f, 0.4992394745349884000000000f, 0.5057284832000732400000000f, 0.5122053027153015100000000f, 0.5186697840690612800000000f, 0.5251218080520629900000000f, 0.5315611362457275400000000f, 0.5379876494407653800000000f, + 0.5444012284278869600000000f, 0.5508016943931579600000000f, 0.5571888685226440400000000f, 0.5635626316070556600000000f, 0.5699228048324585000000000f, 0.5762692093849182100000000f, 0.5826017856597900400000000f, 0.5889202952384948700000000f, 0.5952246189117431600000000f, 0.6015146374702453600000000f, + 0.6077901124954223600000000f, 0.6140509843826293900000000f, 0.6202970147132873500000000f, 0.6265281438827514600000000f, 0.6327440738677978500000000f, 0.6389448642730712900000000f, 0.6451302766799926800000000f, 0.6513000726699829100000000f, 0.6574541926383972200000000f, 0.6635924577713012700000000f, + 0.6697147488594055200000000f, 0.6758209466934204100000000f, 0.6819108128547668500000000f, 0.6879842281341552700000000f, 0.6940411329269409200000000f, 0.7000812292098999000000000f, 0.7061045169830322300000000f, 0.7121107578277587900000000f, 0.7180998921394348100000000f, 0.7240716814994812000000000f, + 0.7300260066986084000000000f, 0.7359628081321716300000000f, 0.7418818473815918000000000f, 0.7477830052375793500000000f, 0.7536661028861999500000000f, 0.7595310807228088400000000f, 0.7653777003288269000000000f, 0.7712059617042541500000000f, 0.7770156264305114700000000f, 0.7828065156936645500000000f, + 0.7885786294937133800000000f, 0.7943316698074340800000000f, 0.8000655770301818800000000f, 0.8057801723480224600000000f, 0.8114753961563110400000000f, 0.8171511292457580600000000f, 0.8228070735931396500000000f, 0.8284432291984558100000000f, 0.8340594172477722200000000f, 0.8396555185317993200000000f, + 0.8452314138412475600000000f, 0.8507869243621826200000000f, 0.8563219308853149400000000f, 0.8618362545967102100000000f, 0.8673298358917236300000000f, 0.8728026151657104500000000f, 0.8782541751861572300000000f, 0.8836847543716430700000000f, 0.8890939354896545400000000f, 0.8944817185401916500000000f, + 0.8998479843139648400000000f, 0.9051925539970397900000000f, 0.9105152487754821800000000f, 0.9158160686492919900000000f, 0.9210947751998901400000000f, 0.9263513088226318400000000f, 0.9315855503082275400000000f, 0.9367973208427429200000000f, 0.9419865608215332000000000f, 0.9471529722213745100000000f, + 0.9522966742515564000000000f, 0.9574174284934997600000000f, 0.9625151157379150400000000f, 0.9675895571708679200000000f, 0.9726406931877136200000000f, 0.9776684641838073700000000f, 0.9826726913452148400000000f, 0.9876530766487121600000000f, 0.9926097989082336400000000f, 0.9975425601005554200000000f, + 1.0024513006210327000000000f, 1.0073359012603760000000000f, 1.0121961832046509000000000f, 1.0170321464538574000000000f, 1.0218435525894165000000000f, 1.0266302824020386000000000f, 1.0313923358917236000000000f, 1.0361295938491821000000000f, 1.0408418178558350000000000f, 1.0455290079116821000000000f, + 1.0501909255981445000000000f, 1.0548275709152222000000000f, 1.0594388246536255000000000f, 1.0640245676040649000000000f, 1.0685845613479614000000000f, 1.0731189250946045000000000f, 1.0776274204254150000000000f, 1.0821099281311035000000000f, 1.0865663290023804000000000f, 1.0909965038299561000000000f, + 1.0954004526138306000000000f, 1.0997780561447144000000000f, 1.1041290760040283000000000f, 1.1084536314010620000000000f, 1.1127513647079468000000000f, 1.1170222759246826000000000f, 1.1212662458419800000000000f, 1.1254832744598389000000000f, 1.1296732425689697000000000f, 1.1338359117507935000000000f, + 1.1379711627960205000000000f, 1.1420791149139404000000000f, 1.1461595296859741000000000f, 1.1502122879028320000000000f, 1.1542373895645142000000000f, 1.1582345962524414000000000f, 1.1622040271759033000000000f, 1.1661453247070312000000000f, 1.1700586080551147000000000f, 1.1739436388015747000000000f, + 1.1778002977371216000000000f, 1.1816288232803345000000000f, 1.1854286193847656000000000f, 1.1892000436782837000000000f, 1.1929427385330200000000000f, 1.1966567039489746000000000f, 1.2003418207168579000000000f, 1.2039979696273804000000000f, 1.2076252698898315000000000f, 1.2112232446670532000000000f, + 1.2147921323776245000000000f, 1.2183318138122559000000000f, 1.2218420505523682000000000f, 1.2253229618072510000000000f, 1.2287741899490356000000000f, 1.2321958541870117000000000f, 1.2355878353118896000000000f, 1.2389501333236694000000000f, 1.2422825098037720000000000f, 1.2455849647521973000000000f, + 1.2488573789596558000000000f, 1.2520997524261475000000000f, 1.2553119659423828000000000f, 1.2584939002990723000000000f, 1.2616454362869263000000000f, 1.2647666931152344000000000f, 1.2678573131561279000000000f, 1.2709175348281860000000000f, 1.2739471197128296000000000f, 1.2769459486007690000000000f, + 1.2799140214920044000000000f, 1.2828512191772461000000000f, 1.2857576608657837000000000f, 1.2886329889297485000000000f, 1.2914773225784302000000000f, 1.2942904233932495000000000f, 1.2970724105834961000000000f, 1.2998231649398804000000000f, 1.3025425672531128000000000f, 1.3052306175231934000000000f, + 1.3078873157501221000000000f, 1.3105123043060303000000000f, 1.3131058216094971000000000f, 1.3156676292419434000000000f, 1.3181978464126587000000000f, 1.3206962347030640000000000f, 1.3231627941131592000000000f, 1.3255974054336548000000000f, 1.3280001878738403000000000f, 1.3303710222244263000000000f, + 1.3327096700668335000000000f, 1.3350162506103516000000000f, 1.3372906446456909000000000f, 1.3395328521728516000000000f, 1.3417427539825439000000000f, 1.3439202308654785000000000f, 1.3460655212402344000000000f, 1.3481782674789429000000000f, 1.3502584695816040000000000f, 1.3523062467575073000000000f, + 1.3543214797973633000000000f, 1.3563039302825928000000000f, 1.3582537174224854000000000f, 1.3601709604263306000000000f, 1.3620551824569702000000000f, 1.3639067411422729000000000f, 1.3657253980636597000000000f, 1.3675111532211304000000000f, 1.3692638874053955000000000f, 1.3709838390350342000000000f, + 1.3726705312728882000000000f, 1.3743242025375366000000000f, 1.3759448528289795000000000f, 1.3775322437286377000000000f, 1.3790863752365112000000000f, 1.3806074857711792000000000f, 1.3820952177047729000000000f, 1.3835495710372925000000000f, 1.3849706649780273000000000f, 1.3863584995269775000000000f, + 1.3877127170562744000000000f, 1.3890335559844971000000000f, 1.3903210163116455000000000f, 1.3915749788284302000000000f, 1.3927953243255615000000000f, 1.3939821720123291000000000f, 1.3951354026794434000000000f, 1.3962548971176147000000000f, 1.3973408937454224000000000f, 1.3983932733535767000000000f, + 1.3994117975234985000000000f, 1.4003967046737671000000000f, 1.4013478755950928000000000f, 1.4022653102874756000000000f, 1.4031487703323364000000000f, 1.4039986133575439000000000f, 1.4048146009445190000000000f, 1.4055966138839722000000000f, 1.4063447713851929000000000f, 1.4070591926574707000000000f, + 1.4077396392822266000000000f, 1.4083861112594604000000000f, 1.4089987277984619000000000f, 1.4095773696899414000000000f, 1.4101220369338989000000000f, 1.4106327295303345000000000f, 1.4111093282699585000000000f, 1.4115520715713501000000000f, 1.4119608402252197000000000f, 1.4123353958129883000000000f, + 1.4126759767532349000000000f, 1.4129825830459595000000000f, 1.4132552146911621000000000f, 1.4134936332702637000000000f, 1.4136980772018433000000000f, 1.4138684272766113000000000f, 1.4140048027038574000000000f, 1.4141069650650024000000000f, 1.4141751527786255000000000f, 1.4142091274261475000000000f, + 1.4142091274261475000000000f, 1.4141751527786255000000000f, 1.4141069650650024000000000f, 1.4140048027038574000000000f, 1.4138684272766113000000000f, 1.4136980772018433000000000f, 1.4134936332702637000000000f, 1.4132550954818726000000000f, 1.4129825830459595000000000f, 1.4126759767532349000000000f, + 1.4123353958129883000000000f, 1.4119607210159302000000000f, 1.4115520715713501000000000f, 1.4111093282699585000000000f, 1.4106327295303345000000000f, 1.4101220369338989000000000f, 1.4095773696899414000000000f, 1.4089987277984619000000000f, 1.4083861112594604000000000f, 1.4077396392822266000000000f, + 1.4070591926574707000000000f, 1.4063447713851929000000000f, 1.4055966138839722000000000f, 1.4048146009445190000000000f, 1.4039986133575439000000000f, 1.4031487703323364000000000f, 1.4022653102874756000000000f, 1.4013477563858032000000000f, 1.4003967046737671000000000f, 1.3994117975234985000000000f, + 1.3983932733535767000000000f, 1.3973408937454224000000000f, 1.3962548971176147000000000f, 1.3951354026794434000000000f, 1.3939821720123291000000000f, 1.3927953243255615000000000f, 1.3915748596191406000000000f, 1.3903210163116455000000000f, 1.3890335559844971000000000f, 1.3877127170562744000000000f, + 1.3863583803176880000000000f, 1.3849706649780273000000000f, 1.3835495710372925000000000f, 1.3820950984954834000000000f, 1.3806074857711792000000000f, 1.3790863752365112000000000f, 1.3775322437286377000000000f, 1.3759448528289795000000000f, 1.3743242025375366000000000f, 1.3726705312728882000000000f, + 1.3709837198257446000000000f, 1.3692638874053955000000000f, 1.3675111532211304000000000f, 1.3657253980636597000000000f, 1.3639067411422729000000000f, 1.3620551824569702000000000f, 1.3601708412170410000000000f, 1.3582537174224854000000000f, 1.3563039302825928000000000f, 1.3543213605880737000000000f, + 1.3523062467575073000000000f, 1.3502584695816040000000000f, 1.3481782674789429000000000f, 1.3460655212402344000000000f, 1.3439202308654785000000000f, 1.3417427539825439000000000f, 1.3395328521728516000000000f, 1.3372905254364014000000000f, 1.3350161314010620000000000f, 1.3327096700668335000000000f, + 1.3303709030151367000000000f, 1.3280001878738403000000000f, 1.3255974054336548000000000f, 1.3231626749038696000000000f, 1.3206962347030640000000000f, 1.3181978464126587000000000f, 1.3156676292419434000000000f, 1.3131058216094971000000000f, 1.3105123043060303000000000f, 1.3078871965408325000000000f, + 1.3052306175231934000000000f, 1.3025425672531128000000000f, 1.2998231649398804000000000f, 1.2970724105834961000000000f, 1.2942904233932495000000000f, 1.2914772033691406000000000f, 1.2886328697204590000000000f, 1.2857575416564941000000000f, 1.2828512191772461000000000f, 1.2799140214920044000000000f, + 1.2769459486007690000000000f, 1.2739471197128296000000000f, 1.2709175348281860000000000f, 1.2678573131561279000000000f, 1.2647665739059448000000000f, 1.2616454362869263000000000f, 1.2584937810897827000000000f, 1.2553118467330933000000000f, 1.2520996332168579000000000f, 1.2488572597503662000000000f, + 1.2455849647521973000000000f, 1.2422825098037720000000000f, 1.2389501333236694000000000f, 1.2355878353118896000000000f, 1.2321958541870117000000000f, 1.2287741899490356000000000f, 1.2253228425979614000000000f, 1.2218420505523682000000000f, 1.2183316946029663000000000f, 1.2147921323776245000000000f, + 1.2112232446670532000000000f, 1.2076251506805420000000000f, 1.2039978504180908000000000f, 1.2003417015075684000000000f, 1.1966565847396851000000000f, 1.1929427385330200000000000f, 1.1891999244689941000000000f, 1.1854286193847656000000000f, 1.1816287040710449000000000f, 1.1778002977371216000000000f, + 1.1739435195922852000000000f, 1.1700584888458252000000000f, 1.1661452054977417000000000f, 1.1622039079666138000000000f, 1.1582344770431519000000000f, 1.1542372703552246000000000f, 1.1502121686935425000000000f, 1.1461594104766846000000000f, 1.1420789957046509000000000f, 1.1379710435867310000000000f, + 1.1338357925415039000000000f, 1.1296731233596802000000000f, 1.1254831552505493000000000f, 1.1212662458419800000000000f, 1.1170221567153931000000000f, 1.1127512454986572000000000f, 1.1084535121917725000000000f, 1.1041289567947388000000000f, 1.0997780561447144000000000f, 1.0954004526138306000000000f, + 1.0909965038299561000000000f, 1.0865662097930908000000000f, 1.0821098089218140000000000f, 1.0776273012161255000000000f, 1.0731188058853149000000000f, 1.0685844421386719000000000f, 1.0640244483947754000000000f, 1.0594387054443359000000000f, 1.0548274517059326000000000f, 1.0501908063888550000000000f, + 1.0455288887023926000000000f, 1.0408416986465454000000000f, 1.0361294746398926000000000f, 1.0313922166824341000000000f, 1.0266302824020386000000000f, 1.0218434333801270000000000f, 1.0170320272445679000000000f, 1.0121960639953613000000000f, 1.0073357820510864000000000f, 1.0024513006210327000000000f, + 0.9975425004959106400000000f, 0.9926097393035888700000000f, 0.9876530170440673800000000f, 0.9826725125312805200000000f, 0.9776684045791626000000000f, 0.9726406335830688500000000f, 0.9675894975662231400000000f, 0.9625149965286254900000000f, 0.9574173688888549800000000f, 0.9522966146469116200000000f, + 0.9471529126167297400000000f, 0.9419864416122436500000000f, 0.9367972612380981400000000f, 0.9315854907035827600000000f, 0.9263512492179870600000000f, 0.9210947155952453600000000f, 0.9158159494400024400000000f, 0.9105151891708374000000000f, 0.9051924347877502400000000f, 0.8998478651046752900000000f, + 0.8944816589355468800000000f, 0.8890938758850097700000000f, 0.8836846351623535200000000f, 0.8782541155815124500000000f, 0.8728024363517761200000000f, 0.8673297166824340800000000f, 0.8618361353874206500000000f, 0.8563218116760253900000000f, 0.8507867455482482900000000f, 0.8452312946319580100000000f, + 0.8396554589271545400000000f, 0.8340593576431274400000000f, 0.8284431099891662600000000f, 0.8228070139884948700000000f, 0.8171509504318237300000000f, 0.8114752769470214800000000f, 0.8057801127433776900000000f, 0.8000654578208923300000000f, 0.7943315505981445300000000f, 0.7885785102844238300000000f, + 0.7828064560890197800000000f, 0.7770155668258667000000000f, 0.7712058424949646000000000f, 0.7653776407241821300000000f, 0.7595309019088745100000000f, 0.7536660432815551800000000f, 0.7477828264236450200000000f, 0.7418816685676574700000000f, 0.7359626293182373000000000f, 0.7300259470939636200000000f, + 0.7240716218948364300000000f, 0.7180998325347900400000000f, 0.7121106386184692400000000f, 0.7061043977737426800000000f, 0.7000811696052551300000000f, 0.6940410137176513700000000f, 0.6879841089248657200000000f, 0.6819106936454772900000000f, 0.6758208274841308600000000f, 0.6697146296501159700000000f, + 0.6635923385620117200000000f, 0.6574540734291076700000000f, 0.6512999534606933600000000f, 0.6451301574707031300000000f, 0.6389448046684265100000000f, 0.6327440142631530800000000f, 0.6265279650688171400000000f, 0.6202968955039978000000000f, 0.6140508651733398400000000f, 0.6077899932861328100000000f, + 0.6015145182609558100000000f, 0.5952244997024536100000000f, 0.5889201760292053200000000f, 0.5826016664505004900000000f, 0.5762690901756286600000000f, 0.5699226856231689500000000f, 0.5635625123977661100000000f, 0.5571887493133544900000000f, 0.5508015751838684100000000f, 0.5444011092185974100000000f, + 0.5379875302314758300000000f, 0.5315610170364379900000000f, 0.5251216888427734400000000f, 0.5186696648597717300000000f, 0.5122051835060119600000000f, 0.5057283639907836900000000f, 0.4992393255233764600000000f, 0.4927382767200470000000000f, 0.4862253665924072300000000f, 0.4797007441520690900000000f, + 0.4731644988059997600000000f, 0.4666169285774231000000000f, 0.4600581228733062700000000f, 0.4534881711006164600000000f, 0.4469073116779327400000000f, 0.4403156936168670700000000f, 0.4337134659290313700000000f, 0.4271008074283599900000000f, 0.4204778075218200700000000f, 0.4138446748256683300000000f, + 0.4072016179561615000000000f, 0.4005487561225891100000000f, 0.3938861787319183300000000f, 0.3872141540050506600000000f, 0.3805327713489532500000000f, 0.3738422691822052000000000f, 0.3671427369117736800000000f, 0.3604343533515930200000000f, 0.3537172675132751500000000f, 0.3469916582107543900000000f, + 0.3402577340602874800000000f, 0.3335155844688415500000000f, 0.3267653882503509500000000f, 0.3200073242187500000000000f, 0.3132415413856506300000000f, 0.3064682185649871800000000f, 0.2996875047683715800000000f, 0.2928995788097381600000000f, 0.2861045897006988500000000f, 0.2793027162551879900000000f, + 0.2724941074848175000000000f, 0.2656789422035217300000000f, 0.2588573694229126000000000f, 0.2520295381546020500000000f, 0.2451956570148468000000000f, 0.2383558601140976000000000f, 0.2315103262662887600000000f, 0.2246592044830322300000000f, 0.2178026735782623300000000f, 0.2109408974647522000000000f, + 0.2040740400552749600000000f, 0.1972022652626037600000000f, 0.1903257369995117200000000f, 0.1834446042776107800000000f, 0.1765590757131576500000000f, 0.1696692854166030900000000f, 0.1627754122018814100000000f, 0.1558776050806045500000000f, 0.1489760577678680400000000f, 0.1420709043741226200000000f, + 0.1351623386144638100000000f, 0.1282505095005035400000000f, 0.1213355958461761500000000f, 0.1144177615642547600000000f, 0.1074971556663513200000000f, 0.1005739644169807400000000f, 0.0936483591794967650000000f, 0.0867204889655113220000000f, 0.0797905325889587400000000f, 0.0728586539626121520000000f, + 0.0659250169992446900000000f, 0.0589897930622100830000000f, 0.0520531460642814640000000f, 0.0451152473688125610000000f, 0.0381762608885765080000000f, 0.0312363542616367340000000f, 0.0242956969887018200000000f, 0.0173544511198997500000000f, 0.0104127889499068260000000f, 0.0034708750899881124000000f +}; + +/* Synthesis windows for overlap-add */ +/* for (j=0 ; jfftlen ; j++) hs->olapWinSyn[j] = (float)sin(EVS_PI*((float)j+0.5f)/(float)(hs->fftlen); */ +const float olapWinSyn256[256] = +{ + 0.0061358846f, + 0.0184067299f, + 0.0306748032f, + 0.0429382569f, + 0.0551952443f, + 0.0674439196f, + 0.0796824380f, + 0.0919089565f, + 0.1041216339f, + 0.1163186309f, + 0.1284981108f, + 0.1406582393f, + 0.1527971853f, + 0.1649131205f, + 0.1770042204f, + 0.1890686641f, + 0.2011046348f, + 0.2131103199f, + 0.2250839114f, + 0.2370236060f, + 0.2489276057f, + 0.2607941179f, + 0.2726213554f, + 0.2844075372f, + 0.2961508882f, + 0.3078496400f, + 0.3195020308f, + 0.3311063058f, + 0.3426607173f, + 0.3541635254f, + 0.3656129978f, + 0.3770074102f, + 0.3883450467f, + 0.3996241998f, + 0.4108431711f, + 0.4220002708f, + 0.4330938189f, + 0.4441221446f, + 0.4550835871f, + 0.4659764958f, + 0.4767992301f, + 0.4875501601f, + 0.4982276670f, + 0.5088301425f, + 0.5193559902f, + 0.5298036247f, + 0.5401714727f, + 0.5504579729f, + 0.5606615762f, + 0.5707807459f, + 0.5808139581f, + 0.5907597019f, + 0.6006164794f, + 0.6103828063f, + 0.6200572118f, + 0.6296382389f, + 0.6391244449f, + 0.6485144010f, + 0.6578066933f, + 0.6669999223f, + 0.6760927036f, + 0.6850836678f, + 0.6939714609f, + 0.7027547445f, + 0.7114321957f, + 0.7200025080f, + 0.7284643904f, + 0.7368165689f, + 0.7450577854f, + 0.7531867990f, + 0.7612023855f, + 0.7691033376f, + 0.7768884657f, + 0.7845565972f, + 0.7921065773f, + 0.7995372691f, + 0.8068475535f, + 0.8140363297f, + 0.8211025150f, + 0.8280450453f, + 0.8348628750f, + 0.8415549774f, + 0.8481203448f, + 0.8545579884f, + 0.8608669386f, + 0.8670462455f, + 0.8730949784f, + 0.8790122264f, + 0.8847970984f, + 0.8904487232f, + 0.8959662498f, + 0.9013488470f, + 0.9065957045f, + 0.9117060320f, + 0.9166790599f, + 0.9215140393f, + 0.9262102421f, + 0.9307669611f, + 0.9351835099f, + 0.9394592236f, + 0.9435934582f, + 0.9475855910f, + 0.9514350210f, + 0.9551411683f, + 0.9587034749f, + 0.9621214043f, + 0.9653944417f, + 0.9685220943f, + 0.9715038910f, + 0.9743393828f, + 0.9770281427f, + 0.9795697657f, + 0.9819638691f, + 0.9842100924f, + 0.9863080972f, + 0.9882575677f, + 0.9900582103f, + 0.9917097537f, + 0.9932119492f, + 0.9945645707f, + 0.9957674145f, + 0.9968202993f, + 0.9977230666f, + 0.9984755806f, + 0.9990777278f, + 0.9995294175f, + 0.9998305818f, + 0.9999811753f, + 0.9999811753f, + 0.9998305818f, + 0.9995294175f, + 0.9990777278f, + 0.9984755806f, + 0.9977230666f, + 0.9968202993f, + 0.9957674145f, + 0.9945645707f, + 0.9932119492f, + 0.9917097537f, + 0.9900582103f, + 0.9882575677f, + 0.9863080972f, + 0.9842100924f, + 0.9819638691f, + 0.9795697657f, + 0.9770281427f, + 0.9743393828f, + 0.9715038910f, + 0.9685220943f, + 0.9653944417f, + 0.9621214043f, + 0.9587034749f, + 0.9551411683f, + 0.9514350210f, + 0.9475855910f, + 0.9435934582f, + 0.9394592236f, + 0.9351835099f, + 0.9307669611f, + 0.9262102421f, + 0.9215140393f, + 0.9166790599f, + 0.9117060320f, + 0.9065957045f, + 0.9013488470f, + 0.8959662498f, + 0.8904487232f, + 0.8847970984f, + 0.8790122264f, + 0.8730949784f, + 0.8670462455f, + 0.8608669386f, + 0.8545579884f, + 0.8481203448f, + 0.8415549774f, + 0.8348628750f, + 0.8280450453f, + 0.8211025150f, + 0.8140363297f, + 0.8068475535f, + 0.7995372691f, + 0.7921065773f, + 0.7845565972f, + 0.7768884657f, + 0.7691033376f, + 0.7612023855f, + 0.7531867990f, + 0.7450577854f, + 0.7368165689f, + 0.7284643904f, + 0.7200025080f, + 0.7114321957f, + 0.7027547445f, + 0.6939714609f, + 0.6850836678f, + 0.6760927036f, + 0.6669999223f, + 0.6578066933f, + 0.6485144010f, + 0.6391244449f, + 0.6296382389f, + 0.6200572118f, + 0.6103828063f, + 0.6006164794f, + 0.5907597019f, + 0.5808139581f, + 0.5707807459f, + 0.5606615762f, + 0.5504579729f, + 0.5401714727f, + 0.5298036247f, + 0.5193559902f, + 0.5088301425f, + 0.4982276670f, + 0.4875501601f, + 0.4767992301f, + 0.4659764958f, + 0.4550835871f, + 0.4441221446f, + 0.4330938189f, + 0.4220002708f, + 0.4108431711f, + 0.3996241998f, + 0.3883450467f, + 0.3770074102f, + 0.3656129978f, + 0.3541635254f, + 0.3426607173f, + 0.3311063058f, + 0.3195020308f, + 0.3078496400f, + 0.2961508882f, + 0.2844075372f, + 0.2726213554f, + 0.2607941179f, + 0.2489276057f, + 0.2370236060f, + 0.2250839114f, + 0.2131103199f, + 0.2011046348f, + 0.1890686641f, + 0.1770042204f, + 0.1649131205f, + 0.1527971853f, + 0.1406582393f, + 0.1284981108f, + 0.1163186309f, + 0.1041216339f, + 0.0919089565f, + 0.0796824380f, + 0.0674439196f, + 0.0551952443f, + 0.0429382569f, + 0.0306748032f, + 0.0184067299f, + 0.0061358846f +}; +const float olapWinSyn320[320] = +{ + 0.0049087191000580788000000f, 0.0147256832569837570000000f, 0.0245412290096282960000000f, 0.0343544110655784610000000f, 0.0441642776131629940000000f, 0.0539698898792266850000000f, 0.0637703016400337220000000f, 0.0735645666718482970000000f, 0.0833517387509346010000000f, 0.0931308791041374210000000f, + 0.1029010415077209500000000f, 0.1126612871885299700000000f, 0.1224106773734092700000000f, 0.1321482658386230500000000f, 0.1418731212615966800000000f, 0.1515842974185943600000000f, 0.1612808704376220700000000f, 0.1709618866443634000000000f, 0.1806264370679855300000000f, 0.1902735829353332500000000f, + 0.1999023705720901500000000f, 0.2095119059085845900000000f, 0.2191012501716613800000000f, 0.2286694645881652800000000f, 0.2382156550884246800000000f, 0.2477388679981231700000000f, 0.2572382092475891100000000f, 0.2667127549648284900000000f, 0.2761616110801696800000000f, 0.2855838239192962600000000f, + 0.2949785292148590100000000f, 0.3043448030948638900000000f, 0.3136817514896392800000000f, 0.3229884505271911600000000f, 0.3322640359401702900000000f, 0.3415075838565826400000000f, 0.3507182002067565900000000f, 0.3598950505256652800000000f, 0.3690371811389923100000000f, 0.3781437575817108200000000f, + 0.3872138857841491700000000f, 0.3962467014789581300000000f, 0.4052413105964660600000000f, 0.4141968786716461200000000f, 0.4231125116348266600000000f, 0.4319873750209808300000000f, 0.4408206045627594000000000f, 0.4496113359928131100000000f, 0.4583587348461151100000000f, 0.4670619666576385500000000f, + 0.4757201671600341800000000f, 0.4843325316905975300000000f, 0.4928981959819793700000000f, 0.5014163851737976100000000f, 0.5098862051963806200000000f, 0.5183069109916687000000000f, 0.5266776680946350100000000f, 0.5349976420402526900000000f, 0.5432660579681396500000000f, 0.5514820814132690400000000f, + 0.5596449971199035600000000f, 0.5677539706230163600000000f, 0.5758082270622253400000000f, 0.5838069319725036600000000f, 0.5917494297027587900000000f, 0.5996348857879638700000000f, 0.6074625253677368200000000f, 0.6152316331863403300000000f, 0.6229414343833923300000000f, 0.6305911540985107400000000f, + 0.6381801366806030300000000f, 0.6457076072692871100000000f, 0.6531728506088256800000000f, 0.6605751514434814500000000f, 0.6679137349128723100000000f, 0.6751880049705505400000000f, 0.6823971867561340300000000f, 0.6895405650138855000000000f, 0.6966174840927124000000000f, 0.7036272883415222200000000f, + 0.7105692625045776400000000f, 0.7174427509307861300000000f, 0.7242470979690551800000000f, 0.7309816479682922400000000f, 0.7376457452774047900000000f, 0.7442387342453002900000000f, 0.7507599592208862300000000f, 0.7572088837623596200000000f, 0.7635847926139831500000000f, 0.7698870897293090800000000f, + 0.7761152386665344200000000f, 0.7822685241699218800000000f, 0.7883464694023132300000000f, 0.7943483591079711900000000f, 0.8002737760543823200000000f, 0.8061220049858093300000000f, 0.8118925094604492200000000f, 0.8175848126411438000000000f, 0.8231983184814453100000000f, 0.8287324905395507800000000f, + 0.8341867327690124500000000f, 0.8395606279373168900000000f, 0.8448535799980163600000000f, 0.8500651121139526400000000f, 0.8551946878433227500000000f, 0.8602418899536132800000000f, 0.8652061223983764600000000f, 0.8700870275497436500000000f, 0.8748840093612670900000000f, 0.8795967102050781300000000f, + 0.8842245936393737800000000f, 0.8887673020362854000000000f, 0.8932242989540100100000000f, 0.8975952267646789600000000f, 0.9018796682357788100000000f, 0.9060771465301513700000000f, 0.9101873040199279800000000f, 0.9142097830772399900000000f, 0.9181441068649292000000000f, 0.9219899177551269500000000f, + 0.9257469177246093800000000f, 0.9294146299362182600000000f, 0.9329928159713745100000000f, 0.9364810585975647000000000f, 0.9398790597915649400000000f, 0.9431864023208618200000000f, 0.9464029073715210000000000f, 0.9495282173156738300000000f, 0.9525619745254516600000000f, 0.9555038809776306200000000f, + 0.9583537578582763700000000f, 0.9611112475395202600000000f, 0.9637760519981384300000000f, 0.9663480520248413100000000f, 0.9688268303871154800000000f, 0.9712122678756713900000000f, 0.9735041260719299300000000f, 0.9757021665573120100000000f, 0.9778060913085937500000000f, 0.9798158407211303700000000f, + 0.9817311167716980000000000f, 0.9835518002510070800000000f, 0.9852776527404785200000000f, 0.9869085550308227500000000f, 0.9884443283081054700000000f, 0.9898848533630371100000000f, 0.9912299513816833500000000f, 0.9924795627593994100000000f, 0.9936334490776062000000000f, 0.9946916103363037100000000f, + 0.9956538677215576200000000f, 0.9965202212333679200000000f, 0.9972904324531555200000000f, 0.9979646205902099600000000f, 0.9985425472259521500000000f, 0.9990242719650268600000000f, 0.9994097352027893100000000f, 0.9996988177299499500000000f, 0.9998915791511535600000000f, 0.9999879598617553700000000f, + 0.9999879598617553700000000f, 0.9998915791511535600000000f, 0.9996988177299499500000000f, 0.9994097352027893100000000f, 0.9990242719650268600000000f, 0.9985425472259521500000000f, 0.9979646205902099600000000f, 0.9972904324531555200000000f, 0.9965201616287231400000000f, 0.9956538677215576200000000f, + 0.9946916103363037100000000f, 0.9936334490776062000000000f, 0.9924795031547546400000000f, 0.9912299513816833500000000f, 0.9898848533630371100000000f, 0.9884443283081054700000000f, 0.9869085550308227500000000f, 0.9852776527404785200000000f, 0.9835517406463623000000000f, 0.9817311167716980000000000f, + 0.9798157811164856000000000f, 0.9778060913085937500000000f, 0.9757021069526672400000000f, 0.9735041260719299300000000f, 0.9712122678756713900000000f, 0.9688268303871154800000000f, 0.9663479924201965300000000f, 0.9637760519981384300000000f, 0.9611111879348754900000000f, 0.9583536982536315900000000f, + 0.9555038809776306200000000f, 0.9525619149208068800000000f, 0.9495281577110290500000000f, 0.9464029073715210000000000f, 0.9431864023208618200000000f, 0.9398790001869201700000000f, 0.9364809989929199200000000f, 0.9329927563667297400000000f, 0.9294146299362182600000000f, 0.9257468581199646000000000f, + 0.9219899177551269500000000f, 0.9181440472602844200000000f, 0.9142097234725952100000000f, 0.9101873040199279800000000f, 0.9060771465301513700000000f, 0.9018796086311340300000000f, 0.8975952267646789600000000f, 0.8932242989540100100000000f, 0.8887672424316406300000000f, 0.8842245936393737800000000f, + 0.8795966506004333500000000f, 0.8748839497566223100000000f, 0.8700869679450988800000000f, 0.8652060627937316900000000f, 0.8602418303489685100000000f, 0.8551946878433227500000000f, 0.8500650525093078600000000f, 0.8448535203933715800000000f, 0.8395605683326721200000000f, 0.8341866731643676800000000f, + 0.8287324309349060100000000f, 0.8231982588768005400000000f, 0.8175847530364990200000000f, 0.8118925094604492200000000f, 0.8061219453811645500000000f, 0.8002737164497375500000000f, 0.7943482995033264200000000f, 0.7883464097976684600000000f, 0.7822684645652771000000000f, 0.7761151790618896500000000f, + 0.7698870301246643100000000f, 0.7635847330093383800000000f, 0.7572088241577148400000000f, 0.7507598996162414600000000f, 0.7442386746406555200000000f, 0.7376456856727600100000000f, 0.7309815883636474600000000f, 0.7242470383644104000000000f, 0.7174426913261413600000000f, 0.7105692028999328600000000f, + 0.7036272287368774400000000f, 0.6966174244880676300000000f, 0.6895405054092407200000000f, 0.6823971271514892600000000f, 0.6751879453659057600000000f, 0.6679136753082275400000000f, 0.6605750918388366700000000f, 0.6531727910041809100000000f, 0.6457075476646423300000000f, 0.6381800770759582500000000f, + 0.6305910944938659700000000f, 0.6229413151741027800000000f, 0.6152315139770507800000000f, 0.6074624657630920400000000f, 0.5996347665786743200000000f, 0.5917493700981140100000000f, 0.5838068723678588900000000f, 0.5758081078529357900000000f, 0.5677539110183715800000000f, 0.5596449375152587900000000f, + 0.5514820218086242700000000f, 0.5432659983634948700000000f, 0.5349975824356079100000000f, 0.5266776084899902300000000f, 0.5183068513870239300000000f, 0.5098861455917358400000000f, 0.5014163255691528300000000f, 0.4928981363773345900000000f, 0.4843324422836303700000000f, 0.4757201075553894000000000f, + 0.4670618772506713900000000f, 0.4583586752414703400000000f, 0.4496112763881683300000000f, 0.4408205151557922400000000f, 0.4319873154163360600000000f, 0.4231124520301818800000000f, 0.4141968190670013400000000f, 0.4052412509918212900000000f, 0.3962466120719909700000000f, 0.3872138261795043900000000f, + 0.3781436979770660400000000f, 0.3690371215343475300000000f, 0.3598949611186981200000000f, 0.3507181406021118200000000f, 0.3415074944496154800000000f, 0.3322639465332031300000000f, 0.3229883611202240000000000f, 0.3136816620826721200000000f, 0.3043447136878967300000000f, 0.2949784696102142300000000f, + 0.2855837643146514900000000f, 0.2761615216732025100000000f, 0.2667126953601837200000000f, 0.2572381198406219500000000f, 0.2477387785911560100000000f, 0.2382155656814575200000000f, 0.2286693751811981200000000f, 0.2191011607646942100000000f, 0.2095118165016174300000000f, 0.1999022960662841800000000f, + 0.1902734935283660900000000f, 0.1806263476610183700000000f, 0.1709618121385574300000000f, 0.1612807810306549100000000f, 0.1515842080116272000000000f, 0.1418730318546295200000000f, 0.1321481764316558800000000f, 0.1224105954170227100000000f, 0.1126612052321434000000000f, 0.1029009595513343800000000f, + 0.0931307896971702580000000f, 0.0833516493439674380000000f, 0.0735644772648811340000000f, 0.0637702122330665590000000f, 0.0539698041975498200000000f, 0.0441641919314861300000000f, 0.0343543216586112980000000f, 0.0245411414653062820000000f, 0.0147255966439843180000000f, 0.0049086315557360649000000f +}; + + +/*-------------------------------------------------------------------* + * AMR-WB ISF codebook - common 1st stage for 46bit and 36bit codebooks, + * 2 splits + * + * codebook vector dimension number of vectors + * ~~~~~~~~ ~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~ + * 1_1 9 256 + * 1_2 7 256 + *-------------------------------------------------------------------*/ + +/*-------------------------------------------------------------------* + * 1nd stage, 1st split: ISF0 to ISF8 + *-------------------------------------------------------------------*/ + +const float dico1_isf[] = +{ + 226.1477f, 422.2338f, 404.4563f, 152.3442f, 1.2553f, -102.5648f, -77.5073f, -32.1403f, 14.9134f, + 6.9890f, -26.5711f, -4.8001f, 122.2654f, 297.4533f, 158.0168f, 97.1963f, 43.4786f, -29.4927f, + 289.1461f, 493.4574f, 504.5048f, 393.1421f, 389.3840f, 397.8990f, 397.4072f, 381.0959f, 360.5083f, + -35.6482f, 323.0566f, 370.2882f, 252.9499f, 239.6172f, 209.0563f, 203.9713f, 191.4865f, 164.6219f, + 16.1026f, -17.1264f, -109.6817f, -184.2085f, 254.5133f, 208.7087f, 75.3774f, 52.8718f, -35.2364f, + 15.8336f, -47.0775f, -139.1713f, -23.5561f, 259.0049f, 120.0214f, 23.8825f, -18.5948f, -134.3813f, + 217.4017f, 369.5988f, 409.6801f, 338.5433f, 330.4056f, 386.7012f, 434.5276f, 492.7760f, 484.6164f, + -46.1429f, -79.6218f, 128.1106f, 199.9543f, 339.7710f, 309.8338f, 238.4430f, 156.8895f, 72.7742f, + 61.1308f, 114.6106f, 28.7939f, -131.9070f, -185.5015f, -350.3943f, -232.0556f, -62.9803f, -194.0513f, + 88.2757f, 51.2294f, -53.9555f, 120.0698f, 65.9863f, -105.8813f, -64.0929f, -151.0651f, -243.7652f, + 24.1201f, -12.6302f, -23.7808f, -98.2577f, -211.1396f, -323.5447f, -401.0499f, -204.4768f, -258.4671f, + 39.7202f, -23.9607f, 55.2442f, 43.6804f, -105.4100f, -97.8749f, -211.3002f, 9.7097f, -58.7138f, + 2.1766f, -51.7480f, -138.9340f, -268.1601f, -37.5098f, -125.8675f, -203.7929f, -12.2603f, -127.2472f, + -14.0622f, -81.7822f, -203.4806f, -89.5766f, 119.8931f, -51.7010f, -2.1055f, -38.5536f, -149.8808f, + 23.6196f, -19.7370f, -92.7527f, -260.9933f, -380.1402f, -158.8319f, -276.5396f, -29.3644f, -67.0346f, + 10.0869f, -54.0238f, -104.0772f, 43.4993f, -118.0066f, 16.7674f, -108.4172f, -138.9907f, -140.3299f, + 222.5364f, 321.1411f, 193.8368f, -60.0340f, -121.7460f, -35.9078f, 53.6514f, 109.0639f, 145.0366f, + -57.1173f, 143.6362f, 159.6491f, 26.6189f, 2.3305f, 30.0608f, 65.3329f, 78.8683f, 63.4622f, + 247.1436f, 350.7171f, 389.0685f, 295.2953f, 258.6614f, 266.7955f, 305.9202f, 355.1905f, 389.1698f, + -40.0882f, 114.6876f, 237.0104f, 161.9769f, 188.5636f, 180.3751f, 187.4189f, 168.3521f, 159.5175f, + -46.7654f, -132.1011f, -238.9261f, -204.8685f, 228.1911f, 129.1599f, 36.0960f, 169.1651f, 107.7902f, + -69.5087f, -114.5055f, -60.0494f, -15.9078f, 105.1520f, 39.1060f, -3.6140f, 83.1345f, 62.4498f, + 324.4036f, 287.6214f, 108.7328f, 320.4871f, 489.7306f, 267.9902f, 278.2168f, 405.7287f, 184.7344f, + -85.2571f, -118.8197f, 180.9905f, 177.4239f, 154.8864f, 106.5995f, 78.7528f, 111.5907f, 106.4840f, + -90.5891f, 2.5823f, 2.5231f, -151.4854f, -184.4761f, -166.9757f, -147.6148f, -65.2055f, -39.1239f, + -114.9974f, -71.3698f, 52.3087f, -18.1814f, 39.4264f, -34.2483f, -32.8691f, -45.8165f, -1.2029f, + 22.1063f, 6.7469f, -79.0146f, -247.7831f, -386.2835f, -437.2287f, -208.2931f, 68.6375f, -14.1447f, + 46.7840f, -11.0692f, 9.1612f, 43.4278f, -124.5574f, 124.1172f, -8.5368f, -30.1898f, 103.7909f, + -105.9007f, -181.3862f, -169.7189f, -257.0920f, -250.0032f, -150.2815f, -150.4918f, -38.5650f, -26.7658f, + -77.3138f, -101.1008f, -103.9903f, -17.1337f, -15.2577f, -54.2134f, -53.5373f, 66.9219f, 25.6872f, + 3.6265f, -56.7222f, -147.2143f, -330.5455f, -390.5518f, -43.3139f, -126.9112f, 133.5488f, 52.7399f, + -31.5816f, -111.6706f, -148.4743f, 75.1588f, -22.0969f, 119.9764f, 29.6891f, -9.5309f, -54.7378f, + 264.5383f, 274.1302f, 96.5690f, 21.7008f, 97.2691f, 55.1255f, -40.9705f, -92.2272f, -38.6482f, + 13.8969f, -15.1538f, -27.1357f, 135.8413f, 77.4989f, -36.1739f, 125.8114f, 35.5744f, -28.2436f, + 196.2991f, 345.8166f, 588.9347f, 510.5197f, 500.8432f, 457.6244f, 436.9384f, 472.1788f, 414.4815f, + 162.4519f, 280.7038f, 386.4482f, 479.3623f, 390.8287f, 411.1292f, 372.5701f, 289.3485f, 407.8594f, + -49.5343f, -147.0080f, -256.8338f, 54.1618f, 243.5530f, 87.1110f, 195.7264f, 119.5070f, 85.9479f, + -43.9641f, -150.1866f, -310.9041f, 196.7455f, 171.2780f, 33.0834f, 83.3645f, -32.4579f, -75.7126f, + 228.4330f, 442.3277f, 481.6548f, 426.3000f, 487.1132f, 559.8019f, 590.4699f, 565.5949f, 513.3911f, + -68.0544f, -164.7799f, 2.8141f, 451.2739f, 425.3554f, 461.7245f, 391.6532f, 369.1004f, 314.9413f, + 3.2743f, -49.3561f, -123.9568f, -40.1754f, -137.2377f, -271.6588f, -38.4305f, -104.5226f, -209.8071f, + 12.8092f, -40.2922f, -113.2953f, 65.4057f, -15.2443f, -159.0118f, 17.0998f, -81.3044f, -146.3446f, + 40.4305f, -8.9102f, -24.9719f, -113.7701f, -248.7160f, -332.5068f, -423.4328f, -23.8073f, -43.9266f, + -29.4866f, -119.6504f, -169.5775f, 85.2585f, -57.7724f, -138.3062f, -265.4940f, -52.0935f, -84.4635f, + -47.3285f, -147.4516f, -280.5169f, -38.0164f, -50.7237f, -141.1316f, -60.9737f, -147.8608f, -233.9212f, + -22.0146f, -99.1479f, -228.8716f, 91.6618f, 61.1343f, -83.5247f, 4.2834f, -101.7035f, -58.0283f, + -48.6094f, -104.2664f, -155.2664f, -226.4858f, -231.7223f, -205.7180f, -314.6280f, -150.3995f, 135.1819f, + -75.2552f, -171.9896f, -276.5969f, -137.0060f, -55.2086f, -99.5797f, -195.1097f, -57.2647f, -72.3255f, + 174.9245f, 258.0028f, 192.8297f, 81.3562f, 198.8450f, 180.2081f, 132.0824f, 113.5126f, 58.1412f, + -87.2559f, 34.2946f, 130.7081f, 62.1078f, 82.7816f, 74.4854f, 111.6818f, 120.3099f, 80.1334f, + -11.9671f, 183.3834f, 313.7754f, 257.2813f, 241.7612f, 256.9710f, 329.4492f, 385.5374f, 434.7875f, + -66.8195f, -94.6890f, 200.6887f, 141.3063f, 115.2635f, 204.7280f, 215.7973f, 270.9673f, 228.4647f, + -24.9070f, -120.1441f, -175.1481f, -8.0896f, 110.9215f, 307.0280f, 174.2457f, 112.7169f, 35.9639f, + -85.1717f, -152.2496f, -2.5803f, 66.0904f, 80.5138f, 128.8919f, 137.5303f, 159.4245f, 139.7766f, + -14.1396f, 274.4125f, 374.6268f, 335.3957f, 336.4666f, 435.5791f, 495.5083f, 529.9642f, 509.9389f, + -51.7794f, -133.3125f, -25.4473f, 264.8054f, 162.9175f, 171.9332f, 189.6735f, 202.1561f, 304.5228f, + 12.7820f, -17.2653f, -74.5083f, -134.5510f, -180.1133f, -294.9349f, -78.6120f, 84.8225f, -12.0772f, + -137.7282f, -213.7303f, -17.3509f, 48.2225f, -23.9524f, -26.4293f, -30.7054f, 11.1575f, 23.4229f, + 28.3886f, -22.3550f, -158.4269f, -299.3692f, -485.7126f, -469.8884f, 93.8213f, 156.3351f, 64.4156f, + -28.7029f, -110.1881f, -234.8032f, -83.3735f, -66.7772f, -146.3531f, 129.8178f, 13.7979f, -40.1959f, + -11.2220f, -81.0542f, -215.8795f, -186.0052f, -249.1487f, -354.7951f, 67.0249f, -8.7287f, -52.7080f, + -75.1895f, -93.5102f, -63.8842f, -40.2971f, -43.3423f, -18.3122f, 59.9384f, 48.9469f, 42.9198f, + -0.3036f, -79.3921f, -222.4614f, -402.4193f, -556.4007f, -208.9512f, 60.4822f, 0.2592f, 57.2596f, + -130.2469f, -254.9911f, -337.7263f, -76.9102f, -61.5888f, -8.3782f, -17.2822f, 37.1637f, 42.0772f, + 151.9460f, 229.6417f, 191.5279f, 12.9809f, -92.7110f, -204.7091f, -245.2630f, -53.2589f, -101.3680f, + 15.8084f, -69.0148f, -180.2926f, 176.9411f, 336.6405f, 148.3504f, 51.2260f, -50.6708f, -158.2893f, + 328.7315f, 655.2856f, 719.0299f, 605.1412f, 575.6907f, 490.5742f, 422.8277f, 353.4364f, 289.8675f, + 144.5240f, 474.8398f, 690.7612f, 638.0545f, 473.3627f, 248.6244f, 8.4810f, -128.9032f, 27.8837f, + -29.8052f, -109.6768f, -289.4402f, -289.9344f, 350.9098f, 241.8981f, 108.0220f, 27.7568f, -86.8368f, + -12.5998f, -103.5273f, -217.2510f, -9.8401f, 388.4400f, 266.5437f, 118.9818f, 49.1643f, -64.3603f, + 28.5445f, 288.4229f, 348.8730f, 378.0052f, 387.8595f, 690.6161f, 887.8799f, 718.7092f, 543.2699f, + -27.0127f, -136.3472f, -228.6534f, 91.4073f, 452.4637f, 352.8853f, 244.5759f, 199.3164f, 97.9452f, + -0.2574f, -38.8124f, -106.0784f, -81.9691f, -235.3859f, -136.9961f, -210.8024f, -316.9619f, -149.7671f, + -6.3268f, -89.9384f, -197.0412f, 160.1820f, 58.3899f, -80.1867f, -134.0614f, -254.4108f, -249.4793f, + 40.1439f, -3.4822f, -88.7857f, -80.2522f, -219.3521f, -305.1500f, -421.5967f, -471.9935f, -60.7522f, + 55.8529f, 24.5260f, -52.9174f, -26.1113f, -123.8744f, -235.0002f, -306.0707f, -450.7246f, -249.8812f, + -56.2297f, -152.7118f, -263.1169f, -243.0294f, -78.2260f, -99.3225f, -257.7953f, -369.9445f, -154.2971f, + -15.4570f, -97.8124f, -244.1879f, 10.4628f, 212.1971f, 36.6411f, -51.0200f, -150.9477f, -262.8206f, + -47.9169f, -145.0780f, -295.8412f, -176.3119f, -220.4176f, -239.8767f, -162.2583f, -277.5646f, -13.5098f, + -45.4312f, -120.7871f, -231.7391f, -104.6837f, 93.3399f, -13.0435f, -131.8873f, -253.9684f, -52.8010f, + 36.7261f, 97.8902f, 216.2452f, 22.2667f, -121.9688f, -165.2371f, -60.1795f, -22.1111f, 91.7368f, + -104.8126f, -27.6777f, 148.6412f, 44.3956f, -17.0786f, -34.0943f, 48.6552f, 67.5896f, 52.1341f, + 590.8627f, 669.3461f, 483.5975f, 208.4471f, 107.7190f, 123.1392f, 179.9797f, 179.2124f, 198.5541f, + -51.3512f, -7.3050f, 448.6575f, 261.8456f, 189.7417f, 139.0593f, 120.8041f, 144.0752f, 115.5179f, + -87.2434f, -195.6786f, -351.1762f, -282.1990f, -27.3961f, 2.1866f, 51.0065f, 120.9792f, 154.0704f, + -38.7878f, -118.5436f, -201.9035f, 97.1421f, 24.9785f, -20.8748f, 52.5830f, -4.3230f, 177.0334f, + -57.4864f, -155.8205f, -285.0674f, -156.5139f, 319.0307f, 288.4199f, 313.3522f, 292.7644f, 224.7193f, + -60.1766f, -170.1086f, -288.5482f, 312.6666f, 231.6275f, 142.7810f, 206.6260f, 124.0985f, 127.5073f, + -87.3474f, 17.7221f, -15.2086f, -151.2513f, -201.3116f, -202.2629f, -237.4979f, -150.1082f, -125.3288f, + -123.1549f, -147.2588f, 55.9560f, -39.6018f, -44.1818f, -147.1130f, -69.1241f, -56.1722f, -4.4924f, + 45.5201f, 15.5222f, -93.3382f, -254.1893f, -410.5618f, -226.8515f, -287.7839f, -386.6172f, -128.1340f, + 10.1233f, -19.6005f, -61.5127f, -8.8349f, -177.1218f, -110.5849f, -207.5041f, -213.2586f, 74.8075f, + -98.2741f, -195.7624f, -290.1091f, -230.1600f, -244.7515f, -194.7701f, -128.1076f, -46.1729f, -28.2903f, + -126.3800f, -193.1177f, -95.3231f, -119.6219f, -56.1586f, -69.0881f, -102.1922f, -52.5595f, -30.4027f, + -13.9604f, -91.5188f, -202.7529f, -375.3352f, -503.8488f, -122.5019f, -187.2047f, -144.9473f, -17.6464f, + -37.1158f, -113.9219f, -208.9531f, -3.1283f, -117.0010f, 43.6858f, -64.0984f, -108.2942f, 77.5131f, + -38.6401f, -49.9736f, 343.9084f, 326.3879f, 226.1680f, 136.9212f, 9.0736f, -37.1756f, -84.7974f, + -10.5004f, -100.6890f, 48.4106f, 394.7867f, 233.0419f, 165.9509f, 56.3291f, 2.7924f, -28.5845f, + 164.3221f, 505.0226f, 640.4844f, 633.9930f, 680.5828f, 631.7908f, 585.4574f, 501.5025f, 393.1295f, + -37.0300f, 293.6539f, 656.3401f, 612.9729f, 632.0821f, 560.9024f, 468.8401f, 382.9867f, 278.2211f, + -26.9959f, -117.0381f, -266.9459f, -169.9414f, 442.3678f, 351.1593f, 196.7216f, 129.6217f, 42.5401f, + -28.9160f, -126.1295f, -248.8180f, 219.9974f, 419.6462f, 237.5276f, 144.8018f, 41.0794f, -19.0438f, + -30.6524f, 324.5342f, 466.4269f, 433.6403f, 538.3355f, 578.5025f, 582.9940f, 533.2873f, 475.3817f, + -101.0867f, -47.3945f, 562.3863f, 521.2437f, 635.9947f, 581.9960f, 561.7294f, 477.7560f, 364.4759f, + -32.1078f, -119.5424f, -239.6324f, -86.9073f, -147.6602f, -263.4799f, -212.9377f, -261.9229f, -330.2635f, + 20.8260f, -48.5704f, -135.4246f, 164.8506f, 20.4817f, -48.8885f, -105.4348f, -206.6621f, 3.6375f, + 30.9311f, -34.7599f, -124.8998f, -258.7565f, -390.0532f, -468.4556f, -485.3543f, -264.1984f, -115.9895f, + -26.5921f, -106.6166f, -238.7686f, 53.4977f, -56.8913f, -155.1848f, -245.0791f, -329.9394f, -85.9503f, + -43.8040f, -135.2615f, -311.2635f, -322.8195f, 91.5184f, -51.5741f, -73.3097f, -108.7735f, -204.0501f, + -61.9589f, -158.0212f, -286.8211f, -163.7011f, 114.5577f, 29.0545f, -65.0919f, -65.1646f, 71.9506f, + -59.8760f, -170.6047f, -325.2270f, -421.8182f, -131.3054f, -184.2594f, -219.1312f, -132.9352f, -98.8301f, + -65.8626f, -165.1987f, -320.2537f, -353.1492f, -51.0331f, -7.3456f, -135.3074f, -235.8573f, 12.1485f, + 12.8460f, -11.9241f, 121.7405f, 24.2470f, -57.8971f, 19.1365f, -23.0243f, 220.3897f, 189.9156f, + -119.6102f, -129.9914f, 75.9549f, -17.3359f, 26.2798f, 28.0181f, 57.3185f, 79.8925f, 95.0199f, + -81.0524f, -19.0879f, 531.3251f, 384.0082f, 378.6000f, 387.1200f, 396.1896f, 433.4382f, 379.9696f, + -82.3204f, -67.1148f, 345.0646f, 244.9884f, 277.8043f, 263.1406f, 275.4622f, 311.7924f, 291.4141f, + -34.2889f, -127.1388f, -298.1820f, -380.4511f, 268.4245f, 354.6007f, 200.7670f, 149.3555f, 67.1469f, + -114.0830f, -239.0252f, -314.3921f, 24.6004f, 51.2722f, 105.4223f, 101.1157f, 137.3569f, 135.9245f, + -91.7432f, -32.7591f, 373.1560f, 319.3955f, 437.4347f, 503.4907f, 608.7997f, 578.2119f, 502.0230f, + -70.3367f, -179.9099f, -239.7652f, 256.5794f, 269.9891f, 291.1810f, 333.6932f, 305.8695f, 278.4421f, + -38.0671f, -120.8247f, -186.4547f, -239.7784f, -303.6527f, -286.7954f, -300.0361f, -205.3057f, -184.5087f, + -134.2125f, -185.9339f, -13.8119f, -65.8529f, 19.0133f, -30.1823f, -58.4970f, -93.5678f, -55.1841f, + -20.3990f, -104.7817f, -249.4716f, -358.9899f, -499.3363f, -434.6861f, -133.7299f, -130.1813f, -59.0671f, + -26.7201f, -94.4739f, -228.6340f, -28.5857f, -81.7289f, -186.7961f, -62.0135f, -167.5409f, 51.9732f, + -76.8652f, -194.8085f, -392.5224f, -495.1741f, -106.3757f, -87.6781f, -40.9442f, -25.9922f, 6.6919f, + -141.6526f, -241.2805f, -161.8672f, -45.4915f, -24.1067f, 7.6906f, 3.7741f, 45.2149f, 42.3436f, + -76.2028f, -185.3649f, -353.8127f, -492.3104f, -348.1328f, -172.4144f, -108.0814f, -55.5374f, -10.8210f, + -88.1331f, -202.9139f, -371.2243f, -273.3005f, -107.5773f, -103.9134f, -45.1607f, -40.9613f, 31.8985f, + 157.9412f, 199.7964f, 203.2689f, 127.6304f, 6.7547f, -75.7475f, -130.0489f, -209.2208f, -228.8015f, + -44.6527f, -50.6749f, 107.6295f, 92.4422f, 79.8121f, 133.5672f, 52.5620f, -6.2270f, -43.2877f, + 261.9115f, 472.0228f, 456.3473f, 335.7553f, 289.8814f, 234.7976f, 206.1187f, 157.4174f, 120.7698f, + 155.2229f, 242.6315f, 377.1642f, 293.6065f, 226.0318f, 155.2748f, 156.4116f, 128.6701f, 98.5061f, + 74.5256f, 70.1303f, -53.6869f, -182.3488f, 106.1648f, 41.5585f, -37.0232f, 6.5336f, -75.1722f, + -31.2252f, -113.3890f, -244.5892f, 75.8334f, 233.5228f, 76.5742f, 8.2886f, -109.6154f, 29.9907f, + 199.0678f, 337.3158f, 432.8418f, 315.2969f, 366.8018f, 352.4917f, 361.4405f, 280.1715f, 187.7336f, + 53.4911f, 143.3279f, 208.4704f, 298.2910f, 261.7387f, 149.2119f, 115.7060f, 59.9002f, 32.6898f, + 118.3519f, 194.3090f, 56.3174f, -33.3258f, -48.8783f, -210.5418f, -188.4141f, -181.0565f, -298.4099f, + 91.1937f, 135.5274f, 26.3852f, -57.5649f, 66.0117f, -82.2194f, -94.6889f, -88.3680f, -188.1230f, + 119.8292f, 164.8051f, 60.2985f, -68.4990f, -150.8028f, -282.2156f, -282.8785f, -353.0452f, -396.4856f, + 120.5806f, 120.4464f, 62.5068f, -23.5466f, -183.4260f, -164.0083f, -233.7240f, -309.0768f, -85.4341f, + 26.4925f, 47.3529f, -53.5415f, -218.9011f, -56.8672f, -174.1118f, -201.0902f, -193.1382f, -284.6390f, + 50.9597f, 20.8274f, -88.6445f, 17.8450f, 185.2710f, 12.4814f, -62.7698f, -74.9989f, -191.3486f, + 83.3881f, 63.9878f, -27.8680f, -181.7226f, -342.0545f, -62.8876f, -178.1327f, -229.1320f, -18.6240f, + 85.1419f, 45.8095f, 15.3667f, 69.0366f, -75.9137f, -34.4539f, -88.4330f, -163.4411f, 19.3370f, + 81.8880f, 213.5459f, 222.3313f, 109.1533f, 47.1884f, -17.2578f, -19.4486f, 3.7457f, -32.8905f, + 22.8266f, 54.6145f, 70.9314f, -2.0301f, 104.3592f, 45.7102f, 41.3375f, 82.5320f, 77.2795f, + 210.7176f, 326.3462f, 356.6618f, 280.9097f, 240.9705f, 212.4392f, 230.9905f, 220.8317f, 250.9306f, + 59.6089f, 218.2601f, 340.5622f, 179.8372f, 86.7106f, 42.1021f, 73.5578f, 70.2340f, 71.3620f, + 61.9071f, 46.6476f, 111.0709f, -59.8230f, -105.9862f, 89.4424f, 34.0065f, 42.7793f, -22.3657f, + -71.5290f, 31.9224f, 46.2106f, 8.2769f, 5.2717f, 15.6736f, 45.9446f, 74.5921f, 72.2933f, + 63.1228f, 347.0971f, 255.3817f, 42.2624f, -13.4026f, 95.4917f, 190.7911f, 219.1920f, 207.8866f, + 63.7817f, 21.7322f, 237.9311f, 133.1283f, 19.5484f, 128.6760f, 26.4302f, 103.7761f, 85.3130f, + 39.2312f, 80.2880f, 7.1932f, -118.9054f, -41.8213f, -170.3956f, -190.1681f, -25.3174f, -119.5246f, + -33.4058f, 60.1838f, 52.1765f, -11.5418f, -17.6690f, -28.5228f, -40.5342f, -31.3702f, -37.5340f, + 95.6257f, 128.8044f, 3.7503f, -171.8902f, -331.7014f, -422.7089f, 30.8156f, 15.6229f, -103.6316f, + 76.5623f, 145.2620f, 106.4321f, -70.8798f, -192.7731f, -152.0614f, 107.2952f, 31.2426f, -23.0299f, + 0.9016f, -4.6471f, -96.0447f, -197.1141f, -39.1036f, -170.4243f, 8.3031f, -73.0702f, -168.4342f, + -86.2673f, -18.7660f, 13.9540f, -105.8362f, -72.7468f, -57.3178f, -42.7630f, 10.3291f, 27.6536f, + 83.1109f, 54.8163f, 28.1776f, -137.0164f, -242.1605f, -32.9744f, -141.6118f, 26.8712f, 17.8517f, + 35.5325f, 65.1065f, -1.1122f, -37.2264f, -38.7638f, -41.0658f, -18.6295f, 44.3877f, 57.2718f, + 101.1713f, 97.2361f, 67.3819f, 236.9884f, 158.4350f, 20.2720f, 23.0851f, -73.7010f, -124.8067f, + 44.9800f, -33.1049f, -21.2276f, 224.2546f, 49.9567f, 88.2466f, -23.1899f, -98.6740f, 50.9732f, + -24.3959f, 403.6523f, 511.0127f, 404.3978f, 440.2577f, 428.9172f, 401.8223f, 375.5111f, 321.4924f, + 15.1345f, 142.1195f, 295.8327f, 367.1741f, 284.5674f, 257.7681f, 257.3533f, 227.7437f, 300.6506f, + -44.9562f, -131.9449f, -296.8129f, -184.1626f, 153.8183f, 14.5297f, 172.3343f, 69.5618f, 2.2208f, + -22.2475f, -119.2772f, -205.2499f, 310.9423f, 177.0844f, 73.5587f, -1.5010f, -44.3403f, 96.9000f, + 27.7742f, 173.5793f, 311.4776f, 285.5815f, 427.9854f, 452.0145f, 477.2097f, 401.7775f, 316.6574f, + 52.6696f, 140.2801f, 215.3995f, 166.1714f, 292.6204f, 318.2898f, 341.5682f, 274.8850f, 196.1860f, + 51.5561f, 96.4057f, -0.0610f, -80.6567f, -175.2689f, -292.8310f, -100.7723f, -200.9591f, -247.1591f, + 96.6859f, 97.0977f, 35.4401f, 47.1563f, -76.2811f, -194.8284f, -34.9894f, -110.1535f, -169.8929f, + 30.4654f, 7.6447f, -108.2569f, -243.2014f, -383.8708f, -478.0505f, -162.0353f, -178.7682f, -249.4727f, + 135.4580f, 198.9998f, 81.4247f, -69.9475f, -181.4226f, -284.4768f, -29.8270f, -92.7044f, -189.7940f, + -40.1188f, -133.9427f, -295.2091f, -278.5829f, -103.4496f, -237.8449f, -74.7856f, -155.3338f, -248.5054f, + -47.4470f, -149.6037f, -292.4242f, 221.6694f, 98.4280f, -14.0849f, -138.2963f, -163.0445f, -19.4243f, + 79.5896f, 39.1792f, -58.2936f, -253.9809f, -422.3516f, -18.3412f, -2.7302f, -102.9275f, 43.5500f, + -17.9005f, -70.1182f, -104.1536f, -126.4881f, -219.3935f, -153.8877f, -270.2488f, 155.3837f, 114.2388f, + 188.3484f, 261.8459f, 266.6991f, 243.5570f, 172.7795f, 64.3333f, 45.3547f, 14.1479f, -58.3812f, + 42.3610f, 96.6123f, 113.8369f, 96.5219f, 138.7232f, 47.5273f, 42.4855f, 87.4416f, 115.5724f, + -5.4013f, 368.9961f, 386.7844f, 312.8328f, 294.8554f, 318.4847f, 330.7657f, 356.5357f, 348.3268f, + 113.9440f, 136.1339f, 283.1776f, 188.4109f, 151.5282f, 128.5029f, 167.5631f, 242.2409f, 260.3565f, + -13.3113f, 76.9204f, 83.0527f, -49.6054f, 32.9182f, 193.1624f, 242.1413f, 224.6298f, 146.4784f, + 49.3300f, 80.8438f, 67.2940f, 65.3665f, 141.4567f, 78.9471f, 115.6802f, 154.3108f, 177.7814f, + -2.1684f, 97.5184f, 210.7061f, 182.4635f, 248.3353f, 312.9833f, 448.6478f, 502.5403f, 436.6044f, + 10.4934f, 93.6577f, 144.0456f, 109.2677f, 171.7553f, 160.5641f, 247.6292f, 348.4738f, 372.3836f, + 62.0393f, 66.4595f, -22.8432f, -154.2429f, -311.1715f, -269.7167f, 30.1724f, -82.4276f, -130.4250f, + -1.8658f, -10.8456f, -5.2486f, -28.7596f, -130.9176f, -235.6978f, 116.9998f, 34.2436f, -79.9885f, + 32.1393f, -12.8439f, -142.0784f, -272.6861f, -469.8031f, -450.3773f, 42.8701f, -56.9028f, -113.0164f, + 44.2438f, 0.5177f, -95.0709f, -229.7896f, -388.2228f, -193.8794f, 161.5550f, 62.3152f, 16.3412f, + -21.7573f, -96.5696f, -171.8374f, -270.5201f, -389.2275f, -187.1907f, 4.2880f, -69.4009f, -139.6222f, + -59.1336f, -137.9044f, -127.8821f, -82.4177f, -132.8951f, 55.2591f, 25.2046f, 165.8443f, 176.7896f, + 13.1713f, -65.9463f, -177.8707f, -363.8923f, -474.4700f, 53.7845f, 194.7626f, 99.8684f, 126.7437f, + 26.4565f, 54.2781f, -5.8084f, -213.5320f, -186.7453f, 6.5259f, 119.4530f, 196.2039f, 188.0246f, + -12.3442f, -52.3945f, 174.0135f, 50.5399f, -55.6784f, -95.2558f, -196.2955f, -198.2056f, -234.0973f, + 23.6446f, -54.5462f, -134.7219f, 193.6175f, 178.7128f, -0.9450f, 7.7510f, -88.8611f, -200.7396f, + 154.0881f, 689.2718f, 650.6971f, 522.8596f, 436.5025f, 314.9000f, 250.7824f, 187.1628f, 148.5410f, + 83.9959f, 202.8234f, 359.2843f, 411.3538f, 425.6817f, 308.8017f, 206.3666f, 113.2320f, 60.3929f, + -21.1689f, -91.1694f, -252.6742f, -235.0333f, 249.5398f, 114.6655f, -0.7796f, -65.2547f, -172.8182f, + -30.5567f, -123.2070f, -309.0227f, -44.0884f, 320.4634f, 157.6161f, 61.6828f, -45.3025f, -139.1032f, + 206.4974f, 723.0883f, 782.3015f, 479.5419f, 242.9557f, -15.8222f, -162.4184f, 134.4517f, 319.9661f, + -41.0232f, -148.1419f, -92.0839f, 478.0700f, 348.8458f, 292.6417f, 221.8808f, 139.1332f, 83.7320f, + -6.8324f, -77.6477f, -56.3444f, 19.3478f, -110.6184f, -96.5414f, -225.9007f, -330.6617f, -424.5623f, + 26.9337f, -4.4548f, -148.8763f, -80.3516f, 81.8311f, -110.8947f, -150.9911f, -162.4880f, -279.5481f, + 15.4135f, -1.8583f, -56.8319f, -146.1688f, -266.5346f, -355.1809f, -419.6793f, -456.7536f, -416.2208f, + 112.1756f, 88.2059f, 26.0259f, -86.2333f, -258.4741f, -66.9660f, -164.5662f, -250.9281f, -276.0475f, + -51.5026f, -135.9180f, -210.3467f, -175.0943f, -7.7200f, -1.5529f, -138.1960f, -292.0197f, -364.5311f, + 1.6098f, -29.3697f, -112.8375f, -233.4716f, 123.6812f, 20.4676f, -81.0632f, -116.0258f, -218.5294f, + -34.1878f, -103.0825f, -139.6876f, -229.9859f, -246.3806f, -96.8411f, -204.4168f, -321.0166f, -418.4522f, + 27.1891f, -2.9717f, 21.2254f, -122.5167f, -201.1399f, 36.0115f, -56.9192f, -106.8464f, -192.5580f, + 77.7097f, 24.2840f, 152.6398f, 61.5673f, -54.9359f, 27.7810f, -85.7347f, -79.4392f, -81.0366f, + 59.2315f, 15.7636f, 128.6461f, 63.2966f, -11.4618f, 18.7670f, -58.2229f, 42.0642f, 49.7434f, + 247.9855f, 413.3163f, 345.0402f, 192.3750f, 145.4847f, 121.6956f, 123.6805f, 107.2007f, 94.2462f, + 104.2558f, 282.0381f, 490.4723f, 344.7097f, 244.1310f, 96.7224f, 2.9896f, -31.7180f, -23.3323f, + -22.5118f, -53.8832f, -113.5013f, -234.2837f, -4.7630f, -0.8369f, -15.3972f, 57.4113f, 45.6486f, + -41.6155f, -134.7804f, -200.2841f, 179.2444f, 29.8214f, 36.0840f, -106.4028f, 151.5328f, 102.1621f, + 141.5078f, 201.5805f, 79.4698f, -159.8402f, -279.6548f, -324.4731f, -129.3751f, 72.2403f, 81.4769f, + -45.8403f, -152.7728f, -116.5580f, 262.2678f, 114.2470f, 210.0651f, 100.2266f, 64.9777f, -14.6634f, + -39.9272f, -124.8000f, -75.7294f, -110.6360f, -223.7299f, -102.2257f, -226.1053f, -85.4944f, -173.4764f, + -91.6640f, 30.6543f, 4.1065f, -65.4408f, -39.3890f, -89.5364f, -102.5911f, -125.5036f, -48.1974f, + 27.2660f, 19.3735f, -66.4810f, -233.9350f, -388.9383f, -229.7098f, -102.6715f, -201.6806f, -177.6036f, + 153.9685f, 141.8902f, 89.4281f, -53.1892f, -209.9941f, 8.0810f, -71.3509f, -135.8233f, -78.6157f, + -48.4004f, -143.6756f, -250.1705f, -343.5184f, -330.9693f, -81.7413f, -159.8642f, -192.9882f, -201.0525f, + -49.7401f, -133.3727f, -211.5154f, -166.0789f, -199.3352f, -4.0380f, -98.3591f, -184.6634f, -113.6087f, + 32.7128f, -26.7812f, -78.3951f, -264.0457f, -339.2219f, 40.1904f, -121.6728f, -51.6241f, -125.0696f, + 1.8568f, -67.7562f, -73.4413f, -115.9242f, -245.2522f, 77.1352f, -22.1839f, 2.7514f, -4.3203f, + 19.0296f, -62.4543f, 21.8088f, 217.8850f, 43.1886f, 12.7766f, -121.5772f, -171.9543f, -180.7850f, + -0.3986f, -96.1580f, -120.0616f, 336.5914f, 176.9306f, 54.3062f, -66.4501f, -138.8101f, -90.7495f, + 109.0295f, 377.1798f, 641.5853f, 577.4881f, 571.3625f, 438.8002f, 310.6432f, 204.9863f, 132.6160f, + -76.9013f, -15.0371f, 664.7503f, 520.0686f, 489.1051f, 371.2256f, 270.3431f, 196.9454f, 166.5973f, + -42.2498f, -134.3667f, -336.4376f, -457.6409f, 173.4562f, 138.1508f, 34.3921f, -18.1609f, -85.9677f, + -20.8727f, -125.4622f, -192.7956f, 434.5861f, 290.6413f, 142.0824f, 77.1623f, -13.2305f, -29.4274f, + 178.7104f, 373.0402f, 459.7581f, 474.3989f, 557.5211f, 569.2194f, 525.4768f, 358.3187f, 210.4229f, + -26.8194f, 77.7574f, 350.3222f, 445.4183f, 524.4524f, 462.1511f, 381.7293f, 289.9692f, 204.0649f, + 47.7632f, 17.1803f, -105.1057f, 10.4223f, -60.5128f, -219.3625f, -119.8198f, -230.6158f, -301.9153f, + 60.2078f, 16.2198f, -62.5382f, 98.4891f, -50.3729f, -119.2299f, -183.9794f, -286.1903f, -145.0719f, + 52.5866f, 72.1675f, -32.1273f, -162.5446f, -282.0867f, -356.6873f, -196.9938f, -290.2792f, -343.8752f, + 58.1756f, 83.5942f, -32.7989f, -128.5429f, -265.7008f, -326.2490f, -166.5130f, -258.2744f, -31.7978f, + -49.8436f, -148.3240f, -287.2763f, -389.7832f, -131.7967f, 6.5863f, -71.1640f, -182.3324f, -272.4139f, + -32.6407f, -113.2022f, -199.3120f, -231.3794f, 5.2103f, 172.0263f, 60.2526f, -14.7182f, -108.9096f, + 27.2077f, -23.7367f, -95.9858f, -283.8613f, -409.0134f, -31.3871f, -148.6489f, -208.9727f, -274.8275f, + 69.4333f, -0.7143f, -57.0494f, -261.8966f, -366.3107f, 188.4734f, 53.9671f, 24.5447f, 25.3948f, + -4.4283f, 5.6792f, 301.6043f, 172.8969f, 55.6507f, -7.7604f, -81.7609f, -49.2316f, -63.0654f, + -12.4033f, -97.3530f, 37.2340f, 215.5548f, 48.4286f, 11.6666f, -133.9813f, 32.1272f, -33.6059f, + 57.9103f, 293.2768f, 591.9909f, 431.5314f, 338.6320f, 236.6151f, 185.2476f, 175.1540f, 156.0322f, + -63.6185f, -100.3640f, 351.1546f, 428.5004f, 353.7403f, 293.3142f, 196.1020f, 152.1965f, 114.6518f, + -20.0721f, -100.8514f, -174.7278f, -314.6773f, -143.5646f, 298.1905f, 181.1825f, 142.0341f, 71.3729f, + -64.7951f, -146.2021f, -143.2170f, 33.9854f, 13.8056f, 156.0337f, 163.4005f, 334.1913f, 325.3497f, + -79.9064f, -121.2133f, 229.6626f, 303.8755f, 306.8218f, 415.8466f, 436.8824f, 486.2830f, 451.8081f, + -67.6130f, -122.0631f, 41.7635f, 134.7727f, 156.2778f, 308.4236f, 340.0357f, 434.5742f, 391.1108f, + -2.6037f, -46.9405f, -151.3320f, -160.0405f, -239.8193f, -368.3138f, -88.0921f, -150.1500f, -191.7920f, + -79.3309f, -112.6262f, -20.0215f, -129.1640f, -35.3227f, -69.4806f, -159.3188f, -223.7142f, -132.1779f, + 21.9835f, -11.3374f, -106.7910f, -244.8813f, -406.4640f, -311.7320f, -96.4711f, -182.5312f, 57.8956f, + 25.8713f, -0.7151f, -79.9440f, -80.0111f, -224.4878f, -136.2209f, -22.1062f, -137.4635f, -22.6838f, + -17.4638f, -88.0421f, -183.7897f, -361.0791f, -194.1127f, 29.9571f, -12.3110f, 17.3506f, -52.9132f, + -108.1431f, -191.9295f, -193.9598f, -196.0948f, -165.6809f, -79.0258f, -53.5949f, 30.1916f, 37.3619f, + 10.0420f, -70.0023f, -183.1197f, -393.7681f, -492.0758f, 102.2096f, -13.6587f, -51.6821f, -101.1752f, + -25.8195f, -90.5090f, -174.4579f, -208.3670f, -308.3139f, -74.5783f, -38.9631f, -104.3672f, 142.1591f +}; + +/*-------------------------------------------------------------------* + * 1nd stage, 2nd split: ISF9 to ISF15 + *-------------------------------------------------------------------*/ + +const float dico2_isf[] = +{ + 530.1115f, 512.7983f, 443.8771f, 306.1447f, 171.2327f, 70.8250f, 56.8183f, + 248.5479f, 252.9719f, 260.5429f, 221.7305f, 172.6754f, 84.8419f, 141.5120f, + 166.9014f, 171.9745f, 263.4265f, 204.8570f, 129.5061f, 45.8705f, -162.9417f, + 47.0761f, 115.3926f, 182.9788f, 181.5048f, 89.7111f, 17.3276f, -86.2999f, + -57.3148f, -93.7950f, 58.2071f, 31.0844f, 152.3217f, 108.6931f, 41.3677f, + -163.1767f, -217.0378f, 215.5667f, 199.7393f, 91.8320f, 56.3535f, -37.1534f, + 16.9371f, 75.2105f, 106.8429f, 58.4518f, 26.0167f, 13.3113f, -106.5544f, + -16.6336f, -49.0904f, 66.7054f, 162.6404f, 110.2851f, 24.4686f, -138.4124f, + -145.3240f, -33.7683f, -134.5548f, -42.3167f, -36.8413f, -70.9451f, -34.7360f, + -234.5519f, -328.1575f, -78.2304f, 181.4482f, 100.8272f, -4.3886f, -98.7986f, + -18.7314f, 128.6640f, 38.0685f, -113.4033f, -211.9919f, -310.5748f, -138.0866f, + -222.6271f, -45.5429f, 72.9616f, 3.9276f, -52.1214f, -162.3586f, -29.6134f, + -241.3416f, -50.3196f, -96.3331f, -145.0456f, 17.4087f, -29.8105f, 108.3555f, + -399.1142f, -421.4348f, 49.0965f, 185.0085f, 99.2830f, 49.7543f, 20.2726f, + -109.7596f, 29.7695f, -65.3607f, -141.1745f, -110.3974f, -215.1475f, -110.3518f, + -46.4209f, -20.4624f, -0.5266f, 52.1919f, -12.3074f, -79.8395f, -162.1720f, + 415.6808f, 323.0418f, 248.6461f, 267.3440f, 181.1869f, 81.5855f, 4.8347f, + 188.1995f, 162.5893f, 175.4467f, 144.9775f, 131.0177f, 114.8023f, 75.6850f, + 280.8494f, 225.0358f, 142.4128f, 52.8503f, 44.0619f, 35.6548f, -77.7252f, + 116.2722f, 68.6422f, 192.5792f, 142.9262f, 75.7274f, 63.5846f, 13.9314f, + -13.4854f, -92.0420f, -101.3018f, -13.9503f, -1.5377f, 38.4848f, 59.2146f, + -38.0921f, -119.6284f, -10.4956f, 88.8682f, 35.1836f, 43.2013f, -33.7051f, + 35.4547f, 5.0305f, -82.4376f, -100.9264f, -41.5222f, 33.5725f, -24.8381f, + 28.3963f, -13.4840f, -22.4480f, -11.9734f, 63.1961f, 13.8177f, -75.0030f, + -42.4115f, -130.9516f, -245.5204f, -25.9129f, -23.6896f, -49.8110f, 125.7094f, + -193.2334f, -261.3991f, -284.3770f, 75.4337f, 11.9830f, -86.1044f, 47.5069f, + 126.4967f, 37.0484f, -34.7501f, -35.5687f, -159.6523f, -277.2735f, -60.1203f, + -0.1156f, -91.4527f, 35.7808f, 12.8593f, -134.0804f, -237.8749f, -85.9030f, + -134.0644f, -159.5199f, -185.8239f, -255.9559f, -59.8235f, 31.9001f, 86.5795f, + -191.3466f, -290.9137f, -99.7657f, 18.9475f, -18.6283f, 52.5484f, -49.6458f, + 46.4725f, -26.2220f, -128.3100f, -152.1911f, -106.3316f, -212.7650f, -21.8051f, + -22.1899f, -50.6587f, -4.0987f, -2.7160f, -63.9780f, -18.1671f, -8.5809f, + 384.5044f, 415.7100f, 375.3419f, 221.7875f, 82.0605f, -10.5889f, 6.1831f, + 316.8826f, 269.9225f, 294.6225f, 200.5877f, 87.3740f, -13.6950f, 64.9923f, + 258.7122f, 274.8100f, 241.2115f, 150.6316f, 22.2879f, -82.2525f, -100.3677f, + 199.2028f, 140.2225f, 163.4630f, 153.3341f, 35.3954f, -56.3718f, -6.8714f, + -75.2059f, -12.0741f, -10.5019f, 87.1330f, 34.8811f, -55.7089f, 9.3485f, + -43.9131f, -38.3306f, 184.0508f, 124.7862f, 72.2168f, 1.2740f, 68.2432f, + 98.5331f, 56.9808f, -18.2386f, 106.3234f, 18.7400f, -82.2337f, -91.2981f, + 56.8543f, 26.8486f, 79.2505f, 142.2529f, 26.5547f, -20.1961f, 20.0251f, + -101.2805f, -186.8430f, -272.0712f, -136.2303f, -296.2366f, -195.7741f, 24.4320f, + -195.6167f, -300.4726f, -112.7403f, 30.7313f, -121.6459f, -194.0080f, -41.2612f, + 98.2285f, 20.7275f, -91.7240f, -183.2970f, -349.5879f, -345.3007f, 56.7721f, + -162.4512f, -215.0840f, 54.6896f, -51.9437f, -204.1752f, -302.6133f, 17.1211f, + -127.3559f, -165.3954f, -278.6780f, -194.2370f, -33.4488f, -168.4021f, 38.6555f, + -295.7049f, -301.6402f, -62.3113f, -29.8345f, -17.8150f, -12.4093f, 147.9211f, + 33.3799f, -13.6109f, -78.2303f, -156.7363f, -259.0581f, -406.3858f, -96.3685f, + -70.3287f, -128.8603f, -35.8870f, -146.8926f, 10.7114f, -71.6699f, -42.8127f, + 499.4422f, 424.3595f, 305.0398f, 196.0019f, 126.5760f, 63.9795f, 61.1516f, + 266.3734f, 181.9720f, 175.4860f, 108.0995f, 56.9864f, 10.7695f, 159.6035f, + 247.9333f, 184.5145f, 152.3734f, 41.9318f, -90.6959f, -210.2689f, -54.1531f, + 76.7519f, 154.5846f, 129.7565f, 83.0209f, 81.7690f, -11.2691f, -31.6182f, + 58.5084f, -37.0541f, -121.7467f, 29.7202f, -30.0062f, -124.9186f, -19.6730f, + 18.1514f, 3.4725f, 18.4977f, 68.3406f, 54.2768f, 11.6546f, 150.1885f, + 85.0507f, 80.6332f, -9.5051f, -97.5608f, -37.4477f, -107.8952f, -71.4574f, + 10.1458f, 46.5077f, 14.7448f, 5.4868f, -1.5563f, -51.9743f, -20.1740f, + -186.2883f, -239.8358f, -385.3964f, -279.2732f, -246.3584f, -317.5150f, 77.9409f, + -290.8109f, -394.1977f, -416.1625f, -291.0747f, -246.4900f, -66.6275f, 7.0910f, + -53.3572f, -98.2187f, -188.6130f, -239.5862f, -382.9682f, -469.8791f, 4.8130f, + -236.2064f, -299.8000f, -219.3447f, -267.9179f, -424.8446f, -200.9900f, 22.5746f, + -78.8698f, -167.2648f, -305.5687f, -418.8565f, -37.5231f, -91.3323f, -69.9264f, + -187.4632f, -276.9708f, -417.8298f, -350.3085f, -51.2638f, -35.7869f, 125.5794f, + -56.7695f, -75.4877f, -200.1077f, -284.6027f, -223.5758f, -298.6907f, -81.9158f, + -129.2158f, -228.6000f, -204.9319f, -246.4877f, -109.8989f, -81.0975f, -118.3144f, + 455.1133f, 431.3343f, 366.9250f, 323.3162f, 279.7654f, 166.3696f, 60.4075f, + 2.2427f, -42.4551f, 320.2264f, 303.9626f, 161.9218f, 44.0682f, -10.4932f, + 148.9215f, 132.3074f, 122.6564f, 103.3307f, 47.4590f, -3.4202f, -185.0445f, + -145.6115f, 18.4827f, 228.0817f, 172.5267f, 38.5907f, -90.1562f, -43.9888f, + -193.6085f, -14.9922f, -111.3547f, 102.4688f, 119.0297f, 66.3613f, 1.6199f, + -229.1052f, -217.2523f, 26.9406f, 25.7113f, 183.7947f, 138.0997f, 4.9246f, + -54.0735f, 27.3595f, -6.9751f, 41.3897f, 26.0272f, 65.3047f, -117.9287f, + -173.6861f, -55.0424f, 72.3582f, 74.4772f, 59.1275f, 32.2629f, -52.0966f, + -100.2805f, -203.3997f, -281.1161f, -77.1917f, 52.4149f, -18.1558f, -70.9170f, + -319.7560f, -456.2388f, -303.5891f, 199.8376f, 140.0785f, 37.0556f, -44.1020f, + 53.3338f, -0.8373f, -29.0162f, -53.8806f, -156.4895f, -44.6551f, -144.9031f, + -94.4005f, -181.9505f, 79.8505f, 87.0198f, -12.1349f, -82.6727f, -75.0313f, + -207.6459f, -248.8868f, -181.9412f, -267.7931f, 100.0395f, 108.0778f, -54.3928f, + -445.8355f, -486.1193f, -148.8008f, -29.2654f, -20.9138f, 5.3055f, 34.4656f, + -121.3450f, 45.0588f, -55.9190f, -194.9437f, -134.0013f, 48.6244f, -162.3284f, + -240.5215f, -57.3889f, -52.6141f, 16.9554f, -1.6593f, 47.0915f, -144.2315f, + 326.1222f, 306.0203f, 250.4581f, 152.3629f, 138.5136f, 136.6061f, 24.8198f, + 27.9826f, 75.7094f, 172.8544f, 182.3980f, 170.1943f, 85.7041f, 145.3514f, + 181.4035f, 144.2242f, 74.8556f, 1.4272f, -61.0836f, -28.1913f, -88.2541f, + 22.2453f, 80.4679f, 118.3400f, 80.0672f, 73.2458f, 39.5447f, 103.6288f, + -15.5237f, -80.2624f, -190.5397f, -72.0487f, 107.7333f, 24.8407f, -9.9839f, + -84.5773f, -169.2563f, -115.8907f, 53.5535f, 128.0731f, 120.4292f, -112.8952f, + 147.5641f, 31.5040f, -120.2366f, -181.4932f, 22.0867f, -14.3306f, 88.8276f, + -38.8943f, 9.5208f, -14.2124f, -59.1263f, 77.8884f, 3.1099f, 55.9227f, + -166.2941f, -272.4271f, -413.5079f, -51.9034f, 151.3775f, 62.8211f, 125.4737f, + -251.4761f, -399.5025f, -496.4470f, 15.1387f, 25.6129f, -47.9447f, 27.2588f, + 145.3730f, 69.2023f, -67.5157f, -217.2383f, -216.1160f, -118.5795f, -73.6690f, + -45.7917f, -144.0127f, -166.1374f, -47.5218f, -180.4311f, -59.2610f, -28.7005f, + -253.6976f, -332.1650f, -464.5507f, -299.7163f, 194.1511f, 140.7432f, 86.8261f, + -311.8663f, -444.9106f, -568.2597f, -74.2214f, 168.0938f, 91.5796f, 69.8801f, + 16.2576f, -36.8680f, -158.1385f, -270.2551f, 14.7501f, -79.0270f, -96.1519f, + -66.0490f, -143.0125f, -113.3699f, -34.3890f, -25.0086f, 12.5482f, -114.0537f, + 394.4650f, 360.5732f, 366.5918f, 277.4828f, 181.5850f, 89.9984f, 133.6822f, + 84.7064f, 117.2216f, 411.7273f, 263.7720f, 26.7575f, -178.8131f, -69.9364f, + 30.5200f, 177.1075f, 123.5531f, 7.2231f, -92.4543f, -193.6012f, -94.9796f, + 65.2717f, 8.1559f, 165.7135f, 84.0440f, -35.7379f, -118.5377f, -66.5232f, + -113.0977f, -31.5885f, -27.3286f, -26.0692f, 15.5114f, 21.2791f, -23.2414f, + -138.0497f, -166.9724f, -35.1916f, 20.7464f, 36.6236f, 3.5627f, 20.9882f, + -11.0900f, 124.4114f, 110.4337f, 5.6888f, -93.7853f, -22.5026f, 30.8623f, + -29.4226f, -47.2009f, 89.3512f, 13.6996f, 22.5131f, 2.3075f, -51.7825f, + -137.2009f, -200.8273f, -290.6017f, -325.7113f, -275.5810f, -53.4554f, 64.1025f, + -438.9569f, -542.2731f, -412.1423f, -89.9884f, -28.4069f, 15.6647f, 13.8672f, + -63.4932f, -90.8672f, -207.9037f, -306.7191f, -456.9608f, -272.1003f, 37.6908f, + -307.9492f, -374.7438f, -96.2506f, -168.0490f, -243.8695f, -64.5296f, -3.1349f, + -334.4494f, -210.9558f, -246.0072f, -354.2072f, -131.6393f, -27.1645f, 29.5091f, + -366.0860f, -407.0811f, -257.3381f, -286.1801f, -81.4441f, 77.6511f, -10.1480f, + -204.4162f, 30.5330f, -38.3922f, -195.6373f, -339.5407f, -347.7475f, -31.6897f, + -243.6551f, -274.7409f, -17.3959f, -136.0264f, -9.8248f, 34.1080f, -72.7180f, + 392.4115f, 321.3055f, 213.3703f, 97.3249f, 35.2497f, -8.7278f, 80.8223f, + 116.4944f, 155.2541f, 148.9464f, 124.6089f, 78.0606f, 24.1574f, 118.5191f, + 184.6981f, 148.0850f, 51.9562f, -96.3499f, -247.0329f, -172.3801f, 29.4305f, + 110.9024f, 81.4259f, 152.8654f, 45.1114f, -9.8257f, 17.3401f, 36.9414f, + -27.9329f, 30.8783f, -37.1648f, -24.5270f, -50.2764f, -114.4973f, 79.3175f, + -64.1897f, -136.2614f, 44.8825f, 47.6375f, 26.8591f, -0.2729f, 147.6527f, + 135.7539f, 66.4931f, 38.8074f, 22.5599f, -70.1020f, -117.9085f, 73.4314f, + -74.1601f, -0.9165f, 58.6634f, 8.8413f, -20.0486f, -4.3857f, 84.5215f, + -240.3710f, -336.9822f, -425.7879f, -557.5921f, -313.4519f, -18.6503f, -2.2911f, + -375.5428f, -498.5622f, -604.7405f, -284.0899f, -22.5439f, 21.7506f, 87.1215f, + -48.5853f, -99.7448f, -219.1610f, -385.9877f, -498.9206f, -58.0072f, -32.0391f, + -187.4733f, -257.8106f, -348.0662f, -465.0402f, -523.0202f, -126.9367f, 7.9922f, + -242.4066f, -358.0976f, -506.2984f, -527.3067f, 103.2345f, 112.8789f, 19.5721f, + -329.7812f, -399.2909f, -525.3788f, -519.3241f, -114.6023f, 18.0531f, 108.4014f, + -101.3959f, -182.8774f, -323.7689f, -459.4139f, -208.2967f, -218.5872f, -30.6618f, + -83.9128f, -188.9391f, -321.0572f, -481.5454f, -309.1473f, 5.7541f, -53.7133f, + 508.3954f, 514.6412f, 492.8828f, 409.4624f, 279.6907f, 139.5316f, -25.0946f, + 225.7716f, 321.9763f, 361.4909f, 313.2012f, 246.2739f, 141.2217f, 40.0333f, + 183.5499f, 361.1524f, 299.5782f, 200.8792f, 127.5401f, 74.2915f, -43.7510f, + 87.8314f, 192.1731f, 193.5542f, 170.6556f, 233.6155f, 150.0142f, -17.3959f, + 16.6972f, 31.8549f, -16.4255f, 68.2118f, 202.5792f, 133.4167f, -24.8757f, + -118.5934f, -60.2884f, 62.2425f, 224.9154f, 157.3277f, 86.2001f, 127.8335f, + 83.3985f, 95.4353f, 47.7289f, -24.4079f, 122.0239f, 35.9347f, -62.3200f, + 85.0292f, 81.2156f, 121.2625f, 104.6399f, 119.6594f, 126.2998f, -77.7217f, + -111.4887f, -105.1822f, -30.9685f, -48.2729f, -55.9544f, -59.5831f, 92.3539f, + -80.0937f, -149.8609f, -166.3557f, 134.5224f, 22.8807f, -72.2311f, -71.7019f, + -106.2400f, 96.5443f, 49.1033f, -82.1511f, -202.4001f, -182.6395f, 30.4307f, + -38.6498f, -47.0332f, 196.2347f, 62.6390f, -109.4412f, -217.5327f, 118.6330f, + -165.3289f, -6.5073f, -110.5468f, -172.9718f, 83.9014f, 82.6244f, -54.8262f, + -220.1304f, -267.2490f, -88.9432f, 199.2986f, 140.8517f, 50.8656f, 126.1685f, + -167.2625f, 130.8662f, 38.2409f, -25.2887f, 14.1618f, -84.0247f, -96.2550f, + -141.5362f, 19.9235f, 142.0336f, -6.1892f, -91.4426f, 58.7228f, -64.2743f, + 356.9441f, 345.0619f, 293.3749f, 255.2251f, 264.2440f, 181.1552f, -59.9296f, + 246.4391f, 212.9810f, 208.9891f, 281.1677f, 232.7401f, 140.5526f, -31.7890f, + 305.7318f, 278.3117f, 199.8758f, 171.6015f, 133.0515f, 98.0317f, -152.6052f, + 194.0116f, 162.7764f, 97.4355f, 145.3808f, 115.4215f, 67.7161f, -75.3193f, + 50.0116f, -43.0169f, -150.4608f, 36.4008f, 15.3428f, 67.7103f, -90.2827f, + 84.1801f, -22.9641f, -98.8488f, 180.4238f, 151.9562f, 59.9903f, 26.9906f, + 177.5510f, 105.3890f, -1.4605f, -131.7380f, -19.1906f, 90.9329f, -125.9315f, + 119.9137f, 55.8859f, 20.5790f, 85.2794f, 50.1218f, 92.1433f, -60.8729f, + -14.4439f, -72.6866f, -93.8542f, -160.4042f, -42.8567f, 3.3977f, 156.0409f, + -54.5578f, -142.4629f, -245.2400f, 100.6745f, 148.4848f, 83.6861f, 108.3569f, + 51.3106f, 177.4475f, 69.0944f, -111.1996f, -202.9647f, 42.3005f, -83.6978f, + 30.1802f, -55.2034f, 78.5647f, -47.9833f, -191.5273f, -51.2293f, 23.2575f, + -5.5372f, -75.8171f, -203.4011f, -289.5156f, 106.7613f, 141.4280f, -13.0810f, + -141.4010f, -221.2458f, -112.2780f, -89.1527f, 63.0527f, 92.4026f, 123.8935f, + -105.1256f, 76.2826f, -29.3279f, -146.3319f, -79.8275f, 4.2937f, 30.2187f, + -50.0448f, -103.1965f, -61.1121f, -87.1858f, -185.4814f, 103.5567f, 10.4906f, + 483.7709f, 447.9613f, 357.9065f, 269.2391f, 168.5860f, 81.9800f, -109.5565f, + 312.3829f, 259.3732f, 343.4722f, 283.4192f, 160.6555f, 62.4472f, -64.0786f, + 177.4189f, 268.0235f, 209.2622f, 107.3129f, 57.2866f, 17.7874f, 43.3733f, + 118.3413f, 189.8245f, 200.1482f, 138.5254f, 93.9936f, 70.6362f, -26.8448f, + 30.9857f, 35.8345f, 11.3604f, 57.5567f, 90.9626f, 20.1319f, 6.8180f, + -66.7255f, 112.7395f, 51.2972f, 171.5931f, 105.7922f, 1.0289f, -4.0888f, + 161.4374f, 94.0077f, 56.1444f, 67.9007f, 60.5061f, -0.5993f, 5.5333f, + 22.6145f, 84.7579f, 96.3842f, 85.7332f, 58.1820f, 68.5529f, -7.0445f, + 89.2476f, -2.9310f, -93.5695f, -80.5243f, -200.4216f, -74.7223f, 78.7932f, + -37.6075f, -106.1347f, -177.1898f, 12.7187f, -117.0868f, -224.7555f, 18.0710f, + -3.9184f, -42.1867f, -96.2393f, -135.5441f, -300.7351f, -209.1140f, 3.3638f, + -127.2731f, -168.0130f, -23.6514f, -125.4722f, -275.0623f, -116.8249f, 78.4081f, + -0.3268f, -109.2929f, -235.6517f, -163.5220f, -72.4472f, 7.1522f, -14.1950f, + -201.5567f, -203.8994f, -147.8831f, -113.7655f, -70.6486f, -37.9403f, 10.4648f, + -61.9333f, -122.2785f, -205.0957f, -87.3765f, -199.0248f, -324.4658f, -76.9686f, + -114.1747f, -179.4460f, -22.8678f, -120.9749f, -219.5858f, -55.7430f, -137.0347f, + 416.5525f, 356.2247f, 246.4192f, 151.7590f, 80.9813f, 33.7425f, -87.5668f, + 232.7198f, 199.8298f, 232.8017f, 197.1352f, 122.7492f, 47.7377f, -18.8607f, + 307.4450f, 336.4361f, 172.1882f, -36.4639f, -118.2980f, 12.7783f, -74.1220f, + 100.4413f, 183.0223f, 131.6807f, 19.7279f, 5.8399f, 116.3680f, -36.1637f, + 115.0603f, 28.3727f, -46.6535f, 9.9458f, 14.2165f, 8.8947f, 42.1125f, + -11.0346f, -1.0867f, -12.6705f, 44.5022f, 8.2729f, 72.2938f, 41.9570f, + 188.4713f, 119.1476f, 5.8222f, -109.1441f, -124.7922f, 20.2470f, 37.4241f, + 88.4120f, 18.1026f, 44.8535f, 28.1015f, -53.1688f, 52.0384f, -48.7039f, + 7.0136f, -80.7959f, -218.2056f, -230.6367f, -196.4241f, -188.3921f, 125.5651f, + -223.0832f, -308.3413f, -371.4560f, -67.3406f, -172.4539f, -210.1611f, 44.0330f, + 70.5425f, 5.5613f, -121.1026f, -250.2220f, -391.0280f, -78.8702f, 62.0359f, + -53.2080f, -153.5175f, -168.9519f, -200.2387f, -356.0113f, -56.1841f, -8.4833f, + 28.1989f, -103.3445f, -275.6373f, -372.5401f, -62.2850f, 20.7805f, 129.8285f, + -131.8626f, -230.9837f, -332.7086f, -149.5865f, -154.3909f, 21.7068f, 17.3275f, + 16.7300f, -61.8863f, -181.1369f, -350.5149f, -246.6439f, -61.1861f, -114.9767f, + -62.9283f, -50.0990f, -128.3168f, -223.8037f, -188.6130f, -48.9473f, 4.2910f, + 397.1338f, 354.0856f, 410.7048f, 392.6840f, 265.0492f, 133.1239f, -39.9595f, + 140.3398f, 130.2926f, 612.1718f, 513.2461f, 282.4946f, 41.1820f, 3.7939f, + -25.5253f, 283.5953f, 206.7656f, 117.4847f, 85.9801f, 16.9447f, -106.7023f, + -199.2065f, 170.3263f, 280.7031f, 221.1866f, 139.8684f, 69.7774f, 44.7026f, + -218.6125f, 116.3745f, 51.8822f, -46.6960f, 133.6225f, 87.8249f, 5.3826f, + -351.2338f, -39.4894f, 84.6148f, 241.0717f, 156.3851f, 57.0277f, -22.5485f, + -16.1558f, 137.3482f, 31.9090f, -76.7114f, 15.3505f, 47.2591f, -65.0792f, + -82.6497f, 23.1536f, 174.7281f, 111.0391f, 165.1666f, 97.6276f, -66.0758f, + -144.8786f, -188.8722f, -232.9240f, 11.8115f, -15.8240f, 97.1230f, 8.4134f, + -145.3324f, -253.9705f, -310.2223f, 186.1852f, 173.7029f, 84.4147f, -31.0347f, + -137.6416f, 107.5353f, 6.4667f, -172.8744f, -362.7197f, 36.0251f, 7.3423f, + -273.1752f, -271.7551f, 168.5304f, 103.1478f, -19.2394f, -121.0773f, 71.0605f, + -382.1200f, -84.7432f, -167.9304f, -156.0550f, 39.5436f, 102.1275f, 28.0496f, + -362.7133f, -347.0801f, -139.5875f, -5.2563f, 181.0231f, 147.5667f, 92.1709f, + -322.5983f, 22.0118f, 11.8984f, -116.7982f, -140.8088f, -50.1710f, -20.0495f, + -342.8153f, -116.9352f, -43.2698f, 29.1059f, 25.4655f, 14.1526f, 1.1041f, + 319.3257f, 143.9371f, -9.8398f, 138.1817f, 272.2951f, 230.7682f, -67.6844f, + 120.5561f, 82.8050f, 86.9118f, 293.3890f, 188.8921f, 54.7609f, -21.7199f, + 231.6328f, 148.0905f, 27.2085f, -3.2337f, 100.6721f, 70.2593f, 42.8315f, + 64.4154f, -17.9857f, 99.5439f, 116.0344f, 85.7395f, 106.6537f, 41.0177f, + 62.6236f, -27.4056f, -139.7237f, -70.5707f, 148.2318f, 128.9077f, 124.7000f, + -92.9236f, -144.0688f, -77.1586f, 288.9071f, 226.4347f, 124.6281f, -55.6669f, + 78.3503f, 42.4807f, -79.0042f, -178.3122f, 128.1446f, 107.8855f, -55.1806f, + 79.1238f, 66.4433f, 43.2504f, 16.2992f, 80.8281f, 140.7251f, 73.5809f, + -134.6119f, -155.8599f, -200.3194f, -90.9865f, 253.7969f, 164.9683f, 31.5576f, + -248.1197f, -375.5200f, -476.6351f, 180.7157f, 210.6575f, 79.8609f, 81.7351f, + 78.7261f, -9.7665f, -75.8617f, -194.4922f, -307.4282f, 75.4347f, -56.0501f, + -175.4331f, -210.0029f, 75.9892f, -41.3638f, -129.4197f, 26.7040f, 24.1293f, + -89.1388f, -186.3199f, -327.9780f, -225.0781f, 123.8019f, 49.8056f, 110.5614f, + -262.0009f, -365.9398f, -315.0958f, -44.6833f, 152.6366f, 130.9091f, -24.3555f, + 96.1914f, 0.9431f, -122.7709f, -265.0437f, -118.4077f, 70.4388f, -34.3324f, + -41.7155f, -106.2450f, 35.3080f, -77.1729f, -11.0485f, 113.3317f, -43.5801f, + 345.8234f, 448.9382f, 398.8093f, 278.1467f, 193.7783f, 109.9307f, -32.5084f, + 105.2215f, 192.0218f, 307.4095f, 251.2213f, 135.6460f, 27.1659f, 48.2501f, + 131.1255f, 248.6208f, 194.8135f, 35.9742f, -89.6413f, -70.1114f, 74.4933f, + 10.3277f, 157.1341f, 220.2146f, 132.8669f, 58.2022f, -4.2414f, 52.5998f, + -171.9997f, 219.1700f, 183.7592f, 79.7388f, -28.2743f, -72.7875f, 54.8047f, + -281.0813f, 5.4272f, 138.6439f, 89.6476f, 26.7423f, -52.0621f, 181.8158f, + 42.9908f, 121.1063f, 40.1449f, 4.6961f, 41.3091f, 11.3680f, 61.7374f, + -69.6739f, 44.0933f, 62.9511f, 55.3414f, 47.1718f, 45.0520f, 10.5398f, + -254.2462f, -161.6377f, -252.0311f, -59.3082f, -64.1228f, -5.1355f, -167.6060f, + -249.7012f, -368.7658f, -266.1853f, -40.5172f, -31.5949f, 20.3852f, -73.7292f, + -259.0964f, -63.9727f, -123.4555f, -266.6797f, -372.6790f, -79.9634f, -32.2913f, + -237.8991f, -261.1591f, -67.3100f, -201.9258f, -271.1355f, 110.5556f, -31.4253f, + -252.1870f, -59.5241f, -149.7008f, -264.8359f, -95.9333f, -15.7623f, -55.9292f, + -291.6127f, -310.8436f, -291.0997f, -152.3425f, -38.1903f, 16.9302f, 107.5521f, + -234.1635f, -77.8775f, -155.4929f, -169.1375f, -170.1633f, -210.0618f, 12.2871f, + -432.5516f, -222.0327f, -146.7204f, -103.4423f, -49.3643f, -8.0516f, 0.3778f, + 330.7150f, 223.7578f, 120.2566f, 152.9689f, 119.1688f, 39.3462f, 21.3169f, + 106.4649f, 114.2936f, 78.3297f, 104.4772f, 135.1724f, 78.5670f, 48.1339f, + 284.0033f, 187.5895f, 88.2418f, 0.6583f, -25.3445f, -53.7671f, 63.9802f, + 106.5275f, 81.1295f, 67.7705f, 114.2483f, 4.6206f, 98.6728f, 68.0557f, + 132.7267f, 80.9311f, 70.2013f, 34.2614f, 45.4356f, 17.9487f, 185.5185f, + -179.6926f, -64.9953f, -11.8397f, 5.1401f, 42.9932f, 67.5337f, 154.7699f, + 53.6060f, 34.2805f, 16.7478f, -53.4059f, -36.7348f, 13.1978f, 110.7422f, + 37.6082f, -5.5267f, 88.1530f, 15.7336f, 24.4194f, 27.1976f, 50.6641f, + -182.5485f, -287.0959f, -395.1311f, -458.4781f, -119.8993f, 119.0388f, -26.2634f, + -239.2084f, -359.3420f, -447.6111f, -221.6196f, -3.2312f, 35.8538f, -9.6860f, + -70.9599f, -105.8073f, -192.0091f, -294.5047f, -334.6240f, 111.9638f, -29.3527f, + -193.0902f, -307.5872f, -268.9553f, -266.8591f, -276.8985f, 53.4395f, -127.3159f, + -112.3830f, -214.7503f, -352.5892f, -431.6330f, 130.6462f, 125.3650f, -24.3701f, + -138.4310f, -254.9568f, -325.5955f, -173.9416f, 0.3136f, 147.4202f, -59.5469f, + -63.4081f, -119.3462f, -237.6156f, -366.1194f, -116.1935f, 96.5096f, -74.8714f, + -91.5009f, -186.5192f, -95.3213f, -190.6698f, -103.7853f, 133.5730f, -129.6124f +}; + +/*-------------------------------------------------------------------* + * AMR-WB ISF codebook - 46bits, 2 stages, 1st stage common with the + * 36bit codebook,5 splits in the 2nd stage + * + * codebook vector dimension number of vectors + * ~~~~~~~~ ~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~ + * 2_1 3 64 + * 2_2 3 128 + * 2_3 3 128 + * 2_4 3 32 + * 2_5 4 32 + *-------------------------------------------------------------------*/ + +/*-------------------------------------------------------------------* + * 2nd stage, 1st split: ISF0 to ISF2 + *-------------------------------------------------------------------*/ + +const float dico21_isf_46b[] = +{ + 128.4688f, 159.8148f, 97.2755f, + -12.9836f, 197.1542f, 62.3669f, + -11.1370f, -5.4038f, 227.1786f, + -102.5247f, 49.5302f, 138.2452f, + 56.6014f, 92.4597f, 68.2462f, + -59.4614f, 95.8021f, 47.7671f, + 10.6214f, 16.4206f, 132.7432f, + -33.0052f, -36.4880f, 121.6274f, + 111.3621f, 86.8573f, -60.9301f, + 18.4019f, -16.9460f, -196.8595f, + 91.2159f, 47.1568f, 150.3417f, + 40.7444f, -123.8314f, 17.6656f, + 68.7560f, 76.0870f, 3.0834f, + 40.5189f, -22.9558f, -36.8239f, + 68.9463f, 20.8592f, 75.1641f, + -13.4297f, -49.7472f, 59.4394f, + 222.6512f, 108.2263f, -13.1594f, + -26.2678f, -128.5232f, -249.6796f, + -61.3770f, -106.3253f, 180.3803f, + -69.2195f, -180.5594f, 77.3840f, + 125.7118f, 69.8739f, 44.7696f, + -150.6344f, 66.9866f, 7.4132f, + 7.5039f, -4.7150f, 76.2746f, + -46.9159f, -98.2953f, 78.4325f, + 118.5603f, 14.1695f, -131.2373f, + -50.1565f, -86.1739f, -148.3825f, + 66.6965f, -72.1903f, 115.4583f, + -94.5599f, -121.9918f, 8.8523f, + 77.1679f, 15.2443f, 6.1163f, + -1.0987f, -69.2605f, -43.3316f, + 43.3928f, -36.3404f, 29.4998f, + -36.0829f, -87.1134f, 1.6094f, + 69.0548f, 158.6352f, -17.3680f, + -65.7580f, 148.4039f, -58.1224f, + -1.4207f, 106.6547f, 129.4115f, + -163.9787f, 200.5753f, 108.3887f, + 8.0981f, 96.4962f, 18.4523f, + -22.7513f, 51.0308f, -0.8203f, + -1.3389f, 52.2067f, 70.5057f, + -56.5316f, 15.5148f, 68.5082f, + 73.6822f, 28.9345f, -56.5083f, + -10.5212f, -17.6820f, -126.8611f, + 144.6737f, -44.4661f, -8.2446f, + -32.2712f, -161.9950f, -67.5138f, + 29.9266f, 37.2667f, -20.0451f, + -15.7787f, -11.7016f, -26.2432f, + 27.7648f, 34.4647f, 33.4065f, + -13.8614f, -38.4420f, 5.6107f, + 27.0098f, 76.8588f, -130.2875f, + -76.5280f, 30.9527f, -90.1727f, + -135.8326f, -53.3710f, 85.3346f, + -137.4852f, -34.8750f, -33.3215f, + 18.2807f, 78.3958f, -50.7970f, + -64.5101f, 14.5083f, -5.6925f, + -16.6084f, 1.0141f, 33.5889f, + -63.0082f, -42.0433f, 31.0393f, + 32.2577f, 8.3123f, -92.4112f, + -31.6346f, -58.2893f, -92.9305f, + 58.7086f, -72.6659f, -98.0877f, + -72.8089f, -97.1838f, -63.2264f, + -7.5866f, 25.6299f, -54.3822f, + -10.3321f, -19.4552f, -70.7729f, + 9.4725f, 4.3403f, 0.0721f, + -50.7563f, -41.0679f, -38.2745f +}; + +/*-------------------------------------------------------------------* + * 2nd stage, 2nd split: ISF3 to ISF5 + *-------------------------------------------------------------------*/ + +const float dico22_isf_46b[] = +{ + -49.5271f, 121.1295f, 16.4769f, + -94.4022f, 76.8061f, 2.1280f, + -58.8683f, 32.7926f, -6.6703f, + -83.7461f, 49.5749f, -58.1205f, + -96.5332f, -51.1816f, 62.2310f, + -104.6874f, -104.4218f, -36.9709f, + -84.8023f, 0.4441f, -31.0082f, + -105.8907f, -31.0867f, -72.0962f, + -17.4561f, 170.2726f, 62.0341f, + 64.3231f, 77.6492f, 152.6545f, + -13.0558f, 31.6496f, 73.1381f, + -25.9540f, -16.3235f, 138.6579f, + -116.2904f, -22.1347f, 133.9606f, + -42.0923f, -209.9028f, 88.4509f, + -56.0897f, -9.1734f, 75.5450f, + 68.7883f, -157.0452f, 33.8343f, + 20.5838f, 115.6837f, 9.8136f, + -32.8948f, 98.7358f, -40.4656f, + -22.8099f, 41.1383f, -49.3496f, + -66.1700f, 67.9190f, -122.8227f, + -18.8196f, 17.0630f, -114.9884f, + -64.0458f, -162.7084f, -94.5118f, + -54.2084f, 1.0923f, -75.9526f, + -60.5415f, -80.9324f, -82.4130f, + 46.5760f, 125.8621f, 83.1458f, + 129.9934f, 19.7027f, 148.2803f, + 92.6546f, 96.4434f, -0.8040f, + 181.9977f, -6.0791f, 78.6212f, + 93.0392f, -99.5781f, -41.6073f, + 26.0437f, -172.0070f, -58.1634f, + 47.8475f, -34.2895f, -54.2498f, + 34.4187f, -96.6345f, -28.5027f, + -15.8270f, 90.1190f, 65.2787f, + -24.1274f, 60.7006f, 6.3059f, + -25.2307f, 6.3412f, 30.0794f, + -26.6845f, -0.7965f, -24.5917f, + -59.0614f, -117.3599f, 62.4002f, + -7.0821f, -130.0555f, 20.9710f, + -21.7086f, -36.6794f, 1.9468f, + 0.6440f, -74.2564f, 5.5161f, + 35.9276f, 57.9971f, 81.4502f, + 42.2272f, 3.3575f, 106.2218f, + 42.1565f, 13.6719f, 43.0135f, + 55.6116f, -33.1310f, 56.8126f, + 18.4410f, -61.4055f, 109.0841f, + 1.0223f, -125.1248f, 96.1657f, + 16.9404f, -28.1707f, 26.5748f, + 33.5245f, -84.6827f, 52.6704f, + 14.2066f, 54.8716f, 30.7506f, + 21.9479f, 68.4119f, -19.0589f, + 10.1034f, 17.7161f, 1.1122f, + 28.3594f, 21.5207f, -39.3190f, + 42.6619f, -71.6784f, -94.4716f, + -1.6345f, -110.6804f, -94.5938f, + 18.7091f, -26.5385f, -18.5676f, + -2.2267f, -59.7051f, -47.6606f, + 63.0633f, 76.6895f, 37.6845f, + 90.5993f, 31.2041f, 74.2520f, + 64.4418f, 37.7231f, 4.2748f, + 100.9151f, -12.1708f, 27.5607f, + 104.1606f, -30.0584f, -35.7097f, + 121.5339f, -81.6812f, 34.1503f, + 59.3840f, -5.5457f, -8.5514f, + 58.5319f, -58.3782f, 3.4649f, + -126.3823f, 217.4185f, 72.9956f, + -149.8116f, 119.9919f, 17.7920f, + -98.1555f, 10.6050f, 30.1117f, + -142.4950f, 30.1718f, -20.4500f, + -188.3500f, -32.7229f, 62.5055f, + -165.4842f, -201.2336f, -25.1871f, + -114.8346f, -46.6803f, -1.4401f, + -185.9166f, -45.3806f, -42.6756f, + -37.7442f, 124.2892f, 142.7720f, + 41.5423f, 244.7676f, 173.7613f, + -74.1037f, 46.8818f, 112.0588f, + -57.0922f, 25.5056f, 241.9654f, + -166.9268f, 94.6864f, 141.8443f, + -141.0368f, -145.0649f, 168.9254f, + -135.5530f, 39.8468f, 65.4743f, + -245.6494f, 76.1803f, -5.6309f, + -25.5608f, 185.7902f, -18.2246f, + -116.1471f, 125.0659f, -65.5997f, + -21.6448f, 139.2267f, -103.0516f, + -152.7089f, 32.1737f, -111.7466f, + -19.9673f, -12.1771f, -217.1499f, + -69.4452f, -156.0378f, -228.9529f, + -79.9513f, -19.3186f, -140.5787f, + -134.0792f, -92.8863f, -131.5222f, + 85.7696f, 178.6823f, 22.5404f, + 219.0179f, 182.4547f, 100.9819f, + 132.7898f, 105.4102f, -65.5694f, + 175.6583f, 30.2382f, -109.3055f, + 23.2833f, 65.0492f, -161.3234f, + 51.9178f, -98.2708f, -192.0347f, + 84.2797f, 61.1831f, -113.4513f, + 110.0580f, 0.1775f, -193.4730f, + -88.3674f, 114.5595f, 71.3481f, + -61.4713f, 52.7833f, 47.8295f, + -61.8477f, -23.0151f, 15.1016f, + -52.0862f, -46.0690f, -37.7005f, + -129.6202f, -120.6827f, 44.2216f, + -62.4412f, -165.8667f, -2.2683f, + -58.1508f, -82.2449f, 9.3842f, + -31.2569f, -108.3441f, -35.0348f, + -4.4143f, 48.6610f, 132.2242f, + 50.8942f, -27.6676f, 181.6500f, + 2.0066f, -17.6839f, 71.9731f, + 92.7139f, -37.1637f, 98.9732f, + -54.3785f, -76.9789f, 115.8870f, + -7.4354f, -117.3479f, 199.5254f, + -24.6757f, -59.5165f, 54.3134f, + 97.6902f, -113.0194f, 131.1002f, + 48.4163f, 132.4722f, -58.7820f, + 13.3327f, 68.6117f, -81.0715f, + 66.7414f, 64.6961f, -45.2427f, + 36.7779f, 14.7160f, -89.5910f, + 29.2181f, -25.5238f, -132.3077f, + -30.5052f, -80.0320f, -150.5560f, + 0.1157f, -11.7322f, -63.8467f, + -21.6912f, -43.0765f, -94.6223f, + 125.3290f, 95.1208f, 75.9759f, + 197.4010f, 92.9319f, -0.5012f, + 123.8246f, 45.4969f, 25.5317f, + 120.7415f, 34.4155f, -28.8961f, + 176.6600f, -20.0903f, -19.4091f, + 130.6288f, -84.9368f, -113.4633f, + 82.2281f, 16.0388f, -59.4614f, + 93.1589f, -21.5846f, -101.7248f +}; + +/*-------------------------------------------------------------------* + * 2nd stage, 3rd split: ISF6 to ISF8 + *-------------------------------------------------------------------*/ + +const float dico23_isf_46b[] = +{ + -3.8995f, 58.9472f, 140.2168f, + 53.1422f, 116.3810f, 87.0383f, + 99.7094f, -40.4441f, 113.1331f, + 165.1496f, 2.2135f, 71.5223f, + -105.3934f, -104.9144f, -38.2897f, + -20.3247f, -32.1811f, 5.1214f, + -32.0250f, -106.9634f, -37.7452f, + 35.0256f, -95.9288f, -28.2073f, + -116.9343f, -27.2704f, 164.5334f, + -34.2352f, 142.6884f, 167.9453f, + 72.9835f, -124.0776f, 148.8355f, + 148.2748f, 14.5359f, 190.7047f, + -145.5305f, -123.4847f, 30.8224f, + -120.2600f, -39.3306f, 2.0939f, + -52.9049f, -176.3645f, 3.0609f, + 27.9487f, -164.3167f, -60.3281f, + 70.4088f, 66.5042f, -47.2043f, + 24.2507f, 69.1997f, -15.5014f, + 127.5028f, 31.2976f, -40.8233f, + 96.9136f, 102.7271f, -1.9768f, + -65.7818f, -70.8663f, -86.5155f, + -0.6444f, -8.8675f, -61.8361f, + -5.3369f, -58.3089f, -47.3390f, + 46.4765f, -35.6284f, -57.4718f, + 46.3328f, 129.6813f, -59.6592f, + 18.9988f, 118.4842f, 13.3515f, + 172.5430f, -21.3132f, -26.8827f, + 84.7525f, 177.2668f, 22.5077f, + -140.2432f, -73.0634f, -146.3583f, + -16.3786f, 19.6063f, -107.1305f, + -3.0698f, -104.1769f, -97.1330f, + 33.2378f, -33.4660f, -134.9635f, + -29.8971f, -15.7433f, 134.7990f, + 34.9346f, 52.2504f, 85.7197f, + 60.8752f, -31.2562f, 62.5970f, + 42.3279f, 15.7348f, 45.3299f, + -61.8761f, -80.5864f, 11.3831f, + 1.9118f, -12.4255f, 68.2023f, + -25.4049f, -61.6688f, 57.1412f, + 21.3127f, -30.3874f, 28.3554f, + -44.5637f, -86.8534f, 137.9897f, + -18.2977f, 31.6219f, 82.2796f, + 19.0573f, -58.8750f, 104.6892f, + 41.1433f, 1.5028f, 117.9977f, + -102.7489f, -51.4207f, 71.3300f, + -59.0984f, -10.9389f, 78.5554f, + -69.1486f, -120.0273f, 65.0256f, + 39.6252f, -86.2109f, 50.9690f, + 29.0714f, 22.6919f, -38.4256f, + 12.6360f, 17.2986f, 5.2183f, + 75.9445f, 11.6720f, -55.4942f, + 66.2898f, 37.5939f, 3.0594f, + -53.0062f, -46.4272f, -35.4140f, + -25.4219f, 2.9542f, -21.2949f, + 1.3392f, -73.4502f, 4.6640f, + 17.5926f, -24.6153f, -19.1614f, + 58.2567f, -8.0154f, -7.3521f, + 9.4616f, 56.2212f, 37.1474f, + 99.2497f, -8.5999f, 23.5678f, + 62.8908f, 76.5199f, 37.4883f, + -61.5740f, -23.6494f, 18.8743f, + -27.4404f, 12.7151f, 31.8660f, + -8.8214f, -125.3200f, 22.5806f, + 60.3707f, -57.3931f, 1.9729f, + -142.0781f, 128.1134f, 29.9265f, + -8.1434f, 177.0072f, 67.7176f, + -42.2467f, 31.9985f, 246.1330f, + 143.5303f, 102.5801f, 81.3050f, + -117.3709f, -24.3191f, -68.7836f, + -80.1727f, 55.9021f, -61.6700f, + -65.9167f, -159.9841f, -103.0851f, + 100.4774f, -105.1623f, -39.0393f, + -248.4434f, 113.0562f, -0.9632f, + -114.2012f, 244.7349f, 67.3892f, + -149.2039f, -141.9386f, 151.3480f, + 96.8171f, 204.6967f, 174.6282f, + -203.4799f, -43.3805f, -41.7327f, + -154.4080f, 46.2418f, -107.0591f, + -133.7993f, -265.7036f, -48.9596f, + -67.3323f, -174.6485f, -259.0245f, + 29.4362f, 57.7183f, -143.2330f, + -30.9358f, 102.7735f, -36.8946f, + 97.2809f, 57.7730f, -111.7326f, + 148.5371f, 105.7429f, -63.3760f, + -55.6062f, -1.6898f, -72.6741f, + -22.0825f, 43.4697f, -48.9841f, + -13.6583f, -42.0695f, -99.1267f, + 39.0227f, 11.1441f, -94.4170f, + -31.1674f, 118.4450f, -103.1298f, + -30.5761f, 181.1050f, -22.4168f, + 96.8625f, -8.6867f, -192.7743f, + 258.0970f, 258.6485f, 17.2359f, + -75.4867f, -15.7399f, -128.9883f, + -69.4209f, 56.4875f, -131.4587f, + -35.1219f, -77.9249f, -156.1559f, + -15.4754f, -8.8922f, -194.7119f, + -74.8584f, 44.6175f, 122.9601f, + -15.9046f, 95.4389f, 74.2532f, + 34.5640f, -37.7631f, 189.4453f, + 93.9878f, 31.0970f, 82.8675f, + -96.2834f, 15.6201f, 33.9921f, + -60.9930f, 57.5930f, 52.2667f, + -0.7661f, -130.2809f, 93.4385f, + 120.2708f, -79.2677f, 42.9508f, + -179.2200f, 97.8633f, 164.7641f, + -85.0375f, 121.2092f, 89.0752f, + -33.4305f, -135.1092f, 255.3923f, + 71.7349f, 68.5372f, 165.8218f, + -187.7999f, -24.7305f, 65.9037f, + -136.4161f, 45.6197f, 73.4184f, + -48.8887f, -218.9293f, 120.9648f, + 61.8728f, -162.4253f, 36.5784f, + 17.9416f, 66.9736f, -75.1315f, + -24.6266f, 61.4069f, 5.3953f, + 100.0199f, -13.7281f, -105.7749f, + 125.9485f, 48.0431f, 20.6117f, + -83.4273f, 1.6803f, -29.7397f, + -60.9733f, 33.6154f, -6.9071f, + 49.9381f, -77.0001f, -90.5842f, + 103.7070f, -35.1051f, -38.3706f, + -120.2797f, 129.5670f, -56.7507f, + -51.1815f, 120.2600f, 22.5398f, + 198.7324f, 23.1592f, -132.3752f, + 219.6951f, 76.6881f, -5.4836f, + -147.6706f, 39.1117f, -18.2240f, + -91.4913f, 78.8627f, 0.3161f, + 40.5908f, -105.4075f, -192.5737f, + 124.6250f, -81.8382f, -127.0619f +}; + +/*-------------------------------------------------------------------* + * 2nd stage, 4th split: ISF9 to ISF11 + *-------------------------------------------------------------------*/ + +const float dico24_isf_46b[] = +{ + -30.8071f, -34.8458f, -1.7377f, + -66.7509f, 30.0385f, -82.3340f, + 62.4748f, -75.5700f, 38.3392f, + 47.0287f, -40.0671f, 126.1063f, + 12.5178f, -8.7146f, -50.3954f, + 27.9620f, 30.3537f, -104.7235f, + 71.0260f, -29.6231f, -25.7014f, + 120.7753f, 38.6709f, -56.4990f, + -89.5313f, -61.4613f, -32.9542f, + -149.7260f, 38.4143f, -27.8365f, + -35.1587f, -137.6189f, 4.6136f, + -110.8198f, -69.6633f, 69.4652f, + -25.4794f, -48.9702f, -64.6927f, + -34.0250f, -68.5378f, -137.1167f, + 16.3769f, -77.3935f, -18.8382f, + 60.1539f, -54.6626f, -95.0395f, + -29.9828f, 6.8644f, 42.3138f, + -15.0985f, 138.6659f, 35.6532f, + 34.1357f, 3.3162f, 60.3957f, + -1.5046f, 61.8542f, 93.5327f, + 49.8233f, 37.2486f, -21.0923f, + 2.6462f, 96.2433f, -48.4645f, + 100.8559f, 5.8835f, 34.9436f, + 80.3813f, 84.4933f, 38.3143f, + -78.4639f, 3.3495f, 7.0416f, + -121.9442f, 90.8917f, 79.7252f, + -15.2997f, -67.8455f, 60.6317f, + -56.1035f, -3.5687f, 110.7510f, + -22.2741f, 27.4204f, -26.9833f, + -61.1362f, 73.0974f, 7.1390f, + 21.0362f, -11.6205f, 9.0680f, + 9.3252f, 52.8599f, 21.3451f +}; + +/*-------------------------------------------------------------------* + * 2nd stage, 1st split: ISF12 to ISF15 + *-------------------------------------------------------------------*/ + +const float dico25_isf_46b[] = +{ + 65.8574f, 55.5896f, -46.5520f, 44.9019f, + 80.4838f, -7.7875f, 36.7110f, 88.1867f, + -41.5522f, 122.0924f, -8.3769f, 6.2406f, + -24.0605f, 63.0705f, 27.8308f, 99.4548f, + -34.8725f, 39.6270f, -72.1743f, 48.7995f, + 28.2859f, -11.6999f, -78.4246f, 134.1911f, + -100.6717f, 12.7337f, -3.2716f, 31.4897f, + -40.5514f, -60.1846f, 28.1000f, 115.5554f, + 56.1050f, -26.6471f, -104.7202f, -9.7237f, + 31.5196f, -30.3722f, -34.0636f, 41.4375f, + 8.5013f, 60.4295f, -72.4835f, -46.4772f, + -18.1378f, -10.8741f, 10.5206f, 35.6699f, + -44.7247f, -14.6405f, -68.4296f, -12.8925f, + -36.6233f, -86.8592f, -73.8785f, 47.7951f, + -51.6319f, -46.3776f, -74.4907f, -105.4981f, + -67.2817f, -67.7186f, 6.9193f, -16.9668f, + 108.8168f, 52.7624f, -16.3049f, -50.0846f, + 72.9801f, -33.7268f, 89.4150f, -54.0673f, + 62.1588f, 93.8928f, 54.7414f, 17.8328f, + 26.7626f, 9.6218f, 88.5287f, 29.9594f, + 8.1440f, 44.9198f, 5.0806f, 2.9996f, + 26.4759f, -96.7328f, 49.0444f, 31.6496f, + -58.6349f, 53.6024f, 80.8924f, -3.3883f, + -60.0341f, -51.9482f, 112.9073f, 26.0056f, + 55.9483f, -14.6255f, -33.5049f, -127.3506f, + 70.1847f, -12.4499f, 7.3368f, -8.8635f, + 10.1728f, 65.7077f, 45.2101f, -90.9790f, + -12.5750f, -10.0652f, 45.9762f, -30.2995f, + 1.2805f, -3.2898f, -17.5766f, -44.9828f, + 22.1316f, -84.0894f, -21.1065f, -32.5923f, + -81.6581f, 43.6873f, -8.6894f, -65.0775f, + -35.4129f, -58.9663f, 65.8078f, -102.2045f +}; + +/*-------------------------------------------------------------------* + * AMR-WB ISF codebook - 36bits, 2 stages, 1st stage common with the + * 46bit codebook,3 splits in the 2nd stage + * + * codebook vector dimension number of vectors + * ~~~~~~~~ ~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~ + * 2_1 5 128 + * 2_2 4 128 + * 2_3 7 64 + *-------------------------------------------------------------------*/ + +/*-------------------------------------------------------------------* + * 2nd stage, 1st split: ISF0 to ISF4 + *-------------------------------------------------------------------*/ + +const float dico21_isf_36b[] = +{ + -20.3147f, -37.6762f, 82.8575f, 122.9161f, -28.4468f, + 31.9756f, -79.5400f, 141.6557f, 53.2923f, -77.0688f, + -49.3360f, -129.1711f, 71.5448f, 85.1944f, 55.7117f, + -19.1147f, -16.1797f, 217.6729f, 89.8943f, 28.1868f, + 0.9668f, -28.5091f, 63.7145f, 147.3305f, 86.3104f, + 52.0605f, 43.3415f, 108.6263f, 83.9071f, -42.8628f, + -39.7734f, -7.6796f, 110.7755f, 44.0677f, 106.4663f, + 32.7239f, 124.4301f, 113.4192f, 7.2217f, 33.0503f, + -9.5746f, -1.9619f, 48.6607f, 51.4268f, -79.8193f, + -14.9729f, -2.0174f, 111.5604f, -3.5774f, -139.2041f, + -54.5000f, -100.1092f, 35.8796f, 45.5500f, -73.7805f, + -56.2694f, 74.4424f, 122.2707f, 20.1155f, -38.3887f, + 65.2094f, -3.9808f, 17.2638f, 96.6362f, 14.0115f, + 148.8982f, 77.1199f, 93.1280f, 28.7596f, 2.2577f, + 14.8324f, -159.4414f, 11.4260f, -1.0211f, -33.2422f, + 35.9112f, 103.8106f, 61.4044f, -9.7034f, -78.2548f, + 62.7658f, -47.4034f, 27.3267f, 32.6865f, -54.7569f, + -6.2693f, -33.7779f, 43.5591f, -36.6678f, -73.8111f, + -104.9376f, -105.4944f, 137.0911f, 41.7979f, -9.4558f, + -26.6750f, -26.3288f, 192.3279f, -40.3915f, -60.3539f, + -20.5168f, -51.3274f, 24.2191f, 47.5655f, 3.7810f, + 52.7448f, 32.7149f, 110.3630f, -21.5464f, -46.7397f, + -4.6471f, -85.4498f, 129.3530f, -31.6973f, 65.0658f, + 85.9795f, -53.2356f, 57.2992f, -67.2997f, -16.4516f, + 54.7607f, -37.1454f, -42.4738f, -34.5633f, -75.7294f, + 0.0517f, -0.6519f, -1.3703f, -12.9917f, -148.9960f, + -25.8564f, -84.6818f, 59.5151f, -72.5006f, -156.8837f, + 95.5045f, 42.2665f, 60.9475f, -54.5273f, -154.2295f, + 44.2810f, -53.2856f, -76.4082f, 42.9736f, -9.5286f, + 83.7851f, 46.2184f, 4.1979f, -25.1575f, -51.0520f, + -43.1590f, -111.8518f, -2.3420f, -129.5042f, 6.3083f, + 36.5568f, 37.9981f, 30.8304f, -113.4959f, -79.9345f, + -1.8493f, -15.3605f, -7.7093f, 98.5986f, -37.6177f, + 29.8557f, 67.8956f, 39.3578f, 63.5122f, 23.6349f, + -27.0502f, -93.1902f, -21.6230f, 155.8476f, 2.5165f, + -44.7515f, 124.6855f, 64.1401f, 107.4525f, 76.4296f, + -5.6913f, 14.2025f, -18.3757f, 129.1303f, 47.2448f, + 88.4045f, 81.8179f, 106.0131f, 126.8375f, 71.9790f, + 5.1288f, -31.2676f, -85.3474f, 183.8293f, 137.8851f, + 112.3553f, 147.7620f, 6.3634f, -19.8307f, 97.9225f, + 68.1479f, 45.1480f, 20.4456f, 58.0360f, -109.0384f, + 91.7441f, 107.7617f, 15.1212f, 47.0576f, -18.7769f, + 0.0359f, -42.2360f, -42.2471f, 94.1364f, -132.5071f, + -36.3673f, 208.5491f, 17.4150f, 13.0281f, -33.9693f, + 75.8679f, 58.1435f, -27.7181f, 158.0312f, -17.2012f, + 159.6027f, 144.6236f, 31.6370f, -72.6323f, -59.9622f, + 9.6094f, -39.8213f, -175.1189f, 48.5059f, -67.6102f, + 8.4503f, 159.5329f, -43.0075f, -121.1605f, -83.4178f, + -10.0988f, 8.8687f, -32.4219f, 44.4166f, 5.5756f, + -42.8299f, 63.9306f, 20.2856f, 86.9213f, -32.1874f, + 14.3835f, -9.6605f, -102.7732f, 119.7146f, -5.8143f, + -181.8677f, 162.2914f, 114.1354f, 64.3820f, -7.2207f, + 11.2529f, -7.2901f, -66.7670f, 60.6365f, 71.2140f, + 69.9911f, 56.0744f, -10.7183f, 90.0489f, 100.9538f, + -40.2531f, -96.6451f, -154.5512f, 92.9078f, 43.9867f, + 146.6528f, -60.2643f, -42.7063f, -1.4891f, 60.9280f, + 38.2143f, 33.0628f, -113.9071f, -1.8860f, -48.5082f, + 45.4740f, 54.2829f, -45.4768f, -38.2865f, -114.7585f, + -5.4061f, -32.4176f, -108.6457f, -45.8426f, -147.6796f, + 41.4813f, 12.9066f, -41.5456f, -134.2382f, -189.2112f, + 46.4330f, 6.8074f, -160.9846f, 53.8969f, 64.9889f, + 149.8519f, 39.6080f, -79.5860f, 34.3934f, -61.0983f, + -47.2568f, -110.8652f, -117.2089f, -0.3717f, -64.7306f, + 109.4393f, 12.8368f, -59.4424f, -122.1797f, -31.4694f, + -14.4126f, 8.5189f, 89.4622f, 59.7035f, 14.3509f, + -23.3690f, -32.3486f, 92.0827f, -3.3169f, -16.0022f, + -66.1460f, -89.0215f, 49.1022f, -7.9295f, 141.6034f, + -91.8393f, 6.6528f, 142.3305f, -60.9383f, 61.1140f, + -9.9035f, -11.7998f, 27.9396f, 56.3528f, 60.7524f, + 59.7717f, -10.3224f, 100.1088f, 37.9471f, 56.4210f, + -8.0706f, -14.3273f, 18.7969f, -25.3479f, 97.6871f, + 24.5711f, 30.0075f, 106.4596f, -49.8085f, 48.5911f, + -50.4430f, -10.2232f, 15.4334f, 3.6211f, -45.0851f, + -2.3100f, 32.1923f, 14.7250f, -35.3260f, -71.2667f, + -131.2863f, -5.1029f, 11.0382f, 61.7451f, 35.4884f, + -11.6345f, 94.0117f, 53.4418f, -66.3264f, -6.6649f, + 57.0155f, 5.4850f, -4.4053f, 12.7554f, 23.6955f, + 74.8564f, 77.0331f, 21.2315f, -32.6182f, 33.2036f, + 9.1670f, -78.1914f, -30.2862f, -11.1652f, 54.5347f, + 47.7388f, 92.4139f, 41.3020f, -133.3741f, 53.0528f, + -22.2909f, -55.2830f, -33.2798f, -6.2896f, -28.8257f, + -23.1116f, -35.0033f, -3.2927f, -72.9685f, -7.7727f, + -82.3073f, -104.1028f, 84.5118f, -69.8221f, -43.1637f, + -19.5349f, -2.7976f, 85.8117f, -104.2825f, -27.2739f, + -22.1902f, -16.4648f, -6.6730f, -5.7920f, 27.7237f, + 12.5658f, 8.3566f, 24.7755f, -53.6096f, 12.7618f, + -53.5741f, -68.1802f, 40.6279f, -26.4454f, 38.0614f, + -26.1757f, -16.7503f, 52.0974f, -117.6298f, 86.4284f, + -45.3502f, -78.0491f, -31.6007f, -35.9389f, -106.1265f, + -24.8954f, -15.9989f, -21.2401f, -95.2454f, -86.1251f, + -112.2460f, -94.4001f, -19.4652f, -33.9923f, -34.6433f, + -95.7000f, 92.3440f, 39.8654f, -64.8912f, -115.0483f, + 25.8969f, 9.4794f, -63.2644f, -27.6289f, 36.9308f, + 25.6901f, 52.9741f, -35.3425f, -86.0458f, -14.2567f, + -38.4101f, -62.7105f, -86.5748f, -73.4519f, 11.4446f, + -7.0262f, 6.9787f, -7.4983f, -161.9427f, 3.4520f, + 19.1677f, 23.8207f, 38.9733f, 15.3764f, -21.7743f, + -43.1688f, 31.9400f, 52.7685f, -11.9674f, 20.1452f, + -35.0128f, -59.7929f, -36.1783f, 73.7702f, 71.2205f, + -83.5945f, 115.1128f, 46.5742f, -28.7420f, 110.8292f, + 0.6347f, 53.5489f, 14.3686f, 18.4025f, 71.1819f, + 35.9728f, 45.7217f, 71.9726f, -20.7319f, 145.8423f, + -8.1019f, -5.6290f, -13.8278f, 53.1928f, 152.8343f, + 57.0881f, 50.3240f, -64.1728f, -11.0774f, 129.9089f, + 36.0925f, 31.0887f, -32.6698f, 39.1693f, -52.3060f, + -3.1405f, 84.8560f, -12.4226f, 1.0655f, -18.3673f, + -58.9719f, 98.0129f, -83.8334f, 55.3139f, 35.7679f, + -87.3652f, 121.2513f, -67.0447f, -107.5562f, 38.2622f, + 62.0513f, 60.4638f, -69.1208f, 43.6854f, 20.7579f, + 79.9694f, 10.7071f, 3.2196f, -93.6621f, 75.1450f, + 66.1122f, 46.9324f, -124.5950f, -78.3322f, 41.3915f, + 4.3229f, 13.8757f, -33.6575f, -92.7601f, 177.5551f, + -42.5067f, -60.2164f, -63.5331f, 67.8862f, -21.5990f, + -14.9811f, 12.6046f, -39.5598f, -30.2755f, -22.9980f, + -80.2668f, -125.5028f, -37.7023f, 27.0213f, 31.0364f, + -121.0989f, 17.0095f, 6.9604f, -72.1639f, 13.2205f, + -45.0105f, -7.6587f, -57.9626f, -15.4159f, 79.2983f, + -11.3128f, 60.2083f, -11.6157f, -61.5281f, 64.7932f, + -17.6502f, -51.3289f, -123.9766f, -9.4275f, 141.7024f, + -64.4806f, -80.0931f, -43.9064f, -86.7513f, 103.4672f, + -12.6910f, -17.1597f, -58.5736f, 21.2452f, -75.2569f, + -2.3195f, -14.7279f, -99.6098f, -65.8753f, -44.8940f, + -103.7556f, 33.9613f, -73.7263f, -13.9038f, -66.1526f, + -23.2670f, -33.9743f, -103.9167f, -170.2949f, -66.2644f, + -26.4354f, -31.7233f, -108.7190f, 9.2282f, 14.7962f, + -9.0340f, -7.5327f, -60.7032f, -100.1385f, 55.1481f, + -23.7530f, -88.2969f, -220.5980f, -68.4569f, 27.6805f, + 3.3643f, -11.1758f, -92.5898f, -201.1381f, 102.8789f +}; + +/*-------------------------------------------------------------------* + * 2nd stage, 2nd split: ISF5 to ISF8 + *-------------------------------------------------------------------*/ + +const float dico22_isf_36b[] = +{ + -116.4826f, -2.3267f, 37.0276f, 11.9585f, + -83.2536f, -34.0855f, -47.5833f, 101.8900f, + 1.6666f, -19.3089f, 81.2133f, 5.5915f, + -50.2199f, -43.0204f, 11.8773f, 45.9389f, + -83.6736f, 100.7533f, 42.9626f, -91.7069f, + -15.8879f, -6.8432f, -49.2481f, 46.8567f, + 40.2748f, 25.3026f, 49.6150f, -14.6042f, + 49.1020f, -13.9172f, -9.5624f, 9.9442f, + -53.7549f, -26.0755f, -108.5515f, -72.7670f, + -64.1594f, -75.7696f, -78.4742f, 30.5700f, + -82.2540f, -34.1100f, -20.0480f, -86.1655f, + -68.0474f, -31.0203f, -36.5615f, -15.3976f, + 8.8102f, -2.3252f, -61.3614f, -93.8460f, + 8.4465f, -43.1451f, -59.6402f, -26.4485f, + 57.8873f, -1.8283f, -0.9150f, -58.1355f, + -0.3760f, -52.6396f, -15.1757f, -69.7872f, + 26.6552f, 140.6710f, -45.5320f, -5.9904f, + 53.5205f, 18.1777f, -108.7393f, 57.1700f, + 53.1281f, 101.4898f, 52.8254f, 25.2450f, + 23.9310f, 45.2712f, -17.5932f, 37.8318f, + 90.1549f, 147.8806f, 33.8829f, -46.8215f, + 132.2255f, 69.0079f, -106.1068f, 1.3402f, + 103.9284f, 60.8167f, 10.9874f, -26.8688f, + 101.6619f, 32.7808f, -33.2101f, 33.7802f, + -103.9522f, 60.0893f, -100.1459f, -71.1324f, + -6.7456f, -25.3835f, -118.9063f, -2.2439f, + -15.7859f, 68.4583f, -59.0835f, -70.2552f, + -10.4160f, 10.4323f, -34.1781f, -24.5999f, + 47.1747f, 44.4596f, -64.8288f, -183.2536f, + 62.0332f, -25.7788f, -126.3596f, -90.0926f, + 83.7341f, 59.4975f, -55.2472f, -82.6595f, + 53.3482f, 14.1273f, -71.7379f, -20.0471f, + -110.1113f, -92.4130f, 15.5809f, 3.7302f, + -18.8013f, -91.7902f, -14.6105f, 98.1369f, + -21.2096f, -126.2513f, 53.1438f, 11.3308f, + -34.3197f, -67.9178f, 83.0592f, 77.2733f, + -152.4262f, 38.6895f, -24.6967f, -146.6594f, + 41.7355f, -66.1454f, -64.2312f, 165.7005f, + 27.0772f, -43.2220f, 54.9943f, -65.1872f, + 28.8899f, -50.2606f, 25.5035f, 56.2652f, + -137.7163f, -80.7691f, -80.0014f, -42.7037f, + -62.3651f, -150.7820f, -138.8149f, 38.1900f, + -68.7802f, -192.5785f, -7.8749f, -55.9578f, + -98.5983f, -168.6083f, -0.7398f, 84.2329f, + -35.1656f, -67.9774f, -65.6374f, -160.6224f, + 4.9446f, -110.8514f, -89.3759f, -62.4133f, + -34.1288f, -108.8451f, 13.3702f, -98.1466f, + -29.4614f, -102.8405f, -22.8325f, -16.4528f, + 163.9105f, 20.5337f, -82.4577f, -139.6505f, + 149.8660f, -13.6016f, -146.1693f, 154.5116f, + 26.6673f, -89.2330f, 126.1283f, -0.6475f, + 65.0738f, -119.9143f, 75.1351f, 75.9130f, + 179.3039f, 128.5647f, -1.9070f, -129.8349f, + 146.4228f, 30.7058f, -2.7357f, 122.1955f, + 110.1199f, -48.4108f, 78.0568f, -35.8715f, + 105.8916f, -63.1848f, -27.3019f, 70.1234f, + -61.4940f, -116.2433f, -200.7709f, -120.8167f, + 22.5673f, -63.6047f, -213.1464f, 7.0661f, + 48.3577f, -141.9964f, 65.3628f, -93.1012f, + 32.5991f, -160.4748f, -45.5903f, 37.6377f, + 54.6730f, -43.7561f, -151.6335f, -243.7797f, + 101.1397f, -52.0073f, -123.8756f, 16.0909f, + 63.7439f, -50.8957f, -25.0308f, -130.5887f, + 88.2969f, -64.3814f, -48.5324f, -43.0123f, + -181.9705f, -24.0096f, 2.3863f, 89.5185f, + -59.5915f, 80.1714f, -56.6992f, 94.5562f, + -62.1659f, 18.9433f, 76.0160f, 57.8553f, + -22.4665f, 10.7743f, 12.0918f, 108.9830f, + -118.1671f, 72.3971f, 109.1443f, -1.3839f, + -23.8459f, 76.9232f, 22.9444f, 33.4435f, + -44.5975f, 47.9554f, 65.6020f, -20.3018f, + 13.6440f, 14.2271f, 38.9794f, 49.0774f, + -159.0490f, 40.0263f, -30.2347f, -15.6526f, + -132.0447f, -0.4802f, -133.5965f, 61.0673f, + -69.7882f, 40.8409f, -13.3128f, -38.0654f, + -72.3667f, 32.7089f, -13.7936f, 42.2054f, + -51.7645f, 41.9187f, -35.3954f, -139.3463f, + -70.4106f, 21.2248f, -89.5260f, 9.2659f, + -17.3511f, 18.5094f, 18.3073f, -71.0465f, + -25.6477f, 4.9120f, 17.7504f, 1.3904f, + -132.5788f, 97.9003f, 25.0501f, 88.4524f, + -16.3421f, 39.3618f, -136.5657f, 107.5423f, + -38.7664f, 155.3425f, 55.5880f, 47.1198f, + 43.2628f, 4.6910f, -39.9914f, 101.5498f, + 0.0830f, 197.2389f, 101.6377f, -36.9070f, + 62.8279f, 111.5018f, -37.6259f, 87.5036f, + -1.4618f, 80.2742f, 122.5196f, 12.8147f, + 65.1409f, 54.2334f, 34.3093f, 79.7332f, + -91.6271f, 123.5048f, -23.6092f, -9.5877f, + -3.2208f, -58.6010f, -121.8443f, 78.4266f, + -14.0112f, 114.0430f, 23.9902f, -40.4777f, + -15.4729f, 68.1635f, -63.4068f, 16.5519f, + -8.1780f, 157.1093f, -11.2800f, -137.0649f, + 8.0606f, 59.4657f, -140.5838f, -36.3320f, + 22.2676f, 74.5499f, 82.8755f, -76.6792f, + 29.5054f, 61.7793f, -8.0867f, -27.0956f, + -128.1797f, -72.1649f, 129.2723f, 46.4323f, + -20.7709f, 111.3353f, 22.0263f, 131.4695f, + -41.9162f, -9.2182f, 158.1064f, 11.2798f, + -7.1545f, 53.6140f, 106.2812f, 108.0610f, + -99.5471f, 8.6443f, 67.7713f, -74.7187f, + 115.0857f, 125.6656f, 126.8208f, 118.1528f, + 8.3489f, -10.6246f, 129.8214f, -69.4937f, + 46.4587f, 5.2711f, 105.7244f, 50.4485f, + -177.6754f, -70.1548f, 45.4547f, -74.5236f, + -88.7724f, 24.0424f, -57.8465f, 204.7888f, + -68.8890f, -112.1224f, 110.3182f, -61.1447f, + -94.7905f, 5.0186f, 77.6790f, 167.9779f, + -23.0125f, -19.1513f, 44.8958f, -142.4394f, + 28.0225f, -67.2659f, -53.6584f, 36.2990f, + -54.0239f, -49.3550f, 55.1522f, -32.8946f, + 2.0792f, -48.4861f, 14.9542f, -7.9957f, + -100.8337f, 121.3744f, 234.8044f, 83.3187f, + 36.5393f, 50.8425f, -23.7400f, 196.1698f, + -0.3059f, -61.1762f, 189.5078f, 122.4017f, + 57.0232f, -28.8934f, 61.7134f, 134.6930f, + 107.9555f, 52.8736f, 109.5032f, -22.1311f, + 191.2912f, 98.4213f, 38.7853f, 16.9729f, + 104.1509f, -28.9315f, 167.6925f, 40.9011f, + 108.7356f, -8.7976f, 46.5837f, 36.6080f, + -211.7768f, 190.5028f, 100.4753f, -45.0833f, + -32.7791f, -95.3684f, -171.2339f, 186.7766f, + -44.0395f, -212.9286f, 151.2602f, 39.5958f, + -37.2152f, -119.5092f, 43.4460f, 194.5965f, + 37.2023f, 64.8673f, 8.5289f, -117.5366f, + 163.8890f, -5.9760f, -22.5312f, -30.3817f, + 105.4272f, 11.3735f, 47.6228f, -110.1422f, + 62.3479f, -93.6059f, 19.4353f, -14.9112f +}; + +/*-------------------------------------------------------------------* + * 2nd stage, 3rd split: ISF9 to ISF15 + *-------------------------------------------------------------------*/ + +const float dico23_isf_36b[] = +{ + 31.6601f, -7.0021f, 26.7324f, -10.6919f, -47.7440f, -109.3316f, -1.6793f, + 17.6152f, -69.1639f, 81.7745f, -11.6557f, -53.0002f, -28.8501f, 51.3155f, + -17.3392f, 39.6296f, -29.4208f, -34.2716f, -18.7475f, -53.4279f, -21.0682f, + -95.6211f, -11.0108f, 24.5639f, -6.9345f, -43.8606f, -40.3930f, 22.5841f, + -30.9469f, -2.2484f, 85.8968f, -25.2118f, 44.4649f, -13.7549f, -19.6283f, + 42.5807f, -25.3893f, 55.9790f, -44.6039f, 50.3451f, 29.5180f, 49.0040f, + 64.7422f, 35.0105f, -24.0120f, -94.6131f, 72.4785f, -29.0560f, -16.8213f, + -17.7762f, -36.1097f, 19.1423f, -88.8131f, 9.4121f, -60.6212f, 15.2182f, + 26.1194f, 33.0214f, 38.6243f, -16.4898f, 20.5108f, -71.7754f, -109.7775f, + 55.6133f, -47.5797f, 0.0746f, 8.1716f, -55.6639f, -5.8260f, -6.7666f, + 86.9148f, 36.0665f, -8.0422f, -18.6522f, -31.9936f, -5.4779f, -65.2340f, + 20.0656f, -14.5303f, -94.7449f, -11.7982f, -35.2031f, 6.9138f, -22.0461f, + 20.9060f, 41.0458f, 29.0299f, 33.4933f, 27.0675f, 5.1646f, -39.4529f, + 76.7175f, 28.2216f, -34.8562f, 16.7304f, 25.2291f, 7.4912f, 15.3906f, + 47.1053f, 13.3625f, 50.9902f, -31.9588f, 9.8596f, 83.1329f, -61.0081f, + 39.4355f, -39.6936f, -53.1235f, -8.1282f, 22.3882f, 83.7131f, 8.6440f, + 13.9302f, -48.4179f, 80.1925f, 79.6573f, 22.8321f, -61.0888f, -32.5848f, + 32.2601f, -45.5857f, 53.4300f, 53.4773f, 33.0895f, 45.4420f, 17.2865f, + -36.0406f, -57.6566f, -26.6841f, 4.2674f, -39.8452f, -76.9236f, -85.9930f, + -29.8696f, -72.1261f, -22.6802f, 51.6689f, -10.3407f, -71.6716f, 33.3209f, + -2.6190f, -11.9459f, -0.7138f, 9.1651f, 80.0695f, -58.7987f, 3.7833f, + -10.6521f, -14.2910f, -1.7854f, -6.9002f, 114.1547f, 51.0851f, 0.4936f, + 45.5988f, -65.6262f, 3.5076f, -36.3037f, 31.3412f, -22.8916f, -48.6823f, + -71.1623f, -95.4642f, 38.3287f, -9.4939f, 52.9002f, -8.4421f, 36.7283f, + 86.2675f, 37.9505f, 41.2317f, 16.4269f, 16.7260f, -62.6682f, 32.6168f, + 9.9181f, -25.0994f, -8.3770f, 2.2985f, 5.3157f, -6.0428f, 60.1555f, + 49.0247f, 6.0545f, -54.7919f, 58.6261f, -3.9732f, -80.9565f, -44.3777f, + 30.6734f, -24.5101f, -82.4513f, -27.4901f, -10.8146f, -84.7650f, 64.6334f, + 18.0553f, 14.7350f, -8.7675f, 109.6707f, 51.4393f, -24.1075f, 42.7732f, + 43.6601f, 21.1278f, -43.7223f, -36.3814f, 81.3688f, 10.3561f, 115.5857f, + 44.7304f, 4.0203f, -57.4008f, 16.1462f, 84.4927f, 16.5958f, -107.7931f, + 19.3887f, -44.8683f, -99.3061f, 65.1051f, 45.6203f, -0.6984f, 23.6828f, + 6.4828f, 56.2769f, 13.3073f, -28.0424f, -72.7066f, -58.5212f, 106.1769f, + -11.1674f, -25.7849f, -34.9574f, -36.9812f, -58.1843f, 50.2182f, 98.0044f, + 47.6759f, 0.1786f, -19.4605f, -91.2611f, -35.5267f, 13.8815f, 10.2127f, + -41.1350f, -39.8329f, -34.1829f, -47.4437f, -91.9939f, -2.6788f, -4.2821f, + -79.6033f, 42.6213f, 2.0653f, -74.4526f, 41.0602f, -5.7905f, 63.6539f, + -31.4071f, 12.4383f, -9.2647f, -81.5461f, 16.0430f, 114.6936f, 27.3863f, + -41.2719f, -36.6253f, -79.4997f, -46.2467f, 46.8034f, -19.4146f, -14.6126f, + -31.9554f, -93.9975f, 17.8233f, -51.0152f, -11.4389f, 58.4455f, -21.6241f, + 12.9670f, 60.7166f, 46.9564f, -34.6928f, -3.1553f, 2.7762f, 24.2978f, + 83.1108f, 31.8670f, 23.6533f, 6.8663f, -63.0785f, 56.1031f, 59.2073f, + 11.6877f, 51.3190f, 25.3083f, -33.9761f, -99.5482f, -6.6294f, -41.7488f, + -3.1041f, 33.3329f, -24.8851f, 20.0947f, -63.3399f, 87.2565f, -20.6208f, + -52.2549f, 102.0059f, 26.9280f, -22.0208f, 85.2782f, 28.3108f, -43.2782f, + 0.8584f, 60.5987f, -44.2357f, -33.9700f, 19.1247f, 33.1631f, -10.8275f, + -63.5371f, 16.2471f, -0.2828f, -76.6458f, 2.8322f, 15.2373f, -95.8412f, + 5.5912f, -53.4989f, -30.8518f, 4.1365f, -62.3116f, 79.0018f, -114.5611f, + -36.8596f, 12.7812f, 81.1609f, 39.2434f, 21.9162f, -17.2064f, 127.1804f, + -30.4279f, -15.8549f, 90.5057f, 4.9324f, -55.6202f, 88.7264f, 31.2457f, + -6.4338f, -33.9992f, 78.4675f, 12.7460f, -51.8920f, 5.7002f, -71.3454f, + -22.6305f, -75.0886f, -18.4430f, 71.6854f, -49.9613f, 51.9112f, 38.5919f, + -80.1990f, 4.2373f, -60.6613f, 30.4453f, 20.4006f, 28.0162f, 55.1546f, + -96.2887f, 10.3433f, 38.5883f, 59.1444f, 23.2247f, 45.0000f, -24.9305f, + -30.9055f, -18.2692f, -6.1201f, -5.6460f, 2.1550f, 18.2502f, -16.8166f, + -28.0966f, -69.3654f, -10.5762f, 63.4193f, 43.8444f, 16.6643f, -67.9380f, + -68.3269f, 93.1501f, 72.8030f, 27.6125f, -21.1484f, -73.4926f, -29.7929f, + -88.0045f, 91.0304f, 15.1885f, -15.1144f, -61.6391f, 47.5526f, 17.2017f, + -10.0973f, 16.8435f, 32.7608f, 50.6231f, -36.3173f, -19.8196f, 8.7833f, + 1.1920f, 35.7643f, -58.4480f, 53.1925f, -71.1458f, -22.3426f, 37.8118f, + -51.2779f, 69.9477f, -30.3236f, 31.2621f, 35.5419f, -64.6025f, 35.1224f, + -0.6572f, 57.9364f, 5.6749f, 50.6782f, 25.3456f, 68.4492f, 45.6955f, + -53.8176f, 44.6419f, -53.4407f, 51.5645f, 1.3456f, -4.0462f, -72.5604f, + 54.6610f, -1.6150f, -14.3009f, 99.1775f, -24.2467f, 36.0557f, -42.7052f +}; + +/*-------------------------------------------------------------------* + * AMR-WB ISF codebook for SID - 28bits, 1 stage, 5 splits + * + * codebook vector dimension number of vectors + * ~~~~~~~~ ~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~ + * 1 2 64 + * 2 3 64 + * 3 3 64 + * 4 4 32 + * 5 4 32 + *-------------------------------------------------------------------*/ + +/*-------------------------------------------------------------------* + * 1st stage, 1st split: ISF0 to ISF1 + *-------------------------------------------------------------------*/ + +const float dico1_ns_28b[64*2] = +{ + -105.0619f, -262.8448f, + -86.6322f, -209.7320f, + -91.1931f, -168.0481f, + -53.8753f, -176.1473f, + -82.7923f, -129.2635f, + -75.0845f, -93.9859f, + -33.9476f, -90.3333f, + -74.4463f, -50.0451f, + -27.3422f, -41.3458f, + -64.0658f, -2.5361f, + 28.8179f, -70.0786f, + 10.5059f, -12.8463f, + -39.9581f, 28.7359f, + -63.4034f, 44.7503f, + -36.8732f, 67.0368f, + -2.3563f, 50.6058f, + -55.9412f, 91.2822f, + 5.5577f, 85.1171f, + -25.2586f, 105.6009f, + 34.3216f, 71.1726f, + -48.3043f, 133.1605f, + -17.0366f, 148.8321f, + 14.8305f, 130.6908f, + 45.5592f, 106.8464f, + -43.7865f, 177.4889f, + 28.9675f, 168.2081f, + -1.7812f, 190.4731f, + 68.4806f, 149.8876f, + -32.5396f, 218.9960f, + 47.8438f, 206.6539f, + 8.1960f, 234.8430f, + 89.3668f, 188.0221f, + 90.4035f, 118.3064f, + 88.4263f, 237.5410f, + 117.3136f, 145.4498f, + 82.0645f, 73.1093f, + 119.3943f, 103.4796f, + 128.2321f, 184.8528f, + 149.1563f, 129.2199f, + 144.9058f, 51.5776f, + 54.4305f, 22.6608f, + 142.5451f, 8.2812f, + 97.4966f, -31.8767f, + 173.0963f, 84.9898f, + 188.5170f, 42.9719f, + 166.5772f, 162.2136f, + 226.1740f, 86.5496f, + 202.2992f, 129.9512f, + 223.9365f, 175.1483f, + 177.6235f, 206.6174f, + 267.4435f, 128.4469f, + 129.8694f, 226.5438f, + 232.5047f, 231.7147f, + 182.8960f, 252.1132f, + 297.7026f, 201.9668f, + 127.2108f, 277.0716f, + 189.5906f, 309.6084f, + 50.8926f, 267.2207f, + 262.1367f, 287.8791f, + 138.4480f, 342.2196f, + 34.3804f, 314.8025f, + -25.4771f, 275.9066f, + -13.5804f, 397.0122f, + 103.9035f, 438.8237f +}; + +/*-------------------------------------------------------------------* + * 1st stage, 2ndt split: ISF2 to ISF4 + *-------------------------------------------------------------------*/ + +const float dico2_ns_28b[64*3] = +{ + -322.0252f, -345.3659f, -370.7835f, + -314.5226f, -178.1928f, -163.4712f, + -172.6074f, -171.2812f, -211.3224f, + -84.6538f, -225.6710f, -309.6982f, + -65.7865f, -173.3148f, -227.1618f, + -112.2154f, -192.0593f, -106.9376f, + -215.4487f, -115.9810f, -117.3159f, + -63.6069f, -129.9179f, -139.6890f, + -144.6460f, -90.4563f, -90.4457f, + -68.4568f, -140.0307f, -62.0772f, + -148.8729f, -8.2807f, -139.6018f, + -71.8488f, -61.9658f, -63.2677f, + -20.5518f, -74.4279f, -109.2530f, + 7.0237f, -104.2936f, -83.9866f, + -53.7369f, 23.9918f, -110.5212f, + 27.5927f, -37.1603f, -114.8537f, + 5.1437f, -60.8316f, -213.2375f, + -0.0302f, -32.5161f, -30.9893f, + 17.0532f, 37.8947f, -123.4512f, + 69.4656f, -20.4364f, -83.2673f, + 86.8486f, -101.9140f, -164.6497f, + 92.7595f, -46.0582f, -17.0665f, + 55.0807f, 56.5797f, -51.6089f, + 141.9268f, 31.5952f, -111.9348f, + 83.1350f, 25.3995f, 13.2634f, + -41.6305f, 36.7624f, -1.8806f, + 35.5619f, -11.1360f, 49.0468f, + -138.6944f, 20.1165f, -16.0470f, + -85.7227f, -29.5173f, 56.5419f, + -24.5306f, 39.2035f, 95.3233f, + -280.8913f, 17.3520f, 10.4723f, + -223.4287f, -48.5814f, 60.3781f, + -165.0790f, 52.0898f, 122.9863f, + -358.1462f, 27.5800f, 87.6394f, + -104.6460f, 124.2969f, 51.2676f, + -36.4609f, -74.1586f, 163.9110f, + -38.0255f, 47.6372f, 191.7725f, + -30.7896f, 123.7246f, 138.8302f, + 50.7064f, 39.0454f, 126.9589f, + 33.4334f, -114.5499f, 82.0810f, + 52.0289f, 100.6551f, 62.9260f, + 68.9398f, -28.6776f, 181.7511f, + 76.3353f, 117.0400f, 150.0834f, + 135.9951f, 8.5581f, 86.5077f, + 146.9219f, 71.3024f, 159.6375f, + 147.3144f, 111.7858f, 78.8838f, + 94.6612f, 83.2958f, 257.4856f, + 100.5727f, 220.5308f, 96.9196f, + 134.4751f, 159.3021f, -29.6067f, + 158.3509f, 171.9108f, 198.9399f, + 238.9283f, 150.3837f, 148.0492f, + 209.2346f, 237.2747f, 84.4977f, + -21.9723f, 227.3437f, 75.1847f, + 39.1823f, 202.0239f, 221.5619f, + -142.6753f, 174.8218f, 173.9311f, + 284.1931f, 135.5243f, 4.0420f, + 197.3545f, 139.2970f, 296.6173f, + 248.5921f, 227.1523f, 257.1579f, + 130.8344f, 201.7665f, 332.6679f, + 147.8451f, 316.0691f, 223.3704f, + -76.1983f, 342.8470f, 323.9619f, + 206.5931f, 276.1481f, 385.6192f, + 358.4664f, 283.4258f, 153.2502f, + 488.2212f, 389.4155f, 415.1465f +}; + +/*-------------------------------------------------------------------* + * 1st stage, 3rd split: ISF5 to ISF7 + *-------------------------------------------------------------------*/ + +const float dico3_ns_28b[64*3] = +{ + -314.4522f, -327.3454f, -302.2017f, + -203.9117f, -244.9068f, -323.6309f, + -186.2536f, -189.6962f, -235.4297f, + -115.3995f, -187.7246f, -247.4612f, + -142.8871f, -150.1942f, -153.3509f, + -72.7072f, -161.6552f, -154.8560f, + -92.6058f, -153.8863f, -41.3953f, + -98.5994f, -78.7129f, -107.5332f, + -23.9335f, -69.1898f, -172.7805f, + -32.7960f, -77.3107f, -77.6193f, + -69.7610f, -48.7327f, -12.2728f, + -28.2008f, -18.3660f, -63.7045f, + -116.3960f, -85.9584f, 84.0164f, + -24.9241f, -65.7832f, 98.1712f, + -51.8131f, 60.9599f, -23.0835f, + -11.5386f, -0.7831f, 49.5084f, + 20.9367f, 25.8838f, -24.0191f, + -91.0503f, 8.0161f, 98.1430f, + 81.8089f, -19.4694f, 12.5661f, + 12.6976f, 75.6776f, 53.0320f, + -45.8943f, -7.2062f, 185.7293f, + 78.8625f, 17.9396f, 120.6767f, + 99.9111f, 72.2135f, 20.5674f, + 13.7143f, 77.9979f, 152.4088f, + 78.0738f, 102.8484f, 94.6295f, + -84.5040f, 118.1050f, 114.7064f, + 50.0596f, 139.6647f, -0.1577f, + 7.5966f, 168.3675f, 112.1363f, + 87.3316f, 174.4695f, 109.2434f, + 143.4298f, 64.6162f, 83.1959f, + 155.2307f, 122.7478f, 124.7551f, + 149.4719f, 147.9446f, 29.2261f, + 108.3426f, 127.0695f, 180.3353f, + 153.8867f, 197.0929f, 130.5922f, + 98.1956f, 38.2729f, -83.1688f, + 175.9048f, 59.9165f, 174.8273f, + 220.7233f, 88.4354f, 29.6527f, + 183.5505f, 149.7702f, 195.9197f, + 248.2375f, 152.2900f, 108.7161f, + 92.6034f, 52.6123f, 242.1773f, + 133.7155f, 156.6441f, 253.6524f, + 129.4868f, 215.2826f, 202.4702f, + 50.8526f, 163.2149f, 231.3041f, + 207.4225f, 119.3517f, 287.7008f, + 284.9414f, 152.0429f, 226.6699f, + 194.1092f, 217.5607f, 272.9373f, + 115.7381f, 149.7147f, 341.2299f, + 110.4872f, 243.8135f, 296.4818f, + 49.2583f, 242.9759f, 185.7527f, + 218.4281f, 232.2570f, 184.3956f, + 149.3219f, 300.8763f, 240.4531f, + 280.7402f, 239.3506f, 291.1599f, + 210.7589f, 249.5308f, 362.4219f, + 201.8519f, 322.7530f, 312.7221f, + 267.0336f, 316.7373f, 236.0985f, + 293.8933f, 307.2101f, 334.8007f, + 364.5740f, 258.0872f, 136.8430f, + 271.0491f, 175.6599f, 414.3537f, + 219.3663f, 355.8581f, 410.6574f, + 321.8781f, 317.4617f, 431.4073f, + 295.9753f, 408.9221f, 344.4007f, + 445.2552f, 358.3636f, 347.1212f, + 405.7584f, 486.9081f, 556.9660f, + 579.1823f, 650.5953f, 732.6415f +}; + +/*-------------------------------------------------------------------* + * 1st stage, 4th split: ISF8 to ISF11 + *-------------------------------------------------------------------*/ + +const float dico4_ns_28b[32*4] = +{ + -303.1361f, -333.7803f, -347.8725f, -359.4826f, + -215.7523f, -238.3714f, -259.0660f, -289.4405f, + -125.2913f, -144.5697f, -186.1030f, -220.5702f, + 107.0201f, -62.5400f, -178.2959f, 78.3558f, + 103.6377f, 26.1626f, -62.5396f, -119.5691f, + -2.9518f, -82.1288f, 30.9020f, 106.1641f, + 63.5315f, 92.0127f, 120.0751f, 120.2205f, + 225.8191f, 123.6829f, 24.8449f, 116.4136f, + -3.5121f, 76.7992f, 133.5771f, 242.3746f, + 133.9970f, 90.5385f, 122.6116f, 242.8362f, + 67.7067f, 58.1366f, 214.2467f, 205.7587f, + 139.2159f, 144.6370f, 188.0780f, 146.8699f, + 52.7259f, 173.3530f, 190.5093f, 217.0651f, + 152.5843f, 183.9790f, 190.4016f, 255.0127f, + 89.0815f, 165.5783f, 224.8295f, 325.9805f, + 164.7109f, 145.4724f, 282.2096f, 266.3416f, + 115.0926f, 262.9259f, 270.8098f, 248.1893f, + 210.4561f, 232.8534f, 230.5395f, 175.4710f, + 185.5563f, 241.3006f, 257.2568f, 319.6433f, + 287.0131f, 201.7823f, 191.6938f, 262.7153f, + 234.9706f, 135.0743f, 100.3842f, 342.4814f, + 244.1460f, 248.1535f, 331.5106f, 281.3059f, + 283.8415f, 319.6996f, 272.8347f, 232.3501f, + 255.2254f, 187.9562f, 269.5668f, 445.0594f, + 318.1439f, 297.7580f, 274.9042f, 354.5264f, + 198.0688f, 291.9682f, 350.7645f, 365.4872f, + 331.2469f, 333.9341f, 361.1275f, 306.5865f, + 252.3140f, 405.2271f, 344.4444f, 310.3618f, + 301.5996f, 329.9839f, 399.8752f, 449.5998f, + 442.5639f, 384.1796f, 319.3500f, 359.8945f, + 367.3365f, 417.2813f, 488.9795f, 508.7549f, + 620.4818f, 690.0919f, 671.0975f, 590.9387f +}; + +/*-------------------------------------------------------------------* + * 1st stage, 5th split: ISF12 to ISF15 + *-------------------------------------------------------------------*/ + +const float dico5_ns_28b[32*4] = +{ + -316.2941f, -343.3920f, -368.9643f, -99.0392f, + 97.0450f, 71.7080f, 262.1754f, 50.0767f, + 112.4468f, 274.7287f, 358.7211f, 38.6232f, + 257.1795f, 217.8952f, 258.6022f, 85.4104f, + 215.6079f, 228.7031f, 355.6118f, 81.4276f, + 218.4167f, 314.1638f, 296.3636f, 46.5526f, + 236.5851f, 302.2603f, 359.7074f, -54.3647f, + 305.5962f, 297.4161f, 292.2765f, 81.3061f, + 295.4005f, 276.4861f, 384.1555f, 21.9038f, + 212.3865f, 337.6641f, 394.4713f, 59.4888f, + 287.8841f, 272.8244f, 385.4754f, 116.6899f, + 301.1416f, 360.9641f, 343.2708f, 40.2882f, + 209.5407f, 306.5670f, 375.3650f, 158.1632f, + 260.4655f, 357.6203f, 312.8495f, 128.1323f, + 288.3843f, 275.2455f, 301.9735f, 171.2988f, + 321.4736f, 340.3829f, 387.3967f, 138.5811f, + 250.1021f, 392.3276f, 410.9932f, 144.0109f, + 282.6727f, 320.9480f, 370.8150f, 233.3823f, + 161.9622f, 255.8086f, 284.8333f, 188.2323f, + 393.9827f, 349.8717f, 309.8297f, 141.6719f, + 354.6675f, 313.7792f, 268.4562f, -9.8681f, + 396.7580f, 327.4283f, 395.0635f, 73.8789f, + 369.8889f, 434.5653f, 367.9579f, 86.8706f, + 356.9169f, 409.7761f, 383.1727f, 205.7493f, + 373.4236f, 385.5478f, 394.8253f, -47.0644f, + 305.1456f, 409.5952f, 437.7072f, 36.1164f, + 460.1152f, 411.4012f, 345.2657f, 18.4203f, + 438.6750f, 413.5906f, 461.8582f, 46.2207f, + 364.6111f, 379.8415f, 498.6693f, 139.3899f, + 433.1401f, 358.6805f, 429.9292f, 196.6537f, + 405.9484f, 502.2995f, 476.5874f, 123.6977f, + 527.5430f, 471.6736f, 394.4862f, 127.2615f +}; + + +const float *lsf_means[2] = { means_wb_31bits_ma_lsf, means_nb_31bits_ma_lsf }; + +const lsp_unw_triplet p16_gamma0_92to1[16] = +{ + { 0.00000f, 1.19764f, -0.59173f }, + { -0.91173f, 1.79182f, -0.80921f }, + { -0.51779f, 1.44703f, -0.81871f }, + { -0.44862f, 1.36777f, -0.75103f }, + { -0.45150f, 1.30719f, -0.74220f }, + { -0.43157f, 1.21326f, -0.68538f }, + { -0.43606f, 1.21317f, -0.69131f }, + { -0.39200f, 1.04941f, -0.58674f }, + { -0.45208f, 1.10009f, -0.59175f }, + { -0.42553f, 0.99725f, -0.49992f }, + { -0.50168f, 1.07575f, -0.51401f }, + { -0.49800f, 1.06563f, -0.50592f }, + { -0.53101f, 1.16372f, -0.58033f }, + { -0.48744f, 1.07596f, -0.52531f }, + { -0.51899f, 1.04998f, -0.49495f }, + { -0.47730f, 0.90959f, 0.00000f } +}; + +const lsp_unw_triplet p16_gamma0_94to1[16] = +{ + { 0.00000f, 0.78925f, -0.38537f }, + { -0.57154f, 1.19486f, -0.54136f }, + { -0.33642f, 0.99096f, -0.56792f }, + { -0.29856f, 0.93785f, -0.51255f }, + { -0.29716f, 0.89303f, -0.50509f }, + { -0.28264f, 0.81530f, -0.46020f }, + { -0.27926f, 0.80997f, -0.46378f }, + { -0.25334f, 0.69596f, -0.38969f }, + { -0.29656f, 0.72916f, -0.38888f }, + { -0.27488f, 0.65949f, -0.32999f }, + { -0.32630f, 0.70913f, -0.33659f }, + { -0.33069f, 0.70668f, -0.33105f }, + { -0.35437f, 0.77582f, -0.38003f }, + { -0.31771f, 0.70752f, -0.34216f }, + { -0.35066f, 0.70177f, -0.31664f }, + { -0.33404f, 0.62528f, 0.00000f } +}; + +const float dico_lsf_abs_8b[256*M] = +{ + 377.3749f, 688.0079f, 1147.3799f, 1461.0438f, 1786.7794f, 2143.6711f, 2522.1946f, 2889.7402f, 3263.6023f, 3628.4624f, 4005.4351f, 4379.4170f, 4783.9556f, 5157.1753f, 5555.1797f, 5926.6816f, + 601.5123f, 1066.8242f, 1384.3585f, 1652.9448f, 1978.3910f, 2311.2676f, 2674.0537f, 3010.3896f, 3360.0623f, 3725.9336f, 4093.3335f, 4470.6431f, 4859.1006f, 5210.4717f, 5598.3716f, 5954.4204f, + 552.5036f, 859.7047f, 1355.2023f, 1624.9041f, 1887.5609f, 2173.1638f, 2540.7429f, 2926.8169f, 3323.2173f, 3680.7197f, 4008.3447f, 4330.8442f, 4692.8228f, 5033.9697f, 5443.3467f, 5875.4497f, + 459.4534f, 793.3189f, 1293.7278f, 1617.3970f, 1920.0642f, 2192.2153f, 2487.5627f, 2772.1514f, 3111.3823f, 3461.2671f, 3867.0176f, 4279.8550f, 4741.0664f, 5141.0181f, 5552.8237f, 5933.6934f, + 327.9834f, 430.4954f, 723.9031f, 1528.6172f, 1763.1125f, 2013.7936f, 2334.2153f, 2569.0334f, 3017.9436f, 3308.0610f, 3591.7820f, 3865.5430f, 4693.5786f, 5286.7646f, 5647.7036f, 5987.2305f, + 455.0753f, 606.0817f, 963.7564f, 1374.9937f, 1536.4897f, 1914.7618f, 2376.9631f, 2580.8184f, 2989.1501f, 3258.8386f, 3485.1460f, 3741.1270f, 4297.4912f, 5207.3779f, 5672.3818f, 5980.5322f, + 434.9507f, 558.8508f, 890.7061f, 1355.7625f, 1552.6155f, 1895.7960f, 2222.5579f, 2502.6079f, 2841.8738f, 3137.5264f, 3367.7336f, 3860.7769f, 4795.2554f, 5090.9370f, 5421.8218f, 5874.4287f, + 281.0164f, 404.5417f, 729.2898f, 997.1851f, 1699.8862f, 1961.3673f, 2255.7202f, 2540.9187f, 2804.4553f, 3057.1843f, 3750.2288f, 4340.9893f, 4716.8647f, 5002.7471f, 5477.2998f, 5965.7402f, + 372.2410f, 505.3570f, 762.3755f, 997.3586f, 1174.4255f, 1986.1741f, 2368.1367f, 2624.1733f, 3194.6084f, 3403.2793f, 3877.7622f, 4425.7676f, 4824.7837f, 5158.1606f, 5532.7466f, 5893.5483f, + 367.3766f, 501.1806f, 824.5358f, 1090.6857f, 1271.9792f, 1527.7137f, 2381.4382f, 2694.4634f, 2964.5359f, 3639.4832f, 3946.4038f, 4254.3916f, 4645.8076f, 5033.5396f, 5373.8735f, 5878.4385f, + 229.4505f, 352.5671f, 701.0831f, 1226.4518f, 1678.3601f, 1895.7949f, 2140.0664f, 2526.5515f, 3080.3391f, 3297.8284f, 3845.3987f, 4427.9785f, 4704.4551f, 4997.4155f, 5434.0698f, 5918.4785f, + 336.3082f, 516.7915f, 881.9847f, 1272.5824f, 1505.1870f, 1880.7520f, 2274.9458f, 2611.0083f, 3126.5256f, 3655.5332f, 4183.3877f, 4668.2993f, 5004.0029f, 5305.3491f, 5650.4985f, 5943.7383f, + 296.0867f, 469.6519f, 956.5997f, 1224.1262f, 1443.0049f, 1727.6880f, 2216.1677f, 2689.3677f, 3060.4456f, 3520.9438f, 3916.6050f, 4343.7954f, 4763.8906f, 5156.0132f, 5553.8115f, 5936.9634f, + 407.1503f, 577.5120f, 839.7361f, 1455.3907f, 1665.2137f, 1935.0054f, 2398.0537f, 2652.2605f, 3111.1831f, 3505.5962f, 3766.7554f, 4204.8730f, 4699.1631f, 4970.8652f, 5295.5962f, 5695.6919f, + 281.0083f, 361.8386f, 950.9102f, 1464.1158f, 1634.7019f, 1965.4950f, 2211.1406f, 2662.1055f, 2846.0122f, 3585.8884f, 4048.7148f, 4358.9150f, 4683.8755f, 5046.0908f, 5400.0859f, 5956.1040f, + 279.1811f, 393.9142f, 876.8306f, 1502.2417f, 1673.0590f, 2288.7161f, 2545.3674f, 3028.9507f, 3517.5840f, 3824.4246f, 4144.8486f, 4481.8140f, 4821.2769f, 5162.3975f, 5542.8560f, 5928.5854f, + 379.7892f, 500.9199f, 725.0223f, 998.7143f, 1179.6127f, 1771.9886f, 2775.4812f, 3136.8457f, 3378.6143f, 3674.0188f, 3946.3604f, 4184.4824f, 4521.5454f, 4934.8940f, 5315.5029f, 5759.7544f, + 317.4339f, 442.2628f, 778.7388f, 1167.8633f, 1356.1576f, 1578.5603f, 1840.1584f, 2870.7527f, 3236.1504f, 3502.7249f, 3876.3696f, 4100.5244f, 4650.2632f, 5235.1890f, 5665.2285f, 5999.0649f, + 350.2696f, 492.2163f, 763.0640f, 1264.7550f, 1515.0244f, 1755.7783f, 2489.3274f, 2898.6252f, 3143.1018f, 3643.0640f, 4035.0657f, 4255.0889f, 4641.7231f, 5138.5107f, 5557.1318f, 5920.2402f, + 301.3833f, 464.9852f, 762.3419f, 1012.2126f, 1803.5172f, 2192.4214f, 2651.6287f, 3013.6697f, 3251.3591f, 3539.4675f, 3946.3433f, 4469.3560f, 4890.7446f, 5200.4878f, 5509.6753f, 5910.2397f, + 253.1752f, 356.8990f, 630.3325f, 1163.1683f, 1528.6230f, 2023.4438f, 2488.6001f, 2745.5627f, 2933.7024f, 3237.4414f, 3976.9258f, 4415.2534f, 4789.9131f, 5194.3423f, 5714.6445f, 6032.4160f, + 265.1815f, 364.7549f, 590.0148f, 805.2595f, 1564.7582f, 2150.6536f, 2365.6501f, 2598.7876f, 2861.5334f, 3514.1265f, 4005.6328f, 4609.3091f, 4955.4478f, 5238.4116f, 5519.5884f, 5890.7925f, + 209.3544f, 313.1497f, 503.2642f, 949.4504f, 1729.7280f, 1912.6814f, 2117.5051f, 2498.6272f, 3284.6587f, 3810.8555f, 4105.0195f, 4349.5151f, 4770.3682f, 5210.2910f, 5585.1533f, 5970.3638f, + 302.3150f, 415.6502f, 684.1018f, 922.3598f, 1489.4418f, 2235.6252f, 2449.9773f, 2800.6938f, 3061.3721f, 3526.1001f, 3905.8174f, 4170.7891f, 4446.4209f, 4907.9937f, 5470.7158f, 5914.7261f, + 264.9068f, 366.4342f, 582.8182f, 790.8568f, 1619.4548f, 2034.0782f, 2337.6724f, 2632.1714f, 2933.2356f, 3430.1858f, 3815.0198f, 4276.3931f, 4748.3149f, 5164.0098f, 5553.3320f, 5974.9092f, + 249.6359f, 361.9234f, 581.9844f, 841.1097f, 1657.5543f, 2184.4114f, 2525.9739f, 2820.0503f, 3120.7190f, 3623.7678f, 4050.5435f, 4434.5742f, 4802.6782f, 5171.8438f, 5575.0068f, 5963.7402f, + 290.1085f, 404.2538f, 664.1223f, 878.2748f, 1237.1085f, 2237.4707f, 2497.5647f, 2957.7786f, 3289.3928f, 3626.5276f, 4190.9243f, 4594.6450f, 4981.7456f, 5283.5513f, 5617.1538f, 5938.3760f, + 182.7846f, 270.3831f, 490.2131f, 1070.2524f, 1674.5724f, 2092.4905f, 2524.1472f, 2929.3523f, 3334.8005f, 3712.0061f, 4101.2896f, 4475.7324f, 4866.1919f, 5231.7559f, 5606.4077f, 5960.9644f, + 286.7701f, 386.1487f, 577.4210f, 764.3087f, 1151.2404f, 2014.4502f, 2399.8547f, 2879.0371f, 3160.2502f, 3450.6274f, 3869.8240f, 4368.3618f, 4816.7861f, 5187.6450f, 5564.7231f, 5962.0386f, + 179.9538f, 266.0682f, 647.9122f, 1380.2810f, 1776.1240f, 2208.4592f, 2590.6843f, 2993.6758f, 3368.2034f, 3753.2156f, 4125.2124f, 4508.6050f, 4878.9932f, 5249.3291f, 5612.5049f, 5965.2134f, + 309.2416f, 434.7111f, 724.6614f, 936.5360f, 1264.9886f, 2272.1338f, 2548.4519f, 2904.0798f, 3313.4990f, 3579.7854f, 3914.5811f, 4297.5938f, 4756.9072f, 5163.2017f, 5592.2822f, 5943.7222f, + 256.9009f, 393.7155f, 769.3966f, 1200.9640f, 1774.4797f, 2307.9629f, 2794.6799f, 3165.9431f, 3507.7952f, 3840.5791f, 4142.8877f, 4453.5078f, 4790.6973f, 5142.6123f, 5530.5977f, 5923.2188f, + 394.1425f, 602.0079f, 934.5173f, 1352.9718f, 1813.9639f, 2172.5435f, 2603.7295f, 2963.9590f, 3335.2344f, 3732.0515f, 4120.0151f, 4487.9668f, 4877.6294f, 5238.9336f, 5596.1479f, 5939.6489f, + 373.0307f, 665.4328f, 1227.4684f, 1524.6017f, 1947.3784f, 2361.6384f, 2778.1921f, 3134.5396f, 3462.3992f, 3752.4592f, 4069.0352f, 4404.2720f, 4782.2241f, 5145.0581f, 5541.9980f, 5932.9136f, + 449.9942f, 814.1862f, 1344.2784f, 1682.7061f, 2086.3599f, 2486.9709f, 2916.1177f, 3265.9099f, 3616.3977f, 3919.6345f, 4218.5342f, 4519.2207f, 4857.5220f, 5193.5269f, 5573.7339f, 5934.5400f, + 531.4455f, 965.7403f, 1458.5353f, 1773.3784f, 2236.0146f, 2650.9109f, 3099.2871f, 3467.1567f, 3809.7056f, 4094.6472f, 4378.5811f, 4660.2471f, 4962.5078f, 5270.9863f, 5629.4160f, 5973.6450f, + 565.5986f, 1091.1300f, 1561.4944f, 1983.5482f, 2492.8821f, 2897.5085f, 3233.5361f, 3539.8831f, 3838.6494f, 4093.4460f, 4372.1924f, 4678.2251f, 4999.2646f, 5325.0371f, 5672.8887f, 5998.9990f, + 581.0623f, 976.0275f, 1447.0302f, 1779.9243f, 2148.2158f, 2543.8347f, 2979.5061f, 3373.6099f, 3796.8259f, 4164.8242f, 4510.5493f, 4853.5527f, 5175.6318f, 5465.3647f, 5763.2334f, 6050.6582f, + 429.4613f, 802.5781f, 1229.0529f, 1512.6678f, 1835.8625f, 2216.9915f, 2625.3999f, 2995.9927f, 3379.5146f, 3764.7837f, 4156.1382f, 4532.4570f, 4906.4678f, 5262.8960f, 5626.6519f, 5970.6504f, + 224.5468f, 328.6938f, 615.8844f, 1207.4470f, 1520.9565f, 1865.9806f, 2182.4731f, 2431.4897f, 3239.3486f, 3490.9065f, 3775.7139f, 4291.4312f, 4740.0815f, 5192.0786f, 5532.9302f, 5928.7236f, + 312.1133f, 424.3103f, 716.4448f, 921.9969f, 1244.5491f, 2017.9143f, 2248.4170f, 2840.0688f, 3138.9390f, 3399.7288f, 3723.3479f, 3999.6824f, 4582.2339f, 5148.5166f, 5631.8989f, 6000.7192f, + 373.5378f, 506.7356f, 789.6149f, 942.6201f, 1695.8035f, 2021.6426f, 2323.3867f, 2649.5979f, 2853.1729f, 3169.5815f, 3524.9375f, 3848.6399f, 4261.7319f, 4978.9668f, 5505.4004f, 5924.7939f, + 503.2296f, 724.8124f, 940.3833f, 1220.5646f, 1439.8641f, 1726.9827f, 2215.5464f, 2476.0925f, 2846.8127f, 3232.0950f, 3638.5989f, 3986.3333f, 4371.3052f, 5022.0664f, 5657.4897f, 6040.3452f, + 398.3355f, 530.8898f, 835.5377f, 1058.3699f, 1327.2036f, 1814.9178f, 2114.2439f, 2515.8892f, 2754.9077f, 3094.8794f, 3598.7061f, 3981.2385f, 4605.9160f, 5110.8364f, 5550.1899f, 5953.9600f, + 327.7583f, 454.8903f, 825.9029f, 1025.4349f, 1321.1567f, 1551.4836f, 1978.2037f, 2838.9021f, 3111.9041f, 3417.3940f, 3841.0564f, 4696.0547f, 5126.1641f, 5409.5347f, 5711.7163f, 5968.3394f, + 327.1260f, 431.3983f, 721.9533f, 871.1266f, 1507.7616f, 1847.8716f, 2144.9641f, 2491.1108f, 2702.0847f, 3483.1516f, 3917.5173f, 4254.1260f, 4704.4863f, 4981.6284f, 5450.1035f, 5937.7861f, + 443.5867f, 610.7686f, 818.9614f, 999.3525f, 1181.9182f, 1884.4948f, 2243.3950f, 2522.8867f, 2993.8594f, 3196.6631f, 3835.5020f, 4233.2568f, 4506.8604f, 4985.0249f, 5544.1382f, 5980.0083f, + 395.7788f, 582.9504f, 822.1151f, 1013.0453f, 1224.6812f, 1988.4263f, 2452.4744f, 2686.4263f, 2952.8831f, 3135.0867f, 3562.5471f, 4006.6929f, 4401.7471f, 5038.5654f, 5567.4189f, 5986.0850f, + 264.3071f, 372.0398f, 616.4940f, 842.1705f, 1350.0250f, 1822.1957f, 2165.8896f, 2662.2937f, 3055.4390f, 3502.6787f, 3923.4236f, 4352.6587f, 4772.5068f, 5158.1309f, 5573.9385f, 5972.6895f, + 218.7390f, 325.2024f, 635.0441f, 1103.4701f, 1636.4287f, 2070.2615f, 2274.2910f, 2453.2002f, 3069.4382f, 3615.7065f, 3980.0811f, 4484.8662f, 4848.6416f, 5093.7163f, 5522.6973f, 5907.4048f, + 260.0797f, 461.2137f, 1049.2261f, 1334.1865f, 1628.6233f, 2014.9823f, 2413.4802f, 2844.4973f, 3232.3040f, 3661.0122f, 4069.8274f, 4466.5210f, 4857.6553f, 5234.4463f, 5608.4517f, 5954.7920f, + 301.7969f, 406.3861f, 706.7324f, 1387.1207f, 1581.4719f, 2004.7585f, 2291.9421f, 2548.9978f, 3076.8755f, 3343.1306f, 3623.1770f, 4279.7432f, 4777.6563f, 5084.3960f, 5473.4536f, 5872.0615f, + 344.0269f, 472.3550f, 776.6819f, 1455.1270f, 1611.6870f, 2012.4386f, 2417.4033f, 2621.8564f, 3318.9663f, 3709.0132f, 3944.1958f, 4299.0293f, 4776.4038f, 5184.1089f, 5545.5454f, 5913.9531f, + 332.1463f, 433.0623f, 992.1605f, 1254.8217f, 1498.4819f, 1824.6357f, 2118.3374f, 2444.6484f, 2684.8369f, 2930.4683f, 3557.4851f, 4292.9014f, 4786.7251f, 5138.2168f, 5616.2739f, 5996.8369f, + 281.7202f, 372.7708f, 1074.7051f, 1443.0428f, 1687.6460f, 1980.7075f, 2275.4241f, 2632.2017f, 2848.1765f, 3118.7881f, 3628.5857f, 4522.9585f, 4876.2163f, 5177.2739f, 5600.6675f, 5960.9634f, + 412.0151f, 535.6881f, 768.8618f, 1462.2601f, 1789.1055f, 1947.8196f, 2224.6890f, 2447.9089f, 2834.6140f, 3472.6721f, 3729.8525f, 4008.2893f, 4525.7271f, 4822.9194f, 5204.6611f, 5895.0942f, + 263.8760f, 379.7789f, 825.0498f, 1113.1218f, 1465.8749f, 1846.7463f, 2146.0496f, 2487.2766f, 2845.8447f, 3388.4800f, 3883.8447f, 4440.7603f, 4867.0815f, 5214.7280f, 5535.8149f, 5906.9932f, + 409.8116f, 583.7237f, 859.1983f, 1172.0491f, 1377.6473f, 1984.8322f, 2361.7292f, 2688.9368f, 3238.6563f, 3542.6716f, 3944.3005f, 4441.0840f, 4881.1211f, 5224.6045f, 5604.3711f, 5909.3657f, + 318.0743f, 438.8244f, 852.9153f, 1061.4503f, 1290.7609f, 1552.5408f, 2053.1118f, 2373.2883f, 2926.1560f, 3452.9551f, 4098.6626f, 4585.2773f, 4967.0898f, 5271.2720f, 5644.6709f, 5961.9585f, + 370.3631f, 496.5860f, 932.6390f, 1213.4189f, 1452.6641f, 1803.1532f, 2092.2354f, 2607.5247f, 2883.8086f, 3112.1086f, 3687.5657f, 4525.1274f, 4846.9404f, 5130.0537f, 5416.4141f, 5804.5122f, + 247.8941f, 343.9862f, 751.6780f, 1526.2566f, 1712.5012f, 2038.0667f, 2324.0371f, 2727.9749f, 3005.8975f, 3378.9817f, 3858.2002f, 4339.2017f, 4716.4580f, 5125.0918f, 5564.3589f, 5969.7163f, + 297.6552f, 401.7544f, 891.9346f, 1380.2275f, 1540.3125f, 1782.6058f, 2009.2045f, 2614.2092f, 2899.5396f, 3379.9722f, 3804.1169f, 4284.8540f, 4696.3335f, 5118.4551f, 5525.9839f, 5934.2686f, + 226.1444f, 333.4511f, 682.9995f, 1307.4166f, 1554.1943f, 1849.3679f, 2116.3438f, 2756.3567f, 3204.3018f, 3540.4106f, 4002.1895f, 4402.7734f, 4796.4395f, 5192.6812f, 5600.6841f, 5960.1855f, + 196.3791f, 299.9716f, 572.3173f, 1201.8826f, 1804.7235f, 2012.0171f, 2264.7415f, 2790.3406f, 3272.6926f, 3668.4863f, 4063.0435f, 4442.4419f, 4810.5957f, 5156.0923f, 5512.8501f, 5900.7441f, + 280.1911f, 391.5190f, 705.9903f, 1435.5063f, 1588.2345f, 2116.5032f, 2357.1875f, 2670.7461f, 3299.0071f, 3507.9336f, 4044.3057f, 4591.9023f, 4981.4575f, 5281.1270f, 5654.7158f, 5949.9263f, + 262.5740f, 370.5089f, 654.7243f, 1278.9299f, 1847.3096f, 2087.3394f, 2553.8892f, 2887.8269f, 3254.0747f, 3810.6626f, 4258.4390f, 4528.8022f, 4872.9741f, 5206.0483f, 5565.2876f, 5918.5596f, + 193.6133f, 356.3127f, 1076.8109f, 1485.8608f, 1887.7994f, 2273.1333f, 2676.7832f, 3052.3513f, 3419.1294f, 3792.5024f, 4161.7036f, 4532.6431f, 4898.5176f, 5262.0498f, 5622.8901f, 5976.4863f, + 302.7377f, 409.7598f, 899.1851f, 1176.6501f, 1531.3615f, 1933.6494f, 2229.9561f, 2819.8936f, 3031.6248f, 3807.0129f, 4118.7495f, 4412.7339f, 4704.6758f, 5012.0190f, 5351.4160f, 5892.3232f, + 421.1889f, 587.3521f, 835.9208f, 1248.0127f, 1475.8882f, 1779.3772f, 2330.6294f, 2606.6780f, 3026.0417f, 3513.8035f, 3754.6023f, 4081.0518f, 4536.3438f, 4815.9336f, 5117.6392f, 5802.9902f, + 378.0719f, 722.0884f, 1327.5808f, 1665.8940f, 1954.7782f, 2238.9473f, 2608.8538f, 2958.7910f, 3341.5112f, 3721.2021f, 4095.8457f, 4457.6865f, 4843.8672f, 5212.5142f, 5589.5122f, 5945.3730f, + 468.4631f, 962.3222f, 1541.0238f, 1919.1746f, 2347.4365f, 2650.7366f, 2927.5945f, 3166.4202f, 3451.0664f, 3757.8477f, 4109.2383f, 4467.9443f, 4858.6045f, 5211.8428f, 5593.3311f, 5951.0137f, + 422.2508f, 845.8956f, 1495.2552f, 1811.3933f, 2128.1157f, 2371.2532f, 2656.0715f, 2942.9011f, 3294.5308f, 3652.0935f, 4031.2534f, 4399.2222f, 4801.9497f, 5163.3721f, 5559.4517f, 5934.4063f, + 423.1028f, 661.7286f, 991.1974f, 1204.3813f, 1472.8564f, 2003.0298f, 2443.5833f, 2789.2795f, 3354.1692f, 3722.7822f, 4032.7351f, 4320.9727f, 4621.8140f, 4963.7310f, 5429.8203f, 5900.1465f, + 361.2513f, 485.9720f, 828.4865f, 1340.9952f, 1497.8477f, 2072.8511f, 2437.9839f, 2674.9912f, 3259.3357f, 3539.0474f, 3789.1389f, 4087.5015f, 4404.8867f, 4771.0947f, 5500.2227f, 6015.7041f, + 301.8146f, 392.9569f, 685.1938f, 1783.6246f, 2034.8542f, 2257.1614f, 2519.8713f, 2782.6279f, 3152.1135f, 3400.8662f, 3614.3801f, 3906.7375f, 4233.1968f, 4712.3682f, 5596.0396f, 5998.5742f, + 242.0591f, 371.0809f, 729.0743f, 1190.6813f, 1851.5691f, 2132.6724f, 2334.7773f, 2522.3608f, 3091.8643f, 3621.4614f, 3854.5227f, 4174.7017f, 4490.7510f, 4780.1230f, 5157.6147f, 5865.4756f, + 431.2477f, 562.1808f, 888.5207f, 1034.2062f, 1443.2480f, 2109.8850f, 2337.1443f, 2829.1870f, 3070.1301f, 3252.6370f, 3510.3967f, 4366.2236f, 4843.2139f, 5133.0537f, 5549.8911f, 5850.3252f, + 420.2594f, 668.9339f, 911.1281f, 1218.0372f, 1806.5541f, 2050.8423f, 2394.5708f, 2761.3542f, 3021.1716f, 3414.0020f, 3970.9626f, 4342.2900f, 4691.6074f, 5062.5386f, 5452.6655f, 5792.8384f, + 257.3011f, 370.8905f, 604.8825f, 1096.4209f, 1711.8464f, 1934.4335f, 2319.4717f, 2769.0144f, 3019.0200f, 3354.3726f, 4119.8809f, 4354.8589f, 4557.7979f, 4893.5776f, 5450.3042f, 5910.4136f, + 241.4264f, 347.9253f, 622.2432f, 1248.8121f, 1559.7318f, 1848.8098f, 2315.5635f, 2571.5894f, 2879.5754f, 3624.1069f, 3968.0334f, 4238.9727f, 4713.4746f, 5156.6792f, 5568.5596f, 5975.8716f, + 478.7131f, 629.4184f, 918.1857f, 1342.7815f, 1535.1541f, 1803.0487f, 2483.7764f, 2724.4321f, 2998.1257f, 3634.9932f, 3915.9443f, 4119.2837f, 4327.0283f, 4980.3516f, 5532.6880f, 5964.3052f, + 265.7818f, 373.8575f, 723.3755f, 1186.0619f, 1509.2827f, 2064.2075f, 2298.1992f, 2566.4395f, 2785.7659f, 3423.1396f, 3883.9011f, 4136.8940f, 4463.0386f, 5010.6592f, 5539.0337f, 5931.4414f, + 221.4221f, 347.7610f, 707.4465f, 1187.0800f, 1575.9095f, 1824.3983f, 1979.3307f, 2299.3174f, 2967.6799f, 3472.3381f, 3955.8469f, 4292.6079f, 4794.8745f, 5127.5181f, 5652.6729f, 5953.0132f, + 397.2769f, 510.2605f, 746.8268f, 1588.0735f, 1991.5200f, 2150.6843f, 2439.0486f, 2712.2754f, 2972.5825f, 3501.2673f, 3917.5459f, 4143.6069f, 4443.4414f, 4829.1929f, 5490.0376f, 6028.3794f, + 280.5184f, 370.6464f, 640.7120f, 1721.3899f, 1948.9806f, 2149.9592f, 2400.4678f, 2674.0542f, 3146.3154f, 3419.8850f, 3813.9553f, 4417.4497f, 4818.3652f, 5139.6323f, 5465.0669f, 5879.7183f, + 325.2418f, 431.2627f, 1008.7708f, 1271.9235f, 1527.4150f, 2066.6370f, 2242.3311f, 2883.4065f, 3180.6614f, 3352.5015f, 3756.9688f, 4386.6904f, 4857.6621f, 5189.2212f, 5514.7573f, 5856.8086f, + 451.8427f, 582.4401f, 925.8821f, 1363.4249f, 1503.2460f, 1961.5940f, 2265.6001f, 2574.4414f, 3123.0769f, 3345.1587f, 3634.3022f, 4266.0137f, 4880.8052f, 5223.5776f, 5567.8901f, 5880.3770f, + 411.0873f, 553.3847f, 809.2106f, 1023.4841f, 1189.0618f, 1786.0770f, 2121.8489f, 2454.6458f, 2947.4700f, 3220.3210f, 3828.0911f, 4218.0229f, 4831.2383f, 5322.1445f, 5727.3906f, 6033.3887f, + 310.5608f, 442.2204f, 742.7755f, 1097.5740f, 1340.9608f, 1854.4385f, 2261.6399f, 2634.8315f, 3297.8879f, 3638.6956f, 3925.8770f, 4232.9146f, 4559.9287f, 4893.5830f, 5403.0981f, 5917.7056f, + 377.5583f, 488.4103f, 945.2491f, 1234.1572f, 1416.0774f, 1666.5979f, 1932.9910f, 2746.2000f, 2997.4753f, 3216.6152f, 3559.3999f, 3843.8130f, 4359.6626f, 5014.2920f, 5560.6162f, 5992.7212f, + 285.2173f, 389.6116f, 825.5790f, 1238.8229f, 1459.6588f, 1860.8855f, 2178.6296f, 2519.1597f, 2828.0032f, 3278.8101f, 3560.8286f, 4142.0552f, 4691.0698f, 5117.7778f, 5558.7944f, 5954.6680f, + 465.7002f, 631.7491f, 914.5521f, 1340.0057f, 1562.5760f, 1844.1741f, 2186.1208f, 2483.7080f, 2901.9417f, 3190.3162f, 3474.7651f, 3873.4065f, 4240.1973f, 4761.1255f, 5428.2832f, 5958.5273f, + 340.5456f, 449.2341f, 793.7005f, 1387.7467f, 1555.8701f, 1938.7877f, 2201.6155f, 2579.5762f, 2914.9724f, 3149.8584f, 3699.3984f, 3985.6790f, 4331.7534f, 4999.4805f, 5514.6924f, 5969.4897f, + 395.8350f, 564.1188f, 774.8214f, 1276.3201f, 1721.8716f, 1864.0143f, 2267.5696f, 2790.2031f, 3003.9434f, 3377.6140f, 3917.7395f, 4167.3867f, 4465.2529f, 4936.1138f, 5464.0479f, 5905.0444f, + 324.1844f, 443.0006f, 728.8958f, 1398.6589f, 1584.1820f, 1923.8724f, 2348.0903f, 2561.5554f, 3154.5991f, 3449.1746f, 3771.7927f, 4182.1899f, 4937.0791f, 5361.6509f, 5727.7656f, 6002.7505f, + 267.1790f, 373.7663f, 703.5949f, 1173.7009f, 1390.2002f, 1905.7941f, 2177.4961f, 2703.2627f, 3022.9121f, 3308.9612f, 3798.5823f, 4187.1533f, 4703.2163f, 5136.0918f, 5571.1655f, 5966.6577f, + 272.9294f, 399.3804f, 797.7335f, 1180.1516f, 1426.4850f, 2097.2839f, 2355.4727f, 2793.8774f, 3137.1907f, 3458.7727f, 3893.6628f, 4245.8047f, 4652.3794f, 5106.5293f, 5568.1885f, 5948.3169f, + 324.5529f, 431.7663f, 759.6147f, 1494.8739f, 1668.8168f, 2110.5635f, 2427.4104f, 2672.9270f, 3170.5266f, 3448.2080f, 3717.1240f, 4034.2280f, 4375.3647f, 5041.1372f, 5666.9517f, 6014.7217f, + 306.4759f, 404.5361f, 795.7795f, 1675.9967f, 1835.0950f, 2160.6624f, 2430.8855f, 2734.2646f, 3270.1426f, 3586.1355f, 3821.9670f, 4102.0078f, 4372.9404f, 4918.9146f, 5412.0376f, 5868.5225f, + 421.3803f, 607.7995f, 813.0241f, 1286.8525f, 1827.2451f, 2026.8683f, 2333.9453f, 2730.9817f, 2988.4067f, 3303.8513f, 3759.1897f, 4057.5264f, 4441.5493f, 4890.0078f, 5212.0469f, 5672.2188f, + 423.8560f, 599.5201f, 829.0651f, 1082.6381f, 1245.9272f, 1623.7075f, 2453.0420f, 2855.6631f, 3171.3855f, 3475.5881f, 3715.4219f, 3972.1326f, 4419.1597f, 4894.0283f, 5363.8691f, 5919.2681f, + 441.2789f, 634.8879f, 921.6287f, 1189.0240f, 1368.7466f, 2012.1312f, 2383.7656f, 2638.5222f, 2975.0288f, 3163.6150f, 3433.9958f, 3838.9917f, 4186.6426f, 4856.8477f, 5559.1196f, 5977.2290f, + 349.2039f, 466.2342f, 724.2582f, 904.4043f, 1190.4492f, 1981.7565f, 2226.5554f, 2592.5098f, 2865.5525f, 3195.8196f, 3735.6345f, 4267.1660f, 4810.9893f, 5207.5093f, 5605.1445f, 5952.0361f, + 497.7713f, 719.9073f, 925.0815f, 1146.3021f, 1326.7095f, 1574.5039f, 2306.7678f, 2714.8022f, 2967.5190f, 3400.1121f, 3732.0544f, 3981.7878f, 4553.4819f, 5090.0869f, 5426.2085f, 5833.5220f, + 471.7526f, 648.3213f, 902.1542f, 1245.7086f, 1423.3403f, 1701.1757f, 2125.8530f, 2407.0481f, 2969.5583f, 3294.1296f, 3712.8398f, 4140.7930f, 4808.4668f, 5322.3896f, 5662.1255f, 5950.6211f, + 345.3843f, 485.9887f, 841.2579f, 1035.9401f, 1244.8905f, 1488.1833f, 2340.4253f, 2607.0859f, 2845.4153f, 3223.1768f, 3557.0696f, 4119.7944f, 4666.8896f, 5145.8589f, 5565.7534f, 5976.6875f, + 332.4270f, 427.5984f, 829.9191f, 1138.0469f, 1339.4468f, 1589.0535f, 1926.0630f, 2432.9331f, 2699.7964f, 3311.4355f, 3716.1003f, 4270.4990f, 4760.3647f, 5208.3950f, 5619.2080f, 5971.2715f, + 249.0114f, 381.2982f, 925.7067f, 1520.3356f, 1842.8396f, 2368.2908f, 2783.4033f, 3272.5757f, 3673.7402f, 4046.3950f, 4370.4966f, 4688.0269f, 5002.6772f, 5316.3594f, 5650.2192f, 5977.6587f, + 263.3275f, 451.6255f, 1252.2307f, 1503.0652f, 1786.7695f, 2082.7554f, 2451.1829f, 2804.7590f, 3116.7583f, 3493.8892f, 3884.6575f, 4349.6724f, 4770.0156f, 5143.1636f, 5542.5913f, 5931.5522f, + 252.9447f, 341.5762f, 632.7664f, 1766.8096f, 2084.1511f, 2272.7332f, 2531.1006f, 2765.2080f, 3134.5417f, 3380.6223f, 3640.8015f, 3932.7854f, 4532.1172f, 5245.2070f, 5597.0776f, 5973.6831f, + 234.9979f, 324.6731f, 1239.8643f, 1663.1921f, 1858.7769f, 2171.1614f, 2403.8818f, 2680.6433f, 2836.4985f, 3192.6577f, 3864.8811f, 4385.8066f, 4845.9766f, 5150.2412f, 5631.1519f, 6011.7773f, + 284.5302f, 410.1263f, 985.4119f, 1298.3987f, 1789.4304f, 1996.9287f, 2450.8525f, 2831.6011f, 2994.2073f, 3214.1306f, 3525.0498f, 3819.9141f, 4672.7544f, 5424.3545f, 5691.0732f, 5980.3096f, + 244.2704f, 415.5891f, 1038.3009f, 1317.5186f, 1686.4528f, 2081.3147f, 2476.9873f, 2959.5393f, 3214.9561f, 3569.1431f, 3934.4736f, 4308.7114f, 4728.3687f, 5105.7964f, 5488.1938f, 5908.9443f, + 335.8417f, 468.3464f, 1003.6253f, 1275.0145f, 1534.2854f, 1985.3167f, 2348.3411f, 2743.3169f, 2956.0967f, 3408.5063f, 3866.8574f, 4287.0034f, 4556.7222f, 4922.7832f, 5259.7480f, 5800.2876f, + 388.2726f, 518.0591f, 832.5999f, 1325.0247f, 1528.8624f, 1808.1732f, 2151.0820f, 2486.1331f, 2815.4980f, 3158.5391f, 3635.3606f, 3960.5383f, 4671.7686f, 5371.8140f, 5777.8940f, 6056.4722f, + 506.5153f, 673.0771f, 900.0349f, 1154.2124f, 1378.2689f, 1786.9409f, 2081.9631f, 2398.6965f, 2859.7441f, 3075.4841f, 3546.6563f, 4322.6694f, 4732.0049f, 4992.5542f, 5267.5859f, 5807.1812f, + 487.2466f, 653.6116f, 968.5656f, 1389.2708f, 1601.5822f, 1910.9694f, 2282.4038f, 2608.7063f, 3032.6233f, 3361.9692f, 3629.8552f, 3908.8335f, 4318.4009f, 4646.5781f, 5043.5962f, 5792.7393f, + 432.8733f, 591.7551f, 899.2619f, 1490.1176f, 1789.8751f, 2060.3750f, 2434.8779f, 2840.3374f, 3122.1292f, 3472.8079f, 3830.8870f, 4097.2622f, 4353.5464f, 4650.2075f, 4981.5752f, 5482.9565f, + 378.4767f, 508.5656f, 802.8280f, 947.2892f, 1532.0898f, 2038.8177f, 2349.1965f, 2650.2039f, 2863.8018f, 3591.6697f, 3918.9211f, 4256.6255f, 4604.8467f, 4899.0996f, 5237.6084f, 5791.5029f, + 407.0908f, 546.0364f, 866.1215f, 1098.6927f, 1347.2009f, 1657.1525f, 1965.5845f, 2717.7190f, 3033.4961f, 3509.9031f, 3873.4150f, 4131.4438f, 4389.5693f, 4774.2295f, 5450.1768f, 5977.5151f, + 429.3459f, 568.8134f, 903.5659f, 1099.2942f, 1379.4979f, 2207.5940f, 2479.9919f, 2780.9072f, 3206.3960f, 3425.4084f, 3682.5911f, 3950.1941f, 4324.0840f, 4689.4922f, 5068.2534f, 5787.2852f, + 371.9443f, 524.7249f, 890.0464f, 1670.7485f, 1958.5308f, 2182.7007f, 2558.5007f, 2835.4937f, 3192.0740f, 3634.4817f, 3950.0942f, 4259.6953f, 4628.0049f, 4999.1616f, 5364.9893f, 5801.6855f, + 323.1922f, 451.0327f, 787.1655f, 1011.6555f, 1323.8138f, 2177.6636f, 2401.1392f, 2826.8796f, 3432.8999f, 3653.1851f, 3883.9897f, 4082.7559f, 4361.6753f, 4635.1475f, 5084.7544f, 5823.3062f, + 377.0061f, 524.2181f, 743.6288f, 1378.9187f, 1857.6434f, 2056.4695f, 2453.7949f, 2902.1995f, 3127.2651f, 3463.3523f, 3980.1316f, 4241.2578f, 4528.5859f, 4881.4521f, 5239.3145f, 5580.5986f, + 308.7965f, 403.7058f, 705.9506f, 1823.8571f, 2126.9387f, 2369.2810f, 2647.2048f, 2855.8276f, 3209.7708f, 3498.2310f, 3747.6047f, 3972.8647f, 4254.3325f, 4574.4292f, 5087.3965f, 5890.4219f, + 274.7571f, 383.7251f, 573.6029f, 1142.8372f, 2151.7173f, 2558.8972f, 2751.9468f, 2987.4412f, 3234.3350f, 3526.0127f, 3922.9927f, 4189.0249f, 4483.3774f, 4877.1860f, 5396.7798f, 5921.8125f, + 248.5916f, 423.6264f, 1260.9626f, 1696.0492f, 1972.9108f, 2298.5972f, 2592.9307f, 2947.2292f, 3266.2227f, 3614.3572f, 3980.3892f, 4359.4067f, 4770.2842f, 5158.9058f, 5554.6597f, 5936.9043f, + 320.5471f, 429.6766f, 657.1440f, 1390.1080f, 2194.6426f, 2507.6086f, 2712.3662f, 2980.3408f, 3216.1682f, 3544.8467f, 3956.9790f, 4227.5308f, 4463.7563f, 4745.7124f, 5088.6650f, 5525.8516f, + 245.5478f, 520.3131f, 1177.0693f, 1454.0125f, 1770.2620f, 2160.8779f, 2551.2700f, 2950.2324f, 3326.8621f, 3710.4624f, 4104.3936f, 4481.9971f, 4865.9736f, 5230.6396f, 5608.5649f, 5965.6162f, + 514.5864f, 956.9897f, 1287.9597f, 1520.3473f, 1802.0631f, 2116.4980f, 2509.8552f, 2865.9822f, 3238.7510f, 3611.3108f, 4016.4353f, 4431.8457f, 4860.3442f, 5231.4814f, 5614.6016f, 5963.9976f, + 537.0523f, 932.2803f, 1380.2690f, 1709.4702f, 2079.9902f, 2446.4014f, 2859.4204f, 3229.6975f, 3623.4031f, 4012.5327f, 4373.7568f, 4724.3359f, 5078.2686f, 5397.6040f, 5721.9639f, 6028.1167f, + 452.5153f, 798.2777f, 1099.3080f, 1317.0807f, 1652.6885f, 2059.7708f, 2471.0164f, 2808.5396f, 3146.5076f, 3494.0779f, 3870.6912f, 4310.8281f, 4777.5024f, 5181.2617f, 5574.4912f, 5934.3813f, + 340.3716f, 430.5102f, 872.3513f, 1636.3792f, 1772.8615f, 2074.0161f, 2295.1008f, 2693.0037f, 3177.7710f, 3391.7559f, 3670.8718f, 4224.3926f, 4896.3877f, 5199.9883f, 5580.4512f, 5911.7671f, + 317.8269f, 414.8185f, 881.1970f, 1658.4944f, 1852.0098f, 2136.0415f, 2380.8228f, 2668.9141f, 3046.8027f, 3299.0051f, 3523.0593f, 3758.9412f, 4116.9063f, 5061.2124f, 5624.1777f, 5989.4761f, + 374.0671f, 488.0840f, 734.0546f, 1415.9261f, 1648.7783f, 1852.8462f, 2099.1895f, 2347.5562f, 2954.8359f, 3269.6714f, 3536.7920f, 4116.1743f, 4481.4355f, 4913.8838f, 5467.2817f, 5909.8779f, + 340.4291f, 448.5775f, 1041.4979f, 1426.0011f, 1637.8165f, 1968.6743f, 2210.7976f, 2647.5144f, 2913.8650f, 3131.7698f, 3429.8755f, 3722.6763f, 4104.6479f, 4969.0093f, 5574.2231f, 5978.2070f, + 254.2538f, 412.7710f, 947.8206f, 1209.3683f, 1690.4813f, 2040.7881f, 2401.4314f, 2728.0066f, 3016.2290f, 3530.3865f, 3964.6563f, 4393.6934f, 4804.2168f, 5187.9302f, 5586.4399f, 5954.8950f, + 241.0244f, 347.0750f, 835.2348f, 1601.9089f, 1786.4336f, 2134.3950f, 2396.0139f, 2848.9712f, 3239.9138f, 3623.8250f, 4029.5088f, 4400.3936f, 4797.3564f, 5195.7310f, 5596.6689f, 5965.9878f, + 309.3683f, 453.6776f, 812.9343f, 1125.9915f, 1423.5935f, 2149.2227f, 2514.9277f, 3031.3599f, 3463.7219f, 3790.7839f, 4064.0039f, 4297.9839f, 4653.4551f, 5189.7061f, 5721.2954f, 6033.0752f, + 469.4284f, 730.1902f, 973.0643f, 1170.5016f, 1572.2559f, 2084.2769f, 2567.8604f, 2963.4592f, 3286.9617f, 3580.3228f, 3882.8706f, 4335.5483f, 4859.7197f, 5258.2827f, 5627.9785f, 5957.8623f, + 454.6165f, 795.2360f, 1078.7705f, 1294.9473f, 1761.6650f, 2235.2788f, 2695.8455f, 3095.7695f, 3473.4897f, 3833.0889f, 4185.7290f, 4528.9863f, 4893.0039f, 5240.7627f, 5608.8594f, 5951.0718f, + 563.4587f, 875.8987f, 1139.0026f, 1378.2317f, 1855.7401f, 2279.7683f, 2651.3079f, 2968.4397f, 3279.4453f, 3607.2500f, 3975.5796f, 4358.3574f, 4768.7969f, 5135.3706f, 5525.3501f, 5904.2617f, + 461.7852f, 855.0644f, 1367.4387f, 1702.5593f, 2141.0093f, 2500.9055f, 2853.8596f, 3123.9744f, 3406.0178f, 3694.0481f, 4028.9985f, 4373.1113f, 4768.2891f, 5137.6895f, 5541.3721f, 5921.4507f, + 438.6031f, 753.0179f, 1269.3203f, 1630.4396f, 2027.2959f, 2350.9695f, 2672.1396f, 2957.1809f, 3250.1545f, 3546.5315f, 3894.0161f, 4249.9346f, 4666.2266f, 5061.2524f, 5490.7749f, 5904.6362f, + 543.3182f, 828.4835f, 1239.1818f, 1471.1134f, 1737.8622f, 2037.2484f, 2434.5112f, 2801.3242f, 3162.3250f, 3508.1255f, 3849.0903f, 4165.7588f, 4588.3809f, 5020.0952f, 5475.2813f, 5904.6377f, + 519.5982f, 837.6639f, 1171.2003f, 1363.0320f, 1617.4617f, 1976.1787f, 2472.0303f, 2901.3264f, 3340.7300f, 3736.0830f, 4103.3843f, 4444.8657f, 4800.9482f, 5145.6011f, 5544.2002f, 5933.0981f, + 433.3774f, 582.7663f, 899.6142f, 1150.7437f, 1321.1309f, 1947.8643f, 2557.8604f, 2733.1497f, 3240.4907f, 3634.7915f, 3855.9856f, 4058.0281f, 4364.2568f, 5096.5225f, 5659.0952f, 6013.8145f, + 424.9731f, 604.3164f, 868.1793f, 1207.7882f, 1414.2374f, 1713.2893f, 2520.2900f, 2960.8887f, 3210.8542f, 3584.5403f, 3914.5796f, 4149.8550f, 4505.7705f, 4886.9575f, 5214.5361f, 5597.8389f, + 347.0334f, 494.2440f, 753.7191f, 1451.0435f, 1700.7461f, 1925.4844f, 2605.7988f, 2870.4744f, 3173.7312f, 3758.7219f, 4112.1929f, 4400.3882f, 4866.1016f, 5165.8799f, 5433.0371f, 5781.1509f, + 318.4942f, 464.3939f, 783.5214f, 1491.0234f, 1708.4984f, 2280.2876f, 2533.3354f, 2885.1736f, 3443.7451f, 3669.8506f, 4000.6792f, 4269.6626f, 4571.2739f, 4827.2158f, 5277.3813f, 5850.4736f, + 386.8698f, 519.0056f, 725.0029f, 981.5649f, 1156.1665f, 1500.4691f, 2421.7993f, 2962.4722f, 3175.0166f, 3548.4756f, 3860.7961f, 4146.4150f, 4658.9897f, 5088.3999f, 5531.8945f, 5951.4624f, + 315.9294f, 738.5538f, 1171.9581f, 1553.7167f, 1949.9159f, 2319.6641f, 2707.5493f, 3069.2996f, 3444.6157f, 3811.2139f, 4177.5469f, 4545.6943f, 4905.0444f, 5271.3926f, 5622.6831f, 5974.4141f, + 216.5136f, 598.1122f, 1059.3214f, 1466.4785f, 1880.1747f, 2263.6533f, 2658.3081f, 3030.4099f, 3413.6802f, 3780.1853f, 4157.1455f, 4519.1919f, 4893.5439f, 5244.3530f, 5603.1064f, 5926.8379f, + 375.4021f, 487.0890f, 844.4013f, 1574.3596f, 1794.5249f, 2106.2878f, 2418.5217f, 2657.8938f, 3116.6096f, 3457.8625f, 3691.0596f, 3930.1062f, 4259.5928f, 4592.4370f, 5020.5078f, 5840.3989f, + 474.3148f, 724.2144f, 974.0716f, 1283.4182f, 1521.2632f, 1746.4248f, 2333.0957f, 2874.2966f, 3111.9636f, 3440.0410f, 3752.9678f, 3975.7139f, 4294.7056f, 4821.9893f, 5201.5562f, 5658.8301f, + 400.0291f, 564.9626f, 808.2393f, 1083.2745f, 1300.4403f, 2080.7405f, 2588.6882f, 2858.4629f, 3206.4502f, 3429.8623f, 3746.9080f, 4341.4868f, 4713.2803f, 4986.4258f, 5336.7339f, 5710.1123f, + 354.4416f, 480.1495f, 834.1089f, 1037.7775f, 1350.0652f, 1791.1736f, 2193.0159f, 2504.6775f, 2776.0623f, 3153.0994f, 4108.1357f, 4597.4082f, 4861.9688f, 5092.8613f, 5473.2295f, 5932.0332f, + 237.3935f, 346.9133f, 675.5335f, 1481.0535f, 1716.8414f, 1884.7153f, 2099.3057f, 2725.5403f, 3022.8506f, 3276.2922f, 3639.1001f, 4185.3926f, 4941.6597f, 5292.0093f, 5682.0391f, 5981.0215f, + 367.4981f, 469.7130f, 820.7811f, 1219.7736f, 1368.4479f, 1624.6671f, 1804.2581f, 2607.8589f, 2891.3174f, 3212.2432f, 3760.7290f, 4015.6111f, 4618.0068f, 5129.3213f, 5652.1582f, 6042.1113f, + 312.6796f, 415.8322f, 674.1500f, 853.7709f, 1808.7385f, 2232.5310f, 2497.8157f, 2834.2991f, 3039.7012f, 3301.4050f, 3659.2969f, 4455.9453f, 4841.4912f, 5111.6167f, 5502.2534f, 5924.6357f, + 341.9309f, 471.7513f, 758.1926f, 979.7221f, 1287.4463f, 1737.0303f, 2160.7915f, 2664.5562f, 2961.8315f, 3461.7439f, 3732.6611f, 4109.0928f, 4568.9111f, 5037.4331f, 5511.3169f, 5966.1304f, + 351.3721f, 462.1897f, 765.1075f, 946.3102f, 1322.8093f, 2292.2400f, 2503.6494f, 2819.7234f, 3079.2803f, 3297.6252f, 3571.4668f, 3872.0823f, 4337.6426f, 5079.1504f, 5562.8110f, 5942.7153f, + 435.4323f, 614.4746f, 892.8980f, 1215.9469f, 1395.9762f, 1814.3936f, 2155.9590f, 2465.0427f, 3201.6211f, 3490.9224f, 3853.2620f, 4410.1855f, 4786.0625f, 5095.0181f, 5394.4805f, 5715.3364f, + 294.6053f, 417.1553f, 1046.2922f, 1443.0247f, 1636.7180f, 1956.4248f, 2189.9697f, 2869.8071f, 3129.9385f, 3462.5681f, 3895.2805f, 4213.4541f, 4541.8950f, 5009.1958f, 5472.7642f, 5983.0063f, + 322.1185f, 446.8733f, 689.4188f, 1338.2788f, 1643.1023f, 1903.8652f, 2494.2722f, 2804.6968f, 3103.8682f, 3640.1233f, 3965.9861f, 4172.5596f, 4404.7388f, 4670.7544f, 5240.3682f, 5893.4600f, + 209.7024f, 336.5508f, 729.0126f, 1217.3285f, 1699.0111f, 1891.2837f, 2146.8486f, 2830.0850f, 3108.6204f, 3446.0396f, 3754.1230f, 3945.1038f, 4474.5806f, 5191.6987f, 5613.3076f, 5970.2695f, + 346.6580f, 470.5094f, 663.3455f, 1266.9061f, 2020.5759f, 2270.5173f, 2527.3550f, 2826.9104f, 3078.3403f, 3401.2625f, 3804.3770f, 4100.3091f, 4407.7876f, 4732.2319f, 5150.2749f, 5808.2559f, + 283.7796f, 391.4603f, 1165.6863f, 1456.1125f, 1692.9001f, 2008.4825f, 2322.7837f, 2784.0608f, 2998.5811f, 3268.5164f, 3548.9373f, 4167.1289f, 4643.9878f, 5099.2881f, 5473.0781f, 5929.8242f, + 301.0849f, 383.1578f, 692.0848f, 1648.9374f, 1873.0947f, 2109.6113f, 2345.0110f, 2613.1121f, 2922.0193f, 3170.0020f, 3405.0774f, 3881.9875f, 4778.3154f, 5092.5205f, 5445.7100f, 5920.7896f, + 509.1023f, 750.8580f, 963.8820f, 1295.3452f, 1634.8796f, 1818.7975f, 2151.1250f, 2590.3354f, 2867.5596f, 3238.7666f, 3747.2834f, 4053.8911f, 4457.8164f, 4928.0151f, 5295.3521f, 5789.0571f, + 421.8951f, 547.9814f, 967.4185f, 1153.8607f, 1461.4230f, 1813.0994f, 2155.2703f, 2570.9712f, 2777.6597f, 3048.9863f, 3432.0986f, 3729.3877f, 4395.7461f, 5028.7402f, 5486.4946f, 5951.5024f, + 340.6758f, 445.7014f, 931.8882f, 1253.4775f, 1521.9260f, 1969.5759f, 2267.5332f, 2735.0112f, 2948.7678f, 3236.5166f, 3529.5505f, 3882.3674f, 4699.5781f, 5089.6641f, 5377.7842f, 5880.7778f, + 284.1882f, 408.6918f, 786.3123f, 1670.3220f, 2042.9493f, 2265.2275f, 2691.2012f, 3035.8762f, 3334.1719f, 3863.1194f, 4276.8916f, 4571.0420f, 4996.4404f, 5336.5205f, 5647.9556f, 5944.5996f, + 300.0066f, 616.4817f, 1238.7324f, 1614.8296f, 1997.6188f, 2367.4343f, 2784.5605f, 3168.8354f, 3569.8250f, 3965.6011f, 4336.3804f, 4689.5874f, 5044.2012f, 5365.7456f, 5697.5654f, 6010.6572f, + 242.9420f, 476.8371f, 1250.6661f, 1671.6031f, 2159.6443f, 2637.7417f, 3049.8589f, 3371.6045f, 3674.8706f, 3951.1006f, 4230.6416f, 4543.2827f, 4887.4478f, 5220.5581f, 5595.2686f, 5962.1313f, + 242.6795f, 331.1335f, 635.2861f, 1801.5236f, 2084.1472f, 2264.4692f, 2506.2891f, 2799.4441f, 3236.7134f, 3489.6038f, 3859.3291f, 4424.8008f, 4964.6348f, 5298.6533f, 5640.2031f, 5988.0552f, + 254.0538f, 336.2447f, 1216.6261f, 1717.7201f, 1886.0708f, 2176.6338f, 2405.8547f, 2762.3037f, 2934.8816f, 3167.0657f, 3385.5457f, 3804.4346f, 4848.8198f, 5286.0352f, 5630.5391f, 6086.4492f, + 295.2298f, 426.2079f, 630.7856f, 1155.5609f, 1827.6831f, 2120.5283f, 2462.4373f, 2759.6152f, 2990.9526f, 3253.4216f, 3910.9834f, 4204.2754f, 4462.7944f, 4909.7529f, 5579.9653f, 5985.8579f, + 298.9633f, 410.3875f, 810.1115f, 1346.1040f, 1499.2391f, 2210.3948f, 2467.9424f, 2792.7122f, 3284.0874f, 3493.0740f, 3784.1899f, 4319.6396f, 4860.6548f, 5213.8540f, 5609.8672f, 5949.6890f, + 437.9900f, 575.3093f, 866.0077f, 1104.2080f, 1307.4966f, 1959.9323f, 2293.9365f, 2604.6704f, 2966.6514f, 3228.0056f, 3548.8499f, 4096.4424f, 4769.5420f, 5086.5449f, 5416.5317f, 5853.6909f, + 412.4955f, 569.1867f, 864.0179f, 1117.6798f, 1348.6332f, 1976.5171f, 2334.3960f, 2640.3381f, 3006.5347f, 3327.5784f, 3695.8564f, 4042.1753f, 4362.7837f, 4687.4751f, 5389.8662f, 5966.5825f, + 406.8686f, 542.0319f, 867.3541f, 1436.3810f, 1678.6399f, 2000.1501f, 2358.1204f, 2651.3806f, 3042.1216f, 3339.2766f, 3617.9963f, 3933.3860f, 4249.0278f, 4591.8530f, 5502.0400f, 6020.7910f, + 375.4336f, 519.7731f, 764.5574f, 1215.1381f, 1482.9417f, 1696.8020f, 1957.0332f, 2169.1169f, 2973.4634f, 3687.7449f, 3966.8525f, 4258.8042f, 4680.6567f, 4947.0225f, 5230.9824f, 5843.2466f, + 443.2378f, 574.0562f, 813.3345f, 1282.7894f, 1538.0752f, 1727.8997f, 2007.8584f, 2194.5601f, 2755.8220f, 3460.9243f, 3654.1399f, 4030.5530f, 4572.4727f, 4904.7847f, 5400.6147f, 5934.2656f, + 423.6246f, 540.1947f, 862.8629f, 1386.7659f, 1577.2052f, 1811.0304f, 2046.7363f, 2309.0366f, 3129.1145f, 3533.0020f, 3738.4211f, 4021.1111f, 4357.3677f, 4634.8740f, 5307.2920f, 5944.9155f, + 287.7661f, 401.5490f, 725.6079f, 950.8911f, 1186.5465f, 1490.1750f, 2114.7920f, 2562.4019f, 3028.3977f, 3519.6277f, 3940.5737f, 4339.3086f, 4765.8188f, 5172.3428f, 5582.8022f, 5971.0273f, + 382.6039f, 537.7234f, 836.8093f, 1371.3546f, 1578.9803f, 1869.8213f, 2292.5596f, 2540.8601f, 3032.9834f, 3402.5059f, 3737.0569f, 4053.9937f, 4446.6240f, 5251.8457f, 5710.7935f, 6022.2925f, + 313.2195f, 415.0511f, 690.6860f, 1561.4832f, 1815.6521f, 2059.9187f, 2345.5095f, 2614.8701f, 3006.9604f, 3291.9744f, 3590.4119f, 3996.1516f, 4365.4995f, 4853.4956f, 5465.1572f, 5954.5718f, + 361.7959f, 448.4001f, 921.3198f, 1343.1167f, 1488.6287f, 1736.7700f, 1950.8906f, 2536.0193f, 2768.7393f, 3062.4473f, 3484.6570f, 3888.5618f, 4618.4038f, 5092.6641f, 5523.3657f, 5966.6772f, + 249.5541f, 366.6601f, 684.6592f, 1203.0931f, 1642.2089f, 1961.8837f, 2227.3289f, 2421.1348f, 2660.5676f, 3229.5410f, 3822.5837f, 4232.7266f, 4782.5181f, 5127.2612f, 5570.2676f, 5978.9858f, + 287.4206f, 421.3210f, 704.0352f, 1279.8597f, 1562.7307f, 2115.4241f, 2492.4517f, 2780.9470f, 3317.3616f, 3606.1492f, 4026.6375f, 4337.9014f, 4699.6895f, 4997.2573f, 5431.1787f, 5903.8628f, + 487.9554f, 740.9349f, 1021.9616f, 1327.3262f, 1620.8544f, 1890.7717f, 2269.1218f, 2584.4868f, 2911.2896f, 3424.9221f, 3855.1670f, 4205.9272f, 4707.2466f, 5147.1846f, 5601.1152f, 5953.4673f, + 400.8269f, 513.4500f, 786.8242f, 1269.3298f, 1441.4178f, 1696.9789f, 1911.0537f, 2223.0684f, 2847.1619f, 3113.3845f, 3670.6318f, 4146.2900f, 4555.9204f, 5083.8579f, 5574.8120f, 5987.6030f, + 379.0329f, 487.7222f, 914.8179f, 1130.9854f, 1430.1394f, 1830.0769f, 2088.8796f, 2613.6855f, 2803.1633f, 3457.1777f, 4032.6118f, 4306.7344f, 4662.6899f, 4959.6348f, 5245.5234f, 5787.3940f, + 340.6941f, 451.0338f, 656.2767f, 911.5805f, 1124.9330f, 1733.8730f, 2518.7861f, 2768.6851f, 3211.3733f, 3717.7583f, 3929.6772f, 4176.2993f, 4522.4517f, 5011.5547f, 5575.8784f, 6006.7222f, + 341.5027f, 441.6417f, 807.2695f, 1060.2080f, 1251.2837f, 1478.9895f, 1750.0796f, 2594.8977f, 2924.5027f, 3401.4751f, 3852.0557f, 4292.4683f, 4718.2930f, 5159.4775f, 5562.4067f, 5972.5571f, + 313.8985f, 421.5380f, 667.2407f, 873.6023f, 1110.1119f, 2060.7332f, 2381.0916f, 2746.2288f, 3080.5649f, 3399.9905f, 3897.5884f, 4434.9990f, 5048.1343f, 5390.8149f, 5744.3931f, 6007.9326f, + 252.1832f, 354.2392f, 673.5427f, 1339.1161f, 1554.8853f, 2014.9351f, 2300.4138f, 2829.6182f, 3213.1714f, 3409.5105f, 3604.3242f, 3927.8020f, 4622.3218f, 5103.4565f, 5559.5024f, 5971.5986f, + 385.2648f, 513.7607f, 760.7678f, 983.5819f, 1175.7727f, 2134.7810f, 2592.9614f, 2822.0161f, 3232.2524f, 3445.3516f, 3750.7583f, 4094.6714f, 4401.5830f, 4753.4204f, 5549.2319f, 6034.7148f, + 220.6833f, 314.5706f, 622.2172f, 1350.8225f, 1785.5879f, 2077.5837f, 2504.2158f, 3057.6992f, 3436.0974f, 3695.2976f, 3953.4272f, 4267.8701f, 4660.6865f, 5073.6831f, 5501.9478f, 5929.9780f, + 207.8814f, 310.4071f, 646.2098f, 1270.5835f, 1542.7271f, 2079.3804f, 2440.0339f, 2843.4690f, 3272.4854f, 3657.9851f, 4061.2014f, 4444.9780f, 4841.6060f, 5224.5947f, 5620.9141f, 5972.7261f, + 326.1488f, 456.7737f, 740.3350f, 961.4597f, 1262.7579f, 2190.7178f, 2483.5300f, 2872.4180f, 3328.4910f, 3811.0334f, 4153.1602f, 4441.8271f, 4801.1802f, 5065.2988f, 5381.6309f, 5693.2886f, + 206.2046f, 328.0855f, 618.9507f, 980.9994f, 1695.9775f, 1982.3051f, 2275.5444f, 2806.0271f, 3269.5178f, 3491.2456f, 3722.1775f, 4145.9121f, 4843.1167f, 5266.8677f, 5656.8794f, 5992.1201f, + 308.1086f, 407.7706f, 806.7985f, 1045.7629f, 1401.8912f, 2108.3472f, 2331.7849f, 2952.5391f, 3174.1865f, 3374.0686f, 3645.4260f, 4292.7183f, 4939.2969f, 5250.4829f, 5607.2358f, 5932.8657f, + 267.5990f, 378.7492f, 642.2629f, 871.7917f, 1691.7523f, 2087.5117f, 2423.1462f, 2686.1487f, 3021.7893f, 3724.0247f, 4035.5454f, 4369.5903f, 4680.1167f, 4991.4175f, 5323.6875f, 5811.7471f, + 312.3856f, 437.4281f, 714.5340f, 899.5771f, 1632.7545f, 1938.5369f, 2295.5544f, 2625.6189f, 2900.5576f, 3295.4934f, 3557.1260f, 3960.1123f, 4731.6079f, 5141.8447f, 5502.7793f, 5954.0049f, + 332.2842f, 449.0976f, 875.9957f, 1206.1912f, 1422.6793f, 2097.5745f, 2354.2483f, 2715.8494f, 3093.4697f, 3344.5132f, 3623.4814f, 3889.3655f, 4256.2002f, 4994.5742f, 5593.8428f, 5985.9575f, + 286.9586f, 434.7701f, 781.3996f, 1248.3495f, 1835.5530f, 2137.1155f, 2573.7449f, 2869.9299f, 3126.0564f, 3459.1448f, 3769.4475f, 4138.3076f, 4688.0298f, 5084.9028f, 5436.8086f, 5894.2520f, + 327.0000f, 429.0804f, 663.7327f, 849.7463f, 1174.9340f, 2383.3875f, 2695.9597f, 2941.2026f, 3214.4724f, 3433.6287f, 3778.9312f, 4134.8096f, 4504.8022f, 5066.7559f, 5599.2290f, 5985.7334f, + 244.4052f, 499.2254f, 1294.8232f, 1689.3677f, 2123.5024f, 2572.4958f, 3042.9067f, 3446.8752f, 3836.3740f, 4175.6729f, 4485.3213f, 4792.3755f, 5094.9077f, 5386.1816f, 5699.6411f, 6008.2114f, + 561.9757f, 1020.3204f, 1494.1995f, 1841.8171f, 2297.0906f, 2772.6184f, 3204.8804f, 3565.8628f, 3935.4106f, 4253.4141f, 4559.7021f, 4849.9653f, 5140.2852f, 5428.6934f, 5731.2251f, 6023.5078f, + 581.6182f, 1053.5670f, 1478.5878f, 1784.4789f, 2125.1157f, 2454.5889f, 2809.0256f, 3141.7256f, 3490.7529f, 3848.5923f, 4201.7271f, 4568.7720f, 4945.9619f, 5288.6289f, 5647.7642f, 5981.9341f, + 258.9683f, 364.0963f, 722.5463f, 1763.2114f, 1969.3870f, 2265.5239f, 2532.1821f, 2883.3557f, 3388.1838f, 3725.3120f, 4080.9338f, 4390.3818f, 4716.3599f, 5068.4941f, 5452.2778f, 5847.1401f, + 271.5428f, 401.4228f, 695.5894f, 857.3072f, 1776.5358f, 2008.5603f, 2554.4143f, 2844.4021f, 3018.6877f, 3226.1279f, 3482.3398f, 3810.6858f, 4549.3071f, 5266.2764f, 5614.6157f, 5945.6904f, + 330.3132f, 444.6271f, 669.0279f, 874.5479f, 1102.9247f, 2052.1780f, 2436.2378f, 2711.1165f, 3037.7537f, 3298.2036f, 3898.6858f, 4241.5415f, 4606.7637f, 5086.6919f, 5569.7397f, 5988.6797f, + 232.3014f, 344.5512f, 578.5155f, 1213.9569f, 1880.9729f, 2105.6685f, 2335.4148f, 2550.3965f, 3147.6501f, 3491.9253f, 3791.5613f, 4159.6694f, 4642.2441f, 5103.3340f, 5605.4106f, 5989.7969f, + 346.3687f, 444.8047f, 714.3775f, 889.1195f, 1211.8463f, 2168.7598f, 2430.2490f, 2760.6326f, 3012.4961f, 3268.8750f, 3565.1558f, 4172.5791f, 4781.5391f, 5127.6704f, 5512.6323f, 5911.3779f, + 398.0477f, 553.8537f, 845.8521f, 1119.3066f, 1309.7244f, 1928.3351f, 2351.2095f, 2649.8230f, 3050.6750f, 3297.0566f, 3592.7275f, 3916.1785f, 4723.3325f, 5318.1221f, 5703.9697f, 5996.7651f, + 371.4409f, 471.0789f, 896.4924f, 1197.7544f, 1400.8007f, 1611.1555f, 1867.3550f, 2818.4475f, 3002.5906f, 3250.1440f, 3546.5891f, 4265.0371f, 4890.3369f, 5274.4722f, 5659.3560f, 5946.9644f, + 330.9331f, 448.7211f, 808.3973f, 978.2021f, 1652.6361f, 1969.0725f, 2357.0146f, 2680.4792f, 2859.9165f, 3078.9578f, 3423.6895f, 4233.3169f, 4856.7813f, 5086.5723f, 5393.9961f, 5938.6035f, + 323.9659f, 433.8731f, 1045.5168f, 1369.1907f, 1561.9178f, 1984.2457f, 2224.0959f, 2747.3657f, 2995.0359f, 3242.9248f, 3501.0344f, 4022.2388f, 4847.4985f, 5210.9922f, 5658.1357f, 6005.0718f, + 354.6574f, 501.6520f, 852.5305f, 1020.8707f, 1540.5925f, 1998.5675f, 2253.1487f, 2845.3960f, 3056.5273f, 3305.0466f, 3954.2900f, 4591.7471f, 4915.2856f, 5221.9082f, 5544.7285f, 5879.9150f, + 363.1311f, 474.7310f, 907.5490f, 1106.8586f, 1367.2662f, 1646.6934f, 2031.3650f, 2326.4382f, 2568.6519f, 3030.1091f, 3905.6482f, 4265.9111f, 4716.1831f, 5017.0454f, 5469.8149f, 5958.6182f, + 379.9262f, 524.4459f, 845.4813f, 1275.4414f, 1458.2488f, 1772.5863f, 2067.7981f, 2526.8850f, 3066.4063f, 3307.8713f, 3807.2900f, 4199.1509f, 4452.4653f, 4854.7471f, 5464.8833f, 5947.7842f, + 371.8218f, 483.9148f, 778.2747f, 1208.0812f, 1366.3983f, 1623.4895f, 1798.8777f, 2224.6445f, 3103.7175f, 3386.0408f, 3782.8284f, 4307.4727f, 4698.8994f, 5118.1255f, 5505.1919f, 5921.1724f, + 217.9059f, 323.3224f, 639.7305f, 1026.5331f, 1312.9242f, 1885.6948f, 2361.8403f, 2805.5396f, 3213.2600f, 3631.5017f, 4033.4087f, 4426.3423f, 4821.3203f, 5208.3833f, 5590.5205f, 5956.1538f, + 211.9971f, 311.2018f, 504.6345f, 858.3289f, 1574.7019f, 1934.9866f, 2381.4163f, 2786.2043f, 3238.9326f, 3611.0518f, 4005.2578f, 4401.0615f, 4802.1479f, 5192.5493f, 5587.1479f, 5965.5977f, + 219.3884f, 319.3835f, 604.0102f, 1114.8630f, 1481.3870f, 2036.0469f, 2303.4883f, 2616.1384f, 3253.6335f, 3556.5107f, 3946.6567f, 4520.3555f, 5091.0479f, 5416.3037f, 5748.5737f, 5946.5757f, + 350.3716f, 515.4462f, 756.5206f, 1061.4270f, 1251.9570f, 1723.2751f, 2687.6689f, 3036.2019f, 3273.9678f, 3744.2939f, 4098.6284f, 4391.4160f, 4917.6777f, 5244.2852f, 5551.4976f, 5880.1572f, + 311.6069f, 458.7317f, 795.9418f, 969.5021f, 1511.2507f, 1952.5673f, 2273.6116f, 2795.8657f, 3049.7053f, 3578.0598f, 3911.1873f, 4327.2598f, 4735.3105f, 5122.3423f, 5479.7817f, 5858.1504f, + 267.8399f, 390.6757f, 886.2357f, 1179.5110f, 1466.6409f, 2088.7725f, 2328.1262f, 2993.5786f, 3283.5256f, 3593.2822f, 4095.7588f, 4500.4009f, 4887.5132f, 5219.0859f, 5553.4224f, 5915.6831f, + 279.2209f, 413.3200f, 648.4438f, 1282.1798f, 1793.2556f, 1952.1060f, 2484.9436f, 2857.3630f, 3077.2114f, 3548.2585f, 4045.4526f, 4309.5947f, 4760.2900f, 5208.1948f, 5620.9717f, 5968.3237f, + 306.2321f, 424.7843f, 618.7867f, 1288.7572f, 2110.7849f, 2346.5396f, 2582.5366f, 2833.5730f, 3074.3774f, 3464.7886f, 3984.6379f, 4262.0337f, 4601.5132f, 4999.6992f, 5498.8926f, 5920.4814f, + 259.2613f, 353.6931f, 762.5328f, 1906.2162f, 2088.1213f, 2317.9741f, 2546.5935f, 2880.3687f, 3332.0002f, 3636.9216f, 3946.4287f, 4226.0356f, 4502.1084f, 5007.0601f, 5496.4824f, 5924.8877f, + 244.3871f, 357.0287f, 1114.7865f, 1651.1329f, 1850.2976f, 2200.5942f, 2484.7026f, 2872.6968f, 3092.8455f, 3373.5869f, 3707.5891f, 4180.1289f, 4603.5298f, 5132.2671f, 5554.7617f, 5973.5220f, + 700.5439f, 1363.5277f, 1745.2494f, 2081.9539f, 2379.8628f, 2623.6003f, 2883.6484f, 3133.9824f, 3457.7092f, 3819.0100f, 4191.0537f, 4547.0400f, 4912.5127f, 5241.3423f, 5594.9395f, 5930.6099f, + 268.7704f, 370.8200f, 609.4679f, 1558.5339f, 1961.6279f, 2155.8916f, 2419.4485f, 2655.5103f, 3152.6685f, 3426.9221f, 3716.8181f, 4107.1616f, 4965.5698f, 5384.2026f, 5706.7183f, 6015.6196f, + 305.7638f, 395.9599f, 1103.0944f, 1383.6494f, 1612.9742f, 1915.2496f, 2189.8008f, 2555.3608f, 2720.8220f, 3038.2434f, 3927.1301f, 4263.0518f, 4685.7217f, 4984.1377f, 5272.6162f, 5984.5376f, + 294.0385f, 426.7762f, 814.5162f, 1056.9037f, 1715.3539f, 2005.3177f, 2316.4392f, 2647.4297f, 2893.8242f, 3196.7476f, 3720.0044f, 4186.9790f, 4840.4512f, 5290.1250f, 5684.2139f, 5967.5859f, + 359.5141f, 517.6051f, 807.4898f, 1143.5930f, 1328.1393f, 1814.7098f, 2309.8894f, 2618.8655f, 3160.5962f, 3445.0479f, 3883.2664f, 4235.5200f, 4718.7324f, 5367.3608f, 5765.9331f, 6034.9233f, + 241.5752f, 375.5109f, 818.8776f, 1298.7773f, 1656.9050f, 2169.8962f, 2565.1440f, 3015.9919f, 3437.9463f, 3863.8203f, 4254.4023f, 4637.0952f, 5027.8252f, 5358.3784f, 5685.5000f, 5980.4063f, + 322.5406f, 454.9644f, 963.3659f, 1513.8885f, 1704.5070f, 2235.6599f, 2523.6467f, 2995.0757f, 3287.8682f, 3552.8811f, 3872.4360f, 4201.2227f, 4571.9087f, 5066.6792f, 5562.1206f, 5935.7900f, + 412.5748f, 615.8419f, 1126.9519f, 1455.5172f, 1653.3076f, 1965.2689f, 2240.6904f, 2672.5129f, 3127.3301f, 3477.8540f, 3983.6145f, 4458.6558f, 4896.7998f, 5237.9814f, 5609.1597f, 5939.6416f, + 342.1361f, 470.6100f, 958.3576f, 1195.0166f, 1426.4667f, 1684.2009f, 2194.0950f, 2545.9453f, 2946.1851f, 3415.2820f, 3657.4158f, 4408.6763f, 5097.2251f, 5404.2202f, 5719.9829f, 5977.7959f, + 297.8767f, 386.6347f, 1095.8346f, 1454.3085f, 1651.6417f, 1927.9633f, 2198.4927f, 2583.1694f, 2757.0144f, 3009.6497f, 3310.9514f, 3956.9753f, 4677.3208f, 5122.2222f, 5539.0688f, 5993.0542f, + 334.7170f, 450.1582f, 747.3162f, 1560.2024f, 1808.2147f, 2006.5011f, 2415.2419f, 2680.1956f, 3016.5549f, 3651.1340f, 3975.3625f, 4209.6563f, 4531.0396f, 5121.7212f, 5585.2202f, 5962.3667f, + 256.4101f, 495.5723f, 1341.4860f, 1805.1255f, 2201.8318f, 2514.7769f, 2820.4092f, 3102.3867f, 3414.3872f, 3754.7742f, 4108.2378f, 4465.9258f, 4857.4355f, 5216.2144f, 5592.3076f, 5951.9995f, + 530.7974f, 1017.4255f, 1463.9575f, 1858.6631f, 2360.1265f, 2770.3811f, 3106.0894f, 3379.1919f, 3647.7175f, 3895.9026f, 4188.8652f, 4522.8984f, 4893.7954f, 5241.4312f, 5623.8994f, 5975.3608f, + 597.1553f, 1198.0758f, 1722.7361f, 2128.6658f, 2519.1504f, 2825.5122f, 3086.1943f, 3330.0283f, 3608.2961f, 3906.9929f, 4241.8105f, 4603.1694f, 4972.8159f, 5308.1670f, 5651.1968f, 5976.6704f, + 699.1581f, 1293.3193f, 1637.3395f, 1912.7987f, 2163.3445f, 2425.7944f, 2704.0396f, 3006.5984f, 3358.2126f, 3746.1548f, 4125.0762f, 4489.7485f, 4854.0088f, 5188.5146f, 5558.2056f, 5913.3164f, + 489.0107f, 921.4806f, 1329.8511f, 1644.8383f, 2013.6794f, 2365.2683f, 2746.1553f, 3085.6912f, 3457.0234f, 3825.2183f, 4203.4224f, 4575.9331f, 4950.6606f, 5298.7559f, 5659.8618f, 5997.0015f, + 230.3653f, 389.8415f, 938.1970f, 1294.3594f, 1768.8275f, 2189.1001f, 2597.3755f, 2985.8518f, 3323.6023f, 3705.8533f, 4065.5361f, 4446.4224f, 4818.4502f, 5185.9634f, 5583.2168f, 5954.2573f, + 283.9404f, 400.2146f, 630.6198f, 1491.5646f, 2295.1375f, 2496.3457f, 2726.5803f, 2971.1951f, 3207.2317f, 3634.5439f, 4178.0376f, 4423.5537f, 4836.2109f, 5172.1821f, 5464.0454f, 5777.5801f, + 242.6232f, 351.1541f, 807.9852f, 1621.9950f, 2043.8676f, 2532.5122f, 2860.5505f, 3200.3403f, 3499.8274f, 3760.3772f, 4068.9617f, 4410.7339f, 4778.8413f, 5153.0142f, 5553.1997f, 5932.5996f, + 227.3320f, 323.2667f, 752.3189f, 1572.3750f, 1930.6083f, 2355.0117f, 2717.6223f, 2968.3215f, 3233.4026f, 3551.9622f, 3918.5608f, 4346.0190f, 4778.6880f, 5159.6172f, 5568.5566f, 5980.8086f, + 307.9120f, 439.7297f, 660.0276f, 1243.3854f, 1532.3577f, 1796.3936f, 2437.3232f, 2691.4072f, 3030.3025f, 3524.1379f, 3771.7576f, 4083.2375f, 4601.1567f, 4963.4697f, 5434.8530f, 5942.8315f +}; + +const float lsf_cdk_nb_gc_stg1[] = +{ + -50.2820f, -20.3699f, -85.9016f, -168.2552f, -219.7203f, -228.3721f, -209.7385f, -115.7139f, -70.1936f, 2.9143f, 53.7331f, 204.0881f, 324.2565f, 283.0311f, 194.2415f, 55.6127f, + -7.7024f, 55.3216f, 40.0302f, -2.6173f, -31.0254f, -49.9638f, -89.5104f, -79.9710f, -100.2947f, -84.2426f, -89.8130f, -44.4505f, 8.1330f, 123.3018f, 115.2609f, 17.5947f, + -29.7454f, 23.9522f, -6.6145f, -47.3088f, -83.6021f, -109.3905f, -118.2556f, -70.7910f, -71.2423f, -49.5609f, -49.3213f, 0.8054f, 70.8270f, 167.7499f, 132.1748f, 26.7946f, + -46.7868f, 21.9789f, 17.0331f, 1.6574f, -5.3416f, -1.5485f, -24.7294f, -2.2697f, -36.0918f, -31.9601f, -52.9409f, -18.2356f, -16.6137f, 52.8291f, 99.2958f, 9.2780f, + -48.8451f, -8.8573f, -49.2111f, -93.0997f, -116.0209f, -119.2193f, -130.6934f, -90.0435f, -85.8524f, -49.9080f, -30.8948f, 57.8291f, 207.6663f, 238.5938f, 162.1688f, 42.1291f, + 6.0599f, 96.6534f, 89.7254f, 64.7391f, 47.1759f, 39.3332f, 3.8599f, 12.1104f, -25.8483f, -30.7162f, -54.9950f, -24.3625f, -65.0093f, -91.8893f, 41.2788f, -9.3500f, + -74.6215f, -34.1444f, -45.1607f, -35.7601f, 20.1298f, 61.8053f, 45.9485f, 61.3004f, 23.1269f, 17.0184f, -14.6351f, 11.5369f, 40.6714f, 134.6762f, 127.4157f, 23.2286f, + -53.8382f, -7.1967f, 51.3428f, 149.2781f, 132.0314f, 106.9591f, 40.3082f, 28.7839f, -20.0071f, -32.1960f, -69.3754f, -44.7267f, -19.1058f, 81.8775f, 103.3263f, 11.7826f, + -83.4690f, -58.9994f, -100.6923f, -109.7423f, -77.3123f, -51.0569f, -49.0334f, -11.2254f, -13.7028f, 11.7115f, 17.4433f, 113.4333f, 269.5462f, 270.9727f, 181.4436f, 50.9590f, + 19.0904f, 106.4309f, 78.2419f, 22.1934f, -28.2661f, -71.6118f, -97.8980f, -57.5252f, -73.2944f, -59.0236f, -70.7380f, -30.7879f, -16.6118f, 71.0734f, 102.1686f, 10.6722f, + -44.5958f, 9.5910f, -9.9670f, -35.4491f, -36.7779f, -38.2726f, -71.5033f, -56.3692f, -75.3217f, -60.2630f, -64.3206f, -15.0396f, 51.1008f, 156.1136f, 128.1305f, 24.1397f, + -26.8342f, 50.7102f, 47.9495f, 34.1131f, 33.1750f, 40.6004f, 1.8381f, 6.9380f, -34.5476f, -37.5681f, -63.3813f, -32.2824f, -50.5980f, -25.5098f, 69.6276f, -1.2117f, + 6.7027f, 67.8112f, 38.0872f, -23.7302f, -79.0851f, -119.7724f, -146.1929f, -104.8024f, -107.0018f, -86.5365f, -75.9935f, -16.8613f, 84.1440f, 178.1427f, 133.5219f, 27.8811f, + 46.6789f, 157.1987f, 135.6186f, 86.3393f, 50.7338f, 16.6195f, -30.7043f, -23.0751f, -58.4989f, -58.2831f, -83.9640f, -51.4746f, -40.3803f, 39.6990f, 89.0926f, 5.3683f, + -66.8068f, -25.7930f, -49.4702f, -55.7445f, -47.4219f, -47.2327f, -55.9657f, -21.6380f, -32.0155f, -16.3766f, -23.1897f, 25.9724f, 108.6076f, 192.8678f, 143.8874f, 32.5168f, + -29.4610f, 51.1883f, 125.8174f, 178.0158f, 192.4019f, 200.6733f, 150.3214f, 139.0109f, 70.5642f, 49.0546f, 5.2967f, 10.7600f, -32.3233f, -56.1770f, 38.7244f, -6.3720f, + -90.7935f, -86.8579f, -165.1847f, -206.9982f, -177.3116f, -110.7218f, -60.4555f, 28.9968f, 59.3721f, 111.7430f, 148.9078f, 297.0840f, 382.8354f, 319.0586f, 217.5980f, 66.9906f, + -8.8907f, 51.2038f, 20.6150f, -25.0275f, -6.4919f, 28.5998f, -19.2903f, -28.0775f, -67.6854f, -70.6924f, -91.1332f, -51.9799f, 4.7191f, 121.9776f, 114.5332f, 16.9555f, + -29.5779f, 38.1348f, 16.9460f, -13.1717f, -43.7665f, -58.5053f, -66.8853f, -23.5223f, -47.7123f, -38.4358f, -52.6004f, -12.1781f, -9.5310f, 62.0772f, 102.4962f, 10.5329f, + -51.3839f, 10.1170f, 8.8413f, 7.1799f, 27.0856f, 57.8446f, 40.2151f, 55.8005f, 14.1522f, 8.5107f, -25.3037f, -4.1035f, -34.2602f, -19.2221f, 74.9812f, 1.2982f, + -9.0629f, 39.9632f, -4.2048f, -68.4062f, -125.5652f, -168.4946f, -200.3423f, -148.8132f, -131.2517f, -83.3627f, -43.4004f, 70.8276f, 231.0238f, 241.4682f, 165.0121f, 42.8259f, + 23.0736f, 143.9185f, 165.8485f, 141.1318f, 126.9031f, 113.7775f, 58.7625f, 48.6260f, 0.7530f, -14.8817f, -51.1437f, -31.9407f, -63.3610f, -68.5826f, 42.2195f, -8.3010f, + -64.7372f, -30.3666f, -13.8118f, 64.0613f, 130.9271f, 167.6980f, 130.2968f, 120.2481f, 53.8473f, 30.9594f, -13.2901f, -0.2919f, -12.6298f, 33.0601f, 89.8137f, 7.9164f, + -27.4071f, 46.5739f, 73.0324f, 90.7500f, 97.4257f, 110.0360f, 75.8612f, 77.2110f, 30.1418f, 14.8390f, -22.5191f, -7.5352f, -58.3772f, -104.3289f, 27.0985f, -11.5599f, + -48.6199f, -8.4983f, -71.8930f, -149.9820f, -149.4210f, -44.3473f, 3.8456f, 37.8226f, 11.8655f, 4.7745f, -23.8053f, 15.0402f, 99.2230f, 190.4169f, 143.6005f, 32.2851f, + 15.9306f, 86.2159f, 75.9614f, 40.8587f, 13.8614f, -5.1135f, -53.5447f, -49.2651f, -83.1781f, -77.3701f, -94.7805f, -58.1423f, -37.1552f, 59.5436f, 95.8876f, 7.8334f, + -71.4812f, -18.0191f, -10.6353f, -10.9646f, -4.7830f, 7.0689f, -8.9645f, 17.0751f, -8.9055f, -4.5033f, -26.7167f, 6.5207f, 41.1034f, 136.7648f, 126.6881f, 22.6529f, + -13.3071f, 67.8215f, 50.5701f, 22.0055f, -0.1895f, -16.2081f, -44.2669f, -15.2243f, -42.5961f, -37.7900f, -54.1335f, -14.8001f, -44.7622f, -39.3502f, 68.9017f, -1.9700f, + 54.4719f, 135.4882f, 107.6822f, 37.1723f, -15.7729f, -58.2111f, -117.6718f, -111.5628f, -125.9742f, -95.3344f, -71.1785f, 20.4405f, 178.9972f, 225.0608f, 154.3984f, 37.7039f, + 199.1418f, 301.5473f, 242.3446f, 156.1444f, 129.3343f, 112.5769f, 60.9076f, 24.7294f, -36.1788f, -44.7856f, -49.6138f, 35.8621f, 132.4271f, 180.8326f, 145.9355f, 30.7412f, + -95.8307f, -73.4794f, -76.3260f, -32.8480f, 25.0377f, 53.0367f, 47.9260f, 71.8612f, 48.9617f, 48.0805f, 31.5298f, 92.4644f, 215.5727f, 252.6642f, 172.3081f, 47.3738f, + -2.1387f, 144.6784f, 257.4241f, 293.7984f, 302.9054f, 301.4404f, 234.6555f, 199.2878f, 117.8049f, 82.4572f, 28.1316f, 27.9394f, -20.8952f, -53.5108f, 47.9862f, -3.2292f +}; + +const float lsf_cdk_nb_gc_stg2[] = +{ + -11.7897f, -34.0201f, -78.3915f, -67.4130f, 11.6646f, 27.0897f, + -25.4365f, -16.9519f, 1.3623f, -14.4721f, -40.8934f, -28.8082f, + -17.5541f, -24.8863f, -42.0546f, -57.4396f, -48.2462f, -17.3640f, + -23.4838f, -18.0105f, -23.4463f, -23.8641f, 20.1374f, 22.8944f, + -27.9673f, -51.2149f, -32.0136f, 58.4191f, 66.0445f, 33.8922f, + -28.8229f, -24.7667f, 12.6486f, 32.0241f, 14.4964f, 5.0635f, + 11.7718f, 12.7508f, -18.2755f, -64.0918f, -88.2808f, -46.2724f, + 11.7478f, -4.0560f, -28.8370f, -15.2873f, -17.0688f, -21.2716f, + 21.1704f, 4.6685f, -15.1944f, 19.2773f, 48.9464f, 24.7768f, + -31.9223f, -48.4027f, -40.5826f, -2.3521f, -7.7634f, -9.3639f, + 49.8116f, 38.9864f, -9.6274f, -43.4792f, -14.3368f, 6.7127f, + -17.8859f, 16.5261f, 17.9780f, -18.2431f, -4.9259f, 4.9691f, + 34.1057f, 28.5456f, 37.3357f, 25.9730f, -12.0323f, -14.3174f, + -35.7203f, -11.7712f, 71.0202f, 87.9962f, 53.5089f, 22.0342f, + -29.0835f, 7.8202f, 61.7147f, 30.4243f, -7.0096f, -12.3327f, + 121.0591f, 124.7827f, 86.3632f, 52.5283f, 25.7588f, 2.2977f +}; + +const float lsf_cdk_nb_gc_stg3[] = +{ + -20.1057f, -62.1359f, -90.9211f, -83.2088f, -41.8080f, 4.3801f, 64.9293f, 55.2259f, 18.8953f, 8.4560f, + -12.4851f, -29.8479f, -46.3014f, -59.0597f, -57.9280f, -55.5646f, -16.2912f, 29.7501f, 6.4438f, 1.9289f, + -42.4234f, -57.2848f, -42.1410f, -25.0914f, -20.5850f, -22.9466f, -28.6753f, -9.5206f, -2.8536f, -2.4606f, + 2.9437f, -3.2337f, -19.4418f, -30.8279f, -40.2200f, -54.7107f, -69.2608f, -36.5696f, -14.6763f, -7.4390f, + 56.9685f, 42.9405f, 2.6357f, -28.9316f, -41.7842f, -41.1244f, 7.2469f, 37.7725f, 9.4299f, 3.8716f, + -13.4056f, -11.0915f, -7.8932f, -4.4242f, -3.6432f, -6.2205f, -52.2374f, -101.3244f, -31.8836f, -12.9959f, + -49.5845f, -68.9839f, -40.9861f, -4.8425f, 25.7585f, 49.5206f, 52.3506f, 42.0803f, 18.1566f, 7.3750f, + 7.9175f, 30.0116f, 39.2961f, 39.8519f, 33.8428f, 18.7027f, -42.1156f, -114.4817f, -41.9139f, -14.3475f, + -10.3140f, -13.1813f, -8.6771f, -12.5086f, -7.9996f, 8.1476f, 62.8062f, 70.2916f, 23.1315f, 10.3555f, + 7.8827f, -9.7751f, -27.3751f, -19.0843f, -3.1083f, 5.0911f, -8.9477f, -1.9864f, -0.0476f, -1.0431f, + -25.6990f, -1.3466f, 13.9307f, -1.5450f, -21.5161f, -36.5054f, -27.3657f, 9.1052f, 0.5716f, -0.5675f, + 26.0226f, 39.0806f, 25.3016f, 10.6567f, -7.6451f, -27.7012f, -57.9450f, -49.0041f, -17.4613f, -8.2350f, + 24.7306f, 40.5991f, 39.1729f, 32.6364f, 20.0500f, 9.7588f, 17.8440f, 32.3000f, 10.7014f, 4.0975f, + -31.9825f, -23.6145f, 19.2348f, 43.8139f, 32.4545f, 14.8018f, -12.9031f, -14.2377f, -3.4099f, -2.2026f, + 17.4813f, 29.7370f, 40.6045f, 56.0407f, 77.3266f, 109.6360f, 126.9981f, 90.0105f, 41.2847f, 18.3934f, + 62.0530f, 98.1263f, 103.5605f, 86.5243f, 56.8051f, 24.7345f, -16.4333f, -39.4116f, -16.3685f, -5.1868f +}; + +const float lsf_cdk_nb_vc_stg1[] = +{ + -47.8739f, -33.3324f, -111.7403f, -187.1021f, -217.8067f, -211.2333f, -197.1951f, -112.5993f, -54.4085f, 25.6601f, 103.3922f, 273.8963f, 384.4787f, 321.9756f, 214.8825f, 64.7502f, + 5.7213f, 62.0822f, 4.1813f, -75.3379f, -130.0791f, -169.8000f, -137.2333f, -8.1913f, 9.1551f, 12.5919f, -10.2666f, 24.1670f, 78.8903f, 170.0603f, 136.5900f, 28.5131f, + -61.2759f, -38.8420f, -92.0781f, -106.8447f, -84.5683f, -75.2343f, -90.1177f, -57.8575f, -57.3309f, -23.0973f, -6.5859f, 96.8941f, 263.0488f, 266.3097f, 177.9874f, 48.9404f, + -4.6756f, 65.2555f, 47.7555f, 30.0066f, 28.7910f, 33.2401f, 1.0363f, 13.6479f, -20.0856f, -24.5283f, -44.3793f, -10.0354f, -56.2017f, -77.3347f, 55.5984f, -6.2838f, + -40.8653f, -14.8363f, -92.0112f, -175.7323f, -221.1710f, -161.1121f, -52.8429f, 37.5645f, 41.2468f, 45.5229f, 26.4500f, 86.3998f, 219.2824f, 253.3986f, 172.4165f, 46.3912f, + -35.6673f, 17.5904f, -11.9410f, -25.7858f, -8.8584f, 21.6273f, 0.1729f, 6.5783f, -34.6991f, -36.4150f, -56.0023f, -21.0789f, -19.8846f, 54.1067f, 99.1987f, 9.4728f, + -14.2776f, 27.3931f, -14.6997f, -66.6010f, -99.6813f, -122.6578f, -150.2305f, -113.9728f, -109.1274f, -78.9555f, -60.2257f, 27.8011f, 190.2385f, 229.8084f, 157.2525f, 39.3867f, + 7.6929f, 67.9322f, 38.8456f, -21.1201f, -59.7777f, -99.3488f, -141.1098f, -110.2669f, -114.7237f, -91.8703f, -77.7551f, -15.8694f, 90.5305f, 184.5058f, 136.0935f, 29.0311f, + -81.2402f, -78.5803f, -151.4014f, -172.9501f, -128.6324f, -73.2223f, -54.4444f, -10.0382f, 0.8191f, 49.8313f, 85.4796f, 237.9407f, 375.9963f, 320.3293f, 212.6340f, 64.0690f, + -7.5501f, 56.9796f, 22.4374f, -12.3837f, -25.5942f, -46.4205f, -67.6393f, -25.5805f, -48.1321f, -39.6622f, -53.1014f, -11.2472f, -23.2435f, 35.6549f, 94.7977f, 6.9705f, + -35.2312f, 5.7296f, -40.3538f, -74.0301f, -73.9051f, -78.4101f, -69.6657f, -23.5663f, -38.8351f, -23.3996f, -29.2527f, 14.7714f, 60.7441f, 159.3770f, 132.0680f, 26.1624f, + 63.7916f, 158.4710f, 108.6537f, 49.2831f, 12.4814f, -34.2755f, -68.0055f, -38.2006f, -61.2743f, -54.7496f, -73.2102f, -37.3536f, -2.8530f, 99.6502f, 109.4658f, 14.7136f, + -46.8550f, -17.8951f, -73.5817f, -109.9269f, -59.6995f, 13.9228f, 17.3227f, 37.6147f, 5.2378f, 2.5800f, -15.0369f, 23.6412f, 86.2658f, 178.2385f, 140.5764f, 30.3354f, + -64.0179f, -34.7786f, -33.8634f, 32.5490f, 41.5821f, 30.0052f, 2.8933f, 7.9098f, -23.6020f, -21.4437f, -40.3389f, -5.3147f, 46.4389f, 149.8765f, 129.5062f, 24.3633f, + 53.2208f, 88.2962f, 18.1083f, -68.6983f, -163.9225f, -257.5996f, -286.3273f, -136.1982f, -54.0297f, 17.4621f, 96.5930f, 257.5079f, 374.4247f, 316.8143f, 211.5481f, 63.1783f, + 174.9770f, 220.4714f, 114.9514f, 39.1980f, 15.6628f, -57.4971f, -151.3537f, -151.4255f, -122.5434f, -39.5915f, 43.3476f, 204.8011f, 347.0733f, 300.8141f, 202.2481f, 58.3570f, + -24.8002f, 5.5647f, -51.1305f, -108.2679f, -143.4691f, -168.1934f, -183.0667f, -123.7768f, -105.2566f, -53.2548f, -15.6183f, 132.2483f, 301.9698f, 276.6960f, 185.6425f, 51.4215f, + 63.0767f, 97.9030f, 23.3427f, -27.8271f, -7.6827f, 11.5110f, -9.1648f, -16.5310f, -60.2418f, -68.6020f, -79.4697f, -9.9630f, 143.1208f, 212.2018f, 148.4344f, 34.8853f, + -52.8577f, -17.0901f, -38.4446f, -44.4913f, -48.3650f, -49.3479f, -79.7237f, -66.0328f, -77.9226f, -56.8956f, -48.1326f, 19.1059f, 138.4749f, 210.3387f, 148.5705f, 35.3026f, + 16.4209f, 102.4966f, 100.9513f, 64.0511f, 50.2873f, 36.1014f, -21.6103f, -26.7705f, -65.0290f, -62.8056f, -83.1056f, -46.5621f, -51.3341f, 1.7945f, 78.1135f, 1.0912f, + -75.6609f, -71.8274f, -139.7561f, -117.4244f, -22.4806f, 39.5285f, 53.1389f, 65.2518f, 36.9996f, 37.9781f, 25.3240f, 92.8186f, 227.9041f, 260.3466f, 176.7927f, 48.2170f, + -18.6440f, 33.8824f, 28.5803f, 10.9212f, 5.0722f, 4.4072f, -39.6675f, -38.3990f, -75.6662f, -72.1438f, -87.2765f, -46.7029f, -6.7231f, 107.6602f, 110.8838f, 15.3706f, + 21.3981f, 74.2394f, 19.3760f, -47.0944f, -99.2094f, -138.5254f, -193.3578f, -171.5091f, -176.8980f, -112.0385f, -43.8164f, 79.0272f, 251.8247f, 251.6656f, 170.8083f, 44.5524f, + 67.4133f, 149.9282f, 118.6238f, 30.5943f, -33.2344f, -70.7200f, -120.6338f, -105.4183f, -118.8368f, -86.5003f, -64.0278f, 50.0950f, 231.7671f, 247.4923f, 167.0543f, 43.3706f, + -40.9878f, -39.3167f, -163.9672f, -281.7721f, -267.4339f, -138.3948f, -88.8411f, 0.7440f, 65.0724f, 165.9769f, 269.7260f, 427.8145f, 485.5638f, 388.7820f, 254.5937f, 84.1430f, + 12.9002f, 76.9394f, 62.5283f, 13.6656f, -10.4341f, -35.7194f, -84.1773f, -75.4588f, -98.8663f, -85.0203f, -91.0417f, -43.6094f, 6.1868f, 120.0995f, 114.3634f, 17.2779f, + -21.4884f, 29.4970f, 1.0910f, -37.4928f, -55.1841f, -66.8253f, -92.8491f, -74.1643f, -90.3904f, -72.3158f, -69.6267f, -16.2943f, 51.2075f, 158.6230f, 128.0881f, 24.5940f, + 140.4902f, 213.5873f, 167.7455f, 102.0038f, 85.7659f, 59.5426f, 9.2403f, -0.7622f, -35.6690f, -35.9801f, -58.6565f, -15.1000f, 23.5135f, 101.5155f, 111.5278f, 16.5967f, + -62.8100f, -47.2312f, -97.3130f, -60.9976f, 82.6761f, 193.9902f, 154.0588f, 118.2896f, 43.6828f, 13.9735f, -22.6650f, 0.5943f, 26.8732f, 111.3673f, 120.5305f, 20.1022f, + -44.4747f, -10.4204f, 32.1805f, 131.3261f, 157.9129f, 155.8841f, 90.2107f, 70.7406f, 9.4064f, -4.0535f, -42.4163f, -26.0150f, -39.1314f, 20.5559f, 82.2390f, 4.9553f, + 88.4086f, 134.4090f, 60.3778f, -13.5659f, -72.1912f, -160.4579f, -261.2583f, -247.6886f, -121.4628f, -13.9737f, 35.4003f, 197.3431f, 335.8232f, 294.0672f, 197.4029f, 56.5130f, + 267.3715f, 336.4754f, 224.6896f, 104.9689f, 104.5109f, 94.7971f, -20.0482f, -88.9197f, -142.8754f, -60.7279f, 30.3207f, 189.5033f, 335.5709f, 295.5561f, 200.0838f, 57.2552f +}; + +const float lsf_cdk_nb_vc_stg2[] = +{ + -9.6827f, -17.9738f, -44.2587f, -53.7409f, 10.1005f, 32.4057f, + -29.5803f, -35.3673f, -50.3175f, -49.1053f, -47.5762f, -37.2894f, + -10.3138f, -3.1171f, 2.9317f, -20.2045f, -78.9643f, -84.6932f, + 13.6252f, 8.7360f, -21.5126f, -20.8022f, -14.8279f, -30.9676f, + -28.1089f, -48.1602f, -64.6161f, -0.2872f, 108.6371f, 93.6271f, + -38.2393f, 1.9703f, 14.1451f, -7.5949f, 39.2872f, 33.7052f, + -38.5209f, -10.1299f, 61.9126f, 45.3993f, -7.5115f, -17.0167f, + 26.2164f, 20.2119f, 40.4075f, 45.2381f, -2.3925f, -17.4109f, + -19.1953f, -10.5024f, 12.6622f, -19.8408f, -40.6066f, 1.8757f, + -32.7274f, -41.0545f, -26.1793f, 15.7486f, 1.2783f, -17.0256f, + 3.5921f, 2.2211f, -27.0254f, -81.1776f, -88.9427f, -11.1151f, + 48.7753f, 42.6625f, 3.8241f, -21.1582f, 27.5770f, 36.8815f, + 6.8266f, -6.1852f, -19.6226f, 28.9512f, 50.9852f, 15.2853f, + -33.3786f, -38.1386f, 24.6782f, 95.1954f, 64.2442f, 33.4105f, + 49.0652f, 49.8207f, 29.3688f, -11.7891f, -57.3484f, -44.4722f, + 91.6464f, 85.0063f, 63.6020f, 55.1679f, 36.0606f, 12.7997f +}; + +const float lsf_cdk_nb_vc_stg3[] = +{ + -16.5483f, -67.8691f, -113.3476f, -92.9768f, -18.1549f, 21.7013f, 31.7869f, 25.1431f, 9.0112f, 3.4920f, + -7.8375f, -22.7162f, -45.0895f, -61.3419f, -64.4643f, -67.3643f, -44.8953f, -6.2556f, -7.9342f, -3.9490f, + -63.5255f, -72.6896f, -45.5471f, -30.5803f, -26.8317f, -24.4668f, -15.1301f, 4.8754f, -0.5588f, -0.8157f, + -2.2381f, 13.4403f, 16.0097f, 1.0526f, -24.8448f, -61.3997f, -91.3894f, -39.4637f, -19.2183f, -9.1265f, + -16.0140f, -32.7087f, -45.2478f, -59.4365f, -60.1819f, -31.6687f, 70.4575f, 64.2544f, 19.1841f, 9.3201f, + -8.2141f, 2.4761f, 7.4360f, 11.7049f, 14.0396f, 16.9693f, -53.7166f, -119.3159f, -33.5007f, -15.4114f, + -64.5115f, -52.5888f, 30.5453f, 56.2986f, 31.6535f, 9.3509f, 4.3678f, 13.3055f, 5.1440f, 2.0290f, + 22.3180f, 44.1101f, 48.7477f, 40.2739f, 14.9495f, -7.3707f, -10.3082f, 6.3741f, 1.0122f, 0.2673f, + -42.3440f, -58.8447f, -42.2171f, -8.0384f, 34.3873f, 59.7095f, 50.7660f, 38.7146f, 16.7582f, 7.2512f, + -0.1088f, -28.5624f, -30.3477f, -2.8206f, -1.3093f, -12.9286f, -21.2371f, -1.4331f, -2.6014f, -1.5170f, + -41.2001f, 4.7383f, 13.3788f, -12.5767f, -22.3489f, -14.4064f, 10.9753f, 22.2182f, 6.2625f, 2.5488f, + 63.9302f, 51.1717f, 10.5411f, -23.3105f, -47.9860f, -59.1260f, -29.9675f, 0.0559f, -4.8774f, -2.3217f, + 37.1022f, 14.8587f, -19.5761f, -23.3122f, 2.3273f, 32.9204f, 53.1779f, 43.4994f, 16.5403f, 7.5156f, + 48.8143f, 82.6708f, 85.7133f, 77.5688f, 56.9332f, 24.0950f, -63.9412f, -138.5729f, -45.8026f, -17.6440f, + -4.0024f, 18.2212f, 40.5425f, 57.9095f, 69.5262f, 79.8498f, 71.0971f, 51.3637f, 24.2751f, 10.9558f, + 94.3797f, 104.2925f, 88.4585f, 69.5855f, 42.3052f, 34.1349f, 37.9570f, 35.2368f, 16.3058f, 7.4056f +}; + +const float lsf_cdk_wb_gc_stg1[] = +{ + -21.1721f, -6.9787f, -78.7739f, -158.7331f, -205.5198f, -259.2706f, -287.6161f, -271.9965f, -264.8213f, -231.0206f, -194.9294f, -147.7609f, -117.1413f, -85.8077f, -63.7689f, -31.4680f, + -66.9546f, -30.5144f, -36.8376f, -53.0491f, -36.1642f, -48.5647f, -62.2295f, -55.2760f, -57.6386f, -55.8977f, -55.9952f, -40.6957f, -43.2573f, -33.7185f, -37.3113f, -27.4703f, + -18.0276f, 24.5300f, -3.1374f, -40.7788f, -39.2887f, -55.1486f, -87.4694f, -97.8466f, -113.0920f, -112.2454f, -110.4983f, -92.0446f, -80.8734f, -57.2883f, -52.4648f, -39.3426f, + -14.5043f, 41.4594f, 30.8683f, 19.7189f, 29.0785f, 7.4155f, -21.7427f, -23.9321f, -38.3113f, -41.2907f, -40.8309f, -25.7969f, -29.7702f, -20.8620f, -29.2581f, -26.0135f, + -39.7173f, -14.6068f, -62.7880f, -111.0359f, -122.7799f, -150.6084f, -167.3332f, -164.6087f, -165.9175f, -146.9592f, -135.1085f, -110.8433f, -97.6828f, -72.7079f, -64.6184f, -45.5537f, + -42.5539f, 26.5080f, 31.4593f, 1.2393f, 1.6319f, 6.6465f, 16.6621f, 35.3616f, 33.5966f, 53.0816f, 65.9800f, 78.6870f, 64.5119f, 50.4778f, 20.7076f, 7.5572f, + -2.4650f, 88.7057f, 93.4778f, 47.6900f, 47.2210f, 51.8796f, 27.4629f, 23.3020f, 8.4560f, 12.2382f, 12.4948f, 25.9549f, 18.2040f, 17.5385f, -2.2674f, -6.8910f, + -25.2995f, 40.1554f, 131.5320f, 193.8438f, 224.6298f, 213.8258f, 187.1185f, 169.5623f, 131.4438f, 108.3838f, 93.4648f, 94.1147f, 68.7427f, 48.9293f, 15.1647f, 1.4396f, + -63.4604f, -63.8774f, -152.1996f, -247.2777f, -281.1492f, -288.1032f, -252.3883f, -181.6764f, -141.4441f, -90.3039f, -56.5279f, -23.8054f, -11.9068f, -1.3377f, -7.5474f, -0.6953f, + -77.4333f, -60.8457f, -86.6258f, -86.4012f, -29.1547f, 7.2174f, 40.0438f, 63.6826f, 53.0035f, 51.5329f, 55.6684f, 68.8552f, 50.7040f, 34.0814f, 7.7594f, -2.1278f, + 30.9564f, 87.5489f, 69.5663f, 23.2907f, 13.9146f, -0.9477f, -37.0125f, -58.8950f, -99.1749f, -117.9716f, -127.4967f, -107.3465f, -91.7610f, -62.6527f, -50.4613f, -32.9533f, + -64.2954f, -37.5670f, -21.0138f, 41.6351f, 121.9423f, 170.7496f, 195.4955f, 225.2859f, 224.2241f, 223.8838f, 222.3937f, 225.7590f, 188.7341f, 143.2967f, 83.3796f, 41.8113f, + 10.6654f, 55.4135f, 18.0177f, -53.2381f, -88.7693f, -114.5825f, -122.2372f, -110.6857f, -120.7652f, -124.3872f, -136.2432f, -135.4537f, -132.9560f, -104.3421f, -82.6202f, -57.8286f, + -56.8219f, -2.2176f, 4.5106f, 4.9045f, 63.5084f, 94.3949f, 92.6963f, 98.2198f, 78.5731f, 65.0247f, 60.8502f, 70.0685f, 53.4160f, 34.2990f, 2.3436f, -13.6945f, + 62.5259f, 160.0315f, 153.0699f, 116.3367f, 94.9113f, 59.6879f, 36.7834f, 42.8554f, 34.9832f, 32.1663f, 34.2612f, 46.5764f, 32.6032f, 22.8721f, -2.2313f, -9.0276f, + -17.8885f, 81.5994f, 153.8725f, 203.3483f, 260.8972f, 308.2464f, 337.7084f, 369.5280f, 355.1932f, 340.5538f, 332.7582f, 318.9620f, 261.2268f, 196.0706f, 116.6797f, 63.9204f, + 20.6478f, 57.4084f, 3.7268f, -83.6103f, -145.3750f, -207.9262f, -235.3695f, -209.9292f, -200.7669f, -173.1530f, -148.7498f, -120.9027f, -110.3875f, -91.3718f, -83.8093f, -58.7850f, + -39.9125f, 14.8531f, -3.7779f, -42.3801f, -47.0086f, -54.0654f, -37.4186f, -7.7530f, -2.3503f, 11.8227f, 22.9690f, 37.9258f, 31.1117f, 26.1390f, 3.9131f, -4.7425f, + 13.2679f, 79.8638f, 51.3108f, -15.0032f, -39.4744f, -78.1680f, -87.2337f, -58.9813f, -51.8486f, -39.6199f, -34.6732f, -22.2829f, -24.1548f, -18.6608f, -25.3619f, -24.4411f, + -31.4295f, 11.0108f, 63.6155f, 150.7589f, 166.6739f, 132.7679f, 86.6371f, 71.7386f, 36.6906f, 13.2914f, -2.6491f, 5.5439f, -13.1750f, -13.8798f, -27.3878f, -22.3777f, + -24.3473f, 16.7839f, -21.6102f, -77.9093f, -107.7952f, -144.9666f, -139.6022f, -95.3828f, -79.5686f, -54.4138f, -40.2750f, -17.7668f, -12.9124f, -7.1218f, -21.3606f, -21.7144f, + -3.0221f, 85.8766f, 60.9027f, 16.5821f, 7.9817f, -16.4117f, -11.2119f, 17.4948f, 20.8488f, 33.8053f, 43.5158f, 54.6661f, 45.1287f, 38.3086f, 11.1080f, 2.6446f, + 6.4417f, 122.4950f, 125.6148f, 93.2892f, 108.5553f, 111.2156f, 105.3841f, 113.7573f, 102.0970f, 107.1194f, 105.9578f, 110.0393f, 89.3394f, 67.9986f, 28.3953f, 10.5845f, + 5.3008f, 132.8202f, 246.6148f, 259.5175f, 279.9749f, 270.1955f, 242.3427f, 226.1996f, 198.6216f, 175.1598f, 153.5215f, 148.0765f, 116.8644f, 82.8352f, 39.2114f, 16.4926f, + -77.2826f, -81.0630f, -142.8123f, -175.7374f, -154.6778f, -134.7003f, -107.5754f, -71.3200f, -53.8328f, -25.9739f, -7.0973f, 14.6180f, 12.4415f, 12.6191f, -3.8318f, -4.2210f, + -73.5975f, -49.6810f, -33.1272f, 10.8925f, 60.1080f, 61.8344f, 45.3548f, 45.5924f, 22.6090f, 11.2679f, 6.9455f, 18.9899f, -3.4566f, -13.0973f, -24.6136f, -17.3529f, + 93.3489f, 170.7564f, 135.3343f, 56.2893f, 22.2173f, -20.1927f, -41.3723f, -39.2133f, -50.1699f, -54.9363f, -60.2521f, -47.5990f, -54.0679f, -44.0381f, -47.1772f, -37.0088f, + -27.3811f, 60.8027f, 88.5729f, 82.6088f, 118.1956f, 140.5540f, 153.1990f, 173.3699f, 166.1148f, 168.4157f, 165.4583f, 168.4201f, 141.6623f, 111.7883f, 61.8626f, 28.6598f, + 61.0331f, 119.7275f, 83.9777f, -1.2269f, -56.5834f, -121.3104f, -176.1751f, -202.5282f, -219.9765f, -194.9138f, -167.0230f, -130.8084f, -105.0937f, -81.6082f, -73.9476f, -53.6392f, + -27.5935f, 45.9596f, 43.4074f, 35.4528f, 51.8229f, 58.2166f, 66.0162f, 87.5896f, 84.5125f, 96.2322f, 104.1692f, 116.0263f, 98.4793f, 78.3333f, 38.3067f, 15.3865f, + 174.0302f, 282.5094f, 259.6900f, 204.4108f, 189.3996f, 158.0569f, 123.9944f, 123.1922f, 118.3560f, 110.6961f, 101.0661f, 96.5273f, 78.1838f, 52.7614f, 22.4974f, 2.3781f, + 59.8885f, 245.4498f, 371.2458f, 409.7723f, 455.9382f, 450.3678f, 424.1982f, 412.1477f, 364.9408f, 325.9947f, 285.4946f, 257.5709f, 202.0349f, 150.8332f, 79.0164f, 39.6259f +}; + +const float lsf_cdk_wb_gc_stg2[] = +{ + -30.3104f, -56.7575f, -84.1487f, -72.1960f, -22.8352f, 3.3243f, + -46.3791f, -58.1840f, -25.7428f, -7.3327f, -15.5902f, -11.0671f, + -25.6715f, -22.2643f, -12.1418f, -44.6014f, -57.5933f, -25.0539f, + 20.6377f, 3.9627f, -56.7740f, -110.5344f, -99.0040f, -23.5388f, + -33.0807f, -65.7310f, -43.7344f, 59.6097f, 60.3127f, 29.3885f, + 12.2596f, 64.5636f, 86.5834f, 56.7668f, 33.1992f, 8.0321f, + -27.2580f, -0.3414f, 60.0624f, 27.3071f, -13.3937f, -18.6842f, + 24.2406f, 11.7818f, 14.7099f, 38.2644f, 1.7464f, -12.1068f, + 7.3676f, -14.0551f, -58.7823f, -43.8456f, 44.8481f, 49.4476f, + -27.1385f, -20.1290f, 3.2930f, 11.7314f, 24.8512f, 17.5045f, + 6.8143f, -14.7678f, -42.8682f, -16.1166f, -13.7942f, -20.4421f, + 1.4928f, 29.4512f, 13.1269f, -26.8534f, -7.1498f, 6.9288f, + 12.0685f, 25.8088f, 13.8913f, 37.8771f, 77.3020f, 41.3878f, + -31.3089f, -16.5767f, 72.2701f, 101.6937f, 66.1076f, 29.3520f, + 33.0047f, 43.3667f, 18.6451f, -26.2905f, -83.9726f, -67.8400f, + 103.2615f, 89.8720f, 41.6101f, 14.5203f, 4.9658f, -6.6327f +}; + +const float lsf_cdk_wb_gc_stg3[] = +{ + -41.3186f, -87.9369f, -117.0141f, -113.4593f, -76.4138f, -35.5126f, -13.8432f, -7.5581f, -3.0880f, 2.3802f, + -19.0684f, -32.7726f, -38.9479f, -44.5597f, -48.0524f, -54.3931f, -59.1547f, -53.0509f, -42.1806f, -24.7633f, + 27.3501f, -3.4361f, -42.3300f, -83.6244f, -126.2025f, -139.2743f, -121.0968f, -84.5803f, -46.8967f, -18.1514f, + -0.8794f, 7.8351f, 13.7504f, 10.5629f, -2.3365f, -27.6351f, -53.8406f, -67.9140f, -63.0094f, -41.9336f, + 9.4961f, -11.0357f, -24.5415f, -6.6821f, 20.3012f, 24.1832f, 9.4935f, -5.4294f, -16.9057f, -12.2235f, + -53.4765f, -68.3201f, -39.2295f, -10.3152f, -3.0430f, -6.2765f, -10.5345f, -10.9752f, -8.2812f, -5.0682f, + 52.0481f, 94.0614f, 84.0495f, 48.7509f, 4.2751f, -40.3696f, -69.1195f, -63.3772f, -42.9216f, -24.6160f, + 10.0049f, 13.7676f, 17.2697f, 29.3297f, 46.7856f, 60.3615f, 66.0947f, 59.6799f, 45.2938f, 27.9216f, + 3.2564f, -15.2692f, -47.6037f, -66.2845f, -62.6754f, -33.3695f, 8.7487f, 22.9938f, 23.4655f, 15.0233f, + -23.6148f, 4.1981f, 21.0969f, 4.2267f, -12.9805f, -17.4187f, -2.7787f, 14.0826f, 22.1174f, 12.4585f, + 44.7733f, 31.5401f, -0.1129f, -26.8177f, -43.6473f, -45.9941f, -38.3653f, -26.4489f, -17.8081f, -11.4307f, + -21.6468f, 9.0710f, 56.6256f, 68.0223f, 58.5665f, 37.6095f, 13.9228f, -1.0286f, -7.3812f, -7.6752f, + 45.1285f, 52.2192f, 35.8172f, 24.0812f, 18.9679f, 16.9917f, 14.5014f, 8.4539f, -0.8742f, -3.9224f, + -36.6106f, -54.0904f, -50.6995f, -17.6751f, 24.5062f, 61.1192f, 77.2085f, 68.1297f, 51.1173f, 30.6627f, + 45.4659f, 77.8448f, 86.8785f, 84.8886f, 78.1169f, 70.7257f, 58.9888f, 47.0442f, 34.4050f, 19.2233f, + -40.9082f, -17.6764f, 44.9914f, 99.5556f, 123.8320f, 129.2527f, 119.7749f, 99.9787f, 72.9475f, 42.1147f +}; + +const float lsf_cdk_wb_vc_stg1[] = +{ + -28.5460f, -28.7607f, -132.3446f, -253.0434f, -312.8796f, -342.8824f, -300.5386f, -244.2990f, -209.7251f, -159.5373f, -112.6287f, -67.3791f, -48.8219f, -29.0922f, -22.2704f, -4.3572f, + -46.5981f, -22.9649f, -50.9384f, -55.9409f, -47.4823f, -67.2740f, -93.7612f, -98.1688f, -103.5437f, -102.1144f, -101.9471f, -86.9149f, -76.1870f, -53.2461f, -51.2004f, -39.3148f, + 12.7666f, 41.7683f, -13.1290f, -96.2977f, -149.3018f, -210.6122f, -234.0799f, -215.3711f, -220.5745f, -210.7746f, -191.5374f, -156.6170f, -137.7840f, -109.8098f, -92.2552f, -56.2013f, + -45.2993f, -13.6438f, -31.2795f, 0.5585f, 26.1751f, 13.9611f, 18.6252f, 28.1510f, 20.3802f, 26.9694f, 32.9577f, 42.5006f, 29.2892f, 25.1029f, 1.3317f, -5.8774f, + -65.7100f, -62.1535f, -124.6012f, -161.3454f, -151.1323f, -164.9561f, -165.1614f, -150.4622f, -139.8421f, -109.2422f, -83.0457f, -55.1891f, -45.0696f, -29.5104f, -29.5390f, -21.1071f, + -75.2456f, -87.4543f, -164.3682f, -176.4217f, -83.4371f, -28.9912f, -6.9410f, 7.5825f, -2.7413f, 1.1408f, 4.1258f, 6.3013f, -0.6780f, -0.2756f, -18.0540f, -14.7263f, + 109.2056f, 132.5509f, 37.4910f, -93.8923f, -199.5966f, -323.5385f, -370.8597f, -259.1066f, -144.1366f, -52.9207f, -7.3753f, 8.7209f, 4.6669f, 18.2182f, 35.3204f, 18.9218f, + 34.9292f, 54.1737f, -19.4212f, -84.9971f, -62.3420f, -22.1402f, -18.0859f, -54.5195f, -107.3912f, -147.4533f, -198.2396f, -216.4862f, -199.3848f, -152.0050f, -94.9586f, -38.9081f, + -43.7524f, -65.5612f, -209.2403f, -339.0183f, -315.2712f, -219.0569f, -129.2175f, -68.7060f, -44.3255f, -17.2217f, 5.9129f, 29.8303f, 18.2167f, 13.0068f, -3.9593f, 4.1232f, + -20.9014f, 30.0658f, 17.8576f, -24.7442f, -27.5837f, -29.5508f, -45.9995f, -42.7483f, -54.9773f, -59.2762f, -57.4101f, -42.5711f, -43.9485f, -38.1621f, -41.1044f, -32.5227f, + -0.5370f, 38.0716f, 14.4030f, -41.8046f, -67.6856f, -96.6404f, -122.3561f, -123.7498f, -138.9439f, -138.4913f, -136.8318f, -124.9522f, -118.9503f, -96.3028f, -81.0357f, -58.1597f, + -19.4244f, 61.2237f, 71.3972f, 25.6367f, 35.9458f, 21.4457f, -1.7383f, 3.2413f, -12.2673f, -20.9311f, -19.4463f, -5.0683f, -9.0711f, -11.3618f, -25.0494f, -19.2853f, + -30.0686f, 7.6179f, -29.1133f, -90.4660f, -97.3464f, -101.9661f, -79.7809f, -41.4927f, -30.2058f, -14.9387f, -1.3463f, 14.7957f, 5.7342f, -1.8387f, -13.7457f, -15.5035f, + -60.0474f, -62.2162f, -94.9658f, -16.5692f, 137.3642f, 195.2581f, 171.5869f, 140.1564f, 102.9256f, 81.4529f, 62.9621f, 57.0500f, 25.7595f, 5.7185f, -17.0122f, -18.2020f, + 186.4318f, 224.6768f, 114.4757f, -1.7200f, -54.2938f, -162.2942f, -260.9445f, -305.8334f, -275.9291f, -196.7974f, -106.2413f, -38.2122f, -9.9698f, -0.0348f, -3.2806f, -1.0904f, + 131.8525f, 182.9257f, 129.5468f, 39.5803f, -1.4035f, -45.6323f, -49.7229f, -34.2829f, -46.2254f, -45.3785f, -41.8506f, -32.6587f, -52.7586f, -51.1091f, -48.4846f, -48.8108f, + -7.2430f, 5.5232f, -74.0471f, -159.3008f, -202.7316f, -252.2241f, -289.9449f, -278.4816f, -262.2343f, -234.1872f, -194.1267f, -147.2734f, -119.3163f, -94.6419f, -70.6759f, -32.5601f, + -22.3081f, -6.0222f, -71.4069f, -57.5585f, 87.3579f, 111.3674f, 19.2319f, -62.1519f, -140.4286f, -175.0389f, -160.2987f, -104.7539f, -80.1002f, -50.0734f, -23.5490f, 1.6408f, + 23.3797f, 81.2481f, 31.3892f, -52.3576f, -81.9250f, -125.5061f, -125.9686f, -77.3511f, -70.4429f, -55.1778f, -44.3888f, -25.9966f, -26.5913f, -23.2118f, -31.8502f, -31.7050f, + -27.1231f, 37.7616f, 25.1095f, 15.1436f, 46.6224f, 72.7080f, 91.0447f, 118.4813f, 115.1246f, 132.4240f, 135.0095f, 145.7460f, 121.1771f, 93.8520f, 46.9298f, 19.6713f, + -19.2617f, 10.4880f, -44.5537f, -114.3566f, -130.3973f, -156.7718f, -173.2891f, -165.3661f, -167.0274f, -147.1746f, -129.2874f, -104.7640f, -95.4641f, -77.5872f, -69.6100f, -49.0499f, + -3.7184f, 35.4165f, -28.7033f, -86.2246f, -61.2082f, -15.9498f, 31.1702f, 56.3138f, 49.9412f, 77.3057f, 94.0143f, 94.3239f, 78.8126f, 62.9187f, 30.4449f, 9.8069f, + 55.4567f, 100.2570f, 28.4890f, -59.9100f, -114.0757f, -166.5609f, -236.0665f, -274.6304f, -256.7512f, -58.8984f, 6.9854f, 2.1456f, 44.3655f, 27.4061f, -65.0542f, -69.1642f, + 95.5202f, 139.3445f, 117.4449f, 81.4589f, 34.9276f, -44.4909f, -90.4718f, -127.2388f, -175.4005f, -220.3445f, -288.6741f, -303.4144f, -260.5738f, -126.2845f, -58.1968f, -29.1673f, + 3.0556f, 18.3576f, -71.4110f, -183.6864f, -237.4567f, -273.2383f, -199.6331f, -69.6698f, -37.7715f, -22.6972f, -8.8733f, 16.1036f, 11.3358f, -3.2045f, -17.9569f, -20.6306f, + 39.1896f, 96.2913f, 80.5943f, 18.4912f, -3.4620f, -34.5205f, -64.0148f, -77.2972f, -99.9022f, -107.3139f, -104.8068f, -92.0120f, -86.4257f, -73.8585f, -70.7371f, -53.2077f, + 81.1530f, 122.0539f, 53.2063f, -53.6774f, -106.3376f, -163.4776f, -180.9786f, -175.0377f, -183.3532f, -183.5190f, -169.4248f, -137.3097f, -123.3554f, -101.5521f, -94.1512f, -61.8612f, + 47.0309f, 137.9525f, 111.1768f, 67.6681f, 63.8415f, 52.4017f, 35.8194f, 35.6828f, 19.7444f, 10.1125f, 6.1064f, 10.9675f, 5.0407f, -0.1812f, -16.8272f, -19.3810f, + 42.6721f, 92.5038f, 31.4316f, -5.1224f, -6.0796f, -41.9120f, -30.0922f, 1.7396f, 15.4681f, 21.9765f, 36.6015f, 47.1275f, 37.4374f, 28.9853f, 9.1342f, 2.7556f, + -25.6593f, 22.2684f, 98.1230f, 166.4577f, 187.4970f, 165.0274f, 123.8612f, 113.1471f, 79.0653f, 48.7839f, 25.8742f, 32.9158f, 10.3013f, 1.0495f, -15.4120f, -15.0391f, + 304.7019f, 354.4388f, 217.4228f, 65.5482f, 65.3717f, 25.9965f, -93.4052f, -188.0092f, -255.0247f, -224.5901f, -158.7919f, -116.2751f, -72.5203f, -57.4171f, -28.9851f, -1.9506f, + 179.5714f, 241.9845f, 193.4582f, 112.7762f, 108.6980f, 80.4323f, 56.9618f, 58.6676f, 36.2938f, 12.8297f, 4.7285f, 10.9217f, 12.0551f, 12.0937f, 1.6504f, -14.7259f +}; + +const float lsf_cdk_wb_vc_stg2[] = +{ + -4.8704f, -25.4945f, -63.8565f, -65.1017f, -4.5396f, 12.9750f, + -51.6246f, -71.2351f, -70.8930f, -49.5365f, -41.5492f, -21.1764f, + -4.1941f, -21.5321f, -43.7546f, -75.1360f, -101.6917f, -51.6149f, + 39.1412f, 15.8593f, -34.7315f, -30.9497f, 5.4101f, -22.1983f, + -27.3812f, -44.2900f, -51.8477f, 17.0318f, 63.3214f, 33.3719f, + -42.1936f, -38.7776f, 26.9794f, 58.3819f, 22.3255f, 7.3631f, + -17.3453f, 32.8013f, 16.4392f, -4.8961f, 34.6309f, 3.7975f, + 20.9889f, 11.0332f, 21.2790f, 43.6082f, 11.3288f, -4.0437f, + -30.7619f, -28.1362f, -7.6918f, -26.0495f, -20.5254f, 20.4943f, + -5.8695f, -15.0159f, -12.0884f, 4.0124f, -37.3326f, -57.6803f, + 31.1085f, 51.7290f, 46.8635f, -11.1193f, -84.1480f, -75.2940f, + 31.7638f, 33.3860f, -2.0831f, -68.1944f, -69.2055f, 16.6054f, + 26.8476f, 11.7277f, -21.2873f, -16.1653f, 77.7471f, 74.9747f, + -11.9492f, -11.8103f, 39.7377f, 110.8560f, 91.1983f, 51.6182f, + -16.9337f, 34.0576f, 97.5442f, 55.3237f, 6.0911f, -14.5976f, + 63.2733f, 65.6975f, 59.3910f, 57.9345f, 46.9389f, 25.4049f +}; + +const float lsf_cdk_wb_vc_stg3[] = +{ + -32.9020f, -78.5896f, -107.4534f, -95.7731f, -74.7222f, -53.0220f, -21.3706f, -6.3135f, 4.4667f, 8.3786f, + -55.7273f, -51.1982f, -23.4921f, -31.8303f, -40.9730f, -44.0985f, -32.5056f, -19.4304f, -11.2363f, -6.8031f, + -1.3625f, -17.5965f, -40.9966f, -56.5415f, -66.9172f, -82.2625f, -98.8410f, -92.9959f, -64.2789f, -34.2565f, + -0.1831f, 28.9371f, 27.3975f, 6.7646f, -26.2844f, -55.3561f, -55.5887f, -25.6472f, 4.2175f, 6.7426f, + -0.1042f, -22.5234f, -18.6769f, 9.5775f, 20.8908f, 1.7399f, -25.4612f, -48.9497f, -58.9339f, -45.8070f, + -59.3842f, -92.5268f, -67.7156f, -8.1650f, 22.6518f, 30.8838f, 30.1565f, 24.4312f, 17.5083f, 9.4537f, + 61.2263f, 100.3160f, 74.2819f, 32.8490f, -21.2300f, -80.0984f, -138.8597f, -144.8649f, -102.7813f, -51.4501f, + 20.9615f, 14.5464f, 12.7374f, 42.2801f, 62.5685f, 59.3555f, 43.2439f, 37.0487f, 22.3288f, 14.0209f, + 6.4664f, -20.5406f, -67.1147f, -81.1455f, -18.3522f, 38.5675f, 31.4978f, 9.2431f, -5.5141f, -0.9299f, + -14.7299f, -8.8186f, -2.0488f, -3.6924f, -11.6375f, -3.0631f, 38.0648f, 50.4570f, 46.9399f, 28.7229f, + 34.6418f, 11.8422f, -31.9716f, -72.1947f, -102.4017f, -89.6780f, -33.2158f, 7.5030f, 18.7080f, 14.6731f, + -62.1236f, -44.3324f, 53.6090f, 72.1405f, 58.0429f, 57.2172f, 43.2329f, 33.7172f, 19.9635f, 6.9351f, + 73.8739f, 68.1656f, 32.4182f, 5.6585f, -7.7073f, 3.9480f, 12.5407f, 12.3801f, -2.4527f, -5.8024f, + -21.3075f, -24.8496f, -17.5965f, 2.9303f, 59.0699f, 104.4524f, 127.5622f, 113.8932f, 89.2660f, 52.1358f, + 4.2469f, 56.7592f, 88.2184f, 81.0948f, 49.2982f, 15.3523f, -8.4240f, -22.2333f, -30.5271f, -24.1128f, + 46.4076f, 80.4091f, 88.4039f, 96.0474f, 97.7032f, 96.0620f, 87.9680f, 71.7615f, 52.3257f, 28.0991f +}; + +const float *const lsf_codebook[2][2][TCXLPC_NUMSTAGES] = +{ + { + { lsf_cdk_wb_gc_stg1, lsf_cdk_wb_gc_stg2, lsf_cdk_wb_gc_stg3 }, + { lsf_cdk_wb_vc_stg1, lsf_cdk_wb_vc_stg2, lsf_cdk_wb_vc_stg3 } + }, + { + { lsf_cdk_nb_gc_stg1, lsf_cdk_nb_gc_stg2, lsf_cdk_nb_gc_stg3 }, + { lsf_cdk_nb_vc_stg1, lsf_cdk_nb_vc_stg2, lsf_cdk_nb_vc_stg3 } + } +}; + +const int lsf_numbits[TCXLPC_NUMSTAGES] = { 5, 4, 4 }; + +const int lsf_dims[TCXLPC_NUMSTAGES] = { 16, 6, 10 }; +const int lsf_offs[TCXLPC_NUMSTAGES] = { 0, 0, 6 }; + +const float lsf_ind_cdk_nb_gc_stg4[] = +{ + -33.5099f, -17.2439f, + 1.9585f, 6.4210f, + -21.9240f, 24.8014f, + 23.6604f, 49.3421f +}; + +const float lsf_ind_cdk_nb_vc_stg4[] = +{ + -33.5292f, -23.3982f, + 15.6149f, 34.3889f, + -9.2455f, 6.1721f, + 60.7325f, 78.8354f +}; + +const float lsf_ind_cdk_wb_gc_stg4[] = +{ + -31.4516f, -19.9820f, + 9.1071f, 6.9160f, + -17.3554f, 28.1193f, + 31.7476f, 59.9379f +}; + +const float lsf_ind_cdk_wb_vc_stg4[] = +{ + -25.6665f, -20.7100f, + 17.1565f, 9.9963f, + -13.7601f, 37.4813f, + 55.4374f, 66.3001f +}; + +const float *const lsf_ind_codebook[2][2][TCXLPC_IND_NUMSTAGES] = +{ + { { lsf_ind_cdk_wb_gc_stg4 }, { lsf_ind_cdk_wb_vc_stg4 } }, + { { lsf_ind_cdk_nb_gc_stg4 }, { lsf_ind_cdk_nb_vc_stg4 } } +}; + +const int lsf_ind_numbits[TCXLPC_IND_NUMSTAGES] = { 2 }; + +const int lsf_ind_dims[TCXLPC_IND_NUMSTAGES] = { 2 }; +const int lsf_ind_offs[TCXLPC_IND_NUMSTAGES] = { 0 }; + +const Word16 min_distance_thr[2][2] = /* 14Q1*1.28 */ +{ + /* GC, VC */ + /* WB */ { 580, 580 }, + /* NB */ {1000, 580 } +}; + +const float lsf_q_diff_cb_8b_rf[256*16] = +{ + -49.142456f, 13.490689f, -21.704788f, 63.851589f, 17.341200f, 49.889275f, 4.535705f, -49.377617f, 12.881550f, 3.317029f, -45.874687f, -91.048477f, -159.075317f, -244.532806f, -208.950378f, -60.136238f, + -71.911499f, -50.432014f, -131.216339f, -25.763540f, -90.432335f, -140.176178f, -31.643175f, -46.414715f, -23.065298f, -42.936611f, -38.403904f, 15.094532f, -0.061476f, -28.153961f, -21.246065f, 10.218022f, + -134.834076f, -120.343132f, 98.120338f, 51.493057f, -18.822592f, 5.707322f, -93.194328f, 48.820892f, 38.169155f, 22.535019f, 17.952980f, -59.919395f, -154.178802f, -66.216209f, -30.895947f, -30.548832f, + -41.079960f, -11.862259f, -32.120766f, -35.889202f, -28.737438f, 26.212168f, -37.682671f, -117.789268f, -206.368179f, -150.378693f, -26.382723f, -33.924740f, 14.733324f, -7.089695f, 8.373900f, 41.311722f, + -44.370823f, -21.727020f, -164.064880f, 39.315842f, 14.170435f, 2.276680f, -43.158184f, -105.471977f, 46.076225f, -35.652943f, -72.096603f, -88.481071f, -121.452873f, -86.098267f, -92.925804f, -58.238682f, + -62.593822f, -14.669445f, -39.062012f, -12.045748f, -53.345932f, -70.633652f, -100.257874f, -63.507019f, 57.782543f, 62.015087f, 67.188080f, 65.260689f, -49.929119f, -162.794342f, -204.251465f, -104.609535f, + -66.932289f, -18.313484f, -68.981606f, -25.012476f, -94.210236f, 1.026957f, -67.785004f, -35.943043f, -53.149406f, -87.719955f, -112.206566f, -113.875397f, 111.780113f, 102.159576f, 1.001174f, -50.978374f, + -101.098640f, -70.354515f, -151.534393f, -91.954025f, 3.666550f, 78.893501f, 42.150974f, -57.122208f, -56.242603f, -97.829124f, -66.723511f, 11.967057f, 16.204992f, -23.608727f, -19.899971f, 28.121500f, + 10.450438f, 45.892262f, -54.131168f, -16.160269f, -64.032661f, -176.495041f, -5.962820f, -72.027107f, -150.201141f, -32.517159f, 61.674686f, 44.256657f, 46.283817f, -5.180211f, -141.241837f, -167.211639f, + -173.577682f, -92.975533f, -112.498154f, -101.956200f, -66.556870f, -79.061409f, -139.621201f, -1.422741f, -10.495166f, 71.210350f, 49.869511f, -2.298943f, -35.104397f, 24.463161f, -11.476251f, -46.980118f, + -37.676750f, 24.794701f, -40.237633f, 33.943848f, -51.101398f, 166.382629f, 110.829704f, 23.702038f, 23.627102f, -6.121801f, 0.773019f, -142.445435f, -263.982605f, -14.189220f, -131.928268f, -155.050293f, + -30.214348f, -9.421390f, -102.936676f, 83.361900f, -24.453602f, -180.015442f, 92.876984f, -79.562981f, -9.609303f, -34.706200f, -120.354073f, -29.731850f, -81.171555f, 36.295174f, 61.845047f, 47.662693f, + -110.844032f, 83.765533f, -123.206459f, -51.540508f, -51.287010f, -48.821514f, -29.502964f, -6.343169f, 23.775656f, -0.353102f, -23.523582f, -94.919563f, -133.085464f, -118.824188f, -53.901115f, -52.530910f, + -55.833942f, -37.825222f, 21.633268f, -2.833855f, -172.300034f, 74.660912f, -62.712250f, -77.443947f, 114.319824f, 49.023743f, 36.734745f, 53.222221f, -31.211931f, -15.118987f, -37.109795f, -50.964909f, + -2.209181f, 103.944717f, 186.623413f, -64.544991f, -32.391006f, -40.504578f, -24.400692f, 23.758614f, -28.194080f, -40.393677f, -41.950493f, -90.601120f, -169.530365f, -181.697540f, -67.184174f, -66.990860f, + -24.511374f, 34.831326f, 36.412617f, 49.172550f, -16.029377f, -109.529999f, 4.142260f, -20.617449f, -56.997406f, 30.342079f, -83.989975f, 1.144082f, 161.687592f, 61.147705f, -86.482475f, -92.777733f, + -88.158249f, -53.647205f, -131.604202f, 18.409283f, -8.442244f, -74.841873f, -30.877779f, 73.223831f, 26.580759f, -20.676722f, -31.395731f, -93.706764f, -88.946129f, -60.194122f, -118.809082f, -83.768547f, + -27.869957f, -5.078736f, -133.762909f, -274.870483f, 25.990072f, 21.509178f, 36.674843f, -3.828471f, -37.908432f, 2.206993f, -2.133470f, 15.392393f, -76.964806f, -123.400665f, -55.604580f, 13.984759f, + -39.818924f, -24.414286f, -78.231728f, 114.239975f, 68.886200f, 49.643444f, 61.244785f, 24.158489f, -11.322248f, -82.068733f, -152.400940f, -144.792816f, -89.084679f, -107.811325f, -15.021494f, 27.688988f, + -26.188799f, 13.887177f, -74.969177f, 125.939407f, 54.065468f, -29.856068f, 6.488181f, -63.185188f, -96.026291f, -188.663879f, -165.438187f, 203.997070f, 43.201817f, 21.809793f, -74.018494f, -76.644218f, + 14.730933f, 52.225765f, -133.046051f, 73.062096f, -12.101256f, -61.917290f, -85.989738f, -25.391121f, 61.084568f, -56.463966f, 192.920975f, 44.298870f, -151.724915f, 91.825546f, 4.643712f, -14.348310f, + -83.082611f, -43.735950f, -57.932819f, -63.816303f, -127.738678f, -96.165390f, 27.380922f, 106.262009f, 117.074669f, 97.982422f, 63.797035f, 48.936672f, -12.647917f, -65.618805f, -84.200691f, -93.463432f, + -79.058868f, -82.570656f, -23.950100f, -42.977753f, 35.295464f, -60.833336f, -54.265438f, -1.680498f, -73.608223f, -41.047230f, -32.325935f, -36.250416f, -2.680869f, 24.178974f, 12.027203f, 4.833654f, + -70.078651f, -40.907417f, -113.092224f, 27.616556f, -46.329929f, 104.583298f, 82.129387f, 0.280690f, -27.957493f, -79.316704f, 111.977844f, 50.056763f, -19.403173f, 25.433884f, 70.602043f, 28.069981f, + -1.787399f, 19.136635f, -48.166355f, 5.009412f, -62.536564f, 75.527115f, -47.088139f, -11.585875f, -65.448433f, -92.899475f, 107.363365f, -32.311649f, -203.382462f, -152.693619f, -50.552776f, 31.944372f, + 8.727448f, 163.701584f, -151.617279f, -120.834221f, -140.449585f, -168.542450f, -161.597626f, -134.148041f, -44.436928f, 23.024485f, 88.100662f, 153.087036f, 171.657425f, 142.269592f, 72.176025f, 34.152279f, + 24.626226f, 141.228775f, 68.035118f, 32.383106f, 29.076723f, -23.316879f, -11.166278f, 28.757330f, -105.244186f, -168.721451f, 15.529101f, -45.646198f, -99.508888f, 12.179071f, 41.687931f, -6.929618f, + -32.293335f, -15.942890f, 0.017796f, 227.668884f, 35.207336f, -33.792694f, 82.114479f, 15.197913f, -26.902617f, 65.209732f, 1.587932f, -56.761986f, -22.348925f, -26.869337f, 19.428514f, 27.321255f, + -102.949432f, -25.011555f, -147.959137f, -87.200294f, 47.153675f, 18.530943f, -0.166834f, 19.560911f, 89.191528f, 52.157402f, 2.918095f, -61.719532f, -94.293381f, -51.465199f, -1.655222f, -17.656567f, + -38.911335f, 6.948825f, -39.729725f, -51.301937f, -53.620224f, -108.789536f, 155.468872f, 63.620651f, 35.850296f, 70.581047f, 42.754013f, 127.703674f, 66.715858f, -130.426041f, -146.462341f, 74.622078f, + -1.029140f, 54.317455f, 8.387774f, 41.543407f, -10.573199f, 24.244738f, 30.842634f, -26.604139f, -33.421272f, -9.906475f, -31.059523f, 10.844967f, 30.019199f, -202.162201f, -258.204132f, 91.369331f, + -153.889771f, 115.453377f, 72.695793f, -18.096334f, 20.942005f, -35.160381f, -38.443104f, -34.397667f, -48.781742f, -1.410000f, 62.099541f, 79.766754f, 142.615189f, 135.960159f, 96.626495f, 58.906452f, + -79.472115f, -49.353893f, -49.954609f, -155.367615f, -116.776726f, 15.010523f, 18.099497f, -55.247025f, 16.403715f, 87.059982f, -23.132126f, -173.747818f, -144.933502f, -28.767344f, -32.596806f, -0.380802f, + -15.925756f, -5.412324f, -105.707176f, -130.356949f, -98.465538f, -47.166088f, -87.599068f, 42.630928f, -62.413151f, -107.954193f, 158.527435f, 98.763542f, -3.586527f, -6.147307f, -13.222188f, -23.993233f, + -24.975382f, 56.402035f, 52.029133f, -3.636582f, -18.978687f, -30.510057f, -20.777334f, 0.297320f, -75.612679f, -166.890121f, -182.792877f, -17.244802f, 17.907167f, -95.983925f, -107.016418f, 6.600997f, + 13.935800f, 124.014893f, -78.200630f, -86.667000f, 27.445192f, -62.815701f, -53.436100f, -106.422089f, -98.502609f, -122.057808f, -94.039665f, 79.832077f, 85.983383f, 86.996208f, 71.870331f, 101.132660f, + -51.503838f, -34.840988f, -93.907707f, 54.647934f, 85.969376f, -35.794395f, -36.596844f, -102.254219f, -196.495346f, 34.254475f, -15.691520f, -81.330208f, -7.808877f, -105.690956f, -96.873695f, 28.378246f, + 79.900681f, 76.900246f, 101.535088f, 103.327919f, 76.696190f, 36.222244f, -87.911812f, -186.179047f, 47.998817f, 180.776077f, 27.586971f, 68.147926f, 8.632617f, -127.173943f, -218.839523f, -269.181305f, + -51.884178f, -23.658228f, -7.389097f, 51.481766f, -16.066425f, -70.871017f, -193.338547f, 194.566742f, 115.566246f, -35.451885f, -78.933662f, 8.663171f, 16.445974f, -68.275475f, -91.542229f, 1.517690f, + -39.556801f, 39.785755f, -76.877228f, -215.618423f, 126.814384f, 37.883842f, 26.489124f, -32.631229f, -79.764656f, -5.413741f, -44.822353f, -38.384186f, 145.878082f, 205.717392f, 96.100632f, 80.714775f, + -36.383427f, 1.122570f, 179.888214f, -48.044216f, -121.014236f, -85.808846f, -125.241035f, -79.817886f, -0.247583f, 50.953720f, 13.693697f, -5.582759f, -50.636333f, -46.192039f, -66.636848f, -36.257576f, + -122.950089f, -101.489883f, -260.444885f, -20.923767f, -57.475227f, 15.233345f, -42.816353f, -43.372814f, 58.668098f, 2.198759f, -2.974080f, 16.032595f, 93.305153f, 50.504028f, -14.432660f, -50.193291f, + -16.826427f, 8.873464f, -87.595573f, 23.091625f, -3.794562f, 38.739624f, 159.341888f, 57.302864f, 10.663289f, -44.891232f, -143.189377f, -141.278580f, 34.162834f, 67.916397f, -11.724302f, 82.864563f, + 8.689659f, 79.660339f, -106.648331f, -40.056900f, -61.659725f, -89.878143f, 30.882858f, -96.414940f, -87.919632f, 71.567696f, -13.048811f, -99.413971f, 158.306488f, 148.612640f, 101.164139f, 44.707798f, + 51.876743f, 173.028961f, -7.548154f, 42.151535f, -0.306372f, -63.804768f, -65.823441f, -61.424610f, -3.614527f, -0.266337f, -28.529921f, -42.772068f, -92.503525f, -24.051035f, -29.639515f, -52.302032f, + -21.027899f, 32.422092f, -19.221569f, -81.996292f, 170.400146f, 147.834946f, 78.837563f, 54.455120f, -4.170513f, -14.816674f, 66.761642f, 29.512554f, 1.267826f, -7.617690f, -74.421074f, -86.431335f, + -19.333296f, 100.725983f, 62.089886f, 80.720032f, -11.293929f, -156.758041f, 130.283081f, 64.092621f, 10.666490f, 23.035032f, 9.748004f, -82.614822f, -134.818069f, -117.491508f, -98.273796f, 27.608231f, + 3.230417f, 41.808163f, 13.598584f, 214.913864f, 110.737106f, 36.832939f, -14.412317f, -27.091141f, -72.668190f, 5.492285f, 219.188553f, 157.024200f, 139.305466f, 42.584637f, -89.405518f, -147.115540f, + 5.685055f, 57.183292f, -12.697913f, 68.282562f, -33.609550f, -33.049332f, 87.031670f, -39.772167f, -127.605225f, -30.905075f, -129.695374f, -167.423813f, 14.979711f, -80.101776f, -175.781570f, -120.638008f, + -26.057411f, -22.450294f, -86.065346f, -174.294159f, -236.409439f, 106.705414f, 94.844818f, -24.300186f, -47.618366f, -4.900061f, -8.250068f, 26.776390f, 23.026890f, -0.663881f, -8.460385f, 52.523418f, + -239.938965f, -188.228012f, -72.794617f, -24.974373f, 64.134842f, 47.954140f, 37.109238f, 56.990929f, 19.013355f, 2.195176f, -39.343456f, -65.541855f, -48.117985f, 33.679371f, 1.032876f, -8.904166f, + 1.318133f, 23.793682f, -11.594374f, 208.226288f, 86.628777f, -41.451736f, -85.691925f, -59.617199f, -144.367111f, -168.655807f, 108.856461f, 32.739384f, -66.105087f, -32.850475f, 68.247009f, 136.522278f, + 46.231567f, 61.993446f, -37.963066f, 71.883453f, 4.955863f, 90.692329f, -55.423782f, -173.421982f, 91.392097f, 4.265558f, -86.143791f, 11.978693f, -147.210098f, -173.357559f, 47.334595f, 132.379639f, + -8.091352f, 36.792015f, 42.705544f, 0.830618f, -22.491022f, -42.331161f, -6.163970f, 83.671753f, -37.618378f, -48.777485f, 136.386185f, 88.433350f, 121.425102f, 78.104286f, -118.565308f, -236.474899f, + -34.999004f, 35.648041f, 104.321472f, -80.549561f, 88.479385f, 4.159388f, -68.049988f, -110.190895f, -59.762150f, -34.927917f, -42.892593f, -50.185341f, -31.525537f, 28.561077f, 30.799391f, 32.589943f, + -19.395960f, 10.917861f, -33.211983f, 59.916050f, 17.923265f, 69.628220f, -59.527351f, -0.360134f, 20.055620f, -76.225594f, 59.490189f, 219.202728f, 44.065163f, -105.835022f, 149.316025f, 103.121368f, + -26.811831f, 4.917114f, -50.918606f, -51.282066f, -44.665630f, -34.671989f, 54.816383f, -53.930695f, -122.650787f, 9.736618f, -86.848312f, -33.875164f, 28.787636f, -128.559616f, -13.832273f, 240.435959f, + -127.768944f, -120.395676f, -224.640091f, -106.371384f, -110.915848f, -119.944382f, -64.704178f, -86.686111f, 57.449604f, 91.349197f, 96.250694f, 156.740128f, 176.836166f, 127.207031f, 51.964844f, 14.125758f, + -47.998665f, 17.796474f, 29.304367f, 75.164230f, 58.860054f, 113.970734f, 70.417877f, 23.055088f, -25.342611f, -99.771896f, 5.999279f, 51.847668f, -60.419800f, -163.240036f, -99.791527f, -66.431305f, + -0.302659f, 17.211594f, -98.700340f, 53.635334f, -28.992607f, -89.555244f, 112.895592f, -32.920498f, -109.022964f, 150.316772f, 124.435059f, 47.075050f, 111.757408f, 77.910065f, -34.123623f, 33.374477f, + -8.188879f, 23.113052f, -14.419042f, 58.259747f, -4.053533f, 3.542868f, 101.208923f, 41.556973f, 65.754631f, 15.887958f, -6.614230f, -95.157341f, -213.709061f, 82.959053f, 10.967265f, 42.520882f, + -12.848677f, 33.983711f, 26.826427f, 55.942802f, 17.707258f, 59.918518f, 15.309278f, 207.269272f, 99.491982f, 42.829330f, 116.586906f, 97.039436f, -36.674652f, -119.304512f, 74.699173f, 64.565712f, + -127.629143f, 210.633652f, 90.269417f, -15.052937f, 10.047224f, -44.578220f, -32.594685f, -24.894297f, -32.681622f, 36.690662f, 60.424084f, 6.454986f, 7.198017f, 25.681587f, -4.052445f, -25.874166f, + -13.218253f, 25.233515f, -43.822559f, 14.608809f, 50.092663f, 29.797066f, 122.838074f, 60.946331f, -15.227234f, 70.429047f, 49.234367f, 22.393675f, 241.398132f, 68.944763f, -19.084089f, 15.646838f, + -61.749660f, 22.046791f, -33.557991f, -16.016773f, -39.896496f, -65.069405f, -73.831696f, -54.138386f, -41.472534f, -59.811478f, -96.109680f, -119.990692f, -91.886162f, -31.355206f, -9.082160f, -39.052567f, + -27.257662f, 71.028709f, -136.328506f, -98.025055f, -21.314344f, -16.991056f, -34.343781f, -70.373230f, -55.339901f, -30.724577f, -8.068395f, -12.537150f, 6.994465f, -2.531820f, -19.959831f, -32.511631f, + -189.575684f, -170.668686f, 159.468323f, 69.316818f, 9.541554f, -35.932343f, -76.965225f, -73.569916f, -80.277435f, -52.695671f, 36.840542f, 4.612717f, -5.781191f, 68.836777f, 46.053165f, 5.477945f, + 23.076845f, 56.007298f, 58.995125f, 73.648643f, -23.558571f, 31.706146f, 6.650000f, -81.954597f, -43.828186f, -91.444901f, -136.752670f, 3.109934f, -61.638336f, 161.845291f, 158.234512f, 75.812927f, + -29.586615f, 8.254013f, -12.131930f, 42.161793f, -20.277391f, -118.423508f, -194.639008f, -196.011337f, 38.792351f, 37.828663f, -2.185939f, 11.298992f, -6.172924f, -4.559058f, -65.562843f, -27.597832f, + -47.978813f, 22.640007f, -58.066402f, 58.001053f, -47.134541f, 8.486321f, -6.111372f, -31.006121f, 51.575218f, 5.865514f, 17.294910f, -41.168453f, 73.907234f, 13.599236f, -307.273499f, -197.696899f, + -44.109650f, 49.449520f, 84.357780f, -161.258835f, -95.109154f, -44.129417f, -5.148076f, -26.549320f, -4.192320f, -31.172485f, -35.216717f, 42.882584f, 4.978696f, 0.798938f, 44.287029f, 7.057617f, + -44.323925f, -3.754397f, -20.289011f, 35.057964f, 30.896481f, 47.822914f, 57.432564f, -18.862158f, -58.972874f, -40.730820f, -53.210159f, 151.582123f, 189.086823f, -47.681084f, -160.354431f, 18.183973f, + -24.190926f, -8.054521f, -60.337772f, 17.447094f, 52.011765f, 64.135529f, -12.559262f, -64.698524f, -145.641434f, -49.002659f, 27.998568f, 54.442074f, 31.638771f, -105.428864f, -187.366058f, -170.395126f, + -52.519932f, -45.655670f, -54.255409f, 18.195887f, -47.736511f, -25.311331f, -74.233253f, -139.686768f, -7.455135f, 30.180883f, 16.468306f, 73.234703f, 89.610466f, 86.974052f, 38.241241f, -12.159492f, + 27.982965f, 58.867645f, 9.410244f, -37.832794f, -107.431290f, 148.510559f, 114.846024f, 37.929848f, -49.612717f, -97.690834f, -11.054573f, -58.132690f, -120.672997f, -0.656331f, 67.064285f, -17.834682f, + -38.582962f, 4.200229f, -16.068153f, 16.516636f, -13.899181f, 5.986161f, -2.004643f, 12.832077f, -44.597519f, -86.681267f, -38.071716f, -52.322094f, 61.482838f, 23.035675f, 222.921036f, 209.259064f, + -53.377850f, 219.871765f, 18.681116f, -49.476475f, -66.432587f, -11.111042f, 8.136900f, 38.469578f, 83.534767f, 23.165945f, -66.981857f, -119.944641f, -90.701843f, -5.017766f, 13.544878f, 7.416979f, + -26.158424f, 21.733870f, 8.429042f, -7.359868f, -81.261559f, -0.384979f, 107.991409f, -33.468559f, 163.344254f, 171.295059f, 21.148136f, -44.234226f, -50.298836f, -2.045869f, -46.947075f, -69.817322f, + 54.305538f, 77.911476f, 98.722816f, -46.229565f, -143.810577f, -1.355024f, 61.036888f, -13.015687f, -3.865948f, 88.857635f, 7.053370f, 11.180832f, -46.409653f, -90.435066f, -105.360260f, -147.441849f, + 75.489372f, 105.739868f, 60.188259f, 33.809502f, -21.277689f, -21.943260f, -50.937679f, -75.105469f, 43.895504f, -42.176373f, -73.326416f, 343.493774f, 168.802673f, 63.476738f, 36.762135f, 96.509972f, + -43.959518f, -13.900088f, -83.791946f, -2.585726f, -89.923798f, -318.138428f, 56.854568f, 72.487968f, -32.397919f, 28.099873f, -17.146538f, -96.395309f, 0.466646f, -28.547890f, -71.721748f, -40.413429f, + -91.491898f, -100.288185f, -158.042801f, -94.347038f, 41.776943f, 56.555912f, 18.842609f, 21.550163f, -8.122741f, 83.330833f, 83.349388f, 56.535236f, 6.853065f, -16.367655f, 6.860499f, 12.135324f, + -122.978020f, 41.508400f, -57.019398f, 119.866692f, 169.921616f, 82.577713f, 6.609851f, 29.209021f, -35.676617f, -95.016159f, -42.960949f, -61.483852f, -28.365889f, 44.539429f, 11.786313f, -39.760418f, + -35.204288f, -3.827494f, 1.364895f, 53.625450f, 67.540977f, 12.539343f, -62.200562f, -131.499298f, -190.222824f, 97.861145f, 145.009247f, 116.742218f, 39.964626f, 5.113988f, -49.972206f, -22.433067f, + -21.844286f, -3.302132f, -103.041687f, 72.974442f, 0.991044f, 31.884541f, -68.314651f, 15.106439f, 38.181488f, -142.549530f, -177.428543f, 26.987268f, -65.951744f, -49.118980f, 100.179466f, 67.782463f, + -68.886017f, -50.878456f, -101.627640f, 94.751526f, 63.353767f, -35.431698f, 88.086647f, 85.405006f, 1.274280f, -8.066319f, 108.974724f, 81.340332f, 19.295490f, -5.680541f, -76.852966f, -93.998848f, + 0.026969f, 0.110805f, -0.074311f, 0.076925f, 0.017105f, 0.036573f, -0.118072f, 0.068798f, 0.056649f, 0.036456f, 0.063553f, 0.071463f, 0.000525f, -0.019787f, -0.046544f, 0.021337f, + -17.799213f, 17.198961f, -23.454958f, -48.785267f, 32.178555f, 142.656906f, 87.394043f, -46.504601f, -91.326263f, -128.089188f, 168.745255f, 12.046860f, -75.234085f, 321.776276f, 84.140045f, 147.402191f, + -7.771455f, 13.708800f, -83.826019f, -18.597784f, -45.941696f, -97.131195f, 73.443825f, 13.631736f, -35.554703f, 154.701080f, 86.402138f, 6.515917f, -68.449318f, -152.233841f, -30.240294f, -16.017389f, + -55.553074f, -10.045274f, -82.091660f, -104.274841f, -102.906937f, -76.238228f, -59.226723f, -42.700069f, 16.344666f, 35.539070f, 49.328686f, 56.921478f, 131.003021f, 165.738358f, 186.387207f, 144.321213f, + 24.576750f, 51.924622f, 2.034293f, 189.503342f, 148.765106f, 101.905212f, 63.054604f, -22.561197f, -112.342194f, 8.821053f, 33.745621f, -43.875877f, -58.067898f, -146.850281f, -17.419054f, 72.366890f, + -30.276649f, -31.782654f, -80.339973f, 100.106911f, 93.313034f, 4.726528f, -48.094799f, -115.030556f, -191.082672f, 102.985733f, 88.130089f, 19.376783f, 42.609215f, 50.674198f, 152.159012f, 114.587776f, + -137.391373f, 14.609784f, -65.256355f, 1.609928f, 37.473400f, 26.934027f, 24.673132f, 119.508095f, 88.831779f, 43.605965f, 27.401138f, -7.082619f, -78.587341f, -76.090195f, -60.487331f, -49.042698f, + -3.795852f, 48.615219f, -32.316784f, 47.219639f, -71.672012f, -177.180862f, 227.674683f, 121.423073f, 55.595085f, 89.844704f, 18.789379f, 72.883820f, -30.959936f, -1.702511f, 69.411217f, 21.385332f, + -31.896704f, 58.013481f, 15.825336f, 21.007841f, 73.693138f, 2.008733f, 47.849987f, 22.561638f, -56.861252f, -96.624382f, 116.512817f, 122.175636f, 14.970264f, -131.112076f, -137.480362f, 145.503159f, + 3.666602f, 60.865307f, 190.182358f, 42.435371f, -21.053213f, -17.096897f, -76.084404f, -13.743227f, 117.478218f, 140.799774f, 154.908340f, 88.790558f, 92.327370f, 121.949478f, 69.189064f, 33.268280f, + -24.028364f, -0.568868f, -10.598723f, 23.224901f, -10.145369f, 23.696190f, -80.020584f, 133.288193f, 78.874382f, -28.811146f, -74.702332f, -142.888794f, -177.398254f, -126.189499f, -64.583435f, -4.795106f, + -42.301235f, 1.254746f, -92.263153f, -67.414131f, -68.581459f, -105.596657f, -95.386429f, -140.669708f, -167.874496f, -26.571861f, 58.823044f, 95.171120f, 164.426514f, 117.247391f, 67.970955f, 67.381973f, + 12.281957f, 57.241734f, 145.007370f, 102.782562f, 6.108451f, 23.661549f, -109.679001f, 79.513168f, 54.415848f, -107.359993f, -127.692383f, -2.818198f, -116.707993f, 22.176086f, -1.896818f, 13.089568f, + 42.066715f, 109.299110f, 22.366495f, -16.778564f, 21.774530f, -4.182106f, -18.286386f, -52.603218f, -118.524780f, -89.037674f, 118.551682f, 115.277679f, 89.577263f, 130.519241f, 158.623138f, 169.276016f, + -127.461502f, -97.991295f, -154.912262f, 156.017349f, 83.816185f, -40.645927f, -30.617186f, -97.806175f, -64.010101f, 50.553226f, 32.767338f, -3.065530f, 46.381119f, 52.668839f, 32.740833f, -18.864176f, + -35.447090f, 10.117445f, -29.844646f, 121.351227f, 83.683456f, 57.303402f, 15.328587f, 44.133987f, 67.000153f, 104.188065f, 10.872536f, -10.320432f, 63.163109f, -83.689003f, -200.906555f, -56.971607f, + -73.476898f, -50.613533f, 157.811996f, -36.126892f, -3.998129f, -33.125019f, -40.811184f, 75.547150f, -26.170004f, 16.685923f, 89.786247f, -2.189539f, -13.579331f, 56.560184f, 54.771152f, 26.603344f, + -50.784908f, -37.853783f, -22.237158f, -10.529336f, -75.668167f, 170.388672f, 64.201385f, 9.919388f, -25.087654f, -97.517700f, -38.260277f, 51.479713f, 98.044075f, 224.824921f, 125.035980f, 68.006523f, + -13.163634f, 49.532330f, 22.343836f, 23.637941f, -71.608704f, -200.313492f, 22.972029f, -65.936508f, -139.879044f, 109.168282f, 73.714027f, 8.318653f, -33.382645f, -57.808838f, -26.988724f, 70.492950f, + -57.241489f, -35.265514f, -140.595444f, 85.484810f, 13.172671f, -44.652134f, -64.718590f, 80.219849f, 113.279419f, 8.199357f, 46.910881f, 1.842971f, 6.611537f, 108.265114f, 84.200981f, -15.673004f, + -54.020992f, -40.065796f, 68.741219f, 89.963760f, -22.845310f, 156.119400f, 40.349724f, 13.827300f, 99.219742f, -10.468677f, -69.469467f, -91.899101f, -28.343006f, -18.399660f, -48.014648f, 18.084986f, + 39.514809f, 117.259254f, 84.999840f, 3.152317f, -89.788651f, -15.256340f, 128.664642f, 16.396799f, -2.824860f, -2.224188f, -108.113235f, -104.294632f, 285.672485f, 258.659821f, 131.015823f, 46.896381f, + 35.400707f, 199.269470f, -50.829807f, -59.871765f, -112.504417f, -87.914078f, -74.663177f, -14.457950f, 3.730728f, 8.424652f, 34.759491f, 5.061568f, 49.715153f, 29.911200f, -4.833649f, -7.921039f, + 79.273865f, 68.455246f, 143.235184f, 29.923138f, -61.068966f, 27.401043f, -93.697815f, 39.637844f, 278.054901f, 207.706467f, 114.287697f, 191.970261f, 28.365456f, -67.643982f, -126.002037f, -324.593506f, + -38.810867f, 77.219002f, 226.800339f, 84.473801f, -40.547543f, -21.564167f, 131.517456f, 93.058868f, 25.796638f, 24.364828f, -21.709984f, 0.377355f, -100.328873f, -63.233959f, 39.949356f, -20.796144f, + -49.434875f, 13.246425f, 235.871155f, 150.979660f, 94.417747f, 49.695023f, 9.298592f, 42.695667f, 12.962906f, 29.078457f, 141.417770f, 131.790558f, 139.121719f, 102.666374f, 34.500813f, -11.908920f, + -2.108662f, 13.590509f, -38.806015f, -50.421722f, -148.383850f, -9.163120f, 221.518173f, 91.873947f, -57.944500f, 7.884820f, -23.169016f, -6.481791f, 39.176830f, -30.829500f, -216.452530f, -132.310471f, + -60.222321f, -37.813641f, -144.648758f, -74.471680f, -53.668755f, -36.867607f, 163.549622f, 118.314560f, 9.347286f, -64.045303f, 54.008766f, 6.278257f, -3.053545f, 65.511765f, 31.613440f, 28.923603f, + -68.111702f, -58.754192f, -20.550688f, -9.141284f, 178.296661f, 46.222195f, 85.088615f, 25.129522f, 3.565898f, 73.297729f, 22.594685f, -30.790440f, -60.898556f, -59.714981f, -25.799683f, -26.515989f, + 79.872566f, 27.157415f, -193.357193f, 172.950409f, 131.502487f, -2.173946f, -11.273206f, 11.559188f, -135.590240f, -117.606354f, 162.157654f, 74.852615f, 84.181198f, 42.567123f, 72.688606f, 30.169746f, + -22.176310f, 8.126409f, -98.820702f, 162.383163f, 130.916565f, 39.752148f, -32.870506f, -173.600403f, 116.578125f, 45.067692f, -27.598148f, 8.555970f, -3.395607f, -42.335846f, -20.110458f, -40.589352f, + 31.181765f, 77.636864f, 60.341606f, 90.832474f, -9.832494f, -111.538925f, 111.043030f, 140.765152f, 80.575752f, 24.432682f, 81.943199f, 20.720406f, 1.215079f, 4.115319f, -68.575241f, -91.525787f, + -84.731537f, -0.527349f, 25.745188f, 36.190254f, -62.206528f, -86.327141f, -27.536991f, -15.557912f, 32.424694f, 13.717608f, 11.215924f, 22.781013f, 9.574938f, 61.158257f, 61.121010f, 32.403088f, + -18.375742f, 10.047339f, -50.339001f, -6.936292f, 12.167328f, 150.529266f, 222.465683f, 183.672455f, 58.230515f, 30.788654f, -22.198248f, 57.085861f, 28.043667f, -36.177765f, 171.042053f, 134.737167f, + 0.297151f, 95.241844f, 51.197784f, 41.369175f, 33.568478f, 7.960698f, 55.897408f, 15.283177f, 29.098846f, 91.276161f, 20.340677f, -60.202499f, -171.769867f, -193.836426f, 13.407167f, 121.289520f, + -77.249527f, -31.146763f, -86.916313f, 13.008453f, -21.325594f, -35.007175f, -0.394985f, 39.783211f, 158.601135f, 162.017731f, 166.716888f, 164.855255f, 145.650070f, 87.215416f, 13.765621f, -16.071383f, + -11.922022f, 69.904465f, 145.530533f, 137.786896f, 42.237782f, 75.689651f, 121.502434f, 26.309196f, 0.019661f, -62.185799f, -152.175339f, 86.949432f, 41.679405f, 18.519968f, 34.415928f, 25.165304f, + -9.927750f, 11.307752f, -64.252609f, 131.465469f, 47.641304f, 22.456234f, 36.158360f, -40.804043f, -91.170403f, 86.573074f, -47.294422f, 15.884171f, 222.589951f, 158.826157f, 154.847031f, 224.892197f, + 34.394650f, 50.068573f, -4.612890f, 39.353638f, -13.351929f, 82.855324f, -34.119553f, -198.830780f, 169.354126f, 20.893297f, 2.412445f, -82.652008f, -123.564072f, 148.278564f, 67.057632f, 86.445847f, + 8.496761f, 55.847862f, 9.401371f, -12.230957f, -48.765945f, 339.392365f, 127.588539f, -17.772644f, 73.892937f, -37.477283f, 39.123516f, 58.133339f, -42.253559f, -161.082916f, 77.454605f, 125.429886f, + 43.473793f, 173.585449f, 85.007156f, 42.041813f, -61.597820f, 51.345463f, 44.502201f, -8.306359f, -2.903240f, -41.573891f, 114.340172f, 93.989349f, -18.752844f, 33.966118f, 85.911499f, -5.925835f, + 69.373337f, 94.525620f, 55.872551f, -12.796402f, -57.766541f, 205.378647f, 150.999893f, -34.033718f, 46.349552f, 51.589359f, -9.740956f, 165.190857f, 245.511856f, 140.620789f, 33.383125f, -80.622025f, + -24.897663f, 9.583753f, 62.261280f, -111.380074f, -93.574211f, 37.958935f, 11.259578f, -85.749733f, -185.118637f, 15.325944f, -47.716419f, -70.300369f, -64.094902f, -120.984238f, -115.879242f, -5.316128f, + -43.105038f, -38.260498f, -69.155273f, -106.188942f, -215.693817f, -116.750755f, -22.012207f, -17.229620f, 2.833113f, 47.987717f, 6.774336f, -11.583231f, 16.325312f, 30.872992f, 21.988634f, 21.333845f, + -40.281574f, -19.919075f, 83.175934f, 145.520676f, 74.963409f, -17.649036f, -97.185730f, -32.826363f, -53.159214f, -13.556940f, -30.614326f, -68.210266f, -70.881149f, -25.398729f, -57.834473f, -78.295006f, + -54.354683f, -53.242130f, -151.652374f, 75.184731f, -12.681744f, -62.721302f, 39.976120f, -84.622726f, -164.732422f, -81.025864f, -59.992664f, 18.575914f, 59.433632f, 91.230606f, 74.121452f, 15.667545f, + -56.008598f, -36.547680f, -74.135963f, 60.449661f, -43.171642f, 20.404333f, -94.677895f, -134.441208f, -21.513660f, -79.943031f, -11.399878f, -26.450451f, -51.884460f, 13.872990f, -10.700389f, 13.693831f, + -54.557514f, 14.214915f, -109.558357f, -39.927799f, -80.414780f, -21.436823f, -29.838932f, -133.094101f, 41.575626f, 119.561104f, 108.865402f, 113.994164f, 70.534935f, -74.075966f, -153.541779f, 13.645255f, + -19.660948f, 72.645828f, 57.090542f, 10.197439f, -82.249893f, -86.073334f, -65.963997f, 26.606983f, 62.380840f, -79.725609f, -67.844391f, -100.735214f, 103.173157f, 41.282562f, -14.417590f, 97.527374f, + -15.501063f, 10.106770f, 19.181379f, -48.813862f, -54.115250f, 235.424240f, 13.094974f, -96.655479f, -53.639637f, 13.621657f, 1.518511f, 44.934509f, 57.590019f, -41.299301f, -105.937149f, 5.567881f, + -26.978188f, 39.920815f, 39.867668f, -30.284748f, -137.471680f, -12.073587f, -11.821868f, -56.056862f, -109.460243f, -95.643143f, 71.884705f, 3.678432f, -69.469994f, 46.625034f, 21.143269f, -12.124670f, + -235.238770f, -189.902191f, -98.019753f, 1.308181f, 6.093620f, -51.336655f, -74.336411f, -58.007866f, -34.142288f, -23.622774f, 21.920612f, 54.356789f, 118.404907f, 98.866112f, 78.824142f, 48.048695f, + 38.583252f, 140.003342f, 104.366905f, 59.575905f, 16.539742f, 143.487717f, 46.418877f, 67.189468f, -16.257248f, -14.486803f, -37.126595f, -97.505363f, -80.173981f, -94.221985f, -115.390350f, -118.126472f, + 14.582953f, 70.503632f, -14.045506f, -19.149410f, -112.971611f, -166.393768f, 175.770172f, 72.728432f, -123.819260f, -84.734123f, -79.798332f, 15.522896f, 9.189954f, 45.245491f, 67.264786f, 21.392374f, + -30.288527f, 176.278839f, -42.118710f, -113.833649f, 18.178839f, -98.263985f, -5.378097f, -36.394852f, 56.751965f, 34.232403f, -15.896103f, -21.939495f, -36.014275f, -97.239891f, -44.097141f, -21.397247f, + -57.630421f, -14.344311f, -48.722851f, 4.000876f, -85.091949f, 134.974442f, 96.790924f, 44.602585f, 116.120537f, 108.384445f, 134.965012f, 62.810093f, -51.505104f, -66.570000f, 0.324640f, -61.159451f, + 46.961773f, 91.328773f, 255.896439f, 266.543579f, 55.914829f, 1.617108f, 3.187201f, -8.799063f, 27.105843f, 96.940453f, -6.333913f, -40.912540f, -123.896332f, -219.183456f, -147.103104f, -82.445755f, + 4.730723f, 14.597744f, -4.770158f, 50.178673f, -46.408352f, 46.296600f, 159.859604f, 44.269157f, 25.871405f, 18.163599f, -69.356171f, 99.161255f, 145.530502f, 110.339287f, -78.356651f, -249.688126f, + -4.995772f, 7.796484f, -231.294037f, 72.029633f, 33.000286f, -63.268135f, 113.155357f, -3.829946f, -48.667412f, 20.674379f, -19.940260f, -66.963058f, -30.490475f, 1.557967f, -21.697649f, -25.190910f, + -68.609848f, -42.050915f, -81.286026f, -171.873383f, 5.826807f, -37.863060f, 65.958603f, 64.783348f, 16.320978f, 7.862601f, -63.484844f, -35.056782f, 36.112469f, 25.719179f, -27.790937f, -49.815948f, + -52.712395f, 5.407033f, -50.664661f, -57.217823f, 93.290443f, 86.227432f, 47.213612f, 8.067347f, -70.909805f, -102.342758f, -81.671745f, -96.333832f, -76.863091f, -17.267122f, 0.470240f, 11.259017f, + 45.857506f, 61.279209f, -16.262930f, 65.889984f, 39.496490f, 31.019928f, 10.330289f, -12.880993f, -158.328720f, -214.299026f, 136.159515f, 34.651714f, 58.886429f, 52.877373f, 18.637857f, -97.587326f, + -83.695442f, -46.231495f, -126.655914f, 84.273537f, 24.091738f, -77.565994f, -121.072006f, -65.358688f, 13.704159f, 17.912792f, 129.792953f, 45.167286f, -76.637970f, -90.235817f, 29.498278f, 22.527498f, + -38.629421f, -13.281903f, 19.966961f, 21.830301f, -71.014816f, -56.646057f, -183.160706f, 153.295105f, 121.722061f, 122.379555f, 191.160324f, 94.983765f, -38.069660f, -13.902174f, -28.430313f, -3.660168f, + -61.012142f, -16.898062f, -122.156700f, 40.265934f, -4.676280f, 89.712509f, 77.850525f, -22.210423f, 54.780842f, -9.432448f, -77.245964f, 33.276836f, 8.500788f, 24.147732f, -37.488598f, -50.028263f, + -13.981007f, -3.172497f, 12.233177f, -3.165506f, -42.713432f, 159.373047f, 120.601517f, 61.609337f, -95.282997f, 154.044556f, 146.461670f, 105.883102f, 35.354893f, -32.637356f, 13.527010f, 52.834805f, + -59.811607f, 31.116199f, -44.788532f, -25.192825f, 11.671334f, -60.872108f, 94.383209f, 44.916836f, -91.212807f, -106.707802f, -36.229931f, -17.900185f, -138.207123f, -165.818100f, 56.715836f, 45.974777f, + -7.959111f, 85.271294f, 17.490253f, -50.336193f, -56.605679f, -100.320343f, -152.276581f, -135.327911f, 88.408737f, 129.427505f, 125.965462f, 98.592941f, 27.923223f, 7.087426f, 27.595392f, 42.971786f, + -25.500626f, 121.667168f, 83.573936f, 3.791471f, -23.845556f, 49.105648f, 81.526443f, 160.776093f, 22.598379f, -98.819115f, -47.420437f, -16.478176f, 46.472534f, -122.984657f, 0.608375f, 57.243511f, + -12.015658f, -0.135543f, -139.000534f, 151.549393f, 71.025963f, -20.232512f, 95.418777f, -70.840523f, 52.608326f, 22.649012f, -56.357464f, 137.754135f, 50.294880f, -87.514961f, 20.277452f, 193.218811f, + -111.404922f, -69.059303f, -107.005531f, 53.955250f, 56.233429f, 68.297432f, 9.512801f, -94.675659f, 125.887329f, 141.677551f, 37.625774f, -55.039444f, -107.942078f, -106.586906f, -103.690109f, -31.521854f, + -7.459867f, 80.387726f, -22.849117f, -7.418187f, -31.289583f, -58.895996f, 121.585495f, 71.303520f, 69.327995f, 33.343830f, -42.588058f, 246.521713f, 44.359360f, -30.136723f, 45.514824f, 33.970772f, + 13.146280f, 37.437431f, 11.781944f, 221.298462f, 64.525116f, -28.227280f, -2.765812f, -60.692303f, -105.971016f, 145.109314f, 29.132435f, -9.364019f, 92.389153f, -40.417786f, -167.946228f, 91.506371f, + 20.380590f, 124.691406f, -34.959442f, -32.687466f, -68.501457f, -12.932295f, 8.627584f, -95.438469f, 34.264408f, 157.920456f, 94.634033f, 154.451233f, 203.167297f, 140.269073f, 62.590698f, -14.471005f, + -23.798073f, 20.029366f, -28.207727f, -42.335686f, -94.120468f, -119.036964f, -160.177826f, 13.003415f, -10.760310f, -23.243717f, 23.871334f, -25.554195f, -70.506531f, -62.087463f, 52.588543f, 91.934219f, + -45.170189f, -10.087015f, -66.042885f, -262.296326f, 71.659988f, 42.020767f, -0.749665f, 30.568419f, -84.345169f, -88.957222f, 62.976131f, 17.781088f, 35.814819f, 41.151264f, 100.832329f, 51.108604f, + -55.090458f, 141.549744f, 45.250282f, 126.572884f, 51.766277f, -4.223619f, -20.867323f, -46.912258f, 12.903956f, -24.562819f, -59.262470f, -34.927166f, -24.950871f, 4.246840f, 14.226479f, -12.156185f, + -18.676003f, 56.782200f, 24.631006f, 31.817165f, -57.425724f, -164.249939f, -100.221893f, -51.068310f, -151.775375f, -103.694389f, 51.353741f, -14.789831f, 103.796227f, 121.169785f, 67.449203f, 45.746460f, + -9.249492f, -0.717516f, -95.589256f, -58.979927f, 183.596542f, 82.821739f, -44.961880f, -113.124100f, -73.027855f, 24.111319f, -9.787043f, -20.309830f, -9.503817f, -25.950542f, -63.329922f, -49.288395f, + -39.281731f, -8.520073f, 12.045630f, 113.941223f, 56.889790f, 11.705962f, -25.992363f, -25.818201f, 41.962906f, 136.173462f, 158.992706f, 71.041000f, -94.766388f, -115.894958f, -100.844521f, -76.998589f, + -8.995197f, 14.692396f, 10.648182f, 46.508247f, -46.040749f, -30.752420f, -101.055634f, 157.707993f, 120.625099f, -34.914780f, -60.452560f, -125.891411f, -64.873436f, 115.602501f, 134.647278f, 88.401085f, + -16.291512f, 25.577784f, -57.797333f, -93.257050f, 204.563004f, 23.844887f, 18.521849f, -48.872440f, -34.910671f, 52.242157f, 90.209885f, 155.241089f, 122.966759f, 97.500565f, 51.306534f, 61.434639f, + 5.888782f, 91.756126f, 55.121063f, 59.742477f, -13.308426f, -24.613007f, -59.364792f, -131.265594f, -87.939194f, -56.433189f, -38.294590f, 21.820187f, 22.980511f, -26.082766f, -9.050174f, -5.993128f, + -109.033333f, -70.663361f, -105.171837f, -29.390360f, 23.201317f, -1.143196f, -0.591588f, -62.349960f, 177.791931f, 64.124794f, 18.023848f, 85.805557f, 57.960117f, -10.079674f, -10.009348f, -11.720422f, + -1.513953f, 39.937832f, 25.296638f, 52.355652f, 31.179762f, 169.450806f, 131.414230f, 42.987076f, 48.422070f, -2.570796f, -102.850693f, -184.716797f, 126.997742f, 120.658882f, 70.227798f, 51.911579f, + 14.841161f, 42.875328f, -31.856815f, -61.852024f, -95.273911f, -33.013256f, 70.492905f, -26.551783f, -11.850163f, 50.677963f, -74.369408f, 121.694061f, 184.952850f, 83.381836f, 119.151489f, 86.071533f, + -76.190552f, 217.282104f, -47.804283f, 21.103445f, 63.081154f, 35.664818f, 9.597631f, -78.337799f, 33.574825f, 9.579362f, 11.619099f, -66.239075f, -93.457573f, -67.129135f, -28.104412f, -48.758240f, + -32.987583f, 55.155075f, -19.071968f, 25.848909f, 147.531418f, 161.891159f, 100.338860f, 122.278191f, 117.346077f, 121.715561f, 59.932480f, -5.041065f, -11.882968f, 25.816359f, 5.152595f, -6.028398f, + -50.602802f, 47.969971f, 109.523300f, -18.894117f, 104.845932f, 3.333271f, 81.642517f, 48.507870f, 18.322062f, 13.163134f, -27.716911f, -78.545464f, -60.946442f, -21.241007f, -43.533047f, -54.892029f, + 23.136389f, 29.755871f, 115.663109f, 366.295105f, 92.912613f, -56.490879f, -23.877293f, -67.456276f, -41.077976f, 176.197632f, 112.048927f, 87.809334f, 124.036644f, 73.674416f, 55.857883f, -59.281975f, + 36.171646f, 81.249886f, 0.990727f, 62.659752f, -6.243932f, -32.411499f, 103.505295f, -8.062663f, -11.415750f, -33.329777f, -157.624710f, 108.892738f, -52.815735f, -116.408310f, -114.794746f, -108.042885f, + -53.235435f, -53.853008f, -22.214457f, -62.809551f, -184.508316f, 55.657627f, 60.393047f, 8.903349f, 119.629532f, 99.485672f, 93.179787f, 12.529486f, -36.033150f, 91.600227f, 120.306450f, 101.186569f, + -266.389862f, -40.268497f, 58.560471f, -15.688929f, 15.476221f, 40.140427f, 70.106178f, 33.398193f, -55.307781f, -54.812614f, 9.501314f, -32.842312f, 1.404359f, 72.411819f, 48.677658f, 19.896832f, + -30.625458f, -22.088581f, 23.690083f, 147.814285f, 106.761505f, 32.618851f, -56.217175f, -56.086750f, -39.910542f, -27.860449f, 41.870930f, 33.237003f, 14.673645f, 133.780670f, 65.161377f, 29.900471f, + 52.106541f, 97.515167f, -46.684582f, 28.368923f, 50.509525f, -14.864295f, 9.164424f, -87.343681f, -53.357895f, -14.466661f, -124.789276f, 139.007889f, 57.820137f, -198.630005f, 89.412651f, 73.174347f, + -11.813260f, 28.477610f, 43.814209f, 53.005009f, -31.552076f, 12.509279f, -45.665352f, 0.665018f, 89.380127f, 35.962025f, 56.310169f, 231.104538f, 77.507759f, -6.636252f, -114.024948f, -103.220619f, + 3.209964f, 92.323235f, 134.360977f, 72.508331f, -71.873093f, -24.684990f, -70.873833f, -80.898567f, 36.660206f, 107.964767f, 56.888454f, -41.093380f, -94.986824f, 5.479705f, 85.588272f, 86.314072f, + 2.358892f, 19.563696f, -40.146599f, 106.779350f, 84.014519f, 66.932846f, 7.030437f, -25.116844f, 113.391785f, 69.206184f, -40.131550f, 153.922714f, 143.482407f, 34.324108f, 313.322266f, 143.053925f, + -22.836403f, 14.444014f, -49.938580f, -50.887901f, -139.897385f, 96.043907f, 97.666435f, -49.784187f, 51.330086f, 49.973110f, 36.349068f, 19.132963f, -131.961868f, -176.490204f, 84.266121f, 168.514481f, + -37.196350f, -31.474470f, -145.770355f, 73.739777f, -13.749185f, -36.067165f, -73.649986f, 69.205238f, 57.424969f, -29.286839f, 50.821659f, 151.341400f, 196.208405f, 145.900299f, 73.740807f, 59.942463f, + -48.483910f, 109.854485f, 175.905731f, 107.550728f, 182.661041f, 127.042297f, 56.932144f, -4.789718f, -40.474155f, -4.276073f, 15.682971f, -20.523733f, -2.600147f, 47.862274f, 10.863128f, -28.360899f, + -38.357815f, 12.670331f, -18.138870f, 42.676201f, 92.674187f, 36.742359f, 52.514660f, -5.668614f, -115.172440f, 43.835323f, 63.331287f, 56.027485f, 115.062248f, 3.782463f, -26.444477f, 273.927704f, + -70.262749f, -8.360212f, 4.471777f, 3.338549f, 59.435081f, 178.305817f, 71.276756f, -18.074911f, 8.591813f, 75.633720f, 25.886395f, -77.867401f, -98.552505f, 23.158539f, 89.771393f, 55.317135f, + -43.166435f, -20.516071f, -21.639067f, 58.366417f, -37.861000f, 87.507889f, 228.670868f, 168.987442f, 151.971222f, 95.947609f, 62.651642f, 55.564648f, -1.630664f, -52.394417f, -111.610962f, 110.578148f, + -3.820340f, 128.265320f, 241.518845f, 81.778282f, 29.058863f, -34.290600f, -72.192398f, -76.477760f, -66.605965f, -11.854634f, 31.504972f, 41.623680f, 49.260410f, 46.350578f, 25.015730f, 0.466101f, + -74.436829f, -21.117008f, 50.415005f, 41.561440f, 24.320005f, 3.089626f, 84.041313f, 176.202164f, 134.057922f, 109.030365f, 39.151558f, 51.717243f, 205.704620f, 150.353210f, 111.243019f, 26.017376f, + -0.922336f, 8.721625f, 49.901936f, 20.303036f, -45.592381f, -38.354324f, 58.650257f, -53.023918f, -56.784760f, -43.466248f, -124.796875f, -123.479370f, -110.273987f, -34.595661f, -16.564945f, 34.111702f, + -30.525043f, -2.907169f, -178.401764f, -44.677608f, -17.348223f, -31.677353f, -14.556618f, -31.867868f, 20.035357f, 2.716418f, -2.513957f, -41.058819f, -52.201744f, 41.795589f, 65.134628f, 38.667267f, + -92.711220f, -81.188332f, 165.320053f, 146.599762f, 22.146481f, -21.278519f, -40.179806f, -68.613281f, 115.899551f, 67.407913f, 2.306747f, 0.489086f, -1.279717f, 7.199631f, -40.551086f, -8.905237f, + -56.852066f, -32.516693f, -15.849322f, 68.052765f, 92.856277f, 97.140533f, 38.923428f, -64.162766f, -101.875473f, -63.277794f, -78.587120f, -32.074039f, 106.572845f, 95.851845f, 38.376095f, 15.852232f, + -53.858379f, -20.356443f, -84.059586f, -105.614822f, -51.119640f, -2.018013f, -77.954140f, -175.482086f, 79.777809f, 19.744781f, -53.635326f, -51.991280f, -49.052460f, -20.029406f, 16.108711f, 24.346910f, + 65.308319f, 24.882250f, -53.676472f, 35.191555f, -75.052139f, -100.669830f, 139.646332f, 26.502867f, -87.489288f, 144.371918f, 85.639999f, -5.127411f, 49.956379f, -68.622177f, -194.561584f, -257.525238f, + -72.071564f, 88.947922f, 181.188904f, -141.172180f, 21.858112f, 21.690336f, 80.976372f, 74.222694f, 14.965449f, 4.836141f, -13.533607f, 12.946756f, 80.034424f, 18.799646f, -1.797944f, -11.852658f, + -55.483604f, -28.792759f, -51.127789f, -27.386141f, -3.054134f, 270.684784f, 127.849197f, -7.843138f, -46.675968f, -2.273780f, -41.244320f, 107.264915f, 109.052605f, -57.428146f, -94.478180f, 201.012741f, + 58.417904f, 129.794479f, 88.032875f, -43.482414f, 1.503281f, 18.233082f, -4.274224f, -9.935395f, -90.743645f, -138.744934f, 13.047572f, 99.424622f, 79.562485f, -10.939718f, -128.585876f, -119.279457f, + -106.237129f, -91.740143f, 68.612770f, 19.771488f, -23.333853f, 6.881060f, -114.409279f, 37.293667f, 27.547070f, -21.962831f, 62.975277f, 126.174873f, 137.661591f, 88.351982f, 21.489727f, 36.082073f, + 49.864040f, 101.988388f, 41.740952f, -2.001927f, -83.519859f, 222.208069f, 203.213120f, 27.999317f, -8.565958f, -46.465588f, -117.948517f, -54.232327f, 28.665607f, -23.274929f, -55.554726f, -66.254654f, + -52.622940f, -27.317537f, -61.638550f, 130.447021f, 38.187801f, -83.578110f, 91.015823f, 65.975807f, -29.551769f, -55.780457f, -169.249374f, 136.943573f, 43.613983f, 85.860855f, 145.805145f, 83.847832f, + 15.936594f, 90.094734f, -129.895950f, 8.163410f, -8.877759f, -0.308240f, -33.896103f, 62.208805f, 103.766220f, 66.179008f, 27.826544f, -68.158470f, -111.605835f, -60.367783f, -34.454868f, -50.271614f, + -51.554886f, -21.024059f, -18.746723f, 92.973503f, -20.544609f, -4.456210f, 41.285404f, -2.806954f, 202.912384f, 180.625198f, 93.686058f, 105.542542f, -40.283619f, -22.137281f, 28.882605f, 86.878098f, + 166.593475f, 204.373047f, 175.392639f, 6.547530f, -67.728508f, -1.995924f, 104.944130f, 25.587944f, -76.602921f, 2.406351f, -37.560753f, -66.060905f, 82.223129f, -5.690928f, -80.786980f, -192.349823f, + 5.629341f, 24.807444f, 33.959263f, 139.666183f, 67.254204f, 113.142754f, 5.735409f, -36.896606f, 102.640205f, 13.071086f, -75.008644f, 135.153275f, 112.622955f, 93.684708f, 55.722095f, 17.380138f, + -78.392647f, 67.183548f, 41.397549f, 47.879723f, -95.470726f, -223.305008f, 34.429707f, 203.257339f, 81.951591f, 24.905951f, -102.131676f, -172.571976f, 80.404175f, -3.289175f, -63.539902f, -178.667999f, + -8.287517f, 28.750130f, 2.918398f, -190.230972f, 30.998074f, -24.621058f, 57.173183f, 67.070824f, -30.796249f, 125.394531f, 129.483154f, 69.056030f, 61.479782f, 5.587425f, -26.427807f, -42.299709f, + -53.579803f, 3.932101f, 19.298172f, 60.866375f, 203.507217f, 92.185112f, 4.952492f, 26.875463f, 58.186695f, 23.599648f, -55.879227f, -95.170883f, -128.408905f, -56.559254f, -13.179881f, -6.339478f, + 32.887764f, 110.878929f, 47.881824f, 61.743668f, 32.366764f, -43.335995f, 132.176224f, 23.456560f, -170.514435f, 21.666937f, -6.332648f, 200.979141f, 36.371750f, 69.918137f, 54.659019f, -24.744967f, + -48.200562f, -14.369913f, -109.873573f, 132.716415f, 33.534492f, 21.027716f, 29.168337f, -6.307217f, 29.464451f, -16.280748f, -5.903169f, -33.134434f, -163.021179f, -114.629570f, 242.579056f, 153.244400f, + -245.076645f, -119.108864f, 30.076363f, 46.303539f, 62.514118f, -1.635351f, 60.051456f, 85.906593f, 63.114086f, 96.103294f, 94.438263f, 60.414326f, 27.037113f, 46.420849f, 23.188837f, -4.991467f, + 48.128830f, 147.061111f, -19.109028f, -62.073257f, 73.974655f, 35.121407f, 48.858604f, 17.476908f, -27.161577f, -26.075205f, -23.080959f, -22.997204f, 22.060139f, 18.945644f, 12.078902f, 26.152502f, + -11.399143f, 35.660534f, 7.735845f, 28.895029f, 11.763469f, 67.383682f, 32.067547f, 172.807663f, 41.212330f, -64.892891f, 202.612274f, 66.128975f, 24.998840f, 129.758621f, 97.607491f, 64.079475f, + 16.849846f, -8.063315f, -96.246849f, -42.776253f, -61.709106f, 8.576951f, 41.636856f, 4.893633f, -184.455124f, 90.305283f, 214.893326f, 77.557159f, -52.231232f, -59.771557f, 115.499374f, 10.271899f, + -52.432972f, -10.506747f, 32.671928f, 30.160530f, -30.343365f, -108.296562f, -124.741348f, -114.153496f, 22.689064f, 53.387943f, 152.464798f, 195.884613f, 223.508789f, 180.783310f, 88.327431f, 24.891722f, + 44.069721f, 128.580154f, 87.081917f, 97.057877f, 80.764305f, 71.377975f, 76.201828f, 19.052254f, -86.244247f, -55.772846f, -78.071259f, 59.358582f, -18.004076f, -97.394165f, 203.970825f, 128.282730f, + -29.760933f, -17.373451f, -26.997627f, 298.461884f, 135.359589f, -5.173777f, 50.398880f, 16.654043f, -28.228046f, 127.954193f, 88.721756f, 31.046473f, 72.834770f, 51.219566f, 124.174194f, 179.024460f, + -71.473610f, -8.079115f, -80.057495f, 73.607849f, -11.565989f, 6.495467f, 75.740349f, 69.178413f, 172.751343f, 50.800892f, -29.929661f, -55.132294f, -39.521492f, -34.578106f, 29.018955f, 18.790855f, + 4.944071f, 58.298073f, 72.167747f, -20.213915f, -49.029274f, -5.245622f, 135.798645f, 114.233170f, 48.812248f, 154.565750f, 91.869995f, 9.594048f, 29.263868f, 29.942837f, 60.248390f, 56.068134f, + 20.676535f, 129.442535f, 114.557922f, 65.585472f, 9.776167f, 76.209824f, 142.460770f, 65.045479f, 31.220121f, 68.550804f, 85.770195f, 65.380852f, 33.190002f, -80.774033f, -170.538605f, 61.262844f, + -23.503824f, 198.854172f, 14.658221f, 54.346264f, 29.317448f, -15.893962f, 6.081978f, 50.519886f, 129.337723f, 125.421761f, 131.127838f, 197.853912f, 207.257065f, 154.032959f, 90.113098f, 66.989784f, + -62.626553f, 0.772200f, -28.967108f, -85.223953f, -146.385803f, 82.958099f, -24.949381f, 93.786552f, 94.234512f, -39.738564f, -74.894165f, -36.566628f, -39.978264f, 3.580493f, -15.366054f, -32.318130f, + -54.913471f, 12.737958f, -117.342049f, -59.757664f, -14.541400f, -24.570677f, -20.895752f, -18.573147f, -31.541250f, 3.822062f, 63.816460f, 68.993881f, 96.323494f, 113.108215f, 60.914867f, 38.452541f, + -74.699921f, -33.957706f, 274.636505f, 42.985191f, -13.963601f, 35.379383f, 27.960144f, -9.738332f, 15.494253f, -5.034236f, -48.640007f, -28.968740f, -24.268768f, 34.582504f, 11.429268f, 13.275120f, + 32.094368f, 53.997974f, 58.552933f, 60.038021f, 15.307313f, -14.686091f, -79.145950f, -92.266304f, 6.606106f, -31.398434f, 1.153621f, 61.459366f, 211.102783f, 199.088348f, 139.181458f, 90.360237f, + 13.961225f, 107.374969f, -42.851105f, 111.353691f, 85.895554f, -10.314037f, -36.885490f, -48.654755f, -86.748146f, -13.811635f, -28.521486f, -133.376526f, 66.836365f, 63.232780f, 50.980137f, 33.082199f, + 0.719331f, 59.833492f, 52.997120f, 109.368217f, 78.191238f, 181.871460f, 110.776367f, 41.572018f, 32.371555f, 59.911247f, 100.121117f, 147.708542f, 67.625221f, -90.737854f, -184.544220f, -95.008667f, + 17.476965f, 51.444233f, 130.136398f, 86.703789f, -21.260557f, -68.970932f, -246.970169f, 111.624298f, 106.618408f, -70.539291f, -17.852840f, 74.588875f, 22.676432f, 82.200706f, 75.469940f, 86.911079f, + -21.763515f, 88.468819f, 69.462051f, 28.234957f, 137.905060f, 97.628418f, 100.231453f, 71.048729f, -26.023251f, 18.455929f, 100.078911f, 91.618004f, 129.572266f, 162.295929f, 117.883362f, 73.251602f, + 20.503130f, 123.177406f, 98.707054f, -61.945675f, -133.366302f, -42.585499f, 17.451960f, -85.110466f, -109.559792f, 57.105164f, 49.939404f, 71.494247f, 106.595436f, -5.332850f, -10.096909f, 95.286079f, + -98.944687f, -70.735931f, -91.238235f, 77.213318f, 43.834396f, 103.931374f, 14.455284f, -18.546854f, 60.298130f, 69.783432f, 81.150307f, 75.219597f, 117.014557f, 133.318222f, 45.655605f, 44.907104f, + -17.773401f, 16.685305f, 35.210880f, 58.453514f, -39.141315f, 154.492096f, 160.108368f, 54.245167f, 143.091782f, 18.370985f, -46.498653f, 30.260704f, -32.253002f, 114.865051f, 94.643227f, 42.126125f, + 8.305405f, 73.466248f, 71.895737f, 7.841229f, -21.096027f, -83.805069f, 142.372986f, 32.864574f, -67.817047f, 0.273488f, -20.763456f, -39.558540f, 45.929173f, 245.427109f, 63.606354f, -33.662392f, + -9.818366f, 215.528351f, -34.979908f, -46.600666f, -52.985126f, -36.442551f, -23.177917f, 89.040405f, 115.907364f, 85.734955f, 85.459145f, 53.537971f, 38.606289f, 35.117779f, -9.532898f, -46.531116f, + 70.627678f, 109.927406f, 130.617371f, 127.965912f, 68.237038f, 175.485825f, 141.335297f, 101.838699f, 85.440056f, 100.211769f, -9.782224f, -34.040447f, -36.362839f, -103.141747f, -183.433182f, -281.405945f, + 13.631050f, 103.082298f, 153.487061f, 95.539291f, 80.014320f, 47.319462f, -47.897068f, 144.786728f, 150.994034f, 33.507248f, 38.446999f, -11.836577f, -52.710697f, -5.434279f, -6.585646f, -43.525864f, + -46.841568f, -36.090340f, 91.028366f, 223.865204f, 162.487579f, 161.622040f, 92.281693f, 72.600441f, 62.700375f, 116.998756f, 104.000122f, 56.268940f, 3.313947f, 39.044933f, 12.683829f, -66.421524f, + -53.988426f, -4.046704f, -43.765293f, -58.490433f, -61.409744f, 68.780487f, 180.177185f, 130.743820f, 59.566154f, 41.610359f, -29.455439f, -47.845570f, -53.330845f, -194.252975f, -99.193802f, -28.624321f, + -40.226192f, 19.173496f, -102.776230f, -115.559639f, -2.041245f, 17.804632f, 54.120743f, 35.981876f, 107.003677f, 67.225113f, 6.590813f, 31.162287f, 75.625832f, 94.116089f, 68.273361f, 19.100948f, + -81.027779f, -47.543785f, -81.577866f, 147.072006f, 140.771072f, 98.894592f, 98.462875f, 120.500710f, 69.188560f, -27.267778f, -26.730125f, 19.004963f, 28.982193f, 18.988167f, 15.679336f, 0.912693f, + 60.063290f, 68.444176f, -38.306652f, 274.795166f, 81.706596f, 1.653586f, 59.518078f, 81.843979f, 45.452694f, -98.132660f, 99.485909f, 72.635452f, 59.011009f, 43.986206f, 68.393044f, 153.643753f, + -54.196396f, 105.024605f, -46.588734f, 29.173431f, 46.003738f, 53.556526f, -1.795008f, -94.732422f, 74.060417f, 37.018723f, 57.519180f, 40.312252f, 4.980567f, 1.190214f, 65.139198f, 16.854973f, + 83.697479f, 124.012848f, 136.707169f, 105.191093f, 50.574764f, 7.427887f, 165.615936f, 120.431198f, 35.935490f, 146.632690f, 107.372086f, 101.817780f, 178.695389f, 32.956997f, -43.566265f, -170.662201f, + -45.706387f, 22.193432f, 48.583588f, 7.809529f, 108.639076f, 20.145479f, -8.151466f, 16.626425f, 45.076824f, 100.699867f, 56.172535f, 31.245377f, 41.698193f, 43.700226f, 33.969212f, 13.647820f, + 30.930534f, 96.241432f, 20.796177f, 20.642069f, -30.030577f, 105.024353f, 182.286652f, 51.891121f, -23.670610f, 19.259420f, -25.995207f, 144.711807f, 151.061661f, 39.095882f, 216.597061f, 151.033951f, + 55.972961f, 165.229263f, 42.423416f, -9.421596f, 9.304959f, -24.490530f, 65.337448f, 0.772096f, 34.500309f, 28.041000f, 164.460770f, 148.005341f, -44.788933f, -131.866653f, 118.602074f, 174.952545f, + -36.805115f, 2.389628f, -160.064590f, -74.493019f, -34.030777f, -37.621536f, 21.365028f, 11.060207f, 72.113487f, 151.263977f, 203.227783f, 232.426346f, 240.348846f, 198.561386f, 130.545105f, 79.279305f, + -5.590322f, 28.170464f, 31.049704f, 123.245987f, 143.256638f, 251.395782f, 35.744690f, -42.437420f, -26.080673f, 16.841845f, 18.203182f, 83.183998f, 68.937943f, -68.034676f, 4.653465f, 101.861214f, + 75.410370f, 146.164398f, 101.675415f, 188.854752f, 65.271072f, -0.098294f, 44.761238f, -45.286770f, -80.445572f, 95.316223f, -28.573139f, 1.249410f, 194.675003f, 77.615021f, 9.229208f, 122.592499f, + -53.932175f, 216.979111f, -2.220833f, 63.310429f, 91.275101f, 57.843071f, 70.857147f, 42.466930f, 77.749489f, 57.652969f, 21.516739f, -1.124474f, -30.274309f, -13.056955f, 15.011532f, -30.375456f, + 67.425507f, 84.229256f, 101.499359f, 28.049738f, -35.614960f, 320.076202f, 252.214386f, 152.618103f, 138.893570f, 99.840240f, 27.951473f, 49.207226f, 65.402916f, 7.603233f, -14.404366f, -35.147362f, + -19.139826f, 222.586807f, 160.578033f, 15.308187f, 37.928532f, 2.810670f, 89.260468f, 73.903893f, -14.074634f, 9.220748f, 52.358765f, 29.237804f, 68.572754f, 74.369972f, 135.163269f, 53.634529f, + 27.498774f, 55.932766f, 90.594849f, 106.451241f, 66.339134f, 276.491119f, 112.921783f, 68.186401f, 34.717724f, 217.367447f, 183.300674f, 171.332642f, 233.111526f, 113.635857f, -94.105415f, 101.164040f +}; + +/*----------------------------------------------------------------------------------* + * LSF quantization - Scaling factors + *----------------------------------------------------------------------------------*/ + +/* stable ISP vector */ +const float stable_ISP[M] = +{ + 0.9808f, 0.9239f, 0.8315f, 0.7071f, 0.5556f, 0.3827f, 0.1951f, 0.0f, -0.195f, -0.3826f, -0.5555f, -0.7071f, -0.8314f, -0.9238f, -0.9808f, 0.045f +}; + +/* stable ISF vector */ +const float stable_ISF[M] = +{ + 399.846527f, 799.890991f, 1199.888550f, 1600.019531f, 1999.927002f, 2399.963379f, 2799.979736f, 3200.0f, 3599.812256f, 3999.815918f, 4399.827637f, 4799.980469f, 5199.744629f, 5599.576660f, 6000.153320f, 1554.147827f +}; + +/* stable LSP vector (corresponds to GEWB_Ave[]) */ +const float stable_LSP[M] = +{ + 0.9899f, 0.9667f, 0.8998f, 0.7837f, 0.6581f, 0.5009f, 0.3307f, 0.1643f, -0.0224f, -0.1955f, -0.3658f, -0.5200f, -0.6730f, -0.8040f, -0.9057f,-0.9700f +}; + + +/*----------------------------------------------------------------------------------* + * LSF quantization - Mean LSF vectors + *----------------------------------------------------------------------------------*/ +/* These are not used anywhere */ +/* A 16-by-1 matrix */ +const float means_wb_cleanspeech_lsf16k0[16] = {355.08f, 696.48f, 1260.55f, 1735.55f, 2220.70f, 2676.17f, 3123.44f, 3560.94f, 3989.45f, 4399.61f, 4869.14f, 5372.66f, 5894.53f, 6364.45f, 6883.20f, 7302.73f}; +/* A 16-by-1 matrix */ +const float means_swb_cleanspeech_lsf25k6[16] = {614.44f, 1437.24f, 2259.37f, 2994.68f, 3732.57f, 4420.10f, 5187.93f, 5985.97f, 6790.66f, 7523.16f, 8283.87f, 9010.86f, 9757.03f, 10458.90f, 11209.84f, 11888.64f}; +/* A 16-by-1 matrix */ +const float means_swb_cleanspeech_lsf32k0[16] = {739.65f, 1811.71f, 2794.79f, 3708.53f, 4594.87f, 5528.75f, 6583.99f, 7512.05f, 8455.51f, 9352.67f, 10266.73f, 11133.74f, 12067.91f, 12958.21f, 13940.67f, 14794.15f}; + +/* An 16-by-1 matrix */ +const float SVWB2_Ave[16] = +{ + 389.8438f, 581.2500f, 1047.6563f, 1493.3594f, 1985.9375f, 2462.8906f, 2923.8281f, 3392.9688f, 3851.9531f, 4298.4375f, 4819.9219f, 5337.5000f, 5893.7500f, 6378.9063f, 6899.6094f, 7325.7813f +}; +/* An 16-by-1 matrix */ +const float IANB_Ave[16] = +{ + 283.5938f, 559.7656f, 973.8281f, 1331.2500f, 1695.3125f, 2037.1094f, 2383.9844f, 2713.6719f, 3035.9375f, 3334.3750f, 3614.0625f, 3910.9375f, 4261.3281f, 4854.2969f, 5467.5781f, 5934.7656f +}; +/* An 16-by-1 matrix */ +const float IAWB_Ave[16] = +{ + 225.3906f, 527.3438f, 986.7188f, 1380.8594f, 1773.0469f, 2150.0000f, 2537.8906f, 2914.0625f, 3298.8281f, 3670.3125f, 4051.1719f, 4421.4844f, 4807.4219f, 5182.8125f, 5566.0156f, 5940.2344f +}; +/* An 16-by-1 matrix */ +const float IAWB2_Ave[16] = +{ + 285.5469f, 694.1406f, 1247.6563f, 1713.2813f, 2198.8281f, 2658.5938f, 3129.6875f, 3579.6875f, 4034.7656f, 4480.0781f, 4973.0469f, 5483.2031f, 5986.7188f, 6460.1563f, 6953.5156f, 7393.3594f +}; +/* An 16-by-1 matrix */ +const float UVNB_Ave[16] = +{ + 397.6563f, 689.0625f, 1115.6250f, 1465.2344f, 1801.1719f, 2113.2813f, 2434.7656f, 2719.1406f, 3001.9531f, 3243.7500f, 3460.5469f, 3642.5781f, 3897.2656f, 4586.3281f, 5351.1719f, 5888.2813f +}; +/* An 16-by-1 matrix */ +const float UVWB_Ave[16] = +{ + 350.7813f, 742.1875f, 1239.0625f, 1636.7188f, 2023.8281f, 2406.6406f, 2786.7188f, 3150.7813f, 3513.6719f, 3862.5000f, 4212.5000f, 4545.3125f, 4893.3594f, 5232.8125f, 5586.3281f, 5930.8594f +}; +/* An 16-by-1 matrix */ +const float SVNB_Ave[16] = +{ + 347.6563f, 495.3125f, 753.9063f, 1133.5938f, 1538.2813f, 1883.9844f, 2278.1250f, 2595.3125f, 2924.6094f, 3203.9063f, 3478.9063f, 3728.5156f, 4214.0625f, 4908.2031f, 5452.7344f, 5930.8594f +}; +/* An 16-by-1 matrix */ +const float SVWB_Ave[16] = +{ + 325.0000f, 487.5000f, 761.3281f, 1204.2969f, 1613.6719f, 1998.8281f, 2413.6719f, 2760.5469f, 3128.1250f, 3485.1563f, 3857.4219f, 4195.7031f, 4603.5156f, 5023.4375f, 5456.2500f, 5878.1250f +}; +/* An 16-by-1 matrix */ +const float GEWB_Ave[16] = +{ + 289.8438f, 527.3438f, 919.5313f, 1365.2344f, 1736.7188f, 2131.2500f, 2513.2813f, 2863.6719f, 3245.7031f, 3600.7813f, 3962.8906f, 4314.0625f, 4703.9063f, 5102.7344f, 5508.2031f, 5899.6094f +}; +/* An 16-by-1 matrix */ +const float GEWB2_Ave[16] = +{ + 355.0781f, 696.4844f, 1260.5469f, 1735.5469f, 2220.7031f, 2676.1719f, 3123.4375f, 3560.9375f, 3989.4531f, 4399.6094f, 4869.1406f, 5372.6563f, 5894.5313f, 6364.4531f, 6883.2031f, 7302.7344f +}; +/* An 16-by-1 matrix */ +const float GENB_Ave[16] = +{ + 326.5625f, 525.0000f, 881.6406f, 1274.6094f, 1630.0781f, 1965.2344f, 2324.2188f, 2619.9219f, 2935.1563f, 3216.4063f, 3469.1406f, 3687.1094f, 4059.7656f, 4775.7813f, 5412.1094f, 5912.1094f +}; +/* An 16-by-1 matrix */ +const float TRNB_Ave[16] = +{ + 358.9844f, 521.4844f, 822.6563f, 1227.3438f, 1598.4375f, 1928.9063f, 2306.6406f, 2605.4688f, 2925.7813f, 3202.7344f, 3464.0625f, 3689.0625f, 4118.7500f, 4837.1094f, 5429.6875f, 5920.3125f +}; +/* An 16-by-1 matrix */ +const float TRWB_Ave[16] = +{ + 325.7813f, 517.9688f, 840.2344f, 1305.0781f, 1681.6406f, 2069.9219f, 2467.9688f, 2811.7188f, 3190.2344f, 3543.3594f, 3906.6406f, 4244.9219f, 4637.1094f, 5043.7500f, 5463.2813f, 5877.3438f +}; +/* An 16-by-1 matrix */ +const float TRWB2_Ave[16] = +{ + 369.1406f, 603.9063f, 1119.5313f, 1621.0938f, 2086.7188f, 2565.6250f, 2992.1875f, 3441.0156f, 3864.8438f, 4271.0938f, 4753.9063f, 5303.5156f, 5851.9531f, 6359.3750f, 6880.4688f, 7335.1563f +}; +/* An 16-by-1 matrix */ +const float AUNB_Ave[16] = +{ + 346.4844f, 563.6719f, 920.3125f, 1247.6563f, 1603.5156f, 1933.2031f, 2281.6406f, 2591.7969f, 2905.0781f, 3195.7031f, 3463.6719f, 3702.3438f, 4056.6406f, 4758.5938f, 5413.2813f, 5910.5469f +}; +/* An 16-by-1 matrix */ +const float AUWB_Ave[16] = +{ + 316.4063f, 573.4375f, 967.1875f, 1334.7656f, 1717.1875f, 2086.7188f, 2465.2344f, 2818.3594f, 3191.7969f, 3546.0938f, 3917.9688f, 4284.7656f, 4692.9688f, 5107.4219f, 5525.7813f, 5911.3281f +}; +/* An 16-by-1 matrix */ +const float AUWB2_Ave[16] = +{ + 364.4531f, 681.6406f, 1187.5000f, 1623.8281f, 2101.1719f, 2535.1563f, 2986.7188f, 3408.2031f, 3848.4375f, 4269.5313f, 4771.0938f, 5330.8594f, 5883.5938f, 6366.0156f, 6889.0625f, 7331.2500f +}; +/* An 16-by-1 matrix */ +const float Predictor0[16] = +{ + 0.83499f, 0.83499f, 0.83499f, 0.82999f, 0.82999f, 0.82999f, 0.80499f, 0.80750f, 0.79999f, 0.79300f, 0.80750f, 0.80750f, 0.79300f, 0.78500f, 0.78500f, 0.75500f +}; +/* An 16-by-1 matrix */ +const float Predictor1[16] = +{ + 0.82501f, 0.82501f, 0.82501f, 0.81299f, 0.80301f, 0.81299f, 0.81299f, 0.79749f, 0.79999f, 0.79999f, 0.80750f, 0.82001f, 0.82001f, 0.81500f, 0.82501f, 0.81299f +}; +/* An 16-by-1 matrix */ +const float Predictor2[16] = +{ + 0.73999f, 0.72000f, 0.74799f, 0.73999f, 0.74799f, 0.73300f, 0.73300f, 0.72501f, 0.72501f, 0.73300f, 0.73999f, 0.73999f, 0.72000f, 0.70499f, 0.72000f, 0.70499f +}; +/* An 16-by-1 matrix */ +const float Predictor3[16] = +{ + 0.73999f, 0.73999f, 0.75500f, 0.73999f, 0.74799f, 0.72501f, 0.71500f, 0.70499f, 0.69000f, 0.70499f, 0.72000f, 0.75500f, 0.76300f, 0.75500f, 0.76300f, 0.75800f +}; +/* An 16-by-1 matrix */ +const float Predictor4[16] = +{ + 0.57999f, 0.56000f, 0.58801f, 0.57999f, 0.58801f, 0.57300f, 0.57300f, 0.56500f, 0.56500f, 0.57300f, 0.57999f, 0.57999f, 0.56000f, 0.54501f, 0.54001f, 0.52499f +}; +/* An 16-by-1 matrix */ +const float Predictor5[16] = +{ + 0.72751f, 0.72000f, 0.72000f, 0.72751f, 0.72751f, 0.72000f, 0.72000f, 0.72000f, 0.72751f, 0.73499f, 0.74301f, 0.75000f, 0.75000f, 0.71301f, 0.71301f, 0.71301f +}; +/* An 16-by-1 matrix */ +const float Predictor6[16] = +{ + 0.73499f, 0.72751f, 0.73499f, 0.72000f, 0.72000f, 0.70001f, 0.68301f, 0.66501f, 0.64499f, 0.67001f, 0.68301f, 0.74301f, 0.75000f, 0.72000f, 0.75000f, 0.74301f +}; +/* An 16-by-1 matrix */ +const float Predictor7[16] = +{ + 0.74301f, 0.73499f, 0.74301f, 0.74301f, 0.74301f, 0.73499f, 0.74301f, 0.75000f, 0.75000f, 0.75500f, 0.76501f, 0.74301f, 0.73499f, 0.72751f, 0.71301f, 0.75500f +}; +/* An 16-by-1 matrix */ +const float Predictor8[16] = +{ + 0.75500f, 0.75500f, 0.75500f, 0.75000f, 0.75000f, 0.75000f, 0.73499f, 0.72751f, 0.72000f, 0.71301f, 0.72751f, 0.72751f, 0.71301f, 0.70499f, 0.70499f, 0.67499f +}; +/* An 16-by-16 matrix */ +const float UVD_MA1[256] = +{ + -117.5781f, -196.4844f, -166.4063f, -73.0469f, -51.1719f, -25.0000f, -17.5781f, -7.8125f, 4.2969f, 21.8750f, 24.6094f, 35.1563f, 42.9688f, 68.3594f, 37.8906f, 12.8906f, + 62.8906f, 137.8906f, 185.1563f, 196.0938f, 276.9531f, 305.4688f, 310.1563f, 298.8281f, 246.8750f, 207.8125f, 158.5938f, 111.3281f, 89.8438f, 56.6406f, 37.8906f, 20.3125f, + -14.4531f, -1.9531f, 80.0781f, 126.1719f, 160.9375f, 136.3281f, 86.3281f, 35.5469f, -2.3438f, -23.0469f, -33.5938f, -43.7500f, -12.5000f, 81.6406f, 28.5156f, 8.9844f, + -106.6406f, -240.2344f, -320.3125f, -310.1563f, -325.7813f, -327.3438f, -321.0938f, -319.9219f, -293.3594f, -273.8281f, -250.3906f, -219.5313f, -152.7344f, -105.8594f, -71.8750f, -24.6094f, + 102.3438f, 65.6250f, 40.6250f, -3.5156f, -30.4688f, -63.6719f, -55.0781f, -77.7344f, -74.6094f, -97.2656f, -95.7031f, -123.8281f, -65.6250f, 208.9844f, 42.5781f, 12.8906f, + -160.1563f, -263.6719f, -266.0156f, -238.6719f, -195.3125f, -154.6875f, -106.6406f, -71.4844f, -18.3594f, 23.4375f, 75.7813f, 139.4531f, 407.8125f, 421.8750f, 130.8594f, 54.6875f, + 60.1563f, 72.2656f, 100.0000f, 92.9688f, 79.2969f, 92.9688f, 109.3750f, 101.5625f, 117.1875f, 104.2969f, 100.7813f, 76.5625f, 47.2656f, -241.4063f, -102.7344f, -23.4375f, + 134.7656f, 275.3906f, 335.5469f, 307.0313f, 290.2344f, 228.1250f, 166.0156f, 104.2969f, 65.6250f, 41.0156f, 28.9063f, 10.9375f, 46.4844f, 104.2969f, 41.0156f, 15.2344f, + -15.2344f, -64.8438f, -89.8438f, -76.5625f, -99.6094f, -107.8125f, -124.2188f, -136.3281f, -151.1719f, -171.0938f, -210.5469f, -239.4531f, -293.7500f, -373.4375f, -528.5156f, -635.9375f, + 194.5313f, 187.1094f, 161.7188f, 90.2344f, 38.2813f, 1.9531f, -7.0313f, -16.0156f, -23.4375f, -30.4688f, -35.5469f, -37.5000f, -31.6406f, 28.1250f, 11.7188f, -3.1250f, + 16.0156f, 46.8750f, 25.3906f, 55.0781f, 45.7031f, 72.6563f, 97.2656f, 116.7969f, 163.2813f, 203.1250f, 221.0938f, 241.4063f, 270.3125f, 226.1719f, 125.3906f, 64.8438f, + -92.1875f, -108.5938f, -26.9531f, 5.0781f, 44.1406f, 141.4063f, 173.8281f, 210.5469f, 196.4844f, 151.1719f, 105.0781f, 67.1875f, 46.8750f, -8.2031f, 0.3906f, 1.5625f, + -40.2344f, -17.9688f, -53.5156f, -51.5625f, -42.1875f, -37.8906f, -26.1719f, -14.4531f, -3.1250f, 16.0156f, 32.0313f, 41.7969f, 16.7969f, -236.3281f, -73.8281f, -21.8750f, + -85.9375f, -123.0469f, -188.2813f, -201.5625f, -191.0156f, -173.8281f, -162.1094f, -141.4063f, -118.7500f, -80.0781f, -53.1250f, -26.5625f, -2.7344f, 51.1719f, 27.3438f, 9.7656f, + -3.9063f, -47.2656f, -82.0313f, -92.5781f, -87.5000f, -117.9688f, -96.0938f, -121.0938f, -105.8594f, -133.9844f, -111.3281f, -142.1875f, 10.9375f, 274.6094f, 52.7344f, 21.0938f, + 46.0938f, 19.5313f, -26.1719f, -64.8438f, -136.3281f, -162.5000f, -172.6563f, -174.2188f, -171.4844f, -164.0625f, -149.2188f, -124.6094f, -95.7031f, -81.6406f, -54.6875f, -32.0313f +}; +/* An 16-by-16 matrix */ +const float UVD_MA2[256] = +{ + -29.2969f, -25.0000f, -58.5938f, -90.2344f, -106.2500f, -108.5938f, -96.8750f, -75.7813f, -60.9375f, -41.7969f, -28.9063f, -16.7969f, -35.9375f, -8.2031f, 3.5156f, 1.9531f, + 153.5156f, 107.4219f, -4.6875f, -60.9375f, -81.2500f, -83.9844f, -63.2813f, -51.5625f, -44.9219f, -42.5781f, -36.7188f, -33.2031f, -40.6250f, -3.9063f, 1.9531f, -0.3906f, + -116.0156f, -151.9531f, -38.6719f, -30.4688f, -25.7813f, -7.4219f, -4.6875f, 3.1250f, 0.0000f, -1.1719f, -5.8594f, -8.5938f, -44.1406f, -32.0313f, -6.2500f, 0.7813f, + 23.0469f, -4.2969f, 1.9531f, -12.8906f, -4.2969f, -23.8281f, -27.3438f, -54.2969f, -55.8594f, -93.3594f, -80.8594f, -87.1094f, 277.7344f, 273.8281f, 55.8594f, 26.5625f, + -76.1719f, 158.5938f, 86.7188f, 19.1406f, -2.3438f, -8.9844f, -2.3438f, 3.5156f, 0.0000f, 5.0781f, 10.1563f, 19.1406f, -17.1875f, -50.3906f, -7.0313f, -2.7344f, + 8.9844f, -11.7188f, -55.0781f, 30.8594f, -7.0313f, -29.6875f, -21.4844f, -5.4688f, 17.1875f, 38.2813f, 34.3750f, 33.5938f, -37.5000f, -137.1094f, -43.7500f, -15.2344f, + 148.4375f, 128.5156f, 91.7969f, 67.5781f, 55.0781f, 28.1250f, 9.7656f, -1.5625f, -2.3438f, -7.4219f, -8.2031f, -12.8906f, -21.4844f, -8.9844f, 1.1719f, -0.3906f, + -31.6406f, -82.0313f, -110.9375f, 61.7188f, 154.6875f, 113.2813f, 63.6719f, 23.0469f, -9.7656f, -8.5938f, -3.9063f, -2.3438f, -17.9688f, -12.5000f, 3.5156f, 1.9531f, + 3.5156f, 13.2813f, -5.8594f, 1.9531f, 8.9844f, -18.7500f, -49.6094f, -94.9219f, -135.5469f, -164.4531f, -177.7344f, -185.5469f, -193.3594f, -175.3906f, -114.8438f, -63.6719f, + -5.0781f, -66.7969f, -162.5000f, -161.7188f, -95.7031f, -9.7656f, 26.9531f, 39.8438f, 40.6250f, 32.8125f, 19.5313f, 12.8906f, -14.8438f, -1.5625f, 0.0000f, 1.9531f, + 19.5313f, 46.0938f, 26.5625f, 14.4531f, 57.4219f, 124.6094f, 144.9219f, 138.6719f, 113.6719f, 79.6875f, 50.7813f, 31.6406f, 8.2031f, 17.9688f, 14.0625f, 8.5938f, + -37.1094f, -42.1875f, 121.4844f, 83.5938f, -10.9375f, -59.7656f, -88.2813f, -75.0000f, -50.3906f, -26.9531f, -16.4063f, -4.2969f, -18.7500f, -6.6406f, 5.0781f, 0.7813f, + -72.2656f, -87.1094f, -40.6250f, 10.1563f, 20.7031f, 34.7656f, 51.5625f, 70.7031f, 100.7813f, 135.1563f, 155.0781f, 173.8281f, 153.1250f, 94.1406f, 48.8281f, 22.6563f, + 32.4219f, 12.8906f, -3.5156f, -31.6406f, 15.6250f, 38.6719f, 21.8750f, 3.1250f, -19.9219f, -33.2031f, -41.4063f, -48.4375f, -76.5625f, 1.9531f, 1.9531f, 0.0000f, + 55.8594f, 57.8125f, 7.4219f, -47.2656f, -96.4844f, -82.4219f, -26.1719f, 32.4219f, 77.3438f, 104.6875f, 113.2813f, 117.1875f, 93.7500f, 64.0625f, 33.5938f, 14.4531f, + -77.3438f, -53.1250f, 144.5313f, 145.3125f, 117.1875f, 93.7500f, 60.9375f, 44.1406f, 30.8594f, 23.4375f, 17.1875f, 11.3281f, -13.6719f, -14.8438f, 2.3438f, 2.7344f +}; +/* An 16-by-16 matrix */ +const float UVWB_MA3[256] = +{ + -10.1563f, 8.9844f, 2.7344f, -2.3438f, -0.3906f, 1.1719f, 15.6250f, 13.6719f, -16.7969f, -9.3750f, 21.8750f, 61.3281f, 103.5156f, 165.2344f, 149.2188f, 101.5625f, + 23.8281f, -117.1875f, -50.7813f, -39.4531f, -3.1250f, 41.4063f, 42.1875f, 44.5313f, 34.3750f, 16.7969f, -0.7813f, -12.8906f, -21.8750f, 26.1719f, 11.3281f, 5.0781f, + -12.1094f, 18.3594f, 17.5781f, -47.2656f, 17.9688f, 8.5938f, 43.3594f, 91.0156f, -100.0000f, -98.4375f, -48.0469f, -27.7344f, -12.1094f, 21.0938f, 21.8750f, 12.8906f, + 7.8125f, -60.1563f, 26.1719f, 77.3438f, -90.6250f, -65.2344f, -33.5938f, -4.6875f, 30.8594f, 45.3125f, 34.3750f, 30.4688f, 17.1875f, 29.2969f, 10.5469f, -2.7344f, + -5.4688f, 59.7656f, -64.8438f, 8.2031f, 41.7969f, 25.0000f, 91.0156f, -87.1094f, -57.4219f, -10.5469f, -0.3906f, 16.7969f, 23.8281f, 27.3438f, 19.5313f, 7.0313f, + 1.1719f, -44.9219f, -3.1250f, 55.8594f, 75.0000f, 75.3906f, -48.4375f, -76.1719f, -77.3438f, -63.2813f, -29.2969f, 5.4688f, 17.5781f, 32.4219f, 30.8594f, 19.1406f, + 4.6875f, -22.2656f, 9.7656f, -11.3281f, -4.2969f, 4.6875f, -2.7344f, -5.0781f, -4.6875f, 12.1094f, 28.9063f, 38.6719f, -3.9063f, -164.4531f, -81.6406f, -43.3594f, + -9.7656f, 44.9219f, 46.4844f, -7.4219f, -45.7031f, -64.0625f, -79.2969f, -92.5781f, -80.4688f, -66.0156f, -42.9688f, -16.0156f, -4.2969f, 5.8594f, 0.3906f, -2.7344f, + -5.0781f, 66.4063f, -55.8594f, -50.0000f, -87.5000f, -36.7188f, 0.3906f, 37.5000f, 56.2500f, 39.8438f, 11.3281f, 0.7813f, -14.4531f, 17.9688f, 2.7344f, -4.6875f, + -4.2969f, 3.9063f, -13.2813f, 14.8438f, 9.3750f, 33.5938f, 58.2031f, 82.4219f, 93.7500f, 108.9844f, 96.4844f, 85.1563f, 60.1563f, 62.8906f, 28.9063f, 5.8594f, + -9.3750f, 25.0000f, 42.9688f, 48.8281f, -9.3750f, 48.0469f, 62.8906f, 64.8438f, 69.1406f, 7.0313f, -43.7500f, -45.3125f, -55.0781f, -45.7031f, -44.1406f, -35.5469f, + -1.5625f, -7.8125f, -6.6406f, -4.2969f, -10.5469f, 5.0781f, -5.8594f, -15.6250f, -22.6563f, -61.3281f, -98.4375f, -110.5469f, -112.5000f, -72.6563f, -63.2813f, -43.7500f, + -7.8125f, 0.7813f, 12.5000f, 17.1875f, -12.1094f, -19.1406f, 3.1250f, 5.0781f, 21.4844f, -23.0469f, -63.2813f, -82.8125f, -23.8281f, 150.0000f, 44.9219f, 14.0625f, + -1.5625f, 16.4063f, -29.2969f, 35.9375f, 104.6875f, -79.2969f, -48.8281f, 3.9063f, 20.3125f, 47.2656f, 28.1250f, -16.7969f, -42.5781f, -18.3594f, -25.7813f, -29.6875f, + -15.2344f, 29.6875f, 104.6875f, -99.2188f, -10.9375f, 33.9844f, 0.7813f, 35.5469f, 33.2031f, 26.5625f, 34.7656f, 37.5000f, 16.4063f, 35.1563f, 15.2344f, 1.5625f, + 0.7813f, 0.7813f, -21.8750f, 2.7344f, 26.1719f, -12.1094f, -85.5469f, -75.0000f, -9.3750f, 57.0313f, 97.2656f, 105.0781f, 81.6406f, 77.7344f, 41.4063f, 12.1094f +}; +/* An 16-by-16 matrix */ +const float SVNB_SN1[256] = +{ + 52.7344f, 42.5781f, 52.7344f, -59.7656f, -214.4531f, 83.5938f, 162.5000f, 76.1719f, 113.6719f, 96.4844f, 39.0625f, -49.6094f, -226.1719f, -62.5000f, -25.7813f, -12.5000f, + -41.7969f, -58.5938f, -107.0313f, -58.2031f, 250.7813f, 232.0313f, 132.0313f, 71.4844f, 31.6406f, -12.1094f, -5.4688f, -58.5938f, -151.1719f, -15.6250f, -17.1875f, -7.0313f, + 28.5156f, 16.4063f, 66.7969f, 132.4219f, 83.2031f, 16.4063f, -53.5156f, -108.2031f, -148.0469f, -172.2656f, -171.8750f, -186.7188f, 105.4688f, 49.2188f, -1.5625f, 2.3438f, + -119.9219f, -187.1094f, -248.4375f, -232.8125f, -39.0625f, 32.4219f, 65.2344f, 78.1250f, 101.5625f, 146.8750f, 204.2969f, 410.5469f, 446.0938f, 191.4063f, 97.2656f, 42.1875f, + -57.8125f, -83.9844f, -126.5625f, -222.6563f, -358.2031f, -267.5781f, -81.2500f, 49.6094f, 111.3281f, 137.8906f, 172.2656f, 367.1875f, 429.6875f, 178.9063f, 89.4531f, 39.0625f, + 166.7969f, 168.7500f, 214.0625f, 166.4063f, 51.9531f, 5.0781f, -3.5156f, -55.0781f, -42.1875f, -56.2500f, -76.1719f, -163.6719f, -286.3281f, -56.2500f, -42.5781f, -17.5781f, + -44.9219f, -85.9375f, -75.7813f, 258.2031f, 350.0000f, 268.7500f, 191.0156f, 137.1094f, 82.4219f, 100.7813f, 57.4219f, 11.7188f, -291.4063f, -306.2500f, -60.9375f, -37.1094f, + 6.2500f, -18.7500f, -34.3750f, -167.9688f, -311.7188f, 14.0625f, 79.6875f, 26.5625f, 67.9688f, 63.2813f, 7.8125f, 23.8281f, 244.9219f, 103.9063f, 39.8438f, 18.7500f, + -98.4375f, -144.5313f, -246.0938f, -239.8438f, 265.6250f, 400.0000f, 339.4531f, 233.5938f, 163.6719f, 101.1719f, 75.3906f, 10.5469f, 35.1563f, 60.9375f, 20.7031f, 10.5469f, + -18.7500f, 12.8906f, 10.1563f, -88.6719f, -217.1875f, -299.2188f, -152.7344f, 90.2344f, 161.3281f, 110.1563f, 88.2813f, 34.7656f, 75.7813f, 73.0469f, 17.1875f, 11.7188f, + -79.6875f, -113.6719f, -134.7656f, -51.1719f, 48.8281f, 28.1250f, 6.2500f, -11.3281f, -41.4063f, -19.1406f, -10.5469f, 71.4844f, 278.9063f, 108.2031f, 44.5313f, 19.1406f, + -4.2969f, 80.0781f, 111.3281f, 26.9531f, -22.6563f, -80.8594f, -117.5781f, -62.5000f, -11.7188f, -0.7813f, 4.6875f, -38.6719f, -226.5625f, -69.5313f, -31.2500f, -16.0156f, + 46.8750f, 73.8281f, 109.7656f, 166.7969f, 91.4063f, 53.9063f, 48.4375f, 49.2188f, 19.5313f, 80.0781f, 47.2656f, 29.6875f, -311.3281f, -470.3125f, -91.7969f, -51.9531f, + 24.6094f, -7.0313f, 57.0313f, 260.1563f, 187.5000f, 92.1875f, 52.3438f, -15.2344f, -37.8906f, -50.7813f, -68.3594f, -147.6563f, -291.4063f, -62.1094f, -41.4063f, -17.9688f, + 150.7813f, 155.8594f, 162.1094f, 61.3281f, -68.3594f, -110.1563f, -123.0469f, -124.2188f, -86.7188f, -87.8906f, -104.2969f, -133.5938f, 123.8281f, 59.3750f, 5.8594f, 5.4688f, + 15.2344f, 21.8750f, 27.7344f, -37.1094f, -151.1719f, -198.8281f, -232.4219f, -182.0313f, -154.2969f, -72.6563f, -9.3750f, 164.4531f, 317.9688f, 114.0625f, 49.6094f, 20.3125f +}; +/* An 16-by-16 matrix */ +const float SVNB_SN2[256] = +{ + -6.2500f, 43.3594f, 43.3594f, -34.7656f, -44.9219f, -157.8125f, -200.7813f, 63.2813f, 108.2031f, 16.0156f, -36.7188f, -34.7656f, 5.8594f, 12.1094f, 0.7813f, 0.7813f, + -32.0313f, -38.6719f, -9.7656f, -112.1094f, -181.2500f, 79.6875f, 7.0313f, -48.0469f, -14.8438f, 21.8750f, 42.5781f, 77.3438f, 62.5000f, 37.5000f, 16.0156f, 7.4219f, + -37.1094f, -24.2188f, -94.5313f, -162.1094f, 124.2188f, 46.0938f, -47.2656f, 17.1875f, 28.9063f, 15.6250f, 33.2031f, 44.5313f, 20.3125f, 14.0625f, 8.2031f, 3.1250f, + 11.3281f, 15.6250f, 16.7969f, 8.9844f, -78.9063f, -58.2031f, 112.5000f, 58.2031f, -7.8125f, -42.5781f, -72.6563f, -107.4219f, -49.6094f, 7.0313f, -9.7656f, -2.3438f, + 7.8125f, 14.0625f, -37.8906f, -89.0625f, 220.7031f, 198.4375f, 52.3438f, 16.4063f, -27.3438f, -92.5781f, -100.7813f, -101.1719f, -48.0469f, -3.5156f, -11.3281f, -3.9063f, + -28.1250f, -66.0156f, 192.1875f, 180.8594f, 75.3906f, 79.6875f, -5.0781f, -29.2969f, -32.0313f, -48.8281f, -70.7031f, -89.8438f, -70.7031f, -3.9063f, -15.6250f, -4.6875f, + -42.1875f, -86.3281f, -89.4531f, 253.1250f, 224.6094f, 112.5000f, 57.0313f, 0.3906f, -5.4688f, -1.5625f, -19.9219f, -46.8750f, -31.6406f, -5.4688f, -6.6406f, -1.9531f, + -77.7344f, -103.1250f, -120.7031f, 81.6406f, 3.1250f, -50.0000f, 9.3750f, -18.3594f, 33.9844f, 100.3906f, 93.7500f, 72.2656f, 36.3281f, 27.3438f, 13.2813f, 6.2500f, + 9.7656f, 32.0313f, -23.4375f, -60.5469f, -158.9844f, -240.2344f, 11.3281f, 39.0625f, -44.1406f, 12.5000f, 80.8594f, 100.7813f, 79.2969f, 43.3594f, 19.1406f, 8.2031f, + 14.4531f, 49.6094f, 37.1094f, 1.5625f, 43.7500f, -17.5781f, -84.7656f, -61.7188f, -108.2031f, -158.9844f, -118.7500f, -59.3750f, 28.1250f, 20.3125f, -2.3438f, 0.0000f, + -11.7188f, -31.6406f, -45.3125f, -162.5000f, -85.5469f, 264.4531f, 210.1563f, 128.1250f, 83.2031f, 23.4375f, -23.4375f, -42.5781f, -30.4688f, 0.0000f, -1.9531f, 0.0000f, + 3.5156f, -5.8594f, 10.1563f, 29.2969f, -68.3594f, -131.2500f, -262.8906f, -228.9063f, 92.9688f, 121.0938f, 77.3438f, 73.8281f, 82.8125f, 49.2188f, 18.7500f, 9.3750f, + -7.0313f, -1.5625f, -31.2500f, 39.8438f, 50.7813f, -45.3125f, -104.6875f, -183.9844f, -221.4844f, -40.6250f, 80.0781f, 86.3281f, 55.8594f, 31.6406f, 11.3281f, 4.6875f, + 1.5625f, 15.2344f, 25.3906f, 44.9219f, 34.3750f, 73.8281f, 53.1250f, 48.4375f, 19.1406f, 41.4063f, 14.4531f, 34.7656f, -146.4844f, -244.5313f, -44.5313f, -28.5156f, + 210.9375f, 205.0781f, 184.3750f, 86.3281f, 46.0938f, -12.1094f, 5.8594f, 2.7344f, -27.7344f, -54.2969f, -42.1875f, -36.3281f, -5.0781f, -1.5625f, -5.0781f, -3.1250f, + -17.1875f, -17.1875f, -55.8594f, -106.2500f, -205.0781f, -142.5781f, 187.1094f, 196.0938f, 121.8750f, 87.8906f, 62.8906f, 28.1250f, 10.9375f, 16.4063f, 10.1563f, 4.6875f +}; +/* An 16-by-16 matrix */ +const float SVWB_SN1[256] = +{ + -27.7344f, -23.8281f, -66.4063f, -219.9219f, -375.7813f, -330.0781f, 72.6563f, 164.4531f, 110.1563f, 134.3750f, 101.5625f, 60.5469f, 72.6563f, 20.3125f, -7.0313f, -4.2969f, + -41.7969f, -54.2969f, -112.8906f, -105.4688f, 307.8125f, 240.2344f, 97.2656f, 67.9688f, -0.3906f, -9.3750f, 62.1094f, 41.4063f, -17.9688f, -71.4844f, -73.0469f, -41.7969f, + -56.2500f, -86.3281f, -83.9844f, 140.2344f, 75.0000f, -13.2813f, -72.6563f, -127.3438f, -100.0000f, -48.4375f, -19.1406f, 32.8125f, 83.5938f, 92.5781f, 72.6563f, 35.5469f, + 85.1563f, 129.6875f, 130.8594f, 16.0156f, -74.6094f, -153.9063f, -239.8438f, -212.1094f, -162.1094f, -148.0469f, -111.3281f, -59.7656f, -33.5938f, -39.4531f, -26.9531f, -5.0781f, + 229.2969f, 240.6250f, 285.9375f, 163.6719f, 105.4688f, 98.4375f, 39.8438f, 15.6250f, 20.7031f, -13.6719f, -22.2656f, -13.2813f, 7.4219f, -5.4688f, -5.8594f, -46.8750f, + -29.6875f, -86.7188f, -49.6094f, 475.0000f, 464.0625f, 318.3594f, 207.8125f, 125.0000f, 121.4844f, 89.0625f, 13.2813f, -23.0469f, -37.5000f, -33.5938f, -17.1875f, -14.8438f, + -68.7500f, -110.1563f, -198.0469f, -177.7344f, 438.2813f, 530.8594f, 376.9531f, 289.8438f, 238.2813f, 175.0000f, 185.1563f, 160.9375f, 72.2656f, 49.6094f, 49.6094f, -9.3750f, + -60.9375f, -87.8906f, 6.2500f, 178.9063f, 165.2344f, 171.0938f, 153.5156f, 156.2500f, 205.0781f, 257.0313f, 266.4063f, 266.0156f, 239.0625f, 171.0938f, 104.2969f, 26.5625f, + 34.7656f, 46.8750f, 67.1875f, 138.6719f, 76.1719f, -3.1250f, -8.5938f, -26.1719f, -42.9688f, -15.6250f, -36.3281f, -63.6719f, -149.2188f, -267.5781f, -361.7188f, -182.8125f, + -88.6719f, -141.4063f, -176.5625f, -225.3906f, -83.2031f, -8.5938f, 21.8750f, 32.0313f, 51.5625f, 84.3750f, 135.9375f, 164.0625f, 139.8438f, 116.7969f, 100.3906f, 55.8594f, + 14.8438f, -30.0781f, 45.7031f, 334.3750f, 189.8438f, 110.1563f, 6.2500f, -60.1563f, -50.7813f, -123.0469f, -241.4063f, -305.8594f, -348.4375f, -212.8906f, -34.3750f, 23.0469f, + 85.1563f, 126.5625f, 90.6250f, -63.2813f, -227.7344f, -215.6250f, 49.2188f, 24.2188f, -15.6250f, -10.5469f, -88.6719f, -135.9375f, -130.4688f, -126.5625f, -92.9688f, -25.3906f, + 32.0313f, 6.2500f, -7.8125f, -210.5469f, -307.4219f, 235.9375f, 132.8125f, 101.1719f, 101.5625f, -20.7031f, -98.0469f, -82.4219f, -4.6875f, 49.6094f, 66.7969f, 38.6719f, + -9.3750f, 65.6250f, 78.9063f, -55.4688f, -87.1094f, -175.0000f, -110.1563f, 47.6563f, 57.8125f, 60.5469f, 141.7969f, 148.4375f, 135.5469f, 102.7344f, 48.4375f, -26.5625f, + 64.4531f, 58.5938f, 88.2813f, 37.1094f, -67.1875f, -100.3906f, -161.3281f, -199.2188f, -208.2031f, -286.7188f, -396.0938f, -471.0938f, -325.7813f, -63.2813f, 2.3438f, 37.8906f, + -30.4688f, -28.1250f, -31.6406f, -125.7813f, -236.3281f, -285.5469f, -289.0625f, -220.3125f, -139.0625f, -85.5469f, -58.9844f, 4.2969f, 78.1250f, 92.5781f, 82.8125f, 66.4063f +}; +/* An 16-by-16 matrix */ +const float SVWB_SN2[256] = +{ + -49.2188f, -59.3750f, -133.5938f, -165.2344f, 121.4844f, 37.1094f, 1.1719f, 11.3281f, -36.3281f, 1.5625f, 88.6719f, 75.3906f, 55.4688f, 46.8750f, 36.3281f, 24.2188f, + 74.2188f, 100.7813f, 149.2188f, 121.0938f, 64.8438f, -4.2969f, -30.0781f, -26.1719f, -84.7656f, -127.7344f, -128.9063f, -147.6563f, -180.0781f, -120.7031f, -55.4688f, -18.3594f, + -6.2500f, -22.6563f, -30.0781f, -132.4219f, -208.5938f, 183.2031f, 155.8594f, 92.5781f, 113.2813f, 52.7344f, 13.2813f, 33.5938f, -5.4688f, -30.0781f, -11.7188f, 3.9063f, + 5.0781f, -1.5625f, 251.5625f, 223.4375f, 160.9375f, 171.0938f, 106.2500f, 111.7188f, 91.4063f, 69.1406f, 46.0938f, 57.4219f, 51.1719f, 53.9063f, 49.6094f, 14.8438f, + -28.5156f, -34.3750f, -43.7500f, 16.4063f, 14.0625f, 55.0781f, 165.6250f, 150.7813f, 196.8750f, 225.0000f, 204.2969f, 188.6719f, 168.3594f, 128.1250f, 91.0156f, 23.0469f, + -46.8750f, -66.0156f, -105.4688f, -173.8281f, -231.6406f, -104.6875f, -51.9531f, -53.9063f, -4.2969f, 21.8750f, 51.9531f, 82.0313f, 64.8438f, 45.3125f, 47.6563f, 53.5156f, + 110.1563f, 144.5313f, 99.6094f, 29.6875f, -34.7656f, -74.6094f, 54.2969f, 31.2500f, 4.6875f, 68.7500f, 72.2656f, 56.6406f, 95.3125f, 98.8281f, 67.5781f, -7.0313f, + 5.0781f, 5.4688f, -16.7969f, 28.5156f, -23.0469f, -105.4688f, -175.0000f, -242.9688f, -23.0469f, 146.0938f, 137.8906f, 114.4531f, 73.8281f, -21.0938f, -77.7344f, -47.6563f, + -29.2969f, -41.4063f, -109.7656f, -121.8750f, 228.5156f, 158.2031f, 72.2656f, 24.2188f, -68.7500f, -124.6094f, -128.9063f, -156.2500f, -163.2813f, -63.2813f, -1.5625f, 30.4688f, + -12.1094f, -4.2969f, -30.8594f, -32.4219f, -34.3750f, -107.0313f, -133.9844f, -168.3594f, -243.3594f, -202.3438f, -57.8125f, -4.2969f, -6.6406f, -8.2031f, 8.2031f, 35.1563f, + -39.4531f, -67.5781f, -93.7500f, 173.4375f, 118.3594f, 47.2656f, 40.6250f, -14.4531f, 72.2656f, 52.3438f, -17.5781f, -53.1250f, -64.0625f, 1.5625f, 59.7656f, 44.5313f, + -3.1250f, 15.6250f, 41.7969f, -29.6875f, -99.2188f, -215.2344f, -262.8906f, 112.5000f, 124.2188f, 9.7656f, 5.4688f, -24.2188f, -37.8906f, -0.7813f, 5.0781f, -7.8125f, + 33.9844f, 49.6094f, 31.2500f, 84.3750f, 131.2500f, 57.4219f, 73.4375f, 64.4531f, -3.9063f, 48.8281f, 75.3906f, 33.9844f, -49.2188f, -154.6875f, -287.5000f, -261.3281f, + 0.7813f, 1.5625f, 37.5000f, 72.2656f, 2.3438f, 24.2188f, -14.4531f, -53.1250f, -69.1406f, -97.6563f, -88.6719f, 78.5156f, 290.6250f, 254.2969f, 137.1094f, 28.9063f, + -6.2500f, -15.2344f, -32.0313f, -69.1406f, -148.4375f, -71.4844f, -9.3750f, -42.5781f, -75.7813f, -158.9844f, -250.3906f, -240.2344f, -61.3281f, 57.0313f, 74.6094f, 65.2344f, + -8.2031f, -4.6875f, -15.2344f, -24.6094f, -62.1094f, -50.0000f, 7.8125f, 2.3438f, 6.2500f, 15.2344f, -23.4375f, -94.9219f, -232.0313f, -286.3281f, -142.1875f, 17.9688f +}; +/* An 16-by-32 matrix */ +const float GEWB_MA1[512] = +{ + 105.0781f, 104.6875f, 162.5000f, 112.1094f, 61.3281f, 2.7344f, -51.5625f, -107.8125f, -188.2813f, -273.8281f, -400.3906f, -527.3438f, -641.4063f, -383.5938f, -125.3906f, -19.1406f, + 92.5781f, 370.7031f, 536.7188f, 479.6875f, 522.2656f, 476.1719f, 438.6719f, 396.8750f, 332.8125f, 293.7500f, 259.3750f, 218.3594f, 175.0000f, 119.5313f, 75.7813f, 32.4219f, + -2.3438f, -68.7500f, -145.7031f, -43.3594f, -86.3281f, -151.1719f, -188.6719f, -249.6094f, -294.1406f, -307.0313f, -302.3438f, -255.8594f, -128.1250f, -44.5313f, -9.7656f, 10.5469f, + 52.7344f, 64.0625f, -1.5625f, -70.7031f, -142.1875f, -206.2500f, -181.2500f, -165.6250f, -153.5156f, -122.6563f, -94.5313f, -72.2656f, -40.6250f, -23.8281f, -12.5000f, -14.4531f, + 5.8594f, -85.1563f, -125.7813f, 260.9375f, 233.2031f, 133.9844f, 76.5625f, -1.9531f, -17.9688f, -62.1094f, -140.2344f, -204.6875f, -245.7031f, -214.0625f, -120.3125f, -37.1094f, + 94.5313f, 180.8594f, 299.6094f, 258.2031f, 217.9688f, 157.4219f, 104.6875f, 74.6094f, 27.7344f, -1.5625f, -19.9219f, -40.2344f, -55.0781f, -68.7500f, -62.8906f, -55.4688f, + -69.9219f, -57.4219f, 279.2969f, 337.8906f, 378.9063f, 364.0625f, 321.0938f, 298.0469f, 235.1563f, 200.7813f, 170.3125f, 144.5313f, 111.3281f, 73.8281f, 41.4063f, 14.0625f, + -19.1406f, -88.6719f, -230.0781f, -364.4531f, -457.8125f, -273.4375f, -96.8750f, -68.3594f, -51.5625f, -51.5625f, -48.8281f, -40.2344f, -18.3594f, -19.1406f, -4.6875f, 23.4375f, + -2.7344f, -88.6719f, -157.8125f, 106.2500f, 32.4219f, -19.5313f, -64.4531f, -124.6094f, -133.9844f, -195.7031f, -285.5469f, -366.7969f, -395.7031f, -237.1094f, -78.9063f, -0.7813f, + -29.6875f, -105.8594f, -258.2031f, -227.3438f, 115.6250f, 33.5938f, -23.4375f, -64.8438f, -130.8594f, -122.6563f, -83.2031f, -111.3281f, -126.5625f, -109.3750f, -64.0625f, -15.2344f, + -103.1250f, -176.5625f, -43.3594f, 66.7969f, 89.4531f, 139.4531f, 138.6719f, 180.0781f, 198.8281f, 201.9531f, 191.0156f, 172.2656f, 135.5469f, 96.0938f, 61.7188f, 29.2969f, + 26.1719f, -19.1406f, -132.8125f, -213.2813f, -296.0938f, -358.9844f, -342.1875f, -283.9844f, -257.0313f, -221.4844f, -192.1875f, -156.2500f, -91.4063f, -54.6875f, -24.6094f, 14.0625f, + -55.4688f, 36.7188f, 200.7813f, 156.2500f, 158.5938f, 151.9531f, 148.0469f, 161.3281f, 152.7344f, 147.2656f, 138.2813f, 122.6563f, 95.7031f, 60.9375f, 36.7188f, 13.2813f, + 37.8906f, -18.3594f, -123.4375f, -242.1875f, -341.4063f, -69.9219f, -80.4688f, -113.2813f, -118.7500f, -200.7813f, -269.5313f, -282.4219f, -196.4844f, -98.4375f, -28.5156f, 15.2344f, + 189.4531f, 263.2813f, 207.8125f, 76.1719f, 14.8438f, -23.4375f, 6.6406f, 20.3125f, 24.6094f, 28.9063f, 33.2031f, 24.2188f, 13.6719f, -3.9063f, -8.5938f, -19.9219f, + -41.0156f, -8.9844f, 112.1094f, 153.9063f, 183.2031f, 237.8906f, 275.7813f, 335.9375f, 364.4531f, 364.4531f, 341.4063f, 308.2031f, 249.2188f, 181.6406f, 116.0156f, 57.8125f, + -87.1094f, -194.9219f, -326.9531f, -317.5781f, -152.7344f, -90.2344f, -69.5313f, -71.0938f, -31.6406f, 0.7813f, 32.8125f, 44.1406f, 51.1719f, 55.4688f, 49.6094f, 41.7969f, + -25.0000f, 105.0781f, 343.3594f, 331.6406f, 395.7031f, 451.9531f, 488.2813f, 522.2656f, 493.3594f, 459.3750f, 409.3750f, 351.5625f, 274.6094f, 196.0938f, 124.2188f, 64.4531f, + 23.8281f, 0.3906f, -77.3438f, -81.6406f, -134.7656f, -162.8906f, -109.3750f, -109.3750f, -119.9219f, -106.2500f, -133.2031f, -163.2813f, -235.9375f, -288.2813f, -346.4844f, -153.9063f, + 17.5781f, 30.0781f, 48.4375f, 59.3750f, 38.6719f, 16.7969f, 7.8125f, -1.5625f, -35.5469f, -33.2031f, -75.0000f, -109.3750f, -212.5000f, -294.5313f, -459.3750f, -506.2500f, + 67.5781f, 26.9531f, -19.1406f, -88.2813f, -134.3750f, -187.1094f, -191.0156f, -241.4063f, -283.9844f, -355.0781f, -438.2813f, -564.8438f, -504.6875f, -192.1875f, -80.0781f, 3.9063f, + -31.2500f, -31.2500f, 132.0313f, 111.3281f, 48.0469f, 18.7500f, -29.6875f, -31.2500f, -41.0156f, -46.0938f, -42.1875f, -31.2500f, -22.6563f, -10.9375f, -3.5156f, -3.1250f, + 28.9063f, -30.8594f, -114.0625f, -241.4063f, -295.3125f, 134.7656f, 84.3750f, 70.3125f, 55.8594f, -28.5156f, -72.6563f, -87.1094f, -78.1250f, -55.8594f, -20.3125f, -8.2031f, + -98.8281f, -202.7344f, -225.7813f, -73.4375f, -37.5000f, -13.6719f, -2.7344f, 10.5469f, 51.9531f, 85.1563f, 100.7813f, 100.7813f, 90.2344f, 70.3125f, 46.8750f, 27.3438f, + 106.6406f, 289.0625f, 371.0938f, 287.5000f, 273.8281f, 248.0469f, 238.6719f, 235.1563f, 221.0938f, 208.2031f, 192.9688f, 174.6094f, 136.7188f, 89.8438f, 51.1719f, 16.4063f, + -39.0625f, -134.7656f, -274.2188f, -137.5000f, 276.9531f, 266.4063f, 189.4531f, 126.5625f, 62.8906f, 43.7500f, 57.8125f, 9.7656f, -34.3750f, -41.4063f, -33.5938f, -39.4531f, + 119.9219f, 103.5156f, 98.8281f, 25.3906f, -24.6094f, -29.2969f, -66.0156f, -110.1563f, -152.3438f, -195.7031f, -214.8438f, -207.8125f, -158.5938f, -115.6250f, -72.6563f, -51.5625f, + -10.1563f, 27.3438f, 19.5313f, -32.8125f, -34.7656f, 10.9375f, 41.4063f, 77.7344f, 119.1406f, 152.7344f, 175.7813f, 183.2031f, 163.6719f, 117.5781f, 74.6094f, 31.2500f, + 8.5938f, 15.2344f, -60.1563f, -166.4063f, -233.2031f, -194.1406f, -62.1094f, -26.9531f, 16.0156f, 37.1094f, 44.5313f, 44.5313f, 38.6719f, 12.8906f, -2.7344f, -15.6250f, + -63.2813f, -139.0625f, -199.6094f, -180.0781f, -185.5469f, -200.3906f, -186.3281f, -189.4531f, -154.2969f, -97.2656f, -53.1250f, -27.7344f, -1.5625f, 12.8906f, 21.0938f, 25.0000f, + -32.0313f, -115.2344f, -219.5313f, 94.1406f, 25.3906f, -63.6719f, -88.6719f, -150.0000f, -92.5781f, -89.4531f, -103.9063f, -87.1094f, -36.7188f, 3.9063f, 16.0156f, 12.1094f, + -40.6250f, -126.1719f, -117.9688f, 286.3281f, 252.3438f, 163.2813f, 105.8594f, 58.2031f, 60.5469f, 60.1563f, 46.4844f, 38.6719f, 34.7656f, 24.6094f, 5.0781f, -6.2500f +}; +/* An 16-by-32 matrix */ +const float GETRNB_SN1[512] = +{ + -46.4844f, -105.8594f, -166.7969f, 174.6094f, 125.3906f, 22.6563f, 14.4531f, -41.0156f, -25.3906f, 38.6719f, 41.4063f, 8.2031f, -108.2031f, 20.7031f, 3.5156f, -2.3438f, + -36.3281f, -94.1406f, -169.1406f, -322.6563f, -401.5625f, 6.6406f, 70.3125f, 53.9063f, 125.0000f, 91.4063f, 59.3750f, 91.7969f, 380.0781f, 232.0313f, 77.7344f, 37.5000f, + -117.1875f, -185.1563f, -216.0156f, -194.1406f, -146.0938f, -90.2344f, -87.5000f, -66.4063f, -56.6406f, 19.9219f, 60.1563f, 278.9063f, 522.6563f, 269.5313f, 105.8594f, 46.0938f, + -44.9219f, -89.0625f, -96.8750f, 3.5156f, -10.5469f, -76.5625f, -93.7500f, -105.0781f, -114.4531f, -121.0938f, -107.8125f, -99.2188f, 300.3906f, 187.8906f, 45.7031f, 23.0469f, + 67.1875f, 22.6563f, 183.2031f, 228.5156f, 200.0000f, 131.2500f, 56.6406f, -20.3125f, -65.2344f, -134.3750f, -148.0469f, -190.2344f, 111.3281f, 147.2656f, 10.5469f, 10.5469f, + 31.6406f, 13.2813f, 224.2188f, 335.5469f, 319.5313f, 274.2188f, 203.5156f, 134.3750f, 69.1406f, 8.9844f, -45.3125f, -107.0313f, -238.6719f, -30.4688f, -23.8281f, -13.6719f, + 29.6875f, 7.4219f, -40.6250f, -151.5625f, -268.3594f, 21.0938f, 108.9844f, 56.2500f, 92.5781f, 87.1094f, 42.9688f, 3.5156f, -130.8594f, 1.5625f, 1.1719f, -3.9063f, + 44.9219f, 148.4375f, 189.8438f, 174.2188f, 151.9531f, 123.4375f, 93.3594f, 97.2656f, 76.9531f, 80.8594f, 63.2813f, 55.0781f, -169.9219f, -592.1875f, -159.7656f, -53.1250f, + -57.0313f, -135.9375f, -166.0156f, 251.9531f, 389.8438f, 308.5938f, 237.8906f, 182.8125f, 110.1563f, 112.1094f, 59.7656f, 33.9844f, -180.0781f, -231.2500f, -34.3750f, -25.0000f, + -97.2656f, -183.9844f, -326.1719f, -250.7813f, 230.0781f, 375.0000f, 346.4844f, 248.8281f, 172.6563f, 111.7188f, 94.5313f, 51.5625f, 55.4688f, 116.7969f, 38.6719f, 17.1875f, + 50.0000f, 14.4531f, -46.8750f, -122.6563f, -223.0469f, -285.1563f, -339.0625f, -217.9688f, -101.1719f, -42.5781f, 3.1250f, 161.3281f, 447.2656f, 231.6406f, 82.0313f, 35.9375f, + 58.9844f, 129.2969f, 104.2969f, 50.7813f, -9.3750f, -34.7656f, -51.9531f, -16.7969f, -29.2969f, 22.2656f, 7.4219f, 36.7188f, -183.2031f, -310.9375f, -48.4375f, -35.1563f, + -132.4219f, -182.8125f, -114.0625f, -13.2813f, 29.6875f, 69.9219f, 90.2344f, 105.0781f, 101.1719f, 109.7656f, 107.4219f, 79.6875f, -36.3281f, 61.3281f, 20.7031f, 6.2500f, + 12.8906f, 68.7500f, 9.7656f, -78.5156f, -121.4844f, -194.1406f, -198.8281f, -94.5313f, -18.3594f, 2.3438f, 33.5938f, 18.7500f, -64.4531f, 68.7500f, 9.3750f, 3.1250f, + 10.5469f, 87.1094f, 180.0781f, 195.3125f, 187.1094f, 185.5469f, 191.0156f, 218.7500f, 248.0469f, 289.4531f, 360.9375f, 526.1719f, 603.9063f, 314.8438f, 108.2031f, 21.0938f, + 199.2188f, 181.2500f, 157.0313f, 44.5313f, -31.2500f, -111.3281f, -113.2813f, -125.3906f, -110.5469f, -143.7500f, -126.9531f, -165.6250f, 151.5625f, 157.0313f, 20.3125f, 14.8438f, + 203.5156f, 239.8438f, 285.9375f, 214.4531f, 167.1875f, 108.5938f, 70.3125f, 31.6406f, 5.4688f, -42.9688f, -79.6875f, -138.6719f, -253.5156f, -12.5000f, -21.8750f, -14.0625f, + 28.1250f, 10.1563f, 102.3438f, 102.7344f, 62.1094f, 44.1406f, 23.4375f, -3.9063f, -28.5156f, -47.2656f, -78.5156f, -128.5156f, -300.0000f, -23.8281f, -23.4375f, -15.2344f, + 33.2031f, 22.2656f, 45.3125f, -15.6250f, -30.4688f, -62.1094f, -60.1563f, -96.4844f, -85.9375f, -142.9688f, -129.2969f, -207.8125f, -13.6719f, 134.3750f, 0.0000f, 9.7656f, + 205.8594f, 358.9844f, 523.0469f, 478.5156f, 464.8438f, 399.6094f, 302.3438f, 225.3906f, 153.5156f, 62.5000f, -1.5625f, -71.8750f, -109.7656f, 11.3281f, -8.2031f, -4.6875f, + -89.8438f, -110.5469f, -132.0313f, -148.0469f, -122.2656f, -114.4531f, -63.6719f, -47.6563f, 5.8594f, 37.8906f, 94.9219f, 65.6250f, 141.0156f, 175.3906f, 39.8438f, 23.8281f, + 147.6563f, 144.1406f, 144.1406f, 53.1250f, 16.4063f, -28.1250f, -28.5156f, -60.1563f, -60.5469f, -101.5625f, -105.4688f, -173.4375f, -219.5313f, 67.5781f, -14.0625f, -3.5156f, + 65.6250f, 42.1875f, -14.0625f, -135.5469f, -218.3594f, -170.3125f, -99.2188f, -102.7344f, -92.1875f, -88.6719f, -96.4844f, -92.9688f, 310.9375f, 190.6250f, 48.0469f, 24.2188f, + -58.9844f, -46.0938f, 63.6719f, 176.5625f, 167.9688f, 189.0625f, 178.1250f, 163.2813f, 147.2656f, 141.7969f, 100.0000f, 71.4844f, -157.4219f, -558.2031f, -149.2188f, -49.2188f, + -79.6875f, -142.9688f, -254.6875f, -200.0000f, 167.1875f, 137.8906f, 71.0938f, 34.3750f, -3.9063f, -36.7188f, -21.0938f, -4.2969f, 312.8906f, 205.8594f, 58.9844f, 29.6875f, + 23.4375f, 30.8594f, -66.0156f, -181.6406f, -308.2031f, -329.6875f, -21.4844f, 70.7031f, 81.6406f, 67.1875f, 82.0313f, 41.7969f, 101.5625f, 155.8594f, 35.5469f, 20.3125f, + -26.9531f, -80.0781f, -147.2656f, -64.0625f, 252.7344f, 228.1250f, 117.9688f, 58.9844f, 12.5000f, -52.7344f, -53.1250f, -87.1094f, -105.0781f, 66.4063f, 1.5625f, 1.9531f, + 14.8438f, 163.2813f, 345.7031f, 382.4219f, 386.7188f, 401.1719f, 339.8438f, 314.0625f, 261.3281f, 209.7656f, 140.6250f, 94.1406f, -131.2500f, -500.3906f, -132.0313f, -43.3594f, + -164.0625f, -273.4375f, -356.2500f, -242.9688f, -131.6406f, -19.9219f, 26.1719f, 67.5781f, 127.3438f, 216.4063f, 299.2188f, 544.9219f, 646.8750f, 349.2188f, 152.3438f, 69.5313f, + -55.0781f, -98.4375f, -198.0469f, -321.0938f, -423.4375f, -330.0781f, -109.3750f, 7.8125f, 58.2031f, 94.5313f, 153.5156f, 371.4844f, 557.8125f, 289.0625f, 118.3594f, 52.7344f, + -46.8750f, -14.4531f, 12.1094f, 41.0156f, 28.1250f, 38.6719f, 20.7031f, 45.7031f, 23.0469f, 66.7969f, 46.8750f, 69.1406f, -161.7188f, -387.8906f, -62.5000f, -38.2813f, + -149.2188f, -239.0625f, -246.4844f, -65.2344f, 1.5625f, 40.6250f, 50.7813f, 55.0781f, 94.5313f, 126.9531f, 135.9375f, 167.9688f, 409.3750f, 254.2969f, 86.7188f, 42.5781f +}; +/* An 16-by-16 matrix */ +const float GETRNB_SN2[256] = +{ + -10.5469f, 27.7344f, 17.5781f, -1.5625f, 10.9375f, 26.9531f, 9.7656f, 36.7188f, 17.5781f, 35.1563f, 17.5781f, 33.9844f, -69.1406f, -221.4844f, -45.3125f, -23.0469f, + -81.2500f, -57.4219f, 207.4219f, 155.8594f, 77.7344f, 44.1406f, -8.2031f, -10.9375f, -13.2813f, -14.8438f, -18.7500f, -17.9688f, -18.3594f, 7.0313f, -0.3906f, -0.3906f, + 26.9531f, -7.8125f, -44.9219f, -138.6719f, -148.4375f, 151.5625f, 148.0469f, 75.3906f, 52.3438f, 14.4531f, -16.4063f, -23.4375f, -13.6719f, 11.3281f, 2.3438f, 1.9531f, + 41.7969f, 34.7656f, -38.2813f, -73.8281f, 148.0469f, 112.8906f, 26.5625f, 8.5938f, -27.7344f, -69.9219f, -73.0469f, -75.0000f, -53.5156f, 1.5625f, -6.6406f, -2.7344f, + -17.1875f, -31.6406f, -144.9219f, -175.0000f, 88.2813f, 29.2969f, -20.3125f, 16.7969f, 15.6250f, 14.0625f, 30.8594f, 46.8750f, 50.7813f, 29.6875f, 14.0625f, 5.8594f, + 51.1719f, 44.9219f, 75.0000f, 69.1406f, 9.7656f, -2.7344f, -8.9844f, -37.1094f, -51.5625f, -71.8750f, -80.4688f, -95.7031f, -78.1250f, -4.6875f, -11.3281f, -4.2969f, + 17.5781f, -9.7656f, -97.2656f, 19.5313f, -73.8281f, -139.8438f, 98.8281f, 56.6406f, -15.2344f, 10.5469f, 13.2813f, -7.8125f, -20.3125f, 5.0781f, 0.3906f, 0.7813f, + -99.2188f, -60.5469f, 8.9844f, -34.7656f, -11.7188f, 8.9844f, -8.9844f, -8.2031f, -17.5781f, -33.5938f, -35.9375f, -42.5781f, -18.7500f, 20.3125f, 1.1719f, 1.1719f, + -96.8750f, -91.0156f, 54.2969f, 83.2031f, 90.6250f, 141.0156f, 136.3281f, 156.6406f, 145.7031f, 117.5781f, 89.8438f, 80.8594f, 79.6875f, 39.4531f, 12.5000f, 5.4688f, + 191.7969f, 213.2813f, 159.7656f, 57.4219f, 13.2813f, -7.0313f, 20.3125f, 23.0469f, 18.7500f, 10.5469f, 5.4688f, 2.7344f, -0.3906f, -14.4531f, -6.2500f, -3.5156f, + 14.0625f, 16.0156f, 0.0000f, -8.2031f, -11.3281f, -25.0000f, -80.8594f, -135.1563f, -201.5625f, -138.6719f, -25.0000f, 28.5156f, 60.9375f, 36.7188f, 11.7188f, 4.2969f, + -10.9375f, -67.5781f, -108.5938f, 197.6563f, 166.7969f, 64.0625f, 43.3594f, 8.2031f, -12.8906f, -23.8281f, -30.4688f, -35.1563f, -12.5000f, 15.2344f, 1.5625f, 1.5625f, + -17.1875f, -23.4375f, -83.9844f, -145.7031f, -189.4531f, -105.4688f, 4.6875f, 58.9844f, 105.8594f, 103.5156f, 83.9844f, 69.5313f, 59.7656f, 27.7344f, 12.5000f, 6.6406f, + 42.9688f, 60.5469f, -11.3281f, -101.1719f, -85.1563f, -71.4844f, -68.3594f, -51.5625f, -33.2031f, -38.2813f, -33.9844f, -36.3281f, -30.0781f, 0.0000f, -3.5156f, -1.5625f, + -45.3125f, -5.4688f, 91.7969f, 0.3906f, -92.9688f, -155.4688f, -163.6719f, -21.4844f, 42.5781f, 30.0781f, 24.2188f, 28.9063f, 28.5156f, 18.3594f, 6.2500f, 3.1250f, + -7.8125f, -42.1875f, -85.5469f, 96.0938f, 7.8125f, -71.8750f, -128.1250f, -175.3906f, -26.1719f, 55.4688f, 48.8281f, 42.9688f, 35.5469f, 28.9063f, 10.9375f, 5.0781f +}; +/* An 16-by-32 matrix */ +const float GETRWB_SN1[512] = +{ + -90.6250f, -74.6094f, 110.1563f, 96.8750f, 134.3750f, 152.3438f, 167.1875f, 191.4063f, 210.1563f, 231.2500f, 242.1875f, 237.1094f, 208.2031f, 145.3125f, 101.9531f, 53.1250f, + -23.0469f, -88.6719f, -163.2813f, -112.5000f, -96.4844f, -175.0000f, -195.7031f, -251.5625f, -296.8750f, -360.1563f, -434.3750f, -470.3125f, -204.2969f, -50.7813f, 4.6875f, 51.1719f, + 54.2969f, 327.3438f, 547.6563f, 518.3594f, 572.2656f, 543.3594f, 535.5469f, 524.2188f, 476.5625f, 448.0469f, 406.6406f, 355.4688f, 286.3281f, 202.3438f, 130.8594f, 70.7031f, + 82.4219f, 57.8125f, -36.7188f, -107.4219f, -189.0625f, -228.9063f, -211.3281f, -247.6563f, -227.7344f, -199.6094f, -165.6250f, -125.7813f, -111.3281f, -116.7969f, -75.7813f, -33.9844f, + 160.1563f, 141.4063f, 131.6406f, 28.5156f, -14.0625f, -44.1406f, -70.3125f, -107.0313f, -145.7031f, -192.5781f, -195.7031f, -184.7656f, -153.5156f, -141.0156f, -105.8594f, -98.0469f, + -33.2031f, -142.9688f, -319.9219f, -207.8125f, 294.1406f, 268.7500f, 161.7188f, 79.2969f, 9.3750f, -16.7969f, 50.3906f, 23.4375f, -39.0625f, -48.0469f, -37.8906f, -44.5313f, + 1.5625f, 14.4531f, 189.0625f, 200.7813f, 132.8125f, 87.8906f, 34.7656f, 23.0469f, 15.6250f, 1.1719f, -1.9531f, -0.3906f, -4.2969f, -19.1406f, -16.7969f, -18.7500f, + -87.1094f, -183.9844f, -258.2031f, -221.4844f, -193.7500f, -202.7344f, -181.2500f, -211.7188f, -189.0625f, -133.9844f, -107.8125f, -72.2656f, -16.7969f, 6.6406f, 32.8125f, 51.9531f, + -41.4063f, -121.8750f, -260.9375f, -289.4531f, 150.3906f, 128.5156f, 47.2656f, -61.3281f, -165.2344f, -277.3438f, -373.8281f, -500.0000f, -446.4844f, -128.9063f, -7.8125f, 51.1719f, + 97.6563f, 61.3281f, 27.7344f, -121.0938f, -215.6250f, -289.0625f, -291.0156f, -303.9063f, -323.0469f, -415.6250f, -521.8750f, -636.3281f, -307.8125f, -76.1719f, -17.1875f, 51.1719f, + 54.6875f, 247.2656f, 378.9063f, 337.5000f, 338.6719f, 297.2656f, 266.7969f, 253.1250f, 223.4375f, 212.5000f, 201.5625f, 183.2031f, 149.6094f, 92.9688f, 55.8594f, 21.4844f, + 45.3125f, 55.8594f, 89.4531f, 52.3438f, -9.7656f, -46.8750f, -90.6250f, -130.0781f, -208.9844f, -250.7813f, -384.7656f, -491.7969f, -731.6406f, -674.6094f, -128.9063f, -3.9063f, + -25.0000f, -32.0313f, -24.2188f, -90.6250f, -120.3125f, -135.1563f, -115.6250f, -106.2500f, -59.7656f, -10.1563f, 42.1875f, 80.0781f, 90.6250f, 61.7188f, 50.3906f, 20.7031f, + 32.0313f, -35.9375f, -120.7031f, -308.9844f, -440.6250f, -101.1719f, -94.9219f, -158.2031f, -143.3594f, -248.8281f, -352.7344f, -423.4375f, -263.6719f, -77.7344f, 6.6406f, 57.0313f, + -96.4844f, -222.2656f, -346.0938f, -296.0938f, -130.4688f, -80.4688f, -61.7188f, -58.5938f, -25.0000f, 22.2656f, 74.2188f, 98.4375f, 101.9531f, 82.0313f, 63.6719f, 50.3906f, + -8.9844f, -124.6094f, -178.9063f, 308.9844f, 280.4688f, 156.2500f, 91.0156f, -31.6406f, -67.9688f, -156.2500f, -296.0938f, -409.3750f, -522.6563f, -405.4688f, -112.5000f, -2.3438f, + 19.5313f, 180.4688f, 118.3594f, -18.3594f, -47.6563f, -52.3438f, 5.8594f, 53.5156f, 69.9219f, 86.7188f, 103.9063f, 97.2656f, 85.5469f, 48.0469f, 31.2500f, 11.7188f, + -45.3125f, -129.6875f, -253.9063f, -431.2500f, -533.9844f, -269.9219f, -146.8750f, -115.2344f, -69.5313f, -77.7344f, -66.4063f, -9.3750f, 48.8281f, 37.1094f, 48.8281f, 65.6250f, + -25.7813f, -122.6563f, -205.4688f, 126.9531f, 60.9375f, -21.8750f, -44.5313f, -112.1094f, -49.2188f, -72.2656f, -114.0625f, -116.4063f, -73.8281f, -31.6406f, 0.3906f, 8.9844f, + 57.4219f, -11.7188f, -113.6719f, -301.1719f, -366.7969f, 102.3438f, 71.0938f, 49.2188f, 49.6094f, -39.0625f, -63.6719f, -52.3438f, -35.5469f, -37.1094f, -20.3125f, -7.4219f, + -87.8906f, -193.7500f, -175.3906f, -23.8281f, 17.9688f, 52.7344f, 71.0938f, 96.4844f, 126.5625f, 157.8125f, 178.5156f, 181.2500f, 164.0625f, 119.1406f, 81.6406f, 41.4063f, + 163.2813f, 121.8750f, 162.1094f, 28.9063f, -60.9375f, -134.7656f, -156.2500f, -247.6563f, -300.3906f, -412.8906f, -532.0313f, -719.1406f, -721.8750f, -183.9844f, -57.4219f, 33.9844f, + 14.8438f, 7.4219f, -90.6250f, -215.6250f, -272.6563f, -367.5781f, -188.6719f, 46.4844f, 21.0938f, -13.2813f, 27.3438f, -26.5625f, -56.2500f, -75.0000f, -98.8281f, -92.1875f, + 31.2500f, -11.7188f, -83.5938f, -61.3281f, -114.0625f, -121.8750f, -110.5469f, -135.5469f, -150.0000f, -145.3125f, -190.2344f, -196.4844f, -291.4063f, -371.0938f, -535.9375f, -251.5625f, + 17.1875f, 21.4844f, 48.4375f, 70.7031f, 48.8281f, 42.5781f, 23.8281f, 11.3281f, -28.5156f, -21.0938f, -80.4688f, -108.5938f, -249.2188f, -362.8906f, -610.5469f, -680.4688f, + 313.2813f, 321.4844f, 283.5938f, 137.8906f, 106.2500f, 47.6563f, 45.7031f, 36.7188f, 31.2500f, 15.6250f, 26.5625f, 18.3594f, 16.4063f, -7.4219f, -10.1563f, -26.9531f, + 19.5313f, -37.8906f, -119.5313f, -260.1563f, -358.5938f, -433.2031f, -439.0625f, -303.1250f, -277.3438f, -284.3750f, -263.6719f, -189.8438f, -58.5938f, -1.1719f, 36.3281f, 62.5000f, + 31.6406f, -56.2500f, -51.1719f, 124.6094f, 88.6719f, -37.5000f, -92.1875f, -201.9531f, -277.7344f, -370.7031f, -480.8594f, -642.1875f, -634.7656f, -173.4375f, -45.7031f, 33.5938f, + -89.8438f, -92.5781f, 228.9063f, 312.1094f, 363.6719f, 399.6094f, 420.7031f, 460.5469f, 442.5781f, 430.0781f, 401.1719f, 355.0781f, 285.5469f, 201.1719f, 128.9063f, 66.7969f, + 175.0000f, 246.8750f, 408.9844f, 305.4688f, 246.4844f, 152.3438f, 60.5469f, -32.0313f, -133.5938f, -267.5781f, -430.8594f, -593.7500f, -694.9219f, -363.6719f, -83.5938f, 13.2813f, + -30.0781f, -137.5000f, -137.8906f, 307.4219f, 366.4063f, 264.4531f, 200.3906f, 137.5000f, 110.9375f, 108.5938f, 96.4844f, 70.7031f, 55.0781f, 28.5156f, 3.1250f, -15.2344f, + 21.0938f, 16.4063f, -26.1719f, -116.4063f, -181.6406f, -231.6406f, -208.2031f, -213.6719f, -244.5313f, -289.4531f, -381.6406f, -514.4531f, -650.3906f, -239.4531f, -46.4844f, 31.2500f +}; +/* An 16-by-16 matrix */ +const float GETRWB_SN2[256] = +{ + -78.9063f, -96.0938f, -139.0625f, -139.0625f, -90.6250f, -64.0625f, -30.8594f, 1.5625f, 30.4688f, 50.7813f, 59.3750f, 64.4531f, 66.4063f, 55.0781f, 35.1563f, 27.3438f, + 14.8438f, 30.4688f, -28.1250f, -72.2656f, -174.2188f, -215.6250f, 105.0781f, 115.2344f, 40.6250f, 30.0781f, -21.0938f, -71.8750f, -65.6250f, -28.1250f, -12.5000f, -0.7813f, + 26.9531f, 36.3281f, 15.2344f, 45.3125f, 39.0625f, 17.9688f, 19.5313f, -0.3906f, -0.7813f, 24.2188f, 3.1250f, -41.0156f, -157.8125f, -256.2500f, -192.9688f, -87.5000f, + -111.3281f, -119.1406f, 102.7344f, 37.8906f, 11.3281f, 12.8906f, -9.3750f, 21.0938f, 13.6719f, 9.7656f, -1.5625f, -2.3438f, -11.7188f, 5.0781f, 7.8125f, 8.2031f, + -10.9375f, -27.3438f, -62.5000f, 13.2813f, 1.9531f, -56.6406f, -103.1250f, -166.0156f, -210.5469f, -128.5156f, -7.4219f, 89.0625f, 160.5469f, 109.3750f, 55.0781f, 19.9219f, + 95.3125f, 95.7031f, 7.4219f, -124.6094f, -180.0781f, -71.8750f, -3.9063f, 18.3594f, 85.9375f, 114.4531f, 120.7031f, 128.9063f, 109.7656f, 54.6875f, 27.7344f, 4.6875f, + -50.0000f, -98.0469f, -146.0938f, 165.6250f, 108.9844f, 26.5625f, 13.6719f, -26.5625f, 5.0781f, 17.5781f, -2.3438f, -16.0156f, -28.5156f, -6.6406f, 3.1250f, 10.5469f, + -21.4844f, -2.7344f, 171.0938f, 195.3125f, 192.5781f, 172.6563f, 111.7188f, 82.4219f, 26.5625f, -15.2344f, -45.7031f, -65.2344f, -70.3125f, -51.1719f, -29.2969f, -24.6094f, + 11.7188f, 12.1094f, 26.9531f, 44.5313f, -67.1875f, -158.9844f, -232.8125f, -152.7344f, 39.8438f, 66.0156f, 61.7188f, 51.1719f, 17.9688f, 1.5625f, -2.3438f, -1.1719f, + 26.9531f, 29.6875f, 12.8906f, 92.9688f, 64.0625f, 46.4844f, 62.5000f, 64.4531f, 106.6406f, 133.5938f, 149.6094f, 163.6719f, 178.1250f, 147.6563f, 102.3438f, 37.5000f, + -21.4844f, 16.7969f, -23.0469f, -106.6406f, -78.1250f, -111.7188f, -112.1094f, -86.3281f, -96.4844f, -95.7031f, -75.7813f, -62.5000f, -50.3906f, -14.0625f, -12.1094f, 1.1719f, + -13.6719f, -17.9688f, -106.2500f, -139.4531f, 189.0625f, 96.0938f, -4.2969f, 8.2031f, -48.0469f, -76.9531f, -39.8438f, -36.7188f, -37.5000f, -8.5938f, 2.3438f, 2.3438f, + -45.7031f, -73.4375f, -98.4375f, -88.6719f, 0.0000f, 179.6875f, 197.6563f, 205.4688f, 195.7031f, 151.9531f, 97.6563f, 51.1719f, -10.9375f, -12.5000f, 9.3750f, 6.6406f, + 155.8594f, 199.6094f, 152.3438f, 57.0313f, 31.2500f, -32.8125f, -31.6406f, -22.2656f, -48.0469f, -53.9063f, -37.1094f, -32.0313f, -19.9219f, -12.8906f, -5.4688f, -17.5781f, + -3.5156f, 4.6875f, 117.1875f, 118.7500f, 71.0938f, 10.5469f, -76.9531f, -100.7813f, -134.3750f, -153.5156f, -150.0000f, -124.2188f, -54.6875f, -1.9531f, -2.3438f, 2.3438f, + 25.0000f, 9.7656f, -2.7344f, -100.0000f, -119.5313f, 148.8281f, 94.9219f, 37.5000f, -6.6406f, -74.2188f, -111.3281f, -96.0938f, -25.3906f, 18.7500f, 14.4531f, 11.3281f +}; +/* An 16-by-16 matrix */ +const float TRWB2_SN1[256] = +{ + -28.9063f, -150.0000f, -298.4375f, -376.5625f, -438.2813f, -356.2500f, -319.9219f, -289.0625f, -284.3750f, -223.4375f, -148.0469f, -123.8281f, -97.6563f, -19.9219f, -26.1719f, 33.2031f, + -121.4844f, -241.4063f, -171.4844f, -42.1875f, 60.9375f, 100.3906f, 157.8125f, 212.1094f, 251.1719f, 284.7656f, 285.9375f, 223.4375f, 174.2188f, 128.5156f, 92.1875f, 64.0625f, + 204.2969f, 605.0781f, 608.2031f, 576.5625f, 536.7188f, 465.6250f, 417.1875f, 360.5469f, 351.9531f, 307.8125f, 280.0781f, 156.6406f, 102.3438f, 2.3438f, -39.0625f, -143.7500f, + -5.0781f, -31.2500f, -73.8281f, -150.7813f, -189.8438f, -139.4531f, -84.3750f, -24.6094f, 25.3906f, 73.8281f, 96.8750f, 75.7813f, 85.1563f, 85.5469f, 80.0781f, 66.0156f, + -40.6250f, -202.7344f, -301.5625f, 192.1875f, 87.5000f, 7.0313f, -79.2969f, -95.3125f, -49.2188f, -85.9375f, -141.4063f, -162.8906f, -105.8594f, -27.7344f, -13.2813f, -19.5313f, + -78.9063f, 48.4375f, 316.7969f, 380.8594f, 517.9688f, 573.4375f, 630.0781f, 596.4844f, 575.7813f, 533.5938f, 476.5625f, 353.9063f, 273.4375f, 198.8281f, 137.1094f, 80.8594f, + -22.2656f, -76.5625f, -92.9688f, -109.7656f, -104.2969f, -93.3594f, -74.2188f, -53.5156f, -10.5469f, 1.5625f, 30.0781f, -69.5313f, -100.0000f, -216.0156f, -261.3281f, -431.6406f, + -71.4844f, -82.4219f, 314.0625f, 308.2031f, 267.5781f, 206.6406f, 187.1094f, 157.4219f, 144.9219f, 122.2656f, 108.9844f, 19.1406f, -7.4219f, -60.9375f, -69.9219f, -130.8594f, + 296.0938f, 331.2500f, 237.5000f, 122.2656f, 105.8594f, 68.7500f, 69.1406f, 28.5156f, 41.4063f, 23.8281f, 23.0469f, -62.1094f, -79.2969f, -112.1094f, -104.6875f, -133.9844f, + 77.7344f, 27.3438f, 37.1094f, -11.3281f, -95.7031f, -160.5469f, -291.0156f, -394.1406f, -575.3906f, -750.3906f, -1028.5156f, -643.7500f, -209.7656f, -110.9375f, -33.9844f, 80.8594f, + 32.0313f, -84.7656f, -179.6875f, -252.3438f, -280.4688f, -320.7031f, -383.9844f, -500.7813f, -617.1875f, -823.4375f, -727.7344f, -237.8906f, -158.9844f, -47.6563f, -19.5313f, 94.9219f, + -51.5625f, 142.1875f, 142.1875f, 132.8125f, 191.0156f, 193.7500f, 232.8125f, 236.7188f, 275.0000f, 295.3125f, 303.5156f, 240.6250f, 203.5156f, 159.7656f, 119.1406f, 82.4219f, + 48.0469f, -73.8281f, -35.5469f, -119.5313f, -124.6094f, -158.9844f, -234.3750f, -265.2344f, -355.8594f, -333.9844f, -221.0938f, -97.2656f, -25.3906f, -0.3906f, -25.3906f, -9.7656f, + 30.8594f, -22.6563f, -40.2344f, -58.5938f, -104.6875f, -103.5156f, -166.4063f, -187.1094f, -239.8438f, -262.1094f, -392.5781f, -538.2813f, -791.7969f, -604.2969f, -221.8750f, -20.3125f, + -107.4219f, -261.3281f, -417.9688f, -428.5156f, -268.7500f, -169.1406f, -132.8125f, -57.8125f, -10.5469f, 75.7813f, 120.7031f, 108.2031f, 89.4531f, 73.4375f, 32.0313f, 49.6094f, + 155.0781f, 524.6094f, 578.9063f, 675.3906f, 772.6563f, 785.9375f, 769.1406f, 723.4375f, 675.3906f, 614.8438f, 549.6094f, 424.6094f, 331.2500f, 248.4375f, 168.3594f, 108.5938f +}; +/* An 16-by-16 matrix */ +const float TRWB2_SN2[256] = +{ + 19.5313f, -25.7813f, -189.8438f, -332.0313f, 196.8750f, 134.7656f, 101.9531f, 3.9063f, -80.8594f, -85.1563f, -67.9688f, -7.0313f, 28.1250f, 26.9531f, 1.1719f, 9.3750f, + -66.7969f, -171.4844f, -246.8750f, 152.3438f, 55.8594f, -34.7656f, -114.0625f, -122.6563f, -88.6719f, -61.3281f, 12.8906f, 70.7031f, 72.2656f, 79.6875f, 50.0000f, 65.2344f, + 178.9063f, 179.2969f, 30.4688f, -97.6563f, -142.5781f, -148.8281f, -137.8906f, -149.2188f, -127.7344f, -110.9375f, -74.6094f, -7.0313f, 1.1719f, 14.4531f, 11.3281f, 37.1094f, + -66.0156f, -88.6719f, -165.2344f, -175.0000f, -189.4531f, -166.4063f, -142.1875f, -110.9375f, -92.9688f, -71.8750f, -89.0625f, -74.2188f, -56.6406f, 6.6406f, 25.3906f, 56.6406f, + -1.5625f, -46.8750f, -66.4063f, -130.0781f, -264.4531f, -305.4688f, -280.8594f, -152.7344f, -43.7500f, 90.6250f, 181.2500f, 153.1250f, 107.4219f, 83.9844f, 47.2656f, 54.2969f, + -36.7188f, -50.7813f, 176.9531f, 115.2344f, -17.5781f, -111.7188f, -173.4375f, -184.7656f, -202.7344f, -167.1875f, -104.6875f, -15.6250f, -4.6875f, 17.9688f, 15.2344f, 46.0938f, + -73.8281f, -95.7031f, 314.4531f, 318.3594f, 202.3438f, 114.4531f, 63.2813f, 42.9688f, -26.1719f, -61.7188f, -87.1094f, -46.8750f, -14.0625f, 5.8594f, 10.1563f, 23.4375f, + 8.9844f, 50.7813f, 41.7969f, 0.0000f, -12.1094f, -25.7813f, 12.8906f, 8.5938f, 39.4531f, -3.9063f, -12.5000f, -90.6250f, -109.7656f, -230.4688f, -262.5000f, -425.3906f, + 19.9219f, 41.4063f, 61.3281f, 51.5625f, 15.6250f, 4.2969f, -28.5156f, -25.7813f, -64.4531f, -114.8438f, -219.1406f, -300.7813f, -289.8438f, -191.0156f, -78.9063f, 1.5625f, + 9.7656f, 89.8438f, 111.7188f, 69.9219f, 29.2969f, 7.0313f, 5.8594f, 9.3750f, 42.5781f, 73.0469f, 121.0938f, 130.4688f, 128.1250f, 113.6719f, 92.5781f, 82.8125f, + -92.9688f, -192.1875f, -214.8438f, 219.9219f, 298.4375f, 238.2813f, 211.7188f, 166.7969f, 145.7031f, 101.9531f, 64.8438f, 66.7969f, 47.6563f, 13.2813f, -8.2031f, -35.9375f, + -140.2344f, -180.4688f, -3.9063f, 8.5938f, -16.4063f, -0.7813f, 30.4688f, 65.2344f, 60.1563f, 60.5469f, 28.9063f, 28.5156f, 25.7813f, 36.7188f, 34.7656f, 49.2188f, + -1.9531f, -42.9688f, -146.0938f, -213.2813f, -150.7813f, -53.1250f, 37.1094f, 119.1406f, 170.7031f, 222.6563f, 240.2344f, 217.9688f, 180.8594f, 130.8594f, 81.6406f, 58.9844f, + 8.9844f, 146.8750f, 114.0625f, 91.7969f, 189.4531f, 202.7344f, 256.6406f, 214.4531f, 186.7188f, 132.0313f, 72.6563f, 2.7344f, -10.9375f, -60.5469f, -37.1094f, -73.4375f, + 64.8438f, 54.2969f, -108.2031f, -279.6875f, -321.0938f, 91.4063f, 124.6094f, 127.3438f, 91.4063f, 14.0625f, -60.5469f, -123.8281f, -96.4844f, -31.2500f, 19.1406f, 45.7031f, + 168.3594f, 333.2031f, 291.0156f, 200.0000f, 126.9531f, 54.2969f, 32.4219f, -12.1094f, -9.7656f, -18.3594f, -6.6406f, -4.6875f, -9.3750f, -16.7969f, -1.9531f, 5.0781f +}; +/* An 16-by-32 matrix */ +const float GEWB2_MA1[512] = +{ + 257.4219f, 661.7188f, 638.2813f, 591.0156f, 509.7656f, 428.9063f, 364.4531f, 314.4531f, 286.3281f, 243.7500f, 205.0781f, 132.4219f, 93.3594f, 19.5313f, -13.6719f, -83.9844f, + 2.3438f, 25.3906f, 48.8281f, 21.4844f, -33.2031f, -49.2188f, -106.2500f, -123.4375f, -198.0469f, -228.9063f, -394.5313f, -499.2188f, -758.2031f, -746.0938f, -166.4063f, 30.4688f, + 109.7656f, 123.0469f, 92.1875f, -1.5625f, -39.8438f, -66.7969f, -90.6250f, -130.8594f, -141.4063f, -166.0156f, -190.6250f, -235.5469f, -261.3281f, -287.5000f, -253.1250f, -231.6406f, + 11.3281f, -98.0469f, -227.3438f, -340.2344f, -378.5156f, -350.3906f, -387.1094f, -420.7031f, -498.0469f, -578.1250f, -389.8438f, -153.5156f, -96.4844f, -3.5156f, 10.9375f, 105.8594f, + -23.4375f, -141.0156f, 156.6406f, 215.6250f, 92.1875f, 13.6719f, -76.5625f, -83.9844f, -193.7500f, -266.7969f, -355.8594f, -320.3125f, -225.0000f, -116.7969f, -93.7500f, -55.0781f, + 162.5000f, 224.2188f, 258.5938f, 136.7188f, 51.9531f, -62.5000f, -168.3594f, -305.0781f, -468.7500f, -645.3125f, -794.9219f, -426.5625f, -175.3906f, -75.0000f, -4.2969f, 102.7344f, + -80.4688f, -237.8906f, -363.6719f, 10.9375f, -89.4531f, -139.8438f, -212.1094f, -180.4688f, -147.2656f, -140.6250f, -131.2500f, -98.0469f, -41.0156f, 13.6719f, 10.1563f, 31.2500f, + 144.1406f, 490.6250f, 539.0625f, 613.6719f, 674.2188f, 674.6094f, 642.1875f, 594.1406f, 527.3438f, 451.5625f, 384.3750f, 292.1875f, 226.5625f, 154.2969f, 99.2188f, 42.1875f, + -57.4219f, -187.1094f, -128.9063f, -28.5156f, -106.2500f, -172.2656f, -267.5781f, -326.9531f, -444.9219f, -569.5313f, -535.1563f, -161.7188f, -81.2500f, -4.6875f, 5.4688f, 83.2031f, + -19.5313f, 39.0625f, -32.0313f, -98.8281f, -2.7344f, 46.4844f, 114.8438f, 153.1250f, 192.9688f, 225.7813f, 230.0781f, 204.2969f, 180.4688f, 149.6094f, 117.1875f, 97.2656f, + -36.7188f, -141.4063f, -224.6094f, -300.7813f, -385.5469f, -390.2344f, -360.1563f, -272.2656f, -227.3438f, -119.1406f, -52.7344f, -12.1094f, -3.1250f, 8.9844f, -12.8906f, 24.2188f, + 11.3281f, -25.0000f, -1.5625f, -48.0469f, -134.3750f, -161.7188f, -265.2344f, -299.6094f, -450.0000f, -547.2656f, -822.2656f, -744.1406f, -227.3438f, -117.1875f, -25.0000f, 87.1094f, + 167.1875f, 386.7188f, 398.0469f, 316.0156f, 266.0156f, 183.5938f, 142.9688f, 69.9219f, 49.2188f, -10.1563f, -55.0781f, -141.7969f, -165.2344f, -209.3750f, -170.7031f, -212.8906f, + -51.9531f, -139.4531f, 142.1875f, 94.1406f, -15.2344f, -88.6719f, -130.4688f, -119.1406f, -166.4063f, -114.0625f, -39.8438f, 33.9844f, 62.1094f, 71.0938f, 62.5000f, 74.2188f, + 218.7500f, 298.4375f, 207.4219f, 60.9375f, 8.5938f, -7.0313f, 8.9844f, -7.8125f, 7.4219f, 0.0000f, 5.0781f, -23.8281f, -13.6719f, -17.1875f, -4.6875f, -18.7500f, + 12.8906f, -91.7969f, -247.6563f, -426.9531f, 53.1250f, -12.1094f, -26.5625f, -111.3281f, -206.6406f, -208.9844f, -180.4688f, -97.2656f, -37.1094f, -20.7031f, -45.3125f, -23.8281f, + -73.4375f, -245.3125f, -349.2188f, 274.2188f, 273.4375f, 145.7031f, 76.5625f, 19.9219f, 37.1094f, -21.8750f, -74.6094f, -70.7031f, -67.5781f, -51.5625f, -45.3125f, -85.1563f, + 14.4531f, -73.4375f, -258.2031f, -424.6094f, -516.4063f, -100.7813f, -72.6563f, -70.7031f, -92.9688f, -145.3125f, -163.2813f, -198.4375f, -169.1406f, -76.9531f, -28.5156f, 10.9375f, + -90.2344f, -86.7188f, 355.8594f, 341.7969f, 261.3281f, 171.8750f, 141.7969f, 117.5781f, 100.3906f, 75.0000f, 57.4219f, 26.5625f, 30.0781f, 16.7969f, 22.2656f, 6.6406f, + -1.5625f, -73.0469f, -139.0625f, -160.1563f, -222.2656f, -194.9219f, -228.1250f, -221.8750f, -257.8125f, -274.6094f, -376.9531f, -469.1406f, -601.5625f, -276.5625f, -98.4375f, 33.9844f, + 85.9375f, 25.0000f, -26.1719f, -139.4531f, -223.4375f, -290.6250f, -356.6406f, -459.3750f, -562.1094f, -739.8438f, -840.6250f, -297.6563f, -163.6719f, -57.0313f, -3.9063f, 109.7656f, + -98.8281f, -244.9219f, -419.9219f, -471.0938f, -281.6406f, -155.4688f, -131.6406f, -73.4375f, -46.0938f, 19.5313f, 48.8281f, 77.3438f, 78.1250f, 74.2188f, 37.5000f, 64.0625f, + -135.9375f, -289.4531f, -333.5938f, -139.4531f, -63.6719f, -40.2344f, -10.1563f, 55.8594f, 90.2344f, 124.2188f, 130.8594f, 126.9531f, 107.0313f, 91.0156f, 65.2344f, 74.2188f, + -55.8594f, -100.0000f, -74.6094f, -109.3750f, -97.6563f, -74.6094f, -32.0313f, 14.4531f, 49.2188f, 39.8438f, 26.1719f, -50.7813f, -78.9063f, -167.9688f, -193.3594f, -316.4063f, + 90.6250f, 41.7969f, -8.5938f, -133.2031f, -194.1406f, -204.2969f, -237.1094f, -252.3438f, -291.4063f, -269.5313f, -186.7188f, -115.2344f, -62.5000f, -30.0781f, -20.7031f, -2.7344f, + -12.8906f, -38.2813f, -100.7813f, -195.7031f, -230.0781f, -171.0938f, -123.4375f, -65.6250f, -22.6563f, 32.0313f, 68.3594f, 85.5469f, 97.2656f, 101.1719f, 92.5781f, 88.2813f, + -153.5156f, -259.7656f, -7.4219f, 72.2656f, 97.2656f, 103.9063f, 147.6563f, 182.8125f, 194.9219f, 198.4375f, 181.2500f, 151.5625f, 121.0938f, 92.9688f, 72.6563f, 56.6406f, + -93.7500f, -38.6719f, 159.3750f, 187.5000f, 270.7031f, 297.2656f, 369.5313f, 368.3594f, 371.4844f, 348.8281f, 305.4688f, 239.4531f, 188.2813f, 137.1094f, 101.5625f, 63.6719f, + -8.9844f, 204.2969f, 345.7031f, 352.7344f, 457.8125f, 502.7344f, 578.9063f, 582.4219f, 576.5625f, 547.6563f, 484.3750f, 392.5781f, 307.4219f, 235.9375f, 169.1406f, 114.0625f, + 102.3438f, 385.9375f, 353.1250f, 285.9375f, 286.7188f, 259.7656f, 279.2969f, 256.2500f, 262.8906f, 240.2344f, 211.3281f, 145.3125f, 110.9375f, 54.2969f, 26.5625f, -32.8125f, + -46.4844f, 174.2188f, 436.7188f, 474.6094f, 535.9375f, 500.0000f, 471.8750f, 386.3281f, 344.1406f, 263.6719f, 217.5781f, 124.6094f, 88.6719f, 8.9844f, -15.2344f, -100.0000f, + -39.8438f, 69.5313f, 148.0469f, 98.4375f, 142.5781f, 124.6094f, 177.7344f, 147.2656f, 161.3281f, 108.5938f, 87.8906f, -14.0625f, -26.1719f, -137.1094f, -146.4844f, -301.5625f +}; +/* An 16-by-16 matrix */ +const float AUNB_SN1[256] = +{ + -70.3125f, -30.8594f, -19.9219f, 15.2344f, 25.7813f, 38.6719f, 18.7500f, 42.1875f, 21.8750f, 49.6094f, 13.2813f, 17.9688f, -183.5938f, -330.0781f, -55.0781f, -35.1563f, + -82.8125f, 32.0313f, 110.9375f, 164.8438f, 162.5000f, 162.5000f, 122.2656f, 112.8906f, 91.0156f, 82.0313f, 42.1875f, 21.4844f, -171.4844f, -516.7969f, -131.2500f, -48.0469f, + -3.5156f, 158.2031f, 207.8125f, 257.4219f, 277.3438f, 311.7188f, 329.6875f, 379.2969f, 418.7500f, 461.3281f, 571.8750f, 747.2656f, 792.1875f, 481.2500f, 214.4531f, 103.5156f, + 29.2969f, 19.1406f, 128.9063f, 192.5781f, 175.0000f, 128.5156f, 79.6875f, 26.1719f, -7.0313f, -52.3438f, -91.7969f, -156.2500f, -236.3281f, -11.7188f, -26.1719f, -14.0625f, + -3.5156f, -2.7344f, -37.1094f, -86.7188f, -125.7813f, -164.4531f, -125.3906f, -91.0156f, -42.9688f, -33.5938f, 26.1719f, -7.4219f, 1.1719f, 134.7656f, 16.0156f, 11.7188f, + 59.7656f, 13.2813f, -67.1875f, -150.7813f, -195.3125f, -214.0625f, -196.4844f, -164.0625f, -123.8281f, -80.8594f, -44.5313f, 71.4844f, 428.1250f, 258.2031f, 77.3438f, 36.7188f, + 240.6250f, 195.7031f, 183.9844f, 85.9375f, 61.3281f, 21.4844f, 1.5625f, -62.8906f, -69.5313f, -122.6563f, -104.2969f, -151.9531f, 84.3750f, 167.5781f, 17.9688f, 14.8438f, + -218.3594f, -333.5938f, -308.2031f, -144.1406f, -59.7656f, 25.0000f, 57.0313f, 115.6250f, 151.5625f, 203.1250f, 224.2188f, 374.2188f, 578.5156f, 350.7813f, 132.8125f, 64.0625f, + 51.1719f, 53.5156f, 45.3125f, 22.2656f, 25.0000f, -8.2031f, -14.8438f, -43.7500f, -48.0469f, -77.7344f, -83.5938f, -148.0469f, -250.3906f, 32.4219f, -20.7031f, -8.2031f, + -39.4531f, -126.5625f, -253.1250f, -312.8906f, -326.1719f, -287.8906f, -195.7031f, -115.6250f, -33.5938f, 56.2500f, 156.2500f, 400.3906f, 586.3281f, 336.3281f, 125.7813f, 58.9844f, + -90.2344f, -155.0781f, -200.0000f, -197.6563f, -120.3125f, -78.1250f, -49.6094f, -35.5469f, -7.0313f, 6.6406f, 36.7188f, 44.5313f, 311.7188f, 244.1406f, 62.8906f, 34.3750f, + -202.3438f, -241.0156f, -78.5156f, 40.2344f, 100.7813f, 108.9844f, 106.6406f, 104.2969f, 109.7656f, 98.0469f, 83.5938f, 44.5313f, 22.6563f, 105.4688f, 27.3438f, 12.1094f, + 6.6406f, -33.5938f, -30.4688f, -32.0313f, -8.5938f, -28.5156f, -66.7969f, -116.7969f, -130.4688f, -168.3594f, -164.8438f, -205.4688f, 201.9531f, 199.6094f, 27.7344f, 20.7031f, + 107.8125f, 71.0938f, -15.6250f, -131.2500f, -180.0781f, -36.3281f, 133.5938f, 104.2969f, 64.8438f, 7.0313f, -16.7969f, -76.5625f, -57.0313f, 92.1875f, 7.0313f, 5.4688f, + 88.6719f, 132.0313f, 87.5000f, 73.4375f, 41.7969f, 31.2500f, 22.2656f, 35.9375f, 13.2813f, 31.2500f, -1.9531f, -1.5625f, -201.1719f, -362.1094f, -67.9688f, -39.0625f, + 285.5469f, 290.6250f, 311.3281f, 263.6719f, 230.4688f, 171.0938f, 128.1250f, 83.9844f, 56.2500f, 9.3750f, -37.5000f, -93.3594f, -189.8438f, -68.3594f, -25.3906f, -16.0156f +}; +/* An 16-by-16 matrix */ +const float AUWB_SN1[256] = +{ + 128.1250f, 53.5156f, 139.8438f, 128.9063f, 71.8750f, 56.6406f, -23.4375f, -114.8438f, -216.7969f, -306.2500f, -369.1406f, -340.6250f, -234.7656f, -131.6406f, -60.5469f, -12.8906f, + 12.5000f, -82.8125f, -190.6250f, -254.2969f, -293.7500f, -342.5781f, -348.4375f, -346.0938f, -333.2031f, -310.5469f, -275.3906f, -214.4531f, -128.9063f, -87.5000f, -49.6094f, -3.5156f, + 145.3125f, 127.7344f, 76.9531f, 12.8906f, 5.0781f, -21.4844f, -33.9844f, -48.4375f, -48.8281f, -57.8125f, -56.2500f, -65.6250f, -68.3594f, -71.8750f, -49.6094f, -48.8281f, + 293.7500f, 283.9844f, 243.3594f, 202.7344f, 175.3906f, 136.7188f, 120.7031f, 112.8906f, 106.2500f, 98.4375f, 72.2656f, 48.4375f, 46.0938f, 13.6719f, 8.5938f, -7.8125f, + 5.4688f, 56.2500f, 115.6250f, 168.7500f, 162.5000f, 126.9531f, 69.1406f, 64.8438f, 58.9844f, 48.0469f, 42.5781f, 40.6250f, 18.3594f, -8.5938f, -17.5781f, -19.1406f, + 121.0938f, 43.7500f, -55.0781f, -206.6406f, -255.4688f, -20.7031f, 63.2813f, -12.8906f, -116.0156f, -215.2344f, -301.5625f, -319.1406f, -210.9375f, -112.1094f, -37.1094f, -2.7344f, + -61.7188f, 94.1406f, 173.0469f, 212.1094f, 218.3594f, 226.1719f, 221.0938f, 236.7188f, 238.2813f, 242.9688f, 235.1563f, 225.7813f, 189.4531f, 129.2969f, 76.9531f, 40.6250f, + -183.9844f, -207.0313f, 14.4531f, 106.2500f, 155.0781f, 172.6563f, 182.0313f, 204.2969f, 219.1406f, 231.2500f, 237.5000f, 225.0000f, 189.4531f, 135.9375f, 86.7188f, 51.9531f, + 63.2813f, 0.0000f, -33.9844f, -33.2031f, -58.9844f, -129.2969f, -160.1563f, -235.5469f, -299.6094f, -402.3438f, -526.5625f, -707.8125f, -677.7344f, -264.8438f, -110.9375f, -2.3438f, + -60.9375f, 14.0625f, 5.8594f, 10.1563f, 16.0156f, 46.0938f, 78.5156f, 103.5156f, 132.4219f, 149.2188f, 164.0625f, 169.9219f, 147.2656f, 103.1250f, 62.1094f, 32.8125f, + -26.9531f, -107.0313f, -160.5469f, -61.7188f, 23.4375f, -21.8750f, -74.2188f, -119.1406f, -144.9219f, -151.9531f, -160.5469f, -158.9844f, -132.0313f, -107.8125f, -67.5781f, -38.6719f, + 0.0000f, -10.1563f, -76.5625f, -148.0469f, -144.1406f, -127.7344f, -75.3906f, -57.8125f, -30.0781f, -3.9063f, 24.6094f, 38.2813f, 38.2813f, 19.1406f, 15.6250f, -1.9531f, + -58.2031f, -168.7500f, -284.7656f, -360.5469f, -362.1094f, -299.2188f, -221.8750f, -177.7344f, -130.0781f, -85.5469f, -47.6563f, -11.3281f, 4.2969f, 3.5156f, 7.8125f, 21.0938f, + 69.1406f, 25.0000f, -23.4375f, -90.6250f, -160.5469f, -215.6250f, -217.5781f, -214.8438f, -198.8281f, -181.2500f, -148.4375f, -129.2969f, -116.0156f, -112.5000f, -83.9844f, -66.4063f, + -6.2500f, 171.4844f, 379.2969f, 431.2500f, 472.2656f, 516.7969f, 523.0469f, 536.7188f, 514.4531f, 477.7344f, 432.4219f, 383.9844f, 305.0781f, 208.9844f, 123.0469f, 58.9844f, + -168.7500f, -283.9844f, -267.9688f, -132.8125f, -60.9375f, -15.6250f, 7.0313f, 39.8438f, 66.0156f, 100.3906f, 119.5313f, 130.8594f, 115.6250f, 83.2031f, 53.5156f, 37.8906f +}; +/* An 16-by-16 matrix */ +const float AUWB2_SN1[256] = +{ + -41.7969f, -174.2188f, -326.1719f, -406.6406f, -450.0000f, -453.5156f, -447.6563f, -378.5156f, -323.4375f, -208.2031f, -98.0469f, -94.5313f, -54.2969f, 67.1875f, 37.1094f, 182.0313f, + 410.9375f, 393.7500f, 410.9375f, 341.7969f, 337.5000f, 292.1875f, 305.8594f, 269.5313f, 294.5313f, 279.2969f, 268.7500f, 133.5938f, 76.1719f, -12.5000f, -98.0469f, -198.8281f, + -121.4844f, -66.4063f, 142.9688f, 246.8750f, 292.1875f, 337.1094f, 383.9844f, 407.0313f, 436.7188f, 464.0625f, 442.5781f, 349.6094f, 284.3750f, 242.5781f, 179.6875f, 163.2813f, + 237.5000f, 205.0781f, 125.7813f, 11.7188f, -92.5781f, -188.6719f, -336.7188f, -460.1563f, -644.9219f, -853.1250f, -1082.0313f, -526.9531f, -167.9688f, -10.9375f, 50.0000f, 219.5313f, + 115.6250f, 66.7969f, -75.0000f, -167.5781f, -190.6250f, -183.5938f, -192.1875f, -184.7656f, -175.0000f, -137.5000f, -94.5313f, -120.7031f, -131.6406f, -82.0313f, -103.5156f, -71.0938f, + 324.6094f, 274.6094f, 178.1250f, 84.7656f, 64.4531f, 25.3906f, 6.6406f, -20.7031f, -26.1719f, -30.4688f, -14.8438f, -86.7188f, -132.8125f, -128.5156f, -136.3281f, -152.7344f, + 63.2813f, -5.0781f, -61.7188f, -130.8594f, -205.4688f, -275.3906f, -385.1563f, -486.3281f, -640.6250f, -839.4531f, -1075.7813f, -525.0000f, -145.3125f, -4.6875f, 52.3438f, 220.3125f, + -30.8594f, -151.9531f, -222.2656f, -273.0469f, -316.7969f, -367.1875f, -413.2813f, -507.4219f, -599.2188f, -811.3281f, -762.8906f, -198.0469f, -84.3750f, 55.8594f, 74.6094f, 237.1094f, + -41.4063f, -45.3125f, -82.0313f, -87.8906f, -126.1719f, -128.9063f, -192.9688f, -191.7969f, -273.4375f, -295.7031f, -412.8906f, -556.2500f, -867.9688f, -589.4531f, -101.1719f, 135.9375f, + -142.9688f, -292.1875f, -459.7656f, -475.0000f, -397.2656f, -272.6563f, -173.4375f, -60.1563f, 3.9063f, 111.3281f, 141.0156f, 110.9375f, 99.6094f, 140.2344f, 73.0469f, 142.5781f, + 30.0781f, 174.6094f, 163.2813f, 185.5469f, 176.9531f, 179.2969f, 185.5469f, 201.1719f, 219.5313f, 253.1250f, 257.0313f, 176.5625f, 143.3594f, 130.4688f, 95.3125f, 79.6875f, + 3.9063f, 76.9531f, 66.4063f, 64.8438f, 56.2500f, 23.4375f, 20.3125f, -0.7813f, -7.8125f, -15.6250f, 7.0313f, -92.9688f, -108.9844f, -169.5313f, -176.1719f, -315.2344f, + -179.6875f, -278.5156f, -213.6719f, -59.7656f, 25.0000f, 94.9219f, 150.7813f, 192.1875f, 242.1875f, 293.7500f, 296.4844f, 209.3750f, 173.8281f, 126.5625f, 58.9844f, -12.5000f, + -96.0938f, -154.6875f, -161.3281f, -144.9219f, -138.2813f, -123.8281f, -119.9219f, -89.0625f, -76.1719f, -39.4531f, -14.0625f, -67.9688f, -76.9531f, -63.2813f, -101.9531f, -136.3281f, + -128.5156f, -93.7500f, 127.3438f, 180.4688f, 167.1875f, 134.3750f, 158.2031f, 146.0938f, 171.4844f, 169.5313f, 182.4219f, 49.6094f, 33.2031f, -60.1563f, -96.8750f, -266.7969f, + -4.6875f, 5.8594f, -86.7188f, -88.6719f, -12.1094f, 48.4375f, 78.1250f, 114.8438f, 139.4531f, 211.3281f, 237.1094f, 179.2969f, 146.8750f, 137.5000f, 110.1563f, 110.5469f +}; +/* An 16-by-16 matrix */ +const float CNG_SN1[256] = +{ + 234.3750f, 640.6250f, 1187.1094f, 1662.8906f, 2153.1250f, 2632.8125f, 3120.7031f, 3581.6406f, 4059.7656f, 4535.9375f, 5031.2500f, 5507.8125f, 6007.0313f, 6466.4063f, 6959.3750f, 7389.8438f, + 464.0625f, 971.4844f, 1463.2813f, 1915.2344f, 2383.9844f, 2836.3281f, 3295.7031f, 3744.9219f, 4209.3750f, 4669.5313f, 5145.3125f, 5607.4219f, 6079.6875f, 6528.1250f, 6997.2656f, 7426.5625f, + 135.1563f, 312.1094f, 882.4219f, 1388.6719f, 1904.6875f, 2412.1094f, 2935.9375f, 3438.6719f, 3934.7656f, 4423.0469f, 4933.9844f, 5444.5313f, 5969.5313f, 6466.0156f, 6959.7656f, 7437.1094f, + 171.4844f, 631.2500f, 1346.0938f, 1852.7344f, 2372.2656f, 2846.8750f, 3341.0156f, 3799.2188f, 4276.1719f, 4728.9063f, 5200.0000f, 5653.9063f, 6113.2813f, 6551.9531f, 6989.8438f, 7412.8906f, + 359.7656f, 703.1250f, 1162.5000f, 1565.2344f, 1994.1406f, 2397.2656f, 2803.9063f, 3183.5938f, 3537.8906f, 3872.6563f, 4300.3906f, 4900.3906f, 5340.2344f, 6055.4688f, 6807.8125f, 7393.3594f, + 350.0000f, 741.7969f, 1185.5469f, 1612.5000f, 2070.7031f, 2511.3281f, 2970.3125f, 3405.8594f, 3861.7188f, 4319.9219f, 4850.3906f, 5320.7031f, 5844.5313f, 6302.7344f, 6826.1719f, 7210.9375f, + 282.0313f, 588.6719f, 991.0156f, 1342.5781f, 1690.6250f, 2027.3438f, 2350.7813f, 2672.2656f, 2963.6719f, 3258.9844f, 3486.3281f, 3715.2344f, 3874.6094f, 4326.1719f, 5317.5781f, 5867.5781f, + 123.0469f, 239.0625f, 652.7344f, 1136.7188f, 1558.5938f, 1985.5469f, 2390.6250f, 2800.7813f, 3198.4375f, 3583.2031f, 3964.0625f, 4369.5313f, 4785.1563f, 5180.4688f, 5582.0313f, 5970.3125f, + 345.7031f, 753.1250f, 1175.7813f, 1551.9531f, 1934.3750f, 2304.6875f, 2675.0000f, 3034.7656f, 3398.8281f, 3753.5156f, 4133.2031f, 4507.8125f, 4885.9375f, 5253.9063f, 5629.6875f, 5995.7031f, + 132.0313f, 398.4375f, 1037.8906f, 1459.3750f, 1890.2344f, 2262.1094f, 2658.5938f, 3031.2500f, 3413.2813f, 3773.0469f, 4151.1719f, 4518.3594f, 4896.0938f, 5260.9375f, 5631.2500f, 5989.8438f, + 439.8438f, 767.1875f, 1171.4844f, 1505.8594f, 1860.9375f, 2190.6250f, 2532.0313f, 2846.0938f, 3167.5781f, 3448.0469f, 3738.2813f, 4159.7656f, 4687.1094f, 5126.9531f, 5555.8594f, 5957.8125f, + 150.3906f, 318.3594f, 781.2500f, 1148.0469f, 1525.7813f, 1905.8594f, 2262.8906f, 2630.4688f, 2992.5781f, 3330.4688f, 3636.3281f, 3963.2813f, 4530.0781f, 5060.5469f, 5510.1563f, 5953.5156f, + 247.2656f, 564.4531f, 937.5000f, 1286.3281f, 1654.2969f, 2019.9219f, 2399.6094f, 2767.1875f, 3147.2656f, 3507.8125f, 3876.5625f, 4267.1875f, 4682.4219f, 5077.3438f, 5475.0000f, 5882.0313f, + 228.1250f, 487.5000f, 878.9063f, 1223.0469f, 1582.0313f, 1921.8750f, 2269.9219f, 2598.4375f, 2918.3594f, 3220.3125f, 3481.6406f, 3703.1250f, 3979.6875f, 4775.3906f, 5418.3594f, 5907.4219f, + 451.9531f, 710.9375f, 1072.2656f, 1369.1406f, 1700.7813f, 1991.0156f, 2317.1875f, 2596.8750f, 2893.7500f, 3138.2813f, 3373.0469f, 3548.0469f, 3897.2656f, 4776.5625f, 5398.0469f, 5901.5625f, + 223.4375f, 547.2656f, 982.0313f, 1367.5781f, 1758.9844f, 2134.7656f, 2526.9531f, 2904.2969f, 3287.5000f, 3643.7500f, 4025.7813f, 4417.5781f, 4815.6250f, 5196.4844f, 5588.2813f, 5961.3281f +}; +/* An 16-by-32 matrix */ +const float IAA_MA1[512] = +{ + -68.3594f, -191.4063f, -203.1250f, -246.4844f, -251.9531f, -239.8438f, -238.2813f, -214.0625f, -196.4844f, -168.7500f, -137.8906f, -117.5781f, -92.9688f, -55.0781f, -26.1719f, 10.1563f, + 117.5781f, 158.9844f, 88.6719f, 37.5000f, -4.6875f, -7.0313f, -5.0781f, 0.7813f, 15.2344f, 41.7969f, 48.4375f, 35.9375f, 32.4219f, 39.0625f, 24.2188f, 28.1250f, + -109.3750f, -287.8906f, -222.2656f, -64.0625f, -3.5156f, 39.0625f, 55.0781f, 82.4219f, 98.4375f, 109.7656f, 107.0313f, 84.7656f, 80.4688f, 85.5469f, 45.7031f, 41.4063f, + -103.9063f, -294.1406f, -328.5156f, -229.2969f, -190.2344f, -134.7656f, -102.7344f, -65.2344f, -44.5313f, -11.7188f, 3.1250f, 12.5000f, 13.2813f, 23.8281f, 21.4844f, 40.6250f, + -35.5469f, -53.5156f, -114.4531f, -136.3281f, -137.5000f, -127.3438f, -104.6875f, -96.4844f, -69.5313f, -50.3906f, -21.8750f, -37.5000f, -4.2969f, 85.5469f, 19.1406f, 21.8750f, + -7.0313f, 0.3906f, -12.8906f, -5.4688f, -7.4219f, -1.9531f, -8.5938f, -5.4688f, -16.7969f, -14.4531f, -40.6250f, -55.8594f, -146.4844f, -300.7813f, -74.2188f, -39.0625f, + 28.1250f, -8.5938f, -47.2656f, -85.9375f, -125.0000f, -147.6563f, -195.3125f, -229.2969f, -284.7656f, -310.5469f, -412.5000f, -509.7656f, -660.5469f, -425.7813f, -176.5625f, -23.4375f, + 7.4219f, -108.9844f, -176.9531f, -226.5625f, -229.6875f, -288.6719f, -335.1563f, -407.8125f, -500.3906f, -630.4688f, -359.7656f, -146.8750f, -106.6406f, -32.8125f, -0.7813f, 73.0469f, + 333.2031f, 296.4844f, 230.8594f, 146.8750f, 101.5625f, 47.6563f, 15.2344f, -27.7344f, -51.9531f, -71.8750f, -81.6406f, -116.0156f, -116.7969f, -66.7969f, -48.4375f, -32.4219f, + 103.9063f, 13.2813f, -71.0938f, -143.3594f, -201.5625f, -267.9688f, -344.1406f, -437.8906f, -552.3438f, -716.4063f, -824.2188f, -389.4531f, -202.7344f, -107.0313f, -42.5781f, 53.5156f, + -0.7813f, -3.1250f, 16.4063f, 35.5469f, 67.1875f, 82.4219f, 116.4063f, 131.2500f, 169.1406f, 159.7656f, 213.2813f, 407.4219f, 585.5469f, 405.4688f, 160.1563f, 73.8281f, + 33.5938f, 99.2188f, 101.1719f, 99.2188f, 96.0938f, 85.5469f, 71.8750f, 47.6563f, 30.8594f, 4.2969f, -21.4844f, -66.4063f, -141.7969f, -364.8438f, -144.9219f, -73.4375f, + 65.6250f, 65.2344f, -47.6563f, -95.3125f, -126.9531f, -132.8125f, -140.2344f, -133.9844f, -129.2969f, -113.6719f, -108.5938f, -105.4688f, -106.2500f, -63.2813f, -39.4531f, -17.9688f, + -95.3125f, -179.2969f, -143.3594f, -132.8125f, -115.2344f, -85.9375f, -67.5781f, -41.7969f, -8.5938f, 20.7031f, 40.2344f, 114.4531f, 423.4375f, 315.2344f, 101.5625f, 45.7031f, + -124.6094f, -253.9063f, -267.5781f, -166.7969f, -113.2813f, -41.0156f, 9.7656f, 62.8906f, 118.3594f, 163.2813f, 229.2969f, 419.5313f, 610.5469f, 423.8281f, 156.2500f, 66.4063f, + 57.0313f, 100.3906f, 110.1563f, 115.2344f, 118.3594f, 114.8438f, 116.0156f, 102.3438f, 92.5781f, 75.3906f, 35.9375f, 133.2031f, 476.5625f, 345.3125f, 123.0469f, 56.2500f, + -113.6719f, -217.9688f, 57.4219f, 78.5156f, 110.1563f, 109.3750f, 121.0938f, 117.9688f, 122.2656f, 119.5313f, 114.0625f, 93.3594f, 77.3438f, 73.4375f, 41.4063f, 36.7188f, + -4.2969f, -3.1250f, -60.9375f, -79.6875f, -90.2344f, -97.6563f, -103.5156f, -112.8906f, -105.0781f, -123.4375f, -125.7813f, -175.7813f, -190.6250f, -264.0625f, -303.9063f, -380.0781f, + -45.7031f, -10.5469f, 1.5625f, 37.5000f, 67.9688f, 89.4531f, 105.8594f, 121.0938f, 134.3750f, 141.4063f, 134.3750f, 106.6406f, 81.6406f, 70.3125f, 42.5781f, 41.4063f, + -101.5625f, -113.2813f, 58.9844f, 105.0781f, 158.5938f, 172.6563f, 215.2344f, 230.4688f, 265.2344f, 266.0156f, 351.5625f, 505.0781f, 637.1094f, 442.1875f, 186.3281f, 86.3281f, + -14.4531f, 146.0938f, 153.9063f, 161.7188f, 163.6719f, 154.2969f, 134.7656f, 122.2656f, 110.1563f, 99.6094f, 82.4219f, 49.2188f, 32.8125f, 19.9219f, -3.9063f, -20.7031f, + 157.8125f, 127.7344f, 67.9688f, 10.9375f, -48.4375f, -113.2813f, -191.4063f, -271.4844f, -394.9219f, -433.9844f, -206.6406f, -112.5000f, -71.4844f, -26.9531f, -2.7344f, 55.4688f, + 219.9219f, 293.7500f, 228.5156f, 216.7969f, 200.0000f, 186.7188f, 165.6250f, 154.6875f, 146.8750f, 133.9844f, 117.1875f, 75.7813f, 75.3906f, 63.2813f, 30.4688f, 17.9688f, + -23.0469f, -51.1719f, -13.6719f, 19.1406f, 21.0938f, -4.6875f, -35.9375f, -72.2656f, -94.9219f, -112.8906f, -112.5000f, -134.3750f, -127.3438f, 0.0000f, -14.8438f, 2.3438f, + 193.7500f, 227.3438f, 220.3125f, 200.7813f, 203.5156f, 191.4063f, 189.8438f, 170.3125f, 168.7500f, 125.0000f, 178.1250f, 414.0625f, 594.9219f, 413.2813f, 163.6719f, 75.7813f, + 67.9688f, 30.0781f, 7.0313f, -34.7656f, -43.7500f, -76.5625f, -64.4531f, -96.4844f, -86.7188f, -127.3438f, -129.6875f, -192.9688f, 194.9219f, 241.0156f, 47.2656f, 23.4375f, + 123.0469f, 116.7969f, 89.4531f, 53.5156f, 30.4688f, -1.1719f, -15.6250f, -53.9063f, -77.3438f, -119.9219f, -146.4844f, -196.0938f, -201.1719f, -9.7656f, -34.3750f, -19.1406f, + -90.6250f, -11.3281f, 137.8906f, 155.8594f, 189.4531f, 190.2344f, 204.2969f, 205.4688f, 217.1875f, 218.3594f, 203.1250f, 162.1094f, 128.1250f, 110.5469f, 73.0469f, 64.8438f, + 71.0938f, 150.3906f, 157.4219f, 176.9531f, 201.1719f, 223.4375f, 248.0469f, 269.9219f, 307.4219f, 332.8125f, 450.7813f, 579.2969f, 694.9219f, 480.8594f, 204.6875f, 96.0938f, + -106.6406f, -192.1875f, -72.2656f, -37.8906f, -20.3125f, -19.9219f, -6.6406f, -10.5469f, 5.0781f, 7.8125f, 17.5781f, -7.8125f, 20.3125f, 95.3125f, 22.6563f, 21.8750f, + 7.8125f, -1.1719f, -94.1406f, -104.2969f, -75.7813f, -33.5938f, 1.5625f, 29.2969f, 54.6875f, 74.6094f, 78.1250f, 60.1563f, 53.5156f, 57.0313f, 33.2031f, 30.0781f, + 35.9375f, 245.3125f, 238.6719f, 276.5625f, 275.7813f, 279.6875f, 262.5000f, 271.0938f, 255.8594f, 241.7969f, 214.8438f, 168.7500f, 138.2813f, 110.9375f, 79.6875f, 67.1875f +}; +/* An 16-by-8 matrix */ +const float GESVNB_AR1[128] = +{ + -9.7656f, -25.0000f, -54.6875f, -46.0938f, 105.4688f, 93.7500f, 49.6094f, 27.3438f, 7.8125f, -15.6250f, -21.8750f, -43.3594f, -32.0313f, 25.0000f, 0.7813f, 1.9531f, + 31.6406f, 40.6250f, 27.7344f, 27.3438f, 0.0000f, -19.1406f, -21.0938f, -28.5156f, -23.0469f, -35.9375f, -39.8438f, -78.5156f, -157.8125f, -20.3125f, -15.6250f, -5.8594f, + -43.7500f, -84.7656f, -98.0469f, -78.9063f, -13.2813f, 22.2656f, 22.6563f, 24.2188f, 30.8594f, 49.6094f, 69.1406f, 119.5313f, 204.6875f, 123.0469f, 43.7500f, 20.7031f, + 6.6406f, -2.3438f, 13.2813f, 25.7813f, 5.4688f, -10.1563f, -67.9688f, -76.5625f, -55.4688f, -51.1719f, -39.8438f, -37.8906f, 70.3125f, 60.1563f, 11.3281f, 6.6406f, + 1.9531f, -10.5469f, -41.7969f, -76.9531f, -133.9844f, -130.0781f, -71.0938f, -55.8594f, -35.5469f, -6.6406f, 16.7969f, 46.8750f, 149.6094f, 104.2969f, 32.4219f, 15.6250f, + -0.3906f, -5.8594f, -13.6719f, -21.8750f, -66.0156f, -56.6406f, 33.5938f, 39.4531f, 30.0781f, 18.7500f, 11.3281f, 30.4688f, -3.5156f, 26.5625f, 5.8594f, 3.5156f, + 1.1719f, 3.5156f, 125.0000f, 175.7813f, 150.3906f, 135.9375f, 83.9844f, 60.5469f, 41.0156f, 17.5781f, -5.0781f, -29.2969f, -106.2500f, -50.3906f, -20.3125f, -8.9844f, + 1.5625f, 19.1406f, 21.0938f, 35.1563f, 35.9375f, 39.4531f, 23.0469f, 26.9531f, 7.8125f, 27.3438f, 8.9844f, 16.7969f, -109.3750f, -243.7500f, -44.5313f, -21.4844f +}; +/* An 16-by-8 matrix */ +const float GESVNB_AR2[128] = +{ + -8.5938f, -13.6719f, -12.1094f, -64.8438f, -64.0625f, 84.7656f, 82.8125f, 60.5469f, 64.8438f, 48.0469f, 26.1719f, 12.8906f, -8.2031f, -16.0156f, -1.1719f, -0.3906f, + -5.4688f, -7.8125f, -6.2500f, -27.3438f, -30.0781f, -20.7031f, 8.9844f, -2.7344f, -38.2813f, -48.0469f, -38.6719f, -19.1406f, 139.4531f, 44.5313f, 14.0625f, 7.4219f, + -22.2656f, -46.4844f, -118.3594f, -83.9844f, -12.8906f, -40.2344f, -37.8906f, -45.7031f, -41.0156f, -39.8438f, -26.1719f, -52.3438f, -68.7500f, 44.1406f, 6.2500f, 3.1250f, + -4.6875f, 5.4688f, 11.7188f, -14.4531f, -43.7500f, -88.2813f, -80.4688f, -9.7656f, 48.8281f, 52.3438f, 38.6719f, 32.4219f, 21.4844f, -1.5625f, 3.5156f, 1.5625f, + -7.4219f, 8.9844f, 66.7969f, 22.2656f, 5.0781f, -5.8594f, -10.1563f, -16.4063f, -25.3906f, -26.9531f, -30.0781f, -66.0156f, -137.1094f, -41.0156f, -19.1406f, -8.2031f, + -5.4688f, -3.9063f, 3.1250f, 13.6719f, 62.8906f, 40.6250f, -28.9063f, -39.8438f, -52.7344f, -18.3594f, 17.5781f, 103.1250f, 20.3125f, -26.9531f, -0.3906f, -1.9531f, + 83.2031f, 110.9375f, 89.8438f, 47.2656f, 19.5313f, 4.6875f, 16.7969f, 18.7500f, 10.5469f, -2.7344f, -9.3750f, -15.2344f, 29.2969f, 0.3906f, -3.5156f, -1.1719f, + -29.2969f, -53.5156f, -34.7656f, 107.4219f, 64.0625f, 25.3906f, 48.8281f, 35.5469f, 33.5938f, 35.5469f, 21.8750f, 3.9063f, 3.5156f, -3.9063f, 0.0000f, 0.0000f +}; +/* An 16-by-8 matrix */ +const float GESVWB_AR1[128] = +{ + -1.1719f, -6.2500f, -12.1094f, 0.7813f, -31.6406f, -48.0469f, -88.2813f, -101.5625f, -76.5625f, -47.6563f, -7.8125f, 30.4688f, 69.5313f, 56.6406f, 32.8125f, 17.9688f, + 21.4844f, 16.4063f, 5.8594f, 12.5000f, -18.7500f, -31.6406f, -42.5781f, -53.5156f, -73.0469f, -103.1250f, -128.9063f, -151.1719f, -141.7969f, -68.7500f, -14.8438f, 14.4531f, + -12.5000f, -27.3438f, -56.2500f, -105.0781f, -131.6406f, -71.4844f, 23.0469f, 22.6563f, 17.1875f, 19.1406f, 16.4063f, 19.9219f, 28.1250f, 19.5313f, 10.1563f, 14.8438f, + -7.0313f, -22.6563f, -30.8594f, 48.8281f, 137.5000f, 113.6719f, 70.3125f, 46.0938f, 28.1250f, 9.7656f, -8.9844f, -32.0313f, -72.2656f, -65.2344f, -12.8906f, 2.3438f, + -3.9063f, 52.7344f, 212.5000f, 201.9531f, 201.9531f, 219.1406f, 201.1719f, 206.2500f, 195.3125f, 184.3750f, 161.3281f, 149.6094f, 124.2188f, 85.5469f, 46.0938f, 22.2656f, + -21.0938f, -109.3750f, -239.8438f, -214.0625f, -203.5156f, -203.9063f, -175.0000f, -187.1094f, -178.5156f, -171.0938f, -147.2656f, -138.6719f, -124.2188f, -105.8594f, -86.7188f, -34.7656f, + -24.2188f, -37.5000f, -33.5938f, -3.9063f, 40.6250f, 60.5469f, 46.8750f, 43.7500f, 74.2188f, 103.1250f, 113.6719f, 106.2500f, 90.6250f, 64.8438f, 37.1094f, 10.5469f, + 12.8906f, 23.8281f, 60.5469f, 47.2656f, 3.5156f, -10.9375f, 2.3438f, 40.2344f, 25.0000f, 6.6406f, 1.5625f, -0.7813f, -12.1094f, -34.3750f, -81.6406f, -80.4688f +}; +/* An 16-by-8 matrix */ +const float GESVWB_AR2[128] = +{ + -57.4219f, -127.3438f, -164.4531f, -35.5469f, -8.5938f, -9.7656f, -5.4688f, -8.2031f, 12.5000f, 29.6875f, 40.6250f, 39.8438f, 25.3906f, 18.3594f, 19.5313f, 16.0156f, + -15.2344f, -6.2500f, 23.8281f, -5.0781f, -14.8438f, -21.8750f, 18.3594f, 59.7656f, 76.1719f, 83.2031f, 82.8125f, 85.9375f, 95.7031f, 95.7031f, 81.6406f, 33.5938f, + -13.2813f, -28.5156f, 32.0313f, 151.1719f, 77.7344f, 27.7344f, 21.8750f, -7.0313f, -12.8906f, -21.8750f, -34.3750f, -30.8594f, -1.9531f, 23.0469f, 21.4844f, 11.3281f, + -2.7344f, -8.2031f, -8.2031f, -61.7188f, -48.0469f, 118.7500f, 88.2813f, 65.6250f, 48.4375f, 3.1250f, -29.2969f, -35.5469f, -21.0938f, -1.9531f, 14.4531f, 11.7188f, + -10.1563f, -8.5938f, -26.1719f, -87.8906f, 41.7969f, 14.8438f, -32.0313f, -44.1406f, -83.2031f, -80.0781f, -24.2188f, 10.9375f, 34.7656f, 37.1094f, 20.3125f, 6.6406f, + 88.6719f, 157.8125f, 126.9531f, 52.3438f, 17.5781f, -6.2500f, 1.1719f, -5.8594f, -21.4844f, -25.3906f, -21.4844f, -21.0938f, -7.0313f, -3.1250f, 0.3906f, -5.4688f, + 7.4219f, 11.7188f, 4.6875f, 10.9375f, 18.7500f, 5.0781f, 0.7813f, -18.3594f, -14.8438f, 16.0156f, 11.3281f, -3.1250f, -60.1563f, -123.0469f, -160.5469f, -94.5313f, + 3.1250f, 9.3750f, 11.3281f, -23.8281f, -83.9844f, -128.5156f, -92.5781f, -41.4063f, -4.6875f, -4.6875f, -25.0000f, -46.0938f, -65.2344f, -46.4844f, 3.1250f, 20.3125f +}; +/* An 16-by-32 matrix */ +const float AUWB2_MA1[512] = +{ + 152.7344f, 116.4063f, 69.9219f, -14.4531f, -87.8906f, -151.1719f, -244.9219f, -337.5000f, -475.0000f, -642.1875f, -823.4375f, -314.0625f, -108.2031f, -1.9531f, 47.2656f, 182.8125f, + 137.1094f, 83.2031f, 55.0781f, -29.2969f, -50.7813f, -64.0625f, -129.6875f, -160.1563f, -204.6875f, -223.8281f, -224.6094f, -185.1563f, -129.2969f, -40.2344f, -8.5938f, 78.5156f, + 31.6406f, 341.4063f, 444.1406f, 477.7344f, 485.1563f, 492.9688f, 483.5938f, 462.8906f, 445.7031f, 423.8281f, 387.8906f, 286.3281f, 222.6563f, 165.6250f, 100.0000f, 56.6406f, + -2.3438f, -9.7656f, -41.0156f, -57.4219f, -127.7344f, -133.5938f, -229.2969f, -242.1875f, -372.6563f, -446.4844f, -733.5938f, -804.2969f, -139.0625f, -39.0625f, 52.3438f, 186.3281f, + -76.9531f, -197.2656f, -322.6563f, -407.4219f, -337.1094f, -189.4531f, -115.6250f, -40.2344f, -2.3438f, 69.5313f, 105.0781f, 95.7031f, 90.2344f, 125.0000f, 94.9219f, 161.3281f, + -202.3438f, -236.3281f, 110.1563f, 167.9688f, 207.8125f, 232.8125f, 264.0625f, 292.1875f, 315.6250f, 336.3281f, 325.7813f, 266.0156f, 208.5938f, 194.5313f, 114.4531f, 131.6406f, + -95.3125f, -219.9219f, -281.2500f, -233.9844f, -195.3125f, -192.9688f, -244.9219f, -288.6719f, -401.5625f, -476.1719f, -116.0156f, 3.5156f, 27.7344f, 106.2500f, 111.3281f, 219.9219f, + -175.0000f, -333.5938f, -357.8125f, -202.3438f, -112.1094f, -20.3125f, 21.8750f, 95.7031f, 135.5469f, 204.6875f, 217.5781f, 194.1406f, 162.5000f, 176.5625f, 125.3906f, 170.7031f, + 58.5938f, 44.1406f, 10.9375f, -10.1563f, 0.3906f, -31.2500f, -69.1406f, -88.2813f, -75.3906f, -60.9375f, -24.2188f, -88.6719f, -93.7500f, -149.6094f, -208.9844f, -316.0156f, + -93.7500f, -96.0938f, -67.9688f, -25.7813f, 31.2500f, 58.2031f, 95.3125f, 110.9375f, 161.3281f, 169.5313f, 184.7656f, 61.7188f, 21.8750f, -65.2344f, -127.3438f, -282.4219f, + 51.1719f, -4.2969f, 55.0781f, 12.5000f, 9.3750f, -47.6563f, -155.0781f, -238.2813f, -346.8750f, -317.1875f, 11.7188f, 90.6250f, 119.5313f, 144.9219f, 133.2031f, 174.2188f, + -61.7188f, -212.8906f, -206.6406f, 58.9844f, 55.4688f, -39.4531f, -166.4063f, -279.6875f, -402.7344f, -577.7344f, -605.4688f, -137.5000f, -51.5625f, 56.6406f, 73.0469f, 201.9531f, + 57.8125f, -40.6250f, -173.8281f, -328.5156f, -12.1094f, 71.4844f, -33.5938f, -123.4375f, -240.2344f, -257.8125f, -90.2344f, 32.8125f, 75.0000f, 107.4219f, 78.5156f, 121.4844f, + -71.4844f, -85.9375f, -94.9219f, -71.0938f, -92.5781f, -68.7500f, -103.9063f, -91.0156f, -131.2500f, -132.4219f, -253.9063f, -398.0469f, -645.3125f, -330.4688f, -20.3125f, 151.1719f, + -40.6250f, -45.7031f, -99.2188f, -129.6875f, -74.6094f, 0.3906f, 25.0000f, 71.0938f, 123.8281f, 193.3594f, 244.5313f, 224.2188f, 202.7344f, 198.4375f, 178.1250f, 197.2656f, + -58.9844f, -92.5781f, 192.1875f, 187.1094f, 106.6406f, 54.2969f, 14.0625f, -23.4375f, -46.4844f, 28.9063f, 67.9688f, 73.4375f, 116.4063f, 142.9688f, 135.5469f, 186.7188f, + 61.7188f, 8.9844f, -82.0313f, -175.7813f, -262.8906f, -248.8281f, -165.2344f, -129.2969f, -51.9531f, 5.4688f, 50.0000f, 26.9531f, 24.2188f, 55.8594f, 66.7969f, 122.2656f, + 195.7031f, 153.9063f, 14.4531f, -22.2656f, 26.1719f, 27.3438f, 17.9688f, 13.6719f, 35.9375f, 46.8750f, 131.6406f, 100.7813f, 107.8125f, 110.5469f, 143.7500f, 195.3125f, + 16.4063f, -61.3281f, -155.4688f, -234.3750f, -289.8438f, -304.6875f, -305.0781f, -382.8125f, -455.4688f, -636.3281f, -378.1250f, -58.2031f, -38.6719f, 73.4375f, 81.6406f, 206.6406f, + -93.7500f, 74.2188f, 181.6406f, 212.1094f, 224.6094f, 220.7031f, 236.3281f, 232.8125f, 255.0781f, 233.9844f, 227.7344f, 108.9844f, 79.2969f, -19.9219f, -72.6563f, -230.0781f, + 123.4375f, 144.9219f, 162.8906f, 145.3125f, 114.4531f, 73.8281f, 89.8438f, 60.1563f, 71.8750f, 35.5469f, 36.7188f, -68.3594f, -77.3438f, -139.8438f, -177.3438f, -287.5000f, + 28.1250f, -62.1094f, -141.4063f, -194.9219f, -247.2656f, -269.5313f, -310.1563f, -288.6719f, -258.5938f, -178.1250f, -140.6250f, -132.0313f, -98.0469f, -2.3438f, 19.5313f, 135.1563f, + -78.9063f, -129.6875f, -167.1875f, -180.4688f, -198.4375f, -171.8750f, -215.6250f, -252.7344f, -345.7031f, -475.3906f, -676.9531f, -241.7969f, -63.2813f, 37.1094f, 78.9063f, 199.2188f, + -35.5469f, -152.7344f, -276.9531f, -345.3125f, -395.3125f, -391.0156f, -365.6250f, -278.9063f, -198.8281f, -77.3438f, 16.4063f, 38.6719f, 46.4844f, 101.9531f, 92.9688f, 193.7500f, + -144.5313f, 35.9375f, 185.9375f, 235.9375f, 266.0156f, 297.6563f, 322.6563f, 348.8281f, 364.8438f, 391.0156f, 372.6563f, 305.8594f, 245.7031f, 230.4688f, 160.9375f, 182.4219f, + -75.3906f, -8.5938f, -10.9375f, 17.9688f, 83.5938f, 151.1719f, 196.0938f, 251.1719f, 284.3750f, 337.5000f, 335.5469f, 282.4219f, 226.9531f, 222.2656f, 169.9219f, 188.6719f, + 87.1094f, 113.6719f, 247.2656f, 198.4375f, 136.7188f, 55.0781f, -60.9375f, -185.9375f, -363.2813f, -553.5156f, -706.6406f, -298.4375f, -80.4688f, 30.0781f, 74.6094f, 201.1719f, + -185.5469f, -308.9844f, -162.8906f, 29.2969f, 78.5156f, 133.9844f, 159.3750f, 214.4531f, 239.0625f, 276.1719f, 267.9688f, 223.4375f, 180.8594f, 178.5156f, 125.3906f, 145.7031f, + 328.9063f, 279.6875f, 261.3281f, 231.6406f, 163.6719f, 165.2344f, 145.7031f, 125.3906f, 106.6406f, 109.3750f, 138.2813f, 84.7656f, 75.3906f, 90.6250f, 68.3594f, 114.8438f, + 45.3125f, -23.4375f, -56.2500f, -116.7969f, -164.4531f, -215.2344f, -285.9375f, -371.8750f, -469.9219f, -649.2188f, -779.6875f, -209.7656f, -93.7500f, 21.4844f, 53.9063f, 189.8438f, + -126.1719f, -259.7656f, -267.9688f, -83.5938f, -78.5156f, -101.5625f, -145.7031f, -128.5156f, -130.0781f, -64.4531f, 25.7813f, 37.5000f, 68.3594f, 121.0938f, 113.6719f, 189.8438f, + -7.4219f, 16.7969f, 13.6719f, 15.6250f, 16.4063f, 21.4844f, 24.6094f, 39.4531f, 51.9531f, 75.7813f, 86.7188f, 59.3750f, 45.7031f, 56.6406f, 51.9531f, 83.2031f +}; + +/*----------------------------------------------------------------------------------* + * LSF quantization - LSF mode/codebook selection tables + *----------------------------------------------------------------------------------*/ +const short CB_lsf[] = +{ + -1, /* Mode 0 : INACTIVE NB, Safety net */ + -1, /* Mode 1 : UNVOICED NB, Safety net */ + 0, /* Mode 2 : VOICED NB, Safety net */ + 2, /* Mode 3 : GENERIC NB, Safety net */ + 2, /* Mode 4 : TRANSITION NB, Safety net */ + 4, /* Mode 5 : AUDIO NB, Safety net */ + -1, /* Mode 6 : INACTIVE WB, Safety net */ + -1, /* Mode 7 : UNVOICED WB, Safety net */ + 5, /* Mode 8 : VOICED WB, Safety net */ + 7, /* Mode 9 : GENERIC WB, Safety net */ + 7, /* Mode 10 : TRANSITION WB, Safety net */ + 9, /* Mode 11 : AUDIO WB, Safety net */ + -1, /* Mode 12 : INACTIVE WB16k, Safety net */ + -1, /* Mode 13 : UNVOICED WB16k, Safety net */ + -1, /* Mode 14 : VOICED WB16k, Safety net */ + -1, /* Mode 15 : GENERIC WB 16k, Safety net */ + 10, /* Mode 16 : TRANSITION WB16k, Safety net */ + -1, /* Mode 17 : AUDIO WB16k, Safety net */ + 13 /* Mode 18 : CNG, Safety net */ +}; + +const short CB_p_lsf[] = +{ + 0, /* Mode 0 : INACTIVE NB, Predictive */ + 1, /* Mode 1 : UNVOICED NB, Predictive */ + 4, /* Mode 2 : VOICED NB, Predictive */ + 4, /* Mode 3 : GENERIC NB, Predictive */ + -1, /* Mode 4 : TRANSITION NB, Predictive */ + -1, /* Mode 5 : AUDIO NB, Predictive */ + 0, /* Mode 6 : INACTIVE WB, Predictive */ + 1, /* Mode 7 : UNVOICED WB, Predictive */ + 6, /* Mode 8 : VOICED WB, Predictive */ + 6, /* Mode 9 : GENERIC WB, Predictive */ + -1, /* Mode 10 : TRANSITION WB, Predictive */ + -1, /* Mode 11 : AUDIO WB, Predictive */ + 0, /* Mode 12 : INACTIVE WB16k, Predictive */ + -1, /* Mode 13 : UNVOICED WB16k, Predictive */ + -1, /* Mode 14 : VOICED WB16k, Predictive */ + 8, /* Mode 15 : GENERIC WB16k, Predictive */ + -1, /* Mode 16 : TRANSITION WB16k, Predictive */ + 10, /* Mode 17 : AUDIO WB16k, Predictive */ + 9, /* Mode 18 : GENERIC WB, MA Predictive */ +}; + + +const float *const ModeMeans[] = {IANB_Ave, UVNB_Ave, SVNB_Ave, GENB_Ave, TRNB_Ave, AUNB_Ave, IAWB_Ave, UVWB_Ave, + SVWB_Ave, GEWB_Ave, TRWB_Ave, AUWB_Ave, IAWB2_Ave, NULL, SVWB2_Ave, GEWB2_Ave, TRWB2_Ave, AUWB2_Ave + }; +const float * const Predictors[] = {Predictor6, NULL, Predictor1, Predictor3, NULL, Predictor6,Predictor5, NULL, Predictor0, + Predictor2, NULL, Predictor5, Predictor7, NULL, Predictor8, Predictor4, NULL, Predictor7 + }; +const float means_nb_31bits_ma_lsf[16] = {336.3281f , 531.2500f , 886.7188f , 1266.7969f , 1629.2969f , 1973.4375f , 2348.4375f , 2646.8750f , 2998.4375f , 3292.1875f , 3591.4062f , 3806.2500f , 4132.8125f , 4652.7344f , 5250.0000f , 5883.2031f}; +const float means_wb_31bits_ma_lsf[16] = {319.5312f , 548.0469f , 934.3750f , 1353.5156f , 1730.0781f , 2120.3125f , 2505.4688f , 2860.5469f , 3243.7500f , 3601.9531f , 3969.5312f , 4332.4219f , 4736.3281f , 5137.8906f , 5562.8906f , 5963.2812f}; + + +const short CBsizes[] = +{ + 1,2,4,8,16,32,64 +}; + + +const short CBbits[] = +{ + -1, /* Mode 0 : INACTIVE NB, Safety net */ + -1, /* Mode 1 : UNVOICED NB, Safety net */ + 4, /* Mode 2 : VOICED NB, Safety net */ + 5, /* Mode 3 : GENERIC NB, Safety net */ + 5, /* Mode 4 : TRANSITION NB, Safety net */ + 4, /* Mode 5 : AUDIO NB, Safety net */ + -1, /* Mode 6 : INACTIVE WB, Safety net */ + -1, /* Mode 7 : UNVOICED WB, Safety net */ + 4, /* Mode 8 : VOICED WB, Safety net */ + 5, /* Mode 9 : GENERIC WB, Safety net */ + 5, /* Mode 10 : TRANSITION WB, Safety net */ + 4, /* Mode 11 : AUDIO WB, Safety net */ + -1, /* Mode 12 : INACTIVE WB16k, Safety net */ + -1, /* Mode 13 : UNVOICED WB16k, Safety net */ + 4, /* Mode 14 : VOICED WB16k, Safety net */ + -1, /* Mode 15 : GENERIC WB16k, Safety net */ + 4, /* Mode 16 : TRANSITION WB16k, Safety net */ + -1, /* Mode 17 : AUDIO WB16k, Safety net */ + 4, /* Mode 18: CNG, Safety net */ +}; + + +const short CBbits_p[] = +{ + 5, /* Mode 0 : INACTIVE NB, Predictive */ + 4, /* Mode 1 : UNVOICED NB, Predictive */ + 3, /* Mode 2 : VOICED NB, Predictive */ + 3, /* Mode 3 : GENERIC NB, Predictive */ + -1, /* Mode 4 : TRANSITION NB, Predictive */ + 0, /* Mode 5 : AUDIO NB, Predictive */ + 5, /* Mode 6 : INACTIVE WB, Predictive */ + 4, /* Mode 7 : UNVOICED WB, Predictive */ + 3, /* Mode 8 : VOICED WB, Predictive */ + 3, /* Mode 9 : GENERIC WB, Predictive */ + -1, /* Mode 10 : TRANSITION WB, Predictive */ + 0, /* Mode 11 : AUDIO WB, Predictive */ + 5, /* Mode 12 : INACTIVE WB16k, Predictive */ + -1, /* Mode 13 : UNVOICED WB16k, Predictive */ + 3, /* Mode 14 : VOICED WB16k, Predictive */ + 5, /* Mode 15 : GENERIC WB16k, Predictive */ + -1, /* Mode 16 : TRANSITION WB16k, Predictive */ + 5, /* Mode 17 : AUDIO WB16k, Predictive */ + 5, /* Mode 9 : GENERIC WB, Predictive */ +}; + + + +const short BitsVQ[]= +{ + -1, /* Mode 0 : INACTIVE NB, Safety net */ + -1, /* Mode 1 : UNVOICED NB, Safety net */ + 8, /* Mode 2 : VOICED NB, Safety net */ + 9, /* Mode 3 : GENERIC NB, Safety net */ + 9, /* Mode 4 : TRANSITION NB, Safety net */ + 4, /* Mode 5 : AUDIO NB, Safety net */ + -1, /* Mode 6 : INACTIVE WB, Safety net */ + -1, /* Mode 7 : UNVOICED WB, Safety net */ + 8, /* Mode 8 : VOICED WB, Safety net */ + 9, /* Mode 9 : GENERIC WB, Safety net */ + 9, /* Mode 10 : TRANSITION WB, Safety net */ + 4, /* Mode 11 : AUDIO WB, Safety net */ + -1, /* Mode 12 : INACTIVE WB16k, Safety net */ + -1, /* Mode 13 : UNVOICED WB16k, Safety net */ + 8, /* Mode 14 : VOICED WB16k, Safety net */ + -1, /* Mode 15 : GENERIC WB16k, Safety net */ + 8, /* Mode 16 : TRANSITION WB16k, Safety net */ + -1, /* Mode 17 : AUDIO WB16k, Safety net */ + 4, /* Mode 18: CNG, Safety net */ +}; + + +const short BitsVQ_p[]= +{ + 5, /* Mode 0 : INACTIVE NB, Predictive */ + 8, /* Mode 1 : UNVOICED NB, Predictive */ + 6, /* Mode 2 : VOICED NB, Predictive */ + 6, /* Mode 3 : GENERIC NB, Predictive */ + -1, /* Mode 4 : TRANSITION NB, Predictive */ + 0, /* Mode 5 : AUDIO NB, Predictive */ + 5, /* Mode 6 : INACTIVE WB, Predictive */ + 12, /* Mode 7 : UNVOICED WB, Predictive */ + 6, /* Mode 8 : VOICED WB, Predictive */ + 6, /* Mode 9 : GENERIC WB, Predictive */ + -1, /* Mode 10 : TRANSITION WB, Predictive */ + 0, /* Mode 11 : AUDIO WB, Predictive */ + 5, /* Mode 12 : INACTIVE WB16k, Predictive */ + -1, /* Mode 13 : UNVOICED WB16k, Predictive */ + 6, /* Mode 14 : VOICED WB16k, Predictive */ + 5, /* Mode 15 : GENERIC WB16k, Predictive */ + -1, /* Mode 16 : TRANSITION WB16k, Predictive */ + 5, /* Mode 17 : AUDIO WB16k, Predictive */ + 5, /* Mode 18 : GENERIC WB, MA Predictive */ +}; + + +const short predmode_tab[][6] = +{ + {1,1,2,2,0,2}, + {1,1,2,2,0,2}, + {1,-1,2,1,0,1}, + {1,1,2,1,0,1} /* should check how is the cb for audio mode at 13.2*/ +}; + +const float *const Quantizers[] = {SVNB_SN1, SVNB_SN2, GETRNB_SN1, GETRNB_SN2, AUNB_SN1,SVWB_SN1, SVWB_SN2, GETRWB_SN1, + GETRWB_SN2, AUWB_SN1,TRWB2_SN1, TRWB2_SN2, AUWB2_SN1, CNG_SN1 + }; +const float *const Quantizers_p[] = {IAA_MA1, UVD_MA1, UVD_MA2, UVWB_MA3, GESVNB_AR1, GESVNB_AR2, GESVWB_AR1, GESVWB_AR2, + GEWB2_MA1,GEWB_MA1, AUWB2_MA1 + }; + +const float vals[NO_LEADERS][MAX_NO_VALS]= +{ + {1.0f, 0.0f, 0.0f, 0.0f}, + {0.5f, 0.0f, 0.0f, 0.0f}, + {1.0f, 0.0f, 0.0f, 0.0f}, + {2.0f, 0.0f, 0.0f, 0.0f}, + {1.5f, 0.5f, 0.0f, 0.0f}, + {1.0f, 0.0f, 0.0f, 0.0f}, + {2.0f, 1.0f, 0.0f, 0.0f}, + {1.5f, 0.5f, 0.0f, 0.0f}, + {1.0f, 0.0f, 0.0f, 0.0f}, + {2.0f, 1.0f, 0.0f, 0.0f}, + {2.0f, 0.0f, 0.0f, 0.0f}, + {1.5f, 0.5f, 0.0f, 0.0f}, + {2.5f, 0.5f, 0.0f, 0.0f}, + {2.0f, 1.0f, 0.0f, 0.0f}, + {2.0f, 1.0f, 0.0f, 0.0f}, + {3.0f, 1.0f, 0.0f, 0.0f}, + {1.5f, 0.5f, 0.0f, 0.0f}, + {2.5f, 1.5f, 0.5f, 0.0f}, + {2.0f, 1.0f, 0.0f, 0.0f}, + {2.0f, 0.0f, 0.0f, 0.0f}, + {3.0f, 1.0f, 0.0f, 0.0f}, + {1.5f, 0.5f, 0.0f, 0.0f}, + {2.5f, 1.5f, 0.5f, 0.0f}, + {2.0f, 1.0f, 0.0f, 0.0f}, + {2.0f, 1.0f, 0.0f, 0.0f}, + {3.0f, 1.0f, 0.0f, 0.0f}, + {3.0f, 2.0f, 1.0f, 0.0f}, + {1.5f, 0.5f, 0.0f, 0.0f}, + {2.5f, 1.5f, 0.5f, 0.0f}, + {2.5f, 0.5f, 0.0f, 0.0f}, + {3.5f, 0.5f, 0.0f, 0.0f}, + {2.0f, 1.0f, 0.0f, 0.0f}, + {2.0f, 0.0f, 0.0f, 0.0f}, + {3.0f, 1.0f, 0.0f, 0.0f}, + {3.0f, 2.0f, 1.0f, 0.0f}, + {4.0f, 0.0f, 0.0f, 0.0f}, + {1.5f, 0.5f, 0.0f, 0.0f}, + {2.5f, 1.5f, 0.5f, 0.0f}, + {2.5f, 1.5f, 0.5f, 0.0f}, + {3.5f, 1.5f, 0.5f, 0.0f}, + {2.0f, 1.0f, 0.0f, 0.0f}, + {3.0f, 2.0f, 1.0f, 0.0f}, + {3.0f, 2.0f, 1.0f, 0.0f}, + {3.0f, 0.0f, 0.0f, 0.0f}, + {4.0f, 1.0f, 0.0f, 0.0f}, + {1.5f, 0.0f, 0.0f, 0.0f}, + {2.5f, 1.5f, 0.5f, 0.0f}, + {2.5f, 1.5f, 0.5f, 0.0f}, + {3.5f, 1.5f, 0.5f, 0.0f} +}; + +const int no_vals[NO_LEADERS]= {2,1,2,2,2,2,3,2,1,3,2,2,2,3,3,3,2,3,3,2,3,2,3,2,3,3,4,2,3,2,2,3,2,2,4,2,2,3,3,3,3,4,4,2,3,1,3,3,3}; + +const int no_vals_ind[NO_LEADERS][MAX_NO_VALS]= +{ + {2,6,0,0}, + {8,0,0,0}, + {4,4,0,0}, + {1,7,0,0}, + {1,7,0,0}, + {6,2,0,0}, + {1,2,5,0}, + {2,6,0,0}, + {8,0,0,0}, + {1,4,3,0}, + {2,6,0,0}, + {3,5,0,0}, + {1,7,0,0}, + {1,6,1,0}, + {2,2,4,0}, + {1,1,6,0}, + {4,4,0,0}, + {1,1,6,0}, + {2,4,2,0}, + {3,5,0,0}, + {1,3,4,0}, + {5,3,0,0}, + {1,2,5,0}, + {2,6,0,0}, + {3,2,3,0}, + {1,5,2,0}, + {1,1,1,5}, + {6,2,0,0}, + {1,3,4,0}, + {2,6,0,0}, + {1,7,0,0}, + {3,4,1,0}, + {4,4,0,0}, + {1,7,0,0}, + {1,1,3,3}, + {1,7,0,0}, + {7,1,0,0}, + {1,4,3,0}, + {2,1,5,0}, + {1,1,6,0}, + {4,2,2,0}, + {1,1,5,1}, + {1,2,1,4}, + {2,6,0,0}, + {1,2,5,0}, + {8,0,0,0}, + {1,5,2,0}, + {2,2,4,0}, + {1,2,5,0} +}; + +const int C_VQ[LATTICE_DIM+1][LATTICE_DIM+1]= +{ + {1,0,0,0,0,0,0,0,0}, + {1,1,0,0,0,0,0,0,0}, + {1,2,1,0,0,0,0,0,0}, + {1,3,3,1,0,0,0,0,0}, + {1,4,6,4,1,0,0,0,0}, + {1,5,10,10,5,1,0,0,0}, + {1,6,15,20,15,6,1,0,0}, + {1,7,21,35,35,21,7,1,0}, + {1,8,28,56,70,56,28,8,1} +}; + +const unsigned int table_no_cv[] = { 0, 112, 240, 1360, 1376, 2400, 4192, 5536, 9120, 9376, 18336, 18448, 25616, 26640, 33808, 40528, 40752, + 49712, 56880, 83760, 84208, 88688, 95856, 117360, 124528, 142448, 153200, 155888, 159472, 195312, 198896, 199920, + 235760, 236880, 238928, 274768, 274784, 275808, 311648, 333152, 340320, 367200, 410208, 423648,423760, 425104, 425232, 446736, 500496, 522000 + ,0 + }; + +const int pi0[] = {28,1,70,8,8,28,168,28,1,280,28,56,8,56,420,56, 70, 56,420, 56, 280, 56, 168, 28, 560, 168,336,28,280,28,8 + ,280,70, 8, 1120, 8, 8, 280, 168, 56, 420, 336, 840, 28, 168, 1, 168, 420, 168 + }; + +const float pl_HQ[] = /* vectors in first layers */ +{ + 1, 1, 0, 0, 0, 0, 0, 0, /* 112, 4, 28 */ + 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, /* 128, 128, 1 */ + 1, 1, 1, 1, 0, 0, 0, 0, /* 1120, 16, 70 */ + 2, 0, 0, 0, 0, 0, 0, 0, /* 16 , 2, 8 */ + 1.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, /* 5 */ /* 1024,128, 8 */ + 1, 1, 1, 1, 1, 1, 0, 0, /* 1792, 64, 28 */ + 2, 1, 1, 0, 0, 0, 0, 0, /* 1344, 8, 168 */ + 1.5, 1.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, /* 3584, 128, 28*/ + 1, 1, 1, 1, 1, 1, 1, 1, /*256, 256, 1*/ + 2, 1, 1, 1, 1, 0, 0, 0, /* 10 */ /* 8960, 32, 280 */ + 2, 2, 0, 0, 0, 0, 0, 0, /* 112, 4, 28 */ + 1.5, 1.5, 1.5, 0.5, 0.5, 0.5, 0.5, 0.5, /* 7168, 128, 56 */ + 2.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, /* 1024, 128, 8*/ + 2, 1, 1, 1, 1, 1, 1, 0, /* 7168, 128, 56*/ + 2, 2, 1, 1, 0, 0, 0, 0, /* 15 */ /* 6720, 16, 420 */ + 3, 1, 0, 0, 0, 0, 0, 0, /* 224, 4, 56 */ + 1.5, 1.5, 1.5, 1.5, 0.5, 0.5, 0.5, 0.5, /* 8960, 128, 70 */ + 2.5, 1.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, /* 7168, 128, 56*/ + 2.0, 2.0, 1.0, 1.0, 1.0, 1.0, 0, 0, /* 26880, 64, 420 */ + 2, 2, 2, 0, 0, 0, 0, 0, /*20 */ /* 448, 8, 56 */ + 3, 1, 1, 1, 0, 0, 0, 0, /* 4480, 16, 280 */ + 1.5, 1.5, 1.5, 1.5, 1.5, 0.5, 0.5, 0.5, /* 7168, 128, 56 */ + 2.5, 1.5, 1.5, 0.5, 0.5, 0.5, 0.5, 0.5, /* 21504, 128, 168 */ + 2.0, 2.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, /* 7168, 256, 28 */ + 2.0, 2.0, 2.0, 1.0, 1.0, 0, 0, 0, /* 25 */ /* 17920, 32, 560 */ + 3.0, 1.0, 1.0, 1.0, 1.0, 1.0, 0, 0, /* 10752, 64, 168 */ + 3.0, 2.0, 1.0, 0, 0, 0, 0, 0, /* 2688, 8, 336 */ + 1.5, 1.5, 1.5, 1.5, 1.5, 1.5, 0.5, 0.5, /* 3584, 128, 28 */ + 2.5, 1.5, 1.5, 1.5, 0.5, 0.5, 0.5, 0.5, /* 35840,128,280*/ + 2.5, 2.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, /*30 */ /* 3584, 128, 28*/ + 3.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, /* 1024,128, 8 */ + 2.0, 2.0, 2.0, 1.0, 1.0, 1.0, 1.0, 0, + 2.0f, 2.0f, 2.0f, 2.0f, 0.0f, 0.0f, 0.0f, 0.0f, + 3.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, + 3.0f, 2.0f, 1.0f, 1.0f, 1.0f, 0.0f, 0.0f, 0.0f, + 4.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, + 1.5f, 1.5f, 1.5f, 1.5f, 1.5f, 1.5f, 1.5f, 0.5f, + 2.5f, 1.5f, 1.5f, 1.5f, 1.5f, 0.5f, 0.5f, 0.5f, + 2.5f, 2.5f, 1.5f, 0.5f, 0.5f, 0.5f, 0.5f, 0.5f, + 3.5f, 1.5f, 0.5f, 0.5f, 0.5f, 0.5f, 0.5f, 0.5f, + 2.0f, 2.0f, 2.0f, 2.0f, 1.0f, 1.0f, 0.0f, 0.0f, + 3.0f, 2.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 0.0f, + 3.0f, 2.0f, 2.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, + 3.0f, 3.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, + 4.0f, 1.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, + 1.5f, 1.5f, 1.5f, 1.5f, 1.5f, 1.5f, 1.5f, 1.5f, + 2.5f, 1.5f, 1.5f, 1.5f, 1.5f, 1.5f, 0.5f, 0.5f, + 2.5f, 2.5f, 1.5f, 1.5f, 0.5f, 0.5f, 0.5f, 0.5f, + 3.5f, 1.5f, 1.5f, 0.5f, 0.5f, 0.5f, 0.5f, 0.5f +}; + +/*----------------------------------------------------------------------------------* + * LSF quantization for CNG + *----------------------------------------------------------------------------------*/ + +const short cng_sort[] = {/*5f */1,1,0,1,0,0, /* 4f */0,1,0,1,0,0,1,1,1,1}; + +const short perm_MSLVQ[][4] = +{ + /* 5f*/ + {6,11,7,15}, + {6,15,-1,0}, + {5,8,7,15}, + {7,10,-1,0}, + {-1,0,0,0}, + {-1,0,0,0}, + /* 4f */ + {-1,0,0,0}, + {0,9,7,10}, + {-1,0,0,0}, + {7,15,-1,0}, + {-1,0,0,0}, + {-1,0,0,0}, + {6,10,7,11}, + {6,11,7,12}, + {6,11,7,12}, + {6,11,7,12} +}; + +const int pl_par[] = /* 1 if even number of signs */ +{ + 0, 1, 0, 0, -1, 0, 0, 1, 0, 0, + 0, -1, 1, 0, 0, 0, 1, -1, 0, 0, + 0, -1, 1, 0, 0, 0, 0, 1, -1, 1, -1, 0, + 0, 0, 0, 0, -1, 1, -1, 1, 0, 0, 0, 0, 0, 1, -1, 1, -1 +}; + +const float scales[][MAX_NO_SCALES*2]= /* 2 subvectors */ +{ + {1.528f, 0.000f, 0.000f, 1.532f, 0.000f, 0.000f, }, /* 14 */ + {1.605f, 0.000f, 0.000f, 1.532f, 0.000f, 0.000f, }, /* 15 */ + {1.275f, 2.458f, 0.000f, 1.532f, 0.000f, 0.000f, }, /* 18 */ + {1.275f, 2.458f, 0.000f, 1.631f, 0.000f, 0.000f, }, /* 19 */ + {1.057f, 1.794f, 2.896f, 1.154f, 1.860f, 3.067f, }, /* 25 */ + {0.927f, 1.458f, 2.317f, 1.033f, 1.791f, 3.440f, }, /* 28*/ /* mode 0 UV WB*/ + {1.284f, 2.676f, 0.000f, 1.451f, 0.000f, 0.000f, }, + {1.368f, 0.000f, 0.000f, 1.401f, 2.477f, 0.000f, }, /* 19 */ + {0.861f, 1.243f, 1.818f, 1.228f, 2.226f, 10.307f, }, /* 24 */ + {1.072f, 1.934f, 3.633f, 1.221f, 2.938f, 10.723f, }, /* 25 */ + {0.899f, 1.417f, 0.677f, 1.033f, 1.837f, 10.893f, }, /* 29 */ + {0.830f, 1.323f, 0.629f, 0.911f, 1.585f, 10.088f, }, /* 32 */ /* mode 1 UV NB*/ + {1.573f, 0.000f, 0.000f, 1.656f, 0.000f, 0.000f, }, /* 17 */ + {1.239f, 2.404f, 0.000f, 1.556f, 0.000f, 0.000f, }, /* 18 */ + {1.055f, 1.700f, 4.439f, 1.656f, 0.000f, 0.000f, }, /* 21 */ + {1.250f, 2.404f, 4.132f, 1.355f, 2.361f, 0.000f, }, /* 22 */ + {1.056f, 1.785f, 4.523f, 1.318f, 2.586f, 0.000f, }, /* 25 */ + {0.996f, 1.505f, 3.355f, 1.185f, 1.776f, 2.728f, }, + {0.929f, 1.387f, 3.357f, 1.080f, 1.701f, 2.885f, }, + {0.922f, 1.493f, 3.369f, 1.080f, 1.701f, 2.885f, }, + {0.922f, 1.493f, 3.369f, 1.066f, 1.694f, 3.135f, }, + {0.922f, 1.493f, 3.369f, 0.962f, 1.550f, 3.946f, }, /* 30 */ + {0.746f, 1.108f, 2.869f, 0.959f, 1.481f, 3.907f, }, /* 32 */ + {0.770f, 1.194f, 2.823f, 0.907f, 1.402f, 2.116f, }, + {0.748f, 1.103f, 2.866f, 1.182f, 0.811f, 3.332f, },/* 34*/ + {0.677f, 0.963f, 2.127f, 0.726f, 1.082f, 2.204f, }, /* 37*/ /* mode 2 V WB*/ + {1.639f, 0.000f, 0.000f, 1.218f, 2.161f, 0.000f, }, /* 17 */ + {1.286f, 2.446f, 0.000f, 1.410f, 0.000f, 0.000f, }, /* 18 */ + {1.086f, 1.728f, 3.758f, 1.218f, 2.161f, 0.000f, }, /* 22 */ + {1.035f, 1.575f, 4.815f, 1.218f, 2.161f, 0.000f, }, /* 23 */ + {0.964f, 1.533f, 4.942f, 1.218f, 2.161f, 0.000f, }, /* 24 */ + {0.841f, 1.198f, 1.982f, 1.218f, 2.161f, 0.000f, }, /* 25 */ + {0.898f, 1.298f, 2.184f, 1.216f, 2.664f, 0.000f, }, /* 27 */ + {0.841f, 1.237f, 2.237f, 0.995f, 1.657f, 2.836f, }, /* 29 */ + {0.697f, 0.981f, 2.043f, 0.935f, 1.505f, 0.659f, }, /* 34 */ + {0.669f, 0.909f, 1.328f, 0.985f, 0.654f, 1.911f, }, /* 37 */ /* mode 3 V NB*/ + {1.212f, 1.897f, 0.000f, 0.000f, 0.000f, 0.000f, }, /* 12 (11.883) */ + {1.634f, 0.000f, 0.000f, 1.669f, 0.000f, 0.000f, }, /* 16 (15.826) */ + {1.288f, 2.423f, 0.000f, 1.669f, 0.000f, 0.000f, }, /* 19 (18.572) */ + {1.212f, 1.897f, 0.000f, 1.669f, 0.000f, 0.000f, }, /* 20 (19.796) */ + {1.083f, 1.766f, 3.175f, 1.669f, 0.000f, 0.000f, }, /* 21 (20.910) */ + {1.037f, 1.609f, 4.228f, 1.669f, 0.000f, 0.000f, }, /* 22 (21.776) */ + {1.095f, 1.659f, 2.716f, 1.315f, 2.506f, 0.000f, }, /* 23 (22.959) */ + {0.941f, 1.386f, 2.221f, 1.315f, 2.506f, 0.000f, }, /* 25 (24.992) */ + {0.908f, 1.306f, 1.901f, 1.320f, 2.623f, 0.000f, }, /* 26 (25.904) */ + {1.075f, 1.767f, 0.790f, 1.320f, 2.623f, 0.000f, }, /* 27 (26.829) */ + {1.022f, 1.531f, 0.759f, 1.110f, 1.755f, 2.594f, }, /* 28 (27.989) */ + {1.075f, 1.767f, 0.790f, 1.093f, 1.902f, 3.014f, }, /* 29 (28.984) */ + {0.893f, 1.472f, 0.675f, 1.103f, 1.770f, 2.842f, }, /* 30 (29.980) */ + {0.910f, 1.548f, 0.685f, 1.032f, 1.651f, 2.513f, }, /* 31 (30.966) */ + {0.826f, 1.256f, 0.632f, 0.981f, 1.542f, 2.217f, }, /* 32 (31.995) */ /* G WB*/ + {1.184f, 1.810f, 2.761f, 0.000f, 0.000f, 0.000f, }, /* 12 (11.925) */ + {1.611f, 0.000f, 0.000f, 1.618f, 0.000f, 0.000f, }, /* 16 (15.826) */ + {1.184f, 1.810f, 2.761f, 1.550f, 0.000f, 0.000f, }, /* 19 (18.745) */ + {1.184f, 1.810f, 2.761f, 1.618f, 0.000f, 0.000f, }, /* 20 (19.838) */ + {1.063f, 1.737f, 2.985f, 1.618f, 0.000f, 0.000f, }, /* 21 (20.910) */ + {1.078f, 1.825f, 3.162f, 1.469f, 2.249f, 0.000f, }, /* 22 (21.985) */ + {1.375f, 0.915f, 2.082f, 1.469f, 2.249f, 0.000f, }, /* 23 (22.815) */ + {0.960f, 1.423f, 0.700f, 1.310f, 2.132f, 0.000f, }, /* 25 (24.996) */ + {1.124f, 0.794f, 1.902f, 1.283f, 2.302f, 0.000f, }, /* 26 (25.993) */ + {1.077f, 1.727f, 0.767f, 1.250f, 1.951f, 2.981f, }, /* 27 (26.954) */ + {0.933f, 1.471f, 0.685f, 1.250f, 1.951f, 2.981f, }, /* 28 (27.992) */ + {0.927f, 1.600f, 0.674f, 1.154f, 1.776f, 2.854f, }, /* 29 (28.996) */ + {1.047f, 0.722f, 1.785f, 1.056f, 1.642f, 2.701f, }, /* 30 (29.988) */ + {0.971f, 0.688f, 1.509f, 1.043f, 1.730f, 2.931f, }, /* 31 (30.962) */ + {0.919f, 0.662f, 1.367f, 1.057f, 1.808f, 3.069f, }, /* 32 (31.987) */ /* G NB*/ + + {1.617f, 0.000f, 0.000f, 1.657f, 0.000f, 0.000f, }, /* 17 */ + {1.275f, 2.298f, 0.000f, 1.563f, 0.000f, 0.000f, }, /* 18 */ + {1.308f, 2.354f, 0.000f, 1.387f, 0.000f, 0.000f, }, /* 21 */ + {1.291f, 2.418f, 0.000f, 1.355f, 2.443f, 0.000f, }, /* 22 */ + {1.079f, 1.769f, 3.012f, 1.387f, 0.000f, 0.000f, }, /* 24 */ + {1.079f, 1.769f, 3.012f, 1.325f, 2.555f, 0.000f, }, /* 25 */ + {0.897f, 1.340f, 2.604f, 1.070f, 1.689f, 2.527f, }, /* 28 */ + {0.897f, 1.340f, 2.604f, 0.939f, 1.454f, 2.083f, }, /* 30 */ + {0.905f, 1.327f, 2.599f, 1.109f, 0.777f, 1.705f, }, + {0.762f, 1.101f, 2.359f, 0.939f, 1.454f, 2.083f, }, + {0.794f, 1.226f, 3.180f, 1.109f, 0.777f, 1.705f, }, /* 33 */ /* mode 6 T WB */ + {1.629f, 0.000f, 0.000f, 1.191f, 2.211f, 0.000f, }, /* 17 */ + {1.277f, 2.557f, 0.000f, 1.367f, 0.000f, 0.000f, }, /* 18 */ + {1.082f, 1.761f, 3.929f, 1.191f, 2.211f, 0.000f, }, /* 22 */ + {1.018f, 1.535f, 2.808f, 1.191f, 2.211f, 0.000f, }, /* 23 */ + {0.944f, 1.477f, 2.763f, 1.191f, 2.211f, 0.000f, }, /* 24 */ + {0.910f, 1.744f, 3.317f, 1.191f, 2.211f, 0.000f, }, /* 25 */ + {0.920f, 1.648f, 3.068f, 0.969f, 1.683f, 3.953f, }, /* 28 */ + {0.739f, 1.111f, 2.694f, 0.879f, 1.411f, 2.305f, }, /* 31 */ + {0.709f, 1.032f, 2.717f, 0.810f, 1.245f, 1.824f, }, /* 32*/ /* mode 7 T NB*/ + {0.758f, 1.116f, 1.964f, 2.021f, 0.798f, 1.219f, }, /* 31 */ + {0.699f, 1.034f, 1.978f, 2.021f, 0.798f, 1.219f, }, /* 32 */ /* mode 8 G 16k */ + {0.726f, 1.050f, 1.845f, 1.355f, 0.860f, 2.205f, }, /* 32 (31.998) */ + {0.677f, 0.997f, 1.669f, 1.355f, 0.860f, 2.205f, }, /* 33 (32.983) */ + {1.646f, 0.000f, 0.000f, 1.254f, 2.459f, 0.000f, }, /* 17 */ + {1.073f, 1.863f, 3.231f, 1.678f, 0.000f, 0.000f, }, /* 21 */ + {1.073f, 1.863f, 3.231f, 1.254f, 2.459f, 0.000f, }, /* 22 */ + {0.951f, 1.492f, 2.496f, 1.255f, 2.971f, 0.000f, }, /* 25 */ + {1.148f, 1.841f, 0.813f, 1.255f, 2.971f, 0.000f, }, /* 26 */ + {0.602f, 0.869f, 1.418f, 1.264f, 0.764f, 2.218f}, /* 36 */ /* mode 10 AUDIO_WB LVQ bitrate 15-36 + 4 + 1*/ + {0.853f, 1.769f, 4.425f, 1.000f, 1.000f, 1.000f}, /* 17 */ + {1.011f, 1.663f, 4.403f, 1.578f, 0.000f, 0.000f}, /* 21 */ + {1.011f, 1.663f, 4.403f, 1.202f, 2.424f, 0.000f}, /* 22 */ + {0.881f, 1.618f, 4.136f, 1.202f, 2.424f, 0.000f}, /* 25 */ + {0.847f, 1.791f, 4.466f, 1.202f, 2.424f, 0.000f}, /* 26 */ + {0.670f, 1.112f, 2.389f, 1.202f, 2.424f, 0.000f}, /* 28 */ /* mode 11 AUDIO_NB */ + {1.131f, 1.815f, 0.796f, 1.265f, 2.794f, 0.000f, }, /* 26 */ + {0.570f, 0.804f, 1.197f, 1.162f, 1.949f, 0.728f, }, /* 36*/ /* mode 12 AUDIO_WB 16k bitrate 15-36 + 4 + 1*/ + {1.045f, 1.586f, 3.754f, 1.669f, 0.000f, 0.000f, }, /* 22 (21.776) */ + {0.880f, 1.280f, 2.824f, 1.099f, 1.735f, 0.000f, }, /* 28 (27.994) */ + {0.831f, 1.215f, 2.927f, 1.089f, 1.708f, 2.479f, }, /* 29 (28.996) */ + {0.870f, 1.327f, 2.906f, 1.066f, 1.719f, 2.676f, }, /* 30 (29.991) */ + {0.772f, 1.122f, 2.351f, 1.446f, 0.944f, 2.072f, }, /* 32 (31.992) */ + {0.701f, 0.977f, 1.738f, 0.947f, 1.453f, 2.082f, }, /* 33 (32.993) */ + {0.719f, 1.021f, 1.701f, 1.119f, 0.794f, 1.696f, }, /* 34 (33.968) */ + {0.640f, 0.884f, 1.732f, 0.755f, 1.090f, 1.548f, }, /* 37 (36.995) */ /* VOICED 16k */ + /* 5sf */ + {1.218f, 0.796f, 2.283f, 1.290f, 3.325f, 0.000f, }, /* 25 (24.980) */ + {1.590f, 0.835f, 4.436f, 1.097f, 3.070f, 0.000f, }, /* 25 (24.974) */ + {0.994f, 2.617f, 0.000f, 1.091f, 2.233f, 3.457f, }, /* 25 (24.852) */ + {0.887f, 1.573f, 3.543f, 1.088f, 1.827f, 3.067f, }, /* 25 (24.994) */ + {0.837f, 1.238f, 1.903f, 1.298f, 2.797f, 0.000f, }, /* 25 (24.996) */ + {1.138f, 2.826f, 0.000f, 1.106f, 2.796f, 4.391f, }, /* 25 (24.671) */ + + /* 4sf */ + {0.941f, 1.931f, 4.473f, 0.681f, 1.266f, 2.328f, }, /* 25 (24.936) */ + {1.352f, 4.332f, 0.000f, 0.820f, 1.545f, 4.175f, }, /* 25 (24.955) */ + {1.343f, 3.607f, 0.000f, 0.859f, 1.453f, 2.590f, }, /* 25 (24.853) */ + {1.208f, 2.740f, 0.000f, 0.759f, 1.240f, 2.182f, }, /* 25 (24.881) */ + {1.123f, 2.736f, 0.000f, 0.874f, 1.498f, 2.586f, }, /* 25 (24.939) */ + {0.919f, 2.471f, 0.000f, 0.615f, 1.072f, 2.096f, }, /* 25 (24.996) */ + {1.548f, 4.508f, 0.000f, 0.825f, 2.178f, 4.305f, }, /* 25 (24.310) */ + {1.217f, 2.898f, 0.000f, 0.737f, 1.217f, 1.930f, }, /* 25 (24.955) */ + {0.976f, 2.190f, 5.716f, 1.506f, 0.642f, 4.211f, }, /* 25 (24.984) */ + {1.107f, 2.595f, 0.000f, 1.302f, 0.604f, 0.880f, }, /* 25 (24.866) */ +}; + +const float scales_p[][MAX_NO_SCALES*2]= /* 2 subvectors 20 modes */ +{ + {1.464f, 2.374f, 0.000f, 0.000f, 0.000f, 0.000f, }, /* 9 (8.464) */ + {1.265f, 2.564f, 0.000f, 1.638f, 0.000f, 0.000f, }, /* 19 (18.572) */ + {1.063f, 1.703f, 2.805f, 1.294f, 2.353f, 0.000f, }, /* 23 (22.959) */ + {1.063f, 1.917f, 3.063f, 1.365f, 0.000f, 0.000f, }, /* 24 (23.949) */ + {0.914f, 1.412f, 2.223f, 1.294f, 2.353f, 0.000f, }, /* 25 (24.992) */ + {0.882f, 1.401f, 2.402f, 1.313f, 2.441f, 0.000f, }, /* 27 (26.902) */ + {1.356f, 0.867f, 2.377f, 1.070f, 1.686f, 2.546f, }, /* 28 (27.996) */ + {0.846f, 1.348f, 2.546f, 1.076f, 1.742f, 2.658f, }, /* 29 (28.937) */ + {0.845f, 1.379f, 2.566f, 1.019f, 1.577f, 2.443f, }, /* 30 (29.954) */ + {0.756f, 1.189f, 2.799f, 1.084f, 1.804f, 2.758f, }, /* 31 (30.978) */ + {0.755f, 1.218f, 2.821f, 0.944f, 1.433f, 1.973f, }, /* 32 (31.978) */ + {0.724f, 1.235f, 2.942f, 1.255f, 0.848f, 2.000f, }, /* 34 (33.975) */ + {0.687f, 1.113f, 2.338f, 0.853f, 1.328f, 1.944f, }, /* 35 (34.975) */ + {0.648f, 1.029f, 1.836f, 0.854f, 1.356f, 1.961f, }, /* 36 (35.889) */ + {0.648f, 1.029f, 1.836f, 0.687f, 1.058f, 1.900f, }, /* 39 (38.488) */ /* V WB*/ + {1.613f, 0.000f, 0.000f, 0.000f, 0.000f, 0.000f, }, /* 8 (7.913) */ + {1.267f, 2.475f, 0.000f, 1.619f, 0.000f, 0.000f, }, /* 19 (18.572) */ + {1.014f, 1.630f, 2.464f, 1.285f, 2.151f, 0.000f, }, /* 23 (22.773) */ + {0.893f, 1.390f, 2.314f, 1.465f, 2.299f, 0.000f, }, /* 24 (23.999) */ + {0.930f, 1.401f, 2.150f, 1.280f, 2.254f, 0.000f, }, /* 25 (24.992) */ + {0.893f, 1.390f, 2.314f, 1.276f, 2.206f, 2.984f, }, /* 27 (26.962) */ + {0.893f, 1.390f, 2.314f, 1.036f, 1.646f, 2.471f, }, /* 28 (27.835) */ + {0.857f, 1.337f, 2.464f, 1.043f, 1.730f, 2.625f, }, /* 29 (28.937) */ + {0.765f, 1.219f, 1.553f, 1.036f, 1.646f, 2.471f, }, /* 30 (29.969) */ + {0.789f, 1.328f, 1.652f, 1.052f, 1.784f, 2.706f, }, /* 31 (30.952) */ + {0.764f, 1.224f, 1.555f, 0.920f, 1.443f, 2.035f, }, /* 32 (31.978) */ + {0.663f, 1.061f, 1.238f, 1.379f, 0.898f, 1.951f, }, /* 34 (33.992) */ + {0.673f, 1.104f, 1.306f, 1.259f, 0.828f, 1.954f, }, /* 35 (35.000) */ + {0.666f, 1.071f, 1.249f, 0.803f, 1.241f, 1.729f, }, /* 36 (35.980) */ + {0.658f, 1.039f, 1.214f, 0.950f, 0.651f, 1.429f, }, /* 39 (38.512) */ /* V NB*/ + + {1.600f, 0.000f, 0.000f, 1.553f, 0.000f, 0.000f, }, /* 15 (14.733) */ + {1.134f, 1.986f, 3.295f, 1.553f, 0.000f, 0.000f, }, /* 19 (18.745) */ + {0.987f, 1.788f, 2.659f, 1.647f, 0.000f, 0.000f, }, /* 22 (21.776) */ + {0.899f, 1.602f, 2.579f, 1.647f, 0.000f, 0.000f, }, /* 23 (22.791) */ + {0.797f, 1.294f, 2.140f, 1.647f, 0.000f, 0.000f, }, /* 24 (23.999) */ + {0.797f, 1.294f, 2.140f, 1.335f, 2.225f, 0.000f, }, /* 25 (24.996) */ + {0.741f, 1.151f, 1.816f, 1.335f, 2.225f, 0.000f, }, /* 26 (25.934) */ + {0.797f, 1.294f, 2.140f, 1.186f, 1.932f, 0.000f, }, /* 28 (27.969) */ + {0.741f, 1.151f, 1.816f, 1.164f, 1.823f, 2.769f, }, /* 29 (28.996) */ + {0.708f, 1.126f, 1.953f, 1.076f, 1.730f, 2.777f, }, /* 30 (29.988) */ + {0.660f, 1.049f, 1.571f, 1.076f, 1.730f, 2.777f, }, /* 31 (30.931) */ + {0.662f, 1.026f, 1.554f, 1.074f, 1.913f, 3.022f, }, /* 32 (31.987) */ + {0.660f, 1.049f, 1.571f, 1.439f, 0.926f, 2.131f, }, /* 33 (32.982) */ + {0.630f, 0.966f, 1.522f, 1.312f, 0.881f, 2.207f, }, /* 34 (33.967) */ + {0.617f, 0.921f, 1.447f, 1.032f, 1.549f, 0.756f, }, /* 35 (34.994) */ /* G WB*/ + + {1.595f, 0.000f, 0.000f, 1.502f, 0.000f, 0.000f, }, /* 15 (14.733) */ + {1.123f, 1.946f, 3.732f, 1.502f, 0.000f, 0.000f, }, /* 19 (18.792) */ + {1.033f, 2.075f, 4.339f, 1.419f, 2.446f, 0.000f, }, /* 22 (21.985) */ + {0.985f, 1.793f, 5.965f, 1.281f, 2.324f, 0.000f, }, /* 23 (22.773) */ + {0.881f, 1.606f, 6.995f, 1.419f, 2.446f, 0.000f, }, /* 24 (23.932) */ + {0.844f, 1.582f, 7.020f, 1.281f, 2.324f, 0.000f, }, /* 25 (24.955) */ + {0.789f, 1.520f, 7.203f, 1.281f, 2.324f, 0.000f, }, /* 26 (25.991) */ + {0.869f, 1.547f, 6.995f, 1.030f, 1.754f, 3.102f, }, /* 28 (27.979) */ + {0.817f, 1.492f, 7.120f, 1.030f, 1.754f, 3.102f, }, /* 29 (28.878) */ + {0.755f, 1.382f, 7.133f, 1.030f, 1.754f, 3.102f, }, /* 30 (29.954) */ + {0.706f, 1.315f, 7.225f, 1.030f, 1.754f, 3.102f, }, /* 31 (30.893) */ + {0.689f, 1.296f, 7.290f, 1.016f, 1.875f, 3.239f, }, /* 32 (31.963) */ + {0.698f, 1.275f, 7.209f, 0.914f, 1.548f, 2.433f, }, /* 33 (32.997) */ + {0.679f, 1.315f, 7.290f, 1.229f, 1.845f, 0.813f, }, /* 34 (33.986) */ + {0.679f, 1.315f, 7.290f, 1.188f, 0.772f, 1.955f, }, /* 35 (34.952) */ /* G NB*/ + + + {1.011f, 1.777f, 2.760f, 1.614f, 0.000f, 0.000f, }, /* 21 */ + {0.853f, 1.382f, 2.066f, 1.245f, 2.679f, 0.000f, }, /* 25 */ + { 1.207f, 0.778f, 2.208f, 1.245f, 2.679f, 0.000f, }, /* 26 */ + { 1.207f, 0.778f, 2.208f, 1.013f, 1.832f, 3.053f, }, /* 29 */ + {1.207f, 0.778f, 2.208f, 1.420f, 0.872f, 2.330f, }, /* 30 */ + {0.525f, 0.770f, 1.073f, 0.815f, 1.237f, 0.567f,}, /* 40 */ /* mode 7 AUDIO_WB 19-40 + 0 + 1 */ + {1.070f, 1.791f, 3.903f, 1.599f, 0.000f, 0.000f}, /* 21 */ + {0.820f, 1.217f, 2.089f, 1.255f, 2.290f, 0.000f}, /* 25 */ + {0.780f, 1.169f, 2.495f, 1.255f, 2.290f, 0.000f}, /* 26 */ + {1.075f, 0.723f, 2.361f, 1.110f, 1.961f, 3.491f}, /* 30 */ + {0.691f, 1.029f, 2.337f, 1.034f, 1.791f, 4.004f}, /* 31 */ + {0.671f, 1.076f, 2.606f, 0.955f, 1.547f, 2.514f}, /* 32 */ /*mode 8 AUDIO_NB */ + {1.184f, 0.776f, 2.117f, 1.057f, 1.670f, 0.674f,}, /* 30 */ + {0.521f, 0.747f, 1.033f, 0.796f, 1.333f, 0.542f,}, /* 40 */ /* mode 9 AUDIO_WB 16k 19-40+ 0 + 1*/ + {1.679f, 0.000f, 0.000f, 1.282f, 2.471f, 0.000f, }, /* 17 (16.823) */ + {1.088f, 1.849f, 3.195f, 1.687f, 0.000f, 0.000f, }, /* 21 (20.910) */ + {1.088f, 1.849f, 3.195f, 1.282f, 2.471f, 0.000f, }, /* 22 (21.907) */ + {1.126f, 1.689f, 0.790f, 1.282f, 2.471f, 0.000f, }, /* 25 (24.863) */ + {0.930f, 1.382f, 0.682f, 1.282f, 2.471f, 0.000f, }, /* 26 (25.921) */ + {1.115f, 0.794f, 1.852f, 1.281f, 3.033f, 0.000f, }, /* 27 (26.837) */ + {0.840f, 1.376f, 0.623f, 0.800f, 1.416f, 4.260f, }, /* 36 (35.998) */ /* INACTIVE NB */ + + {0.801f, 1.148f, 1.802f, 0.000f, 0.000f, 0.000f, }, /* 17 (16.932) */ + {1.089f, 1.812f, 3.172f, 1.677f, 0.000f, 0.000f, }, /* 21 (20.910) */ + {1.089f, 1.904f, 3.221f, 1.521f, 2.635f, 0.000f, }, /* 22 (21.985) */ + {0.845f, 1.212f, 1.934f, 1.313f, 2.419f, 0.000f, }, /* 25 (24.845) */ + {0.779f, 1.095f, 1.700f, 1.313f, 2.419f, 0.000f, }, /* 26 (25.999) */ + {0.723f, 1.015f, 1.664f, 1.313f, 2.419f, 0.000f, }, /* 27 (26.981) */ + {0.893f, 0.652f, 1.438f, 1.076f, 0.720f, 1.794f, }, /* 36 (35.929) */ /* INACTIVE WB*/ + + {1.359f, 2.306f, 0.000f, 1.669f, 0.000f, 0.000f, }, /* 17 (16.823) */ + {1.077f, 1.927f, 3.546f, 1.669f, 0.000f, 0.000f, }, /* 21 (20.910) */ + {1.077f, 2.032f, 3.578f, 1.429f, 2.711f, 0.000f, }, /* 22 (21.985) */ + {0.833f, 1.253f, 2.105f, 1.283f, 2.556f, 0.000f, }, /* 25 (24.845) */ + {0.776f, 1.152f, 1.858f, 1.283f, 2.556f, 0.000f, }, /* 26 (25.934) */ + {0.719f, 1.066f, 1.732f, 1.283f, 2.556f, 0.000f, }, /* 27 (26.914) */ + {0.941f, 0.651f, 1.565f, 0.722f, 1.190f, 1.940f, }, /* 36 (35.915) */ /* INACTIVE 16k*/ + + {1.292f, 2.479f, 0.000f, 1.541f, 0.000f, 0.000f, }, /* 18 (17.479) */ + {1.202f, 1.903f, 0.000f, 1.541f, 0.000f, 0.000f, }, /* 19 (18.703) */ + {1.028f, 1.641f, 2.455f, 1.648f, 0.000f, 0.000f, }, /* 22 (21.776) */ + {1.247f, 0.878f, 2.329f, 1.648f, 0.000f, 0.000f, }, /* 23 (22.791) */ + {0.863f, 1.358f, 2.522f, 1.648f, 0.000f, 0.000f, }, /* 24 (23.999) */ + {0.817f, 1.222f, 2.010f, 1.074f, 1.785f, 2.733f, }, /* 29 (28.966) */ + {0.815f, 0.612f, 1.281f, 1.055f, 1.724f, 2.952f, }, /* 32 (31.990) */ /* UNVOICED NB */ + {1.545f, 0.000f, 0.000f, 1.548f, 0.000f, 0.000f, }, /* 14 (13.640) */ + {1.640f, 0.000f, 0.000f, 1.548f, 0.000f, 0.000f, }, /* 15 (14.733) */ + {1.287f, 2.749f, 0.000f, 1.548f, 0.000f, 0.000f, }, /* 18 (17.479) */ + {1.287f, 2.749f, 0.000f, 1.654f, 0.000f, 0.000f, }, /* 19 (18.572) */ + {1.190f, 2.026f, 0.000f, 1.654f, 0.000f, 0.000f, }, /* 20 (19.796) */ + {0.931f, 1.458f, 2.450f, 1.294f, 2.742f, 0.000f, }, /* 25 (24.992) */ + {0.877f, 1.396f, 2.737f, 1.081f, 1.816f, 3.360f, }, /* 28 (27.996) */ /* UNVOICED WB*/ + + {1.131f, 1.636f, 0.000f, 1.371f, 0.000f, 0.000f, }, /* 24 (23.818) */ + {0.934f, 1.277f, 0.728f,1.157f, 1.697f, 0.000f, }, /* 30 (29.992) */ + {0.833f, 1.162f, 0.658f,1.151f, 1.687f, 0.000f, }, /* 31 (30.998) */ + {0.751f, 1.032f, 0.598f,1.151f, 1.687f, 0.000f, }, /* 32 (31.987) */ + {0.709f, 1.005f, 0.570f, 1.060f, 1.772f, 2.719f, }, /* 34 (33.994) */ + {0.746f, 1.001f, 0.601f,1.004f, 1.803f, 2.892f, }, /* 35 (35.000) */ + {0.743f, 1.000f, 0.599f,0.936f, 1.861f, 2.874f, }, /* 36 (35.994) */ + {0.775f, 0.614f, 1.037f, 0.796f, 1.304f, 1.905f, }, /* 39 (38.301) */ /* VOICED 16k */ + {0.894f, 1.339f, 2.549f, 1.308f, 2.601f, 0.000f, }, /* 26 (25.917) */ + {0.720f, 1.012f, 1.598f, 1.512f, 0.926f, 2.137f, }, /* 32 (31.980) */ + {0.681f, 0.973f, 1.649f, 1.381f, 0.876f, 2.129f, }, /* 33 (32.990) */ + {0.684f, 0.964f, 1.640f, 1.168f, 1.776f, 0.787f, }, /* 34 (33.974) */ + {0.668f, 0.935f, 1.551f, 1.016f, 1.518f, 0.712f, }, /* 35 (34.989) */ + {0.659f, 0.911f, 1.425f, 1.337f, 0.889f, 0.642f, }, /* 36 (35.988) */ + {0.659f, 0.911f, 1.425f, 0.839f, 1.287f, 0.607f, }, /* 37 (36.989) */ /* GENERIC 16k*/ + {1.633f, 0.000f, 0.000f, 1.687f, 0.000f, 0.000f, }, /* 16 (15.826) */ + {1.076f, 1.790f, 2.942f, 1.687f, 0.000f, 0.000f, }, /* 21 (20.910) */ + {0.834f, 1.229f, 1.890f, 1.687f, 0.000f, 0.000f, }, /* 24 (23.999) */ + {0.938f, 1.404f, 2.153f, 1.306f, 2.630f, 0.000f, }, /* 25 (24.992) */ + {1.340f, 0.886f, 2.320f, 1.306f, 2.630f, 0.000f, }, /* 26 (25.917) */ + {0.833f, 1.250f, 1.908f, 1.306f, 2.630f, 0.000f, }, /* 27 (26.883) */ + {0.833f, 1.213f, 1.873f, 1.125f, 1.839f, 2.819f, }, /* 28 (27.901) */ + {0.765f, 1.162f, 1.690f, 1.024f, 1.738f, 2.838f, }, /* 30 (29.916) */ + {0.725f, 1.050f, 1.791f, 1.480f, 0.922f, 3.104f, }, /* 31 (30.993) */ + {0.712f, 1.012f, 1.549f, 1.494f, 0.903f, 3.364f, }, /* 32 (31.980) */ + {0.659f, 0.927f, 1.357f, 1.494f, 0.903f, 3.364f, }, /* 33 (32.958) */ + {0.822f, 0.614f, 1.288f, 0.910f, 1.509f, 2.255f, }, /* 34 (33.987) */ + {0.841f, 0.624f, 1.278f, 1.161f, 0.762f, 1.808f, }, /* 35 (34.994) */ + {0.838f, 0.622f, 1.266f, 1.080f, 0.711f, 1.710f, }, /* 36 (35.968) */ + {0.832f, 0.619f, 1.275f, 0.938f, 1.430f, 0.644f, }, /* 37 (36.971) */ /* GENERIC 12.8k MA*/ + + {0.884f, 1.349f, 2.570f, 1.314f, 2.609f, 0.000f, }, /* 26 (25.917) */ + {0.711f, 1.018f, 1.615f, 1.482f, 0.921f, 3.431f, }, /* 32 (31.980) */ + {0.679f, 0.974f, 1.659f, 0.948f, 1.549f, 3.448f, }, /* 33 (32.995) */ + {0.831f, 0.618f, 1.481f, 0.933f, 1.514f, 2.310f, }, /* 34 (33.993) */ + {0.816f, 0.610f, 1.402f, 1.426f, 0.877f, 2.265f, }, /* 35 (34.992) */ + {0.787f, 1.257f, 0.596f, 0.859f, 1.447f, 2.431f, }, /* 36 (35.997) */ + {0.787f, 1.257f, 0.596f, 1.106f, 0.735f, 1.659f, }, /* 37 (36.961) */ /* AUDIO 16k */ +}; + +/* An 16-by-34 matrix in Scale = 20.48f */ +const float sigma_MSLVQ[][16] = +{ + { 1.0f }, /* IA NB */ + { 1.0f }, /* UV NB */ + {41.8457031f, 43.9453125f, 62.5976563f, 72.3632813f, 78.7597656f, 82.4707031f, 85.4492188f, 86.5722656f, 86.6210938f, 84.9121094f, 85.2050781f, 105.5664063f, 127.8320313f, 68.6523438f, 25.7324219f, 16.9433594f }, /* V NB */ + {48.9257813f, 50.5859375f, 71.0449219f, 72.4609375f, 74.5117188f, 77.8808594f, 79.5898438f, 80.8105469f, 79.9804688f, 74.5117188f, 70.0683594f, 88.7207031f, 119.1406250f, 102.0019531f, 37.1093750f, 25.0976563f }, /* G NB */ + {48.2421875f, 48.0468750f, 68.7500000f, 76.9531250f, 80.9570313f, 85.1562500f, 89.0625000f, 91.8457031f, 90.4296875f, 85.2050781f, 81.5917969f, 106.2988281f, 133.6425781f, 84.3750000f, 34.7656250f, 26.6113281f }, /* T NB */ + {85.5957031f, 82.9101563f, 99.5605469f, 105.9570313f, 106.6406250f, 106.8847656f, 101.6601563f, 99.5605469f, 97.7050781f, 97.0703125f, 97.1191406f, 117.8710938f, 128.1738281f, 153.9550781f, 33.1542969f, 14.5996094f },/* AU NB*/ + { 1.0f }, + { 1.0f }, /* UV WB*/ + {44.2382813f, 52.1972656f, 85.7910156f, 98.6816406f, 101.7089844f, 107.2753906f, 106.9824219f, 112.0605469f, 118.8476563f, 126.3183594f, 125.4882813f, 126.8554688f, 136.3281250f, 136.7675781f, 146.9726563f, 129.7851563f }, /* V WB */ + {61.8164063f, 69.8730469f, 94.6289063f, 97.0214844f, 96.0449219f, 101.3671875f, 100.5371094f, 104.3945313f, 108.5937500f, 106.9824219f, 107.9101563f, 112.8417969f, 120.7519531f, 120.6542969f, 122.0214844f, 119.6289063f }, /* G WB */ + {56.8847656f, 56.9335938f, 86.7187500f, 100.1953125f, 101.9042969f, 108.5449219f, 113.4765625f, 117.9199219f, 124.1699219f, 122.1679688f, 126.3183594f, 137.4023438f, 153.9550781f, 158.8867188f, 161.9140625f, 155.9570313f }, /* T WB */ + {84.8632813f, 88.6230469f, 112.0605469f, 118.3593750f, 123.3886719f, 121.0937500f, 115.4785156f, 118.7011719f, 118.5058594f, 119.0429688f, 123.9257813f, 127.6855469f, 138.5742188f, 125.2441406f, 118.9941406f, 109.0332031f },/* AU WB */ + { 1.0f }, + { 1.0f }, + {75.2441406f, 84.3261719f, 110.6933594f, 125.0000000f, 134.0332031f, 140.3808594f, 146.6308594f, 159.5214844f, 161.3281250f, 173.9746094f, 186.9628906f, 190.9667969f, 196.2402344f, 181.9335938f, 177.9785156f, 187.2070313f }, /* VO 16k */ + {89.6972656f, 92.9687500f, 122.0703125f, 129.0527344f, 130.4687500f, 128.3691406f, 132.5683594f, 139.2578125f, 137.9882813f, 139.9902344f, 152.8320313f, 157.3730469f, 172.4121094f, 179.4433594f, 147.9980469f, 194.1894531f }, /* G 16k */ + {90.3320313f, 108.3496094f, 118.7500000f, 125.7324219f, 135.7421875f, 137.9882813f, 143.0175781f, 145.1660156f, 145.8007813f, 155.1757813f, 171.2402344f, 176.1230469f, 165.4785156f, 161.3769531f, 148.6816406f, 174.4140625f }, /* T 16k */ + {103.1250000f, 112.3046875f, 142.3339844f, 150.6347656f, 150.0488281f, 145.8496094f, 149.3164063f, 145.8496094f, 153.5156250f, 157.3242188f, 175.0000000f, 170.9960938f, 157.4707031f, 168.1152344f, 156.5917969f, 229.0527344f },/* AU 16k */ + {87.5488281f, 116.4062500f, 102.3925781f, 103.1738281f, 100.8789063f, 95.2636719f, 101.7578125f, 110.5468750f, 122.2167969f, 115.2343750f, 107.2753906f, 108.8378906f, 101.7089844f, 111.5722656f, 111.6699219f, 155.9570313f }, + {160.5957031f, 122.6074219f, 117.4804688f, 129.7363281f, 130.9570313f, 133.8378906f, 139.1601563f, 159.9121094f, 168.0664063f, 161.3281250f, 141.9433594f, 142.1386719f, 132.0312500f, 129.8828125f, 122.9980469f, 160.9863281f }, + {53.2226563f, 105.1757813f, 133.9355469f, 143.3593750f, 158.2031250f, 168.1640625f, 160.5957031f, 164.4042969f, 173.4863281f, 182.0800781f, 170.0683594f, 165.3320313f, 128.1738281f, 96.5332031f, 91.9433594f, 93.7988281f }, + {69.5312500f, 169.0429688f, 118.9453125f, 104.6875000f, 100.7812500f, 98.3398438f, 98.8281250f, 95.9472656f, 97.8027344f, 97.6562500f, 95.8496094f, 99.8046875f, 94.3847656f, 106.5917969f, 117.1386719f, 144.7265625f }, + {136.1816406f, 130.5175781f, 130.9082031f, 133.3007813f, 131.3476563f, 129.1992188f, 133.8867188f, 166.1621094f, 197.0703125f, 281.9824219f, 305.7617188f, 255.8105469f, 392.7734375f, 336.6699219f, 135.2050781f, 96.7773438f }, + {123.0957031f, 119.6777344f, 126.3183594f, 119.5800781f, 117.3339844f, 108.4472656f, 107.9101563f, 112.2070313f, 148.2910156f, 153.9550781f, 127.6367188f, 129.9316406f, 132.5683594f, 149.3164063f, 144.6777344f, 244.6289063f }, + {92.3339844f, 97.5097656f, 94.0917969f, 90.2832031f, 94.1894531f, 95.8007813f, 92.8710938f, 86.4746094f, 83.8867188f, 74.1699219f, 70.8984375f, 69.3847656f, 71.5332031f, 167.2851563f, 71.8750000f, 21.5820313f }, + {44.0429688f, 73.9257813f, 140.6738281f, 121.8750000f, 129.5410156f, 127.3437500f, 115.7226563f, 104.8339844f, 106.2500000f, 110.0097656f, 125.0000000f, 107.5195313f, 85.6445313f, 79.2968750f, 69.9218750f, 55.9570313f }, + {106.4453125f, 99.4140625f, 95.6542969f, 92.7246094f, 94.3359375f, 92.0898438f, 83.6914063f, 84.7167969f, 87.1582031f, 101.6113281f, 91.1621094f, 75.3417969f, 73.0957031f, 71.5332031f, 68.0175781f, 63.7207031f }, + {43.3105469f, 125.5371094f, 107.4707031f, 85.4003906f, 83.1542969f, 80.7617188f, 78.8574219f, 80.0781250f, 80.1269531f, 88.0859375f, 93.2128906f, 81.3964844f, 74.8535156f, 73.0957031f, 65.8203125f, 59.3750000f }, + {149.6093750f, 127.3925781f, 117.1875000f, 111.9628906f, 113.4277344f, 113.8671875f, 107.8125000f, 97.9492188f, 100.7324219f, 113.5253906f, 167.9687500f, 203.4667969f, 154.9804688f, 119.1894531f, 107.1289063f, 104.8828125f }, + {59.5214844f, 86.2792969f, 106.0058594f, 113.7207031f, 134.4726563f, 120.9960938f, 120.4589844f, 100.4882813f, 98.5839844f, 100.0488281f, 132.3730469f, 191.8457031f, 194.7753906f, 77.8320313f, 70.0195313f, 41.9433594f }, + {88.2812500f, 92.3828125f, 92.1386719f, 93.5546875f, 97.6074219f, 92.7734375f, 89.0625000f, 87.2070313f, 88.8671875f, 94.1406250f, 121.5820313f, 121.9238281f, 116.7968750f, 122.1191406f, 164.5996094f, 140.4296875f }, + {86.2792969f, 92.8710938f, 83.5937500f, 86.0839844f, 95.8984375f, 95.2148438f, 90.5273438f, 86.5234375f, 82.1289063f, 81.3964844f, 77.9785156f, 89.4042969f, 143.7011719f, 168.3593750f, 41.5039063f, 27.6855469f }, + {97.1679688f, 101.0253906f, 104.3945313f, 110.4003906f, 108.7890625f, 107.4707031f, 97.8515625f, 92.6757813f, 79.1503906f, 81.6406250f, 77.1972656f, 108.8867188f, 212.2070313f, 198.8281250f, 47.4609375f, 35.3515625f }, + {74.8535156f, 97.3632813f, 100.1464844f, 91.6992188f, 90.3808594f, 89.6484375f, 83.2031250f, 84.0820313f, 81.9335938f, 96.4355469f, 110.9863281f, 92.6757813f, 83.4960938f, 82.1289063f, 77.8808594f, 70.8984375f} +}; + +/* An 16-by-34 matrix in Scale = 20.48f */ +const float inv_sigma_MSLVQ[][16] = +{ + {1.0f }, /* IA NB */ + {1.0f }, /* UV NB */ + {0.0238973f, 0.0227556f, 0.0159750f, 0.0138192f, 0.0126968f, 0.0121255f, 0.0117029f, 0.0115510f, 0.0115445f, 0.0117769f, 0.0117364f, 0.0094727f, 0.0078228f, 0.0145661f, 0.0388615f, 0.0590202f }, /* V NB */ + {0.0204391f, 0.0197683f, 0.0140756f, 0.0138005f, 0.0134207f, 0.0128401f, 0.0125644f, 0.0123746f, 0.0125031f, 0.0134207f, 0.0142718f, 0.0112713f, 0.0083934f, 0.0098037f, 0.0269474f, 0.0398444f }, /* G NB */ + {0.0207287f, 0.0208130f, 0.0145455f, 0.0129949f, 0.0123522f, 0.0117431f, 0.0112281f, 0.0108878f, 0.0110583f, 0.0117364f, 0.0122561f, 0.0094074f, 0.0074826f, 0.0118519f, 0.0287640f, 0.0375780f }, /* T NB */ + {0.0116828f, 0.0120612f, 0.0100441f, 0.0094378f, 0.0093773f, 0.0093559f, 0.0098367f, 0.0100441f, 0.0102349f, 0.0103018f, 0.0102966f, 0.0084838f, 0.0078019f, 0.0064954f, 0.0301620f, 0.0684950f }, /* AU NB */ + {1.0f }, + {1.0f }, /* UV WB */ + {0.0226049f, 0.0191581f, 0.0116562f, 0.0101336f, 0.0098320f, 0.0093218f, 0.0093473f, 0.0089237f, 0.0084141f, 0.0079165f, 0.0079689f, 0.0078830f, 0.0073352f, 0.0073117f, 0.0068040f, 0.0077050f }, /* V WB */ + {0.0161769f, 0.0143117f, 0.0105676f, 0.0103070f, 0.0104118f, 0.0098651f, 0.0099466f, 0.0095790f, 0.0092086f, 0.0093473f, 0.0092670f, 0.0088620f, 0.0082814f, 0.0082881f, 0.0081953f, 0.0083592f }, /* G WB */ + {0.0175794f, 0.0175643f, 0.0115315f, 0.0099805f, 0.0098131f, 0.0092128f, 0.0088124f, 0.0084803f, 0.0080535f, 0.0081855f, 0.0079165f, 0.0072779f, 0.0064954f, 0.0062938f, 0.0061761f, 0.0064120f }, /* T WB */ + {0.0117837f, 0.0112837f, 0.0089237f, 0.0084488f, 0.0081045f, 0.0082581f, 0.0086596f, 0.0084245f, 0.0084384f, 0.0084003f, 0.0080693f, 0.0078317f, 0.0072163f, 0.0079844f, 0.0084038f, 0.0091715f }, /* AU WB */ + {1.0f }, + {1.0f }, + {0.0132901f, 0.0118587f, 0.0090340f, 0.0080000f, 0.0074608f, 0.0071235f, 0.0068198f, 0.0062687f, 0.0061985f, 0.0057480f, 0.0053487f, 0.0052365f, 0.0050958f, 0.0054965f, 0.0056187f, 0.0053417f }, /* V 16k */ + {0.0111486f, 0.0107563f, 0.0081920f, 0.0077488f, 0.0076647f, 0.0077900f, 0.0075433f, 0.0071809f, 0.0072470f, 0.0071434f, 0.0065431f, 0.0063543f, 0.0058001f, 0.0055728f, 0.0067568f, 0.0051496f }, /* G 16k */ + {0.0110703f, 0.0092294f, 0.0084211f, 0.0079534f, 0.0073669f, 0.0072470f, 0.0069921f, 0.0068887f, 0.0068587f, 0.0064443f, 0.0058397f, 0.0056778f, 0.0060431f, 0.0061967f, 0.0067258f, 0.0057335f }, /* T 16k */ + {0.0096970f, 0.0089043f, 0.0070257f, 0.0066386f, 0.0066645f, 0.0068564f, 0.0066972f, 0.0068564f, 0.0065140f, 0.0063563f, 0.0057143f, 0.0058481f, 0.0063504f, 0.0059483f, 0.0063860f, 0.0043658f }, /* AU 16k */ + {0.0114222f, 0.0085906f, 0.0097663f, 0.0096924f, 0.0099129f, 0.0104972f, 0.0098273f, 0.0090459f, 0.0081822f, 0.0086780f, 0.0093218f, 0.0091880f, 0.0098320f, 0.0089628f, 0.0089550f, 0.0064120f }, + {0.0062268f, 0.0081561f, 0.0085121f, 0.0077079f, 0.0076361f, 0.0074717f, 0.0071860f, 0.0062534f, 0.0059500f, 0.0061985f, 0.0070451f, 0.0070354f, 0.0075740f, 0.0076992f, 0.0081302f, 0.0062117f }, + {0.0187890f, 0.0095079f, 0.0074663f, 0.0069755f, 0.0063210f, 0.0059466f, 0.0062268f, 0.0060826f, 0.0057641f, 0.0054921f, 0.0058800f, 0.0060484f, 0.0078019f, 0.0103591f, 0.0108763f, 0.0106611f }, + {0.0143820f, 0.0059157f, 0.0084072f, 0.0095522f, 0.0099225f, 0.0101688f, 0.0101186f, 0.0104224f, 0.0102247f, 0.0102400f, 0.0104330f, 0.0100196f, 0.0105949f, 0.0093816f, 0.0085369f, 0.0069096f }, + {0.0073431f, 0.0076618f, 0.0076389f, 0.0075018f, 0.0076134f, 0.0077400f, 0.0074690f, 0.0060182f, 0.0050743f, 0.0035463f, 0.0032705f, 0.0039091f, 0.0025460f, 0.0029703f, 0.0073962f, 0.0103330f }, + {0.0081238f, 0.0083558f, 0.0079165f, 0.0083626f, 0.0085227f, 0.0092211f, 0.0092670f, 0.0089121f, 0.0067435f, 0.0064954f, 0.0078347f, 0.0076964f, 0.0075433f, 0.0066972f, 0.0069119f, 0.0040878f }, + {0.0108302f, 0.0102554f, 0.0106279f, 0.0110763f, 0.0106169f, 0.0104383f, 0.0107676f, 0.0115641f, 0.0119208f, 0.0134826f, 0.0141047f, 0.0144124f, 0.0139795f, 0.0059778f, 0.0139130f, 0.0463348f }, + {0.0227051f, 0.0135271f, 0.0071086f, 0.0082051f, 0.0077196f, 0.0078528f, 0.0086414f, 0.0095389f, 0.0094118f, 0.0090901f, 0.0080000f, 0.0093006f, 0.0116762f, 0.0126108f, 0.0143017f, 0.0178709f }, + {0.0093945f, 0.0100589f, 0.0104543f, 0.0107846f, 0.0106004f, 0.0108590f, 0.0119487f, 0.0118040f, 0.0114734f, 0.0098414f, 0.0109695f, 0.0132728f, 0.0136807f, 0.0139795f, 0.0147021f, 0.0156935f }, + {0.0230891f, 0.0079658f, 0.0093049f, 0.0117095f, 0.0120258f, 0.0123821f, 0.0126811f, 0.0124878f, 0.0124802f, 0.0113525f, 0.0107281f, 0.0122855f, 0.0133594f, 0.0136807f, 0.0151929f, 0.0168421f }, + {0.0066841f, 0.0078498f, 0.0085333f, 0.0089315f, 0.0088162f, 0.0087822f, 0.0092754f, 0.0102094f, 0.0099273f, 0.0088086f, 0.0059535f, 0.0049148f, 0.0064524f, 0.0083900f, 0.0093345f, 0.0095345f }, + {0.0168007f, 0.0115903f, 0.0094334f, 0.0087935f, 0.0074365f, 0.0082647f, 0.0083016f, 0.0099514f, 0.0101436f, 0.0099951f, 0.0075544f, 0.0052125f, 0.0051341f, 0.0128482f, 0.0142817f, 0.0238417f }, + {0.0113274f, 0.0108245f, 0.0108532f, 0.0106889f, 0.0102451f, 0.0107789f, 0.0112281f, 0.0114670f, 0.0112527f, 0.0106224f, 0.0082249f, 0.0082018f, 0.0085619f, 0.0081887f, 0.0060753f, 0.0071210f }, + {0.0115903f, 0.0107676f, 0.0119626f, 0.0116166f, 0.0104277f, 0.0105026f, 0.0110464f, 0.0115576f, 0.0121760f, 0.0122855f, 0.0128240f, 0.0111851f, 0.0069589f, 0.0059397f, 0.0240941f, 0.0361199f }, + {0.0102915f, 0.0098985f, 0.0095790f, 0.0090579f, 0.0091921f, 0.0093049f, 0.0102196f, 0.0107903f, 0.0126342f, 0.0122488f, 0.0129538f, 0.0091839f, 0.0047124f, 0.0050295f, 0.0210700f, 0.0282873f }, + {0.0133594f, 0.0102708f, 0.0099854f, 0.0109052f, 0.0110643f, 0.0111547f, 0.0120188f, 0.0118931f, 0.0122050f, 0.0103696f, 0.0090101f, 0.0107903f, 0.0119766f, 0.0121760f, 0.0128401f, 0.0141047f} +}; + +/* An 16-by-19 matrix in Scale = 20.48f */ +const float sigma_p[][16] = +{ + {59.3261719f, 63.9160156f, 69.7753906f, 66.3574219f, 67.3339844f, 68.5546875f, 66.6015625f, 66.0156250f, 66.0156250f, 67.9687500f, 68.2617188f, 84.3261719f, 96.5820313f, 118.6523438f, 44.0917969f, 43.1152344f }, /* IA NB */ + {51.2207031f, 66.6015625f, 69.3847656f, 68.6035156f, 67.9199219f, 69.6289063f, 69.6777344f, 69.5800781f, 52.5878906f, 64.9902344f, 65.3808594f, 68.7500000f, 71.4355469f, 77.0507813f, 77.9296875f, 80.3222656f }, /* U NB */ + {32.7148438f, 34.9121094f, 47.0703125f, 55.6152344f, 60.1562500f, 68.3105469f, 71.8261719f, 72.7539063f, 73.8281250f, 70.8984375f, 69.4335938f, 77.1972656f, 95.8007813f, 74.3164063f, 20.8984375f, 10.9375000f }, /* V NB */ + {53.8085938f, 61.3281250f, 78.1738281f, 75.8789063f, 73.7792969f, 81.3964844f, 80.7128906f, 80.5664063f, 83.6914063f, 77.0996094f, 72.5097656f, 86.6210938f, 121.6796875f, 117.7734375f, 40.0390625f, 16.8945313f },/* G NB */ + {1.0f }, /* T NB */ + {57.0312500f, 64.5996094f, 71.4355469f, 75.8789063f, 77.0507813f, 79.0039063f, 74.5117188f, 74.2187500f, 72.9492188f, 72.8515625f, 66.9433594f, 73.9257813f, 109.6191406f, 121.5332031f, 23.7792969f, 13.3789063f }, /* AU NB */ + {55.4687500f, 65.6738281f, 71.8261719f, 71.6308594f, 73.0468750f, 74.3164063f, 73.0957031f, 73.4863281f, 73.8769531f, 75.2441406f, 78.0761719f, 82.6171875f, 90.1367188f, 95.8496094f, 66.0644531f, 68.9941406f }, /* IA WB */ + {67.9687500f, 64.0625000f, 65.8203125f, 76.9531250f, 117.1875000f, 145.5078125f, 77.6855469f, 23.2421875f, 81.0546875f, 81.1035156f, 81.4453125f, 85.0585938f, 90.0878906f, 95.8984375f, 92.3828125f, 90.7226563f }, /* U WB */ + {35.6933594f, 39.4042969f, 57.3242188f, 64.6484375f, 68.0175781f, 76.2695313f, 80.7128906f, 82.0800781f, 85.1562500f, 89.6484375f, 89.9414063f, 95.3613281f, 104.7363281f, 106.0546875f, 105.2734375f, 97.8515625f }, /* V WB */ + {61.4257813f, 75.1464844f, 88.4277344f, 82.1777344f, 82.4218750f, 89.1601563f, 89.2578125f, 94.1894531f, 95.5566406f, 95.9472656f, 97.0703125f, 102.6367188f, 107.2265625f, 107.3730469f, 105.4199219f, 98.1933594f },/* G WB */ + {1.0f },/* T WB */ + {51.1230469f, 62.5976563f, 71.5820313f, 75.5371094f, 78.9550781f, 79.9804688f, 79.4433594f, 82.9101563f, 82.6171875f, 83.1054688f, 84.8632813f, 86.1328125f, 89.5996094f, 83.6914063f, 79.3945313f, 78.2226563f }, /* AU WB */ + {72.9980469f, 86.2792969f, 90.0878906f, 89.5996094f, 92.4316406f, 90.5273438f, 90.5273438f, 92.1386719f, 97.3632813f, 101.3671875f, 111.7675781f, 110.8398438f, 97.5585938f, 93.1640625f, 92.8710938f, 115.7226563f },/* IA 16k */ + {1.0f },/* U 16k */ + {54.4921875f, 67.4804688f, 94.1406250f, 125.0000000f, 122.8027344f, 123.0957031f, 118.5546875f, 115.0878906f, 128.5644531f, 140.3808594f, 144.2382813f, 139.4042969f, 151.4160156f, 138.1347656f, 140.3808594f, 154.7851563f }, /* V 16k */ + {96.8261719f, 117.3339844f, 132.5683594f, 134.4726563f, 140.7226563f, 136.8652344f, 141.6992188f, 141.1132813f, 143.8964844f, 152.6367188f, 168.5058594f, 169.1406250f, 158.4960938f, 156.1523438f, 147.4609375f, 182.4707031f },/* G 16k */ + {1.0f },/* T 16k */ + {55.1269531f, 70.3613281f, 83.1054688f, 87.2070313f, 90.5273438f, 91.4550781f, 94.7265625f, 93.6035156f, 97.6074219f, 98.7304688f, 104.6875000f, 99.6582031f, 95.6054688f, 91.6503906f, 88.4765625f, 78.2226563f, },/* NOT USED ! AU 16k */ + {69.5312500f, 80.1757813f, 101.3183594f, 100.9277344f, 106.4941406f, 111.1816406f, 107.6171875f, 112.9882813f, 116.6992188f, 117.1875000f, 120.9472656f, 125.0976563f, 130.7617188f, 128.7109375f, 123.3886719f, 104.9316406f} /* G WB for MA*/ +}; +/* An 16-by-19 matrix in Scale = 20.48f */ +const float inv_sigma_p[][16] = +{ + {0.0168560f, 0.0156455f, 0.0143317f, 0.0150699f, 0.0148513f, 0.0145869f, 0.0150147f, 0.0151479f, 0.0151479f, 0.0147126f, 0.0146495f, 0.0118587f, 0.0103539f, 0.0084280f, 0.0226800f, 0.0231937f }, /* IA NB */ + {0.0195234f, 0.0150147f, 0.0144124f, 0.0145765f, 0.0147232f, 0.0143619f, 0.0143518f, 0.0143719f, 0.0190158f, 0.0153869f, 0.0152950f, 0.0145455f, 0.0139986f, 0.0129785f, 0.0128321f, 0.0124498f }, /* U NB */ + {0.0305672f, 0.0286434f, 0.0212448f, 0.0179807f, 0.0166234f, 0.0146390f, 0.0139225f, 0.0137450f, 0.0135450f, 0.0141047f, 0.0144023f, 0.0129538f, 0.0104383f, 0.0134560f, 0.0478505f, 0.0914286f }, /* V NB */ + {0.0185844f, 0.0163057f, 0.0127920f, 0.0131789f, 0.0135539f, 0.0122855f, 0.0123896f, 0.0124121f, 0.0119487f, 0.0129702f, 0.0137912f, 0.0115445f, 0.0082183f, 0.0084909f, 0.0249756f, 0.0591908f }, /* G NB */ + {1.0f }, /* T NB */ + {0.0175342f, 0.0154800f, 0.0139986f, 0.0131789f, 0.0129785f, 0.0126576f, 0.0134207f, 0.0134737f, 0.0137082f, 0.0137265f, 0.0149380f, 0.0135271f, 0.0091225f, 0.0082282f, 0.0420534f, 0.0747445f }, /* AU NB */ + {0.0180282f, 0.0152268f, 0.0139225f, 0.0139605f, 0.0136898f, 0.0134560f, 0.0136807f, 0.0136080f, 0.0135360f, 0.0132901f, 0.0128080f, 0.0121040f, 0.0110943f, 0.0104330f, 0.0151367f, 0.0144940f }, /* IA WB */ + {0.0147126f, 0.0156098f, 0.0151929f, 0.0129949f, 0.0085333f, 0.0068725f, 0.0128724f, 0.0430252f, 0.0123373f, 0.0123299f, 0.0122782f, 0.0117566f, 0.0111003f, 0.0104277f, 0.0108245f, 0.0110226f }, /* U WB */ + {0.0280164f, 0.0253779f, 0.0174446f, 0.0154683f, 0.0147021f, 0.0131114f, 0.0123896f, 0.0121832f, 0.0117431f, 0.0111547f, 0.0111183f, 0.0104864f, 0.0095478f, 0.0094291f, 0.0094991f, 0.0102196f }, /* V WB */ + {0.0162798f, 0.0133073f, 0.0113087f, 0.0121687f, 0.0121327f, 0.0112158f, 0.0112035f, 0.0106169f, 0.0104650f, 0.0104224f, 0.0103018f, 0.0097431f, 0.0093260f, 0.0093133f, 0.0094859f, 0.0101840f }, /* G WB */ + {1.0f }, /* T WB */ + {0.0195606f, 0.0159750f, 0.0139700f, 0.0132385f, 0.0126654f, 0.0125031f, 0.0125876f, 0.0120612f, 0.0121040f, 0.0120329f, 0.0117837f, 0.0116100f, 0.0111608f, 0.0119487f, 0.0125953f, 0.0127840f }, /* AU WB */ + {0.0136990f, 0.0115903f, 0.0111003f, 0.0111608f, 0.0108188f, 0.0110464f, 0.0110464f, 0.0108532f, 0.0102708f, 0.0098651f, 0.0089471f, 0.0090220f, 0.0102503f, 0.0107338f, 0.0107676f, 0.0086414f }, /* IA 16k*/ + {1.0f }, /* U 16k */ + {0.0183513f, 0.0148191f, 0.0106224f, 0.0080000f, 0.0081431f, 0.0081238f, 0.0084349f, 0.0086890f, 0.0077782f, 0.0071235f, 0.0069330f, 0.0071734f, 0.0066043f, 0.0072393f, 0.0071235f, 0.0064606f }, /* V 16k */ + {0.0103278f, 0.0085227f, 0.0075433f, 0.0074365f, 0.0071062f, 0.0073065f, 0.0070572f, 0.0070865f, 0.0069494f, 0.0065515f, 0.0059345f, 0.0059122f, 0.0063093f, 0.0064040f, 0.0067815f, 0.0054803f }, /* G 16k */ + {1.0f }, /* T 16k */ + {0.0181399f, 0.0142124f, 0.0120329f, 0.0114670f, 0.0110464f, 0.0109343f, 0.0105567f, 0.0106834f, 0.0102451f, 0.0101286f, 0.0095522f, 0.0100343f, 0.0104597f, 0.0109110f, 0.0113024f, 0.0127840f },/* NOT USED ! AU 16k */ + {0.0143820f, 0.0124726f, 0.0098699f, 0.0099081f, 0.0093902f, 0.0089943f, 0.0092922f, 0.0088505f, 0.0085690f, 0.0085333f, 0.0082681f, 0.0079938f, 0.0076475f, 0.0077693f, 0.0081045f, 0.0095300f} /* G WB for MA*/ +}; +const int no_lead[][MAX_NO_SCALES*2] = +{ + { 1, 0, 0, 1, 0, 0, }, /* 14 */ + { 2, 0, 0, 1, 0, 0, }, /* 15 */ + { 4, 2, 0, 1, 0, 0, }, /* 18 */ + { 4, 2, 0, 2, 0, 0, }, /* 19 */ + { 7, 5, 2, 5, 4, 2, }, /* 25 */ + { 8, 8, 3, 8, 6, 2, }, /* 28 */ /* mode 0 UV WB*/ + { 4, 2, 0, 1, 0, 0, }, /* 18 */ + { 4, 0, 0, 2, 1, 0, }, /* 19 */ + { 9, 8, 8, 2, 2, 1, }, /* 24 */ + { 8, 5, 2, 5, 2, 1, }, /* 25 */ + { 18, 16, 8, 5, 5, 1, }, /* 29 */ + { 24, 21, 10, 8, 8, 2, }, /* 32 */ /* mode 1 UV NB*/ + { 2, 0, 0, 2, 0, 0, }, /* 17 */ + { 4, 2, 0, 1, 0, 0, }, /* 18 */ + { 7, 5, 2, 2, 0, 0, }, /* 21 */ + { 5, 2, 1, 4, 1, 0, }, /* 22 */ + { 8, 5, 2, 5, 2, 0, }, /* 25 */ + { 8, 7, 4, 5, 3, 2, }, + { 8, 8, 4, 6, 5, 2, }, + { 13, 8, 5, 6, 5, 2, }, + { 13, 8, 5, 8, 6, 2, }, + { 13, 8, 5, 11, 8, 2, }, /* 30 */ + { 24, 21, 8, 9, 8, 2, }, /* 32 */ + { 23, 18, 8, 13, 11, 3, }, + { 23, 21, 8, 17, 13, 4, }, /* 34 */ + { 31, 31, 17, 26, 25, 9, }, /* 37 */ /* mode 2 V WB*/ + { 2, 0, 0, 2, 2, 0, }, /* 17 */ + { 4, 2, 0, 1, 0, 0, }, /* 18 */ + { 7, 5, 2, 2, 2, 0, }, /* 22 */ + { 8, 7, 2, 2, 2, 0, }, /* 23 */ + { 11, 8, 2, 2, 2, 0, }, /* 24 */ + { 13, 13, 9, 2, 2, 0, }, /* 25 */ + { 13, 11, 7, 5, 2, 0, }, /* 27 */ + { 18, 14, 9, 5, 5, 2, }, /* 29 */ + { 31, 31, 14, 11, 11, 5, }, /* 34 */ + { 31, 31, 27, 24, 21, 14, }, /* 37 */ /* mode 3 V NB */ + { 5, 4, 0, 0, 0, 0, }, /* 12 (11.883) */ + { 2, 0, 0, 2, 0, 0, }, /* 16 (15.826) */ + { 4, 2, 0, 2, 0, 0, }, /* 19 (18.572) */ + { 5, 4, 0, 2, 0, 0, }, /* 20 (19.796) */ + { 7, 5, 2, 2, 0, 0, }, /* 21 (20.910) */ + { 8, 7, 2, 2, 0, 0, }, /* 22 (21.776) */ + { 5, 5, 2, 4, 2, 0, }, /* 23 (22.959) */ + { 8, 8, 5, 4, 2, 0, }, /* 25 (24.992) */ + { 8, 8, 7, 5, 2, 0, }, /* 26 (25.904) */ + { 13, 9, 8, 5, 2, 0, }, /* 27 (26.829) */ + { 13, 11, 8, 5, 5, 1, }, /* 28 (27.989) */ + { 13, 9, 8, 8, 5, 2, }, /* 29 (28.984) */ + { 22, 16, 10, 6, 5, 2, }, /* 30 (29.980) */ + { 21, 14, 10, 8, 7, 2, }, /* 31 (30.966) */ + { 24, 21, 10, 8, 8, 2, }, /* 32 (31.995) */ /* G WB*/ + { 5, 4, 1, 0, 0, 0, }, /* 12 (11.925) */ + { 2, 0, 0, 2, 0, 0, }, /* 16 (15.826) */ + { 5, 4, 1, 1, 0, 0, }, /* 19 (18.745) */ + { 5, 4, 1, 2, 0, 0, }, /* 20 (19.838) */ + { 7, 5, 2, 2, 0, 0, }, /* 21 (20.910) */ + { 8, 5, 2, 2, 1, 0, }, /* 22 (21.985) */ + { 9, 8, 5, 2, 1, 0, }, /* 23 (22.815) */ + { 14, 13, 8, 2, 2, 0, }, /* 25 (24.996) */ + { 13, 8, 7, 4, 2, 0, }, /* 26 (25.993) */ + { 13, 9, 8, 5, 2, 2, }, /* 27 (26.954) */ + { 18, 13, 8, 5, 2, 2, }, /* 28 (27.992) */ + { 21, 13, 11, 5, 3, 2, }, /* 29 (28.996) */ + { 22, 21, 13, 5, 5, 2, }, /* 30 (29.988) */ + { 23, 21, 17, 7, 5, 2, }, /* 31 (30.962) */ + { 27, 23, 21, 8, 5, 2, }, /* 32 (31.987) */ /* G NB*/ + + { 2, 0, 0, 2, 0, 0, }, /* 17 */ + { 4, 2, 0, 1, 0, 0, }, /* 18 */ + { 4, 1, 0, 4, 0, 0, }, /* 21 */ + { 5, 2, 0, 4, 1, 0, }, /* 22 */ + { 8, 5, 2, 4, 0, 0, }, /* 24 */ + { 8, 5, 2, 5, 2, 0, }, /* 25 */ + { 14, 10, 5, 5, 5, 1, }, /* 28 */ + { 14, 10, 5, 8, 8, 4, }, /* 30 */ + { 13, 10, 5, 13, 8, 8, }, + { 23, 21, 8, 8, 8, 4, }, + { 23, 18, 5, 13, 8, 8, }, /* 33 */ /* mode 6 T WB */ + { 2, 0, 0, 2, 2, 0, }, /* 17 */ + { 4, 2, 0, 1, 0, 0, }, /* 18 */ + { 7, 5, 2, 2, 2, 0, }, /* 22 */ + { 8, 7, 4, 2, 2, 0, }, /* 23 */ + { 11, 8, 5, 2, 2, 0, }, /* 24 */ + { 18, 8, 5, 2, 2, 0, }, /* 25 */ + { 16, 8, 5, 5, 5, 2, }, /* 28 */ + { 28, 23, 8, 5, 5, 5, }, /* 31 */ + { 31, 31, 8, 5, 5, 7, }, /* 32 */ /* mode 7 T NB */ + { 18, 18, 11, 9, 6, 5, }, /* 31 */ + { 24, 23, 13, 9, 6, 5, }, /* 32 */ /* mode 8 G 16k */ + { 24, 23, 13, 9, 6, 5, }, /* 32 (31.998) */ + { 36, 31, 18, 9, 6, 5, }, /* 33 (32.983) */ /* T 16k */ + { 2, 0, 0, 2, 2, 0, }, /* 17 */ + { 7, 5, 2, 2, 0, 0, }, /* 21 */ + { 7, 5, 2, 2, 2, 0, }, /* 22 */ + { 9, 8, 3, 4, 2, 0, }, /* 25 */ + { 11, 9, 8, 4, 2, 0, }, /* 26 */ /* mode 10 AUDIO_WB*/ + { 48, 48, 34, 13, 11, 9 }, /* 36 */ /* mode 10 AUDIO_WB 36 + 4 + 1 */ + { 22, 10, 3, 0, 0, 0 }, /* 17 */ + { 6, 6, 2, 2, 0, 0 }, /* 21 */ + { 6, 6, 2, 2, 2, 0 }, /* 22 */ + { 23, 10, 3, 2, 2, 0 }, /* 26 */ + { 32, 16, 3, 2, 2, 0 }, /* 27 */ + { 39, 30, 12, 2, 2, 0 }, /* 28 */ /* AUDIO_NB */ + { 11, 9, 8, 4, 2, 0, }, /* 26 */ + { 48, 48, 48, 13, 9, 8, }, /* 36 */ /* mode 12 AUDIO_WB 16k 15-36 + 4 + 1*/ + { 8, 7, 2, 2, 0, 0, }, /* 22 (21.776) */ + { 13, 13, 5, 5, 5, 0, }, /* 28 (27.994) */ + { 18, 17, 5, 5, 5, 1, }, /* 29 (28.996) */ + { 17, 13, 5, 8, 6, 2, }, /* 30 (29.991) */ + { 23, 21, 8, 9, 8, 3, }, /* 32 (31.992) */ + { 31, 29, 16, 8, 8, 3, }, /* 33 (32.993) */ + { 31, 25, 16, 12, 8, 8, }, /* 34 (33.968) */ + { 46, 48, 18, 18, 18, 12, }, /* 37 (36.995) */ /* VOICED 16k actually not used */ + { 14, 12, 9, 2, 2, 0, }, /* 25 (24.980) */ + { 15, 13, 3, 2, 2, 0, }, /* 25 (24.974) */ + { 17, 3, 0, 2, 2, 1, }, /* 25 (24.852) */ + { 13, 10, 3, 2, 2, 2, }, /* 25 (24.994) */ + { 14, 13, 8, 2, 2, 0, }, /* 25 (24.996) */ + { 7, 3, 0, 5, 3, 1, }, /* 25 (24.671) */ + { 4, 3, 2, 6, 6, 5, }, /* 25 (24.936) */ + { 4, 2, 0, 9, 9, 3, }, /* 25 (24.955) */ + { 4, 2, 0, 9, 8, 2, }, /* 25 (24.853) */ + { 4, 2, 0, 9, 7, 6, }, /* 25 (24.881) */ + { 6, 3, 0, 6, 3, 2, }, /* 25 (24.939) */ + { 3, 2, 0, 9, 8, 5, }, /* 25 (24.996) */ + { 2, 2, 0, 15, 3, 3, }, /* 25 (24.310) */ + { 4, 2, 0, 9, 9, 3, }, /* 25 (24.955) */ + { 4, 4, 2, 7, 6, 3, }, /* 25 (24.984) */ + { 3, 2, 0, 9, 7, 6, }, /* 25 (24.866) */ +}; + +const int no_lead_p[][MAX_NO_SCALES*2] = +{ + { 2, 1, 0, 0, 0, 0, }, /* 9 (8.464) */ + { 4, 2, 0, 2, 0, 0, }, /* 19 (18.572) */ + { 5, 5, 2, 4, 2, 0, }, /* 23 (22.959) */ + { 8, 5, 2, 4, 0, 0, }, /* 24 (23.949) */ + { 8, 8, 5, 4, 2, 0, }, /* 25 (24.992) */ + { 13, 11, 5, 5, 2, 0, }, /* 27 (26.902) */ + { 11, 10, 5, 6, 5, 2, }, /* 28 (27.996) */ + { 14, 13, 5, 7, 5, 2, }, /* 29 (28.937) */ + { 16, 13, 5, 8, 7, 2, }, /* 30 (29.954) */ + { 21, 21, 5, 8, 5, 2, }, /* 31 (30.978) */ + { 24, 21, 5, 8, 8, 4, }, /* 32 (31.978) */ + { 32, 23, 5, 13, 11, 5, }, /* 34 (33.975) */ + { 36, 31, 8, 16, 13, 5, }, /* 35 (34.975) */ + { 45, 35, 16, 18, 13, 5, }, /* 36 (35.889) */ + { 45, 35, 16, 38, 31, 8, }, /* 39 (38.488) */ /* V WB*/ /* 14 */ + + { 2, 0, 0, 0, 0, 0, }, /* 8 (7.913) */ + { 4, 2, 0, 2, 0, 0, }, /* 19 (18.572) */ + { 8, 7, 2, 2, 2, 0, }, /* 23 (22.773) */ + { 13, 11, 5, 2, 1, 0, }, /* 24 (23.999) */ + { 8, 8, 5, 4, 2, 0, }, /* 25 (24.992) */ + { 13, 11, 5, 5, 2, 1, }, /* 27 (26.962) */ + { 13, 11, 5, 5, 5, 2, }, /* 28 (27.835) */ + { 14, 13, 5, 7, 5, 2, }, /* 29 (28.937) */ + { 23, 21, 5, 5, 5, 2, }, /* 30 (29.969) */ + { 23, 18, 5, 8, 5, 2, }, /* 31 (30.952) */ + { 24, 21, 5, 8, 8, 4, }, /* 32 (31.978) */ + { 43, 41, 13, 9, 8, 5, }, /* 34 (33.992) */ + { 43, 36, 13, 13, 10, 5, }, /* 35 (35.000) */ + { 43, 40, 13, 17, 13, 9, }, /* 36 (35.980) */ + { 43, 42, 13, 31, 30, 18, }, /* 39 (38.512) */ /* V NB*/ /* 29 */ + + { 2, 0, 0, 1, 0, 0, }, /* 15 (14.733) */ + { 5, 4, 1, 1, 0, 0, }, /* 19 (18.745) */ + { 8, 7, 2, 2, 0, 0, }, /* 22 (21.776) */ + { 10, 9, 5, 2, 0, 0, }, /* 23 (22.791) */ + { 14, 13, 8, 2, 0, 0, }, /* 24 (23.999) */ + { 14, 13, 8, 2, 2, 0, }, /* 25 (24.996) */ + { 18, 17, 13, 2, 2, 0, }, /* 26 (25.934) */ + { 14, 13, 8, 5, 4, 0, }, /* 28 (27.969) */ + { 18, 17, 13, 5, 4, 2, }, /* 29 (28.996) */ + { 22, 21, 13, 5, 5, 2, }, /* 30 (29.988) */ + { 31, 23, 21, 5, 5, 2, }, /* 31 (30.931) */ + { 27, 23, 21, 8, 5, 2, }, /* 32 (31.987) */ + { 31, 23, 21, 9, 8, 5, }, /* 33 (32.982) */ + { 32, 31, 24, 11, 8, 5, }, /* 34 (33.967) */ + { 32, 32, 28, 13, 11, 8, }, /* 35 (34.994) */ /* G WB*/ /* 44 */ + + { 2, 0, 0, 1, 0, 0, }, /* 15 (14.733) */ + { 5, 4, 2, 1, 0, 0, }, /* 19 (18.792) */ + { 8, 5, 2, 2, 1, 0, }, /* 22 (21.985) */ + { 8, 7, 2, 2, 2, 0, }, /* 23 (22.773) */ + { 13, 11, 2, 2, 1, 0, }, /* 24 (23.932) */ + { 16, 13, 2, 2, 2, 0, }, /* 25 (24.955) */ + { 21, 17, 2, 2, 2, 0, }, /* 26 (25.991) */ + { 13, 12, 2, 5, 5, 2, }, /* 28 (27.979) */ + { 18, 16, 2, 5, 5, 2, }, /* 29 (28.878) */ + { 23, 21, 2, 5, 5, 2, }, /* 30 (29.954) */ + { 32, 28, 2, 5, 5, 2, }, /* 31 (30.893) */ + { 38, 31, 2, 7, 5, 2, }, /* 32 (31.963) */ + { 33, 31, 2, 8, 8, 4, }, /* 33 (32.997) */ + { 42, 31, 2, 9, 9, 8, }, /* 34 (33.986) */ + { 42, 31, 2, 13, 11, 9, }, /* 35 (34.952) */ /* G NB*/ /* 59 */ + + + { 7, 5, 2, 2, 0, 0, }, /* 21 */ + { 8, 8, 5, 4, 2, 0, }, /* 25 */ + { 13, 8, 5, 4, 2, 0, }, /* 26 */ + { 13, 8, 5, 8, 6, 2, }, /* 29 */ + { 13, 8, 5, 9, 8, 5, }, /* 30 */ + { 48, 48, 48, 36, 36, 28 }, /* 40 */ /* mode 7 AUDIO_WB */ /* 65*/ + { 7, 5, 2, 2, 0, 0 }, /* 21 */ + { 13, 13, 9, 2, 2, 0 }, /* 25 */ + { 18, 18, 9, 2, 2, 0 }, /* 26 */ + { 24, 23, 10, 5, 4, 2 }, /* 30 */ + { 31, 31, 12, 5, 5, 2 }, /* 31 */ + { 43, 34, 12, 5, 5, 4 }, /* 32 */ /*AUDIO_NB */ /* 71 */ + { 13, 8, 5, 9, 8, 5, }, /* 30 */ + { 48, 48, 45, 45, 31, 25, }, /* 40 */ /* mode AUDIO_WB 16k */ /* 73*/ + { 2, 0, 0, 2, 2, 0, }, /* 17 (16.823) */ + { 7, 5, 2, 2, 0, 0, }, /* 21 (20.910) */ + { 7, 5, 2, 2, 2, 0, }, /* 22 (21.907) */ + { 13, 11, 10, 2, 2, 0, }, /* 25 (24.863) */ + { 18, 18, 10, 2, 2, 0, }, /* 26 (25.921) */ + { 13, 9, 9, 5, 2, 0, }, /* 27 (26.837) */ + { 40, 28, 25, 18, 17, 2, }, /* 36 (35.998) */ /* INACTIVE NB*/ /* 80*/ + + { 18, 17, 11, 0, 0, 0, }, /* 17 (16.932) */ + { 7, 5, 2, 2, 0, 0, }, /* 21 (20.910) */ + { 8, 5, 2, 2, 1, 0, }, /* 22 (21.985) */ + { 13, 13, 9, 2, 2, 0, }, /* 25 (24.845) */ + { 18, 18, 12, 2, 2, 0, }, /* 26 (25.999) */ + { 23, 23, 16, 2, 2, 0, }, /* 27 (26.981) */ + { 36, 32, 24, 17, 13, 13, }, /* 36 (35.929) */ /* INACTIVE WB */ + + { 2, 2, 0, 2, 0, 0, }, /* 17 (16.823) */ + { 7, 5, 2, 2, 0, 0, }, /* 21 (20.910) */ + { 8, 5, 2, 2, 1, 0, }, /* 22 (21.985) */ + { 13, 13, 9, 2, 2, 0, }, /* 25 (24.845) */ + { 18, 17, 13, 2, 2, 0, }, /* 26 (25.934) */ + { 23, 22, 17, 2, 2, 0, }, /* 27 (26.914) */ + { 34, 32, 24, 16, 16, 13, }, /* 36 (35.915) */ /* INACTIVE WB 16k*/ + + { 4, 2, 0, 1, 0, 0, }, /* 18 (17.479) */ + { 5, 4, 0, 1, 0, 0, }, /* 19 (18.703) */ + { 8, 7, 2, 2, 0, 0, }, /* 22 (21.776) */ + { 10, 9, 5, 2, 0, 0, }, /* 23 (22.791) */ + { 15, 13, 5, 2, 0, 0, }, /* 24 (23.999) */ + { 18, 16, 8, 5, 5, 1, }, /* 29 (28.966) */ + { 42, 32, 31, 5, 5, 2, }, /* 32 (31.990) */ /* UNVOICED NB*/ + { 1, 0, 0, 1, 0, 0, }, /* 14 (13.640) */ + { 2, 0, 0, 1, 0, 0, }, /* 15 (14.733) */ + { 4, 2, 0, 1, 0, 0, }, /* 18 (17.479) */ + { 4, 2, 0, 2, 0, 0, }, /* 19 (18.572) */ + { 5, 4, 0, 2, 0, 0, }, /* 20 (19.796) */ + { 8, 8, 5, 4, 2, 0, }, /* 25 (24.992) */ + { 11, 10, 5, 6, 5, 2, }, /* 28 (27.996) */ /* UNVOICED WB */ + + { 9, 3, 0, 4, 0, 0, }, /* 24 (23.818) */ + { 18, 13, 10, 8, 3, 0, }, /* 30 (29.992) */ + { 24, 18, 10, 9, 3, 0, }, /* 31 (30.998) */ + { 32, 25, 10, 9, 3, 0, }, /* 32 (31.987) */ + { 42, 31, 10, 12, 3, 2, }, /* 34 (33.994) */ + { 44, 32, 27, 15, 3, 2, }, /* 35 (35.000) */ + { 44, 32, 25, 19, 3, 2, }, /* 36 (35.994) */ + { 48, 39, 32, 35, 15, 3, }, /* 39 (38.301) */ /* VOICED 16k */ + { 11, 10, 5, 4, 2, 0, }, /* 26 (25.917) */ + { 23, 23, 17, 8, 7, 2, }, /* 32 (31.980) */ + { 32, 31, 18, 9, 7, 5, }, /* 33 (32.990) */ + { 31, 31, 18, 11, 9, 8, }, /* 34 (33.974) */ + { 32, 32, 20, 13, 12, 8, }, /* 35 (34.989) */ + { 32, 32, 23, 18, 17, 8, }, /* 36 (35.988) */ + { 32, 32, 23, 23, 22, 10, }, /* 37 (36.989) */ /* GENERIC 16k*/ + + { 2, 0, 0, 2, 0, 0, }, /* 16 (15.826) */ + { 7, 5, 2, 2, 0, 0, }, /* 21 (20.910) */ + { 14, 13, 8, 2, 0, 0, }, /* 24 (23.999) */ + { 8, 8, 5, 4, 2, 0, }, /* 25 (24.992) */ + { 11, 10, 5, 4, 2, 0, }, /* 26 (25.917) */ + { 16, 13, 8, 4, 2, 0, }, /* 27 (26.883) */ + { 13, 13, 8, 5, 4, 2, }, /* 28 (27.901) */ + { 23, 18, 13, 5, 5, 2, }, /* 30 (29.916) */ + { 23, 23, 13, 7, 5, 2, }, /* 31 (30.993) */ + { 23, 23, 17, 8, 7, 2, }, /* 32 (31.980) */ + { 32, 31, 24, 8, 7, 2, }, /* 33 (32.958) */ + { 42, 32, 31, 9, 9, 4, }, /* 34 (33.987) */ + { 40, 32, 29, 12, 9, 9, }, /* 35 (34.994) */ + { 40, 32, 31, 17, 11, 11, }, /* 36 (35.968) */ + { 41, 32, 31, 20, 18, 13, }, /* 37 (36.971) */ /* GENERIC 12.8k MA*/ + + + { 11, 10, 5, 4, 2, 0, }, /* 26 (25.917) */ + { 23, 23, 17, 8, 7, 2, }, /* 32 (31.980) */ + { 31, 31, 18, 9, 8, 2, }, /* 33 (32.995) */ + { 48, 32, 24, 9, 8, 3, }, /* 34 (33.993) */ + { 48, 32, 28, 11, 10, 3, }, /* 35 (34.992) */ + { 48, 37, 32, 16, 12, 4, }, /* 36 (35.997) */ + { 48, 37, 32, 18, 17, 12, }, /* 37 (36.961) */ /* AUDIO 16k */ +}; + +const short min_lat_bits_SN[] = {-1, -1, 17, 12, 17, 17, -1, -1, 17, 12, 17, 17, -1, -1, 22, -1, 32, 26 + }; + +const short min_lat_bits_pred[] = {17, 18, 9, 15, -1, 21, 17, 14, 9, 15, -1, 21, 17, -1, -1, 26, -1, 26, 16}; + + + +const short offset_in_lvq_mode_SN[][21] = +{ + {0}, /* I NB */ + {0,1,1,1,1,1,2,3,3,3,3,4,4,4,5}, /* UV NB*/ + {0,1,1,1,1,2,3,4,5,5,6,6,7,7,7,7,7,8,8,8,9}, /* V NB */ + {0,0,0,0,1,1,1,2,3,4,5,6,6,7,8,9,10,11,12,13,14}, /* G NB */ + {0,1,1,1,1,2,3,4,5,5,5,6,6,6,7,8}, /* T NB */ + {0,0,0,0,1,2,2,2,2,3,4,5}, /* A NB */ + {0}, /* I WB */ + {0,1,1,1,2,3,3,3,3,3,3,4,4,4,5}, /* UV WB*/ + {0,1,1,1,2,3,3,3,4,5,6,7,8,9,9,10,11,12,12,12,13}, /* V WB */ + {0,0,0,0,1,1,1,2,3,4,5,6,6,7,8,9,10,11,12,13,14}, /* G WB */ + {0,1,1,1,2,3,3,4,5,5,5,6,6,7,8,9,10}, /* T WB */ + {0,0,0,0,1,2,2,2,3,4,4,4,4,4,4,4,4,4,4,5}, /* A WB */ + {0}, + {0}, + {0,0,0,0,0,0,1,2,3,3,4,5,6,6,6,7}, /* V 16k */ + {0}, /* G 16k */ + {0,1}, /* T 16k */ + {0}, /*{0,0,0,0,0,0,0,0,0,0,1} */ /* A 16k */ +}; +const short offset_in_lvq_mode_pred[][32] = +{ + {0,0,0,0,1,2,2,2,3,4,5,5,5,5,5,5,5,5,5,6}, /* I NB */ + {0,1,1,1,2,3,4,4,4,4,4,5,5,5,6}, /* UV NB */ + {0,0,0,0,0,0,0,0,0,0,1,1,1,1,2,3,4,4,5,6,7,8,9,10,10,11,12,13,13,13,14}, /* V NB */ + {0,0,0,0,1,1,1,2,3,4,5,6,6,7,8,9,10,11,12,13,14}, /* G NB */ + {0}, /* T NB */ + {0,0,0,0,1,2,2,2,2,3,4,5}, /* A NB */ + {0,0,0,0,1,2,2,2,3,4,5,5,5,5,5,5,5,5,5,6}, /* I WB */ + {0,1,1,1,2,3,4,4,4,4,4,5,5,5,6}, /* UV WB */ + {0,0,0,0,0,0,0,0,0,0,1,1,1,1,2,3,4,4,5,6,7,8,9,10,10,11,12,13,13,13,14}, /* V WB */ + {0,0,0,0,1,1,1,2,3,4,5,6,6,7,8,9,10,11,12,13,14}, /* G WB */ + {0}, /* T WB */ + {0,0,0,0,1,2,2,2,3,4,4,4,4,4,4,4,4,4,4,5}, /* A WB */ + {0,0,0,0,1,2,2,2,3,4,5,5,5,5,5,5,5,5,5,6}, /* I 16k */ + {0}, /* UV 16k */ + {0,0,0,0,0,0,1,2,3,3,4,5,6,6,6,7}, /* V 16k */ + {0,0,0,0,0,0,1,2,3,4,5,6}, /* G 16k */ + {0}, /* T 16k */ + {0,0,0,0,0,0,1,2,3,4,5,6}, /* A 16k */ + {0,0,0,0,0,1,1,1,2,3,4,5,6,6,7,8,9,10,11,12,13,14}, /* G WB MA*/ +}; +const short offset_lvq_modes_SN[] = {-1,-1,26,51,77,96,-1,-1,12,36,66,90,-1,-1,105,-1,88,102, + 112 + }; /* CNG */ + +const short offset_lvq_modes_pred[] = {74, 95, 15, 45, -1, 66, 81, 102, 0, 30, -1, 60, 88, -1, 109, 117, -1, 139, 124}; + + +/*-----------------------------------------------------------------* + * BC-TCVQ frame-end quantization tables (BC-TCVQ is used in Voiced mode for 16kHz isf) + *-----------------------------------------------------------------*/ +const int NTRANS[4][NUM_STATE] = {{0,2,4,6,8,10,12,14,0,2,4,6,8,10,12,14}, /* indices of previous state of first branche */ + {1,3,5,7,9,11,13,15,1,3,5,7,9,11,13,15}, /* indices of previous state of second branches */ + {4,2,1,3,0,2,1,3,2,0,3,1,7,0,3,1}, /* indices of previous subset of first branch */ + {2,0,3,6,2,0,3,1,0,2,1,3,0,2,1,5} /* indices of previous subset of second branch */ +}; + +const int NTRANS2[4][NUM_STATE] = {{0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7}, + {8,8,9,9,10,10,11,11,12,12,13,13,14,14,15,15}, + {4,2,2,0,1,3,3,6,0,2,2,0,1,3,3,1}, + {2,0,0,2,3,1,1,3,7,0,0,2,3,1,1,5} +}; + +/* BC-TCQ Bit Allocations */ +const short BC_TCVQ_BIT_ALLOC_40B[M/2+4] = {1, 4, 5,5,4,4, 2,2,2,2, 5,4 }; /*1+39bit*/ + +const short FixBranch_tbl[4][4][N_STAGE_VQ - 4] = +{ + {{0, 0, 0, 0}, {1, 0, 0, 0}, {0, 1, 0, 0}, {1, 1, 0, 0}}, /* incase of initial state 0 */ + {{0, 0, 1, 0}, {1, 0, 1, 0}, {0, 1, 1, 0}, {1, 1, 1, 0}}, /* incase of initial state 4 */ + {{0, 0, 0, 1}, {1, 0, 0, 1}, {0, 1, 0, 1}, {1, 1, 0, 1}}, /* incase of initial state 8 */ + {{0, 0, 1, 1}, {1, 0, 1, 1}, {0, 1, 1, 1}, {1, 1, 1, 1}} /* incase of initial state 12 */ +}; + +/* Intra-Prediction */ +const float AR_IntraCoeff[N_STAGE_VQ-1][2][2] = +{ + {{-0.292479f, 0.676331f}, {-0.422648f, 0.217490f}}, + {{ 0.048957f, 0.500476f}, { 0.087301f, 0.287286f}}, + {{ 0.199481f, 0.502784f}, { 0.106762f, 0.420907f}}, + {{ 0.240459f, 0.440504f}, { 0.214255f, 0.396496f}}, + {{ 0.193161f, 0.494850f}, { 0.158690f, 0.306771f}}, + {{ 0.093435f, 0.370662f}, { 0.065526f, 0.148231f}}, + {{ 0.037417f, 0.336906f}, {-0.024246f, 0.187298f}} +}; + +const float SN_IntraCoeff[N_STAGE_VQ-1][2][2] = +{ + {{-0.452324f, 0.808759f}, {-0.524298f, 0.305544f}}, + {{ 0.009663f, 0.606028f}, {-0.013208f, 0.421115f}}, + {{ 0.144877f, 0.673495f}, { 0.080963f, 0.580317f}}, + {{ 0.208225f, 0.633144f}, { 0.215958f, 0.584520f}}, + {{ 0.050822f, 0.767842f}, { 0.076879f, 0.416693f}}, + {{ 0.005058f, 0.550614f}, {-0.006786f, 0.296984f}}, + {{-0.023860f, 0.611144f}, {-0.162706f, 0.576228f}} +}; + +const float scale_ARSN[M] = {1.8307f, 1.8404f, 1.8009f, 1.7416f, 1.7240f, 1.7467f, 1.6106f, 1.6497f, 1.5702f, 1.5548f, 1.5745f, 1.6199f, 1.5633f, 1.5239f, 1.5796f, 1.5615f}; +const float scale_inv_ARSN[M] = {0.5462f, 0.5434f, 0.5553f, 0.5742f, 0.5800f, 0.5725f, 0.6209f, 0.6062f, 0.6369f, 0.6432f, 0.6351f, 0.6173f, 0.6397f, 0.6562f, 0.6331f, 0.6404f}; + +/* TCVQ Codebook */ +const float AR_TCVQ_CB_SUB1[2][128][2] = +{ + { + {-170.0561F,-169.3847F,},{-90.97870F,48.531700F,},{-148.6968F,17.218300F,},{-107.0229F,-34.21990F,},{-129.8378F,-87.31650F,},{-220.1001F,-234.4751F,},{-129.6736F,52.471700F,},{20.510900F,-288.6602F,}, + {-221.5495F,-0.070200F,},{58.214300F,123.37490F,},{-74.50640F,211.33990F,},{-48.14920F,123.86970F,},{-192.6126F,-247.4666F,},{-206.1983F,104.78470F,},{-125.3893F,-150.7979F,},{-168.7912F,-86.03110F,}, + {-95.16320F,-89.65400F,},{-12.70900F,177.33540F,},{-73.43770F,-250.7212F,},{-51.23060F,-84.00830F,},{-264.2502F,102.67830F,},{-184.2570F,-157.5882F,},{-121.9781F,-62.24850F,},{-132.6231F,115.89740F,}, + {-47.38870F,-84.58990F,},{-2.521300F,94.296500F,},{-79.13010F,-82.28630F,},{-49.25610F,-5.992200F,},{-286.7041F,-146.2168F,},{-178.7492F,-2.262600F,},{-115.8487F,-10.64920F,},{-119.9947F,-216.1283F,}, + {-69.10170F,1.3002000F,},{-68.48210F,-106.6926F,},{24.572700F,141.84890F,},{51.813600F,206.02520F,},{-51.84400F,-72.25850F,},{-175.4067F,-470.9963F,},{-112.2572F,-109.9498F,},{-51.26580F,339.48830F,}, + {-38.93840F,-40.88940F,},{-29.20570F,-69.73790F,},{-55.22180F,51.015500F,},{-12.33040F,42.160700F,},{-31.81780F,63.017700F,},{-174.1785F,-89.95120F,},{-110.4181F,-345.4240F,},{-49.84300F,-64.35890F,}, + {-59.63520F,-175.9810F,},{-69.02910F,-44.58650F,},{-43.97120F,-49.59230F,},{-87.25920F,-138.5465F,},{-96.25540F,-174.5186F,},{-154.7553F,-275.2756F,},{-109.5143F,128.62810F,},{-14.54350F,-25.04360F,}, + {-46.05230F,81.366800F,},{-32.03440F,24.870900F,},{-132.5154F,-143.2318F,},{-22.59640F,-51.55940F,},{-178.7877F,251.71930F,},{-148.7196F,-212.2087F,},{-106.1241F,217.56180F,},{24.099800F,29.423900F,}, + {-119.7589F,-323.8735F,},{121.21500F,173.78130F,},{28.604700F,-10.13160F,},{37.177600F,85.584900F,},{87.071500F,238.62500F,},{109.09800F,76.070100F,},{167.92980F,224.78890F,},{165.46650F,86.241500F,}, + {-9.919200F,0.5865000F,},{126.17610F,92.028000F,},{-38.94060F,-121.2069F,},{4.4071000F,-13.64760F,},{32.528700F,-1.269700F,},{109.85480F,288.47620F,},{193.40720F,153.42400F,},{34.912700F,501.59090F,}, + {12.630000F,53.019400F,},{11.431500F,13.336900F,},{191.94830F,224.70850F,},{40.979900F,-73.55240F,},{5.8897000F,-171.8742F,},{111.18560F,4.0700000F,},{201.66060F,-41.15440F,},{122.30070F,274.89960F,}, + {-2.425900F,-107.2105F,},{-24.07350F,-25.13440F,},{-4.758000F,-49.75210F,},{66.313900F,932.60360F,},{63.427900F,76.575200F,},{131.07660F,161.35400F,},{211.93280F,81.864800F,},{90.057500F,-27.39110F,}, + {-0.656200F,269.81920F,},{38.372300F,52.479100F,},{9.8096000F,55.003200F,},{101.87250F,118.98060F,},{121.92950F,-125.7858F,},{131.37830F,88.916800F,},{218.95100F,305.25590F,},{299.20050F,200.64100F,}, + {-5.459000F,-45.76330F,},{64.972100F,353.45030F,},{-19.39350F,0.4459000F,},{183.81020F,144.04150F,},{134.69810F,96.639400F,},{135.54900F,-149.4564F,},{219.02860F,440.63140F,},{200.41160F,402.24270F,}, + {39.254000F,-5.942300F,},{72.189700F,27.428900F,},{65.129100F,51.010200F,},{47.723500F,14.090300F,},{219.06510F,290.25100F,},{156.45050F,43.423900F,},{232.59480F,-226.2346F,},{263.13970F,83.869400F,}, + {74.758000F,73.874300F,},{14.975400F,-30.59550F,},{167.16620F,0.0965000F,},{101.95820F,53.053900F,},{-11.37910F,-38.59220F,},{158.02420F,120.38810F,},{239.72370F,224.38630F,},{657.07030F,665.65960F,}, + }, + + { + {-368.0999F,-65.52540F,},{-102.2718F,-140.9826F,},{-20.59040F,-66.70470F,},{-95.79090F,184.47330F,},{-837.7641F,-904.4130F,},{-510.6703F,492.69680F,},{-339.6600F,-757.9813F,},{-254.7818F,-220.3240F,}, + {-195.1893F,174.78510F,},{-225.8519F,-77.48110F,},{-216.3949F,43.255000F,},{-38.17870F,-32.99880F,},{-513.7912F,0.1722000F,},{-480.2339F,-631.9721F,},{-338.9732F,89.728000F,},{-150.2896F,414.33830F,}, + {-299.8150F,-389.7000F,},{-78.78780F,-23.51500F,},{-110.4856F,-76.99170F,},{-55.54460F,-127.1259F,},{-217.9132F,295.10380F,},{-475.2952F,178.16700F,},{-313.6053F,299.37920F,},{-383.7671F,290.27470F,}, + {-162.0853F,-139.3168F,},{-10.81860F,411.75810F,},{44.425800F,-95.93580F,},{31.498700F,285.88550F,},{-313.9570F,-197.7654F,},{-439.8449F,-43.63990F,},{-311.4479F,-51.44460F,},{-112.9209F,-79.77700F,}, + {-135.4290F,-11.18290F,},{-14.37020F,-101.2914F,},{-55.36790F,-170.9950F,},{-97.12010F,33.922700F,},{-341.4857F,133.28130F,},{-419.5535F,-1029.264F,},{-261.0493F,-606.2968F,},{-445.1823F,-298.5443F,}, + {-95.70290F,-200.4782F,},{-18.66770F,205.38260F,},{5.2869000F,154.20340F,},{-176.5040F,-252.4035F,},{-172.0901F,-378.6187F,},{-372.2359F,-501.4665F,},{-252.0296F,-151.3651F,},{-287.6742F,43.301600F,}, + {-63.75070F,119.02160F,},{-136.2005F,87.531000F,},{-87.96100F,287.68010F,},{36.839700F,-33.04480F,},{-118.0163F,-214.5814F,},{-365.9238F,-348.5409F,},{-236.4188F,-425.5134F,},{-25.16220F,-39.63130F,}, + {-63.00320F,-82.32200F,},{-152.9630F,-507.2372F,},{-57.66390F,48.660600F,},{5.3785000F,51.097300F,},{-168.7345F,-49.50600F,},{-359.4378F,-199.1688F,},{-233.7651F,-285.0083F,},{33.347500F,60.305100F,}, + {9.5961000F,-60.67060F,},{-22.43980F,93.048400F,},{184.09080F,107.94670F,},{164.32090F,265.57780F,},{-67.49340F,123.30580F,},{233.22030F,704.96710F,},{353.99250F,-262.9922F,},{210.06920F,175.77800F,}, + {-104.2510F,-314.3242F,},{0.9024000F,-7.495400F,},{86.823700F,85.372000F,},{72.376700F,137.49970F,},{-13.00090F,-69.46920F,},{236.74980F,46.279600F,},{374.54780F,-27.20110F,},{136.88650F,-35.73790F,}, + {-34.16180F,16.487600F,},{283.87900F,353.51860F,},{21.261500F,12.921800F,},{123.46920F,17.014100F,},{98.105500F,5.7719000F,},{238.18290F,-47.81850F,},{386.73840F,560.96730F,},{32.152700F,578.18980F,}, + {70.706200F,208.99530F,},{69.254100F,50.614900F,},{273.61320F,220.89670F,},{244.46280F,129.16830F,},{108.85950F,215.41490F,},{265.47770F,276.31920F,},{395.46140F,283.90850F,},{412.94530F,299.13520F,}, + {-5.075000F,-154.7571F,},{142.09250F,160.91980F,},{172.66840F,-70.68220F,},{79.050300F,-150.7248F,},{220.80900F,545.83980F,},{289.05480F,1023.7731F,},{421.94000F,140.86480F,},{436.59640F,74.580500F,}, + {31.476700F,103.73850F,},{84.791000F,-50.67070F,},{136.49490F,394.28200F,},{264.97310F,-186.0375F,},{531.67460F,343.03590F,},{310.71060F,184.35030F,},{494.98260F,403.81940F,},{406.31780F,490.15840F,}, + {137.11870F,78.459100F,},{-26.93550F,-247.3193F,},{-13.90060F,-408.4927F,},{315.74950F,11.906200F,},{507.81160F,-77.48790F,},{313.84650F,400.68920F,},{543.13960F,-127.4566F,},{895.02000F,968.45590F,}, + {65.022700F,5.1458000F,},{203.36110F,32.767800F,},{99.442400F,-280.2416F,},{385.57300F,174.81870F,},{303.53400F,86.087500F,},{316.97760F,81.139300F,},{545.10640F,789.31480F,},{585.50660F,162.80340F,}, + } +}; + +const float AR_TCVQ_CB_SUB2[2][64][2] = +{ + { + {-139.4748F,-20.51230F,},{-205.2710F,65.240700F,},{-90.66390F,99.509000F,},{-51.55990F,-140.1515F,},{-367.2977F,-86.40560F,},{-101.5758F,-506.4093F,},{-467.6164F,-177.7713F,},{-325.3952F,19.243000F,}, + {-51.50950F,-0.580700F,},{-156.7042F,-109.3179F,},{-82.92030F,-84.85600F,},{-75.64660F,36.105400F,},{-226.3753F,-277.4524F,},{-336.8399F,-293.0652F,},{-261.4553F,168.08600F,},{-203.4850F,280.69810F,}, + {-242.0593F,-177.4998F,},{-93.17880F,198.93370F,},{-6.034900F,-224.4959F,},{152.10510F,274.83370F,},{-347.4922F,202.31740F,},{-450.9290F,32.755600F,},{-246.8381F,-399.5943F,},{-242.2880F,-493.4214F,}, + {-104.8258F,-183.7260F,},{-127.2704F,-288.3692F,},{17.116300F,247.94440F,},{28.590000F,141.33180F,},{-88.39520F,-8.409100F,},{-244.1211F,-41.49450F,},{-281.3448F,-44.43050F,},{-435.1837F,-417.8239F,}, + {7.2419000F,-97.64420F,},{32.515300F,38.550200F,},{13.574300F,-6.174500F,},{102.88080F,-123.3195F,},{184.39410F,428.29360F,},{-20.13120F,-127.9658F,},{-97.25060F,379.22250F,},{541.89470F,342.12550F,}, + {3.8567000F,79.183500F,},{339.32440F,253.39800F,},{87.921000F,66.552800F,},{117.63820F,32.476100F,},{490.72400F,188.26100F,},{152.82630F,-303.6073F,},{415.46300F,-125.0126F,},{20.317700F,471.51620F,}, + {120.83170F,146.52980F,},{183.34470F,88.231900F,},{241.62970F,156.33030F,},{23.616600F,-36.17640F,},{130.82320F,95.319300F,},{123.34420F,-25.34570F,},{-17.53680F,-385.5626F,},{253.17360F,-114.7059F,}, + {85.112600F,-25.82990F,},{-42.33470F,-51.85570F,},{195.47230F,-7.405400F,},{322.01970F,63.832500F,},{188.75460F,-173.2249F,},{506.79120F,93.875700F,},{390.46690F,470.76120F,},{243.34080F,526.34460F,}, + }, + + { + {-165.6917F,-377.1008F,},{-17.98370F,-75.86160F,},{7.9923000F,116.25350F,},{-130.2646F,-108.4639F,},{-311.2591F,-203.8264F,},{-339.0670F,-23.57200F,},{-7.653600F,-54.53950F,},{-423.8622F,-353.1093F,}, + {-240.0843F,-95.08200F,},{-143.2687F,8.5443000F,},{-101.9498F,-202.8074F,},{-43.42630F,-10.37850F,},{-291.0372F,55.326100F,},{-189.0665F,-593.2565F,},{-128.3240F,5.0444000F,},{-420.8219F,35.762800F,}, + {-206.5327F,85.114800F,},{-202.6915F,-233.0529F,},{-107.8853F,-28.10810F,},{-33.95630F,-155.5147F,},{-19.77350F,-490.9996F,},{-113.7118F,159.73310F,},{-345.0899F,238.75620F,},{68.787700F,-156.6325F,}, + {-52.29900F,-95.54260F,},{14.606500F,197.56230F,},{9.1784000F,-3.906100F,},{-88.07510F,114.63690F,},{-356.4571F,-517.1363F,},{-68.02240F,-113.1240F,},{-424.2482F,-150.8795F,},{-54.13860F,-30.29230F,}, + {-48.11040F,48.722800F,},{-9.974700F,-288.3043F,},{44.249300F,-134.2835F,},{68.270600F,70.915400F,},{294.67340F,-174.3828F,},{471.33110F,206.81070F,},{363.89680F,386.90480F,},{52.930000F,47.618800F,}, + {104.26640F,127.63530F,},{149.10830F,-71.25040F,},{280.53550F,183.93680F,},{288.38200F,42.039600F,},{61.611600F,50.856600F,},{170.86680F,156.74650F,},{139.90090F,-260.6101F,},{539.24370F,326.70950F,}, + {71.975100F,-6.711500F,},{169.81850F,90.253300F,},{157.30500F,24.483300F,},{59.160200F,-48.84550F,},{-42.61460F,-92.55310F,},{270.15440F,-94.32920F,},{487.06470F,75.464100F,},{345.55540F,126.52380F,}, + {-110.4957F,258.30830F,},{17.373900F,41.055800F,},{60.912700F,355.85580F,},{151.18090F,229.57390F,},{269.34040F,569.72710F,},{259.50450F,412.82330F,},{-14.73050F,568.47830F,},{252.07040F,354.99801F,}, + } +}; + +const float AR_TCVQ_CB_SUB3[4][32][2] = +{ + { + {-190.2462F,3.7460000F,},{-178.0891F,-156.6944F,},{37.733100F,176.00550F,},{-93.45970F,165.15130F,},{-267.7612F,-511.1700F,},{27.017600F,-276.8829F,},{-118.0160F,-462.8076F,},{188.15520F,-112.6265F,}, + {-112.2084F,-272.1046F,},{-75.63800F,28.803700F,},{-62.17480F,-51.65160F,},{-62.91250F,-122.3795F,},{-315.9380F,163.32500F,},{-335.8190F,-361.7829F,},{-10.02270F,-28.26150F,},{-411.0079F,-169.0698F,}, + {21.274600F,52.847800F,},{41.786600F,-55.20310F,},{131.61950F,-6.998400F,},{157.68690F,287.15550F,},{-42.42940F,-201.8275F,},{281.21280F,-25.80890F,},{-13.25970F,522.18800F,},{-66.78560F,354.06180F,}, + {20.563700F,-135.3851F,},{140.59070F,104.26130F,},{279.11580F,136.98410F,},{39.195800F,51.957500F,},{34.262500F,51.346000F,},{381.14700F,390.58580F,},{491.52390F,213.96490F,},{288.60580F,536.49710F,}, + }, + + { + {-133.0008F,-181.1299F,},{-84.55430F,-304.3680F,},{40.548600F,-157.9567F,},{-35.81290F,-86.14820F,},{-296.9231F,-235.1026F,},{-357.0671F,-316.6972F,},{-258.1654F,-349.4409F,},{-504.7979F,-113.4180F,}, + {-123.9764F,51.459200F,},{-224.7199F,-60.69300F,},{-89.06170F,-50.36220F,},{-100.2134F,190.61760F,},{-111.9099F,-529.1262F,},{-36.32900F,-101.2426F,},{-311.5327F,69.813400F,},{-318.3195F,-534.8423F,}, + {84.270600F,222.53200F,},{-0.942100F,28.769200F,},{213.25620F,65.535600F,},{97.994500F,73.849700F,},{30.130700F,19.067100F,},{-368.2725F,229.34600F,},{148.61930F,481.44170F,},{418.05130F,44.184400F,}, + {45.929700F,-10.41460F,},{151.92930F,-55.78590F,},{7.0662000F,84.175000F,},{287.46830F,226.85480F,},{429.16810F,486.29900F,},{176.48300F,159.59660F,},{579.15160F,254.26680F,},{-68.04440F,453.68870F,}, + }, + + { + {-100.1363F,-189.9851F,},{-26.01900F,223.37290F,},{-2.345900F,62.933400F,},{-66.92170F,59.692200F,},{-463.9627F,-172.0395F,},{-422.4871F,43.361300F,},{-250.2149F,-359.6565F,},{-90.88240F,-37.63640F,}, + {-199.5678F,57.586700F,},{-112.5751F,-36.52960F,},{189.51950F,260.19820F,},{-238.2629F,-142.8535F,},{-139.3418F,-351.6046F,},{-336.3076F,-424.9823F,},{-30.62490F,-40.98700F,},{-103.6085F,-330.2230F,}, + {5.6849000F,7.1876000F,},{31.018100F,-149.6002F,},{-80.41110F,-100.6484F,},{119.56500F,103.01690F,},{11.508400F,27.501500F,},{13.331700F,25.835000F,},{457.61300F,261.34590F,},{52.531100F,28.992900F,}, + {203.48110F,71.918000F,},{51.549200F,32.858000F,},{141.30200F,-35.55590F,},{22.330400F,-70.91510F,},{349.22210F,178.05560F,},{447.99330F,289.70830F,},{82.904000F,107.10660F,},{348.09590F,102.38850F,}, + }, + + { + {37.061900F,181.46230F,},{3.6812000F,53.960400F,},{-142.5384F,-250.3814F,},{-155.8055F,67.085000F,},{-97.44510F,-42.54350F,},{-36.71330F,-123.6734F,},{-63.68890F,-97.47460F,},{-233.4995F,-274.8922F,}, + {-72.26240F,14.184600F,},{-183.6676F,-77.60290F,},{25.462700F,93.954700F,},{-40.64230F,-141.5510F,},{-85.75550F,-313.0151F,},{-338.1776F,-25.63660F,},{-363.6425F,-156.2840F,},{-67.37240F,-51.54950F,}, + {-58.24200F,-193.3120F,},{181.77980F,98.461400F,},{-70.01130F,-27.99830F,},{171.39450F,112.01820F,},{321.84770F,218.43910F,},{12.987700F,52.170200F,},{22.943500F,52.400800F,},{34.529100F,56.928800F,}, + {72.765700F,16.633700F,},{26.847700F,-102.3211F,},{104.45050F,-37.68410F,},{15.601300F,31.425000F,},{32.724900F,50.955400F,},{264.88060F,147.81980F,},{316.65590F,175.13690F,},{359.29350F,211.19690F,}, + } +}; + +const float SN_TCVQ_CB_SUB1[2][128][2] = +{ + { + {-249.7201F,40.935000F,},{-190.5588F,-175.3474F,},{-207.0069F,-316.9469F,},{-163.5806F,-247.6570F,},{-304.9679F,-414.6172F,},{-228.6147F,150.62910F,},{-195.6332F,-287.7428F,},{-190.9146F,-284.4862F,}, + {-274.4084F,-267.7108F,},{-199.2563F,-297.6162F,},{-152.2094F,-112.0928F,},{-148.0732F,-148.0190F,},{-223.7592F,-331.2033F,},{-227.6105F,-303.8584F,},{-195.2056F,-316.4586F,},{-262.2246F,-164.0172F,}, + {-201.5461F,313.27600F,},{-103.5079F,-192.2481F,},{-204.4250F,-221.9848F,},{-76.03550F,1125.8286F,},{-234.5633F,-67.04640F,},{-221.8844F,-339.4012F,},{-194.2347F,258.93820F,},{-251.0932F,-362.9766F,}, + {-135.0324F,-147.6629F,},{-98.67180F,-122.1392F,},{-163.4477F,232.42880F,},{-93.88090F,-181.8259F,},{-165.4640F,-213.2693F,},{-217.3162F,-119.1242F,},{-194.1371F,958.06900F,},{-176.2805F,-91.93370F,}, + {-176.7314F,-261.5485F,},{-143.7121F,-243.8883F,},{-148.1108F,-258.7831F,},{-118.9980F,-33.07910F,},{-214.2710F,155.74650F,},{-213.2181F,-251.6092F,},{-188.9855F,-166.4937F,},{-151.3290F,-213.3292F,}, + {-127.0467F,-214.8412F,},{-89.61480F,46.211900F,},{-32.48210F,392.23270F,},{-46.92120F,181.57460F,},{-113.0420F,-86.90470F,},{-201.7185F,60.547200F,},{-187.6557F,583.69500F,},{-161.9915F,53.907100F,}, + {-163.7852F,-39.11590F,},{-135.6215F,426.20040F,},{-169.3460F,29.788000F,},{-53.86960F,-113.5168F,},{-169.7033F,-280.7249F,},{-200.7809F,368.96580F,},{-184.8111F,-10.30170F,},{-56.33640F,-124.8625F,}, + {-146.8623F,587.82200F,},{-128.5270F,146.07030F,},{-123.4510F,-196.9422F,},{-22.75330F,-2.165400F,},{-105.3485F,-182.0782F,},{-198.0657F,-211.0788F,},{-181.9700F,-70.67280F,},{-100.1089F,-202.3083F,}, + {-76.38740F,283.61110F,},{-34.55220F,-139.0253F,},{-72.58420F,-153.9831F,},{11.931600F,-78.54570F,},{-30.11220F,-124.4284F,},{159.48950F,53.219000F,},{246.00260F,265.74940F,},{341.77020F,533.29990F,}, + {-78.13370F,-74.09460F,},{64.957700F,503.70880F,},{234.41130F,423.72930F,},{107.71920F,181.32610F,},{221.30620F,615.15230F,},{166.00660F,108.59500F,},{260.32690F,147.33710F,},{472.14910F,915.47850F,}, + {-71.05110F,-159.7740F,},{-37.06930F,-55.00150F,},{25.370000F,198.17320F,},{49.636800F,82.767400F,},{132.76160F,91.831000F,},{187.70590F,159.38410F,},{281.83160F,469.86870F,},{434.41380F,295.44770F,}, + {63.308300F,141.27590F,},{54.061700F,294.21520F,},{-65.88060F,-50.19340F,},{72.918300F,-12.50020F,},{26.680200F,-36.36690F,},{206.31630F,1119.4720F,},{306.99130F,308.17540F,},{487.14390F,573.31600F,}, + {-185.9491F,948.56350F,},{7.6792000F,52.069300F,},{0.9533000F,-92.26370F,},{166.57380F,312.24880F,},{153.64230F,230.62340F,},{207.81570F,610.05630F,},{315.18780F,208.51600F,},{550.64840F,410.71780F,}, + {-5.303600F,-102.8303F,},{32.350300F,-61.52830F,},{61.661100F,-14.86550F,},{240.57980F,214.70890F,},{329.97410F,212.08160F,},{209.52500F,92.791300F,},{356.06930F,594.08890F,},{638.68310F,525.05230F,}, + {45.061100F,-21.59060F,},{102.92090F,33.850300F,},{-49.38050F,91.477600F,},{147.03860F,74.554000F,},{179.35820F,1032.6932F,},{211.70910F,362.16160F,},{367.65010F,370.43750F,},{740.51460F,596.78260F,}, + {-7.303000F,724.00010F,},{177.80790F,142.93470F,},{213.00960F,110.61410F,},{324.63510F,326.04950F,},{475.33930F,330.59920F,},{218.87990F,211.76850F,},{395.71800F,253.94620F,},{744.16310F,915.21080F,}, + }, + + { + {-206.2475F,-95.90960F,},{-246.3082F,21.747300F,},{-280.0828F,-108.0290F,},{-15.81770F,518.20420F,},{-394.8764F,-268.7632F,},{-323.0682F,-133.0426F,},{-256.3050F,-624.6605F,},{-387.5242F,-608.8890F,}, + {-175.6982F,364.49880F,},{-210.8799F,823.99400F,},{-233.7273F,-494.8845F,},{-151.1368F,-199.8177F,},{-429.7681F,-772.9858F,},{-317.0574F,-240.9158F,},{-253.5630F,-57.26850F,},{-341.3936F,228.86220F,}, + {-281.1353F,-234.9062F,},{-109.7592F,-108.9512F,},{-225.6748F,247.90130F,},{65.929400F,31.226900F,},{-398.6104F,-52.49470F,},{-310.1716F,101.05650F,},{-249.3468F,320.56650F,},{-354.3097F,16.494000F,}, + {-277.0976F,-595.7491F,},{-188.3772F,523.29140F,},{-90.61150F,-382.6038F,},{40.513800F,903.74660F,},{-358.6226F,-460.4389F,},{-308.4215F,501.50370F,},{-237.7401F,882.27940F,},{-333.4506F,-381.9203F,}, + {-243.6204F,127.42030F,},{-75.62440F,666.13180F,},{-34.39620F,414.18390F,},{149.42210F,464.74430F,},{-162.1738F,5.7292000F,},{-308.1293F,-447.4555F,},{-236.0531F,158.90870F,},{-339.5853F,443.61930F,}, + {-196.4904F,-408.9761F,},{-212.8717F,-310.0990F,},{-50.11780F,183.79020F,},{32.747800F,249.33110F,},{-231.0534F,-589.2890F,},{-273.0207F,681.87410F,},{-234.5115F,-144.0888F,},{-306.1589F,641.38990F,}, + {-86.46690F,-261.1131F,},{-87.17310F,101.82230F,},{-32.13380F,-174.4069F,},{-147.5939F,-474.4269F,},{-289.3846F,378.38780F,},{-269.2454F,-337.1601F,},{-222.4565F,-232.3191F,},{-395.3117F,-157.5576F,}, + {-129.1616F,202.52440F,},{-68.35150F,307.27670F,},{-85.86670F,-1.271900F,},{-17.84710F,-328.4484F,},{-374.8384F,115.94100F,},{-260.0821F,26.484400F,},{-220.8236F,-532.8561F,},{-103.5023F,-8.057100F,}, + {253.68710F,299.43310F,},{99.798300F,140.48320F,},{132.05620F,-133.5340F,},{649.87660F,635.39510F,},{80.181400F,-88.45330F,},{377.92370F,11.967000F,},{475.26380F,362.41510F,},{663.04860F,481.53290F,}, + {125.93200F,564.57300F,},{125.00390F,699.34770F,},{161.43320F,82.756400F,},{388.46600F,81.488500F,},{299.40020F,103.03960F,},{380.48160F,344.82180F,},{479.55360F,94.266000F,},{656.04440F,313.06860F,}, + {29.314100F,121.82290F,},{294.35730F,556.75000F,},{136.00140F,242.52100F,},{251.75710F,185.26940F,},{393.60200F,297.97100F,},{404.77110F,790.64840F,},{528.97090F,207.17710F,},{629.35130F,831.62210F,}, + {63.429500F,363.62860F,},{344.74340F,320.98350F,},{386.67160F,190.67860F,},{240.19720F,-79.32440F,},{753.49380F,482.21660F,},{413.70600F,537.17310F,},{539.83860F,557.06520F,},{800.08120F,624.70540F,}, + {234.99860F,63.354100F,},{148.31920F,320.29180F,},{277.09270F,415.69540F,},{456.34320F,536.84340F,},{214.59280F,227.59820F,},{414.97560F,183.63070F,},{552.78850F,426.47270F,},{818.25130F,872.82940F,}, + {73.162100F,-246.0924F,},{46.113400F,-192.6345F,},{278.84370F,698.09160F,},{506.97560F,263.00580F,},{373.99370F,491.39020F,},{422.46610F,438.95710F,},{570.45150F,307.05580F,},{829.71370F,470.72770F,}, + {13.191300F,-73.93830F,},{20.994200F,-13.84500F,},{311.61780F,0.1251000F,},{291.89030F,929.08090F,},{554.80360F,450.16100F,},{436.77840F,653.52060F,},{582.72210F,893.43050F,},{943.77210F,632.08490F,}, + {452.66180F,701.26420F,},{152.06640F,-49.38430F,},{466.26870F,391.67580F,},{616.44670F,391.50590F,},{505.32310F,142.80040F,},{448.40750F,271.20620F,},{590.86500F,699.51280F,},{1072.8364F,818.59820F,}, + } +}; + +const float SN_TCVQ_CB_SUB2[2][64][2] = +{ + { + {-276.9441F,-237.9956F,},{-240.2330F,-400.5215F,},{-168.0618F,-125.3249F,},{-17.18770F,403.15550F,},{-410.3021F,-12.59720F,},{-401.4485F,-725.0255F,},{-378.9797F,-42.53260F,},{-223.4008F,-557.0544F,}, + {-221.8536F,60.339100F,},{-55.66380F,-73.67660F,},{-31.18270F,208.03420F,},{-14.70030F,-246.7032F,},{-152.7168F,497.98040F,},{-385.0540F,-285.9732F,},{-187.2953F,-199.3057F,},{-377.2813F,37.510600F,}, + {-330.8419F,-541.7451F,},{-349.7656F,237.12440F,},{-143.6113F,-363.2778F,},{-150.6399F,137.64050F,},{-113.2274F,3.7534000F,},{-325.2374F,36.570200F,},{-206.2273F,671.09990F,},{-82.19470F,45.011800F,}, + {-206.7859F,334.70390F,},{-283.9658F,-89.72660F,},{-50.10190F,12.089100F,},{51.980300F,29.857900F,},{-107.5514F,-303.3203F,},{-240.0561F,-533.9766F,},{-132.4427F,-5.247100F,},{-404.3979F,480.69020F,}, + {175.02300F,332.36460F,},{233.95710F,41.575700F,},{430.97410F,434.21950F,},{248.10350F,487.89410F,},{297.34090F,302.33480F,},{207.50040F,-27.75610F,},{281.96760F,184.93040F,},{299.70790F,161.32720F,}, + {100.61040F,107.78600F,},{135.17980F,-148.3558F,},{190.27510F,196.71720F,},{435.19680F,47.673600F,},{344.53480F,606.71120F,},{774.72370F,483.79650F,},{830.43490F,475.25730F,},{680.48470F,492.90810F,}, + {52.827400F,-98.47120F,},{84.402600F,213.06580F,},{195.15830F,-48.72150F,},{538.51170F,746.06460F,},{118.75210F,29.688100F,},{589.58180F,237.71470F,},{602.54520F,540.84130F,},{211.57020F,715.21980F,}, + {-93.92180F,-182.2399F,},{301.03150F,254.59590F,},{356.44790F,109.52270F,},{510.59830F,279.64910F,},{716.35110F,402.13940F,},{409.68830F,191.91910F,},{634.49470F,286.14310F,},{974.51980F,759.27030F,}, + }, + + { + {-284.8923F,-332.8634F,},{-230.3763F,119.65300F,},{-155.3427F,115.29910F,},{-12.21440F,5.0214000F,},{-257.4728F,-29.15460F,},{-235.7490F,-480.0754F,},{-202.7355F,-263.5491F,},{-321.4648F,18.445600F,}, + {-294.7758F,-80.74580F,},{-319.5455F,-165.6476F,},{-275.4234F,-501.8569F,},{-100.6586F,-323.5581F,},{-315.1043F,-276.3239F,},{-71.14410F,-278.0978F,},{-362.3847F,1.2822000F,},{-177.8863F,-448.9796F,}, + {-329.8557F,164.76280F,},{-232.8216F,-393.7935F,},{-196.9382F,-183.5567F,},{-179.3588F,287.84510F,},{-131.8585F,-284.4139F,},{-326.5890F,401.69820F,},{-239.3882F,485.08990F,},{-238.0748F,504.86220F,}, + {-111.2109F,13.897700F,},{-109.4982F,-165.7892F,},{39.187700F,49.242200F,},{-179.4392F,-52.56030F,},{-62.00650F,-58.79660F,},{-112.2621F,74.326700F,},{21.768200F,-102.5222F,},{-103.2492F,-123.8958F,}, + {-2.999300F,235.37390F,},{24.464500F,117.61140F,},{209.73120F,-60.41300F,},{112.71650F,222.38860F,},{75.577500F,-161.0497F,},{337.52400F,31.008400F,},{267.89200F,155.94850F,},{328.81130F,647.32140F,}, + {45.064300F,-82.58150F,},{237.66130F,132.73260F,},{4.8216000F,-253.8600F,},{277.79930F,430.66600F,},{39.273100F,199.22940F,},{139.99440F,-162.6469F,},{494.67560F,176.94150F,},{207.76570F,239.06330F,}, + {-100.0752F,-265.5905F,},{15.938200F,454.44360F,},{233.38360F,309.59500F,},{189.17920F,-23.98650F,},{185.76940F,100.17430F,},{675.38230F,486.70190F,},{472.14070F,579.37430F,},{575.03280F,434.82210F,}, + {152.01630F,129.07580F,},{68.559300F,-151.6359F,},{400.30690F,123.64090F,},{409.88600F,286.04450F,},{578.27810F,432.67370F,},{502.13100F,240.50900F,},{675.71990F,390.09750F,},{781.79560F,651.86880F,}, + } +}; + +const float SN_TCVQ_CB_SUB3[4][32][2] = +{ + { + {-147.1049F,-340.6287F,},{-158.8735F,313.47230F,},{-238.5137F,-175.2864F,},{-154.9957F,-34.27780F,},{-186.0273F,-415.2119F,},{-311.3175F,-97.27870F,},{-102.8572F,-258.6216F,},{-184.6271F,589.29930F,}, + {-279.5144F,121.03210F,},{-240.5628F,-383.6411F,},{-289.7553F,-518.3302F,},{77.502600F,128.26760F,},{-349.3453F,-608.3804F,},{-340.3397F,-491.6917F,},{-276.4456F,-539.0219F,},{-308.0319F,-331.5846F,}, + {25.470200F,-122.3889F,},{-23.10160F,-214.1888F,},{-0.632900F,26.756400F,},{142.04180F,-65.81690F,},{247.83350F,718.83400F,},{90.964100F,-139.8895F,},{485.82500F,582.96200F,},{641.17530F,379.95140F,}, + {79.709900F,202.16160F,},{199.84410F,369.96700F,},{239.35830F,94.047800F,},{423.70620F,282.88420F,},{317.36140F,127.76640F,},{337.65540F,94.710900F,},{217.43590F,208.86400F,},{764.35860F,815.30510F,}, + }, + + { + {-370.2650F,11.518200F,},{-323.1142F,-461.2694F,},{-135.8559F,-129.8608F,},{-14.09620F,84.290400F,},{-567.7608F,-453.9710F,},{-266.5970F,-249.6583F,},{-291.9762F,-592.7589F,},{-274.9419F,479.50260F,}, + {-208.9252F,-386.0126F,},{-214.9314F,-42.54240F,},{-186.7444F,227.07210F,},{-121.1719F,-272.9866F,},{-510.8044F,-87.79140F,},{-302.7620F,-617.7623F,},{-324.5998F,-240.0224F,},{-47.00890F,-86.66380F,}, + {12.928800F,78.024900F,},{47.313200F,-86.25450F,},{183.98160F,182.61360F,},{316.09290F,122.14870F,},{371.33160F,278.26560F,},{168.42590F,-225.2161F,},{775.28210F,548.66520F,},{642.86270F,346.51310F,}, + {51.413000F,448.60110F,},{112.29160F,198.86870F,},{133.44860F,-92.65510F,},{392.28070F,469.91310F,},{124.10680F,-283.7072F,},{583.68000F,286.00210F,},{521.95260F,271.37440F,},{931.01620F,692.52800F,}, + }, + + { + {-341.3078F,-146.2225F,},{-92.54280F,10.245600F,},{6.3784000F,340.04950F,},{-277.1624F,169.62960F,},{15.939400F,-300.4278F,},{-413.4964F,-527.4807F,},{25.713000F,81.620300F,},{-395.4344F,-535.2822F,}, + {-30.72550F,-179.8318F,},{-261.9265F,-367.7827F,},{-4.797200F,22.196000F,},{-63.59540F,-168.5926F,},{-320.1832F,-419.0108F,},{-346.2061F,-53.06720F,},{-127.6520F,-195.8498F,},{-21.51770F,-5.277200F,}, + {254.60570F,253.18280F,},{143.04340F,160.79980F,},{240.36910F,98.565800F,},{60.270300F,84.249700F,},{4.6884000F,24.362900F,},{88.200900F,69.498000F,},{659.95560F,473.75490F,},{293.20990F,70.108000F,}, + {11.956700F,71.243400F,},{109.95050F,-114.0644F,},{-138.5130F,-251.0179F,},{366.76410F,361.08470F,},{241.70930F,34.973000F,},{654.41940F,441.34520F,},{322.92560F,106.27710F,},{605.58650F,564.89110F,}, + }, + + { + {-142.8305F,-357.6638F,},{-135.1517F,-91.95450F,},{-202.7971F,-55.12860F,},{10.622800F,119.25650F,},{-99.61230F,-36.02510F,},{-247.5775F,-381.3310F,},{-193.0612F,-420.8008F,},{-130.4904F,-356.4558F,}, + {-220.9295F,27.109700F,},{40.264600F,84.888100F,},{-115.6413F,-362.4221F,},{-195.5899F,-402.2075F,},{-170.5517F,-393.0729F,},{-56.84850F,-56.71290F,},{-82.37190F,-78.84410F,},{24.433000F,140.77510F,}, + {63.625500F,-48.12080F,},{296.32420F,215.87390F,},{32.041200F,80.732200F,},{-69.63830F,-95.39770F,},{63.503200F,133.94610F,},{450.10010F,363.00900F,},{76.867200F,96.687600F,},{16.700500F,-57.93000F,}, + {66.165600F,144.72830F,},{-183.0404F,-407.2658F,},{268.25850F,163.71400F,},{219.75790F,95.572100F,},{411.11030F,329.38500F,},{101.35990F,133.20170F,},{415.09750F,248.72830F,},{337.80520F,255.31020F,}, + } +}; + + + +const float AR_SVQ_CB1[32][8] = +{ + {-0.339000F, 1.5012220F, 6.1853590F, 1.6161480F, 17.3955550F, -42.95738F, 3.77089400F, 65.3032460F}, + {-1.351974F, 0.8601210F, 3.1036570F, -4.589009F, -2.7011160F, 9.0795180F, 109.094322F, -18.118401F}, + {-0.051575F, 0.6542590F, 0.3318340F, 3.1915060F, -28.443743F, -15.45044F, 27.7376230F, -38.083717F}, + {-0.147188F, 0.7379020F, 16.596052F, 29.073309F, -15.221093F, 27.937109F, 10.4191210F, 3.21426900F}, + {-0.174719F, 0.3557820F, 3.3571020F, -2.442146F, 15.4601880F, -25.54004F, -21.377092F, -50.052696F}, + {-0.080591F, -0.031826F, 3.2809340F, -3.976039F, -16.756672F, 41.078621F, -1.8470560F, -49.312294F}, + {0.0404590F, -0.057671F, 4.6628590F, -1.082124F, -38.447117F, -7.158832F, -34.349442F, -28.560730F}, + {-0.191480F, 0.3673300F, -2.228691F, -4.763459F, -19.210003F, -70.05153F, -11.678687F, -5.9500840F}, + {-0.475299F, -0.021802F, 9.2386790F, 30.398779F, 9.72456700F, -26.96944F, -10.201661F, -5.2955280F}, + {-0.118115F, 0.3768040F, -0.202488F, -11.21918F, 8.99932300F, -25.32194F, -49.176136F, 13.3742710F}, + {0.6345730F, -1.451740F, -8.976882F, -2.891539F, -5.2668590F, -0.626124F, -8.6982240F, -1.6381660F}, + {-0.238382F, 0.4619150F, -0.689163F, 17.277664F, -21.009787F, -22.53389F, 41.9676740F, 23.4523370F}, + {0.1244690F, 0.2248090F, -1.099318F, -5.740384F, -21.103287F, 37.994751F, -39.226761F, 15.9438480F}, + {0.1411080F, -0.771317F, -31.48548F, 36.181248F, -5.2501020F, 7.1155840F, -12.062582F, -29.405684F}, + {-0.496825F, 0.9002190F, 0.1078140F, -1.812450F, 64.9175870F, -25.02316F, -18.672247F, 3.00326800F}, + {-0.877380F, -0.101788F, -10.38443F, -42.23261F, 14.1089240F, 1.3607690F, 4.64615900F, -31.426619F}, + {0.0982910F, 0.0130060F, -0.021137F, 1.7109680F, 32.0608750F, -0.580048F, 30.8528560F, 20.9283330F}, + {0.3703540F, -1.599935F, 1.9165930F, -3.437332F, -15.018585F, 112.87896F, 6.09581900F, 6.06509400F}, + {-0.239501F, 0.5997340F, 2.2582460F, -26.70808F, 23.7027260F, 26.134411F, -12.169220F, 39.0906330F}, + {1.1549010F, -2.333077F, 0.9387050F, -0.701751F, -0.2820180F, -2.514828F, -84.775269F, 106.470406F}, + {-0.120044F, 0.4967050F, -16.62750F, -24.21043F, -2.7719380F, -23.45862F, 10.9770750F, 30.4632150F}, + {-0.452348F, 0.9215980F, 4.0024690F, -0.181623F, 29.6472510F, 32.739918F, -21.457884F, -17.419983F}, + {-0.247916F, -0.922579F, 1.4429350F, 1.8360180F, -12.594628F, 29.236597F, 27.3443550F, 68.9287800F}, + {0.7650280F, -0.545622F, -0.185167F, 2.1660980F, 10.6230550F, 11.247939F, -85.990189F, -37.903763F}, + {-0.236738F, 0.4044940F, 35.338413F, -21.96892F, -4.0015380F, -6.422642F, 11.3325710F, 3.03891400F}, + {-0.526660F, 1.1162520F, -3.871234F, -0.059409F, 0.78312500F, -9.391847F, 18.9848520F, -131.23975F}, + {-0.433725F, 0.2320700F, -3.264241F, -3.579835F, 21.6186620F, -52.31819F, 41.0296550F, -17.336693F}, + {-0.150218F, 0.2436480F, -6.385384F, 26.976192F, 20.1004640F, 15.708211F, -20.112616F, 38.2443770F}, + {-0.024170F, 0.8500570F, -4.579786F, -12.50560F, -54.536289F, 19.191902F, 19.6398750F, 10.2497080F}, + {-0.124103F, 1.0465660F, 3.0224720F, 11.137490F, 30.1374190F, 9.5446160F, 29.8574750F, -40.261337F}, + {-0.196671F, 0.7005810F, -9.238495F, -7.187382F, 2.81278600F, 38.941822F, 36.7256850F, 1.86695500F}, + {0.0413730F, -0.259086F, 3.8143860F, 10.183937F, -33.918419F, -13.19506F, -21.927582F, 40.2238810F}, +}; + +const float AR_SVQ_CB2[16][8] = +{ + {-14.44511F, -23.12155F, 81.241760F, -34.49714F, 21.0647720F, 22.618990F, -6.4248760F, -9.472386F}, + {-0.129507F, -38.33505F, 3.5780910F, -25.32102F, -71.163628F, -8.083008F, 7.34998800F, 3.5089460F}, + {-0.531659F, 42.984482F, -2.949942F, 23.185688F, 78.3983150F, 3.3631430F, -14.996096F, -8.493151F}, + {-0.553943F, 15.531711F, -8.511508F, -71.40907F, 18.1345100F, -63.29620F, -15.015837F, -2.255207F}, + {4.7402910F, 0.7143230F, -75.55894F, 25.115595F, -16.831573F, -18.81928F, 4.13968000F, 3.3929720F}, + {-32.50397F, 68.406067F, -3.199107F, -21.32696F, -25.471333F, 25.902178F, 10.0576690F, 2.3217050F}, + {11.180623F, 1.3522740F, 0.9572140F, -3.889576F, -39.069595F, 114.30133F, 29.1799030F, -4.798602F}, + {2.5571490F, -21.08170F, -29.49300F, -35.49685F, 24.4835700F, 46.452934F, -32.716568F, -32.81908F}, + {1.2645100F, 2.9239020F, 2.2633560F, 2.5141150F, -11.900713F, 5.8893120F, -68.704033F, 65.771515F}, + {-4.081663F, 17.567835F, 10.064315F, 22.194927F, -36.000233F, -26.37986F, -45.523380F, -52.28128F}, + {0.0228670F, -14.62688F, -13.12301F, -27.02922F, 41.2410550F, 21.242199F, 47.1964420F, 51.328987F}, + {-9.871984F, -24.99879F, 2.6157990F, 80.172798F, 0.43614800F, 36.480019F, 10.4512970F, 2.2055040F}, + {25.002769F, 10.773156F, 19.834276F, 2.9322950F, -2.5556860F, 6.9424410F, 10.6092970F, 0.1834710F}, + {-7.853089F, 17.244720F, 22.289469F, 30.428480F, -21.601667F, -66.57227F, 34.5492820F, 36.391033F}, + {4.8071940F, -49.02123F, 4.8164340F, 21.801281F, 39.0447200F, -62.45168F, -33.871502F, -1.336098F}, + {-2.572755F, -7.192194F, -2.623712F, -2.309371F, 14.2487590F, -21.16166F, 68.2372970F, -68.92265F}, +}; + + + +const float W_DTX_HO[HO_HIST_SIZE] = +{ + 0.2f, 0.16f, 0.128f, 0.1024f, 0.08192f, 0.065536f, 0.0524288f, 0.01048576f +}; +const float ENR_ATT[5] = +{ + 1.7938412f, 1.3952098f, 1.0962363f, 0.9965784f, 0.9965784f +}; +const float HO_ATT[5] = +{ + 0.5370318f, 0.6165950f, 0.6839116f, 0.7079458f, 0.7079458f +}; + +const short uniform_model[] = { MAX_AR_FREQ, MAX_AR_FREQ / 2, 0 }; + + +/*-----------------------------------------------------------------* + * LSF quantization - mid-frame quantization tables + *-----------------------------------------------------------------*/ + +const float tbl_mid_gen_wb_2b[] = +{ + 0.4656f, 0.6281f, 0.7148f, 0.6457f, 0.6442f, 0.5957f, 0.5953f, 0.5216f, 0.4722f, 0.4609f, 0.4141f, 0.3861f, 0.3809f, 0.3685f, 0.4144f, 0.7097f, + 0.1809f, 0.1051f, 0.2402f, 0.3904f, 0.3790f, 0.4562f, 0.4577f, 0.5524f, 0.6081f, 0.5894f, 0.6131f, 0.6512f, 0.6503f, 0.6465f, 0.6216f, 0.4204f, + 0.4828f, 0.4701f, 0.1855f, 0.2034f, 0.1897f, 0.1691f, 0.1876f, 0.1558f, 0.1762f, 0.1863f, 0.1950f, 0.1997f, 0.2279f, 0.2492f, 0.3031f, 0.2513f, + 0.8591f, 0.9902f, 0.8941f, 0.8507f, 0.8395f, 0.8579f, 0.8529f, 0.8665f, 0.8549f, 0.8490f, 0.8456f, 0.8310f, 0.8161f, 0.7884f, 0.7167f, 0.7381f +}; + + +const float tbl_mid_gen_wb_5b[] = +{ + 0.7947f, 0.9837f, 0.8671f, 0.7440f, 0.7914f, 0.7161f, 0.7356f, 0.7865f, 0.8401f, 0.8431f, 0.8563f, 0.8033f, 0.6896f, 0.4937f, 0.3437f, 0.3075f, + 0.4612f, 0.2591f, 0.4370f, 0.5153f, 0.3171f, 0.5653f, 0.3472f, 0.5987f, 0.6648f, 0.5528f, 0.6331f, 0.7603f, 0.7581f, 0.6949f, 0.7584f, -0.5701f, + 1.1047f, 1.2127f, 1.0304f, 0.9669f, 0.9211f, 0.9570f, 0.9737f, 1.0175f, 1.0595f, 1.0628f, 1.0624f, 1.0506f, 1.0449f, 1.0223f, 0.9471f, 0.7819f, + 0.5180f, 0.7050f, 0.3588f, 0.7186f, 0.4978f, 0.3805f, 0.6429f, 0.6934f, 0.5602f, 0.2931f, 0.0892f, 0.1234f, 0.2023f, 0.5777f, 0.8607f, 0.4873f, + 0.3062f, 0.3852f, 0.4086f, 0.1959f, 0.5432f, 0.5655f, 0.4243f, 0.7347f, 0.4984f, 0.4668f, 0.6266f, 0.7349f, 0.3971f, 0.1670f, 0.2119f, 1.6488f, + 0.7244f, 0.7778f, 0.5486f, 0.3610f, 0.5400f, 0.8138f, 0.9969f, 1.0270f, 0.9713f, 0.8714f, 0.6736f, 0.3734f, 0.3453f, 0.3443f, 0.3385f, 0.3996f, + 0.6084f, 0.6795f, 0.7118f, 0.5561f, 0.6997f, 0.8225f, 0.8165f, 0.5717f, 0.2765f, 0.5144f, 0.8840f, 1.2194f, 1.1934f, 1.1069f, 0.5796f, 0.2798f, + 0.3175f, 0.6022f, 0.3374f, 0.6010f, 0.4594f, 0.4490f, 0.6831f, 0.2538f, 0.7456f, 0.8330f, 0.6722f, 0.6850f, 0.8292f, 0.6778f, 0.1392f, 1.2199f, + 0.8647f, 0.8161f, 0.6485f, 0.6343f, 0.3797f, 0.6515f, 0.4315f, 0.3022f, 0.3024f, 0.2120f, 0.2551f, 0.4923f, 0.6934f, 0.7993f, 0.8923f, 1.4418f, + 0.9937f, 1.0501f, 0.8747f, 0.8225f, 0.7346f, 0.6469f, 0.6941f, 0.5764f, 0.5015f, 0.5440f, 0.4532f, 0.3822f, 0.3245f, 0.2851f, 0.2747f, 0.9828f, + 0.0887f, 0.2277f, 0.7413f, 0.4800f, 0.2756f, 0.2946f, 0.5888f, 0.6998f, 0.6227f, 0.7478f, 0.5725f, 0.1379f, 0.1431f, 0.1805f, 0.4829f, 0.8794f, + 0.7376f, 0.1250f, 0.6556f, 0.7320f, 0.6059f, 0.6806f, 0.6199f, 0.7132f, 0.8434f, 1.0333f, 1.0499f, 0.7492f, 0.6957f, 0.9826f, 1.2112f, 1.0154f, + 0.3330f, 0.1984f, 0.5798f, 0.6109f, 0.7079f, 0.6028f, 0.7755f, 0.3997f, 0.2174f, 0.3778f, 0.1806f, 0.3828f, 0.6677f, 0.1698f, -0.0764f, 0.2957f, + 0.5380f, 0.3941f, 0.1545f, 0.1817f, 0.1492f, 0.1176f, 0.1401f, 0.1443f, 0.1624f, 0.2161f, 0.1050f, 0.0465f, 0.0992f, 0.1548f, 0.2871f, 0.4829f, + 0.2054f, -0.0147f, 0.0101f, 0.1512f, 0.1155f, 0.1964f, 0.2419f, 0.3925f, 0.4822f, 0.5127f, 0.5489f, 0.5979f, 0.5555f, 0.4388f, 0.2863f, 0.2983f, + 0.1288f, 0.3915f, 0.9106f, 0.8310f, 0.8671f, 0.8521f, 0.9646f, 1.0005f, 0.8326f, 0.7556f, 0.7819f, 0.9050f, 0.9725f, 0.9163f, 0.8449f, 1.2049f, + 0.3862f, 0.9760f, 1.0310f, 1.0706f, 1.0307f, 1.0134f, 0.8999f, 0.8605f, 0.7434f, 0.6955f, 0.6213f, 0.5850f, 0.6099f, 0.5950f, 0.5231f, 0.8160f, + 0.4494f, 0.0389f, 0.0654f, 0.3875f, 0.5487f, 0.6697f, 0.7089f, 0.7020f, 0.6666f, 0.5399f, 0.4341f, 0.4210f, 0.6284f, 0.9229f, 0.7662f, 0.4618f, + 0.2426f, 0.5138f, 0.8489f, 0.7178f, 0.9105f, 0.9475f, 0.5281f, 0.6052f, 0.6291f, 0.2624f, 0.3647f, 0.3014f, 0.1434f, 0.1341f, 0.4881f, 0.4822f, + 0.1594f, 0.2811f, 0.9458f, 1.0056f, 0.7466f, 0.3447f, 0.2163f, 0.1379f, 0.3098f, 0.4083f, 0.6490f, 0.5827f, 0.4478f, 0.6663f, 0.6737f, 0.6829f, + 0.5054f, 0.5285f, 0.4076f, 0.3663f, 0.3258f, -0.0096f, -0.0710f, -0.2110f, -0.0830f, 0.1579f, 0.3359f, 0.4516f, 0.4427f, 0.5405f, 0.6043f, 0.3350f, + 0.6481f, 0.4408f, 0.1212f, 0.4304f, 0.2494f, 0.4807f, 0.2526f, 0.1751f, 0.5094f, 0.3185f, 0.3301f, 0.4504f, 0.4499f, 0.2312f, 0.1710f, -0.2053f, + 0.7435f, 0.5872f, 0.1184f, 0.1298f, 0.2084f, 0.3730f, 0.5612f, 0.8230f, 0.9030f, 0.8439f, 0.8983f, 0.9624f, 0.9242f, 0.8337f, 0.7372f, 0.4667f, + 0.8055f, 0.7332f, 0.1523f, 0.5286f, 0.8466f, 0.4619f, 0.4315f, 0.4763f, 0.3932f, 0.6572f, 0.6947f, 0.7321f, 0.7294f, 0.8217f, 1.1139f, 0.6574f, + 0.0249f, 0.0296f, 0.2452f, 0.4120f, 0.4165f, 0.4159f, 0.3285f, 0.3109f, 0.0730f, -0.0183f, 0.0082f, 0.0305f, 0.0754f, 0.1446f, 0.2425f, 0.1412f, + 0.6086f, 0.9737f, 0.8510f, 0.1865f, 0.0105f, 0.0343f, 0.1827f, 0.3665f, 0.5118f, 0.5408f, 0.5763f, 0.6490f, 0.7326f, 0.7545f, 0.8498f, 0.6690f, + 0.8440f, 0.9721f, 0.6413f, 0.3723f, 0.6549f, 0.3935f, 0.4616f, 0.3716f, 0.3139f, 0.3851f, 0.2738f, 0.1968f, 0.2633f, 0.3083f, 0.3398f, -0.1988f, + 0.8972f, 0.8181f, 0.2972f, 0.2365f, 0.3111f, 0.2415f, 0.3441f, 0.3439f, 0.2514f, 0.3043f, 0.4160f, 0.2861f, 0.1513f, 0.1437f, 0.1116f, 0.4593f, + 0.5325f, 0.3790f, -0.1778f, -0.2148f, 0.0383f, 0.1772f, 0.3178f, 0.2004f, 0.2038f, 0.2017f, 0.2756f, 0.3042f, 0.4692f, 0.5370f, 0.6363f, 0.0806f, + 0.0427f, 0.0436f, 0.0133f, 0.0101f, -0.0678f, -0.1081f, -0.0871f, -0.0717f, -0.0147f, 0.0031f, 0.0231f, 0.0648f, 0.0721f, 0.0178f, 0.0190f, 0.1752f, + 0.0608f, 0.0258f, 0.3738f, 0.8259f, 0.8728f, 0.9939f, 0.9193f, 0.9188f, 0.9589f, 0.8421f, 0.8073f, 0.7910f, 0.6457f, 0.5261f, 0.6520f, 0.5040f, + 0.3360f, 0.8495f, 0.8652f, 0.5642f, 0.3230f, 0.2924f, 0.2144f, 0.0397f, 0.0596f, 0.0316f, -0.0152f, -0.0704f, -0.0675f, 0.0751f, 0.0680f, 0.5636f +}; + + + +const float tbl_mid_voi_wb_1b[] = +{ + 0.5556f, 0.5614f, 0.5803f, 0.6146f, 0.6082f, 0.6382f, 0.6492f, 0.6840f, 0.6957f, 0.6899f, 0.6887f, 0.7039f, 0.7110f, 0.7170f, 0.7103f, 0.7392f, + 0.4658f, 0.4096f, 0.2833f, 0.3310f, 0.3540f, 0.3314f, 0.3406f, 0.3062f, 0.3059f, 0.3186f, 0.3194f, 0.2953f, 0.3098f, 0.3201f, 0.3667f, 0.3327f +}; +const float tbl_mid_voi_wb_4b[] = +{ + 0.5294f, 0.5170f, 0.4304f, 0.4984f, 0.4290f, 0.6661f, 0.3867f, 0.3063f, 0.5393f, 0.6129f, 0.1603f, 0.3603f, 0.6527f, 0.4752f, 1.0162f, 1.4353f, + 0.5102f, 0.4928f, 0.4840f, 0.4249f, 0.4917f, 0.4009f, 0.3227f, 0.5597f, 0.5797f, 0.3755f, 0.3920f, 0.1344f, 0.5097f, 0.9082f, 0.7013f, -0.5011f, + 0.5175f, 0.4830f, 0.5432f, 0.6072f, 0.6592f, 0.7000f, 0.7624f, 0.8040f, 0.9490f, 0.3295f, 0.3397f, 0.4241f, 0.1642f, -0.0386f, 0.6188f, 0.5986f, + 0.4839f, 0.4651f, 0.3263f, 0.3700f, 0.2745f, 0.3867f, 0.3851f, 0.5132f, 0.8931f, 0.8760f, 1.0596f, 0.8724f, 0.6003f, 0.5049f, 0.3836f, 0.3676f, + 0.4969f, 0.4703f, 0.4758f, 0.4850f, 0.4228f, 0.3513f, 0.7059f, 0.6520f, 0.2106f, 0.0978f, 0.1457f, 0.5174f, 0.8381f, 0.6043f, 0.0969f, 0.7654f, + 0.4801f, 0.4578f, 0.6019f, 0.4476f, 0.4376f, 0.3113f, 0.5259f, 0.7027f, 0.5497f, 0.8644f, 0.5973f, 0.1313f, 0.0133f, 0.2014f, 0.2304f, 1.0817f, + 0.5863f, 0.5892f, 0.6066f, 0.6727f, 0.7041f, 0.5282f, 0.6442f, 0.6023f, 0.8434f, 0.9365f, 0.6537f, 0.4810f, 1.2195f, 1.1746f, 0.9103f, 0.5129f, + 0.5512f, 0.5199f, 0.2983f, 0.5917f, 0.4551f, 0.5614f, 0.6073f, 0.7500f, 0.4989f, 0.5331f, 0.8576f, 0.6138f, 0.2936f, 0.8562f, 1.6316f, 0.7646f, + 0.5793f, 0.5562f, 0.6601f, 0.7161f, 0.5777f, 0.4990f, 0.4840f, 0.4064f, 0.5700f, 0.3790f, 0.7224f, 0.9551f, 0.7356f, 1.1203f, 0.2266f, 1.6149f, + 0.5042f, 0.5144f, 0.3071f, 0.4324f, 0.5917f, 0.4579f, 0.4522f, 0.2905f, 0.5115f, 0.5843f, 0.5678f, 0.6080f, 0.6961f, -0.0033f, -0.3615f, 0.0158f, + 0.5445f, 0.5767f, 0.6388f, 0.5713f, 0.7336f, 0.8816f, 0.7753f, 0.3746f, 0.0739f, 0.7244f, 0.6869f, 0.4683f, 0.4260f, 0.7398f, 0.4341f, 0.3155f, + 0.5650f, 0.5765f, 0.6671f, 0.5102f, 0.5444f, 0.7536f, 0.7220f, 0.8862f, 0.5741f, 0.5022f, 0.4807f, 1.1700f, 0.9869f, 0.4616f, 0.9180f, 0.0763f, + 0.6106f, 0.6861f, 0.7754f, 0.8440f, 0.8752f, 0.9422f, 0.9259f, 1.0264f, 1.0205f, 0.9623f, 0.8996f, 0.8816f, 0.8076f, 0.7327f, 0.6793f, 1.1467f, + 0.4955f, 0.5031f, 0.5100f, 0.5392f, 0.4195f, 0.1782f, 0.1258f, 0.0135f, 0.0714f, 0.2085f, 0.5150f, 0.6615f, 0.3156f, 0.3900f, 0.7506f, 0.3932f, + 0.4143f, 0.3389f, 0.2405f, 0.3305f, 0.3641f, 0.4799f, 0.3964f, 0.2111f, 0.0548f, -0.0133f, -0.0056f, -0.0572f, 0.0485f, 0.2417f, 0.2814f, 0.1920f, + 0.3978f, 0.2283f, 0.0296f, 0.0478f, 0.0913f, 0.0751f, 0.1447f, 0.1568f, 0.2758f, 0.3280f, 0.2700f, 0.2151f, 0.2654f, 0.2303f, 0.2255f, 0.2530f +}; + +const float tbl_mid_voi_wb_5b[] = +{ + 0.5105f, 0.4663f, 0.5008f, 0.6860f, 0.5005f, 0.5466f, 0.4820f, 0.6168f, 0.3562f, 0.3763f, 0.5162f, 0.4556f, 0.2225f, 0.7751f, 2.1033f, 0.5617f, + 0.5323f, 0.4977f, 0.2730f, 0.5039f, 0.3926f, 0.5704f, 0.7351f, 0.7961f, 0.7014f, 0.5227f, 0.3810f, 0.5430f, 0.7882f, 1.5348f, 0.5372f, 0.9516f, + 0.5161f, 0.4988f, 0.5340f, 0.5273f, 0.5461f, 0.5780f, 0.5404f, 0.6856f, 0.7294f, 0.0169f, 0.7186f, 0.4543f, 0.2812f, -0.4187f, 0.6098f, 0.7624f, + 0.5273f, 0.5303f, 0.4892f, 0.5282f, 0.4056f, 0.8344f, 0.4427f, 0.4065f, 0.3812f, 0.4848f, 0.2908f, 0.2198f, 0.7839f, 0.3860f, 1.1033f, 1.7247f, + 0.5119f, 0.5130f, 0.5387f, 0.3300f, 0.5096f, 0.5286f, 0.3192f, 0.9277f, 0.2096f, 0.4280f, 0.6923f, 0.8753f, 0.4327f, 0.2869f, -0.3342f, 0.8895f, + 0.5090f, 0.4776f, 0.5277f, 0.4664f, 0.5432f, 0.8258f, 0.9150f, 0.9896f, 0.9090f, 0.6744f, 0.3770f, 0.2396f, 0.2459f, 0.4065f, 0.1192f, 0.1223f, + 0.5595f, 0.5394f, 0.4375f, 0.5036f, 0.5839f, 0.6266f, 0.3891f, 0.6103f, 0.5874f, 0.5663f, 1.2253f, 0.8567f, 0.6243f, 0.6796f, 0.4019f, -0.7769f, + 0.4793f, 0.4995f, 0.3308f, 0.3321f, 0.2196f, 0.4284f, 0.5544f, 0.4090f, 0.5595f, 0.7174f, 0.7982f, 0.6268f, 0.1198f, 0.4918f, 0.8815f, 0.0723f, + 0.5645f, 0.5575f, 0.5454f, 0.5652f, 0.6970f, 0.6375f, 0.7182f, 0.3128f, 1.0318f, 0.3448f, 0.0133f, 0.7923f, 0.1477f, 0.3566f, 0.8901f, 0.8689f, + 0.5182f, 0.5078f, 0.6249f, 0.5317f, 0.6768f, 0.3704f, 0.1840f, 0.5101f, 0.7289f, 0.2379f, 0.4136f, 0.0748f, 0.6097f, 1.1010f, 0.8246f, -0.0766f, + 0.5988f, 0.6057f, 0.5528f, 0.8575f, 0.5987f, 0.5457f, 0.6180f, 0.4199f, 0.7749f, 0.7449f, 0.5272f, 0.5365f, 0.9174f, 0.7994f, -0.4513f, 0.7950f, + 0.5716f, 0.5605f, 0.6473f, 0.5607f, 0.5092f, 0.6426f, 0.7466f, 0.9075f, 0.5011f, 0.6658f, 0.3106f, 1.0367f, 0.7924f, 0.1091f, 1.0966f, -0.2937f, + 0.4433f, 0.4193f, 0.4868f, 0.5121f, 0.4497f, 0.2652f, 0.8222f, 0.5557f, -0.0414f, 0.0932f, 0.0376f, 0.4227f, 0.7474f, 0.3534f, 0.3456f, 0.6976f, + 0.5268f, 0.5018f, 0.2730f, 0.3274f, 0.1291f, 0.0664f, 0.3102f, 0.2047f, 0.4332f, 0.3378f, 0.4121f, 0.7203f, 0.8165f, 0.7094f, 0.8077f, 0.4042f, + 0.5477f, 0.5231f, 0.6094f, 0.4463f, 0.7288f, 0.5550f, 0.4852f, 0.7322f, 0.6085f, 0.8074f, 0.5868f, 0.2406f, 1.8234f, 0.5357f, 0.7511f, 0.4092f, + 0.5616f, 0.5749f, 0.6051f, 0.5437f, 0.5948f, 0.8798f, 0.7179f, 0.4225f, 0.2786f, 0.2233f, 0.6857f, 1.2117f, 1.2260f, 0.9426f, 0.3945f, 0.5651f, + 0.4840f, 0.4684f, 0.2549f, 0.5206f, 0.6155f, 0.4246f, 0.5436f, 0.3423f, 0.5080f, 0.5930f, 0.5267f, 0.5302f, 0.6339f, -0.2225f, -0.6138f, -0.1388f, + 0.4198f, 0.3463f, 0.3111f, 0.4959f, 0.3487f, 0.3243f, 0.3250f, 0.6211f, 1.2876f, 1.0880f, 0.8094f, 0.7806f, 0.6797f, 0.3919f, 0.2967f, 0.4151f, + 0.4972f, 0.4686f, 0.7088f, 0.6465f, 0.4597f, 0.2859f, 0.3155f, 0.1088f, 0.3838f, 0.3647f, 0.8309f, 0.5647f, 0.4517f, 0.7146f, 0.1884f, 1.9724f, + 0.5113f, 0.4938f, 0.5241f, 0.5526f, 0.4893f, 0.1725f, 0.5946f, 0.7423f, 0.4025f, 0.7991f, 0.6111f, -0.0446f, -0.2892f, 0.1679f, 0.6741f, 1.0726f, + 0.5833f, 0.5838f, 0.6032f, 0.5539f, 0.5489f, 0.3820f, 0.6023f, 0.5336f, 0.8758f, 0.8451f, 1.0522f, 1.2495f, 1.0576f, 1.2314f, 1.3334f, 0.8928f, + 0.6036f, 0.6123f, 0.7860f, 0.7755f, 0.8086f, 0.7890f, 0.8469f, 0.9213f, 0.8550f, 0.8890f, 0.9344f, 0.8727f, 0.9338f, 0.3353f, 0.4170f, 1.8179f, + 0.5830f, 0.6630f, 0.6732f, 0.7561f, 0.6958f, 0.6695f, 0.3412f, 0.6684f, 0.4912f, 1.0853f, 0.3577f, 0.9663f, 0.4184f, 0.9851f, 0.7226f, 1.6406f, + 0.5759f, 0.6087f, 0.5859f, 0.6453f, 0.8016f, 0.8000f, 0.8058f, 0.1508f, -0.1484f, 0.8003f, 0.7444f, 0.4837f, 0.5323f, 0.6758f, 0.6735f, 0.4804f, + 0.5787f, 0.5712f, 0.6827f, 0.5971f, 0.4699f, 0.6927f, 0.7919f, 0.7616f, 0.8621f, 1.4702f, 1.3328f, 0.2976f, 0.4855f, 0.8906f, 1.0309f, 0.8087f, + 0.5932f, 0.7057f, 0.8047f, 0.9032f, 0.9799f, 1.0813f, 0.9935f, 1.0927f, 1.0693f, 0.6721f, 0.7683f, 0.7983f, 0.7954f, 0.9188f, 0.9385f, 0.4985f, + 0.4977f, 0.4603f, 0.4455f, 0.4127f, 0.4110f, 0.4941f, 0.4759f, 0.5349f, 0.3683f, -0.2632f, -0.1787f, -0.2694f, 0.1011f, 0.5906f, 0.2528f, 0.2884f, + 0.4634f, 0.4195f, 0.4343f, 0.4690f, 0.2649f, 0.5263f, 0.3176f, 0.0849f, 0.2367f, 0.3145f, 0.1513f, 0.0400f, -0.0157f, -0.0790f, 0.2078f, 0.3531f, + 0.4901f, 0.4280f, 0.0448f, 0.1648f, 0.4062f, 0.4517f, 0.4672f, 0.2977f, 0.1751f, 0.4745f, 0.2782f, 0.1945f, 0.4484f, 0.6724f, 0.4767f, -0.3629f, + 0.4990f, 0.4870f, 0.4556f, 0.3975f, 0.5759f, 0.1679f, 0.0186f, -0.0121f, -0.0310f, 0.1391f, 0.4368f, 0.4048f, 0.2680f, 0.2939f, 0.6137f, 0.1220f, + 0.4576f, 0.3876f, 0.1800f, 0.0838f, 0.2449f, 0.2391f, 0.1902f, 0.3734f, 0.6560f, 0.6120f, 0.2977f, 0.2925f, 0.3012f, 0.2707f, 0.1258f, 0.9602f, + 0.2486f, 0.0856f, 0.0151f, 0.0339f, 0.0400f, 0.0309f, 0.0806f, 0.0645f, 0.1008f, 0.0578f, 0.0978f, 0.0977f, 0.1286f, 0.1623f, 0.0981f, 0.1181f +}; + +const float tbl_mid_unv_wb_4b[] = +{ + 0.6335f, 0.3837f, 0.0061f, 0.3077f, 0.6323f, 0.7715f, 0.4749f, 0.4108f, 0.4372f, 0.4293f, 0.4158f, 0.3722f, 0.3496f, 0.1979f, 0.2359f, -0.1160f, + 0.8317f, 0.8118f, 0.2606f, 0.1187f, 0.0552f, 0.1774f, 0.3932f, 0.2072f, 0.3864f, 0.5424f, 0.7232f, 0.7687f, 0.4769f, 0.3494f, 0.4378f, 0.5646f, + 0.3911f, 0.3263f, 0.7933f, 0.5272f, 0.1287f, 0.0682f, 0.5376f, 0.7098f, 0.6191f, 0.8087f, 0.5485f, 0.3026f, 0.2164f, 0.1960f, 0.2562f, 1.0169f, + 0.2349f, 0.3254f, 0.5092f, 0.6735f, 0.7200f, 0.8835f, 0.8933f, 0.9395f, 0.8850f, 0.7653f, 0.7524f, 0.7371f, 0.6408f, 0.5230f, 0.5062f, 0.3452f, + 0.3460f, 0.0962f, 0.0094f, 0.2461f, 0.2226f, 0.3936f, 0.4201f, 0.5459f, 0.7673f, 0.8199f, 0.8280f, 0.8231f, 0.8197f, 0.8607f, 0.8010f, 0.3089f, + 0.7795f, 0.6877f, 0.7032f, 0.6328f, 0.4300f, 0.5229f, 0.2279f, 0.1276f, 0.0707f, 0.1435f, 0.2128f, 0.3172f, 0.6441f, 0.6792f, 0.6553f, 0.9661f, + 0.2191f, 0.1685f, 0.6328f, 1.1384f, 0.9794f, 0.3831f, 0.1536f, 0.2111f, 0.4062f, 0.4802f, 0.6310f, 0.6891f, 0.6434f, 0.7195f, 0.6825f, 0.6281f, + 0.7000f, 0.7134f, 1.0741f, 1.0685f, 0.6870f, 0.6970f, 0.6415f, 0.5947f, 0.6529f, 0.4188f, 0.3670f, 0.3035f, 0.1731f, 0.1189f, 0.1361f, 0.2484f, + 0.5120f, 1.0280f, 0.2212f, 0.7419f, 0.3666f, 0.4217f, 0.8202f, 0.9157f, 0.2588f, 0.2309f, 0.3245f, 0.2828f, 0.2803f, 0.7001f, 0.7999f, 0.5475f, + 0.9854f, 1.3984f, 0.7880f, 0.6188f, 0.6003f, 0.6025f, 0.5882f, 0.6020f, 0.7360f, 0.7624f, 0.7677f, 0.8184f, 0.8239f, 0.6515f, 0.5525f, 0.4851f, + 0.4527f, 0.6817f, 0.5962f, -0.1834f, 0.5938f, 0.2848f, 0.0740f, 0.7295f, 0.7859f, 0.2945f, 0.2364f, 0.4472f, 0.6828f, 0.8532f, 0.7874f, 0.4340f, + 0.4691f, -0.8407f, 0.4513f, 0.4736f, 0.5430f, 0.5205f, 0.7277f, 0.5125f, 0.4374f, 0.4812f, 0.4402f, 0.4600f, 0.5441f, 0.5339f, 0.5000f, 0.5523f, + 0.3114f, 0.8277f, 0.8566f, 0.3543f, 1.1264f, 1.0654f, 0.8704f, 0.2286f, 0.2817f, 0.5363f, 0.4860f, 0.4854f, 0.4885f, 0.4981f, 0.5884f, 0.6849f, + 0.0269f, -0.0212f, -0.0053f, -0.0662f, 0.0548f, 0.1794f, 0.2147f, 0.2311f, 0.1580f, 0.1215f, 0.0883f, 0.0883f, 0.0939f, 0.1213f, 0.1671f, 0.5387f, + 0.2015f, 0.2757f, 0.3759f, 0.3556f, 0.1435f, -0.0599f, -0.1540f, -0.1010f, -0.0265f, 0.1109f, 0.1375f, 0.2138f, 0.2321f, 0.2154f, 0.3242f, 0.0302f, + 0.6567f, 0.8920f, 0.9432f, 0.9931f, 1.0095f, 1.0340f, 1.0733f, 1.0465f, 1.0174f, 1.0278f, 0.9835f, 0.9231f, 0.8690f, 0.9104f, 0.8308f, 0.9015f +}; + +const float tbl_mid_unv_wb_5b[] = +{ + 0.7613f, 0.7719f, 0.1405f, 0.0932f, 0.5149f, 0.7991f, 1.0299f, 1.0621f, 0.9101f, 0.8061f, 0.5653f, 0.3541f, 0.3723f, 0.2189f, 0.2387f, 0.2759f, + 0.6765f, 0.5271f, 0.6522f, 0.6740f, 0.7323f, 0.6686f, 0.6427f, 0.6389f, 0.5635f, 0.4064f, 0.4204f, 0.2217f, -0.0540f, 0.0055f, -0.0003f, 1.0891f, + 0.7776f, 1.0019f, 0.8036f, 0.6873f, 0.6593f, 0.6663f, 0.6333f, 0.6830f, 0.8102f, 0.8412f, 0.8499f, 0.8505f, 0.8562f, 0.7727f, 0.6647f, 0.3785f, + 0.3357f, 0.3489f, 0.6355f, 0.5608f, 0.4041f, 0.4265f, 0.3007f, 0.4162f, 0.4157f, 0.7509f, 0.9377f, 1.0489f, 0.5420f, 0.4535f, 0.3596f, -0.5336f, + 0.1412f, 0.0807f, 0.4569f, 0.7835f, 0.9173f, 1.0155f, 0.9137f, 0.8909f, 0.9678f, 0.9173f, 0.8315f, 0.6923f, 0.6220f, 0.6253f, 0.6100f, 0.4810f, + 0.6266f, 0.4207f, 0.3287f, 0.1977f, 0.2270f, 0.3251f, 0.5619f, 0.7677f, 0.9096f, 0.8856f, 0.9169f, 0.9138f, 1.0827f, 1.0625f, 1.0292f, 0.8096f, + 0.3048f, 0.8186f, 0.8589f, 0.4195f, 1.3250f, 1.0856f, 0.7364f, 0.3688f, 0.3584f, 0.5818f, 0.5060f, 0.5001f, 0.6320f, 0.5961f, 0.7227f, 0.9292f, + -0.0186f, -0.0066f, 0.4828f, 0.1428f, 0.6790f, 0.5731f, 0.1672f, 1.0123f, 0.3792f, 0.2371f, 0.6724f, 0.5954f, 0.4266f, 0.1336f, 0.1317f, 0.6593f, + 0.0588f, 0.0455f, 0.0269f, -0.0433f, -0.0288f, -0.0401f, -0.0520f, -0.0180f, 0.0298f, 0.0687f, 0.0692f, 0.1117f, 0.1235f, 0.0825f, 0.0981f, 0.3321f, + 0.0534f, 0.0996f, 0.3916f, 0.4144f, 0.3053f, 0.4633f, 0.5347f, 0.3117f, 0.0487f, 0.0038f, -0.0633f, -0.0580f, -0.0198f, 0.2142f, 0.3482f, 0.1270f, + 0.2523f, 0.2594f, 0.1522f, 0.2921f, 0.3506f, 0.2707f, 0.4275f, 0.4855f, 0.5752f, 0.5218f, 0.3174f, 0.2905f, 0.2825f, 0.3531f, 0.4339f, 1.7003f, + 0.4843f, -0.0775f, -0.2139f, 0.3039f, 0.0370f, 0.1183f, 0.1276f, 0.3465f, 0.6921f, 0.5677f, 0.6350f, 0.6406f, 0.5105f, 0.5348f, 0.6704f, 0.0065f, + 0.3712f, 0.3044f, 1.1308f, 0.6067f, 0.0439f, -0.4632f, 0.7686f, 0.7904f, 0.5471f, 0.8138f, 0.6427f, 0.3550f, 0.2907f, 0.3527f, 0.4539f, 0.6299f, + 0.4107f, 0.5028f, 0.7238f, 0.3862f, -0.0910f, 1.1435f, 0.2016f, -0.0878f, 0.7719f, 0.6242f, 0.2342f, 0.1538f, 0.3210f, 0.4376f, 0.2715f, 0.3880f, + 0.2006f, 0.1022f, 0.9856f, 1.0177f, 0.5172f, 0.2847f, 0.2673f, -0.1435f, 0.2402f, 0.1511f, 0.2873f, 0.5806f, 0.6432f, 0.7030f, 0.6057f, 0.6605f, + 0.9265f, 0.7899f, 0.3217f, 0.2282f, 0.1476f, 0.1837f, 0.2586f, 0.1089f, 0.2017f, 0.4537f, 0.6116f, 0.4845f, 0.2765f, 0.2964f, 0.4001f, 0.6137f, + 0.8898f, 1.0569f, 1.3651f, 1.0880f, 0.7427f, 0.8146f, 0.7277f, 0.4933f, 0.4686f, 0.3226f, 0.2556f, 0.3925f, 0.3609f, 0.3534f, 0.4061f, 0.6180f, + 0.7097f, -0.6082f, 0.1367f, 0.2578f, 0.5352f, 0.6455f, 0.7388f, 0.5255f, 0.5767f, 0.6179f, 0.4126f, 0.5127f, 0.7127f, 0.8766f, 0.7792f, 0.5824f, + 0.4750f, 0.8985f, 0.5078f, 0.1736f, 0.6068f, 0.1146f, 0.0343f, 0.4376f, 0.5880f, 0.1435f, -0.0373f, 0.0317f, 0.4657f, 1.0099f, 0.8661f, 0.1866f, + 0.9984f, 2.3701f, 0.4294f, 0.4330f, 0.5639f, 0.5165f, 0.4100f, 0.4402f, 0.6263f, 0.5455f, 0.6353f, 0.6244f, 0.6031f, 0.5825f, 0.5097f, 0.6299f, + 0.5541f, 0.6583f, 0.3303f, 0.6556f, 0.1792f, 1.0361f, 1.2642f, 0.3391f, 0.1741f, 0.0453f, 0.9879f, 0.9531f, 0.6357f, 0.7319f, 0.7423f, 0.6173f, + 0.3987f, 0.4249f, -0.6046f, -0.6882f, 0.4910f, 0.6716f, 0.4378f, 0.3805f, 0.3341f, 0.4671f, 0.4465f, 0.4801f, 0.4397f, 0.6006f, 0.6054f, 0.4252f, + 0.4695f, 1.1709f, 0.4102f, 0.7910f, 0.1483f, 0.3870f, 0.6370f, 1.0548f, 0.0811f, 0.3290f, 0.4093f, 0.1806f, 0.2059f, 0.7384f, 0.8635f, 0.5733f, + 0.2723f, 0.5489f, 0.8253f, 0.8299f, 0.7252f, 0.6647f, 0.9867f, 0.9697f, 0.7177f, 0.4570f, 0.3074f, 0.7912f, 0.8034f, 0.7441f, 0.7787f, -0.0162f, + 0.4101f, 0.7419f, 0.1299f, 1.6854f, 0.9991f, 0.4401f, 0.5282f, 0.4610f, 0.7582f, 0.6075f, 0.6122f, 0.5946f, 0.7110f, 0.3059f, 0.2600f, 0.6038f, + 0.6606f, 0.5502f, 0.1162f, 0.5003f, 0.6136f, 0.4821f, 0.4274f, 0.2171f, 0.2387f, 0.2595f, 0.1985f, 0.4479f, 0.5427f, -0.1344f, 0.0898f, -0.3306f, + 0.5889f, 0.9132f, 1.0845f, -0.3197f, -0.3362f, 0.0343f, 0.5076f, 0.3968f, 0.5618f, 0.3596f, 0.4779f, 0.7531f, 0.7416f, 0.4266f, 0.3987f, 0.5340f, + 0.7489f, 0.3257f, 0.8281f, 1.2605f, 0.8413f, 0.6688f, 0.1844f, 0.3748f, 0.7825f, 1.1222f, 0.8489f, 0.1323f, 0.3507f, 0.8581f, 0.9935f, 0.6921f, + 0.8856f, 0.7036f, 0.6252f, 0.7064f, 0.3820f, 0.6683f, -0.3320f, 0.4602f, -0.1010f, 0.1065f, 0.1942f, 0.5670f, 0.8811f, 0.6730f, 0.7053f, 0.7718f, + 0.1447f, -1.5991f, 0.6787f, 0.7162f, 0.5069f, 0.3163f, 0.6009f, 0.4212f, 0.2517f, 0.5189f, 0.5235f, 0.4147f, 0.4682f, 0.2541f, 0.2860f, 0.3872f, + 0.5444f, 0.5385f, 0.4809f, 0.5395f, 1.1487f, -0.3404f, -0.3082f, -0.3512f, -0.2280f, 0.3479f, 0.5481f, 0.4996f, 0.3860f, 0.4747f, 0.4639f, 0.4263f, + 0.7822f, 1.0122f, 1.0295f, 1.0430f, 1.0629f, 1.1165f, 1.1447f, 1.1354f, 1.1063f, 1.0919f, 1.0188f, 0.9977f, 0.8758f, 0.8855f, 0.7471f, 0.9058f +}; + + + +/*------------------------------------------------------------------------------* + * AVQ - RE8 tables + *------------------------------------------------------------------------------*/ + +/* NOTE: Many values here could fit in shorts instead of ints */ +const int select_table22[5][9] = +{ + {1, 1, 1, 1, 1, 1, 1, 1, 1}, + {0, 1, 2, 3, 4, 5, 6, 7, 8}, + {0, 0, 1, 3, 6, 10, 15, 21, 28}, + {0, 0, 0, 1, 4, 10, 20, 35, 56}, + {0, 0, 0, 0, 1, 5, 15, 35, 70} +}; + +/* value of leader element */ +const int vals_a[36][4] = +{ + {1}, {0,2}, {0,2}, {1,3}, {0,4}, {2,0}, {1,3}, {0,2,4}, + {2}, {1,3}, {2,0,4}, {0,4}, {1,5}, {1,3}, {2,0,4}, {0,2,4}, + {1,3,5}, {0,2,6}, {0,4}, {0,2,6}, {0,2,4,6}, {1,7}, {0,8}, {0,6}, + {0,2,8}, {0,4,8}, {1,9}, {0,2,10}, {0,8}, {0,6,10}, {0,12}, {0,4,12}, + {0,10}, {0,2,14}, {0,8,12}, {0,16} +}; + +/* code parameter for every leader */ +const int vals_q[36][4] = +{ + {7,1}, {2,2,2}, {4,2,4}, {7,2,1}, {1,2,1}, {6,2,2}, {7,2,2}, {3,3,3,1}, + {8,1}, {7,2,3}, {5,3,4,1}, {2,2,2}, {7,2,1}, {7,2,4}, {7,3,2,1}, {4,3,4,2}, + {7,3,2,1}, {2,3,2,1}, {3,2,3}, {4,3,4,1}, {3,4,3,2}, {7,2,1}, {1,2,1}, {2,2,2}, + {3,3,3,1}, {2,3,2,1}, {7,2,1}, {2,3,2,1}, {2,2,2}, {2,3,2,1}, {1,2,1}, {2,3,2,1}, + {2,2,2}, {2,3,2,1}, {2,3,2,1}, {1,2,1} +}; + +/* codebook start address for every leader */ +const unsigned int Is[36] = +{ + 0, 128, 256, 1376, 240, 0, 1792, 2400, 5376, 5632, 12800, 3744, + 21760, 22784, 31744, 38912, 45632, 3856, 52800, 53248, 57728, 60416, 4080, 61440, + 61552, 62896, 63120, 64144, 64368, 64480, 64704, 64720, 64944, 65056, 65280, 65504 +}; + +/* A3 - Number of the absolute leaders in codebook Q3 */ +const int AA3[NB_LDQ3] = +{ + 0, 1, 4, 2, 3, 7, 11, 17, 22 +}; + +/* A4 - Number of the absolute leaders in codebook Q4 */ +const int AA4[NB_LDQ4] = +{ + 5, 6, 8, 9, 10, 12, 13, 14, 15, + 16, 18, 19, 20, 21, 23, 24, 25, 26, + 27, 28, 29, 30, 31, 32, 33, 34, 35 +}; + +/* I3 - Cardinality offsets for absolute leaders in Q3 */ +const unsigned int II3[NB_LDQ3] = +{ + 0, 128, 240, 256, 1376, 2400, 3744, 3856, 4080 +}; + +/* I4 - Cardinality offset for absolute leaders in Q4 */ +const unsigned int II4[NB_LDQ4] = +{ + 0, 1792, 5376, 5632, 12800, 21760, 22784, 31744, 38912, + 45632, 52800, 53248, 57728, 60416, 61440, 61552, 62896, 63120, + 64144, 64368, 64480, 64704, 64720, 64944, 65056, 65280, 65504 +}; + +/*------------------------------------------------------------------------------* + * Position of the first absolute leader on a spherical shell (or sphere) + *------------------------------------------------------------------------------*/ + +const int Da_pos[NB_SPHERE] = +{ + 0, 2, 5, 8, 13, 18, 20, 22, 23, 25, 26, 27, 27, 28, 28, 28, + 29, 30, 31, 31, 32, 32, 32, 32, 32, 34, 35, 35, 35, 35, 35, 35 +}; + +/*------------------------------------------------------------------------------* + * Number of absolute leaders on a spherical shell + *------------------------------------------------------------------------------*/ + +const int Da_nb[NB_SPHERE] = +{ + 2, 3, 3, 5, 5, 2, 2, 1, 2, 1, 1, 0, 1, 0, 0, 1, + 1, 1, 0, 1, 0, 0, 0, 0, 2, 1, 0, 0, 0, 0, 0, 1 +}; + +/*------------------------------------------------------------------------------* + * Identification code of an absolute leader + *------------------------------------------------------------------------------*/ + +const int Da_id[NB_LEADER] = +{ + 0x0001, 0x0004, 0x0008, 0x000B, 0x0020, 0x000C, 0x0015, 0x0024, + 0x0010, 0x001F, 0x0028, 0x0040, 0x004F, 0x0029, 0x002C, 0x0044, + 0x0059, 0x00A4, 0x0060, 0x00A8, 0x00C4, 0x012D, 0x0200, 0x0144, + 0x0204, 0x0220, 0x0335, 0x04E4, 0x0400, 0x0584, 0x0A20, 0x0A40, + 0x09C4, 0x12C4, 0x0C20, 0x2000 +}; + +/*------------------------------------------------------------------------------* + * Codebook number for each absolute leader + *------------------------------------------------------------------------------*/ + +const int Da_nq[NB_LEADER+2] = +{ + 2, 2, 3, 3, 2, 4, 4, 3, 4, 4, 4, 3, 4, 4, 4, 4, + 4, 3, 4, 4, 4, 4, 3, 4, 4, 4, 4, 4, 4, 4, 4, 4, + 4, 4, 4, 4, 0, 100 +}; + + +/*------------------------------------------------------------------------------* + * SWB TBE tables + *------------------------------------------------------------------------------*/ + +const short skip_bands_SWB_TBE[NUM_SHB_SUBFR+1] = {0, 20, 40, 60, 80, 100, 120, 140, 160, 180, 200, 220, 240, 260, 280, 300, 320}; /* bands for SWB TBE quantisation */ +const short skip_bands_WB_TBE[NUM_SHB_SUBFR/2+1] = {0, 10, 20, 30, 40, 50, 60, 70, 80}; /* bands for WB TBE quantisation */ + +const float interpol_frac_shb[NB_SUBFR*2] = { 0.7f, 0.3f, 0.4f, 0.6f, 0.1f, 0.9f, 0.0f, 1.0f }; + +/* All pass filter coeffs for interpolation and decimation by a factor of 2 */ +const float AP1_STEEP[ALLPASSSECTIONS_STEEP] = +{ 0.06056541924291f, 0.42943401549235f, 0.80873048306552f }; + +const float AP2_STEEP[ALLPASSSECTIONS_STEEP] = +{ 0.22063024829630f, 0.63593943961708f, 0.94151583095682f }; + +const float cos_fb_exc[32] = +{ + 9.536743164062500e-007f,9.353497034680913e-007f,8.810801546133007e-007f,7.929511980364623e-007f,6.743495646333031e-007f,5.298330165715015e-007f,3.649553264040151e-007f,1.860525884467279e-007f, + 0.000000000000000e+000f,-1.860526737118562e-007f,-3.649554116691434e-007f,-5.298331302583392e-007f,-6.743496214767220e-007f,-7.929512548798812e-007f,-8.810802114567196e-007f,-9.353497603115102e-007f, + -9.536743164062500e-007f,-9.353497034680913e-007f,-8.810801546133007e-007f,-7.929511411930434e-007f,-6.743495077898842e-007f,-5.298329597280826e-007f,-3.649552411388868e-007f,-1.860525173924543e-007f, + 0.000000000000000e+000f,1.860527589769845e-007f,3.649554969342717e-007f,5.298331871017581e-007f,6.743496783201408e-007f,7.929513117233000e-007f,8.810802683001384e-007f,9.353497603115102e-007f +}; + +const float recip_order[15] = +{ + 0.0000000f, 1.0000000f, 0.5000000f, 0.3333333f, 0.2500000f, + 0.2000000f, 0.1666667f, 0.1428571f, 0.1250000f, 0.1111111f, + 0.1000000f, 0.0909091f, 0.0833333f, 0.0769231f, 0.0714286f +}; + +const float STEPS[4] = { 0.00635f, 0.003175f, 0.0015875f, 0.00079375f}; + +const float Hilbert_coeffs[4*NUM_HILBERTS][HILBERT_ORDER1+1] = +{ + { 0.0f, 0.8740234375f, 0.0f, -1.87371826171875f, 0.0f, 1.0f}, /* num_Real[0] */ + {0.72613525390625f, 0.0f, -1.7236328125f, 0.0f, 1.0f, 0.0f}, /* num_Imag[0] */ + { 1.0f, 0.0f, -1.87371826171875f, 0.0f, 0.8740234375f, 0.0f}, /* den_Real[0] */ + { 1.0f, 0.0f, -1.7236328125f, 0.0f, 0.72613525390625f, 0.0f}, /* den_Imag[0] */ + {0.46820068359375f, 0.0f, -1.45599365234375f, 0.0f, 1.0f, 0.0f}, /* num_Real[1] */ + {0.15289306640625f, 0.0f, -1.10711669921875f, 0.0f, 1.0f, 0.0f}, /* num_Imag[1] */ + { 1.0f, 0.0f, -1.45599365234375f, 0.0f, 0.46820068359375f, 0.0f}, /* den_Real[1] */ + { 1.0f, 0.0f, -1.10711669921875f, 0.0f, 0.15289306640625f, 0.0f} /* den_Imag[1] */ +}; + +/* Overlap add window for SHB excitation used in analysis and synthesis */ +const float window_shb[L_SHB_LAHEAD]= /* sin, 1, sin */ +{ + 4.618346E-02f, 1.381564E-01f, 2.289505E-01f, 3.177914E-01f, 4.039210E-01f, 4.866045E-01f, 5.651364E-01f, 6.388468E-01f, 7.071068E-01f, 7.693340E-01f, + 8.249975E-01f, 8.736224E-01f, 9.147939E-01f, 9.481606E-01f, 9.734381E-01f, 9.904104E-01f, 9.989330E-01f, 1.000000e+000f, 1.000000e+000f, 1.000000e+000f +}; + +/* Upsampled overlap add window for SHB excitation used transition generation */ +const float window_shb_32k[2*L_SHB_LAHEAD]= +{ + 4.618346E-02f, 9.216993E-02f, 1.381564E-01f, 1.835534E-01f, 2.289505E-01f, 2.733710E-01f, 3.177914E-01f, 3.608562E-01f, 4.039210E-01f, 4.452628E-01f, + 4.866045E-01f, 5.258704E-01f, 5.651364E-01f, 6.019916E-01f, 6.388468E-01f, 6.729768E-01f, 7.071068E-01f, 7.382205E-01f, 7.693340E-01f, 7.971658E-01f, + 8.249975E-01f, 8.493099E-01f, 8.736224E-01f, 8.942082E-01f, 9.147939E-01f, 9.314773E-01f, 9.481606E-01f, 9.607993E-01f, 9.734381E-01f, 9.819242E-01f, + 9.904104E-01f, 9.946717E-01f, 9.989330E-01f, 9.994665E-01f, 1.000000e+000f, 1.000000e+000f, 1.000000e+000f, 1.000000e+000f, 1.000000e+000f, 1.000000e+000f +}; + +/* Short overlap add window for SHB excitation used in anal and synth */ +const float subwin_shb[SHB_OVERLAP_LEN+1]= +{ + 0.000000000f, 0.006155830f, 0.024471742f, 0.054496738f, 0.095491503f, + 0.146446609f, 0.206107374f, 0.273004750f, 0.345491503f, 0.421782767f, + 0.500000000f, 0.578217233f, 0.654508497f, 0.726995250f, 0.793892626f, + 0.853553391f, 0.904508497f, 0.945503262f, 0.975528258f, 0.993844170f, + 1.000000000f +}; + +const float window_wb[L_SHB_LAHEAD/4]=/* sin, 1 */ +{ 2.289505E-001f, 5.651364E-001f, 8.249975E-001f, 9.734381E-001f, 1.000000e+000f}; + +/* Short overlap add window for SHB excitation used in anal and synth */ +const float subwin_wb[SHB_OVERLAP_LEN/2+1]= +{0.00000000f, 0.15643448f, 0.30901700f, 0.45399052f, 0.58778524f, 0.70710677f, 0.80901700f, 0.89100653f, 0.95105654f, 0.98768836f, 1.0000000f}; + +/* Window for calculating SHB LPC coeffs */ +const float win_lpc_shb[(L_LOOK_12k8 + L_SUBFR + L_FRAME) * 5/8]= +{ + 0.0000337210f, 0.0001348794f, 0.0003034616f, 0.0005394449f, 0.0008427974f, 0.0012134782f, 0.0016514373f, 0.0021566156f, 0.0027289450f, 0.0033683483f, + 0.0040747393f, 0.0048480226f, 0.0056880940f, 0.0065948401f, 0.0075681387f, 0.0086078584f, 0.0097138590f, 0.0108859914f, 0.0121240975f, 0.0134280101f, + 0.0147975536f, 0.0162325430f, 0.0177327850f, 0.0192980770f, 0.0209282080f, 0.0226229582f, 0.0243820988f, 0.0262053927f, 0.0280925938f, 0.0300434477f, + 0.0320576912f, 0.0341350526f, 0.0362752518f, 0.0384779999f, 0.0407430000f, 0.0430699465f, 0.0454585255f, 0.0479084149f, 0.0504192842f, 0.0529907947f, + 0.0556225996f, 0.0583143439f, 0.0610656645f, 0.0638761903f, 0.0667455422f, 0.0696733332f, 0.0726591683f, 0.0757026449f, 0.0788033524f, 0.0819608725f, + 0.0851747795f, 0.0884446397f, 0.0917700121f, 0.0951504482f, 0.0985854920f, 0.1020746802f, 0.1056175421f, 0.1092136000f, 0.1128623686f, 0.1165633559f, + 0.1203160626f, 0.1241199826f, 0.1279746028f, 0.1318794033f, 0.1358338573f, 0.1398374315f, 0.1438895859f, 0.1479897739f, 0.1521374423f, 0.1563320319f, + 0.1605729768f, 0.1648597049f, 0.1691916381f, 0.1735681920f, 0.1779887763f, 0.1824527948f, 0.1869596453f, 0.1915087200f, 0.1960994051f, 0.2007310816f, + 0.2054031247f, 0.2101149041f, 0.2148657844f, 0.2196551248f, 0.2244822791f, 0.2293465964f, 0.2342474205f, 0.2391840904f, 0.2441559401f, 0.2491622991f, + 0.2542024921f, 0.2592758392f, 0.2643816562f, 0.2695192543f, 0.2746879405f, 0.2798870178f, 0.2851157847f, 0.2903735361f, 0.2956595627f, 0.3009731516f, + 0.3063135860f, 0.3116801456f, 0.3170721065f, 0.3224887415f, 0.3279293199f, 0.3333931079f, 0.3388793684f, 0.3443873616f, 0.3499163444f, 0.3554655711f, + 0.3610342931f, 0.3666217595f, 0.3722272163f, 0.3778499077f, 0.3834890752f, 0.3891439582f, 0.3948137938f, 0.4004978174f, 0.4061952622f, 0.4119053598f, + 0.4176273399f, 0.4233604308f, 0.4291038591f, 0.4348568502f, 0.4406186280f, 0.4463884155f, 0.4521654343f, 0.4579489052f, 0.4637380481f, 0.4695320822f, + 0.4753302259f, 0.4811316971f, 0.4869357134f, 0.4927414919f, 0.4985482494f, 0.5043552028f, 0.5101615687f, 0.5159665639f, 0.5217694055f, 0.5275693108f, + 0.5333654974f, 0.5391571836f, 0.5449435881f, 0.5507239304f, 0.5564974308f, 0.5622633107f, 0.5680207922f, 0.5737690989f, 0.5795074552f, 0.5852350873f, + 0.5909512225f, 0.5966550899f, 0.6023459200f, 0.6080229454f, 0.6136854001f, 0.6193325205f, 0.6249635449f, 0.6305777137f, 0.6361742697f, 0.6417524579f, + 0.6473115260f, 0.6528507242f, 0.6583693052f, 0.6638665247f, 0.6693416413f, 0.6747939164f, 0.6802226146f, 0.6856270037f, 0.6910063547f, 0.6963599419f, + 0.7016870434f, 0.7069869405f, 0.7122589184f, 0.7175022660f, 0.7227162760f, 0.7279002451f, 0.7330534742f, 0.7381752681f, 0.7432649359f, 0.7483217913f, + 0.7533451519f, 0.7583343404f, 0.7632886838f, 0.7682075137f, 0.7730901667f, 0.7779359842f, 0.7827443127f, 0.7875145034f, 0.7922459131f, 0.7969379034f, + 0.8015898416f, 0.8062011002f, 0.8107710572f, 0.8152990961f, 0.8197846062f, 0.8242269825f, 0.8286256258f, 0.8329799428f, 0.8372893461f, 0.8415532545f, + 0.8457710928f, 0.8499422922f, 0.8540662899f, 0.8581425298f, 0.8621704620f, 0.8661495432f, 0.8700792367f, 0.8739590124f, 0.8777883471f, 0.8815667242f, + 0.8852936341f, 0.8889685740f, 0.8925910483f, 0.8961605683f, 0.8996766527f, 0.9031388271f, 0.9065466245f, 0.9098995853f, 0.9131972572f, 0.9164391954f, + 0.9196249627f, 0.9227541293f, 0.9258262731f, 0.9288409798f, 0.9317978427f, 0.9346964630f, 0.9375364498f, 0.9403174198f, 0.9430389982f, 0.9457008176f, + 0.9483025192f, 0.9508437519f, 0.9533241731f, 0.9557434481f, 0.9581012506f, 0.9603972626f, 0.9626311744f, 0.9648026847f, 0.9669115005f, 0.9689573374f, + 0.9709399196f, 0.9728589795f, 0.9747142583f, 0.9765055057f, 0.9782324802f, 0.9798949488f, 0.9814926873f, 0.9830254801f, 0.9844931206f, 0.9858954107f, + 0.9872321612f, 0.9885031920f, 0.9897083316f, 0.9908474173f, 0.9919202956f, 0.9929268217f, 0.9938668599f, 0.9947402834f, 0.9955469743f, 0.9962868239f, + 0.9969597324f, 0.9975656090f, 0.9981043719f, 0.9985759486f, 0.9989802753f, 0.9993172977f, 0.9995869701f, 0.9997892562f, 0.9999241288f, 0.9999915697f +}; + +const float win_lpc_hb_wb[(L_LOOK_12k8 + L_SUBFR + L_FRAME) * 5/32]= +{ + 0.000171338f, 0.001541333f, 0.004277569f, 0.008372546f, 0.01381504f, 0.020590133f, 0.028679254f, 0.038060234f, + 0.048707358f, 0.060591444f, 0.073679918f, 0.087936906f, 0.10332333f, 0.119797017f, 0.137312814f, 0.155822712f, + 0.175275976f, 0.195619285f, 0.216796882f, 0.238750718f, 0.26142062f, 0.284744452f, 0.308658284f, 0.33309657f, + 0.357992328f, 0.383277318f, 0.408882237f, 0.434736904f, 0.460770452f, 0.486911526f, 0.513088474f, 0.539229548f, + 0.565263096f, 0.591117763f, 0.616722682f, 0.642007672f, 0.66690343f, 0.691341716f, 0.715255548f, 0.73857938f, + 0.761249282f, 0.783203118f, 0.804380715f, 0.824724024f, 0.844177288f, 0.862687186f, 0.880202983f, 0.89667667f, + 0.912063094f, 0.926320082f, 0.939408556f, 0.951292642f, 0.961939766f, 0.971320746f, 0.979409867f, 0.98618496f, + 0.991627454f, 0.995722431f, 0.998458667f, 0.999828662f +}; + +const float ola_win_shb_switch_fold[L_SUBFR16k] = +{ + 0.009817319f, 0.029448173f, 0.049067674f, 0.068668259f, 0.088242371f, 0.107782463f, 0.127281003f, 0.146730474f, + 0.166123378f, 0.185452238f, 0.204709603f, 0.223888048f, 0.242980180f, 0.261978638f, 0.280876099f, 0.299665277f, + 0.318338928f, 0.336889853f, 0.355310901f, 0.373594970f, 0.391735011f, 0.409724030f, 0.427555093f, 0.445221326f, + 0.462715917f, 0.480032122f, 0.497163266f, 0.514102744f, 0.530844026f, 0.547380657f, 0.563706262f, 0.579814548f, + 0.595699304f, 0.611354407f, 0.626773822f, 0.641951603f, 0.656881899f, 0.671558955f, 0.685977112f, 0.700130812f, + 0.714014598f, 0.727623118f, 0.740951125f, 0.753993482f, 0.766745160f, 0.779201243f, 0.791356929f, 0.803207531f, + 0.814748483f, 0.825975333f, 0.836883753f, 0.847469539f, 0.857728610f, 0.867657010f, 0.877250911f, 0.886506616f, + 0.895420555f, 0.903989293f, 0.912209526f, 0.920078084f, 0.927591935f, 0.934748182f, 0.941544065f, 0.947976965f, + 0.954044402f, 0.959744037f, 0.965073672f, 0.970031253f, 0.974614869f, 0.978822751f, 0.982653279f, 0.986104976f, + 0.989176510f, 0.991866698f, 0.994174502f, 0.996099033f, 0.997639549f, 0.998795456f, 0.999566309f, 0.999951809f +}; + +/* Window for calculating whitening filter for SHB excitation */ +const float win_flatten[ L_FRAME16k/2]= +{ + 9.57802E-05f, 0.000383084f, 0.000861802f, 0.00153175f, 0.002392671f, 0.003444236f, 0.004686042f, 0.006117614f, + 0.007738401f, 0.009547785f, 0.011545071f, 0.013729494f, 0.016100218f, 0.018656334f, 0.021396862f, 0.024320754f, + 0.027426888f, 0.030714075f, 0.034181054f, 0.037826499f, 0.041649013f, 0.04564713f, 0.049819319f, 0.054163981f, + 0.058679453f, 0.063364004f, 0.068215839f, 0.0732331f, 0.078413864f, 0.083756147f, 0.089257901f, 0.094917019f, + 0.100731333f, 0.106698615f, 0.112816579f, 0.119082881f, 0.12549512f, 0.13205084f, 0.138747529f, 0.145582621f, + 0.152553498f, 0.159657489f, 0.166891873f, 0.174253877f, 0.181740681f, 0.189349417f, 0.197077169f, 0.204920978f, + 0.212877838f, 0.2209447f, 0.229118474f, 0.237396028f, 0.245774191f, 0.254249754f, 0.262819469f, 0.271480052f, + 0.280228187f, 0.28906052f, 0.297973669f, 0.306964218f, 0.316028723f, 0.325163712f, 0.334365684f, 0.343631114f, + 0.352956452f, 0.362338126f, 0.37177254f, 0.381256082f, 0.390785116f, 0.400355993f, 0.409965046f, 0.419608593f, + 0.42928294f, 0.43898438f, 0.448709196f, 0.458453663f, 0.468214047f, 0.477986609f, 0.487767604f, 0.497553287f, + 0.507339906f, 0.517123714f, 0.526900961f, 0.536667901f, 0.546420794f, 0.556155902f, 0.565869495f, 0.575557852f, + 0.585217262f, 0.594844023f, 0.604434447f, 0.61398486f, 0.623491603f, 0.632951034f, 0.642359529f, 0.651713483f, + 0.661009312f, 0.670243455f, 0.679412375f, 0.688512557f, 0.697540517f, 0.706492795f, 0.715365961f, 0.724156616f, + 0.732861391f, 0.741476953f, 0.75f, 0.758427267f, 0.766755524f, 0.774981583f, 0.78310229f, 0.791114534f, + 0.799015247f, 0.8068014f, 0.814470012f, 0.822018143f, 0.829442903f, 0.836741446f, 0.843910977f, 0.850948748f, + 0.857852063f, 0.864618278f, 0.871244799f, 0.87772909f, 0.884068664f, 0.890261093f, 0.896304006f, 0.902195086f, + 0.907932076f, 0.91351278f, 0.918935058f, 0.924196833f, 0.92929609f, 0.934230874f, 0.938999296f, 0.943599527f, + 0.948029807f, 0.952288437f, 0.956373785f, 0.960284288f, 0.964018446f, 0.967574828f, 0.970952073f, 0.974148887f, + 0.977164044f, 0.97999639f, 0.982644839f, 0.985108376f, 0.987386059f, 0.989477014f, 0.99138044f, 0.993095607f, + 0.99462186f, 0.995958613f, 0.997105353f, 0.998061642f, 0.998827114f, 0.999401474f, 0.999784503f, 0.999976054f +}; + +const float win_flatten_4k[ L_FRAME16k/8]= +{ + 0.000385482f, 0.003465772f, 0.00960736f, 0.018772382f, 0.030904332f, 0.045928413f, 0.063751996f, 0.084265194f, + 0.107341535f, 0.132838745f, 0.160599627f, 0.190453025f, 0.222214883f, 0.255689379f, 0.290670131f, 0.326941471f, + 0.364279775f, 0.402454839f, 0.441231301f, 0.480370092f, 0.519629908f, 0.558768699f, 0.597545161f, 0.635720225f, + 0.673058529f, 0.709329869f, 0.744310621f, 0.777785117f, 0.809546975f, 0.839400373f, 0.867161255f, 0.892658465f, + 0.915734806f, 0.936248004f, 0.954071587f, 0.969095668f, 0.981227618f, 0.99039264f, 0.996534228f, 0.999614518f +}; + +const float wb_bwe_lsfvq_cbook_8bit[256*6] = +{ + 0.064311408f, 0.10468847f, 0.15634165f, 0.20375369f, 0.28696818f, 0.40275119f, + 0.123011120f, 0.15468679f, 0.22408577f, 0.27191057f, 0.32490698f, 0.37368365f, + 0.062166951f, 0.10810068f, 0.20470853f, 0.26741467f, 0.32058192f, 0.38620580f, + 0.174916950f, 0.19449120f, 0.24146226f, 0.29131976f, 0.38403433f, 0.43426356f, + 0.061881055f, 0.10185221f, 0.16703630f, 0.24048992f, 0.31339988f, 0.37993594f, + 0.177282270f, 0.19826299f, 0.25380750f, 0.29369257f, 0.35085620f, 0.42745721f, + 0.074096108f, 0.12090045f, 0.17319672f, 0.23572965f, 0.34671734f, 0.40846492f, + 0.193731520f, 0.25350369f, 0.27155532f, 0.30359655f, 0.33746877f, 0.40740063f, + 0.108401970f, 0.13491719f, 0.17991717f, 0.21799053f, 0.30440233f, 0.40384627f, + 0.174536930f, 0.19361701f, 0.22834544f, 0.25644155f, 0.32851965f, 0.41061748f, + 0.107099060f, 0.13363550f, 0.17994689f, 0.22695679f, 0.35903688f, 0.43662047f, + 0.137970100f, 0.24785769f, 0.26827308f, 0.30078557f, 0.34276146f, 0.42785187f, + 0.066387915f, 0.12114685f, 0.23766229f, 0.29916662f, 0.34589517f, 0.39398126f, + 0.137657570f, 0.24889487f, 0.27118048f, 0.31891228f, 0.38713554f, 0.45651107f, + 0.128872750f, 0.16127981f, 0.21523141f, 0.25706016f, 0.34536624f, 0.44451874f, + 0.218467830f, 0.25571942f, 0.27589334f, 0.30889302f, 0.36007931f, 0.43548091f, + 0.056956662f, 0.09351124f, 0.14796259f, 0.22055691f, 0.34257293f, 0.42610824f, + 0.180505310f, 0.20235648f, 0.26672026f, 0.30524807f, 0.34745481f, 0.38838059f, + 0.101998340f, 0.13874827f, 0.19761236f, 0.28698298f, 0.36602473f, 0.40947282f, + 0.187859700f, 0.20997279f, 0.27259784f, 0.31595901f, 0.37782186f, 0.41948720f, + 0.080803553f, 0.15174572f, 0.23117477f, 0.28917899f, 0.36979528f, 0.42341956f, + 0.177685260f, 0.19914809f, 0.26693575f, 0.33390045f, 0.38670310f, 0.42635921f, + 0.123052730f, 0.15593820f, 0.23170087f, 0.28281293f, 0.34711335f, 0.43915513f, + 0.209470720f, 0.25584593f, 0.27727828f, 0.32496712f, 0.39502842f, 0.45856840f, + 0.111734840f, 0.14147902f, 0.20349777f, 0.25418848f, 0.31658104f, 0.37184560f, + 0.177056760f, 0.19666426f, 0.25464026f, 0.29941442f, 0.37334871f, 0.45296459f, + 0.109640340f, 0.13537075f, 0.20335155f, 0.26529530f, 0.35213594f, 0.43554990f, + 0.155959700f, 0.25239450f, 0.27483222f, 0.32663911f, 0.37442742f, 0.42423408f, + 0.060802584f, 0.098534495f, 0.17139797f, 0.27724784f, 0.34847788f, 0.40446891f, + 0.131805190f, 0.17878972f, 0.29302125f, 0.34778777f, 0.39172069f, 0.43333138f, + 0.117051780f, 0.14714169f, 0.25283080f, 0.31096928f, 0.35792401f, 0.40593001f, + 0.244642480f, 0.26542671f, 0.31064604f, 0.34894237f, 0.39502788f, 0.45113983f, + 0.057704683f, 0.10158624f, 0.18821861f, 0.25351465f, 0.33014694f, 0.43374062f, + 0.177105410f, 0.19658676f, 0.24332913f, 0.27865263f, 0.33845007f, 0.38627285f, + 0.085525863f, 0.16781621f, 0.24699003f, 0.29584215f, 0.34250327f, 0.39210727f, + 0.189876270f, 0.21305679f, 0.26289427f, 0.30053004f, 0.36670247f, 0.40832210f, + 0.077609843f, 0.14485938f, 0.23309675f, 0.28603452f, 0.33963436f, 0.41664103f, + 0.180406410f, 0.20188257f, 0.27483060f, 0.32204807f, 0.36496152f, 0.40626347f, + 0.109972660f, 0.13794764f, 0.23344532f, 0.30007610f, 0.37112553f, 0.45007031f, + 0.243211860f, 0.26638262f, 0.29846135f, 0.32926348f, 0.38096489f, 0.42680115f, + 0.115753390f, 0.14391596f, 0.21486068f, 0.26084368f, 0.32379458f, 0.41507919f, + 0.172120490f, 0.19028171f, 0.22318579f, 0.25543954f, 0.36796374f, 0.43638971f, + 0.114912990f, 0.14340870f, 0.20702577f, 0.29029375f, 0.38645739f, 0.43383786f, + 0.141428780f, 0.25522990f, 0.28059674f, 0.31690999f, 0.35024347f, 0.40617629f, + 0.075129960f, 0.14698488f, 0.26110380f, 0.31719769f, 0.36377356f, 0.41101429f, + 0.112868350f, 0.24334299f, 0.28096316f, 0.33454465f, 0.41219625f, 0.46410751f, + 0.114073120f, 0.14243275f, 0.23024102f, 0.32882107f, 0.39744618f, 0.44429863f, + 0.221774120f, 0.26274601f, 0.29020551f, 0.34374641f, 0.39126416f, 0.44235948f, + 0.080079738f, 0.13106315f, 0.18837026f, 0.27151645f, 0.37668958f, 0.43255839f, + 0.192999400f, 0.21775426f, 0.26678052f, 0.30557605f, 0.38446194f, 0.43054658f, + 0.135743140f, 0.17819346f, 0.26983813f, 0.31540557f, 0.35817370f, 0.39888741f, + 0.187602960f, 0.21325656f, 0.29023036f, 0.33244221f, 0.37354374f, 0.41305910f, + 0.092309319f, 0.15685370f, 0.21826152f, 0.28145456f, 0.34801734f, 0.40449806f, + 0.182635620f, 0.20695883f, 0.29330586f, 0.34611408f, 0.38827609f, 0.42744945f, + 0.142778630f, 0.18181581f, 0.24718913f, 0.30036890f, 0.36118151f, 0.41174750f, + 0.236204610f, 0.26138275f, 0.28782872f, 0.31976781f, 0.38485547f, 0.44582109f, + 0.116877780f, 0.14600852f, 0.23439658f, 0.29078582f, 0.33978214f, 0.38680132f, + 0.175246750f, 0.19919182f, 0.25508981f, 0.32738942f, 0.40268065f, 0.44634249f, + 0.137050570f, 0.17196927f, 0.22227536f, 0.26698633f, 0.35381724f, 0.42069877f, + 0.206672940f, 0.25909379f, 0.28239012f, 0.33396266f, 0.38073064f, 0.42642507f, + 0.061761568f, 0.10948738f, 0.22960285f, 0.31900229f, 0.37225715f, 0.42291697f, + 0.176470360f, 0.27105045f, 0.30450833f, 0.35896554f, 0.40397125f, 0.45254757f, + 0.121439660f, 0.15285670f, 0.25458177f, 0.31503554f, 0.37326878f, 0.43680361f, + 0.248663160f, 0.27168576f, 0.31107735f, 0.34636713f, 0.40424762f, 0.44219064f, + 0.070101929f, 0.11626106f, 0.17205417f, 0.22172190f, 0.27958755f, 0.35136489f, + 0.177289590f, 0.19891422f, 0.23900178f, 0.26750187f, 0.31516079f, 0.36488918f, + 0.077375897f, 0.14011343f, 0.22628590f, 0.27710762f, 0.32419150f, 0.37404180f, + 0.181505360f, 0.20134192f, 0.25984204f, 0.30768103f, 0.38822145f, 0.43297287f, + 0.074548254f, 0.13055888f, 0.20082796f, 0.24940258f, 0.30161427f, 0.36031073f, + 0.180461770f, 0.19943970f, 0.27094461f, 0.31420032f, 0.37052353f, 0.43473550f, + 0.074096252f, 0.11976634f, 0.19559390f, 0.30014559f, 0.36503791f, 0.41589500f, + 0.226750330f, 0.26034000f, 0.28387883f, 0.31307141f, 0.34924905f, 0.39466978f, + 0.112939270f, 0.14324718f, 0.19444530f, 0.23409602f, 0.28823566f, 0.35312882f, + 0.177658770f, 0.19744005f, 0.23826049f, 0.27114023f, 0.35113598f, 0.44339139f, + 0.114194520f, 0.13976692f, 0.19017221f, 0.23985925f, 0.34337933f, 0.40059157f, + 0.174247680f, 0.25422512f, 0.27291618f, 0.31259836f, 0.35694641f, 0.44284664f, + 0.079551504f, 0.12808054f, 0.20489528f, 0.31763242f, 0.38800666f, 0.43699908f, + 0.125618080f, 0.25750129f, 0.29652463f, 0.33625458f, 0.37097478f, 0.41695760f, + 0.128908580f, 0.16228143f, 0.22845947f, 0.30852429f, 0.38999548f, 0.43734932f, + 0.169819550f, 0.25672921f, 0.27816521f, 0.33356870f, 0.38415880f, 0.45040976f, + 0.057932155f, 0.096138661f, 0.17637437f, 0.28982999f, 0.37938107f, 0.44064176f, + 0.191452430f, 0.21929421f, 0.28254485f, 0.31749442f, 0.35804814f, 0.39526710f, + 0.112918430f, 0.14011863f, 0.23116641f, 0.29091351f, 0.34974963f, 0.42044500f, + 0.190242080f, 0.21680224f, 0.27563442f, 0.33525335f, 0.39940885f, 0.43998378f, + 0.071851696f, 0.13973452f, 0.23632015f, 0.30396344f, 0.38541794f, 0.45171152f, + 0.184630070f, 0.20535151f, 0.28517376f, 0.32789614f, 0.37951171f, 0.43497879f, + 0.132603770f, 0.16874406f, 0.24771421f, 0.29658241f, 0.37943509f, 0.43056925f, + 0.244405020f, 0.26554052f, 0.30099568f, 0.33429706f, 0.39811794f, 0.44169908f, + 0.127688830f, 0.15825875f, 0.20983321f, 0.25719782f, 0.34290920f, 0.39590250f, + 0.186549100f, 0.20879511f, 0.25591707f, 0.29476812f, 0.39344232f, 0.44883705f, + 0.121737520f, 0.15062455f, 0.21825312f, 0.27097532f, 0.35836887f, 0.41602781f, + 0.157742360f, 0.25669794f, 0.28102574f, 0.34671864f, 0.41050850f, 0.46008611f, + 0.073161878f, 0.13388489f, 0.21462934f, 0.27572797f, 0.36075527f, 0.41919188f, + 0.110086280f, 0.24803245f, 0.31035821f, 0.35293169f, 0.39119687f, 0.43174112f, + 0.135783090f, 0.17715049f, 0.27354016f, 0.32581513f, 0.38440836f, 0.44428392f, + 0.241434570f, 0.26676851f, 0.30639927f, 0.35469044f, 0.41439486f, 0.46056301f, + 0.072374815f, 0.13092581f, 0.21330540f, 0.26565725f, 0.32462099f, 0.41762579f, + 0.187292630f, 0.21108778f, 0.25580340f, 0.28624311f, 0.33138816f, 0.37684385f, + 0.098711036f, 0.18228306f, 0.24984319f, 0.31049971f, 0.37903925f, 0.43890093f, + 0.185453530f, 0.20642460f, 0.26094355f, 0.29915816f, 0.37078354f, 0.42966194f, + 0.090091891f, 0.15555244f, 0.20914149f, 0.27320212f, 0.36822053f, 0.42967380f, + 0.201609780f, 0.23445421f, 0.29016518f, 0.32638897f, 0.37174990f, 0.41508051f, + 0.113139770f, 0.14155327f, 0.22791682f, 0.31995140f, 0.37521299f, 0.41972433f, + 0.242912130f, 0.26597026f, 0.30674398f, 0.34632679f, 0.38930327f, 0.42944494f, + 0.126299270f, 0.15994217f, 0.23121635f, 0.27579474f, 0.33301124f, 0.41152335f, + 0.178158900f, 0.19664722f, 0.23704785f, 0.27359930f, 0.39265986f, 0.45771152f, + 0.129551450f, 0.16291546f, 0.22120094f, 0.28045517f, 0.37621782f, 0.42867219f, + 0.187946560f, 0.27082805f, 0.30209272f, 0.33978012f, 0.37078287f, 0.41235280f, + 0.068654959f, 0.13086497f, 0.26542795f, 0.33399948f, 0.38525278f, 0.43688097f, + 0.096004458f, 0.20898133f, 0.30225243f, 0.35934752f, 0.41301071f, 0.45632845f, + 0.123398330f, 0.15749653f, 0.25528304f, 0.31414621f, 0.39506227f, 0.45492910f, + 0.225770510f, 0.26622774f, 0.29947052f, 0.36073788f, 0.40423935f, 0.44409324f, + 0.064717384f, 0.11872284f, 0.20919028f, 0.28301016f, 0.36802144f, 0.44747754f, + 0.193151690f, 0.21918993f, 0.26823232f, 0.30766049f, 0.39674668f, 0.45522504f, + 0.136849720f, 0.17581869f, 0.26349318f, 0.31417345f, 0.36960066f, 0.42791831f, + 0.193061690f, 0.21996506f, 0.29517646f, 0.33806725f, 0.39153706f, 0.44340380f, + 0.098565179f, 0.16979528f, 0.23333485f, 0.30380484f, 0.36654435f, 0.41758552f, + 0.142901030f, 0.21043695f, 0.30522982f, 0.36025073f, 0.40676141f, 0.45003224f, + 0.145613190f, 0.18443712f, 0.24662242f, 0.31447027f, 0.38225381f, 0.42837277f, + 0.251176660f, 0.28085865f, 0.31587424f, 0.34871696f, 0.39445892f, 0.44662421f, + 0.133816690f, 0.17622163f, 0.24380327f, 0.28396237f, 0.32809307f, 0.37532433f, + 0.177315700f, 0.20318793f, 0.27655558f, 0.35488501f, 0.40768754f, 0.44723190f, + 0.130848580f, 0.16442355f, 0.23815274f, 0.28617893f, 0.35951574f, 0.41662766f, + 0.134220490f, 0.26123559f, 0.29436035f, 0.34059452f, 0.38761183f, 0.45385345f, + 0.059422872f, 0.10497064f, 0.21978301f, 0.33427086f, 0.40351136f, 0.45184884f, + 0.142994260f, 0.27380337f, 0.32392882f, 0.36784687f, 0.40465562f, 0.44600403f, + 0.116004830f, 0.14796778f, 0.27228987f, 0.34179617f, 0.39311954f, 0.44016822f, + 0.245996100f, 0.26896363f, 0.31898875f, 0.36352887f, 0.40696431f, 0.44890165f, + 0.072173498f, 0.11864839f, 0.17283789f, 0.22419420f, 0.31759785f, 0.43734225f, + 0.139241880f, 0.17819210f, 0.22803594f, 0.26501417f, 0.32263158f, 0.39061689f, + 0.079146669f, 0.12807914f, 0.20505754f, 0.28451768f, 0.34267396f, 0.39425014f, + 0.185581160f, 0.20673854f, 0.24816327f, 0.28211183f, 0.37238530f, 0.42474096f, + 0.073407181f, 0.12148770f, 0.18750487f, 0.26671948f, 0.34627834f, 0.42100649f, + 0.176786130f, 0.19666658f, 0.25287274f, 0.30668454f, 0.37086389f, 0.41259755f, + 0.085308694f, 0.14425344f, 0.19922831f, 0.25959335f, 0.34555917f, 0.41120310f, + 0.188639580f, 0.26239423f, 0.28521213f, 0.32391588f, 0.35782756f, 0.41337293f, + 0.122131020f, 0.15263056f, 0.20129258f, 0.23778684f, 0.30478596f, 0.39871654f, + 0.175429700f, 0.19423608f, 0.23678906f, 0.27549846f, 0.36067030f, 0.41160394f, + 0.119189400f, 0.14839651f, 0.19721773f, 0.23690964f, 0.32670187f, 0.43820403f, + 0.131684130f, 0.25721459f, 0.28448545f, 0.32294678f, 0.36442816f, 0.44250607f, + 0.085802449f, 0.14103937f, 0.22418659f, 0.30627724f, 0.35842445f, 0.40982625f, + 0.128820440f, 0.25444798f, 0.28309633f, 0.34424530f, 0.39272354f, 0.43691562f, + 0.132605980f, 0.16563241f, 0.21732948f, 0.26659585f, 0.39024087f, 0.45279860f, + 0.234312330f, 0.26289148f, 0.28858043f, 0.31923045f, 0.36693357f, 0.42273091f, + 0.066913619f, 0.11174564f, 0.17118640f, 0.24009352f, 0.37462610f, 0.44981068f, + 0.185639320f, 0.20948515f, 0.27095540f, 0.30761470f, 0.35471667f, 0.41869175f, + 0.125534910f, 0.15639919f, 0.22045213f, 0.29690027f, 0.36034274f, 0.40578263f, + 0.194798190f, 0.22069282f, 0.28234110f, 0.32713553f, 0.38517899f, 0.42816026f, + 0.085073073f, 0.15836545f, 0.24638386f, 0.30374430f, 0.35995427f, 0.43827551f, + 0.185516870f, 0.21322354f, 0.26435247f, 0.32313780f, 0.37976277f, 0.43915130f, + 0.136729910f, 0.17363096f, 0.23523415f, 0.27817766f, 0.36010086f, 0.44481285f, + 0.239499040f, 0.26742173f, 0.29913088f, 0.33337737f, 0.38191519f, 0.45262276f, + 0.109306830f, 0.13962816f, 0.20534886f, 0.27722030f, 0.33992319f, 0.39062291f, + 0.179595260f, 0.19941354f, 0.27015954f, 0.31834604f, 0.38647809f, 0.45654088f, + 0.118738240f, 0.14800700f, 0.21956599f, 0.27258212f, 0.36918433f, 0.44755545f, + 0.176908270f, 0.26077464f, 0.28640628f, 0.35265194f, 0.39663136f, 0.43922160f, + 0.059878687f, 0.10816162f, 0.21481956f, 0.28530654f, 0.34399690f, 0.42289176f, + 0.125298830f, 0.16761966f, 0.29455499f, 0.36736398f, 0.41514581f, 0.45568637f, + 0.132064950f, 0.16520436f, 0.24257245f, 0.31378956f, 0.37122182f, 0.41558003f, + 0.248260440f, 0.27214823f, 0.30690390f, 0.33828614f, 0.40254065f, 0.45821278f, + 0.082464811f, 0.14120604f, 0.19676137f, 0.24440753f, 0.31120215f, 0.41734941f, + 0.183048080f, 0.20313040f, 0.25374041f, 0.28978449f, 0.35392058f, 0.40046587f, + 0.096008750f, 0.19205652f, 0.26031936f, 0.30998267f, 0.36005002f, 0.41374267f, + 0.194524100f, 0.22245612f, 0.26543764f, 0.29833795f, 0.36269526f, 0.43446257f, + 0.096760412f, 0.17681885f, 0.23611019f, 0.28616845f, 0.34521951f, 0.42352547f, + 0.191620720f, 0.21818699f, 0.28052740f, 0.31781127f, 0.36781149f, 0.43254535f, + 0.125638810f, 0.15853683f, 0.23819940f, 0.29029299f, 0.37995224f, 0.45315055f, + 0.243017800f, 0.27328285f, 0.30734326f, 0.33963007f, 0.37608978f, 0.41520298f, + 0.133222750f, 0.16798774f, 0.21402212f, 0.24935760f, 0.32005623f, 0.41682314f, + 0.186885370f, 0.21039202f, 0.25286530f, 0.28529456f, 0.36191248f, 0.44972585f, + 0.114535160f, 0.14259486f, 0.19594154f, 0.24858528f, 0.38835896f, 0.45716846f, + 0.166527800f, 0.26567252f, 0.29289306f, 0.33677574f, 0.37519203f, 0.43541243f, + 0.084944791f, 0.15003156f, 0.24253235f, 0.32251109f, 0.37827375f, 0.43099351f, + 0.119303270f, 0.24856258f, 0.29065368f, 0.36470470f, 0.42883150f, 0.46638276f, + 0.120605420f, 0.15682171f, 0.24962093f, 0.34730291f, 0.41806540f, 0.46035776f, + 0.219732780f, 0.27560250f, 0.30592696f, 0.35044880f, 0.39439534f, 0.45312034f, + 0.077308553f, 0.13464280f, 0.19751880f, 0.25325059f, 0.34806166f, 0.44638905f, + 0.200278980f, 0.22979005f, 0.27661907f, 0.31333340f, 0.38330744f, 0.44013638f, + 0.147984570f, 0.20195322f, 0.26483855f, 0.31025032f, 0.36569269f, 0.42239969f, + 0.195086490f, 0.23098500f, 0.30395854f, 0.34483682f, 0.38586214f, 0.42438066f, + 0.096725831f, 0.15616494f, 0.21843296f, 0.29493721f, 0.35664482f, 0.43073450f, + 0.186832170f, 0.21579466f, 0.30557582f, 0.35804882f, 0.40192237f, 0.44148013f, + 0.131465720f, 0.16604695f, 0.23214633f, 0.30213654f, 0.36326612f, 0.43615662f, + 0.248074080f, 0.27538389f, 0.30784390f, 0.33816285f, 0.38664576f, 0.43811284f, + 0.129804270f, 0.16455588f, 0.24948399f, 0.29846586f, 0.34646629f, 0.39636043f, + 0.166400470f, 0.20256213f, 0.26232918f, 0.34952652f, 0.42374855f, 0.46579300f, + 0.142332960f, 0.18013006f, 0.23247726f, 0.28747540f, 0.37225279f, 0.42277361f, + 0.218164380f, 0.27036123f, 0.29741317f, 0.33658242f, 0.37288172f, 0.43297122f, + 0.070747526f, 0.12972708f, 0.23503772f, 0.30178403f, 0.35944976f, 0.43280902f, + 0.203817720f, 0.28320849f, 0.32265104f, 0.36469291f, 0.39977801f, 0.44224295f, + 0.122382190f, 0.15795076f, 0.27432170f, 0.33024348f, 0.37383108f, 0.41668653f, + 0.246445660f, 0.27118517f, 0.31770823f, 0.35773353f, 0.39648445f, 0.43540417f, + 0.070426224f, 0.12260340f, 0.18382397f, 0.23249431f, 0.29712141f, 0.39919694f, + 0.183126440f, 0.20602093f, 0.24375562f, 0.27361644f, 0.33459363f, 0.41471750f, + 0.088748459f, 0.16327910f, 0.22175401f, 0.26667908f, 0.31866453f, 0.39616098f, + 0.187460500f, 0.20871643f, 0.27548782f, 0.31634516f, 0.39309748f, 0.43994220f, + 0.081379567f, 0.12891936f, 0.18833934f, 0.25567206f, 0.32705903f, 0.38458961f, + 0.191505080f, 0.21728053f, 0.28226653f, 0.32386961f, 0.38391795f, 0.45235836f, + 0.082156793f, 0.13994262f, 0.21264164f, 0.30082758f, 0.36988471f, 0.43363836f, + 0.237145870f, 0.26759673f, 0.29733906f, 0.32792373f, 0.36448143f, 0.40360639f, + 0.128199820f, 0.16341814f, 0.21755898f, 0.25443908f, 0.30439771f, 0.35908714f, + 0.189707910f, 0.21668527f, 0.25769184f, 0.28813697f, 0.34477993f, 0.41777603f, + 0.125467980f, 0.15380570f, 0.20025914f, 0.24632028f, 0.36725388f, 0.42488725f, + 0.203165520f, 0.26241863f, 0.28495340f, 0.32547246f, 0.36743034f, 0.44873687f, + 0.093381965f, 0.15915305f, 0.22155271f, 0.30877697f, 0.38380526f, 0.43903641f, + 0.155729460f, 0.27199100f, 0.30995504f, 0.35152115f, 0.38662749f, 0.43394669f, + 0.141375780f, 0.18067408f, 0.23815984f, 0.29034933f, 0.38882061f, 0.44831617f, + 0.205067360f, 0.26200850f, 0.28831845f, 0.35265548f, 0.41227841f, 0.46066867f, + 0.072047472f, 0.12115468f, 0.18961933f, 0.28488105f, 0.40495409f, 0.46004731f, + 0.198557750f, 0.22705201f, 0.27591618f, 0.31064014f, 0.36695315f, 0.41465139f, + 0.128799860f, 0.16494038f, 0.25362087f, 0.29961433f, 0.35336792f, 0.42859765f, + 0.189710480f, 0.22045927f, 0.29038955f, 0.34755716f, 0.41335089f, 0.45984727f, + 0.087636105f, 0.16804885f, 0.24880519f, 0.32500502f, 0.39871150f, 0.45243576f, + 0.183164490f, 0.20372954f, 0.28663902f, 0.33639693f, 0.39567505f, 0.45029614f, + 0.135442360f, 0.17219131f, 0.25232067f, 0.30812818f, 0.37522467f, 0.44933943f, + 0.237947800f, 0.26313746f, 0.29423846f, 0.33363250f, 0.40548313f, 0.46136835f, + 0.136450240f, 0.17206573f, 0.23044273f, 0.28127300f, 0.34912154f, 0.39454258f, + 0.184673430f, 0.21026600f, 0.27179282f, 0.32517703f, 0.41007950f, 0.46131088f, + 0.120635550f, 0.15057589f, 0.23738282f, 0.29356081f, 0.37244051f, 0.42760875f, + 0.165980800f, 0.26393604f, 0.29879643f, 0.37329254f, 0.42416075f, 0.46364654f, + 0.083243472f, 0.13716891f, 0.20532429f, 0.28573678f, 0.34618078f, 0.42885349f, + 0.124185840f, 0.25817832f, 0.30013923f, 0.35832406f, 0.40788565f, 0.45242538f, + 0.148751310f, 0.21168861f, 0.28155588f, 0.33399871f, 0.39200642f, 0.44392882f, + 0.250092790f, 0.27749655f, 0.31714030f, 0.35382269f, 0.40755488f, 0.45807079f, + 0.090218008f, 0.15844407f, 0.21605547f, 0.26747762f, 0.33611136f, 0.43256724f, + 0.194821460f, 0.22238574f, 0.26892332f, 0.29957274f, 0.34593681f, 0.39087253f, + 0.088872041f, 0.18684006f, 0.27868480f, 0.33185291f, 0.38399584f, 0.43532623f, + 0.187631470f, 0.21132813f, 0.26919143f, 0.30608744f, 0.37267119f, 0.45037854f, + 0.078499578f, 0.14581909f, 0.22353298f, 0.28124283f, 0.35460841f, 0.44710837f, + 0.203049030f, 0.23554188f, 0.29130760f, 0.32976939f, 0.38552827f, 0.43804459f, + 0.132090630f, 0.16828557f, 0.25117965f, 0.33118164f, 0.39126122f, 0.43521955f, + 0.245699330f, 0.28091560f, 0.31693809f, 0.35063725f, 0.38679310f, 0.42687325f, + 0.141120120f, 0.18351512f, 0.24129878f, 0.28194334f, 0.34056397f, 0.42074436f, + 0.176576340f, 0.19930558f, 0.25055988f, 0.30421218f, 0.40924681f, 0.46535353f, + 0.117761100f, 0.14946364f, 0.21764598f, 0.29577606f, 0.40879019f, 0.46136645f, + 0.204842420f, 0.27294301f, 0.30601511f, 0.35160404f, 0.38727312f, 0.43085356f, + 0.073765998f, 0.14878616f, 0.27867445f, 0.35617826f, 0.40839136f, 0.45292538f, + 0.125517660f, 0.25496685f, 0.32758337f, 0.38197773f, 0.42435415f, 0.46126376f, + 0.135962010f, 0.17555426f, 0.24178151f, 0.31425983f, 0.40720232f, 0.45869366f, + 0.213570120f, 0.27094587f, 0.30863435f, 0.37331744f, 0.42018011f, 0.46102471f, + 0.082998736f, 0.14651530f, 0.21003822f, 0.28279492f, 0.38739390f, 0.45279145f, + 0.198570550f, 0.22875204f, 0.28417900f, 0.32642267f, 0.40238371f, 0.45320042f, + 0.141324200f, 0.19351582f, 0.27967266f, 0.32946724f, 0.37612094f, 0.41912905f, + 0.201481430f, 0.23856193f, 0.30309500f, 0.34633198f, 0.40074668f, 0.44775506f, + 0.094264220f, 0.16969966f, 0.23129383f, 0.28788431f, 0.37402386f, 0.44657509f, + 0.190612400f, 0.23544456f, 0.31650278f, 0.36818431f, 0.41389673f, 0.45404931f, + 0.145178650f, 0.19384152f, 0.26072685f, 0.31177170f, 0.38904763f, 0.44618125f, + 0.249738030f, 0.28583093f, 0.32433884f, 0.36184735f, 0.40237550f, 0.44552961f, + 0.144466440f, 0.19269281f, 0.25474986f, 0.29651925f, 0.34405115f, 0.39494788f, + 0.177748120f, 0.20967896f, 0.29994813f, 0.37438345f, 0.42341220f, 0.46196806f, + 0.144017810f, 0.18743776f, 0.25098351f, 0.29549083f, 0.36361608f, 0.43793137f, + 0.191890800f, 0.26774988f, 0.29463282f, 0.34191791f, 0.38746328f, 0.45369258f, + 0.081212845f, 0.13994797f, 0.22358119f, 0.33366778f, 0.41201077f, 0.45855130f, + 0.181044650f, 0.28450829f, 0.33194281f, 0.38005566f, 0.41856023f, 0.45789922f, + 0.136313630f, 0.18429069f, 0.26984493f, 0.34070980f, 0.40759216f, 0.45475266f, + 0.240476170f, 0.27948010f, 0.32327234f, 0.37258368f, 0.41532038f, 0.45744253f +}; + +const float swb_tbe_lsfvq_cbook_8b[256*LPC_SHB_ORDER] = +{ + 0.052035f, 0.098557f, 0.128235f, 0.155222f, 0.187634f, 0.220354f, 0.248003f, 0.327378f, 0.416763f, 0.468886f, + 0.050902f, 0.090274f, 0.123988f, 0.172234f, 0.224479f, 0.288101f, 0.337089f, 0.374172f, 0.403673f, 0.442608f, + 0.047188f, 0.089025f, 0.128973f, 0.167152f, 0.212901f, 0.254805f, 0.296290f, 0.362619f, 0.403389f, 0.449070f, + 0.035345f, 0.083282f, 0.158003f, 0.212631f, 0.253206f, 0.293314f, 0.325157f, 0.356067f, 0.389327f, 0.439909f, + 0.049324f, 0.091699f, 0.133308f, 0.177313f, 0.216889f, 0.248068f, 0.286140f, 0.319129f, 0.388743f, 0.452730f, + 0.037590f, 0.074792f, 0.126499f, 0.196718f, 0.236226f, 0.274430f, 0.316669f, 0.363084f, 0.433737f, 0.467349f, + 0.049999f, 0.094260f, 0.156667f, 0.193806f, 0.224624f, 0.253432f, 0.298661f, 0.377723f, 0.419777f, 0.464133f, + 0.038569f, 0.077613f, 0.169806f, 0.204031f, 0.242844f, 0.289350f, 0.336338f, 0.381981f, 0.423438f, 0.462244f, + 0.039797f, 0.077432f, 0.113315f, 0.148404f, 0.200326f, 0.241409f, 0.286872f, 0.359925f, 0.404895f, 0.452684f, + 0.050430f, 0.099036f, 0.143005f, 0.195455f, 0.242036f, 0.281478f, 0.323205f, 0.366833f, 0.402614f, 0.450408f, + 0.039724f, 0.079916f, 0.130839f, 0.179575f, 0.218692f, 0.261122f, 0.320798f, 0.380589f, 0.420132f, 0.460065f, + 0.062070f, 0.105792f, 0.170204f, 0.199290f, 0.234202f, 0.268038f, 0.333250f, 0.390551f, 0.418930f, 0.457810f, + 0.079997f, 0.120714f, 0.160981f, 0.199639f, 0.229158f, 0.259921f, 0.288582f, 0.329020f, 0.380142f, 0.430256f, + 0.045641f, 0.080952f, 0.126548f, 0.172023f, 0.224929f, 0.281759f, 0.360638f, 0.396302f, 0.426277f, 0.459174f, + 0.067880f, 0.101438f, 0.143420f, 0.179072f, 0.220060f, 0.263601f, 0.346964f, 0.387408f, 0.415045f, 0.444299f, + 0.038652f, 0.093084f, 0.143655f, 0.192895f, 0.264359f, 0.309455f, 0.341003f, 0.380032f, 0.409710f, 0.453003f, + 0.050708f, 0.090949f, 0.126797f, 0.165211f, 0.202591f, 0.237959f, 0.282372f, 0.346666f, 0.391780f, 0.440679f, + 0.046423f, 0.087161f, 0.150877f, 0.194305f, 0.229067f, 0.270295f, 0.334805f, 0.371802f, 0.405116f, 0.457953f, + 0.044360f, 0.087261f, 0.139254f, 0.182219f, 0.219289f, 0.261504f, 0.309799f, 0.359196f, 0.408816f, 0.457282f, + 0.034881f, 0.089771f, 0.160723f, 0.208734f, 0.255654f, 0.288616f, 0.323156f, 0.354465f, 0.423951f, 0.466020f, + 0.051086f, 0.093155f, 0.140520f, 0.176030f, 0.216785f, 0.257930f, 0.308053f, 0.359569f, 0.390408f, 0.419868f, + 0.051928f, 0.099511f, 0.144135f, 0.190596f, 0.241070f, 0.289741f, 0.335984f, 0.378008f, 0.417474f, 0.459764f, + 0.041656f, 0.085336f, 0.164968f, 0.198531f, 0.228507f, 0.264871f, 0.318823f, 0.366222f, 0.416159f, 0.459177f, + 0.063772f, 0.119952f, 0.176631f, 0.218406f, 0.251883f, 0.296547f, 0.335911f, 0.368682f, 0.403997f, 0.454099f, + 0.059576f, 0.096358f, 0.126102f, 0.157582f, 0.193300f, 0.225485f, 0.274787f, 0.360048f, 0.430168f, 0.473165f, + 0.050090f, 0.098011f, 0.150107f, 0.194228f, 0.239956f, 0.284161f, 0.328550f, 0.373362f, 0.417904f, 0.459405f, + 0.050455f, 0.091803f, 0.128564f, 0.163400f, 0.213005f, 0.269193f, 0.341329f, 0.387102f, 0.424272f, 0.465410f, + 0.056626f, 0.105111f, 0.157033f, 0.200776f, 0.238054f, 0.282274f, 0.337598f, 0.395108f, 0.431675f, 0.466636f, + 0.041642f, 0.108843f, 0.169446f, 0.197564f, 0.223758f, 0.251886f, 0.303709f, 0.346790f, 0.412135f, 0.456278f, + 0.045415f, 0.088367f, 0.137979f, 0.191624f, 0.240474f, 0.288265f, 0.348450f, 0.394310f, 0.440392f, 0.471964f, + 0.046252f, 0.096877f, 0.163695f, 0.195612f, 0.222631f, 0.252841f, 0.329557f, 0.384350f, 0.432499f, 0.470718f, + 0.053043f, 0.104263f, 0.159826f, 0.209898f, 0.257555f, 0.321633f, 0.369402f, 0.398653f, 0.424938f, 0.462350f, + 0.043656f, 0.081158f, 0.119295f, 0.162597f, 0.202663f, 0.242606f, 0.285262f, 0.336831f, 0.412286f, 0.457530f, + 0.042710f, 0.080739f, 0.129188f, 0.194265f, 0.236487f, 0.281364f, 0.322263f, 0.353819f, 0.398147f, 0.457506f, + 0.034022f, 0.067080f, 0.110067f, 0.161100f, 0.245813f, 0.298294f, 0.336441f, 0.379210f, 0.426400f, 0.464858f, + 0.041504f, 0.104317f, 0.174678f, 0.212809f, 0.241453f, 0.277049f, 0.329887f, 0.379542f, 0.415948f, 0.452461f, + 0.043385f, 0.093120f, 0.156620f, 0.187415f, 0.219909f, 0.252543f, 0.285489f, 0.331396f, 0.421562f, 0.463942f, + 0.032947f, 0.067948f, 0.125627f, 0.195426f, 0.246592f, 0.284364f, 0.333690f, 0.378531f, 0.417714f, 0.452488f, + 0.049156f, 0.104448f, 0.150380f, 0.189623f, 0.226621f, 0.266196f, 0.320491f, 0.363628f, 0.410110f, 0.460970f, + 0.059406f, 0.107544f, 0.158619f, 0.213862f, 0.255056f, 0.305344f, 0.347819f, 0.379775f, 0.414531f, 0.461875f, + 0.042551f, 0.081551f, 0.122191f, 0.173384f, 0.212196f, 0.253318f, 0.299526f, 0.366219f, 0.418377f, 0.460170f, + 0.054564f, 0.097456f, 0.139734f, 0.189857f, 0.240306f, 0.279858f, 0.341376f, 0.385962f, 0.412633f, 0.443663f, + 0.047246f, 0.085779f, 0.123843f, 0.162683f, 0.199213f, 0.237097f, 0.335143f, 0.388883f, 0.421806f, 0.461765f, + 0.053449f, 0.122299f, 0.157276f, 0.197221f, 0.242155f, 0.288987f, 0.338839f, 0.378598f, 0.407019f, 0.443119f, + 0.061169f, 0.096794f, 0.155005f, 0.186632f, 0.216953f, 0.248877f, 0.315884f, 0.372060f, 0.409344f, 0.450829f, + 0.050160f, 0.097186f, 0.144946f, 0.191946f, 0.238536f, 0.282942f, 0.336958f, 0.391570f, 0.431474f, 0.468178f, + 0.070512f, 0.115329f, 0.156141f, 0.186164f, 0.223411f, 0.278915f, 0.315935f, 0.370299f, 0.422165f, 0.463007f, + 0.052587f, 0.101896f, 0.154071f, 0.206102f, 0.254920f, 0.314033f, 0.367686f, 0.401531f, 0.433527f, 0.471797f, + 0.067698f, 0.106830f, 0.141570f, 0.175913f, 0.207186f, 0.239077f, 0.299182f, 0.363370f, 0.402273f, 0.448275f, + 0.050042f, 0.096846f, 0.142801f, 0.189262f, 0.233767f, 0.278335f, 0.328758f, 0.378276f, 0.424023f, 0.463870f, + 0.048564f, 0.093699f, 0.138452f, 0.183259f, 0.224028f, 0.268624f, 0.319818f, 0.373529f, 0.420181f, 0.461720f, + 0.035663f, 0.110208f, 0.182596f, 0.215274f, 0.262474f, 0.305840f, 0.334102f, 0.363985f, 0.391665f, 0.450045f, + 0.052124f, 0.097379f, 0.141664f, 0.187867f, 0.225707f, 0.268701f, 0.306038f, 0.358072f, 0.403022f, 0.453386f, + 0.046364f, 0.094056f, 0.145010f, 0.197890f, 0.235910f, 0.284683f, 0.329466f, 0.366312f, 0.443226f, 0.473416f, + 0.065692f, 0.108572f, 0.157530f, 0.204882f, 0.236869f, 0.270301f, 0.305422f, 0.366582f, 0.418869f, 0.464143f, + 0.081775f, 0.123697f, 0.162035f, 0.213510f, 0.253580f, 0.285130f, 0.316195f, 0.376374f, 0.434072f, 0.472957f, + 0.071914f, 0.116132f, 0.153572f, 0.182184f, 0.211027f, 0.240482f, 0.272342f, 0.368056f, 0.422300f, 0.463416f, + 0.055135f, 0.104947f, 0.151424f, 0.197856f, 0.244545f, 0.291623f, 0.334237f, 0.376193f, 0.417664f, 0.459559f, + 0.047928f, 0.088506f, 0.128407f, 0.196811f, 0.234221f, 0.262202f, 0.339912f, 0.389867f, 0.432755f, 0.470636f, + 0.061209f, 0.130070f, 0.168080f, 0.195727f, 0.232576f, 0.266266f, 0.329227f, 0.384677f, 0.415326f, 0.450918f, + 0.054489f, 0.114179f, 0.160730f, 0.204526f, 0.247099f, 0.288682f, 0.320040f, 0.350371f, 0.393345f, 0.454259f, + 0.050257f, 0.098343f, 0.146333f, 0.195038f, 0.244345f, 0.293566f, 0.353243f, 0.395361f, 0.430313f, 0.469396f, + 0.046313f, 0.098069f, 0.159706f, 0.198648f, 0.234593f, 0.268660f, 0.359439f, 0.425175f, 0.450429f, 0.472752f, + 0.065195f, 0.111302f, 0.163983f, 0.223289f, 0.264603f, 0.313139f, 0.359677f, 0.394680f, 0.421766f, 0.463443f, + 0.049833f, 0.099641f, 0.142577f, 0.172120f, 0.206797f, 0.237530f, 0.271835f, 0.310803f, 0.368226f, 0.442268f, + 0.051561f, 0.092407f, 0.127677f, 0.184605f, 0.228561f, 0.264833f, 0.337058f, 0.373648f, 0.408072f, 0.458254f, + 0.050312f, 0.093979f, 0.133001f, 0.176857f, 0.224745f, 0.262482f, 0.313019f, 0.370051f, 0.406746f, 0.461218f, + 0.056453f, 0.100292f, 0.164556f, 0.206451f, 0.238837f, 0.280290f, 0.320629f, 0.359375f, 0.404283f, 0.462747f, + 0.064422f, 0.107489f, 0.148611f, 0.185763f, 0.218563f, 0.255882f, 0.294328f, 0.331455f, 0.376622f, 0.436460f, + 0.046651f, 0.088769f, 0.126223f, 0.207005f, 0.246095f, 0.284572f, 0.333915f, 0.369094f, 0.423764f, 0.462912f, + 0.056372f, 0.100125f, 0.145020f, 0.186096f, 0.223092f, 0.266834f, 0.309121f, 0.374704f, 0.413627f, 0.455613f, + 0.035065f, 0.084427f, 0.179107f, 0.228245f, 0.259827f, 0.296722f, 0.342853f, 0.375360f, 0.423312f, 0.459834f, + 0.051556f, 0.093559f, 0.131989f, 0.171289f, 0.206668f, 0.242179f, 0.276215f, 0.370322f, 0.418996f, 0.458514f, + 0.064906f, 0.103567f, 0.160614f, 0.209947f, 0.240290f, 0.279374f, 0.314472f, 0.370362f, 0.411818f, 0.440592f, + 0.051333f, 0.093194f, 0.134650f, 0.184715f, 0.225233f, 0.258320f, 0.299595f, 0.380254f, 0.431966f, 0.466464f, + 0.054906f, 0.104680f, 0.156332f, 0.201242f, 0.242115f, 0.293254f, 0.350097f, 0.390361f, 0.417661f, 0.453152f, + 0.057964f, 0.111565f, 0.163839f, 0.193942f, 0.229367f, 0.268561f, 0.301745f, 0.355413f, 0.397475f, 0.426184f, + 0.043021f, 0.099243f, 0.155661f, 0.184626f, 0.228258f, 0.302504f, 0.358238f, 0.390818f, 0.429834f, 0.463440f, + 0.045380f, 0.120045f, 0.163293f, 0.195013f, 0.229454f, 0.271296f, 0.350581f, 0.391168f, 0.420733f, 0.455968f, + 0.047668f, 0.096305f, 0.154868f, 0.214976f, 0.270766f, 0.313434f, 0.350305f, 0.385491f, 0.424396f, 0.457538f, + 0.047251f, 0.089307f, 0.132379f, 0.176882f, 0.213945f, 0.248516f, 0.284924f, 0.345563f, 0.410789f, 0.454839f, + 0.043366f, 0.088702f, 0.144534f, 0.191411f, 0.235903f, 0.273950f, 0.319010f, 0.377616f, 0.422360f, 0.464893f, + 0.045624f, 0.091445f, 0.137199f, 0.184217f, 0.230245f, 0.275709f, 0.321477f, 0.366635f, 0.411549f, 0.456497f, + 0.042352f, 0.097756f, 0.173684f, 0.215934f, 0.261779f, 0.294833f, 0.331844f, 0.376147f, 0.440475f, 0.470683f, + 0.038091f, 0.091036f, 0.161878f, 0.196009f, 0.230216f, 0.262778f, 0.314032f, 0.356498f, 0.393785f, 0.443990f, + 0.045665f, 0.091177f, 0.141352f, 0.193543f, 0.239618f, 0.284706f, 0.341027f, 0.382868f, 0.419859f, 0.463306f, + 0.041904f, 0.103110f, 0.154646f, 0.188554f, 0.225202f, 0.267803f, 0.305332f, 0.349841f, 0.431723f, 0.469552f, + 0.077431f, 0.117466f, 0.168864f, 0.221652f, 0.253857f, 0.294713f, 0.346262f, 0.377031f, 0.425887f, 0.467332f, + 0.064470f, 0.103906f, 0.134849f, 0.160779f, 0.196409f, 0.244298f, 0.314086f, 0.379702f, 0.416731f, 0.463122f, + 0.049451f, 0.112350f, 0.166433f, 0.195509f, 0.227644f, 0.285465f, 0.331780f, 0.367291f, 0.432216f, 0.466286f, + 0.058067f, 0.098622f, 0.137834f, 0.175730f, 0.218379f, 0.270120f, 0.325626f, 0.378807f, 0.443060f, 0.474998f, + 0.052308f, 0.115312f, 0.157669f, 0.200104f, 0.247392f, 0.279777f, 0.322273f, 0.392271f, 0.433586f, 0.467817f, + 0.058782f, 0.111246f, 0.168484f, 0.215834f, 0.244122f, 0.273877f, 0.299244f, 0.338369f, 0.412816f, 0.466858f, + 0.055542f, 0.086661f, 0.144229f, 0.216409f, 0.252097f, 0.297799f, 0.342351f, 0.370742f, 0.429205f, 0.465769f, + 0.063246f, 0.100799f, 0.164514f, 0.204780f, 0.229008f, 0.259317f, 0.319118f, 0.378226f, 0.441896f, 0.474270f, + 0.049656f, 0.100510f, 0.158979f, 0.226797f, 0.269956f, 0.309657f, 0.351457f, 0.393377f, 0.442146f, 0.470304f, + 0.066278f, 0.103915f, 0.139783f, 0.171615f, 0.205432f, 0.233412f, 0.258944f, 0.302518f, 0.408815f, 0.464278f, + 0.048237f, 0.093317f, 0.141389f, 0.189982f, 0.235703f, 0.281926f, 0.328964f, 0.373539f, 0.416565f, 0.460637f, + 0.051115f, 0.089333f, 0.124829f, 0.175556f, 0.227688f, 0.272289f, 0.313617f, 0.356144f, 0.426854f, 0.468024f, + 0.057016f, 0.110189f, 0.160396f, 0.211405f, 0.246994f, 0.287899f, 0.335640f, 0.370610f, 0.408313f, 0.462788f, + 0.045706f, 0.110933f, 0.160922f, 0.208233f, 0.238788f, 0.272099f, 0.299401f, 0.332730f, 0.381907f, 0.454209f, + 0.044199f, 0.080129f, 0.119936f, 0.210423f, 0.254754f, 0.297418f, 0.348033f, 0.383461f, 0.436047f, 0.467678f, + 0.059370f, 0.103993f, 0.152197f, 0.193477f, 0.232752f, 0.273256f, 0.312825f, 0.377850f, 0.411394f, 0.457251f, + 0.059698f, 0.114702f, 0.164424f, 0.210373f, 0.258366f, 0.304006f, 0.349730f, 0.389369f, 0.431678f, 0.467558f, + 0.050972f, 0.099832f, 0.140005f, 0.182190f, 0.219279f, 0.255299f, 0.294189f, 0.366548f, 0.411624f, 0.452662f, + 0.059947f, 0.105101f, 0.147291f, 0.189602f, 0.242184f, 0.277632f, 0.329136f, 0.385035f, 0.415412f, 0.464746f, + 0.050246f, 0.103445f, 0.142498f, 0.184607f, 0.213644f, 0.242299f, 0.319253f, 0.380800f, 0.447847f, 0.479237f, + 0.067193f, 0.115430f, 0.155858f, 0.206126f, 0.252681f, 0.293822f, 0.356656f, 0.397588f, 0.423304f, 0.464089f, + 0.071847f, 0.116894f, 0.157883f, 0.194092f, 0.230547f, 0.274564f, 0.325945f, 0.365502f, 0.398749f, 0.451080f, + 0.071752f, 0.107567f, 0.149280f, 0.194893f, 0.232418f, 0.278702f, 0.361895f, 0.398599f, 0.425587f, 0.457898f, + 0.068739f, 0.115103f, 0.157316f, 0.197895f, 0.237993f, 0.279071f, 0.328650f, 0.383319f, 0.420022f, 0.465113f, + 0.052303f, 0.094829f, 0.144186f, 0.186062f, 0.279484f, 0.319196f, 0.354590f, 0.387530f, 0.437802f, 0.465583f, + 0.055846f, 0.106998f, 0.151640f, 0.182290f, 0.210559f, 0.239134f, 0.274479f, 0.338376f, 0.407908f, 0.453481f, + 0.056627f, 0.103955f, 0.149473f, 0.194316f, 0.238331f, 0.280339f, 0.318046f, 0.371471f, 0.426297f, 0.467870f, + 0.061231f, 0.103217f, 0.144741f, 0.186145f, 0.226738f, 0.267120f, 0.329755f, 0.373349f, 0.417263f, 0.463712f, + 0.045494f, 0.110081f, 0.163067f, 0.227778f, 0.280124f, 0.307836f, 0.336439f, 0.369219f, 0.402807f, 0.456421f, + 0.053383f, 0.102864f, 0.156288f, 0.198372f, 0.233337f, 0.267640f, 0.304209f, 0.356227f, 0.407078f, 0.455673f, + 0.056676f, 0.107005f, 0.155125f, 0.201255f, 0.250254f, 0.297223f, 0.339905f, 0.382321f, 0.423693f, 0.461944f, + 0.054333f, 0.117799f, 0.170332f, 0.204234f, 0.239159f, 0.274313f, 0.314448f, 0.375919f, 0.415366f, 0.461096f, + 0.066036f, 0.136196f, 0.172592f, 0.232898f, 0.276089f, 0.302787f, 0.329116f, 0.395210f, 0.449302f, 0.475747f, + 0.070331f, 0.100716f, 0.133253f, 0.171137f, 0.209264f, 0.237895f, 0.305371f, 0.364686f, 0.438728f, 0.479133f, + 0.049672f, 0.104018f, 0.154836f, 0.206341f, 0.253671f, 0.295628f, 0.338852f, 0.376356f, 0.415621f, 0.460077f, + 0.056211f, 0.101148f, 0.145610f, 0.197140f, 0.227748f, 0.264313f, 0.341533f, 0.388764f, 0.445317f, 0.477085f, + 0.055185f, 0.133050f, 0.180174f, 0.209627f, 0.248220f, 0.279970f, 0.328967f, 0.384183f, 0.427107f, 0.462356f, + 0.090510f, 0.132862f, 0.173536f, 0.213099f, 0.242241f, 0.277461f, 0.307068f, 0.358492f, 0.406083f, 0.445895f, + 0.058962f, 0.100504f, 0.149829f, 0.208057f, 0.234691f, 0.276924f, 0.357507f, 0.397315f, 0.440325f, 0.472359f, + 0.060359f, 0.115102f, 0.165680f, 0.200810f, 0.227294f, 0.259266f, 0.358724f, 0.400750f, 0.443988f, 0.474842f, + 0.057406f, 0.110946f, 0.171732f, 0.222531f, 0.261630f, 0.332974f, 0.376127f, 0.402824f, 0.429325f, 0.465189f, + 0.043822f, 0.082882f, 0.122127f, 0.163180f, 0.199988f, 0.233325f, 0.273271f, 0.326231f, 0.395731f, 0.451164f, + 0.043530f, 0.086208f, 0.128358f, 0.174740f, 0.247178f, 0.286590f, 0.326910f, 0.374201f, 0.412175f, 0.456349f, + 0.044183f, 0.084451f, 0.124772f, 0.160673f, 0.219266f, 0.265006f, 0.316722f, 0.374047f, 0.409896f, 0.451766f, + 0.050936f, 0.101062f, 0.152285f, 0.210171f, 0.245676f, 0.292805f, 0.333955f, 0.366681f, 0.401168f, 0.455315f, + 0.046805f, 0.085866f, 0.127908f, 0.181072f, 0.225619f, 0.265095f, 0.301043f, 0.341348f, 0.395446f, 0.449907f, + 0.042622f, 0.082584f, 0.131883f, 0.184679f, 0.232497f, 0.279794f, 0.335535f, 0.379437f, 0.425137f, 0.465917f, + 0.052394f, 0.096555f, 0.141288f, 0.193157f, 0.229466f, 0.269961f, 0.307875f, 0.369736f, 0.427604f, 0.463768f, + 0.049014f, 0.101187f, 0.157612f, 0.211850f, 0.252631f, 0.293740f, 0.349772f, 0.390796f, 0.430148f, 0.466887f, + 0.061472f, 0.102460f, 0.130638f, 0.154914f, 0.188934f, 0.224962f, 0.289961f, 0.378839f, 0.409509f, 0.454753f, + 0.040355f, 0.111547f, 0.160810f, 0.198176f, 0.232341f, 0.282372f, 0.328114f, 0.365421f, 0.405953f, 0.452666f, + 0.051498f, 0.100439f, 0.143970f, 0.177506f, 0.213658f, 0.248304f, 0.327782f, 0.387335f, 0.423694f, 0.464601f, + 0.068825f, 0.113622f, 0.169531f, 0.214249f, 0.247214f, 0.285172f, 0.328523f, 0.387739f, 0.417886f, 0.464554f, + 0.072521f, 0.113366f, 0.160172f, 0.198528f, 0.226144f, 0.254678f, 0.310546f, 0.354542f, 0.387805f, 0.442152f, + 0.056215f, 0.098619f, 0.133402f, 0.181712f, 0.239008f, 0.278502f, 0.344724f, 0.388895f, 0.423036f, 0.467855f, + 0.062429f, 0.109771f, 0.162502f, 0.196939f, 0.224387f, 0.262071f, 0.323117f, 0.368722f, 0.416985f, 0.462413f, + 0.060110f, 0.108774f, 0.150308f, 0.199802f, 0.264652f, 0.304578f, 0.347395f, 0.390206f, 0.426311f, 0.464915f, + 0.045681f, 0.089659f, 0.149800f, 0.186117f, 0.216751f, 0.246327f, 0.290352f, 0.344660f, 0.389432f, 0.444891f, + 0.050829f, 0.096543f, 0.155589f, 0.190895f, 0.224301f, 0.271682f, 0.326354f, 0.381553f, 0.421373f, 0.457146f, + 0.044771f, 0.084669f, 0.139044f, 0.192501f, 0.226907f, 0.263807f, 0.306407f, 0.377071f, 0.414961f, 0.450916f, + 0.058452f, 0.110406f, 0.157460f, 0.204676f, 0.258762f, 0.290562f, 0.319844f, 0.352065f, 0.432222f, 0.472393f, + 0.056675f, 0.105769f, 0.145256f, 0.189372f, 0.223155f, 0.268584f, 0.316662f, 0.365541f, 0.401645f, 0.434404f, + 0.049272f, 0.094814f, 0.143723f, 0.196904f, 0.246241f, 0.301437f, 0.346313f, 0.383753f, 0.419651f, 0.459244f, + 0.047694f, 0.094350f, 0.151873f, 0.209061f, 0.245856f, 0.275424f, 0.315157f, 0.371735f, 0.428434f, 0.463634f, + 0.070013f, 0.117284f, 0.176432f, 0.220387f, 0.259562f, 0.300623f, 0.342089f, 0.390694f, 0.417372f, 0.462571f, + 0.058921f, 0.104850f, 0.142858f, 0.178126f, 0.210803f, 0.238810f, 0.288098f, 0.384526f, 0.432185f, 0.467076f, + 0.047972f, 0.097327f, 0.148890f, 0.203855f, 0.243240f, 0.283598f, 0.334893f, 0.372088f, 0.412174f, 0.464413f, + 0.053684f, 0.096809f, 0.143044f, 0.181581f, 0.228389f, 0.270800f, 0.322361f, 0.391276f, 0.430659f, 0.466880f, + 0.044586f, 0.122337f, 0.167705f, 0.201662f, 0.240097f, 0.289818f, 0.345058f, 0.382092f, 0.438138f, 0.472021f, + 0.058657f, 0.131647f, 0.175035f, 0.201389f, 0.228297f, 0.262383f, 0.300653f, 0.346236f, 0.427618f, 0.466306f, + 0.038131f, 0.079609f, 0.143124f, 0.213799f, 0.246000f, 0.274980f, 0.350246f, 0.403256f, 0.438897f, 0.468033f, + 0.068699f, 0.115225f, 0.168266f, 0.197077f, 0.222782f, 0.246507f, 0.334509f, 0.387455f, 0.435752f, 0.475064f, + 0.051779f, 0.102976f, 0.156663f, 0.213128f, 0.264735f, 0.326526f, 0.372141f, 0.403846f, 0.432850f, 0.471923f, + 0.060586f, 0.101498f, 0.135493f, 0.173480f, 0.209652f, 0.250462f, 0.291284f, 0.342503f, 0.417229f, 0.462133f, + 0.044335f, 0.086169f, 0.144113f, 0.197628f, 0.235900f, 0.273515f, 0.311798f, 0.358357f, 0.413356f, 0.462417f, + 0.037139f, 0.074523f, 0.116614f, 0.165055f, 0.223223f, 0.273117f, 0.329507f, 0.383426f, 0.435814f, 0.470269f, + 0.047181f, 0.097768f, 0.171023f, 0.205397f, 0.245358f, 0.295311f, 0.336586f, 0.369485f, 0.421233f, 0.465914f, + 0.062309f, 0.104500f, 0.147401f, 0.193110f, 0.228058f, 0.260174f, 0.286437f, 0.328216f, 0.408873f, 0.457704f, + 0.033758f, 0.076535f, 0.146968f, 0.223914f, 0.256314f, 0.293898f, 0.344191f, 0.380044f, 0.429295f, 0.458511f, + 0.053820f, 0.100870f, 0.151208f, 0.199506f, 0.237034f, 0.278242f, 0.317503f, 0.365012f, 0.414293f, 0.458401f, + 0.048959f, 0.115875f, 0.173948f, 0.217520f, 0.259862f, 0.301989f, 0.347552f, 0.382497f, 0.417961f, 0.461917f, + 0.049542f, 0.091687f, 0.132903f, 0.189723f, 0.224344f, 0.257479f, 0.299641f, 0.352070f, 0.426438f, 0.468136f, + 0.074975f, 0.118701f, 0.151425f, 0.178468f, 0.223099f, 0.296570f, 0.342204f, 0.375124f, 0.418237f, 0.461155f, + 0.048862f, 0.101636f, 0.141831f, 0.184422f, 0.217823f, 0.249609f, 0.343243f, 0.399113f, 0.450686f, 0.477330f, + 0.074971f, 0.112223f, 0.157913f, 0.196284f, 0.243594f, 0.305898f, 0.340704f, 0.371399f, 0.418209f, 0.461180f, + 0.047352f, 0.115276f, 0.160725f, 0.193027f, 0.229854f, 0.263731f, 0.301940f, 0.378552f, 0.414083f, 0.446173f, + 0.059846f, 0.105671f, 0.144046f, 0.198296f, 0.245954f, 0.283923f, 0.350516f, 0.391352f, 0.430367f, 0.471737f, + 0.074555f, 0.112890f, 0.160280f, 0.193719f, 0.233102f, 0.266509f, 0.312007f, 0.386544f, 0.420167f, 0.458038f, + 0.067261f, 0.111598f, 0.155216f, 0.207272f, 0.253291f, 0.309808f, 0.375775f, 0.406060f, 0.429646f, 0.466527f, + 0.072015f, 0.113855f, 0.152641f, 0.185966f, 0.212160f, 0.244403f, 0.279304f, 0.353568f, 0.397873f, 0.432053f, + 0.057609f, 0.105877f, 0.148922f, 0.188700f, 0.232036f, 0.282119f, 0.329612f, 0.375947f, 0.416782f, 0.457815f, + 0.050973f, 0.100177f, 0.140092f, 0.185550f, 0.238056f, 0.273150f, 0.321487f, 0.383660f, 0.415638f, 0.456817f, + 0.039806f, 0.126350f, 0.178948f, 0.213873f, 0.255655f, 0.294524f, 0.330344f, 0.360261f, 0.416162f, 0.466911f, + 0.063393f, 0.108247f, 0.149242f, 0.189683f, 0.222867f, 0.262691f, 0.299364f, 0.359972f, 0.412753f, 0.457277f, + 0.050600f, 0.099234f, 0.150035f, 0.198292f, 0.246257f, 0.290806f, 0.336586f, 0.382631f, 0.424274f, 0.463374f, + 0.067312f, 0.111338f, 0.151025f, 0.202518f, 0.240338f, 0.269562f, 0.300697f, 0.385260f, 0.440923f, 0.472259f, + 0.092753f, 0.142329f, 0.176758f, 0.223424f, 0.268502f, 0.296763f, 0.319964f, 0.376238f, 0.441441f, 0.477606f, + 0.057530f, 0.097677f, 0.159509f, 0.201106f, 0.224079f, 0.245637f, 0.286003f, 0.375766f, 0.445386f, 0.477458f, + 0.055718f, 0.105169f, 0.156792f, 0.203385f, 0.244396f, 0.285413f, 0.325547f, 0.384007f, 0.421448f, 0.459753f, + 0.044415f, 0.093549f, 0.159707f, 0.192449f, 0.225942f, 0.267813f, 0.348584f, 0.389866f, 0.428214f, 0.465053f, + 0.073100f, 0.142639f, 0.179538f, 0.209861f, 0.241096f, 0.284495f, 0.333600f, 0.382609f, 0.420087f, 0.454347f, + 0.056150f, 0.133011f, 0.171789f, 0.209798f, 0.243168f, 0.280293f, 0.313300f, 0.361975f, 0.402894f, 0.441400f, + 0.050711f, 0.100022f, 0.148476f, 0.200043f, 0.247876f, 0.305520f, 0.362364f, 0.399378f, 0.431164f, 0.470519f, + 0.050151f, 0.102726f, 0.178139f, 0.214644f, 0.239684f, 0.272465f, 0.350549f, 0.395865f, 0.439724f, 0.472007f, + 0.057321f, 0.112456f, 0.176664f, 0.223544f, 0.265943f, 0.332838f, 0.374528f, 0.400087f, 0.422190f, 0.452780f, + 0.068936f, 0.111462f, 0.152424f, 0.184775f, 0.213783f, 0.241083f, 0.269875f, 0.305906f, 0.384801f, 0.449720f, + 0.047841f, 0.090004f, 0.137440f, 0.184176f, 0.226672f, 0.280565f, 0.332422f, 0.379775f, 0.414877f, 0.455906f, + 0.051208f, 0.095910f, 0.134766f, 0.179194f, 0.228900f, 0.267574f, 0.317929f, 0.370086f, 0.401118f, 0.446217f, + 0.057304f, 0.108307f, 0.167260f, 0.219044f, 0.253957f, 0.285245f, 0.321407f, 0.369771f, 0.413636f, 0.462874f, + 0.062714f, 0.102112f, 0.146902f, 0.188999f, 0.226385f, 0.267241f, 0.309584f, 0.346847f, 0.387502f, 0.451009f, + 0.045352f, 0.084823f, 0.120662f, 0.187181f, 0.252978f, 0.294385f, 0.328589f, 0.369623f, 0.440700f, 0.470814f, + 0.054539f, 0.107161f, 0.151423f, 0.184774f, 0.222621f, 0.270311f, 0.310645f, 0.379532f, 0.421532f, 0.464395f, + 0.041931f, 0.097165f, 0.176126f, 0.244078f, 0.285457f, 0.311564f, 0.343280f, 0.380534f, 0.427693f, 0.465345f, + 0.049656f, 0.089927f, 0.123487f, 0.158143f, 0.207460f, 0.251012f, 0.298147f, 0.386381f, 0.434882f, 0.470227f, + 0.064608f, 0.113031f, 0.152816f, 0.202317f, 0.244207f, 0.281442f, 0.321974f, 0.369506f, 0.411120f, 0.458796f, + 0.041667f, 0.088042f, 0.149426f, 0.187507f, 0.226638f, 0.278825f, 0.313814f, 0.388390f, 0.448889f, 0.473167f, + 0.063255f, 0.112633f, 0.161884f, 0.207517f, 0.248243f, 0.290171f, 0.339946f, 0.392358f, 0.424077f, 0.465045f, + 0.047738f, 0.124639f, 0.167770f, 0.198211f, 0.225569f, 0.260577f, 0.319448f, 0.357208f, 0.390762f, 0.448737f, + 0.056281f, 0.097031f, 0.133672f, 0.175612f, 0.249666f, 0.302816f, 0.358207f, 0.396586f, 0.431468f, 0.464859f, + 0.065840f, 0.114000f, 0.154376f, 0.181022f, 0.219481f, 0.272109f, 0.342283f, 0.390114f, 0.425579f, 0.463533f, + 0.054385f, 0.087287f, 0.133120f, 0.219075f, 0.277198f, 0.318550f, 0.353398f, 0.394571f, 0.451311f, 0.473024f, + 0.050377f, 0.099870f, 0.139986f, 0.179622f, 0.215723f, 0.254691f, 0.298673f, 0.344156f, 0.401375f, 0.451981f, + 0.047282f, 0.095779f, 0.154096f, 0.204588f, 0.238142f, 0.277769f, 0.328001f, 0.383819f, 0.421546f, 0.464335f, + 0.051096f, 0.097245f, 0.143694f, 0.189341f, 0.232614f, 0.275390f, 0.321690f, 0.370345f, 0.414317f, 0.459688f, + 0.057607f, 0.108697f, 0.166883f, 0.217010f, 0.265314f, 0.303576f, 0.339093f, 0.374926f, 0.429392f, 0.466921f, + 0.058130f, 0.096368f, 0.163828f, 0.194469f, 0.230519f, 0.266092f, 0.322506f, 0.379323f, 0.410417f, 0.440281f, + 0.059593f, 0.104108f, 0.143990f, 0.199751f, 0.246890f, 0.283738f, 0.342763f, 0.388274f, 0.417119f, 0.460115f, + 0.044521f, 0.105111f, 0.173587f, 0.207942f, 0.239336f, 0.273945f, 0.308799f, 0.369491f, 0.436878f, 0.469005f, + 0.074773f, 0.133154f, 0.177818f, 0.224283f, 0.264970f, 0.306138f, 0.340046f, 0.370218f, 0.412563f, 0.459546f, + 0.075738f, 0.111821f, 0.145360f, 0.181385f, 0.219465f, 0.256030f, 0.308392f, 0.373355f, 0.418157f, 0.463492f, + 0.056087f, 0.105731f, 0.160372f, 0.206032f, 0.244637f, 0.282396f, 0.334056f, 0.375992f, 0.420837f, 0.468046f, + 0.076209f, 0.108262f, 0.143499f, 0.182696f, 0.233318f, 0.271088f, 0.327756f, 0.373740f, 0.439247f, 0.474235f, + 0.052399f, 0.112281f, 0.162812f, 0.201017f, 0.261354f, 0.299326f, 0.327620f, 0.386801f, 0.447769f, 0.474791f, + 0.074893f, 0.121992f, 0.163699f, 0.207822f, 0.244930f, 0.271999f, 0.296466f, 0.345316f, 0.435127f, 0.476239f, + 0.058176f, 0.105085f, 0.149574f, 0.194188f, 0.249818f, 0.296524f, 0.337963f, 0.402402f, 0.448624f, 0.472243f, + 0.060779f, 0.099068f, 0.167491f, 0.198796f, 0.227494f, 0.254019f, 0.329803f, 0.403981f, 0.450520f, 0.475438f, + 0.052532f, 0.104934f, 0.160049f, 0.218916f, 0.277885f, 0.331831f, 0.371634f, 0.402258f, 0.429073f, 0.470420f, + 0.066857f, 0.108497f, 0.146533f, 0.186402f, 0.214087f, 0.239551f, 0.273028f, 0.339210f, 0.442001f, 0.475864f, + 0.058742f, 0.098634f, 0.140424f, 0.200627f, 0.237759f, 0.274315f, 0.336864f, 0.374803f, 0.415969f, 0.461915f, + 0.055406f, 0.096635f, 0.130990f, 0.174857f, 0.231572f, 0.277597f, 0.327848f, 0.376613f, 0.419923f, 0.465467f, + 0.063142f, 0.117506f, 0.165530f, 0.207973f, 0.252515f, 0.292023f, 0.332960f, 0.374855f, 0.422203f, 0.463402f, + 0.073810f, 0.115150f, 0.161374f, 0.201145f, 0.234138f, 0.271883f, 0.300056f, 0.334944f, 0.401703f, 0.457714f, + 0.037073f, 0.082702f, 0.150719f, 0.196430f, 0.266875f, 0.302676f, 0.341803f, 0.383090f, 0.434380f, 0.469480f, + 0.056987f, 0.107639f, 0.156686f, 0.198247f, 0.233643f, 0.272298f, 0.323545f, 0.383539f, 0.424062f, 0.466175f, + 0.068935f, 0.128609f, 0.175519f, 0.221849f, 0.262138f, 0.308833f, 0.354349f, 0.391305f, 0.431214f, 0.465646f, + 0.058327f, 0.099513f, 0.135693f, 0.173498f, 0.210477f, 0.259223f, 0.309074f, 0.365292f, 0.418318f, 0.460997f, + 0.053768f, 0.108301f, 0.148739f, 0.187783f, 0.248594f, 0.294002f, 0.326224f, 0.362744f, 0.418485f, 0.459503f, + 0.072347f, 0.113391f, 0.145826f, 0.186488f, 0.216571f, 0.246055f, 0.321765f, 0.384969f, 0.449111f, 0.479851f, + 0.068789f, 0.114708f, 0.171724f, 0.209662f, 0.240956f, 0.286235f, 0.354813f, 0.393328f, 0.420976f, 0.466079f, + 0.076792f, 0.122064f, 0.164111f, 0.196669f, 0.228773f, 0.263496f, 0.298068f, 0.369577f, 0.412072f, 0.446788f, + 0.072788f, 0.097673f, 0.130704f, 0.203771f, 0.250741f, 0.295679f, 0.355656f, 0.375931f, 0.431577f, 0.468953f, + 0.084680f, 0.123747f, 0.166460f, 0.199970f, 0.238683f, 0.271627f, 0.332322f, 0.389857f, 0.417976f, 0.454237f, + 0.047850f, 0.120236f, 0.163003f, 0.208247f, 0.285501f, 0.314491f, 0.348042f, 0.393049f, 0.436136f, 0.467946f, + 0.074354f, 0.116190f, 0.158181f, 0.188861f, 0.216650f, 0.247676f, 0.294654f, 0.344099f, 0.416305f, 0.461946f, + 0.053571f, 0.101937f, 0.148655f, 0.194776f, 0.237718f, 0.284302f, 0.333285f, 0.379409f, 0.424284f, 0.464382f, + 0.058960f, 0.099074f, 0.140467f, 0.196967f, 0.231626f, 0.264843f, 0.323752f, 0.385782f, 0.425341f, 0.465240f, + 0.043253f, 0.133255f, 0.191933f, 0.224667f, 0.269958f, 0.309788f, 0.340578f, 0.370291f, 0.414823f, 0.464356f, + 0.055527f, 0.103077f, 0.145933f, 0.195951f, 0.237681f, 0.276359f, 0.307310f, 0.343951f, 0.415470f, 0.466831f, + 0.056607f, 0.103731f, 0.150533f, 0.199143f, 0.247090f, 0.294661f, 0.337006f, 0.380695f, 0.436417f, 0.469044f, + 0.058017f, 0.111478f, 0.184738f, 0.222470f, 0.248826f, 0.274226f, 0.313164f, 0.396522f, 0.439606f, 0.469562f, + 0.059766f, 0.131086f, 0.177741f, 0.250119f, 0.292365f, 0.314884f, 0.343841f, 0.383029f, 0.418571f, 0.469165f, + 0.063549f, 0.123913f, 0.167854f, 0.196007f, 0.222730f, 0.248052f, 0.296431f, 0.381363f, 0.440747f, 0.474918f, + 0.057303f, 0.104523f, 0.145906f, 0.215521f, 0.258023f, 0.293742f, 0.329884f, 0.375696f, 0.425649f, 0.463893f, + 0.062113f, 0.113749f, 0.146593f, 0.190918f, 0.221197f, 0.281815f, 0.352860f, 0.400393f, 0.454168f, 0.477972f, + 0.065394f, 0.121516f, 0.199177f, 0.235275f, 0.266790f, 0.299190f, 0.343026f, 0.386286f, 0.439359f, 0.470243f, + 0.079123f, 0.135214f, 0.178870f, 0.220386f, 0.255756f, 0.285377f, 0.317392f, 0.361228f, 0.405450f, 0.467724f, + 0.056167f, 0.115899f, 0.166770f, 0.207524f, 0.241655f, 0.297597f, 0.366322f, 0.404801f, 0.440200f, 0.470576f, + 0.065840f, 0.126504f, 0.164612f, 0.196957f, 0.220935f, 0.267816f, 0.338526f, 0.391567f, 0.453372f, 0.479359f, + 0.044781f, 0.115425f, 0.177337f, 0.247881f, 0.284229f, 0.319088f, 0.355269f, 0.403159f, 0.444401f, 0.467850f +}; + +const float wac_swb[LPC_SHB_ORDER + 1] = +{ + 1.00030000f, 0.99972246f, 0.99889029f, 0.99750487f, + 0.99556853f, 0.99308446f, 0.99005679f, 0.98649053f, + 0.98239158f, 0.97776669f, 0.97262346f +}; + +const float lbr_wb_bwe_lsfvq_cbook_2bit[4*4] = {0.11829331f, 0.18065347f, 0.27315149f, 0.36268139f, + 0.20006990f, 0.24350365f, 0.33066865f, 0.40078221f, + 0.13430431f, 0.20694768f, 0.32580520f, 0.41176145f, + 0.25797083f, 0.29579351f, 0.36694117f, 0.42482337f + }; + +const float wac[LPC_SHB_ORDER + 1] = { 1.000030000f, 0.999876638f, + 0.999506642f, 0.998890286f, + 0.998028026f, 0.996920500f, + 0.995568526f, 0.993973102f, + 0.992135406f, 0.990056789f, + 0.987738783f + }; + +/* 5-bit TD SWB BWE temporal shaping codebook */ +const float SHBCB_SubGain5bit[128] = +{ + -0.1457681f, -0.4764620f, -0.4013963f, -0.3677013f, + -0.4313035f, -0.3313996f, -0.3050383f, -0.2133066f, + -1.0206577f, -0.9364462f, -0.0586007f, -0.4846374f, + -1.6047017f, -0.3614168f, -0.3000874f, -0.2672006f, + -0.0931186f, -0.4041055f, -0.5172903f, -0.5874190f, + -0.4911704f, -0.2494092f, -0.5456603f, -0.1857298f, + -0.2215641f, -0.3130259f, -0.3029806f, -0.4504822f, + -0.0164831f, -1.1390385f, -1.4790464f, -1.5514144f, + -0.5643114f, -0.4608741f, -0.3408080f, -0.1252954f, + -0.1276388f, -0.2821012f, -0.5614353f, -0.8928169f, + -0.2834879f, -0.1340739f, -0.6259241f, -0.5918277f, + -0.1487753f, -0.5728573f, -0.7163700f, -0.2789117f, + -0.8768165f, -0.6980218f, -0.5036601f, -0.0499640f, + -0.9883066f, -0.9968036f, -1.0402167f, -0.0137106f, + -0.3300310f, -0.5241924f, -0.4624851f, -0.1401303f, + -1.6058040f, -1.3385040f, -0.4591369f, -0.1534372f, + -0.1989556f, -0.2591312f, -0.4850197f, -0.4037134f, + -0.1111035f, -0.3369072f, -0.9321365f, -1.2062822f, + -0.2261946f, -0.2280687f, -0.3570638f, -0.6421078f, + -0.6153073f, -0.2471987f, -0.2481002f, -0.3052209f, + -0.2385272f, -0.6048125f, -0.1758713f, -0.5861754f, + -0.0317327f, -0.6809157f, -0.7702834f, -0.7792925f, + -0.2770282f, -0.3142404f, -0.3788958f, -0.2723185f, + -0.2970077f, -0.4682712f, -0.2584636f, -0.2690060f, + -0.5592654f, -0.8185204f, -0.1815633f, -0.2389702f, + -0.7487352f, -0.4618911f, -0.2345186f, -0.1725288f, + -0.4382800f, -0.2999320f, -0.1591911f, -0.5732270f, + -0.3830038f, -0.1750423f, -0.3638722f, -0.3974119f, + -0.7911282f, -0.0631017f, -0.5198654f, -0.6708761f, + -0.5033713f, -0.4643340f, -0.1527029f, -0.3067638f, + -0.3547296f, -0.3050630f, -0.2355810f, -0.3526833f, + -1.0319320f, -0.3646283f, -0.2706210f, -0.1999401f +}; + +/* 5-bit TD WB BWE temporal shaping codebook */ +const float HBCB_SubGain5bit[128] = +{ + -59.470337f, -69.488670f, -38.659931f, -19.719824f, + -1.7830310f, -4.812642f, -8.744000f, -10.867781f, + -13.246320f, -15.094897f, -15.727152f, -15.801854f, + -7.879738f, -5.120556f, -3.429671f, -7.706632f, + -50.144310f, -60.062901f, -32.317268f, -16.175051f, + -10.900867f, -11.864854f, -9.386131f, -1.335022f, + -13.235695f, -14.241489f, -13.557719f, -11.050961f, + -0.612834f, -7.908495f, -9.054081f, -8.763001f, + -57.235970f, -64.192162f, -30.073193f, -4.640105f, + -10.025522f, -6.857354f, -1.353238f, -6.571805f, + -8.077633f, -9.067668f, -9.157619f, -9.171074f, + -6.871120f, -4.052971f, -7.285939f, -7.970854f, + -44.516933f, -53.591618f, -30.267939f, -10.678650f, + -3.160364f, -7.559843f, -7.367127f, -3.052069f, + -8.343053f, -7.577167f, -3.678010f, -6.135194f, + -7.522539f, -9.290725f, -10.048427f, -8.378534f, + -68.482224f, -75.261124f, -30.160120f, -10.437404f, + -2.787138f, -2.637044f, -5.920231f, -8.091020f, + -7.519012f, -9.081453f, -9.857375f, -10.380337f, + -6.422596f, -6.540410f, -7.954427f, -7.877131f, + -49.924343f, -57.036163f, -26.225056f, -5.391133f, + -8.174749f, -6.656519f, -4.389360f, -2.953642f, + -10.844235f, -10.494500f, -8.072153f, -4.695106f, + -4.305107f, -2.655748f, -7.638941f, -9.281904f, + -56.389565f, -61.898930f, -19.212666f, -8.088096f, + -6.302619f, -2.904698f, -7.059662f, -5.392998f, + -2.423694f, -5.054863f, -7.913060f, -8.444733f, + -3.101384f, -6.855487f, -4.557333f, -6.881396f, + -45.418392f, -52.252014f, -22.952511f, -7.653957f, + -3.941019f, -7.339684f, -4.011926f, -7.481068f, + -6.772878f, -4.939885f, -7.817589f, -3.977276f, + -2.728315f, -6.770474f, -8.485444f, -4.669493f +}; + + +/* 6 bit Quantizer table for SHB overall gain */ +const float SHBCB_FrameGain64[64]= +{ + 0.044072020f, 0.074116257f, 0.104772820f, 0.137129910f, 0.172361440f, 0.209110170f, 0.248146360f, 0.290349910f, + 0.336033220f, 0.384576680f, 0.436074570f, 0.491054220f, 0.550217560f, 0.613450140f, 0.681455200f, 0.753997600f, + 0.831286250f, 0.914336560f, 1.003638100f, 1.100985500f, 1.205300400f, 1.317519300f, 1.437191800f, 1.566197500f, + 1.704663300f, 1.853099500f, 2.013720200f, 2.190476500f, 2.382512800f, 2.591447500f, 2.818724200f, 3.064693900f, + 3.331486000f, 3.621288500f, 3.936974000f, 4.279052900f, 4.652247100f, 5.063426700f, 5.516226500f, 6.014047700f, + 6.565030700f, 7.179005400f, 7.869640600f, 8.646445300f, 9.521977600f, 10.52553600f, 11.67516800f, 13.00652900f, + 14.56494800f, 16.38657700f, 18.56994600f, 21.17650800f, 24.29317200f, 27.95810000f, 32.33308400f, 37.72507700f, + 44.44091200f, 52.62181300f, 62.89529200f, 76.21739000f, 94.34608600f, 119.5521800f, 160.0594500f, 245.1366400f +}; + +/* 4 bit Quantizer table for SHB overall gain */ +const float SHBCB_FrameGain16[16]= +{ + 0.148650413f, + 0.477894376f, + 0.970739390f, + 1.882108080f, + 3.981442531f, + 7.946689290f, + 14.46817648f, + 24.39527659f, + 39.12384197f, + 60.03913602f, + 88.76762784f, + 130.1507349f, + 184.4881647f, + 271.3320980f, + 409.9269865f, + 735.8126500f +}; + +/* 18th order elliptic Bandpass filter at 14.15 to 20 kHz sampled at 48 kHz b0,b1,b2,a0,a1,a2 */ +const float full_band_bpf_1[6][5] = +{ + { 9.6362039055508E-02f, 9.7862105350605E-02f, 3.0245537519444E-02f, 9.7862105350605E-02f, 9.6362039055508E-02f}, + { 9.6362039055508E-02f, 1.4633143118038E-01f, 1.0233713813742E-01f, 1.4633143118038E-01f, 9.6362039055508E-02f}, + { 9.6362039055508E-02f, 1.6626923151583E-02f, -1.3709502682285E-01f, 1.6626923151583E-02f, 9.6362039055508E-02f}, + { 1.0000000000000E+00f, 2.3991100643722E+00f, 2.9774531499625E+00f, 2.0824517848412E+00f, 8.0090184246950E-01f}, + { 1.0000000000000E+00f, 1.8724727524876E+00f, 2.4558672940808E+00f, 1.6868952908597E+00f, 7.5556052044790E-01f}, + { 1.0000000000000E+00f, 2.5823882989829E+00f, 3.2419903202957E+00f, 2.1041782509434E+00f, 6.8348510539492E-01f} +}; + +/* 12th order elliptic Bandpass filter at 16.3 to 19.8 kHz sampled at 48 kHz b0,b1,b2,a0,a1,a2 */ +const float full_band_bpf_2[6][5] = +{ + { 6.0003889556380E-02f, 1.1128037231775E-01f, 1.1894140617207E-01f, 1.1128037231775E-01f, 6.0003889556380E-02f}, + { 6.0003889556380E-02f, 1.4172832594169E-01f, 1.6515046627146E-01f, 1.4172832594169E-01f, 6.0003889556380E-02f}, + { 6.0003889556380E-02f, 3.1639978682801E-02f, -3.7925280401819E-02f, 3.1639978682801E-02f, 6.0003889556380E-02f}, + { 1.0000000000000E+00f, 2.7969061159585E+00f, 3.7380107651703E+00f, 2.5896033662624E+00f, 8.7195105769838E-01f}, + { 1.0000000000000E+00f, 2.4858753840930E+00f, 3.3360972572945E+00f, 2.3002595115472E+00f, 8.4059566462167E-01f}, + { 1.0000000000000E+00f, 2.8681737877693E+00f, 3.8085295994769E+00f, 2.5421873471575E+00f, 7.9182537841461E-01f} +}; + +/* 12th order elliptic Bandpass filter at 15.4 to 20.0 kHz sampled at 48 kHz b0,b1,b2,a0,a1,a2 */ +const float full_band_bpf_3[6][5] = +{ + {7.4636437949154E-02f, 1.0834902081890E-01f, 8.7514468139390E-02f, 1.0834902081890E-01f, 7.4636437949154E-02f}, + {7.4636437949154E-02f, 1.4782752996297E-01f, 1.4824632166087E-01f, 1.4782752996297E-01f, 7.4636437949154E-02f}, + {7.4636437949154E-02f, 2.4020393588811E-02f, -8.1869063979759E-02f, 2.4020393588811E-02f, 7.4636437949154E-02f}, + {1.0000000000000E+00f, 2.6521893008573E+00f, 3.4460829518042E+00f, 2.3910633156124E+00f, 8.3876600358846E-01f}, + {1.0000000000000E+00f, 2.2507856816983E+00f, 2.9756720931932E+00f, 2.0502894449026E+00f, 8.0167514850932E-01f}, + {1.0000000000000E+00f, 2.7689100300130E+00f, 3.5940097427365E+00f, 2.3681560760262E+00f, 7.4233948915492E-01f} +}; + + +/* 4-bit/3-bit TD SWB BWE differential LSF scalar quantizer tables */ +const float lsf_q_cb_4b[16] = +{ + 0.01798018f, 0.02359377f, 0.02790103f, 0.03181538f, + 0.03579450f, 0.03974377f, 0.04364637f, 0.04754591f, + 0.05181858f, 0.05624165f, 0.06022101f, 0.06419064f, + 0.06889389f, 0.07539274f, 0.08504436f, 0.10014875f +}; + +const float lsf_q_cb_3b[8] = +{ + 0.02070812f, 0.02978384f, 0.03800822f, 0.04548685f, + 0.05307309f, 0.06137543f, 0.07216742f, 0.09013262f +}; + +const float *const lsf_q_cb[NUM_Q_LSF] = { lsf_q_cb_4b, lsf_q_cb_4b, lsf_q_cb_3b, lsf_q_cb_3b, lsf_q_cb_3b }; +const short lsf_q_cb_size[NUM_Q_LSF] = {16, 16, 8, 8, 8}; +const short lsf_q_num_bits[NUM_Q_LSF] = { 4, 4, 3, 3, 3 }; + +/* Tables for approximation of upper half of SWB LSFs */ +const float mirror_point_q_cb[MIRROR_POINT_Q_CB_SIZE] = { 0.01436178f, 0.02111641f, 0.02735687f, 0.03712105f }; + +const float lsf_grid[4][5] = +{ + { 0.15998503f, 0.31215086f, 0.47349756f, 0.66540429f, 0.84043882f }, + { 0.15614473f, 0.30697672f, 0.45619822f, 0.62493785f, 0.77798001f }, + { 0.14185823f, 0.26648724f, 0.39740108f, 0.55685745f, 0.74688616f }, + { 0.15416561f, 0.27238427f, 0.39376780f, 0.59287916f, 0.86613986f } +}; + +const float grid_smoothing[5] = { 0.2f, 0.35f, 0.5f, 0.75f, 0.8f }; + +const float allpass_poles_3_ov_2[9] = +{ + 0.072265625000000f, + 0.626983642578125f, + 0.934020996093750f, + 0.778808593750000f, + 0.219360351562500f, + 0.970703125000000f, + 0.872039794921875f, + 0.438964843750000f, + 0.990966796875000f +}; + +const float decimate_3_ov_2_lowpass_num[3] = +{ + 0.195271809895833f, + 0.390543619791667f, + 0.195271809895833f +}; + +const float decimate_3_ov_2_lowpass_den[3] = +{ + 1.0f, + 0.0f, + 0.171630859375f +}; + + +/*------------------------------------------------------------------------------* + * WB BWE tables + *------------------------------------------------------------------------------*/ + +const float F_2_5[64] = +{ + 1.1606680f, 0.6594560f, + -4.9874350f, -5.1700310f, + 10.230799f, -0.0125740f, + 10.605126f, 9.7910260f, + -0.3739880f, -0.6027910f, + 6.2753817f, 0.3307670f, + 9.4537100f, 8.8558020f, + 2.9320890f, 2.1643160f, + 3.1332030f, 2.9710870f, + 8.061906f, -0.5905290f, + 15.754963f, 5.0496380f, + 17.227070f, 18.329395f, + -2.4710190f, -3.1725330f, + -1.4136470f, -1.9457110f, + 15.147771f, 14.506490f, + 11.358370f, 11.714662f, + 9.4275510f, -0.1223030f, + 7.0970160f, -1.5805260f, + 12.498663f, 3.1614850f, + 10.349261f, 1.5185040f, + 5.3809850f, -1.7341900f, + 1.1224600f, -2.2397020f, + 12.362551f, 12.133788f, + 4.2788690f, -1.7729040f, + 6.1577130f, 5.4971410f, + 3.3243130f, -2.5710470f, + 19.097071f, 9.3576920f, + 7.6509204f, 7.4404626f, + -0.5055090f, -3.7073090f, + 18.584702f, 11.302494f, + 18.706564f, 18.308905f, + 23.010420f, 22.915377f +}; + +/*------------------------------------------------------------------------------* + * SWB BWE tables + *------------------------------------------------------------------------------*/ + +const short swb_bwe_trans_subband[SWB_FENV_TRANS+1] = {240, 316, 392, 476, 560}; +const short swb_bwe_trans_subband_width[SWB_FENV_TRANS] = {76, 76, 84, 84}; +const short swb_bwe_subband[SWB_FENV+1] = {240, 256, 280, 296, 320, 336, 360, 376, 400, 424, 448, 472, 496, 528, 560}; +const float swb_inv_bwe_subband_width[SWB_FENV] = {0.0625f, 0.04167f, 0.0625f, 0.04167f, 0.0625f, 0.04167f, 0.0625f, 0.04167f, 0.04167f, 0.04167f, 0.04167f, 0.04167f, 0.03125f, 0.03125f}; +const short swb_bwe_sm_subband[SWB_FENV] = {248, 268, 288, 308, 328, 348, 368, 388, 412, 436, 460, 484, 512, 544}; +const float smooth_factor[SWB_FENV-1] = {0.05f, 0.05f, 0.05f, 0.05f, 0.05f, 0.05f, 0.05f, 0.0417f, 0.0417f, 0.0417f, 0.0417f, 0.03125f, 0.03125f}; + +const short fb_bwe_subband[DIM_FB+1] = {640, 680, 720, 800}; +const float fb_inv_bwe_subband_width[DIM_FB] = {0.0250f, 0.0250f, 0.0125f}; +const short fb_bwe_sm_subband[DIM_FB] = {656, 696, 760}; +const float fb_smooth_factor[DIM_FB] = {0.03125f, 0.0250f, 0.015625f}; + +const float EnvCdbk11 [N_CB11 * DIM11] = +{ + -8.6703f, 0.1116f, 4.5639f, 8.2950f, 8.5148f, 4.7195f, 2.8963f, + 5.9419f, -1.2168f, -3.2933f, -5.9491f, -7.6969f, -8.6146f, -9.9275f, + 2.9127f, 7.1689f, 13.5188f, 17.1801f, 16.7640f, 16.3455f, 13.5231f, + 6.3569f, 9.6697f, 11.4712f, 11.0915f, 8.5859f, 6.7523f, 5.1755f, + -2.0082f, -2.8539f, -2.1756f, -0.7832f, 0.3904f, 1.8543f, 2.1094f, + 2.5602f, 3.7358f, 4.9688f, 4.2290f, 3.0234f, 2.6829f, 1.7943f, + 23.3857f, 21.3282f, 18.3157f, 16.3757f, 15.0204f, 14.1209f, 13.2521f, + 13.9500f, 18.9069f, 22.5926f, 24.4781f, 23.1748f, 20.1496f, 17.3157f, + 11.5571f, 8.1506f, 4.6099f, 3.8231f, 4.6089f, 5.3538f, 6.3890f, + 23.5508f, 24.0512f, 25.1225f, 26.4155f, 27.3361f, 27.9432f, 27.5377f, + -3.2117f, 0.8204f, 1.7588f, 0.6950f, -2.4959f, -5.2582f, -6.1620f, + 17.3871f, 16.3436f, 16.0602f, 16.9090f, 18.8782f, 20.4382f, 21.5310f, + 13.3594f, 15.6030f, 16.8792f, 16.4242f, 14.3912f, 12.3198f, 10.3571f, + -14.5849f, -9.0025f, -5.4218f, -1.2669f, 0.0853f, -3.3069f, -4.4553f, + 3.3195f, 1.9941f, 3.5010f, 6.9539f, 8.3192f, 10.5007f, 11.0406f, + 12.8683f, 11.0255f, 9.8051f, 9.8299f, 11.8326f, 13.3332f, 15.0119f, + -13.9167f, -13.3153f, -12.4970f, -11.3929f, -10.0932f, -8.9132f, -7.7378f, + -10.6935f, -12.4430f, -14.6553f, -16.8742f, -17.5158f, -17.6704f, -16.9116f, + -29.4308f, -29.2243f, -28.4494f, -28.0282f, -26.3950f, -24.5370f, -22.9103f, + -19.0168f, -18.8921f, -17.9786f, -17.2745f, -15.9625f, -14.5997f, -12.9787f, + -54.2808f, -53.8105f, -52.6712f, -52.1042f, -50.4929f, -48.4342f, -46.7588f, + 32.8477f, 32.8894f, 32.4420f, 31.6529f, 31.0708f, 30.3821f, 29.2828f, + 28.0454f, 26.7402f, 24.8801f, 23.3249f, 21.7053f, 20.7367f, 19.6371f, + 18.0979f, 15.6543f, 12.7634f, 9.4607f, 8.0952f, 6.9453f, 5.8996f, + 39.5644f, 40.7490f, 41.1718f, 40.9096f, 39.7482f, 38.4272f, 37.4463f, + 11.4554f, 10.5291f, 8.0459f, 5.0217f, 1.6581f, -0.9919f, -3.2238f, + -39.1890f, -38.4633f, -37.2799f, -36.7970f, -35.1580f, -33.2348f, -31.5786f, + 7.1490f, 3.6224f, -0.6163f, -1.5147f, -1.4079f, -1.4364f, -1.1211f, + -85.7873f, -85.5637f, -84.1707f, -83.8699f, -82.0486f, -80.1192f, -78.3737f, + -23.7889f, -23.9925f, -23.1930f, -22.8609f, -21.4574f, -19.9363f, -18.2458f, + -5.3981f, -6.4065f, -8.6148f, -9.9870f, -10.8787f, -11.7942f, -11.6944f, + -5.0767f, -6.1222f, -6.8130f, -6.4157f, -5.5037f, -4.2203f, -3.5243f, +}; + +const float EnvCdbk1st [N_CB1ST * DIM1ST] = +{ + -7.1064f, -4.4453f, 2.9351f, + -1.9308f, 0.6335f, -3.2258f, + -12.4978f, -0.4815f, 9.6818f, + -8.0902f, 0.9278f, -1.6759f, + -7.1051f, 6.9529f, 4.8166f, + 1.1089f, 4.6364f, -4.3871f, + -6.5985f, -2.8197f, -1.8909f, + -4.9078f, 0.2022f, -5.2175f, + -2.3609f, 14.6030f, -5.0669f, + 2.1685f, 1.6108f, 2.9025f, + -2.4455f, -6.5834f, 5.9636f, + 0.5645f, 6.0806f, -0.8753f, + -2.4904f, 5.3534f, 6.2069f, + -4.6416f, 0.1448f, -1.6019f, + -1.6724f, -12.9702f, 7.2641f, + 10.1438f, -0.3729f, -11.2325f, + -2.8994f, -2.2776f, -2.6711f, + 6.2755f, -6.5279f, -7.3185f, + -4.3406f, -3.6577f, -5.3655f, + 1.0746f, -9.0396f, 2.0233f, + 10.4764f, 9.2495f, -1.1811f, + 7.0665f, -2.1678f, -2.2621f, + 12.4715f, -4.9604f, -4.7190f, + 2.9306f, 0.3267f, 0.6027f, + -4.5326f, 1.6741f, 4.2905f, + 3.1882f, -2.3954f, -11.3147f, + 8.4338f, -7.3615f, 4.8623f, + -2.6210f, 1.6649f, 12.4120f, + 3.3880f, -0.5639f, -2.4950f, + 3.2948f, -7.3733f, 8.8713f, + 6.0225f, 1.0109f, -0.5767f, + -6.5622f, 4.0120f, 1.1130f, + 0.6314f, -2.9813f, 6.5088f, + -7.4838f, 4.5892f, -4.7926f, + -1.3492f, -3.5415f, -0.5914f, + 7.7312f, 4.1477f, 1.5695f, + -4.8092f, 9.5178f, 12.2277f, + -9.4609f, 1.4097f, 4.0613f, + -16.8501f, -16.0390f, -16.4874f, + 0.5711f, -4.6892f, -7.1391f, + 1.8938f, 3.4746f, -15.0275f, + 1.5014f, -9.6125f, -11.1128f, + 5.9617f, -2.3434f, 6.2473f, + -3.2715f, -2.2302f, 4.2871f, + 6.9371f, -13.2527f, 15.8528f, + -13.0084f, 9.4873f, 6.7652f, + 1.8265f, -8.3584f, -3.6477f, + 3.2532f, 8.9518f, -4.4112f, + -0.0785f, -4.0189f, 2.5487f, + -1.3509f, 0.6566f, 7.1658f, + -6.7577f, 3.2716f, 8.7273f, + 6.3343f, -6.6206f, -0.7569f, + -12.4925f, -3.0187f, 0.8888f, + 4.1806f, 6.8020f, 1.1128f, + 6.4660f, -0.8290f, -6.3590f, + 8.5089f, 2.3611f, 6.9696f, + 7.0355f, -12.5942f, -3.3116f, + -3.1974f, 1.3584f, 0.7314f, + 0.0624f, 1.1725f, 0.9528f, + 3.0031f, 0.7847f, 6.0715f, + 2.8083f, -1.5392f, 3.0486f, + 1.2144f, 11.1444f, 0.7234f, + 4.5417f, 1.9083f, -3.9930f, + -1.2897f, 1.7931f, 3.4268f, + 0.4267f, -2.1125f, -2.6993f, + -1.9870f, -1.0444f, 1.8659f, + -1.3273f, -1.6306f, -5.4788f, + -3.3603f, -2.6373f, -10.5580f, + 4.0034f, 3.2267f, 0.9765f, + -4.0725f, 3.9372f, -1.6940f, + -4.0711f, -2.4655f, 0.2350f, + -0.6742f, 1.2957f, -8.1420f, + 3.8434f, 3.5916f, -7.9753f, + -4.9118f, -8.9335f, 1.3240f, + 1.4296f, -5.1151f, -0.6183f, + 4.0664f, 4.0592f, 4.2287f, + 13.9299f, 3.5845f, 0.8860f, + 0.2439f, -0.5414f, 3.6573f, + 9.4697f, 2.8531f, -3.9907f, + -2.9106f, 7.6316f, 1.6666f, + -4.2611f, -5.3043f, -1.8686f, + -0.6757f, 8.2847f, -9.2447f, + -8.4955f, 9.9028f, -7.6020f, + -3.4387f, -7.6714f, -6.0496f, + -0.9730f, -4.6977f, -3.6204f, + -9.2868f, -1.7316f, -6.9325f, + -5.6205f, -2.2721f, 7.9555f, + -2.0678f, -14.3696f, -2.1494f, + 2.3769f, -1.1084f, -6.1183f, + 0.7835f, 0.2474f, -1.3438f, + 5.3736f, 0.8512f, 3.1856f, + 9.6507f, -1.3584f, 1.8708f, + -5.4226f, 3.8576f, -10.4452f, + 5.5806f, -13.8209f, 4.3938f, + 3.3739f, -5.2782f, 3.3015f, + 1.1772f, 3.8147f, 1.5955f, + -4.3838f, 13.1395f, 4.3243f, + -0.8337f, 2.8533f, -1.2842f, + 3.2788f, -2.6680f, -0.3603f, + 2.4648f, 4.5784f, 9.2339f, + 2.3348f, 2.6773f, -1.2865f, + -3.0488f, -5.1440f, 1.7493f, + -1.6552f, -0.5978f, -0.7764f, + 3.0011f, -1.2935f, 11.0366f, + 3.4439f, -4.0880f, -3.8069f, + -1.4637f, -7.1676f, -1.1671f, + 11.1758f, -13.1846f, -12.3361f, + 8.1990f, 8.4704f, -10.2721f, + 6.2564f, 7.5395f, 5.6662f, + 5.0554f, 4.9418f, -2.2877f, + -9.7668f, -10.0395f, -10.4193f, + -3.1503f, -5.9735f, 12.7823f, + -2.0408f, 4.1857f, 1.8667f, + 15.7600f, -9.7299f, 1.8762f, + -7.4519f, 9.4311f, -0.6946f, + -6.1047f, -0.5603f, 1.7096f, + 0.8003f, 3.3634f, 5.0259f, + -2.6989f, 3.7629f, -5.3679f, + -9.2139f, -7.9377f, -3.4621f, + 0.6323f, -1.7255f, 0.6234f, + 0.7594f, 9.7404f, 7.6543f, + -9.8933f, -10.0711f, 7.5139f, + 1.0426f, 6.6449f, 3.6587f, + 11.4042f, 11.5230f, 9.3039f, + -2.6163f, 8.2102f, -3.3574f, + -12.2920f, 5.4115f, -0.8387f, + 5.7900f, -2.3232f, 1.6209f, + 0.8904f, 1.1318f, -4.1407f, +}; + +const float EnvCdbk2nd [N_CB2ND * DIM2ND] = +{ + 4.3123f, -7.1616f, -4.3357f, -3.7263f, + 2.9572f, 3.3303f, -0.6874f, 1.1173f, + -3.4084f, -2.2922f, -0.0278f, 5.6960f, + -1.8039f, -2.1619f, -1.3655f, 0.4079f, + 7.5721f, 7.6436f, -5.2359f, -2.7457f, + 4.6943f, -3.0448f, 0.0822f, 7.7951f, + -11.1369f, -0.6607f, 4.0977f, 3.6717f, + -5.2941f, -2.8345f, -6.9855f, 4.2023f, + -2.9965f, -2.5020f, -2.5223f, -3.4361f, + 0.5260f, -3.2518f, -0.7710f, -3.4717f, + -3.2275f, 0.0098f, 1.0879f, -1.9621f, + -2.7904f, 2.1268f, -2.0540f, 1.4661f, + 1.1360f, -4.2031f, -3.1894f, -15.3458f, + -4.5909f, -1.8549f, 8.6689f, -2.5094f, + 0.7713f, -0.8552f, -4.1104f, -6.2533f, + 4.5892f, -0.6343f, -2.7162f, -1.3109f, + 4.3900f, 0.4919f, -9.0866f, -6.1448f, + 4.5483f, -5.1698f, -7.6465f, 4.1951f, + -8.1259f, -8.4044f, 0.4404f, 2.5339f, + -2.4877f, -3.3596f, 2.8155f, 1.0442f, + -2.3782f, 6.4752f, -3.9302f, -5.2807f, + 6.3692f, 8.6921f, 8.3109f, 7.1381f, + -4.3445f, -5.2789f, 7.2494f, 6.4679f, + -8.3291f, 3.9280f, 3.0088f, -5.0540f, + -1.8438f, 3.0318f, 6.4879f, 8.7826f, + -0.4718f, -2.2438f, -5.7862f, -1.2336f, + 10.0184f, -4.2246f, 0.7347f, 1.1461f, + 1.5549f, 10.1485f, 2.7490f, -4.4112f, + 3.9959f, 0.4078f, 2.1473f, 1.9496f, + -1.6255f, 0.4947f, 0.9865f, -7.3990f, + 1.7798f, -10.0697f, 0.7408f, 3.9759f, + -5.8117f, 1.1179f, -4.6947f, -3.5752f, + -4.5471f, 7.3211f, 6.4493f, 1.1780f, + -5.1254f, -6.0444f, -6.3492f, -5.9237f, + 0.6636f, -0.9113f, 3.1921f, 4.7217f, + -4.2586f, 1.3321f, 2.7703f, 2.8306f, + 3.3356f, 3.2010f, -1.0860f, -4.2324f, + -0.0572f, 0.4406f, 1.1161f, 1.1049f, + 4.5545f, -3.5389f, 7.3418f, 1.1747f, + 1.3350f, -0.0281f, -2.2930f, 3.0295f, + -3.0651f, -4.9167f, -4.5557f, 12.4767f, + -6.3679f, -4.1824f, 1.1715f, -4.2173f, + -0.0461f, 0.7412f, -2.1034f, -1.9263f, + 1.3714f, 3.5413f, 7.5363f, -5.9934f, + 1.8748f, 0.1406f, 2.3146f, -2.0562f, + 3.1775f, 4.7516f, 3.8512f, 0.3460f, + 0.3842f, 3.9440f, -8.8737f, 1.0470f, + 10.8029f, -0.3986f, -5.1051f, -3.4119f, + -6.4836f, -1.8259f, -1.4253f, 0.1826f, + 5.8438f, 4.9884f, -0.8889f, -10.9021f, + 6.1138f, -2.6130f, 2.0330f, -6.2434f, + -1.4101f, 4.2119f, 1.7856f, -1.4207f, + 2.1209f, -3.7111f, 0.1093f, 0.9671f, + 7.4373f, 3.1851f, -4.0372f, 4.3934f, + -0.0516f, -7.6212f, 4.2391f, -3.9245f, + -8.6836f, 5.9347f, -2.4382f, 3.3478f, + 4.3786f, 3.2445f, 3.4065f, 5.0603f, + 0.7547f, 8.9234f, -1.6469f, 2.3801f, + -0.6099f, 3.2294f, -2.8632f, 8.0661f, + -13.2408f, -13.2180f, -12.4864f, -12.5763f, + 0.1226f, 3.5019f, 2.1036f, 3.8209f, + -0.0830f, 1.5923f, 5.8683f, 1.5813f, + -2.2786f, -6.4905f, -2.5958f, -0.6420f, + 8.5661f, 3.8130f, 2.3928f, -1.7038f, +}; + +const float EnvCdbk3rd [N_CB3RD * DIM3RD] = +{ + 4.0282f, -9.5862f, 2.9221f, + 10.8219f, 9.5405f, 6.8798f, + -9.1733f, 15.9318f, -3.7461f, + 7.3196f, -2.8702f, -8.7570f, + -0.2304f, 0.1350f, 0.7863f, + -5.9316f, 0.6347f, 7.0661f, + -7.7220f, -4.1510f, -0.4015f, + 9.7056f, 4.7338f, -3.3708f, + 3.4447f, 0.7509f, 0.1539f, + 5.2980f, 3.3256f, 3.8228f, + -5.3770f, -11.5675f, -5.7681f, + 1.9411f, -3.1576f, 2.3162f, + -1.5410f, -2.9216f, -6.1087f, + -3.7107f, -0.7720f, -1.7048f, + -1.9664f, -5.5485f, -0.9158f, + 1.2430f, 3.8485f, -7.4409f, + -0.4624f, 6.9662f, 6.1050f, + 0.8584f, 3.6275f, 1.5624f, + 3.3487f, 0.1438f, -3.8870f, + -3.1533f, 7.5889f, -1.5958f, + -2.9036f, -2.0471f, 2.1555f, + 3.6715f, 6.4176f, -1.1670f, + 3.1461f, -5.5497f, -3.0001f, + -9.1009f, 2.7549f, 0.6103f, + 0.2373f, 0.7927f, 4.7365f, + -0.5389f, 2.0197f, -2.5074f, + 0.2485f, -1.9583f, -1.6996f, + 8.5694f, -2.4399f, 0.6128f, + -6.2513f, 1.3320f, -6.2922f, + 4.4430f, -1.3696f, 9.1921f, + -3.1673f, -6.6975f, 5.9466f, + -3.3971f, 2.3931f, 1.7433f, +}; + +const float EnvCdbk4th [N_CB4TH * DIM4TH] = +{ + 3.9996f, -0.8196f, -0.8101f, 2.3072f, + -1.0920f, -9.7095f, -3.7135f, 3.7429f, + 6.0104f, 4.4383f, 1.6047f, 5.1343f, + 6.8807f, -0.7893f, 5.2292f, 0.7940f, + -9.5225f, -8.2399f, -7.9213f, -8.3027f, + 7.2240f, -5.4987f, -2.6163f, 0.5630f, + -1.8336f, 10.4454f, -6.2079f, -14.0773f, + 6.4124f, -2.7411f, 0.5417f, 9.6735f, + -1.8885f, 1.4517f, -3.3639f, 2.1092f, + -0.4634f, 3.2291f, 3.3717f, 3.7183f, + 0.0901f, 0.3886f, -0.0922f, -1.1829f, + 1.9060f, -8.7228f, -5.5919f, -5.4642f, + 0.2125f, -0.1681f, 0.3767f, -5.9653f, + 4.5684f, 0.5205f, -0.4649f, -2.8002f, + 1.0087f, -4.7453f, -1.7135f, 0.6236f, + -4.0975f, 3.0989f, 3.7884f, -3.0078f, + -7.4785f, -4.8629f, 5.0050f, 1.6473f, + -4.6660f, 3.9258f, 0.6885f, -9.2509f, + -6.3693f, 5.1420f, -4.3946f, -1.4094f, + 4.3917f, 4.4225f, 0.2383f, -8.5391f, + 3.0850f, -8.0277f, 4.5875f, 3.6649f, + 11.6159f, 15.1327f, 9.0448f, 7.9694f, + -1.1705f, 9.7014f, 0.2305f, -3.3610f, + 2.1195f, 5.1060f, -7.2972f, -2.8333f, + 1.5208f, -0.4510f, -3.6906f, -0.5684f, + -7.1756f, -2.2582f, -2.4200f, 3.8082f, + 1.5182f, 6.9508f, 6.7654f, 1.1582f, + 1.4735f, 3.5020f, 6.0723f, 8.8626f, + -3.3340f, 0.1007f, 2.3028f, 5.5202f, + -3.0476f, -3.8494f, 5.4259f, 10.3093f, + 1.2195f, -1.0819f, -3.6514f, -12.8475f, + 6.7971f, 7.2347f, 2.5053f, -2.0263f, + 2.8809f, 3.5069f, -1.8220f, 0.4511f, + 4.6384f, -1.1164f, -5.9159f, -5.1137f, + 0.2896f, -3.1271f, -2.2772f, -3.8561f, + 1.9906f, -2.6068f, 1.6778f, -0.7475f, + 1.6325f, -1.1855f, 3.1499f, 4.9140f, + -4.2298f, -4.1599f, 1.4122f, -8.2593f, + -4.1992f, 0.3220f, 1.0148f, 1.1155f, + -10.0725f, 0.0539f, 0.2930f, -3.3347f, + -2.5810f, -2.4752f, 1.8829f, -2.2701f, + -1.3208f, -1.1970f, 12.7140f, 1.5150f, + -0.8982f, -0.0921f, 4.5338f, 0.8027f, + 1.0017f, 2.1335f, -0.5513f, 5.3882f, + -0.2457f, -3.0283f, -1.8919f, 5.7746f, + -2.0213f, -2.1347f, -1.7599f, 0.3340f, + 5.7553f, -4.6913f, 1.6804f, -7.3915f, + 1.5389f, 3.2468f, 2.4237f, -2.5921f, + 1.3040f, 0.2492f, 6.9277f, -6.1561f, + -6.9638f, 4.9625f, 3.9857f, 3.6889f, + 3.9950f, 0.3810f, -7.4544f, 5.1955f, + -2.1874f, -4.0774f, 1.4863f, 2.7600f, + -1.6673f, -2.7653f, -7.0891f, -0.3532f, + -0.2106f, 8.9759f, -2.0994f, 4.4973f, + -1.9481f, 2.7454f, -3.9753f, 12.9773f, + 0.3607f, 2.7997f, -2.3719f, -4.0297f, + -5.1272f, -5.4413f, -2.2644f, -1.8938f, + 0.1319f, -8.5628f, 3.0773f, -3.3584f, + 10.3160f, 2.4523f, -3.0328f, -1.0118f, + -2.7438f, -0.6207f, -5.7929f, -6.3978f, + -0.1295f, -0.2443f, 0.3800f, 2.1601f, + 2.7023f, 2.0427f, 2.1407f, 1.3633f, + -3.5645f, 0.2107f, -1.7811f, -2.7432f, + -1.3301f, 3.6876f, 0.6120f, 0.3900f, +}; + +const float EnvCdbkFB [N_CB_FB * DIM_FB] = +{ + -16.6120f, -9.7056f, -7.3815f, + 12.7223f, -5.3619f, -4.2098f, + 9.6082f, 17.5423f, 19.7838f, + 22.0461f, 24.1701f, 20.8503f, + -96.6904f, -89.9023f, -88.6123f, + 20.9213f, 27.6011f, 27.4229f, + 3.8206f, 7.0540f, 5.3791f, + 15.0749f, 22.8806f, 23.6351f, + 26.7480f, 32.6483f, 31.6408f, + -19.5344f, -13.3342f, -11.0528f, + -27.4315f, -20.0228f, -17.3748f, + -6.7548f, -7.7102f, -9.4666f, + -3.3129f, 6.9621f, 14.9937f, + 15.4388f, 19.6911f, 17.7925f, + 5.2569f, 13.0270f, 15.1931f, + 40.3814f, 47.0644f, 46.7397f, + -10.6760f, -3.9121f, -1.8455f, + -1.9827f, 5.3065f, 7.7240f, + -148.2341f, -141.3109f, -139.3314f, + -179.7394f, -172.2927f, -172.7284f, + 17.6754f, 17.9788f, -4.8806f, + -0.9671f, 3.3663f, 2.9027f, + 11.3567f, 15.3245f, 13.9899f, + 1.5588f, 8.5468f, 10.5230f, + -7.7918f, -0.8556f, 1.6643f, + -5.4487f, 2.0822f, 4.7052f, + -23.9540f, -16.9712f, -14.6548f, + -34.0472f, -27.2912f, -24.7197f, + -2.8087f, 0.4624f, -3.6887f, + -14.1611f, -7.1801f, -4.6916f, + 32.8420f, 38.8016f, 38.3823f, + 7.4425f, 11.3804f, 9.7292f +}; + +const float Mean_env_fb[DIM_FB] = {13.75f, 6.29f, 3.70f}; + +const float w_NOR[SWB_FENV] = {1.f,0.97826087f,0.957446809f,0.9375f,0.918367347f,0.9f,0.882352941f,0.865384615f,0.849056604f,0.833333333f,0.818181818f,0.803571429f,0.789473684f,0.775862069f}; +const float Mean_env[SWB_FENV] = {28.62f, 28.96f, 28.05f, 27.97f, 26.91f, 26.82f, 26.35f, 25.98f, 24.94f, 24.03f, 22.94f, 22.14f, 21.23f, 20.40f}; + +const float Env_TR_Cdbk1 [N_CB_TR1 * DIM_TR1] = +{ + 0.8936f, -9.1696f, + 32.0275f, 30.1795f, + -1.2201f, 6.6391f, + 38.5962f, 23.2366f, + 34.9278f, 32.6481f, + 15.0969f, 12.8381f, + 9.3963f, 3.1078f, + 14.3113f, 5.5971f, + 11.9502f, 8.6515f, + 2.4150f, 3.4154f, + -21.4020f, -18.1087f, + 8.7368f, 9.8116f, + 16.6597f, 9.4849f, + 25.7150f, 8.0681f, + 17.7652f, 25.6994f, + 44.2378f, 28.6702f, + 41.3199f, 36.1883f, + 33.1667f, 25.2245f, + -5.3921f, -9.7030f, + 13.1902f, 19.8007f, + 28.8781f, 20.0006f, + 18.7409f, 17.3426f, + 21.5070f, 29.7424f, + -13.1680f, -15.5559f, + 10.9594f, 11.5574f, + 8.7570f, 13.8680f, + 5.2123f, 11.9711f, + 8.0290f, -5.2743f, + 3.1843f, 21.5110f, + 19.2978f, 5.6924f, + -7.6163f, -4.0852f, + 2.5510f, -4.4247f, + 3.4072f, -14.1479f, + -6.8577f, 0.9589f, + 22.6250f, 21.6469f, + 15.9534f, 30.0623f, + 17.8474f, 20.3281f, + -3.1654f, -6.0729f, + 39.5602f, 40.5625f, + 44.3017f, 45.7556f, + 24.8628f, 19.5166f, + 33.7547f, 41.1213f, + 23.1020f, 13.1469f, + 17.6623f, 12.7562f, + 20.3773f, 11.0551f, + 31.6668f, 35.0770f, + 15.4383f, 22.8811f, + 22.8419f, 35.1167f, + 25.0950f, 23.1698f, + 20.2523f, 14.9332f, + 24.8694f, 27.0211f, + 13.8576f, 10.4789f, + 6.3835f, 8.1955f, + 10.6597f, -0.3484f, + 27.2026f, 29.9373f, + 12.4182f, 13.9096f, + 24.9543f, 16.3771f, + 15.7197f, 18.8608f, + -1.4782f, 1.6952f, + 36.4783f, 37.1348f, + 29.6594f, 13.6072f, + -26.6995f, -24.6742f, + 20.3405f, 19.6463f, + 44.2412f, 40.9698f, + 28.9498f, 23.7751f, + 39.3428f, 32.2458f, + -23.8252f, -22.0790f, + 27.6318f, 33.9910f, + -47.7664f, -44.4696f, + -44.8104f, -41.2774f, + -50.8776f, -47.8616f, + -50.3099f, -44.0979f, + -54.5008f, -51.0234f, + -63.3373f, -60.1146f, + -45.5444f, -42.1435f, + -48.2447f, -44.8312f, + -49.9558f, -46.6690f, + -59.1385f, -55.6583f, + -44.2409f, -43.8251f, + -46.6791f, -43.3332f, + -46.0956f, -42.6861f, + -92.7279f, -89.3799f, + 49.9817f, 46.4450f, + -14.8152f, -11.2475f, + -106.9255f, -103.4843f, + -46.5934f, -45.0424f, + -47.3033f, -43.9775f, + -80.0456f, -76.6952f, + -56.1359f, -53.1578f, + -49.1835f, -45.8131f, + -54.9042f, -45.8573f, + 36.9949f, 28.4050f, + -43.6866f, -40.3702f, + -52.0047f, -45.5982f, + -47.6930f, -41.4457f, + -52.5989f, -49.8475f, + 30.0399f, 27.7911f, + 10.0141f, 17.5614f, + 21.8223f, 17.7785f, + -3.1767f, -2.1954f, + -17.5132f, -21.5664f, + 6.0779f, 0.3815f, + 0.0063f, 13.5452f, + 5.5074f, 5.2318f, + 15.8166f, 0.6300f, + -17.7247f, -15.7262f, + -38.5381f, -35.6042f, + -6.3132f, -18.4667f, + 9.5978f, 6.4559f, + 2.4632f, 8.4172f, + -70.2432f, -66.7283f, + 10.2658f, 23.7825f, + -42.1539f, -38.8022f, + -48.5397f, -45.1815f, + 16.8840f, 15.6262f, + -6.1500f, 8.4442f, + -31.1246f, -29.6824f, + 5.9496f, 16.3765f, + 21.9557f, 25.5364f, + -9.8102f, -7.7609f, + 48.7145f, 36.0093f, + 34.1627f, 19.4172f, + 14.2249f, 16.2026f, + 19.8782f, 23.2358f, + 1.3653f, -0.3587f, + 27.4538f, 26.1047f, + -9.4912f, -12.5633f, + -15.5232f, -3.4597f +}; + +const float Env_TR_Cdbk2 [N_CB_TR2 * DIM_TR2] = +{ + 10.3071f, 1.4647f, + -1.8782f, 6.6168f, + -9.3764f, -12.9146f, + 0.3372f, -15.6956f, + -5.0830f, 0.1825f, + 2.8660f, 1.1668f, + 3.7385f, -4.0567f, + 8.6094f, 5.8040f, + 1.4099f, -4.4378f, + 10.2655f, -3.2743f, + -7.8499f, 5.0612f, + 1.4560f, 0.4976f, + -2.2400f, 10.1737f, + 2.6910f, -6.0696f, + 6.5484f, -1.4502f, + 5.0708f, 1.0902f, + -3.5214f, 4.2403f, + 6.8248f, -10.6363f, + 0.8362f, -2.5676f, + -2.8563f, -3.5507f, + 6.0370f, -6.4758f, + -1.4405f, -8.6255f, + -4.9844f, 6.8277f, + 4.4568f, -2.0374f, + 0.7265f, -7.3953f, + -4.9226f, -7.8758f, + -1.8669f, -1.9698f, + 5.0262f, 7.3509f, + -0.3770f, -5.4681f, + -5.3582f, -4.5491f, + 3.1235f, -0.5936f, + 1.6121f, -0.9381f, + -0.8137f, -3.3498f, + -0.3523f, -1.5590f, + 1.9211f, 9.8411f, + 3.5654f, 5.3423f, + -1.3437f, 1.1031f, + 1.1914f, 2.0560f, + -0.9800f, 3.3605f, + -4.1634f, 2.2153f, + -10.9385f, -2.6849f, + 0.0040f, 2.6311f, + 0.6873f, 3.4294f, + -2.7967f, -0.5984f, + 2.7559f, 3.2450f, + -4.2294f, -1.6565f, + 1.6359f, 4.6566f, + -0.5137f, 2.2080f, + 2.7641f, -9.3968f, + 2.3449f, -2.5829f, + 6.6876f, 11.5962f, + -7.7096f, 1.4816f, + -2.6264f, 0.8111f, + 0.1002f, 1.1574f, + -7.1116f, -1.9581f, + -2.0027f, 2.4814f, + 1.0402f, 6.7866f, + -0.8642f, 4.8143f, + -13.6639f, 6.3768f, + -1.3155f, -0.2595f, + -2.1558f, -5.5755f, + 5.1910f, 3.3215f, + -2.8061f, -11.5155f, + -0.0134f, 0.0015f +}; + +const float Mean_env_tr[5] = { 27.23f, 23.81f, 23.87f, 19.51f }; + +/*------------------------------------------------------------------------------* + * LR MDCT SWB BWE coding tables + *------------------------------------------------------------------------------*/ + +const float gain_table_SWB_BWE[NB_SWB_SUBBANDS] = {-0.4f, 0.1f, 0.6f, 1.1f}; + +const short bits_lagIndices_modeNormal[NB_SWB_SUBBANDS] = {2, 2, 1, 1}; +const short subband_offsets_12KBPS[NB_SWB_SUBBANDS] = {SWB_SB_OFF0_12KBPS, SWB_SB_OFF1_12KBPS, SWB_SB_OFF2_12KBPS, SWB_SB_OFF3_12KBPS}; +const short subband_offsets_16KBPS[NB_SWB_SUBBANDS] = {SWB_SB_OFF0_16KBPS, SWB_SB_OFF1_16KBPS, SWB_SB_OFF2_16KBPS, SWB_SB_OFF3_16KBPS}; + +/* Search offset for the subbands that use a partial search */ +const short subband_search_offsets[NB_SWB_SUBBANDS] = +{ + 0, 0, 64, 64 +}; +/* SPT : shorten subband length table */ +const Word16 bw_SPT_tbl[2][SPT_SHORTEN_SBNUM]= +{ + {15, 31, 31, 31}, /* 13.2kbps: original band_width 53, 66, 82, 102 */ + {15, 15, 31, 31} /* 16.4kbps: original band_width 51 64, 80, 90 */ +}; + + +/* Harmonic Mode */ +const short bits_lagIndices_mode0_Har[NB_SWB_SUBBANDS_HAR_SEARCH_SB] = {1,1}; + +/* 13.2 kbps */ +const short subband_offsets_sub5_13p2kbps_Har[NB_SWB_SUBBANDS_HAR] = +{ + SWB_SB_OFF0_SUB5_12KBPS_HAR, SWB_SB_OFF1_SUB5_12KBPS_HAR, SWB_SB_OFF2_SUB5_12KBPS_HAR, SWB_SB_OFF3_SUB5_12KBPS_HAR +}; + +/* Search offset for the subbands that use a partial search */ +const short subband_search_offsets_13p2kbps_Har[NB_SWB_SUBBANDS_HAR_SEARCH_SB] = +{ + 120, 210 +}; + +/* 16.4 kbps */ +const short subband_offsets_sub5_16p4kbps_Har[NB_SWB_SUBBANDS_HAR] = +{ + SWB_SB_OFF0_SUB5_16KBPS_HAR, SWB_SB_OFF1_SUB5_16KBPS_HAR, SWB_SB_OFF2_SUB5_16KBPS_HAR, SWB_SB_OFF3_SUB5_16KBPS_HAR +}; + +/* Search offset for the subbands that use a partial search */ +const short subband_search_offsets_16p4kbps_Har[NB_SWB_SUBBANDS_HAR_SEARCH_SB] = +{ + 120, 210 +}; + + +/*------------------------------------------------------------------------------* + * HQ core tables + *------------------------------------------------------------------------------*/ + +const float wscw16q15[] = +{ + -1.0f, -0.999939f, -0.999878f, -0.999725f, -0.999573f, -0.999359f, -0.999084f, -0.99881f, + -0.998444f, -0.998077f, -0.99765f, -0.997162f, -0.996643f, -0.996094f, -0.995514f, -0.994873f, + -0.994171f, -0.993439f, -0.992676f, -0.991852f, -0.990997f, -0.990112f, -0.989166f, -0.98819f, + -0.987183f, -0.986115f, -0.984985f, -0.983856f, -0.982666f, -0.981415f, -0.980133f, -0.978821f, + -0.977448f, -0.976074f, -0.974609f, -0.973114f, -0.971588f, -0.970032f, -0.968414f, -0.966766f, + -0.965088f, -0.963348f, -0.961548f, -0.959747f, -0.957886f, -0.955994f, -0.954041f, -0.952057f, + -0.950043f, -0.947968f, -0.945862f, -0.943726f, -0.941559f, -0.939331f, -0.937042f, -0.934753f, + -0.932404f, -0.930023f, -0.927582f, -0.92514f, -0.922607f, -0.920074f, -0.91748f, -0.914886f, + -0.912201f, -0.909515f, -0.906769f, -0.903992f, -0.901184f, -0.898315f, -0.895416f, -0.892487f, + -0.889526f, -0.886505f, -0.883453f, -0.880371f, -0.877258f, -0.874084f, -0.87088f, -0.867645f, + -0.86438f, -0.861084f, -0.857727f, -0.85434f, -0.850922f, -0.847473f, -0.843964f, -0.840454f, + -0.836884f, -0.833282f, -0.829651f, -0.825989f, -0.822266f, -0.818512f, -0.814758f, -0.810944f, + -0.807098f, -0.803223f, -0.799286f, -0.795349f, -0.791351f, -0.787354f, -0.783295f, -0.779205f, + -0.775085f, -0.770935f, -0.766754f, -0.762512f, -0.75827f, -0.753998f, -0.749664f, -0.745331f, + -0.740936f, -0.736542f, -0.732086f, -0.727631f, -0.723114f, -0.718567f, -0.71402f, -0.709412f, + 0.704803f, 0.700134f, 0.695435f, 0.690735f, 0.685974f, 0.681213f, 0.676392f, 0.67157f, + 0.666687f, 0.661804f, 0.656891f, 0.651947f, 0.646942f, 0.641937f, 0.636932f, 0.631866f, + 0.62677f, 0.621674f, 0.616516f, 0.611359f, 0.606171f, 0.600952f, 0.595703f, 0.590424f, + 0.585144f, 0.579803f, 0.574463f, 0.569092f, 0.563721f, 0.558289f, 0.552856f, 0.547394f, + 0.541901f, 0.536377f, 0.530853f, 0.525299f, 0.519714f, 0.514099f, 0.508484f, 0.502838f, + 0.497162f, 0.491486f, 0.485748f, 0.480042f, 0.474274f, 0.468506f, 0.462708f, 0.456909f, + 0.45108f, 0.445221f, 0.439362f, 0.433472f, 0.427551f, 0.421631f, 0.41568f, 0.409729f, + 0.403748f, 0.397736f, 0.391724f, 0.385712f, 0.379669f, 0.373596f, 0.367523f, 0.36142f, + 0.355316f, 0.349182f, 0.343048f, 0.336884f, 0.330719f, 0.324524f, 0.318329f, 0.312134f, + 0.305908f, 0.299652f, 0.293427f, 0.28714f, 0.280884f, 0.274597f, 0.26828f, 0.261993f, + 0.255646f, 0.249329f, 0.242981f, 0.236633f, 0.230255f, 0.223877f, 0.217499f, 0.211121f, + 0.204712f, 0.198303f, 0.191895f, 0.185455f, 0.179016f, 0.172577f, 0.166138f, 0.159668f, + 0.153198f, 0.146729f, 0.140259f, 0.133759f, 0.127289f, 0.120789f, 0.114288f, 0.107788f, + 0.101288f, 0.0947571f, 0.0882568f, 0.0817261f, 0.0751953f, 0.0686646f, 0.0621338f, 0.055603f, + 0.0490723f, 0.0425415f, 0.0359802f, 0.0294495f, 0.0229187f, 0.0163574f, 0.00982666f,0.00326538f +}; + +const float wscw16q15_32[160] = +{ + -0.99998795f, -0.99989157f, -0.99969882f, -0.99940971f, -0.99902428f, -0.99854256f, + -0.99796460f, -0.99729046f, -0.99652019f,-0.99565388f, -0.99469160f, -0.99363345f, + -0.99247953f, -0.99122996f, -0.98988485f, -0.98844433f, -0.98690855f, -0.98527764f, + -0.98355177f, -0.98173111f, -0.97981582f, -0.97780610f, -0.97570213f, -0.97350412f, + -0.97121229f, -0.96882685f, -0.96634802f, -0.96377607f, -0.96111122f, -0.95835373f, + -0.95550388f, -0.95256194f, -0.94952818f, -0.94640291f, -0.94318642f, -0.93987902f, + -0.93648104f, -0.93299280f, -0.92941463f, -0.92574689f, -0.92198992f, -0.91814408f, + -0.91420976f, -0.91018732f, -0.90607715f, -0.90187965f, -0.89759523f, -0.89322430f, + -0.88876728f, -0.88422459f, -0.87959669f, -0.87488400f, -0.87008699f, -0.86520612f, + -0.86024186f, -0.85519469f, -0.85006509f, -0.84485357f, -0.83956061f, -0.83418673f, + -0.82873246f, -0.82319831f, -0.81758481f, -0.81189252f, -0.80612197f, -0.80027373f, + -0.79434836f, -0.78834643f, -0.78226851f, -0.77611520f, -0.76988708f, -0.76358476f, + -0.75720885f, -0.75075995f, -0.74423869f, -0.73764570f, -0.73098162f, -0.72424708f, + -0.71744274f, -0.71056925f, 0.70362727f, 0.69661748f, 0.68954054f, 0.68239715f, + 0.67518798f, 0.66791374f, 0.66057513f, 0.65317284f, 0.64570760f, 0.63818013f, + 0.63059115f, 0.62294139f, 0.61523159f, 0.60746249f, 0.59963485f, 0.59174941f, + 0.58380693f, 0.57580819f, 0.56775395f, 0.55964499f, 0.55148209f, 0.54326604f, + 0.53499762f, 0.52667764f, 0.51830690f, 0.50988620f, 0.50141636f, 0.49289819f, + 0.48433252f, 0.47572016f, 0.46706195f, 0.45835873f, 0.44961133f, 0.44082059f, + 0.43198737f, 0.42311251f, 0.41419687f, 0.40524131f, 0.39624670f, 0.38721389f, + 0.37814376f, 0.36903718f, 0.35989504f, 0.35071820f, 0.34150757f, 0.33226402f, + 0.32298845f, 0.31368174f, 0.30434480f, 0.29497853f, 0.28558383f, 0.27616160f, + 0.26671276f, 0.25723821f, 0.24773886f, 0.23821564f, 0.22866946f, 0.21910124f, + 0.20951190f, 0.19990237f, 0.19027357f, 0.18062644f, 0.17096189f, 0.16128086f, + 0.15158430f, 0.14187312f, 0.13214826f, 0.12241068f, 0.11266129f, 0.10290104f, + 0.09313088f, 0.08335174f, 0.07356456f, 0.06377030f, 0.05396989f, 0.04416428f, + 0.03435441f, 0.02454123f, 0.01472568f, 0.00490872f +}; + +const float wscw16q15_16[80] = +{ + -0.99995181f, -0.99956631f, -0.99879546f, -0.99763955f, + -0.99609903f, -0.99417450f, -0.99186670f, -0.98917651f, + -0.98610498f, -0.98265328f, -0.97882275f, -0.97461487f, + -0.97003125f, -0.96507367f, -0.95974404f, -0.95404440f, + -0.94797697f, -0.94154407f, -0.93474818f, -0.92759194f, + -0.92007808f, -0.91220953f, -0.90398929f, -0.89542056f, + -0.88650662f, -0.87725091f, -0.86765701f, -0.85772861f, + -0.84746954f, -0.83688375f, -0.82597533f, -0.81474848f, + -0.80320753f, -0.79135693f, -0.77920124f, -0.76674516f, + -0.75399348f, -0.74095113f, -0.72762312f, -0.71401460f, + 0.70013081f, 0.68597711f, 0.67155895f, 0.65688190f, + 0.64195160f, 0.62677382f, 0.61135441f, 0.59569930f, + 0.57981455f, 0.56370626f, 0.54738066f, 0.53084403f, + 0.51410274f, 0.49716327f, 0.48003212f, 0.46271592f, + 0.44522133f, 0.42755509f, 0.40972403f, 0.39173501f, + 0.37359497f, 0.35531090f, 0.33688985f, 0.31833893f, + 0.29966528f, 0.28087610f, 0.26197864f, 0.24298018f, + 0.22388805f, 0.20470960f, 0.18545224f, 0.16612338f, + 0.14673047f, 0.12728100f, 0.10778246f, 0.08824237f, + 0.06866826f, 0.04906767f, 0.02944817f, 0.00981732f +}; + +const float wscw16q15_8[40] = +{ + -0.999816894531250f, -0.998260498046875f, -0.995178222656250f, -0.990570068359375f, + -0.984436035156250f, -0.976776123046875f, -0.967590332031250f, -0.956939697265625f, + -0.944793701171875f, -0.931213378906250f, -0.916198730468750f, -0.899749755859375f, + -0.881927490234375f, -0.862731933593750f, -0.842224121093750f, -0.820404052734375f, + -0.797332763671875f, -0.773010253906250f, -0.747497558593750f, -0.720855712890625f, + 0.693084716796875f, 0.664245605468750f, 0.634399414062500f, 0.603546142578125f, + 0.571777343750000f, 0.539123535156250f, 0.505645751953125f, 0.471405029296875f, + 0.436401367187500f, 0.400756835937500f, 0.364471435546875f, 0.327636718750000f, + 0.290283203125000f, 0.252502441406250f, 0.214294433593750f, 0.175781250000000f, + 0.137023925781250f, 0.098022460937500f, 0.058868408203125f, 0.019622802734375f, +}; + +/* Codebook for quantization of norms */ +const float dicn[40] = +{ + 131072.0f, 92681.900024f, + 65536.0f, 46340.950012f, + 32768.0f, 23170.475006f, + 16384.0f, 11585.237503f, + 8192.0f, 5792.618751f, + 4096.0f, 2896.309376f, + 2048.0f, 1448.154688f, + 1024.0f, 724.077344f, + 512.0f, 362.038672f, + 256.0f, 181.019336f, + 128.0f, 90.509668f, + 64.0f, 45.254834f, + 32.0f, 22.627417f, + 16.0f, 11.313708f, + 8.0f, 5.656854f, + 4.0f, 2.828427f, + 2.0f, 1.414214f, + 1.0f, 0.707107f, + 0.5f, 0.353553f, + 0.25f, 0.176777f +}; + +const float dicn_inv[40]= /* Inversion of the codebook for quantization of norms */ +{ + 0.00000762939453f, 0.00001078959322f, + 0.00001525878906f, 0.00002157918644f, + 0.00003051757813f, 0.00004315837288f, + 0.00006103515625f, 0.00008631674575f, + 0.0001220703125f, 0.00017263349151f, + 0.000244140625f, 0.00034526698297f, + 0.00048828125f, 0.00069053396594f, + 0.0009765625f, 0.00138106793188f, + 0.001953125f, 0.00276213586376f, + 0.00390625f, 0.00552427172752f, + 0.0078125f, 0.01104854345505f, + 0.015625f, 0.02209708691010f, + 0.03125f, 0.04419417382019f, + 0.0625f, 0.08838835154664f, + 0.125f, 0.17677670309327f, + 0.25f, 0.35355340618655f, + 0.5f, 0.70710656237316f, + 1.0f, 1.41421312474633f, + 2.0f, 2.82843024949583f, + 4.0f, 5.65684449900157f +}; + +/* Codebook for quantization of peak gain */ +const float dicn_pg[45] = +{ + 131072.0000000f, 110217.9749401f, + 92681.9000237f, 77935.8774888f, + 65536.0000000f, 55108.9874701f, + 46340.9500118f, 38967.9387444f, + 32768.0000000f, 27554.4937350f, + 23170.4750059f, 16384.0000000f, + 11585.2375030f, 8192.0000000f, + 5792.6187515f, 4096.0000000f, + 2896.3093757f, 2048.0000000f, + 1448.1546879f, 1024.0000000f, + 724.0773439f, 512.0000000f, + 362.0386720f, 256.0000000f, + 181.0193360f, 128.0000000f, + 90.5096680f, 64.0000000f, + 45.2548340f, 32.0000000f, + 22.6274170f, 16.0000000f, + 11.3137085f, 8.0000000f, + 5.6568542f, 4.0000000f, + 2.8284271f, 2.0000000f, + 1.4142136f, 1.0000000f, + 0.7071070f, 0.5000000f, + 0.3535530f, 0.2500000f, + 0.176777f +}; + +const short expPkEnrg_tbl[45] = +{ + 0, 0, 0, 0, 0, 2, 2, 2, 2, + 4, 4, 4, 6, 6, 8, 8, 10, 10, + 12, 12, 14, 14, 16, 16, 18, 18, 20, + 20, 22, 22, 24, 24, 26, 26, 28, 28, + 30, 30, 32, 32, 34, 34, 36, 36, 38 +}; + +const int manPkEnrg_tbl[45] = +{ + 2147483646, 1518500308, 1073741787, 759250076, 536870912, + 1518500294, 1073741787, 759250076, 536870912, 1518500294, + 1073741787, 536870912, 1073741787, 536870912, 1073741787, + 536870912, 1073741787, 536870912, 1073741606, 536870912, + 1073741968, 536870912, 1073741244, 536870912, 1073741244, + 536870912, 1073744140, 536870912, 1073744140, 536870912, + 1073744140, 536870912, 1073744140, 536870912, 1073697800, + 536870912, 1073697800, 536870912, 1073883168, 536870912, + 1073512448, 536870912, 1073512448, 536870912, 1073512448 +}; +const int E_max5_tbl[40] = +{ + 2047999999, 1448154663, 1024000000, 1448154663, 1024000000, + 1448154663, 1024000000, 1448154663, 1024000000, 1448154663, + 1024000000, 1448154663, 1024000000, 1448154663, 1024000000, + 1448154663, 1024000000, 1448154785, 1024000000, 1448154785, + 1024000000, 1448154296, 1024000000, 1448154296, 1024000000, + 1448156250, 1024000000, 1448156250, 1024000000, 1448156250, + 1024000000, 1448156250, 1024000000, 1448125000, 1024000000, + 1448125000, 1024000000, 1448250000, 1024000000, 1448000000 +}; + + +const short resize_huffsizn[32] = +{ + 0, 0, 0, 0, 0, 11, 10, 10, 9, 8, 7, 6, 5, 4, 3, 2, + 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 0, 0, 0, 0, 0, 0 +}; + +const short huffsizn[32] = +{ + 7, 7, 7, 7, 7, 7, 7, 7, 6, 6, 6, 6, 4, 4, 3, 3, + 3, 3, 4, 4, 6, 6, 6, 6, 7, 7, 7, 7, 7, 7, 7, 7 +}; + +const short huffnorm_tran[32] = +{ + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,122, 10, 6, 1, + 0, 3, 2, 26, 58, 186, 442, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 +}; + +const short huffsizn_tran[32] = +{ + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 5, 3, 2, 2, + 2, 4, 6, 8, 9, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 +}; + +const short pgain_huffsizn[32] = +{ + 10, 11, 10, 10, 9, 8, 6, 5, 5, 4, 4, 4, 4, 4, 4, 4, + 4, 4, 4, 4, 4, 4, 5, 5, 6, 7, 7, 8, 10, 10, 12, 12 +}; + +const short dicnlg2[40] = +{ + 34, 33, 32, 31, 30, 29, 28, 27, 26, 25, + 24, 23, 22, 21, 20, 19, 18, 17, 16, 15, + 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, + 4, 3, 2, 1, 0, -1, -2, -3, -4, -5 +}; + +/*** Table for quantization of MLT coefficients ***/ +const short norm_order_48[NB_SFM] = +{ + 0, 1, 8, 9, 16, 20, 24, 28, 32, 36, 40, 41, 37, 33, 29, 25, 21, 17, 11, 10, 3, 2, + 4, 5, 12, 13, 18, 22, 26, 30, 34, 38, 42, 43, 39, 35, 31, 27, 23, 19, 15, 14, 7, 6 +}; + +const short norm_order_32[SFM_N_SWB] = +{ + 0, 1, 8, 9, 16, 20, 24, 28, 32, 36, 37, 33, 29, 25, 21, 17, 11, 10, 3, 2, + 4, 5, 12, 13, 18, 22, 26, 30, 34, 38, 35, 31, 27, 23, 19, 15, 14, 7, 6 +}; + +const short norm_order_16[SFM_N_WB] = +{ + 0, 1, 8, 9, 16, 20, 24, 21, 17, 11, 10, 3, 2, + 4, 5, 12, 13, 18, 22, 25, 23, 19, 15, 14, 7, 6 +}; + +const short intl_bw_16[N_INTL_GRP_16] = {16, 16}; +const short intl_bw_32[N_INTL_GRP_32] = {16, 24}; +const short intl_bw_48[N_INTL_GRP_48] = {16, 24, 32}; + +const short intl_cnt_16[N_INTL_GRP_16] = {4, 1}; +const short intl_cnt_32[N_INTL_GRP_32] = {4, 4}; +const short intl_cnt_48[N_INTL_GRP_48] = {4, 3, 2}; + +const short band_start_HQ[44] = +{ + 0, 8, 16, 24, 32, 40, 48, 56, 64, 72, 80, 88, + 96, 104, 112, 120, 128, 144, 160, 176, 192, 208, 224, 240, + 256, 280, 304, 328, 352, 376, 400, 424, 448, 472, 496, 520, + 544, 576, 608, 640, 672, 704, 736, 768 +}; + +const short band_end_HQ[44] = +{ + 8, 16, 24, 32, 40, 48, 56, 64, 72, 80, 88, 96, + 104, 112, 120, 128, 144, 160, 176, 192, 208, 224, 240, 256, + 280, 304, 328, 352, 376, 400, 424, 448, 472, 496, 520, 544, + 576, 608, 640, 672, 704, 736, 768, 800 +}; + +const short band_len_HQ[44] = +{ + 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, + 8, 8, 8, 8, 16, 16, 16, 16, 16, 16, 16, 16, + 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, + 32, 32, 32, 32, 32, 32, 32, 32 +}; + +const short band_start_wb[26] = +{ + 0, 8, 16, 24, 32, 40, 48, 56, 64, 72, 80, 88, + 96, 104, 112, 120, 128, 144, 160, 176, 192, 208, 224, 240, + 256, 288 +}; + +const short band_end_wb[26] = +{ + 8, 16, 24, 32, 40, 48, 56, 64, 72, 80, 88, 96, + 104, 112, 120, 128, 144, 160, 176, 192, 208, 224, 240, 256, + 288, 320 +}; + +const short band_len_wb[26] = +{ + 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, + 8, 8, 8, 8, 16, 16, 16, 16, 16, 16, 16, 16, + 32, 32 +}; +const Word16 band_len_harm[SFM_N_HARM_FB] = +{ + 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, + 16, 16, 16, 16, 16, 16, 32, 32, 32, 48, 48, 48, 48, 64, 64, 64, 96 +}; + +const Word16 band_start_harm[SFM_N_HARM_FB] = +{ + 0, 8, 16, 24, 32, 40, 48, 56, 64, 72, 80, 88, 96, 104, 112, 120, + 128, 144, 160, 176, 192, 208, 224, 256, 288, 320, 368, 416, 464, 512, 576, 640, 704 +}; + +const Word16 band_end_harm[SFM_N_HARM_FB] = +{ + 8, 16, 24, 32, 40, 48, 56, 64, 72, 80, 88, 96, 104, 112, 120, 128, + 144, 160, 176, 192, 208, 224, 256, 288, 320, 368, 416, 464, 512, 576, 640, 704, 800 +}; + + +const float rat[SFM_N_WB] = {1.5f, 1.5f, 1.5f, 1.5f, 1.5f, 1.5f, 1.5f, 1.5f, 1.5f, 1.5f, 1.5f, 1.5f, 1.5f, 1.5f, 1.5f, 1.5f, + 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 0.8f, 0.8f + }; + +const short sfm_width[20] = {3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 5, 5, 6, 6, 6, 7, 8}; +const short a_map[20] = {8, 6, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 4, 5, 7, 11}; + + +const Word32 SQRT_DIM_fx[65] = /* sqrt(x) for x = 0, 1, ..., 64. in Q15 */ +{ + 0, 32768, 46341, 56756, 65536, 73271, 80265, 86696, + 92682, 98304, 103622, 108679, 113512, 118147, 122607, 126910, + 131072, 135106, 139023, 142832, 146543, 150162, 153696, 157150, + 160530, 163840, 167085, 170268, 173392, 176461, 179478, 182445, + 185364, 188238, 191069, 193858, 196608, 199320, 201996, 204636, + 207243, 209818, 212361, 214874, 217358, 219814, 222243, 224646, + 227023, 229376, 231705, 234010, 236293, 238555, 240795, 243014, + 245213, 247393, 249554, 251696, 253820, 255926, 258015, 260088, + 262144 +}; + + + +/*------------------------------------------------------------------------------* + * HQ core tables for SWB signals + *------------------------------------------------------------------------------*/ + + +const float window_8_16_32kHz[370] = +{ + 0.00009609f, 0.00028765f, 0.00058708f, 0.00099202f, 0.00150079f, 0.00211209f, 0.00282484f, 0.00363808f, + 0.00455097f, 0.00556272f, 0.00667261f, 0.00787994f, 0.00918405f, 0.01058429f, 0.01208004f, 0.01367067f, + 0.01535558f, 0.01713416f, 0.01900581f, 0.02096992f, 0.02302588f, 0.02517309f, 0.02741093f, 0.02973879f, + 0.03215604f, 0.03466206f, 0.03725620f, 0.03993782f, 0.04270627f, 0.04556089f, 0.04850099f, 0.05152591f, + 0.05463496f, 0.05782743f, 0.06110262f, 0.06445980f, 0.06789825f, 0.07141723f, 0.07501599f, 0.07869376f, + 0.08244978f, 0.08628326f, 0.09019341f, 0.09417944f, 0.09824051f, 0.10237582f, 0.10658453f, 0.11086578f, + 0.11521874f, 0.11964252f, 0.12413626f, 0.12869907f, 0.13333005f, 0.13802829f, 0.14279289f, 0.14762290f, + 0.15251740f, 0.15747544f, 0.16249607f, 0.16757831f, 0.17272120f, 0.17792375f, 0.18318496f, 0.18850384f, + 0.19387938f, 0.19931055f, 0.20479633f, 0.21033568f, 0.21592756f, 0.22157091f, 0.22726467f, 0.23300778f, + 0.23879915f, 0.24463771f, 0.25052236f, 0.25645201f, 0.26242554f, 0.26844185f, 0.27449982f, 0.28059832f, + 0.28673623f, 0.29291240f, 0.29912569f, 0.30537495f, 0.31165902f, 0.31797676f, 0.32432698f, 0.33070852f, + 0.33712021f, 0.34326770f, 0.34902538f, 0.35469475f, 0.36039689f, 0.36612343f, 0.37187036f, 0.37763517f, + 0.38341599f, 0.38921132f, 0.39501987f, 0.40084050f, 0.40667214f, 0.41251382f, 0.41836457f, 0.42422351f, + 0.43008975f, 0.43596242f, 0.44184069f, 0.44772373f, 0.45361072f, 0.45950085f, 0.46539332f, 0.47128734f, + 0.47718210f, 0.48307684f, 0.48897077f, 0.49486311f, 0.50075309f, 0.50663994f, 0.51252290f, 0.51840120f, + 0.52427408f, 0.53014079f, 0.53600058f, 0.54185268f, 0.54769636f, 0.55353086f, 0.55935545f, 0.56516939f, + 0.57097193f, 0.57676236f, 0.58253993f, 0.58830393f, 0.59405363f, 0.59978832f, 0.60550728f, 0.61120980f, + 0.61689518f, 0.62256271f, 0.62821170f, 0.63384146f, 0.63945131f, 0.64504055f, 0.65060852f, 0.65615454f, + 0.66167795f, 0.66717809f, 0.67265431f, 0.67810596f, 0.68353240f, 0.68893300f, 0.69430713f, 0.69965417f, + 0.70497350f, 0.71026452f, 0.71552664f, 0.72075927f, 0.72596181f, 0.73113370f, 0.73627436f, 0.74053370f, + 0.74223132f, 0.74645982f, 0.75150351f, 0.75651380f, 0.76149018f, 0.76643212f, 0.77133911f, 0.77621068f, + 0.78104633f, 0.78584558f, 0.79060798f, 0.79533307f, 0.80002041f, 0.80466956f, 0.80928010f, 0.81385162f, + 0.81838372f, 0.82287601f, 0.82732812f, 0.83173967f, 0.83611032f, 0.84043971f, 0.84472753f, 0.84897345f, + 0.85317717f, 0.85733839f, 0.86145684f, 0.86553224f, 0.86956435f, 0.87355292f, 0.87749772f, 0.88139855f, + 0.88525520f, 0.88906748f, 0.89283524f, 0.89655830f, 0.90023654f, 0.90386982f, 0.90745805f, 0.91100112f, + 0.91449896f, 0.91795152f, 0.92135875f, 0.92472064f, 0.92803719f, 0.93130842f, 0.93453436f, 0.93771509f, + 0.94085071f, 0.94394132f, 0.94698708f, 0.94998816f, 0.95294479f, 0.95585723f, 0.95872577f, 0.96155077f, + 0.96433265f, 0.96707190f, 0.96976909f, 0.97242491f, 0.97504018f, 0.97761590f, 0.98015330f, 0.98265393f, + 0.98511982f, 0.98755371f, 0.98995949f, 0.99234319f, 0.99471536f, 0.99709994f, 0.99708681f, 0.99466528f, + 0.99222861f, 0.98975303f, 0.98722813f, 0.98464802f, 0.98200891f, 0.97930819f, 0.97654393f, 0.97371465f, + 0.97081921f, 0.96785667f, 0.96482628f, 0.96172739f, 0.95855948f, 0.95532207f, 0.95201479f, 0.94863729f, + 0.94518926f, 0.94167046f, 0.93808064f, 0.93441963f, 0.93068723f, 0.92688329f, 0.92300768f, 0.91906029f, + 0.91504101f, 0.91094975f, 0.90678646f, 0.90255106f, 0.89824351f, 0.89386377f, 0.88941182f, 0.88488765f, + 0.88029124f, 0.87562260f, 0.87088175f, 0.86606871f, 0.86118350f, 0.85622616f, 0.85119674f, 0.84609529f, + 0.84092187f, 0.83567654f, 0.83035938f, 0.82497048f, 0.81950991f, 0.81397777f, 0.80837415f, 0.80269917f, + 0.79695293f, 0.79113554f, 0.78524714f, 0.77928784f, 0.77325776f, 0.76715706f, 0.76098587f, 0.75474432f, + 0.74843257f, 0.74205077f, 0.73559908f, 0.72907763f, 0.72248661f, 0.71582617f, 0.70909647f, 0.70229768f, + 0.69542998f, 0.68849352f, 0.68148847f, 0.67559894f, 0.67322974f, 0.66727332f, 0.66006356f, 0.65278589f, + 0.64544049f, 0.63802752f, 0.63054716f, 0.62299955f, 0.61538487f, 0.60770327f, 0.59995491f, 0.59213992f, + 0.58425845f, 0.57631064f, 0.56829662f, 0.56021651f, 0.55207043f, 0.54385849f, 0.53558078f, 0.52723738f, + 0.51882839f, 0.51035385f, 0.50181382f, 0.49320834f, 0.48453743f, 0.47580109f, 0.46699931f, 0.45813206f, + 0.44919928f, 0.44020091f, 0.43113683f, 0.42200694f, 0.41281107f, 0.40354904f, 0.39422063f, 0.38482561f, + 0.37536367f, 0.36583448f, 0.35623768f, 0.34657285f, 0.33683949f, 0.32703708f, 0.31716502f, 0.30722265f, + 0.29720921f, 0.28712387f, 0.27696571f, 0.26673368f, 0.25642665f, 0.24604332f, 0.23558226f, 0.22504184f, + 0.21442026f, 0.20371546f, 0.19292514f, 0.18204665f, 0.17107697f, 0.16001264f, 0.14884960f, 0.13758311f, + 0.12620753f, 0.11471608f, 0.10310041f, 0.09135008f, 0.07945161f, 0.06738693f, 0.05513058f, 0.04264380f, + 0.02985996f, 0.01663146f +}; +const float window_256kHz[592] = /*ALDO at 25.6 maybe not needed ?*/ +{ + 0.00002505f, 0.00009623f, 0.00021144f, 0.00036963f, 0.00057004f, 0.00081212f, 0.00109541f, 0.00141951f, + 0.00178408f, 0.00218883f, 0.00263346f, 0.00311775f, 0.00364144f, 0.00420431f, 0.00480616f, 0.00544680f, + 0.00612602f, 0.00684364f, 0.00759949f, 0.00839340f, 0.00922518f, 0.01009468f, 0.01100174f, 0.01194618f, + 0.01292786f, 0.01394661f, 0.01500228f, 0.01609471f, 0.01722376f, 0.01838925f, 0.01959105f, 0.02082899f, + 0.02210292f, 0.02341269f, 0.02475814f, 0.02613912f, 0.02755547f, 0.02900704f, 0.03049367f, 0.03201520f, + 0.03357147f, 0.03516233f, 0.03678761f, 0.03844715f, 0.04014078f, 0.04186836f, 0.04362970f, 0.04542464f, + 0.04725302f, 0.04911467f, 0.05100942f, 0.05293708f, 0.05489750f, 0.05689050f, 0.05891590f, 0.06097352f, + 0.06306319f, 0.06518472f, 0.06733794f, 0.06952266f, 0.07173869f, 0.07398585f, 0.07626395f, 0.07857281f, + 0.08091223f, 0.08328201f, 0.08568197f, 0.08811192f, 0.09057164f, 0.09306095f, 0.09557964f, 0.09812751f, + 0.10070437f, 0.10330999f, 0.10594419f, 0.10860674f, 0.11129745f, 0.11401609f, 0.11676246f, 0.11953635f, + 0.12233753f, 0.12516579f, 0.12802091f, 0.13090267f, 0.13381086f, 0.13674524f, 0.13970559f, 0.14269169f, + 0.14570330f, 0.14874021f, 0.15180217f, 0.15488896f, 0.15800034f, 0.16113609f, 0.16429595f, 0.16747970f, + 0.17068710f, 0.17391790f, 0.17717186f, 0.18044875f, 0.18374831f, 0.18707031f, 0.19041448f, 0.19378059f, + 0.19716839f, 0.20057763f, 0.20400804f, 0.20745938f, 0.21093140f, 0.21442384f, 0.21793644f, 0.22146894f, + 0.22502109f, 0.22859261f, 0.23218326f, 0.23579277f, 0.23942087f, 0.24306730f, 0.24673180f, 0.25041408f, + 0.25411390f, 0.25783097f, 0.26156503f, 0.26531581f, 0.26908303f, 0.27286642f, 0.27666570f, 0.28048060f, + 0.28431085f, 0.28815616f, 0.29201627f, 0.29589088f, 0.29977972f, 0.30368251f, 0.30759896f, 0.31152881f, + 0.31547175f, 0.31942751f, 0.32339581f, 0.32737635f, 0.33136886f, 0.33537304f, 0.33938861f, 0.34341527f, + 0.34689352f, 0.35040979f, 0.35394433f, 0.35749191f, 0.36105010f, 0.36461744f, 0.36819295f, 0.37177588f, + 0.37536568f, 0.37896184f, 0.38256397f, 0.38617170f, 0.38978470f, 0.39340267f, 0.39702533f, 0.40065241f, + 0.40428366f, 0.40791884f, 0.41155771f, 0.41520004f, 0.41884562f, 0.42249422f, 0.42614564f, 0.42979966f, + 0.43345608f, 0.43711469f, 0.44077529f, 0.44443769f, 0.44810168f, 0.45176708f, 0.45543368f, 0.45910129f, + 0.46276972f, 0.46643878f, 0.47010827f, 0.47377802f, 0.47744783f, 0.48111751f, 0.48478688f, 0.48845574f, + 0.49212392f, 0.49579124f, 0.49945749f, 0.50312250f, 0.50678610f, 0.51044808f, 0.51410828f, 0.51776651f, + 0.52142258f, 0.52507633f, 0.52872755f, 0.53237609f, 0.53602175f, 0.53966436f, 0.54330374f, 0.54693971f, + 0.55057209f, 0.55420071f, 0.55782539f, 0.56144595f, 0.56506222f, 0.56867402f, 0.57228118f, 0.57588352f, + 0.57948087f, 0.58307305f, 0.58665990f, 0.59024124f, 0.59381690f, 0.59738672f, 0.60095051f, 0.60450811f, + 0.60805935f, 0.61160407f, 0.61514209f, 0.61867325f, 0.62219738f, 0.62571432f, 0.62922390f, 0.63272595f, + 0.63622033f, 0.63970685f, 0.64318537f, 0.64665571f, 0.65011773f, 0.65357125f, 0.65701613f, 0.66045220f, + 0.66387931f, 0.66729730f, 0.67070601f, 0.67410530f, 0.67749501f, 0.68087499f, 0.68424508f, 0.68760514f, + 0.69095502f, 0.69429456f, 0.69762363f, 0.70094207f, 0.70424975f, 0.70754651f, 0.71083222f, 0.71410673f, + 0.71736991f, 0.72062160f, 0.72386169f, 0.72709002f, 0.73030646f, 0.73351088f, 0.73670315f, 0.73988313f, + 0.74305069f, 0.74620570f, 0.74934804f, 0.75247757f, 0.75559418f, 0.75869773f, 0.76178811f, 0.76486519f, + 0.76792885f, 0.77097898f, 0.77401546f, 0.77703816f, 0.78004699f, 0.78304181f, 0.78602253f, 0.78898904f, + 0.79194121f, 0.79487896f, 0.79780216f, 0.80071072f, 0.80360454f, 0.80648352f, 0.80934755f, 0.81219653f, + 0.81503038f, 0.81784900f, 0.82065230f, 0.82344018f, 0.82621255f, 0.82896934f, 0.83171045f, 0.83443579f, + 0.83714529f, 0.83983887f, 0.84251645f, 0.84517794f, 0.84782328f, 0.85045240f, 0.85306521f, 0.85566165f, + 0.85824166f, 0.86080517f, 0.86335210f, 0.86588241f, 0.86839603f, 0.87089291f, 0.87337298f, 0.87583620f, + 0.87828250f, 0.88071185f, 0.88312419f, 0.88551948f, 0.88789767f, 0.89025873f, 0.89260261f, 0.89492928f, + 0.89723869f, 0.89953083f, 0.90180566f, 0.90406314f, 0.90630327f, 0.90852600f, 0.91073133f, 0.91291923f, + 0.91508969f, 0.91724270f, 0.91937824f, 0.92149632f, 0.92359691f, 0.92568004f, 0.92774569f, 0.92979387f, + 0.93182459f, 0.93383786f, 0.93583369f, 0.93781212f, 0.93977315f, 0.94171681f, 0.94364315f, 0.94555218f, + 0.94744396f, 0.94931853f, 0.95117594f, 0.95301624f, 0.95483951f, 0.95664580f, 0.95843521f, 0.96020781f, + 0.96196370f, 0.96370298f, 0.96542577f, 0.96713221f, 0.96882242f, 0.97049658f, 0.97215486f, 0.97379745f, + 0.97542459f, 0.97703653f, 0.97863356f, 0.98021601f, 0.98178428f, 0.98333882f, 0.98488019f, 0.98640904f, + 0.98792619f, 0.98943268f, 0.99092986f, 0.99241955f, 0.99390438f, 0.99538840f, 0.99687865f, 0.99839048f, + 0.99839048f, 0.99687316f, 0.99536647f, 0.99385512f, 0.99233208f, 0.99079337f, 0.98923638f, 0.98765934f, + 0.98606092f, 0.98444012f, 0.98279615f, 0.98112838f, 0.97943628f, 0.97771944f, 0.97597747f, 0.97421006f, + 0.97241695f, 0.97059790f, 0.96875269f, 0.96688116f, 0.96498313f, 0.96305846f, 0.96110701f, 0.95912868f, + 0.95712335f, 0.95509092f, 0.95303131f, 0.95094444f, 0.94883023f, 0.94668862f, 0.94451953f, 0.94232293f, + 0.94009875f, 0.93784694f, 0.93556747f, 0.93326028f, 0.93092535f, 0.92856264f, 0.92617212f, 0.92375376f, + 0.92130753f, 0.91883342f, 0.91633139f, 0.91380144f, 0.91124353f, 0.90865767f, 0.90604383f, 0.90340200f, + 0.90073218f, 0.89803436f, 0.89530852f, 0.89255467f, 0.88977280f, 0.88696291f, 0.88412500f, 0.88125907f, + 0.87836512f, 0.87544316f, 0.87249319f, 0.86951521f, 0.86650924f, 0.86347528f, 0.86041334f, 0.85732343f, + 0.85420557f, 0.85105976f, 0.84788602f, 0.84468436f, 0.84145481f, 0.83819737f, 0.83491207f, 0.83159893f, + 0.82825795f, 0.82488917f, 0.82149260f, 0.81806828f, 0.81461621f, 0.81113643f, 0.80762895f, 0.80409381f, + 0.80053104f, 0.79694065f, 0.79332267f, 0.78967714f, 0.78600409f, 0.78230354f, 0.77857552f, 0.77482007f, + 0.77103722f, 0.76722699f, 0.76338943f, 0.75952457f, 0.75563243f, 0.75171306f, 0.74776649f, 0.74379276f, + 0.73979190f, 0.73576394f, 0.73170893f, 0.72762691f, 0.72351790f, 0.71938195f, 0.71521909f, 0.71102937f, + 0.70681283f, 0.70256949f, 0.69829940f, 0.69400260f, 0.68967913f, 0.68532903f, 0.68095233f, 0.67654908f, + 0.67211932f, 0.66766308f, 0.66318040f, 0.65867133f, 0.65413589f, 0.64957414f, 0.64498610f, 0.64037182f, + 0.63573134f, 0.63106468f, 0.62637190f, 0.62165301f, 0.61690807f, 0.61213710f, 0.60734015f, 0.60251723f, + 0.59766840f, 0.59279367f, 0.58789308f, 0.58296667f, 0.57801446f, 0.57303647f, 0.56803275f, 0.56300331f, + 0.55794818f, 0.55286738f, 0.54776094f, 0.54262888f, 0.53747121f, 0.53228796f, 0.52707914f, 0.52184477f, + 0.51658486f, 0.51129942f, 0.50598845f, 0.50065198f, 0.49528999f, 0.48990250f, 0.48448950f, 0.47905099f, + 0.47358696f, 0.46809741f, 0.46258232f, 0.45704168f, 0.45147548f, 0.44588369f, 0.44026628f, 0.43462323f, + 0.42895451f, 0.42326008f, 0.41753990f, 0.41179392f, 0.40602210f, 0.40022438f, 0.39440070f, 0.38855100f, + 0.38267520f, 0.37677323f, 0.37084500f, 0.36489043f, 0.35890941f, 0.35290185f, 0.34686763f, 0.34080663f, + 0.33471872f, 0.32860376f, 0.32246161f, 0.31629211f, 0.31009508f, 0.30387035f, 0.29761773f, 0.29133699f, + 0.28502794f, 0.27869032f, 0.27232389f, 0.26592837f, 0.25950348f, 0.25304891f, 0.24656432f, 0.24004937f, + 0.23350366f, 0.22692680f, 0.22031833f, 0.21367779f, 0.20700468f, 0.20029842f, 0.19355844f, 0.18678407f, + 0.17997463f, 0.17312933f, 0.16624735f, 0.15932777f, 0.15236958f, 0.14537166f, 0.13833277f, 0.13125154f, + 0.12412643f, 0.11695568f, 0.10973731f, 0.10246907f, 0.09514831f, 0.08777196f, 0.08033640f, 0.07283723f, + 0.06526908f, 0.05762520f, 0.04989688f, 0.04207239f, 0.03413516f, 0.02605991f, 0.01780324f, 0.00927214f +}; + +const float small_overlap_48[R2_48/7]= +{ + 0.01308960f, 0.03925982f, 0.06540313f, 0.09150162f, 0.11753740f, 0.14349262f, 0.16934950f, 0.19509032f, + 0.22069744f, 0.24615329f, 0.27144045f, 0.29654157f, 0.32143947f, 0.34611706f, 0.37055744f, 0.39474386f, + 0.41865974f, 0.44228869f, 0.46561452f, 0.48862124f, 0.51129309f, 0.53361452f, 0.55557023f, 0.57714519f, + 0.59832460f, 0.61909395f, 0.63943900f, 0.65934582f, 0.67880075f, 0.69779046f, 0.71630194f, 0.73432251f, + 0.75183981f, 0.76884183f, 0.78531693f, 0.80125381f, 0.81664156f, 0.83146961f, 0.84572782f, 0.85940641f, + 0.87249601f, 0.88498764f, 0.89687274f, 0.90814317f, 0.91879121f, 0.92880955f, 0.93819134f, 0.94693013f, + 0.95501994f, 0.96245524f, 0.96923091f, 0.97534232f, 0.98078528f, 0.98555606f, 0.98965139f, 0.99306846f, + 0.99580493f, 0.99785892f, 0.99922904f, 0.99991433f +}; + +const float small_overlap_25[R2_25/7]= +{ + 0.02454123f, 0.07356456f, 0.12241068f, 0.17096189f, 0.21910124f, 0.26671276f, 0.31368174f, 0.35989504f, + 0.40524131f, 0.44961133f, 0.49289819f, 0.53499762f, 0.57580819f, 0.61523159f, 0.65317284f, 0.68954054f, + 0.72424708f, 0.75720885f, 0.78834643f, 0.81758481f, 0.84485357f, 0.87008699f, 0.89322430f, 0.91420976f, + 0.93299280f, 0.94952818f, 0.96377607f, 0.97570213f, 0.98527764f, 0.99247953f, 0.99729046f, 0.99969882f +}; + +const float small_overlap_int[R2_16/7]= +{ + 0.07845910f, 0.15643447f, + 0.23344536f, 0.30901699f, 0.38268343f, 0.45399050f, 0.52249856f, 0.58778525f, 0.64944805f, 0.69778617f, + 0.71630612f, 0.76040597f, 0.80901699f, 0.85264016f, 0.89100652f, 0.92387953f, 0.95105652f, 0.97236992f, + 0.98768834f, 0.99691733f +}; + + +const float half_overlap_48[3*R2_48/7]= +{ + 0.00436331f, 0.01308960f, + 0.02181489f, 0.03053851f, 0.03925982f, 0.04797813f, 0.05669279f, 0.06540313f, 0.07410849f, 0.08280821f, + 0.09150162f, 0.10018806f, 0.10886687f, 0.11753740f, 0.12619897f, 0.13485093f, 0.14349262f, 0.15212339f, + 0.16074257f, 0.16934950f, 0.17794355f, 0.18652404f, 0.19509032f, 0.20364175f, 0.21217767f, 0.22069744f, + 0.22920039f, 0.23768589f, 0.24615329f, 0.25460195f, 0.26303121f, 0.27144045f, 0.27982901f, 0.28819627f, + 0.29654157f, 0.30486430f, 0.31316381f, 0.32143947f, 0.32969065f, 0.33791672f, 0.34611706f, 0.35429104f, + 0.36243804f, 0.37055744f, 0.37864862f, 0.38671096f, 0.39474386f, 0.40274669f, 0.41071885f, 0.41865974f, + 0.42656874f, 0.43444526f, 0.44228869f, 0.45009844f, 0.45787392f, 0.46561452f, 0.47331967f, 0.48098877f, + 0.48862124f, 0.49621650f, 0.50377398f, 0.51129309f, 0.51877326f, 0.52621392f, 0.53361452f, 0.54097447f, + 0.54829323f, 0.55557023f, 0.56280493f, 0.56999676f, 0.57714519f, 0.58424967f, 0.59130965f, 0.59832460f, + 0.60529399f, 0.61221728f, 0.61909395f, 0.62592347f, 0.63270533f, 0.63943900f, 0.64612398f, 0.65275975f, + 0.65934582f, 0.66588167f, 0.67236681f, 0.67880075f, 0.68518299f, 0.69151306f, 0.69779046f, 0.70401472f, + 0.71018538f, 0.71630194f, 0.72236396f, 0.72837097f, 0.73432251f, 0.74021813f, 0.74605738f, 0.75183981f, + 0.75756498f, 0.76323247f, 0.76884183f, 0.77439264f, 0.77988448f, 0.78531693f, 0.79068957f, 0.79600200f, + 0.80125381f, 0.80644460f, 0.81157398f, 0.81664156f, 0.82164694f, 0.82658975f, 0.83146961f, 0.83628616f, + 0.84103901f, 0.84572782f, 0.85035222f, 0.85491187f, 0.85940641f, 0.86383551f, 0.86819881f, 0.87249601f, + 0.87672676f, 0.88089074f, 0.88498764f, 0.88901714f, 0.89297894f, 0.89687274f, 0.90069824f, 0.90445515f, + 0.90814317f, 0.91176204f, 0.91531148f, 0.91879121f, 0.92220097f, 0.92554050f, 0.92880955f, 0.93200787f, + 0.93513521f, 0.93819134f, 0.94117602f, 0.94408902f, 0.94693013f, 0.94969913f, 0.95239580f, 0.95501994f, + 0.95757136f, 0.96004985f, 0.96245524f, 0.96478732f, 0.96704594f, 0.96923091f, 0.97134207f, 0.97337926f, + 0.97534232f, 0.97723111f, 0.97904547f, 0.98078528f, 0.98245040f, 0.98404070f, 0.98555606f, 0.98699637f, + 0.98836151f, 0.98965139f, 0.99086590f, 0.99200495f, 0.99306846f, 0.99405634f, 0.99496852f, 0.99580493f, + 0.99656550f, 0.99725019f, 0.99785892f, 0.99839167f, 0.99884839f, 0.99922904f, 0.99953359f, 0.99976203f, + 0.99991433f, 0.99999048f +}; + +const float half_overlap_25[3*R2_25/7]= +{ + 0.00818114f, 0.02454123f, 0.04089475f, 0.05723732f, 0.07356456f, 0.08987211f, 0.10615561f, 0.12241068f, + 0.13863297f, 0.15481816f, 0.17096189f, 0.18705985f, 0.20310773f, 0.21910124f, 0.23503609f, 0.25090801f, + 0.26671276f, 0.28244610f, 0.29810383f, 0.31368174f, 0.32917568f, 0.34458148f, 0.35989504f, 0.37511224f, + 0.39022901f, 0.40524131f, 0.42014512f, 0.43493645f, 0.44961133f, 0.46416584f, 0.47859608f, 0.49289819f, + 0.50706834f, 0.52110274f, 0.53499762f, 0.54874927f, 0.56235401f, 0.57580819f, 0.58910822f, 0.60225052f, + 0.61523159f, 0.62804795f, 0.64069616f, 0.65317284f, 0.66547466f, 0.67759830f, 0.68954054f, 0.70129818f, + 0.71286806f, 0.72424708f, 0.73543221f, 0.74642045f, 0.75720885f, 0.76779452f, 0.77817464f, 0.78834643f, + 0.79830715f, 0.80805415f, 0.81758481f, 0.82689659f, 0.83598698f, 0.84485357f, 0.85349396f, 0.86190585f, + 0.87008699f, 0.87803519f, 0.88574831f, 0.89322430f, 0.90046115f, 0.90745693f, 0.91420976f, 0.92071783f, + 0.92697940f, 0.93299280f, 0.93875641f, 0.94426870f, 0.94952818f, 0.95453345f, 0.95928317f, 0.96377607f, + 0.96801094f, 0.97198664f, 0.97570213f, 0.97915640f, 0.98234852f, 0.98527764f, 0.98794298f, 0.99034383f, + 0.99247953f, 0.99434953f, 0.99595331f, 0.99729046f, 0.99836060f, 0.99916346f, 0.99969882f, 0.99996653f, +}; + +const float half_overlap_int[3*R2_16/7]= +{ + 0.02617695f, 0.05233596f, 0.07845910f, 0.10452846f, 0.13052619f, 0.15643447f, + 0.18223553f, 0.20791169f, 0.23344536f, 0.25881905f, 0.28401534f, 0.30901699f, 0.33380686f, 0.35836795f, + 0.38268343f, 0.40673664f, 0.43051110f, 0.45399050f, 0.47715876f, 0.50000000f, 0.52249856f, 0.54463904f, + 0.56640624f, 0.58778525f, 0.60876143f, 0.62932039f, 0.64944805f, 0.66913061f, 0.68835458f, 0.70401457f, + 0.71018553f, 0.72537437f, 0.74314483f, 0.76040597f, 0.77714596f, 0.79335334f, 0.80901699f, 0.82412619f, + 0.83867057f, 0.85264016f, 0.86602540f, 0.87881711f, 0.89100652f, 0.90258528f, 0.91354546f, 0.92387953f, + 0.93358043f, 0.94264149f, 0.95105652f, 0.95881973f, 0.96592583f, 0.97236992f, 0.97814760f, 0.98325491f, + 0.98768834f, 0.99144486f, 0.99452190f, 0.99691733f, 0.99862953f, 0.99965732f +}; + +const float window_48kHz[1110] = +{ + 0.00000717f, 0.00002765f, 0.00006087f, 0.00010657f, 0.00016454f, 0.00023464f, 0.00031674f, 0.00041075f, + 0.00051659f, 0.00063416f, 0.00076341f, 0.00090428f, 0.00105670f, 0.00122062f, 0.00139600f, 0.00158279f, + 0.00178095f, 0.00199044f, 0.00221121f, 0.00244323f, 0.00268646f, 0.00294088f, 0.00320644f, 0.00348313f, + 0.00377089f, 0.00406971f, 0.00437956f, 0.00470041f, 0.00503222f, 0.00537498f, 0.00572866f, 0.00609322f, + 0.00646865f, 0.00685492f, 0.00725200f, 0.00765987f, 0.00807851f, 0.00850788f, 0.00894798f, 0.00939876f, + 0.00986022f, 0.01033232f, 0.01081504f, 0.01130837f, 0.01181227f, 0.01232672f, 0.01285171f, 0.01338721f, + 0.01393319f, 0.01448963f, 0.01505652f, 0.01563383f, 0.01622153f, 0.01681961f, 0.01742804f, 0.01804680f, + 0.01867586f, 0.01931521f, 0.01996482f, 0.02062467f, 0.02129474f, 0.02197501f, 0.02266545f, 0.02336603f, + 0.02407675f, 0.02479757f, 0.02552847f, 0.02626943f, 0.02702042f, 0.02778143f, 0.02855244f, 0.02933340f, + 0.03012432f, 0.03092515f, 0.03173588f, 0.03255648f, 0.03338694f, 0.03422723f, 0.03507731f, 0.03593718f, + 0.03680680f, 0.03768616f, 0.03857522f, 0.03947397f, 0.04038238f, 0.04130042f, 0.04222808f, 0.04316532f, + 0.04411212f, 0.04506846f, 0.04603431f, 0.04700965f, 0.04799445f, 0.04898869f, 0.04999234f, 0.05100537f, + 0.05202776f, 0.05305949f, 0.05410053f, 0.05515085f, 0.05621043f, 0.05727924f, 0.05835725f, 0.05944444f, + 0.06054078f, 0.06164624f, 0.06276080f, 0.06388444f, 0.06501711f, 0.06615880f, 0.06730949f, 0.06846913f, + 0.06963771f, 0.07081519f, 0.07200155f, 0.07319676f, 0.07440080f, 0.07561362f, 0.07683522f, 0.07806555f, + 0.07930459f, 0.08055231f, 0.08180868f, 0.08307367f, 0.08434725f, 0.08562940f, 0.08692008f, 0.08821927f, + 0.08952693f, 0.09084304f, 0.09216756f, 0.09350047f, 0.09484173f, 0.09619131f, 0.09754919f, 0.09891534f, + 0.10028971f, 0.10167229f, 0.10306304f, 0.10446193f, 0.10586893f, 0.10728400f, 0.10870712f, 0.11013826f, + 0.11157738f, 0.11302444f, 0.11447943f, 0.11594230f, 0.11741303f, 0.11889158f, 0.12037792f, 0.12187201f, + 0.12337383f, 0.12488334f, 0.12640051f, 0.12792530f, 0.12945769f, 0.13099763f, 0.13254510f, 0.13410005f, + 0.13566247f, 0.13723231f, 0.13880953f, 0.14039412f, 0.14198602f, 0.14358521f, 0.14519166f, 0.14680532f, + 0.14842616f, 0.15005415f, 0.15168925f, 0.15333143f, 0.15498066f, 0.15663689f, 0.15830009f, 0.15997023f, + 0.16164727f, 0.16333117f, 0.16502191f, 0.16671943f, 0.16842371f, 0.17013472f, 0.17185240f, 0.17357674f, + 0.17530768f, 0.17704520f, 0.17878926f, 0.18053981f, 0.18229683f, 0.18406028f, 0.18583011f, 0.18760630f, + 0.18938880f, 0.19117758f, 0.19297259f, 0.19477381f, 0.19658119f, 0.19839469f, 0.20021428f, 0.20203992f, + 0.20387157f, 0.20570919f, 0.20755274f, 0.20940219f, 0.21125750f, 0.21311862f, 0.21498552f, 0.21685816f, + 0.21873650f, 0.22062050f, 0.22251012f, 0.22440532f, 0.22630606f, 0.22821231f, 0.23012402f, 0.23204116f, + 0.23396367f, 0.23589153f, 0.23782470f, 0.23976312f, 0.24170677f, 0.24365560f, 0.24560957f, 0.24756865f, + 0.24953278f, 0.25150194f, 0.25347607f, 0.25545514f, 0.25743911f, 0.25942794f, 0.26142158f, 0.26341999f, + 0.26542314f, 0.26743098f, 0.26944347f, 0.27146056f, 0.27348222f, 0.27550841f, 0.27753908f, 0.27957419f, + 0.28161370f, 0.28365757f, 0.28570575f, 0.28775820f, 0.28981489f, 0.29187576f, 0.29394078f, 0.29600991f, + 0.29808309f, 0.30016029f, 0.30224147f, 0.30432658f, 0.30641558f, 0.30850843f, 0.31060508f, 0.31270549f, + 0.31480962f, 0.31691743f, 0.31902887f, 0.32114389f, 0.32326246f, 0.32538454f, 0.32751007f, 0.32963901f, + 0.33177133f, 0.33390698f, 0.33604591f, 0.33818808f, 0.34033345f, 0.34248196f, 0.34432825f, 0.34619672f, + 0.34807434f, 0.34995817f, 0.35184686f, 0.35373965f, 0.35563601f, 0.35753559f, 0.35943811f, 0.36134336f, + 0.36325118f, 0.36516141f, 0.36707393f, 0.36898864f, 0.37090544f, 0.37282426f, 0.37474501f, 0.37666763f, + 0.37859204f, 0.38051820f, 0.38244605f, 0.38437553f, 0.38630659f, 0.38823918f, 0.39017326f, 0.39210879f, + 0.39404572f, 0.39598401f, 0.39792361f, 0.39986450f, 0.40180663f, 0.40374996f, 0.40569446f, 0.40764009f, + 0.40958682f, 0.41153461f, 0.41348342f, 0.41543322f, 0.41738398f, 0.41933567f, 0.42128825f, 0.42324169f, + 0.42519595f, 0.42715101f, 0.42910683f, 0.43106338f, 0.43302063f, 0.43497855f, 0.43693710f, 0.43889626f, + 0.44085600f, 0.44281628f, 0.44477708f, 0.44673836f, 0.44870009f, 0.45066225f, 0.45262480f, 0.45458771f, + 0.45655096f, 0.45851451f, 0.46047834f, 0.46244241f, 0.46440670f, 0.46637117f, 0.46833580f, 0.47030055f, + 0.47226541f, 0.47423033f, 0.47619530f, 0.47816027f, 0.48012523f, 0.48209014f, 0.48405498f, 0.48601971f, + 0.48798430f, 0.48994874f, 0.49191298f, 0.49387701f, 0.49584078f, 0.49780428f, 0.49976748f, 0.50173034f, + 0.50369284f, 0.50565495f, 0.50761664f, 0.50957789f, 0.51153865f, 0.51349892f, 0.51545865f, 0.51741783f, + 0.51937641f, 0.52133438f, 0.52329171f, 0.52524836f, 0.52720432f, 0.52915954f, 0.53111401f, 0.53306770f, + 0.53502057f, 0.53697261f, 0.53892378f, 0.54087405f, 0.54282340f, 0.54477180f, 0.54671922f, 0.54866564f, + 0.55061103f, 0.55255535f, 0.55449858f, 0.55644070f, 0.55838168f, 0.56032149f, 0.56226010f, 0.56419748f, + 0.56613362f, 0.56806847f, 0.57000202f, 0.57193423f, 0.57386509f, 0.57579455f, 0.57772261f, 0.57964922f, + 0.58157436f, 0.58349801f, 0.58542013f, 0.58734071f, 0.58925971f, 0.59117711f, 0.59309288f, 0.59500700f, + 0.59691943f, 0.59883016f, 0.60073915f, 0.60264638f, 0.60455182f, 0.60645545f, 0.60835724f, 0.61025717f, + 0.61215520f, 0.61405132f, 0.61594549f, 0.61783769f, 0.61972789f, 0.62161608f, 0.62350222f, 0.62538628f, + 0.62726824f, 0.62914809f, 0.63102578f, 0.63290129f, 0.63477461f, 0.63664570f, 0.63851454f, 0.64038110f, + 0.64224536f, 0.64410729f, 0.64596688f, 0.64782408f, 0.64967889f, 0.65153127f, 0.65338119f, 0.65522864f, + 0.65707360f, 0.65891602f, 0.66075590f, 0.66259321f, 0.66442791f, 0.66626000f, 0.66808944f, 0.66991621f, + 0.67174028f, 0.67356164f, 0.67538025f, 0.67719610f, 0.67900916f, 0.68081941f, 0.68262682f, 0.68443137f, + 0.68623303f, 0.68803180f, 0.68982763f, 0.69162050f, 0.69341041f, 0.69519731f, 0.69698119f, 0.69876203f, + 0.70053980f, 0.70231448f, 0.70408605f, 0.70585448f, 0.70761976f, 0.70938186f, 0.71114076f, 0.71289643f, + 0.71464886f, 0.71639803f, 0.71814390f, 0.71988647f, 0.72162570f, 0.72336158f, 0.72509409f, 0.72682320f, + 0.72854889f, 0.73027115f, 0.73198995f, 0.73370527f, 0.73541708f, 0.73712538f, 0.73883014f, 0.74053133f, + 0.74222894f, 0.74392295f, 0.74561334f, 0.74730009f, 0.74898317f, 0.75066257f, 0.75233827f, 0.75401025f, + 0.75567849f, 0.75734297f, 0.75900367f, 0.76066057f, 0.76231366f, 0.76396291f, 0.76560830f, 0.76724982f, + 0.76888745f, 0.77052118f, 0.77215097f, 0.77377682f, 0.77539870f, 0.77701660f, 0.77863050f, 0.78024038f, + 0.78184623f, 0.78344803f, 0.78504575f, 0.78663939f, 0.78822893f, 0.78981434f, 0.79139562f, 0.79297274f, + 0.79454569f, 0.79611446f, 0.79767902f, 0.79923936f, 0.80079547f, 0.80234733f, 0.80389492f, 0.80543823f, + 0.80697724f, 0.80851193f, 0.81004230f, 0.81156833f, 0.81309000f, 0.81460729f, 0.81612020f, 0.81762870f, + 0.81913279f, 0.82063245f, 0.82212766f, 0.82361842f, 0.82510470f, 0.82658650f, 0.82806380f, 0.82953658f, + 0.83100484f, 0.83246856f, 0.83392773f, 0.83538233f, 0.83683236f, 0.83827780f, 0.83971863f, 0.84115485f, + 0.84258645f, 0.84401340f, 0.84543571f, 0.84685336f, 0.84826633f, 0.84967462f, 0.85107821f, 0.85247710f, + 0.85387127f, 0.85526072f, 0.85664542f, 0.85802538f, 0.85940058f, 0.86077102f, 0.86213667f, 0.86349754f, + 0.86485361f, 0.86620487f, 0.86755132f, 0.86889294f, 0.87022973f, 0.87156168f, 0.87288878f, 0.87421101f, + 0.87552839f, 0.87684088f, 0.87814849f, 0.87945122f, 0.88074904f, 0.88204196f, 0.88332997f, 0.88461305f, + 0.88589122f, 0.88716444f, 0.88843273f, 0.88969608f, 0.89095447f, 0.89220791f, 0.89345638f, 0.89469988f, + 0.89593841f, 0.89717197f, 0.89840053f, 0.89962411f, 0.90084270f, 0.90205629f, 0.90326488f, 0.90446846f, + 0.90566704f, 0.90686060f, 0.90804915f, 0.90923267f, 0.91041118f, 0.91158466f, 0.91275311f, 0.91391654f, + 0.91507493f, 0.91622829f, 0.91737662f, 0.91851991f, 0.91965816f, 0.92079138f, 0.92191956f, 0.92304270f, + 0.92416080f, 0.92527386f, 0.92638188f, 0.92748486f, 0.92858281f, 0.92967572f, 0.93076360f, 0.93184645f, + 0.93292426f, 0.93399705f, 0.93506481f, 0.93612755f, 0.93718527f, 0.93823797f, 0.93928566f, 0.94032834f, + 0.94136602f, 0.94239870f, 0.94342639f, 0.94444909f, 0.94546681f, 0.94647956f, 0.94748733f, 0.94849015f, + 0.94948801f, 0.95048093f, 0.95146891f, 0.95245197f, 0.95343011f, 0.95440334f, 0.95537168f, 0.95633513f, + 0.95729371f, 0.95824743f, 0.95919630f, 0.96014034f, 0.96107957f, 0.96201399f, 0.96294363f, 0.96386850f, + 0.96478862f, 0.96570402f, 0.96661470f, 0.96752070f, 0.96842204f, 0.96931873f, 0.97021081f, 0.97109831f, + 0.97198124f, 0.97285966f, 0.97373358f, 0.97460304f, 0.97546808f, 0.97632874f, 0.97718506f, 0.97803710f, + 0.97888489f, 0.97972850f, 0.98056799f, 0.98140340f, 0.98223483f, 0.98306234f, 0.98388601f, 0.98470595f, + 0.98552225f, 0.98633502f, 0.98714441f, 0.98795054f, 0.98875359f, 0.98955376f, 0.99035126f, 0.99114636f, + 0.99193936f, 0.99273065f, 0.99352070f, 0.99431009f, 0.99509960f, 0.99589027f, 0.99668360f, 0.99748189f, + 0.99828914f, 0.99911401f, 0.99911401f, 0.99828759f, 0.99747571f, 0.99666970f, 0.99586557f, 0.99506104f, + 0.99425460f, 0.99344523f, 0.99263215f, 0.99181478f, 0.99099266f, 0.99016542f, 0.98933274f, 0.98849437f, + 0.98765009f, 0.98679972f, 0.98594310f, 0.98508007f, 0.98421052f, 0.98333434f, 0.98245143f, 0.98156170f, + 0.98066506f, 0.97976145f, 0.97885080f, 0.97793305f, 0.97700814f, 0.97607603f, 0.97513666f, 0.97419000f, + 0.97323600f, 0.97227462f, 0.97130583f, 0.97032960f, 0.96934589f, 0.96835468f, 0.96735594f, 0.96634965f, + 0.96533578f, 0.96431430f, 0.96328520f, 0.96224846f, 0.96120406f, 0.96015197f, 0.95909219f, 0.95802469f, + 0.95694946f, 0.95586649f, 0.95477576f, 0.95367726f, 0.95257097f, 0.95145688f, 0.95033498f, 0.94920527f, + 0.94806772f, 0.94692233f, 0.94576909f, 0.94460799f, 0.94343902f, 0.94226217f, 0.94107743f, 0.93988480f, + 0.93868427f, 0.93747583f, 0.93625947f, 0.93503520f, 0.93380299f, 0.93256285f, 0.93131476f, 0.93005873f, + 0.92879475f, 0.92752281f, 0.92624292f, 0.92495505f, 0.92365922f, 0.92235541f, 0.92104362f, 0.91972385f, + 0.91839609f, 0.91706034f, 0.91571660f, 0.91436487f, 0.91300513f, 0.91163740f, 0.91026166f, 0.90887792f, + 0.90748616f, 0.90608640f, 0.90467862f, 0.90326283f, 0.90183902f, 0.90040720f, 0.89896735f, 0.89751949f, + 0.89606360f, 0.89459969f, 0.89312776f, 0.89164780f, 0.89015982f, 0.88866382f, 0.88715979f, 0.88564773f, + 0.88412765f, 0.88259954f, 0.88106340f, 0.87951924f, 0.87796706f, 0.87640684f, 0.87483861f, 0.87326235f, + 0.87167807f, 0.87008576f, 0.86848544f, 0.86687709f, 0.86526073f, 0.86363635f, 0.86200395f, 0.86036353f, + 0.85871510f, 0.85705867f, 0.85539422f, 0.85372176f, 0.85204129f, 0.85035282f, 0.84865635f, 0.84695188f, + 0.84523941f, 0.84351895f, 0.84179049f, 0.84005404f, 0.83830960f, 0.83655718f, 0.83479677f, 0.83302839f, + 0.83125203f, 0.82946769f, 0.82767538f, 0.82587511f, 0.82406687f, 0.82225067f, 0.82042651f, 0.81859440f, + 0.81675434f, 0.81490633f, 0.81305038f, 0.81118649f, 0.80931466f, 0.80743490f, 0.80554721f, 0.80365160f, + 0.80174807f, 0.79983662f, 0.79791726f, 0.79599000f, 0.79405483f, 0.79211177f, 0.79016081f, 0.78820196f, + 0.78623522f, 0.78426061f, 0.78227812f, 0.78028777f, 0.77828954f, 0.77628346f, 0.77426952f, 0.77224773f, + 0.77021809f, 0.76818061f, 0.76613530f, 0.76408216f, 0.76202120f, 0.75995241f, 0.75787581f, 0.75579140f, + 0.75369919f, 0.75159918f, 0.74949138f, 0.74737580f, 0.74525243f, 0.74312128f, 0.74098237f, 0.73883570f, + 0.73668126f, 0.73451908f, 0.73234915f, 0.73017147f, 0.72798607f, 0.72579293f, 0.72359208f, 0.72138350f, + 0.71916722f, 0.71694323f, 0.71471154f, 0.71247217f, 0.71022510f, 0.70797036f, 0.70570794f, 0.70343786f, + 0.70116012f, 0.69887472f, 0.69658167f, 0.69428098f, 0.69197265f, 0.68965669f, 0.68733312f, 0.68500192f, + 0.68266311f, 0.68031670f, 0.67796269f, 0.67560109f, 0.67323190f, 0.67085514f, 0.66847080f, 0.66607889f, + 0.66367943f, 0.66127241f, 0.65885784f, 0.65643574f, 0.65400609f, 0.65156892f, 0.64912423f, 0.64667201f, + 0.64421229f, 0.64174507f, 0.63927035f, 0.63678813f, 0.63429843f, 0.63180125f, 0.62929660f, 0.62678447f, + 0.62426489f, 0.62173785f, 0.61920336f, 0.61666143f, 0.61411206f, 0.61155525f, 0.60899102f, 0.60641937f, + 0.60384030f, 0.60125382f, 0.59865994f, 0.59605866f, 0.59344998f, 0.59083391f, 0.58821046f, 0.58557964f, + 0.58294143f, 0.58029586f, 0.57764293f, 0.57498264f, 0.57231499f, 0.56963999f, 0.56695765f, 0.56426797f, + 0.56157095f, 0.55886660f, 0.55615492f, 0.55343592f, 0.55070960f, 0.54797596f, 0.54523501f, 0.54248675f, + 0.53973118f, 0.53696832f, 0.53419815f, 0.53142069f, 0.52863593f, 0.52584388f, 0.52304455f, 0.52023793f, + 0.51742403f, 0.51460284f, 0.51177438f, 0.50893864f, 0.50609563f, 0.50324534f, 0.50038778f, 0.49752294f, + 0.49465084f, 0.49177147f, 0.48888482f, 0.48599091f, 0.48308973f, 0.48018128f, 0.47726556f, 0.47434256f, + 0.47141230f, 0.46847477f, 0.46552996f, 0.46257788f, 0.45961852f, 0.45665188f, 0.45367796f, 0.45069676f, + 0.44770827f, 0.44471249f, 0.44170942f, 0.43869905f, 0.43568138f, 0.43265640f, 0.42962411f, 0.42658451f, + 0.42353758f, 0.42048333f, 0.41742175f, 0.41435283f, 0.41127656f, 0.40819293f, 0.40510195f, 0.40200359f, + 0.39889786f, 0.39578474f, 0.39266422f, 0.38953629f, 0.38640095f, 0.38325818f, 0.38010797f, 0.37695031f, + 0.37378519f, 0.37061258f, 0.36743249f, 0.36424489f, 0.36104978f, 0.35784713f, 0.35463693f, 0.35141916f, + 0.34819381f, 0.34496085f, 0.34172027f, 0.33847206f, 0.33521618f, 0.33195262f, 0.32868136f, 0.32540237f, + 0.32211564f, 0.31882113f, 0.31551882f, 0.31220868f, 0.30889070f, 0.30556483f, 0.30223106f, 0.29888935f, + 0.29553966f, 0.29218198f, 0.28881626f, 0.28544246f, 0.28206056f, 0.27867052f, 0.27527229f, 0.27186583f, + 0.26845112f, 0.26502809f, 0.26159670f, 0.25815692f, 0.25470869f, 0.25125196f, 0.24778667f, 0.24431278f, + 0.24083023f, 0.23733896f, 0.23383891f, 0.23033001f, 0.22681220f, 0.22328542f, 0.21974958f, 0.21620462f, + 0.21265047f, 0.20908703f, 0.20551423f, 0.20193197f, 0.19834018f, 0.19473875f, 0.19112758f, 0.18750657f, + 0.18387561f, 0.18023459f, 0.17658339f, 0.17292189f, 0.16924994f, 0.16556742f, 0.16187418f, 0.15817007f, + 0.15445492f, 0.15072857f, 0.14699084f, 0.14324154f, 0.13948047f, 0.13570741f, 0.13192214f, 0.12812442f, + 0.12431400f, 0.12049059f, 0.11665391f, 0.11280364f, 0.10893944f, 0.10506094f, 0.10116776f, 0.09725946f, + 0.09333558f, 0.08939561f, 0.08543899f, 0.08146510f, 0.07747327f, 0.07346273f, 0.06943264f, 0.06538204f, + 0.06130985f, 0.05721482f, 0.05309551f, 0.04895024f, 0.04477702f, 0.04057343f, 0.03633653f, 0.03206261f, + 0.02774685f, 0.02338280f, 0.01896129f, 0.01446831f, 0.00987977f, 0.00514389f +}; + + +const float short_window_8kHz[80] = +{ + 0.01963369f, 0.05887080f, 0.09801714f, 0.13701234f, 0.17579628f, 0.21430915f, 0.25249158f, 0.29028468f, + 0.32763018f, 0.36447050f, 0.40074883f, 0.43640924f, 0.47139674f, 0.50565737f, 0.53913832f, 0.57178796f, + 0.60355594f, 0.63439328f, 0.66425244f, 0.69308736f, 0.72085360f, 0.74750833f, 0.77301045f, 0.79732065f, + 0.82040144f, 0.84221723f, 0.86273439f, 0.88192126f, 0.89974828f, 0.91618796f, 0.93121493f, 0.94480605f, + 0.95694034f, 0.96759909f, 0.97676588f, 0.98442657f, 0.99056934f, 0.99518473f, 0.99826561f, 0.99980724f, + 0.99980724f, 0.99826561f, 0.99518473f, 0.99056934f, 0.98442657f, 0.97676588f, 0.96759909f, 0.95694034f, + 0.94480605f, 0.93121493f, 0.91618796f, 0.89974828f, 0.88192126f, 0.86273439f, 0.84221723f, 0.82040144f, + 0.79732065f, 0.77301045f, 0.74750833f, 0.72085360f, 0.69308736f, 0.66425244f, 0.63439328f, 0.60355594f, + 0.57178796f, 0.53913832f, 0.50565737f, 0.47139674f, 0.43640924f, 0.40074883f, 0.36447050f, 0.32763018f, + 0.29028468f, 0.25249158f, 0.21430915f, 0.17579628f, 0.13701234f, 0.09801714f, 0.05887080f, 0.01963369f +}; + +const float short_window_16kHz[160] = +{ + 0.00981732f, 0.02944817f, 0.04906767f, 0.06866826f, + 0.08824237f, 0.10778246f, 0.12728100f, 0.14673047f, + 0.16612338f, 0.18545224f, 0.20470960f, 0.22388805f, + 0.24298018f, 0.26197864f, 0.28087610f, 0.29966528f, + 0.31833893f, 0.33688985f, 0.35531090f, 0.37359497f, + 0.39173501f, 0.40972403f, 0.42755509f, 0.44522133f, + 0.46271592f, 0.48003212f, 0.49716327f, 0.51410274f, + 0.53084403f, 0.54738066f, 0.56370626f, 0.57981455f, + 0.59569930f, 0.61135441f, 0.62677382f, 0.64195160f, + 0.65688190f, 0.67155895f, 0.68597711f, 0.70013081f, + 0.71401460f, 0.72762312f, 0.74095113f, 0.75399348f, + 0.76674516f, 0.77920124f, 0.79135693f, 0.80320753f, + 0.81474848f, 0.82597533f, 0.83688375f, 0.84746954f, + 0.85772861f, 0.86765701f, 0.87725091f, 0.88650662f, + 0.89542056f, 0.90398929f, 0.91220953f, 0.92007808f, + 0.92759194f, 0.93474818f, 0.94154407f, 0.94797697f, + 0.95404440f, 0.95974404f, 0.96507367f, 0.97003125f, + 0.97461487f, 0.97882275f, 0.98265328f, 0.98610498f, + 0.98917651f, 0.99186670f, 0.99417450f, 0.99609903f, + 0.99763955f, 0.99879546f, 0.99956631f, 0.99995181f, + 0.99995181f, 0.99956631f, 0.99879546f, 0.99763955f, + 0.99609903f, 0.99417450f, 0.99186670f, 0.98917651f, + 0.98610498f, 0.98265328f, 0.97882275f, 0.97461487f, + 0.97003125f, 0.96507367f, 0.95974404f, 0.95404440f, + 0.94797697f, 0.94154407f, 0.93474818f, 0.92759194f, + 0.92007808f, 0.91220953f, 0.90398929f, 0.89542056f, + 0.88650662f, 0.87725091f, 0.86765701f, 0.85772861f, + 0.84746954f, 0.83688375f, 0.82597533f, 0.81474848f, + 0.80320753f, 0.79135693f, 0.77920124f, 0.76674516f, + 0.75399348f, 0.74095113f, 0.72762312f, 0.71401460f, + 0.70013081f, 0.68597711f, 0.67155895f, 0.65688190f, + 0.64195160f, 0.62677382f, 0.61135441f, 0.59569930f, + 0.57981455f, 0.56370626f, 0.54738066f, 0.53084403f, + 0.51410274f, 0.49716327f, 0.48003212f, 0.46271592f, + 0.44522133f, 0.42755509f, 0.40972403f, 0.39173501f, + 0.37359497f, 0.35531090f, 0.33688985f, 0.31833893f, + 0.29966528f, 0.28087610f, 0.26197864f, 0.24298018f, + 0.22388805f, 0.20470960f, 0.18545224f, 0.16612338f, + 0.14673047f, 0.12728100f, 0.10778246f, 0.08824237f, + 0.06866826f, 0.04906767f, 0.02944817f, 0.00981732f +}; + +const float short_window_32kHz[320] = +{ + 0.00490872f, 0.01472568f, 0.02454123f, 0.03435441f, 0.04416428f, 0.05396989f, + 0.06377030f, 0.07356456f, 0.08335174f, 0.09313088f, 0.10290104f, 0.11266129f, + 0.12241068f, 0.13214826f, 0.14187312f, 0.15158430f, 0.16128086f, 0.17096189f, + 0.18062644f, 0.19027357f, 0.19990237f, 0.20951190f, 0.21910124f, 0.22866946f, + 0.23821564f, 0.24773886f, 0.25723821f, 0.26671276f, 0.27616160f, 0.28558383f, + 0.29497853f, 0.30434480f, 0.31368174f, 0.32298845f, 0.33226402f, 0.34150757f, + 0.35071820f, 0.35989504f, 0.36903718f, 0.37814376f, 0.38721389f, 0.39624670f, + 0.40524131f, 0.41419687f, 0.42311251f, 0.43198737f, 0.44082059f, 0.44961133f, + 0.45835873f, 0.46706195f, 0.47572016f, 0.48433252f, 0.49289819f, 0.50141636f, + 0.50988620f, 0.51830690f, 0.52667764f, 0.53499762f, 0.54326604f, 0.55148209f, + 0.55964499f, 0.56775395f, 0.57580819f, 0.58380693f, 0.59174941f, 0.59963485f, + 0.60746249f, 0.61523159f, 0.62294139f, 0.63059115f, 0.63818013f, 0.64570760f, + 0.65317284f, 0.66057513f, 0.66791374f, 0.67518798f, 0.68239715f, 0.68954054f, + 0.69661748f, 0.70362727f, 0.71056925f, 0.71744274f, 0.72424708f, 0.73098162f, + 0.73764570f, 0.74423869f, 0.75075995f, 0.75720885f, 0.76358476f, 0.76988708f, + 0.77611520f, 0.78226851f, 0.78834643f, 0.79434836f, 0.80027373f, 0.80612197f, + 0.81189252f, 0.81758481f, 0.82319831f, 0.82873246f, 0.83418673f, 0.83956061f, + 0.84485357f, 0.85006509f, 0.85519469f, 0.86024186f, 0.86520612f, 0.87008699f, + 0.87488400f, 0.87959669f, 0.88422459f, 0.88876728f, 0.89322430f, 0.89759523f, + 0.90187965f, 0.90607715f, 0.91018732f, 0.91420976f, 0.91814408f, 0.92198992f, + 0.92574689f, 0.92941463f, 0.93299280f, 0.93648104f, 0.93987902f, 0.94318642f, + 0.94640291f, 0.94952818f, 0.95256194f, 0.95550388f, 0.95835373f, 0.96111122f, + 0.96377607f, 0.96634802f, 0.96882685f, 0.97121229f, 0.97350412f, 0.97570213f, + 0.97780610f, 0.97981582f, 0.98173111f, 0.98355177f, 0.98527764f, 0.98690855f, + 0.98844433f, 0.98988485f, 0.99122996f, 0.99247953f, 0.99363345f, 0.99469160f, + 0.99565388f, 0.99652019f, 0.99729046f, 0.99796460f, 0.99854256f, 0.99902428f, + 0.99940971f, 0.99969882f, 0.99989157f, 0.99998795f, 0.99998795f, 0.99989157f, + 0.99969882f, 0.99940971f, 0.99902428f, 0.99854256f, 0.99796460f, 0.99729046f, + 0.99652019f, 0.99565388f, 0.99469160f, 0.99363345f, 0.99247953f, 0.99122996f, + 0.98988485f, 0.98844433f, 0.98690855f, 0.98527764f, 0.98355177f, 0.98173111f, + 0.97981582f, 0.97780610f, 0.97570213f, 0.97350412f, 0.97121229f, 0.96882685f, + 0.96634802f, 0.96377607f, 0.96111122f, 0.95835373f, 0.95550388f, 0.95256194f, + 0.94952818f, 0.94640291f, 0.94318642f, 0.93987902f, 0.93648104f, 0.93299280f, + 0.92941463f, 0.92574689f, 0.92198992f, 0.91814408f, 0.91420976f, 0.91018732f, + 0.90607715f, 0.90187965f, 0.89759523f, 0.89322430f, 0.88876728f, 0.88422459f, + 0.87959669f, 0.87488400f, 0.87008699f, 0.86520612f, 0.86024186f, 0.85519469f, + 0.85006509f, 0.84485357f, 0.83956061f, 0.83418673f, 0.82873246f, 0.82319831f, + 0.81758481f, 0.81189252f, 0.80612197f, 0.80027373f, 0.79434836f, 0.78834643f, + 0.78226851f, 0.77611520f, 0.76988708f, 0.76358476f, 0.75720885f, 0.75075995f, + 0.74423869f, 0.73764570f, 0.73098162f, 0.72424708f, 0.71744274f, 0.71056925f, + 0.70362727f, 0.69661748f, 0.68954054f, 0.68239715f, 0.67518798f, 0.66791374f, + 0.66057513f, 0.65317284f, 0.64570760f, 0.63818013f, 0.63059115f, 0.62294139f, + 0.61523159f, 0.60746249f, 0.59963485f, 0.59174941f, 0.58380693f, 0.57580819f, + 0.56775395f, 0.55964499f, 0.55148209f, 0.54326604f, 0.53499762f, 0.52667764f, + 0.51830690f, 0.50988620f, 0.50141636f, 0.49289819f, 0.48433252f, 0.47572016f, + 0.46706195f, 0.45835873f, 0.44961133f, 0.44082059f, 0.43198737f, 0.42311251f, + 0.41419687f, 0.40524131f, 0.39624670f, 0.38721389f, 0.37814376f, 0.36903718f, + 0.35989504f, 0.35071820f, 0.34150757f, 0.33226402f, 0.32298845f, 0.31368174f, + 0.30434480f, 0.29497853f, 0.28558383f, 0.27616160f, 0.26671276f, 0.25723821f, + 0.24773886f, 0.23821564f, 0.22866946f, 0.21910124f, 0.20951190f, 0.19990237f, + 0.19027357f, 0.18062644f, 0.17096189f, 0.16128086f, 0.15158430f, 0.14187312f, + 0.13214826f, 0.12241068f, 0.11266129f, 0.10290104f, 0.09313088f, 0.08335174f, + 0.07356456f, 0.06377030f, 0.05396989f, 0.04416428f, 0.03435441f, 0.02454123f, + 0.01472568f, 0.00490872f +}; + +const float short_window_48kHz[480] = +{ + 0.00326538f, 0.00982666f, 0.0163574f, 0.0229187f, 0.0294495f, 0.0359802f, + 0.0425415f, 0.0490723f, 0.055603f, 0.0621338f, 0.0686646f, 0.0751953f, + 0.0817261f, 0.0882568f, 0.0947571f, 0.101288f, 0.107788f, 0.114288f, + 0.120789f, 0.127289f, 0.133759f, 0.140259f, 0.146729f, 0.153198f, + 0.159668f, 0.166138f, 0.172577f, 0.179016f, 0.185455f, 0.191895f, + 0.198303f, 0.204712f, 0.211121f, 0.217499f, 0.223877f, 0.230255f, + 0.236633f, 0.242981f, 0.249329f, 0.255646f, 0.261993f, 0.26828f, + 0.274597f, 0.280884f, 0.28714f, 0.293427f, 0.299652f, 0.305908f, + 0.312134f, 0.318329f, 0.324524f, 0.330719f, 0.336884f, 0.343048f, + 0.349182f, 0.355316f, 0.36142f, 0.367523f, 0.373596f, 0.379669f, + 0.385712f, 0.391724f, 0.397736f, 0.403748f, 0.409729f, 0.41568f, + 0.421631f, 0.427551f, 0.433472f, 0.439362f, 0.445221f, 0.45108f, + 0.456909f, 0.462708f, 0.468506f, 0.474274f, 0.480042f, 0.485748f, + 0.491486f, 0.497162f, 0.502838f, 0.508484f, 0.514099f, 0.519714f, + 0.525299f, 0.530853f, 0.536377f, 0.541901f, 0.547394f, 0.552856f, + 0.558289f, 0.563721f, 0.569092f, 0.574463f, 0.579803f, 0.585144f, + 0.590424f, 0.595703f, 0.600952f, 0.606171f, 0.611359f, 0.616516f, + 0.621674f, 0.62677f, 0.631866f, 0.636932f, 0.641937f, 0.646942f, + 0.651947f, 0.656891f, 0.661804f, 0.666687f, 0.67157f, 0.676392f, + 0.681213f, 0.685974f, 0.690735f, 0.695435f, 0.700134f, 0.704803f, + 0.709412f, 0.71402f, 0.718567f, 0.723114f, 0.727631f, 0.732086f, + 0.736542f, 0.740936f, 0.745331f, 0.749664f, 0.753998f, 0.75827f, + 0.762512f, 0.766754f, 0.770935f, 0.775085f, 0.779205f, 0.783295f, + 0.787354f, 0.791351f, 0.795349f, 0.799286f, 0.803223f, 0.807098f, + 0.810944f, 0.814758f, 0.818512f, 0.822266f, 0.825989f, 0.829651f, + 0.833282f, 0.836884f, 0.840454f, 0.843964f, 0.847473f, 0.850922f, + 0.85434f, 0.857727f, 0.861084f, 0.86438f, 0.867645f, 0.87088f, + 0.874084f, 0.877258f, 0.880371f, 0.883453f, 0.886505f, 0.889526f, + 0.892487f, 0.895416f, 0.898315f, 0.901184f, 0.903992f, 0.906769f, + 0.909515f, 0.912201f, 0.914886f, 0.91748f, 0.920074f, 0.922607f, + 0.92514f, 0.927582f, 0.930023f, 0.932404f, 0.934753f, 0.937042f, + 0.939331f, 0.941559f, 0.943726f, 0.945862f, 0.947968f, 0.950043f, + 0.952057f, 0.954041f, 0.955994f, 0.957886f, 0.959747f, 0.961548f, + 0.963348f, 0.965088f, 0.966766f, 0.968414f, 0.970032f, 0.971588f, + 0.973114f, 0.974609f, 0.976074f, 0.977448f, 0.978821f, 0.980133f, + 0.981415f, 0.982666f, 0.983856f, 0.984985f, 0.986115f, 0.987183f, + 0.98819f, 0.989166f, 0.990112f, 0.990997f, 0.991852f, 0.992676f, + 0.993439f, 0.994171f, 0.994873f, 0.995514f, 0.996094f, 0.996643f, + 0.997162f, 0.99765f, 0.998077f, 0.998444f, 0.99881f, 0.999084f, + 0.999359f, 0.999573f, 0.999725f, 0.999878f, 0.999939f, 0.999969f, + 0.999969f, 0.999939f, 0.999878f, 0.999725f, 0.999573f, 0.999359f, + 0.999084f, 0.99881f, 0.998444f, 0.998077f, 0.99765f, 0.997162f, + 0.996643f, 0.996094f, 0.995514f, 0.994873f, 0.994171f, 0.993439f, + 0.992676f, 0.991852f, 0.990997f, 0.990112f, 0.989166f, 0.98819f, + 0.987183f, 0.986115f, 0.984985f, 0.983856f, 0.982666f, 0.981415f, + 0.980133f, 0.978821f, 0.977448f, 0.976074f, 0.974609f, 0.973114f, + 0.971588f, 0.970032f, 0.968414f, 0.966766f, 0.965088f, 0.963348f, + 0.961548f, 0.959747f, 0.957886f, 0.955994f, 0.954041f, 0.952057f, + 0.950043f, 0.947968f, 0.945862f, 0.943726f, 0.941559f, 0.939331f, + 0.937042f, 0.934753f, 0.932404f, 0.930023f, 0.927582f, 0.92514f, + 0.922607f, 0.920074f, 0.91748f, 0.914886f, 0.912201f, 0.909515f, + 0.906769f, 0.903992f, 0.901184f, 0.898315f, 0.895416f, 0.892487f, + 0.889526f, 0.886505f, 0.883453f, 0.880371f, 0.877258f, 0.874084f, + 0.87088f, 0.867645f, 0.86438f, 0.861084f, 0.857727f, 0.85434f, + 0.850922f, 0.847473f, 0.843964f, 0.840454f, 0.836884f, 0.833282f, + 0.829651f, 0.825989f, 0.822266f, 0.818512f, 0.814758f, 0.810944f, + 0.807098f, 0.803223f, 0.799286f, 0.795349f, 0.791351f, 0.787354f, + 0.783295f, 0.779205f, 0.775085f, 0.770935f, 0.766754f, 0.762512f, + 0.75827f, 0.753998f, 0.749664f, 0.745331f, 0.740936f, 0.736542f, + 0.732086f, 0.727631f, 0.723114f, 0.718567f, 0.71402f, 0.709412f, + 0.704803f, 0.700134f, 0.695435f, 0.690735f, 0.685974f, 0.681213f, + 0.676392f, 0.67157f, 0.666687f, 0.661804f, 0.656891f, 0.651947f, + 0.646942f, 0.641937f, 0.636932f, 0.631866f, 0.62677f, 0.621674f, + 0.616516f, 0.611359f, 0.606171f, 0.600952f, 0.595703f, 0.590424f, + 0.585144f, 0.579803f, 0.574463f, 0.569092f, 0.563721f, 0.558289f, + 0.552856f, 0.547394f, 0.541901f, 0.536377f, 0.530853f, 0.525299f, + 0.519714f, 0.514099f, 0.508484f, 0.502838f, 0.497162f, 0.491486f, + 0.485748f, 0.480042f, 0.474274f, 0.468506f, 0.462708f, 0.456909f, + 0.45108f, 0.445221f, 0.439362f, 0.433472f, 0.427551f, 0.421631f, + 0.41568f, 0.409729f, 0.403748f, 0.397736f, 0.391724f, 0.385712f, + 0.379669f, 0.373596f, 0.367523f, 0.36142f, 0.355316f, 0.349182f, + 0.343048f, 0.336884f, 0.330719f, 0.324524f, 0.318329f, 0.312134f, + 0.305908f, 0.299652f, 0.293427f, 0.28714f, 0.280884f, 0.274597f, + 0.26828f, 0.261993f, 0.255646f, 0.249329f, 0.242981f, 0.236633f, + 0.230255f, 0.223877f, 0.217499f, 0.211121f, 0.204712f, 0.198303f, + 0.191895f, 0.185455f, 0.179016f, 0.172577f, 0.166138f, 0.159668f, + 0.153198f, 0.146729f, 0.140259f, 0.133759f, 0.127289f, 0.120789f, + 0.114288f, 0.107788f, 0.101288f, 0.0947571f, 0.0882568f, 0.0817261f, + 0.0751953f, 0.0686646f, 0.0621338f, 0.055603f, 0.0490723f, 0.0425415f, + 0.0359802f, 0.0294495f, 0.0229187f, 0.0163574f, 0.00982666f, 0.00326538f +}; +const short subf_norm_groups[4][11] = +{ + {0,1,8,9,16,20,24,28,32,36,40}, + {2,3,10,11,17,21,25,29,33,37,41}, + {4,5,12,13,18,22,26,30,34,38,42}, + {6,7,14,15,19,23,27,31,35,39,43} +}; + +const float gain_att[MAX_P_ATT] = +{ + 0.4794745f, 0.5910453f, 0.6647078f, 0.7245839f, 0.7598486f, 0.7912783f, 0.8165831f, 0.8396713f, + 0.8562786f, 0.8716393f, 0.8848335f, 0.8971617f, 0.9061614f, 0.9146075f, 0.9220175f, 0.9290045f, + 0.9344148f, 0.9395265f, 0.9440797f, 0.9484073f, 0.9518549f, 0.9551361f, 0.9581067f, 0.9609474f, + 0.9632704f, 0.9654923f, 0.9675346f, 0.9694900f, 0.9711209f, 0.9726879f, 0.9741332f, 0.9755263f, + 0.9767067f, 0.9778463f, 0.9789108f, 0.9799438f, 0.9808353f, 0.9816967f, 0.9825032f, 0.9832868f +}; + +const Word16 stab_trans_fx[10] = /* Q15 */ +{ + 16384, 11381, 7232, 4292, 2433, + 1341, 728, 391, 209, 112 +}; +const float stab_trans[L_STAB_TBL] = +{ + 0.500000f, 0.347332f, 0.220704f, 0.130976f, 0.074252f, + 0.040937f, 0.022211f, 0.011944f, 0.006392f, 0.003412f +}; + +const float env_stab_tp[2][2] = +{ + {0.999f, 0.5f}, + {0.001f, 0.5f} +}; + +const float att_step[NB_G] = { 4.0000000f, 2.0000000f, 1.3333333f, 1.0000000f}; + +const Word32 table_logcum_fx[563] = +{ + 0, 0, 0, 65536, 169408, 300480, 452650, 622058, 806041, + 1002649, 1210393, 1428099, 1654816, 1889761, 2132272, 2381791, 2637833, + 2899977, 3167853, 3441134, 3719526, 4002767, 4290623, 4582876, 4879332, + 5179812, 5484152, 5792200, 6103816, 6418871, 6737244, 7058822, 7383500, + 7711180, 8041769, 8375181, 8711333, 9050150, 9391557, 9735485, 10081869, + 10430647, 10781759, 11135150, 11490766, 11848556, 12208469, 12570461, 12934487, + 13300503, 13668469, 14038345, 14410092, 14783676, 15159061, 15536214, 15915101, + 16295692, 16677956, 17061866, 17447390, 17834504, 18223180, 18613394, 19005122, + 19398338, 19793020, 20189146, 20586692, 20985640, 21385968, 21787658, 22190686, + 22595040, 23000696, 23407638, 23815850, 24225314, 24636014, 25047934, 25461060, + 25875374, 26290862, 26707510, 27125304, 27544232, 27964278, 28385428, 28807674, + 29231000, 29655392, 30080844, 30507338, 30934866, 31363416, 31792978, 32223540, + 32655092, 33087624, 33521126, 33955588, 34391000, 34827352, 35264636, 35702840, + 36141960, 36581988, 37022908, 37464716, 37907404, 38350964, 38795388, 39240668, + 39686792, 40133760, 40581560, 41030188, 41479632, 41929888, 42380948, 42832808, + 43285456, 43738892, 44193104, 44648088, 45103840, 45560348, 46017612, 46475624, + 46934376, 47393864, 47854080, 48315024, 48776684, 49239060, 49702144, 50165928, + 50630412, 51095588, 51561452, 52028000, 52495224, 52963124, 53431688, 53900916, + 54370808, 54841348, 55312540, 55784380, 56256856, 56729972, 57203720, 57678096, + 58153096, 58628716, 59104952, 59581800, 60059256, 60537316, 61015980, 61495236, + 61975084, 62455524, 62936548, 63418156, 63900340, 64383100, 64866428, 65350328, + 65834792, 66319816, 66805396, 67291536, 67778224, 68265456, 68753240, 69241560, + 69730424, 70219816, 70709744, 71200208, 71691192, 72182704, 72674736, 73167280, + 73660344, 74153920, 74648008, 75142600, 75637704, 76133296, 76629400, 77125992, + 77623080, 78120656, 78618728, 79117280, 79616320, 80115840, 80615832, 81116312, + 81617256, 82118680, 82620568, 83122920, 83625744, 84129024, 84632768, 85136968, + 85641624, 86146728, 86652288, 87158304, 87664760, 88171664, 88679008, 89186792, + 89695016, 90203680, 90712776, 91222304, 91732256, 92242648, 92753464, 93264704, + 93776368, 94288448, 94800952, 95313872, 95827208, 96340960, 96855120, 97369696, + 97884672, 98400064, 98915856, 99432048, 99948648, 100465640, 100983040, 101500832, + 102019016, 102537592, 103056568, 103575928, 104095672, 104615808, 105136328, 105657232, + 106178520, 106700184, 107222232, 107744656, 108267456, 108790632, 109314176, 109838096, + 110362384, 110887040, 111412064, 111937448, 112463208, 112989320, 113515800, 114042640, + 114569832, 115097392, 115625304, 116153568, 116682184, 117211160, 117740480, 118270152, + 118800168, 119330536, 119861248, 120392312, 120923712, 121455448, 121987536, 122519960, + 123052720, 123585816, 124119248, 124653016, 125187120, 125721552, 126256320, 126791416, + 127326840, 127862592, 128398664, 128935072, 129471800, 130008856, 130546224, 131083920, + 131621936, 132160272, 132698920, 133237888, 133777176, 134316768, 134856688, 135396912, + 135937440, 136478288, 137019440, 137560912, 138102688, 138644768, 139187152, 139729840, + 140272832, 140816128, 141359712, 141903616, 142447808, 142992304, 143537104, 144082192, + 144627568, 145173248, 145719232, 146265504, 146812064, 147358912, 147906048, 148453488, + 149001200, 149549216, 150097504, 150646096, 151194960, 151744112, 152293536, 152843264, + 153393264, 153943536, 154494096, 155044944, 155596064, 156147456, 156699120, 157251072, + 157803296, 158355792, 158908560, 159461616, 160014928, 160568512, 161122368, 161676496, + 162230896, 162785568, 163340496, 163895696, 164451168, 165006896, 165562896, 166119152, + 166675664, 167232448, 167789504, 168346816, 168904368, 169462208, 170020288, 170578624, + 171137232, 171696080, 172255200, 172814560, 173374192, 173934064, 174494192, 175054576, + 175615216, 176176096, 176737232, 177298608, 177860256, 178422128, 178984256, 179546640, + 180109264, 180672128, 181235248, 181798608, 182362208, 182926064, 183490144, 184054480, + 184619056, 185183872, 185748928, 186314224, 186879760, 187445520, 188011536, 188577776, + 189144272, 189710992, 190277936, 190845136, 191412560, 191980208, 192548112, 193116224, + 193684592, 194253168, 194821984, 195391040, 195960320, 196529824, 197099568, 197669520, + 198239712, 198810144, 199380784, 199951648, 200522752, 201094080, 201665616, 202237392, + 202809376, 203381600, 203954032, 204526688, 205099568, 205672672, 206246000, 206819536, + 207393296, 207967280, 208541472, 209115888, 209690528, 210265376, 210840432, 211415712, + 211991216, 212566912, 213142848, 213718976, 214295328, 214871888, 215448672, 216025664, + 216602864, 217180272, 217757888, 218335712, 218913760, 219492000, 220070464, 220649120, + 221228000, 221807072, 222386368, 222965856, 223545552, 224125456, 224705568, 225285872, + 225866400, 226447120, 227028032, 227609168, 228190496, 228772016, 229353760, 229935680, + 230517824, 231100160, 231682688, 232265424, 232848352, 233431472, 234014800, 234598336, + 235182048, 235765968, 236350080, 236934400, 237518896, 238103600, 238688496, 239273600, + 239858880, 240444352, 241030032, 241615888, 242201952, 242788192, 243374640, 243961264, + 244548096, 245135104, 245722304, 246309696, 246897280, 247485056, 248073008, 248661152, + 249249488, 249838016, 250426720, 251015616, 251604704, 252193968, 252783424, 253373056, + 253962880, 254552896, 255143088, 255733472, 256324032, 256914768, 257505696, 258096800, + 258688096, 259279568, 259871216, 260463056, 261055056, 261647264, 262239632, 262832192, + 263424928, 264017840, 264610928, 265204192, 265797632, 266391264, 266985072, 267579040, + 268173200, 268767520, 269362048, 269956736, 270551584, 271146624, 271741824, 272337216, + 272932768, 273528480, 274124384, 274720480, 275316704, 275913120, 276509728, 277106496, + 277703424, 278300544, 278897824, 279495264, 280092896, 280690688, 281288640, 281886752, + 282485056, 283083520 +}; +const Word32 pow_getbitsfrompulses_fx[16] = /*Q21 */ +{ + 2097152, 2190001, 2286961, 2388214, 2493948, 2604365, 2719671, 2840081, + 2965822, 3097129, 3234251, 3377442, 3526976, 3683128, 3846194, 4016480 +}; +const Word16 DDP_fx[4] = { 3, 0, 1, 2 }; + +const float DDP[4] = { 3.0f, 0.0f, 1.0f, 2.0f }; + + +const short step_tcq[8][STATES] = { {0,4}, {0,4}, {1,5}, {1,5}, {2,6}, {2,6}, {3,7}, {3,7} }; +const short denc[8][STATES] = { {0,2}, {2,0}, {1,3}, {3,1}, {2,0}, {0,2}, {3,1}, {1,3} }; /* enc trellis */ +const short ddec[8][STATES] = { {0,2}, {1,3}, {2,0}, {3,1}, {2,0}, {3,1}, {0,2}, {1,3} }; /* dec trellis */ + + +const short step_LSB[STATES_LSB][2] = { {0,1}, {2,3}, {0,1}, {2,3} }; +const short denc_LSB[STATES_LSB][2] = { {0,3}, {2,1}, {3,0}, {1,2} }; +const short dqnt_LSB[STATES_LSB][4] = { {0,8,1,8}, {0,8,1,8}, {8,0,8,1}, {8,0,8,1} }; + +const short dstep_LSB[4][2] = { {0,2}, {0,2}, {1,3}, {1,3} }; +const short ddec_LSB[4][2] = { {0,3}, {3,0}, {2,1}, {1,2} }; + + +const short nextstate[STATES][2] = {{0, 1}, {2, 3}, {4, 5}, {6, 7}, {0, 1}, {2, 3}, {4, 5}, {6, 7}};/*current state points to next two states */ + +/*------------------------------------------------------------------------------* + * PVQ tables + *------------------------------------------------------------------------------*/ + +const short fine_gain_bits[8] = {0, 0, 0, 1, 2, 2, 4, 5}; +const float finegain_1[2] = {-0.7448924f, 0.7718827f}; +const float finegain_2[4] = {-1.0847910f, -0.3616628f, 0.3668007f, 1.1455675f}; +const float finegain_3[8] = {-1.0000000f, -0.7142857f, -0.4285714f, -0.1428571f, 0.1428571f, 0.4285714f, 0.7142857f, 1.0000000f}; +const float finegain_4[16] = {-1.3234321f, -1.1164439f, -0.9153915f, -0.7248241f, -0.5453916f, -0.3807825f, -0.2259278f, -0.0836715f, 0.0576803f, 0.1999166f, 0.3715899f, 0.5541582f, 0.7598588f, 0.9764980f, 1.2082281f, 1.4567725f}; +const float finegain_5[32] = {-1.3099370f, -1.1532731f, -0.9939113f, -0.8627403f, -0.7693628f, -0.6901322f, -0.6188556f, -0.5438313f, -0.4899869f, -0.4145289f, -0.3440915f, -0.2936875f, -0.2241453f, -0.1636186f, -0.1052746f, -0.0292431f, 0.0273763f, 0.0848355f, 0.1443042f, 0.2095194f, 0.2794882f, 0.3366661f, 0.4131591f, 0.4740591f, 0.5545165f, 0.6196313f, 0.6719442f, 0.7650533f, 0.9012053f, 1.0432675f, 1.2264170f, 1.5085750f}; +const float* const finegain[5] = { finegain_1, finegain_2, finegain_3, finegain_4, finegain_5 }; + +/* getk(16,8)+ maxqKIind=40 --> KMAX=127 needs support , 32bit- saturates at dim=6 + getK(21,9)+ maxqKInd=64 --> KMAX=512, needs support , 32bit saturates at dim=5 + getK(TBD,TBD)+ maxqKInd=TBD --> KMAX=1024, needs support , 32bit saturates at dim~=4 + getK(TBD,TBD)+ maxqKInd=TBD --> KMAX=32767, needs support, 32bit saturates at dim =3 +*/ +const unsigned char hBitsMinus1_N01[2] = {1, 7}; + +const unsigned char hBitsMinus1_N02[65]= +{ + 64, 15, 23, 28, 31, 34, 36, 38, 39, 41, 42, 43, 44, 45, 46, 47, + 47, 48, 49, 49, 50, 51, 52, 53, 54, 54, 55, 56, 57, 57, 58, 59, + 60, 61, 62, 63, 63, 64, 65, 65, 67, 68, 69, 69, 70, 71, 72, 72, + 73, 74, 75, 76, 77, 78, 79, 80, 80, 81, 82, 83, 84, 85, 86, 87, + 87 +}; + +const unsigned char hBitsMinus1_N03[65]= +{ + 64, 20, 33, 41, 48, 53, 57, 61, 64, 66, 69, 71, 73, 75, 76, 78, + 80, 81, 82, 83, 85, 86, 88, 90, 92, 93, 95, 96, 98, 99, 100, 102, + 104, 106, 108, 110, 111, 113, 114, 115, 118, 120, 122, 123, 125, 127, 128, 129, + 131, 133, 135, 137, 139, 141, 142, 144, 145, 146, 149, 151, 153, 155, 157, 158, + 160 +}; + +const unsigned char hBitsMinus1_N04[65]= +{ + 64, 23, 39, 51, 60, 67, 73, 79, 83, 87, 91, 94, 97, 100, 102, 105, + 107, 109, 111, 113, 115, 116, 119, 122, 125, 127, 130, 132, 134, 136, 138, 141, + 144, 147, 150, 152, 154, 156, 158, 160, 164, 167, 170, 173, 175, 177, 180, 182, + 184, 187, 190, 193, 196, 199, 201, 203, 205, 207, 211, 214, 217, 220, 222, 225, + 227 +}; + +const unsigned char hBitsMinus1_N05[54]= +{ + 53, 26, 45, 59, 70, 79, 87, 94, 100, 105, 110, 114, 118, 122, 125, 128, + 131, 134, 136, 139, 141, 144, 148, 152, 155, 158, 161, 164, 167, 170, 172, 176, + 181, 184, 188, 191, 194, 197, 200, 202, 207, 211, 215, 219, 222, 225, 228, 231, + 233, 238, 242, 246, 250, 253 +}; + +const unsigned char hBitsMinus1_N06[42]= +{ + 41, 28, 49, 65, 78, 89, 99, 107, 114, 120, 126, 132, 136, 141, 145, 149, + 153, 156, 159, 162, 165, 168, 173, 178, 183, 187, 191, 194, 198, 201, 204, 209, + 214, 219, 224, 228, 231, 235, 238, 241, 247, 253 +}; + +const unsigned char hBitsMinus1_N07[34]= +{ + 33, 30, 52, 70, 85, 98, 109, 118, 126, 134, 141, 147, 153, 158, 163, 168, + 172, 176, 180, 184, 188, 191, 197, 203, 208, 213, 218, 222, 226, 230, 233, 240, + 246, 252 +}; + +const unsigned char hBitsMinus1_N08[29]= +{ + 28, 31, 55, 75, 91, 105, 117, 128, 138, 146, 154, 161, 168, 174, 180, 185, + 190, 195, 200, 204, 208, 212, 219, 226, 232, 238, 243, 248, 253 +}; + +const unsigned char hBitsMinus1_N09[25]= +{ + 24, 33, 58, 79, 97, 112, 125, 137, 148, 157, 166, 174, 182, 189, 195, 201, + 207, 212, 217, 222, 227, 231, 240, 247, 254 +}; + +const unsigned char hBitsMinus1_N10[22]= +{ + 21, 34, 61, 83, 101, 118, 132, 145, 157, 167, 177, 186, 194, 202, 209, 216, + 222, 228, 234, 239, 245, 250 +}; + +const unsigned char hBitsMinus1_N11[19]= +{ + 18, 35, 63, 86, 106, 123, 139, 152, 165, 176, 187, 197, 206, 214, 222, 230, + 237, 243, 250 +}; + +const unsigned char hBitsMinus1_N12[17]= +{ + 16, 36, 65, 89, 110, 128, 144, 159, 173, 185, 196, 207, 217, 226, 234, 242, + 250 +}; + +const unsigned char hBitsMinus1_N13[16]= +{ + 15, 37, 67, 92, 113, 133, 150, 165, 180, 193, 205, 216, 227, 237, 246, 254, +}; + +const unsigned char hBitsMinus1_N14[14]= +{ + 13, 38, 68, 94, 117, 137, 155, 171, 186, 200, 213, 225, 236, 247 +}; + +const unsigned char hBitsMinus1_N15[13]= +{ + 12, 39, 70, 97, 120, 141, 160, 177, 193, 207, 221, 233, 245 +}; + +const unsigned char hBitsMinus1_N16[13]= +{ + 12, 39, 71, 99, 123, 144, 164, 182, 198, 214, 228, 241, 253 +}; + +const unsigned char hBitsMinus1_N17[12]= +{ + 11, 40, 73, 101, 126, 148, 168, 187, 204, 220, 234, 248 +}; + +const unsigned char hBitsMinus1_N18[12]= +{ + 11, 41, 74, 103, 128, 151, 172, 191, 209, 225, 241, 255 +}; + +const unsigned char hBitsMinus1_N19[11]= +{ + 10, 41, 75, 105, 131, 154, 176, 196, 214, 231, 247 +}; + +const unsigned char hBitsMinus1_N20[11]= +{ + 10, 42, 77, 107, 133, 157, 179, 200, 219, 236, 253 +}; + +const unsigned char hBitsMinus1_N21[10]= +{ + 9, 43, 78, 108, 135, 160, 183, 204, 223, 241 +}; + +const unsigned char hBitsMinus1_N22[10]= +{ + 9, 43, 79, 110, 138, 163, 186, 207, 227, 246 +}; + +const unsigned char hBitsMinus1_N23[10]= +{ + 9, 44, 80, 111, 140, 165, 189, 211, 231, 250 +}; + +const unsigned char hBitsMinus1_N24[10]= +{ + 9, 44, 81, 113, 142, 168, 192, 214, 235, 255 +}; + +const unsigned char hBitsMinus1_N25[9]= +{ + 8, 45, 82, 114, 143, 170, 195, 217, 239 +}; + +const unsigned char hBitsMinus1_N26[9]= +{ + 8, 45, 83, 116, 145, 172, 197, 221, 242 +}; + +const unsigned char hBitsMinus1_N27[9]= +{ + 8, 46, 84, 117, 147, 175, 200, 224, 246 +}; + +const unsigned char hBitsMinus1_N28[9]= +{ + 8, 46, 84, 118, 149, 177, 202, 227, 249 +}; +const unsigned char hBitsMinus1_N29[9]= +{ + 8, 46, 85, 119, 150, 179, 205, 229, 252 +}; +const unsigned char hBitsMinus1_N30[8]= +{ + 7, 47, 86, 121, 152, 181, 207, 232 +}; +const unsigned char hBitsMinus1_N31[8]= +{ + 7, 47, 87, 122, 153, 182, 209, 235 +}; +const unsigned char hBitsMinus1_N32[8]= +{ + 7, 47, 87, 123, 155, 184, 212, 237 +}; +const unsigned char hBitsMinus1_N33[8]= +{ + 7, 48, 88, 124, 156, 186, 214, 240 +}; +const unsigned char hBitsMinus1_N34[8]= +{ + 7, 48, 89, 125, 158, 188, 216, 242 +}; +const unsigned char hBitsMinus1_N35[8]= +{ + 7, 49, 90, 126, 159, 189, 218, 245 +}; +const unsigned char hBitsMinus1_N36[8]= +{ + 7, 49, 90, 127, 160, 191, 220, 247 +}; +const unsigned char hBitsMinus1_N37[8]= +{ + 7, 49, 91, 128, 162, 193, 222, 249 +}; +const unsigned char hBitsMinus1_N38[8]= +{ + 7, 49, 91, 129, 163, 194, 224, 251 +}; +const unsigned char hBitsMinus1_N39[8]= +{ + 7, 50, 92, 130, 164, 196, 225, 253 +}; +const unsigned char hBitsMinus1_N40[8]= +{ + 7, 50, 93, 131, 165, 197, 227, 255 +}; +const unsigned char hBitsMinus1_N41[7]= +{ + 6, 50, 93, 131, 166, 199, 229 +}; +const unsigned char hBitsMinus1_N42[7]= +{ + 6, 51, 94, 132, 167, 200, 230 +}; +const unsigned char hBitsMinus1_N43[7]= +{ + 6, 51, 94, 133, 168, 201, 232 +}; +const unsigned char hBitsMinus1_N44[7]= +{ + 6, 51, 95, 134, 170, 203, 234 +}; +const unsigned char hBitsMinus1_N45[7]= +{ + 6, 51, 95, 135, 171, 204, 235 +}; +const unsigned char hBitsMinus1_N46[7]= +{ + 6, 52, 96, 135, 172, 205, 237 +}; +const unsigned char hBitsMinus1_N47[7]= +{ + 6, 52, 96, 136, 173, 206, 238 +}; +const unsigned char hBitsMinus1_N48[7]= +{ + 6, 52, 97, 137, 174, 208, 240 +}; +const unsigned char hBitsMinus1_N49[7]= +{ + 6, 52, 97, 138, 175, 209, 241 +}; +const unsigned char hBitsMinus1_N50[7]= +{ + 6, 53, 98, 138, 175, 210, 243 +}; +const unsigned char hBitsMinus1_N51[7]= +{ + 6, 53, 98, 139, 176, 211, 244 +}; +const unsigned char hBitsMinus1_N52[7]= +{ + 6, 53, 99, 140, 177, 212, 245 +}; +const unsigned char hBitsMinus1_N53[7]= +{ + 6, 53, 99, 140, 178, 213, 247 +}; +const unsigned char hBitsMinus1_N54[7]= +{ + 6, 54, 100, 141, 179, 214, 248 +}; +const unsigned char hBitsMinus1_N55[7]= +{ + 6, 54, 100, 142, 180, 216, 249 +}; +const unsigned char hBitsMinus1_N56[7]= +{ + 6, 54, 100, 142, 181, 217, 250 +}; +const unsigned char hBitsMinus1_N57[7]= +{ + 6, 54, 101, 143, 181, 218, 252 +}; +const unsigned char hBitsMinus1_N58[7]= +{ + 6, 54, 101, 143, 182, 219, 253 +}; +const unsigned char hBitsMinus1_N59[7]= +{ + 6, 55, 102, 144, 183, 220, 254 +}; +const unsigned char hBitsMinus1_N60[7]= +{ + 6, 55, 102, 145, 184, 221, 255 +}; +const unsigned char hBitsMinus1_N61[6]= +{ + 5, 55, 102, 145, 185, 221 +}; +const unsigned char hBitsMinus1_N62[6]= +{ + 5, 55, 103, 146, 185, 222 +}; +const unsigned char hBitsMinus1_N63[6]= +{ + 5, 55, 103, 146, 186, 223 +}; +const unsigned char hBitsMinus1_N64[6]= +{ + 5, 55, 103, 147, 187, 224 +}; + +const short dsHighDiracsTab[PVQ_MAX_BAND_SIZE - DS_INDEX_LINEAR_END ] = +{ + 23, 25, 27, 29, 31, 33, 35, 37, 39, + 43, 47, 51, 55, 59, 63, 67, 71, 75, + 83, 91, 99, 107, 115, 123, 131, 139, 147, + 163, 179, 195, 211, 227, 243, 259, 275, 291, + 323, 355, 387, 419, 451, 483, 512 +}; + +const unsigned int intLimCDivInvDQ31[67+1] = +{ + 0x00000000, 0x80000000, 0x40000000, 0x2aaaaaab, 0x20000000, 0x1999999a, 0x15555556, 0x12492493, + 0x10000000, 0x0e38e38f, 0x0ccccccd, 0x0ba2e8bb, 0x0aaaaaab, 0x09d89d8a, 0x0924924a, 0x08888889, + 0x08000000, 0x07878788, 0x071c71c8, 0x06bca1b0, 0x06666667, 0x06186187, 0x05d1745e, 0x0590b217, + 0x05555556, 0x051eb852, 0x04ec4ec5, 0x04bda130, 0x04924925, 0x0469ee59, 0x04444445, 0x04210843, + 0x04000000, 0x03e0f83f, 0x03c3c3c4, 0x03a83a84, 0x038e38e4, 0x03759f23, 0x035e50d8, 0x03483484, + 0x03333334, 0x031f3832, 0x030c30c4, 0x02fa0be9, 0x02e8ba2f, 0x02d82d83, 0x02c8590c, 0x02b93106, + 0x02aaaaab, 0x029cbc15, 0x028f5c29, 0x02828283, 0x02762763, 0x026a43a0, 0x025ed098, 0x0253c826, + 0x02492493, 0x023ee090, 0x0234f72d, 0x022b63cc, 0x02222223, 0x02192e2a, 0x02108422, 0x02082083, + 0x02000000, 0x01f81f82, 0x01f07c20, 0x01e9131b +}; + +const unsigned char obtainEnergyQuantizerDensity_f[57] = +{ + 1, 1, 1, 1, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 4, 4, 4, + 4, 4, 4, 6, 6, 6, 6, 8, + 8, 8, 10,10,12,12,14,14, + 16,18,20,20,22,24,26,30, + 32,34,38,42,46,50,54,58, + 64,70,76,82,90,98,108,118, 128 +}; + + +/* (char)ceil(log2(hBitsN[N][0])) - 2) */ +unsigned char f_log2_n[ PVQ_MAX_BAND_SIZE + 1] = +{ + 0xff, 0xff, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, + 0x03, 0x03, 0x03, 0x03, 0x02, 0x02, 0x02, 0x02, + 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, + 0x02, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, + 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, + 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, + 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, + 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, + 0x01 +}; + +const unsigned char* const hBitsN[ PVQ_MAX_BAND_SIZE + 1 ]= +{ + f_log2_n/*N=0*/, hBitsMinus1_N01, hBitsMinus1_N02, hBitsMinus1_N03, hBitsMinus1_N04, + hBitsMinus1_N05, hBitsMinus1_N06, hBitsMinus1_N07, hBitsMinus1_N08, hBitsMinus1_N09, + hBitsMinus1_N10, hBitsMinus1_N11, hBitsMinus1_N12, hBitsMinus1_N13, hBitsMinus1_N14, + hBitsMinus1_N15, hBitsMinus1_N16, hBitsMinus1_N17, hBitsMinus1_N18, hBitsMinus1_N19, + hBitsMinus1_N20, hBitsMinus1_N21, hBitsMinus1_N22, hBitsMinus1_N23, hBitsMinus1_N24, + hBitsMinus1_N25, hBitsMinus1_N26, hBitsMinus1_N27, hBitsMinus1_N28, hBitsMinus1_N29, + hBitsMinus1_N30, hBitsMinus1_N31, hBitsMinus1_N32, hBitsMinus1_N33, hBitsMinus1_N34, + hBitsMinus1_N35, hBitsMinus1_N36, hBitsMinus1_N37, hBitsMinus1_N38, hBitsMinus1_N39, + hBitsMinus1_N40, hBitsMinus1_N41, hBitsMinus1_N42, hBitsMinus1_N43, hBitsMinus1_N44, + hBitsMinus1_N45, hBitsMinus1_N46, hBitsMinus1_N47, hBitsMinus1_N48, hBitsMinus1_N49, + hBitsMinus1_N50, hBitsMinus1_N51, hBitsMinus1_N52, hBitsMinus1_N53, hBitsMinus1_N54, + hBitsMinus1_N55, hBitsMinus1_N56, hBitsMinus1_N57, hBitsMinus1_N58, hBitsMinus1_N59, + hBitsMinus1_N60, hBitsMinus1_N61, hBitsMinus1_N62, hBitsMinus1_N63, hBitsMinus1_N64, +}; + +const short lim_neg_inv_tbl_fx[MAX_SPLITS + 1 ] = +{ + /* 1 = optimized inv_tbl_fx constant for div by 1, Q15 */ + /* 2-10 = negated inv_tbl_fx Q15*/ + 0, + -32768, -16384, -10923, -8192, -6554, + -5462, -4681, -4096, -3641, -3277 +}; + +const short fg_inv_tbl_fx [HQ_MAX_BAND_LEN/8 + 1 ] = +{ + /* i/8 , slice of inv_tbl_fx , Q15 */ + 0, + 4096, 2048, 1366, 1024, 820, 683, + 586, 512, 456, 410, 373, 342 +} ; + + +const unsigned int exactdivodd[ODD_DIV_SIZE] = +{ + /* exactdivodd[0]=1/1,exactdivodd[1]=1/3 , exactdivodd[n]=1/(2*n+1), exactdivodd[47]=1/95 ) */ + 1U, 2863311531U, 3435973837U, 3067833783U, 954437177U, 3123612579U, 3303820997U, 4008636143U, + 4042322161U, 678152731U, 1022611261U, 3921491879U, 3264175145U, 1749801491U, 1332920885U, 3186588639U, + 1041204193U, 2331553675U, 2437684141U, 2532929431U, 3247414297U, 799063683U, 2767867813U, 1736263375U, + 438261969U, 4210752251U, 2350076445U, 1483715975U, 3089362441U, 2693454067U, 3238827797U, 3204181951U, + 3237744577U, 128207979U, 2738819725U, 3811027319U, 3353604601U, 2519714147U, 1059797125U, 1631000239U, + 2014922929U, 724452315U, 4244438269U, 1875962727U, 4198451177U, 3539808211U, 1062196213U, 3571604383U +}; + +const short gain_cb_size[MAX_GAIN_BITS] = {2, 4, 8, 16, 32}; + +const short inner_frame_tbl[4] = {L_FRAME8k, L_FRAME16k, L_FRAME32k, L_FRAME48k}; /* corresponds to NB, WB, SWB, FB */ + +/*------------------------------------------------------------------------------* + * LR-MDCT tables + *------------------------------------------------------------------------------*/ + +/* subband width tables */ + +/* NB short win: 7200/8000/9600, 13200/16400/24400 */ +const short band_width_40_4_6_0_0_0[4] = { 6, 8, 11, 15 }; +const short band_width_40_5_6_0_0_0[5] = { 6, 7, 7, 9, 11 }; + +/* NB long win: 7200, 8000, 9600, 13200, 16400 */ +const short band_width_160_13_6_2_0_0[13] = { 6, 6, 6, 6, 7, 8, 9, 10, 13, 15, 19, 24, 31 }; +const short band_width_160_14_6_3_0_0[14] = { 6, 6, 6, 6, 6, 7, 8, 9, 10, 12, 15, 18, 22, 29 }; +const short band_width_160_17_6_3_0_0[17] = { 6, 6, 6, 6, 6, 6, 7, 7, 8, 8, 9, 10, 11, 13, 15, 17, 19 }; +const short band_width_160_18_6_4_0_0[18] = { 6, 6, 6, 6, 6, 6, 6, 7, 7, 8, 8, 9, 10, 11, 12, 14, 15, 17 }; + +/* WB short win: 13200/16400/24400 */ +const short band_width_80_7_6_0_0_0[7] = { 6, 7, 8, 10, 12, 16, 21 }; + +/* WB long win: 13200, 16400 */ +const short band_width_320_18_6_3_0_0[18] = { 6, 6, 6, 6, 6, 7, 7, 8, 10, 11, 13, 16, 19, 24, 30, 37, 47, 61 }; +const short band_width_320_20_6_3_0_0[20] = { 6, 6, 6, 6, 6, 6, 7, 8, 8, 9, 11, 12, 14, 17, 20, 23, 28, 34, 42, 51 }; + +/* SWB short win: 13200, 16400 */ +const short band_width_142_8_8_0_0_0[8] = {7,8,10,11,15,21,29,41}; +const short band_width_160_8_8_0_0_0[8] = { 8, 9, 11,13,17,23,32,47}; + +/* SWB long win: 13200, 16400 */ +const short band_width_568_22_6_2_0_0[22] = { 6, 6, 6, 6, 6, 6, 7, 8, 9, 10, 11, 13, 16, 19, 23, 28, 34, 42, 55, 68, 84, 105}; +const short band_width_640_24_6_4_0_0[24] = { 6, 6, 6, 6, 6, 6, 7,7,8,9,10,11,13,15,18,21,26,32,39,48,59, 74,92,115}; + +/* LR-MDCT: NB configuration tables */ +const Xcore_Config xcore_config_8kHz_007200bps_long = { 13, L_FRAME8k, band_width_160_13_6_2_0_0, 536870912L, 24576, 13107, 2, 2, 0, 0.0f, 0.40f, 0.13f, 1.2f, 0.32f }; +const Xcore_Config xcore_config_8kHz_008000bps_long = { 14, L_FRAME8k, band_width_160_14_6_3_0_0, 536870912L, 24576, 13107, 2, 2, 0, 0.0f, 0.40f, 0.13f, 1.2f, 0.32f }; +const Xcore_Config xcore_config_8kHz_013200bps_long = { 17, L_FRAME8k, band_width_160_17_6_3_0_0, 429496730L, 24576, 13107, 2, 4, 2, 12.0f, 0.40f, 0.13f, 1.2f, 0.32f }; +const Xcore_Config xcore_config_8kHz_016400bps_long = { 18, L_FRAME8k, band_width_160_18_6_4_0_0, 322122547L, 24576, 13107, 2, 2, 0, 0.0f, 0.40f, 0.13f, 1.2f, 0.32f }; + +const Xcore_Config xcore_config_8kHz_007200bps_short = { 4, L_FRAME8k / NUM_TIME_SWITCHING_BLOCKS, band_width_40_4_6_0_0_0, 966367642L, 24576, 13107, 2, 2, 0, 0.0f, 0.30f, 0.09f, 1.2f, 0.32f }; +const Xcore_Config xcore_config_8kHz_008000bps_short = { 4, L_FRAME8k / NUM_TIME_SWITCHING_BLOCKS, band_width_40_4_6_0_0_0, 1181116006L, 24576, 13107, 2, 4, 0, 0.0f, 0.30f, 0.09f, 1.2f, 0.32f }; +const Xcore_Config xcore_config_8kHz_013200bps_short = { 5, L_FRAME8k / NUM_TIME_SWITCHING_BLOCKS, band_width_40_5_6_0_0_0, 751619276L, 24576, 11469, 2, 4, 0, 0.0f, 0.70f, 0.11f, 1.2f, 0.32f }; +const Xcore_Config xcore_config_8kHz_016400bps_short = { 5, L_FRAME8k / NUM_TIME_SWITCHING_BLOCKS, band_width_40_5_6_0_0_0, 536870912L, 24576, 11469, 2, 6, 0, 0.0f, 0.90f, 0.11f, 1.2f, 0.32f }; + +/* LR-MDCT: WB configuration tables */ +const Xcore_Config xcore_config_16kHz_013200bps_long = { 18, L_FRAME16k, band_width_320_18_6_3_0_0, 429496730L, 24576, 13106, 2, 6, 3, 12.0f, 0.40f, 0.12f, 1.1f, 0.32f }; +const Xcore_Config xcore_config_16kHz_016400bps_long = { 20, L_FRAME16k, band_width_320_20_6_3_0_0, 429496730L, 24576, 13106, 2, 6, 3, 12.0f, 0.40f, 0.12f, 1.2f, 0.32f }; + +const Xcore_Config xcore_config_16kHz_013200bps_short = { 7, L_FRAME16k / NUM_TIME_SWITCHING_BLOCKS, band_width_80_7_6_0_0_0, 966367642L, 24576, 9830, 2, 4, 0, 0.0f, 0.30f, 0.13f, 1.1f, 0.32f }; +const Xcore_Config xcore_config_16kHz_016400bps_short = { 7, L_FRAME16k / NUM_TIME_SWITCHING_BLOCKS, band_width_80_7_6_0_0_0, 966367642L, 24576, 11468, 2, 8, 0, 0.0f, 0.30f, 0.13f, 1.2f, 0.32f }; + +/* LR-MDCT: SWB configuration tables */ +const Xcore_Config xcore_config_32kHz_013200bps_long = { 22, 568, band_width_568_22_6_2_0_0, 322122547L, 24576, 6554, 2, 4, 5, 14.0f, 0.40f, 0.13f, 1.2f, 0.26f }; +const Xcore_Config xcore_config_32kHz_016400bps_long = { 24, 640, band_width_640_24_6_4_0_0, 322122547L, 24576, 8192, 2, 4, 5, 14.0f, 0.40f, 0.13f, 1.2f, 0.26f }; +const Xcore_Config xcore_config_32kHz_013200bps_short = { 8, 568 / NUM_TIME_SWITCHING_BLOCKS, band_width_142_8_8_0_0_0, 1610612736L, 24576, 13107, 2, 4, 0, 0.0f, 0.50f, 0.11f, 1.2f, 0.48f }; +const Xcore_Config xcore_config_32kHz_016400bps_short = { 8, 640 / NUM_TIME_SWITCHING_BLOCKS, band_width_160_8_8_0_0_0, 644245094L, 24576, 8192, 2, 4, 0, 0.0f, 0.30f, 0.13f, 1.2f, 0.32f }; + +/* bandwidths */ +const short Nb[ NB_SFM] = +{ + 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 16, 16, 16, 16, + 16, 16, 16, 16, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, + 32, 32, 32, 32, 32, 32, 32, 32 +}; + +/* log2(Nb) to calculate minimum bits for one pulse in PVQ */ +const short LNb[ NB_SFM] = +{ + 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, + 4, 4, 4, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, + 5, 5 +}; + + +/*------------------------------------------------------------------------------* + * GSC tables + *------------------------------------------------------------------------------*/ + +const short gsc_sfm_start[MBANDS_GN] = {0, 16, 32, 48, 64, 80, 96, 112, 128, 144, 160, 176, 192, 208, 224, 240}; + +const short gsc_sfm_end[MBANDS_GN] = {16, 32, 48, 64, 80, 96, 112, 128, 144, 160, 176, 192, 208, 224, 240, 256}; + +const short gsc_sfm_size[MBANDS_GN] = {16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16}; + +const float sm_table[] = +{ + 1.0f, 0.9804f, 0.9607f, 0.9411f, 0.9215f, 0.902f, 0.8825f, 0.863f, + 0.8436f, 0.8242f, 0.8049f, 0.7857f, 0.7666f, 0.7475f, 0.7286f, 0.7097f, 0.691f, 0.6724f, + 0.6539f, 0.6355f, 0.6173f, 0.5993f, 0.5813f, 0.5636f, 0.546f, 0.5286f, 0.5114f, 0.4943f, + 0.4775f, 0.4609f, 0.4444f, 0.4282f, 0.4122f, 0.3964f, 0.3809f, 0.3656f, 0.3506f, 0.3357f, + 0.3212f, 0.3069f, 0.2929f, 0.2791f, 0.2657f, 0.2525f, 0.2396f, 0.227f, 0.2147f, 0.2027f, + 0.191f, 0.1796f, 0.1685f, 0.1578f, 0.1474f, 0.1373f, 0.1275f, 0.1181f, 0.109f, 0.1003f, + 0.0919f, 0.0838f, 0.0761f, 0.0688f, 0.0618f, 0.0552f, 0.0489f, 0.0431f, 0.0375f, 0.0324f, + 0.0276f, 0.0232f, 0.0192f, 0.0156f, 0.0123f, 0.0094f, 0.0069f, 0.0048f, 0.0031f, 0.0017f, + 0.0008f, 0.0002f +}; + +const short GSC_freq_bits[] = +{ + 21, 66, -6, 25, 15, 11, 10, 5, 0, 0, 5, 4, 0, 0, 4, 0, 0, /* ACELP_7k20*/ + 21, 74, -4, 26, 16, 12, 11, 9, 0, 0, 4, 4, 1, 1, 3, 0, 0, /* ACELP_8k00*/ + 26, 96, -4, 28, 18, 13, 12,10,10, 5, 4, 4, 1, 0, 1, 3, 4, /* ACELP_11k60*/ + 26, 96, -4, 28, 18, 13, 12,10,10, 5, 4, 4, 1, 0, 1, 3, 4, /* ACELP_12k15*/ + 26, 96, -4, 28, 18, 13, 12,10,10, 5, 4, 4, 1, 0, 1, 3, 4, /* ACELP_12k85*/ + 31, 96, -4, 28, 18, 13, 12,10,10, 5, 4, 4, 1, 0, 1, 3, 4, /* ACELP_13k20*/ +}; + +const float mfreq_loc[] = { 175.0f, 375.0f, 775.0f, 1175.0f, 1575.0f, 1975.0f, 2375.0f, 2775.0f, 3175.0f, 3575.0f, 3975.0f, + 4375.0f, 4775.0f, 5175.0f, 5575.0f, 6375.0f, 7175.0f, 7975.0f + }; +const short mfreq_bindiv_loc[] = { 8, 8, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 32, 32, 32 }; +const float mean_gp[] = { 0.5853f }; + +const float dic_gp[] = +{ + -0.5847f, + -0.4695f, + -0.3897f, + -0.2731f, + -0.1986f, + -0.1244f, + -0.0492f, + -0.005f, + 0.0631f, + 0.1379f, + 0.211f, + 0.2859f, + 0.3229f, + 0.3994f, + 0.5217f, + 0.6135f, + -0.5471f, + -0.5089f, + -0.4285f, + -0.3512f, + -0.3124f, + -0.235f, + -0.162f, + -0.0872f, + 0.0249f, + 0.1013f, + 0.1741f, + 0.2485f, + 0.361f, + 0.4376f, + 0.4776f, + 0.5645f +}; + +const float Gain_meanNB[] = { 2.4052f }; + +const float Gain_mean_dicNB[] = +{ + -0.3197f, + -0.2272f, + -0.1386f, + -0.0966f, + -0.0132f, + 0.1970f, + 0.2865f, + 0.3743f, + 0.4640f, + 0.5108f, + 0.5581f, + 0.6086f, + 0.6588f, + 0.7642f, + 0.7101f, + 0.0698f, + -0.1827f, + 0.2418f, + 0.1540f, + -0.2733f, + -0.4144f, + -0.5162f, + -0.6806f, + -1.3182f, + -2.4026f, + -0.4643f, + -0.7983f, + -1.9470f, + -1.8160f, + -1.6910f, + -1.7558f, + -0.5677f, + -0.3673f, + -0.6224f, + -0.7379f, + -0.8624f, + -0.9321f, + -1.0098f, + -1.1600f, + -1.2380f, + -1.4052f, + -1.4876f, + -2.1967f, + -1.5599f, + -2.1399f, + -2.3041f, + 0.8225f, + 0.9564f, + 0.8835f, + 1.1436f, + -2.0176f, + 1.0387f, + -1.0822f, + -1.6264f, + -2.2534f, + -1.8746f, + 1.4304f, + 0.0288f, + 0.1116f, + -0.0553f, + 0.4192f, + 0.3303f, + -2.0750f, + -2.3558f, +}; + +const float Mean_dic_NB[] = +{ + -0.1084f, + -0.0243f, + -0.0292f, + -0.0091f, + 0.0061f, + 0.0171f, + 0.0362f, + 0.0153f, + 0.0416f, + 0.0558f, +}; + +const float Gain_dic1_NB[] = +{ + -0.1479f, -0.0224f, 0.0013f, + -0.4797f, 0.0718f, 0.1627f, + -0.1073f, 0.0291f, 0.1613f, + -0.0258f, 0.0652f, 0.0264f, + -0.2961f, 0.0842f, -0.0332f, + -0.3053f, 0.1508f, 0.1381f, + -0.4650f, -0.1832f, 0.1581f, + -0.2546f, -0.0879f, -0.1215f, + -0.0043f, -0.0785f, 0.0235f, + 0.0816f, 0.0283f, -0.0604f, + -0.4709f, 0.1612f, 0.0056f, + -0.4504f, 0.2876f, 0.1183f, + -0.0440f, 0.2040f, 0.0408f, + -0.4619f, -0.2252f, -0.0783f, + 0.1016f, -0.1067f, -0.0839f, + 0.1452f, -0.1337f, 0.0386f, + -0.0648f, -0.1970f, -0.0826f, + -0.2599f, -0.2477f, -0.0048f, + -0.1528f, 0.1452f, -0.0814f, + -0.1389f, 0.2661f, 0.1590f, + 0.0066f, 0.1432f, -0.0809f, + -0.0450f, -0.0207f, -0.1229f, + -0.4643f, -0.4412f, 0.0796f, + -0.4543f, -0.0387f, -0.2415f, + -0.1626f, 0.0349f, -0.2839f, + -0.4194f, 0.2517f, -0.1816f, + 0.2068f, 0.0736f, -0.0144f, + 0.1757f, -0.2445f, -0.0527f, + 0.3370f, -0.2115f, -0.2366f, + 0.1961f, -0.0010f, -0.1484f, + 0.0568f, 0.0997f, -0.2436f, + 0.3561f, 0.0213f, 0.0641f, + 0.0842f, -0.1502f, -0.2506f, + 0.2140f, -0.0362f, -0.0016f, + 0.0165f, -0.2625f, 0.0660f, + 0.1958f, 0.0804f, 0.1159f, + -0.4695f, -0.0308f, -0.0092f, + 0.3114f, -0.1023f, -0.0851f, + 0.0979f, 0.2260f, 0.1403f, + 0.2066f, -0.0569f, 0.1335f, + 0.1691f, -0.4590f, 0.0869f, + -0.0883f, -0.4109f, -0.0535f, + 0.0565f, -0.0827f, 0.1460f, + 0.2996f, -0.1503f, 0.0652f, + 0.2724f, 0.0221f, -0.3213f, + -0.1344f, -0.1588f, 0.1293f, + 0.1083f, 0.0079f, 0.0442f, + -0.0937f, 0.2946f, -0.1892f, + -0.2424f, 0.2840f, 0.0099f, + 0.1915f, -0.2486f, 0.1314f, + 0.1551f, 0.1553f, -0.1036f, + 0.3353f, -0.3337f, 0.0364f, + 0.3521f, 0.0979f, -0.1083f, + 0.2671f, 0.2169f, 0.0300f, + 0.2135f, 0.2717f, -0.2642f, + -0.1578f, -0.2715f, -0.2692f, + 0.1316f, -0.3985f, -0.1668f, + 0.0981f, 0.1393f, 0.0241f, + -0.4342f, -0.4417f, -0.2072f, + -0.1788f, -0.4128f, 0.1708f, + -0.1655f, 0.1284f, 0.0670f, + 0.0782f, 0.2996f, -0.0288f, + -0.2984f, -0.0440f, 0.1108f, + 0.0423f, 0.0853f, 0.1295f, +}; + +const float Gain_dic2_NB[] = +{ + 0.0069f, 0.0000f, -0.0160f, + -0.1361f, 0.0009f, 0.0504f, + 0.0686f, -0.1568f, 0.0088f, + -0.1019f, 0.0198f, -0.1206f, + -0.0927f, 0.1671f, 0.1099f, + 0.1272f, -0.3770f, 0.0631f, + -0.2733f, 0.1496f, -0.2809f, + 0.1256f, 0.0058f, 0.1945f, + 0.0714f, -0.0204f, -0.1284f, + 0.0723f, 0.1021f, -0.0563f, + -0.1024f, -0.0165f, 0.2383f, + 0.0004f, -0.0753f, 0.0971f, + -0.1114f, -0.2459f, 0.0641f, + -0.2982f, -0.0906f, 0.1089f, + -0.0539f, -0.0952f, -0.0441f, + -0.2955f, 0.1435f, 0.1833f, + -0.2669f, 0.1288f, -0.0425f, + 0.1440f, 0.0907f, -0.3104f, + -0.0192f, -0.0612f, -0.3029f, + -0.2480f, -0.1188f, -0.1250f, + 0.1324f, 0.1419f, 0.0826f, + -0.0648f, 0.1114f, -0.0257f, + 0.1196f, -0.0173f, 0.0218f, + 0.0103f, 0.0574f, 0.0926f, + 0.0076f, 0.2916f, -0.0493f, + 0.0422f, -0.2048f, 0.2074f, + -0.0113f, 0.1221f, -0.1958f, + 0.0371f, 0.2279f, 0.2620f, + 0.2392f, 0.0843f, -0.0641f, + 0.1969f, -0.1415f, -0.1273f, + -0.0055f, -0.2421f, -0.1429f, + 0.2138f, -0.1407f, 0.1003f, +}; + +const float Gain_dic3_NB[] = +{ + -0.0039f, 0.0159f, -0.0553f, 0.0027f, + -0.0523f, 0.1349f, 0.0894f, 0.0451f, + 0.0334f, -0.0825f, -0.0732f, -0.1526f, + -0.0298f, 0.0199f, 0.1314f, -0.1946f, + 0.0391f, 0.0695f, -0.2694f, 0.0085f, + -0.1451f, 0.0762f, -0.0925f, -0.1033f, + 0.0412f, -0.1568f, -0.0964f, 0.0887f, + 0.0856f, -0.2846f, 0.1538f, -0.0637f, + -0.2905f, 0.0529f, 0.1016f, 0.0456f, + -0.1409f, 0.0596f, -0.1553f, 0.2095f, + 0.1415f, 0.1177f, -0.0536f, 0.1551f, + 0.1159f, -0.0458f, 0.0909f, 0.0066f, + -0.0159f, -0.0901f, 0.1231f, 0.2221f, + -0.1032f, -0.1080f, 0.0302f, -0.0098f, + 0.1173f, 0.1404f, -0.0101f, -0.1590f, + 0.1665f, 0.1661f, 0.2222f, 0.1193f, +}; + +const float Gain_dic2_NBHR[] = +{ + 0.0070f, 0.0001f, -0.0229f, + -0.1476f, -0.0493f, -0.0424f, + 0.0791f, -0.0927f, -0.0399f, + -0.0308f, -0.0735f, -0.0748f, + -0.0704f, 0.0302f, 0.0273f, + -0.0211f, 0.1279f, -0.0281f, + 0.0572f, 0.0045f, -0.1133f, + -0.0134f, -0.0686f, 0.0436f, + 0.0393f, 0.1088f, 0.1543f, + 0.0893f, -0.0201f, 0.0237f, + 0.0556f, -0.2804f, 0.0660f, + 0.0715f, 0.0698f, -0.0348f, + -0.0301f, -0.0085f, -0.2187f, + -0.1319f, -0.1649f, 0.0427f, + 0.0807f, -0.1180f, -0.1678f, + -0.1901f, 0.0498f, -0.1630f, + -0.1202f, 0.1876f, -0.1245f, + -0.2966f, -0.1514f, -0.1179f, + 0.1663f, -0.0185f, -0.0722f, + -0.1638f, 0.0966f, -0.0110f, + -0.1854f, 0.0728f, 0.1377f, + -0.0693f, 0.1437f, 0.0784f, + -0.3336f, -0.1445f, 0.1210f, + -0.1093f, -0.1429f, -0.1739f, + 0.0029f, -0.1845f, -0.0220f, + 0.1253f, 0.0407f, -0.2262f, + -0.2861f, 0.2587f, -0.2925f, + -0.1164f, 0.1825f, 0.2457f, + 0.0103f, 0.0251f, 0.3118f, + -0.2296f, 0.2562f, 0.0336f, + -0.2257f, -0.0035f, -0.3586f, + 0.1669f, 0.1657f, -0.3857f, + 0.1019f, -0.0912f, -0.3838f, + 0.1482f, 0.0660f, 0.0626f, + 0.1384f, 0.1899f, 0.2057f, + 0.3452f, -0.0544f, -0.1323f, + 0.0236f, 0.0488f, 0.0614f, + 0.0541f, 0.2623f, -0.1335f, + -0.1744f, -0.0697f, 0.2553f, + 0.0943f, -0.1671f, 0.2403f, + 0.0826f, 0.1646f, 0.0282f, + -0.0668f, 0.0418f, -0.0898f, + 0.1419f, -0.4567f, 0.0836f, + 0.0229f, 0.1079f, -0.1457f, + -0.0715f, -0.2943f, 0.2078f, + -0.0311f, 0.1224f, -0.3045f, + 0.0428f, 0.4151f, 0.3314f, + -0.0059f, 0.2989f, 0.0695f, + 0.1725f, -0.2325f, -0.0715f, + 0.1631f, 0.1202f, -0.0993f, + 0.2841f, 0.1833f, 0.0490f, + 0.0929f, -0.1452f, 0.0702f, + -0.3833f, 0.1174f, -0.1297f, + -0.1458f, -0.0391f, 0.0797f, + -0.1412f, -0.3200f, -0.0097f, + -0.0287f, -0.1278f, 0.1406f, + -0.3695f, 0.1286f, 0.1848f, + -0.0450f, 0.0097f, 0.1487f, + -0.2966f, 0.0239f, 0.0167f, + -0.0159f, -0.3233f, -0.2040f, + 0.2004f, -0.0729f, 0.0498f, + 0.1943f, 0.0051f, 0.2050f, + 0.0757f, -0.0325f, 0.1324f, + 0.2545f, -0.2377f, 0.1312f, +}; + +const float Gain_dic3_NBHR[] = +{ + 0.0715f, 0.0018f, -0.0493f, -0.0232f, + 0.1305f, 0.0268f, 0.1323f, -0.1251f, + -0.1410f, 0.0158f, -0.1367f, -0.0843f, + 0.0502f, 0.0811f, 0.0024f, -0.1302f, + -0.0186f, 0.0869f, -0.0034f, 0.0203f, + 0.0363f, -0.0908f, -0.0475f, -0.1196f, + -0.1168f, -0.0588f, -0.0135f, 0.0275f, + -0.0716f, -0.1147f, -0.1479f, 0.0151f, + 0.1947f, -0.3535f, 0.1525f, -0.2753f, + 0.0423f, 0.1132f, -0.4115f, -0.0120f, + -0.0956f, -0.0720f, -0.0388f, -0.1134f, + -0.1746f, 0.1026f, -0.0357f, -0.2402f, + -0.0087f, 0.0068f, -0.1182f, 0.0290f, + 0.1152f, 0.0665f, -0.1780f, -0.0283f, + 0.0167f, -0.0212f, -0.1534f, -0.1048f, + 0.1047f, -0.2240f, -0.0385f, -0.0466f, + -0.1331f, 0.0561f, -0.1063f, 0.0637f, + -0.0312f, 0.0037f, -0.1930f, 0.1494f, + 0.0655f, -0.0945f, -0.3072f, 0.0248f, + 0.0922f, 0.0580f, 0.0735f, 0.0007f, + -0.1207f, 0.0363f, 0.0319f, -0.0303f, + 0.1547f, -0.0751f, 0.0242f, 0.0058f, + 0.1397f, 0.1735f, 0.1842f, -0.2776f, + -0.2707f, 0.0977f, 0.2668f, 0.0901f, + -0.2028f, -0.1033f, 0.3865f, 0.2659f, + -0.0203f, 0.0380f, -0.0256f, 0.2631f, + -0.2270f, 0.1163f, 0.0372f, 0.0927f, + 0.1894f, 0.2838f, 0.1924f, -0.0104f, + 0.0680f, 0.0122f, 0.0997f, 0.1458f, + 0.1162f, 0.1180f, 0.0179f, 0.1828f, + 0.2204f, 0.1676f, 0.0196f, -0.1003f, + 0.0476f, -0.1876f, 0.0683f, 0.0840f, + -0.0641f, -0.2440f, -0.0112f, -0.0693f, + -0.0161f, 0.0641f, 0.0769f, -0.3024f, + 0.1061f, 0.1410f, -0.0572f, -0.2854f, + 0.0487f, -0.4075f, 0.0459f, 0.0278f, + -0.0140f, 0.1022f, -0.1243f, -0.1545f, + 0.0240f, -0.0290f, 0.0314f, -0.1991f, + -0.0383f, -0.0890f, -0.0607f, 0.1311f, + 0.0164f, -0.1524f, 0.0296f, 0.2814f, + 0.3526f, 0.0346f, -0.1425f, 0.0093f, + 0.2652f, -0.0205f, 0.0395f, 0.2426f, + 0.0958f, -0.0937f, -0.0302f, 0.1301f, + 0.0615f, 0.0446f, -0.2835f, -0.2160f, + -0.1053f, -0.2025f, 0.0248f, 0.1055f, + -0.1728f, 0.2409f, -0.2493f, -0.1572f, + -0.0157f, 0.0293f, -0.4112f, 0.2406f, + 0.0512f, -0.1206f, -0.2211f, 0.3179f, + 0.0121f, -0.0455f, 0.0431f, 0.0451f, + -0.0626f, 0.2130f, -0.2451f, 0.0946f, + 0.1376f, -0.0196f, -0.1657f, 0.1258f, + -0.1862f, -0.0097f, -0.2866f, 0.0556f, + -0.2513f, 0.0485f, -0.0144f, -0.0726f, + 0.0073f, -0.0115f, 0.0484f, -0.0645f, + -0.0966f, -0.3504f, 0.2229f, -0.2486f, + -0.0344f, 0.2348f, 0.0088f, 0.1117f, + 0.0088f, -0.0947f, 0.1894f, -0.2441f, + -0.0181f, 0.1194f, 0.2775f, 0.0341f, + -0.2369f, -0.1871f, 0.1625f, -0.0285f, + 0.0220f, 0.1462f, 0.4066f, 0.3429f, + -0.0763f, -0.1673f, -0.1866f, -0.1501f, + 0.1374f, -0.1128f, -0.1530f, -0.1874f, + 0.1933f, 0.1366f, -0.3527f, 0.1357f, + -0.1419f, 0.1760f, -0.1364f, 0.2775f, + -0.1707f, -0.0667f, 0.0668f, -0.2065f, + 0.2295f, -0.1684f, 0.1824f, -0.0617f, + -0.0431f, -0.1322f, 0.3309f, -0.0529f, + -0.1430f, 0.1042f, 0.2921f, -0.2119f, + 0.0358f, 0.1299f, -0.1342f, 0.0989f, + 0.0631f, 0.1654f, -0.0598f, -0.0405f, + 0.1884f, 0.2592f, -0.0807f, 0.1176f, + 0.0948f, 0.4565f, -0.1406f, 0.3869f, + 0.1129f, 0.2113f, 0.1108f, 0.2958f, + 0.1392f, 0.1289f, -0.1663f, 0.3001f, + -0.0943f, 0.1483f, 0.1463f, 0.2112f, + -0.0376f, -0.0049f, -0.0515f, -0.0564f, + 0.0234f, 0.1798f, 0.0996f, -0.0633f, + 0.1864f, -0.3743f, 0.2672f, 0.0607f, + 0.1720f, -0.2764f, 0.4289f, -0.2641f, + 0.0758f, -0.1174f, 0.0803f, -0.0964f, + 0.0473f, -0.1906f, 0.0144f, -0.2328f, + -0.2278f, -0.2336f, -0.0060f, 0.4555f, + -0.2079f, -0.0547f, -0.1176f, 0.2006f, + -0.3511f, 0.1197f, 0.0539f, 0.3127f, + 0.0956f, 0.1653f, 0.1317f, 0.0846f, + 0.2158f, -0.1499f, 0.4502f, 0.1656f, + -0.1886f, 0.1181f, -0.2266f, 0.6047f, + -0.0670f, -0.1125f, 0.0923f, -0.0642f, + -0.0690f, -0.0762f, 0.1423f, 0.0834f, + 0.1107f, -0.3762f, 0.0924f, 0.3090f, + 0.1900f, 0.2673f, 0.3150f, 0.2012f, + -0.2339f, -0.1082f, -0.0508f, -0.0173f, + 0.2405f, -0.2444f, -0.0301f, 0.1156f, + 0.0136f, -0.2449f, -0.1253f, 0.1158f, + -0.0633f, 0.3504f, 0.2381f, 0.0768f, + -0.0143f, -0.0412f, 0.1767f, 0.2347f, + -0.0512f, 0.2515f, 0.0832f, -0.2386f, + 0.2573f, 0.7121f, -0.0018f, -0.2141f, + -0.2079f, -0.0557f, 0.0805f, 0.1525f, + 0.0022f, -0.1280f, -0.0237f, -0.0035f, + 0.0038f, -0.0122f, 0.1163f, 0.5874f, + 0.0644f, -0.0581f, 0.1875f, 0.0136f, + 0.0457f, 0.0263f, -0.0413f, 0.1088f, + 0.1644f, 0.0582f, 0.2423f, 0.1638f, + -0.0532f, 0.0697f, 0.1184f, 0.0443f, + 0.1633f, -0.1285f, 0.1561f, 0.1394f, + 0.1586f, 0.0050f, -0.0458f, -0.1260f, + 0.2517f, 0.0403f, 0.1285f, 0.0333f, + -0.0813f, 0.0750f, 0.0248f, -0.1389f, + -0.0383f, 0.0755f, -0.2281f, -0.0295f, + -0.0820f, 0.0345f, 0.0096f, 0.1308f, + 0.1616f, 0.0888f, -0.0324f, 0.0543f, + -0.3135f, 0.1556f, -0.1552f, 0.0187f, + 0.3031f, 0.2066f, 0.1139f, 0.1557f, + 0.2055f, 0.0801f, 0.3248f, -0.0781f, + 0.0372f, -0.2464f, 0.1343f, -0.0524f, + -0.1885f, 0.0032f, 0.1451f, -0.0297f, + 0.0820f, -0.1000f, -0.1336f, -0.0005f, + 0.2121f, -0.0259f, 0.0784f, -0.2882f, + 0.1259f, 0.3045f, -0.2021f, -0.1408f, + -0.1636f, 0.2132f, 0.0897f, -0.0322f, + -0.1013f, 0.1537f, -0.0700f, -0.0400f, + -0.0256f, 0.0338f, 0.1603f, -0.1077f, + -0.0390f, -0.2649f, 0.2294f, 0.1718f, + -0.0313f, -0.0166f, -0.0901f, -0.2568f, + -0.3501f, 0.1449f, 0.1334f, -0.1623f, + -0.4515f, 0.0182f, 0.0428f, 0.0424f, + -0.3133f, 0.1780f, -0.3883f, 0.2519f, +}; + +const float YG_mean16[] = +{ + -0.0968f, + -0.0468f, + -0.0409f, + -0.0332f, + -0.0147f, + -0.0042f, + 0.0111f, + 0.0096f, + 0.0293f, + 0.0198f, + 0.0219f, + 0.0164f, + 0.0358f, + 0.0083f, + 0.0398f, + 0.0448f, +}; + +const float YG_dicMR_1[] = +{ + -0.4588f, 0.2016f, 0.1315f, -0.0513f, + -0.0294f, 0.0652f, -0.0335f, -0.0347f, + -0.1948f, -0.1154f, 0.1059f, 0.0594f, + 0.0724f, -0.2188f, 0.0901f, 0.0750f, + -0.4597f, -0.3254f, 0.1015f, 0.1244f, + -0.4774f, -0.1611f, -0.1151f, 0.0548f, + -0.2210f, -0.1962f, -0.1262f, 0.1056f, + -0.2346f, 0.0050f, -0.0631f, -0.0547f, + 0.0510f, 0.2386f, -0.0519f, -0.0042f, + 0.1308f, -0.0595f, 0.0388f, 0.0238f, + -0.0647f, 0.1891f, 0.1005f, -0.0799f, + 0.0823f, -0.0955f, -0.0579f, -0.1152f, + -0.4790f, -0.4482f, -0.1689f, 0.1149f, + 0.1525f, 0.0422f, -0.1130f, -0.0037f, + -0.2356f, 0.0643f, 0.0151f, 0.1466f, + -0.1910f, 0.2170f, -0.1056f, 0.0514f, + -0.4373f, 0.2081f, -0.1106f, -0.1895f, + -0.0445f, -0.0433f, -0.2631f, 0.0195f, + -0.0889f, 0.0855f, 0.0683f, 0.0715f, + -0.2201f, 0.2731f, 0.0719f, -0.2914f, + 0.0038f, 0.1073f, -0.0835f, 0.1121f, + -0.4455f, -0.3868f, -0.3375f, -0.1949f, + 0.1764f, 0.0140f, -0.3015f, -0.1613f, + 0.2167f, -0.3999f, 0.0677f, 0.0572f, + 0.0831f, 0.0842f, 0.0345f, -0.1490f, + 0.3124f, -0.0055f, 0.0042f, 0.0352f, + -0.1561f, -0.2081f, -0.1269f, -0.1350f, + 0.2519f, 0.2059f, 0.0364f, 0.1061f, + 0.1418f, 0.1911f, 0.1266f, -0.0479f, + 0.1115f, 0.2308f, 0.1216f, -0.3146f, + -0.4631f, -0.0101f, 0.1038f, 0.1255f, + 0.1921f, 0.0393f, 0.1236f, 0.0941f, + -0.1365f, 0.2635f, 0.0780f, 0.1258f, + 0.1220f, 0.0830f, 0.0146f, 0.0258f, + 0.0614f, -0.2434f, -0.2840f, -0.2344f, + 0.0638f, -0.3144f, -0.1540f, 0.0817f, + 0.3029f, -0.1514f, -0.0944f, -0.1617f, + 0.0407f, 0.0474f, 0.1163f, 0.0163f, + 0.2027f, -0.0636f, 0.1049f, -0.2933f, + -0.1169f, -0.0300f, 0.0174f, -0.2837f, + 0.0550f, -0.3618f, 0.0322f, -0.1958f, + 0.1659f, 0.1862f, -0.2466f, 0.1048f, + 0.0488f, -0.0304f, 0.0638f, 0.1441f, + 0.1882f, -0.1807f, -0.0447f, 0.0559f, + -0.4542f, -0.0850f, 0.0678f, -0.1340f, + -0.4317f, 0.2362f, 0.0687f, 0.1451f, + -0.4217f, -0.4143f, 0.0213f, -0.1866f, + 0.2853f, 0.1540f, -0.0279f, -0.1151f, + -0.3994f, -0.0247f, -0.3232f, -0.0221f, + 0.2004f, -0.1819f, 0.1119f, -0.0644f, + 0.2475f, -0.1406f, 0.0951f, 0.1147f, + 0.2541f, -0.1261f, -0.2486f, 0.0897f, + 0.2016f, 0.0042f, 0.1040f, -0.0797f, + -0.1140f, -0.4007f, 0.0491f, 0.0794f, + -0.4653f, 0.1045f, -0.0824f, 0.0541f, + -0.2492f, 0.1539f, 0.1023f, -0.0183f, + -0.0211f, -0.0926f, -0.0495f, 0.0572f, + 0.1609f, 0.1286f, -0.1199f, -0.3680f, + -0.1378f, -0.4261f, -0.2389f, -0.0422f, + -0.4306f, -0.1056f, -0.1813f, -0.2662f, + 0.0590f, 0.1732f, 0.0657f, 0.1213f, + 0.1749f, 0.0180f, -0.0507f, 0.1508f, + -0.0724f, 0.1574f, -0.2109f, -0.1965f, + -0.0112f, -0.0797f, 0.1006f, -0.0723f, +}; + +const float YG_dicMR_2[] = +{ + 0.0228f, 0.0529f, -0.0298f, 0.0091f, + -0.0032f, -0.0203f, 0.0257f, -0.1199f, + -0.0972f, -0.1446f, 0.0973f, -0.0390f, + 0.1325f, -0.0197f, -0.1147f, 0.0997f, + 0.0963f, -0.1539f, -0.0230f, -0.0630f, + -0.1623f, 0.0325f, -0.0331f, -0.0305f, + 0.0970f, -0.0857f, 0.1538f, -0.0361f, + -0.2846f, 0.0992f, -0.2111f, 0.1353f, + -0.0333f, -0.0737f, -0.0642f, 0.0198f, + -0.1646f, -0.1605f, -0.1393f, -0.1688f, + -0.0503f, 0.0930f, -0.1707f, 0.0298f, + 0.0665f, -0.3677f, 0.0868f, 0.0036f, + 0.1102f, -0.2346f, 0.1557f, -0.2765f, + 0.0772f, -0.1922f, 0.0404f, 0.1428f, + 0.0762f, -0.0352f, 0.0451f, 0.0668f, + 0.0095f, -0.1723f, -0.2433f, 0.0611f, + -0.2235f, -0.2127f, -0.0279f, 0.1118f, + -0.2035f, 0.0849f, 0.0888f, -0.2901f, + 0.1098f, 0.1764f, -0.0625f, 0.1007f, + 0.0902f, 0.1143f, -0.3346f, 0.1015f, + 0.0841f, 0.0401f, 0.0707f, -0.2672f, + 0.1622f, 0.0297f, 0.0082f, -0.0532f, + 0.1355f, 0.0621f, 0.1365f, 0.2015f, + 0.0762f, 0.1201f, 0.1211f, -0.0066f, + -0.0974f, 0.0770f, 0.1685f, -0.0806f, + -0.1118f, 0.1734f, 0.0503f, 0.1013f, + 0.0709f, 0.0217f, -0.1615f, -0.1139f, + -0.0176f, 0.1448f, -0.0264f, -0.1122f, + -0.0531f, 0.0113f, 0.0778f, 0.0461f, + -0.3335f, 0.0486f, 0.0892f, 0.0152f, + -0.1348f, -0.0405f, 0.1884f, 0.2103f, + -0.0387f, 0.0294f, -0.0525f, 0.1893f, +}; + +const float YG_dicMR_3[] = +{ + -0.0251f, -0.0350f, -0.0207f, -0.0047f, + -0.0986f, 0.0444f, -0.1942f, 0.0205f, + 0.0972f, -0.1449f, -0.0134f, -0.0624f, + 0.0691f, 0.0313f, -0.1153f, 0.0682f, + -0.0600f, -0.1532f, 0.0686f, 0.0726f, + -0.2082f, 0.1143f, 0.0874f, -0.2235f, + 0.0664f, 0.0363f, 0.0510f, -0.1081f, + -0.0409f, -0.1231f, 0.1104f, -0.1281f, + 0.1524f, -0.1042f, 0.1901f, 0.0286f, + 0.2634f, 0.0987f, -0.0240f, 0.0196f, + 0.0332f, 0.0404f, 0.0347f, -0.3404f, + 0.1252f, -0.1383f, -0.0367f, 0.2006f, + 0.0302f, 0.1576f, 0.0487f, 0.0664f, + -0.0403f, -0.1715f, -0.1502f, 0.0404f, + 0.0814f, 0.1978f, -0.1116f, 0.2533f, + -0.0878f, 0.0256f, -0.0268f, 0.1310f, + -0.0548f, 0.0305f, 0.1372f, -0.0063f, + 0.1706f, -0.2698f, 0.1976f, -0.3231f, + -0.3001f, 0.2054f, -0.1872f, 0.1393f, + -0.0756f, 0.1066f, -0.0278f, -0.0562f, + -0.2551f, 0.1538f, 0.1377f, 0.0787f, + 0.0689f, 0.2857f, -0.1765f, -0.0746f, + -0.0800f, -0.0604f, -0.0612f, -0.1461f, + 0.0864f, 0.0811f, -0.3889f, 0.1219f, + 0.0810f, -0.0055f, 0.0534f, 0.0743f, + 0.0794f, -0.3690f, 0.0922f, 0.0731f, + -0.0230f, -0.0132f, 0.1657f, 0.2333f, + 0.1238f, 0.2026f, 0.2103f, -0.1805f, + -0.2186f, -0.0329f, 0.0040f, -0.0083f, + 0.1654f, 0.1588f, 0.2346f, 0.1744f, + 0.1993f, -0.1624f, -0.4251f, -0.1638f, + 0.0670f, 0.0227f, -0.1506f, -0.1057f, +}; + +const float YG_dicMR_4[] = +{ + -0.0398f, -0.0108f, -0.0263f, 0.0079f, + 0.1358f, 0.0373f, 0.0281f, 0.0293f, + 0.1507f, 0.1997f, 0.1958f, 0.1756f, + -0.1560f, -0.1623f, 0.0297f, 0.1620f, + 0.0863f, -0.1354f, -0.0860f, -0.0209f, + -0.2836f, 0.2034f, -0.2525f, 0.0796f, + -0.1247f, -0.0991f, -0.1167f, -0.1276f, + 0.1198f, -0.3596f, 0.0987f, -0.0051f, + 0.0362f, 0.0702f, -0.0111f, -0.1328f, + -0.0148f, 0.0420f, -0.1931f, -0.0108f, + 0.1745f, -0.1095f, 0.2103f, 0.1230f, + -0.0264f, 0.0641f, 0.1489f, 0.0289f, + 0.2348f, 0.2016f, -0.2473f, -0.0091f, + -0.0077f, -0.1208f, 0.0883f, -0.0523f, + -0.0091f, 0.1614f, -0.0183f, 0.0706f, + -0.2039f, 0.0593f, 0.0207f, -0.0256f, +}; + +const float mean_m[] = { 2.8717f }; + +const float mean_gain_dic[] = +{ + -0.1804f, + -0.1267f, + -0.0185f, + 0.0358f, + 0.1402f, + 0.1903f, + 0.2399f, + 0.2894f, + 0.3379f, + 0.3858f, + 0.4356f, + 0.4857f, + 0.5380f, + 0.6452f, + 0.6992f, + 0.5914f, + 0.0885f, + -0.0721f, + -0.2922f, + -0.4726f, + -0.6732f, + -2.8699f, + -2.0059f, + 0.7528f, + 0.8083f, + -0.3501f, + -0.4106f, + -0.8156f, + -2.2665f, + -2.2112f, + -2.1036f, + -1.9001f, + -1.7967f, + -1.7001f, + -1.6094f, + -1.5218f, + -1.3355f, + -1.2328f, + -1.1354f, + -0.9654f, + -0.6031f, + -0.2352f, + -0.5368f, + -0.7426f, + -0.8894f, + -1.0479f, + -1.4292f, + -2.4899f, + 1.0016f, + 0.8661f, + 1.0718f, + 1.1517f, + 0.9318f, + -2.5695f, + -2.8128f, + -2.3365f, + -2.4168f, + -2.2389f, + -2.6467f, + -2.7259f, + 1.3428f, + 1.2399f, + 1.4988f, + 1.7072f, +}; + +const float YGain_mean_LR[] = +{ + -0.0940f, + -0.0435f, + -0.0348f, + -0.0284f, + -0.0113f, + -0.0029f, + 0.0156f, + 0.0123f, + 0.0288f, + 0.0167f, + 0.0324f, + 0.0369f, +}; + +const float YGain_dic1_LR[] = +{ + -0.4660f, 0.0389f, -0.0220f, + -0.0378f, 0.1016f, -0.0036f, + -0.0241f, -0.0205f, 0.0967f, + -0.4472f, -0.2070f, -0.0781f, + -0.1901f, 0.2501f, 0.0111f, + -0.4541f, -0.4299f, 0.0666f, + 0.0197f, -0.0832f, -0.0755f, + -0.1999f, -0.0008f, -0.0770f, + 0.1179f, 0.0525f, -0.0474f, + 0.0591f, 0.2288f, -0.0186f, + -0.4468f, -0.4279f, -0.2691f, + -0.3880f, 0.2118f, -0.1605f, + -0.2224f, 0.0950f, 0.1028f, + -0.4478f, 0.2234f, 0.0952f, + -0.0352f, 0.1378f, -0.2121f, + 0.2143f, -0.3769f, 0.0736f, + 0.1089f, 0.0811f, 0.0917f, + -0.1318f, -0.2008f, -0.2444f, + 0.1339f, -0.0469f, 0.0567f, + 0.2245f, -0.1437f, -0.0427f, + 0.2121f, 0.1750f, -0.1378f, + 0.1945f, -0.0252f, -0.2556f, + -0.0819f, -0.4228f, -0.0453f, + -0.4492f, -0.0842f, 0.1383f, + 0.2943f, 0.0266f, 0.0106f, + 0.2405f, -0.1113f, 0.1391f, + 0.1588f, -0.2987f, -0.2134f, + 0.2265f, 0.1837f, 0.0951f, + -0.0302f, 0.2034f, 0.1404f, + -0.4421f, -0.0608f, -0.2788f, + -0.1736f, -0.1872f, 0.0451f, + 0.0840f, -0.2138f, 0.0652f, +}; + +const float YGain_dic2_LR[] = +{ + -0.0718f, -0.0178f, -0.0101f, 0.0026f, + 0.0675f, 0.0806f, -0.3212f, 0.0423f, + 0.0064f, -0.1738f, 0.0211f, 0.0003f, + -0.2054f, -0.1316f, 0.0600f, -0.1170f, + 0.0105f, -0.0505f, 0.1732f, 0.0282f, + 0.0254f, -0.0482f, 0.0554f, -0.1338f, + 0.0638f, -0.0556f, 0.0402f, 0.1480f, + 0.1496f, 0.0983f, -0.0297f, -0.1025f, + 0.0034f, 0.0444f, -0.1327f, -0.1633f, + -0.1793f, 0.0958f, -0.1200f, -0.0319f, + -0.3214f, 0.0670f, 0.0283f, 0.0808f, + -0.3269f, 0.1307f, -0.3079f, 0.1485f, + -0.0844f, 0.0677f, -0.1040f, 0.1779f, + -0.2606f, -0.2042f, -0.1393f, 0.0948f, + 0.1570f, 0.1228f, 0.1182f, 0.1300f, + -0.0362f, 0.1092f, 0.0294f, -0.0957f, + -0.1465f, 0.0641f, 0.1266f, -0.0182f, + 0.1676f, -0.0844f, 0.0926f, 0.0055f, + 0.0318f, 0.0583f, 0.0917f, -0.3336f, + 0.0165f, 0.1601f, -0.0881f, 0.0224f, + 0.1485f, 0.0699f, -0.0988f, 0.1190f, + -0.2517f, 0.1238f, 0.1276f, -0.2371f, + 0.0124f, -0.0108f, -0.1272f, 0.0421f, + -0.1400f, -0.1221f, 0.0972f, 0.1542f, + 0.0587f, 0.0358f, 0.0254f, 0.0125f, + -0.0780f, -0.1659f, -0.2174f, -0.0971f, + -0.0475f, 0.1229f, 0.0746f, 0.1120f, + 0.0819f, 0.0898f, 0.1615f, -0.0950f, + 0.0923f, -0.1925f, -0.1311f, 0.1660f, + 0.1057f, -0.2756f, 0.1153f, -0.2155f, + 0.1153f, -0.0761f, -0.0735f, -0.0506f, + 0.0922f, -0.3286f, 0.1058f, 0.0996f, +}; + +const float YGain_dic3_LR[] = +{ + -0.0810f, -0.0466f, -0.0299f, -0.1110f, -0.0512f, + 0.0888f, -0.0116f, -0.1622f, 0.0996f, 0.0549f, + -0.1406f, -0.0835f, 0.0897f, 0.0128f, 0.0658f, + -0.0958f, -0.0384f, -0.0188f, 0.1526f, -0.0546f, + -0.0446f, -0.1591f, -0.0990f, 0.0242f, 0.0650f, + 0.0059f, 0.0158f, 0.0180f, 0.1281f, 0.1497f, + -0.1966f, 0.0746f, -0.0936f, -0.0051f, 0.0602f, + 0.0038f, 0.0325f, -0.1016f, -0.0009f, -0.1385f, + 0.0718f, -0.1831f, 0.1082f, -0.0897f, 0.0557f, + 0.1308f, 0.1992f, 0.1872f, 0.1371f, 0.1449f, + -0.0131f, 0.0489f, -0.2706f, -0.1422f, 0.0554f, + 0.0300f, -0.0106f, 0.1011f, -0.0918f, -0.1585f, + 0.1445f, -0.1593f, -0.1646f, -0.0943f, -0.0868f, + 0.0244f, -0.0142f, -0.0110f, -0.0264f, 0.0251f, + -0.1774f, -0.0473f, -0.2856f, 0.2274f, 0.2675f, + 0.1251f, 0.1851f, -0.1073f, -0.1877f, -0.2566f, + 0.0885f, 0.1921f, -0.0673f, -0.0339f, 0.0364f, + -0.0533f, 0.0944f, 0.1116f, -0.1010f, 0.0646f, + -0.0492f, 0.1618f, -0.2695f, 0.2154f, -0.0825f, + -0.0139f, 0.0988f, 0.0656f, 0.0628f, -0.0539f, + 0.0817f, 0.2109f, 0.2841f, -0.1492f, -0.1509f, + 0.3113f, 0.1205f, -0.4354f, 0.0290f, 0.2983f, + 0.1837f, 0.0186f, 0.0660f, 0.0179f, -0.0140f, + 0.0917f, -0.3063f, 0.0353f, 0.1767f, 0.1473f, + -0.2414f, 0.1508f, 0.1609f, 0.1647f, 0.1367f, + 0.0313f, -0.0359f, -0.0337f, -0.0899f, 0.2352f, + 0.0341f, -0.0414f, 0.2115f, 0.1313f, 0.0311f, + 0.0299f, -0.1503f, 0.0406f, 0.0575f, -0.0966f, + 0.0914f, 0.0680f, 0.0994f, 0.1587f, -0.3097f, + -0.2103f, 0.1496f, -0.1844f, -0.3256f, -0.2372f, + -0.2251f, 0.0767f, 0.1015f, -0.0279f, -0.1582f, + 0.0647f, 0.0207f, 0.0148f, -0.2710f, 0.0109f, +}; + +const short Odx_fft64[64] = +{ + 0,59,54,49,44,39,34,29,24,19,14,9,4,63,58,53,48,43,38,33,28,23,18,13,8,3,62,57,52,47,42,37, + 32,27,22,17,12,7,2,61,56,51,46,41,36,31,26,21,16,11,6,1,60,55,50,45,40,35,30,25,20,15,10,5 +}; + +const float w_fft64[32] = +{ + 1.0000000f,0.00000000f,0.70710677f,0.70710677f,0.92387950f,0.38268346f,0.38268346f,0.92387950f, + 0.98078525f,0.19509032f,0.55557024f,0.83146960f,0.83146960f,0.55557024f,0.19509032f,0.98078525f, + 0.99518472f,0.098017141f,0.63439327f,0.77301043f,0.88192123f,0.47139674f,0.29028469f,0.95694035f, + 0.95694035f,0.29028469f,0.47139674f,0.88192123f,0.77301043f,0.63439327f,0.098017141f,0.99518472f +}; + +const short Ip_fft64[6] = { 32,1,0,64,32,96 }; + +const short Odx_fft32_15[32] = { 0,17,2,19,4,21,6,23,8,25,10,27,12,29,14,31,16,1,18,3,20,5,22,7,24,9,26,11,28,13,30,15 }; + +const float w_fft32[16] = +{ + 1.0000000f,0.00000000f,0.70710677f,0.70710677f,0.92387950f,0.38268346f,0.38268346f,0.92387950f, + 0.98078525f,0.19509032f,0.55557024f,0.83146960f,0.83146960f,0.55557024f,0.19509032f,0.98078525f +}; + +const short Ip_fft32[6] = { 16,1,0,32,16,48 }; + +const short Odx_fft32_5[32] = { 0,27,22,17,12,7,2,29,24,19,14,9,4,31,26,21,16,11,6,1,28,23,18,13,8,3,30,25,20,15,10,5 }; + +const short Odx_fft16[16] = {0,11,6,1,12,7,2,13,8,3,14,9,4,15,10,5}; + +const float w_fft16[8] = { 1.0000000f,0.00000000f,0.70710677f,0.70710677f,0.92387950f,0.38268346f,0.38268346f,0.92387950f }; + +const short Ip_fft16[6] = {8,1,0,16,8,24}; + +const float w_fft8[8] = {1.0000000f,0.00000000f,0.70710677f,0.70710677f }; + +const short Ip_fft8[6] = {4,1,0,8,4,12}; + +const short Idx_dortft80[80] = +{ + 0,65,50,35,20,5,70,55,40,25,10,75,60,45,30,15,16,1,66,51,36,21,6,71,56,41,26,11,76,61, + 46,31,32,17,2,67,52,37,22,7,72,57,42,27,12,77,62,47,48,33,18,3,68,53,38,23,8,73,58,43, + 28,13,78,63,64,49,34,19,4,69,54,39,24,9,74,59,44,29,14,79 +}; + +const short Idx_dortft120[120] = +{ + 0,105,90,75,60,45,30,15,16,1,106,91,76,61,46,31,32,17,2,107,92,77,62,47, + 48,33,18,3,108,93,78,63,64,49,34,19,4,109,94,79,80,65,50,35,20,5,110,95, + 96,81,66,51,36,21,6,111,112,97,82,67,52,37,22,7,8,113,98,83,68,53,38,23, + 24,9,114,99,84,69,54,39,40,25,10,115,100,85,70,55,56,41,26,11,116,101,86, + 71,72,57,42,27,12,117,102,87,88,73,58,43,28,13,118,103,104,89,74,59,44,29,14,119 +}; + +const short Idx_dortft160[160] = +{ + 0,65,130,35,100,5,70,135,40,105,10,75,140,45,110,15,80,145, + 50,115,20,85,150,55,120,25,90,155,60,125,30,95,96,1,66,131, + 36,101,6,71,136,41,106,11,76,141,46,111,16,81,146,51,116,21, + 86,151,56,121,26,91,156,61,126,31,32,97,2,67,132,37,102,7, + 72,137,42,107,12,77,142,47,112,17,82,147,52,117,22,87,152,57, + 122,27,92,157,62,127,128,33,98,3,68,133,38,103,8,73,138,43, + 108,13,78,143,48,113,18,83,148,53,118,23,88,153,58,123,28,93, + 158,63,64,129,34,99,4,69,134,39,104,9,74,139,44,109,14,79, + 144,49,114,19,84,149,54,119,24,89,154,59,124,29,94,159 +}; + +const short Idx_dortft320[320] = +{ + 0,65,130,195,260,5,70,135,200,265,10,75,140,205,270,15,80,145,210,275,20,85,150,215,280,25,90,155,220,285,30,95, + 160,225,290,35,100,165,230,295,40,105,170,235,300,45,110,175,240,305,50,115,180,245,310,55,120,185,250,315,60,125, + 190,255,256,1,66,131,196,261,6,71,136,201,266,11,76,141,206,271,16,81,146,211,276,21,86,151,216,281,26,91,156,221, + 286,31,96,161,226,291,36,101,166,231,296,41,106,171,236,301,46,111,176,241,306,51,116,181,246,311,56,121,186,251, + 316,61,126,191,192,257,2,67,132,197,262,7,72,137,202,267,12,77,142,207,272,17,82,147,212,277,22,87,152,217,282,27, + 92,157,222,287,32,97,162,227,292,37,102,167,232,297,42,107,172,237,302,47,112,177,242,307,52,117,182,247,312,57,122, + 187,252,317,62,127,128,193,258,3,68,133,198,263,8,73,138,203,268,13,78,143,208,273,18,83,148,213,278,23,88,153,218, + 283,28,93,158,223,288,33,98,163,228,293,38,103,168,233,298,43,108,173,238,303,48,113,178,243,308,53,118,183,248,313, + 58,123,188,253,318,63,64,129,194,259,4,69,134,199,264,9,74,139,204,269,14,79,144,209,274,19,84,149,214,279,24,89,154, + 219,284,29,94,159,224,289,34,99,164,229,294,39,104,169,234,299,44,109,174,239,304,49,114,179,244,309,54,119,184,249, + 314,59,124,189,254,319 +}; + +const short Idx_dortft480[480] = +{ + 0,225,450,195,420,165,390,135,360,105,330,75,300,45,270,15,240,465,210,435,180,405,150,375,120,345, + 90,315,60,285,30,255,256,1,226,451,196,421,166,391,136,361,106,331,76,301,46,271,16,241,466,211,436, + 181,406,151,376,121,346,91,316,61,286,31,32,257,2,227,452,197,422,167,392,137,362,107,332,77,302,47, + 272,17,242,467,212,437,182,407,152,377,122,347,92,317,62,287,288,33,258,3,228,453,198,423,168,393,138, + 363,108,333,78,303,48,273,18,243,468,213,438,183,408,153,378,123,348,93,318,63,64,289,34,259,4,229,454, + 199,424,169,394,139,364,109,334,79,304,49,274,19,244,469,214,439,184,409,154,379,124,349,94,319,320, + 65,290,35,260,5,230,455,200,425,170,395,140,365,110,335,80,305,50,275,20,245,470,215,440,185,410,155, + 380,125,350,95,96,321,66,291,36,261,6,231,456,201,426,171,396,141,366,111,336,81,306,51,276,21,246,471, + 216,441,186,411,156,381,126,351,352,97,322,67,292,37,262,7,232,457,202,427,172,397,142,367,112,337,82, + 307,52,277,22,247,472,217,442,187,412,157,382,127,128,353,98,323,68,293,38,263,8,233,458,203,428,173, + 398,143,368,113,338,83,308,53,278,23,248,473,218,443,188,413,158,383,384,129,354,99,324,69,294,39,264, + 9,234,459,204,429,174,399,144,369,114,339,84,309,54,279,24,249,474,219,444,189,414,159,160,385,130,355, + 100,325,70,295,40,265,10,235,460,205,430,175,400,145,370,115,340,85,310,55,280,25,250,475,220,445,190, + 415,416,161,386,131,356,101,326,71,296,41,266,11,236,461,206,431,176,401,146,371,116,341,86,311,56,281, + 26,251,476,221,446,191,192,417,162,387,132,357,102,327,72,297,42,267,12,237,462,207,432,177,402,147,372, + 117,342,87,312,57,282,27,252,477,222,447,448,193,418,163,388,133,358,103,328,73,298,43,268,13,238,463, + 208,433,178,403,148,373,118,343,88,313,58,283,28,253,478,223,224,449,194,419,164,389,134,359,104,329,74, + 299,44,269,14,239,464,209,434,179,404,149,374,119,344,89,314,59,284,29,254,479 +}; + +const short Ip_fft128[10] = { 64, 1, 0, 128, 64, 192, 32, 160, 96, 224 }; + +const float w_fft128[64] = +{ + 1.0000000f, 0.00000000f, 0.70710677f, 0.70710677f, 0.92387950f, 0.38268346f, 0.38268346f, 0.92387950f, + 0.98078525f, 0.19509032f, 0.55557024f, 0.83146960f, 0.83146960f, 0.55557024f, 0.19509032f, 0.98078525f, + 0.99518472f, 0.09801714f, 0.63439327f, 0.77301043f, 0.88192123f, 0.47139674f, 0.29028469f, 0.95694035f, + 0.95694035f, 0.29028469f, 0.47139674f, 0.88192123f, 0.77301043f, 0.63439327f, 0.09801714f, 0.99518472f, + 0.99879545f, 0.04906767f, 0.67155895f, 0.74095112f, 0.90398929f, 0.42755509f, 0.33688985f, 0.94154406f, + 0.97003125f, 0.24298017f, 0.51410274f, 0.85772861f, 0.80320753f, 0.59569930f, 0.14673047f, 0.98917650f, + 0.98917650f, 0.14673047f, 0.59569930f, 0.80320753f, 0.85772861f, 0.51410274f, 0.24298017f, 0.97003125f, + 0.94154406f, 0.33688985f, 0.42755509f, 0.90398929f, 0.74095112f, 0.67155895f, 0.04906767f, 0.99879545f +}; + +const short Ip_fft256[10] = {128, 1, 0, 256, 128, 384, 64, 320,192, 448}; + +const float w_fft256[128] = +{ + 1.00000000f, 0.00000000f, 0.70710678f, 0.70710678f, 0.92387953f, 0.38268343f, 0.38268343f, 0.92387953f, + 0.98078528f, 0.19509032f, 0.55557023f, 0.83146961f, 0.83146961f, 0.55557023f, 0.19509032f, 0.98078528f, + 0.99518473f, 0.09801714f, 0.63439328f, 0.77301045f, 0.88192126f, 0.47139674f, 0.29028468f, 0.95694034f, + 0.95694034f, 0.29028468f, 0.47139674f, 0.88192126f, 0.77301045f, 0.63439328f, 0.09801714f, 0.99518473f, + 0.99879546f, 0.04906767f, 0.67155895f, 0.74095113f, 0.90398929f, 0.42755509f, 0.33688985f, 0.94154407f, + 0.97003125f, 0.24298018f, 0.51410274f, 0.85772861f, 0.80320753f, 0.59569930f, 0.14673047f, 0.98917651f, + 0.98917651f, 0.14673047f, 0.59569930f, 0.80320753f, 0.85772861f, 0.51410274f, 0.24298018f, 0.97003125f, + 0.94154407f, 0.33688985f, 0.42755509f, 0.90398929f, 0.74095113f, 0.67155895f, 0.04906767f, 0.99879546f, + 0.99969882f, 0.02454123f, 0.68954054f, 0.72424708f, 0.91420976f, 0.40524131f, 0.35989504f, 0.93299280f, + 0.97570213f, 0.21910124f, 0.53499762f, 0.84485357f, 0.81758481f, 0.57580819f, 0.17096189f, 0.98527764f, + 0.99247953f, 0.12241068f, 0.61523159f, 0.78834643f, 0.87008699f, 0.49289819f, 0.26671276f, 0.96377607f, + 0.94952818f, 0.31368174f, 0.44961133f, 0.89322430f, 0.75720885f, 0.65317284f, 0.07356456f, 0.99729046f, + 0.99729046f, 0.07356456f, 0.65317284f, 0.75720885f, 0.89322430f, 0.44961133f, 0.31368174f, 0.94952818f, + 0.96377607f, 0.26671276f, 0.49289819f, 0.87008699f, 0.78834643f, 0.61523159f, 0.12241068f, 0.99247953f, + 0.98527764f, 0.17096189f, 0.57580819f, 0.81758481f, 0.84485357f, 0.53499762f, 0.21910124f, 0.97570213f, + 0.93299280f, 0.35989504f, 0.40524131f, 0.91420976f, 0.72424708f, 0.68954054f, 0.02454123f, 0.99969882f +}; + +const short Ip_fft512[18] = {256, 1, 0, 512, 256, 768, 128, 640,384, 896, 64, 576, 320, 832, 192, 704,448, 960}; + +const float w_fft512[256] = +{ + 1.00000000f, 0.00000000f, 0.70710678f, 0.70710678f, 0.92387953f, 0.38268343f, 0.38268343f, 0.92387953f, + 0.98078528f, 0.19509032f, 0.55557023f, 0.83146961f, 0.83146961f, 0.55557023f, 0.19509032f, 0.98078528f, + 0.99518473f, 0.09801714f, 0.63439328f, 0.77301045f, 0.88192126f, 0.47139674f, 0.29028468f, 0.95694034f, + 0.95694034f, 0.29028468f, 0.47139674f, 0.88192126f, 0.77301045f, 0.63439328f, 0.09801714f, 0.99518473f, + 0.99879546f, 0.04906767f, 0.67155895f, 0.74095113f, 0.90398929f, 0.42755509f, 0.33688985f, 0.94154407f, + 0.97003125f, 0.24298018f, 0.51410274f, 0.85772861f, 0.80320753f, 0.59569930f, 0.14673047f, 0.98917651f, + 0.98917651f, 0.14673047f, 0.59569930f, 0.80320753f, 0.85772861f, 0.51410274f, 0.24298018f, 0.97003125f, + 0.94154407f, 0.33688985f, 0.42755509f, 0.90398929f, 0.74095113f, 0.67155895f, 0.04906767f, 0.99879546f, + 0.99969882f, 0.02454123f, 0.68954054f, 0.72424708f, 0.91420976f, 0.40524131f, 0.35989504f, 0.93299280f, + 0.97570213f, 0.21910124f, 0.53499762f, 0.84485357f, 0.81758481f, 0.57580819f, 0.17096189f, 0.98527764f, + 0.99247953f, 0.12241068f, 0.61523159f, 0.78834643f, 0.87008699f, 0.49289819f, 0.26671276f, 0.96377607f, + 0.94952818f, 0.31368174f, 0.44961133f, 0.89322430f, 0.75720885f, 0.65317284f, 0.07356456f, 0.99729046f, + 0.99729046f, 0.07356456f, 0.65317284f, 0.75720885f, 0.89322430f, 0.44961133f, 0.31368174f, 0.94952818f, + 0.96377607f, 0.26671276f, 0.49289819f, 0.87008699f, 0.78834643f, 0.61523159f, 0.12241068f, 0.99247953f, + 0.98527764f, 0.17096189f, 0.57580819f, 0.81758481f, 0.84485357f, 0.53499762f, 0.21910124f, 0.97570213f, + 0.93299280f, 0.35989504f, 0.40524131f, 0.91420976f, 0.72424708f, 0.68954054f, 0.02454123f, 0.99969882f, + 0.99992470f, 0.01227154f, 0.69837625f, 0.71573083f, 0.91911385f, 0.39399204f, 0.37131719f, 0.92850608f, + 0.97831737f, 0.20711138f, 0.54532499f, 0.83822471f, 0.82458930f, 0.56573181f, 0.18303989f, 0.98310549f, + 0.99390697f, 0.11022221f, 0.62485949f, 0.78073723f, 0.87607009f, 0.48218377f, 0.27851969f, 0.96043052f, + 0.95330604f, 0.30200595f, 0.46053871f, 0.88763962f, 0.76516727f, 0.64383154f, 0.08579731f, 0.99631261f, + 0.99811811f, 0.06132074f, 0.66241578f, 0.74913639f, 0.89867447f, 0.43861624f, 0.32531029f, 0.94560733f, + 0.96697647f, 0.25486566f, 0.50353838f, 0.86397286f, 0.79583690f, 0.60551104f, 0.13458071f, 0.99090264f, + 0.98730142f, 0.15885814f, 0.58579786f, 0.81045720f, 0.85135519f, 0.52458968f, 0.23105811f, 0.97293995f, + 0.93733901f, 0.34841868f, 0.41642956f, 0.90916798f, 0.73265427f, 0.68060100f, 0.03680722f, 0.99932238f, + 0.99932238f, 0.03680722f, 0.68060100f, 0.73265427f, 0.90916798f, 0.41642956f, 0.34841868f, 0.93733901f, + 0.97293995f, 0.23105811f, 0.52458968f, 0.85135519f, 0.81045720f, 0.58579786f, 0.15885814f, 0.98730142f, + 0.99090264f, 0.13458071f, 0.60551104f, 0.79583690f, 0.86397286f, 0.50353838f, 0.25486566f, 0.96697647f, + 0.94560733f, 0.32531029f, 0.43861624f, 0.89867447f, 0.74913639f, 0.66241578f, 0.06132074f, 0.99811811f, + 0.99631261f, 0.08579731f, 0.64383154f, 0.76516727f, 0.88763962f, 0.46053871f, 0.30200595f, 0.95330604f, + 0.96043052f, 0.27851969f, 0.48218377f, 0.87607009f, 0.78073723f, 0.62485949f, 0.11022221f, 0.99390697f, + 0.98310549f, 0.18303989f, 0.56573181f, 0.82458930f, 0.83822471f, 0.54532499f, 0.20711138f, 0.97831737f, + 0.92850608f, 0.37131719f, 0.39399204f, 0.91911385f, 0.71573083f, 0.69837625f, 0.01227154f, 0.99992470f +}; + +const short Idx_dortft40[40] = +{ + 0, 25, 10, 35, 20, 5, 30, 15, 16, 1, 26, 11, 36, 21, 6, 31, 32, 17, 2, 27, + 12, 37, 22, 7, 8, 33, 18, 3, 28, 13, 38, 23, 24, 9, 34, 19, 4, 29, 14, 39 +}; + +const short Odx_fft8_5[8] = {0, 3, 6, 1, 4, 7, 2, 5}; +const short Idx_dortft20[20] = {0, 5, 10, 15, 16, 1, 6, 11, 12, 17, 2, 7, 8, 13, 18, 3, 4, 9, 14, 19}; +const short Odx_fft4_5[4] = {0, 3, 2, 1}; +const float w_fft4[2] = {1.0000000f, 0.00000000f}; +const short Ip_fft4[6] = {2,1,0,4,2,6}; +const short ip_edct2_64[6] = {16, 64, 0, 32, 16, 48}; + +const float w_edct2_64[80] = +{ + 1.00000000f, 0.00000000f, 0.70710678f, 0.70710678f, 0.92387953f, 0.38268343f, 0.38268343f, 0.92387953f, + 0.98078528f, 0.19509032f, 0.55557023f, 0.83146961f, 0.83146961f, 0.55557023f, 0.19509032f, 0.98078528f, + 0.70710678f, 0.49984940f, 0.49939772f, 0.49864522f, 0.49759236f, 0.49623976f, 0.49458825f, 0.49263882f, + 0.49039264f, 0.48785106f, 0.48501562f, 0.48188803f, 0.47847016f, 0.47476409f, 0.47077203f, 0.46649639f, + 0.46193976f, 0.45710487f, 0.45199464f, 0.44661215f, 0.44096063f, 0.43504349f, 0.42886430f, 0.42242678f, + 0.41573480f, 0.40879240f, 0.40160376f, 0.39417321f, 0.38650522f, 0.37860442f, 0.37047556f, 0.36212354f, + 0.35355339f, 0.34477027f, 0.33577947f, 0.32658642f, 0.31719664f, 0.30761579f, 0.29784965f, 0.28790409f, + 0.27778511f, 0.26749880f, 0.25705137f, 0.24644909f, 0.23569836f, 0.22480566f, 0.21377754f, 0.20262065f, + 0.19134171f, 0.17994751f, 0.16844492f, 0.15684087f, 0.14514233f, 0.13335637f, 0.12149008f, 0.10955062f, + 0.09754516f, 0.08548094f, 0.07336523f, 0.06120533f, 0.04900857f, 0.03678228f, 0.02453383f, 0.01227061f +}; + +/* HVQ */ +const float hvq_thr_adj[5] = { 0.7071068f, 0.5000000f, 0.2500000f, 0.5000000f, 0.7071068f}; + +const float hvq_class_c[16] = +{ + -0.2324457f, -0.4390556f, 0.0651793f, 0.2109977f, + 0.1471332f, -0.1351437f, 0.4312476f, -0.1384814f, + -0.1384814f, 0.4312476f, -0.1351437f, 0.1471332f, + 0.2109977f, 0.0651793f, -0.4390556f, -0.2324457f +}; + +const short hvq_cb_search_overlap24k[17] = +{ + 0, 8, 17, 27, + 39, 53, 69, 89, + 113, 128, 128, 128, + 128, 128, 128, 128, + 128 +}; + +const short hvq_cb_search_overlap32k[21] = +{ + 0, 6, 13, 21, + 30, 40, 51, 64, + 78, 96, 116, 128, + 128, 128, 128, 128, + 128, 128, 128, 128, + 128 +}; + +const float hvq_peak_cb[1024] = +{ + -0.6912956f, -0.6271097f, -0.7024875f, 0.4262808f, + -0.7780800f, -0.8390081f, -0.2123103f, 0.1755754f, + -0.6005284f, -0.6187206f, -0.1867433f, 0.5583949f, + -0.1626335f, -0.6971197f, -0.6486326f, 0.4250869f, + -0.8399908f, -0.8860587f, 0.0171807f, 0.2217064f, + -0.7976624f, -0.4009260f, -0.2953390f, 0.2432917f, + -0.0157667f, -0.6356865f, -0.3266405f, 0.8188483f, + -0.8489450f, -0.6545582f, 0.0063441f, 0.1921560f, + -0.4517379f, -0.8665710f, -0.2336057f, 0.1562026f, + 0.4618506f, -0.7325841f, -0.6645442f, 0.7730063f, + -0.3442883f, -0.7223252f, -0.6207414f, -0.0612312f, + -0.4947599f, -0.7362953f, 0.2769519f, 0.6891029f, + -0.6117975f, -0.7841619f, -0.0077496f, 0.1986304f, + -0.5240943f, -0.9067913f, 0.0485043f, 0.2167943f, + -0.5396412f, -0.1256491f, -0.1235545f, 0.6819669f, + -0.8648130f, -0.4241201f, 0.0204877f, 0.2068082f, + -0.5605495f, -0.5470207f, -0.2261054f, 0.1577327f, + -0.6742380f, -0.5969556f, 0.0214089f, 0.1821478f, + -0.2017185f, -0.8361119f, -0.1487647f, 0.2677230f, + -0.9043679f, -0.1694224f, 0.0082920f, 0.2133927f, + -0.2797693f, -0.6069181f, -0.2787998f, 0.1967338f, + -0.7057108f, -0.7816155f, 0.2978523f, 0.1754361f, + -0.3176815f, -0.9099026f, 0.0490125f, 0.2141907f, + -0.4198575f, -0.7583196f, 0.0635993f, 0.2175556f, + -0.5430584f, -0.4931615f, 0.0181889f, 0.2223880f, + -0.6798062f, -0.3401114f, 0.0158910f, 0.1975791f, + -0.4111015f, -0.6318658f, -0.0022674f, 0.2056921f, + 0.0577086f, -0.4957561f, -0.3895008f, 0.4151040f, + -0.0493461f, -0.8356919f, -0.2944458f, 0.0766301f, + -0.6653519f, -0.3581038f, -0.1475882f, -0.0488843f, + -0.2951041f, -0.8518280f, 0.1970185f, 0.1934331f, + -0.7088394f, -0.1404796f, 0.0230110f, 0.1779071f, + -0.2349629f, -0.7451124f, 0.0672633f, 0.1989080f, + -0.8420037f, 0.0843352f, 0.0575119f, 0.2087238f, + -0.4653422f, -0.3204370f, 0.0104996f, 0.2118398f, + -0.4042698f, -0.2978680f, -0.1369022f, 0.1310524f, + -0.3691715f, -0.4627771f, 0.0194469f, 0.1874501f, + -0.7932880f, -0.4999925f, 0.5272518f, 0.1987127f, + -0.3157207f, -0.7989150f, 0.0281708f, -0.0724433f, + -0.4063714f, -0.5531399f, 0.2087681f, 0.2166726f, + -0.6433928f, -0.7400934f, 0.1283951f, -0.2888276f, + -0.6992665f, -0.2153651f, 0.2638986f, 0.2449246f, + 0.0759221f, -0.6326668f, -0.0243810f, 0.4197445f, + -0.1053094f, -0.3928218f, 0.0776661f, 0.5284011f, + 0.0786145f, -0.5979541f, -0.3155530f, 0.1330860f, + -0.2138216f, -0.5920822f, 0.0591093f, 0.2060311f, + 0.5341295f, -0.7605932f, -0.5172090f, 0.2604366f, + -0.1048604f, -0.8851262f, 0.1927255f, 0.1973499f, + -0.5168340f, -0.1512779f, 0.0180467f, 0.2015491f, + 0.0335269f, -0.8175794f, -0.0216168f, 0.1691676f, + -0.1815545f, -0.4323540f, -0.1449728f, 0.1241323f, + -0.3259940f, -0.4574721f, -0.2285515f, -0.1586095f, + 0.0051494f, -0.1975091f, -0.1569577f, 0.4943931f, + -0.6204569f, 0.0525578f, 0.0120660f, 0.1902273f, + -0.4779290f, -0.6992531f, 0.7534508f, 0.4339787f, + -0.1187649f, -0.6976845f, 0.1573026f, 0.1922948f, + -0.2681343f, -0.3088476f, 0.0065871f, 0.2084513f, + -0.3780985f, -0.3375740f, 0.1472063f, 0.1975328f, + -0.2351356f, -0.1280155f, -0.1625378f, 0.2005500f, + -0.0170806f, -0.6339361f, -0.0847550f, 0.0556140f, + -0.2045688f, -0.4398525f, 0.0735149f, 0.1856326f, + -0.3233196f, -0.7640965f, 0.4361117f, 0.1472444f, + 0.0629942f, -0.7853858f, 0.5146322f, 0.6244928f, + -0.0839811f, -0.8881392f, 0.3847862f, 0.2300789f, + -0.2330840f, -0.5500582f, 0.0594403f, 0.0210406f, + -0.3345076f, -0.1781868f, 0.0208460f, 0.1883004f, + -0.7935783f, 0.3725855f, 0.3278117f, 0.4754694f, + -0.0642284f, -0.2632120f, -0.1505273f, 0.2129149f, + -0.3033468f, -0.4616954f, 0.3710885f, 0.2992681f, + -0.4248384f, -0.0016876f, 0.0134380f, 0.1927050f, + -0.0092953f, -0.1855540f, 0.3449483f, 0.7852289f, + -0.3791312f, -0.0964576f, 0.2097941f, 0.3001604f, + -0.0848375f, -0.5015270f, 0.1259740f, 0.1763195f, + 0.5429158f, -0.3354102f, -0.2024174f, 0.6442416f, + 0.3773962f, -0.8102532f, -0.3228953f, -0.0772150f, + -0.2048677f, -0.3115774f, 0.1465945f, 0.1916357f, + -0.1810441f, 0.0864401f, 0.1519246f, 0.5593738f, + 0.0822840f, -0.7269843f, -0.3622333f, -0.4062700f, + 0.1607091f, -0.3317170f, -0.2421061f, 0.1359637f, + -0.0962719f, -0.3355251f, 0.0679005f, 0.1770951f, + 0.0250174f, -0.3651731f, -0.0426421f, 0.1630863f, + -0.1534063f, -0.2206571f, 0.0377216f, 0.1773635f, + -0.0503107f, -0.6410940f, 0.2730565f, 0.1690477f, + -0.4957757f, -0.0244409f, -0.0162808f, -0.0955787f, + -0.2524313f, -0.0397484f, 0.0112025f, 0.1818186f, + -0.8109849f, -0.1058945f, 0.2174591f, -0.2708842f, + -0.1470562f, -0.1641739f, -0.1197168f, 0.0447477f, + 0.0588656f, -0.6303298f, 0.1348466f, 0.1117979f, + 0.0743650f, -0.8166042f, 0.3325572f, 0.1713777f, + -0.2014585f, -0.3172087f, 0.0655640f, 0.0041949f, + 0.4579843f, -0.6991156f, -0.1204969f, 0.1891217f, + -0.2764455f, -0.8453921f, 0.7031553f, 0.1247506f, + 0.2536679f, -0.0081430f, 0.0907404f, 0.7806163f, + -0.1158093f, -0.1102171f, -0.0149151f, 0.1648406f, + 0.2353252f, -0.7899960f, 0.1050820f, 0.0800406f, + -0.7417480f, 0.0943212f, 0.4042825f, 0.0998893f, + -0.0950040f, -0.0430378f, 0.1080511f, 0.3676440f, + 0.0093255f, -0.3641596f, -0.1371177f, -0.0609554f, + -0.5714336f, 0.2519692f, 0.2317291f, 0.2202618f, + -0.4146698f, -0.2566845f, 0.2659634f, -0.0347036f, + -0.3670773f, 0.1802618f, 0.5463926f, 0.6508593f, + -0.0678326f, -0.7015804f, 0.3010046f, -0.0498279f, + -0.0220688f, -0.1813971f, 0.0217875f, 0.1577779f, + 0.0649310f, -0.4638375f, 0.0635012f, 0.0496216f, + -0.0147237f, -0.2600337f, 0.2481463f, 0.3285215f, + 0.0016037f, -0.3668163f, 0.1572298f, 0.1535826f, + 0.0720517f, -0.4195340f, 0.7542142f, 0.8043668f, + 0.0327889f, -0.8709202f, 0.5519686f, 0.1322237f, + 0.0325743f, -0.6758953f, 0.4356905f, 0.1690573f, + 0.0222460f, -0.4592628f, 0.2421902f, 0.1418606f, + -0.5079813f, -0.1937920f, 0.7216264f, 0.2938249f, + -0.0027737f, -0.2586997f, 0.1006489f, 0.1311191f, + 0.1067900f, -0.2263411f, -0.0675541f, 0.0894570f, + -0.1463278f, -0.1350150f, 0.1979781f, 0.1301280f, + -0.2848267f, 0.1030649f, 0.2004989f, 0.1749749f, + 0.0528965f, -0.5370577f, 0.3406753f, 0.1271570f, + -0.0828084f, -0.4938643f, 0.4483900f, 0.1278149f, + -0.7256999f, 0.2998409f, 0.7843215f, 0.4678534f, + 0.0178764f, -0.5886182f, 0.6584490f, 0.3674424f, + 0.3457182f, -0.4777862f, 0.0898507f, 0.2238471f, + 0.2808650f, -0.5159423f, -0.1746428f, -0.1639121f, + -0.2412612f, -0.1413623f, 0.3805663f, 0.1746805f, + -0.0037664f, -0.5041469f, 0.0297737f, -0.2529321f, + 0.0385025f, -0.1210239f, -0.0919721f, -0.0045255f, + 0.0070289f, -0.0661929f, 0.0154059f, 0.1206527f, + -0.0688511f, -0.3501640f, 0.3048728f, 0.0806736f, + 0.1477360f, -0.2446724f, -0.1408905f, -0.0903137f, + 0.7393242f, -0.6937444f, 0.2281068f, 0.5408337f, + 0.2058932f, -0.1764501f, 0.1488327f, 0.2644186f, + -0.2103685f, -0.7390670f, 0.3717342f, -0.4480860f, + 0.0866347f, -0.2311362f, 0.1469333f, 0.0725029f, + 0.0817948f, -0.1216286f, 0.0533709f, 0.0628859f, + -0.0171689f, 0.0986378f, 0.0927410f, 0.1758267f, + 0.0104681f, -0.1266550f, 0.2014265f, 0.1157332f, + 0.1939706f, 0.2196828f, 0.3266076f, 0.7405447f, + -0.7823431f, -0.3710044f, 0.6980741f, -0.4465685f, + 0.0743889f, -0.2648934f, 0.2536655f, 0.0943156f, + 0.2177452f, -0.0949112f, 0.0081777f, 0.1387556f, + 0.1303671f, 0.1490959f, 0.1788726f, 0.4326436f, + 0.3473369f, -0.3169577f, -0.0234188f, 0.0441885f, + 0.0540186f, -0.8776336f, 0.8440490f, 0.1417058f, + -0.0917870f, -0.3147601f, 0.5500574f, 0.1602690f, + 0.2136007f, -0.5448702f, 0.2987510f, 0.0277404f, + 0.0474804f, -0.6571059f, 0.6386938f, 0.0971133f, + 0.8189747f, -0.7255339f, -0.0875124f, 0.1071008f, + -0.3016306f, -0.4416167f, 0.7533376f, 0.0058841f, + -0.1006996f, -0.1797670f, 0.1598059f, -0.1746155f, + -0.2759751f, -0.4375621f, 0.5324653f, -0.2187090f, + -0.0208548f, 0.0007885f, 0.1221271f, -0.0071798f, + 0.0937424f, -0.3872427f, 0.4131232f, 0.0814878f, + 0.1091490f, -0.3197269f, 0.3081368f, 0.0438068f, + 0.5405672f, -0.7493672f, 0.2284625f, 0.0522655f, + 0.2024367f, -0.2027840f, 0.0568407f, -0.0238867f, + 0.0971868f, -0.2548049f, 0.1213150f, -0.1210491f, + 0.2468838f, -0.7298202f, 0.2279600f, -0.2664659f, + 0.0852271f, -0.5106476f, 0.5313835f, 0.0594584f, + -0.1823397f, -0.4332103f, 0.0531194f, -0.6742789f, + 0.1030347f, -0.0238603f, 0.5571925f, 0.5078690f, + 0.1173396f, -0.1079135f, 0.1567269f, 0.0102248f, + 0.0996963f, -0.0219312f, 0.3216055f, 0.2366872f, + -0.3354882f, 0.1576330f, 0.5458030f, 0.1454629f, + 0.1444273f, -0.2365381f, 0.4773806f, 0.2506996f, + 0.1122540f, 0.0514636f, 0.1089756f, 0.0667886f, + -0.3413622f, 0.0448554f, 0.1877440f, -0.3506308f, + 0.1328394f, -0.0670468f, 0.0414011f, -0.0965496f, + 0.1299393f, -0.1839806f, 0.2569631f, -0.0070157f, + 0.1898328f, -0.0451201f, 0.0642396f, -0.0240266f, + -0.1290649f, -0.1413532f, 0.4606663f, -0.0510201f, + 0.0606055f, -0.4923670f, 0.4283018f, -0.1857787f, + 0.2395181f, -0.4428843f, 0.0877497f, -0.3090582f, + 0.1463607f, -0.4354426f, -0.2673760f, -0.7759982f, + 0.0363660f, -0.7473857f, 0.6714249f, -0.1897013f, + 0.0078778f, -0.3179395f, 0.8379888f, 0.3211752f, + -0.0229962f, 0.2191676f, 0.2311431f, 0.1050956f, + 0.1829474f, 0.0992829f, 0.7687454f, 0.7776823f, + 0.1946814f, -0.1941786f, 0.0124760f, -0.2574112f, + -0.1012860f, 0.0992883f, 0.3672758f, 0.0414330f, + 0.0971759f, -0.1978175f, 0.3925655f, -0.0065848f, + 0.7740223f, -0.2335201f, -0.0906675f, 0.1745083f, + 0.1516487f, -0.1042227f, 0.2148387f, -0.0795036f, + 0.0798246f, -0.6448072f, 0.8609363f, 0.0393394f, + 0.0779220f, -0.4600459f, 0.7273327f, 0.0570835f, + 0.4454859f, -0.2072924f, 0.2193948f, 0.1384101f, + 0.1703254f, -0.0609580f, 0.1299055f, -0.1323671f, + 0.1839394f, -0.3244128f, 0.3025059f, -0.1719029f, + 0.1127521f, -0.3544195f, 0.5826200f, 0.0178632f, + 0.1347488f, -0.2685010f, 0.4751232f, -0.0335460f, + -0.0268326f, 0.0229464f, 0.5944858f, 0.1651578f, + 0.1752550f, 0.0136593f, 0.3010034f, 0.0409467f, + 0.6297039f, -0.5169880f, -0.2259630f, -0.5169126f, + -0.3645581f, 0.5447856f, 0.5927204f, 0.1806151f, + 0.3826406f, -0.6356577f, 0.6929637f, 0.0339571f, + 0.1438846f, -0.1324825f, 0.3836886f, -0.1131758f, + 0.1225381f, -0.2508278f, 0.1022063f, -0.5355556f, + 0.1951728f, -0.0473224f, 0.1347071f, -0.2533568f, + 0.7506700f, -0.7468928f, 0.6686158f, 0.2984126f, + 0.1631571f, 0.0422823f, 0.2118532f, -0.1436800f, + -0.0460037f, 0.0633928f, 0.2509617f, -0.3180083f, + 0.1858027f, -0.1040863f, 0.2692820f, -0.1939493f, + 0.2203176f, 0.5295745f, 0.6812901f, 0.7900824f, + 0.2034420f, -0.0552806f, 0.0599414f, -0.4107925f, + 0.2479052f, -0.1359192f, 0.8121924f, 0.3484631f, + 0.1398457f, -0.2176905f, 0.5621405f, -0.1195728f, + -0.0080597f, 0.3218221f, 0.7571263f, 0.3912670f, + 0.2116680f, -0.6982532f, 0.3125198f, -0.7360096f, + 0.0948572f, -0.2203334f, 0.3659414f, -0.3956103f, + 0.1293136f, -0.3171252f, 0.7146217f, -0.0790813f, + 0.1411146f, -0.4510387f, 0.8887131f, -0.0377003f, + 0.2301871f, -0.0353170f, 0.5297350f, 0.0379717f, + 0.6152722f, -0.1928382f, 0.0785710f, -0.1588030f, + 0.1337912f, 0.1823085f, 0.3354832f, -0.0887607f, + 0.0494082f, -0.1225804f, 0.7939893f, 0.0220200f, + 0.1421773f, 0.3523192f, 0.4413828f, 0.1457048f, + -0.0882652f, 0.3232748f, 0.4595339f, -0.1386560f, + 0.0601664f, -0.4816208f, 0.8133457f, -0.3112419f, + 0.1845199f, -0.0171361f, 0.3659768f, -0.2448125f, + 0.1891260f, -0.0106495f, 0.2419292f, -0.3683512f, + 0.6530412f, -0.4171780f, 0.4613151f, 0.0030213f, + 0.1778989f, -0.1239391f, 0.5100323f, -0.2197134f, + -0.2717385f, 0.1272452f, 0.7572512f, -0.2318920f, + 0.3716251f, 0.1855403f, 0.5916812f, 0.3385713f, + 0.1300696f, 0.0471288f, 0.5215391f, -0.1457248f, + -0.2123145f, -0.1802899f, 0.5974199f, -0.7072856f, + 0.2174739f, -0.7171207f, 0.7595373f, -0.5396347f, + 0.1682724f, -0.1652717f, 0.7105864f, -0.1779208f, + 0.1949437f, -0.0545715f, 0.4387951f, -0.3539158f, + 0.1556118f, -0.2676762f, 0.8786431f, -0.1395478f, + 0.1839802f, -0.1270819f, 0.0981727f, -0.8218095f, + 0.1961324f, 0.0044393f, 0.2839973f, -0.5454667f, + 0.1691811f, 0.1170212f, 0.7761239f, -0.0004658f, + 0.2532176f, -0.3257096f, 0.6409724f, -0.4603164f, + 0.1836927f, -0.2327923f, 0.4239208f, -0.6877027f, + 0.8283811f, 0.0514265f, 0.3075364f, 0.1290827f, + 0.1590365f, -0.0471006f, 0.6768611f, -0.3246488f, + 0.1948562f, 0.1742693f, 0.4112475f, -0.3959884f, + 0.1608810f, 0.5362161f, 0.7247152f, 0.1551418f, + -0.0640990f, 0.2785439f, 0.4195016f, -0.6363523f, + -0.4977460f, 0.4795997f, 0.6537622f, -0.7041565f, + 0.1993300f, -0.0009453f, 0.5226769f, -0.5072073f, + 0.1647024f, -0.1025920f, 0.8690643f, -0.2884946f, + 0.1903634f, 0.0383981f, 0.4024816f, -0.6858912f, + 0.3935245f, -0.1394052f, 0.2460183f, -0.8132467f, + 0.0876800f, 0.1823305f, 0.6760031f, -0.4640969f, + 0.1928370f, -0.0154626f, 0.7054892f, -0.5314507f, + 0.7363694f, -0.4335648f, 0.3939214f, -0.6439396f, + 0.2216142f, 0.2584981f, 0.7753125f, -0.2883786f, + 0.1655171f, -0.0354699f, 0.9000988f, -0.4917610f, + 0.6522388f, 0.6980886f, 0.7493314f, 0.5121635f, + 0.2039644f, 0.0748634f, 0.4817260f, -0.8814858f, + 0.1984904f, 0.0331222f, 0.6597681f, -0.7397799f, + 0.6551378f, 0.0189344f, 0.7086707f, -0.2207969f, + 0.3331688f, 0.2704824f, 0.5667230f, -0.6593540f, + 0.2047795f, -0.0638265f, 0.8838190f, -0.7884763f, + 0.2100875f, 0.6368825f, 0.8423747f, -0.2746185f, + 0.2074577f, 0.1714071f, 0.8760290f, -0.6561672f, + 0.1851064f, 0.1440378f, 0.7655031f, -0.8835155f +}; + +const short hvq_pg_huff_offset[NUM_PG_HUFFLEN] = {0,2,3,8,9,11,13,15,19}; +const short hvq_pg_huff_thres[NUM_PG_HUFFLEN] = {0,0x2,0x4,0x18,0x20,0x40,0x80,0x100,0x300}; + +const short hvq_pg_huff_tab[32] = +{ + 30, 31, 1, 0, 2, 3, 28, 29, 4, 5, 27, 25, 26, 6, 24, 7, 8, 22, 23, 9, 10, 11, 12, 13, 14, + 15, 16, 17, 18, 19, 20, 21 +}; + +const short hvq_cp_huff_len[52] = +{ + 3, 4, 5, 6, 6, 6, 6, 6, 4, 4, 5, 5, 5, 5, 4, 4, 4, 5, 5, 5, 5, 5, 6, 6, 6, 6, 7, 7, 8, + 8, 8, 8, 8, 9, 10, 10, 11, 11, 11, 10, 10, 10, 10, 11, 12, 12, 13, 13, 12, 12, 11, 12 +}; + +const short hvq_cp_huff_val[52] = +{ + 7, 8, 6, 3, 4, 5, 6, 7, 9, 10, 7, 8, 9, 10, 11, 12, 13, 11, 12, 13, 14, 15, 8, 9, 10, + 11, 4, 5, 3, 4, 5, 6, 7, 5, 4, 5, 3, 4, 5, 6, 7, 8, 9, 6, 1, 2, 0, 1, 3, 4, 7, 5 +}; + +const short hvq_cp_layer1_map5[HVQ_CP_MAP_LEN] = { 16, 8, 4, 2, 1, 18, 17, 9 }; + +const short hvq_cp_huff_thres[HVQ_CP_HUFF_NUM_LEN] = { 0x0, 0x2, 0xC, 0x20, 0x50, 0x60, 0x100, 0x180, 0x600, 0x1000, 0x1C00 }; +const short hvq_cp_huff_offset[HVQ_CP_HUFF_NUM_LEN] = { 0, 2, 7, 12, 18, 19, 24, 26, 35, 45, 51 }; + +const short hvq_cp_huff_tab[52] = +{ + 46, 47, 44, 45, 48, 49, 51, 36, 37, 38, 43, 50, 34, 35, 39, 40, 41, 42, 33, 28, 29, 30, 31, 32, 26, 27, + 3, 4, 5, 6, 7, 22, 23, 24, 25, 2, 10, 11, 12, 13, 17, 18, 19, 20, 21, 1, 8, 9, 14, 15, 16, 0 +}; + +const short pow2_angle_res[8] = {16384, 17867, 19484, 21247, 23170, 25268, 27554, 30048}; /* Q14 */ + +/*----------------------------------------------------------------------------------* + * FEC for HQ core + *----------------------------------------------------------------------------------*/ + +const short Num_bands_NB[MAX_SB_NB] = {8,8,2}; + +const float SmoothingWin_NB875[70] = +{ + 0.00000000f,0.00050347f,0.00201285f,0.00452512f,0.00803521f,0.01253604f,0.01801857f,0.02447174f,0.03188256f,0.04023611f, + 0.04951557f,0.05970223f,0.07077560f,0.08271337f,0.09549150f,0.10908426f,0.12346427f,0.13860257f,0.15446869f,0.17103064f, + 0.18825510f,0.20610736f,0.22455151f,0.24355036f,0.26306567f,0.28305814f,0.30348748f,0.32431260f,0.34549150f,0.36698157f, + 0.38873953f,0.41072154f,0.43288338f,0.45518035f,0.47756758f,0.50000000f,0.52243245f,0.54481965f,0.56711662f,0.58927846f, + 0.61126047f,0.63301843f,0.65450847f,0.67568743f,0.69651252f,0.71694189f,0.73693430f,0.75644964f,0.77544850f,0.79389262f, + 0.81174493f,0.82896936f,0.84553134f,0.86139745f,0.87653571f,0.89091575f,0.90450847f,0.91728663f,0.92922437f,0.94029778f, + 0.95048445f,0.95976388f,0.96811742f,0.97552824f,0.98198146f,0.98746395f,0.99196482f,0.99547487f,0.99798715f,0.99949653f +}; + +const float SmoothingWin_NB2[16] = +{ + 0.00000000f,0.00960736f,0.03806023f,0.08426519f,0.14644661f,0.22221488f,0.30865828f,0.40245484f,0.50000000f,0.59754516f, + 0.69134172f,0.77778512f,0.85355339f,0.91573481f,0.96193977f,0.99039264f +}; + +/*----------------------------------------------------------------------------------* + * SC-VBR + *----------------------------------------------------------------------------------*/ + +const float bp1_num_coef_wb[5] = {0.9329833984375,0,-1.865966796875,0,0.9329833984375}; +const float bp1_den_coef_wb[5] = {1,0,-1.8614501953125,0,0.8704833984375}; + +const float shape1_num_coef[11] = +{ + 0.959381103515625f, -0.074554443359375f, -0.4161376953125f, 0.1317138671875f, + -0.3109130859375f, 0.00146484375f, 0.080535888671875f, -0.109100341796875f, + -0.023681640625f, 0.03192138671875f, 0.012176513671875f +}; + +const float shape1_den_coef[11] = +{ + 1, 0.0897216796875f, -0.373443603515625f, 0.123046875f, -0.293243408203125f, + -0.06097412109375f, 0.071258544921875f, -0.1190185546875f, -0.048675537109375f, + 0.026153564453125f, 0.007720947265625f +}; + +const float shape2_num_coef[11] = +{ + 0.938720703125f, 0.000946044921875f, -0.295989990234375f, 0.2904052734375f, + -0.17938232421875f, -0.221221923828125f, -0.3194580078125f, 0.01348876953125f, + 0.10003662109375f, -0.001922607421875f, 0.034027099609375f +}; + +const float shape2_den_coef[11] = +{ + 1, 0.488861083984375f, -0.02716064453125f, 0.390594482421875f, 0.07159423828125f, + -0.213165283203125f, -0.402587890625f, -0.176849365234375f, -0.028961181640625f, + -0.0455322265625f, -0.00927734375f +}; + +const float shape3_num_coef[11] = +{ + 0.936431884765625f, -0.011688232421875f, -0.303253173828125f, -0.293121337890625f, + -0.183013916015625f, 0.232269287109375f, -0.317169189453125f, -0.010833740234375f, + 0.098846435546875f, 0.0003662109375f, 0.0364990234375f +}; + +const float shape3_den_coef[11] = +{ + 1, -0.50347900390625f, -0.027801513671875f, -0.395111083984375f, 0.06976318359375f, + 0.22674560546875f, -0.408477783203125f, 0.18511962890625f, -0.03607177734375f, + 0.0482177734375f, -0.008331298828125f +}; + +const float txlpf1_num_coef[11] = +{ + 0.016845703125, 0.024169921875, 0.062744140625, 0.0831298828125, 0.1124267578125, + 0.11767578125, 0.1124267578125, 0.0831298828125, 0.062744140625, 0.024169921875, + 0.016845703125 +}; + +const float txlpf1_den_coef[11] = +{ + 1, -2.3126220703125, 3.8590087890625, -3.8023681640625, 2.989990234375, + -1.5567626953125, 0.6748046875, -0.17529296875, 0.0423583984375, -0.0030517578125, + 0.00048828125 +}; + +const float txhpf1_num_coef[11] = +{ + 0.016845703125, -0.024169921875, 0.062744140625, -0.0831298828125, 0.1124267578125, + -0.11767578125, 0.1124267578125, -0.0831298828125, 0.062744140625, -0.024169921875, + 0.016845703125 +}; + +const float txhpf1_den_coef[11] = +{ + 1, 2.3126220703125, 3.8590087890625, 3.8023681640625, 2.989990234375, 1.5567626953125, + 0.6748046875, 0.17529296875, 0.0423583984375, 0.0030517578125, 0.00048828125 +}; + +/* NELP filter coefficients */ +const float bp1_num_coef_nb_fx_order7[8] = +{ + 0.180780569293627f, 0.821512462016641f, 1.901786162198923f, 2.798216464912205f, + 2.798216464912205f, 1.901786162198923f, 0.821512462016641f, 0.180780569293627f +}; + +const float bp1_den_coef_nb_fx_order7[8] = +{ + 1.0f, 1.972212566911875f, 2.906981567843655f, 2.667903533650106f, + 1.784691945273023f, 0.807367818229743f, 0.232764318343094f, 0.032669566591295f +}; + + +/* order 8 LPF for nelp frames when non-native sampling freq inputs used with -max_band NB */ +/* used to suppress frequencies above 4kHz present at the output of filters in pre_proc() */ + +const float num_nelp_lp[NELP_LP_ORDER+1] = +{ + 0.088754442436105f, 0.427948705228526f, 1.097120864220837f, 1.834535180016855f, + 2.164546590741725f, 1.833722723336889f, 1.096120298806107f, 0.427341227067866f, 0.088564563680987f +}; + +const float den_nelp_lp[NELP_LP_ORDER+1] = +{ + 1.000000000000000f, 1.076558216566388f, 2.638952788853937f, 1.485213059043660f, + 1.941109655171129f, 0.433697456681428f, 0.488030665133170f, -0.014677457543018f, 0.043067530202687f +}; + + + +/* NELP gain tables */ +const float UVG1CB_WB[UVG1_CBSIZE][2] = +{ + { -0.271424f, -0.258097f, }, + { 1.546157f, 1.503115f, }, + { 0.454480f, 1.182801f, }, + { 2.182661f, 2.194626f, }, + { 0.504902f, 0.481656f, }, + { 1.416585f, 2.597607f, }, + { 1.193427f, 1.140118f, }, + { 2.649107f, 2.640023f, }, + { 0.132870f, 0.204961f, }, + { 1.708137f, 1.672001f, }, + { 1.274749f, 0.636471f, }, + { 2.405026f, 2.403867f, }, + { 0.666233f, 0.649061f, }, + { 2.081430f, 2.065141f, }, + { 1.734086f, 1.037998f, }, + { 2.969951f, 2.962773f, }, + { -0.014392f, -0.034103f, }, + { 1.417866f, 1.814293f, }, + { 0.842041f, 0.798819f, }, + { 2.308757f, 2.275084f, }, + { 0.139464f, 0.831392f, }, + { 1.952503f, 1.961636f, }, + { 0.844903f, 1.609146f, }, + { 2.790210f, 2.775995f, }, + { 0.368318f, 0.275885f, }, + { 1.825159f, 1.830021f, }, + { 0.998048f, 0.987868f, }, + { 2.529417f, 2.508405f, }, + { 0.908356f, 0.289270f, }, + { 2.184707f, 1.707541f, }, + { 1.341007f, 1.338580f, }, + { 3.185808f, 3.172863f, }, +}; + +const float UVG1CB_NB[UVG1_CBSIZE][2] = +{ + { -0.584898f, -0.629564f, }, + { 0.588898f, 0.602697f, }, + { -0.420328f, 0.440621f, }, + { 0.676153f, 1.866763f, }, + { -0.057218f, -0.486523f, }, + { 0.973746f, 0.995785f, }, + { 0.335472f, 0.304245f, }, + { 1.717476f, 1.710655f, }, + { -0.303435f, -0.349463f, }, + { 0.736475f, 0.719210f, }, + { 0.326864f, -0.053863f, }, + { 1.433214f, 1.440908f, }, + { -0.031290f, -0.103346f, }, + { 1.117363f, 1.089082f, }, + { -0.012970f, 0.729895f, }, + { 2.060025f, 2.043535f, }, + { -0.437514f, -0.472825f, }, + { 0.428648f, 1.164362f, }, + { 0.049001f, 0.050772f, }, + { 1.352832f, 1.287837f, }, + { -0.173046f, -0.210522f, }, + { 1.097114f, 0.641427f, }, + { 0.765980f, 0.138765f, }, + { 1.876515f, 1.861232f, }, + { -0.475929f, 0.036795f, }, + { 0.851593f, 0.866113f, }, + { 0.192944f, 0.177338f, }, + { 1.585417f, 1.565396f, }, + { 0.328590f, -0.377592f, }, + { 1.193646f, 1.239326f, }, + { 0.480756f, 0.442872f, }, + { 2.297758f, 2.282144f, }, +}; + +const float UVG2CB1_WB[UVG2_CBSIZE][5] = +{ + { 0.223040f, 0.241651f, 0.363680f, 1.453550f, 0.639043f, }, + { 1.367034f, 1.128134f, 0.995599f, 0.852711f, 0.746318f, }, + { 1.203618f, 0.984239f, 0.732146f, 0.524829f, 0.416474f, }, + { 1.885173f, 0.737643f, 0.440409f, 0.360901f, 0.354375f, }, + { 0.285902f, 0.339404f, 1.683466f, 0.632872f, 0.362779f, }, + { 1.014419f, 1.046733f, 1.076532f, 1.102226f, 1.117500f, }, + { 0.886868f, 0.893899f, 0.901808f, 0.906043f, 0.912148f, }, + { 3.225548f, 1.222902f, 0.637340f, 0.530948f, 0.499932f, }, + { 0.907185f, 0.704885f, 0.549973f, 0.479615f, 0.420607f, }, + { 1.743322f, 1.114901f, 0.838360f, 0.725076f, 0.584914f, }, + { 0.697213f, 0.741751f, 0.795735f, 0.849916f, 0.905532f, }, + { 1.447413f, 1.332714f, 1.201884f, 1.085950f, 0.997001f, }, + { 0.239259f, 0.250031f, 0.378390f, 1.388066f, 1.962520f, }, + { 0.858277f, 1.795467f, 2.537226f, 0.883659f, 0.697253f, }, + { 0.634313f, 0.755069f, 0.874414f, 1.167114f, 1.456359f, }, + { 0.479120f, 2.683769f, 1.225698f, 0.698405f, 0.631620f, }, + { 0.194304f, 0.223532f, 0.246663f, 0.286883f, 1.884711f, }, + { 1.085250f, 1.075760f, 1.060584f, 1.037376f, 1.019217f, }, + { 0.355082f, 1.585122f, 0.637538f, 0.429221f, 0.431000f, }, + { 1.537046f, 1.876537f, 1.162872f, 0.718938f, 0.537773f, }, + { 0.366750f, 0.384063f, 0.462624f, 0.727828f, 1.333889f, }, + { 1.159580f, 1.178847f, 1.198408f, 1.203392f, 1.195077f, }, + { 0.889680f, 0.921507f, 0.957437f, 0.985704f, 1.004871f, }, + { 2.209824f, 1.807385f, 1.465675f, 1.158738f, 0.996400f, }, + { 0.380420f, 0.456231f, 0.569092f, 0.732313f, 0.877647f, }, + { 1.140464f, 1.134349f, 1.126392f, 1.111634f, 1.094200f, }, + { 0.552280f, 0.636810f, 0.771019f, 0.949718f, 1.090795f, }, + { 1.356338f, 1.328390f, 1.665898f, 1.744565f, 1.397443f, }, + { 0.358875f, 0.378330f, 0.492142f, 2.726906f, 0.934503f, }, + { 1.339929f, 1.530712f, 1.653071f, 2.002372f, 2.265826f, }, + { 0.848927f, 0.901721f, 1.004240f, 1.088962f, 1.148716f, }, + { 2.655634f, 4.390627f, 2.488829f, 1.779943f, 0.689514f, }, + { 0.323918f, 0.365752f, 0.360473f, 0.406899f, 0.521889f, }, + { 1.089529f, 1.049556f, 0.999532f, 0.947192f, 0.910775f, }, + { 0.778315f, 0.772521f, 0.770412f, 0.757735f, 0.766615f, }, + { 2.382149f, 1.389184f, 0.821738f, 0.560577f, 0.437522f, }, + { 0.422645f, 0.427987f, 3.028798f, 0.996559f, 0.548607f, }, + { 0.943902f, 0.991288f, 1.222348f, 1.287613f, 1.275699f, }, + { 0.976039f, 0.966009f, 0.952110f, 0.937347f, 0.925149f, }, + { 4.404412f, 2.299179f, 1.359051f, 0.845995f, 0.611213f, }, + { 0.527446f, 0.618156f, 0.706851f, 0.629108f, 0.566558f, }, + { 1.233373f, 1.169295f, 1.096161f, 1.026234f, 0.965180f, }, + { 0.825364f, 0.833740f, 0.844135f, 0.853512f, 0.863188f, }, + { 1.505253f, 1.418813f, 1.328096f, 1.229135f, 1.135295f, }, + { 0.693032f, 0.827423f, 1.234705f, 1.845313f, 2.542454f, }, + { 0.945943f, 1.081860f, 1.265427f, 1.540595f, 1.749407f, }, + { 1.052402f, 1.008307f, 0.871943f, 0.749492f, 2.088583f, }, + { 2.146194f, 2.016499f, 1.782081f, 1.524242f, 1.323508f, }, + { 0.290883f, 0.301913f, 0.334033f, 0.442895f, 2.885471f, }, + { 0.606905f, 1.398622f, 1.501382f, 1.030661f, 0.895216f, }, + { 0.980941f, 0.933889f, 0.878940f, 0.827155f, 0.794956f, }, + { 1.832121f, 1.420187f, 1.218118f, 0.992368f, 0.811142f, }, + { 0.349042f, 0.479090f, 1.353992f, 0.999951f, 1.142766f, }, + { 1.316650f, 1.312876f, 1.299885f, 1.276895f, 1.233464f, }, + { 0.986649f, 0.998506f, 1.008895f, 1.015456f, 1.020661f, }, + { 3.044209f, 2.251119f, 1.400128f, 0.883141f, 0.610713f, }, + { 0.606060f, 0.626282f, 0.675680f, 0.754010f, 0.845070f, }, + { 1.271739f, 1.240164f, 1.197404f, 1.148908f, 1.103891f, }, + { 0.766260f, 0.820830f, 0.890415f, 0.954560f, 1.014693f, }, + { 1.742866f, 1.608286f, 1.450560f, 1.281919f, 1.141203f, }, + { 0.419616f, 0.455676f, 1.951458f, 1.863714f, 0.973334f, }, + { 0.875636f, 1.291339f, 1.924261f, 3.300506f, 3.929508f, }, + { 0.588088f, 0.613937f, 0.671033f, 1.786119f, 1.131808f, }, + { 7.419703f, 4.514918f, 3.368681f, 1.171582f, 0.557291f, }, +}; + +const float UVG2CB2_WB[UVG2_CBSIZE][5] = +{ + { 0.382157f, 0.339570f, 0.399108f, 1.276274f, 0.654653f, }, + { 0.526317f, 0.624477f, 1.514850f, 1.357657f, 0.962890f, }, + { 0.497765f, 0.587492f, 0.755478f, 0.832206f, 0.968825f, }, + { 1.242760f, 1.236637f, 1.218059f, 1.186075f, 1.163104f, }, + { 0.350569f, 0.423863f, 0.687511f, 0.576640f, 0.586036f, }, + { 1.068227f, 1.080389f, 1.090163f, 1.093335f, 1.096811f, }, + { 1.134662f, 0.996393f, 0.866640f, 0.727742f, 0.651101f, }, + { 0.416366f, 0.476179f, 0.898235f, 1.911077f, 2.415833f, }, + { 0.693081f, 0.445820f, 0.352293f, 0.295523f, 0.303834f, }, + { 0.338564f, 0.344193f, 0.431633f, 2.166267f, 1.070002f, }, + { 0.981922f, 0.923891f, 0.870264f, 0.809574f, 0.755981f, }, + { 2.437343f, 1.744939f, 1.275522f, 0.913573f, 0.738923f, }, + { 1.652469f, 0.575451f, 0.373855f, 0.353600f, 0.379997f, }, + { 1.120803f, 1.140296f, 1.155888f, 1.163382f, 1.169191f, }, + { 1.051700f, 1.024805f, 0.989204f, 0.951249f, 0.920163f, }, + { 0.558571f, 0.622568f, 1.201735f, 2.024839f, 3.632277f, }, + { 0.332205f, 0.361342f, 0.368816f, 0.486187f, 2.551270f, }, + { 0.716016f, 0.764423f, 0.901925f, 1.144217f, 1.269692f, }, + { 0.972618f, 0.744037f, 0.605346f, 0.645594f, 1.346183f, }, + { 1.306825f, 1.337871f, 1.339887f, 1.326540f, 1.327383f, }, + { 0.810386f, 0.703444f, 0.617077f, 0.525349f, 0.470428f, }, + { 1.189609f, 1.159137f, 1.117761f, 1.075965f, 1.039311f, }, + { 1.509928f, 1.073290f, 0.915705f, 0.830047f, 0.707661f, }, + { 0.527199f, 1.969524f, 1.839455f, 1.250142f, 0.888607f, }, + { 0.553059f, 2.484691f, 0.928542f, 0.631924f, 0.595981f, }, + { 0.534157f, 0.538470f, 1.048001f, 3.098313f, 1.438832f, }, + { 0.875629f, 0.891265f, 0.918069f, 0.943470f, 0.966723f, }, + { 3.212350f, 2.380788f, 1.750784f, 1.325976f, 1.309454f, }, + { 1.393980f, 1.018875f, 0.714902f, 0.510150f, 0.433226f, }, + { 0.861995f, 0.935236f, 1.133018f, 1.412823f, 1.616763f, }, + { 1.073054f, 1.063390f, 1.045198f, 1.023854f, 1.003573f, }, + { 0.547694f, 0.604539f, 1.419472f, 0.968088f, 6.634663f, }, + { 0.384404f, 0.407015f, 1.841710f, 0.733522f, 0.484417f, }, + { 0.630723f, 0.612993f, 2.852480f, 1.407572f, 1.173696f, }, + { 0.886615f, 0.844153f, 0.800046f, 0.760230f, 0.725250f, }, + { 2.092080f, 1.654743f, 1.432156f, 1.346378f, 1.255149f, }, + { 0.797508f, 0.740916f, 0.717801f, 0.679101f, 0.657052f, }, + { 0.959244f, 1.037313f, 1.117438f, 1.190695f, 1.260351f, }, + { 1.084782f, 1.018723f, 0.943477f, 0.876418f, 0.814781f, }, + { 0.976114f, 1.153683f, 1.398515f, 1.677934f, 1.925023f, }, + { 1.066698f, 0.689574f, 0.546216f, 0.402266f, 0.342894f, }, + { 0.244053f, 0.249520f, 0.360608f, 0.654699f, 3.729612f, }, + { 0.955958f, 0.940178f, 0.919330f, 0.894537f, 0.876740f, }, + { 3.224046f, 1.094907f, 0.788658f, 0.951478f, 0.890611f, }, + { 2.441966f, 0.858237f, 0.584262f, 0.545170f, 0.539909f, }, + { 1.123818f, 1.180721f, 1.238015f, 1.283992f, 1.321097f, }, + { 0.956697f, 0.985042f, 1.019696f, 1.050902f, 1.078825f, }, + { 0.743688f, 2.034202f, 4.022331f, 2.727508f, 2.650772f, }, + { 0.250845f, 0.245822f, 0.291984f, 0.385336f, 1.449503f, }, + { 0.461815f, 0.591238f, 0.787875f, 0.956948f, 1.806615f, }, + { 0.875089f, 0.862359f, 0.856436f, 0.847061f, 0.839057f, }, + { 1.309442f, 1.502701f, 1.661279f, 1.673280f, 1.662961f, }, + { 0.985927f, 0.857309f, 0.739752f, 0.643488f, 0.569376f, }, + { 1.650427f, 1.495147f, 1.278185f, 1.049539f, 0.900202f, }, + { 1.006963f, 1.593657f, 0.993154f, 0.790603f, 0.850326f, }, + { 1.225572f, 1.441567f, 1.728901f, 2.088278f, 2.349483f, }, + { 0.341446f, 1.432559f, 0.749195f, 0.421280f, 0.404079f, }, + { 1.145314f, 1.033705f, 0.970105f, 0.917177f, 2.347552f, }, + { 0.971156f, 0.977194f, 0.977277f, 0.972506f, 0.966892f, }, + { 0.513513f, 4.115618f, 2.258778f, 1.186578f, 1.154071f, }, + { 1.963588f, 1.292572f, 0.969148f, 0.756260f, 0.630658f, }, + { 1.142688f, 1.247234f, 1.361439f, 1.456244f, 1.531956f, }, + { 1.188195f, 1.119173f, 1.043934f, 0.966349f, 0.898995f, }, + { 0.296171f, 0.760591f, 1.599661f, 5.561118f, 5.121441f, }, +}; + + +const float UVG2CB1_NB[UVG2_CBSIZE][5] = +{ + { 0.188739f, 0.191757f, 0.191531f, 0.191578f, 0.209839f, }, + { 0.869071f, 0.859505f, 0.832542f, 0.797074f, 0.773080f, }, + { 0.431109f, 0.727906f, 2.508026f, 0.925174f, 0.548901f, }, + { 1.217337f, 1.160289f, 1.097694f, 1.018471f, 0.957574f, }, + { 0.497102f, 0.495688f, 0.490534f, 0.481662f, 0.463058f, }, + { 0.803575f, 0.867673f, 0.944431f, 1.007241f, 1.060698f, }, + { 0.783034f, 0.762224f, 0.738827f, 0.711210f, 0.682893f, }, + { 3.227538f, 1.670940f, 0.968417f, 0.670516f, 0.602001f, }, + { 0.379041f, 0.397159f, 0.339889f, 0.431105f, 0.898154f, }, + { 1.313227f, 1.132838f, 0.938410f, 0.794448f, 0.643291f, }, + { 0.390638f, 0.395881f, 0.593166f, 2.306134f, 1.028762f, }, + { 1.248727f, 1.269418f, 1.296714f, 1.309796f, 1.304405f, }, + { 1.520874f, 0.734382f, 0.485483f, 0.396077f, 0.389855f, }, + { 0.421502f, 0.516180f, 1.720254f, 1.504402f, 1.050148f, }, + { 0.245081f, 0.257874f, 0.449391f, 1.466236f, 1.733604f, }, + { 1.559619f, 2.358229f, 1.100964f, 0.677191f, 0.515930f, }, + { 0.258870f, 0.281444f, 0.341911f, 0.423056f, 0.517793f, }, + { 0.841801f, 0.860159f, 0.881827f, 0.899050f, 0.920338f, }, + { 0.365189f, 0.499345f, 0.710492f, 0.869768f, 0.990808f, }, + { 1.078960f, 1.121199f, 1.170587f, 1.201313f, 1.215423f, }, + { 0.343519f, 1.297406f, 0.680773f, 0.408835f, 0.329668f, }, + { 1.027852f, 1.031491f, 1.031891f, 1.021937f, 1.017812f, }, + { 0.548592f, 2.012860f, 1.072282f, 0.615844f, 0.417353f, }, + { 1.760444f, 1.645651f, 1.491751f, 1.317721f, 1.142677f, }, + { 0.879361f, 0.558186f, 0.385066f, 0.300063f, 0.280186f, }, + { 1.629306f, 1.276033f, 0.873148f, 0.597645f, 0.464031f, }, + { 0.233010f, 0.252664f, 0.263381f, 0.410771f, 2.333462f, }, + { 0.979199f, 1.428996f, 2.192152f, 1.742747f, 1.094684f, }, + { 0.679754f, 0.659549f, 0.643852f, 0.621674f, 0.603191f, }, + { 1.077752f, 0.992367f, 1.129539f, 1.027383f, 2.264297f, }, + { 0.676422f, 0.735375f, 0.819505f, 0.911898f, 0.992613f, }, + { 4.819767f, 2.100243f, 0.962614f, 0.621495f, 0.509149f, }, + { 0.276365f, 0.274270f, 0.270315f, 0.266915f, 0.271854f, }, + { 0.955282f, 0.937005f, 0.911375f, 0.886292f, 0.866125f, }, + { 0.231384f, 0.382150f, 1.480144f, 0.647910f, 0.407074f, }, + { 1.503587f, 1.359087f, 1.192322f, 1.035379f, 0.920358f, }, + { 0.225897f, 0.284201f, 0.386850f, 1.479923f, 0.754288f, }, + { 0.932117f, 0.985694f, 1.055295f, 1.107535f, 1.153749f, }, + { 1.047555f, 0.950740f, 0.840054f, 0.733910f, 0.667261f, }, + { 2.085890f, 1.583746f, 1.211518f, 0.930697f, 0.725212f, }, + { 0.425680f, 0.429169f, 0.415950f, 0.398797f, 0.384700f, }, + { 1.078194f, 1.039819f, 0.987399f, 0.930104f, 0.885793f, }, + { 0.468506f, 0.527117f, 0.811323f, 3.412384f, 1.928112f, }, + { 1.453081f, 1.399223f, 1.322881f, 1.235534f, 1.155194f, }, + { 0.677564f, 0.686571f, 0.612173f, 0.620178f, 1.607781f, }, + { 0.838759f, 0.966836f, 1.138047f, 1.458807f, 1.531620f, }, + { 0.752352f, 0.769151f, 0.792542f, 0.814617f, 0.830990f, }, + { 0.998295f, 3.910764f, 2.022774f, 1.004988f, 0.660092f, }, + { 0.346421f, 0.347923f, 0.341870f, 0.334828f, 0.332826f, }, + { 0.933744f, 0.949722f, 0.965032f, 0.974951f, 0.980120f, }, + { 0.609754f, 0.656553f, 0.694920f, 0.735124f, 0.784513f, }, + { 1.250595f, 1.226482f, 1.191682f, 1.145255f, 1.104473f, }, + { 0.557881f, 0.567717f, 0.565744f, 0.564657f, 0.554475f, }, + { 1.096985f, 1.105627f, 1.102877f, 1.093358f, 1.084804f, }, + { 2.230968f, 0.968956f, 0.615720f, 0.542594f, 0.589697f, }, + { 2.443527f, 2.128707f, 1.780354f, 1.424964f, 1.106474f, }, + { 0.202766f, 0.221654f, 0.253737f, 0.404291f, 1.663403f, }, + { 0.505346f, 1.337503f, 1.263272f, 0.954743f, 0.901882f, }, + { 0.385023f, 0.382150f, 0.399218f, 0.630553f, 3.211494f, }, + { 1.364681f, 1.413025f, 1.445785f, 1.648508f, 1.724301f, }, + { 0.991474f, 0.853670f, 0.661673f, 0.512336f, 0.418893f, }, + { 0.671308f, 0.761259f, 4.046266f, 1.926581f, 0.891469f, }, + { 0.634219f, 0.750043f, 0.930049f, 1.197664f, 1.262605f, }, + { 3.747086f, 2.672835f, 1.889530f, 1.215477f, 0.841197f, }, +}; + +const float UVG2CB2_NB[UVG2_CBSIZE][5]= +{ + { 0.234676f, 0.211553f, 0.198300f, 0.188137f, 0.189102f, }, + { 0.621072f, 0.655881f, 0.734889f, 0.880212f, 1.232321f, }, + { 0.372062f, 0.443795f, 0.705281f, 0.739519f, 0.743747f, }, + { 1.024051f, 1.049997f, 1.079370f, 1.098001f, 1.118202f, }, + { 0.494519f, 0.485721f, 0.479727f, 0.474381f, 0.473326f, }, + { 1.059136f, 1.014755f, 0.967436f, 0.915428f, 0.876510f, }, + { 1.887753f, 0.709034f, 0.440367f, 0.343384f, 0.369381f, }, + { 0.393820f, 0.574466f, 2.762395f, 1.407229f, 1.047606f, }, + { 0.370772f, 0.356840f, 0.349999f, 0.327343f, 0.316005f, }, + { 0.397170f, 0.417453f, 0.528104f, 2.356989f, 1.370805f, }, + { 0.566954f, 1.780471f, 0.793633f, 0.493204f, 0.504320f, }, + { 1.212718f, 1.247958f, 1.263151f, 1.270187f, 1.276770f, }, + { 0.388100f, 0.353795f, 0.474245f, 1.451972f, 0.869892f, }, + { 1.891456f, 1.262146f, 0.797925f, 0.583916f, 0.508257f, }, + { 0.969344f, 0.868915f, 0.772349f, 0.677308f, 0.608680f, }, + { 0.486474f, 0.539484f, 0.782305f, 0.907366f, 5.745668f, }, + { 0.289328f, 0.301705f, 0.347406f, 0.516255f, 1.165024f, }, + { 0.960737f, 0.937409f, 0.906673f, 0.874736f, 0.848802f, }, + { 0.400429f, 0.378419f, 0.439385f, 0.636950f, 2.656142f, }, + { 0.992977f, 1.083218f, 1.174551f, 1.247095f, 1.351591f, }, + { 0.359381f, 0.333729f, 0.374249f, 0.520426f, 1.795028f, }, + { 1.052276f, 1.045824f, 1.029194f, 1.005147f, 0.990365f, }, + { 2.640896f, 1.119783f, 0.637471f, 0.504513f, 0.497219f, }, + { 0.510018f, 0.592500f, 1.147016f, 3.572948f, 1.835225f, }, + { 0.617425f, 0.380988f, 0.295255f, 0.238370f, 0.230673f, }, + { 0.709915f, 0.749521f, 0.990016f, 1.431043f, 1.574221f, }, + { 0.653333f, 0.698564f, 0.760571f, 0.804532f, 0.831992f, }, + { 0.715875f, 3.498556f, 1.594958f, 0.912733f, 0.845138f, }, + { 0.898701f, 0.751704f, 0.624648f, 0.525250f, 0.464610f, }, + { 1.375977f, 1.297850f, 1.215381f, 1.145089f, 1.080297f, }, + { 0.561123f, 1.764692f, 1.703012f, 1.037951f, 0.817155f, }, + { 0.611282f, 0.835322f, 1.656358f, 2.071091f, 3.677700f, }, + { 0.305955f, 0.288104f, 0.277282f, 0.266999f, 0.262681f, }, + { 0.842437f, 0.860463f, 0.878879f, 0.890085f, 0.905076f, }, + { 0.415168f, 0.495616f, 1.605015f, 1.158622f, 1.086554f, }, + { 1.144592f, 1.160015f, 1.162718f, 1.153999f, 1.152784f, }, + { 0.726849f, 0.577021f, 0.459744f, 0.381537f, 0.341456f, }, + { 1.240211f, 1.143782f, 1.043599f, 0.936329f, 0.857727f, }, + { 1.329362f, 0.934539f, 0.696166f, 0.547436f, 0.475481f, }, + { 0.470979f, 1.229760f, 4.335935f, 2.037582f, 1.538102f, }, + { 0.448859f, 0.435001f, 0.410153f, 0.387131f, 0.374390f, }, + { 0.753476f, 0.847563f, 0.984091f, 1.208422f, 2.367011f, }, + { 0.781083f, 0.745169f, 0.707134f, 0.671579f, 0.640062f, }, + { 1.421280f, 1.411590f, 1.398311f, 1.358993f, 1.337416f, }, + { 0.377859f, 0.545381f, 1.647399f, 0.625545f, 0.420396f, }, + { 1.635438f, 1.273369f, 1.092522f, 0.862149f, 0.739370f, }, + { 0.921246f, 0.885689f, 0.844748f, 0.800456f, 0.770371f, }, + { 0.385947f, 0.408195f, 0.715197f, 4.936704f, 4.011602f, }, + { 0.295343f, 0.296573f, 0.339012f, 0.409703f, 0.531531f, }, + { 0.943088f, 0.948849f, 0.961247f, 0.966943f, 0.973872f, }, + { 0.376239f, 0.425963f, 0.446486f, 0.849370f, 3.799501f, }, + { 1.085015f, 1.208963f, 1.360517f, 1.478597f, 1.597861f, }, + { 0.600520f, 0.585154f, 0.557646f, 0.520820f, 0.498211f, }, + { 1.173770f, 1.141539f, 1.096824f, 1.055073f, 1.028510f, }, + { 3.669747f, 1.622178f, 0.809242f, 0.707943f, 0.704413f, }, + { 0.977405f, 1.162230f, 1.695878f, 2.019914f, 2.051052f, }, + { 1.221003f, 0.609077f, 0.389066f, 0.326390f, 0.333196f, }, + { 0.836930f, 0.904878f, 0.994299f, 1.088050f, 1.140088f, }, + { 0.812087f, 0.799997f, 0.786734f, 0.767023f, 0.753822f, }, + { 1.504493f, 1.542127f, 1.585432f, 1.577024f, 1.594146f, }, + { 0.649261f, 0.634440f, 0.619454f, 0.606033f, 0.621463f, }, + { 2.088260f, 1.685051f, 1.277621f, 1.004769f, 0.891082f, }, + { 1.133569f, 1.000746f, 0.882781f, 0.781417f, 0.706843f, }, + { 2.340990f, 6.501577f, 3.762808f, 3.059604f, 2.127793f, }, +}; + +const float frac_4sf[NB_SUBFR+2] = {0.25f,0.5f,0.75f,1.0f,1.0f,1.0f}; + +/* ERB table for PPP-ampl-quant */ +const float erb_WB[NUM_ERB_WB+1] = {0.0f, 92.8061f, 185.6121f, 278.4182f, 371.2243f, 464.0304f, 556.8364f, 649.6425f, 746.4f, 853.6f, + 972.5f, 1104.0f, 1251.8f, 1415.8f, 1599.2f, 1804.6f, 2035.2f, 2294.9f, 2588.4f, 2921.2f, 3300.1f, + 3733.7f, 4400.0f, 5300.0f, 6400.0f+1 + }; + +/* ERB table for PPP-ampl-quant */ +const float erb_NB[NUM_ERB_NB+1] = {0.0f, 92.8061f, 185.6121f, 278.4182f, 371.2243f, 464.0304f, 556.8364f, 649.6425f, 746.4f, 853.6f, + 972.5f, 1104.0f, 1251.8f, 1415.8f, 1599.2f, 1804.6f, 2035.2f, 2294.9f, 2588.4f, 2921.2f, 3300.1f, + 3733.7f, 4000.0f+1.0f + }; + + + + +/*Amplitude and power tables for PPP*/ + + +const float AmpCB1_WB[64][10] = +{ + { 0.6903076f, 0.1939697f, -0.0797119f, 0.4355469f, -0.3873291f, -0.2260742f, -0.3911133f, -0.5643311f, -0.2563477f, -0.6229248f, }, + { -0.1126709f, -0.0081787f, -0.8730469f, -0.6052246f, -0.2464600f, -0.2209473f, -1.0415039f, -0.0791016f, 0.8033447f, 0.9818115f, }, + { 0.0195313f, 0.0949707f, -0.1873779f, 0.1053467f, 0.6691895f, 0.2043457f, -0.4365234f, 0.0150146f, -0.3861084f, -0.4388428f, }, + { -0.1040039f, -0.0064697f, -0.1318359f, -0.3275146f, -0.3905029f, -0.1159668f, -0.1651611f, 0.7639160f, -0.1746826f, 0.1524658f, }, + { 0.2513428f, 0.0826416f, 0.0178223f, 0.1234131f, 0.1166992f, -0.2468262f, -0.0030518f, 0.0366211f, 0.0513916f, -0.7152100f, }, + { 0.1253662f, -0.0551758f, -0.8963623f, -0.1284180f, 0.4660645f, 0.1341553f, -0.1226807f, 0.0804443f, -0.0623779f, -0.0803223f, }, + { 0.2552490f, 0.0878906f, -0.0732422f, 0.0177002f, -0.1835938f, -0.2094727f, -0.0539551f, -0.2651367f, -0.1837158f, 0.3298340f, }, + { 0.0892334f, 0.1798096f, -0.0260010f, -0.5029297f, -0.3632813f, 0.0839844f, 0.3912354f, 0.1480713f, 0.0828857f, 0.0283203f, }, + { 0.4482422f, 0.5822754f, -0.1462402f, -0.0363770f, -0.2092285f, -0.4478760f, -0.3458252f, -0.0810547f, -0.2269287f, -0.2905273f, }, + { -0.1427002f, -0.1944580f, -0.0552979f, 0.0360107f, -0.1495361f, -0.3796387f, -0.2167969f, 0.2578125f, 0.3308105f, 0.4068604f, }, + { 0.1247559f, 0.1523438f, 0.1331787f, 0.1420898f, 0.1464844f, 0.2175293f, -0.0987549f, -0.2814941f, -0.3813477f, -0.2678223f, }, + { -0.1912842f, 0.0567627f, 0.2713623f, -0.1588135f, -0.0565186f, -0.2633057f, 0.0889893f, 0.2781982f, -0.2365723f, 0.0744629f, }, + { 0.0533447f, -0.0980225f, -0.1251221f, 0.0946045f, -0.0208740f, -0.0777588f, 0.0198975f, 0.2747803f, 0.0385742f, -0.2030029f, }, + { -0.5032959f, -0.0024414f, -0.3450928f, -0.1866455f, -0.1752930f, 0.4207764f, 0.0096436f, -0.0334473f, 0.2014160f, 0.5001221f, }, + { 0.2891846f, 0.1131592f, 0.0546875f, -0.0548096f, 0.0357666f, -0.0291748f, -0.1254883f, -0.5865479f, 0.1652832f, 0.0526123f, }, + { -0.2708740f, -0.0598145f, -0.4698486f, 0.2000732f, -0.3570557f, 0.0997314f, 0.1812744f, 0.3084717f, 0.6645508f, -0.2434082f, }, + { 0.1801758f, 0.0617676f, -0.2005615f, 0.2445068f, -0.2045898f, -0.0961914f, -0.2052002f, -0.2454834f, 0.1695557f, 0.0551758f, }, + { 0.0723877f, 0.0003662f, -0.1464844f, -0.4866943f, -0.1994629f, -0.5261230f, -0.0837402f, 0.1076660f, 0.7611084f, 0.2954102f, }, + { -0.0239258f, -0.1534424f, -0.2487793f, -0.0607910f, 0.1701660f, 0.0819092f, -0.2810059f, -0.0987549f, -0.0544434f, 0.4448242f, }, + { -0.2005615f, -0.2812500f, -0.1010742f, 0.0128174f, -0.0394287f, -0.4768066f, -0.1171875f, 0.8940430f, 0.3778076f, -0.0959473f, }, + { 0.0115967f, 0.0772705f, 0.1545410f, 0.0915527f, 0.1842041f, -0.2481689f, -0.3825684f, 0.0527344f, 0.1254883f, -0.2227783f, }, + { 0.1535645f, 0.0312500f, -0.3966064f, -0.8383789f, -0.0638428f, -0.0396729f, -0.2171631f, 0.5264893f, 0.3081055f, 0.4190674f, }, + { -0.0732422f, -0.0500488f, -0.0107422f, 0.0500488f, -0.1442871f, -0.1391602f, -0.1767578f, -0.1640625f, -0.6193848f, 0.7390137f, }, + { 0.2678223f, 0.1837158f, -0.0831299f, -0.2939453f, 0.1679688f, 0.1695557f, 0.1475830f, 0.1279297f, -0.5125732f, -0.3587646f, }, + { 0.2264404f, 0.2128906f, -0.1640625f, -0.1746826f, -0.2386475f, -0.2203369f, -0.6093750f, 0.0625000f, 0.0761719f, 0.3355713f, }, + { -0.4206543f, -0.1483154f, -0.4594727f, -0.2647705f, -0.4395752f, -0.1612549f, 0.0081787f, 0.5280762f, 0.8085938f, 0.7099609f, }, + { -0.0407715f, -0.2131348f, -0.0538330f, -0.0920410f, 0.2261963f, 0.4747314f, -0.0726318f, -0.0601807f, 0.0538330f, -0.0989990f, }, + { -0.0058594f, -0.0932617f, -0.1798096f, -0.0833740f, 0.0736084f, -0.2141113f, 0.0952148f, 0.0852051f, 0.1323242f, 0.2091064f, }, + { 0.0683594f, -0.0986328f, -0.0920410f, -0.3527832f, -0.1470947f, -0.0388184f, -0.1246338f, 0.3900146f, 0.6949463f, -0.5618896f, }, + { 0.1639404f, -0.1295166f, -0.2979736f, -0.2177734f, 0.0880127f, 0.0325928f, 0.0277100f, -0.0759277f, 0.3677979f, -0.0937500f, }, + { -0.0576172f, 0.0109863f, 0.0015869f, 0.0354004f, 0.1287842f, 0.1157227f, 0.1973877f, -0.2890625f, -0.1326904f, 0.1346436f, }, + { -0.5839844f, -0.4726563f, 0.6256104f, -0.3073730f, -0.0262451f, 0.8498535f, 0.1336670f, -0.1856689f, 0.2552490f, -0.3615723f, }, + { 0.2789307f, 0.1363525f, 0.1433105f, 0.3216553f, -0.2327881f, -0.1235352f, 0.0993652f, -0.0509033f, -0.2639160f, -0.3424072f, }, + { -0.1450195f, -0.0863037f, -0.0986328f, -0.2144775f, 0.0317383f, -0.1334229f, -0.4830322f, -0.3986816f, 0.5043945f, 0.7299805f, }, + { 0.0216064f, -0.1804199f, 0.1171875f, 0.2476807f, 0.4869385f, 0.0728760f, -0.3737793f, -0.4809570f, -0.2060547f, 0.0288086f, }, + { -0.1903076f, 0.0183105f, 0.2968750f, 0.0424805f, -0.0295410f, -0.2458496f, -0.1253662f, 0.7687988f, -0.3609619f, -0.4833984f, }, + { 0.1330566f, 0.1237793f, -0.1539307f, -0.0908203f, -0.1164551f, -0.1145020f, -0.4532471f, -0.3994141f, 0.6538086f, -0.2875977f, }, + { -0.1756592f, 0.4648438f, -0.2844238f, -0.5416260f, 0.6319580f, -0.4401855f, -0.1687012f, 0.2226563f, 0.0496826f, 0.0396729f, }, + { 0.0792236f, 0.0402832f, 0.0103760f, 0.0251465f, -0.0506592f, 0.0223389f, -0.0788574f, 0.0734863f, -0.3242188f, 0.0986328f, }, + { 0.1268311f, 0.0035400f, -0.3908691f, -0.7529297f, -0.4443359f, 0.4560547f, 0.5106201f, 0.4832764f, 0.0402832f, 0.0413818f, }, + { 0.3297119f, 0.0418701f, 0.1832275f, 0.2293701f, -0.3898926f, -0.5673828f, -0.1989746f, 0.2021484f, -0.1926270f, -0.0102539f, }, + { -0.3741455f, -0.5036621f, 0.0029297f, -0.0317383f, 0.0321045f, -0.2081299f, -0.1573486f, 0.2968750f, 0.1500244f, 0.9132080f, }, + { 0.3156738f, 0.2070313f, 0.0788574f, -0.2164307f, -0.0966797f, 0.2358398f, -0.2329102f, -0.2315674f, -0.1378174f, 0.0136719f, }, + { -0.6917725f, -0.1943359f, 0.2750244f, -0.1196289f, 0.1929932f, 0.0257568f, 0.6441650f, 0.5915527f, -0.0351563f, -0.0194092f, }, + { 0.1166992f, 0.1459961f, 0.0941162f, -0.1187744f, -0.2178955f, -0.0629883f, -0.1239014f, 0.1033936f, 0.0749512f, -0.0965576f, }, + { -0.0539551f, -0.1945801f, -0.5654297f, -0.5361328f, -0.0507813f, 0.1706543f, 0.3137207f, 0.0917969f, 0.0322266f, 0.8020020f, }, + { 0.2020264f, 0.0666504f, 0.1511230f, -0.1662598f, -0.1623535f, -0.2447510f, 0.4382324f, -0.2630615f, -0.0224609f, -0.1494141f, }, + { -0.1772461f, -0.1871338f, -0.0651855f, 0.1232910f, -0.2083740f, 0.0977783f, 0.4428711f, -0.0352783f, 0.2946777f, 0.0161133f, }, + { 0.3226318f, -0.3433838f, -0.5522461f, 0.6215820f, -0.8986816f, 0.0903320f, 0.0522461f, -0.0622559f, 0.0098877f, -0.1475830f, }, + { 0.0751953f, 0.1774902f, 0.2271729f, -0.4831543f, -0.4985352f, 0.0230713f, -0.1488037f, -0.1068115f, 0.4594727f, 0.2546387f, }, + { -0.1896973f, -0.2528076f, 0.1849365f, 0.4140625f, 0.0014648f, -0.0837402f, -0.2946777f, -0.1687012f, 0.0214844f, 0.2056885f, }, + { 0.2508545f, -0.6955566f, 0.1931152f, 0.5025635f, -0.5915527f, -0.3566895f, 0.0744629f, 0.2541504f, 0.5715332f, -0.3035889f, }, + { 0.0424805f, 0.2756348f, -0.0412598f, -0.1683350f, 0.1796875f, 0.0754395f, -0.0246582f, -0.1369629f, -0.0092773f, -0.3012695f, }, + { -0.1484375f, -0.1203613f, -0.0399170f, -0.1759033f, 0.0124512f, 0.0491943f, -0.2569580f, 0.2943115f, 0.1843262f, 0.1572266f, }, + { -0.0872803f, -0.0704346f, 0.1311035f, 0.3092041f, -0.4298096f, -0.4210205f, 0.2612305f, -0.0916748f, -0.0374756f, 0.4644775f, }, + { 0.0192871f, -0.1690674f, -0.0493164f, -0.1682129f, -0.2377930f, 0.4620361f, 0.5146484f, 0.3255615f, -0.2312012f, -0.1903076f, }, + { 0.1265869f, 0.1673584f, 0.1207275f, -0.0250244f, -0.0406494f, -0.5839844f, -0.4185791f, -0.1566162f, 0.4027100f, 0.1048584f, }, + { -0.6008301f, -0.6690674f, -0.1459961f, -0.2133789f, -0.0878906f, 0.0629883f, 0.0137939f, 0.5603027f, 0.8631592f, 0.5303955f, }, + { -0.6993408f, -0.4714355f, 0.4382324f, 0.1785889f, 0.8659668f, 0.6092529f, 0.1042480f, -0.0080566f, -0.1989746f, -0.0837402f, }, + { -0.1126709f, -0.3986816f, -0.2426758f, 0.2862549f, 0.0958252f, -0.1733398f, 0.3666992f, 0.3581543f, -0.1519775f, -0.0079346f, }, + { -0.3291016f, -0.3769531f, -0.1755371f, 0.0749512f, 0.1933594f, -0.0291748f, -0.1894531f, 0.0708008f, 0.7672119f, -0.2042236f, }, + { -0.1950684f, -0.4904785f, -0.2330322f, 0.0911865f, 0.3895264f, 0.0446777f, 0.1790771f, -0.2359619f, 0.3367920f, 0.3422852f, }, + { 0.0632324f, 0.0235596f, -0.1402588f, -0.3793945f, 0.0538330f, 0.1779785f, 0.3406982f, -0.5042725f, 0.3288574f, 0.4116211f, }, + { -0.6131592f, -0.7923584f, 0.2189941f, 0.3343506f, 0.1785889f, 0.7132568f, 0.3502197f, 0.2432861f, -0.1719971f, 0.5898438f, }, +}; + +const float AmpCB2_WB[64][NUM_ERB_WB-11] = +{ + { -0.6440430f, -0.9412842f, -0.4294434f, -0.2949219f, -0.0466309f, 0.0389404f, -0.2319336f, -0.1098633f, 0.2105713f, 0.1079102f, 0.4969482f, }, + { -0.4946289f, -0.2966309f, -0.0410156f, 0.2607422f, 0.3669434f, 0.0721436f, -0.4752197f, -0.3333740f, 0.3204346f, 0.2917480f, -0.1278076f, }, + { -0.1077881f, -0.4111328f, -0.5169678f, -0.4548340f, 0.0230713f, -0.2200928f, 0.0957031f, 0.2851563f, 0.0251465f, -0.2612305f, 0.3663330f, }, + { -0.0891113f, -0.2781982f, 0.0103760f, -0.4144287f, 0.5330811f, 0.2702637f, -0.0310059f, -0.3801270f, -0.2866211f, 0.3372803f, 0.0837402f, }, + { -0.9149170f, -0.8078613f, 0.3862305f, -0.4830322f, -0.3272705f, -0.2501221f, 0.2025146f, 0.4436035f, 0.3615723f, 0.1921387f, 0.0462646f, }, + { -0.3024902f, 0.3492432f, 0.0751953f, 0.1372070f, 0.0250244f, -0.3753662f, -0.0424805f, -0.2448730f, -0.0109863f, 0.0928955f, 0.1412354f, }, + { -0.0139160f, -1.1547852f, -0.3400879f, -0.3972168f, -0.1367188f, -0.1831055f, -0.0544434f, 0.3460693f, -0.0383301f, 0.3912354f, 0.2581787f, }, + { -0.1021729f, -0.0318604f, 0.0043945f, 0.0097656f, -0.0592041f, 0.1383057f, 0.2592773f, -0.1258545f, -0.0489502f, -0.3864746f, 0.1397705f, }, + { -0.1972656f, -0.4180908f, -0.3748779f, -0.8411865f, -0.5124512f, 0.2797852f, 0.6298828f, -0.0056152f, 0.1745605f, 0.0341797f, 0.1682129f, }, + { 0.2075195f, -0.2042236f, -0.1374512f, 0.6433105f, 0.6220703f, -0.1190186f, -0.1306152f, 0.1604004f, -0.2916260f, -0.3640137f, 0.0024414f, }, + { -0.3928223f, -0.1088867f, -0.0776367f, -0.1069336f, -0.0368652f, -0.3568115f, -0.3955078f, 0.5030518f, 0.1983643f, -0.0679932f, 0.1213379f, }, + { 0.0664063f, 0.3243408f, 0.8707275f, -0.0333252f, -0.4309082f, -0.1732178f, 0.1746826f, -0.1142578f, -0.3200684f, 0.0369873f, 0.0091553f, }, + { -0.6645508f, -0.6773682f, 0.5106201f, 0.1523438f, 0.4240723f, -0.0963135f, 0.2899170f, -0.2170410f, 0.2026367f, 0.1855469f, -0.1749268f, }, + { -0.4940186f, 0.0648193f, 0.8546143f, 0.0848389f, 0.2305908f, 0.5201416f, -0.3406982f, -0.1900635f, -0.3637695f, -0.0385742f, 0.0506592f, }, + { 0.1384277f, 0.1832275f, -0.8450928f, 0.0635986f, -0.3825684f, -0.2211914f, 0.2255859f, 0.0825195f, -0.2115479f, 0.0895996f, 0.2694092f, }, + { 0.2476807f, -0.0581055f, -0.2412109f, -0.0196533f, 0.0035400f, 0.8724365f, -0.2165527f, 0.0878906f, -0.1306152f, -0.0454102f, -0.1984863f, }, + { -0.7901611f, -0.2988281f, -0.6390381f, -0.3236084f, -0.2197266f, -0.1802979f, -0.0936279f, 0.1629639f, 0.0574951f, 0.5928955f, 0.1083984f, }, + { 0.0723877f, -0.0451660f, 0.0239258f, 0.1107178f, 0.0212402f, 0.0679932f, -0.0878906f, -0.1634521f, 0.1940918f, 0.0045166f, -0.1522217f, }, + { -0.1595459f, 0.0336914f, -0.2122803f, -0.7363281f, -0.3769531f, -0.3050537f, -0.0606689f, -0.0479736f, -0.0694580f, 0.3665771f, 0.3288574f, }, + { 0.4578857f, 0.5678711f, -0.0314941f, -0.1593018f, 0.0213623f, 0.0230713f, -0.0419922f, -0.2906494f, -0.2431641f, 0.0565186f, 0.0645752f, }, + { -0.7781982f, 0.4841309f, -0.4343262f, -0.3663330f, -0.0781250f, 0.3804932f, 0.1367188f, 0.1179199f, 0.1606445f, -0.0684814f, 0.0032959f, }, + { 0.3410645f, 0.3455811f, 0.4287109f, 0.4215088f, -0.0510254f, -0.2830811f, -0.8228760f, -0.4202881f, 0.0097656f, 0.1563721f, 0.2064209f, }, + { 0.1831055f, -0.0721436f, -0.0902100f, 0.2911377f, -0.5708008f, -0.7106934f, -0.1754150f, 0.0891113f, 0.4385986f, -0.0533447f, 0.1330566f, }, + { 0.4268799f, -0.2358398f, 0.3483887f, 0.5930176f, 0.3239746f, 0.1156006f, 0.2293701f, -0.5023193f, 0.3295898f, -0.3774414f, -0.1860352f, }, + { 0.0274658f, -1.0097656f, -0.8222656f, -0.1558838f, 0.3651123f, 0.3641357f, 0.1378174f, -0.2027588f, 0.3438721f, 0.0571289f, 0.0599365f, }, + { -0.0908203f, 0.0476074f, 0.0826416f, 0.9923096f, -0.3820801f, -0.0838623f, -0.0528564f, 0.1816406f, -0.4593506f, -0.0216064f, -0.0709229f, }, + { -0.0932617f, 0.0047607f, 0.1876221f, -0.2689209f, -0.2048340f, 0.0321045f, -0.1481934f, 0.2655029f, -0.2266846f, 0.3780518f, -0.1091309f, }, + { 0.5135498f, -0.2371826f, -0.1018066f, 0.1846924f, -0.5032959f, 0.4859619f, 0.7374268f, 0.0797119f, -0.0924072f, -0.0382080f, -0.3691406f, }, + { -0.5632324f, -0.3831787f, -0.3620605f, 0.0217285f, 0.6049805f, -0.0521240f, -0.0050049f, 0.2900391f, 0.1230469f, -0.1649170f, -0.0112305f, }, + { 0.1193848f, 0.2438965f, 0.6281738f, 0.2525635f, 0.0142822f, -0.2141113f, -0.3364258f, 0.5401611f, 0.0205078f, -0.2205811f, -0.2149658f, }, + { -0.1483154f, 0.0217285f, -0.1906738f, -0.4112549f, -0.1121826f, -0.3144531f, 0.4411621f, 0.6064453f, -0.0036621f, -0.0483398f, -0.1405029f, }, + { -0.1398926f, 0.1059570f, 0.1309814f, -0.0438232f, 0.3334961f, 0.0666504f, 0.5408936f, -0.0391846f, -0.1319580f, 0.1721191f, -0.3923340f, }, + { -0.2827148f, -0.5968018f, -0.3002930f, -0.4692383f, -0.8939209f, -0.1755371f, -0.1816406f, 0.2257080f, 0.4927979f, 0.2955322f, 0.3292236f, }, + { -0.2895508f, -0.2291260f, 0.0817871f, 0.4484863f, -0.1107178f, 0.1083984f, -0.4520264f, 0.0457764f, -0.1560059f, -0.1802979f, 0.3052979f, }, + { -0.1142578f, -0.2053223f, -0.1651611f, -0.0408936f, -0.5419922f, 0.0467529f, -0.3332520f, -0.2600098f, -0.1348877f, 0.1938477f, 0.4077148f, }, + { 0.5878906f, -0.4910889f, 0.0612793f, -0.5061035f, 0.0288086f, 0.5469971f, 0.0718994f, -0.4511719f, 0.1008301f, -0.0118408f, 0.0270996f, }, + { -0.9810791f, -0.2739258f, 0.0173340f, 0.0988770f, -0.2679443f, 0.1605225f, 0.0800781f, 0.2320557f, -0.0592041f, 0.0386963f, 0.1845703f, }, + { 0.1788330f, -0.2473145f, 0.2261963f, 0.1134033f, 0.2038574f, -0.3339844f, -0.0565186f, -0.1020508f, -0.6037598f, -0.0163574f, 0.3380127f, }, + { 0.3627930f, -0.6284180f, -0.3841553f, 0.1114502f, -0.1810303f, 0.0325928f, -0.1904297f, 0.4764404f, 0.1839600f, 0.1348877f, -0.1826172f, }, + { 0.0256348f, -0.1459961f, 0.4594727f, 0.0733643f, 0.1989746f, 0.4689941f, 0.7780762f, -0.1578369f, -0.5560303f, -0.3768311f, 0.0242920f, }, + { -0.2340088f, -0.4066162f, -0.2828369f, -0.2165527f, 0.0584717f, 0.4531250f, 0.3331299f, 0.1597900f, -0.3719482f, -0.0627441f, 0.1051025f, }, + { -0.0260010f, 0.1607666f, -0.2484131f, 0.5333252f, 0.6381836f, 0.1149902f, -0.3725586f, -0.2827148f, -0.4122314f, 0.1370850f, -0.0079346f, }, + { 0.3060303f, 0.3309326f, -0.2558594f, -0.2641602f, -0.3215332f, -0.6365967f, -0.4783936f, 0.1893311f, -0.0057373f, 0.2429199f, 0.2893066f, }, + { 0.2471924f, -0.2930908f, 0.5899658f, -0.4735107f, -0.0197754f, -0.3760986f, 0.0611572f, -0.0622559f, 0.3349609f, -0.1107178f, 0.0308838f, }, + { -0.2131348f, -0.3076172f, 0.4172363f, -0.1783447f, 0.2612305f, 0.3060303f, 0.0164795f, 0.1778564f, 0.3900146f, -0.1558838f, -0.3122559f, }, + { -0.0080566f, 1.3244629f, -0.1993408f, -0.1282959f, -0.4194336f, -0.1973877f, 0.1755371f, -0.1502686f, -0.2128906f, 0.0849609f, -0.0424805f, }, + { 0.4191895f, 0.2589111f, -0.1988525f, -0.3002930f, -0.4962158f, 0.1414795f, -0.1572266f, 0.3470459f, 0.0850830f, -0.1052246f, 0.0004883f, }, + { 0.1179199f, -0.0541992f, -0.2270508f, 0.1770020f, 0.7844238f, 0.6767578f, 0.1777344f, -0.3449707f, -0.1590576f, -0.3391113f, -0.1560059f, }, + { -0.8125000f, -0.3956299f, -0.8646240f, 0.2727051f, 0.0249023f, 0.2139893f, 0.0980225f, 0.0609131f, 0.2003174f, 0.0106201f, 0.1795654f, }, + { -0.1617432f, 0.0485840f, 0.3641357f, 0.5297852f, -0.1687012f, 0.0897217f, -0.0732422f, -0.5701904f, -0.0310059f, 0.2840576f, -0.1230469f, }, + { -0.0175781f, -0.1773682f, -0.2204590f, -0.2037354f, 0.0482178f, -0.4010010f, -0.2200928f, -0.2586670f, 0.1503906f, 0.3557129f, 0.1806641f, }, + { 1.0510254f, 0.2182617f, 0.3227539f, 0.1658936f, 0.4617920f, -0.0134277f, -0.1634521f, -0.1632080f, -0.4183350f, -0.0769043f, -0.1451416f, }, + { -0.3125000f, 0.1191406f, 0.0589600f, -0.3349609f, -0.4459229f, -0.1573486f, 0.3552246f, -0.2974854f, 0.3870850f, 0.1805420f, 0.0191650f, }, + { 0.1004639f, 0.5653076f, -0.2331543f, 0.4560547f, -0.0517578f, -0.0189209f, -0.6677246f, -0.0904541f, 0.4674072f, -0.3410645f, -0.0067139f, }, + { -0.1766357f, -0.4234619f, -0.2376709f, 0.3557129f, -0.0074463f, -0.4187012f, 0.4326172f, -0.2279053f, 0.3645020f, 0.1231689f, -0.1282959f, }, + { 0.0885010f, 0.3580322f, 0.3571777f, 0.7139893f, 0.0313721f, -0.3254395f, 0.7673340f, -0.2785645f, -0.3659668f, -0.3144531f, -0.1190186f, }, + { -0.4461670f, -0.2279053f, -0.6152344f, -0.1757813f, 0.4323730f, -0.0736084f, 0.5866699f, -0.3427734f, -0.1993408f, 0.1694336f, 0.1402588f, }, + { -0.1972656f, -0.2259521f, 0.2590332f, 0.5465088f, 0.3033447f, 0.1679688f, 0.0880127f, 0.2653809f, -0.3750000f, 0.1682129f, -0.3142090f, }, + { -0.0045166f, 0.1613770f, -0.2009277f, -0.4409180f, 0.5423584f, 0.1967773f, -0.4154053f, 0.0867920f, 0.0161133f, 0.0145264f, -0.0277100f, }, + { 0.6175537f, 0.3530273f, 0.1025391f, 0.6667480f, -0.4237061f, -0.1635742f, 0.2559814f, 0.0174561f, 0.2136230f, -0.3725586f, -0.2358398f, }, + { -0.7753906f, -0.5085449f, -0.0787354f, 0.5269775f, 0.0772705f, 0.4493408f, 0.3431396f, 0.2863770f, 0.2897949f, -0.3660889f, -0.1544189f, }, + { -0.0256348f, 0.6243896f, 0.5678711f, 0.1593018f, 0.4521484f, -0.1777344f, -0.0374756f, -0.0557861f, -0.1776123f, -0.4370117f, 0.0822754f, }, + { 0.2703857f, 0.3000488f, -0.3687744f, -0.0080566f, 0.3094482f, -0.0795898f, 0.1496582f, 0.0836182f, 0.1068115f, -0.2139893f, -0.1420898f, }, + { -0.0743408f, 0.4204102f, 0.0687256f, 0.4670410f, 0.1961670f, 0.4636230f, 0.1690674f, 0.4763184f, -0.2429199f, -0.4978027f, -0.3062744f, }, +}; + +const float AmpCB1_NB[64][10] = +{ + { -0.1654053f, 0.0225830f, -0.0270996f, -0.0269775f, 0.2412109f, 0.3807373f, 0.0659180f, 0.1627197f, -0.4450684f, -0.3065186f, }, + { -0.1195068f, 0.2031250f, 0.2547607f, 0.1160889f, 0.0960693f, -0.2059326f, -0.1043701f, 0.1945801f, 0.1542969f, -0.6091309f, }, + { -0.2388916f, -0.0262451f, -0.1037598f, 0.1671143f, -0.0137939f, 0.3101807f, -0.3544922f, 0.0906982f, 0.0773926f, -0.0802002f, }, + { -0.4196777f, -0.2498779f, 0.0861816f, 0.0103760f, -0.0727539f, -0.0061035f, 0.0258789f, 0.1152344f, 0.0144043f, 0.1684570f, }, + { -0.1468506f, -0.0095215f, -0.0260010f, -0.2210693f, -0.0953369f, -0.2404785f, 0.8065186f, -0.3626709f, 0.0179443f, -0.1810303f, }, + { 0.0046387f, 0.6844482f, 0.6374512f, -0.5574951f, -0.4931641f, -0.2757568f, -0.3796387f, -0.2587891f, 0.1137695f, -0.0288086f, }, + { -0.1284180f, 0.1268311f, -0.1064453f, 0.0407715f, -0.1121826f, 0.3370361f, 0.4052734f, -0.7114258f, 0.0064697f, 0.1297607f, }, + { -0.1298828f, -0.0091553f, -0.1239014f, -0.2608643f, -0.0881348f, 0.0689697f, 0.0767822f, 0.2393799f, -0.0554199f, 0.1057129f, }, + { -0.1083984f, 0.3237305f, 0.2436523f, -0.2648926f, -0.1080322f, 0.4058838f, -0.0787354f, -0.2316895f, -0.1201172f, -0.0784912f, }, + { -0.1230469f, 0.3017578f, 0.2929688f, -0.4526367f, -0.2939453f, -0.1282959f, 0.2476807f, 0.1656494f, -0.0776367f, -0.0573730f, }, + { -0.1595459f, 0.0799561f, 0.0809326f, 0.0035400f, 0.1088867f, -0.0115967f, -0.0111084f, -0.3620605f, -0.1965332f, 0.3243408f, }, + { -0.2655029f, -0.3869629f, -0.4637451f, -0.3741455f, 0.1379395f, 0.1649170f, 0.4655762f, 0.3406982f, 0.1804199f, 0.1855469f, }, + { -0.1618652f, -0.0634766f, -0.0844727f, 0.1097412f, 0.2415771f, -0.0484619f, -0.0496826f, 0.0549316f, -0.0694580f, -0.0745850f, }, + { -0.1499023f, 0.1054688f, 0.3111572f, 0.3743896f, -0.3065186f, -0.5782471f, -0.3297119f, -0.0371094f, 0.0830078f, 0.1740723f, }, + { -0.1306152f, -0.0023193f, -0.1931152f, -0.3433838f, -0.2236328f, 0.3674316f, 0.0305176f, -0.0748291f, 0.4138184f, -0.0208740f, }, + { -0.1770020f, -0.0509033f, -0.0943604f, -0.0794678f, -0.0494385f, -0.2812500f, -0.0952148f, 0.8125000f, -0.3991699f, -0.1613770f, }, + { 0.0085449f, 0.6231689f, 0.3908691f, -0.0101318f, -0.1129150f, -0.0559082f, 0.1468506f, -0.1931152f, -0.5075684f, -0.4431152f, }, + { -0.2077637f, -0.1036377f, -0.0067139f, -0.1203613f, -0.2396240f, -0.1391602f, -0.2370605f, 0.4085693f, 0.4304199f, -0.0531006f, }, + { -0.1744385f, -0.2550049f, -0.1977539f, -0.1551514f, 0.3480225f, 0.2666016f, -0.3017578f, 0.3925781f, 0.3521729f, -0.3566895f, }, + { -0.1485596f, 0.0104980f, -0.0227051f, -0.0340576f, -0.0910645f, 0.1572266f, 0.3681641f, -0.0794678f, -0.3319092f, 0.0386963f, }, + { -0.1595459f, -0.0155029f, -0.1354980f, 0.1695557f, 0.0258789f, 0.2176514f, 0.3197021f, -0.2097168f, 0.2191162f, -0.4987793f, }, + { -0.1580811f, 0.0906982f, 0.0367432f, -0.2225342f, -0.0272217f, -0.0794678f, -0.2165527f, -0.0494385f, 0.2059326f, 0.2479248f, }, + { -0.1055908f, 0.1292725f, -0.0477295f, 0.0616455f, -0.3343506f, -0.3385010f, 0.0019531f, -0.3613281f, 0.3748779f, 0.4058838f, }, + { -0.0965576f, 0.2808838f, 0.0531006f, 0.0130615f, -0.4930420f, 0.0977783f, -0.1494141f, 0.2263184f, -0.1268311f, 0.0618896f, }, + { -0.0632324f, 0.1217041f, 0.1021729f, 0.4041748f, 0.0617676f, 0.1252441f, -0.0283203f, -0.2343750f, -0.4765625f, 0.0495605f, }, + { -0.2266846f, -0.0645752f, -0.0947266f, -0.0854492f, -0.0809326f, -0.1855469f, 0.2073975f, 0.0993652f, 0.2543945f, -0.0582275f, }, + { -0.1636963f, -0.1370850f, -0.3129883f, -0.3398438f, 0.2999268f, 0.3934326f, -0.1170654f, 0.0469971f, -0.2275391f, 0.4582520f, }, + { -0.1649170f, -0.1644287f, -0.2720947f, -0.3518066f, -0.1295166f, -0.1829834f, -0.3696289f, 0.4030762f, 0.2746582f, 0.6761475f, }, + { -0.1168213f, -0.0415039f, 0.0032959f, 0.1840820f, 0.0203857f, -0.4288330f, 0.2061768f, 0.3145752f, -0.2209473f, -0.0629883f, }, + { -0.1295166f, 0.2650146f, 0.2165527f, 0.2479248f, 0.1126709f, -0.2359619f, -0.2001953f, -0.3516846f, 0.1048584f, -0.1018066f, }, + { 0.0498047f, 0.3005371f, 0.2530518f, 0.2572021f, -0.3260498f, 0.1391602f, -0.4268799f, -0.3048096f, 0.3642578f, -0.3304443f, }, + { -0.2150879f, -0.3081055f, -0.2680664f, 0.0340576f, -0.3149414f, 0.0582275f, 0.2814941f, 0.5670166f, 0.0845947f, -0.1109619f, }, + { -0.1329346f, 0.2382813f, 0.3703613f, -0.2185059f, 0.0959473f, -0.1402588f, -0.3804932f, 0.4400635f, -0.2359619f, -0.2302246f, }, + { -0.1170654f, 0.1140137f, 0.0300293f, -0.2657471f, -0.2978516f, 0.1655273f, 0.1063232f, 0.4238281f, 0.3122559f, -0.5507813f, }, + { -0.0954590f, 0.1540527f, 0.1090088f, 0.2415771f, 0.2912598f, -0.2208252f, -0.5318604f, -0.0478516f, -0.2353516f, 0.1923828f, }, + { -0.2137451f, -0.0399170f, -0.1242676f, -0.0753174f, -0.2893066f, -0.3552246f, 0.5163574f, -0.0109863f, -0.1661377f, 0.4389648f, }, + { -0.1304932f, -0.0384521f, -0.0197754f, -0.0413818f, -0.0382080f, 0.0040283f, 0.5717773f, 0.3431396f, -0.3316650f, -0.4497070f, }, + { 0.0848389f, 0.5574951f, -0.0909424f, -0.2821045f, -0.0947266f, -0.3173828f, -0.1009521f, -0.1269531f, -0.1217041f, 0.3027344f, }, + { -0.1890869f, -0.0913086f, -0.0759277f, -0.0317383f, 0.1782227f, 0.1362305f, -0.0368652f, -0.3087158f, 0.2631836f, -0.0051270f, }, + { -0.1608887f, -0.0693359f, -0.0324707f, -0.0544434f, -0.2700195f, 0.3283691f, -0.5699463f, 0.6500244f, -0.2468262f, 0.1657715f, }, + { -0.1601563f, 0.2799072f, 0.1865234f, 0.0861816f, 0.1184082f, -0.0355225f, 0.0467529f, -0.0833740f, -0.1870117f, -0.2249756f, }, + { -0.1683350f, 0.1031494f, 0.1486816f, 0.0482178f, -0.2299805f, 0.0017090f, 0.0825195f, -0.2088623f, 0.0970459f, 0.0354004f, }, + { -0.0905762f, 0.0471191f, -0.0531006f, 0.0501709f, 0.1600342f, 0.0670166f, -0.5103760f, -0.6008301f, 0.1827393f, 0.5450439f, }, + { -0.2102051f, -0.0853271f, -0.2390137f, -0.5036621f, -0.4549561f, -0.0799561f, 0.1895752f, 0.2188721f, 0.6021729f, 0.3729248f, }, + { -0.1538086f, -0.0754395f, 0.0653076f, -0.2451172f, 0.4641113f, -0.4619141f, 0.3084717f, -0.1016846f, 0.0235596f, -0.1296387f, }, + { -0.1057129f, 0.1004639f, 0.1906738f, 0.0179443f, -0.0760498f, -0.2207031f, -0.1341553f, 0.0847168f, -0.0704346f, 0.0909424f, }, + { -0.2785645f, -0.5052490f, -0.3870850f, 0.0092773f, 0.0030518f, -0.1314697f, 0.0582275f, 0.0665283f, 0.7423096f, 0.3959961f, }, + { -0.1625977f, -0.0958252f, 0.0119629f, -0.2052002f, -0.4398193f, -0.4805908f, 0.0639648f, 0.5673828f, 0.1359863f, 0.3109131f, }, + { -0.1397705f, 0.0496826f, 0.2478027f, 0.3808594f, -0.2122803f, -0.0626221f, -0.0632324f, 0.1617432f, -0.2075195f, -0.3491211f, }, + { -0.1741943f, 0.0634766f, -0.1269531f, -0.0966797f, -0.0446777f, -0.2653809f, -0.0637207f, -0.0292969f, 0.6909180f, -0.3861084f, }, + { -0.1768799f, -0.2017822f, -0.1839600f, 0.0709229f, 0.1633301f, -0.3206787f, -0.2274170f, 0.2235107f, 0.1588135f, 0.2570801f, }, + { -0.1528320f, 0.1188965f, 0.0242920f, 0.0083008f, -0.0084229f, -0.1060791f, 0.1054688f, 0.2896729f, -0.7102051f, 0.3507080f, }, + { 0.0031738f, 0.1186523f, 0.0438232f, -0.0684814f, -0.0476074f, 0.0458984f, 0.0274658f, 0.0631104f, 0.0792236f, -0.2156982f, }, + { -0.0797119f, 0.2645264f, 0.1076660f, -0.0852051f, 0.0261230f, -0.4985352f, -0.5046387f, 0.2553711f, 0.3415527f, -0.0638428f, }, + { -0.1223145f, 0.0593262f, 0.0791016f, -0.1320801f, 0.0493164f, -0.1818848f, 0.1904297f, -0.6083984f, 0.6853027f, -0.1759033f, }, + { -0.1250000f, -0.0379639f, 0.0521240f, 0.0434570f, -0.2858887f, 0.0262451f, -0.2822266f, 0.0543213f, -0.2902832f, 0.6239014f, }, + { -0.0693359f, 0.0103760f, 0.1621094f, 0.2254639f, 0.4279785f, 0.1444092f, -0.3077393f, -0.2526855f, -0.0969238f, -0.2296143f, }, + { -0.0592041f, 0.1368408f, 0.1516113f, 0.1588135f, -0.5328369f, -0.2712402f, 0.3176270f, -0.0472412f, 0.1828613f, -0.1640625f, }, + { -0.1552734f, -0.1666260f, -0.2694092f, -0.0260010f, -0.2291260f, 0.3488770f, 0.1036377f, -0.1116943f, 0.0406494f, 0.3037109f, }, + { -0.2464600f, -0.2500000f, -0.1783447f, -0.2355957f, -0.1719971f, -0.0488281f, 0.0598145f, -0.2712402f, 0.1557617f, 0.8917236f, }, + { -0.1867676f, -0.2125244f, -0.3250732f, 0.3856201f, 0.1418457f, -0.1818848f, 0.1850586f, -0.1828613f, 0.1491699f, 0.1022949f, }, + { 0.1617432f, 0.6575928f, 0.4746094f, 0.2373047f, -0.2082520f, -0.3527832f, -0.2325439f, -0.4761963f, -0.3914795f, 0.0251465f, }, + { -0.1722412f, -0.1170654f, -0.0356445f, -0.0483398f, -0.1888428f, -0.0102539f, -0.5377197f, -0.1309814f, 0.6752930f, 0.2192383f, }, + { 0.3857422f, 0.0058594f, -0.2855225f, -0.7182617f, -0.0224609f, -0.0063477f, 0.0157471f, 0.6589355f, 0.0461426f, -0.0391846f, }, +}; + +const float AmpCB2_NB[64][NUM_ERB_NB-11] = +{ + { -0.3272705f, -0.5357666f, -0.5212402f, -0.5770264f, -0.0291748f, 0.2365723f, 0.2133789f, 0.2821045f, 0.5249023f, }, + { -0.4830322f, -0.1585693f, 0.4256592f, 0.1947021f, -0.0460205f, 0.0360107f, -0.1456299f, -0.1938477f, 0.2578125f, }, + { -0.1920166f, -0.7766113f, -0.0615234f, 0.2192383f, -0.3077393f, -0.0083008f, 0.1613770f, 0.1492920f, 0.2762451f, }, + { -0.0614014f, -0.4768066f, 0.4499512f, -0.4759521f, -0.0169678f, 0.2546387f, 0.0058594f, 0.0426025f, 0.0667725f, }, + { -0.7796631f, 0.1635742f, -0.1790771f, -0.1296387f, -0.0235596f, 0.1617432f, -0.1452637f, 0.2922363f, 0.2039795f, }, + { -0.2419434f, -0.3170166f, -0.0476074f, -0.1835938f, 0.2772217f, -0.0462646f, -0.2868652f, 0.4969482f, 0.0085449f, }, + { -0.1165771f, -0.1077881f, -0.2160645f, -0.1300049f, -0.2982178f, -0.2171631f, -0.1343994f, -0.0806885f, 0.7720947f, }, + { 0.2283936f, -0.3262939f, 0.4389648f, 0.4605713f, -0.0831299f, 0.4077148f, -0.1730957f, 0.0855713f, -0.5191650f, }, + { -0.4798584f, -0.2246094f, -0.2915039f, -0.3267822f, -0.4327393f, -0.0050049f, 0.4486084f, 0.4691162f, 0.2683105f, }, + { -0.2091064f, -0.0395508f, 0.0731201f, 0.1614990f, 0.2230225f, -0.5992432f, -0.2036133f, 0.0751953f, 0.3183594f, }, + { 0.0439453f, -0.2159424f, -0.6424561f, -0.1560059f, 0.4260254f, 0.2362061f, 0.1654053f, -0.1584473f, 0.1162109f, }, + { 0.2198486f, 0.0548096f, 0.0306396f, -0.1246338f, -0.4475098f, 0.0584717f, 0.4268799f, 0.1882324f, -0.2727051f, }, + { -0.4167480f, -0.5472412f, -0.7061768f, 0.1716309f, 0.1473389f, 0.3642578f, 0.2156982f, 0.3981934f, -0.0975342f, }, + { -0.3813477f, 0.6392822f, 0.0561523f, 0.2449951f, -0.1861572f, -0.2570801f, -0.0939941f, 0.0666504f, 0.0167236f, }, + { 0.0489502f, -0.1596680f, 0.1182861f, 0.0249023f, -0.1984863f, -0.0718994f, -0.5196533f, 0.2128906f, 0.3461914f, }, + { 0.2908936f, 0.3344727f, -0.0516357f, 0.3864746f, 0.2343750f, -0.0842285f, -0.3662109f, -0.5479736f, 0.3079834f, }, + { -0.8170166f, -0.6268311f, -0.0902100f, -0.2342529f, 0.1499023f, 0.2873535f, 0.4077148f, 0.2321777f, 0.1304932f, }, + { -0.3887939f, -0.3190918f, 0.3374023f, -0.0258789f, -0.2515869f, -0.1680908f, 0.0852051f, 0.4509277f, -0.0152588f, }, + { -0.1164551f, -0.5043945f, -0.0493164f, 0.5245361f, 0.1579590f, 0.2154541f, 0.2985840f, -0.2791748f, -0.1693115f, }, + { -0.0017090f, 0.0620117f, 0.1402588f, 0.0010986f, -0.0533447f, 0.0633545f, -0.0512695f, 0.0549316f, -0.0916748f, }, + { -0.1992188f, -0.1697998f, -0.2695313f, -0.2386475f, -0.1428223f, 0.5881348f, 0.1357422f, 0.1325684f, -0.0954590f, }, + { 0.1632080f, 0.1032715f, -0.4191895f, 0.0694580f, 0.2100830f, -0.0947266f, -0.3323975f, 0.1473389f, 0.1198730f, }, + { -0.1748047f, -0.1082764f, 0.0384521f, -0.3699951f, 0.4213867f, 0.0933838f, -0.1541748f, -0.2619629f, 0.3612061f, }, + { -0.3197021f, 0.1839600f, 0.1601563f, 0.4989014f, 0.3814697f, 0.1998291f, -0.1711426f, -0.0054932f, -0.3897705f, }, + { 0.1705322f, -0.3187256f, -0.4444580f, -0.3024902f, -0.2082520f, 0.0717773f, 0.0242920f, 0.4542236f, 0.1485596f, }, + { -0.1524658f, -0.1459961f, 0.8823242f, 0.1215820f, 0.1072998f, -0.1634521f, 0.0013428f, -0.1185303f, -0.2050781f, }, + { 0.0874023f, -0.0047607f, 0.0284424f, 0.2374268f, 0.1889648f, -0.1801758f, 0.0671387f, -0.2779541f, 0.0374756f, }, + { 0.9049072f, 0.2556152f, -0.1990967f, -0.0694580f, -0.1649170f, -0.0241699f, -0.0589600f, -0.0628662f, -0.1644287f, }, + { -0.0258789f, -0.3233643f, -0.0633545f, 0.0238037f, 0.3593750f, -0.0970459f, 0.1794434f, 0.0798340f, -0.1767578f, }, + { 0.3852539f, 0.1671143f, 0.4841309f, 0.4128418f, -0.3395996f, -0.5194092f, -0.1412354f, -0.0258789f, 0.0478516f, }, + { 0.1051025f, 0.6181641f, 0.5786133f, -0.3067627f, -0.4166260f, -0.0673828f, -0.2805176f, -0.0701904f, 0.1379395f, }, + { 0.1437988f, 0.1914063f, 0.5604248f, 0.1511230f, 0.0447998f, 0.1984863f, 0.0732422f, -0.7188721f, 0.0198975f, }, + { -0.4567871f, -0.4455566f, -0.4774170f, 0.0874023f, 0.1121826f, -0.1832275f, 0.0067139f, 0.2205811f, 0.4639893f, }, + { -0.6800537f, -0.5657959f, 0.1495361f, 0.3919678f, 0.4643555f, 0.1820068f, -0.1105957f, 0.0122070f, 0.0493164f, }, + { -0.2126465f, -0.2292480f, -0.2612305f, 0.2015381f, 0.2001953f, 0.4853516f, -0.4189453f, -0.1402588f, 0.1666260f, }, + { 0.2492676f, 0.0478516f, 0.0937500f, -0.1872559f, 0.1337891f, 0.4652100f, -0.0257568f, -0.2523193f, -0.1605225f, }, + { -0.5086670f, 0.1397705f, -0.3353271f, -0.0181885f, 0.6464844f, -0.0897217f, 0.0534668f, 0.0068359f, -0.0493164f, }, + { -0.0194092f, -0.2641602f, -0.1170654f, 0.4262695f, -0.0842285f, -0.0839844f, -0.1319580f, 0.3371582f, -0.1453857f, }, + { 0.0798340f, 0.2503662f, -0.2617188f, -0.3918457f, -0.2225342f, 0.0906982f, 0.0837402f, -0.0916748f, 0.3031006f, }, + { 0.0195313f, 0.1561279f, 0.3962402f, 0.2287598f, 0.3037109f, 0.1455078f, -0.7296143f, -0.0583496f, 0.0146484f, }, + { -0.0426025f, -0.0079346f, -0.2868652f, -0.0270996f, -0.2048340f, -0.4375000f, 0.1359863f, 0.3990479f, 0.1784668f, }, + { -0.1359863f, -0.0168457f, 0.2880859f, -0.3371582f, 0.0878906f, -0.4665527f, 0.3079834f, 0.0263672f, 0.1428223f, }, + { 0.5368652f, -0.5162354f, -0.2258301f, 0.1552734f, 0.0467529f, 0.2119141f, -0.0467529f, -0.1580811f, 0.0103760f, }, + { -0.0161133f, 0.1383057f, 0.1837158f, 0.1790771f, -0.2916260f, -0.2655029f, 0.4916992f, -0.3359375f, 0.0294189f, }, + { -0.5313721f, -0.2567139f, -0.0686035f, 0.0997314f, 0.4832764f, 0.6678467f, 0.2369385f, -0.1950684f, -0.2867432f, }, + { 0.0245361f, 0.1723633f, -0.0971680f, 0.3406982f, -0.5158691f, 0.3939209f, -0.2431641f, -0.0194092f, -0.0194092f, }, + { 0.4986572f, -0.1890869f, 0.1245117f, -0.2659912f, -0.0947266f, -0.2548828f, -0.0179443f, -0.0051270f, 0.2294922f, }, + { -0.1256104f, 0.6081543f, -0.2509766f, 0.0135498f, 0.1733398f, 0.2613525f, 0.0368652f, -0.3142090f, -0.1203613f, }, + { -0.0582275f, -0.4512939f, -0.2867432f, -0.2519531f, -0.0408936f, -0.0268555f, 0.7149658f, 0.0069580f, -0.0008545f, }, + { -0.6600342f, -0.0666504f, -0.0430908f, 0.3498535f, 0.0167236f, -0.0166016f, 0.4282227f, 0.1210938f, -0.2513428f, }, + { -0.2482910f, -0.1375732f, -0.0230713f, -0.0366211f, -0.2628174f, 0.4401855f, 0.3079834f, -0.4549561f, 0.1862793f, }, + { -0.4635010f, 0.2604980f, 0.5312500f, -0.1123047f, -0.0560303f, 0.3322754f, 0.2177734f, -0.0086670f, -0.3698730f, }, + { -0.1070557f, 0.2401123f, -0.2008057f, -0.5410156f, 0.0625000f, 0.0047607f, 0.2144775f, 0.3509521f, -0.1156006f, }, + { 0.2248535f, 0.1666260f, 0.1831055f, 0.1038818f, 0.0725098f, -0.3530273f, -0.0493164f, 0.4061279f, -0.3757324f, }, + { -0.1922607f, -0.1535645f, -0.1187744f, -0.0233154f, -0.0476074f, 0.0054932f, 0.0765381f, -0.0277100f, 0.1982422f, }, + { -0.0174561f, 0.0262451f, 0.2633057f, 0.5915527f, 0.6512451f, 0.4146729f, -0.0242920f, -0.5423584f, -0.3773193f, }, + { -0.0345459f, -0.0263672f, 0.1510010f, -0.1804199f, -0.6883545f, -0.0946045f, 0.0640869f, 0.2572021f, 0.3013916f, }, + { 0.3581543f, -0.0311279f, 0.2976074f, 0.1005859f, 0.7291260f, -0.2221680f, -0.1623535f, -0.1467285f, -0.2969971f, }, + { 0.1098633f, 0.0793457f, -0.6901855f, 0.3529053f, -0.1878662f, -0.0552979f, 0.2028809f, 0.0281982f, -0.0177002f, }, + { 0.2027588f, 0.0904541f, -0.0405273f, 0.1490479f, 0.2208252f, 0.1151123f, 0.5897217f, -0.1938477f, -0.5638428f, }, + { 0.0079346f, -0.0964355f, -0.1202393f, -0.1090088f, 0.4118652f, 0.3842773f, 0.0352783f, 0.3597412f, -0.6079102f, }, + { -0.0806885f, -0.0521240f, 0.1759033f, 0.9394531f, 0.0192871f, -0.2336426f, -0.2525635f, -0.2095947f, -0.0510254f, }, + { 0.3243408f, 0.5150146f, 0.1837158f, -0.1337891f, 0.0733643f, -0.1789551f, -0.2141113f, -0.0584717f, -0.0194092f, }, + { 0.4123535f, 0.6411133f, 0.6176758f, 0.4884033f, 0.1588135f, 0.0512695f, -0.1547852f, -0.3433838f, -0.5122070f, }, +}; + + + +const float PowerCB_WB[64][2] = +{ + { -1.6459961f, -0.8359375f, }, + { -0.083007813f, 0.17089844f, }, + { -0.31152344f, -0.45849609f, }, + { 0.02734375f, 0.52441406f, }, + { -0.76123047f, -0.30566406f, }, + { 0.09765625f, 0.16796875f, }, + { -0.19384766f, 0.11621094f, }, + { 0.13867188f, 0.69091797f, }, + { -0.64599609f, -0.91796875f, }, + { -0.265625f, 0.57128906f, }, + { -0.30224609f, -0.12451172f, }, + { 0.28662109f, 0.47558594f, }, + { -0.61621094f, -0.047851563f, }, + { 0.15966797f, 0.073730469f, }, + { 0.020019531f, -0.14746094f, }, + { 0.45947266f, 0.91601563f, }, + { -1.1020508f, -0.60205078f, }, + { 0.013671875f, 0.098632813f, }, + { -0.25390625f, -0.27392578f, }, + { 0.16503906f, 0.51171875f, }, + { -0.52734375f, -0.24169922f, }, + { 0.092773438f, 0.28417969f, }, + { -0.13867188f, -0.01171875f, }, + { 0.28222656f, 0.77392578f, }, + { -0.64648438f, -0.53173828f, }, + { -0.034667969f, 0.27734375f, }, + { -0.22998047f, -0.012695313f, }, + { 0.55664063f, 0.44384766f, }, + { -0.41796875f, -0.0625f, }, + { 0.20751953f, 0.36132813f, }, + { 0.068359375f, 0.005859375f, }, + { 0.77880859f, 0.92333984f, }, + { -1.0625f, -1.1279297f, }, + { -0.15039063f, 0.26416016f, }, + { -0.15380859f, -0.41943359f, }, + { -0.0390625f, 0.64160156f, }, + { -0.87011719f, 0.24902344f, }, + { 0.19677734f, 0.21972656f, }, + { -0.29638672f, 0.28417969f, }, + { 0.070800781f, 0.89697266f, }, + { -0.44921875f, -0.67675781f, }, + { -0.10986328f, 0.42578125f, }, + { -0.19287109f, -0.12597656f, }, + { 0.40478516f, 0.47900391f, }, + { -0.46142578f, 0.16845703f, }, + { 0.31396484f, 0.11767578f, }, + { -0.02734375f, -0.011230469f, }, + { 0.59130859f, 0.72363281f, }, + { -0.87548828f, -0.71240234f, }, + { 0.01953125f, 0.1953125f, }, + { -0.11669922f, -0.22998047f, }, + { 0.25976563f, 0.60449219f, }, + { -0.37792969f, -0.25195313f, }, + { 0.11914063f, 0.40576172f, }, + { -0.076660156f, 0.07421875f, }, + { 0.28125f, 1.1166992f, }, + { -0.453125f, -0.41210938f, }, + { 0.020019531f, 0.37060547f, }, + { -0.078613281f, -0.096679688f, }, + { 0.42626953f, 0.66064453f, }, + { -0.3125f, 0.051269531f, }, + { 0.33935547f, 0.30419922f, }, + { 0.17773438f, -0.08984375f, }, + { 0.60449219f, 1.1943359f, }, +}; + + +const float PowerCB_NB[64][2] = +{ + { -1.6352539f, -1.359375f, }, + { -0.3828125f, 0.18798828f, }, + { -0.43505859f, -0.27441406f, }, + { 0.061523438f, 0.44677734f, }, + { -0.74121094f, -0.70214844f, }, + { 0.1484375f, 0.025878906f, }, + { -0.15332031f, -0.21826172f, }, + { 0.33544922f, 0.59521484f, }, + { -1.262207f, -0.88232422f, }, + { -0.031738281f, 0.074707031f, }, + { -0.59521484f, -0.16455078f, }, + { 0.24267578f, 0.34179688f, }, + { -0.43652344f, -0.51318359f, }, + { 0.078613281f, 0.22021484f, }, + { -0.022460938f, -0.25195313f, }, + { 0.48193359f, 0.74169922f, }, + { -1.1118164f, -1.1245117f, }, + { -0.17285156f, 0.21728516f, }, + { -0.25976563f, -0.26367188f, }, + { 0.0024414063f, 0.62060547f, }, + { -0.51123047f, -0.69970703f, }, + { 0.328125f, -0.10986328f, }, + { -0.16357422f, -0.036621094f, }, + { 0.49169922f, 0.515625f, }, + { -0.66503906f, -0.91748047f, }, + { -0.045410156f, 0.17919922f, }, + { -0.22851563f, -0.12646484f, }, + { 0.87890625f, -0.14160156f, }, + { -0.54589844f, -0.38720703f, }, + { 0.20117188f, 0.23046875f, }, + { -0.0043945313f, -0.096191406f, }, + { 0.71826172f, 0.79785156f, }, + { -1.2827148f, -1.3901367f, }, + { -0.13134766f, 0.080078125f, }, + { -0.33642578f, -0.18212891f, }, + { 0.2109375f, 0.45898438f, }, + { -0.78173828f, -0.40966797f, }, + { 0.15185547f, 0.13232422f, }, + { -0.10351563f, -0.12255859f, }, + { 0.26513672f, 0.83691406f, }, + { -0.98339844f, -0.65234375f, }, + { 0.053222656f, 0.11767578f, }, + { -0.38525391f, -0.053710938f, }, + { 0.35595703f, 0.43359375f, }, + { -0.20410156f, -0.62353516f, }, + { 0.125f, 0.32910156f, }, + { 0.10644531f, -0.10595703f, }, + { 0.50146484f, 1.0083008f, }, + { -0.86376953f, -1.1196289f, }, + { -0.13476563f, 0.41650391f, }, + { -0.17578125f, -0.37304688f, }, + { 0.18359375f, 0.60888672f, }, + { -0.62207031f, -0.54785156f, }, + { 0.29394531f, 0.1328125f, }, + { -0.064941406f, -0.015625f, }, + { 0.67089844f, 0.54589844f, }, + { -0.90820313f, -0.87646484f, }, + { -0.011230469f, 0.30273438f, }, + { -0.25634766f, 0.029296875f, }, + { 0.52246094f, 0.26757813f, }, + { -0.33740234f, -0.39013672f, }, + { 0.34228516f, 0.27929688f, }, + { 0.039550781f, 0.0087890625f, }, + { 0.95166016f, 1.0351563f, }, +}; + +/* sinc for warp/extrapolate./16384., in Q14 */ +const float sinc[8][12] = +{ + {0.0f/16384.0f,0.0f/16384.0f,0.0f/16384.0f,0.0f/16384.0f,0.0f/16384.0f,16384.0f/16384.0f,0.0f/16384.0f,0.0f/16384.0f,0.0f/16384.0f,0.0f/16384.0f,0.0f/16384.0f,0.0f/16384.0f,}, + {-388.0f/16384.0f,484.0f/16384.0f,-638.0f/16384.0f,939.0f/16384.0f,-1773.0f/16384.0f,15966.0f/16384.0f,2281.0f/16384.0f,-1063.0f/16384.0f,694.0f/16384.0f,-514.0f/16384.0f,409.0f/16384.0f,-339.0f/16384.0f,}, + {-701.0f/16384.0f,868.0f/16384.0f,-1134.0f/16384.0f,1639.0f/16384.0f,-2949.0f/16384.0f,14751.0f/16384.0f,4917.0f/16384.0f,-2106.0f/16384.0f,1341.0f/16384.0f,-982.0f/16384.0f,776.0f/16384.0f,-640.0f/16384.0f,}, + {-895.0f/16384.0f,1101.0f/16384.0f,-1427.0f/16384.0f,2029.0f/16384.0f,-3503.0f/16384.0f,12849.0f/16384.0f,7709.0f/16384.0f,-2964.0f/16384.0f,1835.0f/16384.0f,-1328.0f/16384.0f,1042.0f/16384.0f,-856.0f/16384.0f,}, + {-947.0f/16384.0f,1159.0f/16384.0f,-1489.0f/16384.0f,2086.0f/16384.0f,-3476.0f/16384.0f,10430.0f/16384.0f,10430.0f/16384.0f,-3476.0f/16384.0f,2086.0f/16384.0f,-1489.0f/16384.0f,1159.0f/16384.0f,-947.0f/16384.0f,}, + {-856.0f/16384.0f,1042.0f/16384.0f,-1328.0f/16384.0f,1835.0f/16384.0f,-2964.0f/16384.0f,7709.0f/16384.0f,12849.0f/16384.0f,-3503.0f/16384.0f,2029.0f/16384.0f,-1427.0f/16384.0f,1101.0f/16384.0f,-895.0f/16384.0f,}, + {-640.0f/16384.0f,776.0f/16384.0f,-982.0f/16384.0f,1341.0f/16384.0f,-2106.0f/16384.0f,4917.0f/16384.0f,14751.0f/16384.0f,-2949.0f/16384.0f,1639.0f/16384.0f,-1134.0f/16384.0f,868.0f/16384.0f,-701.0f/16384.0f,}, + {-339.0f/16384.0f,409.0f/16384.0f,-514.0f/16384.0f,694.0f/16384.0f,-1063.0f/16384.0f,2281.0f/16384.0f,15966.0f/16384.0f,-1773.0f/16384.0f,939.0f/16384.0f,-638.0f/16384.0f,484.0f/16384.0f,-388.0f/16384.0f,}, +}; + +/*----------------------------------------------------------------------------------* + * Highrate SWB BWE tables + *----------------------------------------------------------------------------------*/ + +const float overlap_coefs_48kHz[NSV_OVERLAP*WIDTH_BAND] = +{ 0.30f, 0.34f, 0.36f, 0.39f, 0.42f, 0.44f, 0.46f, 0.475f, 0.49f, 0.51f, 0.54f, 0.57f, 0.62f, 0.72f, 0.83f, 0.95f }; + +const float overlap_coefs[NSV_OVERLAP*WIDTH_BAND] = +{ 0.2700f, 0.3060f, 0.3240f, 0.3510f, 0.3780f, 0.3960f, 0.4140f, 0.4275f, 0.4410f, 0.4590f, 0.4860f, 0.5130f, 0.5580f, 0.6480f, 0.7470f, 0.855f }; + +const float swb_hr_env_code1[NUM_ENVLOPE_CODE_HR1*2] = +{ + 0.044983f, 0.041700f, + 0.524276f, 0.469365f, + 0.671757f, 0.605513f, + 0.983501f, 0.855093f, + 1.227874f, 1.132200f, + 1.672212f, 1.432704f, + 2.548211f, 2.361091f, + 3.196961f, 3.306999f, + 2.580753f, 5.217478f, + 4.207751f, 7.243802f, + 3.517157f, 1.738487f, + 4.381567f, 2.753657f, + 4.758266f, 4.696094f, + 6.827988f, 6.106459f, + 4.450459f, 10.131211f, + 7.256045f, 12.488036f, + 6.708720f, 1.953339f, + 6.604030f, 3.699560f, + 10.612728f, 2.537916f, + 9.387467f, 4.241173f, + 7.119045f, 8.281485f, + 9.062854f, 7.086526f, + 8.919388f, 9.762914f, + 11.299319f, 11.763904f, + 11.782217f, 5.879754f, + 14.050457f, 9.665228f, + 11.201525f, 9.001128f, + 14.434753f, 13.236565f, + 14.337260f, 3.904411f, + 20.071049f, 4.335061f, + 18.105812f, 8.223599f, + 22.352287f, 9.603263f, + 7.242756f, 16.564487f, + 11.777528f, 19.167645f, + 11.121798f, 15.455982f, + 14.563579f, 17.359568f, + 17.821218f, 11.894719f, + 17.466026f, 15.296063f, + 21.336960f, 13.455175f, + 20.544336f, 17.125366f, + 9.056358f, 22.338306f, + 11.238424f, 28.832520f, + 13.262732f, 25.143383f, + 16.243559f, 28.256853f, + 15.269305f, 21.539135f, + 16.983515f, 24.699589f, + 19.591730f, 22.689682f, + 20.146198f, 25.888466f, + 17.797417f, 19.453121f, + 21.290621f, 20.186579f, + 24.097319f, 19.086721f, + 23.613092f, 22.545858f, + 23.682005f, 16.328239f, + 26.886553f, 19.402439f, + 26.009769f, 15.632211f, + 28.939930f, 16.240620f, + 25.094482f, 12.366419f, + 27.713383f, 13.263280f, + 28.330946f, 10.329259f, + 30.632830f, 12.851279f, + 25.273802f, 6.138124f, + 29.195339f, 7.222413f, + 32.171322f, 5.019567f, + 31.979000f, 9.473855f, +}; + +const float swb_hr_env_code2[NUM_ENVLOPE_CODE_HR2*2] = +{ + 0.512539f, 0.472507f, + 1.338963f, 1.108591f, + 2.544041f, 1.759765f, + 3.124053f, 3.045299f, + 4.892713f, 3.721097f, + 4.010297f, 5.750862f, + 5.111215f, 2.164709f, + 6.667518f, 3.893404f, + 8.454117f, 2.751430f, + 11.123573f, 3.518174f, + 6.622948f, 5.960704f, + 8.562429f, 5.003579f, + 8.919363f, 7.784057f, + 10.759037f, 5.959438f, + 12.449193f, 8.359519f, + 13.677005f, 11.230577f, + 13.672631f, 5.457414f, + 16.471989f, 3.917684f, + 20.910328f, 6.432810f, + 25.457325f, 8.617220f, + 16.410700f, 7.574456f, + 18.574385f, 10.291498f, + 22.088757f, 12.512156f, + 21.170530f, 17.208714f, + 5.276107f, 9.622470f, + 9.093585f, 11.274686f, + 11.945659f, 15.538144f, + 16.550409f, 15.046564f, + 6.358148f, 17.547396f, + 13.316619f, 21.765524f, + 7.646096f, 26.106720f, + 2.451297f, 31.933104f +}; + +const float swb_hr_env_code3[NUM_ENVLOPE_CODE_HR_TR*N_BANDS_TRANS_BWE_HR] = +{ + 0.799219f, 0.677609f, + 1.754571f, 1.215689f, + 2.846222f, 2.017775f, + 4.379336f, 1.975914f, + 5.935472f, 2.945818f, + 3.938621f, 4.220399f, + 8.080808f, 2.632276f, + 7.579771f, 4.986835f, + 4.956485f, 10.363663f, + 7.739148f, 8.652471f, + 9.238397f, 7.051655f, + 10.205707f, 5.619638f, + 10.645117f, 4.374648f, + 11.660180f, 3.474015f, + 10.845836f, 2.664596f, + 11.724073f, 1.637023f +}; + +/* Searching thresholds for quantization of norms */ +const float thren_HQ[39] = +{ + 110217.974940f, 77935.877489f, + 55108.987470f, 38967.938744f, + 27554.493735f, 19483.969372f, + 13777.246868f, 9741.984686f, + 6888.623434f, 4870.992343f, + 3444.311717f, 2435.496172f, + 1722.155858f, 1217.748086f, + 861.077929f, 608.874043f, + 430.538965f, 304.437021f, + 215.269482f, 152.218511f, + 107.634741f, 76.109255f, + 53.817371f, 38.054628f, + 26.908685f, 19.027314f, + 13.454343f, 9.513657f, + 6.727171f, 4.756828f, + 3.363586f, 2.378414f, + 1.681793f, 1.189207f, + 0.840896f, 0.594604f, + 0.420448f, 0.297302f, + 0.210224f +}; + +/*----------------------------------------------------------------------------------* + * ACELP/HQ core switching + *----------------------------------------------------------------------------------*/ + +/* short filters for BWE of ACELP->HQ switching frame */ +const float hp12800_16000[21] = +{ + -0.00000000f, 0.00212227f, -0.00632535f, 0.01161181f, -0.01235466f, 0.00000000f, 0.03177450f, -0.08143591f, + 0.13749378f, -0.18212549f, 0.19916883f, -0.18212549f, 0.13749378f, -0.08143591f, 0.03177450f, 0.00000000f, + -0.01235466f, 0.01161181f, -0.00632535f, 0.00212227f, -0.00000000f +}; + +const float hp12800_32000[41] = +{ + -0.00000000f, 0.00136608f, 0.00106650f, -0.00143351f, -0.00317865f, 0.00000000f, 0.00583523f, 0.00477033f, + -0.00620853f, -0.01289218f, -0.00000000f, 0.02060233f, 0.01596749f, -0.02003257f, -0.04092361f, 0.00000000f, + 0.06909412f, 0.05929089f, -0.09152269f, -0.30127931f, 0.60052441f, -0.30127931f, -0.09152269f, 0.05929089f, + 0.06909412f, 0.00000000f, -0.04092361f, -0.02003257f, 0.01596749f, 0.02060233f, -0.00000000f, -0.01289218f, + -0.00620853f, 0.00477033f, 0.00583523f, 0.00000000f, -0.00317865f, -0.00143351f, 0.00106650f, 0.00136608f, + -0.00000000f +}; + +const float hp12800_48000[61] = +{ + -0.00000000f, 0.00067336f, 0.00101850f, 0.00071064f, -0.00030497f, -0.00156225f, -0.00211804f, -0.00111583f, + 0.00136699f, 0.00388820f, 0.00427438f, 0.00122967f, -0.00413694f, -0.00827775f, -0.00727539f, 0.00000000f, + 0.00994020f, 0.01548435f, 0.01063964f, -0.00437614f, -0.02123403f, -0.02726869f, -0.01372549f, 0.01631621f, + 0.04603958f, 0.05175432f, 0.01589299f, -0.06098444f, -0.15675008f, -0.23604172f, 0.73360516f, -0.23604172f, + -0.15675008f, -0.06098444f, 0.01589299f, 0.05175432f, 0.04603958f, 0.01631621f, -0.01372549f, -0.02726869f, + -0.02123403f, -0.00437614f, 0.01063964f, 0.01548435f, 0.00994020f, 0.00000000f, -0.00727539f, -0.00827775f, + -0.00413694f, 0.00122967f, 0.00427438f, 0.00388820f, 0.00136699f, -0.00111583f, -0.00211804f, -0.00156225f, + -0.00030497f, 0.00071064f, 0.00101850f, 0.00067336f, -0.00000000f +}; + + +const float hp16000_32000[33] = +{ + -0.00000000f, 0.00188788f, -0.00000000f, -0.00386248f, -0.00000000f, 0.00824247f, -0.00000000f, -0.01594711f, + -0.00000000f, 0.02867656f, -0.00000000f, -0.05071856f, -0.00000000f, 0.09801591f, -0.00000000f, -0.31594176f, + 0.50070579f, -0.31594176f, -0.00000000f, 0.09801591f, -0.00000000f, -0.05071856f, -0.00000000f, 0.02867656f, + -0.00000000f, -0.01594711f, -0.00000000f, 0.00824247f, -0.00000000f, -0.00386248f, -0.00000000f, 0.00188788f, + -0.00000000f +}; + +const float hp16000_48000[49] = +{ + -0.00000000f, 0.00100660f, 0.00119953f, -0.00000000f, -0.00195325f, -0.00254135f, -0.00000000f, 0.00421805f, + 0.00534416f, 0.00000000f, -0.00829341f, -0.01018351f, -0.00000000f, 0.01504620f, 0.01817861f, 0.00000000f, + -0.02654841f, -0.03231243f, -0.00000000f, 0.04992164f, 0.06470722f, 0.00000000f, -0.13575216f, -0.27474220f, + 0.66706142f, -0.27474220f, -0.13575216f, 0.00000000f, 0.06470722f, 0.04992164f, -0.00000000f, -0.03231243f, + -0.02654841f, 0.00000000f, 0.01817861f, 0.01504620f, -0.00000000f, -0.01018351f, -0.00829341f, 0.00000000f, + 0.00534416f, 0.00421805f, -0.00000000f, -0.00254135f, -0.00195325f, -0.00000000f, 0.00119953f, 0.00100660f, + -0.00000000f +}; + +const double cu15[28][3] = +{ + /* xx/3, xx*xx/3, xx*xx*xx/3 xx v */ + /* 0:*/ { 0.0222222222, 0.0014814815, 0.0000987654 }, /* 1/15 */ + /* 1:*/ { 0.0444444444, 0.0059259259, 0.0007901235 }, /* 2/15 */ + /* 2:*/ { 0.0666666667, 0.0133333333, 0.0026666667 }, + /* 3:*/ { 0.0888888889, 0.0237037037, 0.0063209877 }, + /* 4:*/ { 0.1111111111, 0.0370370370, 0.0123456790 }, + /* 5:*/ { 0.1333333333, 0.0533333333, 0.0213333333 }, + /* 6:*/ { 0.1555555556, 0.0725925926, 0.0338765432 }, + /* 7:*/ { 0.1777777778, 0.0948148148, 0.0505679012 }, + /* 8:*/ { 0.2000000000, 0.1200000000, 0.0720000000 }, /* 9/15 */ + /* 9:*/ { 0.2222222222, 0.1481481481, 0.0987654321 }, /* 10/15 */ + /*10:*/ { 0.2444444444, 0.1792592593, 0.1314567901 }, + /*11:*/ { 0.2666666667, 0.2133333333, 0.1706666667 }, + /*12:*/ { 0.2888888889, 0.2503703704, 0.2169876543 }, + /*13:*/ { 0.3111111111, 0.2903703704, 0.2710123457 }, /* 14/15 */ + /*14:*/ { 0.3555555556, 0.3792592593, 0.4045432099 }, /* 16/15 */ + /*15:*/ { 0.3777777778, 0.4281481481, 0.4852345679 }, + /*16:*/ { 0.4000000000, 0.4800000000, 0.5760000000 }, /* 18/15 */ + /*17:*/ { 0.4222222222, 0.5348148148, 0.6774320988 }, + /*18:*/ { 0.4444444444, 0.5925925926, 0.7901234568 }, /* 20/15 */ + /*19:*/ { 0.4666666667, 0.6533333333, 0.9146666667 }, + /*20:*/ { 0.4888888889, 0.7170370370, 1.0516543210 }, + /*21:*/ { 0.5111111111, 0.7837037037, 1.2016790123 }, + /*22:*/ { 0.5333333333, 0.8533333333, 1.3653333333 }, + /*23:*/ { 0.5555555556, 0.9259259259, 1.5432098765 }, + /*24:*/ { 0.5777777778, 1.0014814815, 1.7359012346 }, + /*25:*/ { 0.6000000000, 1.0800000000, 1.9440000000 }, /* 27/15 */ + /*26:*/ { 0.6222222222, 1.1614814815, 2.1680987654 }, + /*27:*/ { 0.6444444444, 1.2459259259, 2.4087901235 }, /* 29/15 */ +}; + +const double cu4[6][3] = +{ + /* xx/3, xx*xx/3, xx*xx*xx/3 */ + /* 0:*/ { 0.0833333333, 0.0208333333, 0.0052083333 }, /*0.25*/ + /* 1:*/ { 0.1666666667, 0.0833333333, 0.0416666667 }, /*0.5*/ + /* 2:*/ { 0.2500000000, 0.1875000000, 0.1406250000 }, /*0.75*/ + /* 3:*/ { 0.4166666667, 0.5208333333, 0.6510416667 }, /*1.25*/ + /* 4:*/ { 0.5000000000, 0.7500000000, 1.1250000000 }, /*1.5*/ + /* 5:*/ { 0.5833333333, 1.0208333333, 1.7864583333 } /*1.75*/ +}; + +const short ct2[7][13] = +{ + /* accepted configurations */ + /*input 12.8, output :*/ + /*8*/ {30, 22, 30, 16, 25, 30, 19, 30, 30, 0, 8, 4, 15}, + /*16*/ {25, 22, 19, 16, 16, 0, 0, 0, 12, 1, 4, 4, 15}, + /*32*/ {19, 16, 19, 16, 16, 0, 0, 0, 6, 2, 2, 4, 15}, + /*48*/ {17, 14, 15, 16, 16, 0, 0, 0, 4, 3, 4, 4, 15}, + + /*input 16, output :*/ + /*12*/ { 9, 3, 4, 5, 9, 0, 0, 0, 5, 0, 5, 5, 4}, + /*32*/ { 4, 4, 4, 4, 4, 0, 0, 0, 2, 1, 1, 4, 4}, + /*48*/ {18, 18, 18, 18, 18, 0, 0, 0, 5, 2, 1, 4, 15}, +}; + + +/*----------------------------------------------------------------------------------* + * hp filter for filtering random part of excitation in frame error concealment + * Used in lib_dec\syn_bfi.c + *----------------------------------------------------------------------------------*/ + +const float h_high[5] = { -0.0125f, -0.1090f, 0.7813f, -0.1090f, -0.0125f }; + +const float sincos_t_rad3[T_SIN_PI_2+1] = +{ + 0.000000000000000f, 0.004090604026235f, 0.008181139603937f, 0.012271538285720f, 0.016361731626487f, 0.020451651184577f, 0.024541228522912f, 0.028630395210139f, + 0.032719082821776f, 0.036807222941359f, 0.040894747161583f, 0.044981587085452f, 0.049067674327418f, 0.053152940514528f, 0.057237317287569f, 0.061320736302209f, + 0.065403129230143f, 0.069484427760237f, 0.073564563599667f, 0.077643468475068f, 0.081721074133668f, 0.085797312344440f, 0.089872114899235f, 0.093945413613929f, + 0.098017140329561f, 0.102087226913474f, 0.106155605260457f, 0.110222207293883f, 0.114286964966846f, 0.118349810263305f, 0.122410675199216f, 0.126469491823675f, + 0.130526192220052f, 0.134580708507126f, 0.138632972840227f, 0.142682917412363f, 0.146730474455362f, 0.150775576241001f, 0.154818155082141f, 0.158858143333861f, + 0.162895473394589f, 0.166930077707230f, 0.170961888760301f, 0.174990839089060f, 0.179016861276633f, 0.183039887955141f, 0.187059851806832f, 0.191076685565203f, + 0.195090322016128f, 0.199100693998982f, 0.203107734407763f, 0.207111376192219f, 0.211111552358965f, 0.215108195972610f, 0.219101240156870f, 0.223090618095693f, + 0.227076263034373f, 0.231058108280671f, 0.235036087205927f, 0.239010133246176f, 0.242980179903264f, 0.246946160745958f, 0.250908009411060f, 0.254865659604515f, + 0.258819045102521f, 0.262768099752639f, 0.266712757474898f, 0.270652952262902f, 0.274588618184932f, 0.278519689385053f, 0.282446100084213f, 0.286367784581343f, + 0.290284677254462f, 0.294196712561769f, 0.298103825042740f, 0.302005949319228f, 0.305903020096553f, 0.309794972164597f, 0.313681740398891f, 0.317563259761712f, + 0.321439465303162f, 0.325310292162263f, 0.329175675568039f, 0.333035550840599f, 0.336889853392220f, 0.340738518728429f, 0.344581482449080f, 0.348418680249435f, + 0.352250047921233f, 0.356075521353776f, 0.359895036534988f, 0.363708529552498f, 0.367515936594704f, 0.371317193951837f, 0.375112238017038f, 0.378901005287410f, + 0.382683432365090f, 0.386459455958303f, 0.390229012882428f, 0.393992040061048f, 0.397748474527011f, 0.401498253423481f, 0.405241314004990f, 0.408977593638489f, + 0.412707029804395f, 0.416429560097637f, 0.420145122228702f, 0.423853654024676f, 0.427555093430282f, 0.431249378508924f, 0.434936447443717f, 0.438616238538528f, + 0.442288690219001f, 0.445953741033595f, 0.449611329654607f, 0.453261394879198f, 0.456903875630421f, 0.460538710958240f, 0.464165840040552f, 0.467785202184201f, + 0.471396736825998f, 0.475000383533732f, 0.478596082007181f, 0.482183772079123f, 0.485763393716340f, 0.489334887020625f, 0.492898192229784f, 0.496453249718633f, + 0.500000000000000f, 0.503538383725718f, 0.507068341687617f, 0.510589814818519f, 0.514102744193222f, 0.517607071029487f, 0.521102736689023f, 0.524589682678469f, + 0.528067850650368f, 0.531537182404149f, 0.534997619887097f, 0.538449105195327f, 0.541891580574752f, 0.545324988422046f, 0.548749271285616f, 0.552164371866554f, + 0.555570233019602f, 0.558966797754107f, 0.562354009234973f, 0.565731810783613f, 0.569100145878898f, 0.572458958158102f, 0.575808191417845f, 0.579147789615035f, + 0.582477696867802f, 0.585797857456439f, 0.589108215824328f, 0.592408716578875f, 0.595699304492433f, 0.598979924503229f, 0.602250521716282f, 0.605511041404326f, + 0.608761429008721f, 0.612001630140370f, 0.615231590580627f, 0.618451256282204f, 0.621660573370077f, 0.624859488142386f, 0.628047947071334f, 0.631225896804083f, + 0.634393284163645f, 0.637550056149777f, 0.640696159939861f, 0.643831542889791f, 0.646956152534857f, 0.650069936590618f, 0.653172842953777f, 0.656264819703058f, + 0.659345815100069f, 0.662415777590172f, 0.665474655803342f, 0.668522398555031f, 0.671558954847018f, 0.674584273868271f, 0.677598304995789f, 0.680600997795453f, + 0.683592302022871f, 0.686572167624217f, 0.689540544737067f, 0.692497383691237f, 0.695442635009612f, 0.698376249408973f, 0.701298177800824f, 0.704208371292213f, + 0.707106781186547f, 0.709993358984412f, 0.712868056384380f, 0.715730825283819f, 0.718581617779698f, 0.721420386169390f, 0.724247082951467f, 0.727061660826497f, + 0.729864072697836f, 0.732654271672413f, 0.735432211061519f, 0.738197844381584f, 0.740951125354959f, 0.743692007910687f, 0.746420446185274f, 0.749136394523459f, + 0.751839807478977f, 0.754530639815318f, 0.757208846506485f, 0.759874382737746f, 0.762527203906388f, 0.765167265622459f, 0.767794523709512f, 0.770408934205345f, + 0.773010453362737f, 0.775599037650177f, 0.778174643752598f, 0.780737228572094f, 0.783286749228650f, 0.785823163060853f, 0.788346427626606f, 0.790856500703845f, + 0.793353340291235f, 0.795836904608884f, 0.798307152099031f, 0.800764041426753f, 0.803207531480645f, 0.805637581373517f, 0.808054150443073f, 0.810457198252595f, + 0.812846684591615f, 0.815222569476594f, 0.817584813151584f, 0.819933376088899f, 0.822268218989775f, 0.824589302785025f, 0.826896588635696f, 0.829190037933717f, + 0.831469612302545f, 0.833735273597809f, 0.835986983907947f, 0.838224705554838f, 0.840448401094438f, 0.842658033317402f, 0.844853565249707f, 0.847034960153274f, + 0.849202181526579f, 0.851355193105265f, 0.853493958862750f, 0.855618443010829f, 0.857728610000272f, 0.859824424521420f, 0.861905851504774f, 0.863972856121587f, + 0.866025403784439f, 0.868063460147822f, 0.870086991108711f, 0.872095962807139f, 0.874090341626759f, 0.876070094195407f, 0.878035187385663f, 0.879985588315404f, + 0.881921264348355f, 0.883842183094633f, 0.885748312411290f, 0.887639620402854f, 0.889516075421856f, 0.891377646069366f, 0.893224301195515f, 0.895056009900018f, + 0.896872741532688f, 0.898674465693954f, 0.900461152235364f, 0.902232771260093f, 0.903989293123443f, 0.905730688433339f, 0.907456928050819f, 0.909167983090522f, + 0.910863824921176f, 0.912544425166069f, 0.914209755703531f, 0.915859788667400f, 0.917494496447491f, 0.919113851690058f, 0.920717827298248f, 0.922306396432559f, + 0.923879532511287f, 0.925437209210971f, 0.926979400466833f, 0.928506080473216f, 0.930017223684012f, 0.931512804813095f, 0.932992798834739f, 0.934457180984039f, + 0.935905926757326f, 0.937339011912575f, 0.938756412469813f, 0.940158104711519f, 0.941544065183021f, 0.942914270692887f, 0.944268698313317f, 0.945607325380521f, + 0.946930129495106f, 0.948237088522441f, 0.949528180593037f, 0.950803384102905f, 0.952062677713924f, 0.953306040354194f, 0.954533451218389f, 0.955744889768105f, + 0.956940335732209f, 0.958119769107168f, 0.959283170157394f, 0.960430519415566f, 0.961561797682962f, 0.962676986029777f, 0.963776065795440f, 0.964859018588927f, + 0.965925826289068f, 0.966976471044852f, 0.968010935275723f, 0.969029201671875f, 0.970031253194544f, 0.971017073076290f, 0.971986644821279f, 0.972939952205560f, + 0.973876979277334f, 0.974797710357222f, 0.975702130038528f, 0.976590223187499f, 0.977461974943572f, 0.978317370719628f, 0.979156396202234f, 0.979979037351883f, + 0.980785280403230f, 0.981575111865320f, 0.982348518521816f, 0.983105487431216f, 0.983846005927077f, 0.984570061618220f, 0.985277642388941f, 0.985968736399212f, + 0.986643332084879f, 0.987301418157858f, 0.987942983606322f, 0.988568017694885f, 0.989176509964781f, 0.989768450234042f, 0.990343828597665f, 0.990902635427780f, + 0.991444861373810f, 0.991970497362629f, 0.992479534598710f, 0.992971964564277f, 0.993447779019444f, 0.993906970002356f, 0.994349529829318f, 0.994775451094928f, + 0.995184726672197f, 0.995577349712672f, 0.995953313646548f, 0.996312612182778f, 0.996655239309180f, 0.996981189292537f, 0.997290456678690f, 0.997583036292635f, + 0.997858923238603f, 0.998118112900149f, 0.998360600940223f, 0.998586383301244f, 0.998795456205172f, 0.998987816153567f, 0.999163459927649f, 0.999322384588350f, + 0.999464587476366f, 0.999590066212200f, 0.999698818696204f, 0.999790843108610f, 0.999866137909562f, 0.999924701839145f, 0.999966533917401f, 0.999991633444351f, + 1.000000000000000f +}; + +/*----------------------------------------------------------------------------------* + * TCX + *----------------------------------------------------------------------------------*/ + +const float gain_corr_fac[3] = {1.0208f,1.0103f,1.0052f}; /*pow(10,2^(-n-2)/28)*/ +const float gain_corr_inv_fac[3] = {0.9797f,0.9898f,0.9949f};/*pow(10,-2^(-n-2)/28)*/ + +const float inter4_2tcx2[4][4] = +{ + { 0.2325402f, 0.5349195f, 0.2325402f, 0.0000000f }, + { 0.1353017f, 0.5094465f, 0.3400065f, 0.0152453f }, + { 0.0608774f, 0.4391226f, 0.4391226f, 0.0608774f }, + { 0.0152453f, 0.3400065f, 0.5094465f, 0.1353017f } +}; + +const float inter6_2tcx2[6][4] = +{ + { 0.2241379f, 0.5517241f, 0.2241379f, 0.0000000f }, + { 0.1562044f, 0.5388595f, 0.2990011f, 0.0059349f }, + { 0.0991379f, 0.5018346f, 0.3750000f, 0.0240275f }, + { 0.0549361f, 0.4450639f, 0.4450639f, 0.0549361f }, + { 0.0240275f, 0.3750000f, 0.5018346f, 0.0991379f }, + { 0.0059349f, 0.2990011f, 0.5388595f, 0.1562044f } +}; +const float inter_core_12_8kHz_output_8kHz[] = +{ + 0.5349196f, 0.5094466f, 0.4391227f, 0.3400065f, + 0.2325402f, 0.1353016f, 0.0608773f, 0.0152453f, + 0.0000000f +}; +const float inter_core_12_8kHz_output_16kHz[] = +{ + 0.4279357f, 0.4147958f, 0.3774199f, 0.3214508f, + 0.2548195f, 0.1860321f, 0.1225801f, 0.0699165f, + 0.0312127f, 0.0078047f, 0.0000000f, 0.0000000f, + 0.0000000f +}; +const float inter_core_12_8kHz_output_32kHz[] = +{ + 0.2139679f, 0.2123089f, 0.2073979f, 0.1994284f, + 0.1887100f, 0.1756491f, 0.1607254f, 0.1444646f, + 0.1274097f, 0.1100939f, 0.0930161f, 0.0766219f, + 0.0612900f, 0.0473253f, 0.0349583f, 0.0243509f, + 0.0156063f, 0.0087817f, 0.0039024f, 0.0009753f, + 0.0000000f +}; +const float inter_core_12_8kHz_output_48kHz[] = +{ + 0.1426452f, 0.1421528f, 0.1406841f, 0.1382653f, + 0.1349386f, 0.1307618f, 0.1258066f, 0.1201564f, + 0.1139041f, 0.1071503f, 0.1000000f, 0.0925607f, + 0.0849398f, 0.0772420f, 0.0695677f, 0.0620107f, + 0.0546572f, 0.0475844f, 0.0408600f, 0.0345417f, + 0.0286774f, 0.0233055f, 0.0184558f, 0.0141503f, + 0.0104042f, 0.0072274f, 0.0046257f, 0.0026016f, + 0.0011560f, 0.0002890f, 0.0000000f, 0.0000000f, + 0.0000000f +}; +const float inter_core_16kHz_output_8kHz[] = +{ + 0.5517241f, 0.5388595f, 0.5018346f, 0.4450639f, 0.3750000f, 0.2990011f, + 0.2241379f, 0.1562044f, 0.0991379f, 0.0549361f, 0.0240275f, 0.0059349f, + 0.0000000f +}; +const float inter_core_16kHz_output_16kHz[] = +{ + 0.5517241f, 0.5388595f, 0.5018346f, 0.4450639f, 0.3750000f, 0.2990011f, + 0.2241379f, 0.1562044f, 0.0991379f, 0.0549361f, 0.0240275f, 0.0059349f, + 0.0000000f +}; +const float inter_core_16kHz_output_32kHz[] = +{ + 0.2758621f, 0.2742414f, 0.2694298f, 0.2615753f, 0.2509173f, 0.2377748f, + 0.2225320f, 0.2056203f, 0.1875000f, 0.1686403f, 0.1495006f, 0.1305132f, + 0.1120690f, 0.0945060f, 0.0781022f, 0.0630725f, 0.0495690f, 0.0376861f, + 0.0274680f, 0.0189188f, 0.0120137f, 0.0067120f, 0.0029675f, 0.0007394f, + 0.0000000f +}; +const float inter_core_16kHz_output_48kHz[] = +{ + 0.1839080f, 0.1834272f, 0.1819912f, 0.1796198f, 0.1763457f, 0.1722133f, + 0.1672782f, 0.1616061f, 0.1552712f, 0.1483546f, 0.1409433f, 0.1331275f, + 0.1250000f, 0.1166535f, 0.1081796f, 0.0996670f, 0.0912002f, 0.0828579f, + 0.0747126f, 0.0668293f, 0.0592649f, 0.0520681f, 0.0452794f, 0.0389306f, + 0.0330460f, 0.0276422f, 0.0227295f, 0.0183120f, 0.0143894f, 0.0109575f, + 0.0080092f, 0.0055360f, 0.0035286f, 0.0019783f, 0.0008771f, 0.0002189f, + 0.0000000f +}; +const float inter_core_25_6kHz_output_8kHz[] = +{ + 0.5349196f, 0.5094466f, 0.4391227f, 0.3400065f, + 0.2325402f, 0.1353016f, 0.0608773f, 0.0152453f, + 0.0000000f +}; +const float inter_core_25_6kHz_output_16kHz[] = +{ + 0.5349196f, 0.5094466f, 0.4391227f, 0.3400065f, + 0.2325402f, 0.1353016f, 0.0608773f, 0.0152453f, + 0.0000000f +}; +const float inter_core_25_6kHz_output_32kHz[] = +{ + 0.4279357f, 0.4147958f, 0.3774199f, 0.3214508f, + 0.2548195f, 0.1860321f, 0.1225801f, 0.0699165f, + 0.0312127f, 0.0078047f, 0.0000000f, 0.0000000f, + 0.0000000f +}; +const float inter_core_25_6kHz_output_48kHz[] = +{ + 0.2852965f, 0.2813740f, 0.2698819f, 0.2516166f, + 0.2278099f, 0.2000000f, 0.1698781f, 0.1391327f, + 0.1093111f, 0.0817166f, 0.0573517f, 0.0369093f, + 0.0208069f, 0.0092505f, 0.0023118f, 0.0000000f, + 0.0000000f +}; + +const TCX_LTP_FILTER tcxLtpFilters[12] = +{ + { inter_core_12_8kHz_output_8kHz, 2 }, + { inter_core_12_8kHz_output_16kHz, 3 }, + { inter_core_12_8kHz_output_32kHz, 5 }, + { inter_core_12_8kHz_output_48kHz, 8 }, + { inter_core_16kHz_output_8kHz, 2 }, + { inter_core_16kHz_output_16kHz, 2 }, + { inter_core_16kHz_output_32kHz, 4 }, + { inter_core_16kHz_output_48kHz, 6 }, + { inter_core_25_6kHz_output_8kHz, 2 }, + { inter_core_25_6kHz_output_16kHz, 2 }, + { inter_core_25_6kHz_output_32kHz, 3 }, + { inter_core_25_6kHz_output_48kHz, 4 }, +}; + + +const SCALE_TCX_SETUP scaleTcxTable[13] = +{ + { 0, 0, 8000, 0.67f }, + { 0, 8000, 9600, 0.70f }, + { 0, 9600, 13200, 0.76f }, + { 0, 13200, 16400, 0.86f }, + { 0, 16400, 24400, 0.90f }, + { 0, 24400, 64000, 0.96f }, + + { 1, 0, 8000, 1.f }, + { 1, 8000, 9600, 1.f }, + { 1, 9600, 13200, 1.f }, + { 1, 13200, 16400, 0.85f /*0.85f*/ }, + { 1, 16400, 24400, 0.88f /*0.90*/}, + { 1, 24400, 32000, 0.90f /*0.90*/}, + { 1, 32000, 32400, 0.95f /*0.91f*/}, +}; + + +/*----------------------------------------------------------------------------------* + * Arithmetic coder + *----------------------------------------------------------------------------------*/ + +const unsigned char ari_lookup_s17_LC[4096] = +{ + 0x01,0x04,0x29,0x13,0x0A,0x0D,0x05,0x10, + 0x10,0x0D,0x00,0x0D,0x2A,0x2A,0x22,0x25, + 0x25,0x28,0x2B,0x2E,0x31,0x34,0x34,0x0E, + 0x21,0x21,0x21,0x36,0x38,0x38,0x36,0x10, + 0x10,0x08,0x09,0x0B,0x0C,0x0E,0x0E,0x21, + 0x36,0x36,0x36,0x36,0x36,0x36,0x36,0x10, + 0x10,0x1A,0x09,0x1D,0x0C,0x20,0x20,0x21, + 0x36,0x36,0x36,0x36,0x36,0x0A,0x36,0x16, + 0x1A,0x1A,0x2D,0x0C,0x20,0x20,0x21,0x21, + 0x21,0x36,0x38,0x38,0x38,0x38,0x36,0x16, + 0x16,0x1A,0x3F,0x1F,0x20,0x21,0x24,0x06, + 0x36,0x36,0x36,0x38,0x00,0x0A,0x36,0x22, + 0x3E,0x3E,0x3F,0x30,0x20,0x21,0x06,0x06, + 0x06,0x38,0x36,0x36,0x36,0x26,0x36,0x1C, + 0x1C,0x3E,0x3F,0x02,0x20,0x21,0x06,0x36, + 0x36,0x38,0x0A,0x0A,0x0A,0x0A,0x05,0x16, + 0x16,0x16,0x16,0x16,0x16,0x16,0x16,0x16, + 0x16,0x16,0x16,0x16,0x16,0x16,0x16,0x16, + 0x16,0x3F,0x3F,0x0E,0x35,0x14,0x38,0x38, + 0x05,0x05,0x05,0x0D,0x13,0x13,0x1C,0x16, + 0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F, + 0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F, + 0x3F,0x3F,0x3F,0x20,0x35,0x14,0x27,0x38, + 0x38,0x0A,0x2A,0x2A,0x2A,0x16,0x05,0x10, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x3F,0x02,0x0E,0x02,0x14,0x13,0x0A, + 0x0D,0x0D,0x0D,0x13,0x00,0x00,0x16,0x19, + 0x19,0x3F,0x3F,0x02,0x02,0x14,0x38,0x36, + 0x0A,0x0A,0x0A,0x0D,0x0D,0x0D,0x1C,0x22, + 0x22,0x3F,0x3F,0x02,0x17,0x26,0x26,0x1C, + 0x1C,0x10,0x16,0x16,0x16,0x19,0x22,0x25, + 0x39,0x39,0x39,0x39,0x39,0x39,0x39,0x39, + 0x39,0x39,0x39,0x39,0x39,0x39,0x39,0x39, + 0x39,0x39,0x15,0x2C,0x2E,0x2E,0x2E,0x31, + 0x31,0x31,0x31,0x31,0x31,0x31,0x34,0x39, + 0x39,0x39,0x15,0x2C,0x2E,0x2E,0x0C,0x34, + 0x34,0x34,0x36,0x36,0x36,0x36,0x36,0x36, + 0x36,0x39,0x15,0x3C,0x2E,0x31,0x34,0x34, + 0x31,0x31,0x31,0x1F,0x1E,0x1E,0x1E,0x1E, + 0x1E,0x39,0x28,0x2C,0x2E,0x31,0x37,0x34, + 0x01,0x01,0x01,0x01,0x01,0x00,0x39,0x39, + 0x39,0x39,0x39,0x2C,0x2E,0x31,0x1E,0x34, + 0x34,0x35,0x01,0x01,0x01,0x01,0x01,0x01, + 0x01,0x39,0x39,0x3C,0x2E,0x03,0x07,0x34, + 0x34,0x0F,0x39,0x39,0x39,0x39,0x39,0x39, + 0x39,0x39,0x39,0x15,0x2B,0x31,0x1E,0x34, + 0x34,0x01,0x39,0x39,0x39,0x39,0x39,0x39, + 0x39,0x39,0x39,0x39,0x39,0x39,0x39,0x39, + 0x39,0x39,0x39,0x39,0x39,0x39,0x39,0x39, + 0x39,0x39,0x39,0x2C,0x39,0x2F,0x2E,0x2E, + 0x2E,0x2E,0x2E,0x2E,0x2E,0x2E,0x2E,0x2E, + 0x2E,0x2E,0x2E,0x2E,0x2E,0x2E,0x2E,0x2E, + 0x2E,0x2E,0x2E,0x2E,0x2E,0x2E,0x2E,0x2E, + 0x2E,0x39,0x1E,0x1E,0x1E,0x1E,0x1E,0x1E, + 0x1E,0x1E,0x1E,0x1E,0x1E,0x1E,0x1E,0x1E, + 0x1E,0x1E,0x1E,0x1E,0x1E,0x1E,0x1E,0x1E, + 0x1E,0x1E,0x1E,0x1E,0x1E,0x1E,0x1E,0x1E, + 0x1E,0x1E,0x1E,0x1E,0x1E,0x0F,0x2E,0x2E, + 0x2E,0x2E,0x2E,0x2E,0x2E,0x2E,0x2E,0x2E, + 0x2E,0x2E,0x39,0x15,0x39,0x39,0x39,0x39, + 0x39,0x39,0x39,0x39,0x39,0x39,0x39,0x39, + 0x39,0x39,0x39,0x39,0x39,0x39,0x39,0x39, + 0x39,0x39,0x39,0x39,0x39,0x39,0x39,0x39, + 0x19,0x1C,0x16,0x22,0x22,0x25,0x25,0x25, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x3E,0x3E,0x2F,0x3D,0x21,0x36,0x38,0x05, + 0x0D,0x0D,0x0D,0x10,0x16,0x16,0x16,0x25, + 0x2D,0x2D,0x37,0x3D,0x33,0x38,0x05,0x0D, + 0x0D,0x10,0x16,0x16,0x16,0x16,0x16,0x25, + 0x2F,0x2F,0x30,0x12,0x06,0x05,0x0A,0x0D, + 0x0D,0x10,0x16,0x16,0x16,0x22,0x22,0x25, + 0x1F,0x1F,0x32,0x3B,0x29,0x0A,0x0A,0x10, + 0x16,0x16,0x16,0x16,0x22,0x22,0x22,0x25, + 0x02,0x02,0x14,0x29,0x05,0x0D,0x2A,0x10, + 0x16,0x16,0x16,0x22,0x22,0x22,0x22,0x25, + 0x35,0x35,0x14,0x29,0x0A,0x2A,0x2A,0x10, + 0x16,0x16,0x16,0x22,0x22,0x22,0x22,0x25, + 0x17,0x17,0x26,0x05,0x0D,0x10,0x10,0x16, + 0x22,0x22,0x22,0x22,0x22,0x22,0x22,0x25, + 0x26,0x26,0x26,0x26,0x26,0x26,0x26,0x26, + 0x26,0x26,0x26,0x26,0x26,0x26,0x26,0x26, + 0x26,0x26,0x26,0x1C,0x0D,0x16,0x16,0x16, + 0x22,0x22,0x22,0x22,0x22,0x22,0x25,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x26,0x1C,0x1C,0x10,0x16,0x16,0x22, + 0x22,0x22,0x22,0x22,0x22,0x25,0x25,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x1C,0x1C,0x1C,0x16,0x16,0x16,0x22, + 0x22,0x22,0x22,0x25,0x25,0x25,0x25,0x00, + 0x00,0x26,0x1C,0x1C,0x16,0x16,0x16,0x22, + 0x22,0x22,0x22,0x25,0x25,0x25,0x25,0x00, + 0x16,0x16,0x16,0x16,0x16,0x22,0x22,0x22, + 0x25,0x25,0x25,0x25,0x25,0x25,0x25,0x00, + 0x15,0x15,0x15,0x15,0x15,0x15,0x15,0x15, + 0x15,0x15,0x15,0x15,0x15,0x15,0x15,0x15, + 0x15,0x15,0x3C,0x1E,0x0F,0x06,0x27,0x2A, + 0x2A,0x10,0x16,0x16,0x16,0x16,0x16,0x22, + 0x2C,0x2C,0x0B,0x37,0x23,0x27,0x13,0x2A, + 0x10,0x10,0x10,0x16,0x16,0x16,0x16,0x22, + 0x1B,0x1B,0x1D,0x0F,0x24,0x13,0x13,0x2A, + 0x00,0x10,0x16,0x16,0x16,0x16,0x16,0x22, + 0x1F,0x1F,0x03,0x24,0x07,0x0A,0x0A,0x10, + 0x16,0x16,0x16,0x16,0x16,0x16,0x16,0x22, + 0x22,0x35,0x06,0x27,0x13,0x2A,0x2A,0x10, + 0x16,0x16,0x16,0x16,0x16,0x22,0x22,0x22, + 0x22,0x06,0x27,0x27,0x13,0x2A,0x2A,0x10, + 0x16,0x16,0x16,0x16,0x16,0x16,0x22,0x22, + 0x22,0x05,0x0A,0x2A,0x2A,0x10,0x10,0x16, + 0x16,0x16,0x16,0x16,0x16,0x22,0x22,0x22, + 0x22,0x22,0x22,0x22,0x22,0x22,0x22,0x22, + 0x22,0x22,0x22,0x22,0x22,0x22,0x22,0x22, + 0x22,0x0D,0x2A,0x10,0x10,0x10,0x10,0x16, + 0x16,0x16,0x16,0x16,0x16,0x22,0x22,0x25, + 0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10, + 0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10, + 0x10,0x10,0x10,0x10,0x10,0x16,0x16,0x16, + 0x16,0x16,0x16,0x22,0x22,0x22,0x22,0x25, + 0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10, + 0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10, + 0x10,0x10,0x10,0x10,0x16,0x16,0x16,0x16, + 0x16,0x22,0x22,0x22,0x22,0x22,0x22,0x25, + 0x0D,0x0D,0x10,0x10,0x10,0x16,0x16,0x16, + 0x16,0x22,0x22,0x22,0x22,0x22,0x22,0x25, + 0x0D,0x0D,0x0D,0x0D,0x0D,0x10,0x10,0x16, + 0x16,0x16,0x16,0x22,0x22,0x22,0x22,0x25, + 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x11, + 0x11,0x11,0x11,0x3A,0x11,0x11,0x11,0x18, + 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, + 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x11, + 0x11,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, + 0x3A,0x3A,0x3A,0x3A,0x3A,0x11,0x3A,0x11, + 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, + 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x11, + 0x11,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, + 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x11, + 0x11,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, + 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x18, + 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, + 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x11, + 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, + 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x18, + 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, + 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, + 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, + 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x11, + 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, + 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, + 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, + 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x11,0x18, + 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, + 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, + 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, + 0x3A,0x3A,0x3A,0x11,0x3A,0x3A,0x3A,0x11, + 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, + 0x3A,0x3A,0x3A,0x3A,0x11,0x11,0x11,0x18, + 0x00,0x11,0x3A,0x11,0x11,0x11,0x11,0x11, + 0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x18, + 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, + 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, + 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, + 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, + 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, + 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, + 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, + 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, + 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, + 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, + 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, + 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, + 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, + 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, + 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, + 0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18, + 0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18, + 0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18, + 0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18, + 0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18, + 0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18, + 0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18, + 0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18, + 0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18, + 0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18, + 0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18, + 0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18, + 0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18, + 0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18, + 0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18, + 0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18, + 0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18, + 0x18,0x11,0x11,0x11,0x18,0x18,0x18,0x18, + 0x18,0x25,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x11, + 0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x18, + 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x11, + 0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x18, + 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x11, + 0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x18, + 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x11, + 0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x18, + 0x3A,0x3A,0x3A,0x3A,0x3A,0x11,0x3A,0x11, + 0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x18, + 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x11, + 0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x18, + 0x3A,0x3A,0x3A,0x3A,0x3A,0x11,0x11,0x11, + 0x11,0x11,0x11,0x11,0x11,0x11,0x18,0x18, + 0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18, + 0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18, + 0x18,0x3A,0x11,0x11,0x11,0x11,0x11,0x11, + 0x11,0x11,0x11,0x11,0x11,0x11,0x18,0x18, + 0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11, + 0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11, + 0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11, + 0x11,0x11,0x11,0x11,0x11,0x11,0x18,0x18, + 0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11, + 0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11, + 0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11, + 0x11,0x11,0x11,0x11,0x18,0x18,0x18,0x18, + 0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11, + 0x11,0x11,0x18,0x18,0x18,0x18,0x18,0x18, + 0x18,0x18,0x11,0x18,0x18,0x18,0x18,0x18, + 0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x00, + 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, + 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, + 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, + 0x3A,0x3A,0x3A,0x3A,0x11,0x11,0x11,0x11, + 0x11,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, + 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x11,0x11, + 0x11,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, + 0x3A,0x3A,0x3A,0x3A,0x11,0x11,0x11,0x11, + 0x11,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, + 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x11,0x11, + 0x11,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, + 0x3A,0x3A,0x3A,0x3A,0x11,0x11,0x11,0x11, + 0x11,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, + 0x3A,0x3A,0x3A,0x3A,0x3A,0x11,0x11,0x11, + 0x11,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, + 0x3A,0x3A,0x3A,0x3A,0x11,0x11,0x11,0x11, + 0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11, + 0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11, + 0x11,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, + 0x3A,0x3A,0x3A,0x3A,0x11,0x11,0x11,0x18, + 0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18, + 0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18, + 0x18,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, + 0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x18, + 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, + 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, + 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, + 0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x18, + 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x11, + 0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x18, + 0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11, + 0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x18, + 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, + 0x3A,0x11,0x11,0x11,0x11,0x11,0x11,0x11, + 0x11,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, + 0x3A,0x3A,0x3A,0x3A,0x3A,0x11,0x3A,0x11, + 0x11,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, + 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, + 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, + 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, + 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, + 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, + 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, + 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, + 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, + 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x11, + 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, + 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x11, + 0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11, + 0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11, + 0x11,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, + 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x11, + 0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11, + 0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11, + 0x11,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, + 0x3A,0x3A,0x3A,0x3A,0x3A,0x11,0x3A,0x3A, + 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, + 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, + 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, + 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x11, + 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, + 0x3A,0x3A,0x3A,0x3A,0x11,0x11,0x3A,0x11, + 0x11,0x3A,0x3A,0x3A,0x11,0x3A,0x3A,0x3A, + 0x3A,0x3A,0x11,0x11,0x11,0x3A,0x11,0x11, + 0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11, + 0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11, + 0x11,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, + 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, + 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, + 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, + 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, + 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, + 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, + 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, + 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, + 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, + 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, + 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, + 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, + 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, + 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, + 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, + 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, + 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, + 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, + 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, + 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, + 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, + 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, + 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, + 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, + 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, + 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, + 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, + 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, + 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, + 0x18,0x3A,0x3A,0x11,0x11,0x11,0x18,0x18, + 0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x00, + 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, + 0x3A,0x3A,0x11,0x11,0x11,0x3A,0x11,0x11, + 0x11,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, + 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x11,0x11, + 0x11,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, + 0x3A,0x3A,0x3A,0x3A,0x11,0x11,0x11,0x11, + 0x11,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, + 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x11,0x11, + 0x11,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, + 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x11,0x11, + 0x11,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, + 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x11,0x11, + 0x11,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, + 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x11,0x11, + 0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11, + 0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11, + 0x11,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, + 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x11,0x18, + 0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18, + 0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18, + 0x18,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, + 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x11,0x18, + 0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18, + 0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18, + 0x18,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, + 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x11,0x18, + 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, + 0x3A,0x3A,0x11,0x11,0x11,0x11,0x11,0x18, + 0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11, + 0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x18, + 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, + 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, + 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, + 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, + 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, + 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, + 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, + 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, + 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, + 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, + 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, + 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, + 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, + 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, + 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, + 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, + 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, + 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, + 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, + 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, + 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, + 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, + 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, + 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, + 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, + 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, + 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, + 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, + 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, + 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x11, + 0x11,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, + 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x11, + 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, + 0x3A,0x3A,0x3A,0x11,0x3A,0x3A,0x3A,0x3A, + 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, + 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, + 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, + 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, + 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, + 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, + 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, + 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, + 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, + 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, + 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, + 0x3A,0x11,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, + 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, + 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, + 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, + 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, + 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, + 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, + 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, + 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, + 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, + 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, + 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, + 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, + 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, + 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x2A, + 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, + 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, + 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, + 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, + 0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11, + 0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11, + 0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11, + 0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11, + 0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11, + 0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11, + 0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11, + 0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11, + 0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11, + 0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11, + 0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11, + 0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11, + 0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11, + 0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11, + 0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11, + 0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11, + 0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11, + 0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11, + 0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11, + 0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11, + 0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11, + 0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11, + 0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11, + 0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11, + 0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11, + 0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11, + 0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11, + 0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11, + 0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11, + 0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11, + 0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11, + 0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11, + 0x11,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x11, + 0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x18, + 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, + 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x11, + 0x11,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, + 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x11, + 0x11,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, + 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x11, + 0x11,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, + 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x11, + 0x11,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, + 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x11, + 0x11,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, + 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x11, + 0x11,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, + 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x11, + 0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11, + 0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11, + 0x11,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, + 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x11, + 0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11, + 0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11, + 0x11,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, + 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x11, + 0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11, + 0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11, + 0x11,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, + 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x11, + 0x11,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, + 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x11, + 0x11,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, + 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x11, + 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, + 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, + 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, + 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, + 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, + 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, + 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, + 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, + 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, + 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, + 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, + 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, + 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, + 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, + 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, + 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, + 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, + 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, + 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, + 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, + 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, + 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, + 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, + 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, + 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, + 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, + 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, + 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, + 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, + 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, + 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, + 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A +}; + +const unsigned short ari_pk_s17_LC_ext[64][18] = +{ + { + 16384, 16368,16337,16231,16143,16115,16059,15916,15793,15710,15586,15472,15367,15302,15201,15107,15020, + 0 + }, + { + 16384, 8983, 8540, 8498, 8485, 4319, 3666, 3594, 3579, 2285, 1908, 1851, 1835, 1326, 1120, 1085, 1074, + 0 + }, + { + 16384, 12022,10039, 9520, 9346, 7347, 5335, 4648, 4382, 3815, 3083, 2728, 2562, 2363, 2050, 1869, 1777, + 0 + }, + { + 16384, 13429,11201,10562,10371, 8231, 5713, 4770, 4441, 3798, 2844, 2359, 2152, 1947, 1614, 1406, 1304, + 0 + }, + { + 16384, 13229,11403,10769,10529, 8415, 6431, 5645, 5311, 4448, 3547, 3176, 3001, 2617, 2181, 1984, 1886, + 0 + }, + { + 16384, 15168,13754,13120,12826,11553, 9705, 8723, 8227, 7675, 6762, 6180, 5842, 5585, 5141, 4816, 4607, + 0 + }, + { + 16384, 14625,12743,12034,11772,10059, 7706, 6652, 6223, 5594, 4594, 4023, 3742, 3501, 3089, 2818, 2664, + 0 + }, + { + 16384, 15275,13679,12951,12652,11158, 8852, 7652, 7121, 6406, 5242, 4542, 4196, 3894, 3398, 3063, 2864, + 0 + }, + { + 16384, 4860, 3338, 3214, 3193, 1428, 676, 571, 547, 356, 222, 189, 180, 139, 102, 89, 84, + 0 + }, + { + 16384, 8357, 5798, 5475, 5410, 3093, 1523, 1227, 1152, 849, 560, 470, 441, 370, 294, 261, 248, + 0 + }, + { + 16384, 15550,14350,13710,13387,12297,10541, 9493, 8929, 8354, 7371, 6696, 6299, 6008, 5491, 5107, 4856, + 0 + }, + { + 16384, 10346, 7298, 6933, 6865, 4052, 1863, 1471, 1381, 1055, 673, 536, 491, 429, 339, 293, 273, + 0 + }, + { + 16384, 11652, 8699, 8030, 7839, 5667, 3460, 2766, 2532, 2093, 1542, 1301, 1203, 1070, 893, 802, 759, + 0 + }, + { + 16384, 15639,14601,14037,13729,12847,11421,10520, 9978, 9521, 8720, 8136, 7750, 7493, 7033, 6676, 6426, + 0 + }, + { + 16384, 12427, 9590, 8715, 8386, 6641, 4708, 3886, 3515, 3071, 2490, 2198, 2052, 1886, 1670, 1549, 1478, + 0 + }, + { + 16384, 13605,10996,10363,10183, 7802, 5032, 4124, 3840, 3267, 2403, 1976, 1804, 1633, 1345, 1171, 1086, + 0 + }, + { + 16384, 15936,15224,14759,14464,13808,12678,11866,11331,10910,10150, 9549, 9122, 8853, 8352, 7938, 7626, + 0 + }, + { + 16384, 16383,16382,14829,14138,14137,14136,12895,12272,10935, 9788, 9082, 8674, 8073, 7508, 7118, 6867, + 0 + }, + { + 16384, 13888,11474,10840,10662, 8335, 5585, 4695, 4411, 3801, 2917, 2506, 2337, 2150, 1847, 1672, 1581, + 0 + }, + { + 16384, 15463,14162,13504,13196,11977,10063, 8978, 8429, 7811, 6768, 6088, 5705, 5406, 4882, 4504, 4266, + 0 + }, + { + 16384, 13764,11941,11367,11151, 9312, 7171, 6301, 5943, 5335, 4430, 3942, 3708, 3466, 3074, 2819, 2679, + 0 + }, + { + 16384, 5179, 3300, 3206, 3197, 1220, 374, 303, 293, 171, 81, 63, 59, 44, 29, 24, 22, + 0 + }, + { + 16384, 16026,15468,15096,14842,14329,13447,12790,12322,11985,11367,10860,10477,10248, 9811, 9443, 9148, + 0 + }, + { + 16384, 12809,11291,10848,10649, 8976, 7199, 6506, 6196, 5657, 4887, 4451, 4219, 3974, 3590, 3365, 3218, + 0 + }, + { + 16384, 16383,16382,15744,15348,15347,15346,14714,14288,13688,13097,12652,12328,11967,11584,11278,11045, + 0 + }, + { + 16384, 15415,14987,14866,14806,13751,13046,12818,12709,12187,11720,11527,11427,11096,10759,10601,10510, + 0 + }, + { + 16384, 5926, 4280, 4090, 4053, 2138, 1120, 947, 903, 632, 413, 353, 334, 264, 198, 174, 166, + 0 + }, + { + 16384, 9206, 6640, 6345, 6291, 3683, 1772, 1423, 1342, 1024, 652, 515, 467, 406, 314, 267, 245, + 0 + }, + { + 16384, 15086,13966,13505,13271,12238,10875,10157, 9763, 9331, 8629, 8155, 7845, 7608, 7198, 6892, 6670, + 0 + }, + { + 16384, 11427, 8599, 8132, 8027, 5406, 3012, 2429, 2270, 1823, 1244, 1006, 920, 814, 654, 564, 524, + 0 + }, + { + 16384, 11561, 8220, 7814, 7737, 4780, 2215, 1731, 1621, 1279, 830, 657, 599, 532, 424, 366, 339, + 0 + }, + { + 16384, 11649, 9374, 8867, 8724, 6398, 4154, 3470, 3253, 2718, 2010, 1695, 1570, 1412, 1172, 1042, 980, + 0 + }, + { + 16384, 13021,10503, 9726, 9443, 7520, 5271, 4369, 4016, 3495, 2741, 2365, 2181, 1990, 1719, 1561, 1478, + 0 + }, + { + 16384, 13815,11388,10605,10316, 8467, 6133, 5175, 4782, 4255, 3466, 3063, 2864, 2688, 2408, 2229, 2125, + 0 + }, + { + 16384, 16175,15807,15536,15338,15006,14402,13919,13549,13312,12871,12491,12182,12010,11681,11390,11143, + 0 + }, + { + 16384, 14310,12047,11336,11110, 9065, 6381, 5318, 4938, 4279, 3272, 2732, 2499, 2284, 1920, 1693, 1574, + 0 + }, + { + 16384, 14765,12824,12096,11834,10003, 7429, 6282, 5841, 5145, 4022, 3402, 3123, 2868, 2426, 2150, 2003, + 0 + }, + { + 16384, 16295,16127,15943,15802,15650,15360,15059,14816,14668,14401,14162,13954,13839,13634,13443,13275, + 0 + }, + { + 16384, 14182,12821,12340,12120,10698, 9040, 8284, 7908, 7378, 6549, 6053, 5772, 5520, 5080, 4785, 4597, + 0 + }, + { + 16384, 15164,13583,12892,12600,11161, 8997, 7888, 7386, 6744, 5673, 5015, 4673, 4391, 3898, 3555, 3349, + 0 + }, + { + 16384, 3758, 2571, 2481, 2467, 988, 478, 412, 397, 245, 154, 133, 127, 95, 69, 61, 58, + 0 + }, + { + 16384, 14805,13193,12553,12285,10706, 8596, 7623, 7178, 6542, 5563, 4996, 4703, 4426, 3967, 3662, 3482, + 0 + }, + { + 16384, 15787,14870,14320,14005,13147,11705,10747,10171, 9651, 8735, 8068, 7629, 7332, 6785, 6361, 6061, + 0 + }, + { + 16384, 7111, 4622, 4304, 4233, 2346, 1174, 938, 870, 659, 455, 389, 365, 316, 260, 236, 226, + 0 + }, + { + 16384, 7146, 4703, 4532, 4512, 2078, 740, 583, 556, 371, 201, 153, 141, 118, 87, 72, 66, + 0 + }, + { + 16384, 9593, 7184, 6853, 6790, 4144, 2206, 1832, 1745, 1320, 878, 741, 697, 599, 476, 424, 401, + 0 + }, + { + 16384, 9209, 5969, 5479, 5351, 3346, 1763, 1382, 1261, 1017, 733, 622, 578, 520, 446, 410, 392, + 0 + }, + { + 16384, 11324, 8681, 8252, 8159, 5450, 3114, 2606, 2473, 1987, 1412, 1211, 1142, 1017, 847, 765, 730, + 0 + }, + { + 16384, 12663,10073, 9527, 9392, 6827, 4204, 3489, 3286, 2713, 1966, 1666, 1554, 1400, 1172, 1051, 994, + 0 + }, + { + 16384, 10413, 7096, 6340, 6115, 4393, 2704, 2156, 1947, 1634, 1254, 1091, 1010, 925, 805, 742, 707, + 0 + }, + { + 16384, 13337,11073,10477,10306, 8045, 5534, 4705, 4438, 3804, 2942, 2530, 2360, 2164, 1850, 1668, 1574, + 0 + }, + { + 16384, 14323,12104,11391,11156, 9183, 6649, 5649, 5287, 4676, 3778, 3302, 3089, 2886, 2548, 2341, 2223, + 0 + }, + { + 16384, 11646, 8435, 7504, 7150, 5603, 3882, 3170, 2853, 2487, 2029, 1791, 1666, 1549, 1386, 1288, 1231, + 0 + }, + { + 16384, 13147,11339,10752,10524, 8775, 6682, 5776, 5398, 4813, 3908, 3406, 3154, 2933, 2554, 2310, 2176, + 0 + }, + { + 16384, 14551,12495,11707,11356, 9962, 8005, 7006, 6500, 6034, 5298, 4839, 4575, 4381, 4057, 3825, 3673, + 0 + }, + { + 16384, 12395, 9526, 9032, 8925, 6130, 3448, 2813, 2649, 2144, 1489, 1231, 1142, 1020, 836, 738, 694, + 0 + }, + { + 16384, 14921,13187,12475,12164,10758, 8775, 7752, 7257, 6727, 5864, 5306, 5004, 4777, 4393, 4119, 3942, + 0 + }, + { + 16384, 2151, 1301, 1276, 1274, 315, 84, 70, 68, 32, 14, 11, 10, 7, 4, 3, 2, + 0 + }, + { + 16384, 16383,16382,13774,13091,13090,13089,11287,10713, 7917, 6052, 5265, 4947, 4161, 3534, 3199, 3039, + 0 + }, + { + 16384, 14374,12331,11688,11474, 9505, 6993, 5998, 5634, 4991, 4008, 3498, 3265, 3036, 2658, 2417, 2285, + 0 + }, + { + 16384, 8798, 5867, 5626, 5593, 2841, 1038, 807, 765, 538, 302, 234, 215, 182, 139, 119, 111, + 0 + }, + { + 16384, 13325,10612,10015, 9860, 7343, 4583, 3802, 3571, 3023, 2269, 1945, 1817, 1670, 1440, 1309, 1243, + 0 + }, + { + 16384, 7741, 5790, 5571, 5528, 3110, 1698, 1464, 1409, 1034, 704, 613, 585, 487, 381, 342, 327, + 0 + }, + { + 16384, 9664, 7506, 7059, 6917, 4820, 3136, 2640, 2455, 2000, 1504, 1297, 1217, 1073, 896, 815, 777, + 0 + } +}; + +const int NumRatioBits[2][17] = +{ + /* NB */ + { + 5, 4, 4, 4, 4, 4, 4, 3, 3, 3, 3, 2, 2, 2 + , 2, 2, 2 + }, + + /* WB */ + { + 5, 5, 5, 5, 5, 5, 4, 4, 4, 4, 4, 4, 4, 4 + , 2, 2, 2 + } +}; + +const float Ratios_WB_2[32] = + /* 2 */ { 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 24, 26, 28, 30, 32, 34, 36, 38, 40, 60, 64, 72 }; + +const float Ratios_WB_3[32] = + /* 3 */ { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30, 32, 34, 36, 38, 40, 44, 48, 54, 60, 68, 78, 80 }; + +const float Ratios_WB_4[32] = + /* 4 */ { 1.5f, 2, 2.5f, 3, 4, 5, 6, 7, 8, 9, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30, 32, 34, 36, 38, 40, 42, 44, 48, 52, 54, 68 }; + +const float Ratios_WB_5[32] = + /* 5 */ { 1, 1.5f, 2, 2.5f, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 18, 20, 22, 24, 26, 28, 30, 32, 34, 36, 40, 44, 48, 54 }; + +const float Ratios_WB_6[32] = + /* 6 */ { 1, 1.5f, 2, 2.5f, 3, 3.5f, 4, 4.5f, 5, 5.5f, 6, 6.5f, 7, 7.5f, 8, 9, 10, 11, 12, 13, 14, 15, 16, 18, 20, 22, 24, 26, 28, 34, 40, 41 }; + +const float Ratios_WB_7[32] = + /* 7 */ { 1, 1.5f, 2, 2.5f, 3, 3.5f, 4, 4.5f, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22.5f, 24, 25, 27, 28, 30, 35 }; + +const float Ratios_WB_8[16] = + /* 8 */ { 0.5f, 1, 1.5f, 2, 2.5f, 3, 3.5f, 4, 4.5f, 5, 5.5f, 6, 7, 8, 9, 10 }; + +const float Ratios_WB_9[16] = + /* 9 */ { 1, 2, 2.5f, 3, 4, 5, 6, 7, 8, 9, 10, 12, 15, 16, 18, 27 }; + +const float Ratios_WB_10[16] = + /* 10 */ { 1, 1.5f, 2, 2.5f, 3, 3.5f, 4, 5, 6, 8, 10, 15, 18, 22, 24, 26 }; + +const float Ratios_WB_11[16] = + /* 11 */ { 1, 1.5f, 2, 2.5f, 3, 3.5f, 4, 5, 6, 8, 10, 12, 13, 14, 18, 21 }; + +const float Ratios_WB_12[16] = + /* 12 */ { 0.5f, 1, 1.5f, 2, 2.5f, 3, 4, 5, 6, 8, 9, 11, 12, 13.5f, 16, 20 }; + +const float Ratios_WB_13[16] = + /* 13 */ { 0.5f, 1, 1.5f, 2, 2.5f, 3, 4, 5, 6, 7, 8, 10, 11, 12, 14, 20 }; + +const float Ratios_WB_14[16] = + /* 14 */ { 0.5f, 1, 1.5f, 2, 2.5f, 3, 4, 4.5f, 6, 7.5f, 9, 10, 12, 14, 15, 18 }; + +const float Ratios_WB_15[16] = + /* 15 */ { 0.5f, 1, 1.25f, 1.5f, 1.75f, 2, 2.5f, 3, 3.5f, 4, 4.5f, 5, 6, 8, 9, 14 }; + +const float Ratios_WB_16[4] = + /* 16 */ { 0.5f, 1, 2, 4 }; + +const float Ratios_WB_17[4] = + /* 17 */ { 1, 1.5f, 2, 4 }; + +const float Ratios_WB_18[4] = + /* 18 */ { 1, 2, 3, 4 }; + +const float Ratios_NB_2[32] = + /* 2 */ { 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 30, 32, 34, 36, 38, 40 }; + +const float Ratios_NB_3[16] = + /* 3 */ { 0.5f, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 12, 16, 20, 24, 30 }; + +const float Ratios_NB_4[16] = + /* 4 */ { 2, 3, 4, 5, 6, 7, 8, 9, 10, 12, 14, 16, 18, 20, 24, 30 }; + +const float Ratios_NB_5[16] = + /* 5 */ { 2, 3, 4, 5, 6, 7, 8, 9, 10, 12, 14, 16, 18, 20, 24, 30 }; + +const float Ratios_NB_6[16] = + /* 6 */ { 2, 2.5f, 3, 3.5f, 4, 5, 6, 7, 8, 9, 10, 12, 14, 16, 18, 20 }; + +const float Ratios_NB_7[16] = + /* 7 */ { 1, 2, 2.5f, 3, 4, 5, 6, 7, 8, 9, 10, 12, 14, 16, 18, 20 }; + +const float Ratios_NB_8[16] = + /* 8 */ { 1, 1.5f, 2, 2.5f, 3, 3.5f, 4, 4.5f, 5, 6, 7, 8, 9, 10, 12, 16 }; + +const float Ratios_NB_9[8] = + /* 9 */ { 1, 2, 3, 4, 5, 6, 8, 10 }; + +const float Ratios_NB_10[8] = + /* 10 */ { 1, 2, 3, 4, 5, 6, 8, 10 }; + +const float Ratios_NB_11[8] = + /* 11 */ { 1, 1.5f, 2, 3, 4, 5, 6, 8 }; + +const float Ratios_NB_12[8] = + /* 12 */ { 1, 2, 2.5f, 3, 4, 5, 6, 8 }; + +const float Ratios_NB_13[4] = + /* 13 */ { 1, 2, 3, 4 }; + +const float Ratios_NB_14[4] = + /* 14 */ { 1, 2, 4, 6 }; + +const float Ratios_NB_15[4] = + /* 15 */ { 1, 2, 3, 4 }; + +const float Ratios_NB_16[4] = + /* 16 */ { 1, 1.5f, 2, 4 }; + +const float Ratios_NB_17[4] = + /* 17 */ { 1, 1.5f, 2, 3 }; + +const float Ratios_NB_18[4] = + /* 18 */ { 0.5f, 1, 2, 3 }; + +const float *const Ratios[2][17] = +{ + /* NB */ + { + Ratios_NB_2, + Ratios_NB_3, + Ratios_NB_4, + Ratios_NB_5, + Ratios_NB_6, + Ratios_NB_7, + Ratios_NB_8, + Ratios_NB_9, + Ratios_NB_10, + Ratios_NB_11, + Ratios_NB_12, + Ratios_NB_13, + Ratios_NB_14, + Ratios_NB_15, + Ratios_NB_16, + Ratios_NB_17, + Ratios_NB_18 + }, + + /* WB */ + { + Ratios_WB_2, + Ratios_WB_3, + Ratios_WB_4, + Ratios_WB_5, + Ratios_WB_6, + Ratios_WB_7, + Ratios_WB_8, + Ratios_WB_9, + Ratios_WB_10, + Ratios_WB_11, + Ratios_WB_12, + Ratios_WB_13, + Ratios_WB_14, + Ratios_WB_15, + Ratios_WB_16, + Ratios_WB_17, + Ratios_WB_18 + } +}; + +#define QGC(x) FL2WORD16_SCALE(x, 4) +const Word16 qGains[2][1 << kTcxHmNumGainBits] = +{ + /* GC */ { QGC(0.75f) }, + /* VC */ { QGC(0.6f), QGC(1.4f), QGC(4.5f), QGC(10.0f) } +}; + +/*----------------------------------------------------------------------------------* + * TNS + *----------------------------------------------------------------------------------*/ + +struct TnsParameters const tnsParametersIGF32kHz_LowBR[1] = +{ + { 600, 3, 1.85f, 0.075f } +}; + +struct TnsParameters const tnsParameters32kHz[2] = +{ + { 4500, 3, 1.35f, 0.0300f }, + { 600, 1, 1.75f, 0.0625f } +}; + +struct TnsParameters const tnsParameters32kHz_grouped[2] = +{ + { 8400, 3, 1.375f, 0.03125f }, + { 800, 3, 1.375f, 0.03125f } +}; + +struct TnsParameters const tnsParameters16kHz[1] = +{ + { 600, 3, 1.5f, 0.05f } +}; + + +struct TnsParameters const tnsParameters16kHz_grouped[2] = +{ + { 4400, 3, 1.5f, 0.05f }, + { 800, 3, 1.5f, 0.05f } +}; + +struct TnsParameters const tnsParameters48kHz_grouped[2] = +{ + { 10400, 3, 1.375f, 0.03125f }, + { 800, 3, 1.375f, 0.03125f } +}; + +float const tnsAcfWindow[TNS_MAX_FILTER_ORDER] = +{ + 0.997803f, 0.991211f, 0.980225f, 0.964844f, 0.945068f, 0.920898f, 0.892334f, 0.859375f +}; + +/* Definition of the mapping between TNS parameters and a bitstream */ +/* Helper structures for hufmann table coding */ + +const Coding codesTnsCoeff0TCX20[] = +{ + { -8+INDEX_SHIFT, 609, 11 }, /* 01001100001 */ + { -7+INDEX_SHIFT, 305, 10 }, /* 0100110001 */ + { -6+INDEX_SHIFT, 77, 8 }, /* 01001101 */ + { -5+INDEX_SHIFT, 39, 7 }, /* 0100111 */ + { -4+INDEX_SHIFT, 8, 5 }, /* 01000 */ + { -3+INDEX_SHIFT, 21, 5 }, /* 10101 */ + { -2+INDEX_SHIFT, 11, 4 }, /* 1011 */ + { -1+INDEX_SHIFT, 3, 3 }, /* 011 */ + { 0+INDEX_SHIFT, 3, 2 }, /* 11 */ + { 1+INDEX_SHIFT, 0, 2 }, /* 00 */ + { 2+INDEX_SHIFT, 4, 3 }, /* 100 */ + { 3+INDEX_SHIFT, 5, 4 }, /* 0101 */ + { 4+INDEX_SHIFT, 20, 5 }, /* 10100 */ + { 5+INDEX_SHIFT, 18, 6 }, /* 010010 */ + { 6+INDEX_SHIFT, 153, 9 }, /* 010011001 */ + { 7+INDEX_SHIFT, 608, 11 } /* 01001100000 */ +}; + +const Coding codesTnsCoeff0TCX10[] = +{ + { -8+INDEX_SHIFT, 441, 9 }, /* 110111001 */ + { -7+INDEX_SHIFT, 111, 7 }, /* 1101111 */ + { -6+INDEX_SHIFT, 8, 4 }, /* 1000 */ + { -5+INDEX_SHIFT, 9, 4 }, /* 1001 */ + { -4+INDEX_SHIFT, 14, 4 }, /* 1110 */ + { -3+INDEX_SHIFT, 15, 4 }, /* 1111 */ + { -2+INDEX_SHIFT, 3, 3 }, /* 011 */ + { -1+INDEX_SHIFT, 5, 3 }, /* 101 */ + { 0+INDEX_SHIFT, 0, 2 }, /* 00 */ + { 1+INDEX_SHIFT, 2, 3 }, /* 010 */ + { 2+INDEX_SHIFT, 12, 4 }, /* 1100 */ + { 3+INDEX_SHIFT, 26, 5 }, /* 11010 */ + { 4+INDEX_SHIFT, 54, 6 }, /* 110110 */ + { 5+INDEX_SHIFT, 221, 8 }, /* 11011101 */ + { 6+INDEX_SHIFT, 881, 10 }, /* 1101110001 */ + { 7+INDEX_SHIFT, 880, 10 } /* 1101110000 */ +}; + +const Coding codesTnsCoeff1TCX20[] = +{ + { -8+INDEX_SHIFT, 30018, 15 }, /* 111010101000010 */ + { -7+INDEX_SHIFT, 30019, 15 }, /* 111010101000011 */ + { -6+INDEX_SHIFT, 7505, 13 }, /* 1110101010001 */ + { -5+INDEX_SHIFT, 3753, 12 }, /* 111010101001 */ + { -4+INDEX_SHIFT, 939, 10 }, /* 1110101011 */ + { -3+INDEX_SHIFT, 235, 8 }, /* 11101011 */ + { -2+INDEX_SHIFT, 28, 5 }, /* 11100 */ + { -1+INDEX_SHIFT, 6, 3 }, /* 110 */ + { 0+INDEX_SHIFT, 0, 1 }, /* 0 */ + { 1+INDEX_SHIFT, 2, 2 }, /* 10 */ + { 2+INDEX_SHIFT, 15, 4 }, /* 1111 */ + { 3+INDEX_SHIFT, 59, 6 }, /* 111011 */ + { 4+INDEX_SHIFT, 116, 7 }, /* 1110100 */ + { 5+INDEX_SHIFT, 468, 9 }, /* 111010100 */ + { 6+INDEX_SHIFT, 1877, 11 }, /* 11101010101 */ + { 7+INDEX_SHIFT, 15008, 14 } /* 11101010100000 */ +}; + +const Coding codesTnsCoeff1TCX10[] = +{ + { -8+INDEX_SHIFT, 2818, 12 }, /* 101100000010 */ + { -7+INDEX_SHIFT, 2819, 12 }, /* 101100000011 */ + { -6+INDEX_SHIFT, 705, 10 }, /* 1011000001 */ + { -5+INDEX_SHIFT, 353, 9 }, /* 101100001 */ + { -4+INDEX_SHIFT, 177, 8 }, /* 10110001 */ + { -3+INDEX_SHIFT, 45, 6 }, /* 101101 */ + { -2+INDEX_SHIFT, 10, 4 }, /* 1010 */ + { -1+INDEX_SHIFT, 3, 3 }, /* 011 */ + { 0+INDEX_SHIFT, 6, 3 }, /* 110 */ + { 1+INDEX_SHIFT, 0, 2 }, /* 00 */ + { 2+INDEX_SHIFT, 7, 3 }, /* 111 */ + { 3+INDEX_SHIFT, 4, 3 }, /* 100 */ + { 4+INDEX_SHIFT, 2, 3 }, /* 010 */ + { 5+INDEX_SHIFT, 23, 5 }, /* 10111 */ + { 6+INDEX_SHIFT, 89, 7 }, /* 1011001 */ + { 7+INDEX_SHIFT, 1408, 11 } /* 10110000000 */ +}; + +const Coding codesTnsCoeff2TCX20[] = +{ + { -8+INDEX_SHIFT, 13312, 14 }, /* 11010000000000 */ + { -7+INDEX_SHIFT, 13313, 14 }, /* 11010000000001 */ + { -6+INDEX_SHIFT, 3329, 12 }, /* 110100000001 */ + { -5+INDEX_SHIFT, 833, 10 }, /* 1101000001 */ + { -4+INDEX_SHIFT, 209, 8 }, /* 11010001 */ + { -3+INDEX_SHIFT, 53, 6 }, /* 110101 */ + { -2+INDEX_SHIFT, 12, 4 }, /* 1100 */ + { -1+INDEX_SHIFT, 2, 2 }, /* 10 */ + { 0+INDEX_SHIFT, 0, 1 }, /* 0 */ + { 1+INDEX_SHIFT, 7, 3 }, /* 111 */ + { 2+INDEX_SHIFT, 27, 5 }, /* 11011 */ + { 3+INDEX_SHIFT, 105, 7 }, /* 1101001 */ + { 4+INDEX_SHIFT, 417, 9 }, /* 110100001 */ + { 5+INDEX_SHIFT, 1665, 11 }, /* 11010000001 */ + { 6+INDEX_SHIFT, 13314, 14 }, /* 11010000000010 */ + { 7+INDEX_SHIFT, 13315, 14 } /* 11010000000011 */ +}; + +const Coding codesTnsCoeff2TCX10[] = +{ + { -8+INDEX_SHIFT, 512, 12 }, /* 001000000000 */ + { -7+INDEX_SHIFT, 513, 12 }, /* 001000000001 */ + { -6+INDEX_SHIFT, 65, 9 }, /* 001000001 */ + { -5+INDEX_SHIFT, 17, 7 }, /* 0010001 */ + { -4+INDEX_SHIFT, 5, 5 }, /* 00101 */ + { -3+INDEX_SHIFT, 0, 3 }, /* 000 */ + { -2+INDEX_SHIFT, 6, 3 }, /* 110 */ + { -1+INDEX_SHIFT, 1, 2 }, /* 01 */ + { 0+INDEX_SHIFT, 2, 2 }, /* 10 */ + { 1+INDEX_SHIFT, 7, 3 }, /* 111 */ + { 2+INDEX_SHIFT, 3, 4 }, /* 0011 */ + { 3+INDEX_SHIFT, 9, 6 }, /* 001001 */ + { 4+INDEX_SHIFT, 33, 8 }, /* 00100001 */ + { 5+INDEX_SHIFT, 129, 10 }, /* 0010000001 */ + { 6+INDEX_SHIFT, 514, 12 }, /* 001000000010 */ + { 7+INDEX_SHIFT, 515, 12 } /* 001000000011 */ +}; + +const Coding codesTnsCoeff3TCX20[] = +{ + { -8+INDEX_SHIFT, 13318, 14 }, /* 11010000000110 */ + { -7+INDEX_SHIFT, 13319, 14 }, /* 11010000000111 */ + { -6+INDEX_SHIFT, 6656, 13 }, /* 1101000000000 */ + { -5+INDEX_SHIFT, 1665, 11 }, /* 11010000001 */ + { -4+INDEX_SHIFT, 417, 9 }, /* 110100001 */ + { -3+INDEX_SHIFT, 105, 7 }, /* 1101001 */ + { -2+INDEX_SHIFT, 27, 5 }, /* 11011 */ + { -1+INDEX_SHIFT, 7, 3 }, /* 111 */ + { 0+INDEX_SHIFT, 0, 1 }, /* 0 */ + { 1+INDEX_SHIFT, 2, 2 }, /* 10 */ + { 2+INDEX_SHIFT, 12, 4 }, /* 1100 */ + { 3+INDEX_SHIFT, 53, 6 }, /* 110101 */ + { 4+INDEX_SHIFT, 209, 8 }, /* 11010001 */ + { 5+INDEX_SHIFT, 833, 10 }, /* 1101000001 */ + { 6+INDEX_SHIFT, 6657, 13 }, /* 1101000000001 */ + { 7+INDEX_SHIFT, 6658, 13 } /* 1101000000010 */ +}; + +const Coding codesTnsCoeff3TCX10[] = +{ + { -8+INDEX_SHIFT, 1284, 12 }, /* 010100000100 */ + { -7+INDEX_SHIFT, 1285, 12 }, /* 010100000101 */ + { -6+INDEX_SHIFT, 1286, 12 }, /* 010100000110 */ + { -5+INDEX_SHIFT, 1287, 12 }, /* 010100000111 */ + { -4+INDEX_SHIFT, 161, 9 }, /* 010100001 */ + { -3+INDEX_SHIFT, 41, 7 }, /* 0101001 */ + { -2+INDEX_SHIFT, 11, 5 }, /* 01011 */ + { -1+INDEX_SHIFT, 0, 2 }, /* 00 */ + { 0+INDEX_SHIFT, 2, 2 }, /* 10 */ + { 1+INDEX_SHIFT, 3, 2 }, /* 11 */ + { 2+INDEX_SHIFT, 3, 3 }, /* 011 */ + { 3+INDEX_SHIFT, 4, 4 }, /* 0100 */ + { 4+INDEX_SHIFT, 21, 6 }, /* 010101 */ + { 5+INDEX_SHIFT, 81, 8 }, /* 01010001 */ + { 6+INDEX_SHIFT, 640, 11 }, /* 01010000000 */ + { 7+INDEX_SHIFT, 641, 11 } /* 01010000001 */ +}; + +const Coding codesTnsCoeff4TCX20[] = +{ + { -8+INDEX_SHIFT, 13318, 14 }, /* 11010000000110 */ + { -7+INDEX_SHIFT, 13319, 14 }, /* 11010000000111 */ + { -6+INDEX_SHIFT, 6656, 13 }, /* 1101000000000 */ + { -5+INDEX_SHIFT, 833, 10 }, /* 1101000001 */ + { -4+INDEX_SHIFT, 209, 8 }, /* 11010001 */ + { -3+INDEX_SHIFT, 53, 6 }, /* 110101 */ + { -2+INDEX_SHIFT, 12, 4 }, /* 1100 */ + { -1+INDEX_SHIFT, 2, 2 }, /* 10 */ + { 0+INDEX_SHIFT, 0, 1 }, /* 0 */ + { 1+INDEX_SHIFT, 7, 3 }, /* 111 */ + { 2+INDEX_SHIFT, 27, 5 }, /* 11011 */ + { 3+INDEX_SHIFT, 105, 7 }, /* 1101001 */ + { 4+INDEX_SHIFT, 417, 9 }, /* 110100001 */ + { 5+INDEX_SHIFT, 1665, 11 }, /* 11010000001 */ + { 6+INDEX_SHIFT, 6657, 13 }, /* 1101000000001 */ + { 7+INDEX_SHIFT, 6658, 13 } /* 1101000000010 */ +}; + +const Coding codesTnsCoeff4TCX10[] = +{ + { -8+INDEX_SHIFT, 20, 12 }, /* 000000010100 */ + { -7+INDEX_SHIFT, 21, 12 }, /* 000000010101 */ + { -6+INDEX_SHIFT, 22, 12 }, /* 000000010110 */ + { -5+INDEX_SHIFT, 3, 9 }, /* 000000011 */ + { -4+INDEX_SHIFT, 1, 7 }, /* 0000001 */ + { -3+INDEX_SHIFT, 1, 5 }, /* 00001 */ + { -2+INDEX_SHIFT, 1, 3 }, /* 001 */ + { -1+INDEX_SHIFT, 2, 2 }, /* 10 */ + { 0+INDEX_SHIFT, 3, 2 }, /* 11 */ + { 1+INDEX_SHIFT, 1, 2 }, /* 01 */ + { 2+INDEX_SHIFT, 1, 4 }, /* 0001 */ + { 3+INDEX_SHIFT, 1, 6 }, /* 000001 */ + { 4+INDEX_SHIFT, 0, 8 }, /* 00000000 */ + { 5+INDEX_SHIFT, 23, 12 }, /* 000000010111 */ + { 6+INDEX_SHIFT, 8, 11 }, /* 00000001000 */ + { 7+INDEX_SHIFT, 9, 11 } /* 00000001001 */ +}; + +const Coding codesTnsCoeff5[] = +{ + { -8+INDEX_SHIFT, 6788, 13 }, /* 1101010000100 */ + { -7+INDEX_SHIFT, 6789, 13 }, /* 1101010000101 */ + { -6+INDEX_SHIFT, 6790, 13 }, /* 1101010000110 */ + { -5+INDEX_SHIFT, 849, 10 }, /* 1101010001 */ + { -4+INDEX_SHIFT, 213, 8 }, /* 11010101 */ + { -3+INDEX_SHIFT, 107, 7 }, /* 1101011 */ + { -2+INDEX_SHIFT, 27, 5 }, /* 11011 */ + { -1+INDEX_SHIFT, 7, 3 }, /* 111 */ + { 0+INDEX_SHIFT, 0, 1 }, /* 0 */ + { 1+INDEX_SHIFT, 2, 2 }, /* 10 */ + { 2+INDEX_SHIFT, 12, 4 }, /* 1100 */ + { 3+INDEX_SHIFT, 52, 6 }, /* 110100 */ + { 4+INDEX_SHIFT, 425, 9 }, /* 110101001 */ + { 5+INDEX_SHIFT, 6791, 13 }, /* 1101010000111 */ + { 6+INDEX_SHIFT, 3392, 12 }, /* 110101000000 */ + { 7+INDEX_SHIFT, 3393, 12 } /* 110101000001 */ +}; + +const Coding codesTnsCoeff6[] = +{ + { -8+INDEX_SHIFT, 4, 12 }, /* 000000000100 */ + { -7+INDEX_SHIFT, 5, 12 }, /* 000000000101 */ + { -6+INDEX_SHIFT, 6, 12 }, /* 000000000110 */ + { -5+INDEX_SHIFT, 1, 9 }, /* 000000001 */ + { -4+INDEX_SHIFT, 1, 7 }, /* 0000001 */ + { -3+INDEX_SHIFT, 1, 5 }, /* 00001 */ + { -2+INDEX_SHIFT, 1, 3 }, /* 001 */ + { -1+INDEX_SHIFT, 2, 2 }, /* 10 */ + { 0+INDEX_SHIFT, 3, 2 }, /* 11 */ + { 1+INDEX_SHIFT, 1, 2 }, /* 01 */ + { 2+INDEX_SHIFT, 1, 4 }, /* 0001 */ + { 3+INDEX_SHIFT, 1, 6 }, /* 000001 */ + { 4+INDEX_SHIFT, 1, 8 }, /* 00000001 */ + { 5+INDEX_SHIFT, 7, 12 }, /* 000000000111 */ + { 6+INDEX_SHIFT, 0, 11 }, /* 00000000000 */ + { 7+INDEX_SHIFT, 1, 11 } /* 00000000001 */ +}; + +const Coding codesTnsCoeff7[] = +{ + { -8+INDEX_SHIFT, 14, 11 }, /* 00000001110 */ + { -7+INDEX_SHIFT, 15, 11 }, /* 00000001111 */ + { -6+INDEX_SHIFT, 0, 10 }, /* 0000000000 */ + { -5+INDEX_SHIFT, 1, 10 }, /* 0000000001 */ + { -4+INDEX_SHIFT, 1, 7 }, /* 0000001 */ + { -3+INDEX_SHIFT, 1, 5 }, /* 00001 */ + { -2+INDEX_SHIFT, 1, 4 }, /* 0001 */ + { -1+INDEX_SHIFT, 1, 2 }, /* 01 */ + { 0+INDEX_SHIFT, 2, 10 }, /* 0000000010 */ + { 1+INDEX_SHIFT, 1, 1 }, /* 1 */ + { 2+INDEX_SHIFT, 1, 3 }, /* 001 */ + { 3+INDEX_SHIFT, 1, 6 }, /* 000001 */ + { 4+INDEX_SHIFT, 3, 10 }, /* 0000000011 */ + { 5+INDEX_SHIFT, 4, 10 }, /* 0000000100 */ + { 6+INDEX_SHIFT, 5, 10 }, /* 0000000101 */ + { 7+INDEX_SHIFT, 6, 10 } /* 0000000110 */ +}; + +const Coding codesTnsCoeff456[] = +{ + { -8+INDEX_SHIFT, 516, 12 }, /* 001000000100 */ + { -7+INDEX_SHIFT, 517, 12 }, /* 001000000101 */ + { -6+INDEX_SHIFT, 518, 12 }, /* 001000000110 */ + { -5+INDEX_SHIFT, 65, 9 }, /* 001000001 */ + { -4+INDEX_SHIFT, 17, 7 }, /* 0010001 */ + { -3+INDEX_SHIFT, 5, 5 }, /* 00101 */ + { -2+INDEX_SHIFT, 3, 4 }, /* 0011 */ + { -1+INDEX_SHIFT, 1, 2 }, /* 01 */ + { 0+INDEX_SHIFT, 3, 2 }, /* 11 */ + { 1+INDEX_SHIFT, 2, 2 }, /* 10 */ + { 2+INDEX_SHIFT, 0, 3 }, /* 000 */ + { 3+INDEX_SHIFT, 9, 6 }, /* 001001 */ + { 4+INDEX_SHIFT, 33, 8 }, /* 00100001 */ + { 5+INDEX_SHIFT, 519, 12 }, /* 001000000111 */ + { 6+INDEX_SHIFT, 256, 11 }, /* 00100000000 */ + { 7+INDEX_SHIFT, 257, 11 } /* 00100000001 */ +}; + +const Coding codesTnsCoeff0WBTCX20[] = +{ + { -8+INDEX_SHIFT, 225, 10 }, /* 0011100001 */ + { -7+INDEX_SHIFT, 113, 9 }, /* 001110001 */ + { -6+INDEX_SHIFT, 29, 7 }, /* 0011101 */ + { -5+INDEX_SHIFT, 15, 6 }, /* 001111 */ + { -4+INDEX_SHIFT, 2, 4 }, /* 0010 */ + { -3+INDEX_SHIFT, 0, 3 }, /* 000 */ + { -2+INDEX_SHIFT, 13, 4 }, /* 1101 */ + { -1+INDEX_SHIFT, 2, 3 }, /* 010 */ + { 0+INDEX_SHIFT, 5, 3 }, /* 101 */ + { 1+INDEX_SHIFT, 3, 3 }, /* 011 */ + { 2+INDEX_SHIFT, 4, 3 }, /* 100 */ + { 3+INDEX_SHIFT, 7, 3 }, /* 111 */ + { 4+INDEX_SHIFT, 12, 4 }, /* 1100 */ + { 5+INDEX_SHIFT, 6, 5 }, /* 00110 */ + { 6+INDEX_SHIFT, 57, 8 }, /* 00111001 */ + { 7+INDEX_SHIFT, 224, 10 } /* 0011100000 */ +}; + + +const Coding codesTnsCoeff1WBTCX20[] = +{ + { -8+INDEX_SHIFT, 512, 12 }, /* 001000000000 */ + { -7+INDEX_SHIFT, 513, 12 }, /* 001000000001 */ + { -6+INDEX_SHIFT, 514, 12 }, /* 001000000010 */ + { -5+INDEX_SHIFT, 65, 9 }, /* 001000001 */ + { -4+INDEX_SHIFT, 17, 7 }, /* 0010001 */ + { -3+INDEX_SHIFT, 5, 5 }, /* 00101 */ + { -2+INDEX_SHIFT, 0, 3 }, /* 000 */ + { -1+INDEX_SHIFT, 2, 3 }, /* 010 */ + { 0+INDEX_SHIFT, 3, 2 }, /* 11 */ + { 1+INDEX_SHIFT, 2, 2 }, /* 10 */ + { 2+INDEX_SHIFT, 3, 3 }, /* 011 */ + { 3+INDEX_SHIFT, 3, 4 }, /* 0011 */ + { 4+INDEX_SHIFT, 9, 6 }, /* 001001 */ + { 5+INDEX_SHIFT, 33, 8 }, /* 00100001 */ + { 6+INDEX_SHIFT, 129, 10 }, /* 0010000001 */ + { 7+INDEX_SHIFT, 515, 12 } /* 001000000011 */ +}; + + +const Coding codesTnsCoeff2WB[] = +{ + { -8+INDEX_SHIFT, 5632, 13 }, /* 1011000000000 */ + { -7+INDEX_SHIFT, 5633, 13 }, /* 1011000000001 */ + { -6+INDEX_SHIFT, 1409, 11 }, /* 10110000001 */ + { -5+INDEX_SHIFT, 353, 9 }, /* 101100001 */ + { -4+INDEX_SHIFT, 89, 7 }, /* 1011001 */ + { -3+INDEX_SHIFT, 23, 5 }, /* 10111 */ + { -2+INDEX_SHIFT, 4, 3 }, /* 100 */ + { -1+INDEX_SHIFT, 0, 2 }, /* 00 */ + { 0+INDEX_SHIFT, 3, 2 }, /* 11 */ + { 1+INDEX_SHIFT, 1, 2 }, /* 01 */ + { 2+INDEX_SHIFT, 10, 4 }, /* 1010 */ + { 3+INDEX_SHIFT, 45, 6 }, /* 101101 */ + { 4+INDEX_SHIFT, 177, 8 }, /* 10110001 */ + { 5+INDEX_SHIFT, 705, 10 }, /* 1011000001 */ + { 6+INDEX_SHIFT, 5634, 13 }, /* 1011000000010 */ + { 7+INDEX_SHIFT, 5635, 13 } /* 1011000000011 */ +}; + +const Coding codesTnsCoeff3WB[] = +{ + { -8+INDEX_SHIFT, 5638, 13 }, /* 1011000000110 */ + { -7+INDEX_SHIFT, 5639, 13 }, /* 1011000000111 */ + { -6+INDEX_SHIFT, 2816, 12 }, /* 101100000000 */ + { -5+INDEX_SHIFT, 353, 9 }, /* 101100001 */ + { -4+INDEX_SHIFT, 177, 8 }, /* 10110001 */ + { -3+INDEX_SHIFT, 45, 6 }, /* 101101 */ + { -2+INDEX_SHIFT, 10, 4 }, /* 1010 */ + { -1+INDEX_SHIFT, 0, 2 }, /* 00 */ + { 0+INDEX_SHIFT, 3, 2 }, /* 11 */ + { 1+INDEX_SHIFT, 1, 2 }, /* 01 */ + { 2+INDEX_SHIFT, 4, 3 }, /* 100 */ + { 3+INDEX_SHIFT, 23, 5 }, /* 10111 */ + { 4+INDEX_SHIFT, 89, 7 }, /* 1011001 */ + { 5+INDEX_SHIFT, 705, 10 }, /* 1011000001 */ + { 6+INDEX_SHIFT, 2817, 12 }, /* 101100000001 */ + { 7+INDEX_SHIFT, 2818, 12 } /* 101100000010 */ +}; + +int const nTnsCoeffCodes = sizeof(codesTnsCoeff0TCX20)/sizeof(codesTnsCoeff0TCX20[0]); + +const Coding * const codesTnsCoeffSWBTCX20[] = { codesTnsCoeff0TCX20, codesTnsCoeff1TCX20, codesTnsCoeff2TCX20, codesTnsCoeff3TCX20, codesTnsCoeff4TCX20, codesTnsCoeff5, codesTnsCoeff6, codesTnsCoeff7 }; +const Coding * const codesTnsCoeffSWBTCX10[] = { codesTnsCoeff0TCX10, codesTnsCoeff1TCX10, codesTnsCoeff2TCX10, codesTnsCoeff3TCX10, codesTnsCoeff4TCX10, codesTnsCoeff5, codesTnsCoeff6, codesTnsCoeff7 }; +const Coding * const codesTnsCoeffWBTCX20[] = { codesTnsCoeff0WBTCX20, codesTnsCoeff1WBTCX20, codesTnsCoeff2WB, codesTnsCoeff3WB, codesTnsCoeff456, codesTnsCoeff456, codesTnsCoeff456, codesTnsCoeff7 }; + +int const nTnsCoeffTables = sizeof(codesTnsCoeffSWBTCX20)/sizeof(codesTnsCoeffSWBTCX20[0]); + +const Coding codesTnsOrderTCX20[] = +{ + { 1, 0, 2 }, /* 00 */ + { 2, 40, 6 }, /* 101000 */ + { 3, 41, 6 }, /* 101001 */ + { 4, 21, 5 }, /* 10101 */ + { 5, 11, 4 }, /* 1011 */ + { 6, 4, 3 }, /* 100 */ + { 7, 1, 2 }, /* 01 */ + { 8, 3, 2 } /* 11 */ +}; +const Coding codesTnsOrderTCX10[] = +{ + { 1, 0, 3 }, /* 000 */ + { 2, 16, 5 }, /* 10000 */ + { 3, 17, 5 }, /* 10001 */ + { 4, 9, 4 }, /* 1001 */ + { 5, 1, 3 }, /* 001 */ + { 6, 5, 3 }, /* 101 */ + { 7, 1, 2 }, /* 01 */ + { 8, 3, 2 } /* 11 */ +}; +const Coding codesTnsOrder[] = +{ + { 1, 96, 7 }, /* 1100000 */ + { 2, 97, 7 }, /* 1100001 */ + { 3, 49, 6 }, /* 110001 */ + { 4, 25, 5 }, /* 11001 */ + { 5, 13, 4 }, /* 1101 */ + { 6, 7, 3 }, /* 111 */ + { 7, 2, 2 }, /* 10 */ + { 8, 0, 1 } /* 0 */ +}; + +int const nTnsOrderCodes = sizeof(codesTnsOrder)/sizeof(codesTnsOrder[0]); + +ParamsBitMap const tnsSWBTCX20FilterCoeffBitMap = +{ + 1, + { + { 0, GetSWBTCX20TnsFilterCoeffBits, TRUE, GetTnsFilterCoeff, SetTnsFilterCoeff, EncodeSWBTCX20TnsFilterCoeff, DecodeSWBTCX20TnsFilterCoeff, NULL } /* TNS filter coefficients */ + } +}; + +ParamsBitMap const tnsSWBTCX10FilterCoeffBitMap = +{ + 1, + { + { 0, GetSWBTCX10TnsFilterCoeffBits, TRUE, GetTnsFilterCoeff, SetTnsFilterCoeff, EncodeSWBTCX10TnsFilterCoeff, DecodeSWBTCX10TnsFilterCoeff, NULL } /* TNS filter coefficients */ + } +}; + +ParamsBitMap const tnsSWBTCX20FilterBitMap = +{ + 1, + { + { 0, GetTnsFilterOrderBitsSWBTCX20, FALSE, GetTnsFilterOrder, SetTnsFilterOrder, EncodeTnsFilterOrderSWBTCX20, DecodeTnsFilterOrderSWBTCX20, &tnsSWBTCX20FilterCoeffBitMap } /* TNS filter order */ + } +}; + +ParamsBitMap const tnsSWBTCX10FilterBitMap = +{ + 1, + { + { 0, GetTnsFilterOrderBitsSWBTCX10, FALSE, GetTnsFilterOrder, SetTnsFilterOrder, EncodeTnsFilterOrderSWBTCX10, DecodeTnsFilterOrderSWBTCX10, &tnsSWBTCX10FilterCoeffBitMap } /* TNS filter order */ + } +}; + +ParamsBitMap const tnsSWBTCX20BitMap = +{ + 1, + { + { 1, NULL, FALSE, GetNumOfTnsFilters, SetNumOfTnsFilters, NULL, NULL, &tnsSWBTCX20FilterBitMap } /* Number of TNS filters */ + } +}; + +/* For storing/reading bits in SWB/FB mode */ +ParamsBitMap const tnsEnabledSWBTCX20BitMap = +{ + 1, + { + { 1, NULL, TRUE, GetTnsEnabled, SetTnsEnabled, NULL, NULL, &tnsSWBTCX20BitMap } /* TNS Enabled/Disable */ + } +}; + +ParamsBitMap const tnsSWBTCX10BitMap = +{ + 1, + { + { 1, NULL, FALSE, GetNumOfTnsFilters, SetNumOfTnsFilters, NULL, NULL, &tnsSWBTCX10FilterBitMap } /* Number of TNS filters */ + } +}; + +/* For storing/reading bits in SWB/FB mode */ +ParamsBitMap const tnsEnabledSWBTCX10BitMap = +{ + 1, + { + { 1, NULL, TRUE, GetTnsEnabled, SetTnsEnabled, NULL, NULL, &tnsSWBTCX10BitMap } /* TNS Enabled/Disable */ + } +}; + +ParamsBitMap const tnsWBTCX20FilterCoeffBitMap = +{ + 1, + { + { 0, GetWBTCX20TnsFilterCoeffBits, TRUE, GetTnsFilterCoeff, SetTnsFilterCoeff, EncodeWBTCX20TnsFilterCoeff, DecodeWBTCX20TnsFilterCoeff, NULL } /* TNS filter coefficients */ + } +}; + + +ParamsBitMap const tnsWBTCX20FilterBitMap = +{ + 1, + { + { 0, GetTnsFilterOrderBits, FALSE, GetTnsFilterOrder, SetTnsFilterOrder, EncodeTnsFilterOrder, DecodeTnsFilterOrder, &tnsWBTCX20FilterCoeffBitMap } /* TNS filter order */ + } +}; + + +/* For storing/reading bits in WB mode */ +ParamsBitMap const tnsEnabledWBTCX20BitMap = +{ + 1, + { + { 1, NULL, TRUE, GetTnsEnabledSingleFilter, SetTnsEnabledSingleFilter, NULL, NULL, &tnsWBTCX20FilterBitMap } /* TNS Enabled/Disable */ + } +}; + + +/** + * 4 bit resolution TNS coefficients. + */ +float const tnsCoeff4[16]= +{ + -0.99573418F, /* = sin(-8*(EVS_PI/2.0)/(8 + 0.5)) */ + -0.96182564F, /* = sin(-7*(EVS_PI/2.0)/(8 + 0.5)) */ + -0.89516329F, + -0.79801723F, + -0.67369564F, + -0.52643216F, + -0.36124167F, + -0.18374952F, /* = sin(-1*(EVS_PI/2.0)/(8 + 0.5)) */ + 0.00000000F, /* = sin(0*(EVS_PI/2.0)/(8 + 0.5)) */ + 0.20791169F, /* = sin(1*(EVS_PI/2.0)/(8 - 0.5)) */ + 0.40673664F, + 0.58778525F, + 0.74314483F, + 0.86602540F, + 0.95105652F, /* = sin(6*(EVS_PI/2.0)/(8 - 0.5)) */ + 0.99452190F /* = sin(7*(EVS_PI/2.0)/(8 - 0.5)) */ +}; + +/**********************************************************************/ /** +igf settings structure for each bitrate mode +**************************************************************************/ +const int swb_offset_LB_new[15][IGF_MAX_SFB] = +{ + /* 0: for 9600 kbs WB */ + { + 4, 164, 186, 242, 320 + }, + /* 1: for 13200 kbs WB RF */ + { + 4, 164, 186, 242, 320 + }, + /* 2: for 9600 kbs SWB */ + { + 4, 200, 322, 444, 566 + }, + /* 3: for 13200 kbs SWB */ + { + 7, 256, 288, 328, 376, 432, 496, 566 + }, + /* 4: for 13200 kbs SWB RF */ + { + 4, 200, 322, 444, 566 + }, + /* 5: for 16400 kbs SWB */ + { + 8, 256, 288, 328, 376, 432, 496, 576, 640 + }, + /* 6: for 24400 kbs SWB */ + { + 9, 256, 284, 318, 358, 402, 450, 508, 576, 640 + }, + /* 7: for 32000 kbs SWB */ + { + 9, 256, 284, 318, 358, 402, 450, 508, 576, 640 + }, + /* 8: for 48000 kbs SWB */ + { + 4, 512, 534, 576, 640 + }, + /* 9: for 16400 kbs FB */ + { + 10, 256, 288, 328, 376, 432, 496, 576, 640, 720, 800 + }, + /* 10: for 24400 kbs FB */ + { + 11, 256, 284, 318, 358, 402, 450, 508, 576, 640, 720, 800 + }, + /* 11: for 32000 kbs FB */ + { + 11, 256, 284, 318, 358, 402, 450, 508, 576, 640, 720, 800 + }, + /* 12: for 48000 kbs FB */ + { + 5, 512, 584, 656, 728, 800 + }, + /* 14: for 96000 kbs FB */ + { + 3, 640, 720, 800 /* old: 640, 760, 880 */ + }, + /* 14: for 128000 kbs FB */ + { + 3, 640, 720, 800 /* old: 640, 760, 880 */ + } +}; + +const float igf_whitening_TH[15][2][IGF_MAX_TILES] = +{ + /* 0: for 9600 kbs WB */ + { + /* medium */ {0.36f, 0.36f, 0.f, 0.f}, + /* strong */ {1.41f, 1.41f, 0.f, 0.f} + }, + /* 1: for 13200 kbs WB RF */ + { + /* medium */ {0.36f, 0.36f, 0.f, 0.f}, + /* strong */ {1.41f, 1.41f, 0.f, 0.f} + }, + /* 2: for 9600 kbs SWB */ + { + /* medium */ {0.84f, 0.89f, 0.f, 0.f}, + /* strong */ {1.30f, 1.25f, 0.f, 0.f} + }, + /* 3: for 13200 kbs SWB */ + { + /* medium */ {0.84f, 0.89f, 0.f, 0.f}, + /* strong */ {1.30f, 1.25f, 0.f, 0.f} + }, + /* 4: for 13200 kbs SWB RF */ + { + /* medium */ {0.84f, 0.89f, 0.f, 0.f}, + /* strong */ {1.30f, 1.25f, 0.f, 0.f} + }, + /* 5: for 16400 kbs SWB */ + { + /* medium */ {0.83f, 0.89f, 0.89f, 0.f}, + /* strong */ {1.31f, 1.19f, 1.19f, 0.f} + }, + /* 6: for 24400 kbs SWB*/ + { + /* medium */ {0.81f, 0.85f, 0.85f, 0.f}, + /* strong */ {1.35f, 1.23f, 1.23f, 0.f} + }, + /* 7: for 32000 kbs SWB */ + { + /* medium */ {0.91f, 0.85f, 0.85f, 0.f}, + /* strong */ {1.34f, 1.35f, 1.35f, 0.f} + }, + /* 8: for 48000 kbs SWB */ + { + /* medium */ {1.15f, 0.f, 0.f, 0.f}, + /* strong */ {1.19f, 0.f, 0.f, 0.f} + }, + /* 10: for 16400 kbs FB */ + { + /* medium */ {0.63f, 0.27f, 0.36f, 0.f}, + /* strong */ {1.53f, 1.32f, 0.67f, 0.f} + }, + /* 10: for 24400 kbs FB */ + { + /* medium */ {0.78f, 0.31f, 0.34f, 0.34f}, + /* strong */ {1.49f, 1.38f, 0.65f, 0.65f} + }, + /* 11: for 32000 kbs FB */ + { + /* medium */ {0.78f, 0.31f, 0.34f, 0.34f}, + /* strong */ {1.49f, 1.38f, 0.65f, 0.65f} + }, + /* 12: for 48000 kbs FB */ + { + /* medium */ {0.80f, 0.f, 0.f, 0.f}, + /* strong */ {1.00f, 0.f, 0.f, 0.f} + }, + /* 13: for 96000 kbs FB */ + { + /* medium */ {0.f, 0.f, 0.f, 0.f}, + /* strong */ {2.82f, 0.f, 0.f, 0.f} + }, + /* 14: for 128000 kbs FB */ + { + /* medium */ {0.f, 0.f, 0.f, 0.f}, + /* strong */ {2.82f, 0.f, 0.f, 0.f} + } +}; + +/* IGF SCF arithmetic coder cumulative frequency tables and offsets */ +const short cf_off_se01_tab[9] = +{ + +1, /* 9.6 kbs B*/ + +1, /* 13.2 kbs WB RF B*/ + +1, /* 9.6 kbs SWB B*/ + +1, /* 13.2 kbs A*/ + +1, /* 13.2 kbs SWB RF B*/ + +1, /* 16.4 kbs B*/ + +1, /* 24.4 kbs B*/ + +1, /* 32.0 kbs A*/ + -1 /* 48.0 kbs B*/ +}; + +const short cf_off_se02_tab[9][IGF_CTX_COUNT] = +{ + { +1, +2, +2, +2, +3, +3, +4}, /* 9.6 kbs B*/ + { +1, +2, +2, +2, +3, +3, +4}, /* 13.2 kbs WB RF B*/ + { +0, +2, +3, +3, +2, +2, +4}, /* 9.6 kbs SWB B*/ + { +0, +2, +3, +3, +2, +2, +4}, /* 13.2 kbs A*/ + { +0, +2, +3, +3, +2, +2, +4}, /* 13.2 kbs SWB RF B*/ + { +0, +2, +3, +3, +2, +2, +4}, /* 16.4 kbs B*/ + { -1, +2, +2, +2, +2, +3, +5}, /* 24.4 kbs B*/ + { -1, +2, +2, +2, +2, +3, +5}, /* 32.0 kbs A*/ + { +3, +2, +3, +2, +3, +3, +6} /* 48.0 kbs B*/ +}; + +const short cf_off_se10_tab = -7; + +const short cf_off_se11_tab[IGF_CTX_COUNT][IGF_CTX_COUNT] = +{ + { -5, +0, +0, +0, +0, +0, +0}, + { +0, +0, +0, +0, +0, +0, +0}, + { +0, +0, +0, +0, +0, +0, +0}, + { +0, +0, +0, +0, +0, +0, +0}, + { +0, +0, +0, +0, +0, +0, +0}, + { +0, +0, +0, +0, +0, +0, +1}, + { +0, +1, +0, +0, +3, +0, +3} +}; + +const unsigned short cf_se00_tab[IGF_SYMBOLS_IN_TABLE + 1] = +{ + 16384, 16356, 16299, 16185, 15904, 15282, 14669, 13598, 11886, 9541, 6613, 3845, 1799, 606, 153, 32, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0 +}; + +const unsigned short cf_se01_tab[9][IGF_SYMBOLS_IN_TABLE + 1] = +{ + {16384, 16320, 16285, 16237, 16163, 16049, 15864, 15604, 15187, 14557, 13612, 12308, 10590, 8535, 6346, 4396, 2900, 1917, 1289, 870, 593, 408, 279, 181, 122, 78, 52, 0}, /* 9.6 kbs B*/ + {16384, 16320, 16285, 16237, 16163, 16049, 15864, 15604, 15187, 14557, 13612, 12308, 10590, 8535, 6346, 4396, 2900, 1917, 1289, 870, 593, 408, 279, 181, 122, 78, 52, 0}, /* 13.2 kbs WB RF B*/ + {16384, 16375, 16362, 16339, 16307, 16258, 16180, 16061, 15845, 15463, 14795, 13680, 11828, 9252, 6358, 3769, 2079, 1186, 687, 415, 242, 150, 100, 67, 44, 30, 19, 0}, /* 9.6 kbs SWB B*/ + {16384, 16375, 16362, 16339, 16307, 16258, 16180, 16061, 15845, 15463, 14795, 13680, 11828, 9252, 6358, 3769, 2079, 1186, 687, 415, 242, 150, 100, 67, 44, 30, 19, 0}, /* 13.2 kbs A*/ + {16384, 16375, 16362, 16339, 16307, 16258, 16180, 16061, 15845, 15463, 14795, 13680, 11828, 9252, 6358, 3769, 2079, 1186, 687, 415, 242, 150, 100, 67, 44, 30, 19, 0}, /* 13.2 kbs SWB RF B*/ + {16384, 16375, 16362, 16339, 16307, 16258, 16180, 16061, 15845, 15463, 14795, 13680, 11828, 9252, 6358, 3769, 2079, 1186, 687, 415, 242, 150, 100, 67, 44, 30, 19, 0}, /* 16.4 kbs B*/ + {16384, 16369, 16356, 16337, 16311, 16268, 16197, 16073, 15876, 15544, 14977, 13987, 12327, 9908, 7017, 4393, 2545, 1446, 840, 493, 292, 183, 111, 70, 45, 31, 20, 0}, /* 24.4 kbs B*/ + {16384, 16369, 16356, 16337, 16311, 16268, 16197, 16073, 15876, 15544, 14977, 13987, 12327, 9908, 7017, 4393, 2545, 1446, 840, 493, 292, 183, 111, 70, 45, 31, 20, 0}, /* 32.0 kbs A*/ + {16384, 16368, 16355, 16334, 16291, 16212, 16071, 15816, 15359, 14523, 13014, 10534, 7345, 4272, 2228, 1149, 626, 357, 215, 139, 93, 67, 53, 43, 36, 28, 22, 0} /* 48.0 kbs B*/ +}; + +const unsigned short cf_se02_tab[9][IGF_CTX_COUNT][IGF_SYMBOLS_IN_TABLE + 1] = +{ + { /* 9.6 kbs B */ + { 16384, 16369, 16348, 16316, 16256, 16172, 16017, 15735, 15246, 14363, 13036, 11139, 8916, 6724, 4757, 3282, 2221, 1549, 1105, 771, 548, 364, 238, 151, 89, 50, 30, 0}, + { 16384, 16371, 16358, 16339, 16290, 16241, 16153, 16040, 15813, 15397, 14601, 13301, 11360, 8916, 6254, 3911, 2220, 1280, 755, 461, 278, 177, 111, 70, 35, 20, 12, 0}, + { 16384, 16375, 16359, 16333, 16286, 16243, 16154, 16024, 15771, 15380, 14712, 13537, 11742, 9425, 6872, 4378, 2327, 1197, 671, 412, 259, 145, 93, 52, 26, 13, 5, 0}, + { 16384, 16372, 16358, 16326, 16289, 16241, 16147, 16014, 15765, 15321, 14670, 13546, 11912, 9787, 7323, 4824, 2536, 1330, 731, 438, 258, 148, 86, 37, 22, 11, 2, 0}, + { 16384, 16376, 16364, 16344, 16315, 16272, 16219, 16119, 15910, 15620, 15100, 14254, 13063, 11489, 9413, 7100, 4738, 2751, 1584, 973, 597, 349, 201, 96, 47, 22, 9, 0}, + { 16384, 16364, 16340, 16312, 16288, 16237, 16166, 16026, 15756, 15390, 14833, 13870, 12627, 10998, 8985, 6893, 4720, 3048, 1860, 1131, 725, 449, 215, 111, 56, 34, 14, 0}, + { 16384, 16326, 16297, 16246, 16183, 16064, 15884, 15632, 15240, 14763, 14107, 13230, 12185, 10886, 9390, 7781, 6194, 4696, 3350, 2259, 1506, 975, 604, 356, 201, 106, 48, 0} + }, + { /* 13.2 kbs WB RF B*/ + { 16384, 16369, 16348, 16316, 16256, 16172, 16017, 15735, 15246, 14363, 13036, 11139, 8916, 6724, 4757, 3282, 2221, 1549, 1105, 771, 548, 364, 238, 151, 89, 50, 30, 0}, + { 16384, 16371, 16358, 16339, 16290, 16241, 16153, 16040, 15813, 15397, 14601, 13301, 11360, 8916, 6254, 3911, 2220, 1280, 755, 461, 278, 177, 111, 70, 35, 20, 12, 0}, + { 16384, 16375, 16359, 16333, 16286, 16243, 16154, 16024, 15771, 15380, 14712, 13537, 11742, 9425, 6872, 4378, 2327, 1197, 671, 412, 259, 145, 93, 52, 26, 13, 5, 0}, + { 16384, 16372, 16358, 16326, 16289, 16241, 16147, 16014, 15765, 15321, 14670, 13546, 11912, 9787, 7323, 4824, 2536, 1330, 731, 438, 258, 148, 86, 37, 22, 11, 2, 0}, + { 16384, 16376, 16364, 16344, 16315, 16272, 16219, 16119, 15910, 15620, 15100, 14254, 13063, 11489, 9413, 7100, 4738, 2751, 1584, 973, 597, 349, 201, 96, 47, 22, 9, 0}, + { 16384, 16364, 16340, 16312, 16288, 16237, 16166, 16026, 15756, 15390, 14833, 13870, 12627, 10998, 8985, 6893, 4720, 3048, 1860, 1131, 725, 449, 215, 111, 56, 34, 14, 0}, + { 16384, 16326, 16297, 16246, 16183, 16064, 15884, 15632, 15240, 14763, 14107, 13230, 12185, 10886, 9390, 7781, 6194, 4696, 3350, 2259, 1506, 975, 604, 356, 201, 106, 48, 0} + }, + { /* 9.6 kbs SWB B*/ + { 16384, 16359, 16349, 16331, 16300, 16236, 16112, 15894, 15480, 14691, 13257, 10996, 8168, 5357, 3193, 1864, 1098, 676, 426, 265, 173, 117, 81, 59, 45, 35, 26, 0}, + { 16384, 16374, 16370, 16367, 16362, 16348, 16325, 16283, 16204, 16058, 15715, 14980, 13521, 11144, 7972, 4702, 2366, 1063, 480, 241, 128, 71, 42, 22, 14, 9, 5, 0}, + { 16384, 16380, 16377, 16375, 16372, 16365, 16354, 16334, 16295, 16216, 16056, 15716, 15034, 13690, 11467, 8404, 5150, 2385, 908, 417, 199, 106, 62, 35, 21, 13, 7, 0}, + { 16384, 16378, 16376, 16373, 16368, 16360, 16346, 16318, 16267, 16173, 15991, 15644, 14932, 13623, 11575, 8688, 5224, 2309, 891, 393, 202, 103, 57, 34, 20, 11, 8, 0}, + { 16384, 16375, 16372, 16365, 16348, 16322, 16279, 16201, 16046, 15728, 15214, 14297, 12811, 10673, 7918, 4530, 2109, 978, 466, 234, 121, 72, 46, 31, 25, 17, 13, 0}, + { 16384, 16366, 16357, 16341, 16325, 16289, 16220, 16084, 15768, 15300, 14466, 13206, 11402, 9176, 6633, 4092, 2192, 1171, 592, 315, 179, 111, 74, 46, 31, 26, 18, 0}, + { 16384, 16301, 16266, 16211, 16140, 16045, 15889, 15652, 15358, 14883, 14192, 13119, 11753, 10181, 8445, 6708, 5023, 3449, 2226, 1375, 849, 516, 353, 231, 153, 107, 78, 0} + }, + { /* 13.2 kbs A */ + { 16384, 16359, 16349, 16331, 16300, 16236, 16112, 15894, 15480, 14691, 13257, 10996, 8168, 5357, 3193, 1864, 1098, 676, 426, 265, 173, 117, 81, 59, 45, 35, 26, 0}, + { 16384, 16374, 16370, 16367, 16362, 16348, 16325, 16283, 16204, 16058, 15715, 14980, 13521, 11144, 7972, 4702, 2366, 1063, 480, 241, 128, 71, 42, 22, 14, 9, 5, 0}, + { 16384, 16380, 16377, 16375, 16372, 16365, 16354, 16334, 16295, 16216, 16056, 15716, 15034, 13690, 11467, 8404, 5150, 2385, 908, 417, 199, 106, 62, 35, 21, 13, 7, 0}, + { 16384, 16378, 16376, 16373, 16368, 16360, 16346, 16318, 16267, 16173, 15991, 15644, 14932, 13623, 11575, 8688, 5224, 2309, 891, 393, 202, 103, 57, 34, 20, 11, 8, 0}, + { 16384, 16375, 16372, 16365, 16348, 16322, 16279, 16201, 16046, 15728, 15214, 14297, 12811, 10673, 7918, 4530, 2109, 978, 466, 234, 121, 72, 46, 31, 25, 17, 13, 0}, + { 16384, 16366, 16357, 16341, 16325, 16289, 16220, 16084, 15768, 15300, 14466, 13206, 11402, 9176, 6633, 4092, 2192, 1171, 592, 315, 179, 111, 74, 46, 31, 26, 18, 0}, + { 16384, 16301, 16266, 16211, 16140, 16045, 15889, 15652, 15358, 14883, 14192, 13119, 11753, 10181, 8445, 6708, 5023, 3449, 2226, 1375, 849, 516, 353, 231, 153, 107, 78, 0} + }, + { /* 13.2 kbs SWB RF B*/ + { 16384, 16359, 16349, 16331, 16300, 16236, 16112, 15894, 15480, 14691, 13257, 10996, 8168, 5357, 3193, 1864, 1098, 676, 426, 265, 173, 117, 81, 59, 45, 35, 26, 0}, + { 16384, 16374, 16370, 16367, 16362, 16348, 16325, 16283, 16204, 16058, 15715, 14980, 13521, 11144, 7972, 4702, 2366, 1063, 480, 241, 128, 71, 42, 22, 14, 9, 5, 0}, + { 16384, 16380, 16377, 16375, 16372, 16365, 16354, 16334, 16295, 16216, 16056, 15716, 15034, 13690, 11467, 8404, 5150, 2385, 908, 417, 199, 106, 62, 35, 21, 13, 7, 0}, + { 16384, 16378, 16376, 16373, 16368, 16360, 16346, 16318, 16267, 16173, 15991, 15644, 14932, 13623, 11575, 8688, 5224, 2309, 891, 393, 202, 103, 57, 34, 20, 11, 8, 0}, + { 16384, 16375, 16372, 16365, 16348, 16322, 16279, 16201, 16046, 15728, 15214, 14297, 12811, 10673, 7918, 4530, 2109, 978, 466, 234, 121, 72, 46, 31, 25, 17, 13, 0}, + { 16384, 16366, 16357, 16341, 16325, 16289, 16220, 16084, 15768, 15300, 14466, 13206, 11402, 9176, 6633, 4092, 2192, 1171, 592, 315, 179, 111, 74, 46, 31, 26, 18, 0}, + { 16384, 16301, 16266, 16211, 16140, 16045, 15889, 15652, 15358, 14883, 14192, 13119, 11753, 10181, 8445, 6708, 5023, 3449, 2226, 1375, 849, 516, 353, 231, 153, 107, 78, 0} + }, + { /* 16.4 kbs B */ + { 16384, 16359, 16349, 16331, 16300, 16236, 16112, 15894, 15480, 14691, 13257, 10996, 8168, 5357, 3193, 1864, 1098, 676, 426, 265, 173, 117, 81, 59, 45, 35, 26, 0}, + { 16384, 16374, 16370, 16367, 16362, 16348, 16325, 16283, 16204, 16058, 15715, 14980, 13521, 11144, 7972, 4702, 2366, 1063, 480, 241, 128, 71, 42, 22, 14, 9, 5, 0}, + { 16384, 16380, 16377, 16375, 16372, 16365, 16354, 16334, 16295, 16216, 16056, 15716, 15034, 13690, 11467, 8404, 5150, 2385, 908, 417, 199, 106, 62, 35, 21, 13, 7, 0}, + { 16384, 16378, 16376, 16373, 16368, 16360, 16346, 16318, 16267, 16173, 15991, 15644, 14932, 13623, 11575, 8688, 5224, 2309, 891, 393, 202, 103, 57, 34, 20, 11, 8, 0}, + { 16384, 16375, 16372, 16365, 16348, 16322, 16279, 16201, 16046, 15728, 15214, 14297, 12811, 10673, 7918, 4530, 2109, 978, 466, 234, 121, 72, 46, 31, 25, 17, 13, 0}, + { 16384, 16366, 16357, 16341, 16325, 16289, 16220, 16084, 15768, 15300, 14466, 13206, 11402, 9176, 6633, 4092, 2192, 1171, 592, 315, 179, 111, 74, 46, 31, 26, 18, 0}, + { 16384, 16301, 16266, 16211, 16140, 16045, 15889, 15652, 15358, 14883, 14192, 13119, 11753, 10181, 8445, 6708, 5023, 3449, 2226, 1375, 849, 516, 353, 231, 153, 107, 78, 0} + }, + { /* 24.4 kbs B */ + { 16384, 16351, 16333, 16303, 16254, 16163, 15993, 15681, 15080, 13987, 12109, 9465, 6588, 4160, 2488, 1480, 912, 589, 389, 266, 190, 131, 93, 68, 47, 34, 24, 0}, + { 16384, 16379, 16375, 16369, 16360, 16345, 16328, 16286, 16211, 16078, 15810, 15233, 14058, 11933, 8881, 5609, 2940, 1290, 558, 274, 150, 80, 47, 29, 17, 11, 6, 0}, + { 16384, 16382, 16380, 16377, 16370, 16358, 16337, 16300, 16224, 16088, 15811, 15233, 14112, 12019, 9061, 5723, 2780, 1121, 480, 239, 123, 69, 41, 22, 13, 8, 5, 0}, + { 16384, 16377, 16375, 16369, 16363, 16351, 16325, 16268, 16172, 16009, 15686, 15039, 13830, 11799, 8924, 5422, 2444, 960, 441, 220, 111, 63, 37, 22, 11, 6, 3, 0}, + { 16384, 16374, 16369, 16363, 16356, 16335, 16290, 16214, 16068, 15826, 15382, 14550, 13126, 10956, 8000, 4622, 2090, 973, 478, 249, 128, 75, 42, 19, 13, 7, 4, 0}, + { 16384, 16375, 16370, 16367, 16362, 16340, 16298, 16232, 16097, 15860, 15440, 14718, 13570, 11874, 9557, 6790, 4053, 2166, 1150, 622, 323, 179, 96, 53, 33, 17, 12, 0}, + { 16384, 16335, 16304, 16276, 16228, 16166, 16094, 15983, 15775, 15501, 15040, 14417, 13552, 12326, 10847, 9117, 7308, 5373, 3666, 2297, 1336, 807, 495, 313, 216, 152, 114, 0} + }, + { /* 32.0 kbs A */ + { 16384, 16351, 16333, 16303, 16254, 16163, 15993, 15681, 15080, 13987, 12109, 9465, 6588, 4160, 2488, 1480, 912, 589, 389, 266, 190, 131, 93, 68, 47, 34, 24, 0}, + { 16384, 16379, 16375, 16369, 16360, 16345, 16328, 16286, 16211, 16078, 15810, 15233, 14058, 11933, 8881, 5609, 2940, 1290, 558, 274, 150, 80, 47, 29, 17, 11, 6, 0}, + { 16384, 16382, 16380, 16377, 16370, 16358, 16337, 16300, 16224, 16088, 15811, 15233, 14112, 12019, 9061, 5723, 2780, 1121, 480, 239, 123, 69, 41, 22, 13, 8, 5, 0}, + { 16384, 16377, 16375, 16369, 16363, 16351, 16325, 16268, 16172, 16009, 15686, 15039, 13830, 11799, 8924, 5422, 2444, 960, 441, 220, 111, 63, 37, 22, 11, 6, 3, 0}, + { 16384, 16374, 16369, 16363, 16356, 16335, 16290, 16214, 16068, 15826, 15382, 14550, 13126, 10956, 8000, 4622, 2090, 973, 478, 249, 128, 75, 42, 19, 13, 7, 4, 0}, + { 16384, 16375, 16370, 16367, 16362, 16340, 16298, 16232, 16097, 15860, 15440, 14718, 13570, 11874, 9557, 6790, 4053, 2166, 1150, 622, 323, 179, 96, 53, 33, 17, 12, 0}, + { 16384, 16335, 16304, 16276, 16228, 16166, 16094, 15983, 15775, 15501, 15040, 14417, 13552, 12326, 10847, 9117, 7308, 5373, 3666, 2297, 1336, 807, 495, 313, 216, 152, 114, 0} + }, + { /* 48.0 kbs B */ + { 16384, 16334, 16310, 16285, 16254, 16204, 16128, 16031, 15903, 15697, 15380, 14820, 13857, 12267, 9878, 7099, 4509, 2576, 1478, 871, 531, 349, 230, 163, 111, 80, 62, 0}, + { 16384, 16337, 16327, 16307, 16278, 16239, 16178, 16092, 15947, 15719, 15286, 14428, 12833, 10246, 7123, 4088, 1896, 849, 481, 287, 190, 139, 94, 66, 52, 34, 24, 0}, + { 16384, 16352, 16341, 16329, 16312, 16295, 16265, 16223, 16151, 16026, 15825, 15437, 14645, 13089, 10612, 7364, 4077, 1783, 779, 444, 281, 192, 138, 93, 65, 43, 30, 0}, + { 16384, 16354, 16347, 16337, 16314, 16284, 16233, 16165, 16051, 15847, 15450, 14621, 13069, 10623, 7298, 3789, 1569, 727, 445, 302, 207, 143, 96, 59, 36, 18, 9, 0}, + { 16384, 16352, 16342, 16330, 16314, 16295, 16266, 16215, 16127, 15984, 15709, 15190, 14242, 12540, 9979, 6448, 3160, 1392, 752, 481, 344, 251, 169, 115, 73, 28, 8, 0}, + { 16384, 16340, 16320, 16302, 16272, 16257, 16220, 16135, 16011, 15784, 15370, 14688, 13423, 11457, 8721, 5529, 2736, 1375, 784, 525, 353, 263, 172, 113, 78, 26, 11, 0}, + { 16384, 16238, 16170, 16113, 16077, 16030, 16000, 15948, 15873, 15752, 15535, 15157, 14595, 13788, 12569, 10767, 8611, 6186, 4101, 2459, 1478, 881, 607, 385, 243, 168, 116, 0} + } +}; + +/* only needed for >= 48 kbs */ + +const unsigned short cf_se10_tab[IGF_SYMBOLS_IN_TABLE + 1] = +{ + 16384, 15493, 15154, 14810, 14331, 13701, 13086, 12403, 11585, 10923, 10293, 9631, 8943, 8385, 7760, 7182, 6593, 6009, 5540, 5082, 4571, 4133, 3711, 3299, 2887, 2460, 2043, 0 +}; + +const unsigned short cf_se11_tab[IGF_CTX_COUNT][IGF_CTX_COUNT][IGF_SYMBOLS_IN_TABLE + 1] = +{ + { + { 16384, 16313, 16312, 16241, 16206, 16099, 15957, 15386, 14601, 12852, 10282, 7534, 4964, 2966, 1824, 896, 504, 255, 113, 112, 41, 40, 39, 38, 37, 36, 1, 0}, + { 16384, 16383, 16382, 16381, 16380, 16379, 16378, 16207, 16206, 16205, 16120, 15949, 14663, 12777, 9947, 6860, 3773, 1972, 772, 430, 259, 174, 89, 4, 3, 2, 1, 0}, + { 16384, 16383, 16382, 16381, 16380, 16379, 16378, 16377, 16376, 16115, 15941, 14891, 12965, 11477, 8587, 5347, 3421, 1407, 620, 8, 7, 6, 5, 4, 3, 2, 1, 0}, + { 16384, 16383, 16382, 16381, 16380, 16379, 16378, 16254, 16253, 16004, 15005, 13756, 12006, 9256, 5755, 3755, 1755, 756, 132, 131, 130, 129, 5, 4, 3, 2, 1, 0}, + { 16384, 16383, 16382, 16381, 16380, 16379, 16378, 16377, 15964, 15550, 14929, 12856, 9954, 6430, 2906, 1456, 1042, 628, 214, 8, 7, 6, 5, 4, 3, 2, 1, 0}, + { 16384, 16383, 16382, 16381, 16380, 16379, 16378, 16087, 15503, 14334, 14333, 11994, 10240, 8193, 5268, 2929, 1760, 1176, 299, 298, 297, 296, 295, 294, 293, 2, 1, 0}, + { 16384, 16383, 16382, 16381, 16380, 16379, 16378, 16377, 14922, 13467, 10919, 9464, 7280, 6189, 3641, 2914, 2187, 1824, 1823, 1096, 369, 368, 367, 4, 3, 2, 1, 0} + }, + { + { 16384, 16383, 16382, 16381, 16380, 16379, 16378, 16377, 16238, 16237, 15678, 15399, 14840, 13441, 11341, 8681, 6161, 3781, 2522, 702, 283, 144, 5, 4, 3, 2, 1, 0}, + { 16384, 16383, 16382, 16381, 16380, 16379, 16378, 16377, 16376, 16375, 16374, 15693, 14671, 12625, 7507, 4778, 2390, 1368, 1028, 347, 7, 6, 5, 4, 3, 2, 1, 0}, + { 16384, 16383, 16382, 16381, 16380, 16379, 16378, 16377, 16376, 16375, 16374, 15595, 13776, 9877, 6498, 3639, 3120, 1561, 1042, 523, 265, 6, 5, 4, 3, 2, 1, 0}, + { 16384, 16383, 16382, 16381, 16380, 16379, 16378, 16377, 16376, 15709, 13704, 12702, 11032, 7355, 3010, 1340, 1007, 674, 341, 8, 7, 6, 5, 4, 3, 2, 1, 0}, + { 16384, 16383, 16382, 16381, 16380, 16379, 16378, 16377, 16376, 16375, 16374, 12816, 10683, 7125, 2854, 720, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0}, + { 16384, 16383, 16382, 16381, 16380, 16379, 16378, 16377, 16376, 16375, 12738, 12737, 10920, 9103, 5466, 1828, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0}, + { 16384, 16383, 16382, 16381, 16380, 15359, 15358, 14337, 14336, 14335, 14334, 14333, 10240, 7170, 5124, 2054, 1032, 1031, 1030, 1029, 7, 6, 5, 4, 3, 2, 1, 0} + }, + { + { 16384, 16383, 16382, 16107, 16106, 16105, 16104, 16103, 15966, 15965, 15690, 15140, 14315, 12939, 10324, 8122, 4956, 2479, 1654, 966, 691, 416, 141, 140, 3, 2, 1, 0}, + { 16384, 16383, 16382, 16381, 16380, 16379, 16378, 16377, 16376, 16375, 15320, 14265, 12945, 10568, 8984, 6343, 4230, 1853, 797, 270, 7, 6, 5, 4, 3, 2, 1, 0}, + { 16384, 16383, 16382, 16381, 16380, 16379, 16112, 16111, 16110, 15037, 14501, 12622, 11012, 7790, 5374, 3226, 1347, 542, 275, 274, 273, 6, 5, 4, 3, 2, 1, 0}, + { 16384, 16383, 16382, 16381, 16380, 16379, 16378, 16377, 16376, 16375, 15597, 14819, 12090, 7021, 4292, 1953, 1175, 787, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0}, + { 16384, 16383, 16382, 16381, 16380, 16379, 16378, 16377, 16376, 15935, 14165, 12838, 9297, 6641, 3985, 1772, 1331, 890, 449, 8, 7, 6, 5, 4, 3, 2, 1, 0}, + { 16384, 16383, 16382, 16381, 16380, 16379, 16378, 16377, 16376, 14740, 13923, 9010, 6555, 4100, 2464, 828, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0}, + { 16384, 16383, 16382, 16381, 16380, 16379, 16378, 16377, 16376, 13104, 13103, 8192, 4920, 1647, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0} + }, + { + { 16384, 16383, 16382, 16381, 16380, 16379, 16378, 16377, 16077, 16076, 16075, 15926, 15176, 14425, 10819, 7664, 5711, 2856, 1354, 754, 454, 154, 5, 4, 3, 2, 1, 0}, + { 16384, 16383, 16382, 16381, 16380, 16379, 16378, 16377, 16376, 16044, 16043, 14373, 12369, 10030, 7023, 5019, 1677, 676, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0}, + { 16384, 16383, 16382, 16381, 16380, 16379, 16378, 16077, 16076, 16075, 15470, 14258, 12743, 11531, 6375, 3040, 3039, 917, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0}, + { 16384, 16383, 16382, 16381, 16380, 16379, 16378, 16377, 16376, 16375, 15309, 13531, 11396, 7480, 3564, 1786, 364, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0}, + { 16384, 16383, 16382, 16381, 16380, 16379, 16378, 16377, 15833, 15289, 13652, 10377, 6556, 3827, 3283, 1646, 555, 554, 553, 552, 7, 6, 5, 4, 3, 2, 1, 0}, + { 16384, 16383, 16382, 16381, 16380, 16379, 16378, 14146, 13404, 13403, 13402, 10425, 7448, 3727, 2240, 2239, 752, 751, 750, 749, 7, 6, 5, 4, 3, 2, 1, 0}, + { 16384, 16383, 16382, 16381, 16380, 16379, 15562, 14745, 13928, 10653, 7378, 5742, 2467, 830, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0} + }, + { + { 16384, 16383, 16382, 16381, 16380, 16379, 16378, 16377, 16376, 16375, 16219, 15590, 14803, 13544, 11339, 9292, 6930, 4568, 2521, 1419, 790, 318, 161, 4, 3, 2, 1, 0}, + { 16384, 16383, 16382, 16381, 16380, 16379, 16378, 16377, 16376, 16014, 15652, 14925, 14198, 12743, 10196, 5464, 3645, 1826, 371, 8, 7, 6, 5, 4, 3, 2, 1, 0}, + { 16384, 16383, 16382, 16381, 16380, 16379, 16378, 16377, 16376, 16050, 15396, 15395, 12447, 10810, 8518, 4915, 2950, 1313, 659, 333, 7, 6, 5, 4, 3, 2, 1, 0}, + { 16384, 16383, 16382, 16381, 16380, 16379, 16378, 16377, 16376, 16375, 14792, 14001, 11096, 8455, 6079, 3174, 2119, 535, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0}, + { 16384, 16383, 16382, 16381, 16380, 16379, 16378, 15796, 15795, 15794, 15793, 11700, 8777, 6439, 4101, 1178, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0}, + { 16384, 16383, 16382, 16381, 15473, 15472, 15471, 14563, 13655, 12746, 10017, 7288, 6379, 6378, 4559, 1830, 1829, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0}, + { 16384, 16383, 16382, 16381, 16380, 16379, 16378, 16377, 15723, 15069, 13105, 9174, 7865, 3934, 3280, 1971, 1317, 663, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0} + }, + { + { 16384, 16383, 16382, 16381, 16232, 16231, 16230, 16229, 16228, 16227, 16078, 15628, 15329, 13977, 12325, 10222, 5413, 4212, 1959, 908, 7, 6, 5, 4, 3, 2, 1, 0}, + { 16384, 16383, 16382, 16381, 16380, 16379, 16378, 16377, 16376, 16109, 15842, 15841, 13694, 11815, 10205, 5640, 3493, 2151, 1347, 543, 542, 6, 5, 4, 3, 2, 1, 0}, + { 16384, 16383, 16382, 16381, 16380, 16379, 16378, 16377, 16376, 16168, 14699, 13650, 11761, 9452, 6093, 3784, 1685, 636, 427, 426, 425, 424, 423, 422, 421, 2, 1, 0}, + { 16384, 16383, 16382, 16381, 16380, 16379, 16378, 16377, 16376, 16122, 15611, 14332, 13053, 10238, 7423, 4608, 2561, 2050, 1027, 516, 515, 260, 259, 258, 257, 2, 1, 0}, + { 16384, 16383, 16382, 16381, 16380, 16379, 16378, 16377, 16376, 16375, 15207, 13649, 10531, 6632, 3514, 1176, 398, 397, 396, 395, 394, 393, 5, 4, 3, 2, 1, 0}, + { 16384, 16383, 16382, 16381, 16380, 16379, 16378, 16377, 15749, 15120, 12601, 10082, 8823, 6304, 3785, 3156, 1267, 638, 637, 636, 7, 6, 5, 4, 3, 2, 1, 0}, + { 16384, 16383, 15729, 15728, 15727, 15726, 15725, 15071, 14417, 12453, 10489, 8525, 5905, 1975, 1321, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0} + }, + { + { 16384, 16383, 16372, 16340, 16339, 16328, 16285, 16253, 16136, 15923, 15614, 14931, 13833, 12201, 10175, 7615, 5269, 3243, 2123, 1142, 673, 342, 182, 150, 86, 54, 11, 0}, + { 16384, 16383, 16366, 16349, 16332, 16331, 16314, 16245, 16244, 16141, 15813, 15451, 14105, 12672, 9910, 7113, 4472, 2590, 1071, 484, 294, 156, 53, 36, 19, 18, 1, 0}, + { 16384, 16383, 16382, 16369, 16355, 16341, 16271, 16117, 15921, 15627, 14772, 13089, 10929, 8334, 5487, 3299, 1644, 999, 424, 228, 88, 46, 18, 17, 16, 15, 14, 0}, + { 16384, 16367, 16366, 16365, 16364, 16363, 16259, 16173, 15809, 15028, 13951, 12214, 9278, 6203, 3719, 2052, 1079, 402, 194, 125, 56, 22, 21, 20, 3, 2, 1, 0}, + { 16384, 16383, 16360, 16359, 16358, 16357, 16356, 16333, 16332, 16143, 15954, 15434, 14227, 12262, 9540, 6652, 3882, 1988, 1207, 829, 427, 191, 73, 50, 49, 2, 1, 0}, + { 16384, 16383, 16382, 16381, 16380, 16296, 16254, 15748, 14862, 13427, 11189, 8487, 5278, 3252, 2028, 1099, 551, 340, 298, 214, 172, 88, 46, 45, 3, 2, 1, 0}, + { 16384, 16383, 16307, 16269, 16231, 16230, 16077, 15886, 15464, 14620, 13546, 11896, 9671, 7024, 4338, 2382, 1423, 809, 541, 311, 158, 43, 5, 4, 3, 2, 1, 0} + } +}; + +/**********************************************************************/ /** +igf settings table for each bitrate mode +**************************************************************************/ +/* possible ROMOPTIM: transFac not needed any more, can be deleted */ +const IGF_MODE igfMode[15] = +{ + /* sampleRate, frameLength, bitRate, igfMinFq, transFac, maxHopsize */ + { 16000, 320, 9600, 774, 1.25f, 4 }, /* 9.6kbs WB 0 */ + { 16000, 320, 13200, 774, 1.25f, 4 }, /* 13.2kbs WB RF 1 */ + { 32000, 640, 9600, 800, 1.25f, 2 }, /* 9.6kbs SWB 2 */ + { 32000, 640, 13200, 800, 1.25f, 4 }, /* 13.2kbs SWB 3 */ + { 32000, 640, 13200, 800, 1.25f, 2 }, /* 13.2kbs SWB RF 4 */ + { 32000, 640, 16400, 800, 1.25f, 4 }, /* 16.4kbs SWB 5 */ + { 32000, 640, 24400, 800, 1.25f, 4 }, /* 24.4kbs SWB 6 */ + { 32000, 640, 32000, 800, 1.25f, 4 }, /* 32.0kbs SWB 7 */ + { 32000, 640, 48000, 1600, 1.25f, 4 }, /* 48.0kbs SWB 8 */ + { 48000, 960, 16400, 800, 1.25f, 4 }, /* 16.4kbs FB 9 */ + { 48000, 960, 24400, 800, 1.25f, 2 }, /* 24.4kbs FB 10 */ + { 48000, 960, 32000, 800, 1.25f, 2 }, /* 32.0kbs FB 11 */ + { 48000, 960, 48000, 1600, 1.25f, 2 }, /* 48.0kbs FB 12 */ + { 48000, 960, 96000, 1600, 0.50f, 1 }, /* 96.0kbs FB 13 */ + { 48000, 960, 128000, 1600, 0.50f, 1 } /*128.0kbs FB 14 */ +}; + + +const int bwMode2fs[4] = { 8000, 16000, 32000, 48000 }; + + +const float normReciprocal[CHEAP_NORM_SIZE] = +{ + 0.0f, 1.0000000000f, 0.5000000000f, 0.3333333333f, 0.2500000000f, 0.2000000000f, 0.1666666667f, 0.1428571429f, 0.1250000000f, 0.1111111111f, 0.1000000000f, 0.0909090909f, 0.0833333333f, 0.0769230769f, 0.0714285714f, 0.0666666667f, 0.0625000000f, 0.0588235294f, 0.0555555556f, 0.0526315789f, 0.0500000000f, 0.0476190476f, 0.0454545455f, 0.0434782609f, 0.0416666667f, 0.0400000000f, 0.0384615385f, 0.0370370370f, 0.0357142857f, 0.0344827586f, 0.0333333333f, 0.0322580645f, 0.0312500000f, 0.0303030303f, 0.0294117647f, 0.0285714286f, 0.0277777778f, 0.0270270270f, 0.0263157895f, 0.0256410256f, 0.0250000000f, 0.0243902439f, 0.0238095238f, 0.0232558140f, 0.0227272727f, 0.0222222222f, 0.0217391304f, 0.0212765957f, 0.0208333333f, 0.0204081633f, 0.0200000000f, 0.0196078431f, 0.0192307692f, 0.0188679245f, 0.0185185185f, 0.0181818182f, 0.0178571429f, 0.0175438596f, 0.0172413793f, 0.0169491525f, 0.0166666667f, 0.0163934426f, 0.0161290323f, 0.0158730159f, 0.0156250000f, 0.0153846154f, 0.0151515152f, 0.0149253731f, 0.0147058824f, 0.0144927536f, 0.0142857143f, 0.0140845070f, 0.0138888889f, 0.0136986301f, 0.0135135135f, 0.0133333333f, 0.0131578947f, 0.0129870130f, 0.0128205128f, 0.0126582278f, 0.0125000000f, 0.0123456790f, 0.0121951220f, 0.0120481928f, 0.0119047619f, 0.0117647059f, 0.0116279070f, 0.0114942529f, 0.0113636364f, 0.0112359551f, 0.0111111111f, 0.0109890110f, 0.0108695652f, 0.0107526882f, 0.0106382979f, 0.0105263158f, 0.0104166667f, 0.0103092784f, 0.0102040816f, 0.0101010101f, 0.0100000000f, 0.0099009901f, 0.0098039216f, 0.0097087379f, 0.0096153846f, 0.0095238095f, 0.0094339623f, 0.0093457944f, 0.0092592593f, 0.0091743119f, 0.0090909091f, 0.0090090090f, 0.0089285714f, 0.0088495575f, 0.0087719298f, 0.0086956522f, 0.0086206897f, 0.0085470085f, 0.0084745763f, 0.0084033613f, 0.0083333333f, 0.0082644628f, 0.0081967213f, 0.0081300813f, 0.0080645161f, 0.0080000000f, 0.0079365079f, 0.0078740157f, 0.0078125000f, 0.0077519380f, 0.0076923077f, 0.0076335878f, 0.0075757576f, 0.0075187970f, 0.0074626866f, 0.0074074074f, 0.0073529412f, 0.0072992701f, 0.0072463768f, 0.0071942446f, 0.0071428571f, 0.0070921986f, 0.0070422535f, 0.0069930070f, 0.0069444444f, 0.0068965517f, 0.0068493151f, 0.0068027211f, 0.0067567568f, 0.0067114094f, 0.0066666667f, 0.0066225166f, 0.0065789474f, 0.0065359477f, 0.0064935065f, 0.0064516129f, 0.0064102564f, 0.0063694268f, 0.0063291139f, 0.0062893082f, 0.0062500000f +}; + +const float w1N8[30] = {0.998795f, -0.049068f, 0.995185f, -0.098017f, 0.989177f, -0.146730f, 0.980785f, -0.195090f, 0.970031f, -0.242980f, 0.956940f, -0.290285f, 0.941544f, -0.336890f, 0.923880f, -0.382683f, 0.903989f, -0.427555f, 0.881921f, -0.471397f, 0.857729f, -0.514103f, 0.831470f, -0.555570f, 0.803208f, -0.595699f, 0.773010f, -0.634393f, 0.740951f, -0.671559f}; +const float w2N8[30] = {0.995185f, -0.098017f, 0.980785f, -0.195090f, 0.956940f, -0.290285f, 0.923880f, -0.382683f, 0.881921f, -0.471397f, 0.831470f, -0.555570f, 0.773010f, -0.634393f, 0.707107f, -0.707107f, 0.634393f, -0.773010f, 0.555570f, -0.831470f, 0.471397f, -0.881921f, 0.382683f, -0.923880f, 0.290285f, -0.956940f, 0.195090f, -0.980785f, 0.098017f, -0.995185f}; +const float w3N8[30] = {0.989177f, -0.146730f, 0.956940f, -0.290285f, 0.903989f, -0.427555f, 0.831470f, -0.555570f, 0.740951f, -0.671559f, 0.634393f, -0.773010f, 0.514103f, -0.857729f, 0.382683f, -0.923880f, 0.242980f, -0.970031f, 0.098017f, -0.995185f, -0.049068f, -0.998795f, -0.195090f, -0.980785f, -0.336890f, -0.941544f, -0.471397f, -0.881921f, -0.595699f, -0.803208f}; +const float w4N8[30] = {0.980785f, -0.195090f, 0.923880f, -0.382683f, 0.831470f, -0.555570f, 0.707107f, -0.707107f, 0.555570f, -0.831470f, 0.382683f, -0.923880f, 0.195090f, -0.980785f, 0.000000f, -1.000000f, -0.195090f, -0.980785f, -0.382683f, -0.923880f, -0.555570f, -0.831470f, -0.707107f, -0.707107f, -0.831470f, -0.555570f, -0.923880f, -0.382683f, -0.980785f, -0.195090f}; +const float w5N8[30] = {0.970031f, -0.242980f, 0.881921f, -0.471397f, 0.740951f, -0.671559f, 0.555570f, -0.831470f, 0.336890f, -0.941544f, 0.098017f, -0.995185f, -0.146730f, -0.989177f, -0.382683f, -0.923880f, -0.595699f, -0.803208f, -0.773010f, -0.634393f, -0.903989f, -0.427555f, -0.980785f, -0.195090f, -0.998795f, 0.049068f, -0.956940f, 0.290285f, -0.857729f, 0.514103f}; +const float w6N8[30] = {0.956940f, -0.290285f, 0.831470f, -0.555570f, 0.634393f, -0.773010f, 0.382683f, -0.923880f, 0.098017f, -0.995185f, -0.195090f, -0.980785f, -0.471397f, -0.881921f, -0.707107f, -0.707107f, -0.881921f, -0.471397f, -0.980785f, -0.195090f, -0.995185f, 0.098017f, -0.923880f, 0.382683f, -0.773010f, 0.634393f, -0.555570f, 0.831470f, -0.290285f, 0.956940f}; +const float w7N8[30] = {0.941544f, -0.336890f, 0.773010f, -0.634393f, 0.514103f, -0.857729f, 0.195090f, -0.980785f, -0.146730f, -0.989177f, -0.471397f, -0.881921f, -0.740951f, -0.671559f, -0.923880f, -0.382683f, -0.998795f, -0.049068f, -0.956940f, 0.290285f, -0.803208f, 0.595699f, -0.555570f, 0.831470f, -0.242980f, 0.970031f, 0.098017f, 0.995185f, 0.427555f, 0.903989f}; +const float *w_a[7] = {w1N8, w2N8, w3N8, w4N8, w5N8, w6N8, w7N8}; + + +#define STC(x) WORD322WORD16(x) +#define STCP(a,b) { { STC(a), STC(b) } } + +const PWord16 SineTable512_fx[] = +{ + STCP(0x7fffffff, 0x00000000), STCP(0x7fffd886, 0x006487e3), STCP(0x7fff6216, 0x00c90f88), STCP(0x7ffe9cb2, 0x012d96b1), + STCP(0x7ffd885a, 0x01921d20), STCP(0x7ffc250f, 0x01f6a297), STCP(0x7ffa72d1, 0x025b26d7), STCP(0x7ff871a2, 0x02bfa9a4), + STCP(0x7ff62182, 0x03242abf), STCP(0x7ff38274, 0x0388a9ea), STCP(0x7ff09478, 0x03ed26e6), STCP(0x7fed5791, 0x0451a177), + STCP(0x7fe9cbc0, 0x04b6195d), STCP(0x7fe5f108, 0x051a8e5c), STCP(0x7fe1c76b, 0x057f0035), STCP(0x7fdd4eec, 0x05e36ea9), + STCP(0x7fd8878e, 0x0647d97c), STCP(0x7fd37153, 0x06ac406f), STCP(0x7fce0c3e, 0x0710a345), STCP(0x7fc85854, 0x077501be), + STCP(0x7fc25596, 0x07d95b9e), STCP(0x7fbc040a, 0x083db0a7), STCP(0x7fb563b3, 0x08a2009a), STCP(0x7fae7495, 0x09064b3a), + STCP(0x7fa736b4, 0x096a9049), STCP(0x7f9faa15, 0x09cecf89), STCP(0x7f97cebd, 0x0a3308bd), STCP(0x7f8fa4b0, 0x0a973ba5), + STCP(0x7f872bf3, 0x0afb6805), STCP(0x7f7e648c, 0x0b5f8d9f), STCP(0x7f754e80, 0x0bc3ac35), STCP(0x7f6be9d4, 0x0c27c389), + STCP(0x7f62368f, 0x0c8bd35e), STCP(0x7f5834b7, 0x0cefdb76), STCP(0x7f4de451, 0x0d53db92), STCP(0x7f434563, 0x0db7d376), + STCP(0x7f3857f6, 0x0e1bc2e4), STCP(0x7f2d1c0e, 0x0e7fa99e), STCP(0x7f2191b4, 0x0ee38766), STCP(0x7f15b8ee, 0x0f475bff), + STCP(0x7f0991c4, 0x0fab272b), STCP(0x7efd1c3c, 0x100ee8ad), STCP(0x7ef05860, 0x1072a048), STCP(0x7ee34636, 0x10d64dbd), + STCP(0x7ed5e5c6, 0x1139f0cf), STCP(0x7ec8371a, 0x119d8941), STCP(0x7eba3a39, 0x120116d5), STCP(0x7eabef2c, 0x1264994e), + STCP(0x7e9d55fc, 0x12c8106f), STCP(0x7e8e6eb2, 0x132b7bf9), STCP(0x7e7f3957, 0x138edbb1), STCP(0x7e6fb5f4, 0x13f22f58), + STCP(0x7e5fe493, 0x145576b1), STCP(0x7e4fc53e, 0x14b8b17f), STCP(0x7e3f57ff, 0x151bdf86), STCP(0x7e2e9cdf, 0x157f0086), + STCP(0x7e1d93ea, 0x15e21445), STCP(0x7e0c3d29, 0x16451a83), STCP(0x7dfa98a8, 0x16a81305), STCP(0x7de8a670, 0x170afd8d), + STCP(0x7dd6668f, 0x176dd9de), STCP(0x7dc3d90d, 0x17d0a7bc), STCP(0x7db0fdf8, 0x183366e9), STCP(0x7d9dd55a, 0x18961728), + STCP(0x7d8a5f40, 0x18f8b83c), STCP(0x7d769bb5, 0x195b49ea), STCP(0x7d628ac6, 0x19bdcbf3), STCP(0x7d4e2c7f, 0x1a203e1b), + STCP(0x7d3980ec, 0x1a82a026), STCP(0x7d24881b, 0x1ae4f1d6), STCP(0x7d0f4218, 0x1b4732ef), STCP(0x7cf9aef0, 0x1ba96335), + STCP(0x7ce3ceb2, 0x1c0b826a), STCP(0x7ccda169, 0x1c6d9053), STCP(0x7cb72724, 0x1ccf8cb3), STCP(0x7ca05ff1, 0x1d31774d), + STCP(0x7c894bde, 0x1d934fe5), STCP(0x7c71eaf9, 0x1df5163f), STCP(0x7c5a3d50, 0x1e56ca1e), STCP(0x7c4242f2, 0x1eb86b46), + STCP(0x7c29fbee, 0x1f19f97b), STCP(0x7c116853, 0x1f7b7481), STCP(0x7bf88830, 0x1fdcdc1b), STCP(0x7bdf5b94, 0x203e300d), + STCP(0x7bc5e290, 0x209f701c), STCP(0x7bac1d31, 0x21009c0c), STCP(0x7b920b89, 0x2161b3a0), STCP(0x7b77ada8, 0x21c2b69c), + STCP(0x7b5d039e, 0x2223a4c5), STCP(0x7b420d7a, 0x22847de0), STCP(0x7b26cb4f, 0x22e541af), STCP(0x7b0b3d2c, 0x2345eff8), + STCP(0x7aef6323, 0x23a6887f), STCP(0x7ad33d45, 0x24070b08), STCP(0x7ab6cba4, 0x24677758), STCP(0x7a9a0e50, 0x24c7cd33), + STCP(0x7a7d055b, 0x25280c5e), STCP(0x7a5fb0d8, 0x2588349d), STCP(0x7a4210d8, 0x25e845b6), STCP(0x7a24256f, 0x26483f6c), + STCP(0x7a05eead, 0x26a82186), STCP(0x79e76ca7, 0x2707ebc7), STCP(0x79c89f6e, 0x27679df4), STCP(0x79a98715, 0x27c737d3), + STCP(0x798a23b1, 0x2826b928), STCP(0x796a7554, 0x288621b9), STCP(0x794a7c12, 0x28e5714b), STCP(0x792a37fe, 0x2944a7a2), + STCP(0x7909a92d, 0x29a3c485), STCP(0x78e8cfb2, 0x2a02c7b8), STCP(0x78c7aba2, 0x2a61b101), STCP(0x78a63d11, 0x2ac08026), + STCP(0x78848414, 0x2b1f34eb), STCP(0x786280bf, 0x2b7dcf17), STCP(0x78403329, 0x2bdc4e6f), STCP(0x781d9b65, 0x2c3ab2b9), + STCP(0x77fab989, 0x2c98fbba), STCP(0x77d78daa, 0x2cf72939), STCP(0x77b417df, 0x2d553afc), STCP(0x7790583e, 0x2db330c7), + STCP(0x776c4edb, 0x2e110a62), STCP(0x7747fbce, 0x2e6ec792), STCP(0x77235f2d, 0x2ecc681e), STCP(0x76fe790e, 0x2f29ebcc), + STCP(0x76d94989, 0x2f875262), STCP(0x76b3d0b4, 0x2fe49ba7), STCP(0x768e0ea6, 0x3041c761), STCP(0x76680376, 0x309ed556), + STCP(0x7641af3d, 0x30fbc54d), STCP(0x761b1211, 0x3158970e), STCP(0x75f42c0b, 0x31b54a5e), STCP(0x75ccfd42, 0x3211df04), + STCP(0x75a585cf, 0x326e54c7), STCP(0x757dc5ca, 0x32caab6f), STCP(0x7555bd4c, 0x3326e2c3), STCP(0x752d6c6c, 0x3382fa88), + STCP(0x7504d345, 0x33def287), STCP(0x74dbf1ef, 0x343aca87), STCP(0x74b2c884, 0x34968250), STCP(0x7489571c, 0x34f219a8), + STCP(0x745f9dd1, 0x354d9057), STCP(0x74359cbd, 0x35a8e625), STCP(0x740b53fb, 0x36041ad9), STCP(0x73e0c3a3, 0x365f2e3b), + STCP(0x73b5ebd1, 0x36ba2014), STCP(0x738acc9e, 0x3714f02a), STCP(0x735f6626, 0x376f9e46), STCP(0x7333b883, 0x37ca2a30), + STCP(0x7307c3d0, 0x382493b0), STCP(0x72db8828, 0x387eda8e), STCP(0x72af05a7, 0x38d8fe93), STCP(0x72823c67, 0x3932ff87), + STCP(0x72552c85, 0x398cdd32), STCP(0x7227d61c, 0x39e6975e), STCP(0x71fa3949, 0x3a402dd2), STCP(0x71cc5626, 0x3a99a057), + STCP(0x719e2cd2, 0x3af2eeb7), STCP(0x716fbd68, 0x3b4c18ba), STCP(0x71410805, 0x3ba51e29), STCP(0x71120cc5, 0x3bfdfecd), + STCP(0x70e2cbc6, 0x3c56ba70), STCP(0x70b34525, 0x3caf50da), STCP(0x708378ff, 0x3d07c1d6), STCP(0x70536771, 0x3d600d2c), + STCP(0x7023109a, 0x3db832a6), STCP(0x6ff27497, 0x3e10320d), STCP(0x6fc19385, 0x3e680b2c), STCP(0x6f906d84, 0x3ebfbdcd), + STCP(0x6f5f02b2, 0x3f1749b8), STCP(0x6f2d532c, 0x3f6eaeb8), STCP(0x6efb5f12, 0x3fc5ec98), STCP(0x6ec92683, 0x401d0321), + STCP(0x6e96a99d, 0x4073f21d), STCP(0x6e63e87f, 0x40cab958), STCP(0x6e30e34a, 0x4121589b), STCP(0x6dfd9a1c, 0x4177cfb1), + STCP(0x6dca0d14, 0x41ce1e65), STCP(0x6d963c54, 0x42244481), STCP(0x6d6227fa, 0x427a41d0), STCP(0x6d2dd027, 0x42d0161e), + STCP(0x6cf934fc, 0x4325c135), STCP(0x6cc45698, 0x437b42e1), STCP(0x6c8f351c, 0x43d09aed), STCP(0x6c59d0a9, 0x4425c923), + STCP(0x6c242960, 0x447acd50), STCP(0x6bee3f62, 0x44cfa740), STCP(0x6bb812d1, 0x452456bd), STCP(0x6b81a3cd, 0x4578db93), + STCP(0x6b4af279, 0x45cd358f), STCP(0x6b13fef5, 0x4621647d), STCP(0x6adcc964, 0x46756828), STCP(0x6aa551e9, 0x46c9405c), + STCP(0x6a6d98a4, 0x471cece7), STCP(0x6a359db9, 0x47706d93), STCP(0x69fd614a, 0x47c3c22f), STCP(0x69c4e37a, 0x4816ea86), + STCP(0x698c246c, 0x4869e665), STCP(0x69532442, 0x48bcb599), STCP(0x6919e320, 0x490f57ee), STCP(0x68e06129, 0x4961cd33), + STCP(0x68a69e81, 0x49b41533), STCP(0x686c9b4b, 0x4a062fbd), STCP(0x683257ab, 0x4a581c9e), STCP(0x67f7d3c5, 0x4aa9dba2), + STCP(0x67bd0fbd, 0x4afb6c98), STCP(0x67820bb7, 0x4b4ccf4d), STCP(0x6746c7d8, 0x4b9e0390), STCP(0x670b4444, 0x4bef092d), + STCP(0x66cf8120, 0x4c3fdff4), STCP(0x66937e91, 0x4c9087b1), STCP(0x66573cbb, 0x4ce10034), STCP(0x661abbc5, 0x4d31494b), + STCP(0x65ddfbd3, 0x4d8162c4), STCP(0x65a0fd0b, 0x4dd14c6e), STCP(0x6563bf92, 0x4e210617), STCP(0x6526438f, 0x4e708f8f), + STCP(0x64e88926, 0x4ebfe8a5), STCP(0x64aa907f, 0x4f0f1126), STCP(0x646c59bf, 0x4f5e08e3), STCP(0x642de50d, 0x4faccfab), + STCP(0x63ef3290, 0x4ffb654d), STCP(0x63b0426d, 0x5049c999), STCP(0x637114cc, 0x5097fc5e), STCP(0x6331a9d4, 0x50e5fd6d), + STCP(0x62f201ac, 0x5133cc94), STCP(0x62b21c7b, 0x518169a5), STCP(0x6271fa69, 0x51ced46e), STCP(0x62319b9d, 0x521c0cc2), + STCP(0x61f1003f, 0x5269126e), STCP(0x61b02876, 0x52b5e546), STCP(0x616f146c, 0x53028518), STCP(0x612dc447, 0x534ef1b5), + STCP(0x60ec3830, 0x539b2af0), STCP(0x60aa7050, 0x53e73097), STCP(0x60686ccf, 0x5433027d), STCP(0x60262dd6, 0x547ea073), + STCP(0x5fe3b38d, 0x54ca0a4b), STCP(0x5fa0fe1f, 0x55153fd4), STCP(0x5f5e0db3, 0x556040e2), STCP(0x5f1ae274, 0x55ab0d46), + STCP(0x5ed77c8a, 0x55f5a4d2), STCP(0x5e93dc1f, 0x56400758), STCP(0x5e50015d, 0x568a34a9), STCP(0x5e0bec6e, 0x56d42c99), + STCP(0x5dc79d7c, 0x571deefa), STCP(0x5d8314b1, 0x57677b9d), STCP(0x5d3e5237, 0x57b0d256), STCP(0x5cf95638, 0x57f9f2f8), + STCP(0x5cb420e0, 0x5842dd54), STCP(0x5c6eb258, 0x588b9140), STCP(0x5c290acc, 0x58d40e8c), STCP(0x5be32a67, 0x591c550e), + STCP(0x5b9d1154, 0x59646498), STCP(0x5b56bfbd, 0x59ac3cfd), STCP(0x5b1035cf, 0x59f3de12), STCP(0x5ac973b5, 0x5a3b47ab), + STCP(0x5a82799a, 0x5a82799a) +}; + +/** + * \brief Lookup-Table for binary logarithm + */ +const Word16 ldCoeff[7] = +{ + -32768, -16384, -10923, -8192, -6554, -5461, -4681 + /* -4096, -3641, -3277 */ +}; + +/** + \brief Lookup-Table for binary power algorithm + + This table is used for lookup 2^x with + x in range [0...1.0[ in steps of 1/32 +*/ +const UWord32 exp2_tab_long[32] = +{ + 0x40000000,0x4166C34C,0x42D561B4,0x444C0740, + 0x45CAE0F2,0x47521CC6,0x48E1E9BA,0x4A7A77D4, + 0x4C1BF829,0x4DC69CDD,0x4F7A9930,0x51382182, + 0x52FF6B55,0x54D0AD5A,0x56AC1F75,0x5891FAC1, + 0x5A82799A,0x5C7DD7A4,0x5E8451D0,0x60962665, + 0x62B39509,0x64DCDEC3,0x6712460B,0x69540EC9, + 0x6BA27E65,0x6DFDDBCC,0x70666F76,0x72DC8374, + 0x75606374,0x77F25CCE,0x7A92BE8B,0x7D41D96E +}; + +/** + \brief Lookup-Table for binary power algorithm + + This table is used for lookup 2^x with + x in range [0...1/32[ in steps of 1/1024 +*/ +const UWord32 exp2w_tab_long[32] = +{ + 0x40000000,0x400B1818,0x4016321B,0x40214E0C, + 0x402C6BE9,0x40378BB4,0x4042AD6D,0x404DD113, + 0x4058F6A8,0x40641E2B,0x406F479E,0x407A7300, + 0x4085A051,0x4090CF92,0x409C00C4,0x40A733E6, + 0x40B268FA,0x40BD9FFF,0x40C8D8F5,0x40D413DD, + 0x40DF50B8,0x40EA8F86,0x40F5D046,0x410112FA, + 0x410C57A2,0x41179E3D,0x4122E6CD,0x412E3152, + 0x41397DCC,0x4144CC3B,0x41501CA0,0x415B6EFB +}; + +/** + \brief Lookup-Table for binary power algorithm + + This table is used for lookup 2^x with + x in range [0...1/1024[ in steps of 1/32768 +*/ +const UWord32 exp2x_tab_long[32] = +{ + 0x40000000,0x400058B9,0x4000B173,0x40010A2D, + 0x400162E8,0x4001BBA3,0x4002145F,0x40026D1B, + 0x4002C5D8,0x40031E95,0x40037752,0x4003D011, + 0x400428CF,0x4004818E,0x4004DA4E,0x4005330E, + 0x40058BCE,0x4005E48F,0x40063D51,0x40069613, + 0x4006EED5,0x40074798,0x4007A05B,0x4007F91F, + 0x400851E4,0x4008AAA8,0x4009036E,0x40095C33, + 0x4009B4FA,0x400A0DC0,0x400A6688,0x400ABF4F +}; + +/* square root tables */ +const Word32 SqrtTable[32] = /* Q31 */ +{ + 0x5A82D429, 0x5BEA10FE, 0x5D4BE6E5, 0x5EA89270, 0x60004BE2, 0x615347A1, 0x62A1B68C, 0x63EBC651, + 0x6531A1B5, 0x667370D4, 0x67B1595F, 0x68EB7EC8, 0x6A220277, 0x6B5503F0, 0x6C84A0F9, 0x6DB0F5BD, + 0x6EDA1CE9, 0x70002FC7, 0x7123465A, 0x72437773, 0x7360D8C5, 0x747B7EFA, 0x75937DC4, 0x76A8E7EB, + 0x77BBCF60, 0x78CC4545, 0x79DA5A00, 0x7AE61D3E, 0x7BEF9E07, 0x7CF6EAC2, 0x7DFC113F, 0x7EFF1EC0 +}; + +const Word16 SqrtDiffTable[32] = /* Q21 */ +{ + 0x59CF, 0x5875, 0x572B, 0x55EE, 0x54BF, 0x539C, 0x5284, 0x5177, + 0x5074, 0x4F7A, 0x4E89, 0x4DA1, 0x4CC0, 0x4BE7, 0x4B15, 0x4A4A, + 0x4985, 0x48C6, 0x480C, 0x4758, 0x46AA, 0x4600, 0x455B, 0x44BA, + 0x441D, 0x4385, 0x42F1, 0x4260, 0x41D3, 0x414A, 0x40C3, 0x4040 +}; + + +const Word32 ISqrtTable[32] = /* Q31 */ +{ + 0x7FFE7F85, 0x7E0A4E25, 0x7C2C56C7, 0x7A63002C, 0x78ACD922, 0x7708939D, 0x75750088, 0x73F10C2D, + 0x727BBB1A, 0x71142774, 0x6FB97EA5, 0x6E6AFF54, 0x6D27F79D, 0x6BEFC388, 0x6AC1CBA4, 0x699D83DA, + 0x68826A53, 0x6770068E, 0x6665E882, 0x6563A7DF, 0x6468E364, 0x63754043, 0x62886999, 0x61A20FEE, + 0x60C1E8C8, 0x5FE7AE45, 0x5F131EBE, 0x5E43FC76, 0x5D7A0D4F, 0x5CB51A81, 0x5BF4F061, 0x5B395E26 +}; + +const Word16 ISqrtDiffTable[32] = /* Q21 */ +{ + 0x7D0C, 0x777E, 0x7256, 0x6D8A, 0x6911, 0x64E5, 0x60FD, 0x5D54, + 0x59E5, 0x56AA, 0x53A0, 0x50C2, 0x4E0D, 0x4B7E, 0x4912, 0x46C6, + 0x4499, 0x4288, 0x4090, 0x3EB1, 0x3CE9, 0x3B36, 0x3996, 0x380A, + 0x368F, 0x3524, 0x33C9, 0x327C, 0x313D, 0x300B, 0x2EE5, 0x2DCA +}; + +/* 1/x tables */ +const Word32 InvTable[32] = /* Q31 */ +{ + 0x7FFBFE40, 0x7C1B608E, 0x78752176, 0x750440BA, 0x71C44C49, 0x6EB14D0A, 0x6BC7B6B4, 0x69045A19, + 0x6664598A, 0x63E51EE2, 0x61845308, 0x5F3FD698, 0x5D15BB8E, 0x5B043FD0, 0x5909C861, 0x5724DD3C, + 0x555425B2, 0x53966532, 0x51EA787F, 0x504F5331, 0x4EC3FD84, 0x4D479267, 0x4BD93DBE, 0x4A783ADC, + 0x4923D31D, 0x47DB5CAE, 0x469E3974, 0x456BD608, 0x4443A8D9, 0x43253159, 0x420FF746, 0x41038A01 +}; + +const Word16 InvDiffTable[32] = /* Q20 */ +{ + 0x7C14, 0x74C8, 0x6E1C, 0x67FF, 0x6260, 0x5D33, 0x586C, 0x5400, + 0x4FE7, 0x4C19, 0x4890, 0x4543, 0x422F, 0x3F4F, 0x3C9D, 0x3A17, + 0x37B8, 0x357E, 0x3365, 0x316B, 0x2F8D, 0x2DCB, 0x2C20, 0x2A8D, + 0x290F, 0x27A4, 0x264C, 0x2506, 0x23CF, 0x22A7, 0x218E, 0x2081 +}; + +/* ACELP pulse coding */ +const int low_len[10] = { 0, 0, 8, 5, 7,11,13,15,16,16}; +const int low_mask[10] = { 0, 0, 255,31,127,2047,8191,32767,65535,65535}; +const int indx_fact[10] = { 0, 0,2,172,345,140,190,223,463,1732}; +const int index_len[3] = { 0, 5, 9 }; +const int index_mask_ACELP[3] = { 0, 31, 511 }; diff --git a/src/libs/libevs/lib_com/rom_com.h b/src/libs/libevs/lib_com/rom_com.h new file mode 100644 index 00000000..91505f84 --- /dev/null +++ b/src/libs/libevs/lib_com/rom_com.h @@ -0,0 +1,1230 @@ +/*==================================================================================== + EVS Codec 3GPP TS26.443 Nov 13, 2018. Version 12.11.0 / 13.7.0 / 14.3.0 / 15.1.0 + ====================================================================================*/ + +#ifndef ROM_COM_H +#define ROM_COM_H + +#include +#include "options.h" +#include "stat_enc.h" +#include "stat_dec.h" +#include "stl.h" +#include "basop_util.h" + +typedef struct +{ + int fin; /* input frequency */ + int fout; /* output frequency */ + short fac_num; /* numerator of resampling factor */ + const float *filter; /* resampling filter coefficients */ + short filt_len; /* number of filter coeff. */ + unsigned short flags; /* flags from config. table */ +} Resampling_cfg; + +typedef struct +{ + short bands; + short bw; + const short *band_width; + Word32 L_qint; + Word16 eref_fx; + Word16 bit_alloc_weight_fx; + short gqlevs; + short Ngq; + short p2a_bands; + float p2a_th; + float pd_thresh; + float ld_slope; + float ni_coef; + float ni_pd_th; +} Xcore_Config; + +/*-----------------------------------------------------------------* + * Table of bitrates + *-----------------------------------------------------------------*/ + +extern const long brate_tbl[SIZE_BRATE_TBL]; +extern const long acelp_sig_tbl[MAX_ACELP_SIG]; + +/*-----------------------------------------------------------------* + * Bit-allocation tables + *-----------------------------------------------------------------*/ + +extern const short LSF_bits_tbl[]; /* Bit allocation table for end-frame ISF quantizer */ +extern const short mid_LSF_bits_tbl[]; /* Bit allocation table for mid-frame ISF quantizer */ +extern const short Es_pred_bits_tbl[]; /* Bit allocation table for scaled innovation energy prediction */ +extern const short gain_bits_tbl[]; /* Bit allocation table for gain quantizer */ +extern const short ACB_bits_tbl[]; /* Bit allocation table for adaptive codebook (pitch) */ +extern const short FCB_bits_tbl[]; /* Bit allocation table for algebraic (fixed) codebook (innovation) */ +extern const short reserved_bits_tbl[]; /* Bit allocation table for reseved bits */ + +extern const short ACB_bits_16kHz_tbl[]; /* Bit allocation table for adaptive codebook (pitch) @16kHz */ +extern const short FCB_bits_16kHz_tbl[]; /* Bit allocation table for algebraic (fixed) codebook (innovation) @16kHz */ +extern const short gain_bits_16kHz_tbl[]; /* Bit allocation table for gain quantizer @16kHz */ +extern const short AVQ_bits_16kHz_tbl[]; /* Bit allocation table for AVQ bits @16kHz ACELP, active segments */ + +extern const long unsigned pulsestostates[17][9]; /* Number of states for any combination of pulses in any combination of vector length */ + +extern const unsigned char ACELP_NRG_MODE[RATE_MODE_MAX][BANDWIDTH_MODE_MAX][ACELP_MODE_MAX+RF_MODE_MAX]; +extern const unsigned char ACELP_NRG_BITS[3]; + +extern const unsigned char ACELP_LTP_MODE[RATE_MODE_MAX][BANDWIDTH_MODE_MAX][ACELP_MODE_MAX+RF_MODE_MAX]; +extern const unsigned char ACELP_LTP_BITS[RATE_MODE_MAX][BANDWIDTH_MODE_MAX][ACELP_MODE_MAX+RF_MODE_MAX]; +extern const unsigned char ACELP_LTP_BITS_SFR[8+RF_MODE_MAX][5]; + +extern const unsigned char ACELP_LTF_MODE[RATE_MODE_MAX][BANDWIDTH_MODE_MAX][ACELP_MODE_MAX+RF_MODE_MAX]; +extern const unsigned char ACELP_LTF_BITS[4]; + +extern const unsigned char ACELP_GAINS_MODE[RATE_MODE_MAX][BANDWIDTH_MODE_MAX][ACELP_MODE_MAX+RF_MODE_MAX]; +extern const unsigned char ACELP_GAINS_BITS[10]; + +extern const unsigned char ACELP_BPF_MODE[RATE_MODE_MAX][BANDWIDTH_MODE_MAX][ACELP_MODE_MAX+RF_MODE_MAX]; +extern const unsigned char ACELP_BPF_BITS[3]; + + +/*----------------------------------------------------------------------------------* + * Pre-processing + *----------------------------------------------------------------------------------*/ + +extern const float inv_tbl[]; /* Table of 1/x values */ + +extern const Resampling_cfg resampling_cfg_tbl[]; /* table of resampling configurations */ +extern const FrameSizeParams FrameSizeConfig[FRAME_SIZE_NB]; + +extern const float h_high[]; /* HP filter for filtering random part of excitation in FEC */ +extern const float crit_bands[]; /* Table of critical bands */ +extern const int pow2[]; /* Table with power of 2 values */ +extern const float sincos_t[]; /* FFT - sinus and cosinus tables */ +extern const float sincos_t_ext[]; +extern const float sincos_t_rad3[]; +extern const short fft256_read_indexes[]; /* FFT */ +extern const float inter4_2[]; /* 1/4 resolution interpolation filter */ +extern const float LP_assym_window[]; /* Assymetric window for LP analysis @12.8kHz */ +extern const float LP_assym_window_16k[]; /* Assymetric window for LP analysis @16kHz */ +extern const float hamcos_window[]; /* Hamming-Cosinus window */ +extern const float grid50[]; /* Table of grid points for evaluating Chebyshev polynomials */ +extern const float grid40[]; /* Table of grid points for evaluating Chebyshev polynomials */ +extern const float grid100[]; /* Table of 100 grid points for evaluating Chebyshev polynomials */ + +extern const float wind_sss[LEN_WIN_SSS]; /* window for modify_sf ana */ +extern const float filter5_39s320_120[]; /* LP FIR filter for 8kHz signal resampling */ + +extern const float lag_window_8k[17]; +extern const float lag_window_12k8[][17]; +extern const float lag_window_16k[][17]; +extern const float lag_window_25k6[][17]; +extern const float lag_window_32k[][17]; +extern const float lag_window_48k[17]; + +extern const float interpol_frac_12k8[]; /* LPC interpolation coefficients */ +extern const float interpol_isp_amr_wb[]; /* LPC interpolation coefficients for AMR-WB interoperable mode */ +extern const float interpol_frac_16k[]; /* LPC interpolation coefficients @ 16kHz */ +extern const float interpol_frac_mid[]; /* LPC interpolation coefficients with mid-ISFs */ +extern const float interpol_frac_mid_16k[]; /* LPC interpolation coefficients with mid-ISFs @ 16kHz */ +extern const float interpol_frac_mid_relaxprev_12k8[]; /* LPC interpolation coefficients with mid-ISFs @ 16kHz - relaxed prev frame interp */ +extern const float interpol_frac_mid_FEC[]; /* LPC interpolation coefficients with mid-ISFs - FEC */ +extern const float interpol_frac_mid_relaxprev_16k[]; /* LPC interpolation coefficients with mid-ISFs @ 16kHz - relaxed prev frame interp */ +extern const float interpol_frac_mid_16k_FEC[]; /* LPC interpolation coefficients with mid-ISFs @ 16kHz - FEC */ +extern const float interpol_frac_mid_relaxprev_pred_12k8[]; +extern const float interpol_frac_mid_relaxprev_pred_16k[]; + +extern const float inter6_2[PIT_FIR_SIZE6_2]; +extern const Float32 inter4_2tcx2[4][4]; +extern const Float32 inter6_2tcx2[6][4]; +typedef struct TCX_LTP_FILTER +{ + const float *filt; + int length; +} TCX_LTP_FILTER; +extern const TCX_LTP_FILTER tcxLtpFilters[12]; + +extern const float gain_qua_mless_7b[]; /* Gain quantization - gain quantization table */ +extern const float gain_qua_mless_6b[]; /* Gain quantization - gain quantization table */ +extern const float gain_qua_mless_5b[]; /* Gain quantization - gain quantization table */ +extern const float pred_gain[]; /* Gain quantization - MA predicition coefficients for gain quantizer */ +extern const float t_qua_gain6b[]; /* Gain quantization - gain quantization table for AMR-WB interoperable mode */ +extern const float t_qua_gain7b[]; /* Gain quantization - gain quantization table for AMR-WB interoperable mode */ +extern const float Es_pred_qua_5b[]; /* Gain quantization - quantization table for scaled innovation energy prediciton */ +extern const float Es_pred_qua_4b[]; /* Gain quantization - quantization table for scaled innovation energy prediciton */ +extern const float Es_pred_qua_3b[]; /* Gain quantization - quantization table for scaled innovation energy prediciton */ +extern const float Es_pred_qua_4b_no_ltp[]; /* Gain quantization - quantization table for scaled innovation energy prediciton */ + +extern const float b_1sfr[]; /* Gain quantization - gain estimation constants for gain quantizer at 7.2 and 8.0 kbps */ +extern const float b_2sfr[]; /* Gain quantization - gain estimation constants for gain quantizer at 7.2 and 8.0 kbps */ +extern const float b_3sfr[]; /* Gain quantization - gain estimation constants for gain quantizer at 7.2 and 8.0 kbps */ +extern const float b_4sfr[]; /* Gain quantization - gain estimation constants for gain quantizer at 7.2 and 8.0 kbps */ + +extern const float gp_gamma_1sfr_8b[]; /* Gain quantization - gain quantization table for gain quantizer at 7.2 and 8.0 kbps */ +extern const float gp_gamma_2sfr_8b[]; /* Gain quantization - gain quantization table for gain quantizer at 7.2 and 8.0 kbps */ +extern const float gp_gamma_3sfr_8b[]; /* Gain quantization - gain quantization table for gain quantizer at 7.2 and 8.0 kbps */ +extern const float gp_gamma_4sfr_8b[]; /* Gain quantization - gain quantization table for gain quantizer at 7.2 and 8.0 kbps */ + +extern const float gp_gamma_1sfr_7b[]; /* Gain quantization - gain quantization table for gain quantizer at 7.2 and 8.0 kbps */ +extern const float gp_gamma_2sfr_7b[]; /* Gain quantization - gain quantization table for gain quantizer at 7.2 and 8.0 kbps */ +extern const float gp_gamma_3sfr_7b[]; /* Gain quantization - gain quantization table for gain quantizer at 7.2 and 8.0 kbps */ +extern const float gp_gamma_4sfr_7b[]; /* Gain quantization - gain quantization table for gain quantizer at 7.2 and 8.0 kbps */ + +extern const float gp_gamma_1sfr_7b[]; /* Gain quantization - gain quantization table for gain quantizer at 7.2 and 8.0 kbps */ +extern const float gp_gamma_2sfr_7b[]; /* Gain quantization - gain quantization table for gain quantizer at 7.2 and 8.0 kbps */ +extern const float gp_gamma_3sfr_7b[]; /* Gain quantization - gain quantization table for gain quantizer at 7.2 and 8.0 kbps */ +extern const float gp_gamma_4sfr_7b[]; /* Gain quantization - gain quantization table for gain quantizer at 7.2 and 8.0 kbps */ + +extern const float gp_gamma_1sfr_6b[]; /* Gain quantization - gain quantization table for gain quantizer at 7.2 and 8.0 kbps */ +extern const float gp_gamma_2sfr_6b[]; /* Gain quantization - gain quantization table for gain quantizer at 7.2 and 8.0 kbps */ +extern const float gp_gamma_3sfr_6b[]; /* Gain quantization - gain quantization table for gain quantizer at 7.2 and 8.0 kbps */ +extern const float gp_gamma_4sfr_6b[]; /* Gain quantization - gain quantization table for gain quantizer at 7.2 and 8.0 kbps */ + +extern const short E_ROM_qua_gain5b_const[]; +extern const short E_ROM_qua_gain6b_const[]; +extern const short E_ROM_qua_gain7b_const[]; + +extern const float gain_qua_mless[]; + +extern const float tbl_gain_code_tc[]; /* TC - code gain quantization table */ +extern const float tbl_gain_trans_tc[]; /* TC - gain quantization table for g_trans */ +extern const float glottal_cdbk[]; /* TC - table of prototype glottal impulses */ + +extern const int PI_select_table[23][8]; /* selection table for Pulse indexing */ +extern const int PI_offset[8][8]; /* offset table for Pulse indexing */ +extern const short PI_factor[]; /* EVS_PI factor table for Pulse indexing */ + +extern const float deem_tab[]; /* HF BWE - de-emphasis coefficients */ +extern const float filt_hp[]; +extern const float exp_tab_p[]; /* HF BWE - Table of values exp(-j*w*i) */ +extern const float exp_tab_q[]; /* HF BWE - Table of values exp(-j*w*i) */ +extern const float HP_gain[]; /* HF BWE - quantization table for 23.85 */ +extern const float fir_6k_8k[]; /* HF BWE - band-pass filter coefficients */ + +extern const float b_hp400[]; /* HF (6-7kHz) BWE - 400Hz HP filter coefficients */ +extern const float a_hp400[]; /* HF (6-7kHz) BWE - 400Hz HP filter coefficients */ +extern const float fir_6k_7k[]; /* HF (6-7kHz) BWE - 6.0 - 7.0 kHz BP filter coefficients */ + +extern const float low_H[]; /* Enhacer - 2.0 - 6.4 kHz impulse response with phase dispersion */ +extern const float mid_H[]; /* Enhancer - 3.2 - 6.4 kHz impulse response with phase dispersion */ + +extern const float filt_lp[1 + L_FILT]; +extern const float filt_lp_16kHz[1+L_FILT16k]; + +extern const float tab_hup_l[SIZ_TAB_HUP_L]; /* NB post-filter */ +extern const float tab_hup_s[SIZ_TAB_HUP_S]; /* NB post-filter */ + +extern const float edct_table_80[]; /* EDCT */ +extern const float edct_table_120[]; /* EDCT */ +extern const float edct_table_320[]; /* EDCT */ +extern const float edct_table_480[]; /* EDCT */ +extern const float edct_table_128[]; /* EDCT */ +extern const float edct_table_160[]; /* EDCT */ +extern const float edct_table_40[]; /* EDCT */ +extern const float edct_table_20[]; /* EDCT */ +extern const float edct_table_64[]; +extern const float edct_table_100[]; /* EDCT */ +extern const float edct_table_200[]; +extern const float edct_table_240[]; +extern const float edct_table_256[]; +extern const float edct_table_400[]; +extern const float edct_table_600[]; /* EDCT */ + +extern const short crit_bins[]; /* (used only in AMR-WB IO mode) */ +extern const float crit_bins_corr[CRIT_NOIS_BAND]; +extern const float crit_bands_loc[]; /* (used only in AMR-WB IO mode) */ +extern const float mfreq_loc_LD[]; /* LD music post-filter */ +extern const short mfreq_bindiv_LD[]; +extern const float post_dct_wind[OFFSET2]; +extern const float MAX_SNR_SNR1_tab[]; +extern const float INV_MAX_SNR_tab[]; +extern const float sc_qnoise[]; + +extern const float W_DTX_HO[HO_HIST_SIZE]; +extern const float ENR_ATT[5]; +extern const float HO_ATT[5]; + +extern const short hq_swb_bwe_nb_bits[]; + +/*----------------------------------------------------------------------------------* + * ISF quantization (AMR-WB IO mode) + *----------------------------------------------------------------------------------*/ + +extern const float mean_isf_amr_wb[M]; /* Mean ISF vector (only in AMR-WB IO mode) */ +extern const float mean_isf_noise_amr_wb[]; /* Mean ISF vector for SID frame (only in AMR-WB IO mode) */ +extern const float gaus_dico[]; /* Gaussian codebook */ +extern const float gaus_dico_swb[]; /* Gaussian codebook for SWB TBE */ + +extern const float dico1_isf[]; /* ISF codebook - common 1st stage, 1st split (only in AMR-WB IO mode) */ +extern const float dico2_isf[]; /* ISF codebook - common 1st stage, 2nd split (only in AMR-WB IO mode) */ + +extern const float dico21_isf_46b[]; /* ISF codebook - 46b, 2nd stage, 1st split (only in AMR-WB IO mode) */ +extern const float dico22_isf_46b[]; /* ISF codebook - 46b, 2nd stage, 2st split (only in AMR-WB IO mode) */ +extern const float dico23_isf_46b[]; /* ISF codebook - 46b, 2nd stage, 3rd split (only in AMR-WB IO mode) */ +extern const float dico24_isf_46b[]; /* ISF codebook - 46b, 2nd stage, 4th split (only in AMR-WB IO mode) */ +extern const float dico25_isf_46b[]; /* ISF codebook - 46b, 2nd stage, 5th split (only in AMR-WB IO mode) */ + +extern const float dico21_isf_36b[]; /* ISF codebook - 36b, 2nd stage, 1st split (only in AMR-WB IO mode) */ +extern const float dico22_isf_36b[]; /* ISF codebook - 36b, 2nd stage, 2nd split (only in AMR-WB IO mode) */ +extern const float dico23_isf_36b[]; /* ISF codebook - 36b, 2nd stage, 3rd split (only in AMR-WB IO mode) */ + +extern const float dico1_ns_28b[]; /* ISF codebook for SID frames - 28b, 1st split */ +extern const float dico2_ns_28b[]; /* ISF codebook for SID frames - 28b, 2nd spilt */ +extern const float dico3_ns_28b[]; /* ISF codebook for SID frames - 28b, 3rd spilt */ +extern const float dico4_ns_28b[]; /* ISF codebook for SID frames - 28b, 4th spilt */ +extern const float dico5_ns_28b[]; /* ISF codebook for SID frames - 28b, 5th spilt */ + +extern const float dico1_cng_ev[]; +extern const float dico2_cng_ev[]; +extern const float dico3_cng_ev[]; +extern const float dico4_cng_ev[]; +extern const float dico5_cng_ev[]; + +/*----------------------------------------------------------------------------------* + * LSF quantization - MSVQ tables + *----------------------------------------------------------------------------------*/ + +extern const float stable_ISP[]; +extern const float stable_LSP[]; +extern const float stable_ISF[]; + +extern const float UVWB_Ave[]; +extern const float UVNB_Ave[]; +extern const float SVWB_Ave[]; +extern const float SVNB_Ave[]; +extern const float IAWB_Ave[]; +extern const float IANB_Ave[]; +extern const float GENB_Ave[]; +extern const float GEWB_Ave[]; +extern const float GEWB2_Ave[]; +extern const float TRWB_Ave[]; +extern const float TRWB2_Ave[]; +extern const float means_wb_cleanspeech_lsf16k0[]; +extern const float means_swb_cleanspeech_lsf25k6[]; +extern const float means_swb_cleanspeech_lsf32k0[]; +extern const float ModeMean12[]; + +extern const float Predictor0[]; +extern const float Predictor1[]; +extern const float Predictor2[]; +extern const float Predictor3[]; +extern const float Predictor4[]; +extern const float Predictor5[]; +extern const float Predictor6[]; +extern const float Predictor7[]; +extern const float Predictor8[]; +extern const float CNG_SN1[]; + +extern const short CB_lsf[]; +extern const short CB_p_lsf[]; +extern const float *const ModeMeans[]; +extern const float *const Predictors[]; +extern const short CBsizes[]; +extern const short CBbits[]; + +extern const short CBbits_p[]; +extern const float vals[NO_LEADERS][MAX_NO_VALS]; +extern const int no_vals[NO_LEADERS]; +extern const int no_vals_ind[NO_LEADERS][MAX_NO_VALS]; +extern const int C_VQ[LATTICE_DIM+1][LATTICE_DIM+1]; +extern const short BitsVQ[]; +extern const short BitsVQ_p[]; +extern const int no_lead[][MAX_NO_SCALES*2]; +extern const int no_lead_p[][MAX_NO_SCALES*2]; +extern const float sigma_MSLVQ[][16]; +extern const float sigma_p[][16]; +extern const float inv_sigma_MSLVQ[][16]; +extern const float inv_sigma_p[][16]; +extern const float scales[][MAX_NO_SCALES*2]; +extern const float scales_p[][MAX_NO_SCALES*2]; +extern const short predmode_tab[][6]; +extern const float pl_HQ[]; +extern const int pi0[]; +extern const unsigned int table_no_cv[]; +extern const int pl_par[]; +extern const float *const Quantizers[]; +extern const float *const Quantizers_p[]; +extern const short cng_sort[]; +extern const short perm_MSLVQ[][4]; +extern const short min_lat_bits_SN[]; +extern const short min_lat_bits_pred[]; +extern const short offset_in_lvq_mode_SN[][21]; +extern const short offset_in_lvq_mode_pred[][32]; +extern const short offset_lvq_modes_SN[]; +extern const short offset_lvq_modes_pred[]; + +/*-----------------------------------------------------------------* + * LSF quantization - BC-TCVQ tables + *-----------------------------------------------------------------*/ + +extern const short FixBranch_tbl[4][4][N_STAGE_VQ - 4]; + +extern const short BC_TCVQ_BIT_ALLOC_40B[]; + +extern const int NTRANS[4][16]; +extern const int NTRANS2[4][16]; + +extern const float AR_IntraCoeff[N_STAGE_VQ-1][2][2]; +extern const float SN_IntraCoeff[N_STAGE_VQ-1][2][2]; + +extern const float scale_ARSN[]; +extern const float scale_inv_ARSN[]; + +extern const float AR_TCVQ_CB_SUB1[2][128][2]; +extern const float AR_TCVQ_CB_SUB2[2][64][2]; +extern const float AR_TCVQ_CB_SUB3[4][32][2]; + +extern const float SN_TCVQ_CB_SUB1[2][128][2]; +extern const float SN_TCVQ_CB_SUB2[2][64][2]; +extern const float SN_TCVQ_CB_SUB3[4][32][2]; + +extern const float AR_SVQ_CB1[32][8]; +extern const float AR_SVQ_CB2[16][8]; + + +extern const short uniform_model[]; + +/*-----------------------------------------------------------------* + * LSF quantization - mid-frame quantization tables + *-----------------------------------------------------------------*/ + +extern const float tbl_mid_gen_wb_2b[]; +extern const float tbl_mid_gen_wb_5b[]; + +extern const float tbl_mid_unv_wb_4b[]; +extern const float tbl_mid_unv_wb_5b[]; + +extern const float tbl_mid_voi_wb_1b[]; +extern const float tbl_mid_voi_wb_4b[]; +extern const float tbl_mid_voi_wb_5b[]; + +/*-----------------------------------------------------------------* + * LSF quantization - Mode 2 quantization tables + *-----------------------------------------------------------------*/ + +extern const float lsf_init[16]; +extern const Float32 means_wb_31bits_ma_lsf[16]; +extern const Float32 means_nb_31bits_ma_lsf[16]; +extern const float *lsf_means[2]; +extern const float *const lsf_codebook[2][2][TCXLPC_NUMSTAGES]; +extern const int lsf_numbits[TCXLPC_NUMSTAGES]; +extern const int lsf_dims[TCXLPC_NUMSTAGES]; +extern const int lsf_offs[TCXLPC_NUMSTAGES]; +extern const float lsf_q_diff_cb_8b_rf[]; +extern const float lsf_cdk_nb_gc_stg1[]; +extern const float lsf_cdk_nb_gc_stg2[]; +extern const float lsf_cdk_nb_gc_stg3[]; +extern const float lsf_ind_cdk_nb_gc_stg4[]; +extern const float lsf_cdk_nb_vc_stg1[]; +extern const float lsf_cdk_nb_vc_stg2[]; +extern const float lsf_cdk_nb_vc_stg3[]; +extern const float lsf_ind_cdk_nb_vc_stg4[]; +extern const float lsf_cdk_wb_gc_stg1[]; +extern const float lsf_cdk_wb_gc_stg2[]; +extern const float lsf_cdk_wb_gc_stg3[]; +extern const float lsf_ind_cdk_wb_gc_stg4[]; +extern const float lsf_cdk_wb_vc_stg1[]; +extern const float lsf_cdk_wb_vc_stg2[]; +extern const float lsf_cdk_wb_vc_stg3[]; +extern const float lsf_ind_cdk_wb_vc_stg4[]; + +extern const float *const lsf_ind_codebook[2][2][TCXLPC_IND_NUMSTAGES]; +extern const int lsf_ind_numbits[TCXLPC_IND_NUMSTAGES]; +extern const int lsf_ind_dims[TCXLPC_IND_NUMSTAGES]; +extern const int lsf_ind_offs[TCXLPC_IND_NUMSTAGES]; +extern const Word16 min_distance_thr[2][2]; + +typedef float lsp_unw_triplet[3]; +extern const lsp_unw_triplet p16_gamma0_92to1[16]; +extern const lsp_unw_triplet p16_gamma0_94to1[16]; + + +/*------------------------------------------------------------------------------* + * AVQ - RE8 tables + *------------------------------------------------------------------------------*/ + +extern const int select_table22[][9]; +extern const int vals_a[][4]; /* value of leader element */ +extern const int vals_q[][4]; /* code parameter for every leader */ +extern const unsigned int Is[]; /* codebook start address for every leader */ +extern const int AA3[]; /* A3 - Number of the absolute leaders in codebook Q3 */ +extern const int AA4[]; /* A4 - Number of the absolute leaders in codebook Q4 */ +extern const unsigned int II3[]; /* I3 - Cardinality offsets for absolute leaders in Q3 */ +extern const unsigned int II4[]; /* I4 - Cardinality offset for absolute leaders in Q4 */ +extern const int Da_pos[]; /* Position of the first absolute leader on a spherical shell (or sphere) */ +extern const int Da_nb[]; /* Number of absolute leaders on a spherical shell */ +extern const int Da_id[]; /* identification code of an absolute leader */ +extern const int Da_nq[]; /* Codebook number for each absolute leader */ + +/*------------------------------------------------------------------------------* + * SWB TBE tables + *------------------------------------------------------------------------------*/ + +extern const short skip_bands_SWB_TBE[]; /* bands for SWB TBE quantisation */ +extern const short skip_bands_WB_TBE[]; /* bands for WB TBE quantisation */ + +extern const float interpol_frac_shb[]; + +extern const float AP1_STEEP[]; /* All pass filter coeffs for interpolation and decimation by a factor of 2 */ +extern const float AP2_STEEP[]; /* All pass filter coeffs for interpolation and decimation by a factor of 2 */ +extern const float STEPS[]; /* Granuality in conversion from lpc to lsp */ + +extern const float cos_fb_exc[]; +extern const float recip_order[]; + +extern const float win_lpc_shb[]; /* Window for calculating SHB LPC coeffs */ +extern const float win_lpc_hb_wb[]; +extern const float ola_win_shb_switch_fold[]; +extern const float win_flatten[]; /* Window for calculating whitening filter for SHB excitation */ +extern const float win_flatten_4k[]; /* Window for calculating whitening filter for WB excitation */ +extern const float window_shb[]; /* Overlap add window for SHB excitation used in anal and synth */ +extern const float window_shb_32k[]; /* Upsampled overlap add window for SHB excitation used transition generation */ +extern const float subwin_shb[]; /* Short overlap add window for SHB excitation used in anal and synth */ +extern const float window_wb[]; +extern const float subwin_wb[]; /* Short overlap add window for SHB excitation used in anal and synth */ + +extern const float Hilbert_coeffs[4*NUM_HILBERTS][HILBERT_ORDER1+1]; + +extern const float wac[]; +extern const float wac_swb[]; + +extern const float wb_bwe_lsfvq_cbook_8bit[]; +extern const float lbr_wb_bwe_lsfvq_cbook_2bit[]; +extern const float swb_tbe_lsfvq_cbook_8b[]; +extern const float SHBCB_SubGain5bit[]; /* 5 bit Quantizer table for SHB gain shapes */ +extern const float HBCB_SubGain5bit[]; /* 5-bit TD WB BWE temporal shaping codebook */ +extern const float SHBCB_FrameGain64[]; /* 6 bit Quantizer table for SHB overall gain */ +extern const float SHBCB_FrameGain16[]; + +extern const float full_band_bpf_1[][5]; +extern const float full_band_bpf_2[][5]; +extern const float full_band_bpf_3[][5]; + +extern const float lsf_q_cb_4b[]; /* 4 bit differential scalar quantizer table for TD SWB BWE LSFs 1 and 2*/ +extern const float lsf_q_cb_3b[]; /* 3 bit differential scalar quantizer table for TD SWB BWE LSFs 3, 4 and 5*/ +extern const float *const lsf_q_cb[]; /* Codebook array for each LSF */ +extern const short lsf_q_cb_size[]; /* Size of each element of the above */ +extern const short lsf_q_num_bits[]; /* Size of each element of the above, in bits */ +extern const float mirror_point_q_cb[]; /* LSF mirroring point codebook */ +extern const float lsf_grid[4][5]; /* LSF mirroring adjustment grid */ +extern const float grid_smoothing[]; /* LSF mirroring smoothing table */ + +extern const float overlap_coefs[]; /* HR SWB BWE - overlap coefficients */ +extern const float overlap_coefs_48kHz[]; /* HR SWB BWE - overlap coefficients @48kHz */ +extern const float swb_hr_env_code1[]; /* HR SWB BWE - envelope Q table - first two subabnds in non-transient frames */ +extern const float swb_hr_env_code2[]; /* HR SWB BWE - envelope Q table - second two subabnds in non-transient frames*/ +extern const float swb_hr_env_code3[]; /* HR SWB BWE - envelope Q table - two subabnds in transient frames */ + +extern const float allpass_poles_3_ov_2[9]; +extern const float decimate_3_ov_2_lowpass_num[3]; +extern const float decimate_3_ov_2_lowpass_den[3]; + + +/*------------------------------------------------------------------------------* + * WB BWE tables + *------------------------------------------------------------------------------*/ + +extern const float F_2_5[64]; + +/*------------------------------------------------------------------------------* + * SWB BWE tables + *------------------------------------------------------------------------------*/ + +extern const short swb_bwe_trans_subband[]; +extern const short swb_bwe_trans_subband_width[]; +extern const short swb_bwe_subband[]; +extern const float swb_inv_bwe_subband_width[]; +extern const short swb_bwe_sm_subband[]; +extern const float smooth_factor[]; +extern const short fb_bwe_subband[]; +extern const float fb_inv_bwe_subband_width[]; +extern const short fb_bwe_sm_subband[]; +extern const float fb_smooth_factor[]; +extern const float EnvCdbk11 []; +extern const float EnvCdbk1st []; +extern const float EnvCdbk2nd []; +extern const float EnvCdbk3rd []; +extern const float EnvCdbk4th []; +extern const float EnvCdbkFB[]; +extern const float Env_TR_Cdbk1 []; +extern const float Env_TR_Cdbk2 []; +extern const float w_NOR[]; +extern const float Mean_env[]; +extern const float Mean_env_fb[]; +extern const float Mean_env_tr[]; + +/*------------------------------------------------------------------------------* + * ACEPL/HQ core switching tables + *------------------------------------------------------------------------------*/ + +extern const float hp12800_32000[]; +extern const float hp16000_32000[]; +extern const float hp12800_48000[]; +extern const float hp16000_48000[]; +extern const float hp12800_16000[]; + + +extern const double cu15[28][3]; +extern const double cu4[6][3]; +extern const short ct2[7][13]; + +/*------------------------------------------------------------------------------* + * HQ core tables + *------------------------------------------------------------------------------*/ + +extern const float window_48kHz[]; +extern const float window_256kHz[]; +extern const float half_overlap_25[]; +extern const float half_overlap_48[]; +extern const float half_overlap_int[]; +extern const float small_overlap_25[]; +extern const float small_overlap_48[]; +extern const float small_overlap_int[]; +extern const float window_8_16_32kHz[]; + +extern const float short_window_48kHz[]; +extern const float short_window_32kHz[]; +extern const float short_window_16kHz[]; +extern const float short_window_8kHz[]; + +extern const float wscw16q15[]; +extern const float wscw16q15_8[]; +extern const float wscw16q15_16[]; +extern const float wscw16q15_32[]; + +/* Band structure */ +extern const short band_len_HQ[]; +extern const short band_start_HQ[]; +extern const short band_end_HQ[]; +extern const short band_len_wb[]; +extern const short band_start_wb[]; +extern const short band_end_wb[]; +extern const short band_len_harm[]; +extern const short band_start_harm[]; +extern const short band_end_harm[]; +extern const float rat[SFM_N_WB]; + +extern const short intl_bw_16[N_INTL_GRP_16]; +extern const short intl_bw_32[N_INTL_GRP_32]; +extern const short intl_bw_48[N_INTL_GRP_48]; +extern const short intl_cnt_16[N_INTL_GRP_16]; +extern const short intl_cnt_32[N_INTL_GRP_32]; +extern const short intl_cnt_48[N_INTL_GRP_48]; +extern const short norm_order_48[NB_SFM]; +extern const short norm_order_32[SFM_N_SWB]; +extern const short norm_order_16[SFM_N_WB]; + +extern const float dicn_pg[45]; +extern const short expPkEnrg_tbl[45]; +extern const int manPkEnrg_tbl[45]; +extern const int E_max5_tbl[40]; + +extern const float thren_pg[44]; + +extern const float dicn[40]; +extern const float dicn_inv[40]; +extern const float thren_HQ[39]; +extern const short dicnlg2[40]; +extern const short huffnorm[32]; +extern const short huffsizn[32]; +extern const short huffcoef[60]; +extern const short pgain_huffnorm[32]; +extern const short pgain_huffsizn[32]; + +extern const short resize_huffnorm[32]; +extern const short resize_huffsizn[32]; + +extern const short huffnorm_tran[32]; +extern const short huffsizn_tran[32]; + +extern const short sfm_width[20]; +extern const short a_map[20]; +extern const short subf_norm_groups[4][11]; + +extern const Word32 SQRT_DIM_fx[]; + +/* HQ inner_frame signallisation table */ +extern const short inner_frame_tbl[]; + +/* NB short win: 7200/8000/9600, 13200/16400 */ +extern const short band_width_40_4_6_0_0_0[4]; +extern const short band_width_40_5_6_0_0_0[5]; + +/* NB long win: 7200, 8000, 9600, 13200, 16400 */ +extern const short band_width_160_18_6_4_0_0[18]; +extern const short band_width_160_17_6_3_0_0[17]; +extern const short band_width_160_14_6_3_0_0[14]; +extern const short band_width_160_13_6_2_0_0[13]; + +/* WB short win: 13200/16400 */ +extern const short band_width_80_7_6_0_0_0[7]; + +/* WB long win: 13200, 16400 */ +extern const short band_width_320_18_6_3_0_0[18]; +extern const short band_width_320_20_6_3_0_0[20]; + +/* SWB short win: 13200, 16400 */ +extern const short band_width_142_8_8_0_0_0[8]; +extern const short band_width_160_8_8_0_0_0[8]; + +/* SWB long win: 13200, 16400 */ +extern const short band_width_568_22_6_2_0_0[22]; +extern const short band_width_640_24_6_4_0_0[24]; + +/* LR-MDCT configuration tables */ +extern const Xcore_Config xcore_config_8kHz_007200bps_long; +extern const Xcore_Config xcore_config_8kHz_008000bps_long; +extern const Xcore_Config xcore_config_8kHz_013200bps_long; +extern const Xcore_Config xcore_config_8kHz_016400bps_long; + +extern const Xcore_Config xcore_config_8kHz_007200bps_short; +extern const Xcore_Config xcore_config_8kHz_008000bps_short; +extern const Xcore_Config xcore_config_8kHz_013200bps_short; +extern const Xcore_Config xcore_config_8kHz_016400bps_short; + +extern const Xcore_Config xcore_config_16kHz_013200bps_long; +extern const Xcore_Config xcore_config_16kHz_016400bps_long; + +extern const Xcore_Config xcore_config_16kHz_013200bps_short; +extern const Xcore_Config xcore_config_16kHz_016400bps_short; + +extern const Xcore_Config xcore_config_32kHz_013200bps_long; +extern const Xcore_Config xcore_config_32kHz_016400bps_long; + +extern const Xcore_Config xcore_config_32kHz_013200bps_short; +extern const Xcore_Config xcore_config_32kHz_016400bps_short; + + +extern const short Nb[NB_SFM]; +extern const short LNb[ NB_SFM]; + +extern const Word32 pow_getbitsfrompulses_fx[16]; +extern const Word32 table_logcum_fx[563]; +extern const Word16 DDP_fx[4]; +extern const float DDP[4]; + + +extern const short step_tcq[8][STATES]; +extern const short denc[8][STATES]; +extern const short ddec[8][STATES]; + +extern const short step_LSB[STATES_LSB][2]; +extern const short denc_LSB[STATES_LSB][2]; +extern const short dqnt_LSB[STATES_LSB][4]; +extern const short dstep_LSB[4][2]; +extern const short ddec_LSB[4][2]; + +extern const short nextstate[STATES][2]; + +extern const short fine_gain_bits[]; +extern const float *const finegain[]; + +extern const unsigned char hBitsMinus1_N01[2]; +extern const unsigned char hBitsMinus1_N02[65]; +extern const unsigned char hBitsMinus1_N03[65]; +extern const unsigned char hBitsMinus1_N04[65]; +extern const unsigned char hBitsMinus1_N05[54]; +extern const unsigned char hBitsMinus1_N06[42]; +extern const unsigned char hBitsMinus1_N07[34]; +extern const unsigned char hBitsMinus1_N08[29]; +extern const unsigned char hBitsMinus1_N09[25]; +extern const unsigned char hBitsMinus1_N10[22]; +extern const unsigned char hBitsMinus1_N11[19]; +extern const unsigned char hBitsMinus1_N12[17]; +extern const unsigned char hBitsMinus1_N13[16]; +extern const unsigned char hBitsMinus1_N14[14]; +extern const unsigned char hBitsMinus1_N15[13]; +extern const unsigned char hBitsMinus1_N16[13]; +extern const unsigned char hBitsMinus1_N17[12]; +extern const unsigned char hBitsMinus1_N18[12]; +extern const unsigned char hBitsMinus1_N19[11]; +extern const unsigned char hBitsMinus1_N20[11]; +extern const unsigned char hBitsMinus1_N21[10]; +extern const unsigned char hBitsMinus1_N22[10]; +extern const unsigned char hBitsMinus1_N23[10]; +extern const unsigned char hBitsMinus1_N24[10]; +extern const unsigned char hBitsMinus1_N25[9]; +extern const unsigned char hBitsMinus1_N26[9]; +extern const unsigned char hBitsMinus1_N27[9]; +extern const unsigned char hBitsMinus1_N28[9]; +extern const unsigned char hBitsMinus1_N29[9]; +extern const unsigned char hBitsMinus1_N30[8]; +extern const unsigned char hBitsMinus1_N31[8]; +extern const unsigned char hBitsMinus1_N32[8]; +extern const unsigned char hBitsMinus1_N33[8]; +extern const unsigned char hBitsMinus1_N34[8]; +extern const unsigned char hBitsMinus1_N35[8]; +extern const unsigned char hBitsMinus1_N36[8]; +extern const unsigned char hBitsMinus1_N37[8]; +extern const unsigned char hBitsMinus1_N38[8]; +extern const unsigned char hBitsMinus1_N39[8]; +extern const unsigned char hBitsMinus1_N40[8]; +extern const unsigned char hBitsMinus1_N41[7]; +extern const unsigned char hBitsMinus1_N42[7]; +extern const unsigned char hBitsMinus1_N43[7]; +extern const unsigned char hBitsMinus1_N44[7]; +extern const unsigned char hBitsMinus1_N45[7]; +extern const unsigned char hBitsMinus1_N46[7]; +extern const unsigned char hBitsMinus1_N47[7]; +extern const unsigned char hBitsMinus1_N48[7]; +extern const unsigned char hBitsMinus1_N49[7]; +extern const unsigned char hBitsMinus1_N50[7]; +extern const unsigned char hBitsMinus1_N51[7]; +extern const unsigned char hBitsMinus1_N52[7]; +extern const unsigned char hBitsMinus1_N53[7]; +extern const unsigned char hBitsMinus1_N54[7]; +extern const unsigned char hBitsMinus1_N55[7]; +extern const unsigned char hBitsMinus1_N56[7]; +extern const unsigned char hBitsMinus1_N57[7]; +extern const unsigned char hBitsMinus1_N58[7]; +extern const unsigned char hBitsMinus1_N59[7]; +extern const unsigned char hBitsMinus1_N60[7]; +extern const unsigned char hBitsMinus1_N61[6]; +extern const unsigned char hBitsMinus1_N62[6]; +extern const unsigned char hBitsMinus1_N63[6]; +extern const unsigned char hBitsMinus1_N64[6]; +extern const unsigned char* const hBitsN[65]; +extern const short dsHighDiracsTab[43]; +extern const unsigned int intLimCDivInvDQ31[68]; +extern const unsigned char obtainEnergyQuantizerDensity_f[57]; +extern const short lim_neg_inv_tbl_fx[11]; +extern const short fg_inv_tbl_fx[13] ; +/* functions and tables for pvq_indexing */ +extern const unsigned int exactdivodd[ODD_DIV_SIZE] ; + +extern const float gain_att[]; +extern const float att_step[]; +extern const float gain_qlow[]; +extern const short gain_cb_size[]; +extern const float stab_trans[]; +extern const Word16 stab_trans_fx[]; +extern const float env_stab_tp[2][2]; +/*----------------------------------------------------------------------------------* + * SWB BWE for LR MDCT core + *----------------------------------------------------------------------------------*/ +extern const float gain_table_SWB_BWE[NB_SWB_SUBBANDS]; +/* HQ_NORMAL mode */ +extern const short bits_lagIndices_modeNormal[NB_SWB_SUBBANDS]; +extern const short subband_offsets_12KBPS[NB_SWB_SUBBANDS]; +extern const short subband_offsets_16KBPS[NB_SWB_SUBBANDS]; +extern const short subband_search_offsets[NB_SWB_SUBBANDS]; +extern const short bw_SPT_tbl[2][SPT_SHORTEN_SBNUM]; + +/* HQ_HARMONIC mode */ +extern const short bits_lagIndices_mode0_Har[NB_SWB_SUBBANDS_HAR_SEARCH_SB]; +extern const short subband_offsets_sub5_13p2kbps_Har[NB_SWB_SUBBANDS_HAR]; +extern const short subband_search_offsets_13p2kbps_Har[NB_SWB_SUBBANDS_HAR_SEARCH_SB]; +extern const short subband_offsets_sub5_16p4kbps_Har[NB_SWB_SUBBANDS_HAR]; +extern const short subband_search_offsets_16p4kbps_Har[NB_SWB_SUBBANDS_HAR_SEARCH_SB] ; + +/*----------------------------------------------------------------------------------* + * SC-VBR + *----------------------------------------------------------------------------------*/ + +/* NELP filter coefficients */ +extern const float bp1_num_coef_wb[5]; +extern const float bp1_den_coef_wb[5]; +extern const float shape1_num_coef[11]; +extern const float shape1_den_coef[11]; +extern const float shape2_num_coef[11]; +extern const float shape2_den_coef[11]; +extern const float shape3_num_coef[11]; +extern const float shape3_den_coef[11]; +extern const float txlpf1_num_coef[11]; +extern const float txlpf1_den_coef[11]; +extern const float txhpf1_num_coef[11]; +extern const float txhpf1_den_coef[11]; +extern const float bp1_num_coef_nb_fx_order7[8]; +extern const float bp1_den_coef_nb_fx_order7[8]; +extern const float num_nelp_lp[NELP_LP_ORDER+1]; +extern const float den_nelp_lp[NELP_LP_ORDER+1]; + +extern const float UVG1CB_WB[UVG1_CBSIZE][2]; +extern const float UVG2CB1_WB[UVG2_CBSIZE][5]; +extern const float UVG2CB2_WB[UVG2_CBSIZE][5]; + +extern const float UVG1CB_NB[UVG1_CBSIZE][2]; +extern const float UVG2CB1_NB[UVG2_CBSIZE][5]; +extern const float UVG2CB2_NB[UVG2_CBSIZE][5]; + +extern const float frac_4sf[NB_SUBFR + 2]; + +extern const float erb_WB[NUM_ERB_WB + 1]; +extern const float erb_NB[NUM_ERB_NB + 1]; + +extern const float AmpCB1_WB[64][10]; +extern const float AmpCB2_WB[64][NUM_ERB_WB - 11]; + +extern const float AmpCB1_NB[64][10]; +extern const float AmpCB2_NB[64][NUM_ERB_NB - 11]; + +extern const float PowerCB_WB[64][2]; +extern const float PowerCB_NB[64][2]; +extern const float sinc[8][12]; + +extern const float hvq_thr_adj[5]; +extern const float hvq_peak_cb[1024]; +extern const float hvq_class_c[16]; +extern const short hvq_cb_search_overlap24k[17]; +extern const short hvq_cb_search_overlap32k[21]; + +extern const short hvq_pg_huff_offset[NUM_PG_HUFFLEN]; +extern const short hvq_pg_huff_thres[NUM_PG_HUFFLEN]; +extern const short hvq_pg_huff_tab[32]; + +extern const short hvq_cp_huff_len[52]; +extern const short hvq_cp_huff_val[52]; +extern const short hvq_cp_layer1_map5[HVQ_CP_MAP_LEN]; + +extern const short hvq_cp_huff_thres[HVQ_CP_HUFF_NUM_LEN]; +extern const short hvq_cp_huff_offset[HVQ_CP_HUFF_NUM_LEN]; +extern const short hvq_cp_huff_tab[52]; + +extern const short pow2_angle_res[8]; + +/*------------------------------------------------------------------------------* + * GSC mode + *------------------------------------------------------------------------------*/ + +extern const float sin_table256[]; + +extern const short gsc_sfm_start[]; +extern const short gsc_sfm_end[]; +extern const short gsc_sfm_size[]; + +extern const float sm_table[]; + +extern const float mfreq_loc[]; +extern const short mfreq_bindiv_loc[]; + +extern const float mean_gp[]; +extern const float dic_gp[]; + +extern const float Gain_mean[]; +extern const float Gain_meanHR[]; +extern const float Gain_mean_dic[]; +extern const float Gain_mean_dicHR[]; + +extern const float YG_mean16[]; +extern const float YG_dicMR_1[]; +extern const float YG_dicMR_2[]; +extern const float YG_dicMR_3[]; +extern const float YG_dicMR_4[]; + +extern const float mean_m[]; +extern const float mean_gain_dic[]; + +extern const float YGain_mean_LR[]; +extern const float YGain_dic1_LR[]; +extern const float YGain_dic2_LR[]; +extern const float YGain_dic3_LR[]; +extern const float Gain_dic2_NBHR[]; +extern const float Gain_dic3_NBHR[]; + +extern const short GSC_freq_bits[]; +extern const short GSC_freq_DL0_bits[]; + +extern const float Gain_meanNB[]; +extern const float Gain_mean_dicNB[]; +extern const float Mean_dic_NB[]; +extern const float Gain_dic1_NB[]; +extern const float Gain_dic2_NB[]; +extern const float Gain_dic3_NB[]; + + +/*------------------------------------------------------------------------------* + * FFT transform + *------------------------------------------------------------------------------*/ + +extern const short Odx_fft64[64]; +extern const float w_fft64[32]; +extern const short Ip_fft64[6]; +extern const short Odx_fft32_15[32]; +extern const float w_fft32[16]; +extern const short Ip_fft32[6]; +extern const short Odx_fft32_5[32]; +extern const short Odx_fft16[16]; +extern const float w_fft16[8]; +extern const short Ip_fft16[6]; +extern const float w_fft8[8]; +extern const short Ip_fft8[6]; +extern const short Idx_dortft80[80]; +extern const short Idx_dortft120[120]; +extern const short Idx_dortft160[160]; +extern const short Idx_dortft320[320]; +extern const short Idx_dortft480[480]; +extern const short Ip_fft128[10]; +extern const float w_fft128[64]; +extern const short Ip_fft256[10]; +extern const float w_fft256[128]; +extern const short Ip_fft512[18]; +extern const float w_fft512[256]; +extern const short Idx_dortft40[40]; +extern const short Odx_fft8_5[8]; +extern const short ip_edct2_64[6]; +extern const float w_edct2_64[80]; +extern const short Idx_dortft20[20]; +extern const short Odx_fft4_5[4]; +extern const float w_fft4[2]; +extern const short Ip_fft4[6]; + +/*----------------------------------------------------------------------------------* + * FEC for HQ core + *----------------------------------------------------------------------------------*/ + +extern const float Asr_LP32[41]; +extern const float Asr_LP16[21]; +extern const float Asr_LP48[61]; + +extern const short Num_bands_NB[]; +extern const float SmoothingWin_NB875[]; +extern const float SmoothingWin_NB2[]; + +/*----------------------------------------------------------------------------------* + * CLDFB + *----------------------------------------------------------------------------------*/ + +extern const int freqTable[2]; + +extern const float CLDFB80_10[100]; +extern const float CLDFB80_16[160]; +extern const float CLDFB80_20[200]; +extern const float CLDFB80_30[300]; +extern const float CLDFB80_32[320]; +extern const float CLDFB80_40[400]; +extern const float CLDFB80_60[600]; + +extern const float *const CLDFB80_COEF[]; + +extern const float rot_vec_ana_re_L10[5]; +extern const float rot_vec_ana_im_L10[5]; +extern const float rot_vec_ana_re_L16[8]; +extern const float rot_vec_ana_im_L16[8]; +extern const float rot_vec_ana_re_L20[10]; +extern const float rot_vec_ana_im_L20[10]; +extern const float rot_vec_ana_re_L30[15]; +extern const float rot_vec_ana_im_L30[15]; +extern const float rot_vec_ana_re_L32[16]; +extern const float rot_vec_ana_im_L32[16]; +extern const float rot_vec_ana_re_L40[20]; +extern const float rot_vec_ana_im_L40[20]; +extern const float rot_vec_ana_re_L60[30]; +extern const float rot_vec_ana_im_L60[30]; + +extern const float rot_vec_syn_re_L10[5]; +extern const float rot_vec_syn_im_L10[5]; +extern const float rot_vec_syn_re_L16[8]; +extern const float rot_vec_syn_im_L16[8]; +extern const float rot_vec_syn_re_L20[10]; +extern const float rot_vec_syn_im_L20[10]; +extern const float rot_vec_syn_re_L30[15]; +extern const float rot_vec_syn_im_L30[15]; +extern const float rot_vec_syn_re_L32[16]; +extern const float rot_vec_syn_im_L32[16]; +extern const float rot_vec_syn_re_L40[20]; +extern const float rot_vec_syn_im_L40[20]; +extern const float rot_vec_syn_re_L60[30]; +extern const float rot_vec_syn_im_L60[30]; + +extern const float bpf_weights_16[CLDFB_NO_COL_MAX]; + +extern const float CNG_details_codebook[64][NUM_ENV_CNG]; +/*----------------------------------------------------------------------------------* + * FD CNG + *----------------------------------------------------------------------------------*/ + +extern const int d_array[18]; +extern const float m_array[18]; +extern const float msQeqInvAv_thresh[3]; +extern const float msNoiseSlopeMax[4]; + +extern const SCALE_SETUP scaleTable[20]; +extern const SCALE_SETUP scaleTable_cn_only[18]; +extern const float scaleTable_cn_only_amrwbio[3][2]; + +extern const int sidparts_encoder_noise_est[24]; + + +extern const FD_CNG_SETUP FdCngSetup_nb; +extern const FD_CNG_SETUP FdCngSetup_wb1; +extern const FD_CNG_SETUP FdCngSetup_wb2; +extern const FD_CNG_SETUP FdCngSetup_wb3; +extern const FD_CNG_SETUP FdCngSetup_swb1; +extern const FD_CNG_SETUP FdCngSetup_swb2; + +extern const short maxN_37bits; +extern const short maxC_37bits; +extern const short stages_37bits; +extern const int levels_37bits[6]; +extern const short bits_37bits[6]; +extern const float * const cdk_37bits[]; + +extern const float fftSineTab640[321]; + +extern const float olapWinAna512[512]; +extern const float olapWinAna640[640]; + +extern const float olapWinSyn256[256]; +extern const float olapWinSyn320[320]; + + +/*----------------------------------------------------------------------------------* + * TCX + *----------------------------------------------------------------------------------*/ + +extern float const gain_corr_fac[]; +extern float const gain_corr_inv_fac[]; + +extern const SCALE_TCX_SETUP scaleTcxTable[13]; + + +/*----------------------------------------------------------------------------------* + * Arithmetic coder + *----------------------------------------------------------------------------------*/ + +extern const unsigned char ari_lookup_s17_LC[4096]; +extern const unsigned short ari_pk_s17_LC_ext[64][18]; + +extern const int NumRatioBits[2][17]; +extern const float Ratios_WB_2[32]; +extern const float Ratios_WB_3[32]; +extern const float Ratios_WB_4[32]; +extern const float Ratios_WB_5[32]; +extern const float Ratios_WB_6[32]; +extern const float Ratios_WB_7[32]; +extern const float Ratios_WB_8[16]; +extern const float Ratios_WB_9[16]; +extern const float Ratios_WB_10[16]; +extern const float Ratios_WB_11[16]; +extern const float Ratios_WB_12[16]; +extern const float Ratios_WB_13[16]; +extern const float Ratios_WB_14[16]; +extern const float Ratios_WB_15[16]; +extern const float Ratios_WB_16[4]; +extern const float Ratios_WB_17[4]; +extern const float Ratios_WB_18[4]; +extern const float Ratios_NB_2[32]; +extern const float Ratios_NB_3[16]; +extern const float Ratios_NB_4[16]; +extern const float Ratios_NB_5[16]; +extern const float Ratios_NB_6[16]; +extern const float Ratios_NB_7[16]; +extern const float Ratios_NB_8[16]; +extern const float Ratios_NB_9[8]; +extern const float Ratios_NB_10[8]; +extern const float Ratios_NB_11[8]; +extern const float Ratios_NB_12[8]; +extern const float Ratios_NB_13[4]; +extern const float Ratios_NB_14[4]; +extern const float Ratios_NB_15[4]; +extern const float Ratios_NB_16[4]; +extern const float Ratios_NB_17[4]; +extern const float Ratios_NB_18[4]; +extern const float *const Ratios[2][17]; + +extern const Word16 qGains[2][1 << kTcxHmNumGainBits]; + +/*----------------------------------------------------------------------------------* + * Innovative codebook + *----------------------------------------------------------------------------------*/ + +extern const PulseConfig PulseConfTable[]; + +/*----------------------------------------------------------------------------------* + * TNS + *----------------------------------------------------------------------------------*/ + +extern struct TnsParameters const tnsParametersIGF32kHz_LowBR[1]; +extern struct TnsParameters const tnsParameters32kHz[2]; +extern struct TnsParameters const tnsParameters32kHz_grouped[2]; +extern struct TnsParameters const tnsParameters16kHz[1]; +extern struct TnsParameters const tnsParameters16kHz_grouped[2]; +extern struct TnsParameters const tnsParameters48kHz_grouped[2]; + +extern float const tnsAcfWindow[TNS_MAX_FILTER_ORDER]; + +extern ParamsBitMap const tnsEnabledSWBTCX20BitMap; +extern ParamsBitMap const tnsEnabledSWBTCX10BitMap; +extern ParamsBitMap const tnsEnabledWBTCX20BitMap; + +extern const Coding codesTnsAllCoeffs[]; + +extern const Coding codesTnsCoeff0SWBTCX20[]; +extern const Coding codesTnsCoeff0SWBTCX10[]; +extern const Coding codesTnsCoeff1SWBTCX20[]; +extern const Coding codesTnsCoeff1SWBTCX10[]; +extern const Coding codesTnsCoeff2SWBTCX20[]; +extern const Coding codesTnsCoeff2SWBTCX10[]; +extern const Coding codesTnsCoeff3SWBTCX20[]; +extern const Coding codesTnsCoeff3SWBTCX10[]; +extern const Coding codesTnsCoeff4SWBTCX20[]; +extern const Coding codesTnsCoeff4SWBTCX10[]; +extern const Coding codesTnsCoeff5[]; +extern const Coding codesTnsCoeff6[]; + +extern const Coding codesTnsCoeff0WBTCX20[]; +extern const Coding codesTnsCoeff1WBTCX20[]; +extern const Coding codesTnsCoeff2WBTCX20[]; +extern const Coding codesTnsCoeff3WB[]; + +extern const Coding codesTnsCoeff456[]; +extern const Coding codesTnsCoeff7[]; + +extern int const nTnsCoeffCodes; + +extern const Coding * const codesTnsCoeffSWBTCX20[]; +extern const Coding * const codesTnsCoeffSWBTCX10[]; +extern const Coding * const codesTnsCoeffWBTCX20[]; +extern int const nTnsCoeffTables; + +extern const Coding codesTnsOrderTCX20[]; +extern const Coding codesTnsOrderTCX10[]; +extern const Coding codesTnsOrder[]; +extern int const nTnsOrderCodes; + +extern float const tnsCoeff4[16]; + +/**********************************************************************/ /** +igf settings structure for each bitrate mode +**************************************************************************/ +typedef struct igf_mode_type +{ + int sampleRate; + int frameLength; + int bitRate; + int igfMinFq; + float transFac; + int maxHopsize; +} IGF_MODE,*H_IGF_MODE; + +extern const IGF_MODE igfMode[15]; +extern const int swb_offset_LB_new[15][IGF_MAX_SFB]; +extern const float igf_whitening_TH[15][2][IGF_MAX_TILES]; +extern const short cf_off_se01_tab[9]; +extern const short cf_off_se10_tab; +extern const short cf_off_se02_tab[9][IGF_CTX_COUNT]; +extern const short cf_off_se11_tab[IGF_CTX_COUNT][IGF_CTX_COUNT]; +extern const unsigned short cf_se00_tab[IGF_SYMBOLS_IN_TABLE + 1]; +extern const unsigned short cf_se01_tab[9][IGF_SYMBOLS_IN_TABLE + 1]; +extern const unsigned short cf_se02_tab[9][IGF_CTX_COUNT][IGF_SYMBOLS_IN_TABLE + 1]; +extern const unsigned short cf_se10_tab[IGF_SYMBOLS_IN_TABLE + 1]; +extern const unsigned short cf_se11_tab[IGF_CTX_COUNT][IGF_CTX_COUNT][IGF_SYMBOLS_IN_TABLE + 1]; + +extern const int bwMode2fs[4]; + +extern const float normReciprocal[CHEAP_NORM_SIZE]; +extern const float *w_a[7]; + +extern const PWord16 SineTable512_fx[]; +extern const Word16 ldCoeff[7]; +extern const UWord32 exp2_tab_long[32]; +extern const UWord32 exp2w_tab_long[32]; +extern const UWord32 exp2x_tab_long[32]; +extern const Word16 invTable[INV_TABLE_SIZE+1]; +extern const Word16 sqrtTable[SQRT_TABLE_SIZE+1]; +extern const Word16 invSqrtTable[SQRT_TABLE_SIZE+1]; + +/* ACELP pulse coding */ +extern const int low_len[10]; +extern const int low_mask[10]; +extern const int indx_fact[10]; +extern const int index_len[3]; +extern const int index_mask_ACELP[3]; + +#endif + diff --git a/src/libs/libevs/lib_com/rom_com_fx.cpp b/src/libs/libevs/lib_com/rom_com_fx.cpp deleted file mode 100755 index 69c99440..00000000 --- a/src/libs/libevs/lib_com/rom_com_fx.cpp +++ /dev/null @@ -1,21498 +0,0 @@ -/*==================================================================================== - EVS Codec 3GPP TS26.442 Apr 03, 2018. Version 12.11.0 / 13.6.0 / 14.2.0 - ====================================================================================*/ - -#include "options.h" /* Compilation switches */ -#include "prot_fx.h" -#include "rom_com_fx.h" /* Static table prototypes */ -#include "cnst_fx.h" /* Decoder static structure */ -#include "stl.h" - -#include "basop_util.h" - - - - -/*----------------------------------------------------------------------------------* - * Table of bitrates - *----------------------------------------------------------------------------------*/ - -const Word32 brate_tbl[SIZE_BRATE_TBL] = -{ - ACELP_7k20, ACELP_8k00, ACELP_9k60, ACELP_13k20, ACELP_16k40, ACELP_24k40, - ACELP_32k, ACELP_48k, ACELP_64k, HQ_96k, HQ_128k -}; - -/*----------------------------------------------------------------------------------* - * Conversion of ACELP signalling parameters (ACELP internal Fs, coder type, bandwidth, sharpening flag) to index - * (to be consulted with the decision matrix) - * - * - in order to retrieve the index, each section in this table starts with a bitrate - * - the second value in each section corresponds to the number of bits - * - the other values represent indices created by combining different parameters into a single value through the macro SIG2IND() - *----------------------------------------------------------------------------------*/ - -/* Combine coder_type, bandwidth, formant sharpening flag, and channel-aware flag into one indice */ -#define SIG2IND(ctype, bw, sf, ca_rf) ( ctype | (bw << 3) | (sf << 6) | (ca_rf << 7) ) - -const Word32 acelp_sig_tbl[MAX_ACELP_SIG] = -{ - /* GENERIC UNVOICED VOICED TRANSITION AUDIO INACTIVE */ - ACELP_7k20, 4, - SIG2IND(GENERIC, NB, 1, 0), SIG2IND(UNVOICED, NB, 0, 0), SIG2IND(VOICED, NB, 1, 0), SIG2IND(TRANSITION, NB, 1, 0), SIG2IND(AUDIO, NB, 0, 0), SIG2IND(INACTIVE, NB, 0, 0), - SIG2IND(GENERIC, WB, 1, 0), SIG2IND(UNVOICED, WB, 0, 0), SIG2IND(VOICED, WB, 1, 0), SIG2IND(TRANSITION, WB, 1, 0), SIG2IND(AUDIO, WB, 0, 0), SIG2IND(INACTIVE, WB, 0, 0), - SIG2IND(GENERIC, NB, 0, 0), - SIG2IND(GENERIC, WB, 0, 0), - SIG2IND(LR_MDCT, NB, 0, 0), - - ACELP_8k00, 4, - SIG2IND(GENERIC, NB, 1, 0), SIG2IND(UNVOICED, NB, 0, 0), SIG2IND(VOICED, NB, 1, 0), SIG2IND(TRANSITION, NB, 1, 0), SIG2IND(AUDIO, NB, 0, 0), SIG2IND(INACTIVE, NB, 0, 0), - SIG2IND(GENERIC, WB, 1, 0), SIG2IND(UNVOICED, WB, 0, 0), SIG2IND(VOICED, WB, 1, 0), SIG2IND(TRANSITION, WB, 1, 0), SIG2IND(AUDIO, WB, 0, 0), SIG2IND(INACTIVE, WB, 0, 0), - SIG2IND(GENERIC, NB, 0, 0), - SIG2IND(GENERIC, WB, 0, 0), - SIG2IND(LR_MDCT, NB, 0, 0), - - ACELP_13k20, 5, - SIG2IND(GENERIC, NB, 1, 0), SIG2IND(VOICED, NB, 1, 0), SIG2IND(TRANSITION, NB, 0, 0), SIG2IND(AUDIO, NB, 0, 0), SIG2IND(INACTIVE, NB, 0, 0), - SIG2IND(GENERIC, WB, 1, 0), SIG2IND(VOICED, WB, 1, 0), SIG2IND(TRANSITION, WB, 0, 0), SIG2IND(AUDIO, WB, 0, 0), SIG2IND(INACTIVE, WB, 0, 0), - SIG2IND(GENERIC, SWB, 1, 0), SIG2IND(VOICED, SWB, 1, 0), SIG2IND(TRANSITION, SWB, 0, 0), SIG2IND(AUDIO, SWB, 0, 0), SIG2IND(INACTIVE, SWB, 0, 0), - SIG2IND(GENERIC, NB, 0, 0), SIG2IND(VOICED, NB, 0, 0), - SIG2IND(GENERIC, WB, 0, 0), SIG2IND(VOICED, WB, 0, 0), - SIG2IND(GENERIC, SWB, 0, 0), SIG2IND(VOICED, SWB, 0, 0), - SIG2IND(GENERIC, WB, 1, 1), SIG2IND(UNVOICED, WB, 0, 1), SIG2IND(VOICED, WB, 1, 1), SIG2IND(INACTIVE, WB, 0, 1), - SIG2IND(GENERIC, SWB, 1, 1), SIG2IND(UNVOICED, SWB, 0, 1), SIG2IND(VOICED, SWB, 1, 1), SIG2IND(INACTIVE, SWB, 0, 1), - SIG2IND(LR_MDCT, NB, 0, 0), - SIG2IND(LR_MDCT, WB, 0, 0), - SIG2IND(LR_MDCT, SWB, 0, 0), - - ACELP_32k, 4, - SIG2IND(GENERIC, WB, 1, 0), SIG2IND(TRANSITION, WB, 1, 0), SIG2IND(INACTIVE, WB, 0, 0), - SIG2IND(GENERIC, SWB, 1, 0), SIG2IND(TRANSITION, SWB, 1, 0), SIG2IND(INACTIVE, SWB, 0, 0), - SIG2IND(GENERIC, FB, 1, 0), SIG2IND(TRANSITION, FB, 1, 0), SIG2IND(INACTIVE, FB, 0, 0), - SIG2IND(GENERIC, WB, 0, 0), SIG2IND(TRANSITION, WB, 0, 0), - SIG2IND(GENERIC, SWB, 0, 0), SIG2IND(TRANSITION, SWB, 0, 0), - SIG2IND(GENERIC, FB, 0, 0), SIG2IND(TRANSITION, FB, 0, 0), - - ACELP_64k, 4, - SIG2IND(GENERIC, WB, 0, 0), SIG2IND(TRANSITION, WB, 0, 0), SIG2IND(INACTIVE, WB, 0, 0), - SIG2IND(GENERIC, SWB, 1, 0), SIG2IND(TRANSITION, SWB, 1, 0), SIG2IND(INACTIVE, SWB, 0, 0), - SIG2IND(GENERIC, FB, 1, 0), SIG2IND(TRANSITION, FB, 1, 0), SIG2IND(INACTIVE, FB, 0, 0), - SIG2IND(GENERIC, SWB, 0, 0), SIG2IND(TRANSITION, SWB, 0, 0), - SIG2IND(GENERIC, FB, 0, 0), SIG2IND(TRANSITION, FB, 0, 0), -}; - -/*----------------------------------------------------------------------------------* - * ACELP bit allocation tables - *----------------------------------------------------------------------------------*/ - -/* bit allocation table for end-frame LSF quantizer */ -const Word16 LSF_bits_tbl[] = -{ - /* IC UC VC GC TC AC */ - 22, 37, 31, 29, 31, 22, /* ACELP_7k20 */ - 22, 40, 36, 33, 34, 22, /* ACELP_8k00 */ - 31, 0, 37, 37, 40, 31, /* ACELP_11k60 */ - 31, 0, 39, 39, 41, 31, /* ACELP_12k15 */ - 31, 0, 38, 38, 40, 31, /* ACELP_12k85 */ - 31, 0, 38, 38, 40, 31, /* ACELP_13k20 */ - 31, 0, 37, 42, 42, 31, /* ACELP_14k80 */ - 31, 0, 43, 40, 40, 31, /* ACELP_16k40 */ - 31, 0, 42, 40, 40, 0, /* ACELP_22k60 */ - 31, 0, 46, 41, 41, 31, /* ACELP_24k40 */ - 41, 0, 0, 41, 41, 0, /* ACELP_29k00 */ - 41, 0, 0, 41, 41, 0, /* ACELP_29k20 */ - 41, 0, 0, 41, 41, 0, /* ACELP_30k20 */ - 41, 0, 0, 41, 41, 0, /* ACELP_30k40 */ - 41, 0, 0, 41, 41, 0, /* ACELP_32k */ - 41, 0, 0, 41, 41, 0, /* ACELP_48k */ - 41, 0, 0, 41, 41, 0, /* ACELP_64k */ -}; - -/* bit allocation table for mid-frame LSF quantizer */ -const Word16 mid_LSF_bits_tbl[] = -{ - /* IC UC VC GC TC AC */ - 2, 5, 4, 5, 5, 2, /* ACELP_7k20 */ - 2, 5, 4, 5, 5, 2, /* ACELP_8k00 */ - 2, 0, 4, 5, 5, 2, /* ACELP_11k60 */ - 2, 0, 5, 5, 5, 2, /* ACELP_12k15 */ - 2, 0, 5, 5, 5, 2, /* ACELP_12k85 */ - 2, 0, 5, 5, 5, 2, /* ACELP_13k20 */ - 4, 0, 5, 5, 5, 4, /* ACELP_14k80 */ - 4, 0, 5, 5, 5, 4, /* ACELP_16k40 */ - 5, 0, 5, 5, 5, 5, /* ACELP_22k60 */ - 5, 0, 5, 5, 5, 5, /* ACELP_24k40 */ - 5, 0, 0, 5, 5, 5, /* ACELP_29k00 */ - 5, 0, 0, 5, 5, 5, /* ACELP_29k20 */ - 5, 0, 0, 5, 5, 5, /* ACELP_30k20 */ - 5, 0, 0, 5, 5, 5, /* ACELP_30k40 */ - 5, 0, 0, 5, 5, 5, /* ACELP_32k */ - 5, 0, 0, 5, 5, 5, /* ACELP_48k */ - 5, 0, 0, 5, 5, 5, /* ACELP_64k */ -}; - - -/* bit allocation table for scaled innovation energy prediction */ -const Word16 Es_pred_bits_tbl[] = -{ - /* UC VC GC TC */ - 0, 0, 0, 4, /* ACELP_7k20 */ - 0, 0, 0, 4, /* ACELP_8k00 */ - 0, 5, 4, 4, /* ACELP_11k60 */ - 0, 5, 5, 5, /* ACELP_12k15 */ - 0, 5, 4, 5, /* ACELP_12k85 */ - 0, 5, 4, 4, /* ACELP_13k20 */ - 0, 5, 5, 5, /* ACELP_14k80 */ - 0, 5, 5, 5, /* ACELP_16k40 */ - 0, 5, 5, 5, /* ACELP_22k60 */ - 0, 5, 5, 5, /* ACELP_24k40 */ - 0, 0, 5, 5, /* ACELP_29k00 */ - 0, 0, 5, 5, /* ACELP_29k20 */ - 0, 0, 5, 5, /* ACELP_30k20 */ - 0, 0, 5, 5, /* ACELP_30k40 */ - 0, 0, 5, 5, /* ACELP_32k */ - 0, 0, 5, 5, /* ACELP_48k */ - 0, 0, 5, 5, /* ACELP_64k */ -}; - -/* bit allocation table for gain quantizer (ACELP@12.8kHz) */ -/* the 4 values allocated correspond to 4 subframes */ -const Word16 gain_bits_tbl[] = -{ - /* UC VC GC TC0_0 TC0_64 TC0_128 TC0_192 TC64 TC128 TC192 */ - 7,7,7,7, 7,6,6,6, 6,6,6,6, 5,5,5,5, 5,5,6,5, 5,3,6,6, 5,3,3,6, 3,6,6,6, 3,3,6,6, 3,3,3,10, /* ACELP_7k20 */ - 7,7,7,7, 8,7,6,6, 8,7,6,6, 5,5,5,5, 5,6,5,5, 5,3,6,6, 5,3,3,6, 3,5,5,5, 3,3,6,6, 3,3,3,14, /* ACELP_8k00 */ - 0,0,0,0, 6,6,6,6, 6,6,6,6, 6,6,6,6, 6,6,6,6, 6,3,6,6, 6,3,3,6, 3,6,6,6, 3,3,6,6, 3,3,3,13, /* ACELP_11k60 */ - 0,0,0,0, 6,6,6,6, 6,6,6,6, 6,6,6,6, 6,6,6,6, 6,3,6,6, 6,3,3,6, 3,6,6,6, 3,3,6,6, 3,3,3,14, /* ACELP_12k15 */ - 0,0,0,0, 6,6,6,6, 6,6,6,6, 6,6,6,6, 6,6,6,6, 6,3,6,6, 6,3,3,6, 3,6,6,6, 3,3,6,5, 3,3,3,14, /* ACELP_12k85 */ - 0,0,0,0, 6,6,6,6, 6,6,6,6, 6,6,6,6, 6,6,6,6, 6,3,6,6, 6,3,3,6, 3,6,6,6, 3,3,6,6, 3,3,3,15, /* ACELP_13k20 */ - 0,0,0,0, 6,6,6,6, 6,6,6,6, 6,6,6,6, 6,6,6,6, 6,3,6,6, 6,3,3,6, 3,6,6,6, 3,3,6,6, 3,3,3,15, /* ACELP_14k80 */ - 0,0,0,0, 6,6,6,6, 6,6,6,6, 6,6,6,6, 6,6,6,6, 6,3,6,6, 6,3,3,6, 3,6,6,6, 3,3,6,6, 3,3,3,15, /* ACELP_16k40 */ - 0,0,0,0, 6,6,6,6, 6,6,6,6, 6,6,6,6, 6,6,6,6, 6,3,6,6, 6,3,3,6, 3,6,6,6, 3,3,6,6, 3,3,3,14, /* ACELP_22k60 */ - 0,0,0,0, 6,6,6,6, 6,6,6,6, 6,6,6,6, 6,6,6,6, 6,3,6,6, 6,3,3,6, 3,6,6,6, 3,3,6,6, 3,3,3,15, /* ACELP_24k40 */ -}; - -/* bit allocation table for gain gain quantizer (ACELP@16kHz) */ -/* the 5 values allocated correspond to 5 subframes */ -const Word16 gain_bits_16kHz_tbl[] = -{ - /* IC GC TC0 TC64 TC128 TC192 TC256 */ - 0,0,0,0,0, 6,0,0,0,0, 0,0,0,0,0, 0,0,0,0,0, 0,0,0,0,0, 0,0,0,0,0, 0,0,0,0, 0, /* ACELP_8k00 */ - 0,0,0,0,0, 6,0,0,0,0, 0,0,0,0,0, 0,0,0,0,0, 0,0,0,0,0, 0,0,0,0,0, 0,0,0,0, 0, /* ACELP_14k80 */ - 6,6,6,6,6, 6,6,6,6,6, 6,6,6,6,6, 3,6,6,6,6, 3,3,6,6,6, 3,3,3,6,6, 3,3,3,3,15, /* ACELP_22k60 */ - 6,6,6,6,6, 6,6,6,6,6, 6,6,6,6,6, 3,6,6,6,6, 3,3,6,6,6, 3,3,3,6,6, 3,3,3,3,16, /* ACELP_24k40 */ - 6,6,6,6,6, 6,6,6,6,6, 6,6,6,6,6, 3,6,6,6,6, 3,3,6,6,6, 3,3,3,6,6, 3,3,3,3,14, /* ACELP_29k00 */ - 6,6,6,6,6, 6,6,6,6,6, 6,6,6,6,6, 3,6,6,6,6, 3,3,6,6,6, 3,3,3,6,6, 3,3,3,3,14, /* ACELP_29k20 */ - 6,6,6,6,6, 6,6,6,6,6, 6,6,6,6,6, 3,6,6,6,6, 3,3,6,6,6, 3,3,3,6,6, 3,3,3,3,14, /* ACELP_30k20 */ - 6,6,6,6,6, 6,6,6,6,6, 6,6,6,6,6, 3,6,6,6,6, 3,3,6,6,6, 3,3,3,6,6, 3,3,3,3,14, /* ACELP_30k40 */ - 6,6,6,6,6, 6,6,6,6,6, 6,6,6,6,6, 3,6,6,6,6, 3,3,6,6,6, 3,3,3,6,6, 3,3,3,3,14, /* ACELP_32k */ - 12,12,12,12,12, 12,12,12,12,12, 12,12,12,12,12, 6,12,12,12,12, 6,6,12,12,12, 6,6,6,12,12, 6,6,6,6,12, /* ACELP_48k */ - 12,12,12,12,12, 12,12,12,12,12, 12,12,12,12,12, 6,12,12,12,12, 6,6,12,12,12, 6,6,6,12,12, 6,6,6,6,12 /* ACELP_64k */ -}; - -/* bit allocation table for adaptive codebook (pitch) (ACELP@12.8kHz) */ -/* the 4 values correspond to 4 subframes */ -const Word16 ACB_bits_tbl[] = -{ - /* UC VC GC TC0_0 TC0_64 TC0_128 TC0_192 TC64 TC128 TC192 */ - 0,0,0,0, 9,5,5,5, 8,5, 8,5, 6,5,6,6, 0,7,6,6, 0,0,7,6, 0,0,0,7, 0,0,9,6, 0,0,5,9, 0,0,0,8, /* ACELP_7k20 */ - 0,0,0,0, 10,5,5,5, 9,5, 8,5, 6,5,6,6, 0,7,6,6, 0,0,7,5, 0,0,0,7, 0,0,9,6, 0,0,5,9, 0,0,0,9, /* ACELP_8k00 */ - 0,0,0,0, 10,5,5,5, 10,6, 9,6, 6,5,6,6, 0,7,6,6, 0,0,7,6, 0,0,0,7, 0,0,9,6, 0,0,5,9, 0,0,0,9, /* ACELP_11k60 */ - 0,0,0,0, 10,5,5,5, 10,6, 9,6, 6,6,6,6, 0,7,6,6, 0,0,7,6, 0,0,0,7, 0,0,9,6, 0,0,5,9, 0,0,0,9, /* ACELP_12k15 */ - 0,0,0,0, 10,5,5,5, 10,6, 9,6, 6,5,6,6, 0,7,6,6, 0,0,7,6, 0,0,0,7, 0,0,9,6, 0,0,5,9, 0,0,0,9, /* ACELP_12k85 */ - 0,0,0,0, 10,5,5,5, 10,6, 9,6, 6,5,6,6, 0,7,6,6, 0,0,7,6, 0,0,0,7, 0,0,9,6, 0,0,5,9, 0,0,0,9, /* ACELP_13k20 */ - 0,0,0,0, 10,5,5,5, 10,6,10,6, 6,6,6,6, 0,7,6,6, 0,0,7,6, 0,0,0,7, 0,0,9,6, 0,0,5,9, 0,0,0,9, /* ACELP_14k80 */ - 0,0,0,0, 10,5,5,5, 10,6,10,6, 6,6,6,6, 0,7,6,6, 0,0,7,6, 0,0,0,7, 0,0,9,6, 0,0,5,9, 0,0,0,9, /* ACELP_16k40 */ - 0,0,0,0, 10,5,5,5, 10,6,10,6, 6,6,6,6, 0,7,6,6, 0,0,7,6, 0,0,0,7, 0,0,9,6, 0,0,5,9, 0,0,0,9, /* ACELP_22k60 */ - 0,0,0,0, 10,5,5,5, 10,6,10,6, 6,6,6,6, 0,7,6,6, 0,0,7,6, 0,0,0,7, 0,0,9,6, 0,0,5,9, 0,0,0,9, /* ACELP_24k40 */ -}; - -/* bit allocation table for adaptive codebook (pitch) (ACELP@16kHz) */ -/* the 5 values correspond to 5 subframes */ -const Word16 ACB_bits_16kHz_tbl[] = -{ - /* IC GC TC0 TC64 TC128 TC192 TC256 */ - 0,0, 0,0,0, 9,0, 0,0,0, 0,0, 0,0,0, 0,0, 0,0,0, 0,0, 0,0,0, 0,0,0, 0,0, 0,0,0,0, 0, /* ACELP_8k00 */ - 0,0, 0,0,0, 10,0, 0,0,0, 0,0, 0,0,0, 0,0, 0,0,0, 0,0, 0,0,0, 0,0,0, 0,0, 0,0,0,0, 0, /* ACELP_14k80 */ - 10,6,10,6,6, 10,6,10,6,6, 5,8,10,6,6, 0,6,10,6,6, 0,0,10,6,6, 0,0,0,10,6, 0,0,0,0,10, /* ACELP_22k60 */ - 10,6,10,6,6, 10,6,10,6,6, 5,8,10,6,6, 0,6,10,6,6, 0,0,10,6,6, 0,0,0,10,6, 0,0,0,0,10, /* ACELP_24k40 */ - 10,6,10,6,6, 10,6,10,6,6, 6,8,10,6,6, 0,6,10,6,6, 0,0,10,6,6, 0,0,0,10,6, 0,0,0,0,10, /* ACELP_29k00 */ - 10,6,10,6,6, 10,6,10,6,6, 6,8,10,6,6, 0,6,10,6,6, 0,0,10,6,6, 0,0,0,10,6, 0,0,0,0,10, /* ACELP_29k20 */ - 10,6,10,6,6, 10,6,10,6,6, 6,8,10,6,6, 0,6,10,6,6, 0,0,10,6,6, 0,0,0,10,6, 0,0,0,0,10, /* ACELP_30k20 */ - 10,6,10,6,6, 10,6,10,6,6, 6,8,10,6,6, 0,6,10,6,6, 0,0,10,6,6, 0,0,0,10,6, 0,0,0,0,10, /* ACELP_30k40 */ - 10,6,10,6,6, 10,6,10,6,6, 6,8,10,6,6, 0,6,10,6,6, 0,0,10,6,6, 0,0,0,10,6, 0,0,0,0,10, /* ACELP_32k */ - 10,6,10,6,6, 10,6,10,6,6, 6,8,10,6,6, 0,6,10,6,6, 0,0,10,6,6, 0,0,0,10,6, 0,0,0,0,10, /* ACELP_48k */ - 10,6,10,6,6, 10,6,10,6,6, 6,8,10,6,6, 0,6,10,6,6, 0,0,10,6,6, 0,0,0,10,6, 0,0,0,0,10 /* ACELP_64k */ -}; - -/* bit allocation table for algebraic (fixed) codebook (innovation) (ACELP@12.8kHz) */ -/* the 4 values correspond to 4 subframes */ -const Word16 FCB_bits_tbl[] = -{ - /* UC VC GC TC0_0 TC0_64 TC0_128 TC0_192 TC64 TC128 TC192 */ - 13,13,13,13, 12,12,12,20, 12,12,12,20, 12, 7,12,12, 12,12, 7,12, 12,12,12,12, 12,12,20,12, 12,12,12,12, 12,12,12,12, 12,12,12,20, /* ACELP_7k20 */ - 13,13,13,13, 12,20,12,20, 12,20,12,20, 20,12,12,12, 20,12,12,12, 20,12,20,12, 20,12,20,20, 20,12,12,20, 20,12,20,12, 12,20,12,20, /* ACELP_8k00 */ - 0, 0, 0, 0, 28,36,28,36, 28,28,28,36, 28,28,28,28, 28,28,28,28, 28,28,36,28, 28,36,28,36, 28,36,28,28, 28,28,28,36, 28,36,28,36, /* ACELP_11k60 */ - 0, 0, 0, 0, 28,36,36,36, 28,36,28,36, 36,28,28,28, 36,28,28,28, 36,28,36,28, 36,36,28,43, 28,36,28,36, 28,36,28,36, 28,36,36,36, /* ACELP_12k15 */ - 0, 0, 0, 0, 36,36,36,43, 36,36,36,36, 36,36,28,36, 36,28,36,36, 36,36,36,36, 36,36,43,43, 36,36,36,36, 36,36,36,43, 36,36,36,43, /* ACELP_12k85 */ - 0, 0, 0, 0, 36,43,36,43, 36,36,36,43, 36,36,36,36, 36,36,36,36, 36,36,43,36, 36,43,43,43, 36,43,36,36, 43,36,43,36, 36,43,36,43, /* ACELP_13k20 */ - 0, 0, 0, 0, 43,50,43,50, 43,43,43,43, 43,43,43,43, 43,43,43,43, 43,43,50,43, 43,50,50,50, 43,43,43,50, 50,43,50,43, 43,50,43,50, /* ACELP_14k80 */ - 0, 0, 0, 0, 50,56,50,56, 50,50,50,56, 56,50,50,50, 56,50,50,50, 56,50,56,56, 56,56,56,56, 50,56,50,56, 50,56,56,56, 50,56,56,56, /* ACELP_16k40 */ - 0, 0, 0, 0, 83,83,83,87, 78,83,83,83, 83,78,83,83, 83,78,83,87, 83,87,83,87, 83,87,87,92, 87,83,87,83, 87,83,87,87, 83,87,87,87, /* ACELP_22k60 */ - 0, 0, 0, 0, 92,92,92,92, 87,92,92,92, 92,87,92,92, 92,87,92,92, 92,92,92,92, 92,92,92,92, 92,92,92,92, 92,92,92,92, 92,92,92,92, /* ACELP_24k40 */ -}; - -/* bit allocation table for algebraic (fixed) codebook (innovation) (ACELP@16kHz) */ -/* the 5 values correspond to 5 subframes */ -const Word16 FCB_bits_16kHz_tbl[] = -{ - /* IC GC TC0 TC64 TC128 TC192 TC256 */ - 0, 0, 0, 0, 0, 12, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* ACELP_8k00 */ - 0, 0, 0, 0, 0, 36, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* ACELP_14k80 */ - 0, 0, 0, 0, 0, 62,56,56,56,62, 62,56,56,56,56, 56,56,56,56,73, 62,56,62,62,62, 56,62,62,62,73, 62,62,62,62,68, /* ACELP_22k60 */ - 0, 0, 0, 0, 0, 68,68,68,73,73, 68,68,68,68,73, 68,73,68,73,73, 73,73,73,73,73, 73,78,73,73,78, 73,78,73,73,78, /* ACELP_24k40 */ - 12,12,12,12,12, 36,28,28,36,36, 36,28,28,36,36, 36,28,28,36,36, 36,28,28,36,36, 36,28,28,36,36, 36,28,28,36,36, /* ACELP_29k00 */ - 12,12,12,12,12, 36,28,28,36,36, 36,28,28,36,36, 36,28,28,36,36, 36,28,28,36,36, 36,28,28,36,36, 36,28,28,36,36, /* ACELP_29k20 */ - 12,12,12,12,12, 36,36,36,36,36, 36,36,36,36,36, 36,36,36,36,36, 36,36,36,36,36, 36,36,36,36,36, 36,36,36,36,36, /* ACELP_30k20 */ - 12,12,12,12,12, 36,36,36,36,36, 36,36,36,36,36, 36,36,36,36,36, 36,36,36,36,36, 36,36,36,36,36, 36,36,36,36,36, /* ACELP_30k40 */ - 12,12,12,12,12, 36,36,36,36,36, 36,36,36,36,36, 36,36,36,36,36, 36,36,36,36,36, 36,36,36,36,36, 36,36,36,36,36, /* ACELP_32k */ - 12,12,12,12,12, 36,36,36,36,36, 36,36,36,36,36, 36,36,36,36,36, 36,36,36,36,36, 36,36,36,36,36, 36,36,36,36,36, /* ACELP_48k */ - 12,12,12,12,12, 36,36,36,36,36, 36,36,36,36,36, 36,36,36,36,36, 36,36,36,36,36, 36,36,36,36,36, 36,36,36,36,36 /* ACELP_64k */ -}; - -/* bit allocation table for AVQ bits in active segments (ACELP@16kHz) */ -const Word16 AVQ_bits_16kHz_tbl[] = -{ - /* IC GC TC0 TC64 TC128 TC192 TC256 */ - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* ACELP_8k00 */ - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* ACELP_14k80 */ - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* ACELP_22k60 */ - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* ACELP_24k40 */ - 78, 78, 78, 78, 78, 48, 48, 48, 48, 49, 48, 49, 49, 48, 49, 50, 50, 51, 52, 52, 50, 54, 53, 54, 54, 55, 55, 55, 55, 54, 52, 56, 56, 56, 56, /* ACELP_29k00 */ - 79, 79, 79, 79, 78, 49, 49, 49, 49, 49, 50, 49, 49, 50, 49, 52, 52, 51, 52, 52, 54, 54, 53, 54, 54, 56, 55, 55, 56, 56, 56, 56, 56, 56, 56, /* ACELP_29k20 */ - 78, 78, 78, 78, 78, 50, 50, 50, 50, 49, 51, 50, 50, 50, 50, 53, 53, 53, 52, 52, 55, 55, 55, 54, 54, 57, 57, 56, 56, 56, 57, 57, 57, 57, 56, /* ACELP_30k20 */ - 79, 79, 79, 79, 78, 51, 51, 51, 50, 50, 51, 51, 51, 51, 51, 54, 54, 53, 53, 53, 56, 56, 56, 55, 54, 58, 57, 57, 57, 57, 58, 58, 58, 57, 57, /* ACELP_30k40 */ - 86, 85, 85, 85, 85, 57, 57, 57, 57, 57, 58, 58, 57, 57, 57, 60, 60, 60, 60, 59, 62, 62, 62, 62, 61, 64, 64, 64, 63, 63, 64, 64, 64, 64, 64, /* ACELP_32k */ - 143,142,142,142,142, 116,115,115,115,115, 116,116,115,115,115, 119,119,118,118,118, 121,121,121,121,121, 124,124,123,123,123, 126,126,126,126,126, /* ACELP_48k */ - 207,206,206,206,206, 180,179,179,179,179, 180,180,179,179,179, 183,183,182,182,182, 185,185,185,185,185, 188,188,187,187,187, 190,190,190,190,190 /* ACELP_64k */ -}; - -/* bit allocation table for reserved bits (ACELP@12.8kHz) */ -const Word16 reserved_bits_tbl[] = -{ - /* UC VC GC TC0_0 TC0_64 TC0_128 TC0_192 TC64 TC128 TC192 */ - 1, 0, 0, 0, 0, 2, 4, 0, 3, 0, /* ACELP_7k20 */ - 14, 0, 0, 0, 0, 0, 1, 0, 0, 0, /* ACELP_8k00 */ - 0, 0, 0, 0, 1, 3, 6, 2, 6, 0, /* ACELP_11k60 */ - 0, 0, 0, 0, 2, 4, 0, 3, 7, 0, /* ACELP_12k15 */ - 0, 0, 0, 0, 1, 3, 0, 2, 0, 0, /* ACELP_12k85 */ - 0, 0, 0, 0, 1, 4, 1, 3, 0, 0, /* ACELP_13k20 */ - 0, 0, 0, 0, 2, 5, 2, 4, 1, 1, /* ACELP_14k80 */ - 0, 0, 0, 0, 2, 0, 5, 5, 3, 3, /* ACELP_16k40 */ - 0, 0, 2, 2, 0, 1, 3, 0, 0, 1, /* ACELP_22k60 */ - 0, 0, 1, 1, 3, 8, 19, 7, 11, 11, /* ACELP_24k40 */ -}; - - - -/*----------------------------------------------------------------------------------* - * Power of 2 table (2^x) - *----------------------------------------------------------------------------------*/ - -const Word32 pow2[] = -{ - 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, 65536, 131072, 262144, 524288, 1048576 -}; -const Word16 crit_bins_corr_fx[CRIT_NOIS_BAND] = -{ - /*.9f, .9f, .85f, .8f, .775f, .75f, .725f , .7f , .675f, .65f, .625f , .60f, .6f, .6f, .6f, .6f, .6f, .6f, .6f, .6f, .6f, .6f, .6f*/ - 29491, 29491, 27853, 26214, 25395, 24576, 23577 , 22938, 22118, 21299, 20480, - 19661, 19661, 19661, 19661, 19661, 19661, 19661, 19661, 19661, 19661, 19661, 19661 -}; -const Word16 crit_bins[CRIT_NOIS_BAND] = -{ - 4, 4, 4, 4, 4, 5, 6, 6, 6, 8, 8, 10, 11, 13, 15, 18, 22, 16, 16, 20, 20, 20, 16 -}; -const Word16 mfreq_bindiv_loc[] = { 8, 8, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 32, 32, 32 }; -const Word16 mfreq_bindiv_LD[] = {10, 10, 10, 10, 11, 12, 14, 15, 16, 19, 21, 24, 28, 32, 38, 45, 55, 70, 90, 110}; -const Word16 mfreq_loc_LD[] = { 100, 200, 300, 400, 510, 630, 770, 920, 1080, 1270, 1480, - 1720, 2000, 2320, 2700, 3150, 3700, 4400, 5300, (6400-BIN_16kdct) - }; - -/* bit allocation table for gain quantizer (ACELP@12.8kHz) */ -/* the 4 values allocated correspond to 4 subframes */ - -/*----------------------------------------------------* - * Table for FFT - -----------------------------------------------------*/ - -const Word16 Odx_fft32_5[32] = { 0,27,22,17,12,7,2,29,24,19,14,9,4,31,26,21,16,11,6,1,28,23,18,13,8,3,30,25,20,15,10,5 }; - -const Word16 Idx_dortft160[160] = -{ - 0,65,130,35,100,5,70,135,40,105,10,75,140,45,110,15,80,145, - 50,115,20,85,150,55,120,25,90,155,60,125,30,95,96,1,66,131, - 36,101,6,71,136,41,106,11,76,141,46,111,16,81,146,51,116,21, - 86,151,56,121,26,91,156,61,126,31,32,97,2,67,132,37,102,7, - 72,137,42,107,12,77,142,47,112,17,82,147,52,117,22,87,152,57, - 122,27,92,157,62,127,128,33,98,3,68,133,38,103,8,73,138,43, - 108,13,78,143,48,113,18,83,148,53,118,23,88,153,58,123,28,93, - 158,63,64,129,34,99,4,69,134,39,104,9,74,139,44,109,14,79, - 144,49,114,19,84,149,54,119,24,89,154,59,124,29,94,159 -}; - -const Word16 nextstate[STATES][2] = {{0, 1}, {2, 3}, {4, 5}, {6, 7}, {0, 1}, {2, 3}, {4, 5}, {6, 7}};/*current state points to next two states */ - -const Word16 fine_gain_bits[8] = {0, 0, 0, 1, 2, 2, 4, 5}; - - -const Word16 resize_huffsizn[32] = -{ - 0, 0, 0, 0, 0, 11, 10, 10, 9, 8, 7, 6, 5, 4, 3, 2, - 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 0, 0, 0, 0, 0, 0 -}; - -const Word16 huffsizn[32] = -{ - 7, 7, 7, 7, 7, 7, 7, 7, 6, 6, 6, 6, 4, 4, 3, 3, - 3, 3, 4, 4, 6, 6, 6, 6, 7, 7, 7, 7, 7, 7, 7, 7 -}; - -const Word16 huffnorm_tran[32] = -{ - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,122, 10, 6, 1, - 0, 3, 2, 26, 58, 186, 442, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 -}; - -const Word16 huffsizn_tran[32] = -{ - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 5, 3, 2, 2, - 2, 4, 6, 8, 9, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 -}; - -const Word16 pgain_huffsizn[32] = -{ - 10, 11, 10, 10, 9, 8, 6, 5, 5, 4, 4, 4, 4, 4, 4, 4, - 4, 4, 4, 4, 4, 4, 5, 5, 6, 7, 7, 8, 10, 10, 12, 12 -}; - -const Word16 dicnlg2[40] = -{ - 34, 33, 32, 31, 30, 29, 28, 27, 26, 25, - 24, 23, 22, 21, 20, 19, 18, 17, 16, 15, - 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, - 4, 3, 2, 1, 0, -1, -2, -3, -4, -5 -}; - -/*** Table for quantization of MLT coefficients ***/ -const Word16 norm_order_48[NB_SFM] = -{ - 0, 1, 8, 9, 16, 20, 24, 28, 32, 36, 40, 41, 37, 33, 29, 25, 21, 17, 11, 10, 3, 2, - 4, 5, 12, 13, 18, 22, 26, 30, 34, 38, 42, 43, 39, 35, 31, 27, 23, 19, 15, 14, 7, 6 -}; -const Word16 norm_order_32[SFM_N_SWB] = -{ - 0, 1, 8, 9, 16, 20, 24, 28, 32, 36, 37, 33, 29, 25, 21, 17, 11, 10, 3, 2, - 4, 5, 12, 13, 18, 22, 26, 30, 34, 38, 35, 31, 27, 23, 19, 15, 14, 7, 6 -}; -const Word16 norm_order_16[SFM_N_WB] = -{ - 0, 1, 8, 9, 16, 20, 24, 21, 17, 11, 10, 3, 2, - 4, 5, 12, 13, 18, 22, 25, 23, 19, 15, 14, 7, 6 -}; - -const Word16 intl_bw_16[N_INTL_GRP_16] = {16, 16}; -const Word16 intl_bw_32[N_INTL_GRP_32] = {16, 24}; -const Word16 intl_bw_48[N_INTL_GRP_48] = {16, 24, 32}; -const Word16 intl_cnt_16[N_INTL_GRP_16] = {4, 1}; -const Word16 intl_cnt_32[N_INTL_GRP_32] = {4, 4}; -const Word16 intl_cnt_48[N_INTL_GRP_48] = {4, 3, 2}; - -const Word16 band_start_HQ[44] = -{ - 0, 8, 16, 24, 32, 40, 48, 56, 64, 72, 80, 88, - 96, 104, 112, 120, 128, 144, 160, 176, 192, 208, 224, 240, - 256, 280, 304, 328, 352, 376, 400, 424, 448, 472, 496, 520, - 544, 576, 608, 640, 672, 704, 736, 768 -}; - -const Word16 band_end_HQ[44] = -{ - 8, 16, 24, 32, 40, 48, 56, 64, 72, 80, 88, 96, - 104, 112, 120, 128, 144, 160, 176, 192, 208, 224, 240, 256, - 280, 304, 328, 352, 376, 400, 424, 448, 472, 496, 520, 544, - 576, 608, 640, 672, 704, 736, 768, 800 -}; - -const Word16 band_len_HQ[44] = -{ - 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, - 8, 8, 8, 8, 16, 16, 16, 16, 16, 16, 16, 16, - 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, - 32, 32, 32, 32, 32, 32, 32, 32 -}; - -const Word16 band_start_wb[26] = -{ - 0, 8, 16, 24, 32, 40, 48, 56, 64, 72, 80, 88, - 96, 104, 112, 120, 128, 144, 160, 176, 192, 208, 224, 240, - 256, 288 -}; - -const Word16 band_end_wb[26] = -{ - 8, 16, 24, 32, 40, 48, 56, 64, 72, 80, 88, 96, - 104, 112, 120, 128, 144, 160, 176, 192, 208, 224, 240, 256, - 288, 320 -}; - -const Word16 band_len_wb[26] = -{ - 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, - 8, 8, 8, 8, 16, 16, 16, 16, 16, 16, 16, 16, - 32, 32 -}; - -const Word16 band_len_harm[SFM_N_HARM_FB] = -{ - 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, - 16, 16, 16, 16, 16, 16, 32, 32, 32, 48, 48, 48, 48, 64, 64, 64, 96 -}; - -const Word16 band_start_harm[SFM_N_HARM_FB] = -{ - 0, 8, 16, 24, 32, 40, 48, 56, 64, 72, 80, 88, 96, 104, 112, 120, - 128, 144, 160, 176, 192, 208, 224, 256, 288, 320, 368, 416, 464, 512, 576, 640, 704 -}; - -const Word16 band_end_harm[SFM_N_HARM_FB] = -{ - 8, 16, 24, 32, 40, 48, 56, 64, 72, 80, 88, 96, 104, 112, 120, 128, - 144, 160, 176, 192, 208, 224, 256, 288, 320, 368, 416, 464, 512, 576, 640, 704, 800 -}; - -const Word16 min_lat_bits_SN_fx[] = {-1, -1, 17, 12, 17, 17, -1, -1, 17, 12, 17, 17, -1, -1, 22, -1, 32, 26 - }; - -const Word16 min_lat_bits_pred_fx[] = {17, 18, 9, 15, -1, 21, 17, 14, 9, 15, -1, 21, 17, -1, -1, 26, -1, 26, 16}; - -const Word16 offset_in_lvq_mode_SN_fx[][21] = -{ - {0}, /* I NB */ - {0,1,1,1,1,1,2,3,3,3,3,4,4,4,5}, /* UV NB*/ - {0,1,1,1,1,2,3,4,5,5,6,6,7,7,7,7,7,8,8,8,9}, /* V NB */ - {0,0,0,0,1,1,1,2,3,4,5,6,6,7,8,9,10,11,12,13,14}, /* G NB */ - {0,1,1,1,1,2,3,4,5,5,5,6,6,6,7,8}, /* T NB */ - {0,0,0,0,1,2,2,2,2,3,4,5}, /* A NB */ - {0}, /* I WB */ - {0,1,1,1,2,3,3,3,3,3,3,4,4,4,5}, /* UV WB*/ - {0,1,1,1,2,3,3,3,4,5,6,7,8,9,9,10,11,12,12,12,13}, /* V WB */ - {0,0,0,0,1,1,1,2,3,4,5,6,6,7,8,9,10,11,12,13,14}, /* G WB */ - {0,1,1,1,2,3,3,4,5,5,5,6,6,7,8,9,10}, /* T WB */ - {0,0,0,0,1,2,2,2,3,4,4,4,4,4,4,4,4,4,4,5}, /* A WB */ - {0}, - {0}, - {0,0,0,0,0,0,1,2,3,3,4,5,6,6,6,7}, /* V 16k */ - {0}, /* G 16k */ - {0,1}, /* T 16k */ - {0}, /*{0,0,0,0,0,0,0,0,0,0,1} */ /* A 16k */ -}; -const Word16 offset_in_lvq_mode_pred_fx[][32] = -{ - {0,0,0,0,1,2,2,2,3,4,5,5,5,5,5,5,5,5,5,6}, /* I NB */ - {0,1,1,1,2,3,4,4,4,4,4,5,5,5,6}, /* UV NB */ - {0,0,0,0,0,0,0,0,0,0,1,1,1,1,2,3,4,4,5,6,7,8,9,10,10,11,12,13,13,13,14}, /* V NB */ - {0,0,0,0,1,1,1,2,3,4,5,6,6,7,8,9,10,11,12,13,14}, /* G NB */ - {0}, /* T NB */ - {0,0,0,0,1,2,2,2,2,3,4,5}, /* A NB */ - {0,0,0,0,1,2,2,2,3,4,5,5,5,5,5,5,5,5,5,6}, /* I WB */ - {0,1,1,1,2,3,4,4,4,4,4,5,5,5,6}, /* UV WB */ - {0,0,0,0,0,0,0,0,0,0,1,1,1,1,2,3,4,4,5,6,7,8,9,10,10,11,12,13,13,13,14}, /* V WB */ - {0,0,0,0,1,1,1,2,3,4,5,6,6,7,8,9,10,11,12,13,14}, /* G WB */ - {0}, /* T WB */ - {0,0,0,0,1,2,2,2,3,4,4,4,4,4,4,4,4,4,4,5}, /* A WB */ - {0,0,0,0,1,2,2,2,3,4,5,5,5,5,5,5,5,5,5,6}, /* I 16k */ - {0}, /* UV 16k */ - {0,0,0,0,0,0,1,2,3,3,4,5,6,6,6,7}, /* V 16k */ - {0,0,0,0,0,0,1,2,3,4,5,6}, /* G 16k */ - {0}, /* T 16k */ - {0,0,0,0,0,0,1,2,3,4,5,6}, /* A 16k */ - {0,0,0,0,0,1,1,1,2,3,4,5,6,6,7,8,9,10,11,12,13,14}, /* G WB MA*/ -}; - - -const Word16 offset_lvq_modes_SN_fx[] = {-1,-1,26,51,77,96,-1,-1,12,36,66,90,-1,-1,105,-1,88,102, - 112 - }; /* CNG */ - -const Word16 offset_lvq_modes_pred_fx[] = {74, 95, 15, 45, -1, 66, 81, 102, 0, 30, -1, 60, 88, -1, 109, 117, -1, 139, 124}; - -const Word16 sfm_width[20] = {3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 5, 5, 6, 6, 6, 7, 8}; -const Word16 a_table_fx[20] = {8, 6, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 4, 5, 7, 11}; - - -const Word16 inner_frame_tbl[4] = {L_FRAME8k, L_FRAME16k, L_FRAME32k, L_FRAME48k}; /* corresponds to NB, WB, SWB, FB */ - - - -/*------------------------------------------------------------------------------* - * SWB BWE tables - *------------------------------------------------------------------------------*/ - -const Word16 fb_bwe_subband[DIM_FB+1] = {640, 680, 720, 800}; -const Word16 fb_bwe_sm_subband[DIM_FB] = {656, 696, 760}; - -/*------------------------------------------------------------------------------* - * SWB TBE tables - *------------------------------------------------------------------------------*/ - -const Word16 lsf_q_num_bits[NUM_Q_LSF] = { 4, 4, 3, 3, 3 }; - -const Word16 skip_bands_SWB_TBE[NUM_SHB_SUBFR+1] = {0, 20, 40, 60, 80, 100, 120, 140, 160, 180, 200, 220, 240, 260, 280, 300, 320}; /* bands for SWB TBE quantisation */ -const Word16 skip_bands_WB_TBE[NUM_SHB_SUBFR/2+1] = {0, 10, 20, 30, 40, 50, 60, 70, 80}; /* bands for WB TBE quantisation */ - -const Word16 swb_lsp_prev_interp_init[10] = {32767, 31164, 26510, 19261, 10126, 0, -10126, -19261, -26510, -31164}; -/* st->swb_lsp_prev_interp[i] = (float)cos( (float)i * PI / (float)10.0f )*/ - -const Word16 allpass_poles_3_ov_2[9] = /* Q15 */ -{ - 2368, - 20545, - 30606, - 25520, - 7188, - 31808, - 28575, - 14384, - 32472 -}; -const Word16 decimate_3_ov_2_lowpass_num[3] = /* Q15 */ -{ - 6399, - 12797, - 6399 -}; -const Word16 decimate_3_ov_2_lowpass_den[3] = /* Q15 */ -{ - 32767, - 0, - 5624 -}; - -const Word16 interpol_frac_shb[NB_SUBFR*2] = -{ - 22938, 9830, 13107, 19660, 3277, 29490, 0, 32767 /* Q15*/ - /*0.7f, 0.3f, 0.4f, 0.6f, 0.1f, 0.9f, 0.0f, 1.0f */ -}; - -/*----------------------------------------------------------------------------------* -* ACELP/HQ core switching -*----------------------------------------------------------------------------------*/ -/* bandwidths */ -const Word16 Nb[ NB_SFM] = -{ - 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 16, 16, 16, 16, - 16, 16, 16, 16, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, - 32, 32, 32, 32, 32, 32, 32, 32 -}; - -/* log2(Nb) to calculate minimum bits for one pulse in PVQ */ -const Word16 LNb[ NB_SFM] = -{ - 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, - 4, 4, 4, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, - 5, 5 -}; - - -const Word16 sin_switch_8[15] = {3212, 6393, 9512, 12540, 15447, 18205, 20788, 23170, - 25330, 27246, 28899, 30274, 31357, 32138, 32610 - }; - -const Word16 sin_switch_16[30] = {1660, 3315, 4962, 6596, 8213, 9810, 11380, 12922, - 14431, 15902, 17333, 18719, 20057, 21344, 22576, 23750, - 24863, 25912, 26895, 27808, 28651, 29419, 30112, 30728, - 31265, 31722, 32097, 32390, 32600, 32726 - }; - - -const Word16 sin_switch_32[60] = {844, 1687, 2529, 3369, 4207, 5043, 5875, 6703, - 7526, 8345, 9158, 9965, 10766, 11559, 12345, 13122, - 13891, 14650, 15400, 16140, 16869, 17586, 18293, 18986, - 19668, 20336, 20991, 21632, 22258, 22870, 23467, 24048, - 24613, 25162, 25694, 26209, 26707, 27187, 27649, 28092, - 28518, 28924, 29311, 29678, 30026, 30354, 30662, 30949, - 31216, 31462, 31688, 31892, 32075, 32237, 32378, 32497, - 32594, 32670, 32725, 32757 - }; - - -const Word16 sin_switch_48[90] = {566, 1131, 1696, 2261, 2825, 3388, 3950, 4511, - 5070, 5628, 6185, 6739, 7292, 7842, 8390, 8935, - 9478, 10018, 10555, 11089, 11620, 12147, 12670, 13190, - 13706, 14218, 14725, 15228, 15727, 16220, 16709, 17194, - 17672, 18146, 18614, 19077, 19534, 19985, 20431, 20870, - 21303, 21729, 22149, 22563, 22970, 23370, 23763, 24148, - 24527, 24899, 25263, 25619, 25968, 26309, 26642, 26968, - 27285, 27594, 27895, 28188, 28472, 28747, 29015, 29273, - 29523, 29764, 29996, 30219, 30433, 30639, 30835, 31021, - 31199, 31367, 31526, 31676, 31816, 31946, 32068, 32179, - 32281, 32373, 32456, 32529, 32592, 32646, 32690, 32724, - 32748, 32763 - }; - - -const Word16 one_on_win_48k_fx[210] = -{ - 16399, 16412, 16425, 16439, 16452, 16465, 16479, 16492, - 16506, 16519, 16533, 16547, 16561, 16575, 16589, 16603, - 16618, 16632, 16647, 16662, 16677, 16692, 16707, 16722, - 16738, 16754, 16770, 16786, 16802, 16818, 16835, 16851, - 16868, 16885, 16902, 16919, 16937, 16955, 16972, 16990, - 17008, 17027, 17045, 17064, 17083, 17102, 17121, 17140, - 17160, 17180, 17200, 17220, 17240, 17261, 17281, 17302, - 17323, 17345, 17366, 17388, 17410, 17432, 17454, 17477, - 17499, 17522, 17545, 17569, 17592, 17616, 17640, 17664, - 17689, 17713, 17738, 17763, 17789, 17814, 17840, 17866, - 17892, 17918, 17945, 17972, 17999, 18027, 18054, 18082, - 18110, 18139, 18167, 18196, 18225, 18255, 18284, 18314, - 18345, 18375, 18406, 18437, 18468, 18499, 18531, 18563, - 18596, 18628, 18661, 18695, 18728, 18762, 18796, 18830, - 18865, 18900, 18935, 18971, 19007, 19043, 19080, 19117, - 19154, 19191, 19229, 19267, 19306, 19345, 19384, 19423, - 19463, 19504, 19544, 19585, 19626, 19668, 19710, 19752, - 19795, 19838, 19882, 19926, 19970, 20015, 20060, 20105, - 20151, 20198, 20244, 20291, 20339, 20387, 20435, 20484, - 20533, 20583, 20633, 20684, 20735, 20787, 20839, 20891, - 20944, 20997, 21051, 21106, 21161, 21216, 21272, 21328, - 21385, 21443, 21501, 21559, 21618, 21678, 21738, 21799, - 21860, 21922, 21984, 22048, 22111, 22175, 22240, 22306, - 22372, 22439, 22506, 22574, 22643, 22712, 22782, 22853, - 22924, 22996, 23069, 23142, 23216, 23291, 23367, 23443, - 23521, 23599, 23677, 23757, 23837, 23918, 24000, 24083, - 24167, 24251 -}; - -const Word16 one_on_win_8k_16k_48k_fx[70] = -{ - 16432, 16472, 16512, 16554, 16596, 16639, 16684, 16730, - 16778, 16826, 16876, 16928, 16981, 17036, 17092, 17150, - 17210, 17271, 17334, 17399, 17465, 17534, 17604, 17676, - 17751, 17827, 17905, 17986, 18068, 18153, 18240, 18329, - 18421, 18515, 18612, 18711, 18813, 18918, 19025, 19135, - 19248, 19364, 19483, 19606, 19731, 19860, 19992, 20128, - 20268, 20411, 20558, 20709, 20865, 21024, 21188, 21357, - 21530, 21708, 21891, 22079, 22273, 22472, 22677, 22888, - 23105, 23329, 23560, 23797, 24041, 24251 -}; - - - -/* short filters for BWE of ACELP->HQ switching frame in Q15 */ -const Word16 hp12800_16000_fx[21] = -{ - -0, 70, -207, 380, -405, 0, 1041, -2668, 4505, - -5968, 6526, -5968, 4505, -2668, 1041, 0, -405, 380, - -207, 70, -0 -}; - -const Word16 hp12800_32000_fx[41] = -{ - -0, 45, 35, -47, -104, 0, 191, 156, - -203, -422, -0, 675, 523, -656, -1341, 0, - 2264, 1943, -2999, -9872, 19678, -9872, -2999, 1943, - 2264, 0, -1341, -656, 523, 675, -0, -422, - -203, 156, 191, 0, -104, -47, 35, 45, -0 -}; - -const Word16 hp12800_48000_fx[61] = -{ - -0, 22, 33, 23, -10, -51, -69, -37, 45, 127, - 140, 40, -136, -271, -238, 0, 326, 507, 349, -143, - -696, -894, -450, 535, 1509, 1696, 521, -1998, -5136, -7735, - 24039, -7735, -5136, -1998, 521, 1696, 1509, 535, -450, -894, - -696, -143, 349, 507, 326, 0, -238, -271, -136, 40, - 140, 127, 45, -37, -69, -51, -10, 23, 33, 22, -0, -}; - - -const Word16 hp16000_32000_fx[33] = -{ - -0, 62, -0, -127, -0, 270, -0, -523, -0, 940, - -0, -1662, -0, 3212, -0, -10353, 16407, -10353, -0, 3212, - -0, -1662, -0, 940, -0, -523, -0, 270, -0, -127, - -0, 62, -0 -}; - -const Word16 hp16000_48000_fx[49] = -{ - -0, 33, 39, -0, -64, -83, -0, 138, 175, 0, - -272, -334, -0, 493, 596, 0, -870, -1059, -0, 1636, - 2120, 0, -4448, -9003, 21858, -9003, -4448, 0, 2120, 1636, - -0, -1059, -870, 0, 596, 493, -0, -334, -272, 0, - 175, 138, -0, -83, -64, -0, 39, 33, -0 -}; - - - -const Word16 inner_frame_tbl_fx[4] = {L_FRAME8k, L_FRAME16k, L_FRAME32k, L_FRAME48k}; /* corresponds to NB, WB, SWB, FB */ - - -const Word16 cu15_fx[28][3] = /*Q13*/ -{ - /* xx/3, xx*xx/3, xx*xx*xx/3 xx v */ - /* 0:*/ { 182, 12, 1 }, /* 1/15 */ - /* 1:*/ { 364, 49, 6 }, /* 2/15 */ - /* 2:*/ { 546, 109, 22 }, /* 3/15 */ - /* 3:*/ { 728, 194, 52 }, /* 4/15 */ - /* 4:*/ { 910, 303, 101 }, /* 5/15 */ - /* 5:*/ { 1092, 437, 175 }, /* 6/15 */ - /* 6:*/ { 1274, 595, 278 }, /* 7/15 */ - /* 7:*/ { 1456, 777, 414 }, /* 8/15 */ - /* 8:*/ { 1638, 983, 590 }, /* 9/15 */ - /* 9:*/ { 1820, 1214, 809 }, /* 10/15 */ - /*10:*/ { 2002, 1468, 1077 }, /* 11/15 */ - /*11:*/ { 2185, 1748, 1398 }, /* 12/15 */ - /*12:*/ { 2367, 2051, 1778 }, /* 13/15 */ - /*13:*/ { 2549, 2379, 2220 }, /* 14/15 */ - /*14:*/ { 2913, 3107, 3314 }, /* 16/15 */ - /*15:*/ { 3095, 3507, 3975 }, /* 17/15 */ - /*16:*/ { 3277, 3932, 4719 }, /* 18/15 */ - /*17:*/ { 3459, 4381, 5550 }, /* 19/15 */ - /*18:*/ { 3641, 4855, 6473 }, /* 20/15 */ - /*19:*/ { 3823, 5352, 7493 }, /* 21/15 */ - /*20:*/ { 4005, 5874, 8615 }, /* 22/15 */ - /*21:*/ { 4187, 6420, 9844 }, /* 23/15 */ - /*22:*/ { 4369, 6991, 11185 }, /* 24/15 */ - /*23:*/ { 4551, 7585, 12642 }, /* 25/15 */ - /*24:*/ { 4733, 8204, 14221 }, /* 26/15 */ - /*25:*/ { 4915, 8847, 15925 }, /* 27/15 */ - /*26:*/ { 5097, 9515, 17761 }, /* 28/15 */ - /*27:*/ { 5279, 10207, 19733 }, /* 29/15 */ -}; - -const Word16 cu4_fx[6][3] = /*Q13*/ -{ - /* xx/3, xx*xx/3, xx*xx*xx/3 xx v */ - /* 0:*/ { 683, 171, 43 }, /* 1/4 */ - /* 1:*/ { 1365, 683, 341 }, /* 2/4 */ - /* 2:*/ { 2048, 1536, 1152 }, /* 3/4 */ - /* 3:*/ { 3413, 4267, 5333 }, /* 5/4 */ - /* 4:*/ { 4096, 6144, 9216 }, /* 6/4 */ - /* 5:*/ { 4779, 8363, 14635 }, /* 7/4 */ -}; - -const Word16 ct2_fx[7][14] = -{ - /* accepted configurations */ - /*input 12.8, output : fout/fin Q13*/ - /*8*/ {30, 22, 30, 16, 25, 30, 19, 30, 30, 0, 8, 4, 15, 5120}, - /*16*/ {25, 22, 19, 16, 16, 0, 0, 0, 12, 1, 4, 4, 15, 10240}, - /*32*/ {19, 16, 19, 16, 16, 0, 0, 0, 6, 2, 2, 4, 15, 20480}, - /*48*/ {17, 14, 15, 16, 16, 0, 0, 0, 4, 3, 4, 4, 15, 30720}, - - /*input 16, output :*/ - /*12*/ { 9, 3, 4, 5, 9, 0, 0, 0, 5, 0, 5, 5, 4, 6554}, - /*32*/ { 4, 4, 4, 4, 4, 0, 0, 0, 2, 1, 1, 4, 4, 16384}, - /*48*/ {18, 18, 18, 18, 18, 0, 0, 0, 5, 2, 1, 4, 15, 24576}, -}; - - -/* stable ISF vector */ -const Word16 stable_ISF_fx[M] = -{ 1023, 2048, 3072, 4096, 5120, 6144, 7168, 8192, 9216, 10240, 11264, 12288, 13311, 14335, 15361, 3978}; -/*------------------------------------------------------------------------------* - * SWB CNG table - *------------------------------------------------------------------------------*/ -const Word16 lsp_shb_prev_tbl_fx[LPC_SHB_ORDER]= -{ - /*Q15 */ - 0, - 1638, - 3277, - 4915, - 6554, - 8192, - 9830, - 11469, - 13107, - 14746 -}; -const Word16 ENR_ATT_fx[5] = /*Q8*/ -{ - 459, 357, 281, 255, 255 -}; - -const Word16 sin_table256_fx[] = -{ - 101, 302, 503, 704, 905, 1106, 1307, 1507, 1708, - 1909, 2110, 2310, 2511, 2711, 2912, 3112, 3312, 3512, - 3712, 3911, 4111, 4310, 4510, 4709, 4907, 5106, 5305, - 5503, 5701, 5899, 6097, 6294, 6491, 6688, 6885, 7081, - 7278, 7473, 7669, 7864, 8059, 8254, 8449, 8643, 8836, - 9030, 9223, 9416, 9608, 9800, 9992, 10183, 10374, 10565, - 10755, 10945, 11134, 11323, 11511, 11699, 11887, 12074, 12261, - 12447, 12633, 12818, 13003, 13187, 13371, 13554, 13737, 13919, - 14101, 14282, 14463, 14643, 14823, 15002, 15180, 15358, 15535, - 15712, 15888, 16064, 16239, 16413, 16587, 16760, 16932, 17104, - 17275, 17446, 17616, 17785, 17953, 18121, 18288, 18455, 18621, - 18786, 18950, 19114, 19277, 19439, 19601, 19761, 19921, 20081, - 20239, 20397, 20554, 20710, 20865, 21020, 21174, 21327, 21479, - 21631, 21781, 21931, 22080, 22228, 22375, 22522, 22668, 22812, - 22956, 23099, 23241, 23383, 23523, 23663, 23801, 23939, 24076, - 24212, 24347, 24481, 24614, 24746, 24878, 25008, 25138, 25266, - 25394, 25520, 25646, 25771, 25894, 26017, 26139, 26259, 26379, - 26498, 26616, 26733, 26848, 26963, 27077, 27190, 27301, 27412, - 27522, 27630, 27738, 27844, 27950, 28054, 28158, 28260, 28361, - 28461, 28560, 28658, 28755, 28851, 28946, 29040, 29132, 29224, - 29314, 29404, 29492, 29579, 29665, 29750, 29833, 29916, 29997, - 30078, 30157, 30235, 30312, 30388, 30462, 30536, 30608, 30680, - 30750, 30819, 30886, 30953, 31018, 31082, 31146, 31207, 31268, - 31328, 31386, 31443, 31499, 31554, 31608, 31660, 31711, 31761, - 31810, 31858, 31904, 31950, 31994, 32037, 32078, 32119, 32158, - 32196, 32233, 32268, 32303, 32336, 32368, 32398, 32428, 32456, - 32483, 32509, 32534, 32557, 32579, 32600, 32620, 32638, 32656, - 32672, 32686, 32700, 32712, 32723, 32733, 32742, 32749, 32756, - 32760, 32764, 32767, 32767 -}; -/*----------------------------------------------------------------------------------* - * 2nd order high-pass filter with cut-off frequency at 400 Hz. - * Designed with Chebyshev of 2nd type - * Optimized for fixed-point to get the following frequency response: - * - * frequency: 0Hz 100Hz 200Hz 300Hz 400Hz 630Hz 1.5kHz 3kHz - * dB loss: -infdB -30dB -20dB -10dB -3dB +6dB +1dB 0dB - * - * Algorithm: - * - * y[i] = b[0]*x[i] + b[1]*x[i-1] + b[2]*x[i-2] - * + a[1]*y[i-1] + a[2]*y[i-2]; - * - * short b[3] = {3660, -7320, 3660}; in Q12 - * short a[3] = {4096, 7320, -3540}; in Q12 - *----------------------------------------------------------------------------------*/ -const Word16 b_hp400_fx[3] = { 3660, -7320, 3660}; /* Q12 (/4) */ -const Word16 a_hp400_fx[3] = {16384, 29280, -14160}; /* Q12 (x4) */ -/*----------------------------------------------------------------------------------* - * 15th-order band-pass 6kHz to 7kHz FIR filter. - * - * frequency: 4kHz 5kHz 5.5kHz 6kHz 6.5kHz 7kHz 7.5kHz 8kHz - * dB loss: -60dB -45dB -13dB -3dB 0dB -3dB -13dB -45dB - * - * gain = 4.0 - *----------------------------------------------------------------------------------*/ -const Word16 fir_6k_7k_fx[31] = -{ - -32, 47, 32, -27, -369, - 1122, -1421, 0, 3798, -8880, - 12349, -10984, 3548, 7766, -18001, - 22118, -18001, 7766, 3548, -10984, - 12349, -8880, 3798, 0, -1421, - 1122, -369, -27, 32, 47, - -32 -}; - - -const Word16 no_lead_fx[][MAX_NO_SCALES*2] = -{ - { 1, 0, 0, 1, 0, 0, }, /* 14 */ - { 2, 0, 0, 1, 0, 0, }, /* 15 */ - { 4, 2, 0, 1, 0, 0, }, /* 18 */ - { 4, 2, 0, 2, 0, 0, }, /* 19 */ - { 7, 5, 2, 5, 4, 2, }, /* 25 */ - { 8, 8, 3, 8, 6, 2, }, /* 28 */ /* mode UV WB*/ - { 4, 2, 0, 1, 0, 0, }, /* 18 */ - { 4, 0, 0, 2, 1, 0, }, /* 19 */ - { 9, 8, 8, 2, 2, 1, }, /* 24 */ - { 8, 5, 2, 5, 2, 1, }, /* 25 */ - { 18, 16, 8, 5, 5, 1, }, /* 29 */ - { 24, 21, 10, 8, 8, 2, }, /* 32 */ /* mode UV NB*/ - - { 2, 0, 0, 2, 0, 0, }, /* 17 */ - { 4, 2, 0, 1, 0, 0, }, /* 18 */ - { 7, 5, 2, 2, 0, 0, }, /* 21 */ - { 5, 2, 1, 4, 1, 0, }, /* 22 */ - { 8, 5, 2, 5, 2, 0, }, /* 25 */ - { 8, 7, 4, 5, 3, 2, }, - { 8, 8, 4, 6, 5, 2, }, - { 13, 8, 5, 6, 5, 2, }, - { 13, 8, 5, 8, 6, 2, }, - { 13, 8, 5, 11, 8, 2, }, /* 30 */ - { 24, 21, 8, 9, 8, 2, }, /* 32 */ - { 23, 18, 8, 13, 11, 3, }, - { 23, 21, 8, 17, 13, 4, }, /* 34 */ - { 31, 31, 17, 26, 25, 9, }, /* 37 */ /* mode V WB*/ - { 2, 0, 0, 2, 2, 0, }, /* 17 */ - { 4, 2, 0, 1, 0, 0, }, /* 18 */ - { 7, 5, 2, 2, 2, 0, }, /* 22 */ - { 8, 7, 2, 2, 2, 0, }, /* 23 */ - { 11, 8, 2, 2, 2, 0, }, /* 24 */ - { 13, 13, 9, 2, 2, 0, }, /* 25 */ - { 13, 11, 7, 5, 2, 0, }, /* 27 */ - { 18, 14, 9, 5, 5, 2, }, /* 29 */ - { 31, 31, 14, 11, 11, 5, }, /* 34 */ - { 31, 31, 27, 24, 21, 14, }, /* 37 */ /* mode V NB */ - { 5, 4, 0, 0, 0, 0, }, /* 12 (11.883) */ - { 2, 0, 0, 2, 0, 0, }, /* 16 (15.826) */ - { 4, 2, 0, 2, 0, 0, }, /* 19 (18.572) */ - { 5, 4, 0, 2, 0, 0, }, /* 20 (19.796) */ - { 7, 5, 2, 2, 0, 0, }, /* 21 (20.910) */ - { 8, 7, 2, 2, 0, 0, }, /* 22 (21.776) */ - { 5, 5, 2, 4, 2, 0, }, /* 23 (22.959) */ - { 8, 8, 5, 4, 2, 0, }, /* 25 (24.992) */ - { 8, 8, 7, 5, 2, 0, }, /* 26 (25.904) */ - { 13, 9, 8, 5, 2, 0, }, /* 27 (26.829) */ - { 13, 11, 8, 5, 5, 1, }, /* 28 (27.989) */ - { 13, 9, 8, 8, 5, 2, }, /* 29 (28.984) */ - { 22, 16, 10, 6, 5, 2, }, /* 30 (29.980) */ - { 21, 14, 10, 8, 7, 2, }, /* 31 (30.966) */ - { 24, 21, 10, 8, 8, 2, }, /* 32 (31.995) */ /* G WB*/ - - { 5, 4, 1, 0, 0, 0, }, /* 12 (11.925) */ - { 2, 0, 0, 2, 0, 0, }, /* 16 (15.826) */ - { 5, 4, 1, 1, 0, 0, }, /* 19 (18.745) */ - { 5, 4, 1, 2, 0, 0, }, /* 20 (19.838) */ - { 7, 5, 2, 2, 0, 0, }, /* 21 (20.910) */ - { 8, 5, 2, 2, 1, 0, }, /* 22 (21.985) */ - { 9, 8, 5, 2, 1, 0, }, /* 23 (22.815) */ - { 14, 13, 8, 2, 2, 0, }, /* 25 (24.996) */ - { 13, 8, 7, 4, 2, 0, }, /* 26 (25.993) */ - { 13, 9, 8, 5, 2, 2, }, /* 27 (26.954) */ - { 18, 13, 8, 5, 2, 2, }, /* 28 (27.992) */ - { 21, 13, 11, 5, 3, 2, }, /* 29 (28.996) */ - { 22, 21, 13, 5, 5, 2, }, /* 30 (29.988) */ - { 23, 21, 17, 7, 5, 2, }, /* 31 (30.962) */ - { 27, 23, 21, 8, 5, 2, }, /* 32 (31.987) */ /* G NB*/ - { 2, 0, 0, 2, 0, 0, }, /* 17 */ - { 4, 2, 0, 1, 0, 0, }, /* 18 */ - { 4, 1, 0, 4, 0, 0, }, /* 21 */ - { 5, 2, 0, 4, 1, 0, }, /* 22 */ - { 8, 5, 2, 4, 0, 0, }, /* 24 */ - { 8, 5, 2, 5, 2, 0, }, /* 25 */ - { 14, 10, 5, 5, 5, 1, }, /* 28 */ - { 14, 10, 5, 8, 8, 4, }, /* 30 */ - { 13, 10, 5, 13, 8, 8, }, - { 23, 21, 8, 8, 8, 4, }, - { 23, 18, 5, 13, 8, 8, }, /* 33 */ - /* mode T WB */ - { 2, 0, 0, 2, 2, 0, }, /* 17 */ - { 4, 2, 0, 1, 0, 0, }, /* 18 */ - { 7, 5, 2, 2, 2, 0, }, /* 22 */ - { 8, 7, 4, 2, 2, 0, }, /* 23 */ - { 11, 8, 5, 2, 2, 0, }, /* 24 */ - { 18, 8, 5, 2, 2, 0, }, /* 25 */ - { 16, 8, 5, 5, 5, 2, }, /* 28 */ - { 28, 23, 8, 5, 5, 5, }, /* 31 */ - { 31, 31, 8, 5, 5, 7, }, /* 32 */ /* mode T NB */ - - { 18, 18, 11, 9, 6, 5, }, /* 31 */ - { 24, 23, 13, 9, 6, 5, }, /* 32 */ /* mode G 16k */ - - { 24, 23, 13, 9, 6, 5, }, /* 32 (31.998) */ - { 36, 31, 18, 9, 6, 5, }, /* 33 (32.983) */ /* T 16k */ - - { 2, 0, 0, 2, 2, 0, }, /* 17 */ - { 7, 5, 2, 2, 0, 0, }, /* 21 */ - { 7, 5, 2, 2, 2, 0, }, /* 22 */ - { 9, 8, 3, 4, 2, 0, }, /* 25 */ - { 11, 9, 8, 4, 2, 0, }, /* 26 */ - { 48, 48, 34, 13, 11, 9 }, /* 36 */ /* mode AUDIO_WB 36 + 4 + 1 */ - - { 22, 10, 3, 0, 0, 0 }, /* 17 */ - { 6, 6, 2, 2, 0, 0 }, /* 21 */ - { 6, 6, 2, 2, 2, 0 }, /* 22 */ - { 23, 10, 3, 2, 2, 0 }, /* 26 */ - { 32, 16, 3, 2, 2, 0 }, /* 27 */ /* AUDIO_NB */ - { 39, 30, 12, 2, 2, 0 }, /* 28 */ /* AUDIO_NB */ - { 11, 9, 8, 4, 2, 0, }, /* 26 */ - { 48, 48, 48, 13, 9, 8 }, /* 36 */ /* mode AUDIO_WB 16k 15-36 + 4 + 1*/ - { 8, 7, 2, 2, 0, 0, }, /* 22 (21.776) */ - { 13, 13, 5, 5, 5, 0, }, /* 28 (27.994) */ - { 18, 17, 5, 5, 5, 1, }, /* 29 (28.996) */ - { 17, 13, 5, 8, 6, 2, }, /* 30 (29.991) */ - { 23, 21, 8, 9, 8, 3, }, /* 32 (31.992) */ - { 31, 29, 16, 8, 8, 3, }, /* 33 (32.993) */ - { 31, 25, 16, 12, 8, 8, }, /* 34 (33.968) */ - { 46, 48, 18, 18, 18, 12, }, /* 37 (36.995) */ /* VOICED 16k */ - { 14, 12, 9, 2, 2, 0, }, /* 25 (24.980) */ - { 15, 13, 3, 2, 2, 0, }, /* 25 (24.974) */ - { 17, 3, 0, 2, 2, 1, }, /* 25 (24.852) */ - { 13, 10, 3, 2, 2, 2, }, /* 25 (24.994) */ - { 14, 13, 8, 2, 2, 0, }, /* 25 (24.996) */ - { 7, 3, 0, 5, 3, 1, }, /* 25 (24.671) */ - { 4, 3, 2, 6, 6, 5, }, /* 25 (24.936) */ - { 4, 2, 0, 9, 9, 3, }, /* 25 (24.955) */ - { 4, 2, 0, 9, 8, 2, }, /* 25 (24.853) */ - { 4, 2, 0, 9, 7, 6, }, /* 25 (24.881) */ - { 6, 3, 0, 6, 3, 2, }, /* 25 (24.939) */ - { 3, 2, 0, 9, 8, 5, }, /* 25 (24.996) */ - { 2, 2, 0, 15, 3, 3, }, /* 25 (24.310) */ - { 4, 2, 0, 9, 9, 3, }, /* 25 (24.955) */ - { 4, 4, 2, 7, 6, 3, }, /* 25 (24.984) */ - { 3, 2, 0, 9, 7, 6, }, /* 25 (24.866) */ - -}; - -const Word16 no_lead_p_fx[][MAX_NO_SCALES*2] = -{ - - { 2, 1, 0, 0, 0, 0, }, /* 9 (8.464) */ - { 4, 2, 0, 2, 0, 0, }, /* 19 (18.572) */ - { 5, 5, 2, 4, 2, 0, }, /* 23 (22.959) */ - { 8, 5, 2, 4, 0, 0, }, /* 24 (23.949) */ - { 8, 8, 5, 4, 2, 0, }, /* 25 (24.992) */ - { 13, 11, 5, 5, 2, 0, }, /* 27 (26.902) */ - { 11, 10, 5, 6, 5, 2, }, /* 28 (27.996) */ - { 14, 13, 5, 7, 5, 2, }, /* 29 (28.937) */ - { 16, 13, 5, 8, 7, 2, }, /* 30 (29.954) */ - { 21, 21, 5, 8, 5, 2, }, /* 31 (30.978) */ - { 24, 21, 5, 8, 8, 4, }, /* 32 (31.978) */ - { 32, 23, 5, 13, 11, 5, }, /* 34 (33.975) */ - { 36, 31, 8, 16, 13, 5, }, /* 35 (34.975) */ - { 45, 35, 16, 18, 13, 5, }, /* 36 (35.889) */ - { 45, 35, 16, 38, 31, 8, }, /* 39 (38.488) */ /* V WB*/ /* 14 */ - - { 2, 0, 0, 0, 0, 0, }, /* 8 (7.913) */ - { 4, 2, 0, 2, 0, 0, }, /* 19 (18.572) */ - { 8, 7, 2, 2, 2, 0, }, /* 23 (22.773) */ - { 13, 11, 5, 2, 1, 0, }, /* 24 (23.999) */ - { 8, 8, 5, 4, 2, 0, }, /* 25 (24.992) */ - { 13, 11, 5, 5, 2, 1, }, /* 27 (26.962) */ - { 13, 11, 5, 5, 5, 2, }, /* 28 (27.835) */ - { 14, 13, 5, 7, 5, 2, }, /* 29 (28.937) */ - { 23, 21, 5, 5, 5, 2, }, /* 30 (29.969) */ - { 23, 18, 5, 8, 5, 2, }, /* 31 (30.952) */ - { 24, 21, 5, 8, 8, 4, }, /* 32 (31.978) */ - { 43, 41, 13, 9, 8, 5, }, /* 34 (33.992) */ - { 43, 36, 13, 13, 10, 5, }, /* 35 (35.000) */ - { 43, 40, 13, 17, 13, 9, }, /* 36 (35.980) */ - { 43, 42, 13, 31, 30, 18, }, /* 39 (38.512) */ /* V NB*/ /* 29 */ - - { 2, 0, 0, 1, 0, 0, }, /* 15 (14.733) */ - { 5, 4, 1, 1, 0, 0, }, /* 19 (18.745) */ - { 8, 7, 2, 2, 0, 0, }, /* 22 (21.776) */ - { 10, 9, 5, 2, 0, 0, }, /* 23 (22.791) */ - { 14, 13, 8, 2, 0, 0, }, /* 24 (23.999) */ - { 14, 13, 8, 2, 2, 0, }, /* 25 (24.996) */ - { 18, 17, 13, 2, 2, 0, }, /* 26 (25.934) */ - { 14, 13, 8, 5, 4, 0, }, /* 28 (27.969) */ - { 18, 17, 13, 5, 4, 2, }, /* 29 (28.996) */ - { 22, 21, 13, 5, 5, 2, }, /* 30 (29.988) */ - { 31, 23, 21, 5, 5, 2, }, /* 31 (30.931) */ - { 27, 23, 21, 8, 5, 2, }, /* 32 (31.987) */ - { 31, 23, 21, 9, 8, 5, }, /* 33 (32.982) */ - { 32, 31, 24, 11, 8, 5, }, /* 34 (33.967) */ - { 32, 32, 28, 13, 11, 8, }, /* 35 (34.994) */ /* G WB*/ /* 44 */ - - { 2, 0, 0, 1, 0, 0, }, /* 15 (14.733) */ - { 5, 4, 2, 1, 0, 0, }, /* 19 (18.792) */ - { 8, 5, 2, 2, 1, 0, }, /* 22 (21.985) */ - { 8, 7, 2, 2, 2, 0, }, /* 23 (22.773) */ - { 13, 11, 2, 2, 1, 0, }, /* 24 (23.932) */ - { 16, 13, 2, 2, 2, 0, }, /* 25 (24.955) */ - { 21, 17, 2, 2, 2, 0, }, /* 26 (25.991) */ - { 13, 12, 2, 5, 5, 2, }, /* 28 (27.979) */ - { 18, 16, 2, 5, 5, 2, }, /* 29 (28.878) */ - { 23, 21, 2, 5, 5, 2, }, /* 30 (29.954) */ - { 32, 28, 2, 5, 5, 2, }, /* 31 (30.893) */ - { 38, 31, 2, 7, 5, 2, }, /* 32 (31.963) */ - { 33, 31, 2, 8, 8, 4, }, /* 33 (32.997) */ - { 42, 31, 2, 9, 9, 8, }, /* 34 (33.986) */ - { 42, 31, 2, 13, 11, 9, }, /* 35 (34.952) */ /* G NB*/ /* 59 */ - - { 7, 5, 2, 2, 0, 0, }, /* 21 (20.910) */ - { 8, 8, 5, 4, 2, 0, }, /* 25 (24.992) */ - { 13, 8, 5, 4, 2, 0, }, /* 26 */ - { 13, 8, 5, 8, 6, 2, }, /* 29 */ - { 13, 8, 5, 9, 8, 5, }, /* 30 */ - { 48, 48, 48, 36, 36, 28 }, /* 40 */ /* mode 7 AUDIO_WB */ /* 65*/ - - { 7, 5, 2, 2, 0, 0 }, /* 21 */ - { 13, 13, 9, 2, 2, 0 }, /* 25 */ - { 18, 18, 9, 2, 2, 0 }, /* 26 */ - { 24, 23, 10, 5, 4, 2 }, /* 30 */ - { 31, 31, 12, 5, 5, 2 }, /* 31 */ /*AUDIO_NB */ /* 70 */ - { 43, 34, 12, 5, 5, 4 }, /* 32 */ /*AUDIO_NB */ /* 71 */ - { 13, 8, 5, 9, 8, 5, }, /* 30 */ - { 48, 48, 45, 45, 31, 25 }, /* 40 */ /* mode AUDIO_WB 16k */ /* 73*/ - - { 2, 0, 0, 2, 2, 0, }, /* 17 (16.823) */ - { 7, 5, 2, 2, 0, 0, }, /* 21 (20.910) */ - { 7, 5, 2, 2, 2, 0, }, /* 22 (21.907) */ - { 13, 11, 10, 2, 2, 0, }, /* 25 (24.863) */ - { 18, 18, 10, 2, 2, 0, }, /* 26 (25.921) */ - { 13, 9, 9, 5, 2, 0, }, /* 27 (26.837) */ - { 40, 28, 25, 18, 17, 2, }, /* 36 (35.998) */ /* INACTIVE NB*/ /* 80*/ - - { 18, 17, 11, 0, 0, 0, }, /* 17 (16.932) */ - { 7, 5, 2, 2, 0, 0, }, /* 21 (20.910) */ - { 8, 5, 2, 2, 1, 0, }, /* 22 (21.985) */ - { 13, 13, 9, 2, 2, 0, }, /* 25 (24.845) */ - { 18, 18, 12, 2, 2, 0, }, /* 26 (25.999) */ - { 23, 23, 16, 2, 2, 0, }, /* 27 (26.981) */ - { 36, 32, 24, 17, 13, 13, }, /* 36 (35.929) */ /* INACTIVE WB */ /* 87 */ - - { 2, 2, 0, 2, 0, 0, }, /* 17 (16.823) */ - { 7, 5, 2, 2, 0, 0, }, /* 21 (20.910) */ - { 8, 5, 2, 2, 1, 0, }, /* 22 (21.985) */ - { 13, 13, 9, 2, 2, 0, }, /* 25 (24.845) */ - { 18, 17, 13, 2, 2, 0, }, /* 26 (25.934) */ - { 23, 22, 17, 2, 2, 0, }, /* 27 (26.914) */ - { 34, 32, 24, 16, 16, 13, }, /* 36 (35.915) */ /* INACTIVE WB 16k*/ /* 94 */ - - { 4, 2, 0, 1, 0, 0, }, /* 18 (17.479) */ - { 5, 4, 0, 1, 0, 0, }, /* 19 (18.703) */ - { 8, 7, 2, 2, 0, 0, }, /* 22 (21.776) */ - { 10, 9, 5, 2, 0, 0, }, /* 23 (22.791) */ - { 15, 13, 5, 2, 0, 0, }, /* 24 (23.999) */ - { 18, 16, 8, 5, 5, 1, }, /* 29 (28.966) */ - { 42, 32, 31, 5, 5, 2, }, /* 32 (31.990) */ /* UNVOICED NB*/ /* 100 */ - - { 1, 0, 0, 1, 0, 0, }, /* 14 (13.640) */ - { 2, 0, 0, 1, 0, 0, }, /* 15 (14.733) */ - { 4, 2, 0, 1, 0, 0, }, /* 18 (17.479) */ - { 4, 2, 0, 2, 0, 0, }, /* 19 (18.572) */ - { 5, 4, 0, 2, 0, 0, }, /* 20 (19.796) */ - { 8, 8, 5, 4, 2, 0, }, /* 25 (24.992) */ - { 11, 10, 5, 6, 5, 2, }, /* 28 (27.996) */ /* UNVOICED WB */ /* 106 */ - { 9, 3, 0, 4, 0, 0, }, /* 24 (23.818) */ - { 18, 13, 10, 8, 3, 0, }, /* 30 (29.992) */ - { 24, 18, 10, 9, 3, 0, }, /* 31 (30.998) */ - { 32, 25, 10, 9, 3, 0, }, /* 32 (31.987) */ - { 42, 31, 10, 12, 3, 2, }, /* 34 (33.994) */ - { 44, 32, 27, 15, 3, 2, }, /* 35 (35.000) */ - { 44, 32, 25, 19, 3, 2, }, /* 36 (35.994) */ - { 48, 39, 32, 35, 15, 3, }, /* 39 (38.301) */ /* VOICED 16k */ - { 11, 10, 5, 4, 2, 0, }, /* 26 (25.917) */ /* 107 */ - { 23, 23, 17, 8, 7, 2, }, /* 32 (31.980) */ - { 32, 31, 18, 9, 7, 5, }, /* 33 (32.990) */ - { 31, 31, 18, 11, 9, 8, }, /* 34 (33.974) */ - { 32, 32, 20, 13, 12, 8, }, /* 35 (34.989) */ - { 32, 32, 23, 18, 17, 8, }, /* 36 (35.988) */ - { 32, 32, 23, 23, 22, 10, }, /* 37 (36.989) */ /* GENERIC 16k*/ /* 113 */ - - { 2, 0, 0, 2, 0, 0, }, /* 16 (15.826) */ /* 114 */ - { 7, 5, 2, 2, 0, 0, }, /* 21 (20.910) */ - { 14, 13, 8, 2, 0, 0, }, /* 24 (23.999) */ - { 8, 8, 5, 4, 2, 0, }, /* 25 (24.992) */ - { 11, 10, 5, 4, 2, 0, }, /* 26 (25.917) */ - { 16, 13, 8, 4, 2, 0, }, /* 27 (26.883) */ - { 13, 13, 8, 5, 4, 2, }, /* 28 (27.901) */ - { 23, 18, 13, 5, 5, 2, }, /* 30 (29.916) */ - { 23, 23, 13, 7, 5, 2, }, /* 31 (30.993) */ - { 23, 23, 17, 8, 7, 2, }, /* 32 (31.980) */ - { 32, 31, 24, 8, 7, 2, }, /* 33 (32.958) */ - { 42, 32, 31, 9, 9, 4, }, /* 34 (33.987) */ - { 40, 32, 29, 12, 9, 9, }, /* 35 (34.994) */ - { 40, 32, 31, 17, 11, 11, }, /* 36 (35.968) */ - { 41, 32, 31, 20, 18, 13, }, /* 37 (36.971) */ /* GENERIC 12.8k MA*/ /* 128 */ - - { 11, 10, 5, 4, 2, 0, }, /* 26 (25.917) */ /* 129 */ - { 23, 23, 17, 8, 7, 2, }, /* 32 (31.980) */ - { 31, 31, 18, 9, 8, 2, }, /* 33 (32.995) */ - { 48, 32, 24, 9, 8, 3, }, /* 34 (33.993) */ - { 48, 32, 28, 11, 10, 3, }, /* 35 (34.992) */ - { 48, 37, 32, 16, 12, 4, }, /* 36 (35.997) */ - { 48, 37, 32, 18, 17, 12, }, /* 37 (36.961) */ /* AUDIO 16k */ -}; - -const Word16 pl_HQ_fx[] = /* Q1 vectors in first layers */ -{ - 2, 2, 0, 0, 0, 0, 0, 0, /* 112, 4, 28 */ - 1, 1, 1, 1, 1, 1, 1, 1, /* 128, 128, 1 */ - 2, 2, 2, 2, 0, 0, 0, 0, /* 1120, 16, 70 */ - 4, 0, 0, 0, 0, 0, 0, 0, /* 16 , 2, 8 */ - 3, 1, 1, 1, 1, 1, 1, 1, /* 5 */ /* 1024,128, 8 */ - 2, 2, 2, 2, 2, 2, 0, 0, /* 1792, 64, 28 */ - 4, 2, 2, 0, 0, 0, 0, 0, /* 1344, 8, 168 */ - 3, 3, 1, 1, 1, 1, 1, 1, /* 3584, 128, 28*/ - 2, 2, 2, 2, 2, 2, 2, 2, /*256, 256, 1*/ - 4, 2, 2, 2, 2, 0, 0, 0, /* 10 */ /* 8960, 32, 280 */ - 4, 4, 0, 0, 0, 0, 0, 0, /* 112, 4, 28 */ - 3, 3, 3, 1, 1, 1, 1, 1, /* 7168, 128, 56 */ - 5, 1, 1, 1, 1, 1, 1, 1, /* 1024, 128, 8*/ - 4, 2, 2, 2, 2, 2, 2, 0, /* 7168, 128, 56*/ - 4, 4, 2, 2, 0, 0, 0, 0, /* 15 */ /* 6720, 16, 420 */ - 6, 2, 0, 0, 0, 0, 0, 0, /* 224, 4, 56 */ - 3, 3, 3, 3, 1, 1, 1, 1, /* 8960, 128, 70 */ - 5, 3, 1, 1, 1, 1, 1, 1, /* 7168, 128, 56*/ - 4, 4, 2, 2, 2, 2, 0, 0, /* 26880, 64, 420 */ - 4, 4, 4, 0, 0, 0, 0, 0, /*20 */ /* 448, 8, 56 */ - 6, 2, 2, 2, 0, 0, 0, 0, /* 4480, 16, 280 */ - 3, 3, 3, 3, 3, 1, 1, 1, /* 7168, 128, 56 */ - 5, 3, 3, 1, 1, 1, 1, 1, /* 21504, 128, 168 */ - 4, 4, 2, 2, 2, 2, 2, 2, /* 7168, 256, 28 */ - 4, 4, 4, 2, 2, 0, 0, 0, /* 25 */ /* 17920, 32, 560 */ - 6, 2, 2, 2, 2, 2, 0, 0, /* 10752, 64, 168 */ - 6, 4, 2, 0, 0, 0, 0, 0, /* 2688, 8, 336 */ - 3, 3, 3, 3, 3, 3, 1, 1, /* 3584, 128, 28 */ - 5, 3, 3, 3, 1, 1, 1, 1, /* 35840,128,280*/ - 5, 5, 1, 1, 1, 1, 1, 1, /*30 */ /* 3584, 128, 28*/ - 7, 1, 1, 1, 1, 1, 1, 1, /* 1024,128, 8 */ - 4, 4, 4, 2, 2, 2, 2, 0, - 4, 4, 4, 4, 0, 0, 0, 0, - 6, 2, 2, 2, 2, 2, 2, 2, - 6, 4, 2, 2, 2, 0, 0, 0, - 8, 0, 0, 0, 0, 0, 0, 0, - 3, 3, 3, 3, 3, 3, 3, 1, - 5, 3, 3, 3, 3, 1, 1, 1, - 5, 5, 3, 1, 1, 1, 1, 1, - 7, 3, 1, 1, 1, 1, 1, 1, - 4, 4, 4, 4, 2, 2, 0, 0, - 6, 4, 2, 2, 2, 2, 2, 0, - 6, 4, 4, 2, 0, 0, 0, 0, - 6, 6, 0, 0, 0, 0, 0, 0, - 8, 2, 2, 0, 0, 0, 0, 0, - 3, 3, 3, 3, 3, 3, 3, 3, - 5, 3, 3, 3, 3, 3, 1, 1, - 5, 5, 3, 3, 1, 1, 1, 1, - 7, 3, 3, 1, 1, 1, 1, 1 -}; - -const Word32 table_no_cv_fx[] = { 0, 112, 240, 1360, 1376, 2400, 4192, 5536, 9120, 9376, 18336, 18448, 25616, 26640, 33808, 40528, 40752, - 49712, 56880, 83760, 84208, 88688, 95856, 117360, 124528, 142448, 153200, 155888, 159472, 195312, 198896, 199920, - 235760, 236880, 238928, 274768, 274784, 275808, 311648, 333152, 340320, 367200, 410208, 423648,423760, 425104, 425232, 446736, 500496, 522000 - ,0 - }; - - - -/* Innovative codebook config */ -const PulseConfig PulseConfTable[ACELP_FIXED_CDK_NB] = -{ - /* Design rules: - * ---> "fixed" + "tried-pair-pos"*2 = pulses & 0xfe - * ---> tracks with pulses % 3 == 0, have always TRACKPOS_FIXED_FIRST */ - /* bits,iter,alp,pulses,fixed,tried-pair-pos,codetrack*/ - { 7, 4, 16384/*2.0f Q13*/, 1, 0, {8}, TRACKPOS_FREE_ONE }, /* 7 bits, 1 pulses, 4 tracks, 1000 free track */ - { 10, 4, 16384/*2.0f Q13*/, 2, 0, {8}, TRACKPOS_FIXED_EVEN }, /* 10 bits, 2 pulses, 4 tracks 1010 (used only even tracks designed for NB) */ - { 12, 4, 16384/*2.0f Q13*/, 2, 0, {8}, TRACKPOS_FIXED_TWO }, /* 12 bits, 2 pulses, 2 tracks 11 used all tracks ala AMR-WB 6.6 */ - { 15, 4, 16384/*2.0f Q13*/, 3, 0, {8}, TRACKPOS_FIXED_FIRST }, /* 15 bits, 3 pulses, 4 tracks 1110 fixed track to first ? */ - { 17, 6, 16384/*2.0f Q13*/, 3, 0, {8}, TRACKPOS_FREE_THREE }, /* 17 bits, 3 pulses, 4 tracks (used all tracks) - 1110, 1101, 1011, 0111 */ - { 20, 4, 16384/*2.0f Q13*/, 4, 0, {4, 8}, TRACKPOS_FIXED_FIRST }, /* 20 bits, 4 pulses, 4 tracks 1111 */ - { 24, 4, 16384/*2.0f Q13*/, 5, 0, {4, 8}, TRACKPOS_FIXED_FIRST }, /* 24 bits, 5 pulses, 4 tracks 2111 fixed track to first */ - { 26, 4, 16384/*2.0f Q13*/, 5, 0, {4, 8}, TRACKPOS_FREE_ONE }, /* 26 bits, 5 pulses, 4 tracks 2111 one free track ? */ - { 28, 4, 12288/*1.5f Q13*/, 6, 0, {4, 8, 8}, TRACKPOS_FIXED_FIRST }, /* 28 bits, 6 pulses, 4 tracks 2211 */ - { 30, 4, 12288/*1.5f Q13*/, 6, 0, {4, 8, 8}, TRACKPOS_FIXED_TWO }, /* 30 bits, 6 pulses, 4 tracks 2211 free consecutive track positions ? */ - { 32, 4, 12288/*1.5f Q13*/, 7, 0, {4, 8, 8}, TRACKPOS_FIXED_FIRST }, /* 32 bits, 6 pulses, 4 tracks 2221 fixed ?*/ - { 34, 4, 12288/*1.5f Q13*/, 7, 0, {4, 8, 8}, TRACKPOS_FREE_THREE }, /* 34 bits, 6 pulses, 4 tracks 2221 free track positions ? */ - { 36, 4, 8192/*1.0f Q13*/, 8, 2, {4, 8, 8}, TRACKPOS_FIXED_FIRST }, /* 36 bits, 8 pulses, 4 tracks 2222 */ - { 40, 4, 8192/*1.0f Q13*/, 9, 2, {4, 8, 8}, TRACKPOS_FIXED_FIRST }, /* 40 bits, 9 pulses, 4 tracks 3222 fixed ?*/ - { 43, 4, 8192/*1.0f Q13*/, 10, 2, {4, 6, 8, 8}, TRACKPOS_FIXED_FIRST }, /* 44 bits, 10 pulses, 4 tracks 3322 */ - { 46, 4, 8192/*1.0f Q13*/, 10, 2, {4, 6, 8, 8}, TRACKPOS_FIXED_TWO }, /* 46 bits, 10 pulses, 4 tracks 3322 free consecutive tracks ? */ - { 47, 4, 8192/*1.0f Q13*/, 11, 2, {4, 6, 8, 8}, TRACKPOS_FIXED_FIRST }, /* 47 bits, 10 pulses, 4 tracks 3332 fixed ? */ - { 49, 4, 8192/*1.0f Q13*/, 11, 2, {4, 6, 8, 8}, TRACKPOS_FREE_THREE }, /* 49 bits, 10 pulses, 4 tracks 3332 free three track positions ? */ - { 50, 4, 8192/*1.0f Q13*/, 12, 4, {4, 6, 8, 8}, TRACKPOS_FIXED_FIRST }, /* 50 bits, 12 pulses, 4 tracks 3333 */ - { 53, 4, 8192/*1.0f Q13*/, 13, 4, {4, 6, 8, 8}, TRACKPOS_FIXED_FIRST }, /* 53 bits, 13 pulses, 4 tracks 4333 fixed ? */ - { 55, 4, 8192/*1.0f Q13*/, 13, 4, {4, 6, 8, 8}, TRACKPOS_FREE_ONE }, /* 55 bits, 13 pulses, 4 tracks 4333 free one ? */ - { 56, 4, 8192/*1.0f Q13*/, 14, 4, {4, 6, 6, 8, 8}, TRACKPOS_FIXED_FIRST }, /* 56 bits, 14 pulses, 4 tracks 4433 fixed ?!?! */ - { 58, 4, 8192/*1.0f Q13*/, 14, 4, {4, 6, 6, 8, 8}, TRACKPOS_FIXED_TWO }, /* 58 bits, 14 pulses, 4 tracks 4433 free consecutive ? */ - { 59, 4, 8192/*1.0f Q13*/, 15, 4, {4, 6, 6, 8, 8}, TRACKPOS_FIXED_FIRST }, /* 59 bits, 15 pulses, 4 tracks 4443 fixed ? */ - { 61, 4, 8192/*1.0f Q13*/, 15, 4, {4, 6, 6, 8, 8}, TRACKPOS_FREE_THREE }, /* 61 bits, 15 pulses, 4 tracks 4443 free ? */ - { 62, 3, 6554/*0.8f Q13*/, 16, 4, {4, 4, 6, 6, 8, 8}, TRACKPOS_FIXED_FIRST }, /* 62 bits, 16 pulses, 4 tracks 4444 */ - { 65, 3, 6554/*0.8f Q13*/, 17, 4, {4, 4, 6, 6, 8, 8}, TRACKPOS_FIXED_FIRST }, /* 65 bits, 17 pulses, 4 tracks 5444 fixed ?*/ - { 68, 3, 6144/*0.75f Q13*/, 18, 4, {2, 3, 4, 5, 6, 7, 8}, TRACKPOS_FIXED_FIRST }, /* 68 bits, 18 pulses, 4 tracks 5544 */ - { 70, 3, 6144/*0.75f Q13*/, 19, 4, {2, 3, 4, 5, 6, 7, 8}, TRACKPOS_FIXED_FIRST }, /* 70 bits, 19 pulses, 4 tracks 5554 fixed ? */ - { 73, 3, 6144/*0.75f Q13*/, 20, 4, {2, 3, 4, 5, 6, 7, 8, 8}, TRACKPOS_FIXED_FIRST }, /* 73 bits, 20 pulses, 4 tracks 5555 fixed ? */ - { 75, 3, 6144/*0.75f Q13*/, 21, 4, {2, 3, 4, 5, 6, 7, 8, 8}, TRACKPOS_FIXED_FIRST }, /* 75 bits, 21 pulses, 4 tracks 6555 fixed ? */ - { 78, 3, 6144/*0.75f Q13*/, 22, 4, {2, 3, 4, 5, 6, 7, 8, 8, 8}, TRACKPOS_FIXED_FIRST }, /* 78 bits, 22 pulses, 4 tracks 6655 fixed ? */ - { 80, 3, 6144/*0.75f Q13*/, 23, 4, {2, 3, 4, 5, 6, 7, 8, 8, 8}, TRACKPOS_FIXED_FIRST }, /* 80 bits, 23 pulses, 4 tracks 6665 fixed ? */ - { 83, 2, 2458/*0.30f Q13*/, 24, 4, {2, 3, 4, 5, 6, 7, 8, 8, 8, 8}, TRACKPOS_FIXED_FIRST}, /* 83 bits, 24 pulses, 4 tracks 6666 */ - { 85, 2, 2458/*0.30f Q13*/, 25, 4, {2, 3, 4, 5, 6, 7, 8, 8, 8, 8}, TRACKPOS_FIXED_FIRST}, /* 85 bits, 25 pulses, 4 tracks 7666 */ - { 87, 2, 2048/*0.25f Q13*/, 26, 4, {2, 3, 4, 5, 6, 7, 8, 8, 8, 8, 8}, TRACKPOS_FIXED_FIRST}, /* 87 bits, 26 pulses, 4 tracks 7766 */ - { 89, 2, 2048/*0.25f Q13*/, 27, 4, {2, 3, 4, 5, 6, 7, 8, 8, 8, 8, 8}, TRACKPOS_FIXED_FIRST}, /* 89 bits, 27 pulses, 4 tracks 7776 */ - { 92, 2, 2048/*0.25f Q13*/, 28, 4, {2, 3, 4, 5, 6, 7, 8, 8, 8, 8, 8, 8}, TRACKPOS_FIXED_FIRST}, /* 92 bits, 28 pulses, 4 tracks 7777 */ - { 94, 2, 2048/*0.25f Q13*/, 29, 4, {2, 3, 4, 5, 6, 7, 8, 8, 8, 8, 8, 8}, TRACKPOS_FIXED_FIRST}, /* 94 bits, 29 pulses, 4 tracks 8777 */ - { 96, 1, 1638/*0.20f Q13*/, 30, 4, {2, 3, 4, 5, 6, 7, 8, 8, 8, 8, 8, 8, 8}, TRACKPOS_FIXED_FIRST}, /* 96 bits, 30 pulses, 4 tracks 8877 */ - { 98, 1, 1638/*0.20f Q13*/, 31, 4, {2, 3, 4, 5, 6, 7, 8, 8, 8, 8, 8, 8, 8}, TRACKPOS_FIXED_FIRST}, /* 98 bits, 31 pulses, 4 tracks 8887 */ -}; - -/*----------------------------------------------------------------------------------* - * LSF quantization for CNG - *----------------------------------------------------------------------------------*/ -const Word16 cng_sort_fx[] = {/*5f */1,1,0,1,0,0, /* 4f */0,1,0,1,0,0,1,1,1,1}; - -const Word16 perm_MSLVQ_fx[][4] = -{ - /* 5f*/ - {6,11,7,15}, - {6,15,-1,0}, - {5,8,7,15}, - {7,10,-1,0}, - {-1,0,0,0}, - {-1,0,0,0}, - /* 4f */ - {-1,0,0,0}, - {0,9,7,10}, - {-1,0,0,0}, - {7,15,-1,0}, - {-1,0,0,0}, - {-1,0,0,0}, - {6,10,7,11}, - {6,11,7,12}, - {6,11,7,12}, - {6,11,7,12} -}; -/*----------------------------------------------------------------------------------* - * table of cos(x) in Q15 used in FFT for spectral analysis - *----------------------------------------------------------------------------------*/ -const Word16 cos_table_129[129] = -{ - 32767, - 32758, 32729, 32679, 32610, 32522, 32413, 32286, 32138, - 31972, 31786, 31581, 31357, 31114, 30853, 30572, 30274, - 29957, 29622, 29269, 28899, 28511, 28106, 27684, 27246, - 26791, 26320, 25833, 25330, 24812, 24279, 23732, 23170, - 22595, 22006, 21403, 20788, 20160, 19520, 18868, 18205, - 17531, 16846, 16151, 15447, 14733, 14010, 13279, 12540, - 11793, 11039, 10279, 9512, 8740, 7962, 7180, 6393, - 5602, 4808, 4011, 3212, 2411, 1608, 804, 0, - -804, -1608, -2411, -3212, -4011, -4808, -5602, -6393, - -7180, -7962, -8740, -9512, -10279, -11039, -11793, -12540, - -13279, -14010, -14733, -15447, -16151, -16846, -17531, -18205, - -18868, -19520, -20160, -20788, -21403, -22006, -22595, -23170, - -23732, -24279, -24812, -25330, -25833, -26320, -26791, -27246, - -27684, -28106, -28511, -28899, -29269, -29622, -29957, -30274, - -30572, -30853, -31114, -31357, -31581, -31786, -31972, -32138, - -32286, -32413, -32522, -32610, -32679, -32729, -32758, -32768 -}; - -/*----------------------------------------------------------------------------------* - * slope in Q11 used to compute y = acos(x) - ----------------------------------------------------------------------------------*/ -const Word16 acos_slope[128] = -{ - -26214, -9039, -5243, -3799, -2979, -2405, -2064, -1771, - -1579, -1409, -1279, -1170, -1079, -1004, -933, -880, - -827, -783, -743, -708, -676, -647, -621, -599, - -576, -557, -538, -521, -506, -492, -479, -466, - -456, -445, -435, -426, -417, -410, -402, -395, - -389, -383, -377, -372, -367, -363, -359, -355, - -351, -348, -345, -342, -340, -337, -335, -333, - -331, -330, -329, -328, -327, -326, -326, -326, - -326, -326, -326, -327, -328, -329, -330, -331, - -333, -335, -337, -340, -342, -345, -348, -351, - -355, -359, -363, -367, -372, -377, -383, -389, - -395, -402, -410, -417, -426, -435, -445, -456, - -466, -479, -492, -506, -521, -538, -557, -576, - -599, -621, -647, -676, -708, -743, -783, -827, - -880, -933, -1004, -1079, -1170, -1279, -1409, -1579, - -1771, -2064, -2405, -2979, -3799, -5243, -9039,-26214 -}; - -/*----------------------------------------------------------------------------------* - * Quantization table for scaled innovation energy prediciton in Q8 - *----------------------------------------------------------------------------------*/ -const Word16 Es_pred_qua_5b_fx[32] = -{ - -2048, - -525, - 642, - 1688, - 2547, - 3326, - 4026, - 4647, - 5211, - 5740, - 6221, - 6661, - 7067, - 7447, - 7815, - 8170, - 8518, - 8865, - 9204, - 9551, - 9912, - 10284, - 10669, - 11077, - 11509, - 11976, - 12486, - 13049, - 13695, - 14434, - 15354, - 16640, -}; - - -const Word16 Es_pred_qua_4b_fx[16] = -{ - -2048, - -36, - 1828, - 3284, - 4584, - 5742, - 6821, - 7834, - /*8779, */ - 8778, - 9701, - 10610, - 11524, - 12487, - 13560, - 14862, - 16640 -}; - - -const Word16 Es_pred_qua_3b_fx[8] = -{ - 1521/* 5.9422f Q8*/, - 3909/*15.2711f Q8*/, - 5987/*23.3857f Q8*/, - 7816/*30.5310f Q8*/, - 9477/*37.0190f Q8*/, - 11124/*43.4539f Q8*/, - 12863/*50.2442f Q8*/, - 15031/*58.7164f Q8*/ -}; -const Word16 Es_pred_qua_4b_no_ltp_fx[16] = -{ - -1280/*-5.f Q8*/, - 0/* 0.f Q8*/, - 1280/* 5.f Q8*/, - 2560/*10.f Q8*/, - 3840/*15.f Q8*/, - 5120/*20.f Q8*/, - 6400/*25.f Q8*/, - 7680/*30.f Q8*/, - 8960/*35.f Q8*/, - 10240/*40.f Q8*/, - 11520/*45.f Q8*/, - 12800/*50.f Q8*/, - 14080/*55.f Q8*/, - 15360/*60.f Q8*/, - 16640/*65.f Q8*/, - 17920/*70.f Q8*/ -}; -/*----------------------------------------------------------------------------------* - * Transition coding - gain quantization table - *----------------------------------------------------------------------------------*/ -const Word16 tbl_gain_code_tc_fx[N_GAIN_CODE_TC] = /*q13 */ -{ - 2966, - 5930, - 7924, - 9712, - 11566, - 13754, - 16993, - 27280 -}; -/*----------------------------------------------------------------------------------* - * MA predicition coefficients for gain quantizer - *----------------------------------------------------------------------------------*/ - -const Word16 pred_gain_fx[GAIN_PRED_ORDER] = {8192, 6554, 4915, 3277}; - -const Word16 t_qua_gain6b_fx[64*2] = -{ - 1566, 1332, - 1577, 3557, - 3071, 6490, - 4193, 10163, - 4496, 2534, - 5019, 4488, - 5586, 15614, - 5725, 1422, - 6453, 580, - 6724, 6831, - 7657, 3527, - 8072, 2099, - 8232, 5319, - 8827, 8775, - 9740, 2868, - 9856, 1465, - 10087, 12488, - 10241, 4453, - 10859, 6618, - 11321, 3587, - 11417, 1800, - 11643, 2428, - 11718, 988, - 12312, 5093, - 12523, 8413, - 12574, 26214, - 12601, 3396, - 13172, 1623, - 13285, 2423, - 13418, 6087, - 13459, 12810, - 13656, 3607, - 14111, 4521, - 14144, 1229, - 14425, 1871, - 14431, 7234, - 14445, 2834, - 14628, 10036, - 14860, 17496, - 15161, 3629, - 15209, 5819, - 15299, 2256, - 15518, 4722, - 15663, 1060, - 15759, 7972, - 15939, 11964, - 16020, 2996, - 16086, 1707, - 16521, 4254, - 16576, 6224, - 16894, 2380, - 16906, 681, - 17213, 8406, - 17610, 3418, - 17895, 5269, - 18168, 11748, - 18230, 1575, - 18607, 32767, - 18728, 21684, - 19137, 2543, - 19422, 6577, - 19446, 4097, - 19450, 9056, - 20371, 14885 -}; - -const Word16 t_qua_gain7b_fx[128*2] = -{ - 204, 441, - 464, 1977, - 869, 1077, - 1072, 3062, - 1281, 4759, - 1647, 1539, - 1845, 7020, - 1853, 634, - 1995, 2336, - 2351, 15400, - 2661, 1165, - 2702, 3900, - 2710, 10133, - 3195, 1752, - 3498, 2624, - 3663, 849, - 3984, 5697, - 4214, 3399, - 4415, 1304, - 4695, 2056, - 5376, 4558, - 5386, 676, - 5518, 23554, - 5567, 7794, - 5644, 3061, - 5672, 1513, - 5957, 2338, - 6533, 1060, - 6804, 5998, - 6820, 1767, - 6937, 3837, - 7277, 414, - 7305, 2665, - 7466, 11304, - 7942, 794, - 8007, 1982, - 8007, 1366, - 8326, 3105, - 8336, 4810, - 8708, 7954, - 8989, 2279, - 9031, 1055, - 9247, 3568, - 9283, 1631, - 9654, 6311, - 9811, 2605, - 10120, 683, - 10143, 4179, - 10245, 1946, - 10335, 1218, - 10468, 9960, - 10651, 3000, - 10951, 1530, - 10969, 5290, - 11203, 2305, - 11325, 3562, - 11771, 6754, - 11839, 1849, - 11941, 4495, - 11954, 1298, - 11975, 15223, - 11977, 883, - 11986, 2842, - 12438, 2141, - 12593, 3665, - 12636, 8367, - 12658, 1594, - 12886, 2628, - 12984, 4942, - 13146, 1115, - 13224, 524, - 13341, 3163, - 13399, 1923, - 13549, 5961, - 13606, 1401, - 13655, 2399, - 13782, 3909, - 13868, 10923, - 14226, 1723, - 14232, 2939, - 14278, 7528, - 14439, 4598, - 14451, 984, - 14458, 2265, - 14792, 1403, - 14818, 3445, - 14899, 5709, - 15017, 15362, - 15048, 1946, - 15069, 2655, - 15405, 9591, - 15405, 4079, - 15570, 7183, - 15687, 2286, - 15691, 1624, - 15699, 3068, - 15772, 5149, - 15868, 1205, - 15970, 696, - 16249, 3584, - 16338, 1917, - 16424, 2560, - 16483, 4438, - 16529, 6410, - 16620, 11966, - 16839, 8780, - 17030, 3050, - 17033, 18325, - 17092, 1568, - 17123, 5197, - 17351, 2113, - 17374, 980, - 17566, 26214, - 17609, 3912, - 17639, 32767, - 18151, 7871, - 18197, 2516, - 18202, 5649, - 18679, 3283, - 18930, 1370, - 19271, 13757, - 19317, 4120, - 19460, 1973, - 19654, 10018, - 19764, 6792, - 19912, 5135, - 20040, 2841, - 21234, 19833 -}; -/*----------------------------------------------------------------------------------* - * Tables for mode TC - * (tbl_gain_code_tc[i]+(tbl_gain_code_tc[i+1]-tbl_gain_code_tc[i])/2) - *----------------------------------------------------------------------------------*/ -const Word16 tbl_gain_code_tc_quant_mean[N_GAIN_CODE_TC-1] = -{ - 4448, 6927, 8818, 10639, - 12660, 15374, 22136 -}; /* Q13 */ - -const Word16 gain_qua_mless_7b_fx[128*2] = -{ - 419, 28, - 1499, 607, - 1586, 322, - 1632, 144, - 1686, 229, - 1745, 495, - 2182, 409, - 2515, 716, - 2772, 824, - 3069, 1069, - 3211, 936, - 3218, 89, - 3477, 1244, - 3755, 272, - 3865, 549, - 3881, 348, - 4171, 181, - 4414, 627, - 4419, 472, - 4909, 1429, - 5238, 404, - 5241, 1651, - 5721, 85, - 5833, 250, - 5846, 693, - 5897, 325, - 6036, 544, - 6088, 779, - 6459, 1889, - 6650, 157, - 6678, 462, - 6798, 879, - 6922, 993, - 6929, 1130, - 7352, 620, - 7461, 386, - 7864, 232, - 7999, 314, - 8136, 536, - 8398, 712, - 8680, 459, - 8797, 1276, - 9046, 806, - 9198, 86, - 9434, 398, - 9730, 587, - 9735, 267, - 9742, 175, - 9917, 917, - 10042, 509, - 10053, 655, - 10132, 1030, - 10238, 339, - 10694, 1560, - 10817, 447, - 10964, 723, - 11405, 1149, - 11526, 549, - 11582, 386, - 11602, 791, - 11618, 286, - 11883, 862, - 11954, 607, - 12057, 214, - 12104, 496, - 12170, 1397, - 12437, 668, - 12616, 335, - 12668, 952, - 12684, 435, - 12983, 112, - 13235, 742, - 13399, 549, - 13525, 380, - 13527, 270, - 13625, 1044, - 13733, 482, - 13820, 617, - 14036, 817, - 14041, 1257, - 14295, 425, - 14346, 684, - 14367, 319, - 14416, 199, - 14644, 898, - 14944, 518, - 15090, 364, - 15154, 578, - 15309, 462, - 15360, 1933, - 15362, 756, - 15381, 262, - 15566, 1127, - 15699, 639, - 15804, 410, - 16081, 316, - 16161, 993, - 16359, 701, - 16451, 828, - 16500, 543, - 16540, 491, - 16617, 1729, - 16630, 196, - 16749, 369, - 16959, 1530, - 17028, 442, - 17139, 603, - 17369, 898, - 17393, 268, - 17972, 763, - 17985, 1361, - 18016, 333, - 18032, 667, - 18234, 406, - 18270, 105, - 18299, 554, - 18342, 488, - 18747, 1207, - 19027, 1073, - 19530, 216, - 19566, 963, - 19751, 835, - 19794, 615, - 19810, 298, - 19988, 710, - 19990, 449, - 20005, 374, - 20149, 531, -}; -const Word16 gain_qua_mless_6b_fx[64*2] = -{ - 1676, 71, - 2128, 198, - 2318, 491, - 2348, 339, - 2798, 625, - 2893, 785, - 3911, 1099, - 4779, 244, - 4781, 427, - 5115, 935, - 5294, 1509, - 5767, 114, - 6018, 543, - 6152, 335, - 6205, 675, - 6234, 1822, - 6740, 1251, - 7034, 802, - 7782, 434, - 8005, 230, - 9232, 622, - 9337, 336, - 9388, 520, - 9770, 1038, - 9865, 734, - 10224, 879, - 10617, 118, - 10776, 426, - 11518, 249, - 11708, 1399, - 12044, 587, - 12270, 501, - 12277, 348, - 12498, 684, - 13020, 786, - 13097, 1196, - 13530, 422, - 13818, 917, - 14123, 290, - 14500, 1039, - 14538, 636, - 14636, 556, - 14667, 484, - 14931, 362, - 15055, 210, - 15653, 1594, - 15830, 1874, - 15868, 717, - 15897, 828, - 16153, 434, - 16540, 294, - 16874, 608, - 16936, 513, - 17182, 373, - 17644, 1337, - 17696, 126, - 18342, 1122, - 18461, 944, - 18991, 242, - 19114, 795, - 19187, 674, - 19256, 449, - 19485, 557, - 19515, 344, -}; - -const Word16 gain_qua_mless_5b_fx[32*2] = -{ - 2695, 109, - 3444, 271, - 3529, 433, - 4284, 801, - 4365, 607, - 4935, 1089, - 6896, 1407, - 7722, 324, - 7913, 146, - 8090, 468, - 9049, 913, - 9499, 600, - 9894, 741, - 9942, 1840, - 11906, 382, - 12008, 1103, - 12349, 243, - 12429, 501, - 13687, 630, - 13974, 896, - 14510, 748, - 15160, 322, - 15424, 428, - 15679, 541, - 15832, 1574, - 15999, 1281, - 17223, 211, - 17719, 1029, - 18185, 649, - 18432, 818, - 18638, 353, - 18889, 493, -}; - -const Word16 gp_gamma_1sfr_8b_fx[2*256] = /*Q14/Q9 */ -{ - 305, 152, - 333, 37, - 352, 556, - 573, 82, - 652, 12, - 694, 207, - 808, 389, - 915, 776, - 986, 1089, - 987, 1583, - 1055, 60, - 1202, 2779, - 1205, 20, - 1346, 127, - 1432, 332, - 1689, 6554, - 1715, 261, - 1820, 49, - 2041, 698, - 2179, 4032, - 2199, 100, - 2272, 1303, - 2317, 461, - 2340, 175, - 2562, 26, - 2574, 14814, - 2657, 2101, - 2732, 66, - 2818, 9, - 2836, 296, - 2929, 938, - 3479, 130, - 3510, 220, - 3651, 3154, - 3667, 717, - 3720, 384, - 3783, 530, - 3811, 10744, - 3883, 5385, - 3941, 1609, - 3964, 46, - 4120, 80, - 4402, 15, - 4440, 1181, - 4485, 173, - 4740, 311, - 4848, 31, - 5125, 7642, - 5147, 110, - 5167, 908, - 5237, 252, - 5323, 623, - 5376, 2514, - 5590, 7, - 5595, 4475, - 5634, 64, - 5654, 461, - 5822, 22, - 5893, 140, - 5905, 1810, - 6177, 367, - 6268, 201, - 6352, 1092, - 6567, 752, - 6626, 50, - 6734, 95, - 6758, 295, - 6882, 3085, - 6962, 1363, - 7274, 540, - 7413, 166, - 7635, 2120, - 7642, 38, - 7671, 393, - 7730, 227, - 7860, 75, - 7980, 115, - 8011, 955, - 8092, 3687, - 8120, 17, - 8146, 5902, - 8453, 672, - 8524, 1602, - 8583, 58, - 8679, 275, - 8873, 332, - 8920, 454, - 8969, 9712, - 9129, 2566, - 9159, 196, - 9193, 1127, - 9219, 142, - 9300, 9, - 9302, 828, - 9409, 91, - 9736, 26, - 9872, 574, - 10066, 246, - 10131, 1352, - 10154, 1971, - 10196, 399, - 10238, 15785, - 10255, 4254, - 10401, 67, - 10439, 43, - 10511, 116, - 10531, 7399, - 10706, 998, - 10798, 722, - 10845, 171, - 10848, 304, - 10876, 2981, - 11069, 28204, - 11139, 507, - 11280, 12, - 11427, 388, - 11459, 214, - 11647, 1174, - 11710, 5061, - 11742, 1614, - 11793, 806, - 11816, 82, - 11890, 132, - 11996, 2301, - 12000, 603, - 12060, 55, - 12232, 256, - 12299, 33, - 12438, 338, - 12452, 458, - 12627, 3563, - 12646, 9489, - 12665, 934, - 12801, 1329, - 12802, 190, - 12877, 683, - 12941, 103, - 13038, 1890, - 13209, 6209, - 13222, 12674, - 13318, 21, - 13374, 283, - 13385, 149, - 13391, 383, - 13453, 545, - 13564, 1064, - 13596, 2561, - 13771, 810, - 13834, 1481, - 13874, 69, - 14027, 226, - 14093, 4429, - 14147, 7, - 14171, 609, - 14185, 47, - 14223, 3051, - 14273, 434, - 14321, 314, - 14415, 120, - 14443, 1252, - 14500, 173, - 14557, 933, - 14616, 1696, - 14639, 8229, - 14724, 89, - 14837, 703, - 14902, 2072, - 14917, 366, - 15000, 487, - 15009, 30, - 15095, 256, - 15138, 1119, - 15228, 3580, - 15371, 1386, - 15387, 5525, - 15398, 17932, - 15462, 149, - 15471, 791, - 15551, 569, - 15554, 2467, - 15559, 201, - 15616, 14, - 15664, 319, - 15798, 401, - 15811, 974, - 15874, 41, - 15929, 1649, - 15945, 79, - 16046, 111, - 16225, 647, - 16230, 1240, - 16297, 4110, - 16328, 10499, - 16331, 278, - 16355, 3003, - 16383, 455, - 16404, 169, - 16435, 2172, - 16438, 850, - 16745, 7090, - 16776, 354, - 16801, 1063, - 16803, 62, - 16812, 223, - 16927, 530, - 16951, 721, - 17039, 1447, - 17208, 1837, - 17233, 135, - 17371, 4642, - 17570, 406, - 17608, 267, - 17696, 906, - 17702, 2529, - 17705, 23239, - 17709, 1209, - 17745, 592, - 17800, 92, - 17858, 35, - 17860, 3360, - 17866, 9, - 17978, 184, - 18035, 321, - 18255, 754, - 18274, 480, - 18320, 18, - 18406, 55, - 18582, 13017, - 18677, 1516, - 18726, 1998, - 18904, 25, - 18914, 6103, - 19020, 8567, - 19022, 1116, - 19025, 349, - 19147, 239, - 19224, 604, - 19251, 160, - 19270, 4870, - 19358, 3789, - 19394, 126, - 19394, 103, - 19433, 72, - 19444, 46, - 19448, 2842, - 19489, 430, - 19575, 815, - 19628, 1306, - 19631, 972, - 19637, 202, - 19642, 289, - 19660, 527, - 19717, 1697, - 19731, 2263, - 19754, 676, - 19854, 382, -}; - -const Word16 gp_gamma_1sfr_7b_fx[2*128] = /*Q14/Q9 */ -{ - 350, 85, - 428, 24, - 438, 681, - 642, 195, - 1071, 2012, - 1080, 402, - 1148, 1236, - 1159, 62, - 1424, 12, - 1662, 134, - 1985, 299, - 2100, 34, - 2163, 3168, - 2219, 538, - 2393, 6580, - 2499, 967, - 2882, 221, - 2974, 12743, - 3251, 98, - 3294, 51, - 3586, 1560, - 3711, 411, - 3721, 700, - 3862, 21, - 3947, 169, - 4001, 2249, - 4198, 4632, - 4372, 8, - 4993, 70, - 5022, 265, - 5568, 1194, - 5664, 495, - 5698, 115, - 5885, 854, - 6115, 2990, - 6266, 153, - 6376, 39, - 6432, 16, - 6601, 345, - 7108, 1957, - 7231, 660, - 7491, 202, - 7687, 93, - 8054, 3882, - 8108, 9624, - 8186, 1424, - 8243, 59, - 8354, 935, - 8358, 6401, - 8383, 439, - 8794, 285, - 8940, 124, - 9643, 25, - 9643, 581, - 9670, 2709, - 10065, 160, - 10218, 9, - 10240, 1728, - 10249, 80, - 10418, 1113, - 10497, 373, - 10650, 236, - 11095, 44, - 11095, 756, - 11284, 4978, - 11290, 16722, - 11815, 2299, - 11882, 482, - 12059, 114, - 12332, 8550, - 12363, 1394, - 12392, 186, - 12517, 336, - 12549, 3413, - 12694, 953, - 13096, 614, - 13185, 71, - 13247, 262, - 13479, 1914, - 13791, 14, - 13805, 30, - 14064, 138, - 14182, 420, - 14212, 1175, - 14477, 765, - 14605, 2745, - 14612, 6324, - 14730, 4199, - 14833, 301, - 14842, 203, - 14910, 12790, - 15171, 100, - 15191, 1625, - 15289, 532, - 15405, 52, - 15550, 985, - 16096, 357, - 16175, 2113, - 16284, 232, - 16333, 669, - 16363, 22999, - 16396, 156, - 16443, 1270, - 16455, 3482, - 16543, 8, - 16650, 5425, - 16878, 452, - 16989, 84, - 17024, 9676, - 17194, 876, - 17730, 20, - 17780, 1442, - 17864, 38, - 17874, 254, - 17929, 526, - 18011, 2403, - 18751, 7153, - 18786, 117, - 18820, 4420, - 19002, 63, - 19099, 401, - 19111, 183, - 19197, 776, - 19202, 2953, - 19236, 1052, - 19255, 301, - 19354, 1760, - 19432, 593, -}; - -const Word16 gp_gamma_1sfr_6b_fx[2*64] = /*Q14/Q9 */ -{ - 436, 182, - 473, 63, - 962, 16, - 992, 647, - 1258, 1582, - 1447, 351, - 1711, 125, - 1809, 46, - 2569, 4173, - 2607, 957, - 2826, 251, - 2904, 12481, - 3248, 26, - 3594, 2254, - 3664, 78, - 3715, 483, - 4232, 8, - 4681, 188, - 5066, 6623, - 5232, 1273, - 6232, 695, - 6234, 49, - 6238, 113, - 6312, 318, - 7012, 17, - 7327, 3183, - 8008, 1739, - 8692, 446, - 8769, 163, - 8923, 1019, - 9094, 81, - 10358, 286, - 10491, 28, - 10612, 9788, - 10715, 760, - 11045, 4822, - 11319, 2403, - 11684, 56, - 12314, 108, - 12460, 556, - 12580, 9, - 12716, 213, - 12821, 1336, - 14202, 374, - 14325, 16971, - 14612, 838, - 14625, 3285, - 14668, 6231, - 14919, 39, - 15131, 137, - 15476, 1847, - 16056, 255, - 16277, 494, - 16290, 66, - 16582, 1048, - 16859, 17, - 17220, 8723, - 17443, 4295, - 18069, 2499, - 18212, 176, - 18499, 91, - 18517, 1445, - 18522, 332, - 18596, 663, -}; - -const Word16 gp_gamma_2sfr_7b_fx[2*128] = /*Q14/Q9 */ -{ - 99, 1224, - 156, 243, - 168, 579, - 290, 355, - 437, 441, - 475, 187, - 734, 738, - 930, 93, - 1133, 153, - 1136, 298, - 1490, 508, - 1946, 401, - 1978, 16790, - 2098, 224, - 2117, 962, - 2407, 119, - 2686, 339, - 2929, 555, - 3404, 271, - 3465, 171, - 3469, 422, - 3714, 663, - 4436, 494, - 4494, 332, - 4571, 220, - 4583, 2182, - 4997, 848, - 5346, 380, - 5419, 108, - 5570, 579, - 5758, 266, - 5875, 442, - 5927, 170, - 6204, 3338, - 6394, 6435, - 6515, 328, - 6638, 730, - 6687, 1472, - 7045, 1056, - 7101, 498, - 7123, 210, - 7163, 9668, - 7345, 386, - 7598, 280, - 7853, 627, - 8462, 442, - 8648, 331, - 8822, 236, - 8887, 551, - 8953, 906, - 9317, 136, - 9587, 386, - 9651, 691, - 9796, 286, - 9852, 489, - 10005, 1215, - 10041, 192, - 10623, 576, - 10758, 329, - 10840, 425, - 10944, 792, - 11038, 257, - 11190, 1870, - 11541, 501, - 11729, 642, - 11873, 367, - 12064, 163, - 12332, 216, - 12339, 1100, - 12339, 295, - 12478, 444, - 12561, 568, - 12665, 845, - 13257, 396, - 13317, 677, - 13411, 511, - 13709, 324, - 13710, 1547, - 13711, 246, - 14054, 991, - 14112, 447, - 14246, 580, - 14355, 748, - 14394, 175, - 14453, 99, - 14604, 363, - 14887, 491, - 15074, 282, - 15110, 637, - 15242, 1292, - 15351, 413, - 15430, 843, - 15700, 541, - 15776, 204, - 15964, 335, - 15992, 688, - 16077, 453, - 16315, 4617, - 16406, 1032, - 16549, 595, - 16666, 384, - 16850, 776, - 16851, 482, - 16916, 253, - 17234, 309, - 17307, 2128, - 17469, 546, - 17666, 643, - 17699, 421, - 17852, 882, - 17870, 146, - 18146, 1244, - 18457, 489, - 18478, 346, - 18588, 723, - 18826, 208, - 19011, 1731, - 19042, 586, - 19286, 281, - 19428, 944, - 19446, 382, - 19555, 444, - 19689, 792, - 19755, 1111, - 19762, 527, - 19769, 1405, - 19774, 657, - 19780, 2675, -}; - -const Word16 gp_gamma_2sfr_6b_fx[2*64] = /*Q14/Q9 */ -{ - 185, 306, - 435, 519, - 458, 145, - 1000, 211, - 1217, 394, - 1241, 751, - 1788, 93, - 2026, 1234, - 2162, 265, - 2397, 158, - 2617, 472, - 3324, 340, - 3391, 623, - 3835, 207, - 4503, 17210, - 4628, 407, - 4939, 897, - 5102, 275, - 5300, 120, - 5560, 511, - 6309, 1909, - 6571, 335, - 6770, 205, - 6990, 642, - 7085, 5087, - 7500, 428, - 8357, 827, - 8452, 261, - 9079, 537, - 9289, 354, - 9854, 1176, - 9864, 165, - 10436, 8580, - 10549, 437, - 10615, 677, - 11010, 282, - 11940, 530, - 12183, 367, - 12475, 920, - 12865, 225, - 13359, 618, - 13431, 441, - 13521, 1623, - 14177, 341, - 14299, 130, - 14452, 775, - 14799, 508, - 15250, 276, - 15715, 1130, - 15757, 660, - 15879, 422, - 16355, 3256, - 16439, 187, - 16751, 562, - 16906, 331, - 17178, 827, - 17889, 471, - 18219, 2175, - 18786, 248, - 18985, 1354, - 19067, 703, - 19220, 384, - 19349, 954, - 19422, 553, -}; -const Word16 gp_gamma_3sfr_6b_fx[2*64] = /*Q14/Q9 */ -{ - 195, 150, - 817, 288, - 1152, 616, - 1366, 188, - 1377, 410, - 1526, 902, - 1570, 98, - 2258, 238, - 2489, 518, - 2935, 338, - 3142, 161, - 3456, 1705, - 3990, 432, - 4159, 709, - 4187, 270, - 4374, 1236, - 5283, 526, - 5431, 131, - 5507, 356, - 5762, 211, - 6792, 620, - 6842, 446, - 6969, 304, - 7671, 807, - 8362, 245, - 8448, 530, - 8610, 380, - 9314, 1088, - 9828, 170, - 9921, 7010, - 10026, 459, - 10193, 312, - 10261, 658, - 11554, 394, - 11739, 882, - 11791, 542, - 11985, 4329, - 11996, 246, - 12762, 13441, - 12844, 1512, - 13131, 465, - 13135, 339, - 13215, 740, - 14138, 608, - 14524, 417, - 14780, 1030, - 14823, 283, - 15016, 171, - 15264, 527, - 15823, 2706, - 15943, 699, - 15959, 360, - 16350, 473, - 17211, 573, - 17366, 901, - 17517, 238, - 17799, 414, - 18069, 1415, - 18630, 1920, - 18887, 634, - 19018, 318, - 19304, 495, - 19400, 1114, - 19413, 767, -}; - - -const Word16 gp_gamma_4sfr_6b_fx[2*64] = /*Q14/Q9 */ -{ - 153, 141, - 282, 501, - 399, 239, - 783, 369, - 1110, 744, - 1430, 183, - 1440, 1748, - 1524, 1091, - 1602, 296, - 1828, 99, - 2000, 439, - 2678, 228, - 2815, 600, - 3084, 347, - 3861, 477, - 4154, 163, - 4214, 285, - 4428, 733, - 4976, 384, - 5482, 566, - 5552, 234, - 6158, 929, - 6536, 470, - 6560, 326, - 7288, 173, - 7429, 663, - 7447, 10616, - 7871, 407, - 8457, 266, - 8559, 550, - 8679, 1421, - 9457, 356, - 9533, 785, - 9854, 471, - 10584, 5781, - 10792, 3815, - 10813, 206, - 10829, 302, - 10986, 606, - 11380, 433, - 11468, 1073, - 12485, 356, - 12726, 520, - 12783, 721, - 13554, 259, - 13763, 139, - 13884, 430, - 14060, 2592, - 14266, 599, - 14332, 925, - 14997, 337, - 15355, 485, - 15526, 712, - 16440, 587, - 16504, 395, - 16626, 204, - 17228, 1287, - 17563, 805, - 17629, 517, - 18159, 1814, - 18320, 303, - 19228, 437, - 19263, 636, - 19417, 989, -}; - -const Word16 b_1sfr_fx[2] = /*Q12 */ -{ - 9697, -920 -}; -const Word16 b_2sfr_fx[4] = /*Q12 */ -{ - -1, 70, 3763, 542 -}; -const Word16 b_3sfr_fx[6] = -{ - -478, 110, 553, 3264, 92, 730 -}; -const Word16 b_4sfr_fx[8] = -{ - -381, 65, -271, 836, 3246, 34, 143, 650 -}; -/*-------------------------------------------------------------------* - * 1/4 resolution interpolation filter (-3 dB at 0.913*fs/2) - * Used in lib_com_fx\PRED_LT4_FX.C - * Q14 - *-------------------------------------------------------------------*/ -const Word16 inter4_2_fx[] = -{ - 0, 1, 2, 1, - -2, -7, -10, -7, - 4, 19, 28, 22, - -2, -33, -55, -49, - -10, 47, 91, 92, - 38, -52, -133, -153, - -88, 43, 175, 231, - 165, -9, -209, -325, - -275, -60, 226, 431, - 424, 175, -213, -544, - -619, -355, 153, 656, - 871, 626, -16, -762, - -1207, -1044, -249, 853, - 1699, 1749, 780, -923, - -2598, -3267, -2147, 968, - 5531, 10359, 14031, 15401, - 14031, 10359, 5531, 968, - -2147, -3267, -2598, -923, - 780, 1749, 1699, 853, - -249, -1044, -1207, -762, - -16, 626, 871, 656, - 153, -355, -619, -544, - -213, 175, 424, 431, - 226, -60, -275, -325, - -209, -9, 165, 231, - 175, 43, -88, -153, - -133, -52, 38, 92, - 91, 47, -10, -49, - -55, -33, -2, 22, - 28, 19, 4, -7, - -10, -7, -2, 1, - 2, 1, 0, 0 -}; - -const Word16 pwf_fx[17]= -{ - 22938, 16056, 11239, 7868, 5507, 3855, 2699, 1889, - 1322, 926, 648, 454, 317, 222, 156, 109, - 76 -}; - -const Word16 Gamma_29491_Tbl[] = -{ - 29491, 26542, 23888, 21499, 19349, 17414, 15672, 14105, - 12694, 11425, 10282, 9254, 8329, 7496, 6746, 6071 -}; - - -/* Used in 'lsp2lsf_fx.c' */ -const Word8 Ind_Guess[256]= -{ - 126, 122, 120, 119, 117, 116, 115, 114, - 113, 112, 111, 110, 110, 109, 108, 108, - 107, 106, 106, 105, 104, 104, 103, 103, - 102, 102, 101, 101, 100, 100, 99, 99, - 98, 98, 97, 97, 96, 96, 95, 95, - 94, 94, 94, 93, 93, 92, 92, 91, - 91, 91, 90, 90, 89, 89, 89, 88, - 88, 87, 87, 87, 86, 86, 86, 85, - 85, 84, 84, 84, 83, 83, 83, 82, - 82, 82, 81, 81, 81, 80, 80, 80, - 79, 79, 78, 78, 78, 77, 77, 77, - 76, 76, 76, 75, 75, 75, 74, 74, - 74, 73, 73, 73, 72, 72, 72, 72, - 71, 71, 71, 70, 70, 70, 69, 69, - 69, 68, 68, 68, 67, 67, 67, 66, - 66, 66, 65, 65, 65, 64, 64, 64, - 64, 63, 63, 63, 62, 62, 62, 61, - 61, 61, 60, 60, 60, 59, 59, 59, - 58, 58, 58, 57, 57, 57, 56, 56, - 56, 55, 55, 55, 55, 54, 54, 54, - 53, 53, 53, 52, 52, 52, 51, 51, - 51, 50, 50, 50, 49, 49, 49, 48, - 48, 47, 47, 47, 46, 46, 46, 45, - 45, 45, 44, 44, 44, 43, 43, 43, - 42, 42, 41, 41, 41, 40, 40, 40, - 39, 39, 38, 38, 38, 37, 37, 36, - 36, 36, 35, 35, 34, 34, 33, 33, - 33, 32, 32, 31, 31, 30, 30, 29, - 29, 28, 28, 27, 27, 26, 26, 25, - 25, 24, 24, 23, 23, 22, 21, 21, - 20, 19, 19, 18, 17, 17, 16, 15, - 14, 13, 12, 11, 10, 8, 7, 5 -}; -/* Version 101 points */ - - -const Word16 tbl_mid_voi_wb_1b_fx[] = /* Q13*/ -{ - 4551, 4599, 4754, 5035, 4982, 5228, 5318, 5603, 5699, 5652, 5642, 5766, 5825, 5874, 5819, 6056, - 3816, 3355, 2321, 2712, 2900, 2715, 2790, 2508, 2506, 2610, 2617, 2419, 2538, 2622, 3004, 2725, -}; -const Word16 tbl_mid_voi_wb_4b_fx[] = -{ - 4337, 4235, 3526, 4083, 3514, 5457, 3168, 2509, 4418, 5021, 1313, 2952, 5347, 3893, 8325, 11758, - 4180, 4037, 3965, 3481, 4028, 3284, 2644, 4585, 4749, 3076, 3211, 1101, 4175, 7440, 5745, -4105, - 4239, 3957, 4450, 4974, 5400, 5734, 6246, 6586, 7774, 2699, 2783, 3474, 1345, -316, 5069, 4904, - 3964, 3810, 2673, 3031, 2249, 3168, 3155, 4204, 7316, 7176, 8680, 7147, 4918, 4136, 3142, 3011, - 4071, 3853, 3898, 3973, 3464, 2878, 5783, 5341, 1725, 801, 1194, 4239, 6866, 4950, 794, 6270, - 3933, 3750, 4931, 3667, 3585, 2550, 4308, 5757, 4503, 7081, 4893, 1076, 109, 1650, 1887, 8861, - 4803, 4827, 4969, 5511, 5768, 4327, 5277, 4934, 6909, 7672, 5355, 3940, 9990, 9622, 7457, 4202, - 4515, 4259, 2444, 4847, 3728, 4599, 4975, 6144, 4087, 4367, 7025, 5028, 2405, 7014, 13366, 6264, - 4746, 4556, 5408, 5866, 4733, 4088, 3965, 3329, 4669, 3105, 5918, 7824, 6026, 9177, 1856, 13229, - 4130, 4214, 2516, 3542, 4847, 3751, 3704, 2380, 4190, 4787, 4651, 4981, 5702, -27, -2961, 129, - 4461, 4724, 5233, 4680, 6010, 7222, 6351, 3069, 605, 5934, 5627, 3836, 3490, 6060, 3556, 2585, - 4628, 4723, 5465, 4180, 4460, 6173, 5915, 7260, 4703, 4114, 3938, 9585, 8085, 3781, 7520, 625, - 5002, 5621, 6352, 6914, 7170, 7719, 7585, 8408, 8360, 7883, 7370, 7222, 6616, 6002, 5565, 9394, - 4059, 4121, 4178, 4417, 3437, 1460, 1031, 111, 585, 1708, 4219, 5419, 2585, 3195, 6149, 3221, - 3394, 2776, 1970, 2707, 2983, 3931, 3247, 1729, 449, -109, -46, -469, 397, 1980, 2305, 1573, - 3259, 1870, 242, 392, 748, 615, 1185, 1285, 2259, 2687, 2212, 1762, 2174, 1887, 1847, 2073, -}; -const Word16 tbl_mid_voi_wb_5b_fx[] = -{ - 4182, 3820, 4103, 5620, 4100, 4478, 3949, 5053, 2918, 3083, 4229, 3732, 1823, 6350, 17230, 4601, - 4361, 4077, 2236, 4128, 3216, 4673, 6022, 6522, 5746, 4282, 3121, 4448, 6457, 12573, 4401, 7796, - 4228, 4086, 4375, 4320, 4474, 4735, 4427, 5616, 5975, 138, 5887, 3722, 2304, -3430, 4995, 6246, - 4320, 4344, 4008, 4327, 3323, 6835, 3627, 3330, 3123, 3971, 2382, 1801, 6422, 3162, 9038, 14129, - 4193, 4202, 4413, 2703, 4175, 4330, 2615, 7600, 1717, 3506, 5671, 7170, 3545, 2350, -2738, 7287, - 4170, 3912, 4323, 3821, 4450, 6765, 7496, 8107, 7447, 5525, 3088, 1963, 2014, 3330, 976, 1002, - 4583, 4419, 3584, 4125, 4783, 5133, 3188, 5000, 4812, 4639, 10038, 7018, 5114, 5567, 3292, -6364, - 3926, 4092, 2710, 2721, 1799, 3509, 4542, 3351, 4583, 5877, 6539, 5135, 981, 4029, 7221, 592, - 4624, 4567, 4468, 4630, 5710, 5222, 5883, 2562, 8453, 2825, 109, 6491, 1210, 2921, 7292, 7118, - 4245, 4160, 5119, 4356, 5544, 3034, 1507, 4179, 5971, 1949, 3388, 613, 4995, 9019, 6755, -628, - 4905, 4962, 4529, 7025, 4905, 4470, 5063, 3440, 6348, 6102, 4319, 4395, 7515, 6549, -3697, 6513, - 4683, 4592, 5303, 4593, 4171, 5264, 6116, 7434, 4105, 5454, 2544, 8493, 6491, 894, 8983, -2406, - 3632, 3435, 3988, 4195, 3684, 2173, 6735, 4552, -339, 763, 308, 3463, 6123, 2895, 2831, 5715, - 4316, 4111, 2236, 2682, 1058, 544, 2541, 1677, 3549, 2767, 3376, 5901, 6689, 5811, 6617, 3311, - 4487, 4285, 4992, 3656, 5970, 4547, 3975, 5998, 4985, 6614, 4807, 1971, 14937, 4388, 6153, 3352, - 4601, 4710, 4957, 4454, 4873, 7207, 5881, 3461, 2282, 1829, 5617, 9926, 10043, 7722, 3232, 4629, - 3965, 3837, 2088, 4265, 5042, 3478, 4453, 2804, 4162, 4858, 4315, 4343, 5193, -1823, -5028, -1137, - 3439, 2837, 2549, 4062, 2857, 2657, 2662, 5088, 10548, 8913, 6631, 6395, 5568, 3210, 2431, 3400, - 4073, 3839, 5806, 5296, 3766, 2342, 2585, 891, 3144, 2988, 6807, 4626, 3700, 5854, 1543, 16158, - 4189, 4045, 4293, 4527, 4008, 1413, 4871, 6081, 3297, 6546, 5006, -365, -2369, 1375, 5522, 8787, - 4778, 4782, 4941, 4538, 4497, 3129, 4934, 4371, 7175, 6923, 8620, 10236, 8664, 10088, 10923, 7314, - 4945, 5016, 6439, 6353, 6624, 6463, 6938, 7547, 7004, 7283, 7655, 7149, 7650, 2747, 3416, 14892, - 4776, 5431, 5515, 6194, 5700, 5485, 2795, 5476, 4024, 8891, 2930, 7916, 3428, 8070, 5920, 13440, - 4718, 4986, 4800, 5286, 6567, 6554, 6601, 1235, -1216, 6556, 6098, 3962, 4361, 5536, 5517, 3935, - 4741, 4679, 5593, 4891, 3849, 5675, 6487, 6239, 7062, 12044, 10918, 2438, 3977, 7296, 8445, 6625, - 4859, 5781, 6592, 7399, 8027, 8858, 8139, 8951, 8760, 5506, 6294, 6540, 6516, 7527, 7688, 4084, - 4077, 3771, 3650, 3381, 3367, 4048, 3899, 4382, 3017, -2156, -1464, -2207, 828, 4838, 2071, 2363, - 3796, 3437, 3558, 3842, 2170, 4311, 2602, 696, 1939, 2576, 1239, 328, -129, -647, 1702, 2893, - 4015, 3506, 367, 1350, 3328, 3700, 3827, 2439, 1434, 3887, 2279, 1593, 3673, 5508, 3905, -2973, - 4088, 3990, 3732, 3256, 4718, 1375, 152, -99, -254, 1140, 3578, 3316, 2195, 2408, 5027, 999, - 3749, 3175, 1475, 686, 2006, 1959, 1558, 3059, 5374, 5014, 2439, 2396, 2467, 2218, 1031, 7866, - 2037, 701, 124, 278, 328, 253, 660, 528, 826, 473, 801, 800, 1053, 1330, 804, 967, -}; - -const Word16 tbl_mid_unv_wb_4b_fx[] = -{ - 5190, 3143, 50, 2521, 5180, 6320, 3890, 3365, 3582, 3517, 3406, 3049, 2864, 1621, 1932, -950, - 6813, 6650, 2135, 972, 452, 1453, 3221, 1697, 3165, 4443, 5924, 6297, 3907, 2862, 3586, 4625, - 3204, 2673, 6499, 4319, 1054, 559, 4404, 5815, 5072, 6625, 4493, 2479, 1773, 1606, 2099, 8330, - 1924, 2666, 4171, 5517, 5898, 7238, 7318, 7696, 7250, 6269, 6164, 6038, 5249, 4284, 4147, 2828, - 2834, 788, 77, 2016, 1824, 3224, 3441, 4472, 6286, 6717, 6783, 6743, 6715, 7051, 6562, 2531, - 6386, 5634, 5761, 5184, 3523, 4284, 1867, 1045, 579, 1176, 1743, 2599, 5276, 5564, 5368, 7914, - 1795, 1380, 5184, 9326, 8023, 3138, 1258, 1729, 3328, 3934, 5169, 5645, 5271, 5894, 5591, 5145, - 5734, 5844, 8799, 8753, 5628, 5710, 5255, 4872, 5349, 3431, 3006, 2486, 1418, 974, 1115, 2035, - 4194, 8421, 1812, 6078, 3003, 3455, 6719, 7501, 2120, 1892, 2658, 2317, 2296, 5735, 6553, 4485, - 8072, 11456, 6455, 5069, 4918, 4936, 4819, 4932, 6029, 6246, 6289, 6704, 6749, 5337, 4526, 3974, - 3709, 5584, 4884, -1502, 4864, 2333, 606, 5976, 6438, 2413, 1937, 3663, 5593, 6989, 6450, 3555, - 3843, -6887, 3697, 3880, 4448, 4264, 5961, 4198, 3583, 3942, 3606, 3768, 4457, 4374, 4096, 4524, - 2551, 6781, 7017, 2902, 9227, 8728, 7130, 1873, 2308, 4393, 3981, 3976, 4002, 4080, 4820, 5611, - 220, -174, -43, -542, 449, 1470, 1759, 1893, 1294, 995, 723, 723, 769, 994, 1369, 4413, - 1651, 2259, 3079, 2913, 1176, -491, -1262, -827, -217, 908, 1126, 1751, 1901, 1765, 2656, 247, - 5380, 7307, 7727, 8135, 8270, 8471, 8792, 8573, 8335, 8420, 8057, 7562, 7119, 7458, 6806, 7385, -}; -const Word16 tbl_mid_unv_wb_5b_fx[] = -{ - 6237, 6323, 1151, 763, 4218, 6546, 8437, 8701, 7456, 6604, 4631, 2901, 3050, 1793, 1955, 2260, - 5542, 4318, 5343, 5521, 5999, 5477, 5265, 5234, 4616, 3329, 3444, 1816, -442, 45, -2, 8922, - 6370, 8208, 6583, 5630, 5401, 5458, 5188, 5595, 6637, 6891, 6962, 6967, 7014, 6330, 5445, 3101, - 2750, 2858, 5206, 4594, 3310, 3494, 2463, 3410, 3405, 6151, 7682, 8593, 4440, 3715, 2946, -4371, - 1157, 661, 3743, 6418, 7515, 8319, 7485, 7298, 7928, 7515, 6812, 5671, 5095, 5122, 4997, 3940, - 5133, 3446, 2693, 1620, 1860, 2663, 4603, 6289, 7451, 7255, 7511, 7486, 8869, 8704, 8431, 6632, - 2497, 6706, 7036, 3437, 10854, 8893, 6033, 3021, 2936, 4766, 4145, 4097, 5177, 4883, 5920, 7612, - -152, -54, 3955, 1170, 5562, 4695, 1370, 8293, 3106, 1942, 5508, 4878, 3495, 1094, 1079, 5401, - 482, 373, 220, -355, -236, -328, -426, -147, 244, 563, 567, 915, 1012, 676, 804, 2721, - 437, 816, 3208, 3395, 2501, 3795, 4380, 2553, 399, 31, -519, -475, -162, 1755, 2852, 1040, - 2067, 2125, 1247, 2393, 2872, 2218, 3502, 3977, 4712, 4275, 2600, 2380, 2314, 2893, 3555, 13929, - 3967, -635, -1752, 2490, 303, 969, 1045, 2839, 5670, 4651, 5202, 5248, 4182, 4381, 5492, 53, - 3041, 2494, 9264, 4970, 360, -3795, 6296, 6475, 4482, 6667, 5265, 2908, 2381, 2889, 3718, 5160, - 3364, 4119, 5929, 3164, -745, 9368, 1652, -719, 6323, 5113, 1919, 1260, 2630, 3585, 2224, 3178, - 1643, 837, 8074, 8337, 4237, 2332, 2190, -1176, 1968, 1238, 2354, 4756, 5269, 5759, 4962, 5411, - 7590, 6471, 2635, 1869, 1209, 1505, 2118, 892, 1652, 3717, 5010, 3969, 2265, 2428, 3278, 5027, - 7289, 8658, 11183, 8913, 6084, 6673, 5961, 4041, 3839, 2643, 2094, 3215, 2956, 2895, 3327, 5063, - 5814, -4982, 1120, 2112, 4384, 5288, 6052, 4305, 4724, 5062, 3380, 4200, 5838, 7181, 6383, 4771, - 3891, 7361, 4160, 1422, 4971, 939, 281, 3585, 4817, 1176, -306, 260, 3815, 8273, 7095, 1529, - 8179, 19416, 3518, 3547, 4619, 4231, 3359, 3606, 5131, 4469, 5204, 5115, 4941, 4772, 4175, 5160, - 4539, 5393, 2706, 5371, 1468, 8488, 10356, 2778, 1426, 371, 8093, 7808, 5208, 5996, 6081, 5057, - 3266, 3481, -4953, -5638, 4022, 5502, 3586, 3117, 2737, 3826, 3658, 3933, 3602, 4920, 4959, 3483, - 3846, 9592, 3360, 6480, 1215, 3170, 5218, 8641, 664, 2695, 3353, 1479, 1687, 6049, 7074, 4696, - 2231, 4497, 6761, 6799, 5941, 5445, 8083, 7944, 5879, 3744, 2518, 6482, 6581, 6096, 6379, -133, - 3360, 6078, 1064, 13807, 8185, 3605, 4327, 3777, 6211, 4977, 5015, 4871, 5825, 2506, 2130, 4946, - 5412, 4507, 952, 4098, 5027, 3949, 3501, 1778, 1955, 2126, 1626, 3669, 4446, -1101, 736, -2708, - 4824, 7481, 8884, -2619, -2754, 281, 4158, 3251, 4602, 2946, 3915, 6169, 6075, 3495, 3266, 4375, - 6135, 2668, 6784, 10326, 6892, 5479, 1511, 3070, 6410, 9193, 6954, 1084, 2873, 7030, 8139, 5670, - 7255, 5764, 5122, 5787, 3129, 5475, -2720, 3770, -827, 872, 1591, 4645, 7218, 5513, 5778, 6323, - 1185, -13100, 5560, 5867, 4153, 2591, 4923, 3450, 2062, 4251, 4289, 3397, 3835, 2082, 2343, 3172, - 4460, 4411, 3940, 4420, 9410, -2789, -2525, -2877, -1868, 2850, 4490, 4093, 3162, 3889, 3800, 3492, - 6408, 8292, 8434, 8544, 8707, 9146, 9377, 9301, 9063, 8945, 8346, 8173, 7175, 7254, 6120, 7420, -}; -const Word16 tbl_mid_gen_wb_2b_fx[] = -{ - 3814, 5145, 5856, 5290, 5277, 4880, 4877, 4273, 3868, 3776, 3392, 3163, 3120, 3019, 3395, 5814, - 1482, 861, 1968, 3198, 3105, 3737, 3749, 4525, 4982, 4828, 5023, 5335, 5327, 5296, 5092, 3444, - 3955, 3851, 1520, 1666, 1554, 1385, 1537, 1276, 1443, 1526, 1597, 1636, 1867, 2041, 2483, 2059, - 7038, 8112, 7324, 6969, 6877, 7028, 6987, 7098, 7003, 6955, 6927, 6808, 6685, 6459, 5871, 6047, -}; - - -const Word16 tbl_mid_gen_wb_5b_fx[] = -{ - 6510, 8058, 7103, 6095, 6483, 5866, 6026, 6443, 6882, 6907, 7015, 6581, 5649, 4044, 2816, 2519, - 3778, 2123, 3580, 4221, 2598, 4631, 2844, 4905, 5446, 4529, 5186, 6228, 6210, 5693, 6213, -4670, - 9050, 9934, 8441, 7921, 7546, 7840, 7977, 8335, 8679, 8706, 8703, 8607, 8560, 8375, 7759, 6405, - 4243, 5775, 2939, 5887, 4078, 3117, 5267, 5680, 4589, 2401, 731, 1011, 1657, 4733, 7051, 3992, - 2508, 3156, 3347, 1605, 4450, 4633, 3476, 6019, 4083, 3824, 5133, 6020, 3253, 1368, 1736, 13507, - 5934, 6372, 4494, 2957, 4424, 6667, 8167, 8413, 7957, 7139, 5518, 3059, 2829, 2821, 2773, 3274, - 4984, 5566, 5831, 4556, 5732, 6738, 6689, 4683, 2265, 4214, 7242, 9989, 9776, 9068, 4748, 2292, - 2601, 4933, 2764, 4923, 3763, 3678, 5596, 2079, 6108, 6824, 5507, 5612, 6793, 5553, 1140, 9993, - 7084, 6685, 5313, 5196, 3111, 5337, 3535, 2476, 2477, 1737, 2090, 4033, 5680, 6548, 7310, 11811, - 8140, 8602, 7166, 6738, 6018, 5299, 5686, 4722, 4108, 4456, 3713, 3131, 2658, 2336, 2250, 8051, - 727, 1865, 6073, 3932, 2258, 2413, 4823, 5733, 5101, 6126, 4690, 1130, 1172, 1479, 3956, 7204, - 6042, 1024, 5371, 5997, 4964, 5575, 5078, 5843, 6909, 8465, 8601, 6137, 5699, 8049, 9922, 8318, - 2728, 1625, 4750, 5004, 5799, 4938, 6353, 3274, 1781, 3095, 1479, 3136, 5470, 1391, -626, 2422, - 4407, 3228, 1266, 1488, 1222, 963, 1148, 1182, 1330, 1770, 860, 381, 813, 1268, 2352, 3956, - 1683, -120, 83, 1239, 946, 1609, 1982, 3215, 3950, 4200, 4497, 4898, 4551, 3595, 2345, 2444, - 1055, 3207, 7460, 6808, 7103, 6980, 7902, 8196, 6821, 6190, 6405, 7414, 7967, 7506, 6921, 9871, - 3164, 7995, 8446, 8770, 8443, 8302, 7372, 7049, 6090, 5698, 5090, 4792, 4996, 4874, 4285, 6685, - 3681, 319, 536, 3174, 4495, 5486, 5807, 5751, 5461, 4423, 3556, 3449, 5148, 7560, 6277, 3783, - 1987, 4209, 6954, 5880, 7459, 7762, 4326, 4958, 5154, 2150, 2988, 2469, 1175, 1099, 3999, 3950, - 1306, 2303, 7748, 8238, 6116, 2824, 1772, 1130, 2538, 3345, 5317, 4773, 3668, 5458, 5519, 5594, - 4140, 4329, 3339, 3001, 2669, -79, -582, -1729, -680, 1294, 2752, 3700, 3627, 4428, 4950, 2744, - 5309, 3611, 993, 3526, 2043, 3938, 2069, 1434, 4173, 2609, 2704, 3690, 3686, 1894, 1401, -1682, - 6091, 4810, 970, 1063, 1707, 3056, 4597, 6742, 7397, 6913, 7359, 7884, 7571, 6830, 6039, 3823, - 6599, 6006, 1248, 4330, 6935, 3784, 3535, 3902, 3221, 5384, 5691, 5997, 5975, 6731, 9125, 5385, - 204, 242, 2009, 3375, 3412, 3407, 2691, 2547, 598, -150, 67, 250, 618, 1185, 1987, 1157, - 4986, 7977, 6971, 1528, 86, 281, 1497, 3002, 4193, 4430, 4721, 5317, 6001, 6181, 6962, 5480, - 6914, 7963, 5254, 3050, 5365, 3224, 3781, 3044, 2571, 3155, 2243, 1612, 2157, 2526, 2784, -1629, - 7350, 6702, 2435, 1937, 2549, 1978, 2819, 2817, 2059, 2493, 3408, 2344, 1239, 1177, 914, 3763, - 4362, 3105, -1457, -1760, 314, 1452, 2603, 1642, 1670, 1652, 2258, 2492, 3844, 4399, 5213, 660, - 350, 357, 109, 83, -555, -886, -714, -587, -120, 25, 189, 531, 591, 146, 156, 1435, - 498, 211, 3062, 6766, 7150, 8142, 7531, 7527, 7855, 6898, 6613, 6480, 5290, 4310, 5341, 4129, - 2753, 6959, 7088, 4622, 2646, 2395, 1756, 325, 488, 259, -125, -577, -553, 615, 557, 4617, -}; - -const Word16 CBsizes_fx[] = -{ - 1,2,4,8,16,32,64 -}; - -/*----------------------------------------------------------------------------------* - * LSF quantization - LSF mode/codebook selection tables - *----------------------------------------------------------------------------------*/ -const Word16 CB_lsf_fx[] = -{ - -1, /* Mode 0 : INACTIVE NB, Safety net */ - -1, /* Mode 1 : UNVOICED NB, Safety net */ - 0, /* Mode 2 : VOICED NB, Safety net */ - 2, /* Mode 3 : GENERIC NB, Safety net */ - 2, /* Mode 4 : TRANSITION NB, Safety net */ - 4, /* Mode 5 : AUDIO NB, Safety net */ - -1, /* Mode 6 : INACTIVE WB, Safety net */ - -1, /* Mode 7 : UNVOICED WB, Safety net */ - 5, /* Mode 8 : VOICED WB, Safety net */ - 7, /* Mode 9 : GENERIC WB, Safety net */ - 7, /* Mode 10 : TRANSITION WB, Safety net */ - 9, /* Mode 11 : AUDIO WB, Safety net */ - -1, /* Mode 12 : INACTIVE WB16k, Safety net */ - -1, /* Mode 13 : UNVOICED WB16k, Safety net */ - -1, /* Mode 14 : VOICED WB16k, Safety net */ - -1, /* Mode 15 : GENERIC WB 16k, Safety net */ - 10, /* Mode 16 : TRANSITION WB16k, Safety net */ - -1, /* Mode 17 : AUDIO WB16k, Safety net */ - 13 /* Mode 18 : CNG, Safety net */ -}; - -const Word16 CB_p_lsf_fx[] = -{ - 0, /* Mode 0 : INACTIVE NB, Predictive */ - 1, /* Mode 1 : UNVOICED NB, Predictive */ - 4, /* Mode 2 : VOICED NB, Predictive */ - 4, /* Mode 3 : GENERIC NB, Predictive */ - -1, /* Mode 4 : TRANSITION NB, Predictive */ - -1, /* Mode 5 : AUDIO NB, Predictive */ - 0, /* Mode 6 : INACTIVE WB, Predictive */ - 1, /* Mode 7 : UNVOICED WB, Predictive */ - 6, /* Mode 8 : VOICED WB, Predictive */ - 6, /* Mode 9 : GENERIC WB, Predictive */ - -1, /* Mode 10 : TRANSITION WB, Predictive */ - -1, /* Mode 11 : AUDIO WB, Predictive */ - 0, /* Mode 12 : INACTIVE WB16k, Predictive */ - -1, /* Mode 13 : UNVOICED WB16k, Predictive */ - -1, /* Mode 14 : VOICED WB16k, Predictive */ - 8, /* Mode 15 : GENERIC WB16k, Predictive */ - -1, /* Mode 16 : TRANSITION WB16k, Predictive */ - 10, /* Mode 17 : AUDIO WB16k, Predictive */ - 9, /* Mode 18 : GENERIC WB, MA Predictive */ -}; -const Word16 CBbits_fx[] = -{ - -1, /* Mode 0 : INACTIVE NB, Safety net */ - -1, /* Mode 1 : UNVOICED NB, Safety net */ - 4, /* Mode 2 : VOICED NB, Safety net */ - 5, /* Mode 3 : GENERIC NB, Safety net */ - 5, /* Mode 4 : TRANSITION NB, Safety net */ - 4, /* Mode 5 : AUDIO NB, Safety net */ - -1, /* Mode 6 : INACTIVE WB, Safety net */ - -1, /* Mode 7 : UNVOICED WB, Safety net */ - 4, /* Mode 8 : VOICED WB, Safety net */ - 5, /* Mode 9 : GENERIC WB, Safety net */ - 5, /* Mode 10 : TRANSITION WB, Safety net */ - 4, /* Mode 11 : AUDIO WB, Safety net */ - -1, /* Mode 12 : INACTIVE WB16k, Safety net */ - -1, /* Mode 13 : UNVOICED WB16k, Safety net */ - 4, /* Mode 14 : VOICED WB16k, Safety net */ - -1, /* Mode 15 : GENERIC WB16k, Safety net */ - 4, /* Mode 16 : TRANSITION WB16k, Safety net */ - -1, /* Mode 17 : AUDIO WB16k, Safety net */ - 4, /* Mode 18: CNG, Safety net */ -}; - - -const Word16 CBbits_p_fx[] = -{ - 5, /* Mode 0 : INACTIVE NB, Predictive */ - 4, /* Mode 1 : UNVOICED NB, Predictive */ - 3, /* Mode 2 : VOICED NB, Predictive */ - 3, /* Mode 3 : GENERIC NB, Predictive */ - -1, /* Mode 4 : TRANSITION NB, Predictive */ - 0, /* Mode 5 : AUDIO NB, Predictive */ - 5, /* Mode 6 : INACTIVE WB, Predictive */ - 4, /* Mode 7 : UNVOICED WB, Predictive */ - 3, /* Mode 8 : VOICED WB, Predictive */ - 3, /* Mode 9 : GENERIC WB, Predictive */ - -1, /* Mode 10 : TRANSITION WB, Predictive */ - 0, /* Mode 11 : AUDIO WB, Predictive */ - 5, /* Mode 12 : INACTIVE WB16k, Predictive */ - -1, /* Mode 13 : UNVOICED WB16k, Predictive */ - 3, /* Mode 14 : VOICED WB16k, Predictive */ - 5, /* Mode 15 : GENERIC WB16k, Predictive */ - -1, /* Mode 16 : TRANSITION WB16k, Predictive */ - 5, /* Mode 17 : AUDIO WB16k, Predictive */ - 5, /* Mode 9 : GENERIC WB, Predictive */ -}; - - - -const Word16 BitsVQ_fx[]= -{ - -1, /* Mode 0 : INACTIVE NB, Safety net */ - -1, /* Mode 1 : UNVOICED NB, Safety net */ - 8, /* Mode 2 : VOICED NB, Safety net */ - 9, /* Mode 3 : GENERIC NB, Safety net */ - 9, /* Mode 4 : TRANSITION NB, Safety net */ - 4, /* Mode 5 : AUDIO NB, Safety net */ - -1, /* Mode 6 : INACTIVE WB, Safety net */ - -1, /* Mode 7 : UNVOICED WB, Safety net */ - 8, /* Mode 8 : VOICED WB, Safety net */ - 9, /* Mode 9 : GENERIC WB, Safety net */ - 9, /* Mode 10 : TRANSITION WB, Safety net */ - 4, /* Mode 11 : AUDIO WB, Safety net */ - -1, /* Mode 12 : INACTIVE WB16k, Safety net */ - -1, /* Mode 13 : UNVOICED WB16k, Safety net */ - 8, /* Mode 14 : VOICED WB16k, Safety net */ - -1, /* Mode 15 : GENERIC WB16k, Safety net */ - 8, /* Mode 16 : TRANSITION WB16k, Safety net */ - -1, /* Mode 17 : AUDIO WB16k, Safety net */ - 4, /* Mode 18: CNG, Safety net */ -}; - - -const Word16 BitsVQ_p_fx[]= -{ - 5, /* Mode 0 : INACTIVE NB, Predictive */ - 8, /* Mode 1 : UNVOICED NB, Predictive */ - 6, /* Mode 2 : VOICED NB, Predictive */ - 6, /* Mode 3 : GENERIC NB, Predictive */ - -1, /* Mode 4 : TRANSITION NB, Predictive */ - 0, /* Mode 5 : AUDIO NB, Predictive */ - 5, /* Mode 6 : INACTIVE WB, Predictive */ - 12, /* Mode 7 : UNVOICED WB, Predictive */ - 6, /* Mode 8 : VOICED WB, Predictive */ - 6, /* Mode 9 : GENERIC WB, Predictive */ - -1, /* Mode 10 : TRANSITION WB, Predictive */ - 0, /* Mode 11 : AUDIO WB, Predictive */ - 5, /* Mode 12 : INACTIVE WB16k, Predictive */ - -1, /* Mode 13 : UNVOICED WB16k, Predictive */ - 6, /* Mode 14 : VOICED WB16k, Predictive */ - 5, /* Mode 15 : GENERIC WB16k, Predictive */ - -1, /* Mode 16 : TRANSITION WB16k, Predictive */ - 5, /* Mode 17 : AUDIO WB16k, Predictive */ - 5, /* Mode 18 : GENERIC WB, MA Predictive */ -}; - - -const Word16 predmode_tab[][6] = -{ - {1,1,2,2,0,2}, - {1,1,2,2,0,2}, - {1,-1,2,1,0,1}, - {1,1,2,1,0,2} /* should check how is the cb for audio mode at 13.2*/ -}; - -/* Stable ISP vector in Q15 */ -const Word16 stable_ISP_fx[16] = { 32139, 30274, 27247, 23170, 18206, 12540, 6393, 0, -6390, -12537, -18203, -23170, -27243, -30271, -32139, 1475 }; -/* Stable LSP vector in Q15 */ -/* This LSP corresponds to GEWB_Ave_fx */ -const Word16 stable_LSP_fx[16] = {32437, 31676, 29486, 25681, 21564, 16413, 10838, 5385, -735, -6405, -11986, -17040, -22052, -26346, -29678, -31784}; -/* Length 16 vector in Scale = 2.56f */ -const Word16 SVWB2_Ave_fx[16] = {998, 1488, 2682, 3823, 5084, 6305, 7485, 8686, 9861, 11004, 12339, 13664, 15088, 16330, 17663, 18754 }; -/* An 16-by-1 matrix */ -const Word16 IANB_Ave_fx[16] = -{ - 726, 1433, 2493, 3408, 4340, 5215, 6103, 6947, 7772, 8536, 9252, 10012, 10909, 12427, 13997, 15193 -}; -/* An 16-by-1 matrix */ -const Word16 IAWB_Ave_fx[16] = -{ - 577, 1350, 2526, 3535, 4539, 5504, 6497, 7460, 8445, 9396, 10371, 11319, 12307, 13268, 14249, 15207 -}; -/* An 16-by-1 matrix */ -const Word16 IAWB2_Ave_fx[16] = -{ - 731, 1777, 3194, 4386, 5629, 6806, 8012, 9164, 10329, 11469, 12731, 14037, 15326, 16538, 17801, 18927 -}; -/* Length 16 vector in Scale = 2.56f */ -const Word16 UVNB_Ave_fx[16] = {1018, 1764, 2856, 3751, 4611, 5410, 6233, 6961, 7685, 8304, 8859, 9325, 9977, 11741, 13699, 15074 }; -/* Length 16 vector in Scale = 2.56f */ -const Word16 UVWB_Ave_fx[16] = {898, 1900, 3172, 4190, 5181, 6161, 7134, 8066, 8995, 9888, 10784, 11636, 12527, 13396, 14301, 15183 }; -/* Length 16 vector in Scale = 2.56f */ -const Word16 SVNB_Ave_fx[16] = {890, 1268, 1930, 2902, 3938, 4823, 5832, 6644, 7487, 8202, 8906, 9545, 10788, 12565, 13959, 15183 }; -/* Length 16 vector in Scale = 2.56f */ -const Word16 SVWB_Ave_fx[16] = {832, 1248, 1949, 3083, 4131, 5117, 6179, 7067, 8008, 8922, 9875, 10741, 11785, 12860, 13968, 15048 }; -/* Length 16 vector in Scale = 2.56f */ -const Word16 GEWB_Ave_fx[16] = {742, 1350, 2354, 3495, 4446, 5456, 6434, 7331, 8309, 9218, 10145, 11044, 12042, 13063, 14101, 15103 }; -/* Length 16 vector in Scale = 2.56f */ -const Word16 GEWB2_Ave_fx[16] = {909, 1783, 3227, 4443, 5685, 6851, 7996, 9116, 10213, 11263, 12465, 13754, 15090, 16293, 17621, 18695 }; -/* Length 16 vector in Scale = 2.56f */ -const Word16 GENB_Ave_fx[16] = {836, 1344, 2257, 3263, 4173, 5031, 5950, 6707, 7514, 8234, 8881, 9439, 10393, 12226, 13855, 15135 }; -/* Length 16 vector in Scale = 2.56f */ -const Word16 TRNB_Ave_fx[16] = {919, 1335, 2106, 3142, 4092, 4938, 5905, 6670, 7490, 8199, 8868, 9444, 10544, 12383, 13900, 15156 }; -/* Length 16 vector in Scale = 2.56f */ -const Word16 TRWB_Ave_fx[16] = {834, 1326, 2151, 3341, 4305, 5299, 6318, 7198, 8167, 9071, 10001, 10867, 11871, 12912, 13986, 15046 }; -/* Length 16 vector in Scale = 2.56f */ -const Word16 TRWB2_Ave_fx[16] = {945, 1546, 2866, 4150, 5342, 6568, 7660, 8809, 9894, 10934, 12170, 13577, 14981, 16280, 17614, 18778 }; -/* Length 16 vector in Scale = 2.56f */ -const Word16 AUNB_Ave_fx[16] = {887, 1443, 2356, 3194, 4105, 4949, 5841, 6635, 7437, 8181, 8867, 9478, 10385, 12182, 13858, 15131 }; -/* Length 16 vector in Scale = 2.56f */ -const Word16 AUWB_Ave_fx[16] = {810, 1468, 2476, 3417, 4396, 5342, 6311, 7215, 8171, 9078, 10030, 10969, 12014, 13075, 14146, 15133 }; -/* Length 16 vector in Scale = 2.56f */ -const Word16 AUWB2_Ave_fx[16] = {933, 1745, 3040, 4157, 5379, 6490, 7646, 8725, 9852, 10930, 12214, 13647, 15062, 16297, 17636, 18768 }; -/* Length 16 vector in Scale = 2.56f */ -const Word16 means_wb_cleanspeech_lsf16k0[16] = {727, 1426, 2582, 3554, 4548, 5481, 6397, 7293, 8170, 9010, 9972, 11003, 12072, 13034, 14097, 14956 }; -/* Length 16 vector in Scale = 2.56f */ -const Word16 means_swb_cleanspeech_lsf25k6[16] = {786, 1840, 2892, 3833, 4778, 5658, 6641, 7662, 8692, 9630, 10603, 11534, 12489, 13387, 14349, 15217 }; -/* Length 16 vector in Scale = 2.56f */ -const Word16 means_swb_cleanspeech_lsf32k0[16] = {757, 1855, 2862, 3798, 4705, 5661, 6742, 7692, 8658, 9577, 10513, 11401, 12358, 13269, 14275, 15149 }; - -/* Length 16 vector in Q = 15 */ -const Word16 Predictor0_fx[16] = {27361, 27361, 27361, 27197, 27197, 27197, 26378, 26460, 26214, 25985, 26460, 26460, 25985, 25723, 25723, 24740 }; -/* Length 16 vector in Q = 15 */ -const Word16 Predictor1_fx[16] = {27034, 27034, 27034, 26640, 26313, 26640, 26640, 26132, 26214, 26214, 26460, 26870, 26870, 26706, 27034, 26640 }; -/* Length 16 vector in Q = 15 */ -const Word16 Predictor2_fx[16] = {24248, 23593, 24510, 24248, 24510, 24019, 24019, 23757, 23757, 24019, 24248, 24248, 23593, 23101, 23593, 23101 }; -/* Length 16 vector in Q = 15 */ -const Word16 Predictor3_fx[16] = {24248, 24248, 24740, 24248, 24510, 23757, 23429, 23101, 22610, 23101, 23593, 24740, 25002, 24740, 25002, 24838 }; -/* Length 16 vector in Q = 15 */ -const Word16 Predictor4_fx[16] = {19005, 18350, 19268, 19005, 19268, 18776, 18776, 18514, 18514, 18776, 19005, 19005, 18350, 17859, 17695, 17203 }; -/* Length 16 vector in Q = 15 */ -const Word16 Predictor5_fx[16] = {23839, 23593, 23593, 23839, 23839, 23593, 23593, 23593, 23839, 24084, 24347, 24576, 24576, 23364, 23364, 23364 }; -/* Length 16 vector in Q = 15 */ -const Word16 Predictor6_fx[16] = {24084, 23839, 24084, 23593, 23593, 22938, 22381, 21791, 21135, 21955, 22381, 24347, 24576, 23593, 24576, 24347 }; -/* Length 16 vector in Q = 15 */ -const Word16 Predictor7_fx[16] = {24347, 24084, 24347, 24347, 24347, 24084, 24347, 24576, 24576, 24740, 25068, 24347, 24084, 23839, 23364, 24740 }; -/* Length 16 vector in Q = 15 */ -const Word16 Predictor8_fx[16] = {24740, 24740, 24740, 24576, 24576, 24576, 24084, 23839, 23593, 23364, 23839, 23839, 23364, 23101, 23101, 22118 }; - -const Word16 *const ModeMeans_fx[] = {IANB_Ave_fx, UVNB_Ave_fx, SVNB_Ave_fx, GENB_Ave_fx, TRNB_Ave_fx, AUNB_Ave_fx, IAWB_Ave_fx, UVWB_Ave_fx, - SVWB_Ave_fx, GEWB_Ave_fx, TRWB_Ave_fx, AUWB_Ave_fx, IAWB2_Ave_fx, NULL, SVWB2_Ave_fx, GEWB2_Ave_fx, TRWB2_Ave_fx, AUWB2_Ave_fx - }; -const Word16 * const Predictors_fx[] = {Predictor6_fx, NULL, Predictor1_fx, Predictor3_fx, NULL, Predictor6_fx,Predictor5_fx, NULL, Predictor0_fx, - Predictor2_fx, NULL, Predictor5_fx, Predictor7_fx, NULL, Predictor8_fx, Predictor4_fx, NULL, Predictor7_fx - }; -/* An 16-by-16 matrix in Scale = 2.56f */ -const Word16 UVD_MA1_fx[256] = -{ - -301, -503, -426, -187, -131, -64, -45, -20, 11, 56, 63, 90, 110, 175, 97, 33, - 161, 353, 474, 502, 709, 782, 794, 765, 632, 532, 406, 285, 230, 145, 97, 52, - -37, -5, 205, 323, 412, 349, 221, 91, -6, -59, -86, -112, -32, 209, 73, 23, - -273, -615, -820, -794, -834, -838, -822, -819, -751, -701, -641, -562, -391, -271, -184, -63, - 262, 168, 104, -9, -78, -163, -141, -199, -191, -249, -245, -317, -168, 535, 109, 33, - -410, -675, -681, -611, -500, -396, -273, -183, -47, 60, 194, 357, 1044, 1080, 335, 140, - 154, 185, 256, 238, 203, 238, 280, 260, 300, 267, 258, 196, 121, -618, -263, -60, - 345, 705, 859, 786, 743, 584, 425, 267, 168, 105, 74, 28, 119, 267, 105, 39, - -39, -166, -230, -196, -255, -276, -318, -349, -387, -438, -539, -613, -752, -956, -1353, -1628, - 498, 479, 414, 231, 98, 5, -18, -41, -60, -78, -91, -96, -81, 72, 30, -8, - 41, 120, 65, 141, 117, 186, 249, 299, 418, 520, 566, 618, 692, 579, 321, 166, - -236, -278, -69, 13, 113, 362, 445, 539, 503, 387, 269, 172, 120, -21, 1, 4, - -103, -46, -137, -132, -108, -97, -67, -37, -8, 41, 82, 107, 43, -605, -189, -56, - -220, -315, -482, -516, -489, -445, -415, -362, -304, -205, -136, -68, -7, 131, 70, 25, - -10, -121, -210, -237, -224, -302, -246, -310, -271, -343, -285, -364, 28, 703, 135, 54, - 118, 50, -67, -166, -349, -416, -442, -446, -439, -420, -382, -319, -245, -209, -140, -82 -}; -/* An 16-by-16 matrix in Scale = 2.56f */ -const Word16 UVD_MA2_fx[256] = -{ - -75, -64, -150, -231, -272, -278, -248, -194, -156, -107, -74, -43, -92, -21, 9, 5, - 393, 275, -12, -156, -208, -215, -162, -132, -115, -109, -94, -85, -104, -10, 5, -1, - -297, -389, -99, -78, -66, -19, -12, 8, 0, -3, -15, -22, -113, -82, -16, 2, - 59, -11, 5, -33, -11, -61, -70, -139, -143, -239, -207, -223, 711, 701, 143, 68, - -195, 406, 222, 49, -6, -23, -6, 9, 0, 13, 26, 49, -44, -129, -18, -7, - 23, -30, -141, 79, -18, -76, -55, -14, 44, 98, 88, 86, -96, -351, -112, -39, - 380, 329, 235, 173, 141, 72, 25, -4, -6, -19, -21, -33, -55, -23, 3, -1, - -81, -210, -284, 158, 396, 290, 163, 59, -25, -22, -10, -6, -46, -32, 9, 5, - 9, 34, -15, 5, 23, -48, -127, -243, -347, -421, -455, -475, -495, -449, -294, -163, - -13, -171, -416, -414, -245, -25, 69, 102, 104, 84, 50, 33, -38, -4, 0, 5, - 50, 118, 68, 37, 147, 319, 371, 355, 291, 204, 130, 81, 21, 46, 36, 22, - -95, -108, 311, 214, -28, -153, -226, -192, -129, -69, -42, -11, -48, -17, 13, 2, - -185, -223, -104, 26, 53, 89, 132, 181, 258, 346, 397, 445, 392, 241, 125, 58, - 83, 33, -9, -81, 40, 99, 56, 8, -51, -85, -106, -124, -196, 5, 5, 0, - 143, 148, 19, -121, -247, -211, -67, 83, 198, 268, 290, 300, 240, 164, 86, 37, - -198, -136, 370, 372, 300, 240, 156, 113, 79, 60, 44, 29, -35, -38, 6, 7 -}; -/* An 16-by-16 matrix in Scale = 2.56f */ -const Word16 UVWB_MA3_fx[256] = -{ - -26, 23, 7, -6, -1, 3, 40, 35, -43, -24, 56, 157, 265, 423, 382, 260, - 61, -300, -130, -101, -8, 106, 108, 114, 88, 43, -2, -33, -56, 67, 29, 13, - -31, 47, 45, -121, 46, 22, 111, 233, -256, -252, -123, -71, -31, 54, 56, 33, - 20, -154, 67, 198, -232, -167, -86, -12, 79, 116, 88, 78, 44, 75, 27, -7, - -14, 153, -166, 21, 107, 64, 233, -223, -147, -27, -1, 43, 61, 70, 50, 18, - 3, -115, -8, 143, 192, 193, -124, -195, -198, -162, -75, 14, 45, 83, 79, 49, - 12, -57, 25, -29, -11, 12, -7, -13, -12, 31, 74, 99, -10, -421, -209, -111, - -25, 115, 119, -19, -117, -164, -203, -237, -206, -169, -110, -41, -11, 15, 1, -7, - -13, 170, -143, -128, -224, -94, 1, 96, 144, 102, 29, 2, -37, 46, 7, -12, - -11, 10, -34, 38, 24, 86, 149, 211, 240, 279, 247, 218, 154, 161, 74, 15, - -24, 64, 110, 125, -24, 123, 161, 166, 177, 18, -112, -116, -141, -117, -113, -91, - -4, -20, -17, -11, -27, 13, -15, -40, -58, -157, -252, -283, -288, -186, -162, -112, - -20, 2, 32, 44, -31, -49, 8, 13, 55, -59, -162, -212, -61, 384, 115, 36, - -4, 42, -75, 92, 268, -203, -125, 10, 52, 121, 72, -43, -109, -47, -66, -76, - -39, 76, 268, -254, -28, 87, 2, 91, 85, 68, 89, 96, 42, 90, 39, 4, - 2, 2, -56, 7, 67, -31, -219, -192, -24, 146, 249, 269, 209, 199, 106, 31 -}; -/* An 16-by-16 matrix in Scale = 2.56f */ -const Word16 SVNB_SN1_fx[256] = -{ - 135, 109, 135, -153, -549, 214, 416, 195, 291, 247, 100, -127, -579, -160, -66, -32, - -107, -150, -274, -149, 642, 594, 338, 183, 81, -31, -14, -150, -387, -40, -44, -18, - 73, 42, 171, 339, 213, 42, -137, -277, -379, -441, -440, -478, 270, 126, -4, 6, - -307, -479, -636, -596, -100, 83, 167, 200, 260, 376, 523, 1051, 1142, 490, 249, 108, - -148, -215, -324, -570, -917, -685, -208, 127, 285, 353, 441, 940, 1100, 458, 229, 100, - 427, 432, 548, 426, 133, 13, -9, -141, -108, -144, -195, -419, -733, -144, -109, -45, - -115, -220, -194, 661, 896, 688, 489, 351, 211, 258, 147, 30, -746, -784, -156, -95, - 16, -48, -88, -430, -798, 36, 204, 68, 174, 162, 20, 61, 627, 266, 102, 48, - -252, -370, -630, -614, 680, 1024, 869, 598, 419, 259, 193, 27, 90, 156, 53, 27, - -48, 33, 26, -227, -556, -766, -391, 231, 413, 282, 226, 89, 194, 187, 44, 30, - -204, -291, -345, -131, 125, 72, 16, -29, -106, -49, -27, 183, 714, 277, 114, 49, - -11, 205, 285, 69, -58, -207, -301, -160, -30, -2, 12, -99, -580, -178, -80, -41, - 120, 189, 281, 427, 234, 138, 124, 126, 50, 205, 121, 76, -797, -1204, -235, -133, - 63, -18, 146, 666, 480, 236, 134, -39, -97, -130, -175, -378, -746, -159, -106, -46, - 386, 399, 415, 157, -175, -282, -315, -318, -222, -225, -267, -342, 317, 152, 15, 14, - 39, 56, 71, -95, -387, -509, -595, -466, -395, -186, -24, 421, 814, 292, 127, 52 -}; -/* An 16-by-16 matrix in Scale = 2.56f */ -const Word16 SVNB_SN2_fx[256] = -{ - -16, 111, 111, -89, -115, -404, -514, 162, 277, 41, -94, -89, 15, 31, 2, 2, - -82, -99, -25, -287, -464, 204, 18, -123, -38, 56, 109, 198, 160, 96, 41, 19, - -95, -62, -242, -415, 318, 118, -121, 44, 74, 40, 85, 114, 52, 36, 21, 8, - 29, 40, 43, 23, -202, -149, 288, 149, -20, -109, -186, -275, -127, 18, -25, -6, - 20, 36, -97, -228, 565, 508, 134, 42, -70, -237, -258, -259, -123, -9, -29, -10, - -72, -169, 492, 463, 193, 204, -13, -75, -82, -125, -181, -230, -181, -10, -40, -12, - -108, -221, -229, 648, 575, 288, 146, 1, -14, -4, -51, -120, -81, -14, -17, -5, - -199, -264, -309, 209, 8, -128, 24, -47, 87, 257, 240, 185, 93, 70, 34, 16, - 25, 82, -60, -155, -407, -615, 29, 100, -113, 32, 207, 258, 203, 111, 49, 21, - 37, 127, 95, 4, 112, -45, -217, -158, -277, -407, -304, -152, 72, 52, -6, 0, - -30, -81, -116, -416, -219, 677, 538, 328, 213, 60, -60, -109, -78, 0, -5, 0, - 9, -15, 26, 75, -175, -336, -673, -586, 238, 310, 198, 189, 212, 126, 48, 24, - -18, -4, -80, 102, 130, -116, -268, -471, -567, -104, 205, 221, 143, 81, 29, 12, - 4, 39, 65, 115, 88, 189, 136, 124, 49, 106, 37, 89, -375, -626, -114, -73, - 540, 525, 472, 221, 118, -31, 15, 7, -71, -139, -108, -93, -13, -4, -13, -8, - -44, -44, -143, -272, -525, -365, 479, 502, 312, 225, 161, 72, 28, 42, 26, 12 -}; -/* An 16-by-16 matrix in Scale = 2.56f */ -const Word16 SVWB_SN1_fx[256] = -{ - -71, -61, -170, -563, -962, -845, 186, 421, 282, 344, 260, 155, 186, 52, -18, -11, - -107, -139, -289, -270, 788, 615, 249, 174, -1, -24, 159, 106, -46, -183, -187, -107, - -144, -221, -215, 359, 192, -34, -186, -326, -256, -124, -49, 84, 214, 237, 186, 91, - 218, 332, 335, 41, -191, -394, -614, -543, -415, -379, -285, -153, -86, -101, -69, -13, - 587, 616, 732, 419, 270, 252, 102, 40, 53, -35, -57, -34, 19, -14, -15, -120, - -76, -222, -127, 1216, 1188, 815, 532, 320, 311, 228, 34, -59, -96, -86, -44, -38, - -176, -282, -507, -455, 1122, 1359, 965, 742, 610, 448, 474, 412, 185, 127, 127, -24, - -156, -225, 16, 458, 423, 438, 393, 400, 525, 658, 682, 681, 612, 438, 267, 68, - 89, 120, 172, 355, 195, -8, -22, -67, -110, -40, -93, -163, -382, -685, -926, -468, - -227, -362, -452, -577, -213, -22, 56, 82, 132, 216, 348, 420, 358, 299, 257, 143, - 38, -77, 117, 856, 486, 282, 16, -154, -130, -315, -618, -783, -892, -545, -88, 59, - 218, 324, 232, -162, -583, -552, 126, 62, -40, -27, -227, -348, -334, -324, -238, -65, - 82, 16, -20, -539, -787, 604, 340, 259, 260, -53, -251, -211, -12, 127, 171, 99, - -24, 168, 202, -142, -223, -448, -282, 122, 148, 155, 363, 380, 347, 263, 124, -68, - 165, 150, 226, 95, -172, -257, -413, -510, -533, -734, -1014, -1206, -834, -162, 6, 97, - -78, -72, -81, -322, -605, -731, -740, -564, -356, -219, -151, 11, 200, 237, 212, 170 -}; -/* An 16-by-16 matrix in Scale = 2.56f */ -const Word16 SVWB_SN2_fx[256] = -{ - -126, -152, -342, -423, 311, 95, 3, 29, -93, 4, 227, 193, 142, 120, 93, 62, - 190, 258, 382, 310, 166, -11, -77, -67, -217, -327, -330, -378, -461, -309, -142, -47, - -16, -58, -77, -339, -534, 469, 399, 237, 290, 135, 34, 86, -14, -77, -30, 10, - 13, -4, 644, 572, 412, 438, 272, 286, 234, 177, 118, 147, 131, 138, 127, 38, - -73, -88, -112, 42, 36, 141, 424, 386, 504, 576, 523, 483, 431, 328, 233, 59, - -120, -169, -270, -445, -593, -268, -133, -138, -11, 56, 133, 210, 166, 116, 122, 137, - 282, 370, 255, 76, -89, -191, 139, 80, 12, 176, 185, 145, 244, 253, 173, -18, - 13, 14, -43, 73, -59, -270, -448, -622, -59, 374, 353, 293, 189, -54, -199, -122, - -75, -106, -281, -312, 585, 405, 185, 62, -176, -319, -330, -400, -418, -162, -4, 78, - -31, -11, -79, -83, -88, -274, -343, -431, -623, -518, -148, -11, -17, -21, 21, 90, - -101, -173, -240, 444, 303, 121, 104, -37, 185, 134, -45, -136, -164, 4, 153, 114, - -8, 40, 107, -76, -254, -551, -673, 288, 318, 25, 14, -62, -97, -2, 13, -20, - 87, 127, 80, 216, 336, 147, 188, 165, -10, 125, 193, 87, -126, -396, -736, -669, - 2, 4, 96, 185, 6, 62, -37, -136, -177, -250, -227, 201, 744, 651, 351, 74, - -16, -39, -82, -177, -380, -183, -24, -109, -194, -407, -641, -615, -157, 146, 191, 167, - -21, -12, -39, -63, -159, -128, 20, 6, 16, 39, -60, -243, -594, -733, -364, 46 -}; - -/* An 16-by-32 matrix in Scale = 2.56f */ -const Word16 GEWB_MA1_fx[512] = -{ - 269, 268, 416, 287, 157, 7, -132, -276, -482, -701, -1025, -1350, -1642, -982, -321, -49, - 237, 949, 1374, 1228, 1337, 1219, 1123, 1016, 852, 752, 664, 559, 448, 306, 194, 83, - -6, -176, -373, -111, -221, -387, -483, -639, -753, -786, -774, -655, -328, -114, -25, 27, - 135, 164, -4, -181, -364, -528, -464, -424, -393, -314, -242, -185, -104, -61, -32, -37, - 15, -218, -322, 668, 597, 343, 196, -5, -46, -159, -359, -524, -629, -548, -308, -95, - 242, 463, 767, 661, 558, 403, 268, 191, 71, -4, -51, -103, -141, -176, -161, -142, - -179, -147, 715, 865, 970, 932, 822, 763, 602, 514, 436, 370, 285, 189, 106, 36, - -49, -227, -589, -933, -1172, -700, -248, -175, -132, -132, -125, -103, -47, -49, -12, 60, - -7, -227, -404, 272, 83, -50, -165, -319, -343, -501, -731, -939, -1013, -607, -202, -2, - -76, -271, -661, -582, 296, 86, -60, -166, -335, -314, -213, -285, -324, -280, -164, -39, - -264, -452, -111, 171, 229, 357, 355, 461, 509, 517, 489, 441, 347, 246, 158, 75, - 67, -49, -340, -546, -758, -919, -876, -727, -658, -567, -492, -400, -234, -140, -63, 36, - -142, 94, 514, 400, 406, 389, 379, 413, 391, 377, 354, 314, 245, 156, 94, 34, - 97, -47, -316, -620, -874, -179, -206, -290, -304, -514, -690, -723, -503, -252, -73, 39, - 485, 674, 532, 195, 38, -60, 17, 52, 63, 74, 85, 62, 35, -10, -22, -51, - -105, -23, 287, 394, 469, 609, 706, 860, 933, 933, 874, 789, 638, 465, 297, 148, - -223, -499, -837, -813, -391, -231, -178, -182, -81, 2, 84, 113, 131, 142, 127, 107, - -64, 269, 879, 849, 1013, 1157, 1250, 1337, 1263, 1176, 1048, 900, 703, 502, 318, 165, - 61, 1, -198, -209, -345, -417, -280, -280, -307, -272, -341, -418, -604, -738, -887, -394, - 45, 77, 124, 152, 99, 43, 20, -4, -91, -85, -192, -280, -544, -754, -1176, -1296, - 173, 69, -49, -226, -344, -479, -489, -618, -727, -909, -1122, -1446, -1292, -492, -205, 10, - -80, -80, 338, 285, 123, 48, -76, -80, -105, -118, -108, -80, -58, -28, -9, -8, - 74, -79, -292, -618, -756, 345, 216, 180, 143, -73, -186, -223, -200, -143, -52, -21, - -253, -519, -578, -188, -96, -35, -7, 27, 133, 218, 258, 258, 231, 180, 120, 70, - 273, 740, 950, 736, 701, 635, 611, 602, 566, 533, 494, 447, 350, 230, 131, 42, - -100, -345, -702, -352, 709, 682, 485, 324, 161, 112, 148, 25, -88, -106, -86, -101, - 307, 265, 253, 65, -63, -75, -169, -282, -390, -501, -550, -532, -406, -296, -186, -132, - -26, 70, 50, -84, -89, 28, 106, 199, 305, 391, 450, 469, 419, 301, 191, 80, - 22, 39, -154, -426, -597, -497, -159, -69, 41, 95, 114, 114, 99, 33, -7, -40, - -162, -356, -511, -461, -475, -513, -477, -485, -395, -249, -136, -71, -4, 33, 54, 64, - -82, -295, -562, 241, 65, -163, -227, -384, -237, -229, -266, -223, -94, 10, 41, 31, - -104, -323, -302, 733, 646, 418, 271, 149, 155, 154, 119, 99, 89, 63, 13, -16 -}; -/* An 16-by-32 matrix in Scale = 2.56f */ -const Word16 GETRNB_SN1_fx[512] = -{ - -119, -271, -427, 447, 321, 58, 37, -105, -65, 99, 106, 21, -277, 53, 9, -6, - -93, -241, -433, -826, -1028, 17, 180, 138, 320, 234, 152, 235, 973, 594, 199, 96, - -300, -474, -553, -497, -374, -231, -224, -170, -145, 51, 154, 714, 1338, 690, 271, 118, - -115, -228, -248, 9, -27, -196, -240, -269, -293, -310, -276, -254, 769, 481, 117, 59, - 172, 58, 469, 585, 512, 336, 145, -52, -167, -344, -379, -487, 285, 377, 27, 27, - 81, 34, 574, 859, 818, 702, 521, 344, 177, 23, -116, -274, -611, -78, -61, -35, - 76, 19, -104, -388, -687, 54, 279, 144, 237, 223, 110, 9, -335, 4, 3, -10, - 115, 380, 486, 446, 389, 316, 239, 249, 197, 207, 162, 141, -435, -1516, -409, -136, - -146, -348, -425, 645, 998, 790, 609, 468, 282, 287, 153, 87, -461, -592, -88, -64, - -249, -471, -835, -642, 589, 960, 887, 637, 442, 286, 242, 132, 142, 299, 99, 44, - 128, 37, -120, -314, -571, -730, -868, -558, -259, -109, 8, 413, 1145, 593, 210, 92, - 151, 331, 267, 130, -24, -89, -133, -43, -75, 57, 19, 94, -469, -796, -124, -90, - -339, -468, -292, -34, 76, 179, 231, 269, 259, 281, 275, 204, -93, 157, 53, 16, - 33, 176, 25, -201, -311, -497, -509, -242, -47, 6, 86, 48, -165, 176, 24, 8, - 27, 223, 461, 500, 479, 475, 489, 560, 635, 741, 924, 1347, 1546, 806, 277, 54, - 510, 464, 402, 114, -80, -285, -290, -321, -283, -368, -325, -424, 388, 402, 52, 38, - 521, 614, 732, 549, 428, 278, 180, 81, 14, -110, -204, -355, -649, -32, -56, -36, - 72, 26, 262, 263, 159, 113, 60, -10, -73, -121, -201, -329, -768, -61, -60, -39, - 85, 57, 116, -40, -78, -159, -154, -247, -220, -366, -331, -532, -35, 344, 0, 25, - 527, 919, 1339, 1225, 1190, 1023, 774, 577, 393, 160, -4, -184, -281, 29, -21, -12, - -230, -283, -338, -379, -313, -293, -163, -122, 15, 97, 243, 168, 361, 449, 102, 61, - 378, 369, 369, 136, 42, -72, -73, -154, -155, -260, -270, -444, -562, 173, -36, -9, - 168, 108, -36, -347, -559, -436, -254, -263, -236, -227, -247, -238, 796, 488, 123, 62, - -151, -118, 163, 452, 430, 484, 456, 418, 377, 363, 256, 183, -403, -1429, -382, -126, - -204, -366, -652, -512, 428, 353, 182, 88, -10, -94, -54, -11, 801, 527, 151, 76, - 60, 79, -169, -465, -789, -844, -55, 181, 209, 172, 210, 107, 260, 399, 91, 52, - -69, -205, -377, -164, 647, 584, 302, 151, 32, -135, -136, -223, -269, 170, 4, 5, - 38, 418, 885, 979, 990, 1027, 870, 804, 669, 537, 360, 241, -336, -1281, -338, -111, - -420, -700, -912, -622, -337, -51, 67, 173, 326, 554, 766, 1395, 1656, 894, 390, 178, - -141, -252, -507, -822, -1084, -845, -280, 20, 149, 242, 393, 951, 1428, 740, 303, 135, - -120, -37, 31, 105, 72, 99, 53, 117, 59, 171, 120, 177, -414, -993, -160, -98, - -382, -612, -631, -167, 4, 104, 130, 141, 242, 325, 348, 430, 1048, 651, 222, 109 -}; -/* An 16-by-16 matrix in Scale = 2.56f */ -const Word16 GETRNB_SN2_fx[256] = -{ - -27, 71, 45, -4, 28, 69, 25, 94, 45, 90, 45, 87, -177, -567, -116, -59, - -208, -147, 531, 399, 199, 113, -21, -28, -34, -38, -48, -46, -47, 18, -1, -1, - 69, -20, -115, -355, -380, 388, 379, 193, 134, 37, -42, -60, -35, 29, 6, 5, - 107, 89, -98, -189, 379, 289, 68, 22, -71, -179, -187, -192, -137, 4, -17, -7, - -44, -81, -371, -448, 226, 75, -52, 43, 40, 36, 79, 120, 130, 76, 36, 15, - 131, 115, 192, 177, 25, -7, -23, -95, -132, -184, -206, -245, -200, -12, -29, -11, - 45, -25, -249, 50, -189, -358, 253, 145, -39, 27, 34, -20, -52, 13, 1, 2, - -254, -155, 23, -89, -30, 23, -23, -21, -45, -86, -92, -109, -48, 52, 3, 3, - -248, -233, 139, 213, 232, 361, 349, 401, 373, 301, 230, 207, 204, 101, 32, 14, - 491, 546, 409, 147, 34, -18, 52, 59, 48, 27, 14, 7, -1, -37, -16, -9, - 36, 41, 0, -21, -29, -64, -207, -346, -516, -355, -64, 73, 156, 94, 30, 11, - -28, -173, -278, 506, 427, 164, 111, 21, -33, -61, -78, -90, -32, 39, 4, 4, - -44, -60, -215, -373, -485, -270, 12, 151, 271, 265, 215, 178, 153, 71, 32, 17, - 110, 155, -29, -259, -218, -183, -175, -132, -85, -98, -87, -93, -77, 0, -9, -4, - -116, -14, 235, 1, -238, -398, -419, -55, 109, 77, 62, 74, 73, 47, 16, 8, - -20, -108, -219, 246, 20, -184, -328, -449, -67, 142, 125, 110, 91, 74, 28, 13 -}; -/* An 16-by-32 matrix in Scale = 2.56f */ -const Word16 GETRWB_SN1_fx[512] = -{ - -232, -191, 282, 248, 344, 390, 428, 490, 538, 592, 620, 607, 533, 372, 261, 136, - -59, -227, -418, -288, -247, -448, -501, -644, -760, -922, -1112, -1204, -523, -130, 12, 131, - 139, 838, 1402, 1327, 1465, 1391, 1371, 1342, 1220, 1147, 1041, 910, 733, 518, 335, 181, - 211, 148, -94, -275, -484, -586, -541, -634, -583, -511, -424, -322, -285, -299, -194, -87, - 410, 362, 337, 73, -36, -113, -180, -274, -373, -493, -501, -473, -393, -361, -271, -251, - -85, -366, -819, -532, 753, 688, 414, 203, 24, -43, 129, 60, -100, -123, -97, -114, - 4, 37, 484, 514, 340, 225, 89, 59, 40, 3, -5, -1, -11, -49, -43, -48, - -223, -471, -661, -567, -496, -519, -464, -542, -484, -343, -276, -185, -43, 17, 84, 133, - -106, -312, -668, -741, 385, 329, 121, -157, -423, -710, -957, -1280, -1143, -330, -20, 131, - 250, 157, 71, -310, -552, -740, -745, -778, -827, -1064, -1336, -1629, -788, -195, -44, 131, - 140, 633, 970, 864, 867, 761, 683, 648, 572, 544, 516, 469, 383, 238, 143, 55, - 116, 143, 229, 134, -25, -120, -232, -333, -535, -642, -985, -1259, -1873, -1727, -330, -10, - -64, -82, -62, -232, -308, -346, -296, -272, -153, -26, 108, 205, 232, 158, 129, 53, - 82, -92, -309, -791, -1128, -259, -243, -405, -367, -637, -903, -1084, -675, -199, 17, 146, - -247, -569, -886, -758, -334, -206, -158, -150, -64, 57, 190, 252, 261, 210, 163, 129, - -23, -319, -458, 791, 718, 400, 233, -81, -174, -400, -758, -1048, -1338, -1038, -288, -6, - 50, 462, 303, -47, -122, -134, 15, 137, 179, 222, 266, 249, 219, 123, 80, 30, - -116, -332, -650, -1104, -1367, -691, -376, -295, -178, -199, -170, -24, 125, 95, 125, 168, - -66, -314, -526, 325, 156, -56, -114, -287, -126, -185, -292, -298, -189, -81, 1, 23, - 147, -30, -291, -771, -939, 262, 182, 126, 127, -100, -163, -134, -91, -95, -52, -19, - -225, -496, -449, -61, 46, 135, 182, 247, 324, 404, 457, 464, 420, 305, 209, 106, - 418, 312, 415, 74, -156, -345, -400, -634, -769, -1057, -1362, -1841, -1848, -471, -147, 87, - 38, 19, -232, -552, -698, -941, -483, 119, 54, -34, 70, -68, -144, -192, -253, -236, - 80, -30, -214, -157, -292, -312, -283, -347, -384, -372, -487, -503, -746, -950, -1372, -644, - 44, 55, 124, 181, 125, 109, 61, 29, -73, -54, -206, -278, -638, -929, -1563, -1742, - 802, 823, 726, 353, 272, 122, 117, 94, 80, 40, 68, 47, 42, -19, -26, -69, - 50, -97, -306, -666, -918, -1109, -1124, -776, -710, -728, -675, -486, -150, -3, 93, 160, - 81, -144, -131, 319, 227, -96, -236, -517, -711, -949, -1231, -1644, -1625, -444, -117, 86, - -230, -237, 586, 799, 931, 1023, 1077, 1179, 1133, 1101, 1027, 909, 731, 515, 330, 171, - 448, 632, 1047, 782, 631, 390, 155, -82, -342, -685, -1103, -1520, -1779, -931, -214, 34, - -77, -352, -353, 787, 938, 677, 513, 352, 284, 278, 247, 181, 141, 73, 8, -39, - 54, 42, -67, -298, -465, -593, -533, -547, -626, -741, -977, -1317, -1665, -613, -119, 80 -}; -/* An 16-by-16 matrix in Scale = 2.56f */ -const Word16 GETRWB_SN2_fx[256] = -{ - -202, -246, -356, -356, -232, -164, -79, 4, 78, 130, 152, 165, 170, 141, 90, 70, - 38, 78, -72, -185, -446, -552, 269, 295, 104, 77, -54, -184, -168, -72, -32, -2, - 69, 93, 39, 116, 100, 46, 50, -1, -2, 62, 8, -105, -404, -656, -494, -224, - -285, -305, 263, 97, 29, 33, -24, 54, 35, 25, -4, -6, -30, 13, 20, 21, - -28, -70, -160, 34, 5, -145, -264, -425, -539, -329, -19, 228, 411, 280, 141, 51, - 244, 245, 19, -319, -461, -184, -10, 47, 220, 293, 309, 330, 281, 140, 71, 12, - -128, -251, -374, 424, 279, 68, 35, -68, 13, 45, -6, -41, -73, -17, 8, 27, - -55, -7, 438, 500, 493, 442, 286, 211, 68, -39, -117, -167, -180, -131, -75, -63, - 30, 31, 69, 114, -172, -407, -596, -391, 102, 169, 158, 131, 46, 4, -6, -3, - 69, 76, 33, 238, 164, 119, 160, 165, 273, 342, 383, 419, 456, 378, 262, 96, - -55, 43, -59, -273, -200, -286, -287, -221, -247, -245, -194, -160, -129, -36, -31, 3, - -35, -46, -272, -357, 484, 246, -11, 21, -123, -197, -102, -94, -96, -22, 6, 6, - -117, -188, -252, -227, 0, 460, 506, 526, 501, 389, 250, 131, -28, -32, 24, 17, - 399, 511, 390, 146, 80, -84, -81, -57, -123, -138, -95, -82, -51, -33, -14, -45, - -9, 12, 300, 304, 182, 27, -197, -258, -344, -393, -384, -318, -140, -5, -6, 6, - 64, 25, -7, -256, -306, 381, 243, 96, -17, -190, -285, -246, -65, 48, 37, 29 -}; -/* An 16-by-16 matrix in Scale = 2.56f */ -const Word16 TRWB2_SN1_fx[256] = -{ - -74, -384, -764, -964, -1122, -912, -819, -740, -728, -572, -379, -317, -250, -51, -67, 85, - -311, -618, -439, -108, 156, 257, 404, 543, 643, 729, 732, 572, 446, 329, 236, 164, - 523, 1549, 1557, 1476, 1374, 1192, 1068, 923, 901, 788, 717, 401, 262, 6, -100, -368, - -13, -80, -189, -386, -486, -357, -216, -63, 65, 189, 248, 194, 218, 219, 205, 169, - -104, -519, -772, 492, 224, 18, -203, -244, -126, -220, -362, -417, -271, -71, -34, -50, - -202, 124, 811, 975, 1326, 1468, 1613, 1527, 1474, 1366, 1220, 906, 700, 509, 351, 207, - -57, -196, -238, -281, -267, -239, -190, -137, -27, 4, 77, -178, -256, -553, -669, -1105, - -183, -211, 804, 789, 685, 529, 479, 403, 371, 313, 279, 49, -19, -156, -179, -335, - 758, 848, 608, 313, 271, 176, 177, 73, 106, 61, 59, -159, -203, -287, -268, -343, - 199, 70, 95, -29, -245, -411, -745, -1009, -1473, -1921, -2633, -1648, -537, -284, -87, 207, - 82, -217, -460, -646, -718, -821, -983, -1282, -1580, -2108, -1863, -609, -407, -122, -50, 243, - -132, 364, 364, 340, 489, 496, 596, 606, 704, 756, 777, 616, 521, 409, 305, 211, - 123, -189, -91, -306, -319, -407, -600, -679, -911, -855, -566, -249, -65, -1, -65, -25, - 79, -58, -103, -150, -268, -265, -426, -479, -614, -671, -1005, -1378, -2027, -1547, -568, -52, - -275, -669, -1070, -1097, -688, -433, -340, -148, -27, 194, 309, 277, 229, 188, 82, 127, - 397, 1343, 1482, 1729, 1978, 2012, 1969, 1852, 1729, 1574, 1407, 1087, 848, 636, 431, 278 -}; -/* An 16-by-16 matrix in Scale = 2.56f */ -const Word16 TRWB2_SN2_fx[256] = -{ - 50, -66, -486, -850, 504, 345, 261, 10, -207, -218, -174, -18, 72, 69, 3, 24, - -171, -439, -632, 390, 143, -89, -292, -314, -227, -157, 33, 181, 185, 204, 128, 167, - 458, 459, 78, -250, -365, -381, -353, -382, -327, -284, -191, -18, 3, 37, 29, 95, - -169, -227, -423, -448, -485, -426, -364, -284, -238, -184, -228, -190, -145, 17, 65, 145, - -4, -120, -170, -333, -677, -782, -719, -391, -112, 232, 464, 392, 275, 215, 121, 139, - -94, -130, 453, 295, -45, -286, -444, -473, -519, -428, -268, -40, -12, 46, 39, 118, - -189, -245, 805, 815, 518, 293, 162, 110, -67, -158, -223, -120, -36, 15, 26, 60, - 23, 130, 107, 0, -31, -66, 33, 22, 101, -10, -32, -232, -281, -590, -672, -1089, - 51, 106, 157, 132, 40, 11, -73, -66, -165, -294, -561, -770, -742, -489, -202, 4, - 25, 230, 286, 179, 75, 18, 15, 24, 109, 187, 310, 334, 328, 291, 237, 212, - -238, -492, -550, 563, 764, 610, 542, 427, 373, 261, 166, 171, 122, 34, -21, -92, - -359, -462, -10, 22, -42, -2, 78, 167, 154, 155, 74, 73, 66, 94, 89, 126, - -5, -110, -374, -546, -386, -136, 95, 305, 437, 570, 615, 558, 463, 335, 209, 151, - 23, 376, 292, 235, 485, 519, 657, 549, 478, 338, 186, 7, -28, -155, -95, -188, - 166, 139, -277, -716, -822, 234, 319, 326, 234, 36, -155, -317, -247, -80, 49, 117, - 431, 853, 745, 512, 325, 139, 83, -31, -25, -47, -17, -12, -24, -43, -5, 13 -}; -/* An 16-by-32 matrix in Scale = 2.56f */ -const Word16 GEWB2_MA1_fx[512] = -{ - 659, 1694, 1634, 1513, 1305, 1098, 933, 805, 733, 624, 525, 339, 239, 50, -35, -215, - 6, 65, 125, 55, -85, -126, -272, -316, -507, -586, -1010, -1278, -1941, -1910, -426, 78, - 281, 315, 236, -4, -102, -171, -232, -335, -362, -425, -488, -603, -669, -736, -648, -593, - 29, -251, -582, -871, -969, -897, -991, -1077, -1275, -1480, -998, -393, -247, -9, 28, 271, - -60, -361, 401, 552, 236, 35, -196, -215, -496, -683, -911, -820, -576, -299, -240, -141, - 416, 574, 662, 350, 133, -160, -431, -781, -1200, -1652, -2035, -1092, -449, -192, -11, 263, - -206, -609, -931, 28, -229, -358, -543, -462, -377, -360, -336, -251, -105, 35, 26, 80, - 369, 1256, 1380, 1571, 1726, 1727, 1644, 1521, 1350, 1156, 984, 748, 580, 395, 254, 108, - -147, -479, -330, -73, -272, -441, -685, -837, -1139, -1458, -1370, -414, -208, -12, 14, 213, - -50, 100, -82, -253, -7, 119, 294, 392, 494, 578, 589, 523, 462, 383, 300, 249, - -94, -362, -575, -770, -987, -999, -922, -697, -582, -305, -135, -31, -8, 23, -33, 62, - 29, -64, -4, -123, -344, -414, -679, -767, -1152, -1401, -2105, -1905, -582, -300, -64, 223, - 428, 990, 1019, 809, 681, 470, 366, 179, 126, -26, -141, -363, -423, -536, -437, -545, - -133, -357, 364, 241, -39, -227, -334, -305, -426, -292, -102, 87, 159, 182, 160, 190, - 560, 764, 531, 156, 22, -18, 23, -20, 19, 0, 13, -61, -35, -44, -12, -48, - 33, -235, -634, -1093, 136, -31, -68, -285, -529, -535, -462, -249, -95, -53, -116, -61, - -188, -628, -894, 702, 700, 373, 196, 51, 95, -56, -191, -181, -173, -132, -116, -218, - 37, -188, -661, -1087, -1322, -258, -186, -181, -238, -372, -418, -508, -433, -197, -73, 28, - -231, -222, 911, 875, 669, 440, 363, 301, 257, 192, 147, 68, 77, 43, 57, 17, - -4, -187, -356, -410, -569, -499, -584, -568, -660, -703, -965, -1201, -1540, -708, -252, 87, - 220, 64, -67, -357, -572, -744, -913, -1176, -1439, -1894, -2152, -762, -419, -146, -10, 281, - -253, -627, -1075, -1206, -721, -398, -337, -188, -118, 50, 125, 198, 200, 190, 96, 164, - -348, -741, -854, -357, -163, -103, -26, 143, 231, 318, 335, 325, 274, 233, 167, 190, - -143, -256, -191, -280, -250, -191, -82, 37, 126, 102, 67, -130, -202, -430, -495, -810, - 232, 107, -22, -341, -497, -523, -607, -646, -746, -690, -478, -295, -160, -77, -53, -7, - -33, -98, -258, -501, -589, -438, -316, -168, -58, 82, 175, 219, 249, 259, 237, 226, - -393, -665, -19, 185, 249, 266, 378, 468, 499, 508, 464, 388, 310, 238, 186, 145, - -240, -99, 408, 480, 693, 761, 946, 943, 951, 893, 782, 613, 482, 351, 260, 163, - -23, 523, 885, 903, 1172, 1287, 1482, 1491, 1476, 1402, 1240, 1005, 787, 604, 433, 292, - 262, 988, 904, 732, 734, 665, 715, 656, 673, 615, 541, 372, 284, 139, 68, -84, - -119, 446, 1118, 1215, 1372, 1280, 1208, 989, 881, 675, 557, 319, 227, 23, -39, -256, - -102, 178, 379, 252, 365, 319, 455, 377, 413, 278, 225, -36, -67, -351, -375, -772 -}; -/* An 16-by-16 matrix in Scale = 2.56f */ -const Word16 AUNB_SN1_fx[256] = -{ - -180, -79, -51, 39, 66, 99, 48, 108, 56, 127, 34, 46, -470, -845, -141, -90, - -212, 82, 284, 422, 416, 416, 313, 289, 233, 210, 108, 55, -439, -1323, -336, -123, - -9, 405, 532, 659, 710, 798, 844, 971, 1072, 1181, 1464, 1913, 2028, 1232, 549, 265, - 75, 49, 330, 493, 448, 329, 204, 67, -18, -134, -235, -400, -605, -30, -67, -36, - -9, -7, -95, -222, -322, -421, -321, -233, -110, -86, 67, -19, 3, 345, 41, 30, - 153, 34, -172, -386, -500, -548, -503, -420, -317, -207, -114, 183, 1096, 661, 198, 94, - 616, 501, 471, 220, 157, 55, 4, -161, -178, -314, -267, -389, 216, 429, 46, 38, - -559, -854, -789, -369, -153, 64, 146, 296, 388, 520, 574, 958, 1481, 898, 340, 164, - 131, 137, 116, 57, 64, -21, -38, -112, -123, -199, -214, -379, -641, 83, -53, -21, - -101, -324, -648, -801, -835, -737, -501, -296, -86, 144, 400, 1025, 1501, 861, 322, 151, - -231, -397, -512, -506, -308, -200, -127, -91, -18, 17, 94, 114, 798, 625, 161, 88, - -518, -617, -201, 103, 258, 279, 273, 267, 281, 251, 214, 114, 58, 270, 70, 31, - 17, -86, -78, -82, -22, -73, -171, -299, -334, -431, -422, -526, 517, 511, 71, 53, - 276, 182, -40, -336, -461, -93, 342, 267, 166, 18, -43, -196, -146, 236, 18, 14, - 227, 338, 224, 188, 107, 80, 57, 92, 34, 80, -5, -4, -515, -927, -174, -100, - 731, 744, 797, 675, 590, 438, 328, 215, 144, 24, -96, -239, -486, -175, -65, -41 -}; -/* An 16-by-16 matrix in Scale = 2.56f */ -const Word16 AUWB_SN1_fx[256] = -{ - 328, 137, 358, 330, 184, 145, -60, -294, -555, -784, -945, -872, -601, -337, -155, -33, - 32, -212, -488, -651, -752, -877, -892, -886, -853, -795, -705, -549, -330, -224, -127, -9, - 372, 327, 197, 33, 13, -55, -87, -124, -125, -148, -144, -168, -175, -184, -127, -125, - 752, 727, 623, 519, 449, 350, 309, 289, 272, 252, 185, 124, 118, 35, 22, -20, - 14, 144, 296, 432, 416, 325, 177, 166, 151, 123, 109, 104, 47, -22, -45, -49, - 310, 112, -141, -529, -654, -53, 162, -33, -297, -551, -772, -817, -540, -287, -95, -7, - -158, 241, 443, 543, 559, 579, 566, 606, 610, 622, 602, 578, 485, 331, 197, 104, - -471, -530, 37, 272, 397, 442, 466, 523, 561, 592, 608, 576, 485, 348, 222, 133, - 162, 0, -87, -85, -151, -331, -410, -603, -767, -1030, -1348, -1812, -1735, -678, -284, -6, - -156, 36, 15, 26, 41, 118, 201, 265, 339, 382, 420, 435, 377, 264, 159, 84, - -69, -274, -411, -158, 60, -56, -190, -305, -371, -389, -411, -407, -338, -276, -173, -99, - 0, -26, -196, -379, -369, -327, -193, -148, -77, -10, 63, 98, 98, 49, 40, -5, - -149, -432, -729, -923, -927, -766, -568, -455, -333, -219, -122, -29, 11, 9, 20, 54, - 177, 64, -60, -232, -411, -552, -557, -550, -509, -464, -380, -331, -297, -288, -215, -170, - -16, 439, 971, 1104, 1209, 1323, 1339, 1374, 1317, 1223, 1107, 983, 781, 535, 315, 151, - -432, -727, -686, -340, -156, -40, 18, 102, 169, 257, 306, 335, 296, 213, 137, 97 -}; - -/* An 16-by-16 matrix in Scale = 2.56f */ -const Word16 AUWB2_SN1_fx[256] = -{ - -107, -446, -835, -1041, -1152, -1161, -1146, -969, -828, -533, -251, -242, -139, 172, 95, 466, - 1052, 1008, 1052, 875, 864, 748, 783, 690, 754, 715, 688, 342, 195, -32, -251, -509, - -311, -170, 366, 632, 748, 863, 983, 1042, 1118, 1188, 1133, 895, 728, 621, 460, 418, - 608, 525, 322, 30, -237, -483, -862, -1178, -1651, -2184, -2770, -1349, -430, -28, 128, 562, - 296, 171, -192, -429, -488, -470, -492, -473, -448, -352, -242, -309, -337, -210, -265, -182, - 831, 703, 456, 217, 165, 65, 17, -53, -67, -78, -38, -222, -340, -329, -349, -391, - 162, -13, -158, -335, -526, -705, -986, -1245, -1640, -2149, -2754, -1344, -372, -12, 134, 564, - -79, -389, -569, -699, -811, -940, -1058, -1299, -1534, -2077, -1953, -507, -216, 143, 191, 607, - -106, -116, -210, -225, -323, -330, -494, -491, -700, -757, -1057, -1424, -2222, -1509, -259, 348, - -366, -748, -1177, -1216, -1017, -698, -444, -154, 10, 285, 361, 284, 255, 359, 187, 365, - 77, 447, 418, 475, 453, 459, 475, 515, 562, 648, 658, 452, 367, 334, 244, 204, - 10, 197, 170, 166, 144, 60, 52, -2, -20, -40, 18, -238, -279, -434, -451, -807, - -460, -713, -547, -153, 64, 243, 386, 492, 620, 752, 759, 536, 445, 324, 151, -32, - -246, -396, -413, -371, -354, -317, -307, -228, -195, -101, -36, -174, -197, -162, -261, -349, - -329, -240, 326, 462, 428, 344, 405, 374, 439, 434, 467, 127, 85, -154, -248, -683, - -12, 15, -222, -227, -31, 124, 200, 294, 357, 541, 607, 459, 376, 352, 282, 283 -}; - -/* An 16-by-16 matrix */ -const short CNG_SN1_fx[256] = -{ - 600, 1640, 3039, 4257, 5512, 6740, 7989, 9169, 10393, 11612, 12880, 14100, 15378, 16554, 17816, 18918, - 1188, 2487, 3746, 4903, 6103, 7261, 8437, 9587, 10776, 11954, 13172, 14355, 15564, 16712, 17913, 19012, - 346, 799, 2259, 3555, 4876, 6175, 7516, 8803, 10073, 11323, 12631, 13938, 15282, 16553, 17817, 19039, - 439, 1616, 3446, 4743, 6073, 7288, 8553, 9726, 10947, 12106, 13312, 14474, 15650, 16773, 17894, 18977, - 921, 1800, 2976, 4007, 5105, 6137, 7178, 8150, 9057, 9914, 11009, 12545, 13671, 15502, 17428, 18927, - 896, 1899, 3035, 4128, 5301, 6429, 7604, 8719, 9886, 11059, 12417, 13621, 14962, 16135, 17475, 18460, - 722, 1507, 2537, 3437, 4328, 5190, 6018, 6841, 7587, 8343, 8925, 9511, 9919, 11075, 13613, 15021, - 315, 612, 1671, 2910, 3990, 5083, 6120, 7170, 8188, 9173, 10148, 11186, 12250, 13262, 14290, 15284, - 885, 1928, 3010, 3973, 4952, 5900, 6848, 7769, 8701, 9609, 10581, 11540, 12508, 13450, 14412, 15349, - 338, 1020, 2657, 3736, 4839, 5791, 6806, 7760, 8738, 9659, 10627, 11567, 12534, 13468, 14416, 15334, - 1126, 1964, 2999, 3855, 4764, 5608, 6482, 7286, 8109, 8827, 9570, 10649, 11999, 13125, 14223, 15252, - 385, 815, 2000, 2939, 3906, 4879, 5793, 6734, 7661, 8526, 9309, 10146, 11597, 12955, 14106, 15241, - 633, 1445, 2400, 3293, 4235, 5171, 6143, 7084, 8057, 8980, 9924, 10924, 11987, 12998, 14016, 15058, - 584, 1248, 2250, 3131, 4050, 4920, 5811, 6652, 7471, 8244, 8913, 9480, 10188, 12225, 13871, 15123, - 1157, 1820, 2745, 3505, 4354, 5097, 5932, 6648, 7408, 8034, 8635, 9083, 9977, 12228, 13819, 15108, - 572, 1401, 2514, 3501, 4503, 5465, 6469, 7435, 8416, 9328, 10306, 11309, 12328, 13303, 14306, 15261, -}; -/* An 16-by-32 matrix */ -const Word16 IAA_MA1_fx[512] = -{ - -175, -490, -520, -631, -645, -614, -610, -548, -503, -432, -353, -301, -238, -141, -67, 26, - 301, 407, 227, 96, -12, -18, -13, 2, 39, 107, 124, 92, 83, 100, 62, 72, - -280, -737, -569, -164, -9, 100, 141, 211, 252, 281, 274, 217, 206, 219, 117, 106, - -266, -753, -841, -587, -487, -345, -263, -167, -114, -30, 8, 32, 34, 61, 55, 104, - -91, -137, -293, -349, -352, -326, -268, -247, -178, -129, -56, -96, -11, 219, 49, 56, - -18, 1, -33, -14, -19, -5, -22, -14, -43, -37, -104, -143, -375, -770, -190, -100, - 72, -22, -121, -220, -320, -378, -500, -587, -729, -795, -1056, -1305, -1691, -1090, -452, -60, - 19, -279, -453, -580, -588, -739, -858, -1044, -1281, -1614, -921, -376, -273, -84, -2, 187, - 853, 759, 591, 376, 260, 122, 39, -71, -133, -184, -209, -297, -299, -171, -124, -83, - 266, 34, -182, -367, -516, -686, -881, -1121, -1414, -1834, -2110, -997, -519, -274, -109, 137, - -2, -8, 42, 91, 172, 211, 298, 336, 433, 409, 546, 1043, 1499, 1038, 410, 189, - 86, 254, 259, 254, 246, 219, 184, 122, 79, 11, -55, -170, -363, -934, -371, -188, - 168, 167, -122, -244, -325, -340, -359, -343, -331, -291, -278, -270, -272, -162, -101, -46, - -244, -459, -367, -340, -295, -220, -173, -107, -22, 53, 103, 293, 1084, 807, 260, 117, - -319, -650, -685, -427, -290, -105, 25, 161, 303, 418, 587, 1074, 1563, 1085, 400, 170, - 146, 257, 282, 295, 303, 294, 297, 262, 237, 193, 92, 341, 1220, 884, 315, 144, - -291, -558, 147, 201, 282, 280, 310, 302, 313, 306, 292, 239, 198, 188, 106, 94, - -11, -8, -156, -204, -231, -250, -265, -289, -269, -316, -322, -450, -488, -676, -778, -973, - -117, -27, 4, 96, 174, 229, 271, 310, 344, 362, 344, 273, 209, 180, 109, 106, - -260, -290, 151, 269, 406, 442, 551, 590, 679, 681, 900, 1293, 1631, 1132, 477, 221, - -37, 374, 394, 414, 419, 395, 345, 313, 282, 255, 211, 126, 84, 51, -10, -53, - 404, 327, 174, 28, -124, -290, -490, -695, -1011, -1111, -529, -288, -183, -69, -7, 142, - 563, 752, 585, 555, 512, 478, 424, 396, 376, 343, 300, 194, 193, 162, 78, 46, - -59, -131, -35, 49, 54, -12, -92, -185, -243, -289, -288, -344, -326, 0, -38, 6, - 496, 582, 564, 514, 521, 490, 486, 436, 432, 320, 456, 1060, 1523, 1058, 419, 194, - 174, 77, 18, -89, -112, -196, -165, -247, -222, -326, -332, -494, 499, 617, 121, 60, - 315, 299, 229, 137, 78, -3, -40, -138, -198, -307, -375, -502, -515, -25, -88, -49, - -232, -29, 353, 399, 485, 487, 523, 526, 556, 559, 520, 415, 328, 283, 187, 166, - 182, 385, 403, 453, 515, 572, 635, 691, 787, 852, 1154, 1483, 1779, 1231, 524, 246, - -273, -492, -185, -97, -52, -51, -17, -27, 13, 20, 45, -20, 52, 244, 58, 56, - 20, -3, -241, -267, -194, -86, 4, 75, 140, 191, 200, 154, 137, 146, 85, 77, - 92, 628, 611, 708, 706, 716, 672, 694, 655, 619, 550, 432, 354, 284, 204, 172 -}; -/* An 16-by-8 matrix in Scale = 2.56f */ -const Word16 GESVNB_AR1_fx[128] = -{ - -25, -64, -140, -118, 270, 240, 127, 70, 20, -40, -56, -111, -82, 64, 2, 5, - 81, 104, 71, 70, 0, -49, -54, -73, -59, -92, -102, -201, -404, -52, -40, -15, - -112, -217, -251, -202, -34, 57, 58, 62, 79, 127, 177, 306, 524, 315, 112, 53, - 17, -6, 34, 66, 14, -26, -174, -196, -142, -131, -102, -97, 180, 154, 29, 17, - 5, -27, -107, -197, -343, -333, -182, -143, -91, -17, 43, 120, 383, 267, 83, 40, - -1, -15, -35, -56, -169, -145, 86, 101, 77, 48, 29, 78, -9, 68, 15, 9, - 3, 9, 320, 450, 385, 348, 215, 155, 105, 45, -13, -75, -272, -129, -52, -23, - 4, 49, 54, 90, 92, 101, 59, 69, 20, 70, 23, 43, -280, -624, -114, -55 -}; -/* An 16-by-8 matrix in Scale = 2.56f */ -const Word16 GESVNB_AR2_fx[128] = -{ - -22, -35, -31, -166, -164, 217, 212, 155, 166, 123, 67, 33, -21, -41, -3, -1, - -14, -20, -16, -70, -77, -53, 23, -7, -98, -123, -99, -49, 357, 114, 36, 19, - -57, -119, -303, -215, -33, -103, -97, -117, -105, -102, -67, -134, -176, 113, 16, 8, - -12, 14, 30, -37, -112, -226, -206, -25, 125, 134, 99, 83, 55, -4, 9, 4, - -19, 23, 171, 57, 13, -15, -26, -42, -65, -69, -77, -169, -351, -105, -49, -21, - -14, -10, 8, 35, 161, 104, -74, -102, -135, -47, 45, 264, 52, -69, -1, -5, - 213, 284, 230, 121, 50, 12, 43, 48, 27, -7, -24, -39, 75, 1, -9, -3, - -75, -137, -89, 275, 164, 65, 125, 91, 86, 91, 56, 10, 9, -10, 0, 0 -}; -/* An 16-by-8 matrix in Scale = 2.56f */ -const Word16 GESVWB_AR1_fx[128] = -{ - -3, -16, -31, 2, -81, -123, -226, -260, -196, -122, -20, 78, 178, 145, 84, 46, - 55, 42, 15, 32, -48, -81, -109, -137, -187, -264, -330, -387, -363, -176, -38, 37, - -32, -70, -144, -269, -337, -183, 59, 58, 44, 49, 42, 51, 72, 50, 26, 38, - -18, -58, -79, 125, 352, 291, 180, 118, 72, 25, -23, -82, -185, -167, -33, 6, - -10, 135, 544, 517, 517, 561, 515, 528, 500, 472, 413, 383, 318, 219, 118, 57, - -54, -280, -614, -548, -521, -522, -448, -479, -457, -438, -377, -355, -318, -271, -222, -89, - -62, -96, -86, -10, 104, 155, 120, 112, 190, 264, 291, 272, 232, 166, 95, 27, - 33, 61, 155, 121, 9, -28, 6, 103, 64, 17, 4, -2, -31, -88, -209, -206 -}; -/* An 16-by-8 matrix in Scale = 2.56f */ -const Word16 GESVWB_AR2_fx[128] = -{ - -147, -326, -421, -91, -22, -25, -14, -21, 32, 76, 104, 102, 65, 47, 50, 41, - -39, -16, 61, -13, -38, -56, 47, 153, 195, 213, 212, 220, 245, 245, 209, 86, - -34, -73, 82, 387, 199, 71, 56, -18, -33, -56, -88, -79, -5, 59, 55, 29, - -7, -21, -21, -158, -123, 304, 226, 168, 124, 8, -75, -91, -54, -5, 37, 30, - -26, -22, -67, -225, 107, 38, -82, -113, -213, -205, -62, 28, 89, 95, 52, 17, - 227, 404, 325, 134, 45, -16, 3, -15, -55, -65, -55, -54, -18, -8, 1, -14, - 19, 30, 12, 28, 48, 13, 2, -47, -38, 41, 29, -8, -154, -315, -411, -242, - 8, 24, 29, -61, -215, -329, -237, -106, -12, -12, -64, -118, -167, -119, 8, 52 -}; - -/* An 16-by-32 matrix in Scale = 2.56f */ -const Word16 AUWB2_MA1_fx[512] = -{ - 391, 298, 179, -37, -225, -387, -627, -864, -1216, -1644, -2108, -804, -277, -5, 121, 468, - 351, 213, 141, -75, -130, -164, -332, -410, -524, -573, -575, -474, -331, -103, -22, 201, - 81, 874, 1137, 1223, 1242, 1262, 1238, 1185, 1141, 1085, 993, 733, 570, 424, 256, 145, - -6, -25, -105, -147, -327, -342, -587, -620, -954, -1143, -1878, -2059, -356, -100, 134, 477, - -197, -505, -826, -1043, -863, -485, -296, -103, -6, 178, 269, 245, 231, 320, 243, 413, - -518, -605, 282, 430, 532, 596, 676, 748, 808, 861, 834, 681, 534, 498, 293, 337, - -244, -563, -720, -599, -500, -494, -627, -739, -1028, -1219, -297, 9, 71, 272, 285, 563, - -448, -854, -916, -518, -287, -52, 56, 245, 347, 524, 557, 497, 416, 452, 321, 437, - 150, 113, 28, -26, 1, -80, -177, -226, -193, -156, -62, -227, -240, -383, -535, -809, - -240, -246, -174, -66, 80, 149, 244, 284, 413, 434, 473, 158, 56, -167, -326, -723, - 131, -11, 141, 32, 24, -122, -397, -610, -888, -812, 30, 232, 306, 371, 341, 446, - -158, -545, -529, 151, 142, -101, -426, -716, -1031, -1479, -1550, -352, -132, 145, 187, 517, - 148, -104, -445, -841, -31, 183, -86, -316, -615, -660, -231, 84, 192, 275, 201, 311, - -183, -220, -243, -182, -237, -176, -266, -233, -336, -339, -650, -1019, -1652, -846, -52, 387, - -104, -117, -254, -332, -191, 1, 64, 182, 317, 495, 626, 574, 519, 508, 456, 505, - -151, -237, 492, 479, 273, 139, 36, -60, -119, 74, 174, 188, 298, 366, 347, 478, - 158, 23, -210, -450, -673, -637, -423, -331, -133, 14, 128, 69, 62, 143, 171, 313, - 501, 394, 37, -57, 67, 70, 46, 35, 92, 120, 337, 258, 276, 283, 368, 500, - 42, -157, -398, -600, -742, -780, -781, -980, -1166, -1629, -968, -149, -99, 188, 209, 529, - -240, 190, 465, 543, 575, 565, 605, 596, 653, 599, 583, 279, 203, -51, -186, -589, - 316, 371, 417, 372, 293, 189, 230, 154, 184, 91, 94, -175, -198, -358, -454, -736, - 72, -159, -362, -499, -633, -690, -794, -739, -662, -456, -360, -338, -251, -6, 50, 346, - -202, -332, -428, -462, -508, -440, -552, -647, -885, -1217, -1733, -619, -162, 95, 202, 510, - -91, -391, -709, -884, -1012, -1001, -936, -714, -509, -198, 42, 99, 119, 261, 238, 496, - -370, 92, 476, 604, 681, 762, 826, 893, 934, 1001, 954, 783, 629, 590, 412, 467, - -193, -22, -28, 46, 214, 387, 502, 643, 728, 864, 859, 723, 581, 569, 435, 483, - 223, 291, 633, 508, 350, 141, -156, -476, -930, -1417, -1809, -764, -206, 77, 191, 515, - -475, -791, -417, 75, 201, 343, 408, 549, 612, 707, 686, 572, 463, 457, 321, 373, - 842, 716, 669, 593, 419, 423, 373, 321, 273, 280, 354, 217, 193, 232, 175, 294, - 116, -60, -144, -299, -421, -551, -732, -952, -1203, -1662, -1996, -537, -240, 55, 138, 486, - -323, -665, -686, -214, -201, -260, -373, -329, -333, -165, 66, 96, 175, 310, 291, 486, - -19, 43, 35, 40, 42, 55, 63, 101, 133, 194, 222, 152, 117, 145, 133, 213 -}; - - -const Word16 *const Quantizers_fx[] = {SVNB_SN1_fx, SVNB_SN2_fx, GETRNB_SN1_fx, GETRNB_SN2_fx, AUNB_SN1_fx,SVWB_SN1_fx, SVWB_SN2_fx, GETRWB_SN1_fx, - GETRWB_SN2_fx, AUWB_SN1_fx,/* U13, */ - TRWB2_SN1_fx, TRWB2_SN2_fx, AUWB2_SN1_fx, CNG_SN1_fx - }; -const Word16 *const Quantizers_p_fx[] = {IAA_MA1_fx, UVD_MA1_fx, UVD_MA2_fx, UVWB_MA3_fx, GESVNB_AR1_fx, GESVNB_AR2_fx, GESVWB_AR1_fx, GESVWB_AR2_fx, - GEWB2_MA1_fx,GEWB_MA1_fx, AUWB2_MA1_fx - }; - -/* Q1 */ -const Word16 sigma_MSLVQ_fx[][16] = -{ - {3}, - {3}, - {107, 113, 160, 185, 202, 211, 219, 222, 222, 217, 218, 270, 327, 176, 66, 43}, - {125, 130, 182, 185, 191, 199, 204, 207, 205, 191, 179, 227, 305, 261, 95, 64}, - {123, 123, 176, 197, 207, 218, 228, 235, 232, 218, 209, 272, 342, 216, 89, 68}, - {219, 212, 255, 271, 273, 274, 260, 255, 250, 248, 249, 302, 328, 394, 85, 37}, - {3}, - {3}, - {113, 134, 220, 253, 260, 275, 274, 287, 304, 323, 321, 325, 349, 350, 376, 332}, - {158, 179, 242, 248, 246, 259, 257, 267, 278, 274, 276, 289, 309, 309, 312, 306}, - {146, 146, 222, 256, 261, 278, 290, 302, 318, 313, 323, 352, 394, 407, 415, 399}, - {217, 227, 287, 303, 316, 310, 296, 304, 303, 305, 317, 327, 355, 321, 305, 279}, - {3}, - {3}, - {193, 216, 283, 320, 343, 359, 375, 408, 413, 445, 479, 489, 502, 466, 456, 479}, - {230, 238, 312, 330, 334, 329, 339, 357, 353, 358, 391, 403, 441, 459, 379, 497}, - {231, 277, 304, 322, 347, 353, 366, 372, 373, 397, 438, 451, 424, 413, 381, 447}, - {264, 287, 364, 386, 384, 373, 382, 373, 393, 403, 448, 438, 403, 430, 401, 586}, - {224, 298, 262, 264, 258, 244, 260, 283, 313, 295, 275, 279, 260, 286, 286, 399}, - {411, 314, 301, 332, 335, 343, 356, 409, 430, 413, 363, 364, 338, 332, 315, 412}, - {136, 269, 343, 367, 405, 430, 411, 421, 444, 466, 435, 423, 328, 247, 235, 240}, - {178, 433, 305, 268, 258, 252, 253, 246, 250, 250, 245, 256, 242, 273, 300, 371}, - {349, 334, 335, 341, 336, 331, 343, 425, 505, 722, 783, 655,1006, 862, 346, 248}, - {315, 306, 323, 306, 300, 278, 276, 287, 380, 394, 327, 333, 339, 382, 370, 626}, - {236, 250, 241, 231, 241, 245, 238, 221, 215, 190, 181, 178, 183, 428, 184, 55}, - {113, 189, 360, 312, 332, 326, 296, 268, 272, 282, 320, 275, 219, 203, 179, 143}, - {273, 255, 245, 237, 242, 236, 214, 217, 223, 260, 233, 193, 187, 183, 174, 163}, - {111, 321, 275, 219, 213, 207, 202, 205, 205, 225, 239, 208, 192, 187, 168, 152}, - {383, 326, 300, 287, 290, 292, 276, 251, 258, 291, 430, 521, 397, 305, 274, 269}, - {152, 221, 271, 291, 344, 310, 308, 257, 252, 256, 339, 491, 499, 199, 179, 107}, - {226, 237, 236, 239, 250, 238, 228, 223, 227, 241, 311, 312, 299, 313, 421, 360}, - {221, 238, 214, 220, 246, 244, 232, 221, 210, 208, 200, 229, 368, 431, 106, 71}, - {249, 259, 267, 283, 278, 275, 251, 237, 203, 209, 198, 279, 543, 509, 122, 90}, - {192, 249, 256, 235, 231, 230, 213, 215, 210, 247, 284, 237, 214, 210, 199, 181}, -}; - -/* An 16-by-19 matrix in Scale = 2.56f */ -const Word16 sigma_p_fx[][16] = -{ - {152, 164, 179, 170, 172, 176, 171, 169, 169, 174, 175, 216, 247, 304, 113, 110}, - {131, 171, 178, 176, 174, 178, 178, 178, 135, 166, 167, 176, 183, 197, 199, 206}, - {84, 89, 120, 142, 154, 175, 184, 186, 189, 181, 178, 198, 245, 190, 54, 28}, - {138, 157, 200, 194, 189, 208, 207, 206, 214, 197, 186, 222, 311, 302, 103, 43}, - {3}, - {146, 165, 183, 194, 197, 202, 191, 190, 187, 186, 171, 189, 281, 311, 61, 34}, - {142, 168, 184, 183, 187, 190, 187, 188, 189, 193, 200, 212, 231, 245, 169, 177}, - {174, 164, 168, 197, 300, 372, 199, 59, 208, 208, 209, 218, 231, 246, 237, 232}, - {91, 101, 147, 165, 174, 195, 207, 210, 218, 230, 230, 244, 268, 272, 269, 250}, - {157, 192, 226, 210, 211, 228, 228, 241, 245, 246, 248, 263, 274, 275, 270, 251}, - {3}, - {131, 160, 183, 193, 202, 205, 203, 212, 212, 213, 217, 220, 229, 214, 203, 200}, - {187, 221, 231, 229, 237, 232, 232, 236, 249, 259, 286, 284, 250, 238, 238, 296}, - {3}, - {140, 173, 241, 320, 314, 315, 304, 295, 329, 359, 369, 357, 388, 354, 359, 396}, - {248, 300, 339, 344, 360, 350, 363, 361, 368, 391, 431, 433, 406, 400, 377, 467}, - {3}, - {141, 180, 213, 223, 232, 234, 242, 240, 250, 253, 268, 255, 245, 235, 227, 200}, - {178, 205, 259, 258, 273, 285, 275, 289, 299, 300, 310, 320, 335, 329, 316, 269}, -}; - -/* An 16-by-33 matrix in Scale = 32768.00f */ -const Word16 inv_sigma_MSLVQ_fx[][16] = -{ - {32767}, - {32767}, - {783, 746, 523, 453, 416, 397, 384, 378, 378, 386, 384, 310, 256, 477, 1273, 1935}, - {670, 647, 461, 452, 440, 421, 412, 405, 410, 440, 468, 369, 275, 321, 883, 1305}, - {679, 682, 477, 426, 405, 385, 368, 357, 362, 385, 401, 308, 245, 388, 942, 1231}, - {383, 395, 329, 309, 307, 307, 322, 329, 335, 338, 337, 278, 256, 213, 989, 2243}, - {32767}, - {32767}, - {740, 628, 382, 332, 322, 305, 306, 292, 276, 259, 261, 258, 240, 240, 223, 253}, - {530, 469, 346, 338, 341, 323, 326, 314, 302, 306, 304, 290, 271, 272, 269, 274}, - {576, 576, 378, 327, 322, 302, 289, 278, 264, 268, 259, 238, 213, 206, 202, 210}, - {386, 370, 292, 277, 266, 271, 284, 276, 276, 275, 264, 257, 236, 262, 275, 300}, - {32767}, - {32767}, - {435, 389, 296, 262, 244, 233, 223, 205, 203, 188, 175, 172, 167, 180, 184, 175}, - {365, 352, 268, 254, 251, 255, 247, 235, 237, 234, 214, 208, 190, 183, 221, 169}, - {363, 302, 276, 261, 241, 237, 229, 226, 225, 211, 191, 186, 198, 203, 220, 188}, - {318, 292, 230, 218, 218, 225, 219, 225, 213, 208, 187, 192, 208, 195, 209, 143}, - {374, 281, 320, 318, 325, 344, 322, 296, 268, 284, 305, 301, 322, 294, 293, 210}, - {204, 267, 279, 253, 250, 245, 235, 205, 195, 203, 231, 231, 248, 252, 266, 204}, - {616, 312, 245, 229, 207, 195, 204, 199, 189, 180, 193, 198, 256, 340, 356, 349}, - {471, 194, 275, 313, 325, 333, 332, 342, 335, 336, 342, 328, 347, 307, 280, 226}, - {241, 251, 250, 246, 250, 254, 245, 197, 166, 116, 107, 128, 83, 97, 242, 339}, - {266, 274, 259, 274, 279, 302, 304, 292, 221, 213, 257, 252, 247, 219, 227, 134}, - {355, 336, 348, 363, 348, 342, 353, 379, 391, 442, 462, 472, 458, 196, 456,1518}, - {744, 443, 233, 269, 253, 257, 283, 313, 308, 298, 262, 305, 383, 413, 469, 585}, - {308, 330, 343, 353, 347, 356, 392, 387, 376, 322, 359, 435, 448, 458, 482, 514}, - {756, 261, 305, 384, 394, 406, 415, 409, 409, 372, 352, 403, 438, 448, 498, 552}, - {219, 257, 280, 293, 289, 288, 304, 335, 325, 289, 195, 161, 211, 275, 306, 312}, - {550, 380, 309, 288, 244, 271, 272, 326, 332, 328, 248, 171, 168, 421, 468, 781}, - {371, 355, 356, 350, 336, 353, 368, 376, 369, 348, 269, 269, 281, 268, 199, 233}, - {380, 353, 392, 381, 342, 344, 362, 379, 399, 403, 420, 367, 228, 195, 789,1184}, - {337, 324, 314, 297, 301, 305, 335, 354, 414, 401, 425, 301, 154, 165, 690, 927}, - {438, 337, 327, 357, 363, 365, 394, 390, 400, 340, 295, 354, 392, 399, 421, 462}, -}; - -/* An 16-by-19 matrix in Scale = 32768.00f */ -const Word16 inv_sigma_p_fx[][16] = -{ - {552, 513, 469, 494, 486, 478, 492, 496, 496, 482, 480, 388, 339, 276, 743, 760}, - {640, 492, 472, 478, 482, 471, 470, 471, 623, 504, 501, 477, 459, 425, 421, 408}, - {1001, 939, 696, 589, 545, 480, 456, 451, 444, 462, 472, 424, 342, 441, 1567, 3002}, - {609, 534, 419, 432, 444, 403, 406, 407, 391, 425, 452, 378, 269, 278, 818, 1939}, - {32767}, - {574, 507, 459, 432, 425, 415, 440, 442, 449, 450, 490, 443, 299, 270, 1377, 2451}, - {591, 499, 456, 457, 449, 441, 448, 446, 443, 436, 420, 397, 364, 342, 496, 475}, - {482, 512, 498, 426, 280, 225, 422, 1411, 404, 404, 402, 385, 364, 342, 355, 361}, - {917, 831, 572, 507, 482, 430, 406, 399, 385, 365, 364, 344, 313, 309, 311, 335}, - {533, 436, 371, 399, 398, 368, 367, 348, 343, 342, 338, 319, 306, 305, 311, 334}, - {32767}, - {641, 523, 458, 434, 415, 410, 412, 395, 397, 394, 386, 381, 366, 392, 413, 419}, - {449, 380, 364, 366, 354, 362, 362, 356, 337, 323, 293, 296, 336, 352, 353, 283}, - {32767}, - {601, 485, 348, 262, 267, 266, 276, 285, 255, 233, 227, 235, 216, 237, 233, 212}, - {338, 279, 247, 244, 233, 239, 231, 232, 228, 215, 194, 194, 207, 210, 222, 180}, - {32767}, - {594, 466, 394, 376, 362, 358, 346, 350, 336, 332, 313, 329, 343, 358, 370, 419}, - {471, 409, 323, 325, 308, 295, 305, 290, 281, 280, 271, 262, 251, 255, 266, 312}, -}; - -const Word16 CNG_details_codebook_fx[64][NUM_ENV_CNG]= /* Q6 */ -{ - {443,547,613,547,510,471,540,479,586,535,565,611,532,500,462,551,498,463,446,484}, - {600,499,472,537,633,654,641,646,674,677,687,693,693,690,688,700,693,696,640,571}, - {529,537,501,582,537,474,505,491,521,545,561,591,566,609,570,608,636,655,649,524}, - {648,690,689,684,693,599,668,714,663,675,524,519,726,658,673,696,654,715,708,668}, - {623,630,660,656,686,688,637,666,630,555,470,468,464,445,502,583,615,545,605,592}, - {659,668,669,625,662,700,700,693,702,702,688,677,654,584,525,492,446,477,634,615}, - {634,648,656,552,520,557,662,659,572,617,691,683,684,666,673,695,682,698,680,623}, - {756,743,734,709,730,757,746,722,484,552,779,688,686,610,616,749,758,694,745,729}, - {549,568,556,625,683,619,609,667,663,684,709,649,691,668,594,511,525,617,542,684}, - {550,467,533,760,739,692,773,756,743,770,765,791,779,784,775,792,759,577,642,553}, - {658,674,656,651,670,582,593,520,467,470,522,589,600,596,587,631,652,679,645,669}, - {788,765,787,797,785,799,787,786,780,692,641,550,501,513,726,747,670,687,734,773}, - {641,654,668,673,665,682,689,684,697,665,664,593,544,494,458,537,622,650,635,635}, - {706,753,762,716,748,762,788,792,785,788,799,777,782,766,760,710,704,503,519,735}, - {748,775,784,635,717,504,539,640,764,778,681,721,791,786,787,780,780,770,774,781}, - {752,516,624,780,713,753,569,548,770,784,749,740,690,755,776,748,744,730,767,698}, - {453,471,516,517,561,653,659,616,629,608,682,698,679,681,645,587,594,522,499,469}, - {617,534,506,615,782,792,754,771,740,787,791,776,782,787,793,788,775,778,651,736}, - {661,593,490,495,491,495,554,656,658,611,628,660,680,677,698,678,673,699,687,679}, - {798,793,786,795,799,772,771,696,624,557,507,545,724,757,747,770,780,785,793,784}, - {703,695,703,714,697,701,697,631,598,498,475,451,503,611,648,664,664,683,679,688}, - {744,672,659,762,785,745,757,761,761,767,722,757,761,737,699,471,582,770,724,756}, - {775,746,535,680,541,513,697,723,743,744,769,741,741,738,769,772,779,743,714,724}, - {767,771,697,756,766,752,710,477,602,783,746,766,692,708,783,782,761,778,787,785}, - {483,588,700,665,665,640,650,717,699,707,692,698,700,692,668,650,609,610,540,484}, - {507,618,788,766,754,692,709,785,788,770,793,785,799,784,767,776,789,759,761,495}, - {709,712,706,678,661,604,503,480,653,664,664,639,621,675,695,689,704,681,711,709}, - {788,740,770,768,771,776,732,749,739,764,714,492,544,783,714,708,717,559,739,768}, - {758,771,789,779,777,799,791,785,779,779,752,675,718,510,501,600,727,750,752,758}, - {759,765,676,658,774,767,737,749,769,784,778,738,755,769,788,756,473,530,777,725}, - {669,665,721,653,499,774,780,781,767,561,690,747,722,779,757,727,764,745,770,736}, - {731,768,745,775,783,782,715,741,786,673,766,777,764,730,773,769,774,781,778,764}, - {557,505,545,604,660,672,604,596,580,612,587,556,546,597,530,494,437,480,546,555}, - {560,588,510,495,606,720,718,742,756,755,767,774,776,778,772,772,776,776,754,592}, - {680,644,620,612,516,477,471,499,502,598,664,588,656,682,689,671,668,672,682,692}, - {757,778,781,799,775,750,799,758,789,774,489,579,799,739,774,723,686,788,787,778}, - {705,685,654,680,672,680,657,579,574,619,639,518,482,545,665,587,540,599,606,651}, - {729,767,767,773,783,778,793,773,784,779,757,768,686,654,679,564,483,549,490,522}, - {725,693,715,588,522,629,721,647,697,684,614,725,708,674,715,729,717,725,689,738}, - {797,783,795,797,782,757,636,624,508,517,703,750,746,757,772,771,774,790,779,799}, - {556,591,652,692,728,712,698,688,704,718,728,717,713,693,716,558,490,540,620,678}, - {532,617,777,775,763,789,768,785,778,791,792,792,793,777,781,724,551,665,540,509}, - {710,697,706,717,673,679,620,581,546,474,562,684,680,675,660,656,702,680,701,708}, - {771,793,788,787,794,791,792,783,791,792,733,770,532,525,692,761,777,753,734,728}, - {724,695,678,652,695,735,697,712,714,721,696,710,569,581,570,522,642,704,748,726}, - {796,754,785,782,732,814,803,794,799,790,810,806,794,797,756,745,749,506,741,779}, - {793,767,785,780,724,648,488,747,784,771,793,740,759,805,794,796,795,795,801,806}, - {787,508,640,775,722,792,774,705,781,801,774,800,786,806,808,783,795,797,784,782}, - {654,649,601,597,594,667,646,662,615,623,651,671,669,674,682,653,624,484,473,665}, - {790,765,479,527,746,728,770,753,721,774,794,802,789,782,803,795,764,804,779,776}, - {738,699,642,509,515,501,466,614,702,612,683,720,687,717,704,739,714,733,721,718}, - {778,795,791,786,758,783,783,743,744,527,554,789,762,767,722,722,777,788,776,782}, - {694,696,700,696,709,710,696,689,674,662,581,538,496,637,644,681,679,671,689,704}, - {776,788,742,796,779,756,788,789,782,798,795,804,771,753,571,611,504,545,593,779}, - {799,717,747,682,487,573,766,774,775,762,711,802,799,796,790,787,802,789,773,786}, - {795,797,790,804,788,791,774,706,532,770,786,743,789,708,755,785,804,803,807,770}, - {568,722,738,680,713,703,693,749,703,705,740,720,712,631,621,727,730,722,574,612}, - {626,762,734,770,759,750,792,775,790,792,788,786,791,767,782,778,794,745,504,544}, - {774,784,779,753,654,560,530,532,555,699,742,695,716,767,770,772,778,780,779,782}, - {781,781,790,783,792,798,787,792,765,740,701,537,564,773,767,756,786,797,789,801}, - {738,717,799,794,772,784,774,790,788,748,789,769,768,763,504,587,783,751,784,732}, - {776,789,763,772,800,786,802,787,805,799,776,773,792,761,750,702,532,745,807,735}, - {765,778,764,484,607,791,757,760,700,687,789,777,779,783,768,791,778,757,784,770}, - {800,825,775,782,821,679,805,824,752,824,796,785,829,817,824,803,814,807,762,779} -}; - -const Word16 interpol_frac_mid_fx[NB_SUBFR*3] = { 16384, 16384, 0, - 0, 32767, 0, - 0, 16384, 16384, - 0, 0, 32767 - }; - -const Word16 interpol_frac_mid_16k_fx[NB_SUBFR16k*3] = { 18022, 14746, 0, - 4915, 27853, 0, - 0, 24576, 8192, - 0, 11469, 21299, - 0, 0, 32767 - }; - - -const Word16 pi0_fx[] = {28,1,70,8,8,28,168,28,1,280,28,56,8,56,420,56, 70, 56,420, 56, 280, 56, 168, 28, 560, 168,336,28,280,28,8 - ,280,70, 8, 1120, 8, 8, 280, 168, 56, 420, 336, 840, 28, 168, 1, 168, 420, 168 - }; - -const Word16 pl_par_fx[] = /* 1 if even number of signs */ -{ - 0, 1, 0, 0, -1, 0, 0, 1, 0, 0, - 0, -1, 1, 0, 0, 0, 1, -1, 0, 0, - 0, -1, 1, 0, 0, 0, 0, 1, -1, 1, -1, 0, - 0, 0, 0, 0, -1, 1, -1, 1, 0, 0, 0, 0, 0, 1, -1, 1, -1 -}; -const Word16 no_vals_fx[NO_LEADERS]= {2,1,2,2,2,2,3,2,1,3,2,2,2,3,3,3,2,3,3,2,3,2,3,2,3,3,4,2,3,2,2,3,2,2,4,2,2,3,3,3,3,4,4,2,3,1,3,3,3}; - -const Word16 no_vals_ind_fx[NO_LEADERS][MAX_NO_VALS]= -{ - {2,6,0,0}, - {8,0,0,0}, - {4,4,0,0}, - {1,7,0,0}, - {1,7,0,0}, - {6,2,0,0}, - {1,2,5,0}, - {2,6,0,0}, - {8,0,0,0}, - {1,4,3,0}, - {2,6,0,0}, - {3,5,0,0}, - {1,7,0,0}, - {1,6,1,0}, - {2,2,4,0}, - {1,1,6,0}, - {4,4,0,0}, - {1,1,6,0}, - {2,4,2,0}, - {3,5,0,0}, - {1,3,4,0}, - {5,3,0,0}, - {1,2,5,0}, - {2,6,0,0}, - {3,2,3,0}, - {1,5,2,0}, - {1,1,1,5}, - {6,2,0,0}, - {1,3,4,0}, - {2,6,0,0}, - {1,7,0,0}, - {3,4,1,0}, - {4,4,0,0}, - {1,7,0,0}, - {1,1,3,3}, - {1,7,0,0}, - {7,1,0,0}, - {1,4,3,0}, - {2,1,5,0}, - {1,1,6,0}, - {4,2,2,0}, - {1,1,5,1}, - {1,2,1,4}, - {2,6,0,0}, - {1,2,5,0}, - {8,0,0,0}, - {1,5,2,0}, - {2,2,4,0}, - {1,2,5,0} -}; - -const Word16 C_VQ_fx[LATTICE_DIM+1][LATTICE_DIM+1]= -{ - {1,0,0,0,0,0,0,0,0}, - {1,1,0,0,0,0,0,0,0}, - {1,2,1,0,0,0,0,0,0}, - {1,3,3,1,0,0,0,0,0}, - {1,4,6,4,1,0,0,0,0}, - {1,5,10,10,5,1,0,0,0}, - {1,6,15,20,15,6,1,0,0}, - {1,7,21,35,35,21,7,1,0}, - {1,8,28,56,70,56,28,8,1} -}; - -const Word16 vals_fx[NO_LEADERS][MAX_NO_VALS]= /*Q1 */ -{ - {2, 0, 0, 0}, - {1, 0, 0, 0}, - {2, 0, 0, 0}, - {4, 0, 0, 0}, - {3, 1, 0, 0}, - {2, 0, 0, 0}, - {4, 2, 0, 0}, - {3, 1, 0, 0}, - {2, 0, 0, 0}, - {4, 2, 0, 0}, - {4, 0, 0, 0}, - {3, 1, 0, 0}, - {5, 1, 0, 0}, - {4, 2, 0, 0}, - {4, 2, 0, 0}, - {6, 2, 0, 0}, - {3, 1, 0, 0}, - {5, 3, 1, 0}, - {4, 2, 0, 0}, - {4, 0, 0, 0}, - {6, 2, 0, 0}, - {3, 1, 0, 0}, - {5, 3, 1, 0}, - {4, 2, 0, 0}, - {4, 2, 0, 0}, - {6, 2, 0, 0}, - {6, 4, 2, 0}, - {3, 1, 0, 0}, - {5, 3, 1, 0}, - {5, 1, 0, 0}, - {7, 1, 0, 0}, - {4, 2, 0, 0}, - {4, 0, 0, 0}, - {6, 2, 0, 0}, - {6, 4, 2, 0}, - {8, 0, 0, 0}, - {3, 1, 0, 0}, - {5, 3, 1, 0}, - {5, 3, 1, 0}, - {7, 3, 1, 0}, - {4, 2, 0, 0}, - {6, 4, 2, 0}, - {6, 4, 2, 0}, - {6, 0, 0, 0}, - {8, 2, 0, 0}, - {3, 0, 0, 0}, - {5, 3, 1, 0}, - {5, 3, 1, 0}, - {7, 3, 1, 0}, -}; - -/* An 6-by-128 matrix in Scale = 2048.00f */ -const Word16 scales_fx[][6] = -{ - {3129, 0, 0, 3138, 0, 0, }, /* 14 */ - {3287, 0, 0, 3138, 0, 0, }, /* 15 */ - {2611, 5034, 0, 3138, 0, 0, }, - {2611, 5034, 0, 3340, 0, 0, }, - {2165, 3674, 5931, 2363, 3809, 6281, }, - {1898, 2986, 4745, 2116, 3668, 7045, }, /* 28 */ /* mode 0 UV WB*/ - {2630, 5480, 0, 2972, 0, 0, }, - {2802, 0, 0, 2869, 5073, 0, }, - {1763, 2546, 3723, 2515, 4559, 21109, }, - {2195, 3961, 7440, 2501, 6017, 21961, }, - {1841, 2902, 1386, 2116, 3762, 22309, }, - {1700, 2710, 1288, 1866, 3246, 20660, }, /* 32 */ /* mode 1 UV NB*/ - - - {3222, 0, 0, 3391, 0, 0, }, - {2537, 4923, 0, 3187, 0, 0, }, - {2161, 3482, 9091, 3391, 0, 0, }, - {2560, 4923, 8462, 2775, 4835, 0, }, - {2163, 3656, 9263, 2699, 5296, 0, }, - {2040, 3082, 6871, 2427, 3637, 5587, }, - {1903, 2841, 6875, 2212, 3484, 5908, }, - {1888, 3058, 6900, 2212, 3484, 5908, }, - {1888, 3058, 6900, 2183, 3469, 6420, }, - {1888, 3058, 6900, 1970, 3174, 8081, }, - {1528, 2269, 5876, 1964, 3033, 8002, }, - {1577, 2445, 5782, 1858, 2871, 4334, }, - - {1532, 2259, 5870, 2421, 1661, 6824, }, /* 34 */ - - {1386, 1972, 4356, 1487, 2216, 4514, }, /* 37 */ /* mode 2 V WB*/ - {3357, 0, 0, 2494, 4426, 0, }, - {2634, 5009, 0, 2888, 0, 0, }, - {2224, 3539, 7696, 2494, 4426, 0, }, - {2120, 3226, 9861, 2494, 4426, 0, }, - {1974, 3140, 10121, 2494, 4426, 0, }, - {1722, 2454, 4059, 2494, 4426, 0, }, - {1839, 2658, 4473, 2490, 5456, 0, }, - {1722, 2533, 4581, 2038, 3394, 5808, }, - - {1427, 2009, 4184, 1915, 3082, 1350, }, - {1370, 1862, 2720, 2017, 1339, 3914, }, /* 37 */ /* mode 3 V NB */ - - {2482, 3885, 0, 0, 0, 0, }, - {3346, 0, 0, 3418, 0, 0, }, - {2638, 4962, 0, 3418, 0, 0, }, - {2482, 3885, 0, 3418, 0, 0, }, - {2218, 3617, 6502, 3418, 0, 0, }, - {2124, 3295, 8659, 3418, 0, 0, }, - {2243, 3398, 5562, 2693, 5132, 0, }, - {1927, 2839, 4549, 2693, 5132, 0, }, - {1860, 2675, 3893, 2703, 5372, 0, }, - {2202, 3619, 1618, 2703, 5372, 0, }, - {2093, 3135, 1554, 2273, 3594, 5313, }, - {2202, 3619, 1618, 2238, 3895, 6173, }, - {1829, 3015, 1382, 2259, 3625, 5820, }, - {1864, 3170, 1403, 2114, 3381, 5147, }, - {1692, 2572, 1294, 2009, 3158, 4540, }, /* 32 (31.995) */ /* G WB*/ - {2425, 3707, 5655, 0, 0, 0, }, - {3299, 0, 0, 3314, 0, 0, }, - {2425, 3707, 5655, 3174, 0, 0, }, - {2425, 3707, 5655, 3314, 0, 0, }, - {2177, 3557, 6113, 3314, 0, 0, }, - {2208, 3738, 6476, 3009, 4606, 0, }, - {2816, 1874, 4264, 3009, 4606, 0, }, - {1966, 2914, 1434, 2683, 4366, 0, }, - {2302, 1626, 3895, 2628, 4714, 0, }, - {2206, 3537, 1571, 2560, 3996, 6105, }, - {1911, 3013, 1403, 2560, 3996, 6105, }, - {1898, 3277, 1380, 2363, 3637, 5845, }, - {2144, 1479, 3656, 2163, 3363, 5532, }, - {1989, 1409, 3090, 2136, 3543, 6003, }, - {1882, 1356, 2800, 2165, 3703, 6285, }, /* 32 (31.987) */ /* G NB*/ - {3312, 0, 0, 3394, 0, 0, }, - {2611, 4706, 0, 3201, 0, 0, }, - {2679, 4821, 0, 2841, 0, 0, }, - {2644, 4952, 0, 2775, 5003, 0, }, - {2210, 3623, 6169, 2841, 0, 0, }, - {2210, 3623, 6169, 2714, 5233, 0, }, - {1837, 2744, 5333, 2191, 3459, 5175, }, - {1837, 2744, 5333, 1923, 2978, 4266, }, - {1853, 2718, 5323, 2271, 1591, 3492, }, - {1561, 2255, 4831, 1923, 2978, 4266, }, - {1626, 2511, 6513, 2271, 1591, 3492, }, /* 33 */ - /* mode 6 T WB */ - {3336, 0, 0, 2439, 4528, 0, }, - {2615, 5237, 0, 2800, 0, 0, }, - {2216, 3607, 8047, 2439, 4528, 0, }, - {2085, 3144, 5751, 2439, 4528, 0, }, - {1933, 3025, 5659, 2439, 4528, 0, }, - {1864, 3572, 6793, 2439, 4528, 0, }, - {1884, 3375, 6283, 1985, 3447, 8096, }, - {1513, 2275, 5517, 1800, 2890, 4721, }, - {1452, 2114, 5564, 1659, 2550, 3736, }, /* 32 */ /* mode 7 T NB */ - - {1552, 2286, 4022, 2497, 4139, 1634,}, - {1432, 2118, 4051, 2497, 4139, 1634, }, /* 32 */ /* mode 8 G 16k */ - - {1487, 2150, 3779, 2775, 1761, 4516, }, - {1386, 2042, 3418, 2775, 1761, 4516, }, /* 33 (32.983) */ /* T 16k */ - - {3371, 0, 0, 2568, 5036, 0, }, - {2198, 3815, 6617, 3437, 0, 0, }, - {2198, 3815, 6617, 2568, 5036, 0, }, - {1948, 3056, 5112, 2570, 6085, 0, }, - {2351, 3770, 1665, 2570, 6085, 0, }, /* 26 */ - {1233, 1780, 2904, 2589, 1565, 4542, }, /* 36 */ /* mode 10 AUDIO_WB 36 + 4 + 1 */ - - {1747, 3623, 9062, 0, 0, 0, }, - {2071, 3406, 9017, 3232, 0, 0, }, - {2071, 3406, 9017, 2462, 4964, 0, }, - {1804, 3314, 8471, 2462, 4964, 0, }, - {1735, 3668, 9146, 2462, 4964, 0, }, /* 27 */ /* AUDIO_NB */ - {1372, 2277, 4893, 2462, 4964, 0, }, /* 28 */ /* AUDIO_NB */ - {2316, 3717, 1630, 2591, 5722, 0, }, - {1167, 1647, 2451, 2380, 3992, 1491, }, /* 36 */ /* mode 12 AUDIO_WB 16k 15-36 + 4 + 1*/ - {2140, 3248, 7688, 3418, 0, 0, }, - {1802, 2621, 5784, 2251, 3553, 0, }, - {1702, 2488, 5994, 2230, 3498, 5077, }, - {1782, 2718, 5951, 2183, 3521, 5480, }, - - {1581, 2298, 4815, 2961, 1933, 4243, }, - - {1436, 2001, 3559, 1939, 2976, 4264, }, - - {1473, 2091, 3484, 2292, 1626, 3473, }, - - {1311, 1810, 3547, 1546, 2232, 3170, }, /* 37 (36.995) */ /* VOICED 16k */ - {2494, 1630, 4676, 2642, 6810, 0, }, - {3256, 1710, 9085, 2247, 6287, 0, }, - - {2036, 5360, 0, 2234, 4573, 7080, }, - {1817, 3222, 7256, 2228, 3742, 6281, }, - {1714, 2535, 3897, 2658, 5728, 0, }, - {2331, 5788, 0, 2265, 5726, 8993, }, - {1927, 3955, 9161, 1395, 2593, 4768, }, - {2769, 8872, 0, 1679, 3164, 8550, }, - {2750, 7387, 0, 1759, 2976, 5304, }, - {2474, 5612, 0, 1554, 2540, 4469, }, - {2300, 5603, 0, 1790, 3068, 5296, }, - {1882, 5061, 0, 1260, 2195, 4293, }, - {3170, 9232, 0, 1690, 4461, 8817, }, - {2492, 5935, 0, 1509, 2492, 3953, }, - - {1999, 4485, 11706, 3084, 1315, 8624, }, - {2267, 5315, 0, 2666, 1237, 1802}, /* CNG */ - -};/* An 6-by-146 matrix in Scale = 2048.00f */ -const Word16 scales_p_fx[][6] = -{ - {2998, 4862, 0, 0, 0, 0, }, - {2591, 5251, 0, 3355, 0, 0, }, - {2177, 3488, 5745, 2650, 4819, 0, }, - {2177, 3926, 6273, 2796, 0, 0, }, - {1872, 2892, 4553, 2650, 4819, 0, }, - {1806, 2869, 4919, 2689, 4999, 0, }, - {2777, 1776, 4868, 2191, 3453, 5214, }, - {1733, 2761, 5214, 2204, 3568, 5444, }, - {1731, 2824, 5255, 2087, 3230, 5003, }, - {1548, 2435, 5732, 2220, 3695, 5648, }, - {1546, 2494, 5777, 1933, 2935, 4041, }, - {1483, 2529, 6025, 2570, 1737, 4096, }, - {1407, 2279, 4788, 1747, 2720, 3981, }, - {1327, 2107, 3760, 1749, 2777, 4016, }, - {1327, 2107, 3760, 1407, 2167, 3891, }, /* 39 (38.488) */ /* V WB*/ /* 14 */ - {3303, 0, 0, 0, 0, 0, }, - {2595, 5069, 0, 3316, 0, 0, }, - {2077, 3338, 5046, 2632, 4405, 0, }, - {1829, 2847, 4739, 3000, 4708, 0, }, - {1905, 2869, 4403, 2621, 4616, 0, }, - {1829, 2847, 4739, 2613, 4518, 6111, }, - {1829, 2847, 4739, 2122, 3371, 5061, }, - {1755, 2738, 5046, 2136, 3543, 5376, }, - {1567, 2497, 3181, 2122, 3371, 5061, }, - {1616, 2720, 3383, 2154, 3654, 5542, }, - {1565, 2507, 3185, 1884, 2955, 4168, }, - {1358, 2173, 2535, 2824, 1839, 3996, }, - {1378, 2261, 2675, 2578, 1696, 4002, }, - {1364, 2193, 2558, 1645, 2542, 3541, }, - {1348, 2128, 2486, 1946, 1333, 2927, }, /* 39 (38.512) */ /* V NB*/ /* 29 */ - {3277, 0, 0, 3181, 0, 0, }, - {2322, 4067, 6748, 3181, 0, 0, }, - {2021, 3662, 5446, 3373, 0, 0, }, - {1841, 3281, 5282, 3373, 0, 0, }, - {1632, 2650, 4383, 3373, 0, 0, }, - {1632, 2650, 4383, 2734, 4557, 0, }, - {1518, 2357, 3719, 2734, 4557, 0, }, - {1632, 2650, 4383, 2429, 3957, 0, }, - {1518, 2357, 3719, 2384, 3734, 5671, }, - {1450, 2306, 4000, 2204, 3543, 5687, }, - {1352, 2148, 3217, 2204, 3543, 5687, }, - {1356, 2101, 3183, 2200, 3918, 6189, }, - {1352, 2148, 3217, 2947, 1896, 4364, }, - {1290, 1978, 3117, 2687, 1804, 4520, }, - {1264, 1886, 2963, 2114, 3172, 1548, }, /* 35 (34.994) */ /* G WB*/ /* 44 */ - {3267, 0, 0, 3076, 0, 0, }, - {2300, 3985, 7643, 3076, 0, 0, }, - {2116, 4250, 8886, 2906, 5009, 0, }, - {2017, 3672, 12216, 2623, 4760, 0, }, - {1804, 3289, 14326, 2906, 5009, 0, }, - {1729, 3240, 14377, 2623, 4760, 0, }, - {1616, 3113, 14752, 2623, 4760, 0, }, - {1780, 3168, 14326, 2109, 3592, 6353, }, - {1673, 3056, 14582, 2109, 3592, 6353, }, - {1546, 2830, 14608, 2109, 3592, 6353, }, - {1446, 2693, 14797, 2109, 3592, 6353, }, - {1411, 2654, 14930, 2081, 3840, 6633, }, - {1430, 2611, 14764, 1872, 3170, 4983, }, - {1391, 2693, 14930, 2517, 3779, 1665, }, - {1391, 2693, 14930, 2433, 1581, 4004, }, /* 35 (34.952) */ /* G NB*/ /* 59 */ - - {2070, 3639, 5652, 3305, 0,0,}, - {1747, 2830, 4231, 2550, 5487, 0,}, - {2472, 1593, 4522, 2550, 5487, 0,}, - {2472, 1593, 4522, 2075, 3752, 6253}, - {2472, 1593, 4522, 2908, 1786, 4772,}, - {1075, 1577, 2198, 1669, 2533, 1161}, /* 40 (39.990) */ /* AUDIO_WB */ /* 65 */ - - {2191, 3668, 7993, 3275, 0, 0, }, - {1679, 2492, 4278, 2570, 4690, 0, }, - {1597, 2394, 5110, 2570, 4690, 0, }, - {2202, 1481, 4835, 2273, 4016, 7150, }, - - {1415, 2107, 4786, 2118, 3668, 8200, }, /* 31 */ /*AUDIO_NB */ /* 70 */ - {1374, 2204, 5337, 1956, 3168, 5149, }, /* 32 */ /*AUDIO_NB */ /* 71 */ - {2425, 4336, 1589,3420, 2165, 1380, }, - {1067, 1530, 2116, 1630, 2730, 1110,}, /* 40 */ /* mode AUDIO_WB 16k */ /* 73*/ - - {3439, 0, 0, 2626, 5061, 0, }, - {2228, 3787, 6543, 3455, 0, 0, }, - {2228, 3787, 6543, 2626, 5061, 0, }, - {2306, 3459, 1618, 2626, 5061, 0, }, - {1905, 2830, 1397, 2626, 5061, 0, }, - {2284, 1626, 3793, 2623, 6212, 0, }, - {1720, 2818, 1276, 1638, 2900, 8724, }, /* 36 (35.998) */ /* INACTIVE NB */ - {1640, 2351, 3690, 0, 0, 0, }, - {2230, 3711, 6496, 3434, 0, 0, }, - {2230, 3899, 6597, 3115, 5396, 0, }, - {1731, 2482, 3961, 2689, 4954, 0, }, - {1595, 2243, 3482, 2689, 4954, 0, }, - {1481, 2079, 3408, 2689, 4954, 0, }, - {1829, 1335, 2945, 2204, 1475, 3674, }, /* 36 (35.929) */ /* INACTIVE WB*/ - {2783, 4723, 0, 3418, 0, 0, }, - {2206, 3946, 7262, 3418, 0, 0, }, - {2206, 4162, 7328, 2927, 5552, 0, }, - {1706, 2566, 4311, 2628, 5235, 0, }, - {1589, 2359, 3805, 2628, 5235, 0, }, - {1473, 2183, 3547, 2628, 5235, 0, }, - {1927, 1333, 3205, 1479, 2437, 3973, }, /* 36 (35.915) */ /* INACTIVE 16k*/ - - {2646, 5077, 0, 3156, 0, 0, }, - {2462, 3897, 0, 3156, 0, 0, }, - {2105, 3361, 5028, 3375, 0, 0, }, - {2554, 1798, 4770, 3375, 0, 0, }, - {1767, 2781, 5165, 3375, 0, 0, }, - {1673, 2503, 4116, 2200, 3656, 5597, }, - {1669, 1253, 2623, 2161, 3531, 6046, }, /* 32 (31.990) */ /* UNVOICED NB*/ - - {3164, 0, 0, 3170, 0, 0, }, - {3359, 0, 0, 3170, 0, 0, }, - {2636, 5630, 0, 3170, 0, 0, }, - {2636, 5630, 0, 3387, 0, 0, }, - {2437, 4149, 0, 3387, 0, 0, }, - {1907, 2986, 5018, 2650, 5616, 0, }, - {1796, 2859, 5605, 2214, 3719, 6881, }, /* 28 (27.996) */ /* UNVOICED WB */ - {2316, 3351, 0, 2808, 0, 0, }, - {1913, 2615, 1491, 2370, 3475, 0, }, - {1706, 2380, 1348, 2357, 3455, 0, }, - {1538, 2114, 1225, 2357, 3455, 0, }, - {1452, 2058, 1167, 2171, 3629, 5569, }, - {1528, 2050, 1231, 2056, 3693, 5923, }, - {1522, 2048, 1227, 1917, 3811, 5886, }, - {1587, 1257, 2124, 1630, 2671, 3901, }, /* 39 (38.301) */ /* VOICED 16k */ - {1831, 2742, 5220, 2679, 5327, 0, }, - {1475, 2073, 3273, 3097, 1896, 4377, }, - {1395, 1993, 3377, 2828, 1794, 4360, }, - {1401, 1974, 3359, 2392, 3637, 1612, }, - {1368, 1915, 3176, 2081, 3109, 1458, }, - {1350, 1866, 2918, 2738, 1821, 1315, }, - {1350, 1866, 2918, 1718, 2636, 1243, }, /* 37 (36.989) */ /* GENERIC 16k*/ - {3344, 0, 0, 3455, 0, 0, }, - {2204, 3666, 6025, 3455, 0, 0, }, - {1708, 2517, 3871, 3455, 0, 0, }, - {1921, 2875, 4409, 2675, 5386, 0, }, - {2744, 1815, 4751, 2675, 5386, 0, }, - {1706, 2560, 3908, 2675, 5386, 0, }, - {1706, 2484, 3836, 2304, 3766, 5773, }, - {1567, 2380, 3461, 2097, 3559, 5812, }, - {1485, 2150, 3668, 3031, 1888, 6357, }, - {1458, 2073, 3172, 3060, 1849, 6889, }, - {1350, 1898, 2779, 3060, 1849, 6889, }, - {1683, 1257, 2638, 1864, 3090, 4618, }, - {1722, 1278, 2617, 2378, 1561, 3703, }, - {1716, 1274, 2593, 2212, 1456, 3502, }, - {1704, 1268, 2611, 1921, 2929, 1319, }, /* 37 (36.971) */ /* GENERIC 12.8k MA*/ - {1810, 2763, 5263, 2691, 5343, 0, }, - {1456, 2085, 3308, 3035, 1886, 7027, }, - - {1391, 1995, 3398, 1942, 3172, 7062, }, - - {1702, 1266, 3033, 1911, 3101, 4731, }, - {1671, 1249, 2871, 2920, 1796, 4639, }, - {1612, 2574, 1221, 1759, 2963, 4979, }, - {1612, 2574, 1221, 2265, 1505, 3398}, /* 37 (36.993) */ /* AUDIO 16k */ - -}; - - - -/*-----------------------------------------------------------------* - * BC-TCVQ frame-end quantization tables (BC-TCVQ is used in Voiced mode for 16kHz isf) - *-----------------------------------------------------------------*/ -const Word16 NTRANS[4][NUM_STATE] = {{0,2,4,6,8,10,12,14,0,2,4,6,8,10,12,14}, /* indices of previous state of first branche */ - {1,3,5,7,9,11,13,15,1,3,5,7,9,11,13,15}, /* indices of previous state of second branches */ - {4,2,1,3,0,2,1,3,2,0,3,1,7,0,3,1}, /* indices of previous subset of first branch */ - {2,0,3,6,2,0,3,1,0,2,1,3,0,2,1,5} /* indices of previous subset of second branch */ -}; - -const Word16 NTRANS2[4][NUM_STATE] = {{0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7}, - {8,8,9,9,10,10,11,11,12,12,13,13,14,14,15,15}, - {4,2,2,0,1,3,3,6,0,2,2,0,1,3,3,1}, - {2,0,0,2,3,1,1,3,7,0,0,2,3,1,1,5} -}; - -/* BC-TCQ Bit Allocations */ -const Word16 BC_TCVQ_BIT_ALLOC_40B[M/2+4] = {1, 4, 5,5,4,4, 2,2,2,2, 5,4 }; /*1+39bit*/ - -const Word16 FixBranch_tbl[4][4][N_STAGE_VQ - 4] = -{ - {{0, 0, 0, 0}, {1, 0, 0, 0}, {0, 1, 0, 0}, {1, 1, 0, 0}}, /* incase of initial state 0 */ - {{0, 0, 1, 0}, {1, 0, 1, 0}, {0, 1, 1, 0}, {1, 1, 1, 0}}, /* incase of initial state 4 */ - {{0, 0, 0, 1}, {1, 0, 0, 1}, {0, 1, 0, 1}, {1, 1, 0, 1}}, /* incase of initial state 8 */ - {{0, 0, 1, 1}, {1, 0, 1, 1}, {0, 1, 1, 1}, {1, 1, 1, 1}} /* incase of initial state 12 */ -}; - -const Word16 AR_IntraCoeff_fx[N_STAGE_VQ-1][2][2] = /* Q15 */ -{ - {{-9584, 22162}, {-13849, 7127}}, - {{ 1604, 16400}, { 2861, 9414}}, - {{ 6537, 16475}, { 3498, 13792}}, - {{ 7879, 14434}, { 7021, 12992}}, - {{ 6329, 16215}, { 5200, 10052}}, - {{ 3062, 12146}, { 2147, 4857}}, - {{ 1226, 11040}, { -794, 6137}} -}; -const Word16 SN_IntraCoeff_fx[N_STAGE_VQ-1][2][2] = /* Q15 */ -{ - {{-14822, 26501}, {-17180, 10012}}, - {{ 317, 19858}, { -432, 13799}}, - {{ 4747, 22069}, { 2653, 19016}}, - {{ 6823, 20747}, { 7077, 19154}}, - {{ 1665, 25161}, { 2519, 13654}}, - {{ 166, 18043}, { -221, 9732}}, - {{ -781, 20026}, { -5332, 18882}} -}; -const Word16 scale_ARSN_fx[M] = /* Q14 */ -{ - 29994, 30153, 29506, 28534, 28246, 28618, 26388, 27029, - 25726, 25474, 25797, 26540, 25613, 24968, 25880, 25584 -}; -const Word16 scale_inv_ARSN_fx[M] = /* Q15 */ -{ - 17898, 17806, 18196, 18815, 19005, 18760, 20342, 19864, - 20870, 21076, 20811, 20228, 20962, 21502, 20745, 20985 -}; -const Word16 AR_TCVQ_CB_SUB1_fx[2][128][2] = /* x2.65 */ -{ - { - {-435 , -434}, {-233 , 124}, {-381 , 44}, {-274 , -88}, {-332 , -224}, {-563 , -600}, {-332 , 134}, { 53 , -739}, - {-567 , 0}, { 149 , 316}, {-191 , 541}, {-123 , 317}, {-493 , -634}, {-528 , 268}, {-321 , -386}, {-432 , -220}, - {-244 , -230}, { -33 , 454}, {-188 , -642}, {-131 , -215}, {-676 , 263}, {-472 , -403}, {-312 , -159}, {-340 , 297}, - {-121 , -217}, { -6 , 241}, {-203 , -211}, {-126 , -15}, {-734 , -374}, {-458 , -6}, {-297 , -27}, {-307 , -553}, - {-177 , 3}, {-175 , -273}, { 63 , 363}, { 133 , 527}, {-133 , -185}, {-449 , -1206}, {-287 , -281}, {-131 , 869}, - {-100 , -105}, { -75 , -179}, {-141 , 131}, { -32 , 108}, { -81 , 161}, {-446 , -230}, {-283 , -884}, {-128 , -165}, - {-153 , -451}, {-177 , -114}, {-113 , -127}, {-223 , -355}, {-246 , -447}, {-396 , -705}, {-280 , 329}, { -37 , -64}, - {-118 , 208}, { -82 , 64}, {-339 , -367}, { -58 , -132}, {-458 , 644}, {-381 , -543}, {-272 , 557}, { 62 , 75}, - {-307 , -829}, { 310 , 445}, { 73 , -26}, { 95 , 219}, { 223 , 611}, { 279 , 195}, { 430 , 575}, { 424 , 221}, - { -25 , 2}, { 323 , 236}, {-100 , -310}, { 11 , -35}, { 83 , -3}, { 281 , 738}, { 495 , 393}, { 89 , 1284}, - { 32 , 136}, { 29 , 34}, { 491 , 575}, { 105 , -188}, { 15 , -440}, { 285 , 10}, { 516 , -105}, { 313 , 704}, - { -6 , -274}, { -62 , -64}, { -12 , -127}, { 170 , 2387}, { 162 , 196}, { 336 , 413}, { 543 , 210}, { 231 , -70}, - { -2 , 691}, { 98 , 134}, { 25 , 141}, { 261 , 305}, { 312 , -322}, { 336 , 228}, { 561 , 781}, { 766 , 514}, - { -14 , -117}, { 166 , 905}, { -50 , 1}, { 471 , 369}, { 345 , 247}, { 347 , -383}, { 561 , 1128}, { 513 , 1030}, - { 100 , -15}, { 185 , 70}, { 167 , 131}, { 122 , 36}, { 561 , 743}, { 401 , 111}, { 595 , -579}, { 674 , 215}, - { 191 , 189}, { 38 , -78}, { 428 , 0}, { 261 , 136}, { -29 , -99}, { 405 , 308}, { 614 , 574}, {1682 , 1704} - }, - { - {-942 , -168}, {-262 , -361}, { -53 , -171}, {-245 , 472}, {-2145 , -2315}, {-1307 , 1261}, {-870 , -1940}, { -652 , -564}, - {-500 , 447}, {-578 , -198}, {-554 , 111}, { -98 , -84}, {-1315 , 0}, {-1229 , -1618}, {-868 , 230}, { -385 , 1061}, - {-768 , -998}, {-202 , -60}, {-283 , -197}, {-142 , -325}, { -558 , 755}, {-1217 , 456}, {-803 , 766}, { -982 , 743}, - {-415 , -357}, { -28 , 1054}, { 114 , -246}, { 81 , 732}, { -804 , -506}, {-1126 , -112}, {-797 , -132}, { -289 , -204}, - {-347 , -29}, { -37 , -259}, {-142 , -438}, {-249 , 87}, { -874 , 341}, {-1074 , -2635}, {-668 , -1552}, {-1140 , -764}, - {-245 , -513}, { -48 , 526}, { 14 , 395}, {-452 , -646}, { -441 , -969}, { -953 , -1284}, {-645 , -387}, { -736 , 111}, - {-163 , 305}, {-349 , 224}, {-225 , 736}, { 94 , -85}, { -302 , -549}, { -937 , -892}, {-605 , -1089}, { -64 , -101}, - {-161 , -211}, {-392 , -1299}, {-148 , 125}, { 14 , 131}, { -432 , -127}, { -920 , -510}, {-598 , -730}, { 85 , 154}, - { 25 , -155}, { -57 , 238}, { 471 , 276}, { 421 , 680}, { -173 , 316}, { 597 , 1805}, { 906 , -673}, { 538 , 450}, - {-267 , -805}, { 2 , -19}, { 222 , 219}, { 185 , 352}, { -33 , -178}, { 606 , 118}, { 959 , -70}, { 350 , -91}, - { -87 , 42}, { 727 , 905}, { 54 , 33}, { 316 , 44}, { 251 , 15}, { 610 , -122}, { 990 , 1436}, { 82 , 1480}, - { 181 , 535}, { 177 , 130}, { 700 , 565}, { 626 , 331}, { 279 , 551}, { 680 , 707}, {1012 , 727}, { 1057 , 766}, - { -13 , -396}, { 364 , 412}, { 442 , -181}, { 202 , -386}, { 565 , 1397}, { 740 , 2621}, {1080 , 361}, { 1118 , 191}, - { 81 , 266}, { 217 , -130}, { 349 , 1009}, { 678 , -476}, { 1361 , 878}, { 795 , 472}, {1267 , 1034}, { 1040 , 1255}, - { 351 , 201}, { -69 , -633}, { -36 , -1046}, { 808 , 30}, { 1300 , -198}, { 803 , 1026}, {1390 , -326}, { 2291 , 2479}, - { 166 , 13}, { 521 , 84}, { 255 , -717}, { 987 , 448}, { 777 , 220}, { 811 , 208}, {1395 , 2021}, { 1499 , 417} - } -}; -const Word16 AR_TCVQ_CB_SUB2_fx[2][64][2] = -{ - { - {-357 , -53}, {-525 , 167}, {-232 , 255}, {-132 , -359}, {-940 , -221}, { -260 , -1296}, {-1197 , -455}, { -833 , 49}, - {-132 , -1}, {-401 , -280}, {-212 , -217}, {-194 , 92}, {-580 , -710}, { -862 , -750}, { -669 , 430}, { -521 , 719}, - {-620 , -454}, {-239 , 509}, { -15 , -575}, { 389 , 704}, {-890 , 518}, {-1154 , 84}, { -632 , -1023}, { -620 , -1263}, - {-268 , -470}, {-326 , -738}, { 44 , 635}, { 73 , 362}, {-226 , -22}, { -625 , -106}, { -720 , -114}, {-1114 , -1070}, - { 19 , -250}, { 83 , 99}, { 35 , -16}, { 263 , -316}, { 472 , 1096}, { -52 , -328}, { -249 , 971}, { 1387 , 876}, - { 10 , 203}, { 869 , 649}, { 225 , 170}, { 301 , 83}, {1256 , 482}, { 391 , -777}, { 1064 , -320}, { 52 , 1207}, - { 309 , 375}, { 469 , 226}, { 619 , 400}, { 60 , -93}, { 335 , 244}, { 316 , -65}, { -45 , -987}, { 648 , -294}, - { 218 , -66}, {-108 , -133}, { 500 , -19}, { 824 , 163}, { 483 , -443}, { 1297 , 240}, { 1000 , 1205}, { 623 , 1347} - }, - { - {-424 , -965}, { -46 , -194}, { 20 , 298}, {-333 , -278}, {-797 , -522}, {-868 , -60}, { -20 , -140}, {-1085 , -904}, - {-615 , -243}, {-367 , 22}, {-261 , -519}, {-111 , -27}, {-745 , 142}, {-484 , -1519}, { -329 , 13}, {-1077 , 92}, - {-529 , 218}, {-519 , -597}, {-276 , -72}, { -87 , -398}, { -51 , -1257}, {-291 , 409}, { -883 , 611}, { 176 , -401}, - {-134 , -245}, { 37 , 506}, { 23 , -10}, {-225 , 293}, {-913 , -1324}, {-174 , -290}, {-1086 , -386}, { -139 , -78}, - {-123 , 125}, { -26 , -738}, { 113 , -344}, { 175 , 182}, { 754 , -446}, {1207 , 529}, { 932 , 990}, { 136 , 122}, - { 267 , 327}, { 382 , -182}, { 718 , 471}, { 738 , 108}, { 158 , 130}, { 437 , 401}, { 358 , -667}, { 1380 , 836}, - { 184 , -17}, { 435 , 231}, { 403 , 63}, { 151 , -125}, {-109 , -237}, { 692 , -241}, { 1247 , 193}, { 885 , 324}, - {-283 , 661}, { 44 , 105}, { 156 , 911}, { 387 , 588}, { 690 , 1459}, { 664 , 1057}, { -38 , 1455}, { 645 , 909} - } -}; -const Word16 AR_TCVQ_CB_SUB3_fx[4][32][2] = -{ - { - {-487 , 9}, {-456 , -400}, { 96 , 451}, {-239 , 422}, {-685 , -1309}, { 68 , -709}, {-302 , -1185}, { 481 , -287}, - {-287 , -697}, {-194 , 73}, {-159 , -132}, {-161 , -312}, {-809 , 417}, {-860 , -926}, { -26 , -71}, {-1052 , -432}, - { 53 , 134}, { 106 , -140}, { 336 , -18}, { 404 , 735}, {-109 , -516}, { 719 , -65}, { -34 , 1336}, { -171 , 905}, - { 52 , -347}, { 359 , 266}, { 715 , 351}, { 100 , 133}, { 87 , 130}, { 975 , 999}, {1257 , 547}, { 738 , 1372} - }, - { - {-340 , -464}, {-216 , -779}, { 104 , -403}, { -92 , -221}, {-760 , -602}, {-914 , -811}, {-661 , -895}, {-1292 , -290}, - {-317 , 131}, {-575 , -154}, {-228 , -129}, {-257 , 487}, {-286 , -1354}, { -93 , -259}, {-798 , 179}, { -815 , -1368}, - { 215 , 570}, { -2 , 73}, { 545 , 167}, { 250 , 188}, { 76 , 48}, {-943 , 587}, { 379 , 1232}, { 1070 , 112}, - { 117 , -27}, { 389 , -142}, { 18 , 214}, { 735 , 581}, {1098 , 1244}, { 451 , 408}, {1482 , 650}, { -174 , 1160} - }, - { - {-256 , -485}, { -67 , 571}, { -5 , 161}, {-171 , 153}, {-1188 , -440}, {-1081 , 110}, {-641 , -921}, {-232 , -96}, - {-511 , 146}, {-288 , -93}, { 484 , 665}, {-610 , -366}, { -357 , -899}, { -861 , -1088}, { -78 , -105}, {-265 , -845}, - { 15 , 18}, { 79 , -383}, {-205 , -258}, { 306 , 264}, { 28 , 69}, { 34 , 65}, {1170 , 669}, { 133 , 74}, - { 521 , 183}, { 132 , 84}, { 362 , -90}, { 57 , -181}, { 894 , 456}, { 1147 , 742}, { 212 , 274}, { 891 , 262} - }, - { - { 94 , 464}, { 8 , 138}, {-365 , -640}, {-399 , 172}, {-249 , -109}, { -94 , -316}, {-163 , -250}, {-598 , -704}, - {-185 , 36}, {-470 , -199}, { 65 , 241}, {-104 , -362}, {-220 , -801}, {-866 , -66}, {-931 , -400}, {-172 , -132}, - {-148 , -494}, { 465 , 251}, {-179 , -72}, { 439 , 287}, { 824 , 559}, { 33 , 134}, { 59 , 134}, { 88 , 146}, - { 186 , 43}, { 69 , -261}, { 267 , -96}, { 40 , 79}, { 84 , 130}, { 678 , 378}, { 811 , 448}, { 920 , 541} - } -}; -const Word16 SN_TCVQ_CB_SUB1_fx[2][128][2] = -{ - { - {-639 , 105}, {-488 , -449}, {-530 , -811}, {-419 , -634}, {-781 , -1061}, {-585 , 386}, {-501 , -737}, {-489 , -728}, - {-702 , -685}, {-510 , -762}, {-390 , -287}, {-379 , -379}, {-573 , -848}, {-583 , -778}, {-500 , -810}, {-671 , -420}, - {-516 , 802}, {-265 , -492}, {-523 , -568}, {-195 , 2882}, {-600 , -172}, {-568 , -869}, {-497 , 663}, {-643 , -929}, - {-346 , -378}, {-253 , -313}, {-418 , 595}, {-240 , -465}, {-424 , -546}, {-556 , -305}, {-497 , 2453}, {-451 , -235}, - {-452 , -670}, {-368 , -624}, {-379 , -662}, {-305 , -85}, {-549 , 399}, {-546 , -644}, {-484 , -426}, {-387 , -546}, - {-325 , -550}, {-229 , 118}, { -83 , 1004}, {-120 , 465}, {-289 , -222}, {-516 , 155}, {-480 , 1494}, {-415 , 138}, - {-419 , -100}, {-347 , 1091}, {-434 , 76}, {-138 , -291}, {-434 , -719}, {-514 , 945}, {-473 , -26}, {-144 , -320}, - {-376 , 1505}, {-329 , 374}, {-316 , -504}, { -58 , -6}, {-270 , -466}, {-507 , -540}, {-466 , -181}, {-256 , -518}, - {-196 , 726}, { -88 , -356}, {-186 , -394}, { 31 , -201}, { -77 , -319}, { 408 , 136}, { 630 , 680}, { 875 , 1365}, - {-200 , -190}, { 166 , 1289}, { 600 , 1085}, { 276 , 464}, { 567 , 1575}, { 425 , 278}, { 666 , 377}, {1209 , 2344}, - {-182 , -409}, { -95 , -141}, { 65 , 507}, { 127 , 212}, { 340 , 235}, { 481 , 408}, { 721 , 1203}, {1112 , 756}, - { 162 , 362}, { 138 , 753}, {-169 , -128}, { 187 , -32}, { 68 , -93}, { 528 , 2866}, { 786 , 789}, {1247 , 1468}, - {-476 , 2428}, { 20 , 133}, { 2 , -236}, { 426 , 799}, { 393 , 590}, { 532 , 1562}, { 807 , 534}, {1410 , 1051}, - { -14 , -263}, { 83 , -158}, { 158 , -38}, { 616 , 550}, { 845 , 543}, { 536 , 238}, { 912 , 1521}, {1635 , 1344}, - { 115 , -55}, { 263 , 87}, {-126 , 234}, { 376 , 191}, { 459 , 2644}, { 542 , 927}, { 941 , 948}, {1896 , 1528}, - { -19 , 1853}, { 455 , 366}, { 545 , 283}, { 831 , 835}, {1217 , 846}, { 560 , 542}, {1013 , 650}, {1905 , 2343} - }, - { - {-528 , -246}, {-631 , 56}, {-717 , -277}, { -40 , 1327}, {-1011 , -688}, {-827 , -341}, {-656 , -1599}, { -992 , -1559}, - {-450 , 933}, {-540 , 2109}, {-598 , -1267}, {-387 , -512}, {-1100 , -1979}, {-812 , -617}, {-649 , -147}, { -874 , 586}, - {-720 , - 601}, {-281 , -279}, {-578 , 635}, { 169 , 80}, {-1020 , -134}, {-794 , 259}, {-638 , 821}, { -907 , 42}, - {-709 , -1525}, {-482 , 1340}, {-232 , -979}, { 104 , 2314}, { -918 , -1179}, {-790 , 1284}, {-609 , 2259}, { -854 , -978}, - {-624 , 326}, {-194 , 1705}, { -88 , 1060}, { 383 , 1190}, { -415 , 15}, {-789 , -1145}, {-604 , 407}, { -869 , 1136}, - {-503 , -1047}, {-545 , -794}, {-128 , 471}, { 84 , 638}, { -591 , -1509}, {-699 , 1746}, {-600 , -369}, { -784 , 1642}, - {-221 , -668}, {-223 , 261}, { -82 , -446}, {-378 , -1215}, { -741 , 969}, {-689 , -863}, {-569 , -595}, {-1012 , -403}, - {-331 , 518}, {-175 , 787}, {-220 , -3}, { -46 , -841}, { -960 , 297}, {-666 , 68}, {-565 , -1364}, { -265 , -21}, - { 649 , 767}, { 255 , 360}, { 338 , -342}, {1664 , 1627}, { 205 , -226}, { 967 , 31}, {1217 , 928}, { 1697 , 1233}, - { 322 , 1445}, { 320 , 1790}, { 413 , 212}, { 994 , 209}, { 766 , 264}, { 974 , 883}, {1228 , 241}, { 1679 , 801}, - { 75 , 312}, { 754 , 1425}, { 348 , 621}, { 644 , 474}, { 1008 , 763}, {1036 , 2024}, {1354 , 530}, { 1611 , 2129}, - { 162 , 931}, { 883 , 822}, { 990 , 488}, { 615 , -203}, { 1929 , 1234}, {1059 , 1375}, {1382 , 1426}, { 2048 , 1599}, - { 602 , 162}, { 380 , 820}, { 709 , 1064}, {1168 , 1374}, { 549 , 583}, {1062 , 470}, {1415 , 1092}, { 2095 , 2234}, - { 187 , -630}, { 118 , -493}, { 714 , 1787}, {1298 , 673}, { 957 , 1258}, {1082 , 1124}, {1460 , 786}, { 2124 , 1205}, - { 34 , -189}, { 54 , -35}, { 798 , 0}, { 747 , 2378}, { 1420 , 1152}, {1118 , 1673}, {1492 , 2287}, { 2416 , 1618}, - {1159 , 1795}, { 389 , -126}, {1194 , 1003}, {1578 , 1002}, { 1294 , 366}, {1148 , 694}, {1513 , 1791}, { 2746 , 2096} - } -}; -const Word16 SN_TCVQ_CB_SUB2_fx[2][64][2] = -{ - { - {-709 , -609}, {-615 , -1025}, {-430 , -321}, { -44 , 1032}, {-1050 , -32}, {-1028 , -1856}, {-970 , -109}, { -572 , -1426}, - {-568 , 154}, {-142 , -189}, { -80 , 533}, { -38 , -632}, { -391 , 1275}, { -986 , -732}, {-479 , -510}, { -966 , 96}, - {-847 , -1387}, {-895 , 607}, {-368 , -930}, {-386 , 352}, { -290 , 10}, { -833 , 94}, {-528 , 1718}, { -210 , 115}, - {-529 , 857}, {-727 , -230}, {-128 , 31}, { 133 , 76}, { -275 , -777}, { -615 , -1367}, {-339 , -13}, {-1035 , 1231}, - { 448 , 851}, { 599 , 106}, {1103 , 1112}, { 635 , 1249}, { 761 , 774}, { 531 , -71}, { 722 , 473}, { 767 , 413}, - { 258 , 276}, { 346 , -380}, { 487 , 504}, {1114 , 122}, { 882 , 1553}, { 1983 , 1239}, {2126 , 1217}, { 1742 , 1262}, - { 135 , -252}, { 216 , 545}, { 500 , -125}, {1379 , 1910}, { 304 , 76}, { 1509 , 609}, {1543 , 1385}, { 542 , 1831}, - {-240 , -467}, { 771 , 652}, { 913 , 280}, {1307 , 716}, { 1834 , 1029}, { 1049 , 491}, {1624 , 733}, { 2495 , 1944} - }, - { - {-729 , -852}, {-590 , 306}, {-398 , 295}, { -31 , 13}, {-659 , -75}, {-604 , -1229}, {-519 , -675}, {-823 , 47}, - {-755 , -207}, {-818 , -424}, {-705 , -1285}, {-258 , -828}, {-807 , -707}, {-182 , -712}, {-928 , 3}, {-455 , -1149}, - {-844 , 422}, {-596 , -1008}, {-504 , -470}, {-459 , 737}, {-338 , -728}, {-836 , 1028}, {-613 , 1242}, {-609 , 1292}, - {-285 , 36}, {-280 , -424}, { 100 , 126}, {-459 , -135}, {-159 , -151}, {-287 , 190}, { 56 , -262}, {-264 , -317}, - { -8 , 603}, { 63 , 301}, { 537 , -155}, { 289 , 569}, { 193 , -412}, { 864 , 79}, { 686 , 399}, { 842 , 1657}, - { 115 , -211}, { 608 , 340}, { 12 , -650}, { 711 , 1103}, { 101 , 510}, { 358 , -416}, {1266 , 453}, { 532 , 612}, - {-256 , -680}, { 41 , 1163}, { 597 , 793}, { 484 , -61}, { 476 , 256}, {1729 , 1246}, {1209 , 1483}, {1472 , 1113}, - { 389 , 330}, { 176 , -388}, {1025 , 317}, {1049 , 732}, {1480 , 1108}, {1285 , 616}, {1730 , 999}, {2001 , 1669} - } -}; -const Word16 SN_TCVQ_CB_SUB3_fx[4][32][2] = -{ - { - {-377 , -872}, {-407 , 801}, {-611 , -449}, {-397 , -87}, {-476 , -1063}, {-797 , -249}, {-263 , -662}, {-473 , 1508}, - {-716 , 310}, {-616 , -982}, {-742 , -1326}, { 197 , 327}, {-894 , -1556}, {-871 , -1259}, {-708 , -1380}, {-789 , -848}, - { 64 , -313}, { -59 , -547}, { -2 , 67}, { 363 , -167}, { 633 , 1840}, { 232 , -357}, {1243 , 1492}, {1640 , 973}, - { 203 , 518}, { 511 , 946}, { 612 , 241}, {1085 , 724}, { 811 , 326}, { 863 , 241}, { 556 , 534}, {1956 , 2087} - }, - { - {-948 , 28}, {-827 , -1180}, {-348 , -331}, { -36 , 216}, {-1453 , -1162}, {-682 , -639}, {-747 , -1517}, {-704 , 1228}, - {-535 , -988}, {-550 , -109}, {-478 , 580}, {-310 , -699}, {-1308 , -225}, {-775 , -1581}, {-831 , -613}, {-120 , -222}, - { 32 , 200}, { 120 , -221}, { 470 , 466}, { 808 , 313}, { 950 , 711}, { 430 , -576}, {1984 , 1405}, {1645 , 887}, - { 131 , 1148}, { 286 , 508}, { 342 , -236}, {1003 , 1202}, { 317 , -726}, {1493 , 732}, {1336 , 694}, {2382 , 1772} - }, - { - {-874 , -374}, {-237 , 26}, { 15 , 870}, {-710 , 433}, { 40 , -769}, {-1059 , -1350}, { 65 , 208}, {-1012 , -1369}, - { -79 , -459}, {-671 , -942}, { -12 , 56}, {-162 , -431}, {-820 , -1073}, { -886 , -136}, {-327 , -501}, { -55 , -14}, - { 652 , 647}, { 365 , 411}, { 614 , 252}, { 154 , 215}, { 12 , 62}, { 226 , 177}, {1689 , 1213}, { 751 , 179}, - { 31 , 182}, { 281 , -291}, {-354 , -642}, { 939 , 924}, { 619 , 90}, { 1675 , 1130}, { 827 , 272}, { 1550 , 1446} - }, - { - {-366 , -916}, {-346 , -234}, {-518 , -140}, { 26 , 305}, {-254 , -92}, {-634 , -976}, {-493 , -1076}, {-334 , -913}, - {-566 , 68}, { 102 , 216}, {-296 , -927}, {-501 , -1030}, {-437 , -1006}, {-146 , -145}, {-211 , -202}, { 62 , 359}, - { 163 , -122}, { 759 , 553}, { 82 , 207}, {-177 , -243}, { 163 , 343}, {1152 , 929}, { 197 , 248}, { 43 , -147}, - { 169 , 371}, {-468 , -1043}, { 686 , 418}, { 563, 245}, {1052 , 843}, { 259 , 341}, {1063 , 637}, { 865 , 654} - } -}; -const Word16 AR_SVQ_CB1_fx[32][8] = /* x2.56 */ -{ - { -1, 4, 16, 4, 45, -110, 10, 167, }, - { -3, 2, 8, -12, -7, 23, 279, -46, }, - { 0, 2, 1, 8, -73, -40, 71, -97, }, - { 0, 2, 42, 74, -39, 72, 27, 8, }, - { 0, 1, 9, -6, 40, -65, -55, -128, }, - { 0, 0, 8, -10, -43, 105, -5, -126, }, - { 0, 0, 12, -3, -98, -18, -88, -73, }, - { 0, 1, -6, -12, -49, -179, -30, -15, }, - { -1, 0, 24, 78, 25, -69, -26, -14, }, - { 0, 1, -1, -29, 23, -65, -126, 34, }, - { 2, -4, -23, -7, -13, -2, -22, -4, }, - { -1, 1, -2, 44, -54, -58, 107, 60, }, - { 0, 1, -3, -15, -54, 97, -100, 41, }, - { 0, -2, -81, 93, -13, 18, -31, -75, }, - { -1, 2, 0, -5, 166, -64, -48, 8, }, - { -2, 0, -27, -108, 36, 3, 12, -80, }, - { 0, 0, 0, 4, 82, -1, 79, 54, }, - { 1, -4, 5, -9, -38, 289, 16, 16, }, - { -1, 2, 6, -68, 61, 67, -31, 100, }, - { 3, -6, 2, -2, -1, -6, -217, 273, }, - { 0, 1, -43, -62, -7, -60, 28, 78, }, - { -1, 2, 10, 0, 76, 84, -55, -45, }, - { -1, -2, 4, 5, -32, 75, 70, 176, }, - { 2, -1, 0, 6, 27, 29, -220, -97, }, - { -1, 1, 90, -56, -10, -16, 29, 8, }, - { -1, 3, -10, 0, 2, -24, 49, -336, }, - { -1, 1, -8, -9, 55, -134, 105, -44, }, - { 0, 1, -16, 69, 51, 40, -51, 98, }, - { 0, 2, -12, -32, -140, 49, 50, 26, }, - { 0, 3, 8, 29, 77, 24, 76, -103, }, - { -1, 2, -24, -18, 7, 100, 94, 5, }, - { 0, -1, 10, 26, -87, -34, -56, 103, } -}; -const Word16 AR_SVQ_CB2_fx[16][8] = /* x2.56 */ -{ - { -37, -59, 208, -88, 54, 58, -16, -24, }, - { 0, -98, 9, -65, -182, -21, 19, 9, }, - { -1, 110, -8, 59, 201, 9, -38, -22, }, - { -1, 40, -22, -183, 46, -162, -38, -6, }, - { 12, 2, -193, 64, -43, -48, 11, 9, }, - { -83, 175, -8, -55, -65, 66, 26, 6, }, - { 29, 3, 2, -10, -100, 293, 75, -12, }, - { 7, -54, -76, -91, 63, 119, -84, -84, }, - { 3, 7, 6, 6, -30, 15, -176, 168, }, - { -10, 45, 26, 57, -92, -68, -117, -134, }, - { 0, -37, -34, -69, 106, 54, 121, 131, }, - { -25, -64, 7, 205, 1, 93, 27, 6, }, - { 64, 28, 51, 8, -7, 18, 27, 0, }, - { -20, 44, 57, 78, -55, -170, 88, 93, }, - { 12, -125, 12, 56, 100, -160, -87, -3, }, - { -7, -18, -7, -6, 36, -54, 175, -176, } -}; - -const Word16 interpol_frac_mid_relaxprev_12k8_fx[NB_SUBFR*3] = { 0, 22938, 9830, - 0, 0, 32767, - 0, 0, 32767, - 0, 0, 32767 - }; - -const Word16 interpol_frac_mid_FEC_fx[NB_SUBFR*3] = { 8192, 18022, 6554, - 0, 22938, 9830, - 0, 14746, 18022, - 0, 0, 32767 - }; - -const Word16 interpol_frac_mid_relaxprev_pred_12k8_fx[NB_SUBFR*3] = { 4915, 22938, 4915, - 1638, 21299, 9830, - 0, 16384, 16384, - 0, 0, 32767 - }; - -const Word16 interpol_frac_mid_relaxprev_16k_fx[NB_SUBFR16k*3] = { 0, 22938, 9830, - 0, 0, 32767, - 0, 0, 32767, - 0, 0, 32767, - 0, 0, 32767 - }; - -const Word16 interpol_frac_mid_16k_FEC_fx[NB_SUBFR16k*3] = { 13107, 13107, 6554, - 0, 26214, 6554, - 0, 21299, 11469, - 0, 4915, 27853, - 0, 0, 32767 - }; - -const Word16 interpol_frac_mid_relaxprev_pred_16k_fx[NB_SUBFR16k*3] = { 4915, 22938, 4915, - 1638, 21299, 9830, - 0, 16384, 16384, - 0, 4915, 27853, - 0, 0, 32767 - }; - -const Word16 filter_LP15_180H_fx[] = /* Sincfilt.m: N=180*2+1, Fmin=0, Fmax=1/15, hann( N )' */ -{ - 16384, 16263, 15904, 15317, 14516, 13524, - 12366, 11073, 9678, 8216, 6723, 5236, - 3790, 2416, 1144, 0, -997, -1831, - -2492, -2976, -3285, -3425, -3408, -3248, - -2966, -2583, -2123, -1610, -1070, -526, - 0, 487, 919, 1281, 1564, 1761, - 1869, 1891, 1830, 1695, 1496, 1244, - 954, 641, 318, 0, -300, -569, - -799, -982, -1113, -1188, -1209, -1176, - -1094, -969, -809, -623, -420, -209, - 0, 198, 377, 531, 653, 741, - 793, 807, 786, 732, 649, 543, - 418, 282, 140, 0, -133, -253, - -356, -438, -497, -531, -540, -526, - -489, -433, -362, -278, -187, -93, - 0, 88, 167, 234, 288, 325, - 347, 352, 342, 317, 280, 233, - 179, 120, 59, 0, -56, -105, - -147, -180, -203, -215, -217, -210, - -194, -170, -141, -107, -72, -35, - 0, 33, 61, 85, 103, 116, - 122, 122, 117, 107, 93, 76, - 58, 38, 19, 0, -17, -31, - -43, -51, -57, -59, -58, -55, - -49, -42, -34, -25, -16, -8, - 0, 7, 12, 16, 19, 20, - 21, 20, 18, 16, 13, 10, - 7, 4, 2, 0, -1, -2, - -3, -3, -3, -3, -2, -2, - -1, -1, 0, 0, 0, 0, - 0 -}; - -const Word16 filter_LP15_180H_13b_fx[6*31] = /*Q13 Sincfilt.m: N=180*2+1, Fmin=0, Fmax=1/12, hann( N )'*/ -{ - 8192, 8132, 7952, 7658, 7258, 6762, - 6183, 5536, 4839, 4108, 3362, 2618, - 1895, 1208, 572, 0, -498, -915, - -1246, -1488, -1643, -1713, -1704, -1624, - -1483, -1291, -1061, -805, -535, -263, - 0, 244, 459, 640, 782, 880, - 935, 945, 915, 848, 748, 622, - 477, 320, 159, 0, -150, -285, - -400, -491, -556, -594, -604, -588, - -547, -485, -405, -312, -210, -104, - 0, 99, 189, 265, 327, 371, - 396, 404, 393, 366, 325, 271, - 209, 141, 70, 0, -66, -127, - -178, -219, -248, -266, -270, -263, - -245, -217, -181, -139, -94, -46, - 0, 44, 83, 117, 144, 163, - 173, 176, 171, 158, 140, 116, - 89, 60, 30, 0, -28, -53, - -74, -90, -101, -108, -109, -105, - -97, -85, -70, -54, -36, -18, - 0, 16, 31, 43, 52, 58, - 61, 61, 58, 53, 47, 38, - 29, 19, 9, 0, -8, -16, - -21, -26, -28, -29, -29, -27, - -25, -21, -17, -13, -8, -4, - 0, 3, 6, 8, 10, 10, - 10, 10, 9, 8, 6, 5, - 3, 2, 1, 0, -1, -1, - -1, -2, -2, -1, -1, -1, - -1, 0, 0, 0, 0, 0, - 0 -}; -const Word16 filter_LP12_180H_fx[] = /* Sincfilt.m: N=180*2+1, Fmin=0, Fmax=1/12, hann( N )' */ -{ - 16384, 16196, 15641, 14741, 13533, 12067, - 10402, 8604, 6742, 4887, 3105, 1459, - 0, -1230, -2202, -2900, -3322, -3478, - -3392, -3095, -2628, -2037, -1371, -676, - 0, 618, 1143, 1550, 1822, 1954, - 1946, 1811, 1565, 1233, 842, 421, - 0, -394, -736, -1008, -1196, -1294, - -1299, -1217, -1059, -839, -576, -290, - 0, 274, 514, 707, 842, 913, - 920, 865, 755, 600, 413, 208, - 0, -197, -371, -511, -609, -662, - -667, -627, -548, -436, -300, -151, - 0, 143, 270, 371, 443, 481, - 485, 456, 398, 316, 217, 109, - 0, -104, -195, -268, -319, -346, - -348, -326, -284, -225, -155, -78, - 0, 73, 137, 189, 224, 242, - 243, 227, 198, 156, 107, 54, - 0, -50, -94, -128, -151, -163, - -163, -152, -131, -103, -70, -35, - 0, 32, 60, 82, 96, 103, - 102, 95, 81, 64, 43, 21, - 0, -19, -36, -48, -56, -59, - -58, -53, -45, -35, -23, -11, - 0, 10, 18, 24, 28, 29, - 28, 25, 21, 16, 10, 5, - 0, -4, -7, -9, -10, -10, - -9, -8, -6, -5, -3, -1, - 0, 1, 1, 2, 2, 1, - 1, 1, 0, 0, 0, 0, - 0 -}; -const Word16 filter_LP12_180H_13b_fx[] = /*Q13 Sincfilt.m: N=180*2+1, Fmin=0, Fmax=1/12, hann( N )*/ -{ - 8192, 8098, 7820, 7370, 6766, 6033, - 5201, 4302, 3371, 2443, 1553, 729, - 0, -615, -1101, -1450, -1661, -1739, - -1696, -1547, -1314, -1019, -685, -338, - 0, 309, 571, 775, 911, 977, - 973, 905, 783, 616, 421, 210, - 0, -197, -368, -504, -598, -647, - -649, -608, -529, -420, -288, -145, - 0, 137, 257, 353, 421, 457, - 460, 432, 377, 300, 206, 104, - 0, -99, -185, -255, -305, -331, - -333, -314, -274, -218, -150, -76, - 0, 72, 135, 186, 221, 240, - 242, 228, 199, 158, 109, 55, - 0, -52, -97, -134, -159, -173, - -174, -163, -142, -113, -77, -39, - 0, 37, 69, 94, 112, 121, - 121, 114, 99, 78, 53, 27, - 0, -25, -47, -64, -76, -81, - -81, -76, -66, -52, -35, -18, - 0, 16, 30, 41, 48, 52, - 51, 47, 41, 32, 21, 11, - 0, -10, -18, -24, -28, -30, - -29, -27, -23, -17, -12, -6, - 0, 5, 9, 12, 14, 14, - 14, 13, 10, 8, 5, 2, - 0, -2, -4, -5, -5, -5, - -5, -4, -3, -2, -1, -1, - 0, 0, 1, 1, 1, 1, - 0, 0, 0, 0, 0, 0, - 0 -}; - -const Word16 filter_LP24_90H_fx[] = -{ - - 10240, 10208, 10111, 9951, 9731, - 9452, 9119, 8734, 8304, 7834, - 7328, 6794, 6237, 5664, 5081, - 4495, 3913, 3339, 2780, 2241, - 1727, 1242, 791, 376, 0, - -335, -629, -880, -1089, -1256, - -1383, -1471, -1523, -1540, -1527, - -1487, -1422, -1337, -1235, -1119, - -994, -862, -727, -592, -460, - -333, -212, -101, 0, 90, - 167, 232, 285, 325, 354, - 371, 378, 376, 366, 349, - 326, 299, 269, 236, 203, - 171, 139, 109, 81, 56, - 34, 15, 0, -12, -21, - -27, -30, -31, -31, -29, - -26, -22, -18, -14, -10, - -7, -4, -2, -1, 0, - 0, 0, 0, 0, 0, - 0, - 0 - -}; - -const Word16 filter_LP24_90H_13b_fx[] = -{ - - 5120, 5104, 5056, 4976, 4865, - 4726, 4559, 4367, 4152, 3917, - 3664, 3397, 3119, 2832, 2541, - 2248, 1956, 1669, 1390, 1120, - 863, 621, 396, 188, 0, - -168, -315, -440, -545, -628, - -691, -735, -761, -770, -764, - -743, -711, -668, -617, -560, - -497, -431, -364, -296, -230, - -166, -106, -51, 0, 45, - 84, 116, 143, 163, 177, - 186, 189, 188, 183, 174, - 163, 149, 134, 118, 102, - 85, 69, 54, 40, 28, - 17, 8, 0, -6, -10, - -13, -15, -16, -15, -14, - -13, -11, -9, -7, -5, - -3, -2, -1, 0, 0, - 0, 0, 0, 0, 0, - 0, - 0 -}; - -const Word16 filter_LP3_90H_fx[] = /* Sincfilt.m: N=90*2+1, Fmin=0, Fmax=1/3, hann( N )' */ -{ - 16384, 13545, 6766, 0, -3371, -2689, - 0, 1907, 1661, 0, -1314, -1187, - 0, 990, 911, 0, -783, -729, - 0, 638, 598, 0, -529, -499, - 0, 445, 421, 0, -377, -357, - 0, 321, 305, 0, -274, -260, - 0, 234, 221, 0, -199, -188, - 0, 169, 159, 0, -142, -134, - 0, 119, 112, 0, -99, -93, - 0, 81, 76, 0, -66, -61, - 0, 52, 48, 0, -41, -37, - 0, 31, 28, 0, -23, -20, - 0, 16, 14, 0, -10, -9, - 0, 6, 5, 0, -3, -2, - 0, 1, 1, 0, 0, 0, - 0 -}; - -const Word16 filter_LP15_360H_13b_fx[] = /* Sincfilt.m: N=360*2+1, Fmin=0, Fmax=1/15, hann( N )' */ -{ - - 8192, 8132, 7954, 7662, 7265, 6772, 6196, 5552, - 4857, 4127, 3381, 2636, 1911, 1220, 579, 0, - -506, -931, -1269, -1519, -1681, -1757, -1752, -1674, - -1533, -1339, -1104, -840, -560, -276, 0, 258, - 488, 682, 836, 946, 1008, 1024, 996, 927, - 821, 687, 529, 357, 178, 0, -170, -325, - -458, -567, -646, -694, -710, -696, -652, -581, - -489, -379, -257, -129, 0, 124, 238, 338, - 420, 481, 518, 533, 523, 492, 440, 372, - 289, 197, 99, 0, -96, -184, -262, -326, - -374, -405, -417, -410, -386, -346, -293, -228, - -156, -78, 0, 76, 147, 209, 260, 299, - 324, 334, 329, 310, 279, 236, 184, 125, - 63, 0, -62, -119, -169, -211, -243, -263, - -271, -268, -252, -227, -192, -150, -102, -52, - 0, 50, 97, 138, 173, 198, 215, 222, - 219, 207, 186, 157, 123, 84, 42, 0, - -41, -80, -113, -142, -163, -176, -182, -180, - -170, -152, -129, -101, -69, -35, 0, 34, - 65, 93, 116, 133, 144, 149, 147, 139, - 125, 106, 82, 56, 28, 0, -28, -53, - -76, -95, -109, -118, -121, -120, -113, -101, - -86, -67, -46, -23, 0, 22, 43, 61, - 77, 88, 95, 98, 97, 91, 82, 69, - 54, 37, 19, 0, -18, -35, -49, -61, - -70, -76, -78, -77, -73, -65, -55, -43, - -29, -15, 0, 14, 27, 39, 48, 55, - 60, 62, 61, 57, 51, 43, 33, 23, - 11, 0, -11, -21, -30, -37, -43, -46, - -48, -47, -44, -39, -33, -26, -17, -9, - 0, 8, 16, 23, 28, 32, 35, 36, - 35, 33, 29, 25, 19, 13, 6, 0, - -6, -12, -17, -21, -24, -25, -26, -25, - -24, -21, -18, -14, -9, -5, 0, 4, - 8, 12, 14, 16, 18, 18, 17, 16, - 14, 12, 9, 6, 3, 0, -3, -6, - -8, -10, -11, -11, -12, -11, -10, -9, - -8, -6, -4, -2, 0, 2, 3, 5, - 6, 6, 7, 7, 7, 6, 5, 4, - 3, 2, 1, 0, -1, -2, -3, -3, - -3, -3, -3, -3, -3, -3, -2, -2, - -1, 0, 0, 0, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0 - -}; - -const Resampling_cfg_fx resampling_cfg_tbl_fx[] = -{ - /* fin fout up.fac. den.fac. len.out filter coefs. filter mem./2 flags */ - {8000, 12800, 8, 5, 256, filter5_39s320_120_fx, 15, RS_INV_FAC }, - {12800, 8000, 5, 8, 160, filter5_39s320_120_fx, L_FILT_UP8k, RS_INV_FAC }, - {16000, 8000, 6, 12, 160, filter_LP12_180H_fx, 180/6, 0 }, - - {12800, 16000, 15, 12, 320, filter_LP15_180H_fx, L_FILT_UP16k, 0 }, - {12800, 32000, 15, 6, 640, filter_LP15_180H_fx, L_FILT_UP32k, 0 }, - {12800, 48000, 15, 4, 960, filter_LP15_180H_fx, L_FILT_UP48k , 0 }, - - {16000, 12800, 12, 15, 256, filter_LP15_180H_fx, L_FILT16k, 0 }, - {16000, 32000, 12, 6, 640, filter_LP12_180H_fx, L_FILT16k, 0 }, - {16000, 48000, 12, 4, 960, filter_LP12_180H_fx, L_FILT16k, 0 }, - - {32000, 12800, 6, 15, 256, filter_LP15_180H_13b_fx, L_FILT32k, 0 }, - {32000, 16000, 6, 12, 320, filter_LP12_180H_13b_fx, L_FILT32k, 0 }, - {32000, 25600, 12, 15, 512, filter_LP15_360H_13b_fx, L_FILT32k, 0 }, - {32000, 48000, 3, 2, 960, filter_LP3_90H_fx, L_FILT32k, 0 }, - - {48000, 12800, 4, 15, 256, filter_LP15_180H_13b_fx, L_FILT48k, 0 }, - {48000, 16000, 4, 12, 320, filter_LP12_180H_13b_fx, L_FILT48k, 0 }, - {48000, 25600, 8, 15, 512, filter_LP15_360H_13b_fx, L_FILT48k, 0 }, - {48000, 32000, 2, 3, 640, filter_LP3_90H_fx, L_FILT48k, 0 }, - - /* configs with NB 4kHz low-pass */ - {16000, 12800, 12, 15, 256, filter_LP24_90H_fx, L_FILT16k, 0 }, - {32000, 12800, 6, 15, 256, filter_LP24_90H_13b_fx, L_FILT32k, 0 }, - {48000, 12800, 4, 15, 256, filter_LP24_90H_13b_fx, L_FILT48k, 0 }, - { 0, 0, 0, 0, 0, 0, 0, 0 } /* trailing entry (just to calculate the length of this table) */ -}; -/*-------------------------------------------------------------------* - * 1/4 resolution interpolation filter (-3 dB at 0.791*fs/2) - * for fractional pitch search - * Used in lib_enc\pit_enc.c Q14 - *-------------------------------------------------------------------*/ -const Word16 inter4_1_fx[32] = -{ - -12, -26, 32, 206, - 420, 455, 73, -766, - -1732, -2142,-1242, 1376, - 5429, 9910,13418,14746, - 13418, 9910, 5429, 1376, - -1242, -2142,-1732, -766, - 73, 455, 420, 206, - 32, -26, -12, 0 -}; -const Word16 CNG_burst_att_fx[6][8] = -{ - {30076, 27793, 25832, 24129, 22637, 21319, 20146, 19095}, - {29714, 27181, 25046, 23222, 21646, 20270, 20205, 20205}, - {29415, 26685, 24418, 22506, 22410, 22410, 22410, 22410}, - {29310, 26512, 24201, 23198, 23198, 23198, 23198, 23198}, - {29310, 26512, 24201, 23198, 23198, 23198, 23198, 23198}, - {29789, 27307, 25206, 23406, 21845, 20480, 19661, 19661} -}; -/* 2.0 - 6.4 kHz phase dispersion */ -const Word16 Low_H_phasedisp[L_SUBFR]= -{ - 16389, 16381, 16386, 16382, 16382, 16383, 16381, 16384, 16385, 10265, - 10154, 9894, 14052, 16343, -531, 13216, 16373, 15510, 9407, 15949, - 4726, 14593, 10404, 9796, -16336, -1815,-10623, 12647, 14556,-12683, - 11389, 8176, 16382,-14197, 11781, 10379, 7516, 10424,-12472, 16285, - -1200,-13137, 12659, -7446, 15684, -3763,-13418, -5280, 521, -9685, - -16375, -1219, 8436,-13059, -12861,-12775, 0, 3, 0, -2, - -1, -1, -1, 2 -}; - -/* 3.2 - 6.4 kHz phase dispersion */ -const Word16 Mid_H_phasedisp[L_SUBFR]= -{ - 16382, 16382, 16384, 16385, 16386, 16388, 16387, 16383, 16387, 16383, - 16386, 16386, 16386, 16384, 16382, 16388, 14847, 9629, 13249, 14487, - 10995, 643, 13818, 13779, 6468, 8665, 11634, 9781,-14636, -982, - 11746, -722, 16386,-16365, -11422, 16354, 7363, 13148,-11538,-13903, - -15051, -8862, 8812,-16371, -12146, 7661, -9637,-13253, -6922, 4, - -4, -1, -5, 1, 7, 6, -7, -1, 4, -4, - 0, -1, -3, 3 -}; -/* phase table needed in FFT */ -const Word16 phs_tbl_dec[64*2] = -{ - /* part of table that is not scaled by 2 */ - 16384, 0, 16305, -1606, 16069, -3196, 15678, -4756, 15136, -6270, - 14449, -7723, 13622, -9102, 12665, -10394, 11585, -11585, 10394, -12665, - 9102, -13622, 7723, -14449, 6270, -15136, 4756, -15678, 3196, -16069, - 1606, -16305, 0, -16384, -1606, -16305, -3196, -16069, -4756, -15678, - -6270, -15136, -7723, -14449, -9102, -13622, -10394, -12665, -11585, -11585, - -12665, -10394, -13622, -9102, -14449, -7723, -15136, -6270, -15678, -4756, - -16069, -3196, -16305, -1606, - /* part of table that is scaled by 2 (this save one operation in FFT inner loops) */ - 32767, 0, 32610, -3212, 32138, -6392, 31356, -9512, 30272, -12540, - 28898, -15446, 27244, -18204, 25330, -20788, 23170, -23170, 20788, -25330, - 18204, -27244, 15446, -28898, 12540, -30272, 9512, -31356, 6392, -32138, - 3212, -32610, 0, -32768, -3212, -32610, -6392, -32138, -9512, -31356, - -12540, -30272, -15446, -28898, -18204, -27244, -20788, -25330, -23170, -23170, - -25330, -20788, -27244, -18204, -28898, -15446, -30272, -12540, -31356, -9512, - -32138, -6392, -32610, -3212 -}; - -const Word16 FFT_W64[(64*2)*2] = -{ - 16384, 0, 16364, -804, 16305, -1606, 16207, -2404, - 16069, -3196, 15893, -3981, 15679, -4756, 15426, -5520, - 15137, -6270, 14811, -7005, 14449, -7723, 14053, -8423, - 13623, -9102, 13160, -9760, 12665, -10394, 12140, -11003, - 11585, -11585, 11003, -12140, 10394, -12665, 9760, -13160, - 9102, -13623, 8423, -14053, 7723, -14449, 7005, -14811, - 6270, -15137, 5520, -15426, 4756, -15679, 3981, -15893, - 3196, -16069, 2404, -16207, 1606, -16305, 804, -16364, - 0, -16384, -804, -16364, -1606, -16305, -2404, -16207, - -3196, -16069, -3981, -15893, -4756, -15679, -5520, -15426, - -6270, -15137, -7005, -14811, -7723, -14449, -8423, -14053, - -9102, -13623, -9760, -13160, -10394, -12665, -11003, -12140, - -11585, -11585, -12140, -11003, -12665, -10394, -13160, -9760, - -13623, -9102, -14053, -8423, -14449, -7723, -14811, -7005, - -15137, -6270, -15426, -5520, -15679, -4756, -15893, -3981, - -16069, -3196, -16207, -2404, -16305, -1606, -16364, -804, - /* The following is a duplication of the above but scaled up by a factor of 2. - * This save one operation in inverse FFT inner loops */ - 32767, 0, 32729, -1608, 32610, -3212, 32413, -4808, - 32138, -6393, 31786, -7962, 31357, -9512, 30853, -11039, - 30274, -12540, 29622, -14010, 28899, -15447, 28106, -16846, - 27246, -18205, 26320, -19520, 25330, -20788, 24279, -22006, - 23170, -23170, 22006, -24279, 20788, -25330, 19520, -26320, - 18205, -27246, 16846, -28106, 15447, -28899, 14010, -29622, - 12540, -30274, 11039, -30853, 9512, -31357, 7962, -31786, - 6393, -32138, 4808, -32413, 3212, -32610, 1608, -32729, - 0, -32768, -1608, -32729, -3212, -32610, -4808, -32413, - -6393, -32138, -7962, -31786, -9512, -31357, -11039, -30853, - -12540, -30274, -14010, -29622, -15447, -28899, -16846, -28106, - -18205, -27246, -19520, -26320, -20788, -25330, -22006, -24279, - -23170, -23170, -24279, -22006, -25330, -20788, -26320, -19520, - -27246, -18205, -28106, -16846, -28899, -15447, -29622, -14010, - -30274, -12540, -30853, -11039, -31357, -9512, -31786, -7962, - -32138, -6393, -32413, -4808, -32610, -3212, -32729, -1608 -}; - -const Word16 FFT_W128[] = -{ - /* part of table that is not scaled by 2 */ - 16384, 0, 16379, -402, 16364, -804, 16339, -1205, - 16305, -1606, 16260, -2006, 16206, -2404, 16142, -2801, - 16069, -3196, 15985, -3590, 15893, -3981, 15790, -4370, - 15678, -4756, 15557, -5139, 15426, -5519, 15286, -5896, - 15136, -6270, 14978, -6639, 14811, -7005, 14634, -7366, - 14449, -7723, 14255, -8075, 14053, -8423, 13842, -8765, - 13622, -9102, 13395, -9434, 13159, -9760, 12916, -10080, - 12665, -10394, 12406, -10701, 12139, -11002, 11866, -11297, - 11585, -11585, 11297, -11866, 11002, -12139, 10701, -12406, - 10394, -12665, 10080, -12916, 9760, -13159, 9434, -13395, - 9102, -13622, 8765, -13842, 8423, -14053, 8075, -14255, - 7723, -14449, 7366, -14634, 7005, -14811, 6639, -14978, - 6270, -15136, 5896, -15286, 5519, -15426, 5139, -15557, - 4756, -15678, 4370, -15790, 3981, -15893, 3590, -15985, - 3196, -16069, 2801, -16142, 2404, -16206, 2006, -16260, - 1606, -16305, 1205, -16339, 804, -16364, 402, -16379, - 0, -16384, -402, -16379, -804, -16364, -1205, -16339, - -1606, -16305, -2006, -16260, -2404, -16206, -2801, -16142, - -3196, -16069, -3590, -15985, -3981, -15893, -4370, -15790, - -4756, -15678, -5139, -15557, -5519, -15426, -5896, -15286, - -6270, -15136, -6639, -14978, -7005, -14811, -7366, -14634, - -7723, -14449, -8075, -14255, -8423, -14053, -8765, -13842, - -9102, -13622, -9434, -13395, -9760, -13159, -10080, -12916, - -10394, -12665, -10701, -12406, -11002, -12139, -11297, -11866, - -11585, -11585, -11866, -11297, -12139, -11002, -12406, -10701, - -12665, -10394, -12916, -10080, -13159, -9760, -13395, -9434, - -13622, -9102, -13842, -8765, -14053, -8423, -14255, -8075, - -14449, -7723, -14634, -7366, -14811, -7005, -14978, -6639, - -15136, -6270, -15286, -5896, -15426, -5519, -15557, -5139, - -15678, -4756, -15790, -4370, -15893, -3981, -15985, -3590, - -16069, -3196, -16142, -2801, -16206, -2404, -16260, -2006, - -16305, -1606, -16339, -1205, -16364, -804, -16379, -402, - /* part of table that is scaled by 2 (this save one operation in FFT inner loops) */ - 32767, 0, 32758, -804, 32728, -1608, 32678, -2410, - 32610, -3212, 32520, -4012, 32412, -4808, 32284, -5602, - 32138, -6392, 31970, -7180, 31786, -7962, 31580, -8740, - 31356, -9512, 31114, -10278, 30852, -11038, 30572, -11792, - 30272, -12540, 29956, -13278, 29622, -14010, 29268, -14732, - 28898, -15446, 28510, -16150, 28106, -16846, 27684, -17530, - 27244, -18204, 26790, -18868, 26318, -19520, 25832, -20160, - 25330, -20788, 24812, -21402, 24278, -22004, 23732, -22594, - 23170, -23170, 22594, -23732, 22004, -24278, 21402, -24812, - 20788, -25330, 20160, -25832, 19520, -26318, 18868, -26790, - 18204, -27244, 17530, -27684, 16846, -28106, 16150, -28510, - 15446, -28898, 14732, -29268, 14010, -29622, 13278, -29956, - 12540, -30272, 11792, -30572, 11038, -30852, 10278, -31114, - 9512, -31356, 8740, -31580, 7962, -31786, 7180, -31970, - 6392, -32138, 5602, -32284, 4808, -32412, 4012, -32520, - 3212, -32610, 2410, -32678, 1608, -32728, 804, -32758, - 0, -32768, -804, -32758, -1608, -32728, -2410, -32678, - -3212, -32610, -4012, -32520, -4808, -32412, -5602, -32284, - -6392, -32138, -7180, -31970, -7962, -31786, -8740, -31580, - -9512, -31356, -10278, -31114, -11038, -30852, -11792, -30572, - -12540, -30272, -13278, -29956, -14010, -29622, -14732, -29268, - -15446, -28898, -16150, -28510, -16846, -28106, -17530, -27684, - -18204, -27244, -18868, -26790, -19520, -26318, -20160, -25832, - -20788, -25330, -21402, -24812, -22004, -24278, -22594, -23732, - -23170, -23170, -23732, -22594, -24278, -22004, -24812, -21402, - -25330, -20788, -25832, -20160, -26318, -19520, -26790, -18868, - -27244, -18204, -27684, -17530, -28106, -16846, -28510, -16150, - -28898, -15446, -29268, -14732, -29622, -14010, -29956, -13278, - -30272, -12540, -30572, -11792, -30852, -11038, -31114, -10278, - -31356, -9512, -31580, -8740, -31786, -7962, -31970, -7180, - -32138, -6392, -32284, -5602, -32412, -4808, -32520, -4012, - -32610, -3212, -32678, -2410, -32728, -1608, -32758, -804 -}; - -const Word16 FFT_W256[(256*2)*2] = -{ - /* Each adjacent pair represents the real and imaginary part of a complex number: */ - /* W = exp{-j*(PI*n/256)} = cos(PI*n/256)*16384 -j*sin(PI*n/256)*16384 for n=0, 1, ..., 255. */ - 16384, 0, 16383, -201, 16379, -402, 16373, -603, - 16364, -804, 16353, -1005, 16340, -1205, 16324, -1406, - 16305, -1606, 16284, -1806, 16261, -2006, 16235, -2205, - 16207, -2404, 16176, -2603, 16143, -2801, 16107, -2999, - 16069, -3196, 16029, -3393, 15986, -3590, 15941, -3786, - 15893, -3981, 15843, -4176, 15791, -4370, 15736, -4563, - 15679, -4756, 15619, -4948, 15557, -5139, 15493, -5330, - 15426, -5520, 15357, -5708, 15286, -5897, 15213, -6084, - 15137, -6270, 15059, -6455, 14978, -6639, 14896, -6823, - 14811, -7005, 14724, -7186, 14635, -7366, 14543, -7545, - 14449, -7723, 14354, -7900, 14256, -8076, 14155, -8250, - 14053, -8423, 13949, -8595, 13842, -8765, 13733, -8935, - 13623, -9102, 13510, -9269, 13395, -9434, 13279, -9598, - 13160, -9760, 13039, -9921, 12916, -10080, 12792, -10238, - 12665, -10394, 12537, -10549, 12406, -10702, 12274, -10853, - 12140, -11003, 12004, -11151, 11866, -11297, 11727, -11442, - 11585, -11585, 11442, -11727, 11297, -11866, 11151, -12004, - 11003, -12140, 10853, -12274, 10702, -12406, 10549, -12537, - 10394, -12665, 10238, -12792, 10080, -12916, 9921, -13039, - 9760, -13160, 9598, -13279, 9434, -13395, 9269, -13510, - 9102, -13623, 8935, -13733, 8765, -13842, 8595, -13949, - 8423, -14053, 8250, -14155, 8076, -14256, 7900, -14354, - 7723, -14449, 7545, -14543, 7366, -14635, 7186, -14724, - 7005, -14811, 6823, -14896, 6639, -14978, 6455, -15059, - 6270, -15137, 6084, -15213, 5897, -15286, 5708, -15357, - 5520, -15426, 5330, -15493, 5139, -15557, 4948, -15619, - 4756, -15679, 4563, -15736, 4370, -15791, 4176, -15843, - 3981, -15893, 3786, -15941, 3590, -15986, 3393, -16029, - 3196, -16069, 2999, -16107, 2801, -16143, 2603, -16176, - 2404, -16207, 2205, -16235, 2006, -16261, 1806, -16284, - 1606, -16305, 1406, -16324, 1205, -16340, 1005, -16353, - 804, -16364, 603, -16373, 402, -16379, 201, -16383, - 0, -16384, -201, -16383, -402, -16379, -603, -16373, - -804, -16364, -1005, -16353, -1205, -16340, -1406, -16324, - -1606, -16305, -1806, -16284, -2006, -16261, -2205, -16235, - -2404, -16207, -2603, -16176, -2801, -16143, -2999, -16107, - -3196, -16069, -3393, -16029, -3590, -15986, -3786, -15941, - -3981, -15893, -4176, -15843, -4370, -15791, -4563, -15736, - -4756, -15679, -4948, -15619, -5139, -15557, -5330, -15493, - -5520, -15426, -5708, -15357, -5897, -15286, -6084, -15213, - -6270, -15137, -6455, -15059, -6639, -14978, -6823, -14896, - -7005, -14811, -7186, -14724, -7366, -14635, -7545, -14543, - -7723, -14449, -7900, -14354, -8076, -14256, -8250, -14155, - -8423, -14053, -8595, -13949, -8765, -13842, -8935, -13733, - -9102, -13623, -9269, -13510, -9434, -13395, -9598, -13279, - -9760, -13160, -9921, -13039, -10080, -12916, -10238, -12792, - -10394, -12665, -10549, -12537, -10702, -12406, -10853, -12274, - -11003, -12140, -11151, -12004, -11297, -11866, -11442, -11727, - -11585, -11585, -11727, -11442, -11866, -11297, -12004, -11151, - -12140, -11003, -12274, -10853, -12406, -10702, -12537, -10549, - -12665, -10394, -12792, -10238, -12916, -10080, -13039, -9921, - -13160, -9760, -13279, -9598, -13395, -9434, -13510, -9269, - -13623, -9102, -13733, -8935, -13842, -8765, -13949, -8595, - -14053, -8423, -14155, -8250, -14256, -8076, -14354, -7900, - -14449, -7723, -14543, -7545, -14635, -7366, -14724, -7186, - -14811, -7005, -14896, -6823, -14978, -6639, -15059, -6455, - -15137, -6270, -15213, -6084, -15286, -5897, -15357, -5708, - -15426, -5520, -15493, -5330, -15557, -5139, -15619, -4948, - -15679, -4756, -15736, -4563, -15791, -4370, -15843, -4176, - -15893, -3981, -15941, -3786, -15986, -3590, -16029, -3393, - -16069, -3196, -16107, -2999, -16143, -2801, -16176, -2603, - -16207, -2404, -16235, -2205, -16261, -2006, -16284, -1806, - -16305, -1606, -16324, -1406, -16340, -1205, -16353, -1005, - -16364, -804, -16373, -603, -16379, -402, -16383, -201, - - /* The following is a duplication of the above but scaled up by a factor of 2. - * This save one operation in inverse FFT inner loops */ - 32767, 0, 32766, -402, 32758, -804, 32746, -1206, - 32729, -1608, 32706, -2009, 32679, -2411, 32647, -2811, - 32610, -3212, 32568, -3612, 32522, -4011, 32470, -4410, - 32413, -4808, 32352, -5205, 32286, -5602, 32214, -5998, - 32138, -6393, 32058, -6787, 31972, -7180, 31881, -7571, - 31786, -7962, 31686, -8351, 31581, -8740, 31471, -9127, - 31357, -9512, 31238, -9896, 31114, -10279, 30986, -10660, - 30853, -11039, 30715, -11417, 30572, -11793, 30425, -12167, - 30274, -12540, 30118, -12910, 29957, -13279, 29792, -13646, - 29622, -14010, 29448, -14373, 29269, -14733, 29086, -15091, - 28899, -15447, 28707, -15800, 28511, -16151, 28311, -16500, - 28106, -16846, 27897, -17190, 27684, -17531, 27467, -17869, - 27246, -18205, 27020, -18538, 26791, -18868, 26557, -19195, - 26320, -19520, 26078, -19841, 25833, -20160, 25583, -20475, - 25330, -20788, 25073, -21097, 24812, -21403, 24548, -21706, - 24279, -22006, 24008, -22302, 23732, -22595, 23453, -22884, - 23170, -23170, 22884, -23453, 22595, -23732, 22302, -24008, - 22006, -24279, 21706, -24548, 21403, -24812, 21097, -25073, - 20788, -25330, 20475, -25583, 20160, -25833, 19841, -26078, - 19520, -26320, 19195, -26557, 18868, -26791, 18538, -27020, - 18205, -27246, 17869, -27467, 17531, -27684, 17190, -27897, - 16846, -28106, 16500, -28311, 16151, -28511, 15800, -28707, - 15447, -28899, 15091, -29086, 14733, -29269, 14373, -29448, - 14010, -29622, 13646, -29792, 13279, -29957, 12910, -30118, - 12540, -30274, 12167, -30425, 11793, -30572, 11417, -30715, - 11039, -30853, 10660, -30986, 10279, -31114, 9896, -31238, - 9512, -31357, 9127, -31471, 8740, -31581, 8351, -31686, - 7962, -31786, 7571, -31881, 7180, -31972, 6787, -32058, - 6393, -32138, 5998, -32214, 5602, -32286, 5205, -32352, - 4808, -32413, 4410, -32470, 4011, -32522, 3612, -32568, - 3212, -32610, 2811, -32647, 2411, -32679, 2009, -32706, - 1608, -32729, 1206, -32746, 804, -32758, 402, -32766, - 0, -32768, -402, -32766, -804, -32758, -1206, -32746, - -1608, -32729, -2009, -32706, -2411, -32679, -2811, -32647, - -3212, -32610, -3612, -32568, -4011, -32522, -4410, -32470, - -4808, -32413, -5205, -32352, -5602, -32286, -5998, -32214, - -6393, -32138, -6787, -32058, -7180, -31972, -7571, -31881, - -7962, -31786, -8351, -31686, -8740, -31581, -9127, -31471, - -9512, -31357, -9896, -31238, -10279, -31114, -10660, -30986, - -11039, -30853, -11417, -30715, -11793, -30572, -12167, -30425, - -12540, -30274, -12910, -30118, -13279, -29957, -13646, -29792, - -14010, -29622, -14373, -29448, -14733, -29269, -15091, -29086, - -15447, -28899, -15800, -28707, -16151, -28511, -16500, -28311, - -16846, -28106, -17190, -27897, -17531, -27684, -17869, -27467, - -18205, -27246, -18538, -27020, -18868, -26791, -19195, -26557, - -19520, -26320, -19841, -26078, -20160, -25833, -20475, -25583, - -20788, -25330, -21097, -25073, -21403, -24812, -21706, -24548, - -22006, -24279, -22302, -24008, -22595, -23732, -22884, -23453, - -23170, -23170, -23453, -22884, -23732, -22595, -24008, -22302, - -24279, -22006, -24548, -21706, -24812, -21403, -25073, -21097, - -25330, -20788, -25583, -20475, -25833, -20160, -26078, -19841, - -26320, -19520, -26557, -19195, -26791, -18868, -27020, -18538, - -27246, -18205, -27467, -17869, -27684, -17531, -27897, -17190, - -28106, -16846, -28311, -16500, -28511, -16151, -28707, -15800, - -28899, -15447, -29086, -15091, -29269, -14733, -29448, -14373, - -29622, -14010, -29792, -13646, -29957, -13279, -30118, -12910, - -30274, -12540, -30425, -12167, -30572, -11793, -30715, -11417, - -30853, -11039, -30986, -10660, -31114, -10279, -31238, -9896, - -31357, -9512, -31471, -9127, -31581, -8740, -31686, -8351, - -31786, -7962, -31881, -7571, -31972, -7180, -32058, -6787, - -32138, -6393, -32214, -5998, -32286, -5602, -32352, -5205, - -32413, -4808, -32470, -4410, -32522, -4011, -32568, -3612, - -32610, -3212, -32647, -2811, -32679, -2411, -32706, -2009, - -32729, -1608, -32746, -1206, -32758, -804, -32766, -402 -}; - -const Word16 FFT_W512[(512*2)*2] = -{ - 16384, 0, 16384, -101, 16383, -201, 16381, -302, - 16379, -402, 16376, -503, 16373, -603, 16369, -704, - 16364, -804, 16359, -904, 16353, -1005, 16347, -1105, - 16340, -1205, 16332, -1306, 16324, -1406, 16315, -1506, - 16305, -1606, 16295, -1706, 16284, -1806, 16273, -1906, - 16261, -2006, 16248, -2105, 16235, -2205, 16221, -2305, - 16207, -2404, 16192, -2503, 16176, -2603, 16160, -2702, - 16143, -2801, 16125, -2900, 16107, -2999, 16088, -3098, - 16069, -3196, 16049, -3295, 16029, -3393, 16008, -3492, - 15986, -3590, 15964, -3688, 15941, -3786, 15917, -3883, - 15893, -3981, 15868, -4078, 15843, -4176, 15817, -4273, - 15791, -4370, 15763, -4467, 15736, -4563, 15707, -4660, - 15679, -4756, 15649, -4852, 15619, -4948, 15588, -5044, - 15557, -5139, 15525, -5235, 15493, -5330, 15460, -5425, - 15426, -5520, 15392, -5614, 15357, -5708, 15322, -5803, - 15286, -5897, 15250, -5990, 15213, -6084, 15175, -6177, - 15137, -6270, 15098, -6363, 15059, -6455, 15019, -6547, - 14978, -6639, 14937, -6731, 14896, -6823, 14854, -6914, - 14811, -7005, 14768, -7096, 14724, -7186, 14680, -7276, - 14635, -7366, 14589, -7456, 14543, -7545, 14497, -7635, - 14449, -7723, 14402, -7812, 14354, -7900, 14305, -7988, - 14256, -8076, 14206, -8163, 14155, -8250, 14104, -8337, - 14053, -8423, 14001, -8509, 13949, -8595, 13896, -8680, - 13842, -8765, 13788, -8850, 13733, -8935, 13678, -9019, - 13623, -9102, 13567, -9186, 13510, -9269, 13453, -9352, - 13395, -9434, 13337, -9516, 13279, -9598, 13219, -9679, - 13160, -9760, 13100, -9841, 13039, -9921, 12978, -10001, - 12916, -10080, 12854, -10159, 12792, -10238, 12729, -10316, - 12665, -10394, 12601, -10471, 12537, -10549, 12472, -10625, - 12406, -10702, 12340, -10778, 12274, -10853, 12207, -10928, - 12140, -11003, 12072, -11077, 12004, -11151, 11935, -11224, - 11866, -11297, 11797, -11370, 11727, -11442, 11656, -11514, - 11585, -11585, 11514, -11656, 11442, -11727, 11370, -11797, - 11297, -11866, 11224, -11935, 11151, -12004, 11077, -12072, - 11003, -12140, 10928, -12207, 10853, -12274, 10778, -12340, - 10702, -12406, 10625, -12472, 10549, -12537, 10471, -12601, - 10394, -12665, 10316, -12729, 10238, -12792, 10159, -12854, - 10080, -12916, 10001, -12978, 9921, -13039, 9841, -13100, - 9760, -13160, 9679, -13219, 9598, -13279, 9516, -13337, - 9434, -13395, 9352, -13453, 9269, -13510, 9186, -13567, - 9102, -13623, 9019, -13678, 8935, -13733, 8850, -13788, - 8765, -13842, 8680, -13896, 8595, -13949, 8509, -14001, - 8423, -14053, 8337, -14104, 8250, -14155, 8163, -14206, - 8076, -14256, 7988, -14305, 7900, -14354, 7812, -14402, - 7723, -14449, 7635, -14497, 7545, -14543, 7456, -14589, - 7366, -14635, 7276, -14680, 7186, -14724, 7096, -14768, - 7005, -14811, 6914, -14854, 6823, -14896, 6731, -14937, - 6639, -14978, 6547, -15019, 6455, -15059, 6363, -15098, - 6270, -15137, 6177, -15175, 6084, -15213, 5990, -15250, - 5897, -15286, 5803, -15322, 5708, -15357, 5614, -15392, - 5520, -15426, 5425, -15460, 5330, -15493, 5235, -15525, - 5139, -15557, 5044, -15588, 4948, -15619, 4852, -15649, - 4756, -15679, 4660, -15707, 4563, -15736, 4467, -15763, - 4370, -15791, 4273, -15817, 4176, -15843, 4078, -15868, - 3981, -15893, 3883, -15917, 3786, -15941, 3688, -15964, - 3590, -15986, 3492, -16008, 3393, -16029, 3295, -16049, - 3196, -16069, 3098, -16088, 2999, -16107, 2900, -16125, - 2801, -16143, 2702, -16160, 2603, -16176, 2503, -16192, - 2404, -16207, 2305, -16221, 2205, -16235, 2105, -16248, - 2006, -16261, 1906, -16273, 1806, -16284, 1706, -16295, - 1606, -16305, 1506, -16315, 1406, -16324, 1306, -16332, - 1205, -16340, 1105, -16347, 1005, -16353, 904, -16359, - 804, -16364, 703, -16369, 603, -16373, 503, -16376, - 402, -16379, 302, -16381, 201, -16383, 101, -16384, - 0, -16384, -101, -16384, -201, -16383, -302, -16381, - -402, -16379, -503, -16376, -603, -16373, -704, -16369, - -804, -16364, -904, -16359, -1005, -16353, -1105, -16347, - -1205, -16340, -1306, -16332, -1406, -16324, -1506, -16315, - -1606, -16305, -1706, -16295, -1806, -16284, -1906, -16273, - -2006, -16261, -2105, -16248, -2205, -16235, -2305, -16221, - -2404, -16207, -2503, -16192, -2603, -16176, -2702, -16160, - -2801, -16143, -2900, -16125, -2999, -16107, -3098, -16088, - -3196, -16069, -3295, -16049, -3393, -16029, -3492, -16008, - -3590, -15986, -3688, -15964, -3786, -15941, -3883, -15917, - -3981, -15893, -4078, -15868, -4176, -15843, -4273, -15817, - -4370, -15791, -4467, -15763, -4563, -15736, -4660, -15707, - -4756, -15679, -4852, -15649, -4948, -15619, -5044, -15588, - -5139, -15557, -5235, -15525, -5330, -15493, -5425, -15460, - -5520, -15426, -5614, -15392, -5708, -15357, -5803, -15322, - -5897, -15286, -5990, -15250, -6084, -15213, -6177, -15175, - -6270, -15137, -6363, -15098, -6455, -15059, -6547, -15019, - -6639, -14978, -6731, -14937, -6823, -14896, -6914, -14854, - -7005, -14811, -7096, -14768, -7186, -14724, -7276, -14680, - -7366, -14635, -7456, -14589, -7545, -14543, -7635, -14497, - -7723, -14449, -7812, -14402, -7900, -14354, -7988, -14305, - -8076, -14256, -8163, -14206, -8250, -14155, -8337, -14104, - -8423, -14053, -8509, -14001, -8595, -13949, -8680, -13896, - -8765, -13842, -8850, -13788, -8935, -13733, -9019, -13678, - -9102, -13623, -9186, -13567, -9269, -13510, -9352, -13453, - -9434, -13395, -9516, -13337, -9598, -13279, -9679, -13219, - -9760, -13160, -9841, -13100, -9921, -13039, -10001, -12978, - -10080, -12916, -10159, -12854, -10238, -12792, -10316, -12729, - -10394, -12665, -10471, -12601, -10549, -12537, -10625, -12472, - -10702, -12406, -10778, -12340, -10853, -12274, -10928, -12207, - -11003, -12140, -11077, -12072, -11151, -12004, -11224, -11935, - -11297, -11866, -11370, -11797, -11442, -11727, -11514, -11656, - -11585, -11585, -11656, -11514, -11727, -11442, -11797, -11370, - -11866, -11297, -11935, -11224, -12004, -11151, -12072, -11077, - -12140, -11003, -12207, -10928, -12274, -10853, -12340, -10778, - -12406, -10702, -12472, -10625, -12537, -10549, -12601, -10471, - -12665, -10394, -12729, -10316, -12792, -10238, -12854, -10159, - -12916, -10080, -12978, -10001, -13039, -9921, -13100, -9840, - -13160, -9760, -13219, -9679, -13279, -9598, -13337, -9516, - -13395, -9434, -13453, -9352, -13510, -9269, -13567, -9186, - -13623, -9102, -13678, -9019, -13733, -8935, -13788, -8850, - -13842, -8765, -13896, -8680, -13949, -8595, -14001, -8509, - -14053, -8423, -14104, -8337, -14155, -8250, -14206, -8163, - -14256, -8076, -14305, -7988, -14354, -7900, -14402, -7812, - -14449, -7723, -14497, -7635, -14543, -7545, -14589, -7456, - -14635, -7366, -14680, -7276, -14724, -7186, -14768, -7096, - -14811, -7005, -14854, -6914, -14896, -6823, -14937, -6731, - -14978, -6639, -15019, -6547, -15059, -6455, -15098, -6363, - -15137, -6270, -15175, -6177, -15213, -6084, -15250, -5990, - -15286, -5897, -15322, -5803, -15357, -5708, -15392, -5614, - -15426, -5520, -15460, -5425, -15493, -5330, -15525, -5235, - -15557, -5139, -15588, -5044, -15619, -4948, -15649, -4852, - -15679, -4756, -15707, -4660, -15736, -4563, -15763, -4467, - -15791, -4370, -15817, -4273, -15843, -4176, -15868, -4078, - -15893, -3981, -15917, -3883, -15941, -3786, -15964, -3688, - -15986, -3590, -16008, -3492, -16029, -3393, -16049, -3295, - -16069, -3196, -16088, -3098, -16107, -2999, -16125, -2900, - -16143, -2801, -16160, -2702, -16176, -2603, -16192, -2503, - -16207, -2404, -16221, -2305, -16235, -2205, -16248, -2105, - -16261, -2006, -16273, -1906, -16284, -1806, -16295, -1706, - -16305, -1606, -16315, -1506, -16324, -1406, -16332, -1306, - -16340, -1205, -16347, -1105, -16353, -1005, -16359, -904, - -16364, -804, -16369, -703, -16373, -603, -16376, -503, - -16379, -402, -16381, -302, -16383, -201, -16384, -101, - /* The following is a duplication of the above but scaled up by a factor of 2. - * This save one operation in inverse FFT inner loops */ - 32767, 0, 32767, -201, 32766, -402, 32762, -603, - 32758, -804, 32753, -1005, 32746, -1206, 32738, -1407, - 32729, -1608, 32718, -1809, 32706, -2009, 32693, -2210, - 32679, -2411, 32664, -2611, 32647, -2811, 32629, -3012, - 32610, -3212, 32590, -3412, 32568, -3612, 32546, -3812, - 32522, -4011, 32496, -4211, 32470, -4410, 32442, -4609, - 32413, -4808, 32383, -5007, 32352, -5205, 32319, -5404, - 32286, -5602, 32251, -5800, 32214, -5998, 32177, -6195, - 32138, -6393, 32099, -6590, 32058, -6787, 32015, -6983, - 31972, -7180, 31927, -7376, 31881, -7571, 31834, -7767, - 31786, -7962, 31737, -8157, 31686, -8351, 31634, -8546, - 31581, -8740, 31527, -8933, 31471, -9127, 31415, -9319, - 31357, -9512, 31298, -9704, 31238, -9896, 31177, -10088, - 31114, -10279, 31050, -10469, 30986, -10660, 30920, -10850, - 30853, -11039, 30784, -11228, 30715, -11417, 30644, -11605, - 30572, -11793, 30499, -11980, 30425, -12167, 30350, -12354, - 30274, -12540, 30196, -12725, 30118, -12910, 30038, -13095, - 29957, -13279, 29875, -13463, 29792, -13646, 29707, -13828, - 29622, -14010, 29535, -14192, 29448, -14373, 29359, -14553, - 29269, -14733, 29178, -14912, 29086, -15091, 28993, -15269, - 28899, -15447, 28803, -15624, 28707, -15800, 28610, -15976, - 28511, -16151, 28411, -16326, 28311, -16500, 28209, -16673, - 28106, -16846, 28002, -17018, 27897, -17190, 27791, -17361, - 27684, -17531, 27576, -17700, 27467, -17869, 27357, -18037, - 27246, -18205, 27133, -18372, 27020, -18538, 26906, -18703, - 26791, -18868, 26674, -19032, 26557, -19195, 26439, -19358, - 26320, -19520, 26199, -19681, 26078, -19841, 25956, -20001, - 25833, -20160, 25708, -20318, 25583, -20475, 25457, -20632, - 25330, -20788, 25202, -20943, 25073, -21097, 24943, -21251, - 24812, -21403, 24680, -21555, 24548, -21706, 24414, -21856, - 24279, -22006, 24144, -22154, 24008, -22302, 23870, -22449, - 23732, -22595, 23593, -22740, 23453, -22884, 23312, -23028, - 23170, -23170, 23028, -23312, 22884, -23453, 22740, -23593, - 22595, -23732, 22449, -23870, 22302, -24008, 22154, -24144, - 22006, -24279, 21856, -24414, 21706, -24548, 21555, -24680, - 21403, -24812, 21251, -24943, 21097, -25073, 20943, -25202, - 20788, -25330, 20632, -25457, 20475, -25583, 20318, -25708, - 20160, -25833, 20001, -25956, 19841, -26078, 19681, -26199, - 19520, -26320, 19358, -26439, 19195, -26557, 19032, -26674, - 18868, -26791, 18703, -26906, 18538, -27020, 18372, -27133, - 18205, -27246, 18037, -27357, 17869, -27467, 17700, -27576, - 17531, -27684, 17361, -27791, 17190, -27897, 17018, -28002, - 16846, -28106, 16673, -28209, 16500, -28311, 16326, -28411, - 16151, -28511, 15976, -28610, 15800, -28707, 15624, -28803, - 15447, -28899, 15269, -28993, 15091, -29086, 14912, -29178, - 14733, -29269, 14553, -29359, 14373, -29448, 14192, -29535, - 14010, -29622, 13828, -29707, 13646, -29792, 13463, -29875, - 13279, -29957, 13095, -30038, 12910, -30118, 12725, -30196, - 12540, -30274, 12354, -30350, 12167, -30425, 11980, -30499, - 11793, -30572, 11605, -30644, 11417, -30715, 11228, -30784, - 11039, -30853, 10850, -30920, 10660, -30986, 10469, -31050, - 10279, -31114, 10088, -31177, 9896, -31238, 9704, -31298, - 9512, -31357, 9319, -31415, 9127, -31471, 8933, -31527, - 8740, -31581, 8546, -31634, 8351, -31686, 8157, -31737, - 7962, -31786, 7767, -31834, 7571, -31881, 7376, -31927, - 7180, -31972, 6983, -32015, 6787, -32058, 6590, -32099, - 6393, -32138, 6195, -32177, 5998, -32214, 5800, -32251, - 5602, -32286, 5404, -32319, 5205, -32352, 5007, -32383, - 4808, -32413, 4609, -32442, 4410, -32470, 4211, -32496, - 4011, -32522, 3812, -32546, 3612, -32568, 3412, -32590, - 3212, -32610, 3012, -32629, 2811, -32647, 2611, -32664, - 2411, -32679, 2210, -32693, 2009, -32706, 1809, -32718, - 1608, -32729, 1407, -32738, 1206, -32746, 1005, -32753, - 804, -32758, 603, -32762, 402, -32766, 201, -32767, - 0, -32768, -201, -32767, -402, -32766, -603, -32762, - -804, -32758, -1005, -32753, -1206, -32746, -1407, -32738, - -1608, -32729, -1809, -32718, -2009, -32706, -2210, -32693, - -2411, -32679, -2611, -32664, -2811, -32647, -3012, -32629, - -3212, -32610, -3412, -32590, -3612, -32568, -3812, -32546, - -4011, -32522, -4211, -32496, -4410, -32470, -4609, -32442, - -4808, -32413, -5007, -32383, -5205, -32352, -5404, -32319, - -5602, -32286, -5800, -32251, -5998, -32214, -6195, -32177, - -6393, -32138, -6590, -32099, -6787, -32058, -6983, -32015, - -7180, -31972, -7376, -31927, -7571, -31881, -7767, -31834, - -7962, -31786, -8157, -31737, -8351, -31686, -8546, -31634, - -8740, -31581, -8933, -31527, -9127, -31471, -9319, -31415, - -9512, -31357, -9704, -31298, -9896, -31238, -10088, -31177, - -10279, -31114, -10469, -31050, -10660, -30986, -10850, -30920, - -11039, -30853, -11228, -30784, -11417, -30715, -11605, -30644, - -11793, -30572, -11980, -30499, -12167, -30425, -12354, -30350, - -12540, -30274, -12725, -30196, -12910, -30118, -13095, -30038, - -13279, -29957, -13463, -29875, -13646, -29792, -13828, -29707, - -14010, -29622, -14192, -29535, -14373, -29448, -14553, -29359, - -14733, -29269, -14912, -29178, -15091, -29086, -15269, -28993, - -15447, -28899, -15624, -28803, -15800, -28707, -15976, -28610, - -16151, -28511, -16326, -28411, -16500, -28311, -16673, -28209, - -16846, -28106, -17018, -28002, -17190, -27897, -17361, -27791, - -17531, -27684, -17700, -27576, -17869, -27467, -18037, -27357, - -18205, -27246, -18372, -27133, -18538, -27020, -18703, -26906, - -18868, -26791, -19032, -26674, -19195, -26557, -19358, -26439, - -19520, -26320, -19681, -26199, -19841, -26078, -20001, -25956, - -20160, -25833, -20318, -25708, -20475, -25583, -20632, -25457, - -20788, -25330, -20943, -25202, -21097, -25073, -21251, -24943, - -21403, -24812, -21555, -24680, -21706, -24548, -21856, -24414, - -22006, -24279, -22154, -24144, -22302, -24008, -22449, -23870, - -22595, -23732, -22740, -23593, -22884, -23453, -23028, -23312, - -23170, -23170, -23312, -23028, -23453, -22884, -23593, -22740, - -23732, -22595, -23870, -22449, -24008, -22302, -24144, -22154, - -24279, -22006, -24414, -21856, -24548, -21706, -24680, -21555, - -24812, -21403, -24943, -21251, -25073, -21097, -25202, -20943, - -25330, -20788, -25457, -20632, -25583, -20475, -25708, -20318, - -25833, -20160, -25956, -20001, -26078, -19841, -26199, -19681, - -26320, -19520, -26439, -19358, -26557, -19195, -26674, -19032, - -26791, -18868, -26906, -18703, -27020, -18538, -27133, -18372, - -27246, -18205, -27357, -18037, -27467, -17869, -27576, -17700, - -27684, -17531, -27791, -17361, -27897, -17190, -28002, -17018, - -28106, -16846, -28209, -16673, -28311, -16500, -28411, -16326, - -28511, -16151, -28610, -15976, -28707, -15800, -28803, -15624, - -28899, -15447, -28993, -15269, -29086, -15091, -29178, -14912, - -29269, -14733, -29359, -14553, -29448, -14373, -29535, -14192, - -29622, -14010, -29707, -13828, -29792, -13646, -29875, -13463, - -29957, -13279, -30038, -13095, -30118, -12910, -30196, -12725, - -30274, -12540, -30350, -12354, -30425, -12167, -30499, -11980, - -30572, -11793, -30644, -11605, -30715, -11417, -30784, -11228, - -30853, -11039, -30920, -10850, -30986, -10660, -31050, -10469, - -31114, -10279, -31177, -10088, -31238, -9896, -31298, -9704, - -31357, -9512, -31415, -9319, -31471, -9127, -31527, -8933, - -31581, -8740, -31634, -8546, -31686, -8351, -31737, -8157, - -31786, -7962, -31834, -7767, -31881, -7571, -31927, -7376, - -31972, -7180, -32015, -6983, -32058, -6787, -32099, -6590, - -32138, -6393, -32177, -6195, -32214, -5998, -32251, -5800, - -32286, -5602, -32319, -5404, -32352, -5205, -32383, -5007, - -32413, -4808, -32442, -4609, -32470, -4410, -32496, -4211, - -32522, -4011, -32546, -3812, -32568, -3612, -32590, -3412, - -32610, -3212, -32629, -3012, -32647, -2811, -32664, -2611, - -32679, -2411, -32693, -2210, -32706, -2009, -32718, -1809, - -32729, -1608, -32738, -1407, -32746, -1206, -32753, -1005, - -32758, -804, -32762, -603, -32766, -402, -32767, -201 -}; - -const Word16 sincos_t_rad3_fx[T_SIN_PI_2+1] = -{ - 0, 134, 268, 402, 536, 670, 804, 938, - 1072, 1206, 1340, 1474, 1608, 1742, 1876, 2009, - 2143, 2277, 2411, 2544, 2678, 2811, 2945, 3078, - 3212, 3345, 3479, 3612, 3745, 3878, 4011, 4144, - 4277, 4410, 4543, 4675, 4808, 4941, 5073, 5205, - 5338, 5470, 5602, 5734, 5866, 5998, 6130, 6261, - 6393, 6524, 6655, 6787, 6918, 7049, 7180, 7310, - 7441, 7571, 7702, 7832, 7962, 8092, 8222, 8351, - 8481, 8610, 8740, 8869, 8998, 9127, 9255, 9384, - 9512, 9640, 9768, 9896, 10024, 10151, 10279, 10406, - 10533, 10660, 10786, 10913, 11039, 11165, 11291, 11417, - 11543, 11668, 11793, 11918, 12043, 12167, 12292, 12416, - 12540, 12664, 12787, 12910, 13033, 13156, 13279, 13401, - 13524, 13646, 13767, 13889, 14010, 14131, 14252, 14373, - 14493, 14613, 14733, 14852, 14972, 15091, 15210, 15328, - 15447, 15565, 15683, 15800, 15917, 16035, 16151, 16268, - 16384, 16500, 16616, 16731, 16846, 16961, 17075, 17190, - 17304, 17417, 17531, 17644, 17757, 17869, 17981, 18093, - 18205, 18316, 18427, 18538, 18648, 18758, 18868, 18978, - 19087, 19195, 19304, 19412, 19520, 19627, 19735, 19841, - 19948, 20054, 20160, 20265, 20371, 20475, 20580, 20684, - 20788, 20891, 20994, 21097, 21199, 21301, 21403, 21504, - 21605, 21706, 21806, 21906, 22006, 22105, 22204, 22302, - 22400, 22498, 22595, 22692, 22788, 22884, 22980, 23076, - 23170, 23265, 23359, 23453, 23546, 23640, 23732, 23824, - 23916, 24008, 24099, 24189, 24279, 24369, 24459, 24548, - 24636, 24724, 24812, 24900, 24986, 25073, 25159, 25245, - 25330, 25415, 25499, 25583, 25667, 25750, 25833, 25915, - 25997, 26078, 26159, 26239, 26320, 26399, 26478, 26557, - 26635, 26713, 26791, 26868, 26944, 27020, 27096, 27171, - 27246, 27320, 27394, 27467, 27540, 27612, 27684, 27756, - 27827, 27897, 27967, 28037, 28106, 28175, 28243, 28311, - 28378, 28445, 28511, 28577, 28642, 28707, 28771, 28835, - 28899, 28962, 29024, 29086, 29148, 29209, 29269, 29329, - 29389, 29448, 29506, 29564, 29622, 29679, 29736, 29792, - 29847, 29902, 29957, 30011, 30064, 30118, 30170, 30222, - 30274, 30325, 30375, 30425, 30475, 30524, 30572, 30620, - 30668, 30715, 30761, 30807, 30853, 30897, 30942, 30986, - 31029, 31072, 31114, 31156, 31197, 31238, 31278, 31318, - 31357, 31396, 31434, 31471, 31508, 31545, 31581, 31617, - 31651, 31686, 31720, 31753, 31786, 31818, 31850, 31881, - 31912, 31942, 31972, 32001, 32029, 32058, 32085, 32112, - 32138, 32164, 32190, 32214, 32239, 32262, 32286, 32308, - 32330, 32352, 32373, 32393, 32413, 32433, 32452, 32470, - 32488, 32505, 32522, 32538, 32553, 32568, 32583, 32597, - 32610, 32623, 32635, 32647, 32658, 32669, 32679, 32689, - 32698, 32706, 32714, 32722, 32729, 32735, 32741, 32746, - 32750, 32755, 32758, 32761, 32764, 32766, 32767, 32767, - 32767 -}; - -/*----------------------------------------------------------------------------------* - * Sine & Cosine - table for the FFT and IFFT of 1024 points, value range [0 ... sin(-5pi/4)] - * dimension of the table = 641=4*256*(5/8)+1 - *----------------------------------------------------------------------------------*/ -/* every 4th value is identical to sincos_t above, (but sincos_t is also used by swb_tbe_com) a separate table is used */ -const Word16 sincos_t_ext_fx[641] = -{ - 0, 201, 402, 603, 804, 1005, 1206, 1407, - 1608, 1809, 2009, 2210, 2411, 2611, 2811, 3012, - 3212, 3412, 3612, 3812, 4011, 4211, 4410, 4609, - 4808, 5007, 5205, 5404, 5602, 5800, 5998, 6195, - 6393, 6590, 6787, 6983, 7180, 7376, 7571, 7767, - 7962, 8157, 8351, 8546, 8740, 8933, 9127, 9319, - 9512, 9704, 9896, 10088, 10279, 10469, 10660, 10850, - 11039, 11228, 11417, 11605, 11793, 11980, 12167, 12354, - 12540, 12725, 12910, 13095, 13279, 13463, 13646, 13828, - 14010, 14192, 14373, 14553, 14733, 14912, 15091, 15269, - 15447, 15624, 15800, 15976, 16151, 16326, 16500, 16673, - 16846, 17018, 17190, 17361, 17531, 17700, 17869, 18037, - 18205, 18372, 18538, 18703, 18868, 19032, 19195, 19358, - 19520, 19681, 19841, 20001, 20160, 20318, 20475, 20632, - 20788, 20943, 21097, 21251, 21403, 21555, 21706, 21856, - 22006, 22154, 22302, 22449, 22595, 22740, 22884, 23028, - 23170, 23312, 23453, 23593, 23732, 23870, 24008, 24144, - 24279, 24414, 24548, 24680, 24812, 24943, 25073, 25202, - 25330, 25457, 25583, 25708, 25833, 25956, 26078, 26199, - 26320, 26439, 26557, 26674, 26791, 26906, 27020, 27133, - 27246, 27357, 27467, 27576, 27684, 27791, 27897, 28002, - 28106, 28209, 28311, 28411, 28511, 28610, 28707, 28803, - 28899, 28993, 29086, 29178, 29269, 29359, 29448, 29535, - 29622, 29707, 29792, 29875, 29957, 30038, 30118, 30196, - 30274, 30350, 30425, 30499, 30572, 30644, 30715, 30784, - 30853, 30920, 30986, 31050, 31114, 31177, 31238, 31298, - 31357, 31415, 31471, 31527, 31581, 31634, 31686, 31737, - 31786, 31834, 31881, 31927, 31972, 32015, 32058, 32099, - 32138, 32177, 32214, 32251, 32286, 32319, 32352, 32383, - 32413, 32442, 32470, 32496, 32522, 32546, 32568, 32590, - 32610, 32629, 32647, 32664, 32679, 32693, 32706, 32718, - 32729, 32738, 32746, 32753, 32758, 32762, 32766, 32767, - 32767, 32767, 32766, 32762, 32758, 32753, 32746, 32738, - 32729, 32718, 32706, 32693, 32679, 32664, 32647, 32629, - 32610, 32590, 32568, 32546, 32522, 32496, 32470, 32442, - 32413, 32383, 32352, 32319, 32286, 32251, 32214, 32177, - 32138, 32099, 32058, 32015, 31972, 31927, 31881, 31834, - 31786, 31737, 31686, 31634, 31581, 31527, 31471, 31415, - 31357, 31298, 31238, 31177, 31114, 31050, 30986, 30920, - 30853, 30784, 30715, 30644, 30572, 30499, 30425, 30350, - 30274, 30196, 30118, 30038, 29957, 29875, 29792, 29707, - 29622, 29535, 29448, 29359, 29269, 29178, 29086, 28993, - 28899, 28803, 28707, 28610, 28511, 28411, 28311, 28209, - 28106, 28002, 27897, 27791, 27684, 27576, 27467, 27357, - 27246, 27133, 27020, 26906, 26791, 26674, 26557, 26439, - 26320, 26199, 26078, 25956, 25833, 25708, 25583, 25457, - 25330, 25202, 25073, 24943, 24812, 24680, 24548, 24414, - 24279, 24144, 24008, 23870, 23732, 23593, 23453, 23312, - 23170, 23028, 22884, 22740, 22595, 22449, 22302, 22154, - 22006, 21856, 21706, 21555, 21403, 21251, 21097, 20943, - 20788, 20632, 20475, 20318, 20160, 20001, 19841, 19681, - 19520, 19358, 19195, 19032, 18868, 18703, 18538, 18372, - 18205, 18037, 17869, 17700, 17531, 17361, 17190, 17018, - 16846, 16673, 16500, 16326, 16151, 15976, 15800, 15624, - 15447, 15269, 15091, 14912, 14733, 14553, 14373, 14192, - 14010, 13828, 13646, 13463, 13279, 13095, 12910, 12725, - 12540, 12354, 12167, 11980, 11793, 11605, 11417, 11228, - 11039, 10850, 10660, 10469, 10279, 10088, 9896, 9704, - 9512, 9319, 9127, 8933, 8740, 8546, 8351, 8157, - 7962, 7767, 7571, 7376, 7180, 6983, 6787, 6590, - 6393, 6195, 5998, 5800, 5602, 5404, 5205, 5007, - 4808, 4609, 4410, 4211, 4011, 3812, 3612, 3412, - 3212, 3012, 2811, 2611, 2411, 2210, 2009, 1809, - 1608, 1407, 1206, 1005, 804, 603, 402, 201, - 0, -201, -402, -603, -804, -1005, -1206, -1407, - -1608, -1809, -2009, -2210, -2411, -2611, -2811, -3012, - -3212, -3412, -3612, -3812, -4011, -4211, -4410, -4609, - -4808, -5007, -5205, -5404, -5602, -5800, -5998, -6195, - -6393, -6590, -6787, -6983, -7180, -7376, -7571, -7767, - -7962, -8157, -8351, -8546, -8740, -8933, -9127, -9319, - -9512, -9704, -9896, -10088, -10279, -10469, -10660, -10850, - -11039, -11228, -11417, -11605, -11793, -11980, -12167, -12354, - -12540, -12725, -12910, -13095, -13279, -13463, -13646, -13828, - -14010, -14192, -14373, -14553, -14733, -14912, -15091, -15269, - -15447, -15624, -15800, -15976, -16151, -16326, -16500, -16673, - -16846, -17018, -17190, -17361, -17531, -17700, -17869, -18037, - -18205, -18372, -18538, -18703, -18868, -19032, -19195, -19358, - -19520, -19681, -19841, -20001, -20160, -20318, -20475, -20632, - -20788, -20943, -21097, -21251, -21403, -21555, -21706, -21856, - -22006, -22154, -22302, -22449, -22595, -22740, -22884, -23028, - -23028 -}; - -const Word16 FFT_reorder_64[]= -{ - 0, 32, 16, 48, - 8, 40, 24, 56, - 4, 36, 20, 52, - 12, 44, 28, 60, - 2, 34, 18, 50, - 10, 42, 26, 58, - 6, 38, 22, 54, - 14, 46, 30, 62 -}; - -const Word16 FFT_reorder_256[]= -{ - 0, 128, 64, 192, - 32, 160, 96, 224, - 16, 144, 80, 208, - 48, 176, 112, 240, - 8, 136, 72, 200, - 40, 168, 104, 232, - 24, 152, 88, 216, - 56, 184, 120, 248, - 4, 132, 68, 196, - 36, 164, 100, 228, - 20, 148, 84, 212, - 52, 180, 116, 244, - 12, 140, 76, 204, - 44, 172, 108, 236, - 28, 156, 92, 220, - 60, 188, 124, 252, - 2, 130, 66, 194, - 34, 162, 98, 226, - 18, 146, 82, 210, - 50, 178, 114, 242, - 10, 138, 74, 202, - 42, 170, 106, 234, - 26, 154, 90, 218, - 58, 186, 122, 250, - 6, 134, 70, 198, - 38, 166, 102, 230, - 22, 150, 86, 214, - 54, 182, 118, 246, - 14, 142, 78, 206, - 46, 174, 110, 238, - 30, 158, 94, 222, - 62, 190, 126, 254 -}; - -const Word16 FFT_REORDER_128[64] = -{ - 0, 64, 32, 96, 16, 80, 48, 112, - 8, 72, 40, 104, 24, 88, 56, 120, - 4, 68, 36, 100, 20, 84, 52, 116, - 12, 76, 44, 108, 28, 92, 60, 124, - 2, 66, 34, 98, 18, 82, 50, 114, - 10, 74, 42, 106, 26, 90, 58, 122, - 6, 70, 38, 102, 22, 86, 54, 118, - 14, 78, 46, 110, 30, 94, 62, 126 -}; -const Word16 FFT_REORDER_512[256] = -{ - 0, 256, 128, 384, 64, 320, 192, 448, - 32, 288, 160, 416, 96, 352, 224, 480, - 16, 272, 144, 400, 80, 336, 208, 464, - 48, 304, 176, 432, 112, 368, 240, 496, - 8, 264, 136, 392, 72, 328, 200, 456, - 40, 296, 168, 424, 104, 360, 232, 488, - 24, 280, 152, 408, 88, 344, 216, 472, - 56, 312, 184, 440, 120, 376, 248, 504, - 4, 260, 132, 388, 68, 324, 196, 452, - 36, 292, 164, 420, 100, 356, 228, 484, - 20, 276, 148, 404, 84, 340, 212, 468, - 52, 308, 180, 436, 116, 372, 244, 500, - 12, 268, 140, 396, 76, 332, 204, 460, - 44, 300, 172, 428, 108, 364, 236, 492, - 28, 284, 156, 412, 92, 348, 220, 476, - 60, 316, 188, 444, 124, 380, 252, 508, - 2, 258, 130, 386, 66, 322, 194, 450, - 34, 290, 162, 418, 98, 354, 226, 482, - 18, 274, 146, 402, 82, 338, 210, 466, - 50, 306, 178, 434, 114, 370, 242, 498, - 10, 266, 138, 394, 74, 330, 202, 458, - 42, 298, 170, 426, 106, 362, 234, 490, - 26, 282, 154, 410, 90, 346, 218, 474, - 58, 314, 186, 442, 122, 378, 250, 506, - 6, 262, 134, 390, 70, 326, 198, 454, - 38, 294, 166, 422, 102, 358, 230, 486, - 22, 278, 150, 406, 86, 342, 214, 470, - 54, 310, 182, 438, 118, 374, 246, 502, - 14, 270, 142, 398, 78, 334, 206, 462, - 46, 302, 174, 430, 110, 366, 238, 494, - 30, 286, 158, 414, 94, 350, 222, 478, - 62, 318, 190, 446, 126, 382, 254, 510 -}; - -const Word16 FFT_REORDER_1024[512] = -{ - 0, 512, 256, 768, 128, 640, 384, 896, - 64, 576, 320, 832, 192, 704, 448, 960, - 32, 544, 288, 800, 160, 672, 416, 928, - 96, 608, 352, 864, 224, 736, 480, 992, - 16, 528, 272, 784, 144, 656, 400, 912, - 80, 592, 336, 848, 208, 720, 464, 976, - 48, 560, 304, 816, 176, 688, 432, 944, - 112, 624, 368, 880, 240, 752, 496, 1008, - 8, 520, 264, 776, 136, 648, 392, 904, - 72, 584, 328, 840, 200, 712, 456, 968, - 40, 552, 296, 808, 168, 680, 424, 936, - 104, 616, 360, 872, 232, 744, 488, 1000, - 24, 536, 280, 792, 152, 664, 408, 920, - 88, 600, 344, 856, 216, 728, 472, 984, - 56, 568, 312, 824, 184, 696, 440, 952, - 120, 632, 376, 888, 248, 760, 504, 1016, - 4, 516, 260, 772, 132, 644, 388, 900, - 68, 580, 324, 836, 196, 708, 452, 964, - 36, 548, 292, 804, 164, 676, 420, 932, - 100, 612, 356, 868, 228, 740, 484, 996, - 20, 532, 276, 788, 148, 660, 404, 916, - 84, 596, 340, 852, 212, 724, 468, 980, - 52, 564, 308, 820, 180, 692, 436, 948, - 116, 628, 372, 884, 244, 756, 500, 1012, - 12, 524, 268, 780, 140, 652, 396, 908, - 76, 588, 332, 844, 204, 716, 460, 972, - 44, 556, 300, 812, 172, 684, 428, 940, - 108, 620, 364, 876, 236, 748, 492, 1004, - 28, 540, 284, 796, 156, 668, 412, 924, - 92, 604, 348, 860, 220, 732, 476, 988, - 60, 572, 316, 828, 188, 700, 444, 956, - 124, 636, 380, 892, 252, 764, 508, 1020, - 2, 514, 258, 770, 130, 642, 386, 898, - 66, 578, 322, 834, 194, 706, 450, 962, - 34, 546, 290, 802, 162, 674, 418, 930, - 98, 610, 354, 866, 226, 738, 482, 994, - 18, 530, 274, 786, 146, 658, 402, 914, - 82, 594, 338, 850, 210, 722, 466, 978, - 50, 562, 306, 818, 178, 690, 434, 946, - 114, 626, 370, 882, 242, 754, 498, 1010, - 10, 522, 266, 778, 138, 650, 394, 906, - 74, 586, 330, 842, 202, 714, 458, 970, - 42, 554, 298, 810, 170, 682, 426, 938, - 106, 618, 362, 874, 234, 746, 490, 1002, - 26, 538, 282, 794, 154, 666, 410, 922, - 90, 602, 346, 858, 218, 730, 474, 986, - 58, 570, 314, 826, 186, 698, 442, 954, - 122, 634, 378, 890, 250, 762, 506, 1018, - 6, 518, 262, 774, 134, 646, 390, 902, - 70, 582, 326, 838, 198, 710, 454, 966, - 38, 550, 294, 806, 166, 678, 422, 934, - 102, 614, 358, 870, 230, 742, 486, 998, - 22, 534, 278, 790, 150, 662, 406, 918, - 86, 598, 342, 854, 214, 726, 470, 982, - 54, 566, 310, 822, 182, 694, 438, 950, - 118, 630, 374, 886, 246, 758, 502, 1014, - 14, 526, 270, 782, 142, 654, 398, 910, - 78, 590, 334, 846, 206, 718, 462, 974, - 46, 558, 302, 814, 174, 686, 430, 942, - 110, 622, 366, 878, 238, 750, 494, 1006, - 30, 542, 286, 798, 158, 670, 414, 926, - 94, 606, 350, 862, 222, 734, 478, 990, - 62, 574, 318, 830, 190, 702, 446, 958, - 126, 638, 382, 894, 254, 766, 510, 1022 -}; - -const Word16 Gamma_19661_Tbl_fx[] = -{ - 19661, 11797, 7078, 4247, 2548, 1529, 917, 550, 330, 198, 119, 71, 43, 26, 16, 10 -};/*Q15 */ - -/*-----------------------------------------------------------------* - * Transition coding - gain quantization table for g_trans - *-----------------------------------------------------------------*/ -const Word16 tbl_gain_trans_tc_fx[N_GAIN_TC] = -{ - 4588, 11109, 19212, 29862,/*<- Q7 -Q4 ->*/ 5536, 8184, 13115, 24000 -}; -/*-----------------------------------------------------------------* - * Transition coding - table of prototype glottal impulses - *-----------------------------------------------------------------*/ -const Word16 Glottal_cdbk_fx[L_IMPULSE*NUM_IMPULSE] = /*Q13*/ -{ - /* impulse 0 */ - -715, -1690, -2903, -1742, -1295, -4266, - -4893, 1725, 8192, 5812, -628, -1956, - 581, 936, -81, 831, 1517, - - /* impulse 1 */ - -2168, -1356, -404, -2715, -4469, -2164, - -2180, -8058, -9140, 1163, 10343, 6677, - -1758, -2839, 377, 326, -490, - - /* impulse 2 */ - 360, 561, 4184, 2533, -3326, -2549, - 2059, -2112, -9542, -6134, 1307, 124, - -3421, -1465, 475, -886, -1262, - - /* impulse 3 */ - -1294, -715, -184, -1544, -1638, -219, - -3503, -9409, -7955, -1407, -285, -2494, - 305, 4658, 3289, 116, 1488, - - /* impulse 4 */ - 837, 2523, 2444, 2679, 5962, 6935, - -924, -9907, -7565, 643, 1350, -2577, - -2100, -277, -1546, -2279, -882, - - /* impulse 5 */ - -418, -886, -48, -494, -2368, -2060, - -1233, -5271,-10430, -6955, 3301, 7578, - 2599, -1665, -461, 735, -181, - - /* impulse 6 */ - -467, -1865, -1455, -127, -1881, -3776, - 822, 8335, 8192, 863, -2762, -375, - 757, -558, -285, 653, 150, - - /* impulse 7 */ - 1087, 471, -618, 706, 1546, -1605, - -3256, 2396, 8060, 5189, -99, -37, - 1105, -668, -1434, -59, -81 -}; - -/*----------------------------------------------------------------------------------* - * Gaussian codebook - *----------------------------------------------------------------------------------*/ -/*table in Q12*/ -const Word16 gaus_dico_fx[190] = -{ - -399, -125, 523, -466, 305, -658, -809, 47, - -141, -171, -583, -259, 296, 1334, -285, -401, - -478, -418, 140, -540, 177, -1089, 130, -292, - 143, 492, -310, -862, -320, 388, 546, 84, - -1202, 107, 108, 340, 239, -130, 930, 342, - 153, -264, -763, -113, 387, -535, 83, -856, - -361, -421, 120, 396, -367, 640, 817, 222, - -1017, -82, -120, 890, 340, -384, 47, 339, - -505, -430, 161, 979, 890, -267, 104, 508, - -150, -194, 442, 193, 413, -24, 395, -43, - -217, 69, -398, 167, 116, -936, -95, 1466, - -435, 461, 862, -136, -94, 1311, -371, 68, - 134, -296, -156, -564, -48, -487, 647, 315, - 513, -101, -685, -318, -344, -644, -66, 851, - 414, -29, 509, 414, 502, 399, 557, 649, - -299, 750, 546, -756, -12, -365, 593, -707, - 394, -131, -375, -62, -914, -256, -424, 64, - 464, -1140, 280, 91, -83, -288, -550, 389, - 52, -1228, 6, -430, 74, 205, -478, -148, - -592, 282, -73, 1212, 42, 580, -334, 484, - -765, 443, 649, 271, -739, 375, 613, -460, - -208, 235, -120, -49, -311, 605, 875, 521, - 202, -506, -548, -1088, -43, -221, 673, -245, - -27, 469, 353, 53, 744, 275 -}; - -const Word16 Idx_dortft320_16fx[320] = -{ - 0,65,130,195,260,5,70,135,200,265,10,75,140,205,270,15,80,145,210,275,20,85,150,215,280,25,90,155,220,285,30,95, - 160,225,290,35,100,165,230,295,40,105,170,235,300,45,110,175,240,305,50,115,180,245,310,55,120,185,250,315,60,125, - 190,255,256,1,66,131,196,261,6,71,136,201,266,11,76,141,206,271,16,81,146,211,276,21,86,151,216,281,26,91,156,221, - 286,31,96,161,226,291,36,101,166,231,296,41,106,171,236,301,46,111,176,241,306,51,116,181,246,311,56,121,186,251, - 316,61,126,191,192,257,2,67,132,197,262,7,72,137,202,267,12,77,142,207,272,17,82,147,212,277,22,87,152,217,282,27, - 92,157,222,287,32,97,162,227,292,37,102,167,232,297,42,107,172,237,302,47,112,177,242,307,52,117,182,247,312,57,122, - 187,252,317,62,127,128,193,258,3,68,133,198,263,8,73,138,203,268,13,78,143,208,273,18,83,148,213,278,23,88,153,218, - 283,28,93,158,223,288,33,98,163,228,293,38,103,168,233,298,43,108,173,238,303,48,113,178,243,308,53,118,183,248,313, - 58,123,188,253,318,63,64,129,194,259,4,69,134,199,264,9,74,139,204,269,14,79,144,209,274,19,84,149,214,279,24,89,154, - 219,284,29,94,159,224,289,34,99,164,229,294,39,104,169,234,299,44,109,174,239,304,49,114,179,244,309,54,119,184,249, - 314,59,124,189,254,319 -}; -const Word16 Ip_fft128_16fx[10] = {64, 1, 0, 128, 64, 192, 32, 160, 96, 224}; -const Word32 w_fft128_16fx[64] = -{ - 1073741824, 0, 759250112, 759250112, 992008064, 410903232, 410903232, 992008064, - 1053110144, 209476640, 596539008, 892783680, 892783680, 596539008, 209476640, 1053110144, - 1068571456, 105245104, 681174592, 830013632, 946955712, 506158400, 311690816, 1027506880, - 1027506880, 311690816, 506158400, 946955712, 830013632, 681174592, 105245104, 1068571456, - 1072448448, 52686008, 721080960, 795590208, 970651136, 459083776, 361732736, 1010975232, - 1041563136, 260897968, 552013632, 920979072, 862437504, 639627264, 157550640, 1062120192, - 1062120192, 157550640, 639627264, 862437504, 920979072, 552013632, 260897968, 1041563136, - 1010975232, 361732736, 459083776, 970651136, 795590208, 721080960, 52686008, 1072448448, -}; -const Word16 Ip_fft32_16fx[6] = {16,1,0,32,16,48}; -const Word16 Ip_fft64_16fx[6] = {32,1,0,64,32,96}; -const Word16 Odx_fft64_16fx[64] = -{ - 0,59,54,49,44,39,34,29,24,19,14,9,4,63,58,53,48,43,38,33,28,23,18,13,8,3,62,57,52,47,42,37, - 32,27,22,17,12,7,2,61,56,51,46,41,36,31,26,21,16,11,6,1,60,55,50,45,40,35,30,25,20,15,10,5 -}; -const Word32 w_fft64_16fx[32] = -{ - 1073741824, 0, 759250112, 759250112, 992008064, 410903232, 410903232, 992008064, - 1053110144, 209476640, 596539008, 892783680, 892783680, 596539008, 209476640, 1053110144, - 1068571456, 105245104, 681174592, 830013632, 946955712, 506158400, 311690816, 1027506880, - 1027506880, 311690816, 506158400, 946955712, 830013632, 681174592, 105245104, 1068571456, -}; -const Word32 w_fft32_16fx[16] = -{ - 1073741824, 0, 759250113, 759250113, 992008059, 410903236, 410903236, 992008059, - 1053110143, 209476636, 596539003, 892783685, 892783685, 596539003, 209476636, 1053110143 -}; -const Word16 edct_table_320_16fx[320] = -{ - 7747, 7747, 7747, 7746, 7746, 7745, 7744, 7742, - 7741, 7739, 7737, 7735, 7733, 7730, 7728, 7725, - 7722, 7719, 7716, 7712, 7708, 7704, 7700, 7696, - 7692, 7687, 7682, 7677, 7672, 7666, 7661, 7655, - 7649, 7643, 7637, 7630, 7623, 7617, 7610, 7602, - 7595, 7587, 7580, 7572, 7563, 7555, 7547, 7538, - 7529, 7520, 7511, 7501, 7492, 7482, 7472, 7462, - 7451, 7441, 7430, 7419, 7408, 7397, 7386, 7374, - 7362, 7350, 7338, 7326, 7314, 7301, 7288, 7275, - 7262, 7249, 7235, 7221, 7208, 7194, 7179, 7165, - 7150, 7136, 7121, 7106, 7091, 7075, 7060, 7044, - 7028, 7012, 6995, 6979, 6962, 6946, 6929, 6912, - 6894, 6877, 6859, 6842, 6824, 6806, 6787, 6769, - 6750, 6732, 6713, 6694, 6674, 6655, 6635, 6616, - 6596, 6576, 6556, 6535, 6515, 6494, 6473, 6452, - 6431, 6410, 6388, 6367, 6345, 6323, 6301, 6279, - 6257, 6234, 6211, 6189, 6166, 6143, 6119, 6096, - 6072, 6049, 6025, 6001, 5977, 5953, 5928, 5904, - 5879, 5854, 5829, 5804, 5779, 5753, 5728, 5702, - 5676, 5650, 5624, 5598, 5572, 5545, 5518, 5492, - 5465, 5438, 5411, 5383, 5356, 5328, 5301, 5273, - 5245, 5217, 5189, 5160, 5132, 5104, 5075, 5046, - 5017, 4988, 4959, 4930, 4900, 4871, 4841, 4811, - 4781, 4751, 4721, 4691, 4661, 4630, 4600, 4569, - 4538, 4508, 4477, 4446, 4414, 4383, 4352, 4320, - 4288, 4257, 4225, 4193, 4161, 4129, 4097, 4064, - 4032, 3999, 3967, 3934, 3901, 3868, 3835, 3802, - 3769, 3736, 3702, 3669, 3635, 3602, 3568, 3534, - 3500, 3466, 3432, 3398, 3364, 3330, 3295, 3261, - 3226, 3192, 3157, 3122, 3087, 3052, 3017, 2982, - 2947, 2912, 2877, 2841, 2806, 2771, 2735, 2699, - 2664, 2628, 2592, 2556, 2520, 2484, 2448, 2412, - 2376, 2340, 2304, 2267, 2231, 2194, 2158, 2121, - 2085, 2048, 2011, 1975, 1938, 1901, 1864, 1827, - 1790, 1753, 1716, 1679, 1642, 1605, 1567, 1530, - 1493, 1455, 1418, 1381, 1343, 1306, 1268, 1231, - 1193, 1156, 1118, 1080, 1043, 1005, 967, 930, - 892, 854, 816, 778, 740, 703, 665, 627, - 589, 551, 513, 475, 437, 399, 361, 323, - 285, 247, 209, 171, 133, 95, 57, 19 -}; -const Word16 edct_table_128_16fx[128] = /*Q15 */ -{ - 9742, 9740, 9737, 9733, 9727, 9720, 9711, 9701, - 9689, 9676, 9661, 9645, 9627, 9608, 9588, 9566, - 9543, 9518, 9492, 9464, 9435, 9405, 9373, 9339, - 9305, 9269, 9231, 9192, 9152, 9110, 9067, 9023, - 8977, 8930, 8882, 8832, 8781, 8728, 8675, 8619, - 8563, 8505, 8447, 8386, 8325, 8262, 8198, 8133, - 8067, 7999, 7930, 7860, 7789, 7717, 7643, 7568, - 7492, 7415, 7337, 7258, 7178, 7097, 7014, 6931, - 6846, 6761, 6674, 6586, 6498, 6408, 6318, 6226, - 6134, 6040, 5946, 5851, 5755, 5658, 5560, 5462, - 5362, 5262, 5161, 5059, 4957, 4854, 4750, 4645, - 4539, 4433, 4327, 4219, 4111, 4002, 3893, 3783, - 3673, 3562, 3450, 3338, 3226, 3113, 2999, 2885, - 2771, 2656, 2541, 2425, 2309, 2193, 2076, 1959, - 1842, 1724, 1607, 1489, 1370, 1252, 1133, 1014, - 895, 776, 657, 538, 418, 299, 179, 60 -}; -const Word16 edct_table_160_16fx[160] = -{ - 9213, 9212, 9211, 9208, 9204, 9200, 9195, 9188, - 9181, 9173, 9164, 9155, 9144, 9132, 9120, 9107, - 9093, 9078, 9062, 9045, 9027, 9009, 8989, 8969, - 8948, 8926, 8903, 8880, 8855, 8830, 8803, 8776, - 8748, 8719, 8690, 8659, 8628, 8596, 8563, 8529, - 8495, 8459, 8423, 8386, 8348, 8309, 8270, 8230, - 8188, 8147, 8104, 8061, 8016, 7971, 7926, 7879, - 7832, 7784, 7735, 7686, 7635, 7584, 7533, 7480, - 7427, 7373, 7319, 7263, 7207, 7151, 7093, 7035, - 6976, 6917, 6857, 6796, 6735, 6673, 6610, 6547, - 6483, 6418, 6353, 6287, 6221, 6154, 6086, 6018, - 5949, 5880, 5810, 5739, 5668, 5597, 5525, 5452, - 5379, 5305, 5231, 5156, 5081, 5005, 4929, 4852, - 4775, 4698, 4620, 4541, 4462, 4383, 4303, 4223, - 4142, 4061, 3980, 3898, 3816, 3734, 3651, 3568, - 3484, 3400, 3316, 3231, 3146, 3061, 2976, 2890, - 2804, 2718, 2631, 2544, 2457, 2370, 2282, 2195, - 2107, 2019, 1930, 1842, 1753, 1664, 1575, 1486, - 1397, 1307, 1218, 1128, 1038, 948, 858, 768, - 678, 588, 497, 407, 317, 226, 136, 45 -}; - -const Word16 ip_edct2_64_fx[6] = {16, 64, 0, 32, 16, 48}; - -const Word16 w_edct2_64_fx[80] = /*Q14 */ -{ - 16384, 0, 11585, 11585, 15137, 6270, 6270, 15137, - 16069, 3196, 9102, 13623, 13623, 9102, 3196, 16069, - 11585, 8190, 8182, 8170, 8153, 8130, 8103, 8071, - 8035, 7993, 7946, 7895, 7839, 7779, 7713, 7643, - 7568, 7489, 7405, 7317, 7225, 7128, 7027, 6921, - 6811, 6698, 6580, 6458, 6333, 6203, 6070, 5933, - 5793, 5649, 5501, 5351, 5197, 5040, 4880, 4717, - 4551, 4383, 4212, 4038, 3862, 3683, 3503, 3320, - 3135, 2948, 2760, 2570, 2378, 2185, 1990, 1795, - 1598, 1401, 1202, 1003, 803, 603, 402, 201 -}; -/*------------------------------------------------------------------------------* - * FIX POINT EDCT tables - *------------------------------------------------------------------------------*/ -const Word16 edct_table_80_fx[80] = /*Q16 */ -{ - 21911, 21903, 21886, 21860, 21827, 21784, 21734, 21675, - 21608, 21532, 21448, 21356, 21255, 21147, 21030, 20905, - 20772, 20631, 20482, 20325, 20161, 19988, 19808, 19621, - 19425, 19222, 19012, 18795, 18570, 18338, 18099, 17853, - 17600, 17340, 17074, 16801, 16522, 16236, 15944, 15646, - 15341, 15031, 14715, 14394, 14067, 13734, 13396, 13053, - 12705, 12352, 11994, 11632, 11265, 10894, 10519, 10139, - 9756, 9369, 8978, 8584, 8186, 7786, 7382, 6975, - 6566, 6155, 5741, 5324, 4906, 4486, 4064, 3640, - 3215, 2789, 2362, 1934, 1505, 1075, 645, 215 -}; - -const Word16 edct_table_100_fx[] = -{ - 20723, 20718, 20708, 20692, 20672, 20646, 20616, 20580, - 20539, 20493, 20442, 20386, 20325, 20259, 20188, 20112, - 20031, 19946, 19855, 19759, 19658, 19553, 19443, 19328, - 19208, 19083, 18954, 18820, 18681, 18538, 18390, 18238, - 18081, 17920, 17754, 17584, 17410, 17231, 17048, 16861, - 16670, 16474, 16275, 16071, 15864, 15652, 15437, 15218, - 14995, 14768, 14538, 14304, 14067, 13826, 13582, 13335, - 13084, 12830, 12573, 12312, 12049, 11783, 11513, 11241, - 10966, 10689, 10409, 10126, 9841, 9553, 9263, 8971, - 8676, 8379, 8081, 7780, 7477, 7173, 6867, 6559, - 6249, 5938, 5625, 5311, 4996, 4679, 4362, 4043, - 3723, 3403, 3081, 2759, 2436, 2112, 1788, 1464, - 1139, 814, 488, 163 -}; - -const Word16 edct_table_120_fx[120] = /*Q16 */ -{ - 19800, 19797, 19790, 19780, 19766, 19749, 19729, 19705, - 19678, 19648, 19614, 19576, 19536, 19492, 19445, 19394, - 19340, 19283, 19223, 19159, 19092, 19021, 18948, 18871, - 18791, 18708, 18621, 18531, 18438, 18342, 18243, 18141, - 18035, 17927, 17815, 17701, 17583, 17462, 17339, 17212, - 17082, 16950, 16815, 16676, 16535, 16391, 16244, 16095, - 15942, 15787, 15629, 15469, 15306, 15140, 14972, 14801, - 14628, 14452, 14273, 14092, 13909, 13723, 13535, 13345, - 13152, 12958, 12761, 12561, 12360, 12156, 11951, 11743, - 11533, 11322, 11108, 10893, 10675, 10456, 10235, 10012, - 9788, 9562, 9334, 9104, 8874, 8641, 8407, 8172, - 7935, 7697, 7457, 7217, 6975, 6732, 6487, 6242, - 5995, 5748, 5499, 5250, 4999, 4748, 4496, 4243, - 3990, 3736, 3481, 3225, 2969, 2713, 2456, 2199, - 1941, 1683, 1424, 1166, 907, 648, 389, 130 -}; - -const Word16 edct_table_320_fx[320] = /*Q16 */ -{ - 15495, 15495, 15494, 15493, 15491, 15489, 15487, 15484, - 15481, 15478, 15474, 15470, 15466, 15461, 15456, 15450, - 15444, 15438, 15431, 15424, 15417, 15409, 15401, 15392, - 15383, 15374, 15364, 15354, 15344, 15333, 15322, 15310, - 15298, 15286, 15273, 15260, 15247, 15233, 15219, 15205, - 15190, 15175, 15159, 15143, 15127, 15110, 15093, 15076, - 15058, 15040, 15021, 15002, 14983, 14964, 14944, 14924, - 14903, 14882, 14860, 14839, 14817, 14794, 14771, 14748, - 14725, 14701, 14677, 14652, 14627, 14602, 14576, 14550, - 14524, 14497, 14470, 14443, 14415, 14387, 14359, 14330, - 14301, 14271, 14242, 14212, 14181, 14150, 14119, 14088, - 14056, 14024, 13991, 13958, 13925, 13891, 13858, 13823, - 13789, 13754, 13719, 13683, 13647, 13611, 13575, 13538, - 13501, 13463, 13425, 13387, 13349, 13310, 13271, 13231, - 13192, 13152, 13111, 13071, 13030, 12988, 12947, 12905, - 12862, 12820, 12777, 12734, 12690, 12647, 12602, 12558, - 12513, 12468, 12423, 12377, 12331, 12285, 12239, 12192, - 12145, 12098, 12050, 12002, 11954, 11905, 11856, 11807, - 11758, 11708, 11658, 11608, 11557, 11507, 11455, 11404, - 11352, 11301, 11248, 11196, 11143, 11090, 11037, 10983, - 10930, 10876, 10821, 10767, 10712, 10657, 10601, 10546, - 10490, 10434, 10378, 10321, 10264, 10207, 10150, 10092, - 10034, 9976, 9918, 9859, 9800, 9741, 9682, 9623, - 9563, 9503, 9443, 9382, 9322, 9261, 9200, 9138, - 9077, 9015, 8953, 8891, 8829, 8766, 8703, 8640, - 8577, 8513, 8450, 8386, 8322, 8258, 8193, 8129, - 8064, 7999, 7933, 7868, 7802, 7737, 7671, 7604, - 7538, 7471, 7405, 7338, 7271, 7203, 7136, 7068, - 7001, 6933, 6865, 6796, 6728, 6659, 6591, 6522, - 6453, 6383, 6314, 6244, 6175, 6105, 6035, 5965, - 5895, 5824, 5754, 5683, 5612, 5541, 5470, 5399, - 5327, 5256, 5184, 5113, 5041, 4969, 4897, 4824, - 4752, 4680, 4607, 4534, 4462, 4389, 4316, 4243, - 4169, 4096, 4023, 3949, 3876, 3802, 3728, 3654, - 3580, 3506, 3432, 3358, 3284, 3209, 3135, 3060, - 2986, 2911, 2836, 2761, 2687, 2612, 2537, 2462, - 2386, 2311, 2236, 2161, 2085, 2010, 1934, 1859, - 1783, 1708, 1632, 1557, 1481, 1405, 1329, 1254, - 1178, 1102, 1026, 950, 874, 798, 722, 646, - 570, 494, 418, 342, 266, 190, 114, 38 -}; - -const Word16 edct_table_480_fx[480] = /*Q16 */ -{ - 14001, 14001, 14001, 14000, 14000, 13999, 13998, 13997, - 13996, 13995, 13993, 13991, 13990, 13988, 13986, 13983, - 13981, 13978, 13976, 13973, 13970, 13967, 13963, 13960, - 13956, 13953, 13949, 13945, 13940, 13936, 13932, 13927, - 13922, 13917, 13912, 13907, 13902, 13896, 13890, 13885, - 13879, 13872, 13866, 13860, 13853, 13846, 13840, 13833, - 13825, 13818, 13811, 13803, 13795, 13787, 13779, 13771, - 13763, 13754, 13746, 13737, 13728, 13719, 13709, 13700, - 13691, 13681, 13671, 13661, 13651, 13641, 13630, 13620, - 13609, 13598, 13587, 13576, 13565, 13553, 13542, 13530, - 13518, 13506, 13494, 13482, 13469, 13457, 13444, 13431, - 13418, 13405, 13392, 13378, 13365, 13351, 13337, 13323, - 13309, 13295, 13280, 13266, 13251, 13236, 13221, 13206, - 13191, 13175, 13160, 13144, 13128, 13112, 13096, 13080, - 13063, 13047, 13030, 13013, 12996, 12979, 12962, 12944, - 12927, 12909, 12891, 12873, 12855, 12837, 12819, 12800, - 12782, 12763, 12744, 12725, 12706, 12686, 12667, 12647, - 12628, 12608, 12588, 12568, 12547, 12527, 12506, 12486, - 12465, 12444, 12423, 12402, 12380, 12359, 12337, 12316, - 12294, 12272, 12250, 12227, 12205, 12182, 12160, 12137, - 12114, 12091, 12068, 12045, 12021, 11998, 11974, 11950, - 11926, 11902, 11878, 11854, 11829, 11804, 11780, 11755, - 11730, 11705, 11680, 11654, 11629, 11603, 11578, 11552, - 11526, 11500, 11474, 11447, 11421, 11394, 11368, 11341, - 11314, 11287, 11260, 11232, 11205, 11177, 11150, 11122, - 11094, 11066, 11038, 11010, 10981, 10953, 10924, 10895, - 10867, 10838, 10809, 10779, 10750, 10721, 10691, 10662, - 10632, 10602, 10572, 10542, 10512, 10481, 10451, 10420, - 10390, 10359, 10328, 10297, 10266, 10235, 10203, 10172, - 10140, 10109, 10077, 10045, 10013, 9981, 9949, 9917, - 9884, 9852, 9819, 9786, 9754, 9721, 9688, 9654, - 9621, 9588, 9554, 9521, 9487, 9454, 9420, 9386, - 9352, 9318, 9283, 9249, 9214, 9180, 9145, 9111, - 9076, 9041, 9006, 8971, 8935, 8900, 8865, 8829, - 8794, 8758, 8722, 8686, 8650, 8614, 8578, 8542, - 8505, 8469, 8432, 8396, 8359, 8322, 8285, 8248, - 8211, 8174, 8137, 8099, 8062, 8025, 7987, 7949, - 7912, 7874, 7836, 7798, 7760, 7721, 7683, 7645, - 7606, 7568, 7529, 7491, 7452, 7413, 7374, 7335, - 7296, 7257, 7218, 7178, 7139, 7100, 7060, 7020, - 6981, 6941, 6901, 6861, 6821, 6781, 6741, 6701, - 6661, 6620, 6580, 6539, 6499, 6458, 6418, 6377, - 6336, 6295, 6254, 6213, 6172, 6131, 6090, 6048, - 6007, 5966, 5924, 5883, 5841, 5799, 5758, 5716, - 5674, 5632, 5590, 5548, 5506, 5464, 5422, 5379, - 5337, 5295, 5252, 5210, 5167, 5124, 5082, 5039, - 4996, 4953, 4911, 4868, 4825, 4782, 4738, 4695, - 4652, 4609, 4566, 4522, 4479, 4435, 4392, 4348, - 4305, 4261, 4218, 4174, 4130, 4086, 4042, 3999, - 3955, 3911, 3867, 3823, 3778, 3734, 3690, 3646, - 3602, 3557, 3513, 3469, 3424, 3380, 3335, 3291, - 3246, 3202, 3157, 3112, 3068, 3023, 2978, 2933, - 2889, 2844, 2799, 2754, 2709, 2664, 2619, 2574, - 2529, 2484, 2439, 2394, 2349, 2303, 2258, 2213, - 2168, 2122, 2077, 2032, 1986, 1941, 1896, 1850, - 1805, 1759, 1714, 1668, 1623, 1577, 1532, 1486, - 1441, 1395, 1350, 1304, 1258, 1213, 1167, 1121, - 1076, 1030, 984, 939, 893, 847, 801, 756, - 710, 664, 618, 573, 527, 481, 435, 389, - 344, 298, 252, 206, 160, 115, 69, 23 -}; - -const Word16 edct_table_600_fx[] = -{ - 26483, 26483, 26483, 26482, 26481, 26481, 26479, 26478, - 26477, 26475, 26473, 26471, 26469, 26467, 26464, 26461, - 26459, 26455, 26452, 26449, 26445, 26441, 26437, 26433, - 26429, 26424, 26420, 26415, 26410, 26404, 26399, 26393, - 26387, 26381, 26375, 26369, 26362, 26356, 26349, 26342, - 26335, 26327, 26320, 26312, 26304, 26296, 26287, 26279, - 26270, 26261, 26252, 26243, 26234, 26224, 26214, 26204, - 26194, 26184, 26173, 26163, 26152, 26141, 26130, 26118, - 26107, 26095, 26083, 26071, 26059, 26046, 26033, 26021, - 26008, 25994, 25981, 25968, 25954, 25940, 25926, 25912, - 25897, 25883, 25868, 25853, 25838, 25823, 25807, 25791, - 25776, 25760, 25743, 25727, 25711, 25694, 25677, 25660, - 25643, 25625, 25608, 25590, 25572, 25554, 25535, 25517, - 25498, 25480, 25461, 25441, 25422, 25403, 25383, 25363, - 25343, 25323, 25302, 25282, 25261, 25240, 25219, 25198, - 25176, 25155, 25133, 25111, 25089, 25067, 25044, 25022, - 24999, 24976, 24953, 24929, 24906, 24882, 24858, 24834, - 24810, 24786, 24761, 24737, 24712, 24687, 24662, 24636, - 24611, 24585, 24559, 24533, 24507, 24481, 24454, 24427, - 24401, 24373, 24346, 24319, 24291, 24264, 24236, 24208, - 24180, 24151, 24123, 24094, 24065, 24036, 24007, 23978, - 23948, 23918, 23888, 23858, 23828, 23798, 23767, 23737, - 23706, 23675, 23644, 23612, 23581, 23549, 23518, 23486, - 23453, 23421, 23389, 23356, 23323, 23290, 23257, 23224, - 23191, 23157, 23123, 23090, 23056, 23021, 22987, 22953, - 22918, 22883, 22848, 22813, 22778, 22742, 22707, 22671, - 22635, 22599, 22563, 22526, 22490, 22453, 22416, 22379, - 22342, 22305, 22267, 22230, 22192, 22154, 22116, 22078, - 22039, 22001, 21962, 21923, 21884, 21845, 21806, 21766, - 21727, 21687, 21647, 21607, 21567, 21527, 21486, 21446, - 21405, 21364, 21323, 21282, 21241, 21199, 21157, 21116, - 21074, 21032, 20989, 20947, 20905, 20862, 20819, 20776, - 20733, 20690, 20647, 20603, 20560, 20516, 20472, 20428, - 20384, 20339, 20295, 20250, 20205, 20161, 20116, 20070, - 20025, 19980, 19934, 19888, 19842, 19796, 19750, 19704, - 19658, 19611, 19565, 19518, 19471, 19424, 19377, 19329, - 19282, 19234, 19186, 19139, 19091, 19042, 18994, 18946, - 18897, 18849, 18800, 18751, 18702, 18653, 18604, 18554, - 18505, 18455, 18405, 18355, 18305, 18255, 18205, 18154, - 18104, 18053, 18002, 17951, 17900, 17849, 17798, 17747, - 17695, 17643, 17592, 17540, 17488, 17436, 17383, 17331, - 17278, 17226, 17173, 17120, 17067, 17014, 16961, 16908, - 16854, 16801, 16747, 16693, 16640, 16586, 16531, 16477, - 16423, 16368, 16314, 16259, 16204, 16149, 16094, 16039, - 15984, 15929, 15873, 15818, 15762, 15706, 15650, 15595, - 15538, 15482, 15426, 15370, 15313, 15256, 15200, 15143, - 15086, 15029, 14972, 14914, 14857, 14800, 14742, 14684, - 14627, 14569, 14511, 14453, 14395, 14336, 14278, 14220, - 14161, 14103, 14044, 13985, 13926, 13867, 13808, 13749, - 13689, 13630, 13570, 13511, 13451, 13391, 13332, 13272, - 13212, 13151, 13091, 13031, 12971, 12910, 12849, 12789, - 12728, 12667, 12606, 12545, 12484, 12423, 12362, 12300, - 12239, 12177, 12116, 12054, 11992, 11930, 11868, 11806, - 11744, 11682, 11620, 11558, 11495, 11433, 11370, 11307, - 11245, 11182, 11119, 11056, 10993, 10930, 10867, 10803, - 10740, 10677, 10613, 10550, 10486, 10422, 10358, 10295, - 10231, 10167, 10103, 10039, 9974, 9910, 9846, 9781, - 9717, 9652, 9588, 9523, 9458, 9394, 9329, 9264, - 9199, 9134, 9069, 9003, 8938, 8873, 8808, 8742, - 8677, 8611, 8546, 8480, 8414, 8348, 8283, 8217, - 8151, 8085, 8019, 7953, 7886, 7820, 7754, 7688, - 7621, 7555, 7488, 7422, 7355, 7289, 7222, 7155, - 7088, 7022, 6955, 6888, 6821, 6754, 6687, 6620, - 6553, 6485, 6418, 6351, 6283, 6216, 6149, 6081, - 6014, 5946, 5879, 5811, 5743, 5676, 5608, 5540, - 5472, 5404, 5337, 5269, 5201, 5133, 5065, 4997, - 4928, 4860, 4792, 4724, 4656, 4587, 4519, 4451, - 4382, 4314, 4246, 4177, 4109, 4040, 3972, 3903, - 3834, 3766, 3697, 3629, 3560, 3491, 3422, 3354, - 3285, 3216, 3147, 3078, 3009, 2941, 2872, 2803, - 2734, 2665, 2596, 2527, 2458, 2389, 2320, 2251, - 2182, 2112, 2043, 1974, 1905, 1836, 1767, 1697, - 1628, 1559, 1490, 1421, 1351, 1282, 1213, 1144, - 1074, 1005, 936, 867, 797, 728, 659, 589, - 520, 451, 381, 312, 243, 173, 104, 35 -}; - -const Word16 edct_table_128_fx[128] = /*Q16 */ -{ - 19483, 19480, 19474, 19466, 19454, 19439, 19422, 19401, - 19378, 19351, 19322, 19290, 19255, 19217, 19176, 19132, - 19086, 19036, 18984, 18928, 18870, 18809, 18746, 18679, - 18610, 18537, 18462, 18385, 18304, 18221, 18135, 18046, - 17954, 17860, 17763, 17664, 17561, 17457, 17349, 17239, - 17126, 17011, 16893, 16773, 16650, 16524, 16396, 16266, - 16133, 15998, 15860, 15720, 15578, 15433, 15286, 15137, - 14985, 14831, 14675, 14516, 14356, 14193, 14028, 13861, - 13692, 13521, 13348, 13173, 12996, 12816, 12635, 12452, - 12268, 12081, 11892, 11702, 11510, 11316, 11121, 10924, - 10725, 10524, 10322, 10119, 9914, 9707, 9499, 9290, - 9079, 8867, 8653, 8438, 8222, 8005, 7786, 7566, - 7345, 7123, 6900, 6676, 6451, 6225, 5998, 5770, - 5541, 5312, 5081, 4850, 4618, 4385, 4152, 3918, - 3684, 3449, 3213, 2977, 2741, 2504, 2266, 2029, - 1791, 1552, 1314, 1075, 837, 598, 359, 120 -}; - -const Word16 edct_table_160_fx[160] = /*Q16 */ -{ - 18426, 18425, 18421, 18416, 18409, 18400, 18389, 18377, - 18362, 18346, 18329, 18309, 18288, 18265, 18240, 18214, - 18185, 18155, 18123, 18090, 18055, 18018, 17979, 17938, - 17896, 17852, 17806, 17759, 17710, 17659, 17607, 17552, - 17497, 17439, 17380, 17319, 17256, 17192, 17126, 17058, - 16989, 16918, 16846, 16772, 16696, 16619, 16540, 16459, - 16377, 16293, 16208, 16121, 16033, 15943, 15851, 15758, - 15664, 15568, 15470, 15371, 15271, 15169, 15065, 14960, - 14854, 14746, 14637, 14527, 14415, 14301, 14186, 14070, - 13953, 13834, 13714, 13592, 13469, 13345, 13220, 13093, - 12965, 12836, 12706, 12574, 12441, 12307, 12172, 12036, - 11898, 11759, 11620, 11479, 11337, 11193, 11049, 10904, - 10758, 10610, 10462, 10312, 10162, 10011, 9858, 9705, - 9551, 9395, 9239, 9082, 8925, 8766, 8606, 8446, - 8285, 8123, 7960, 7797, 7632, 7467, 7301, 7135, - 6968, 6800, 6632, 6463, 6293, 6122, 5952, 5780, - 5608, 5435, 5262, 5089, 4915, 4740, 4565, 4389, - 4214, 4037, 3861, 3684, 3506, 3328, 3150, 2972, - 2793, 2614, 2435, 2256, 2076, 1896, 1716, 1536, - 1356, 1175, 994, 814, 633, 452, 271, 90 -}; - -const Word16 edct_table_40_fx[40] = /*Q16 */ -{ - 26049, 26009, 25928, 25808, 25648, 25448, 25210, 24932, - 24616, 24262, 23870, 23442, 22977, 22477, 21943, 21375, - 20773, 20140, 19475, 18781, 18058, 17306, 16528, 15725, - 14897, 14047, 13174, 12282, 11370, 10441, 9496, 8536, - 7563, 6578, 5584, 4580, 3570, 2554, 1534, 512 -}; - -const Word16 edct_table_20_fx[20] = /*Q16 */ -{ - 30939, 30749, 30368, 29801, 29049, 28119, 27015, 25745, - 24316, 22737, 21018, 19169, 17202, 15129, 12963, 10717, - 8405, 6041, 3639, 1216 -}; - - -const Word16 edct_table_64_fx[] = -{ - 23167, 23153, 23125, 23083, 23027, 22958, 22874, 22777, - 22666, 22542, 22403, 22252, 22087, 21908, 21717, 21512, - 21295, 21064, 20821, 20565, 20297, 20017, 19725, 19420, - 19105, 18777, 18438, 18089, 17728, 17356, 16975, 16582, - 16180, 15769, 15347, 14917, 14477, 14029, 13572, 13107, - 12634, 12154, 11666, 11171, 10670, 10162, 9648, 9128, - 8603, 8072, 7537, 6997, 6453, 5905, 5353, 4798, - 4241, 3681, 3118, 2554, 1988, 1421, 853, 284 -}; - - -const Word16 edct_table_200_fx[] = -{ - 17427, 17426, 17423, 17420, 17416, 17411, 17404, 17397, - 17388, 17378, 17368, 17356, 17343, 17329, 17314, 17298, - 17281, 17262, 17243, 17223, 17201, 17179, 17155, 17131, - 17105, 17079, 17051, 17022, 16992, 16961, 16929, 16896, - 16862, 16827, 16791, 16754, 16716, 16676, 16636, 16595, - 16553, 16509, 16465, 16420, 16373, 16326, 16278, 16228, - 16178, 16126, 16074, 16021, 15966, 15911, 15855, 15797, - 15739, 15680, 15620, 15558, 15496, 15433, 15369, 15304, - 15238, 15171, 15103, 15035, 14965, 14894, 14823, 14751, - 14677, 14603, 14528, 14452, 14375, 14297, 14218, 14139, - 14058, 13977, 13895, 13812, 13728, 13643, 13558, 13471, - 13384, 13296, 13207, 13117, 13027, 12935, 12843, 12750, - 12657, 12562, 12467, 12371, 12274, 12177, 12078, 11979, - 11880, 11779, 11678, 11576, 11473, 11370, 11266, 11161, - 11055, 10949, 10843, 10735, 10627, 10518, 10409, 10299, - 10188, 10076, 9964, 9852, 9739, 9625, 9510, 9395, - 9280, 9164, 9047, 8930, 8812, 8694, 8575, 8455, - 8335, 8215, 8094, 7973, 7851, 7728, 7605, 7482, - 7358, 7234, 7109, 6984, 6858, 6732, 6606, 6479, - 6352, 6224, 6096, 5967, 5839, 5710, 5580, 5450, - 5320, 5190, 5059, 4928, 4796, 4664, 4532, 4400, - 4268, 4135, 4002, 3868, 3735, 3601, 3467, 3333, - 3198, 3064, 2929, 2794, 2659, 2523, 2388, 2252, - 2116, 1980, 1844, 1708, 1572, 1436, 1299, 1163, - 1026, 889, 753, 616, 479, 342, 205, 68 -}; - -const Word16 edct_table_240_fx[] = -{ - 16650, 16650, 16648, 16646, 16643, 16640, 16635, 16630, - 16625, 16618, 16611, 16603, 16595, 16585, 16575, 16565, - 16553, 16541, 16528, 16515, 16501, 16486, 16470, 16454, - 16437, 16419, 16401, 16381, 16362, 16341, 16320, 16298, - 16275, 16252, 16228, 16203, 16178, 16151, 16125, 16097, - 16069, 16040, 16010, 15980, 15949, 15918, 15885, 15852, - 15819, 15784, 15749, 15713, 15677, 15640, 15602, 15564, - 15525, 15485, 15445, 15404, 15362, 15320, 15277, 15233, - 15189, 15144, 15098, 15052, 15005, 14957, 14909, 14860, - 14811, 14761, 14710, 14659, 14607, 14554, 14501, 14447, - 14392, 14337, 14282, 14225, 14168, 14111, 14053, 13994, - 13934, 13874, 13814, 13753, 13691, 13629, 13566, 13502, - 13438, 13374, 13309, 13243, 13176, 13109, 13042, 12974, - 12905, 12836, 12767, 12696, 12626, 12554, 12482, 12410, - 12337, 12264, 12190, 12115, 12040, 11965, 11889, 11812, - 11735, 11657, 11579, 11501, 11422, 11342, 11262, 11182, - 11101, 11019, 10937, 10855, 10772, 10689, 10605, 10521, - 10436, 10351, 10265, 10179, 10093, 10006, 9919, 9831, - 9743, 9654, 9565, 9476, 9386, 9296, 9205, 9114, - 9023, 8931, 8839, 8746, 8653, 8560, 8466, 8372, - 8278, 8183, 8088, 7993, 7897, 7801, 7704, 7608, - 7511, 7413, 7315, 7217, 7119, 7020, 6921, 6822, - 6723, 6623, 6523, 6422, 6321, 6221, 6119, 6018, - 5916, 5814, 5712, 5609, 5507, 5404, 5300, 5197, - 5093, 4990, 4885, 4781, 4677, 4572, 4467, 4362, - 4257, 4151, 4046, 3940, 3834, 3728, 3622, 3515, - 3408, 3302, 3195, 3088, 2981, 2873, 2766, 2658, - 2551, 2443, 2335, 2227, 2119, 2011, 1903, 1795, - 1686, 1578, 1469, 1361, 1252, 1143, 1035, 926, - 817, 708, 599, 490, 381, 272, 163, 54 -}; - -const Word16 edct_table_256_fx[] = -{ - 16384, 16383, 16382, 16380, 16378, 16375, 16371, 16367, - 16362, 16356, 16350, 16343, 16336, 16328, 16319, 16310, - 16300, 16290, 16278, 16267, 16254, 16242, 16228, 16214, - 16199, 16184, 16168, 16151, 16134, 16116, 16098, 16079, - 16059, 16039, 16018, 15997, 15975, 15952, 15929, 15905, - 15881, 15856, 15830, 15804, 15777, 15750, 15722, 15693, - 15664, 15634, 15604, 15573, 15541, 15509, 15476, 15443, - 15409, 15375, 15340, 15304, 15268, 15231, 15194, 15156, - 15117, 15078, 15039, 14999, 14958, 14917, 14875, 14832, - 14789, 14746, 14702, 14657, 14612, 14566, 14520, 14473, - 14426, 14378, 14329, 14280, 14231, 14181, 14130, 14079, - 14027, 13975, 13922, 13869, 13815, 13761, 13706, 13651, - 13595, 13538, 13481, 13424, 13366, 13308, 13249, 13190, - 13130, 13069, 13008, 12947, 12885, 12823, 12760, 12697, - 12633, 12569, 12504, 12439, 12373, 12307, 12240, 12173, - 12106, 12038, 11969, 11901, 11831, 11762, 11691, 11621, - 11550, 11478, 11406, 11334, 11261, 11188, 11114, 11040, - 10965, 10891, 10815, 10740, 10663, 10587, 10510, 10433, - 10355, 10277, 10198, 10119, 10040, 9961, 9881, 9800, - 9719, 9638, 9557, 9475, 9393, 9310, 9227, 9144, - 9061, 8977, 8892, 8808, 8723, 8638, 8552, 8466, - 8380, 8293, 8206, 8119, 8032, 7944, 7856, 7768, - 7679, 7590, 7501, 7411, 7321, 7231, 7141, 7050, - 6960, 6868, 6777, 6685, 6593, 6501, 6409, 6316, - 6223, 6130, 6037, 5943, 5850, 5756, 5661, 5567, - 5472, 5377, 5282, 5187, 5092, 4996, 4900, 4804, - 4708, 4611, 4515, 4418, 4321, 4224, 4127, 4030, - 3932, 3835, 3737, 3639, 3541, 3442, 3344, 3246, - 3147, 3048, 2949, 2851, 2751, 2652, 2553, 2454, - 2354, 2255, 2155, 2055, 1956, 1856, 1756, 1656, - 1556, 1456, 1356, 1255, 1155, 1055, 954, 854, - 754, 653, 553, 452, 352, 251, 151, 50 -}; - -const Word16 edct_table_400_fx[] = -{ - 29308, 29308, 29307, 29306, 29304, 29302, 29299, 29296, - 29292, 29288, 29284, 29279, 29273, 29267, 29261, 29254, - 29247, 29239, 29231, 29223, 29214, 29204, 29194, 29184, - 29173, 29162, 29150, 29138, 29125, 29112, 29099, 29085, - 29070, 29055, 29040, 29024, 29008, 28991, 28974, 28957, - 28939, 28920, 28901, 28882, 28862, 28842, 28821, 28800, - 28779, 28757, 28734, 28711, 28688, 28664, 28640, 28615, - 28590, 28565, 28539, 28512, 28485, 28458, 28430, 28402, - 28373, 28344, 28315, 28285, 28255, 28224, 28192, 28161, - 28129, 28096, 28063, 28030, 27996, 27962, 27927, 27892, - 27856, 27820, 27784, 27747, 27710, 27672, 27634, 27595, - 27556, 27517, 27477, 27437, 27396, 27355, 27313, 27272, - 27229, 27186, 27143, 27100, 27055, 27011, 26966, 26921, - 26875, 26829, 26782, 26736, 26688, 26640, 26592, 26544, - 26495, 26445, 26395, 26345, 26294, 26243, 26192, 26140, - 26088, 26035, 25982, 25929, 25875, 25821, 25766, 25711, - 25655, 25600, 25543, 25487, 25430, 25372, 25315, 25256, - 25198, 25139, 25079, 25020, 24960, 24899, 24838, 24777, - 24715, 24653, 24591, 24528, 24465, 24401, 24337, 24273, - 24208, 24143, 24078, 24012, 23946, 23879, 23812, 23745, - 23677, 23609, 23541, 23472, 23403, 23334, 23264, 23194, - 23123, 23052, 22981, 22909, 22837, 22765, 22692, 22619, - 22546, 22472, 22398, 22324, 22249, 22174, 22098, 22023, - 21947, 21870, 21793, 21716, 21639, 21561, 21483, 21404, - 21326, 21246, 21167, 21087, 21007, 20927, 20846, 20765, - 20684, 20602, 20520, 20437, 20355, 20272, 20189, 20105, - 20021, 19937, 19852, 19768, 19682, 19597, 19511, 19425, - 19339, 19252, 19165, 19078, 18991, 18903, 18815, 18726, - 18638, 18549, 18459, 18370, 18280, 18190, 18100, 18009, - 17918, 17827, 17735, 17643, 17551, 17459, 17366, 17274, - 17181, 17087, 16994, 16900, 16805, 16711, 16616, 16521, - 16426, 16331, 16235, 16139, 16043, 15946, 15850, 15753, - 15656, 15558, 15461, 15363, 15265, 15166, 15068, 14969, - 14870, 14770, 14671, 14571, 14471, 14371, 14271, 14170, - 14069, 13968, 13867, 13765, 13663, 13562, 13459, 13357, - 13254, 13152, 13049, 12946, 12842, 12739, 12635, 12531, - 12427, 12323, 12218, 12113, 12008, 11903, 11798, 11693, - 11587, 11481, 11375, 11269, 11163, 11056, 10950, 10843, - 10736, 10628, 10521, 10414, 10306, 10198, 10090, 9982, - 9874, 9765, 9657, 9548, 9439, 9330, 9221, 9112, - 9002, 8892, 8783, 8673, 8563, 8453, 8342, 8232, - 8122, 8011, 7900, 7789, 7678, 7567, 7456, 7344, - 7233, 7121, 7010, 6898, 6786, 6674, 6562, 6450, - 6337, 6225, 6112, 6000, 5887, 5774, 5661, 5548, - 5435, 5322, 5209, 5096, 4982, 4869, 4755, 4642, - 4528, 4414, 4300, 4187, 4073, 3959, 3845, 3730, - 3616, 3502, 3388, 3273, 3159, 3044, 2930, 2815, - 2701, 2586, 2472, 2357, 2242, 2127, 2013, 1898, - 1783, 1668, 1553, 1438, 1323, 1208, 1093, 978, - 863, 748, 633, 518, 403, 288, 173, 58 -}; - -const Word16 Ip_fft16_fx[6] = {8,1,0,16,8,24}; -const Word16 w_fft16_fx[8] = {16384, 0, 11585, 11585, 15137, 6270, 6270, 15137}; /*Q14 */ - -const Word16 Ip_fft8_fx[6] = {4,1,0,8,4,12}; -const Word16 w_fft8_fx[4] = {16384, 0, 11585, 11585}; /*Q14 */ - -const Word16 Ip_fft32_fx[6] = {16,1,0,32,16,48}; -const Word16 w_fft32_fx[16] = /*Q14 */ -{ - 16384, 0, 11585, 11585, 15137, 6270, 6270, 15137, - 16069, 3196, 9102, 13623, 13623, 9102, 3196, 16069 -}; - -const Word16 Ip_fft64_fx[6] = {32,1,0,64,32,96}; -const Word16 w_fft64_fx[32] = /*Q14 */ -{ - 16384, 0, 11585, 11585, 15137, 6270, 6270, 15137, - 16069, 3196, 9102, 13623, 13623, 9102, 3196, 16069, - 16305, 1606, 10394, 12665, 14449, 7723, 4756, 15679, - 15679, 4756, 7723, 14449, 12665, 10394, 1606, 16305 -}; - -const Word16 Ip_fft4_fx[6] = {2,1,0,4,2,6}; -const Word16 w_fft4_fx[2] = {16384, 0}; /*Q14 */ - -const Word16 Ip_fft128_fx[10] = {64,1,0,128,64,192,32,160,96,224}; -const Word16 w_fft128_fx[64] = /*Q14 */ -{ - 16384, 0, 11585, 11585, 15137, 6270, 6270, 15137, - 16069, 3196, 9102, 13623, 13623, 9102, 3196, 16069, - 16305, 1606, 10394, 12665, 14449, 7723, 4756, 15679, - 15679, 4756, 7723, 14449, 12665, 10394, 1606, 16305, - 16364, 804, 11003, 12140, 14811, 7005, 5520, 15426, - 15893, 3981, 8423, 14053, 13160, 9760, 2404, 16207, - 16207, 2404, 9760, 13160, 14053, 8423, 3981, 15893, - 15426, 5520, 7005, 14811, 12140, 11003, 804, 16364 -}; - -/* For the general fix point fft implementation */ -const Word16 sincos_t_fx[161] = -{ - /*Q15 */ - 0, - 804, 1607, 2410, 3211, 4011, - 4808, 5602, 6392, 7179, 7961, - 8739, 9512, 10278, 11039, 11793, - 12539, 13278, 14010, 14732, 15446, - 16151, 16846, 17530, 18204, 18868, - 19519, 20159, 20787, 21403, 22005, - 22594, 23170, 23732, 24279, 24812, - 25330, 25832, 26319, 26790, 27245, - 27684, 28106, 28511, 28898, 29269, - 29621, 29956, 30273, 30572, 30852, - 31114, 31357, 31581, 31785, 31971, - 32138, 32285, 32413, 32521, 32610, - 32679, 32728, 32758, 32767, 32758, - 32728, 32679, 32610, 32521, 32413, - 32285, 32138, 31971, 31785, 31581, - 31357, 31114, 30852, 30572, 30273, - 29956, 29621, 29269, 28898, 28511, - 28106, 27684, 27245, 26790, 26319, - 25832, 25330, 24812, 24279, 23732, - 23170, 22594, 22005, 21403, 20787, - 20159, 19519, 18868, 18204, 17530, - 16846, 16151, 15446, 14732, 14010, - 13278, 12539, 11793, 11039, 10278, - 9512, 8739, 7961, 7179, 6392, - 5602, 4808, 4011, 3211, 2410, - 1607, 804, 0, -804, -1607, - -2410, -3211, -4011, -4808, -5602, - -6392, -7179, -7961, -8739, -9512, - -10278, -11039, -11793, -12539, -13278, - -14010, -14732, -15446, -16151, -16846, - -17530, -18204, -18868, -19519, -20159, - -20787, -21403, -22005, -22594, -23170, -}; - -/*------------------------------------------------------------------------------* - * GSC tables - *------------------------------------------------------------------------------*/ - -const Word16 gsc_sfm_start[MBANDS_GN] = {0, 16, 32, 48, 64, 80, 96, 112, 128, 144, 160, 176, 192, 208, 224, 240}; - -const Word16 gsc_sfm_end[MBANDS_GN] = {16, 32, 48, 64, 80, 96, 112, 128, 144, 160, 176, 192, 208, 224, 240, 256}; - -const Word16 gsc_sfm_size[MBANDS_GN] = {16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16}; - - -/*GSC related */ -const Word16 GSC_freq_bits[] = -{ - 21, 66, -6, 25, 15, 11, 10, 5, 0, 0, 5, 4, 0, 0, 4, 0, 0, /* ACELP_7k20*/ - 21, 74, -4, 26, 16, 12, 11, 9, 0, 0, 4, 4, 1, 1, 3, 0, 0, /* ACELP_8k00*/ - 26, 96, -4, 28, 18, 13, 12,10,10, 5, 4, 4, 1, 0, 1, 3, 4, /* ACELP_11k60*/ - 26, 96, -4, 28, 18, 13, 12,10,10, 5, 4, 4, 1, 0, 1, 3, 4, /* ACELP_12k15*/ - 26, 96, -4, 28, 18, 13, 12,10,10, 5, 4, 4, 1, 0, 1, 3, 4, /* ACELP_12k85*/ - 31, 96, -4, 28, 18, 13, 12,10,10, 5, 4, 4, 1, 0, 1, 3, 4, /* ACELP_13k20*/ -}; - -/***IN Q2 ****/ -const Word16 mfreq_loc_Q2fx[] = { 700, 1500, 3100, 4700, 6300, 7900, 9500, 11100, 12700, 14300, 15900, 17500, 19100, 20700, 22300, 25500, 28700, 31900 }; -const Word16 mfreq_loc_div_25[] = {7, 15, 31, 47, 63, 79, 95, 111, 127, 143, 159, 175, 191, 207, 223, 255, 287, 319}; - -const Word16 mfreq_bindiv_loc_fx[] = {8, 8, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 32, 32, 32 }; -/*const Word16 mean_gp_fx[] = {4795}; */ -const Word16 mean_gp_fx[] = {9590}; /*Q14*/ - -const Word16 dic_gp_fx[] = /*Q14*/ -{ - -9580, -7692, -6385, -4474, -3254, -2038, -806, -82, - 1034, 2259, 3457, 4684, 5290, 6544, 8548, 10052, - -8964, -8338, -7021, -5754, -5118, -3850, -2654, -1429, - 408, 1660, 2852, 4071, 5915, 7170, 7825, 9249 -}; - -const Word16 Gain_meanNB_fx[]= -{ - 9852, -};/* Q12 */ - -const Word16 Gain_mean_dicNB_fx[1*64] = /*Q12 */ -{ - -1309, -931, -568, -396, -54, 807, 1174, 1533, - 1901, 2092, 2286, 2493, 2698, 3130, 2909, 286, - -748, 990, 631, -1119, -1697, -2114, -2788, -5399, - -9841, -1902, -3270, -7975, -7438, -6926, -7192, -2325, - -1504, -2549, -3022, -3532, -3818, -4136, -4751, -5071, - -5756, -6093, -8998, -6389, -8765, -9438, 3369, 3917, - 3619, 4684, -8264, 4255, -4433, -6662, -9230, -7678, - 5859, 118, 457, -227, 1717, 1353, -8499, -9649 -}; - -const Word16 Mean_dic_NB_fx[1*10] = /*Q12 */ -{ - -444, -100, -120, -37, 25, - 70, 148, 63, 170, 229 -}; - -const Word16 Gain_dic1_NB_fx[3*64] = /*Q12 */ -{ - -606, -92, 5, - -1965, 294, 666, - -440, 119, 661, - -106, 267, 108, - -1213, 345, -136, - -1251, 618, 566, - -1905, -750, 648, - -1043, -360, -498, - -18, -322, 96, - 334, 116, -247, - -1929, 660, 23, - -1845, 1178, 485, - -180, 836, 167, - -1892, -922, -321, - 416, -437, -344, - 595, -548, 158, - -265, -807, -338, - -1065, -1015, -20, - -626, 595, -333, - -569, 1090, 651, - 27, 587, -331, - -184, -85, -503, - -1902, -1807, 326, - -1861, -159, -989, - -666, 143, -1163, - -1718, 1031, -744, - 847, 301, -59, - 720, -1001, -216, - 1380, -866, -969, - 803, -4, -608, - 233, 408, -998, - 1459, 87, 263, - 345, -615, -1026, - 877, -148, -7, - 68, -1075, 270, - 802, 329, 475, - -1923, -126, -38, - 1275, -419, -349, - 401, 926, 575, - 846, -233, 547, - 693, -1880, 356, - -362, -1683, -219, - 231, -339, 598, - 1227, -616, 267, - 1116, 91, -1316, - -551, -650, 530, - 444, 32, 181, - -384, 1207, -775, - -993, 1163, 41, - 784, -1018, 538, - 635, 636, -424, - 1373, -1367, 149, - 1442, 401, -444, - 1094, 888, 123, - 874, 1113, -1082, - -646, -1112, -1103, - 539, -1632, -683, - 402, 571, 99, - -1778, -1809, -849, - -732, -1691, 700, - -678, 526, 274, - 320, 1227, -118, - -1222, -180, 454, - 173, 349, 530 -}; - -const Word16 Gain_dic2_NB_fx[3*32] = /*Q12 */ -{ - 28, 0, -66, - -557, 4, 206, - 281, -642, 36, - -417, 81, -494, - -380, 684, 450, - 521, -1544, 258, - -1119, 613, -1151, - 514, 24, 797, - 292, -84, -526, - 296, 418, -231, - -419, -68, 976, - 2, -308, 398, - -456, -1007, 263, - -1221, -371, 446, - -221, -390, -181, - -1210, 588, 751, - -1093, 528, -174, - 590, 372, -1271, - -79, -251, -1241, - -1016, -487, -512, - 542, 581, 338, - -265, 456, -105, - 490, -71, 89, - 42, 235, 379, - 31, 1194, -202, - 173, -839, 850, - -46, 500, -802, - 152, 933, 1073, - 980, 345, -263, - 807, -580, -521, - -23, -992, -585, - 876, -576, 411 -}; - -const Word16 Gain_dic3_NB_fx[4*16] = /*Q12 */ -{ - -16, 65, -227, 11, - -214, 553, 366, 185, - 137, -338, -300, -625, - -122, 82, 538, -797, - 160, 285, -1103, 35, - -594, 312, -379, -423, - 169, -642, -395, 363, - 351, -1166, 630, -261, - -1190, 217, 416, 187, - -577, 244, -636, 858, - 580, 482, -220, 635, - 475, -188, 372, 27, - -65, -369, 504, 910, - -423, -442, 124, -40, - 480, 575, -41, -651, - 682, 680, 910, 489 -}; - -const Word16 Gain_dic2_NBHR_fx[3*64] = /*Q12 */ -{ - 29, 0, -94, - -605, -202, -174, - 324, -380, -163, - -126, -301, -306, - -288, 124, 112, - -86, 524, -115, - 234, 18, -464, - -55, -281, 179, - 161, 446, 632, - 366, -82, 97, - 228, -1149, 270, - 293, 286, -143, - -123, -35, -896, - -540, -675, 175, - 331, -483, -687, - -779, 204, -668, - -492, 768, -510, - -1215, -620, -483, - 681, -76, -296, - -671, 396, -45, - -759, 298, 564, - -284, 589, 321, - -1366, -592, 496, - -448, -585, -712, - 12, -756, -90, - 513, 167, -927, - -1172, 1060, -1198, - -477, 748, 1006, - 42, 103, 1277, - -940, 1049, 138, - -924, -14, -1469, - 684, 679, -1580, - 417, -374, -1572, - 607, 270, 256, - 567, 778, 843, - 1414, -223, -542, - 97, 200, 251, - 222, 1074, -547, - -714, -285, 1046, - 386, -684, 984, - 338, 674, 116, - -274, 171, -368, - 581, -1871, 342, - 94, 442, -597, - -293, -1205, 851, - -127, 501, -1247, - 175, 1700, 1357, - -24, 1224, 285, - 707, -952, -293, - 668, 492, -407, - 1164, 751, 201, - 381, -595, 288, - -1570, 481, -531, - -597, -160, 326, - -578, -1311, -40, - -118, -523, 576, - -1513, 527, 757, - -184, 40, 609, - -1215, 98, 68, - -65, -1324, -836, - 821, -299, 204, - 796, 21, 840, - 310, -133, 542, - 1042, -974, 537 -}; - -const Word16 Gain_dic3_NBHR_fx[4*128] = /*Q12 */ -{ - 293, 7, -202, -95, - 535, 110, 542, -512, - -578, 65, -560, -345, - 206, 332, 10, -533, - -76, 356, -14, 83, - 149, -372, -195, -490, - -478, -241, -55, 113, - -293, -470, -606, 62, - 797, -1448, 625, -1128, - 173, 464, -1686, -49, - -392, -295, -159, -464, - -715, 420, -146, -984, - -36, 28, -484, 119, - 472, 272, -729, -116, - 68, -87, -628, -429, - 429, -918, -158, -191, - -545, 230, -435, 261, - -128, 15, -791, 612, - 268, -387, -1258, 102, - 378, 238, 301, 3, - -494, 149, 131, -124, - 634, -308, 99, 24, - 572, 711, 754, -1137, - -1109, 400, 1093, 369, - -831, -423, 1583, 1089, - -83, 156, -105, 1078, - -930, 476, 152, 380, - 776, 1162, 788, -43, - 279, 50, 408, 597, - 476, 483, 73, 749, - 903, 686, 80, -411, - 195, -768, 280, 344, - -263, -999, -46, -284, - -66, 263, 315, -1239, - 435, 578, -234, -1169, - 199, -1669, 188, 114, - -57, 419, -509, -633, - 98, -119, 129, -816, - -157, -365, -249, 537, - 67, -624, 121, 1153, - 1444, 142, -584, 38, - 1086, -84, 162, 994, - 392, -384, -124, 533, - 252, 183, -1161, -885, - -431, -829, 102, 432, - -708, 987, -1021, -644, - -64, 120, -1684, 985, - 210, -494, -906, 1302, - 50, -186, 177, 185, - -256, 872, -1004, 387, - 564, -80, -679, 515, - -763, -40, -1174, 228, - -1029, 199, -59, -297, - 30, -47, 198, -264, - -396, -1435, 913, -1018, - -141, 962, 36, 458, - 36, -388, 776, -1000, - -74, 489, 1137, 140, - -970, -766, 666, -117, - 90, 599, 1665, 1405, - -313, -685, -764, -615, - 563, -462, -627, -768, - 792, 560, -1445, 556, - -581, 721, -559, 1137, - -699, -273, 274, -846, - 940, -690, 747, -253, - -177, -541, 1355, -217, - -586, 427, 1196, -868, - 147, 532, -550, 405, - 258, 677, -245, -166, - 772, 1062, -331, 482, - 388, 1870, -576, 1585, - 462, 865, 454, 1212, - 570, 528, -681, 1229, - -386, 607, 599, 865, - -154, -20, -211, -231, - 96, 736, 408, -259, - 763, -1533, 1094, 249, - 705, -1132, 1757, -1082, - 310, -481, 329, -395, - 194, -781, 59, -954, - -933, -957, -25, 1866, - -852, -224, -482, 822, - -1438, 490, 221, 1281, - 392, 677, 539, 347, - 884, -614, 1844, 678, - -773, 484, -928, 2477, - -274, -461, 378, -263, - -283, -312, 583, 342, - 453, -1541, 378, 1266, - 778, 1095, 1290, 824, - -958, -443, -208, -71, - 985, -1001, -123, 473, - 56, -1003, -513, 474, - -259, 1435, 975, 315, - -59, -169, 724, 961, - -210, 1030, 341, -977, - 1054, 2917, -7, -877, - -852, -228, 330, 625, - 9, -524, -97, -14, - 16, -50, 476, 2406, - 264, -238, 768, 56, - 187, 108, -169, 446, - 673, 238, 992, 671, - -218, 285, 485, 181, - 669, -526, 639, 571, - 650, 20, -188, -516, - 1031, 165, 526, 136, - -333, 307, 102, -569, - -157, 309, -934, -121, - -336, 141, 39, 536, - 662, 364, -133, 222, - -1284, 637, -636, 77, - 1241, 846, 467, 638, - 842, 328, 1330, -320, - 152, -1009, 550, -215, - -772, 13, 594, -122, - 336, -410, -547, -2, - 869, -106, 321, -1180, - 516, 1247, -828, -577, - -670, 873, 367, -132, - -415, 630, -287, -164, - -105, 138, 657, -441, - -160, -1085, 940, 704, - -128, -68, -369, -1052, - -1434, 594, 546, -665, - -1849, 75, 175, 174, - -1283, 729, -1590, 1032 -}; - - -const Word16 mean_m_fx[1*1] = /*Q12 */ -{ - 11762 -}; -const Word16 mean_gain_dic_fx[1*64]= -{ - -739, -519, -76, 147, 574, 779, 983, 1185, - 1384, 1580, 1784, 1989, 2204, 2643, 2864, 2422, - 362, -295, -1197, -1936, -2757, -11755, -8216, 3083, - 3311, -1434, -1682, -3341, -9284, -9057, -8616, -7783, - -7359, -6964, -6592, -6233, -5470, -5050, -4651, -3954, - -2470, -963, -2199, -3042, -3643, -4292, -5854, -10199, - 4103, 3548, 4390, 4717, 3817, -10525, -11521, -9570, - -9899, -9171, -10841, -11165, 5500, 5079, 6139, 6993 -}; /* Q12 */ - -const Word16 YGain_mean_LR_fx[1*12]= -{ - -385, -178, -143, -116, -46, -12, - 64, 50, 118, 68, 133, 151 -}; - -const Word16 YGain_dic1_LR_fx[3*32]= /*Q12 */ -{ - -1909, 159, -90, - -155, 416, -15, - -99, -84, 396, - -1832, -848, -320, - -779, 1024, 45, - -1860, -1761, 273, - 81, -341, -309, - -819, -3, -315, - 483, 215, -194, - 242, 937, -76, - -1830, -1753, -1102, - -1589, 868, -657, - -911, 389, 421, - -1834, 915, 390, - -144, 564, -869, - 878, -1544, 301, - 446, 332, 376, - -540, -822, -1001, - 548, -192, 232, - 920, -589, -175, - 869, 717, -564, - 797, -103, -1047, - -335, -1732, -186, - -1840, -345, 566, - 1205, 109, 43, - 985, -456, 570, - 650, -1223, -874, - 928, 752, 390, - -124, 833, 575, - -1811, -249, -1142, - -711, -767, 185, - 344, -876, 267, -}; - -const Word16 YGain_dic2_LR_fx[4*32] = /*Q12 */ -{ - -294, -73, -41, 11, - 276, 330, -1316, 173, - 26, -712, 86, 1, - -841, -539, 246, -479, - 43, -207, 709, 116, - 104, -197, 227, -548, - 261, -228, 165, 606, - 613, 403, -122, -420, - 14, 182, -544, -669, - -734, 392, -492, -131, - -1316, 274, 116, 331, - -1339, 535, -1261, 608, - -346, 277, -426, 729, - -1067, -836, -571, 388, - 643, 503, 484, 532, - -148, 447, 120, -392, - -600, 263, 519, -75, - 686, -346, 379, 23, - 130, 239, 376, -1366, - 68, 656, -361, 92, - 608, 286, -405, 487, - -1031, 507, 523, -971, - 51, -44, -521, 172, - -573, -500, 398, 632, - 240, 147, 104, 51, - -319, -680, -890, -398, - -195, 503, 306, 459, - 335, 368, 662, -389, - 378, -788, -537, 680, - 433, -1129, 472, -883, - 472, -312, -301, -207, - 378, -1346, 433, 408, -}; - -const Word16 YGain_dic3_LR_fx[5*32] = /*Q12 */ -{ - -332, -191, -122, -455, -210, - 364, -48, -664, 408, 225, - -576, -342, 367, 52, 270, - -392, -157, -77, 625, -224, - -183, -652, -406, 99, 266, - 24, 65, 74, 525, 613, - -805, 306, -383, -21, 247, - 16, 133, -416, -4, -567, - 294, -750, 443, -367, 228, - 536, 816, 767, 562, 594, - -54, 200, -1108, -582, 227, - 123, -43, 414, -376, -649, - 592, -652, -674, -386, -356, - 100, -58, -45, -108, 103, - -727, -194, -1170, 931, 1096, - 512, 758, -440, -769, -1051, - 362, 787, -276, -139, 149, - -218, 387, 457, -414, 265, - -202, 663, -1104, 882, -338, - -57, 405, 269, 257, -221, - 335, 864, 1164, -611, -618, - 1275, 494, -1783, 119, 1222, - 752, 76, 270, 73, -57, - 376, -1255, 145, 724, 603, - -989, 618, 659, 675, 560, - 128, -147, -138, -368, 963, - 140, -170, 866, 538, 127, - 122, -616, 166, 236, -396, - 374, 279, 407, 650, -1269, - -861, 613, -755, -1334, -972, - -922, 314, 416, -114, -648, - 265, 85, 61, -1110, 45 -}; - -const Word16 YG_mean16_fx[1*16] = /*Q12 */ -{ - -396, -192, -168, -136, -60, -17, 45, 39, - 120, 81, 90, 67, 147, 34, 163, 184 -}; - -const Word16 YG_dicMR_1_fx[4*64] = /*Q12 */ -{ - -1879, 826, 539, -210, - -120, 267, -137, -142, - -798, -473, 434, 243, - 297, -896, 369, 307, - -1883, -1333, 416, 510, - -1955, -660, -471, 224, - -905, -804, -517, 433, - -961, 20, -258, -224, - 209, 977, -213, -17, - 536, -244, 159, 97, - -265, 775, 412, -327, - 337, -391, -237, -472, - -1962, -1836, -692, 471, - 625, 173, -463, -15, - -965, 263, 62, 600, - -782, 889, -433, 211, - -1791, 852, -453, -776, - -182, -177, -1078, 80, - -364, 350, 280, 293, - -902, 1119, 295, -1194, - 16, 440, -342, 459, - -1825, -1584, -1382, -798, - 723, 57, -1235, -661, - 888, -1638, 277, 234, - 340, 345, 141, -610, - 1280, -23, 17, 144, - -639, -852, -520, -553, - 1032, 843, 149, 435, - 581, 783, 519, -196, - 457, 945, 498, -1289, - -1897, -41, 425, 514, - 787, 161, 506, 385, - -559, 1079, 319, 515, - 500, 340, 60, 106, - 251, -997, -1163, -960, - 261, -1288, -631, 335, - 1241, -620, -387, -662, - 167, 194, 476, 67, - 830, -261, 430, -1201, - -479, -123, 71, -1162, - 225, -1482, 132, -802, - 680, 763, -1010, 429, - 200, -125, 261, 590, - 771, -740, -183, 229, - -1860, -348, 278, -549, - -1768, 967, 281, 594, - -1727, -1697, 87, -764, - 1169, 631, -114, -471, - -1636, -101, -1324, -91, - 821, -745, 458, -264, - 1014, -576, 390, 470, - 1041, -517, -1018, 367, - 826, 17, 426, -326, - -467, -1641, 201, 325, - -1906, 428, -338, 222, - -1021, 630, 419, -75, - -86, -379, -203, 234, - 659, 527, -491, -1507, - -564, -1745, -979, -173, - -1764, -433, -743, -1090, - 242, 709, 269, 497, - 716, 74, -208, 618, - -297, 645, -864, -805, - -46, -326, 412, -296 -}; -const Word16 YG_dicMR_2_fx[4*32] = /*Q12 */ -{ - 93, 217, -122, 37, - -13, -83, 105, -491, - -398, -592, 399, -160, - 543, -81, -470, 408, - 394, -630, -94, -258, - -665, 133, -136, -125, - 397, -351, 630, -148, - -1166, 406, -865, 554, - -136, -302, -263, 81, - -674, -657, -571, -691, - -206, 381, -699, 122, - 272, -1506, 356, 15, - 451, -961, 638, -1133, - 316, -787, 165, 585, - 312, -144, 185, 274, - 39, -706, -997, 250, - -915, -871, -114, 458, - -834, 348, 364, -1188, - 450, 723, -256, 412, - 369, 468, -1371, 416, - 344, 164, 290, -1094, - 664, 122, 34, -218, - 555, 254, 559, 825, - 312, 492, 496, -27, - -399, 315, 690, -330, - -458, 710, 206, 415, - 290, 89, -662, -467, - -72, 593, -108, -460, - -217, 46, 319, 189, - -1366, 199, 365, 62, - -552, -166, 772, 861, - -159, 120, -215, 775 -}; -const Word16 YG_dicMR_3_fx[4*32] = /*Q12 */ -{ - -103, -143, -85, -19, - -404, 182, -795, 84, - 398, -594, -55, -256, - 283, 128, -472, 279, - -246, -628, 281, 297, - -853, 468, 358, -915, - 272, 149, 209, -443, - -168, -504, 452, -525, - 624, -427, 779, 117, - 1079, 404, -98, 80, - 136, 165, 142, -1394, - 513, -566, -150, 822, - 124, 646, 199, 272, - -165, -702, -615, 165, - 333, 810, -457, 1038, - -360, 105, -110, 537, - -224, 125, 562, -26, - 699, -1105, 809, -1323, - -1229, 841, -767, 571, - -310, 437, -114, -230, - -1045, 630, 564, 322, - 282, 1170, -723, -306, - -328, -247, -251, -598, - 354, 332, -1593, 499, - 332, -23, 219, 304, - 325, -1511, 378, 299, - -94, -54, 679, 956, - 507, 830, 861, -739, - -895, -135, 16, -34, - 677, 650, 961, 714, - 816, -665, -1741, -671, - 274, 93, -617, -433 -}; -const Word16 YG_dicMR_4_fx[4*16] = /*Q12 */ -{ - -163, -44, -108, 32, - 556, 153, 115, 120, - 617, 818, 802, 719, - -639, -665, 122, 664, - 353, -555, -352, -86, - -1162, 833, -1034, 326, - -511, -406, -478, -523, - 491, -1473, 404, -21, - 148, 288, -45, -544, - -61, 172, -791, -44, - 715, -449, 861, 504, - -108, 263, 610, 118, - 962, 826, -1013, -37, - -32, -495, 362, -214, - -37, 661, -75, 289, - -835, 243, 85, -105 -}; - - -/***********IN Q15*****************/ -const Word16 sm_table_fx[] = -{ - 32767, 32126, 31480, 30838, 30196, 29557, 28918, 28279, 27643, 27007, - 26375, 25746, 25120, 24494, 23875, 23255, 22643, 22033, 21427, 20824, - 20228, 19638, 19048, 18468, 17891, 17321, 16758, 16197, 15647, 15103, - 14562, 14031, 13507, 12989, 12481, 11980, 11488, 11000, 10525, 10056, - 9598, 9146, 8706, 8274, 7851, 7438, 7035, 6642, 6259, 5885, - 5521, 5171, 4830, 4499, 4178, 3870, 3572, 3287, 3011, 2746, - 2494, 2254, 2025, 1809, 1602, 1412, 1229, 1062, 904, 760, - 629, 511, 403, 308, 226, 157, 102, 56, 26, 7, -}; - -const Word32 GSC_freq_bits_fx[] = -{ - 5505024, 17563648, -1572864, 6553600, 3932160, 2883584, 2621440, 1310720, 0, 0, 1310720, 1048576, 0, 0, 1048576, 0, 0, /* ACELP_7k20*/ - 5505024, 19660800, -1048576, 6815744, 4194304, 3145728, 2883584, 2359296, 0, 0, 1048576, 1048576, 262144, 262144, 786432, 0, 0, /* ACELP_8k00*/ - 6815744, 25165824, -1048576, 7340032, 4718592, 3407872, 3145728, 2621440, 2621440, 1310720, 1048576, 1048576, 262144, 0, 262144, 786432, 1048576, /* ACELP_11k60*/ - 6815744, 25165824, -1048576, 7340032, 4718592, 3407872, 3145728, 2621440, 2621440, 1310720, 1048576, 1048576, 262144, 0, 262144, 786432, 1048576, /* ACELP_12k15*/ - 6815744, 25165824, -1048576, 7340032, 4718592, 3407872, 3145728, 2621440, 2621440, 1310720, 1048576, 1048576, 262144, 0, 262144, 786432, 1048576, /* ACELP_12k85*/ - 8126464, 25165824, -1048576, 7340032, 4718592, 3407872, 3145728, 2621440, 2621440, 1310720, 1048576, 1048576, 262144, 0, 262144, 786432, 1048576, /* ACELP_13k20*/ -}; - -const Word32 pow2_fx[] = -{ - 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, 65536, 131072, 262144, 524288, 1048576 -}; - - -/*----------------------------------------------------------------------------------* - * means of ISFs for WB active speech - *----------------------------------------------------------------------------------*/ -const Word16 Mean_isf_wb[M] = /* G722.2 active speech ISF's means */ -{ - 738, 1326, 2336, 3578, 4596, 5662, 6711, 7730, - 8750, 9753,10705, 11728, 12833, 13971,15043, 4037 -}; -const Word16 interpol_isp_amr_wb_fx[] = {14746, 26214, 31457, 32767}; -const Word16 interpol_frac_16k_fx[NB_SUBFR16k] = { 6554, 13107, 19661, 26214, 32767 }; -const Word16 interpol_frac_fx[NB_SUBFR] = {8192, 16384, 24576,32767}; - - -/*----------------------------------------------------------------------------------* - * ISF quantization (AMR-WB IO mode) - *----------------------------------------------------------------------------------*/ - -const Word16 mean_isf_amr_wb_fx[M] = -{ - 738, 1326, 2336, 3578, 4596, 5662, 6711, 7730, - 8750, 9753,10705, 11728, 12833, 13971,15043, 4037 -}; -const Word16 mean_isf_noise_amr_wb_fx[M]= -{ - 478, 1100, 2213, 3267, 4219, 5222, 6198, 7240, - 8229, 9153,10098, 11108, 12144, 13184,14165, 3803 -}; - -/* ISF codebook - common 1st stage, 1st split (only in AMR-WB IO mode) */ -/*------------------------------------------------------* - * Indirection for 1st stage 1st split of 46 bit cb. : - The transmitted_index = indirect_dico1[found_index]; - *------------------------------------------------------*/ -const Word16 Indirect_dico1[SIZE_BK1] = -{ - 2, 6, 18, 22, 34, 35, 38, 50, - 66, 67, 70, 82, 98, 99, 102, 130, - 131, 134, 146, 150, 162, 178, 194, 198, - 210, 226, 230, 242, 0, 1, 3, 4, - 5, 7, 8, 9, 10, 11, 12, 13, - 14, 15, 16, 17, 19, 20, 21, 23, - 24, 25, 26, 27, 28, 29, 30, 31, - 32, 33, 36, 37, 39, 40, 41, 42, - 43, 44, 45, 46, 47, 48, 49, 51, - 52, 53, 54, 55, 56, 57, 58, 59, - 60, 61, 62, 63, 64, 65, 68, 69, - 71, 72, 73, 74, 75, 76, 77, 78, - 79, 80, 81, 83, 84, 85, 86, 87, - 88, 89, 90, 91, 92, 93, 94, 95, - 96, 97, 100, 101, 103, 104, 105, 106, - 107, 108, 109, 110, 111, 112, 113, 114, - 115, 116, 117, 118, 119, 120, 121, 122, - 123, 124, 125, 126, 127, 128, 129, 132, - 133, 135, 136, 137, 138, 139, 140, 141, - 142, 143, 144, 145, 147, 148, 149, 151, - 152, 153, 154, 155, 156, 157, 158, 159, - 160, 161, 163, 164, 165, 166, 167, 168, - 169, 170, 171, 172, 173, 174, 175, 176, - 177, 179, 180, 181, 182, 183, 184, 185, - 186, 187, 188, 189, 190, 191, 192, 193, - 195, 196, 197, 199, 200, 201, 202, 203, - 204, 205, 206, 207, 208, 209, 211, 212, - 213, 214, 215, 216, 217, 218, 219, 220, - 221, 222, 223, 224, 225, 227, 228, 229, - 231, 232, 233, 234, 235, 236, 237, 238, - 239, 240, 241, 243, 244, 245, 246, 247, - 248, 249, 250, 251, 252, 253, 254, 255 -}; - -const Word16 dico1_isf_fx[]= -{ - 740, 1263, 1292, 1006, 997, 1019, 1017, 976, 923, - 557, 946, 1049, 867, 846, 990, 1112, 1262, 1241, - 633, 898, 996, 756, 662, 683, 783, 909, 996, - 830, 736, 278, 820, 1254, 686, 712, 1039, 473, - 503, 885, 1508, 1307, 1282, 1172, 1119, 1209, 1061, - 416, 719, 989, 1227, 1001, 1052, 954, 741, 1044, - 585, 1132, 1233, 1091, 1247, 1433, 1512, 1448, 1314, - -31, 469, 803, 659, 619, 658, 843, 987, 1113, - 842, 1678, 1841, 1549, 1474, 1256, 1082, 905, 742, - 370, 1216, 1768, 1633, 1212, 636, 22, -330, 71, - 73, 738, 893, 968, 993, 1768, 2273, 1840, 1391, - 1513, 1714, 1238, 534, 276, 315, 461, 459, 508, - 421, 1293, 1640, 1623, 1742, 1617, 1499, 1284, 1006, - -95, 752, 1680, 1569, 1618, 1436, 1200, 980, 712, - -78, 831, 1194, 1110, 1378, 1481, 1492, 1365, 1217, - 670, 1208, 1168, 860, 742, 601, 528, 403, 309, - 397, 621, 966, 752, 579, 398, 400, 329, 252, - 510, 864, 1108, 807, 939, 902, 925, 717, 481, - 539, 835, 913, 719, 617, 544, 591, 565, 642, - 162, 889, 654, 108, -34, 244, 488, 561, 532, - -62, 1033, 1308, 1035, 1127, 1098, 1029, 961, 823, - -14, 945, 990, 801, 755, 815, 847, 913, 892, - 394, 1765, 1666, 1339, 1117, 806, 642, 479, 380, - 529, 1851, 2003, 1228, 622, -41, -416, 344, 819, - 635, 1058, 883, 492, 372, 312, 317, 274, 241, - 279, 966, 1642, 1478, 1463, 1123, 795, 525, 339, - 457, 955, 1177, 1214, 1427, 1457, 1345, 917, 539, - 148, 751, 1515, 1105, 867, 606, 474, 448, 399, - 579, 1081, 1035, 390, 3, -263, -198, -82, 38, - 18, -68, -12, 313, 761, 405, 249, 111, -76, - -91, 827, 948, 648, 613, 535, 522, 490, 421, - 41, -44, -281, -472, 652, 534, 193, 135, -90, - 41, -121, -356, -60, 663, 307, 61, -48, -344, - -118, -204, 328, 512, 870, 793, 610, 402, 186, - 156, 293, 74, -338, -475, -897, -594, -161, -497, - 226, 131, -138, 307, 169, -271, -164, -387, -624, - 62, -32, -61, -252, -541, -828, -1027, -523, -662, - 102, -61, 141, 112, -270, -251, -541, 25, -150, - 6, -132, -356, -686, -96, -322, -522, -31, -326, - -36, -209, -521, -229, 307, -132, -5, -99, -384, - 60, -51, -237, -668, -973, -407, -708, -75, -172, - 26, -138, -266, 111, -302, 43, -278, -356, -359, - 570, 822, 496, -154, -312, -92, 137, 279, 371, - -146, 368, 409, 68, 6, 77, 167, 202, 162, - -103, 294, 607, 415, 483, 462, 480, 431, 408, - -120, -338, -612, -524, 584, 331, 92, 433, 276, - -178, -293, -154, -41, 269, 100, -9, 213, 160, - -218, -304, 463, 454, 397, 273, 202, 286, 273, - -232, 7, 6, -388, -472, -427, -378, -167, -100, - -294, -183, 134, -47, 101, -88, -84, -117, -3, - 57, 17, -202, -634, -989, -1119, -533, 176, -36, - 120, -28, 23, 111, -319, 318, -22, -77, 266, - -271, -464, -434, -658, -640, -385, -385, -99, -69, - -198, -259, -266, -44, -39, -139, -137, 171, 66, - 9, -145, -377, -846, -1000, -111, -325, 342, 135, - -81, -286, -380, 192, -57, 307, 76, -24, -140, - 677, 702, 247, 56, 249, 141, -105, -236, -99, - 36, -39, -69, 348, 198, -93, 322, 91, -72, - -127, -376, -657, 139, 623, 223, 501, 306, 220, - -113, -384, -796, 504, 438, 85, 213, -83, -194, - -174, -422, 7, 1155, 1089, 1182, 1003, 945, 806, - 8, -126, -317, -103, -351, -695, -98, -268, -537, - 33, -103, -290, 167, -39, -407, 44, -208, -375, - 104, -23, -64, -291, -637, -851, -1084, -61, -112, - -75, -306, -434, 218, -148, -354, -680, -133, -216, - -121, -377, -718, -97, -130, -361, -156, -379, -599, - -56, -254, -586, 235, 157, -214, 11, -260, -149, - -124, -267, -397, -580, -593, -527, -805, -385, 346, - -193, -440, -708, -351, -141, -255, -499, -147, -185, - 448, 660, 494, 208, 509, 461, 338, 291, 149, - -223, 88, 335, 159, 212, 191, 286, 308, 205, - -171, -242, 514, 362, 295, 524, 552, 694, 585, - -64, -308, -448, -21, 284, 786, 446, 289, 92, - -218, -390, -7, 169, 206, 330, 352, 408, 358, - -36, 702, 959, 859, 861, 1115, 1269, 1357, 1305, - -133, -341, -65, 678, 417, 440, 486, 518, 780, - 33, -44, -191, -344, -461, -755, -201, 217, -31, - -353, -547, -44, 123, -61, -68, -79, 29, 60, - 73, -57, -406, -766, -1243, -1203, 240, 400, 165, - -73, -282, -601, -213, -171, -375, 332, 35, -103, - -29, -207, -553, -476, -638, -908, 172, -22, -135, - -192, -239, -164, -103, -111, -47, 153, 125, 110, - -1, -203, -570, -1030, -1424, -535, 155, 1, 147, - -333, -653, -865, -197, -158, -21, -44, 95, 108, - 389, 588, 490, 33, -237, -524, -628, -136, -260, - 40, -177, -462, 453, 862, 380, 131, -130, -405, - -76, -281, -741, -742, 898, 619, 277, 71, -222, - -32, -265, -556, -25, 994, 682, 305, 126, -165, - -69, -349, -585, 234, 1158, 903, 626, 510, 251, - -1, -99, -272, -210, -603, -351, -540, -811, -383, - -16, -230, -504, 410, 149, -205, -343, -651, -639, - 103, -9, -227, -205, -562, -781, -1079, -1208, -156, - 143, 63, -135, -67, -317, -602, -784, -1154, -640, - -144, -391, -674, -622, -200, -254, -660, -947, -395, - -40, -250, -625, 27, 543, 94, -131, -386, -673, - -123, -371, -757, -451, -564, -614, -415, -711, -35, - -116, -309, -593, -268, 239, -33, -338, -650, -135, - 94, 251, 554, 57, -312, -423, -154, -57, 235, - -268, -71, 381, 114, -44, -87, 125, 173, 133, - -131, -19, 1149, 670, 486, 356, 309, 369, 296, - -223, -501, -899, -722, -70, 6, 131, 310, 394, - -99, -303, -517, 249, 64, -53, 135, -11, 453, - -147, -399, -730, -401, 817, 738, 802, 749, 575, - -154, -435, -739, 800, 593, 366, 529, 318, 326, - -224, 45, -39, -387, -515, -518, -608, -384, -321, - -315, -377, 143, -101, -113, -377, -177, -144, -12, - 117, 40, -239, -651, -1051, -581, -737, -990, -328, - 26, -50, -157, -23, -453, -283, -531, -546, 192, - -252, -501, -743, -589, -627, -499, -328, -118, -72, - -324, -494, -244, -306, -144, -177, -262, -135, -78, - -36, -234, -519, -961, -1290, -314, -479, -371, -45, - -95, -292, -535, -8, -300, 112, -164, -277, 198, - -99, -128, 880, 836, 579, 351, 23, -95, -217, - -27, -258, 124, 1011, 597, 425, 144, 7, -73, - -69, -300, -683, -435, 1132, 899, 504, 332, 109, - -74, -323, -637, 563, 1074, 608, 371, 105, -49, - -259, -121, 1440, 1334, 1628, 1490, 1438, 1223, 933, - -82, -306, -613, -222, -378, -675, -545, -671, -845, - 53, -124, -347, 422, 52, -125, -270, -529, 9, - 79, -89, -320, -662, -999, -1199, -1243, -676, -297, - -68, -273, -611, 137, -146, -397, -627, -845, -220, - -112, -346, -797, -826, 234, -132, -188, -278, -522, - -159, -405, -734, -419, 293, 74, -167, -167, 184, - -153, -437, -833, -1080, -336, -472, -561, -340, -253, - -169, -423, -820, -904, -131, -19, -346, -604, 31, - 33, -31, 312, 62, -148, 49, -59, 564, 486, - -306, -333, 194, -44, 67, 72, 147, 205, 243, - -207, -49, 1360, 983, 969, 991, 1014, 1110, 973, - -211, -172, 883, 627, 711, 674, 705, 798, 746, - -88, -325, -763, -974, 687, 908, 514, 382, 172, - -292, -612, -805, 63, 131, 270, 259, 352, 348, - -235, -84, 955, 818, 1120, 1289, 1559, 1480, 1285, - -180, -461, -614, 657, 691, 745, 854, 783, 713, - -97, -309, -477, -614, -777, -734, -768, -526, -472, - -344, -476, -35, -169, 49, -77, -150, -240, -141, - -52, -268, -639, -919, -1278, -1113, -342, -333, -151, - -68, -242, -585, -73, -209, -478, -159, -429, 133, - -197, -499, -1005, -1268, -272, -224, -105, -67, 17, - -363, -618, -414, -116, -62, 20, 10, 116, 108, - -195, -475, -906, -1260, -891, -441, -277, -142, -28, - -226, -519, -950, -700, -275, -266, -116, -105, 82, - 404, 511, 520, 327, 17, -194, -333, -536, -586, - -114, -130, 276, 237, 204, 342, 135, -16, -111, - 191, 180, -137, -467, 272, 106, -95, 17, -192, - -80, -290, -626, 194, 598, 196, 21, -281, 77, - 137, 367, 534, 764, 670, 382, 296, 153, 84, - 303, 497, 144, -85, -125, -539, -482, -464, -764, - 233, 347, 68, -147, 169, -210, -242, -226, -482, - 307, 422, 154, -175, -386, -722, -724, -904, -1015, - 309, 308, 160, -60, -470, -420, -598, -791, -219, - 68, 121, -137, -560, -146, -446, -515, -494, -729, - 130, 53, -227, 46, 474, 32, -161, -192, -490, - 213, 164, -71, -465, -876, -161, -456, -587, -48, - 218, 117, 39, 177, -194, -88, -226, -418, 50, - 210, 547, 569, 279, 121, -44, -50, 10, -84, - 58, 140, 182, -5, 267, 117, 106, 211, 198, - 153, 559, 872, 460, 222, 108, 188, 180, 183, - 158, 119, 284, -153, -271, 229, 87, 110, -57, - -183, 82, 118, 21, 13, 40, 118, 191, 185, - 163, 56, 609, 341, 50, 329, 68, 266, 218, - 100, 206, 18, -304, -107, -436, -487, -65, -306, - -86, 154, 134, -30, -45, -73, -104, -80, -96, - 245, 330, 10, -440, -849, -1082, 79, 40, -265, - 196, 372, 272, -181, -493, -389, 275, 80, -59, - 2, -12, -246, -505, -100, -436, 21, -187, -431, - -221, -48, 36, -271, -186, -147, -109, 26, 71, - 213, 140, 72, -351, -620, -84, -363, 69, 46, - 91, 167, -3, -95, -99, -105, -48, 114, 147, - 259, 249, 172, 607, 406, 52, 59, -189, -320, - 115, -85, -54, 574, 128, 226, -59, -253, 130, - 39, 364, 757, 940, 728, 660, 659, 583, 770, - -115, -338, -760, -471, 394, 37, 441, 178, 6, - -57, -305, -525, 796, 453, 188, -4, -114, 248, - 71, 444, 797, 731, 1096, 1157, 1222, 1029, 811, - 135, 359, 551, 425, 749, 815, 874, 704, 502, - 132, 247, 0, -206, -449, -750, -258, -514, -633, - 248, 249, 91, 121, -195, -499, -90, -282, -435, - 78, 20, -277, -623, -983, -1224, -415, -458, -639, - 347, 509, 208, -179, -464, -728, -76, -237, -486, - -103, -343, -756, -713, -265, -609, -191, -398, -636, - -121, -383, -749, 567, 252, -36, -354, -417, -50, - 204, 100, -149, -650, -1081, -47, -7, -263, 111, - -46, -180, -267, -324, -562, -394, -692, 398, 292, - 482, 670, 683, 624, 442, 165, 116, 36, -149, - 108, 247, 291, 247, 355, 122, 109, 224, 296, - 292, 349, 725, 482, 388, 329, 429, 620, 667, - -34, 197, 213, -127, 84, 494, 620, 575, 375, - 126, 207, 172, 167, 362, 202, 296, 395, 455, - -6, 250, 539, 467, 636, 801, 1149, 1287, 1118, - 27, 240, 369, 280, 440, 411, 634, 892, 953, - 159, 170, -58, -395, -797, -690, 77, -211, -334, - -5, -28, -13, -74, -335, -603, 300, 88, -205, - 82, -33, -364, -698, -1203, -1153, 110, -146, -289, - 113, 1, -243, -588, -994, -496, 414, 160, 42, - -56, -247, -440, -693, -996, -479, 11, -178, -357, - -151, -353, -327, -211, -340, 141, 65, 425, 453, - 34, -169, -455, -932, -1215, 138, 499, 256, 324, - 68, 139, -15, -547, -478, 17, 306, 502, 481, - -32, -134, 445, 129, -143, -244, -503, -507, -599, - 61, -140, -345, 496, 458, -2, 20, -227, -514, - 215, 519, 920, 1053, 1090, 791, 528, 290, 155, - -54, -233, -647, -602, 639, 294, -2, -167, -442, - -78, -315, -791, -113, 820, 403, 158, -116, -356, - -105, -379, -236, 1224, 893, 749, 568, 356, 214, - -17, -199, -144, 50, -283, -247, -578, -846, -1087, - 69, -11, -381, -206, 209, -284, -387, -416, -716, - 39, -5, -145, -374, -682, -909, -1074, -1169, -1066, - 287, 226, 67, -221, -662, -171, -421, -642, -707, - -132, -348, -538, -448, -20, -4, -354, -748, -933, - 4, -75, -289, -598, 317, 52, -208, -297, -559, - -88, -264, -358, -589, -631, -248, -523, -822, -1071, - 70, -8, 54, -314, -515, 92, -146, -274, -493, - 199, 62, 391, 158, -141, 71, -219, -203, -207, - 152, 40, 329, 162, -29, 48, -149, 108, 127, - 267, 722, 1256, 882, 625, 248, 8, -81, -60, - -58, -138, -291, -600, -12, -2, -39, 147, 117, - -107, -345, -513, 459, 76, 92, -272, 388, 262, - 362, 516, 203, -409, -716, -831, -331, 185, 209, - -117, -391, -298, 671, 292, 538, 257, 166, -38, - -102, -319, -194, -283, -573, -262, -579, -219, -444, - -235, 78, 11, -168, -101, -229, -263, -321, -123, - 70, 50, -170, -599, -996, -588, -263, -516, -455, - 394, 363, 229, -136, -538, 21, -183, -348, -201, - -124, -368, -640, -879, -847, -209, -409, -494, -515, - -127, -341, -541, -425, -510, -10, -252, -473, -291, - 84, -69, -201, -676, -868, 103, -311, -132, -320, - 5, -173, -188, -297, -628, 197, -57, 7, -11, - 49, -160, 56, 558, 111, 33, -311, -440, -463, - -1, -246, -307, 862, 453, 139, -170, -355, -232, - -197, -38, 1702, 1331, 1252, 950, 692, 504, 426, - -108, -344, -861, -1172, 444, 354, 88, -46, -220, - -53, -321, -494, 1113, 744, 364, 198, -34, -75, - -69, 199, 897, 1140, 1343, 1183, 977, 742, 522, - 122, 44, -269, 27, -155, -562, -307, -590, -773, - 154, 42, -160, 252, -129, -305, -471, -733, -371, - 135, 185, -82, -416, -722, -913, -504, -743, -880, - 149, 214, -84, -329, -680, -835, -426, -661, -81, - -128, -380, -735, -998, -337, 17, -182, -467, -697, - -84, -290, -510, -592, 13, 440, 154, -38, -279, - 70, -61, -246, -727, -1047, -80, -381, -535, -704, - 178, -2, -146, -670, -938, 482, 138, 63, 65, - -11, 15, 772, 443, 142, -20, -209, -126, -161, - -32, -249, 95, 552, 124, 30, -343, 82, -86, - -163, -257, 899, 1097, 906, 751, 502, 390, 294, - -51, -258, -447, -806, -368, 763, 464, 364, 183, - -166, -374, -367, 87, 35, 399, 418, 856, 833, - -205, -310, 588, 778, 785, 1065, 1118, 1245, 1157, - -173, -312, 107, 345, 400, 790, 870, 1113, 1001, - -7, -120, -387, -410, -614, -943, -226, -384, -491, - -203, -288, -51, -331, -90, -178, -408, -573, -338, - 56, -29, -273, -627, -1041, -798, -247, -467, 148, - 66, -2, -205, -205, -575, -349, -57, -352, -58, - -45, -225, -471, -924, -497, 77, -32, 44, -135, - -277, -491, -497, -502, -424, -202, -137, 77, 96, - 26, -179, -469, -1008, -1260, 262, -35, -132, -259, - -66, -232, -447, -533, -789, -191, -100, -267, 364, - 111, 43, -287, -423, -608, -987, -922, -799, -827, - 77, 76, -101, -260, -549, -850, -88, -231, -329, - 75, 24, -66, -269, -427, -528, -773, 201, -5, - 67, 7, -61, -320, -487, 12, -200, -242, -94, - 27, -54, -149, -354, -661, -594, -450, -481, 560, - 31, -69, -246, -549, -1141, -178, -232, -275, -288, - 16, -84, -176, 7, -83, -210, -246, -424, -589, - 63, -60, -201, -90, -269, -400, -685, -1218, -258, - 169, 217, 142, -71, -243, -433, -504, -511, -537, - 6, -105, -234, -321, -188, -131, -307, -521, -1319, - -34, -151, -369, 11, 44, -95, -280, -500, 160, - 31, -37, -163, -334, 288, 89, -150, -86, -299, - -35, -161, -362, -74, -74, -263, 240, 9, -153, - -45, -208, -529, -896, 89, 24, -130, -313, -373, - 234, 276, 197, -10, -236, -162, -134, -85, -112, - 42, -73, 133, 392, 98, 72, -153, -162, -99, - -3, -145, -338, 408, 401, 133, -52, -296, -501, - 3, -109, -152, -85, -56, 42, -145, 703, 205, - -49, -149, -281, -134, -121, -41, -21, 16, 958, - 30, -107, -196, -463, -523, 490, 236, 70, -128, - -33, -161, -364, -148, 757, 516, 250, 43, -65, - -34, -193, -244, 750, 527, 349, 234, 172, 134, - -64, -223, -379, 55, 28, 248, 793, 442, 320, - 29, -85, -298, -622, -888, 127, 206, 387, 460, - -48, -170, -477, -876, 573, 635, 440, 375, 311, - 42, 3, -212, -441, -718, -821, 388, 373, 211, - -106, -155, 1092, 459, 570, 561, 506, 604, 514, - -144, -264, 0, 460, 619, 877, 916, 1273, 921 -}; -/* ISF codebook - common 1st stage, 2nd split (only in AMR-WB IO mode) */ -const Word16 dico2_isf_fx[] = -{ - 1357, 1313, 1136, 784, 438, 181, 145, - 636, 648, 667, 568, 442, 217, 362, - 427, 440, 674, 524, 332, 117, -417, - 121, 295, 468, 465, 230, 44, -221, - -147, -240, 149, 80, 390, 278, 106, - -418, -556, 552, 511, 235, 144, -95, - 43, 193, 274, 150, 67, 34, -273, - -43, -126, 171, 416, 282, 63, -354, - -372, -86, -344, -108, -94, -182, -89, - -600, -840, -200, 465, 258, -11, -253, - -48, 329, 97, -290, -543, -795, -354, - -570, -117, 187, 10, -133, -416, -76, - -618, -129, -247, -371, 45, -76, 277, - -1022, -1079, 126, 474, 254, 127, 52, - -281, 76, -167, -361, -283, -551, -283, - -119, -52, -1, 134, -32, -204, -415, - 1064, 827, 637, 684, 464, 209, 12, - 482, 416, 449, 371, 335, 294, 194, - 719, 576, 365, 135, 113, 91, -199, - 298, 176, 493, 366, 194, 163, 36, - -35, -236, -259, -36, -4, 99, 152, - -98, -306, -27, 228, 90, 111, -86, - 91, 13, -211, -258, -106, 86, -64, - 73, -35, -57, -31, 162, 35, -192, - -109, -335, -629, -66, -61, -128, 322, - -495, -669, -728, 193, 31, -220, 122, - 324, 95, -89, -91, -409, -710, -154, - 0, -234, 92, 33, -343, -609, -220, - -343, -408, -476, -655, -153, 82, 222, - -490, -745, -255, 49, -48, 135, -127, - 119, -67, -328, -390, -272, -545, -56, - -57, -130, -10, -7, -164, -47, -22, - 984, 1064, 961, 568, 210, -27, 16, - 811, 691, 754, 514, 224, -35, 166, - 662, 704, 618, 386, 57, -211, -257, - 510, 359, 418, 393, 91, -144, -18, - -193, -31, -27, 223, 89, -143, 24, - -112, -98, 471, 319, 185, 3, 175, - 252, 146, -47, 272, 48, -211, -234, - 146, 69, 203, 364, 68, -52, 51, - -259, -478, -697, -349, -758, -501, 63, - -501, -769, -289, 79, -311, -497, -106, - 251, 53, -235, -469, -895, -884, 145, - -416, -551, 140, -133, -523, -775, 44, - -326, -423, -713, -497, -86, -431, 99, - -757, -772, -160, -76, -46, -32, 379, - 85, -35, -200, -401, -663, -1040, -247, - -180, -330, -92, -376, 27, -183, -110, - 1279, 1086, 781, 502, 324, 164, 157, - 682, 466, 449, 277, 146, 28, 409, - 635, 472, 390, 107, -232, -538, -139, - 196, 396, 332, 213, 209, -29, -81, - 150, -95, -312, 76, -77, -320, -50, - 46, 9, 47, 175, 139, 30, 384, - 218, 206, -24, -250, -96, -276, -183, - 26, 119, 38, 14, -4, -133, -52, - -477, -614, -987, -715, -631, -813, 200, - -744, -1009, -1065, -745, -631, -171, 18, - -137, -251, -483, -613, -980, -1203, 12, - -605, -767, -562, -686, -1088, -515, 58, - -202, -428, -782, -1072, -96, -234, -179, - -480, -709, -1070, -897, -131, -92, 321, - -145, -193, -512, -729, -572, -765, -210, - -331, -585, -525, -631, -281, -208, -303, - 1165, 1104, 939, 828, 716, 426, 155, - 6, -109, 820, 778, 415, 113, -27, - 381, 339, 314, 265, 121, -9, -474, - -373, 47, 584, 442, 99, -231, -113, - -496, -38, -285, 262, 305, 170, 4, - -587, -556, 69, 66, 471, 354, 13, - -138, 70, -18, 106, 67, 167, -302, - -445, -141, 185, 191, 151, 83, -133, - -257, -521, -720, -198, 134, -46, -182, - -819, -1168, -777, 512, 359, 95, -113, - 137, -2, -74, -138, -401, -114, -371, - -242, -466, 204, 223, -31, -212, -192, - -532, -637, -466, -686, 256, 277, -139, - -1141, -1244, -381, -75, -54, 14, 88, - -311, 115, -143, -499, -343, 124, -416, - -616, -147, -135, 43, -4, 121, -369, - 835, 783, 641, 390, 355, 350, 64, - 72, 194, 443, 467, 436, 219, 372, - 464, 369, 192, 4, -156, -72, -226, - 57, 206, 303, 205, 188, 101, 265, - -40, -205, -488, -184, 276, 64, -26, - -217, -433, -297, 137, 328, 308, -289, - 378, 81, -308, -465, 57, -37, 227, - -100, 24, -36, -151, 199, 8, 143, - -426, -697, -1059, -133, 388, 161, 321, - -644, -1023, -1271, 39, 66, -123, 70, - 372, 177, -173, -556, -553, -304, -189, - -117, -369, -425, -122, -462, -152, -73, - -649, -850, -1189, -767, 497, 360, 222, - -798, -1139, -1455, -190, 430, 234, 179, - 42, -94, -405, -692, 38, -202, -246, - -169, -366, -290, -88, -64, 32, -292, - 1010, 923, 938, 710, 465, 230, 342, - 217, 300, 1054, 675, 68, -458, -179, - 78, 453, 316, 18, -237, -496, -243, - 167, 21, 424, 215, -91, -303, -170, - -290, -81, -70, -67, 40, 54, -59, - -353, -427, -90, 53, 94, 9, 54, - -28, 318, 283, 15, -240, -58, 79, - -75, -121, 229, 35, 58, 6, -133, - -351, -514, -744, -834, -705, -137, 164, - -1124, -1388, -1055, -230, -73, 40, 36, - -163, -233, -532, -785, -1170, -697, 96, - -788, -959, -246, -430, -624, -165, -8, - -856, -540, -630, -907, -337, -70, 76, - -937, -1042, -659, -733, -208, 199, -26, - -523, 78, -98, -501, -869, -890, -81, - -624, -703, -45, -348, -25, 87, -186, - 1005, 823, 546, 249, 90, -22, 207, - 298, 397, 381, 319, 200, 62, 303, - 473, 379, 133, -247, -632, -441, 75, - 284, 208, 391, 115, -25, 44, 95, - -72, 79, -95, -63, -129, -293, 203, - -164, -349, 115, 122, 69, -1, 378, - 348, 170, 99, 58, -179, -302, 188, - -190, -2, 150, 23, -51, -11, 216, - -615, -863, -1090, -1427, -802, -48, -6, - -961, -1276, -1548, -727, -58, 56, 223, - -124, -255, -561, -988, -1277, -148, -82, - -480, -660, -891, -1191, -1339, -325, 20, - -621, -917, -1296, -1350, 264, 289, 50, - -844, -1022, -1345, -1329, -293, 46, 278, - -260, -468, -829, -1176, -533, -560, -78, - -215, -484, -822, -1233, -791, 15, -138, - 1301, 1317, 1262, 1048, 716, 357, -64, - 578, 824, 925, 802, 630, 362, 102, - 470, 925, 767, 514, 327, 190, -112, - 225, 492, 495, 437, 598, 384, -45, - 43, 82, -42, 175, 519, 342, -64, - -304, -154, 159, 576, 403, 221, 327, - 214, 244, 122, -62, 312, 92, -160, - 218, 208, 310, 268, 306, 323, -199, - -285, -269, -79, -124, -143, -153, 236, - -205, -384, -426, 344, 59, -185, -184, - -272, 247, 126, -210, -518, -468, 78, - -99, -120, 502, 160, -280, -557, 304, - -423, -17, -283, -443, 215, 212, -140, - -564, -684, -228, 510, 361, 130, 323, - -428, 335, 98, -65, 36, -215, -246, - -362, 51, 364, -16, -234, 150, -165, - 914, 883, 751, 653, 676, 464, -153, - 631, 545, 535, 720, 596, 360, -81, - 783, 712, 512, 439, 341, 251, -391, - 497, 417, 249, 372, 295, 173, -193, - 128, -110, -385, 93, 39, 173, -231, - 216, -59, -253, 462, 389, 154, 69, - 455, 270, -4, -337, -49, 233, -322, - 307, 143, 53, 218, 128, 236, -156, - -37, -186, -240, -411, -110, 9, 399, - -140, -365, -628, 258, 380, 214, 277, - 131, 454, 177, -285, -520, 108, -214, - 77, -141, 201, -123, -490, -131, 60, - -14, -194, -521, -741, 273, 362, -33, - -362, -566, -287, -228, 161, 237, 317, - -269, 195, -75, -375, -204, 11, 77, - -128, -264, -156, -223, -475, 265, 27, - 1238, 1147, 916, 689, 432, 210, -280, - 800, 664, 879, 726, 411, 160, -164, - 454, 686, 536, 275, 147, 46, 111, - 303, 486, 512, 355, 241, 181, -69, - 79, 92, 29, 147, 233, 52, 17, - -171, 289, 131, 439, 271, 3, -10, - 413, 241, 144, 174, 155, -2, 14, - 58, 217, 247, 219, 149, 175, -18, - 228, -8, -240, -206, -513, -191, 202, - -96, -272, -454, 33, -300, -575, 46, - -10, -108, -246, -347, -770, -535, 9, - -326, -430, -61, -321, -704, -299, 201, - -1, -280, -603, -419, -185, 18, -36, - -516, -522, -379, -291, -181, -97, 27, - -159, -313, -525, -224, -510, -831, -197, - -292, -459, -59, -310, -562, -143, -351, - 1066, 912, 631, 389, 207, 86, -224, - 596, 512, 596, 505, 314, 122, -48, - 787, 861, 441, -93, -303, 33, -190, - 257, 469, 337, 51, 15, 298, -93, - 295, 73, -119, 25, 36, 23, 108, - -28, -3, -32, 114, 21, 185, 107, - 482, 305, 15, -279, -319, 52, 96, - 226, 46, 115, 72, -136, 133, -125, - 18, -207, -559, -590, -503, -482, 321, - -571, -789, -951, -172, -441, -538, 113, - 181, 14, -310, -641, -1001, -202, 159, - -136, -393, -433, -513, -911, -144, -22, - 72, -265, -706, -954, -159, 53, 332, - -338, -591, -852, -383, -395, 56, 44, - 43, -158, -464, -897, -631, -157, -294, - -161, -128, -328, -573, -483, -125, 11, - 1017, 906, 1051, 1005, 679, 341, -102, - 359, 334, 1567, 1314, 723, 105, 10, - -65, 726, 529, 301, 220, 43, -273, - -510, 436, 719, 566, 358, 179, 114, - -560, 298, 133, -120, 342, 225, 14, - -899, -101, 217, 617, 400, 146, -58, - -41, 352, 82, -196, 39, 121, -167, - -212, 59, 447, 284, 423, 250, -169, - -371, -484, -596, 30, -41, 249, 22, - -372, -650, -794, 477, 445, 216, -79, - -352, 275, 17, -443, -929, 92, 19, - -699, -696, 431, 264, -49, -310, 182, - -978, -217, -430, -400, 101, 261, 72, - -929, -889, -357, -13, 463, 378, 236, - -826, 56, 30, -299, -360, -128, -51, - -878, -299, -111, 75, 65, 36, 3, - 817, 368, -25, 354, 697, 591, -173, - 309, 212, 222, 751, 484, 140, -56, - 593, 379, 70, -8, 258, 180, 110, - 165, -46, 255, 297, 219, 273, 105, - 160, -70, -358, -181, 379, 330, 319, - -238, -369, -198, 740, 580, 319, -143, - 201, 109, -202, -456, 328, 276, -141, - 203, 170, 111, 42, 207, 360, 188, - -345, -399, -513, -233, 650, 422, 81, - -635, -961, -1220, 463, 539, 204, 209, - 202, -25, -194, -498, -787, 193, -143, - -449, -538, 195, -106, -331, 68, 62, - -228, -477, -840, -576, 317, 128, 283, - -671, -937, -807, -114, 391, 335, -62, - 246, 2, -314, -679, -303, 180, -88, - -107, -272, 90, -198, -28, 290, -112, - 885, 1149, 1021, 712, 496, 281, -83, - 269, 492, 787, 643, 347, 70, 124, - 336, 636, 499, 92, -229, -179, 191, - 26, 402, 564, 340, 149, -11, 135, - -440, 561, 470, 204, -72, -186, 140, - -720, 14, 355, 229, 68, -133, 465, - 110, 310, 103, 12, 106, 29, 158, - -178, 113, 161, 142, 121, 115, 27, - -651, -414, -645, -152, -164, -13, -429, - -639, -944, -681, -104, -81, 52, -189, - -663, -164, -316, -683, -954, -205, -83, - -609, -669, -172, -517, -694, 283, -80, - -646, -152, -383, -678, -246, -40, -143, - -747, -796, -745, -390, -98, 43, 275, - -599, -199, -398, -433, -436, -538, 31, - -1107, -568, -376, -265, -126, -21, 1, - 847, 573, 308, 392, 305, 101, 55, - 273, 293, 201, 267, 346, 201, 123, - 727, 480, 226, 2, -65, -138, 164, - 273, 208, 173, 292, 12, 253, 174, - 340, 207, 180, 88, 116, 46, 475, - -460, -166, -30, 13, 110, 173, 396, - 137, 88, 43, -137, -94, 34, 284, - 96, -14, 226, 40, 63, 70, 130, - -467, -735, -1012, -1174, -307, 305, -67, - -612, -920, -1146, -567, -8, 92, -25, - -182, -271, -492, -754, -857, 287, -75, - -494, -787, -689, -683, -709, 137, -326, - -288, -550, -903, -1105, 334, 321, -62, - -354, -653, -834, -445, 1, 377, -152, - -162, -306, -608, -937, -297, 247, -192, - -234, -477, -244, -488, -266, 342, -332 -}; - -/* ISF codebook - 46b, 2nd stage, 1st split (only in AMR-WB IO mode) */ -const Word16 dico21_isf_46b_fx[] = -{ - 329, 409, 249, - -33, 505, 160, - -29, -14, 582, - -262, 127, 354, - 145, 237, 175, - -152, 245, 122, - 27, 42, 340, - -84, -93, 311, - 285, 222, -156, - 47, -43, -504, - 234, 121, 385, - 104, -317, 45, - 176, 195, 8, - 104, -59, -94, - 177, 53, 192, - -34, -127, 152, - 570, 277, -34, - -67, -329, -639, - -157, -272, 462, - -177, -462, 198, - 322, 179, 115, - -386, 171, 19, - 19, -12, 195, - -120, -252, 201, - 304, 36, -336, - -128, -221, -380, - 171, -185, 296, - -242, -312, 23, - 198, 39, 16, - -3, -177, -111, - 111, -93, 76, - -92, -223, 4, - 177, 406, -44, - -168, 380, -149, - -4, 273, 331, - -420, 513, 277, - 21, 247, 47, - -58, 131, -2, - -3, 134, 180, - -145, 40, 175, - 189, 74, -145, - -27, -45, -325, - 370, -114, -21, - -83, -415, -173, - 77, 95, -51, - -40, -30, -67, - 71, 88, 86, - -35, -98, 14, - 69, 197, -334, - -196, 79, -231, - -348, -137, 218, - -352, -89, -85, - 47, 201, -130, - -165, 37, -15, - -43, 3, 86, - -161, -108, 79, - 83, 21, -237, - -81, -149, -238, - 150, -186, -251, - -186, -249, -162, - -19, 66, -139, - -26, -50, -181, - 24, 11, 0, - -130, -105, -98 -}; -/* ISF codebook - 46b, 2nd stage, 2st split (only in AMR-WB IO mode) */ -const Word16 dico22_isf_46b_fx[]= -{ - -127, 310, 42, - -242, 197, 5, - -151, 84, -17, - -214, 127, -149, - -247, -131, 159, - -268, -267, -95, - -217, 1, -79, - -271, -80, -185, - -45, 436, 159, - 165, 199, 391, - -33, 81, 187, - -66, -42, 355, - -298, -57, 343, - -108, -537, 226, - -144, -23, 193, - 176, -402, 87, - 53, 296, 25, - -84, 253, -104, - -58, 105, -126, - -169, 174, -314, - -48, 44, -294, - -164, -417, -242, - -139, 3, -194, - -155, -207, -211, - 119, 322, 213, - 333, 50, 380, - 237, 247, -2, - 466, -16, 201, - 238, -255, -107, - 67, -440, -149, - 122, -88, -139, - 88, -247, -73, - -41, 231, 167, - -62, 155, 16, - -65, 16, 77, - -68, -2, -63, - -151, -300, 160, - -18, -333, 54, - -56, -94, 5, - 2, -190, 14, - 92, 148, 209, - 108, 9, 272, - 108, 35, 110, - 142, -85, 145, - 47, -157, 279, - 3, -320, 246, - 43, -72, 68, - 86, -217, 135, - 36, 140, 79, - 56, 175, -49, - 26, 45, 3, - 73, 55, -101, - 109, -183, -242, - -4, -283, -242, - 48, -68, -48, - -6, -153, -122, - 161, 196, 96, - 232, 80, 190, - 165, 97, 11, - 258, -31, 71, - 267, -77, -91, - 311, -209, 87, - 152, -14, -22, - 150, -149, 9, - -324, 557, 187, - -384, 307, 46, - -251, 27, 77, - -365, 77, -52, - -482, -84, 160, - -424, -515, -64, - -294, -120, -4, - -476, -116, -109, - -97, 318, 365, - 106, 627, 445, - -190, 120, 287, - -146, 65, 619, - -427, 242, 363, - -361, -371, 432, - -347, 102, 168, - -629, 195, -14, - -65, 476, -47, - -297, 320, -168, - -55, 356, -264, - -391, 82, -286, - -51, -31, -556, - -178, -399, -586, - -205, -49, -360, - -343, -238, -337, - 220, 457, 58, - 561, 467, 259, - 340, 270, -168, - 450, 77, -280, - 60, 167, -413, - 133, -252, -492, - 216, 157, -290, - 282, 0, -495, - -226, 293, 183, - -157, 135, 122, - -158, -59, 39, - -133, -118, -97, - -332, -309, 113, - -160, -425, -6, - -149, -211, 24, - -80, -277, -90, - -11, 125, 338, - 130, -71, 465, - 5, -45, 184, - 237, -95, 253, - -139, -197, 297, - -19, -300, 511, - -63, -152, 139, - 250, -289, 336, - 124, 339, -150, - 34, 176, -208, - 171, 166, -116, - 94, 38, -229, - 75, -65, -339, - -78, -205, -385, - 0, -30, -163, - -56, -110, -242, - 321, 244, 194, - 505, 238, -1, - 317, 116, 65, - 309, 88, -74, - 452, -51, -50, - 334, -217, -290, - 211, 41, -152, - 238, -55, -260 -}; - -/* ISF codebook - 46b, 2nd stage, 3rd split (only in AMR-WB IO mode) */ -const Word16 dico23_isf_46b_fx[]= -{ - -10, 151, 359, - 136, 298, 223, - 255, -104, 290, - 423, 6, 183, - -270, -269, -98, - -52, -82, 13, - -82, -274, -97, - 90, -246, -72, - -299, -70, 421, - -88, 365, 430, - 187, -318, 381, - 380, 37, 488, - -373, -316, 79, - -308, -101, 5, - -135, -451, 8, - 72, -421, -154, - 180, 170, -121, - 62, 177, -40, - 326, 80, -105, - 248, 263, -5, - -168, -181, -221, - -2, -23, -158, - -14, -149, -121, - 119, -91, -147, - 119, 332, -153, - 49, 303, 34, - 442, -55, -69, - 217, 454, 58, - -359, -187, -375, - -42, 50, -274, - -8, -267, -249, - 85, -86, -346, - -77, -40, 345, - 89, 134, 219, - 156, -80, 160, - 108, 40, 116, - -158, -206, 29, - 5, -32, 175, - -65, -158, 146, - 55, -78, 73, - -114, -222, 353, - -47, 81, 211, - 49, -151, 268, - 105, 4, 302, - -263, -132, 183, - -151, -28, 201, - -177, -307, 166, - 101, -221, 130, - 74, 58, -98, - 32, 44, 13, - 194, 30, -142, - 170, 96, 8, - -136, -119, -91, - -65, 8, -55, - 3, -188, 12, - 45, -63, -49, - 149, -21, -19, - 24, 144, 95, - 254, -22, 60, - 161, 196, 96, - -158, -61, 48, - -70, 33, 82, - -23, -321, 58, - 155, -147, 5, - -364, 328, 77, - -21, 453, 173, - -108, 82, 630, - 367, 263, 208, - -300, -62, -176, - -205, 143, -158, - -169, -410, -264, - 257, -269, -100, - -636, 289, -2, - -292, 627, 173, - -382, -363, 387, - 248, 524, 447, - -521, -111, -107, - -395, 118, -274, - -343, -680, -125, - -172, -447, -663, - 75, 148, -367, - -79, 263, -94, - 249, 148, -286, - 380, 271, -162, - -142, -4, -186, - -57, 111, -125, - -35, -108, -254, - 100, 29, -242, - -80, 303, -264, - -78, 464, -57, - 248, -22, -494, - 661, 662, 44, - -193, -40, -330, - -178, 145, -337, - -90, -199, -400, - -40, -23, -498, - -192, 114, 315, - -41, 244, 190, - 88, -97, 485, - 241, 80, 212, - -246, 40, 87, - -156, 147, 134, - -2, -334, 239, - 308, -203, 110, - -459, 251, 422, - -218, 310, 228, - -86, -346, 654, - 184, 175, 425, - -481, -63, 169, - -349, 117, 188, - -125, -560, 310, - 158, -416, 94, - 46, 171, -192, - -63, 157, 14, - 256, -35, -271, - 322, 123, 53, - -214, 4, -76, - -156, 86, -18, - 128, -197, -232, - 265, -90, -98, - -308, 332, -145, - -131, 308, 58, - 509, 59, -339, - 562, 196, -14, - -378, 100, -47, - -234, 202, 1, - 104, -270, -493, - 319, -210, -325 -}; -/* ISF codebook - 46b, 2nd stage, 4th split (only in AMR-WB IO mode) */ -const Word16 dico24_isf_46b_fx[]= -{ - -79, -89, -4, - -171, 77, -211, - 160, -193, 98, - 120, -103, 323, - 32, -22, -129, - 72, 78, -268, - 182, -76, -66, - 309, 99, -145, - -229, -157, -84, - -383, 98, -71, - -90, -352, 12, - -284, -178, 178, - -65, -125, -166, - -87, -175, -351, - 42, -198, -48, - 154, -140, -243, - -77, 18, 108, - -39, 355, 91, - 87, 8, 155, - -4, 158, 239, - 128, 95, -54, - 7, 246, -124, - 258, 15, 89, - 206, 216, 98, - -201, 9, 18, - -312, 233, 204, - -39, -174, 155, - -144, -9, 284, - -57, 70, -69, - -157, 187, 18, - 54, -30, 23, - 24, 135, 55 -}; - -/* ISF codebook - 46b, 2nd stage, 5th split (only in AMR-WB IO mode) */ -const Word16 dico25_isf_46b_fx[]= -{ - 169, 142, -119, 115, - 206, -20, 94, 226, - -106, 313, -21, 16, - -62, 161, 71, 255, - -89, 101, -185, 125, - 72, -30, -201, 344, - -258, 33, -8, 81, - -104, -154, 72, 296, - 144, -68, -268, -25, - 81, -78, -87, 106, - 22, 155, -186, -119, - -46, -28, 27, 91, - -114, -37, -175, -33, - -94, -222, -189, 122, - -132, -119, -191, -270, - -172, -173, 18, -43, - 279, 135, -42, -128, - 187, -86, 229, -138, - 159, 240, 140, 46, - 69, 25, 227, 77, - 21, 115, 13, 8, - 68, -248, 126, 81, - -150, 137, 207, -9, - -154, -133, 289, 67, - 143, -37, -86, -326, - 180, -32, 19, -23, - 26, 168, 116, -233, - -32, -26, 118, -78, - 3, -8, -45, -115, - 57, -215, -54, -83, - -209, 112, -22, -167, - -91, -151, 168, -262 -}; - -/* ISF codebook - 36b, 2nd stage, 1st split (only in AMR-WB IO mode) */ -const Word16 dico21_isf_36b_fx[]= -{ - -52, -96, 212, 315, -73, - 82, -204, 363, 136, -197, - -126, -331, 183, 218, 143, - -49, -41, 557, 230, 72, - 2, -73, 163, 377, 221, - 133, 111, 278, 215, -110, - -102, -20, 284, 113, 273, - 84, 319, 290, 18, 85, - -25, -5, 125, 132, -204, - -38, -5, 286, -9, -356, - -140, -256, 92, 117, -189, - -144, 191, 313, 51, -98, - 167, -10, 44, 247, 36, - 381, 197, 238, 74, 6, - 38, -408, 29, -3, -85, - 92, 266, 157, -25, -200, - 161, -121, 70, 84, -140, - -16, -86, 112, -94, -189, - -269, -270, 351, 107, -24, - -68, -67, 492, -103, -155, - -53, -131, 62, 122, 10, - 135, 84, 283, -55, -120, - -12, -219, 331, -81, 167, - 220, -136, 147, -172, -42, - 140, -95, -109, -88, -194, - 0, -2, -4, -33, -381, - -66, -217, 152, -186, -402, - 244, 108, 156, -140, -395, - 113, -136, -196, 110, -24, - 214, 118, 11, -64, -131, - -110, -286, -6, -332, 16, - 94, 97, 79, -291, -205, - -5, -39, -20, 252, -96, - 76, 174, 101, 163, 61, - -69, -239, -55, 399, 6, - -115, 319, 164, 275, 196, - -15, 36, -47, 331, 121, - 226, 209, 271, 325, 184, - 13, -80, -218, 471, 353, - 288, 378, 16, -51, 251, - 174, 116, 52, 149, -279, - 235, 276, 39, 120, -48, - 0, -108, -108, 241, -339, - -93, 534, 45, 33, -87, - 194, 149, -71, 405, -44, - 409, 370, 81, -186, -154, - 25, -102, -448, 124, -173, - 22, 408, -110, -310, -214, - -26, 23, -83, 114, 14, - -110, 164, 52, 223, -82, - 37, -25, -263, 306, -15, - -466, 415, 292, 165, -18, - 29, -19, -171, 155, 182, - 179, 144, -27, 231, 258, - -103, -247, -396, 238, 113, - 375, -154, -109, -4, 156, - 98, 85, -292, -5, -124, - 116, 139, -116, -98, -294, - -14, -83, -278, -117, -378, - 106, 33, -106, -344, -484, - 119, 17, -412, 138, 166, - 384, 101, -204, 88, -156, - -121, -284, -300, -1, -166, - 280, 33, -152, -313, -81, - -37, 22, 229, 153, 37, - -60, -83, 236, -8, -41, - -169, -228, 126, -20, 363, - -235, 17, 364, -156, 156, - -25, -30, 72, 144, 156, - 153, -26, 256, 97, 144, - -21, -37, 48, -65, 250, - 63, 77, 273, -128, 124, - -129, -26, 40, 9, -115, - -6, 82, 38, -90, -182, - -336, -13, 28, 158, 91, - -30, 241, 137, -170, -17, - 146, 14, -11, 33, 61, - 192, 197, 54, -84, 85, - 23, -200, -78, -29, 140, - 122, 237, 106, -341, 136, - -57, -142, -85, -16, -74, - -59, -90, -8, -187, -20, - -211, -267, 216, -179, -110, - -50, -7, 220, -267, -70, - -57, -42, -17, -15, 71, - 32, 21, 63, -137, 33, - -137, -175, 104, -68, 97, - -67, -43, 133, -301, 221, - -116, -200, -81, -92, -272, - -64, -41, -54, -244, -220, - -287, -242, -50, -87, -89, - -245, 236, 102, -166, -295, - 66, 24, -162, -71, 95, - 66, 136, -90, -220, -36, - -98, -161, -222, -188, 29, - -18, 18, -19, -415, 9, - 49, 61, 100, 39, -56, - -111, 82, 135, -31, 52, - -90, -153, -93, 189, 182, - -214, 295, 119, -74, 284, - 2, 137, 37, 47, 182, - 92, 117, 184, -53, 373, - -21, -14, -35, 136, 391, - 146, 129, -164, -28, 333, - 92, 80, -84, 100, -134, - -8, 217, -32, 3, -47, - -151, 251, -215, 142, 92, - -224, 310, -172, -275, 98, - 159, 155, -177, 112, 53, - 205, 27, 8, -240, 192, - 169, 120, -319, -201, 106, - 11, 36, -86, -237, 455, - -109, -154, -163, 174, -55, - -38, 32, -101, -78, -59, - -205, -321, -97, 69, 79, - -310, 44, 18, -185, 34, - -115, -20, -148, -39, 203, - -29, 154, -30, -158, 166, - -45, -131, -317, -24, 363, - -165, -205, -112, -222, 265, - -32, -44, -150, 54, -193, - -6, -38, -255, -169, -115, - -266, 87, -189, -36, -169, - -60, -87, -266, -436, -170, - -68, -81, -278, 24, 38, - -23, -19, -155, -256, 141, - -61, -226, -565, -175, 71, - 9, -29, -237, -515, 263 -}; - -/* ISF codebook - 36b, 2nd stage, 2nd split (only in AMR-WB IO mode) */ -const Word16 dico22_isf_36b_fx[]= -{ - -298, -6, 95, 31, - -213, -87, -122, 261, - 4, -49, 208, 14, - -129, -110, 30, 118, - -214, 258, 110, -235, - -41, -18, -126, 120, - 103, 65, 127, -37, - 126, -36, -24, 25, - -138, -67, -278, -186, - -164, -194, -201, 78, - -211, -87, -51, -221, - -174, -79, -94, -39, - 23, -6, -157, -240, - 22, -110, -153, -68, - 148, -5, -2, -149, - -1, -135, -39, -179, - 68, 360, -117, -15, - 137, 47, -278, 146, - 136, 260, 135, 65, - 61, 116, -45, 97, - 231, 379, 87, -120, - 338, 177, -272, 3, - 266, 156, 28, -69, - 260, 84, -85, 86, - -266, 154, -256, -182, - -17, -65, -304, -6, - -40, 175, -151, -180, - -27, 27, -87, -63, - 121, 114, -166, -469, - 159, -66, -323, -231, - 214, 152, -141, -212, - 137, 36, -184, -51, - -282, -237, 40, 10, - -48, -235, -37, 251, - -54, -323, 136, 29, - -88, -174, 213, 198, - -390, 99, -63, -375, - 107, -169, -164, 424, - 69, -111, 141, -167, - 74, -129, 65, 144, - -353, -207, -205, -109, - -160, -386, -355, 98, - -176, -493, -20, -143, - -252, -432, -2, 216, - -90, -174, -168, -411, - 13, -284, -229, -160, - -87, -279, 34, -251, - -75, -263, -58, -42, - 420, 53, -211, -358, - 384, -35, -374, 396, - 68, -228, 323, -2, - 167, -307, 192, 194, - 459, 329, -5, -332, - 375, 79, -7, 313, - 282, -124, 200, -92, - 271, -162, -70, 180, - -157, -298, -514, -309, - 58, -163, -546, 18, - 124, -364, 167, -238, - 83, -411, -117, 96, - 140, -112, -388, -624, - 259, -133, -317, 41, - 163, -130, -64, -334, - 226, -165, -124, -110, - -466, -61, 6, 229, - -153, 205, -145, 242, - -159, 48, 195, 148, - -58, 28, 31, 279, - -303, 185, 279, -4, - -61, 197, 59, 86, - -114, 123, 168, -52, - 35, 36, 100, 126, - -407, 102, -77, -40, - -338, -1, -342, 156, - -179, 105, -34, -97, - -185, 84, -35, 108, - -133, 107, -91, -357, - -180, 54, -229, 24, - -44, 47, 47, -182, - -66, 13, 45, 4, - -339, 251, 64, 226, - -42, 101, -350, 275, - -99, 398, 142, 121, - 111, 12, -102, 260, - 0, 505, 260, -94, - 161, 285, -96, 224, - -4, 206, 314, 33, - 167, 139, 88, 204, - -235, 316, -60, -25, - -8, -150, -312, 201, - -36, 292, 61, -104, - -40, 174, -162, 42, - -21, 402, -29, -351, - 21, 152, -360, -93, - 57, 191, 212, -196, - 76, 158, -21, -69, - -328, -185, 331, 119, - -53, 285, 56, 337, - -107, -24, 405, 29, - -18, 137, 272, 277, - -255, 22, 173, -191, - 295, 322, 325, 302, - 21, -27, 332, -178, - 119, 13, 271, 129, - -455, -180, 116, -191, - -227, 62, -148, 524, - -176, -287, 282, -157, - -243, 13, 199, 430, - -59, -49, 115, -365, - 72, -172, -137, 93, - -138, -126, 141, -84, - 5, -124, 38, -20, - -258, 311, 601, 213, - 94, 130, -61, 502, - -1, -157, 485, 313, - 146, -74, 158, 345, - 276, 135, 280, -57, - 490, 252, 99, 43, - 267, -74, 429, 105, - 278, -23, 119, 94, - -542, 488, 257, -115, - -84, -244, -438, 478, - -113, -545, 387, 101, - -95, -306, 111, 498, - 95, 166, 22, -301, - 420, -15, -58, -78, - 270, 29, 122, -282, - 160, -240, 50, -38 -}; -/* ISF codebook - 36b, 2nd stage, 3rd split (only in AMR-WB IO mode) */ -const Word16 dico23_isf_36b_fx[]= -{ - 81, -18, 68, -27, -122, -280, -4, - 45, -177, 209, -30, -136, -74, 131, - -44, 101, -75, -88, -48, -137, -54, - -245, -28, 63, -18, -112, -103, 58, - -79, -6, 220, -65, 114, -35, -50, - 109, -65, 143, -114, 129, 76, 125, - 166, 90, -61, -242, 186, -74, -43, - -46, -92, 49, -227, 24, -155, 39, - 67, 85, 99, -42, 53, -184, -281, - 142, -122, 0, 21, -142, -15, -17, - 223, 92, -21, -48, -82, -14, -167, - 51, -37, -243, -30, -90, 18, -56, - 54, 105, 74, 86, 69, 13, -101, - 196, 72, -89, 43, 65, 19, 39, - 121, 34, 131, -82, 25, 213, -156, - 101, -102, -136, -21, 57, 214, 22, - 36, -124, 205, 204, 58, -156, -83, - 83, -117, 137, 137, 85, 116, 44, - -92, -148, -68, 11, -102, -197, -220, - -76, -185, -58, 132, -26, -183, 85, - -7, -31, -2, 23, 205, -151, 10, - -27, -37, -5, -18, 292, 131, 1, - 117, -168, 9, -93, 80, -59, -125, - -182, -244, 98, -24, 135, -22, 94, - 221, 97, 106, 42, 43, -160, 83, - 25, -64, -21, 6, 14, -15, 154, - 126, 15, -140, 150, -10, -207, -114, - 79, -63, -211, -70, -28, -217, 165, - 46, 38, -22, 281, 132, -62, 109, - 112, 54, -112, -93, 208, 27, 296, - 115, 10, -147, 41, 216, 42, -276, - 50, -115, -254, 167, 117, -2, 61, - 17, 144, 34, -72, -186, -150, 272, - -29, -66, -89, -95, -149, 129, 251, - 122, 0, -50, -234, -91, 36, 26, - -105, -102, -88, -121, -236, -7, -11, - -204, 109, 5, -191, 105, -15, 163, - -80, 32, -24, -209, 41, 294, 70, - -106, -94, -204, -118, 120, -50, -37, - -82, -241, 46, -131, -29, 150, -55, - 33, 155, 120, -89, -8, 7, 62, - 213, 82, 61, 18, -161, 144, 152, - 30, 131, 65, -87, -255, -17, -107, - -8, 85, -64, 51, -162, 223, -53, - -134, 261, 69, -56, 218, 72, -111, - 2, 155, -113, -87, 49, 85, -28, - -163, 42, -1, -196, 7, 39, -245, - 14, -137, -79, 11, -160, 202, -293, - -94, 33, 208, 100, 56, -44, 326, - -78, -41, 232, 13, -142, 227, 80, - -16, -87, 201, 33, -133, 15, -183, - -58, -192, -47, 184, -128, 133, 99, - -205, 11, -155, 78, 52, 72, 141, - -246, 26, 99, 151, 59, 115, -64, - -79, -47, -16, -14, 6, 47, -43, - -72, -178, -27, 162, 112, 43, -174, - -175, 238, 186, 71, -54, -188, -76, - -225, 233, 39, -39, -158, 122, 44, - -26, 43, 84, 130, -93, -51, 22, - 3, 92, -150, 136, -182, -57, 97, - -131, 179, -78, 80, 91, -165, 90, - -2, 148, 15, 130, 65, 175, 117, - -138, 114, -137, 132, 3, -10, -186, - 140, -4, -37, 254, -62, 92, -109 -}; - -/* ISF codebook for SID frames - 28b, 1st split */ -const Word16 dico1_ns_28b_fx[]= -{ - -269, -673, - -222, -537, - -233, -430, - -138, -451, - -212, -331, - -192, -241, - -87, -231, - -191, -128, - -70, -106, - -164, -6, - 74, -179, - 27, -33, - -102, 74, - -162, 115, - -94, 172, - -6, 130, - -143, 234, - 14, 218, - -65, 270, - 88, 182, - -124, 341, - -44, 381, - 38, 335, - 117, 274, - -112, 454, - 74, 431, - -5, 488, - 175, 384, - -83, 561, - 122, 529, - 21, 601, - 229, 481, - 231, 303, - 226, 608, - 300, 372, - 210, 187, - 306, 265, - 328, 473, - 382, 331, - 371, 132, - 139, 58, - 365, 21, - 250, -82, - 443, 218, - 483, 110, - 426, 415, - 579, 222, - 518, 333, - 573, 448, - 455, 529, - 685, 329, - 332, 580, - 595, 593, - 468, 645, - 762, 517, - 326, 709, - 485, 793, - 130, 684, - 671, 737, - 354, 876, - 88, 806, - -65, 706, - -35, 1016, - 266, 1123 -}; -/* ISF codebook for SID frames - 28b, 2nd spilt */ -const Word16 dico2_ns_28b_fx[]= -{ - -824, -884, -949, - -805, -456, -418, - -442, -438, -541, - -217, -578, -793, - -168, -444, -582, - -287, -492, -274, - -552, -297, -300, - -163, -333, -358, - -370, -232, -232, - -175, -358, -159, - -381, -21, -357, - -184, -159, -162, - -53, -191, -280, - 18, -267, -215, - -138, 61, -283, - 71, -95, -294, - 13, -156, -546, - 0, -83, -79, - 44, 97, -316, - 178, -52, -213, - 222, -261, -422, - 237, -118, -44, - 141, 145, -132, - 363, 81, -287, - 213, 65, 34, - -107, 94, -5, - 91, -29, 126, - -355, 51, -41, - -219, -76, 145, - -63, 100, 244, - -719, 44, 27, - -572, -124, 155, - -423, 133, 315, - -917, 71, 224, - -268, 318, 131, - -93, -190, 420, - -97, 122, 491, - -79, 317, 355, - 130, 100, 325, - 86, -293, 210, - 133, 258, 161, - 176, -73, 465, - 195, 300, 384, - 348, 22, 221, - 376, 183, 409, - 377, 286, 202, - 242, 213, 659, - 257, 565, 248, - 344, 408, -76, - 405, 440, 509, - 612, 385, 379, - 536, 607, 216, - -56, 582, 192, - 100, 517, 567, - -365, 448, 445, - 728, 347, 10, - 505, 357, 759, - 636, 582, 658, - 335, 517, 852, - 378, 809, 572, - -195, 878, 829, - 529, 707, 987, - 918, 726, 392, - 1250, 997, 1063 -}; - -/* ISF codebook for SID frames - 28b, 3rd spilt */ -const Word16 dico3_ns_28b_fx[]= -{ - -805, -838, -774, - -522, -627, -828, - -477, -486, -603, - -295, -481, -634, - -366, -384, -393, - -186, -414, -396, - -237, -394, -106, - -252, -202, -275, - -61, -177, -442, - -84, -198, -199, - -179, -125, -31, - -72, -47, -163, - -298, -220, 215, - -64, -168, 251, - -133, 156, -59, - -30, -2, 127, - 54, 66, -61, - -233, 21, 251, - 209, -50, 32, - 33, 194, 136, - -117, -18, 475, - 202, 46, 309, - 256, 185, 53, - 35, 200, 390, - 200, 263, 242, - -216, 302, 294, - 128, 358, 0, - 19, 431, 287, - 224, 447, 280, - 367, 165, 213, - 397, 314, 319, - 383, 379, 75, - 277, 325, 462, - 394, 505, 334, - 251, 98, -213, - 450, 153, 448, - 565, 226, 76, - 470, 383, 502, - 635, 390, 278, - 237, 135, 620, - 342, 401, 649, - 331, 551, 518, - 130, 418, 592, - 531, 306, 737, - 729, 389, 580, - 497, 557, 699, - 296, 383, 874, - 283, 624, 759, - 126, 622, 476, - 559, 595, 472, - 382, 770, 616, - 719, 613, 745, - 540, 639, 928, - 517, 826, 801, - 684, 811, 604, - 752, 786, 857, - 933, 661, 350, - 694, 450, 1061, - 562, 911, 1051, - 824, 813, 1104, - 758, 1047, 882, - 1140, 917, 889, - 1039, 1246, 1426, - 1483, 1666, 1876 -}; -/* ISF codebook for SID frames - 28b, 4th spilt */ -const Word16 dico4_ns_28b_fx[]= -{ - -776, -854, -891, -920, - -552, -610, -663, -741, - -321, -370, -476, -565, - 274, -160, -456, 201, - 265, 67, -160, -306, - -8, -210, 79, 272, - 163, 236, 307, 308, - 578, 317, 64, 298, - -9, 197, 342, 620, - 343, 232, 314, 622, - 173, 149, 548, 527, - 356, 370, 481, 376, - 135, 444, 488, 556, - 391, 471, 487, 653, - 228, 424, 576, 835, - 422, 372, 722, 682, - 295, 673, 693, 635, - 539, 596, 590, 449, - 475, 618, 659, 818, - 735, 517, 491, 673, - 602, 346, 257, 877, - 625, 635, 849, 720, - 727, 818, 698, 595, - 653, 481, 690, 1139, - 814, 762, 704, 908, - 507, 747, 898, 936, - 848, 855, 924, 785, - 646, 1037, 882, 795, - 772, 845, 1024, 1151, - 1133, 983, 818, 921, - 940, 1068, 1252, 1302, - 1588, 1767, 1718, 1513 -}; -/* ISF codebook for SID frames - 28b, 5th spilt */ -const Word16 dico5_ns_28b_fx[]= -{ - -810, -879, -945, -254, - 248, 184, 671, 128, - 288, 703, 918, 99, - 658, 558, 662, 219, - 552, 585, 910, 208, - 559, 804, 759, 119, - 606, 774, 921, -139, - 782, 761, 748, 208, - 756, 708, 983, 56, - 544, 864, 1010, 152, - 737, 698, 987, 299, - 771, 924, 879, 103, - 536, 785, 961, 405, - 667, 916, 801, 328, - 738, 705, 773, 439, - 823, 871, 992, 355, - 640, 1004, 1052, 369, - 724, 822, 949, 597, - 415, 655, 729, 482, - 1009, 896, 793, 363, - 908, 803, 687, -25, - 1016, 838, 1011, 189, - 947, 1112, 942, 222, - 914, 1049, 981, 527, - 956, 987, 1011, -120, - 781, 1049, 1121, 92, - 1178, 1053, 884, 47, - 1123, 1059, 1182, 118, - 933, 972, 1277, 357, - 1109, 918, 1101, 503, - 1039, 1286, 1220, 317, - 1351, 1207, 1010, 326 -}; - -/*----------------------------------------------------------------------------------* - * table of cos(x) in Q15 used in FFT for spectral analysis - *----------------------------------------------------------------------------------*/ - - -/*------------------------------------------------------------------------------* - * Critical bands in Q0 - *------------------------------------------------------------------------------*/ - -const Word16 wind_sss_fx[LEN_WIN_SSS] = /*window for subsampling*/ -{ - 2621, 2627, 2645, 2675, 2717, 2771, 2836, 2914, - 3003, 3103, 3216, 3340, 3475, 3621, 3779, 3948, - 4127, 4318, 4519, 4730, 4952, 5184, 5426, 5677, - 5938, 6209, 6488, 6777, 7074, 7379, 7693, 8015, - 8344, 8681, 9025, 9375, 9733, 10097, 10466, 10842, - 11223, 11609, 12000, 12395, 12795, 13198, 13605, 14016, - 14429, 14845, 15263, 15683, 16105, 16527, 16951, 17376, - 17800, 18225, 18649, 19072, 19495, 19916, 20335, 20752, - 21166, 21578, 21987, 22392, 22794, 23191, 23585, 23973, - 24357, 24735, 25108, 25474, 25835, 26189, 26537, 26877, - 27210, 27536, 27853, 28163, 28464, 28757, 29041, 29316, - 29582, 29838, 30085, 30322, 30549, 30765, 30972, 31167, - 31352, 31526, 31690, 31842, 31983, 32112, 32230, 32337, - 32432, 32515, 32586, 32646, 32694, 32730, 32754, 32766, - 32767, 32096, 30111, 26894, 22575, 17333, 11380, 4962 -}; -/*----------------------------------------------------------------------------------* - * Low-pass FIR filter for low-frequency post-filtering @ 8kHz - * fir1(240,(3900/32000),hanning(241))*5 - *----------------------------------------------------------------------------------*/ - -const Word16 filter5_39s320_120_fx[121] = /* Q15 */ -{ - 19968, 19480, 18061, 15834, 12993, 9779, 6458, 3290, - 506, -1713, -3253, -4075, -4212, -3762, -2873, -1720, - -488, 654, 1568, 2160, 2389, 2263, 1838, 1201, - 460, -275, -903, -1348, -1566, -1546, -1312, -914, - -422, 90, 547, 891, 1083, 1108, 975, 716, - 376, 9, -331, -599, -762, -805, -732, -562, - -325, -61, 192, 399, 533, 582, 546, 435, - 272, 83, -103, -259, -366, -413, -398, -328, - -218, -86, 46, 161, 243, 283, 280, 238, - 166, 77, -14, -94, -153, -185, -188, -163, - -119, -62, -3, 50, 90, 113, 117, 104, - 78, 44, 9, -23, -47, -62, -65, -58, - -45, -27, -8, 9, 21, 28, 30, 27, - 20, 13, 5, -2, -7, -9, -9, -8, - -6, -3, -1, 0, 1, 1, 1, 0, - 0 - -}; - - -const Word16 Assym_window_W16fx[L_LP] = /*Q15*/ -{ - 2621, 2624, 2630, 2640, 2655, 2674, 2698, 2725, - 2757, 2792, 2833, 2877, 2925, 2978, 3034, 3095, - 3160, 3229, 3302, 3379, 3460, 3545, 3634, 3727, - 3824, 3925, 4029, 4138, 4250, 4366, 4486, 4609, - 4737, 4867, 5002, 5140, 5281, 5426, 5575, 5727, - 5882, 6040, 6202, 6367, 6535, 6707, 6881, 7059, - 7239, 7422, 7609, 7798, 7990, 8184, 8382, 8581, - 8784, 8989, 9196, 9406, 9618, 9832, 10049, 10268, - 10489, 10711, 10936, 11163, 11391, 11622, 11854, 12087, - 12322, 12559, 12797, 13037, 13278, 13520, 13763, 14007, - 14253, 14499, 14746, 14994, 15243, 15493, 15743, 15994, - 16245, 16496, 16748, 17000, 17253, 17505, 17758, 18010, - 18263, 18515, 18767, 19019, 19270, 19521, 19772, 20022, - 20271, 20519, 20767, 21014, 21260, 21504, 21748, 21991, - 22232, 22473, 22711, 22949, 23185, 23419, 23652, 23883, - 24113, 24340, 24566, 24790, 25012, 25231, 25449, 25664, - 25878, 26089, 26297, 26503, 26707, 26908, 27107, 27303, - 27496, 27687, 27874, 28059, 28241, 28420, 28596, 28769, - 28939, 29105, 29269, 29429, 29586, 29739, 29889, 30036, - 30179, 30319, 30455, 30588, 30717, 30842, 30964, 31082, - 31196, 31306, 31413, 31516, 31615, 31709, 31800, 31888, - 31971, 32050, 32125, 32196, 32263, 32325, 32384, 32439, - 32489, 32535, 32577, 32615, 32649, 32679, 32704, 32725, - 32742, 32755, 32763, 32767, 32767, 32758, 32741, 32715, - 32681, 32638, 32587, 32527, 32458, 32381, 32296, 32203, - 32101, 31991, 31873, 31746, 31612, 31470, 31320, 31162, - 30996, 30823, 30642, 30454, 30259, 30056, 29847, 29630, - 29407, 29177, 28940, 28697, 28448, 28193, 27931, 27664, - 27391, 27113, 26829, 26540, 26246, 25947, 25643, 25335, - 25022, 24706, 24385, 24060, 23732, 23401, 23066, 22728, - 22387, 22043, 21697, 21349, 20999, 20646, 20292, 19937, - 19580, 19223, 18864, 18505, 18145, 17785, 17425, 17065, - 16705, 16346, 15988, 15631, 15275, 14920, 14567, 14215, - 13866, 13519, 13174, 12832, 12492, 12156, 11823, 11493, - 11166, 10844, 10525, 10210, 9900, 9594, 9292, 8996, - 8704, 8418, 8137, 7861, 7591, 7327, 7068, 6816, - 6570, 6330, 6097, 5870, 5650, 5437, 5231, 5032, - 4840, 4656, 4479, 4310, 4148, 3994, 3848, 3709, - 3579, 3457, 3343, 3237, 3139, 3050, 2969, 2896, - 2832, 2776, 2729, 2690, 2660, 2639, 2626, 2621 -}; - -const Word16 assym_window_16k_fx[L_LP_16k] = /*Q15*/ -{ - 2621, 2623, 2627, 2634, 2643, 2655, 2670, 2688, - 2708, 2731, 2757, 2785, 2816, 2849, 2886, 2925, - 2966, 3011, 3058, 3107, 3159, 3214, 3271, 3331, - 3394, 3459, 3527, 3597, 3670, 3745, 3823, 3903, - 3985, 4071, 4158, 4248, 4341, 4436, 4533, 4632, - 4734, 4839, 4945, 5054, 5165, 5279, 5394, 5512, - 5632, 5754, 5879, 6005, 6134, 6264, 6397, 6531, - 6668, 6807, 6947, 7090, 7234, 7381, 7529, 7679, - 7831, 7984, 8140, 8297, 8455, 8616, 8778, 8941, - 9107, 9273, 9442, 9611, 9782, 9955, 10129, 10304, - 10481, 10659, 10838, 11019, 11200, 11383, 11567, 11752, - 11938, 12125, 12313, 12502, 12693, 12883, 13075, 13268, - 13461, 13655, 13850, 14046, 14242, 14439, 14637, 14835, - 15033, 15232, 15432, 15631, 15832, 16032, 16233, 16434, - 16635, 16837, 17039, 17240, 17442, 17644, 17846, 18048, - 18250, 18452, 18653, 18855, 19056, 19257, 19458, 19658, - 19858, 20058, 20257, 20456, 20654, 20852, 21049, 21245, - 21441, 21637, 21831, 22025, 22218, 22410, 22602, 22792, - 22982, 23170, 23358, 23545, 23730, 23915, 24098, 24280, - 24461, 24641, 24820, 24997, 25173, 25348, 25521, 25693, - 25863, 26032, 26200, 26366, 26530, 26693, 26854, 27014, - 27171, 27328, 27482, 27635, 27786, 27935, 28082, 28227, - 28371, 28513, 28652, 28790, 28926, 29059, 29191, 29320, - 29448, 29573, 29697, 29818, 29937, 30053, 30168, 30280, - 30390, 30498, 30603, 30706, 30807, 30905, 31002, 31095, - 31186, 31275, 31362, 31446, 31527, 31606, 31683, 31757, - 31828, 31897, 31963, 32027, 32088, 32147, 32203, 32257, - 32307, 32356, 32401, 32444, 32484, 32522, 32557, 32589, - 32619, 32646, 32670, 32692, 32711, 32727, 32741, 32751, - 32760, 32765, 32767, 32767, 32762, 32751, 32734, 32712, - 32685, 32652, 32614, 32570, 32521, 32466, 32406, 32341, - 32270, 32194, 32112, 32026, 31934, 31837, 31735, 31627, - 31515, 31398, 31275, 31148, 31016, 30878, 30737, 30590, - 30438, 30282, 30122, 29957, 29787, 29613, 29434, 29252, - 29065, 28874, 28679, 28480, 28277, 28070, 27859, 27644, - 27426, 27205, 26980, 26751, 26520, 26285, 26047, 25805, - 25561, 25314, 25065, 24812, 24557, 24300, 24040, 23777, - 23513, 23246, 22978, 22707, 22435, 22161, 21885, 21608, - 21329, 21049, 20768, 20485, 20202, 19918, 19632, 19347, - 19060, 18773, 18486, 18198, 17911, 17623, 17335, 17047, - 16760, 16473, 16186, 15900, 15614, 15330, 15046, 14763, - 14481, 14200, 13921, 13643, 13367, 13092, 12818, 12547, - 12277, 12010, 11744, 11481, 11220, 10961, 10705, 10451, - 10200, 9951, 9706, 9463, 9223, 8987, 8754, 8523, - 8297, 8073, 7854, 7637, 7425, 7216, 7011, 6810, - 6613, 6420, 6231, 6046, 5865, 5689, 5517, 5350, - 5187, 5028, 4875, 4726, 4581, 4442, 4307, 4177, - 4052, 3932, 3818, 3708, 3603, 3503, 3409, 3320, - 3236, 3157, 3084, 3016, 2953, 2895, 2844, 2797, - 2756, 2720, 2690, 2665, 2646, 2632, 2624, 2621 -}; -/*------------------------------------------------------------------------------* - * lag window for windowing the autocorrelations in LP analysis - * Used in lib_enc\analy_lp_fx.c - *------------------------------------------------------------------------------*/ -const Word16 Hamcos_Window[L_LP_AMR_WB] = -{ - 2621, 2622, 2626, 2632, 2640, 2650, 2662, 2677, - 2694, 2714, 2735, 2759, 2785, 2814, 2844, 2877, - 2912, 2949, 2989, 3031, 3075, 3121, 3169, 3220, - 3273, 3328, 3385, 3444, 3506, 3569, 3635, 3703, - 3773, 3845, 3919, 3996, 4074, 4155, 4237, 4321, - 4408, 4496, 4587, 4680, 4774, 4870, 4969, 5069, - 5171, 5275, 5381, 5489, 5599, 5710, 5824, 5939, - 6056, 6174, 6295, 6417, 6541, 6666, 6793, 6922, - 7052, 7185, 7318, 7453, 7590, 7728, 7868, 8009, - 8152, 8296, 8442, 8589, 8737, 8887, 9038, 9191, - 9344, 9499, 9655, 9813, 9971, 10131, 10292, 10454, - 10617, 10781, 10946, 11113, 11280, 11448, 11617, 11787, - 11958, 12130, 12303, 12476, 12650, 12825, 13001, 13178, - 13355, 13533, 13711, 13890, 14070, 14250, 14431, 14612, - 14793, 14975, 15158, 15341, 15524, 15708, 15891, 16076, - 16260, 16445, 16629, 16814, 16999, 17185, 17370, 17555, - 17740, 17926, 18111, 18296, 18481, 18666, 18851, 19036, - 19221, 19405, 19589, 19773, 19956, 20139, 20322, 20504, - 20686, 20867, 21048, 21229, 21408, 21588, 21767, 21945, - 22122, 22299, 22475, 22651, 22825, 22999, 23172, 23344, - 23516, 23686, 23856, 24025, 24192, 24359, 24525, 24689, - 24853, 25016, 25177, 25337, 25496, 25654, 25811, 25967, - 26121, 26274, 26426, 26576, 26725, 26873, 27019, 27164, - 27308, 27450, 27590, 27729, 27867, 28003, 28137, 28270, - 28401, 28531, 28659, 28785, 28910, 29033, 29154, 29274, - 29391, 29507, 29622, 29734, 29845, 29953, 30060, 30165, - 30268, 30370, 30469, 30566, 30662, 30755, 30847, 30936, - 31024, 31109, 31193, 31274, 31354, 31431, 31506, 31579, - 31651, 31719, 31786, 31851, 31914, 31974, 32032, 32088, - 32142, 32194, 32243, 32291, 32336, 32379, 32419, 32458, - 32494, 32528, 32560, 32589, 32617, 32642, 32664, 32685, - 32703, 32719, 32733, 32744, 32753, 32760, 32764, 32767, - 32767, 32765, 32757, 32745, 32727, 32705, 32678, 32646, - 32609, 32567, 32520, 32468, 32411, 32349, 32283, 32211, - 32135, 32054, 31968, 31877, 31781, 31681, 31575, 31465, - 31351, 31231, 31107, 30978, 30844, 30706, 30563, 30415, - 30263, 30106, 29945, 29779, 29609, 29434, 29255, 29071, - 28883, 28691, 28494, 28293, 28087, 27878, 27664, 27446, - 27224, 26997, 26767, 26533, 26294, 26052, 25806, 25555, - 25301, 25043, 24782, 24516, 24247, 23974, 23698, 23418, - 23134, 22847, 22557, 22263, 21965, 21665, 21361, 21054, - 20743, 20430, 20113, 19794, 19471, 19146, 18817, 18486, - 18152, 17815, 17476, 17134, 16789, 16442, 16092, 15740, - 15385, 15028, 14669, 14308, 13944, 13579, 13211, 12841, - 12470, 12096, 11721, 11344, 10965, 10584, 10202, 9819, - 9433, 9047, 8659, 8270, 7879, 7488, 7095, 6701, - 6306, 5910, 5514, 5116, 4718, 4319, 3919, 3519, - 3118, 2716, 2315, 1913, 1510, 1108, 705, 302 -}; -/*----------------------------------------------------------------------------------* - * AMR-WB IO WB BWE - deemphasis, values in Q15: - *----------------------------------------------------------------------------------*/ -const Word16 deem_tab_fx[56] = -{ - 20668, 20625, 20583, 20541, 20501, 20462, 20423, 20385, - 20348, 20313, 20277, 20243, 20210, 20177, 20146, 20115, - 20085, 20055, 20027, 19999, 19972, 19946, 19921, 19896, - 19873, 19850, 19827, 19806, 19785, 19766, 19746, 19728, - 19710, 19693, 19677, 19662, 19647, 19633, 19620, 19607, - 19596, 19585, 19574, 19565, 19556, 19548, 19540, 19533, - 19527, 19522, 19518, 19514, 19510, 19508, 19506, 19505 -}; - - -/*----------------------------------------------------------------------------------* - * AMR-WB IO WB BWE - HP filter in frequency domain, values in Q15: - *----------------------------------------------------------------------------------*/ -const Word16 filt_hp_fx[56] = -{ - 53, 153, 274, 415, 578, 765, 978, 1217, 1483, 1778, 2102, - 2457, 2843, 3261, 3710, 4192, 4706, 5252, 5829, 6438, 7077, - 7746, 8443, 9168, 9918, 10693, 11489, 12306, 13141, 13992, - 14856, 15732, 16615, 17504, 18395, 19287, 20174, 21056, 21928, - 22787, 23631, 24456, 25260, 26039, 26791, 27512, 28201, 28853, - 29468, 30043, 30574, 31061, 31502, 31894, 32237, 32529 -}; - -/*----------------------------------------------------------------------------------* - * AMR-WB IO WB BWE - gains for 23k85 mode, values in Q15: - *----------------------------------------------------------------------------------*/ -const Word16 HP_gain_fx[16] = -{ - 3624, 4673, 5597, 6479, 7425, 8378, 9324, 10264, - 11210, 12206, 13391, 14844, 16770, 19655, 24289, 32728 -}; - -/*----------------------------------------------------------------------------------* - * AMR-WB IO WB BWE - band-pass 6-8kHz FIR filter, values in Q15: - *----------------------------------------------------------------------------------*/ -const Word16 fir_6k_8k_fx[31] = -{ - 44, -155, 323, -482, 563, -590, 726, -1180, 1986, -2818, 3028, - -1991, -423, 3583, -6281, 7342, -6281, 3583, -423, -1991, 3028, - -2818, 1986, -1180, 726, -590, 563, -482, 323, -155, 44 -}; - -const Word16 exp_tab_q_fx[34] = /*Q14 */ -{ - 16384, -16068, 15137, -13622, - 11585, -9101, 6270, -3195, - 0, 3196, -6269, 9102, - -11584, 13623, -15136, 16069, - -16383, 0, -3195, 6270, - -9101, 11585, -13622, 15137, - -16068, 16384, -16068, 15137, - -13622, 11585, -9101, 6270, - -3195, 0 -}; - -const Word16 exp_tab_p_fx[34] = /*Q14 */ -{ - 16384, -11584, 0, 11585, - -16383, 11585, 0, -11584, - 16384, -11584, 0, 11585, - -16383, 11585, 0, -11584, - 16384, 0, -11584, 16384, - -11584, 0, 11585, -16383, - 11585, 0, -11584, 16384, - -11584, 0, 11585, -16383, - 11585, 0 -}; -const Word16 swb_bwe_trans_subband_width_fx[SWB_FENV_TRANS] = {76, 76, 84, 84}; -const Word16 sqrt_swb_bwe_trans_subband_width_fx[SWB_FENV_TRANS] = {17854, 17854, 18770, 18770};/*Q11 */ -const Word16 sqrt_swb_bwe_subband_fx_L1[SWB_FENV] = {16384, 20066, 16384, 20066, 16384, 20066, 16384, 20066, 20066, 20066, 20066, 20066, 23170, 23170}; /*Q12 */ -const Word16 sqrt_swb_bwe_subband_fx_L2[SWB_FENV/2] = {25905, 25905, 25905, 25905, 28378, 28378, 32767}; /*Q12 */ -const Word16 smooth_factor_fx[SWB_FENV-1] = {1638, 1638, 1638, 1638, 1638, 1638, 1638, 1366, 1366, 1366, 1366, 1024, 1024}; -const Word16 swb_bwe_sm_subband_fx[SWB_FENV] = {248, 268, 288, 308, 328, 348, 368, 388, 412, 436, 460, 484, 512, 544}; - -const Word16 swb_bwe_trans_subband_fx[SWB_FENV_TRANS+1] = {240, 316, 392, 476, 560}; -const Word16 swb_bwe_subband_fx[SWB_FENV+1] = {240, 256, 280, 296, 320, 336, 360, 376, 400, 424, 448, 472, 496, 528, 560}; -const Word16 F_2_5_fx[64] = /*Q10 */ -{ - 1189, 675, -5106, -5293, 10476, -12, 10860, 10026, - -382, -616, 6426, 339, 9681, 9068, 3002, 2216, - 3208, 3042, 8255, -604, 16133, 5171, 17641, 18769, - -2529, -3248, -1447, -1991, 15511, 14855, 11631, 11996, - 9654, -124, 7267, -1617, 12799, 3237, 10598, 1555, - 5510, -1775, 1149, -2292, 12659, 12425, 4382, -1814, - 6305, 5629, 3404, -2632, 19555, 9582, 7835, 7619, - -517, -3795, 19031, 11574, 19156, 18748, 23563, 23465, -}; - -const Word16 swb_inv_bwe_subband_width_fx[SWB_FENV] = {2048,1365,2048,1365,2048,1365,2048,1365,1365,1365,1365,1365,1024,1024}; - -const Word16 EnvCdbk11_fx [N_CB11 * DIM11] = /*Q8 */ -{ - -2220, 29, 1168, 2124, 2180, 1208, 741, - 1521, -312, -843, -1523, -1970, -2205, -2541, - 746, 1835, 3461, 4398, 4292, 4184, 3462, - 1627, 2475, 2937, 2839, 2198, 1729, 1325, - -514, -731, -557, -200, 100, 475, 540, - 655, 956, 1272, 1083, 774, 687, 459, - 5987, 5460, 4689, 4192, 3845, 3615, 3393, - 3571, 4840, 5784, 6266, 5933, 5158, 4433, - 2959, 2087, 1180, 979, 1180, 1371, 1636, - 6029, 6157, 6431, 6762, 6998, 7153, 7050, - -822, 210, 450, 178, -639, -1346, -1577, - 4451, 4184, 4111, 4329, 4833, 5232, 5512, - 3420, 3994, 4321, 4205, 3684, 3154, 2651, - -3734, -2305, -1388, -324, 22, -847, -1141, - 850, 510, 896, 1780, 2130, 2688, 2826, - 3294, 2823, 2510, 2516, 3029, 3413, 3843, - -3563, -3409, -3199, -2917, -2584, -2282, -1981, - -2738, -3185, -3752, -4320, -4484, -4524, -4329, - -7534, -7481, -7283, -7175, -6757, -6281, -5865, - -4868, -4836, -4603, -4422, -4086, -3738, -3323, - -13896, -13775, -13484, -13339, -12926, -12399, -11970, - 8409, 8420, 8305, 8103, 7954, 7778, 7496, - 7180, 6845, 6369, 5971, 5557, 5309, 5027, - 4633, 4008, 3267, 2422, 2072, 1778, 1510, - 10128, 10432, 10540, 10473, 10176, 9837, 9586, - 2933, 2695, 2060, 1286, 424, -254, -825, - -10032, -9847, -9544, -9420, -9000, -8508, -8084, - 1830, 927, -158, -388, -360, -368, -287, - -21962, -21904, -21548, -21471, -21004, -20511, -20064, - -6090, -6142, -5937, -5852, -5493, -5104, -4671, - -1382, -1640, -2205, -2557, -2785, -3019, -2994, - -1300, -1567, -1744, -1642, -1409, -1080, -902, -}; - -const Word16 EnvCdbk1st_fx [N_CB1ST * DIM1ST] = /*Q8 */ -{ - -1819, -1138, 751, - -494, 162, -826, - -3199, -123, 2479, - -2071, 238, -429, - -1819, 1780, 1233, - 284, 1187, -1123, - -1689, -722, -484, - -1256, 52, -1336, - -604, 3738, -1297, - 555, 412, 743, - -626, -1685, 1527, - 145, 1557, -224, - -638, 1370, 1589, - -1188, 37, -410, - -428, -3320, 1860, - 2597, -95, -2876, - -742, -583, -684, - 1607, -1671, -1874, - -1111, -936, -1374, - 275, -2314, 518, - 2682, 2368, -302, - 1809, -555, -579, - 3193, -1270, -1208, - 750, 84, 154, - -1160, 429, 1098, - 816, -613, -2897, - 2159, -1885, 1245, - -671, 426, 3177, - 867, -144, -639, - 843, -1888, 2271, - 1542, 259, -148, - -1680, 1027, 285, - 162, -763, 1666, - -1916, 1175, -1227, - -345, -907, -151, - 1979, 1062, 402, - -1231, 2437, 3130, - -2422, 361, 1040, - -4314, -4106, -4221, - 146, -1200, -1828, - 485, 889, -3847, - 384, -2461, -2845, - 1526, -600, 1599, - -838, -571, 1097, - 1776, -3393, 4058, - -3330, 2429, 1732, - 468, -2140, -934, - 833, 2292, -1129, - -20, -1029, 652, - -346, 168, 1834, - -1730, 838, 2234, - 1622, -1695, -194, - -3198, -773, 228, - 1070, 1741, 285, - 1655, -212, -1628, - 2178, 604, 1784, - 1801, -3224, -848, - -819, 348, 187, - 16, 300, 244, - 769, 201, 1554, - 719, -394, 780, - 311, 2853, 185, - 1163, 489, -1022, - -330, 459, 877, - 109, -541, -691, - -509, -267, 478, - -340, -417, -1403, - -860, -675, -2703, - 1025, 826, 250, - -1043, 1008, -434, - -1042, -631, 60, - -173, 332, -2084, - 984, 919, -2042, - -1257, -2287, 339, - 366, -1309, -158, - 1041, 1039, 1083, - 3566, 918, 227, - 62, -139, 936, - 2424, 730, -1022, - -745, 1954, 427, - -1091, -1358, -478, - -173, 2121, -2367, - -2175, 2535, -1946, - -880, -1964, -1549, - -249, -1203, -927, - -2377, -443, -1775, - -1439, -582, 2037, - -529, -3679, -550, - 608, -284, -1566, - 201, 63, -344, - 1376, 218, 816, - 2471, -348, 479, - -1388, 988, -2674, - 1429, -3538, 1125, - 864, -1351, 845, - 301, 977, 408, - -1122, 3364, 1107, - -213, 730, -329, - 839, -683, -92, - 631, 1172, 2364, - 598, 685, -329, - -780, -1317, 448, - -424, -153, -199, - 768, -331, 2825, - 882, -1047, -975, - -375, -1835, -299, - 2861, -3375, -3158, - 2099, 2168, -2630, - 1602, 1930, 1451, - 1294, 1265, -586, - -2500, -2570, -2667, - -806, -1529, 3272, - -522, 1072, 478, - 4035, -2491, 480, - -1908, 2414, -178, - -1563, -143, 438, - 205, 861, 1287, - -691, 963, -1374, - -2359, -2032, -886, - 162, -442, 160, - 194, 2494, 1960, - -2533, -2578, 1924, - 267, 1701, 937, - 2919, 2950, 2382, - -670, 2102, -859, - -3147, 1385, -215, - 1482, -595, 415, - 228, 290, -1060, -}; - -const Word16 EnvCdbk2nd_fx [N_CB2ND * DIM2ND] = /*Q8 */ -{ - 1104, -1833, -1110, -954, - 757, 853, -176, 286, - -873, -587, -7, 1458, - -462, -553, -350, 104, - 1938, 1957, -1340, -703, - 1202, -779, 21, 1996, - -2851, -169, 1049, 940, - -1355, -726, -1788, 1076, - -767, -641, -646, -880, - 135, -832, -197, -889, - -826, 3, 279, -502, - -714, 544, -526, 375, - 291, -1076, -816, -3929, - -1175, -475, 2219, -642, - 197, -219, -1052, -1601, - 1175, -162, -695, -336, - 1124, 126, -2326, -1573, - 1164, -1323, -1958, 1074, - -2080, -2152, 113, 649, - -637, -860, 721, 267, - -609, 1658, -1006, -1352, - 1631, 2225, 2128, 1827, - -1112, -1351, 1856, 1656, - -2132, 1006, 770, -1294, - -472, 776, 1661, 2248, - -121, -574, -1481, -316, - 2565, -1081, 188, 293, - 398, 2598, 704, -1129, - 1023, 104, 550, 499, - -416, 127, 253, -1894, - 456, -2578, 190, 1018, - -1488, 286, -1202, -915, - -1164, 1874, 1651, 302, - -1312, -1547, -1625, -1516, - 170, -233, 817, 1209, - -1090, 341, 709, 725, - 854, 819, -278, -1083, - -15, 113, 286, 283, - 1166, -906, 1880, 301, - 342, -7, -587, 776, - -785, -1259, -1166, 3194, - -1630, -1071, 300, -1080, - -12, 190, -538, -493, - 351, 907, 1929, -1534, - 480, 36, 593, -526, - 813, 1216, 986, 89, - 98, 1010, -2272, 268, - 2766, -102, -1307, -873, - -1660, -467, -365, 47, - 1496, 1277, -228, -2791, - 1565, -669, 520, -1598, - -361, 1078, 457, -364, - 543, -950, 28, 248, - 1904, 815, -1034, 1125, - -13, -1951, 1085, -1005, - -2223, 1519, -624, 857, - 1121, 831, 872, 1295, - 193, 2284, -422, 609, - -156, 827, -733, 2065, - -3390, -3384, -3197, -3220, - 31, 896, 539, 978, - -21, 408, 1502, 405, - -583, -1662, -665, -164, - 2193, 976, 613, -436, -}; - -const Word16 EnvCdbk3rd_fx [N_CB3RD * DIM3RD] = /*Q8 */ -{ - 1031, -2454, 748, - 2770, 2442, 1761, - -2348, 4079, -959, - 1874, -735, -2242, - -59, 35, 201, - -1518, 162, 1809, - -1977, -1063, -103, - 2485, 1212, -863, - 882, 192, 39, - 1356, 851, 979, - -1377, -2961, -1477, - 497, -808, 593, - -394, -748, -1564, - -950, -198, -436, - -503, -1420, -234, - 318, 985, -1905, - -118, 1783, 1563, - 220, 929, 400, - 857, 37, -995, - -807, 1943, -409, - -743, -524, 552, - 940, 1643, -299, - 805, -1421, -768, - -2330, 705, 156, - 61, 203, 1213, - -138, 517, -642, - 64, -501, -435, - 2194, -625, 157, - -1600, 341, -1611, - 1137, -351, 2353, - -811, -1715, 1522, - -870, 613, 446, -}; - -const Word16 EnvCdbk4th_fx [N_CB4TH * DIM4TH] = /*Q8 */ -{ - 1024, -210, -207, 591, - -280, -2486, -951, 958, - 1539, 1136, 411, 1314, - 1761, -202, 1339, 203, - -2438, -2109, -2028, -2125, - 1849, -1408, -670, 144, - -469, 2674, -1589, -3604, - 1642, -702, 139, 2476, - -483, 372, -861, 540, - -119, 827, 863, 952, - 23, 99, -24, -303, - 488, -2233, -1432, -1399, - 54, -43, 96, -1527, - 1170, 133, -119, -717, - 258, -1215, -439, 160, - -1049, 793, 970, -770, - -1914, -1245, 1281, 422, - -1194, 1005, 176, -2368, - -1631, 1316, -1125, -361, - 1124, 1132, 61, -2186, - 790, -2055, 1174, 938, - 2974, 3874, 2315, 2040, - -300, 2484, 59, -860, - 543, 1307, -1868, -725, - 389, -115, -945, -146, - -1837, -578, -620, 975, - 389, 1779, 1732, 296, - 377, 897, 1555, 2269, - -854, 26, 590, 1413, - -780, -985, 1389, 2639, - 312, -277, -935, -3289, - 1740, 1852, 641, -519, - 738, 898, -466, 115, - 1187, -286, -1514, -1309, - 74, -801, -583, -987, - 510, -667, 430, -191, - 418, -303, 806, 1258, - -1083, -1065, 362, -2114, - -1075, 82, 260, 286, - -2579, 14, 75, -854, - -661, -634, 482, -581, - -338, -306, 3255, 388, - -230, -24, 1161, 205, - 256, 546, -141, 1379, - -63, -775, -484, 1478, - -517, -546, -451, 86, - 1473, -1201, 430, -1892, - 394, 831, 620, -664, - 334, 64, 1773, -1576, - -1783, 1270, 1020, 944, - 1023, 98, -1908, 1330, - -560, -1044, 380, 707, - -427, -708, -1815, -90, - -54, 2298, -537, 1151, - -499, 703, -1018, 3322, - 92, 717, -607, -1032, - -1313, -1393, -580, -485, - 34, -2192, 788, -860, - 2641, 628, -776, -259, - -702, -159, -1483, -1638, - -33, -63, 97, 553, - 692, 523, 548, 349, - -913, 54, -456, -702, - -341, 944, 157, 100, -}; - -const Word16 w_NOR_fx[SWB_FENV] = /*Q15 */ -{ - 32767, 32056, 31374, 30720, 30093, 29491, 28913, - 28357, 27822, 27307, 26810, 26331, 25869, 25423, -}; - -const Word16 Mean_env_fx[SWB_FENV] = /*Q8 */ -{ - 7327, 7414, 7181, 7160, 6889, 6866, 6746, - 6651, 6385, 6152, 5873, 5668, 5435, 5222, -}; - -const Word16 Env_TR_Cdbk1_fx [N_CB_TR1 * DIM_TR1] = /*Q8 */ -{ - 229, -2347, - 8199, 7726, - -312, 1700, - 9881, 5949, - 8942, 8358, - 3865, 3287, - 2405, 796, - 3664, 1433, - 3059, 2215, - 618, 874, - -5479, -4636, - 2237, 2512, - 4265, 2428, - 6583, 2065, - 4548, 6579, - 11325, 7340, - 10578, 9264, - 8491, 6457, - -1380, -2484, - 3377, 5069, - 7393, 5120, - 4798, 4440, - 5506, 7614, - -3371, -3982, - 2806, 2959, - 2242, 3550, - 1334, 3065, - 2055, -1350, - 815, 5507, - 4940, 1457, - -1950, -1046, - 653, -1133, - 872, -3622, - -1756, 245, - 5792, 5542, - 4084, 7696, - 4569, 5204, - -810, -1555, - 10127, 10384, - 11341, 11713, - 6365, 4996, - 8641, 10527, - 5914, 3366, - 4522, 3266, - 5217, 2830, - 8107, 8980, - 3952, 5858, - 5848, 8990, - 6424, 5931, - 5185, 3823, - 6367, 6917, - 3548, 2683, - 1634, 2098, - 2729, -89, - 6964, 7664, - 3179, 3561, - 6388, 4193, - 4024, 4828, - -378, 434, - 9338, 9507, - 7593, 3483, - -6835, -6317, - 5207, 5029, - 11326, 10488, - 7411, 6086, - 10072, 8255, - -6099, -5652, - 7074, 8702, - -12228, -11384, - -11471, -10567, - -13025, -12253, - -12879, -11289, - -13952, -13062, - -16214, -15389, - -11659, -10789, - -12351, -11477, - -12789, -11947, - -15139, -14249, - -11326, -11219, - -11950, -11093, - -11800, -10928, - -23738, -22881, - 12795, 11890, - -3793, -2879, - -27373, -26492, - -11928, -11531, - -12110, -11258, - -20492, -19634, - -14371, -13608, - -12591, -11728, - -14055, -11739, - 9471, 7272, - -11184, -10335, - -13313, -11673, - -12209, -10610, - -13465, -12761, - 7690, 7115, - 2564, 4496, - 5587, 4551, - -813, -562, - -4483, -5521, - 1556, 98, - 2, 3468, - 1410, 1339, - 4049, 161, - -4538, -4026, - -9866, -9115, - -1616, -4727, - 2457, 1653, - 631, 2155, - -17982, -17082, - 2628, 6088, - -10791, -9933, - -12426, -11566, - 4322, 4000, - -1574, 2162, - -7968, -7599, - 1523, 4192, - 5621, 6537, - -2511, -1987, - 12471, 9218, - 8746, 4971, - 3642, 4148, - 5089, 5948, - 350, -92, - 7028, 6683, - -2430, -3216, - -3974, -886, -}; - -const Word16 Env_TR_Cdbk2_fx [N_CB_TR2 * DIM_TR2] = /*Q8 */ -{ - 2639, 375, - -481, 1694, - -2400, -3306, - 86, -4018, - -1301, 47, - 734, 299, - 957, -1039, - 2204, 1486, - 361, -1136, - 2628, -838, - -2010, 1296, - 373, 127, - -573, 2604, - 689, -1554, - 1676, -371, - 1298, 279, - -901, 1086, - 1747, -2723, - 214, -657, - -731, -909, - 1545, -1658, - -369, -2208, - -1276, 1748, - 1141, -522, - 186, -1893, - -1260, -2016, - -478, -504, - 1287, 1882, - -97, -1400, - -1372, -1165, - 800, -152, - 413, -240, - -208, -858, - -90, -399, - 492, 2519, - 913, 1368, - -344, 282, - 305, 526, - -251, 860, - -1066, 567, - -2800, -687, - 1, 674, - 176, 878, - -716, -153, - 706, 831, - -1083, -424, - 419, 1192, - -132, 565, - 708, -2406, - 600, -661, - 1712, 2969, - -1974, 379, - -672, 208, - 26, 296, - -1821, -501, - -513, 635, - 266, 1737, - -221, 1232, - -3498, 1632, - -337, -66, - -552, -1427, - 1329, 850, - -718, -2948, - -3, 0, -}; - -const Word16 Mean_env_tr_fx[5]= {6971, 6095, 6111, 4995}; /*Q8 */ - - -const Word16 EnvCdbkFB_fx [N_CB_FB * DIM_FB] = /*Q7 */ -{ - -2126, -1242, -945, - 1628, -686, -539, - 1230, 2245, 2532, - 2822, 3094, 2669, - -12376, -11507, -11342, - 2678, 3533, 3510, - 489, 903, 689, - 1930, 2929, 3025, - 3424, 4179, 4050, - -2500, -1707, -1415, - -3511, -2563, -2224, - -865, -987, -1212, - -424, 891, 1919, - 1976, 2520, 2277, - 673, 1667, 1945, - 5169, 6024, 5983, - -1367, -501, -236, - -254, 679, 989, - -18974, -18088, -17834, - -23007, -22053, -22109, - 2262, 2301, -625, - -124, 431, 372, - 1454, 1962, 1791, - 200, 1094, 1347, - -997, -110, 213, - -697, 267, 602, - -3066, -2172, -1876, - -4358, -3493, -3164, - -360, 59, -472, - -1813, -919, -601, - 4204, 4967, 4913, - 953, 1457, 1245 -}; - -const Word16 Mean_env_fb_fx[DIM_FB] = {1760, 805, 473}; /*Q8 */ - - -/*-------------------------------------------------------------------* - * Pulse indexing tables for ACELP innovation coding - *-------------------------------------------------------------------*/ - -const Word32 PI_select_table_fx[23][8] = -{ - {1, 0, 0, 0, 0, 0, 0, 0}, - {1, 1, 0, 0, 0, 0, 0, 0}, - {1, 2, 1, 0, 0, 0, 0, 0}, - {1, 3, 3, 1, 0, 0, 0, 0}, - {1, 4, 6, 4, 1, 0, 0, 0}, - {1, 5, 10, 10, 5, 1, 0, 0}, - {1, 6, 15, 20, 15, 6, 1, 0}, - {1, 7, 21, 35, 35, 21, 7, 1}, - {1, 8, 28, 56, 70, 56, 28, 8}, - {1, 9, 36, 84, 126, 126, 84, 36}, - {1, 10, 45, 120, 210, 252, 210, 120}, - {1, 11, 55, 165, 330, 462, 462, 330}, - {1, 12, 66, 220, 495, 792, 924, 792}, - {1, 13, 78, 286, 715, 1287, 1716, 1716}, - {1, 14, 91, 364, 1001, 2002, 3003, 3432}, - {1, 15, 105, 455, 1365, 3003, 5005, 6435}, - {1, 16, 120, 560, 1820, 4368, 8008, 11440}, - {1, 17, 136, 680, 2380, 6188, 12376, 19448}, - {1, 18, 153, 816, 3060, 8568, 18564, 31824}, - {1, 19, 171, 969, 3876, 11628, 27132, 50388}, - {1, 20, 190, 1140, 4845, 15504, 38760, 77520}, - {1, 21, 210, 1330, 5985, 20349, 54264, 116280}, - {1, 22, 231, 1540, 7315, 26334, 74613, 1705444} -}; - -const Word32 PI_offset_fx[8][8] = -{ - /* for 0p(0). */ - {0x00000,0x00000,0x00000,0x00000,0x00000,0x00000,0x00000,0x00000}, - /* for 1p(1). */ - {0x00000,0x00000,0x00000,0x00000,0x00000,0x00000,0x00000,0x00000}, - /* for 2p(2,1). */ - {0x00000,0x00000,0x00000,0x00000,0x00000,0x00000,0x00000,0x00000}, - /* for 3p(3,2,1). */ - {0x00000,0x00000,0x01180,0x01540,0x00000,0x00000,0x00000,0x00000}, - /* for 4p(4,3,2,1). */ - {0x00000,0x00000,0x071C0,0x0A640,0x0ABE0,0x00000,0x00000,0x00000}, - /* for 5p(5,4,3,2,1). */ - {0x00000,0x00000,0x22200,0x3E900,0x45200,0x45980,0x00000,0x00000}, - /* for 6p(6,5,4,3,2,1). */ - {0x00000,0x00000,0x07d200,0x127c00,0x16ed80,0x179c80,0x17a5e0,0x00000}, - /* for 7p(7,6,5,4,3,2,1). */ - {0x00000,0x00000,0x165800,0x454400,0x654200,0x6E2500,0x6F2B80,0x6F36C0} -}; - -const Word16 PI_factor_fx[7] = {0,0,120,560,1820,4368,8008}; - -/*------------------------------------------------------------------------------* - * AVQ - RE8 tables - *------------------------------------------------------------------------------*/ - -const Word16 select_table22_fx[5][9] = -{ - {1, 1, 1, 1, 1, 1, 1, 1, 1}, - {0, 1, 2, 3, 4, 5, 6, 7, 8}, - {0, 0, 1, 3, 6, 10, 15, 21, 28}, - {0, 0, 0, 1, 4, 10, 20, 35, 56}, - {0, 0, 0, 0, 1, 5, 15, 35, 70} -}; - -/* value of leader element */ -const Word16 vals_a_fx[36][4] = -{ - {1}, {0,2}, {0,2}, {1,3}, {0,4}, {2,0}, {1,3}, {0,2,4}, - {2}, {1,3}, {2,0,4}, {0,4}, {1,5}, {1,3}, {2,0,4}, {0,2,4}, - {1,3,5}, {0,2,6}, {0,4}, {0,2,6}, {0,2,4,6}, {1,7}, {0,8}, {0,6}, - {0,2,8}, {0,4,8}, {1,9}, {0,2,10}, {0,8}, {0,6,10}, {0,12}, {0,4,12}, - {0,10}, {0,2,14}, {0,8,12}, {0,16} -}; - -/* code parameter for every leader */ -const Word16 vals_q_fx[36][4] = -{ - {7,1}, {2,2,2}, {4,2,4}, {7,2,1}, {1,2,1}, {6,2,2}, {7,2,2}, {3,3,3,1}, - {8,1}, {7,2,3}, {5,3,4,1}, {2,2,2}, {7,2,1}, {7,2,4}, {7,3,2,1}, {4,3,4,2}, - {7,3,2,1}, {2,3,2,1}, {3,2,3}, {4,3,4,1}, {3,4,3,2}, {7,2,1}, {1,2,1}, {2,2,2}, - {3,3,3,1}, {2,3,2,1}, {7,2,1}, {2,3,2,1}, {2,2,2}, {2,3,2,1}, {1,2,1}, {2,3,2,1}, - {2,2,2}, {2,3,2,1}, {2,3,2,1}, {1,2,1} -}; - -/* codebook start address for every leader */ -const UWord16 Is_fx[36] = -{ - 0, 128, 256, 1376, 240, 0, 1792, 2400, 5376, 5632, 12800, 3744, - 21760, 22784, 31744, 38912, 45632, 3856, 52800, 53248, 57728, 60416, 4080, 61440, - 61552, 62896, 63120, 64144, 64368, 64480, 64704, 64720, 64944, 65056, 65280, 65504 -}; - -/* A3 - Number of the absolute leaders in codebook Q3 */ -const Word16 A3_fx[NB_LDQ3] = -{ - 0, 1, 4, 2, 3, 7, 11, 17, 22 -}; - -/* A4 - Number of the absolute leaders in codebook Q4 */ -const Word16 A4_fx[NB_LDQ4] = -{ - 5, 6, 8, 9, 10, 12, 13, 14, 15, - 16, 18, 19, 20, 21, 23, 24, 25, 26, - 27, 28, 29, 30, 31, 32, 33, 34, 35 -}; - -/* I3 - Cardinality offsets for absolute leaders in Q3 */ -const UWord16 I3_fx[NB_LDQ3] = -{ - 0, 128, 240, 256, 1376, 2400, 3744, 3856, 4080 -}; - -/* I4 - Cardinality offset for absolute leaders in Q4 */ -const UWord16 I4_fx[NB_LDQ4] = -{ - 0, 1792, 5376, 5632, 12800, 21760, 22784, 31744, 38912, - 45632, 52800, 53248, 57728, 60416, 61440, 61552, 62896, 63120, - 64144, 64368, 64480, 64704, 64720, 64944, 65056, 65280, 65504 -}; - -/* Da_pos - Position of the first absolute leader on a spherical shell (or sphere) */ -const Word16 Da_pos_fx[NB_SPHERE] = -{ - 0, 2, 5, 8, 13, 18, 20, 22, 23, 25, 26, 27, 27, 28, 28, 28, - 29, 30, 31, 31, 32, 32, 32, 32, 32, 34, 35, 35, 35, 35, 35, 35 -}; - -/* Da_nb - Number of absolute leaders on a spherical shell */ -const Word16 Da_nb_fx[NB_SPHERE] = -{ - 2, 3, 3, 5, 5, 2, 2, 1, 2, 1, 1, 0, 1, 0, 0, 1, - 1, 1, 0, 1, 0, 0, 0, 0, 2, 1, 0, 0, 0, 0, 0, 1 -}; - -/* Da_id - identification code of an absolute leader */ -const Word16 Da_id_fx[NB_LEADER] = -{ - 0x0001, 0x0004, 0x0008, 0x000B, 0x0020, 0x000C, 0x0015, 0x0024, - 0x0010, 0x001F, 0x0028, 0x0040, 0x004F, 0x0029, 0x002C, 0x0044, - 0x0059, 0x00A4, 0x0060, 0x00A8, 0x00C4, 0x012D, 0x0200, 0x0144, - 0x0204, 0x0220, 0x0335, 0x04E4, 0x0400, 0x0584, 0x0A20, 0x0A40, - 0x09C4, 0x12C4, 0x0C20, 0x2000 -}; - -/* Da_nq - Codebook number for each absolute leader */ -const Word16 Da_nq_fx[NB_LEADER+2] = -{ - 2, 2, 3, 3, 2, 4, 4, 3, 4, 4, 4, 3, 4, 4, 4, 4, - 4, 3, 4, 4, 4, 4, 3, 4, 4, 4, 4, 4, 4, 4, 4, 4, - 4, 4, 4, 4, 0, 100 -}; - - -/*------------------------------------------------------------------------------* - * LP muisc post-filter - *------------------------------------------------------------------------------*/ - -const Word16 post_dct_wind_fx[OFFSET2] = /*Q15 */ -{ - 32767, 32766, 32759, 32748, 32733, 32713, 32689, 32660, - 32627, 32590, 32548, 32502, 32452, 32397, 32338, 32274, - 32207, 32135, 32059, 31979, 31894, 31805, 31712, 31615, - 31514, 31409, 31300, 31187, 31070, 30949, 30823, 30695, - 30562, 30425, 30285, 30141, 29993, 29841, 29686, 29527, - 29365, 29200, 29030, 28858, 28682, 28503, 28320, 28134, - 27945, 27753, 27558, 27360, 27159, 26955, 26749, 26539, - 26327, 26112, 25894, 25674, 25452, 25226, 24999, 24769, - 24537, 24303, 24067, 23828, 23588, 23345, 23101, 22855, - 22607, 22358, 22107, 21854, 21600, 21345, 21088, 20830, - 20570, 20310, 20049, 19786, 19523, 19258, 18993, 18728, - 18461, 18195, 17927, 17659, 17391, 17123, 16854, 16586, - 16317, 16048, 15779, 15511, 15243, 14975, 14707, 14440, - 14173, 13907, 13642, 13377, 13114, 12851, 12589, 12328, - 12068, 11809, 11552, 11296, 11041, 10787, 10536, 10285, - 10037, 9790, 9545, 9301, 9060, 8820, 8583, 8348, - 8115, 7884, 7655, 7429, 7205, 6983, 6765, 6548, - 6335, 6124, 5916, 5710, 5508, 5308, 5112, 4918, - 4728, 4540, 4356, 4175, 3998, 3824, 3653, 3485, - 3321, 3161, 3004, 2851, 2701, 2555, 2413, 2274, - 2139, 2009, 1882, 1758, 1639, 1524, 1413, 1306, - 1203, 1104, 1009, 918, 831, 749, 671, 597, - 527, 461, 400, 343, 291, 242, 199, 159, - 124, 93, 67, 45, 27, 14, 5, 1 -}; - -const Word16 mfreq_loc_LD_fx[] = { 100, 200, 300, 400, 510, 630, 770, 920, 1080, 1270, 1480, - 1720, 2000, 2320, 2700, 3150, 3700, 4400, 5300, (6400-BIN_16kdct_fx) - }; - -const Word16 inv_mfreq_bindiv_LD_fx[] = {3277, 3277, 3277, 3277, 2979, 2731, 2341, 2185, 2048, 1725, 1560, 1365, 1170, 1024, 862, 728, 596, 468, 364, 298}; /*Q15 */ - -const Word16 inv_mfreq_bindiv_LD_M1_fx[] = {3641, 3641, 3641, 3641, 3277, 2979, 2521, 2341, 2185, 1820, 1638, 1425, 1214, 1057, 886, 745, 607, 475, 368, 301}; /*Q15 */ - -const Word16 sc_qnoise_fx[] = {3277, 3277, 3277, 3277, 3277, 3277, 2979, 2979, 2979, 2979, 2979, 2979, 2979, 2979, 2979, 2185, 2185, 2185, 2185, 2185}; - -const Word16 MAX_SNR_SNR1_tab_FX[MBANDS_GN_LD] = { 16815, 16815, 16815, 16815, 16815, 16815, 16815, 16815, 16815, 16815, 16815, 16815, 16815, 16815, 16815, 16815, 17096, 17096, 17096, 17096}; - -const Word16 INV_MAX_SNR_tab_FX[MBANDS_GN_LD] = { 862, 862, 862, 862, 862, 862, 862, 862, 862, 862, 862, 862, 862, 862, 862, 862, 1425, 1425, 1425, 1425}; - -/*const Word16 inv_mfreq_bindiv_LD1_fx[] = {13107, 13107, 13107, 13107, 11916, 10923, 9362, 8738, 8192, 6899, 6242, 5461, 4681, 4096, 3449, 2913, 2383, 1872, 1456, 1192}; //Q17 */ - -/*------------------------------------------------------------------------------* - * Highrate SWB BWE tables - *------------------------------------------------------------------------------*/ - -const Word16 overlap_coefs_48kHz_fx[NSV_OVERLAP*WIDTH_BAND] = /* in Q15 */ -{ - 9830, 11141, 11796, 12780, 13763, 14418, 15073, 15565, 16056, 16712, 17695, 18678, 20316, 23593, 27197, 31130 -}; - -const Word16 overlap_coefs_fx[NSV_OVERLAP*WIDTH_BAND] = /* in Q15 */ -{ - 8847, 10027, 10617, 11502, 12386, 12976, 13566, 14008, 14451, 15041, 15925, 16810, 18285, 21234, 24478, 28017 -}; - -const Word16 swb_hr_env_code1_fx[NUM_ENVLOPE_CODE_HR1*2] = /* in Q9 */ -{ - 23, 21, 268, 240, 344, 310, 504, 438, - 629, 580, 856, 734, 1305, 1209, 1637, 1693, - 1321, 2671, 2154, 3709, 1801, 890, 2243, 1410, - 2436, 2404, 3496, 3127, 2279, 5187, 3715, 6394, - 3435, 1000, 3381, 1894, 5434, 1299, 4806, 2171, - 3645, 4240, 4640, 3628, 4567, 4999, 5785, 6023, - 6032, 3010, 7194, 4949, 5735, 4609, 7391, 6777, - 7341, 1999, 10276, 2220, 9270, 4210, 11444, 4917, - 3708, 8481, 6030, 9814, 5694, 7913, 7457, 8888, - 9124, 6090, 8943, 7832, 10925, 6889, 10519, 8768, - 4637, 11437, 5754, 14762, 6791, 12873, 8317, 14468, - 7818, 11028, 8696, 12646, 10031, 11617, 10315, 13255, - 9112, 9960, 10901, 10336, 12338, 9772, 12090, 11543, - 12125, 8360, 13766, 9934, 13317, 8004, 14817, 8315, - 12848, 6332, 14189, 6791, 14505, 5289, 15684, 6580, - 12940, 3143, 14948, 3698, 16472, 2570, 16373, 4851 -}; - -const Word16 swb_hr_env_code2_fx[NUM_ENVLOPE_CODE_HR2*2] = /* in Q9 */ -{ - 262, 242, 686, 568, 1303, 901, 1600, 1559, - 2505, 1905, 2053, 2944, 2617, 1108, 3414, 1993, - 4329, 1409, 5695, 1801, 3391, 3052, 4384, 2562, - 4567, 3985, 5509, 3051, 6374, 4280, 7003, 5750, - 7000, 2794, 8434, 2006, 10706, 3294, 13034, 4412, - 8402, 3878, 9510, 5269, 11309, 6406, 10839, 8811, - 2701, 4927, 4656, 5773, 6116, 7956, 8474, 7704, - 3255, 8984, 6818, 11144, 3915, 13367, 1255, 16350 -}; - -const Word16 swb_hr_env_code3_fx[NUM_ENVLOPE_CODE_HR_TR*N_BANDS_TRANS_BWE_HR] = /* in Q9 */ -{ - 409, 347, 898, 622, 1457, 1033, 2242, 1012, - 3039, 1508, 2017, 2161, 4137, 1348, 3881, 2553, - 2538, 5306, 3962, 4430, 4730, 3610, 5225, 2877, - 5450, 2240, 5970, 1779, 5553, 1364, 6003, 838 -}; - - -const Word16 Ip_fft256_fx[10] = {128, 1, 0, 256, 128, 384, 64, 320,192, 448}; -const Word16 w_fft256_fx[128] = -{ - 16384, 0, 11585, 11585, 15137, 6270, 6270, 15137, - 16069, 3196, 9102, 13623, 13623, 9102, 3196, 16069, - 16305, 1606, 10394, 12665, 14449, 7723, 4756, 15679, - 15679, 4756, 7723, 14449, 12665, 10394, 1606, 16305, - 16364, 804, 11003, 12140, 14811, 7005, 5520, 15426, - 15893, 3981, 8423, 14053, 13160, 9760, 2404, 16207, - 16207, 2404, 9760, 13160, 14053, 8423, 3981, 15893, - 15426, 5520, 7005, 14811, 12140, 11003, 804, 16364, - 16379, 402, 11297, 11866, 14978, 6639, 5897, 15286, - 15986, 3590, 8765, 13842, 13395, 9434, 2801, 16143, - 16261, 2006, 10080, 12916, 14256, 8076, 4370, 15791, - 15557, 5139, 7366, 14635, 12406, 10702, 1205, 16340, - 16340, 1205, 10702, 12406, 14635, 7366, 5139, 15557, - 15791, 4370, 8076, 14256, 12916, 10080, 2006, 16261, - 16143, 2801, 9434, 13395, 13842, 8765, 3590, 15986, - 15286, 5897, 6639, 14978, 11866, 11297, 402, 16379 -}; - -const Word16 Ip_fft512_fx[18] = {256, 1, 0, 512, 256, 768, 128, 640,384, 896, 64, 576, 320, 832, 192, 704,448, 960}; -const Word16 w_fft512_fx[256] = -{ - 16384, 0, 11585, 11585, 15137, 6270, 6270, 15137, - 16069, 3196, 9102, 13623, 13623, 9102, 3196, 16069, - 16305, 1606, 10394, 12665, 14449, 7723, 4756, 15679, - 15679, 4756, 7723, 14449, 12665, 10394, 1606, 16305, - 16364, 804, 11003, 12140, 14811, 7005, 5520, 15426, - 15893, 3981, 8423, 14053, 13160, 9760, 2404, 16207, - 16207, 2404, 9760, 13160, 14053, 8423, 3981, 15893, - 15426, 5520, 7005, 14811, 12140, 11003, 804, 16364, - 16379, 402, 11297, 11866, 14978, 6639, 5897, 15286, - 15986, 3590, 8765, 13842, 13395, 9434, 2801, 16143, - 16261, 2006, 10080, 12916, 14256, 8076, 4370, 15791, - 15557, 5139, 7366, 14635, 12406, 10702, 1205, 16340, - 16340, 1205, 10702, 12406, 14635, 7366, 5139, 15557, - 15791, 4370, 8076, 14256, 12916, 10080, 2006, 16261, - 16143, 2801, 9434, 13395, 13842, 8765, 3590, 15986, - 15286, 5897, 6639, 14978, 11866, 11297, 402, 16379, - 16383, 201, 11442, 11727, 15059, 6455, 6084, 15213, - 16029, 3393, 8935, 13733, 13510, 9269, 2999, 16107, - 16284, 1806, 10238, 12792, 14354, 7900, 4563, 15736, - 15619, 4948, 7545, 14543, 12537, 10549, 1406, 16324, - 16353, 1005, 10853, 12274, 14724, 7186, 5330, 15493, - 15843, 4176, 8250, 14155, 13039, 9921, 2205, 16235, - 16176, 2603, 9598, 13279, 13949, 8595, 3786, 15941, - 15357, 5708, 6823, 14896, 12004, 11151, 603, 16373, - 16373, 603, 11151, 12004, 14896, 6823, 5708, 15357, - 15941, 3786, 8595, 13949, 13279, 9598, 2603, 16176, - 16235, 2205, 9921, 13039, 14155, 8250, 4176, 15843, - 15493, 5330, 7186, 14724, 12274, 10853, 1005, 16353, - 16324, 1406, 10549, 12537, 14543, 7545, 4948, 15619, - 15736, 4563, 7900, 14354, 12792, 10238, 1806, 16284, - 16107, 2999, 9269, 13510, 13733, 8935, 3393, 16029, - 15213, 6084, 6455, 15059, 11727, 11442, 201, 16383 -}; -const Word16 sinq_16k[3*L_FRAME16k/20] = -{ - 536, 1608, 2678, 3745, 4808, 5866, 6918, 7962, - 8998, 10024, 11039, 12043, 13033, 14010, 14972, 15917, - 16846, 17757, 18648, 19520, 20371, 21199, 22006, 22788, - 23546, 24279, 24986, 25667, 26319, 26944, 27540, 28106, - 28642, 29147, 29622, 30064, 30475, 30852, 31197, 31508, - 31786, 32029, 32238, 32413, 32553, 32658, 32728, 32763 -}; -const Word16 sinq_32k[3*L_FRAME32k/20] = -{ - 268, 804, 1340, 1876, 2411, 2945, 3479, 4011, 4543, 5073, 5602, 6130, - 6655, 7180, 7702, 8222, 8740, 9255, 9768, 10279, 10786, 11291, 11793, 12292, - 12787, 13279, 13767, 14252, 14733, 15210, 15683, 16151, 16616, 17075, 17531, 17981, - 18427, 18868, 19304, 19734, 20160, 20580, 20994, 21403, 21806, 22203, 22595, 22980, - 23359, 23732, 24098, 24459, 24812, 25159, 25499, 25832, 26159, 26478, 26790, 27095, - 27393, 27684, 27967, 28243, 28511, 28771, 29024, 29269, 29506, 29735, 29956, 30170, - 30375, 30572, 30761, 30941, 31114, 31278, 31433, 31580, 31719, 31849, 31971, 32084, - 32189, 32285, 32372, 32451, 32521, 32582, 32634, 32678, 32713, 32740, 32757, 32766 -}; - -const Word16 sinq_48k[3*L_FRAME48k/20] = -{ - 179, 536, 893, 1251, 1608, 1965, 2321, 2678, 3034, 3390, 3745, 4100, - 4454, 4808, 5161, 5514, 5866, 6217, 6568, 6918, 7267, 7615, 7962, 8308, - 8654, 8998, 9341, 9683, 10024, 10364, 10702, 11039, 11375, 11710, 12043, 12375, - 12705, 13033, 13361, 13686, 14010, 14332, 14653, 14972, 15289, 15604, 15918, 16229, - 16539, 16846, 17152, 17455, 17757, 18056, 18353, 18648, 18941, 19232, 19520, 19806, - 20090, 20371, 20650, 20926, 21200, 21471, 21740, 22006, 22269, 22530, 22789, 23044, - 23297, 23547, 23794, 24038, 24280, 24519, 24754, 24987, 25217, 25444, 25667, 25888, - 26106, 26320, 26531, 26740, 26945, 27147, 27345, 27541, 27733, 27921, 28107, 28289, - 28468, 28643, 28815, 28984, 29149, 29310, 29468, 29623, 29774, 29922, 30066, 30206, - 30343, 30476, 30606, 30732, 30854, 30973, 31087, 31199, 31306, 31410, 31510, 31606, - 31699, 31788, 31873, 31954, 32031, 32105, 32175, 32241, 32303, 32361, 32415, 32466, - 32513, 32556, 32595, 32630, 32661, 32688, 32712, 32731, 32747, 32759, 32766, 32767 -}; -const Word16 Asr_LP16_fx[21] = -{ - /*Q15 */ - 0, 110, 0, -428, 0, 1153, 0, -2832, - 0, 10199, 16384, 10199, 0, -2832, 0, 1153, - 0, -428, 0, 110, 0 -}; - -const Word16 Asr_LP32_fx[41] = -{ - /*Q15 */ - 0, 24, 55, 58, 0, -113, -214, -198, - 0, 323, 576, 510, 0, -795, -1416, -1280, - 0, 2337, 5099, 7334, 8192, 7334, 5099, 2337, - 0, -1280, -1416, -795, 0, 510, 576, 323, - 0, -198, -214, -113, 0, 58, 55, 24, - 0 -}; - -const Word16 Asr_LP48_fx[61] = -{ - /*Q17 */ - 0, 38, 93, 146, 167, 123, 0, -192, - -408, -571, -592, -407, 0, 564, 1143, 1537, - 1546, 1035, 0, -1391, -2801, -3776, -3843, -2635, - 0, 3919, 8679, 13599, 17887, 20809, 21845, 20809, - 17887, 13599, 8679, 3919, 0, -2635, -3843, -3776, - -2801, -1391, 0, 1035, 1546, 1537, 1143, 564, - 0, -407, -592, -571, -408, -192, 0, 123, - 167, 146, 93, 38, 0 -}; -const Word16 short_window_48kHz_fx[L_FRAME48k/2/2] = /* second half is symetric and omitted */ -{ - 107, 322, 536, 751, 965, 1179, 1394, 1608, 1822, 2036, 2250, 2464, 2678, 2892, 3105, 3319, - 3532, 3745, 3958, 4171, 4383, 4596, 4808, 5020, 5232, 5444, 5655, 5866, 6077, 6288, 6498, 6708, - 6918, 7127, 7336, 7545, 7754, 7962, 8170, 8377, 8585, 8791, 8998, 9204, 9409, 9615, 9819, 10024, - 10228, 10431, 10634, 10837, 11039, 11241, 11442, 11643, 11843, 12043, 12242, 12441, 12639, 12836, 13033, 13230, - 13426, 13621, 13816, 14010, 14204, 14397, 14589, 14781, 14972, 15162, 15352, 15541, 15730, 15917, 16105, 16291, - 16477, 16662, 16846, 17030, 17213, 17395, 17576, 17757, 17937, 18116, 18294, 18472, 18648, 18824, 18999, 19174, - 19347, 19520, 19692, 19863, 20033, 20202, 20371, 20538, 20705, 20871, 21035, 21199, 21363, 21525, 21686, 21846, - 22006, 22164, 22322, 22478, 22634, 22788, 22942, 23095, 23246, 23397, 23546, 23695, 23843, 23989, 24135, 24279, - 24423, 24565, 24707, 24847, 24986, 25125, 25262, 25398, 25533, 25667, 25800, 25931, 26062, 26191, 26320, 26447, - 26573, 26698, 26821, 26944, 27066, 27186, 27305, 27423, 27540, 27655, 27770, 27883, 27995, 28106, 28216, 28324, - 28431, 28537, 28642, 28746, 28848, 28949, 29049, 29148, 29245, 29341, 29436, 29530, 29622, 29713, 29803, 29891, - 29979, 30064, 30149, 30232, 30315, 30395, 30475, 30553, 30630, 30705, 30780, 30853, 30924, 30994, 31063, 31131, - 31197, 31262, 31326, 31388, 31449, 31508, 31567, 31624, 31679, 31733, 31786, 31837, 31887, 31936, 31984, 32029, - 32074, 32117, 32159, 32200, 32239, 32276, 32313, 32348, 32381, 32413, 32444, 32473, 32501, 32528, 32553, 32577, - 32600, 32621, 32640, 32658, 32675, 32691, 32705, 32717, 32729, 32738, 32747, 32754, 32759, 32764, 32766, 32767, -}; -const Word16 short_window_32kHz_fx[L_FRAME32k/2/2] = /* second half is symetric and omitted */ -{ - 161, 483, 804, 1126, 1447, 1768, 2090, 2411, 2731, 3052, 3372, 3692, 4011, 4330, 4649, 4967, - 5285, 5602, 5919, 6235, 6550, 6865, 7180, 7493, 7806, 8118, 8429, 8740, 9049, 9358, 9666, 9973, - 10279, 10584, 10888, 11191, 11492, 11793, 12093, 12391, 12688, 12984, 13279, 13572, 13865, 14155, 14445, 14733, - 15019, 15305, 15588, 15871, 16151, 16430, 16708, 16984, 17258, 17531, 17802, 18071, 18338, 18604, 18868, 19130, - 19390, 19649, 19905, 20160, 20413, 20663, 20912, 21159, 21403, 21646, 21886, 22125, 22361, 22595, 22827, 23056, - 23284, 23509, 23732, 23953, 24171, 24387, 24601, 24812, 25021, 25228, 25432, 25633, 25833, 26029, 26223, 26415, - 26604, 26791, 26975, 27156, 27335, 27511, 27684, 27855, 28023, 28188, 28351, 28511, 28668, 28823, 28974, 29123, - 29269, 29412, 29553, 29690, 29825, 29957, 30086, 30212, 30335, 30455, 30572, 30687, 30798, 30906, 31012, 31114, - 31214, 31310, 31403, 31494, 31581, 31665, 31747, 31825, 31900, 31972, 32041, 32107, 32169, 32229, 32286, 32339, - 32389, 32437, 32481, 32522, 32559, 32594, 32626, 32654, 32679, 32701, 32720, 32736, 32749, 32758, 32764, 32767, -}; - -const Word16 short_window_16kHz_fx[L_FRAME16k/2/2] = /* second half is symetric and omitted */ -{ - 322, 965, 1608, 2250, 2892, 3532, 4171, 4808, 5444, 6077, 6708, 7336, 7962, 8585, 9204, 9819, - 10431, 11039, 11643, 12242, 12836, 13426, 14010, 14589, 15162, 15730, 16291, 16846, 17395, 17937, 18472, 18999, - 19520, 20033, 20538, 21035, 21525, 22006, 22478, 22942, 23397, 23843, 24279, 24707, 25125, 25533, 25931, 26320, - 26698, 27066, 27423, 27770, 28106, 28431, 28746, 29049, 29341, 29622, 29891, 30149, 30395, 30630, 30853, 31063, - 31262, 31449, 31624, 31786, 31936, 32074, 32200, 32313, 32413, 32501, 32577, 32640, 32691, 32729, 32754, 32766, -}; - -const Word16 short_window_8kHz_fx[L_FRAME8k/2/2] = /* second half is symetric and omitted */ -{ - 643, 1929, 3212, 4490, 5760, 7022, 8274, 9512, - 10736, 11943, 13132, 14300, 15447, 16569, 17666, 18736, - 19777, 20788, 21766, 22711, 23621, 24494, 25330, 26127, - 26883, 27598, 28270, 28899, 29483, 30022, 30514, 30959, - 31357, 31706, 32007, 32258, 32459, 32610, 32711, 32762, -}; - -const Word16 Hilbert_coeffs_fx[4*NUM_HILBERTS][HILBERT_ORDER1+1] = /* Q14 */ -{ - { 0, 14320, 0, -30699, 0, 16384}, /* num_Real[0] */ - {11897, 0, -28240, 0, 16384, 0}, /* num_Imag[0] */ - {16384, 0, -30699, 0, 14320, 0}, /* den_Real[0] */ - {16384, 0, -28240, 0, 11897, 0}, /* den_Imag[0] */ - {7671, 0, -23855, 0, 16384, 0}, /* num_Real[1] */ - { 2505, 0, -18139, 0, 16384, 0}, /* num_Imag[1] */ - {16384, 0, -23855, 0, 7671, 0}, /* den_Imag[1] */ - {16384, 0, -18139, 0, 2505, 0}, /* den_Imag[1] */ -}; - - -const Word16 win_flatten_4k_fx[L_FRAME16k/8] = /*Q15 */ -{ - 13, 114, 315, 615, 1013, 1505, 2089, 2761, - 3517, 4353, 5263, 6241, 7282, 8378, 9525, 10713, - 11937, 13188, 14458, 15741, 17027, 18310, 19580, 20831, - 22055, 23243, 24390, 25486, 26527, 27505, 28415, 29251, - 30007, 30679, 31263, 31755, 32153, 32453, 32654, 32755 -}; - -const Word16 gaus_dico_swb_fx[256] = -{ - /*Q15 */ - 709, 11759, -5333, -2701, 2397, -18, -4286, 2368, - -4576, -1584, -900, -940, 3676, 5441, -44, 2234, - -5698, 3082, -2671, 1666, -640, -3343, -1005, -1689, - 2048, 281, -3935, -3723, 5628, 385, -746, -3243, - -3332, -7228, -1748, -206, -5474, 2554, 2861, 3168, - 5039, 588, -508, -8167, 6549, -3433, 2187, -3666, - -5874, 2767, 8370, 1038, 6434, 6279, 625, 4030, - -1031, 1823, 9896, -1395, 2712, -1110, -742, 6142, - -4456, -10487, -144, -5104, 1968, -312, 6176, 2173, - 2334, -240, 2712, 7460, 2219, -3116, -56, 2770, - 5577, -1225, 770, 3557, 2246, 2322, 3077, 41, - 992, -4971, 441, -5039, 4913, 3811, 1142, -1283, - -6578, 4171, -1473, -3793, -5008, 1984, -1138, -1185, - 5646, 1014, -5118, 7141, 2656, -7241, -3538, 2337, - 7239, -504, -943, -10129, 702, -3811, -302, 2435, - 5090, 3744, 2335, -3904, -1401, -1662, -7256, 6484, - -6864, -5428, 1954, -7316, -1420, -1542, 5442, 311, - 3698, -1343, -2974, 8756, 324, -1903, 2580, 2635, - 4236, -1851, 3147, -772, -708, -3830, 2601, -1889, - -3444, -762, 3939, 3206, -7406, -837, -1167, -438, - 3707, -1015, -7472, 1849, 4277, 1459, -3047, -3760, - 740, -7134, -3753, -3092, 209, -12121, 1398, 2266, - 2505, -7974, -1121, -3481, -5644, 1329, 4532, 958, - 5311, -4258, -3195, -1769, -3055, 4399, -15, 10182, - 4503, 1912, -1574, 5054, -3163, 4881, -5364, 1925, - -1205, -6432, 2305, -8917, -1422, 514, -3001, 3928, - 2321, 360, -355, 1477, -3492, -4570, 1913, 2772, - -1380, -5161, 3812, 2614, 2204, -3135, 1244, -3066, - -4446, -6389, 4899, -5250, 1372, 1999, 1122, 5312, - 1310, -1189, -3310, 6403, 3818, 7734, 1620, -8533, - 706, 7498, -4472, 1272, -949, 3203, -4427, -2855, - 4419, 2283, 6410, 2584, -3397, -3382, -2976, -48, -}; - - -const Word16 win_flatten_fx[L_FRAME16k/2] = /*Q15 */ -{ - 3, 13, 28, 50, 78, 113, 154, 200, 254, 313, - 378, 450, 528, 611, 701, 797, 899, 1006, 1120, 1239, - 1365, 1496, 1632, 1775, 1923, 2076, 2235, 2400, 2569, 2745, - 2925, 3110, 3301, 3496, 3697, 3902, 4112, 4327, 4546, 4770, - 4999, 5232, 5469, 5710, 5955, 6205, 6458, 6715, 6976, 7240, - 7508, 7779, 8054, 8331, 8612, 8896, 9183, 9472, 9764, 10059, - 10356, 10655, 10956, 11260, 11566, 11873, 12182, 12493, 12805, 13119, - 13434, 13750, 14067, 14385, 14703, 15023, 15342, 15663, 15983, 16304, - 16625, 16945, 17265, 17586, 17905, 18224, 18542, 18860, 19176, 19492, - 19806, 20119, 20431, 20741, 21049, 21355, 21660, 21963, 22263, 22561, - 22857, 23150, 23441, 23729, 24014, 24297, 24576, 24852, 25125, 25395, - 25661, 25923, 26182, 26437, 26689, 26936, 27179, 27418, 27653, 27884, - 28110, 28332, 28549, 28761, 28969, 29172, 29370, 29563, 29751, 29934, - 30112, 30284, 30451, 30613, 30769, 30920, 31065, 31205, 31338, 31467, - 31589, 31705, 31816, 31921, 32020, 32113, 32199, 32280, 32355, 32423, - 32486, 32542, 32592, 32636, 32673, 32704, 32730, 32748, 32761, 32767 -}; -const Word16 AP1_STEEP_FX[ALLPASSSECTIONS_STEEP] = {1985, 14072, 26500}; /*Q15 Format */ -const Word16 AP2_STEEP_FX[ALLPASSSECTIONS_STEEP] = {7230, 20838, 30852}; /*Q15 Format */ - -const Word16 cos_fb_exc_fx[32] = /* Q15 */ -{ - /*Q35*/ - 32767, 32138, 30274, 27246, 23170, 18205, 12540, 6393, - 0, -6393, -12540, -18205, -23170, -27246, -30274, -32138, - -32768, -32138, -30274, -27246, -23170, -18205, -12540, -6393, - 0, 6393, 12540, 18205, 23170, 27246, 30274, 32138, -}; - - -const Word16 subwin_wb_fx[SHB_OVERLAP_LEN/2+1]= -{0, 5126, 10126, 14876, 19261, 23170, 26510, 29197, 31164, 32365, 32767 }; - -const Word16 window_wb_fx[L_SHB_LAHEAD/4]=/*sin, 1 */ -{ 7502, 18518, 27034, 31898, 32767}; /*Q15*/ - -const Word16 window_shb_fx[L_SHB_LAHEAD]= /*sin, 1, sin */ -{ - /*Q15(round) */ - 1513, 4527, 7502, 10413, 13236, 15945, 18518, 20934, 23170, 25210, - 27034, 28627, 29976, 31069, 31898, 32454, 32733, 32767, 32767, 32767, -}; - -const Word16 window_shb_32k_fx[2*L_SHB_LAHEAD] = -{ - /*Q15(round) */ - 1513, 3020, 4527, 6015, 7502, 8958, 10413, 11825, 13236, 14590, - 15945, 17232, 18518, 19726, 20934, 22052, 23170, 24190, 25210, 26122, - 27034, 27830, 28627, 29301, 29976, 30523, 31069, 31483, 31898, 32176, - 32454, 32593, 32733, 32751, 32767, 32767, 32767, 32767, 32767, 32767, -}; - -const Word16 subwin_shb_fx[SHB_OVERLAP_LEN+1]= -{ - /*Q15(round) */ - 0, 202, 802, 1786, 3129, - 4799, 6754, 8946, 11321, 13821, - 16384,18947, 21447, 23822, 26014, - 27969, 29639, 30982, 31966, 32566, - 32767 -}; - -/*----------------------------------------------------------------------------------* - * FEC for HQ core - *----------------------------------------------------------------------------------*/ - -const short Num_bands_NB[MAX_SB_NB] = {8,8,2}; - - -const Word16 hvq_cb_search_overlap24k[17] = -{ - 0, 8, 17, 27, - 39, 53, 69, 89, - 113, 128, 128, 128, - 128, 128, 128, 128, - 128 -}; - -const Word16 hvq_cb_search_overlap32k[21] = -{ - 0, 6, 13, 21, - 30, 40, 51, 64, - 78, 96, 116, 128, - 128, 128, 128, 128, - 128, 128, 128, 128, - 128 -}; - - -const Word16 hvq_pg_huff_offset[NUM_PG_HUFFLEN] = {0,2,3,8,9,11,13,15,19}; -const Word16 hvq_pg_huff_thres[NUM_PG_HUFFLEN] = {0,0x2,0x4,0x18,0x20,0x40,0x80,0x100,0x300}; - -const Word16 hvq_pg_huff_tab[32] = -{ - 30, 31, 1, 0, 2, 3, 28, 29, 4, 5, 27, 25, 26, 6, 24, 7, 8, 22, 23, 9, 10, 11, 12, 13, 14, - 15, 16, 17, 18, 19, 20, 21 -}; - -const Word16 hvq_cp_huff_len[52] = -{ - 3, 4, 5, 6, 6, 6, 6, 6, 4, 4, 5, 5, 5, 5, 4, 4, 4, 5, 5, 5, 5, 5, 6, 6, 6, 6, 7, 7, 8, - 8, 8, 8, 8, 9, 10, 10, 11, 11, 11, 10, 10, 10, 10, 11, 12, 12, 13, 13, 12, 12, 11, 12 -}; - -const Word16 hvq_cp_huff_val[52] = -{ - 7, 8, 6, 3, 4, 5, 6, 7, 9, 10, 7, 8, 9, 10, 11, 12, 13, 11, 12, 13, 14, 15, 8, 9, 10, - 11, 4, 5, 3, 4, 5, 6, 7, 5, 4, 5, 3, 4, 5, 6, 7, 8, 9, 6, 1, 2, 0, 1, 3, 4, 7, 5 -}; - -const Word16 hvq_cp_layer1_map5[HVQ_CP_MAP_LEN] = { 16, 8, 4, 2, 1, 18, 17, 9 }; - -const Word16 hvq_cp_huff_thres[HVQ_CP_HUFF_NUM_LEN] = { 0x0, 0x2, 0xC, 0x20, 0x50, 0x60, 0x100, 0x180, 0x600, 0x1000, 0x1C00 }; -const Word16 hvq_cp_huff_offset[HVQ_CP_HUFF_NUM_LEN] = { 0, 2, 7, 12, 18, 19, 24, 26, 35, 45, 51 }; - -const Word16 hvq_cp_huff_tab[52] = -{ - 46, 47, 44, 45, 48, 49, 51, 36, 37, 38, 43, 50, 34, 35, 39, 40, 41, 42, 33, 28, 29, 30, 31, 32, 26, 27, - 3, 4, 5, 6, 7, 22, 23, 24, 25, 2, 10, 11, 12, 13, 17, 18, 19, 20, 21, 1, 8, 9, 14, 15, 16, 0 -}; - - - - -const Word16 * const lsf_q_cb_fx[NUM_Q_LSF] = { lsf_q_cb_4b_fx, lsf_q_cb_4b_fx, lsf_q_cb_3b_fx, lsf_q_cb_3b_fx, lsf_q_cb_3b_fx }; -const Word16 lsf_q_cb_size_fx[NUM_Q_LSF] = {16, 16, 8, 8, 8}; -const Word16 grid_smoothing_fx[5] = { 6554, 11469, 16384, 24576, 26214 }; -const Word16 mirror_point_q_cb_fx[MIRROR_POINT_Q_CB_SIZE] = { 471, 692, 896, 1216}; - -const Word16 lbr_wb_bwe_lsfvq_cbook_2bit_fx[4*4] = -{ - /*Q15 */ - 3876, 5920, 8951, 11884, - 6556, 7979, 10835, 13133, - 4401, 6781, 10676, 13493, - 8453, 9693, 12024, 13921, -}; - -const Word32 SHBCB_FrameGain16_fx[16]= -{ - /*Q18*/ - 38968, 125277, 254474, 493383, 1043711, 2083177, 3792746, 6395076, - 10256080, 15738899, 23269902, 34118236, 48362464, 71128080, 107459896, 192888864 -}; -const Word16 full_band_bpf_1_fx[6][5] = /*in Q13*/ -{ - { 789, 802, 248, 802, 789}, - { 789, 1199, 838, 1199, 789}, - { 789, 136, -1123, 136, 789}, - { 8192, 19654, 24391, 17059, 6561}, - { 8192, 15339, 20118, 13819, 6190}, - { 8192, 21155, 26558, 17237, 5599} -}; - -/* 12th order elliptic Bandpass filter at 16.3 to 19.8 kHz sampled at 48 kHz b0,b1,b2,a0,a1,a2 */ -const Word16 full_band_bpf_2_fx[6][5] = /*in Q13*/ -{ - { 492, 912, 974, 912, 492}, - { 492, 1161, 1353, 1161, 492}, - { 492, 259, -311, 259, 492}, - { 8192, 22912, 30622, 21214, 7143}, - { 8192, 20364, 27329, 18844, 6886}, - { 8192, 23496, 31199, 20826, 6487} -}; - -/* 12th order elliptic Bandpass filter at 15.4 to 20.0 kHz sampled at 48 kHz b0,b1,b2,a0,a1,a2 */ -const Word16 full_band_bpf_3_fx[6][5] = /*in Q13*/ -{ - {611, 888, 717, 888, 611}, - {611, 1211, 1214, 1211, 611}, - {611, 197, -671, 197, 611}, - {8192, 21727, 28230, 19588, 6871}, - {8192, 18438, 24377, 16796, 6567}, - {8192, 22683, 29442, 19400, 6081} -}; - -const Word16 SHBCB_SubGain5bit_fx[128] = -{ - /*Q14 */ - -2388, -7806, -6576, -6024, - -7066, -5430, -4998, -3495, - -16722, -15343, -960, -7940, - -26291, -5921, -4917, -4378, - -1526, -6621, -8475, -9624, - -8047, -4086, -8940, -3043, - -3630, -5129, -4964, -7381, - -270, -18662, -24233, -25418, - -9246, -7551, -5584, -2053, - -2091, -4622, -9199, -14628, - -4645, -2197, -10255, -9697, - -2438, -9386, -11737, -4570, - -14366, -11436, -8252, -819, - -16192, -16332, -17043, -225, - -5407, -8588, -7577, -2296, - -26309, -21930, -7522, -2514, - -3260, -4246, -7947, -6614, - -1820, -5520, -15272, -19764, - -3706, -3737, -5850, -10520, - -10081, -4050, -4065, -5001, - -3908, -9909, -2881, -9604, - -520, -11156, -12620, -12768, - -4539, -5149, -6208, -4462, - -4866, -7672, -4235, -4407, - -9163, -13411, -2975, -3915, - -12267, -7568, -3842, -2827, - -7181, -4914, -2608, -9392, - -6275, -2868, -5962, -6511, - -12962, -1034, -8517, -10992, - -8247, -7608, -2502, -5026, - -5812, -4998, -3860, -5778, - -16907, -5974, -4434, -3276, -}; - - -/* 5-bit TD WB BWE temporal shaping codebook */ - -const Word16 HBCB_SubGain5bit_fx[128] = -{ - -15224, -17789, -9897, -5048, -456, -1232, -2238, -2782, - -3391, -3864, -4026, -4045, -2017, -1311, -878, -1973, - -12837, -15376, -8273, -4141, -2791, -3037, -2403, -342, - -3388, -3646, -3471, -2829, -157, -2025, -2318, -2243, - -14652, -16433, -7699, -1188, -2567, -1755, -346, -1682, - -2068, -2321, -2344, -2348, -1759, -1038, -1865, -2041, - -11396, -13719, -7749, -2734, -809, -1935, -1886, -781, - -2136, -1940, -942, -1571, -1926, -2378, -2572, -2145, - -17531, -19267, -7721, -2672, -714, -675, -1516, -2071, - -1925, -2325, -2523, -2657, -1644, -1674, -2036, -2017, - -12781, -14601, -6714, -1380, -2093, -1704, -1124, -756, - -2776, -2687, -2066, -1202, -1102, -680, -1956, -2376, - -14436, -15846, -4918, -2071, -1613, -744, -1807, -1381, - -620, -1294, -2026, -2162, -794, -1755, -1167, -1762, - -11627, -13377, -5876, -1959, -1009, -1879, -1027, -1915, - -1734, -1265, -2001, -1018, -698, -1733, -2172, -1195, - -}; - -const Word32 SHBCB_FrameGain64_fx[64]= -{ - /* Q18 */ - 11553, 19429, 27466, 35948, 45184, 54817, 65050, 76114, - 88089, 100815, 114314, 128727, 144236, 160812, 178639, 197656, - 217917, 239688, 263098, 288617, 315962, 345380, 376751, 410569, - 446867, 485779, 527885, 574220, 624562, 679333, 738912, 803391, - 873329, 949299, 1032054, 1121728, 1219559, 1327347, 1446046, 1576547, - 1720983, 1881933, 2062979, 2266614, 2496129, 2759206, 3060575, 3409584, - 3818114, 4295643, 4868000, 5551295, 6368310, 7329048, 8475924, 9889403, - 11649918, 13794493, 16487623, 19979932, 24732260, 31339886, 41958624, 64261100, -}; - -const Word16 lsf_grid_fx[4][5] = -{ - { 5242, 10229, 15516, 21804, 27540, }, - { 5117, 10059, 14949, 20478, 25493, }, - { 4648, 8732, 13022, 18247, 24474, }, - { 5052, 8925, 12903, 19427, 28382, } -}; - -const Word16 ola_win_shb_switch_fold_fx[L_SUBFR16k] = -{ - 322, 965, 1608, 2250, 2892, 3532, 4171, 4808, - 5444, 6077, 6708, 7336, 7962, 8585, 9204, 9819, - 10431, 11039, 11643, 12242, 12836, 13426, 14010, 14589, - 15162, 15730, 16291, 16846, 17395, 17937, 18472, 18999, - 19520, 20033, 20538, 21035, 21525, 22006, 22478, 22942, - 23397, 23843, 24279, 24707, 25125, 25533, 25931, 26320, - 26698, 27066, 27423, 27770, 28106, 28431, 28746, 29049, - 29341, 29622, 29891, 30149, 30395, 30630, 30853, 31063, - 31262, 31449, 31624, 31786, 31936, 32074, 32200, 32313, - 32413, 32501, 32577, 32640, 32691, 32729, 32754, 32766 -}; -const Word16 win_lpc_hb_wb_fx[(L_LOOK_12k8 + L_SUBFR + L_FRAME) * 5/32] = -{ - 17, 70, 157, 279, 435, 625, 849, 1106, - 1396, 1718, 2071, 2454, 2867, 3309, 3779, 4276, - 4799, 5346, 5917, 6510, 7125, 7759, 8411, 9081, - 9766, 10465, 11177, 11900, 12633, 13373, 14120, 14872, - 15627, 16384, 17141, 17896, 18648, 19395, 20135, 20868, - 21591, 22303, 23002, 23687, 24357, 25009, 25643, 26258, - 26851, 27422, 27969, 28492, 28989, 29459, 29901, 30314, - 30697, 31050, 31372, 31662, 31919, 32143, 32333, 32489, - 32611, 32698, 32751 -}; - -const Word16 wac_h[LPC_SHB_ORDER] = -{ - 32763, - 32751, - 32731, - 32703, - 32667, - 32622, - 32570, - 32510, - 32442, - 32366 -}; - -const Word16 wac_l[LPC_SHB_ORDER] = -{ - 31381, - 27317, - 20869, - 12529, - 2980, - 25869, - 16731, - 9600, - 5926, - 7354 -}; - -const Word16 lpc_weights_fx[LPC_SHB_ORDER+1] = -{ - 32767, 31948, 31150, 30371, 29612, - 28871, 28149, 27446, 26760, 26091, 25438 -}; - - - -const Word16 SHBCB_SubGain5bit_12_fx[128] = -{ - /*Q12 */ - -597, -1952, -1644, -1506, -1767, -1357, -1249, -874, - -4181, -3836, -240, -1985, -6573, -1480, -1229, -1094, - -381, -1655, -2119, -2406, -2012, -1022, -2235, -761, - -908, -1282, -1241, -1845, -68, -4666, -6058, -6355, - -2311, -1888, -1396, -513, -523, -1155, -2300, -3657, - -1161, -549, -2564, -2424, -609, -2346, -2934, -1142, - -3591, -2859, -2063, -205, -4048, -4083, -4261, -56, - -1352, -2147, -1894, -574, -6577, -5483, -1881, -628, - -815, -1061, -1987, -1654, -455, -1380, -3818, -4941, - -926, -934, -1463, -2630, -2520, -1013, -1016, -1250, - -977, -2477, -720, -2401, -130, -2789, -3155, -3192, - -1135, -1287, -1552, -1115, -1217, -1918, -1059, -1102, - -2291, -3353, -744, -979, -3067, -1892, -961, -707, - -1795, -1229, -652, -2348, -1569, -717, -1490, -1628, - -3240, -258, -2129, -2748, -2062, -1902, -625, -1257, - -1453, -1250, -965, -1445, -4227, -1494, -1108, -819, - - -}; - - -const Word16 lsf_q_cb_4b_fx[16] = -{ - 589, 773, 914, 1043, - 1173, 1302, 1430, 1558, - 1698, 1843, 1973, 2103, - 2258, 2470, 2787, 3282 - -}; - -const Word16 lsf_q_cb_3b_fx[8] = -{ - 679, 976, 1245, 1491, - 1739, 2011, 2365, 2953 -}; - -const Word16 pwAlpha[10]= {0x6666, 0x51ec, 0x4189, 0x346e, 0x29f1, - 0x218e, 0x1ad8, 0x157a, 0x112e, 0x0dbe - }; - -const Word16 wb_bwe_lsfvq_cbook_8bit_fx[256*6] = -{ - 2107, 3430, 5123, 6677, 9403, 13197, - 4031, 5069, 7343, 8910, 10647, 12245, - 2037, 3542, 6708, 8763, 10505, 12655, - 5732, 6373, 7912, 9546, 12584, 14230, - 2028, 3337, 5473, 7880, 10269, 12450, - 5809, 6497, 8317, 9624, 11497, 14007, - 2428, 3962, 5675, 7724, 11361, 13385, - 6348, 8307, 8898, 9948, 11058, 13350, - 3552, 4421, 5896, 7143, 9975, 13233, - 5719, 6344, 7482, 8403, 10765, 13455, - 3509, 4379, 5896, 7437, 11765, 14307, - 4521, 8122, 8791, 9856, 11232, 14020, - 2175, 3970, 7788, 9803, 11334, 12910, - 4511, 8156, 8886, 10450, 12686, 14959, - 4223, 5285, 7053, 8423, 11317, 14566, - 7159, 8379, 9040, 10122, 11799, 14270, - 1866, 3064, 4848, 7227, 11225, 13963, - 5915, 6631, 8740, 10002, 11385, 12726, - 3342, 4547, 6475, 9404, 11994, 13418, - 6156, 6880, 8932, 10353, 12380, 13746, - 2648, 4972, 7575, 9476, 12117, 13875, - 5822, 6526, 8747, 10941, 12671, 13971, - 4032, 5110, 7592, 9267, 11374, 14390, - 6864, 8384, 9086, 10649, 12944, 15026, - 3661, 4636, 6668, 8329, 10374, 12185, - 5802, 6444, 8344, 9811, 12234, 14843, - 3593, 4436, 6663, 8693, 11539, 14272, - 5110, 8270, 9006, 10703, 12269, 13901, - 1992, 3229, 5616, 9085, 11419, 13254, - 4319, 5859, 9602, 11396, 12836, 14199, - 3836, 4822, 8285, 10190, 11728, 13302, - 8016, 8698, 10179, 11434, 12944, 14783, - 1891, 3329, 6168, 8307, 10818, 14213, - 5803, 6442, 7973, 9131, 11090, 12657, - 2803, 5499, 8093, 9694, 11223, 12849, - 6222, 6981, 8615, 9848, 12016, 13380, - 2543, 4747, 7638, 9373, 11129, 13652, - 5912, 6615, 9006, 10553, 11959, 13312, - 3604, 4520, 7650, 9833, 12161, 14748, - 7970, 8729, 9780, 10789, 12483, 13985, - 3793, 4716, 7041, 8547, 10610, 13601, - 5640, 6235, 7313, 8370, 12057, 14300, - 3765, 4699, 6784, 9512, 12663, 14216, - 4634, 8363, 9195, 10385, 11477, 13310, - 2462, 4816, 8556, 10394, 11920, 13468, - 3698, 7974, 9207, 10962, 13507, 15208, - 3738, 4667, 7545, 10775, 13024, 14559, - 7267, 8610, 9509, 11264, 12821, 14495, - 2624, 4295, 6173, 8897, 12343, 14174, - 6324, 7135, 8742, 10013, 12598, 14108, - 4448, 5839, 8842, 10335, 11737, 13071, - 6147, 6988, 9510, 10893, 12240, 13535, - 3025, 5140, 7152, 9223, 11404, 13255, - 5985, 6782, 9611, 11341, 12723, 14007, - 4679, 5958, 8100, 9842, 11835, 13492, - 7740, 8565, 9432, 10478, 12611, 14609, - 3830, 4784, 7681, 9528, 11134, 12675, - 5742, 6527, 8359, 10728, 13195, 14626, - 4491, 5635, 7284, 8749, 11594, 13785, - 6772, 8490, 9253, 10943, 12476, 13973, - 2024, 3588, 7524, 10453, 12198, 13858, - 5783, 8882, 9978, 11763, 13237, 14829, - 3979, 5009, 8342, 10323, 12231, 14313, - 8148, 8903, 10193, 11350, 13246, 14490, - 2297, 3810, 5638, 7265, 9162, 11514, - 5809, 6518, 7832, 8766, 10327, 11957, - 2535, 4591, 7415, 9080, 10623, 12257, - 5948, 6598, 8515, 10082, 12721, 14188, - 2443, 4278, 6581, 8172, 9883, 11807, - 5913, 6535, 8878, 10296, 12141, 14245, - 2428, 3925, 6409, 9835, 11962, 13628, - 7430, 8531, 9302, 10259, 11444, 12933, - 3701, 4694, 6372, 7671, 9445, 11571, - 5822, 6470, 7807, 8885, 11506, 14529, - 3742, 4580, 6232, 7860, 11252, 13127, - 5710, 8330, 8943, 10243, 11696, 14511, - 2607, 4197, 6714, 10408, 12714, 14320, - 4116, 8438, 9717, 11018, 12156, 13663, - 4224, 5318, 7486, 10110, 12779, 14331, - 5565, 8413, 9115, 10930, 12588, 14759, - 1898, 3150, 5779, 9497, 12432, 14439, - 6274, 7186, 9258, 10404, 11733, 12952, - 3700, 4591, 7575, 9533, 11461, 13777, - 6234, 7104, 9032, 10986, 13088, 14417, - 2354, 4579, 7744, 9960, 12629, 14802, - 6050, 6729, 9345, 10745, 12436, 14253, - 4345, 5529, 8117, 9718, 12433, 14109, - 8009, 8701, 9863, 10954, 13046, 14474, - 4184, 5186, 6876, 8428, 11236, 12973, - 6113, 6842, 8386, 9659, 12892, 14707, - 3989, 4936, 7152, 8879, 11743, 13632, - 5169, 8411, 9209, 11361, 13452, 15076, - 2397, 4387, 7033, 9035, 11821, 13736, - 3607, 8128, 10170, 11565, 12819, 14147, - 4449, 5805, 8963, 10676, 12596, 14558, - 7911, 8741, 10040, 11622, 13579, 15092, - 2372, 4290, 6990, 8705, 10637, 13685, - 6137, 6917, 8382, 9380, 10859, 12348, - 3235, 5973, 8187, 10174, 12420, 14382, - 6077, 6764, 8551, 9803, 12150, 14079, - 2952, 5097, 6853, 8952, 12066, 14080, - 6606, 7683, 9508, 10695, 12182, 13601, - 3707, 4638, 7468, 10484, 12295, 13754, - 7960, 8715, 10051, 11348, 12757, 14072, - 4139, 5241, 7576, 9037, 10912, 13485, - 5838, 6444, 7768, 8965, 12867, 14998, - 4245, 5338, 7248, 9190, 12328, 14047, - 6159, 8874, 9899, 11134, 12150, 13512, - 2250, 4288, 8698, 10944, 12624, 14316, - 3146, 6848, 9904, 11775, 13534, 14953, - 4044, 5161, 8365, 10294, 12945, 14907, - 7398, 8724, 9813, 11821, 13246, 14552, - 2121, 3890, 6855, 9274, 12059, 14663, - 6329, 7182, 8789, 10081, 13001, 14917, - 4484, 5761, 8634, 10295, 12111, 14022, - 6326, 7208, 9672, 11078, 12830, 14529, - 3230, 5564, 7646, 9955, 12011, 13683, - 4683, 6896, 10002, 11805, 13329, 14747, - 4771, 6044, 8081, 10305, 12526, 14037, - 8231, 9203, 10351, 11427, 12926, 14635, - 4385, 5774, 7989, 9305, 10751, 12299, - 5810, 6658, 9062, 11629, 13359, 14655, - 4288, 5388, 7804, 9378, 11781, 13652, - 4398, 8560, 9646, 11161, 12701, 14872, - 1947, 3440, 7202, 10953, 13222, 14806, - 4686, 8972, 10615, 12054, 13260, 14615, - 3801, 4849, 8922, 11200, 12882, 14423, - 8061, 8813, 10453, 11912, 13335, 14710, - 2365, 3888, 5664, 7346, 10407, 14331, - 4563, 5839, 7472, 8684, 10572, 12800, - 2593, 4197, 6719, 9323, 11229, 12919, - 6081, 6774, 8132, 9244, 12202, 13918, - 2405, 3981, 6144, 8740, 11347, 13796, - 5793, 6444, 8286, 10049, 12152, 13520, - 2795, 4727, 6528, 8506, 11323, 13474, - 6181, 8598, 9346, 10614, 11725, 13545, - 4002, 5001, 6596, 7792, 9987, 13065, - 5748, 6365, 7759, 9028, 11818, 13487, - 3906, 4863, 6462, 7763, 10705, 14359, - 4315, 8428, 9322, 10582, 11942, 14500, - 2812, 4622, 7346, 10036, 11745, 13429, - 4221, 8338, 9277, 11280, 12869, 14317, - 4345, 5427, 7121, 8736, 12787, 14837, - 7678, 8614, 9456, 10461, 12024, 13852, - 2193, 3662, 5609, 7867, 12276, 14739, - 6083, 6864, 8879, 10080, 11623, 13720, - 4114, 5125, 7224, 9729, 11808, 13297, - 6383, 7232, 9252, 10720, 12622, 14030, - 2788, 5189, 8074, 9953, 11795, 14361, - 6079, 6987, 8662, 10589, 12444, 14390, - 4480, 5690, 7708, 9115, 11800, 14576, - 7848, 8763, 9802, 10924, 12515, 14832, - 3582, 4575, 6729, 9084, 11139, 12800, - 5885, 6534, 8853, 10432, 12664, 14960, - 3891, 4850, 7195, 8932, 12097, 14665, - 5797, 8545, 9385, 11556, 12997, 14392, - 1962, 3544, 7039, 9349, 11272, 13857, - 4106, 5493, 9652, 12038, 13603, 14932, - 4328, 5413, 7949, 10282, 12164, 13618, - 8135, 8918, 10057, 11085, 13190, 15015, - 2702, 4627, 6447, 8009, 10197, 13676, - 5998, 6656, 8315, 9496, 11597, 13122, - 3146, 6293, 8530, 10158, 11798, 13558, - 6374, 7289, 8698, 9776, 11885, 14236, - 3171, 5794, 7737, 9377, 11312, 13878, - 6279, 7150, 9192, 10414, 12052, 14174, - 4117, 5195, 7805, 9512, 12450, 14849, - 7963, 8955, 10071, 11129, 12324, 13605, - 4365, 5505, 7013, 8171, 10488, 13658, - 6124, 6894, 8286, 9349, 11859, 14737, - 3753, 4673, 6421, 8146, 12726, 14980, - 5457, 8706, 9598, 11035, 12294, 14268, - 2783, 4916, 7947, 10568, 12395, 14123, - 3909, 8145, 9524, 11951, 14052, 15282, - 3952, 5139, 8180, 11380, 13699, 15085, - 7200, 9031, 10025, 11484, 12924, 14848, - 2533, 4412, 6472, 8299, 11405, 14627, - 6563, 7530, 9064, 10267, 12560, 14422, - 4849, 6618, 8678, 10166, 11983, 13841, - 6393, 7569, 9960, 11300, 12644, 13906, - 3170, 5117, 7158, 9665, 11687, 14114, - 6122, 7071, 10013, 11733, 13170, 14466, - 4308, 5441, 7607, 9900, 11904, 14292, - 8129, 9024, 10087, 11081, 12670, 14356, - 4253, 5392, 8175, 9780, 11353, 12988, - 5453, 6638, 8596, 11453, 13885, 15263, - 4664, 5903, 7618, 9420, 12198, 13853, - 7149, 8859, 9746, 11029, 12219, 14188, - 2318, 4251, 7702, 9889, 11778, 14182, - 6679, 9280, 10573, 11950, 13100, 14491, - 4010, 5176, 8989, 10821, 12250, 13654, - 8076, 8886, 10411, 11722, 12992, 14267, - 2308, 4017, 6024, 7618, 9736, 13081, - 6001, 6751, 7987, 8966, 10964, 13589, - 2908, 5350, 7266, 8739, 10442, 12981, - 6143, 6839, 9027, 10366, 12881, 14416, - 2667, 4224, 6172, 8378, 10717, 12602, - 6275, 7120, 9249, 10613, 12580, 14823, - 2692, 4586, 6968, 9858, 12120, 14209, - 7771, 8769, 9743, 10745, 11943, 13225, - 4201, 5355, 7129, 8337, 9975, 11767, - 6216, 7100, 8444, 9442, 11298, 13690, - 4111, 5040, 6562, 8071, 12034, 13923, - 6657, 8599, 9337, 10665, 12040, 14704, - 3060, 5215, 7260, 10118, 12577, 14386, - 5103, 8913, 10157, 11519, 12669, 14220, - 4633, 5920, 7804, 9514, 12741, 14690, - 6720, 8585, 9448, 11556, 13510, 15095, - 2361, 3970, 6213, 9335, 13270, 15075, - 6506, 7440, 9041, 10179, 12024, 13587, - 4221, 5405, 8311, 9818, 11579, 14044, - 6216, 7224, 9515, 11389, 13545, 15068, - 2872, 5507, 8153, 10650, 13065, 14825, - 6002, 6676, 9393, 11023, 12965, 14755, - 4438, 5642, 8268, 10097, 12295, 14724, - 7797, 8622, 9642, 10932, 13287, 15118, - 4471, 5638, 7551, 9217, 11440, 12928, - 6051, 6890, 8906, 10655, 13437, 15116, - 3953, 4934, 7779, 9619, 12204, 14012, - 5439, 8649, 9791, 12232, 13899, 15193, - 2728, 4495, 6728, 9363, 11344, 14053, - 4069, 8460, 9835, 11742, 13366, 14825, - 4874, 6937, 9226, 10944, 12845, 14547, - 8195, 9093, 10392, 11594, 13355, 15010, - 2956, 5192, 7080, 8765, 11014, 14174, - 6384, 7287, 8812, 9816, 11336, 12808, - 2912, 6122, 9132, 10874, 12583, 14265, - 6148, 6925, 8821, 10030, 12212, 14758, - 2572, 4778, 7325, 9216, 11620, 14651, - 6654, 7718, 9546, 10806, 12633, 14354, - 4328, 5514, 8231, 10852, 12821, 14261, - 8051, 9205, 10385, 11490, 12674, 13988, - 4624, 6013, 7907, 9239, 11160, 13787, - 5786, 6531, 8210, 9968, 13410, 15249, - 3859, 4898, 7132, 9692, 13395, 15118, - 6712, 8944, 10028, 11521, 12690, 14118, - 2417, 4875, 9132, 11671, 13382, 14841, - 4113, 8355, 10734, 12517, 13905, 15115, - 4455, 5753, 7923, 10298, 13343, 15030, - 6998, 8878, 10113, 12233, 13768, 15107, - 2720, 4801, 6883, 9267, 12694, 14837, - 6507, 7496, 9312, 10696, 13185, 14850, - 4631, 6341, 9164, 10796, 12325, 13734, - 6602, 7817, 9932, 11349, 13132, 14672, - 3089, 5561, 7579, 9433, 12256, 14633, - 6246, 7715, 10371, 12065, 13563, 14878, - 4757, 6352, 8543, 10216, 12748, 14620, - 8183, 9366, 10628, 11857, 13185, 14599, - 4734, 6314, 8348, 9716, 11274, 12942, - 5824, 6871, 9829, 12268, 13874, 15138, - 4719, 6142, 8224, 9683, 11915, 14350, - 6288, 8774, 9655, 11204, 12696, 14867, - 2661, 4586, 7326, 10934, 13501, 15026, - 5932, 9323, 10877, 12454, 13715, 15004, - 4467, 6039, 8842, 11164, 13356, 14901, - 7880, 9158, 10593, 12209, 13609, 14989, -}; - -const Word16 swb_tbe_lsfvq_cbook_8b[256*LPC_SHB_ORDER] = /* Q15 */ -{ - 1705, 3230, 4202, 5086, 6148, 7221, 8127, 10728, 13656, 15364, - 1668, 2958, 4063, 5644, 7356, 9440, 11046, 12261, 13228, 14503, - 1546, 2917, 4226, 5477, 6976, 8349, 9709, 11882, 13218, 14715, - 1158, 2729, 5177, 6967, 8297, 9611, 10655, 11668, 12757, 14415, - 1616, 3005, 4368, 5810, 7107, 8129, 9376, 10457, 12738, 14835, - 1232, 2451, 4145, 6446, 7741, 8993, 10377, 11898, 14213, 15314, - 1638, 3089, 5134, 6351, 7360, 8304, 9787, 12377, 13755, 15209, - 1264, 2543, 5564, 6686, 7958, 9481, 11021, 12517, 13875, 15147, - 1304, 2537, 3713, 4863, 6564, 7910, 9400, 11794, 13268, 14834, - 1652, 3245, 4686, 6405, 7931, 9223, 10591, 12020, 13193, 14759, - 1302, 2619, 4287, 5884, 7166, 8556, 10512, 12471, 13767, 15075, - 2034, 3467, 5577, 6530, 7674, 8783, 10920, 12798, 13727, 15002, - 2621, 3956, 5275, 6542, 7509, 8517, 9456, 10781, 12456, 14099, - 1496, 2653, 4147, 5637, 7370, 9233, 11817, 12986, 13968, 15046, - 2224, 3324, 4700, 5868, 7211, 8638, 11369, 12695, 13600, 14559, - 1267, 3050, 4707, 6321, 8663, 10140, 11174, 12453, 13425, 14844, - 1662, 2980, 4155, 5414, 6639, 7797, 9253, 11360, 12838, 14440, - 1521, 2856, 4944, 6367, 7506, 8857, 10971, 12183, 13275, 15006, - 1454, 2859, 4563, 5971, 7186, 8569, 10151, 11770, 13396, 14984, - 1143, 2942, 5267, 6840, 8377, 9457, 10589, 11615, 13892, 15271, - 1674, 3053, 4605, 5768, 7104, 8452, 10094, 11782, 12793, 13758, - 1702, 3261, 4723, 6245, 7899, 9494, 11010, 12387, 13680, 15066, - 1365, 2796, 5406, 6505, 7488, 8679, 10447, 12000, 13637, 15046, - 2090, 3931, 5788, 7157, 8254, 9717, 11007, 12081, 13238, 14880, - 1952, 3157, 4132, 5164, 6334, 7389, 9004, 11798, 14096, 15505, - 1641, 3212, 4919, 6364, 7863, 9311, 10766, 12234, 13694, 15054, - 1653, 3008, 4213, 5354, 6980, 8821, 11185, 12685, 13903, 15251, - 1856, 3444, 5146, 6579, 7801, 9250, 11062, 12947, 14145, 15291, - 1365, 3567, 5552, 6474, 7332, 8254, 9952, 11364, 13505, 14951, - 1488, 2896, 4521, 6279, 7880, 9446, 11418, 12921, 14431, 15465, - 1516, 3174, 5364, 6410, 7295, 8285, 10799, 12594, 14172, 15424, - 1738, 3416, 5237, 6878, 8440, 10539, 12105, 13063, 13924, 15150, - 1431, 2659, 3909, 5328, 6641, 7950, 9347, 11037, 13510, 14992, - 1400, 2646, 4233, 6366, 7749, 9220, 10560, 11594, 13046, 14992, - 1115, 2198, 3607, 5279, 8055, 9774, 11024, 12426, 13972, 15232, - 1360, 3418, 5724, 6973, 7912, 9078, 10810, 12437, 13630, 14826, - 1422, 3051, 5132, 6141, 7206, 8275, 9355, 10859, 13814, 15202, - 1080, 2227, 4117, 6404, 8080, 9318, 10934, 12404, 13688, 14827, - 1611, 3423, 4928, 6214, 7426, 8723, 10502, 11915, 13438, 15105, - 1947, 3524, 5198, 7008, 8358, 10006, 11397, 12444, 13583, 15135, - 1394, 2672, 4004, 5681, 6953, 8301, 9815, 12000, 13709, 15079, - 1788, 3193, 4579, 6221, 7874, 9170, 11186, 12647, 13521, 14538, - 1548, 2811, 4058, 5331, 6528, 7769, 10982, 12743, 13822, 15131, - 1751, 4007, 5154, 6463, 7935, 9470, 11103, 12406, 13337, 14520, - 2004, 3172, 5079, 6116, 7109, 8155, 10351, 12192, 13413, 14773, - 1644, 3185, 4750, 6290, 7816, 9271, 11041, 12831, 14139, 15341, - 2311, 3779, 5116, 6100, 7321, 9139, 10353, 12134, 13834, 15172, - 1723, 3339, 5049, 6754, 8353, 10290, 12048, 13157, 14206, 15460, - 2218, 3501, 4639, 5764, 6789, 7834, 9804, 11907, 13182, 14689, - 1640, 3173, 4679, 6202, 7660, 9120, 10773, 12395, 13894, 15200, - 1591, 3070, 4537, 6005, 7341, 8802, 10480, 12240, 13768, 15130, - 1169, 3611, 5983, 7054, 8601, 10022, 10948, 11927, 12834, 14747, - 1708, 3191, 4642, 6156, 7396, 8805, 10028, 11733, 13206, 14857, - 1519, 3082, 4752, 6484, 7730, 9328, 10796, 12003, 14524, 15513, - 2153, 3558, 5162, 6714, 7762, 8857, 10008, 12012, 13725, 15209, - 2680, 4053, 5310, 6996, 8309, 9343, 10361, 12333, 14224, 15498, - 2356, 3805, 5032, 5970, 6915, 7880, 8924, 12060, 13838, 15185, - 1807, 3439, 4962, 6483, 8013, 9556, 10952, 12327, 13686, 15059, - 1571, 2900, 4208, 6449, 7675, 8592, 11138, 12775, 14181, 15422, - 2006, 4262, 5508, 6414, 7621, 8725, 10788, 12605, 13609, 14776, - 1785, 3741, 5267, 6702, 8097, 9460, 10487, 11481, 12889, 14885, - 1647, 3223, 4795, 6391, 8007, 9620, 11575, 12955, 14100, 15381, - 1518, 3214, 5233, 6509, 7687, 8803, 11778, 13932, 14760, 15491, - 2136, 3647, 5373, 7317, 8671, 10261, 11786, 12933, 13820, 15186, - 1633, 3265, 4672, 5640, 6776, 7783, 8907, 10184, 12066, 14492, - 1690, 3028, 4184, 6049, 7489, 8678, 11045, 12244, 13372, 15016, - 1649, 3080, 4358, 5795, 7364, 8601, 10257, 12126, 13328, 15113, - 1850, 3286, 5392, 6765, 7826, 9185, 10506, 11776, 13248, 15163, - 2111, 3522, 4870, 6087, 7162, 8385, 9645, 10861, 12341, 14302, - 1529, 2909, 4136, 6783, 8064, 9325, 10942, 12094, 13886, 15169, - 1847, 3281, 4752, 6098, 7310, 8744, 10129, 12278, 13554, 14930, - 1149, 2767, 5869, 7479, 8514, 9723, 11235, 12300, 13871, 15068, - 1689, 3066, 4325, 5613, 6772, 7936, 9051, 12135, 13730, 15025, - 2127, 3394, 5263, 6880, 7874, 9155, 10305, 12136, 13494, 14437, - 1682, 3054, 4412, 6053, 7380, 8465, 9817, 12460, 14155, 15285, - 1799, 3430, 5123, 6594, 7934, 9609, 11472, 12791, 13686, 14849, - 1899, 3656, 5369, 6355, 7516, 8800, 9888, 11646, 13024, 13965, - 1410, 3252, 5101, 6050, 7480, 9912, 11739, 12806, 14085, 15186, - 1487, 3934, 5351, 6390, 7519, 8890, 11488, 12818, 13787, 14941, - 1562, 3156, 5075, 7044, 8872, 10271, 11479, 12632, 13907, 14993, - 1548, 2926, 4338, 5796, 7011, 8143, 9336, 11323, 13461, 14904, - 1421, 2907, 4736, 6272, 7730, 8977, 10453, 12374, 13840, 15234, - 1495, 2996, 4496, 6036, 7545, 9034, 10534, 12014, 13486, 14958, - 1388, 3203, 5691, 7076, 8578, 9661, 10874, 12326, 14433, 15423, - 1248, 2983, 5304, 6423, 7544, 8611, 10290, 11682, 12904, 14549, - 1496, 2988, 4632, 6342, 7852, 9329, 11175, 12546, 13758, 15182, - 1373, 3379, 5067, 6179, 7379, 8775, 10005, 11464, 14147, 15386, - 2537, 3849, 5533, 7263, 8318, 9657, 11346, 12355, 13955, 15314, - 2113, 3405, 4419, 5268, 6436, 8005, 10292, 12442, 13655, 15176, - 1620, 3681, 5454, 6406, 7459, 9354, 10872, 12035, 14163, 15279, - 1903, 3232, 4517, 5758, 7156, 8851, 10670, 12413, 14518, 15565, - 1714, 3779, 5166, 6557, 8107, 9168, 10560, 12854, 14208, 15329, - 1926, 3645, 5521, 7072, 7999, 8974, 9806, 11088, 13527, 15298, - 1820, 2840, 4726, 7091, 8261, 9758, 11218, 12148, 14064, 15262, - 2072, 3303, 5391, 6710, 7504, 8497, 10457, 12394, 14480, 15541, - 1627, 3294, 5209, 7432, 8846, 10147, 11517, 12890, 14488, 15411, - 2172, 3405, 4580, 5623, 6732, 7648, 8485, 9913, 13396, 15213, - 1581, 3058, 4633, 6225, 7724, 9238, 10779, 12240, 13650, 15094, - 1675, 2927, 4090, 5753, 7461, 8922, 10277, 11670, 13987, 15336, - 1868, 3611, 5256, 6927, 8093, 9434, 10998, 12144, 13380, 15165, - 1498, 3635, 5273, 6823, 7825, 8916, 9811, 10903, 12514, 14884, - 1448, 2626, 3930, 6895, 8348, 9746, 11404, 12565, 14288, 15325, - 1945, 3408, 4987, 6340, 7627, 8954, 10251, 12381, 13481, 14983, - 1956, 3759, 5388, 6894, 8466, 9962, 11460, 12759, 14145, 15321, - 1670, 3271, 4588, 5970, 7185, 8366, 9640, 12011, 13488, 14833, - 1964, 3444, 4826, 6213, 7936, 9097, 10785, 12617, 13612, 15229, - 1646, 3390, 4669, 6049, 7001, 7940, 10461, 12478, 14675, 15704, - 2202, 3782, 5107, 6754, 8280, 9628, 11687, 13028, 13871, 15207, - 2354, 3830, 5174, 6360, 7555, 8997, 10681, 11977, 13066, 14781, - 2351, 3525, 4892, 6386, 7616, 9133, 11859, 13061, 13946, 15004, - 2252, 3772, 5155, 6485, 7799, 9145, 10769, 12561, 13763, 15241, - 1714, 3107, 4725, 6097, 9158, 10459, 11619, 12699, 14346, 15256, - 1830, 3506, 4969, 5973, 6900, 7836, 8994, 11088, 13366, 14860, - 1856, 3406, 4898, 6367, 7810, 9186, 10422, 12172, 13969, 15331, - 2006, 3382, 4743, 6100, 7430, 8753, 10805, 12234, 13673, 15195, - 1491, 3607, 5343, 7464, 9179, 10087, 11024, 12099, 13199, 14956, - 1749, 3371, 5121, 6500, 7646, 8770, 9968, 11673, 13339, 14931, - 1857, 3506, 5083, 6595, 8200, 9739, 11138, 12528, 13884, 15137, - 1780, 3860, 5581, 6692, 7837, 8989, 10304, 12318, 13611, 15109, - 2164, 4463, 5655, 7632, 9047, 9922, 10784, 12950, 14723, 15589, - 2305, 3300, 4366, 5608, 6857, 7795, 10006, 11950, 14376, 15700, - 1628, 3408, 5074, 6761, 8312, 9687, 11104, 12332, 13619, 15076, - 1842, 3314, 4771, 6460, 7463, 8661, 11191, 12739, 14592, 15633, - 1808, 4360, 5904, 6869, 8134, 9174, 10780, 12589, 13995, 15150, - 2966, 4354, 5686, 6983, 7938, 9092, 10062, 11747, 13307, 14611, - 1932, 3293, 4910, 6818, 7690, 9074, 11715, 13019, 14429, 15478, - 1978, 3772, 5429, 6580, 7448, 8496, 11755, 13132, 14549, 15560, - 1881, 3635, 5627, 7292, 8573, 10911, 12325, 13200, 14068, 15243, - 1436, 2716, 4002, 5347, 6553, 7646, 8955, 10690, 12967, 14784, - 1426, 2825, 4206, 5726, 8100, 9391, 10712, 12262, 13506, 14954, - 1448, 2767, 4089, 5265, 7185, 8684, 10378, 12257, 13431, 14803, - 1669, 3312, 4990, 6887, 8050, 9595, 10943, 12015, 13145, 14920, - 1534, 2814, 4191, 5933, 7393, 8687, 9865, 11185, 12958, 14743, - 1397, 2706, 4322, 6052, 7618, 9168, 10995, 12433, 13931, 15267, - 1717, 3164, 4630, 6329, 7519, 8846, 10088, 12116, 14012, 15197, - 1606, 3316, 5165, 6942, 8278, 9625, 11461, 12806, 14095, 15299, - 2014, 3357, 4281, 5076, 6191, 7372, 9501, 12414, 13419, 14901, - 1322, 3655, 5269, 6494, 7613, 9253, 10752, 11974, 13302, 14833, - 1687, 3291, 4718, 5817, 7001, 8136, 10741, 12692, 13884, 15224, - 2255, 3723, 5555, 7021, 8101, 9345, 10765, 12705, 13693, 15223, - 2376, 3715, 5249, 6505, 7410, 8345, 10176, 11618, 12708, 14488, - 1842, 3232, 4371, 5954, 7832, 9126, 11296, 12743, 13862, 15331, - 2046, 3597, 5325, 6453, 7353, 8588, 10588, 12082, 13664, 15152, - 1970, 3564, 4925, 6547, 8672, 9980, 11383, 12786, 13969, 15234, - 1497, 2938, 4909, 6099, 7102, 8072, 9514, 11294, 12761, 14578, - 1666, 3164, 5098, 6255, 7350, 8902, 10694, 12503, 13808, 14980, - 1467, 2774, 4556, 6308, 7435, 8644, 10040, 12356, 13597, 14776, - 1915, 3618, 5160, 6707, 8479, 9521, 10481, 11536, 14163, 15479, - 1857, 3466, 4760, 6205, 7312, 8801, 10376, 11978, 13161, 14235, - 1615, 3107, 4710, 6452, 8069, 9877, 11348, 12575, 13751, 15049, - 1563, 3092, 4977, 6851, 8056, 9025, 10327, 12181, 14039, 15192, - 2294, 3843, 5781, 7222, 8505, 9851, 11210, 12802, 13676, 15158, - 1931, 3436, 4681, 5837, 6908, 7825, 9440, 12600, 14162, 15305, - 1572, 3189, 4879, 6680, 7970, 9293, 10974, 12193, 13506, 15218, - 1759, 3172, 4687, 5950, 7484, 8874, 10563, 12821, 14112, 15299, - 1461, 4009, 5495, 6608, 7867, 9497, 11307, 12520, 14357, 15467, - 1922, 4314, 5736, 6599, 7481, 8598, 9852, 11345, 14012, 15280, - 1249, 2609, 4690, 7006, 8061, 9011, 11477, 13214, 14382, 15337, - 2251, 3776, 5514, 6458, 7300, 8078, 10961, 12696, 14279, 15567, - 1697, 3374, 5134, 6984, 8675, 10700, 12194, 13233, 14184, 15464, - 1985, 3326, 4440, 5685, 6870, 8207, 9545, 11223, 13672, 15143, - 1453, 2824, 4722, 6476, 7730, 8963, 10217, 11743, 13545, 15152, - 1217, 2442, 3821, 5409, 7315, 8949, 10797, 12564, 14281, 15410, - 1546, 3204, 5604, 6730, 8040, 9677, 11029, 12107, 13803, 15267, - 2042, 3424, 4830, 6328, 7473, 8525, 9386, 10755, 13398, 14998, - 1106, 2508, 4816, 7337, 8399, 9630, 11278, 12453, 14067, 15024, - 1764, 3305, 4955, 6537, 7767, 9117, 10404, 11961, 13576, 15021, - 1604, 3797, 5700, 7128, 8515, 9896, 11389, 12534, 13696, 15136, - 1623, 3004, 4355, 6217, 7351, 8437, 9819, 11537, 13974, 15340, - 2457, 3890, 4962, 5848, 7311, 9718, 11213, 12292, 13705, 15111, - 1601, 3330, 4648, 6043, 7138, 8179, 11247, 13078, 14768, 15641, - 2457, 3677, 5174, 6432, 7982, 10024, 11164, 12170, 13704, 15112, - 1552, 3777, 5267, 6325, 7532, 8642, 9894, 12404, 13569, 14620, - 1961, 3463, 4720, 6498, 8059, 9304, 11486, 12824, 14102, 15458, - 2443, 3699, 5252, 6348, 7638, 8733, 10224, 12666, 13768, 15009, - 2204, 3657, 5086, 6792, 8300, 10152, 12313, 13306, 14079, 15287, - 2360, 3731, 5002, 6094, 6952, 8009, 9152, 11586, 13038, 14158, - 1888, 3469, 4880, 6183, 7603, 9244, 10801, 12319, 13657, 15002, - 1670, 3283, 4591, 6080, 7801, 8951, 10534, 12572, 13620, 14969, - 1304, 4140, 5864, 7008, 8377, 9651, 10825, 11805, 13637, 15300, - 2077, 3547, 4890, 6216, 7303, 8608, 9810, 11796, 13525, 14984, - 1658, 3252, 4916, 6498, 8069, 9529, 11029, 12538, 13903, 15184, - 2206, 3648, 4949, 6636, 7875, 8833, 9853, 12624, 14448, 15475, - 3039, 4664, 5792, 7321, 8798, 9724, 10485, 12329, 14465, 15650, - 1885, 3201, 5227, 6590, 7343, 8049, 9372, 12313, 14594, 15645, - 1826, 3446, 5138, 6665, 8008, 9352, 10668, 12583, 13810, 15065, - 1455, 3065, 5233, 6306, 7404, 8776, 11422, 12775, 14032, 15239, - 2395, 4674, 5883, 6877, 7900, 9322, 10931, 12537, 13765, 14888, - 1840, 4359, 5629, 6875, 7968, 9185, 10266, 11861, 13202, 14464, - 1662, 3278, 4865, 6555, 8122, 10011, 11874, 13087, 14128, 15418, - 1643, 3366, 5837, 7033, 7854, 8928, 11487, 12972, 14409, 15467, - 1878, 3685, 5789, 7325, 8714, 10906, 12273, 13110, 13834, 14837, - 2259, 3652, 4995, 6055, 7005, 7900, 8843, 10024, 12609, 14736, - 1568, 2949, 4504, 6035, 7428, 9194, 10893, 12444, 13595, 14939, - 1678, 3143, 4416, 5872, 7501, 8768, 10418, 12127, 13144, 14622, - 1878, 3549, 5481, 7178, 8322, 9347, 10532, 12117, 13554, 15167, - 2055, 3346, 4814, 6193, 7418, 8757, 10144, 11365, 12698, 14779, - 1486, 2779, 3954, 6134, 8290, 9646, 10767, 12112, 14441, 15428, - 1787, 3511, 4962, 6055, 7295, 8858, 10179, 12437, 13813, 15217, - 1374, 3184, 5771, 7998, 9354, 10209, 11249, 12469, 14015, 15248, - 1627, 2947, 4046, 5182, 6798, 8225, 9770, 12661, 14250, 15408, - 2117, 3704, 5007, 6630, 8002, 9222, 10550, 12108, 13472, 15034, - 1365, 2885, 4896, 6144, 7426, 9137, 10283, 12727, 14709, 15505, - 2073, 3691, 5305, 6800, 8134, 9508, 11139, 12857, 13896, 15239, - 1564, 4084, 5497, 6495, 7391, 8539, 10468, 11705, 12804, 14704, - 1844, 3180, 4380, 5754, 8181, 9923, 11738, 12995, 14138, 15232, - 2157, 3736, 5059, 5932, 7192, 8916, 11216, 12783, 13945, 15189, - 1782, 2860, 4362, 7179, 9083, 10438, 11580, 12929, 14789, 15500, - 1651, 3273, 4587, 5886, 7069, 8346, 9787, 11277, 13152, 14811, - 1549, 3138, 5049, 6704, 7803, 9102, 10748, 12577, 13813, 15215, - 1674, 3187, 4709, 6204, 7622, 9024, 10541, 12135, 13576, 15063, - 1888, 3562, 5468, 7111, 8694, 9948, 11111, 12286, 14070, 15300, - 1905, 3158, 5368, 6372, 7554, 8719, 10568, 12430, 13449, 14427, - 1953, 3411, 4718, 6545, 8090, 9298, 11232, 12723, 13668, 15077, - 1459, 3444, 5688, 6814, 7843, 8977, 10119, 12107, 14316, 15368, - 2450, 4363, 5827, 7349, 8683, 10032, 11143, 12131, 13519, 15058, - 2482, 3664, 4763, 5944, 7191, 8390, 10105, 12234, 13702, 15188, - 1838, 3465, 5255, 6751, 8016, 9254, 10946, 12321, 13790, 15337, - 2497, 3548, 4702, 5987, 7645, 8883, 10740, 12247, 14393, 15540, - 1717, 3679, 5335, 6587, 8564, 9808, 10735, 12675, 14672, 15558, - 2454, 3997, 5364, 6810, 8026, 8913, 9715, 11315, 14258, 15605, - 1906, 3443, 4901, 6363, 8186, 9716, 11074, 13186, 14701, 15474, - 1992, 3246, 5488, 6514, 7455, 8324, 10807, 13238, 14763, 15579, - 1721, 3438, 5244, 7173, 9106, 10873, 12178, 13181, 14060, 15415, - 2191, 3555, 4802, 6108, 7015, 7850, 8947, 11115, 14483, 15593, - 1925, 3232, 4601, 6574, 7791, 8989, 11038, 12282, 13630, 15136, - 1816, 3167, 4292, 5730, 7588, 9096, 10743, 12341, 13760, 15252, - 2069, 3850, 5424, 6815, 8274, 9569, 10910, 12283, 13835, 15185, - 2419, 3773, 5288, 6591, 7672, 8909, 9832, 10975, 13163, 14998, - 1215, 2710, 4939, 6437, 8745, 9918, 11200, 12553, 14234, 15384, - 1867, 3527, 5134, 6496, 7656, 8923, 10602, 12568, 13896, 15276, - 2259, 4214, 5751, 7270, 8590, 10120, 11611, 12822, 14130, 15258, - 1911, 3261, 4446, 5685, 6897, 8494, 10128, 11970, 13707, 15106, - 1762, 3549, 4874, 6153, 8146, 9634, 10690, 11886, 13713, 15057, - 2371, 3716, 4778, 6111, 7097, 8063, 10544, 12615, 14716, 15724, - 2254, 3759, 5627, 6870, 7896, 9379, 11627, 12889, 13795, 15272, - 2516, 4000, 5378, 6444, 7496, 8634, 9767, 12110, 13503, 14640, - 2385, 3201, 4283, 6677, 8216, 9689, 11654, 12319, 14142, 15367, - 2775, 4055, 5455, 6553, 7821, 8901, 10890, 12775, 13696, 14884, - 1568, 3940, 5341, 6824, 9355, 10305, 11405, 12879, 14291, 15334, - 2436, 3807, 5183, 6189, 7099, 8116, 9655, 11275, 13641, 15137, - 1755, 3340, 4871, 6382, 7790, 9316, 10921, 12432, 13903, 15217, - 1932, 3246, 4603, 6454, 7590, 8678, 10609, 12641, 13938, 15245, - 1417, 4366, 6289, 7362, 8846, 10151, 11160, 12134, 13593, 15216, - 1820, 3378, 4782, 6421, 7788, 9056, 10070, 11271, 13614, 15297, - 1855, 3399, 4933, 6526, 8097, 9655, 11043, 12475, 14301, 15370, - 1901, 3653, 6053, 7290, 8154, 8986, 10262, 12993, 14405, 15387, - 1958, 4295, 5824, 8196, 9580, 10318, 11267, 12551, 13716, 15374, - 2082, 4060, 5500, 6423, 7298, 8128, 9713, 12497, 14442, 15562, - 1878, 3425, 4781, 7062, 8455, 9625, 10810, 12311, 13948, 15201, - 2035, 3727, 4804, 6256, 7248, 9235, 11563, 13120, 14882, 15662, - 2143, 3982, 6527, 7709, 8742, 9804, 11240, 12658, 14397, 15409, - 2593, 4431, 5861, 7222, 8381, 9351, 10400, 11837, 13286, 15326, - 1840, 3798, 5465, 6800, 7919, 9752, 12004, 13265, 14424, 15420, - 2157, 4145, 5394, 6454, 7240, 8776, 11093, 12831, 14856, 15708, - 1467, 3782, 5811, 8123, 9314, 10456, 11641, 13211, 14562, 15331, -}; - - -const Word16 wac_swb_h[LPC_SHB_ORDER] = -{ - 32758, - 32731, - 32686, - 32622, - 32541, - 32442, - 32325, - 32191, - 32039, - 31870 -}; - -const Word16 wac_swb_l[LPC_SHB_ORDER] = -{ - 29673, - 20874, - 7850, - 25873, - 12831, - 5927, - 10541, - 239, - 15037, - 30328 -}; - - - - -const Word16 lsf_q_diff_cb_8b_rf[256*16] = /* Q6 */ -{ - -3145, 863, -1389, 4087, 1110, 3193, 290, -3160, 824, 212, -2936, -5827, -10181, -15650, -13373, -3849, - -4602, -3228, -8398, -1649, -5788, -8971, -2025, -2971, -1476, -2748, -2458, 966, -4, -1802, -1360, 654, - -8629, -7702, 6280, 3296, -1205, 365, -5964, 3125, 2443, 1442, 1149, -3835, -9867, -4238, -1977, -1955, - -2629, -759, -2056, -2297, -1839, 1678, -2412, -7539, -13208, -9624, -1688, -2171, 943, -454, 536, 2644, - -2840, -1391, -10500, 2516, 907, 146, -2762, -6750, 2949, -2282, -4614, -5663, -7773, -5510, -5947, -3727, - -4006, -939, -2500, -771, -3414, -4521, -6417, -4064, 3698, 3969, 4300, 4177, -3195, -10419, -13072, -6695, - -4284, -1172, -4415, -1601, -6029, 66, -4338, -2300, -3402, -5614, -7181, -7288, 7154, 6538, 64, -3263, - -6470, -4503, -9698, -5885, 235, 5049, 2698, -3656, -3600, -6261, -4270, 766, 1037, -1511, -1274, 1800, - 669, 2937, -3464, -1034, -4098, -11296, -382, -4610, -9613, -2081, 3947, 2832, 2962, -332, -9039, -10702, - -11109, -5950, -7200, -6525, -4260, -5060, -8936, -91, -672, 4557, 3192, -147, -2247, 1566, -734, -3007, - -2411, 1587, -2575, 2172, -3270, 10648, 7093, 1517, 1512, -392, 49, -9117, -16895, -908, -8443, -9923, - -1934, -603, -6588, 5335, -1565, -11521, 5944, -5092, -615, -2221, -7703, -1903, -5195, 2323, 3958, 3050, - -7094, 5361, -7885, -3299, -3282, -3125, -1888, -406, 1522, -23, -1506, -6075, -8517, -7605, -3450, -3362, - -3573, -2421, 1385, -181, -11027, 4778, -4014, -4956, 7316, 3138, 2351, 3406, -1998, -968, -2375, -3262, - -141, 6652, 11944, -4131, -2073, -2592, -1562, 1521, -1804, -2585, -2685, -5798, -10850, -11629, -4300, -4287, - -1569, 2229, 2330, 3147, -1026, -7010, 265, -1320, -3648, 1942, -5375, 73, 10348, 3913, -5535, -5938, - -5642, -3433, -8423, 1178, -540, -4790, -1976, 4686, 1701, -1323, -2009, -5997, -5693, -3852, -7604, -5361, - -1784, -325, -8561, -17592, 1663, 1377, 2347, -245, -2426, 141, -137, 985, -4926, -7898, -3559, 895, - -2548, -1563, -5007, 7311, 4409, 3177, 3920, 1546, -725, -5252, -9754, -9267, -5701, -6900, -961, 1772, - -1676, 889, -4798, 8060, 3460, -1911, 415, -4044, -6146, -12074, -10588, 13056, 2765, 1396, -4737, -4905, - 943, 3342, -8515, 4676, -774, -3963, -5503, -1625, 3909, -3614, 12347, 2835, -9710, 5877, 297, -918, - -5317, -2799, -3708, -4084, -8175, -6155, 1752, 6801, 7493, 6271, 4083, 3132, -809, -4200, -5389, -5982, - -5060, -5285, -1533, -2751, 2259, -3893, -3473, -108, -4711, -2627, -2069, -2320, -172, 1547, 770, 309, - -4485, -2618, -7238, 1767, -2965, 6693, 5256, 18, -1789, -5076, 7167, 3204, -1242, 1628, 4519, 1796, - -114, 1225, -3083, 321, -4002, 4834, -3014, -741, -4189, -5946, 6871, -2068, -13016, -9772, -3235, 2044, - 559, 10477, -9704, -7733, -8989, -10787, -10342, -8585, -2844, 1474, 5638, 9798, 10986, 9105, 4619, 2186, - 1576, 9039, 4354, 2073, 1861, -1492, -715, 1840, -6736, -10798, 994, -2921, -6369, 779, 2668, -443, - -2067, -1020, 1, 14571, 2253, -2163, 5255, 973, -1722, 4173, 102, -3633, -1430, -1720, 1243, 1749, - -6589, -1601, -9469, -5581, 3018, 1186, -11, 1252, 5708, 3338, 187, -3950, -6035, -3294, -106, -1130, - -2490, 445, -2543, -3283, -3432, -6963, 9950, 4072, 2294, 4517, 2736, 8173, 4270, -8347, -9374, 4776, - -66, 3476, 537, 2659, -677, 1552, 1974, -1703, -2139, -634, -1988, 694, 1921, -12938, -16525, 5848, - -9849, 7389, 4653, -1158, 1340, -2250, -2460, -2201, -3122, -90, 3974, 5105, 9127, 8701, 6184, 3770, - -5086, -3159, -3197, -9944, -7474, 961, 1158, -3536, 1050, 5572, -1480, -11120, -9276, -1841, -2086, -24, - -1019, -346, -6765, -8343, -6302, -3019, -5606, 2728, -3994, -6909, 10146, 6321, -230, -393, -846, -1536, - -1598, 3610, 3330, -233, -1215, -1953, -1330, 19, -4839, -10681, -11699, -1104, 1146, -6143, -6849, 422, - 892, 7937, -5005, -5547, 1756, -4020, -3420, -6811, -6304, -7812, -6019, 5109, 5503, 5568, 4600, 6472, - -3296, -2230, -6010, 3497, 5502, -2291, -2342, -6544, -12576, 2192, -1004, -5205, -500, -6764, -6200, 1816, - 5114, 4922, 6498, 6613, 4909, 2318, -5626, -11915, 3072, 11570, 1766, 4361, 552, -8139, -14006, -17228, - -3321, -1514, -473, 3295, -1028, -4536, -12374, 12452, 7396, -2269, -5052, 554, 1053, -4370, -5859, 97, - -2532, 2546, -4920, -13800, 8116, 2425, 1695, -2088, -5105, -346, -2869, -2457, 9336, 13166, 6150, 5166, - -2329, 72, 11513, -3075, -7745, -5492, -8015, -5108, -16, 3261, 876, -357, -3241, -2956, -4265, -2320, - -7869, -6495, -16668, -1339, -3678, 975, -2740, -2776, 3755, 141, -190, 1026, 5972, 3232, -924, -3212, - -1077, 568, -5606, 1478, -243, 2479, 10198, 3667, 682, -2873, -9164, -9042, 2186, 4347, -750, 5303, - 556, 5098, -6825, -2564, -3946, -5752, 1977, -6171, -5627, 4580, -835, -6362, 10132, 9511, 6475, 2861, - 3320, 11074, -483, 2698, -20, -4084, -4213, -3931, -231, -17, -1826, -2737, -5920, -1539, -1897, -3347, - -1346, 2075, -1230, -5248, 10906, 9461, 5046, 3485, -267, -948, 4273, 1889, 81, -488, -4763, -5532, - -1237, 6446, 3974, 5166, -723, -10033, 8338, 4102, 683, 1474, 624, -5287, -8628, -7519, -6290, 1767, - 207, 2676, 870, 13754, 7087, 2357, -922, -1734, -4651, 352, 14028, 10050, 8916, 2725, -5722, -9415, - 364, 3660, -813, 4370, -2151, -2115, 5570, -2545, -8167, -1978, -8301, -10715, 959, -5127, -11250, -7721, - -1668, -1437, -5508, -11155, -15130, 6829, 6070, -1555, -3048, -314, -528, 1714, 1474, -42, -541, 3361, - -15356, -12047, -4659, -1598, 4105, 3069, 2375, 3647, 1217, 140, -2518, -4195, -3080, 2155, 66, -570, - 84, 1523, -742, 13326, 5544, -2653, -5484, -3816, -9239, -10794, 6967, 2095, -4231, -2102, 4368, 8737, - 2959, 3968, -2430, 4601, 317, 5804, -3547, -11099, 5849, 273, -5513, 767, -9421, -11095, 3029, 8472, - -518, 2355, 2733, 53, -1439, -2709, -394, 5355, -2408, -3122, 8729, 5660, 7771, 4999, -7588, -15134, - -2240, 2281, 6677, -5155, 5663, 266, -4355, -7052, -3825, -2235, -2745, -3212, -2018, 1828, 1971, 2086, - -1241, 699, -2126, 3835, 1147, 4456, -3810, -23, 1284, -4878, 3807, 14029, 2820, -6773, 9556, 6600, - -1716, 315, -3259, -3282, -2859, -2219, 3508, -3452, -7850, 623, -5558, -2168, 1842, -8228, -885, 15388, - -8177, -7705, -14377, -6808, -7099, -7676, -4141, -5548, 3677, 5846, 6160, 10031, 11318, 8141, 3326, 904, - -3072, 1139, 1875, 4811, 3767, 7294, 4507, 1476, -1622, -6385, 384, 3318, -3867, -10447, -6387, -4252, - -19, 1102, -6317, 3433, -1856, -5732, 7225, -2107, -6977, 9620, 7964, 3013, 7152, 4986, -2184, 2136, - -524, 1479, -923, 3729, -259, 227, 6477, 2660, 4208, 1017, -423, -6090, -13677, 5309, 702, 2721, - -822, 2175, 1717, 3580, 1133, 3835, 980, 13265, 6367, 2741, 7462, 6211, -2347, -7635, 4781, 4132, - -8168, 13481, 5777, -963, 643, -2853, -2086, -1593, -2092, 2348, 3867, 413, 461, 1644, -259, -1656, - -846, 1615, -2805, 935, 3206, 1907, 7862, 3901, -975, 4507, 3151, 1433, 15449, 4412, -1221, 1001, - -3952, 1411, -2148, -1025, -2553, -4164, -4725, -3465, -2654, -3828, -6151, -7679, -5881, -2007, -581, -2499, - -1744, 4546, -8725, -6274, -1364, -1087, -2198, -4504, -3542, -1966, -516, -802, 448, -162, -1277, -2081, - -12133, -10923, 10206, 4436, 611, -2300, -4926, -4708, -5138, -3373, 2358, 295, -370, 4406, 2947, 351, - 1477, 3584, 3776, 4714, -1508, 2029, 426, -5245, -2805, -5852, -8752, 199, -3945, 10358, 10127, 4852, - -1894, 528, -776, 2698, -1298, -7579, -12457, -12545, 2483, 2421, -140, 723, -395, -292, -4196, -1766, - -3071, 1449, -3716, 3712, -3017, 543, -391, -1984, 3301, 375, 1107, -2635, 4730, 870, -19666, -12653, - -2823, 3165, 5399, -10321, -6087, -2824, -329, -1699, -268, -1995, -2254, 2744, 319, 51, 2834, 452, - -2837, -240, -1298, 2244, 1977, 3061, 3676, -1207, -3774, -2607, -3405, 9701, 12102, -3052, -10263, 1164, - -1548, -515, -3862, 1117, 3329, 4105, -804, -4141, -9321, -3136, 1792, 3484, 2025, -6747, -11991, -10905, - -3361, -2922, -3472, 1165, -3055, -1620, -4751, -8940, -477, 1932, 1054, 4687, 5735, 5566, 2447, -778, - 1791, 3768, 602, -2421, -6876, 9505, 7350, 2428, -3175, -6252, -707, -3720, -7723, -42, 4292, -1141, - -2469, 269, -1028, 1057, -890, 383, -128, 821, -2854, -5548, -2437, -3349, 3935, 1474, 14267, 13393, - -3416, 14072, 1196, -3166, -4252, -711, 521, 2462, 5346, 1483, -4287, -7676, -5805, -321, 867, 475, - -1674, 1391, 539, -471, -5201, -25, 6911, -2142, 10454, 10963, 1353, -2831, -3219, -131, -3005, -4468, - 3476, 4986, 6318, -2959, -9204, -87, 3906, -833, -247, 5687, 451, 716, -2970, -5788, -6743, -9436, - 4831, 6767, 3852, 2164, -1362, -1404, -3260, -4807, 2809, -2699, -4693, 21984, 10803, 4063, 2353, 6177, - -2813, -890, -5363, -165, -5755, -20361, 3639, 4639, -2073, 1798, -1097, -6169, 30, -1827, -4590, -2586, - -5855, -6418, -10115, -6038, 2674, 3620, 1206, 1379, -520, 5333, 5334, 3618, 439, -1048, 439, 777, - -7871, 2657, -3649, 7671, 10875, 5285, 423, 1869, -2283, -6081, -2750, -3935, -1815, 2851, 754, -2545, - -2253, -245, 87, 3432, 4323, 803, -3981, -8416, -12174, 6263, 9281, 7472, 2558, 327, -3198, -1436, - -1398, -211, -6595, 4670, 63, 2041, -4372, 967, 2444, -9123, -11355, 1727, -4221, -3144, 6411, 4338, - -4409, -3256, -6504, 6064, 4055, -2268, 5638, 5466, 82, -516, 6974, 5206, 1235, -364, -4919, -6016, - 2, 7, -5, 5, 1, 2, -8, 4, 4, 2, 4, 5, 0, -1, -3, 1, - -1139, 1101, -1501, -3122, 2059, 9130, 5593, -2976, -5845, -8198, 10800, 771, -4815, 20594, 5385, 9434, - -497, 877, -5365, -1190, -2940, -6216, 4700, 872, -2276, 9901, 5530, 417, -4381, -9743, -1935, -1025, - -3555, -643, -5254, -6674, -6586, -4879, -3791, -2733, 1046, 2275, 3157, 3643, 8384, 10607, 11929, 9237, - 1573, 3323, 130, 12128, 9521, 6522, 4035, -1444, -7190, 565, 2160, -2808, -3716, -9398, -1115, 4631, - -1938, -2034, -5142, 6407, 5972, 302, -3078, -7362, -12229, 6591, 5640, 1240, 2727, 3243, 9738, 7334, - -8793, 935, -4176, 103, 2398, 1724, 1579, 7649, 5685, 2791, 1754, -453, -5030, -4870, -3871, -3139, - -243, 3111, -2068, 3022, -4587, -11340, 14571, 7771, 3558, 5750, 1203, 4665, -1981, -109, 4442, 1369, - -2041, 3713, 1013, 1345, 4716, 129, 3062, 1444, -3639, -6184, 7457, 7819, 958, -8391, -8799, 9312, - 235, 3895, 12172, 2716, -1347, -1094, -4869, -880, 7519, 9011, 9914, 5683, 5909, 7805, 4428, 2129, - -1538, -36, -678, 1486, -649, 1517, -5121, 8530, 5048, -1844, -4781, -9145, -11353, -8076, -4133, -307, - -2707, 80, -5905, -4315, -4389, -6758, -6105, -9003, -10744, -1701, 3765, 6091, 10523, 7504, 4350, 4312, - 786, 3663, 9280, 6578, 391, 1514, -7019, 5089, 3483, -6871, -8172, -180, -7469, 1419, -121, 838, - 2692, 6995, 1431, -1074, 1394, -268, -1170, -3367, -7586, -5698, 7587, 7378, 5733, 8353, 10152, 10834, - -8158, -6271, -9914, 9985, 5364, -2601, -1959, -6260, -4097, 3235, 2097, -196, 2968, 3371, 2095, -1207, - -2269, 648, -1910, 7766, 5356, 3667, 981, 2825, 4288, 6668, 696, -661, 4042, -5356, -12858, -3646, - -4703, -3239, 10100, -2312, -256, -2120, -2612, 4835, -1675, 1068, 5746, -140, -869, 3620, 3505, 1703, - -3250, -2423, -1423, -674, -4843, 10905, 4109, 635, -1606, -6241, -2449, 3295, 6275, 14389, 8002, 4352, - -842, 3170, 1430, 1513, -4583, -12820, 1470, -4220, -8952, 6987, 4718, 532, -2136, -3700, -1727, 4512, - -3663, -2257, -8998, 5471, 843, -2858, -4142, 5134, 7250, 525, 3002, 118, 423, 6929, 5389, -1003, - -3457, -2564, 4399, 5758, -1462, 9992, 2582, 885, 6350, -670, -4446, -5882, -1814, -1178, -3073, 1157, - 2529, 7505, 5440, 202, -5746, -976, 8235, 1049, -181, -142, -6919, -6675, 18283, 16554, 8385, 3001, - 2266, 12753, -3253, -3832, -7200, -5627, -4778, -925, 239, 539, 2225, 324, 3182, 1914, -309, -507, - 5074, 4381, 9167, 1915, -3908, 1754, -5997, 2537, 17796, 13293, 7314, 12286, 1815, -4329, -8064, -20774, - -2484, 4942, 14515, 5406, -2595, -1380, 8417, 5956, 1651, 1559, -1389, 24, -6421, -4047, 2557, -1331, - -3164, 848, 15096, 9663, 6043, 3180, 595, 2733, 830, 1861, 9051, 8435, 8904, 6571, 2208, -762, - -135, 870, -2484, -3227, -9497, -586, 14177, 5880, -3708, 505, -1483, -415, 2507, -1973, -13853, -8468, - -3854, -2420, -9258, -4766, -3435, -2360, 10467, 7572, 598, -4099, 3457, 402, -195, 4193, 2023, 1851, - -4359, -3760, -1315, -585, 11411, 2958, 5446, 1608, 228, 4691, 1446, -1971, -3898, -3822, -1651, -1697, - 5112, 1738, -12375, 11069, 8416, -139, -721, 740, -8678, -7527, 10378, 4791, 5388, 2724, 4652, 1931, - -1419, 520, -6325, 10393, 8379, 2544, -2104, -11110, 7461, 2884, -1766, 548, -217, -2709, -1287, -2598, - 1996, 4969, 3862, 5813, -629, -7138, 7107, 9009, 5157, 1564, 5244, 1326, 78, 263, -4389, -5858, - -5423, -34, 1648, 2316, -3981, -5525, -1762, -996, 2075, 878, 718, 1458, 613, 3914, 3912, 2074, - -1176, 643, -3222, -444, 779, 9634, 14238, 11755, 3727, 1970, -1421, 3653, 1795, -2315, 10947, 8623, - 19, 6095, 3277, 2648, 2148, 509, 3577, 978, 1862, 5842, 1302, -3853, -10993, -12406, 858, 7763, - -4944, -1993, -5563, 833, -1365, -2240, -25, 2546, 10150, 10369, 10670, 10551, 9322, 5582, 881, -1029, - -763, 4474, 9314, 8818, 2703, 4844, 7776, 1684, 1, -3980, -9739, 5565, 2667, 1185, 2203, 1611, - -635, 724, -4112, 8414, 3049, 1437, 2314, -2611, -5835, 5541, -3027, 1017, 14246, 10165, 9910, 14393, - 2201, 3204, -295, 2519, -855, 5303, -2184, -12725, 10839, 1337, 154, -5290, -7908, 9490, 4292, 5533, - 544, 3574, 602, -783, -3121, 21721, 8166, -1137, 4729, -2399, 2504, 3721, -2704, -10309, 4957, 8028, - 2782, 11109, 5440, 2691, -3942, 3286, 2848, -532, -186, -2661, 7318, 6015, -1200, 2174, 5498, -379, - 4440, 6050, 3576, -819, -3697, 13144, 9664, -2178, 2966, 3302, -623, 10572, 15713, 9000, 2137, -5160, - -1593, 613, 3985, -7128, -5989, 2429, 721, -5488, -11848, 981, -3054, -4499, -4102, -7743, -7416, -340, - -2759, -2449, -4426, -6796, -13804, -7472, -1409, -1103, 181, 3071, 434, -741, 1045, 1976, 1407, 1365, - -2578, -1275, 5323, 9313, 4798, -1130, -6220, -2101, -3402, -868, -1959, -4365, -4536, -1626, -3701, -5011, - -3479, -3407, -9706, 4812, -812, -4014, 2558, -5416, -10543, -5186, -3840, 1189, 3804, 5839, 4744, 1003, - -3585, -2339, -4745, 3869, -2763, 1306, -6059, -8604, -1377, -5116, -730, -1693, -3321, 888, -685, 876, - -3492, 910, -7012, -2555, -5147, -1372, -1910, -8518, 2661, 7652, 6967, 7296, 4514, -4741, -9827, 873, - -1258, 4649, 3654, 653, -5264, -5509, -4222, 1703, 3992, -5102, -4342, -6447, 6603, 2642, -923, 6242, - -992, 647, 1228, -3124, -3463, 15067, 838, -6186, -3433, 872, 97, 2876, 3686, -2643, -6780, 356, - -1727, 2555, 2552, -1938, -8798, -773, -757, -3588, -7005, -6121, 4601, 235, -4446, 2984, 1353, -776, - -15055, -12154, -6273, 84, 390, -3286, -4758, -3713, -2185, -1512, 1403, 3479, 7578, 6327, 5045, 3075, - 2469, 8960, 6679, 3813, 1059, 9183, 2971, 4300, -1040, -927, -2376, -6240, -5131, -6030, -7385, -7560, - 933, 4512, -899, -1226, -7230, -10649, 11249, 4655, -7924, -5423, -5107, 993, 588, 2896, 4305, 1369, - -1938, 11282, -2696, -7285, 1163, -6289, -344, -2329, 3632, 2191, -1017, -1404, -2305, -6223, -2822, -1369, - -3688, -918, -3118, 256, -5446, 8638, 6195, 2855, 7432, 6937, 8638, 4020, -3296, -4260, 21, -3914, - 3006, 5845, 16377, 17059, 3579, 103, 204, -563, 1735, 6204, -405, -2618, -7929, -14028, -9415, -5277, - 303, 934, -305, 3211, -2970, 2963, 10231, 2833, 1656, 1162, -4439, 6346, 9314, 7062, -5015, -15980, - -320, 499, -14803, 4610, 2112, -4049, 7242, -245, -3115, 1323, -1276, -4286, -1951, 100, -1389, -1612, - -4391, -2691, -5202, -11000, 373, -2423, 4221, 4146, 1045, 503, -4063, -2244, 2311, 1646, -1779, -3188, - -3374, 346, -3243, -3662, 5971, 5519, 3022, 516, -4538, -6550, -5227, -6165, -4919, -1105, 30, 721, - 2935, 3922, -1041, 4217, 2528, 1985, 661, -824, -10133, -13715, 8714, 2218, 3769, 3384, 1193, -6246, - -5357, -2959, -8106, 5394, 1542, -4964, -7749, -4183, 877, 1146, 8307, 2891, -4905, -5775, 1888, 1442, - -2472, -850, 1278, 1397, -4545, -3625, -11722, 9811, 7790, 7832, 12234, 6079, -2436, -890, -1820, -234, - -3905, -1081, -7818, 2577, -299, 5742, 4982, -1421, 3506, -604, -4944, 2130, 544, 1545, -2399, -3202, - -895, -203, 783, -203, -2734, 10200, 7718, 3943, -6098, 9859, 9374, 6777, 2263, -2089, 866, 3381, - -3828, 1991, -2866, -1612, 747, -3896, 6041, 2875, -5838, -6829, -2319, -1146, -8845, -10612, 3630, 2942, - -509, 5457, 1119, -3222, -3623, -6421, -9746, -8661, 5658, 8283, 8062, 6310, 1787, 454, 1766, 2750, - -1632, 7787, 5349, 243, -1526, 3143, 5218, 10290, 1446, -6324, -3035, -1055, 2974, -7871, 39, 3664, - -769, -9, -8896, 9699, 4546, -1295, 6107, -4534, 3367, 1450, -3607, 8816, 3219, -5601, 1298, 12366, - -7130, -4420, -6848, 3453, 3599, 4371, 609, -6059, 8057, 9067, 2408, -3523, -6908, -6822, -6636, -2017, - -477, 5145, -1462, -475, -2003, -3769, 7781, 4563, 4437, 2134, -2726, 15777, 2839, -1929, 2913, 2174, - 841, 2396, 754, 14163, 4130, -1807, -177, -3884, -6782, 9287, 1864, -599, 5913, -2587, -10749, 5856, - 1304, 7980, -2237, -2092, -4384, -828, 552, -6108, 2193, 10107, 6057, 9885, 13003, 8977, 4006, -926, - -1523, 1282, -1805, -2709, -6024, -7618, -10251, 832, -689, -1488, 1528, -1635, -4512, -3974, 3366, 5884, - -2891, -646, -4227, -16787, 4586, 2689, -48, 1956, -5398, -5693, 4030, 1138, 2292, 2634, 6453, 3271, - -3526, 9059, 2896, 8101, 3313, -270, -1336, -3002, 826, -1572, -3793, -2235, -1597, 272, 910, -778, - -1195, 3634, 1576, 2036, -3675, -10512, -6414, -3268, -9714, -6636, 3287, -947, 6643, 7755, 4317, 2928, - -592, -46, -6118, -3775, 11750, 5301, -2878, -7240, -4674, 1543, -626, -1300, -608, -1661, -4053, -3154, - -2514, -545, 771, 7292, 3641, 749, -1664, -1652, 2686, 8715, 10176, 4547, -6065, -7417, -6454, -4928, - -576, 940, 681, 2977, -2947, -1968, -6468, 10093, 7720, -2235, -3869, -8057, -4152, 7399, 8617, 5658, - -1043, 1637, -3699, -5968, 13092, 1526, 1185, -3128, -2234, 3343, 5773, 9935, 7870, 6240, 3284, 3932, - 377, 5872, 3528, 3824, -852, -1575, -3799, -8401, -5628, -3612, -2451, 1396, 1471, -1669, -579, -384, - -6978, -4522, -6731, -1881, 1485, -73, -38, -3990, 11379, 4104, 1154, 5492, 3709, -645, -641, -750, - -97, 2556, 1619, 3351, 1996, 10845, 8411, 2751, 3099, -165, -6582, -11822, 8128, 7722, 4495, 3322, - 950, 2744, -2039, -3959, -6098, -2113, 4512, -1699, -758, 3243, -4760, 7788, 11837, 5336, 7626, 5509, - -4876, 13906, -3059, 1351, 4037, 2283, 614, -5014, 2149, 613, 744, -4239, -5981, -4296, -1799, -3121, - -2111, 3530, -1221, 1654, 9442, 10361, 6422, 7826, 7510, 7790, 3836, -323, -761, 1652, 330, -386, - -3239, 3070, 7009, -1209, 6710, 213, 5225, 3105, 1173, 842, -1774, -5027, -3901, -1359, -2786, -3513, - 1481, 1904, 7402, 23443, 5946, -3615, -1528, -4317, -2629, 11277, 7171, 5620, 7938, 4715, 3575, -3794, - 2315, 5200, 63, 4010, -400, -2074, 6624, -516, -731, -2133, -10088, 6969, -3380, -7450, -7347, -6915, - -3407, -3447, -1422, -4020, -11809, 3562, 3865, 570, 7656, 6367, 5964, 802, -2306, 5862, 7700, 6476, - -17049, -2577, 3748, -1004, 990, 2569, 4487, 2137, -3540, -3508, 608, -2102, 90, 4634, 3115, 1273, - -1960, -1414, 1516, 9460, 6833, 2088, -3598, -3590, -2554, -1783, 2680, 2127, 939, 8562, 4170, 1914, - 3335, 6241, -2988, 1816, 3233, -951, 587, -5590, -3415, -926, -7987, 8897, 3700, -12712, 5722, 4683, - -756, 1823, 2804, 3392, -2019, 801, -2923, 43, 5720, 2302, 3604, 14791, 4960, -425, -7298, -6606, - 205, 5909, 8599, 4641, -4600, -1580, -4536, -5178, 2346, 6910, 3641, -2630, -6079, 351, 5478, 5524, - 151, 1252, -2569, 6834, 5377, 4284, 450, -1607, 7257, 4429, -2568, 9851, 9183, 2197, 20053, 9155, - -1462, 924, -3196, -3257, -8953, 6147, 6251, -3186, 3285, 3198, 2326, 1225, -8446, -11295, 5393, 10785, - -2381, -2014, -9329, 4719, -880, -2308, -4714, 4429, 3675, -1874, 3253, 9686, 12557, 9338, 4719, 3836, - -3103, 7031, 11258, 6883, 11690, 8131, 3644, -307, -2590, -274, 1004, -1314, -166, 3063, 695, -1815, - -2455, 811, -1161, 2731, 5931, 2352, 3361, -363, -7371, 2805, 4053, 3586, 7364, 242, -1692, 17531, - -4497, -535, 286, 214, 3804, 11412, 4562, -1157, 550, 4841, 1657, -4984, -6307, 1482, 5745, 3540, - -2763, -1313, -1385, 3735, -2423, 5601, 14635, 10815, 9726, 6141, 4010, 3556, -104, -3353, -7143, 7077, - -245, 8209, 15457, 5234, 1860, -2195, -4620, -4895, -4263, -759, 2016, 2664, 3153, 2966, 1601, 30, - -4764, -1351, 3227, 2660, 1556, 198, 5379, 11277, 8580, 6978, 2506, 3310, 13165, 9623, 7120, 1665, - -59, 558, 3194, 1299, -2918, -2455, 3754, -3394, -3634, -2782, -7987, -7903, -7058, -2214, -1060, 2183, - -1954, -186, -11418, -2859, -1110, -2027, -932, -2040, 1282, 174, -161, -2628, -3341, 2675, 4169, 2475, - -5934, -5196, 10580, 9382, 1417, -1362, -2572, -4391, 7418, 4314, 148, 31, -82, 461, -2595, -570, - -3639, -2081, -1014, 4355, 5943, 6217, 2491, -4106, -6520, -4050, -5030, -2053, 6821, 6135, 2456, 1015, - -3447, -1303, -5380, -6759, -3272, -129, -4989, -11231, 5106, 1264, -3433, -3327, -3139, -1282, 1031, 1558, - 4180, 1592, -3435, 2252, -4803, -6443, 8937, 1696, -5599, 9240, 5481, -328, 3197, -4392, -12452, -16482, - -4613, 5693, 11596, -9035, 1399, 1388, 5182, 4750, 958, 310, -866, 829, 5122, 1203, -115, -759, - -3551, -1843, -3272, -1753, -195, 17324, 8182, -502, -2987, -146, -2640, 6865, 6979, -3675, -6047, 12865, - 3739, 8307, 5634, -2783, 96, 1167, -274, -636, -5808, -8880, 835, 6363, 5092, -700, -8229, -7634, - -6799, -5871, 4391, 1265, -1493, 440, -7322, 2387, 1763, -1406, 4030, 8075, 8810, 5655, 1375, 2309, - 3191, 6527, 2671, -128, -5345, 14221, 13006, 1792, -548, -2974, -7549, -3471, 1835, -1490, -3556, -4240, - -3368, -1748, -3945, 8349, 2444, -5349, 5825, 4222, -1891, -3570, -10832, 8764, 2791, 5495, 9332, 5366, - 1020, 5766, -8313, 522, -568, -20, -2169, 3981, 6641, 4235, 1781, -4362, -7143, -3864, -2205, -3217, - -3300, -1346, -1200, 5950, -1315, -285, 2642, -180, 12986, 11560, 5996, 6755, -2578, -1417, 1848, 5560, - 10662, 13080, 11225, 419, -4335, -128, 6716, 1638, -4903, 154, -2404, -4228, 5262, -364, -5170, -12310, - 360, 1588, 2173, 8939, 4304, 7241, 367, -2361, 6569, 837, -4801, 8650, 7208, 5996, 3566, 1112, - -5017, 4300, 2649, 3064, -6110, -14292, 2204, 13008, 5245, 1594, -6536, -11045, 5146, -211, -4067, -11435, - -530, 1840, 187, -12175, 1984, -1576, 3659, 4293, -1971, 8025, 8287, 4420, 3935, 358, -1691, -2707, - -3429, 252, 1235, 3895, 13024, 5900, 317, 1720, 3724, 1510, -3576, -6091, -8218, -3620, -844, -406, - 2105, 7096, 3064, 3952, 2071, -2774, 8459, 1501, -10913, 1387, -405, 12863, 2328, 4475, 3498, -1584, - -3085, -920, -7032, 8494, 2146, 1346, 1867, -404, 1886, -1042, -378, -2121, -10433, -7336, 15525, 9808, - -15685, -7623, 1925, 2963, 4001, -105, 3843, 5498, 4039, 6151, 6044, 3867, 1730, 2971, 1484, -319, - 3080, 9412, -1223, -3973, 4734, 2248, 3127, 1119, -1738, -1669, -1477, -1472, 1412, 1213, 773, 1674, - -730, 2282, 495, 1849, 753, 4313, 2052, 11060, 2638, -4153, 12967, 4232, 1600, 8305, 6247, 4101, - 1078, -516, -6160, -2738, -3949, 549, 2665, 313, -11805, 5780, 13753, 4964, -3343, -3825, 7392, 657, - -3356, -672, 2091, 1930, -1942, -6931, -7983, -7306, 1452, 3417, 9758, 12537, 14305, 11570, 5653, 1593, - 2820, 8229, 5573, 6212, 5169, 4568, 4877, 1219, -5520, -3569, -4997, 3799, -1152, -6233, 13054, 8210, - -1905, -1112, -1728, 19102, 8663, -331, 3226, 1066, -1807, 8189, 5678, 1987, 4661, 3278, 7947, 11458, - -4574, -517, -5124, 4711, -740, 416, 4847, 4427, 11056, 3251, -1915, -3528, -2529, -2213, 1857, 1203, - 316, 3731, 4619, -1294, -3138, -336, 8691, 7311, 3124, 9892, 5880, 614, 1873, 1916, 3856, 3588, - 1323, 8284, 7332, 4197, 626, 4877, 9117, 4163, 1998, 4387, 5489, 4184, 2124, -5170, -10914, 3921, - -1504, 12727, 938, 3478, 1876, -1017, 389, 3233, 8278, 8027, 8392, 12663, 13264, 9858, 5767, 4287, - -4008, 49, -1854, -5454, -9369, 5309, -1597, 6002, 6031, -2543, -4793, -2340, -2559, 229, -983, -2068, - -3514, 815, -7510, -3824, -931, -1573, -1337, -1189, -2019, 245, 4084, 4416, 6165, 7239, 3899, 2461, - -4781, -2173, 17577, 2751, -894, 2264, 1789, -623, 992, -322, -3113, -1854, -1553, 2213, 731, 850, - 2054, 3456, 3747, 3842, 980, -940, -5065, -5905, 423, -2009, 74, 3933, 13511, 12742, 8908, 5783, - 894, 6872, -2742, 7127, 5497, -660, -2361, -3114, -5552, -884, -1825, -8536, 4278, 4047, 3263, 2117, - 46, 3829, 3392, 7000, 5004, 11640, 7090, 2661, 2072, 3834, 6408, 9453, 4328, -5807, -11811, -6081, - 1119, 3292, 8329, 5549, -1361, -4414, -15806, 7144, 6824, -4515, -1143, 4774, 1451, 5261, 4830, 5562, - -1393, 5662, 4446, 1807, 8826, 6248, 6415, 4547, -1665, 1181, 6405, 5864, 8293, 10387, 7545, 4688, - 1312, 7883, 6317, -3965, -8535, -2725, 1117, -5447, -7012, 3655, 3196, 4576, 6822, -341, -646, 6098, - -6332, -4527, -5839, 4942, 2805, 6652, 925, -1187, 3859, 4466, 5194, 4814, 7489, 8532, 2922, 2874, - -1137, 1068, 2253, 3741, -2505, 9887, 10247, 3472, 9158, 1176, -2976, 1937, -2064, 7351, 6057, 2696, - 532, 4702, 4601, 502, -1350, -5364, 9112, 2103, -4340, 18, -1329, -2532, 2939, 15707, 4071, -2154, - -628, 13794, -2239, -2982, -3391, -2332, -1483, 5699, 7418, 5487, 5469, 3426, 2471, 2248, -610, -2978, - 4520, 7035, 8360, 8190, 4367, 11231, 9045, 6518, 5468, 6414, -626, -2179, -2327, -6601, -11740, -18010, - 872, 6597, 9823, 6115, 5121, 3028, -3065, 9266, 9664, 2144, 2461, -758, -3373, -348, -421, -2786, - -2998, -2310, 5826, 14327, 10399, 10344, 5906, 4646, 4013, 7488, 6656, 3601, 212, 2499, 812, -4251, - -3455, -259, -2801, -3743, -3930, 4402, 11531, 8368, 3812, 2663, -1885, -3062, -3413, -12432, -6348, -1832, - -2574, 1227, -6578, -7396, -131, 1139, 3464, 2303, 6848, 4302, 422, 1994, 4840, 6023, 4369, 1222, - -5186, -3043, -5221, 9413, 9009, 6329, 6302, 7712, 4428, -1745, -1711, 1216, 1855, 1215, 1003, 58, - 3844, 4380, -2452, 17587, 5229, 106, 3809, 5238, 2909, -6280, 6367, 4649, 3777, 2815, 4377, 9833, - -3469, 6722, -2982, 1867, 2944, 3428, -115, -6063, 4740, 2369, 3681, 2580, 319, 76, 4169, 1079, - 5357, 7937, 8749, 6732, 3237, 475, 10599, 7708, 2300, 9384, 6872, 6516, 11437, 2109, -2788, -10922, - -2925, 1420, 3109, 500, 6953, 1289, -522, 1064, 2885, 6445, 3595, 2000, 2669, 2797, 2174, 873, - 1980, 6159, 1331, 1321, -1922, 6722, 11666, 3321, -1515, 1233, -1664, 9262, 9668, 2502, 13862, 9666, - 3582, 10575, 2715, -603, 596, -1567, 4182, 49, 2208, 1795, 10525, 9472, -2866, -8439, 7591, 11197, - -2356, 153, -10244, -4768, -2178, -2408, 1367, 708, 4615, 9681, 13007, 14875, 15382, 12708, 8355, 5074, - -358, 1803, 1987, 7888, 9168, 16089, 2288, -2716, -1669, 1078, 1165, 5324, 4412, -4354, 298, 6519, - 4826, 9355, 6507, 12087, 4177, -6, 2865, -2898, -5149, 6100, -1829, 80, 12459, 4967, 591, 7846, - -3452, 13887, -142, 4052, 5842, 3702, 4535, 2718, 4976, 3690, 1377, -72, -1938, -836, 961, -1944, - 4315, 5391, 6496, 1795, -2279, 20485, 16142, 9768, 8889, 6390, 1789, 3149, 4186, 487, -922, -2249, - -1225, 14246, 10277, 980, 2427, 180, 5713, 4730, -901, 590, 3351, 1871, 4389, 4760, 8650, 3433, - 1760, 3580, 5798, 6813, 4246, 17695, 7227, 4364, 2222, 13912, 11731, 10965, 14919, 7273, -6023, 6474, -}; - - -const Word16 win_lpc_shb_fx[(L_LOOK_12k8 + L_SUBFR + L_FRAME) * 5/8] = -{ - /*Q15 */ - 1, 4, 10, 18, 28, 40, 54, 71, 89, 110, 134, 159, 186, 216, 248, - 282, 318, 357, 397, 440, 485, 532, 581, 632, 686, 741, 799, 859, 921, - 984, 1050, 1119, 1189, 1261, 1335, 1411, 1490, 1570, 1652, 1736, 1823, - 1911, 2001, 2093, 2187, 2283, 2381, 2481, 2582, 2686, 2791, 2898, 3007, - 3118, 3230, 3345, 3461, 3579, 3698, 3819, 3942, 4067, 4193, 4321, 4451, - 4582, 4715, 4849, 4985, 5123, 5261, 5402, 5544, 5687, 5832, 5978, 6126, - 6275, 6426, 6577, 6730, 6885, 7041, 7197, 7356, 7515, 7676, 7837, 8000, - 8164, 8329, 8496, 8663, 8831, 9001, 9171, 9342, 9515, 9688, 9862, 10037, - 10213, 10390, 10567, 10745, 10924, 11104, 11285, 11466, 11648, 11830, 12013, - 12197, 12381, 12566, 12751, 12937, 13123, 13310, 13497, 13684, 13872, 14060, - 14249, 14438, 14627, 14816, 15006, 15195, 15385, 15575, 15765, 15955, 16146, - 16336, 16526, 16716, 16907, 17097, 17287, 17477, 17667, 17856, 18046, 18235, - 18424, 18612, 18801, 18989, 19176, 19364, 19551, 19737, 19923, 20109, 20294, - 20478, 20662, 20846, 21028, 21210, 21392, 21573, 21753, 21932, 22111, 22289, - 22466, 22642, 22818, 22992, 23166, 23339, 23510, 23681, 23851, 24020, 24188, - 24355, 24520, 24685, 24848, 25011, 25172, 25332, 25491, 25648, 25804, 25960, - 26113, 26266, 26417, 26567, 26715, 26862, 27007, 27152, 27294, 27435, 27575, - 27713, 27850, 27985, 28119, 28251, 28381, 28510, 28637, 28762, 28886, 29008, - 29129, 29248, 29364, 29480, 29593, 29705, 29815, 29923, 30029, 30133, 30236, - 30337, 30435, 30532, 30627, 30720, 30811, 30901, 30988, 31073, 31156, 31238, - 31317, 31394, 31469, 31543, 31614, 31683, 31750, 31815, 31878, 31938, 31997, - 32054, 32108, 32161, 32211, 32259, 32305, 32349, 32390, 32430, 32467, 32502, - 32535, 32566, 32595, 32621, 32645, 32667, 32687, 32705, 32720, 32734, 32745, - 32753, 32760, 32765, 32767 -}; - -#define SHC(x) ((Word16)x) - -const Word16 cos_coef_new[4]= { SHC(0x02BA), SHC(0xE60A), SHC(0xEEEF), SHC(0xAAAB)}; - -/*Sachin: New table. cos_diff_table[i] = sub(cos_table[i+1],cos_table[i]) */ -const Word16 cos_diff_table[512] = -{ - SHC(0xFFFF), SHC(0xFFF8), SHC(0xFFF4), SHC(0xFFEF), SHC(0xFFE9), SHC(0xFFE5), SHC(0xFFE0), SHC(0xFFDB), - SHC(0xFFD6), SHC(0xFFD2), SHC(0xFFCC), SHC(0xFFC7), SHC(0xFFC3), SHC(0xFFBE), SHC(0xFFB8), SHC(0xFFB4), - SHC(0xFFB0), SHC(0xFFAA), SHC(0xFFA5), SHC(0xFFA1), SHC(0xFF9C), SHC(0xFF97), SHC(0xFF92), SHC(0xFF8E), - SHC(0xFF89), SHC(0xFF84), SHC(0xFF80), SHC(0xFF7B), SHC(0xFF76), SHC(0xFF71), SHC(0xFF6D), SHC(0xFF69), - SHC(0xFF64), SHC(0xFF5F), SHC(0xFF5B), SHC(0xFF56), SHC(0xFF52), SHC(0xFF4D), SHC(0xFF49), SHC(0xFF45), - SHC(0xFF40), SHC(0xFF3C), SHC(0xFF38), SHC(0xFF33), SHC(0xFF2F), SHC(0xFF2B), SHC(0xFF27), SHC(0xFF23), - SHC(0xFF1E), SHC(0xFF1B), SHC(0xFF16), SHC(0xFF13), SHC(0xFF0E), SHC(0xFF0B), SHC(0xFF06), SHC(0xFF03), - SHC(0xFEFF), SHC(0xFEFB), SHC(0xFEF8), SHC(0xFEF3), SHC(0xFEF1), SHC(0xFEEC), SHC(0xFEE9), SHC(0xFEE5), - SHC(0xFEE2), SHC(0xFEDF), SHC(0xFEDB), SHC(0xFED8), SHC(0xFED4), SHC(0xFED1), SHC(0xFECE), SHC(0xFECB), - SHC(0xFEC7), SHC(0xFEC5), SHC(0xFEC1), SHC(0xFEBF), SHC(0xFEBB), SHC(0xFEB9), SHC(0xFEB6), SHC(0xFEB3), - SHC(0xFEB0), SHC(0xFEAE), SHC(0xFEAB), SHC(0xFEA8), SHC(0xFEA6), SHC(0xFEA3), SHC(0xFEA1), SHC(0xFE9F), - SHC(0xFE9C), SHC(0xFE9A), SHC(0xFE98), SHC(0xFE95), SHC(0xFE94), SHC(0xFE91), SHC(0xFE8F), SHC(0xFE8E), - SHC(0xFE8B), SHC(0xFE8A), SHC(0xFE88), SHC(0xFE86), SHC(0xFE85), SHC(0xFE83), SHC(0xFE81), SHC(0xFE80), - SHC(0xFE7F), SHC(0xFE7D), SHC(0xFE7B), SHC(0xFE7B), SHC(0xFE79), SHC(0xFE79), SHC(0xFE77), SHC(0xFE76), - SHC(0xFE75), SHC(0xFE74), SHC(0xFE73), SHC(0xFE73), SHC(0xFE72), SHC(0xFE71), SHC(0xFE71), SHC(0xFE70), - SHC(0xFE6F), SHC(0xFE70), SHC(0xFE6E), SHC(0xFE6F), SHC(0xFE6E), SHC(0xFE6E), SHC(0xFE6E), SHC(0xFE6E), - SHC(0xFE6E), SHC(0xFE6E), SHC(0xFE6E), SHC(0xFE6E), SHC(0xFE6F), SHC(0xFE6E), SHC(0xFE70), SHC(0xFE6F), - SHC(0xFE70), SHC(0xFE71), SHC(0xFE71), SHC(0xFE72), SHC(0xFE73), SHC(0xFE73), SHC(0xFE74), SHC(0xFE75), - SHC(0xFE76), SHC(0xFE77), SHC(0xFE79), SHC(0xFE79), SHC(0xFE7B), SHC(0xFE7B), SHC(0xFE7D), SHC(0xFE7F), - SHC(0xFE80), SHC(0xFE81), SHC(0xFE83), SHC(0xFE85), SHC(0xFE86), SHC(0xFE88), SHC(0xFE8A), SHC(0xFE8B), - SHC(0xFE8E), SHC(0xFE8F), SHC(0xFE91), SHC(0xFE94), SHC(0xFE95), SHC(0xFE98), SHC(0xFE9A), SHC(0xFE9C), - SHC(0xFE9F), SHC(0xFEA1), SHC(0xFEA3), SHC(0xFEA6), SHC(0xFEA8), SHC(0xFEAB), SHC(0xFEAE), SHC(0xFEB0), - SHC(0xFEB3), SHC(0xFEB6), SHC(0xFEB9), SHC(0xFEBB), SHC(0xFEBF), SHC(0xFEC1), SHC(0xFEC5), SHC(0xFEC7), - SHC(0xFECB), SHC(0xFECE), SHC(0xFED1), SHC(0xFED4), SHC(0xFED8), SHC(0xFEDB), SHC(0xFEDF), SHC(0xFEE2), - SHC(0xFEE5), SHC(0xFEE9), SHC(0xFEEC), SHC(0xFEF1), SHC(0xFEF3), SHC(0xFEF8), SHC(0xFEFB), SHC(0xFEFF), - SHC(0xFF03), SHC(0xFF06), SHC(0xFF0B), SHC(0xFF0E), SHC(0xFF13), SHC(0xFF16), SHC(0xFF1B), SHC(0xFF1E), - SHC(0xFF23), SHC(0xFF27), SHC(0xFF2B), SHC(0xFF2F), SHC(0xFF33), SHC(0xFF38), SHC(0xFF3C), SHC(0xFF40), - SHC(0xFF45), SHC(0xFF49), SHC(0xFF4D), SHC(0xFF52), SHC(0xFF56), SHC(0xFF5B), SHC(0xFF5F), SHC(0xFF64), - SHC(0xFF69), SHC(0xFF6D), SHC(0xFF71), SHC(0xFF76), SHC(0xFF7B), SHC(0xFF80), SHC(0xFF84), SHC(0xFF89), - SHC(0xFF8E), SHC(0xFF92), SHC(0xFF97), SHC(0xFF9C), SHC(0xFFA1), SHC(0xFFA5), SHC(0xFFAA), SHC(0xFFB0), - SHC(0xFFB4), SHC(0xFFB8), SHC(0xFFBE), SHC(0xFFC3), SHC(0xFFC7), SHC(0xFFCC), SHC(0xFFD2), SHC(0xFFD6), - SHC(0xFFDB), SHC(0xFFE0), SHC(0xFFE5), SHC(0xFFE9), SHC(0xFFEF), SHC(0xFFF4), SHC(0xFFF8), SHC(0xFFFF), - SHC(0x0001), SHC(0x0008), SHC(0x000C), SHC(0x0011), SHC(0x0017), SHC(0x001B), SHC(0x0020), SHC(0x0025), - SHC(0x002A), SHC(0x002E), SHC(0x0034), SHC(0x0039), SHC(0x003D), SHC(0x0042), SHC(0x0048), SHC(0x004C), - SHC(0x0050), SHC(0x0056), SHC(0x005B), SHC(0x005F), SHC(0x0064), SHC(0x0069), SHC(0x006E), SHC(0x0072), - SHC(0x0077), SHC(0x007C), SHC(0x0080), SHC(0x0085), SHC(0x008A), SHC(0x008F), SHC(0x0093), SHC(0x0097), - SHC(0x009C), SHC(0x00A1), SHC(0x00A5), SHC(0x00AA), SHC(0x00AE), SHC(0x00B3), SHC(0x00B7), SHC(0x00BB), - SHC(0x00C0), SHC(0x00C4), SHC(0x00C8), SHC(0x00CD), SHC(0x00D1), SHC(0x00D5), SHC(0x00D9), SHC(0x00DD), - SHC(0x00E2), SHC(0x00E5), SHC(0x00EA), SHC(0x00ED), SHC(0x00F2), SHC(0x00F5), SHC(0x00FA), SHC(0x00FD), - SHC(0x0101), SHC(0x0105), SHC(0x0108), SHC(0x010D), SHC(0x010F), SHC(0x0114), SHC(0x0117), SHC(0x011B), - SHC(0x011E), SHC(0x0121), SHC(0x0125), SHC(0x0128), SHC(0x012C), SHC(0x012F), SHC(0x0132), SHC(0x0135), - SHC(0x0139), SHC(0x013B), SHC(0x013F), SHC(0x0141), SHC(0x0145), SHC(0x0147), SHC(0x014A), SHC(0x014D), - SHC(0x0150), SHC(0x0152), SHC(0x0155), SHC(0x0158), SHC(0x015A), SHC(0x015D), SHC(0x015F), SHC(0x0161), - SHC(0x0164), SHC(0x0166), SHC(0x0168), SHC(0x016B), SHC(0x016C), SHC(0x016F), SHC(0x0171), SHC(0x0172), - SHC(0x0175), SHC(0x0176), SHC(0x0178), SHC(0x017A), SHC(0x017B), SHC(0x017D), SHC(0x017F), SHC(0x0180), - SHC(0x0181), SHC(0x0183), SHC(0x0185), SHC(0x0185), SHC(0x0187), SHC(0x0187), SHC(0x0189), SHC(0x018A), - SHC(0x018B), SHC(0x018C), SHC(0x018D), SHC(0x018D), SHC(0x018E), SHC(0x018F), SHC(0x018F), SHC(0x0190), - SHC(0x0191), SHC(0x0190), SHC(0x0192), SHC(0x0191), SHC(0x0192), SHC(0x0192), SHC(0x0192), SHC(0x0192), - SHC(0x0192), SHC(0x0192), SHC(0x0192), SHC(0x0192), SHC(0x0191), SHC(0x0192), SHC(0x0190), SHC(0x0191), - SHC(0x0190), SHC(0x018F), SHC(0x018F), SHC(0x018E), SHC(0x018D), SHC(0x018D), SHC(0x018C), SHC(0x018B), - SHC(0x018A), SHC(0x0189), SHC(0x0187), SHC(0x0187), SHC(0x0185), SHC(0x0185), SHC(0x0183), SHC(0x0181), - SHC(0x0180), SHC(0x017F), SHC(0x017D), SHC(0x017B), SHC(0x017A), SHC(0x0178), SHC(0x0176), SHC(0x0175), - SHC(0x0172), SHC(0x0171), SHC(0x016F), SHC(0x016C), SHC(0x016B), SHC(0x0168), SHC(0x0166), SHC(0x0164), - SHC(0x0161), SHC(0x015F), SHC(0x015D), SHC(0x015A), SHC(0x0158), SHC(0x0155), SHC(0x0152), SHC(0x0150), - SHC(0x014D), SHC(0x014A), SHC(0x0147), SHC(0x0145), SHC(0x0141), SHC(0x013F), SHC(0x013B), SHC(0x0139), - SHC(0x0135), SHC(0x0132), SHC(0x012F), SHC(0x012C), SHC(0x0128), SHC(0x0125), SHC(0x0121), SHC(0x011E), - SHC(0x011B), SHC(0x0117), SHC(0x0114), SHC(0x010F), SHC(0x010D), SHC(0x0108), SHC(0x0105), SHC(0x0101), - SHC(0x00FD), SHC(0x00FA), SHC(0x00F5), SHC(0x00F2), SHC(0x00ED), SHC(0x00EA), SHC(0x00E5), SHC(0x00E2), - SHC(0x00DD), SHC(0x00D9), SHC(0x00D5), SHC(0x00D1), SHC(0x00CD), SHC(0x00C8), SHC(0x00C4), SHC(0x00C0), - SHC(0x00BB), SHC(0x00B7), SHC(0x00B3), SHC(0x00AE), SHC(0x00AA), SHC(0x00A5), SHC(0x00A1), SHC(0x009C), - SHC(0x0097), SHC(0x0093), SHC(0x008F), SHC(0x008A), SHC(0x0085), SHC(0x0080), SHC(0x007C), SHC(0x0077), - SHC(0x0072), SHC(0x006E), SHC(0x0069), SHC(0x0064), SHC(0x005F), SHC(0x005B), SHC(0x0056), SHC(0x0050), - SHC(0x004C), SHC(0x0048), SHC(0x0042), SHC(0x003D), SHC(0x0039), SHC(0x0034), SHC(0x002E), SHC(0x002A), - SHC(0x0025), SHC(0x0020), SHC(0x001B), SHC(0x0017), SHC(0x0011), SHC(0x000C), SHC(0x0008), SHC(0x0001) -}; - -const Word16 cos_table[512]= -{ - SHC(0x7fff), - SHC(0x7ffe), - SHC(0x7ff6), - SHC(0x7fea), - SHC(0x7fd9), - SHC(0x7fc2), - SHC(0x7fa7), - SHC(0x7f87), - SHC(0x7f62), - SHC(0x7f38), - SHC(0x7f0a), - SHC(0x7ed6), - SHC(0x7e9d), - SHC(0x7e60), - SHC(0x7e1e), - SHC(0x7dd6), - SHC(0x7d8a), - SHC(0x7d3a), - SHC(0x7ce4), - SHC(0x7c89), - SHC(0x7c2a), - SHC(0x7bc6), - SHC(0x7b5d), - SHC(0x7aef), - SHC(0x7a7d), - SHC(0x7a06), - SHC(0x798a), - SHC(0x790a), - SHC(0x7885), - SHC(0x77fb), - SHC(0x776c), - SHC(0x76d9), - SHC(0x7642), - SHC(0x75a6), - SHC(0x7505), - SHC(0x7460), - SHC(0x73b6), - SHC(0x7308), - SHC(0x7255), - SHC(0x719e), - SHC(0x70e3), - SHC(0x7023), - SHC(0x6f5f), - SHC(0x6e97), - SHC(0x6dca), - SHC(0x6cf9), - SHC(0x6c24), - SHC(0x6b4b), - SHC(0x6a6e), - SHC(0x698c), - SHC(0x68a7), - SHC(0x67bd), - SHC(0x66d0), - SHC(0x65de), - SHC(0x64e9), - SHC(0x63ef), - SHC(0x62f2), - SHC(0x61f1), - SHC(0x60ec), - SHC(0x5fe4), - SHC(0x5ed7), - SHC(0x5dc8), - SHC(0x5cb4), - SHC(0x5b9d), - SHC(0x5a82), - SHC(0x5964), - SHC(0x5843), - SHC(0x571e), - SHC(0x55f6), - SHC(0x54ca), - SHC(0x539b), - SHC(0x5269), - SHC(0x5134), - SHC(0x4ffb), - SHC(0x4ec0), - SHC(0x4d81), - SHC(0x4c40), - SHC(0x4afb), - SHC(0x49b4), - SHC(0x486a), - SHC(0x471d), - SHC(0x45cd), - SHC(0x447b), - SHC(0x4326), - SHC(0x41ce), - SHC(0x4074), - SHC(0x3f17), - SHC(0x3db8), - SHC(0x3c57), - SHC(0x3af3), - SHC(0x398d), - SHC(0x3825), - SHC(0x36ba), - SHC(0x354e), - SHC(0x33df), - SHC(0x326e), - SHC(0x30fc), - SHC(0x2f87), - SHC(0x2e11), - SHC(0x2c99), - SHC(0x2b1f), - SHC(0x29a4), - SHC(0x2827), - SHC(0x26a8), - SHC(0x2528), - SHC(0x23a7), - SHC(0x2224), - SHC(0x209f), - SHC(0x1f1a), - SHC(0x1d93), - SHC(0x1c0c), - SHC(0x1a83), - SHC(0x18f9), - SHC(0x176e), - SHC(0x15e2), - SHC(0x1455), - SHC(0x12c8), - SHC(0x113a), - SHC(0xfab), - SHC(0xe1c), - SHC(0xc8c), - SHC(0xafb), - SHC(0x96b), - SHC(0x7d9), - SHC(0x648), - SHC(0x4b6), - SHC(0x324), - SHC(0x192), - SHC(0x0), - SHC(0xfe6e), - SHC(0xfcdc), - SHC(0xfb4a), - SHC(0xf9b8), - SHC(0xf827), - SHC(0xf695), - SHC(0xf505), - SHC(0xf374), - SHC(0xf1e4), - SHC(0xf055), - SHC(0xeec6), - SHC(0xed38), - SHC(0xebab), - SHC(0xea1e), - SHC(0xe892), - SHC(0xe707), - SHC(0xe57d), - SHC(0xe3f4), - SHC(0xe26d), - SHC(0xe0e6), - SHC(0xdf61), - SHC(0xdddc), - SHC(0xdc59), - SHC(0xdad8), - SHC(0xd958), - SHC(0xd7d9), - SHC(0xd65c), - SHC(0xd4e1), - SHC(0xd367), - SHC(0xd1ef), - SHC(0xd079), - SHC(0xcf04), - SHC(0xcd92), - SHC(0xcc21), - SHC(0xcab2), - SHC(0xc946), - SHC(0xc7db), - SHC(0xc673), - SHC(0xc50d), - SHC(0xc3a9), - SHC(0xc248), - SHC(0xc0e9), - SHC(0xbf8c), - SHC(0xbe32), - SHC(0xbcda), - SHC(0xbb85), - SHC(0xba33), - SHC(0xb8e3), - SHC(0xb796), - SHC(0xb64c), - SHC(0xb505), - SHC(0xb3c0), - SHC(0xb27f), - SHC(0xb140), - SHC(0xb005), - SHC(0xaecc), - SHC(0xad97), - SHC(0xac65), - SHC(0xab36), - SHC(0xaa0a), - SHC(0xa8e2), - SHC(0xa7bd), - SHC(0xa69c), - SHC(0xa57e), - SHC(0xa463), - SHC(0xa34c), - SHC(0xa238), - SHC(0xa129), - SHC(0xa01c), - SHC(0x9f14), - SHC(0x9e0f), - SHC(0x9d0e), - SHC(0x9c11), - SHC(0x9b17), - SHC(0x9a22), - SHC(0x9930), - SHC(0x9843), - SHC(0x9759), - SHC(0x9674), - SHC(0x9592), - SHC(0x94b5), - SHC(0x93dc), - SHC(0x9307), - SHC(0x9236), - SHC(0x9169), - SHC(0x90a1), - SHC(0x8fdd), - SHC(0x8f1d), - SHC(0x8e62), - SHC(0x8dab), - SHC(0x8cf8), - SHC(0x8c4a), - SHC(0x8ba0), - SHC(0x8afb), - SHC(0x8a5a), - SHC(0x89be), - SHC(0x8927), - SHC(0x8894), - SHC(0x8805), - SHC(0x877b), - SHC(0x86f6), - SHC(0x8676), - SHC(0x85fa), - SHC(0x8583), - SHC(0x8511), - SHC(0x84a3), - SHC(0x843a), - SHC(0x83d6), - SHC(0x8377), - SHC(0x831c), - SHC(0x82c6), - SHC(0x8276), - SHC(0x822a), - SHC(0x81e2), - SHC(0x81a0), - SHC(0x8163), - SHC(0x812a), - SHC(0x80f6), - SHC(0x80c8), - SHC(0x809e), - SHC(0x8079), - SHC(0x8059), - SHC(0x803e), - SHC(0x8027), - SHC(0x8016), - SHC(0x800a), - SHC(0x8002), - SHC(0x8001), - SHC(0x8002), - SHC(0x800a), - SHC(0x8016), - SHC(0x8027), - SHC(0x803e), - SHC(0x8059), - SHC(0x8079), - SHC(0x809e), - SHC(0x80c8), - SHC(0x80f6), - SHC(0x812a), - SHC(0x8163), - SHC(0x81a0), - SHC(0x81e2), - SHC(0x822a), - SHC(0x8276), - SHC(0x82c6), - SHC(0x831c), - SHC(0x8377), - SHC(0x83d6), - SHC(0x843a), - SHC(0x84a3), - SHC(0x8511), - SHC(0x8583), - SHC(0x85fa), - SHC(0x8676), - SHC(0x86f6), - SHC(0x877b), - SHC(0x8805), - SHC(0x8894), - SHC(0x8927), - SHC(0x89be), - SHC(0x8a5a), - SHC(0x8afb), - SHC(0x8ba0), - SHC(0x8c4a), - SHC(0x8cf8), - SHC(0x8dab), - SHC(0x8e62), - SHC(0x8f1d), - SHC(0x8fdd), - SHC(0x90a1), - SHC(0x9169), - SHC(0x9236), - SHC(0x9307), - SHC(0x93dc), - SHC(0x94b5), - SHC(0x9592), - SHC(0x9674), - SHC(0x9759), - SHC(0x9843), - SHC(0x9930), - SHC(0x9a22), - SHC(0x9b17), - SHC(0x9c11), - SHC(0x9d0e), - SHC(0x9e0f), - SHC(0x9f14), - SHC(0xa01c), - SHC(0xa129), - SHC(0xa238), - SHC(0xa34c), - SHC(0xa463), - SHC(0xa57e), - SHC(0xa69c), - SHC(0xa7bd), - SHC(0xa8e2), - SHC(0xaa0a), - SHC(0xab36), - SHC(0xac65), - SHC(0xad97), - SHC(0xaecc), - SHC(0xb005), - SHC(0xb140), - SHC(0xb27f), - SHC(0xb3c0), - SHC(0xb505), - SHC(0xb64c), - SHC(0xb796), - SHC(0xb8e3), - SHC(0xba33), - SHC(0xbb85), - SHC(0xbcda), - SHC(0xbe32), - SHC(0xbf8c), - SHC(0xc0e9), - SHC(0xc248), - SHC(0xc3a9), - SHC(0xc50d), - SHC(0xc673), - SHC(0xc7db), - SHC(0xc946), - SHC(0xcab2), - SHC(0xcc21), - SHC(0xcd92), - SHC(0xcf04), - SHC(0xd079), - SHC(0xd1ef), - SHC(0xd367), - SHC(0xd4e1), - SHC(0xd65c), - SHC(0xd7d9), - SHC(0xd958), - SHC(0xdad8), - SHC(0xdc59), - SHC(0xdddc), - SHC(0xdf61), - SHC(0xe0e6), - SHC(0xe26d), - SHC(0xe3f4), - SHC(0xe57d), - SHC(0xe707), - SHC(0xe892), - SHC(0xea1e), - SHC(0xebab), - SHC(0xed38), - SHC(0xeec6), - SHC(0xf055), - SHC(0xf1e4), - SHC(0xf374), - SHC(0xf505), - SHC(0xf695), - SHC(0xf827), - SHC(0xf9b8), - SHC(0xfb4a), - SHC(0xfcdc), - SHC(0xfe6e), - SHC(0x0), - SHC(0x192), - SHC(0x324), - SHC(0x4b6), - SHC(0x648), - SHC(0x7d9), - SHC(0x96b), - SHC(0xafb), - SHC(0xc8c), - SHC(0xe1c), - SHC(0xfab), - SHC(0x113a), - SHC(0x12c8), - SHC(0x1455), - SHC(0x15e2), - SHC(0x176e), - SHC(0x18f9), - SHC(0x1a83), - SHC(0x1c0c), - SHC(0x1d93), - SHC(0x1f1a), - SHC(0x209f), - SHC(0x2224), - SHC(0x23a7), - SHC(0x2528), - SHC(0x26a8), - SHC(0x2827), - SHC(0x29a4), - SHC(0x2b1f), - SHC(0x2c99), - SHC(0x2e11), - SHC(0x2f87), - SHC(0x30fc), - SHC(0x326e), - SHC(0x33df), - SHC(0x354e), - SHC(0x36ba), - SHC(0x3825), - SHC(0x398d), - SHC(0x3af3), - SHC(0x3c57), - SHC(0x3db8), - SHC(0x3f17), - SHC(0x4074), - SHC(0x41ce), - SHC(0x4326), - SHC(0x447b), - SHC(0x45cd), - SHC(0x471d), - SHC(0x486a), - SHC(0x49b4), - SHC(0x4afb), - SHC(0x4c40), - SHC(0x4d81), - SHC(0x4ec0), - SHC(0x4ffb), - SHC(0x5134), - SHC(0x5269), - SHC(0x539b), - SHC(0x54ca), - SHC(0x55f6), - SHC(0x571e), - SHC(0x5843), - SHC(0x5964), - SHC(0x5a82), - SHC(0x5b9d), - SHC(0x5cb4), - SHC(0x5dc8), - SHC(0x5ed7), - SHC(0x5fe4), - SHC(0x60ec), - SHC(0x61f1), - SHC(0x62f2), - SHC(0x63ef), - SHC(0x64e9), - SHC(0x65de), - SHC(0x66d0), - SHC(0x67bd), - SHC(0x68a7), - SHC(0x698c), - SHC(0x6a6e), - SHC(0x6b4b), - SHC(0x6c24), - SHC(0x6cf9), - SHC(0x6dca), - SHC(0x6e97), - SHC(0x6f5f), - SHC(0x7023), - SHC(0x70e3), - SHC(0x719e), - SHC(0x7255), - SHC(0x7308), - SHC(0x73b6), - SHC(0x7460), - SHC(0x7505), - SHC(0x75a6), - SHC(0x7642), - SHC(0x76d9), - SHC(0x776c), - SHC(0x77fb), - SHC(0x7885), - SHC(0x790a), - SHC(0x798a), - SHC(0x7a06), - SHC(0x7a7d), - SHC(0x7aef), - SHC(0x7b5d), - SHC(0x7bc6), - SHC(0x7c2a), - SHC(0x7c89), - SHC(0x7ce4), - SHC(0x7d3a), - SHC(0x7d8a), - SHC(0x7dd6), - SHC(0x7e1e), - SHC(0x7e60), - SHC(0x7e9d), - SHC(0x7ed6), - SHC(0x7f0a), - SHC(0x7f38), - SHC(0x7f62), - SHC(0x7f87), - SHC(0x7fa7), - SHC(0x7fc2), - SHC(0x7fd9), - SHC(0x7fea), - SHC(0x7ff6), - SHC(0x7ffe) -}; - - - -const Word16 window_8_16_32kHz_fx[370] = -{ - 3, 9, 19, 33, 49, 69, 93, 119, - 149, 182, 219, 258, 301, 347, 396, 448, - 503, 561, 623, 687, 755, 825, 898, 974, - 1054, 1136, 1221, 1309, 1399, 1493, 1589, 1688, - 1790, 1895, 2002, 2112, 2225, 2340, 2458, 2579, - 2702, 2827, 2955, 3086, 3219, 3355, 3493, 3633, - 3775, 3920, 4068, 4217, 4369, 4523, 4679, 4837, - 4998, 5160, 5325, 5491, 5660, 5830, 6003, 6177, - 6353, 6531, 6711, 6892, 7076, 7260, 7447, 7635, - 7825, 8016, 8209, 8403, 8599, 8796, 8995, 9195, - 9396, 9598, 9802, 10007, 10212, 10419, 10628, 10837, - 11047, 11248, 11437, 11623, 11809, 11997, 12185, 12374, - 12564, 12754, 12944, 13135, 13326, 13517, 13709, 13901, - 14093, 14286, 14478, 14671, 14864, 15057, 15250, 15443, - 15636, 15829, 16023, 16216, 16409, 16602, 16794, 16987, - 17179, 17372, 17564, 17755, 17947, 18138, 18329, 18519, - 18710, 18899, 19089, 19278, 19466, 19654, 19841, 20028, - 20214, 20400, 20585, 20770, 20954, 21137, 21319, 21501, - 21682, 21862, 22042, 22220, 22398, 22575, 22751, 22926, - 23101, 23274, 23446, 23618, 23788, 23958, 24126, 24266, - 24321, 24460, 24625, 24789, 24953, 25114, 25275, 25435, - 25593, 25751, 25907, 26061, 26215, 26367, 26518, 26668, - 26817, 26964, 27110, 27254, 27398, 27540, 27680, 27819, - 27957, 28093, 28228, 28362, 28494, 28625, 28754, 28882, - 29008, 29133, 29256, 29378, 29499, 29618, 29736, 29852, - 29966, 30079, 30191, 30301, 30410, 30517, 30623, 30727, - 30830, 30931, 31031, 31129, 31226, 31322, 31416, 31508, - 31599, 31689, 31777, 31864, 31950, 32035, 32118, 32200, - 32280, 32360, 32439, 32517, 32595, 32673, 32673, 32593, - 32513, 32432, 32349, 32265, 32178, 32090, 31999, 31907, - 31812, 31715, 31615, 31514, 31410, 31304, 31196, 31085, - 30972, 30857, 30739, 30619, 30497, 30372, 30245, 30116, - 29984, 29850, 29714, 29575, 29434, 29290, 29144, 28996, - 28845, 28692, 28537, 28379, 28219, 28057, 27892, 27725, - 27555, 27383, 27209, 27033, 26854, 26672, 26489, 26303, - 26115, 25924, 25731, 25536, 25338, 25138, 24936, 24731, - 24525, 24316, 24104, 23890, 23674, 23456, 23236, 23013, - 22788, 22561, 22331, 22138, 22060, 21865, 21629, 21390, - 21150, 20907, 20662, 20414, 20165, 19913, 19659, 19403, - 19145, 18885, 18622, 18357, 18090, 17821, 17550, 17277, - 17001, 16723, 16443, 16161, 15877, 15591, 15303, 15012, - 14719, 14425, 14127, 13828, 13527, 13223, 12918, 12610, - 12300, 11988, 11673, 11356, 11038, 10716, 10393, 10067, - 9739, 9408, 9076, 8740, 8403, 8062, 7720, 7374, - 7026, 6675, 6322, 5965, 5606, 5243, 4878, 4508, - 4136, 3759, 3378, 2993, 2603, 2208, 1807, 1397, - 978, 545 -}; - - - - -const Word16 window_48kHz_fx[1110] = -{ - 0, 1, 2, 3, 5, 8, 10, 13, - 17, 21, 25, 30, 35, 40, 46, 52, - 58, 65, 72, 80, 88, 96, 105, 114, - 124, 133, 144, 154, 165, 176, 188, 200, - 212, 225, 238, 251, 265, 279, 293, 308, - 323, 339, 354, 371, 387, 404, 421, 439, - 457, 475, 493, 512, 532, 551, 571, 591, - 612, 633, 654, 676, 698, 720, 743, 766, - 789, 813, 837, 861, 885, 910, 936, 961, - 987, 1013, 1040, 1067, 1094, 1122, 1149, 1178, - 1206, 1235, 1264, 1293, 1323, 1353, 1384, 1414, - 1445, 1477, 1508, 1540, 1573, 1605, 1638, 1671, - 1705, 1739, 1773, 1807, 1842, 1877, 1912, 1948, - 1984, 2020, 2057, 2093, 2130, 2168, 2206, 2244, - 2282, 2320, 2359, 2399, 2438, 2478, 2518, 2558, - 2599, 2640, 2681, 2722, 2764, 2806, 2848, 2891, - 2934, 2977, 3020, 3064, 3108, 3152, 3196, 3241, - 3286, 3332, 3377, 3423, 3469, 3515, 3562, 3609, - 3656, 3704, 3751, 3799, 3847, 3896, 3945, 3994, - 4043, 4092, 4142, 4192, 4242, 4293, 4343, 4394, - 4445, 4497, 4549, 4600, 4653, 4705, 4758, 4811, - 4864, 4917, 4971, 5024, 5078, 5133, 5187, 5242, - 5297, 5352, 5407, 5463, 5519, 5575, 5631, 5688, - 5744, 5801, 5859, 5916, 5974, 6031, 6089, 6147, - 6206, 6265, 6323, 6382, 6442, 6501, 6561, 6620, - 6680, 6741, 6801, 6862, 6922, 6983, 7045, 7106, - 7168, 7229, 7291, 7353, 7416, 7478, 7541, 7604, - 7667, 7730, 7793, 7857, 7920, 7984, 8048, 8112, - 8177, 8241, 8306, 8371, 8436, 8501, 8566, 8632, - 8697, 8763, 8829, 8895, 8961, 9028, 9094, 9161, - 9228, 9295, 9362, 9429, 9497, 9564, 9632, 9700, - 9768, 9836, 9904, 9972, 10041, 10109, 10178, 10247, - 10316, 10385, 10454, 10523, 10593, 10662, 10732, 10802, - 10871, 10941, 11012, 11082, 11152, 11222, 11283, 11344, - 11406, 11467, 11529, 11591, 11653, 11716, 11778, 11840, - 11903, 11966, 12028, 12091, 12154, 12217, 12280, 12343, - 12406, 12469, 12532, 12595, 12658, 12722, 12785, 12849, - 12912, 12976, 13039, 13103, 13166, 13230, 13294, 13358, - 13421, 13485, 13549, 13613, 13677, 13741, 13805, 13869, - 13933, 13997, 14061, 14125, 14189, 14253, 14318, 14382, - 14446, 14510, 14574, 14639, 14703, 14767, 14832, 14896, - 14960, 15025, 15089, 15153, 15218, 15282, 15346, 15411, - 15475, 15540, 15604, 15668, 15733, 15797, 15862, 15926, - 15990, 16055, 16119, 16183, 16248, 16312, 16376, 16441, - 16505, 16569, 16634, 16698, 16762, 16826, 16891, 16955, - 17019, 17083, 17147, 17211, 17275, 17339, 17404, 17468, - 17532, 17596, 17659, 17723, 17787, 17851, 17915, 17979, - 18042, 18106, 18170, 18233, 18297, 18361, 18424, 18488, - 18551, 18614, 18678, 18741, 18804, 18868, 18931, 18994, - 19057, 19120, 19183, 19246, 19309, 19372, 19434, 19497, - 19560, 19622, 19685, 19748, 19810, 19872, 19935, 19997, - 20059, 20121, 20183, 20245, 20307, 20369, 20431, 20493, - 20554, 20616, 20677, 20739, 20800, 20862, 20923, 20984, - 21045, 21106, 21167, 21228, 21289, 21349, 21410, 21471, - 21531, 21591, 21652, 21712, 21772, 21832, 21892, 21952, - 22012, 22071, 22131, 22190, 22250, 22309, 22368, 22427, - 22486, 22545, 22604, 22663, 22722, 22780, 22839, 22897, - 22955, 23013, 23071, 23129, 23187, 23245, 23303, 23360, - 23418, 23475, 23532, 23589, 23646, 23703, 23760, 23817, - 23873, 23930, 23986, 24042, 24098, 24154, 24210, 24266, - 24321, 24377, 24432, 24488, 24543, 24598, 24653, 24707, - 24762, 24817, 24871, 24925, 24979, 25034, 25087, 25141, - 25195, 25248, 25302, 25355, 25408, 25461, 25514, 25567, - 25620, 25672, 25724, 25777, 25829, 25881, 25932, 25984, - 26036, 26087, 26138, 26189, 26240, 26291, 26342, 26393, - 26443, 26493, 26543, 26593, 26643, 26693, 26743, 26792, - 26841, 26890, 26939, 26988, 27037, 27086, 27134, 27182, - 27230, 27278, 27326, 27374, 27421, 27469, 27516, 27563, - 27610, 27657, 27703, 27750, 27796, 27842, 27888, 27934, - 27980, 28025, 28071, 28116, 28161, 28206, 28250, 28295, - 28340, 28384, 28428, 28472, 28516, 28559, 28603, 28646, - 28689, 28732, 28775, 28818, 28860, 28903, 28945, 28987, - 29029, 29071, 29112, 29154, 29195, 29236, 29277, 29318, - 29358, 29399, 29439, 29479, 29519, 29559, 29598, 29638, - 29677, 29716, 29755, 29794, 29832, 29871, 29909, 29947, - 29985, 30023, 30061, 30098, 30135, 30172, 30209, 30246, - 30283, 30319, 30356, 30392, 30428, 30464, 30499, 30535, - 30570, 30605, 30640, 30675, 30710, 30744, 30779, 30813, - 30847, 30881, 30914, 30948, 30981, 31014, 31047, 31080, - 31113, 31145, 31178, 31210, 31242, 31274, 31306, 31337, - 31369, 31400, 31431, 31462, 31493, 31523, 31554, 31584, - 31614, 31644, 31674, 31704, 31733, 31763, 31792, 31821, - 31850, 31879, 31907, 31936, 31964, 31992, 32020, 32048, - 32076, 32104, 32131, 32159, 32186, 32213, 32240, 32267, - 32294, 32320, 32347, 32373, 32399, 32426, 32452, 32478, - 32504, 32530, 32556, 32582, 32607, 32633, 32659, 32685, - 32712, 32739, 32739, 32712, 32685, 32659, 32633, 32606, - 32580, 32553, 32527, 32500, 32473, 32446, 32418, 32391, - 32363, 32335, 32307, 32279, 32251, 32222, 32193, 32164, - 32134, 32105, 32075, 32045, 32015, 31984, 31953, 31922, - 31891, 31859, 31828, 31796, 31764, 31731, 31698, 31665, - 31632, 31599, 31565, 31531, 31497, 31462, 31428, 31393, - 31357, 31322, 31286, 31250, 31214, 31177, 31141, 31104, - 31066, 31029, 30991, 30953, 30915, 30876, 30837, 30798, - 30759, 30719, 30679, 30639, 30599, 30558, 30517, 30476, - 30435, 30393, 30351, 30309, 30266, 30224, 30181, 30138, - 30094, 30050, 30006, 29962, 29917, 29873, 29827, 29782, - 29737, 29691, 29645, 29598, 29551, 29505, 29457, 29410, - 29362, 29314, 29266, 29218, 29169, 29120, 29070, 29021, - 28971, 28921, 28871, 28820, 28769, 28718, 28667, 28615, - 28563, 28511, 28459, 28406, 28353, 28300, 28246, 28192, - 28138, 28084, 28030, 27975, 27920, 27864, 27809, 27753, - 27697, 27640, 27584, 27527, 27470, 27412, 27355, 27297, - 27238, 27180, 27121, 27062, 27003, 26944, 26884, 26824, - 26763, 26703, 26642, 26581, 26520, 26458, 26396, 26334, - 26272, 26209, 26146, 26083, 26020, 25956, 25892, 25828, - 25763, 25699, 25634, 25568, 25503, 25437, 25371, 25305, - 25239, 25172, 25105, 25037, 24970, 24902, 24834, 24766, - 24697, 24628, 24559, 24490, 24420, 24351, 24281, 24210, - 24140, 24069, 23998, 23926, 23855, 23783, 23711, 23638, - 23566, 23493, 23420, 23346, 23273, 23199, 23125, 23050, - 22976, 22901, 22826, 22750, 22675, 22599, 22523, 22446, - 22370, 22293, 22215, 22138, 22060, 21983, 21904, 21826, - 21747, 21669, 21589, 21510, 21430, 21351, 21271, 21190, - 21110, 21029, 20948, 20866, 20785, 20703, 20621, 20538, - 20456, 20373, 20290, 20207, 20123, 20039, 19955, 19871, - 19787, 19702, 19617, 19532, 19446, 19360, 19274, 19188, - 19102, 19015, 18928, 18841, 18754, 18666, 18578, 18490, - 18402, 18313, 18224, 18135, 18046, 17956, 17866, 17776, - 17686, 17595, 17505, 17414, 17322, 17231, 17139, 17047, - 16955, 16863, 16770, 16677, 16584, 16490, 16397, 16303, - 16209, 16114, 16020, 15925, 15830, 15735, 15639, 15543, - 15447, 15351, 15254, 15158, 15061, 14964, 14866, 14768, - 14671, 14572, 14474, 14375, 14276, 14177, 14078, 13978, - 13878, 13778, 13678, 13578, 13477, 13376, 13274, 13173, - 13071, 12969, 12867, 12764, 12662, 12559, 12455, 12352, - 12248, 12144, 12040, 11936, 11831, 11726, 11621, 11515, - 11410, 11304, 11197, 11091, 10984, 10877, 10770, 10663, - 10555, 10447, 10339, 10230, 10122, 10013, 9904, 9794, - 9684, 9574, 9464, 9353, 9243, 9131, 9020, 8908, - 8797, 8684, 8572, 8459, 8346, 8233, 8119, 8006, - 7892, 7777, 7662, 7547, 7432, 7317, 7201, 7085, - 6968, 6851, 6734, 6617, 6499, 6381, 6263, 6144, - 6025, 5906, 5786, 5666, 5546, 5425, 5304, 5183, - 5061, 4939, 4817, 4694, 4570, 4447, 4323, 4198, - 4074, 3948, 3823, 3696, 3570, 3443, 3315, 3187, - 3058, 2929, 2800, 2669, 2539, 2407, 2275, 2142, - 2009, 1875, 1740, 1604, 1467, 1330, 1191, 1051, - 909, 766, 621, 474, 324, 169 -}; - - -const Word16 window_256kHz[592] = /*ALDO at 25.6 maybe not needed ?*/ -{ - 1, 3, 7, 12, 19, 27, 36, 47, - 58, 72, 86, 102, 119, 138, 157, 178, - 201, 224, 249, 275, 302, 331, 361, 391, - 424, 457, 492, 527, 564, 603, 642, 683, - 724, 767, 811, 857, 903, 951, 999, 1049, - 1100, 1152, 1205, 1260, 1315, 1372, 1430, 1488, - 1548, 1609, 1671, 1735, 1799, 1864, 1931, 1998, - 2066, 2136, 2207, 2278, 2351, 2424, 2499, 2575, - 2651, 2729, 2808, 2887, 2968, 3049, 3132, 3215, - 3300, 3385, 3472, 3559, 3647, 3736, 3826, 3917, - 4009, 4101, 4195, 4289, 4385, 4481, 4578, 4676, - 4774, 4874, 4974, 5075, 5177, 5280, 5384, 5488, - 5593, 5699, 5806, 5913, 6021, 6130, 6240, 6350, - 6461, 6573, 6685, 6798, 6912, 7026, 7141, 7257, - 7373, 7491, 7608, 7726, 7845, 7965, 8085, 8206, - 8327, 8449, 8571, 8694, 8817, 8941, 9066, 9191, - 9316, 9442, 9569, 9696, 9823, 9951, 10079, 10208, - 10337, 10467, 10597, 10727, 10858, 10990, 11121, 11253, - 11367, 11482, 11598, 11714, 11831, 11948, 12065, 12182, - 12300, 12418, 12536, 12654, 12772, 12891, 13010, 13129, - 13248, 13367, 13486, 13605, 13725, 13844, 13964, 14084, - 14203, 14323, 14443, 14563, 14683, 14804, 14924, 15044, - 15164, 15284, 15405, 15525, 15645, 15765, 15885, 16006, - 16126, 16246, 16366, 16486, 16606, 16726, 16846, 16966, - 17086, 17206, 17325, 17445, 17564, 17684, 17803, 17922, - 18041, 18160, 18279, 18397, 18516, 18634, 18753, 18871, - 18988, 19106, 19224, 19341, 19458, 19575, 19692, 19809, - 19925, 20041, 20157, 20273, 20388, 20503, 20618, 20733, - 20848, 20962, 21076, 21190, 21303, 21416, 21529, 21642, - 21754, 21866, 21978, 22089, 22200, 22311, 22421, 22531, - 22641, 22751, 22860, 22968, 23077, 23185, 23293, 23400, - 23507, 23613, 23719, 23825, 23931, 24036, 24140, 24244, - 24348, 24452, 24555, 24657, 24759, 24861, 24962, 25063, - 25163, 25263, 25363, 25462, 25561, 25659, 25756, 25854, - 25950, 26047, 26142, 26238, 26333, 26427, 26521, 26614, - 26707, 26799, 26891, 26982, 27073, 27164, 27253, 27343, - 27432, 27520, 27608, 27695, 27781, 27868, 27953, 28038, - 28123, 28207, 28290, 28373, 28456, 28537, 28619, 28699, - 28780, 28859, 28938, 29017, 29095, 29172, 29249, 29325, - 29401, 29476, 29550, 29624, 29698, 29771, 29843, 29915, - 29986, 30056, 30126, 30196, 30264, 30333, 30400, 30467, - 30534, 30600, 30665, 30730, 30794, 30858, 30921, 30984, - 31046, 31107, 31168, 31228, 31288, 31347, 31406, 31464, - 31522, 31579, 31635, 31691, 31746, 31801, 31856, 31909, - 31963, 32016, 32068, 32120, 32171, 32222, 32273, 32323, - 32372, 32422, 32471, 32520, 32568, 32617, 32666, 32715, - 32715, 32666, 32616, 32567, 32517, 32466, 32415, 32364, - 32311, 32258, 32204, 32150, 32094, 32038, 31981, 31923, - 31864, 31805, 31744, 31683, 31621, 31557, 31494, 31429, - 31363, 31296, 31229, 31161, 31091, 31021, 30950, 30878, - 30805, 30731, 30657, 30581, 30505, 30427, 30349, 30270, - 30189, 30108, 30026, 29943, 29860, 29775, 29689, 29603, - 29515, 29427, 29337, 29247, 29156, 29064, 28971, 28877, - 28782, 28687, 28590, 28492, 28394, 28294, 28194, 28093, - 27991, 27888, 27784, 27679, 27573, 27466, 27358, 27250, - 27140, 27030, 26919, 26806, 26693, 26579, 26464, 26349, - 26232, 26114, 25996, 25876, 25756, 25635, 25512, 25389, - 25265, 25140, 25015, 24888, 24761, 24632, 24503, 24373, - 24242, 24110, 23977, 23843, 23708, 23573, 23436, 23299, - 23161, 23022, 22882, 22741, 22599, 22457, 22313, 22169, - 22024, 21878, 21731, 21583, 21435, 21285, 21135, 20984, - 20832, 20679, 20525, 20370, 20215, 20059, 19901, 19743, - 19584, 19425, 19264, 19103, 18940, 18777, 18613, 18448, - 18283, 18116, 17949, 17781, 17612, 17442, 17271, 17100, - 16927, 16754, 16580, 16405, 16230, 16053, 15876, 15698, - 15518, 15339, 15158, 14976, 14794, 14611, 14427, 14242, - 14056, 13869, 13682, 13494, 13305, 13115, 12924, 12732, - 12540, 12346, 12152, 11957, 11761, 11564, 11366, 11168, - 10968, 10768, 10566, 10364, 10161, 9957, 9752, 9547, - 9340, 9132, 8924, 8714, 8503, 8292, 8079, 7866, - 7651, 7436, 7219, 7002, 6783, 6563, 6343, 6121, - 5897, 5673, 5448, 5221, 4993, 4764, 4533, 4301, - 4067, 3832, 3596, 3358, 3118, 2876, 2632, 2387, - 2139, 1888, 1635, 1379, 1119, 854, 583, 304 -}; - -const Word16 small_overlap_48[R2_48/7]= -{ - 429, 1286, 2143, 2998, 3851, 4702, 5549, 6393, - 7232, 8066, 8895, 9717, 10533, 11342, 12142, 12935, - 13719, 14493, 15257, 16011, 16754, 17485, 18205, 18912, - 19606, 20286, 20953, 21605, 22243, 22865, 23472, 24062, - 24636, 25193, 25733, 26255, 26760, 27246, 27713, 28161, - 28590, 28999, 29389, 29758, 30107, 30435, 30743, 31029, - 31294, 31538, 31760, 31960, 32138, 32295, 32429, 32541, - 32631, 32698, 32743, 32765 -}; - -const Word16 small_overlap_25[R2_25/7]= -{ - 804, 2411, 4011, 5602, 7180, 8740, 10279, 11793, - 13279, 14733, 16151, 17531, 18868, 20160, 21403, 22595, - 23732, 24812, 25833, 26791, 27684, 28511, 29269, 29957, - 30572, 31114, 31581, 31972, 32286, 32522, 32679, 32758 -}; - -const Word16 small_overlap_int[R2_16/7]= -{ - 2571, 5126, - 7650, 10126, 12540, 14876, 17121, 19261, 21281, 22865, - 23472, 24917, 26510, 27939, 29197, 30274, 31164, 31863, - 32365, 32667 -}; - - -const Word16 half_overlap_48[3*R2_48/7]= -{ - 143, 429, - 715, 1001, 1286, 1572, 1858, 2143, 2428, 2713, - 2998, 3283, 3567, 3851, 4135, 4419, 4702, 4985, - 5267, 5549, 5831, 6112, 6393, 6673, 6953, 7232, - 7510, 7788, 8066, 8343, 8619, 8895, 9169, 9444, - 9717, 9990, 10262, 10533, 10803, 11073, 11342, 11609, - 11876, 12142, 12408, 12672, 12935, 13197, 13458, 13719, - 13978, 14236, 14493, 14749, 15004, 15257, 15510, 15761, - 16011, 16260, 16508, 16754, 16999, 17243, 17485, 17727, - 17966, 18205, 18442, 18678, 18912, 19145, 19376, 19606, - 19834, 20061, 20286, 20510, 20732, 20953, 21172, 21390, - 21605, 21820, 22032, 22243, 22452, 22659, 22865, 23069, - 23271, 23472, 23670, 23867, 24062, 24255, 24447, 24636, - 24824, 25010, 25193, 25375, 25555, 25733, 25909, 26083, - 26255, 26426, 26594, 26760, 26924, 27086, 27246, 27403, - 27559, 27713, 27864, 28014, 28161, 28306, 28449, 28590, - 28729, 28865, 28999, 29131, 29261, 29389, 29514, 29637, - 29758, 29877, 29993, 30107, 30219, 30328, 30435, 30540, - 30643, 30743, 30840, 30936, 31029, 31120, 31208, 31294, - 31378, 31459, 31538, 31614, 31688, 31760, 31829, 31896, - 31960, 32022, 32081, 32138, 32193, 32245, 32295, 32342, - 32387, 32429, 32469, 32506, 32541, 32573, 32603, 32631, - 32655, 32678, 32698, 32715, 32730, 32743, 32753, 32760, - 32765, 32767 -}; - -const Word16 half_overlap_25[3*R2_25/7]= -{ - 268, 804, 1340, 1876, 2411, 2945, 3479, 4011, - 4543, 5073, 5602, 6130, 6655, 7180, 7702, 8222, - 8740, 9255, 9768, 10279, 10786, 11291, 11793, 12292, - 12787, 13279, 13767, 14252, 14733, 15210, 15683, 16151, - 16616, 17075, 17531, 17981, 18427, 18868, 19304, 19735, - 20160, 20580, 20994, 21403, 21806, 22204, 22595, 22980, - 23359, 23732, 24099, 24459, 24812, 25159, 25499, 25833, - 26159, 26478, 26791, 27096, 27394, 27684, 27967, 28243, - 28511, 28771, 29024, 29269, 29506, 29736, 29957, 30170, - 30375, 30572, 30761, 30942, 31114, 31278, 31434, 31581, - 31720, 31850, 31972, 32085, 32190, 32286, 32373, 32452, - 32522, 32583, 32635, 32679, 32714, 32741, 32758, 32767 -}; - -const Word16 half_overlap_int[3*R2_16/7]= -{ - 858, 1715, 2571, 3425, 4277, 5126, - 5971, 6813, 7650, 8481, 9307, 10126, 10938, 11743, - 12540, 13328, 14107, 14876, 15636, 16384, 17121, 17847, - 18560, 19261, 19948, 20622, 21281, 21926, 22556, 23069, - 23271, 23769, 24351, 24917, 25466, 25997, 26510, 27005, - 27482, 27939, 28378, 28797, 29197, 29576, 29935, 30274, - 30592, 30888, 31164, 31419, 31651, 31863, 32052, 32219, - 32365, 32488, 32588, 32667, 32723, 32757 -}; - - -/*----------------------------------------------------------------------------------* - * SC-VBR - *----------------------------------------------------------------------------------*/ - -const Word16 bp1_num_coef_wb_fx[5]= { 15286, 0, -30572, 0, 15286, }; /* Q14 */ - -const Word16 bp1_den_coef_wb_fx[5]= { 16384, 0, -30498, 0, 14262, }; /* Q14 */ - - - -const Word16 shape1_num_coef_fx[11]= /* Q15 */ -{ - 31437, -2443, -13636, 4316, - -10188, 48, 2639, -3575, - -776, 1046, 399 -}; - - -const Word16 shape1_den_coef_fx[11]= { 32767, /* Q15 */ - 2940, -12237, 4032, -9609, - -1998, 2335, -3900, -1595, - 857, 253 - }; - -const Word16 shape2_num_coef_fx[11]= /* Q15 */ -{ - 30760, 31, -9699, 9516, - -5878, -7249, -10468, 442, - 3278, -63, 1115 -}; - - -const Word16 shape2_den_coef_fx[11]= { 32767, /* Q15 */ - 16019, -890, 12799, 2346, - -6985, -13192, -5795, -949, - -1492, -304 - }; - - -const Word16 shape3_num_coef_fx[11]= /* Q15 */ -{ - 30685, -383, -9937, -9605, - -5997, 7611, -10393, -355, - 3239, 12, 1196 -}; - - -const Word16 shape3_den_coef_fx[11]= { 32767, /* Q15 */ - -16498, -911, -12947, 2286, - 7430, -13385, 6066, -1182, - 1580, -273 - }; - - - -const Word16 txlpf1_num_coef_fx[11] = /* Q13 */ -{ - 138, 198, 514, 681, 921, - 964, 921, 681, 514, 198, - 138, -}; - - - -const Word16 txlpf1_den_coef_fx[11] = /* Q13 */ -{ - 8192,-18945, 31613,-31149, 24494, - -12753, 5528, -1436, 347, -25, - 4, -}; - - - -const Word16 txhpf1_num_coef_fx[11] = /* Q13 */ -{ - 138, -198, 514, -681, 921, - -964, 921, -681, 514, -198, - 138, -}; - - -const Word16 txhpf1_den_coef_fx[11] = /* Q13 */ -{ - 8192, 18945, 31613, 31149, 24494, - 12753, 5528, 1436, 347, 25, - 4, -}; - -/* NELP filter coefficients */ - -/*BP1_ORDER = 7; */ -const Word16 bp1_num_coef_nb_fx_order7[8] = -{ - /* Q = BP1_COEF_NB_QF_ORDER7 = 13 */ - 1481, 6730, 15579, 22923, 22923, 15579, 6730, 1481, - -}; -const Word16 bp1_den_coef_nb_fx_order7[8] = -{ - /* Q = BP1_COEF_NB_QF_ORDER7 = 13 */ - 8192, 16156, 23814, 21855, 14620, 6614, 1907, 268, -}; - - -/* NELP gain tables */ - -const Word16 UVG1CB_WB_FX[UVG1_CBSIZE][2] = /* Q13 */ -{ - { -2224, -2114, }, - { 12666, 12314, }, - { 3723, 9690, }, - { 17880, 17978, }, - { 4136, 3946, }, - { 11605, 21280, }, - { 9777, 9340, }, - { 21701, 21627, }, - { 1088, 1679, }, - { 13993, 13697, }, - { 10443, 5214, }, - { 19702, 19692, }, - { 5458, 5317, }, - { 17051, 16918, }, - { 14206, 8503, }, - { 24330, 24271, }, - { -118, -279, }, - { 11615, 14863, }, - { 6898, 6544, }, - { 18913, 18637, }, - { 1142, 6811, }, - { 15995, 16070, }, - { 6921, 13182, }, - { 22857, 22741, }, - { 3017, 2260, }, - { 14952, 14992, }, - { 8176, 8093, }, - { 20721, 20549, }, - { 7441, 2370, }, - { 17897, 13988, }, - { 10986, 10966, }, - { 26098, 25992, }, -}; - -const Word16 UVG1CB_NB_FX[UVG1_CBSIZE][2] = /* Q13 */ -{ - { -4791, -5157, }, - { 4824, 4937, }, - { -3443, 3610, }, - { 5539, 15293, }, - { -469, -3986, }, - { 7977, 8157, }, - { 2748, 2492, }, - { 14070, 14014, }, - { -2486, -2863, }, - { 6033, 5892, }, - { 2678, -441, }, - { 11741, 11804, }, - { -256, -847, }, - { 9153, 8922, }, - { -106, 5979, }, - { 16876, 16741, }, - { -3584, -3873, }, - { 3511, 9538, }, - { 401, 416, }, - { 11082, 10550, }, - { -1418, -1725, }, - { 8988, 5255, }, - { 6275, 1137, }, - { 15372, 15247, }, - { -3899, 301, }, - { 6976, 7095, }, - { 1581, 1453, }, - { 12988, 12824, }, - { 2692, -3093, }, - { 9778, 10153, }, - { 3938, 3628, }, - { 18823, 18695, }, -}; - -const Word16 UVG2CB1_WB_FX[UVG2_CBSIZE][5] = /* Q12 */ -{ - { 914, 990, 1490, 5954, 2618, }, - { 5599, 4621, 4078, 3493, 3057, }, - { 4930, 4031, 2999, 2150, 1706, }, - { 7722, 3021, 1804, 1478, 1452, }, - { 1171, 1390, 6895, 2592, 1486, }, - { 4155, 4287, 4409, 4515, 4577, }, - { 3633, 3661, 3694, 3711, 3736, }, - { 13212, 5009, 2611, 2175, 2048, }, - { 3716, 2887, 2253, 1965, 1723, }, - { 7141, 4567, 3434, 2970, 2396, }, - { 2856, 3038, 3259, 3481, 3709, }, - { 5929, 5459, 4923, 4448, 4084, }, - { 980, 1024, 1550, 5686, 8038, }, - { 3516, 7354, 10392, 3619, 2856, }, - { 2598, 3093, 3582, 4780, 5965, }, - { 1962, 10993, 5020, 2861, 2587, }, - { 796, 916, 1010, 1175, 7720, }, - { 4445, 4406, 4344, 4249, 4175, }, - { 1454, 6493, 2611, 1758, 1765, }, - { 6296, 7686, 4763, 2945, 2203, }, - { 1502, 1573, 1895, 2981, 5464, }, - { 4750, 4829, 4909, 4929, 4895, }, - { 3644, 3774, 3922, 4037, 4116, }, - { 9051, 7403, 6003, 4746, 4081, }, - { 1558, 1869, 2331, 3000, 3595, }, - { 4671, 4646, 4614, 4553, 4482, }, - { 2262, 2608, 3158, 3890, 4468, }, - { 5556, 5441, 6824, 7146, 5724, }, - { 1470, 1550, 2016, 11169, 3828, }, - { 5488, 6270, 6771, 8202, 9281, }, - { 3477, 3693, 4113, 4460, 4705, }, - { 10877, 17984, 10194, 7291, 2824, }, - { 1327, 1498, 1476, 1667, 2138, }, - { 4463, 4299, 4094, 3880, 3731, }, - { 3188, 3164, 3156, 3104, 3140, }, - { 9757, 5690, 3366, 2296, 1792, }, - { 1731, 1753, 12406, 4082, 2247, }, - { 3866, 4060, 5007, 5274, 5225, }, - { 3998, 3957, 3900, 3839, 3789, }, - { 18040, 9417, 5567, 3465, 2504, }, - { 2160, 2532, 2895, 2577, 2321, }, - { 5052, 4789, 4490, 4203, 3953, }, - { 3381, 3415, 3458, 3496, 3536, }, - { 6166, 5811, 5440, 5035, 4650, }, - { 2839, 3389, 5057, 7558, 10414, }, - { 3875, 4431, 5183, 6310, 7166, }, - { 4311, 4130, 3571, 3070, 8555, }, - { 8791, 8260, 7299, 6243, 5421, }, - { 1191, 1237, 1368, 1814, 11819, }, - { 2486, 5729, 6150, 4222, 3667, }, - { 4018, 3825, 3600, 3388, 3256, }, - { 7504, 5817, 4989, 4065, 3322, }, - { 1430, 1962, 5546, 4096, 4681, }, - { 5393, 5378, 5324, 5230, 5052, }, - { 4041, 4090, 4132, 4159, 4181, }, - { 12469, 9221, 5735, 3617, 2501, }, - { 2482, 2565, 2768, 3088, 3461, }, - { 5209, 5080, 4905, 4706, 4522, }, - { 3139, 3362, 3647, 3910, 4156, }, - { 7139, 6588, 5941, 5251, 4674, }, - { 1719, 1866, 7993, 7634, 3987, }, - { 3587, 5289, 7882, 13519, 16095, }, - { 2409, 2515, 2749, 7316, 4636, }, - { 30391, 18493, 13798, 4799, 2283, }, -}; - -const Word16 UVG2CB2_WB_FX[UVG2_CBSIZE][5] = /* Q12 */ -{ - { 1565, 1391, 1635, 5228, 2681, }, - { 2156, 2558, 6205, 5561, 3944, }, - { 2039, 2406, 3094, 3409, 3968, }, - { 5090, 5065, 4989, 4858, 4764, }, - { 1436, 1736, 2816, 2362, 2400, }, - { 4375, 4425, 4465, 4478, 4493, }, - { 4648, 4081, 3550, 2981, 2667, }, - { 1705, 1950, 3679, 7828, 9895, }, - { 2839, 1826, 1443, 1210, 1245, }, - { 1387, 1410, 1768, 8873, 4383, }, - { 4022, 3784, 3565, 3316, 3096, }, - { 9983, 7147, 5225, 3742, 3027, }, - { 6769, 2357, 1531, 1448, 1556, }, - { 4591, 4671, 4735, 4765, 4789, }, - { 4308, 4198, 4052, 3896, 3769, }, - { 2288, 2550, 4922, 8294, 14878, }, - { 1361, 1480, 1511, 1991, 10450, }, - { 2933, 3131, 3694, 4687, 5201, }, - { 3984, 3048, 2479, 2644, 5514, }, - { 5353, 5480, 5488, 5434, 5437, }, - { 3319, 2881, 2528, 2152, 1927, }, - { 4873, 4748, 4578, 4407, 4257, }, - { 6185, 4396, 3751, 3400, 2899, }, - { 2159, 8067, 7534, 5121, 3640, }, - { 2265, 10177, 3803, 2588, 2441, }, - { 2188, 2206, 4293, 12691, 5893, }, - { 3587, 3651, 3760, 3864, 3960, }, - { 13158, 9752, 7171, 5431, 5364, }, - { 5710, 4173, 2928, 2090, 1774, }, - { 3531, 3831, 4641, 5787, 6622, }, - { 4395, 4356, 4281, 4194, 4111, }, - { 2243, 2476, 5814, 3965, 27176, }, - { 1575, 1667, 7544, 3005, 1984, }, - { 2583, 2511, 11684, 5765, 4807, }, - { 3632, 3458, 3277, 3114, 2971, }, - { 8569, 6778, 5866, 5515, 5141, }, - { 3267, 3035, 2940, 2782, 2691, }, - { 3929, 4249, 4577, 4877, 5162, }, - { 4443, 4173, 3864, 3590, 3337, }, - { 3998, 4725, 5728, 6873, 7885, }, - { 4369, 2824, 2237, 1648, 1404, }, - { 1000, 1022, 1477, 2682, 15276, }, - { 3916, 3851, 3766, 3664, 3591, }, - { 13206, 4485, 3230, 3897, 3648, }, - { 10002, 3515, 2393, 2233, 2211, }, - { 4603, 4836, 5071, 5259, 5411, }, - { 3919, 4035, 4177, 4304, 4419, }, - { 3046, 8332, 16475, 11172, 10858, }, - { 1027, 1007, 1196, 1578, 5937, }, - { 1892, 2422, 3227, 3920, 7400, }, - { 3584, 3532, 3508, 3470, 3437, }, - { 5363, 6155, 6805, 6854, 6811, }, - { 4038, 3512, 3030, 2636, 2332, }, - { 6760, 6124, 5235, 4299, 3687, }, - { 4125, 6528, 4068, 3238, 3483, }, - { 5020, 5905, 7082, 8554, 9623, }, - { 1399, 5868, 3069, 1726, 1655, }, - { 4691, 4234, 3974, 3757, 9616, }, - { 3978, 4003, 4003, 3983, 3960, }, - { 2103, 16858, 9252, 4860, 4727, }, - { 8043, 5294, 3970, 3098, 2583, }, - { 4680, 5109, 5576, 5965, 6275, }, - { 4867, 4584, 4276, 3958, 3682, }, - { 1213, 3115, 6552, 22778, 20977, }, -}; - - -const Word16 UVG2CB1_NB_FX[UVG2_CBSIZE][5] = /* Q12 */ -{ - { 773, 785, 785, 785, 860, }, - { 3560, 3521, 3410, 3265, 3167, }, - { 1766, 2982, 10273, 3790, 2248, }, - { 4986, 4753, 4496, 4172, 3922, }, - { 2036, 2030, 2009, 1973, 1897, }, - { 3291, 3554, 3868, 4126, 4345, }, - { 3207, 3122, 3026, 2913, 2797, }, - { 13220, 6844, 3967, 2746, 2466, }, - { 1553, 1627, 1392, 1766, 3679, }, - { 5379, 4640, 3844, 3254, 2635, }, - { 1600, 1622, 2430, 9446, 4214, }, - { 5115, 5200, 5311, 5365, 5343, }, - { 6229, 3008, 1989, 1622, 1597, }, - { 1726, 2114, 7046, 6162, 4301, }, - { 1004, 1056, 1841, 6006, 7101, }, - { 6388, 9659, 4510, 2774, 2113, }, - { 1060, 1153, 1400, 1733, 2121, }, - { 3448, 3523, 3612, 3683, 3770, }, - { 1496, 2045, 2910, 3563, 4058, }, - { 4419, 4592, 4795, 4921, 4978, }, - { 1407, 5314, 2788, 1675, 1350, }, - { 4210, 4225, 4227, 4186, 4169, }, - { 2247, 8245, 4392, 2522, 1709, }, - { 7211, 6741, 6110, 5397, 4680, }, - { 3602, 2286, 1577, 1229, 1148, }, - { 6674, 5227, 3576, 2448, 1901, }, - { 954, 1035, 1079, 1683, 9558, }, - { 4011, 5853, 8979, 7138, 4484, }, - { 2784, 2702, 2637, 2546, 2471, }, - { 4414, 4065, 4627, 4208, 9275, }, - { 2771, 3012, 3357, 3735, 4066, }, - { 19742, 8603, 3943, 2546, 2085, }, - { 1132, 1123, 1107, 1093, 1114, }, - { 3913, 3838, 3733, 3630, 3548, }, - { 948, 1565, 6063, 2654, 1667, }, - { 6159, 5567, 4884, 4241, 3770, }, - { 925, 1164, 1585, 6062, 3090, }, - { 3818, 4037, 4322, 4536, 4726, }, - { 4291, 3894, 3441, 3006, 2733, }, - { 8544, 6487, 4962, 3812, 2970, }, - { 1744, 1758, 1704, 1633, 1576, }, - { 4416, 4259, 4044, 3810, 3628, }, - { 1919, 2159, 3323, 13977, 7898, }, - { 5952, 5731, 5419, 5061, 4732, }, - { 2775, 2812, 2507, 2540, 6585, }, - { 3436, 3960, 4661, 5975, 6274, }, - { 3082, 3150, 3246, 3337, 3404, }, - { 4089, 16018, 8285, 4116, 2704, }, - { 1419, 1425, 1400, 1371, 1363, }, - { 3825, 3890, 3953, 3993, 4015, }, - { 2498, 2689, 2846, 3011, 3213, }, - { 5122, 5024, 4881, 4691, 4524, }, - { 2285, 2325, 2317, 2313, 2271, }, - { 4493, 4529, 4517, 4478, 4443, }, - { 9138, 3969, 2522, 2222, 2415, }, - { 10009, 8719, 7292, 5837, 4532, }, - { 831, 908, 1039, 1656, 6813, }, - { 2070, 5478, 5174, 3911, 3694, }, - { 1577, 1565, 1635, 2583, 13154, }, - { 5590, 5788, 5922, 6752, 7063, }, - { 4061, 3497, 2710, 2099, 1716, }, - { 2750, 3118, 16574, 7891, 3651, }, - { 2598, 3072, 3809, 4906, 5172, }, - { 15348, 10948, 7740, 4979, 3446, }, -}; - -const Word16 UVG2CB2_NB_FX[UVG2_CBSIZE][5]= /* Q12 */ -{ - { 961, 867, 812, 771, 775, }, - { 2544, 2686, 3010, 3605, 5048, }, - { 1524, 1818, 2889, 3029, 3046, }, - { 4195, 4301, 4421, 4497, 4580, }, - { 2026, 1990, 1965, 1943, 1939, }, - { 4338, 4156, 3963, 3750, 3590, }, - { 7732, 2904, 1804, 1407, 1513, }, - { 1613, 2353, 11315, 5764, 4291, }, - { 1519, 1462, 1434, 1341, 1294, }, - { 1627, 1710, 2163, 9654, 5615, }, - { 2322, 7293, 3251, 2020, 2066, }, - { 4967, 5112, 5174, 5203, 5230, }, - { 1590, 1449, 1943, 5947, 3563, }, - { 7747, 5170, 3268, 2392, 2082, }, - { 3970, 3559, 3164, 2774, 2493, }, - { 1993, 2210, 3204, 3717, 23534, }, - { 1185, 1236, 1423, 2115, 4772, }, - { 3935, 3840, 3714, 3583, 3477, }, - { 1640, 1550, 1800, 2609, 10880, }, - { 4067, 4437, 4811, 5108, 5536, }, - { 1472, 1367, 1533, 2132, 7352, }, - { 4310, 4284, 4216, 4117, 4057, }, - { 10817, 4587, 2611, 2066, 2037, }, - { 2089, 2427, 4698, 14635, 7517, }, - { 2529, 1561, 1209, 976, 945, }, - { 2908, 3070, 4055, 5862, 6448, }, - { 2676, 2861, 3115, 3295, 3408, }, - { 2932, 14330, 6533, 3739, 3462, }, - { 3681, 3079, 2559, 2151, 1903, }, - { 5636, 5316, 4978, 4690, 4425, }, - { 2298, 7228, 6976, 4251, 3347, }, - { 2504, 3421, 6784, 8483, 15064, }, - { 1253, 1180, 1136, 1094, 1076, }, - { 3451, 3524, 3600, 3646, 3707, }, - { 1701, 2030, 6574, 4746, 4451, }, - { 4688, 4751, 4762, 4727, 4722, }, - { 2977, 2363, 1883, 1563, 1399, }, - { 5080, 4685, 4275, 3835, 3513, }, - { 5445, 3828, 2851, 2242, 1948, }, - { 1929, 5037, 17760, 8346, 6300, }, - { 1839, 1782, 1680, 1586, 1534, }, - { 3086, 3472, 4031, 4950, 9695, }, - { 3199, 3052, 2896, 2751, 2622, }, - { 5822, 5782, 5727, 5566, 5478, }, - { 1548, 2234, 6748, 2562, 1722, }, - { 6699, 5216, 4475, 3531, 3028, }, - { 3773, 3628, 3460, 3279, 3155, }, - { 1581, 1672, 2929, 20221, 16432, }, - { 1210, 1215, 1389, 1678, 2177, }, - { 3863, 3886, 3937, 3961, 3989, }, - { 1541, 1745, 1829, 3479, 15563, }, - { 4444, 4952, 5573, 6056, 6545, }, - { 2460, 2397, 2284, 2133, 2041, }, - { 4808, 4676, 4493, 4322, 4213, }, - { 15031, 6644, 3315, 2900, 2885, }, - { 4003, 4760, 6946, 8274, 8401, }, - { 5001, 2495, 1594, 1337, 1365, }, - { 3428, 3706, 4073, 4457, 4670, }, - { 3326, 3277, 3222, 3142, 3088, }, - { 6162, 6317, 6494, 6459, 6530, }, - { 2659, 2599, 2537, 2482, 2546, }, - { 8554, 6902, 5233, 4116, 3650, }, - { 4643, 4099, 3616, 3201, 2895, }, - { 9589, 26630, 15412, 12532, 8715, }, -}; - - -const Word16 frac_4sf_fx[NB_SUBFR+2]= {4,8,12,16,16,16}; /* Q4 */ - -/* ERB table for PPP-ampl-quant */ - -/* ERB table for PPP-ampl-quant */ -const Word16 erb_WB_fx[NUM_ERB_WB+1]= {0, 238, 475, 713, 950, 1188, 1426, 1663, 1911, 2185, 2490, 2826, 3205, 3624, 4094, 4620, 5210, 5875, 6626, 7478, 8448, 9558, 11264, 13568, 16387}; - - -/* ERB table for PPP-ampl-quant */ -const Word16 erb_NB_fx[NUM_ERB_NB+1]= {0, 238, 475, 713, 950, 1188, 1426, 1663, 1911, 2185, 2490, 2826, 3205, 3624, 4094, 4620, 5210, 5875, 6626, 7478, 8448, 9558, 10243}; - - -const Word16 AmpCB1_WB_fx[640] = -{ - 5655, 1589, -653, 3568, -3173, -1852, -3204, -4623, -2100, -5103, - -923, -67, -7152, -4958, -2019, -1810, -8532, -648, 6581, 8043, - 160, 778, -1535, 863, 5482, 1674, -3576, 123, -3163, -3595, - -852, -53, -1080, -2683, -3199, -950, -1353, 6258, -1431, 1249, - 2059, 677, 146, 1011, 956, -2022, -25, 300, 421, -5859, - 1027, -452, -7343, -1052, 3818, 1099, -1005, 659, -511, -658, - 2091, 720, -600, 145, -1504, -1716, -442, -2172, -1505, 2702, - 731, 1473, -213, -4120, -2976, 688, 3205, 1213, 679, 232, - 3672, 4770, -1198, -298, -1714, -3669, -2833, -664, -1859, -2380, - -1169, -1593, -453, 295, -1225, -3110, -1776, 2112, 2710, 3333, - 1022, 1248, 1091, 1164, 1200, 1782, -809, -2306, -3124, -2194, - -1567, 465, 2223, -1301, -463, -2157, 729, 2279, -1938, 610, - 437, -803, -1025, 775, -171, -637, 163, 2251, 316, -1663, - -4123, -20, -2827, -1529, -1436, 3447, 79, -274, 1650, 4097, - 2369, 927, 448, -449, 293, -239, -1028, -4805, 1354, 431, - -2219, -490, -3849, 1639, -2925, 817, 1485, 2527, 5444, -1994, - 1476, 506, -1643, 2003, -1676, -788, -1681, -2011, 1389, 452, - 593, 3, -1200, -3987, -1634, -4310, -686, 882, 6235, 2420, - -196, -1257, -2038, -498, 1394, 671, -2302, -809, -446, 3644, - -1643, -2304, -828, 105, -323, -3906, -960, 7324, 3095, -786, - 95, 633, 1266, 750, 1509, -2033, -3134, 432, 1028, -1825, - 1258, 256, -3249, -6868, -523, -325, -1779, 4313, 2524, 3433, - -600, -410, -88, 410, -1182, -1140, -1448, -1344, -5074, 6054, - 2194, 1505, -681, -2408, 1376, 1389, 1209, 1048, -4199, -2939, - 1855, 1744, -1344, -1431, -1955, -1805, -4992, 512, 624, 2749, - -3446, -1215, -3764, -2169, -3601, -1321, 67, 4326, 6624, 5816, - -334, -1746, -441, -754, 1853, 3889, -595, -493, 441, -811, - -48, -764, -1473, -683, 603, -1754, 780, 698, 1084, 1713, - 560, -808, -754, -2890, -1205, -318, -1021, 3195, 5693, -4603, - 1343, -1061, -2441, -1784, 721, 267, 227, -622, 3013, -768, - -472, 90, 13, 290, 1055, 948, 1617, -2368, -1087, 1103, - -4784, -3872, 5125, -2518, -215, 6962, 1095, -1521, 2091, -2962, - 2285, 1117, 1174, 2635, -1907, -1012, 814, -417, -2162, -2805, - -1188, -707, -808, -1757, 260, -1093, -3957, -3266, 4132, 5980, - 177, -1478, 960, 2029, 3989, 597, -3062, -3940, -1688, 236, - -1559, 150, 2432, 348, -242, -2014, -1027, 6298, -2957, -3960, - 1090, 1014, -1261, -744, -954, -938, -3713, -3272, 5356, -2356, - -1439, 3808, -2330, -4437, 5177, -3606, -1382, 1824, 407, 325, - 649, 330, 85, 206, -415, 183, -646, 602, -2656, 808, - 1039, 29, -3202, -6168, -3640, 3736, 4183, 3959, 330, 339, - 2701, 343, 1501, 1879, -3194, -4648, -1630, 1656, -1578, -84, - -3065, -4126, 24, -260, 263, -1705, -1289, 2432, 1229, 7481, - 2586, 1696, 646, -1773, -792, 1932, -1908, -1897, -1129, 112, - -5667, -1592, 2253, -980, 1581, 211, 5277, 4846, -288, -159, - 956, 1196, 771, -973, -1785, -516, -1015, 847, 614, -791, - -442, -1594, -4632, -4392, -416, 1398, 2570, 752, 264, 6570, - 1655, 546, 1238, -1362, -1330, -2005, 3590, -2155, -184, -1224, - -1452, -1533, -534, 1010, -1707, 801, 3628, -289, 2414, 132, - 2643, -2813, -4524, 5092, -7362, 740, 428, -510, 81, -1209, - 616, 1454, 1861, -3958, -4084, 189, -1219, -875, 3764, 2086, - -1554, -2071, 1515, 3392, 12, -686, -2414, -1382, 176, 1685, - 2055, -5698, 1582, 4117, -4846, -2922, 610, 2082, 4682, -2487, - 348, 2258, -338, -1379, 1472, 618, -202, -1122, -76, -2468, - -1216, -986, -327, -1441, 102, 403, -2105, 2411, 1510, 1288, - -715, -577, 1074, 2533, -3521, -3449, 2140, -751, -307, 3805, - 158, -1385, -404, -1378, -1948, 3785, 4216, 2667, -1894, -1559, - 1037, 1371, 989, -205, -333, -4784, -3429, -1283, 3299, 859, - -4922, -5481, -1196, -1748, -720, 516, 113, 4590, 7071, 4345, - -5729, -3862, 3590, 1463, 7094, 4991, 854, -66, -1630, -686, - -923, -3266, -1988, 2345, 785, -1420, 3004, 2934, -1245, -65, - -2696, -3088, -1438, 614, 1584, -239, -1552, 580, 6285, -1673, - -1598, -4018, -1909, 747, 3191, 366, 1467, -1933, 2759, 2804, - 518, 193, -1149, -3108, 441, 1458, 2791, -4131, 2694, 3372, - -5023, -6491, 1794, 2739, 1463, 5843, 2869, 1993, -1409, 4832 -}; - -const Word16 pwf78_fx[17]= { 25559, 19936, 15550, 12129, 9460, 7379, 5755, 4489, - 3501, 2731, 2130, 1661, 1296, 1011, 788, 615, - 479 - }; /* 0.78^i (i=1,...,17), Q15 */ - - - - -const Word16 AmpCB2_WB_fx[64*(NUM_ERB_WB-13)]= -{ - -5276, -7711, -3518, -2416, -382, 319, -1900, -900, 1725, 884, - 4071, -4052, -2430, -336, 2136, 3006, 591, -3893, -2731, 2625, - 2390, -1047, -883, -3368, -4235, -3726, 189, -1803, 784, 2336, - 206, -2140, 3001, -730, -2279, 85, -3395, 4367, 2214, -254, - -3114, -2348, 2763, 686, -7495, -6618, 3164, -3957, -2681, -2049, - 1659, 3634, 2962, 1574, 379, -2478, 2861, 616, 1124, 205, - -3075, -348, -2006, -90, 761, 1157, -114, -9460, -2786, -3254, - -1120, -1500, -446, 2835, -314, 3205, 2115, -837, -261, 36, - 80, -485, 1133, 2124, -1031, -401, -3166, 1145, -1616, -3425, - -3071, -6891, -4198, 2292, 5160, -46, 1430, 280, 1378, 1700, - -1673, -1126, 5270, 5096, -975, -1070, 1314, -2389, -2982, 20, - -3218, -892, -636, -876, -302, -2923, -3240, 4121, 1625, -557, - 994, 544, 2657, 7133, -273, -3530, -1419, 1431, -936, -2622, - 303, 75, -5444, -5549, 4183, 1248, 3474, -789, 2375, -1778, - 1660, 1520, -1433, -4047, 531, 7001, 695, 1889, 4261, -2791, - -1557, -2980, -316, 415, 1134, 1501, -6923, 521, -3134, -1812, - 1848, 676, -1733, 734, 2207, 2029, -476, -1976, -161, 29, - 7147, -1774, 720, -1070, -372, -1626, -6473, -2448, -5235, -2651, - -1800, -1477, -767, 1335, 471, 4857, 888, 593, -370, 196, - 907, 174, 557, -720, -1339, 1590, 37, -1247, -1307, 276, - -1739, -6032, -3088, -2499, -497, -393, -569, 3003, 2694, 3751, - 4652, -258, -1305, 175, 189, -344, -2381, -1992, 463, 529, - -6375, 3966, -3558, -3001, -640, 3117, 1120, 966, 1316, -561, - 27, 2794, 2831, 3512, 3453, -418, -2319, -6741, -3443, 80, - 1281, 1691, 1500, -591, -739, 2385, -4676, -5822, -1437, 730, - 3593, -437, 1090, 3497, -1932, 2854, 4858, 2654, 947, 1879, - -4115, 2700, -3092, -1524, 225, -8272, -6736, -1277, 2991, 2983, - 1129, -1661, 2817, 468, 491, -744, 390, 677, 8129, -3130, - -687, -433, 1488, -3763, -177, -581, -764, 39, 1537, -2203, - -1678, 263, -1214, 2175, -1857, 3097, -894, 4207, -1943, -834, - 1513, -4123, 3981, 6041, 653, -757, -313, -3024, -4614, -3139, - -2966, 178, 4956, -427, -41, 2376, 1008, -1351, -92, 978, - 1998, 5146, 2069, 117, -1754, -2756, 4425, 168, -1807, -1761, - -1215, 178, -1562, -3369, -919, -2576, 3614, 4968, -30, -396, - -1151, -1146, 868, 1073, -359, 2732, 546, 4431, -321, -1081, - 1410, -3214, -2316, -4889, -2460, -3844, -7323, -1438, -1488, 1849, - 4037, 2421, 2697, -2372, -1877, 670, 3674, -907, 888, -3703, - 375, -1278, -1477, 2501, -936, -1682, -1353, -335, -4440, 383, - -2730, -2130, -1105, 1588, 3340, 4816, -4023, 502, -4146, 236, - 4481, 589, -3696, 826, -97, 222, -8037, -2244, 142, 810, - -2195, 1315, 656, 1901, -485, 317, 1512, 1465, -2026, 1853, - 929, 1670, -2736, -463, -836, -4946, -134, 2769, 2972, -5148, - -3147, 913, -1483, 267, -1560, 3903, 1507, 1105, -1496, 210, - -1196, 3764, 601, 1630, 3842, 6374, -1293, -4555, -3087, 199, - -1917, -3331, -2317, -1774, 479, 3712, 2729, 1309, -3047, -514, - 861, -213, 1317, -2035, 4369, 5228, 942, -3052, -2316, -3377, - 1123, -65, 2507, 2711, -2096, -2164, -2634, -5215, -3919, 1551, - -47, 1990, 2370, 2025, -2401, 4833, -3879, -162, -3081, 501, - -510, 2744, -907, 253, -1746, -2520, 3418, -1461, 2140, 2507, - 135, 1457, 3195, -1277, -2558, -66, 10850, -1633, -1051, -3436, - -1617, 1438, -1231, -1744, 696, -348, 3434, 2121, -1629, -2460, - -4065, 1159, -1288, 2843, 697, -862, 4, 966, -444, -1860, - 1450, 6426, 5544, 1456, -2826, -1303, -2778, -1278, -6656, -3241, - -7083, 2234, 204, 1753, 803, 499, 1641, 87, 1471, -1325, - 398, 2983, 4340, -1382, 735, -600, -4671, -254, 2327, -1008, - -144, -1453, -1806, -1669, 395, -3285, -1803, -2119, 1232, 2914, - 1480, 8610, 1788, 2644, 1359, 3783, -110, -1339, -1337, -3427, - -630, -1189, -2560, 976, 483, -2744, -3653, -1289, 2910, -2437, - 3171, 1479, 157, 823, 4631, -1910, 3736, -424, -155, -5470, - -741, 3829, -2794, -55, -1447, -3469, -1947, 2914, -61, -3430, - 3544, -1867, 2986, 1009, -1051, 725, 2933, 2926, 5849, 257, - -2666, 6286, -2282, -2998, -2576, -975, -3655, -1867, -5040, -1440, - 3542, -603, 4806, -2808, -1633, 1388, 1149, -1616, -1851, 2122, - 4477, 2485, 1376, 721, 2174, -3072, 1378, -2574, -37, 1322, - -1646, -3612, 4443, 1612, -3403, 711, 132, 119, -227, 5059, - 2892, 840, 5462, -3471, -1340, 2097, 143, 1750, -3052, -1932, - -6352, -4166, -645, 4317, 633, 3681, 2811, 2346, 2374, -2999, - -1265, -210, 5115, 4652, 1305, 3704, -1456, -307, -457, -1455, - -3580, 674, 2215, 2458, -3021, -66, 2535, -652, 1226, 685, - 875, -1753, -1164, -609, 3444, 563, 3826, 1607, 3798, 1385, - 3902, -1990, -4078, -2509 -}; - - -const Word16 AmpCB1_NB_fx[640] = -{ - -1355, 185, -222, -221, 1976, 3119, 540, 1333, -3646, -2511, - -979, 1664, 2087, 951, 787, -1687, -855, 1594, 1264, -4990, - -1957, -215, -850, 1369, -113, 2541, -2904, 743, 634, -657, - -3438, -2047, 706, 85, -596, -50, 212, 944, 118, 1380, - -1203, -78, -213, -1811, -781, -1970, 6607, -2971, 147, -1483, - 38, 5607, 5222, -4567, -4040, -2259, -3110, -2120, 932, -236, - -1052, 1039, -872, 334, -919, 2761, 3320, -5828, 53, 1063, - -1064, -75, -1015, -2137, -722, 565, 629, 1961, -454, 866, - -888, 2652, 1996, -2170, -885, 3325, -645, -1898, -984, -643, - -1008, 2472, 2400, -3708, -2408, -1051, 2029, 1357, -636, -470, - -1307, 655, 663, 29, 892, -95, -91, -2966, -1610, 2657, - -2175, -3170, -3799, -3065, 1130, 1351, 3814, 2791, 1478, 1520, - -1326, -520, -692, 899, 1979, -397, -407, 450, -569, -611, - -1228, 864, 2549, 3067, -2511, -4737, -2701, -304, 680, 1426, - -1070, -19, -1582, -2813, -1832, 3010, 250, -613, 3390, -171, - -1450, -417, -773, -651, -405, -2304, -780, 6656, -3270, -1322, - 70, 5105, 3202, -83, -925, -458, 1203, -1582, -4158, -3630, - -1702, -849, -55, -986, -1963, -1140, -1942, 3347, 3526, -435, - -1429, -2089, -1620, -1271, 2851, 2184, -2472, 3216, 2885, -2922, - -1217, 86, -186, -279, -746, 1288, 3016, -651, -2719, 317, - -1307, -127, -1110, 1389, 212, 1783, 2619, -1718, 1795, -4086, - -1295, 743, 301, -1823, -223, -651, -1774, -405, 1687, 2031, - -865, 1059, -391, 505, -2739, -2773, 16, -2960, 3071, 3325, - -791, 2301, 435, 107, -4039, 801, -1224, 1854, -1039, 507, - -518, 997, 837, 3311, 506, 1026, -232, -1920, -3904, 406, - -1857, -529, -776, -700, -663, -1520, 1699, 814, 2084, -477, - -1341, -1123, -2564, -2784, 2457, 3223, -959, 385, -1864, 3754, - -1351, -1347, -2229, -2882, -1061, -1499, -3028, 3302, 2250, 5539, - -957, -340, 27, 1508, 167, -3513, 1689, 2577, -1810, -516, - -1061, 2171, 1774, 2031, 923, -1933, -1640, -2881, 859, -834, - 408, 2462, 2073, 2107, -2671, 1140, -3497, -2497, 2984, -2707, - -1762, -2524, -2196, 279, -2580, 477, 2306, 4645, 693, -909, - -1089, 1952, 3034, -1790, 786, -1149, -3117, 3605, -1933, -1886, - -959, 934, 246, -2177, -2440, 1356, 871, 3472, 2558, -4512, - -782, 1262, 893, 1979, 2386, -1809, -4357, -392, -1928, 1576, - -1751, -327, -1018, -617, -2370, -2910, 4230, -90, -1361, 3596, - -1069, -315, -162, -339, -313, 33, 4684, 2811, -2717, -3684, - 695, 4567, -745, -2311, -776, -2600, -827, -1040, -997, 2480, - -1549, -748, -622, -260, 1460, 1116, -302, -2529, 2156, -42, - -1318, -568, -266, -446, -2212, 2690, -4669, 5325, -2022, 1358, - -1312, 2293, 1528, 706, 970, -291, 383, -683, -1532, -1843, - -1379, 845, 1218, 395, -1884, 14, 676, -1711, 795, 290, - -742, 386, -435, 411, 1311, 549, -4181, -4922, 1497, 4465, - -1722, -699, -1958, -4126, -3727, -655, 1553, 1793, 4933, 3055, - -1260, -618, 535, -2008, 3802, -3784, 2527, -833, 193, -1062, - -866, 823, 1562, 147, -623, -1808, -1099, 694, -577, 745, - -2282, -4139, -3171, 76, 25, -1077, 477, 545, 6081, 3244, - -1332, -785, 98, -1681, -3603, -3937, 524, 4648, 1114, 2547, - -1145, 407, 2030, 3120, -1739, -513, -518, 1325, -1700, -2860, - -1427, 520, -1040, -792, -366, -2174, -522, -240, 5660, -3163, - -1449, -1653, -1507, 581, 1338, -2627, -1863, 1831, 1301, 2106, - -1252, 974, 199, 68, -69, -869, 864, 2373, -5818, 2873, - 26, 972, 359, -561, -390, 376, 225, 517, 649, -1767, - -653, 2167, 882, -698, 214, -4084, -4134, 2092, 2798, -523, - -1002, 486, 648, -1082, 404, -1490, 1560, -4984, 5614, -1441, - -1024, -311, 427, 356, -2342, 215, -2312, 445, -2378, 5111, - -568, 85, 1328, 1847, 3506, 1183, -2521, -2070, -794, -1881, - -485, 1121, 1242, 1301, -4365, -2222, 2602, -387, 1498, -1344, - -1272, -1365, -2207, -213, -1877, 2858, 849, -915, 333, 2488, - -2019, -2048, -1461, -1930, -1409, -400, 490, -2222, 1276, 7305, - -1530, -1741, -2663, 3159, 1162, -1490, 1516, -1498, 1222, 838, - 1325, 5387, 3888, 1944, -1706, -2890, -1905, -3901, -3207, 206, - -1411, -959, -292, -396, -1547, -84, -4405, -1073, 5532, 1796, - 3160, 48, -2339, -5884, -184, -52, 129, 5398, 378, -321 -}; - -const Word16 AmpCB2_NB_fx[64*(NUM_ERB_NB-13)]= -{ - -2681, -4389, -4270, -4727, -239, 1938, 1748, 2311, 4300, -3957, - -1299, 3487, 1595, -377, 295, -1193, -1588, 2112, -1573, -6362, - -504, 1796, -2521, -68, 1322, 1223, 2263, -503, -3906, 3686, - -3899, -139, 2086, 48, 349, 547, -6387, 1340, -1467, -1062, - -193, 1325, -1190, 2394, 1671, -1982, -2597, -390, -1504, 2271, - -379, -2350, 4071, 70, -955, -883, -1770, -1065, -2443, -1779, - -1101, -661, 6325, 1871, -2673, 3596, 3773, -681, 3340, -1418, - 701, -4253, -3931, -1840, -2388, -2677, -3545, -41, 3675, 3843, - 2198, -1713, -324, 599, 1323, 1827, -4909, -1668, 616, 2608, - 360, -1769, -5263, -1278, 3490, 1935, 1355, -1298, 952, 1801, - 449, 251, -1021, -3666, 479, 3497, 1542, -2234, -3414, -4483, - -5785, 1406, 1207, 2984, 1767, 3262, -799, -3124, 5237, 460, - 2007, -1525, -2106, -770, 546, 137, 401, -1308, 969, 204, - -1626, -589, -4257, 1744, 2836, 2383, 2740, -423, 3166, 1920, - -690, -3000, -4489, 2523, -6693, -5135, -739, -1919, 1228, 2354, - 3340, 1902, 1069, -3185, -2614, 2764, -212, -2061, -1377, 698, - 3694, -125, -954, -4132, -404, 4297, 1294, 1765, 2446, -2287, - -1387, -14, 508, 1149, 9, -437, 519, -420, 450, -751, - -1632, -1391, -2208, -1955, -1170, 4818, 1112, 1086, -782, 1337, - 846, -3434, 569, 1721, -776, -2723, 1207, 982, -1432, -887, - 315, -3031, 3452, 765, -1263, -2146, 2959, -2619, 1507, 1312, - 4087, 3125, 1637, -1402, -45, -3193, 1397, -2611, -3641, -2478, - -1706, 588, 199, 3721, 1217, -1249, -1196, 7228, 996, 879, - -1339, 11, -971, -1680, 716, -39, 233, 1945, 1548, -1476, - 550, -2277, 307, 7413, 2094, -1631, -569, -1351, -198, -483, - -515, -1347, -212, -2649, -519, 195, 2944, -795, 1470, 654, - -1448, 3156, 1369, 3966, 3382, -2782, -4255, -1157, -212, 392, - 861, 5064, 4740, -2513, -3413, -552, -2298, -575, 1130, 1178, - 1568, 4591, 1238, 367, 1626, 600, -5889, 163, -3742, -3650, - -3911, 716, 919, -1501, 55, 1807, 3801, -5571, -4635, 1225, - 3211, 3804, 1491, -906, 100, 404, -1742, -1878, -2140, 1651, - 1640, 3976, -3432, -1149, 1365, 2042, 392, 768, -1534, 1096, - 3811, -211, -2067, -1315, -4167, 1145, -2747, -149, 5296, -735, - 438, 56, -404, -159, -2164, -959, 3492, -690, -688, -1081, - 2762, -1191, 654, 2051, -2144, -3210, -1823, 743, 686, -751, - 2483, 160, 1279, 3246, 1874, 2488, 1192, -5977, -478, 120, - -349, -65, -2350, -222, -1678, -3584, 1114, 3269, 1462, -1114, - -138, 2360, -2762, 720, -3822, 2523, 216, 1170, 4398, -4229, - -1850, 1272, 383, 1736, -383, -1295, 85, -132, 1133, 1505, - 1467, -2389, -2175, 4028, -2752, 241, -4353, -2103, -562, 817, - 3959, 5471, 1941, -1598, -2349, 201, 1412, -796, 2791, -4226, - 3227, -1992, -159, -159, 4085, -1549, 1020, -2179, -776, -2088, - -147, -42, 1880, -1029, 4982, -2056, 111, 1420, 2141, 302, - -2574, -986, -477, -3697, -2349, -2064, -335, -220, 5857, 57, - -7, -5407, -546, -353, 2866, 137, -136, 3508, 992, -2059, - -2034, -1127, -189, -300, -2153, 3606, 2523, -3727, 1526, -3797, - 2134, 4352, -920, -459, 2722, 1784, -71, -3030, -877, 1967, - -1645, -4432, 512, 39, 1757, 2875, -947, 1842, 1365, 1500, - 851, 594, -2892, -404, 3327, -3078, -1575, -1258, -973, -191, - -390, 45, 627, -227, 1624, -143, 215, 2157, 4846, 5335, - 3397, -199, -4443, -3091, -283, -216, 1237, -1478, -5639, -775, - 525, 2107, 2469, 2934, -255, 2438, 824, 5973, -1820, -1330, - -1202, -2433, 900, 650, -5654, 2891, -1539, -453, 1662, 231, - -145, 1661, 741, -332, 1221, 1809, 943, 4831, -1588, -4619, - 65, -790, -985, -893, 3374, 3148, 289, 2947, -4980, -661, - -427, 1441, 7696, 158, -1914, -2069, -1717, -418, 2657, 4219, - 1505, -1096, 601, -1466, -1754, -479, -159, 3378, 5252, 5060, - 4001, 1301, 420, -1268, -2813, -4196 -}; - -const Word16 PowerCB_WB_fx[128] = -{ - -3371, -1712, - -170, 350, - -638, -939, - 56, 1074, - -1559, -626, - 200, 344, - -397, 238, - 284, 1415, - -1323, -1880, - -544, 1170, - -619, -255, - 587, 974, - -1262, -98, - 327, 151, - 41, -302, - 941, 1876, - -2257, -1233, - 28, 202, - -520, -561, - 338, 1048, - -1080, -495, - 190, 582, - -284, -24, - 578, 1585, - -1324, -1089, - -71, 568, - -471, -26, - 1140, 909, - -856, -128, - 425, 740, - 140, 12, - 1595, 1891, - -2176, -2310, - -308, 541, - -315, -859, - -80, 1314, - -1782, 510, - 403, 450, - -607, 582, - 145, 1837, - -920, -1386, - -225, 872, - -395, -258, - 829, 981, - -945, 345, - 643, 241, - -56, -23, - 1211, 1482, - -1793, -1459, - 40, 400, - -239, -471, - 532, 1238, - -774, -516, - 244, 831, - -157, 152, - 576, 2287, - -928, -844, - 41, 759, - -161, -198, - 873, 1353, - -640, 105, - 695, 623, - 364, -184, - 1238, 2446 -}; - - - -const Word16 PowerCB_NB_fx[128] = -{ - -3349, -2784, - -784, 385, - -891, -562, - 126, 915, - -1518, -1438, - 304, 53, - -314, -447, - 687, 1219, - -2585, -1807, - -65, 153, - -1219, -337, - 497, 700, - -894, -1051, - 161, 451, - -46, -516, - 987, 1519, - -2277, -2303, - -354, 445, - -532, -540, - 5, 1271, - -1047, -1433, - 672, -225, - -335, -75, - 1007, 1056, - -1362, -1879, - -93, 367, - -468, -259, - 1800, -290, - -1118, -793, - 412, 472, - -9, -197, - 1471, 1634, - -2627, -2847, - -269, 164, - -689, -373, - 432, 940, - -1601, -839, - 311, 271, - -212, -251, - 543, 1714, - -2014, -1336, - 109, 241, - -789, -110, - 729, 888, - -418, -1277, - 256, 674, - 218, -217, - 1027, 2065, - -1769, -2293, - -276, 853, - -360, -764, - 376, 1247, - -1274, -1122, - 602, 272, - -133, -32, - 1374, 1118, - -1860, -1795, - -23, 620, - -525, 60, - 1070, 548, - -691, -799, - 701, 572, - 81, 18, - 1949, 2120 -}; - - -const Word16 sinc_fx[8][12]= /* sinc for warp/extrapolate, in Q14 */ -{ - {0,0,0,0,0,16384,0,0,0,0,0,0,}, - {-388,484,-638,939,-1773,15966,2281,-1063,694,-514,409,-339,}, - {-701,868,-1134,1639,-2949,14751,4917,-2106,1341,-982,776,-640,}, - {-895,1101,-1427,2029,-3503,12849,7709,-2964,1835,-1328,1042,-856,}, - {-947,1159,-1489,2086,-3476,10430,10430,-3476,2086,-1489,1159,-947,}, - {-856,1042,-1328,1835,-2964,7709,12849,-3503,2029,-1427,1101,-895,}, - {-640,776,-982,1341,-2106,4917,14751,-2949,1639,-1134,868,-701,}, - {-339,409,-514,694,-1063,2281,15966,-1773,939,-638,484,-388,}, -}; - - -const Word32 inverse_table[]= -{ - 0, - 134217728, 67108864, 44739242, 33554432, 26843545, 22369621, 19173961, 16777216, 14913080, 13421772, 12201611, 11184810, 10324440, 9586980, 8947848, 8388608, 7895160, 7456540, 7064090, 6710886, 6391320, 6100805, 5835553, 5592405, 5368709, 5162220, 4971026, 4793490, 4628197, 4473924, 4329604, 4194304, 4067203, 3947580, 3834792, 3728270, 3627506, 3532045, 3441480, 3355443, 3273603, 3195660, 3121342, 3050402, 2982616, 2917776, 2855696, 2796202, 2739137, 2684354, 2631720, 2581110, 2532409, 2485513, 2440322, 2396745, 2354696, 2314098, 2274876, 2236962, 2200290, 2164802, 2130440, 2097152, 2064888, 2033601, 2003249, 1973790, 1945184, 1917396, 1890390, 1864135, 1838599, 1813753, 1789569, 1766022, 1743087, 1720740, 1698958, 1677721, 1657008, 1636801, 1617081, 1597830, 1579032, 1560671, 1542732, 1525201, 1508064, 1491308, 1474920, 1458888, 1443201, 1427848, 1412818, 1398101, 1383687, 1369568, 1355734, 1342177, 1328888, 1315860, 1303084, 1290555, 1278264, 1266204, 1254371, 1242756, 1231355, 1220161, 1209168, 1198372, 1187767, 1177348, 1167110, 1157049, 1147160, 1137438, 1127880, 1118481, 1109237, 1100145, 1091201, 1082401, 1073741, 1065220, 1056832, 1048576, 1040447, 1032444, 1024562, 1016800, 1009155, 1001624, 994205, 986895, 979691, 972592, 965595, 958698, 951898, 945195, 938585, 932067, 925639, 919299, 913045, 906876, 900790, 894784, 888859, 883011, 877240, 871543, 865920, 860370, 854889, 849479, 844136, 838860, 833650, 828504, 823421, 818400, 813440, 808540, 803698, 798915, 794187, 789516, 784898, 780335, 775825, 771366, 766958, 762600, 758292, 754032, 749819, 745654, 741534, 737460, 733430, 729444, 725501, 721600, 717741, 713924, 710146, 706409, 702710, 699050, 695428, 691843, 688296, 684784, 681308, 677867, 674460, 671088, 667749, 664444, 661171, 657930, 654720, 651542, 648394, 645277, 642190, 639132, 636102, 633102, 630130, 627185, 624268, 621378, 618514, 615677, 612866, 610080, 607320, 604584, 601873, 599186, 596523, 593883, 591267, 588674, 586103, 583555, 581029, 578524, 576041, 573580, 571139, 568719, 566319, 563940, 561580, 559240, 556920, 554618, 552336, 550072, 547827, 545600, 543391, 541200, 539027, 536870, 534731, 532610, 530504, 528416, 526344, -}; - - -const Word16 W_DTX_HO_FX[HO_HIST_SIZE] = /* Q15 */ -{ - 6554, 5243, 4194, 3355, 2684, 2147, 1718, 344 -}; - -const Word16 HO_ATT_FX[5] = /* Q15 */ -{ - 17597, 20205, 22410, 23198, 23198 -}; - -/*----------------------------------------------------------------------------------* - * SWB HR BWE - *----------------------------------------------------------------------------------*/ - -const Word16 wscw16q15_fx[240] = -{ - -32768, -32766, -32764, -32759, -32754, -32747, -32738, -32729, -32717, -32705, -32691, - -32675, -32658, -32640, -32621, -32600, -32577, -32553, -32528, -32501, -32473, -32444, - -32413, -32381, -32348, -32313, -32276, -32239, -32200, -32159, -32117, -32074, -32029, - -31984, -31936, -31887, -31837, -31786, -31733, -31679, -31624, -31567, -31508, -31449, - -31388, -31326, -31262, -31197, -31131, -31063, -30994, -30924, -30853, -30780, -30705, - -30630, -30553, -30475, -30395, -30315, -30232, -30149, -30064, -29979, -29891, -29803, - -29713, -29622, -29530, -29436, -29341, -29245, -29148, -29049, -28949, -28848, -28746, - -28642, -28537, -28431, -28324, -28216, -28106, -27995, -27883, -27770, -27655, -27540, - -27423, -27305, -27186, -27066, -26944, -26821, -26698, -26573, -26447, -26320, -26191, - -26062, -25931, -25800, -25667, -25533, -25398, -25262, -25125, -24986, -24847, -24707, - -24565, -24423, -24279, -24135, -23989, -23843, -23695, -23546, -23397, -23246, 23095, - 22942, 22788, 22634, 22478, 22322, 22164, 22006, 21846, 21686, 21525, 21363, - 21199, 21035, 20871, 20705, 20538, 20371, 20202, 20033, 19863, 19692, 19520, - 19347, 19174, 18999, 18824, 18648, 18472, 18294, 18116, 17937, 17757, 17576, - 17395, 17213, 17030, 16846, 16662, 16477, 16291, 16105, 15917, 15730, 15541, - 15352, 15162, 14972, 14781, 14589, 14397, 14204, 14010, 13816, 13621, 13426, - 13230, 13033, 12836, 12639, 12441, 12242, 12043, 11843, 11643, 11442, 11241, - 11039, 10837, 10634, 10431, 10228, 10024, 9819, 9615, 9409, 9204, 8998, - 8791, 8585, 8377, 8170, 7962, 7754, 7545, 7336, 7127, 6918, 6708, - 6498, 6288, 6077, 5866, 5655, 5444, 5232, 5020, 4808, 4596, 4383, - 4171, 3958, 3745, 3532, 3319, 3105, 2892, 2678, 2464, 2250, 2036, - 1822, 1608, 1394, 1179, 965, 751, 536, 322, 107 -}; -const Word16 wscw16q15_8_fx[40] = -{ - -32762, -32711, -32610, -32459, -32258, -32007, -31706, -31357, - -30959, -30514, -30022, -29483, -28899, -28270, -27598, -26883, - -26127, -25330, -24494, -23621, 22711, 21766, 20788, 19777, - 18736, 17666, 16569, 15447, 14300, 13132, 11943, 10736, - 9512, 8274, 7022, 5760, 4490, 3212, 1929, 643 -}; -const Word16 wscw16q15_16_fx[80] = -{ - -32766, -32754, -32729, -32691, -32640, -32577, -32501, -32413, - -32313, -32200, -32074, -31936, -31786, -31624, -31449, -31262, - -31063, -30853, -30630, -30395, -30149, -29891, -29622, -29341, - -29049, -28746, -28431, -28106, -27770, -27423, -27066, -26698, - -26320, -25931, -25533, -25125, -24707, -24279, -23843, -23397, - 22942, 22478, 22006, 21525, 21035, 20538, 20033, 19520, - 18999, 18472, 17937, 17395, 16846, 16291, 15730, 15162, - 14589, 14010, 13426, 12836, 12242, 11643, 11039, 10431, - 9819, 9204, 8585, 7962, 7336, 6708, 6077, 5444, - 4808, 4171, 3532, 2892, 2250, 1608, 965, 322 -}; -const Word16 wscw16q15_32_fx[160] = -{ - -32768, -32764, -32758, -32749, -32736, -32720, -32701, -32679, -32654, -32626, -32594, - -32559, -32522, -32481, -32437, -32389, -32339, -32286, -32229, -32169, -32107, -32041, - -31972, -31900, -31825, -31747, -31665, -31581, -31494, -31403, -31310, -31214, -31114, - -31012, -30906, -30798, -30687, -30572, -30455, -30335, -30212, -30086, -29957, -29825, - -29690, -29553, -29412, -29269, -29123, -28974, -28823, -28668, -28511, -28351, -28188, - -28023, -27855, -27684, -27511, -27335, -27156, -26975, -26791, -26604, -26415, -26223, - -26029, -25833, -25633, -25432, -25228, -25021, -24812, -24601, -24387, -24171, -23953, - -23732, -23509, -23284, 23056, 22827, 22595, 22361, 22125, 21886, 21646, 21403, - 21159, 20912, 20663, 20413, 20160, 19905, 19649, 19390, 19130, 18868, 18604, - 18338, 18071, 17802, 17531, 17258, 16984, 16708, 16430, 16151, 15871, 15588, - 15305, 15019, 14733, 14445, 14155, 13865, 13572, 13279, 12984, 12688, 12391, - 12093, 11793, 11492, 11191, 10888, 10584, 10279, 9973, 9666, 9358, 9049, - 8740, 8429, 8118, 7806, 7493, 7180, 6865, 6550, 6235, 5919, 5602, - 5285, 4967, 4649, 4330, 4011, 3692, 3372, 3052, 2731, 2411, 2090, - 1768, 1447, 1126, 804, 483, 161 -}; - -/*------------------------------------------------------------------------------* - * HQ MDCT tables - *------------------------------------------------------------------------------*/ -const Word16 hvq_class_c_fx[16] = /* Q15 */ -{ - -7617, -14387, 2136, 6914, - 4821, -4428, 14131, -4538, - -4538, 14131, -4428, 4821, - 6914, 2136, -14387, -7617 -}; -const Word32 dicn_fx[40] = /* Q=14 */ -{ - 2147483647, 1518500224, - 1073741824, 759250112, - 536870912, 379625056, - 268435456, 189812528, - 134217728, 94906264, - 67108864, 47453132, - 33554432, 23726566, - 16777216, 11863283, - 8388608, 5931642, - 4194304, 2965821, - 2097152, 1482910, - 1048576, 741455, - 524288, 370728, - 262144, 185364, - 131072, 92682, - 65536, 46341, - 32768, 23170, - 16384, 11585, - 8192, 5793, - 4096, 2896 -}; -const Word16 sqac_headroom_fx[146] = /* Q0 */ -{ - 0 /*not used */, 0, 0, 1, 1, 1, 1, 1, 1, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, - 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, - 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, - 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, - 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, - 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, - 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, - 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, - 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, - 3, 3, 3, 3, 3, 3, 3, 3, 3, 4, - 4, 4, 4, 4, 4, 4, 4, 4, - 4, 4, 4, 4, 4, 4, 4, 4 -}; - -const Word16 inv_N_fx[32] = /* Q15 */ -{ - 0, 1056, 2113, 3170, - 4227, 5284, 6341, 7398, - 8455, 9512, 10569, 11626, - 12683, 13740, 14797, 15854, - 16912, 17969, 19026, 20083, - 21140, 22197, 23254, 24311, - 25368, 26425, 27482, 28539, - 29596, 30653, 31710, 32767 -}; - -const Word16 hvq_bwe_fac_fx[16] = /* Q15 */ -{ - 16384, 17408, 18432, 19456, - 20480, 21504, 22528, 23552, - 24576, 25600, 26624, 27648, - 28672, 29696, 30720, 31744 -}; - -const Word16 att_step_fx[4]= /* Q=13 */ -{ - 32767, 16384, 10923, 8192 -}; - -const Word16 gain_att_fx[40]= /* Q=15 */ -{ - 15711, 19367, 21781, 23743, 24899, 25929, 26758, 27514, - 28059, 28562, 28994, 29398, 29693, 29970, 30213, 30442, - 30619, 30786, 30936, 31077, 31190, 31298, 31395, 31488, - 31564, 31637, 31704, 31768, 31822, 31873, 31920, 31966, - 32005, 32042, 32077, 32111, 32140, 32168, 32195, 32220 -}; - -const Word16 stab_trans_fx[10] = /* Q15 */ -{ - 16384, 11381, 7232, 4292, 2433, - 1341, 728, 391, 209, 112 -}; - -const Word16 env_stab_tp_fx[2][2] = /* Q15 */ -{ - {32735, 16384}, - {33, 16384} -}; - - -const Word16 subf_norm_groups_fx[4][11] = -{ - {0,1,8,9,16,20,24,28,32,36,40}, - {2,3,10,11,17,21,25,29,33,37,41}, - {4,5,12,13,18,22,26,30,34,38,42}, - {6,7,14,15,19,23,27,31,35,39,43} -}; - -const Word32 dicn_pg_fx[45] = /* Q12 */ -{ - 536870912, 451452834, 379625056, 319225344, 268435456, - 225726416, 189812528, 159612672, 134217728, 112863208, - 94906264, 67108864, 47453132, 33554432, 23726566, - 16777216, 11863283, 8388608, 5931641, 4194304, - 2965821, 2097152, 1482910, 1048576, 741455, - 524288, 370728, 262144, 185364, 131072, - 92682, 65536, 46341, 32768, 23170, - 16384, 11585, 8192, 5793, 4096, - 2896, 2048, 1448, 1024, 724 -}; - -const Word16 hvq_peak_cb_fx[1024] = /* Q15 */ -{ - -22652,-20549,-23019, 13968,-25496,-27493, -6957, 5753,-19678,-20274, - -6119, 18297, -5329,-22843,-21254, 13929,-27525,-29034, 563, 7265, - -26138,-13138, -9678, 7972, -517,-20830,-10703, 26832,-27818,-21449, - 208, 6297,-14803,-28396, -7655, 5118, 15134,-24005,-21776, 25330, - -11282,-23669,-20340, -2006,-16212,-24127, 9075, 22581,-20047,-25695, - -254, 6509,-17174,-29714, 1589, 7104,-17683, -4117, -4049, 22347, - -28338,-13898, 671, 6777,-18368,-17925, -7409, 5169,-22093,-19561, - 702, 5969, -6610,-27398, -4875, 8773,-29634, -5552, 272, 6992, - -9167,-19887, -9136, 6447,-23125,-25612, 9760, 5749,-10410,-29816, - 1606, 7019,-13758,-24849, 2084, 7129,-17795,-16160, 596, 7287, - -22276,-11145, 521, 6474,-13471,-20705, -74, 6740, 1891,-16245, - -12763, 13602, -1617,-27384, -9648, 2511,-21802,-11734, -4836, -1602, - -9670,-27913, 6456, 6338,-23227, -4603, 754, 5830, -7699,-24416, - 2204, 6518,-27591, 2763, 1885, 6839,-15248,-10500, 344, 6942, - -13247, -9761, -4486, 4294,-12097,-15164, 637, 6142,-25994,-16384, - 17277, 6511,-10346,-26179, 923, -2374,-13316,-18125, 6841, 7100, - -21083,-24251, 4207, -9464,-22914, -7057, 8647, 8026, 2488,-20731, - -799, 13754, -3451,-12872, 2545, 17315, 2576,-19594,-10340, 4361, - -7007,-19401, 1937, 6751, 17502,-24923,-16948, 8534, -3436,-29004, - 6315, 6467,-16936, -4957, 591, 6604, 1099,-26790, -708, 5543, - -5949,-14167, -4750, 4068,-10682,-14990, -7489, -5197, 169, -6472, - -5143, 16200,-20331, 1722, 395, 6233,-15661,-22913, 24689, 14221, - -3892,-22862, 5154, 6301, -8786,-10120, 216, 6831,-12390,-11062, - 4824, 6473, -7705, -4195, -5326, 6572, -560,-20773, -2777, 1822, - -6703,-14413, 2409, 6083,-10595,-25038, 14291, 4825, 2064,-25736, - 16863, 20463, -2752,-29103, 12609, 7539, -7638,-18024, 1948, 689, - -10961, -5839, 683, 6170,-26004, 12209, 10742, 15580, -2105, -8625, - -4932, 6977, -9940,-15129, 12160, 9806,-13921, -55, 440, 6315, - -305, -6080, 11303, 25730,-12423, -3161, 6875, 9836, -2780,-16434, - 4128, 5778, 17790,-10991, -6633, 21111, 12367,-26550,-10581, -2530, - -6713,-10210, 4804, 6280, -5932, 2832, 4978, 18330, 2696,-23822, - -11870,-13313, 5266,-10870, -7933, 4455, -3155,-10994, 2225, 5803, - 820,-11966, -1397, 5344, -5027, -7230, 1236, 5812, -1649,-21007, - 8948, 5539,-16246, -801, -533, -3132, -8272, -1302, 367, 5958, - -26574, -3470, 7126, -8876, -4819, -5380, -3923, 1466, 1929,-20655, - 4419, 3663, 2437,-26758, 10897, 5616, -6601,-10394, 2148, 137, - 15007,-22909, -3948, 6197, -9059,-27702, 23041, 4088, 8312, -267, - 2973, 25579, -3795, -3612, -489, 5401, 7711,-25887, 3443, 2623, - -24306, 3091, 13248, 3273, -3113, -1410, 3541, 12047, 306,-11933, - -4493, -1997,-18725, 8257, 7593, 7218,-13588, -8411, 8715, -1137, - -12028, 5907, 17904, 21327, -2223,-22989, 9863, -1633, -723, -5944, - 714, 5170, 2128,-15199, 2081, 1626, -482, -8521, 8131, 10765, - 53,-12020, 5152, 5033, 2361,-13747, 24714, 26357, 1074,-28538, - 18087, 4333, 1067,-22148, 14277, 5540, 729,-15049, 7936, 4648, - -16646, -6350, 23646, 9628, -91, -8477, 3298, 4297, 3499, -7417, - -2214, 2931, -4795, -4424, 6487, 4264, -9333, 3377, 6570, 5734, - 1733,-17598, 11163, 4167, -2713,-16183, 14693, 4188,-23780, 9825, - 25701, 15331, 586,-19288, 21576, 12040, 11328,-15656, 2944, 7335, - 9203,-16906, -5723, -5371, -7906, -4632, 12470, 5724, -123,-16520, - 976, -8288, 1262, -3966, -3014, -148, 230, -2169, 505, 3954, - -2256,-11474, 9990, 2644, 4841, -8017, -4617, -2959, 24226,-22733, - 7475, 17722, 6747, -5782, 4877, 8664, -6893,-24218, 12181,-14683, - 2839, -7574, 4815, 2376, 2680, -3986, 1749, 2061, -563, 3232, - 3039, 5761, 343, -4150, 6600, 3792, 6356, 7199, 10702, 24266, - -25636,-12157, 22874,-14633, 2438, -8680, 8312, 3091, 7135, -3110, - 268, 4547, 4272, 4886, 5861, 14177, 11382,-10386, -767, 1448, - 1770,-28758, 27658, 4643, -3008,-10314, 18024, 5252, 6999,-17854, - 9789, 909, 1556,-21532, 20929, 3182, 26836,-23774, -2868, 3509, - -9884,-14471, 24685, 193, -3300, -5891, 5237, -5722, -9043,-14338, - 17448, -7167, -683, 26, 4002, -235, 3072,-12689, 13537, 2670, - 3577,-10477, 10097, 1435, 17713,-24555, 7486, 1713, 6633, -6645, - 1863, -783, 3185, -8349, 3975, -3967, 8090,-23915, 7470, -8732, - 2793,-16733, 17412, 1948, -5975,-14195, 1741,-22095, 3376, -782, - 18258, 16642, 3845, -3536, 5136, 335, 3267, -719, 10538, 7756, - -10993, 5165, 17885, 4767, 4733, -7751, 15643, 8215, 3678, 1686, - 3571, 2189,-11186, 1470, 6152,-11489, 4353, -2197, 1357, -3164, - 4258, -6029, 8420, -230, 6220, -1478, 2105, -787, -4229, -4632, - 15095, -1672, 1986,-16134, 14035, -6088, 7849,-14512, 2875,-10127, - 4796,-14269, -8761,-25428, 1192,-24490, 22001, -6216, 258,-10418, - 27459, 10524, -754, 7182, 7574, 3444, 5995, 3253, 25190, 25483, - 6379, -6363, 409, -8435, -3319, 3253, 12035, 1358, 3184, -6482, - 12864, -216, 25363, -7652, -2971, 5718, 4969, -3415, 7040, -2605, - 2616,-21129, 28211, 1289, 2553,-15075, 23833, 1871, 14598, -6793, - 7189, 4535, 5581, -1997, 4257, -4337, 6027,-10630, 9913, -5633, - 3695,-11614, 19091, 585, 4415, -8798, 15569, -1099, -879, 752, - 19480, 5412, 5743, 448, 9863, 1342, 20634,-16941, -7404,-16938, - -11946, 17852, 19422, 5918, 12538,-20829, 22707, 1113, 4715, -4341, - 12573, -3709, 4015, -8219, 3349,-17549, 6395, -1551, 4414, -8302, - 24598,-24474, 21909, 9778, 5346, 1386, 6942, -4708, -1507, 2077, - 8224,-10420, 6088, -3411, 8824, -6355, 7219, 17353, 22325, 25889, - 6666, -1811, 1964,-13461, 8123, -4454, 26614, 11418, 4582, -7133, - 18420, -3918, -264, 10545, 24810, 12821, 6936,-22880, 10241,-24118, - 3108, -7220, 11991,-12963, 4237,-10392, 23417, -2591, 4624,-14780, - 29121, -1235, 7543, -1157, 17358, 1244, 20161, -6319, 2575, -5204, - 4384, 5974, 10993, -2909, 1619, -4017, 26017, 722, 4659, 11545, - 14463, 4774, -2892, 10593, 15058, -4543, 1972,-15782, 26652,-10199, - 6046, -562, 11992, -8022, 6197, -349, 7928,-12070, 21399,-13670, - 15116, 99, 5829, -4061, 16713, -7200, -8904, 4170, 24814, -7599, - 12177, 6080, 19388, 11094, 4262, 1544, 17090, -4775, -6957, -5908, - 19576,-23176, 7126,-23499, 24889,-17683, 5514, -5416, 23284, -5830, - 6388, -1788, 14378,-11597, 5099, -8771, 28791, -4573, 6029, -4164, - 3217,-26929, 6427, 145, 9306,-17874, 5544, 3835, 25432, -15, - 8297,-10673, 21003,-15084, 6019, -7628, 13891,-22535, 27144, 1685, - 10077, 4230, 5211, -1543, 22179,-10638, 6385, 5710, 13476,-12976, - 5272, 17571, 23747, 5084, -2100, 9127, 13746,-20852,-16310, 15716, - 21422,-23074, 6532, -31, 17127,-16620, 5397, -3362, 28477, -9453, - 6238, 1258, 13189,-22475, 12895, -4568, 8062,-26648, 2873, 5975, - 22151,-15208, 6319, -507, 23117,-17415, 24129,-14207, 12908,-21101, - 7262, 8470, 25405, -9450, 5424, -1162, 29494,-16114, 21373, 22875, - 24554, 16783, 6684, 2453, 15785,-28885, 6504, 1085, 21619,-24241, - 21468, 620, 23222, -7235, 10917, 8863, 18570,-21606, 6710, -2091, - 28961,-25837, 6884, 20869, 27603, -8999, 6798, 5617, 28706,-21501, - 6066, 4720, 25084,-28951 -}; - -const Word16 rat_fx[SFM_N_WB] = { 24576, 24576, 24576, 24576, 24576, 24576, 24576, 24576, 24576, 24576, 24576, 24576, 24576, 24576, 24576, 24576, - 16384, 16384, 16384, 16384, 16384, 16384, 16384, 16384, 13107, 13107 - }; - -const Word16 fb_inv_bwe_subband_width_fx[DIM_FB] = {819, 819, 409}; -const Word16 fb_smooth_factor_fx[DIM_FB] = {1024, 819, 512}; - -const Word16 hvq_thr_adj_fx[5] = { 23170, 16384, 8192, 16384, 23170}; /* Q15 */ - -const Word16 hvq_index_mapping_fx[4] = {0, 1, 3, 4}; - -const Word16 hq_nominal_scaling_inv[7] = {0, 8192, 11585, 0, 16384, 0, 20066}; /*Q13 */ -const Word16 hq_nominal_scaling[7] = {0, 32767, 23170, 0, 16384, 0, 13377}; /*Q15 */ - -/* %* lowered Table ROM, call with band_len_idx[sfm_size>>3] */ -/* % sfms =[ 8, 16, 24, 32, 48, 64, 80, 96 ], */ -/* sfm/8= [ 1 2 3 4 6 8 10 12]; */ -/* % idx= 0 1 2 3 4 5 6 7; */ -/* call with band_len_idx[sfm_size>>3] */ -const Word16 band_len_idx[1+(MAX_SFM_LEN_FX/8)] = -{ - /*sfm/8*/ /*1*/ /*2 */ /*3 */ /*4 */ /*6 */ /*8 */ /*10*/ /*12*/ - -1 , 0/*8*/, 1/*16*/,2/*24*/,3/*32*/,-1, 4/*48 */,-1, 5/*64 */,-1, 6/*80*/,-1, 7/*96*/ -}; -const Word16 band_len_ener_shift[8] = {1, 2, 2, 2, 3, 3 , 4/*sfm==80*/, 4 /*sfm==96*/}; /* 96 requires 1 bit more than 48 */ -/*% sfms=[8,16,24,32,48,64,80,96], round(sqrt(sfms)*2^11) */ -const Word16 fine_gain_pred_sqrt_bw[8] = {5793, 8192, 10033, 11585, 14189, 16384, 18318 , 20066 }; /* (Q11) */ -const Word32 SQRT_DIM_fx[1+PVQ_MAX_BAND_SIZE] = /* sqrt(x) for x = 0, 1, ..., 64. in Q15 */ -{ - 0, 32768, 46341, 56756, 65536, 73271, 80265, 86696, - 92682, 98304, 103622, 108679, 113512, 118147, 122607, 126910, - 131072, 135106, 139023, 142832, 146543, 150162, 153696, 157150, - 160530, 163840, 167085, 170268, 173392, 176461, 179478, 182445, - 185364, 188238, 191069, 193858, 196608, 199320, 201996, 204636, - 207243, 209818, 212361, 214874, 217358, 219814, 222243, 224646, - 227023, 229376, 231705, 234010, 236293, 238555, 240795, 243014, - 245213, 247393, 249554, 251696, 253820, 255926, 258015, 260088, - 262144 -}; - - - - - - -const Word16 finegain_1_fx[2] = {-12204, 12647}; /* Q14 */ -const Word16 finegain_2_fx[4] = {-17773, -5925, 6010, 18769}; /* Q14 */ -const Word16 finegain_3_fx[8] = {-16384, -11703, -7022, -2341, 2341, 7022, 11703, 16384}; /* Q14 */ -const Word16 finegain_4_fx[16] = /* Q14 */ -{ - -21683, -18292, -14998, -11876, -8936, -6239, -3702, -1371, - 945, 3275, 6088, 9079, 12450, 15999, 19796, 23868 -}; -const Word16 finegain_5_fx[32] = /* Q14 */ -{ - -21462, -18895, -16284, -14135, -12605, -11307, -10139, -8910, - -8028, -6792, -5638, -4812, -3672, -2681, -1725, -479, - 449, 1390, 2364, 3433, 4579, 5516, 6769, 7767, - 9085, 10152, 11009, 12535, 14765, 17093, 20094, 24716 -}; -const Word16* finegain_fx[5] = { finegain_1_fx, finegain_2_fx, finegain_3_fx, finegain_4_fx, finegain_5_fx }; -const Word16 gain_cb_size[MAX_GAIN_BITS] = {2, 4, 8, 16, 32}; - -const UWord32 exactdivodd_fx[ODD_DIV_SIZE_FX]=/* exactdivodd[0]=1/1,exactdivodd[1]=1/3 exactdivodd[47]=1/95 */ -{ - 1U, 2863311531U, 3435973837U, 3067833783U, 954437177U, 3123612579U, 3303820997U, 4008636143U, - 4042322161U, 678152731U, 1022611261U, 3921491879U, 3264175145U, 1749801491U, 1332920885U, 3186588639U, - 1041204193U, 2331553675U, 2437684141U, 2532929431U, 3247414297U, 799063683U, 2767867813U, 1736263375U, - 438261969U, 4210752251U, 2350076445U, 1483715975U, 3089362441U, 2693454067U, 3238827797U, 3204181951U, - 3237744577U, 128207979U, 2738819725U, 3811027319U, 3353604601U, 2519714147U, 1059797125U, 1631000239U, - 2014922929U, 724452315U, 4244438269U, 1875962727U, 4198451177U, 3539808211U, 1062196213U, 3571604383U -}; - - -const Word32 thren_fx[39] = /* Q8 */ -{ - 28215802, 19951584, 14107901, - 9975792, 7053951, 4987896, - 3526975, 2493948, 1763488, - 1246974, 881744, 623487, - 440872, 311744, 220436, - 155872, 110218, 77936, - 55109, 38968, 27554, - 19484, 13777, 9742, - 6889, 4871, 3444, - 2435, 1722, 1218, - 861, 609, 431, - 304, 215, 152, - 108, 76, 54 -}; - -/*------------------------------------------------------------------------------* - * LR-MDCT tables - *------------------------------------------------------------------------------*/ -/* NB short win: 7200/8000/9600, 13200/16400/24400 */ -static const Word16 band_width_40_4_6_0_0_0[4] = { 6, 8, 11, 15 }; -static const Word16 band_width_40_5_6_0_0_0[5] = { 6, 7, 7, 9, 11 }; - -/* NB long win: 7200, 8000, 9600, 13200, 16400/24400 */ -static const Word16 band_width_160_13_6_2_0_0[13] = { 6, 6, 6, 6, 7, 8, 9, 10, 13, 15, 19, 24, 31 }; -static const Word16 band_width_160_14_6_3_0_0[14] = { 6, 6, 6, 6, 6, 7, 8, 9, 10, 12, 15, 18, 22, 29 }; -static const Word16 band_width_160_17_6_3_0_0[17] = { 6, 6, 6, 6, 6, 6, 7, 7, 8, 8, 9, 10, 11, 13, 15, 17, 19 }; -static const Word16 band_width_160_18_6_4_0_0[18] = { 6, 6, 6, 6, 6, 6, 6, 7, 7, 8, 8, 9, 10, 11, 12, 14, 15, 17 }; - -/* WB short win: 13200/16400/24400 */ -static const Word16 band_width_80_7_6_0_0_0[7] = { 6, 7, 8, 10, 12, 16, 21 }; - -/* WB long win: 12800, 16000, 24000 */ -static const Word16 band_width_320_18_6_3_0_0[18] = { 6, 6, 6, 6, 6, 7, 7, 8, 10, 11, 13, 16, 19, 24, 30, 37, 47, 61 }; -static const Word16 band_width_320_20_6_3_0_0[20] = { 6, 6, 6, 6, 6, 6, 7, 8, 8, 9, 11, 12, 14, 17, 20, 23, 28, 34, 42, 51 }; - -/* SWB short win: 12800, 16000, 24000 */ -static const Word16 band_width_142_8_8_0_0_0[8] = {7,8,10,11,15,21,29,41 }; -static const Word16 band_width_160_8_8_0_0_0[8] = { 8, 9, 11,13,17,23,32,47 }; - -/* SWB long win: 12800, 16000, 24000 */ -static const Word16 band_width_568_22_6_2_0_0[22] = { 6, 6, 6, 6, 6, 6, 7, 8, 9, 10, 11, 13, 16, 19, 23, 28, 34, 42, 55, 68, 84, 105}; -static const Word16 band_width_640_24_6_4_0_0[24] = { 6, 6, 6, 6, 6, 6, 7, 7, 8, 9, 10, 11, 13, 15, 18, 21, 26, 32, 39, 48, 59, 74, 92,115 }; - -/* LR-MDCT: NB configuration tables */ -const Xcore_Config_fx xcore_config_8kHz_007200bps_long_fx = { 13, L_FRAME8k, band_width_160_13_6_2_0_0, 536870912L, 24576, 13107, 2, 2, 0, 0, 13107, 4260, 19661 }; -const Xcore_Config_fx xcore_config_8kHz_008000bps_long_fx = { 14, L_FRAME8k, band_width_160_14_6_3_0_0, 536870912L, 24576, 13107, 2, 2, 0, 0, 13107, 4260, 19661 }; -const Xcore_Config_fx xcore_config_8kHz_013200bps_long_fx = { 17, L_FRAME8k, band_width_160_17_6_3_0_0, 429496730L, 24576, 13107, 2, 4, 2, 24576, 13107, 4260, 19661 }; -const Xcore_Config_fx xcore_config_8kHz_016400bps_long_fx = { 18, L_FRAME8k, band_width_160_18_6_4_0_0, 322122547L, 24576, 13107, 2, 2, 0, 0, 13107, 4260, 19661 }; - -const Xcore_Config_fx xcore_config_8kHz_007200bps_short_fx = { 4, L_FRAME8k / NUM_TIME_SWITCHING_BLOCKS, band_width_40_4_6_0_0_0, 966367642L, 24576, 13107, 2, 2, 0, 0, 9830, 2949, 19661 }; -const Xcore_Config_fx xcore_config_8kHz_008000bps_short_fx = { 4, L_FRAME8k / NUM_TIME_SWITCHING_BLOCKS, band_width_40_4_6_0_0_0, 1181116006L, 24576, 13107, 2, 4, 0, 0, 9830, 2949, 19661 }; -const Xcore_Config_fx xcore_config_8kHz_013200bps_short_fx = { 5, L_FRAME8k / NUM_TIME_SWITCHING_BLOCKS, band_width_40_5_6_0_0_0, 751619276L, 24576, 11469, 2, 4, 0, 0, 22938, 3604, 19661 }; -const Xcore_Config_fx xcore_config_8kHz_016400bps_short_fx = { 5, L_FRAME8k / NUM_TIME_SWITCHING_BLOCKS, band_width_40_5_6_0_0_0, 536870912L, 24576, 11469, 2, 6, 0, 0, 22491, 3604, 19661 }; - -/* LR-MDCT: WB configuration tables */ -const Xcore_Config_fx xcore_config_16kHz_013200bps_long_fx = { 18, L_FRAME16k, band_width_320_18_6_3_0_0, 429496730L, 24576, 13106, 2, 6, 3, 24576, 13107, 3932, 18022 }; -const Xcore_Config_fx xcore_config_16kHz_016400bps_long_fx = { 20, L_FRAME16k, band_width_320_20_6_3_0_0, 429496730L, 24576, 13106, 2, 6, 3, 24576, 13107, 3932, 19660 }; - -const Xcore_Config_fx xcore_config_16kHz_013200bps_short_fx = { 7, L_FRAME16k / NUM_TIME_SWITCHING_BLOCKS, band_width_80_7_6_0_0_0, 966367642L, 24576, 9830, 2, 4, 0, 0, 9830, 4258, 18022 }; -const Xcore_Config_fx xcore_config_16kHz_016400bps_short_fx = { 7, L_FRAME16k / NUM_TIME_SWITCHING_BLOCKS, band_width_80_7_6_0_0_0, 966367642L, 24576, 11468, 2, 8, 0, 0, 9830, 4258, 19660 }; - -/* LR-MDCT: SWB configuration tables */ -const Xcore_Config_fx xcore_config_32kHz_013200bps_long_fx = { 22, 568, band_width_568_22_6_2_0_0, 322122547L, 24576, 6554, 2, 4, 5, 28672, 13107, 4260, 19661 }; -const Xcore_Config_fx xcore_config_32kHz_016400bps_long_fx = { 24, 640, band_width_640_24_6_4_0_0, 322122547L, 24576, 8192, 2, 4, 5, 28672, 13107, 4260, 19661 }; - -const Xcore_Config_fx xcore_config_32kHz_013200bps_short_fx = { 8, 568 / NUM_TIME_SWITCHING_BLOCKS, band_width_142_8_8_0_0_0, 1610612736L, 24576, 13107, 2, 4, 0, 0, 16384, 3604, 19661 }; -const Xcore_Config_fx xcore_config_32kHz_016400bps_short_fx = { 8, 640 / NUM_TIME_SWITCHING_BLOCKS, band_width_160_8_8_0_0_0, 644245094L, 24576, 8192, 2, 4, 0, 0, 9830, 4260, 19661 }; - -/*------------------------------------------------------------------------------* - * LR MDCT SWB BWE coding tables - *------------------------------------------------------------------------------*/ -const Word16 subband_offsets_12KBPS[NB_SWB_SUBBANDS] = {SWB_SB_OFF0_12KBPS, SWB_SB_OFF1_12KBPS, SWB_SB_OFF2_12KBPS, SWB_SB_OFF3_12KBPS}; -const Word16 subband_offsets_16KBPS[NB_SWB_SUBBANDS] = {SWB_SB_OFF0_16KBPS, SWB_SB_OFF1_16KBPS, SWB_SB_OFF2_16KBPS, SWB_SB_OFF3_16KBPS}; -const Word16 gain_table_SWB_BWE_fx[NB_SWB_SUBBANDS] = { -6554/*-0.4f*/, 1638/*0.1f*/, 9830/*0.6f*/, 18022/*1.1f*/ }; /* Q14 */ - -const Word16 bits_lagIndices_modeNormal_fx[NB_SWB_SUBBANDS] = {2, 2, 1, 1}; - -/* Search offset for the subbands that use a partial search */ -const Word16 subband_search_offsets_fx[NB_SWB_SUBBANDS] = -{ - 0, 0, 64, 64 -}; -/* SPT : shorten subband length table */ -const Word16 bw_SPT_tbl[2][SPT_SHORTEN_SBNUM]= -{ - {15, 31, 31, 31}, /* 13.2kbps: original band_width 53, 66, 82, 102 */ - {15, 15, 31, 31} /* 16.4kbps: original band_width 51 64, 80, 90 */ -}; - -/* Harmonic Mode */ -const Word16 bits_lagIndices_mode0_Har_fx[NB_SWB_SUBBANDS_HAR_SEARCH_SB] = {1,1}; - -/* 13.2 kbps */ -const Word16 subband_offsets_sub5_13p2kbps_Har_fx[NB_SWB_SUBBANDS_HAR] = -{ - SWB_SB_OFF0_SUB5_12KBPS_HAR, SWB_SB_OFF1_SUB5_12KBPS_HAR, SWB_SB_OFF2_SUB5_12KBPS_HAR, SWB_SB_OFF3_SUB5_12KBPS_HAR -}; - -/* Search offset for the subbands that use a partial search */ -const Word16 subband_search_offsets_13p2kbps_Har_fx[NB_SWB_SUBBANDS_HAR_SEARCH_SB] = -{ - 120, 210 -}; - -/* 16.4 kbps */ -const Word16 subband_offsets_sub5_16p4kbps_Har_fx[NB_SWB_SUBBANDS_HAR] = -{ - SWB_SB_OFF0_SUB5_16KBPS_HAR, SWB_SB_OFF1_SUB5_16KBPS_HAR, SWB_SB_OFF2_SUB5_16KBPS_HAR, SWB_SB_OFF3_SUB5_16KBPS_HAR -}; - -/* Search offset for the subbands that use a partial search */ -const Word16 subband_search_offsets_16p4kbps_Har_fx[NB_SWB_SUBBANDS_HAR_SEARCH_SB] = -{ - 120, 210 -}; - -const Word16 inv_tbl_fx[146] = -{ - 0, 32767, 16384, 10923, 8192, 6554, 5462, 4681, - 4096, 3641, 3277, 2979, 2731, 2521, 2341, 2185, - 2048, 1928, 1820, 1725, 1638, 1560, 1489, 1425, - 1365, 1311, 1260, 1214, 1170, 1130, 1092, 1057, - 1024, 993, 964, 936, 910, 886, 862, 840, - 819, 799, 780, 762, 745, 728, 712, 697, - 683, 669, 655, 643, 630, 618, 607, 596, - 585, 575, 565, 555, 546, 537, 529, 520, - 512, 504, 496, 489, 482, 475, 468, 462, - 455, 449, 443, 437, 431, 426, 420, 415, - 410, 405, 400, 395, 390, 386, 381, 377, - 372, 368, 364, 360, 356, 352, 349, 345, - 341, 338, 334, 331, 328, 324, 321, 318, - 315, 312, 309, 306, 303, 301, 298, 295, - 293, 290, 287, 285, 282, 280, 278, 275, - 273, 271, 269, 266, 264, 262, 260, 258, - 256, 254, 252, 250, 248, 246, 245, 243, - 241, 239, 237, 236, 234, 232, 231, 229, - 228, 226 -}; -const Word32 table_logcum_fx[563] = -{ - 0, 0, 0, 65536, 169408, 300480, 452650, 622058, 806041, - 1002649, 1210393, 1428099, 1654816, 1889761, 2132272, 2381791, 2637833, - 2899977, 3167853, 3441134, 3719526, 4002767, 4290623, 4582876, 4879332, - 5179812, 5484152, 5792200, 6103816, 6418871, 6737244, 7058822, 7383500, - 7711180, 8041769, 8375181, 8711333, 9050150, 9391557, 9735485, 10081869, - 10430647, 10781759, 11135150, 11490766, 11848556, 12208469, 12570461, 12934487, - 13300503, 13668469, 14038345, 14410092, 14783676, 15159061, 15536214, 15915101, - 16295692, 16677956, 17061866, 17447390, 17834504, 18223180, 18613394, 19005122, - 19398338, 19793020, 20189146, 20586692, 20985640, 21385968, 21787658, 22190686, - 22595040, 23000696, 23407638, 23815850, 24225314, 24636014, 25047934, 25461060, - 25875374, 26290862, 26707510, 27125304, 27544232, 27964278, 28385428, 28807674, - 29231000, 29655392, 30080844, 30507338, 30934866, 31363416, 31792978, 32223540, - 32655092, 33087624, 33521126, 33955588, 34391000, 34827352, 35264636, 35702840, - 36141960, 36581988, 37022908, 37464716, 37907404, 38350964, 38795388, 39240668, - 39686792, 40133760, 40581560, 41030188, 41479632, 41929888, 42380948, 42832808, - 43285456, 43738892, 44193104, 44648088, 45103840, 45560348, 46017612, 46475624, - 46934376, 47393864, 47854080, 48315024, 48776684, 49239060, 49702144, 50165928, - 50630412, 51095588, 51561452, 52028000, 52495224, 52963124, 53431688, 53900916, - 54370808, 54841348, 55312540, 55784380, 56256856, 56729972, 57203720, 57678096, - 58153096, 58628716, 59104952, 59581800, 60059256, 60537316, 61015980, 61495236, - 61975084, 62455524, 62936548, 63418156, 63900340, 64383100, 64866428, 65350328, - 65834792, 66319816, 66805396, 67291536, 67778224, 68265456, 68753240, 69241560, - 69730424, 70219816, 70709744, 71200208, 71691192, 72182704, 72674736, 73167280, - 73660344, 74153920, 74648008, 75142600, 75637704, 76133296, 76629400, 77125992, - 77623080, 78120656, 78618728, 79117280, 79616320, 80115840, 80615832, 81116312, - 81617256, 82118680, 82620568, 83122920, 83625744, 84129024, 84632768, 85136968, - 85641624, 86146728, 86652288, 87158304, 87664760, 88171664, 88679008, 89186792, - 89695016, 90203680, 90712776, 91222304, 91732256, 92242648, 92753464, 93264704, - 93776368, 94288448, 94800952, 95313872, 95827208, 96340960, 96855120, 97369696, - 97884672, 98400064, 98915856, 99432048, 99948648, 100465640, 100983040, 101500832, - 102019016, 102537592, 103056568, 103575928, 104095672, 104615808, 105136328, 105657232, - 106178520, 106700184, 107222232, 107744656, 108267456, 108790632, 109314176, 109838096, - 110362384, 110887040, 111412064, 111937448, 112463208, 112989320, 113515800, 114042640, - 114569832, 115097392, 115625304, 116153568, 116682184, 117211160, 117740480, 118270152, - 118800168, 119330536, 119861248, 120392312, 120923712, 121455448, 121987536, 122519960, - 123052720, 123585816, 124119248, 124653016, 125187120, 125721552, 126256320, 126791416, - 127326840, 127862592, 128398664, 128935072, 129471800, 130008856, 130546224, 131083920, - 131621936, 132160272, 132698920, 133237888, 133777176, 134316768, 134856688, 135396912, - 135937440, 136478288, 137019440, 137560912, 138102688, 138644768, 139187152, 139729840, - 140272832, 140816128, 141359712, 141903616, 142447808, 142992304, 143537104, 144082192, - 144627568, 145173248, 145719232, 146265504, 146812064, 147358912, 147906048, 148453488, - 149001200, 149549216, 150097504, 150646096, 151194960, 151744112, 152293536, 152843264, - 153393264, 153943536, 154494096, 155044944, 155596064, 156147456, 156699120, 157251072, - 157803296, 158355792, 158908560, 159461616, 160014928, 160568512, 161122368, 161676496, - 162230896, 162785568, 163340496, 163895696, 164451168, 165006896, 165562896, 166119152, - 166675664, 167232448, 167789504, 168346816, 168904368, 169462208, 170020288, 170578624, - 171137232, 171696080, 172255200, 172814560, 173374192, 173934064, 174494192, 175054576, - 175615216, 176176096, 176737232, 177298608, 177860256, 178422128, 178984256, 179546640, - 180109264, 180672128, 181235248, 181798608, 182362208, 182926064, 183490144, 184054480, - 184619056, 185183872, 185748928, 186314224, 186879760, 187445520, 188011536, 188577776, - 189144272, 189710992, 190277936, 190845136, 191412560, 191980208, 192548112, 193116224, - 193684592, 194253168, 194821984, 195391040, 195960320, 196529824, 197099568, 197669520, - 198239712, 198810144, 199380784, 199951648, 200522752, 201094080, 201665616, 202237392, - 202809376, 203381600, 203954032, 204526688, 205099568, 205672672, 206246000, 206819536, - 207393296, 207967280, 208541472, 209115888, 209690528, 210265376, 210840432, 211415712, - 211991216, 212566912, 213142848, 213718976, 214295328, 214871888, 215448672, 216025664, - 216602864, 217180272, 217757888, 218335712, 218913760, 219492000, 220070464, 220649120, - 221228000, 221807072, 222386368, 222965856, 223545552, 224125456, 224705568, 225285872, - 225866400, 226447120, 227028032, 227609168, 228190496, 228772016, 229353760, 229935680, - 230517824, 231100160, 231682688, 232265424, 232848352, 233431472, 234014800, 234598336, - 235182048, 235765968, 236350080, 236934400, 237518896, 238103600, 238688496, 239273600, - 239858880, 240444352, 241030032, 241615888, 242201952, 242788192, 243374640, 243961264, - 244548096, 245135104, 245722304, 246309696, 246897280, 247485056, 248073008, 248661152, - 249249488, 249838016, 250426720, 251015616, 251604704, 252193968, 252783424, 253373056, - 253962880, 254552896, 255143088, 255733472, 256324032, 256914768, 257505696, 258096800, - 258688096, 259279568, 259871216, 260463056, 261055056, 261647264, 262239632, 262832192, - 263424928, 264017840, 264610928, 265204192, 265797632, 266391264, 266985072, 267579040, - 268173200, 268767520, 269362048, 269956736, 270551584, 271146624, 271741824, 272337216, - 272932768, 273528480, 274124384, 274720480, 275316704, 275913120, 276509728, 277106496, - 277703424, 278300544, 278897824, 279495264, 280092896, 280690688, 281288640, 281886752, - 282485056, 283083520 -}; -const Word32 pow_getbitsfrompulses_fx[16] = /*Q21 */ -{ - 2097152, 2190001, 2286961, 2388214, 2493948, 2604365, 2719671, 2840081, - 2965822, 3097129, 3234251, 3377442, 3526976, 3683128, 3846194, 4016480 -}; -const Word16 DDP_fx[4] = { 3, 0, 1, 2 }; -const Word16 step_tcq_fx[8][STATES] = { {0,4}, {0,4}, {1,5}, {1,5}, {2,6}, {2,6}, {3,7}, {3,7} }; -const Word16 denc_fx[8][STATES] = { {0,2}, {2,0}, {1,3}, {3,1}, {2,0}, {0,2}, {3,1}, {1,3} }; /* enc trellis */ -const Word16 ddec_fx[8][STATES] = { {0,2}, {1,3}, {2,0}, {3,1}, {2,0}, {3,1}, {0,2}, {1,3} }; /* dec trellis */ - -const Word16 step_LSB_fx[STATES_LSB][2] = { {0,1}, {2,3}, {0,1}, {2,3} }; -const Word16 denc_LSB_fx[STATES_LSB][2] = { {0,3}, {2,1}, {3,0}, {1,2} }; -const Word16 dqnt_LSB_fx[STATES_LSB][4] = { {0,8,1,8}, {0,8,1,8}, {8,0,8,1}, {8,0,8,1} }; - -const Word16 dstep_LSB_fx[4][2] = { {0,2}, {0,2}, {1,3}, {1,3} }; -const Word16 ddec_LSB_fx[4][2] = { {0,3}, {3,0}, {2,1}, {1,2} }; - -const Word16 window_48kHz_fx16[1110] = /* Q15 */ -{ - - 0, 1, 2, 3, 5, 8, 10, 13, 17, 21, - 25, 30, 35, 40, 46, 52, 58, 65, 72, 80, - 88, 96, 105, 114, 124, 133, 144, 154, 165, 176, - 188, 200, 212, 225, 238, 251, 265, 279, 293, 308, - 323, 339, 354, 371, 387, 404, 421, 439, 457, 475, - 493, 512, 532, 551, 571, 591, 612, 633, 654, 676, - 698, 720, 743, 766, 789, 813, 837, 861, 885, 910, - 936, 961, 987, 1013, 1040, 1067, 1094, 1122, 1149, 1178, - 1206, 1235, 1264, 1293, 1323, 1353, 1384, 1414, 1445, 1477, - 1508, 1540, 1573, 1605, 1638, 1671, 1705, 1739, 1773, 1807, - 1842, 1877, 1912, 1948, 1984, 2020, 2057, 2093, 2130, 2168, - 2206, 2244, 2282, 2320, 2359, 2399, 2438, 2478, 2518, 2558, - 2599, 2640, 2681, 2722, 2764, 2806, 2848, 2891, 2934, 2977, - 3020, 3064, 3108, 3152, 3196, 3241, 3286, 3332, 3377, 3423, - 3469, 3515, 3562, 3609, 3656, 3704, 3751, 3799, 3847, 3896, - 3945, 3994, 4043, 4092, 4142, 4192, 4242, 4293, 4343, 4394, - 4445, 4497, 4549, 4600, 4653, 4705, 4758, 4811, 4864, 4917, - 4971, 5024, 5078, 5133, 5187, 5242, 5297, 5352, 5407, 5463, - 5519, 5575, 5631, 5688, 5744, 5801, 5859, 5916, 5974, 6031, - 6089, 6147, 6206, 6265, 6323, 6382, 6442, 6501, 6561, 6620, - 6680, 6741, 6801, 6862, 6922, 6983, 7045, 7106, 7168, 7229, - 7291, 7353, 7416, 7478, 7541, 7604, 7667, 7730, 7793, 7857, - 7920, 7984, 8048, 8112, 8177, 8241, 8306, 8371, 8436, 8501, - 8566, 8632, 8697, 8763, 8829, 8895, 8961, 9028, 9094, 9161, - 9228, 9295, 9362, 9429, 9497, 9564, 9632, 9700, 9768, 9836, - 9904, 9972, 10041, 10109, 10178, 10247, 10316, 10385, 10454, 10523, - 10593, 10662, 10732, 10802, 10871, 10941, 11012, 11082, 11152, 11222, - 11283, 11344, 11406, 11467, 11529, 11591, 11653, 11716, 11778, 11840, - 11903, 11966, 12028, 12091, 12154, 12217, 12280, 12343, 12406, 12469, - 12532, 12595, 12658, 12722, 12785, 12849, 12912, 12976, 13039, 13103, - 13166, 13230, 13294, 13358, 13421, 13485, 13549, 13613, 13677, 13741, - 13805, 13869, 13933, 13997, 14061, 14125, 14189, 14253, 14318, 14382, - 14446, 14510, 14574, 14639, 14703, 14767, 14832, 14896, 14960, 15025, - 15089, 15153, 15218, 15282, 15346, 15411, 15475, 15540, 15604, 15668, - 15733, 15797, 15862, 15926, 15990, 16055, 16119, 16183, 16248, 16312, - 16376, 16441, 16505, 16569, 16634, 16698, 16762, 16826, 16891, 16955, - 17019, 17083, 17147, 17211, 17275, 17340, 17404, 17468, 17532, 17596, - 17659, 17723, 17787, 17851, 17915, 17979, 18042, 18106, 18170, 18233, - 18297, 18361, 18424, 18488, 18551, 18614, 18678, 18741, 18804, 18868, - 18931, 18994, 19057, 19120, 19183, 19246, 19309, 19372, 19434, 19497, - 19560, 19622, 19685, 19748, 19810, 19872, 19935, 19997, 20059, 20121, - 20183, 20245, 20307, 20369, 20431, 20493, 20554, 20616, 20677, 20739, - 20800, 20862, 20923, 20984, 21045, 21106, 21167, 21228, 21289, 21349, - 21410, 21471, 21531, 21591, 21652, 21712, 21772, 21832, 21892, 21952, - 22012, 22071, 22131, 22190, 22250, 22309, 22368, 22427, 22486, 22545, - 22604, 22663, 22722, 22780, 22839, 22897, 22955, 23013, 23071, 23129, - 23187, 23245, 23303, 23360, 23418, 23475, 23532, 23589, 23646, 23703, - 23760, 23817, 23873, 23930, 23986, 24042, 24098, 24154, 24210, 24266, - 24321, 24377, 24432, 24488, 24543, 24598, 24653, 24707, 24762, 24817, - 24871, 24925, 24979, 25034, 25087, 25141, 25195, 25248, 25302, 25355, - 25408, 25461, 25514, 25567, 25620, 25672, 25724, 25777, 25829, 25881, - 25932, 25984, 26036, 26087, 26138, 26189, 26240, 26291, 26342, 26393, - 26443, 26493, 26543, 26593, 26643, 26693, 26743, 26792, 26841, 26890, - 26939, 26988, 27037, 27086, 27134, 27182, 27230, 27278, 27326, 27374, - 27421, 27469, 27516, 27563, 27610, 27657, 27703, 27750, 27796, 27842, - 27888, 27934, 27980, 28025, 28071, 28116, 28161, 28206, 28250, 28295, - 28340, 28384, 28428, 28472, 28516, 28559, 28603, 28646, 28689, 28732, - 28775, 28818, 28860, 28903, 28945, 28987, 29029, 29071, 29112, 29154, - 29195, 29236, 29277, 29318, 29358, 29399, 29439, 29479, 29519, 29559, - 29598, 29638, 29677, 29716, 29755, 29794, 29832, 29871, 29909, 29947, - 29985, 30023, 30061, 30098, 30135, 30172, 30209, 30246, 30283, 30319, - 30356, 30392, 30428, 30464, 30499, 30535, 30570, 30605, 30640, 30675, - 30710, 30744, 30779, 30813, 30847, 30881, 30914, 30948, 30981, 31014, - 31047, 31080, 31113, 31145, 31178, 31210, 31242, 31274, 31306, 31337, - 31369, 31400, 31431, 31462, 31493, 31523, 31554, 31584, 31614, 31644, - 31674, 31704, 31733, 31763, 31792, 31821, 31850, 31879, 31907, 31936, - 31964, 31992, 32020, 32048, 32076, 32104, 32131, 32159, 32186, 32213, - 32240, 32267, 32294, 32320, 32347, 32373, 32399, 32426, 32452, 32478, - 32504, 32530, 32556, 32582, 32607, 32633, 32659, 32685, 32712, 32739, - 32739, 32712, 32685, 32659, 32633, 32606, 32580, 32553, 32527, 32500, - 32473, 32446, 32418, 32391, 32363, 32335, 32307, 32279, 32251, 32222, - 32193, 32164, 32134, 32105, 32075, 32045, 32015, 31984, 31953, 31922, - 31891, 31859, 31828, 31796, 31764, 31731, 31698, 31665, 31632, 31599, - 31565, 31531, 31497, 31462, 31428, 31393, 31357, 31322, 31286, 31250, - 31214, 31177, 31141, 31104, 31066, 31029, 30991, 30953, 30915, 30876, - 30837, 30798, 30759, 30719, 30679, 30639, 30599, 30558, 30517, 30476, - 30435, 30393, 30351, 30309, 30266, 30224, 30181, 30138, 30094, 30050, - 30006, 29962, 29917, 29873, 29827, 29782, 29737, 29691, 29645, 29598, - 29551, 29505, 29457, 29410, 29362, 29314, 29266, 29218, 29169, 29120, - 29070, 29021, 28971, 28921, 28871, 28820, 28769, 28718, 28667, 28615, - 28563, 28511, 28459, 28406, 28353, 28300, 28246, 28192, 28138, 28084, - 28030, 27975, 27920, 27864, 27809, 27753, 27697, 27640, 27584, 27527, - 27470, 27412, 27355, 27297, 27238, 27180, 27121, 27062, 27003, 26944, - 26884, 26824, 26763, 26703, 26642, 26581, 26520, 26458, 26396, 26334, - 26272, 26209, 26146, 26083, 26020, 25956, 25892, 25828, 25763, 25699, - 25634, 25568, 25503, 25437, 25371, 25305, 25239, 25172, 25105, 25037, - 24970, 24902, 24834, 24766, 24697, 24628, 24559, 24490, 24420, 24351, - 24281, 24210, 24140, 24069, 23998, 23926, 23855, 23783, 23711, 23638, - 23566, 23493, 23420, 23346, 23273, 23199, 23125, 23050, 22976, 22901, - 22826, 22750, 22675, 22599, 22523, 22446, 22370, 22293, 22215, 22138, - 22060, 21983, 21904, 21826, 21747, 21669, 21589, 21510, 21430, 21351, - 21271, 21190, 21110, 21029, 20948, 20866, 20785, 20703, 20621, 20538, - 20456, 20373, 20290, 20207, 20123, 20039, 19955, 19871, 19787, 19702, - 19617, 19532, 19446, 19360, 19274, 19188, 19102, 19015, 18928, 18841, - 18754, 18666, 18578, 18490, 18402, 18313, 18224, 18135, 18046, 17956, - 17866, 17776, 17686, 17595, 17505, 17414, 17322, 17231, 17139, 17047, - 16955, 16863, 16770, 16677, 16584, 16490, 16397, 16303, 16209, 16114, - 16020, 15925, 15830, 15735, 15639, 15543, 15447, 15351, 15254, 15158, - 15061, 14964, 14866, 14768, 14671, 14572, 14474, 14375, 14276, 14177, - 14078, 13978, 13878, 13778, 13678, 13578, 13477, 13376, 13274, 13173, - 13071, 12969, 12867, 12764, 12662, 12559, 12455, 12352, 12248, 12144, - 12040, 11936, 11831, 11726, 11621, 11515, 11410, 11304, 11197, 11091, - 10984, 10877, 10770, 10663, 10555, 10447, 10339, 10230, 10122, 10013, - 9904, 9794, 9684, 9574, 9464, 9353, 9243, 9131, 9020, 8909, - 8797, 8684, 8572, 8459, 8346, 8233, 8119, 8006, 7892, 7777, - 7662, 7547, 7432, 7317, 7201, 7085, 6968, 6851, 6734, 6617, - 6499, 6381, 6263, 6144, 6025, 5906, 5786, 5666, 5546, 5425, - 5304, 5183, 5061, 4939, 4817, 4694, 4570, 4447, 4323, 4198, - 4074, 3948, 3823, 3696, 3570, 3443, 3315, 3187, 3058, 2929, - 2800, 2669, 2539, 2407, 2275, 2142, 2009, 1875, 1740, 1604, - 1467, 1330, 1191, 1051, 909, 766, 621, 474, 324, 169, -}; - - -const Word16 SmoothingWin_NB875_fx[70] = /*Q15*/ -{ - 0, 16, 66, 148, 263, 411, 590, 802, 1045, 1318, - 1623, 1956, 2319, 2710, 3129, 3574, 4046, 4542, 5062, 5604, - 6169, 6754, 7358, 7981, 8620, 9275, 9945, 10627, 11321, 12025, - 12738, 13459, 14185, 14915, 15649, 16384, 17119, 17853, 18583, 19309, - 20030, 20743, 21447, 22141, 22823, 23493, 24148, 24787, 25410, 26014, - 26599, 27164, 27706, 28226, 28722, 29194, 29639, 30058, 30449, 30812, - 31145, 31450, 31723, 31966, 32178, 32357, 32505, 32620, 32702, 32752 -}; - -const Word16 SmoothingWin_NB2_fx[16] = -{ - 0, 315, 1247, 2761, 4799, 7282, 10114, 13188, 16384, 19580, 22654, 25486, 27969, 30007, 31521, 32453 -}; - - -const Word16 crit_bands_loc_fx[CRIT_NOIS_BAND] = -{ - 100, 200, 300, 400, 510, 630, 770, 920, 1080, 1270, 1480, 1720, - 2000, 2320, 2700, 3150, 3700, 4100, 4500, 5000, 5500, 6000, 6375 -}; - -const unsigned char hBitsMinus1_N01[2] = {1, 7}; - -const unsigned char hBitsMinus1_N02[65]= -{ - 64, 15, 23, 28, 31, 34, 36, 38, 39, 41, 42, 43, 44, 45, 46, 47, - 47, 48, 49, 49, 50, 51, 52, 53, 54, 54, 55, 56, 57, 57, 58, 59, - 60, 61, 62, 63, 63, 64, 65, 65, 67, 68, 69, 69, 70, 71, 72, 72, - 73, 74, 75, 76, 77, 78, 79, 80, 80, 81, 82, 83, 84, 85, 86, 87, - 87 -}; - -const unsigned char hBitsMinus1_N03[65]= -{ - 64, 20, 33, 41, 48, 53, 57, 61, 64, 66, 69, 71, 73, 75, 76, 78, - 80, 81, 82, 83, 85, 86, 88, 90, 92, 93, 95, 96, 98, 99, 100, 102, - 104, 106, 108, 110, 111, 113, 114, 115, 118, 120, 122, 123, 125, 127, 128, 129, - 131, 133, 135, 137, 139, 141, 142, 144, 145, 146, 149, 151, 153, 155, 157, 158, - 160 -}; - -const unsigned char hBitsMinus1_N04[65]= -{ - 64, 23, 39, 51, 60, 67, 73, 79, 83, 87, 91, 94, 97, 100, 102, 105, - 107, 109, 111, 113, 115, 116, 119, 122, 125, 127, 130, 132, 134, 136, 138, 141, - 144, 147, 150, 152, 154, 156, 158, 160, 164, 167, 170, 173, 175, 177, 180, 182, - 184, 187, 190, 193, 196, 199, 201, 203, 205, 207, 211, 214, 217, 220, 222, 225, - 227 -}; - -const unsigned char hBitsMinus1_N05[54]= -{ - 53, 26, 45, 59, 70, 79, 87, 94, 100, 105, 110, 114, 118, 122, 125, 128, - 131, 134, 136, 139, 141, 144, 148, 152, 155, 158, 161, 164, 167, 170, 172, 176, - 181, 184, 188, 191, 194, 197, 200, 202, 207, 211, 215, 219, 222, 225, 228, 231, - 233, 238, 242, 246, 250, 253 -}; - -const unsigned char hBitsMinus1_N06[42]= -{ - 41, 28, 49, 65, 78, 89, 99, 107, 114, 120, 126, 132, 136, 141, 145, 149, - 153, 156, 159, 162, 165, 168, 173, 178, 183, 187, 191, 194, 198, 201, 204, 209, - 214, 219, 224, 228, 231, 235, 238, 241, 247, 253 -}; - -const unsigned char hBitsMinus1_N07[34]= -{ - 33, 30, 52, 70, 85, 98, 109, 118, 126, 134, 141, 147, 153, 158, 163, 168, - 172, 176, 180, 184, 188, 191, 197, 203, 208, 213, 218, 222, 226, 230, 233, 240, - 246, 252 -}; - -const unsigned char hBitsMinus1_N08[29]= -{ - 28, 31, 55, 75, 91, 105, 117, 128, 138, 146, 154, 161, 168, 174, 180, 185, - 190, 195, 200, 204, 208, 212, 219, 226, 232, 238, 243, 248, 253 -}; - -const unsigned char hBitsMinus1_N09[25]= -{ - 24, 33, 58, 79, 97, 112, 125, 137, 148, 157, 166, 174, 182, 189, 195, 201, - 207, 212, 217, 222, 227, 231, 240, 247, 254 -}; - -const unsigned char hBitsMinus1_N10[22]= -{ - 21, 34, 61, 83, 101, 118, 132, 145, 157, 167, 177, 186, 194, 202, 209, 216, - 222, 228, 234, 239, 245, 250 -}; - -const unsigned char hBitsMinus1_N11[19]= -{ - 18, 35, 63, 86, 106, 123, 139, 152, 165, 176, 187, 197, 206, 214, 222, 230, - 237, 243, 250 -}; - -const unsigned char hBitsMinus1_N12[17]= -{ - 16, 36, 65, 89, 110, 128, 144, 159, 173, 185, 196, 207, 217, 226, 234, 242, - 250 -}; - -const unsigned char hBitsMinus1_N13[16]= -{ - 15, 37, 67, 92, 113, 133, 150, 165, 180, 193, 205, 216, 227, 237, 246, 254, -}; - -const unsigned char hBitsMinus1_N14[14]= -{ - 13, 38, 68, 94, 117, 137, 155, 171, 186, 200, 213, 225, 236, 247 -}; - -const unsigned char hBitsMinus1_N15[13]= -{ - 12, 39, 70, 97, 120, 141, 160, 177, 193, 207, 221, 233, 245 -}; - -const unsigned char hBitsMinus1_N16[13]= -{ - 12, 39, 71, 99, 123, 144, 164, 182, 198, 214, 228, 241, 253 -}; - -const unsigned char hBitsMinus1_N17[12]= -{ - 11, 40, 73, 101, 126, 148, 168, 187, 204, 220, 234, 248 -}; - -const unsigned char hBitsMinus1_N18[12]= -{ - 11, 41, 74, 103, 128, 151, 172, 191, 209, 225, 241, 255 -}; - -const unsigned char hBitsMinus1_N19[11]= -{ - 10, 41, 75, 105, 131, 154, 176, 196, 214, 231, 247 -}; - -const unsigned char hBitsMinus1_N20[11]= -{ - 10, 42, 77, 107, 133, 157, 179, 200, 219, 236, 253 -}; - -const unsigned char hBitsMinus1_N21[10]= -{ - 9, 43, 78, 108, 135, 160, 183, 204, 223, 241 -}; - -const unsigned char hBitsMinus1_N22[10]= -{ - 9, 43, 79, 110, 138, 163, 186, 207, 227, 246 -}; - -const unsigned char hBitsMinus1_N23[10]= -{ - 9, 44, 80, 111, 140, 165, 189, 211, 231, 250 -}; - -const unsigned char hBitsMinus1_N24[10]= -{ - 9, 44, 81, 113, 142, 168, 192, 214, 235, 255 -}; - -const unsigned char hBitsMinus1_N25[9]= -{ - 8, 45, 82, 114, 143, 170, 195, 217, 239 -}; - -const unsigned char hBitsMinus1_N26[9]= -{ - 8, 45, 83, 116, 145, 172, 197, 221, 242 -}; - -const unsigned char hBitsMinus1_N27[9]= -{ - 8, 46, 84, 117, 147, 175, 200, 224, 246 -}; - -const unsigned char hBitsMinus1_N28[9]= -{ - 8, 46, 84, 118, 149, 177, 202, 227, 249 -}; -const unsigned char hBitsMinus1_N29[9]= -{ - 8, 46, 85, 119, 150, 179, 205, 229, 252 -}; -const unsigned char hBitsMinus1_N30[8]= -{ - 7, 47, 86, 121, 152, 181, 207, 232 -}; -const unsigned char hBitsMinus1_N31[8]= -{ - 7, 47, 87, 122, 153, 182, 209, 235 -}; -const unsigned char hBitsMinus1_N32[8]= -{ - 7, 47, 87, 123, 155, 184, 212, 237 -}; -const unsigned char hBitsMinus1_N33[8]= -{ - 7, 48, 88, 124, 156, 186, 214, 240 -}; -const unsigned char hBitsMinus1_N34[8]= -{ - 7, 48, 89, 125, 158, 188, 216, 242 -}; -const unsigned char hBitsMinus1_N35[8]= -{ - 7, 49, 90, 126, 159, 189, 218, 245 -}; -const unsigned char hBitsMinus1_N36[8]= -{ - 7, 49, 90, 127, 160, 191, 220, 247 -}; -const unsigned char hBitsMinus1_N37[8]= -{ - 7, 49, 91, 128, 162, 193, 222, 249 -}; -const unsigned char hBitsMinus1_N38[8]= -{ - 7, 49, 91, 129, 163, 194, 224, 251 -}; -const unsigned char hBitsMinus1_N39[8]= -{ - 7, 50, 92, 130, 164, 196, 225, 253 -}; -const unsigned char hBitsMinus1_N40[8]= -{ - 7, 50, 93, 131, 165, 197, 227, 255 -}; -const unsigned char hBitsMinus1_N41[7]= -{ - 6, 50, 93, 131, 166, 199, 229 -}; -const unsigned char hBitsMinus1_N42[7]= -{ - 6, 51, 94, 132, 167, 200, 230 -}; -const unsigned char hBitsMinus1_N43[7]= -{ - 6, 51, 94, 133, 168, 201, 232 -}; -const unsigned char hBitsMinus1_N44[7]= -{ - 6, 51, 95, 134, 170, 203, 234 -}; -const unsigned char hBitsMinus1_N45[7]= -{ - 6, 51, 95, 135, 171, 204, 235 -}; -const unsigned char hBitsMinus1_N46[7]= -{ - 6, 52, 96, 135, 172, 205, 237 -}; -const unsigned char hBitsMinus1_N47[7]= -{ - 6, 52, 96, 136, 173, 206, 238 -}; -const unsigned char hBitsMinus1_N48[7]= -{ - 6, 52, 97, 137, 174, 208, 240 -}; -const unsigned char hBitsMinus1_N49[7]= -{ - 6, 52, 97, 138, 175, 209, 241 -}; -const unsigned char hBitsMinus1_N50[7]= -{ - 6, 53, 98, 138, 175, 210, 243 -}; -const unsigned char hBitsMinus1_N51[7]= -{ - 6, 53, 98, 139, 176, 211, 244 -}; -const unsigned char hBitsMinus1_N52[7]= -{ - 6, 53, 99, 140, 177, 212, 245 -}; -const unsigned char hBitsMinus1_N53[7]= -{ - 6, 53, 99, 140, 178, 213, 247 -}; -const unsigned char hBitsMinus1_N54[7]= -{ - 6, 54, 100, 141, 179, 214, 248 -}; -const unsigned char hBitsMinus1_N55[7]= -{ - 6, 54, 100, 142, 180, 216, 249 -}; -const unsigned char hBitsMinus1_N56[7]= -{ - 6, 54, 100, 142, 181, 217, 250 -}; -const unsigned char hBitsMinus1_N57[7]= -{ - 6, 54, 101, 143, 181, 218, 252 -}; -const unsigned char hBitsMinus1_N58[7]= -{ - 6, 54, 101, 143, 182, 219, 253 -}; -const unsigned char hBitsMinus1_N59[7]= -{ - 6, 55, 102, 144, 183, 220, 254 -}; -const unsigned char hBitsMinus1_N60[7]= -{ - 6, 55, 102, 145, 184, 221, 255 -}; -const unsigned char hBitsMinus1_N61[6]= -{ - 5, 55, 102, 145, 185, 221 -}; -const unsigned char hBitsMinus1_N62[6]= -{ - 5, 55, 103, 146, 185, 222 -}; -const unsigned char hBitsMinus1_N63[6]= -{ - 5, 55, 103, 146, 186, 223 -}; -const unsigned char hBitsMinus1_N64[6]= -{ - 5, 55, 103, 147, 187, 224 -}; - - - -const Word16 dsDiracsTab[65] = -{ - 0, 1, 2, 3, 4, 5, 6, 7, - 8, 9, 10, 11, 12, 13, 14, 15, - 16, 17, 18, 19, 20, 21, 23, 25, - 27, 29, 31, 33, 35, 37, 39, 43, - 47, 51, 55, 59, 63, 67, 71, 75, - 83, 91, 99, 107, 115, 123, 131, 139, - 147, 163, 179, 195, 211, 227, 243, 259, - 275, 291, 323, 355, 387, 419, 451, 483, - 512 -}; - -const unsigned int intLimCDivInvDQ31[67+1] = -{ - 0x00000000, 0x80000000, 0x40000000, 0x2aaaaaab, 0x20000000, 0x1999999a, 0x15555556, 0x12492493, - 0x10000000, 0x0e38e38f, 0x0ccccccd, 0x0ba2e8bb, 0x0aaaaaab, 0x09d89d8a, 0x0924924a, 0x08888889, - 0x08000000, 0x07878788, 0x071c71c8, 0x06bca1b0, 0x06666667, 0x06186187, 0x05d1745e, 0x0590b217, - 0x05555556, 0x051eb852, 0x04ec4ec5, 0x04bda130, 0x04924925, 0x0469ee59, 0x04444445, 0x04210843, - 0x04000000, 0x03e0f83f, 0x03c3c3c4, 0x03a83a84, 0x038e38e4, 0x03759f23, 0x035e50d8, 0x03483484, - 0x03333334, 0x031f3832, 0x030c30c4, 0x02fa0be9, 0x02e8ba2f, 0x02d82d83, 0x02c8590c, 0x02b93106, - 0x02aaaaab, 0x029cbc15, 0x028f5c29, 0x02828283, 0x02762763, 0x026a43a0, 0x025ed098, 0x0253c826, - 0x02492493, 0x023ee090, 0x0234f72d, 0x022b63cc, 0x02222223, 0x02192e2a, 0x02108422, 0x02082083, - 0x02000000, 0x01f81f82, 0x01f07c20, 0x01e9131b -}; - -const unsigned char obtainEnergyQuantizerDensity_f[57] = -{ - 1, 1, 1, 1, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 4, 4, 4, - 4, 4, 4, 6, 6, 6, 6, 8, - 8, 8, 10,10,12,12,14,14, - 16,18,20,20,22,24,26,30, - 32,34,38,42,46,50,54,58, - 64,70,76,82,90,98,108,118, 128 -}; - - -/* (char)ceil(log2(hBitsN[N][0])) - 2) */ -unsigned char f_log2_n[ PVQ_MAX_BAND_SIZE + 1] = -{ - 0xff, 0xff, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, - 0x03, 0x03, 0x03, 0x03, 0x02, 0x02, 0x02, 0x02, - 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, - 0x02, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, - 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, - 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, - 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, - 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, - 0x01 -}; - -const unsigned char* const hBitsN[ PVQ_MAX_BAND_SIZE + 1 ]= -{ - f_log2_n/*N=0*/, hBitsMinus1_N01, hBitsMinus1_N02, hBitsMinus1_N03, hBitsMinus1_N04, - hBitsMinus1_N05, hBitsMinus1_N06, hBitsMinus1_N07, hBitsMinus1_N08, hBitsMinus1_N09, - hBitsMinus1_N10, hBitsMinus1_N11, hBitsMinus1_N12, hBitsMinus1_N13, hBitsMinus1_N14, - hBitsMinus1_N15, hBitsMinus1_N16, hBitsMinus1_N17, hBitsMinus1_N18, hBitsMinus1_N19, - hBitsMinus1_N20, hBitsMinus1_N21, hBitsMinus1_N22, hBitsMinus1_N23, hBitsMinus1_N24, - hBitsMinus1_N25, hBitsMinus1_N26, hBitsMinus1_N27, hBitsMinus1_N28, hBitsMinus1_N29, - hBitsMinus1_N30, hBitsMinus1_N31, hBitsMinus1_N32, hBitsMinus1_N33, hBitsMinus1_N34, - hBitsMinus1_N35, hBitsMinus1_N36, hBitsMinus1_N37, hBitsMinus1_N38, hBitsMinus1_N39, - hBitsMinus1_N40, hBitsMinus1_N41, hBitsMinus1_N42, hBitsMinus1_N43, hBitsMinus1_N44, - hBitsMinus1_N45, hBitsMinus1_N46, hBitsMinus1_N47, hBitsMinus1_N48, hBitsMinus1_N49, - hBitsMinus1_N50, hBitsMinus1_N51, hBitsMinus1_N52, hBitsMinus1_N53, hBitsMinus1_N54, - hBitsMinus1_N55, hBitsMinus1_N56, hBitsMinus1_N57, hBitsMinus1_N58, hBitsMinus1_N59, - hBitsMinus1_N60, hBitsMinus1_N61, hBitsMinus1_N62, hBitsMinus1_N63, hBitsMinus1_N64, -}; - - -const Word16 lim_neg_inv_tbl_fx[MAX_SPLITS + 1] = -{ - 0, - -32768, -16384, -10923, -8192, -6554, - -5462, -4681, -4096, -3641, -3277 -}; - - - -const Word16 Idx2Freq_Tbl[] = { 6554/*12.8*512*/, 48*512, 13108/*25.6*512*/, 32*512, 16*512, 8*512 }; /* in Q9 */ - -/*-------------------------------------------------------------------* - * inverse (reciprocal) of integer, used in FEC_fx.c, pitch_extr and in pitchDoubling_det - * 1/n = One_div[n-1] - *-------------------------------------------------------------------*/ -const Word16 One_div_fx[] = /* in Q15 */ -{ - 32767, /* 1/1 */ - 16384, /* 1/2 */ - 10923, /* 1/3 */ - 8192, /* 1/4 */ - 6554, /* 1/5 */ - 5461, /* 1/6 */ - 4681, /* 1/7 */ - 4096 /* 1/8 */ -}; - -/* - * 1/4 resolution interpolation filter (-3 dB at 0.791*fs/2) - */ -const Word16 E_ROM_inter4_1[UP_SAMP * L_INTERPOL1 + 1] = -{ - /* cut-off frequency at 0.9*fs/2 */ - 14746/*0.900000F Q14*/, - 13418/*0.818959F Q14*/, 9910/*0.604850F Q14*/, 5429/*0.331379F Q14*/, 1376/*0.083958F Q14*/, - -1242/*-0.075795F Q14*/, -2142/*-0.130717F Q14*/, -1732/*-0.105685F Q14*/, -766/*-0.046774F Q14*/, - 73/*0.004467F Q14*/, 455/*0.027789F Q14*/, 420/*0.025642F Q14*/, 206/*0.012571F Q14*/, - 32/*0.001927F Q14*/, -26/*-0.001571F Q14*/, -12/*-0.000753F Q14*/, 0/*0.000000f Q14*/ -}; -/* - * 1/6 resolution interpolation filter (-3 dB at 0.9*fs/2) - */ -const Word16 E_ROM_inter6_1[PIT_UP_SAMP6 * L_INTERPOL1 + 1] = -{ - 14759/*0.900848F Q14*/, - 14158/*0.864136F Q14*/, - 12453/*0.760071F Q14*/, - 9919/*0.605408F Q14*/, - 6948/*0.424072F Q14*/, - 3972/*0.242462F Q14*/, - 1377/*0.0840759F Q14*/, - -563/*-0.0343933F Q14*/, - -1729/*-0.105560F Q14*/, - -2152/*-0.131348F Q14*/, - -1984/*-0.121124F Q14*/, - -1450/*-0.0884705F Q14*/, - -780/*-0.0476379F Q14*/, - -168/*-0.0102539F Q14*/, - 267/*0.0162964F Q14*/, - 485/*0.0296021F Q14*/, - 512/*0.0312195F Q14*/, - 412/*0.0251160F Q14*/, - 258/*0.0157471F Q14*/, - 110/*0.00671387F Q14*/, - 0/*0.000000F Q14*/, - -65/*-0.00399780F Q14*/, - -97/*-0.00592041F Q14*/, - -108/*-0.00656128F Q14*/, - 0/*0.000000F Q14*/ -}; - - -const Word16 Grid[GRID100_POINTS+1] = -{ - 32767, 32751, 32703, 32622, 32509, 32364, - 32187, 31978, 31738, 31466, 31164, 30830, - 30466, 30072, 29649, 29196, 28714, 28204, - 27666, 27101, 26509, 25891, 25248, 24579, - 23886, 23170, 22431, 21669, 20887, 20083, - 19260, 18418, 17557, 16680, 15786, 14876, - 13951, 13013, 12062, 11099, 10125, 9141, - 8149, 7148, 6140, 5126, 4106, 3083, - 2057, 1029, 0, -1029, -2057, -3083, - -4106, -5126, -6140, -7148, -8149, -9141, - -10125, -11099, -12062, -13013, -13951, -14876, - -15786, -16680, -17557, -18418, -19260, -20083, - -20887, -21669, -22431, -23170, -23886, -24579, - -25248, -25891, -26509, -27101, -27666, -28204, - -28714, -29196, -29649, -30072, -30466, -30830, - -31164, -31466, -31738, -31978, -32187, -32364, - -32509, -32622, -32703, -32751, -32760 -}; - -/* 16-byte align end */ - -/*----------------------------------------------------------------------------------* - * impulse response with phase dispersion - * Used in lib_dec\enhancer.c - *----------------------------------------------------------------------------------*/ -/* 2.0 - 6.4 kHz phase dispersion in frequency domain (output of fft_rel) */ -const Word16 low_H[64] = /* (1Q14) */ -{ - 16388, 16380, 16386, 16381, 16382, 16382, 16381, 16383, 16385, 10265, - 10154, 9894, 14051, 16342, -531, 13216, 16372, 15509, 9406, 15948, - 4726, 14593, 10404, 9795, -16337, -1815, -10624, 12646, 14555, -12684, - 11388, 8175, 16382, -14198, 11781, 10378, 7515, 10423, -12473, 16284, - -1200, -13137, 12658, -7446, 15683, -3764, -13419, -5281, 521, -9686, - -16375, -1219, 8435, -13059, -12862, -12775, -1, 2, 0, -3, - -1, -1, -2, 1 -}; - -const Word16 low_H16k[80] = /* (1Q14) */ -{ - 16388, 16380, 16386, 16381, 16382, 16382, 16381, 16383, 16385, 10265, - 10154, 9894, 14051, 16342, -531, 13216, 16372, 15509, 9406, 15948, - 4726, 14593, 10404, 9795, -16337, -1815, -10624, 12646, 14555, -12684, - 11388, 8175, -4121, -13408, 10605, -12308, 16358, 4699, 7640, -7360, - 16382, -14639, -14494, 15695, -907, -10815, -12489, 9416, 15857, - -14198, 11781, 10378, 7515, 10423, -12473, 16284, -1200, -13137, 12658, - -7446, 15683, -3764, -13419, -5281, 521, -9686, -16375, -1219, 8435, - -13059, -12862, -12775, -1, 2, 0, -3, -1, -1, -2, 1 -}; - -/* 3.2 - 6.4 kHz phase dispersion in frequency domain (output of fft_rel) */ -const Word16 mid_H[64] = /* (1Q14) */ -{ - 16382, 16381, 16384, 16384, 16385, 16387, 16386, 16382, 16387, 16382, - 16385, 16385, 16385, 16384, 16382, 16388, 14847, 9629, 13248, 14486, - 10995, 642, 13817, 13779, 6468, 8664, 11634, 9780, -14636, -982, - 11746, -722, 16385, -16366, -11423, 16354, 7362, 13147, -11538, -13904, - -15052, -8862, 8811, -16371, -12146, 7660, -9638, -13254, -6923, 3, - -5, -2, -6, 1, 6, 5, -8, -2, 3, -5, - 0, -2, -4, 3 -}; - -const Word16 mid_H16k[80] = /* (1Q14) */ -{ - 16382, 16381, 16384, 16384, 16385, 16387, 16386, 16382, 16387, 16382, - 16385, 16385, 16385, 16384, 16382, 16388, 14847, 9629, 13248, 14486, - 10995, 642, 13817, 13779, 6468, 8664, 11634, 9780, -14636, -982, - 11746, -722, 108, -16195, -13199, -13289, 5114, 12941, 7110, 8873, - 16385, -13774, -14761, 10047, -15566, -9584, 9707, 2483, 16383, - -16366, -11423, 16354, 7362, 13147, -11538, -13904, -15052, -8862, - 8811, -16371, -12146, 7660, -9638, -13254, -6923, 3, -5, -2, -6, - 1, 6, 5, -8, -2, 3, -5, 0, -2, -4, 3 -}; - - -/*----------------------------------------------------------------------------------* - * Tables for ISF Quantizers - * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - * Used in lib_com\disf.c, lib_dec\isf_dec.c and lib_enc\isf_enc.c - *----------------------------------------------------------------------------------*/ - -/*----------------------------------------------------------------------------------* - * MA prediction coefficients for gain quantizer - * Used in "lib_enc\gain_enc.c" and "lib_dec\gain_dec.c". - *----------------------------------------------------------------------------------*/ - - -/* Initial LSF/ISF memory */ -const Word16 lsf_init[16] = /*14Q1*1.28*/ -{ - 960, 1920, 2880, 3840, 4800, 5760, 6720, 7680, 8640, 9600, 10560, 11520, 12480, 13440, 14400, 15360 -}; - - -/*----------------------------------------------------------------------------------* - * Bitstream packing ordering: - * Nb of bits per quantization index for each coding mode for layers R1 - R5 - * Used in lib_enc\bits_enc.c and lib_dec\bits_dec.c - *----------------------------------------------------------------------------------*/ - -const Word16 gain_corr_fac[3]= {0x4155, 0x40A9, 0x4055}; /* pow(10, 2^(-n-2)/28) (1Q14) */ -const Word16 gain_corr_inv_fac[3]= {0x7D67, 0x7EB2, 0x7F59}; /* pow(10,-2^(-n-2)/28) (0Q15) */ - -/* interpolation windows: Hann * modified Hamming */ -const Word16 inter4_2tcx2[4][4] = -{ - { 7620/*0.2325402f Q15*/, 17528/*0.5349195f Q15*/, 7620/*0.2325402f Q15*/, 0/*0.0000000f Q15*/ }, - { 4434/*0.1353017f Q15*/, 16694/*0.5094465f Q15*/, 11141/*0.3400065f Q15*/, 500/*0.0152453f Q15*/ }, - { 1995/*0.0608774f Q15*/, 14389/*0.4391226f Q15*/, 14389/*0.4391226f Q15*/, 1995/*0.0608774f Q15*/ }, - { 500/*0.0152453f Q15*/, 11141/*0.3400065f Q15*/, 16694/*0.5094465f Q15*/, 4434/*0.1353017f Q15*/ } -}; -const Word16 inter6_2tcx2[6][4] = -{ - { 7345/*0.2241379f Q15*/, 18079/*0.5517241f Q15*/, 7345/*0.2241379f Q15*/, 0/*0.0000000f Q15*/ }, - { 5119/*0.1562044f Q15*/, 17657/*0.5388595f Q15*/, 9798/*0.2990011f Q15*/, 194/*0.0059349f Q15*/ }, - { 3249/*0.0991379f Q15*/, 16444/*0.5018346f Q15*/, 12288/*0.3750000f Q15*/, 787/*0.0240275f Q15*/ }, - { 1800/*0.0549361f Q15*/, 14584/*0.4450639f Q15*/, 14584/*0.4450639f Q15*/, 1800/*0.0549361f Q15*/ }, - { 787/*0.0240275f Q15*/, 12288/*0.3750000f Q15*/, 16444/*0.5018346f Q15*/, 3249/*0.0991379f Q15*/ }, - { 194/*0.0059349f Q15*/, 9798/*0.2990011f Q15*/, 17657/*0.5388595f Q15*/, 5119/*0.1562044f Q15*/ } -}; - -const Word16 inter_core_12_8kHz_output_8kHz[] = -{ - 17528/*0.5349196f Q15*/, 16694/*0.5094466f Q15*/, 14389/*0.4391227f Q15*/, 11141/*0.3400065f Q15*/, - 7620/*0.2325402f Q15*/, 4434/*0.1353016f Q15*/, 1995/*0.0608773f Q15*/, 500/*0.0152453f Q15*/, - 0/*0.0000000f Q15*/ -}; -const Word16 inter_core_12_8kHz_output_16kHz[] = -{ - 14023/*0.4279357f Q15*/, 13592/*0.4147958f Q15*/, 12367/*0.3774199f Q15*/, 10533/*0.3214508f Q15*/, - 8350/*0.2548195f Q15*/, 6096/*0.1860321f Q15*/, 4017/*0.1225801f Q15*/, 2291/*0.0699165f Q15*/, - 1023/*0.0312127f Q15*/, 256/*0.0078047f Q15*/, 0/*0.0000000f Q15*/, 0/*0.0000000f Q15*/, - 0/*0.0000000f Q15*/ -}; -const Word16 inter_core_12_8kHz_output_32kHz[] = -{ - 7011/*0.2139679f Q15*/, 6957/*0.2123089f Q15*/, 6796/*0.2073979f Q15*/, 6535/*0.1994284f Q15*/, - 6184/*0.1887100f Q15*/, 5756/*0.1756491f Q15*/, 5267/*0.1607254f Q15*/, 4734/*0.1444646f Q15*/, - 4175/*0.1274097f Q15*/, 3608/*0.1100939f Q15*/, 3048/*0.0930161f Q15*/, 2511/*0.0766219f Q15*/, - 2008/*0.0612900f Q15*/, 1551/*0.0473253f Q15*/, 1146/*0.0349583f Q15*/, 798/*0.0243509f Q15*/, - 511/*0.0156063f Q15*/, 288/*0.0087817f Q15*/, 128/*0.0039024f Q15*/, 32/*0.0009753f Q15*/, - 0/*0.0000000f Q15*/ -}; -const Word16 inter_core_12_8kHz_output_48kHz[] = -{ - 4674/*0.1426452f Q15*/, 4658/*0.1421528f Q15*/, 4610/*0.1406841f Q15*/, 4531/*0.1382653f Q15*/, - 4422/*0.1349386f Q15*/, 4285/*0.1307618f Q15*/, 4122/*0.1258066f Q15*/, 3937/*0.1201564f Q15*/, - 3732/*0.1139041f Q15*/, 3511/*0.1071503f Q15*/, 3277/*0.1000000f Q15*/, 3033/*0.0925607f Q15*/, - 2783/*0.0849398f Q15*/, 2531/*0.0772420f Q15*/, 2280/*0.0695677f Q15*/, 2032/*0.0620107f Q15*/, - 1791/*0.0546572f Q15*/, 1559/*0.0475844f Q15*/, 1339/*0.0408600f Q15*/, 1132/*0.0345417f Q15*/, - 940/*0.0286774f Q15*/, 764/*0.0233055f Q15*/, 605/*0.0184558f Q15*/, 464/*0.0141503f Q15*/, - 341/*0.0104042f Q15*/, 237/*0.0072274f Q15*/, 152/*0.0046257f Q15*/, 85/*0.0026016f Q15*/, - 38/*0.0011560f Q15*/, 9/*0.0002890f Q15*/, 0/*0.0000000f Q15*/, 0/*0.0000000f Q15*/, - 0/*0.0000000f Q15*/ -}; -const Word16 inter_core_16kHz_output_8kHz[] = -{ - 18079/*0.5517241f Q15*/, 17657/*0.5388595f Q15*/, 16444/*0.5018346f Q15*/, 14584/*0.4450639f Q15*/, 12288/*0.3750000f Q15*/, 9798/*0.2990011f Q15*/, - 7345/*0.2241379f Q15*/, 5119/*0.1562044f Q15*/, 3249/*0.0991379f Q15*/, 1800/*0.0549361f Q15*/, 787/*0.0240275f Q15*/, 194/*0.0059349f Q15*/, - 0/*0.0000000f Q15*/ -}; -const Word16 inter_core_16kHz_output_16kHz[] = -{ - 18079/*0.5517241f Q15*/, 17657/*0.5388595f Q15*/, 16444/*0.5018346f Q15*/, 14584/*0.4450639f Q15*/, 12288/*0.3750000f Q15*/, 9798/*0.2990011f Q15*/, - 7345/*0.2241379f Q15*/, 5119/*0.1562044f Q15*/, 3249/*0.0991379f Q15*/, 1800/*0.0549361f Q15*/, 787/*0.0240275f Q15*/, 194/*0.0059349f Q15*/, - 0/*0.0000000f Q15*/ -}; -const Word16 inter_core_16kHz_output_32kHz[] = -{ - 9039/*0.2758621f Q15*/, 8986/*0.2742414f Q15*/, 8829/*0.2694298f Q15*/, 8571/*0.2615753f Q15*/, 8222/*0.2509173f Q15*/, 7791/*0.2377748f Q15*/, - 7292/*0.2225320f Q15*/, 6738/*0.2056203f Q15*/, 6144/*0.1875000f Q15*/, 5526/*0.1686403f Q15*/, 4899/*0.1495006f Q15*/, 4277/*0.1305132f Q15*/, - 3672/*0.1120690f Q15*/, 3097/*0.0945060f Q15*/, 2559/*0.0781022f Q15*/, 2067/*0.0630725f Q15*/, 1624/*0.0495690f Q15*/, 1235/*0.0376861f Q15*/, - 900/*0.0274680f Q15*/, 620/*0.0189188f Q15*/, 394/*0.0120137f Q15*/, 220/*0.0067120f Q15*/, 97/*0.0029675f Q15*/, 24/*0.0007394f Q15*/, - 0/*0.0000000f Q15*/ -}; -const Word16 inter_core_16kHz_output_48kHz[] = -{ - 6026/*0.1839080f Q15*/, 6011/*0.1834272f Q15*/, 5963/*0.1819912f Q15*/, 5886/*0.1796198f Q15*/, 5778/*0.1763457f Q15*/, 5643/*0.1722133f Q15*/, - 5481/*0.1672782f Q15*/, 5296/*0.1616061f Q15*/, 5088/*0.1552712f Q15*/, 4861/*0.1483546f Q15*/, 4618/*0.1409433f Q15*/, 4362/*0.1331275f Q15*/, - 4096/*0.1250000f Q15*/, 3823/*0.1166535f Q15*/, 3545/*0.1081796f Q15*/, 3266/*0.0996670f Q15*/, 2988/*0.0912002f Q15*/, 2715/*0.0828579f Q15*/, - 2448/*0.0747126f Q15*/, 2190/*0.0668293f Q15*/, 1942/*0.0592649f Q15*/, 1706/*0.0520681f Q15*/, 1484/*0.0452794f Q15*/, 1276/*0.0389306f Q15*/, - 1083/*0.0330460f Q15*/, 906/*0.0276422f Q15*/, 745/*0.0227295f Q15*/, 600/*0.0183120f Q15*/, 472/*0.0143894f Q15*/, 359/*0.0109575f Q15*/, - 262/*0.0080092f Q15*/, 181/*0.0055360f Q15*/, 116/*0.0035286f Q15*/, 65/*0.0019783f Q15*/, 29/*0.0008771f Q15*/, 7/*0.0002189f Q15*/, - 0/*0.0000000f Q15*/ -}; -const Word16 inter_core_25_6kHz_output_8kHz[] = -{ - 17528/*0.5349196f Q15*/, 16694/*0.5094466f Q15*/, 14389/*0.4391227f Q15*/, 11141/*0.3400065f Q15*/, - 7620/*0.2325402f Q15*/, 4434/*0.1353016f Q15*/, 1995/*0.0608773f Q15*/, 500/*0.0152453f Q15*/, - 0/*0.0000000f Q15*/ -}; -const Word16 inter_core_25_6kHz_output_16kHz[] = -{ - 17528/*0.5349196f Q15*/, 16694/*0.5094466f Q15*/, 14389/*0.4391227f Q15*/, 11141/*0.3400065f Q15*/, - 7620/*0.2325402f Q15*/, 4434/*0.1353016f Q15*/, 1995/*0.0608773f Q15*/, 500/*0.0152453f Q15*/, - 0/*0.0000000f Q15*/ -}; -const Word16 inter_core_25_6kHz_output_32kHz[] = -{ - 14023/*0.4279357f Q15*/, 13592/*0.4147958f Q15*/, 12367/*0.3774199f Q15*/, 10533/*0.3214508f Q15*/, - 8350/*0.2548195f Q15*/, 6096/*0.1860321f Q15*/, 4017/*0.1225801f Q15*/, 2291/*0.0699165f Q15*/, - 1023/*0.0312127f Q15*/, 256/*0.0078047f Q15*/, 0/*0.0000000f Q15*/, 0/*0.0000000f Q15*/, - 0/*0.0000000f Q15*/ -}; -const Word16 inter_core_25_6kHz_output_48kHz[] = -{ - 9349/*0.2852965f Q15*/, 9220/*0.2813740f Q15*/, 8843/*0.2698819f Q15*/, 8245/*0.2516166f Q15*/, - 7465/*0.2278099f Q15*/, 6554/*0.2000000f Q15*/, 5567/*0.1698781f Q15*/, 4559/*0.1391327f Q15*/, - 3582/*0.1093111f Q15*/, 2678/*0.0817166f Q15*/, 1879/*0.0573517f Q15*/, 1209/*0.0369093f Q15*/, - 682/*0.0208069f Q15*/, 303/*0.0092505f Q15*/, 76/*0.0023118f Q15*/, 0/*0.0000000f Q15*/, - 0/*0.0000000f Q15*/ -}; - -const TCX_LTP_FILTER tcxLtpFilters[12] = -{ - { inter_core_12_8kHz_output_8kHz, 2 }, - { inter_core_12_8kHz_output_16kHz, 3 }, - { inter_core_12_8kHz_output_32kHz, 5 }, - { inter_core_12_8kHz_output_48kHz, 8 }, - { inter_core_16kHz_output_8kHz, 2 }, - { inter_core_16kHz_output_16kHz, 2 }, - { inter_core_16kHz_output_32kHz, 4 }, - { inter_core_16kHz_output_48kHz, 6 }, - { inter_core_25_6kHz_output_8kHz, 2 }, - { inter_core_25_6kHz_output_16kHz, 2 }, - { inter_core_25_6kHz_output_32kHz, 3 }, - { inter_core_25_6kHz_output_48kHz, 4 }, -}; - -const SCALE_TCX_SETUP scaleTcxTable[13] = -{ - { 0, 0, 8000, 21955/*0.67f Q15*/ }, - { 0, 8000, 9600, 22938/*0.70f Q15*/ }, - { 0, 9600, 13200, 24904/*0.76f Q15*/ }, - { 0, 13200, 16400, 28180/*0.86f Q15*/ }, - { 0, 16400, 24400, 29491/*0.90f Q15*/ }, - { 0, 24400, 64000, 31457/*0.96f Q15*/ }, - { 1, 0, 8000, 32767/*1.f Q15*/ }, - { 1, 8000, 9600, 32767/*1.f Q15*/ }, - { 1, 9600, 13200, 32767/*1.f Q15*/ }, - { 1, 13200, 16400, 27853/*0.85f Q15*/ }, - { 1, 16400, 24400, 28836/*0.88f Q15*/ }, - { 1, 24400, 32000, 29491/*0.90f Q15*/ }, - { 1, 32000, 32400, 31130/*0.95f Q15*/ }, -}; - - -/*----------------------------------------------------------------------------------* -* Quantization table for pitch and innovation gain (gamma) * -*----------------------------------------------------------------------------------*/ -const Word16 E_ROM_qua_gain5b_const[NB_QUA_GAIN5B * 2] = -{ - 1774,577, - 2090,1805, - 2103,3371, - 3908,1116, - 4834,2500, - 6030,4763, - 6838,1334, - 7490,2033, - 8585,3036, - 9845,1575, - 10437,2320, - 10649,3739, - 11298,945, - 12108,1920, - 12310,5108, - 12391,2758, - 12659,1237, - 13729,1557, - 13798,2201, - 13972,3275, - 14881,993, - 15175,1776, - 15409,16190, - 15551,2395, - 15879,4048, - 16341,1335, - 16988,2918, - 18317,7449, - 18368,2026, - 19114,1364, - 19991,4472, - 20644,2790, -}; -#define QUA_PITCH_E 1 -#define QUA_CODE_E 4 - -const Word16 E_ROM_qua_gain6b_const[NB_QUA_GAIN6B * 2] = -{ - 0,2758, - 143,3562, - 397,2146, - 544,4306, - 952,1726, - 1236,724, - 1779,3158, - 1820,5448, - 1975,2473, - 2121,1343, - 3049,3912, - 3081,1885, - 3289,8261, - 3416,2843, - 3495,2204, - 3831,3386, - 4295,4590, - 4300,2476, - 4345,1545, - 4913,1122, - 5198,2080, - 5200,3079, - 5448,3714, - 5482,2689, - 5546,1817, - 5783,17318, - 5934,6236, - 6156,2320, - 6481,4225, - 6828,3351, - 6832,5045, - 6888,2895, - 7186,2559, - 7214,1663, - 7373,2052, - 7906,3819, - 8192,1372, - 8452,3063, - 8464,2354, - 9021,4468, - 9037,2715, - 9175,1874, - 9219,3463, - 9831,2155, - 10523,5383, - 10557,9061, - 10618,3093, - 10633,3949, - 10890,2465, - 11141,1654, - 12132,2790, - 12180,3477, - 12376,2079, - 12494,4560, - 14430,2468, - 14573,3914, - 14576,3111, - 15043,1827, - 15207,1329, - 16073,6155, - 17519,4719, - 18345,2148, - 18554,2784, - 18576,3563, -}; - -const Word16 E_ROM_qua_gain7b_const[NB_QUA_GAIN7B * 2] = -{ - 123,2777, - 369,2102, - 404,4368, - 693,3486, - 1107,719, - 1222,1679, - 1657,1293, - 1667,5547, - 1805,2425, - 2369,3075, - 2489,12063, - 2681,1901, - 2693,3984, - 3031,7547, - 3248,990, - 3466,2672, - 3674,2165, - 3718,1513, - 3844,3456, - 4120,4656, - 4748,2967, - 4821,19622, - 4855,2400, - 4912,1776, - 5245,3860, - 5312,6282, - 5500,1176, - 5713,2056, - 5872,3287, - 5960,2662, - 6170,9756, - 6364,5021, - 6545,1476, - 6788,2283, - 6796,4163, - 7038,2949, - 7216,1831, - 7274,3516, - 7707,2510, - 8123,5762, - 8361,4485, - 8376,2110, - 8594,3135, - 8611,3755, - 8634,1570, - 8636,2748, - 8683,8222, - 9274,335, - 9512,2404, - 9640,5020, - 9690,1893, - 9778,3361, - 9808,15435, - 9936,4029, - 10194,2767, - 10306,6510, - 10325,1252, - 10686,2186, - 10844,32767, - 10913,4453, - 10968,3078, - 11044,1666, - 11076,3609, - 11398,2509, - 11423,5160, - 11848,1994, - 11997,2823, - 12002,3880, - 12084,7573, - 12129,3325, - 12214,5867, - 12331,1496, - 12450,4245, - 12458,2283, - 12768,901, - 12896,4741, - 12898,1811, - 12902,2569, - 12983,2959, - 13173,3331, - 13413,2059, - 13416,3734, - 13429,10641, - 13448,1148, - 13615,5340, - 13674,1425, - 13779,2332, - 13847,4264, - 13909,2657, - 13958,6488, - 14047,3085, - 14130,1648, - 14547,1915, - 14554,3684, - 14749,2739, - 14868,5017, - 14875,2216, - 14898,3197, - 14988,1085, - 15026,4246, - 15375,7971, - 15421,1446, - 15548,2462, - 15722,5920, - 15882,3449, - 15960,1782, - 15994,2863, - 16365,3977, - 16419,4754, - 16472,2162, - 17378,3101, - 17410,2550, - 17743,1339, - 17856,5485, - 17979,1982, - 17996,3628, - 18041,7110, - 18242,4381, - 18602,22207, - 19373,12827, - 19533,2777, - 19640,1678, - 19728,2272, - 19795,8861, - 20065,3275, - 20133,4881, - 20198,3947, - 20290,6128, -}; - -/*----------------------------------------------------------------------------------* - * Quantization table for scaled innovation energy prediction, Q8 * - * Used in "gain_pre.c" * - *----------------------------------------------------------------------------------*/ -const Word16 Es_pred_qua[8] = -{ - 1521/* 5.9422f Q8*/, - 3909/*15.2711f Q8*/, - 5987/*23.3857f Q8*/, - 7816/*30.5310f Q8*/, - 9477/*37.0190f Q8*/, - 11124/*43.4539f Q8*/, - 12863/*50.2442f Q8*/, - 15031/*58.7164f Q8*/ -}; - -const Word16 Es_pred_qua_2[16] = -{ - -1280/*-5.f Q8*/, - 0/* 0.f Q8*/, - 1280/* 5.f Q8*/, - 2560/*10.f Q8*/, - 3840/*15.f Q8*/, - 5120/*20.f Q8*/, - 6400/*25.f Q8*/, - 7680/*30.f Q8*/, - 8960/*35.f Q8*/, - 10240/*40.f Q8*/, - 11520/*45.f Q8*/, - 12800/*50.f Q8*/, - 14080/*55.f Q8*/, - 15360/*60.f Q8*/, - 16640/*65.f Q8*/, - 17920/*70.f Q8*/ -}; - - -const Word16 lag_window_8k[2][16] = /* LAGW_STRONG */ -{ - /* h */ { 32728, 32619, 32438, 32187, 31867, 31480, 31029, 30517, 29946, 29321, 28645, 27923, 27158, 26356, 25521, 24658 }, - /* l */ { 11904, 17280, 30720, 25856, 24192, 28992, 24384, 7360, 19456, 14720, 22080, 12928, 31040, 27328, 22080, 5184 } -}; -const Word16 lag_window_12k8[NUM_LAGW_STRENGTHS][2][16] = -{ - /* LAGW_WEAK */ - { - /* h */ { 32763, 32758, 32750, 32739, 32725, 32707, 32687, 32663, 32637, 32607, 32574, 32538, 32498, 32456, 32411, 32362 }, - /* l */ { 4736, 13312, 16896, 15360, 8896, 30464, 14528, 27008, 2496, 6720, 7296, 4480, 31424, 22976, 12160, 32384 } - }, - /* LAGW_MEDIUM */ - { - /* h */ { 32758, 32739, 32707, 32663, 32607, 32538, 32456, 32362, 32257, 32139, 32009, 31867, 31714, 31549, 31374, 31187 }, - /* l */ { 13312, 15360, 30464, 27008, 6720, 4480, 22976, 32384, 3520, 5888, 11200, 24192, 17472, 29376, 576, 3136 } - }, - /* LAGW_STRONG */ - { - /* h */ { 32750, 32707, 32637, 32538, 32411, 32257, 32075, 31867, 31633, 31374, 31089, 30780, 30449, 30094, 29718, 29321 }, - /* l */ { 16896, 30464, 2496, 4480, 12160, 3520, 24256, 24192, 20736, 576, 18240, 31488, 128, 16704, 11520, 14720 } - } -}; -const Word16 lag_window_16k[NUM_LAGW_STRENGTHS][2][16] = -{ - /* LAGW_WEAK */ - { - /* h */ { 32763, 32760, 32755, 32748, 32739, 32728, 32715, 32700, 32682, 32663, 32642, 32619, 32594, 32567, 32538, 32507 }, - /* l */ { 23360, 22272, 20672, 18304, 15360, 11904, 8000, 3648, 31808, 27008, 22080, 17280, 12608, 8256, 4480, 1344 } - }, - /* LAGW_MEDIUM */ - { - /* h */ { 32760, 32748, 32728, 32700, 32663, 32619, 32567, 32507, 32438, 32362, 32279, 32187, 32088, 31981, 31867, 31746 }, - /* l */ { 22272, 18304, 11904, 3648, 27008, 17280, 8256, 1344, 30720, 32384, 8256, 25856, 21824, 31360, 24192, 3072 } - }, - /* LAGW_STRONG */ - { - /* h */ { 32755, 32728, 32682, 32619, 32538, 32438, 32322, 32187, 32036, 31867, 31682, 31480, 31263, 31029, 30780, 30517 }, - /* l */ { 20672, 11904, 31808, 17280, 4480, 30720, 2944, 25856, 8320, 24192, 16896, 28992, 5824, 24384, 31488, 7360 } - } -}; -const Word16 lag_window_25k6[NUM_LAGW_STRENGTHS][2][16] = -{ - /* LAGW_WEAK */ - { - /* h */ { 32764, 32763, 32761, 32758, 32754, 32750, 32745, 32739, 32732, 32725, 32716, 32707, 32698, 32687, 32676, 32663 }, - /* l */ { 10752, 4736, 5568, 13312, 28096, 16896, 12672, 15360, 25024, 8896, 32576, 30464, 2624, 14528, 832, 27008 } - }, - /* LAGW_MEDIUM */ - { - /* h */ { 32763, 32758, 32750, 32739, 32725, 32707, 32687, 32663, 32637, 32607, 32574, 32538, 32498, 32456, 32411, 32362 }, - /* l */ { 4736, 13312, 16896, 15360, 8896, 30464, 14528, 27008, 2496, 6720, 7296, 4480, 31424, 22976, 12160, 32384 } - }, - /* LAGW_STRONG */ - { - /* h */ { 32761, 32750, 32732, 32707, 32676, 32637, 32591, 32538, 32478, 32411, 32337, 32257, 32169, 32075, 31975, 31867 }, - /* l */ { 5568, 16896, 25024, 30464, 832, 2496, 3328, 4480, 7040, 12160, 21440, 3520, 25728, 24256, 1216, 24192 } - } -}; -const Word16 lag_window_32k[NUM_LAGW_STRENGTHS][2][16] = -{ - /* LAGW_WEAK */ - { - /* h */ { 32764, 32763, 32762, 32760, 32758, 32755, 32752, 32748, 32744, 32739, 32734, 32728, 32722, 32715, 32707, 32700 }, - /* l */ { 15424, 23360, 14720, 22272, 13312, 20672, 11328, 18304, 8704, 15360, 5504, 11904, 1792, 8000, 30464, 3648 } - }, - /* LAGW_MEDIUM */ - { - /* h */ { 32763, 32760, 32755, 32748, 32739, 32728, 32715, 32700, 32682, 32663, 32642, 32619, 32594, 32567, 32538, 32507 }, - /* l */ { 23360, 22272, 20672, 18304, 15360, 11904, 8000, 3648, 31808, 27008, 22080, 17280, 12608, 8256, 4480, 1344 } - }, - /* LAGW_STRONG */ - { - /* h */ { 32762, 32755, 32744, 32728, 32707, 32682, 32653, 32619, 32581, 32538, 32490, 32438, 32382, 32322, 32257, 32187 }, - /* l */ { 14720, 20672, 8704, 11904, 30464, 31808, 16384, 17280, 2240, 4480, 24704, 30720, 23168, 2944, 3520, 25856 } - } -}; -const Word16 lag_window_48k[2][16] = /* LAGW_STRONG */ -{ - /* h */ { 32763, 32760, 32755, 32748, 32739, 32728, 32715, 32700, 32682, 32663, 32642, 32619, 32594, 32567, 32538, 32507 }, - /* l */ { 23360, 22272, 20672, 18304, 15360, 11904, 8000, 3648, 31808, 27008, 22080, 17280, 12608, 8256, 4480, 1344 } -}; - - -#define W16(x) ((Word16)x) - -const Word16 d_array[18] = { 1, 2, 5, 8, 10, 15, 20, 30, 40, 60, 80, 120, 140, 160, 180, 220, 260, 300 }; -const Word16 m_array[18] = { 0/*0.000f Q15*/, 8520/*0.260f Q15*/, 15729/*0.480f Q15*/, 19005/*0.580f Q15*/, 19988/*0.610f Q15*/, 21889/*0.668f Q15*/, 23101/*0.705f Q15*/, 24969/*0.762f Q15*/, 26214/*0.800f Q15*/, 27558/*0.841f Q15*/, 28344/*0.865f Q15*/, 29164/*0.890f Q15*/, 29491/*0.900f Q15*/, 29819/*0.910f Q15*/, 30147/*0.920f Q15*/, 30474/*0.930f Q15*/, 30638/*0.935f Q15*/, 30802/*0.940f Q15*/ }; -const Word16 msQeqInvAv_thresh[3] = { 328/*0.01f Q15*/, 983/*0.03f Q15*/, 1638/*0.05f Q15*/ }; -const Word16 msNoiseSlopeMax[4] = { 32767/*2.f Q14*/, 26214/*1.6f Q14*/, 21299/*1.3f Q14*/, 18022/*1.1f Q14*/ }; -const Word16 preemphCompensation[NB_BANDS] = { 19960/*9.7461f Q11*/, 19493/*9.5182f Q11*/, 18486/*9.0262f Q11*/, 17099/*8.3493f Q11*/, 15516/*7.5764f Q11*/, 13893/*6.7838f Q11*/, 11956/*5.8377f Q11*/, 9933/*4.8502f Q11*/, 8263/*4.0346f Q11*/, 6715/*3.2788f Q11*/, 5383/*2.6283f Q11*/, 4284/*2.0920f Q11*/, 3339/*1.6304f Q11*/, 2632/*1.2850f Q11*/, 2070/*1.0108f Q11*/, 1621/*0.7916f Q11*/, 1284/*0.6268f Q11*/, 1026/*0.5011f Q11*/, 844/*0.4119f Q11*/, 745/*0.3637f Q11*/ }; - -const SCALE_SETUP scaleTable[20] = -{ - { 0, 8000, -704/*-5.5f Q7*/, 0 }, - { 8000, 9600, -640/*-5.0f Q7*/, 0 }, - { 9600, 13200, -512/*-4.0f Q7*/, 0 }, - { 13200, 16400, -384/*-3.0f Q7*/, 0 }, - { 16400, 24400, -192/*-1.5f Q7*/, 0 }, - { 24400, 64001, -64/*-0.5f Q7*/, 0 }, - - { 0, 8000, -704/*-5.5f Q7*/, 1 }, - { 8000, 9600, -640/*-5.0f Q7*/, 1 }, - - { 9600, 13200, -198/*-1.55f Q7*/, 1 }, - { 13200, 16400, -384/*-3.0f Q7*/, 1 }, - - { 16400, 24400, -77/*-0.6f Q7*/, 1 }, - { 24400, 32000, -26/*-0.2f Q7*/, 1 }, - { 32000,128001, 0/* 0.0f Q7*/, 1 }, - - { 0, 8000, -115/*-0.9f Q7*/, 2 }, - { 8000, 9600, -83/*-0.65f Q7*/, 2 }, - { 9600, 13200, -256/*-2.0f Q7*/, 2 }, - { 13200, 16400, -384/*-3.0f Q7*/, 2 }, - - { 16400, 24400, -102/*-0.8f Q7*/, 2 }, - { 24400, 32000, -32/*-0.25f Q7*/, 2 }, - { 32000,128001, 0/* 0.0f Q7*/, 2 }, -}; - -/* - Element scale is precalculated in the following way (fomat: Q2.14): - - scaleTable_cn_only[i].scale = pow( 10.f,-scaleTable_cn_only[i].scale/10.f ) - 1.f; -*/ -const SCALE_SETUP scaleTable_cn_only[18] = -{ - { 0, 8000, 20295/*1.2387211385 Q14*/ /*-3.5f*/, 0 }, - { 8000, 9600, 16306/*0.9952622652 Q14*/ /*-3.0f*/, 0 }, - { 9600, 13200, 12751/*0.7782794237 Q14*/ /*-2.5f*/, 0 }, - { 13200, 16400, 9583/*0.5848932266 Q14*/ /*-2.0f*/, 0 }, - { 16400,128001, 0/*0.0000000000 Q14*/ /* 0.0f*/, 0 }, - - { 0, 8000, 16306/*0.9952622652 Q14*/ /*-3.0f*/, 1 }, - { 8000, 9600, 12751/*0.7782794237 Q14*/ /*-2.5f*/, 1 }, - { 9600, 13200, 6759/*0.4125375748 Q14*/ /*-1.5f*/, 1 }, - { 13200, 16400, 12751/*0.7782794237 Q14*/ /*-2.5f*/, 1 }, - { 16400, 24400, 1999/*0.1220184565 Q14*/ /*-0.5f*/, 1 }, - { 24400,128001, 0/*0.0000000000 Q14*/ /* 0.0f*/, 1 }, - - { 0, 8000, 12751/*0.7782794237 Q14*/ /*-2.0f*/, 2 }, - { 8000, 9600, 12751/*0.7782794237 Q14*/ /*-2.0f*/, 2 }, - { 9600, 13200, 9583/*0.5848932266 Q14*/ /*-2.0f*/, 2 }, - { 13200, 16400, 4242/*0.2589254379 Q14*/ /*-1.0f*/, 2 }, - - { 16400, 24400, 1999/*0.1220184565 Q14*/ /*-0.5f*/, 2 }, - { 24400, 32000, 0/*0.0000000000 Q14*/ /* 0.0f*/, 2 }, - { 32000,128001, 0/*0.0000000000 Q14*/ /* 0.0f*/, 2 } -}; - -const Word16 scaleTable_cn_only_amrwbio[3][2] = -{ - { ACELP_6k60, 24771/*1.5118864315 Q14*/ }, - { ACELP_8k85, 16306/*0.9952622652 Q14*/ }, - { ACELP_12k65, 9583/*0.5848932266 Q14*/ }, -}; - -const Word16 sidparts_encoder_noise_est[24] = { 4, 8, 12, 16, 20, 24, 30, 36, 42, 50, 58, 68, 80, 92, 108, 126, 148, 176, 212, 255, 259, 264, 269, 279 }; - -const Word16 sidPartitions_nb[] = { 4, 8, 12, 16, 20, 24, 30, 36, 42, 50, 58, 68, 80, 92, 108, 126, 159 }; -const Word16 sidPartitions_wb1[] = { 4, 8, 12, 16, 20, 24, 30, 36, 42, 50, 58, 68, 80, 92, 108, 126, 148, 176, 212, 255 }; -const Word16 sidPartitions_wb2[] = { 4, 8, 12, 16, 20, 24, 30, 36, 42, 50, 58, 68, 80, 92, 108, 126, 148, 176, 212, 255, 259 }; -const Word16 sidPartitions_wb3[] = { 4, 8, 12, 16, 20, 24, 30, 36, 42, 50, 58, 68, 80, 92, 108, 126, 148, 176, 212, 255, 319 }; -const Word16 sidPartitions_swb1[] = { 4, 8, 12, 16, 20, 24, 30, 36, 42, 50, 58, 68, 80, 92, 108, 126, 148, 176, 212, 255, 259, 264, 269, 274 }; -const Word16 sidPartitions_swb2[] = { 4, 8, 12, 16, 20, 24, 30, 36, 42, 50, 58, 68, 80, 92, 108, 126, 148, 176, 212, 255, 319, 324, 329, 339 }; - -const Word16 shapingPartitions_nb[] = { 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 25, 28, 31, 34, 37, 40, 43, 47, 51, 55, 59, 64, 69, 74, 80, 86, 93, 100, 108, 117, 126, 136, 159 }; -const Word16 shapingPartitions_wb1[] = { 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 25, 28, 31, 34, 37, 40, 43, 47, 51, 55, 59, 64, 69, 74, 80, 86, 93, 100, 108, 117, 126, 135, 148, 162, 176, 192, 212, 232, 255 }; -const Word16 shapingPartitions_wb2[] = { 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 25, 28, 31, 34, 37, 40, 43, 47, 51, 55, 59, 64, 69, 74, 80, 86, 93, 100, 108, 117, 126, 135, 148, 162, 176, 192, 212, 232, 255 }; -const Word16 shapingPartitions_wb3[] = { 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 25, 28, 31, 34, 37, 40, 43, 47, 51, 55, 59, 64, 69, 74, 80, 86, 93, 100, 108, 117, 126, 136, 148, 176, 212, 256, 308, 319 }; -const Word16 shapingPartitions_swb1[] = { 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 25, 28, 31, 34, 37, 40, 43, 47, 51, 55, 59, 64, 69, 74, 80, 86, 93, 100, 108, 117, 126, 135, 148, 162, 176, 192, 212, 232, 255 }; -const Word16 shapingPartitions_swb2[] = { 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 25, 28, 31, 34, 37, 40, 43, 47, 51, 55, 59, 64, 69, 74, 80, 86, 93, 100, 108, 117, 126, 136, 148, 176, 212, 256, 308, 319 }; - -const FD_CNG_SETUP FdCngSetup_nb = { 512, 160, sizeof(sidPartitions_nb)/sizeof(Word16), sidPartitions_nb, sizeof(shapingPartitions_nb)/sizeof(Word16), shapingPartitions_nb }; -const FD_CNG_SETUP FdCngSetup_wb1 = { 512, 256, sizeof(sidPartitions_wb1)/sizeof(Word16), sidPartitions_wb1, sizeof(shapingPartitions_wb1)/sizeof(Word16), shapingPartitions_wb1 }; -const FD_CNG_SETUP FdCngSetup_wb2 = { 512, 256, sizeof(sidPartitions_wb2)/sizeof(Word16), sidPartitions_wb2, sizeof(shapingPartitions_wb2)/sizeof(Word16), shapingPartitions_wb2 }; -const FD_CNG_SETUP FdCngSetup_wb3 = { 640, 320, sizeof(sidPartitions_wb3)/sizeof(Word16), sidPartitions_wb3, sizeof(shapingPartitions_wb3)/sizeof(Word16), shapingPartitions_wb3 }; -const FD_CNG_SETUP FdCngSetup_swb1 = { 512, 256, sizeof(sidPartitions_swb1)/sizeof(Word16), sidPartitions_swb1, sizeof(shapingPartitions_swb1)/sizeof(Word16), shapingPartitions_swb1 }; -const FD_CNG_SETUP FdCngSetup_swb2 = { 640, 320, sizeof(sidPartitions_swb2)/sizeof(Word16), sidPartitions_swb2, sizeof(shapingPartitions_swb2)/sizeof(Word16), shapingPartitions_swb2 }; - -const Word16 maxN_37bits = 24; -const Word16 maxC_37bits = 8; -const Word16 stages_37bits = 6; -const Word16 levels_37bits[6] = { 128, 64, 64, 64, 64, 64 }; -const Word16 bits_37bits[6] = { 7, 6, 6, 6, 6, 6 }; - -const Word16 cdk_37bits_1_fx[3072] = -{ - W16(0x017B), W16(0x0548), W16(0x068C), W16(0x058B), W16(0x0572), W16(0x0577), W16(0x04BC), W16(0x03C0), - W16(0x0399), W16(0x0237), W16(0x00A1), W16(0xFEB3), W16(0xFCFA), W16(0xFC2F), W16(0xFACB), W16(0xFA70), - W16(0xF914), W16(0xF6A8), W16(0xF439), W16(0xF145), W16(0xF02C), W16(0xEFDD), W16(0xEE63), W16(0xED8C), - W16(0x089B), W16(0x0B41), W16(0x08E4), W16(0x079C), W16(0x05CF), W16(0x03F9), W16(0x03E0), W16(0x031E), - W16(0x02E2), W16(0x0212), W16(0x0015), W16(0xFECD), W16(0xFF39), W16(0xFE3F), W16(0xFBE8), W16(0xFA04), - W16(0xF7FF), W16(0xF5BC), W16(0xF361), W16(0xF14A), W16(0xEFCE), W16(0xEDF1), W16(0xEC58), W16(0xEB8A), - W16(0x0815), W16(0x0642), W16(0x0569), W16(0x03C1), W16(0x044B), W16(0x04DB), W16(0x0474), W16(0x03DF), - W16(0x0432), W16(0x030C), W16(0x0121), W16(0xFF19), W16(0xFD1C), W16(0xFCAE), W16(0xFAF1), W16(0xF9F7), - W16(0xF85E), W16(0xF5DD), W16(0xF370), W16(0xF072), W16(0xEF52), W16(0xEF6F), W16(0xEE06), W16(0xED0C), - W16(0x10A9), W16(0x0DA2), W16(0x0C21), W16(0x0A1E), W16(0x0854), W16(0x07D7), W16(0x0690), W16(0x0658), - W16(0x043C), W16(0x036E), W16(0x00B9), W16(0xFE78), W16(0xFC8A), W16(0xFAEB), W16(0xF926), W16(0xF6C2), - W16(0xF4B5), W16(0xF2B1), W16(0xF0CD), W16(0xEED0), W16(0xEDF7), W16(0xEC97), W16(0xEBD3), W16(0xEB6E), - W16(0xFA8A), W16(0x0181), W16(0x03DF), W16(0x04A4), W16(0x0331), W16(0x0599), W16(0x04DB), W16(0x03CB), - W16(0x0005), W16(0x0161), W16(0xFF3F), W16(0xFEFE), W16(0xFEC7), W16(0xFCED), W16(0xFB97), W16(0xFBA7), - W16(0xFBFC), W16(0xFA73), W16(0xF96A), W16(0xF909), W16(0xF92B), W16(0xF7C3), W16(0xF6C5), W16(0xF5F7), - W16(0x1095), W16(0x0E41), W16(0x096C), W16(0x0813), W16(0x0652), W16(0x046A), W16(0x0423), W16(0x0350), - W16(0x034C), W16(0x023D), W16(0x0074), W16(0xFEC0), W16(0xFF76), W16(0xFE66), W16(0xFB60), W16(0xF90E), - W16(0xF6CC), W16(0xF4B3), W16(0xF27A), W16(0xF058), W16(0xEF09), W16(0xED48), W16(0xEBE3), W16(0xEB2E), - W16(0x0DA9), W16(0x0772), W16(0x056E), W16(0x041F), W16(0x039A), W16(0x0308), W16(0x02C3), W16(0x0275), - W16(0x0221), W16(0x01B5), W16(0x00ED), W16(0x0049), W16(0xFEF4), W16(0xFD31), W16(0xFC0A), W16(0xFBD5), - W16(0xFB17), W16(0xF8FF), W16(0xF705), W16(0xF603), W16(0xF494), W16(0xF2D4), W16(0xF031), W16(0xEDB6), - W16(0x14D0), W16(0x0F44), W16(0x0DF3), W16(0x0C0E), W16(0x0938), W16(0x07D3), W16(0x06C1), W16(0x0522), - W16(0x0475), W16(0x02EA), W16(0x004B), W16(0xFE88), W16(0xFC2B), W16(0xFAAC), W16(0xF8C9), W16(0xF73A), - W16(0xF605), W16(0xF554), W16(0xF3ED), W16(0xF31F), W16(0xF305), W16(0xF26A), W16(0xF225), W16(0xF1E6), - W16(0xFE9B), W16(0x0403), W16(0x0558), W16(0x0336), W16(0x0433), W16(0x02F7), W16(0x01DD), W16(0x012C), - W16(0x016C), W16(0x0124), W16(0x0041), W16(0xFFAF), W16(0xFF0E), W16(0xFE2D), W16(0xFCE7), W16(0xFC8B), - W16(0xFCA0), W16(0xFB7D), W16(0xF975), W16(0xF831), W16(0xF73E), W16(0xF582), W16(0xF394), W16(0xF20E), - W16(0x079D), W16(0x0AD6), W16(0x0B5A), W16(0x09A9), W16(0x084A), W16(0x0738), W16(0x066E), W16(0x0608), - W16(0x047C), W16(0x02E1), W16(0x0059), W16(0xFE81), W16(0xFCD0), W16(0xFABD), W16(0xF93B), W16(0xF769), - W16(0xF5A1), W16(0xF44F), W16(0xF26B), W16(0xEFCD), W16(0xEE85), W16(0xECDA), W16(0xEBE5), W16(0xEB83), - W16(0x04A1), W16(0x0509), W16(0x0556), W16(0x044A), W16(0x038A), W16(0x030A), W16(0x02B8), W16(0x0255), - W16(0x0212), W16(0x01BB), W16(0x0101), W16(0x0035), W16(0xFEEC), W16(0xFD22), W16(0xFC1D), W16(0xFBF2), - W16(0xFB3F), W16(0xF91E), W16(0xF70F), W16(0xF5E9), W16(0xF49C), W16(0xF2E0), W16(0xF02D), W16(0xEDA3), - W16(0x0D77), W16(0x0DC1), W16(0x0D75), W16(0x0AA8), W16(0x0814), W16(0x065D), W16(0x0456), W16(0x0451), - W16(0x0310), W16(0x02B3), W16(0x0134), W16(0xFEFC), W16(0xFD02), W16(0xFB55), W16(0xFA2D), W16(0xF891), - W16(0xF7E0), W16(0xF6F0), W16(0xF59C), W16(0xF425), W16(0xF3A2), W16(0xF253), W16(0xF1DF), W16(0xF188), - W16(0x0274), W16(0x04F8), W16(0x0575), W16(0x048C), W16(0x044E), W16(0x0467), W16(0x0413), W16(0x040C), - W16(0x0213), W16(0x00C8), W16(0x001D), W16(0xFEF2), W16(0xFE21), W16(0xFCF7), W16(0xFC59), W16(0xFB5C), - W16(0xFA76), W16(0xF9A5), W16(0xF914), W16(0xF8D4), W16(0xF853), W16(0xF770), W16(0xF5D5), W16(0xF40D), - W16(0x1148), W16(0x0E53), W16(0x09F3), W16(0x085C), W16(0x0711), W16(0x04CC), W16(0x0453), W16(0x03F2), - W16(0x03BA), W16(0x0278), W16(0x0090), W16(0xFF0A), W16(0xFED1), W16(0xFD92), W16(0xFA84), W16(0xF871), - W16(0xF6BA), W16(0xF489), W16(0xF23B), W16(0xEFD0), W16(0xEED3), W16(0xED71), W16(0xEC93), W16(0xEBF6), - W16(0x0AED), W16(0x075D), W16(0x05A3), W16(0x0493), W16(0x0446), W16(0x0463), W16(0x0411), W16(0x0422), - W16(0x0219), W16(0x00C6), W16(0x001A), W16(0xFF06), W16(0xFE27), W16(0xFCEF), W16(0xFC57), W16(0xFB4F), - W16(0xFA6B), W16(0xF9A0), W16(0xF90D), W16(0xF8CA), W16(0xF827), W16(0xF757), W16(0xF5C4), W16(0xF400), - W16(0x155D), W16(0x0F9F), W16(0x0C38), W16(0x09DC), W16(0x07A7), W16(0x053D), W16(0x03A9), W16(0x051C), - W16(0x04ED), W16(0x02A2), W16(0x00D4), W16(0xFF7C), W16(0xFDB2), W16(0xFBBA), W16(0xF8EA), W16(0xF824), - W16(0xF7FD), W16(0xF68C), W16(0xF3DB), W16(0xF2A3), W16(0xF27D), W16(0xF19C), W16(0xF0C9), W16(0xEFDB), - W16(0xFFCD), W16(0x038E), W16(0x0463), W16(0x037C), W16(0x0340), W16(0x02A6), W16(0x02AB), W16(0x0290), - W16(0x0288), W16(0x01E2), W16(0x00EF), W16(0x002F), W16(0xFEA6), W16(0xFDA9), W16(0xFCAC), W16(0xFBAE), - W16(0xFAAF), W16(0xF96E), W16(0xF84B), W16(0xF6F3), W16(0xF4CD), W16(0xF2DA), W16(0xF0F7), W16(0xEEFD), - W16(0x0C53), W16(0x0BF8), W16(0x0C2B), W16(0x0A1A), W16(0x077A), W16(0x0556), W16(0x03F4), W16(0x03E3), - W16(0x0259), W16(0x01FA), W16(0x0084), W16(0xFE9B), W16(0xFD34), W16(0xFBF2), W16(0xFAFB), W16(0xF9EA), - W16(0xF9DD), W16(0xF9E2), W16(0xF898), W16(0xF6CB), W16(0xF505), W16(0xF2D8), W16(0xF195), W16(0xF0B6), - W16(0x07BE), W16(0x054B), W16(0x0435), W16(0x030E), W16(0x03A2), W16(0x03DA), W16(0x0342), W16(0x026B), - W16(0x01E4), W16(0x0170), W16(0x00CE), W16(0x0009), W16(0xFDFF), W16(0xFE36), W16(0xFCBF), W16(0xFC00), - W16(0xF9B8), W16(0xF7AD), W16(0xF51D), W16(0xF180), W16(0xF15B), W16(0xF1C5), W16(0xF045), W16(0xEF23), - W16(0x0FD5), W16(0x0D41), W16(0x0B8A), W16(0x09BD), W16(0x0838), W16(0x0754), W16(0x0692), W16(0x0611), - W16(0x0487), W16(0x02ED), W16(0x0044), W16(0xFE7B), W16(0xFCBA), W16(0xFAA6), W16(0xF92D), W16(0xF773), - W16(0xF59D), W16(0xF47B), W16(0xF29E), W16(0xEFF4), W16(0xEE86), W16(0xECCF), W16(0xEBD8), W16(0xEB78), - W16(0xFDB6), W16(0x0365), W16(0x05CE), W16(0x0610), W16(0x0505), W16(0x035E), W16(0x02CE), W16(0x01CF), - W16(0x0089), W16(0x00B8), W16(0xFFD1), W16(0xFF08), W16(0xFEAA), W16(0xFE04), W16(0xFDC1), W16(0xFC29), - W16(0xFC4E), W16(0xFB7A), W16(0xFAAD), W16(0xF9D2), W16(0xF818), W16(0xF6F3), W16(0xF5A0), W16(0xF46B), - W16(0x1008), W16(0x0D2C), W16(0x08D0), W16(0x0746), W16(0x05AB), W16(0x039D), W16(0x035A), W16(0x0295), - W16(0x02A9), W16(0x01D8), W16(0x001B), W16(0xFF0D), W16(0xFF48), W16(0xFE4F), W16(0xFBEB), W16(0xFA8C), - W16(0xF912), W16(0xF65C), W16(0xF3E1), W16(0xF14F), W16(0xEF83), W16(0xED7D), W16(0xEBAE), W16(0xEACA), - W16(0x0DAD), W16(0x08AD), W16(0x075B), W16(0x059B), W16(0x04DC), W16(0x0476), W16(0x03F2), W16(0x025C), - W16(0x010B), W16(0x009F), W16(0xFFDA), W16(0xFE63), W16(0xFDF1), W16(0xFDBE), W16(0xFD7D), W16(0xFC45), - W16(0xFB08), W16(0xFA08), W16(0xF8CA), W16(0xF795), W16(0xF5B6), W16(0xF412), W16(0xF2D3), W16(0xF1F4), - W16(0x15E3), W16(0x0F2D), W16(0x0DD2), W16(0x0BB2), W16(0x0912), W16(0x080C), W16(0x06B1), W16(0x0509), - W16(0x03F9), W16(0x0210), W16(0xFF8C), W16(0xFE56), W16(0xFC61), W16(0xFAFD), W16(0xF94E), W16(0xF7D6), - W16(0xF6BB), W16(0xF61C), W16(0xF49D), W16(0xF3F1), W16(0xF3E4), W16(0xF35B), W16(0xF31D), W16(0xF2DF), - W16(0x02E6), W16(0x0643), W16(0x0700), W16(0x05A9), W16(0x04E3), W16(0x047E), W16(0x03C0), W16(0x0266), - W16(0x012B), W16(0x0098), W16(0xFFD2), W16(0xFE89), W16(0xFDF6), W16(0xFD9F), W16(0xFD4A), W16(0xFC4C), - W16(0xFB32), W16(0xFA7B), W16(0xF96E), W16(0xF878), W16(0xF743), W16(0xF5CA), W16(0xF486), W16(0xF36B), - W16(0x080C), W16(0x0B47), W16(0x0BE1), W16(0x0A0A), W16(0x086F), W16(0x079C), W16(0x06AD), W16(0x063D), - W16(0x0465), W16(0x031D), W16(0x0054), W16(0xFE68), W16(0xFCB0), W16(0xFAAD), W16(0xF917), W16(0xF735), - W16(0xF525), W16(0xF3D8), W16(0xF29D), W16(0xF191), W16(0xF0EF), W16(0xF025), W16(0xEF93), W16(0xEF3F), - W16(0x0839), W16(0x0628), W16(0x04DB), W16(0x039C), W16(0x0365), W16(0x02CB), W16(0x029E), W16(0x02A9), - W16(0x02BC), W16(0x01F6), W16(0x0101), W16(0x0026), W16(0xFEB0), W16(0xFDA0), W16(0xFC84), W16(0xFB74), - W16(0xFA68), W16(0xF932), W16(0xF804), W16(0xF691), W16(0xF46D), W16(0xF26E), W16(0xF079), W16(0xEE80), - W16(0x0AC8), W16(0x0CCE), W16(0x0DA8), W16(0x0C60), W16(0x0994), W16(0x083E), W16(0x06D0), W16(0x0529), - W16(0x03EA), W16(0x0249), W16(0xFFB9), W16(0xFE3A), W16(0xFC21), W16(0xFAFA), W16(0xF90B), W16(0xF78E), - W16(0xF65C), W16(0xF571), W16(0xF418), W16(0xF331), W16(0xF33A), W16(0xF29F), W16(0xF24C), W16(0xF219), - W16(0x05E1), W16(0x05CC), W16(0x05EE), W16(0x060D), W16(0x0517), W16(0x0357), W16(0x02C0), W16(0x01D0), - W16(0x0085), W16(0x00B0), W16(0xFFD1), W16(0xFF12), W16(0xFEAD), W16(0xFE06), W16(0xFDBA), W16(0xFC2D), - W16(0xFC50), W16(0xFB87), W16(0xFAB7), W16(0xF9DA), W16(0xF80B), W16(0xF6EC), W16(0xF59D), W16(0xF469), - W16(0x11D1), W16(0x0F70), W16(0x0A08), W16(0x087F), W16(0x068E), W16(0x04B0), W16(0x0432), W16(0x0375), - W16(0x0389), W16(0x023A), W16(0x0028), W16(0xFEB9), W16(0xFF3A), W16(0xFE36), W16(0xFAFC), W16(0xF915), - W16(0xF6F6), W16(0xF510), W16(0xF2CC), W16(0xF0F8), W16(0xEFEB), W16(0xEE83), W16(0xED84), W16(0xECD7), - W16(0x0B3B), W16(0x096D), W16(0x06CD), W16(0x050E), W16(0x04AD), W16(0x034C), W16(0x0288), W16(0x0224), - W16(0x0190), W16(0x0137), W16(0x0015), W16(0xFF8F), W16(0xFE3C), W16(0xFDD9), W16(0xFD04), W16(0xFC60), - W16(0xFB77), W16(0xFAAD), W16(0xF9FB), W16(0xF936), W16(0xF7EF), W16(0xF65B), W16(0xF5A2), W16(0xF4D2), - W16(0x16C0), W16(0x0F48), W16(0x0C90), W16(0x09AC), W16(0x0757), W16(0x058C), W16(0x03D0), W16(0x03AF), - W16(0x0284), W16(0x0249), W16(0x00FA), W16(0xFF36), W16(0xFD66), W16(0xFC00), W16(0xFB05), W16(0xF96E), - W16(0xF8C8), W16(0xF7E7), W16(0xF66D), W16(0xF49F), W16(0xF350), W16(0xF21E), W16(0xF1CA), W16(0xF174), - W16(0xFFE5), W16(0x03B4), W16(0x04C3), W16(0x0399), W16(0x0448), W16(0x049E), W16(0x0425), W16(0x035F), - W16(0x03B2), W16(0x0263), W16(0x00C3), W16(0xFED0), W16(0xFCF3), W16(0xFCDA), W16(0xFBD9), W16(0xFADE), - W16(0xF96B), W16(0xF760), W16(0xF516), W16(0xF1F5), W16(0xF126), W16(0xF0FC), W16(0xEFBB), W16(0xEE91), - W16(0x0A14), W16(0x0BD9), W16(0x0A05), W16(0x08A9), W16(0x06EE), W16(0x04E1), W16(0x0468), W16(0x03AB), - W16(0x0385), W16(0x026A), W16(0x005B), W16(0xFED5), W16(0xFECC), W16(0xFD95), W16(0xFAE2), W16(0xF8D1), - W16(0xF6EB), W16(0xF51F), W16(0xF2F7), W16(0xF0C4), W16(0xEFFB), W16(0xEEB0), W16(0xEDCF), W16(0xED30), - W16(0x0A84), W16(0x07B7), W16(0x0699), W16(0x0588), W16(0x04F8), W16(0x0512), W16(0x0439), W16(0x0387), - W16(0x0354), W16(0x01E7), W16(0x0081), W16(0xFEBF), W16(0xFD3C), W16(0xFC6A), W16(0xFB27), W16(0xFB1A), - W16(0xF9D4), W16(0xF7D3), W16(0xF57F), W16(0xF254), W16(0xF0C2), W16(0xF08D), W16(0xEF08), W16(0xEE09), - W16(0x10BB), W16(0x0E08), W16(0x0CA3), W16(0x0ABA), W16(0x0932), W16(0x0815), W16(0x0737), W16(0x0671), - W16(0x04A3), W16(0x0325), W16(0x0024), W16(0xFE61), W16(0xFC7D), W16(0xFA41), W16(0xF8AF), W16(0xF6FF), - W16(0xF459), W16(0xF2FA), W16(0xF103), W16(0xEF58), W16(0xEE8C), W16(0xED3F), W16(0xEC8D), W16(0xEC48), - W16(0xFCE7), W16(0x0381), W16(0x0337), W16(0x05B9), W16(0x054D), W16(0x01C2), W16(0x0285), W16(0x05FF), - W16(0x013C), W16(0x0143), W16(0x0019), W16(0xFFAB), W16(0xFE36), W16(0xFDDC), W16(0xFC25), W16(0xFB58), - W16(0xFA9A), W16(0xF9FC), W16(0xF8BF), W16(0xF861), W16(0xF87B), W16(0xF713), W16(0xF660), W16(0xF5C9), - W16(0x112E), W16(0x0E94), W16(0x08F3), W16(0x07FC), W16(0x0620), W16(0x044C), W16(0x0403), W16(0x035F), - W16(0x0357), W16(0x0235), W16(0x0029), W16(0xFEA5), W16(0xFF72), W16(0xFE6C), W16(0xFB9C), W16(0xF945), - W16(0xF71B), W16(0xF4FC), W16(0xF2BD), W16(0xF0CA), W16(0xEF8E), W16(0xEDBD), W16(0xEC47), W16(0xEB7F), - W16(0x0E4C), W16(0x084A), W16(0x05D9), W16(0x0481), W16(0x034C), W16(0x02CB), W16(0x0294), W16(0x0222), - W16(0x01EB), W16(0x018D), W16(0x00E0), W16(0x001B), W16(0xFED4), W16(0xFD0C), W16(0xFC56), W16(0xFC9B), - W16(0xFBEE), W16(0xF9CE), W16(0xF7CA), W16(0xF718), W16(0xF5C9), W16(0xF440), W16(0xF1F2), W16(0xEFE7), - W16(0x1518), W16(0x0FD5), W16(0x0E18), W16(0x0C03), W16(0x08E7), W16(0x072A), W16(0x0631), W16(0x04D7), - W16(0x04EC), W16(0x039D), W16(0x00F4), W16(0xFF9B), W16(0xFC59), W16(0xFA81), W16(0xF87B), W16(0xF6DF), - W16(0xF59C), W16(0xF4DC), W16(0xF365), W16(0xF2A1), W16(0xF298), W16(0xF1F8), W16(0xF1A0), W16(0xF168), - W16(0x0193), W16(0x04EA), W16(0x0536), W16(0x03C4), W16(0x0354), W16(0x02B6), W16(0x022D), W16(0x01B1), - W16(0x01AC), W16(0x011E), W16(0x007D), W16(0xFF96), W16(0xFE78), W16(0xFE21), W16(0xFD66), W16(0xFCDE), - W16(0xFC5D), W16(0xFB38), W16(0xFA40), W16(0xF988), W16(0xF86B), W16(0xF70D), W16(0xF58F), W16(0xF3DD), - W16(0x0872), W16(0x0B35), W16(0x0BE0), W16(0x0A14), W16(0x085B), W16(0x07D8), W16(0x0687), W16(0x064C), - W16(0x042E), W16(0x034F), W16(0x00AC), W16(0xFE7B), W16(0xFC91), W16(0xFAF1), W16(0xF933), W16(0xF6D6), - W16(0xF4CC), W16(0xF2CC), W16(0xF0E3), W16(0xEED3), W16(0xEE16), W16(0xECB7), W16(0xEBFA), W16(0xEB9C), - W16(0x0708), W16(0x0631), W16(0x05B1), W16(0x0338), W16(0x042E), W16(0x02E0), W16(0x01D3), W16(0x0124), - W16(0x0171), W16(0x0125), W16(0x003C), W16(0xFFB6), W16(0xFF19), W16(0xFE36), W16(0xFCDF), W16(0xFC93), - W16(0xFCB2), W16(0xFB91), W16(0xF970), W16(0xF83C), W16(0xF74E), W16(0xF596), W16(0xF399), W16(0xF20D), - W16(0x0E8A), W16(0x0F20), W16(0x0E41), W16(0x0B71), W16(0x087A), W16(0x0680), W16(0x049F), W16(0x0516), - W16(0x03B9), W16(0x02FF), W16(0x00FE), W16(0xFF01), W16(0xFCC6), W16(0xFAF5), W16(0xF9B5), W16(0xF808), - W16(0xF723), W16(0xF645), W16(0xF4AE), W16(0xF322), W16(0xF373), W16(0xF254), W16(0xF1FF), W16(0xF1A5), - W16(0x0539), W16(0x05F3), W16(0x0351), W16(0x05D6), W16(0x057A), W16(0x01D0), W16(0x02A3), W16(0x061D), - W16(0x0131), W16(0x0123), W16(0x001A), W16(0xFFA6), W16(0xFE21), W16(0xFDF1), W16(0xFC22), W16(0xFB38), - W16(0xFA75), W16(0xF9E5), W16(0xF892), W16(0xF846), W16(0xF85C), W16(0xF702), W16(0xF669), W16(0xF5E2), - W16(0x11C4), W16(0x0EE5), W16(0x09CF), W16(0x086F), W16(0x068D), W16(0x04AD), W16(0x043D), W16(0x0386), - W16(0x0384), W16(0x027C), W16(0x0077), W16(0xFED8), W16(0xFF16), W16(0xFDD4), W16(0xFB2A), W16(0xF8DE), - W16(0xF6C3), W16(0xF499), W16(0xF24C), W16(0xF02F), W16(0xEF1F), W16(0xEDB6), W16(0xECAD), W16(0xEC0A), - W16(0x09CA), W16(0x0743), W16(0x0573), W16(0x03BB), W16(0x034A), W16(0x02AD), W16(0x0229), W16(0x01B9), - W16(0x018E), W16(0x0112), W16(0x0075), W16(0xFF8F), W16(0xFE7F), W16(0xFE2A), W16(0xFD67), W16(0xFCF4), - W16(0xFC7F), W16(0xFB43), W16(0xFA39), W16(0xF989), W16(0xF871), W16(0xF721), W16(0xF598), W16(0xF3DE), - W16(0x16BC), W16(0x10D3), W16(0x0D86), W16(0x0A30), W16(0x079A), W16(0x057B), W16(0x0420), W16(0x0535), - W16(0x0495), W16(0x0281), W16(0x00C9), W16(0xFF84), W16(0xFD9F), W16(0xFB53), W16(0xF904), W16(0xF835), - W16(0xF809), W16(0xF6A4), W16(0xF4AF), W16(0xF3FE), W16(0xF3EE), W16(0xF31F), W16(0xF259), W16(0xF157), - W16(0x01AD), W16(0x053B), W16(0x0656), W16(0x0556), W16(0x046F), W16(0x03B5), W16(0x0334), W16(0x02C7), - W16(0x0264), W16(0x01B2), W16(0x00D3), W16(0xFF8F), W16(0xFE4B), W16(0xFD3C), W16(0xFC6F), W16(0xFB21), - W16(0xFA52), W16(0xF98D), W16(0xF87D), W16(0xF719), W16(0xF592), W16(0xF3B2), W16(0xF1D6), W16(0xF003), - W16(0x0C15), W16(0x0D4E), W16(0x0C6F), W16(0x09F0), W16(0x0798), W16(0x057F), W16(0x03B6), W16(0x053F), - W16(0x04D0), W16(0x027D), W16(0x00B2), W16(0xFF76), W16(0xFD90), W16(0xFB93), W16(0xF8F0), W16(0xF84F), - W16(0xF81D), W16(0xF6AC), W16(0xF3F7), W16(0xF2AC), W16(0xF2B0), W16(0xF1D0), W16(0xF0FF), W16(0xF006), - W16(0x085E), W16(0x06B3), W16(0x05AE), W16(0x0410), W16(0x0456), W16(0x04FE), W16(0x0396), W16(0x01B6), - W16(0x01EC), W16(0x01B1), W16(0x00D9), W16(0xFEC7), W16(0xFC6D), W16(0xFD63), W16(0xFD25), W16(0xFC60), - W16(0xFACF), W16(0xF9CC), W16(0xF78F), W16(0xF3CC), W16(0xF205), W16(0xF190), W16(0xF022), W16(0xEEC5), - W16(0x1269), W16(0x0F13), W16(0x0C2F), W16(0x09FB), W16(0x08A4), W16(0x07AC), W16(0x065B), W16(0x05EC), - W16(0x045F), W16(0x0299), W16(0x0050), W16(0xFE59), W16(0xFC74), W16(0xFA2F), W16(0xF8C8), W16(0xF7B8), - W16(0xF6A4), W16(0xF54D), W16(0xF3CB), W16(0xF224), W16(0xF148), W16(0xF06F), W16(0xEF7F), W16(0xEE7E), - W16(0xFFA0), W16(0xFFC1), W16(0xFFFB), W16(0x0001), W16(0xFFFD), W16(0xFFCA), W16(0xFFF1), W16(0x0006), - W16(0xFFE3), W16(0xFFCB), W16(0xFFF5), W16(0xFFD8), W16(0xFFD5), W16(0xFFFA), W16(0xFFE9), W16(0xFFCE), - W16(0xFFE8), W16(0xFFEE), W16(0xFFF6), W16(0xFFE1), W16(0x0003), W16(0xFF8C), W16(0xFFD1), W16(0xFF89), - W16(0x1069), W16(0x0D77), W16(0x08FD), W16(0x07C3), W16(0x061F), W16(0x03F0), W16(0x03F7), W16(0x0359), - W16(0x031A), W16(0x0270), W16(0x001B), W16(0xFED7), W16(0xFF68), W16(0xFE31), W16(0xFBAB), W16(0xF969), - W16(0xF779), W16(0xF559), W16(0xF2FD), W16(0xF114), W16(0xEF9C), W16(0xEDC8), W16(0xEC2D), W16(0xEB5B), - W16(0x0BD5), W16(0x0963), W16(0x07B7), W16(0x059A), W16(0x0436), W16(0x030F), W16(0x02AB), W16(0x029A), - W16(0x0257), W16(0x01D3), W16(0x00C4), W16(0xFF32), W16(0xFE18), W16(0xFDB7), W16(0xFCD5), W16(0xFBB2), - W16(0xFB00), W16(0xFA03), W16(0xF8EB), W16(0xF7B3), W16(0xF66E), W16(0xF4C1), W16(0xF341), W16(0xF1C3), - W16(0x186B), W16(0x111B), W16(0x0E20), W16(0x0BE5), W16(0x0994), W16(0x082F), W16(0x06C3), W16(0x0601), - W16(0x03CB), W16(0x0249), W16(0xFFC8), W16(0xFD34), W16(0xFB66), W16(0xFA33), W16(0xF94F), W16(0xF816), - W16(0xF76C), W16(0xF6E3), W16(0xF580), W16(0xF44A), W16(0xF3F4), W16(0xF2F1), W16(0xF2CF), W16(0xF28D), - W16(0x02D3), W16(0x06E5), W16(0x0678), W16(0x050E), W16(0x04A0), W16(0x035A), W16(0x027D), W16(0x0212), - W16(0x019A), W16(0x0120), W16(0x0016), W16(0xFF9E), W16(0xFE40), W16(0xFDCC), W16(0xFD09), W16(0xFC6A), - W16(0xFB8A), W16(0xFAC7), W16(0xFA21), W16(0xF976), W16(0xF835), W16(0xF696), W16(0xF5F2), W16(0xF50D), - W16(0x0A01), W16(0x0C87), W16(0x0BD7), W16(0x09CF), W16(0x086E), W16(0x076D), W16(0x062A), W16(0x05DD), - W16(0x0447), W16(0x0273), W16(0x0050), W16(0xFE70), W16(0xFC86), W16(0xFA57), W16(0xF910), W16(0xF7E5), - W16(0xF6D3), W16(0xF563), W16(0xF3DE), W16(0xF23B), W16(0xF17A), W16(0xF0BD), W16(0xEFBF), W16(0xEE9E), - W16(0x0A10), W16(0x079A), W16(0x06A0), W16(0x0554), W16(0x0475), W16(0x03BB), W16(0x0339), W16(0x02DB), - W16(0x0266), W16(0x01BF), W16(0x00E0), W16(0xFFA1), W16(0xFE4A), W16(0xFD45), W16(0xFC62), W16(0xFAF5), - W16(0xFA2F), W16(0xF979), W16(0xF869), W16(0xF6ED), W16(0xF555), W16(0xF37E), W16(0xF18A), W16(0xEFB7), - W16(0x0D46), W16(0x0D11), W16(0x0DEA), W16(0x0C1D), W16(0x0970), W16(0x084C), W16(0x06D2), W16(0x04E1), - W16(0x03A5), W16(0x020C), W16(0xFFA4), W16(0xFE5E), W16(0xFC58), W16(0xFB02), W16(0xF934), W16(0xF7BF), - W16(0xF692), W16(0xF5F1), W16(0xF48F), W16(0xF3D2), W16(0xF402), W16(0xF368), W16(0xF32B), W16(0xF2F2), - W16(0x0876), W16(0x07D2), W16(0x0757), W16(0x0496), W16(0x05DC), W16(0x045E), W16(0x02DF), W16(0x01A8), - W16(0x01EA), W16(0x0169), W16(0x0001), W16(0xFF2F), W16(0xFE65), W16(0xFD1C), W16(0xFBA4), W16(0xFB98), - W16(0xFBFE), W16(0xFB3B), W16(0xF953), W16(0xF821), W16(0xF7CD), W16(0xF644), W16(0xF4DD), W16(0xF399), - W16(0x10A3), W16(0x0E7E), W16(0x0943), W16(0x081D), W16(0x05EA), W16(0x0408), W16(0x037A), W16(0x031F), - W16(0x02C7), W16(0x01C3), W16(0x0046), W16(0xFEAD), W16(0xFFE1), W16(0xFEC1), W16(0xFBF2), W16(0xF9BF), - W16(0xF7A7), W16(0xF5C0), W16(0xF418), W16(0xF2DA), W16(0xF21C), W16(0xF133), W16(0xF05E), W16(0xEFBD), - W16(0x0DD5), W16(0x0AB1), W16(0x07A5), W16(0x05A6), W16(0x039F), W16(0x0209), W16(0x011E), W16(0x0100), - W16(0x010F), W16(0x012F), W16(0x008E), W16(0xFFF7), W16(0xFF30), W16(0xFE68), W16(0xFDC0), W16(0xFD5D), - W16(0xFCC0), W16(0xFB85), W16(0xFA5F), W16(0xF96C), W16(0xF839), W16(0xF71D), W16(0xF53F), W16(0xF428), - W16(0x1716), W16(0x11B9), W16(0x0DD2), W16(0x0A4B), W16(0x078C), W16(0x05AC), W16(0x042E), W16(0x0529), - W16(0x04B4), W16(0x0269), W16(0x00B9), W16(0xFF59), W16(0xFD99), W16(0xFB32), W16(0xF900), W16(0xF87D), - W16(0xF7F9), W16(0xF6CC), W16(0xF57A), W16(0xF51D), W16(0xF511), W16(0xF454), W16(0xF397), W16(0xF29F), - W16(0x02C7), W16(0x058B), W16(0x0656), W16(0x05B0), W16(0x052D), W16(0x04E3), W16(0x03C6), W16(0x02CC), - W16(0x02A2), W16(0x01CE), W16(0x00A6), W16(0xFF3B), W16(0xFD87), W16(0xFCC8), W16(0xFB6D), W16(0xFB5E), - W16(0xF9F2), W16(0xF7BA), W16(0xF574), W16(0xF25D), W16(0xF166), W16(0xF16B), W16(0xEFD8), W16(0xEF18), - W16(0x0910), W16(0x0C5A), W16(0x0967), W16(0x0839), W16(0x065E), W16(0x045E), W16(0x0412), W16(0x036E), - W16(0x0345), W16(0x0235), W16(0x006F), W16(0xFEB8), W16(0xFF3E), W16(0xFE47), W16(0xFB6E), W16(0xF930), - W16(0xF700), W16(0xF4E2), W16(0xF2AA), W16(0xF095), W16(0xEF83), W16(0xEDD9), W16(0xEC8E), W16(0xEBD7), - W16(0x09A7), W16(0x07C5), W16(0x06F4), W16(0x05C1), W16(0x05B1), W16(0x059E), W16(0x04D3), W16(0x03A8), - W16(0x037B), W16(0x022E), W16(0x00A4), W16(0xFEBE), W16(0xFCF4), W16(0xFC2C), W16(0xFAC8), W16(0xFA59), - W16(0xF8EB), W16(0xF684), W16(0xF414), W16(0xF147), W16(0xF047), W16(0xEFF3), W16(0xEE8A), W16(0xEDC3), - W16(0x106C), W16(0x0D7F), W16(0x0BFD), W16(0x0A0C), W16(0x0897), W16(0x079B), W16(0x06B6), W16(0x0638), - W16(0x0494), W16(0x0315), W16(0x005C), W16(0xFE8A), W16(0xFCCC), W16(0xFA95), W16(0xF905), W16(0xF730), - W16(0xF4BB), W16(0xF34B), W16(0xF14A), W16(0xEF4B), W16(0xEE4B), W16(0xECE3), W16(0xEC19), W16(0xEBD6), - W16(0xFB0B), W16(0x0267), W16(0x048B), W16(0x0582), W16(0x03A0), W16(0x0601), W16(0x0513), W16(0x03E6), - W16(0x0004), W16(0x019D), W16(0xFF41), W16(0xFF1D), W16(0xFD75), W16(0xFCF1), W16(0xFBE7), W16(0xFBD7), - W16(0xFB42), W16(0xFA9B), W16(0xF9D3), W16(0xF97A), W16(0xF991), W16(0xF7F4), W16(0xF72B), W16(0xF5EF), - W16(0x10F7), W16(0x0EDE), W16(0x099F), W16(0x089E), W16(0x0663), W16(0x046B), W16(0x041E), W16(0x038F), - W16(0x035D), W16(0x0207), W16(0x0097), W16(0xFEB0), W16(0xFF14), W16(0xFE44), W16(0xFB5A), W16(0xF923), - W16(0xF705), W16(0xF4FB), W16(0xF2DA), W16(0xF0DF), W16(0xEFC8), W16(0xEDFA), W16(0xEC6A), W16(0xEBA3), - W16(0x0F44), W16(0x09B4), W16(0x0661), W16(0x04A1), W16(0x035A), W16(0x02DD), W16(0x0284), W16(0x0201), - W16(0x01CE), W16(0x01CB), W16(0x012A), W16(0x0044), W16(0xFEED), W16(0xFD34), W16(0xFC6E), W16(0xFC2C), - W16(0xFB81), W16(0xF985), W16(0xF769), W16(0xF645), W16(0xF538), W16(0xF3BD), W16(0xF0F6), W16(0xEE24), - W16(0x159C), W16(0x0F76), W16(0x0E25), W16(0x0C81), W16(0x098C), W16(0x083A), W16(0x06FD), W16(0x0592), - W16(0x0447), W16(0x027F), W16(0xFF9F), W16(0xFDDE), W16(0xFBC9), W16(0xFB42), W16(0xF8E5), W16(0xF761), - W16(0xF618), W16(0xF553), W16(0xF419), W16(0xF34C), W16(0xF35C), W16(0xF2E3), W16(0xF2AB), W16(0xF27E), - W16(0xFFEE), W16(0x05AA), W16(0x071D), W16(0x048C), W16(0x05D5), W16(0x0462), W16(0x02D5), W16(0x0197), - W16(0x01EF), W16(0x0172), W16(0x000F), W16(0xFF30), W16(0xFE66), W16(0xFD1C), W16(0xFBA3), W16(0xFB95), - W16(0xFC03), W16(0xFB3B), W16(0xF952), W16(0xF821), W16(0xF7E2), W16(0xF650), W16(0xF4EB), W16(0xF3A7), - W16(0x077D), W16(0x0A1F), W16(0x0ADC), W16(0x0956), W16(0x080F), W16(0x06D7), W16(0x0609), W16(0x0562), - W16(0x03B9), W16(0x0259), W16(0x0029), W16(0xFE97), W16(0xFCE1), W16(0xFB12), W16(0xF9D3), W16(0xF82B), - W16(0xF6EC), W16(0xF63E), W16(0xF528), W16(0xF2AC), W16(0xF084), W16(0xEE88), W16(0xED6A), W16(0xECA7), - W16(0x05E5), W16(0x05FC), W16(0x05B6), W16(0x0489), W16(0x0361), W16(0x02CE), W16(0x0299), W16(0x0210), - W16(0x01D8), W16(0x018E), W16(0x00E1), W16(0x0010), W16(0xFEC5), W16(0xFD05), W16(0xFC5B), W16(0xFCA7), - W16(0xFC05), W16(0xF9DD), W16(0xF7C1), W16(0xF717), W16(0xF5EC), W16(0xF446), W16(0xF1F0), W16(0xEFE7), - W16(0x0FC3), W16(0x0E43), W16(0x0D5A), W16(0x0A7E), W16(0x07E0), W16(0x05F8), W16(0x0422), W16(0x03E4), - W16(0x02BD), W16(0x026A), W16(0x00D4), W16(0xFEEF), W16(0xFD6B), W16(0xFBF5), W16(0xFAA4), W16(0xF8FD), - W16(0xF838), W16(0xF782), W16(0xF601), W16(0xF4A9), W16(0xF44B), W16(0xF307), W16(0xF2BC), W16(0xF270), - W16(0x0367), W16(0x05CB), W16(0x063A), W16(0x0526), W16(0x0498), W16(0x043E), W16(0x03A2), W16(0x02F4), - W16(0x0231), W16(0x0138), W16(0x0059), W16(0xFF18), W16(0xFE05), W16(0xFD20), W16(0xFC74), W16(0xFB8F), - W16(0xFA94), W16(0xF9C9), W16(0xF96E), W16(0xF949), W16(0xF8F1), W16(0xF80E), W16(0xF680), W16(0xF4B2), - W16(0x1231), W16(0x0E64), W16(0x0A87), W16(0x08C5), W16(0x06FC), W16(0x05D6), W16(0x0537), W16(0x04D6), - W16(0x03A3), W16(0x02C8), W16(0x002D), W16(0xFE7A), W16(0xFE22), W16(0xFCCD), W16(0xFA62), W16(0xF84A), - W16(0xF673), W16(0xF4BD), W16(0xF2A2), W16(0xF06F), W16(0xEFA0), W16(0xEE75), W16(0xEDAD), W16(0xED15), - W16(0x0BB9), W16(0x082C), W16(0x065F), W16(0x0530), W16(0x04A2), W16(0x0450), W16(0x03A7), W16(0x02F5), - W16(0x022F), W16(0x0136), W16(0x005D), W16(0xFF10), W16(0xFE02), W16(0xFD19), W16(0xFC6E), W16(0xFB88), - W16(0xFA8F), W16(0xF9C3), W16(0xF971), W16(0xF949), W16(0xF8E5), W16(0xF80B), W16(0xF680), W16(0xF4B1), - W16(0x1535), W16(0x1077), W16(0x0D5E), W16(0x0A03), W16(0x07A1), W16(0x05C2), W16(0x03E0), W16(0x053D), - W16(0x04B8), W16(0x025C), W16(0x009E), W16(0xFF61), W16(0xFD71), W16(0xFB83), W16(0xF8EF), W16(0xF856), - W16(0xF834), W16(0xF6D9), W16(0xF455), W16(0xF335), W16(0xF312), W16(0xF22D), W16(0xF15B), W16(0xF05C), - W16(0x00C3), W16(0x0490), W16(0x052A), W16(0x0455), W16(0x038A), W16(0x02EC), W16(0x02DF), W16(0x0265), - W16(0x021F), W16(0x0177), W16(0x00B8), W16(0xFFBB), W16(0xFE77), W16(0xFD94), W16(0xFCE7), W16(0xFC16), - W16(0xFB34), W16(0xFA39), W16(0xF949), W16(0xF82F), W16(0xF630), W16(0xF481), W16(0xF32D), W16(0xF19B), - W16(0x0CC9), W16(0x0C4E), W16(0x0C59), W16(0x09DA), W16(0x0795), W16(0x05C3), W16(0x03E9), W16(0x03D1), - W16(0x02C0), W16(0x026A), W16(0x00FD), W16(0xFF2B), W16(0xFD60), W16(0xFBC8), W16(0xFABF), W16(0xF92B), - W16(0xF88B), W16(0xF7D4), W16(0xF646), W16(0xF445), W16(0xF330), W16(0xF216), W16(0xF1D4), W16(0xF19B), - W16(0x0877), W16(0x069D), W16(0x0590), W16(0x0438), W16(0x04B3), W16(0x0508), W16(0x044D), W16(0x0304), - W16(0x0374), W16(0x0231), W16(0x00AB), W16(0xFE4C), W16(0xFC8B), W16(0xFC90), W16(0xFC1E), W16(0xFB28), - W16(0xF9F8), W16(0xF821), W16(0xF5B6), W16(0xF287), W16(0xF18B), W16(0xF10C), W16(0xEFD5), W16(0xEE9B), - W16(0x0FEF), W16(0x0C87), W16(0x0AF8), W16(0x094C), W16(0x0813), W16(0x06D4), W16(0x061E), W16(0x0572), - W16(0x03C3), W16(0x0254), W16(0x001C), W16(0xFE86), W16(0xFCDC), W16(0xFB0D), W16(0xF9D8), W16(0xF82F), - W16(0xF6E0), W16(0xF631), W16(0xF519), W16(0xF2AD), W16(0xF077), W16(0xEE89), W16(0xED6C), W16(0xECA4), - W16(0xFF6F), W16(0x0439), W16(0x05C2), W16(0x0700), W16(0x069C), W16(0x036E), W16(0x02AC), W16(0x011B), - W16(0x0056), W16(0x0068), W16(0x0017), W16(0xFF54), W16(0xFE8E), W16(0xFDF1), W16(0xFD91), W16(0xFC01), - W16(0xFBF7), W16(0xFA9F), W16(0xF9FE), W16(0xF95F), W16(0xF7F6), W16(0xF6F8), W16(0xF62B), W16(0xF5CD), - W16(0x113D), W16(0x0EA0), W16(0x0982), W16(0x0790), W16(0x0603), W16(0x03FC), W16(0x03BB), W16(0x02F3), - W16(0x02B1), W16(0x0200), W16(0x0053), W16(0xFEA6), W16(0xFF21), W16(0xFE15), W16(0xFBCF), W16(0xFA70), - W16(0xF836), W16(0xF5C7), W16(0xF364), W16(0xF0FE), W16(0xEFB5), W16(0xEE15), W16(0xECF4), W16(0xEC36), - W16(0x0D80), W16(0x08AB), W16(0x06F6), W16(0x0577), W16(0x04C6), W16(0x03FE), W16(0x036A), W16(0x0269), - W16(0x011F), W16(0x007F), W16(0xFF7D), W16(0xFEDB), W16(0xFE1D), W16(0xFD6A), W16(0xFCEB), W16(0xFCE8), - W16(0xFC19), W16(0xFAD7), W16(0xF9CA), W16(0xF8EF), W16(0xF7A0), W16(0xF637), W16(0xF4E5), W16(0xF3C8), - W16(0x154E), W16(0x0F85), W16(0x0E6E), W16(0x0C99), W16(0x09C2), W16(0x089D), W16(0x06F1), W16(0x04BB), - W16(0x030D), W16(0x01D2), W16(0xFF8A), W16(0xFE83), W16(0xFC74), W16(0xFB0D), W16(0xF947), W16(0xF7B0), - W16(0xF692), W16(0xF5F4), W16(0xF492), W16(0xF3EA), W16(0xF3DB), W16(0xF344), W16(0xF300), W16(0xF2C7), - W16(0x059C), W16(0x0678), W16(0x0739), W16(0x059B), W16(0x04D3), W16(0x0434), W16(0x03C7), W16(0x029A), - W16(0x0135), W16(0x00BA), W16(0xFFCA), W16(0xFE7B), W16(0xFDE8), W16(0xFDB0), W16(0xFD54), W16(0xFC50), - W16(0xFB26), W16(0xFA10), W16(0xF8CA), W16(0xF79D), W16(0xF5E8), W16(0xF43C), W16(0xF2F5), W16(0xF200), - W16(0x0A2C), W16(0x0BF7), W16(0x0BB0), W16(0x09DA), W16(0x087D), W16(0x079C), W16(0x0640), W16(0x05D4), - W16(0x0434), W16(0x0286), W16(0x0059), W16(0xFE6B), W16(0xFC7B), W16(0xFA60), W16(0xF901), W16(0xF7CA), - W16(0xF6AE), W16(0xF583), W16(0xF462), W16(0xF368), W16(0xF2E5), W16(0xF24B), W16(0xF1B0), W16(0xF143), - W16(0x080E), W16(0x063B), W16(0x04D7), W16(0x03B5), W16(0x032F), W16(0x0286), W16(0x0297), W16(0x0258), - W16(0x01F5), W16(0x0194), W16(0x00B5), W16(0xFFEE), W16(0xFEAA), W16(0xFDBF), W16(0xFD14), W16(0xFC38), - W16(0xFB7B), W16(0xFA4B), W16(0xF95B), W16(0xF827), W16(0xF5DF), W16(0xF427), W16(0xF2A4), W16(0xF0D8), - W16(0x0BF7), W16(0x0DAE), W16(0x0E6C), W16(0x0CA8), W16(0x0988), W16(0x07CC), W16(0x06AC), W16(0x053F), - W16(0x0504), W16(0x0391), W16(0x00A8), W16(0xFEE6), W16(0xFBE1), W16(0xFA1C), W16(0xF842), W16(0xF6C8), - W16(0xF599), W16(0xF4E4), W16(0xF393), W16(0xF2CE), W16(0xF319), W16(0xF280), W16(0xF238), W16(0xF1FF), - W16(0x071A), W16(0x069C), W16(0x0603), W16(0x070B), W16(0x06A3), W16(0x0371), W16(0x02AE), W16(0x0120), - W16(0x0054), W16(0x0072), W16(0x0020), W16(0xFF5E), W16(0xFE81), W16(0xFDEB), W16(0xFD8C), W16(0xFBF4), - W16(0xFBEF), W16(0xFA96), W16(0xF9F7), W16(0xF954), W16(0xF7CB), W16(0xF6D2), W16(0xF602), W16(0xF59F), - W16(0x11C4), W16(0x0EBE), W16(0x09D4), W16(0x083C), W16(0x0610), W16(0x046E), W16(0x0439), W16(0x0387), - W16(0x035C), W16(0x0209), W16(0x00B5), W16(0xFE91), W16(0xFF44), W16(0xFE67), W16(0xFB2E), W16(0xF948), - W16(0xF6F6), W16(0xF530), W16(0xF34C), W16(0xF1B8), W16(0xF0E9), W16(0xEFBC), W16(0xEEDB), W16(0xEE5B), - W16(0x0C81), W16(0x0AAB), W16(0x082C), W16(0x06AA), W16(0x05BA), W16(0x048D), W16(0x02A0), W16(0x01BC), - W16(0x0207), W16(0x00EF), W16(0xFF91), W16(0xFE7F), W16(0xFE1E), W16(0xFD9A), W16(0xFCFD), W16(0xFC21), - W16(0xFB7F), W16(0xFB22), W16(0xFA12), W16(0xF8D4), W16(0xF79C), W16(0xF67E), W16(0xF578), W16(0xF49A), - W16(0x15E4), W16(0x0FAA), W16(0x0D3B), W16(0x0AAE), W16(0x0793), W16(0x055C), W16(0x042F), W16(0x0411), - W16(0x024D), W16(0x0223), W16(0x003E), W16(0xFE80), W16(0xFD25), W16(0xFBCD), W16(0xFAB4), W16(0xF9F2), - W16(0xFA0B), W16(0xFA0B), W16(0xF8CB), W16(0xF71B), W16(0xF541), W16(0xF318), W16(0xF1D1), W16(0xF0E5), - W16(0x00C1), W16(0x04F8), W16(0x05DF), W16(0x04A6), W16(0x04E6), W16(0x051A), W16(0x03EE), W16(0x0222), - W16(0x027D), W16(0x01C6), W16(0x00A1), W16(0xFE74), W16(0xFC93), W16(0xFD00), W16(0xFCA2), W16(0xFBD6), - W16(0xFA8F), W16(0xF921), W16(0xF6B4), W16(0xF360), W16(0xF234), W16(0xF1CC), W16(0xF098), W16(0xEF7C), - W16(0x09A6), W16(0x0B5C), W16(0x08FD), W16(0x0823), W16(0x0635), W16(0x046C), W16(0x0414), W16(0x0355), - W16(0x032D), W16(0x020B), W16(0x005C), W16(0xFE99), W16(0xFF5B), W16(0xFE74), W16(0xFB94), W16(0xF948), - W16(0xF71E), W16(0xF579), W16(0xF3B1), W16(0xF238), W16(0xF1A5), W16(0xF0B2), W16(0xEFF3), W16(0xEF8A), - W16(0x0B75), W16(0x0825), W16(0x06AA), W16(0x05E4), W16(0x058D), W16(0x04CD), W16(0x0380), W16(0x0277), - W16(0x0230), W16(0x01A7), W16(0x00CD), W16(0xFF92), W16(0xFDBE), W16(0xFCF0), W16(0xFB7E), W16(0xFB60), - W16(0xF9ED), W16(0xF79E), W16(0xF567), W16(0xF25B), W16(0xF175), W16(0xF1B3), W16(0xF00F), W16(0xEF68), - W16(0x10BA), W16(0x0DA4), W16(0x0C13), W16(0x0A09), W16(0x0881), W16(0x07B1), W16(0x0695), W16(0x0646), - W16(0x0441), W16(0x0314), W16(0x0082), W16(0xFE65), W16(0xFC91), W16(0xFAB2), W16(0xF912), W16(0xF718), - W16(0xF54B), W16(0xF40C), W16(0xF2E2), W16(0xF1EA), W16(0xF11C), W16(0xF056), W16(0xEFC2), W16(0xEF69), - W16(0xFF55), W16(0x0390), W16(0x0492), W16(0x0613), W16(0x050A), W16(0x0220), W16(0x02D3), W16(0x04A9), - W16(0x0184), W16(0x00B1), W16(0xFFC3), W16(0xFF2D), W16(0xFE4D), W16(0xFDF9), W16(0xFCC9), W16(0xFC03), - W16(0xFB22), W16(0xFAC1), W16(0xFA3B), W16(0xFA38), W16(0xFA06), W16(0xF8D8), W16(0xF7EA), W16(0xF728), - W16(0x11B5), W16(0x0EF5), W16(0x09CB), W16(0x0809), W16(0x064A), W16(0x042E), W16(0x040C), W16(0x0357), - W16(0x02F1), W16(0x024E), W16(0x0056), W16(0xFEAF), W16(0xFF65), W16(0xFE60), W16(0xFB98), W16(0xF94B), - W16(0xF73A), W16(0xF534), W16(0xF2EF), W16(0xF0CD), W16(0xEF97), W16(0xEE13), W16(0xECFC), W16(0xEC4C), - W16(0x0E1A), W16(0x07FF), W16(0x0574), W16(0x0424), W16(0x0308), W16(0x0288), W16(0x025B), W16(0x01DC), - W16(0x01A6), W16(0x0194), W16(0x00BD), W16(0xFFF1), W16(0xFED2), W16(0xFD0A), W16(0xFC7C), W16(0xFD39), - W16(0xFCBF), W16(0xFAB3), W16(0xF883), W16(0xF858), W16(0xF754), W16(0xF580), W16(0xF326), W16(0xF164), - W16(0x1578), W16(0x1060), W16(0x0F1C), W16(0x0D00), W16(0x09C6), W16(0x0813), W16(0x06DB), W16(0x056D), - W16(0x051A), W16(0x03B2), W16(0x0098), W16(0xFEA8), W16(0xFBA2), W16(0xF9EC), W16(0xF816), W16(0xF6B4), - W16(0xF57B), W16(0xF4BD), W16(0xF36B), W16(0xF2CB), W16(0xF2DA), W16(0xF255), W16(0xF211), W16(0xF1D9), - W16(0x037E), W16(0x060E), W16(0x0676), W16(0x0551), W16(0x04A6), W16(0x03E7), W16(0x0350), W16(0x0258), - W16(0x0116), W16(0x0082), W16(0xFF71), W16(0xFEE3), W16(0xFE38), W16(0xFD84), W16(0xFCFA), W16(0xFCF9), - W16(0xFC31), W16(0xFB55), W16(0xFA9A), W16(0xF9FC), W16(0xF8C4), W16(0xF77C), W16(0xF655), W16(0xF56C), - W16(0x084B), W16(0x0BA1), W16(0x0C77), W16(0x0AAE), W16(0x0923), W16(0x080C), W16(0x071E), W16(0x0665), - W16(0x04A1), W16(0x0315), W16(0x0026), W16(0xFE65), W16(0xFC85), W16(0xFA45), W16(0xF8C1), W16(0xF712), - W16(0xF46E), W16(0xF315), W16(0xF120), W16(0xEF4A), W16(0xEE87), W16(0xED2A), W16(0xEC77), W16(0xEC38), - W16(0x0999), W16(0x071B), W16(0x0556), W16(0x042B), W16(0x036A), W16(0x030C), W16(0x02F3), W16(0x0244), - W16(0x023C), W16(0x017E), W16(0x00BA), W16(0xFFC4), W16(0xFE76), W16(0xFD99), W16(0xFCD2), W16(0xFC0E), - W16(0xFB2C), W16(0xFA4D), W16(0xF98D), W16(0xF8D6), W16(0xF71A), W16(0xF57C), W16(0xF44B), W16(0xF2E6), - W16(0x0EC4), W16(0x0F57), W16(0x0DAE), W16(0x0A4B), W16(0x0792), W16(0x05B9), W16(0x042F), W16(0x052A), - W16(0x04B9), W16(0x0265), W16(0x00B7), W16(0xFF57), W16(0xFD8E), W16(0xFB34), W16(0xF8FA), W16(0xF87C), - W16(0xF7F8), W16(0xF6CD), W16(0xF574), W16(0xF502), W16(0xF522), W16(0xF458), W16(0xF39D), W16(0xF2A2), - W16(0x041B), W16(0x055C), W16(0x037A), W16(0x0524), W16(0x046C), W16(0x018B), W16(0x023A), W16(0x0577), - W16(0x011B), W16(0x014E), W16(0x000F), W16(0xFF9F), W16(0xFE98), W16(0xFE17), W16(0xFC95), W16(0xFBDD), - W16(0xFB20), W16(0xFA7B), W16(0xF99C), W16(0xF917), W16(0xF8F0), W16(0xF7A1), W16(0xF6A6), W16(0xF5EF), - W16(0x124C), W16(0x0F7E), W16(0x0A28), W16(0x07F6), W16(0x0685), W16(0x046A), W16(0x0448), W16(0x03B7), - W16(0x0369), W16(0x0234), W16(0x0091), W16(0xFE7E), W16(0xFF1D), W16(0xFE27), W16(0xFB41), W16(0xF906), - W16(0xF6DA), W16(0xF4B7), W16(0xF2AD), W16(0xF08B), W16(0xEF6C), W16(0xEDE1), W16(0xECAB), W16(0xEBFF), - W16(0x0AC7), W16(0x090A), W16(0x066E), W16(0x050B), W16(0x0486), W16(0x0345), W16(0x025D), W16(0x01DD), - W16(0x016D), W16(0x00DB), W16(0xFFF7), W16(0xFF86), W16(0xFE3F), W16(0xFDC9), W16(0xFD3F), W16(0xFCD6), - W16(0xFC18), W16(0xFB8D), W16(0xFB22), W16(0xFAA9), W16(0xF935), W16(0xF7A8), W16(0xF71D), W16(0xF5F9), - W16(0x1773), W16(0x11C9), W16(0x0E4C), W16(0x0B28), W16(0x0863), W16(0x06A2), W16(0x04C0), W16(0x04F4), - W16(0x03AC), W16(0x02F9), W16(0x00FF), W16(0xFF05), W16(0xFCDD), W16(0xFAF6), W16(0xF9B8), W16(0xF7F2), - W16(0xF720), W16(0xF63F), W16(0xF4B7), W16(0xF379), W16(0xF34D), W16(0xF22F), W16(0xF1E0), W16(0xF189), - W16(0x0386), W16(0x0768), W16(0x07CF), W16(0x05BE), W16(0x0445), W16(0x031D), W16(0x02BA), W16(0x02A4), - W16(0x0253), W16(0x01D0), W16(0x00B7), W16(0xFF23), W16(0xFE0F), W16(0xFDB2), W16(0xFCC0), W16(0xFBB3), - W16(0xFB0F), W16(0xFA0E), W16(0xF8FB), W16(0xF7BA), W16(0xF676), W16(0xF4C6), W16(0xF335), W16(0xF1B7), - W16(0x0D50), W16(0x0E22), W16(0x0D40), W16(0x0A33), W16(0x078C), W16(0x058E), W16(0x040F), W16(0x053B), - W16(0x04AC), W16(0x0277), W16(0x00BB), W16(0xFF75), W16(0xFD8E), W16(0xFB57), W16(0xF907), W16(0xF847), - W16(0xF816), W16(0xF6AD), W16(0xF47E), W16(0xF38D), W16(0xF3A2), W16(0xF2BA), W16(0xF1E9), W16(0xF0F0), - W16(0x0956), W16(0x078B), W16(0x0679), W16(0x050A), W16(0x0501), W16(0x04D6), W16(0x03A7), W16(0x0243), - W16(0x0288), W16(0x01A6), W16(0x008F), W16(0xFE95), W16(0xFD0F), W16(0xFCDF), W16(0xFC73), W16(0xFBE7), - W16(0xFAA5), W16(0xF93B), W16(0xF6D9), W16(0xF3BD), W16(0xF254), W16(0xF203), W16(0xF0F4), W16(0xEFE0), - W16(0x1206), W16(0x0EA1), W16(0x0BE4), W16(0x09D1), W16(0x0868), W16(0x0769), W16(0x0635), W16(0x05ED), - W16(0x044B), W16(0x029D), W16(0x003D), W16(0xFE68), W16(0xFC72), W16(0xFA57), W16(0xF901), W16(0xF7E0), - W16(0xF6D5), W16(0xF5A0), W16(0xF464), W16(0xF31B), W16(0xF272), W16(0xF1E0), W16(0xF13B), W16(0xF0C5), - W16(0x0030), W16(0x0026), W16(0xFFFE), W16(0x000F), W16(0x000E), W16(0x002B), W16(0x001B), W16(0xFFFA), - W16(0xFFFD), W16(0x0031), W16(0x000C), W16(0xFFF6), W16(0x0000), W16(0x0025), W16(0x000E), W16(0x0019), - W16(0x002D), W16(0x000F), W16(0xFFFA), W16(0x0019), W16(0x0004), W16(0x0009), W16(0xFFE3), W16(0x001A), - W16(0x1088), W16(0x0E1C), W16(0x0925), W16(0x0774), W16(0x05E9), W16(0x0444), W16(0x03AF), W16(0x031D), - W16(0x02ED), W16(0x01D6), W16(0x001A), W16(0xFEAB), W16(0xFF43), W16(0xFE92), W16(0xFC13), W16(0xF9E1), - W16(0xF7B9), W16(0xF5B2), W16(0xF370), W16(0xF175), W16(0xF007), W16(0xEE39), W16(0xEC85), W16(0xEBB2), - W16(0x0C41), W16(0x0B9B), W16(0x08F6), W16(0x060A), W16(0x047E), W16(0x0367), W16(0x02EB), W16(0x02B5), - W16(0x0229), W16(0x01CD), W16(0x00D1), W16(0xFF51), W16(0xFE2E), W16(0xFD6C), W16(0xFC3C), W16(0xFB9B), - W16(0xFAF3), W16(0xF9FB), W16(0xF904), W16(0xF794), W16(0xF5EB), W16(0xF448), W16(0xF297), W16(0xF112), - W16(0x1841), W16(0x1114), W16(0x0E1F), W16(0x0BC4), W16(0x0928), W16(0x07F2), W16(0x0645), W16(0x0597), - W16(0x0320), W16(0x020F), W16(0xFFBD), W16(0xFD59), W16(0xFB76), W16(0xFA6A), W16(0xF9D9), W16(0xF8B4), - W16(0xF85A), W16(0xF7E9), W16(0xF6BF), W16(0xF59E), W16(0xF4BC), W16(0xF374), W16(0xF2FA), W16(0xF28E), - W16(0x040C), W16(0x085D), W16(0x07F5), W16(0x06B2), W16(0x05B3), W16(0x0489), W16(0x02A3), W16(0x01C6), - W16(0x0210), W16(0x00FA), W16(0xFF92), W16(0xFE81), W16(0xFE16), W16(0xFD92), W16(0xFCF3), W16(0xFC22), - W16(0xFB81), W16(0xFB21), W16(0xFA10), W16(0xF8D1), W16(0xF7AE), W16(0xF682), W16(0xF57B), W16(0xF499), - W16(0x0A70), W16(0x0CC9), W16(0x0C30), W16(0x0A4C), W16(0x08C0), W16(0x07E8), W16(0x068B), W16(0x0608), - W16(0x047C), W16(0x02D7), W16(0x0045), W16(0xFE38), W16(0xFC5A), W16(0xFA03), W16(0xF87A), W16(0xF794), - W16(0xF68A), W16(0xF541), W16(0xF3C7), W16(0xF219), W16(0xF161), W16(0xF04C), W16(0xEF66), W16(0xEE85), - W16(0x09B5), W16(0x0777), W16(0x062C), W16(0x0522), W16(0x041F), W16(0x0379), W16(0x030C), W16(0x028F), - W16(0x022B), W16(0x0180), W16(0x00C3), W16(0xFF88), W16(0xFE4D), W16(0xFD43), W16(0xFCCD), W16(0xFBBF), - W16(0xFABA), W16(0xF9D8), W16(0xF8C3), W16(0xF794), W16(0xF5E1), W16(0xF440), W16(0xF2BA), W16(0xF0EB), - W16(0x0E79), W16(0x0E14), W16(0x0DAD), W16(0x0BF1), W16(0x0986), W16(0x0850), W16(0x069D), W16(0x05E7), - W16(0x0365), W16(0x01E7), W16(0xFF95), W16(0xFD26), W16(0xFB64), W16(0xFA4C), W16(0xF992), W16(0xF86A), - W16(0xF7F2), W16(0xF753), W16(0xF60A), W16(0xF4B6), W16(0xF478), W16(0xF34C), W16(0xF309), W16(0xF2C1), - W16(0x0629), W16(0x085C), W16(0x07B5), W16(0x05D5), W16(0x03A3), W16(0x0232), W16(0x01A6), W16(0x01AA), - W16(0x019D), W16(0x0164), W16(0x00B9), W16(0xFF98), W16(0xFE70), W16(0xFE08), W16(0xFDAD), W16(0xFCF3), - W16(0xFC70), W16(0xFB8D), W16(0xFA6A), W16(0xF94F), W16(0xF7E8), W16(0xF675), W16(0xF524), W16(0xF3D5), - W16(0x11B2), W16(0x0E4F), W16(0x08FA), W16(0x0833), W16(0x0622), W16(0x0493), W16(0x0451), W16(0x02EE), - W16(0x02A4), W16(0x0151), W16(0xFFDB), W16(0xFE6E), W16(0xFEA3), W16(0xFE6B), W16(0xFBEF), W16(0xFA4A), - W16(0xF887), W16(0xF696), W16(0xF461), W16(0xF27D), W16(0xF1CA), W16(0xF0EB), W16(0xF04C), W16(0xF014), - W16(0x0E96), W16(0x0B2E), W16(0x0818), W16(0x05E8), W16(0x03AA), W16(0x0250), W16(0x01F1), W16(0x01F9), - W16(0x01D1), W16(0x016C), W16(0x00CA), W16(0xFF64), W16(0xFE0D), W16(0xFDE3), W16(0xFDAE), W16(0xFCC4), - W16(0xFC4E), W16(0xFB93), W16(0xFA73), W16(0xF957), W16(0xF7B4), W16(0xF62B), W16(0xF527), W16(0xF3B7), - W16(0x17EA), W16(0x10B1), W16(0x0D83), W16(0x0A75), W16(0x07F4), W16(0x0606), W16(0x042B), W16(0x03F9), - W16(0x02B8), W16(0x027D), W16(0x00F7), W16(0xFEED), W16(0xFD61), W16(0xFBC5), W16(0xFA88), W16(0xF8F0), - W16(0xF82A), W16(0xF775), W16(0xF601), W16(0xF4EB), W16(0xF453), W16(0xF321), W16(0xF2CA), W16(0xF274) -}; - -const Word16 cdk_37bits_2_fx[1536] = -{ - W16(0xFFB3), W16(0xFFD1), W16(0xFFDB), W16(0xFFB1), W16(0xFFE5), W16(0x0002), W16(0xFFE4), W16(0xFFED), - W16(0x0018), W16(0x0058), W16(0x005D), W16(0x006D), W16(0x0055), W16(0x0018), W16(0xFFB1), W16(0xFF83), - W16(0xFF6E), W16(0xFF10), W16(0xFEBF), W16(0xFE86), W16(0xFE7C), W16(0xFE80), W16(0xFE8F), W16(0xFEB7), - W16(0xFD2D), W16(0xFEBB), W16(0x0033), W16(0x017C), W16(0xFFED), W16(0xFF59), W16(0x0125), W16(0x0143), - W16(0xFFA1), W16(0xFFB6), W16(0xFFCD), W16(0xFFD2), W16(0xFF67), W16(0x0008), W16(0x0053), W16(0xFFDB), - W16(0xFFC0), W16(0x0014), W16(0xFFC0), W16(0xFF6B), W16(0xFF62), W16(0xFF1F), W16(0xFF27), W16(0xFE5D), - W16(0xFE2D), W16(0xFF2A), W16(0xFF78), W16(0xFF50), W16(0xFF70), W16(0xFFA8), W16(0xFF9A), W16(0xFFDD), - W16(0xFFED), W16(0xFFEE), W16(0x0005), W16(0x0058), W16(0x0061), W16(0x0046), W16(0x0033), W16(0x0038), - W16(0x0028), W16(0x003C), W16(0x0034), W16(0x002D), W16(0xFFCC), W16(0xFFBE), W16(0xFF8D), W16(0xFF79), - W16(0xFEF1), W16(0xFF29), W16(0xFF4E), W16(0xFF83), W16(0xFFA8), W16(0xFFE0), W16(0x0016), W16(0x0049), - W16(0x0085), W16(0x0044), W16(0x0040), W16(0x002F), W16(0x0001), W16(0xFFF3), W16(0xFFAF), W16(0xFFB5), - W16(0xFF89), W16(0xFF71), W16(0xFF59), W16(0xFF44), W16(0xFF48), W16(0xFF52), W16(0xFF54), W16(0xFF57), - W16(0x0021), W16(0xFF57), W16(0xFFC3), W16(0xFFEF), W16(0x006E), W16(0x007D), W16(0x0042), W16(0x0015), - W16(0x0004), W16(0x0006), W16(0x0015), W16(0x000B), W16(0xFFFA), W16(0xFFB0), W16(0xFFA3), W16(0xFFB1), - W16(0xFF96), W16(0xFF7B), W16(0xFF7E), W16(0xFF93), W16(0xFF83), W16(0xFF84), W16(0xFF8F), W16(0xFFA2), - W16(0xFFDE), W16(0xFF98), W16(0xFFB5), W16(0xFF7D), W16(0xFFC8), W16(0x004A), W16(0x0095), W16(0x0118), - W16(0x0018), W16(0xFFB7), W16(0xFF95), W16(0xFF9B), W16(0xFF9D), W16(0xFF73), W16(0xFFC4), W16(0x0033), - W16(0x003B), W16(0xFFAF), W16(0xFFA1), W16(0xFF9B), W16(0x0013), W16(0x0077), W16(0x0058), W16(0x0073), - W16(0xFF2B), W16(0xFFBF), W16(0xFFFD), W16(0x003C), W16(0x0040), W16(0x0096), W16(0x0067), W16(0x0095), - W16(0x0069), W16(0x003F), W16(0x000F), W16(0xFFE4), W16(0xFFAA), W16(0xFF59), W16(0xFF7C), W16(0xFF83), - W16(0xFF92), W16(0xFF82), W16(0xFFA1), W16(0xFFCC), W16(0xFFF5), W16(0x006F), W16(0x00B8), W16(0x00D2), - W16(0x0123), W16(0xFFB5), W16(0xFFA8), W16(0xFFC4), W16(0xFFB1), W16(0xFFBE), W16(0xFFDA), W16(0x000D), - W16(0x002E), W16(0x0047), W16(0x004A), W16(0x003D), W16(0x0038), W16(0x0008), W16(0xFFE0), W16(0xFFC3), - W16(0xFFCA), W16(0xFFA9), W16(0xFFB6), W16(0xFFA2), W16(0xFF8F), W16(0xFF6E), W16(0xFF69), W16(0xFF76), - W16(0xFFDE), W16(0xFF74), W16(0xFF2C), W16(0xFEEE), W16(0xFEF8), W16(0xFF28), W16(0xFF7F), W16(0xFFD0), - W16(0xFFF8), W16(0x002D), W16(0x007E), W16(0x0075), W16(0x006F), W16(0x006B), W16(0x0068), W16(0x0031), - W16(0x0006), W16(0xFFB4), W16(0xFF96), W16(0xFF61), W16(0xFF3E), W16(0xFF33), W16(0xFF24), W16(0xFF32), - W16(0xFF74), W16(0x0009), W16(0x000A), W16(0xFF60), W16(0x000F), W16(0x0039), W16(0x002C), W16(0x0019), - W16(0xFFED), W16(0xFFF5), W16(0xFFF6), W16(0xFFE6), W16(0x0009), W16(0xFFF4), W16(0xFFFD), W16(0xFFDF), - W16(0xFFDC), W16(0xFFAD), W16(0xFFA0), W16(0xFF7E), W16(0xFF5A), W16(0xFF45), W16(0xFF42), W16(0xFF54), - W16(0xFFAD), W16(0xFF8E), W16(0xFF94), W16(0xFFD4), W16(0x002A), W16(0xFFDA), W16(0xFF38), W16(0xFF1F), - W16(0xFF4F), W16(0xFFCA), W16(0x000A), W16(0x008E), W16(0x00B2), W16(0x0058), W16(0x002B), W16(0x0062), - W16(0x005D), W16(0x000C), W16(0xFFDF), W16(0x001B), W16(0x005D), W16(0x0085), W16(0x0044), W16(0x006D), - W16(0xFFAB), W16(0xFFA3), W16(0xFF6B), W16(0xFFB2), W16(0xFFEE), W16(0xFFD1), W16(0xFFE9), W16(0xFFFE), - W16(0x000A), W16(0xFFF3), W16(0x000A), W16(0x0022), W16(0x002D), W16(0x000B), W16(0x000D), W16(0xFFFC), - W16(0xFFEF), W16(0xFFE3), W16(0xFFD6), W16(0xFFDF), W16(0xFFDE), W16(0xFFE5), W16(0xFFF3), W16(0x0003), - W16(0x0058), W16(0xFF6D), W16(0xFEDB), W16(0x0148), W16(0x002F), W16(0xFEF8), W16(0x0025), W16(0x00F8), - W16(0x007F), W16(0x001A), W16(0xFFFD), W16(0x0016), W16(0x000A), W16(0x0003), W16(0xFF8F), W16(0xFFB0), - W16(0xFFC4), W16(0xFFEC), W16(0xFFB3), W16(0xFFB1), W16(0xFF88), W16(0xFF36), W16(0xFECB), W16(0xFE30), - W16(0x000E), W16(0x0038), W16(0x00C8), W16(0x0124), W16(0x013B), W16(0x00A4), W16(0x0050), W16(0x0061), - W16(0x0053), W16(0x0022), W16(0xFFC3), W16(0xFFC8), W16(0xFFB0), W16(0xFF77), W16(0xFF89), W16(0xFF67), - W16(0xFF57), W16(0xFF51), W16(0xFF46), W16(0xFF20), W16(0xFF1B), W16(0xFF2D), W16(0xFF2F), W16(0xFF42), - W16(0xFF7C), W16(0xFF55), W16(0xFF89), W16(0xFFC7), W16(0x0030), W16(0x0076), W16(0x003C), W16(0xFFC6), - W16(0xFFAA), W16(0xFF6A), W16(0xFF99), W16(0xFFC6), W16(0x002C), W16(0x0079), W16(0x0055), W16(0x0003), - W16(0xFFE7), W16(0x0025), W16(0x0019), W16(0xFFE8), W16(0xFFE1), W16(0xFFDC), W16(0xFFEB), W16(0xFFF7), - W16(0x0065), W16(0x0005), W16(0xFFC6), W16(0x0050), W16(0x0034), W16(0x003B), W16(0x0021), W16(0xFFFF), - W16(0x0016), W16(0x0004), W16(0xFFF6), W16(0x0022), W16(0xFFE4), W16(0xFF9E), W16(0xFFC9), W16(0xFFEF), - W16(0x0003), W16(0x001B), W16(0x003A), W16(0x0053), W16(0x0047), W16(0x0049), W16(0x0050), W16(0x005C), - W16(0x001D), W16(0xFFFA), W16(0x0042), W16(0x0045), W16(0x0074), W16(0xFFC3), W16(0xFFB3), W16(0xFFCF), - W16(0x005C), W16(0x0038), W16(0x003E), W16(0x0038), W16(0x0018), W16(0x0004), W16(0xFFCD), W16(0xFFB4), - W16(0xFFA0), W16(0xFFA0), W16(0xFF9C), W16(0xFF96), W16(0xFFA3), W16(0xFF9F), W16(0xFFB6), W16(0xFFD0), - W16(0xFED6), W16(0xFFA8), W16(0xFFDC), W16(0xFFD1), W16(0xFFDB), W16(0xFFFF), W16(0x0015), W16(0x0024), - W16(0x001F), W16(0x0002), W16(0xFFD6), W16(0xFFDB), W16(0xFFE0), W16(0xFFDC), W16(0x0009), W16(0x0022), - W16(0x0036), W16(0x0040), W16(0x0047), W16(0x0068), W16(0x0035), W16(0x001B), W16(0x000A), W16(0x000E), - W16(0xFFDD), W16(0xFF6B), W16(0xFF4C), W16(0xFF80), W16(0xFF71), W16(0xFF90), W16(0xFFAF), W16(0xFFCD), - W16(0xFFCC), W16(0xFFF8), W16(0x0011), W16(0x0039), W16(0x003A), W16(0x0018), W16(0x0047), W16(0x0064), - W16(0x0079), W16(0x0081), W16(0x00DA), W16(0x0122), W16(0x013D), W16(0x014D), W16(0x0166), W16(0x0164), - W16(0xFFD7), W16(0xFF25), W16(0xFEAE), W16(0xFEAA), W16(0xFF89), W16(0x0022), W16(0xFFDF), W16(0x0003), - W16(0x002B), W16(0x0009), W16(0x0003), W16(0x0020), W16(0x0032), W16(0xFFFE), W16(0xFFE6), W16(0x0001), - W16(0x0004), W16(0x000C), W16(0x001D), W16(0x002B), W16(0x0001), W16(0x0016), W16(0x0071), W16(0x0073), - W16(0x0078), W16(0x0042), W16(0x0005), W16(0xFFA0), W16(0x003D), W16(0x0046), W16(0x0018), W16(0xFFCE), - W16(0xFFF6), W16(0xFFEF), W16(0x0010), W16(0xFFE3), W16(0x0004), W16(0x0003), W16(0xFFF9), W16(0xFFE9), - W16(0xFFD6), W16(0xFFC6), W16(0xFFCD), W16(0xFFC6), W16(0xFFB9), W16(0xFFC7), W16(0xFFCB), W16(0xFFDD), - W16(0x00A0), W16(0xFFEB), W16(0xFFE2), W16(0xFF8B), W16(0x000C), W16(0x0079), W16(0x007F), W16(0x00BD), - W16(0x0098), W16(0x002C), W16(0x000B), W16(0xFFD9), W16(0xFFD6), W16(0xFFB0), W16(0xFF62), W16(0xFF53), - W16(0xFF5C), W16(0xFF4D), W16(0xFF42), W16(0xFF63), W16(0xFFAE), W16(0xFFD8), W16(0x0007), W16(0x004E), - W16(0xFF5C), W16(0x0027), W16(0x0008), W16(0x001B), W16(0x0020), W16(0x002A), W16(0x0043), W16(0xFFE7), - W16(0x0049), W16(0x0023), W16(0x0019), W16(0xFFDB), W16(0xFFFC), W16(0xFFF1), W16(0xFFC8), W16(0xFFB7), - W16(0xFFC1), W16(0xFFEF), W16(0x0057), W16(0x00C2), W16(0x00F7), W16(0x0133), W16(0x0193), W16(0x0204), - W16(0x00E7), W16(0xFFB8), W16(0xFF59), W16(0xFF4C), W16(0xFFA9), W16(0xFF9E), W16(0xFFB3), W16(0xFFBF), - W16(0xFFA9), W16(0xFFC1), W16(0xFFEF), W16(0x001A), W16(0x0053), W16(0x0056), W16(0x0051), W16(0x0071), - W16(0x006A), W16(0x0042), W16(0x003B), W16(0x003E), W16(0x0035), W16(0x003A), W16(0x0045), W16(0x0055), - W16(0xFF39), W16(0xFFE6), W16(0xFFED), W16(0xFF80), W16(0xFF51), W16(0xFF63), W16(0xFF81), W16(0xFFC1), - W16(0x0085), W16(0x00B5), W16(0x0078), W16(0x001F), W16(0xFFFA), W16(0xFFC4), W16(0xFFF2), W16(0x0030), - W16(0x005A), W16(0x0026), W16(0x0010), W16(0x0001), W16(0xFFD9), W16(0xFFB9), W16(0xFF83), W16(0xFF55), - W16(0xFF8A), W16(0x0105), W16(0x010B), W16(0xFFD4), W16(0xFFBC), W16(0xFF9B), W16(0xFFD3), W16(0xFFFA), - W16(0xFFF9), W16(0x0026), W16(0x001B), W16(0x001B), W16(0x0020), W16(0x000A), W16(0x0021), W16(0x002E), - W16(0x000E), W16(0x0001), W16(0x0005), W16(0xFFEE), W16(0xFFEA), W16(0x0024), W16(0x0020), W16(0x0022), - W16(0xFFB2), W16(0xFFF7), W16(0xFFB1), W16(0xFF56), W16(0xFF75), W16(0xFFB1), W16(0xFFCD), W16(0xFFBF), - W16(0xFFD3), W16(0xFFD5), W16(0xFFEF), W16(0xFFF9), W16(0x0003), W16(0x0031), W16(0x0039), W16(0x008B), - W16(0x00C8), W16(0x0076), W16(0x0055), W16(0x0034), W16(0x000F), W16(0x0003), W16(0xFFEF), W16(0xFFD6), - W16(0x0028), W16(0xFFFC), W16(0xFFFA), W16(0xFFD1), W16(0xFF1C), W16(0x002B), W16(0x001E), W16(0x000D), - W16(0x0027), W16(0x0018), W16(0x001B), W16(0xFFF3), W16(0x0029), W16(0x0024), W16(0x000A), W16(0xFFFE), - W16(0xFFEB), W16(0xFFED), W16(0xFFFB), W16(0x0002), W16(0xFFFF), W16(0x0004), W16(0x0010), W16(0x001F), - W16(0x008D), W16(0x000D), W16(0xFFDE), W16(0xFFE5), W16(0x0016), W16(0xFFFB), W16(0xFFCA), W16(0xFFDE), - W16(0xFFBB), W16(0xFFA1), W16(0xFFCE), W16(0xFFD8), W16(0x0006), W16(0x0005), W16(0x000E), W16(0x0080), - W16(0x00AB), W16(0x0041), W16(0xFFDE), W16(0xFFA4), W16(0xFF6E), W16(0xFF47), W16(0xFF30), W16(0xFF31), - W16(0xFF69), W16(0xFFAC), W16(0xFF93), W16(0xFF7F), W16(0x0021), W16(0x003F), W16(0xFFD0), W16(0xFF89), - W16(0xFF75), W16(0xFF81), W16(0xFF9C), W16(0xFF4B), W16(0xFF1F), W16(0x0011), W16(0x015C), W16(0x018B), - W16(0x0053), W16(0x001B), W16(0xFF65), W16(0xFED5), W16(0x0002), W16(0x0108), W16(0x0023), W16(0x0033), - W16(0xFFC2), W16(0x0007), W16(0x0014), W16(0x008D), W16(0x0088), W16(0x0096), W16(0x00C7), W16(0x0039), - W16(0xFFCB), W16(0xFF6F), W16(0xFF89), W16(0xFF74), W16(0xFF8B), W16(0xFFC2), W16(0x000E), W16(0x0031), - W16(0x001F), W16(0x0022), W16(0x0056), W16(0x0053), W16(0x0001), W16(0xFF91), W16(0xFF5F), W16(0xFF4A), - W16(0x00C6), W16(0x00D2), W16(0x00BF), W16(0x003B), W16(0x0078), W16(0x008A), W16(0x0068), W16(0x0017), - W16(0x003D), W16(0x0026), W16(0xFFF2), W16(0xFFC0), W16(0xFFA7), W16(0xFFAB), W16(0xFF98), W16(0xFFC2), - W16(0xFFC0), W16(0xFFD2), W16(0xFFCB), W16(0xFFE4), W16(0x0019), W16(0x0033), W16(0x0060), W16(0x0080), - W16(0x000D), W16(0xFFE0), W16(0x005B), W16(0xFFFC), W16(0x0006), W16(0xFFEA), W16(0x001F), W16(0x00A3), - W16(0x00C5), W16(0x00A1), W16(0x00B4), W16(0x006A), W16(0xFFFF), W16(0xFFB6), W16(0xFF4C), W16(0xFEFA), - W16(0xFECE), W16(0xFEDC), W16(0xFF33), W16(0xFF14), W16(0xFF40), W16(0xFF57), W16(0xFF4B), W16(0xFF76), - W16(0xFE80), W16(0xFFD5), W16(0x0044), W16(0x0041), W16(0x0053), W16(0x001C), W16(0x0021), W16(0xFFF9), - W16(0x000C), W16(0xFFEE), W16(0xFFEB), W16(0x001A), W16(0x0020), W16(0xFFEE), W16(0xFFE3), W16(0xFFD5), - W16(0xFFB2), W16(0xFFB4), W16(0xFFAD), W16(0xFFB6), W16(0xFF93), W16(0xFF95), W16(0xFFA8), W16(0xFFB7), - W16(0xFF19), W16(0xFEF4), W16(0xFEC3), W16(0xFEBE), W16(0xFF0D), W16(0xFF3D), W16(0xFF49), W16(0xFF58), - W16(0xFF69), W16(0xFFA0), W16(0x0011), W16(0x0086), W16(0x0065), W16(0x00AB), W16(0x00BE), W16(0x00F6), - W16(0x00B1), W16(0x00C3), W16(0x00C5), W16(0x0089), W16(0x0043), W16(0x0072), W16(0x0060), W16(0x003E), - W16(0xFF96), W16(0xFF5F), W16(0xFFE1), W16(0xFF92), W16(0xFF57), W16(0xFF7E), W16(0xFFDA), W16(0x0008), - W16(0x00B5), W16(0x0092), W16(0x008C), W16(0x0054), W16(0x0055), W16(0x001D), W16(0xFFC1), W16(0xFF8C), - W16(0xFF63), W16(0xFF6F), W16(0xFFAD), W16(0xFFD6), W16(0xFFEE), W16(0x002A), W16(0x0067), W16(0x009F), - W16(0x0004), W16(0xFFCC), W16(0x0081), W16(0x0020), W16(0x001C), W16(0x005E), W16(0x000E), W16(0x0018), - W16(0xFFEF), W16(0xFFF6), W16(0xFFF2), W16(0xFFEB), W16(0x000F), W16(0xFFEB), W16(0xFFDE), W16(0xFFE6), - W16(0xFFE0), W16(0xFFE4), W16(0xFFE4), W16(0xFFD6), W16(0xFFD6), W16(0xFFD9), W16(0xFFED), W16(0x0007), - W16(0xFFC3), W16(0xFFB7), W16(0xFF6C), W16(0xFFF4), W16(0x0172), W16(0xFFED), W16(0xFF8F), W16(0x021C), - W16(0x00B3), W16(0xFF40), W16(0xFFC8), W16(0xFF96), W16(0xFFD8), W16(0xFF89), W16(0xFF9E), W16(0xFF4E), - W16(0xFF5A), W16(0xFFEC), W16(0x0022), W16(0x0023), W16(0x000D), W16(0x0023), W16(0x000D), W16(0xFFF1), - W16(0xFF96), W16(0x00A1), W16(0x012A), W16(0x0086), W16(0x005C), W16(0x004A), W16(0x0082), W16(0x0000), - W16(0x0052), W16(0x0017), W16(0xFFDD), W16(0xFFD8), W16(0xFFD2), W16(0xFFB4), W16(0xFFA4), W16(0xFFD0), - W16(0xFFC1), W16(0xFFE3), W16(0x001D), W16(0x004F), W16(0x0093), W16(0x00BA), W16(0x00DE), W16(0x00E2), - W16(0x01E5), W16(0x005B), W16(0x0048), W16(0x004D), W16(0x0075), W16(0x0093), W16(0x0050), W16(0x0020), - W16(0x0007), W16(0xFFEE), W16(0xFFE9), W16(0xFFED), W16(0xFFEA), W16(0xFFE8), W16(0xFFC2), W16(0xFF9C), - W16(0xFF8E), W16(0xFF89), W16(0xFF8A), W16(0xFF8B), W16(0xFFA4), W16(0xFFBB), W16(0xFFD3), W16(0xFFF3), - W16(0x00F1), W16(0x009F), W16(0xFF81), W16(0xFFA5), W16(0xFF99), W16(0xFF36), W16(0xFF3B), W16(0xFFA2), - W16(0xFFF9), W16(0x0065), W16(0x005E), W16(0x004D), W16(0x0073), W16(0x0023), W16(0x0047), W16(0x0036), - W16(0x0038), W16(0x0018), W16(0xFFD0), W16(0xFFD4), W16(0xFFC4), W16(0xFFBA), W16(0xFFC4), W16(0xFFBE), - W16(0xFFC3), W16(0x0081), W16(0x005E), W16(0x0044), W16(0xFFFE), W16(0x0004), W16(0x0034), W16(0x0057), - W16(0x005A), W16(0x004B), W16(0x001C), W16(0x0002), W16(0xFFE5), W16(0xFFBE), W16(0xFFA9), W16(0xFFBC), - W16(0xFFAA), W16(0xFFA6), W16(0xFFAD), W16(0xFFA9), W16(0xFFA6), W16(0xFF9A), W16(0xFFAE), W16(0xFFC2), - W16(0x00A3), W16(0x007B), W16(0x0032), W16(0x005C), W16(0x0084), W16(0x001C), W16(0xFFAC), W16(0xFF34), - W16(0xFF86), W16(0xFFC6), W16(0x0020), W16(0x0074), W16(0x0079), W16(0x000F), W16(0xFFEC), W16(0x0014), - W16(0x001A), W16(0x0009), W16(0x0015), W16(0x0077), W16(0x00C2), W16(0x0100), W16(0x011E), W16(0x016A), - W16(0xFFBA), W16(0x0029), W16(0x0017), W16(0xFFE0), W16(0x0015), W16(0x001F), W16(0xFFF4), W16(0xFFB0), - W16(0xFFD2), W16(0xFFBB), W16(0xFFEA), W16(0x0007), W16(0x002A), W16(0x0026), W16(0x0033), W16(0x001C), - W16(0x000B), W16(0x0018), W16(0x0029), W16(0x0034), W16(0x004C), W16(0x0079), W16(0x0090), W16(0x00AC), - W16(0xFFF1), W16(0xFFCA), W16(0x0002), W16(0x0052), W16(0xFFBE), W16(0xFF5B), W16(0xFFDD), W16(0xFFEC), - W16(0xFFDD), W16(0xFFF5), W16(0x003C), W16(0x0050), W16(0x003D), W16(0x0016), W16(0x0027), W16(0x002C), - W16(0x0019), W16(0x0017), W16(0x001F), W16(0x0030), W16(0x0021), W16(0x002C), W16(0x0020), W16(0x002B), - W16(0x000E), W16(0x0099), W16(0x0075), W16(0x0097), W16(0x009F), W16(0x007B), W16(0x003E), W16(0xFFF5), - W16(0xFF9F), W16(0xFFB1), W16(0xFFF0), W16(0xFFF9), W16(0x000F), W16(0x000A), W16(0xFFF9), W16(0xFFC0), - W16(0xFFA6), W16(0xFF93), W16(0xFF97), W16(0xFF93), W16(0xFF9E), W16(0xFFAC), W16(0xFFC2), W16(0xFFEC), - W16(0x002D), W16(0xFF24), W16(0xFEC4), W16(0x0070), W16(0xFF17), W16(0x0191), W16(0x00DD), W16(0xFFF4), - W16(0xFDFE), W16(0x00C4), W16(0xFF19), W16(0x0031), W16(0xFFB2), W16(0xFFED), W16(0xFF78), W16(0x0076), - W16(0x00EC), W16(0x00E1), W16(0x007F), W16(0x005A), W16(0x00C6), W16(0x0028), W16(0x00F2), W16(0x01B2), - W16(0x0127), W16(0x0076), W16(0x007F), W16(0x007A), W16(0x0041), W16(0x0078), W16(0x003E), W16(0xFFF5), - W16(0xFFB0), W16(0xFF89), W16(0xFFA4), W16(0xFFBC), W16(0xFFF0), W16(0x000C), W16(0x003C), W16(0x001E), - W16(0x0024), W16(0x003B), W16(0x004F), W16(0x007B), W16(0x0090), W16(0x00AB), W16(0x00B5), W16(0x00C7), - W16(0x00B0), W16(0x007D), W16(0x0076), W16(0x0068), W16(0x0056), W16(0x0050), W16(0xFFE6), W16(0x0004), - W16(0x0038), W16(0x0040), W16(0x001E), W16(0x002C), W16(0x0022), W16(0xFFC9), W16(0xFFAA), W16(0xFF9B), - W16(0xFF7D), W16(0xFF7A), W16(0xFF95), W16(0xFFCF), W16(0x0002), W16(0x0046), W16(0x00A9), W16(0x00F5), - W16(0xFF44), W16(0xFFB4), W16(0xFFDB), W16(0xFFD9), W16(0xFF9D), W16(0xFF8B), W16(0xFF71), W16(0xFF5E), - W16(0xFF8E), W16(0xFF94), W16(0xFFA9), W16(0xFFF0), W16(0x006F), W16(0x007A), W16(0x00AA), W16(0x00C5), - W16(0x00F6), W16(0x0145), W16(0x015F), W16(0x013D), W16(0x0111), W16(0x00FF), W16(0x00DC), W16(0x00C7), - W16(0xFEE8), W16(0xFEFE), W16(0xFEDE), W16(0xFF0B), W16(0xFE87), W16(0xFED9), W16(0xFEB8), W16(0xFEF7), - W16(0x0069), W16(0x0072), W16(0x00AE), W16(0x009A), W16(0x00B6), W16(0x004F), W16(0xFF68), W16(0x0035), - W16(0x022C), W16(0x0238), W16(0x020A), W16(0x0284), W16(0x01BA), W16(0xFFD5), W16(0x003F), W16(0xFF8E), - W16(0x00D0), W16(0x000F), W16(0xFFCE), W16(0xFF88), W16(0x0015), W16(0xFFFE), W16(0x003F), W16(0x001A), - W16(0x0023), W16(0x0019), W16(0x0029), W16(0xFFF1), W16(0xFFE7), W16(0xFFDC), W16(0xFFBF), W16(0xFFE4), - W16(0xFFD7), W16(0xFFDF), W16(0x000D), W16(0x0051), W16(0x0090), W16(0x00C6), W16(0x010D), W16(0x0138), - W16(0x00E7), W16(0x00AC), W16(0x0057), W16(0x0021), W16(0x0008), W16(0xFFE6), W16(0xFFE0), W16(0x0021), - W16(0x002C), W16(0xFFE0), W16(0xFFFC), W16(0x0001), W16(0x000F), W16(0xFFE8), W16(0xFFFD), W16(0x0006), - W16(0x000E), W16(0x000F), W16(0x0021), W16(0x001A), W16(0x0013), W16(0x0006), W16(0x0021), W16(0x0044), - W16(0x013C), W16(0x0128), W16(0x00CA), W16(0xFFFD), W16(0xFFC0), W16(0xFFA0), W16(0x0013), W16(0x0077), - W16(0x00E3), W16(0x00B9), W16(0x0066), W16(0xFFF7), W16(0xFFD2), W16(0xFFE0), W16(0xFF99), W16(0xFF5A), - W16(0xFF78), W16(0xFF7A), W16(0xFF80), W16(0xFF73), W16(0xFF90), W16(0xFF88), W16(0xFF86), W16(0xFF8B), - W16(0x0038), W16(0x006D), W16(0x004E), W16(0x0015), W16(0xFFF6), W16(0xFFF0), W16(0x0004), W16(0x000A), - W16(0x000E), W16(0xFFEE), W16(0xFFE1), W16(0xFFF1), W16(0xFFE5), W16(0xFFEE), W16(0xFFFA), W16(0x001B), - W16(0x0056), W16(0x00A5), W16(0x00D9), W16(0x0103), W16(0x0104), W16(0x0118), W16(0x012A), W16(0x0111), - W16(0x0299), W16(0x000F), W16(0xFFE1), W16(0xFFCC), W16(0xFFC8), W16(0xFFC3), W16(0xFFF5), W16(0xFFDB), - W16(0x0000), W16(0x0006), W16(0x0029), W16(0x001B), W16(0x001F), W16(0xFFF5), W16(0x0011), W16(0x0011), - W16(0x0023), W16(0x002A), W16(0x003B), W16(0x0046), W16(0x004F), W16(0x0049), W16(0x0058), W16(0x0053), - W16(0x004B), W16(0x0043), W16(0x0088), W16(0x00CD), W16(0x0037), W16(0xFE8A), W16(0xFEB7), W16(0xFF69), - W16(0x0019), W16(0x0084), W16(0x0058), W16(0xFFF1), W16(0xFF76), W16(0x00C5), W16(0x016A), W16(0x0028), - W16(0x006B), W16(0x004E), W16(0x001C), W16(0xFFD0), W16(0x0032), W16(0xFFB9), W16(0xFF95), W16(0xFFC6), - W16(0xFF8D), W16(0x005A), W16(0x00CB), W16(0x0100), W16(0x0056), W16(0xFFD6), W16(0x001A), W16(0xFFC6), - W16(0xFFBE), W16(0xFFE8), W16(0xFFEF), W16(0x0009), W16(0xFFF5), W16(0xFFDD), W16(0xFFF6), W16(0x003D), - W16(0x0053), W16(0x00B0), W16(0x00D2), W16(0x0092), W16(0x0050), W16(0x0023), W16(0x0014), W16(0xFFFB), - W16(0x0119), W16(0x0057), W16(0x0013), W16(0x0009), W16(0xFFF2), W16(0xFFBD), W16(0xFF9C), W16(0xFF9F), - W16(0xFFB8), W16(0xFFB1), W16(0xFFE9), W16(0xFFDE), W16(0xFFFC), W16(0x0036), W16(0x007D), W16(0x0096), - W16(0x00A1), W16(0x00CB), W16(0x00FC), W16(0x011C), W16(0x00A5), W16(0x003F), W16(0x0010), W16(0xFFE0), - W16(0x007C), W16(0x00BA), W16(0x0029), W16(0xFF86), W16(0xFF34), W16(0xFFD2), W16(0xFFB7), W16(0xFFE5), - W16(0x0033), W16(0x0041), W16(0x0035), W16(0xFFFB), W16(0x0037), W16(0x0040), W16(0x000B), W16(0x000C), - W16(0x0029), W16(0x0038), W16(0x006F), W16(0x00B3), W16(0x00C6), W16(0x00C4), W16(0x00BB), W16(0x009C), - W16(0x00E5), W16(0x00CF), W16(0x0125), W16(0x00BA), W16(0xFFFD), W16(0x0010), W16(0x0007), W16(0xFFA1), - W16(0xFFFB), W16(0xFFFE), W16(0x0005), W16(0x000E), W16(0x0004), W16(0xFFDE), W16(0x0026), W16(0x0020), - W16(0x0017), W16(0xFFE3), W16(0xFFA9), W16(0xFF84), W16(0xFF5A), W16(0xFF1B), W16(0xFEAE), W16(0xFE61), - W16(0xFD6E), W16(0x012D), W16(0x014A), W16(0x01A9), W16(0x02D2), W16(0x02CA), W16(0x01CC), W16(0xFF5B), - W16(0xFF28), W16(0xFEF0), W16(0xFE82), W16(0xFDF4), W16(0xFDFF), W16(0xFFE2), W16(0x00A4), W16(0x0063), - W16(0xFFC7), W16(0xFF44), W16(0xFEE8), W16(0xFEBA), W16(0xFE4F), W16(0xFF09), W16(0xFE6C), W16(0xFDBE), - W16(0xFFD3), W16(0x0007), W16(0x00A0), W16(0x0043), W16(0x0035), W16(0x0060), W16(0x007A), W16(0x0039), - W16(0xFFD4), W16(0xFFEE), W16(0xFFB3), W16(0xFFAD), W16(0xFFE3), W16(0x008D), W16(0x0055), W16(0xFF7B), - W16(0xFF56), W16(0x0096), W16(0x011B), W16(0x00F3), W16(0x009A), W16(0x006B), W16(0xFFBC), W16(0xFEEB), - W16(0x0298), W16(0x01D9), W16(0x0134), W16(0x0082), W16(0x0005), W16(0x002A), W16(0xFFE3), W16(0xFFB3), - W16(0xFFCA), W16(0xFFF4), W16(0x0019), W16(0x0036), W16(0x0023), W16(0x0010), W16(0x0011), W16(0xFFF2), - W16(0xFFF7), W16(0xFFF5), W16(0xFFFF), W16(0x0001), W16(0x0022), W16(0x003E), W16(0x0047), W16(0x0037) -}; - -const Word16 cdk_37bits_3_fx[1536] = -{ - W16(0xFFCD), W16(0xFFFB), W16(0xFFC7), W16(0x0024), W16(0x0000), W16(0xFFAB), W16(0x014C), W16(0xFF9A), - W16(0xFFF0), W16(0xFFF1), W16(0x0002), W16(0x0015), W16(0xFFF3), W16(0xFFDC), W16(0xFFD2), W16(0x000F), - W16(0xFFC6), W16(0xFFF3), W16(0xFFF1), W16(0x0032), W16(0x006F), W16(0x0054), W16(0x008F), W16(0x009B), - W16(0x001C), W16(0x0006), W16(0xFFFE), W16(0xFFF3), W16(0xFFDF), W16(0xFF49), W16(0xFFB0), W16(0xFFC8), - W16(0xFFFB), W16(0xFFC2), W16(0xFFE5), W16(0xFFBF), W16(0xFFFC), W16(0x00B0), W16(0x0129), W16(0x0079), - W16(0xFFB2), W16(0xFF40), W16(0xFF97), W16(0xFF9B), W16(0xFFCB), W16(0xFFB6), W16(0xFFB4), W16(0xFFBD), - W16(0xFEFA), W16(0xFFA2), W16(0xFF63), W16(0xFFB2), W16(0xFFAB), W16(0xFFAF), W16(0x000F), W16(0x0024), - W16(0x0003), W16(0xFFD1), W16(0xFFF4), W16(0xFFB4), W16(0xFFFC), W16(0x001D), W16(0x0041), W16(0x0066), - W16(0x0039), W16(0xFFE5), W16(0xFFE3), W16(0x000D), W16(0x003B), W16(0x0076), W16(0x0069), W16(0x0044), - W16(0xFF95), W16(0xFF75), W16(0xFF97), W16(0xFFE8), W16(0x0022), W16(0xFFBB), W16(0x0009), W16(0x0049), - W16(0x0046), W16(0x0004), W16(0xFFFA), W16(0x0010), W16(0x001C), W16(0xFFDB), W16(0xFFE9), W16(0xFFCA), - W16(0xFFD3), W16(0xFFAE), W16(0xFFAC), W16(0xFFA9), W16(0xFF8C), W16(0xFF7B), W16(0xFF71), W16(0xFF78), - W16(0x002E), W16(0xFF90), W16(0xFF94), W16(0xFFA4), W16(0xFFAF), W16(0xFFEF), W16(0x0000), W16(0x0076), - W16(0x001E), W16(0x0031), W16(0x0044), W16(0x0081), W16(0xFFFE), W16(0xFFA3), W16(0xFF90), W16(0xFFB4), - W16(0xFFF2), W16(0x0053), W16(0x011E), W16(0x0107), W16(0xFF79), W16(0xFFBB), W16(0xFF82), W16(0xFED6), - W16(0xFFD0), W16(0x004A), W16(0x002F), W16(0xFF34), W16(0xFF4E), W16(0x0016), W16(0x0007), W16(0x0047), - W16(0x004D), W16(0x0025), W16(0x000F), W16(0x0018), W16(0xFFF9), W16(0xFFF9), W16(0xFFDC), W16(0xFFE9), - W16(0xFFFF), W16(0xFFCE), W16(0xFFB7), W16(0xFFB8), W16(0xFFB0), W16(0xFFB4), W16(0xFFB1), W16(0xFF9A), - W16(0x006B), W16(0xFFDD), W16(0x0002), W16(0xFFE4), W16(0xFFE1), W16(0xFFE2), W16(0xFFD5), W16(0xFFC3), - W16(0xFFEC), W16(0xFFE6), W16(0x000D), W16(0xFFD7), W16(0xFF99), W16(0xFFBD), W16(0x0001), W16(0x00C4), - W16(0x00D3), W16(0xFF57), W16(0xFF8A), W16(0xFF78), W16(0xFFF6), W16(0xFFEA), W16(0xFFDC), W16(0xFFDC), - W16(0xFFD2), W16(0x001D), W16(0x0017), W16(0x0004), W16(0xFFF0), W16(0x0014), W16(0xFFF6), W16(0xFF21), - W16(0x0020), W16(0x0041), W16(0x0030), W16(0x000C), W16(0xFFCA), W16(0xFFFF), W16(0x0037), W16(0x003D), - W16(0x000A), W16(0xFFEA), W16(0xFFE0), W16(0xFFCC), W16(0xFFD4), W16(0xFFC0), W16(0xFFD0), W16(0xFFCD), - W16(0xFF6A), W16(0xFFEF), W16(0xFFFF), W16(0x002C), W16(0xFFC8), W16(0x0077), W16(0x0059), W16(0x000B), - W16(0xFFF5), W16(0xFFFA), W16(0xFFF6), W16(0xFFF1), W16(0xFFDD), W16(0xFFCF), W16(0xFFEA), W16(0xFFF1), - W16(0x0000), W16(0xFFF9), W16(0xFFE4), W16(0xFFB7), W16(0xFF96), W16(0xFF61), W16(0xFF43), W16(0xFF3C), - W16(0xFFE4), W16(0xFFE7), W16(0xFFA0), W16(0xFFA4), W16(0x003D), W16(0x00B1), W16(0x0085), W16(0xFFFC), - W16(0xFF91), W16(0xFFCD), W16(0x0002), W16(0x0011), W16(0xFFF4), W16(0x002A), W16(0xFFE1), W16(0xFF92), - W16(0xFF8F), W16(0xFF82), W16(0xFF9A), W16(0xFFB1), W16(0xFFBE), W16(0xFFEA), W16(0x0011), W16(0x002A), - W16(0xFFAC), W16(0xFFD1), W16(0xFFC2), W16(0xFF84), W16(0xFFCF), W16(0xFFFD), W16(0xFFB5), W16(0xFFA4), - W16(0xFFE6), W16(0xFFD3), W16(0x001E), W16(0x0061), W16(0x0062), W16(0xFFFA), W16(0x0023), W16(0x0016), - W16(0x000D), W16(0x000E), W16(0x000E), W16(0x0003), W16(0x0009), W16(0x0015), W16(0x000A), W16(0x0002), - W16(0xFFB7), W16(0xFFD9), W16(0xFFE4), W16(0xFFBB), W16(0x00F9), W16(0xFFCC), W16(0xFFC6), W16(0xFFA8), - W16(0x0026), W16(0x0005), W16(0x0014), W16(0x0039), W16(0x0040), W16(0xFFE4), W16(0xFF68), W16(0xFF9A), - W16(0x002F), W16(0x0058), W16(0xFFB2), W16(0x001C), W16(0xFFCC), W16(0xFF92), W16(0xFF7D), W16(0xFF60), - W16(0xFFB4), W16(0xFFA5), W16(0xFFEC), W16(0xFFF2), W16(0xFFDD), W16(0xFFF6), W16(0x0033), W16(0x00A0), - W16(0x0097), W16(0x0028), W16(0xFFB8), W16(0xFF58), W16(0xFFA8), W16(0x0024), W16(0xFFE4), W16(0xFFE0), - W16(0xFFFB), W16(0xFFEB), W16(0xFFE2), W16(0xFFD9), W16(0xFFFC), W16(0xFFF7), W16(0x000F), W16(0x0004), - W16(0x0053), W16(0x0020), W16(0x004C), W16(0xFFFC), W16(0x003C), W16(0x0052), W16(0x0027), W16(0x000E), - W16(0x0050), W16(0x0024), W16(0x001C), W16(0xFFE9), W16(0xFFDE), W16(0xFFDB), W16(0xFFBA), W16(0xFFB3), - W16(0xFF9E), W16(0xFFAD), W16(0xFFA2), W16(0xFFA3), W16(0xFFB2), W16(0xFFAA), W16(0xFFB4), W16(0xFFBC), - W16(0xFFF7), W16(0xFFF0), W16(0xFFE4), W16(0x000B), W16(0xFFDE), W16(0xFFE3), W16(0x0024), W16(0xFFB4), - W16(0x0062), W16(0x0045), W16(0xFFCB), W16(0xFFB0), W16(0x00DD), W16(0x006B), W16(0xFF74), W16(0xFF89), - W16(0x0001), W16(0xFFBB), W16(0xFFCD), W16(0xFF9D), W16(0xFF92), W16(0xFF76), W16(0xFF9F), W16(0xFFCF), - W16(0xFF91), W16(0xFF37), W16(0xFFB4), W16(0x00BC), W16(0x004A), W16(0xFFB2), W16(0x001B), W16(0xFF97), - W16(0xFF7D), W16(0x0039), W16(0x003C), W16(0xFFE1), W16(0x0007), W16(0xFFEF), W16(0x0045), W16(0x0031), - W16(0x0014), W16(0x0069), W16(0x005C), W16(0xFFF5), W16(0xFFE8), W16(0xFFD8), W16(0xFFA5), W16(0xFFCB), - W16(0x0024), W16(0x000A), W16(0xFEB4), W16(0x0002), W16(0x0003), W16(0xFFCA), W16(0x002D), W16(0xFFE3), - W16(0xFFF5), W16(0xFFE2), W16(0xFFFE), W16(0x000E), W16(0x0008), W16(0x000F), W16(0x0019), W16(0x0032), - W16(0xFFDD), W16(0xFFFB), W16(0xFFCE), W16(0xFFBA), W16(0xFFC9), W16(0xFFDE), W16(0x000E), W16(0x003D), - W16(0xFFC6), W16(0xFFDD), W16(0xFFA6), W16(0xFFB3), W16(0x0105), W16(0xFFDA), W16(0xFFD0), W16(0xFFCD), - W16(0x0000), W16(0xFFB9), W16(0x0018), W16(0xFF8C), W16(0xFFF1), W16(0xFFD9), W16(0x0030), W16(0x002F), - W16(0xFFFF), W16(0xFFF1), W16(0xFFF6), W16(0x0000), W16(0xFFFC), W16(0x0017), W16(0x003C), W16(0x004E), - W16(0xFED7), W16(0x0028), W16(0x0038), W16(0x0015), W16(0x0006), W16(0xFFF7), W16(0xFFF2), W16(0xFFEC), - W16(0xFFD4), W16(0xFFCF), W16(0xFFE3), W16(0x0024), W16(0x0022), W16(0x000D), W16(0x0027), W16(0x0014), - W16(0x0010), W16(0x0015), W16(0x0028), W16(0x001C), W16(0x0007), W16(0xFFD2), W16(0xFFBD), W16(0xFF93), - W16(0x0068), W16(0xFF90), W16(0x002E), W16(0x007D), W16(0x001B), W16(0x004E), W16(0x000D), W16(0x006E), - W16(0x0039), W16(0xFFF7), W16(0xFF97), W16(0x0018), W16(0xFFF1), W16(0xFFC5), W16(0xFF94), W16(0xFFDB), - W16(0x0018), W16(0x0003), W16(0x001A), W16(0xFFE9), W16(0xFFBC), W16(0xFF9E), W16(0xFF96), W16(0xFF88), - W16(0xFFB0), W16(0xFF7C), W16(0xFF95), W16(0x002C), W16(0xFF96), W16(0xFFB9), W16(0x005F), W16(0x0042), - W16(0xFFEA), W16(0xFFBE), W16(0xFFDC), W16(0x0030), W16(0x00AB), W16(0x006D), W16(0xFFC0), W16(0xFFA5), - W16(0xFFE0), W16(0x0098), W16(0x007B), W16(0x0017), W16(0x0040), W16(0x0079), W16(0x005B), W16(0x002E), - W16(0x0021), W16(0x001A), W16(0x0055), W16(0xFFCE), W16(0xFF7A), W16(0x0058), W16(0x001F), W16(0xFFC7), - W16(0xFFCA), W16(0x002E), W16(0x001E), W16(0x0020), W16(0x0004), W16(0x0014), W16(0x000C), W16(0xFFF8), - W16(0xFFF7), W16(0xFFE0), W16(0xFFCF), W16(0xFFEF), W16(0x00B1), W16(0x00C8), W16(0xFF9A), W16(0xFF27), - W16(0x000D), W16(0x0039), W16(0x0036), W16(0x0009), W16(0xFFC7), W16(0xFFBB), W16(0xFFE9), W16(0x0019), - W16(0x0004), W16(0x000D), W16(0x0007), W16(0xFFF6), W16(0xFFF1), W16(0x0018), W16(0x0013), W16(0x003A), - W16(0x0017), W16(0xFFAF), W16(0xFF5F), W16(0xFF23), W16(0xFF3C), W16(0xFF6D), W16(0xFFB3), W16(0x0035), - W16(0xFFAC), W16(0x0041), W16(0xFFE3), W16(0x0054), W16(0xFFCB), W16(0x003E), W16(0xFFFE), W16(0x000E), - W16(0x003A), W16(0x003C), W16(0x0018), W16(0xFFDF), W16(0xFFFB), W16(0x0012), W16(0xFFE9), W16(0xFFC7), - W16(0xFFC1), W16(0xFFE2), W16(0xFFFF), W16(0x0009), W16(0x001F), W16(0x0018), W16(0x0015), W16(0x0009), - W16(0xFFEA), W16(0xFFBD), W16(0xFFEC), W16(0xFFD1), W16(0xFFF5), W16(0x0036), W16(0x005A), W16(0x002D), - W16(0xFFD8), W16(0xFF85), W16(0xFF4D), W16(0xFFA3), W16(0xFFE4), W16(0x0015), W16(0x0097), W16(0x0050), - W16(0x0021), W16(0xFFDA), W16(0xFFB6), W16(0x003A), W16(0xFFF8), W16(0xFFD2), W16(0xFFD6), W16(0xFFD8), - W16(0x0084), W16(0xFF0B), W16(0xFFEF), W16(0xFFD7), W16(0xFFCF), W16(0x0001), W16(0xFFE0), W16(0xFFFE), - W16(0x001C), W16(0x0020), W16(0x0018), W16(0x0005), W16(0xFFF3), W16(0x0009), W16(0xFFFF), W16(0x0007), - W16(0xFFF8), W16(0xFFF2), W16(0xFFF3), W16(0x0001), W16(0x0008), W16(0x000A), W16(0x0014), W16(0x000E), - W16(0xFFD6), W16(0xFFB8), W16(0xFFC6), W16(0xFFF9), W16(0x0008), W16(0xFFFD), W16(0xFFE6), W16(0x0048), - W16(0xFF6D), W16(0x005B), W16(0x0013), W16(0x002F), W16(0xFFD8), W16(0x0003), W16(0x0002), W16(0xFFF8), - W16(0xFFEE), W16(0x0008), W16(0xFFFB), W16(0xFFF6), W16(0xFFFC), W16(0xFFFF), W16(0x0002), W16(0x0002), - W16(0x0059), W16(0x006C), W16(0xFFE7), W16(0x004C), W16(0x0074), W16(0x0086), W16(0x0037), W16(0xFFA6), - W16(0xFFD0), W16(0xFFD6), W16(0xFFC0), W16(0xFFCD), W16(0xFFC3), W16(0xFFD8), W16(0xFFFE), W16(0x0026), - W16(0x0037), W16(0x0027), W16(0x0003), W16(0xFFE9), W16(0xFFC5), W16(0xFFB8), W16(0xFFCD), W16(0xFFCF), - W16(0x0005), W16(0x0037), W16(0x001E), W16(0xFFFC), W16(0x0022), W16(0x0034), W16(0xFF0F), W16(0x002B), - W16(0x0037), W16(0x002D), W16(0x0013), W16(0x0021), W16(0x000C), W16(0x0003), W16(0x000D), W16(0xFFEE), - W16(0xFFCF), W16(0xFFE6), W16(0xFFF6), W16(0xFFEC), W16(0xFFDB), W16(0xFFDB), W16(0xFFDC), W16(0xFFCF), - W16(0xFF53), W16(0x0078), W16(0x00C4), W16(0xFFC3), W16(0x0051), W16(0x0005), W16(0x0002), W16(0x0022), - W16(0x001C), W16(0x0028), W16(0xFFF9), W16(0xFFE4), W16(0xFFF7), W16(0xFFE5), W16(0xFFC9), W16(0xFFE1), - W16(0xFFDF), W16(0xFFE1), W16(0xFFE8), W16(0x0007), W16(0x003C), W16(0x005F), W16(0x0083), W16(0x0089), - W16(0x00EB), W16(0x0009), W16(0xFFB7), W16(0xFF7B), W16(0xFFD0), W16(0x0024), W16(0xFFC8), W16(0xFFBD), - W16(0xFFDF), W16(0xFFE4), W16(0xFFF5), W16(0x002E), W16(0x0023), W16(0x001D), W16(0x002C), W16(0x001B), - W16(0x001A), W16(0xFFF8), W16(0xFFEA), W16(0xFFD5), W16(0xFFE9), W16(0xFFD1), W16(0xFFC9), W16(0xFFC1), - W16(0xFFE3), W16(0xFFB1), W16(0x0009), W16(0x0096), W16(0x0111), W16(0x00E2), W16(0xFFEA), W16(0xFFBB), - W16(0x000E), W16(0xFFF0), W16(0xFFBC), W16(0xFFF9), W16(0xFFC7), W16(0xFF9E), W16(0xFFA3), W16(0xFFBD), - W16(0xFFEE), W16(0x001E), W16(0x0002), W16(0x0020), W16(0x0032), W16(0x0051), W16(0x0052), W16(0x0062), - W16(0x0032), W16(0x0041), W16(0xFFE4), W16(0xFF9B), W16(0x001C), W16(0xFF48), W16(0x0000), W16(0x002F), - W16(0x0015), W16(0x0014), W16(0x003D), W16(0x0026), W16(0xFFF1), W16(0x0015), W16(0xFFF1), W16(0xFFF9), - W16(0xFFF0), W16(0xFFF4), W16(0xFFED), W16(0xFFFA), W16(0x000D), W16(0x001C), W16(0x002B), W16(0x0023), - W16(0xFFEB), W16(0xFFCF), W16(0x0049), W16(0x0037), W16(0x0039), W16(0xFFBA), W16(0xFFF9), W16(0xFFFD), - W16(0x0045), W16(0x0021), W16(0xFF72), W16(0x0033), W16(0x0010), W16(0x0017), W16(0xFFF6), W16(0x0002), - W16(0xFFEC), W16(0xFFDB), W16(0xFFD4), W16(0xFFC8), W16(0xFFE3), W16(0xFFF4), W16(0x0015), W16(0x0019), - W16(0xFFAC), W16(0xFFB9), W16(0x000E), W16(0xFFA3), W16(0xFF88), W16(0xFFB0), W16(0xFFF1), W16(0xFFEA), - W16(0xFFED), W16(0xFFD8), W16(0x0009), W16(0x0004), W16(0xFFEF), W16(0x002C), W16(0x0051), W16(0x004E), - W16(0x0062), W16(0x0074), W16(0x0075), W16(0x0055), W16(0x0027), W16(0x000F), W16(0xFFF2), W16(0xFFDA), - W16(0xFF96), W16(0xFFB4), W16(0x0033), W16(0x001C), W16(0xFF5C), W16(0xFFC5), W16(0xFFC8), W16(0xFFD7), - W16(0x000D), W16(0x0059), W16(0x0077), W16(0x006A), W16(0x002C), W16(0x002D), W16(0x0003), W16(0xFFD2), - W16(0xFFCD), W16(0xFFD8), W16(0xFFD0), W16(0xFFED), W16(0xFFEA), W16(0xFFE8), W16(0xFFF9), W16(0xFFF6), - W16(0x0052), W16(0xFFD4), W16(0xFF5B), W16(0xFF8B), W16(0xFFA9), W16(0x003F), W16(0x007C), W16(0x0028), - W16(0x001B), W16(0x0010), W16(0xFFD1), W16(0xFFCD), W16(0x0004), W16(0xFFCA), W16(0xFFEE), W16(0xFFE7), - W16(0x0008), W16(0x0047), W16(0x0086), W16(0x0087), W16(0x0064), W16(0x0024), W16(0x000C), W16(0xFFD7), - W16(0x00A6), W16(0x008E), W16(0x0077), W16(0xFFD8), W16(0xFF6A), W16(0x003A), W16(0x003B), W16(0x0017), - W16(0x0028), W16(0x0010), W16(0xFFFA), W16(0xFFDE), W16(0xFFFC), W16(0xFFEC), W16(0xFFE0), W16(0x000B), - W16(0x0026), W16(0x003C), W16(0x003F), W16(0x003E), W16(0x0049), W16(0x006F), W16(0x0080), W16(0x0080), - W16(0xFFB8), W16(0xFFC2), W16(0xFFBE), W16(0x0017), W16(0xFFF9), W16(0xFFF0), W16(0xFFE0), W16(0xFFE4), - W16(0x0027), W16(0x0000), W16(0xFFE9), W16(0x00A2), W16(0x002E), W16(0xFF66), W16(0xFF4F), W16(0x0042), - W16(0x007C), W16(0xFFE4), W16(0xFFF6), W16(0x000A), W16(0x0039), W16(0x0054), W16(0x0054), W16(0x0033), - W16(0xFFD9), W16(0x0003), W16(0x0012), W16(0x0010), W16(0x000B), W16(0x0000), W16(0xFF97), W16(0xFF97), - W16(0xFFC8), W16(0x00AF), W16(0x0215), W16(0xFF25), W16(0xFFD7), W16(0xFFF1), W16(0xFF98), W16(0xFFC3), - W16(0xFFF2), W16(0x0005), W16(0xFFDA), W16(0x0052), W16(0x0069), W16(0x0051), W16(0x008A), W16(0x00CA), - W16(0xFFAB), W16(0xFF9D), W16(0x00C3), W16(0x006D), W16(0x002D), W16(0x006D), W16(0x0064), W16(0x0037), - W16(0xFFBA), W16(0xFFA4), W16(0xFFB3), W16(0xFFF0), W16(0xFFFE), W16(0x0045), W16(0x0029), W16(0xFFD6), - W16(0xFF87), W16(0xFFCD), W16(0xFFFF), W16(0xFFCF), W16(0xFFFF), W16(0xFFE4), W16(0x0003), W16(0x0021), - W16(0x0066), W16(0xFF93), W16(0xFFAD), W16(0xFFFA), W16(0xFFC8), W16(0xFFA4), W16(0xFFD9), W16(0x0072), - W16(0x0007), W16(0x000D), W16(0x0011), W16(0x004A), W16(0x002A), W16(0x002B), W16(0x0002), W16(0xFFDF), - W16(0xFFA4), W16(0xFF6C), W16(0xFF66), W16(0xFF97), W16(0x0035), W16(0x0084), W16(0x00B6), W16(0x00EA), - W16(0x0017), W16(0xFFDC), W16(0x005C), W16(0x004A), W16(0xFFF1), W16(0x0038), W16(0xFFE1), W16(0xFF9F), - W16(0xFF3F), W16(0xFF63), W16(0xFFDE), W16(0x0092), W16(0x0082), W16(0x0053), W16(0x0033), W16(0x003F), - W16(0xFFFF), W16(0xFFEB), W16(0xFFD3), W16(0xFFC8), W16(0xFFC0), W16(0xFFD9), W16(0xFFBD), W16(0xFFA6), - W16(0xFFFE), W16(0x0006), W16(0x0045), W16(0xFF02), W16(0x0036), W16(0x008E), W16(0x000B), W16(0xFFE4), - W16(0x001C), W16(0xFFEF), W16(0xFFCF), W16(0xFFD5), W16(0xFFD3), W16(0xFFFA), W16(0xFFE6), W16(0xFFF1), - W16(0xFFFB), W16(0x001D), W16(0x0019), W16(0x001A), W16(0x002E), W16(0x0022), W16(0x0011), W16(0x0005), - W16(0x00D4), W16(0x0039), W16(0x0060), W16(0x0018), W16(0xFFC9), W16(0xFFB3), W16(0xFFDF), W16(0x0057), - W16(0x00B5), W16(0x007C), W16(0x001F), W16(0xFF64), W16(0xFF9B), W16(0xFFF1), W16(0x0011), W16(0xFFD2), - W16(0x002A), W16(0x0029), W16(0x001F), W16(0x0000), W16(0x002A), W16(0x0017), W16(0x0019), W16(0xFFEF), - W16(0x0082), W16(0x0064), W16(0x0002), W16(0x0057), W16(0x0006), W16(0x002D), W16(0x005F), W16(0x006D), - W16(0xFFF1), W16(0x0035), W16(0x0017), W16(0x001B), W16(0xFFB5), W16(0xFF99), W16(0xFFBE), W16(0xFFD3), - W16(0xFFCA), W16(0xFFD1), W16(0xFFDB), W16(0xFFE2), W16(0xFFF8), W16(0xFFF8), W16(0x000B), W16(0x0000), - W16(0x005A), W16(0x0064), W16(0x0024), W16(0x0001), W16(0xFFCF), W16(0xFFA4), W16(0xFF80), W16(0xFFA0), - W16(0xFFE3), W16(0xFFEF), W16(0xFFC4), W16(0x0006), W16(0x0022), W16(0x0093), W16(0x004D), W16(0x006A), - W16(0x0065), W16(0x0030), W16(0x001C), W16(0x001A), W16(0x0029), W16(0x004A), W16(0x0064), W16(0x0061), - W16(0xFFD8), W16(0xFF96), W16(0x000D), W16(0x008E), W16(0xFFDB), W16(0xFFB8), W16(0xFF8A), W16(0x0013), - W16(0x004D), W16(0x0032), W16(0x002E), W16(0xFFBB), W16(0xFFD1), W16(0xFFF1), W16(0x0062), W16(0x001F), - W16(0x0025), W16(0x003D), W16(0x0036), W16(0x0033), W16(0x0091), W16(0x008C), W16(0x0064), W16(0x0041), - W16(0x0053), W16(0x0030), W16(0xFF71), W16(0x005F), W16(0x0086), W16(0xFFCC), W16(0xFF97), W16(0xFFE9), - W16(0xFFF9), W16(0xFFAC), W16(0xFFD8), W16(0x0017), W16(0xFFF9), W16(0x001C), W16(0x000B), W16(0x001F), - W16(0x005A), W16(0x0052), W16(0x0036), W16(0xFFF3), W16(0xFFE2), W16(0xFFCE), W16(0xFFC4), W16(0xFFBA), - W16(0x0019), W16(0x0030), W16(0x0044), W16(0xFFD3), W16(0x000C), W16(0xFFF5), W16(0x0011), W16(0x0030), - W16(0x0029), W16(0xFF5C), W16(0x002B), W16(0x0012), W16(0x0008), W16(0x0004), W16(0x001F), W16(0xFFFA), - W16(0xFFD8), W16(0xFFE9), W16(0xFFE1), W16(0xFFE0), W16(0xFFF7), W16(0xFFF2), W16(0xFFF2), W16(0xFFDC), - W16(0xFFA8), W16(0x00AA), W16(0xFFE6), W16(0x0022), W16(0x000F), W16(0xFFE9), W16(0x0015), W16(0x0043), - W16(0x004C), W16(0xFFE2), W16(0xFFCE), W16(0xFFF5), W16(0xFFEB), W16(0xFFAC), W16(0xFFCE), W16(0x0016), - W16(0x0044), W16(0x005C), W16(0x003F), W16(0x0020), W16(0x0008), W16(0xFFF9), W16(0xFFF1), W16(0xFFE4), - W16(0x0033), W16(0x0005), W16(0x0088), W16(0x0023), W16(0x004C), W16(0xFFBB), W16(0x0015), W16(0x0011), - W16(0x0024), W16(0x002F), W16(0x0019), W16(0x0004), W16(0xFFC8), W16(0xFFB5), W16(0xFFDC), W16(0x0006), - W16(0x0004), W16(0x0011), W16(0x000E), W16(0x0003), W16(0xFFE2), W16(0xFFB2), W16(0xFF99), W16(0xFF7B), - W16(0xFFEE), W16(0xFFF8), W16(0x0017), W16(0x002B), W16(0xFF2C), W16(0xFFA2), W16(0x0086), W16(0x00F1), - W16(0xFFD0), W16(0xFFDD), W16(0xFFD5), W16(0x0032), W16(0x002C), W16(0xFFD5), W16(0xFFFD), W16(0x002B), - W16(0xFFDD), W16(0xFFE7), W16(0xFFF7), W16(0x003C), W16(0x0011), W16(0x002D), W16(0x004D), W16(0x001F), - W16(0xFFCE), W16(0x001A), W16(0x0052), W16(0xFF95), W16(0xFFFC), W16(0xFFEC), W16(0x0007), W16(0x0013), - W16(0x0013), W16(0x000F), W16(0xFFD7), W16(0x0057), W16(0x0028), W16(0x0019), W16(0xFFCD), W16(0xFFD3), - W16(0xFFCC), W16(0xFFF5), W16(0x006F), W16(0x011E), W16(0x00C4), W16(0x0064), W16(0xFFE2), W16(0xFFA3), - W16(0x0053), W16(0xFFE8), W16(0xFFC4), W16(0x0022), W16(0xFF9D), W16(0x0004), W16(0xFFD3), W16(0x001C), - W16(0x0017), W16(0xFFF0), W16(0xFFF1), W16(0x0012), W16(0x0007), W16(0x001D), W16(0x0010), W16(0x0015), - W16(0x001B), W16(0x000B), W16(0xFFE1), W16(0xFFDA), W16(0xFFA6), W16(0xFF79), W16(0x0002), W16(0x020E), - W16(0x003B), W16(0x0003), W16(0xFFFB), W16(0xFFEC), W16(0xFFCA), W16(0xFFD2), W16(0xFFC8), W16(0xFFAB), - W16(0xFFE1), W16(0x0013), W16(0x0005), W16(0x0020), W16(0x0048), W16(0x005D), W16(0x00E1), W16(0xFFA6), - W16(0xFFAC), W16(0x0073), W16(0x008A), W16(0x005B), W16(0xFFDC), W16(0xFFD2), W16(0xFFEF), W16(0x001A), - W16(0x0035), W16(0x0050), W16(0x000C), W16(0x0047), W16(0x0049), W16(0x0038), W16(0x002E), W16(0x0074), - W16(0xFFE5), W16(0xFF9E), W16(0xFF99), W16(0xFFB6), W16(0xFFF1), W16(0x0004), W16(0x0028), W16(0x0004), - W16(0xFFEA), W16(0x0000), W16(0x0000), W16(0x001A), W16(0x0061), W16(0x0079), W16(0x008A), W16(0x00A0), - W16(0x00D0), W16(0xFFF3), W16(0x0055), W16(0x004B), W16(0x005A), W16(0x0016), W16(0xFFE5), W16(0xFFCC), - W16(0xFFC2), W16(0x0004), W16(0x0017), W16(0x0014), W16(0x0007), W16(0x0000), W16(0xFFFB), W16(0xFFF3), - W16(0xFFF9), W16(0xFFFD), W16(0xFFFD), W16(0x0015), W16(0x003F), W16(0x0045), W16(0x0053), W16(0x004B), - W16(0xFFE7), W16(0x005D), W16(0x0018), W16(0xFFE0), W16(0xFFF7), W16(0x0059), W16(0x003D), W16(0xFFEA), - W16(0xFEFA), W16(0xFFDF), W16(0xFFDD), W16(0x0009), W16(0x001F), W16(0x0016), W16(0x0034), W16(0x002E), - W16(0x0033), W16(0x003F), W16(0x004D), W16(0x002D), W16(0x0016), W16(0x0020), W16(0x0023), W16(0x0014), - W16(0xFFC7), W16(0xFFDE), W16(0x0056), W16(0xFFE8), W16(0x003A), W16(0x008F), W16(0xFFEB), W16(0xFFB7), - W16(0x0011), W16(0x0001), W16(0xFFD2), W16(0xFF83), W16(0xFF90), W16(0xFFEE), W16(0x0037), W16(0x0020), - W16(0x0059), W16(0x00BE), W16(0x00A3), W16(0x000F), W16(0xFF91), W16(0xFFB4), W16(0xFF97), W16(0xFF67), - W16(0xFFDF), W16(0x0046), W16(0xFF9A), W16(0xFFB2), W16(0xFFF0), W16(0x000E), W16(0xFF8F), W16(0xFFC7), - W16(0x0017), W16(0x005B), W16(0x0054), W16(0xFFFB), W16(0xFFC4), W16(0xFFD7), W16(0xFFE8), W16(0x0022), - W16(0x0043), W16(0x004C), W16(0x0066), W16(0x0074), W16(0x0092), W16(0x00B9), W16(0x00D5), W16(0x00BB), - W16(0x0071), W16(0x0148), W16(0x00DB), W16(0x00D4), W16(0x005C), W16(0x0031), W16(0x0012), W16(0x0025), - W16(0xFFE7), W16(0xFFEB), W16(0xFFD8), W16(0xFFC1), W16(0xFFE8), W16(0xFFED), W16(0xFFFA), W16(0x0001), - W16(0xFFFF), W16(0xFFF0), W16(0xFFE3), W16(0xFFE7), W16(0x0004), W16(0xFFFF), W16(0xFFF0), W16(0xFFF3), - W16(0x0055), W16(0x0136), W16(0xFFF5), W16(0xFFA3), W16(0xFFE5), W16(0xFFDC), W16(0xFFC6), W16(0xFFDD), - W16(0xFFDF), W16(0x0000), W16(0x0023), W16(0x0040), W16(0x0045), W16(0x0003), W16(0x0007), W16(0x000B), - W16(0x0002), W16(0x0004), W16(0xFFE8), W16(0xFFDF), W16(0xFFAD), W16(0xFFAA), W16(0xFF6E), W16(0xFF35), - W16(0x0017), W16(0x000B), W16(0x002B), W16(0x00DC), W16(0x00B1), W16(0xFFE2), W16(0xFFC0), W16(0x0001), - W16(0x0024), W16(0x0023), W16(0x0029), W16(0x006A), W16(0xFFED), W16(0xFFDF), W16(0xFFCA), W16(0xFF98), - W16(0xFFA4), W16(0xFFEA), W16(0x001A), W16(0x002C), W16(0x0003), W16(0x002A), W16(0x005F), W16(0x0077) -}; - -const Word16 cdk_37bits_4_fx[1536] = -{ - W16(0xFFF5), W16(0xFFA9), W16(0x000E), W16(0xFFC8), W16(0xFFCB), W16(0xFFB9), W16(0xFFD4), W16(0xFFCC), - W16(0xFFCB), W16(0xFFC8), W16(0xFFD3), W16(0x001A), W16(0x0049), W16(0x003A), W16(0x001F), W16(0x0044), - W16(0x0077), W16(0x004D), W16(0xFFEC), W16(0xFF84), W16(0xFFBC), W16(0xFFED), W16(0xFFE0), W16(0xFFE5), - W16(0x0033), W16(0xFFF7), W16(0xFFF9), W16(0x005E), W16(0x00B6), W16(0x003A), W16(0xFFEA), W16(0xFFA0), - W16(0xFFAB), W16(0xFFB9), W16(0xFFD3), W16(0xFFFB), W16(0xFFF2), W16(0xFFFA), W16(0x0010), W16(0x0029), - W16(0x002E), W16(0xFFD6), W16(0xFFCA), W16(0xFFBE), W16(0xFFC9), W16(0xFFCA), W16(0xFFD8), W16(0xFFD2), - W16(0xFF2B), W16(0x0024), W16(0xFFAF), W16(0x0020), W16(0x0068), W16(0x0038), W16(0x0015), W16(0x001B), - W16(0x0006), W16(0x0005), W16(0xFFF4), W16(0xFFCC), W16(0xFFD1), W16(0xFFF3), W16(0xFFDF), W16(0xFFBF), - W16(0x0003), W16(0xFFE3), W16(0x0001), W16(0x0018), W16(0x0021), W16(0x0010), W16(0xFFF4), W16(0xFFD9), - W16(0xFF6C), W16(0xFFD8), W16(0x0011), W16(0xFFB4), W16(0xFFD1), W16(0xFFBD), W16(0x0002), W16(0xFFDA), - W16(0x003A), W16(0x0033), W16(0x0038), W16(0x001D), W16(0x0030), W16(0x002A), W16(0xFFD3), W16(0xFFC7), - W16(0xFFDF), W16(0xFFC0), W16(0xFFDE), W16(0xFFD8), W16(0xFFB9), W16(0xFFCC), W16(0xFFDE), W16(0xFFFF), - W16(0xFFFA), W16(0xFFCE), W16(0xFFB7), W16(0xFFD7), W16(0x0031), W16(0x0017), W16(0xFFB0), W16(0x0018), - W16(0x003E), W16(0x002E), W16(0xFFE7), W16(0x0096), W16(0xFFCB), W16(0xFFC8), W16(0xFFDB), W16(0xFFB8), - W16(0xFFE0), W16(0xFFF6), W16(0xFFE9), W16(0xFFA6), W16(0xFFBD), W16(0xFFC1), W16(0xFFCC), W16(0xFFE0), - W16(0xFFF0), W16(0xFFDA), W16(0xFFD5), W16(0x000E), W16(0xFF85), W16(0x0112), W16(0xFFBB), W16(0xFFDF), - W16(0xFFF1), W16(0xFFF0), W16(0xFFED), W16(0xFFFB), W16(0xFFF6), W16(0x0009), W16(0x0010), W16(0xFFF1), - W16(0x0005), W16(0xFFE2), W16(0xFFDF), W16(0x0003), W16(0xFFBA), W16(0x0003), W16(0xFFFC), W16(0xFFD8), - W16(0xFFBE), W16(0x0070), W16(0xFF97), W16(0xFFC2), W16(0xFFE8), W16(0xFFF4), W16(0x001A), W16(0xFFE6), - W16(0xFFCD), W16(0xFFDA), W16(0xFFB6), W16(0x0020), W16(0x0020), W16(0x0035), W16(0xFFEC), W16(0x0029), - W16(0x003B), W16(0x0012), W16(0x0026), W16(0x002E), W16(0xFFF9), W16(0xFFE0), W16(0xFFD2), W16(0xFFBC), - W16(0x0042), W16(0xFF99), W16(0xFF90), W16(0x0013), W16(0x0007), W16(0xFFBE), W16(0x0007), W16(0x0016), - W16(0x0019), W16(0xFFC5), W16(0xFFF7), W16(0x001A), W16(0xFFC3), W16(0x002E), W16(0x002C), W16(0x0037), - W16(0xFFDC), W16(0xFFE5), W16(0x0001), W16(0x002A), W16(0x0022), W16(0x0042), W16(0x0043), W16(0x003B), - W16(0x002A), W16(0xFF9D), W16(0xFFD0), W16(0xFFFA), W16(0xFFC4), W16(0x000A), W16(0x0005), W16(0xFFD4), - W16(0x0036), W16(0x0036), W16(0xFFFB), W16(0xFFFC), W16(0xFFEE), W16(0xFFC3), W16(0xFF9A), W16(0x004E), - W16(0x005D), W16(0xFFF4), W16(0xFFEB), W16(0x0015), W16(0xFFF1), W16(0xFFD1), W16(0xFF99), W16(0xFF78), - W16(0x004F), W16(0xFFBD), W16(0xFFA8), W16(0x0053), W16(0x0038), W16(0xFFE5), W16(0xFFD2), W16(0x0026), - W16(0xFFE1), W16(0x0003), W16(0xFFD5), W16(0xFFAB), W16(0x0039), W16(0x0045), W16(0x0028), W16(0xFFF6), - W16(0xFFEB), W16(0xFFD6), W16(0xFFD5), W16(0xFFB9), W16(0xFFDA), W16(0xFFEE), W16(0x0000), W16(0x000E), - W16(0xFF7C), W16(0xFF75), W16(0xFFFF), W16(0xFFED), W16(0xFFFF), W16(0x002D), W16(0x001E), W16(0xFFB1), - W16(0x000A), W16(0x0015), W16(0xFFF0), W16(0xFFF8), W16(0xFFE5), W16(0x0015), W16(0x000E), W16(0x0012), - W16(0xFFE4), W16(0x0003), W16(0x000B), W16(0x000D), W16(0x0024), W16(0x003A), W16(0x0039), W16(0x0033), - W16(0xFFBA), W16(0xFFFD), W16(0xFFD0), W16(0xFFC4), W16(0xFFAE), W16(0x0020), W16(0x0024), W16(0x0050), - W16(0xFFFE), W16(0xFFF7), W16(0xFFE7), W16(0x000C), W16(0x0040), W16(0x001F), W16(0x001E), W16(0xFFD4), - W16(0xFF86), W16(0xFF87), W16(0xFF8B), W16(0xFFD1), W16(0x0024), W16(0x0036), W16(0xFFF4), W16(0xFFD6), - W16(0xFFFE), W16(0x001D), W16(0x0010), W16(0xFFDC), W16(0xFFD0), W16(0xFFF2), W16(0xFFE6), W16(0x0003), - W16(0xFFD5), W16(0xFFED), W16(0x006C), W16(0xFF8D), W16(0x000A), W16(0x0022), W16(0x0023), W16(0x001A), - W16(0x0030), W16(0xFFCA), W16(0xFFD4), W16(0xFFF2), W16(0x0004), W16(0xFFE5), W16(0xFFAB), W16(0xFF9B), - W16(0x0058), W16(0xFFD4), W16(0xFFA9), W16(0xFFAF), W16(0xFFDB), W16(0xFFF2), W16(0x003C), W16(0x008E), - W16(0x0007), W16(0xFFEE), W16(0xFFCE), W16(0xFFE0), W16(0xFFF7), W16(0xFFC4), W16(0xFFF3), W16(0xFFF7), - W16(0x0021), W16(0x0016), W16(0x0017), W16(0x000E), W16(0xFFF1), W16(0xFFF4), W16(0x0004), W16(0x0009), - W16(0xFFDA), W16(0xFFC0), W16(0x0048), W16(0x008F), W16(0x0007), W16(0xFF9C), W16(0xFFE3), W16(0xFFEF), - W16(0x0036), W16(0x0023), W16(0xFFF7), W16(0x000E), W16(0xFFEF), W16(0xFFF5), W16(0x0022), W16(0x0004), - W16(0x0022), W16(0xFFE7), W16(0xFFC5), W16(0xFFDC), W16(0xFFCE), W16(0xFFD7), W16(0xFFAE), W16(0xFF8F), - W16(0xFF94), W16(0x0053), W16(0xFFE9), W16(0xFFFD), W16(0x0002), W16(0x000E), W16(0xFFCA), W16(0xFFB0), - W16(0xFF9E), W16(0x0024), W16(0x0040), W16(0x0048), W16(0x0032), W16(0xFFBC), W16(0xFFFE), W16(0x0025), - W16(0x001A), W16(0xFFC6), W16(0xFFD6), W16(0xFFE9), W16(0xFFFB), W16(0x0012), W16(0x000C), W16(0x0005), - W16(0xFFB4), W16(0xFF9D), W16(0x001F), W16(0xFF74), W16(0xFFE3), W16(0xFFF2), W16(0xFFD9), W16(0x005A), - W16(0x0009), W16(0xFFDD), W16(0xFFEB), W16(0x0033), W16(0x0013), W16(0x0003), W16(0xFFD9), W16(0x0000), - W16(0x0004), W16(0x0000), W16(0x0008), W16(0x0045), W16(0x0022), W16(0x0038), W16(0x004F), W16(0x0036), - W16(0xFFC8), W16(0xFFE4), W16(0xFFD6), W16(0x0076), W16(0x0020), W16(0xFFEE), W16(0x004C), W16(0xFFFA), - W16(0xFFB2), W16(0x0008), W16(0x002E), W16(0x001B), W16(0x0002), W16(0xFFEC), W16(0xFFDD), W16(0xFFEF), - W16(0xFFEE), W16(0xFFD1), W16(0xFFC8), W16(0xFFC8), W16(0xFFBB), W16(0xFFE7), W16(0x0008), W16(0x0018), - W16(0xFFF5), W16(0xFFBA), W16(0x000D), W16(0x001B), W16(0x0045), W16(0x0013), W16(0x0001), W16(0x0010), - W16(0x000D), W16(0xFFF9), W16(0x0043), W16(0x000D), W16(0xFFCD), W16(0xFFF2), W16(0x007E), W16(0xFFAA), - W16(0xFF59), W16(0x00A5), W16(0x0018), W16(0xFFEA), W16(0xFFAE), W16(0xFFCB), W16(0xFFD4), W16(0x0013), - W16(0xFFEA), W16(0xFFA6), W16(0xFFB1), W16(0xFFA5), W16(0x0036), W16(0xFFB5), W16(0xFFB5), W16(0xFFD0), - W16(0xFFD2), W16(0x002D), W16(0x002C), W16(0x0013), W16(0xFFF5), W16(0x0013), W16(0x001C), W16(0x001F), - W16(0x000F), W16(0x001F), W16(0x001A), W16(0x002E), W16(0x001C), W16(0xFFF4), W16(0xFFBE), W16(0xFF9E), - W16(0x000C), W16(0x0037), W16(0xFFDB), W16(0x001C), W16(0x003D), W16(0xFF98), W16(0xFF81), W16(0x0097), - W16(0x005A), W16(0x0001), W16(0xFFDE), W16(0xFFCB), W16(0x0024), W16(0xFFFD), W16(0xFFED), W16(0x0011), - W16(0xFFF0), W16(0xFFD4), W16(0xFFCA), W16(0xFFD8), W16(0xFFD8), W16(0xFFE1), W16(0xFFE2), W16(0xFFD1), - W16(0xFFF7), W16(0xFFD4), W16(0xFFF8), W16(0xFFAD), W16(0x002B), W16(0x002B), W16(0xFFC9), W16(0xFFED), - W16(0xFFED), W16(0x0006), W16(0xFFEE), W16(0xFFCF), W16(0xFF8C), W16(0x0007), W16(0x0022), W16(0x0011), - W16(0x007F), W16(0x005A), W16(0x001C), W16(0xFFBB), W16(0xFF8E), W16(0xFFF7), W16(0x00B9), W16(0x00C3), - W16(0xFFDB), W16(0xFFCB), W16(0x0004), W16(0x0024), W16(0x0025), W16(0x0016), W16(0x0019), W16(0xFFEF), - W16(0xFFD2), W16(0xFFCA), W16(0xFFAD), W16(0xFFE6), W16(0xFFCB), W16(0x0005), W16(0x0060), W16(0x0032), - W16(0x002D), W16(0xFFE8), W16(0xFFC9), W16(0xFFF6), W16(0x0177), W16(0xFF8E), W16(0xFF7B), W16(0xFFCF), - W16(0xFFC6), W16(0x000A), W16(0xFFD3), W16(0xFFDB), W16(0xFFF4), W16(0xFFF3), W16(0x0034), W16(0xFFE2), - W16(0x0035), W16(0xFF72), W16(0x0019), W16(0xFFDE), W16(0x0013), W16(0x000A), W16(0x0003), W16(0x0017), - W16(0x002F), W16(0x0006), W16(0x0012), W16(0xFFFB), W16(0xFFF5), W16(0x000D), W16(0x0004), W16(0xFFF9), - W16(0x0026), W16(0x0005), W16(0xFFF2), W16(0xFF8B), W16(0xFFEE), W16(0x0010), W16(0xFFEB), W16(0xFFBC), - W16(0x002C), W16(0x0043), W16(0xFFA2), W16(0x0014), W16(0x002C), W16(0xFFF6), W16(0x0007), W16(0x0000), - W16(0x000F), W16(0xFFF8), W16(0xFFE7), W16(0xFFDB), W16(0xFFC9), W16(0xFFE2), W16(0xFFFB), W16(0x000B), - W16(0x001F), W16(0xFFF4), W16(0xFFFD), W16(0xFFDB), W16(0x0008), W16(0x0052), W16(0xFFBB), W16(0xFFC6), - W16(0x004A), W16(0xFFFB), W16(0x0049), W16(0xFFE0), W16(0x0059), W16(0xFFEA), W16(0xFFD3), W16(0xFFD0), - W16(0xFFD0), W16(0xFFD9), W16(0xFFEB), W16(0xFFD8), W16(0xFFF0), W16(0x0026), W16(0x0084), W16(0x00A7), - W16(0xFFE8), W16(0xFFCB), W16(0x001B), W16(0x0039), W16(0x0009), W16(0x0000), W16(0x0030), W16(0x0048), - W16(0x0046), W16(0x0061), W16(0x000B), W16(0xFFE0), W16(0xFFEB), W16(0xFFC4), W16(0xFFB2), W16(0xFFB2), - W16(0xFFDC), W16(0xFFEC), W16(0x0009), W16(0x0006), W16(0xFFFC), W16(0x0001), W16(0xFFFB), W16(0xFFF4), - W16(0x004E), W16(0x004A), W16(0x003E), W16(0xFFE0), W16(0xFFCC), W16(0x0035), W16(0x0024), W16(0x0024), - W16(0x0017), W16(0xFFB7), W16(0xFFED), W16(0x0048), W16(0xFFF9), W16(0x000B), W16(0xFFCF), W16(0xFFF1), - W16(0xFFF1), W16(0xFFD0), W16(0xFFBC), W16(0xFFAA), W16(0xFF97), W16(0xFFA4), W16(0xFFA7), W16(0xFFAD), - W16(0x001D), W16(0xFFD1), W16(0x0036), W16(0xFFD3), W16(0x0015), W16(0x0016), W16(0x0065), W16(0x000F), - W16(0x0006), W16(0xFFED), W16(0xFFD0), W16(0xFFB1), W16(0xFFDE), W16(0x0022), W16(0x001A), W16(0x0012), - W16(0xFFC0), W16(0xFFBB), W16(0xFFBD), W16(0xFFBB), W16(0xFFD0), W16(0xFFE3), W16(0xFFE2), W16(0xFFE5), - W16(0x001C), W16(0x003A), W16(0x0004), W16(0xFFCD), W16(0x003C), W16(0x004D), W16(0xFFD8), W16(0x0004), - W16(0x0040), W16(0xFFDC), W16(0xFFA3), W16(0xFFB7), W16(0x002F), W16(0x0017), W16(0xFFDC), W16(0xFFFA), - W16(0x0009), W16(0x0033), W16(0x001C), W16(0x0008), W16(0x0004), W16(0xFFE6), W16(0xFFB8), W16(0xFFA5), - W16(0xFFF0), W16(0xFFD4), W16(0x0042), W16(0xFFD4), W16(0xFFE8), W16(0x003F), W16(0x0064), W16(0xFFEB), - W16(0xFFA8), W16(0xFFE1), W16(0x0017), W16(0x000C), W16(0x0020), W16(0xFFB8), W16(0xFFD5), W16(0x000C), - W16(0x0025), W16(0x0051), W16(0x0016), W16(0xFFF3), W16(0xFFCF), W16(0xFFB7), W16(0xFFA6), W16(0xFF84), - W16(0xFFE6), W16(0xFFC8), W16(0x0024), W16(0xFFE1), W16(0x0044), W16(0xFF29), W16(0x0015), W16(0x0029), - W16(0x0004), W16(0x0023), W16(0xFFD5), W16(0xFFEA), W16(0x001B), W16(0x002B), W16(0xFFFB), W16(0x0011), - W16(0x001C), W16(0x0015), W16(0x0017), W16(0x000B), W16(0xFFF6), W16(0x0009), W16(0x0005), W16(0x0007), - W16(0x0060), W16(0xFFE5), W16(0x005F), W16(0xFFCF), W16(0xFFAF), W16(0xFFB2), W16(0xFFD3), W16(0x0002), - W16(0xFFFA), W16(0xFFD1), W16(0x001D), W16(0x001D), W16(0x0019), W16(0x0037), W16(0x002A), W16(0x0025), - W16(0x0027), W16(0x0029), W16(0x003C), W16(0x0049), W16(0x0035), W16(0x0027), W16(0xFFF9), W16(0xFFD0), - W16(0x0067), W16(0xFFDD), W16(0x000F), W16(0x0043), W16(0x0027), W16(0x002A), W16(0x0051), W16(0xFF79), - W16(0xFFDC), W16(0x002B), W16(0x0012), W16(0x0010), W16(0x001B), W16(0xFFFE), W16(0x0000), W16(0xFFCE), - W16(0xFFD6), W16(0x0002), W16(0x0028), W16(0x0030), W16(0xFFE4), W16(0xFFD8), W16(0xFFCD), W16(0xFFC8), - W16(0x003F), W16(0x0064), W16(0x000C), W16(0x0049), W16(0x0034), W16(0x0062), W16(0x006F), W16(0x004F), - W16(0x0004), W16(0xFFB8), W16(0x0006), W16(0xFFDD), W16(0xFFB8), W16(0xFFD3), W16(0xFFE4), W16(0xFFB6), - W16(0xFFE8), W16(0xFFFE), W16(0x0018), W16(0x004A), W16(0x0022), W16(0xFFFA), W16(0xFFF9), W16(0xFFFC), - W16(0xFFD7), W16(0x0066), W16(0xFFFD), W16(0x0013), W16(0x0023), W16(0xFFE5), W16(0xFFB5), W16(0xFFE5), - W16(0xFFFA), W16(0x000D), W16(0x0043), W16(0x0011), W16(0x003E), W16(0x0083), W16(0xFFF8), W16(0xFFC5), - W16(0xFF84), W16(0x000E), W16(0x0013), W16(0xFFBB), W16(0xFFA7), W16(0xFFB8), W16(0xFFDB), W16(0xFFDA), - W16(0xFFFD), W16(0x001C), W16(0xFFE9), W16(0x0005), W16(0x006D), W16(0xFFD2), W16(0x000C), W16(0x0002), - W16(0x003A), W16(0x002A), W16(0x0012), W16(0x0000), W16(0xFF71), W16(0xFFCA), W16(0xFFE6), W16(0x0009), - W16(0x0012), W16(0xFFEF), W16(0xFFFB), W16(0xFFF5), W16(0x000E), W16(0x001C), W16(0x0029), W16(0x0028), - W16(0x0036), W16(0x002B), W16(0xFFE3), W16(0x004D), W16(0xFF48), W16(0x0019), W16(0x0032), W16(0x0003), - W16(0x0066), W16(0x0003), W16(0xFFE0), W16(0xFFFC), W16(0x0004), W16(0xFFFA), W16(0x001A), W16(0x000B), - W16(0x0001), W16(0xFFFE), W16(0xFFFC), W16(0xFFE3), W16(0xFFE8), W16(0x0004), W16(0x0024), W16(0x0032), - W16(0x0021), W16(0x002B), W16(0xFF99), W16(0x000C), W16(0x0008), W16(0x004D), W16(0xFFD5), W16(0xFFC1), - W16(0xFFDE), W16(0xFFD3), W16(0x0001), W16(0xFFE1), W16(0xFFD3), W16(0x0018), W16(0x0044), W16(0x0024), - W16(0x0030), W16(0x0004), W16(0x000F), W16(0x0017), W16(0x002D), W16(0x0042), W16(0x004A), W16(0x0048), - W16(0xFFDF), W16(0x000D), W16(0x000A), W16(0xFFF4), W16(0xFFF0), W16(0xFFCC), W16(0xFFE2), W16(0xFFF4), - W16(0xFFF3), W16(0x0009), W16(0x0024), W16(0x0054), W16(0x0004), W16(0xFFEB), W16(0x0019), W16(0x0092), - W16(0xFF5F), W16(0xFFFD), W16(0x0022), W16(0x001E), W16(0xFFD5), W16(0xFF9D), W16(0xFFB6), W16(0x002E), - W16(0xFFC7), W16(0xFFCB), W16(0xFF9E), W16(0x0036), W16(0xFF8C), W16(0xFFCD), W16(0xFFDC), W16(0xFFF8), - W16(0x0010), W16(0x001B), W16(0x0019), W16(0x0004), W16(0x0035), W16(0x0018), W16(0xFFFD), W16(0x0010), - W16(0x0032), W16(0x004E), W16(0x0035), W16(0x0037), W16(0x000A), W16(0xFFF5), W16(0xFFE6), W16(0xFFE5), - W16(0x002D), W16(0xFFFA), W16(0xFFF7), W16(0xFFF0), W16(0xFFC6), W16(0xFFCA), W16(0xFFEA), W16(0x001E), - W16(0x0041), W16(0x002C), W16(0xFFF9), W16(0xFFEF), W16(0xFFBD), W16(0x00C2), W16(0x0012), W16(0xFF8E), - W16(0xFFF4), W16(0xFFF1), W16(0x004F), W16(0x0026), W16(0xFFF2), W16(0xFFD6), W16(0xFFAE), W16(0xFFA5), - W16(0xFFBD), W16(0xFFEB), W16(0x0056), W16(0xFFA9), W16(0xFF78), W16(0x0020), W16(0x005D), W16(0xFFE9), - W16(0xFFFA), W16(0x0054), W16(0x0026), W16(0xFFFB), W16(0xFFAC), W16(0xFFE8), W16(0xFFF6), W16(0xFFEC), - W16(0x003E), W16(0x0025), W16(0x0045), W16(0x0027), W16(0x0046), W16(0x0031), W16(0x001D), W16(0xFFF3), - W16(0xFFDD), W16(0x0016), W16(0xFFE8), W16(0x003B), W16(0x0004), W16(0x0053), W16(0x0024), W16(0xFFFA), - W16(0xFFDA), W16(0x0014), W16(0xFF6A), W16(0x0062), W16(0x0006), W16(0xFFE2), W16(0x0003), W16(0xFFF4), - W16(0xFFF2), W16(0xFFF7), W16(0xFFFC), W16(0x0012), W16(0x0019), W16(0x0019), W16(0x000D), W16(0x000E), - W16(0x0049), W16(0xFFF4), W16(0x0028), W16(0x000C), W16(0xFFC1), W16(0xFFDF), W16(0x0025), W16(0x003D), - W16(0xFF8A), W16(0x0048), W16(0x001A), W16(0xFFD5), W16(0x003B), W16(0x0055), W16(0x000C), W16(0xFFB4), - W16(0xFFEF), W16(0xFFFF), W16(0x0007), W16(0x0026), W16(0x001D), W16(0x0025), W16(0x0029), W16(0x0030), - W16(0x0059), W16(0x0057), W16(0xFFF3), W16(0xFFE7), W16(0xFFE6), W16(0xFF6D), W16(0x0080), W16(0xFFD4), - W16(0x002A), W16(0x0027), W16(0xFFE6), W16(0xFF9C), W16(0xFFC5), W16(0x0009), W16(0x0023), W16(0x004C), - W16(0x0048), W16(0x004F), W16(0xFFFB), W16(0xFFF3), W16(0x0016), W16(0x0001), W16(0xFFED), W16(0xFFEC), - W16(0xFF76), W16(0x0021), W16(0x009C), W16(0x0018), W16(0xFFD7), W16(0x002C), W16(0xFFD7), W16(0xFFF4), - W16(0x0025), W16(0xFFD1), W16(0xFFC9), W16(0xFFFB), W16(0xFFF5), W16(0x0005), W16(0x001D), W16(0x0035), - W16(0x002A), W16(0xFFEB), W16(0xFFE6), W16(0xFFD3), W16(0xFFDF), W16(0xFFFB), W16(0xFFFB), W16(0xFFEE), - W16(0x000B), W16(0x0024), W16(0x000C), W16(0x0024), W16(0xFFDB), W16(0xFFEC), W16(0xFFF5), W16(0x0009), - W16(0xFFFE), W16(0x0015), W16(0x0034), W16(0x0058), W16(0xFFF7), W16(0xFF52), W16(0x0058), W16(0x0023), - W16(0xFFD8), W16(0xFFD4), W16(0xFFE6), W16(0xFFFB), W16(0x0000), W16(0x0029), W16(0x003E), W16(0x0041), - W16(0xFFF2), W16(0xFFBA), W16(0xFFF7), W16(0x000A), W16(0x002A), W16(0x004C), W16(0xFFC4), W16(0x0042), - W16(0xFFAC), W16(0xFF6C), W16(0x003B), W16(0x0025), W16(0x0005), W16(0xFFE3), W16(0x000B), W16(0x000F), - W16(0x000C), W16(0x0028), W16(0x0021), W16(0x0015), W16(0xFFFF), W16(0xFFFE), W16(0x0006), W16(0x000B), - W16(0x0005), W16(0x006C), W16(0x0018), W16(0x0068), W16(0x0027), W16(0xFFA0), W16(0x0025), W16(0x0003), - W16(0xFFE8), W16(0xFFD7), W16(0xFFE4), W16(0x0026), W16(0x000D), W16(0xFFFF), W16(0x001D), W16(0x001F), - W16(0x0000), W16(0xFFEC), W16(0xFFF5), W16(0x0017), W16(0x0023), W16(0x003C), W16(0x0041), W16(0x0032), - W16(0xFFB5), W16(0x0068), W16(0xFFE8), W16(0x0006), W16(0xFFB3), W16(0x0002), W16(0xFFF4), W16(0x005C), - W16(0xFFE6), W16(0x0011), W16(0xFFE6), W16(0xFFCA), W16(0xFFA2), W16(0x0023), W16(0x004C), W16(0x0038), - W16(0x000B), W16(0x0011), W16(0x0015), W16(0xFFEA), W16(0xFFEC), W16(0xFFFB), W16(0x000A), W16(0x0003), - W16(0xFFFF), W16(0x0040), W16(0xFF79), W16(0xFFC5), W16(0x002C), W16(0xFFCB), W16(0x0007), W16(0xFFF1), - W16(0x0030), W16(0x003E), W16(0x001F), W16(0xFFE1), W16(0x0020), W16(0x0013), W16(0xFFCE), W16(0xFFD6), - W16(0xFFCC), W16(0xFFFF), W16(0x0027), W16(0x004B), W16(0x004B), W16(0x0045), W16(0x0038), W16(0x0036), - W16(0x0008), W16(0xFFF8), W16(0x0026), W16(0xFFFE), W16(0x000F), W16(0xFFD1), W16(0xFFE3), W16(0x0039), - W16(0xFFF3), W16(0xFFCB), W16(0xFFDE), W16(0x000E), W16(0x0102), W16(0xFFC2), W16(0xFF93), W16(0xFFF9), - W16(0x000C), W16(0xFFD7), W16(0xFFF4), W16(0x000F), W16(0xFFFD), W16(0x0022), W16(0x0020), W16(0x0027), - W16(0x002B), W16(0x0034), W16(0x0006), W16(0x0022), W16(0x0018), W16(0x0022), W16(0xFFE0), W16(0xFFFC), - W16(0x0037), W16(0x001E), W16(0x003F), W16(0xFFCC), W16(0xFFE7), W16(0xFFC3), W16(0xFFA8), W16(0xFFE4), - W16(0x0054), W16(0x006D), W16(0x0025), W16(0xFF9E), W16(0xFFBD), W16(0xFFCB), W16(0xFFE6), W16(0x001A), - W16(0xFFD6), W16(0x0080), W16(0x0074), W16(0xFFA3), W16(0x0034), W16(0xFFFA), W16(0x0010), W16(0xFFBF), - W16(0xFFC1), W16(0x0009), W16(0x0006), W16(0xFFE6), W16(0x0000), W16(0x0035), W16(0x003F), W16(0xFFF7), - W16(0xFFE3), W16(0xFFCF), W16(0x0000), W16(0x0019), W16(0x003B), W16(0x0043), W16(0x003F), W16(0x0047), - W16(0x0028), W16(0xFFCD), W16(0x000C), W16(0x0026), W16(0x0052), W16(0xFFF9), W16(0x003A), W16(0xFF99), - W16(0x0071), W16(0xFFAD), W16(0xFFFB), W16(0x001F), W16(0x000C), W16(0xFFF0), W16(0xFFDB), W16(0xFFFF), - W16(0xFFD5), W16(0x0023), W16(0x0022), W16(0x0032), W16(0x0048), W16(0x0025), W16(0xFFFE), W16(0xFFDB), - W16(0x009C), W16(0x0007), W16(0x0022), W16(0x0002), W16(0xFFB7), W16(0xFFAE), W16(0x0011), W16(0xFFE0), - W16(0x0000), W16(0x003B), W16(0x0027), W16(0x004D), W16(0x003A), W16(0xFFE2), W16(0xFFF6), W16(0x0006), - W16(0xFFE3), W16(0xFFCE), W16(0xFFCD), W16(0xFFD5), W16(0xFFFC), W16(0x0000), W16(0xFFF5), W16(0xFFF5), - W16(0x0040), W16(0xFFDE), W16(0x0050), W16(0x0018), W16(0xFFFB), W16(0x0041), W16(0xFF88), W16(0x000F), - W16(0xFFD7), W16(0x006B), W16(0x0038), W16(0xFFFC), W16(0xFFD8), W16(0xFFE9), W16(0xFFEC), W16(0x0007), - W16(0x0002), W16(0x000E), W16(0x0007), W16(0x0035), W16(0x002B), W16(0x0028), W16(0x0018), W16(0xFFFF), - W16(0xFFD6), W16(0x00B3), W16(0x0087), W16(0x001B), W16(0xFFBD), W16(0x001E), W16(0x0073), W16(0x0071), - W16(0x004B), W16(0x0052), W16(0x004D), W16(0xFFCE), W16(0xFFC2), W16(0xFFC6), W16(0xFFCB), W16(0xFF92), - W16(0xFFA3), W16(0xFF9F), W16(0xFFBA), W16(0x0011), W16(0xFFCF), W16(0xFFD7), W16(0x0018), W16(0x0072), - W16(0x0075), W16(0x0016), W16(0xFFD3), W16(0xFFA9), W16(0x0048), W16(0x001E), W16(0x0019), W16(0x000F), - W16(0xFF97), W16(0xFFF0), W16(0x0025), W16(0x003D), W16(0x0003), W16(0xFFE5), W16(0xFFE9), W16(0xFFEB), - W16(0xFFCD), W16(0xFFEA), W16(0xFFF0), W16(0x000E), W16(0x0018), W16(0x002A), W16(0x0030), W16(0x003C), - W16(0x0041), W16(0xFF90), W16(0x0039), W16(0x0015), W16(0x0006), W16(0x0039), W16(0x004B), W16(0x001E), - W16(0xFFFA), W16(0xFFC3), W16(0x0001), W16(0xFFBD), W16(0xFFF5), W16(0xFFC3), W16(0x0001), W16(0xFFFD), - W16(0x0026), W16(0xFFF4), W16(0x0006), W16(0x0069), W16(0x0083), W16(0x0080), W16(0x0077), W16(0x006E), - W16(0x00B3), W16(0x003E), W16(0x0007), W16(0x0037), W16(0x0025), W16(0xFFFD), W16(0xFFA5), W16(0xFFF6), - W16(0x0000), W16(0xFFF8), W16(0xFFED), W16(0x0003), W16(0x001A), W16(0xFFF7), W16(0x001B), W16(0x0030), - W16(0x0001), W16(0x002D), W16(0x0032), W16(0x0016), W16(0x000B), W16(0x0020), W16(0x0017), W16(0x0004), - W16(0xFFED), W16(0x004D), W16(0x0067), W16(0x0053), W16(0xFFD0), W16(0x0003), W16(0xFFC8), W16(0xFFC3), - W16(0xFFF4), W16(0x0001), W16(0x0032), W16(0x005D), W16(0xFFDF), W16(0x0027), W16(0xFFF2), W16(0xFFFB), - W16(0x002B), W16(0x0048), W16(0x002F), W16(0x0019), W16(0x001B), W16(0x0027), W16(0x001B), W16(0xFFFF), - W16(0xFFB9), W16(0xFFFC), W16(0x0003), W16(0x0054), W16(0x006D), W16(0x0003), W16(0xFFCF), W16(0x000B), - W16(0xFFD1), W16(0x000B), W16(0xFFD6), W16(0xFFDC), W16(0x000B), W16(0x0013), W16(0xFFCB), W16(0x0015), - W16(0x0029), W16(0x0046), W16(0x0084), W16(0x0071), W16(0x004F), W16(0x0045), W16(0x0040), W16(0x0038) -}; - -const Word16 cdk_37bits_5_fx[1536] = -{ - W16(0xFFF5), W16(0x0024), W16(0xFFA1), W16(0xFFDD), W16(0x0022), W16(0x004B), W16(0x003F), W16(0x0001), - W16(0x0040), W16(0xFFF4), W16(0xFFEE), W16(0xFFE4), W16(0xFFA4), W16(0xFFD7), W16(0xFFEA), W16(0xFFFD), - W16(0xFFEB), W16(0xFFDF), W16(0xFFDA), W16(0xFFFA), W16(0xFFFC), W16(0xFFF7), W16(0xFFFA), W16(0x0003), - W16(0x0015), W16(0xFFF0), W16(0xFFF2), W16(0xFFC0), W16(0x002F), W16(0x0002), W16(0xFFCA), W16(0xFFCD), - W16(0xFFF3), W16(0xFFFE), W16(0xFFCF), W16(0xFFF4), W16(0x0017), W16(0x0047), W16(0xFFDD), W16(0xFFFD), - W16(0x004D), W16(0xFF98), W16(0xFFBF), W16(0x0005), W16(0x0041), W16(0x0029), W16(0xFFF9), W16(0x0001), - W16(0xFFA6), W16(0xFFB8), W16(0xFFE4), W16(0x0009), W16(0xFFE0), W16(0x0031), W16(0x0005), W16(0xFFFD), - W16(0xFFAC), W16(0xFFF1), W16(0x000B), W16(0xFFFB), W16(0xFFDB), W16(0x000F), W16(0x0062), W16(0x0000), - W16(0xFFFE), W16(0x0018), W16(0x0000), W16(0xFFDB), W16(0xFFE6), W16(0xFFD1), W16(0xFFCF), W16(0xFFE5), - W16(0xFFE6), W16(0x0002), W16(0xFFAF), W16(0x003F), W16(0xFFF2), W16(0xFFD9), W16(0x0036), W16(0xFFF1), - W16(0x0048), W16(0xFFE7), W16(0xFFD8), W16(0x0002), W16(0x003D), W16(0x0002), W16(0x0005), W16(0x0006), - W16(0xFFBD), W16(0xFFCF), W16(0xFFCB), W16(0x0003), W16(0xFFFB), W16(0xFFF2), W16(0xFFD9), W16(0xFFDF), - W16(0xFFF8), W16(0xFFBF), W16(0x0001), W16(0xFFBB), W16(0xFFEA), W16(0xFFE6), W16(0xFFC8), W16(0x0028), - W16(0x0014), W16(0x0041), W16(0x0014), W16(0x0018), W16(0x0006), W16(0x0007), W16(0x0003), W16(0xFFF2), - W16(0xFFBF), W16(0xFFB0), W16(0xFFDA), W16(0xFFCC), W16(0xFFD4), W16(0xFFE4), W16(0xFFCD), W16(0xFFBE), - W16(0xFFA2), W16(0xFFA8), W16(0xFFF8), W16(0x0055), W16(0x002D), W16(0xFFEA), W16(0xFFE6), W16(0x0000), - W16(0x0005), W16(0xFFEF), W16(0x002D), W16(0x002F), W16(0x003D), W16(0xFFE0), W16(0xFFCF), W16(0xFFE2), - W16(0xFFE5), W16(0xFFEB), W16(0xFFEE), W16(0x0018), W16(0x000B), W16(0x0001), W16(0xFFF6), W16(0x0015), - W16(0x001F), W16(0xFFBA), W16(0xFFEA), W16(0x0002), W16(0xFFDC), W16(0xFFFB), W16(0xFFF0), W16(0xFFE6), - W16(0x005A), W16(0x0013), W16(0xFFF6), W16(0xFFCA), W16(0xFFF9), W16(0xFFB6), W16(0x0060), W16(0x0006), - W16(0x0012), W16(0x0046), W16(0x001D), W16(0x000C), W16(0x0022), W16(0x0022), W16(0x001B), W16(0x0012), - W16(0xFFB2), W16(0x0021), W16(0x000B), W16(0xFFDB), W16(0xFFE3), W16(0x0023), W16(0xFFCE), W16(0xFF8C), - W16(0x0058), W16(0xFFF7), W16(0x0026), W16(0xFFFD), W16(0x0016), W16(0x000D), W16(0x0008), W16(0xFFF0), - W16(0x0015), W16(0x001E), W16(0xFFF6), W16(0xFFF0), W16(0xFFD7), W16(0xFFD2), W16(0xFFD7), W16(0xFFEA), - W16(0xFFD8), W16(0x0006), W16(0xFF77), W16(0x0047), W16(0x0021), W16(0xFFEA), W16(0xFFC7), W16(0x0036), - W16(0xFFE1), W16(0x0032), W16(0xFFDD), W16(0xFFF5), W16(0xFFEA), W16(0xFFAD), W16(0x0028), W16(0x0034), - W16(0x001F), W16(0xFFEB), W16(0x0002), W16(0xFFD9), W16(0xFFEC), W16(0xFFE9), W16(0xFFEA), W16(0xFFE7), - W16(0x0021), W16(0xFFFC), W16(0xFFCD), W16(0xFFD7), W16(0x000D), W16(0xFFE4), W16(0x0025), W16(0xFFEC), - W16(0xFFF0), W16(0xFFF2), W16(0x002B), W16(0xFFE5), W16(0x0040), W16(0xFFB0), W16(0x001C), W16(0xFFE5), - W16(0x001C), W16(0xFFF5), W16(0xFFBD), W16(0xFFD3), W16(0xFFB4), W16(0xFFC8), W16(0xFFDC), W16(0x0000), - W16(0x0029), W16(0xFFFC), W16(0xFFE5), W16(0xFFE3), W16(0xFFAB), W16(0xFFDA), W16(0x0017), W16(0xFFD4), - W16(0xFFE6), W16(0xFFFF), W16(0x0032), W16(0xFFF7), W16(0xFFE3), W16(0x002C), W16(0x0042), W16(0x004A), - W16(0xFFE6), W16(0xFFEE), W16(0xFFE5), W16(0x0008), W16(0xFFDC), W16(0xFFEC), W16(0xFFF6), W16(0x000B), - W16(0xFFB6), W16(0x002A), W16(0x0031), W16(0x0011), W16(0x004F), W16(0xFFCA), W16(0xFFEA), W16(0x002A), - W16(0xFFF7), W16(0xFFEF), W16(0x000D), W16(0xFFBB), W16(0x0023), W16(0xFFCC), W16(0x0048), W16(0xFFF2), - W16(0xFFFD), W16(0xFFFD), W16(0xFFFC), W16(0x0001), W16(0x002D), W16(0x0004), W16(0xFFD0), W16(0xFFA2), - W16(0xFFD7), W16(0xFFE2), W16(0x0041), W16(0x000A), W16(0xFFE5), W16(0xFFEB), W16(0x002B), W16(0x001F), - W16(0x0043), W16(0xFFBE), W16(0x0044), W16(0xFFCF), W16(0xFFD9), W16(0x001C), W16(0x001E), W16(0xFFDE), - W16(0xFFE0), W16(0xFFD3), W16(0xFFD0), W16(0xFFE6), W16(0xFFF0), W16(0xFFF7), W16(0xFFED), W16(0x0002), - W16(0xFFD7), W16(0xFFF8), W16(0xFFEB), W16(0x0002), W16(0x0046), W16(0xFFEE), W16(0xFFF7), W16(0xFFD8), - W16(0x001B), W16(0xFFB8), W16(0xFFBA), W16(0xFFCE), W16(0x000B), W16(0x0042), W16(0x000C), W16(0x003A), - W16(0x000F), W16(0xFFFB), W16(0xFFF2), W16(0xFFE0), W16(0xFFBC), W16(0xFFBE), W16(0xFFF1), W16(0x0023), - W16(0xFFE4), W16(0xFFE6), W16(0xFFEA), W16(0xFFA8), W16(0xFFC1), W16(0x0016), W16(0x0054), W16(0x0016), - W16(0x001B), W16(0xFFFD), W16(0xFFE2), W16(0xFFD0), W16(0x0008), W16(0x002A), W16(0xFFE8), W16(0xFFC0), - W16(0x0019), W16(0xFFFE), W16(0x0021), W16(0x0013), W16(0x000B), W16(0xFFF8), W16(0xFFFE), W16(0x000C), - W16(0xFFA9), W16(0x0036), W16(0x0016), W16(0xFFE9), W16(0xFFAB), W16(0x000E), W16(0x0042), W16(0x0006), - W16(0xFFD0), W16(0x0009), W16(0xFFE3), W16(0xFFE0), W16(0x0025), W16(0x0015), W16(0x0011), W16(0x0027), - W16(0xFFF2), W16(0xFFD4), W16(0xFFB1), W16(0xFFC6), W16(0x001F), W16(0x0038), W16(0x002B), W16(0x0029), - W16(0xFFF0), W16(0x0025), W16(0xFFED), W16(0xFF89), W16(0x0014), W16(0x0034), W16(0xFFE5), W16(0xFFF0), - W16(0xFFE6), W16(0x000B), W16(0x0066), W16(0x0016), W16(0xFFF3), W16(0xFFCC), W16(0xFFD6), W16(0xFFEA), - W16(0xFFF8), W16(0x0007), W16(0x0015), W16(0x0013), W16(0x000A), W16(0x0020), W16(0x001A), W16(0x000E), - W16(0xFFD8), W16(0x000C), W16(0xFFF2), W16(0x0001), W16(0xFFD0), W16(0x0006), W16(0x0018), W16(0x0010), - W16(0xFFED), W16(0x0000), W16(0x001A), W16(0xFFFE), W16(0xFFFD), W16(0x003E), W16(0xFF67), W16(0x004E), - W16(0x000B), W16(0x0015), W16(0xFFEC), W16(0xFFE8), W16(0xFFDE), W16(0xFFF3), W16(0xFFFB), W16(0x0033), - W16(0xFFC6), W16(0xFFF1), W16(0xFFDC), W16(0xFFCA), W16(0x0016), W16(0xFFE7), W16(0x0029), W16(0xFFF6), - W16(0xFFF9), W16(0xFFE2), W16(0xFFCD), W16(0x002A), W16(0xFFE5), W16(0xFFC4), W16(0x0006), W16(0x0027), - W16(0x003B), W16(0x0035), W16(0x001C), W16(0x001C), W16(0x0015), W16(0x0025), W16(0x001F), W16(0x0031), - W16(0x0020), W16(0xFFFB), W16(0x0023), W16(0x0015), W16(0xFFF8), W16(0xFFFD), W16(0xFFEE), W16(0x003F), - W16(0x0055), W16(0x0006), W16(0x001B), W16(0xFFF7), W16(0xFFFB), W16(0xFFED), W16(0xFFE4), W16(0xFFEB), - W16(0xFFBA), W16(0x0029), W16(0x005B), W16(0x0063), W16(0xFFA2), W16(0xFFA6), W16(0xFF9D), W16(0xFFBD), - W16(0xFFCC), W16(0xFFB9), W16(0x0034), W16(0x0011), W16(0x000E), W16(0xFFFD), W16(0x0048), W16(0xFFE9), - W16(0xFFD8), W16(0x0071), W16(0xFFAB), W16(0x0013), W16(0xFFEC), W16(0xFFD2), W16(0xFFD3), W16(0xFFF8), - W16(0x0034), W16(0xFFFE), W16(0xFFD9), W16(0xFFCC), W16(0xFFE6), W16(0xFFF1), W16(0xFFF1), W16(0x0004), - W16(0xFFFD), W16(0x0000), W16(0xFFCA), W16(0xFF9C), W16(0xFFE5), W16(0xFFFD), W16(0xFFF9), W16(0x0025), - W16(0x0023), W16(0xFFBA), W16(0xFFDC), W16(0x003F), W16(0x0039), W16(0xFFE2), W16(0x0027), W16(0xFFEA), - W16(0xFFDC), W16(0x0035), W16(0x0008), W16(0xFFF6), W16(0x0012), W16(0xFFE2), W16(0xFFAD), W16(0xFF94), - W16(0x002B), W16(0xFFE5), W16(0x0015), W16(0x001B), W16(0xFF94), W16(0xFFE8), W16(0xFFCE), W16(0x0023), - W16(0x002A), W16(0xFFF6), W16(0x0023), W16(0xFFD7), W16(0x0025), W16(0x0004), W16(0xFFE2), W16(0x0020), - W16(0x004F), W16(0x0026), W16(0xFFC5), W16(0xFFCE), W16(0xFFF7), W16(0x0012), W16(0x0018), W16(0x0019), - W16(0xFFFE), W16(0xFFCA), W16(0xFFFC), W16(0x0002), W16(0x0006), W16(0x002A), W16(0xFF55), W16(0x0006), - W16(0xFFEE), W16(0x0017), W16(0xFFE3), W16(0x0005), W16(0x0036), W16(0x003E), W16(0x000C), W16(0x000A), - W16(0xFFFD), W16(0x0017), W16(0x0022), W16(0x0013), W16(0xFFFF), W16(0xFFF6), W16(0xFFFE), W16(0x001A), - W16(0x0009), W16(0xFFEB), W16(0xFFE5), W16(0x0000), W16(0x0032), W16(0x0058), W16(0x0009), W16(0x0039), - W16(0xFFD0), W16(0xFFF7), W16(0xFFD8), W16(0xFFF0), W16(0x0014), W16(0xFFDC), W16(0xFFE1), W16(0x0009), - W16(0xFFCB), W16(0xFFD9), W16(0x0002), W16(0x000C), W16(0xFFF9), W16(0x000F), W16(0x003F), W16(0x0062), - W16(0x0013), W16(0x002F), W16(0x0028), W16(0xFFE9), W16(0x0030), W16(0x000D), W16(0xFFA7), W16(0x0000), - W16(0x000A), W16(0xFFED), W16(0xFFEB), W16(0x003F), W16(0xFFEE), W16(0xFFEB), W16(0x0014), W16(0x0029), - W16(0xFFE5), W16(0xFFF0), W16(0xFFB0), W16(0xFFCB), W16(0xFFD5), W16(0x0014), W16(0x0034), W16(0x003B), - W16(0xFFE9), W16(0x0059), W16(0xFFBC), W16(0xFFCD), W16(0x000C), W16(0xFFE6), W16(0x001F), W16(0x0013), - W16(0xFFE5), W16(0x0030), W16(0xFFFD), W16(0x0025), W16(0xFFD9), W16(0x0011), W16(0x002C), W16(0xFFAC), - W16(0xFFE2), W16(0x0014), W16(0xFFF0), W16(0xFFDA), W16(0xFFED), W16(0xFFFE), W16(0xFFFC), W16(0x0006), - W16(0xFFDE), W16(0xFFF0), W16(0xFFFB), W16(0x0001), W16(0x001D), W16(0xFFB6), W16(0xFFEF), W16(0x00CD), - W16(0xFF91), W16(0xFFD0), W16(0xFFCD), W16(0x0017), W16(0x0006), W16(0x0026), W16(0x0011), W16(0xFFF3), - W16(0xFFFD), W16(0x0005), W16(0xFFD7), W16(0xFFF7), W16(0xFFE7), W16(0xFFC3), W16(0xFFDB), W16(0xFFD3), - W16(0x0003), W16(0xFFE7), W16(0xFFD9), W16(0x0010), W16(0x0049), W16(0xFFF3), W16(0xFFFD), W16(0xFFB1), - W16(0x000B), W16(0x005E), W16(0x0030), W16(0xFF9D), W16(0xFFE3), W16(0x000F), W16(0xFFFB), W16(0xFFF3), - W16(0x0001), W16(0xFFFC), W16(0xFFF4), W16(0xFFEC), W16(0xFFEE), W16(0xFFF5), W16(0xFFEB), W16(0xFFFE), - W16(0x0049), W16(0x001E), W16(0x0011), W16(0xFFDF), W16(0xFFD5), W16(0x002C), W16(0xFFFD), W16(0xFFF8), - W16(0x0007), W16(0xFFBC), W16(0xFFD4), W16(0x0013), W16(0x0045), W16(0xFFDE), W16(0xFFFE), W16(0x0049), - W16(0xFFF6), W16(0xFFDC), W16(0xFFE6), W16(0x0000), W16(0xFFFA), W16(0xFFEF), W16(0xFFE3), W16(0xFFF1), - W16(0xFFE0), W16(0x000A), W16(0x0019), W16(0x0006), W16(0xFFF3), W16(0xFFFA), W16(0x000B), W16(0x002D), - W16(0x000E), W16(0x002A), W16(0x0015), W16(0xFFFC), W16(0xFFE9), W16(0xFFC0), W16(0x0034), W16(0xFFDF), - W16(0xFFD7), W16(0xFFF3), W16(0x0017), W16(0x000F), W16(0xFFAC), W16(0xFFEF), W16(0x0101), W16(0xFF60), - W16(0xFFE0), W16(0xFFBD), W16(0x0040), W16(0xFFEB), W16(0xFFFF), W16(0xFFE2), W16(0xFFD5), W16(0xFFE1), - W16(0xFFFA), W16(0xFFF7), W16(0xFFF4), W16(0x0003), W16(0xFFFE), W16(0xFFCA), W16(0x0004), W16(0x0097), - W16(0x001E), W16(0xFF9B), W16(0xFFE6), W16(0x0093), W16(0x0033), W16(0x006E), W16(0xFFFB), W16(0xFFBF), - W16(0x0036), W16(0xFFFE), W16(0x002B), W16(0x0004), W16(0x001A), W16(0x005D), W16(0x0027), W16(0xFFF2), - W16(0x0013), W16(0x0013), W16(0x000F), W16(0x0000), W16(0xFFD8), W16(0xFFB8), W16(0xFFD8), W16(0x0002), - W16(0xFFD2), W16(0x0004), W16(0xFFF1), W16(0xFFD9), W16(0x002C), W16(0x006B), W16(0x0016), W16(0xFF7E), - W16(0xFFFE), W16(0xFFFE), W16(0xFFEB), W16(0x000B), W16(0x000F), W16(0x006C), W16(0x000A), W16(0xFF8A), - W16(0xFFBB), W16(0xFFF3), W16(0xFFE8), W16(0xFFDF), W16(0x0055), W16(0x0037), W16(0xFFE0), W16(0xFFE8), - W16(0x0028), W16(0x000A), W16(0x0005), W16(0xFFDF), W16(0x001B), W16(0x0016), W16(0x0015), W16(0x001D), - W16(0xFFFC), W16(0xFFBA), W16(0x0016), W16(0xFFE0), W16(0x001E), W16(0xFFD4), W16(0xFFF6), W16(0xFFE0), - W16(0xFFA2), W16(0xFFF7), W16(0x0018), W16(0x0012), W16(0x0056), W16(0x0032), W16(0x001A), W16(0xFFEB), - W16(0xFFE7), W16(0x0021), W16(0xFFFE), W16(0x001F), W16(0x000E), W16(0x0016), W16(0x0007), W16(0x0011), - W16(0x0008), W16(0xFFF2), W16(0xFFC4), W16(0x0039), W16(0x0003), W16(0xFFFB), W16(0x0008), W16(0xFF8E), - W16(0x0027), W16(0xFFEA), W16(0x0021), W16(0x0041), W16(0xFFF2), W16(0xFFE4), W16(0x0018), W16(0x0005), - W16(0x0006), W16(0x000E), W16(0xFFEB), W16(0xFFDA), W16(0x0009), W16(0x0019), W16(0x002C), W16(0x004F), - W16(0x0077), W16(0xFFEC), W16(0xFFE6), W16(0xFFF4), W16(0xFFF6), W16(0x000D), W16(0x001C), W16(0xFFE2), - W16(0x0030), W16(0x0035), W16(0x0004), W16(0xFFF5), W16(0x001F), W16(0x003C), W16(0xFFD0), W16(0xFFC4), - W16(0xFFB1), W16(0x0000), W16(0xFFF9), W16(0xFFF5), W16(0xFFEB), W16(0xFFF8), W16(0xFFF8), W16(0xFFFB), - W16(0x0023), W16(0xFF64), W16(0x002A), W16(0x0001), W16(0x0004), W16(0x0030), W16(0x0004), W16(0xFFD9), - W16(0x001B), W16(0xFFDF), W16(0xFFF9), W16(0x0022), W16(0x0011), W16(0xFFE4), W16(0xFFE1), W16(0xFFE2), - W16(0x0023), W16(0x0014), W16(0x0025), W16(0xFFF3), W16(0xFFEA), W16(0xFFEB), W16(0xFFED), W16(0xFFF5), - W16(0x004C), W16(0xFFDE), W16(0xFFE9), W16(0x0024), W16(0x0073), W16(0xFFEB), W16(0xFFCA), W16(0x0018), - W16(0x0024), W16(0xFFE8), W16(0x0022), W16(0xFFD7), W16(0xFFD6), W16(0xFFFE), W16(0xFFE4), W16(0xFFFB), - W16(0x0009), W16(0xFFDF), W16(0x000D), W16(0x0008), W16(0x0012), W16(0x000C), W16(0x0012), W16(0x0019), - W16(0xFFC4), W16(0x005D), W16(0x001A), W16(0x004E), W16(0x0030), W16(0x0028), W16(0xFFFA), W16(0xFFE7), - W16(0xFFD3), W16(0xFFE7), W16(0x001A), W16(0x000C), W16(0xFFCB), W16(0xFFD8), W16(0x0013), W16(0x0011), - W16(0x001F), W16(0x003A), W16(0x0019), W16(0x0006), W16(0xFFF2), W16(0xFFFE), W16(0x000C), W16(0x0019), - W16(0xFFFF), W16(0x0027), W16(0xFF96), W16(0x0023), W16(0xFFFA), W16(0x002D), W16(0xFFC5), W16(0x0037), - W16(0x000B), W16(0xFFD5), W16(0x0027), W16(0xFFF7), W16(0x0007), W16(0x001C), W16(0xFFF4), W16(0xFFDB), - W16(0xFFEE), W16(0x0015), W16(0xFFF9), W16(0xFFF6), W16(0xFFE9), W16(0xFFE9), W16(0xFFFF), W16(0x0027), - W16(0x004C), W16(0x0038), W16(0xFFBB), W16(0xFFF4), W16(0x000E), W16(0xFFA5), W16(0xFFD7), W16(0xFFF3), - W16(0xFFE5), W16(0xFFFA), W16(0x0015), W16(0x0046), W16(0x0023), W16(0xFFFA), W16(0xFFED), W16(0x0010), - W16(0x0030), W16(0x0025), W16(0x003E), W16(0x0006), W16(0xFFD6), W16(0xFFDE), W16(0xFFEE), W16(0x0006), - W16(0x0002), W16(0x001D), W16(0xFFC3), W16(0x000D), W16(0xFFFD), W16(0x0008), W16(0x0053), W16(0xFFD9), - W16(0xFFA1), W16(0xFF9C), W16(0x004A), W16(0x0032), W16(0xFFB5), W16(0x0050), W16(0xFFF1), W16(0x000E), - W16(0x0013), W16(0xFFD6), W16(0xFFFA), W16(0xFFF4), W16(0xFFFE), W16(0xFFE9), W16(0xFFCD), W16(0xFFC4), - W16(0x002E), W16(0x001B), W16(0x0026), W16(0xFFC8), W16(0x001D), W16(0xFFA0), W16(0x0026), W16(0x0031), - W16(0x005B), W16(0x0017), W16(0xFFD8), W16(0x0004), W16(0x0003), W16(0xFFD6), W16(0xFFF9), W16(0xFFD2), - W16(0xFFFA), W16(0xFFEF), W16(0xFFF5), W16(0xFFF7), W16(0xFFEF), W16(0x000F), W16(0x0036), W16(0x004E), - W16(0xFFCD), W16(0x0006), W16(0x001E), W16(0x0007), W16(0x0024), W16(0x0000), W16(0x0012), W16(0x000B), - W16(0x0031), W16(0xFFFA), W16(0x0004), W16(0x004F), W16(0xFFB3), W16(0x0017), W16(0xFFCE), W16(0xFFDA), - W16(0xFFD0), W16(0xFFE6), W16(0xFFE6), W16(0x0039), W16(0x0044), W16(0x003F), W16(0x0024), W16(0x0014), - W16(0xFFF4), W16(0xFFE0), W16(0x0002), W16(0x0020), W16(0xFFD5), W16(0xFFE0), W16(0xFFF9), W16(0x0018), - W16(0x004A), W16(0x0032), W16(0xFF9D), W16(0x0010), W16(0xFFBA), W16(0x0019), W16(0x000B), W16(0x001F), - W16(0x0013), W16(0xFFFE), W16(0x0016), W16(0xFFFA), W16(0xFFF2), W16(0xFFED), W16(0xFFEA), W16(0xFFFD), - W16(0x0005), W16(0xFFE1), W16(0x0003), W16(0x0041), W16(0x000E), W16(0xFFF3), W16(0x0050), W16(0x002C), - W16(0xFFDC), W16(0xFFEE), W16(0x0002), W16(0xFF95), W16(0x001E), W16(0x0006), W16(0x0000), W16(0xFFFD), - W16(0x0002), W16(0x000F), W16(0x002E), W16(0x0041), W16(0x0008), W16(0xFFF4), W16(0xFFE4), W16(0xFFEF), - W16(0xFFC3), W16(0x001F), W16(0x0020), W16(0xFFFD), W16(0xFFEA), W16(0x0021), W16(0xFFEA), W16(0xFFEF), - W16(0xFFF4), W16(0x004B), W16(0x000F), W16(0xFFA9), W16(0x0058), W16(0xFFC5), W16(0xFFD5), W16(0x004C), - W16(0xFFE4), W16(0x003A), W16(0x0016), W16(0x000C), W16(0xFFED), W16(0x001D), W16(0x001E), W16(0x0017), - W16(0x0015), W16(0x007A), W16(0x001F), W16(0xFFDC), W16(0xFFEB), W16(0x0025), W16(0x0000), W16(0x000D), - W16(0x0031), W16(0x0001), W16(0xFFF5), W16(0xFFC2), W16(0xFFDF), W16(0xFFF7), W16(0xFFF7), W16(0x0004), - W16(0x002B), W16(0x0029), W16(0x0028), W16(0x0025), W16(0x001B), W16(0x0010), W16(0x000C), W16(0x0011), - W16(0xFFEE), W16(0x0062), W16(0x003D), W16(0x0058), W16(0x0031), W16(0xFFF5), W16(0x000E), W16(0x000D), - W16(0x000D), W16(0x0005), W16(0xFFEC), W16(0xFFF2), W16(0x0020), W16(0x001D), W16(0xFFB1), W16(0xFFEC), - W16(0xFFF4), W16(0xFFEB), W16(0xFFE7), W16(0xFFD8), W16(0xFFF3), W16(0xFFF0), W16(0xFFE2), W16(0xFFDC), - W16(0x0019), W16(0xFFBF), W16(0xFFF8), W16(0x0010), W16(0xFFF3), W16(0xFFE0), W16(0x0028), W16(0x0034), - W16(0xFFE6), W16(0x0016), W16(0x004D), W16(0x0000), W16(0xFFC6), W16(0xFFD8), W16(0xFFC6), W16(0x002E), - W16(0xFFF6), W16(0x0068), W16(0x002D), W16(0xFFE4), W16(0x0009), W16(0x002E), W16(0x0045), W16(0x0059), - W16(0x0013), W16(0x0009), W16(0x0031), W16(0x0012), W16(0x0041), W16(0x0003), W16(0x0009), W16(0xFFF9), - W16(0x0001), W16(0x0005), W16(0x0010), W16(0x0006), W16(0xFFFA), W16(0x0021), W16(0x001A), W16(0xFFE0), - W16(0xFF87), W16(0xFFC2), W16(0x00FF), W16(0xFFF1), W16(0x000C), W16(0x0020), W16(0xFFF1), W16(0x0033), - W16(0x002E), W16(0x0007), W16(0x0048), W16(0xFFA8), W16(0xFFFF), W16(0x003C), W16(0xFFE9), W16(0xFFCA), - W16(0xFFE5), W16(0x0023), W16(0xFFE6), W16(0x0048), W16(0xFFA2), W16(0x002F), W16(0x0011), W16(0xFFF0), - W16(0x0009), W16(0x0016), W16(0x002B), W16(0x002A), W16(0xFFCE), W16(0xFFDF), W16(0xFFC7), W16(0xFFC7), - W16(0xFFE0), W16(0x003A), W16(0x0040), W16(0x0013), W16(0xFF97), W16(0x000B), W16(0x0020), W16(0x001A), - W16(0xFFF6), W16(0xFFD8), W16(0x000C), W16(0x0064), W16(0x0024), W16(0xFFF9), W16(0xFFE1), W16(0xFFE1), - W16(0x0008), W16(0xFFFF), W16(0x0013), W16(0x001C), W16(0x0000), W16(0xFFEA), W16(0xFFEE), W16(0x0007), - W16(0x0042), W16(0xFFE7), W16(0xFFCB), W16(0x0004), W16(0xFFAD), W16(0x0010), W16(0x0001), W16(0x0019), - W16(0xFFD0), W16(0x0052), W16(0x000E), W16(0x000C), W16(0xFFF6), W16(0x0011), W16(0xFFE9), W16(0xFFE9), - W16(0x0013), W16(0xFFE4), W16(0x0014), W16(0x003B), W16(0x0033), W16(0x0034), W16(0x0030), W16(0x0030), - W16(0xFFD0), W16(0x002C), W16(0x0005), W16(0xFFF2), W16(0xFFF0), W16(0xFF90), W16(0xFFB8), W16(0xFFF6), - W16(0x0013), W16(0x001A), W16(0x0026), W16(0xFFFC), W16(0x000E), W16(0x0037), W16(0x0021), W16(0x000E), - W16(0x000E), W16(0x0010), W16(0x0029), W16(0x0020), W16(0x0025), W16(0x0026), W16(0x0033), W16(0x0038), - W16(0x0016), W16(0x000D), W16(0xFFD6), W16(0x002B), W16(0x000D), W16(0x0029), W16(0xFFF8), W16(0x000C), - W16(0x0027), W16(0x0008), W16(0xFFB4), W16(0x0012), W16(0x0016), W16(0xFFCF), W16(0xFFEF), W16(0xFFD4), - W16(0x0029), W16(0x0026), W16(0xFFF5), W16(0x00A4), W16(0x009C), W16(0xFE71), W16(0x003B), W16(0xFF88), - W16(0x0016), W16(0x000A), W16(0x0021), W16(0x0085), W16(0xFFE0), W16(0x0022), W16(0xFFB1), W16(0x000D), - W16(0xFFE9), W16(0x0000), W16(0x0017), W16(0x001A), W16(0x000A), W16(0x000F), W16(0x001A), W16(0xFFF8), - W16(0xFFFA), W16(0xFFCA), W16(0xFFCB), W16(0x0000), W16(0xFFE7), W16(0xFFDF), W16(0xFFD0), W16(0xFFE5), - W16(0x0052), W16(0x0028), W16(0xFFCD), W16(0xFFE0), W16(0x000D), W16(0xFFD1), W16(0x0016), W16(0x001F), - W16(0xFFE1), W16(0xFFDC), W16(0xFFF4), W16(0xFFD9), W16(0xFFE3), W16(0x0048), W16(0x001D), W16(0x0004), - W16(0x0017), W16(0x0009), W16(0xFFAA), W16(0xFFAD), W16(0x0093), W16(0x005D), W16(0x0023), W16(0x008B), - W16(0x0035), W16(0x001A), W16(0x008C), W16(0xFFD3), W16(0x001B), W16(0xFFF8), W16(0x000A), W16(0x001D), - W16(0xFFA4), W16(0xFFFC), W16(0x0037), W16(0xFFFA), W16(0xFFE3), W16(0xFFDA), W16(0x0008), W16(0x0011), - W16(0x0020), W16(0xFFEE), W16(0xFFF0), W16(0xFFD9), W16(0xFFEE), W16(0xFFF2), W16(0xFFE8), W16(0x0010), - W16(0x0043), W16(0x0017), W16(0x0077), W16(0x0038), W16(0xFFF2), W16(0xFFF0), W16(0xFFEC), W16(0xFFC5), - W16(0x0026), W16(0x0007), W16(0x0022), W16(0xFFEB), W16(0xFFFA), W16(0x0012), W16(0x000F), W16(0x0016), - W16(0x0002), W16(0xFFE9), W16(0xFFF4), W16(0x0015), W16(0x0008), W16(0x001D), W16(0x003B), W16(0x0044), - W16(0x0025), W16(0xFFEB), W16(0x0026), W16(0x002A), W16(0xFFDB), W16(0x0000), W16(0x0047), W16(0x0005), - W16(0x000E), W16(0xFFBA), W16(0xFF9B), W16(0x000E), W16(0x0007), W16(0x0052), W16(0x003F), W16(0x0004), - W16(0xFFCE), W16(0x0041), W16(0x002C), W16(0xFFF5), W16(0xFFDC), W16(0x000E), W16(0x0023), W16(0x002A), - W16(0xFFE0), W16(0xFFFA), W16(0x0013), W16(0x000F), W16(0x0001), W16(0xFFF3), W16(0x0019), W16(0x0003), - W16(0xFFDD), W16(0x0010), W16(0x0004), W16(0x0017), W16(0xFFBA), W16(0x002B), W16(0xFFF7), W16(0xFF9E), - W16(0x006E), W16(0xFFF2), W16(0x0013), W16(0xFFAC), W16(0x0037), W16(0x012C), W16(0xFFBB), W16(0xFFB8), - W16(0x002C), W16(0x001F), W16(0x0017), W16(0xFFFE), W16(0xFFCE), W16(0xFFF3), W16(0x001E), W16(0xFFC7), - W16(0xFFE3), W16(0x0038), W16(0xFFD2), W16(0x0010), W16(0x0025), W16(0xFFD2), W16(0x0035), W16(0x0012), - W16(0x001F), W16(0x0028), W16(0x0033), W16(0x003A), W16(0x0021), W16(0xFFE2), W16(0xFFB8), W16(0xFFAF) -}; - -const Word16 cdk_37bits_6_fx[1536] = -{ - W16(0x0003), W16(0xFFDA), W16(0x0007), W16(0x0012), W16(0x0022), W16(0xFFFC), W16(0x001A), W16(0x0047), - W16(0x001D), W16(0x0029), W16(0x0015), W16(0xFFF4), W16(0xFFE2), W16(0xFFC7), W16(0xFFD7), W16(0xFFDC), - W16(0xFFD6), W16(0xFFE8), W16(0xFFE9), W16(0xFFC5), W16(0xFFFA), W16(0x0002), W16(0x0019), W16(0x0032), - W16(0xFF9B), W16(0xFFEF), W16(0xFFDC), W16(0xFFDE), W16(0xFFF3), W16(0x0024), W16(0xFFE6), W16(0xFFCA), - W16(0xFFD9), W16(0x000B), W16(0x0009), W16(0x002B), W16(0xFFFB), W16(0x000A), W16(0xFFE1), W16(0xFFF7), - W16(0x0045), W16(0xFFE3), W16(0x0009), W16(0xFFF9), W16(0xFFD4), W16(0xFFDE), W16(0x001C), W16(0x0027), - W16(0xFFCC), W16(0xFFBD), W16(0xFFF8), W16(0xFFB6), W16(0x0017), W16(0x0015), W16(0x002B), W16(0xFFDC), - W16(0x0026), W16(0x001E), W16(0xFFCC), W16(0xFFF1), W16(0xFFD5), W16(0xFFF5), W16(0x0009), W16(0x000F), - W16(0xFFEA), W16(0xFFD5), W16(0xFFFD), W16(0x0018), W16(0xFFFF), W16(0xFFE9), W16(0xFFEA), W16(0x0000), - W16(0x000C), W16(0x002C), W16(0xFFCF), W16(0x0042), W16(0x001C), W16(0xFFF8), W16(0x0001), W16(0xFFDF), - W16(0xFFEE), W16(0x0014), W16(0x0030), W16(0xFFC4), W16(0x001C), W16(0x0013), W16(0xFFED), W16(0xFFF6), - W16(0x0003), W16(0xFFBD), W16(0xFFC7), W16(0xFFF4), W16(0x000A), W16(0xFFF4), W16(0xFFF5), W16(0xFFE4), - W16(0xFFF2), W16(0xFFD3), W16(0xFFE6), W16(0xFFEF), W16(0x0003), W16(0xFFE0), W16(0xFFCD), W16(0xFFF2), - W16(0x002D), W16(0xFFE1), W16(0x0061), W16(0xFFFF), W16(0xFFD0), W16(0xFFEB), W16(0xFFEA), W16(0x0024), - W16(0x0027), W16(0x000A), W16(0xFFE5), W16(0xFFCA), W16(0xFFE6), W16(0xFFEF), W16(0xFFF9), W16(0xFFE6), - W16(0xFFE1), W16(0x0000), W16(0xFFEB), W16(0x0011), W16(0xFFFA), W16(0xFFF0), W16(0x0024), W16(0x0018), - W16(0x0003), W16(0xFFE4), W16(0xFFF2), W16(0xFFF5), W16(0xFFEF), W16(0xFFE8), W16(0x000D), W16(0x0044), - W16(0xFFE4), W16(0xFFF9), W16(0xFFC7), W16(0xFFF8), W16(0xFF82), W16(0x00CE), W16(0xFFCF), W16(0x0030), - W16(0x0018), W16(0xFFAE), W16(0x0005), W16(0xFFC6), W16(0xFFBA), W16(0x0005), W16(0x0021), W16(0x000B), - W16(0xFFF5), W16(0xFFF4), W16(0x0005), W16(0x002F), W16(0xFFF4), W16(0xFFFB), W16(0xFFFE), W16(0x0004), - W16(0x0007), W16(0x0011), W16(0xFFF5), W16(0xFFE5), W16(0x0003), W16(0x001C), W16(0x003F), W16(0x0042), - W16(0xFFB1), W16(0xFFD1), W16(0x0012), W16(0xFFFB), W16(0x001F), W16(0xFFE4), W16(0x0016), W16(0xFFFF), - W16(0x0001), W16(0xFFFC), W16(0xFFF3), W16(0xFFB8), W16(0x001C), W16(0x0027), W16(0xFFFF), W16(0xFFEF), - W16(0x000F), W16(0x001C), W16(0x001B), W16(0xFFDA), W16(0x0008), W16(0x0003), W16(0x0018), W16(0x002B), - W16(0x0013), W16(0x0000), W16(0x0005), W16(0xFFF6), W16(0xFFF0), W16(0xFF94), W16(0x003D), W16(0x0003), - W16(0x0006), W16(0xFFFE), W16(0xFFFE), W16(0x0023), W16(0x0010), W16(0x000E), W16(0x0022), W16(0xFFDF), - W16(0xFFF7), W16(0xFFD6), W16(0xFFF5), W16(0xFFD2), W16(0xFFCA), W16(0xFFBC), W16(0xFFD7), W16(0xFFF2), - W16(0xFFD3), W16(0xFFF1), W16(0xFFB4), W16(0xFFEE), W16(0xFFCA), W16(0xFFCD), W16(0x000E), W16(0x0046), - W16(0x0001), W16(0xFFEB), W16(0x002D), W16(0x0005), W16(0x0001), W16(0x0011), W16(0xFFFC), W16(0x0007), - W16(0xFFE3), W16(0xFFDE), W16(0xFFF4), W16(0x0022), W16(0x0020), W16(0x000C), W16(0xFFF7), W16(0xFFE6), - W16(0xFFFA), W16(0xFFD0), W16(0x0004), W16(0x0004), W16(0xFFD6), W16(0x0004), W16(0xFFD3), W16(0x0012), - W16(0x001C), W16(0xFFA6), W16(0xFFCE), W16(0x0026), W16(0xFFF3), W16(0x004B), W16(0x002F), W16(0xFFFE), - W16(0x0021), W16(0xFFEE), W16(0xFFE8), W16(0x0008), W16(0x000E), W16(0x0002), W16(0x000C), W16(0xFFFC), - W16(0xFFDF), W16(0x003D), W16(0x0008), W16(0xFFB1), W16(0x0025), W16(0x0009), W16(0x001D), W16(0x0013), - W16(0xFFE9), W16(0xFFC5), W16(0xFFEF), W16(0x0006), W16(0x002C), W16(0x0018), W16(0x0014), W16(0xFFD7), - W16(0xFFD0), W16(0xFFDB), W16(0xFFEB), W16(0x0008), W16(0xFFE9), W16(0xFFF1), W16(0x0009), W16(0x0012), - W16(0x001A), W16(0xFFF4), W16(0xFFD3), W16(0xFFFB), W16(0xFFDF), W16(0x001B), W16(0x0004), W16(0xFFFD), - W16(0x0037), W16(0xFFE2), W16(0xFFF0), W16(0x0014), W16(0xFFF4), W16(0xFFF2), W16(0xFFF5), W16(0x000E), - W16(0xFFFF), W16(0xFFC4), W16(0x00C0), W16(0xFFAA), W16(0xFFBD), W16(0x0002), W16(0x001A), W16(0xFFCE), - W16(0x000E), W16(0xFFDE), W16(0xFF98), W16(0x0022), W16(0x0022), W16(0xFFFA), W16(0x0034), W16(0xFFF5), - W16(0x0013), W16(0xFFDB), W16(0xFFCF), W16(0x0003), W16(0xFFF3), W16(0xFFFB), W16(0x000C), W16(0xFFCE), - W16(0x0034), W16(0x0026), W16(0x0009), W16(0xFFF8), W16(0xFFE9), W16(0xFFE6), W16(0xFFF2), W16(0xFFFA), - W16(0xFFF6), W16(0x0002), W16(0xFFD7), W16(0x001A), W16(0x0007), W16(0x0004), W16(0xFFDC), W16(0xFFF3), - W16(0x0020), W16(0x0017), W16(0xFFD8), W16(0xFFF5), W16(0xFFC0), W16(0x006D), W16(0xFFDC), W16(0x0033), - W16(0xFFE6), W16(0xFFE3), W16(0xFFE1), W16(0xFFE2), W16(0x000C), W16(0x0019), W16(0x0026), W16(0x0023), - W16(0xFFDD), W16(0x0032), W16(0xFFFB), W16(0x0003), W16(0xFFD2), W16(0xFFDB), W16(0x001C), W16(0xFFF2), - W16(0xFFFD), W16(0x003B), W16(0xFFED), W16(0xFFF7), W16(0xFFD6), W16(0xFFB8), W16(0x0027), W16(0x003D), - W16(0x0037), W16(0x0003), W16(0xFFC9), W16(0xFFD7), W16(0x0021), W16(0x0011), W16(0x001E), W16(0xFFEA), - W16(0xFFEF), W16(0x001D), W16(0x0013), W16(0xFFEC), W16(0x0002), W16(0x0021), W16(0x0023), W16(0x003D), - W16(0xFFF4), W16(0xFFF0), W16(0xFFDD), W16(0x0008), W16(0x000F), W16(0xFFBF), W16(0xFFBA), W16(0xFFEF), - W16(0x003F), W16(0xFFE5), W16(0xFFF4), W16(0xFFFC), W16(0x000A), W16(0x000B), W16(0xFFFE), W16(0xFFD7), - W16(0xFFF7), W16(0x0013), W16(0xFFD5), W16(0xFFEA), W16(0xFFD1), W16(0x0025), W16(0xFFF1), W16(0xFFF8), - W16(0x000E), W16(0x004D), W16(0x0028), W16(0x0004), W16(0x001F), W16(0xFFEA), W16(0xFFD0), W16(0xFFCE), - W16(0xFFF1), W16(0xFFFF), W16(0xFFE6), W16(0xFFF1), W16(0xFFC9), W16(0xFFC2), W16(0xFFCC), W16(0xFFD9), - W16(0xFFFB), W16(0xFFC2), W16(0xFFFE), W16(0xFFE4), W16(0x0022), W16(0x0029), W16(0xFFF8), W16(0x0044), - W16(0xFFBD), W16(0xFFEE), W16(0xFFFF), W16(0xFFD1), W16(0xFFFF), W16(0x002C), W16(0xFFF2), W16(0xFFE4), - W16(0xFFFC), W16(0x000C), W16(0xFFE9), W16(0x001B), W16(0x0019), W16(0x0011), W16(0xFFF6), W16(0xFFC8), - W16(0xFFD8), W16(0x0018), W16(0xFFEE), W16(0xFFD1), W16(0x0042), W16(0xFFDE), W16(0x0031), W16(0xFFC4), - W16(0xFFFB), W16(0xFFEC), W16(0x002B), W16(0xFFF6), W16(0x000B), W16(0xFFEE), W16(0xFFCD), W16(0x003C), - W16(0xFFE2), W16(0xFFFE), W16(0x0006), W16(0xFFF5), W16(0xFFF9), W16(0xFFE4), W16(0xFFEA), W16(0xFFE3), - W16(0xFFD6), W16(0x0017), W16(0xFFFC), W16(0xFFEE), W16(0x0024), W16(0xFFF2), W16(0xFFEB), W16(0x0004), - W16(0x000E), W16(0xFFF3), W16(0x0021), W16(0xFFED), W16(0xFFD3), W16(0xFFFE), W16(0x003B), W16(0xFFDD), - W16(0x0006), W16(0x008A), W16(0xFF6E), W16(0x002F), W16(0x002E), W16(0x0020), W16(0x000F), W16(0xFFDB), - W16(0xFFFF), W16(0x0000), W16(0x0045), W16(0xFFF6), W16(0x0008), W16(0x003C), W16(0xFFE5), W16(0xFFF7), - W16(0xFFDD), W16(0xFFFD), W16(0xFFE8), W16(0xFFC4), W16(0xFFEE), W16(0x0000), W16(0x000D), W16(0x0028), - W16(0x0036), W16(0x0020), W16(0xFFDB), W16(0xFFB8), W16(0xFFDC), W16(0xFFEA), W16(0xFFF1), W16(0xFFE2), - W16(0xFFEE), W16(0x0014), W16(0x002C), W16(0xFFCD), W16(0xFFFB), W16(0x0018), W16(0xFFEE), W16(0x001D), - W16(0x0035), W16(0xFFDA), W16(0x0020), W16(0xFFEC), W16(0x0002), W16(0xFFFF), W16(0xFFB9), W16(0x002B), - W16(0xFFE1), W16(0xFFB9), W16(0xFFE5), W16(0x0007), W16(0x0001), W16(0x000A), W16(0x0025), W16(0x0027), - W16(0x0024), W16(0xFFA1), W16(0x0020), W16(0x001A), W16(0x0020), W16(0xFFFD), W16(0x0001), W16(0xFFDD), - W16(0xFFB9), W16(0x0008), W16(0xFFF3), W16(0x003F), W16(0x0004), W16(0x0012), W16(0xFFDE), W16(0x0026), - W16(0xFFF9), W16(0xFFEB), W16(0xFFFD), W16(0xFFFD), W16(0xFFF1), W16(0xFFF0), W16(0xFFEF), W16(0xFFCE), - W16(0x0002), W16(0xFFF6), W16(0xFFD5), W16(0x002D), W16(0x0014), W16(0x000B), W16(0x0050), W16(0xFFFB), - W16(0xFFC8), W16(0xFFF7), W16(0x0000), W16(0xFFF8), W16(0xFFD7), W16(0xFFE9), W16(0x0044), W16(0xFFFF), - W16(0xFFDC), W16(0xFFC0), W16(0x0010), W16(0x0016), W16(0xFFF1), W16(0x0003), W16(0x0011), W16(0x001F), - W16(0xFFD2), W16(0xFFE4), W16(0xFFDE), W16(0x0028), W16(0xFFE1), W16(0x0048), W16(0x001A), W16(0xFFED), - W16(0x0006), W16(0xFFE3), W16(0xFFD1), W16(0x0012), W16(0x002A), W16(0x0001), W16(0xFFF1), W16(0x001A), - W16(0xFFCE), W16(0x0007), W16(0xFFDA), W16(0xFFE4), W16(0x0034), W16(0xFFE1), W16(0xFFD0), W16(0xFFD2), - W16(0xFFD3), W16(0x0000), W16(0xFFF8), W16(0x0023), W16(0x001A), W16(0xFFD7), W16(0xFFC2), W16(0x0007), - W16(0x0027), W16(0x0035), W16(0xFFC3), W16(0x000D), W16(0x001A), W16(0xFFE5), W16(0x0033), W16(0xFFE6), - W16(0x0000), W16(0xFFCF), W16(0xFFFA), W16(0x0016), W16(0x000C), W16(0x0009), W16(0x001D), W16(0x0014), - W16(0x0014), W16(0x0015), W16(0x000F), W16(0xFFF3), W16(0xFFBB), W16(0x002B), W16(0x002F), W16(0xFFE4), - W16(0xFFF4), W16(0xFFEF), W16(0x004E), W16(0xFFCE), W16(0x0009), W16(0x0012), W16(0x0014), W16(0x0008), - W16(0xFFD1), W16(0x001C), W16(0x0010), W16(0xFFE0), W16(0xFFEE), W16(0xFFF1), W16(0x000C), W16(0x0004), - W16(0xFFA0), W16(0x0005), W16(0x0061), W16(0x000D), W16(0xFFE8), W16(0xFFFF), W16(0xFFF5), W16(0x0002), - W16(0xFFF2), W16(0x0003), W16(0x001F), W16(0x0020), W16(0x0006), W16(0x000D), W16(0xFFFF), W16(0xFFF3), - W16(0xFFE8), W16(0xFFFA), W16(0x0011), W16(0x000B), W16(0xFFE7), W16(0xFFDD), W16(0xFFDA), W16(0xFFC3), - W16(0x0013), W16(0x0022), W16(0xFFDA), W16(0x0002), W16(0xFFF1), W16(0x0049), W16(0xFFC8), W16(0x0025), - W16(0xFFBE), W16(0xFFF7), W16(0x001C), W16(0x002B), W16(0xFFC7), W16(0xFFEF), W16(0x0004), W16(0x002C), - W16(0xFFF7), W16(0xFFF3), W16(0xFFFB), W16(0x000B), W16(0x000A), W16(0xFFE8), W16(0xFFDF), W16(0xFFD2), - W16(0x002E), W16(0xFFEE), W16(0xFFFF), W16(0xFFEE), W16(0x003D), W16(0xFFE4), W16(0xFFE8), W16(0x002D), - W16(0x0000), W16(0x0015), W16(0x000C), W16(0xFFD1), W16(0xFFA8), W16(0xFFF7), W16(0x0011), W16(0x0015), - W16(0x0011), W16(0xFFF8), W16(0x0003), W16(0x0022), W16(0xFFD0), W16(0xFFC1), W16(0xFFC2), W16(0xFFD9), - W16(0x0006), W16(0x0016), W16(0xFFFB), W16(0xFF9E), W16(0xFFBD), W16(0xFFDF), W16(0xFFD1), W16(0x0019), - W16(0x000F), W16(0x0021), W16(0xFFE9), W16(0xFFF1), W16(0x0024), W16(0x0010), W16(0x0006), W16(0x0016), - W16(0x0021), W16(0x0014), W16(0x0017), W16(0x0016), W16(0x0002), W16(0xFFE5), W16(0xFFE0), W16(0xFFDD), - W16(0xFFE0), W16(0x0019), W16(0x0009), W16(0x0038), W16(0x0013), W16(0x0005), W16(0x0009), W16(0x0034), - W16(0x0024), W16(0xFFB7), W16(0xFFFD), W16(0x003C), W16(0xFFD1), W16(0xFFED), W16(0xFFFD), W16(0xFFEB), - W16(0xFFF1), W16(0x002C), W16(0x0031), W16(0xFFE2), W16(0xFFFD), W16(0xFFDA), W16(0xFFF5), W16(0x0001), - W16(0x0002), W16(0xFFE6), W16(0xFFDF), W16(0xFFDB), W16(0x0041), W16(0x000A), W16(0xFFD3), W16(0x0000), - W16(0x0021), W16(0x001C), W16(0xFFDC), W16(0x002A), W16(0x0012), W16(0xFFDF), W16(0xFFBD), W16(0x0001), - W16(0xFFF0), W16(0x003B), W16(0x0005), W16(0x0009), W16(0x0031), W16(0x0026), W16(0x001A), W16(0x0007), - W16(0x003C), W16(0xFFE4), W16(0x003E), W16(0xFFF5), W16(0x002C), W16(0xFFFB), W16(0x0024), W16(0xFFD0), - W16(0x001F), W16(0xFFD1), W16(0x0005), W16(0x0012), W16(0x0004), W16(0xFFCC), W16(0x001F), W16(0xFFF1), - W16(0xFFFE), W16(0xFFF4), W16(0xFFE6), W16(0x0020), W16(0xFFFD), W16(0xFFEA), W16(0xFFD6), W16(0xFFB7), - W16(0x0034), W16(0xFFDE), W16(0xFFC8), W16(0xFFBB), W16(0x0018), W16(0xFFFE), W16(0xFFC5), W16(0xFFDE), - W16(0x0010), W16(0xFFFB), W16(0x0013), W16(0xFFD3), W16(0x002C), W16(0x000E), W16(0x0032), W16(0x0002), - W16(0xFFEA), W16(0xFFDE), W16(0xFFD6), W16(0xFFEF), W16(0x0009), W16(0xFFFB), W16(0x0012), W16(0x001C), - W16(0x004A), W16(0xFFD8), W16(0x0012), W16(0x0013), W16(0xFFE1), W16(0xFFF3), W16(0xFFD0), W16(0xFFFB), - W16(0xFFEB), W16(0x001A), W16(0x004F), W16(0xFFF6), W16(0xFFE2), W16(0x001D), W16(0x003B), W16(0xFFBB), - W16(0x0022), W16(0x0016), W16(0x001D), W16(0xFFF7), W16(0xFFF3), W16(0x0000), W16(0x0007), W16(0x0003), - W16(0xFFE8), W16(0xFFFF), W16(0x000B), W16(0x0018), W16(0x0001), W16(0x002D), W16(0xFFE3), W16(0xFFEA), - W16(0xFFDD), W16(0x002D), W16(0x0008), W16(0xFFE3), W16(0x0031), W16(0x0029), W16(0x0000), W16(0xFFD6), - W16(0xFFDF), W16(0xFFE3), W16(0x0001), W16(0x0091), W16(0xFF6B), W16(0x0028), W16(0x0032), W16(0xFFF0), - W16(0x000B), W16(0xFFF6), W16(0x0011), W16(0x000E), W16(0xFFB0), W16(0x003F), W16(0x0007), W16(0x004A), - W16(0x0015), W16(0x0025), W16(0xFFCA), W16(0xFFD4), W16(0xFFE5), W16(0xFFF2), W16(0x0026), W16(0xFFFF), - W16(0xFFED), W16(0xFFFC), W16(0x0006), W16(0x0009), W16(0x000A), W16(0xFFF4), W16(0xFFFF), W16(0xFFFD), - W16(0x004B), W16(0x0013), W16(0xFFF7), W16(0x0009), W16(0x0021), W16(0x0000), W16(0x0015), W16(0x000D), - W16(0xFFD2), W16(0x002C), W16(0xFF9E), W16(0xFFED), W16(0x001E), W16(0x000D), W16(0x000D), W16(0xFFFE), - W16(0xFFFE), W16(0xFFF0), W16(0xFFF3), W16(0xFFF3), W16(0x0006), W16(0x000C), W16(0x0011), W16(0x0003), - W16(0x0026), W16(0x0047), W16(0xFFE0), W16(0xFFF6), W16(0xFFD5), W16(0xFFF6), W16(0xFFF4), W16(0xFFFC), - W16(0x0049), W16(0x001B), W16(0xFFDE), W16(0x0053), W16(0xFFE1), W16(0xFFF3), W16(0xFFF3), W16(0x0004), - W16(0xFFE5), W16(0xFFE4), W16(0xFFFD), W16(0x0013), W16(0xFFE9), W16(0x0005), W16(0xFFF0), W16(0xFFC2), - W16(0xFFFC), W16(0x000D), W16(0x0008), W16(0x0023), W16(0x002A), W16(0xFFCD), W16(0x0034), W16(0x0002), - W16(0xFFE5), W16(0x0032), W16(0x0036), W16(0x0011), W16(0x0006), W16(0xFFC8), W16(0xFFEE), W16(0xFFD7), - W16(0xFFE2), W16(0x0011), W16(0x001D), W16(0x0043), W16(0x002F), W16(0xFFF3), W16(0xFFE0), W16(0xFFD6), - W16(0xFFFC), W16(0x002B), W16(0x0000), W16(0x001E), W16(0x000D), W16(0x002E), W16(0xFFDF), W16(0x0006), - W16(0x000B), W16(0xFFE7), W16(0xFFEA), W16(0xFFF8), W16(0x000B), W16(0xFFDC), W16(0x004B), W16(0xFF7E), - W16(0x005D), W16(0xFFE1), W16(0xFFDF), W16(0xFFF9), W16(0x002E), W16(0xFFF6), W16(0xFFFE), W16(0x0027), - W16(0xFFEB), W16(0x0033), W16(0xFFC8), W16(0x0008), W16(0xFFE0), W16(0xFFEF), W16(0xFFF9), W16(0x0007), - W16(0xFFBB), W16(0x000D), W16(0xFFFF), W16(0x000D), W16(0x003E), W16(0x001F), W16(0x0014), W16(0xFFF6), - W16(0xFFF6), W16(0x003B), W16(0x001A), W16(0xFFD2), W16(0xFFE7), W16(0x0093), W16(0x0065), W16(0xFF85), - W16(0x0028), W16(0xFFCF), W16(0x0031), W16(0x0011), W16(0xFFF6), W16(0xFFE2), W16(0xFFFD), W16(0xFFFA), - W16(0x0003), W16(0x002F), W16(0xFFFB), W16(0xFFCB), W16(0x004A), W16(0x0012), W16(0xFFC6), W16(0xFFED), - W16(0x0029), W16(0xFFA8), W16(0x002F), W16(0x002C), W16(0x0013), W16(0xFFEF), W16(0xFFFD), W16(0x0004), - W16(0x0005), W16(0xFFD9), W16(0xFFD1), W16(0x000C), W16(0x0004), W16(0xFFF4), W16(0x0000), W16(0xFFF0), - W16(0x000F), W16(0xFFEB), W16(0x0029), W16(0x0019), W16(0x001D), W16(0x0022), W16(0xFFF5), W16(0xFFEF), - W16(0xFFBA), W16(0x0018), W16(0x0044), W16(0x002D), W16(0xFFD1), W16(0xFFA7), W16(0x0019), W16(0x0077), - W16(0xFFF4), W16(0x0056), W16(0x0010), W16(0x0017), W16(0x0014), W16(0x0019), W16(0x0015), W16(0xFFBF), - W16(0x001D), W16(0xFFFB), W16(0xFFD8), W16(0xFFEC), W16(0xFFEB), W16(0x000C), W16(0x002E), W16(0x0019), - W16(0xFFE5), W16(0xFFFB), W16(0x0021), W16(0x003B), W16(0x0022), W16(0xFFEE), W16(0xFFF2), W16(0xFFF2), - W16(0xFFFA), W16(0xFFF3), W16(0x000A), W16(0x0006), W16(0xFFF9), W16(0xFFEC), W16(0xFFF5), W16(0x0012), - W16(0xFFDD), W16(0xFFFD), W16(0x001F), W16(0x001A), W16(0x0037), W16(0xFF7C), W16(0x0024), W16(0x001C), - W16(0x000F), W16(0x0024), W16(0x0021), W16(0xFFD4), W16(0x0009), W16(0xFFF3), W16(0x0007), W16(0x0046), - W16(0xFFFF), W16(0x0015), W16(0x0002), W16(0x001C), W16(0xFFCE), W16(0xFFBC), W16(0x0023), W16(0xFFF2), - W16(0xFFF1), W16(0xFFD0), W16(0x001E), W16(0x001F), W16(0x0022), W16(0x0007), W16(0xFFDE), W16(0x001E), - W16(0x003F), W16(0x0009), W16(0x0020), W16(0x003E), W16(0x002F), W16(0x0028), W16(0x0035), W16(0x002D), - W16(0x000E), W16(0x0010), W16(0x002D), W16(0x0004), W16(0xFFDE), W16(0x0002), W16(0x0008), W16(0xFF95), - W16(0x000F), W16(0x002D), W16(0xFFF8), W16(0x003A), W16(0x002D), W16(0x0003), W16(0x0005), W16(0xFFEB), - W16(0xFFF5), W16(0xFFEF), W16(0xFFE0), W16(0x0003), W16(0x001F), W16(0x001B), W16(0x001C), W16(0x0017), - W16(0x0017), W16(0xFFFB), W16(0x0035), W16(0x001A), W16(0x003F), W16(0x0047), W16(0xFFD5), W16(0xFFEC), - W16(0x000E), W16(0x0005), W16(0xFFF6), W16(0x000A), W16(0xFFE4), W16(0x0020), W16(0x0004), W16(0xFFC5), - W16(0xFFD9), W16(0xFFDB), W16(0xFFFE), W16(0xFFE5), W16(0xFFF9), W16(0xFFF1), W16(0x000F), W16(0x001B), - W16(0x0006), W16(0x0052), W16(0x0025), W16(0xFFED), W16(0x001D), W16(0xFFEA), W16(0xFFE0), W16(0x0014), - W16(0xFFBF), W16(0x0042), W16(0x0025), W16(0x0004), W16(0xFFE4), W16(0x000B), W16(0xFFDE), W16(0x000B), - W16(0x0002), W16(0xFFF1), W16(0xFFEF), W16(0x0006), W16(0x0013), W16(0x0013), W16(0x0032), W16(0x0034), - W16(0x0028), W16(0x0016), W16(0x0017), W16(0xFFE7), W16(0x0025), W16(0xFFEF), W16(0x0009), W16(0xFFE8), - W16(0xFFEC), W16(0xFFC2), W16(0x002B), W16(0x0013), W16(0x0009), W16(0x004E), W16(0xFFC9), W16(0xFFC9), - W16(0x0027), W16(0x0040), W16(0xFFE6), W16(0xFFF6), W16(0x0000), W16(0x0007), W16(0xFFFE), W16(0xFFF3), - W16(0x0006), W16(0xFFEE), W16(0xFFF7), W16(0x0038), W16(0xFFFD), W16(0xFFF4), W16(0xFFE9), W16(0x000D), - W16(0xFFDE), W16(0xFFFD), W16(0xFFD1), W16(0x0010), W16(0xFFF1), W16(0x0006), W16(0xFFF2), W16(0x0033), - W16(0x0043), W16(0x000E), W16(0x0018), W16(0x0026), W16(0xFFF0), W16(0xFFA0), W16(0xFFB0), W16(0x00BF), - W16(0xFFF9), W16(0x0002), W16(0xFFFE), W16(0x0033), W16(0x0001), W16(0x0019), W16(0xFFD1), W16(0x000D), - W16(0x0016), W16(0xFFB4), W16(0xFFF4), W16(0xFFCA), W16(0x0046), W16(0x0002), W16(0x002A), W16(0x0010), - W16(0xFFFE), W16(0x0021), W16(0x0018), W16(0x0017), W16(0xFFF1), W16(0xFFE7), W16(0xFFF1), W16(0xFFF4), - W16(0x000D), W16(0xFFE0), W16(0x0019), W16(0x0015), W16(0x0006), W16(0xFFB4), W16(0xFFCB), W16(0x000E), - W16(0x0008), W16(0x0017), W16(0xFFF4), W16(0xFFF1), W16(0x0019), W16(0x000E), W16(0x0010), W16(0x0075), - W16(0xFFBD), W16(0x001F), W16(0x0012), W16(0xFFE7), W16(0x0025), W16(0x000A), W16(0xFFEC), W16(0xFFD9), - W16(0x0002), W16(0xFFF2), W16(0x0032), W16(0x0049), W16(0xFFDA), W16(0x000E), W16(0x0052), W16(0xFFD9), - W16(0x000D), W16(0x0006), W16(0x0006), W16(0xFFEF), W16(0xFFC3), W16(0x0020), W16(0xFFF4), W16(0xFFF0), - W16(0x001E), W16(0xFFFB), W16(0xFFF3), W16(0x000A), W16(0x000C), W16(0x000E), W16(0x0005), W16(0x000B), - W16(0xFFCF), W16(0xFFF1), W16(0xFFE8), W16(0x0019), W16(0xFFF4), W16(0x0043), W16(0xFFEF), W16(0xFFEF), - W16(0x003B), W16(0xFFF5), W16(0x0027), W16(0xFFDD), W16(0xFFE9), W16(0xFFD0), W16(0xFFEB), W16(0xFFF9), - W16(0x001B), W16(0x0003), W16(0x0033), W16(0x002A), W16(0x0049), W16(0x0024), W16(0x000F), W16(0xFFF8), - W16(0x0015), W16(0x0026), W16(0x0010), W16(0x000E), W16(0x0004), W16(0xFFDA), W16(0x0009), W16(0xFFF8), - W16(0x004F), W16(0x003C), W16(0xFFD9), W16(0xFFDE), W16(0xFFF3), W16(0x0012), W16(0xFFE9), W16(0xFFDE), - W16(0x0013), W16(0x0058), W16(0x0010), W16(0xFFF8), W16(0xFFEC), W16(0xFFEB), W16(0x0008), W16(0x001F), - W16(0x005B), W16(0x0043), W16(0xFFFA), W16(0x0028), W16(0xFFEC), W16(0xFFF8), W16(0xFFF9), W16(0x0044), - W16(0x0008), W16(0xFFE6), W16(0x000F), W16(0xFFF1), W16(0x0016), W16(0x0005), W16(0xFFF3), W16(0x0001), - W16(0xFFE4), W16(0xFFF3), W16(0xFFFC), W16(0xFFF7), W16(0x0015), W16(0xFFFC), W16(0xFFE2), W16(0xFFCD), - W16(0x0001), W16(0x0003), W16(0x006E), W16(0xFFEB), W16(0x0011), W16(0xFFC8), W16(0x0023), W16(0x0026), - W16(0xFFF9), W16(0x0000), W16(0xFFD4), W16(0x001A), W16(0x0010), W16(0xFFF0), W16(0xFFE0), W16(0x0029), - W16(0xFFEC), W16(0x0018), W16(0x0027), W16(0x0010), W16(0x0009), W16(0xFFFB), W16(0x0016), W16(0x0034), - W16(0x0041), W16(0x001F), W16(0xFFD6), W16(0xFFBD), W16(0x0011), W16(0x0026), W16(0x003B), W16(0xFFDE), - W16(0xFFD0), W16(0xFFEF), W16(0xFFE6), W16(0xFFF1), W16(0x000B), W16(0xFFF0), W16(0xFFE2), W16(0x001D), - W16(0x001F), W16(0x0038), W16(0x0028), W16(0x0005), W16(0xFFB6), W16(0xFFD4), W16(0x0013), W16(0x0007), - W16(0x0003), W16(0xFFF8), W16(0xFFFF), W16(0xFFDD), W16(0x0002), W16(0x0001), W16(0xFFFD), W16(0xFFD9), - W16(0xFFCE), W16(0x0003), W16(0xFFFE), W16(0x0007), W16(0xFFCF), W16(0x001B), W16(0x0049), W16(0x0026), - W16(0xFFF8), W16(0x0038), W16(0x0046), W16(0x0009), W16(0x006E), W16(0x0044), W16(0x0011), W16(0xFFFF), - W16(0x000F), W16(0x0003), W16(0x002A), W16(0x0001), W16(0xFFE9), W16(0xFFF7), W16(0xFFCF), W16(0x000F), - W16(0x0014), W16(0x0003), W16(0x0028), W16(0x0031), W16(0x0008), W16(0xFFF2), W16(0xFFF2), W16(0xFFE6), - W16(0x0001), W16(0x000E), W16(0xFFA6), W16(0xFFA6), W16(0x0081), W16(0x007A), W16(0xFFA0), W16(0x0023) -}; - -const Word16 * const cdk_37bits[] = { cdk_37bits_1_fx, cdk_37bits_2_fx, cdk_37bits_3_fx, cdk_37bits_4_fx, - cdk_37bits_5_fx, cdk_37bits_6_fx - }; - -const Word16 *lsf_means[2] = { means_wb_31bits_ma_lsf, means_nb_31bits_ma_lsf }; - - -const lsp_unw_triplet p16_gamma0_92to1[16] = /* Q14 */ -{ - { 0, 19622, -9695 }, - { -14938, 29357, -13258 }, - { -8483, 23708, -13414 }, - { -7350, 22410, -12305 }, - { -7397, 21417, -12160 }, - { -7071, 19878, -11229 }, - { -7144, 19877, -11326 }, - { -6423, 17194, -9613 }, - { -7407, 18024, -9695 }, - { -6972, 16339, -8191 }, - { -8220, 17625, -8422 }, - { -8159, 17459, -8289 }, - { -8700, 19066, -9508 }, - { -7986, 17629, -8607 }, - { -8503, 17203, -8109 }, - { -7820, 14903, 0 } -}; - -const lsp_unw_triplet p16_gamma0_94to1[16] = /* Q14 */ -{ - { 0, 12931, -6314 }, - { -9364, 19577, -8870 }, - { -5512, 16236, -9305 }, - { -4892, 15366, -8398 }, - { -4869, 14631, -8275 }, - { -4631, 13358, -7540 }, - { -4575, 13271, -7599 }, - { -4151, 11403, -6385 }, - { -4859, 11947, -6371 }, - { -4504, 10805, -5407 }, - { -5346, 11618, -5515 }, - { -5418, 11578, -5424 }, - { -5806, 12711, -6226 }, - { -5205, 11592, -5606 }, - { -5745, 11498, -5188 }, - { -5473, 10245, 0 } -}; - - -/*Frame size config table*/ -const FrameSizeParams FrameSizeConfig[FRAME_SIZE_NB] = -{ - /* bits, net bits, trans_bits, trans_mode, band_bits, band_mode_min, band_mode_max, reserved_bits */ - { FRAME_0, FRAME_0, 0, {0,0}, 0, 0, 0, 0}, /* 0 kbps ZERO_FRAME*/ - { FRAME_2_4, FRAME_2_4-2, 1, {1,1}, 1, NB, WB, 0}, /* 2.8kbps VBR(SID)*/ - { FRAME_7_2, FRAME_7_2-1, 0, {0,1}, 1, NB, WB, 0}, /* 7.2kbps VBR/CBR*/ - { FRAME_8, FRAME_8-1, 0, {0,1}, 1, NB, WB, 0}, /* 8 kbps VBR/CBR*/ - { FRAME_9_6, FRAME_9_6-2, 0, {0,1}, 2, NB, SWB, 0}, /* 9.6kbps CBR*/ - { FRAME_13_2, FRAME_13_2-2, 0, {0,1}, 2, NB, SWB, 0}, /* 13.2kbps CBR*/ - { FRAME_16_4, FRAME_16_4-3, 0, {0,1}, 2, NB, FB, 1}, /* 16.4kbps CBR*/ - { FRAME_24_4, FRAME_24_4-3, 0, {0,1}, 2, NB, FB, 1}, /* 24.4kbps CBR*/ - { FRAME_32, FRAME_32-3, 0, {0,1}, 2, WB, FB, 1}, /* 32 kbps CBR*/ - { FRAME_48, FRAME_48-3, 0, {0,1}, 2, WB, FB, 1}, /* 48 kbps CBR*/ - { FRAME_64, FRAME_64-3, 0, {0,1}, 2, WB, FB, 1}, /* 64 kbps CBR*/ - { FRAME_96, FRAME_96-3, 0, {0,1}, 2, WB, FB, 1}, /* 96 kbps CBR*/ - { FRAME_128, FRAME_128-3, 0, {0,1}, 2, WB, FB, 1} /*128 kbps CBR*/ -}; - - -/*===OUTER LOOP 0===*/ -/*./genari 64 -1 ../histo/histo_s17_LC_rate_2*/ -/*limit_tns:-1.00*/ -/* -Entropy: -Entropy full mem.: 2.4198 bit (100.00 %) -Entropy no mem. : 3.2222 bit (133.16 %) -Entropy clustered : : 2.4227 bit (100.12 %) -Perf. clustered and mapped : : 2.4321 bit (100.51 %) -*/ -/*Total states: 398*/ -/*Proba models: 64*/ -/*Tables size: 1535.8 of 32 bits words*/ -/*Perf. clustered and mapped : : 2.4318 bit (100.50 %)*/ - -Word8 const ari_lookup_s17_LC[4096] = -{ - 0x01,0x04,0x29,0x13,0x0A,0x0D,0x05,0x10, - 0x10,0x0D,0x00,0x0D,0x2A,0x2A,0x22,0x25, - 0x25,0x28,0x2B,0x2E,0x31,0x34,0x34,0x0E, - 0x21,0x21,0x21,0x36,0x38,0x38,0x36,0x10, - 0x10,0x08,0x09,0x0B,0x0C,0x0E,0x0E,0x21, - 0x36,0x36,0x36,0x36,0x36,0x36,0x36,0x10, - 0x10,0x1A,0x09,0x1D,0x0C,0x20,0x20,0x21, - 0x36,0x36,0x36,0x36,0x36,0x0A,0x36,0x16, - 0x1A,0x1A,0x2D,0x0C,0x20,0x20,0x21,0x21, - 0x21,0x36,0x38,0x38,0x38,0x38,0x36,0x16, - 0x16,0x1A,0x3F,0x1F,0x20,0x21,0x24,0x06, - 0x36,0x36,0x36,0x38,0x00,0x0A,0x36,0x22, - 0x3E,0x3E,0x3F,0x30,0x20,0x21,0x06,0x06, - 0x06,0x38,0x36,0x36,0x36,0x26,0x36,0x1C, - 0x1C,0x3E,0x3F,0x02,0x20,0x21,0x06,0x36, - 0x36,0x38,0x0A,0x0A,0x0A,0x0A,0x05,0x16, - 0x16,0x16,0x16,0x16,0x16,0x16,0x16,0x16, - 0x16,0x16,0x16,0x16,0x16,0x16,0x16,0x16, - 0x16,0x3F,0x3F,0x0E,0x35,0x14,0x38,0x38, - 0x05,0x05,0x05,0x0D,0x13,0x13,0x1C,0x16, - 0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F, - 0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F, - 0x3F,0x3F,0x3F,0x20,0x35,0x14,0x27,0x38, - 0x38,0x0A,0x2A,0x2A,0x2A,0x16,0x05,0x10, - 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, - 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, - 0x00,0x3F,0x02,0x0E,0x02,0x14,0x13,0x0A, - 0x0D,0x0D,0x0D,0x13,0x00,0x00,0x16,0x19, - 0x19,0x3F,0x3F,0x02,0x02,0x14,0x38,0x36, - 0x0A,0x0A,0x0A,0x0D,0x0D,0x0D,0x1C,0x22, - 0x22,0x3F,0x3F,0x02,0x17,0x26,0x26,0x1C, - 0x1C,0x10,0x16,0x16,0x16,0x19,0x22,0x25, - 0x39,0x39,0x39,0x39,0x39,0x39,0x39,0x39, - 0x39,0x39,0x39,0x39,0x39,0x39,0x39,0x39, - 0x39,0x39,0x15,0x2C,0x2E,0x2E,0x2E,0x31, - 0x31,0x31,0x31,0x31,0x31,0x31,0x34,0x39, - 0x39,0x39,0x15,0x2C,0x2E,0x2E,0x0C,0x34, - 0x34,0x34,0x36,0x36,0x36,0x36,0x36,0x36, - 0x36,0x39,0x15,0x3C,0x2E,0x31,0x34,0x34, - 0x31,0x31,0x31,0x1F,0x1E,0x1E,0x1E,0x1E, - 0x1E,0x39,0x28,0x2C,0x2E,0x31,0x37,0x34, - 0x01,0x01,0x01,0x01,0x01,0x00,0x39,0x39, - 0x39,0x39,0x39,0x2C,0x2E,0x31,0x1E,0x34, - 0x34,0x35,0x01,0x01,0x01,0x01,0x01,0x01, - 0x01,0x39,0x39,0x3C,0x2E,0x03,0x07,0x34, - 0x34,0x0F,0x39,0x39,0x39,0x39,0x39,0x39, - 0x39,0x39,0x39,0x15,0x2B,0x31,0x1E,0x34, - 0x34,0x01,0x39,0x39,0x39,0x39,0x39,0x39, - 0x39,0x39,0x39,0x39,0x39,0x39,0x39,0x39, - 0x39,0x39,0x39,0x39,0x39,0x39,0x39,0x39, - 0x39,0x39,0x39,0x2C,0x39,0x2F,0x2E,0x2E, - 0x2E,0x2E,0x2E,0x2E,0x2E,0x2E,0x2E,0x2E, - 0x2E,0x2E,0x2E,0x2E,0x2E,0x2E,0x2E,0x2E, - 0x2E,0x2E,0x2E,0x2E,0x2E,0x2E,0x2E,0x2E, - 0x2E,0x39,0x1E,0x1E,0x1E,0x1E,0x1E,0x1E, - 0x1E,0x1E,0x1E,0x1E,0x1E,0x1E,0x1E,0x1E, - 0x1E,0x1E,0x1E,0x1E,0x1E,0x1E,0x1E,0x1E, - 0x1E,0x1E,0x1E,0x1E,0x1E,0x1E,0x1E,0x1E, - 0x1E,0x1E,0x1E,0x1E,0x1E,0x0F,0x2E,0x2E, - 0x2E,0x2E,0x2E,0x2E,0x2E,0x2E,0x2E,0x2E, - 0x2E,0x2E,0x39,0x15,0x39,0x39,0x39,0x39, - 0x39,0x39,0x39,0x39,0x39,0x39,0x39,0x39, - 0x39,0x39,0x39,0x39,0x39,0x39,0x39,0x39, - 0x39,0x39,0x39,0x39,0x39,0x39,0x39,0x39, - 0x19,0x1C,0x16,0x22,0x22,0x25,0x25,0x25, - 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, - 0x3E,0x3E,0x2F,0x3D,0x21,0x36,0x38,0x05, - 0x0D,0x0D,0x0D,0x10,0x16,0x16,0x16,0x25, - 0x2D,0x2D,0x37,0x3D,0x33,0x38,0x05,0x0D, - 0x0D,0x10,0x16,0x16,0x16,0x16,0x16,0x25, - 0x2F,0x2F,0x30,0x12,0x06,0x05,0x0A,0x0D, - 0x0D,0x10,0x16,0x16,0x16,0x22,0x22,0x25, - 0x1F,0x1F,0x32,0x3B,0x29,0x0A,0x0A,0x10, - 0x16,0x16,0x16,0x16,0x22,0x22,0x22,0x25, - 0x02,0x02,0x14,0x29,0x05,0x0D,0x2A,0x10, - 0x16,0x16,0x16,0x22,0x22,0x22,0x22,0x25, - 0x35,0x35,0x14,0x29,0x0A,0x2A,0x2A,0x10, - 0x16,0x16,0x16,0x22,0x22,0x22,0x22,0x25, - 0x17,0x17,0x26,0x05,0x0D,0x10,0x10,0x16, - 0x22,0x22,0x22,0x22,0x22,0x22,0x22,0x25, - 0x26,0x26,0x26,0x26,0x26,0x26,0x26,0x26, - 0x26,0x26,0x26,0x26,0x26,0x26,0x26,0x26, - 0x26,0x26,0x26,0x1C,0x0D,0x16,0x16,0x16, - 0x22,0x22,0x22,0x22,0x22,0x22,0x25,0x00, - 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, - 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, - 0x00,0x26,0x1C,0x1C,0x10,0x16,0x16,0x22, - 0x22,0x22,0x22,0x22,0x22,0x25,0x25,0x00, - 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, - 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, - 0x00,0x1C,0x1C,0x1C,0x16,0x16,0x16,0x22, - 0x22,0x22,0x22,0x25,0x25,0x25,0x25,0x00, - 0x00,0x26,0x1C,0x1C,0x16,0x16,0x16,0x22, - 0x22,0x22,0x22,0x25,0x25,0x25,0x25,0x00, - 0x16,0x16,0x16,0x16,0x16,0x22,0x22,0x22, - 0x25,0x25,0x25,0x25,0x25,0x25,0x25,0x00, - 0x15,0x15,0x15,0x15,0x15,0x15,0x15,0x15, - 0x15,0x15,0x15,0x15,0x15,0x15,0x15,0x15, - 0x15,0x15,0x3C,0x1E,0x0F,0x06,0x27,0x2A, - 0x2A,0x10,0x16,0x16,0x16,0x16,0x16,0x22, - 0x2C,0x2C,0x0B,0x37,0x23,0x27,0x13,0x2A, - 0x10,0x10,0x10,0x16,0x16,0x16,0x16,0x22, - 0x1B,0x1B,0x1D,0x0F,0x24,0x13,0x13,0x2A, - 0x00,0x10,0x16,0x16,0x16,0x16,0x16,0x22, - 0x1F,0x1F,0x03,0x24,0x07,0x0A,0x0A,0x10, - 0x16,0x16,0x16,0x16,0x16,0x16,0x16,0x22, - 0x22,0x35,0x06,0x27,0x13,0x2A,0x2A,0x10, - 0x16,0x16,0x16,0x16,0x16,0x22,0x22,0x22, - 0x22,0x06,0x27,0x27,0x13,0x2A,0x2A,0x10, - 0x16,0x16,0x16,0x16,0x16,0x16,0x22,0x22, - 0x22,0x05,0x0A,0x2A,0x2A,0x10,0x10,0x16, - 0x16,0x16,0x16,0x16,0x16,0x22,0x22,0x22, - 0x22,0x22,0x22,0x22,0x22,0x22,0x22,0x22, - 0x22,0x22,0x22,0x22,0x22,0x22,0x22,0x22, - 0x22,0x0D,0x2A,0x10,0x10,0x10,0x10,0x16, - 0x16,0x16,0x16,0x16,0x16,0x22,0x22,0x25, - 0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10, - 0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10, - 0x10,0x10,0x10,0x10,0x10,0x16,0x16,0x16, - 0x16,0x16,0x16,0x22,0x22,0x22,0x22,0x25, - 0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10, - 0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10, - 0x10,0x10,0x10,0x10,0x16,0x16,0x16,0x16, - 0x16,0x22,0x22,0x22,0x22,0x22,0x22,0x25, - 0x0D,0x0D,0x10,0x10,0x10,0x16,0x16,0x16, - 0x16,0x22,0x22,0x22,0x22,0x22,0x22,0x25, - 0x0D,0x0D,0x0D,0x0D,0x0D,0x10,0x10,0x16, - 0x16,0x16,0x16,0x22,0x22,0x22,0x22,0x25, - 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x11, - 0x11,0x11,0x11,0x3A,0x11,0x11,0x11,0x18, - 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, - 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x11, - 0x11,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, - 0x3A,0x3A,0x3A,0x3A,0x3A,0x11,0x3A,0x11, - 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, - 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x11, - 0x11,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, - 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x11, - 0x11,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, - 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x18, - 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, - 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x11, - 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, - 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x18, - 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, - 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, - 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, - 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x11, - 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, - 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, - 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, - 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x11,0x18, - 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, - 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, - 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, - 0x3A,0x3A,0x3A,0x11,0x3A,0x3A,0x3A,0x11, - 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, - 0x3A,0x3A,0x3A,0x3A,0x11,0x11,0x11,0x18, - 0x00,0x11,0x3A,0x11,0x11,0x11,0x11,0x11, - 0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x18, - 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, - 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, - 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, - 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, - 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, - 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, - 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, - 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, - 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, - 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, - 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, - 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, - 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, - 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, - 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, - 0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18, - 0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18, - 0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18, - 0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18, - 0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18, - 0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18, - 0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18, - 0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18, - 0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18, - 0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18, - 0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18, - 0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18, - 0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18, - 0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18, - 0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18, - 0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18, - 0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18, - 0x18,0x11,0x11,0x11,0x18,0x18,0x18,0x18, - 0x18,0x25,0x00,0x00,0x00,0x00,0x00,0x00, - 0x00,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x11, - 0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x18, - 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x11, - 0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x18, - 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x11, - 0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x18, - 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x11, - 0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x18, - 0x3A,0x3A,0x3A,0x3A,0x3A,0x11,0x3A,0x11, - 0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x18, - 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x11, - 0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x18, - 0x3A,0x3A,0x3A,0x3A,0x3A,0x11,0x11,0x11, - 0x11,0x11,0x11,0x11,0x11,0x11,0x18,0x18, - 0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18, - 0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18, - 0x18,0x3A,0x11,0x11,0x11,0x11,0x11,0x11, - 0x11,0x11,0x11,0x11,0x11,0x11,0x18,0x18, - 0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11, - 0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11, - 0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11, - 0x11,0x11,0x11,0x11,0x11,0x11,0x18,0x18, - 0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11, - 0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11, - 0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11, - 0x11,0x11,0x11,0x11,0x18,0x18,0x18,0x18, - 0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11, - 0x11,0x11,0x18,0x18,0x18,0x18,0x18,0x18, - 0x18,0x18,0x11,0x18,0x18,0x18,0x18,0x18, - 0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x00, - 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, - 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, - 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, - 0x3A,0x3A,0x3A,0x3A,0x11,0x11,0x11,0x11, - 0x11,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, - 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x11,0x11, - 0x11,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, - 0x3A,0x3A,0x3A,0x3A,0x11,0x11,0x11,0x11, - 0x11,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, - 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x11,0x11, - 0x11,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, - 0x3A,0x3A,0x3A,0x3A,0x11,0x11,0x11,0x11, - 0x11,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, - 0x3A,0x3A,0x3A,0x3A,0x3A,0x11,0x11,0x11, - 0x11,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, - 0x3A,0x3A,0x3A,0x3A,0x11,0x11,0x11,0x11, - 0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11, - 0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11, - 0x11,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, - 0x3A,0x3A,0x3A,0x3A,0x11,0x11,0x11,0x18, - 0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18, - 0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18, - 0x18,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, - 0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x18, - 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, - 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, - 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, - 0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x18, - 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x11, - 0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x18, - 0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11, - 0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x18, - 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, - 0x3A,0x11,0x11,0x11,0x11,0x11,0x11,0x11, - 0x11,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, - 0x3A,0x3A,0x3A,0x3A,0x3A,0x11,0x3A,0x11, - 0x11,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, - 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, - 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, - 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, - 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, - 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, - 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, - 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, - 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, - 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x11, - 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, - 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x11, - 0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11, - 0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11, - 0x11,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, - 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x11, - 0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11, - 0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11, - 0x11,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, - 0x3A,0x3A,0x3A,0x3A,0x3A,0x11,0x3A,0x3A, - 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, - 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, - 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, - 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x11, - 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, - 0x3A,0x3A,0x3A,0x3A,0x11,0x11,0x3A,0x11, - 0x11,0x3A,0x3A,0x3A,0x11,0x3A,0x3A,0x3A, - 0x3A,0x3A,0x11,0x11,0x11,0x3A,0x11,0x11, - 0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11, - 0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11, - 0x11,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, - 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, - 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, - 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, - 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, - 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, - 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, - 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, - 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, - 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, - 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, - 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, - 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, - 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, - 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, - 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, - 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, - 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, - 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, - 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, - 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, - 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, - 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, - 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, - 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, - 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, - 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, - 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, - 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, - 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, - 0x18,0x3A,0x3A,0x11,0x11,0x11,0x18,0x18, - 0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x00, - 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, - 0x3A,0x3A,0x11,0x11,0x11,0x3A,0x11,0x11, - 0x11,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, - 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x11,0x11, - 0x11,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, - 0x3A,0x3A,0x3A,0x3A,0x11,0x11,0x11,0x11, - 0x11,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, - 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x11,0x11, - 0x11,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, - 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x11,0x11, - 0x11,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, - 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x11,0x11, - 0x11,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, - 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x11,0x11, - 0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11, - 0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11, - 0x11,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, - 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x11,0x18, - 0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18, - 0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18, - 0x18,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, - 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x11,0x18, - 0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18, - 0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18, - 0x18,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, - 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x11,0x18, - 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, - 0x3A,0x3A,0x11,0x11,0x11,0x11,0x11,0x18, - 0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11, - 0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x18, - 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, - 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, - 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, - 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, - 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, - 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, - 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, - 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, - 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, - 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, - 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, - 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, - 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, - 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, - 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, - 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, - 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, - 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, - 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, - 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, - 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, - 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, - 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, - 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, - 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, - 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, - 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, - 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, - 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, - 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x11, - 0x11,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, - 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x11, - 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, - 0x3A,0x3A,0x3A,0x11,0x3A,0x3A,0x3A,0x3A, - 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, - 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, - 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, - 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, - 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, - 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, - 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, - 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, - 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, - 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, - 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, - 0x3A,0x11,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, - 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, - 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, - 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, - 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, - 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, - 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, - 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, - 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, - 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, - 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, - 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, - 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, - 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, - 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x2A, - 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, - 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, - 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, - 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, - 0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11, - 0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11, - 0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11, - 0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11, - 0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11, - 0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11, - 0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11, - 0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11, - 0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11, - 0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11, - 0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11, - 0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11, - 0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11, - 0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11, - 0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11, - 0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11, - 0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11, - 0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11, - 0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11, - 0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11, - 0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11, - 0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11, - 0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11, - 0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11, - 0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11, - 0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11, - 0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11, - 0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11, - 0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11, - 0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11, - 0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11, - 0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11, - 0x11,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x11, - 0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x18, - 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, - 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x11, - 0x11,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, - 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x11, - 0x11,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, - 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x11, - 0x11,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, - 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x11, - 0x11,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, - 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x11, - 0x11,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, - 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x11, - 0x11,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, - 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x11, - 0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11, - 0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11, - 0x11,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, - 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x11, - 0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11, - 0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11, - 0x11,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, - 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x11, - 0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11, - 0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11, - 0x11,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, - 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x11, - 0x11,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, - 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x11, - 0x11,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, - 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x11, - 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, - 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, - 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, - 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, - 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, - 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, - 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, - 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, - 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, - 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, - 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, - 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, - 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, - 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, - 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, - 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, - 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, - 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, - 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, - 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, - 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, - 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, - 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, - 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, - 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, - 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, - 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, - 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, - 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, - 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, - 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A, - 0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A,0x3A - -}; - -UWord16 const ari_pk_s17_LC_ext[64][18] = -{ - { - 16384, 16368,16337,16231,16143,16115,16059,15916,15793,15710,15586,15472,15367,15302,15201,15107,15020, - 0 - }, - { - 16384, 8983, 8540, 8498, 8485, 4319, 3666, 3594, 3579, 2285, 1908, 1851, 1835, 1326, 1120, 1085, 1074, - 0 - }, - { - 16384, 12022,10039, 9520, 9346, 7347, 5335, 4648, 4382, 3815, 3083, 2728, 2562, 2363, 2050, 1869, 1777, - 0 - }, - { - 16384, 13429,11201,10562,10371, 8231, 5713, 4770, 4441, 3798, 2844, 2359, 2152, 1947, 1614, 1406, 1304, - 0 - }, - { - 16384, 13229,11403,10769,10529, 8415, 6431, 5645, 5311, 4448, 3547, 3176, 3001, 2617, 2181, 1984, 1886, - 0 - }, - { - 16384, 15168,13754,13120,12826,11553, 9705, 8723, 8227, 7675, 6762, 6180, 5842, 5585, 5141, 4816, 4607, - 0 - }, - { - 16384, 14625,12743,12034,11772,10059, 7706, 6652, 6223, 5594, 4594, 4023, 3742, 3501, 3089, 2818, 2664, - 0 - }, - { - 16384, 15275,13679,12951,12652,11158, 8852, 7652, 7121, 6406, 5242, 4542, 4196, 3894, 3398, 3063, 2864, - 0 - }, - { - 16384, 4860, 3338, 3214, 3193, 1428, 676, 571, 547, 356, 222, 189, 180, 139, 102, 89, 84, - 0 - }, - { - 16384, 8357, 5798, 5475, 5410, 3093, 1523, 1227, 1152, 849, 560, 470, 441, 370, 294, 261, 248, - 0 - }, - { - 16384, 15550,14350,13710,13387,12297,10541, 9493, 8929, 8354, 7371, 6696, 6299, 6008, 5491, 5107, 4856, - 0 - }, - { - 16384, 10346, 7298, 6933, 6865, 4052, 1863, 1471, 1381, 1055, 673, 536, 491, 429, 339, 293, 273, - 0 - }, - { - 16384, 11652, 8699, 8030, 7839, 5667, 3460, 2766, 2532, 2093, 1542, 1301, 1203, 1070, 893, 802, 759, - 0 - }, - { - 16384, 15639,14601,14037,13729,12847,11421,10520, 9978, 9521, 8720, 8136, 7750, 7493, 7033, 6676, 6426, - 0 - }, - { - 16384, 12427, 9590, 8715, 8386, 6641, 4708, 3886, 3515, 3071, 2490, 2198, 2052, 1886, 1670, 1549, 1478, - 0 - }, - { - 16384, 13605,10996,10363,10183, 7802, 5032, 4124, 3840, 3267, 2403, 1976, 1804, 1633, 1345, 1171, 1086, - 0 - }, - { - 16384, 15936,15224,14759,14464,13808,12678,11866,11331,10910,10150, 9549, 9122, 8853, 8352, 7938, 7626, - 0 - }, - { - 16384, 16383,16382,14829,14138,14137,14136,12895,12272,10935, 9788, 9082, 8674, 8073, 7508, 7118, 6867, - 0 - }, - { - 16384, 13888,11474,10840,10662, 8335, 5585, 4695, 4411, 3801, 2917, 2506, 2337, 2150, 1847, 1672, 1581, - 0 - }, - { - 16384, 15463,14162,13504,13196,11977,10063, 8978, 8429, 7811, 6768, 6088, 5705, 5406, 4882, 4504, 4266, - 0 - }, - { - 16384, 13764,11941,11367,11151, 9312, 7171, 6301, 5943, 5335, 4430, 3942, 3708, 3466, 3074, 2819, 2679, - 0 - }, - { - 16384, 5179, 3300, 3206, 3197, 1220, 374, 303, 293, 171, 81, 63, 59, 44, 29, 24, 22, - 0 - }, - { - 16384, 16026,15468,15096,14842,14329,13447,12790,12322,11985,11367,10860,10477,10248, 9811, 9443, 9148, - 0 - }, - { - 16384, 12809,11291,10848,10649, 8976, 7199, 6506, 6196, 5657, 4887, 4451, 4219, 3974, 3590, 3365, 3218, - 0 - }, - { - 16384, 16383,16382,15744,15348,15347,15346,14714,14288,13688,13097,12652,12328,11967,11584,11278,11045, - 0 - }, - { - 16384, 15415,14987,14866,14806,13751,13046,12818,12709,12187,11720,11527,11427,11096,10759,10601,10510, - 0 - }, - { - 16384, 5926, 4280, 4090, 4053, 2138, 1120, 947, 903, 632, 413, 353, 334, 264, 198, 174, 166, - 0 - }, - { - 16384, 9206, 6640, 6345, 6291, 3683, 1772, 1423, 1342, 1024, 652, 515, 467, 406, 314, 267, 245, - 0 - }, - { - 16384, 15086,13966,13505,13271,12238,10875,10157, 9763, 9331, 8629, 8155, 7845, 7608, 7198, 6892, 6670, - 0 - }, - { - 16384, 11427, 8599, 8132, 8027, 5406, 3012, 2429, 2270, 1823, 1244, 1006, 920, 814, 654, 564, 524, - 0 - }, - { - 16384, 11561, 8220, 7814, 7737, 4780, 2215, 1731, 1621, 1279, 830, 657, 599, 532, 424, 366, 339, - 0 - }, - { - 16384, 11649, 9374, 8867, 8724, 6398, 4154, 3470, 3253, 2718, 2010, 1695, 1570, 1412, 1172, 1042, 980, - 0 - }, - { - 16384, 13021,10503, 9726, 9443, 7520, 5271, 4369, 4016, 3495, 2741, 2365, 2181, 1990, 1719, 1561, 1478, - 0 - }, - { - 16384, 13815,11388,10605,10316, 8467, 6133, 5175, 4782, 4255, 3466, 3063, 2864, 2688, 2408, 2229, 2125, - 0 - }, - { - 16384, 16175,15807,15536,15338,15006,14402,13919,13549,13312,12871,12491,12182,12010,11681,11390,11143, - 0 - }, - { - 16384, 14310,12047,11336,11110, 9065, 6381, 5318, 4938, 4279, 3272, 2732, 2499, 2284, 1920, 1693, 1574, - 0 - }, - { - 16384, 14765,12824,12096,11834,10003, 7429, 6282, 5841, 5145, 4022, 3402, 3123, 2868, 2426, 2150, 2003, - 0 - }, - { - 16384, 16295,16127,15943,15802,15650,15360,15059,14816,14668,14401,14162,13954,13839,13634,13443,13275, - 0 - }, - { - 16384, 14182,12821,12340,12120,10698, 9040, 8284, 7908, 7378, 6549, 6053, 5772, 5520, 5080, 4785, 4597, - 0 - }, - { - 16384, 15164,13583,12892,12600,11161, 8997, 7888, 7386, 6744, 5673, 5015, 4673, 4391, 3898, 3555, 3349, - 0 - }, - { - 16384, 3758, 2571, 2481, 2467, 988, 478, 412, 397, 245, 154, 133, 127, 95, 69, 61, 58, - 0 - }, - { - 16384, 14805,13193,12553,12285,10706, 8596, 7623, 7178, 6542, 5563, 4996, 4703, 4426, 3967, 3662, 3482, - 0 - }, - { - 16384, 15787,14870,14320,14005,13147,11705,10747,10171, 9651, 8735, 8068, 7629, 7332, 6785, 6361, 6061, - 0 - }, - { - 16384, 7111, 4622, 4304, 4233, 2346, 1174, 938, 870, 659, 455, 389, 365, 316, 260, 236, 226, - 0 - }, - { - 16384, 7146, 4703, 4532, 4512, 2078, 740, 583, 556, 371, 201, 153, 141, 118, 87, 72, 66, - 0 - }, - { - 16384, 9593, 7184, 6853, 6790, 4144, 2206, 1832, 1745, 1320, 878, 741, 697, 599, 476, 424, 401, - 0 - }, - { - 16384, 9209, 5969, 5479, 5351, 3346, 1763, 1382, 1261, 1017, 733, 622, 578, 520, 446, 410, 392, - 0 - }, - { - 16384, 11324, 8681, 8252, 8159, 5450, 3114, 2606, 2473, 1987, 1412, 1211, 1142, 1017, 847, 765, 730, - 0 - }, - { - 16384, 12663,10073, 9527, 9392, 6827, 4204, 3489, 3286, 2713, 1966, 1666, 1554, 1400, 1172, 1051, 994, - 0 - }, - { - 16384, 10413, 7096, 6340, 6115, 4393, 2704, 2156, 1947, 1634, 1254, 1091, 1010, 925, 805, 742, 707, - 0 - }, - { - 16384, 13337,11073,10477,10306, 8045, 5534, 4705, 4438, 3804, 2942, 2530, 2360, 2164, 1850, 1668, 1574, - 0 - }, - { - 16384, 14323,12104,11391,11156, 9183, 6649, 5649, 5287, 4676, 3778, 3302, 3089, 2886, 2548, 2341, 2223, - 0 - }, - { - 16384, 11646, 8435, 7504, 7150, 5603, 3882, 3170, 2853, 2487, 2029, 1791, 1666, 1549, 1386, 1288, 1231, - 0 - }, - { - 16384, 13147,11339,10752,10524, 8775, 6682, 5776, 5398, 4813, 3908, 3406, 3154, 2933, 2554, 2310, 2176, - 0 - }, - { - 16384, 14551,12495,11707,11356, 9962, 8005, 7006, 6500, 6034, 5298, 4839, 4575, 4381, 4057, 3825, 3673, - 0 - }, - { - 16384, 12395, 9526, 9032, 8925, 6130, 3448, 2813, 2649, 2144, 1489, 1231, 1142, 1020, 836, 738, 694, - 0 - }, - { - 16384, 14921,13187,12475,12164,10758, 8775, 7752, 7257, 6727, 5864, 5306, 5004, 4777, 4393, 4119, 3942, - 0 - }, - { - 16384, 2151, 1301, 1276, 1274, 315, 84, 70, 68, 32, 14, 11, 10, 7, 4, 3, 2, - 0 - }, - { - 16384, 16383,16382,13774,13091,13090,13089,11287,10713, 7917, 6052, 5265, 4947, 4161, 3534, 3199, 3039, - 0 - }, - { - 16384, 14374,12331,11688,11474, 9505, 6993, 5998, 5634, 4991, 4008, 3498, 3265, 3036, 2658, 2417, 2285, - 0 - }, - { - 16384, 8798, 5867, 5626, 5593, 2841, 1038, 807, 765, 538, 302, 234, 215, 182, 139, 119, 111, - 0 - }, - { - 16384, 13325,10612,10015, 9860, 7343, 4583, 3802, 3571, 3023, 2269, 1945, 1817, 1670, 1440, 1309, 1243, - 0 - }, - { - 16384, 7741, 5790, 5571, 5528, 3110, 1698, 1464, 1409, 1034, 704, 613, 585, 487, 381, 342, 327, - 0 - }, - { - 16384, 9664, 7506, 7059, 6917, 4820, 3136, 2640, 2455, 2000, 1504, 1297, 1217, 1073, 896, 815, 777, - 0 - } -}; - - -const Word16 Tab_esc_nb[4] = { 0 << (NBITS_CONTEXT+NBITS_RATEQ), - 1 << (NBITS_CONTEXT+NBITS_RATEQ), - 2 << (NBITS_CONTEXT+NBITS_RATEQ), - 3 << (NBITS_CONTEXT+NBITS_RATEQ) - }; - -const Word16 qGains[2][1 << kTcxHmNumGainBits] = -{ - /* GC */ { 1536 /*0.75f Q11*/ }, - /* VC */ { 1229 /*0.6f Q11*/, 2867 /*1.4f Q11*/, 9216 /*4.5f Q11*/, 20480 /*10.0f Q11*/ } -}; - -const Word16 NumRatioBits[2][17] = -{ - /* NB */ - { - 5, 4, 4, 4, 4, 4, 4, 3, 3, 3, 3, 2, 2, 2 - , 2, 2, 2 - }, - - /* WB */ - { - 5, 5, 5, 5, 5, 5, 4, 4, 4, 4, 4, 4, 4, 4 - , 2, 2, 2 - } -}; - -/* 7Q8 */ -const Word16 Ratios_WB_2[32] = - /* 2 */ { 768, 1024, 1280, 1536, 1792, 2048, 2304, 2560, 2816, 3072, 3328, 3584, 3840, 4096, 4352, 4608, 4864, 5120, 5376, 5632, 6144, 6656, 7168, 7680, 8192, 8704, 9216, 9728, 10240, 15360, 16384, 18432 }; -const Word16 Ratios_WB_3[32] = - /* 3 */ { 256, 512, 768, 1024, 1280, 1536, 1792, 2048, 2304, 2560, 3072, 3584, 4096, 4608, 5120, 5632, 6144, 6656, 7168, 7680, 8192, 8704, 9216, 9728, 10240, 11264, 12288, 13824, 15360, 17408, 19968, 20480 }; -const Word16 Ratios_WB_4[32] = - /* 4 */ { 384, 512, 640, 768, 1024, 1280, 1536, 1792, 2048, 2304, 2560, 3072, 3584, 4096, 4608, 5120, 5632, 6144, 6656, 7168, 7680, 8192, 8704, 9216, 9728, 10240, 10752, 11264, 12288, 13312, 13824, 17408 }; -const Word16 Ratios_WB_5[32] = - /* 5 */ { 256, 384, 512, 640, 768, 1024, 1280, 1536, 1792, 2048, 2304, 2560, 2816, 3072, 3328, 3584, 3840, 4096, 4608, 5120, 5632, 6144, 6656, 7168, 7680, 8192, 8704, 9216, 10240, 11264, 12288, 13824 }; -const Word16 Ratios_WB_6[32] = - /* 6 */ { 256, 384, 512, 640, 768, 896, 1024, 1152, 1280, 1408, 1536, 1664, 1792, 1920, 2048, 2304, 2560, 2816, 3072, 3328, 3584, 3840, 4096, 4608, 5120, 5632, 6144, 6656, 7168, 8704, 10240, 10496 }; -const Word16 Ratios_WB_7[32] = - /* 7 */ { 256, 384, 512, 640, 768, 896, 1024, 1152, 1280, 1536, 1792, 2048, 2304, 2560, 2816, 3072, 3328, 3584, 3840, 4096, 4352, 4608, 4864, 5120, 5376, 5760, 6144, 6400, 6912, 7168, 7680, 8960 }; -const Word16 Ratios_WB_8[16] = - /* 8 */ { 128, 256, 384, 512, 640, 768, 896, 1024, 1152, 1280, 1408, 1536, 1792, 2048, 2304, 2560 }; -const Word16 Ratios_WB_9[16] = - /* 9 */ { 256, 512, 640, 768, 1024, 1280, 1536, 1792, 2048, 2304, 2560, 3072, 3840, 4096, 4608, 6912 }; -const Word16 Ratios_WB_10[16] = - /* 10 */ { 256, 384, 512, 640, 768, 896, 1024, 1280, 1536, 2048, 2560, 3840, 4608, 5632, 6144, 6656 }; -const Word16 Ratios_WB_11[16] = - /* 11 */ { 256, 384, 512, 640, 768, 896, 1024, 1280, 1536, 2048, 2560, 3072, 3328, 3584, 4608, 5376 }; -const Word16 Ratios_WB_12[16] = - /* 12 */ { 128, 256, 384, 512, 640, 768, 1024, 1280, 1536, 2048, 2304, 2816, 3072, 3456, 4096, 5120 }; -const Word16 Ratios_WB_13[16] = - /* 13 */ { 128, 256, 384, 512, 640, 768, 1024, 1280, 1536, 1792, 2048, 2560, 2816, 3072, 3584, 5120 }; -const Word16 Ratios_WB_14[16] = - /* 14 */ { 128, 256, 384, 512, 640, 768, 1024, 1152, 1536, 1920, 2304, 2560, 3072, 3584, 3840, 4608 }; -const Word16 Ratios_WB_15[16] = - /* 15 */ { 128, 256, 320, 384, 448, 512, 640, 768, 896, 1024, 1152, 1280, 1536, 2048, 2304, 3584 }; -const Word16 Ratios_WB_16[4] = - /* 16 */ { 128, 256, 512, 1024 }; -const Word16 Ratios_WB_17[4] = - /* 17 */ { 256, 384, 512, 1024 }; -const Word16 Ratios_WB_18[4] = - /* 18 */ { 256, 512, 768, 1024 }; - -/******************************************************************************/ - -/* 7Q8 */ -const Word16 Ratios_NB_2[32] = - /* 2 */ { 768, 1024, 1280, 1536, 1792, 2048, 2304, 2560, 2816, 3072, 3328, 3584, 3840, 4096, 4352, 4608, 4864, 5120, 5376, 5632, 5888, 6144, 6400, 6656, 6912, 7168, 7680, 8192, 8704, 9216, 9728, 10240 }; -const Word16 Ratios_NB_3[16] = - /* 3 */ { 128, 256, 512, 768, 1024, 1280, 1536, 1792, 2048, 2304, 2560, 3072, 4096, 5120, 6144, 7680 }; -const Word16 Ratios_NB_4[16] = - /* 4 */ { 512, 768, 1024, 1280, 1536, 1792, 2048, 2304, 2560, 3072, 3584, 4096, 4608, 5120, 6144, 7680 }; -const Word16 Ratios_NB_5[16] = - /* 5 */ { 512, 768, 1024, 1280, 1536, 1792, 2048, 2304, 2560, 3072, 3584, 4096, 4608, 5120, 6144, 7680 }; -const Word16 Ratios_NB_6[16] = - /* 6 */ { 512, 640, 768, 896, 1024, 1280, 1536, 1792, 2048, 2304, 2560, 3072, 3584, 4096, 4608, 5120 }; -const Word16 Ratios_NB_7[16] = - /* 7 */ { 256, 512, 640, 768, 1024, 1280, 1536, 1792, 2048, 2304, 2560, 3072, 3584, 4096, 4608, 5120 }; -const Word16 Ratios_NB_8[16] = - /* 8 */ { 256, 384, 512, 640, 768, 896, 1024, 1152, 1280, 1536, 1792, 2048, 2304, 2560, 3072, 4096 }; -const Word16 Ratios_NB_9[8] = - /* 9 */ { 256, 512, 768, 1024, 1280, 1536, 2048, 2560 }; -const Word16 Ratios_NB_10[8] = - /* 10 */ { 256, 512, 768, 1024, 1280, 1536, 2048, 2560 }; -const Word16 Ratios_NB_11[8] = - /* 11 */ { 256, 384, 512, 768, 1024, 1280, 1536, 2048 }; -const Word16 Ratios_NB_12[8] = - /* 12 */ { 256, 512, 640, 768, 1024, 1280, 1536, 2048 }; -const Word16 Ratios_NB_13[4] = - /* 13 */ { 256, 512, 768, 1024 }; -const Word16 Ratios_NB_14[4] = - /* 14 */ { 256, 512, 1024, 1536 }; -const Word16 Ratios_NB_15[4] = - /* 15 */ { 256, 512, 768, 1024 }; -const Word16 Ratios_NB_16[4] = - /* 16 */ { 256, 384, 512, 1024 }; -const Word16 Ratios_NB_17[4] = - /* 17 */ { 256, 384, 512, 768 }; -const Word16 Ratios_NB_18[4] = - /* 18 */ { 128, 256, 512, 768 }; - -/******************************************************************************/ - -const Word16 *const Ratios[2][17] = -{ - /* NB */ - { - Ratios_NB_2, - Ratios_NB_3, - Ratios_NB_4, - Ratios_NB_5, - Ratios_NB_6, - Ratios_NB_7, - Ratios_NB_8, - Ratios_NB_9, - Ratios_NB_10, - Ratios_NB_11, - Ratios_NB_12, - Ratios_NB_13, - Ratios_NB_14, - Ratios_NB_15 - , Ratios_NB_16 - , Ratios_NB_17 - , Ratios_NB_18 - }, - - /* WB */ - { - Ratios_WB_2, - Ratios_WB_3, - Ratios_WB_4, - Ratios_WB_5, - Ratios_WB_6, - Ratios_WB_7, - Ratios_WB_8, - Ratios_WB_9, - Ratios_WB_10, - Ratios_WB_11, - Ratios_WB_12, - Ratios_WB_13, - Ratios_WB_14, - Ratios_WB_15 - , Ratios_WB_16 - , Ratios_WB_17 - , Ratios_WB_18 - } -}; - -/*tns_tabels.c*/ - -struct TnsParameters const tnsParametersIGF32kHz_LowBR[1] = -{ - { 600, 3, 237/*1.85f Q7*/, 2458/*0.075f Q15*/ } -}; - -struct TnsParameters const tnsParameters32kHz[2] = -{ - { 4500, 3, 173/*1.35f Q7*/, 983/*0.0300f Q15*/ }, - { 600, 1, 224/*1.75f Q7*/, 2048/*0.0625f Q15*/ } -}; - -struct TnsParameters const tnsParameters32kHz_grouped[2] = -{ - { 8400, 3, 176/*1.375f Q7*/, 1024/*0.03125f Q15*/ }, - { 800, 3, 176/*1.375f Q7*/, 1024/*0.03125f Q15*/ } -}; - - -/* Tuning for Wide Band 16kHz */ -struct TnsParameters const tnsParameters16kHz[1] = -{ - { 600, 3, 192/*1.5f Q7*/, 1638/*0.05f Q15*/ } -}; - -struct TnsParameters const tnsParameters16kHz_grouped[2] = -{ - { 4400, 3, 192/*1.5f Q7*/, 1638/*0.05f Q15*/ }, - { 800, 3, 192/*1.5f Q7*/, 1638/*0.05f Q15*/ } -}; - -struct TnsParameters const tnsParameters48kHz_grouped[2] = -{ - { 10400, 3, 176/*1.375f Q7*/, 1024/*0.03125f Q15*/ }, - { 800, 3, 176/*1.375f Q7*/, 1024/*0.03125f Q15*/ } -}; - -const Word16 tnsAcfWindow[TNS_MAX_FILTER_ORDER] = -{ - 32696/*0.997803f Q15*/, 32480/*0.991211f Q15*/, 32120/*0.980225f Q15*/, 31616/*0.964844f Q15*/, 30968/*0.945068f Q15*/, 30176/*0.920898f Q15*/, 29240/*0.892334f Q15*/, 28160/*0.859375f Q15*/ -}; - -/**********************************************************************/ -/* Definition of the mapping between TNS parameters and a bitstream */ -/**********************************************************************/ - -/* Helper structures for hufmann table coding */ -const Coding codesTnsCoeff0TCX20[] = -{ - { -8+INDEX_SHIFT, 609, 11 }, /* 01001100001 */ - { -7+INDEX_SHIFT, 305, 10 }, /* 0100110001 */ - { -6+INDEX_SHIFT, 77, 8 }, /* 01001101 */ - { -5+INDEX_SHIFT, 39, 7 }, /* 0100111 */ - { -4+INDEX_SHIFT, 8, 5 }, /* 01000 */ - { -3+INDEX_SHIFT, 21, 5 }, /* 10101 */ - { -2+INDEX_SHIFT, 11, 4 }, /* 1011 */ - { -1+INDEX_SHIFT, 3, 3 }, /* 011 */ - { 0+INDEX_SHIFT, 3, 2 }, /* 11 */ - { 1+INDEX_SHIFT, 0, 2 }, /* 00 */ - { 2+INDEX_SHIFT, 4, 3 }, /* 100 */ - { 3+INDEX_SHIFT, 5, 4 }, /* 0101 */ - { 4+INDEX_SHIFT, 20, 5 }, /* 10100 */ - { 5+INDEX_SHIFT, 18, 6 }, /* 010010 */ - { 6+INDEX_SHIFT, 153, 9 }, /* 010011001 */ - { 7+INDEX_SHIFT, 608, 11 } /* 01001100000 */ -}; - -const Coding codesTnsCoeff0TCX10[] = -{ - { -8+INDEX_SHIFT, 441, 9 }, /* 110111001 */ - { -7+INDEX_SHIFT, 111, 7 }, /* 1101111 */ - { -6+INDEX_SHIFT, 8, 4 }, /* 1000 */ - { -5+INDEX_SHIFT, 9, 4 }, /* 1001 */ - { -4+INDEX_SHIFT, 14, 4 }, /* 1110 */ - { -3+INDEX_SHIFT, 15, 4 }, /* 1111 */ - { -2+INDEX_SHIFT, 3, 3 }, /* 011 */ - { -1+INDEX_SHIFT, 5, 3 }, /* 101 */ - { 0+INDEX_SHIFT, 0, 2 }, /* 00 */ - { 1+INDEX_SHIFT, 2, 3 }, /* 010 */ - { 2+INDEX_SHIFT, 12, 4 }, /* 1100 */ - { 3+INDEX_SHIFT, 26, 5 }, /* 11010 */ - { 4+INDEX_SHIFT, 54, 6 }, /* 110110 */ - { 5+INDEX_SHIFT, 221, 8 }, /* 11011101 */ - { 6+INDEX_SHIFT, 881, 10 }, /* 1101110001 */ - { 7+INDEX_SHIFT, 880, 10 } /* 1101110000 */ -}; - -const Coding codesTnsCoeff1TCX20[] = -{ - { -8+INDEX_SHIFT, 30018, 15 }, /* 111010101000010 */ - { -7+INDEX_SHIFT, 30019, 15 }, /* 111010101000011 */ - { -6+INDEX_SHIFT, 7505, 13 }, /* 1110101010001 */ - { -5+INDEX_SHIFT, 3753, 12 }, /* 111010101001 */ - { -4+INDEX_SHIFT, 939, 10 }, /* 1110101011 */ - { -3+INDEX_SHIFT, 235, 8 }, /* 11101011 */ - { -2+INDEX_SHIFT, 28, 5 }, /* 11100 */ - { -1+INDEX_SHIFT, 6, 3 }, /* 110 */ - { 0+INDEX_SHIFT, 0, 1 }, /* 0 */ - { 1+INDEX_SHIFT, 2, 2 }, /* 10 */ - { 2+INDEX_SHIFT, 15, 4 }, /* 1111 */ - { 3+INDEX_SHIFT, 59, 6 }, /* 111011 */ - { 4+INDEX_SHIFT, 116, 7 }, /* 1110100 */ - { 5+INDEX_SHIFT, 468, 9 }, /* 111010100 */ - { 6+INDEX_SHIFT, 1877, 11 }, /* 11101010101 */ - { 7+INDEX_SHIFT, 15008, 14 } /* 11101010100000 */ -}; - -const Coding codesTnsCoeff1TCX10[] = -{ - { -8+INDEX_SHIFT, 2818, 12 }, /* 101100000010 */ - { -7+INDEX_SHIFT, 2819, 12 }, /* 101100000011 */ - { -6+INDEX_SHIFT, 705, 10 }, /* 1011000001 */ - { -5+INDEX_SHIFT, 353, 9 }, /* 101100001 */ - { -4+INDEX_SHIFT, 177, 8 }, /* 10110001 */ - { -3+INDEX_SHIFT, 45, 6 }, /* 101101 */ - { -2+INDEX_SHIFT, 10, 4 }, /* 1010 */ - { -1+INDEX_SHIFT, 3, 3 }, /* 011 */ - { 0+INDEX_SHIFT, 6, 3 }, /* 110 */ - { 1+INDEX_SHIFT, 0, 2 }, /* 00 */ - { 2+INDEX_SHIFT, 7, 3 }, /* 111 */ - { 3+INDEX_SHIFT, 4, 3 }, /* 100 */ - { 4+INDEX_SHIFT, 2, 3 }, /* 010 */ - { 5+INDEX_SHIFT, 23, 5 }, /* 10111 */ - { 6+INDEX_SHIFT, 89, 7 }, /* 1011001 */ - { 7+INDEX_SHIFT, 1408, 11 } /* 10110000000 */ -}; - -const Coding codesTnsCoeff2TCX20[] = -{ - { -8+INDEX_SHIFT, 13312, 14 }, /* 11010000000000 */ - { -7+INDEX_SHIFT, 13313, 14 }, /* 11010000000001 */ - { -6+INDEX_SHIFT, 3329, 12 }, /* 110100000001 */ - { -5+INDEX_SHIFT, 833, 10 }, /* 1101000001 */ - { -4+INDEX_SHIFT, 209, 8 }, /* 11010001 */ - { -3+INDEX_SHIFT, 53, 6 }, /* 110101 */ - { -2+INDEX_SHIFT, 12, 4 }, /* 1100 */ - { -1+INDEX_SHIFT, 2, 2 }, /* 10 */ - { 0+INDEX_SHIFT, 0, 1 }, /* 0 */ - { 1+INDEX_SHIFT, 7, 3 }, /* 111 */ - { 2+INDEX_SHIFT, 27, 5 }, /* 11011 */ - { 3+INDEX_SHIFT, 105, 7 }, /* 1101001 */ - { 4+INDEX_SHIFT, 417, 9 }, /* 110100001 */ - { 5+INDEX_SHIFT, 1665, 11 }, /* 11010000001 */ - { 6+INDEX_SHIFT, 13314, 14 }, /* 11010000000010 */ - { 7+INDEX_SHIFT, 13315, 14 } /* 11010000000011 */ -}; - -const Coding codesTnsCoeff2TCX10[] = -{ - { -8+INDEX_SHIFT, 512, 12 }, /* 001000000000 */ - { -7+INDEX_SHIFT, 513, 12 }, /* 001000000001 */ - { -6+INDEX_SHIFT, 65, 9 }, /* 001000001 */ - { -5+INDEX_SHIFT, 17, 7 }, /* 0010001 */ - { -4+INDEX_SHIFT, 5, 5 }, /* 00101 */ - { -3+INDEX_SHIFT, 0, 3 }, /* 000 */ - { -2+INDEX_SHIFT, 6, 3 }, /* 110 */ - { -1+INDEX_SHIFT, 1, 2 }, /* 01 */ - { 0+INDEX_SHIFT, 2, 2 }, /* 10 */ - { 1+INDEX_SHIFT, 7, 3 }, /* 111 */ - { 2+INDEX_SHIFT, 3, 4 }, /* 0011 */ - { 3+INDEX_SHIFT, 9, 6 }, /* 001001 */ - { 4+INDEX_SHIFT, 33, 8 }, /* 00100001 */ - { 5+INDEX_SHIFT, 129, 10 }, /* 0010000001 */ - { 6+INDEX_SHIFT, 514, 12 }, /* 001000000010 */ - { 7+INDEX_SHIFT, 515, 12 } /* 001000000011 */ -}; - -const Coding codesTnsCoeff3TCX20[] = -{ - { -8+INDEX_SHIFT, 13318, 14 }, /* 11010000000110 */ - { -7+INDEX_SHIFT, 13319, 14 }, /* 11010000000111 */ - { -6+INDEX_SHIFT, 6656, 13 }, /* 1101000000000 */ - { -5+INDEX_SHIFT, 1665, 11 }, /* 11010000001 */ - { -4+INDEX_SHIFT, 417, 9 }, /* 110100001 */ - { -3+INDEX_SHIFT, 105, 7 }, /* 1101001 */ - { -2+INDEX_SHIFT, 27, 5 }, /* 11011 */ - { -1+INDEX_SHIFT, 7, 3 }, /* 111 */ - { 0+INDEX_SHIFT, 0, 1 }, /* 0 */ - { 1+INDEX_SHIFT, 2, 2 }, /* 10 */ - { 2+INDEX_SHIFT, 12, 4 }, /* 1100 */ - { 3+INDEX_SHIFT, 53, 6 }, /* 110101 */ - { 4+INDEX_SHIFT, 209, 8 }, /* 11010001 */ - { 5+INDEX_SHIFT, 833, 10 }, /* 1101000001 */ - { 6+INDEX_SHIFT, 6657, 13 }, /* 1101000000001 */ - { 7+INDEX_SHIFT, 6658, 13 } /* 1101000000010 */ -}; - -const Coding codesTnsCoeff3TCX10[] = -{ - { -8+INDEX_SHIFT, 1284, 12 }, /* 010100000100 */ - { -7+INDEX_SHIFT, 1285, 12 }, /* 010100000101 */ - { -6+INDEX_SHIFT, 1286, 12 }, /* 010100000110 */ - { -5+INDEX_SHIFT, 1287, 12 }, /* 010100000111 */ - { -4+INDEX_SHIFT, 161, 9 }, /* 010100001 */ - { -3+INDEX_SHIFT, 41, 7 }, /* 0101001 */ - { -2+INDEX_SHIFT, 11, 5 }, /* 01011 */ - { -1+INDEX_SHIFT, 0, 2 }, /* 00 */ - { 0+INDEX_SHIFT, 2, 2 }, /* 10 */ - { 1+INDEX_SHIFT, 3, 2 }, /* 11 */ - { 2+INDEX_SHIFT, 3, 3 }, /* 011 */ - { 3+INDEX_SHIFT, 4, 4 }, /* 0100 */ - { 4+INDEX_SHIFT, 21, 6 }, /* 010101 */ - { 5+INDEX_SHIFT, 81, 8 }, /* 01010001 */ - { 6+INDEX_SHIFT, 640, 11 }, /* 01010000000 */ - { 7+INDEX_SHIFT, 641, 11 } /* 01010000001 */ -}; - -const Coding codesTnsCoeff4TCX20[] = -{ - { -8+INDEX_SHIFT, 13318, 14 }, /* 11010000000110 */ - { -7+INDEX_SHIFT, 13319, 14 }, /* 11010000000111 */ - { -6+INDEX_SHIFT, 6656, 13 }, /* 1101000000000 */ - { -5+INDEX_SHIFT, 833, 10 }, /* 1101000001 */ - { -4+INDEX_SHIFT, 209, 8 }, /* 11010001 */ - { -3+INDEX_SHIFT, 53, 6 }, /* 110101 */ - { -2+INDEX_SHIFT, 12, 4 }, /* 1100 */ - { -1+INDEX_SHIFT, 2, 2 }, /* 10 */ - { 0+INDEX_SHIFT, 0, 1 }, /* 0 */ - { 1+INDEX_SHIFT, 7, 3 }, /* 111 */ - { 2+INDEX_SHIFT, 27, 5 }, /* 11011 */ - { 3+INDEX_SHIFT, 105, 7 }, /* 1101001 */ - { 4+INDEX_SHIFT, 417, 9 }, /* 110100001 */ - { 5+INDEX_SHIFT, 1665, 11 }, /* 11010000001 */ - { 6+INDEX_SHIFT, 6657, 13 }, /* 1101000000001 */ - { 7+INDEX_SHIFT, 6658, 13 } /* 1101000000010 */ -}; - -const Coding codesTnsCoeff4TCX10[] = -{ - { -8+INDEX_SHIFT, 20, 12 }, /* 000000010100 */ - { -7+INDEX_SHIFT, 21, 12 }, /* 000000010101 */ - { -6+INDEX_SHIFT, 22, 12 }, /* 000000010110 */ - { -5+INDEX_SHIFT, 3, 9 }, /* 000000011 */ - { -4+INDEX_SHIFT, 1, 7 }, /* 0000001 */ - { -3+INDEX_SHIFT, 1, 5 }, /* 00001 */ - { -2+INDEX_SHIFT, 1, 3 }, /* 001 */ - { -1+INDEX_SHIFT, 2, 2 }, /* 10 */ - { 0+INDEX_SHIFT, 3, 2 }, /* 11 */ - { 1+INDEX_SHIFT, 1, 2 }, /* 01 */ - { 2+INDEX_SHIFT, 1, 4 }, /* 0001 */ - { 3+INDEX_SHIFT, 1, 6 }, /* 000001 */ - { 4+INDEX_SHIFT, 0, 8 }, /* 00000000 */ - { 5+INDEX_SHIFT, 23, 12 }, /* 000000010111 */ - { 6+INDEX_SHIFT, 8, 11 }, /* 00000001000 */ - { 7+INDEX_SHIFT, 9, 11 } /* 00000001001 */ -}; - -const Coding codesTnsCoeff5[] = -{ - { -8+INDEX_SHIFT, 6788, 13 }, /* 1101010000100 */ - { -7+INDEX_SHIFT, 6789, 13 }, /* 1101010000101 */ - { -6+INDEX_SHIFT, 6790, 13 }, /* 1101010000110 */ - { -5+INDEX_SHIFT, 849, 10 }, /* 1101010001 */ - { -4+INDEX_SHIFT, 213, 8 }, /* 11010101 */ - { -3+INDEX_SHIFT, 107, 7 }, /* 1101011 */ - { -2+INDEX_SHIFT, 27, 5 }, /* 11011 */ - { -1+INDEX_SHIFT, 7, 3 }, /* 111 */ - { 0+INDEX_SHIFT, 0, 1 }, /* 0 */ - { 1+INDEX_SHIFT, 2, 2 }, /* 10 */ - { 2+INDEX_SHIFT, 12, 4 }, /* 1100 */ - { 3+INDEX_SHIFT, 52, 6 }, /* 110100 */ - { 4+INDEX_SHIFT, 425, 9 }, /* 110101001 */ - { 5+INDEX_SHIFT, 6791, 13 }, /* 1101010000111 */ - { 6+INDEX_SHIFT, 3392, 12 }, /* 110101000000 */ - { 7+INDEX_SHIFT, 3393, 12 } /* 110101000001 */ -}; - -const Coding codesTnsCoeff6[] = -{ - { -8+INDEX_SHIFT, 4, 12 }, /* 000000000100 */ - { -7+INDEX_SHIFT, 5, 12 }, /* 000000000101 */ - { -6+INDEX_SHIFT, 6, 12 }, /* 000000000110 */ - { -5+INDEX_SHIFT, 1, 9 }, /* 000000001 */ - { -4+INDEX_SHIFT, 1, 7 }, /* 0000001 */ - { -3+INDEX_SHIFT, 1, 5 }, /* 00001 */ - { -2+INDEX_SHIFT, 1, 3 }, /* 001 */ - { -1+INDEX_SHIFT, 2, 2 }, /* 10 */ - { 0+INDEX_SHIFT, 3, 2 }, /* 11 */ - { 1+INDEX_SHIFT, 1, 2 }, /* 01 */ - { 2+INDEX_SHIFT, 1, 4 }, /* 0001 */ - { 3+INDEX_SHIFT, 1, 6 }, /* 000001 */ - { 4+INDEX_SHIFT, 1, 8 }, /* 00000001 */ - { 5+INDEX_SHIFT, 7, 12 }, /* 000000000111 */ - { 6+INDEX_SHIFT, 0, 11 }, /* 00000000000 */ - { 7+INDEX_SHIFT, 1, 11 } /* 00000000001 */ -}; - -const Coding codesTnsCoeff7[] = -{ - { -8+INDEX_SHIFT, 14, 11 }, /* 00000001110 */ - { -7+INDEX_SHIFT, 15, 11 }, /* 00000001111 */ - { -6+INDEX_SHIFT, 0, 10 }, /* 0000000000 */ - { -5+INDEX_SHIFT, 1, 10 }, /* 0000000001 */ - { -4+INDEX_SHIFT, 1, 7 }, /* 0000001 */ - { -3+INDEX_SHIFT, 1, 5 }, /* 00001 */ - { -2+INDEX_SHIFT, 1, 4 }, /* 0001 */ - { -1+INDEX_SHIFT, 1, 2 }, /* 01 */ - { 0+INDEX_SHIFT, 2, 10 }, /* 0000000010 */ - { 1+INDEX_SHIFT, 1, 1 }, /* 1 */ - { 2+INDEX_SHIFT, 1, 3 }, /* 001 */ - { 3+INDEX_SHIFT, 1, 6 }, /* 000001 */ - { 4+INDEX_SHIFT, 3, 10 }, /* 0000000011 */ - { 5+INDEX_SHIFT, 4, 10 }, /* 0000000100 */ - { 6+INDEX_SHIFT, 5, 10 }, /* 0000000101 */ - { 7+INDEX_SHIFT, 6, 10 } /* 0000000110 */ -}; - -const Coding codesTnsCoeff456[] = -{ - { -8+INDEX_SHIFT, 516, 12 }, /* 001000000100 */ - { -7+INDEX_SHIFT, 517, 12 }, /* 001000000101 */ - { -6+INDEX_SHIFT, 518, 12 }, /* 001000000110 */ - { -5+INDEX_SHIFT, 65, 9 }, /* 001000001 */ - { -4+INDEX_SHIFT, 17, 7 }, /* 0010001 */ - { -3+INDEX_SHIFT, 5, 5 }, /* 00101 */ - { -2+INDEX_SHIFT, 3, 4 }, /* 0011 */ - { -1+INDEX_SHIFT, 1, 2 }, /* 01 */ - { 0+INDEX_SHIFT, 3, 2 }, /* 11 */ - { 1+INDEX_SHIFT, 2, 2 }, /* 10 */ - { 2+INDEX_SHIFT, 0, 3 }, /* 000 */ - { 3+INDEX_SHIFT, 9, 6 }, /* 001001 */ - { 4+INDEX_SHIFT, 33, 8 }, /* 00100001 */ - { 5+INDEX_SHIFT, 519, 12 }, /* 001000000111 */ - { 6+INDEX_SHIFT, 256, 11 }, /* 00100000000 */ - { 7+INDEX_SHIFT, 257, 11 } /* 00100000001 */ -}; - -const Coding codesTnsCoeff0WBTCX20[] = -{ - { -8+INDEX_SHIFT, 225, 10 }, /* 0011100001 */ - { -7+INDEX_SHIFT, 113, 9 }, /* 001110001 */ - { -6+INDEX_SHIFT, 29, 7 }, /* 0011101 */ - { -5+INDEX_SHIFT, 15, 6 }, /* 001111 */ - { -4+INDEX_SHIFT, 2, 4 }, /* 0010 */ - { -3+INDEX_SHIFT, 0, 3 }, /* 000 */ - { -2+INDEX_SHIFT, 13, 4 }, /* 1101 */ - { -1+INDEX_SHIFT, 2, 3 }, /* 010 */ - { 0+INDEX_SHIFT, 5, 3 }, /* 101 */ - { 1+INDEX_SHIFT, 3, 3 }, /* 011 */ - { 2+INDEX_SHIFT, 4, 3 }, /* 100 */ - { 3+INDEX_SHIFT, 7, 3 }, /* 111 */ - { 4+INDEX_SHIFT, 12, 4 }, /* 1100 */ - { 5+INDEX_SHIFT, 6, 5 }, /* 00110 */ - { 6+INDEX_SHIFT, 57, 8 }, /* 00111001 */ - { 7+INDEX_SHIFT, 224, 10 } /* 0011100000 */ -}; - -const Coding codesTnsCoeff1WBTCX20[] = -{ - { -8+INDEX_SHIFT, 512, 12 }, /* 001000000000 */ - { -7+INDEX_SHIFT, 513, 12 }, /* 001000000001 */ - { -6+INDEX_SHIFT, 514, 12 }, /* 001000000010 */ - { -5+INDEX_SHIFT, 65, 9 }, /* 001000001 */ - { -4+INDEX_SHIFT, 17, 7 }, /* 0010001 */ - { -3+INDEX_SHIFT, 5, 5 }, /* 00101 */ - { -2+INDEX_SHIFT, 0, 3 }, /* 000 */ - { -1+INDEX_SHIFT, 2, 3 }, /* 010 */ - { 0+INDEX_SHIFT, 3, 2 }, /* 11 */ - { 1+INDEX_SHIFT, 2, 2 }, /* 10 */ - { 2+INDEX_SHIFT, 3, 3 }, /* 011 */ - { 3+INDEX_SHIFT, 3, 4 }, /* 0011 */ - { 4+INDEX_SHIFT, 9, 6 }, /* 001001 */ - { 5+INDEX_SHIFT, 33, 8 }, /* 00100001 */ - { 6+INDEX_SHIFT, 129, 10 }, /* 0010000001 */ - { 7+INDEX_SHIFT, 515, 12 } /* 001000000011 */ -}; - -const Coding codesTnsCoeff2WB[] = -{ - { -8+INDEX_SHIFT, 5632, 13 }, /* 1011000000000 */ - { -7+INDEX_SHIFT, 5633, 13 }, /* 1011000000001 */ - { -6+INDEX_SHIFT, 1409, 11 }, /* 10110000001 */ - { -5+INDEX_SHIFT, 353, 9 }, /* 101100001 */ - { -4+INDEX_SHIFT, 89, 7 }, /* 1011001 */ - { -3+INDEX_SHIFT, 23, 5 }, /* 10111 */ - { -2+INDEX_SHIFT, 4, 3 }, /* 100 */ - { -1+INDEX_SHIFT, 0, 2 }, /* 00 */ - { 0+INDEX_SHIFT, 3, 2 }, /* 11 */ - { 1+INDEX_SHIFT, 1, 2 }, /* 01 */ - { 2+INDEX_SHIFT, 10, 4 }, /* 1010 */ - { 3+INDEX_SHIFT, 45, 6 }, /* 101101 */ - { 4+INDEX_SHIFT, 177, 8 }, /* 10110001 */ - { 5+INDEX_SHIFT, 705, 10 }, /* 1011000001 */ - { 6+INDEX_SHIFT, 5634, 13 }, /* 1011000000010 */ - { 7+INDEX_SHIFT, 5635, 13 } /* 1011000000011 */ -}; - -const Coding codesTnsCoeff3WB[] = -{ - { -8+INDEX_SHIFT, 5638, 13 }, /* 1011000000110 */ - { -7+INDEX_SHIFT, 5639, 13 }, /* 1011000000111 */ - { -6+INDEX_SHIFT, 2816, 12 }, /* 101100000000 */ - { -5+INDEX_SHIFT, 353, 9 }, /* 101100001 */ - { -4+INDEX_SHIFT, 177, 8 }, /* 10110001 */ - { -3+INDEX_SHIFT, 45, 6 }, /* 101101 */ - { -2+INDEX_SHIFT, 10, 4 }, /* 1010 */ - { -1+INDEX_SHIFT, 0, 2 }, /* 00 */ - { 0+INDEX_SHIFT, 3, 2 }, /* 11 */ - { 1+INDEX_SHIFT, 1, 2 }, /* 01 */ - { 2+INDEX_SHIFT, 4, 3 }, /* 100 */ - { 3+INDEX_SHIFT, 23, 5 }, /* 10111 */ - { 4+INDEX_SHIFT, 89, 7 }, /* 1011001 */ - { 5+INDEX_SHIFT, 705, 10 }, /* 1011000001 */ - { 6+INDEX_SHIFT, 2817, 12 }, /* 101100000001 */ - { 7+INDEX_SHIFT, 2818, 12 } /* 101100000010 */ -}; - -Word16 const nTnsCoeffCodes = sizeof(codesTnsCoeff0TCX20)/sizeof(codesTnsCoeff0TCX20[0]); - -const Coding * codesTnsCoeffSWBTCX20[] = { codesTnsCoeff0TCX20, codesTnsCoeff1TCX20, codesTnsCoeff2TCX20, codesTnsCoeff3TCX20, codesTnsCoeff4TCX20, codesTnsCoeff5, codesTnsCoeff6, codesTnsCoeff7 }; -const Coding * codesTnsCoeffSWBTCX10[] = { codesTnsCoeff0TCX10, codesTnsCoeff1TCX10, codesTnsCoeff2TCX10, codesTnsCoeff3TCX10, codesTnsCoeff4TCX10, codesTnsCoeff5, codesTnsCoeff6, codesTnsCoeff7 }; -const Coding * codesTnsCoeffWBTCX20[] = { codesTnsCoeff0WBTCX20, codesTnsCoeff1WBTCX20, codesTnsCoeff2WB, codesTnsCoeff3WB, codesTnsCoeff456, codesTnsCoeff456, codesTnsCoeff456, codesTnsCoeff7 }; - -Word16 const nTnsCoeffTables = sizeof(codesTnsCoeffSWBTCX20)/sizeof(codesTnsCoeffSWBTCX20[0]); - -const Coding codesTnsOrderTCX20[] = -{ - { 1, 0, 2 }, /* 00 */ - { 2, 40, 6 }, /* 101000 */ - { 3, 41, 6 }, /* 101001 */ - { 4, 21, 5 }, /* 10101 */ - { 5, 11, 4 }, /* 1011 */ - { 6, 4, 3 }, /* 100 */ - { 7, 1, 2 }, /* 01 */ - { 8, 3, 2 } /* 11 */ -}; - -const Coding codesTnsOrderTCX10[] = -{ - { 1, 0, 3 }, /* 000 */ - { 2, 16, 5 }, /* 10000 */ - { 3, 17, 5 }, /* 10001 */ - { 4, 9, 4 }, /* 1001 */ - { 5, 1, 3 }, /* 001 */ - { 6, 5, 3 }, /* 101 */ - { 7, 1, 2 }, /* 01 */ - { 8, 3, 2 } /* 11 */ -}; - -const Coding codesTnsOrder[] = -{ - { 1, 96, 7 }, /* 1100000 */ - { 2, 97, 7 }, /* 1100001 */ - { 3, 49, 6 }, /* 110001 */ - { 4, 25, 5 }, /* 11001 */ - { 5, 13, 4 }, /* 1101 */ - { 6, 7, 3 }, /* 111 */ - { 7, 2, 2 }, /* 10 */ - { 8, 0, 1 } /* 0 */ -}; - -Word16 const nTnsOrderCodes = sizeof(codesTnsOrder)/sizeof(codesTnsOrder[0]); - -ParamsBitMap const tnsSWBTCX20FilterCoeffBitMap[1] = -{ - { - 1, - { - { 0, GetSWBTCX20TnsFilterCoeffBits, TRUE, GetTnsFilterCoeff, SetTnsFilterCoeff, EncodeSWBTCX20TnsFilterCoeff, DecodeSWBTCX20TnsFilterCoeff, NULL } /* TNS filter coefficients */ - } - } -}; - -ParamsBitMap const tnsSWBTCX10FilterCoeffBitMap[1] = -{ - { - 1, - { - { 0, GetSWBTCX10TnsFilterCoeffBits, TRUE, GetTnsFilterCoeff, SetTnsFilterCoeff, EncodeSWBTCX10TnsFilterCoeff, DecodeSWBTCX10TnsFilterCoeff, NULL } /* TNS filter coefficients */ - } - } -}; - -ParamsBitMap tnsSWBTCX20FilterBitMap[1] = -{ - { - 1, - { - { 0, GetTnsFilterOrderBitsSWBTCX20, FALSE, GetTnsFilterOrder, SetTnsFilterOrder, EncodeTnsFilterOrderSWBTCX20, DecodeTnsFilterOrderSWBTCX20, tnsSWBTCX20FilterCoeffBitMap } /* TNS filter order */ - } - } -}; - -ParamsBitMap tnsSWBTCX10FilterBitMap[1] = -{ - { - 1, - { - { 0, GetTnsFilterOrderBitsSWBTCX10, FALSE, GetTnsFilterOrder, SetTnsFilterOrder, EncodeTnsFilterOrderSWBTCX10, DecodeTnsFilterOrderSWBTCX10, tnsSWBTCX10FilterCoeffBitMap } /* TNS filter order */ - } - } -}; - -ParamsBitMap const tnsSWBTCX20BitMap[1] = -{ - { - 1, - { - { 1, NULL, FALSE, GetNumOfTnsFilters, SetNumOfTnsFilters, NULL, NULL, tnsSWBTCX20FilterBitMap } /* Number of TNS filters */ - } - } -}; - -/* For storing/reading bits in SWB/FB mode */ -ParamsBitMap const tnsEnabledSWBTCX20BitMap[1] = -{ - { - 1, - { - { 1, NULL, TRUE, GetTnsEnabled, SetTnsEnabled, NULL, NULL, tnsSWBTCX20BitMap } /* TNS Enabled/Disable */ - } - } -}; - -ParamsBitMap const tnsSWBTCX10BitMap[1] = -{ - { - 1, - { - { 1, NULL, FALSE, GetNumOfTnsFilters, SetNumOfTnsFilters, NULL, NULL, tnsSWBTCX10FilterBitMap } /* Number of TNS filters */ - } - } -}; - -/* For storing/reading bits in SWB/FB mode */ -ParamsBitMap const tnsEnabledSWBTCX10BitMap[1] = -{ - { - 1, - { - { 1, NULL, TRUE, GetTnsEnabled, SetTnsEnabled, NULL, NULL, tnsSWBTCX10BitMap } /* TNS Enabled/Disable */ - } - } -}; - -ParamsBitMap const tnsWBTCX20FilterCoeffBitMap[1] = -{ - { - 1, - { - { 0, GetWBTCX20TnsFilterCoeffBits, TRUE, GetTnsFilterCoeff, SetTnsFilterCoeff, EncodeWBTCX20TnsFilterCoeff, DecodeWBTCX20TnsFilterCoeff, NULL } /* TNS filter coefficients */ - } - } -}; - -ParamsBitMap const tnsWBTCX20FilterBitMap[1] = -{ - { - 1, - { - { 0, GetTnsFilterOrderBits, FALSE, GetTnsFilterOrder, SetTnsFilterOrder, EncodeTnsFilterOrder, DecodeTnsFilterOrder, tnsWBTCX20FilterCoeffBitMap } /* TNS filter order */ - } - } -}; - - -/* For storing/reading bits in WB mode */ -ParamsBitMap const tnsEnabledWBTCX20BitMap[1] = -{ - { - 1, - { - { 1, NULL, TRUE, GetTnsEnabledSingleFilter, SetTnsEnabledSingleFilter, NULL, NULL, tnsWBTCX20FilterBitMap } /* TNS Enabled/Disable */ - } - } -}; - - -/** - * 4 bit resolution TNS coefficients. - */ -const Word16 tnsCoeff4[16]= -{ - -32628/*-0.99573418F Q15*/, /* = sin(-8*(PI/2.0)/(8 + 0.5)) */ - -31517/*-0.96182564F Q15*/, /* = sin(-7*(PI/2.0)/(8 + 0.5)) */ - -29333/*-0.89516329F Q15*/, - -26149/*-0.79801723F Q15*/, - -22076/*-0.67369564F Q15*/, - -17250/*-0.52643216F Q15*/, - -11837/*-0.36124167F Q15*/, - -6021/*-0.18374952F Q15*/, /* = sin(-1*(PI/2.0)/(8 + 0.5)) */ - 0/* 0.00000000F Q15*/, /* = sin(0*(PI/2.0)/(8 + 0.5)) */ - 6813/* 0.20791169F Q15*/, /* = sin(1*(PI/2.0)/(8 - 0.5)) */ - 13328/* 0.40673664F Q15*/, - 19261/* 0.58778525F Q15*/, - 24351/* 0.74314483F Q15*/, - 28378/* 0.86602540F Q15*/, - 31164/* 0.95105652F Q15*/, /* = sin(6*(PI/2.0)/(8 - 0.5)) */ - 32588/* 0.99452190F Q15*/ /* = sin(7*(PI/2.0)/(8 - 0.5)) */ -}; - -/*bits_alloc_tables.c*/ - - -/*NRG MODE*/ -/* NRG mode */ -const Word16 ACELP_NRG_MODE[RATE_MODE_MAX][BANDWIDTH_MODE_MAX][ACELP_MODE_MAX+RF_MODE_MAX] = -{ - {{0,0,1,1,0,0,0,0},{2,2,1,1,0,0,0,0}}, - {{1,1,1,1,0,0,0,0},{1,1,1,1,1,1,1,0}}, -}; - -/* NRG bits : (0/2/3 bits) */ -const Word16 ACELP_NRG_BITS[3] = -{ - 0, - 3, - 4 -}; - -/*LTP MODE*/ -const Word16 ACELP_LTP_MODE[RATE_MODE_MAX][BANDWIDTH_MODE_MAX][ACELP_MODE_MAX+RF_MODE_MAX] = -{ - {{0,0,1,2,0,0,0,0},{0,0,1,2,0,0,0,0}}, - {{4,4,3,4,0,0,0,0},{4,4,3,4,8,0,9,0}}, -}; - -/*LTP BITS*/ -const Word16 ACELP_LTP_BITS_SFR[8+RF_MODE_MAX][5] = -{ - {0,0,0,0,0}, - {8,4,4,4,4}, - {8,5,8,5,5}, - {9,6,6,6,6}, - {9,6,9,6,6}, - {8,5,5,5,5}, - {8,5,8,5,5}, - {8,0,0,0,0}, - {8,5,5,5,5}, /* All-pred mode in RF, rf_frame_type = 0 */ - {8,4,4,4,0}, /* Gen-pred mode in RF, rf_frame_type = 2 */ -}; - - -/*LTF MODE: 0 no filtering, 1 filtering, 2 adaptive*/ -const Word16 ACELP_LTF_MODE[RATE_MODE_MAX][BANDWIDTH_MODE_MAX][ACELP_MODE_MAX+RF_MODE_MAX] = -{ - {{1,1,1,0,0,0,0,0},{1,1,1,0,0,0,0,0}}, - {{0,0,2,0,0,0,0,0},{0,0,2,0,1,1,1,0}}, -}; - -/*LTF BITS*/ -const Word16 ACELP_LTF_BITS[4] = -{ - 0, - 0, - 4, - 0 -}; - -/*GAINS ELEMENT*/ -/*5 modes: (ACELP: 5b/suframe), (AMRWB: 7b/subframe),(AMRWB: 6b/subframe),(UC: 5b/subframe)*/ -const Word16 ACELP_GAINS_MODE[RATE_MODE_MAX][BANDWIDTH_MODE_MAX][ACELP_MODE_MAX+RF_MODE_MAX] = -{ - {{6,6,1,1,0,0,0,0},{7,7,1,1,0,0,0,0}}, - {{2,2,3,3,0,0,0,0},{2,2,3,3,3,2,1,0}}, -}; - -/*GAINS BITS*/ -const Word16 ACELP_GAINS_BITS[10] = -{ - 0, /* skip sub-frame wise gain coding*/ - 5, /* ACELP 5b */ - 6, /* ACELP 6b */ - 7, /* ACELP 7b */ - 6, /* AMR-WB 6b */ - 7, /* AMR-WB 7b */ - 6, /* ACELP_UC 6b */ - 7, /* GUNVOICED UV 7b (5b ICB/2b Gaussian) */ - 4, /* GNELP UV 4b */ - 5 /* GNELP UV 5b */ -}; - -/*ADAPT BPF*/ -/*BPF MODE: 0 no filtering, 1 filtering, 2 adaptive*/ -const Word16 ACELP_BPF_MODE[RATE_MODE_MAX][BANDWIDTH_MODE_MAX][ACELP_MODE_MAX+RF_MODE_MAX] = -{ - {{1,1,1,1,0,0,0,0},{1,1,1,1,0,0,0,0}}, - {{1,1,2,2,0,0,0,0},{1,1,2,2,1,1,1,1}}, -}; - -/*BPF BITS*/ -const Word16 ACELP_BPF_BITS[3] = {0, 0, 2}; - -const Word16 ACELP_CDK_BITS[ACELP_FIXED_CDK_NB] = -{ - 7, 10, 12, 15, 17, 20, 24, 26, 28, 30, 32, 34, 36, 40, 43, 46, - 47, 49, 50, 53, 55, 56, 58, 59, 61, 62, 65, 68, 70, 73, 75, 78, 80, 83, - 85, 87, 89, 92, 94, 96, 98 -}; - -/* Number of pulses & positions to the number of unique states that can be achieved with those pulses */ -const Word32 pulsestostates[17][9] = -{ - { 0, 0, 0, 0, 0, 0, 0, 0, 0}, - { 2, 2, 2, 2, 2, 2, 2, 2, 2}, - { 4, 8, 12, 16, 20, 24, 28, 32, 36}, - { 6, 18, 38, 66, 102, 146, 198, 258, 326}, - { 8, 32, 88, 192, 360, 608, 952, 1408, 1992}, - { 10, 50, 170, 450, 1002, 1970, 3530, 5890, 9290}, - { 12, 72, 292, 912, 2364, 5336, 10836, 20256, 35436}, - { 14, 98, 462, 1666, 4942, 12642, 28814, 59906, 115598}, - { 16, 128, 688, 2816, 9424, 27008, 68464, 157184, 332688}, - { 18, 162, 978, 4482, 16722, 53154, 148626, 374274, 864146}, - { 20, 200, 1340, 6800, 28004, 97880, 299660, 822560, 2060980}, - { 22, 242, 1782, 9922, 44726, 170610, 568150, 1690370, 4573910}, - { 24, 288, 2312, 14016, 68664, 284000, 1022760, 3281280, 9545560}, - { 26, 338, 2938, 19266, 101946, 454610, 1761370, 6065410, 18892250}, - { 28, 392, 3668, 25872, 147084, 703640, 2919620, 10746400, 35704060}, - { 30, 450, 4510, 34050, 207006, 1057730, 4680990, 18347010, 64797470}, - { 32, 512, 5472, 44032, 285088, 1549824, 7288544, 30316544, 113461024}, -}; - - -/*vlpc_1st_cod*/ -const Word16 dico_lsf_abs_8b[256*M] = /*14Q1*1.28*/ -{ - 966, 1761, 2937, 3740, 4574, 5488, 6457, 7398, 8355, 9289, 10254, 11211, 12247, 13202, 14221, 15172, - 1540, 2731, 3544, 4232, 5065, 5917, 6846, 7707, 8602, 9538, 10479, 11445, 12439, 13339, 14332, 15243, - 1414, 2201, 3469, 4160, 4832, 5563, 6504, 7493, 8507, 9423, 10261, 11087, 12014, 12887, 13935, 15041, - 1176, 2031, 3312, 4141, 4915, 5612, 6368, 7097, 7965, 8861, 9900, 10956, 12137, 13161, 14215, 15190, - 840, 1102, 1853, 3913, 4514, 5155, 5976, 6577, 7726, 8469, 9195, 9896, 12016, 13534, 14458, 15327, - 1165, 1552, 2467, 3520, 3933, 4902, 6085, 6607, 7652, 8343, 8922, 9577, 11002, 13331, 14521, 15310, - 1113, 1431, 2280, 3471, 3975, 4853, 5690, 6407, 7275, 8032, 8621, 9884, 12276, 13033, 13880, 15039, - 719, 1036, 1867, 2553, 4352, 5021, 5775, 6505, 7179, 7826, 9601, 11113, 12075, 12807, 14022, 15272, - 953, 1294, 1952, 2553, 3007, 5085, 6062, 6718, 8178, 8712, 9927, 11330, 12351, 13205, 14164, 15087, - 940, 1283, 2111, 2792, 3256, 3911, 6096, 6898, 7589, 9317, 10103, 10891, 11893, 12886, 13757, 15049, - 587, 903, 1795, 3140, 4297, 4853, 5479, 6468, 7886, 8442, 9844, 11336, 12043, 12793, 13911, 15151, - 861, 1323, 2258, 3258, 3853, 4815, 5824, 6684, 8004, 9358, 10709, 11951, 12810, 13582, 14465, 15216, - 758, 1202, 2449, 3134, 3694, 4423, 5673, 6885, 7835, 9014, 10027, 11120, 12196, 13199, 14218, 15199, - 1042, 1478, 2150, 3726, 4263, 4954, 6139, 6790, 7965, 8974, 9643, 10764, 12030, 12725, 13557, 14581, - 719, 926, 2434, 3748, 4185, 5032, 5661, 6815, 7286, 9180, 10365, 11159, 11991, 12918, 13824, 15248, - 715, 1008, 2245, 3846, 4283, 5859, 6516, 7754, 9005, 9791, 10611, 11473, 12342, 13216, 14190, 15177, - 972, 1282, 1856, 2557, 3020, 4536, 7105, 8030, 8649, 9405, 10103, 10712, 11575, 12633, 13608, 14745, - 813, 1132, 1994, 2990, 3472, 4041, 4711, 7349, 8285, 8967, 9924, 10497, 11905, 13402, 14503, 15358, - 897, 1260, 1953, 3238, 3878, 4495, 6373, 7420, 8046, 9326, 10330, 10893, 11883, 13155, 14226, 15156, - 772, 1190, 1952, 2591, 4617, 5613, 6788, 7715, 8323, 9061, 10103, 11442, 12520, 13313, 14105, 15130, - 648, 914, 1614, 2978, 3913, 5180, 6371, 7029, 7510, 8288, 10181, 11303, 12262, 13298, 14629, 15443, - 679, 934, 1510, 2061, 4006, 5506, 6056, 6653, 7326, 8996, 10254, 11800, 12686, 13410, 14130, 15080, - 536, 802, 1288, 2431, 4428, 4896, 5421, 6396, 8409, 9756, 10509, 11135, 12212, 13338, 14298, 15284, - 774, 1064, 1751, 2361, 3813, 5723, 6272, 7170, 7837, 9027, 9999, 10677, 11383, 12564, 14005, 15142, - 678, 938, 1492, 2025, 4146, 5207, 5984, 6738, 7509, 8781, 9766, 10948, 12156, 13220, 14217, 15296, - 639, 927, 1490, 2153, 4243, 5592, 6466, 7219, 7989, 9277, 10369, 11353, 12295, 13240, 14272, 15267, - 743, 1035, 1700, 2248, 3167, 5728, 6394, 7572, 8421, 9284, 10729, 11762, 12753, 13526, 14380, 15202, - 468, 692, 1255, 2740, 4287, 5357, 6462, 7499, 8537, 9503, 10499, 11458, 12457, 13393, 14352, 15260, - 734, 989, 1478, 1957, 2947, 5157, 6144, 7370, 8090, 8834, 9907, 11183, 12331, 13280, 14246, 15263, - 461, 681, 1659, 3534, 4547, 5654, 6632, 7664, 8623, 9608, 10561, 11542, 12490, 13438, 14368, 15271, - 792, 1113, 1855, 2398, 3238, 5817, 6524, 7434, 8483, 9164, 10021, 11002, 12178, 13218, 14316, 15216, - 658, 1008, 1970, 3074, 4543, 5908, 7154, 8105, 8980, 9832, 10606, 11401, 12264, 13165, 14158, 15163, - 1009, 1541, 2392, 3464, 4644, 5562, 6666, 7588, 8538, 9554, 10547, 11489, 12487, 13412, 14326, 15206, - 955, 1704, 3142, 3903, 4985, 6046, 7112, 8024, 8864, 9606, 10417, 11275, 12242, 13171, 14188, 15188, - 1152, 2084, 3441, 4308, 5341, 6367, 7465, 8361, 9258, 10034, 10799, 11569, 12435, 13295, 14269, 15192, - 1361, 2472, 3734, 4540, 5724, 6786, 7934, 8876, 9753, 10482, 11209, 11930, 12704, 13494, 14411, 15293, - 1448, 2793, 3997, 5078, 6382, 7418, 8278, 9062, 9827, 10479, 11193, 11976, 12798, 13632, 14523, 15357, - 1488, 2499, 3704, 4557, 5499, 6512, 7628, 8636, 9720, 10662, 11547, 12425, 13250, 13991, 14754, 15490, - 1099, 2055, 3146, 3872, 4700, 5675, 6721, 7670, 8652, 9638, 10640, 11603, 12561, 13473, 14404, 15285, - 575, 841, 1577, 3091, 3894, 4777, 5587, 6225, 8293, 8937, 9666, 10986, 12135, 13292, 14164, 15178, - 799, 1086, 1834, 2360, 3186, 5166, 5756, 7271, 8036, 8703, 9532, 10239, 11731, 13180, 14418, 15362, - 956, 1297, 2021, 2413, 4341, 5175, 5948, 6783, 7304, 8114, 9024, 9853, 10910, 12746, 14094, 15167, - 1288, 1856, 2407, 3125, 3686, 4421, 5672, 6339, 7288, 8274, 9315, 10205, 11191, 12856, 14483, 15463, - 1020, 1359, 2139, 2709, 3398, 4646, 5412, 6441, 7053, 7923, 9213, 10192, 11791, 13084, 14208, 15242, - 839, 1165, 2114, 2625, 3382, 3972, 5064, 7268, 7966, 8749, 9833, 12022, 13123, 13848, 14622, 15279, - 837, 1104, 1848, 2230, 3860, 4731, 5491, 6377, 6917, 8917, 10029, 10891, 12043, 12753, 13952, 15201, - 1136, 1564, 2097, 2558, 3026, 4824, 5743, 6459, 7664, 8183, 9819, 10837, 11538, 12762, 14193, 15309, - 1013, 1492, 2105, 2593, 3135, 5090, 6278, 6877, 7559, 8026, 9120, 10257, 11268, 12899, 14253, 15324, - 677, 952, 1578, 2156, 3456, 4665, 5545, 6815, 7822, 8967, 10044, 11143, 12218, 13205, 14269, 15290, - 560, 833, 1626, 2825, 4189, 5300, 5822, 6280, 7858, 9256, 10189, 11481, 12413, 13040, 14138, 15123, - 666, 1181, 2686, 3416, 4169, 5158, 6179, 7282, 8275, 9372, 10419, 11434, 12436, 13400, 14358, 15244, - 773, 1040, 1809, 3551, 4049, 5132, 5867, 6525, 7877, 8558, 9275, 10956, 12231, 13016, 14012, 15032, - 881, 1209, 1988, 3725, 4126, 5152, 6189, 6712, 8497, 9495, 10097, 11006, 12228, 13271, 14197, 15140, - 850, 1109, 2540, 3212, 3836, 4671, 5423, 6258, 6873, 7502, 9107, 10990, 12254, 13154, 14378, 15352, - 721, 954, 2751, 3694, 4320, 5071, 5825, 6738, 7291, 7984, 9289, 11579, 12483, 13254, 14338, 15260, - 1055, 1371, 1968, 3743, 4580, 4986, 5695, 6267, 7257, 8890, 9548, 10261, 11586, 12347, 13324, 15091, - 676, 972, 2112, 2850, 3753, 4728, 5494, 6367, 7285, 8675, 9943, 11368, 12460, 13350, 14172, 15122, - 1049, 1494, 2200, 3000, 3527, 5081, 6046, 6884, 8291, 9069, 10097, 11369, 12496, 13375, 14347, 15128, - 814, 1123, 2183, 2717, 3304, 3975, 5256, 6076, 7491, 8840, 10493, 11738, 12716, 13494, 14450, 15263, - 948, 1271, 2388, 3106, 3719, 4616, 5356, 6675, 7383, 7967, 9440, 11584, 12408, 13133, 13866, 14860, - 635, 881, 1924, 3907, 4384, 5217, 5950, 6984, 7695, 8650, 9877, 11108, 12074, 13120, 14245, 15282, - 762, 1028, 2283, 3533, 3943, 4563, 5144, 6692, 7423, 8653, 9739, 10969, 12023, 13103, 14147, 15192, - 579, 854, 1748, 3347, 3979, 4734, 5418, 7056, 8203, 9063, 10246, 11271, 12279, 13293, 14338, 15258, - 503, 768, 1465, 3077, 4620, 5151, 5798, 7143, 8378, 9391, 10401, 11373, 12315, 13200, 14113, 15106, - 717, 1002, 1807, 3675, 4066, 5418, 6034, 6837, 8445, 8980, 10353, 11755, 12753, 13520, 14476, 15232, - 672, 949, 1676, 3274, 4729, 5344, 6538, 7393, 8330, 9755, 10902, 11594, 12475, 13327, 14247, 15152, - 496, 912, 2757, 3804, 4833, 5819, 6853, 7814, 8753, 9709, 10654, 11604, 12540, 13471, 14395, 15300, - 775, 1049, 2302, 3012, 3920, 4950, 5709, 7219, 7761, 9746, 10544, 11297, 12044, 12831, 13700, 15084, - 1078, 1504, 2140, 3195, 3778, 4555, 5966, 6673, 7747, 8995, 9612, 10447, 11613, 12329, 13101, 14856, - 968, 1849, 3399, 4265, 5004, 5732, 6679, 7575, 8554, 9526, 10485, 11412, 12400, 13344, 14309, 15220, - 1199, 2464, 3945, 4913, 6009, 6786, 7495, 8106, 8835, 9620, 10520, 11438, 12438, 13342, 14319, 15235, - 1081, 2165, 3828, 4637, 5448, 6070, 6800, 7534, 8434, 9349, 10320, 11262, 12293, 13218, 14232, 15192, - 1083, 1694, 2537, 3083, 3771, 5128, 6256, 7141, 8587, 9530, 10324, 11062, 11832, 12707, 13900, 15104, - 925, 1244, 2121, 3433, 3834, 5306, 6241, 6848, 8344, 9060, 9700, 10464, 11277, 12214, 14081, 15400, - 773, 1006, 1754, 4566, 5209, 5778, 6451, 7124, 8069, 8706, 9253, 10001, 10837, 12064, 14326, 15356, - 620, 950, 1866, 3048, 4740, 5460, 5977, 6457, 7915, 9271, 9868, 10687, 11496, 12237, 13203, 15016, - 1104, 1439, 2275, 2648, 3695, 5401, 5983, 7243, 7860, 8327, 8987, 11178, 12399, 13141, 14208, 14977, - 1076, 1712, 2332, 3118, 4625, 5250, 6130, 7069, 7734, 8740, 10166, 11116, 12011, 12960, 13959, 14830, - 659, 949, 1548, 2807, 4382, 4952, 5938, 7089, 7729, 8587, 10547, 11148, 11668, 12528, 13953, 15131, - 618, 891, 1593, 3197, 3993, 4733, 5928, 6583, 7372, 9278, 10158, 10852, 12066, 13201, 14256, 15298, - 1226, 1611, 2351, 3438, 3930, 4616, 6358, 6975, 7675, 9306, 10025, 10545, 11077, 12750, 14164, 15269, - 680, 957, 1852, 3036, 3864, 5284, 5883, 6570, 7132, 8763, 9943, 10590, 11425, 12827, 14180, 15184, - 567, 890, 1811, 3039, 4034, 4670, 5067, 5886, 7597, 8889, 10127, 10989, 12275, 13126, 14471, 15240, - 1017, 1306, 1912, 4065, 5098, 5506, 6244, 6943, 7610, 8963, 10029, 10608, 11375, 12363, 14054, 15433, - 718, 949, 1640, 4407, 4989, 5504, 6145, 6846, 8055, 8755, 9764, 11309, 12335, 13157, 13991, 15052, - 833, 1104, 2582, 3256, 3910, 5291, 5740, 7382, 8142, 8582, 9618, 11230, 12436, 13284, 14118, 14993, - 1157, 1491, 2370, 3490, 3848, 5022, 5800, 6591, 7995, 8564, 9304, 10921, 12495, 13372, 14254, 15054, - 1052, 1417, 2072, 2620, 3044, 4572, 5432, 6284, 7546, 8244, 9800, 10798, 12368, 13625, 14662, 15445, - 795, 1132, 1902, 2810, 3433, 4747, 5790, 6745, 8443, 9315, 10050, 10836, 11673, 12528, 13832, 15149, - 967, 1250, 2420, 3159, 3625, 4266, 4948, 7030, 7674, 8235, 9112, 9840, 11161, 12837, 14235, 15341, - 730, 997, 2113, 3171, 3737, 4764, 5577, 6449, 7240, 8394, 9116, 10604, 12009, 13102, 14231, 15244, - 1192, 1617, 2341, 3430, 4000, 4721, 5596, 6358, 7429, 8167, 8895, 9916, 10855, 12188, 13896, 15254, - 872, 1150, 2032, 3553, 3983, 4963, 5636, 6604, 7462, 8064, 9470, 10203, 11089, 12799, 14118, 15282, - 1013, 1444, 1984, 3267, 4408, 4772, 5805, 7143, 7690, 8647, 10029, 10669, 11431, 12636, 13988, 15117, - 830, 1134, 1866, 3581, 4056, 4925, 6011, 6558, 8076, 8830, 9656, 10706, 12639, 13726, 14663, 15367, - 684, 957, 1801, 3005, 3559, 4879, 5574, 6920, 7739, 8471, 9724, 10719, 12040, 13148, 14262, 15275, - 699, 1022, 2042, 3021, 3652, 5369, 6030, 7152, 8031, 8854, 9968, 10869, 11910, 13073, 14255, 15228, - 831, 1105, 1945, 3827, 4272, 5403, 6214, 6843, 8117, 8827, 9516, 10328, 11201, 12905, 14507, 15398, - 785, 1036, 2037, 4291, 4698, 5531, 6223, 7000, 8372, 9181, 9784, 10501, 11195, 12592, 13855, 15023, - 1079, 1556, 2081, 3294, 4678, 5189, 5975, 6991, 7650, 8458, 9624, 10387, 11370, 12518, 13343, 14521, - 1085, 1535, 2122, 2772, 3190, 4157, 6280, 7310, 8119, 8898, 9511, 10169, 11313, 12529, 13732, 15153, - 1130, 1625, 2359, 3044, 3504, 5151, 6102, 6755, 7616, 8099, 8791, 9828, 10718, 12434, 14231, 15302, - 894, 1194, 1854, 2315, 3048, 5073, 5700, 6637, 7336, 8181, 9563, 10924, 12316, 13331, 14349, 15237, - 1274, 1843, 2368, 2935, 3396, 4031, 5905, 6950, 7597, 8704, 9554, 10193, 11657, 13031, 13891, 14934, - 1208, 1660, 2310, 3189, 3644, 4355, 5442, 6162, 7602, 8433, 9505, 10600, 12310, 13625, 14495, 15234, - 884, 1244, 2154, 2652, 3187, 3810, 5991, 6674, 7284, 8251, 9106, 10547, 11947, 13173, 14248, 15300, - 851, 1095, 2125, 2913, 3429, 4068, 4931, 6228, 6911, 8477, 9513, 10932, 12187, 13333, 14385, 15286, - 637, 976, 2370, 3892, 4718, 6063, 7126, 8378, 9405, 10359, 11188, 12001, 12807, 13610, 14465, 15303, - 674, 1156, 3206, 3848, 4574, 5332, 6275, 7180, 7979, 8944, 9945, 11135, 12211, 13166, 14189, 15185, - 648, 874, 1620, 4523, 5335, 5818, 6480, 7079, 8024, 8654, 9320, 10068, 11602, 13428, 14329, 15293, - 602, 831, 3174, 4258, 4758, 5558, 6154, 6862, 7261, 8173, 9894, 11228, 12406, 13185, 14416, 15390, - 728, 1050, 2523, 3324, 4581, 5112, 6274, 7249, 7665, 8228, 9024, 9779, 11962, 13886, 14569, 15310, - 625, 1064, 2658, 3373, 4317, 5328, 6341, 7576, 8230, 9137, 10072, 11030, 12105, 13071, 14050, 15127, - 860, 1199, 2569, 3264, 3928, 5082, 6012, 7023, 7568, 8726, 9899, 10975, 11665, 12602, 13465, 14849, - 994, 1326, 2131, 3392, 3914, 4629, 5507, 6365, 7208, 8086, 9307, 10139, 11960, 13752, 14791, 15505, - 1297, 1723, 2304, 2955, 3528, 4575, 5330, 6141, 7321, 7873, 9079, 11066, 12114, 12781, 13485, 14866, - 1247, 1673, 2480, 3557, 4100, 4892, 5843, 6678, 7764, 8607, 9292, 10007, 11055, 11895, 12912, 14829, - 1108, 1515, 2302, 3815, 4582, 5275, 6233, 7271, 7993, 8890, 9807, 10489, 11145, 11905, 12753, 14036, - 969, 1302, 2055, 2425, 3922, 5219, 6014, 6785, 7331, 9195, 10032, 10897, 11788, 12542, 13408, 14826, - 1042, 1398, 2217, 2813, 3449, 4242, 5032, 6957, 7766, 8985, 9916, 10576, 11237, 12222, 13952, 15302, - 1099, 1456, 2313, 2814, 3532, 5651, 6349, 7119, 8208, 8769, 9427, 10112, 11070, 12005, 12975, 14815, - 952, 1343, 2279, 4277, 5014, 5588, 6550, 7259, 8172, 9304, 10112, 10905, 11848, 12798, 13734, 14852, - 827, 1155, 2015, 2590, 3389, 5575, 6147, 7237, 8788, 9352, 9943, 10452, 11166, 11866, 13017, 14908, - 965, 1342, 1904, 3530, 4756, 5265, 6282, 7430, 8006, 8866, 10189, 10858, 11593, 12497, 13413, 14286, - 791, 1033, 1807, 4669, 5445, 6065, 6777, 7311, 8217, 8955, 9594, 10171, 10891, 11711, 13024, 15079, - 703, 982, 1468, 2926, 5508, 6551, 7045, 7648, 8280, 9027, 10043, 10724, 11477, 12486, 13816, 15160, - 636, 1084, 3228, 4342, 5051, 5884, 6638, 7545, 8362, 9253, 10190, 11160, 12212, 13207, 14220, 15198, - 821, 1100, 1682, 3559, 5618, 6419, 6944, 7630, 8233, 9075, 10130, 10822, 11427, 12149, 13027, 14146, - 629, 1332, 3013, 3722, 4532, 5532, 6531, 7553, 8517, 9499, 10507, 11474, 12457, 13390, 14358, 15272, - 1317, 2450, 3297, 3892, 4613, 5418, 6425, 7337, 8291, 9245, 10282, 11346, 12442, 13393, 14373, 15268, - 1375, 2387, 3533, 4376, 5325, 6263, 7320, 8268, 9276, 10272, 11197, 12094, 13000, 13818, 14648, 15432, - 1158, 2044, 2814, 3372, 4231, 5273, 6326, 7190, 8055, 8945, 9909, 11036, 12230, 13264, 14271, 15192, - 871, 1102, 2233, 4189, 4539, 5309, 5875, 6894, 8135, 8683, 9397, 10814, 12535, 13312, 14286, 15134, - 814, 1062, 2256, 4246, 4741, 5468, 6095, 6832, 7800, 8445, 9019, 9623, 10539, 12957, 14398, 15333, - 958, 1249, 1879, 3625, 4221, 4743, 5374, 6010, 7564, 8370, 9054, 10537, 11472, 12580, 13996, 15129, - 871, 1148, 2666, 3651, 4193, 5040, 5660, 6778, 7459, 8017, 8780, 9530, 10508, 12721, 14270, 15304, - 651, 1057, 2426, 3096, 4328, 5224, 6148, 6984, 7722, 9038, 10150, 11248, 12299, 13281, 14301, 15245, - 617, 889, 2138, 4101, 4573, 5464, 6134, 7293, 8294, 9277, 10316, 11265, 12281, 13301, 14327, 15273, - 792, 1161, 2081, 2883, 3644, 5502, 6438, 7760, 8867, 9704, 10404, 11003, 11913, 13286, 14647, 15445, - 1202, 1869, 2491, 2996, 4025, 5336, 6574, 7586, 8415, 9166, 9940, 11099, 12441, 13461, 14408, 15252, - 1164, 2036, 2762, 3315, 4510, 5722, 6901, 7925, 8892, 9813, 10715, 11594, 12526, 13416, 14359, 15235, - 1442, 2242, 2916, 3528, 4751, 5836, 6787, 7599, 8395, 9235, 10177, 11157, 12208, 13147, 14145, 15115, - 1182, 2189, 3501, 4359, 5481, 6402, 7306, 7997, 8719, 9457, 10314, 11195, 12207, 13152, 14186, 15159, - 1123, 1928, 3249, 4174, 5190, 6018, 6841, 7570, 8320, 9079, 9969, 10880, 11946, 12957, 14056, 15116, - 1391, 2121, 3172, 3766, 4449, 5215, 6232, 7171, 8096, 8981, 9854, 10664, 11746, 12851, 14017, 15116, - 1330, 2144, 2998, 3489, 4141, 5059, 6328, 7427, 8552, 9564, 10505, 11379, 12290, 13173, 14193, 15189, - 1109, 1492, 2303, 2946, 3382, 4987, 6548, 6997, 8296, 9305, 9871, 10389, 11172, 13047, 14487, 15395, - 1088, 1547, 2223, 3092, 3620, 4386, 6452, 7580, 8220, 9176, 10021, 10624, 11535, 12511, 13349, 14330, - 888, 1265, 1930, 3715, 4354, 4929, 6671, 7348, 8125, 9622, 10527, 11265, 12457, 13225, 13909, 14800, - 815, 1189, 2006, 3817, 4374, 5838, 6485, 7386, 8816, 9395, 10242, 10930, 11702, 12358, 13510, 14977, - 990, 1329, 1856, 2513, 2960, 3841, 6200, 7584, 8128, 9084, 9884, 10615, 11927, 13026, 14162, 15236, - 809, 1891, 3000, 3978, 4992, 5938, 6931, 7857, 8818, 9757, 10695, 11637, 12557, 13495, 14394, 15295, - 554, 1531, 2712, 3754, 4813, 5795, 6805, 7758, 8739, 9677, 10642, 11569, 12527, 13426, 14344, 15173, - 961, 1247, 2162, 4030, 4594, 5392, 6191, 6804, 7979, 8852, 9449, 10061, 10905, 11757, 12852, 14951, - 1214, 1854, 2494, 3286, 3894, 4471, 5973, 7358, 7967, 8807, 9608, 10178, 10994, 12344, 13316, 14487, - 1024, 1446, 2069, 2773, 3329, 5327, 6627, 7318, 8209, 8780, 9592, 11114, 12066, 12765, 13662, 14618, - 907, 1229, 2135, 2657, 3456, 4585, 5614, 6412, 7107, 8072, 10517, 11769, 12447, 13038, 14011, 15186, - 608, 888, 1729, 3791, 4395, 4825, 5374, 6977, 7738, 8387, 9316, 10715, 12651, 13548, 14546, 15311, - 941, 1202, 2101, 3123, 3503, 4159, 4619, 6676, 7402, 8223, 9627, 10280, 11822, 13131, 14470, 15468, - 800, 1065, 1726, 2186, 4630, 5715, 6394, 7256, 7782, 8452, 9368, 11407, 12394, 13086, 14086, 15167, - 875, 1208, 1941, 2508, 3296, 4447, 5532, 6821, 7582, 8862, 9556, 10519, 11696, 12896, 14109, 15273, - 900, 1183, 1959, 2423, 3386, 5868, 6409, 7218, 7883, 8442, 9143, 9913, 11104, 13003, 14241, 15213, - 1115, 1573, 2286, 3113, 3574, 4645, 5519, 6311, 8196, 8937, 9864, 11290, 12252, 13043, 13810, 14631, - 754, 1068, 2679, 3694, 4190, 5008, 5606, 7347, 8013, 8864, 9972, 10786, 11627, 12824, 14010, 15316, - 825, 1144, 1765, 3426, 4206, 4874, 6385, 7180, 7946, 9319, 10153, 10682, 11276, 11957, 13415, 15087, - 537, 862, 1866, 3116, 4349, 4842, 5496, 7245, 7958, 8822, 9611, 10099, 11455, 13291, 14370, 15284, - 887, 1205, 1698, 3243, 5173, 5813, 6470, 7237, 7881, 8707, 9739, 10497, 11284, 12115, 13185, 14869, - 726, 1002, 2984, 3728, 4334, 5142, 5946, 7127, 7676, 8367, 9085, 10668, 11889, 13054, 14011, 15180, - 771, 981, 1772, 4221, 4795, 5401, 6003, 6690, 7480, 8115, 8717, 9938, 12232, 13037, 13941, 15157, - 1303, 1922, 2468, 3316, 4185, 4656, 5507, 6631, 7341, 8291, 9593, 10378, 11412, 12616, 13556, 14820, - 1080, 1403, 2477, 2954, 3741, 4642, 5517, 6582, 7111, 7805, 8786, 9547, 11253, 12874, 14045, 15236, - 872, 1141, 2386, 3209, 3896, 5042, 5805, 7002, 7549, 8285, 9036, 9939, 12031, 13030, 13767, 15055, - 728, 1046, 2013, 4276, 5230, 5799, 6889, 7772, 8535, 9890, 10949, 11702, 12791, 13661, 14459, 15218, - 768, 1578, 3171, 4134, 5114, 6061, 7128, 8112, 9139, 10152, 11101, 12005, 12913, 13736, 14586, 15387, - 622, 1221, 3202, 4279, 5529, 6753, 7808, 8631, 9408, 10115, 10830, 11631, 12512, 13365, 14324, 15263, - 621, 848, 1626, 4612, 5335, 5797, 6416, 7167, 8286, 8933, 9880, 11327, 12709, 13565, 14439, 15329, - 650, 861, 3115, 4397, 4828, 5572, 6159, 7071, 7513, 8108, 8667, 9739, 12413, 13532, 14414, 15581, - 756, 1091, 1615, 2958, 4679, 5429, 6304, 7065, 7657, 8329, 10012, 10763, 11425, 12569, 14285, 15324, - 765, 1051, 2074, 3446, 3838, 5659, 6318, 7149, 8407, 8942, 9688, 11058, 12443, 13347, 14361, 15231, - 1121, 1473, 2217, 2827, 3347, 5017, 5872, 6668, 7595, 8264, 9085, 10487, 12210, 13022, 13866, 14985, - 1056, 1457, 2212, 2861, 3453, 5060, 5976, 6759, 7697, 8519, 9461, 10348, 11169, 12000, 13798, 15274, - 1042, 1388, 2220, 3677, 4297, 5120, 6037, 6788, 7788, 8549, 9262, 10069, 10878, 11755, 14085, 15413, - 961, 1331, 1957, 3111, 3796, 4344, 5010, 5553, 7612, 9441, 10155, 10903, 11982, 12664, 13391, 14959, - 1135, 1470, 2082, 3284, 3937, 4423, 5140, 5618, 7055, 8860, 9355, 10318, 11706, 12556, 13826, 15192, - 1084, 1383, 2209, 3550, 4038, 4636, 5240, 5911, 8011, 9044, 9570, 10294, 11155, 11865, 13587, 15219, - 737, 1028, 1858, 2434, 3038, 3815, 5414, 6560, 7753, 9010, 10088, 11109, 12200, 13241, 14292, 15286, - 979, 1377, 2142, 3511, 4042, 4787, 5869, 6505, 7764, 8710, 9567, 10378, 11383, 13445, 14620, 15417, - 802, 1063, 1768, 3997, 4648, 5273, 6005, 6694, 7698, 8427, 9191, 10230, 11176, 12425, 13991, 15244, - 926, 1148, 2359, 3438, 3811, 4446, 4994, 6492, 7088, 7840, 8921, 9955, 11823, 13037, 14140, 15275, - 639, 939, 1753, 3080, 4204, 5022, 5702, 6198, 6811, 8268, 9786, 10836, 12243, 13126, 14260, 15306, - 736, 1079, 1802, 3276, 4001, 5415, 6381, 7119, 8492, 9232, 10308, 11105, 12031, 12793, 13904, 15114, - 1249, 1897, 2616, 3398, 4149, 4840, 5809, 6616, 7453, 8768, 9869, 10767, 12051, 13177, 14339, 15241, - 1026, 1314, 2014, 3249, 3690, 4344, 4892, 5691, 7289, 7970, 9397, 10615, 11663, 13015, 14272, 15328, - 970, 1249, 2342, 2895, 3661, 4685, 5348, 6691, 7176, 8850, 10323, 11025, 11936, 12697, 13429, 14816, - 872, 1155, 1680, 2334, 2880, 4439, 6448, 7088, 8221, 9517, 10060, 10691, 11577, 12830, 14274, 15377, - 874, 1131, 2067, 2714, 3203, 3786, 4480, 6643, 7487, 8708, 9861, 10989, 12079, 13208, 14240, 15290, - 804, 1079, 1708, 2236, 2842, 5275, 6096, 7030, 7886, 8704, 9978, 11354, 12923, 13800, 14706, 15380, - 646, 907, 1724, 3428, 3981, 5158, 5889, 7244, 8226, 8728, 9227, 10055, 11833, 13065, 14232, 15287, - 986, 1315, 1948, 2518, 3010, 5465, 6638, 7224, 8275, 8820, 9602, 10482, 11268, 12169, 14206, 15449, - 565, 805, 1593, 3458, 4571, 5319, 6411, 7828, 8796, 9460, 10121, 10926, 11931, 12989, 14085, 15181, - 532, 795, 1654, 3253, 3949, 5323, 6246, 7279, 8378, 9364, 10397, 11379, 12395, 13375, 14390, 15290, - 835, 1169, 1895, 2461, 3233, 5608, 6358, 7353, 8521, 9756, 10632, 11371, 12291, 12967, 13777, 14575, - 528, 840, 1585, 2511, 4342, 5075, 5825, 7183, 8370, 8938, 9529, 10614, 12398, 13483, 14482, 15340, - 789, 1044, 2065, 2677, 3589, 5397, 5969, 7559, 8126, 8638, 9332, 10989, 12645, 13441, 14355, 15188, - 685, 970, 1644, 2232, 4331, 5344, 6203, 6877, 7736, 9534, 10331, 11186, 11981, 12778, 13629, 14878, - 800, 1120, 1829, 2303, 4180, 4963, 5877, 6722, 7425, 8436, 9106, 10138, 12113, 13163, 14087, 15242, - 851, 1150, 2243, 3088, 3642, 5370, 6027, 6953, 7919, 8562, 9276, 9957, 10896, 12786, 14320, 15324, - 735, 1113, 2000, 3196, 4699, 5471, 6589, 7347, 8003, 8855, 9650, 10594, 12001, 13017, 13918, 15089, - 837, 1098, 1699, 2175, 3008, 6101, 6902, 7529, 8229, 8790, 9674, 10585, 11532, 12971, 14334, 15323, - 626, 1278, 3315, 4325, 5436, 6586, 7790, 8824, 9821, 10690, 11482, 12268, 13043, 13789, 14591, 15381, - 1439, 2612, 3825, 4715, 5881, 7098, 8204, 9129, 10075, 10889, 11673, 12416, 13159, 13897, 14672, 15420, - 1489, 2697, 3785, 4568, 5440, 6284, 7191, 8043, 8936, 9852, 10756, 11696, 12662, 13539, 14458, 15314, - 663, 932, 1850, 4514, 5042, 5800, 6482, 7381, 8674, 9537, 10447, 11239, 12074, 12975, 13958, 14969, - 695, 1028, 1781, 2195, 4548, 5142, 6539, 7282, 7728, 8259, 8915, 9755, 11646, 13482, 14373, 15221, - 846, 1138, 1713, 2239, 2823, 5254, 6237, 6940, 7777, 8443, 9981, 10858, 11793, 13022, 14259, 15331, - 595, 882, 1481, 3108, 4815, 5391, 5979, 6529, 8058, 8939, 9706, 10649, 11884, 13065, 14350, 15334, - 887, 1139, 1829, 2276, 3102, 5552, 6221, 7067, 7712, 8368, 9127, 10682, 12241, 13127, 14112, 15133, - 1019, 1418, 2165, 2865, 3353, 4937, 6019, 6784, 7810, 8440, 9197, 10025, 12092, 13614, 14602, 15352, - 951, 1206, 2295, 3066, 3586, 4125, 4780, 7215, 7687, 8320, 9079, 10918, 12519, 13503, 14488, 15224, - 847, 1149, 2069, 2504, 4231, 5041, 6034, 6862, 7321, 7882, 8765, 10837, 12433, 13022, 13809, 15203, - 829, 1111, 2677, 3505, 3999, 5080, 5694, 7033, 7667, 8302, 8963, 10297, 12410, 13340, 14485, 15373, - 908, 1284, 2182, 2613, 3944, 5116, 5768, 7284, 7825, 8461, 10123, 11755, 12583, 13368, 14195, 15053, - 930, 1215, 2323, 2834, 3500, 4216, 5200, 5956, 6576, 7757, 9998, 10921, 12073, 12844, 14003, 15254, - 973, 1343, 2164, 3265, 3733, 4538, 5294, 6469, 7850, 8468, 9747, 10750, 11398, 12428, 13990, 15226, - 952, 1239, 1992, 3093, 3498, 4156, 4605, 5695, 7946, 8668, 9684, 11027, 12029, 13102, 14093, 15158, - 558, 828, 1638, 2628, 3361, 4827, 6046, 7182, 8226, 9297, 10326, 11331, 12343, 13333, 14312, 15248, - 543, 797, 1292, 2197, 4031, 4954, 6096, 7133, 8292, 9244, 10253, 11267, 12293, 13293, 14303, 15272, - 562, 818, 1546, 2854, 3792, 5212, 5897, 6697, 8329, 9105, 10103, 11572, 13033, 13866, 14716, 15223, - 897, 1320, 1937, 2717, 3205, 4412, 6880, 7773, 8381, 9585, 10492, 11242, 12589, 13425, 14212, 15053, - 798, 1174, 2038, 2482, 3869, 4999, 5820, 7157, 7807, 9160, 10013, 11078, 12122, 13113, 14028, 14997, - 686, 1000, 2269, 3020, 3755, 5347, 5960, 7664, 8406, 9199, 10485, 11521, 12512, 13361, 14217, 15144, - 715, 1058, 1660, 3282, 4591, 4997, 6361, 7315, 7878, 9084, 10356, 11033, 12186, 13333, 14390, 15279, - 784, 1087, 1584, 3299, 5404, 6007, 6611, 7254, 7870, 8870, 10201, 10911, 11780, 12799, 14077, 15156, - 664, 905, 1952, 4880, 5346, 5934, 6519, 7374, 8530, 9311, 10103, 10819, 11525, 12818, 14071, 15168, - 626, 914, 2854, 4227, 4737, 5634, 6361, 7354, 7918, 8636, 9491, 10701, 11785, 13139, 14220, 15292, - 1793, 3491, 4468, 5330, 6092, 6716, 7382, 8023, 8852, 9777, 10729, 11640, 12576, 13418, 14323, 15182, - 688, 949, 1560, 3990, 5022, 5519, 6194, 6798, 8071, 8773, 9515, 10514, 12712, 13784, 14609, 15400, - 783, 1014, 2824, 3542, 4129, 4903, 5606, 6542, 6965, 7778, 10053, 10913, 11995, 12759, 13498, 15320, - 753, 1093, 2085, 2706, 4391, 5134, 5930, 6777, 7408, 8184, 9523, 10719, 12392, 13543, 14552, 15277, - 920, 1325, 2067, 2928, 3400, 4646, 5913, 6704, 8091, 8819, 9941, 10843, 12080, 13740, 14761, 15449, - 618, 961, 2096, 3325, 4242, 5555, 6567, 7721, 8801, 9891, 10891, 11871, 12871, 13717, 14555, 15310, - 826, 1165, 2466, 3876, 4364, 5723, 6461, 7667, 8417, 9095, 9913, 10755, 11704, 12971, 14239, 15196, - 1056, 1577, 2885, 3726, 4232, 5031, 5736, 6842, 8006, 8903, 10198, 11414, 12536, 13409, 14359, 15205, - 876, 1205, 2453, 3059, 3652, 4312, 5617, 6518, 7542, 8743, 9363, 11286, 13049, 13835, 14643, 15303, - 763, 990, 2805, 3723, 4228, 4936, 5628, 6613, 7058, 7705, 8476, 10130, 11974, 13113, 14180, 15342, - 857, 1152, 1913, 3994, 4629, 5137, 6183, 6861, 7722, 9347, 10177, 10777, 11599, 13112, 14298, 15264, - 656, 1269, 3434, 4621, 5637, 6438, 7220, 7942, 8741, 9612, 10517, 11433, 12435, 13354, 14316, 15237, - 1359, 2605, 3748, 4758, 6042, 7092, 7952, 8651, 9338, 9974, 10723, 11579, 12528, 13418, 14397, 15297, - 1529, 3067, 4410, 5449, 6449, 7233, 7901, 8525, 9237, 10002, 10859, 11784, 12730, 13589, 14467, 15300, - 1790, 3311, 4192, 4897, 5538, 6210, 6922, 7697, 8597, 9590, 10560, 11494, 12426, 13283, 14229, 15138, - 1252, 2359, 3404, 4211, 5155, 6055, 7030, 7899, 8850, 9793, 10761, 11714, 12674, 13565, 14489, 15352, - 590, 998, 2402, 3314, 4528, 5604, 6649, 7644, 8508, 9487, 10408, 11383, 12335, 13276, 14293, 15243, - 727, 1025, 1614, 3818, 5876, 6391, 6980, 7606, 8211, 9304, 10696, 11324, 12381, 13241, 13988, 14791, - 621, 899, 2068, 4152, 5232, 6483, 7323, 8193, 8960, 9627, 10417, 11291, 12234, 13192, 14216, 15187, - 582, 828, 1926, 4025, 4942, 6029, 6957, 7599, 8278, 9093, 10032, 11126, 12233, 13209, 14256, 15311, - 788, 1126, 1690, 3183, 3923, 4599, 6240, 6890, 7758, 9022, 9656, 10453, 11779, 12706, 13913, 15214 -}; - - -const Word16 lsf_cdk_nb_gc_stg1[] = /* 14Q1*1.28 */ -{ - -2046, -827, -3490, -8984, -9331, -8562, -2854, 112, 2194, 13294, 11592, 7952, - -294, 2271, 1647, -1260, -2029, -3649, -4081, -3432, -3649, 333, 5042, 4720, - -1209, 984, -241, -3413, -4476, -4817, -2910, -2016, -2016, 2900, 6868, 5408, - -1900, 896, 688, -197, -33, -993, -1470, -1283, -2145, -665, 2161, 4064, - -1998, -351, -1985, -4742, -4879, -5329, -3500, -2023, -1264, 8507, 9766, 6640, - 245, 3962, 3664, 1935, 1601, 144, -1054, -1236, -2225, -2647, -3746, 1695, - -3051, -1382, -1825, 828, 2537, 1872, 957, 689, -592, 1675, 5507, 5216, - -2178, -281, 2097, 5417, 4372, 1648, -802, -1304, -2817, -754, 3345, 4224, - -3400, -2402, -4098, -3148, -2066, -1985, -558, 466, 705, 11042, 11096, 7424, - 776, 4355, 3200, -1139, -2922, -3985, -2990, -2405, -2881, -661, 2897, 4176, - -1818, 394, -385, -1504, -1545, -2913, -3062, -2451, -2609, 2093, 6387, 5248, - -1081, 2069, 1952, 1345, 1649, 64, -1394, -1526, -2577, -2051, -1025, 2863, - 276, 2780, 1567, -3228, -4881, -5970, -4363, -3523, -3089, 3447, 7300, 5456, - 1917, 6445, 5552, 2069, 684, -1233, -2371, -2377, -3409, -1635, 1616, 3648, - -2734, -1049, -2001, -1927, -1908, -2273, -1294, -652, -944, 4451, 7893, 5888, - -1193, 2108, 5153, 7875, 8214, 6145, 2891, 2001, 208, -1312, -2273, 1599, - -3697, -3538, -6739, -7238, -4524, -2464, 2424, 4591, 6098, 15691, 13066, 8912, - -352, 2108, 847, -247, 1179, -769, -2757, -2873, -3713, 203, 4994, 4688, - -1185, 1565, 703, -1788, -2372, -2721, -1951, -1554, -2129, -374, 2529, 4192, - -2094, 401, 352, 1118, 2376, 1632, 582, 351, -1009, -1389, -784, 3056, - -367, 1637, -145, -5132, -6888, -8178, -5371, -3397, -1776, 9469, 9894, 6752, - 953, 5894, 6785, 5196, 4663, 2400, 31, -598, -2065, -2581, -2786, 1743, - -2637, -1222, -560, 5363, 6867, 5329, 2192, 1264, -544, -508, 1345, 3664, - -1112, 1918, 2976, 3989, 4508, 3104, 1245, 606, -897, -2381, -4258, 1119, - -1983, -328, -2930, -6112, -1802, 144, 486, 194, -960, 4066, 7797, 5872, - 648, 3526, 3104, 562, -200, -2177, -3380, -3162, -3857, -1516, 2433, 3920, - -2908, -722, -417, -181, 290, -352, -352, -175, -1088, 1689, 5603, 5184, - -536, 2771, 2064, 10, -643, -1793, -1733, -1523, -2193, -1813, -1585, 2831, - 2239, 5541, 4400, -637, -2370, -4802, -5148, -3901, -2912, 7328, 9222, 6320, - 8159, 12344, 9921, 5311, 4611, 2480, -1461, -1819, -2032, 5438, 7396, 5968, - -3908, -2998, -3105, 1031, 2171, 1952, 2012, 1982, 1280, 8825, 10343, 7056, - -80, 5935, 10546, 12414, 12351, 9601, 4823, 3380, 1152, -840, -2161, 1967 -}; -const Word16 lsf_cdk_nb_gc_stg2[] = /* 14Q1*1.28 */ -{ - -476, -1387, -3185, 464, 1104, 0, - -1029, -675, 63, -1664, -1168, 0, - -691, -1002, -1697, -1968, -704, 0, - -957, -724, -945, 816, 928, 0, - -1131, -2087, -1296, 2704, 1376, 0, - -1167, -1003, 512, 592, 192, 0, - 492, 517, -721, -3600, -1888, 0, - 489, -147, -1153, -688, -864, 0, - 865, 179, -608, 2000, 1008, 0, - -1286, -1953, -1633, -304, -368, 0, - 2033, 1593, -369, -576, 272, 0, - -718, 685, 751, -192, 192, 0, - 1394, 1172, 1520, -480, -576, 0, - -1455, -466, 2896, 2176, 896, 0, - -1171, 324, 2512, -272, -496, 0, - 4950, 5112, 3536, 1040, 80, 0 -}; -const Word16 lsf_cdk_nb_gc_stg3[] = /* 14Q1*1.28 */ -{ - 1, 6, -801, -3701, -3408, -1712, 2661, 2257, 768, - 4, 11, -481, -1886, -2409, -2353, -652, 1216, 256, - 14, 6, -1713, -1706, -1012, -817, -1158, -369, -97, - 8, 15, 127, -780, -1241, -1617, -2819, -1474, -577, - 13, 6, 2320, 103, -1175, -1681, 297, 1536, 384, - 4, 14, -529, -319, -161, -129, -2113, -4131, -1281, - 0, 5, -2001, -1650, -185, 1040, 2146, 1713, 736, - 12, 4, 320, 1615, 1634, 1376, -1700, -4675, -1697, - 15, 13, -401, -348, -511, -320, 2570, 2865, 944, - 7, 14, 335, -1107, -768, -112, -338, -65, 15, - 13, 15, -1025, 563, -38, -865, -1105, 383, 31, - 4, 6, 1056, 1034, 443, -289, -2357, -1986, -689, - 7, 6, 1008, 1608, 1329, 816, 730, 1312, 432, - 4, 12, -1281, 789, 1794, 1328, -517, -561, -113, - 12, 4, 704, 1656, 2289, 3153, 5215, 3682, 1680, - 11, 15, 2528, 4255, 3539, 2320, -669, -1585, -641 -}; -const Word16 lsf_cdk_nb_vc_stg1[] = /* 14Q1*1.28 */ -{ - -1950, -1358, -4562, -8912, -8626, -8050, -2211, 1051, 4226, 15749, 13194, 8800, - 224, 2532, 175, -5316, -6930, -5601, 381, 515, -416, 3224, 6964, 5584, - -2481, -1570, -3746, -3444, -3066, -3665, -2328, -929, -256, 10781, 10903, 7280, - -164, 2676, 1952, 1170, 1362, 32, -809, -978, -1793, -2288, -3137, 2287, - -1649, -589, -3746, -9056, -6586, -2160, 1693, 1869, 1072, 8982, 10375, 7056, - -1442, 731, -465, -352, 881, 0, -1397, -1476, -2273, -792, 2209, 4048, - -570, 1125, -577, -4067, -5011, -6130, -4457, -3228, -2464, 7796, 9414, 6432, - 314, 2780, 1599, -2442, -4050, -5762, -4680, -3747, -3169, 3706, 7556, 5568, - -3306, -3212, -6178, -5257, -2978, -2209, 33, 2038, 3490, 15396, 13130, 8704, - -303, 2334, 927, -1025, -1877, -2753, -1964, -1602, -2145, -943, 1457, 3872, - -1437, 228, -1633, -3020, -3188, -2833, -1579, -942, -1184, 2482, 6532, 5408, - 2622, 6487, 4448, 511, -1383, -2769, -2495, -2230, -2977, -107, 4082, 4480, - -1897, -706, -2994, -2432, 566, 704, 220, 99, -608, 3533, 7300, 5744, - -2605, -1419, -1376, 1700, 1217, 112, -957, -849, -1633, 1902, 6131, 5296, - 2177, 3621, 751, -6700, -10534, -11698, -2205, 713, 3954, 15329, 12986, 8656, - 7156, 9030, 4704, 653, -2345, -6178, -4996, -1616, 1762, 14213, 12329, 8272, - -997, 238, -2066, -5868, -6868, -7474, -4302, -2171, -623, 12371, 11336, 7600, - 2585, 4011, 959, -298, 477, -353, -2457, -2786, -3233, 5865, 8693, 6064, - -2145, -680, -1553, -1961, -2011, -3249, -3184, -2317, -1968, 5674, 8613, 6080, - 675, 4202, 4128, 2060, 1483, -865, -2647, -2552, -3377, -2094, 64, 3184, - -3084, -2915, -5698, -905, 1626, 2176, 1517, 1566, 1024, 9339, 10663, 7232, - -741, 1377, 1168, 206, 185, -1601, -3079, -2936, -3553, -265, 4402, 4528, - 872, 3048, 799, -4039, -5660, -7890, -7222, -4564, -1792, 10306, 10311, 6992, - 2766, 6132, 4848, -1357, -2881, -4914, -4864, -3528, -2608, 9503, 10134, 6832, - -1649, -1598, -6691, -10943, -5664, -3632, 2663, 6788, 11044, 19895, 15933, 10416, - 530, 3138, 2560, -401, -1453, -3425, -4047, -3463, -3713, 252, 4914, 4672, - -879, 1210, 47, -2253, -2732, -3777, -3689, -2947, -2833, 2110, 6499, 5232, - 5749, 8736, 6865, 3519, 2447, 383, -1446, -1459, -2385, 970, 4146, 4560, - -2556, -1914, -3969, 3390, 7938, 6305, 1777, 560, -928, 1091, 4563, 4928, - -1808, -411, 1313, 6469, 6395, 3680, 398, -149, -1713, -1588, 832, 3360, - 3630, 5517, 2479, -2938, -6552, -10675, -4951, -545, 1441, 13744, 12041, 8080, - 10956, 13776, 9201, 4285, 3873, -801, -5835, -2466, 1233, 13746, 12105, 8192 -}; -const Word16 lsf_cdk_nb_vc_stg2[] = /* 14Q1*1.28 */ -{ - -377, -729, -1793, 400, 1312, 0, - -1197, -1432, -2033, -1936, -1520, 0, - -403, -100, 127, -3232, -3456, 0, - 555, 364, -865, -592, -1264, 0, - -1136, -1968, -2640, 4448, 3824, 0, - -1539, 94, 591, 1600, 1376, 0, - -1564, -393, 2528, -304, -688, 0, - 1075, 823, 1648, -96, -704, 0, - -770, -404, 527, -1648, 64, 0, - -1320, -1678, -1072, 48, -688, 0, - 145, 83, -1089, -3632, -448, 0, - 1994, 1756, 159, 1120, 1504, 0, - 282, -236, -800, 2080, 624, 0, - -1357, -1537, 1008, 2624, 1360, 0, - 2002, 2046, 1215, -2336, -1808, 0, - 3757, 3480, 2592, 1472, 512, 0 -}; -const Word16 lsf_cdk_nb_vc_stg3[] = /* 14Q1*1.28 */ -{ - 3, 5, -657, -4633, -3805, -736, 1304, 1024, 368, - 6, 12, -305, -1836, -2507, -2625, -1818, -241, -305, - 6, 4, -2577, -1854, -1236, -1073, -594, 207, -1, - 2, 2, -80, 643, 38, -993, -3719, -1602, -769, - 13, 10, -625, -1825, -2422, -2449, 2887, 2625, 784, - 6, 0, -336, 315, 466, 560, -2183, -4867, -1345, - 10, 7, -2625, 1255, 2305, 1296, 181, 544, 208, - 0, 7, 912, 1998, 1662, 623, -416, 256, 32, - 10, 6, -1713, -1720, -311, 1408, 2066, 1585, 672, - 7, 11, 15, -1217, -99, -33, -851, -33, -81, - 12, 0, -1680, 556, -499, -897, 454, 896, 256, - 2, 8, 2608, 425, -938, -1937, -1205, 15, -177, - 6, 2, 1504, -796, -939, 80, 2179, 1777, 672, - 3, 13, 1984, 3517, 3171, 2320, -2605, -5651, -1857, - 14, 2, -160, 1660, 2380, 2832, 2924, 2097, 992, - 10, 0, 3857, 3623, 2853, 1728, 1554, 1441, 656 -}; -const Word16 lsf_cdk_wb_gc_stg1[] = /* 14Q1*1.28 */ -{ - -854, -266, -3202, -8408, -10604, -11763, -10826, -9448, -7970, -4784, -3493, -2593, - -2727, -1241, -1489, -1469, -1977, -2529, -2344, -2279, -2273, -1750, -1365, -1505, - -728, 1001, -113, -1594, -2256, -3553, -4619, -4591, -4497, -3300, -2327, -2129, - -590, 1699, 1264, 1187, 300, -865, -1554, -1669, -1649, -1202, -837, -1169, - -1612, -578, -2546, -5013, -6155, -6834, -6779, -6002, -5506, -3988, -2968, -2625, - -1725, 1072, 1280, 74, 277, 672, 1385, 2172, 2688, 2643, 2065, 848, - -86, 3639, 3824, 1931, 2115, 1120, 338, 500, 496, 751, 718, -65, - -1024, 1647, 5377, 9202, 8763, 7665, 5376, 4447, 3824, 2803, 2000, 608, - -2585, -2600, -6211, -11489, -11790, -10322, -5788, -3684, -2289, -465, -33, -289, - -3165, -2478, -3521, -1181, 298, 1632, 2160, 2107, 2272, 2075, 1407, 319, - 1275, 3587, 2848, 570, -26, -1489, -4034, -4818, -5202, -3732, -2550, -2049, - -2614, -1530, -848, 4992, 6996, 8002, 9185, 9172, 9106, 7739, 5862, 3408, - 440, 2263, 751, -3627, -4674, -4978, -4938, -5078, -5554, -5428, -4266, -3361, - -2308, -80, 176, 2603, 3871, 3792, 3219, 2667, 2480, 2189, 1405, 95, - 2569, 6546, 6257, 3885, 2438, 1504, 1431, 1319, 1392, 1337, 942, -65, - -712, 3328, 6290, 10673, 12635, 13827, 14544, 13939, 13619, 10691, 8026, 4768, - 842, 2338, 159, -5945, -8498, -9619, -8197, -7076, -6066, -4502, -3722, -3409, - -1628, 617, -129, -1907, -2194, -1505, -95, 486, 928, 1268, 1071, 175, - 538, 3277, 2111, -1606, -3194, -3553, -2105, -1604, -1393, -974, -740, -1009, - -1279, 456, 2593, 6823, 5435, 3536, 1502, 544, -96, -521, -548, -1105, - -983, 675, -865, -4388, -5936, -5697, -3245, -2211, -1633, -519, -276, -849, - -102, 3506, 2480, 332, -670, -448, 859, 1384, 1776, 1846, 1568, 448, - 270, 5022, 5136, 4435, 4546, 4305, 4185, 4385, 4337, 3659, 2785, 1152, - 216, 5449, 10098, 11459, 11060, 9922, 8139, 7175, 6289, 4794, 3394, 1600, - -3137, -3309, -5826, -6310, -5500, -4385, -2187, -1054, -288, 502, 527, -129, - -2997, -2031, -1344, 2452, 2535, 1856, 912, 451, 272, -124, -515, -993, - 3808, 7001, 5536, 908, -807, -1665, -2041, -2232, -2449, -2206, -1782, -1905, - -1117, 2493, 3616, 4843, 5755, 6273, 6815, 6906, 6769, 5801, 4580, 2528, - 2509, 4911, 3439, -2294, -4945, -7203, -9006, -7957, -6818, -4297, -3321, -3009, - -1110, 1877, 1776, 2112, 2398, 2704, 3465, 3938, 4257, 4039, 3202, 1568, - 7131, 11568, 10626, 7755, 6467, 5073, 4839, 4543, 4128, 3206, 2160, 912, - 2457, 10049, 15204, 18687, 18433, 17364, 14947, 13353, 11682, 8277, 6182, 3232 -}; -const Word16 lsf_cdk_wb_gc_stg2[] = /* 14Q1*1.28 */ -{ - -1224, -2316, -3425, -928, 128, 0, - -1874, -2354, -1025, -624, -448, 0, - -1026, -888, -481, -2352, -1024, 0, - 838, 174, -2306, -4048, -960, 0, - -1336, -2679, -1776, 2464, 1200, 0, - 497, 2649, 3536, 1344, 320, 0, - -1099, 4, 2448, -544, -752, 0, - 993, 486, 592, 64, -480, 0, - 288, -551, -2385, 1824, 2016, 0, - -1090, -815, 128, 1008, 704, 0, - 279, -579, -1729, -560, -832, 0, - 60, 1211, 543, -288, 272, 0, - 480, 1062, 560, 3152, 1680, 0, - -1276, -672, 2961, 2704, 1200, 0, - 1357, 1787, 767, -3424, -2768, 0, - 4229, 3682, 1696, 192, -256, 0 -}; -const Word16 lsf_cdk_wb_gc_stg3[] = /* 14Q1*1.28 */ -{ - 15, 1, -1665, -4778, -4630, -3105, -554, -304, -112, - 13, 10, -753, -1579, -1817, -1953, -2415, -2148, -1697, - 8, 15, 1135, -1716, -3415, -5154, -4958, -3443, -1905, - 4, 1, -32, 570, 443, -65, -2187, -2759, -2561, - 4, 14, 399, -979, -269, 816, 385, -194, -673, - 2, 5, -2161, -1600, -401, -97, -412, -433, -321, - 0, 15, 2128, 3449, 1993, 175, -2815, -2580, -1729, - 3, 2, 400, 714, 1209, 1904, 2711, 2436, 1840, - 9, 13, 143, -1925, -2694, -2545, 358, 930, 960, - 10, 0, -960, 868, 173, -513, -97, 577, 896, - 0, 5, 1824, 11, -1080, -1761, -1565, -1058, -705, - 7, 1, -880, 2304, 2790, 2384, 573, -18, -273, - 5, 8, 1840, 1467, 978, 768, 598, 351, -17, - 6, 7, -1473, -2052, -711, 992, 3166, 2788, 2080, - 7, 12, 1856, 3557, 3483, 3184, 2417, 1923, 1408, - 3, 13, -1649, 1850, 4068, 5073, 4907, 4086, 2976 -}; -const Word16 lsf_cdk_wb_vc_stg1[] = /* 14Q1*1.28 */ -{ - -1159, -1161, -5395, -12785, -14024, -12291, -8572, -6523, -4593, -1979, -1169, -897, - -1903, -921, -2065, -1931, -2752, -3825, -4238, -4174, -4145, -3108, -2167, -2081, - 522, 1696, -513, -6103, -8611, -9571, -9024, -8617, -7826, -5631, -4489, -3761, - -1839, -544, -1280, 1080, 564, 752, 844, 1110, 1344, 1185, 1039, 63, - -2685, -2538, -5074, -6161, -6745, -6738, -5709, -4457, -3377, -1830, -1188, -1185, - -3059, -3565, -6706, -3405, -1183, -272, -112, 33, 160, -5, 13, -721, - 4464, 5425, 1535, -8151, -13242, -15171, -5882, -2159, -288, 176, 739, 1440, - 1431, 2210, -769, -2539, -889, -721, -4378, -6019, -8099, -8147, -6215, -3873, - -1779, -2663, -8548, -12911, -8955, -5265, -1796, -700, 240, 746, 528, -160, - -847, 1228, 735, -1117, -1191, -1857, -2236, -2407, -2321, -1779, -1542, -1665, - -11, 1561, 591, -2764, -3940, -4994, -5679, -5652, -5586, -4852, -3930, -3297, - -783, 2500, 2912, 1480, 864, -64, -492, -833, -769, -353, -452, -1009, - -1207, 305, -1169, -3978, -4167, -3249, -1227, -606, -48, 233, -51, -545, - -2442, -2531, -3873, 5622, 7990, 7025, 4210, 3337, 2576, 1042, 237, -673, - 7644, 9215, 4703, -2206, -6625, -10676, -11281, -8039, -4321, -386, 15, -113, - 5397, 7494, 5296, -39, -1846, -2017, -1875, -1846, -1697, -2156, -2072, -1969, - -279, 230, -3010, -8280, -10317, -11859, -10729, -9576, -7922, -4867, -3862, -2865, - -899, -234, -2897, 3569, 4566, 799, -5740, -7153, -6546, -3276, -2048, -960, - 954, 3319, 1295, -3334, -5133, -5137, -2866, -2245, -1793, -1073, -934, -1281, - -1098, 1538, 1024, 1919, 2978, 3729, 4709, 5431, 5521, 4962, 3843, 1920, - -772, 429, -1810, -5319, -6411, -7074, -6828, -6001, -5266, -3901, -3160, -2833, - -140, 1442, -1153, -2496, -631, 1264, 2033, 3167, 3840, 3225, 2577, 1232, - 2263, 4102, 1167, -4671, -6812, -9651, -10507, -2400, 272, 1823, 1124, -2641, - 3904, 5709, 4800, 1435, -1797, -3682, -7176, -9009, -11812, -10666, -5157, -2353, - 122, 738, -2898, -9698, -11180, -8161, -1527, -926, -352, 476, -116, -705, - 1615, 3938, 3296, -117, -1405, -2593, -4075, -4383, -4273, -3528, -3017, -2881, - 3319, 4999, 2191, -4352, -6684, -7394, -7503, -7494, -6914, -5038, -4138, -3841, - 1933, 5658, 4544, 2619, 2149, 1456, 812, 401, 240, 207, 12, -673, - 1747, 3791, 1295, -236, -1712, -1232, 632, 903, 1488, 1527, 1184, 368, - -1030, 922, 4017, 7665, 6754, 5073, 3236, 1989, 1056, 426, 45, -609, - 12487, 14522, 8896, 2687, 1057, -3810, -10425, -9171, -6482, -2948, -2321, -1169, - 7344, 9906, 7921, 4454, 3289, 2320, 1483, 513, 192, 491, 493, 79 -}; -const Word16 lsf_cdk_wb_vc_stg2[] = /* 14Q1*1.28 */ -{ - -182, -1035, -2593, -176, 528, 0, - -2110, -2904, -2881, -1696, -864, 0, - -160, -876, -1777, -4160, -2112, 0, - 1601, 651, -1393, 208, -896, 0, - -1109, -1806, -2112, 2592, 1360, 0, - -1723, -1575, 1104, 912, 288, 0, - -700, 1343, 687, 1408, 144, 0, - 863, 454, 864, 464, -160, 0, - -1234, -1141, -289, -832, 832, 0, - -230, -608, -480, -1520, -2352, 0, - 1268, 2126, 1919, -3440, -3072, 0, - 1298, 1365, -65, -2832, 672, 0, - 1095, 493, -849, 3184, 3056, 0, - -469, -479, 1617, 3728, 2112, 0, - -675, 1400, 3984, 240, -592, 0, - 2580, 2697, 2432, 1920, 1040, 0 -}; -const Word16 lsf_cdk_wb_vc_stg3[] = /* 14Q1*1.28 */ -{ - 7, 3, -1329, -4391, -3913, -3041, -859, -255, 176, - 13, 7, -2257, -960, -1287, -1649, -1313, -770, -433, - 3, 13, -33, -1650, -2302, -2721, -4039, -3798, -2609, - 10, 4, 0, 1123, 279, -1057, -2271, -1039, 160, - 7, 12, 15, -748, 384, 848, -1029, -1992, -2385, - 4, 1, -2417, -2753, -316, 912, 1240, 993, 704, - 0, 0, 2497, 3043, 1347, -849, -5667, -5913, -4193, - 5, 2, 848, 519, 1737, 2560, 1763, 1506, 912, - 12, 12, 271, -2734, -3306, -736, 1294, 383, -209, - 10, 14, -577, -71, -129, -449, 1561, 2068, 1920, - 14, 1, 1408, -1285, -2943, -4177, -1355, 306, 752, - 15, 8, -2529, 2194, 2953, 2368, 1761, 1377, 816, - 14, 10, 3024, 1322, 224, -304, 514, 511, -81, - 1, 12, -849, -709, 112, 2417, 5221, 4664, 3648, - 1, 9, 160, 3607, 3314, 2016, -333, -884, -1233, - 13, 12, 1888, 3621, 3935, 4000, 3607, 2932, 2128 -}; - -const Word16 *const lsf_codebook[2][2][TCXLPC_NUMSTAGES] = -{ - { - { lsf_cdk_wb_gc_stg1, lsf_cdk_wb_gc_stg2, lsf_cdk_wb_gc_stg3 }, - { lsf_cdk_wb_vc_stg1, lsf_cdk_wb_vc_stg2, lsf_cdk_wb_vc_stg3 } - }, - { - { lsf_cdk_nb_gc_stg1, lsf_cdk_nb_gc_stg2, lsf_cdk_nb_gc_stg3 }, - { lsf_cdk_nb_vc_stg1, lsf_cdk_nb_vc_stg2, lsf_cdk_nb_vc_stg3 } - } -}; - -const Word16 lsf_numbits[TCXLPC_NUMSTAGES] = { 5, 4, 4 }; - -const Word16 lsf_dims[TCXLPC_NUMSTAGES] = { 16, 8, 12 }; -const Word16 lsf_offs[TCXLPC_NUMSTAGES] = { 0, 0, 4 }; - -const Word16 lsf_ind_cdk_nb_gc_stg4[] = /* 14Q1*1.28 */ -{ - -1360, -704, 0, - 80, 256, 0, - -896, 1008, 0, - 960, 2016, 0 -}; -const Word16 lsf_ind_cdk_nb_vc_stg4[] = /* 14Q1*1.28 */ -{ - -1360, -944, 0, - 624, 1408, 0, - -368, 240, 0, - 2480, 3216, 0 -}; -const Word16 lsf_ind_cdk_wb_gc_stg4[] = /* 14Q1*1.28 */ -{ - -1280, -816, 0, - 368, 272, 0, - -704, 1136, 0, - 1296, 2448, 0 -}; -const Word16 lsf_ind_cdk_wb_vc_stg4[] = /* 14Q1*1.28 */ -{ - -1040, -848, 0, - 688, 400, 0, - -560, 1520, 0, - 2256, 2704, 0 -}; - -const Word16 *const lsf_ind_codebook[2][2][TCXLPC_IND_NUMSTAGES] = -{ - { { lsf_ind_cdk_wb_gc_stg4 }, { lsf_ind_cdk_wb_vc_stg4 } }, - { { lsf_ind_cdk_nb_gc_stg4 }, { lsf_ind_cdk_nb_vc_stg4 } } -}; - -const Word16 lsf_ind_numbits[TCXLPC_IND_NUMSTAGES] = { 2 }; - -const Word16 lsf_ind_dims[TCXLPC_IND_NUMSTAGES] = { 4 }; -const Word16 lsf_ind_offs[TCXLPC_IND_NUMSTAGES] = { 0 }; - -const Word16 min_distance_thr[2][2] = /* 14Q1*1.28 */ -{ - /* GC, VC */ - /* WB */ { 580, 580 }, - /* NB */ {1000, 580 } -}; - - -/*14Q1*1.28*/ -const Word16 means_nb_31bits_ma_lsf[16] = {861 /*336.3281f*1.28f Q1*/, 1360 /*531.2500f*1.28f Q1*/, 2270 /*886.7188f*1.28f Q1*/, 3243 /*1266.7969f*1.28f Q1*/, 4171 /*1629.2969f*1.28f Q1*/, 5052 /*1973.4375f*1.28f Q1*/, 6012 /*2348.4375f*1.28f Q1*/, 6776 /*2646.8750f*1.28f Q1*/, 7676 /*2998.4375f*1.28f Q1*/, 8428 /*3292.1875f*1.28f Q1*/, 9194 /*3591.4062f*1.28f Q1*/, 9744 /*3806.2500f*1.28f Q1*/, 10580 /*4132.8125f*1.28f Q1*/, 11911 /*4652.7344f*1.28f Q1*/, 13440 /*5250.0000f*1.28f Q1*/, 15061 /*5883.2031f*1.28f Q1*/}; -const Word16 means_wb_31bits_ma_lsf[16] = {818 /*319.5312f*1.28f Q1*/, 1403 /*548.0469f*1.28f Q1*/, 2392 /*934.3750f*1.28f Q1*/, 3465 /*1353.5156f*1.28f Q1*/, 4429 /*1730.0781f*1.28f Q1*/, 5428 /*2120.3125f*1.28f Q1*/, 6414 /*2505.4688f*1.28f Q1*/, 7323 /*2860.5469f*1.28f Q1*/, 8304 /*3243.7500f*1.28f Q1*/, 9221 /*3601.9531f*1.28f Q1*/, 10162 /*3969.5312f*1.28f Q1*/, 11091 /*4332.4219f*1.28f Q1*/, 12125 /*4736.3281f*1.28f Q1*/, 13153 /*5137.8906f*1.28f Q1*/, 14241 /*5562.8906f*1.28f Q1*/, 15266 /*5963.2812f*1.28f Q1*/}; - - -/*! - * \brief CLDFB prototype filter - * - * cldfb bands: 10 - * delay[ms]: 1.00 - * abs. max Val: 1.04 - * scale: 0.50 - */ -const Word16 CLDFB80_10[] = -{ - W16(0x0000), W16(0xfffc), W16(0xffdf), W16(0x0132), W16(0x23b5), - W16(0x0000), W16(0xffff), W16(0xfff3), W16(0x018d), W16(0x2a98), - W16(0x0000), W16(0x0000), W16(0x0006), W16(0x020d), W16(0x3116), - W16(0x0000), W16(0x0000), W16(0x001a), W16(0x02bd), W16(0x36e2), - W16(0x0000), W16(0x0000), W16(0x001c), W16(0x039f), W16(0x3bb5), - W16(0x0000), W16(0xffff), W16(0x001a), W16(0x04b1), W16(0x3f51), - W16(0x0000), W16(0x0000), W16(0x0024), W16(0x05da), W16(0x419a), - W16(0x0000), W16(0x0000), W16(0x002e), W16(0x06ee), W16(0x428c), - W16(0x0000), W16(0x0000), W16(0x0032), W16(0x07bd), W16(0x4267), - W16(0x0000), W16(0xfffc), W16(0x001b), W16(0x0820), W16(0x410b), - W16(0x0000), W16(0xfff0), W16(0xffe9), W16(0x0806), W16(0x3d82), - W16(0x0000), W16(0xfffe), W16(0xffe6), W16(0x0746), W16(0x37fe), - W16(0x0000), W16(0x0000), W16(0x000d), W16(0x05ae), W16(0x31d1), - W16(0x0000), W16(0x0000), W16(0x002a), W16(0x032f), W16(0x2b60), - W16(0x0000), W16(0xfffd), W16(0x0025), W16(0xffcd), W16(0x24a3), - W16(0x0000), W16(0x0003), W16(0x0004), W16(0xfb88), W16(0x1dc0), - W16(0x0000), W16(0x0000), W16(0xffca), W16(0xf66f), W16(0x16c9), - W16(0x0000), W16(0x0000), W16(0xff95), W16(0xf09a), W16(0x0fe8), - W16(0x0000), W16(0xffff), W16(0xff64), W16(0xea2a), W16(0x08e0), - W16(0x0000), W16(0x0012), W16(0xff21), W16(0xe34c), W16(0x02aa) -}; - -/*! - * \brief CLDFB prototype filter - * - * cldfb bands: 16 - * delay[ms]: 1.00 - * abs. max Val: 1.04 - * scale: 0.50 - */ -const Word16 CLDFB80_16[] = -{ - W16(0x0000), W16(0xfffb), W16(0xffdd), W16(0x0123), W16(0x2266), - W16(0x0000), W16(0xfffe), W16(0xffe7), W16(0x0157), W16(0x26c0), - W16(0x0000), W16(0xffff), W16(0xfff4), W16(0x0194), W16(0x2b04), - W16(0x0000), W16(0xffff), W16(0xfffe), W16(0x01e0), W16(0x2f1f), - W16(0x0000), W16(0x0000), W16(0x000c), W16(0x023f), W16(0x32fc), - W16(0x0000), W16(0x0000), W16(0x0019), W16(0x02b0), W16(0x368c), - W16(0x0000), W16(0x0000), W16(0x001d), W16(0x0336), W16(0x39bc), - W16(0x0000), W16(0x0001), W16(0x0013), W16(0x03cf), W16(0x3c7b), - W16(0x0000), W16(0x0001), W16(0x001a), W16(0x047b), W16(0x3ebd), - W16(0x0000), W16(0x0000), W16(0x001e), W16(0x0532), W16(0x407c), - W16(0x0000), W16(0x0000), W16(0x0025), W16(0x05ec), W16(0x41b3), - W16(0x0000), W16(0xffff), W16(0x002d), W16(0x069d), W16(0x4262), - W16(0x0000), W16(0x0000), W16(0x0031), W16(0x0738), W16(0x429c), - W16(0x0000), W16(0x0000), W16(0x0032), W16(0x07b3), W16(0x4271), - W16(0x0000), W16(0xffff), W16(0x002a), W16(0x0804), W16(0x41d1), - W16(0x0000), W16(0xfff9), W16(0x0015), W16(0x0824), W16(0x40a3), - W16(0x0000), W16(0xffec), W16(0xffee), W16(0x0815), W16(0x3e6c), - W16(0x0000), W16(0xfff7), W16(0xffe0), W16(0x07ca), W16(0x3b3b), - W16(0x0000), W16(0xfffd), W16(0xffe8), W16(0x0734), W16(0x379e), - W16(0x0000), W16(0xfffe), W16(0x0000), W16(0x0647), W16(0x33c7), - W16(0x0000), W16(0xffff), W16(0x0018), W16(0x04ff), W16(0x2fd6), - W16(0x0000), W16(0x0000), W16(0x0029), W16(0x035e), W16(0x2bca), - W16(0x0000), W16(0xffff), W16(0x002b), W16(0x0164), W16(0x279c), - W16(0x0000), W16(0x0001), W16(0x0022), W16(0xff11), W16(0x235b), - W16(0x0000), W16(0xfffc), W16(0x000f), W16(0xfc66), W16(0x1f0d), - W16(0x0000), W16(0x0001), W16(0xffec), W16(0xf966), W16(0x1ab4), - W16(0x0000), W16(0x0000), W16(0xffc6), W16(0xf617), W16(0x165a), - W16(0x0000), W16(0x0001), W16(0xffa5), W16(0xf27f), W16(0x120e), - W16(0x0000), W16(0x0001), W16(0xff86), W16(0xeea6), W16(0x0dbd), - W16(0x0000), W16(0x0001), W16(0xff67), W16(0xea95), W16(0x0950), - W16(0x0000), W16(0x0005), W16(0xff40), W16(0xe657), W16(0x051a), - W16(0x0000), W16(0x001b), W16(0xff12), W16(0xe1fc), W16(0x01c8) -}; - -/*! - * \brief CLDFB prototype filter - * - * cldfb bands: 20 - * delay[ms]: 1.00 - * abs. max Val: 1.04 - * scale: 0.50 - */ -const Word16 CLDFB80_20[] = -{ - W16(0x0000), W16(0xfffb), W16(0xffdf), W16(0x011e), W16(0x21f7), - W16(0x0000), W16(0xfffd), W16(0xffe1), W16(0x0146), W16(0x2573), - W16(0x0000), W16(0xffff), W16(0xfff2), W16(0x0173), W16(0x28e6), - W16(0x0000), W16(0xffff), W16(0xfff6), W16(0x01a9), W16(0x2c45), - W16(0x0000), W16(0xffff), W16(0xffff), W16(0x01e9), W16(0x2f84), - W16(0x0000), W16(0x0000), W16(0x000a), W16(0x0235), W16(0x329c), - W16(0x0000), W16(0x0000), W16(0x0014), W16(0x028c), W16(0x3583), - W16(0x0000), W16(0x0000), W16(0x001b), W16(0x02f1), W16(0x3831), - W16(0x0000), W16(0x0000), W16(0x001e), W16(0x0362), W16(0x3a9c), - W16(0x0000), W16(0x0001), W16(0x000d), W16(0x03df), W16(0x3cbb), - W16(0x0000), W16(0x0000), W16(0x001b), W16(0x0469), W16(0x3e89), - W16(0x0000), W16(0x0000), W16(0x001c), W16(0x04fb), W16(0x4004), - W16(0x0000), W16(0x0000), W16(0x0020), W16(0x0590), W16(0x4129), - W16(0x0000), W16(0x0000), W16(0x0027), W16(0x0622), W16(0x41f5), - W16(0x0000), W16(0x0000), W16(0x002e), W16(0x06ad), W16(0x426d), - W16(0x0000), W16(0x0000), W16(0x0030), W16(0x072a), W16(0x429b), - W16(0x0000), W16(0x0000), W16(0x0032), W16(0x0792), W16(0x4288), - W16(0x0000), W16(0x0001), W16(0x002e), W16(0x07e1), W16(0x4232), - W16(0x0000), W16(0xfffe), W16(0x0024), W16(0x0813), W16(0x4186), - W16(0x0000), W16(0xfff8), W16(0x0011), W16(0x0825), W16(0x407d), - W16(0x0000), W16(0xffed), W16(0xfff1), W16(0x0818), W16(0x3eb8), - W16(0x0000), W16(0xfff5), W16(0xffe3), W16(0x07e8), W16(0x3c3c), - W16(0x0000), W16(0xfffe), W16(0xffe1), W16(0x0789), W16(0x3977), - W16(0x0000), W16(0xfffd), W16(0xffee), W16(0x06f6), W16(0x367b), - W16(0x0000), W16(0xfffe), W16(0x0002), W16(0x062a), W16(0x3363), - W16(0x0000), W16(0xffff), W16(0x0016), W16(0x0524), W16(0x303c), - W16(0x0000), W16(0x0000), W16(0x0026), W16(0x03e4), W16(0x2d04), - W16(0x0000), W16(0x0000), W16(0x002d), W16(0x026c), W16(0x29b7), - W16(0x0000), W16(0xfffe), W16(0x0029), W16(0x00bb), W16(0x2657), - W16(0x0000), W16(0x0005), W16(0x0021), W16(0xfed0), W16(0x22ed), - W16(0x0000), W16(0xfff8), W16(0x0014), W16(0xfcae), W16(0x1f7c), - W16(0x0000), W16(0x0002), W16(0xfff7), W16(0xfa55), W16(0x1c03), - W16(0x0000), W16(0x0000), W16(0xffd8), W16(0xf7c8), W16(0x1886), - W16(0x0000), W16(0x0001), W16(0xffbc), W16(0xf50a), W16(0x150f), - W16(0x0000), W16(0x0001), W16(0xffa2), W16(0xf21f), W16(0x11a0), - W16(0x0000), W16(0x0001), W16(0xff89), W16(0xef0b), W16(0x0e2c), - W16(0x0000), W16(0x0001), W16(0xff71), W16(0xebd2), W16(0x0aa5), - W16(0x0000), W16(0xfffe), W16(0xff55), W16(0xe87a), W16(0x0724), - W16(0x0000), W16(0x0006), W16(0xff33), W16(0xe50a), W16(0x03fd), - W16(0x0000), W16(0x001e), W16(0xff0d), W16(0xe18b), W16(0x017f) -}; - -/*! - * \brief CLDFB prototype filter - * - * cldfb bands: 32 - * delay[ms]: 1.00 - * abs. max Val: 1.04 - * scale: 0.50 - */ -const Word16 CLDFB80_32[] = -{ - W16(0x0000), W16(0xfffb), W16(0xffe2), W16(0x0115), W16(0x214f), - W16(0x0000), W16(0xfffc), W16(0xffde), W16(0x012f), W16(0x237e), - W16(0x0000), W16(0xfffd), W16(0xffe2), W16(0x0149), W16(0x25ab), - W16(0x0000), W16(0xfffe), W16(0xffec), W16(0x0165), W16(0x27d4), - W16(0x0000), W16(0xffff), W16(0xfff4), W16(0x0183), W16(0x29f6), - W16(0x0000), W16(0xffff), W16(0xfff6), W16(0x01a6), W16(0x2c10), - W16(0x0000), W16(0xffff), W16(0xfffb), W16(0x01cc), W16(0x2e1d), - W16(0x0000), W16(0xffff), W16(0x0001), W16(0x01f6), W16(0x301c), - W16(0x0000), W16(0x0000), W16(0x0009), W16(0x0226), W16(0x320b), - W16(0x0000), W16(0x0000), W16(0x000f), W16(0x025a), W16(0x33e7), - W16(0x0000), W16(0x0000), W16(0x0015), W16(0x0292), W16(0x35b0), - W16(0x0000), W16(0x0000), W16(0x001b), W16(0x02d0), W16(0x3761), - W16(0x0000), W16(0x0000), W16(0x001d), W16(0x0313), W16(0x38fa), - W16(0x0000), W16(0x0000), W16(0x001e), W16(0x035a), W16(0x3a77), - W16(0x0000), W16(0x0000), W16(0x001b), W16(0x03a7), W16(0x3bd7), - W16(0x0000), W16(0x0000), W16(0x0004), W16(0x03f7), W16(0x3d18), - W16(0x0000), W16(0xffff), W16(0x001b), W16(0x044e), W16(0x3e38), - W16(0x0000), W16(0xffff), W16(0x001a), W16(0x04a8), W16(0x3f39), - W16(0x0000), W16(0x0000), W16(0x001c), W16(0x0504), W16(0x4018), - W16(0x0000), W16(0x0001), W16(0x001f), W16(0x0561), W16(0x40d6), - W16(0x0000), W16(0x0000), W16(0x0022), W16(0x05be), W16(0x4172), - W16(0x0000), W16(0x0000), W16(0x0027), W16(0x0619), W16(0x41eb), - W16(0x0000), W16(0xffff), W16(0x002c), W16(0x0672), W16(0x4242), - W16(0x0000), W16(0x0000), W16(0x002e), W16(0x06c6), W16(0x427b), - W16(0x0000), W16(0x0000), W16(0x002f), W16(0x0714), W16(0x4297), - W16(0x0000), W16(0x0000), W16(0x0031), W16(0x075a), W16(0x429a), - W16(0x0000), W16(0x0000), W16(0x0032), W16(0x0798), W16(0x4285), - W16(0x0000), W16(0x0001), W16(0x0031), W16(0x07cb), W16(0x4255), - W16(0x0000), W16(0xffff), W16(0x002c), W16(0x07f4), W16(0x4206), - W16(0x0000), W16(0xfffe), W16(0x0025), W16(0x0811), W16(0x4193), - W16(0x0000), W16(0xfffb), W16(0x001a), W16(0x0821), W16(0x40fa), - W16(0x0000), W16(0xfff5), W16(0x000b), W16(0x0823), W16(0x404a), - W16(0x0000), W16(0xfff0), W16(0xfff6), W16(0x081b), W16(0x3f2f), - W16(0x0000), W16(0xffef), W16(0xffe9), W16(0x0809), W16(0x3daa), - W16(0x0000), W16(0xfff5), W16(0xffe2), W16(0x07e4), W16(0x3c12), - W16(0x0000), W16(0xfffa), W16(0xffe0), W16(0x07ac), W16(0x3a5c), - W16(0x0000), W16(0xffff), W16(0xffe4), W16(0x0761), W16(0x388d), - W16(0x0000), W16(0xfffd), W16(0xffed), W16(0x0701), W16(0x36ac), - W16(0x0000), W16(0xfffe), W16(0xfff9), W16(0x068a), W16(0x34c0), - W16(0x0000), W16(0xffff), W16(0x0006), W16(0x05fd), W16(0x32cd), - W16(0x0000), W16(0x0000), W16(0x0013), W16(0x0559), W16(0x30d4), - W16(0x0000), W16(0x0000), W16(0x001d), W16(0x049f), W16(0x2ed6), - W16(0x0000), W16(0x0000), W16(0x0026), W16(0x03cf), W16(0x2cd0), - W16(0x0000), W16(0x0000), W16(0x002c), W16(0x02e8), W16(0x2ac1), - W16(0x0000), W16(0x0000), W16(0x002c), W16(0x01eb), W16(0x28aa), - W16(0x0000), W16(0xfffe), W16(0x0029), W16(0x00d7), W16(0x268d), - W16(0x0000), W16(0xfffd), W16(0x0024), W16(0xffae), W16(0x246c), - W16(0x0000), W16(0x000a), W16(0x0021), W16(0xfe6e), W16(0x2248), - W16(0x0000), W16(0xfff3), W16(0x001a), W16(0xfd19), W16(0x2022), - W16(0x0000), W16(0x0003), W16(0x0006), W16(0xfbad), W16(0x1df8), - W16(0x0000), W16(0x0002), W16(0xfff5), W16(0xfa2d), W16(0x1bcb), - W16(0x0000), W16(0xffff), W16(0xffe2), W16(0xf899), W16(0x199d), - W16(0x0000), W16(0x0001), W16(0xffcf), W16(0xf6f2), W16(0x1770), - W16(0x0000), W16(0x0001), W16(0xffbd), W16(0xf537), W16(0x1546), - W16(0x0000), W16(0x0001), W16(0xffad), W16(0xf36b), W16(0x1320), - W16(0x0000), W16(0x0000), W16(0xff9d), W16(0xf18e), W16(0x10fc), - W16(0x0000), W16(0x0001), W16(0xff8e), W16(0xefa2), W16(0x0ed3), - W16(0x0000), W16(0x0001), W16(0xff7f), W16(0xeda7), W16(0x0ca3), - W16(0x0000), W16(0x0001), W16(0xff6f), W16(0xeb9e), W16(0x0a6c), - W16(0x0000), W16(0xfffd), W16(0xff5e), W16(0xe989), W16(0x0837), - W16(0x0000), W16(0x0003), W16(0xff4b), W16(0xe769), W16(0x0618), - W16(0x0000), W16(0x0006), W16(0xff35), W16(0xe542), W16(0x042a), - W16(0x0000), W16(0x0013), W16(0xff1e), W16(0xe314), W16(0x0284), - W16(0x0000), W16(0x0020), W16(0xff06), W16(0xe0e2), W16(0x010c) -}; - -/*! - * \brief CLDFB prototype filter - * - * cldfb bands: 40 - * delay[ms]: 1.00 - * abs. max Val: 1.04 - * scale: 0.50 - */ -const Word16 CLDFB80_40[] = -{ - W16(0x0000), W16(0xfffa), W16(0xffe2), W16(0x0112), W16(0x2117), - W16(0x0000), W16(0xfffb), W16(0xffdc), W16(0x0128), W16(0x22d6), - W16(0x0000), W16(0xfffc), W16(0xffe0), W16(0x013c), W16(0x2494), - W16(0x0000), W16(0xfffe), W16(0xffe5), W16(0x0151), W16(0x2651), - W16(0x0000), W16(0xffff), W16(0xffed), W16(0x0167), W16(0x280b), - W16(0x0000), W16(0xffff), W16(0xfff4), W16(0x0180), W16(0x29c0), - W16(0x0000), W16(0xffff), W16(0xfff4), W16(0x019b), W16(0x2b6f), - W16(0x0000), W16(0xffff), W16(0xfff8), W16(0x01b8), W16(0x2d18), - W16(0x0000), W16(0xffff), W16(0xfffd), W16(0x01d8), W16(0x2eb8), - W16(0x0000), W16(0xffff), W16(0x0002), W16(0x01fb), W16(0x304e), - W16(0x0000), W16(0x0000), W16(0x0008), W16(0x0221), W16(0x31da), - W16(0x0000), W16(0x0000), W16(0x000d), W16(0x0249), W16(0x335a), - W16(0x0000), W16(0x0000), W16(0x0013), W16(0x0275), W16(0x34ce), - W16(0x0000), W16(0x0000), W16(0x0017), W16(0x02a4), W16(0x3634), - W16(0x0000), W16(0x0000), W16(0x001b), W16(0x02d6), W16(0x378b), - W16(0x0000), W16(0x0000), W16(0x001d), W16(0x030c), W16(0x38d3), - W16(0x0000), W16(0x0000), W16(0x001e), W16(0x0344), W16(0x3a08), - W16(0x0000), W16(0x0000), W16(0x001e), W16(0x0380), W16(0x3b2b), - W16(0x0000), W16(0x0000), W16(0x0017), W16(0x03bf), W16(0x3c3b), - W16(0x0000), W16(0xffff), W16(0x0002), W16(0x03ff), W16(0x3d36), - W16(0x0000), W16(0xffff), W16(0x001a), W16(0x0445), W16(0x3e1d), - W16(0x0000), W16(0x0000), W16(0x001a), W16(0x048d), W16(0x3eef), - W16(0x0000), W16(0x0000), W16(0x001b), W16(0x04d6), W16(0x3fad), - W16(0x0000), W16(0x0000), W16(0x001d), W16(0x0520), W16(0x4055), - W16(0x0000), W16(0x0001), W16(0x001f), W16(0x056a), W16(0x40e8), - W16(0x0000), W16(0xffff), W16(0x0021), W16(0x05b5), W16(0x4164), - W16(0x0000), W16(0x0000), W16(0x0026), W16(0x05fe), W16(0x41ca), - W16(0x0000), W16(0x0000), W16(0x0029), W16(0x0646), W16(0x421b), - W16(0x0000), W16(0xffff), W16(0x002d), W16(0x068c), W16(0x4256), - W16(0x0000), W16(0x0000), W16(0x002e), W16(0x06ce), W16(0x427f), - W16(0x0000), W16(0x0000), W16(0x002f), W16(0x070c), W16(0x4295), - W16(0x0000), W16(0x0000), W16(0x0031), W16(0x0746), W16(0x429c), - W16(0x0000), W16(0x0000), W16(0x0032), W16(0x077a), W16(0x4293), - W16(0x0000), W16(0x0000), W16(0x0032), W16(0x07a8), W16(0x427a), - W16(0x0000), W16(0x0001), W16(0x0030), W16(0x07d0), W16(0x424f), - W16(0x0000), W16(0xffff), W16(0x002d), W16(0x07f0), W16(0x4210), - W16(0x0000), W16(0xffff), W16(0x0028), W16(0x080a), W16(0x41ba), - W16(0x0000), W16(0xfffd), W16(0x001f), W16(0x081b), W16(0x414b), - W16(0x0000), W16(0xfffa), W16(0x0018), W16(0x0824), W16(0x40c6), - W16(0x0000), W16(0xfff4), W16(0x0009), W16(0x0822), W16(0x403a), - W16(0xffff), W16(0xfff1), W16(0xfff9), W16(0x081c), W16(0x3f57), - W16(0x0000), W16(0xffed), W16(0xffec), W16(0x0810), W16(0x3e1f), - W16(0x0000), W16(0xfff3), W16(0xffe6), W16(0x07f9), W16(0x3ce2), - W16(0x0000), W16(0xfff6), W16(0xffe1), W16(0x07d5), W16(0x3b92), - W16(0x0000), W16(0xfffb), W16(0xffe0), W16(0x07a6), W16(0x3a2f), - W16(0x0000), W16(0xffff), W16(0xffe3), W16(0x076a), W16(0x38bc), - W16(0x0000), W16(0xfffd), W16(0xffea), W16(0x0720), W16(0x373e), - W16(0x0000), W16(0xfffd), W16(0xfff3), W16(0x06c8), W16(0x35b7), - W16(0x0000), W16(0xfffe), W16(0xfffd), W16(0x0662), W16(0x342a), - W16(0x0000), W16(0xffff), W16(0x0008), W16(0x05ee), W16(0x329a), - W16(0x0000), W16(0x0000), W16(0x0011), W16(0x056b), W16(0x3107), - W16(0x0000), W16(0xffff), W16(0x001a), W16(0x04d9), W16(0x2f70), - W16(0x0000), W16(0x0000), W16(0x0022), W16(0x043a), W16(0x2dd4), - W16(0x0000), W16(0x0000), W16(0x0028), W16(0x038c), W16(0x2c33), - W16(0x0000), W16(0x0000), W16(0x002c), W16(0x02cf), W16(0x2a8c), - W16(0x0000), W16(0x0001), W16(0x002d), W16(0x0205), W16(0x28e0), - W16(0x0000), W16(0xffff), W16(0x002b), W16(0x012c), W16(0x2730), - W16(0x0000), W16(0xfffd), W16(0x0027), W16(0x0045), W16(0x257d), - W16(0x0000), W16(0xffff), W16(0x0023), W16(0xff50), W16(0x23c8), - W16(0x0000), W16(0x000a), W16(0x0021), W16(0xfe4d), W16(0x2211), - W16(0x0000), W16(0xfff3), W16(0x001c), W16(0xfd3c), W16(0x2059), - W16(0x0000), W16(0x0000), W16(0x000b), W16(0xfc1c), W16(0x1e9e), - W16(0x0000), W16(0x0003), W16(0xfffd), W16(0xfaf0), W16(0x1ce2), - W16(0x0000), W16(0x0001), W16(0xffef), W16(0xf9b6), W16(0x1b24), - W16(0x0000), W16(0xfffe), W16(0xffe0), W16(0xf870), W16(0x1965), - W16(0x0000), W16(0x0001), W16(0xffd1), W16(0xf71d), W16(0x17a7), - W16(0x0000), W16(0x0000), W16(0xffc3), W16(0xf5be), W16(0x15ec), - W16(0x0000), W16(0x0001), W16(0xffb5), W16(0xf453), W16(0x1433), - W16(0x0000), W16(0x0001), W16(0xffa8), W16(0xf2de), W16(0x127c), - W16(0x0000), W16(0x0000), W16(0xff9b), W16(0xf15e), W16(0x10c5), - W16(0x0000), W16(0x0001), W16(0xff8f), W16(0xefd4), W16(0x0f0b), - W16(0x0000), W16(0x0001), W16(0xff83), W16(0xee40), W16(0x0d4c), - W16(0x0000), W16(0x0001), W16(0xff77), W16(0xeca4), W16(0x0b88), - W16(0x0000), W16(0x0001), W16(0xff6a), W16(0xeaff), W16(0x09c2), - W16(0x0000), W16(0xfffd), W16(0xff5d), W16(0xe953), W16(0x0800), - W16(0x0000), W16(0x0002), W16(0xff4d), W16(0xe7a0), W16(0x064d), - W16(0x0000), W16(0x0006), W16(0xff3c), W16(0xe5e8), W16(0x04b8), - W16(0x0000), W16(0x0009), W16(0xff2a), W16(0xe42c), W16(0x034d), - W16(0x0000), W16(0x0018), W16(0xff17), W16(0xe26c), W16(0x0212), - W16(0x0001), W16(0x0020), W16(0xff03), W16(0xe0aa), W16(0x00e3) -}; - -/*! - * \brief CLDFB prototype filter - * - * cldfb bands: 60 - * delay[ms]: 1.00 - * abs. max Val: 1.04 - * scale: 0.50 - */ -const Word16 CLDFB80_60[] = -{ - W16(0x0000), W16(0xfffa), W16(0xffe2), W16(0x010f), W16(0x20cd), - W16(0x0000), W16(0xfffb), W16(0xffdf), W16(0x011e), W16(0x21f7), - W16(0x0000), W16(0xfffb), W16(0xffdd), W16(0x012b), W16(0x2320), - W16(0x0000), W16(0xfffd), W16(0xffe0), W16(0x0138), W16(0x244a), - W16(0x0000), W16(0xfffd), W16(0xffe1), W16(0x0146), W16(0x2573), - W16(0x0000), W16(0xfffe), W16(0xffe6), W16(0x0155), W16(0x269b), - W16(0x0000), W16(0xfffe), W16(0xffec), W16(0x0164), W16(0x27c1), - W16(0x0000), W16(0xffff), W16(0xfff2), W16(0x0173), W16(0x28e6), - W16(0x0000), W16(0xffff), W16(0xfff4), W16(0x0184), W16(0x2a08), - W16(0x0000), W16(0xffff), W16(0xfff4), W16(0x0196), W16(0x2b28), - W16(0x0000), W16(0xffff), W16(0xfff6), W16(0x01a9), W16(0x2c45), - W16(0x0000), W16(0xffff), W16(0xfff9), W16(0x01bd), W16(0x2d5e), - W16(0x0000), W16(0xffff), W16(0xfffc), W16(0x01d2), W16(0x2e73), - W16(0x0000), W16(0xffff), W16(0xffff), W16(0x01e9), W16(0x2f84), - W16(0x0000), W16(0x0000), W16(0x0003), W16(0x0201), W16(0x3091), - W16(0x0000), W16(0x0000), W16(0x0008), W16(0x021a), W16(0x3199), - W16(0x0000), W16(0x0000), W16(0x000a), W16(0x0235), W16(0x329c), - W16(0x0000), W16(0x0000), W16(0x000e), W16(0x0251), W16(0x3399), - W16(0x0000), W16(0x0000), W16(0x0012), W16(0x026e), W16(0x3491), - W16(0x0000), W16(0x0000), W16(0x0014), W16(0x028c), W16(0x3583), - W16(0x0000), W16(0x0000), W16(0x0018), W16(0x02ac), W16(0x366f), - W16(0x0000), W16(0x0000), W16(0x001b), W16(0x02ce), W16(0x3753), - W16(0x0000), W16(0x0000), W16(0x001b), W16(0x02f1), W16(0x3831), - W16(0x0000), W16(0x0000), W16(0x001d), W16(0x0315), W16(0x3907), - W16(0x0000), W16(0x0000), W16(0x001e), W16(0x033b), W16(0x39d6), - W16(0x0000), W16(0x0000), W16(0x001e), W16(0x0362), W16(0x3a9c), - W16(0x0000), W16(0x0000), W16(0x001d), W16(0x038a), W16(0x3b5a), - W16(0x0000), W16(0x0000), W16(0x0019), W16(0x03b4), W16(0x3c0f), - W16(0x0000), W16(0x0001), W16(0x000d), W16(0x03df), W16(0x3cbb), - W16(0x0000), W16(0xffff), W16(0x0001), W16(0x040a), W16(0x3d5e), - W16(0x0000), W16(0xfffe), W16(0x0017), W16(0x0439), W16(0x3df8), - W16(0x0000), W16(0x0000), W16(0x001b), W16(0x0469), W16(0x3e89), - W16(0x0000), W16(0x0000), W16(0x001a), W16(0x0499), W16(0x3f10), - W16(0x0000), W16(0x0000), W16(0x001a), W16(0x04c9), W16(0x3f8f), - W16(0x0000), W16(0x0000), W16(0x001c), W16(0x04fb), W16(0x4004), - W16(0x0000), W16(0x0000), W16(0x001e), W16(0x052c), W16(0x406f), - W16(0x0000), W16(0x0001), W16(0x001f), W16(0x055e), W16(0x40d1), - W16(0x0000), W16(0x0000), W16(0x0020), W16(0x0590), W16(0x4129), - W16(0x0000), W16(0x0000), W16(0x0022), W16(0x05c1), W16(0x4177), - W16(0x0000), W16(0x0000), W16(0x0025), W16(0x05f2), W16(0x41bb), - W16(0x0000), W16(0x0000), W16(0x0027), W16(0x0622), W16(0x41f5), - W16(0x0000), W16(0xffff), W16(0x002a), W16(0x0652), W16(0x4226), - W16(0x0000), W16(0xffff), W16(0x002c), W16(0x0680), W16(0x424e), - W16(0x0000), W16(0x0000), W16(0x002e), W16(0x06ad), W16(0x426d), - W16(0x0000), W16(0x0000), W16(0x002e), W16(0x06d9), W16(0x4284), - W16(0x0000), W16(0x0000), W16(0x002f), W16(0x0702), W16(0x4293), - W16(0x0000), W16(0x0000), W16(0x0030), W16(0x072a), W16(0x429b), - W16(0x0000), W16(0x0000), W16(0x0031), W16(0x074f), W16(0x429b), - W16(0x0000), W16(0x0000), W16(0x0032), W16(0x0772), W16(0x4295), - W16(0x0000), W16(0x0000), W16(0x0032), W16(0x0792), W16(0x4288), - W16(0x0000), W16(0x0000), W16(0x0032), W16(0x07af), W16(0x4274), - W16(0x0000), W16(0x0001), W16(0x0031), W16(0x07ca), W16(0x4257), - W16(0x0000), W16(0x0001), W16(0x002e), W16(0x07e1), W16(0x4232), - W16(0x0000), W16(0xffff), W16(0x002c), W16(0x07f5), W16(0x4203), - W16(0x0000), W16(0xfffe), W16(0x0029), W16(0x0806), W16(0x41ca), - W16(0x0000), W16(0xfffe), W16(0x0024), W16(0x0813), W16(0x4186), - W16(0x0000), W16(0xfffd), W16(0x001e), W16(0x081d), W16(0x4137), - W16(0x0000), W16(0xfffa), W16(0x0019), W16(0x0823), W16(0x40de), - W16(0x0000), W16(0xfff8), W16(0x0011), W16(0x0825), W16(0x407d), - W16(0xffff), W16(0xfff3), W16(0x0006), W16(0x0821), W16(0x4023), - W16(0xffff), W16(0xfff2), W16(0xfffb), W16(0x081d), W16(0x3f8c), - W16(0x0000), W16(0xffed), W16(0xfff1), W16(0x0818), W16(0x3eb8), - W16(0x0000), W16(0xffee), W16(0xffeb), W16(0x080d), W16(0x3deb), - W16(0x0000), W16(0xfff2), W16(0xffe7), W16(0x07fd), W16(0x3d18), - W16(0x0000), W16(0xfff5), W16(0xffe3), W16(0x07e8), W16(0x3c3c), - W16(0x0000), W16(0xfff7), W16(0xffe0), W16(0x07ce), W16(0x3b58), - W16(0x0000), W16(0xfffa), W16(0xffe0), W16(0x07ae), W16(0x3a6b), - W16(0x0000), W16(0xfffe), W16(0xffe1), W16(0x0789), W16(0x3977), - W16(0x0000), W16(0xffff), W16(0xffe4), W16(0x075e), W16(0x387d), - W16(0x0000), W16(0xfffd), W16(0xffe8), W16(0x072d), W16(0x377e), - W16(0x0000), W16(0xfffd), W16(0xffee), W16(0x06f6), W16(0x367b), - W16(0x0000), W16(0xfffe), W16(0xfff4), W16(0x06b8), W16(0x3575), - W16(0x0000), W16(0xfffe), W16(0xfffb), W16(0x0674), W16(0x346d), - W16(0x0000), W16(0xfffe), W16(0x0002), W16(0x062a), W16(0x3363), - W16(0x0000), W16(0xffff), W16(0x000a), W16(0x05d9), W16(0x3257), - W16(0x0000), W16(0x0000), W16(0x0010), W16(0x0582), W16(0x314b), - W16(0x0000), W16(0xffff), W16(0x0016), W16(0x0524), W16(0x303c), - W16(0x0000), W16(0xffff), W16(0x001b), W16(0x04c0), W16(0x2f2c), - W16(0x0000), W16(0x0000), W16(0x0021), W16(0x0455), W16(0x2e19), - W16(0x0000), W16(0x0000), W16(0x0026), W16(0x03e4), W16(0x2d04), - W16(0x0000), W16(0x0000), W16(0x0029), W16(0x036d), W16(0x2bed), - W16(0x0000), W16(0x0000), W16(0x002c), W16(0x02f0), W16(0x2ad3), - W16(0x0000), W16(0x0000), W16(0x002d), W16(0x026c), W16(0x29b7), - W16(0x0000), W16(0x0000), W16(0x002c), W16(0x01e2), W16(0x2898), - W16(0x0000), W16(0xffff), W16(0x002b), W16(0x0151), W16(0x2778), - W16(0x0000), W16(0xfffe), W16(0x0029), W16(0x00bb), W16(0x2657), - W16(0x0000), W16(0xfffd), W16(0x0026), W16(0x001d), W16(0x2534), - W16(0x0000), W16(0xfffe), W16(0x0024), W16(0xff7a), W16(0x2411), - W16(0x0000), W16(0x0005), W16(0x0021), W16(0xfed0), W16(0x22ed), - W16(0x0000), W16(0x0009), W16(0x0021), W16(0xfe21), W16(0x21c8), - W16(0x0000), W16(0xfff5), W16(0x001f), W16(0xfd6b), W16(0x20a2), - W16(0x0000), W16(0xfff8), W16(0x0014), W16(0xfcae), W16(0x1f7c), - W16(0x0000), W16(0x0001), W16(0x0009), W16(0xfbeb), W16(0x1e54), - W16(0x0000), W16(0x0003), W16(0x0000), W16(0xfb23), W16(0x1d2c), - W16(0x0000), W16(0x0002), W16(0xfff7), W16(0xfa55), W16(0x1c03), - W16(0x0000), W16(0x0001), W16(0xffed), W16(0xf981), W16(0x1ad9), - W16(0x0000), W16(0xffff), W16(0xffe3), W16(0xf8a7), W16(0x19b0), - W16(0x0000), W16(0x0000), W16(0xffd8), W16(0xf7c8), W16(0x1886), - W16(0x0000), W16(0x0001), W16(0xffcf), W16(0xf6e3), W16(0x175d), - W16(0x0000), W16(0x0000), W16(0xffc5), W16(0xf5f9), W16(0x1636), - W16(0x0000), W16(0x0001), W16(0xffbc), W16(0xf50a), W16(0x150f), - W16(0x0000), W16(0x0001), W16(0xffb3), W16(0xf416), W16(0x13e9), - W16(0x0000), W16(0x0001), W16(0xffaa), W16(0xf31d), W16(0x12c5), - W16(0x0000), W16(0x0001), W16(0xffa2), W16(0xf21f), W16(0x11a0), - W16(0x0000), W16(0x0000), W16(0xff99), W16(0xf11d), W16(0x107b), - W16(0x0000), W16(0x0000), W16(0xff91), W16(0xf016), W16(0x0f55), - W16(0x0000), W16(0x0001), W16(0xff89), W16(0xef0b), W16(0x0e2c), - W16(0x0000), W16(0x0001), W16(0xff81), W16(0xedfc), W16(0x0d01), - W16(0x0000), W16(0x0001), W16(0xff79), W16(0xece9), W16(0x0bd4), - W16(0x0000), W16(0x0001), W16(0xff71), W16(0xebd2), W16(0x0aa5), - W16(0x0000), W16(0x0001), W16(0xff68), W16(0xeab8), W16(0x0976), - W16(0x0000), W16(0xfffd), W16(0xff5f), W16(0xe99b), W16(0x084a), - W16(0x0000), W16(0xfffe), W16(0xff55), W16(0xe87a), W16(0x0724), - W16(0x0000), W16(0x0003), W16(0xff4a), W16(0xe757), W16(0x0607), - W16(0x0000), W16(0x0006), W16(0xff3f), W16(0xe632), W16(0x04f9), - W16(0x0000), W16(0x0006), W16(0xff33), W16(0xe50a), W16(0x03fd), - W16(0x0000), W16(0x000c), W16(0xff27), W16(0xe3e1), W16(0x0315), - W16(0x0000), W16(0x0016), W16(0xff1a), W16(0xe2b7), W16(0x0244), - W16(0x0000), W16(0x001e), W16(0xff0d), W16(0xe18b), W16(0x017f), - W16(0x0002), W16(0x0020), W16(0xff00), W16(0xe05e), W16(0x00a9) -}; - - -/*! - * \brief CLDFB rRotVectr - * - * cldfb bands: 10 - * global gain: 8.00 - * scale: sqrt(1.0/16.00) - */ -const Word16 rRotVectr_10[] = -{ - W16(0x5a71), W16(0x54ea), W16(0x4714), W16(0x3249), W16(0x1891) -}; - -/*! - * \brief CLDFB iRotVectr - * - * cldfb bands: 10 - * global gain: 8.00 - * scale: sqrt(1.0/16.00) - */ -const Word16 iRotVectr_10[] = -{ - W16(0xfc72), W16(0xe0ac), W16(0xc7f7), W16(0xb4be), W16(0xa8e3) -}; - -/*! - * \brief CLDFB rRotVectr - * - * cldfb bands: 16 - * global gain: 5.00 - * scale: sqrt(1.0/8.00) - */ -const Word16 rRotVectr_16[] = -{ - W16(0x652a), W16(0x62bc), W16(0x5c83), W16(0x52bc), W16(0x45c7), - W16(0x3623), W16(0x246b), W16(0x114d) -}; - -/*! - * \brief CLDFB iRotVectr - * - * cldfb bands: 16 - * global gain: 5.00 - * scale: sqrt(1.0/8.00) - */ -const Word16 iRotVectr_16[] = -{ - W16(0xfd84), W16(0xe9d4), W16(0xd6fe), W16(0xc5bb), W16(0xb6b6), - W16(0xaa82), W16(0xa196), W16(0x9c4c) -}; - -/*! - * \brief CLDFB rRotVectr - * - * cldfb bands: 20 - * global gain: 4.00 - * scale: sqrt(1.0/8.00) - */ -const Word16 rRotVectr_20[] = -{ - W16(0x5a7e), W16(0x591a), W16(0x5584), W16(0x4fd3), W16(0x482a), - W16(0x3ebb), W16(0x33c1), W16(0x2780), W16(0x1a46), W16(0x0c67) -}; - -/*! - * \brief CLDFB iRotVectr - * - * cldfb bands: 20 - * global gain: 4.00 - * scale: sqrt(1.0/8.00) - */ -const Word16 iRotVectr_20[] = -{ - W16(0xfe39), W16(0xf017), W16(0xe259), W16(0xd556), W16(0xc95f), - W16(0xbec1), W16(0xb5bf), W16(0xae90), W16(0xa963), W16(0xa658) -}; - -/*! - * \brief CLDFB rRotVectr - * - * cldfb bands: 32 - * global gain: 2.50 - * scale: sqrt(1.0/4.00) - */ -const Word16 rRotVectr_32[] = -{ - W16(0x652f), W16(0x6494), W16(0x6300), W16(0x6078), W16(0x5d02), - W16(0x58a7), W16(0x5371), W16(0x4d6e), W16(0x46ac), W16(0x3f3b), - W16(0x372f), W16(0x2e9a), W16(0x2593), W16(0x1c2f), W16(0x1286), - W16(0x08af) -}; - -/*! - * \brief CLDFB iRotVectr - * - * cldfb bands: 32 - * global gain: 2.50 - * scale: sqrt(1.0/4.00) - */ -const Word16 iRotVectr_32[] = -{ - W16(0xfec2), W16(0xf4d9), W16(0xeb0b), W16(0xe170), W16(0xd821), - W16(0xcf35), W16(0xc6c1), W16(0xbed9), W16(0xb793), W16(0xb0ff), - W16(0xab2d), W16(0xa62d), W16(0xa20b), W16(0x9ed0), W16(0x9c84), - W16(0x9b2e) -}; - -/*! - * \brief CLDFB rRotVectr - * - * cldfb bands: 40 - * global gain: 2.00 - * scale: sqrt(1.0/4.00) - */ -const Word16 rRotVectr_40[] = -{ - W16(0x5a81), W16(0x5a28), W16(0x5941), W16(0x57cc), W16(0x55cd), - W16(0x5347), W16(0x503d), W16(0x4cb4), W16(0x48b3), W16(0x443e), - W16(0x3f5e), W16(0x3a1a), W16(0x347b), W16(0x2e88), W16(0x284c), - W16(0x21d0), W16(0x1b1f), W16(0x1444), W16(0x0d48), W16(0x0637) -}; - -/*! - * \brief CLDFB iRotVectr - * - * cldfb bands: 40 - * global gain: 2.00 - * scale: sqrt(1.0/4.00) - */ -const Word16 iRotVectr_40[] = -{ - W16(0xff1d), W16(0xf803), W16(0xf0f7), W16(0xea02), W16(0xe330), - W16(0xdc8b), W16(0xd61f), W16(0xcff4), W16(0xca15), W16(0xc48c), - W16(0xbf60), W16(0xba9a), W16(0xb642), W16(0xb25e), W16(0xaef5), - W16(0xac0b), W16(0xa9a6), W16(0xa7ca), W16(0xa678), W16(0xa5b4) -}; - -/*! - * \brief CLDFB rRotVectr - * - * cldfb bands: 60 - * global gain: 1.33 - * scale: sqrt(1.0/2.00) - */ -const Word16 rRotVectr_60[] = -{ - W16(0x6882), W16(0x6855), W16(0x67de), W16(0x671e), W16(0x6615), - W16(0x64c5), W16(0x632f), W16(0x6153), W16(0x5f32), W16(0x5ccf), - W16(0x5a2a), W16(0x5747), W16(0x5426), W16(0x50ca), W16(0x4d35), - W16(0x496a), W16(0x456c), W16(0x413d), W16(0x3ce0), W16(0x3859), - W16(0x33aa), W16(0x2ed6), W16(0x29e2), W16(0x24d0), W16(0x1fa5), - W16(0x1a63), W16(0x150f), W16(0x0fac), W16(0x0a3e), W16(0x04c9) -}; - -/*! - * \brief CLDFB iRotVectr - * - * cldfb bands: 60 - * global gain: 1.33 - * scale: sqrt(1.0/2.00) - */ -const Word16 iRotVectr_60[] = -{ - W16(0xff51), W16(0xf9d9), W16(0xf465), W16(0xeefa), W16(0xe99a), - W16(0xe44a), W16(0xdf0e), W16(0xd9e9), W16(0xd4de), W16(0xcff2), - W16(0xcb27), W16(0xc682), W16(0xc204), W16(0xbdb3), W16(0xb990), - W16(0xb59e), W16(0xb1e0), W16(0xae5a), W16(0xab0c), W16(0xa7fb), - W16(0xa526), W16(0xa292), W16(0xa03f), W16(0x9e30), W16(0x9c65), - W16(0x9ae0), W16(0x99a2), W16(0x98ac), W16(0x97fe), W16(0x9799) -}; - -const Word16 cldfb_anaScale[] = -{ - SCALE_CLDFB_ANA_10, SCALE_CLDFB_ANA_16, SCALE_CLDFB_ANA_20, SCALE_CLDFB_ANA_32, SCALE_CLDFB_ANA_40, SCALE_CLDFB_ANA_60 -}; -const Word16 cldfb_synScale[] = -{ - SCALE_CLDFB_SYN_10, SCALE_CLDFB_SYN_16, SCALE_CLDFB_SYN_20, SCALE_CLDFB_SYN_32, SCALE_CLDFB_SYN_40, SCALE_CLDFB_SYN_60 -}; -const Word16 cldfb_synGain[] = -{ - 0x6666, /* 10 bands */ - 0x51EC, /* 16 bands */ - 0x6666, /* 20 bands */ - 0x51EC, /* 32 bands */ - 0x6666, /* 40 bands */ - 0x4CCD /* 60 bands */ -}; -const Word16 *cldfb_protoFilter_2_5ms[] = -{ - CLDFB80_10, CLDFB80_16, CLDFB80_20, CLDFB80_32, CLDFB80_40, CLDFB80_60 -}; -const Word16 cldfb_scale_2_5ms[7] = -{ - 22603/*88.293854 Q8*/, /* 10 bands */ - 22605/*88.299622 Q8*/, /* 16 bands */ - 22605/*88.300926 Q8*/, /* 20 bands */ - 22606/*88.303848 Q8*/, /* 32 bands */ - 22606/*88.304718 Q8*/, /* 40 bands */ - 22535/*88.028412 Q8*/ /* 60 bands */ -}; - - -/**********************************************************************/ /** -igf settings structure for each bitrate mode -**************************************************************************/ -const Word16 swb_offset_LB_new[15][IGF_MAX_SFB] = -{ - /* 0: for 9600 kbs WB */ - { - 4, 164, 186, 242, 320 - }, - /* 1: for 13200 kbs WB RF */ - { - 4, 164, 186, 242, 320 - }, - /* 2: for 9600 kbs SWB */ - { - 4, 200, 322, 444, 566 - }, - /* 3: for 13200 kbs SWB */ - { - 7, 256, 288, 328, 376, 432, 496, 566 - }, - /* 4: for 13200 kbs SWB RF */ - { - 4, 200, 322, 444, 566 - }, - /* 5: for 16400 kbs SWB */ - { - 8, 256, 288, 328, 376, 432, 496, 576, 640 - }, - /* 6: for 24400 kbs SWB */ - { - 9, 256, 284, 318, 358, 402, 450, 508, 576, 640 - }, - /* 7: for 32000 kbs SWB */ - { - 9, 256, 284, 318, 358, 402, 450, 508, 576, 640 - }, - /* 8: for 48000 kbs SWB */ - { - 4, 512, 534, 576, 640 - }, - /* 9: for 16400 kbs FB */ - { - 10, 256, 288, 328, 376, 432, 496, 576, 640, 720, 800 - }, - /* 10: for 24400 kbs FB */ - { - 11, 256, 284, 318, 358, 402, 450, 508, 576, 640, 720, 800 - }, - /* 11: for 32000 kbs FB */ - { - 11, 256, 284, 318, 358, 402, 450, 508, 576, 640, 720, 800 - }, - /* 12: for 48000 kbs FB */ - { - 5, 512, 584, 656, 728, 800 - }, - /* 13: for 96000 kbs FB */ - { - 3, 640, 720, 800 /* old: 640, 760, 880 */ - }, - /* 14: for 128000 kbs FB */ - { - 3, 640, 720, 800 /* old: 640, 760, 880 */ - } -}; - - - -const Word16 igf_whitening_TH[15][2][IGF_MAX_TILES] = -{ - /* 0: for 9600 kbs WB */ - { - /* medium */ { 2949/*0.36f Q13*/, 2949/*0.36f Q13*/, 0/*0.f Q13*/, 0/*0.f Q13*/}, - /* strong */ { 11551/*1.41f Q13*/, 11551/*1.41f Q13*/, 0/*0.f Q13*/, 0/*0.f Q13*/} - }, - /* 1: for 13200 kbs WB RF */ - { - /* medium */ { 2949/*0.36f Q13*/, 2949/*0.36f Q13*/, 0/*0.f Q13*/, 0/*0.f Q13*/}, - /* strong */ { 11551/*1.41f Q13*/, 11551/*1.41f Q13*/, 0/*0.f Q13*/, 0/*0.f Q13*/} - }, - /* 2: for 9600 kbs SWB */ - { - /* medium */ { 6881/*0.84f Q13*/, 7291/*0.89f Q13*/, 0/*0.f Q13*/, 0/*0.f Q13*/}, - /* strong */ { 10650/*1.30f Q13*/, 10240/*1.25f Q13*/, 0/*0.f Q13*/, 0/*0.f Q13*/} - }, - /* 3: for 13200 kbs SWB */ - { - /* medium */ { 6881/*0.84f Q13*/, 7291/*0.89f Q13*/, 0/*0.f Q13*/, 0/*0.f Q13*/}, - /* strong */ { 10650/*1.30f Q13*/, 10240/*1.25f Q13*/, 0/*0.f Q13*/, 0/*0.f Q13*/} - }, - /* 4: for 13200 kbs SWB RF */ - { - /* medium */ { 6881/*0.84f Q13*/, 7291/*0.89f Q13*/, 0/*0.f Q13*/, 0/*0.f Q13*/}, - /* strong */ { 10650/*1.30f Q13*/, 10240/*1.25f Q13*/, 0/*0.f Q13*/, 0/*0.f Q13*/} - }, - /* 5: for 16400 kbs SWB */ - { - /* medium */ { 6799/*0.83f Q13*/, 7291/*0.89f Q13*/, 7291/*0.89f Q13*/, 0/*0.f Q13*/}, - /* strong */ { 10732/*1.31f Q13*/, 9748/*1.19f Q13*/, 9748/*1.19f Q13*/, 0/*0.f Q13*/} - }, - /* 6: for 24400 kbs SWB*/ - { - /* medium */ { 6636/*0.81f Q13*/, 6963/*0.85f Q13*/, 6963/*0.85f Q13*/, 0/*0.f Q13*/}, - /* strong */ { 11059/*1.35f Q13*/, 10076/*1.23f Q13*/, 10076/*1.23f Q13*/, 0/*0.f Q13*/} - }, - /* 7: for 32000 kbs SWB */ - { - /* medium */ { 7455/*0.91f Q13*/, 6963/*0.85f Q13*/, 6963/*0.85f Q13*/, 0/*0.f Q13*/}, - /* strong */ { 10977/*1.34f Q13*/, 11059/*1.35f Q13*/, 11059/*1.35f Q13*/, 0/*0.f Q13*/} - }, - /* 8: for 48000 kbs SWB */ - { - /* medium */ { 9421/*1.15f Q13*/, 0/*0.f Q13*/, 0/*0.f Q13*/, 0/*0.f Q13*/}, - /* strong */ { 9748/*1.19f Q13*/, 0/*0.f Q13*/, 0/*0.f Q13*/, 0/*0.f Q13*/} - }, - /* 9: for 16400 kbs FB */ - { - /* medium */ { 5161/*0.63f Q13*/, 2212/*0.27f Q13*/, 2949/*0.36f Q13*/, 0/*0.f Q13*/}, - /* strong */ { 12534/*1.53f Q13*/, 10813/*1.32f Q13*/, 5489/*0.67f Q13*/, 0/*0.f Q13*/} - }, - /* 10: for 24400 kbs FB */ - { - /* medium */ { 6390/*0.78f Q13*/, 2540/*0.31f Q13*/, 2785/*0.34f Q13*/, 2785/*0.34f Q13*/}, - /* strong */ { 12206/*1.49f Q13*/, 11305/*1.38f Q13*/, 5325/*0.65f Q13*/, 5325/*0.65f Q13*/} - }, - /* 11: for 32000 kbs FB */ - { - /* medium */ { 6390/*0.78f Q13*/, 2540/*0.31f Q13*/, 2785/*0.34f Q13*/, 2785/*0.34f Q13*/}, - /* strong */ { 12206/*1.49f Q13*/, 11305/*1.38f Q13*/, 5325/*0.65f Q13*/, 5325/*0.65f Q13*/} - }, - /* 12: for 48000 kbs FB */ - { - /* medium */ { 6554/*0.80f Q13*/, 0/*0.f Q13*/, 0/*0.f Q13*/, 0/*0.f Q13*/}, - /* strong */ { 8192/*1.00f Q13*/, 0/*0.f Q13*/, 0/*0.f Q13*/, 0/*0.f Q13*/} - }, - /* 13: for 96000 kbs FB */ - { - /* medium */ { 0/*0.f Q13*/, 0/*0.f Q13*/, 0/*0.f Q13*/, 0/*0.f Q13*/}, - /* strong */ { 23101/*2.82f Q13*/, 0/*0.f Q13*/, 0/*0.f Q13*/, 0/*0.f Q13*/} - }, - /* 14: for 128000 kbs FB */ - { - /* medium */ { 0/*0.f Q13*/, 0/*0.f Q13*/, 0/*0.f Q13*/, 0/*0.f Q13*/}, - /* strong */ { 23101/*2.82f Q13*/, 0/*0.f Q13*/, 0/*0.f Q13*/, 0/*0.f Q13*/} - } -}; - - -/* IGF SCF arithmetic coder cumulative frequency tables and offsets */ -const Word16 cf_off_se01_tab[9] = -{ - +1, /* 9.6 kbs B*/ - +1, /* 13.2 kbs WB RF B*/ - +1, /* 9.6 kbs SWB B*/ - +1, /* 13.2 kbs A*/ - +1, /* 13.2 kbs SWB RF B*/ - +1, /* 16.4 kbs B*/ - +1, /* 24.4 kbs B*/ - +1, /* 32.0 kbs A*/ - -1 /* 48.0 kbs B*/ -}; - -const Word16 cf_off_se02_tab[9][IGF_CTX_COUNT] = -{ - { +1, +2, +2, +2, +3, +3, +4}, /* 9.6 kbs B*/ - { +1, +2, +2, +2, +3, +3, +4}, /* 13.2 kbs WB RF B*/ - { +0, +2, +3, +3, +2, +2, +4}, /* 9.6 kbs SWB B*/ - { +0, +2, +3, +3, +2, +2, +4}, /* 13.2 kbs A*/ - { +0, +2, +3, +3, +2, +2, +4}, /* 13.2 kbs SWB RF B*/ - { +0, +2, +3, +3, +2, +2, +4}, /* 16.4 kbs B*/ - { -1, +2, +2, +2, +2, +3, +5}, /* 24.4 kbs B*/ - { -1, +2, +2, +2, +2, +3, +5}, /* 32.0 kbs A*/ - { +3, +2, +3, +2, +3, +3, +6} /* 48.0 kbs B*/ -}; - -const Word16 cf_off_se10_tab = -7; - -const Word16 cf_off_se11_tab[IGF_CTX_COUNT][IGF_CTX_COUNT] = -{ - { -5, +0, +0, +0, +0, +0, +0}, - { +0, +0, +0, +0, +0, +0, +0}, - { +0, +0, +0, +0, +0, +0, +0}, - { +0, +0, +0, +0, +0, +0, +0}, - { +0, +0, +0, +0, +0, +0, +0}, - { +0, +0, +0, +0, +0, +0, +1}, - { +0, +1, +0, +0, +3, +0, +3} -}; - -const Word16 cf_se00_tab[IGF_SYMBOLS_IN_TABLE + 1] = -{ - 16384, 16356, 16299, 16185, 15904, 15282, 14669, 13598, 11886, 9541, 6613, 3845, 1799, 606, 153, 32, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0 -}; - -const Word16 cf_se01_tab[9][IGF_SYMBOLS_IN_TABLE + 1] = -{ - {16384, 16320, 16285, 16237, 16163, 16049, 15864, 15604, 15187, 14557, 13612, 12308, 10590, 8535, 6346, 4396, 2900, 1917, 1289, 870, 593, 408, 279, 181, 122, 78, 52, 0}, /* 9.6 kbs B*/ - {16384, 16320, 16285, 16237, 16163, 16049, 15864, 15604, 15187, 14557, 13612, 12308, 10590, 8535, 6346, 4396, 2900, 1917, 1289, 870, 593, 408, 279, 181, 122, 78, 52, 0}, /* 13.2 kbs WB RF B*/ - {16384, 16375, 16362, 16339, 16307, 16258, 16180, 16061, 15845, 15463, 14795, 13680, 11828, 9252, 6358, 3769, 2079, 1186, 687, 415, 242, 150, 100, 67, 44, 30, 19, 0}, /* 9.6 kbs SWB B*/ - {16384, 16375, 16362, 16339, 16307, 16258, 16180, 16061, 15845, 15463, 14795, 13680, 11828, 9252, 6358, 3769, 2079, 1186, 687, 415, 242, 150, 100, 67, 44, 30, 19, 0}, /* 13.2 kbs A*/ - {16384, 16375, 16362, 16339, 16307, 16258, 16180, 16061, 15845, 15463, 14795, 13680, 11828, 9252, 6358, 3769, 2079, 1186, 687, 415, 242, 150, 100, 67, 44, 30, 19, 0}, /* 13.2 kbs SWB RF B*/ - {16384, 16375, 16362, 16339, 16307, 16258, 16180, 16061, 15845, 15463, 14795, 13680, 11828, 9252, 6358, 3769, 2079, 1186, 687, 415, 242, 150, 100, 67, 44, 30, 19, 0}, /* 16.4 kbs B*/ - {16384, 16369, 16356, 16337, 16311, 16268, 16197, 16073, 15876, 15544, 14977, 13987, 12327, 9908, 7017, 4393, 2545, 1446, 840, 493, 292, 183, 111, 70, 45, 31, 20, 0}, /* 24.4 kbs B*/ - {16384, 16369, 16356, 16337, 16311, 16268, 16197, 16073, 15876, 15544, 14977, 13987, 12327, 9908, 7017, 4393, 2545, 1446, 840, 493, 292, 183, 111, 70, 45, 31, 20, 0}, /* 32.0 kbs A*/ - {16384, 16368, 16355, 16334, 16291, 16212, 16071, 15816, 15359, 14523, 13014, 10534, 7345, 4272, 2228, 1149, 626, 357, 215, 139, 93, 67, 53, 43, 36, 28, 22, 0} /* 48.0 kbs B*/ -}; - - -const Word16 cf_se02_tab[9][IGF_CTX_COUNT][IGF_SYMBOLS_IN_TABLE + 1] = -{ - { /* 9.6 kbs B */ - { 16384, 16369, 16348, 16316, 16256, 16172, 16017, 15735, 15246, 14363, 13036, 11139, 8916, 6724, 4757, 3282, 2221, 1549, 1105, 771, 548, 364, 238, 151, 89, 50, 30, 0}, - { 16384, 16371, 16358, 16339, 16290, 16241, 16153, 16040, 15813, 15397, 14601, 13301, 11360, 8916, 6254, 3911, 2220, 1280, 755, 461, 278, 177, 111, 70, 35, 20, 12, 0}, - { 16384, 16375, 16359, 16333, 16286, 16243, 16154, 16024, 15771, 15380, 14712, 13537, 11742, 9425, 6872, 4378, 2327, 1197, 671, 412, 259, 145, 93, 52, 26, 13, 5, 0}, - { 16384, 16372, 16358, 16326, 16289, 16241, 16147, 16014, 15765, 15321, 14670, 13546, 11912, 9787, 7323, 4824, 2536, 1330, 731, 438, 258, 148, 86, 37, 22, 11, 2, 0}, - { 16384, 16376, 16364, 16344, 16315, 16272, 16219, 16119, 15910, 15620, 15100, 14254, 13063, 11489, 9413, 7100, 4738, 2751, 1584, 973, 597, 349, 201, 96, 47, 22, 9, 0}, - { 16384, 16364, 16340, 16312, 16288, 16237, 16166, 16026, 15756, 15390, 14833, 13870, 12627, 10998, 8985, 6893, 4720, 3048, 1860, 1131, 725, 449, 215, 111, 56, 34, 14, 0}, - { 16384, 16326, 16297, 16246, 16183, 16064, 15884, 15632, 15240, 14763, 14107, 13230, 12185, 10886, 9390, 7781, 6194, 4696, 3350, 2259, 1506, 975, 604, 356, 201, 106, 48, 0} - }, - { /* 13.2 kbs WB RF B*/ - { 16384, 16369, 16348, 16316, 16256, 16172, 16017, 15735, 15246, 14363, 13036, 11139, 8916, 6724, 4757, 3282, 2221, 1549, 1105, 771, 548, 364, 238, 151, 89, 50, 30, 0}, - { 16384, 16371, 16358, 16339, 16290, 16241, 16153, 16040, 15813, 15397, 14601, 13301, 11360, 8916, 6254, 3911, 2220, 1280, 755, 461, 278, 177, 111, 70, 35, 20, 12, 0}, - { 16384, 16375, 16359, 16333, 16286, 16243, 16154, 16024, 15771, 15380, 14712, 13537, 11742, 9425, 6872, 4378, 2327, 1197, 671, 412, 259, 145, 93, 52, 26, 13, 5, 0}, - { 16384, 16372, 16358, 16326, 16289, 16241, 16147, 16014, 15765, 15321, 14670, 13546, 11912, 9787, 7323, 4824, 2536, 1330, 731, 438, 258, 148, 86, 37, 22, 11, 2, 0}, - { 16384, 16376, 16364, 16344, 16315, 16272, 16219, 16119, 15910, 15620, 15100, 14254, 13063, 11489, 9413, 7100, 4738, 2751, 1584, 973, 597, 349, 201, 96, 47, 22, 9, 0}, - { 16384, 16364, 16340, 16312, 16288, 16237, 16166, 16026, 15756, 15390, 14833, 13870, 12627, 10998, 8985, 6893, 4720, 3048, 1860, 1131, 725, 449, 215, 111, 56, 34, 14, 0}, - { 16384, 16326, 16297, 16246, 16183, 16064, 15884, 15632, 15240, 14763, 14107, 13230, 12185, 10886, 9390, 7781, 6194, 4696, 3350, 2259, 1506, 975, 604, 356, 201, 106, 48, 0} - }, - { /* 9.6 kbs SWB B*/ - { 16384, 16359, 16349, 16331, 16300, 16236, 16112, 15894, 15480, 14691, 13257, 10996, 8168, 5357, 3193, 1864, 1098, 676, 426, 265, 173, 117, 81, 59, 45, 35, 26, 0}, - { 16384, 16374, 16370, 16367, 16362, 16348, 16325, 16283, 16204, 16058, 15715, 14980, 13521, 11144, 7972, 4702, 2366, 1063, 480, 241, 128, 71, 42, 22, 14, 9, 5, 0}, - { 16384, 16380, 16377, 16375, 16372, 16365, 16354, 16334, 16295, 16216, 16056, 15716, 15034, 13690, 11467, 8404, 5150, 2385, 908, 417, 199, 106, 62, 35, 21, 13, 7, 0}, - { 16384, 16378, 16376, 16373, 16368, 16360, 16346, 16318, 16267, 16173, 15991, 15644, 14932, 13623, 11575, 8688, 5224, 2309, 891, 393, 202, 103, 57, 34, 20, 11, 8, 0}, - { 16384, 16375, 16372, 16365, 16348, 16322, 16279, 16201, 16046, 15728, 15214, 14297, 12811, 10673, 7918, 4530, 2109, 978, 466, 234, 121, 72, 46, 31, 25, 17, 13, 0}, - { 16384, 16366, 16357, 16341, 16325, 16289, 16220, 16084, 15768, 15300, 14466, 13206, 11402, 9176, 6633, 4092, 2192, 1171, 592, 315, 179, 111, 74, 46, 31, 26, 18, 0}, - { 16384, 16301, 16266, 16211, 16140, 16045, 15889, 15652, 15358, 14883, 14192, 13119, 11753, 10181, 8445, 6708, 5023, 3449, 2226, 1375, 849, 516, 353, 231, 153, 107, 78, 0} - }, - { /* 13.2 kbs A */ - { 16384, 16359, 16349, 16331, 16300, 16236, 16112, 15894, 15480, 14691, 13257, 10996, 8168, 5357, 3193, 1864, 1098, 676, 426, 265, 173, 117, 81, 59, 45, 35, 26, 0}, - { 16384, 16374, 16370, 16367, 16362, 16348, 16325, 16283, 16204, 16058, 15715, 14980, 13521, 11144, 7972, 4702, 2366, 1063, 480, 241, 128, 71, 42, 22, 14, 9, 5, 0}, - { 16384, 16380, 16377, 16375, 16372, 16365, 16354, 16334, 16295, 16216, 16056, 15716, 15034, 13690, 11467, 8404, 5150, 2385, 908, 417, 199, 106, 62, 35, 21, 13, 7, 0}, - { 16384, 16378, 16376, 16373, 16368, 16360, 16346, 16318, 16267, 16173, 15991, 15644, 14932, 13623, 11575, 8688, 5224, 2309, 891, 393, 202, 103, 57, 34, 20, 11, 8, 0}, - { 16384, 16375, 16372, 16365, 16348, 16322, 16279, 16201, 16046, 15728, 15214, 14297, 12811, 10673, 7918, 4530, 2109, 978, 466, 234, 121, 72, 46, 31, 25, 17, 13, 0}, - { 16384, 16366, 16357, 16341, 16325, 16289, 16220, 16084, 15768, 15300, 14466, 13206, 11402, 9176, 6633, 4092, 2192, 1171, 592, 315, 179, 111, 74, 46, 31, 26, 18, 0}, - { 16384, 16301, 16266, 16211, 16140, 16045, 15889, 15652, 15358, 14883, 14192, 13119, 11753, 10181, 8445, 6708, 5023, 3449, 2226, 1375, 849, 516, 353, 231, 153, 107, 78, 0} - }, - { /* 13.2 kbs SWB RF B*/ - { 16384, 16359, 16349, 16331, 16300, 16236, 16112, 15894, 15480, 14691, 13257, 10996, 8168, 5357, 3193, 1864, 1098, 676, 426, 265, 173, 117, 81, 59, 45, 35, 26, 0}, - { 16384, 16374, 16370, 16367, 16362, 16348, 16325, 16283, 16204, 16058, 15715, 14980, 13521, 11144, 7972, 4702, 2366, 1063, 480, 241, 128, 71, 42, 22, 14, 9, 5, 0}, - { 16384, 16380, 16377, 16375, 16372, 16365, 16354, 16334, 16295, 16216, 16056, 15716, 15034, 13690, 11467, 8404, 5150, 2385, 908, 417, 199, 106, 62, 35, 21, 13, 7, 0}, - { 16384, 16378, 16376, 16373, 16368, 16360, 16346, 16318, 16267, 16173, 15991, 15644, 14932, 13623, 11575, 8688, 5224, 2309, 891, 393, 202, 103, 57, 34, 20, 11, 8, 0}, - { 16384, 16375, 16372, 16365, 16348, 16322, 16279, 16201, 16046, 15728, 15214, 14297, 12811, 10673, 7918, 4530, 2109, 978, 466, 234, 121, 72, 46, 31, 25, 17, 13, 0}, - { 16384, 16366, 16357, 16341, 16325, 16289, 16220, 16084, 15768, 15300, 14466, 13206, 11402, 9176, 6633, 4092, 2192, 1171, 592, 315, 179, 111, 74, 46, 31, 26, 18, 0}, - { 16384, 16301, 16266, 16211, 16140, 16045, 15889, 15652, 15358, 14883, 14192, 13119, 11753, 10181, 8445, 6708, 5023, 3449, 2226, 1375, 849, 516, 353, 231, 153, 107, 78, 0} - }, - { /* 16.4 kbs B */ - { 16384, 16359, 16349, 16331, 16300, 16236, 16112, 15894, 15480, 14691, 13257, 10996, 8168, 5357, 3193, 1864, 1098, 676, 426, 265, 173, 117, 81, 59, 45, 35, 26, 0}, - { 16384, 16374, 16370, 16367, 16362, 16348, 16325, 16283, 16204, 16058, 15715, 14980, 13521, 11144, 7972, 4702, 2366, 1063, 480, 241, 128, 71, 42, 22, 14, 9, 5, 0}, - { 16384, 16380, 16377, 16375, 16372, 16365, 16354, 16334, 16295, 16216, 16056, 15716, 15034, 13690, 11467, 8404, 5150, 2385, 908, 417, 199, 106, 62, 35, 21, 13, 7, 0}, - { 16384, 16378, 16376, 16373, 16368, 16360, 16346, 16318, 16267, 16173, 15991, 15644, 14932, 13623, 11575, 8688, 5224, 2309, 891, 393, 202, 103, 57, 34, 20, 11, 8, 0}, - { 16384, 16375, 16372, 16365, 16348, 16322, 16279, 16201, 16046, 15728, 15214, 14297, 12811, 10673, 7918, 4530, 2109, 978, 466, 234, 121, 72, 46, 31, 25, 17, 13, 0}, - { 16384, 16366, 16357, 16341, 16325, 16289, 16220, 16084, 15768, 15300, 14466, 13206, 11402, 9176, 6633, 4092, 2192, 1171, 592, 315, 179, 111, 74, 46, 31, 26, 18, 0}, - { 16384, 16301, 16266, 16211, 16140, 16045, 15889, 15652, 15358, 14883, 14192, 13119, 11753, 10181, 8445, 6708, 5023, 3449, 2226, 1375, 849, 516, 353, 231, 153, 107, 78, 0} - }, - { /* 24.4 kbs B */ - { 16384, 16351, 16333, 16303, 16254, 16163, 15993, 15681, 15080, 13987, 12109, 9465, 6588, 4160, 2488, 1480, 912, 589, 389, 266, 190, 131, 93, 68, 47, 34, 24, 0}, - { 16384, 16379, 16375, 16369, 16360, 16345, 16328, 16286, 16211, 16078, 15810, 15233, 14058, 11933, 8881, 5609, 2940, 1290, 558, 274, 150, 80, 47, 29, 17, 11, 6, 0}, - { 16384, 16382, 16380, 16377, 16370, 16358, 16337, 16300, 16224, 16088, 15811, 15233, 14112, 12019, 9061, 5723, 2780, 1121, 480, 239, 123, 69, 41, 22, 13, 8, 5, 0}, - { 16384, 16377, 16375, 16369, 16363, 16351, 16325, 16268, 16172, 16009, 15686, 15039, 13830, 11799, 8924, 5422, 2444, 960, 441, 220, 111, 63, 37, 22, 11, 6, 3, 0}, - { 16384, 16374, 16369, 16363, 16356, 16335, 16290, 16214, 16068, 15826, 15382, 14550, 13126, 10956, 8000, 4622, 2090, 973, 478, 249, 128, 75, 42, 19, 13, 7, 4, 0}, - { 16384, 16375, 16370, 16367, 16362, 16340, 16298, 16232, 16097, 15860, 15440, 14718, 13570, 11874, 9557, 6790, 4053, 2166, 1150, 622, 323, 179, 96, 53, 33, 17, 12, 0}, - { 16384, 16335, 16304, 16276, 16228, 16166, 16094, 15983, 15775, 15501, 15040, 14417, 13552, 12326, 10847, 9117, 7308, 5373, 3666, 2297, 1336, 807, 495, 313, 216, 152, 114, 0} - }, - { /* 32.0 kbs A */ - { 16384, 16351, 16333, 16303, 16254, 16163, 15993, 15681, 15080, 13987, 12109, 9465, 6588, 4160, 2488, 1480, 912, 589, 389, 266, 190, 131, 93, 68, 47, 34, 24, 0}, - { 16384, 16379, 16375, 16369, 16360, 16345, 16328, 16286, 16211, 16078, 15810, 15233, 14058, 11933, 8881, 5609, 2940, 1290, 558, 274, 150, 80, 47, 29, 17, 11, 6, 0}, - { 16384, 16382, 16380, 16377, 16370, 16358, 16337, 16300, 16224, 16088, 15811, 15233, 14112, 12019, 9061, 5723, 2780, 1121, 480, 239, 123, 69, 41, 22, 13, 8, 5, 0}, - { 16384, 16377, 16375, 16369, 16363, 16351, 16325, 16268, 16172, 16009, 15686, 15039, 13830, 11799, 8924, 5422, 2444, 960, 441, 220, 111, 63, 37, 22, 11, 6, 3, 0}, - { 16384, 16374, 16369, 16363, 16356, 16335, 16290, 16214, 16068, 15826, 15382, 14550, 13126, 10956, 8000, 4622, 2090, 973, 478, 249, 128, 75, 42, 19, 13, 7, 4, 0}, - { 16384, 16375, 16370, 16367, 16362, 16340, 16298, 16232, 16097, 15860, 15440, 14718, 13570, 11874, 9557, 6790, 4053, 2166, 1150, 622, 323, 179, 96, 53, 33, 17, 12, 0}, - { 16384, 16335, 16304, 16276, 16228, 16166, 16094, 15983, 15775, 15501, 15040, 14417, 13552, 12326, 10847, 9117, 7308, 5373, 3666, 2297, 1336, 807, 495, 313, 216, 152, 114, 0} - }, - { /* 48.0 kbs B */ - { 16384, 16334, 16310, 16285, 16254, 16204, 16128, 16031, 15903, 15697, 15380, 14820, 13857, 12267, 9878, 7099, 4509, 2576, 1478, 871, 531, 349, 230, 163, 111, 80, 62, 0}, - { 16384, 16337, 16327, 16307, 16278, 16239, 16178, 16092, 15947, 15719, 15286, 14428, 12833, 10246, 7123, 4088, 1896, 849, 481, 287, 190, 139, 94, 66, 52, 34, 24, 0}, - { 16384, 16352, 16341, 16329, 16312, 16295, 16265, 16223, 16151, 16026, 15825, 15437, 14645, 13089, 10612, 7364, 4077, 1783, 779, 444, 281, 192, 138, 93, 65, 43, 30, 0}, - { 16384, 16354, 16347, 16337, 16314, 16284, 16233, 16165, 16051, 15847, 15450, 14621, 13069, 10623, 7298, 3789, 1569, 727, 445, 302, 207, 143, 96, 59, 36, 18, 9, 0}, - { 16384, 16352, 16342, 16330, 16314, 16295, 16266, 16215, 16127, 15984, 15709, 15190, 14242, 12540, 9979, 6448, 3160, 1392, 752, 481, 344, 251, 169, 115, 73, 28, 8, 0}, - { 16384, 16340, 16320, 16302, 16272, 16257, 16220, 16135, 16011, 15784, 15370, 14688, 13423, 11457, 8721, 5529, 2736, 1375, 784, 525, 353, 263, 172, 113, 78, 26, 11, 0}, - { 16384, 16238, 16170, 16113, 16077, 16030, 16000, 15948, 15873, 15752, 15535, 15157, 14595, 13788, 12569, 10767, 8611, 6186, 4101, 2459, 1478, 881, 607, 385, 243, 168, 116, 0} - } -}; - -/* only needed for >= 48 kbs */ - -const Word16 cf_se10_tab[IGF_SYMBOLS_IN_TABLE + 1] = -{ - 16384, 15493, 15154, 14810, 14331, 13701, 13086, 12403, 11585, 10923, 10293, 9631, 8943, 8385, 7760, 7182, 6593, 6009, 5540, 5082, 4571, 4133, 3711, 3299, 2887, 2460, 2043, 0 -}; - -const Word16 cf_se11_tab[IGF_CTX_COUNT][IGF_CTX_COUNT][IGF_SYMBOLS_IN_TABLE + 1] = -{ - { - { 16384, 16313, 16312, 16241, 16206, 16099, 15957, 15386, 14601, 12852, 10282, 7534, 4964, 2966, 1824, 896, 504, 255, 113, 112, 41, 40, 39, 38, 37, 36, 1, 0}, - { 16384, 16383, 16382, 16381, 16380, 16379, 16378, 16207, 16206, 16205, 16120, 15949, 14663, 12777, 9947, 6860, 3773, 1972, 772, 430, 259, 174, 89, 4, 3, 2, 1, 0}, - { 16384, 16383, 16382, 16381, 16380, 16379, 16378, 16377, 16376, 16115, 15941, 14891, 12965, 11477, 8587, 5347, 3421, 1407, 620, 8, 7, 6, 5, 4, 3, 2, 1, 0}, - { 16384, 16383, 16382, 16381, 16380, 16379, 16378, 16254, 16253, 16004, 15005, 13756, 12006, 9256, 5755, 3755, 1755, 756, 132, 131, 130, 129, 5, 4, 3, 2, 1, 0}, - { 16384, 16383, 16382, 16381, 16380, 16379, 16378, 16377, 15964, 15550, 14929, 12856, 9954, 6430, 2906, 1456, 1042, 628, 214, 8, 7, 6, 5, 4, 3, 2, 1, 0}, - { 16384, 16383, 16382, 16381, 16380, 16379, 16378, 16087, 15503, 14334, 14333, 11994, 10240, 8193, 5268, 2929, 1760, 1176, 299, 298, 297, 296, 295, 294, 293, 2, 1, 0}, - { 16384, 16383, 16382, 16381, 16380, 16379, 16378, 16377, 14922, 13467, 10919, 9464, 7280, 6189, 3641, 2914, 2187, 1824, 1823, 1096, 369, 368, 367, 4, 3, 2, 1, 0} - }, - { - { 16384, 16383, 16382, 16381, 16380, 16379, 16378, 16377, 16238, 16237, 15678, 15399, 14840, 13441, 11341, 8681, 6161, 3781, 2522, 702, 283, 144, 5, 4, 3, 2, 1, 0}, - { 16384, 16383, 16382, 16381, 16380, 16379, 16378, 16377, 16376, 16375, 16374, 15693, 14671, 12625, 7507, 4778, 2390, 1368, 1028, 347, 7, 6, 5, 4, 3, 2, 1, 0}, - { 16384, 16383, 16382, 16381, 16380, 16379, 16378, 16377, 16376, 16375, 16374, 15595, 13776, 9877, 6498, 3639, 3120, 1561, 1042, 523, 265, 6, 5, 4, 3, 2, 1, 0}, - { 16384, 16383, 16382, 16381, 16380, 16379, 16378, 16377, 16376, 15709, 13704, 12702, 11032, 7355, 3010, 1340, 1007, 674, 341, 8, 7, 6, 5, 4, 3, 2, 1, 0}, - { 16384, 16383, 16382, 16381, 16380, 16379, 16378, 16377, 16376, 16375, 16374, 12816, 10683, 7125, 2854, 720, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0}, - { 16384, 16383, 16382, 16381, 16380, 16379, 16378, 16377, 16376, 16375, 12738, 12737, 10920, 9103, 5466, 1828, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0}, - { 16384, 16383, 16382, 16381, 16380, 15359, 15358, 14337, 14336, 14335, 14334, 14333, 10240, 7170, 5124, 2054, 1032, 1031, 1030, 1029, 7, 6, 5, 4, 3, 2, 1, 0} - }, - { - { 16384, 16383, 16382, 16107, 16106, 16105, 16104, 16103, 15966, 15965, 15690, 15140, 14315, 12939, 10324, 8122, 4956, 2479, 1654, 966, 691, 416, 141, 140, 3, 2, 1, 0}, - { 16384, 16383, 16382, 16381, 16380, 16379, 16378, 16377, 16376, 16375, 15320, 14265, 12945, 10568, 8984, 6343, 4230, 1853, 797, 270, 7, 6, 5, 4, 3, 2, 1, 0}, - { 16384, 16383, 16382, 16381, 16380, 16379, 16112, 16111, 16110, 15037, 14501, 12622, 11012, 7790, 5374, 3226, 1347, 542, 275, 274, 273, 6, 5, 4, 3, 2, 1, 0}, - { 16384, 16383, 16382, 16381, 16380, 16379, 16378, 16377, 16376, 16375, 15597, 14819, 12090, 7021, 4292, 1953, 1175, 787, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0}, - { 16384, 16383, 16382, 16381, 16380, 16379, 16378, 16377, 16376, 15935, 14165, 12838, 9297, 6641, 3985, 1772, 1331, 890, 449, 8, 7, 6, 5, 4, 3, 2, 1, 0}, - { 16384, 16383, 16382, 16381, 16380, 16379, 16378, 16377, 16376, 14740, 13923, 9010, 6555, 4100, 2464, 828, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0}, - { 16384, 16383, 16382, 16381, 16380, 16379, 16378, 16377, 16376, 13104, 13103, 8192, 4920, 1647, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0} - }, - { - { 16384, 16383, 16382, 16381, 16380, 16379, 16378, 16377, 16077, 16076, 16075, 15926, 15176, 14425, 10819, 7664, 5711, 2856, 1354, 754, 454, 154, 5, 4, 3, 2, 1, 0}, - { 16384, 16383, 16382, 16381, 16380, 16379, 16378, 16377, 16376, 16044, 16043, 14373, 12369, 10030, 7023, 5019, 1677, 676, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0}, - { 16384, 16383, 16382, 16381, 16380, 16379, 16378, 16077, 16076, 16075, 15470, 14258, 12743, 11531, 6375, 3040, 3039, 917, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0}, - { 16384, 16383, 16382, 16381, 16380, 16379, 16378, 16377, 16376, 16375, 15309, 13531, 11396, 7480, 3564, 1786, 364, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0}, - { 16384, 16383, 16382, 16381, 16380, 16379, 16378, 16377, 15833, 15289, 13652, 10377, 6556, 3827, 3283, 1646, 555, 554, 553, 552, 7, 6, 5, 4, 3, 2, 1, 0}, - { 16384, 16383, 16382, 16381, 16380, 16379, 16378, 14146, 13404, 13403, 13402, 10425, 7448, 3727, 2240, 2239, 752, 751, 750, 749, 7, 6, 5, 4, 3, 2, 1, 0}, - { 16384, 16383, 16382, 16381, 16380, 16379, 15562, 14745, 13928, 10653, 7378, 5742, 2467, 830, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0} - }, - { - { 16384, 16383, 16382, 16381, 16380, 16379, 16378, 16377, 16376, 16375, 16219, 15590, 14803, 13544, 11339, 9292, 6930, 4568, 2521, 1419, 790, 318, 161, 4, 3, 2, 1, 0}, - { 16384, 16383, 16382, 16381, 16380, 16379, 16378, 16377, 16376, 16014, 15652, 14925, 14198, 12743, 10196, 5464, 3645, 1826, 371, 8, 7, 6, 5, 4, 3, 2, 1, 0}, - { 16384, 16383, 16382, 16381, 16380, 16379, 16378, 16377, 16376, 16050, 15396, 15395, 12447, 10810, 8518, 4915, 2950, 1313, 659, 333, 7, 6, 5, 4, 3, 2, 1, 0}, - { 16384, 16383, 16382, 16381, 16380, 16379, 16378, 16377, 16376, 16375, 14792, 14001, 11096, 8455, 6079, 3174, 2119, 535, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0}, - { 16384, 16383, 16382, 16381, 16380, 16379, 16378, 15796, 15795, 15794, 15793, 11700, 8777, 6439, 4101, 1178, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0}, - { 16384, 16383, 16382, 16381, 15473, 15472, 15471, 14563, 13655, 12746, 10017, 7288, 6379, 6378, 4559, 1830, 1829, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0}, - { 16384, 16383, 16382, 16381, 16380, 16379, 16378, 16377, 15723, 15069, 13105, 9174, 7865, 3934, 3280, 1971, 1317, 663, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0} - }, - { - { 16384, 16383, 16382, 16381, 16232, 16231, 16230, 16229, 16228, 16227, 16078, 15628, 15329, 13977, 12325, 10222, 5413, 4212, 1959, 908, 7, 6, 5, 4, 3, 2, 1, 0}, - { 16384, 16383, 16382, 16381, 16380, 16379, 16378, 16377, 16376, 16109, 15842, 15841, 13694, 11815, 10205, 5640, 3493, 2151, 1347, 543, 542, 6, 5, 4, 3, 2, 1, 0}, - { 16384, 16383, 16382, 16381, 16380, 16379, 16378, 16377, 16376, 16168, 14699, 13650, 11761, 9452, 6093, 3784, 1685, 636, 427, 426, 425, 424, 423, 422, 421, 2, 1, 0}, - { 16384, 16383, 16382, 16381, 16380, 16379, 16378, 16377, 16376, 16122, 15611, 14332, 13053, 10238, 7423, 4608, 2561, 2050, 1027, 516, 515, 260, 259, 258, 257, 2, 1, 0}, - { 16384, 16383, 16382, 16381, 16380, 16379, 16378, 16377, 16376, 16375, 15207, 13649, 10531, 6632, 3514, 1176, 398, 397, 396, 395, 394, 393, 5, 4, 3, 2, 1, 0}, - { 16384, 16383, 16382, 16381, 16380, 16379, 16378, 16377, 15749, 15120, 12601, 10082, 8823, 6304, 3785, 3156, 1267, 638, 637, 636, 7, 6, 5, 4, 3, 2, 1, 0}, - { 16384, 16383, 15729, 15728, 15727, 15726, 15725, 15071, 14417, 12453, 10489, 8525, 5905, 1975, 1321, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0} - }, - { - { 16384, 16383, 16372, 16340, 16339, 16328, 16285, 16253, 16136, 15923, 15614, 14931, 13833, 12201, 10175, 7615, 5269, 3243, 2123, 1142, 673, 342, 182, 150, 86, 54, 11, 0}, - { 16384, 16383, 16366, 16349, 16332, 16331, 16314, 16245, 16244, 16141, 15813, 15451, 14105, 12672, 9910, 7113, 4472, 2590, 1071, 484, 294, 156, 53, 36, 19, 18, 1, 0}, - { 16384, 16383, 16382, 16369, 16355, 16341, 16271, 16117, 15921, 15627, 14772, 13089, 10929, 8334, 5487, 3299, 1644, 999, 424, 228, 88, 46, 18, 17, 16, 15, 14, 0}, - { 16384, 16367, 16366, 16365, 16364, 16363, 16259, 16173, 15809, 15028, 13951, 12214, 9278, 6203, 3719, 2052, 1079, 402, 194, 125, 56, 22, 21, 20, 3, 2, 1, 0}, - { 16384, 16383, 16360, 16359, 16358, 16357, 16356, 16333, 16332, 16143, 15954, 15434, 14227, 12262, 9540, 6652, 3882, 1988, 1207, 829, 427, 191, 73, 50, 49, 2, 1, 0}, - { 16384, 16383, 16382, 16381, 16380, 16296, 16254, 15748, 14862, 13427, 11189, 8487, 5278, 3252, 2028, 1099, 551, 340, 298, 214, 172, 88, 46, 45, 3, 2, 1, 0}, - { 16384, 16383, 16307, 16269, 16231, 16230, 16077, 15886, 15464, 14620, 13546, 11896, 9671, 7024, 4338, 2382, 1423, 809, 541, 311, 158, 43, 5, 4, 3, 2, 1, 0} - } -}; - - -/**********************************************************************/ /** -igf settings table for each bitrate mode -**************************************************************************/ -const IGF_MODE igfMode[15] = -{ - /* sampleRate, frameLength, bitRate, igfMinFq, transFac, maxHopsize */ - { 16000, 320, 9600, 774, 20480/*1.25f Q14*/, 4 }, /* 9.6kbs WB 0 */ - { 16000, 320, 13200, 774, 20480/*1.25f Q14*/, 4 }, /* 13.2kbs WB RF 1 */ - { 32000, 640, 9600, 800, 20480/*1.25f Q14*/, 2 }, /* 9.6kbs SWB 2 */ - { 32000, 640, 13200, 800, 20480/*1.25f Q14*/, 4 }, /* 13.2kbs SWB 3 */ - { 32000, 640, 13200, 800, 20480/*1.25f Q14*/, 2 }, /* 13.2kbs SWB RF 4 */ - { 32000, 640, 16400, 800, 20480/*1.25f Q14*/, 4 }, /* 16.4kbs SWB 5 */ - { 32000, 640, 24400, 800, 20480/*1.25f Q14*/, 4 }, /* 24.4kbs SWB 6 */ - { 32000, 640, 32000, 800, 20480/*1.25f Q14*/, 4 }, /* 32.0kbs SWB 7 */ - { 32000, 640, 48000, 1600, 20480/*1.25f Q14*/, 4 }, /* 48.0kbs SWB 8 */ - { 48000, 960, 16400, 800, 20480/*1.25f Q14*/, 4 }, /* 16.4kbs FB 9 */ - { 48000, 960, 24400, 800, 20480/*1.25f Q14*/, 2 }, /* 24.4kbs FB 10 */ - { 48000, 960, 32000, 800, 20480/*1.25f Q14*/, 2 }, /* 32.0kbs FB 11 */ - { 48000, 960, 48000, 1600, 20480/*1.25f Q14*/, 2 }, /* 48.0kbs FB 12 */ - { 48000, 960, 96000, 1600, 8192/*0.50f Q14*/, 1 }, /* 96.0kbs FB 13 */ - { 48000, 960, 128000, 1600, 8192/*0.50f Q14*/, 1 } /*128.0kbs FB 14 */ -}; - -const Word32 bwMode2fs[4] = { 8000, 16000, 32000, 48000 }; - -const PWord16 w1N8[15] = -{ - {{ 32729/*0.998795 Q15*/, -1608/*-0.049068 Q15*/}}, - {{ 32610/*0.995185 Q15*/, -3212/*-0.098017 Q15*/}}, - {{ 32413/*0.989177 Q15*/, -4808/*-0.146730 Q15*/}}, - {{ 32138/*0.980785 Q15*/, -6393/*-0.195090 Q15*/}}, - {{ 31786/*0.970031 Q15*/, -7962/*-0.242980 Q15*/}}, - {{ 31357/*0.956940 Q15*/, -9512/*-0.290285 Q15*/}}, - {{ 30853/*0.941544 Q15*/, -11039/*-0.336890 Q15*/}}, - {{ 30274/*0.923880 Q15*/, -12540/*-0.382683 Q15*/}}, - {{ 29622/*0.903989 Q15*/, -14010/*-0.427555 Q15*/}}, - {{ 28899/*0.881921 Q15*/, -15447/*-0.471397 Q15*/}}, - {{ 28106/*0.857729 Q15*/, -16846/*-0.514103 Q15*/}}, - {{ 27246/*0.831470 Q15*/, -18205/*-0.555570 Q15*/}}, - {{ 26320/*0.803208 Q15*/, -19520/*-0.595699 Q15*/}}, - {{ 25330/*0.773010 Q15*/, -20788/*-0.634393 Q15*/}}, - {{ 24279/*0.740951 Q15*/, -22006/*-0.671559 Q15*/}} -}; - -const PWord16 w2N8[15] = -{ - {{ 32610/*0.995185 Q15*/, -3212/*-0.098017 Q15*/}}, - {{ 32138/*0.980785 Q15*/, -6393/*-0.195090 Q15*/}}, - {{ 31357/*0.956940 Q15*/, -9512/*-0.290285 Q15*/}}, - {{ 30274/*0.923880 Q15*/, -12540/*-0.382683 Q15*/}}, - {{ 28899/*0.881921 Q15*/, -15447/*-0.471397 Q15*/}}, - {{ 27246/*0.831470 Q15*/, -18205/*-0.555570 Q15*/}}, - {{ 25330/*0.773010 Q15*/, -20788/*-0.634393 Q15*/}}, - {{ 23170/*0.707107 Q15*/, -23170/*-0.707107 Q15*/}}, - {{ 20788/*0.634393 Q15*/, -25330/*-0.773010 Q15*/}}, - {{ 18205/*0.555570 Q15*/, -27246/*-0.831470 Q15*/}}, - {{ 15447/*0.471397 Q15*/, -28899/*-0.881921 Q15*/}}, - {{ 12540/*0.382683 Q15*/, -30274/*-0.923880 Q15*/}}, - {{ 9512/*0.290285 Q15*/, -31357/*-0.956940 Q15*/}}, - {{ 6393/*0.195090 Q15*/, -32138/*-0.980785 Q15*/}}, - {{ 3212/*0.098017 Q15*/, -32610/*-0.995185 Q15*/}} -}; - -const PWord16 w3N8[15] = -{ - {{ 32413/*0.989177 Q15*/, -4808/*-0.146730 Q15*/}}, - {{ 31357/*0.956940 Q15*/, -9512/*-0.290285 Q15*/}}, - {{ 29622/*0.903989 Q15*/, -14010/*-0.427555 Q15*/}}, - {{ 27246/*0.831470 Q15*/, -18205/*-0.555570 Q15*/}}, - {{ 24279/*0.740951 Q15*/, -22006/*-0.671559 Q15*/}}, - {{ 20788/*0.634393 Q15*/, -25330/*-0.773010 Q15*/}}, - {{ 16846/*0.514103 Q15*/, -28106/*-0.857729 Q15*/}}, - {{ 12540/*0.382683 Q15*/, -30274/*-0.923880 Q15*/}}, - {{ 7962/*0.242980 Q15*/, -31786/*-0.970031 Q15*/}}, - {{ 3212/*0.098017 Q15*/, -32610/*-0.995185 Q15*/}}, - {{ -1608/*-0.049068 Q15*/, -32729/*-0.998795 Q15*/}}, - {{ -6393/*-0.195090 Q15*/, -32138/*-0.980785 Q15*/}}, - {{-11039/*-0.336890 Q15*/, -30853/*-0.941544 Q15*/}}, - {{-15447/*-0.471397 Q15*/, -28899/*-0.881921 Q15*/}}, - {{-19520/*-0.595699 Q15*/, -26320/*-0.803208 Q15*/}} -}; - -const PWord16 w4N8[15] = -{ - {{ 32138/*0.980785 Q15*/, -6393/*-0.195090 Q15*/}}, - {{ 30274/*0.923880 Q15*/, -12540/*-0.382683 Q15*/}}, - {{ 27246/*0.831470 Q15*/, -18205/*-0.555570 Q15*/}}, - {{ 23170/*0.707107 Q15*/, -23170/*-0.707107 Q15*/}}, - {{ 18205/*0.555570 Q15*/, -27246/*-0.831470 Q15*/}}, - {{ 12540/*0.382683 Q15*/, -30274/*-0.923880 Q15*/}}, - {{ 6393/*0.195090 Q15*/, -32138/*-0.980785 Q15*/}}, - {{ 0/*0.000000 Q15*/, -32768/*-1.000000 Q15*/}}, - {{ -6393/*-0.195090 Q15*/, -32138/*-0.980785 Q15*/}}, - {{-12540/*-0.382683 Q15*/, -30274/*-0.923880 Q15*/}}, - {{-18205/*-0.555570 Q15*/, -27246/*-0.831470 Q15*/}}, - {{-23170/*-0.707107 Q15*/, -23170/*-0.707107 Q15*/}}, - {{-27246/*-0.831470 Q15*/, -18205/*-0.555570 Q15*/}}, - {{-30274/*-0.923880 Q15*/, -12540/*-0.382683 Q15*/}}, - {{-32138/*-0.980785 Q15*/, -6393/*-0.195090 Q15*/}} -}; - -const PWord16 w5N8[15] = -{ - {{ 31786/*0.970031 Q15*/, -7962/*-0.242980 Q15*/}}, - {{ 28899/*0.881921 Q15*/, -15447/*-0.471397 Q15*/}}, - {{ 24279/*0.740951 Q15*/, -22006/*-0.671559 Q15*/}}, - {{ 18205/*0.555570 Q15*/, -27246/*-0.831470 Q15*/}}, - {{ 11039/*0.336890 Q15*/, -30853/*-0.941544 Q15*/}}, - {{ 3212/*0.098017 Q15*/, -32610/*-0.995185 Q15*/}}, - {{ -4808/*-0.146730 Q15*/, -32413/*-0.989177 Q15*/}}, - {{-12540/*-0.382683 Q15*/, -30274/*-0.923880 Q15*/}}, - {{-19520/*-0.595699 Q15*/, -26320/*-0.803208 Q15*/}}, - {{-25330/*-0.773010 Q15*/, -20788/*-0.634393 Q15*/}}, - {{-29622/*-0.903989 Q15*/, -14010/*-0.427555 Q15*/}}, - {{-32138/*-0.980785 Q15*/, -6393/*-0.195090 Q15*/}}, - {{-32729/*-0.998795 Q15*/, 1608/*0.049068 Q15*/}}, - {{-31357/*-0.956940 Q15*/, 9512/*0.290285 Q15*/}}, - {{-28106/*-0.857729 Q15*/, 16846/*0.514103 Q15*/}} -}; - -const PWord16 w6N8[15] = -{ - {{ 31357/*0.956940 Q15*/, -9512/*-0.290285 Q15*/}}, - {{ 27246/*0.831470 Q15*/, -18205/*-0.555570 Q15*/}}, - {{ 20788/*0.634393 Q15*/, -25330/*-0.773010 Q15*/}}, - {{ 12540/*0.382683 Q15*/, -30274/*-0.923880 Q15*/}}, - {{ 3212/*0.098017 Q15*/, -32610/*-0.995185 Q15*/}}, - {{ -6393/*-0.195090 Q15*/, -32138/*-0.980785 Q15*/}}, - {{-15447/*-0.471397 Q15*/, -28899/*-0.881921 Q15*/}}, - {{-23170/*-0.707107 Q15*/, -23170/*-0.707107 Q15*/}}, - {{-28899/*-0.881921 Q15*/, -15447/*-0.471397 Q15*/}}, - {{-32138/*-0.980785 Q15*/, -6393/*-0.195090 Q15*/}}, - {{-32610/*-0.995185 Q15*/, 3212/*0.098017 Q15*/}}, - {{-30274/*-0.923880 Q15*/, 12540/*0.382683 Q15*/}}, - {{-25330/*-0.773010 Q15*/, 20788/*0.634393 Q15*/}}, - {{-18205/*-0.555570 Q15*/, 27246/*0.831470 Q15*/}}, - {{ -9512/*-0.290285 Q15*/, 31357/*0.956940 Q15*/}} -}; - -const PWord16 w7N8[15] = -{ - {{ 30853/*0.941544 Q15*/, -11039/*-0.336890 Q15*/}}, - {{ 25330/*0.773010 Q15*/, -20788/*-0.634393 Q15*/}}, - {{ 16846/*0.514103 Q15*/, -28106/*-0.857729 Q15*/}}, - {{ 6393/*0.195090 Q15*/, -32138/*-0.980785 Q15*/}}, - {{ -4808/*-0.146730 Q15*/, -32413/*-0.989177 Q15*/}}, - {{-15447/*-0.471397 Q15*/, -28899/*-0.881921 Q15*/}}, - {{-24279/*-0.740951 Q15*/, -22006/*-0.671559 Q15*/}}, - {{-30274/*-0.923880 Q15*/, -12540/*-0.382683 Q15*/}}, - {{-32729/*-0.998795 Q15*/, -1608/*-0.049068 Q15*/}}, - {{-31357/*-0.956940 Q15*/, 9512/*0.290285 Q15*/}}, - {{-26320/*-0.803208 Q15*/, 19520/*0.595699 Q15*/}}, - {{-18205/*-0.555570 Q15*/, 27246/*0.831470 Q15*/}}, - {{ -7962/*-0.242980 Q15*/, 31786/*0.970031 Q15*/}}, - {{ 3212/*0.098017 Q15*/, 32610/*0.995185 Q15*/}}, - {{ 14010/*0.427555 Q15*/, 29622/*0.903989 Q15*/}} -}; - -const PWord16 *w_a[7] = {w1N8, w2N8, w3N8, w4N8, w5N8, w6N8, w7N8}; - -const PWord16 w19N[127] = -{ - {{ 31881/*0.972940 Q15*/, 7571/*0.231058 Q15*/}}, - {{ 29269/*0.893224 Q15*/, 14733/*0.449611 Q15*/}}, - {{ 25073/*0.765167 Q15*/, 21097/*0.643832 Q15*/}}, - {{ 19520/*0.595699 Q15*/, 26320/*0.803208 Q15*/}}, - {{ 12910/*0.393992 Q15*/, 30118/*0.919114 Q15*/}}, - {{ 5602/*0.170962 Q15*/, 32286/*0.985278 Q15*/}}, - {{ -2009/*-0.061321 Q15*/, 32706/*0.998118 Q15*/}}, - {{ -9512/*-0.290285 Q15*/, 31357/*0.956940 Q15*/}}, - {{-16500/*-0.503538 Q15*/, 28311/*0.863973 Q15*/}}, - {{-22595/*-0.689541 Q15*/, 23732/*0.724247 Q15*/}}, - {{-27467/*-0.838225 Q15*/, 17869/*0.545325 Q15*/}}, - {{-30853/*-0.941544 Q15*/, 11039/*0.336890 Q15*/}}, - {{-32568/*-0.993907 Q15*/, 3612/*0.110222 Q15*/}}, - {{-32522/*-0.992480 Q15*/, -4011/*-0.122411 Q15*/}}, - {{-30715/*-0.937339 Q15*/, -11417/*-0.348419 Q15*/}}, - {{-27246/*-0.831470 Q15*/, -18205/*-0.555570 Q15*/}}, - {{-22302/*-0.680601 Q15*/, -24008/*-0.732654 Q15*/}}, - {{-16151/*-0.492898 Q15*/, -28511/*-0.870087 Q15*/}}, - {{ -9127/*-0.278520 Q15*/, -31471/*-0.960431 Q15*/}}, - {{ -1608/*-0.049068 Q15*/, -32729/*-0.998795 Q15*/}}, - {{ 5998/*0.183040 Q15*/, -32214/*-0.983105 Q15*/}}, - {{ 13279/*0.405241 Q15*/, -29957/*-0.914210 Q15*/}}, - {{ 19841/*0.605511 Q15*/, -26078/*-0.795837 Q15*/}}, - {{ 25330/*0.773010 Q15*/, -20788/*-0.634393 Q15*/}}, - {{ 29448/*0.898674 Q15*/, -14373/*-0.438616 Q15*/}}, - {{ 31972/*0.975702 Q15*/, -7180/*-0.219101 Q15*/}}, - {{ 32766/*0.999925 Q15*/, 402/*0.012272 Q15*/}}, - {{ 31786/*0.970031 Q15*/, 7962/*0.242980 Q15*/}}, - {{ 29086/*0.887640 Q15*/, 15091/*0.460539 Q15*/}}, - {{ 24812/*0.757209 Q15*/, 21403/*0.653173 Q15*/}}, - {{ 19195/*0.585798 Q15*/, 26557/*0.810457 Q15*/}}, - {{ 12540/*0.382683 Q15*/, 30274/*0.923880 Q15*/}}, - {{ 5205/*0.158858 Q15*/, 32352/*0.987301 Q15*/}}, - {{ -2411/*-0.073565 Q15*/, 32679/*0.997290 Q15*/}}, - {{ -9896/*-0.302006 Q15*/, 31238/*0.953306 Q15*/}}, - {{-16846/*-0.514103 Q15*/, 28106/*0.857729 Q15*/}}, - {{-22884/*-0.698376 Q15*/, 23453/*0.715731 Q15*/}}, - {{-27684/*-0.844854 Q15*/, 17531/*0.534998 Q15*/}}, - {{-30986/*-0.945607 Q15*/, 10660/*0.325310 Q15*/}}, - {{-32610/*-0.995185 Q15*/, 3212/*0.098017 Q15*/}}, - {{-32470/*-0.990903 Q15*/, -4410/*-0.134581 Q15*/}}, - {{-30572/*-0.932993 Q15*/, -11793/*-0.359895 Q15*/}}, - {{-27020/*-0.824589 Q15*/, -18538/*-0.565732 Q15*/}}, - {{-22006/*-0.671559 Q15*/, -24279/*-0.740951 Q15*/}}, - {{-15800/*-0.482184 Q15*/, -28707/*-0.876070 Q15*/}}, - {{ -8740/*-0.266713 Q15*/, -31581/*-0.963776 Q15*/}}, - {{ -1206/*-0.036807 Q15*/, -32746/*-0.999322 Q15*/}}, - {{ 6393/*0.195090 Q15*/, -32138/*-0.980785 Q15*/}}, - {{ 13646/*0.416430 Q15*/, -29792/*-0.909168 Q15*/}}, - {{ 20160/*0.615232 Q15*/, -25833/*-0.788346 Q15*/}}, - {{ 25583/*0.780737 Q15*/, -20475/*-0.624859 Q15*/}}, - {{ 29622/*0.903989 Q15*/, -14010/*-0.427555 Q15*/}}, - {{ 32057/*0.978317 Q15*/, -6787/*-0.207111 Q15*/}}, - {{ 32758/*0.999699 Q15*/, 804/*0.024541 Q15*/}}, - {{ 31686/*0.966976 Q15*/, 8351/*0.254866 Q15*/}}, - {{ 28899/*0.881921 Q15*/, 15447/*0.471397 Q15*/}}, - {{ 24548/*0.749136 Q15*/, 21706/*0.662416 Q15*/}}, - {{ 18868/*0.575808 Q15*/, 26791/*0.817585 Q15*/}}, - {{ 12167/*0.371317 Q15*/, 30425/*0.928506 Q15*/}}, - {{ 4808/*0.146730 Q15*/, 32413/*0.989177 Q15*/}}, - {{ -2811/*-0.085797 Q15*/, 32647/*0.996313 Q15*/}}, - {{-10279/*-0.313682 Q15*/, 31114/*0.949528 Q15*/}}, - {{-17190/*-0.524590 Q15*/, 27897/*0.851355 Q15*/}}, - {{-23170/*-0.707107 Q15*/, 23170/*0.707107 Q15*/}}, - {{-27897/*-0.851355 Q15*/, 17190/*0.524590 Q15*/}}, - {{-31114/*-0.949528 Q15*/, 10279/*0.313682 Q15*/}}, - {{-32647/*-0.996313 Q15*/, 2811/*0.085797 Q15*/}}, - {{-32413/*-0.989177 Q15*/, -4808/*-0.146730 Q15*/}}, - {{-30425/*-0.928506 Q15*/, -12167/*-0.371317 Q15*/}}, - {{-26791/*-0.817585 Q15*/, -18868/*-0.575808 Q15*/}}, - {{-21706/*-0.662416 Q15*/, -24548/*-0.749136 Q15*/}}, - {{-15447/*-0.471397 Q15*/, -28899/*-0.881921 Q15*/}}, - {{ -8351/*-0.254866 Q15*/, -31686/*-0.966976 Q15*/}}, - {{ -804/*-0.024541 Q15*/, -32758/*-0.999699 Q15*/}}, - {{ 6787/*0.207111 Q15*/, -32057/*-0.978317 Q15*/}}, - {{ 14010/*0.427555 Q15*/, -29622/*-0.903989 Q15*/}}, - {{ 20475/*0.624859 Q15*/, -25583/*-0.780737 Q15*/}}, - {{ 25833/*0.788346 Q15*/, -20160/*-0.615232 Q15*/}}, - {{ 29792/*0.909168 Q15*/, -13646/*-0.416430 Q15*/}}, - {{ 32138/*0.980785 Q15*/, -6393/*-0.195090 Q15*/}}, - {{ 32746/*0.999322 Q15*/, 1206/*0.036807 Q15*/}}, - {{ 31581/*0.963776 Q15*/, 8740/*0.266713 Q15*/}}, - {{ 28707/*0.876070 Q15*/, 15800/*0.482184 Q15*/}}, - {{ 24279/*0.740951 Q15*/, 22006/*0.671559 Q15*/}}, - {{ 18538/*0.565732 Q15*/, 27020/*0.824589 Q15*/}}, - {{ 11793/*0.359895 Q15*/, 30572/*0.932993 Q15*/}}, - {{ 4410/*0.134581 Q15*/, 32470/*0.990903 Q15*/}}, - {{ -3212/*-0.098017 Q15*/, 32610/*0.995185 Q15*/}}, - {{-10660/*-0.325310 Q15*/, 30986/*0.945607 Q15*/}}, - {{-17531/*-0.534998 Q15*/, 27684/*0.844854 Q15*/}}, - {{-23453/*-0.715731 Q15*/, 22884/*0.698376 Q15*/}}, - {{-28106/*-0.857729 Q15*/, 16846/*0.514103 Q15*/}}, - {{-31238/*-0.953306 Q15*/, 9896/*0.302006 Q15*/}}, - {{-32679/*-0.997290 Q15*/, 2411/*0.073565 Q15*/}}, - {{-32352/*-0.987301 Q15*/, -5205/*-0.158858 Q15*/}}, - {{-30274/*-0.923880 Q15*/, -12540/*-0.382683 Q15*/}}, - {{-26557/*-0.810457 Q15*/, -19195/*-0.585798 Q15*/}}, - {{-21403/*-0.653173 Q15*/, -24812/*-0.757209 Q15*/}}, - {{-15091/*-0.460539 Q15*/, -29086/*-0.887640 Q15*/}}, - {{ -7962/*-0.242980 Q15*/, -31786/*-0.970031 Q15*/}}, - {{ -402/*-0.012272 Q15*/, -32766/*-0.999925 Q15*/}}, - {{ 7180/*0.219101 Q15*/, -31972/*-0.975702 Q15*/}}, - {{ 14373/*0.438616 Q15*/, -29448/*-0.898674 Q15*/}}, - {{ 20788/*0.634393 Q15*/, -25330/*-0.773010 Q15*/}}, - {{ 26078/*0.795837 Q15*/, -19841/*-0.605511 Q15*/}}, - {{ 29957/*0.914210 Q15*/, -13279/*-0.405241 Q15*/}}, - {{ 32214/*0.983105 Q15*/, -5998/*-0.183040 Q15*/}}, - {{ 32729/*0.998795 Q15*/, 1608/*0.049068 Q15*/}}, - {{ 31471/*0.960431 Q15*/, 9127/*0.278520 Q15*/}}, - {{ 28511/*0.870087 Q15*/, 16151/*0.492898 Q15*/}}, - {{ 24008/*0.732654 Q15*/, 22302/*0.680601 Q15*/}}, - {{ 18205/*0.555570 Q15*/, 27246/*0.831470 Q15*/}}, - {{ 11417/*0.348419 Q15*/, 30715/*0.937339 Q15*/}}, - {{ 4011/*0.122411 Q15*/, 32522/*0.992480 Q15*/}}, - {{ -3612/*-0.110222 Q15*/, 32568/*0.993907 Q15*/}}, - {{-11039/*-0.336890 Q15*/, 30853/*0.941544 Q15*/}}, - {{-17869/*-0.545325 Q15*/, 27467/*0.838225 Q15*/}}, - {{-23732/*-0.724247 Q15*/, 22595/*0.689541 Q15*/}}, - {{-28311/*-0.863973 Q15*/, 16500/*0.503538 Q15*/}}, - {{-31357/*-0.956940 Q15*/, 9512/*0.290285 Q15*/}}, - {{-32706/*-0.998118 Q15*/, 2009/*0.061321 Q15*/}}, - {{-32286/*-0.985278 Q15*/, -5602/*-0.170962 Q15*/}}, - {{-30118/*-0.919114 Q15*/, -12910/*-0.393992 Q15*/}}, - {{-26320/*-0.803208 Q15*/, -19520/*-0.595699 Q15*/}}, - {{-21097/*-0.643832 Q15*/, -25073/*-0.765167 Q15*/}}, - {{-14733/*-0.449611 Q15*/, -29269/*-0.893224 Q15*/}}, - {{ -7571/*-0.231058 Q15*/, -31881/*-0.972940 Q15*/}} -}; - -const PWord16 w18N[127] = -{ - {{ 31972/*0.975702 Q15*/, 7180/*0.219101 Q15*/}}, - {{ 29622/*0.903989 Q15*/, 14010/*0.427555 Q15*/}}, - {{ 25833/*0.788346 Q15*/, 20160/*0.615232 Q15*/}}, - {{ 20788/*0.634393 Q15*/, 25330/*0.773010 Q15*/}}, - {{ 14733/*0.449611 Q15*/, 29269/*0.893224 Q15*/}}, - {{ 7962/*0.242980 Q15*/, 31786/*0.970031 Q15*/}}, - {{ 804/*0.024541 Q15*/, 32758/*0.999699 Q15*/}}, - {{ -6393/*-0.195090 Q15*/, 32138/*0.980785 Q15*/}}, - {{-13279/*-0.405241 Q15*/, 29957/*0.914210 Q15*/}}, - {{-19520/*-0.595699 Q15*/, 26320/*0.803208 Q15*/}}, - {{-24812/*-0.757209 Q15*/, 21403/*0.653173 Q15*/}}, - {{-28899/*-0.881921 Q15*/, 15447/*0.471397 Q15*/}}, - {{-31581/*-0.963776 Q15*/, 8740/*0.266713 Q15*/}}, - {{-32729/*-0.998795 Q15*/, 1608/*0.049068 Q15*/}}, - {{-32286/*-0.985278 Q15*/, -5602/*-0.170962 Q15*/}}, - {{-30274/*-0.923880 Q15*/, -12540/*-0.382683 Q15*/}}, - {{-26791/*-0.817585 Q15*/, -18868/*-0.575808 Q15*/}}, - {{-22006/*-0.671559 Q15*/, -24279/*-0.740951 Q15*/}}, - {{-16151/*-0.492898 Q15*/, -28511/*-0.870087 Q15*/}}, - {{ -9512/*-0.290285 Q15*/, -31357/*-0.956940 Q15*/}}, - {{ -2411/*-0.073565 Q15*/, -32679/*-0.997290 Q15*/}}, - {{ 4808/*0.146730 Q15*/, -32413/*-0.989177 Q15*/}}, - {{ 11793/*0.359895 Q15*/, -30572/*-0.932993 Q15*/}}, - {{ 18205/*0.555570 Q15*/, -27246/*-0.831470 Q15*/}}, - {{ 23732/*0.724247 Q15*/, -22595/*-0.689541 Q15*/}}, - {{ 28106/*0.857729 Q15*/, -16846/*-0.514103 Q15*/}}, - {{ 31114/*0.949528 Q15*/, -10279/*-0.313682 Q15*/}}, - {{ 32610/*0.995185 Q15*/, -3212/*-0.098017 Q15*/}}, - {{ 32522/*0.992480 Q15*/, 4011/*0.122411 Q15*/}}, - {{ 30853/*0.941544 Q15*/, 11039/*0.336890 Q15*/}}, - {{ 27684/*0.844854 Q15*/, 17531/*0.534998 Q15*/}}, - {{ 23170/*0.707107 Q15*/, 23170/*0.707107 Q15*/}}, - {{ 17531/*0.534998 Q15*/, 27684/*0.844854 Q15*/}}, - {{ 11039/*0.336890 Q15*/, 30853/*0.941544 Q15*/}}, - {{ 4011/*0.122411 Q15*/, 32522/*0.992480 Q15*/}}, - {{ -3212/*-0.098017 Q15*/, 32610/*0.995185 Q15*/}}, - {{-10279/*-0.313682 Q15*/, 31114/*0.949528 Q15*/}}, - {{-16846/*-0.514103 Q15*/, 28106/*0.857729 Q15*/}}, - {{-22595/*-0.689541 Q15*/, 23732/*0.724247 Q15*/}}, - {{-27246/*-0.831470 Q15*/, 18205/*0.555570 Q15*/}}, - {{-30572/*-0.932993 Q15*/, 11793/*0.359895 Q15*/}}, - {{-32413/*-0.989177 Q15*/, 4808/*0.146730 Q15*/}}, - {{-32679/*-0.997290 Q15*/, -2411/*-0.073565 Q15*/}}, - {{-31357/*-0.956940 Q15*/, -9512/*-0.290285 Q15*/}}, - {{-28511/*-0.870087 Q15*/, -16151/*-0.492898 Q15*/}}, - {{-24279/*-0.740951 Q15*/, -22006/*-0.671559 Q15*/}}, - {{-18868/*-0.575808 Q15*/, -26791/*-0.817585 Q15*/}}, - {{-12540/*-0.382683 Q15*/, -30274/*-0.923880 Q15*/}}, - {{ -5602/*-0.170962 Q15*/, -32286/*-0.985278 Q15*/}}, - {{ 1608/*0.049068 Q15*/, -32729/*-0.998795 Q15*/}}, - {{ 8740/*0.266713 Q15*/, -31581/*-0.963776 Q15*/}}, - {{ 15447/*0.471397 Q15*/, -28899/*-0.881921 Q15*/}}, - {{ 21403/*0.653173 Q15*/, -24812/*-0.757209 Q15*/}}, - {{ 26320/*0.803208 Q15*/, -19520/*-0.595699 Q15*/}}, - {{ 29957/*0.914210 Q15*/, -13279/*-0.405241 Q15*/}}, - {{ 32138/*0.980785 Q15*/, -6393/*-0.195090 Q15*/}}, - {{ 32758/*0.999699 Q15*/, 804/*0.024541 Q15*/}}, - {{ 31786/*0.970031 Q15*/, 7962/*0.242980 Q15*/}}, - {{ 29269/*0.893224 Q15*/, 14733/*0.449611 Q15*/}}, - {{ 25330/*0.773010 Q15*/, 20788/*0.634393 Q15*/}}, - {{ 20160/*0.615232 Q15*/, 25833/*0.788346 Q15*/}}, - {{ 14010/*0.427555 Q15*/, 29622/*0.903989 Q15*/}}, - {{ 7180/*0.219101 Q15*/, 31972/*0.975702 Q15*/}}, - {{ 0/*0.000000 Q15*/, 32767/*1.000000 Q15*/}}, - {{ -7180/*-0.219101 Q15*/, 31972/*0.975702 Q15*/}}, - {{-14010/*-0.427555 Q15*/, 29622/*0.903989 Q15*/}}, - {{-20160/*-0.615232 Q15*/, 25833/*0.788346 Q15*/}}, - {{-25330/*-0.773010 Q15*/, 20788/*0.634393 Q15*/}}, - {{-29269/*-0.893224 Q15*/, 14733/*0.449611 Q15*/}}, - {{-31786/*-0.970031 Q15*/, 7962/*0.242980 Q15*/}}, - {{-32758/*-0.999699 Q15*/, 804/*0.024541 Q15*/}}, - {{-32138/*-0.980785 Q15*/, -6393/*-0.195090 Q15*/}}, - {{-29957/*-0.914210 Q15*/, -13279/*-0.405241 Q15*/}}, - {{-26320/*-0.803208 Q15*/, -19520/*-0.595699 Q15*/}}, - {{-21403/*-0.653173 Q15*/, -24812/*-0.757209 Q15*/}}, - {{-15447/*-0.471397 Q15*/, -28899/*-0.881921 Q15*/}}, - {{ -8740/*-0.266713 Q15*/, -31581/*-0.963776 Q15*/}}, - {{ -1608/*-0.049068 Q15*/, -32729/*-0.998795 Q15*/}}, - {{ 5602/*0.170962 Q15*/, -32286/*-0.985278 Q15*/}}, - {{ 12540/*0.382683 Q15*/, -30274/*-0.923880 Q15*/}}, - {{ 18868/*0.575808 Q15*/, -26791/*-0.817585 Q15*/}}, - {{ 24279/*0.740951 Q15*/, -22006/*-0.671559 Q15*/}}, - {{ 28511/*0.870087 Q15*/, -16151/*-0.492898 Q15*/}}, - {{ 31357/*0.956940 Q15*/, -9512/*-0.290285 Q15*/}}, - {{ 32679/*0.997290 Q15*/, -2411/*-0.073565 Q15*/}}, - {{ 32413/*0.989177 Q15*/, 4808/*0.146730 Q15*/}}, - {{ 30572/*0.932993 Q15*/, 11793/*0.359895 Q15*/}}, - {{ 27246/*0.831470 Q15*/, 18205/*0.555570 Q15*/}}, - {{ 22595/*0.689541 Q15*/, 23732/*0.724247 Q15*/}}, - {{ 16846/*0.514103 Q15*/, 28106/*0.857729 Q15*/}}, - {{ 10279/*0.313682 Q15*/, 31114/*0.949528 Q15*/}}, - {{ 3212/*0.098017 Q15*/, 32610/*0.995185 Q15*/}}, - {{ -4011/*-0.122411 Q15*/, 32522/*0.992480 Q15*/}}, - {{-11039/*-0.336890 Q15*/, 30853/*0.941544 Q15*/}}, - {{-17531/*-0.534998 Q15*/, 27684/*0.844854 Q15*/}}, - {{-23170/*-0.707107 Q15*/, 23170/*0.707107 Q15*/}}, - {{-27684/*-0.844854 Q15*/, 17531/*0.534998 Q15*/}}, - {{-30853/*-0.941544 Q15*/, 11039/*0.336890 Q15*/}}, - {{-32522/*-0.992480 Q15*/, 4011/*0.122411 Q15*/}}, - {{-32610/*-0.995185 Q15*/, -3212/*-0.098017 Q15*/}}, - {{-31114/*-0.949528 Q15*/, -10279/*-0.313682 Q15*/}}, - {{-28106/*-0.857729 Q15*/, -16846/*-0.514103 Q15*/}}, - {{-23732/*-0.724247 Q15*/, -22595/*-0.689541 Q15*/}}, - {{-18205/*-0.555570 Q15*/, -27246/*-0.831470 Q15*/}}, - {{-11793/*-0.359895 Q15*/, -30572/*-0.932993 Q15*/}}, - {{ -4808/*-0.146730 Q15*/, -32413/*-0.989177 Q15*/}}, - {{ 2411/*0.073565 Q15*/, -32679/*-0.997290 Q15*/}}, - {{ 9512/*0.290285 Q15*/, -31357/*-0.956940 Q15*/}}, - {{ 16151/*0.492898 Q15*/, -28511/*-0.870087 Q15*/}}, - {{ 22006/*0.671559 Q15*/, -24279/*-0.740951 Q15*/}}, - {{ 26791/*0.817585 Q15*/, -18868/*-0.575808 Q15*/}}, - {{ 30274/*0.923880 Q15*/, -12540/*-0.382683 Q15*/}}, - {{ 32286/*0.985278 Q15*/, -5602/*-0.170962 Q15*/}}, - {{ 32729/*0.998795 Q15*/, 1608/*0.049068 Q15*/}}, - {{ 31581/*0.963776 Q15*/, 8740/*0.266713 Q15*/}}, - {{ 28899/*0.881921 Q15*/, 15447/*0.471397 Q15*/}}, - {{ 24812/*0.757209 Q15*/, 21403/*0.653173 Q15*/}}, - {{ 19520/*0.595699 Q15*/, 26320/*0.803208 Q15*/}}, - {{ 13279/*0.405241 Q15*/, 29957/*0.914210 Q15*/}}, - {{ 6393/*0.195090 Q15*/, 32138/*0.980785 Q15*/}}, - {{ -804/*-0.024541 Q15*/, 32758/*0.999699 Q15*/}}, - {{ -7962/*-0.242980 Q15*/, 31786/*0.970031 Q15*/}}, - {{-14733/*-0.449611 Q15*/, 29269/*0.893224 Q15*/}}, - {{-20788/*-0.634393 Q15*/, 25330/*0.773010 Q15*/}}, - {{-25833/*-0.788346 Q15*/, 20160/*0.615232 Q15*/}}, - {{-29622/*-0.903989 Q15*/, 14010/*0.427555 Q15*/}}, - {{-31972/*-0.975702 Q15*/, 7180/*0.219101 Q15*/}} -}; - -const Word16 kLog2TableFrac_x[256] = -{ - 0, 1, 3, 4, 6, 7, 9, 10, - 11, 13, 14, 16, 17, 18, 20, 21, - 22, 24, 25, 26, 28, 29, 30, 32, - 33, 34, 36, 37, 38, 40, 41, 42, - 44, 45, 46, 47, 49, 50, 51, 52, - 54, 55, 56, 57, 59, 60, 61, 62, - 63, 65, 66, 67, 68, 69, 71, 72, - 73, 74, 75, 77, 78, 79, 80, 81, - 82, 84, 85, 86, 87, 88, 89, 90, - 92, 93, 94, 95, 96, 97, 98, 99, - 100, 102, 103, 104, 105, 106, 107, 108, - 109, 110, 111, 112, 113, 114, 116, 117, - 118, 119, 120, 121, 122, 123, 124, 125, - 126, 127, 128, 129, 130, 131, 132, 133, - 134, 135, 136, 137, 138, 139, 140, 141, - 142, 143, 144, 145, 146, 147, 148, 149, - 150, 151, 152, 153, 154, 155, 155, 156, - 157, 158, 159, 160, 161, 162, 163, 164, - 165, 166, 167, 168, 169, 169, 170, 171, - 172, 173, 174, 175, 176, 177, 178, 178, - 179, 180, 181, 182, 183, 184, 185, 185, - 186, 187, 188, 189, 190, 191, 192, 192, - 193, 194, 195, 196, 197, 198, 198, 199, - 200, 201, 202, 203, 203, 204, 205, 206, - 207, 208, 208, 209, 210, 211, 212, 212, - 213, 214, 215, 216, 216, 217, 218, 219, - 220, 220, 221, 222, 223, 224, 224, 225, - 226, 227, 228, 228, 229, 230, 231, 231, - 232, 233, 234, 234, 235, 236, 237, 238, - 238, 239, 240, 241, 241, 242, 243, 244, - 244, 245, 246, 247, 247, 248, 249, 249, - 250, 251, 252, 252, 253, 254, 255, 255 -}; - -const Word16 kExp2TableFrac_x[256] = /* Q15 */ -{ - 32767, 32678, 32590, 32502, 32414, 32326, 32239, 32152, - 32065, 31978, 31892, 31805, 31719, 31634, 31548, 31463, - 31378, 31293, 31208, 31124, 31040, 30956, 30872, 30789, - 30705, 30622, 30540, 30457, 30375, 30293, 30211, 30129, - 30047, 29966, 29885, 29804, 29724, 29643, 29563, 29483, - 29404, 29324, 29245, 29166, 29087, 29008, 28930, 28852, - 28774, 28696, 28618, 28541, 28464, 28387, 28310, 28233, - 28157, 28081, 28005, 27929, 27854, 27778, 27703, 27628, - 27554, 27479, 27405, 27331, 27257, 27183, 27110, 27036, - 26963, 26890, 26818, 26745, 26673, 26601, 26529, 26457, - 26385, 26314, 26243, 26172, 26101, 26031, 25960, 25890, - 25820, 25750, 25681, 25611, 25542, 25473, 25404, 25335, - 25267, 25198, 25130, 25062, 24995, 24927, 24860, 24792, - 24725, 24659, 24592, 24525, 24459, 24393, 24327, 24261, - 24196, 24130, 24065, 24000, 23935, 23870, 23806, 23741, - 23677, 23613, 23549, 23486, 23422, 23359, 23296, 23233, - 23170, 23107, 23045, 22982, 22920, 22858, 22796, 22735, - 22673, 22612, 22551, 22490, 22429, 22368, 22308, 22248, - 22187, 22127, 22068, 22008, 21948, 21889, 21830, 21771, - 21712, 21653, 21595, 21536, 21478, 21420, 21362, 21304, - 21247, 21189, 21132, 21075, 21018, 20961, 20904, 20848, - 20791, 20735, 20679, 20623, 20568, 20512, 20456, 20401, - 20346, 20291, 20236, 20181, 20127, 20072, 20018, 19964, - 19910, 19856, 19802, 19749, 19696, 19642, 19589, 19536, - 19483, 19431, 19378, 19326, 19274, 19221, 19169, 19118, - 19066, 19014, 18963, 18912, 18861, 18810, 18759, 18708, - 18657, 18607, 18557, 18506, 18456, 18406, 18357, 18307, - 18258, 18208, 18159, 18110, 18061, 18012, 17963, 17915, - 17866, 17818, 17770, 17722, 17674, 17626, 17578, 17531, - 17483, 17436, 17389, 17342, 17295, 17248, 17202, 17155, - 17109, 17063, 17016, 16970, 16925, 16879, 16833, 16788, - 16742, 16697, 16652, 16607, 16562, 16517, 16472, 16428 -}; - -const Word16 sqrt_table_pitch_search[256+1] = /* Q11 */ -{ - 0, 2048, 2896, 3547, 4096, 4579, 5017, 5418, - 5793, 6144, 6476, 6792, 7094, 7384, 7663, 7932, - 8192, 8444, 8689, 8927, 9159, 9385, 9606, 9822, - 10033, 10240, 10443, 10642, 10837, 11029, 11217, 11403, - 11585, 11765, 11942, 12116, 12288, 12457, 12625, 12790, - 12953, 13114, 13273, 13430, 13585, 13738, 13890, 14040, - 14189, 14336, 14482, 14626, 14768, 14910, 15050, 15188, - 15326, 15462, 15597, 15731, 15864, 15995, 16126, 16255, - 16384, 16512, 16638, 16764, 16888, 17012, 17135, 17257, - 17378, 17498, 17618, 17736, 17854, 17971, 18087, 18203, - 18318, 18432, 18545, 18658, 18770, 18882, 18992, 19102, - 19212, 19321, 19429, 19537, 19644, 19750, 19856, 19961, - 20066, 20170, 20274, 20377, 20480, 20582, 20684, 20785, - 20886, 20986, 21085, 21185, 21283, 21382, 21480, 21577, - 21674, 21771, 21867, 21962, 22058, 22153, 22247, 22341, - 22435, 22528, 22621, 22713, 22806, 22897, 22989, 23080, - 23170, 23261, 23351, 23440, 23530, 23619, 23707, 23796, - 23884, 23971, 24059, 24146, 24232, 24319, 24405, 24491, - 24576, 24661, 24746, 24831, 24915, 24999, 25083, 25166, - 25249, 25332, 25415, 25497, 25580, 25661, 25743, 25824, - 25905, 25986, 26067, 26147, 26227, 26307, 26387, 26466, - 26545, 26624, 26703, 26781, 26859, 26937, 27015, 27092, - 27170, 27247, 27324, 27400, 27477, 27553, 27629, 27705, - 27780, 27856, 27931, 28006, 28081, 28155, 28230, 28304, - 28378, 28452, 28525, 28599, 28672, 28745, 28818, 28891, - 28963, 29035, 29108, 29180, 29251, 29323, 29394, 29466, - 29537, 29608, 29678, 29749, 29819, 29890, 29960, 30030, - 30099, 30169, 30238, 30308, 30377, 30446, 30515, 30583, - 30652, 30720, 30788, 30856, 30924, 30992, 31059, 31127, - 31194, 31261, 31328, 31395, 31462, 31529, 31595, 31661, - 31727, 31794, 31859, 31925, 31991, 32056, 32122, 32187, - 32252, 32317, 32382, 32446, 32511, 32575, 32640, 32704, - 32766 -}; - - -/******************** moved over from tables_plus.c ************************/ - -/* For bass post filter */ -const Word16 filt_lp[1+L_FILT] = -{ - 2892/*0.088250f Q15*/, 2831/*0.086410f Q15*/, 2657/*0.081074f Q15*/, 2384/*0.072768f Q15*/, - 2041/*0.062294f Q15*/, 1659/*0.050623f Q15*/, 1271/*0.038774f Q15*/, 907/*0.027692f Q15*/, - 594/*0.018130f Q15*/, 347/*0.010578f Q15*/, 171/*0.005221f Q15*/, 64/*0.001946f Q15*/, - 13/*0.000385f Q15*/ -}; -const Word16 filt_lp_16kHz[1+L_FILT16k] = -{ - 2340/*0.071410f Q15*/, 2308/*0.070433f Q15*/, 2214/*0.067568f Q15*/, 2064/*0.062999f Q15*/, - 1868/*0.057020f Q15*/, 1639/*0.050005f Q15*/, 1389/*0.042378f Q15*/, 1133/*0.034577f Q15*/, - 885/*0.027022f Q15*/, 658/*0.020078f Q15*/, 460/*0.014031f Q15*/, 297/*0.009070f Q15*/, - 173/*0.005276f Q15*/, 86/*0.002625f Q15*/, 33/*0.000999f Q15*/, 7/*0.000205f Q15*/ -}; - -/* 1/4 resolution interpolation filter (-3 dB at 0.856*fs/2) */ -const Word16 pitch_inter4_2[PIT_FIR_SIZE2] = -{ - /* cut-off frequency at 0.94*fs/2 */ - 30802/*0.940000f Q15*/, - 28062/*0.856390f Q15*/, 20718/*0.632268f Q15*/, 11061/*0.337560f Q15*/, 1936/*0.059072f Q15*/, - -4295/*-0.131059f Q15*/, -6534/*-0.199393f Q15*/, -5196/*-0.158569f Q15*/, -1847/*-0.056359f Q15*/, - 1560/*0.047606f Q15*/, 3498/*0.106749f Q15*/, 3398/*0.1037059f Q15*/, 1706/*0.052062f Q15*/, - -497/*-0.015182f Q15*/, -2087/*-0.063705f Q15*/, -2414/*-0.073660f Q15*/, -1524/*-0.046497f Q15*/, - -32/*-0.000983f Q15*/, 1253/*0.038227f Q15*/, 1741/*0.053143f Q15*/, 1313/*0.040059f Q15*/, - 305/*0.009308f Q15*/, -710/*-0.021674f Q15*/, -1238/*-0.037767f Q15*/, -1087/*-0.033186f Q15*/, - -427/*-0.013028f Q15*/, 351/*0.010702f Q15*/, 849/*0.025901f Q15*/, 862/*0.026318f Q15*/, - 453/*0.013821f Q15*/, -119/*-0.003645f Q15*/, -551/*-0.016813f Q15*/, -651/*-0.019855f Q15*/, - -418/*-0.012766f Q15*/, -17/*-0.000530f Q15*/, 330/*0.010080f Q15*/, 463/*0.014122f Q15*/, - 349/*0.010657f Q15*/, 85/*0.002594f Q15*/, -176/*-0.005363f Q15*/, -306/*-0.009344f Q15*/, - -265/*-0.008101f Q15*/, -104/*-0.003182f Q15*/, 76/*0.002330f Q15*/, 185/*0.005635f Q15*/, - 182/*0.005562f Q15*/, 93/*0.002844f Q15*/, -21/*-0.000627f Q15*/, -98/*-0.002993f Q15*/, - -110/*-0.003362f Q15*/, -67/*-0.002044f Q15*/, -4/*-0.000116f Q15*/, 43/*0.001315f Q15*/, - 55/*0.001692f Q15*/, 38/*0.001151f Q15*/, 8/*0.000259f Q15*/, -14/*-0.000417f Q15*/, - -20/*-0.000618f Q15*/, -14/*-0.000434f Q15*/, -4/*-0.000133f Q15*/, 2/*0.000063f Q15*/, - 3/*0.000098f Q15*/, 2/*0.000048f Q15*/, 0/*0.000007f Q15*/, 0/*0.000000f Q15*/ -}; -/* 1/4 resolution interpolation filter (-3 dB at 0.791*fs/2) */ -const Word16 pitch_inter4_1[UP_SAMP * L_INTERPOL1 + 1] = -{ - 29491/*0.900000F Q15*/, - 26836/*0.818959F Q15*/, 19820/* 0.604850F Q15*/, 10859/* 0.331379F Q15*/, 2751/* 0.083958F Q15*/, - -2484/*-0.075795F Q15*/, -4283/* -0.130717F Q15*/, -3463/*-0.105685F Q15*/, -1533/*-0.046774F Q15*/, - 146/*0.004467F Q15*/, 911/* 0.027789F Q15*/, 840/* 0.025642F Q15*/, 412/* 0.012571F Q15*/, - 63/*0.001927F Q15*/, -51/* -0.001571F Q15*/, -25/*-0.000753F Q15*/, 0/* 0.000000f Q15*/ -}; -/* 1/6 resolution interpolation filter (-3 dB at 0.95*fs/2) */ -const Word16 pitch_inter6_2[PIT_FIR_SIZE6_2] = -{ - 31129/*0.949986374119862f Q15*/, - 29854/*0.911081104469830f Q15*/, - 26218/*0.800115099292852f Q15*/, - 20753/*0.633320673120883f Q15*/, - 14240/*0.434558462154083f Q15*/, - 7575/*0.231177017786780f Q15*/, - 1618/*0.049378173063717f Q15*/, - -2950/*-0.090039611811170f Q15*/, - -5727/*-0.174782560924477f Q15*/, - -6635/*-0.202477516286360f Q15*/, - -5905/*-0.180218293244902f Q15*/, - -4012/*-0.122429229978978f Q15*/, - -1558/*-0.047552067127379f Q15*/, - 843/*0.025733669494145f Q15*/, - 2687/*0.081995376731897f Q15*/, - 3656/*0.111581381838187f Q15*/, - 3663/*0.111781798292302f Q15*/, - 2834/*0.086499988914996f Q15*/, - 1462/*0.044629684447068f Q15*/, - -79/*-0.002416435594242f Q15*/, - -1423/*-0.043440027386915f Q15*/, - -2289/*-0.069857782812169f Q15*/, - -2533/*-0.077293683967992f Q15*/, - -2166/*-0.066098268486336f Q15*/, - -1336/*-0.040782649068098f Q15*/, - -282/*-0.008590773415008f Q15*/, - 734/*0.022397654632128f Q15*/, - 1480/*0.045171360007974f Q15*/, - 1811/*0.055274128677739f Q15*/, - 1690/*0.051578034020076f Q15*/, - 1187/*0.036232016917169f Q15*/, - 454/*0.013869500422767f Q15*/, - -317/*-0.009680698856947f Q15*/, - -945/*-0.028843394410080f Q15*/, - -1296/*-0.039560663181280f Q15*/, - -1314/*-0.040095747151623f Q15*/, - -1023/*-0.031231107680685f Q15*/, - -520/*-0.015866154815425f Q15*/, - 60/*0.001841532922707f Q15*/, - 575/*0.017553701334759f Q15*/, - 910/*0.027778555138199f Q15*/, - 1003/*0.030612329573745f Q15*/, - 853/*0.026046143652186f Q15*/, - 518/*0.015803012695681f Q15*/, - 91/*0.002782973481834f Q15*/, - -319/*-0.009720124055079f Q15*/, - -617/*-0.018826488463900f Q15*/, - -744/*-0.022710487805852f Q15*/, - -686/*-0.020936374578238f Q15*/, - -473/*-0.014436620433404f Q15*/, - -169/*-0.005169079181373f Q15*/, - 145/*0.004437651243491f Q15*/, - 397/*0.012100372954920f Q15*/, - 531/*0.016207075406240f Q15*/, - 529/*0.016135389123271f Q15*/, - 403/*0.012306629559665f Q15*/, - 196/*0.005986734945567f Q15*/, - -36/*-0.001094950878591f Q15*/, - -236/*-0.007200842219958f Q15*/, - -360/*-0.010998212848124f Q15*/, - -388/*-0.011835179448280f Q15*/, - -322/*-0.009826566540474f Q15*/, - -188/*-0.005747665080695f Q15*/, - -26/*-0.000780600030751f Q15*/, - 125/*0.003810613287985f Q15*/, - 229/*0.006990479233404f Q15*/, - 268/*0.008174249796791f Q15*/, - 240/*0.007317375965949f Q15*/, - 159/*0.004864690818765f Q15*/, - 52/*0.001587005259212f Q15*/, - -54/*-0.001642504305841f Q15*/, - -133/*-0.004070609517416f Q15*/, - -171/*-0.005230670504649f Q15*/, - -164/*-0.005019147682711f Q15*/, - -120/*-0.003673879223241f Q15*/, - -55/*-0.001671460853812f Q15*/, - 14/*0.000420750005150f Q15*/, - 69/*0.002095384947391f Q15*/, - 99/*0.003020513665060f Q15*/, - 101/*0.003095468528243f Q15*/, - 80/*0.002441025550729f Q15*/, - 44/*0.001335514431569f Q15*/, - 4/*0.000120805384516f Q15*/, - -29/*-0.000893340757369f Q15*/, - -49/*-0.001501610712267f Q15*/, - -54/*-0.001636887611783f Q15*/, - -45/*-0.001362571776250f Q15*/, - -27/*-0.000832126175863f Q15*/, - -8/*-0.000232033375863f Q15*/, - 9/*0.000273627139471f Q15*/, - 19/*0.000582092683087f Q15*/, - 22/*0.000666445711949f Q15*/, - 19/*0.000566088888178f Q15*/, - 12/*0.000360374058147f Q15*/, - 4/*0.000136306914913f Q15*/, - -1/*-0.000038864994777f Q15*/, - -4/*-0.000132755824518f Q15*/, - -5/*-0.000148377158880f Q15*/, - -4/*-0.000112937171810f Q15*/, - -2/*-0.000061132514471f Q15*/, - -1/*-0.000019974224468f Q15*/, - 0/*-0.000000460344975f Q15*/, - 0/*0.000001976848453f Q15*/ -}; - -const Word16 grid50_fx[(GRID50_POINTS-1)/2 - 1] = -{ - 32703, 32510, 32188, 31739, 31164, 30467, - 29649, 28715, 27667, 26510, 25248, 23887, - 22431, 20887, 19261, 17558, 15786, 13952, - 12063, 10126, 8149, 6140, 4107, 2058 -}; - - -const Word16 grid40_fx[(GRID40_POINTS-1)/2 - 1] = -{ - 32667, 32365, 31863, 31164, 30274, 29197, - 27939, 26510, 24917, 23170, 21281, 19261, - 17121, 14876, 12540, 10126, 7650, 5126, - 2571 -}; - -const Word16 bit_rates_div50[] = /* bit rate values / 50 to Fit in a Word16 */ -{ - ACELP_7k20/50, ACELP_8k00/50, ACELP_11k60/50, ACELP_12k15/50, - ACELP_12k85/50, ACELP_13k20/50, ACELP_14k80/50, ACELP_16k40/50, ACELP_22k60/50, - ACELP_24k40/50, ACELP_29k00/50, ACELP_29k20/50, ACELP_30k20/50, ACELP_30k40/50, - ACELP_32k /50, ACELP_48k /50, ACELP_64k /50, HQ_96k /50, HQ_128k /50 -}; - -const Word16 bit_rates_16k_div50[] = /* bit rate values / 50 to Fit in a Word16 */ -{ - ACELP_8k00 /50, ACELP_14k80/50, ACELP_22k60/50, ACELP_24k40/50, ACELP_29k00/50, - ACELP_29k20/50, ACELP_30k20/50, ACELP_30k40/50, ACELP_32k /50, ACELP_48k /50, ACELP_64k /50 -}; - -const Word16 L_frame_inv[8] = { 0x4000, 0x369D, 0x3333, 0x2D83, 0x2AAB, 0x28F6, 0, 0x2222 }; - -const Word16 TecLowBandTable[] = {0, 2, 4, 6}; -const Word16 TecSC_Fx[] = -{ - 23999/*0.3662f*2.0f Q15*/, 7065/*0.1078f*2.0f Q15*/, 7825/*0.1194f*2.0f Q15*/, - 8448/*0.1289f*2.0f Q15*/, 8946/*0.1365f*2.0f Q15*/, 9254/*0.1412f*2.0f Q15*/ -}; - -const Word16 uniform_model_fx[] = { MAX_AR_FREQ, MAX_AR_FREQ / 2, 0 }; - -const Word16 RotVector_32[2*20] = -{ - /** - * \brief Twiddle factors are unscaled - */ - SHC(0x7d8a), SHC(0xe707), SHC(0x7642), SHC(0xcf04), SHC(0x6a6e), SHC(0xb8e3), SHC(0x5a82), SHC(0xa57e), - SHC(0x471d), SHC(0x9592), SHC(0x30fc), SHC(0x89be), SHC(0x18f9), SHC(0x8276), SHC(0x7642), SHC(0xcf04), - SHC(0x5a82), SHC(0xa57e), SHC(0x30fc), SHC(0x89be), SHC(0xcf04), SHC(0x89be), SHC(0xa57e), SHC(0xa57e), - SHC(0x89be), SHC(0xcf04), SHC(0x6a6e), SHC(0xb8e3), SHC(0x30fc), SHC(0x89be), SHC(0xe707), SHC(0x8276), - SHC(0xa57e), SHC(0xa57e), SHC(0x8276), SHC(0xe707), SHC(0x89be), SHC(0x30fc), SHC(0xb8e3), SHC(0x6a6e) -}; - -/** - * \brief Twiddle factors are unscaled - */ -const Word16 RotVector_480[2*(480-30)] = -{ - SHC(0x7fff), SHC(0x0000), SHC(0x7ff5), SHC(0xfca6), - SHC(0x7fd3), SHC(0xf94d), SHC(0x7f9b), SHC(0xf5f5), SHC(0x7f4c), SHC(0xf29f), SHC(0x7ee8), SHC(0xef4b), - SHC(0x7e6d), SHC(0xebfa), SHC(0x7ddb), SHC(0xe8ad), SHC(0x7d34), SHC(0xe563), SHC(0x7c77), SHC(0xe21e), - SHC(0x7ba3), SHC(0xdedf), SHC(0x7abb), SHC(0xdba5), SHC(0x79bc), SHC(0xd872), SHC(0x78a8), SHC(0xd546), - SHC(0x7780), SHC(0xd221), SHC(0x7642), SHC(0xcf04), SHC(0x74ef), SHC(0xcbf0), SHC(0x7388), SHC(0xc8e5), - SHC(0x720d), SHC(0xc5e4), SHC(0x707d), SHC(0xc2ec), SHC(0x6eda), SHC(0xc000), SHC(0x6d23), SHC(0xbd1f), - SHC(0x6b5a), SHC(0xba49), SHC(0x697d), SHC(0xb780), SHC(0x678e), SHC(0xb4c3), SHC(0x658d), SHC(0xb214), - SHC(0x637a), SHC(0xaf72), SHC(0x6155), SHC(0xacdf), SHC(0x5f1f), SHC(0xaa5a), SHC(0x5cd9), SHC(0xa7e4), - SHC(0x7fff), SHC(0x0000), SHC(0x7fd3), SHC(0xf94d), SHC(0x7f4c), SHC(0xf29f), SHC(0x7e6d), SHC(0xebfa), - SHC(0x7d34), SHC(0xe563), SHC(0x7ba3), SHC(0xdedf), SHC(0x79bc), SHC(0xd872), SHC(0x7780), SHC(0xd221), - SHC(0x74ef), SHC(0xcbf0), SHC(0x720d), SHC(0xc5e4), SHC(0x6eda), SHC(0xc000), SHC(0x6b5a), SHC(0xba49), - SHC(0x678e), SHC(0xb4c3), SHC(0x637a), SHC(0xaf72), SHC(0x5f1f), SHC(0xaa5a), SHC(0x5a82), SHC(0xa57e), - SHC(0x55a6), SHC(0xa0e1), SHC(0x508e), SHC(0x9c86), SHC(0x4b3d), SHC(0x9872), SHC(0x45b7), SHC(0x94a6), - SHC(0x4000), SHC(0x9126), SHC(0x3a1c), SHC(0x8df3), SHC(0x3410), SHC(0x8b11), SHC(0x2ddf), SHC(0x8880), - SHC(0x278e), SHC(0x8644), SHC(0x2121), SHC(0x845d), SHC(0x1a9d), SHC(0x82cc), SHC(0x1406), SHC(0x8193), - SHC(0x0d61), SHC(0x80b4), SHC(0x06b3), SHC(0x802d), SHC(0x7fff), SHC(0x0000), SHC(0x7f9b), SHC(0xf5f5), - SHC(0x7e6d), SHC(0xebfa), SHC(0x7c77), SHC(0xe21e), SHC(0x79bc), SHC(0xd872), SHC(0x7642), SHC(0xcf04), - SHC(0x720d), SHC(0xc5e4), SHC(0x6d23), SHC(0xbd1f), SHC(0x678e), SHC(0xb4c3), SHC(0x6155), SHC(0xacdf), - SHC(0x5a82), SHC(0xa57e), SHC(0x5321), SHC(0x9eab), SHC(0x4b3d), SHC(0x9872), SHC(0x42e1), SHC(0x92dd), - SHC(0x3a1c), SHC(0x8df3), SHC(0x30fc), SHC(0x89be), SHC(0x278e), SHC(0x8644), SHC(0x1de2), SHC(0x8389), - SHC(0x1406), SHC(0x8193), SHC(0x0a0b), SHC(0x8065), SHC(0x0000), SHC(0x8000), SHC(0xf5f5), SHC(0x8065), - SHC(0xebfa), SHC(0x8193), SHC(0xe21e), SHC(0x8389), SHC(0xd872), SHC(0x8644), SHC(0xcf04), SHC(0x89be), - SHC(0xc5e4), SHC(0x8df3), SHC(0xbd1f), SHC(0x92dd), SHC(0xb4c3), SHC(0x9872), SHC(0xacdf), SHC(0x9eab), - SHC(0x7fff), SHC(0x0000), SHC(0x7f4c), SHC(0xf29f), SHC(0x7d34), SHC(0xe563), SHC(0x79bc), SHC(0xd872), - SHC(0x74ef), SHC(0xcbf0), SHC(0x6eda), SHC(0xc000), SHC(0x678e), SHC(0xb4c3), SHC(0x5f1f), SHC(0xaa5a), - SHC(0x55a6), SHC(0xa0e1), SHC(0x4b3d), SHC(0x9872), SHC(0x4000), SHC(0x9126), SHC(0x3410), SHC(0x8b11), - SHC(0x278e), SHC(0x8644), SHC(0x1a9d), SHC(0x82cc), SHC(0x0d61), SHC(0x80b4), SHC(0x0000), SHC(0x8000), - SHC(0xf29f), SHC(0x80b4), SHC(0xe563), SHC(0x82cc), SHC(0xd872), SHC(0x8644), SHC(0xcbf0), SHC(0x8b11), - SHC(0xc000), SHC(0x9126), SHC(0xb4c3), SHC(0x9872), SHC(0xaa5a), SHC(0xa0e1), SHC(0xa0e1), SHC(0xaa5a), - SHC(0x9872), SHC(0xb4c3), SHC(0x9126), SHC(0xc000), SHC(0x8b11), SHC(0xcbf0), SHC(0x8644), SHC(0xd872), - SHC(0x82cc), SHC(0xe563), SHC(0x80b4), SHC(0xf29f), SHC(0x7fff), SHC(0x0000), SHC(0x7ee8), SHC(0xef4b), - SHC(0x7ba3), SHC(0xdedf), SHC(0x7642), SHC(0xcf04), SHC(0x6eda), SHC(0xc000), SHC(0x658d), SHC(0xb214), - SHC(0x5a82), SHC(0xa57e), SHC(0x4dec), SHC(0x9a73), SHC(0x4000), SHC(0x9126), SHC(0x30fc), SHC(0x89be), - SHC(0x2121), SHC(0x845d), SHC(0x10b5), SHC(0x8118), SHC(0x0000), SHC(0x8000), SHC(0xef4b), SHC(0x8118), - SHC(0xdedf), SHC(0x845d), SHC(0xcf04), SHC(0x89be), SHC(0xc000), SHC(0x9126), SHC(0xb214), SHC(0x9a73), - SHC(0xa57e), SHC(0xa57e), SHC(0x9a73), SHC(0xb214), SHC(0x9126), SHC(0xc000), SHC(0x89be), SHC(0xcf04), - SHC(0x845d), SHC(0xdedf), SHC(0x8118), SHC(0xef4b), SHC(0x8000), SHC(0x0000), SHC(0x8118), SHC(0x10b5), - SHC(0x845d), SHC(0x2121), SHC(0x89be), SHC(0x30fc), SHC(0x9126), SHC(0x4000), SHC(0x9a73), SHC(0x4dec), - SHC(0x7fff), SHC(0x0000), SHC(0x7e6d), SHC(0xebfa), SHC(0x79bc), SHC(0xd872), SHC(0x720d), SHC(0xc5e4), - SHC(0x678e), SHC(0xb4c3), SHC(0x5a82), SHC(0xa57e), SHC(0x4b3d), SHC(0x9872), SHC(0x3a1c), SHC(0x8df3), - SHC(0x278e), SHC(0x8644), SHC(0x1406), SHC(0x8193), SHC(0x0000), SHC(0x8000), SHC(0xebfa), SHC(0x8193), - SHC(0xd872), SHC(0x8644), SHC(0xc5e4), SHC(0x8df3), SHC(0xb4c3), SHC(0x9872), SHC(0xa57e), SHC(0xa57e), - SHC(0x9872), SHC(0xb4c3), SHC(0x8df3), SHC(0xc5e4), SHC(0x8644), SHC(0xd872), SHC(0x8193), SHC(0xebfa), - SHC(0x8000), SHC(0x0000), SHC(0x8193), SHC(0x1406), SHC(0x8644), SHC(0x278e), SHC(0x8df3), SHC(0x3a1c), - SHC(0x9872), SHC(0x4b3d), SHC(0xa57e), SHC(0x5a82), SHC(0xb4c3), SHC(0x678e), SHC(0xc5e4), SHC(0x720d), - SHC(0xd872), SHC(0x79bc), SHC(0xebfa), SHC(0x7e6d), SHC(0x7fff), SHC(0x0000), SHC(0x7ddb), SHC(0xe8ad), - SHC(0x7780), SHC(0xd221), SHC(0x6d23), SHC(0xbd1f), SHC(0x5f1f), SHC(0xaa5a), SHC(0x4dec), SHC(0x9a73), - SHC(0x3a1c), SHC(0x8df3), SHC(0x245b), SHC(0x8545), SHC(0x0d61), SHC(0x80b4), SHC(0xf5f5), SHC(0x8065), - SHC(0xdedf), SHC(0x845d), SHC(0xc8e5), SHC(0x8c78), SHC(0xb4c3), SHC(0x9872), SHC(0xa327), SHC(0xa7e4), - SHC(0x94a6), SHC(0xba49), SHC(0x89be), SHC(0xcf04), SHC(0x82cc), SHC(0xe563), SHC(0x800b), SHC(0xfca6), - SHC(0x8193), SHC(0x1406), SHC(0x8758), SHC(0x2aba), SHC(0x9126), SHC(0x4000), SHC(0x9eab), SHC(0x5321), - SHC(0xaf72), SHC(0x637a), SHC(0xc2ec), SHC(0x707d), SHC(0xd872), SHC(0x79bc), SHC(0xef4b), SHC(0x7ee8), - SHC(0x06b3), SHC(0x7fd3), SHC(0x1de2), SHC(0x7c77), SHC(0x3410), SHC(0x74ef), SHC(0x4880), SHC(0x697d), - SHC(0x7fff), SHC(0x0000), SHC(0x7ffd), SHC(0xfe53), SHC(0x7ff5), SHC(0xfca6), SHC(0x7fe7), SHC(0xfafa), - SHC(0x7fd3), SHC(0xf94d), SHC(0x7fba), SHC(0xf7a1), SHC(0x7f9b), SHC(0xf5f5), SHC(0x7f77), SHC(0xf44a), - SHC(0x7f4c), SHC(0xf29f), SHC(0x7f1d), SHC(0xf0f5), SHC(0x7ee8), SHC(0xef4b), SHC(0x7ead), SHC(0xeda2), - SHC(0x7e6d), SHC(0xebfa), SHC(0x7e27), SHC(0xea53), SHC(0x7ddb), SHC(0xe8ad), SHC(0x7d8a), SHC(0xe707), - SHC(0x7d34), SHC(0xe563), SHC(0x7cd8), SHC(0xe3c0), SHC(0x7c77), SHC(0xe21e), SHC(0x7c10), SHC(0xe07e), - SHC(0x7ba3), SHC(0xdedf), SHC(0x7b32), SHC(0xdd41), SHC(0x7abb), SHC(0xdba5), SHC(0x7a3e), SHC(0xda0b), - SHC(0x79bc), SHC(0xd872), SHC(0x7935), SHC(0xd6db), SHC(0x78a8), SHC(0xd546), SHC(0x7817), SHC(0xd3b2), - SHC(0x7780), SHC(0xd221), SHC(0x76e3), SHC(0xd092), SHC(0x7fff), SHC(0x0000), SHC(0x7fe7), SHC(0xfafa), - SHC(0x7f9b), SHC(0xf5f5), SHC(0x7f1d), SHC(0xf0f5), SHC(0x7e6d), SHC(0xebfa), SHC(0x7d8a), SHC(0xe707), - SHC(0x7c77), SHC(0xe21e), SHC(0x7b32), SHC(0xdd41), SHC(0x79bc), SHC(0xd872), SHC(0x7817), SHC(0xd3b2), - SHC(0x7642), SHC(0xcf04), SHC(0x743e), SHC(0xca69), SHC(0x720d), SHC(0xc5e4), SHC(0x6fae), SHC(0xc175), - SHC(0x6d23), SHC(0xbd1f), SHC(0x6a6e), SHC(0xb8e3), SHC(0x678e), SHC(0xb4c3), SHC(0x6485), SHC(0xb0c2), - SHC(0x6155), SHC(0xacdf), SHC(0x5dfe), SHC(0xa91d), SHC(0x5a82), SHC(0xa57e), SHC(0x56e3), SHC(0xa202), - SHC(0x5321), SHC(0x9eab), SHC(0x4f3e), SHC(0x9b7b), SHC(0x4b3d), SHC(0x9872), SHC(0x471d), SHC(0x9592), - SHC(0x42e1), SHC(0x92dd), SHC(0x3e8b), SHC(0x9052), SHC(0x3a1c), SHC(0x8df3), SHC(0x3597), SHC(0x8bc2), - SHC(0x7fff), SHC(0x0000), SHC(0x7fba), SHC(0xf7a1), SHC(0x7ee8), SHC(0xef4b), SHC(0x7d8a), SHC(0xe707), - SHC(0x7ba3), SHC(0xdedf), SHC(0x7935), SHC(0xd6db), SHC(0x7642), SHC(0xcf04), SHC(0x72cd), SHC(0xc763), - SHC(0x6eda), SHC(0xc000), SHC(0x6a6e), SHC(0xb8e3), SHC(0x658d), SHC(0xb214), SHC(0x603c), SHC(0xab9b), - SHC(0x5a82), SHC(0xa57e), SHC(0x5465), SHC(0x9fc4), SHC(0x4dec), SHC(0x9a73), SHC(0x471d), SHC(0x9592), - SHC(0x4000), SHC(0x9126), SHC(0x389d), SHC(0x8d33), SHC(0x30fc), SHC(0x89be), SHC(0x2925), SHC(0x86cb), - SHC(0x2121), SHC(0x845d), SHC(0x18f9), SHC(0x8276), SHC(0x10b5), SHC(0x8118), SHC(0x085f), SHC(0x8046), - SHC(0x0000), SHC(0x8000), SHC(0xf7a1), SHC(0x8046), SHC(0xef4b), SHC(0x8118), SHC(0xe707), SHC(0x8276), - SHC(0xdedf), SHC(0x845d), SHC(0xd6db), SHC(0x86cb), SHC(0x7fff), SHC(0x0000), SHC(0x7f77), SHC(0xf44a), - SHC(0x7ddb), SHC(0xe8ad), SHC(0x7b32), SHC(0xdd41), SHC(0x7780), SHC(0xd221), SHC(0x72cd), SHC(0xc763), - SHC(0x6d23), SHC(0xbd1f), SHC(0x668f), SHC(0xb36a), SHC(0x5f1f), SHC(0xaa5a), SHC(0x56e3), SHC(0xa202), - SHC(0x4dec), SHC(0x9a73), SHC(0x444d), SHC(0x93bf), SHC(0x3a1c), SHC(0x8df3), SHC(0x2f6e), SHC(0x891d), - SHC(0x245b), SHC(0x8545), SHC(0x18f9), SHC(0x8276), SHC(0x0d61), SHC(0x80b4), SHC(0x01ad), SHC(0x8003), - SHC(0xf5f5), SHC(0x8065), SHC(0xea53), SHC(0x81d9), SHC(0xdedf), SHC(0x845d), SHC(0xd3b2), SHC(0x87e9), - SHC(0xc8e5), SHC(0x8c78), SHC(0xbe8e), SHC(0x91ff), SHC(0xb4c3), SHC(0x9872), SHC(0xab9b), SHC(0x9fc4), - SHC(0xa327), SHC(0xa7e4), SHC(0x9b7b), SHC(0xb0c2), SHC(0x94a6), SHC(0xba49), SHC(0x8eb9), SHC(0xc467), - SHC(0x7fff), SHC(0x0000), SHC(0x7f1d), SHC(0xf0f5), SHC(0x7c77), SHC(0xe21e), SHC(0x7817), SHC(0xd3b2), - SHC(0x720d), SHC(0xc5e4), SHC(0x6a6e), SHC(0xb8e3), SHC(0x6155), SHC(0xacdf), SHC(0x56e3), SHC(0xa202), - SHC(0x4b3d), SHC(0x9872), SHC(0x3e8b), SHC(0x9052), SHC(0x30fc), SHC(0x89be), SHC(0x22bf), SHC(0x84ce), - SHC(0x1406), SHC(0x8193), SHC(0x0506), SHC(0x8019), SHC(0xf5f5), SHC(0x8065), SHC(0xe707), SHC(0x8276), - SHC(0xd872), SHC(0x8644), SHC(0xca69), SHC(0x8bc2), SHC(0xbd1f), SHC(0x92dd), SHC(0xb0c2), SHC(0x9b7b), - SHC(0xa57e), SHC(0xa57e), SHC(0x9b7b), SHC(0xb0c2), SHC(0x92dd), SHC(0xbd1f), SHC(0x8bc2), SHC(0xca69), - SHC(0x8644), SHC(0xd872), SHC(0x8276), SHC(0xe707), SHC(0x8065), SHC(0xf5f5), SHC(0x8019), SHC(0x0506), - SHC(0x8193), SHC(0x1406), SHC(0x84ce), SHC(0x22bf), SHC(0x7fff), SHC(0x0000), SHC(0x7ead), SHC(0xeda2), - SHC(0x7abb), SHC(0xdba5), SHC(0x743e), SHC(0xca69), SHC(0x6b5a), SHC(0xba49), SHC(0x603c), SHC(0xab9b), - SHC(0x5321), SHC(0x9eab), SHC(0x444d), SHC(0x93bf), SHC(0x3410), SHC(0x8b11), SHC(0x22bf), SHC(0x84ce), - SHC(0x10b5), SHC(0x8118), SHC(0xfe53), SHC(0x8003), SHC(0xebfa), SHC(0x8193), SHC(0xda0b), SHC(0x85c2), - SHC(0xc8e5), SHC(0x8c78), SHC(0xb8e3), SHC(0x9592), SHC(0xaa5a), SHC(0xa0e1), SHC(0x9d97), SHC(0xae27), - SHC(0x92dd), SHC(0xbd1f), SHC(0x8a65), SHC(0xcd79), SHC(0x845d), SHC(0xdedf), SHC(0x80e3), SHC(0xf0f5), - SHC(0x800b), SHC(0x035a), SHC(0x81d9), SHC(0x15ad), SHC(0x8644), SHC(0x278e), SHC(0x8d33), SHC(0x389d), - SHC(0x9683), SHC(0x4880), SHC(0xa202), SHC(0x56e3), SHC(0xaf72), SHC(0x637a), SHC(0xbe8e), SHC(0x6e01), - SHC(0x7fff), SHC(0x0000), SHC(0x7e27), SHC(0xea53), SHC(0x78a8), SHC(0xd546), SHC(0x6fae), SHC(0xc175), - SHC(0x637a), SHC(0xaf72), SHC(0x5465), SHC(0x9fc4), SHC(0x42e1), SHC(0x92dd), SHC(0x2f6e), SHC(0x891d), - SHC(0x1a9d), SHC(0x82cc), SHC(0x0506), SHC(0x8019), SHC(0xef4b), SHC(0x8118), SHC(0xda0b), SHC(0x85c2), - SHC(0xc5e4), SHC(0x8df3), SHC(0xb36a), SHC(0x9971), SHC(0xa327), SHC(0xa7e4), SHC(0x9592), SHC(0xb8e3), - SHC(0x8b11), SHC(0xcbf0), SHC(0x83f0), SHC(0xe07e), SHC(0x8065), SHC(0xf5f5), SHC(0x8089), SHC(0x0bb6), - SHC(0x845d), SHC(0x2121), SHC(0x8bc2), SHC(0x3597), SHC(0x9683), SHC(0x4880), SHC(0xa450), SHC(0x5951), - SHC(0xb4c3), SHC(0x678e), SHC(0xc763), SHC(0x72cd), SHC(0xdba5), SHC(0x7abb), SHC(0xf0f5), SHC(0x7f1d), - SHC(0x06b3), SHC(0x7fd3), SHC(0x1c40), SHC(0x7cd8), SHC(0x7fff), SHC(0x0000), SHC(0x7d8a), SHC(0xe707), - SHC(0x7642), SHC(0xcf04), SHC(0x6a6e), SHC(0xb8e3), SHC(0x5a82), SHC(0xa57e), SHC(0x471d), SHC(0x9592), - SHC(0x30fc), SHC(0x89be), SHC(0x18f9), SHC(0x8276), SHC(0x0000), SHC(0x8000), SHC(0xe707), SHC(0x8276), - SHC(0xcf04), SHC(0x89be), SHC(0xb8e3), SHC(0x9592), SHC(0xa57e), SHC(0xa57e), SHC(0x9592), SHC(0xb8e3), - SHC(0x89be), SHC(0xcf04), SHC(0x8276), SHC(0xe707), SHC(0x8000), SHC(0x0000), SHC(0x8276), SHC(0x18f9), - SHC(0x89be), SHC(0x30fc), SHC(0x9592), SHC(0x471d), SHC(0xa57e), SHC(0x5a82), SHC(0xb8e3), SHC(0x6a6e), - SHC(0xcf04), SHC(0x7642), SHC(0xe707), SHC(0x7d8a), SHC(0x0000), SHC(0x7fff), SHC(0x18f9), SHC(0x7d8a), - SHC(0x30fc), SHC(0x7642), SHC(0x471d), SHC(0x6a6e), SHC(0x5a82), SHC(0x5a82), SHC(0x6a6e), SHC(0x471d) -}; - -const Word16 RotVector_600[2*(600-30)] = -{ - SHC(0x7fff), SHC(0x0000), SHC(0x7ff9), SHC(0xfd52), - SHC(0x7fe3), SHC(0xfaa4), SHC(0x7fbf), SHC(0xf7f6), SHC(0x7f8d), SHC(0xf54a), SHC(0x7f4c), SHC(0xf29f), - SHC(0x7efe), SHC(0xeff5), SHC(0x7ea0), SHC(0xed4d), SHC(0x7e35), SHC(0xeaa7), SHC(0x7dbc), SHC(0xe804), - SHC(0x7d34), SHC(0xe563), SHC(0x7c9e), SHC(0xe2c5), SHC(0x7bfb), SHC(0xe02b), SHC(0x7b49), SHC(0xdd94), - SHC(0x7a89), SHC(0xdb01), SHC(0x79bc), SHC(0xd872), SHC(0x78e1), SHC(0xd5e8), SHC(0x77f9), SHC(0xd362), - SHC(0x7703), SHC(0xd0e1), SHC(0x7600), SHC(0xce66), SHC(0x74ef), SHC(0xcbf0), SHC(0x73d1), SHC(0xc980), - SHC(0x72a7), SHC(0xc716), SHC(0x716f), SHC(0xc4b3), SHC(0x702b), SHC(0xc256), SHC(0x6eda), SHC(0xc000), - SHC(0x6d7d), SHC(0xbdb1), SHC(0x6c13), SHC(0xbb6a), SHC(0x6a9d), SHC(0xb92a), SHC(0x691b), SHC(0xb6f3), - SHC(0x7fff), SHC(0x0000), SHC(0x7fe3), SHC(0xfaa4), SHC(0x7f8d), SHC(0xf54a), SHC(0x7efe), SHC(0xeff5), - SHC(0x7e35), SHC(0xeaa7), SHC(0x7d34), SHC(0xe563), SHC(0x7bfb), SHC(0xe02b), SHC(0x7a89), SHC(0xdb01), - SHC(0x78e1), SHC(0xd5e8), SHC(0x7703), SHC(0xd0e1), SHC(0x74ef), SHC(0xcbf0), SHC(0x72a7), SHC(0xc716), - SHC(0x702b), SHC(0xc256), SHC(0x6d7d), SHC(0xbdb1), SHC(0x6a9d), SHC(0xb92a), SHC(0x678e), SHC(0xb4c3), - SHC(0x6450), SHC(0xb07e), SHC(0x60e5), SHC(0xac5d), SHC(0x5d4f), SHC(0xa861), SHC(0x598f), SHC(0xa48c), - SHC(0x55a6), SHC(0xa0e1), SHC(0x5197), SHC(0x9d60), SHC(0x4d64), SHC(0x9a0b), SHC(0x490d), SHC(0x96e5), - SHC(0x4496), SHC(0x93ed), SHC(0x4000), SHC(0x9126), SHC(0x3b4d), SHC(0x8e91), SHC(0x3680), SHC(0x8c2f), - SHC(0x319a), SHC(0x8a00), SHC(0x2c9e), SHC(0x8807), SHC(0x7fff), SHC(0x0000), SHC(0x7fbf), SHC(0xf7f6), - SHC(0x7efe), SHC(0xeff5), SHC(0x7dbc), SHC(0xe804), SHC(0x7bfb), SHC(0xe02b), SHC(0x79bc), SHC(0xd872), - SHC(0x7703), SHC(0xd0e1), SHC(0x73d1), SHC(0xc980), SHC(0x702b), SHC(0xc256), SHC(0x6c13), SHC(0xbb6a), - SHC(0x678e), SHC(0xb4c3), SHC(0x62a0), SHC(0xae69), SHC(0x5d4f), SHC(0xa861), SHC(0x579f), SHC(0xa2b1), - SHC(0x5197), SHC(0x9d60), SHC(0x4b3d), SHC(0x9872), SHC(0x4496), SHC(0x93ed), SHC(0x3daa), SHC(0x8fd5), - SHC(0x3680), SHC(0x8c2f), SHC(0x2f1f), SHC(0x88fd), SHC(0x278e), SHC(0x8644), SHC(0x1fd5), SHC(0x8405), - SHC(0x17fc), SHC(0x8244), SHC(0x100b), SHC(0x8102), SHC(0x080a), SHC(0x8041), SHC(0x0000), SHC(0x8000), - SHC(0xf7f6), SHC(0x8041), SHC(0xeff5), SHC(0x8102), SHC(0xe804), SHC(0x8244), SHC(0xe02b), SHC(0x8405), - SHC(0x7fff), SHC(0x0000), SHC(0x7f8d), SHC(0xf54a), SHC(0x7e35), SHC(0xeaa7), SHC(0x7bfb), SHC(0xe02b), - SHC(0x78e1), SHC(0xd5e8), SHC(0x74ef), SHC(0xcbf0), SHC(0x702b), SHC(0xc256), SHC(0x6a9d), SHC(0xb92a), - SHC(0x6450), SHC(0xb07e), SHC(0x5d4f), SHC(0xa861), SHC(0x55a6), SHC(0xa0e1), SHC(0x4d64), SHC(0x9a0b), - SHC(0x4496), SHC(0x93ed), SHC(0x3b4d), SHC(0x8e91), SHC(0x319a), SHC(0x8a00), SHC(0x278e), SHC(0x8644), - SHC(0x1d3b), SHC(0x8362), SHC(0x12b3), SHC(0x8160), SHC(0x080a), SHC(0x8041), SHC(0xfd52), SHC(0x8007), - SHC(0xf29f), SHC(0x80b4), SHC(0xe804), SHC(0x8244), SHC(0xdd94), SHC(0x84b7), SHC(0xd362), SHC(0x8807), - SHC(0xc980), SHC(0x8c2f), SHC(0xc000), SHC(0x9126), SHC(0xb6f3), SHC(0x96e5), SHC(0xae69), SHC(0x9d60), - SHC(0xa671), SHC(0xa48c), SHC(0x9f1b), SHC(0xac5d), SHC(0x7fff), SHC(0x0000), SHC(0x7f4c), SHC(0xf29f), - SHC(0x7d34), SHC(0xe563), SHC(0x79bc), SHC(0xd872), SHC(0x74ef), SHC(0xcbf0), SHC(0x6eda), SHC(0xc000), - SHC(0x678e), SHC(0xb4c3), SHC(0x5f1f), SHC(0xaa5a), SHC(0x55a6), SHC(0xa0e1), SHC(0x4b3d), SHC(0x9872), - SHC(0x4000), SHC(0x9126), SHC(0x3410), SHC(0x8b11), SHC(0x278e), SHC(0x8644), SHC(0x1a9d), SHC(0x82cc), - SHC(0x0d61), SHC(0x80b4), SHC(0x0000), SHC(0x8000), SHC(0xf29f), SHC(0x80b4), SHC(0xe563), SHC(0x82cc), - SHC(0xd872), SHC(0x8644), SHC(0xcbf0), SHC(0x8b11), SHC(0xc000), SHC(0x9126), SHC(0xb4c3), SHC(0x9872), - SHC(0xaa5a), SHC(0xa0e1), SHC(0xa0e1), SHC(0xaa5a), SHC(0x9872), SHC(0xb4c3), SHC(0x9126), SHC(0xc000), - SHC(0x8b11), SHC(0xcbf0), SHC(0x8644), SHC(0xd872), SHC(0x82cc), SHC(0xe563), SHC(0x80b4), SHC(0xf29f), - SHC(0x7fff), SHC(0x0000), SHC(0x7efe), SHC(0xeff5), SHC(0x7bfb), SHC(0xe02b), SHC(0x7703), SHC(0xd0e1), - SHC(0x702b), SHC(0xc256), SHC(0x678e), SHC(0xb4c3), SHC(0x5d4f), SHC(0xa861), SHC(0x5197), SHC(0x9d60), - SHC(0x4496), SHC(0x93ed), SHC(0x3680), SHC(0x8c2f), SHC(0x278e), SHC(0x8644), SHC(0x17fc), SHC(0x8244), - SHC(0x080a), SHC(0x8041), SHC(0xf7f6), SHC(0x8041), SHC(0xe804), SHC(0x8244), SHC(0xd872), SHC(0x8644), - SHC(0xc980), SHC(0x8c2f), SHC(0xbb6a), SHC(0x93ed), SHC(0xae69), SHC(0x9d60), SHC(0xa2b1), SHC(0xa861), - SHC(0x9872), SHC(0xb4c3), SHC(0x8fd5), SHC(0xc256), SHC(0x88fd), SHC(0xd0e1), SHC(0x8405), SHC(0xe02b), - SHC(0x8102), SHC(0xeff5), SHC(0x8000), SHC(0x0000), SHC(0x8102), SHC(0x100b), SHC(0x8405), SHC(0x1fd5), - SHC(0x88fd), SHC(0x2f1f), SHC(0x8fd5), SHC(0x3daa), SHC(0x7fff), SHC(0x0000), SHC(0x7ea0), SHC(0xed4d), - SHC(0x7a89), SHC(0xdb01), SHC(0x73d1), SHC(0xc980), SHC(0x6a9d), SHC(0xb92a), SHC(0x5f1f), SHC(0xaa5a), - SHC(0x5197), SHC(0x9d60), SHC(0x424f), SHC(0x9283), SHC(0x319a), SHC(0x8a00), SHC(0x1fd5), SHC(0x8405), - SHC(0x0d61), SHC(0x80b4), SHC(0xfaa4), SHC(0x801d), SHC(0xe804), SHC(0x8244), SHC(0xd5e8), SHC(0x871f), - SHC(0xc4b3), SHC(0x8e91), SHC(0xb4c3), SHC(0x9872), SHC(0xa671), SHC(0xa48c), SHC(0x9a0b), SHC(0xb29c), - SHC(0x8fd5), SHC(0xc256), SHC(0x8807), SHC(0xd362), SHC(0x82cc), SHC(0xe563), SHC(0x8041), SHC(0xf7f6), - SHC(0x8073), SHC(0x0ab6), SHC(0x8362), SHC(0x1d3b), SHC(0x88fd), SHC(0x2f1f), SHC(0x9126), SHC(0x4000), - SHC(0x9bb0), SHC(0x4f82), SHC(0xa861), SHC(0x5d4f), SHC(0xb6f3), SHC(0x691b), SHC(0xc716), SHC(0x72a7), - SHC(0x7fff), SHC(0x0000), SHC(0x7e35), SHC(0xeaa7), SHC(0x78e1), SHC(0xd5e8), SHC(0x702b), SHC(0xc256), - SHC(0x6450), SHC(0xb07e), SHC(0x55a6), SHC(0xa0e1), SHC(0x4496), SHC(0x93ed), SHC(0x319a), SHC(0x8a00), - SHC(0x1d3b), SHC(0x8362), SHC(0x080a), SHC(0x8041), SHC(0xf29f), SHC(0x80b4), SHC(0xdd94), SHC(0x84b7), - SHC(0xc980), SHC(0x8c2f), SHC(0xb6f3), SHC(0x96e5), SHC(0xa671), SHC(0xa48c), SHC(0x9872), SHC(0xb4c3), - SHC(0x8d59), SHC(0xc716), SHC(0x8577), SHC(0xdb01), SHC(0x8102), SHC(0xeff5), SHC(0x801d), SHC(0x055c), - SHC(0x82cc), SHC(0x1a9d), SHC(0x88fd), SHC(0x2f1f), SHC(0x9283), SHC(0x424f), SHC(0x9f1b), SHC(0x53a3), - SHC(0xae69), SHC(0x62a0), SHC(0xc000), SHC(0x6eda), SHC(0xd362), SHC(0x77f9), SHC(0xe804), SHC(0x7dbc), - SHC(0xfd52), SHC(0x7ff9), SHC(0x12b3), SHC(0x7ea0), SHC(0x7fff), SHC(0x0000), SHC(0x7dbc), SHC(0xe804), - SHC(0x7703), SHC(0xd0e1), SHC(0x6c13), SHC(0xbb6a), SHC(0x5d4f), SHC(0xa861), SHC(0x4b3d), SHC(0x9872), - SHC(0x3680), SHC(0x8c2f), SHC(0x1fd5), SHC(0x8405), SHC(0x080a), SHC(0x8041), SHC(0xeff5), SHC(0x8102), - SHC(0xd872), SHC(0x8644), SHC(0xc256), SHC(0x8fd5), SHC(0xae69), SHC(0x9d60), SHC(0x9d60), SHC(0xae69), - SHC(0x8fd5), SHC(0xc256), SHC(0x8644), SHC(0xd872), SHC(0x8102), SHC(0xeff5), SHC(0x8041), SHC(0x080a), - SHC(0x8405), SHC(0x1fd5), SHC(0x8c2f), SHC(0x3680), SHC(0x9872), SHC(0x4b3d), SHC(0xa861), SHC(0x5d4f), - SHC(0xbb6a), SHC(0x6c13), SHC(0xd0e1), SHC(0x7703), SHC(0xe804), SHC(0x7dbc), SHC(0x0000), SHC(0x7fff), - SHC(0x17fc), SHC(0x7dbc), SHC(0x2f1f), SHC(0x7703), SHC(0x4496), SHC(0x6c13), SHC(0x579f), SHC(0x5d4f), - SHC(0x7fff), SHC(0x0000), SHC(0x7ffe), SHC(0xfea9), SHC(0x7ff9), SHC(0xfd52), SHC(0x7ff0), SHC(0xfbfb), - SHC(0x7fe3), SHC(0xfaa4), SHC(0x7fd3), SHC(0xf94d), SHC(0x7fbf), SHC(0xf7f6), SHC(0x7fa8), SHC(0xf6a0), - SHC(0x7f8d), SHC(0xf54a), SHC(0x7f6f), SHC(0xf3f4), SHC(0x7f4c), SHC(0xf29f), SHC(0x7f27), SHC(0xf14a), - SHC(0x7efe), SHC(0xeff5), SHC(0x7ed1), SHC(0xeea1), SHC(0x7ea0), SHC(0xed4d), SHC(0x7e6d), SHC(0xebfa), - SHC(0x7e35), SHC(0xeaa7), SHC(0x7dfa), SHC(0xe955), SHC(0x7dbc), SHC(0xe804), SHC(0x7d7a), SHC(0xe6b3), - SHC(0x7d34), SHC(0xe563), SHC(0x7ceb), SHC(0xe414), SHC(0x7c9e), SHC(0xe2c5), SHC(0x7c4e), SHC(0xe178), - SHC(0x7bfb), SHC(0xe02b), SHC(0x7ba3), SHC(0xdedf), SHC(0x7b49), SHC(0xdd94), SHC(0x7aeb), SHC(0xdc4a), - SHC(0x7a89), SHC(0xdb01), SHC(0x7a25), SHC(0xd9b9), SHC(0x7fff), SHC(0x0000), SHC(0x7ff0), SHC(0xfbfb), - SHC(0x7fbf), SHC(0xf7f6), SHC(0x7f6f), SHC(0xf3f4), SHC(0x7efe), SHC(0xeff5), SHC(0x7e6d), SHC(0xebfa), - SHC(0x7dbc), SHC(0xe804), SHC(0x7ceb), SHC(0xe414), SHC(0x7bfb), SHC(0xe02b), SHC(0x7aeb), SHC(0xdc4a), - SHC(0x79bc), SHC(0xd872), SHC(0x786f), SHC(0xd4a4), SHC(0x7703), SHC(0xd0e1), SHC(0x7579), SHC(0xcd2a), - SHC(0x73d1), SHC(0xc980), SHC(0x720d), SHC(0xc5e4), SHC(0x702b), SHC(0xc256), SHC(0x6e2d), SHC(0xbed8), - SHC(0x6c13), SHC(0xbb6a), SHC(0x69de), SHC(0xb80e), SHC(0x678e), SHC(0xb4c3), SHC(0x6524), SHC(0xb18c), - SHC(0x62a0), SHC(0xae69), SHC(0x6004), SHC(0xab5a), SHC(0x5d4f), SHC(0xa861), SHC(0x5a82), SHC(0xa57e), - SHC(0x579f), SHC(0xa2b1), SHC(0x54a6), SHC(0x9ffc), SHC(0x5197), SHC(0x9d60), SHC(0x4e74), SHC(0x9adc), - SHC(0x7fff), SHC(0x0000), SHC(0x7fd3), SHC(0xf94d), SHC(0x7f4c), SHC(0xf29f), SHC(0x7e6d), SHC(0xebfa), - SHC(0x7d34), SHC(0xe563), SHC(0x7ba3), SHC(0xdedf), SHC(0x79bc), SHC(0xd872), SHC(0x7780), SHC(0xd221), - SHC(0x74ef), SHC(0xcbf0), SHC(0x720d), SHC(0xc5e4), SHC(0x6eda), SHC(0xc000), SHC(0x6b5a), SHC(0xba49), - SHC(0x678e), SHC(0xb4c3), SHC(0x637a), SHC(0xaf72), SHC(0x5f1f), SHC(0xaa5a), SHC(0x5a82), SHC(0xa57e), - SHC(0x55a6), SHC(0xa0e1), SHC(0x508e), SHC(0x9c86), SHC(0x4b3d), SHC(0x9872), SHC(0x45b7), SHC(0x94a6), - SHC(0x4000), SHC(0x9126), SHC(0x3a1c), SHC(0x8df3), SHC(0x3410), SHC(0x8b11), SHC(0x2ddf), SHC(0x8880), - SHC(0x278e), SHC(0x8644), SHC(0x2121), SHC(0x845d), SHC(0x1a9d), SHC(0x82cc), SHC(0x1406), SHC(0x8193), - SHC(0x0d61), SHC(0x80b4), SHC(0x06b3), SHC(0x802d), SHC(0x7fff), SHC(0x0000), SHC(0x7fa8), SHC(0xf6a0), - SHC(0x7ea0), SHC(0xed4d), SHC(0x7ceb), SHC(0xe414), SHC(0x7a89), SHC(0xdb01), SHC(0x7780), SHC(0xd221), - SHC(0x73d1), SHC(0xc980), SHC(0x6f84), SHC(0xc12a), SHC(0x6a9d), SHC(0xb92a), SHC(0x6524), SHC(0xb18c), - SHC(0x5f1f), SHC(0xaa5a), SHC(0x5898), SHC(0xa39d), SHC(0x5197), SHC(0x9d60), SHC(0x4a26), SHC(0x97aa), - SHC(0x424f), SHC(0x9283), SHC(0x3a1c), SHC(0x8df3), SHC(0x319a), SHC(0x8a00), SHC(0x28d4), SHC(0x86b0), - SHC(0x1fd5), SHC(0x8405), SHC(0x16ab), SHC(0x8206), SHC(0x0d61), SHC(0x80b4), SHC(0x0405), SHC(0x8010), - SHC(0xfaa4), SHC(0x801d), SHC(0xf14a), SHC(0x80d9), SHC(0xe804), SHC(0x8244), SHC(0xdedf), SHC(0x845d), - SHC(0xd5e8), SHC(0x871f), SHC(0xcd2a), SHC(0x8a87), SHC(0xc4b3), SHC(0x8e91), SHC(0xbc8d), SHC(0x9337), - SHC(0x7fff), SHC(0x0000), SHC(0x7f6f), SHC(0xf3f4), SHC(0x7dbc), SHC(0xe804), SHC(0x7aeb), SHC(0xdc4a), - SHC(0x7703), SHC(0xd0e1), SHC(0x720d), SHC(0xc5e4), SHC(0x6c13), SHC(0xbb6a), SHC(0x6524), SHC(0xb18c), - SHC(0x5d4f), SHC(0xa861), SHC(0x54a6), SHC(0x9ffc), SHC(0x4b3d), SHC(0x9872), SHC(0x4128), SHC(0x91d3), - SHC(0x3680), SHC(0x8c2f), SHC(0x2b5c), SHC(0x8791), SHC(0x1fd5), SHC(0x8405), SHC(0x1406), SHC(0x8193), - SHC(0x080a), SHC(0x8041), SHC(0xfbfb), SHC(0x8010), SHC(0xeff5), SHC(0x8102), SHC(0xe414), SHC(0x8315), - SHC(0xd872), SHC(0x8644), SHC(0xcd2a), SHC(0x8a87), SHC(0xc256), SHC(0x8fd5), SHC(0xb80e), SHC(0x9622), - SHC(0xae69), SHC(0x9d60), SHC(0xa57e), SHC(0xa57e), SHC(0x9d60), SHC(0xae69), SHC(0x9622), SHC(0xb80e), - SHC(0x8fd5), SHC(0xc256), SHC(0x8a87), SHC(0xcd2a), SHC(0x7fff), SHC(0x0000), SHC(0x7f27), SHC(0xf14a), - SHC(0x7c9e), SHC(0xe2c5), SHC(0x786f), SHC(0xd4a4), SHC(0x72a7), SHC(0xc716), SHC(0x6b5a), SHC(0xba49), - SHC(0x62a0), SHC(0xae69), SHC(0x5898), SHC(0xa39d), SHC(0x4d64), SHC(0x9a0b), SHC(0x4128), SHC(0x91d3), - SHC(0x3410), SHC(0x8b11), SHC(0x2647), SHC(0x85db), SHC(0x17fc), SHC(0x8244), SHC(0x0960), SHC(0x8058), - SHC(0xfaa4), SHC(0x801d), SHC(0xebfa), SHC(0x8193), SHC(0xdd94), SHC(0x84b7), SHC(0xcfa3), SHC(0x897d), - SHC(0xc256), SHC(0x8fd5), SHC(0xb5da), SHC(0x97aa), SHC(0xaa5a), SHC(0xa0e1), SHC(0x9ffc), SHC(0xab5a), - SHC(0x96e5), SHC(0xb6f3), SHC(0x8f31), SHC(0xc383), SHC(0x88fd), SHC(0xd0e1), SHC(0x845d), SHC(0xdedf), - SHC(0x8160), SHC(0xed4d), SHC(0x8010), SHC(0xfbfb), SHC(0x8073), SHC(0x0ab6), SHC(0x8286), SHC(0x194d), - SHC(0x7fff), SHC(0x0000), SHC(0x7ed1), SHC(0xeea1), SHC(0x7b49), SHC(0xdd94), SHC(0x7579), SHC(0xcd2a), - SHC(0x6d7d), SHC(0xbdb1), SHC(0x637a), SHC(0xaf72), SHC(0x579f), SHC(0xa2b1), SHC(0x4a26), SHC(0x97aa), - SHC(0x3b4d), SHC(0x8e91), SHC(0x2b5c), SHC(0x8791), SHC(0x1a9d), SHC(0x82cc), SHC(0x0960), SHC(0x8058), - SHC(0xf7f6), SHC(0x8041), SHC(0xe6b3), SHC(0x8286), SHC(0xd5e8), SHC(0x871f), SHC(0xc5e4), SHC(0x8df3), - SHC(0xb6f3), SHC(0x96e5), SHC(0xa95c), SHC(0xa1c8), SHC(0x9d60), SHC(0xae69), SHC(0x9337), SHC(0xbc8d), - SHC(0x8b11), SHC(0xcbf0), SHC(0x8515), SHC(0xdc4a), SHC(0x8160), SHC(0xed4d), SHC(0x8002), SHC(0xfea9), - SHC(0x8102), SHC(0x100b), SHC(0x845d), SHC(0x2121), SHC(0x8a00), SHC(0x319a), SHC(0x91d3), SHC(0x4128), - SHC(0x9bb0), SHC(0x4f82), SHC(0xa768), SHC(0x5c63), SHC(0x7fff), SHC(0x0000), SHC(0x7e6d), SHC(0xebfa), - SHC(0x79bc), SHC(0xd872), SHC(0x720d), SHC(0xc5e4), SHC(0x678e), SHC(0xb4c3), SHC(0x5a82), SHC(0xa57e), - SHC(0x4b3d), SHC(0x9872), SHC(0x3a1c), SHC(0x8df3), SHC(0x278e), SHC(0x8644), SHC(0x1406), SHC(0x8193), - SHC(0x0000), SHC(0x8000), SHC(0xebfa), SHC(0x8193), SHC(0xd872), SHC(0x8644), SHC(0xc5e4), SHC(0x8df3), - SHC(0xb4c3), SHC(0x9872), SHC(0xa57e), SHC(0xa57e), SHC(0x9872), SHC(0xb4c3), SHC(0x8df3), SHC(0xc5e4), - SHC(0x8644), SHC(0xd872), SHC(0x8193), SHC(0xebfa), SHC(0x8000), SHC(0x0000), SHC(0x8193), SHC(0x1406), - SHC(0x8644), SHC(0x278e), SHC(0x8df3), SHC(0x3a1c), SHC(0x9872), SHC(0x4b3d), SHC(0xa57e), SHC(0x5a82), - SHC(0xb4c3), SHC(0x678e), SHC(0xc5e4), SHC(0x720d), SHC(0xd872), SHC(0x79bc), SHC(0xebfa), SHC(0x7e6d), - SHC(0x7fff), SHC(0x0000), SHC(0x7dfa), SHC(0xe955), SHC(0x77f9), SHC(0xd362), SHC(0x6e2d), SHC(0xbed8), - SHC(0x60e5), SHC(0xac5d), SHC(0x508e), SHC(0x9c86), SHC(0x3daa), SHC(0x8fd5), SHC(0x28d4), SHC(0x86b0), - SHC(0x12b3), SHC(0x8160), SHC(0xfbfb), SHC(0x8010), SHC(0xe563), SHC(0x82cc), SHC(0xcfa3), SHC(0x897d), - SHC(0xbb6a), SHC(0x93ed), SHC(0xa95c), SHC(0xa1c8), SHC(0x9a0b), SHC(0xb29c), SHC(0x8df3), SHC(0xc5e4), - SHC(0x8577), SHC(0xdb01), SHC(0x80d9), SHC(0xf14a), SHC(0x8041), SHC(0x080a), SHC(0x83b2), SHC(0x1e88), - SHC(0x8b11), SHC(0x3410), SHC(0x9622), SHC(0x47f2), SHC(0xa48c), SHC(0x598f), SHC(0xb5da), SHC(0x6856), - SHC(0xc980), SHC(0x73d1), SHC(0xdedf), SHC(0x7ba3), SHC(0xf54a), SHC(0x7f8d), SHC(0x0c0c), SHC(0x7f6f), - SHC(0x226c), SHC(0x7b49), SHC(0x37b6), SHC(0x733e), SHC(0x7fff), SHC(0x0000), SHC(0x7d7a), SHC(0xe6b3), - SHC(0x7600), SHC(0xce66), SHC(0x69de), SHC(0xb80e), SHC(0x598f), SHC(0xa48c), SHC(0x45b7), SHC(0x94a6), - SHC(0x2f1f), SHC(0x88fd), SHC(0x16ab), SHC(0x8206), SHC(0xfd52), SHC(0x8007), SHC(0xe414), SHC(0x8315), - SHC(0xcbf0), SHC(0x8b11), SHC(0xb5da), SHC(0x97aa), SHC(0xa2b1), SHC(0xa861), SHC(0x9337), SHC(0xbc8d), - SHC(0x8807), SHC(0xd362), SHC(0x8193), SHC(0xebfa), SHC(0x801d), SHC(0x055c), SHC(0x83b2), SHC(0x1e88), - SHC(0x8c2f), SHC(0x3680), SHC(0x993d), SHC(0x4c51), SHC(0xaa5a), SHC(0x5f1f), SHC(0xbed8), SHC(0x6e2d), - SHC(0xd5e8), SHC(0x78e1), SHC(0xeea1), SHC(0x7ed1), SHC(0x080a), SHC(0x7fbf), SHC(0x2121), SHC(0x7ba3), - SHC(0x38ea), SHC(0x72a7), SHC(0x4e74), SHC(0x6524), SHC(0x60e5), SHC(0x53a3), SHC(0x6f84), SHC(0x3ed6) -}; - - - -/** - * \brief Twiddle factors are unscaled - */ -const Word16 RotVector_256[2*(256-32)] = -{ - SHC(0x7fff), SHC(0x0000), SHC(0x7ff6), SHC(0xfcdc), SHC(0x7fd9), SHC(0xf9b8), SHC(0x7fa7), SHC(0xf695), - SHC(0x7f62), SHC(0xf374), SHC(0x7f0a), SHC(0xf055), SHC(0x7e9d), SHC(0xed38), SHC(0x7e1e), SHC(0xea1e), - SHC(0x7d8a), SHC(0xe707), SHC(0x7ce4), SHC(0xe3f4), SHC(0x7c2a), SHC(0xe0e6), SHC(0x7b5d), SHC(0xdddc), - SHC(0x7a7d), SHC(0xdad8), SHC(0x798a), SHC(0xd7d9), SHC(0x7885), SHC(0xd4e1), SHC(0x776c), SHC(0xd1ef), - SHC(0x7642), SHC(0xcf04), SHC(0x7505), SHC(0xcc21), SHC(0x73b6), SHC(0xc946), SHC(0x7255), SHC(0xc673), - SHC(0x70e3), SHC(0xc3a9), SHC(0x6f5f), SHC(0xc0e9), SHC(0x6dca), SHC(0xbe32), SHC(0x6c24), SHC(0xbb85), - SHC(0x6a6e), SHC(0xb8e3), SHC(0x68a7), SHC(0xb64c), SHC(0x66d0), SHC(0xb3c0), SHC(0x64e9), SHC(0xb140), - SHC(0x62f2), SHC(0xaecc), SHC(0x60ec), SHC(0xac65), SHC(0x5ed7), SHC(0xaa0a), SHC(0x5cb4), SHC(0xa7bd), - SHC(0x7fff), SHC(0x0000), SHC(0x7fd9), SHC(0xf9b8), SHC(0x7f62), SHC(0xf374), SHC(0x7e9d), SHC(0xed38), - SHC(0x7d8a), SHC(0xe707), SHC(0x7c2a), SHC(0xe0e6), SHC(0x7a7d), SHC(0xdad8), SHC(0x7885), SHC(0xd4e1), - SHC(0x7642), SHC(0xcf04), SHC(0x73b6), SHC(0xc946), SHC(0x70e3), SHC(0xc3a9), SHC(0x6dca), SHC(0xbe32), - SHC(0x6a6e), SHC(0xb8e3), SHC(0x66d0), SHC(0xb3c0), SHC(0x62f2), SHC(0xaecc), SHC(0x5ed7), SHC(0xaa0a), - SHC(0x5a82), SHC(0xa57e), SHC(0x55f6), SHC(0xa129), SHC(0x5134), SHC(0x9d0e), SHC(0x4c40), SHC(0x9930), - SHC(0x471d), SHC(0x9592), SHC(0x41ce), SHC(0x9236), SHC(0x3c57), SHC(0x8f1d), SHC(0x36ba), SHC(0x8c4a), - SHC(0x30fc), SHC(0x89be), SHC(0x2b1f), SHC(0x877b), SHC(0x2528), SHC(0x8583), SHC(0x1f1a), SHC(0x83d6), - SHC(0x18f9), SHC(0x8276), SHC(0x12c8), SHC(0x8163), SHC(0x0c8c), SHC(0x809e), SHC(0x0648), SHC(0x8027), - SHC(0x7fff), SHC(0x0000), SHC(0x7fa7), SHC(0xf695), SHC(0x7e9d), SHC(0xed38), SHC(0x7ce4), SHC(0xe3f4), - SHC(0x7a7d), SHC(0xdad8), SHC(0x776c), SHC(0xd1ef), SHC(0x73b6), SHC(0xc946), SHC(0x6f5f), SHC(0xc0e9), - SHC(0x6a6e), SHC(0xb8e3), SHC(0x64e9), SHC(0xb140), SHC(0x5ed7), SHC(0xaa0a), SHC(0x5843), SHC(0xa34c), - SHC(0x5134), SHC(0x9d0e), SHC(0x49b4), SHC(0x9759), SHC(0x41ce), SHC(0x9236), SHC(0x398d), SHC(0x8dab), - SHC(0x30fc), SHC(0x89be), SHC(0x2827), SHC(0x8676), SHC(0x1f1a), SHC(0x83d6), SHC(0x15e2), SHC(0x81e2), - SHC(0x0c8c), SHC(0x809e), SHC(0x0324), SHC(0x800a), SHC(0xf9b8), SHC(0x8027), SHC(0xf055), SHC(0x80f6), - SHC(0xe707), SHC(0x8276), SHC(0xdddc), SHC(0x84a3), SHC(0xd4e1), SHC(0x877b), SHC(0xcc21), SHC(0x8afb), - SHC(0xc3a9), SHC(0x8f1d), SHC(0xbb85), SHC(0x93dc), SHC(0xb3c0), SHC(0x9930), SHC(0xac65), SHC(0x9f14), - SHC(0x7fff), SHC(0x0000), SHC(0x7f62), SHC(0xf374), SHC(0x7d8a), SHC(0xe707), SHC(0x7a7d), SHC(0xdad8), - SHC(0x7642), SHC(0xcf04), SHC(0x70e3), SHC(0xc3a9), SHC(0x6a6e), SHC(0xb8e3), SHC(0x62f2), SHC(0xaecc), - SHC(0x5a82), SHC(0xa57e), SHC(0x5134), SHC(0x9d0e), SHC(0x471d), SHC(0x9592), SHC(0x3c57), SHC(0x8f1d), - SHC(0x30fc), SHC(0x89be), SHC(0x2528), SHC(0x8583), SHC(0x18f9), SHC(0x8276), SHC(0x0c8c), SHC(0x809e), - SHC(0x0000), SHC(0x8000), SHC(0xf374), SHC(0x809e), SHC(0xe707), SHC(0x8276), SHC(0xdad8), SHC(0x8583), - SHC(0xcf04), SHC(0x89be), SHC(0xc3a9), SHC(0x8f1d), SHC(0xb8e3), SHC(0x9592), SHC(0xaecc), SHC(0x9d0e), - SHC(0xa57e), SHC(0xa57e), SHC(0x9d0e), SHC(0xaecc), SHC(0x9592), SHC(0xb8e3), SHC(0x8f1d), SHC(0xc3a9), - SHC(0x89be), SHC(0xcf04), SHC(0x8583), SHC(0xdad8), SHC(0x8276), SHC(0xe707), SHC(0x809e), SHC(0xf374), - SHC(0x7fff), SHC(0x0000), SHC(0x7f0a), SHC(0xf055), SHC(0x7c2a), SHC(0xe0e6), SHC(0x776c), SHC(0xd1ef), - SHC(0x70e3), SHC(0xc3a9), SHC(0x68a7), SHC(0xb64c), SHC(0x5ed7), SHC(0xaa0a), SHC(0x539b), SHC(0x9f14), - SHC(0x471d), SHC(0x9592), SHC(0x398d), SHC(0x8dab), SHC(0x2b1f), SHC(0x877b), SHC(0x1c0c), SHC(0x831c), - SHC(0x0c8c), SHC(0x809e), SHC(0xfcdc), SHC(0x800a), SHC(0xed38), SHC(0x8163), SHC(0xdddc), SHC(0x84a3), - SHC(0xcf04), SHC(0x89be), SHC(0xc0e9), SHC(0x90a1), SHC(0xb3c0), SHC(0x9930), SHC(0xa7bd), SHC(0xa34c), - SHC(0x9d0e), SHC(0xaecc), SHC(0x93dc), SHC(0xbb85), SHC(0x8c4a), SHC(0xc946), SHC(0x8676), SHC(0xd7d9), - SHC(0x8276), SHC(0xe707), SHC(0x8059), SHC(0xf695), SHC(0x8027), SHC(0x0648), SHC(0x81e2), SHC(0x15e2), - SHC(0x8583), SHC(0x2528), SHC(0x8afb), SHC(0x33df), SHC(0x9236), SHC(0x41ce), SHC(0x9b17), SHC(0x4ec0), - SHC(0x7fff), SHC(0x0000), SHC(0x7e9d), SHC(0xed38), SHC(0x7a7d), SHC(0xdad8), SHC(0x73b6), SHC(0xc946), - SHC(0x6a6e), SHC(0xb8e3), SHC(0x5ed7), SHC(0xaa0a), SHC(0x5134), SHC(0x9d0e), SHC(0x41ce), SHC(0x9236), - SHC(0x30fc), SHC(0x89be), SHC(0x1f1a), SHC(0x83d6), SHC(0x0c8c), SHC(0x809e), SHC(0xf9b8), SHC(0x8027), - SHC(0xe707), SHC(0x8276), SHC(0xd4e1), SHC(0x877b), SHC(0xc3a9), SHC(0x8f1d), SHC(0xb3c0), SHC(0x9930), - SHC(0xa57e), SHC(0xa57e), SHC(0x9930), SHC(0xb3c0), SHC(0x8f1d), SHC(0xc3a9), SHC(0x877b), SHC(0xd4e1), - SHC(0x8276), SHC(0xe707), SHC(0x8027), SHC(0xf9b8), SHC(0x809e), SHC(0x0c8c), SHC(0x83d6), SHC(0x1f1a), - SHC(0x89be), SHC(0x30fc), SHC(0x9236), SHC(0x41ce), SHC(0x9d0e), SHC(0x5134), SHC(0xaa0a), SHC(0x5ed7), - SHC(0xb8e3), SHC(0x6a6e), SHC(0xc946), SHC(0x73b6), SHC(0xdad8), SHC(0x7a7d), SHC(0xed38), SHC(0x7e9d), - SHC(0x7fff), SHC(0x0000), SHC(0x7e1e), SHC(0xea1e), SHC(0x7885), SHC(0xd4e1), SHC(0x6f5f), SHC(0xc0e9), - SHC(0x62f2), SHC(0xaecc), SHC(0x539b), SHC(0x9f14), SHC(0x41ce), SHC(0x9236), SHC(0x2e11), SHC(0x8894), - SHC(0x18f9), SHC(0x8276), SHC(0x0324), SHC(0x800a), SHC(0xed38), SHC(0x8163), SHC(0xd7d9), SHC(0x8676), - SHC(0xc3a9), SHC(0x8f1d), SHC(0xb140), SHC(0x9b17), SHC(0xa129), SHC(0xaa0a), SHC(0x93dc), SHC(0xbb85), - SHC(0x89be), SHC(0xcf04), SHC(0x831c), SHC(0xe3f4), SHC(0x8027), SHC(0xf9b8), SHC(0x80f6), SHC(0x0fab), - SHC(0x8583), SHC(0x2528), SHC(0x8dab), SHC(0x398d), SHC(0x9930), SHC(0x4c40), SHC(0xa7bd), SHC(0x5cb4), - SHC(0xb8e3), SHC(0x6a6e), SHC(0xcc21), SHC(0x7505), SHC(0xe0e6), SHC(0x7c2a), SHC(0xf695), SHC(0x7fa7), - SHC(0x0c8c), SHC(0x7f62), SHC(0x2224), SHC(0x7b5d), SHC(0x36ba), SHC(0x73b6), SHC(0x49b4), SHC(0x68a7) -}; - -/** - * \brief Twiddle factors are unscaled - */ -const Word16 RotVector_320[2*(320-20)] = -{ - SHC(0x7fff), SHC(0x0000), SHC(0x7fe7), SHC(0xfafa), SHC(0x7f9b), SHC(0xf5f5), SHC(0x7f1d), SHC(0xf0f5), - SHC(0x7e6d), SHC(0xebfa), SHC(0x7d8a), SHC(0xe707), SHC(0x7c77), SHC(0xe21e), SHC(0x7b32), SHC(0xdd41), - SHC(0x79bc), SHC(0xd872), SHC(0x7817), SHC(0xd3b2), SHC(0x7642), SHC(0xcf04), SHC(0x743e), SHC(0xca69), - SHC(0x720d), SHC(0xc5e4), SHC(0x6fae), SHC(0xc175), SHC(0x6d23), SHC(0xbd1f), SHC(0x6a6e), SHC(0xb8e3), - SHC(0x678e), SHC(0xb4c3), SHC(0x6485), SHC(0xb0c2), SHC(0x6155), SHC(0xacdf), SHC(0x5dfe), SHC(0xa91d), - SHC(0x7fff), SHC(0x0000), SHC(0x7f9b), SHC(0xf5f5), SHC(0x7e6d), SHC(0xebfa), SHC(0x7c77), SHC(0xe21e), - SHC(0x79bc), SHC(0xd872), SHC(0x7642), SHC(0xcf04), SHC(0x720d), SHC(0xc5e4), SHC(0x6d23), SHC(0xbd1f), - SHC(0x678e), SHC(0xb4c3), SHC(0x6155), SHC(0xacdf), SHC(0x5a82), SHC(0xa57e), SHC(0x5321), SHC(0x9eab), - SHC(0x4b3d), SHC(0x9872), SHC(0x42e1), SHC(0x92dd), SHC(0x3a1c), SHC(0x8df3), SHC(0x30fc), SHC(0x89be), - SHC(0x278e), SHC(0x8644), SHC(0x1de2), SHC(0x8389), SHC(0x1406), SHC(0x8193), SHC(0x0a0b), SHC(0x8065), - SHC(0x7fff), SHC(0x0000), SHC(0x7f1d), SHC(0xf0f5), SHC(0x7c77), SHC(0xe21e), SHC(0x7817), SHC(0xd3b2), - SHC(0x720d), SHC(0xc5e4), SHC(0x6a6e), SHC(0xb8e3), SHC(0x6155), SHC(0xacdf), SHC(0x56e3), SHC(0xa202), - SHC(0x4b3d), SHC(0x9872), SHC(0x3e8b), SHC(0x9052), SHC(0x30fc), SHC(0x89be), SHC(0x22bf), SHC(0x84ce), - SHC(0x1406), SHC(0x8193), SHC(0x0506), SHC(0x8019), SHC(0xf5f5), SHC(0x8065), SHC(0xe707), SHC(0x8276), - SHC(0xd872), SHC(0x8644), SHC(0xca69), SHC(0x8bc2), SHC(0xbd1f), SHC(0x92dd), SHC(0xb0c2), SHC(0x9b7b), - SHC(0x7fff), SHC(0x0000), SHC(0x7e6d), SHC(0xebfa), SHC(0x79bc), SHC(0xd872), SHC(0x720d), SHC(0xc5e4), - SHC(0x678e), SHC(0xb4c3), SHC(0x5a82), SHC(0xa57e), SHC(0x4b3d), SHC(0x9872), SHC(0x3a1c), SHC(0x8df3), - SHC(0x278e), SHC(0x8644), SHC(0x1406), SHC(0x8193), SHC(0x0000), SHC(0x8000), SHC(0xebfa), SHC(0x8193), - SHC(0xd872), SHC(0x8644), SHC(0xc5e4), SHC(0x8df3), SHC(0xb4c3), SHC(0x9872), SHC(0xa57e), SHC(0xa57e), - SHC(0x9872), SHC(0xb4c3), SHC(0x8df3), SHC(0xc5e4), SHC(0x8644), SHC(0xd872), SHC(0x8193), SHC(0xebfa), - SHC(0x7fff), SHC(0x0000), SHC(0x7d8a), SHC(0xe707), SHC(0x7642), SHC(0xcf04), SHC(0x6a6e), SHC(0xb8e3), - SHC(0x5a82), SHC(0xa57e), SHC(0x471d), SHC(0x9592), SHC(0x30fc), SHC(0x89be), SHC(0x18f9), SHC(0x8276), - SHC(0x0000), SHC(0x8000), SHC(0xe707), SHC(0x8276), SHC(0xcf04), SHC(0x89be), SHC(0xb8e3), SHC(0x9592), - SHC(0xa57e), SHC(0xa57e), SHC(0x9592), SHC(0xb8e3), SHC(0x89be), SHC(0xcf04), SHC(0x8276), SHC(0xe707), - SHC(0x8000), SHC(0x0000), SHC(0x8276), SHC(0x18f9), SHC(0x89be), SHC(0x30fc), SHC(0x9592), SHC(0x471d), - SHC(0x7fff), SHC(0x0000), SHC(0x7c77), SHC(0xe21e), SHC(0x720d), SHC(0xc5e4), SHC(0x6155), SHC(0xacdf), - SHC(0x4b3d), SHC(0x9872), SHC(0x30fc), SHC(0x89be), SHC(0x1406), SHC(0x8193), SHC(0xf5f5), SHC(0x8065), - SHC(0xd872), SHC(0x8644), SHC(0xbd1f), SHC(0x92dd), SHC(0xa57e), SHC(0xa57e), SHC(0x92dd), SHC(0xbd1f), - SHC(0x8644), SHC(0xd872), SHC(0x8065), SHC(0xf5f5), SHC(0x8193), SHC(0x1406), SHC(0x89be), SHC(0x30fc), - SHC(0x9872), SHC(0x4b3d), SHC(0xacdf), SHC(0x6155), SHC(0xc5e4), SHC(0x720d), SHC(0xe21e), SHC(0x7c77), - SHC(0x7fff), SHC(0x0000), SHC(0x7b32), SHC(0xdd41), SHC(0x6d23), SHC(0xbd1f), SHC(0x56e3), SHC(0xa202), - SHC(0x3a1c), SHC(0x8df3), SHC(0x18f9), SHC(0x8276), SHC(0xf5f5), SHC(0x8065), SHC(0xd3b2), SHC(0x87e9), - SHC(0xb4c3), SHC(0x9872), SHC(0x9b7b), SHC(0xb0c2), SHC(0x89be), SHC(0xcf04), SHC(0x80e3), SHC(0xf0f5), - SHC(0x8193), SHC(0x1406), SHC(0x8bc2), SHC(0x3597), SHC(0x9eab), SHC(0x5321), SHC(0xb8e3), SHC(0x6a6e), - SHC(0xd872), SHC(0x79bc), SHC(0xfafa), SHC(0x7fe7), SHC(0x1de2), SHC(0x7c77), SHC(0x3e8b), SHC(0x6fae), - SHC(0x7fff), SHC(0x0000), SHC(0x7ffa), SHC(0xfd7d), SHC(0x7fe7), SHC(0xfafa), SHC(0x7fc7), SHC(0xf877), - SHC(0x7f9b), SHC(0xf5f5), SHC(0x7f62), SHC(0xf374), SHC(0x7f1d), SHC(0xf0f5), SHC(0x7ecb), SHC(0xee76), - SHC(0x7e6d), SHC(0xebfa), SHC(0x7e02), SHC(0xe980), SHC(0x7d8a), SHC(0xe707), SHC(0x7d07), SHC(0xe492), - SHC(0x7c77), SHC(0xe21e), SHC(0x7bda), SHC(0xdfae), SHC(0x7b32), SHC(0xdd41), SHC(0x7a7d), SHC(0xdad8), - SHC(0x79bc), SHC(0xd872), SHC(0x78ef), SHC(0xd610), SHC(0x7817), SHC(0xd3b2), SHC(0x7732), SHC(0xd159), - SHC(0x7fff), SHC(0x0000), SHC(0x7fc7), SHC(0xf877), SHC(0x7f1d), SHC(0xf0f5), SHC(0x7e02), SHC(0xe980), - SHC(0x7c77), SHC(0xe21e), SHC(0x7a7d), SHC(0xdad8), SHC(0x7817), SHC(0xd3b2), SHC(0x7546), SHC(0xccb4), - SHC(0x720d), SHC(0xc5e4), SHC(0x6e6e), SHC(0xbf47), SHC(0x6a6e), SHC(0xb8e3), SHC(0x660f), SHC(0xb2bf), - SHC(0x6155), SHC(0xacdf), SHC(0x5c45), SHC(0xa749), SHC(0x56e3), SHC(0xa202), SHC(0x5134), SHC(0x9d0e), - SHC(0x4b3d), SHC(0x9872), SHC(0x4502), SHC(0x9432), SHC(0x3e8b), SHC(0x9052), SHC(0x37dc), SHC(0x8cd5), - SHC(0x7fff), SHC(0x0000), SHC(0x7f62), SHC(0xf374), SHC(0x7d8a), SHC(0xe707), SHC(0x7a7d), SHC(0xdad8), - SHC(0x7642), SHC(0xcf04), SHC(0x70e3), SHC(0xc3a9), SHC(0x6a6e), SHC(0xb8e3), SHC(0x62f2), SHC(0xaecc), - SHC(0x5a82), SHC(0xa57e), SHC(0x5134), SHC(0x9d0e), SHC(0x471d), SHC(0x9592), SHC(0x3c57), SHC(0x8f1d), - SHC(0x30fc), SHC(0x89be), SHC(0x2528), SHC(0x8583), SHC(0x18f9), SHC(0x8276), SHC(0x0c8c), SHC(0x809e), - SHC(0x0000), SHC(0x8000), SHC(0xf374), SHC(0x809e), SHC(0xe707), SHC(0x8276), SHC(0xdad8), SHC(0x8583), - SHC(0x7fff), SHC(0x0000), SHC(0x7ecb), SHC(0xee76), SHC(0x7b32), SHC(0xdd41), SHC(0x7546), SHC(0xccb4), - SHC(0x6d23), SHC(0xbd1f), SHC(0x62f2), SHC(0xaecc), SHC(0x56e3), SHC(0xa202), SHC(0x4930), SHC(0x96fd), - SHC(0x3a1c), SHC(0x8df3), SHC(0x29f0), SHC(0x8711), SHC(0x18f9), SHC(0x8276), SHC(0x0789), SHC(0x8039), - SHC(0xf5f5), SHC(0x8065), SHC(0xe492), SHC(0x82f9), SHC(0xd3b2), SHC(0x87e9), SHC(0xc3a9), SHC(0x8f1d), - SHC(0xb4c3), SHC(0x9872), SHC(0xa749), SHC(0xa3bb), SHC(0x9b7b), SHC(0xb0c2), SHC(0x9192), SHC(0xbf47), - SHC(0x7fff), SHC(0x0000), SHC(0x7e02), SHC(0xe980), SHC(0x7817), SHC(0xd3b2), SHC(0x6e6e), SHC(0xbf47), - SHC(0x6155), SHC(0xacdf), SHC(0x5134), SHC(0x9d0e), SHC(0x3e8b), SHC(0x9052), SHC(0x29f0), SHC(0x8711), - SHC(0x1406), SHC(0x8193), SHC(0xfd7d), SHC(0x8006), SHC(0xe707), SHC(0x8276), SHC(0xd159), SHC(0x88ce), - SHC(0xbd1f), SHC(0x92dd), SHC(0xaafa), SHC(0xa052), SHC(0x9b7b), SHC(0xb0c2), SHC(0x8f1d), SHC(0xc3a9), - SHC(0x8644), SHC(0xd872), SHC(0x8135), SHC(0xee76), SHC(0x8019), SHC(0x0506), SHC(0x82f9), SHC(0x1b6e), - SHC(0x7fff), SHC(0x0000), SHC(0x7d07), SHC(0xe492), SHC(0x743e), SHC(0xca69), SHC(0x660f), SHC(0xb2bf), - SHC(0x5321), SHC(0x9eab), SHC(0x3c57), SHC(0x8f1d), SHC(0x22bf), SHC(0x84ce), SHC(0x0789), SHC(0x8039), - SHC(0xebfa), SHC(0x8193), SHC(0xd159), SHC(0x88ce), SHC(0xb8e3), SHC(0x9592), SHC(0xa3bb), SHC(0xa749), - SHC(0x92dd), SHC(0xbd1f), SHC(0x8711), SHC(0xd610), SHC(0x80e3), SHC(0xf0f5), SHC(0x809e), SHC(0x0c8c), - SHC(0x8644), SHC(0x278e), SHC(0x9192), SHC(0x40b9), SHC(0xa202), SHC(0x56e3), SHC(0xb6d0), SHC(0x6903), - SHC(0x7fff), SHC(0x0000), SHC(0x7bda), SHC(0xdfae), SHC(0x6fae), SHC(0xc175), SHC(0x5c45), SHC(0xa749), - SHC(0x42e1), SHC(0x92dd), SHC(0x2528), SHC(0x8583), SHC(0x0506), SHC(0x8019), SHC(0xe492), SHC(0x82f9), - SHC(0xc5e4), SHC(0x8df3), SHC(0xaafa), SHC(0xa052), SHC(0x9592), SHC(0xb8e3), SHC(0x8711), SHC(0xd610), - SHC(0x8065), SHC(0xf5f5), SHC(0x81fe), SHC(0x1680), SHC(0x8bc2), SHC(0x3597), SHC(0x9d0e), SHC(0x5134), - SHC(0xb4c3), SHC(0x678e), SHC(0xd159), SHC(0x7732), SHC(0xf0f5), SHC(0x7f1d), SHC(0x118a), SHC(0x7ecb), - SHC(0x7fff), SHC(0x0000), SHC(0x7a7d), SHC(0xdad8), SHC(0x6a6e), SHC(0xb8e3), SHC(0x5134), SHC(0x9d0e), - SHC(0x30fc), SHC(0x89be), SHC(0x0c8c), SHC(0x809e), SHC(0xe707), SHC(0x8276), SHC(0xc3a9), SHC(0x8f1d), - SHC(0xa57e), SHC(0xa57e), SHC(0x8f1d), SHC(0xc3a9), SHC(0x8276), SHC(0xe707), SHC(0x809e), SHC(0x0c8c), - SHC(0x89be), SHC(0x30fc), SHC(0x9d0e), SHC(0x5134), SHC(0xb8e3), SHC(0x6a6e), SHC(0xdad8), SHC(0x7a7d), - SHC(0x0000), SHC(0x7fff), SHC(0x2528), SHC(0x7a7d), SHC(0x471d), SHC(0x6a6e), SHC(0x62f2), SHC(0x5134) -}; - - -/** - * \brief Twiddle factors are unscaled - * Rotation factor table, real and imaginary part interleaved, for dim1=20,dim2=20 - */ - -const Word16 RotVector_400[2*(400-20)] = -{ - SHC(0x7fff), SHC(0x0000), SHC(0x7ff0), SHC(0xfbfb), SHC(0x7fbf), SHC(0xf7f6), SHC(0x7f6f), SHC(0xf3f4), - SHC(0x7efe), SHC(0xeff5), SHC(0x7e6d), SHC(0xebfa), SHC(0x7dbc), SHC(0xe804), SHC(0x7ceb), SHC(0xe414), - SHC(0x7bfb), SHC(0xe02b), SHC(0x7aeb), SHC(0xdc4a), SHC(0x79bc), SHC(0xd872), SHC(0x786f), SHC(0xd4a4), - SHC(0x7703), SHC(0xd0e1), SHC(0x7579), SHC(0xcd2a), SHC(0x73d1), SHC(0xc980), SHC(0x720d), SHC(0xc5e4), - SHC(0x702b), SHC(0xc256), SHC(0x6e2d), SHC(0xbed8), SHC(0x6c13), SHC(0xbb6a), SHC(0x69de), SHC(0xb80e), - SHC(0x7fff), SHC(0x0000), SHC(0x7fbf), SHC(0xf7f6), SHC(0x7efe), SHC(0xeff5), SHC(0x7dbc), SHC(0xe804), - SHC(0x7bfb), SHC(0xe02b), SHC(0x79bc), SHC(0xd872), SHC(0x7703), SHC(0xd0e1), SHC(0x73d1), SHC(0xc980), - SHC(0x702b), SHC(0xc256), SHC(0x6c13), SHC(0xbb6a), SHC(0x678e), SHC(0xb4c3), SHC(0x62a0), SHC(0xae69), - SHC(0x5d4f), SHC(0xa861), SHC(0x579f), SHC(0xa2b1), SHC(0x5197), SHC(0x9d60), SHC(0x4b3d), SHC(0x9872), - SHC(0x4496), SHC(0x93ed), SHC(0x3daa), SHC(0x8fd5), SHC(0x3680), SHC(0x8c2f), SHC(0x2f1f), SHC(0x88fd), - SHC(0x7fff), SHC(0x0000), SHC(0x7f6f), SHC(0xf3f4), SHC(0x7dbc), SHC(0xe804), SHC(0x7aeb), SHC(0xdc4a), - SHC(0x7703), SHC(0xd0e1), SHC(0x720d), SHC(0xc5e4), SHC(0x6c13), SHC(0xbb6a), SHC(0x6524), SHC(0xb18c), - SHC(0x5d4f), SHC(0xa861), SHC(0x54a6), SHC(0x9ffc), SHC(0x4b3d), SHC(0x9872), SHC(0x4128), SHC(0x91d3), - SHC(0x3680), SHC(0x8c2f), SHC(0x2b5c), SHC(0x8791), SHC(0x1fd5), SHC(0x8405), SHC(0x1406), SHC(0x8193), - SHC(0x080a), SHC(0x8041), SHC(0xfbfb), SHC(0x8010), SHC(0xeff5), SHC(0x8102), SHC(0xe414), SHC(0x8315), - SHC(0x7fff), SHC(0x0000), SHC(0x7efe), SHC(0xeff5), SHC(0x7bfb), SHC(0xe02b), SHC(0x7703), SHC(0xd0e1), - SHC(0x702b), SHC(0xc256), SHC(0x678e), SHC(0xb4c3), SHC(0x5d4f), SHC(0xa861), SHC(0x5197), SHC(0x9d60), - SHC(0x4496), SHC(0x93ed), SHC(0x3680), SHC(0x8c2f), SHC(0x278e), SHC(0x8644), SHC(0x17fc), SHC(0x8244), - SHC(0x080a), SHC(0x8041), SHC(0xf7f6), SHC(0x8041), SHC(0xe804), SHC(0x8244), SHC(0xd872), SHC(0x8644), - SHC(0xc980), SHC(0x8c2f), SHC(0xbb6a), SHC(0x93ed), SHC(0xae69), SHC(0x9d60), SHC(0xa2b1), SHC(0xa861), - SHC(0x7fff), SHC(0x0000), SHC(0x7e6d), SHC(0xebfa), SHC(0x79bc), SHC(0xd872), SHC(0x720d), SHC(0xc5e4), - SHC(0x678e), SHC(0xb4c3), SHC(0x5a82), SHC(0xa57e), SHC(0x4b3d), SHC(0x9872), SHC(0x3a1c), SHC(0x8df3), - SHC(0x278e), SHC(0x8644), SHC(0x1406), SHC(0x8193), SHC(0x0000), SHC(0x8000), SHC(0xebfa), SHC(0x8193), - SHC(0xd872), SHC(0x8644), SHC(0xc5e4), SHC(0x8df3), SHC(0xb4c3), SHC(0x9872), SHC(0xa57e), SHC(0xa57e), - SHC(0x9872), SHC(0xb4c3), SHC(0x8df3), SHC(0xc5e4), SHC(0x8644), SHC(0xd872), SHC(0x8193), SHC(0xebfa), - SHC(0x7fff), SHC(0x0000), SHC(0x7dbc), SHC(0xe804), SHC(0x7703), SHC(0xd0e1), SHC(0x6c13), SHC(0xbb6a), - SHC(0x5d4f), SHC(0xa861), SHC(0x4b3d), SHC(0x9872), SHC(0x3680), SHC(0x8c2f), SHC(0x1fd5), SHC(0x8405), - SHC(0x080a), SHC(0x8041), SHC(0xeff5), SHC(0x8102), SHC(0xd872), SHC(0x8644), SHC(0xc256), SHC(0x8fd5), - SHC(0xae69), SHC(0x9d60), SHC(0x9d60), SHC(0xae69), SHC(0x8fd5), SHC(0xc256), SHC(0x8644), SHC(0xd872), - SHC(0x8102), SHC(0xeff5), SHC(0x8041), SHC(0x080a), SHC(0x8405), SHC(0x1fd5), SHC(0x8c2f), SHC(0x3680), - SHC(0x7fff), SHC(0x0000), SHC(0x7ceb), SHC(0xe414), SHC(0x73d1), SHC(0xc980), SHC(0x6524), SHC(0xb18c), - SHC(0x5197), SHC(0x9d60), SHC(0x3a1c), SHC(0x8df3), SHC(0x1fd5), SHC(0x8405), SHC(0x0405), SHC(0x8010), - SHC(0xe804), SHC(0x8244), SHC(0xcd2a), SHC(0x8a87), SHC(0xb4c3), SHC(0x9872), SHC(0x9ffc), SHC(0xab5a), - SHC(0x8fd5), SHC(0xc256), SHC(0x8515), SHC(0xdc4a), SHC(0x8041), SHC(0xf7f6), SHC(0x8193), SHC(0x1406), - SHC(0x88fd), SHC(0x2f1f), SHC(0x9622), SHC(0x47f2), SHC(0xa861), SHC(0x5d4f), SHC(0xbed8), SHC(0x6e2d), - SHC(0x7fff), SHC(0x0000), SHC(0x7bfb), SHC(0xe02b), SHC(0x702b), SHC(0xc256), SHC(0x5d4f), SHC(0xa861), - SHC(0x4496), SHC(0x93ed), SHC(0x278e), SHC(0x8644), SHC(0x080a), SHC(0x8041), SHC(0xe804), SHC(0x8244), - SHC(0xc980), SHC(0x8c2f), SHC(0xae69), SHC(0x9d60), SHC(0x9872), SHC(0xb4c3), SHC(0x88fd), SHC(0xd0e1), - SHC(0x8102), SHC(0xeff5), SHC(0x8102), SHC(0x100b), SHC(0x88fd), SHC(0x2f1f), SHC(0x9872), SHC(0x4b3d), - SHC(0xae69), SHC(0x62a0), SHC(0xc980), SHC(0x73d1), SHC(0xe804), SHC(0x7dbc), SHC(0x080a), SHC(0x7fbf), - SHC(0x7fff), SHC(0x0000), SHC(0x7aeb), SHC(0xdc4a), SHC(0x6c13), SHC(0xbb6a), SHC(0x54a6), SHC(0x9ffc), - SHC(0x3680), SHC(0x8c2f), SHC(0x1406), SHC(0x8193), SHC(0xeff5), SHC(0x8102), SHC(0xcd2a), SHC(0x8a87), - SHC(0xae69), SHC(0x9d60), SHC(0x9622), SHC(0xb80e), SHC(0x8644), SHC(0xd872), SHC(0x8010), SHC(0xfbfb), - SHC(0x8405), SHC(0x1fd5), SHC(0x91d3), SHC(0x4128), SHC(0xa861), SHC(0x5d4f), SHC(0xc5e4), SHC(0x720d), - SHC(0xe804), SHC(0x7dbc), SHC(0x0c0c), SHC(0x7f6f), SHC(0x2f1f), SHC(0x7703), SHC(0x4e74), SHC(0x6524), - SHC(0x7fff), SHC(0x0000), SHC(0x7ffc), SHC(0xfdfd), SHC(0x7ff0), SHC(0xfbfb), SHC(0x7fdc), SHC(0xf9f8), - SHC(0x7fbf), SHC(0xf7f6), SHC(0x7f9b), SHC(0xf5f5), SHC(0x7f6f), SHC(0xf3f4), SHC(0x7f3a), SHC(0xf1f4), - SHC(0x7efe), SHC(0xeff5), SHC(0x7eb9), SHC(0xedf7), SHC(0x7e6d), SHC(0xebfa), SHC(0x7e18), SHC(0xe9fe), - SHC(0x7dbc), SHC(0xe804), SHC(0x7d57), SHC(0xe60b), SHC(0x7ceb), SHC(0xe414), SHC(0x7c77), SHC(0xe21e), - SHC(0x7bfb), SHC(0xe02b), SHC(0x7b77), SHC(0xde39), SHC(0x7aeb), SHC(0xdc4a), SHC(0x7a57), SHC(0xda5d), - SHC(0x7fff), SHC(0x0000), SHC(0x7fdc), SHC(0xf9f8), SHC(0x7f6f), SHC(0xf3f4), SHC(0x7eb9), SHC(0xedf7), - SHC(0x7dbc), SHC(0xe804), SHC(0x7c77), SHC(0xe21e), SHC(0x7aeb), SHC(0xdc4a), SHC(0x7919), SHC(0xd68a), - SHC(0x7703), SHC(0xd0e1), SHC(0x74a9), SHC(0xcb53), SHC(0x720d), SHC(0xc5e4), SHC(0x6f2f), SHC(0xc095), - SHC(0x6c13), SHC(0xbb6a), SHC(0x68b9), SHC(0xb666), SHC(0x6524), SHC(0xb18c), SHC(0x6155), SHC(0xacdf), - SHC(0x5d4f), SHC(0xa861), SHC(0x5914), SHC(0xa414), SHC(0x54a6), SHC(0x9ffc), SHC(0x5008), SHC(0x9c1b), - SHC(0x7fff), SHC(0x0000), SHC(0x7f9b), SHC(0xf5f5), SHC(0x7e6d), SHC(0xebfa), SHC(0x7c77), SHC(0xe21e), - SHC(0x79bc), SHC(0xd872), SHC(0x7642), SHC(0xcf04), SHC(0x720d), SHC(0xc5e4), SHC(0x6d23), SHC(0xbd1f), - SHC(0x678e), SHC(0xb4c3), SHC(0x6155), SHC(0xacdf), SHC(0x5a82), SHC(0xa57e), SHC(0x5321), SHC(0x9eab), - SHC(0x4b3d), SHC(0x9872), SHC(0x42e1), SHC(0x92dd), SHC(0x3a1c), SHC(0x8df3), SHC(0x30fc), SHC(0x89be), - SHC(0x278e), SHC(0x8644), SHC(0x1de2), SHC(0x8389), SHC(0x1406), SHC(0x8193), SHC(0x0a0b), SHC(0x8065), - SHC(0x7fff), SHC(0x0000), SHC(0x7f3a), SHC(0xf1f4), SHC(0x7ceb), SHC(0xe414), SHC(0x7919), SHC(0xd68a), - SHC(0x73d1), SHC(0xc980), SHC(0x6d23), SHC(0xbd1f), SHC(0x6524), SHC(0xb18c), SHC(0x5bec), SHC(0xa6ec), - SHC(0x5197), SHC(0x9d60), SHC(0x4646), SHC(0x9504), SHC(0x3a1c), SHC(0x8df3), SHC(0x2d3f), SHC(0x8843), - SHC(0x1fd5), SHC(0x8405), SHC(0x1209), SHC(0x8147), SHC(0x0405), SHC(0x8010), SHC(0xf5f5), SHC(0x8065), - SHC(0xe804), SHC(0x8244), SHC(0xda5d), SHC(0x85a9), SHC(0xcd2a), SHC(0x8a87), SHC(0xc095), SHC(0x90d1), - SHC(0x7fff), SHC(0x0000), SHC(0x7eb9), SHC(0xedf7), SHC(0x7aeb), SHC(0xdc4a), SHC(0x74a9), SHC(0xcb53), - SHC(0x6c13), SHC(0xbb6a), SHC(0x6155), SHC(0xacdf), SHC(0x54a6), SHC(0x9ffc), SHC(0x4646), SHC(0x9504), - SHC(0x3680), SHC(0x8c2f), SHC(0x25a3), SHC(0x85a9), SHC(0x1406), SHC(0x8193), SHC(0x0203), SHC(0x8004), - SHC(0xeff5), SHC(0x8102), SHC(0xde39), SHC(0x8489), SHC(0xcd2a), SHC(0x8a87), SHC(0xbd1f), SHC(0x92dd), - SHC(0xae69), SHC(0x9d60), SHC(0xa154), SHC(0xa9db), SHC(0x9622), SHC(0xb80e), SHC(0x8d0d), SHC(0xc7b0), - SHC(0x7fff), SHC(0x0000), SHC(0x7e18), SHC(0xe9fe), SHC(0x786f), SHC(0xd4a4), SHC(0x6f2f), SHC(0xc095), - SHC(0x62a0), SHC(0xae69), SHC(0x5321), SHC(0x9eab), SHC(0x4128), SHC(0x91d3), SHC(0x2d3f), SHC(0x8843), - SHC(0x17fc), SHC(0x8244), SHC(0x0203), SHC(0x8004), SHC(0xebfa), SHC(0x8193), SHC(0xd68a), SHC(0x86e7), - SHC(0xc256), SHC(0x8fd5), SHC(0xaff8), SHC(0x9c1b), SHC(0x9ffc), SHC(0xab5a), SHC(0x92dd), SHC(0xbd1f), - SHC(0x88fd), SHC(0xd0e1), SHC(0x82a9), SHC(0xe60b), SHC(0x8010), SHC(0xfbfb), SHC(0x8147), SHC(0x1209), - SHC(0x7fff), SHC(0x0000), SHC(0x7d57), SHC(0xe60b), SHC(0x7579), SHC(0xcd2a), SHC(0x68b9), SHC(0xb666), - SHC(0x579f), SHC(0xa2b1), SHC(0x42e1), SHC(0x92dd), SHC(0x2b5c), SHC(0x8791), SHC(0x1209), SHC(0x8147), - SHC(0xf7f6), SHC(0x8041), SHC(0xde39), SHC(0x8489), SHC(0xc5e4), SHC(0x8df3), SHC(0xaff8), SHC(0x9c1b), - SHC(0x9d60), SHC(0xae69), SHC(0x8ee1), SHC(0xc41b), SHC(0x8515), SHC(0xdc4a), SHC(0x8065), SHC(0xf5f5), - SHC(0x8102), SHC(0x100b), SHC(0x86e7), SHC(0x2976), SHC(0x91d3), SHC(0x4128), SHC(0xa154), SHC(0x5625), - SHC(0x7fff), SHC(0x0000), SHC(0x7c77), SHC(0xe21e), SHC(0x720d), SHC(0xc5e4), SHC(0x6155), SHC(0xacdf), - SHC(0x4b3d), SHC(0x9872), SHC(0x30fc), SHC(0x89be), SHC(0x1406), SHC(0x8193), SHC(0xf5f5), SHC(0x8065), - SHC(0xd872), SHC(0x8644), SHC(0xbd1f), SHC(0x92dd), SHC(0xa57e), SHC(0xa57e), SHC(0x92dd), SHC(0xbd1f), - SHC(0x8644), SHC(0xd872), SHC(0x8065), SHC(0xf5f5), SHC(0x8193), SHC(0x1406), SHC(0x89be), SHC(0x30fc), - SHC(0x9872), SHC(0x4b3d), SHC(0xacdf), SHC(0x6155), SHC(0xc5e4), SHC(0x720d), SHC(0xe21e), SHC(0x7c77), - SHC(0x7fff), SHC(0x0000), SHC(0x7b77), SHC(0xde39), SHC(0x6e2d), SHC(0xbed8), SHC(0x5914), SHC(0xa414), - SHC(0x3daa), SHC(0x8fd5), SHC(0x1de2), SHC(0x8389), SHC(0xfbfb), SHC(0x8010), SHC(0xda5d), SHC(0x85a9), - SHC(0xbb6a), SHC(0x93ed), SHC(0xa154), SHC(0xa9db), SHC(0x8df3), SHC(0xc5e4), SHC(0x82a9), SHC(0xe60b), - SHC(0x8041), SHC(0x080a), SHC(0x86e7), SHC(0x2976), SHC(0x9622), SHC(0x47f2), SHC(0xacdf), SHC(0x6155), - SHC(0xc980), SHC(0x73d1), SHC(0xe9fe), SHC(0x7e18), SHC(0x0c0c), SHC(0x7f6f), SHC(0x2d3f), SHC(0x77bd), - SHC(0x7fff), SHC(0x0000), SHC(0x7a57), SHC(0xda5d), SHC(0x69de), SHC(0xb80e), SHC(0x5008), SHC(0x9c1b), - SHC(0x2f1f), SHC(0x88fd), SHC(0x0a0b), SHC(0x8065), SHC(0xe414), SHC(0x8315), SHC(0xc095), SHC(0x90d1), - SHC(0xa2b1), SHC(0xa861), SHC(0x8d0d), SHC(0xc7b0), SHC(0x8193), SHC(0xebfa), SHC(0x8147), SHC(0x1209), - SHC(0x8c2f), SHC(0x3680), SHC(0xa154), SHC(0x5625), SHC(0xbed8), SHC(0x6e2d), SHC(0xe21e), SHC(0x7c77), - SHC(0x080a), SHC(0x7fbf), SHC(0x2d3f), SHC(0x77bd), SHC(0x4e74), SHC(0x6524), SHC(0x68b9), SHC(0x499a) -}; - -/* These words are subtracted from high/low/value with a shift left by 1. */ -/* The value 0x0CCC should never be referenced, low is less/equal high */ -/* The value 0x0BBB should never be referenced, loop must break instead. */ -/* Refer to this table with indices: tab_ari_qnew[msb_high][msb_low] */ -const -Word16 tab_ari_qnew[4][4] = { { 0x0000, 0x0CCC, 0x0CCC, 0x0CCC }, - { 0x0000, 0x0000, 0x0CCC, 0x0CCC }, - { 0x0BBB, 0x2000, 0x4000, 0x0CCC }, - { 0x0BBB, 0x0BBB, 0x4000, 0x4000 } -}; - -/* order 8 LPF for nelp frames when non-native sampling freq inputs used with -max_band NB */ -/* used to suppress frequencies above 4kHz present at the output of filters in pre_proc() */ - -const Word16 num_nelp_lp_fx[NELP_LP_ORDER+1] = /*Q13*/ -{ - 727, - 3506, - 8988, - 15029, - 17732, - 15022, - 8979, - 3501, - 726 -}; - -const Word16 den_nelp_lp_fx[NELP_LP_ORDER+1] = -{ - 8192, - 8819, - 21618, - 12167, - 15902, - 3553, - 3998, - -120, - 353 -}; - -/* ACELP pulse coding */ -const Word16 hi_to_low_tmpl[10] = { 0, 0, 0, 3, 9, 5, 3, 1, 8, 8}; -const Word16 low_len[10] = { 0, 0, 8, 5, 7, 11, 13, 15, 16, 16}; -const Word32 low_mask[10] = { 0, 0, 255, 31,127, 2047, 8191, 32767, 65535, 65535}; -const Word16 indx_fact[10] = { 0, 0, 2, 172, 345, 140, 190, 223, 463, 1732}; -const Word16 index_len[3] = {0, 5, 9}; -const UWord32 index_mask_ACELP[3] = {0, 31, 511}; - -/* HQ pre-echo reduction */ -const Word16 inv_jp2[64] = -{ - 16384, 10923, 8192, 6554, 5461, 4681, 4096, 3641, 3277, 2979, 2731, 2521, 2341, 2185, 2048, 1928, - 1820, 1725, 1638, 1560, 1489, 1425, 1365, 1311, 1260, 1214, 1170, 1130, 1092, 1057, 1024, 993, - 964, 936, 910, 886, 862, 840, 819, 799, 780, 762, 745, 728, 712, 697, 683, 669, - 655, 643, 630, 618, 607, 596, 585, 575, 565, 555, 546, 537, 529, 520, 512, 504 -}; - diff --git a/src/libs/libevs/lib_com/rom_com_fx.h b/src/libs/libevs/lib_com/rom_com_fx.h deleted file mode 100755 index b4ab2484..00000000 --- a/src/libs/libevs/lib_com/rom_com_fx.h +++ /dev/null @@ -1,1250 +0,0 @@ -/*==================================================================================== - EVS Codec 3GPP TS26.442 Apr 03, 2018. Version 12.11.0 / 13.6.0 / 14.2.0 - ====================================================================================*/ - -#ifndef ROM_COM_FX_H -#define ROM_COM_FX_H - -#include -#include "stat_com.h" -#include "stat_enc_fx.h" /* Encoder static structure */ -#include "stat_dec_fx.h" /* Decoder static structure */ - - -typedef struct -{ - Word32 fin_fx; /* input frequency Q0 */ - Word32 fout_fx; /* output frequency Q0 */ - Word16 fac_num_fx; /* numerator of resampling factor Q0 */ - Word16 fac_den_fx; /* denominator of resampling factor Q0 */ - Word16 lg_out; /* denominator of resampling factor Q15 */ - const Word16 *filter_fx; /* resampling filter coefficients Q14 */ - Word16 filt_len_fx; /* number of filter coeff. Q0 */ - UNS_Word16 flags_fx; /* flags from config. table Q0 */ -} Resampling_cfg_fx; - -/*-----------------------------------------------------------------* - * Tables with bit-allocations - *-----------------------------------------------------------------*/ - -extern const Word16 LSF_bits_tbl[]; /* Bit allocation table for end-frame ISF quantizer */ -extern const Word16 mid_LSF_bits_tbl[]; /* Bit allocation table for mid-frame ISF quantizer */ -extern const Word16 Es_pred_bits_tbl[]; /* Bit allocation table for scaled innovation energy prediction */ -extern const Word16 gain_bits_tbl[]; /* Bit allocation table for gain quantizer */ -extern const Word16 ACB_bits_tbl[]; /* Bit allocation table for adaptive codebook (pitch) */ -extern const Word16 FCB_bits_tbl[]; /* Bit allocation table for algebraic (fixed) codebook (innovation) */ -extern const Word16 reserved_bits_tbl[]; /* Bit allocation table for reserved bits */ - -extern const Word16 ACB_bits_16kHz_tbl[]; /* Bit allocation table for adaptive codebook (pitch) @16kHz */ -extern const Word16 FCB_bits_16kHz_tbl[]; /* Bit allocation table for algebraic (fixed) codebook (innovation) @16kHz */ -extern const Word16 gain_bits_16kHz_tbl[]; /* Bit allocation table for gain quantizer @16kHz */ -extern const Word16 AVQ_bits_16kHz_tbl[]; /* Bit allocation table for AVQ bits @16kHz ACELP, active segments */ -extern const Word32 pow2[]; /* Table with power of 2 values */ - -extern const Word16 crit_bins[]; /* (used only in AMR-WB IO mode) */ -extern const Word16 mfreq_bindiv_loc[]; -extern const Word16 mfreq_bindiv_LD[]; -extern const Word16 mfreq_loc_LD[]; /* LD music post-filter */ -extern const Word16 crit_bins_corr_fx[]; -/*-----------------------------------------------------------------* - * Table of bitrates - *-----------------------------------------------------------------*/ - -extern const Word32 brate_tbl[SIZE_BRATE_TBL]; -extern const Word32 acelp_sig_tbl[MAX_ACELP_SIG]; - - -extern const Word16 Nb[NB_SFM]; -extern const Word16 LNb[ NB_SFM]; - -/*-----------------------------------------------------------------* - * BC-TCQ frame-end quantization tables - *-----------------------------------------------------------------*/ - -extern const Word16 wind_sss_fx[LEN_WIN_SSS]; /*window for modify_sf ana*/ -extern const Word16 filter5_39s320_120_fx[]; /* LP FIR filter for 8kHz signal resampling */ -extern const Word16 stable_LSF_fx_16k[]; -extern const Word16 UVWB_Ave_fx[]; -extern const Word16 UVNB_Ave_fx[]; -extern const Word16 SVWB_Ave_fx[]; -extern const Word16 SVNB_Ave_fx[]; -extern const Word16 IANB_Ave_fx[]; -extern const Word16 IAWB_Ave_fx[]; -extern const Word16 IAWB2_Ave_fx[]; -extern const Word16 GENB_Ave_fx[]; -extern const Word16 GEWB_Ave_fx[]; -extern const Word16 GEWB2_Ave_fx[]; -extern const Word16 TRWB_Ave_fx[]; -extern const Word16 TRWB2_Ave_fx[]; -extern const Word16 means_wb_cleanspeech_lsf16k0[]; -extern const Word16 means_swb_cleanspeech_lsf25k6[]; -extern const Word16 means_swb_cleanspeech_lsf32k0[]; - -extern const Word16 stable_ISP_fx[]; -extern const Word16 stable_ISF_fx[]; -extern const Word16 stable_LSP_fx[]; -extern const Word16 lsp_shb_prev_tbl_fx[]; -extern const Word16 sin_table256_fx[]; -extern const Word16 b_hp400_fx[]; /* Q12 (/4) */ -extern const Word16 a_hp400_fx[]; -extern const Word16 fir_6k_7k_fx[]; -extern const Word16 no_lead_fx[][MAX_NO_SCALES*2]; -extern const Word16 no_lead_p_fx[][MAX_NO_SCALES*2]; -extern const Word16 change_pl_order_fx[]; -extern const Word16 cng_sort_fx[]; -extern const Word8 Ind_Guess[256]; -extern const Word16 acos_slope[128]; -extern const Word16 cos_table_129[129]; -extern const Word16 Es_pred_qua_5b_fx[32]; -extern const Word16 Es_pred_qua_4b_fx[16]; -extern const Word16 Es_pred_qua_3b_fx[8]; -extern const Word16 Es_pred_qua_4b_no_ltp_fx[16]; -extern const Word16 tbl_gain_code_tc_quant_mean[N_GAIN_CODE_TC-1]; -extern const Word16 tbl_gain_code_tc_fx[N_GAIN_CODE_TC]; -extern const Word16 gain_qua_mless_7b_fx[]; -extern const Word16 gain_qua_mless_6b_fx[]; -extern const Word16 gain_qua_mless_5b_fx[]; -extern const Word16 gp_gamma_1sfr_8b_fx[]; -extern const Word16 gp_gamma_1sfr_7b_fx[]; -extern const Word16 gp_gamma_1sfr_6b_fx[]; -extern const Word16 gp_gamma_2sfr_7b_fx[]; -extern const Word16 gp_gamma_2sfr_6b_fx[]; -extern const Word16 gp_gamma_3sfr_6b_fx[]; -extern const Word16 gp_gamma_4sfr_6b_fx[]; - -extern const Word16 pred_gain_fx[GAIN_PRED_ORDER]; -extern const Word16 t_qua_gain6b_fx[64*2]; -extern const Word16 t_qua_gain7b_fx[128*2]; - -extern const Word16 b_1sfr_fx[]; -extern const Word16 b_2sfr_fx[]; -extern const Word16 b_3sfr_fx[]; -extern const Word16 b_4sfr_fx[]; - -extern const Word16 inter4_2_fx[]; - -extern const Word16 Gamma_19661_Tbl_fx[]; -extern const Word16 Gamma_29491_Tbl[]; -extern const Word16 pwf_fx[17]; - - -extern const Word16 * const ModeMeans_fx[]; -extern const Word16 * const Predictors_fx[]; - -extern const Word16 tbl_mid_voi_wb_1b_fx[]; -extern const Word16 tbl_mid_voi_wb_4b_fx[]; -extern const Word16 tbl_mid_voi_wb_5b_fx[]; - -extern const Word16 tbl_mid_unv_wb_4b_fx[]; -extern const Word16 tbl_mid_unv_wb_5b_fx[]; - -extern const Word16 tbl_mid_gen_wb_2b_fx[]; -extern const Word16 tbl_mid_gen_wb_5b_fx[]; - -extern const Word16 CBsizes_fx[]; -extern const Word16 CBbits_fx[]; -extern const Word16 CBbits_p_fx[]; -extern const Word16 BitsVQ_fx[]; -extern const Word16 BitsVQ_p_fx[]; - - -extern const Word16 Predictor0_fx[]; -extern const Word16 Predictor1_fx[]; -extern const Word16 Predictor2_fx[]; -extern const Word16 Predictor3_fx[]; -extern const Word16 Predictor4_fx[]; -extern const Word16 Predictor5_fx[]; -extern const Word16 Predictor6_fx[]; -extern const Word16 Predictor7_fx[]; -extern const Word16 Predictor8_fx[]; - -extern const Word16 interpol_frac_mid_16k_fx[NB_SUBFR16k*3]; -extern const Word16 interpol_frac_mid_fx[NB_SUBFR*3]; - -extern const Word16 * const Quantizers_p_fx[]; -extern const Word16 * const Quantizers_fx[]; -extern const Word16 CNG_SN1_fx[]; - -extern const Word16 CB_lsf_fx[]; -extern const Word16 CB_p_lsf_fx[]; - -extern const Word16 sigma_p_fx[][16]; -extern const Word16 sigma_MSLVQ_fx[][16]; - -extern const Word16 pi0_fx[]; -extern const Word32 table_no_cv_fx[]; -extern const Word16 pl_par_fx[]; /* 1 if even number of signs */ -extern const Word16 C_VQ_fx[LATTICE_DIM+1][LATTICE_DIM+1]; -extern const Word16 no_vals_ind_fx[NO_LEADERS][MAX_NO_VALS]; -extern const Word16 no_vals_fx[NO_LEADERS]; - -extern const Word16 vals_fx[NO_LEADERS][MAX_NO_VALS]; -extern const Word16 scales_fx[][MAX_NO_SCALES*2]; -extern const Word16 scales_p_fx[][MAX_NO_SCALES*2]; -extern const Word16 predmode_tab[][6]; -extern const Word16 min_lat_bits_SN_fx[]; -extern const Word16 min_lat_bits_pred_fx[]; -extern const Word16 offset_in_lvq_mode_SN_fx[][21]; - -extern const Word16 offset_in_lvq_mode_pred_fx[][32]; - -extern const Word16 offset_lvq_modes_SN_fx[]; -extern const Word16 offset_lvq_modes_pred_fx[]; -extern const Word16 inv_sigma_p_fx[][16]; -extern const Word16 inv_sigma_MSLVQ_fx[][16]; -extern const Word16 perm_MSLVQ_fx[][4]; -extern const Word16 pl_HQ_fx[]; - -/*----------------------------------------------------------------------------------* - * ISF quantization (AMR-WB IO mode) - *----------------------------------------------------------------------------------*/ -extern const Word16 Indirect_dico1[SIZE_BK1]; - -extern const Word16 mean_isf_amr_wb_fx[M]; /* Mean ISF vector (only in AMR-WB IO mode) */ -extern const Word16 mean_isf_noise_amr_wb_fx[]; /* Mean ISF vector for SID frame (only in AMR-WB IO mode) */ - -extern const Word16 dico1_isf_fx[]; /* ISF codebook - common 1st stage, 1st split (only in AMR-WB IO mode) */ -extern const Word16 dico2_isf_fx[]; /* ISF codebook - common 1st stage, 2nd split (only in AMR-WB IO mode) */ - -extern const Word16 dico21_isf_46b_fx[]; /* ISF codebook - 46b, 2nd stage, 1st split (only in AMR-WB IO mode) */ -extern const Word16 dico22_isf_46b_fx[]; /* ISF codebook - 46b, 2nd stage, 2st split (only in AMR-WB IO mode) */ -extern const Word16 dico23_isf_46b_fx[]; /* ISF codebook - 46b, 2nd stage, 3rd split (only in AMR-WB IO mode) */ -extern const Word16 dico24_isf_46b_fx[]; /* ISF codebook - 46b, 2nd stage, 4th split (only in AMR-WB IO mode) */ -extern const Word16 dico25_isf_46b_fx[]; /* ISF codebook - 46b, 2nd stage, 5th split (only in AMR-WB IO mode) */ - -extern const Word16 dico21_isf_36b_fx[]; /* ISF codebook - 36b, 2nd stage, 1st split (only in AMR-WB IO mode) */ -extern const Word16 dico22_isf_36b_fx[]; /* ISF codebook - 36b, 2nd stage, 2nd split (only in AMR-WB IO mode) */ -extern const Word16 dico23_isf_36b_fx[]; /* ISF codebook - 36b, 2nd stage, 3rd split (only in AMR-WB IO mode) */ - -extern const Word16 dico1_ns_28b_fx[]; /* ISF codebook for SID frames - 28b, 1st split */ -extern const Word16 dico2_ns_28b_fx[]; /* ISF codebook for SID frames - 28b, 2nd spilt */ -extern const Word16 dico3_ns_28b_fx[]; /* ISF codebook for SID frames - 28b, 3rd spilt */ -extern const Word16 dico4_ns_28b_fx[]; /* ISF codebook for SID frames - 28b, 4th spilt */ -extern const Word16 dico5_ns_28b_fx[]; /* ISF codebook for SID frames - 28b, 5th spilt */ - -/*-----------------------------------------------------------------* - * BC-TCVQ frame-end quantization tables (BC-TCVQ is used in Voiced mode for 16kHz isf) - *-----------------------------------------------------------------*/ -extern const Word16 NTRANS[4][NUM_STATE]; -extern const Word16 NTRANS2[4][NUM_STATE]; - -extern const Word16 BC_TCVQ_BIT_ALLOC_40B[]; -extern const Word16 FixBranch_tbl[4][4][N_STAGE_VQ - 4]; - -extern const Word16 AR_IntraCoeff_fx[N_STAGE_VQ-1][2][2]; -extern const Word16 SN_IntraCoeff_fx[N_STAGE_VQ-1][2][2]; - -extern const Word16 scale_ARSN_fx[]; -extern const Word16 scale_inv_ARSN_fx[]; - -extern const Word16 AR_TCVQ_CB_SUB1_fx[2][128][2]; -extern const Word16 AR_TCVQ_CB_SUB2_fx[2][64][2]; -extern const Word16 AR_TCVQ_CB_SUB3_fx[4][32][2]; - -extern const Word16 SN_TCVQ_CB_SUB1_fx[2][128][2]; -extern const Word16 SN_TCVQ_CB_SUB2_fx[2][64][2]; -extern const Word16 SN_TCVQ_CB_SUB3_fx[4][32][2]; - -extern const Word16 AR_SVQ_CB1_fx[32][8]; -extern const Word16 AR_SVQ_CB2_fx[16][8]; - - -extern const Word16 interpol_frac_mid_relaxprev_12k8_fx[NB_SUBFR*3]; -extern const Word16 interpol_frac_mid_FEC_fx[NB_SUBFR*3]; -extern const Word16 interpol_frac_mid_relaxprev_pred_12k8_fx[NB_SUBFR*3]; -extern const Word16 interpol_frac_mid_relaxprev_16k_fx[NB_SUBFR16k*3]; -extern const Word16 interpol_frac_mid_16k_FEC_fx[NB_SUBFR16k*3]; -extern const Word16 interpol_frac_mid_relaxprev_pred_16k_fx[NB_SUBFR16k*3]; -extern const Resampling_cfg_fx resampling_cfg_tbl_fx[]; - -extern const Word16 filter_LP15_180H_fx[]; /* Sincfilt.m: N=180*2+1, Fmin=0, Fmax=1/15, hann( N )' */ -extern const Word16 filter_LP3_90H_fx[]; /* Sincfilt.m: N=90*2+1, Fmin=0, Fmax=1/3, hann( N )' */ -extern const Word16 filter_LP12_180H_13b_fx[]; /* Sincfilt.m: N=180*2+1, Fmin=0, Fmax=1/12, hann( N )' */ -extern const Word16 filter_LP15_180H_13b_fx[]; /* Sincfilt.m: N=180*2+1, Fmin=0, Fmax=1/15, hann( N )' */ -extern const Word16 filter_LP15_360H_13b_fx[]; /* Sincfilt.m: N=360*2+1, Fmin=0, Fmax=1/15, hann( N )' */ -extern const Word16 filter_LP24_90H_13b_fx[]; -extern const Word16 filter_LP24_90H_fx[]; - -extern const Word16 inter4_1_fx[]; - -extern const Word16 Low_H_phasedisp[L_SUBFR]; -extern const Word16 Mid_H_phasedisp[L_SUBFR]; -extern const Word16 phs_tbl_dec[]; -extern const Word16 FFT_reorder_64[]; -extern const Word16 FFT_reorder_256[]; - -extern const Word16 tbl_gain_trans_tc_fx[]; -extern const Word16 Glottal_cdbk_fx[]; - -extern const Word16 gaus_dico_fx[]; - - -extern const Word16 edct_table_80_fx[]; /* EDCT */ -extern const Word16 edct_table_120_fx[]; /* EDCT */ -extern const Word16 edct_table_100_fx[]; /* EDCT */ -extern const Word16 edct_table_320_fx[]; /* EDCT */ -extern const Word16 edct_table_480_fx[]; /* EDCT */ -extern const Word16 edct_table_600_fx[]; /* EDCT */ -extern const Word16 edct_table_128_fx[]; /* EDCT */ -extern const Word16 edct_table_160_fx[]; /* EDCT */ -extern const Word16 edct_table_40_fx[]; /* EDCT */ -extern const Word16 edct_table_20_fx[]; /* EDCT */ -extern const Word16 edct_table_64_fx[]; -extern const Word16 edct_table_200_fx[]; -extern const Word16 edct_table_240_fx[]; -extern const Word16 edct_table_256_fx[]; -extern const Word16 edct_table_400_fx[]; - -/*------------------------------------------------------------------------------* - * FFT transform - *------------------------------------------------------------------------------*/ -extern const Word16 FFT_REORDER_128[]; -extern const Word16 FFT_REORDER_512[]; -extern const Word16 FFT_REORDER_1024[]; -extern const Word16 FFT_W64[]; -extern const Word16 FFT_W128[]; -extern const Word16 FFT_W256[]; -extern const Word16 FFT_W512[]; -extern const Word16 sincos_t_rad3_fx[]; -extern const Word16 sincos_t_ext_fx[]; - -extern const Word16 Ip_fft16_fx[6]; -extern const Word16 w_fft16_fx[8]; - -extern const Word16 Ip_fft8_fx[6]; -extern const Word16 w_fft8_fx[4]; - -extern const Word16 Ip_fft32_fx[6]; -extern const Word16 w_fft32_fx[16]; - -extern const Word16 Ip_fft64_fx[6]; -extern const Word16 w_fft64_fx[32]; - -extern const Word16 Ip_fft4_fx[6]; -extern const Word16 w_fft4_fx[2]; - -extern const Word16 Ip_fft128_fx[10]; -extern const Word16 w_fft128_fx[64]; - -extern const Word16 ip_edct2_64_fx[6]; -extern const Word16 w_edct2_64_fx[80]; -extern const Word32 w_fft64_16fx[32]; -extern const Word16 Odx_fft64_16fx[64]; -extern const Word16 Ip_fft64_16fx[6]; -extern const Word16 Ip_fft32_16fx[6]; -extern const Word32 w_fft128_16fx[64]; -extern const Word16 Ip_fft128_16fx[10]; -extern const Word16 Idx_dortft320_16fx[320]; -extern const Word16 Ip_fft32_16fx[6]; -extern const Word32 w_fft32_16fx[16]; -extern const Word16 edct_table_160_16fx[160]; -extern const Word16 edct_table_128_16fx[128]; -extern const Word16 edct_table_320_16fx[320]; -extern const Word16 mean_m_fx[]; - -extern const Word16 YG_dicMR_4_fx[]; -extern const Word16 YG_dicMR_2_fx[]; -extern const Word16 YG_dicMR_3_fx[]; -extern const Word16 YG_dicMR_1_fx[]; -extern const Word16 YG_mean16_fx[]; -extern const Word16 YG_dic1_2_fx[]; -extern const Word16 YG_dic1_1_fx[]; -extern const Word16 YG_mean14_fx[]; -extern const Word16 YGain_dic3_LR_fx[];/*Q13 */ -extern const Word16 YGain_dic2_LR_fx[];/*Q13 */ - -extern const Word16 YGain_mean_LR_fx[]; -extern const Word16 Gain_mean_dicHR_fx[]; -extern const Word16 Gain_mean_dic_fx[]; -extern const Word16 mean_gain_dic_fx[]; -extern const Word16 Gain_mean_fx[]; -extern const Word16 Gain_dic3_NBHR_fx[]; -extern const Word16 Gain_dic2_NBHR_fx[]; -extern const Word16 Gain_dic2_NB_fx[]; -extern const Word16 Gain_dic3_NB_fx[]; -extern const Word16 Mean_dic_NB_fx[]; -extern const Word16 Gain_mean_dicNB_fx[]; -extern const Word16 Gain_meanNB_fx[]; -/*extern const Word16 dic_gp_13_fx[]; */ -extern const Word16 dic_gp_fx[]; -extern const Word16 mean_gp_fx[]; -extern const Word16 Gain_dic1_NB_fx[]; -extern const Word16 YGain_dic1_LR_fx[]; - -extern const Word16 mfreq_loc_Q2fx[]; -extern const Word16 mfreq_loc_div_25[]; -extern const Word16 mfreq_bindiv_loc_fx[]; -extern const Word16 sm_table_fx[]; -extern const Word16 GSC_freq_bits[]; - -extern const Word16 gsc_sfm_start[]; -extern const Word16 gsc_sfm_end[]; -extern const Word16 gsc_sfm_size[]; - -extern const Word16 sincos_t_fx[161]; -extern const Word32 GSC_freq_bits_fx[]; - -extern const Word16 *scalar_tbls_fx[4]; -extern const Word16 scalar_4bit_fx[16]; -extern const Word16 scalar_3bit_fx[8]; -extern const Word16 scalar_2bit_fx[4]; -extern const Word16 scalar_1bit_fx[2]; -extern const Word16 Mean_isf_wb[]; -extern const Word16 interpol_isp_amr_wb_fx[]; -extern const Word16 interpol_frac_16k_fx[NB_SUBFR16k]; -extern const Word16 interpol_frac_fx[NB_SUBFR]; -extern const Word16 CNG_burst_att_fx[6][8]; -extern const Word32 pow2_fx[]; -extern const Word16 CNG_details_codebook_fx[64][NUM_ENV_CNG]; - -extern const Word16 deem_tab_fx[]; /* HF BWE - de-emphasis coefficients */ -extern const Word16 filt_hp_fx[]; /* HF BWE - HP filter coefficients in freq. domain */ -extern const Word16 HP_gain_fx[]; /* HF BWE - quantization table for 23.85 */ -extern const Word16 fir_6k_8k_fx[]; /* HF BWE - band-pass filter coefficients */ -extern const Word16 exp_tab_q_fx[]; -extern const Word16 exp_tab_p_fx[]; -extern const Word16 swb_bwe_trans_subband_width_fx[]; -extern const Word16 sqrt_swb_bwe_trans_subband_width_fx[]; -extern const Word16 sqrt_swb_bwe_subband_fx_L1[]; -extern const Word16 sqrt_swb_bwe_subband_fx_L2[]; -extern const Word16 smooth_factor_fx[]; -extern const Word16 swb_bwe_sm_subband_fx[]; - -extern const Word16 swb_bwe_trans_subband_fx[]; -extern const Word16 swb_bwe_subband_fx[]; -extern const Word16 F_2_5_fx[64]; - -extern const Word16 swb_inv_bwe_subband_width_fx[]; -extern const Word16 w_NOR_fx[]; -extern const Word16 sin_switch_8[15]; -extern const Word16 sin_switch_16[30]; -extern const Word16 sin_switch_32[60]; -extern const Word16 sin_switch_48[90]; -/* sinus table for overlapadd */ -/*extern const Word16 sin_switch_96_16_fx[156]; */ -/*extern const Word16 sin_switch_96_12_fx[108]; */ -extern const Word16 one_on_win_48k_fx[210]; /*Q14 */ -extern const Word16 one_on_win_8k_16k_48k_fx[70]; /*Q14 */ -extern const Word16 TRWB2_Ave_fx[16]; -extern const Word16 TRWB_Ave_fx[16]; -/*------------------------------------------------------------------------------* - * ACEPL/HQ core switching tables - *------------------------------------------------------------------------------*/ -extern const Word16 hp12800_32000_fx[]; -extern const Word16 hp16000_32000_fx[]; -extern const Word16 hp12800_48000_fx[]; -extern const Word16 hp16000_48000_fx[]; -extern const Word16 hp12800_16000_fx[]; -extern const Word16 inner_frame_tbl_fx[]; - - -extern const Word16 EnvCdbk11_fx []; -extern const Word16 EnvCdbk1st_fx []; -extern const Word16 EnvCdbk2nd_fx []; -extern const Word16 EnvCdbk3rd_fx []; -extern const Word16 EnvCdbk4th_fx []; -extern const Word16 Env_TR_Cdbk1_fx []; -extern const Word16 Env_TR_Cdbk2_fx []; -extern const Word16 EnvCdbkFB_fx []; -extern const Word16 Mean_env_fx[]; -extern const Word16 Mean_env_tr_fx[]; -extern const Word16 Mean_env_fb_fx[]; - -extern const Word32 PI_select_table_fx[23][8]; /* selection table for Pulse indexing */ -extern const Word32 PI_offset_fx[8][8]; /* offset table for Pulse indexing */ -extern const Word16 PI_factor_fx[]; /* PI factor table for Pulse indexing */ - -extern const short Num_bands_NB[]; - - -extern const Word16 hvq_cb_search_overlap24k[17]; -extern const Word16 hvq_cb_search_overlap32k[21]; - -extern const Word16 hvq_pg_huff_offset[NUM_PG_HUFFLEN]; -extern const Word16 hvq_pg_huff_thres[NUM_PG_HUFFLEN]; -extern const Word16 hvq_pg_huff_tab[32]; - -extern const Word16 hvq_cp_huff_len[52]; -extern const Word16 hvq_cp_huff_val[52]; -extern const Word16 hvq_cp_layer1_map5[HVQ_CP_MAP_LEN]; - -extern const Word16 hvq_cp_huff_thres[HVQ_CP_HUFF_NUM_LEN]; -extern const Word16 hvq_cp_huff_offset[HVQ_CP_HUFF_NUM_LEN]; -extern const Word16 hvq_cp_huff_tab[52]; - -extern const Word16 pgain_huffnorm[32]; -extern const Word16 pgain_huffsizn[32]; - -extern const Word16 huffnorm_tran[32]; -extern const Word16 huffsizn_tran[32]; - -extern const Word16 resize_huffnorm[32]; -extern const Word16 resize_huffsizn[32]; - -extern const Word16 huffsizn[32]; - -extern const Word16 lsf_q_num_bits[]; /* Size of each element of the above, in bits */ - -/*------------------------------------------------------------------------------* - * AVQ - RE8 tables - *------------------------------------------------------------------------------*/ - -extern const Word16 select_table22_fx[][9]; -extern const Word16 vals_a_fx[][4]; /* value of leader element */ -extern const Word16 vals_q_fx[][4]; /* code parameter for every leader */ -extern const UWord16 Is_fx[]; /* codebook start address for every leader */ -extern const Word16 A3_fx[]; /* A3 - Number of the absolute leaders in codebook Q3 */ -extern const Word16 A4_fx[]; /* A4 - Number of the absolute leaders in codebook Q4 */ -extern const UWord16 I3_fx[]; /* I3 - Cardinality offsets for absolute leaders in Q3 */ -extern const UWord16 I4_fx[]; /* I4 - Cardinality offset for absolute leaders in Q4 */ - -extern const Word16 Da_nq_fx[]; -extern const Word16 Da_pos_fx[], Da_nb_fx[]; -extern const Word16 Da_id_fx[]; - -extern const Word16 Assym_window_W16fx[]; -extern const Word16 assym_window_16k_fx[]; -extern const Word16 Hamcos_Window[]; - -extern const Word16 overlap_coefs_fx[NSV_OVERLAP*WIDTH_BAND]; /* in Q15 */ -extern const Word16 overlap_coefs_48kHz_fx[NSV_OVERLAP*WIDTH_BAND]; /* in Q15 */ - -extern const Word16 swb_hr_env_code1_fx[]; /* HR SWB BWE - envelope Q table - first two subabnds in non-transient frames */ -extern const Word16 swb_hr_env_code2_fx[]; /* HR SWB BWE - envelope Q table - second two subabnds in non-transient frames*/ -extern const Word16 swb_hr_env_code3_fx[]; /* HR SWB BWE - envelope Q table - two subands in transient frames */ - -extern const Word16 short_window_48kHz_fx[L_FRAME48k/2/2]; -extern const Word16 short_window_32kHz_fx[L_FRAME32k/2/2]; -extern const Word16 short_window_16kHz_fx[L_FRAME16k/2/2]; -extern const Word16 short_window_8kHz_fx[L_FRAME8k/2/2]; - - -extern const Word16 Hilbert_coeffs_fx[4*NUM_HILBERTS][HILBERT_ORDER1+1]; -extern const Word16 win_flatten_4k_fx[]; /* Window for calculating whitening filter for WB excitation */ - -extern const Word32 no_lead[][MAX_NO_SCALES*2]; -extern const Word32 no_lead_p[][MAX_NO_SCALES*2]; - -extern const Word16 min_lat_bits_SN_fx[]; -extern const Word16 min_lat_bits_pred_fx[]; - -extern const Word16 fb_bwe_sm_subband[]; -extern const Word16 fb_bwe_subband[]; - -extern const Word16 sfm_width[20]; -extern const Word16 a_table_fx[20]; - -/* HQ inner_frame signallisation table */ -extern const Word16 inner_frame_tbl[]; - - -/*------------------------------------------------------------------------------* - * SWB TBE tables - *------------------------------------------------------------------------------*/ - -extern const Word16 skip_bands_SWB_TBE[]; /* bands for SWB TBE quantisation */ -extern const Word16 skip_bands_WB_TBE[]; /* bands for WB TBE quantisation */ - -extern const Word16 swb_lsp_prev_interp_init[]; - -extern const Word16 allpass_poles_3_ov_2[]; /* All pass 3 over 2 filter coefficients */ -extern const Word16 decimate_3_ov_2_lowpass_num[]; -extern const Word16 decimate_3_ov_2_lowpass_den[]; - -/* Band structure */ -extern const Word16 band_len_HQ[]; -extern const Word16 band_start_HQ[]; -extern const Word16 band_end_HQ[]; -extern const Word16 band_len_wb[]; -extern const Word16 band_start_wb[]; -extern const Word16 band_end_wb[]; -extern const Word16 band_len_harm[]; -extern const Word16 band_start_harm[]; -extern const Word16 band_end_harm[]; -extern const Word16 dicnlg2[40]; - -extern const Word16 intl_bw_16[N_INTL_GRP_16]; -extern const Word16 intl_bw_32[N_INTL_GRP_32]; -extern const Word16 intl_bw_48[N_INTL_GRP_48]; -extern const Word16 intl_cnt_16[N_INTL_GRP_16]; -extern const Word16 intl_cnt_32[N_INTL_GRP_32]; -extern const Word16 intl_cnt_48[N_INTL_GRP_48]; -extern const Word16 norm_order_48[NB_SFM]; -extern const Word16 norm_order_32[SFM_N_SWB]; -extern const Word16 norm_order_16[SFM_N_WB]; - -extern const Word16 gaus_dico_swb_fx[]; /* Gaussian codebook for SWB TBE */ -extern const Word16 win_flatten_fx[]; /* Window for calculating whitening filter for SHB excitation */ -extern const Word16 AP1_STEEP_FX[]; /* All pass filter coeffs for interpolation and decimation by a factor of 2 */ -extern const Word16 AP2_STEEP_FX[]; /* All pass filter coeffs for interpolation and decimation by a factor of 2 */ -extern const Word16 cos_fb_exc_fx[32]; -extern const Word16 window_wb_fx[]; -extern const Word16 subwin_wb_fx[]; /* Short overlap add window for SHB excitation used in anal and synth */ -extern const Word16 window_shb_fx[]; /* Overlap add window for SHB excitation used in anal and synth */ -extern const Word16 window_shb_32k_fx[]; -extern const Word16 subwin_shb_fx[]; /* Short overlap add window for SHB excitation used in anal and synth */ -extern const Word16 * const lsf_q_cb_fx[]; /* Codebook array for each LSF */ -extern const Word16 lsf_q_cb_size_fx[]; /* Size of each element of the above */ -extern const Word16 grid_smoothing_fx[]; /* LSF mirroring smoothing table */ -extern const Word16 mirror_point_q_cb_fx[]; /* LSF mirroring point codebook */ -extern const Word16 lbr_wb_bwe_lsfvq_cbook_2bit_fx[]; -extern const Word16 swb_tbe_lsfvq_cbook_8b[]; -extern const Word32 SHBCB_FrameGain16_fx[]; -extern const Word16 SHBCB_SubGain5bit_fx[]; /* 5 bit Quantizer table for SHB gain shapes */ -extern const Word16 SHBCB_SubGain5bit_12_fx[]; /* 5 bit Quantizer table for SHB gain shapes */ -extern const Word16 HBCB_SubGain5bit_fx[]; /* 5-bit TD WB BWE temporal shaping codebook */ -extern const Word32 SHBCB_FrameGain64_fx[]; /* 6 bit Quantizer table for SHB overall gain */ -extern const Word32 SHBCB_FrameGain16_fx[]; -extern const Word16 full_band_bpf_1_fx[][5]; -extern const Word16 full_band_bpf_2_fx[][5]; -extern const Word16 full_band_bpf_3_fx[][5]; -extern const Word16 lsf_q_cb_4b_fx[]; /* 4 bit differential scalar quantizer table for TD SWB BWE LSFs 1 and 2*/ -extern const Word16 lsf_q_cb_3b_fx[]; /* 3 bit differential scalar quantizer table for TD SWB BWE LSFs 3, 4 and 5*/ - -extern const Word16 cos_coef_new[4]; -extern const Word16 pwAlpha[10]; - -extern const Word16 interpol_frac_shb[NB_SUBFR*2]; - -extern const Word16 wb_bwe_lsfvq_cbook_8bit_fx[]; -extern const Word16 lsf_grid_fx[4][5]; /* LSF mirroring adjustment grid */ -extern const Word16 ola_win_shb_switch_fold_fx[]; -extern const Word16 win_lpc_hb_wb_fx[]; -extern const Word16 wac_h[]; -extern const Word16 wac_l[]; -extern const Word16 wac_swb_h[LPC_SHB_ORDER]; -extern const Word16 wac_swb_l[LPC_SHB_ORDER]; -extern const Word16 lpc_weights_fx[]; -extern const Word16 win_lpc_shb_fx[]; /* Window for calculating SHB LPC coeffs */ -extern const Word16 cos_table[512]; -extern const Word16 cos_diff_table[512]; -extern const Word16 Ip_fft256_fx[10]; -extern const Word16 w_fft256_fx[128]; -extern const Word16 Ip_fft512_fx[18]; -extern const Word16 w_fft512_fx[256]; -extern const Word16 sinq_16k[]; -extern const Word16 sinq_32k[]; -extern const Word16 sinq_48k[]; -extern const Word16 Asr_LP32_fx[41]; -extern const Word16 Asr_LP16_fx[21]; -extern const Word16 Asr_LP48_fx[61]; -extern const Word16 window_8_16_32kHz_fx[]; -extern const Word16 window_48kHz_fx[]; -extern const Word16 window_256kHz[]; -extern const Word16 half_overlap_25[]; -extern const Word16 half_overlap_48[]; -extern const Word16 half_overlap_int[]; -extern const Word16 small_overlap_25[]; -extern const Word16 small_overlap_48[]; -extern const Word16 small_overlap_int[]; - -/* SC-VBR: NELP filter coefficients */ - -extern const Word16 txlpf1_num_coef_fx[11]; -extern const Word16 txlpf1_den_coef_fx[11]; -extern const Word16 txhpf1_num_coef_fx[11]; -extern const Word16 txhpf1_den_coef_fx[11]; - - -extern const Word16 shape1_num_coef_fx[11]; -extern const Word16 shape1_den_coef_fx[11]; -extern const Word16 shape2_num_coef_fx[11]; -extern const Word16 shape2_den_coef_fx[11]; -extern const Word16 shape3_num_coef_fx[11]; -extern const Word16 shape3_den_coef_fx[11]; -extern const Word16 bp1_num_coef_wb_fx[5]; -extern const Word16 bp1_den_coef_wb_fx[5]; -extern const Word16 bp1_num_coef_nb_fx[13]; -extern const Word16 bp1_den_coef_nb_fx[13]; - -extern const Word16 bp1_num_coef_nb_fx_order7[8]; -extern const Word16 bp1_den_coef_nb_fx_order7[8]; - -extern const Word16 UVG1CB_WB_FX[UVG1_CBSIZE][2]; -extern const Word16 UVG2CB1_WB_FX[UVG2_CBSIZE][5]; -extern const Word16 UVG2CB2_WB_FX[UVG2_CBSIZE][5]; - -extern const Word16 UVG1CB_NB_FX[UVG1_CBSIZE][2]; -extern const Word16 UVG2CB1_NB_FX[UVG2_CBSIZE][5]; -extern const Word16 UVG2CB2_NB_FX[UVG2_CBSIZE][5]; - -extern const Word16 frac_4sf_fx[NB_SUBFR +2]; - -extern const Word16 erb_WB_fx[NUM_ERB_WB + 1]; -extern const Word16 erb_NB_fx[NUM_ERB_NB + 1]; - -extern const Word16 AmpCB1_WB_fx[640]; -extern const Word16 pwf78_fx[17]; - -extern const Word16 AmpCB2_WB_fx[64*(NUM_ERB_WB-13)]; - -extern const Word16 AmpCB1_NB_fx[640]; - -extern const Word16 AmpCB2_NB_fx[64*(NUM_ERB_NB-13)]; - -extern const Word16 PowerCB_WB_fx[128]; -extern const Word16 PowerCB_NB_fx[128]; -extern const Word16 sinc_fx[8][12]; -extern const Word16 hvq_cb_search_overlap24k[17]; -extern const Word16 hvq_cb_search_overlap32k[21]; - -extern const Word32 inverse_table[]; - -extern const Word16 post_dct_wind_fx[]; -extern const Word16 mfreq_loc_LD_fx[]; -extern const Word16 inv_mfreq_bindiv_LD_fx[]; -extern const Word16 inv_mfreq_bindiv_LD_M1_fx[]; -/*extern const Word16 inv_mfreq_M1_SC_FACT_fx[]; */ -extern const Word16 sc_qnoise_fx[]; -extern const Word16 MAX_SNR_SNR1_tab_FX[MBANDS_GN_LD]; -extern const Word16 INV_MAX_SNR_tab_FX[MBANDS_GN_LD]; - -extern const Word16 W_DTX_HO_FX[HO_HIST_SIZE]; -extern const Word16 HO_ATT_FX[5]; - - -/*----------------------------------------------------------------------------------* - * SWB HR BWE - *----------------------------------------------------------------------------------*/ - -extern const Word16 wscw16q15_fx[]; -extern const Word16 wscw16q15_8_fx[]; -extern const Word16 wscw16q15_16_fx[]; -extern const Word16 wscw16q15_32_fx[]; - -extern const Word16 crit_bands_loc_fx[]; -extern const Word16 lag_h[]; -extern const Word16 lag_l[]; - -extern const Word16 hvq_class_c_fx[]; -extern const Word32 dicn_fx[40]; -extern const Word16 sqac_headroom_fx[146]; -extern const Word16 inv_N_fx[32]; -extern const Word16 hvq_bwe_fac_fx[16]; -extern const Word16 att_step_fx[4]; -extern const Word16 gain_att_fx[40]; -extern const Word16 stab_trans_fx[]; -extern const Word16 env_stab_tp_fx[2][2]; -extern const Word16 subf_norm_groups_fx[4][11]; -extern const Word32 dicn_pg_fx[]; -extern const Word16 hvq_peak_cb_fx[]; -extern const Word16 rat_fx[SFM_N_WB]; -extern const Word16 fb_inv_bwe_subband_width_fx[]; -extern const Word16 fb_smooth_factor_fx[]; -extern const Word16 hvq_thr_adj_fx[]; -extern const Word16 hvq_index_mapping_fx[4]; -extern const Word16 hq_nominal_scaling_inv[]; -extern const Word16 hq_nominal_scaling[]; -extern const Word16 band_len_idx[]; -extern const Word16 band_len_ener_shift[]; -extern const Word16 fine_gain_pred_sqrt_bw[]; -extern const Word16* finegain_fx[5]; -extern const Word32 SQRT_DIM_fx[]; -extern const Word16 gain_cb_size[]; - -/* PVQ tables */ -extern const UWord32 exactdivodd_fx[ODD_DIV_SIZE_FX]; - - - -extern const Word32 thren_fx[39]; - -typedef struct -{ - Word16 bands; - Word16 bw; - const Word16 *band_width; - Word32 L_qint; - Word16 eref; - Word16 bit_alloc_weight; - Word16 gqlevs; - Word16 Ngq; - Word16 p2a_bands; - Word16 p2a_th; - Word16 pd_thresh; - Word16 ld_slope; - Word16 ni_coef; -} Xcore_Config_fx; - -/* LR-MDCT configuration tables */ -extern const Xcore_Config_fx xcore_config_8kHz_007200bps_long_fx; -extern const Xcore_Config_fx xcore_config_8kHz_008000bps_long_fx; -extern const Xcore_Config_fx xcore_config_8kHz_013200bps_long_fx; -extern const Xcore_Config_fx xcore_config_8kHz_016400bps_long_fx; - -extern const Xcore_Config_fx xcore_config_8kHz_007200bps_short_fx; -extern const Xcore_Config_fx xcore_config_8kHz_008000bps_short_fx; -extern const Xcore_Config_fx xcore_config_8kHz_013200bps_short_fx; -extern const Xcore_Config_fx xcore_config_8kHz_016400bps_short_fx; - -extern const Xcore_Config_fx xcore_config_16kHz_013200bps_long_fx; -extern const Xcore_Config_fx xcore_config_16kHz_016400bps_long_fx; - -extern const Xcore_Config_fx xcore_config_16kHz_013200bps_short_fx; -extern const Xcore_Config_fx xcore_config_16kHz_016400bps_short_fx; - -extern const Xcore_Config_fx xcore_config_32kHz_013200bps_long_fx; -extern const Xcore_Config_fx xcore_config_32kHz_016400bps_long_fx; - -extern const Xcore_Config_fx xcore_config_32kHz_013200bps_short_fx; -extern const Xcore_Config_fx xcore_config_32kHz_016400bps_short_fx; - -extern const Word16 Odx_fft32_5[32]; -extern const Word16 Idx_dortft160[160]; - - -extern const Word16 nextstate[STATES][2]; - -extern const Word16 fine_gain_bits[]; - -/*----------------------------------------------------------------------------------* - * SWB BWE for LR MDCT core - *----------------------------------------------------------------------------------*/ -/* HQ_NORMAL mode */ -extern const Word16 subband_offsets_12KBPS[NB_SWB_SUBBANDS]; -extern const Word16 subband_offsets_16KBPS[NB_SWB_SUBBANDS]; -extern const Word16 bits_lagIndices_modeNormal_fx[NB_SWB_SUBBANDS]; -extern const Word16 subband_search_offsets_fx[NB_SWB_SUBBANDS]; -extern const Word16 bw_SPT_tbl[2][SPT_SHORTEN_SBNUM]; - -/* HQ_HARMONIC mode */ -extern const Word16 bits_lagIndices_mode0_Har_fx[NB_SWB_SUBBANDS_HAR_SEARCH_SB]; -extern const Word16 subband_offsets_sub5_13p2kbps_Har_fx[NB_SWB_SUBBANDS_HAR]; -extern const Word16 subband_search_offsets_13p2kbps_Har_fx[NB_SWB_SUBBANDS_HAR_SEARCH_SB]; -extern const Word16 subband_offsets_sub5_16p4kbps_Har_fx[NB_SWB_SUBBANDS_HAR]; -extern const Word16 subband_search_offsets_16p4kbps_Har_fx[NB_SWB_SUBBANDS_HAR_SEARCH_SB] ; -extern const Word16 gain_table_SWB_BWE_fx[NB_SWB_SUBBANDS]; - - -extern const Word16 inv_tbl_fx[]; -extern const Word32 table_logcum_fx[563]; -extern const Word32 pow_getbitsfrompulses_fx[16]; -extern const Word16 DDP_fx[4]; -extern const Word16 step_tcq_fx[8][STATES]; -extern const Word16 denc_fx[8][STATES]; /* enc trellis */ -extern const Word16 ddec_fx[8][STATES]; /* dec trellis */ -extern const Word16 step_LSB_fx[STATES_LSB][2]; -extern const Word16 denc_LSB_fx[STATES_LSB][2]; -extern const Word16 dqnt_LSB_fx[STATES_LSB][4]; - -extern const Word16 dstep_LSB_fx[4][2]; -extern const Word16 ddec_LSB_fx[4][2]; - -extern const Word16 SmoothingWin_NB875_fx[]; -extern const Word16 SmoothingWin_NB2_fx[]; - -extern const Word16 window_48kHz_fx16[]; -extern const Word16 ENR_ATT_fx[5]; - - -extern const Word16 cu15_fx[28][3]; -extern const Word16 cu4_fx[6][3]; -extern const Word16 ct2_fx[7][14]; - -extern const unsigned char* const hBitsN[65]; -extern const short dsDiracsTab[65]; -extern const unsigned int intLimCDivInvDQ31[68]; -extern const unsigned char obtainEnergyQuantizerDensity_f[57]; - -extern const Word16 lim_neg_inv_tbl_fx[11]; - - -extern const Word16 One_div_fx[]; - - -/*---------------------------------------------------------------------* - * TABLE ROM, defined in lib_com\rom_com.c - *---------------------------------------------------------------------*/ -extern const Word16 inter4_2tcx2[4][4]; -extern const Word16 inter6_2tcx2[6][4]; -typedef struct TCX_LTP_FILTER -{ - const Word16 *filt; - Word16 length; -} TCX_LTP_FILTER; -extern const TCX_LTP_FILTER tcxLtpFilters[12]; - -extern const Word16 Grid[]; -extern const Word16 low_H[64]; -extern const Word16 low_H16k[80]; -extern const Word16 mid_H[64]; -extern const Word16 mid_H16k[80]; - -extern const Word16 E_ROM_inter4_1[PIT_UP_SAMP * L_INTERPOL1 + 1]; -extern const Word16 E_ROM_inter6_1[PIT_UP_SAMP6 * L_INTERPOL1 + 1]; -extern const Word16 E_ROM_qua_gain5b_const[NB_QUA_GAIN5B * 2]; -extern const Word16 E_ROM_qua_gain6b_const[NB_QUA_GAIN6B * 2] ; -extern const Word16 E_ROM_qua_gain7b_const[NB_QUA_GAIN7B * 2] ; -extern const Word16 Es_pred_qua[8]; -extern const Word16 Es_pred_qua_2[16]; - -extern const SCALE_TCX_SETUP scaleTcxTable[13]; - -extern const FrameSizeParams FrameSizeConfig[FRAME_SIZE_NB]; -extern const Word16 amrwb_frame_sizes[9]; - -/*fd_cng_commom.h*/ -extern const Word16 d_array[18]; -extern const Word16 m_array[18]; -#define msQeqInvAv_thres_EXP (-4) -extern const Word16 msQeqInvAv_thresh[3]; -extern const Word16 msNoiseSlopeMax[4]; -extern const Word16 preemphCompensation[NB_BANDS]; -#define msNoiseSlopeMax_EXP 3 - -extern const SCALE_SETUP scaleTable[20]; -extern const SCALE_SETUP scaleTable_cn_only[18]; -extern const Word16 scaleTable_cn_only_amrwbio[3][2]; - -extern const Word16 sidparts_encoder_noise_est[24]; - - -extern const FD_CNG_SETUP FdCngSetup_nb; -extern const FD_CNG_SETUP FdCngSetup_wb1; -extern const FD_CNG_SETUP FdCngSetup_wb2; -extern const FD_CNG_SETUP FdCngSetup_wb3; -extern const FD_CNG_SETUP FdCngSetup_swb1; -extern const FD_CNG_SETUP FdCngSetup_swb2; - -extern const Word16 maxN_37bits; -extern const Word16 maxC_37bits; -extern const Word16 stages_37bits; -extern const Word16 levels_37bits[6]; -extern const Word16 bits_37bits[6]; -extern Word16 const * const cdk_37bits[]; - -/* tcx_utils.c */ -extern const Word16 gain_corr_fac[]; /*pow(10,2^(-n-2)/28)*/ -extern const Word16 gain_corr_inv_fac[];/*pow(10,-2^(-n-2)/28)*/ - -/* ari_stat.h */ -extern const Word8 ari_lookup_s17_LC[4096]; -extern const UWord16 ari_pk_s17_LC_ext[64][18]; -extern const Word16 Tab_esc_nb[4]; - -/* ari_hm.c */ -extern const Word16 NumRatioBits[2][17]; -extern const Word16 Ratios_WB_2[32]; -extern const Word16 Ratios_WB_3[32]; -extern const Word16 Ratios_WB_4[32]; -extern const Word16 Ratios_WB_5[32]; -extern const Word16 Ratios_WB_6[32]; -extern const Word16 Ratios_WB_7[32]; -extern const Word16 Ratios_WB_8[16]; -extern const Word16 Ratios_WB_9[16]; -extern const Word16 Ratios_WB_10[16]; -extern const Word16 Ratios_WB_11[16]; -extern const Word16 Ratios_WB_12[16]; -extern const Word16 Ratios_WB_13[16]; -extern const Word16 Ratios_WB_14[16]; -extern const Word16 Ratios_WB_15[16]; -extern const Word16 Ratios_WB_16[4]; -extern const Word16 Ratios_WB_17[4]; -extern const Word16 Ratios_WB_18[4]; -extern const Word16 Ratios_NB_2[32]; -extern const Word16 Ratios_NB_3[16]; -extern const Word16 Ratios_NB_4[16]; -extern const Word16 Ratios_NB_5[16]; -extern const Word16 Ratios_NB_6[16]; -extern const Word16 Ratios_NB_7[16]; -extern const Word16 Ratios_NB_8[16]; -extern const Word16 Ratios_NB_9[8]; -extern const Word16 Ratios_NB_10[8]; -extern const Word16 Ratios_NB_11[8]; -extern const Word16 Ratios_NB_12[8]; -extern const Word16 Ratios_NB_13[4]; -extern const Word16 Ratios_NB_14[4]; -extern const Word16 Ratios_NB_15[4]; -extern const Word16 Ratios_NB_16[4]; -extern const Word16 Ratios_NB_17[4]; -extern const Word16 Ratios_NB_18[4]; -extern const Word16 *const Ratios[2][17]; - -extern const Word16 qGains[2][1 << kTcxHmNumGainBits]; - -/*tns_tables.h*/ - -extern struct TnsParameters const tnsParametersIGF32kHz_LowBR[1]; - -extern struct TnsParameters const tnsParameters32kHz[2]; - -extern struct TnsParameters const tnsParameters32kHz_grouped[2]; - -extern struct TnsParameters const tnsParameters16kHz[1]; - -extern struct TnsParameters const tnsParameters16kHz_grouped[2]; -extern struct TnsParameters const tnsParameters48kHz_grouped[2]; - -extern const Word16 tnsAcfWindow[TNS_MAX_FILTER_ORDER]; - -/**********************************************************************/ -/* Definition of the mapping between TNS parameters and a bitstream */ -/**********************************************************************/ - -extern ParamsBitMap const tnsEnabledSWBTCX20BitMap[1]; -extern ParamsBitMap const tnsEnabledSWBTCX10BitMap[1]; -extern ParamsBitMap const tnsEnabledWBTCX20BitMap[1]; - -/**********************************************/ -/* Helper structures for hufmann table coding */ -/**********************************************/ - -extern const Coding codesTnsAllCoeffs[]; - -extern const Coding codesTnsCoeff5[]; -extern const Coding codesTnsCoeff6[]; - -extern const Coding codesTnsCoeff0WBTCX20[]; -extern const Coding codesTnsCoeff1WBTCX20[]; -extern const Coding codesTnsCoeff2WBTCX20[]; -extern const Coding codesTnsCoeff3WB[]; - -extern const Coding codesTnsCoeff456[]; -extern const Coding codesTnsCoeff7[]; - -extern Word16 const nTnsCoeffCodes; - -extern const Coding * codesTnsCoeffSWBTCX20[]; -extern const Coding * codesTnsCoeffSWBTCX10[]; -extern const Coding * codesTnsCoeffWBTCX20[]; -extern Word16 const nTnsCoeffTables; - -extern const Coding codesTnsOrderTCX20[]; -extern const Coding codesTnsOrderTCX10[]; -extern const Coding codesTnsOrder[]; -extern Word16 const nTnsOrderCodes; - - -/*******************************/ -/* Quantized TNS coefficients. */ -/*******************************/ - -/* 4 bit resolution TNS coefficients. */ -extern const Word16 tnsCoeff4[16]; - -/*bits_alloc.h*/ - -/*bits_alloc_tables.h*/ -/*RATE MODE CONFIGURATION TABLE*/ -extern const Word16 RATE_MODE_MAPPING[FRAME_SIZE_NB]; - - -/*ACELP INNOVATIVE CDBK*/ -#define ACELP_FIXED_CDK_BITS(n) ACELP_CDK_BITS[n] - -/* Number of states for any combination pulses in any combination of vector length */ -extern const Word32 pulsestostates[17][9]; - - - -/*ACELP NRG ELEMENT*/ -extern const Word16 ACELP_NRG_MODE[RATE_MODE_MAX][BANDWIDTH_MODE_MAX][ACELP_MODE_MAX+RF_MODE_MAX]; -extern const Word16 ACELP_NRG_BITS[3]; - -/*ACELP LTP ELEMENT*/ -extern const Word16 ACELP_LTP_MODE[RATE_MODE_MAX][BANDWIDTH_MODE_MAX][ACELP_MODE_MAX+RF_MODE_MAX]; -extern const Word16 ACELP_LTP_BITS_SFR[8+RF_MODE_MAX][5]; - -/*ACELP LTF ELEMENT*/ -extern const Word16 ACELP_LTF_MODE[RATE_MODE_MAX][BANDWIDTH_MODE_MAX][ACELP_MODE_MAX+RF_MODE_MAX]; -extern const Word16 ACELP_LTF_BITS[4]; - -/*ACELP GAINS ELEMENT*/ -extern const Word16 ACELP_GAINS_MODE[RATE_MODE_MAX][BANDWIDTH_MODE_MAX][ACELP_MODE_MAX+RF_MODE_MAX]; -extern const Word16 ACELP_GAINS_BITS[10]; - -/*ACELP BPF ADAPT ELEMENT*/ -extern const Word16 ACELP_BPF_MODE[RATE_MODE_MAX][BANDWIDTH_MODE_MAX][ACELP_MODE_MAX+RF_MODE_MAX]; -extern const Word16 ACELP_BPF_BITS[3]; - -extern const Word8 gTcxLpcLsf[3][2]; -extern const Word16 *lsf_means[2]; -typedef Word16 lsp_unw_triplet[3]; -extern const lsp_unw_triplet p16_gamma0_92to1[16]; -extern const lsp_unw_triplet p16_gamma0_94to1[16]; - -extern const Word16 *const lsf_codebook[2][2][TCXLPC_NUMSTAGES]; -extern const Word16 lsf_numbits[TCXLPC_NUMSTAGES]; -extern const Word16 lsf_dims[TCXLPC_NUMSTAGES]; -extern const Word16 lsf_offs[TCXLPC_NUMSTAGES]; -extern const Word16 lsf_q_diff_cb_8b_rf[]; -extern const Word16 lsf_cdk_nb_gc_stg1[]; -extern const Word16 lsf_cdk_nb_gc_stg2[]; -extern const Word16 lsf_cdk_nb_gc_stg3[]; -extern const Word16 lsf_ind_cdk_nb_gc_stg4[]; -extern const Word16 lsf_cdk_nb_vc_stg1[]; -extern const Word16 lsf_cdk_nb_vc_stg2[]; -extern const Word16 lsf_cdk_nb_vc_stg3[]; -extern const Word16 lsf_ind_cdk_nb_vc_stg4[]; -extern const Word16 lsf_cdk_wb_gc_stg1[]; -extern const Word16 lsf_cdk_wb_gc_stg2[]; -extern const Word16 lsf_cdk_wb_gc_stg3[]; -extern const Word16 lsf_ind_cdk_wb_gc_stg4[]; -extern const Word16 lsf_cdk_wb_vc_stg1[]; -extern const Word16 lsf_cdk_wb_vc_stg2[]; -extern const Word16 lsf_cdk_wb_vc_stg3[]; -extern const Word16 lsf_ind_cdk_wb_vc_stg4[]; - -extern const Word16 *const lsf_ind_codebook[2][2][TCXLPC_IND_NUMSTAGES]; -extern const Word16 lsf_ind_numbits[TCXLPC_IND_NUMSTAGES]; -extern const Word16 lsf_ind_dims[TCXLPC_IND_NUMSTAGES]; -extern const Word16 lsf_ind_offs[TCXLPC_IND_NUMSTAGES]; -extern const Word16 min_distance_thr[2][2]; - -extern const Word16 mean_isf_wb [16]; - -extern const Word16 means_nb_31bits_ma_lsf[16]; -extern const Word16 means_wb_31bits_ma_lsf[16]; - -extern const Word16 maxC_wbhb_31bits_ma_lsf; -extern const Word16 stages_wbhb_31bits_ma_lsf; -extern const Word16 levels_wbhb_31bits_ma_lsf[5]; -extern const Word16 bits_wbhb_31bits_ma_lsf[5]; - -extern const Word16 lsf_fit_model[5][16]; - - -extern const Word16 cdk_wbhb_31bits_ma_lsf_10_p12[1536]; - -extern const Word16 cdk_wbhb_31bits_ma_lsf_20_p12[768]; - -extern const Word16 cdk_wbhb_31bits_ma_lsf_30_p12[768]; - -extern const Word16 cdk_wbhb_31bits_ma_lsf_40_p12[768]; - -extern const Word16 cdk_wbhb_31bits_ma_lsf_50_p12[768]; - -extern const Word16 cdk_wbhb_31bits_ma_lsf_11_p12[1536]; - -extern const Word16 cdk_wbhb_31bits_ma_lsf_21_p12[768]; - -extern const Word16 cdk_wbhb_31bits_ma_lsf_31_p12[768]; - -extern const Word16 cdk_wbhb_31bits_ma_lsf_41_p12[768]; - -extern const Word16 cdk_wbhb_31bits_ma_lsf_51_p12[768]; - -extern const Word16 * const cdk_wbhb_31bits_ma_lsf0[]; -extern const Word16 * const cdk_wbhb_31bits_ma_lsf1[]; - - -extern const Word16 CLDFB80_10[100]; -extern const Word16 CLDFB80_16[160]; -extern const Word16 CLDFB80_20[200]; -extern const Word16 CLDFB80_32[320]; -extern const Word16 CLDFB80_40[400]; -extern const Word16 CLDFB80_60[600]; - -extern const Word16 rRotVectr_10[]; -extern const Word16 iRotVectr_10[]; -extern const Word16 rRotVectr_16[]; -extern const Word16 iRotVectr_16[]; -extern const Word16 rRotVectr_20[]; -extern const Word16 iRotVectr_20[]; -extern const Word16 rRotVectr_32[]; -extern const Word16 iRotVectr_32[]; -extern const Word16 rRotVectr_40[]; -extern const Word16 iRotVectr_40[]; -extern const Word16 rRotVectr_60[]; -extern const Word16 iRotVectr_60[]; - -extern const Word16 cldfb_anaScale[]; -extern const Word16 cldfb_synScale[]; -extern const Word16 cldfb_synGain[]; -extern const Word16 *cldfb_protoFilter_2_5ms[]; -extern const Word16 cldfb_scale_2_5ms[7]; - - -extern const Word16 lag_window_8k[2][16]; -extern const Word16 lag_window_12k8[NUM_LAGW_STRENGTHS][2][16]; -extern const Word16 lag_window_16k[NUM_LAGW_STRENGTHS][2][16]; -extern const Word16 lag_window_25k6[NUM_LAGW_STRENGTHS][2][16]; -extern const Word16 lag_window_32k[NUM_LAGW_STRENGTHS][2][16]; -extern const Word16 lag_window_48k[2][16]; - -/**********************************************************************/ /** -igf settings structure for each bitrate mode -**************************************************************************/ -typedef struct igf_mode_type -{ - Word32 sampleRate; - Word16 frameLength; - Word32 bitRate; - Word16 igfMinFq; - Word16 transFac; - Word16 maxHopsize; -} IGF_MODE,*H_IGF_MODE; - - -extern const IGF_MODE igfMode[15]; -extern const Word16 swb_offset_LB_new[15][IGF_MAX_SFB]; -extern const Word16 igf_whitening_TH[15][2][IGF_MAX_TILES]; - -extern const Word16 cf_off_se01_tab[9]; - -extern const Word16 cf_off_se10_tab; - -extern const Word16 cf_off_se02_tab[9][IGF_CTX_COUNT]; - -extern const Word16 cf_off_se11_tab[IGF_CTX_COUNT][IGF_CTX_COUNT]; -extern const Word16 cf_se00_tab[IGF_SYMBOLS_IN_TABLE + 1]; - -extern const Word16 cf_se01_tab[9][IGF_SYMBOLS_IN_TABLE + 1]; -extern const Word16 cf_se02_tab[9][IGF_CTX_COUNT][IGF_SYMBOLS_IN_TABLE + 1]; - -extern const Word16 cf_se10_tab[IGF_SYMBOLS_IN_TABLE + 1]; -extern const Word16 cf_se11_tab[IGF_CTX_COUNT][IGF_CTX_COUNT][IGF_SYMBOLS_IN_TABLE + 1]; - -extern const Word32 bwMode2fs[4]; - -extern const Word16 kLog2TableFrac_x[256]; -extern const Word16 kExp2TableFrac_x[256]; -extern const Word16 sqrt_table_pitch_search[256+1]; - -extern const Word16 grid50_fx[(GRID50_POINTS-1)/2 - 1]; -extern const Word16 grid40_fx[(GRID40_POINTS-1)/2 - 1]; -/******************** moved over from table_decl.h ************************/ - -/* For pitch predictor */ -#define INTERP_EXP 0 -extern const Word16 pitch_inter4_1[UP_SAMP * L_INTERPOL1 + 1]; /*1Q14*/ -extern const Word16 pitch_inter4_2[PIT_FIR_SIZE2]; /*1Q14*/ -extern const Word16 pitch_inter6_2[PIT_FIR_SIZE6_2]; /*1Q14*/ - -/* For bass postfilter */ -extern const Word16 filt_lp[1 + L_FILT]; -extern const Word16 filt_lp_16kHz[1+L_FILT16k]; - -extern const Word16 L_frame_inv[8]; - -extern const Word16 TecLowBandTable[]; -extern const Word16 TecSC_Fx[]; - -extern const Word16 uniform_model_fx[]; - -/* fft.c */ -extern const Word16 RotVector_32[2*20]; -extern const Word16 RotVector_256[2*(256-32)]; -extern const Word16 RotVector_320[2*(320-20)]; -extern const Word16 RotVector_400[2*(400-20)]; -extern const Word16 RotVector_480[2*(480-30)]; -extern const Word16 RotVector_600[2*(600-30)]; - -extern const Word16 tab_ari_qnew[4][4]; - - -extern const Word16 num_nelp_lp_fx[NELP_LP_ORDER+1]; -extern const Word16 den_nelp_lp_fx[NELP_LP_ORDER+1]; - -/* ACELP pulse coding */ -extern const Word16 hi_to_low_tmpl[10]; -extern const Word16 low_len[10]; -extern const Word32 low_mask[10]; -extern const Word16 indx_fact[10]; -extern const Word16 index_len[3]; -extern const UWord32 index_mask_ACELP[3]; - -extern const Word16 inv_jp2[]; - -#endif /*ROM_COM_H */ - diff --git a/src/libs/libevs/lib_com/scale_mem_fx.cpp b/src/libs/libevs/lib_com/scale_mem_fx.cpp deleted file mode 100755 index 223b6829..00000000 --- a/src/libs/libevs/lib_com/scale_mem_fx.cpp +++ /dev/null @@ -1,346 +0,0 @@ -/*==================================================================================== - EVS Codec 3GPP TS26.442 Apr 03, 2018. Version 12.11.0 / 13.6.0 / 14.2.0 - ====================================================================================*/ - -#include "options.h" /* Common prototypes */ -#include "prot_fx.h" /* Common prototypes */ -#include "cnst_fx.h" -#include "stl.h" - -/*-------------------------------------------------------------------* - * Rescale_exc: - * - * Find absolute maximum of excitation - * Fin scaling factor to apply the excitation and its related memory - * Scale excitation and total excitation (exc2) - *-------------------------------------------------------------------*/ -Word16 Rescale_exc( - Word16 dct_post_old_exc_fx[], /* i/o: Music post processing memory */ - Word16 exc[], /* i/o: excitation to rescale Q_exc */ - Word16 bwe_exc[], - Word16 *last_exc_dct_in, - Word16 lg, /* i : frame size */ - Word16 lg32, - Word32 L_gain_code, /* i : decoded codebook gain Q16 */ - Word16 *sQ_exc, /* i/o: Excitation scaling factor */ - Word16 *sQsubfr, /* i/o: Past excitation scaling factors */ - Word16 exc2[], /* o : local excitation vector */ - Word16 i_subfr, /* i : subframe number */ - const Word16 coder_type -) -{ - Word16 i, tmp, max, new_Q; - - /*------------------------------------------- - * find maximum of absolute excitation - *-------------------------------------------*/ - max = s_max(abs_s(exc[0]), 1); - FOR (i = 1; i < lg; i++) - { - tmp = abs_s(exc[i]); - max = s_max(max, tmp); - } - - /*---------------------------------------------- - * find scaling (tmp) to set max = [2048..4096[ - *----------------------------------------------*/ - tmp = sub(add(norm_s(max), *sQ_exc), 3); - tmp = s_min(tmp, 12); - - /*---------------------------------------------- - * find scaling (new_Q) to keep gain_code < 2048 - *----------------------------------------------*/ - - new_Q = add(tmp, 1); - tmp = sub(norm_l(L_or(L_gain_code, 1)), 3); /* to get to 0x08000000L (L_or with 1 to avoid norm_l(0)) */ - tmp = s_min(tmp, new_Q); - tmp = s_max(tmp, 0); - tmp = sub(tmp, 1); - - /*#define REMOVE_EXCITATION_PER_FRAME_SCALING */ - - /*---------------------------------------------- - * new_Q = smallest Q since 4 subframes (20ms) - *----------------------------------------------*/ - IF( sub( coder_type, TRANSITION ) == 0 ) - { - tmp = s_min(tmp, 7); - } - ELSE IF (sub(coder_type,INACTIVE)==0) - { - tmp = s_min(tmp, 13); - } - ELSE IF( sub(lg,L_SUBFR) > 0 )/* --> can only happen in AUDIO mode */ - { - tmp = s_min(tmp, 4); /* Limitation of the scaling gain because the frequency domain will add much more energy to the excitation*/ - if( L_sub(L_abs(L_gain_code), 3276800) >= 0 ) /*(1-gain_pit)*past gain code*4 > 50 */ - { - tmp = s_min(tmp, 2); /* Limitation of the scaling gain because the frequency domain might add much more energy to the excitation*/ - } - } - - new_Q = s_min(tmp, sQsubfr[0]); - IF(sub(lg, L_SUBFR)==0) - { - FOR(i = L_Q_MEM-1; i >= 1; i--) - { - new_Q = s_min(new_Q, sQsubfr[i]); - sQsubfr[i] = sQsubfr[i-1]; - move16(); - } - } - ELSE - { - IF(sub(lg, 2*L_SUBFR)==0) - { - new_Q = s_min(new_Q, sQsubfr[L_Q_MEM-1]); - FOR(i = L_Q_MEM-1; i >= 2; i--) - { - sQsubfr[i] = sQsubfr[1]; - move16(); - } - sQsubfr[1] = tmp; - move16(); - sQsubfr[0] = tmp; - move16(); - } - ELSE - { - set16_fx(sQsubfr, tmp, L_Q_MEM); - } - } - sQsubfr[0] = tmp; - move16(); - - /*---------------------------------------------- - * rescale excitation and associated memories - *----------------------------------------------*/ - - tmp = sub(new_Q, *sQ_exc); - - IF (tmp != 0) - { - - Scale_sig(exc-L_EXC_MEM_DEC, add(L_EXC_MEM_DEC, lg), tmp); - IF(last_exc_dct_in != NULL) - { - Scale_sig(last_exc_dct_in, L_FRAME, tmp); - } - IF(bwe_exc != NULL) - { - Scale_sig(bwe_exc-PIT16k_MAX*2, add(PIT16k_MAX*2, lg32), tmp); - } - IF(exc2 != NULL) - { - Scale_sig(exc2, i_subfr, tmp); - } - IF(dct_post_old_exc_fx != NULL) - { - Scale_sig(dct_post_old_exc_fx, DCT_L_POST-OFFSET2, tmp); - } - } - - /* scaling factor of excitation (-1..12) */ - *sQ_exc = new_Q; - move16(); - - return tmp; -} - -/*-------------------------------------------------------------------* - * Rescale_mem: - * - * this function should be called after excitation update (4 subfr) and before frame synthesis - * Rescale excitation related memories - *-------------------------------------------------------------------*/ -void Rescale_mem( - const Word16 Q_exc, /* i : current excitation scaling (>=0) */ - Word16 *prev_Q_syn, /* i/o : scaling factor of previous frame */ - Word16 *Q_syn, /* i/o : scaling factor of frame */ - Word16 *mem_syn2, /* i/o : modified synthesis memory */ - Word16 *mem_syn_clas_estim_fx, /* i/o : old 12k8 core memory for classification */ - const Word16 MaxScaling, /* i: Minimal difference between excitation scaling and synthesis scaling */ - Word16 *mem_deemph, /* i/o: speech deemph filter memory */ - Word16 *pst_old_syn, /* i/o: psfiler */ - Word16 *pst_mem_deemp_err, /* i/o: psfiler */ - Word16 *mem_agc, - PFSTAT *pf_stat, /* i/o: All memories related to NB post filter */ - const Word16 Vad_flag, - const Word16 Cna_flag, - const Word16 *tmp_buffer /* tmp_buffer in Q-1 */ -) -{ - Word16 exp_scale, new_Q, tmp, i; - - /*-------------------------------------------------------------------* - * find scaling of synthesis (based on min of current frame and last frame) - * scaling factor of synthesis (-1..6) - *-------------------------------------------------------------------*/ - new_Q = sub(Q_exc, MaxScaling); - tmp = 1; - move16(); - IF(tmp_buffer != NULL) - { - /* use the temporary synthesis in Q-1 to estimate the scaling */ - FOR (i = 0; i < L_FRAME; i++) - { - tmp = s_max(abs_s(tmp_buffer[i]), tmp); - } - /* we add Q_syn which represents the actual scaling of the memories prev_Q_syn represents the last potential scaling */ - tmp = sub(add(norm_s(tmp), -1), 3); /* -2 ... 12 */ - } - ELSE - { - FOR (i = 0; i < M; i++) - { - tmp = s_max(abs_s(mem_syn2[i]), tmp); - tmp = s_max(abs_s(pst_old_syn[i]), tmp); - tmp = s_max(abs_s(mem_syn_clas_estim_fx[i]), tmp); - } - FOR (; i < L_SUBFR; i++) - { - tmp = s_max(abs_s(pst_old_syn[i]), tmp); - tmp = s_max(abs_s(mem_syn_clas_estim_fx[i]), tmp); - } - FOR (; i < L_SYN_MEM_CLAS_ESTIM; i++) - { - tmp = s_max(abs_s(mem_syn_clas_estim_fx[i]), tmp); - tmp = s_max(abs_s(pst_old_syn[i]), tmp); - } - FOR (; i < NBPSF_PIT_MAX; i++) - { - tmp = s_max(abs_s(pst_old_syn[i]), tmp); - } - /* we add Q_syn which represents the actual scaling of the memories prev_Q_syn represents the last potential scaling */ - tmp = sub(add(norm_s(tmp), *Q_syn), 2); /* -2 ... 12 */ - } - - - IF(Vad_flag != 0) - { - new_Q = s_min(sub(Q_exc,2), tmp); - } - ELSE IF(Cna_flag != 0) - { - new_Q = s_min(Q_exc, sub(tmp, 2)); - } - ELSE - { - new_Q = s_min(Q_exc, tmp); - } - new_Q = s_min(new_Q, 12); /* */ - new_Q = s_max(new_Q, -1); /* */ - - /*#define REMOVE_SYNTHESIS_PER_FRAME_SCALING */ - tmp = s_min(new_Q, *prev_Q_syn); - *prev_Q_syn = new_Q; - move16(); - - exp_scale = sub(tmp, *Q_syn); - *Q_syn = tmp; - move16(); - - /* rescale synthesis memory (mem_syn2) */ - Scale_sig(mem_syn2, M, exp_scale); - Scale_sig(mem_syn_clas_estim_fx, L_SYN_MEM_CLAS_ESTIM, exp_scale); - /*Scale_sig(core_old_syn, L_SYN_MEM, exp_scale);*/ - Scale_sig(mem_deemph, 1, exp_scale); - Scale_sig(pst_old_syn, NBPSF_PIT_MAX, exp_scale); - Scale_sig(pst_mem_deemp_err, 1, exp_scale); - Scale_sig(pf_stat->mem_pf_in, L_SUBFR, exp_scale); /* NB post_filter mem */ - Scale_sig(pf_stat->mem_res2, DECMEM_RES2, exp_scale); /* NB post_filter mem */ - Scale_sig(pf_stat->mem_stp, L_SUBFR, exp_scale); /* NB post_filter mem */ - Scale_sig(mem_agc, 1, exp_scale); /* NB post_filter mem */ - return; -} - -/*-------------------------------------------------------------------* - * Scale_sig32 - * Note: In order to save complexity, call function only, if exp0 != 0 - * Up/down scale a 32 bits vector - *-------------------------------------------------------------------*/ -void scale_sig32( - Word32 x[], /* i/o: signal to scale Qx */ - const Word16 lg, /* i : size of x[] Q0 */ - const Word16 exp0 /* i : exponent: x = round(x << exp) Qx exp */ -) -{ - Word16 i; - - FOR (i = 0; i < lg; i++) - { - /* saturation can occur here */ - x[i] = L_shl(x[i], exp0); - move32(); - } -} - - -/*-------------------------------------------------------------------* - * Rescale_mem: - * - * this function should be called after excitation update (4 subfr) and before frame synthesis - * Rescale excitation related memories - *-------------------------------------------------------------------*/ -Word16 rescale_mem( - const Word16 *Q_exc, /* i : current excitation scaling (>=0) */ - Word16 *prev_Q_syn, /* i/o : scaling factor of previous frame */ - Word16 *Q_syn, /* i/o : scaling factor of frame */ - Word16 *mem_syn2, /* i/o : modified synthesis memory */ - Word16 *syn, /* i/o : synthesis to rescale Q_syn */ - Word16 mem_len, /* i : lenght of modified synthesis memory */ - Word16 i_subfr /* i : subframe number */ -) -{ - Word16 exp_scale, new_Q, tmp; - Word16 i, max16, max_scale; - - max16 = 0; - move16(); - FOR (i = 0; i < mem_len; i++ ) - { - max16 = s_max(max16, abs_s(mem_syn2[i])); - } - IF( syn != NULL ) - { - FOR (i = 0; i < i_subfr; i++ ) - { - max16 = s_max(max16, abs_s(syn[i])); - } - } - max_scale = 15; - move16(); - IF(max16 > 0) - { - max_scale = add(norm_s(max16), -3); - } - - /*-------------------------------------------------------------------* - * find scaling of synthesis (based on min of current frame and last frame) - * scaling factor of synthesis (-1..6) - *-------------------------------------------------------------------*/ - new_Q = sub(*Q_exc, 3); - new_Q = s_max(new_Q, -1); - - tmp = add(max_scale, *Q_syn); - if( sub(s_min(new_Q, *prev_Q_syn), tmp) > 0) - { - new_Q = s_max(tmp, -1); - } - - tmp = s_min(new_Q, *prev_Q_syn); - *prev_Q_syn = new_Q; - move16(); - - exp_scale = sub(tmp, *Q_syn); - *Q_syn = tmp; - move16(); - /* rescale synthesis memory (mem_syn2) */ - Scale_sig(mem_syn2, mem_len, exp_scale); - IF(syn != NULL) - { - Scale_sig(syn, i_subfr, exp_scale); - } - - return exp_scale; -} diff --git a/src/libs/libevs/lib_com/stab_est.cpp b/src/libs/libevs/lib_com/stab_est.cpp new file mode 100644 index 00000000..98f04c03 --- /dev/null +++ b/src/libs/libevs/lib_com/stab_est.cpp @@ -0,0 +1,198 @@ +/*==================================================================================== + EVS Codec 3GPP TS26.443 Nov 13, 2018. Version 12.11.0 / 13.7.0 / 14.3.0 / 15.1.0 + ====================================================================================*/ + +#include +#include "options.h" +#include "cnst.h" +#include "rom_com.h" +#include "prot.h" + +/*-------------------------------------------------------------------* + * Local constants + *-------------------------------------------------------------------*/ + +#define BIN_4000 80 /* The frequency bin corresponding to 4kHz */ +#define MAX_SNR1 45.0f +#define INV_MAX_SNR (1.0f / (MAX_SNR1-1.0f)) /* Max. SNR considered for noise subtraction in voiced segments */ +#define MAX_SNR_SNR1 (MAX_SNR1 * INV_MAX_SNR) /* 45 * (1 / (MAX_SNR1-1)) */ +#define MAX_BANDEXC 20 +#define TH_0_MAX (1.5f*3.125f) +#define TH_1_MAX (1.5f*2.8125f) +#define TH_2_MAX (1.5f*2.1875f) +#define TH_3_MAX (1.5f*1.875f) + +#define TH_UP 0.15625f +#define TH_DW 0.15625f +#define NB_TH3_MIN 30 +#define NB_TH1_MIN 30 + +#define MAX_THR 0.92f + +/*------------------------------------------------------------------------* + * stab_est() + * + * Signal stability estimation based on energy variation + *------------------------------------------------------------------------*/ + +short stab_est( + float etot, /* i : Total energy of the current frame */ + float *lt_diff_etot, /* i/o : Long term total energy variation */ + float *mem_etot, /* i/o : Total energy memory */ + short *nb_thr_3, /* i/o : Number of consecutives frames of level 3 */ + short *nb_thr_1, /* i/o : Number of consecutives frames of level 1 */ + float *thresh, /* i/o : Detection thresold */ + short *last_music_flag, /* i/o : Previous music detection ouptut */ + short vad_flag +) +{ + short i, music_flag2; + float mean_diff; + float ftmp_c, fcorr, dev; + + /*------------------------------------------------------------------------* + * Find mean of the past MAX_LT frames energy variation + *------------------------------------------------------------------------*/ + + mean_diff = 0.0f; + for (i = 1; i= 3 + * (last category was "tonal" and the new one is "very tonal") + *--------------------------------------------------------------------*/ + + if ( dev < thresh[3] && *last_music_flag >= 3 ) + { + music_flag2 = 4; + *nb_thr_3 += 1; + *nb_thr_1 = 0; + } + + /*--------------------------------------------------------------------* + * statistical deviation < Thresh2 and last signal category type >= 2 + * (last category was "moderatly tonal" and the new one is a "tonal" ) + *--------------------------------------------------------------------*/ + + else if ( dev < thresh[2] && *last_music_flag >= 2 ) + { + music_flag2 = 3; + *nb_thr_3 += 1; + *nb_thr_1 = 0; + } + + /*--------------------------------------------------------------------* + * statistical deviation < Thresh1 and last signal category type >= 1 + * (last category was "slightly tonal" and the new one is a "moderatly tonal") + *--------------------------------------------------------------------*/ + + else if ( dev < thresh[1] && *last_music_flag >= 1 ) + { + music_flag2 = 2; + } + + /*--------------------------------------------------------------------* + * statistical deviation < Thresh0 + * (last category was "not tonal" and the new one is "slightly tonal") + *--------------------------------------------------------------------*/ + + else if ( dev < thresh[0] ) + { + music_flag2 = 1; + } + + /*--------------------------------------------------------------------* + * statistical deviation > Thresh0 + * (Statistical deviation is high: the new tonal category is not tonal) + *--------------------------------------------------------------------*/ + + else + { + *nb_thr_1 += 1; + *nb_thr_3 = 0; + } + + /*------------------------------------------------------------------------* + * Update the thresholds + *------------------------------------------------------------------------*/ + + if (*nb_thr_3 > NB_TH3_MIN) + { + /* the number of consecutive categories type 3 or 4 (most tonal and tonal) */ + /* is greater than 30 frames ->increase the deviations thresholds to allow more variation */ + thresh[0] += TH_UP; + thresh[1] += TH_UP; + thresh[2] += TH_UP; + thresh[3] += TH_UP; + } + else if (*nb_thr_1 > NB_TH1_MIN) + { + /* the number of consecutive categories type 0 (non tonal frames) */ + /* is greater than 30 frames -> decrease the deviations thresholds to allow less variation */ + thresh[0] -= TH_DW; + thresh[1] -= TH_DW; + thresh[2] -= TH_DW; + thresh[3] -= TH_DW; + } + + /* limitation of the threshold (this local macro stores the highest of the two and it also counts the # of operations) */ + set_max( &thresh[0], TH_0_MIN2 ); + set_max( &thresh[1], TH_1_MIN2 ); + set_max( &thresh[2], TH_2_MIN2 ); + + set_min( &thresh[0], TH_0_MAX ); + set_min( &thresh[1], TH_1_MAX ); + set_min( &thresh[2], TH_2_MAX ); + + set_max( &thresh[3], TH_3_MIN2 ); + set_min( &thresh[3], TH_3_MAX ); + /*------------------------------------------------------------------------* + * Final updates + *------------------------------------------------------------------------*/ + + *last_music_flag = music_flag2; + if ( vad_flag == 0 ) + { + /* overwrite decision in unvoiced frames */ + music_flag2 = 0; + } + + return music_flag2; +} + diff --git a/src/libs/libevs/lib_com/stab_est_fx.cpp b/src/libs/libevs/lib_com/stab_est_fx.cpp deleted file mode 100755 index 756bf2d4..00000000 --- a/src/libs/libevs/lib_com/stab_est_fx.cpp +++ /dev/null @@ -1,245 +0,0 @@ -/*==================================================================================== - EVS Codec 3GPP TS26.442 Apr 03, 2018. Version 12.11.0 / 13.6.0 / 14.2.0 - ====================================================================================*/ - -#include "options.h" /* Compilation switches */ -#include "cnst_fx.h" /* Common constants */ -#include "prot_fx.h" /* Function prototypes */ -#include "stl.h" /* required for wmc_tool */ -#include "basop_mpy.h" - -/*-------------------------------------------------------------------* - * Local constants - *-------------------------------------------------------------------*/ - -#define BIN_4000 80 /* The frequency bin corresponding to 4kHz */ -#define MAX_BANDEXC 20 - -#define NB_TH3_MIN 30 -#define NB_TH1_MIN 30 - -#define TH_0_MAX_FX 9600 /* Q11 -> 1.5*3.125 */ -#define TH_1_MAX_FX 8640 /* Q11 -> 1.5*2.8125 */ -#define TH_2_MAX_FX 6720 /* Q11 -> 1.5*2.1875 */ -#define TH_3_MAX_FX 5760 /* Q11 -> 1.5*1.875 */ - -#define TH_UP_FX 320 /* Q11 -> 0.15625 */ -#define TH_DW_FX 320 /* Q11 -> 0.15625 */ - -/*------------------------------------------------------------------------* - * stab_est() - * - * Signal stability estimation based on energy variation - *------------------------------------------------------------------------*/ - -Word16 stab_est_fx( - Word16 etot, /* i : Total energy of the current frame */ - Word16 *lt_diff_etot, /* i/o : Long term total energy variation */ - Word16 *mem_etot, /* i/o : Total energy memory */ - Word16 *nb_thr_3, /* i/o : Number of consecutives frames of level 3 */ - Word16 *nb_thr_1, /* i/o : Number of consecutives frames of level 1 */ - Word16 *thresh, /* i/o : Detection thresold */ - Word16 *last_music_flag,/* i/o : Previous music detection ouptut */ - Word16 vad_flag -) -{ - Word16 i, music_flag2, tmp16, exp1, exp2; - Word16 mean_diff; - Word16 dev; - Word32 L_tmp; - - /*------------------------------------------------------------------------* - * Find mean of the past MAX_LT frames energy variation - *------------------------------------------------------------------------*/ - - L_tmp = L_deposit_l(0); - FOR (i = 1; i 1/25 (1/(MAX_LT-15))*/ - - exp1 = norm_l(L_tmp); - L_tmp = L_shl(L_tmp, exp1); - tmp16 = round_fx(L_tmp); - - exp2 = sub(31, exp1); - L_tmp = Isqrt_lc(L_tmp, &exp2); - L_tmp = Mpy_32_16_1(L_tmp, tmp16); /* we now have sqrt(L_corr) Q24 (8+16)*/ - exp2 = sub(31-15, sub(exp1, exp2)); /* for Q8 (because of -8^2 from Etot)*/ - - L_tmp = L_shl(L_tmp, exp2); /* Q8 + Q16*/ - dev = extract_h(L_shl(L_tmp, 3)); /* Q(24+3-16) -> Q11 */ - - /*------------------------------------------------------------------------* - * State machine to decide level of inter-harmonic noise reduction and - * (only if this frame is GOOD or if we are already far from NB_BFI_THR) - * (if music_flag2 is 0, the spectral modification is deactivated, otherwise, it is activated) - *------------------------------------------------------------------------*/ - - music_flag2 = 0; - move16();/* deactivate spectral modification (if music_flag2 != 0 is activated) */ - test(); - /*--------------------------------------------------------------------* - * statistical deviation < thresh3 and last signal category type >= 3 - * (last category was "tonal" and the new one is "very tonal") - *--------------------------------------------------------------------*/ - test(); - test(); - test(); - IF ((sub(dev, thresh[3])< 0 ) && (sub(*last_music_flag,3) >= 0) ) - { - music_flag2 = 4; - move16(); - *nb_thr_3 += 1; - move16(); - *nb_thr_1 = 0; - move16(); - } - - /*--------------------------------------------------------------------* - * statistical deviation < thresh2 and last signal category type >= 2 - * (last category was "moderatly tonal" and the new one is a "tonal" ) - *--------------------------------------------------------------------*/ - ELSE IF ((sub(dev, thresh[2])< 0 ) && (sub(*last_music_flag,2) >= 0) ) - { - music_flag2 = 3; - move16(); - *nb_thr_3 += 1; - move16(); - *nb_thr_1 = 0; - move16(); - } - - /*--------------------------------------------------------------------* - * statistical deviation < thresh1 and last signal category type >= 1 - * (last category was "slightly tonal" and the new one is a "moderatly tonal") - *--------------------------------------------------------------------*/ - ELSE IF ((sub(dev, thresh[1])< 0 ) && (sub(*last_music_flag,1) >= 0) ) - { - music_flag2 = 2; - move16(); - } - - /*--------------------------------------------------------------------* - * statistical deviation < thresh0 - * (last category was "not tonal" and the new one is "slightly tonal") - *--------------------------------------------------------------------*/ - ELSE IF ((sub(dev, thresh[0]) < 0 ) ) - { - music_flag2 = 1; - move16();/* [2000, 4000] Hz */ - } - - /*--------------------------------------------------------------------* - * statistical deviation > thresh0 - * (Statistical deviation is high: the new tonal category is not tonal) - *--------------------------------------------------------------------*/ - ELSE - { - *nb_thr_1 = add(*nb_thr_1,1); - *nb_thr_3 = 0; - move16(); - - } - - /*------------------------------------------------------------------------* - * Update the thresholds - *------------------------------------------------------------------------*/ - IF (sub(*nb_thr_3,NB_TH3_MIN) > 0) - { - - /* the number of consecutive categories type 3 or 4 (most tonal and tonal) */ - /* is greater than 30 frames ->increase the deviations thresholds to allow more variation */ - thresh[0] = add(thresh[0], TH_UP_FX); - move16(); /*Q11 */ - thresh[1] = add(thresh[1], TH_UP_FX); - move16(); - thresh[2] = add(thresh[2], TH_UP_FX); - move16(); - thresh[3] = add(thresh[3], TH_UP_FX); - move16(); - - } - ELSE IF (sub(*nb_thr_1,NB_TH1_MIN) > 0) - { - /* the number of consecutive categories type 0 (non tonal frames) */ - /* is greater than 30 frames -> decrease the deviations thresholds to allow less variation */ - thresh[0] = sub(thresh[0], TH_DW_FX); - move16(); /*Q11 */ - thresh[1] = sub(thresh[1], TH_DW_FX); - move16(); - thresh[2] = sub(thresh[2], TH_DW_FX); - move16(); - thresh[3] = sub(thresh[3], TH_DW_FX); - move16(); - } - - /* limitation of the threshold (this local macro stores the highest of the two and it also - counts the # of operations) */ - - move16(); - move16(); - move16(); - thresh[0] = s_max(thresh[0], TH_0_MIN2_FX); - thresh[1] = s_max(thresh[1], TH_1_MIN2_FX); - thresh[2] = s_max(thresh[2], TH_2_MIN2_FX); - - move16(); - move16(); - move16(); - thresh[0] = s_min(thresh[0], TH_0_MAX_FX); - thresh[1] = s_min(thresh[1], TH_1_MAX_FX); - thresh[2] = s_min(thresh[2], TH_2_MAX_FX); - move16(); - move16(); - thresh[3] = s_max(thresh[3], TH_3_MIN2_FX); - thresh[3] = s_min(thresh[3], TH_3_MAX_FX); - /*------------------------------------------------------------------------* - * Final update - *------------------------------------------------------------------------*/ - - *last_music_flag = music_flag2; - move16(); - if (vad_flag == 0) - { - - music_flag2 = 0; - move16(); - } - - return music_flag2; -} diff --git a/src/libs/libevs/lib_com/stat_com.h b/src/libs/libevs/lib_com/stat_com.h old mode 100755 new mode 100644 index 3fc6598a..e70d2d52 --- a/src/libs/libevs/lib_com/stat_com.h +++ b/src/libs/libevs/lib_com/stat_com.h @@ -1,78 +1,80 @@ /*==================================================================================== - EVS Codec 3GPP TS26.442 Apr 03, 2018. Version 12.11.0 / 13.6.0 / 14.2.0 + EVS Codec 3GPP TS26.443 Nov 13, 2018. Version 12.11.0 / 13.7.0 / 14.3.0 / 15.1.0 ====================================================================================*/ + #ifndef STAT_COM_H #define STAT_COM_H +#include +#include +#include #include "options.h" -#include "basop_util.h" -#include "cnst_fx.h" +#include "typedef.h" +#include "cnst.h" + /*----------------------------------------------------------------------------------* * Declaration of structures *----------------------------------------------------------------------------------*/ -/* Forward declaration of Decoder_State_fx */ -struct Decoder_State_fx; +/* Forward declaration of Decoder_State */ +struct Decoder_State; -/*-----------------------------------------------------------* - * EV-VBR NB postfilter static variables - *-----------------------------------------------------------*/ +/* NB postfilter static variables */ typedef struct { - Word16 on; /* On/off flag */ - Word16 reset; /* reset flag */ - Word16 mem_pf_in[L_SUBFR]; /* Input memory */ - Word16 mem_stp[L_SUBFR]; /* 1/A(gamma1) memory */ - Word16 mem_res2[DECMEM_RES2]; /* A(gamma2) residual */ - Word16 mem_zero[M]; /* null memory to compute i.r. of A(gamma2)/A(gamma1) */ - Word16 gain_prec; /* for gain adjustment */ + int on; /* On/off flag */ + short reset; /* reset flag */ + float mem_pf_in[L_SUBFR]; /* Input memory */ + float mem_stp[L_SUBFR]; /* 1/A(gamma1) memory */ + float mem_res2[DECMEM_RES2]; /* A(gamma2) residual */ + float mem_zero[M]; /* null memory to compute i.r. of A(gamma2)/A(gamma1) */ + float gain_prec; /* for gain adjustment */ } PFSTAT; typedef struct { - Word16 a_fx[MAXLAG_WI]; - Word16 b_fx[MAXLAG_WI]; - Word16 lag_fx; - Word16 nH_fx; - Word16 nH_4kHz_fx; - Word16 upper_cut_off_freq_of_interest_fx; - Word16 upper_cut_off_freq_fx; - Word16 Fs_fx; - Word16 Q; -} DTFS_STRUCTURE_FX; + float a[MAXLAG_WI]; + float b[MAXLAG_WI]; + int lag; + int nH; + int nH_4kHz; + float upper_cut_off_freq_of_interest; + float upper_cut_off_freq; + float Fs; +} DTFS_STRUCTURE; typedef struct { - Word16 lead_sign_ind; - UWord32 index, size; - Word16 dim, k_val; -} PvqEntry_fx; + short lead_sign_ind; + unsigned int index, size; + short dim, k_val; +} PvqEntry; typedef struct { - UWord8 buf[MAX_SIZEBUF_PBITSTREAM]; - Word16 curPos; - Word32 numByte; - Word32 numbits; - Word32 maxBytes; -} BITSTREAM_FX, *PBITSTREAM_FX; + unsigned char buf[MAX_SIZEBUF_PBITSTREAM]; + signed char curPos; + unsigned int numByte; + unsigned int numbits; + unsigned int maxBytes; +} BITSTREAM, *PBITSTREAM; typedef struct { - PBITSTREAM_FX bsInst; + PBITSTREAM bsInst; - Word32 low; - Word32 high; + unsigned int low; + unsigned int high; - Word32 value; - Word16 bits_to_follow; + unsigned int value; + int bits_to_follow; - Word32 num_bits; - Word32 max_bits; + int num_bits; + int max_bits; -} ARCODEC_FX, *PARCODEC_FX; +} ARCODEC, *PARCODEC; /*---------------------------------------------------------------* * Encoder/Decoder Static RAM * @@ -80,51 +82,52 @@ typedef struct typedef struct { /*Coding mode info*/ - Word16 mode_index; + short mode_index; /*LPC info*/ - Word8 midLpc; /*Flag for using or not mid LPC for the current frame*/ - Word8 midLpc_enable; /*Flag enabling or not the mid LPC for the current mode_index*/ + short midLpc; /*Flag for using or not mid LPC for the current frame*/ + short midLpc_enable; /*Flag enabling or not the mid LPC for the current mode*/ /*ICB flags*/ - Word8 pre_emphasis; - Word8 pitch_sharpening; /*Flag for triggering pitch sharpening*/ - Word8 phase_scrambling; /*Flag for triggering phase scrambling*/ - Word16 formant_enh; /*Flag for triggering formant enhancement: Q15 representing 0...1.0f */ - Word8 formant_tilt; + short pre_emphasis; /*Flag for triggering pre-emphasis*/ + short pitch_sharpening; /*Flag for triggering pitch sharpening*/ + short phase_scrambling; /*Flag for triggering phase scrambling*/ + short formant_enh; /*Flag for triggering formant enhancement*/ + short formant_tilt; /*Flag for triggering formant tile*/ - Word8 voice_tilt; /*Flag for triggering new voice factor tilt*/ + short voice_tilt; /*Flag for triggering new voice factor tilt*/ - Word16 formant_enh_num; - Word16 formant_enh_den; + float formant_enh_num; + float formant_enh_den; - Word16 bpf_mode; + short bpf_mode; - Word16 nrg_mode; - Word16 nrg_bits; + short nrg_mode; + short nrg_bits; - Word16 ltp_mode; - Word16 ltp_bits; + short ltp_mode; + short ltp_bits; - Word16 ltf_mode; - Word16 ltf_bits; + short ltf_mode; + short ltf_bits; - Word16 gains_mode[NB_SUBFR16k]; + short gains_mode[NB_SUBFR16k]; + + int fixed_cdk_index[NB_SUBFR16k]; - Word16 fixed_cdk_index[NB_SUBFR16k]; } ACELP_config; -/*tns_base.h*/ +/* tns_base.h */ /** TNS configuration. * Use InitTnsConfiguration to initialize it. */ typedef struct { - Word16 maxOrder; + unsigned char maxOrder; /** Maximum number of filters. */ - Word16 nMaxFilters; + unsigned char nMaxFilters; /** Parameters for each TNS filter */ struct TnsParameters const * pTnsParameters; @@ -133,7 +136,7 @@ typedef struct * Upper border for the first filter is nsbBorders-1. * Upper borders for other filters is the lower border of previous filter. */ - Word16 iFilterBorders[TNS_MAX_NUM_OF_FILTERS+1]; + short iFilterBorders[TNS_MAX_NUM_OF_FILTERS+1]; } STnsConfig; @@ -143,15 +146,15 @@ typedef struct typedef struct { /** Number of subbands covered by the filter. */ - Word16 spectrumLength; + int spectrumLength; /** Filter order. */ - Word16 order; + int order; /** Quantized filter coefficients. */ - Word16 coefIndex[TNS_MAX_FILTER_ORDER]; + int coefIndex[TNS_MAX_FILTER_ORDER]; /** Prediction gain. The ratio of a signal and TNS residual energy. */ - Word16 predictionGain; /* exponent = PRED_GAIN_E */ + float predictionGain; /** Average squared filter coefficient. */ - Word16 avgSqrCoef; /* exponent = 0 */ + float avgSqrCoef; } STnsFilter; /** TNS data. @@ -160,7 +163,7 @@ typedef struct typedef struct { /** Number of active filters. */ - Word16 nFilters; + int nFilters; /** Active filters. */ STnsFilter filter[TNS_MAX_NUM_OF_FILTERS]; } STnsData; @@ -174,213 +177,208 @@ typedef enum typedef struct { /* TCX mdct window */ - const PWord16 *tcx_mdct_window; - const PWord16 *tcx_mdct_window_half; - const PWord16 *tcx_mdct_window_minimum; - const PWord16 *tcx_mdct_window_trans; - Word16 tcx_aldo_window_1[L_FRAME32k*9/32]; - PWord16 tcx_aldo_window_1_trunc[L_FRAME32k*7/32]; - PWord16 tcx_aldo_window_2[L_FRAME32k*7/32]; - Word16 last_aldo; + float tcx_mdct_window[L_MDCT_OVLP_MAX]; /* Sine window for OL decision and DTX transitions*/ + float tcx_aldo_window_1[L_FRAME_MAX]; /* ALDO window long slope */ + float tcx_aldo_window_2[L_MDCT_OVLP_MAX]; /* ALDO window short slope */ + float *tcx_aldo_window_1_trunc; /* ALDO window truncated long slope */ - Word16 tcx5Size; /* Size of the TCX5 spectrum. Always 5ms. */ + short last_aldo; + float tcx_mdct_window_half[L_MDCT_HALF_OVLP_MAX]; + float tcx_mdct_window_minimum[L_MDCT_MIN_OVLP_MAX]; + float tcx_mdct_window_trans[L_MDCT_TRANS_OVLP_MAX]; /* transition window for ACELP->TCX */ - Word16 tcx_mdct_window_length; - Word16 tcx_mdct_window_half_length; /*length of the "half" overlap window*/ - Word16 tcx_mdct_window_min_length; /* length of the "minimum" overlap */ - Word16 tcx_mdct_window_trans_length; /* length of the ACELP->TCX overlap */ + int tcx5Size; /* Size of the TCX5 spectrum. Always 5ms. */ - Word16 tcx_mdct_window_delay; /*length of window delay*/ + short tcx_curr_overlap_mode; /* window overlap of current frame (0: full, 2: none, or 3: half) */ + short tcx_last_overlap_mode; /* previous window overlap, i.e. left-side overlap of current frame */ - Word16 tcx_offset; - Word16 tcx_mdct_window_length_old; /*for keeping old value for sample rate switching */ + int tcx_mdct_window_length; /* length of overlap-add region*/ + int tcx_mdct_window_half_length; /* length of the "half" overlap */ + int tcx_mdct_window_min_length; /* length of the "minimum" overlap */ + int tcx_mdct_window_trans_length; /* length of the ACELP->TCX overlap */ - /* TCX mdct window */ - const PWord16 *tcx_mdct_windowFB; - const PWord16 *tcx_mdct_window_halfFB; - const PWord16 *tcx_mdct_window_minimumFB; - const PWord16 *tcx_mdct_window_transFB; - Word16 tcx_aldo_window_1_FB[L_FRAME_MAX*9/32]; - PWord16 tcx_aldo_window_1_FB_trunc[L_FRAME_MAX*7/32]; - PWord16 tcx_aldo_window_2_FB[L_FRAME_MAX*7/32]; + int tcx_mdct_window_delay; /*length of window delay*/ + int tcx_offset; /* Offset of the folding point relative to the end of the previous synthetised frame */ + int tcx_mdct_window_length_old; /*for keeping old value for sample rate switching */ + float tcx_mdct_windowFB[L_MDCT_OVLP_MAX]; + float tcx_aldo_window_1_FB[L_FRAME_MAX]; /* ALDO window long slope */ + float tcx_aldo_window_2_FB[L_MDCT_OVLP_MAX]; /* ALDO window short slope */ + float *tcx_aldo_window_1_FB_trunc; /* ALDO window truncated long slope */ - Word16 tcx5SizeFB; /* Size of the TCX5 spectrum. Always 5ms. */ + float tcx_mdct_window_halfFB[L_MDCT_HALF_OVLP_MAX]; + float tcx_mdct_window_minimumFB[L_MDCT_MIN_OVLP_MAX]; + float tcx_mdct_window_transFB[L_MDCT_TRANS_OVLP_MAX]; /* transition window for ACELP->TCX */ - Word16 tcx_mdct_window_lengthFB; - Word16 tcx_mdct_window_half_lengthFB; /*length of the "half" overlap window*/ - Word16 tcx_mdct_window_min_lengthFB; /* length of the "minimum" overlap */ - Word16 tcx_mdct_window_trans_lengthFB; /* length of the ACELP->TCX overlap */ + int tcx5SizeFB; /* Size of the TCX5 spectrum. Always 5ms. */ - Word16 tcx_mdct_window_delayFB; /*length of window delay*/ - Word16 tcx_offsetFB; + int tcx_mdct_window_lengthFB; /*length of window, length of overlap-add region*/ + int tcx_mdct_window_half_lengthFB; /*length of the "half" overlap window*/ + int tcx_mdct_window_min_lengthFB; /*length of the "minimum" overlap window*/ + int tcx_mdct_window_trans_lengthFB; /* length of the ACELP->TCX overlap */ - Word16 tcx_coded_lines; /* max number of coded lines, depending on bandwidth mode */ + int tcx_mdct_window_delayFB; /*length of window delay*/ + int tcx_offsetFB; - Word16 tcx_curr_overlap_mode; /* window overlap of current frame (0: full, 2: none, or 3: half) */ - Word16 tcx_last_overlap_mode; /* previous window overlap, i.e. left-side overlap of current frame */ + int tcx_coded_lines; /* max number of coded lines, depending on bandwidth mode */ /* FAC window */ - Word16 lfacNext; - Word16 lfacNextFB; + int lfacNext; + int lfacNextFB; /* TNS */ - Word8 fIsTNSAllowed; + int fIsTNSAllowed; STnsConfig tnsConfig[2][2]; STnsConfig const * pCurrentTnsConfig; /*Quantization*/ - Word16 sq_rounding; /*set the sq deadzone (no deadzone=0.5f)*/ - Word8 tcxRateLoopOpt; + float sq_rounding; /*set the sq deadzone (no deadzone=0.5f)*/ + short tcxRateLoopOpt; /*Bandwidth*/ - Word16 preemph_fac; /*preemphasis factor*/ - Word16 bandwidth; + float preemph_fac; /*preemphasis factor*/ + float bandwidth; /* Context HM - Residual Quantization*/ - Word8 ctx_hm; /*Flag for enabling Context HM*/ - Word8 resq; /*Flag for enabling Residual Quantization*/ - Word16 coder_type; /*INACTIVE, UNVOICED,VOICED,GENERIC*/ + short ctx_hm; /*Flag for enabling Context HM*/ + short resq; /*Flag for enabling Residual Quantization*/ + int coder_type; /*GC,VC,UC*/ - Word16 na_scale; + float na_scale; + + float SFM2; - Word32 SFM2; } TCX_config; /* prot.h */ typedef struct { - Word16 bits; /* bits per subframe */ - Word16 nbiter; /* number of iterations */ - Word16 alp; /* initial energy of all fixed pulses, exponent = ALP_E */ - Word8 nb_pulse; /* number of pulses */ - Word8 fixedpulses; /* number of pulses whose position is determined from correlation and not by iteration */ - Word8 nbpos[13]; /* number of positions tried in the pair-wise search */ - Word8 codetrackpos; /* ordering of tracks -mode */ + int bits; /* bits per subframe */ + int nbiter; /* number of iterations */ + float alp; /* initial energy of all fixed pulses */ + int nb_pulse; /* number of pulses */ + int fixedpulses; /* number of pulses whose position is determined from correlation and not by iteration */ + int nbpos[13]; /* number of positions tried in the pair-wise search */ + enum TRACKPOS codetrackpos; /* ordering of tracks -mode */ } PulseConfig; -/* fd_cng_common.h */ -/* CLDFB-based CNG setup */ +/* ari.h */ typedef struct { - Word16 fftlen; /* FFT length */ - Word16 stopFFTbin; /* Number of FFT bins to be actually processed */ - Word16 numPartitions; /* Number of partitions */ - const Word16* sidPartitions; /* Upper boundaries for grouping the (sub)bands into partitions when transmitting SID frames (define as NULL pointer to avoid grouping) */ + int low,high,vobf; +} Tastat; - Word16 numShapingPartitions; /* Number of partitions */ - const Word16* shapingPartitions; /* Upper boundaries for grouping the (sub)bands into partitions for shaping at the decoder (define as NULL pointer to avoid grouping) */ +/* FD-based CNG setup */ +typedef struct +{ + int fftlen; /* FFT length */ + int stopFFTbin; /* Number of FFT bins to be actually processed */ + int numPartitions; /* Number of partitions */ + const int* sidPartitions; /* Upper boundaries for grouping the (sub)bands into partitions when transmitting SID frames (define as NULL pointer to avoid grouping) */ + + int numShapingPartitions; /* Number of partitions */ + const int* shapingPartitions;/* Upper boundaries for grouping the (sub)bands into partitions for shaping at the decoder (define as NULL pointer to avoid grouping) */ } FD_CNG_SETUP; + /* Scale setup */ typedef struct { - Word32 bitrateFrom; - Word32 bitrateTo; + int bwmode; - Word16 scale; + int bitrateFrom; + int bitrateTo; - Word8 bwmode; + float scale; } SCALE_SETUP; + /* Arrays and variables common to encoder and decoder */ typedef struct { FD_CNG_SETUP FdCngSetup; - Word16 numSlots; /* Number of time slots in CLDFB matrix */ - Word16 regularStopBand;/* Number of CLDFB bands to be considered */ + int numSlots; /* Number of time slots in CLDFB matrix */ + int regularStopBand;/* Number of CLDFB bands to be considered */ - Word16 numCoreBands; /* Number of core bands to be decomposed into FFT subbands */ - Word16 stopBand; /* Total number of (sub)bands to be considered */ - Word16 startBand; /* First (sub)band to be considered */ - Word16 stopFFTbin; /* Total number of FFT subbands */ - Word16 frameSize; /* Frame size in samples */ - Word16 fftlen; /* FFT length used for the decomposition */ - Word16 fftlenShift; - Word16 fftlenFac; + int numCoreBands; /* Number of core bands to be decomposed into FFT subbands */ + int stopBand; /* Total number of (sub)bands to be considered */ + int startBand; /* First (sub)band to be considered */ + int stopFFTbin; /* Total number of FFT subbands */ + int frameSize; /* Frame size in samples */ + int fftlen; /* FFT length used for the decomposition */ - Word16 timeDomainBuffer[L_FRAME16k]; + float timeDomainBuffer[L_FRAME16k]; + float fftBuffer[FFTLEN]; + float olapBufferAna[FFTLEN]; + float olapBufferSynth[FFTLEN]; + float olapBufferSynth2[FFTLEN]; + const float * olapWinAna; + const float * olapWinSyn; + const float * fftSineTab; - Word32 fftBuffer[FFTLEN]; - Word16 *olapBufferAna; /* points to FD_CNG_DEC->olapBufferAna[320] in case of decoder */ - Word16 olapBufferSynth[FFTLEN]; - Word16 *olapBufferSynth2; /* points to FD_CNG_DEC->olapBufferSynth2[FFTLEN] in case of decoder */ - const PWord16 * olapWinAna; - const PWord16 * olapWinSyn; + float msM_win; + float msM_subwin; - Word16 msM_win; - Word16 msM_subwin; - Word16 msFrCnt_init_counter; /* Frame counter at initialization */ - Word16 init_old; + short msFrCnt_init_counter; /* Frame counter at initialization */ + short msFrCnt_init_thresh; + float init_old; + int msFrCnt; /* Frame counter */ + float msAlphaCor[2]; /* Correction factor (smoothed) */ + float msSlope[2]; + float msQeqInvAv[2]; + int msMinBufferPtr; - Word16 msFrCnt_init_thresh; + float msPsdSum[2]; + float msPeriodogSum[2]; - Word16 msFrCnt; /* Frame counter */ - Word32 msAlphaCor[2]; /* Correction factor (smoothed) */ - Word16 msSlope[2]; - Word32 msQeqInvAv[2]; - Word16 msQeqInvAv_exp[2]; - Word16 msMinBufferPtr; + short offsetflag; - Word32 msPsdSum[2]; - Word32 msPeriodogSum[2]; - Word16 msPeriodogSum_exp[2]; + float periodog[PERIODOGLEN]; /* Periodogram */ + float cngNoiseLevel[FFTCLDFBLEN]; /* Noise level applied for the CNG in each (sub)band */ + short seed; /* Seed memory (for random function) */ - Word16 offsetflag; + int npart; /* Number of partitions */ + int midband[NPART]; /* Central band of each partition */ + int nFFTpart; /* Number of hybrid spectral partitions */ + int part[NPART]; /* Partition upper boundaries (band indices starting from 0) */ + float psize[NPART]; /* Partition sizes */ + float psize_inv[NPART]; /* Inverse of partition sizes */ + float FFTscalingFactor; /* Squared ratio between core signal analysis FFT and noise estimator FFT */ + float scalingFactor; + int nCLDFBpart; /* Number of CLDFB spectral partitions */ + int CLDFBpart[NPARTCLDFB]; /* CLDFB Partition upper boundaries (band indices starting from 0 above the core coder bands) */ + float CLDFBpsize_inv[NPARTCLDFB];/* Inverse of CLDFB partition sizes */ - Word32 periodog[PERIODOGLEN]; /* Periodogram */ - Word16 periodog_exp; - Word16 exp_cldfb_periodog; + short inactive_frame_counter; + short sid_frame_counter; + short active_frame_counter; - Word32 cngNoiseLevel[FFTCLDFBLEN]; /* Noise level applied for the CNG in each (sub)band */ - Word16 cngNoiseLevelExp; - Word16 seed; /* Seed memory (for random function) */ + float sidNoiseEst[NPART]; /* Transmitted noise level */ - Word16 npart; /* Number of partitions */ - Word16 midband[NPART]; /* Central band of each partition */ - Word16 nFFTpart; /* Number of hybrid spectral partitions */ - Word16 part[NPART]; /* Partition upper boundaries (band indices starting from 0) */ - Word16 psize[NPART]; /* Partition sizes */ - Word16 psize_norm[NPART]; /* Partition sizes, fractional variable */ - Word16 psize_norm_exp; /* Partition sizes exponent for fractional variable */ - Word16 psize_inv[NPART]; /* Inverse of partition sizes */ - Word16 FFTscalingFactor; /* Squared ratio between core signal analysis FFT and noise estimator FFT */ - Word16 scalingFactor; - Word16 invScalingFactor; - Word16 nCLDFBpart; /* Number of CLDFB spectral partitions */ - Word16 CLDFBpart[NPARTCLDFB]; /* CLDFB Partition upper boundaries (band indices starting from 0 above the core coder bands) */ - Word16 CLDFBpsize_inv[NPARTCLDFB];/* Inverse of CLDFB partition sizes */ + int frame_type_previous; - Word16 inactive_frame_counter; - Word16 sid_frame_counter; - Word16 active_frame_counter; + float A_cng[17]; + float exc_cng[L_FRAME16k]; - Word32 sidNoiseEst[NPART]; /* Transmitted noise level */ - Word16 sidNoiseEstExp; + int CngBitrate; + short CngBandwidth; - Word16 frame_type_previous; + short flag_noisy_speech; + float likelihood_noisy_speech; - Word16 A_cng[M+1]; - Word16 exc_cng[L_FRAME16k]; - - Word32 CngBitrate; - Word16 CngBandwidth; - - Word16 flag_noisy_speech; - Word16 likelihood_noisy_speech; } FD_CNG_COM; typedef FD_CNG_COM *HANDLE_FD_CNG_COM; -/*parameter_bitmaping.h*/ +/* parameter_bitmapping.h */ /** Function that gets specific value from p. * @param p Pointer to a variable that can also be structure or array. * @param index Index of a variable when p is an array, otherwise 0. * @param pValue Pointer to the value. * @return Substructure associated with this value or NULL if there is none. */ -typedef void const * (* TGetParamValue)(void const * p, Word16 index, Word16 * pValue); +typedef void const * (* TGetParamValue)(void const * p, int index, int * pValue); /** Function that puts specific value to p. * @param p Pointer to a variable that can also be structure or array. @@ -388,29 +386,29 @@ typedef void const * (* TGetParamValue)(void const * p, Word16 index, Word16 * p * @param value The value. * @return Substructure associated with this value or NULL if there is none. */ -typedef void * (* TSetParamValue)(void * p, Word16 index, Word16 value); +typedef void * (* TSetParamValue)(void * p, int index, int value); /** Function that return required number of bits for a value when it is coded. * @param value The value. * @param index Index of a variable when it is an element of an array, otherwise 0. * @return Number of bits required to code the value. */ -typedef Word16 (* TGetNumberOfBits)(Word16 value, Word16 index); +typedef int (* TGetNumberOfBits)(int value, int index); /** Function that encodes a value. * @param value The value. * @param index Index of a variable when it is an element of an array, otherwise 0. * @return Coded value. */ -typedef Word16 (* TEncodeValue)(Word16 value, Word16 index); +typedef int (* TEncodeValue)(int value, int index); /** Function that decodes a value. - * @param st Decoder state. + * @param bitstream Bitstream containing a coded value. * @param index Index of a variable when it is an element of an array, otherwise 0. * @param pValue A pointer where the decoded value should be stored. * @return Number of bits read from the bitstream. */ -typedef Word16 (* TDecodeValue)(struct Decoder_State_fx *st, Word16 index, Word16 * pValue); +typedef int (* TDecodeValue)(struct Decoder_State *st, int index, int * pValue); /** Structure that defines mapping between a parameter and a bistream. */ typedef struct ParamBitMap @@ -418,7 +416,7 @@ typedef struct ParamBitMap /** Number of bits in a bitstream required for the parameter. * If nBits is equal to 0 then GetNumberOfBits is used. */ - Word16 nBits; + int nBits; /** Function to get the number of bits required for a value of this parameter. * If nBits != 0 it is not used and can be set to NULL. * If fZeroAllowed == 0 then GetNumberOfBits must take care of this. @@ -430,7 +428,7 @@ typedef struct ParamBitMap * must take care of this flag - there is no additional processing in parameter bitmapping. * If EncodeValue is equal to NULL, then the encode/decode function takes care of this. */ - Word8 fZeroAllowed; + int fZeroAllowed; /** Function to get the value of this parameter. * The function returns a pointer to be used in functions in pSubParamBitMap. * If the function returns NULL then the same pointer as for the current @@ -471,19 +469,19 @@ typedef struct ParamBitMap typedef struct ParamsBitMap { /** Number of parameters in params. */ - Word16 nParams; + int nParams; /** Definition of the mapping for each parameter. */ - ParamBitMap params[NPARAMS_MAX]; + ParamBitMap params[10]; } ParamsBitMap; -/*tns_tables.h*/ +/* tns_tables.h */ struct TnsParameters { /* Parameters for each TNS filter */ - Word16 startLineFrequency; /* Starting lower frequency of the TNS filter [20..16000] */ - Word16 nSubdivisions; /* Number of spectrum subdivisions in which the filter operates [1..8) */ - Word16 minPredictionGain; /* Minimum prediction gain required to turn on the TNS filter. Exponent = PRED_GAIN_E */ - Word16 minAvgSqrCoef; /* Minimum average square of coefficients required to turn on the TNS filter. Exponent = 0 */ + int startLineFrequency; /* Starting lower frequency of the TNS filter [20..16000] */ + int nSubdivisions; /* Number of spectrum subdivisions in which the filter operates [1..8) */ + float minPredictionGain; /* Minimum prediction gain required to turn on the TNS filter */ + float minAvgSqrCoef; /* Minimum average square of coefficients required to turn on the TNS filter */ }; /**********************************************/ @@ -492,21 +490,21 @@ struct TnsParameters typedef struct { - Word8 value; - Word16 code; - Word8 nBits; + unsigned char value; + unsigned short int code; + unsigned char nBits; } Coding; /* Scale TCX setup */ typedef struct { - Word16 bwmode; + int bwmode; - Word32 bitrateFrom; - Word32 bitrateTo; + int bitrateFrom; + int bitrateTo; - Word16 scale; + float scale; } SCALE_TCX_SETUP; @@ -514,93 +512,72 @@ typedef struct /* glob_con.h */ typedef struct { - Word16 frame_bits; /*Bits per frame*/ - Word16 frame_net_bits; /*Net Bits per frame*/ - Word8 transmission_bits; /*max=1*/ - Word8 transmission_mode[2]; /*SID,VBR/CBR*/ - Word8 bandwidth_bits; /*max=2*/ - Word8 bandwidth_min; /*first valid bandwidth (NB,WB,SWB,FB)*/ - Word8 bandwidth_max; /*last valid bandwidth (NB,WB,SWB,FB)*/ - Word8 reserved_bits; /*max=1*/ + unsigned short frame_bits; /*Bits per frame*/ + unsigned short frame_net_bits; /*Net Bits per frame*/ + unsigned char transmission_bits; /*max=1*/ + unsigned char transmission_mode[2]; /*SID,VBR/CBR*/ + unsigned char bandwidth_bits; /*max=2*/ + unsigned char bandwidth_min; /*first valid bandwidth (NB,WB,SWB,FB)*/ + unsigned char bandwidth_max; /*last valid bandwidth (NB,WB,SWB,FB)*/ + unsigned char reserved_bits; /*max=1*/ } FrameSizeParams; typedef struct { - Word16 lb_scale; /*!< Scale of low band area */ - Word16 lb_scale16; /*!< Scale of low band area */ - Word16 ov_lb_scale; /*!< Scale of adjusted overlap low band area */ - Word16 hb_scale; /*!< Scale of high band area */ - Word16 ov_hb_scale; /*!< Scale of adjusted overlap high band area */ -} CLDFB_SCALE_FACTOR; + int no_channels; + int no_col; + int p_filter_length; + CLDFB_TYPE type; -struct CLDFB_FILTER_BANK -{ - const Word16 *p_filter; /*!< Pointer to filter coefficients */ + const float *p_filter; - Word16 *FilterStates; /*!< Pointer to buffer of filter states */ - Word16 FilterStates_e[CLDFB_NO_COL_MAX+9]; /*!< Filter states time slot exponents */ - Word16 FilterStates_eg; /*!< Filter states current exponent */ + /* rotation vectors */ + const float *rot_vec_ana_re; + const float *rot_vec_ana_im; + const float *rot_vec_syn_re; + const float *rot_vec_syn_im; - Word16 p_filter_length; /*!< Size of prototype filter. */ - const Word16 *rRotVctr; /*!< Modulation tables. */ - const Word16 *iRotVctr; - Word16 filterScale; /*!< filter scale */ + /* memory helper states */ + float *memory; + unsigned int memory_length; - Word16 synGain; /*!< gain for synthesis filterbank */ + /* main filter state */ + float *cldfb_state; - Word16 no_channels; /*!< Total number of channels (subbands) */ - Word16 no_col; /*!< Number of time slots */ - Word16 lsb; /*!< Top of low subbands */ - Word16 usb; /*!< Top of high subbands */ - Word16 zeros; /*!< number of zeros in filter coefficients */ + /* other parameters */ + int bandsToZero; /* bands not synthesized */ + int nab; /* number of active bands */ + float scale; /* scaling of frequency domain */ +} +CLDFB_FILTER_BANK; - Word16 anaScalefactor; /*!< Scale factor of analysis cldfb */ - Word16 synScalefactor; /*!< Scale factor of synthesis cldfb */ - Word16 outScalefactor; /*!< Scale factor of output data (syn only) */ - - Word16 synFilterHeadroom; /*!< Headroom for states in synthesis cldfb filterbank */ - - UWord16 flags; /*!< flags */ - - Word16 bandsToZero; /*!< additional bands which are zeroed in inverse modulation */ - - Word16 filtermode; - - Word16 type; - Word16 *memory; - Word16 memory_length; - Word16 scale; -}; - -typedef struct CLDFB_FILTER_BANK *HANDLE_CLDFB_FILTER_BANK; +typedef CLDFB_FILTER_BANK *HANDLE_CLDFB_FILTER_BANK; typedef struct { - Word16 pGainTemp_m[CLDFB_NO_COL_MAX]; - Word16 pGainTemp_e[CLDFB_NO_COL_MAX]; - Word16 loBuffer[CLDFB_NO_COL_MAX + MAX_TEC_SMOOTHING_DEG]; + float pGainTemp[CLDFB_NO_COL_MAX]; + float loBuffer[CLDFB_NO_COL_MAX + MAX_TEC_SMOOTHING_DEG]; - Word16 cldfbExp; - Word16 lastCldfbExp; -} TEMPORAL_ENVELOPE_CODING_DECODER_FX; -typedef TEMPORAL_ENVELOPE_CODING_DECODER_FX* HANDLE_TEC_DEC_FX; +} TEMPORAL_ENVELOPE_CODING_DECODER; +typedef TEMPORAL_ENVELOPE_CODING_DECODER* HANDLE_TEC_DEC; typedef struct { - Word16 loBuffer[CLDFB_NO_COL_MAX + MAX_TEC_SMOOTHING_DEG + DELAY_TEMP_ENV_BUFF_TEC]; - Word16 loTempEnv[CLDFB_NO_COL_MAX]; - Word16 loTempEnv_ns[CLDFB_NO_COL_MAX]; - Word16 hiTempEnv[CLDFB_NO_COL_MAX + DELAY_TEMP_ENV_BUFF_TEC + EXT_DELAY_HI_TEMP_ENV]; - Word16 tranFlag; - Word16 corrFlag; -} TEMPORAL_ENVELOPE_CODING_ENCODER_FX; -typedef TEMPORAL_ENVELOPE_CODING_ENCODER_FX* HANDLE_TEC_ENC_FX; + float loBuffer[CLDFB_NO_COL_MAX + MAX_TEC_SMOOTHING_DEG + DELAY_TEMP_ENV_BUFF_TEC]; + float loTempEnv[CLDFB_NO_COL_MAX]; + float loTempEnv_ns[CLDFB_NO_COL_MAX]; + float hiTempEnv[CLDFB_NO_COL_MAX + DELAY_TEMP_ENV_BUFF_TEC + EXT_DELAY_HI_TEMP_ENV]; + int tranFlag; + int corrFlag; +} TEMPORAL_ENVELOPE_CODING_ENCODER; +typedef TEMPORAL_ENVELOPE_CODING_ENCODER* HANDLE_TEC_ENC; + typedef enum { FRAME_0 = 0, FRAME_2 = 40, - FRAME_2_4 = 48, + FRAME_2_4 = 48, FRAME_4 = 80, FRAME_5_6 = 112, FRAME_7_2 = 144, @@ -619,58 +596,48 @@ typedef enum /*---------------------------------------------------------------* * IGF * *---------------------------------------------------------------*/ + typedef struct igf_grid_struct { - Word16 swb_offset[IGF_MAX_SFB]; - Word16 swb_offset_len; - Word16 startFrequency; - Word16 stopFrequency; - Word16 startLine; - Word16 stopLine; - Word16 startSfb; /* 15Q0, startSfb = [0, 11], IGF start sfb */ - Word16 stopSfb; /* 15Q0, stopSfb = [0, 22], IGF stop sfb */ - Word16 sfbWrap[IGF_MAX_TILES+1]; - Word16 sbWrap[IGF_MAX_TILES]; - Word16 nTiles; /* 15Q0, nTiles = [1, 4], number of tiles */ - Word16 minSrcSubband; - Word16 minSrcFrequency; - Word16 tile[IGF_MAX_TILES]; - Word16 infoIsRefined; - Word16 infoGranuleLen; /* 15Q0, infoGranuleLen = [0, 1200], core coder granule length */ - Word16 infoTransFac; /* 1Q14 */ - Word16 whiteningThreshold[2][IGF_MAX_TILES]; /* 2Q13 */ - Word16 gFactor; /* 1Q14 */ - Word16 fFactor; /* 1Q14 */ - Word16 lFactor; /* 1Q14 */ + int swb_offset[IGF_MAX_SFB]; + int swb_offset_len; + int startFrequency; + int stopFrequency; + int startLine; + int stopLine; + int startSfb; + int stopSfb; + int sfbWrap[IGF_MAX_TILES+1]; + int sbWrap[IGF_MAX_TILES]; + int nTiles; + int minSrcSubband; + int minSrcFrequency; + int tile[IGF_MAX_TILES]; + int infoIsRefined; + int infoGranuleLen; + float infoTransFac; + float whiteningThreshold[2][IGF_MAX_TILES]; + float gFactor; + float fFactor; + float lFactor; } IGF_GRID, *H_IGF_GRID; typedef struct IGF_INFO_struct { - Word16 nfSeed; - Word32 sampleRate; - Word16 frameLength; - Word16 maxHopsize; + short nfSeed; + int sampleRate; + int frameLength; + int maxHopsize; IGF_GRID grid[IGF_NOF_GRIDS]; - Word16 bitRateIndex; + short bitRateIndex; } IGF_INFO, *H_IGF_INFO; typedef struct { - Word16 *indexBuffer; - Word16 *peakIndices, *holeIndices; - Word16 numPeakIndices, numHoleIndices; + int *indexBuffer; + int *peakIndices, *holeIndices; + int numPeakIndices, numHoleIndices; } CONTEXT_HM_CONFIG; -/* Returns: index of next coefficient */ -typedef Word16 (*get_next_coeff_function)( - Word16 ii[2], /* i/o: coefficient indexes */ - Word16 *pp, /* o : peak(1)/hole(0) indicator */ - Word16 *idx, /* o : index in unmapped domain */ - CONTEXT_HM_CONFIG *hm_cfg /* i : HM configuration */ -); - -/*CLDFB-VAD*/ - - #endif diff --git a/src/libs/libevs/lib_com/stat_noise_uv_mod.cpp b/src/libs/libevs/lib_com/stat_noise_uv_mod.cpp new file mode 100644 index 00000000..9a30ff75 --- /dev/null +++ b/src/libs/libevs/lib_com/stat_noise_uv_mod.cpp @@ -0,0 +1,200 @@ +/*==================================================================================== + EVS Codec 3GPP TS26.443 Nov 13, 2018. Version 12.11.0 / 13.7.0 / 14.3.0 / 15.1.0 + ====================================================================================*/ + +#include +#include "options.h" +#include "prot.h" + + +/*---------------------------------------------------------------------* + * Local constants + *---------------------------------------------------------------------*/ + +#define TILT_COMP_LIM 0.75f + +/*---------------------------------------------------------* + * Local functions + *---------------------------------------------------------*/ + +static float calc_tilt(const float *x, const short len); + +/*--------------------------------------------------------------------* + * stat_noise_uv_mod() + * + * Modifies excitation signal in stationary noise segments + *--------------------------------------------------------------------*/ + +void stat_noise_uv_mod( + const short coder_type, /* i : coder type */ + float noisiness, /* i : noisiness parameter */ + const float *lsp_old, /* i : old LSP vector at 4th sfr */ + const float *lsp_new, /* i : LSP vector at 4th sfr */ + const float *lsp_mid, /* i : LSP vector at 2nd sfr */ + float *Aq, /* o : A(z) quantized for the 4 subframes */ + float *exc2, /* o : excitation buffer */ + const short bfi, /* i : bad frame indicator */ + float *ge_sm, /* i/o: smoothed excitation gain */ + short *uv_count, /* i/o: unvoiced counter */ + short *act_count, /* i/o: activation counter */ + float lspold_s[], /* i/o: old LSP */ + short *noimix_seed, /* i/o: mixture seed */ + float *st_min_alpha, /* i/o: minimum alpha */ + float *exc_pe, /* i/o: memory of the preemphasis filter */ + const long bitrate, /* i : core bitrate */ + const short bwidth /* i : Sampling rate */ +) +{ + short i, k; + short i_subfr; + float exctilt; + float vare, ge, randval; + float alpha, min_alpha; + float lspnew_s[M], oldlsp_mix[M], midlsp_mix[M], newlsp_mix[M]; + float beta; + float noimix_fac; + + alpha = 1.0f; + min_alpha = 0.5f; + + /*---------------------------------------------------------* + * Update minimum mixing factor alpha + *---------------------------------------------------------*/ + + /* Activate modifications for WB/SWB <= 9.6kbps for NB only at 9.6kbps */ + if ( coder_type == INACTIVE && ( bitrate == ACELP_9k60 || (bitrate < ACELP_9k60 && bwidth > NB) ) ) + { + if ( !bfi ) + { + min_alpha = max( noisiness/31.0f * 0.5f + 0.5f, *st_min_alpha - 0.05f ); + *st_min_alpha = min_alpha; + } + else + { + min_alpha = *st_min_alpha; + } + } + + /*---------------------------------------------------------* + * Mix excitation signal with random noise + *---------------------------------------------------------*/ + + /* Activate modifications for WB/SWB <= 9.6kbps for NB only at 9.6kbps */ + if ( coder_type == INACTIVE && (bitrate == ACELP_9k60 || (bitrate < ACELP_9k60 && bwidth > NB ) ) ) + { + /* preemphasize the excitation signal with its tilt */ + if( min_alpha < TILT_COMP_LIM ) + { + for (i_subfr=0; i_subfr FULL_NG) + { + *uv_count = FULL_NG; + } + + alpha = 1 + ((float)*uv_count - START_NG)/((float)FULL_NG - START_NG) * (min_alpha - 1.0f); + } + + /* calculate lowpass-filtered excitation gain */ + vare = 0.01f; + for (i=0; i 3) + { + *act_count = 3; + *uv_count = 0; + } + } + + return; +} + +/*---------------------------------------------------------------------------* + * calc_tilt() + * + * Calculate spectral tilt by means of 1st-order LP analysis + *---------------------------------------------------------------------------*/ + +static float calc_tilt( + const float *x, /* i : Signal input */ + const short len /* i : lenght */ +) +{ + int i; + float r0, r1; + + r0 = 0; + r1 = 0; + + for ( i=0; i x + Noimix_fract * x */ - Word16 i_subfr; - Word16 i, k; - - /* Work variables for div and sqrt */ - Word16 tmp_nom,tmp_den,tmp_shift,tmp_res; - Word16 Qdiff,Q_local; /* new Q to be used for states Exc_pe and Ge_sm, and Exc2_local */ - Word32 L_tmp_res,L_tmp, L_tmp3,L_Ge; - - Word16 En_shift,Tmp; - Word16 Exc2_local[L_FRAME]; /* local_copy in scaled Q_local*/ - - /*---------------------------------------------------------* - * Init local variables - *---------------------------------------------------------*/ - alpha = 32767; - move16(); - min_alpha = 16384; - move16(); - - test(); - test(); - test(); - IF (sub(coder_type,INACTIVE) == 0 && ( L_sub(bitrate,ACELP_9k60) == 0 || (L_sub(bitrate,ACELP_9k60) < 0 && sub(bwidth_fx,NB) > 0) ) ) - { - min_alpha = *st_min_alpha; - move16(); - /*---------------------------------------------------------* - * decode noisiness parameter - *---------------------------------------------------------*/ - IF (bfi == 0) - { - tmp_den = 31; - move16(); - tmp_shift = norm_s(tmp_den); - move16(); - L_tmp_res = L_deposit_h(noisiness); - L_tmp_res = L_shl(L_tmp_res,sub(tmp_shift,1)); - tmp_den = shl(tmp_den,tmp_shift); - move16(); - tmp_res = div_l(L_tmp_res,tmp_den); - move16(); - min_alpha = add(tmp_res, 16384); - move16(); - - /**st_min_alpha = sub(*st_min_alpha, 1638); move16();*/ - min_alpha = s_max(min_alpha, sub(*st_min_alpha, 1638)); - - *st_min_alpha = min_alpha; - move16(); - } - } - - /*---------------------------------------------------------* - * Mix excitation signal with random noise - *---------------------------------------------------------*/ - test(); - test(); - test(); - IF ( sub(coder_type,INACTIVE) == 0 && ( L_sub(bitrate,ACELP_9k60) == 0 || (L_sub(bitrate,ACELP_9k60) < 0 && sub(bwidth_fx,NB) > 0) ) ) - { - /* use a local working copy for scaling and filtering, not needed if input Q-range is fixed */ - Copy(exc2, Exc2_local, L_FRAME); - - /* bound Q for internal use, optimization possible */ - Q_local = s_min(11, s_max(-1, Q_exc)); - /* local excitation Q and incoming excitation Q*/ - Qdiff = sub(Q_local, Q_exc); - /* only shift if incoming Q is outside [11..-1] shift is done in energy calculations aswell */ - Scale_sig(Exc2_local, L_FRAME, Qdiff); - /* current excitation Q and previous stat_noise states Q */ - Qdiff = sub(Q_local, *Q_stat_noise); - - *Q_stat_noise_ge = GE_SHIFT; - move16(); /* assign the fixed Q for Ge_sm */ - - IF (Qdiff != 0) - { - Scale_sig(exc_pe, 1, Qdiff); - } - - En_shift = 0; - move16(); - if (sub(Q_local, 3) > 0) - { - /* increase margin for energy accumulation in calc_tilt and vare accumulation */ - En_shift = sub(Q_local, 3); - } - - IF (sub(min_alpha, TILT_COMP_LIM_FX) < 0) - { - FOR (i_subfr=0; i_subfrge_sm = ISP_SMOOTHING_QUANT_A1 * st->ge_sm + (1.0f-ISP_SMOOTHING_QUANT_A1) * ge */ - - IF ( sub(*uv_count,1) == 0) - { - *ge_sm = L_shr(L_Ge,Q_local); - } - ELSE - { - L_tmp = Mult_32_16(L_Ge,P1); /* 0.1*ge still in Q local */ - L_tmp3 = Mult_32_16(*ge_sm,P9); /* 0.9*ge_sm still in Q_ge */ - - *ge_sm = L_add(L_shr(L_tmp,Q_local),L_tmp3); - move32(); /* addition in Q_ge domain*/ - } - - /*--------------------------------------------------------------------* - * generate mixture of excitation and noise - * float: - * noimix_fac = 1.0f/(float)sqrt(alpha*alpha + (1-alpha)*(1-alpha)) - *--------------------------------------------------------------------*/ - - beta = shl(sub(alpha, 16384), 1); - alpha_m1 = sub(32767, alpha); - L_tmp_res = L_mac(0, alpha, alpha); - L_tmp_res = L_mac(L_tmp_res, alpha_m1, alpha_m1); - tmp_den = round_fx(L_Frac_sqrtQ31(L_tmp_res)); - - tmp_nom = sub(32767, tmp_den); - tmp_shift = norm_s(tmp_den); - tmp_den = shl(tmp_den, tmp_shift); - tmp_res = div_s(tmp_nom, tmp_den); - - Noimix_fract = shr(tmp_res, tmp_shift); /* float value is in range 0.0 to 0.42 */ - - /* L_Ge might be 0 in unvoiced WB */ - L_Ge = L_max(L_Ge, 1); - tmp_shift = norm_l(L_Ge); - tmp_den = extract_h(L_shl(L_Ge, tmp_shift)); /* Q_local+Q_ge+tmp_shift-16 */ - tmp_res = div_s(1<<14, tmp_den); /* 15+14-Q_local-tmp_shift-Q_ge+16 */ - L_tmp_res = Mult_32_16(*ge_sm, tmp_res); /* Q_stat_noise_ge+45-Q_local-Q_ge-tmp_shift-15 */ - L_tmp_res = Mult_32_16(L_tmp_res, sub(32767, beta)); /*30-Q_local-tmp_shift+15-15 */ - L_tmp_res = L_add(L_shl(L_tmp_res, sub(add(Q_local, tmp_shift), 15)), beta); /* Q15 */ - tmp_res = extract_h(L_shl(L_tmp_res, 15)); /* 15+15-16=14 */ - - Noimix_fract = extract_l(Mult_32_16(L_tmp_res, Noimix_fract)); /*15+15-15 */ - - FOR (i=0; ige_sm*Rnd*((1.0f)-alpha) - * flt: exc2[i] = (noimix_fract*exc2[i]+exc2 )* alpha + st->ge_sm*Rnd*((1.0f)-alpha) - * NB: currently uses 32bit accumulation for best low level performance, - * possibly overkill if input is always up-scaled - *--------------------------------------------------------------------*/ - - /* (1-alpha)*(float)sqrt(12.0f) * ((float)own_random(&(st->noimix_seed))/65536.0f) */ - randval = Random(noimix_seed); /* +/-32767 */ - randval = mult_r(28378, randval); /* Q downscaled by 2 bits ends up in Q14 */ /*sqrt(12.0f) in Q13*/ - randval = extract_l(L_shl(Mult_32_16(L_Ge, randval), 1-*Q_stat_noise_ge)); /*Q_local+Q_ge+14-15+1-Q_ge=Q_local */ - - L_tmp = L_mult(Exc2_local[i], alpha); /* Q_local + 16 */ - L_tmp = L_mac(L_tmp, randval, alpha_m1); /* Q_local + 16 */ - L_tmp3 = Mult_32_16(L_tmp, Noimix_fract); /* Q_local+16+15-15 */ - L_tmp = L_add(L_tmp3, L_shl(Mult_32_16(L_tmp, tmp_res), 1)); /* Q_local+16+14-15+1 */ - - Exc2_local[i] = extract_h(L_tmp); /*Q_local */ - } - *Q_stat_noise = Q_local; /* update for next call, routine can only be called once every frame */ - Qdiff = sub(Q_exc, Q_local); /* local excitation and incoming excitation */ - Scale_sig(Exc2_local, L_FRAME, Qdiff); - Copy(Exc2_local, exc2, L_FRAME); - - /*--------------------------------------------------------------------* - * Generate low-pass filtered version of ISP coefficients - *--------------------------------------------------------------------*/ - FOR (k=0; k 0) - { - *act_count = 3; - move16(); - *uv_count = 0; - move16(); - } - } - -} -/*---------------------------------------------------------------------------* - * calc_tilt() - * - * Calculate spectral tilt by means of 1st-order LP analysis - *---------------------------------------------------------------------------*/ - -static Word16 calc_tilt_fx( /* o : Excitation tilt Q15*/ - const Word16 *x, /* i : Signal input */ - const Word16 Q_shift, /* i : input scaling */ - const Word16 len /* i : lenght */ -) -{ - Word16 i; - Word16 tmp_shift; - Word32 L_tmp_res; - Word16 tmp_sign,xi,xi_p1; - Word32 r0, r1; - - r0 = L_deposit_l(0); - r1 = L_deposit_l(0); - xi = shr(x[0], Q_shift); - move16(); - - FOR (i=0; i correlation loop can be optimized */ - r0 = L_mac(r0,xi,xi); - - xi_p1 = shr(x[i+1], Q_shift); - r1 = L_mac(r1, xi, xi_p1); - - xi = xi_p1; - move16(); - } - - if (r0 == 0) - { - r0 = L_shl(327, 16); - } - - tmp_shift = norm_l(r0); - move16(); - r0 = L_shl(r0,tmp_shift); - tmp_sign = 1; - move16(); - if (r1 >= 0) - { - tmp_sign = 0; - move16(); - } - r1 = L_abs(r1); - - L_tmp_res = Div_32(r1,extract_h(r0), extract_l(r0)); - L_tmp_res = L_shl(L_tmp_res, tmp_shift); /*Q31 */ - - if (tmp_sign != 0) - { - L_tmp_res = L_negate(L_tmp_res); /*Q31 */ - } - - return extract_h(L_tmp_res); /*Q15 */ -} - -/*---------------------------------------------------------------------------* - * L_Sqrt_Q0 - * - * Calculate square root from fractional values (Q0 -> Q0) - * Uses 32 bit internal representation for precision - *---------------------------------------------------------------------------*/ -Word32 L_Sqrt_Q0( /* o : Square root of input */ - const Word32 x /* i : Input */ -) -{ - Word32 log2_work; - - Word16 log2_int; - Word16 log2_frac; - - IF (x > 0) - { - log2_int = norm_l(x); - log2_frac = Log2_norm_lc(L_shl(x, log2_int)); - - log2_work = L_mac0(30*32768L, log2_frac, 1); - log2_work = L_msu(log2_work, log2_int, 16384); - log2_frac = L_Extract_lc(log2_work, &log2_int); - - return Pow2(log2_int, log2_frac); - } - return 0; -} - diff --git a/src/libs/libevs/basic_op/control.cpp b/src/libs/libevs/lib_com/stl.h old mode 100755 new mode 100644 similarity index 54% rename from src/libs/libevs/basic_op/control.cpp rename to src/libs/libevs/lib_com/stl.h index ae5d6231..859747e3 --- a/src/libs/libevs/basic_op/control.cpp +++ b/src/libs/libevs/lib_com/stl.h @@ -1,30 +1,38 @@ +/*==================================================================================== + EVS Codec 3GPP TS26.443 Nov 13, 2018. Version 12.11.0 / 13.7.0 / 14.3.0 / 15.1.0 + ====================================================================================*/ /* =========================================================================== - File: CONTROL.C v.2.3 - 30.Nov.2009 + File: STL.H v.2.3 - 30.Nov.2009 =========================================================================== - ITU-T STL BASIC OPERATORS + ITU-T STL BASIC OPERATORS - CONTROL FLOW OPERATOR INTERNAL VARIABLE DECLARATIONS + MAIN HEADER FILE History: 07 Nov 04 v2.0 Incorporation of new 32-bit / 40-bit / control - operators for the ITU-T Standard Tool Library as + operators for the ITU-T Standard Tool Library as described in Geneva, 20-30 January 2004 WP 3/16 Q10/16 TD 11 document and subsequent discussions on the wp3audio@yahoogroups.com email reflector. March 06 v2.1 Changed to improve portability. - + ============================================================================ */ -#include "stl.h" -#if WMOPS -int funcId_where_last_call_to_else_occurred; -long funcid_total_wmops_at_last_call_to_else; -int call_occurred = 1; -#endif +#ifndef _STL_H +#define _STL_H + +#include "typedef.h" +#include "basop32.h" +#include "move.h" +#include "control.h" +#include "enh1632.h" +#include "enh40.h" + +#endif /* ifndef _STL_H */ /* end of file */ diff --git a/src/libs/libevs/lib_com/swb_bwe_com.cpp b/src/libs/libevs/lib_com/swb_bwe_com.cpp new file mode 100644 index 00000000..5ccefadb --- /dev/null +++ b/src/libs/libevs/lib_com/swb_bwe_com.cpp @@ -0,0 +1,1518 @@ +/*==================================================================================== + EVS Codec 3GPP TS26.443 Nov 13, 2018. Version 12.11.0 / 13.7.0 / 14.3.0 / 15.1.0 + ====================================================================================*/ + +#include +#include +#include +#include "options.h" +#include "cnst.h" +#include "prot.h" +#include "rom_com.h" + +/*-------------------------------------------------------------------* + * WB_BWE_gain_pred() + * + * predict WB frequency envelopes for 0b WB BWE + *-------------------------------------------------------------------*/ + +short WB_BWE_gain_pred( + float *WB_fenv, /* o : WB frequency envelopes */ + const float *core_dec_freq, /* i : Frequency domain core decoded signal */ + const short coder_type, /* i : coding type */ + short prev_coder_type, /* i : coding type of last frame */ + float prev_WB_fenv, /* i : envelope for last frame */ + float *voice_factors, /* i : voicing factors */ + const float pitch_buf[], /* i : pitch buffer */ + long last_core_brate, /* i : previous frame core bitrate */ + float last_wb_bwe_ener /* i : previous frame wb bwe signal energy */ + ,short last_extl /* i : extl. layer for last frame */ + ,float tilt +) +{ + float enerL, alfa = 1.0f; + short n_freq, mode; + short ener_var_flag = 0; + float voice_factor, pitch; + short env_var_flag = 0; + + mode = NORMAL; + + enerL = EPSILON; + for (n_freq = 128; n_freq<192; n_freq++) + { + enerL += core_dec_freq[n_freq] * core_dec_freq[n_freq]; + } + WB_fenv[0] = EPSILON; + for (n_freq = 192; n_freq<224; n_freq++) + { + WB_fenv[0] += core_dec_freq[n_freq] * core_dec_freq[n_freq]; + } + + WB_fenv[1] = EPSILON; + for (n_freq = 224; n_freq<256; n_freq++) + { + WB_fenv[1] += core_dec_freq[n_freq] * core_dec_freq[n_freq]; + } + + voice_factor = sum_f( voice_factors, 4 ); + pitch = sum_f( pitch_buf, 4 ) + EPSILON; + + if(enerL < 16.0f*max(WB_fenv[0], WB_fenv[1]) && pitch < 308) + { + ener_var_flag = 1; + } + + if(WB_fenv[0] > 2.0f*WB_fenv[1]) + { + alfa = max(2.0f*WB_fenv[1]/WB_fenv[0], 0.1f); + WB_fenv[0] *= alfa; + } + else if (2.0f*WB_fenv[0] < WB_fenv[1] && coder_type != UNVOICED) + { + alfa = max(2.0f*WB_fenv[0]/WB_fenv[1], 0.1f); + WB_fenv[1] *= alfa; + } + + WB_fenv[0] = (float)sqrt((WB_fenv[0]+WB_fenv[1])/64); + + if(coder_type != AUDIO && coder_type != UNVOICED && ener_var_flag == 0) + { + WB_fenv[0] *= 1.5f; + } + + if( coder_type != TRANSITION && coder_type != AUDIO && coder_type != UNVOICED && sqrt(enerL) > 40.0f*WB_fenv[0] && alfa > 0.9f && + !(coder_type == prev_coder_type && WB_fenv[0] > prev_WB_fenv) ) + { + WB_fenv[0] *= min((float)(0.025f*sqrt(enerL)/WB_fenv[0]), 4.0f); + + if( WB_fenv[0] > prev_WB_fenv ) + { + WB_fenv[0] = 0.3f*WB_fenv[0] + 0.7f*prev_WB_fenv; + } + } + + alfa = min(1.5f, max(0.5f, 77.0f*voice_factor/pitch)); + if( sqrt(enerL) > 64.0f*alfa*WB_fenv[0] && 3.0f*WB_fenv[0]*WB_fenv[0] < sqrt(enerL) && prev_coder_type != UNVOICED ) + { + env_var_flag = 1; + WB_fenv[0] *= min((float)(0.015625f*sqrt(enerL)/WB_fenv[0]), 4.0f); + + if( WB_fenv[0] > prev_WB_fenv ) + { + WB_fenv[0] = 0.3f*WB_fenv[0] + 0.7f*prev_WB_fenv; + } + } + + if( coder_type == UNVOICED || prev_coder_type == UNVOICED ) + { + WB_fenv[0] *= 0.5f; + } + + if( coder_type != AUDIO ) + { + WB_fenv[0] /= max(1.2f * voice_factor, 1.0f); + WB_fenv[0] *= min(2.0f, max(0.125f, pitch/400.0f)); + } + + if( last_core_brate > ACELP_8k00 && WB_fenv[0] > last_wb_bwe_ener ) + { + WB_fenv[0] = 0.9f*last_wb_bwe_ener + 0.1f*WB_fenv[0]; + } + + if(last_extl != WB_BWE && (tilt < 8.f)) + { + WB_fenv[0] *= min(0.5, 16.0f*tilt); + } + + if(env_var_flag == 1) + { + WB_fenv[1] = 1.5f*WB_fenv[0]; + WB_fenv[0] *= 0.75f; + } + else + { + WB_fenv[1] = WB_fenv[0]; + } + + if(coder_type == UNVOICED || prev_coder_type == UNVOICED) + { + WB_fenv[1] *= 0.5f; + } + + return (mode); +} + +/*-------------------------------------------------------------------* + * calc_normal_length() + * + *-------------------------------------------------------------------*/ + +void calc_normal_length( + const short core, /* i : core */ + const float *sp, /* i : input signal */ + const short mode, /* i : input mode */ + const short extl, /* i : extension layer */ + short *L_swb_norm, /* o : normalize length */ + short *prev_L_swb_norm /*i/o : last normalize length */ +) +{ + short i, n_freq, n_band, THRES; + const float *pit; + float peak, mean, mag; + short L_swb_norm_trans, L_swb_norm_norm, L_swb_norm_harm, L_swb_norm_cur; + short N; + + if( core == HQ_CORE || extl == SWB_BWE || extl == FB_BWE ) + { + THRES = 8; + } + else + { + THRES = 4; + } + + if( core == HQ_CORE && (mode == HQ_HARMONIC || mode == HQ_HVQ) ) + { + N = 13; + } + else + { + N = 16; + } + + n_band = 0; + pit = sp; + for(i = 0; i < N; i ++) + { + peak = 0.0f; + mean = 0; + + for(n_freq = 0; n_freq < 16; n_freq ++) + { + mag = (float) fabs(*pit); + if (mag > peak) + { + peak = mag; + } + mean += mag; + pit ++; + } + + if((15+THRES)*peak > THRES*mean && peak>10) + { + n_band += 1; + } + } + + if( core == ACELP_CORE ) + { + L_swb_norm_trans = (short)(4 + 0.25f*n_band); + L_swb_norm_norm = (short)(8 + 0.5f*n_band); + L_swb_norm_harm = max((short)(32 + 2.0f*n_band), 24); + + if( mode == HARMONIC ) + { + L_swb_norm_cur = L_swb_norm_harm; + } + else if( mode == NORMAL ) + { + L_swb_norm_cur = L_swb_norm_norm; + } + else + { + L_swb_norm_cur = L_swb_norm_trans; + } + + *L_swb_norm = (short)(0.5f*L_swb_norm_cur + 0.5f* (*prev_L_swb_norm)); + *prev_L_swb_norm = L_swb_norm_cur; + } + else + { + if( mode == HQ_HARMONIC || mode == HQ_HVQ ) + { + L_swb_norm_cur = (short)( 32 + 2.5f*n_band); + } + else + { + L_swb_norm_cur = (short)(8 + 0.5f*n_band); + } + + *L_swb_norm = (short)(0.1f*L_swb_norm_cur + 0.9f* (*prev_L_swb_norm) + 0.5f); + *prev_L_swb_norm = L_swb_norm_cur; + } + + return; +} +/*-------------------------------------------------------------------* +* calc_tilt_bwe() +* +* calculate tilt parameter +*-------------------------------------------------------------------*/ + +void calc_tilt_bwe( + const float *sp, /* i : input signal */ + float *tilt, /* o : signal tilt */ + const short N /* i : signal length */ +) +{ + short i; + float r0, r1; + + r0 = EPSILON; + for(i=0; i 0) + { + WB_signal[n_freq] *= (0.55f - weight); + } + WB_signal[n_freq] *= signum[n_freq]; + } + } + + /* Normalize with envelope */ + for (n_freq = swb_bwe_subband[0]; n_freq prev_WB_fenv[0] ) + { + alfa = 0.4f; + beta = 2.5f; + } + else + { + alfa = 0.6f; + beta = 1.67f; + } + + if( coder_type == GENERIC || ((EnergyL > 0.5f*(*prev_Energy) && EnergyL < 2.0f*(*prev_Energy) && *prev_flag == 1)) ) + { + WB_fenv[0] *= 0.5f; + WB_fenv[1] *= 0.5f; + flag = 1; + } + } + if( (mode == HARMONIC && WB_fenv[1] < 0.25f*WB_fenv[0]) || mode == NORMAL ) + { + if( last_extl == WB_BWE && ( (prev_coder_type == AUDIO && coder_type != AUDIO) || (prev_coder_type != AUDIO && coder_type == AUDIO)) && total_brate <= ACELP_8k00 ) + { + if( WB_fenv[0] > prev_WB_fenv[0] ) + { + wfenv[0] = 0.3f*WB_fenv[0] + 0.7f*prev_WB_fenv[0]; + wfenv[1] = 0.3f*WB_fenv[1] + 0.7f*prev_WB_fenv[1]; + } + else + { + wfenv[0] = 0.5f*WB_fenv[0] + 0.5f*prev_WB_fenv[0]; + wfenv[1] = 0.4f*WB_fenv[1] + 0.4f*prev_WB_fenv[1]; + } + } + else if ( last_extl == WB_BWE && prev_WB_fenv[0]*EnergyL < WB_fenv[0]*(*prev_Energy) && WB_fenv[0] > prev_WB_fenv[0] && coder_type != AUDIO && coder_type != UNVOICED && total_brate <= ACELP_8k00) + { + wfenv[0] = 0.3f*WB_fenv[0] + 0.7f*prev_WB_fenv[0]; + wfenv[1] = 0.3f*WB_fenv[1] + 0.7f*prev_WB_fenv[1]; + } + else if ( last_extl == WB_BWE && EnergyL > alfa*(*prev_Energy) && EnergyL < beta*(*prev_Energy) && prev_coder_type != UNVOICED ) + { + wfenv[0] = 0.5f*(WB_fenv[0] + prev_WB_fenv[0]); + wfenv[1] = 0.5f*(WB_fenv[1] + prev_WB_fenv[1]); + } + else + { + wfenv[0] = WB_fenv[0]; + wfenv[1] = WB_fenv[1]; + } + for (n_freq = swb_bwe_subband[0]; n_freq 0.5f*(*prev_Energy) && EnergyL < 2.0f*(*prev_Energy)) + { + wfenv[0] = 0.25f*wfenv[0] + 0.375f*(prev_WB_fenv[0] + prev_WB_fenv[1]); + } + for (n_freq = swb_bwe_subband[0]; n_freq 8.0f*SWB_fenv[0]) + { + fenvL = SWB_fenv[0]; + } + calc_normal_length( ACELP_CORE, core_dec_freq, mode, extl, &L_swb_norm, prev_L_swb_norm ); + + if( mode == TRANSIENT ) + { + Energy = 0.0f; + for(n_band = 0; n_band < SWB_FENV_TRANS; n_band++) + { + Energy += SWB_fenv[n_band]*SWB_fenv[n_band]; + } + Energy /= SWB_FENV_TRANS; + + /* Reconstruct excitation from LF signal */ + mvr2r(&core_dec_freq[112], &SWB_signal[240+st_offset], 128); + mvr2r(&core_dec_freq[112], &SWB_signal[368+st_offset], 128); + mvr2r(&core_dec_freq[176], &SWB_signal[496+st_offset], 64); + + /* calculate envelope */ + calc_norm_envelop(SWB_signal, envelope, L_swb_norm, SWB_flength, st_offset); + + /* Normalize with envelope */ + for (n_freq = swb_bwe_trans_subband[0]+st_offset; n_freq EnergyL || (tilt_nb > 7 && Energy > 0.5f*EnergyL) || tilt_nb > 12) && Energy > 75 && fenvL > 25)) + { + for (n_freq=swb_bwe_subband[0]+st_offset; n_freq SWB_fenv[n_band+1] ) + { + SWB_fenv[n_band+1] *= (0.8f+0.015f*n_band); + } + else if( SWB_fenv[n_band+1] * 0.9f > SWB_fenv[n_band] ) + { + SWB_fenv[n_band] *= (0.8f+0.015f*n_band); + } + } + + mvr2r(&core_dec_freq[112], &SWB_signal[240+st_offset], 128); + mvr2r(&core_dec_freq[112], &SWB_signal[368+st_offset], 128); + mvr2r(&core_dec_freq[176], &SWB_signal[496+st_offset], 64); + + tmp1 = (float)(fabs(SWB_signal[368+st_offset]) + fabs(SWB_signal[369+st_offset])) + EPSILON; + tmp2 = (float)(fabs(SWB_signal[365+st_offset]) + fabs(SWB_signal[366+st_offset])) + EPSILON; + pit1 = &SWB_signal[368+st_offset]; + + tmp3 = tmp2/tmp1; + if(tmp3 < 0.3) + { + tmp3 = 0.3f; + } + + while(tmp3 < 1) + { + *pit1++ *= tmp3; + tmp3 += 0.1f; + } + + pit1 = &SWB_signal[367+st_offset]; + tmp3 = tmp1/tmp2; + + if( tmp3 > 5 ) + { + tmp3 = 5; + while( tmp3 > 1 ) + { + *pit1-- *= tmp3; + tmp3 -= 0.5f; + } + } + + tmp1 = (float)(fabs(SWB_signal[496+st_offset]) + fabs(SWB_signal[497+st_offset])) + EPSILON; + tmp2 = (float)(fabs(SWB_signal[492+st_offset]) + fabs(SWB_signal[493+st_offset]) + fabs(SWB_signal[494+st_offset]) + fabs(SWB_signal[495+st_offset])) + EPSILON; + pit1 = &SWB_signal[496+st_offset]; + + tmp3 = tmp2/tmp1; + if( tmp3 < 0.3 ) + { + tmp3 = 0.3f; + } + + while(tmp3 < 1) + { + *pit1++ *= tmp3; + tmp3 += 0.1f; + } + + pit1 = &SWB_signal[495+st_offset]; + + tmp3 = tmp1/tmp2; + tmp3 = 0.5f*tmp3; + tmp4 = 0.05f*tmp3; + + while( tmp3 > 1 ) + { + *pit1-- *= tmp3; + tmp3 -= tmp4; + } + + /* calculate envelope */ + calc_norm_envelop(SWB_signal, envelope, L_swb_norm, SWB_flength, st_offset); + } + } + + /* Normalize with envelope */ + if( *frica_flag == 0 && mode != NOISE ) + { + L = swb_bwe_subband[0]+st_offset; + inv_L_swb_norm = 1.0f/L_swb_norm; + weight = (mode != HARMONIC) ? max(min(3.0f*inv_L_swb_norm, 0.5f), 0.2f) : 0.2f; + weight = 0.4f*weight + 0.6f*(*prev_weight); + for(n_freq = L; n_freq 0) + { + SWB_signal[n_freq] *= (1.2f - weight); + } + SWB_signal[n_freq] *= signum[n_freq]; + } + + for (n_freq = L; n_freq 1.25f*Energy && Energy > 0 ) + { + weight = 0.5f*Energy/(*prev_Energy); + } + else + { + weight = 0.5f; + } + + wfenv = weight*prev_SWB_fenv[0] + (1-weight)*SWB_fenv[0]; + factor = fenvL; + factor1 = (wfenv - fenvL) * 0.125f; + for (n_freq = swb_bwe_subband[0]+st_offset; n_freq < swb_bwe_subband[0]+8+st_offset; n_freq++) + { + SWB_signal[n_freq] *= factor; + factor += factor1; + } + + for(n_band = 0; n_band < 12; n_band++) + { + wfenv = weight*prev_SWB_fenv[n_band+1] + (1-weight)*SWB_fenv[n_band+1]; + factor = SWB_fenv[n_band]; + factor1 = (wfenv - SWB_fenv[n_band]) * smooth_factor[n_band]; + for (; n_freq < swb_bwe_sm_subband[n_band+1]+st_offset; n_freq++) + { + SWB_signal[n_freq] *= factor; + factor += factor1; + } + } + + wfenv = weight*prev_SWB_fenv[13] + (1-weight)*SWB_fenv[13]; + factor = SWB_fenv[12]; + factor1 = (wfenv - SWB_fenv[12]) * smooth_factor[12]; + for ( ; n_freq < swb_bwe_sm_subband[13]+st_offset; n_freq++) + { + SWB_signal[n_freq] *= factor; + factor += factor1; + } + + for(n_band=13; n_band 1.8f*energyL[i] && energyL[i+1] > 50) + { + pos = i+1; + break; + } + } + + if (pos > 0) + { + if(pos < 3) + { + pos ++; + } + + energy = EPSILON; + j = L*pos; + for(i=0; i0 ? 1.0f: -1.0f); + } + } + else + { + for ( n_freq = sfidx; n_freq < efidx; n_freq++ ) + { + coeff_out1[n_freq] =coeff_out1[n_freq]*signum[n_freq]; + } + } + + /* normalizing modified low frequency spectrum */ + for( k =0 ; k < nband_lf; ++k ) + { + energy = EPSILON; + for ( i = k*blen+sfidx; i < (k+1)*blen+sfidx; ++i ) + { + energy += coeff_out1[i] * coeff_out1[i]; + } + energy = (float)sqrt(energy/blen); + + for ( i = k*blen+sfidx; i < (k+1)*blen+sfidx; ++i ) + { + coeff_out1[i] /= energy; + } + } + mvr2r(coeff_out1+HQ_GENERIC_OFFSET, &coeff_out[HQ_GENERIC_HIGH0+hq_generic_offset], HQ_GENERIC_LEN0); + mvr2r(coeff_out1+HQ_GENERIC_OFFSET, &coeff_out[HQ_GENERIC_HIGH1+hq_generic_offset], HQ_GENERIC_LEN0); + + if ( hq_generic_offset <= HQ_GENERIC_FOFFSET_24K4 ) + { + mvr2r( &coeff_out1[HQ_GENERIC_LOW0], &coeff_out[HQ_GENERIC_HIGH2+hq_generic_offset], HQ_GENERIC_END_FREQ - HQ_GENERIC_HIGH2 ); + } + + if ( HQ_mode == HQ_GEN_FB ) + { + if ( hq_generic_offset <= HQ_GENERIC_FOFFSET_24K4 ) + { + mvr2r(coeff_out1+HQ_GENERIC_LOW0 + HQ_GENERIC_END_FREQ - HQ_GENERIC_HIGH2, &coeff_out[fb_bwe_subband[0]], 160); + } + else + { + mvr2r(coeff_out1+HQ_GENERIC_OFFSET + HQ_GENERIC_LEN0, &coeff_out[fb_bwe_subband[0]], 160); + } + } + tmp1 = EPSILON; + tmp2 = EPSILON; + for(i=0; i<5; ++i) + { + tmp1 += (float)fabs(coeff_out[HQ_GENERIC_HIGH1+hq_generic_offset+i]); + tmp2 += (float)fabs(coeff_out[HQ_GENERIC_HIGH1-2+hq_generic_offset-i]); + } + + pit1 = &coeff_out[HQ_GENERIC_HIGH1+hq_generic_offset]; + tmp3 = tmp2/tmp1; + if( tmp3 < 0.3f ) + { + tmp3 = 0.3f; + } + + while( tmp3 < 1 ) + { + *pit1++ *= tmp3; + tmp3 += 0.1f; + } + + pit1 = &coeff_out[HQ_GENERIC_HIGH1-1+hq_generic_offset]; + tmp3 = tmp1/tmp2; + if( tmp3 > 5 ) + { + tmp3 = 5; + while( tmp3 > 1 ) + { + *pit1-- *= tmp3; + tmp3 -= 0.5f; + } + } + + if ( hq_generic_offset <= HQ_GENERIC_FOFFSET_24K4 ) + { + tmp1 = (float)(fabs(coeff_out[HQ_GENERIC_HIGH2+hq_generic_offset]) + fabs(coeff_out[HQ_GENERIC_HIGH2+1+hq_generic_offset])) + EPSILON; + tmp2 = (float)(fabs(coeff_out[HQ_GENERIC_HIGH2-4+hq_generic_offset]) + fabs(coeff_out[HQ_GENERIC_HIGH2-3+hq_generic_offset]) + + fabs(coeff_out[HQ_GENERIC_HIGH2-2+hq_generic_offset]) + fabs(coeff_out[HQ_GENERIC_HIGH2-1+hq_generic_offset])) + EPSILON; + + pit1 = &coeff_out[HQ_GENERIC_HIGH2+hq_generic_offset]; + tmp3 = tmp2/tmp1; + if( tmp3 < 0.3f ) + { + tmp3 = 0.3f; + } + + while( tmp3 < 1 ) + { + *pit1++ *= tmp3; + tmp3 += 0.1f; + } + + pit1 = &coeff_out[HQ_GENERIC_HIGH2-1+hq_generic_offset]; + tmp3 = tmp1/tmp2; + tmp3 = 0.5f*tmp3; + tmp4 = 0.05f*tmp3; + while(tmp3 > 1) + { + *pit1-- *= tmp3; + tmp3 -= tmp4; + } + } + + wfenv = hq_generic_fenv[0]; + for (n_freq = swb_bwe_subband[0]+hq_generic_offset,i=0; n_freq 15.f || hq_generic_fenv[nenv] < 5.f) + { + wfenv = hq_generic_fenv[nenv-1]; + for ( i=0; n_freq -#include -#include "options.h" -#include "prot_fx.h" -#include "basop_util.h" -#include "rom_com_fx.h" -#include "stl.h" - - -/*==========================================================================*/ -/* FUNCTION : Word16 WB_BWE_gain_pred_fx () */ -/*--------------------------------------------------------------------------*/ -/* PURPOSE : predict WB frequency envelopes for 0b WB BWE */ -/*--------------------------------------------------------------------------*/ -/* INPUT ARGUMENTS : */ -/* _Word16 *core_dec_freq i : Frequency domain core decoded signal */ -/* _Word16 coder_type i : coding type */ -/* _Word16 prev_coder_type i : coding type of last frame */ -/* _Word16 prev_WB_fenv i : envelope for last frame */ -/* _Word16 *voice_factors i : voicing factors //Q15 */ -/* _Word16 pitch_buf[] i : pitch buffer //Q6 */ -/* _Word16 last_core_brate i : previous frame core bitrate */ -/* _Word16 last_wb_bwe_ener i : previous frame wb bwe signal energy */ -/*--------------------------------------------------------------------------*/ -/* OUTPUT ARGUMENTS : */ -/* _Word16 *WB_fenv, o : WB frequency envelopes Q3 */ -/*--------------------------------------------------------------------------*/ -/* INPUT/OUTPUT ARGUMENTS : */ -/*--------------------------------------------------------------------------*/ -/* RETURN ARGUMENTS : */ -/* _Word16 mode */ -/*--------------------------------------------------------------------------*/ -/* CALLED FROM : */ -/*==========================================================================*/ - -Word16 WB_BWE_gain_pred_fx( - Word16 *WB_fenv, /* o : WB frequency envelopes */ - const Word16 *core_dec_freq, /* i : Frequency domain core decoded signal */ - const Word16 coder_type, /* i : coding type */ - Word16 prev_coder_type, /* i : coding type of last frame */ - Word16 prev_WB_fenv, /* i : envelope for last frame */ - Word16 *voice_factors, /* i : voicing factors //Q15 */ - const Word16 pitch_buf[], /* i : pitch buffer //Q6 */ - Word32 last_core_brate, /* i : previous frame core bitrate */ - Word16 last_wb_bwe_ener , /* i : previous frame wb bwe signal energy */ - Word16 Q_syn - ,Word16 last_extl_fx, - Word16 tilt_wb_fx -) -{ - Word32 enerL; - Word16 n_freq, mode,pitch; - Word16 ener_var_flag = 0; - Word16 voice_factor, enerL_16, enerL_40, enerL_64; - Word16 env_var_flag = 0; - Word16 exp; - Word16 tmp, tmp1; - Word32 L_tmp; - Word32 L_WB_fenv0, L_WB_fenv1; - Word16 pitch_buf_tmp[4]; - Word16 alfa = 32767; - move16(); - - mode = NORMAL; - move16(); - - enerL = L_deposit_l(0); - FOR (n_freq = 128; n_freq<192; n_freq++) - { - enerL = L_mac0( enerL, core_dec_freq[n_freq], core_dec_freq[n_freq] ); /*2(Q_syn) */ - } - - L_WB_fenv0 = L_deposit_l(0); - FOR (n_freq = 192; n_freq<224; n_freq++) - { - L_WB_fenv0 = L_mac0(L_WB_fenv0, core_dec_freq[n_freq],core_dec_freq[n_freq]);/*2*Q_syn */ - } - - L_WB_fenv1 = L_deposit_l(0); - FOR (n_freq = 224; n_freq<256; n_freq++) - { - L_WB_fenv1= L_mac0(L_WB_fenv1, core_dec_freq[n_freq],core_dec_freq[n_freq]);/*2*Q_syn */ - } - - L_tmp = sum16_32_fx( voice_factors, 4); - voice_factor = extract_l(L_shr(L_tmp, 2));/*Q13 */ - Copy_Scale_sig(pitch_buf, pitch_buf_tmp, 4, -1); - pitch = sum16_fx(pitch_buf_tmp, 4) ; - move16(); /*Q5 */ - - L_tmp = L_shr(enerL, 4); - test(); - IF(L_sub(L_max(L_WB_fenv1, L_WB_fenv0), L_tmp) > 0 && sub(9856, pitch) > 0) - { - ener_var_flag = 1; - move16(); - } - - test(); - IF(L_sub(L_WB_fenv0, L_shl(L_WB_fenv1,1)) > 0) - { - exp = norm_l(L_WB_fenv0); - tmp = extract_h(L_shl(L_WB_fenv0, exp)); - tmp = div_s(16384, tmp); /*Q(15+14-2*Q_syn-exp) */ - L_tmp = L_shr(Mult_32_16(L_shl(L_WB_fenv1, 1), tmp), sub(15, exp));/*2*Q_syn+15+exp-15->2*Q_syn+exp */ - /*L_tmp Q15 */ - tmp = extract_l(L_tmp); - alfa = s_max(tmp, 3277);/*Q15 */ - L_WB_fenv0 = Mult_32_16(L_WB_fenv0, alfa);/*2*Q_syn+15-15->2*Q_syn */ - } - ELSE IF (L_sub(L_WB_fenv1, L_shl(L_WB_fenv0, 1)) > 0 && sub(coder_type,UNVOICED) != 0) - { - exp = norm_l(L_WB_fenv1); - tmp = extract_h(L_shl(L_WB_fenv1, exp)); - tmp = div_s(16384, tmp); /*Q(15+14-2*Q_syn-exp) */ - L_tmp = L_shr(Mult_32_16(L_shl(L_WB_fenv0, 1), tmp), sub(15, exp));/*2*Q_syn+15+exp-15->2*Q_syn+exp */ - /*L_tmp Q15 */ - tmp = extract_l(L_tmp); - alfa = s_max(tmp, 3277);/*Q15 */ - L_WB_fenv1 = Mult_32_16(L_WB_fenv1, alfa);/*2*Q_syn+15-15->2*Q_syn */ - } - - if(L_WB_fenv0 == 0) - { - L_WB_fenv0 = L_deposit_l(1); - } - - if(L_WB_fenv1 == 0) - { - L_WB_fenv1 = L_deposit_l(1); - } - - if(enerL == 0) - { - enerL = L_deposit_l(1); - } - - L_tmp = L_add(L_WB_fenv0, L_WB_fenv1); /* In 2*Q_syn */ - exp = norm_l(L_tmp); - tmp = extract_h(L_shl(L_tmp, exp)); - /*exp = sub(exp, 30-(2*Q_syn+6)); //+6(/64) */ - exp = sub(exp, sub(30,add(shl(Q_syn,1),6))); /*+6(/64) */ - - tmp = div_s(16384, tmp); - L_tmp = L_deposit_h(tmp); - L_tmp = Isqrt_lc(L_tmp, &exp); - - WB_fenv[0] = round_fx(L_shl(L_tmp, sub(exp, 12))); /* Q3 */ - - test(); - test(); - IF(sub(coder_type,AUDIO) != 0&& sub(coder_type,UNVOICED) != 0 && ener_var_flag == 0) - { - WB_fenv[0]= add(WB_fenv[0], mult_r(WB_fenv[0], 16384)); - move16(); - } - - exp = norm_l(enerL); - tmp = extract_h(L_shl(enerL, exp)); - exp = sub(exp, sub(30,shl(Q_syn,1))); - - tmp = div_s(16384, tmp); - L_tmp = L_deposit_h(tmp); - L_tmp = Isqrt_lc(L_tmp, &exp); - enerL_16 = round_fx(L_shl(L_tmp, sub(exp, 15))); /* Q0 */ - enerL_40 = mult_r(6554, enerL_16); /*1/40 in Q18 ->Q3 */ - - test(); - test(); - test(); - test(); - test(); - test(); - IF( sub(coder_type,TRANSITION) != 0 && sub(coder_type,AUDIO) != 0 && sub(coder_type,UNVOICED) != 0 && - sub(enerL_40, WB_fenv[0]) > 0 && sub(alfa,29491) > 0 && !(sub(coder_type, prev_coder_type) == 0 && - sub(WB_fenv[0],prev_WB_fenv) > 0) ) - { - IF(WB_fenv[0] != 0) - { - exp = norm_s(WB_fenv[0]); - tmp = div_s(shl(1,sub(14,exp)), WB_fenv[0]); /*Q(29-exp-3) */ - L_tmp = L_mult(enerL_40, tmp); /*Q(30-exp) */ - tmp = round_fx(L_shl(L_tmp, sub(exp,2))); /*Q12 */ - tmp = s_min(tmp, 16384); - L_tmp = L_shr( L_mult0(tmp, WB_fenv[0]), 12);/*Q15 */ - WB_fenv[0] = extract_l(L_tmp);/*Q3 */ - } - - IF( sub(WB_fenv[0],prev_WB_fenv ) > 0) - { - /*WB_fenv[0]= add(mult_r(9830, WB_fenv[0]), mult_r(22938, prev_WB_fenv)); move16();//Q3 */ - WB_fenv[0] = round_fx(L_mac(L_mult(9830, WB_fenv[0]), 22938, prev_WB_fenv));/*Q3 */ - } - } - - L_tmp = L_mult0(voice_factor, 77); - tmp1 = extract_l(L_shr(L_tmp, 13)); - - exp = norm_s(pitch); - tmp = div_s(shl(1,sub(14,exp)), pitch); /*Q(29-exp-5) */ - L_tmp = L_mult0(tmp1, tmp); /*29-exp-5->24-exp */ - tmp = round_fx(L_shl(L_tmp, add(exp,6))); /*14 */ - - tmp1= s_max(tmp, 8192); - alfa = s_min(24576, tmp1);/*Q14 */ - - L_tmp = L_mult0(alfa, WB_fenv[0]);/*Q14+Q3->Q17 */ - L_tmp = L_shr(L_tmp, 14);/*Q3 */ - tmp = extract_l(L_tmp); - - enerL = L_deposit_l(enerL_16); - enerL = L_shl(enerL, 6); /*Q6 */ - tmp1 = i_mult(3, WB_fenv[0]);/*Q3 */ - L_tmp = L_mult0(tmp1, WB_fenv[0]); /*Q6 */ - - test(); - test(); - test(); - IF( sub(shr(enerL_16, 3), tmp) > 0 && L_sub(enerL, L_tmp) > 0 && sub(prev_coder_type,UNVOICED) != 0 && WB_fenv[0] != 0) - { - env_var_flag = 1; - move16(); - enerL_64 = mult_r(4096, enerL_16);/* 1/64 in Q18 ->Q3 */ - - exp = norm_s(WB_fenv[0]); - tmp = div_s(shl(1,sub(14,exp)), WB_fenv[0]); /*Q(29-exp-3) */ - L_tmp = L_mult(enerL_64 ,tmp); /*Q(30-exp) */ - tmp = round_fx(L_shl(L_tmp, sub(exp,2))); /*Q12 */ - tmp = s_min(tmp, 16384); - L_tmp = L_shr( L_mult0(tmp, WB_fenv[0]), 12);/*Q3 */ - WB_fenv[0] = extract_l(L_tmp);/*Q3 */ - - IF( sub(WB_fenv[0],prev_WB_fenv) > 0 ) - { - /*WB_fenv[0] = add(mult_r(9830, WB_fenv[0]), mult_r(22938, prev_WB_fenv));//Q3 */ - WB_fenv[0] = round_fx(L_mac(L_mult(9830, WB_fenv[0]), 22938, prev_WB_fenv));/*Q3 */ - } - } - - test(); - IF(sub(coder_type,UNVOICED) == 0 || sub(prev_coder_type,UNVOICED) == 0) - { - WB_fenv[0] = shr(WB_fenv[0], 1); - move16();/*Q3 */ - } - - IF(sub(coder_type,AUDIO) != 0) - { - tmp = mult_r(voice_factor, 19661); /*Q12 */ - tmp = s_max(tmp, 4096); - exp = norm_s(tmp); - tmp = div_s(shl(1,sub(14,exp)), tmp); /*Q(29-exp-12) */ - L_tmp = L_mult(WB_fenv[0], tmp); /*Q(21-exp) */ - - WB_fenv[0] = round_fx(L_shl(L_tmp, sub(exp,2))); /*Q3 */ - tmp1 = mult_r(328, pitch);/*Q7 */ - tmp = s_min(s_max(tmp1, 16), 256);/*Q7 */ - L_tmp = L_shr( L_mult0(WB_fenv[0], tmp),7);/*Q3 */ - /*WB_fenv[0] = saturate(L_tmp); //Q3 */ - WB_fenv[0] = round_fx(L_shl(L_tmp,16)); /*Q3 */ - } - test(); - IF( L_sub(last_core_brate,ACELP_8k00) > 0 && sub(WB_fenv[0],last_wb_bwe_ener) > 0 ) - { - /*WB_fenv[0]= add(mult_r(29491, last_wb_bwe_ener), mult_r(3277, WB_fenv[0]));//Q3 */ - WB_fenv[0] = round_fx(L_mac(L_mult(29491, last_wb_bwe_ener), 3277, WB_fenv[0]));/*Q3 */ - } - - IF( sub(last_extl_fx, WB_BWE) != 0 && sub(tilt_wb_fx, 128) < 0) - { - WB_fenv[0] = mult_r(s_min(16384, shl(tilt_wb_fx, 8)), WB_fenv[0]); - } - - IF(env_var_flag == 1) - { - WB_fenv[1] = add(WB_fenv[0], mult_r(WB_fenv[0], 16384)); - move16(); - WB_fenv[0] = mult_r(24576, WB_fenv[0]); - move16();/*Q3 */ - } - ELSE - { - WB_fenv[1] = WB_fenv[0]; - move16(); - } - - test(); - IF(sub(coder_type,UNVOICED) == 0 || sub(prev_coder_type,UNVOICED) == 0) - { - WB_fenv[1] = shr(WB_fenv[1], 1); - move16();/*Q3 */ - } - - return (mode); -} - -/*-------------------------------------------------------------------* -* calc_norm_envelop_lf_fx() -* -* calc_envelope of low frequency spectrum -*-------------------------------------------------------------------*/ -static -void calc_norm_envelop_lf_fx( - const Word32 SWB_signal[], /* i : SWB spectrum */ /* Q12 */ - Word32 *envelope, /* o : normalized envelope */ /* Q12 */ - Word16 *L_swb_norm, /* i/o : length of envelope */ - const Word16 HQ_mode, /* i : HQ mode */ /* Q0 */ - const Word16 hq_generic_offset, /* i : frequency offset for representing hq generic */ /* Q0 */ - Word16 *sfreq, /* i : starting frequency index */ - Word16 *efreq /* i : ending frequency index */ -) -{ - Word16 lookback, env_index, n_freq, n_lag_now, n_lag; - - *sfreq = 2; - move16(); - IF ( sub(hq_generic_offset, HQ_GENERIC_FOFFSET_24K4) == 0 ) - { - *efreq = 146; - move16(); - if ( sub(HQ_mode, HQ_GEN_FB) == 0 ) - { - *efreq = 306; - move16(); - } - IF ( sub(add(shl(sub(328,*efreq),1),1),*L_swb_norm) < 0) - { - *L_swb_norm = add(shl(sub(328,*efreq),1),1); - } - } - ELSE - { - *efreq = 130; - move16(); - if ( sub(HQ_mode, HQ_GEN_FB) == 0 ) - { - *efreq = 290; - move16(); - } - IF ( sub(add(shl(sub(400,*efreq),1),1),*L_swb_norm) < 0) - { - *L_swb_norm = add(shl(sub(400,*efreq),1),1); - } - } - lookback = shr(*L_swb_norm,1); - env_index = 0; - move16(); - n_lag_now = *L_swb_norm; - move16(); - - FOR (n_freq = 0; n_freq < lookback; n_freq++) - { - Word16 tmp; - Word32 L_tmp; - - L_tmp = L_deposit_l(1); - tmp = add(lookback,n_freq); - FOR (n_lag=0; n_lag0 && (sub(peak,shl(10,Q_syn)) > 0)) - { - n_band = add(1,n_band); - } - } - - IF( sub(core, ACELP_CORE) == 0 ) - { - L_swb_norm_trans = add(4, mult(n_band, 8192)); - L_swb_norm_norm = add(8, mult(n_band, 16384)); - - L_tmp = L_add(65536, L_mult0(n_band, 4096)); /*Q16 */ - L_swb_norm_harm = s_max(round_fx(L_shl(L_tmp, 5)), 24); /* Q0 */ - - IF( sub(mode,HARMONIC) == 0 ) - { - L_swb_norm_cur = L_swb_norm_harm; - move16(); - } - ELSE IF( sub(mode,NORMAL) == 0 ) - { - L_swb_norm_cur = L_swb_norm_norm; - move16(); - } - ELSE - { - L_swb_norm_cur = L_swb_norm_trans; - move16(); - } - *L_swb_norm = shr(add(L_swb_norm_cur,*prev_L_swb_norm),1); - move16(); - *prev_L_swb_norm = L_swb_norm_cur; - move16(); - } - ELSE - { - test(); - IF( sub(mode,HQ_HARMONIC) == 0 || sub(mode,HQ_HVQ) == 0 ) - { - L_tmp = L_add(65536, L_mult(n_band, 2560)); - L_swb_norm_cur = round_fx(L_shl(L_tmp, 5));/*Q0 */ - } - ELSE - { - L_tmp = L_add(65536, L_mult(n_band, 2048)); /*Q16 */ - L_swb_norm_cur = round_fx(L_shl(L_tmp, 3));/*Q0 */ - } - - /**L_swb_norm = add(mult_r(L_swb_norm_cur, 3277), mult_r(*prev_L_swb_norm, 29491)); */ - *L_swb_norm = round_fx(L_mac(L_mult(L_swb_norm_cur, 3277), *prev_L_swb_norm, 29491)); - *prev_L_swb_norm = L_swb_norm_cur; - move16(); - } - - return; -} -Word32 calc_tilt_bwe_fx( /* o : Tilt in Q24 */ - const Word16 *sp, /* i : input signal */ - const Word16 exp_sp, /* i : Exp of inp signal */ - const Word16 N /* i : signal length */ -) -{ - Word16 i, j; - Word32 L_ener, L_ener_tot, L_temp; - Word16 tmp1, tmp2; - const Word16 *ptr; - Word16 exp2; - - BASOP_SATURATE_WARNING_OFF - - /* this is required for adaptative precision energy summation loop, do not remove */ - Overflow = 0; - move16(); - exp2 = 0; - move16(); - - ptr = sp; - move16(); - L_ener_tot = L_deposit_l(1); - - /* Divide Frame Length by 32 */ - FOR (j = shr(N, 5); j > 0; j--) - { - tmp1 = mult_r(*ptr++, 8192); /* Divide by 4 */ - L_ener = L_mult0(tmp1, tmp1); - /* With the shift by 4 and the L_mult0, no overflow possible for 32 samples */ - FOR (i = 1; i < 32; i++) - { - tmp1 = mult_r(*ptr++, 8192); /* Divide by 4 */ - L_ener = L_mac0(L_ener, tmp1, tmp1); - } - L_ener = L_shr(L_ener, exp2); - L_temp = L_add(L_ener_tot, L_ener); - IF (Overflow != 0) - { - L_ener_tot = L_shr(L_ener_tot, 1); - L_ener = L_shr(L_ener, 1); - exp2 = add(exp2, 1); - /* this is required, do not remove */ - Overflow = 0; - move16(); - } - L_ener_tot = L_add(L_ener_tot, L_ener); - } - L_ener = L_deposit_l(abs_s(sub(sp[1], sp[0]))); - FOR (i = 2; i < N; i++) - { - /* Eq to (sp[i] - sp[i-1]) * (sp[i-1] - sp[i-2]) < 0 */ - tmp1 = sub(sp[i], sp[i-1]); - tmp2 = sub(sp[i-1], sp[i-2]); - tmp2 = mult(tmp1, tmp2); - tmp1 = abs_s(tmp1); - /* to Get either 0 or -1 in 'tmp2' */ - tmp2 = shr(tmp2, 15); - /* this allows this code */ - L_ener = L_msu0(L_ener, tmp2, tmp1); - /* instead of this one */ - /* test(); */ - /* if (tmp2 < 0) */ - /* { */ - /* L_ener = L_mac0(L_ener, 1, tmp1); */ - /* } */ - /* it saves one op */ - } - - tmp1 = norm_l(L_ener_tot); - L_temp = L_shl(L_ener_tot, tmp1); - tmp1 = sub(add(31+4, exp2), add(tmp1, shl(exp_sp, 1))); - L_temp = Isqrt_lc(L_temp, &tmp1); - - /* *tilt_flt = (float)(r1/sqrt(r0)); */ - exp2 = norm_l(L_ener); - L_temp = Mult_32_16(L_temp, round_fx(L_shl(L_ener, exp2))); - exp2 = sub(exp2, tmp1); - exp2 = add(exp2, exp_sp); - - /* Put in Q24 */ - L_temp = L_shr(L_temp, sub(exp2, 24)); - - BASOP_SATURATE_WARNING_ON - - return L_temp; -} -void calc_norm_envelop_fx( - const Word16 SWB_signal[], /* i : SWB spectrum Q_syn*/ - Word32 *envelope, /* o : normalized envelope Q_syn*/ - const Word16 L_swb_norm, /* i : length of envelope Q0 */ - const Word16 SWB_flength, /* i : Length of input/output */ - const Word16 st_offset /* i : offset */ -) -{ - Word16 i, lookback, env_index, n_freq, n_lag_now, n_lag, tmp; - - lookback = shr(L_swb_norm, 1); - move16(); - env_index = add(swb_bwe_subband_fx[0], st_offset); - n_lag_now = L_swb_norm; - move16(); - tmp = sub(add(SWB_flength, st_offset), L_swb_norm); - FOR (n_freq = sub(add(swb_bwe_trans_subband_fx[0], st_offset), lookback); n_freq 0) - { - tmp = sub(18022, weight); /* Q15 */ - WB_signal[n_freq] = extract_l(Mult_32_16(L_tmp,tmp)); /* Q_syn */ - } - - IF(sub(signum[n_freq],1) != 0) - { - WB_signal[n_freq] = negate(WB_signal[n_freq]); - move16(); - } - } - } - - /* Normalize with envelope */ - FOR (n_freq = swb_bwe_subband_fx[0]; n_freqQ(25) */ - - exp = norm_l(energy); - L_tmp1 = L_shl(energy, exp); - exp = 31-exp-(25); - move16(); - L_tmp1 = Isqrt_lc(L_tmp1, &exp); /*Q(31-exp) */ - - FOR (n_freq = swb_bwe_subband_fx[n_band]; n_freq 0 ) - { - alfa = 13107; - move16();/*.4 in Q15 */ - beta = 20480; - move16(); /*2.5 in Q13 */ - } - ELSE - { - alfa = 19661; - move16();/*.6 in Q15 */ - beta = 13681; - move16();/*1.67 in Q13 */ - } - - test(); - test(); - test(); - IF( sub(coder_type,GENERIC) == 0 || ((L_sub(EnergyL,L_shr(*prev_Energy,1)) > 0 && L_sub(*prev_Energy,L_shr( EnergyL, 1))>0 && sub(*prev_flag,1) == 0)) ) - { - WB_fenv[0] = shr( WB_fenv[0], 1); - move16(); - WB_fenv[1] = shr( WB_fenv[1], 1); - move16(); - flag = 1; - move16(); - } - } - L_tmp1 = Mult_32_16(EnergyL,prev_WB_fenv[0]);/*Qsyn+3-15 */ - L_tmp2 = Mult_32_16(*prev_Energy,WB_fenv[0]);/*Q_syn+3-15 */ - prev_ener_alpha = Mult_32_16( *prev_Energy, alfa);/*Q_syn+15-15->Q_syn */ - prev_ener_beta = L_shl( Mult_32_16( *prev_Energy ,beta),2); /*Q_syn+13-15+2 ->Q_syn */ - - test(); - test(); - IF( (sub(mode,HARMONIC) == 0 &&sub(shr(WB_fenv[0], 2), WB_fenv[1]) > 0) || sub(mode,NORMAL) == 0 ) - { - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - IF( sub(last_extl,WB_BWE) == 0 && - ( (sub(prev_coder_type,AUDIO) == 0 && sub(coder_type,AUDIO) != 0) || - (sub(prev_coder_type,AUDIO) != 0 && sub(coder_type,AUDIO) == 0)) && L_sub(total_brate,ACELP_8k00) <= 0 ) - { - IF( sub(WB_fenv[0],prev_WB_fenv[0]) > 0 ) - { - /*wfenv[0]= add(mult_r(9830, WB_fenv[0]), mult_r(22938, prev_WB_fenv[0]));//Q3 */ - wfenv[0]= round_fx(L_mac(L_mult(9830, WB_fenv[0]), 22938, prev_WB_fenv[0]));/*Q3 */ - /*wfenv[1]= add(mult_r(9830, WB_fenv[1]), mult_r(22938, prev_WB_fenv[1]));//Q3 */ - wfenv[1]= round_fx(L_mac(L_mult(9830, WB_fenv[1]), 22938, prev_WB_fenv[1]));/*Q3 */ - } - ELSE - { - /*wfenv[0]= add(mult_r(16384,WB_fenv[0]),mult_r(16384,prev_WB_fenv[0]));//Q3 */ - wfenv[0]= round_fx(L_mac(L_mult(16384,WB_fenv[0]),16384,prev_WB_fenv[0]));/*Q3 */ - /*wfenv[1]= add(mult_r(13108,WB_fenv[1]),mult_r(13108,prev_WB_fenv[1]));//Q3 */ - wfenv[1]= round_fx(L_mac(L_mult(13108,WB_fenv[1]),13108,prev_WB_fenv[1]));/*Q3 */ - } - } - ELSE IF ( sub(last_extl,WB_BWE) == 0 && L_sub(L_tmp1,L_tmp2)<0 && sub(WB_fenv[0],prev_WB_fenv[0]) > 0&& - sub(coder_type,AUDIO) != 0 && sub(coder_type,UNVOICED) != 0 && L_sub(total_brate,ACELP_8k00) <= 0) - { - /*wfenv[0]= add(mult_r(9830,WB_fenv[0]),mult_r(22938,prev_WB_fenv[0]));//Q3 */ - wfenv[0]= round_fx(L_mac(L_mult(9830,WB_fenv[0]),22938,prev_WB_fenv[0]));/*Q3 */ - /*wfenv[1]= add(mult_r(9830,WB_fenv[1]),mult_r(22938,prev_WB_fenv[1]));//Q3 */ - wfenv[1]= round_fx(L_mac(L_mult(9830,WB_fenv[1]),22938,prev_WB_fenv[1]));/*Q3 */ - } - ELSE IF ( sub(last_extl,WB_BWE) == 0 && L_sub(EnergyL,prev_ener_alpha) >0 && L_sub(prev_ener_beta,EnergyL) >0 && - sub(prev_coder_type,UNVOICED) != 0 ) - { - /*wfenv[0] = add(shr(WB_fenv[0],1), shr(prev_WB_fenv[0],1));//Q3 */ - wfenv[0] = round_fx(L_mac(L_mult(WB_fenv[0],16384), prev_WB_fenv[0],16384));/*Q3 */ - /*wfenv[1] = add(shr(WB_fenv[1],1), shr(prev_WB_fenv[1],1));//Q3 */ - wfenv[1] = round_fx(L_mac(L_mult(WB_fenv[1],16384), prev_WB_fenv[1],16384));/*Q3 */ - } - ELSE - { - wfenv[0] = WB_fenv[0]; - move16(); - wfenv[1] = WB_fenv[1]; - move16(); - } - FOR (n_freq = swb_bwe_subband_fx[0]; n_freq 0 && L_sub(*prev_Energy,L_shr(EnergyL,1))>0) - { - L_tmp1 = L_mac(L_mult(8192,wfenv[0]),12288, prev_WB_fenv[0]); - wfenv[0] = round_fx(L_mac(L_tmp1, 12288, prev_WB_fenv[1])); - } - FOR (n_freq = swb_bwe_subband_fx[0]; n_freq 0) - { - fenvL_16 = shl(SWB_fenv[0], 2); - move16(); - } - EnergyL = Mult_32_16(EnergyL,17476); /*2*Q_syn+3; 17476=(1/15) in Q18 */ - EnergyL_16 = 0; - move16(); - IF (EnergyL != 0) - { - exp = norm_l(EnergyL); /* In 2*Q_syn+3 */ - tmp = extract_h(L_shl(EnergyL, exp)); - exp = sub(exp, sub(30,add(shl(Q_syn,1),3+4))); /*+4(/16) */ - - tmp = div_s(16384, tmp); - L_tmp = L_deposit_h(tmp); - L_tmp = Isqrt_lc(L_tmp, &exp); - - EnergyL_16 = round_fx(L_shl(L_tmp, sub(exp, 12))); /* Q3 */ - } - calc_normal_length_fx( ACELP_CORE, core_dec_freq, mode, extl, &L_swb_norm, prev_L_swb_norm ,Q_syn); - - set16_fx( SWB_signal, 0, L_FRAME32k ); - IF( sub(mode,TRANSIENT) == 0 ) - { - Energy = L_deposit_l(0); - FOR(n_band = 0; n_band < SWB_FENV_TRANS; n_band++) - { - Energy = L_mac(Energy,SWB_fenv[n_band],SWB_fenv[n_band]); /*Q(2*1+1)->Q3 */ - } - exp = norm_s(SWB_FENV_TRANS); - tmp = div_s(shl(1,sub(14,exp)), SWB_FENV_TRANS); /*Q(29-exp) */ - L_tmp = Mult_32_16(Energy, tmp); /*Q(3+29-exp+1-16)->Q(17-exp) */ - Energy_16 = round_fx(L_shl(L_tmp, add(exp,2))); /*Q3 */ - - /* Reconstruct excitation from LF signal */ - Copy(&core_dec_freq[112], &SWB_signal[240+st_offset], 128); - Copy(&core_dec_freq[112], &SWB_signal[368+st_offset], 128); - Copy(&core_dec_freq[176], &SWB_signal[496+st_offset], 64); - - /* calculate envelope */ - calc_norm_envelop_fx(SWB_signal, envelope, L_swb_norm, SWB_flength, st_offset); - - /* Normalize with envelope */ - tmp_exp = sub(15, Q_syn); - FOR (n_freq = swb_bwe_trans_subband_fx[0]+st_offset; n_freqQ(-exp1+39) */ - - exp = norm_l(energy); - L_tmp = L_shl(energy,exp); - /*exp = 31-exp-(-exp1+39); */ - exp = sub(sub(exp1,exp),8); - L_tmp = Isqrt_lc(L_tmp, &exp); /*Q(31-exp) */ - - Ltmp_ener = Mult_32_16(L_tmp,SWB_fenv[n_band]);/*Q(31-exp+1+1-16)->Q(17-exp) */ - tmp = add(swb_bwe_trans_subband_fx[n_band+1],st_offset); - tmp_exp = add(Q_syn,sub(exp,2)); - FOR (n_freq = add(swb_bwe_trans_subband_fx[n_band],st_offset); n_freqQ(15-exp) */ - Energy_16 = round_fx(L_shl(L_tmp,add(exp,4))); /*Q3 */ - - IF(sub(last_extl, SWB_BWE) != 0 && sub(last_extl, FB_BWE) != 0) - { - IF(Energy_16 < shr(EnergyL_16, 4) && sub(extl, FB_BWE) == 0) - { - FOR(n_band=0; n_band 0 || (sub(tilt_nb,14336) > 0 && sub(Energy_16,shr(EnergyL_16,1)) > 0) || - sub(tilt_nb,24576) > 0) && sub(Energy_16,600) > 0 && sub(fenvL_16,200) > 0)) - { - tmp = add(swb_bwe_subband_fx[SWB_FENV], st_offset); - FOR (n_freq=add(swb_bwe_subband_fx[0],st_offset); n_freq 0) - { - tmp = extract_l(L_mac0(26214, n_band, 492)); /*Q15; 0.015 in Q15 = 492 */ - SWB_fenv[n_band+1] = mult_r(SWB_fenv[n_band+1], tmp); - move16();/*Q1 */ - } - - IF(sub(mult_r(SWB_fenv[n_band+1],29491),SWB_fenv[n_band]) > 0) - { - tmp = extract_l(L_mac0(26214, n_band,492)); /*Q15; 0.015 in Q15 = 492 */ - SWB_fenv[n_band] = mult_r(SWB_fenv[n_band],tmp); - move16();/*Q1 */ - } - } - Copy(&core_dec_freq[112], &SWB_signal[240+st_offset], 128); - Copy(&core_dec_freq[112], &SWB_signal[368+st_offset], 128); - Copy(&core_dec_freq[176], &SWB_signal[496+st_offset], 64); - - tmp1 = add(abs_s(SWB_signal[368+st_offset]), abs_s(SWB_signal[369+st_offset])); /*Q_syn */ - tmp2 = add(abs_s(SWB_signal[365+st_offset]), abs_s(SWB_signal[366+st_offset])); /*Q_syn */ - pit1 = &SWB_signal[368+st_offset]; - move16(); - - test(); - IF((tmp2 == 0) || (sub(tmp2, mult_r(tmp1, 9830)) < 0)) - { - tmp3 = 9830; - move16();/*0.3 in Q15 */ - WHILE(sub(tmp3,32767) < 0) - { - *pit1 = mult_r(*pit1,tmp3); - move16(); /*Q_syn */ - pit1++; - tmp3 = add(tmp3,3277); /*Q15 */ - } - } - ELSE IF(sub(tmp2, tmp1) < 0) - { - exp = norm_s(tmp1); - tmp = div_s(shl(1,sub(14,exp)),tmp1); /*Q(29-exp) */ - tmp3 = round_fx(L_shl(L_mult(tmp2,tmp),add(exp,2))); /*Q15 */ - WHILE(sub(tmp3, 32767) < 0) - { - *pit1 = mult_r(*pit1,tmp3); - move16(); /*Q_syn */ - pit1++; - tmp3 = add(tmp3,3277); /*Q15 */ - } - } - - pit1 = &SWB_signal[367+st_offset]; - move16(); - IF(sub(mult_r(tmp1,6554),tmp2) > 0) - { - /*20480 = 5 in Q12 */ - FOR(tmp3 = 20480; tmp3 > 4096; tmp3 -= 2048) - { - *pit1 = round_fx(L_shl(L_mult(*pit1,tmp3),3)); /*Q_syn */ - pit1--; - } - } - - tmp1 = add(abs_s(SWB_signal[496+st_offset]),abs_s(SWB_signal[497+st_offset])); /*Q_syn */ - tmp2 = add(add(abs_s(SWB_signal[492+st_offset]),abs_s(SWB_signal[493+st_offset])),add(abs_s(SWB_signal[494+st_offset]),abs_s(SWB_signal[495+st_offset]))); - pit1 = &SWB_signal[496+st_offset]; - move16(); - - test(); - IF((tmp2 == 0) || (sub(tmp2,mult_r(tmp1,9830)) < 0)) - { - tmp3 = 9830; - move16(); /*0.3 in Q15 */ - WHILE(sub(tmp3,32767) < 0) - { - *pit1 = mult_r(*pit1,tmp3); - move16(); /*Q_syn */ - pit1++; - tmp3 = add(tmp3,3277); /*Q15 */ - } - } - ELSE IF(sub(tmp2,tmp1) < 0) - { - exp = norm_s(tmp1); - tmp = div_s(shl(1,sub(14,exp)),tmp1); /*Q(29-exp) */ - tmp3 = round_fx(L_shl(L_mult(tmp2,tmp),add(exp,2))); /*Q15 */ - WHILE(sub(tmp3,32767) < 0) - { - *pit1 = mult_r(*pit1,tmp3); - move16();/*Q_syn */ - pit1++; - tmp3 = add(tmp3,3277); /*Q15 */ - } - } - pit1 = &SWB_signal[495+st_offset]; - - L_tmp3 = L_deposit_h(tmp1); /*Q17 */ - L_tmp4 = Mult_32_16(L_tmp3,1638); /*Q17 */ - exp = 14; - move16(); - IF(tmp2 != 0) - { - exp = norm_s(tmp2); - tmp = div_s(shl(1,sub(14,exp)),tmp2); /*Q(29-exp) */ - L_tmp3 = L_shr(L_mult(tmp1,tmp),1); /*Q(30-exp+1)->Q(30-exp) (+1) due to *0.5 */ - L_tmp4 = Mult_32_16(L_tmp3,1638); /*Q(30-exp) */ - } - - L_tmp1 = L_shl(1L,sub(30,exp)); - WHILE( L_sub(L_tmp3,L_tmp1) > 0 ) - { - L_tmp = Mult_32_16(L_tmp3,*pit1); /*Q(16-exp) */ - *pit1-- = round_fx(L_shl(L_tmp,exp)); /*Q_syn */ - L_tmp3 = L_sub(L_tmp3,L_tmp4); - } - - /* calculate envelope */ - calc_norm_envelop_fx(SWB_signal, envelope, L_swb_norm, SWB_flength, st_offset); - } - } - - /* Normalize with envelope */ - test(); - IF( *frica_flag == 0 && sub(mode, NOISE) != 0 ) - { - L = add(swb_bwe_subband_fx[0],st_offset); - exp = norm_s(L_swb_norm); - inv_L_swb_norm = shl(div_s(shl(1,sub(14,exp)),L_swb_norm),sub(exp,14)); /* Q15 */ - - IF(sub(mode,HARMONIC) != 0) - { - tmp = add(shl(inv_L_swb_norm,1), inv_L_swb_norm) ; - weight = s_max(s_min(tmp,16384), 6554); - } - ELSE - { - weight = 6554; - move16(); - } - - weight = mac_r(L_mult(13107,weight) , 19661,(*prev_weight)); - - FOR (n_freq = L; n_freq 0) - { - tmp = shr(weight,1); /* Q14 */ - tmp = sub(19661,tmp); /* Q14 */ - SWB_signal[n_freq] = extract_l(L_shl(Mult_32_16(L_tmp,tmp),1)); /* Q_syn */ - } - ELSE - { - SWB_signal[n_freq] = extract_l(L_tmp); /* Q_syn */ - } - - IF(sub(signum[n_freq],1) != 0) - { - SWB_signal[n_freq] = negate(SWB_signal[n_freq]); - move16(); - } - } - - tmp_exp = sub(15,Q_syn); - FOR (n_freq = L; n_freqQ(-exp1+39) */ - - exp = norm_l(energy); - L_tmp = L_shl(energy, exp); - /*exp = 31-exp-(-exp1+39);move16(); */ - exp = sub(sub(exp1,exp),8); - Ltmp_ener = Isqrt_lc(L_tmp, &exp); /*Q(31-exp) */ - - tmp = add(swb_bwe_subband_fx[n_band+L],st_offset); - tmp_exp = add(Q_syn,sub(exp,15)); - FOR(n_freq = add(swb_bwe_subband_fx[n_band],st_offset); n_freq 0 && Energy_16 > 0) - { - weight = shr(div_s(Energy_16,*prev_Energy),1); /*Q15 */ - } - ELSE - { - weight = 16384; - move16();/*Q15 */ - } - L_tmp = L_mult(weight, prev_SWB_fenv[0]); /*Q17 */ - L_tmp = L_mac(L_tmp, sub(32767, weight), SWB_fenv[0]);/*Q17 */ - wfenv = round_fx(L_tmp); /*Q1 */ - - tmp = norm_s(wfenv); - IF ( sub(tmp,4) > 0 ) - { - tmp = 12; - move16(); - factor = fenvL_16; - move16();/*Q3 */ - factor1 = mult_r(sub(shl(wfenv,2),fenvL_16),4096); /*Q3 */ - } - ELSE - { - tmp = 14; - move16(); - factor = shr(fenvL_16,2);/*Q1 */ - factor1 = mult_r(sub(wfenv,factor), 4096); /*Q1 */ - } - - tmp2 = add(add(swb_bwe_subband_fx[0],8),st_offset); - FOR (n_freq = add(swb_bwe_subband_fx[0],st_offset); n_freq < tmp2; n_freq++) - { - L_tmp1 = Mult_32_16(SWB_signal_32[n_freq], factor); - SWB_signal_32[n_freq] = L_shl(L_tmp1, tmp-1); - move32();/*15+Qsyn */ - factor = add(factor, factor1); /*Q3 */ - } - - FOR(n_band = 0; n_band < 12; n_band++) - { - L_tmp = L_mult(weight, prev_SWB_fenv[n_band+1]); /*Q17 */ - L_tmp = L_mac(L_tmp, sub(32767,weight), SWB_fenv[n_band+1]);/*Q17 */ - wfenv = round_fx(L_tmp); /*Q1 */ - factor = SWB_fenv[n_band]; - move16(); /*Q1 */ - factor1 = mult_r(sub(wfenv,SWB_fenv[n_band]), smooth_factor_fx[n_band]); /*Q1 */ - tmp = norm_s(factor); - IF ( sub(tmp,4) > 0) - { - tmp = 12; - move16(); - factor = shl(factor, 2); - factor1 = shl(factor1, 2); - } - ELSE - { - tmp = 14; - move16(); - } - - tmp2 = add(swb_bwe_sm_subband_fx[n_band+1],st_offset); - FOR (; n_freq < tmp2; n_freq++) - { - L_tmp1 = Mult_32_16(SWB_signal_32[n_freq], factor); - SWB_signal_32[n_freq] = L_shl(L_tmp1, tmp-1); - move32(); /*15+Qsyn */ - factor = add(factor, factor1); /*Q1 */ - } - } - L_tmp = L_mult(weight, prev_SWB_fenv[13]); /*Q17 */ - L_tmp = L_mac(L_tmp,sub(32767,weight), SWB_fenv[13]);/*Q17 */ - wfenv = round_fx(L_tmp); /*Q1 */ - factor = SWB_fenv[12]; - move16();/*Q1 */ - factor1 = mult_r(sub(wfenv, SWB_fenv[12]), smooth_factor_fx[12]); /*Q1 */ - tmp2 = add(swb_bwe_sm_subband_fx[13],st_offset); - FOR ( ; n_freq < tmp2; n_freq++) - { - L_tmp1 = Mult_32_16(SWB_signal_32[n_freq], factor); - SWB_signal_32[n_freq] = L_shl(L_tmp1,13); - move32();/*15+Qsyn */ - factor = add(factor,factor1); /*Q1 */ - } - - FOR(n_band=13; n_band Q(-exp_L+14+2*Q_synth) */ - Energy_16 = 0; - move16(); - /*exp = 31-(-exp_L+14 +(2*(*Q_synth))); */ - exp = sub(17,sub(shl((*Q_synth),1),exp_L)); - - IF(Energy != 0) - { - exp = norm_l(Energy); - frac = extract_h(L_shl(Energy, exp)); - /*exp = sub(exp, 30-(-exp_L+14-2+(2*(*Q_synth)))); */ - exp = sub(exp,sub(30,add(sub(shl((*Q_synth),1),exp_L),14-2))); - - tmp = div_s(16384, frac); - L_tmp = L_deposit_h(tmp); - Energy = Isqrt_lc(L_tmp, &exp); /*Q(31-exp) */ - Energy_16 = round_fx(L_shl(Energy, sub(exp,15))); /*Q0 */ - } - - test(); - IF(L_sub(SWB_tenv[i], 65536) < 0 && L_sub(Energy, L_shl(SWB_tenv[i], sub(16,exp))) < 0) - { - *Q_synth = add(*Q_synth, 3); - move16(); - } - ELSE - { - pit -= L/4; - move16(); - tmp_ener = 0; - move16(); - exp = 0; - move16(); - - IF(Energy_16 != 0) - { - exp = norm_s(Energy_16); - tmp_ener = div_s(shl(1,sub(14,exp)), Energy_16); /*Q(29-exp) */ - } - - L_tmp = Mult_32_16(SWB_tenv[i], tmp_ener); /*Q(29-exp) */ - tmp = round_fx(L_tmp); /*Q(13-exp) */ - - FOR (j = 0; j < L/4; j++) - { - *pit = round_fx(L_shl(L_mult(tmp, *pit), sub(exp,1))); /*Q(13-exp+1)->Q(14-exp)->Qsyn-3 */ - pit++; - } - } - } - - return; -} - -/*==========================================================================*/ -/* FUNCTION : void time_reduce_pre_echo_fx() */ -/*--------------------------------------------------------------------------*/ -/* PURPOSE : Windowing and time-domain aliasing */ -/*--------------------------------------------------------------------------*/ -/* INPUT ARGUMENTS */ -/* _(Word16*) synth :ACELP core synthesis Q_syn */ -/* _(Word16) L :subframe length */ -/* _(Word16) Q_syn :Q format */ -/*--------------------------------------------------------------------------*/ -/* OUTPUT ARGUMENTS : */ -/* _(Word16*)error : SHB BWE synthesis Q_syn */ -/* _(Word16)prev_td_energy : last td energy Q_syn */ -/*--------------------------------------------------------------------------*/ -/* INPUT/OUTPUT ARGUMENTS : */ -/* _None */ -/*--------------------------------------------------------------------------*/ -/* RETURN ARGUMENTS : */ -/* _ None */ -/*--------------------------------------------------------------------------*/ -void time_reduce_pre_echo_fx( - const Word16 *synth, /* i : ACELP core synthesis Q_syn*/ - Word16 *error, /* i/o: SHB BWE synthesis Q0*/ - Word16 prev_td_energy, /* o : last td energy Q0*/ - const Word16 L, /* i : subframe length */ - Word16 Q_syn, - Word16 Q_synth -) -{ - Word16 i, j, pos = 0, Len; - Word32 energy; - Word16 energy_16; - Word32 energyL[4]; - Word16 tmp_ener; - Word16 *pit; - Word16 tmpi, tmp_exp; - Word16 exp_L, exp, frac, inv_L, exp_j, tmp; - Word32 L_tmp, L_tmp1, Ltmp_ener; - - exp_L = norm_s(L); - inv_L = div_s(shl(1,sub(14,exp_L)), L); /*Q(29-exp_L) */ - FOR(i=0; i<4; i++) - { - Len = i_mult(L, i); - - L_tmp = L_deposit_l(0); - FOR(j=0; j Q(2*Q_syn) */ - - IF(energyL[i] != 0) - { - exp = norm_l(energyL[i]); - frac = extract_h(L_shl(energyL[i], exp)); - exp = sub(exp, sub(30, shl(Q_syn,1))); - - tmp = div_s(16384, frac); - L_tmp = L_deposit_h(tmp); - L_tmp = Isqrt_lc(L_tmp, &exp); - energyL[i] = L_shl(L_tmp, sub(exp, 16)); - move32();/* Q15 */ - } - } - - FOR(i=0; i<3; i++) - { - L_tmp = Mult_32_16(energyL[i], 29491); /*Q14 */ - test(); - IF(L_sub(L_shr(energyL[i+1], 1), L_tmp) > 0 && L_sub(energyL[i+1], 1638400) > 0) - { - pos = add(i, 1); - move16(); - BREAK; - } - } - - IF (pos > 0) - { - if(sub(pos, 3) < 0) - { - pos = add(pos, 1); - } - energy = L_deposit_l(0); - j = i_mult(L, pos); - move16(); - FOR(i=0; i Q(-exp_j+14 +2*Q_synth) */ - energy_16 = 0; - move16(); - - IF(energy != 0) - { - exp = norm_l(energy); - frac = extract_h(L_shl(energy, exp)); - /*exp = sub(exp, 30-(-exp_j+14 +2*Q_synth)); */ - exp = sub(exp, sub(14, sub(shl(Q_synth, 1), exp_j))); - tmp = div_s(16384, frac); - L_tmp = L_deposit_h(tmp); - energy = Isqrt_lc(L_tmp, &exp); /*Q(31-exp) */ - energy_16 = round_fx(L_shl(energy, sub(exp,15))); /*Q0 */ - } - - tmp = mult_r(energy_16, 6554); /*Q0 */ - if(sub(prev_td_energy, tmp) < 0) - { - prev_td_energy = tmp; - move16(); - } - - tmp_ener = 0; - move16(); - exp = 0; - move16(); - IF(energy_16 != 0) - { - exp = norm_s(energy_16); - tmp_ener = div_s(shl(1,sub(14,exp)), energy_16); /*Q(29-exp) */ - } - L_tmp = L_mult(prev_td_energy, tmp_ener); /*Q(30-exp) */ - tmp_exp = add(1, exp); - FOR (i = 0; i < j; i++) - { - error[i] = round_fx(L_shl(Mult_32_16(L_tmp, error[i]), tmp_exp)); /*Q(30-exp+1-16)->Q(15-exp)->Q_synth */ - } - - energy = L_deposit_l(0); - FOR(i=j; i<(j+L); i++) - { - energy = L_mac0(energy, error[i], error[i]); /*(2*Q_synth) */ - } - - energy = Mult_32_16(energy, inv_L); /*Q(29-exp_L+1-16) -> Q(-exp_L+14) */ - energy_16 = 0; - move16(); - IF(energy != 0) - { - exp = norm_l(energy); - frac = extract_h(L_shl(energy, exp)); - /*exp = sub(exp, 30-(-exp_L+14+2*Q_synth)); */ - exp = sub(exp, sub(14, sub(shl(Q_synth, 1), exp_L))); - - tmp = div_s(16384, frac); - L_tmp = L_deposit_h(tmp); - energy = Isqrt_lc(L_tmp, &exp); /*Q(31-exp) */ - energy_16 = round_fx(L_shl(energy, sub(exp,15))); /*Q0 */ - } - - tmp_ener = 0; - move16(); - exp = 0; - move16(); - IF(energy_16 != 0) - { - exp = norm_s(energy_16); - tmp_ener = div_s(shl(1,sub(14,exp)), energy_16); /*Q(29-exp) */ - } - Ltmp_ener = L_mult(prev_td_energy, tmp_ener); /*Q(30-exp) */ - L_tmp1 = L_shl(1, sub(30, exp)); - - pit = &error[j]; - move16(); - FOR (i = 0; i < L; i++) - { - tmpi = round_fx(L_shl(L_mult(i, inv_L), add(1, exp_L))); /*Q15 */ - L_tmp = L_sub(L_tmp1, Ltmp_ener); /*Q(30-exp) */ - L_tmp = Mult_32_16(L_tmp, tmpi); /*Q(30-exp) */ - L_tmp = L_add(Ltmp_ener, L_tmp); /*Q(30-exp) */ - tmp = round_fx(L_shl(Mult_32_16(L_tmp, *pit), add(1, exp))); /*Q0 */ - *pit++ = tmp; - } - } - - return; -} - -/*-------------------------------------------------------------------* - * calc_normal_length_fx_32() - * - *-------------------------------------------------------------------*/ -void calc_normal_length_fx_32( - const Word16 core, /* i : core : Q0 */ - const Word32 *sp, /* i : input signal : Q12 */ - const Word16 mode, /* i : input mode : Q0 */ - const Word16 extl, /* i : extension layer : Q0 */ - Word16 *L_swb_norm, /* o : normalize length : Q0 */ - Word16 *prev_L_swb_norm /*i/o : last normalize length : Q0 */ -) -{ - Word16 i, n_freq, n_band, THRES; - Word16 L_swb_norm_trans, L_swb_norm_norm, L_swb_norm_harm, L_swb_norm_cur; - Word16 N; - - const Word32 *pit; - Word32 peak, mean, mag; - Word32 L_tmp1, L_tmp2; - - THRES = 4; - move16(); - test(); - test(); - if( sub(core,HQ_CORE) == 0 || sub(extl,SWB_BWE) == 0 || sub(extl,FB_BWE) == 0 ) - { - THRES = 8; - move16(); - } - - N = 16; - move16(); - test(); - test(); - if( sub(core,HQ_CORE) == 0 && (sub(mode,HQ_HARMONIC) == 0 || sub(mode,HQ_HVQ) == 0) ) - { - N = 13; - move16(); - } - - n_band = 0; - move16(); - pit = sp; - move16(); - FOR (i = 0; i < N; i ++) - { - peak = 0; - move16(); - mean = 0; - move16(); - - FOR (n_freq = 0; n_freq < 16; n_freq ++) - { - mag = L_abs(*pit); - if (L_sub(mag , peak) > 0) - { - peak = mag; - move16(); - } - mean = L_add(mean, mag); - pit++; - } - - L_tmp1 = Mult_32_16(peak, shl(15+THRES, 10)); - L_tmp2 = Mult_32_16(mean, shl(THRES, 10)); - test(); - if (L_sub(L_tmp1,L_tmp2) > 0 && L_sub(peak,40960) > 0) - { - n_band = add(n_band, 1); - } - } - - IF( sub(core,ACELP_CORE) == 0 ) - { - L_swb_norm_trans = add(4, shr(n_band, 2)); - L_swb_norm_norm = add(8, shr(n_band, 1)); - L_swb_norm_harm = s_max(add(32, shl(n_band, 1)), 24); - - IF( mode == HARMONIC ) - { - L_swb_norm_cur = L_swb_norm_harm ; - move16(); - } - ELSE IF ( mode == NORMAL ) - { - L_swb_norm_cur = L_swb_norm_norm; - move16(); - } - ELSE - { - L_swb_norm_cur = L_swb_norm_trans; - move16(); - } - - *L_swb_norm = shr(add(L_swb_norm_cur, *prev_L_swb_norm), 1); - move16(); - *prev_L_swb_norm = L_swb_norm_cur; - move16(); - } - ELSE - { - test(); - IF( mode == HQ_HARMONIC || mode == HQ_HVQ ) - { - L_swb_norm_cur = add(32, add(shl(n_band, 1), shr(n_band, 1))); - } - ELSE - { - L_swb_norm_cur = add(8, shr(n_band, 1)); - } - - *L_swb_norm = extract_h(L_add(L_mac(L_mult(L_swb_norm_cur, 3276), *prev_L_swb_norm, 29491),32768)); - *prev_L_swb_norm = L_swb_norm_cur; - move16(); - } - - return; -} - - -/*-------------------------------------------------------------------* - * calc_norm_envelop_fx_32() - * - *-------------------------------------------------------------------*/ -void calc_norm_envelop_fx_32( - const Word32 SWB_signal_fx[], /* i : SWB spectrum : Q12 */ - Word32 *envelope_fx, /* o : normalized envelope : Q16 */ - const Word16 L_swb_norm, /* i : length of envelope : Q0 */ - const Word16 SWB_flength, /* i : Length of input/output : Q0 */ - const Word16 st_offset /* i : offset : Q0 */ -) -{ - Word16 i, lookback, env_index, n_freq, n_lag_now, n_lag, tmp; - - lookback = L_swb_norm/2; - move16(); - env_index = swb_bwe_subband_fx[0]+st_offset; - move16(); - n_lag_now = L_swb_norm; - move16(); - tmp = sub(add(SWB_flength,st_offset),L_swb_norm); - FOR (n_freq = sub(add(swb_bwe_trans_subband_fx[0],st_offset),lookback); n_freqQ20*/ - } - - /* mean vector generation for controlling dynamic range */ - FOR( k =0 ; k < nband_lf; ++k ) - { - energy_fx = 1; - move16(); - - tmp = add(i_mult2(add(k,1),blen),sfidx); - FOR ( i = add(i_mult2(k,blen),sfidx); i < tmp; ++i ) - { - energy_fx = L_add(energy_fx,coeff_out1_fx[i]); - } - exp = sub(norm_l(energy_fx),1); - L_tmp = L_shl(energy_fx,exp); - exp1 = norm_l( L_and(blen, 0x00007fff ) ); - L_tmp1 = L_shl( blen, exp1 ); - logic16(); - mean_vector_fx[k] = Div_32(L_tmp, extract_h(L_tmp1), extract_l(L_shr(L_tmp1,1)) & 0x00007fff); - move32();/*31 + 20 + exp1 - exp2*/ - exp = add(51,sub(exp,exp1)); - mean_vector_fx[k] = L_shl(mean_vector_fx[k], sub(20,exp)); - move32();/*Q12->Q20*/ - } - - /* dynamics control */ - FOR( k =0 ; k < nband_lf; ++k ) - { - tmp = add( i_mult2(add(k,1),blen), sfidx); - FOR ( i = add(i_mult2(k,blen),sfidx); i < tmp; ++i ) - { - L_tmp = L_sub(coeff_out1_fx[i],mean_vector_fx[k]); - exp = norm_l(L_tmp); - L_tmp = L_shl(L_tmp, exp); /* exp+12*/ - exp1 = norm_l(rn_weight0_fx); - L_tmp1 = L_shl(rn_weight0_fx, exp1); /* exp1+10*/ - L_tmp = L_mult( extract_h(L_tmp), extract_h(L_tmp1) ); - L_tmp = L_shr(L_tmp, add(exp,sub(exp1,21) )); /* Q20*/ - coeff_out1_fx[i] = L_sub(coeff_out1_fx[i], L_tmp); - move32(); - } - } - - IF ( sub(hq_generic_exc_clas, HQ_GENERIC_EXC0) == 0 ) - { - bwe_seed = add(add(shl(R[0],3),shl(R[1],2)),add(shl(R[2],1),R[3])); - - FOR ( n_freq = sfidx; n_freq < efidx; n_freq++ ) - { - IF ( signum[n_freq] < 0 ) - { - coeff_out1_fx[n_freq] = L_negate(coeff_out1_fx[n_freq]); - move32(); - } - - IF ( Random(&bwe_seed) < 0 ) - { - coeff_out1_fx[n_freq] = L_negate(coeff_out1_fx[n_freq]); - move32(); - } - } - } - ELSE - { - FOR ( n_freq = sfidx; n_freq < efidx; n_freq++ ) - { - IF ( signum[n_freq] < 0 ) - { - coeff_out1_fx[n_freq] = L_negate(coeff_out1_fx[n_freq]); - move32(); - } - } - } - - /* normalizing modified low frequency spectrum */ - FOR( k =0 ; k < nband_lf; ++k ) - { - energy_fx = 1; - move16(); - tmp = add(i_mult2(add(k,1),blen),sfidx); - FOR ( i = add((i_mult2(k,blen)),sfidx); i < tmp; ++i ) - { - exp = norm_l(coeff_out1_fx[i]); - L_tmp1 = L_shl(coeff_out1_fx[i],exp);/* exp + 12*/ - - L_tmp = Mult_32_32( L_tmp1, L_tmp1); - L_tmp = L_shr( L_tmp, sub(i_mult2(2,exp),11) );/*Q20 */ - energy_fx = L_add( energy_fx, L_tmp ); - } - - exp = norm_l(energy_fx); - L_tmp = L_shl(energy_fx,sub(exp,1)); - exp1 = norm_s(blen); - L_tmp1 = L_shl((Word32)blen,add(exp1,16)); - - L_tmp = Div_32( L_tmp, extract_h(L_tmp1), extract_l( L_shr(L_tmp1,1) ) & 0x00007fff ); - exp = sub( add( 34 , exp ), exp1 ); - L_tmp = L_shr( L_tmp, sub(exp,31) ); - exp = 31; - move16(); - - exp = sub( 31 , exp ); - IF (exp & 0x1) - { - L_tmp = L_shr( L_tmp , 1 ); - exp = add(exp,1); - } - L_tmp = Sqrt_l(L_tmp, &exp1); - exp = add( 31 , sub( shr(exp1,1) , shr(exp,1) ) ); - energy_fx = L_shl(L_tmp, sub(31,exp)); /*Q31*/ - - tmp = add(i_mult2(add(k,1),blen),sfidx); - FOR ( i = add((i_mult2(k,blen)),sfidx); i < tmp; ++i ) - { - IF ( L_sub( L_abs( coeff_out1_fx[i] ), coeff_out1_fx[i] ) != 0 ) - { - s = -1; - move16(); - coeff_out1_fx[i] = L_abs(coeff_out1_fx[i]); - move32(); - } - ELSE - { - s = 0; - move16(); - } - exp = norm_l(coeff_out1_fx[i]); - L_tmp = L_shl(coeff_out1_fx[i],sub(exp,1)); - exp1 = norm_l(energy_fx); - L_tmp1 = L_shl((Word32)energy_fx,exp1); - logic16(); - L_tmp = Div_32( L_tmp, extract_h(L_tmp1), extract_l(L_shr(L_tmp1,1)) & 0x00007fff ); - exp = add ( sub( 19 , exp1 ), exp ); - coeff_out1_fx[i] = L_shl(L_tmp,add(sub(12,exp),15)); - move32(); /* Q12 -> Q27 */ - IF( s ) - { - coeff_out1_fx[i] = L_negate( coeff_out1_fx[i] ); - move32(); - } - } - } - - Copy32(&coeff_out1_fx[HQ_GENERIC_OFFSET], &coeff_out_fx[add(HQ_GENERIC_HIGH0,hq_generic_offset)], HQ_GENERIC_LEN0); - Copy32(&coeff_out1_fx[HQ_GENERIC_OFFSET], &coeff_out_fx[add(HQ_GENERIC_HIGH1,hq_generic_offset)], HQ_GENERIC_LEN0); - - IF ( sub(hq_generic_offset , HQ_GENERIC_FOFFSET_24K4) <= 0) - { - Copy32( &coeff_out1_fx[HQ_GENERIC_LOW0], &coeff_out_fx[add(HQ_GENERIC_HIGH2,hq_generic_offset)], sub(HQ_GENERIC_END_FREQ , HQ_GENERIC_HIGH2) ); - } - - IF ( sub(HQ_mode , HQ_GEN_FB) == 0 ) - { - IF ( sub(hq_generic_offset, HQ_GENERIC_FOFFSET_24K4) <= 0 ) - { - Copy32(&coeff_out1_fx[sub(add(HQ_GENERIC_LOW0 , HQ_GENERIC_END_FREQ),HQ_GENERIC_HIGH2)], &coeff_out_fx[fb_bwe_subband[0]], 160); - } - ELSE - { - Copy32(&coeff_out1_fx[add(HQ_GENERIC_OFFSET , HQ_GENERIC_LEN0)], &coeff_out_fx[fb_bwe_subband[0]], 160); - } - } - - - L_tmp1 = L_deposit_l(0); - L_tmp2 = L_deposit_l(0); - FOR(i=0; i<5; ++i) - { - L_tmp1 = L_add(L_tmp1, L_abs(coeff_out_fx[add(add(HQ_GENERIC_HIGH1,hq_generic_offset),i)])); - L_tmp2 = L_add(L_tmp2, L_abs(coeff_out_fx[sub(add(sub(HQ_GENERIC_HIGH1,2),hq_generic_offset),i)])); - } - - pit1_fx = &coeff_out_fx[add(HQ_GENERIC_HIGH1,hq_generic_offset)]; - L_tmp1 = L_max(L_tmp1,1); - L_tmp2 = L_max(L_tmp2,1); - exp1 = norm_l(L_tmp1); - exp2 = sub(norm_l(L_tmp2), 1); - tmp1_fx = extract_h(L_shl(L_tmp1, exp1)); - tmp2_fx = extract_h(L_shl(L_tmp2, exp2)); - tmp3_fx = div_s(tmp2_fx, tmp1_fx);/*15 + exp2 + 15 - (exp1 + 15) */ - tmp3_fx = shr(tmp3_fx, add(5, sub(exp2, exp1)));/*10 */ - - if (sub(tmp3_fx , 307) < 0) - { - tmp3_fx = 307; - move16(); - } - FOR ( ; tmp3_fx < 1024; tmp3_fx += 102) - { - *pit1_fx = Mult_32_16(*pit1_fx, shl(tmp3_fx, 5)); - move32();/*15 + 5 + 10 -15 */ - pit1_fx++; - } - - pit1_fx = &coeff_out_fx[add(sub(HQ_GENERIC_HIGH1,1),hq_generic_offset)]; - - exp1 = sub(norm_l(L_tmp1), 1); - exp2 = norm_l(L_tmp2); - tmp1_fx = extract_h(L_shl(L_tmp1, exp1)); - tmp2_fx = extract_h(L_shl(L_tmp2, exp2)); - tmp3_fx = div_s(tmp1_fx, tmp2_fx);/*15 + exp2 + 15 - (exp1 + 15) */ - tmp3_fx = shr(tmp3_fx, add(5, sub(exp1, exp2)));/*10 */ - - IF (sub(tmp3_fx , 5120)>0) - { - FOR ( tmp3_fx = 5120; tmp3_fx > 1024; tmp3_fx -= 512) - { - L_tmp1 = Mult_32_16(L_shl(*pit1_fx, 5), tmp3_fx); /*15 + 5 + 10 -15 */ - *pit1_fx-- = L_tmp1; - move32(); - } - } - - IF ( sub(hq_generic_offset , HQ_GENERIC_FOFFSET_24K4) <= 0 ) - { - L_tmp1 = L_add(L_abs(coeff_out_fx[add(HQ_GENERIC_HIGH2 , hq_generic_offset)]), L_abs(coeff_out_fx[add(add(HQ_GENERIC_HIGH2,1),hq_generic_offset)])); - L_tmp2 = L_add(L_abs(coeff_out_fx[add(sub(HQ_GENERIC_HIGH2,4),hq_generic_offset)]), L_add(L_abs(coeff_out_fx[add(sub(HQ_GENERIC_HIGH2,3),hq_generic_offset)]), - L_add( L_abs(coeff_out_fx[add(sub(HQ_GENERIC_HIGH2,2),hq_generic_offset)]), L_abs(coeff_out_fx[add(sub(HQ_GENERIC_HIGH2,1),hq_generic_offset)])))); - - pit1_fx = &coeff_out_fx[add(HQ_GENERIC_HIGH2,hq_generic_offset)]; - - L_tmp1 = L_max(L_tmp1,1); - L_tmp2 = L_max(L_tmp2,1); - exp1 = norm_l(L_tmp1); - exp2 = sub(norm_l(L_tmp2), 1); - tmp1_fx = extract_h(L_shl(L_tmp1, exp1)); - tmp2_fx = extract_h(L_shl(L_tmp2, exp2)); - tmp3_fx = div_s(tmp2_fx, tmp1_fx);/*15 + exp2 + 15 - (exp1 + 15) */ - tmp3_fx = shr(tmp3_fx, add(5, sub(exp2, exp1)));/*10 */ - - if (sub(tmp3_fx, 307) < 0) - { - tmp3_fx = 307; - move16(); - } - FOR ( ; tmp3_fx < 1024; tmp3_fx += 102) - { - L_tmp = L_shl(Mult_32_16(*pit1_fx, tmp3_fx), 5); /*15 + 5 + 10 -15 */ - *pit1_fx++ = L_tmp; - move32(); - } - - pit1_fx = &coeff_out_fx[add(sub(HQ_GENERIC_HIGH2,1),hq_generic_offset)]; - - exp1 = sub(norm_l(L_tmp1), 1); - exp2 = norm_l(L_tmp2); - tmp1_fx = extract_h(L_shl(L_tmp1, exp1)); - tmp2_fx = extract_h(L_shl(L_tmp2, exp2)); - tmp3_fx = div_s(tmp1_fx, tmp2_fx);/*15 + exp2 + 15 - (exp1 + 15) */ - tmp3_fx = shr(tmp3_fx, add(5, sub(exp1, exp2)));/*10 */ - tmp3_fx = shr(tmp3_fx, 1); - tmp4_fx = mult_r(tmp3_fx, 1638); - WHILE (tmp3_fx > 1024) - { - L_tmp1 = Mult_32_16(L_shl(*pit1_fx, 5), tmp3_fx); /*15 + 5 + 10 -15 */ - *pit1_fx-- = L_tmp1; - move32(); - tmp3_fx = sub(tmp3_fx, tmp4_fx); - } - } - - - wfenv_fx = hq_generic_fenv_fx[0]; - move16();/*1 */ - i = 0; - move16(); - tmp2 = add(add(swb_bwe_subband_fx[0],hq_generic_offset),8); - FOR (n_freq = add(swb_bwe_subband_fx[0],hq_generic_offset); n_freq 30 || hq_generic_fenv_fx[nenv] < 10) - { - wfenv_fx = hq_generic_fenv_fx[sub(nenv,1)]; - move16();/*1 */ - FOR ( i=0; n_freq +#include "options.h" +#include "prot.h" + +/*-------------------------------------------------------------------* + * swb_hr_nonzero_subband_noise_fill() + * + * SWB BWE HR noise filling of zero subbands + *-------------------------------------------------------------------*/ + +static void swb_hr_nonzero_subband_noise_fill( + const float tilt_wb, /* i : tilt of wideband signal */ + float *t_audio, /* i/o: mdct spectrum */ + short *bwe_highrate_seed, /* i/o: seed of random noise */ + const short N, /* i : length of subband */ + const short Nsv /* i : number of subband */ +) +{ + short i, j; + float *ptr; + float min_bwe, max_bwe, tmpF; + + if( tilt_wb > 5.0f ) + { + for( i=0; i 0 ) + { + min_bwe = min(tmpF, min_bwe); + max_bwe = max(tmpF, max_bwe); + } + } + + if( max_bwe == min_bwe && min_bwe > 1.0f ) + { + min_bwe *= 0.5f; + } + + ptr = &t_audio[i*N]; + for( j=0; j 0 ) + { + *ptr = 0.5f*min_bwe; + } + else + { + *ptr = -0.5f*min_bwe; + } + } + ptr++; + } + } + } + + return; +} + +/*-------------------------------------------------------------------* + * swb_hr_noise_fill() + * + * SWB BWE HR noise filling + *-------------------------------------------------------------------*/ + +void swb_hr_noise_fill( + const short is_transient, /* i : transient flag */ + const short spect_start, /* i : spectrum start point */ + const short spect_end, /* i : spectrum end point */ + const float tilt_wb, /* i : tilt of wideband signal */ + const float pitch, /* i : pitch value */ + const short nq[], /* i : AVQ nq index */ + short Nsv, /* i : number of subband */ + short *bwe_highrate_seed, /* i/o: seed of random noise */ + float *t_audio /* i/o: mdct spectrum */ +) +{ + short i, j, k; + float alpha, beta; + short pos_start, pos_end, incr; + + if( is_transient ) + { + for( i=0; i 5.0f ) + { + beta = 0.25f; + } + else + { + if( 100 > 0.25f*pitch ) + { + beta = 0.25f; + } + else + { + beta = 100/pitch; + } + } + + i = 0; + if( nq[i] == 0 ) + { + i = 1; + while( i < Nsv && nq[i] == 0 ) + { + i++; + } + + pos_start = i; + + + while( i< Nsv && nq[i] != 0 ) + { + i++; + } + + pos_end = i - 1; + + if( pos_end - pos_start > pos_start ) + { + pos_end = 2*pos_start - 1; + } + + incr = pos_end; + + for( j = pos_start-1; j >= 0; j-- ) + { + for( k=0; k= pos_start; j-- ) + { + for( k=0; k max_samp ) + { + max_samp = (float)fabs(hb_synth[i]); + pos = i; + } + } + + if( pos < 160 ) + { + gain = sum2_f( hb_synth + input_frame - 80, 80 ) + EPSILON; + } + else + { + gain = sum2_f( hb_synth, 80 ) + EPSILON; + } + + gain = (float)sqrt(gain/80); + + ind1 = max(0, pos-40); + ind2 = min( input_frame, pos+40 ); + tmpF = sum2_f( hb_synth + ind1, ind2 - ind1 ) + EPSILON; + tmpF = (float)sqrt( tmpF/(ind2-ind1) ); + + gain = min( 1.0f, gain/tmpF ); + + if( last_extl == SWB_BWE || last_extl == FB_BWE ) + { + for( i = ind1; i < input_frame; i++ ) + { + hb_synth[i] *= gain; + } + } + else + { + for( i = ind1; i < ind2; i++ ) + { + hb_synth[i] *= gain; + } + + if( ind2 != input_frame ) + { + step = 0.0f; + alpha = (gain > 0.5f) ? 1.0f : 0.5f; + beta = (alpha - gain)/(input_frame - ind2); + + for( i = ind2; i < input_frame; i++ ) + { + hb_synth[i] *= (gain + step); + step += beta; + } + } + } + + return( gain ); +} diff --git a/src/libs/libevs/lib_com/swb_bwe_com_hr_fx.cpp b/src/libs/libevs/lib_com/swb_bwe_com_hr_fx.cpp deleted file mode 100755 index 6dee75b4..00000000 --- a/src/libs/libevs/lib_com/swb_bwe_com_hr_fx.cpp +++ /dev/null @@ -1,262 +0,0 @@ -/*==================================================================================== - EVS Codec 3GPP TS26.442 Apr 03, 2018. Version 12.11.0 / 13.6.0 / 14.2.0 - ====================================================================================*/ - -#include "options.h" -#include "prot_fx.h" -#include "stl.h" - -/*-------------------------------------------------------------------* - * swb_hr_nonzero_subband_noise_fill() - * - * SWB BWE HR noise filling of zero subbands - *-------------------------------------------------------------------*/ -static void swb_hr_nonzero_subband_noise_fill_fx( - const Word16 tilt_wb_fx, /* i : tilt of wideband signal */ - Word16 *t_audio_fx, /* i/o: mdct spectrum */ - Word16 *bwe_highrate_seed, /* i/o: seed of random noise */ - const Word16 N, /* i : length of subband */ - const Word16 Nsv, /* i : number of subband */ - Word16 Q_audio -) -{ - Word16 i, j; - Word16 *ptr_fx; - Word16 min_bwe_fx, max_bwe_fx, tmpF_fx; - Word16 tmp; - - IF( sub(tilt_wb_fx, 10240) > 0 ) - { - FOR( i=0; i 0 ) - { - min_bwe_fx = s_min(tmpF_fx, min_bwe_fx); - } - } - - test(); - if( sub(max_bwe_fx, min_bwe_fx) == 0 && sub(min_bwe_fx, shl(1, Q_audio)) > 0 ) - { - min_bwe_fx = mult_r(min_bwe_fx, 16384); - } - - ptr_fx = &t_audio_fx[tmp]; - FOR( j=0; j 0 ) - { - beta_fx = 8192; - move16();/*Q15 */ - } - ELSE - { - IF( sub(6400, pitch_fx) > 0 ) - { - beta_fx = 8192; - move16();/*Q15 */ - } - ELSE - { - beta_fx = div_s(1600, pitch_fx); /*Q15+4-4 ->Q15 */ - } - } - - i = 0; - move16(); - IF( nq[i] == 0 ) - { - i = 1; - move16(); - test(); - WHILE( sub(i, Nsv) < 0 && nq[i] == 0 ) - { - i++; - move16(); - test(); - } - - pos_start = i; - move16(); - test(); - WHILE( sub(i, Nsv) < 0 && nq[i] != 0 ) - { - i++; - move16(); - test(); - } - - pos_end = sub(i, 1); - move16(); - - IF( sub(pos_end, shl(pos_start, 1)) > 0 ) - { - pos_end = sub(shl(pos_start, 1), 1); - move16(); - } - - incr = pos_end; - move16(); - - FOR( j = sub(pos_start, 1); j >= 0; j-- ) - { - tmp = shl(j, 3); - tmp1 = shl(incr, 3); - FOR( k=0; k= pos_start; j-- ) - { - tmp = shl(j, 3); - tmp1 = shl(incr, 3); - FOR( k=0; k +#include +#include "options.h" +#include "cnst.h" +#include "prot.h" +#include "rom_com.h" + + +/*-------------------------------------------------------------------* + * hf_parinitiz() + * + * + *-------------------------------------------------------------------*/ + +void hf_parinitiz( + const long total_brate, + const short hqswb_clas, + short lowlength, + short highlength, + short wBands[], + const short **subband_search_offset, + const short **subband_offsets, + short *nBands, + short *nBands_search, + short *swb_lowband, + short *swb_highband +) +{ + *swb_lowband = lowlength; + *swb_highband = highlength; + + if( hqswb_clas == HQ_HARMONIC ) + { + /* Mode dependent initializations (performed every frame in case mode-switching implemented) */ + *nBands = NB_SWB_SUBBANDS_HAR; + *nBands_search = NB_SWB_SUBBANDS_HAR_SEARCH_SB; + + if ( total_brate == HQ_13k20 ) + { + wBands[0] = SWB_SB_BW_LEN0_12KBPS_HAR; + wBands[1] = SWB_SB_BW_LEN1_12KBPS_HAR; + wBands[2] = SWB_SB_BW_LEN2_12KBPS_HAR; + wBands[3] = SWB_SB_BW_LEN3_12KBPS_HAR; + *subband_offsets = subband_offsets_sub5_13p2kbps_Har; + *subband_search_offset = subband_search_offsets_13p2kbps_Har; + } + else + { + wBands[0] = SWB_SB_BW_LEN0_16KBPS_HAR; + wBands[1] = SWB_SB_BW_LEN1_16KBPS_HAR; + wBands[2] = SWB_SB_BW_LEN2_16KBPS_HAR; + wBands[3] = SWB_SB_BW_LEN3_16KBPS_HAR; + *subband_offsets = subband_offsets_sub5_16p4kbps_Har; + *subband_search_offset = subband_search_offsets_16p4kbps_Har; + } + } + else + { + /* Mode-dependent initializations (performed every frame in case mode-switching implemented) */ + *nBands = NB_SWB_SUBBANDS; + *nBands_search = NB_SWB_SUBBANDS; + + if ( total_brate == HQ_13k20 ) + { + wBands[0] = SWB_SB_LEN0_12KBPS; + wBands[1] = SWB_SB_LEN1_12KBPS; + wBands[2] = SWB_SB_LEN2_12KBPS; + wBands[3] = SWB_SB_LEN3_12KBPS; + *subband_offsets = subband_offsets_12KBPS; + } + else + { + wBands[0] = SWB_SB_LEN0_16KBPS; + wBands[1] = SWB_SB_LEN1_16KBPS; + wBands[2] = SWB_SB_LEN2_16KBPS; + wBands[3] = SWB_SB_LEN3_16KBPS; + *subband_offsets = subband_offsets_16KBPS; + } + } + return; +} + +/*-------------------------------------------------------------------* + * GetPredictedSignal() + * + * Routine for calculating the predicted signal + *-------------------------------------------------------------------*/ +void GetPredictedSignal( + const float *predBuf, /* i : prediction buffer */ + float *outBuf, /* o : output buffer */ + const short lag, /* i : prediction buffer offset */ + const short fLen, /* i : length of loop (output) */ + const float gain /* i : gain to be applied */ +) +{ + short i; + + predBuf += lag; + + for(i = 0; i < fLen; i++) + { + *outBuf++ = *predBuf++ * gain; + } + + return; +} +/*-------------------------------------------------------------------* + * est_freq_har_decis() + * + * Harmonic frequency decision matrix + *-------------------------------------------------------------------*/ +static +void est_freq_har_decis( + short *har_freq_est1, /* o: harmonic analysis 1*/ + short *har_freq_est2, /* o: harmonic analysis 2*/ + short sharp, /* i: pka-avg for group 1 */ + short sharp1, /* i: pka-avg for group 2 */ + short hfe_est_countk1, /* i: group pks count 1*/ + short hfe_est_countk2, /* i: group pks count 2*/ + short k, /* i: group count */ + short k1, + short k2, + short *prev_frm_hfe2 /* i: harmonic estimation */ +) +{ + short temp_hfe2 = 0; + + if( k != 0) + { + *har_freq_est1 = (int) sharp /k; + } + if(k1 > 1) + { + *har_freq_est2 = (int) sharp1 /k1; + } + else if( (k1 < 2 && (k2 != 0 || k>1))) + { + *har_freq_est2 = (int) *har_freq_est1; + } + else + { + if((hfe_est_countk1 != 0 || hfe_est_countk2 != 0) && (k1 == 0 && k2 == 0)) + { + *har_freq_est2 = (*har_freq_est1); + } + else + { + *har_freq_est2 = 2*(*har_freq_est1); + } + } + + /* Consider Estimation Error upto 200Hz */ + if( *prev_frm_hfe2 != 0 && ( (short)abs(*prev_frm_hfe2 - *har_freq_est2) < 10 || abs(*prev_frm_hfe2-2*(*har_freq_est2))<10)) + { + *har_freq_est2 = *prev_frm_hfe2; + } + else if(*prev_frm_hfe2 != 0 && abs(*har_freq_est2-2*(*prev_frm_hfe2))<10) + { + *har_freq_est2 =2*( *prev_frm_hfe2); + } + else + { + temp_hfe2 = (short)(*prev_frm_hfe2+*har_freq_est2)/2; + + if(abs(temp_hfe2 -*prev_frm_hfe2) < 2) + { + temp_hfe2 =*prev_frm_hfe2; + *har_freq_est2 = temp_hfe2; + } + } + if( *har_freq_est2 <*har_freq_est1 && (k>1 && k1<2)) + { + *har_freq_est2 = *har_freq_est1; + } + return; +} + +/*--------------------------------------------------------------------------* + * har_est() + * + * Harmonic Structure analysis using LF spectrum + *--------------------------------------------------------------------------*/ + +short har_est( + float spectra[], /* i : coded spectrum */ + short N, /* i : length of the desired spectrum */ + short *har_freq_est1, /* i/o: Estimation harmonics 1 */ + short *har_freq_est2, /* o : Estimation harmonics 2 */ + short *flag_dis, /* i/o: flag for BWE reconstruction */ + short *prev_frm_hfe2, /* i/o: Estimated harmonic update */ + const short subband_search_offset[],/* i : Subband Search range */ + const short sbWidth[], /* i : Subband Search range */ + short *prev_stab_hfe2 /* i/o: Estimated harmonic position */ +) +{ + float peak; + short i, j, q, k , k1, k2; + float input_abs[L_FRAME32k],blk_peak[30]; + short blk_end,blk_st; + short peak_pos,blk_peak_pos[30],diff_peak_pos[30], sharp, sharp1, sharp2; + int min_har_pos; + short blk_peak_pos_te[30]; + float blk_peak_te[30]; + short temp; + short hfe_est_countk,hfe_est_countk1,hfe_est_countk2; + short r1, r2, r3; + short start_pos; + float blk_peak_max; + short blk_peak_pos_max; + + short nlags, ct_hfsb2,sum_diff=0; + short blk_peak_pos_hfsb2[30],diff_peak_pos_hfsb2[30]; + short rem_hfe2 ,q_diffpos_hfe2 = 0,diff_posmax_hfe2, q_diffpos_prevhfe2; + short blk_peak_max_idx,blk_peak_pos_max_diff,diff_peak_pos_te[30]; + rem_hfe2 = 0; + q_diffpos_hfe2 = 0; + diff_posmax_hfe2 = 0; + q_diffpos_prevhfe2 = 0; + + set_s(blk_peak_pos_te,0,30); + set_s(diff_peak_pos,0,30); + + r1 = SWB_HAR_RAN1; + r2 = SWB_HAR_RAN2; + r3 = SWB_HAR_RAN3; + start_pos =r1; + + /* Copy the abs values of LF spectrum*/ + for ( i = start_pos; i < N; i++) + { + input_abs[i] = (float) fabs(spectra[i]); + } + + blk_end = (short) N/LR_BLK_LEN; + blk_st = (short) start_pos/LR_BLK_LEN; + + if( (float)N/(LR_BLK_LEN) - blk_end > 0.0f) + { + blk_end++; + } + + /* initialization of over buffer for fractional point */ + for(i=N; i<(blk_end*LR_BLK_LEN); i++) + { + input_abs[i] = 0.0f; + } + + q = start_pos; + + /* Block Processing, to detect the spectral peaks*/ + for(i = blk_st; i < blk_end; i++) + { + peak = 0.0f; + peak_pos = 0; + + for(j = 0; j < LR_BLK_LEN; j ++, q ++) + { + if (input_abs[q] > peak) + { + peak = input_abs[q]; + peak_pos = q; + } + + if( i > blk_st && input_abs[q] != 0 && input_abs[q] == peak && (peak_pos - blk_peak_pos[i-1]) < LR_HLF_PK_BLK_LEN ) + { + peak = input_abs[q]; + peak_pos = q; + } + } + + blk_peak[i] = peak; + blk_peak_pos[i] = peak_pos; + } + + for(i = blk_st; i < blk_end; i++) + { + if(i > blk_st) + { + if(blk_peak_pos[i] != 0 && blk_peak_pos[i-1] != 0) + { + if((blk_peak_pos[i] - blk_peak_pos[i-1]) < LR_LOWBAND_DIF_PK_LEN) + { + if(blk_peak[i] > blk_peak[i-1]) + { + blk_peak[i-1] = 0.0f; + blk_peak_pos[i-1] = 0; + } + else + { + blk_peak[i] = blk_peak[i-1]; + blk_peak_pos[i] = blk_peak_pos[i-1]; + blk_peak[i-1] = 0.0f; + blk_peak_pos[i-1] = 0; + } + } + } + } + } + + /* peak counts in each group */ + j = 0; + hfe_est_countk = 0; + hfe_est_countk1 = 0; + hfe_est_countk2 = 0; + for(i = blk_st; i < blk_end; i++) + { + if(blk_peak_pos[i] != 0 ) + { + blk_peak_pos_te[j] = blk_peak_pos[i]; + if( blk_peak_pos[i] blk_peak_max) + { + blk_peak_max = blk_peak_te[i-1]; + blk_peak_pos_max = blk_peak_pos_te[i-1] ; + blk_peak_max_idx = i-1; + } + + temp++; + } + blk_peak_pos_max_diff = diff_peak_pos[blk_peak_max_idx]; + + /* Decision for BWE reconstruction */ + if((hfe_est_countk < 2 && hfe_est_countk1 <2 && hfe_est_countk2 <2 ) || min_har_pos >= SWB_HAR_RAN1) + { + *flag_dis = 0; + if((hfe_est_countk == 1 && hfe_est_countk1 == 1)&& (hfe_est_countk2 == 1 || hfe_est_countk2 == 0)) + { + *flag_dis = 1; + } + } + for(i=0; i 0) + { + sharp += diff_peak_pos[i]; + k++; + } + else if((diff_peak_pos[i] <= (min_har_pos+2*LR_LOWBAND_DIF_PK_LEN)) && diff_peak_pos[i] > 0) + { + sharp1 += diff_peak_pos[i]; + k1++; + } + else if(diff_peak_pos[i] > 0) + { + sharp2 += diff_peak_pos[i]; + k2++; + } + } + + est_freq_har_decis(har_freq_est1,har_freq_est2,sharp,sharp1,hfe_est_countk1,hfe_est_countk2,k,k1,k2,prev_frm_hfe2); + + blk_peak_pos_max = blk_peak_pos_te[temp-1]; + + if((*prev_stab_hfe2) > 0 && (*prev_frm_hfe2) > 0 && *prev_stab_hfe2 < N) + { + rem_hfe2 = *har_freq_est2%(*prev_frm_hfe2); + diff_posmax_hfe2 = (short) abs(blk_peak_pos_max-*prev_stab_hfe2); + if(rem_hfe2 == 0) + { + if(diff_posmax_hfe2 < 9 || *har_freq_est2 == 0) + { + blk_peak_pos_max = *prev_stab_hfe2; + } + else + { + q_diffpos_hfe2 = diff_posmax_hfe2/(*har_freq_est2); + q_diffpos_prevhfe2 = diff_posmax_hfe2/(*prev_frm_hfe2); + if(q_diffpos_hfe2 < 10 || q_diffpos_prevhfe2 < 10) + { + blk_peak_pos_max = *prev_stab_hfe2; + } + else + { + *prev_stab_hfe2 = blk_peak_pos_max; + } + } + } + else + { + *prev_stab_hfe2 = blk_peak_pos_max; + } + } + else + { + *prev_stab_hfe2 = blk_peak_pos_max; + } + + if(*har_freq_est1==0 || *har_freq_est2 ==0) + { + *flag_dis =0; + } + } + + if(*flag_dis == 0) + { + if(*prev_frm_hfe2 != 0) + { + *har_freq_est2 = *prev_frm_hfe2; + } + else + { + nlags = (short)pow(2, bits_lagIndices_mode0_Har[0]); + ct_hfsb2 = 0; + for(i = 0; i < j; i++) + { + if(blk_peak_pos_te[i] >=(subband_search_offset[0]- nlags/2) + && blk_peak_pos_te[i] <(subband_search_offset[0] + sbWidth[0]+ nlags/2)) + { + blk_peak_pos_hfsb2[ct_hfsb2] = blk_peak_pos_te[i]; + ct_hfsb2++; + } + } + + if(ct_hfsb2 >1) + { + for(i=1; i(dst_pos) && ii<(sbWidth[k]+sbWidth[k-1]); j--) + { + xSynth_har[ii] = noise_flr[j]; + tmpbuf[ii] = xSynth_har[ii]; + if(predBuf[j] != 0.0f) + { + hf_pulse_peaks[l] = predBuf[j]; + l++; + } + ii++; + } + } + pos =0; + for(j = 0; j< l; j++) + { + st_last_peakpos+=har_freq_est2; + if(st_last_peakpos< hfband_end[k]) + { + pk_sf[k*8+pos].nmrValue = hf_pulse_peaks[j]; + pk_sf[k*8+pos].gainIndex = st_last_peakpos-fLenLow; + pul_res[k]++; + pulse_peak_sb[i] = hf_pulse_peaks[j]; + i++; + pos++; + } + } + st_last_peakpos = temp_last_peakpos; + } + res=i-1; + l=1; + ii = hfband_end[k-1]-fLenLow-1; + for(; k<(bands-harmonic_band); k++) + { + for(j=hfband_end[k-1]-fLenLow; j<(hfband_end[k]-fLenLow); j++) + { + xSynth_har[j] = tmpbuf[ii]; + tmpbuf[j] = xSynth_har[j]; + ii--; + } + pos=0; + while(st_last_peakpos < hfband_end[k-1]) + { + st_last_peakpos +=har_freq_est2; + } + while(st_last_peakpos < hfband_end[k] && pul_res[k] fLen ) + { + mvr2r( inBuf, outBuf, fLen ); + return; + } + + /* span must be odd */ + if( (span & 0x1) == 0 ) + { + span--; + } + + span1 = span >> 1; + + /* first sample */ + sum = *inBuf; + *outBuf++ = sum; + + oldPtr = inBuf; + newPtr = inBuf + 2; + + /* handle start */ + inBuf++; + sum += *inBuf; + + for( i = 1, nItems = 3; i < span1; i++, inBuf++ ) + { + sum += *newPtr++; + *outBuf++ = sum / nItems; + + sum += *newPtr++; + nItems += 2; + } + + ispan = 1.0f / span; + inBuf++; + i++; + sum += *newPtr++; + *outBuf++ = sum * ispan; + + /* moving average */ + for( ; i < fLen - span1; i++, inBuf++ ) + { + sum += *newPtr++; + sum -= *oldPtr++; + *outBuf++ = sum * ispan; + } + + /* handle end */ + nItems = span - 2; + sum -= *oldPtr++; + + for( ; i < fLen - 1; i++, inBuf++ ) + { + sum -= *oldPtr++; + *outBuf++ = sum / nItems; + nItems -= 2; + sum -= *oldPtr++; + } + + /* last sample */ + *outBuf = *inBuf; + + return; +} + +/*-------------------------------------------------------------------* + * SpectrumSmoothing() + * + * Smoothing of the low-frequency envelope + *-------------------------------------------------------------------*/ + +void SpectrumSmoothing( + float *inBuf, /* i : input */ + float *outBuf, /* o : output */ + const short fLen, /* i : length */ + const float th_cut /* i : threshold of cut */ +) +{ + short i, k; + float inBuf_pss[L_FRAME32k]; + float outBuf_pss[L_FRAME32k]; + float max_val[L_FRAME32k/L_SB]; + float max_val_norm; + float inBuf_abs; + short j; + short num_subband_smooth; + short m, n; + short cnt_zero_cont; + short n_list[BANDS_MAX]; + short reset_flag; + + num_subband_smooth = (short) fLen/L_SB; + if( (float)fLen / L_SB - num_subband_smooth > 0.0f ) + { + num_subband_smooth++; + } + + for( i=0; i subband_search_offsets[0]/L_SB && reset_flag == 0) + { + n = 0; + reset_flag = 1; + } + n_list[n] = j; + n++; + } + + if(reset_flag == 1 && n == 1) + { + m = 0; + } + + if(cnt_zero_cont > 3*L_SB/4) + { + for(i=0; i th_cut) + { + outBuf[i] = outBuf_pss[i]; + } + } + + return; +} + +/*-------------------------------------------------------------------* + * Get20Log10Spec() + * + * Calculates 20*log10() for the specified samples. Input and output buffers can be the same. + *-------------------------------------------------------------------*/ +static +void Get20Log10Spec( + const float *inBuf, /* i : input */ + float *outBuf, /* o : output */ + const short fLen /* i : loop length */ +) +{ + short i; + + for( i = 0; i < fLen; i++, inBuf++ ) + { + *outBuf++ = (float) (20.0f * log10(fabs(*inBuf + 1.0))); + } + + return; +} + +void convert_lagIndices_pls2smp( + short lagIndices_in[], + short nBands_search, + short lagIndices_out[], + const float sspectra[], + const short sbWidth[], + const short fLenLow +) +{ + int sb; + int i, cnt; + + for( sb = 0; sb < nBands_search; sb++ ) + { + cnt = 0; + i = 0; + while( cnt <= lagIndices_in[sb] ) + { + if( sspectra[subband_search_offsets[sb]+i] != 0.0f ) + { + cnt++; + } + + i++; + + if( subband_search_offsets[sb] + i + sbWidth[sb] >= fLenLow ) + { + /* over fLenLow, no need for more search */ + break; + } + } + + lagIndices_out[sb] = (short)i-1+subband_search_offsets[sb]; + } + + return; +} + +int get_usebit_npswb( + short hqswb_clas +) +{ + short i; + short bits; + short up_lmt; + const short *bits_req; + + up_lmt = 0; + bits_req = bits_lagIndices_modeNormal; + bits =0; + if(hqswb_clas == HQ_NORMAL) + { + up_lmt = NB_SWB_SUBBANDS; + bits_req = bits_lagIndices_modeNormal; + } + else if ( hqswb_clas == HQ_HARMONIC ) + { + up_lmt = NB_SWB_SUBBANDS_HAR_SEARCH_SB; + bits_req =bits_lagIndices_mode0_Har; + bits = 2; /*noise gain*/ + } + for( i = 0; i < up_lmt; i++ ) + { + bits += bits_req[i]; + } + + return bits; +} + +void SpectrumSmoothing_nss( + float *inBuf, + float *outBuf, + int fLen +) +{ + int i, k; + float inBufw[L_FRAME32k+L_SB_NSS]; + float outBufw[L_FRAME32k+L_SB_NSS]; + float temp_sum_1[NUM_SUBBAND_SMOOTH_MAX]; + float temp_sum_2[NUM_SUBBAND_SMOOTH_MAX]; + float temp_sum_3[NUM_SUBBAND_SMOOTH_MAX]; + float temp_sum_log[NUM_SUBBAND_SMOOTH_MAX]; + float temp_sum_smooth[NUM_SUBBAND_SMOOTH_MAX]; + float temp_sum_div[NUM_SUBBAND_SMOOTH_MAX]; + short num_subband_smooth; + float smr, avg_val, r0; + float clip_cof, avg_val2, thre; + float thre_min; + float max_peak; + + /* calculate subband number */ + num_subband_smooth = (short)(fLen/L_SB_NSS); + if( fLen/(L_SB_NSS + 0.0f) - num_subband_smooth > 0.0f ) + { + num_subband_smooth++; + } + + /* buffer copy for fractional point */ + for( i = 0; i < fLen; i++ ) + { + inBufw[i] = inBuf[i]; + outBufw[i] = 0.0f; + } + + /* initialization of over buffer for fractional point */ + for( i = fLen; i < fLen + L_SB_NSS; i++ ) + { + inBufw[i] = 0.0f; + outBufw[i] = 0.0f; + } + + avg_val = 0.0f; + for( i = 0; i < fLen; i++ ) + { + r0 = (float)fabs(inBufw[i]); + avg_val += r0; + } + avg_val /= (float)fLen; + + max_peak = 0.0f; + for( i = 0; i < fLen; i++ ) + { + r0 = (float)fabs(inBufw[i]); + if( max_peak < r0 ) + { + max_peak = r0; + } + } + + smr = 10.0f * (float)log10( max_peak/(avg_val + 1.0e-20) + 1.0e-20 ); + + for( i = 0; i < num_subband_smooth; i++ ) + { + temp_sum_1[i] = 0.0; + temp_sum_2[i] = 0.0; + + for( k = 0; k < L_SB_NSS_HALF; k++ ) + { + temp_sum_1[i] += (float)(fabs(inBufw[k + L_SB_NSS * i])); + } + + for( k = L_SB_NSS_HALF; k < L_SB_NSS; k++ ) + { + temp_sum_2[i] += (float)(fabs(inBufw[k + L_SB_NSS * i])); + } + + temp_sum_1[i] *= 0.25f; + temp_sum_2[i] *= 0.25f; + temp_sum_3[i] = temp_sum_1[i] * temp_sum_2[i]; + + if( temp_sum_3[i] == 0.0f ) + { + temp_sum_3[i] = temp_sum_1[i] + temp_sum_2[i]; + } + } + + Get20Log10Spec( temp_sum_3, temp_sum_log, num_subband_smooth ); + + for( i = 0; i < num_subband_smooth; i++ ) + { + temp_sum_log[i] *= 0.5f; + } + + SmoothSpec( temp_sum_log, temp_sum_smooth, num_subband_smooth, MA_LEN ); + + for (i = 0; i < num_subband_smooth; i++) + { + temp_sum_div[i] = (float)pow(10, -1.0f * temp_sum_smooth[i]/20); + } + + for (i = 0; i < num_subband_smooth; i++) + { + for (k = 0; k < L_SB_NSS; k++) + { + outBufw[k + L_SB_NSS * i] = inBufw[k + L_SB_NSS * i] * temp_sum_div[i]; + } + } + + avg_val2 = 0.0f; + for( i = 0; i < fLen; i++ ) + { + r0 = (float)fabs(outBufw[i]); + avg_val2 += r0; + } + avg_val2 /= (float)fLen; + + clip_cof = smr - 16.0f; + if( clip_cof < 0.0f ) + { + clip_cof = 0.0f; + } + clip_cof += 2.5f; + + thre = avg_val2 * clip_cof; + thre_min = avg_val2 * 0.25f; + for(i = 0; i < fLen; i++) + { + if( fabs(outBufw[i]) > thre ) + { + if( outBufw[i] < 0.0f ) + { + outBufw[i] = -1.0f*thre; + } + else + { + outBufw[i] = thre; + } + } + + if( fabs(outBufw[i]) < thre_min ) + { + outBufw[i] = 0.0f; + } + } + + for(i = 0; i < fLen; i++) + { + outBuf[i] = outBufw[i]; + } + + return; +} + +static float get_sigma( + float x_abs[], + float avg, + int length +) +{ + int i; + float d; + float sigma; + + d = 0; + for( i=0; i thr ) + { + g[peak_cnt].nmrValue = abs_in[j]; + g[peak_cnt].gainIndex = j; + abs_in[j] = 0.0f; + peak_cnt++; + } + + if( peak_cnt == N_NBIGGESTSEARCH ) + { + break; + } + } + } + + thr *= (0.3f / N_NBIGGESTSEARCH) * peak_cnt + 0.7f; + + if( peak_cnt < N_NBIGGESTSEARCH ) + { + for (j = 0; j < nIdx; j++) + { + if( abs_in[j] > thr ) + { + g[peak_cnt].nmrValue = abs_in[j]; + g[peak_cnt].gainIndex = j; + abs_in[j] = 0.0f; + peak_cnt++; + } + + if( peak_cnt == N_NBIGGESTSEARCH ) + { + break; + } + } + } + + thr *= (0.6f / N_NBIGGESTSEARCH) * peak_cnt + 0.3f; + if( peak_cnt < N_NBIGGESTSEARCH ) + { + for (j = 0; j < nIdx; j++) + { + if( abs_in[j] > thr ) + { + g[peak_cnt].nmrValue = abs_in[j]; + g[peak_cnt].gainIndex = j; + abs_in[j] = 0.0f; + peak_cnt++; + } + + if( peak_cnt == N_NBIGGESTSEARCH ) + { + break; + } + } + } + + *n = peak_cnt; + + return; +} + +/*--------------------------------------------------------------------------* + * spectrumsmooth_noiseton() + * Spectrum normalization for the the core coder + *--------------------------------------------------------------------------*/ +float spectrumsmooth_noiseton( + float spectra[], /* i : core coder */ + const float spectra_ni[], /* i : core coder with sparse filling */ + float sspectra[], /* o : Smoothed tonal information from core coder */ + float sspectra_diff[], /* o : non tonal infomration for gap filling */ + float sspectra_ni[], /* o : smoothed core coder */ + const short fLenLow, /* i : low frequency boundaries */ + short *ni_seed /* io : random seed */ +) +{ + float spectra_diff[L_FRAME32k]; + float ni_ratio,ss_min,cut_sig_th,cut_ni_th; + short i,pcnt,sign; + float spectra_rm[L_FRAME32k]; + float cut_input=0.1f; + float rand_a[L_FRAME32k]; + + /* pre-prepare random array for float-fix interoperability */ + for(i=0; i cut_input ) + { + spectra_rm[i] = spectra[i]; + } + } + SpectrumSmoothing( spectra_rm, sspectra, fLenLow, cut_sig_th); + /*Extract noise informaton from the core coder*/ + mvr2r(sspectra, sspectra_ni, fLenLow); + for(i=0; i cut_input ) + { + spectra_rm[i] = spectra_diff[i]; + } + } + SpectrumSmoothing( spectra_rm, sspectra_diff, fLenLow, cut_ni_th); + /*Normalized corecoder for Gap filling */ + for(i=0; i ss_min ) + { + sspectra[i] =sign*((10-ss_min)/10.0f*(float)fabs(sspectra[i])+ss_min); + } + if(sspectra[i] != 0.0) + { + sspectra_ni[i] = sspectra[i]; + } + else + { + sspectra_ni[i] = sspectra_diff[i]*ni_ratio; + } + if( sspectra_ni[i] == 0.0f) + { + sspectra_ni[i] = 0.5f*10.0f*ni_ratio* rand_a[i]; + } + } + return(ss_min); +} + +/*--------------------------------------------------------------------------* + * noiseinj_hf() + * level adjustments for the missing bands in the core coder + *--------------------------------------------------------------------------*/ + +void noiseinj_hf( + float xSynth_har[], /* o : gap filled information */ + float th_g[], /* i : level adjustment information */ + float band_energy[], /* i : subband energies */ + float *prev_En_sb, /* i/o: band Energies */ + const short p2a_flags[], /* i : Missing bands in the core coder */ + short BANDS, /* i : total bands */ + short band_start[], /* i : band start indices */ + short band_end[], /* i : band end indices */ + const short fLenLow /* i : low frequency bandwidth */ +) +{ + + float *p_En,ni_scale,*p_Enn_sm_sb,En[NB_SWB_SUBBANDS],Enn_sm_sb[NB_SWB_SUBBANDS]; + short k,i; + + short map_pulse_t[L_FRAME32k]; + short map_pulse[L_FRAME32k]; + + set_s(map_pulse_t, 0, band_end[BANDS-1]+1); + set_s(map_pulse, 0, band_end[BANDS-1]+1); + /*level adjust the missing bands in the core coder */ + p_En = En; + for(k=BANDS-NB_SWB_SUBBANDS; k(*prev_ni_ratio)) + { + ni_ratio = 0.8f*ni_ratio_cur +(*prev_ni_ratio)*0.2f; + } + else + { + ni_ratio = 0.6f*ni_ratio_cur +(*prev_ni_ratio)*0.4f; + } + } + else + { + ni_ratio = 0.7f*ni_ratio_cur; + } + *prev_ni_ratio =ni_ratio; + + for(i=0; i=0 ) + { + pos++; + } + count_pos_end = pos; + pul_res_bnd[k] = count_pos_end-count_pos_st; + if(pul_res_bnd[k] >0) + { + peak[k]=(float) fabs(sb_ton[count_pos_st]); + } + k++; + } + while(k= 0.12f) ? 0.05f*ni_gain[k] : 1.0f*ni_gain[k], 1.4f); + + for(j=band_start[i]; j<=band_end[i]; j++) + { + xSynth_har[j-fLenLow] *=ni_gain[k]; + } + E = sum2_f(&xSynth_har[band_start[i]-fLenLow],band_width[i]); /*noise energy*/ + } + k++; + be_tonal[i] = (float) pow (2.0f, band_energy[i])- E; /*tonal energy*/ + + if(be_tonal[i] <0.0f) + { + E=0; + for(j=(band_start[i]-fLenLow); j<=(band_end[i]-fLenLow); j++) + { + xSynth_har[j]*=0.25f; + E+=xSynth_har[j]*xSynth_har[j]; + } + be_tonal[i] = (float) pow (2.0f, band_energy[i])- E; /*tonal energy*/ + } + } + return; +} + +/*--------------------------------------------------------------------------* + * Gettonl_scalfact() + * Gap filling for the core coder + *--------------------------------------------------------------------------*/ +void Gettonl_scalfact ( + float *outBuf, /* o : synthesized spectrum */ + const float *codbuf, /* i : core coder */ + const short fLenLow, /* i : lowband length */ + const short fLenHigh, /* i : highband length */ + short harmonic_band, /* i : total number of Low frequency bands */ + short bands, /* i : total number of subbands in a frame */ + float *band_energy, /* i : band energy of each subband */ + short *band_start, /* i : subband start indices */ + short *band_end, /* i : subband end indices */ + const short p2aflags[], /* i : missing bands in the core coder */ + float be_tonal[], /* i : tonal energy */ + GainItem *pk_sf, /* i : toanl information for Sparse filling */ + short *pul_res_pk /* i : pulse resolution information */ +) +{ + short k,i,band_pos; + short sb_ton_loc[SWB_HAR_RAN1]; + short pos_tmp; + float sb_ton[SWB_HAR_RAN1],est_ton_ene[NB_SWB_SUBBANDS],ton_sf; + float step,enrd_r = 0.9f; + float band_sf[SWB_HAR_RAN1]; + short pos,count_pos_st,count_pos_end,j; + + set_f(est_ton_ene,0.0f,NB_SWB_SUBBANDS); + set_s(sb_ton_loc, -1,SWB_HAR_RAN1); + /* Get the tonal information for sparse filling */ + pos=0; + for(k=0; k=0 ) + { + pos++; + } + count_pos_end = pos; + for(i=count_pos_st; i 0.0f) + { + ton_sf= (float) sqrt(be_tonal[band_pos]/est_ton_ene[k]); + } + for(i=count_pos_st; i 0.0f ) + { + enrd_r *= (float)sqrt(be_tonal[band_pos]/pow(2.0f,band_energy[band_pos])); + } + else + { + enrd_r = 0.0f; + } + enrd_r -=step; + if(p2aflags[band_pos] == 1) + { + for(i= band_start[band_pos]; i<=band_end[band_pos]; i++) + { + outBuf[i-fLenLow] = codbuf[i]; + } + } + else + { + pos =0; + pos+=pos_tmp; + for(j=0; j predBufLen ) + { + /* should never happen */ + lag = predBufLen - fLen; + } + + GetPredictedSignal( predBuf, outBuf, lag, fLen, lagGains[sb]); + outBuf += fLen; + } + + outBuf = ptr_in_outBuf; + + return; +} + + +/*--------------------------------------------------------------------------* + * GetlagGains() + * + * + *--------------------------------------------------------------------------*/ + +void GetlagGains( + const float *predBuf, /* i: predictve buffer */ + const float *band_energy, /* i: band Energies */ + const short nBands, /* i: high frequency bands */ + const short *sbWidth, /* i: high frequency band resolution */ + const short *lagIndices, /* i: correlation indices */ + const short predBufLen, /* i: predictive buffer length */ + float *lagGains /* o: lag gains */ +) +{ + short i; + short sb, fLen, lag; + float outBuf[L_FRAME32k]; + float lagEnergy; + + /* Get the gain information for the missing bands*/ + for( sb = 0; sb < nBands; sb++ ) + { + fLen = sbWidth[sb]; + lag = lagIndices[sb]; + + if(lag + fLen > predBufLen) + { + /* should never happen */ + lag = predBufLen - fLen; + } + + GetPredictedSignal( predBuf, outBuf, lag, fLen, 1.0 ); + + lagEnergy = 0.0f; + for( i=0; i length ) + { + set_f( t_audio + length, 0.0f, inner_frame - length ); + } + } + else /* transient frame */ + { + if( inner_frame == length || bws_cnt > 0) + { + /* Copy the scratch buffer to the output */ + mvr2r( y2, t_audio, length ); + } + else + { + /* un-collapse transient frame and interleave zeros */ + for( i = 0; i < NUM_TIME_SWITCHING_BLOCKS; i++ ) + { + k1 = i*length/NUM_TIME_SWITCHING_BLOCKS; + k2 = i*inner_frame/NUM_TIME_SWITCHING_BLOCKS; + + mvr2r( y2 + k1, t_audio + k2, length/NUM_TIME_SWITCHING_BLOCKS ); + set_f( t_audio + k2 + length/NUM_TIME_SWITCHING_BLOCKS, 0.0f, (inner_frame-length)/NUM_TIME_SWITCHING_BLOCKS ); + } + } + } + + /* update */ + if( (bwe_br == HQ_16k40 || bwe_br == HQ_13k20) && bwidth == SWB ) + { + *prev_hqswb_clas = hqswb_clas; + if( hqswb_clas != HQ_HARMONIC ) + { + *prev_frm_hfe2 = 0; + *prev_stab_hfe2 = 0; + } + } + else + { + *prev_hqswb_clas = is_transient; + } + + if((bwe_br == HQ_16k40 ||bwe_br == HQ_13k20) && bwidth == SWB && hqswb_clas == HQ_NORMAL ) + { + j = 0; + for(k=bands-SPT_SHORTEN_SBNUM; k -#include "options.h" -#include "cnst_fx.h" - -#include "prot_fx.h" -#include "rom_com_fx.h" -#include "stl.h" /* required for wmc_tool */ -#include "basop_mpy.h" - -#include - -/*-------------------------------------------------------------------* - * GetPredictedSignal() - * - * Routine for calculating the predicted signal - *-------------------------------------------------------------------*/ -void GetPredictedSignal_fx( - const Word16 *predBuf_fx, /* i: Q8 */ - Word32 *L_outBuf, /* o: Q9 */ - const Word16 lag_fx, /* i: Q0 */ - const Word16 fLen_fx, /* i: Q0 */ - const Word16 lagGains_fx, /* i: Qgain */ - const Word16 Qgain /* i: Q0 */ -) -{ - Word16 i; - const Word16 *p_predBuf; - Word32 *p_L_outBuf; - - p_predBuf = predBuf_fx + lag_fx; - p_L_outBuf = L_outBuf; - - FOR (i=0; i Q9, 9+7-16=Q0 */ - *p_L_outBuf++ = L_shr(L_mult(*p_predBuf++, lagGains_fx), Qgain); - move32(); - } -} - -/*-------------------------------------------------------------------* - * est_freq_har_decis_fx() - * - * Harmonic frequency decision matrix - *-------------------------------------------------------------------*/ -static -void est_freq_har_decis_fx( - Word16 *har_freq_est1, /* o: harmonic analysis 1 */ - Word16 *har_freq_est2, /* o: harmonic analysis 2 */ - Word16 sharp, /* i: pka-avg for group 1 */ - Word16 sharp1, /* i: pka-avg for group 2 */ - Word16 hfe_est_countk1, /* i: group pks count 1 */ - Word16 hfe_est_countk2, /* i: group pks count 2 */ - Word16 k, /* i: group count */ - Word16 k1, /* i: */ - Word16 k2, /* i: */ - Word16 *prev_frm_hfe2 /* i: harmonic estimation */ -) -{ - Word16 temp_hfe2 = 0; - Word16 har_freq_est2_2; - Word16 prev_frm_hfe2_2; - - IF( k != 0 ) - { - *har_freq_est1 = div_s_ss(sharp, k); - } - - test(); - test(); - IF( sub(k1, 1) > 0 ) - { - *har_freq_est2 = div_s_ss(sharp1, k1); - } - ELSE IF( sub(k1, 2) < 0 && ( k2 != 0 || sub(k, 1) > 0) ) - { - *har_freq_est2 = *har_freq_est1; - move16(); - } - ELSE - { - test(); - test(); - test(); - IF((hfe_est_countk1 != 0 || hfe_est_countk2 != 0) && (k1 == 0 && k2 == 0)) - { - *har_freq_est2 = (*har_freq_est1); - move16(); - } - ELSE - { - *har_freq_est2 = shl(*har_freq_est1, 1); - move16(); - } - } - - /* Consider Estimation Error upto 200Hz */ - test(); - test(); - test(); - har_freq_est2_2 = shl(*har_freq_est2, 1); - prev_frm_hfe2_2 = shl(*prev_frm_hfe2, 1); - IF( *prev_frm_hfe2 != 0 && ( sub(abs_s(sub(*prev_frm_hfe2, *har_freq_est2)), 10) < 0 || sub(abs_s(sub(*prev_frm_hfe2, har_freq_est2_2)),10) < 0 ) ) - { - *har_freq_est2 = *prev_frm_hfe2; - move16(); - } - ELSE IF(*prev_frm_hfe2 != 0 && sub(abs_s(sub(*har_freq_est2, prev_frm_hfe2_2)), 10) < 0) - { - *har_freq_est2 = prev_frm_hfe2_2; - move16(); - } - ELSE - { - temp_hfe2 = shr(add(*prev_frm_hfe2, *har_freq_est2), 1); - move16(); - - IF( sub(abs_s(sub(temp_hfe2, *prev_frm_hfe2)), 2) < 0 ) - { - temp_hfe2 =*prev_frm_hfe2; - move16(); - *har_freq_est2 = temp_hfe2; - move16(); - } - } - - test(); - test(); - if( sub(*har_freq_est2, *har_freq_est1) < 0 && ( sub(k, 1) > 0 && sub(k1, 2) < 0 ) ) - { - *har_freq_est2 = *har_freq_est1; - move16(); - } - - return; -} - -/*--------------------------------------------------------------------------* - * har_est_fx() - * - * Harmonic Structure analysis using LF spectrum - *--------------------------------------------------------------------------*/ - -Word16 har_est_fx( - Word32 L_spectra[], /* i : coded spectrum */ - Word16 N, /* i : length of the desired spectrum */ - Word16 *har_freq_est1, /* i/o: Estimation harmonics 1 */ - Word16 *har_freq_est2, /* o : Estimation harmonics 2 */ - Word16 *flag_dis, /* i/o: flag for BWE reconstruction */ - Word16 *prev_frm_hfe2, /* i/o: Estimated harmonic update */ - const Word16 subband_search_offset[], /* i : Subband Search range */ - const Word16 sbWidth[], /* i : Subband Search range */ - Word16 *prev_stab_hfe2 /* i/o: Estimated harmonic position */ -) -{ - Word32 L_peak; - Word32 L_input_abs[L_FRAME32k], L_blk_peak[30]; - Word32 L_blk_peak_te[30]; - Word32 L_blk_peak_max; - Word32 *p_L_blk_peak, *pm1_L_blk_peak; - - Word16 i, j, q, k , k1, k2; - Word16 blk_end,blk_st; - Word16 peak_pos,blk_peak_pos[30], diff_peak_pos[30], sharp, sharp1, sharp2; - Word16 min_har_pos; - Word16 blk_peak_pos_te[30]; - Word16 temp; - Word16 hfe_est_countk,hfe_est_countk1,hfe_est_countk2; - Word16 r1, r2, r3; - Word16 start_pos; - Word16 blk_peak_pos_max; - - Word16 nlags, nlags_half, ct_hfsb2,sum_diff; - Word16 blk_peak_pos_hfsb2[30],diff_peak_pos_hfsb2[30]; - Word16 rem_hfe2 ,q_diffpos_hfe2, diff_posmax_hfe2, q_diffpos_prevhfe2; - - Word16 blk_end_LEN; - - Word16 *p_blk_peak_pos, *pm1_blk_peak_pos; - Word16 *p_diff_peak_pos,*pm1_diff_peak_pos; - Word16 blk_peak_max_idx, blk_peak_pos_max_diff, diff_peak_pos_te[30]; - Word16 thr1, thr2; - - set32_fx(L_input_abs, 0x0L, L_FRAME32k); - set32_fx(L_blk_peak, 0x0L, 30); - set16_fx(blk_peak_pos, 0, 30); - set16_fx(blk_peak_pos_te, 0, 30); - - rem_hfe2 = 0; - move16(); - q_diffpos_hfe2 = 0; - move16(); - diff_posmax_hfe2 = 0; - move16(); - q_diffpos_prevhfe2 = 0; - move16(); - - set16_fx(diff_peak_pos,0,30); - - r1 = SWB_HAR_RAN1; - move16(); - r2 = SWB_HAR_RAN2; - move16(); - r3 = SWB_HAR_RAN3; - move16(); - start_pos = r1; - move16(); - - /* Copy the abs values of LF spectrum*/ - FOR ( i = start_pos; i < N; i++) - { - L_input_abs[i] = L_abs(L_spectra[i]); - move32(); - } - - blk_end = div_s_ss(N, LR_BLK_LEN); - blk_st = div_s_ss(start_pos, LR_BLK_LEN); - - /*if( N/(LR_BLK_LEN) - blk_end > 0.0f) */ - blk_end_LEN = i_mult(blk_end, LR_BLK_LEN); - if( sub(N, blk_end_LEN) > 0 ) - { - blk_end = add(blk_end, 1); - } - - /* initialization of over buffer for fractional point */ - temp = i_mult(blk_end, LR_BLK_LEN); - FOR(i=N; i 0x0L ) - { - L_peak = L_input_abs[q]; - move32(); - peak_pos = q; - move16(); - } - - test(); - test(); - test(); - IF( sub(i, blk_st) > 0 && L_input_abs[q] != 0x0L && L_sub(L_input_abs[q], L_peak) == 0 && sub(sub(peak_pos, blk_peak_pos[i-1]), LR_HLF_PK_BLK_LEN) < 0 ) - { - L_peak = L_input_abs[q]; - move32(); - peak_pos = q; - move16(); - } - q = add(q, 1); - } - - L_blk_peak[i] = L_peak; - move32(); - blk_peak_pos[i] = peak_pos; - move16(); - } - - p_L_blk_peak = &L_blk_peak[blk_st]; - pm1_L_blk_peak = &L_blk_peak[sub(blk_st, 1)]; - p_blk_peak_pos = &blk_peak_pos[blk_st]; - pm1_blk_peak_pos = &blk_peak_pos[sub(blk_st, 1)]; - FOR(i = blk_st; i < blk_end; i++) - { - IF( sub(i, blk_st) > 0 ) - { - - test(); - IF( *p_blk_peak_pos != 0 && *pm1_blk_peak_pos != 0 ) - { - IF( sub(sub(*p_blk_peak_pos, *pm1_blk_peak_pos), LR_LOWBAND_DIF_PK_LEN) < 0 ) - { - IF( L_sub(*p_L_blk_peak, *pm1_L_blk_peak) > 0 ) - { - *pm1_L_blk_peak = L_deposit_l(0); - *pm1_blk_peak_pos = 0; - move16(); - } - ELSE - { - *p_L_blk_peak = *pm1_L_blk_peak; - move32(); - *p_blk_peak_pos = *pm1_blk_peak_pos; - move16(); - *pm1_L_blk_peak = L_deposit_l(0); - *pm1_blk_peak_pos = 0; - move16(); - } - } - } - } - p_L_blk_peak++; - pm1_L_blk_peak++; - - p_blk_peak_pos++; - pm1_blk_peak_pos++; - } - - /* peak counts in each group */ - j = 0; - move16(); - hfe_est_countk = 0; - move16(); - hfe_est_countk1 = 0; - move16(); - hfe_est_countk2 = 0; - move16(); - FOR(i = blk_st; i < blk_end; i++) - { - IF(blk_peak_pos[i] != 0 ) - { - blk_peak_pos_te[j] = blk_peak_pos[i]; - move16(); - IF( sub(blk_peak_pos[i], r2) < 0 ) - { - hfe_est_countk = add(hfe_est_countk, 1); - } - ELSE IF( sub(blk_peak_pos[i], r3) < 0 ) - { - hfe_est_countk1 = add(hfe_est_countk1, 1); - } - ELSE - { - hfe_est_countk2 = add(hfe_est_countk2, 1); - } - L_blk_peak_te[j] = L_blk_peak[i]; - move32(); - j = add(j, 1); - } - } - - min_har_pos = SWB_HAR_RAN1; - move16(); - temp = 0; - move16(); - L_blk_peak_max = L_blk_peak_te[0]; - move32(); - blk_peak_pos_max = blk_peak_pos_te[0] ; - move16(); - blk_peak_max_idx = 0; - move16(); - - - p_diff_peak_pos = &diff_peak_pos[1]; - pm1_diff_peak_pos = &diff_peak_pos[1-1]; - FOR(i = 1; i < j; i++) - { - *pm1_diff_peak_pos = sub(blk_peak_pos_te[i], blk_peak_pos_te[sub(i,1)]); - if( sub(*pm1_diff_peak_pos, min_har_pos) <= 0 ) - { - min_har_pos = *pm1_diff_peak_pos; - move16(); - } - - IF( L_sub(L_blk_peak_te[sub(i,1)], L_blk_peak_max) > 0x0L ) - { - L_blk_peak_max = L_blk_peak_te[sub(i,1)]; - move32(); - blk_peak_pos_max = blk_peak_pos_te[sub(i,1)]; - move16(); - blk_peak_max_idx = sub(i,1); - } - - temp = add(temp, 1); - - p_diff_peak_pos++; - pm1_diff_peak_pos++; - } - blk_peak_pos_max_diff = diff_peak_pos[blk_peak_max_idx]; - move16(); - - /* Decision for BWE reconstruction */ - test(); - test(); - test(); - IF((sub(hfe_est_countk, 2) < 0 && sub(hfe_est_countk1, 2) < 0 && sub(hfe_est_countk2, 2) <0 ) || sub(min_har_pos, SWB_HAR_RAN1) >= 0 ) - { - *flag_dis = 0; - move16(); - test(); - test(); - test(); - if( (sub(hfe_est_countk, 1) == 0 && sub(hfe_est_countk1, 1) == 0) && (sub(hfe_est_countk2, 1) == 0 || hfe_est_countk2 == 0) ) - { - *flag_dis = 1; - move16(); - } - } - thr1 = add(blk_peak_pos_max_diff, LR_LOWBAND_DIF_PK_LEN); - FOR(i=0; i 0) - { - sharp = add(sharp, diff_peak_pos[i]); - k = add(k, 1); - } - ELSE IF( sub(diff_peak_pos[i], thr2) <= 0 && diff_peak_pos[i] > 0) - { - sharp1 = add(sharp1, diff_peak_pos[i]); - k1 = add(k1, 1); - } - ELSE IF ( diff_peak_pos[i] > 0 ) - { - sharp2 = add(sharp2, diff_peak_pos[i]); - k2 = add(k2, 1); - } - q = add(q, 1); - } - - est_freq_har_decis_fx(har_freq_est1,har_freq_est2,sharp,sharp1,hfe_est_countk1,hfe_est_countk2,k,k1,k2,prev_frm_hfe2); - - blk_peak_pos_max = blk_peak_pos_te[sub(temp,1)]; - move16(); - - test(); - test(); - IF((*prev_stab_hfe2) > 0 && (*prev_frm_hfe2) > 0 && *prev_stab_hfe2 < N) - { - rem_hfe2 = sub(*har_freq_est2, extract_h(L_shl(L_mult(div_s_ss(*har_freq_est2, *prev_frm_hfe2), *prev_frm_hfe2), 15))); - diff_posmax_hfe2 = abs_s(sub(blk_peak_pos_max, *prev_stab_hfe2)); - IF( rem_hfe2 == 0 ) - { - test(); - IF( sub(diff_posmax_hfe2, 9) < 0 || *har_freq_est2 == 0 ) - { - blk_peak_pos_max = *prev_stab_hfe2; - move16(); - } - ELSE - { - q_diffpos_hfe2 = div_s_ss(diff_posmax_hfe2, *har_freq_est2); - q_diffpos_prevhfe2 = div_s_ss(diff_posmax_hfe2, *prev_frm_hfe2); - test(); - IF( sub(q_diffpos_hfe2, 10) < 0 || sub(q_diffpos_prevhfe2, 10) < 0) - { - blk_peak_pos_max = *prev_stab_hfe2; - move16(); - } - ELSE - { - *prev_stab_hfe2 = blk_peak_pos_max; - move16(); - } - } - } - ELSE - { - *prev_stab_hfe2 = blk_peak_pos_max; - move16(); - } - } - ELSE - { - *prev_stab_hfe2 = blk_peak_pos_max; - move16(); - } - - test(); - if( *har_freq_est1 == 0 || *har_freq_est2 == 0 ) - { - *flag_dis = 0; - move16(); - } - } - - IF( *flag_dis == 0 ) - { - IF( *prev_frm_hfe2 != 0 ) - { - *har_freq_est2 = *prev_frm_hfe2; - move16(); - } - ELSE - { - nlags = shl(1, bits_lagIndices_mode0_Har_fx[0]); - nlags_half = shr(nlags, 1); - ct_hfsb2 = 0; - move16(); - FOR(i = 0; i < j; i++) - { - test(); - IF( sub(blk_peak_pos_te[i], sub(subband_search_offset[0], nlags_half)) >= 0 - && - sub(blk_peak_pos_te[i], add(add(subband_search_offset[0], sbWidth[0]), nlags_half)) < 0) - { - blk_peak_pos_hfsb2[ct_hfsb2] = blk_peak_pos_te[i]; - move16(); - ct_hfsb2 = add(ct_hfsb2, 1); - move16(); - } - } - - IF( sub(ct_hfsb2, 1) > 0 ) - { - sum_diff = 0; - move16(); - FOR(i=1; i(dst_pos); j--) - { - IF (sub(ii, add(sbWidth[k],sbWidth[k-1])) >= 0) - { - BREAK; - } - - /*xSynth_har[ii] = noise_flr[j];*/ - L_xSynth_har[ii] = L_shl(L_deposit_l(noise_flr_fx[j]), sub(QsL, Qss)); - L_tmpbuf[ii] = L_xSynth_har[ii]; - move32(); - IF( predBuf_fx[j] != 0x0 ) - { - hf_pulse_peaks_fx[l] = predBuf_fx[j]; - move16(); - l = add(l, 1); - } - ii = add(ii, 1); - } - } - pos = 0; - move16(); - FOR(j = 0; j< l; j++) - { - st_last_peakpos = add(st_last_peakpos, har_freq_est2); - IF( sub(st_last_peakpos, hfband_end[k]) < 0 ) - { - pk_sf_fx[k*8+pos].nmrValue_fx = hf_pulse_peaks_fx[j]; - move16(); /* Qss */ - pk_sf_fx[k*8+pos].gainIndex_fx = sub(st_last_peakpos, fLenLow); - move16(); - pul_res[k] = add(pul_res[k], 1); - move16(); - pulse_peak_sb_fx[i] = hf_pulse_peaks_fx[j]; - move16(); /* Qss */ - i = add(i, 1); - pos = add(pos, 1); - } - } - st_last_peakpos = temp_last_peakpos; - move16(); - } - res = sub(i, 1); - l = 1; - move16(); - ii = sub(sub(hfband_end[k-1], fLenLow), 1); - tmp_fx = sub(bands, harmonic_band); - FOR(; k inItems = 1/3 = 0.33f, 85(Q8) */ - /* 1/3 = 0.3333f -> 0x2AAA Q15 */ - inItems = 0x2AAA; - move16(); - FOR(i = 1; i < span1; i++) - { - L_sum = L_mac0(L_sum, 0x0001, *newPtr++); - - lo = L_Extract_lc(L_sum, &hi); - *outBuf++ = round_fx( L_shl(Mpy_32_16(hi, lo, inItems), 16) ); /* Q(8+15+1-16)=Q8 -> Q(8+16-16)=Q8 */ - - L_sum = L_mac0(L_sum, 0x0001, *newPtr++); - /* nItems += 2, - * only used value is 5 --> - * inItems = 1/5 = 0.2f, 51(Q8) - */ - /* 1/5 = 0.2f -> 0x1999 Q15 */ - inItems = 0x1999; - move16(); - inBuf++; - } - - inBuf++; - L_sum = L_mac0(L_sum, 0x0001, *newPtr++); - - lo = L_Extract_lc(L_sum, &hi); - /* 4681 (in Q15) = 0.1428 = 1/7 */ - *outBuf++ = round_fx(L_shl(Mpy_32_16(hi, lo, 4681), 16)); /* Q(8+15+1-16)=Q8 -> Q(8+16-16)=Q8 */ - i = add(i, 1); - - /*-- Moving average. --*/ - tmp = sub(num_subband, span1); - FOR( ; i < tmp; i++) - { - L_sum = L_mac0(L_sum, 0x0001, *newPtr++); - L_sum = L_msu0(L_sum, 0x0001, *oldPtr++); - - lo = L_Extract_lc(L_sum, &hi); - /* 4681 (in Q15) = 0.1428 = 1/7 */ - *outBuf++ = round_fx(L_shl(Mpy_32_16(hi, lo, 4681), 16)); /* Q(8+15+1-16)=Q8 -> Q(8+16-16)=Q8 */ - inBuf++; - } - - /*-- Handle end. --*/ - /* nItems = span - 2; (nItems = 5, so we can maintain inItems = 1/5 = 0.2f from above) */ - nItems = sub(MA_LEN, 2); - L_sum = L_msu0(L_sum, 0x0001, *oldPtr++); - - tmp = sub(num_subband, 1); - FOR( ; i < tmp; i++) - { - L_sum = L_msu0(L_sum, 0x0001, *oldPtr++); - - lo = L_Extract_lc(L_sum, &hi); - *outBuf++ = round_fx( L_shl(Mpy_32_16(hi, lo, inItems), 16)); /* Q(8+15+1-16)=Q8 -> Q(8+16-16)=Q8 */ - - /* nItems -= 2; */ - nItems = sub(nItems, 2); - - /* 1.0f -> 0x7fff Q15 */ - inItems = 0x7fff; - move16(); - if(sub(nItems, 3) == 0) - { - /* 1/3 = 0.333f -> 0x2AAA Q15 */ - inItems = 0x2AAA; - move16(); - } - L_sum = L_msu0(L_sum, 0x0001, *oldPtr++); - - inBuf++; - } - - /*-- Last sample. --*/ - *outBuf = *inBuf; - move16(); -} - -/*-------------------------------------------------------------------* - * SpectrumSmoothing() - * - * Smoothing of the low-frequency envelope - *-------------------------------------------------------------------*/ - -void SpectrumSmoothing_fx( - const Word32 *L_inBuf, /* i : Qs Low band MDCT */ - Word16 *outBuf_fx, /* o : Qss output */ - Word16 *Qss, /* o : Q0 Q value of output vector */ - const Word16 fLen, /* i : Q0 length */ - const Word16 th_cut_fx /* i : Qss threshold of cut */ -) -{ - /* internal variable */ - Word16 i,j,k; - - Word16 num_subband_smooth_fx; - Word16 num_subband_smooth_pre_fx; - - Word16 exp_normd; - Word16 exp_shift; - - Word16 max_val_norm_fx; - - Word16 Qmax_val_norm[L_FRAME32k/L_SB]; - - Word32 L_inBuf_abs; - Word32 L_inBuf_pss[L_FRAME32k]; - Word32 L_max_val[L_FRAME32k/L_SB]; - Word16 outBuf_pss_fx[L_FRAME32k]; - - Word16 m, n; - Word16 cnt_zero_cont; - Word16 n_list[BANDS_MAX]; - Word16 reset_flag; - Word16 pp, pk; - Word16 exp_norm; - - *Qss = 10; - - num_subband_smooth_pre_fx = mult(fLen, 21845); /* 1/L_SB = 1/12 = 21845(Q18) Q = exp_normn-18 */ - num_subband_smooth_fx = shr(num_subband_smooth_pre_fx, 18-15); - IF( sub(num_subband_smooth_pre_fx, shl(num_subband_smooth_fx, 18-15)) != 0 ) - { - num_subband_smooth_fx++; - } - - FOR( i=0; i 0) - { - exp_normd = norm_l(L_max_val[i]); - max_val_norm_fx = div_s(0x2800, round_fx(L_shl(L_max_val[i], exp_normd))); /* Q10-(Qs+exp_normd-16) */ - Qmax_val_norm[i] = sub(10-12+16+15, exp_normd); - move16(); /* 10 - (12+exp_normd-16) +15 */; - } - ELSE - { - max_val_norm_fx = 0; - move16(); - Qmax_val_norm[i] = 0; - move16(); - } - - exp_shift = sub(*Qss, add(Qmax_val_norm[i], -19)); - FOR( k = 0; k < L_SB; k++ ) - { - exp_norm = norm_l(L_inBuf_pss[j]); - IF ( L_inBuf_pss[j] == 0x0L ) - { - outBuf_pss_fx[j] = 0; - move16(); - } - ELSE IF ( L_sub(L_abs(L_inBuf_pss[j]), L_max_val[i] ) < 0x0L ) - { - IF( L_inBuf_pss[j] >= 0 ) - { - outBuf_pss_fx[j] = round_fx(L_shl(Mpy_32_16_r(L_shl(L_inBuf_pss[j], exp_norm), max_val_norm_fx), sub(exp_shift, exp_norm))); - move32(); - } - ELSE - { - outBuf_pss_fx[j] = negate(round_fx(L_shl(Mpy_32_16_r(L_shl(L_abs(L_inBuf_pss[j]), exp_norm), max_val_norm_fx), sub(exp_shift, exp_norm)))); - } - } - ELSE - { - /* CLIP, for avoiding computational difference */ - outBuf_pss_fx[j] = 0x2800; - move16(); - if ( L_inBuf_pss[j] < 0x0L ) - { - outBuf_pss_fx[j] = -0x2800; - move16(); - } - } - j++; - } - } - - k = 0; - move16(); - m = 0; - move16(); - n = 0; - move16(); - reset_flag = 0; - move16(); - n_list[0] = 0; - move16(); - FOR( j=0; j 0 && reset_flag == 0 ) - { - n = 0; - move16(); - reset_flag = 1; - move16(); - } - n_list[n] = j; - move16(); - n = add(n, 1); - } - - test(); - if( sub(reset_flag, 1) == 0 && sub(n, 1) == 0 ) - { - m = 0; - move16(); - } - - pk = sub(k, L_SB); - IF( sub(cnt_zero_cont, mult_r(L_SB, 24576)) > 0 ) /* cnt_zero_cont > 3*L_SB/4 */ - { - pp = round_fx(L_shl(L_mult(n_list[m], L_SB), 15)); - FOR( i=0; i 0 ) - { - outBuf_fx[i] = outBuf_pss_fx[i]; - move16(); - } - } - - return; -} - -/*-------------------------------------------------------------------* - * Get20Log10Spec() - * - * Calculates 20*log10() for the specified samples. Input and output buffers can be the same. - *-------------------------------------------------------------------*/ - -void Get20Log10Spec_fx( - const Word32 *L_inBuf, /* i : input Q_inBuf */ /* L_inBuf >=0, so L_abs is omitted. */ - Word16 *outBuf_fx, /* o : output Q7 */ - const Word16 fLen, /* i : loop length */ - const Word16 Q_inBuf /* i : Qvalue of L_inBuf */ -) -{ - Word16 i; - Word16 exp, frac; - - Word32 L_tmp; - - Word32 L_lamda; - Word16 Q_inBuf_1; - - Q_inBuf_1 = sub(Q_inBuf, 1); - L_lamda = L_shl(1L, Q_inBuf_1); /* +1 : Q_inBuf -> Q_inBuf-1 for overflow problem */ - - FOR( i = 0; i < fLen; i++) - { - /*outBuf++ = (float) (20.0f * log10(fabs(*inBuf + 1.0))); */ - L_tmp = L_add(L_shr(*L_inBuf++, 1), L_lamda); - exp = 31; - move16(); - if (L_tmp != 0x0L) - { - exp = norm_l(L_tmp); - } - frac = Log2_norm_lc(L_shl(L_tmp, exp)); - exp = sub(30, exp); - exp = sub(exp, Q_inBuf_1); - L_tmp = L_Comp(exp, frac); - - L_tmp = Mpy_32_16_1(L_tmp, 24660); /* 6.0206 in Q12 */ - L_tmp = L_shl(L_tmp, 2+8); /* Q7 */ - *outBuf_fx++ = round_fx(L_tmp); - } - - return; -} - -void convert_lagIndices_pls2smp_fx( - Word16 lagIndices_in_fx[], - Word16 nBands_search_fx, - Word16 lagIndices_out_fx[], - const Word16 sspectra_fx[], - const Word16 sbWidth_fx[], - const Word16 fLenLow_fx -) -{ - Word16 sb; - Word16 i, cnt; - - FOR( sb = 0; sb < nBands_search_fx; sb++ ) - { - cnt = 0; - move16(); - i = 0; - move16(); - - WHILE( sub(cnt, lagIndices_in_fx[sb]) <= 0 ) - { - if( sspectra_fx[subband_search_offsets_fx[sb]+i] != 0 ) - { - cnt = add(cnt, 1); - } - - i = add(i, 1); - - IF( sub(add(subband_search_offsets_fx[sb], add(i, sbWidth_fx[sb])) , fLenLow_fx) >= 0) - { - BREAK; - } - } - - lagIndices_out_fx[sb] = add(sub(i, 1), subband_search_offsets_fx[sb]); - move16(); - } - - return; -} - -Word16 get_usebit_npswb_fx( - Word16 hqswb_clas_fx -) -{ - Word16 i; - Word16 bits; - Word16 up_lmt; - const Word16 *bits_req; - - up_lmt = 0; - move16(); - bits_req = bits_lagIndices_modeNormal_fx; - move16(); - bits = 0; - move16(); - - IF( sub(hqswb_clas_fx, HQ_NORMAL) == 0 ) - { - up_lmt = NB_SWB_SUBBANDS; - move16(); - bits_req = bits_lagIndices_modeNormal_fx; - move16(); - } - ELSE IF ( sub(hqswb_clas_fx, HQ_HARMONIC) == 0 ) - { - up_lmt = NB_SWB_SUBBANDS_HAR_SEARCH_SB; - move16(); - bits_req =bits_lagIndices_mode0_Har_fx; - move16(); - bits = 2; - move16(); /*noise gain*/ - } - - FOR( i = 0; i < up_lmt; i++ ) - { - bits = add(bits, bits_req[i]); - move16(); - } - - return bits; -} - -void SpectrumSmoothing_nss_fx( - const Word32 *L_inBuf, /* i : lowband MDCT */ - Word16 *outBuf_fx, /* o : output */ - Word16 *Qss, /* o : Q value of output vector */ - const Word16 fLen /* i : length */ -) -{ - /* internal variable */ - Word16 i,k; - - Word16 inBuf_fx[L_FRAME32k]; - Word16 Qm; - Word32 L_tmp[L_FRAME32k]; - - Word16 num_subband_smooth_fx; - Word16 exp_tmp; - - Word16 inBufw_fx[L_FRAME32k+L_SB_NSS]; - Word16 outBufw_fx[L_FRAME32k+L_SB_NSS]; - Word32 L_outBufw[L_FRAME32k+L_SB_NSS]; - Word16 Qo[NUM_SUBBAND_SMOOTH_MAX]; - - Word16 avg_val_fx; - Word32 L_avg_val; - Word16 r0_fx; - Word32 L_r0; - Word32 L_temp; - Word16 temp_fx; - - Word16 max_peak_fx; - - Word16 smr_fx; - Word32 L_smr; - - Word32 L_temp_sum_1[NUM_SUBBAND_SMOOTH_MAX]; - Word32 L_temp_sum_2[NUM_SUBBAND_SMOOTH_MAX]; - Word32 L_temp_sum_3[NUM_SUBBAND_SMOOTH_MAX]; - - - Word16 temp_sum_smooth_fx[NUM_SUBBAND_SMOOTH_MAX]; - Word16 temp_sum_div_fx[NUM_SUBBAND_SMOOTH_MAX]; - Word16 Qsumdiv[NUM_SUBBAND_SMOOTH_MAX]; - Word32 L_temp1; - Word16 temp_hi; - Word16 temp_lo; - - - Word16 avg_val2_fx; - Word32 L_avg_val2; - Word16 Qavg_val; - Word16 Qsmr; - Word16 exp, frac; - - Word16 clip_cof_fx; - - Word16 thre_fx, thre_fx_neg; - Word16 thre_min_fx; - - Word16 temp_sum_log_fx[NUM_SUBBAND_SMOOTH_MAX]; - Word16 exp_norm; - Word16 exp_normn; - Word16 exp_normd; - Word16 exp_shift; - - L_tmp[0] = L_deposit_l(0); - FOR(i=0; i Q(exp_normn-exp_normd+15+16) */ - Qsmr=add(sub(add(Qm,exp_tmp), Qavg_val), 31); - - L_temp = L_add(L_shr(L_smr, 1), 0x1L); /* add minimum value */ - exp = norm_l(L_temp); - frac = Log2_norm_lc(L_shl(L_temp, exp)); - exp = sub(30, exp); - exp = sub(exp, sub(Qsmr, 1)); - L_temp = L_Comp(exp, frac); - - L_temp = Mpy_32_16_1(L_temp, 12330); /* 3.0103 in Q12 */ - L_temp = L_shl(L_temp, 2+8); /* Q7 */ - smr_fx = round_fx(L_temp); - - FOR( i = 0; i < num_subband_smooth_fx; i++ ) - { - L_temp_sum_1[i] = L_deposit_l(0); - L_temp_sum_2[i] = L_deposit_l(0); - - FOR( k = 0; k < L_SB_NSS_HALF; k++ ) - { - L_temp_sum_1[i] = L_add( L_temp_sum_1[i], extract_l(abs_s( inBufw_fx[k+L_SB_NSS*i])) ); /* Qm */ move32(); - } - - FOR( k = L_SB_NSS_HALF; k < L_SB_NSS; k++ ) - { - L_temp_sum_2[i] = L_add( L_temp_sum_2[i], extract_l(abs_s( inBufw_fx[k+L_SB_NSS*i])) ); /* Qm */ move32(); - } - - L_temp_sum_1[i] = L_shr(L_temp_sum_1[i], 2); /* *0.25 guarantee low-side 16bit for L_temp_sum_* */ move32(); - L_temp_sum_2[i] = L_shr(L_temp_sum_2[i], 2); /* *0.25 */ move32(); - L_temp_sum_3[i] = L_mult(extract_l(L_temp_sum_1[i]), extract_l(L_temp_sum_2[i])); /* Qm*2+1 */ move32(); - - IF( L_temp_sum_3[i] == 0 ) - { - L_temp_sum_3[i] = L_shl(L_add(L_temp_sum_1[i], L_temp_sum_2[i]), add(Qm, 1)); /*Q(Qm+Qm+1) */ move32(); - } - } - - exp_norm = add(shl(Qm, 1), 1); - Get20Log10Spec_fx(L_temp_sum_3, temp_sum_log_fx, num_subband_smooth_fx, exp_norm); - - /* temp_sum_log_fx // *0.5 Q7 -> Q8 (not change) */ - SmoothSpec_fx(temp_sum_log_fx, temp_sum_smooth_fx, num_subband_smooth_fx); - - FOR (i = 0; i < num_subband_smooth_fx; i++) - { - L_temp1 = L_mult(temp_sum_smooth_fx[i], 1360); /* Q8+Q13+1=Q22, 1360(Q13) = 0.1660 = 3.321928(log2^10) * 0.05 */ - L_temp1 = L_shr(L_temp1, 6); /* Q22 -> Q16 */ - L_temp1 = L_negate(L_temp1); - temp_lo = L_Extract_lc(L_temp1, &temp_hi); - Qsumdiv[i] = sub(14, temp_hi); - temp_sum_div_fx[i] = extract_l(Pow2(14, temp_lo)); /* Qsumdiv[i] */ - exp_norm = norm_s(temp_sum_div_fx[i]); - temp_sum_div_fx[i] = shl(temp_sum_div_fx[i], exp_norm); - move16(); - Qsumdiv[i] = add(Qsumdiv[i], exp_norm); - move16(); - } - - *Qss = 31; - move16(); - FOR (i = 0; i < num_subband_smooth_fx; i++) - { - Qo[i] = add(add(Qm, Qsumdiv[i]), 1); - L_temp1 = 0x0L; - FOR (k = 0; k < L_SB_NSS; k++) - { - L_outBufw[k + L_SB_NSS * i] = L_mult(inBufw_fx[k + L_SB_NSS * i], temp_sum_div_fx[i]); - move32(); - L_temp1 = L_or(L_temp1, L_abs(L_outBufw[k + L_SB_NSS * i])); - } - exp_norm = 31; - if (L_temp1 != 0x0L ) - { - exp_norm = norm_l(L_temp1); - } - FOR (k = 0; k < L_SB_NSS; k++) - { - L_outBufw[k + L_SB_NSS * i] = L_shl(L_outBufw[k + L_SB_NSS * i], exp_norm); - move32(); - } - Qo[i] = add(Qo[i], exp_norm); - move16(); - *Qss = s_min(*Qss, Qo[i]); - move16(); - } - - FOR (i = 0; i < num_subband_smooth_fx; i++) - { - exp_shift = sub(*Qss, Qo[i]); - exp_shift = s_max(-31, exp_shift); - FOR (k = 0; k < L_SB_NSS; k++) - { - L_outBufw[k + L_SB_NSS * i] = L_shl(L_outBufw[k + L_SB_NSS * i], exp_shift); - move16(); - outBufw_fx[k + L_SB_NSS * i] = round_fx(L_outBufw[k + L_SB_NSS * i]); - } - } - *Qss = sub(*Qss, 16); - - L_avg_val2 = L_deposit_l(0); - FOR( i = 0; i < fLen; i++ ) - { - L_r0 = L_abs(L_deposit_l(outBufw_fx[i])); - L_avg_val2 = L_add(L_avg_val2, L_r0); /* Qss */ - } - - exp_normn = norm_l(L_avg_val2); - exp_normn = sub(exp_normn, 1); - exp_normd = norm_s(fLen); - temp_fx = div_l(L_shl(L_avg_val2, exp_normn), shl(fLen, exp_normd)); /* Q(obw+exp_normn - exp_normd) - 1 */ - avg_val2_fx = shr(temp_fx, sub(sub(exp_normn, exp_normd), 1)); /* Qss */ - - /*clip_cof = smr - 16.0f; */ - clip_cof_fx = sub(smr_fx, 2048); /* 2048: 16.0f (Q7) */ - if( clip_cof_fx < 0 ) - { - clip_cof_fx = 0; - move16(); - } - /*clip_cof += 2.5f; */ - clip_cof_fx = add(clip_cof_fx, 320); /* 320: 2.5f (Q7) */ - - thre_fx = round_fx(L_shl(L_mult(avg_val2_fx, clip_cof_fx), 8)); /* Q(Qss+7+1) -> Qss */ - thre_fx_neg = negate(thre_fx); - thre_min_fx = shr(avg_val2_fx, 2); /* *0.25f // Qss */ - - FOR(i = 0; i < fLen; i++) - { - IF( sub(abs_s(outBufw_fx[i]), thre_fx) > 0 ) - { - temp_fx = thre_fx; - move16(); - if(outBufw_fx[i] < 0) - { - temp_fx = thre_fx_neg; - move16(); - } - outBufw_fx[i] = temp_fx; - move16(); - } - - if( sub(abs_s(outBufw_fx[i]), thre_min_fx) < 0 ) - { - outBufw_fx[i] = 0; - move16(); - } - } - - FOR(i = 0; i < fLen; i++) - { - outBuf_fx[i] = outBufw_fx[i]; - move16(); /* Qss */ - } - - return; -} - -/*-------------------------------------------------------------------* - * return_bits_normal2 - * - * arrange bit_budget when HQ_NORMAL - *-------------------------------------------------------------------*/ - -void return_bits_normal2_fx( - Word16 *bit_budget_fx, /* i/o : bit budget */ - const Word16 p2a_flags_fx[], /* i : HF tonal indicator */ - const Word16 bands_fx, /* i : Total number of Subbands in a frame */ - const Word16 bits_lagIndices_fx[] /* i : bits for lagIndices */ -) -{ - Word16 i; - const Word16 *p_p2a_flags_fx; - - p_p2a_flags_fx = &p2a_flags_fx[sub(bands_fx, NB_SWB_SUBBANDS)]; - FOR( i=0 ; i < NB_SWB_SUBBANDS; i++ ) - { - if( sub(*p_p2a_flags_fx++, 1) == 0 ) - { - *bit_budget_fx = add(*bit_budget_fx, bits_lagIndices_fx[i]); - move16(); - } - } - - return; -} - -/*-------------------------------------------------------------------* - * preset_hq2_swb - * - * preset before swb_bwe_{enc,dec}_lr - *-------------------------------------------------------------------*/ - -void preset_hq2_swb_fx -( - const Word16 hqswb_clas_fx, /* i : HQ2 class information */ - const Word16 band_end_fx[], /* i : band end of each SB */ - Word16 *har_bands_fx, /* i/o : Number of LF harmonic bands */ - Word16 p2a_bands_fx, /* i : flag for peakness */ - const Word16 length_fx, /* i : processed band length */ - const Word16 bands_fx, /* i : Total number of Subbands in a frame */ - Word16 *lowlength_fx, /* o : lowband length */ - Word16 *highlength_fx, /* o : highband length */ - Word32 L_m[] /* o : MDCT */ -) -{ - IF( sub(hqswb_clas_fx, HQ_HARMONIC) == 0 ) - { - *har_bands_fx = add(sub(bands_fx, p2a_bands_fx), 1); - move16(); - *lowlength_fx = add(band_end_fx[*har_bands_fx-1], 1); - move16(); - } - ELSE - { - *lowlength_fx = add(band_end_fx[bands_fx-NB_SWB_SUBBANDS-1], 1); - move16(); - } - - *highlength_fx = sub(length_fx, *lowlength_fx); - move16(); - - set32_fx( L_m, 0, length_fx ); - - return; -} - -/*-------------------------------------------------------------------* - * preset_hq2_swb - * - * post process after swb_bwe_{enc,dec}_lr - *-------------------------------------------------------------------*/ - -void post_hq2_swb_fx -( - const Word32 L_m[], /* i : input_signal */ - const Word16 lowlength_fx, /* i : lowband length */ - const Word16 highlength_fx, /* i : highband length */ - const Word16 hqswb_clas_fx, /* i : HQ2 class information */ - const Word16 har_bands_fx, /* i : Number of LF harmonic bands */ - const Word16 bands_fx, /* i : Total number of Subbands in a frame */ - const Word16 p2a_flags_fx[], /* i : HF tonal indicator */ - const Word16 band_start_fx[], /* i : band start of each SB */ - const Word16 band_end_fx[], /* i : band end of each SB */ - Word32 L_y2[], /* o : output signal */ - Word16 npulses_fx[] /* i/o : Number of coded spectrum */ -) -{ - Word16 i, k; - - /* copy the scratch buffer to the output */ - Copy32( &L_m[lowlength_fx], &L_y2[lowlength_fx], highlength_fx ); - - IF( sub(hqswb_clas_fx, HQ_HARMONIC) == 0 ) - { - k = har_bands_fx; - move16(); - } - ELSE - { - k = sub(bands_fx, NB_SWB_SUBBANDS); - move16(); - } - - FOR( ; k 0 ) - { - /* should never happen */ - lag_fx = sub(predBufLen_fx, fLen_fx); - } - ptr_predBuf_fx = predBuf_fx + lag_fx; - - - exp_shift = sub(add(add(Qss, QlagGains_fx[sb]), 1), QsL); - - FOR (i=0; i= 0x0L ) - { - *ptr_L_outBuf++ = L_shr(L_mult(*ptr_predBuf_fx++, lagGains_fx[sb]), exp_shift); - move32(); /* Qss+QlagGains+1 -> QsL */ - } - ELSE - { - *ptr_L_outBuf++ = L_negate(L_shr(L_mult(abs_s(*ptr_predBuf_fx++), lagGains_fx[sb]), exp_shift)); - move32(); /* Qss+QlagGains+1 -> QsL */ - } - } - } - - ptr_L_outBuf = ptr_L_in_outBuf; - - return; -} - -/*--------------------------------------------------------------------------* - * div_s_ss - * - * compute division with Word16 Q0. ex. 10/2 -> 5 - *--------------------------------------------------------------------------*/ - -Word16 div_s_ss( /* o: result of division (Word16 Q0) */ - const Word16 n, /* i: numerator (Word16 Q0 */ - const Word16 d /* i: denominator (Word16 Q0) */ -) -{ - Word16 norm_n, norm_d; - Word16 ns, ds; - Word16 res; - - test(); - IF ( n == 0 || d == 0 ) - { - return 0; - } - - norm_n = norm_s(n); - norm_n = sub(norm_n, 1); - ns = shl(n, norm_n); - - norm_d = norm_s(d); - ds = shl(d, norm_d); - - res = shr(div_s(ns, ds), add(sub(norm_n, norm_d), 15)); - - return res; -} - -void hf_parinitiz_fx( - const Word32 L_total_brate, - const Word16 hqswb_clas_fx, - Word16 lowlength_fx, - Word16 highlength_fx, - Word16 wBands_fx[], - const Word16 **subband_search_offset_fx, - const Word16 **subband_offsets_fx, - Word16 *nBands_fx, - Word16 *nBands_search_fx, - Word16 *swb_lowband_fx, - Word16 *swb_highband_fx -) -{ - *swb_lowband_fx = lowlength_fx; - move16(); - *swb_highband_fx = highlength_fx; - move16(); - - IF( sub(hqswb_clas_fx, HQ_HARMONIC) == 0 ) - { - /* Mode dependent initializations (performed every frame in case mode-switching implemented) */ - *nBands_fx = NB_SWB_SUBBANDS_HAR; - move16(); - *nBands_search_fx = NB_SWB_SUBBANDS_HAR_SEARCH_SB; - move16(); - - IF ( L_sub(L_total_brate, HQ_13k20) == 0 ) - { - wBands_fx[0] = SWB_SB_BW_LEN0_12KBPS_HAR; - move16(); - wBands_fx[1] = SWB_SB_BW_LEN1_12KBPS_HAR; - move16(); - wBands_fx[2] = SWB_SB_BW_LEN2_12KBPS_HAR; - move16(); - wBands_fx[3] = SWB_SB_BW_LEN3_12KBPS_HAR; - move16(); - *subband_offsets_fx = subband_offsets_sub5_13p2kbps_Har_fx; - move16(); - *subband_search_offset_fx = subband_search_offsets_13p2kbps_Har_fx; - move16(); - } - ELSE - { - wBands_fx[0] = SWB_SB_BW_LEN0_16KBPS_HAR; - move16(); - wBands_fx[1] = SWB_SB_BW_LEN1_16KBPS_HAR; - move16(); - wBands_fx[2] = SWB_SB_BW_LEN2_16KBPS_HAR; - move16(); - wBands_fx[3] = SWB_SB_BW_LEN3_16KBPS_HAR; - move16(); - *subband_offsets_fx = subband_offsets_sub5_16p4kbps_Har_fx; - move16(); - *subband_search_offset_fx = subband_search_offsets_16p4kbps_Har_fx; - move16(); - } - } - ELSE - { - /* Mode-dependent initializations (performed every frame in case mode-switching implemented) */ - *nBands_fx = NB_SWB_SUBBANDS; - move16(); - *nBands_search_fx = NB_SWB_SUBBANDS; - move16(); - - IF ( L_sub(L_total_brate, HQ_13k20) == 0 ) - { - wBands_fx[0] = SWB_SB_LEN0_12KBPS; - move16(); - wBands_fx[1] = SWB_SB_LEN1_12KBPS; - move16(); - wBands_fx[2] = SWB_SB_LEN2_12KBPS; - move16(); - wBands_fx[3] = SWB_SB_LEN3_12KBPS; - move16(); - *subband_offsets_fx = subband_offsets_12KBPS; - move16(); - } - ELSE - { - wBands_fx[0] = SWB_SB_LEN0_16KBPS; - move16(); - wBands_fx[1] = SWB_SB_LEN1_16KBPS; - move16(); - wBands_fx[2] = SWB_SB_LEN2_16KBPS; - move16(); - wBands_fx[3] = SWB_SB_LEN3_16KBPS; - move16(); - *subband_offsets_fx = subband_offsets_16KBPS; - move16(); - } - } - - return; -} - -void GetlagGains_fx( - const Word16 *predBuf_fx, /* i: Qss Low freq. Smoothed Spectrum */ - const Word16 Qss, /* i: Q0 Q value of predBuf */ - const Word32 *L_band_energy, /* i: Qbe Band Energy */ - const Word16 Qbe, /* i: Q0 Q value of band energy */ - const Word16 nBands, /* i: Q0 number of SWB subbands */ - const Word16 *sbWidth, /* i: Q0 width of SWB subbands */ - const Word16 *lagIndices, /* i: Q0 lagIndices */ - const Word16 predBufLen, /* i: Q0 length of predBuf */ - Word16 *lagGains_fx, /* o: QlagGains lagGains */ - Word16 *QlagGains /* o: Q0 Q value of lagGains */ -) -{ - Word16 i; - Word16 sb, fLen, lag; - - Word32 L_outBuf[L_FRAME32k]; - - Word16 *ptr_ssBuf_fx; - Word32 L_lagEnergy; - Word16 Qene; - - Word16 temp_lo_fx, temp_hi_fx; - Word16 pow_fx; - Word16 Qpow; - Word16 exp_normd, exp_normn; - Word16 Qdiv; - Word16 exp_norm; - - Word16 temp_fx; - Word32 L_temp; - - Word16 ssBuf_fx[L_FRAME32k]; - Word16 exp_norm_ss; - - exp_norm_ss = 2; - move16(); - FOR (i=0; i 0 ) - { - /* should never happen */ - lag = sub(predBufLen, fLen); - move16(); - } - - GetPredictedSignal_fx( predBuf_fx, L_outBuf, lag, fLen, 0x7fff, 15); - - ptr_ssBuf_fx = ssBuf_fx + lag; - L_lagEnergy = L_deposit_l(0); - FOR( i = 0; i < fLen; i++) - { - L_lagEnergy = L_mac(L_lagEnergy, *ptr_ssBuf_fx, *ptr_ssBuf_fx); /* (Qss-exp_norm_ss)*2+1 */ - ptr_ssBuf_fx++; - } - Qene = add(shl(sub(Qss, exp_norm_ss), 1), 1); - - IF( L_lagEnergy != 0x0L ) - { - /* lagGains[sb] = (float)sqrt( pow(2.0f, band_energy[sb]) / lagEnergy ); */ - /* Pow part (pow(2.0f, band_energy) ) */ - L_temp = L_shr(L_band_energy[sb], sub(Qbe, 16)); /* Qbe -> Q16 */ - temp_lo_fx = L_Extract_lc(L_temp, &temp_hi_fx); - Qpow = sub(14, temp_hi_fx); - pow_fx = extract_l(Pow2(14, temp_lo_fx)); /* Qpow */ - - /* Div part ( pow (2.0f, band_energy[i])/lagEenegy ) */ - exp_normn = norm_s(pow_fx); - exp_normn = sub(exp_normn, 1); - exp_normd = norm_l(L_lagEnergy); - temp_fx = div_s( shl( pow_fx, exp_normn), extract_h(L_shl(L_lagEnergy, exp_normd))); - Qdiv = add(sub(add(Qpow, exp_normn) , add(Qene, exp_normd)), 31); - - exp_norm = norm_s(temp_fx); - temp_fx = shl(temp_fx, exp_norm); - Qdiv = add(Qdiv, exp_norm); - - /* Sqrt part sqrt(pow (2.0f, band_energy[i])/lagEnergy) */ - QlagGains[sb] = add(Qdiv, 16); - IF ( s_and(Qdiv, 1) == 0 ) /* Qdiv % 2 == 0 */ - { - L_temp = Sqrt_l(L_shr(L_deposit_h(temp_fx),1), &exp_norm); - L_temp = L_shr(L_temp, exp_norm); - QlagGains[sb] = sub(shr(QlagGains[sb], 1), 1); - move16(); - lagGains_fx[sb] = round_fx(L_temp); - } - ELSE - { - L_temp = Sqrt_l(L_deposit_h(temp_fx), &exp_norm); - L_temp = L_shr(L_temp, exp_norm); - QlagGains[sb] = shr(QlagGains[sb], 1); - move16(); - lagGains_fx[sb] = round_fx(L_temp); - } - } - ELSE - { - /* lagGains[sb] = 0.0f; */ - lagGains_fx[sb] = 0; - move16(); - QlagGains[sb] = 15; - move16(); - } - } - - return; -} - -/*--------------------------------------------------------------------------* - * noise_extr_corcod() - * Spectrum normalization for the core coder - *--------------------------------------------------------------------------*/ - -void noise_extr_corcod_fx( - Word32 L_spectra[], /* i : QsL core coder */ - const Word32 L_spectra_ni[], /* i : QsL core coder with sparse filling */ - Word16 sspectra_fx[], /* o : Qss Smoothed tonal information from core coder */ - Word16 sspectra_diff_fx[], /* o : Qss non tonal infomration for gap filling */ - Word16 sspectra_ni_fx[], /* o : Qss smoothed core coder */ - const Word16 fLenLow_fx, /* i : Q0 low frequency bands width */ - Word16 prev_hqswb_clas_fx, /* i : Q0 classification information */ - Word16 *prev_ni_ratio_fx, /* i : Q15 noise parameter */ - Word16 *Qss /* o : Q0 Q value for sspectra_*_fx */ -) -{ - Word16 i,pulse_num_fx; - Word32 L_spectra_diff[L_FRAME32k]; /* QsL */ - Word16 Qss_s, Qss_d; - Word16 ni_ratio_fx, ni_ratio_cur_fx, br_adj_fx; /* Q15 */ - Word16 tmp_fx; - Word16 exp_normn, exp_normd, exp_shift; - Word16 exp_norm; - - /*Spectrum Smoothing for tonal signals*/ - SpectrumSmoothing_nss_fx( L_spectra, sspectra_fx, &Qss_s, fLenLow_fx ); - Copy(sspectra_fx, sspectra_ni_fx, fLenLow_fx); - tmp_fx = 0; - FOR(i=0; i 0 ) - { - /* 0.8: 26214(Q15) 0.2: 6554(Q15) */ - ni_ratio_fx = mac_r(L_mult(ni_ratio_cur_fx, 26214), *prev_ni_ratio_fx, 6554); - } - ELSE - { - /* 0.6: 19661(Q15) 0.4: 13107(Q15) */ - ni_ratio_fx = mac_r(L_mult(ni_ratio_cur_fx, 19661), *prev_ni_ratio_fx, 13107); - } - } - ELSE - { - /* 0.7: 22938(Q15) */ - ni_ratio_fx = mult_r(ni_ratio_cur_fx, 22938); - } - *prev_ni_ratio_fx = ni_ratio_fx; - move16(); - - FOR(i=0; inmrValue */ - Word16 *pul_res /* i : Q0 tonal resolution */ -) -{ - Word16 i, j, k; - Word16 exp_norm; - Word16 Inv_band_width_fx[BANDS_MAX]; - Word16 QInvBW[BANDS_MAX]; - - Word16 xSynth_har_fx[L_FRAME32k]; - Word16 QxSynth; /* Q value for xSynth_har_fx */ - Word16 QxSynth_sft; /* Q value for xSynth_har_fx */ - - Word16 sb_ton_loc_fx[SWB_HAR_RAN1]; /* Q0 */ - Word16 sb_ton_fx[SWB_HAR_RAN1]; /* Qss */ - Word16 ni_gain_fx[NB_SWB_SUBBANDS]; - Word16 Qni_gain; - Word16 avg_pe_fx[NB_SWB_SUBBANDS]; - Word16 Qavg_pe[NB_SWB_SUBBANDS]; - Word16 QsN; /* Q value for xSynth_har after multipy ni_lvl */ - Word16 exp_safe; /* overflow prevent shift */ - - Word16 pos,count_pos_st,count_pos_end; - Word16 pul_res_bnd[NB_SWB_SUBBANDS]; - Word16 peak_fx[NB_SWB_SUBBANDS]; /* Qss */ - - Word32 L_E; - Word16 QE; - Word16 temp_lo_fx, temp_hi_fx; - Word32 L_temp; - Word16 exp_pow; - Word32 L_band_energy_Linear[BANDS_MAX]; - - Word16 exp_normd, exp_normn; - - Word16 E_r_fx; - Word16 QE_r; /* Q value for E_r_fx */ - - Word16 exp_shift; - - Word16 E_r_shift_fx; - Word16 fac_fx; - Word16 Qtemp; - Word16 temp2_fx, Qtemp2; - Word16 temp_fx; - - *QbeL = 3; - move16(); - Qni_gain = 8; - move16(); - - FOR(k=0; k=0 ) - { - pos = add(pos, 1); - } - count_pos_end = pos; - move16(); - pul_res_bnd[k] = sub(count_pos_end, count_pos_st); - move16(); - if(pul_res_bnd[k] > 0) - { - peak_fx[k] = abs_s(sb_ton_fx[count_pos_st]); - move16(); - } - k = add(k, 1); - } WHILE( sub(k, NB_SWB_SUBBANDS) < 0 ); - - k = 0; - move16(); - /*energy calculation for tonal components*/ - FOR(i=har_bands; i E * pow(2.0f, -band_energy) */ - /* Pow Part */ - L_temp = L_shr(L_band_energy[i], sub(Qbe, 16)); - temp_lo_fx = L_Extract_lc(L_temp, &temp_hi_fx); - - exp_pow = sub(14, temp_hi_fx); - L_band_energy_Linear[i] = Pow2(14, temp_lo_fx); - move32(); /* Qexp_pow */ - L_band_energy_Linear[i] = L_shl(L_band_energy_Linear[i], sub(*QbeL, exp_pow)); - - /* Div Part */ - E_r_fx = 0x7fff; - move16(); - QE_r = 0; - move16(); - IF(L_band_energy_Linear[i] != 0x0L) - { - exp_normd = norm_l(L_E); - exp_normd = sub(exp_normd, 1); - exp_normn = norm_l(L_band_energy_Linear[i]); - - E_r_fx = div_s( extract_h(L_shl(L_E, exp_normd)), extract_h(L_shl(L_band_energy_Linear[i], exp_normn))); - /* QE_r = (QE-16) - (QbeL+exp_normn-16) + 15; */ - QE_r = add(sub(add(QE, exp_normd) , add(*QbeL, exp_normn)), 15); - } - - L_E = L_shl(L_E, sub(*QbeL, QE)); - QE = *QbeL; - - /* 0.06=15729(Q18) */ - exp_shift = sub(18, QE_r); - E_r_shift_fx = shl(E_r_fx, exp_shift); - - IF ( sub(E_r_shift_fx, 15729) < 0 ) /* E_r < 0.06 */ - { - /* avg_pe[k] = (float) sqrt(pow(2.0f,band_energy[i])/band_width[i]); */ - /* Pre SQRT part */ - /*L_temp = Mpy_32_16_1(L_band_energy_Linear[i], Inv_band_width_fx[i]);*/ /* QbeL + QInvBW -15 */ - L_temp = Mult_32_16(L_band_energy_Linear[i], Inv_band_width_fx[i]); /* QbeL + QInvBW -15 */ - Qtemp = sub(add(*QbeL, QInvBW[i]), 15); - - sqrt_32n_16_fx(L_temp, Qtemp, &avg_pe_fx[k], &Qavg_pe[k]); - - fac_fx = 19661; /* 0.6(Q15) */ - IF(pul_res_bnd[k] != 0) - { - /* Div Part */ - L_temp = Mult_32_16(L_E, Inv_band_width_fx[i]); /* QE+exp_norm+QInvBW[i]+1 */ - Qtemp = sub(add(QE, QInvBW[i]), 15); - - /* SQRT Part */ - sqrt_32n_16_fx(L_temp, Qtemp, &temp2_fx, &Qtemp2); - - /* Div Part */ - exp_normd = norm_s(temp2_fx); - exp_normd = sub(exp_normd, 1); - exp_normn = norm_s(peak_fx[k]); - - fac_fx = div_s(shl(temp2_fx, exp_normd), shl(peak_fx[k], exp_normn)); - fac_fx = shl(fac_fx, sub(add(Qss, exp_normn), add(Qtemp2, exp_normd))); /* Qtemp2+exp_normd-(Qss+exp_normn)+15 -> 15*/ - - } - - ni_gain_fx[k] = mult_r(avg_pe_fx[k], fac_fx); /* Qavg_pe[k] */ move16(); - - L_temp = L_mult(ni_gain_fx[k], ni_gain_fx[k]); - L_temp = Mult_32_16(L_temp, E_r_fx); - - /* 0.12f: 257698038 (Q31) */ - if( L_sub(L_shl(L_temp,sub(31, add(add(shl(Qavg_pe[k], 1), QE_r), 1-15))), 257698038) >= 0 ) - { - ni_gain_fx[k] = mult_r(1638, ni_gain_fx[k]); /* 0.05 : 1638(Q15) */ move16(); - } - Overflow = 0; - move16(); - ni_gain_fx[k] = shl(ni_gain_fx[k], sub(Qni_gain, Qavg_pe[k])); - assert(Qni_gain==8); /* 358 is '(short)(1.4*pow(2,Qni_gain))' */ - ni_gain_fx[k] = s_max(ni_gain_fx[k], 358); /* 1.4 -> 22938(Q14) */ - - exp_shift = QsL-(QxSynth+Qni_gain+1); /* QsL - (QxSynth+Qni_gain+1) */ - FOR(j=band_start[i]; j<=band_end[i]; j++) - { - L_xSynth_har[j-fLenLow] = L_shl(L_mult(xSynth_har_fx[j-fLenLow], ni_gain_fx[k]), exp_shift); /* QsL - (QxSynth+Qni_gain+1) */ move32(); - } - - exp_safe = 4; /* move16(); */ - norm_vec_32_16_scale_fx(&L_xSynth_har[band_start[i]-fLenLow], QsL, band_width[i], &xSynth_har_fx[band_start[i]-fLenLow], &QxSynth_sft, exp_safe); - - L_E = sum2_fx(&xSynth_har_fx[sub(band_start[i], fLenLow)], band_width[i]); - QE = add(shl(QxSynth_sft, 1),1); - - L_E = L_shl(L_E, sub(*QbeL, QE)); - QE = *QbeL; - } - ELSE - { - /* Q8 -> Q12 */ - FOR(j=band_start[i]; j<=band_end[i]; j++) - { - L_xSynth_har[j-fLenLow] = L_shl(L_xSynth_har[j-fLenLow], 4); /* Q8(12+11-15) -> Q12 */ move32(); - } - } - - k = add(k, 1); - - L_be_tonal[i] = L_sub(L_band_energy_Linear[i], L_E); - - IF ( L_be_tonal[i] < 0x0L ) - { - L_E = L_deposit_l(0); - FOR(j=(band_start[i]-fLenLow); j<=(band_end[i]-fLenLow); j++) - { - temp_fx = round_fx(L_shl(L_xSynth_har[j], (*QbeL+7)/2)); /* (12+x-16)*2+1 => QbeL */ - L_xSynth_har[j] = L_shr(L_xSynth_har[j], 2); /* 1/4 */ move32(); - L_E = L_mac( L_E, temp_fx, temp_fx); - } - - L_E = L_shr(L_E, 4); /* 1/4 */ - L_be_tonal[i] = L_sub(L_band_energy_Linear[i], L_E); - move32(); - } - } - - return; -} - - -/*--------------------------------------------------------------------------* - * Gettonl_scalfact() - * Gap filling for the core coder - *--------------------------------------------------------------------------*/ -void Gettonl_scalfact_fx -( - Word32 *L_outBuf, /* i/o: QsL synthesized spectrum */ - Word16 QsL, /* i : Q0 Q value for outBuf */ - const Word32 *L_codbuf, /* i : QsL core coder */ - const Word16 fLenLow, /* i : Q0 lowband length */ - const Word16 fLenHigh, /* i : Q0 highband length */ - const Word16 harmonic_band, /* i : Q0 total number of Low frequency bands */ - const Word16 bands, /* i : Q0 total number of subbands in a frame */ - Word32 *L_band_energy, /* i : Qbe band energy of each subband */ - Word16 Qbe, /* i : Q0 Q value for band_energy */ - const Word16 *band_start, /* i : Q0 subband start indices */ - const Word16 *band_end, /* i : Q0 subband end indices */ - const Word16 p2aflags[], /* i : Q0 missing bands in the core coder */ - Word32 L_be_tonal[], /* i : QbeL tonal energy */ - Word16 QbeL, /* i : Q0 Q value for be_tonal */ - GainItem_fx *pk_sf_fx, /* i : toanl information for Sparse filling */ - Word16 Qss, /* i : Q0 Q value for pk_sf.nmrValue */ - Word16 *pul_res_pk /* i : Q0 pulse resolution information */ -) -{ - Word16 i, j, tmp; - Word16 sb_ton_fx[SWB_HAR_RAN1]; /* Qss */ - Word16 sb_ton_loc_fx[SWB_HAR_RAN1]; /* Q0 */ - Word32 L_est_ton_ene[NB_SWB_SUBBANDS]; /* QetEne */ - Word16 QetEne; - Word16 band_sf_fx[SWB_HAR_RAN1]; /* Qton_sf */ - Word16 pos_fx, k_fx, pos_tmp_fx; /* Q0 */ - Word16 exp_safe; - Word16 temp_fx; - Word16 Qtemp; - - Word16 band_pos_fx; - Word16 count_pos_st_fx, count_pos_end_fx; - - Word16 exp_normd, exp_normn; - - Word16 ton_sf_fx; /* Qton_sf */ - Word16 Qton_sf; - - Word16 step_fx; /* Q15 */ - Word32 L_temp; - - Word16 enrd_r_fx; /* Q15 */ - - Word32 L_band_energy_Linear[BANDS_MAX]; /* QbeL */ - Word16 temp_hi_fx, temp_lo_fx; - Word16 exp_pow; - Word16 exp_shift; - - Word16 Qbsf2[SWB_HAR_RAN1]; - - Qton_sf = sub(sub(QsL, Qss), 1); - - enrd_r_fx = 29491; - move16(); /* 0.9: 29491.2(Q15) */ - - set32_fx(L_est_ton_ene, 0x0L, NB_SWB_SUBBANDS); - set16_fx(sb_ton_loc_fx, -1,SWB_HAR_RAN1); - - /* Get the tonal information for sparse filling */ - pos_fx = 0; - move16(); - FOR(k_fx=0; k_fx= 0 ) - { - test(); - pos_fx = add(pos_fx, 1); - } - count_pos_end_fx = pos_fx; - move16(); - - exp_safe = 2; /* move16(); */ - QetEne = add(shl(sub(Qss, exp_safe), 1), 1); - L_temp = L_add(L_est_ton_ene[k_fx], 0); - FOR(i=count_pos_st_fx; i 0x0L ) - { - ton_sf_fx = div_l(L_shl(L_be_tonal[band_pos_fx], exp_normd), extract_h(L_shl(L_est_ton_ene[k_fx], exp_normn))); /* QbeL+exp_normd - (QetEne+exp_normn-16) - 1 */ - } - - /* Sqrt Part */ - /*sqrt_32n_16_fx(L_deposit_h(ton_sf_fx), (QbeL+exp_normd)-(QetEne+exp_normn-16)-1+16, &ton_sf_fx, &Qton_sf);*/ - sqrt_32n_16_fx(L_deposit_h(ton_sf_fx), add(sub(add(QbeL, exp_normd), add(QetEne, exp_normn)), 31), &ton_sf_fx, &Qton_sf); - - FOR(i=count_pos_st_fx; i 0x0L ) - { - /* enrd_r *=(float)sqrt(be_tonal[band_pos]/pow(2.0f,band_energy[band_pos])); */ - /* Pow Part */ - L_temp = L_shr(L_band_energy[band_pos_fx], sub(Qbe, 16)); - temp_lo_fx = L_Extract_lc(L_temp, &temp_hi_fx); - exp_pow = sub(14, temp_hi_fx); - L_band_energy_Linear[band_pos_fx] = Pow2(14, temp_lo_fx); - move32(); /* Qexp_pow */ - L_band_energy_Linear[band_pos_fx] = L_shl(L_band_energy_Linear[band_pos_fx], sub(QbeL, exp_pow)); - - /* Div Part */ - exp_normd = norm_l(L_be_tonal[band_pos_fx]); - exp_normd = sub(exp_normd, 1); - exp_normn = norm_l(L_band_energy_Linear[band_pos_fx]); - temp_fx = div_l(L_shl(L_be_tonal[band_pos_fx], exp_normd), extract_h(L_shl(L_band_energy_Linear[band_pos_fx], exp_normn))); /* QbeL+exp_normd-(QbeL+exp_normn-16)-1 */ - sqrt_32n_16_fx(L_deposit_h(temp_fx), add(sub(exp_normd, exp_normn), 31), &temp_fx, &Qtemp); - enrd_r_fx = extract_h(L_shl(L_mult(enrd_r_fx, temp_fx), sub(15, Qtemp))); - - enrd_r_fx = sub(enrd_r_fx, step_fx); - } - ELSE - { - enrd_r_fx = 0x0; - move16(); - } - - IF(sub(p2aflags[band_pos_fx], 1) == 0) - { - FOR(i= band_start[band_pos_fx]; i<=band_end[band_pos_fx]; i++) - { - L_outBuf[i-fLenLow] = L_codbuf[i]; - move32(); - } - } - ELSE - { - pos_fx = 0; - move16(); - pos_fx = add(pos_fx, pos_tmp_fx); - exp_shift = sub(sub(QsL, Qss), 1); - FOR(j=0; j 4+4=8 */ - - L_tmp = L_deposit_l(0); - FOR( i=0; i 0 ) - { - pk_sf_fx[peak_cnt_fx].nmrValue_fx = round_fx(L_abs_in[j]); /* Qabs_in-16 */ - pk_sf_fx[peak_cnt_fx].gainIndex_fx = j; - move16(); - L_abs_in[j] = L_deposit_l(0); - peak_cnt_fx = add(peak_cnt_fx, 1); - move16(); - } - - IF( sub(peak_cnt_fx, n_nbiggestsearch) == 0 ) - { - BREAK; - } - } - } - - /* thr *= (0.3f / n_nbiggestsearch) * peak_cnt + 0.7f; */ - /* 0.3=19661(Q16) */ - temp_fx = div_s_ss(19661, n_nbiggestsearch); - L_temp = L_mult(temp_fx, peak_cnt_fx); /* 16+0+1 */ - temp_fx = add(round_fx(L_shl(L_temp, 14)), 22938); /* shift: 17+14-16 -> 15 */ /* 0.7(22937.6:Q15)*/ - L_thr = Mult_32_16(L_thr, temp_fx); - - IF( sub(peak_cnt_fx, n_nbiggestsearch) < 0 ) - { - FOR (j = 0; j < nIdx_fx; j++) - { - IF( L_sub(L_abs_in[j], L_thr) > 0 ) - { - pk_sf_fx[peak_cnt_fx].nmrValue_fx = round_fx(L_abs_in[j]); /* Qabs_in-16 */ - pk_sf_fx[peak_cnt_fx].gainIndex_fx = j; - move16(); - L_abs_in[j] = L_deposit_l(0); - peak_cnt_fx = add(peak_cnt_fx, 1); - move16(); - } - - IF( sub(peak_cnt_fx, n_nbiggestsearch) == 0 ) - { - BREAK; - } - } - } - - /* thr *= (0.6f / n_nbiggestsearch) * peak_cnt + 0.3f; */ - /* 0.6=19661(Q15) */ - temp_fx = div_s_ss(19661, n_nbiggestsearch); - L_temp = L_mult(temp_fx, peak_cnt_fx); /* 15+0+1 */ - temp_fx = add(round_fx(L_shl(L_temp, 15)), 9830); /* shift: 16+15-16 -> 15 */ /* 0.3(9830.4:Q15)*/ - - L_thr = Mult_32_16(L_thr, temp_fx); - IF( sub(peak_cnt_fx, n_nbiggestsearch) < 0 ) - { - FOR (j = 0; j < nIdx_fx; j++) - { - IF( L_sub(L_abs_in[j], L_thr) > 0 ) - { - pk_sf_fx[peak_cnt_fx].nmrValue_fx = round_fx(L_abs_in[j]); /* Qabs_in-16 */ - pk_sf_fx[peak_cnt_fx].gainIndex_fx = j; - move16(); - L_abs_in[j] = L_deposit_l(0); - peak_cnt_fx = add(peak_cnt_fx, 1); - move16(); - } - - IF( sub(peak_cnt_fx, n_nbiggestsearch) == 0 ) - { - BREAK; - } - } - } - - *n_fx = peak_cnt_fx; - move16(); -} - -/*--------------------------------------------------------------------------* - * spectrumsmooth_noiseton() - * Spectrum normalization for the the core coder - *--------------------------------------------------------------------------*/ -Word16 spectrumsmooth_noiseton_fx( /* o : Qss ss_min */ - Word32 L_spectra[], /* i : Qs core coder */ - /*Word16 Qs,*/ /* i : Q0 Q value for spectra, spectra_ni */ - const Word32 L_spectra_ni[], /* i : Qs core coder with sparse filling */ - Word16 sspectra_fx[], /* o : Qss Smoothed tonal information from core coder */ - Word16 sspectra_diff_fx[], /* o : Qss non tonal infomration for gap filling */ - Word16 sspectra_ni_fx[], /* o : Qss smoothed core coder */ - Word16 *Qss, /* o : Q0 Q value for sspectra* */ - const Word16 fLenLow_fx, /* i : Q0 low frequency boundaries */ - Word16 *ni_seed_fx /* io : Q0 random seed */ -) -{ - Word16 i; - Word32 L_spectra_diff[L_FRAME32k]; - Word16 ni_ratio_fx; /* Q15 */ - Word16 ss_min_fx; /* Q10 */ - Word16 cut_sig_th_fx; /* Q10 */ - Word16 cut_ni_th_fx; /* Q10 */ - Word16 pcnt_fx, sign_fx; - Word16 exp_normn, exp_normd; - - Word16 ratio_fx; - Word32 L_temp; - Word32 L_spectra_rm[L_FRAME32k]; - Word32 L_cut_input=410; - Word16 rand_a_fx[L_FRAME32k]; - - /* pre-prepare random array for float-fix interoperability */ - FOR(i=0; i= 0x0L ) - { - L_spectra_rm[i] = L_spectra[i]; - move32(); - } - } - SpectrumSmoothing_fx( L_spectra_rm, sspectra_fx, Qss, fLenLow_fx, cut_sig_th_fx); - - /*Extract noise informaton from the core coder*/ - Copy(sspectra_fx, sspectra_ni_fx, fLenLow_fx); - FOR(i=0; i= 0x0L ) - { - L_spectra_rm[i] = L_spectra_diff[i]; - move32(); - } - } - SpectrumSmoothing_fx( L_spectra_rm, sspectra_diff_fx, Qss, fLenLow_fx, cut_ni_th_fx); - - /*Normalized corecoder for Gap filling */ - /* ratio = 1 - ss_min/10.0 */ - ratio_fx = sub(0x7fff, shl(mult_r(ss_min_fx, 3277), 15-10)); /* Q15 */ - FOR(i=0; i 0) - { - /*sspectra[i] = sign*((10-ss_min)/10.0f*(float)fabs(sspectra[i])+ss_min);*/ - sspectra_fx[i] = add(mult_r(ratio_fx, abs_s(sspectra_fx[i])), ss_min_fx); - IF(sign_fx != 0) - { - sspectra_fx[i] = negate(sspectra_fx[i]); - move16(); - } - } - IF ( sspectra_fx[i] != 0x0 ) - { - sspectra_ni_fx[i] = sspectra_fx[i]; - move16(); - } - ELSE - { - sspectra_ni_fx[i] = mult_r(sspectra_diff_fx[i], ni_ratio_fx); - move16(); - } - - IF( sspectra_ni_fx[i] == 0x0) - { - /*sspectra_ni[i] = 0.5f*10.0f*ni_ratio* own_random(ni_seed)/32768.0f;*/ - L_temp = L_mult(ni_ratio_fx, 20480); /* ni_ratio*5 */ - L_temp = Mult_32_16(L_temp, rand_a_fx[i]); /* Q28 */ - sspectra_ni_fx[i] = round_fx(L_shr(L_temp, 2)); /* Qss */ - } - } - - return(ss_min_fx); -} - -/*--------------------------------------------------------------------------* - * noiseinj_hf() - * level adjustments for the missing bands in the core coder - *--------------------------------------------------------------------------*/ -void noiseinj_hf_fx( - Word32 L_xSynth_har[], /* i/o : Qs gap filled information */ - Word16 Qs, /* i : Q0 Q value for xSynth_har */ - Word32 L_th_g[], /* i : Qs level adjustment information */ - Word32 L_band_energy[], /* i : Qbe subband energies */ - Word16 Qbe, /* i : Q0 Q value for band_energy */ - Word16 *prev_En_sb_fx, /* i/o : QsEn smoothed sqrt band Energies */ - const Word16 p2a_flags_fx[], /* i : Q0 Missing bands in the core coder */ - const Word16 BANDS_fx, /* i : Q0 total bands */ - const Word16 band_start_fx[], /* i : Q0 band start indices */ - const Word16 band_end_fx[], /* i : Q0 band end indices */ - const Word16 fLenLow_fx, /* i : Q0 low frequency bandwidth */ - const Word16 fLenHigh_fx /* i : Q0 SWB frequency bandwidth */ -) -{ - Word16 k,i; - - Word16 *p_prev_En_sb_fx; - Word16 QbeL=7; /* Don't need 3, because this E only use under th samples */ /* QsEn=3 */ - - Word16 map_pulse_t_fx[L_FRAME32k]; - Word16 map_pulse_fx[L_FRAME32k]; - - Word16 QsEn=4; /* kiken */ - Word32 L_En[NB_SWB_SUBBANDS]; - Word32 *p_L_En; - Word16 QE; - Word16 sqrt_En_fx[NB_SWB_SUBBANDS]; /* QsEn */ - Word16 *p_sqrt_En_fx; /* QsEn */ - - Word16 Enn_sm_sb_fx[NB_SWB_SUBBANDS]; - Word16 *p_Enn_sm_sb_fx; - - Word16 exp_safe; - Word16 xSynth_har_fx[L_FRAME32k]; - Word16 QxSynth; - - Word16 Qtemp; - - Word16 ni_scale_fx; /* Q14 */ - - Word16 temp_fx; - Word32 L_temp; - - Word16 exp_normn, exp_normd; - Word16 div_fx; - Word16 Qdiv; - - set16_fx(map_pulse_t_fx, 0, band_end_fx[BANDS_fx-1]+1); - set16_fx(map_pulse_fx, 0, band_end_fx[BANDS_fx-1]+1); - - /*level adjust the missing bands in the core coder */ - exp_safe = 4; /*move16();*/ - norm_vec_32_16_scale_fx(L_xSynth_har, Qs, fLenHigh_fx, xSynth_har_fx, &QxSynth, exp_safe); - QE = add(shl(QxSynth, 1),1); - - p_L_En = L_En; - p_sqrt_En_fx = sqrt_En_fx; - FOR(k=sub(BANDS_fx, NB_SWB_SUBBANDS); k Q2 */ move16(); - } - p_L_En++; - p_sqrt_En_fx++; - } - - p_sqrt_En_fx = sqrt_En_fx; - p_Enn_sm_sb_fx = Enn_sm_sb_fx; - p_prev_En_sb_fx = prev_En_sb_fx; - FOR(k=BANDS_fx-NB_SWB_SUBBANDS; k Q14 */ - FOR(i=band_start_fx[k]; i<=band_end_fx[k]; i++) - { - IF( L_sub(L_abs(L_xSynth_har[i-fLenLow_fx]), L_th_g[k-(BANDS_fx-NB_SWB_SUBBANDS)]) <= 0x0L ) - { - IF(map_pulse_fx[i] == 0) - { - L_xSynth_har[i-fLenLow_fx] = L_shl(Mult_32_16(L_xSynth_har[i-fLenLow_fx], ni_scale_fx), 1); /* Q12+Q14-15-1 = Q12 */ move32(); - } - } - } - *p_prev_En_sb_fx = *p_Enn_sm_sb_fx; - move16(); - } - p_Enn_sm_sb_fx++; - p_sqrt_En_fx++; - p_prev_En_sb_fx++; - } - - return; -} - -/*--------------------------------------------------------------------------* - * updat_prev_frm() - * - * - *--------------------------------------------------------------------------*/ -void updat_prev_frm_fx( - Word32 L_y2[], /* i/o: core coder buffer */ - Word32 L_t_audio[], /* o: core coder buffer */ - Word32 L_bwe_br, /* i: core bitrate */ - Word16 length_fx, /* i: frame length coded bw */ - const Word16 inner_frame_fx, /* i: input frame length */ - Word16 bands_fx, /* i: sub band resolution */ - Word16 bwidth_fx, /* i: NB/WB/SWB indicator */ - const Word16 is_transient_fx, /* i: signal class information */ - Word16 hqswb_clas_fx, /* i: signal class information */ - Word16 *prev_hqswb_clas_fx, /* o: update signal class information */ - Word16 prev_SWB_peak_pos_fx[], /* o: update core coder last coded peaks*/ - Word16 prev_SWB_peak_pos_tmp_fx[], /* o: update core coder last coded peaks*/ - Word16 *prev_frm_hfe2_fx, /* o: update harmonics */ - Word16 *prev_stab_hfe2_fx, /* o: update harmonics */ - Word16 bws_cnt_fx /* i: band width detector */ -) -{ - Word16 i, j, k; - Word16 k1_fx, k2_fx; - Word16 length1_fx, length2_fx, length3_fx; - - /* Copy the coded MDCT coefficient to the output buffer */ - IF ( !is_transient_fx ) - { - /* Copy the scratch buffer to the output */ - Copy32( L_y2, L_t_audio, length_fx ); - - /* If the input frame is larger than coded bandwidth, zero out uncoded MDCT coefficients */ - IF ( sub(inner_frame_fx, length_fx) > 0 ) - { - set32_fx( L_t_audio + length_fx, 0x0L, sub(inner_frame_fx, length_fx) ); - } - } - ELSE /* transient frame */ - { - test(); - IF( sub(inner_frame_fx, length_fx) == 0 || bws_cnt_fx > 0) - { - /* Copy the scratch buffer to the output */ - Copy32( L_y2, L_t_audio, length_fx ); - } - ELSE - { - /* length/NUM_TIME_SWITCHING_BLOCKS */ - /*length1_fx = div_s_ss(length_fx, NUM_TIME_SWITCHING_BLOCKS); */ - length1_fx = shr(length_fx, 2); /* length1 = length/NUM_TIME_SWITCHING_BLOCKS */ - /* inner_frame/NUM_TIME_SWITCHING_BLOCKS */ - /*length2_fx = div_s_ss(inner_frame_fx, NUM_TIME_SWITCHING_BLOCKS); */ - length2_fx = shr(inner_frame_fx, 2); /* length2 = inner_frame/NUM_TIME_SWITCHING_BLOCKS */ - /* (inner_frame-length)/NUM_TIME_SWITCHING_BLOCKS */ - /*length3_fx = div_s_ss(sub(inner_frame_fx, length_fx), NUM_TIME_SWITCHING_BLOCKS); */ - length3_fx = shr(sub(inner_frame_fx, length_fx) ,2); /* (inner_frame-length)/NUM_TIME_SWITCHING_BLOCKS */ - - k1_fx = 0; - move16(); - k2_fx = 0; - move16(); - - /* un-collapse transient frame and interleave zeros */ - FOR( i = 0; i < NUM_TIME_SWITCHING_BLOCKS; i++ ) - { - /*k1 = i*length/NUM_TIME_SWITCHING_BLOCKS; */ - /*k2 = i*inner_frame/NUM_TIME_SWITCHING_BLOCKS; */ - - Copy32( L_y2 + k1_fx, L_t_audio + k2_fx, length1_fx ); - set32_fx( L_t_audio + k2_fx + length1_fx, 0x0L, length3_fx); - - k1_fx = add(k1_fx, length1_fx); - k2_fx = add(k2_fx, length2_fx); - - } - } - } - - IF( (L_sub(L_bwe_br, HQ_16k40) == 0 || L_sub(L_bwe_br, HQ_13k20) == 0 ) && sub(bwidth_fx, SWB) == 0 ) - { - *prev_hqswb_clas_fx = hqswb_clas_fx; - move16(); - IF ( sub(hqswb_clas_fx, HQ_HARMONIC) != 0 ) - { - *prev_frm_hfe2_fx = 0; - move16(); - *prev_stab_hfe2_fx = 0; - move16(); - } - } - ELSE - { - *prev_hqswb_clas_fx = is_transient_fx; - move16(); - } - - test(); - test(); - test(); - IF( (L_sub(L_bwe_br, HQ_16k40) == 0 || L_sub(L_bwe_br, HQ_13k20) == 0) && sub(bwidth_fx, SWB) == 0 && sub(hqswb_clas_fx, HQ_NORMAL) == 0 ) - { - j = 0; - move16(); - FOR(k=sub(bands_fx, SPT_SHORTEN_SBNUM); k +#include +#include "options.h" +#include "cnst.h" +#include "prot.h" +#include "rom_com.h" + +/*-----------------------------------------------------------------* + * Local functions + *-----------------------------------------------------------------*/ + +static void create_random_vector( float output[], const short length, short seed[] ); +static void flip_spectrum( const float input[], float output[], const short length ); +static void Hilbert_transform( float tmp_R[], float tmp_I[], float *tmpi_R, float *tmpi_I, const short length, const short HB_stage_id ); +static void Estimate_mix_factors( const float *shb_res, const float *exc16kWhtnd, const float *White_exc16k, const float pow1, + const float pow22, float *vf_modified, short *vf_ind ); +/*-------------------------------------------------------------------* + * swb_tbe_reset() + * + * Reset the SWB TBE encoder + *-------------------------------------------------------------------*/ + +void swb_tbe_reset( + float mem_csfilt[], + float mem_genSHBexc_filt_down_shb[], + float state_lpc_syn[], + float syn_overlap[], + float state_syn_shbexc[], + float *tbe_demph, + float *tbe_premph, + float mem_stp_swb[], + float *gain_prec_swb +) +{ + set_f( mem_csfilt, 0, 2); + set_f( mem_genSHBexc_filt_down_shb, 0.0f, (2*ALLPASSSECTIONS_STEEP+1) ); + set_f( state_lpc_syn, 0.0f, LPC_SHB_ORDER ); + set_f( syn_overlap, 0.0f, L_SHB_LAHEAD ); + set_f( state_syn_shbexc, 0.0f, L_SHB_LAHEAD ); + *tbe_demph = 0.0f; + *tbe_premph = 0.0f; + set_f(mem_stp_swb, 0, LPC_SHB_ORDER); + *gain_prec_swb = 1.0f; + + return; +} + +/*-------------------------------------------------------------------* + * swb_tbe_reset_synth() + * + * Reset the extra parameters needed for synthesis of the SWB TBE output + *-------------------------------------------------------------------*/ + +void swb_tbe_reset_synth( + float genSHBsynth_Hilbert_Mem[], + float genSHBsynth_state_lsyn_filt_shb_local[] +) +{ + set_f( genSHBsynth_Hilbert_Mem, 0.0f, HILBERT_MEM_SIZE ); + set_f( genSHBsynth_state_lsyn_filt_shb_local, 0.0f, 2 * ALLPASSSECTIONS_STEEP ); + + return; +} + +/*-------------------------------------------------------------------* + * tbe_celp_exc_offset() + * + * Compute tbe bwe celp excitation offset + *-------------------------------------------------------------------*/ +short tbe_celp_exc_offset( + const short T0, /* i : Integer pitch */ + const short T0_frac /* i : Fractional part of the pitch */ +) +{ + short offset; + offset = T0 * HIBND_ACB_L_FAC + + (int) ((float) T0_frac * 0.25f * HIBND_ACB_L_FAC + 2 * HIBND_ACB_L_FAC + 0.5f) + - 2 * HIBND_ACB_L_FAC; + + return offset; +} +/*-------------------------------------------------------------------* + * flip_and_downmix_generic() + * + * flips the spectrum and downmixes the signals, lpf if needed + *-------------------------------------------------------------------*/ + +void flip_and_downmix_generic( + float input[], /* i : input spectrum */ + float output[], /* o : output spectrum */ + const short length, /* i : length of spectra */ + float mem1_ext[], /* i/o: Hilbert filter memory */ + float mem2_ext[], /* i/o: memory */ + float mem3_ext[], /* i/o: memory */ + short *phase_state /* i/o: Phase state in case frequency isn't multiple of 50 Hz */ +) +{ + short i, j; + float tmp[L_FRAME32k + HILBERT_ORDER1]; + float tmpi_R[L_FRAME32k]; + float tmpi_I[L_FRAME32k]; + float tmpi2_R[L_FRAME32k + HILBERT_ORDER2]; + float tmpi2_I[L_FRAME32k + HILBERT_ORDER2]; + float tmp_R[L_FRAME32k + HILBERT_ORDER2]; + float tmp_I[L_FRAME32k + HILBERT_ORDER2]; + short k, period; + float recip_period; + float local_negsin_table[L_FRAME16k]; + float local_cos_table[L_FRAME16k]; + + period = 17; /* == (short) (32000.0f / 1850.0f + 0.5f); */ + + recip_period = 256.0f / (float) period; + for( i=0; i= period ) + { + *phase_state = 0; + } + + for( i=0, j=*phase_state; i < length; ) + { + for( ; (j < period) && (i < length); j++, i++ ) + { + output[i] = tmp_R[i + HILBERT_ORDER2] * local_cos_table[j] + tmp_I[i + HILBERT_ORDER2] * local_negsin_table[j]; + } + + if( j >= period ) + { + j = 0; + } + } + + *phase_state = j; + + return; +} + +/*---------------------------------------------- + * Hilbert_transform() + * + * Hilbert transform + *------------------------------------------------*/ + +static void Hilbert_transform( + float tmp_R[], /* i: Real component of HB */ + float tmp_I[], /* i: Real component of HB */ + float tmpi_R[], /* o: Real component of HB */ + float tmpi_I[], /* o: Imag. component of HB */ + const short length, /* i: input length */ + const short HB_stage_id /* i: HB transform stage */ +) +{ + short i, hb_filter_stage, offset; + + hb_filter_stage = 2*HB_stage_id; + offset = (HB_stage_id == 0) ? 1 : 0; + + if (HB_stage_id == 0 || HB_stage_id == 2) + { + for( i=0; i 0.35f) ) + { + csfilt_num2[0] = 0.2f; + csfilt_den2[1] = -0.8f; + } + else if( igf_flag && (coder_type == UNVOICED || avg_voice_fac < 0.2f) ) + { + csfilt_num2[0] = 0.01f; + csfilt_den2[1] = -0.99f; + } + set_f( wht_fil_mem, 0, LPC_WHTN_ORDER_WB ); + + Decimate_allpass_steep( bwe_exc_extended, mem_genSHBexc_filt_down1, L_FRAME32k, excTmp ); + + flip_spectrum_and_decimby4( excTmp, exc4k, L_FRAME16k, mem_genSHBexc_filt_down2, mem_genSHBexc_filt_down3, 0 ); + + if( uv_flag ) + { + /* unvoiced signal */ + create_random_vector( exc4kWhtnd, L_FRAME16k/4, bwe_seed ); + } + else + { + autocorr(exc4k, R, LPC_WHTN_ORDER_WB+1, L_FRAME16k/4, win_flatten_4k, 0, 1, 1); + + /* Ensure R[0] isn't zero when entering Levinson Durbin */ + R[0] = max(R[0], 1.0e-8f); + for( i = 0; i <= LPC_WHTN_ORDER_WB; i++ ) + { + R[i] = R[i] * wac[i]; + } + lev_dur( lpc_whtn, R, LPC_WHTN_ORDER_WB, ervec ); + + fir( exc4k, lpc_whtn, exc4kWhtnd, wht_fil_mem, L_FRAME16k/4, LPC_WHTN_ORDER_WB, 0); + + /* Ensure pow1 is greater than zero when computing normalization */ + for( i=0, pow1=0.00001f; i 1.0f) + { + formant_fac = 1.0f; + } + else if (formant_fac < 0.0f) + { + formant_fac = 0.0f; + } + + formant_fac = 1.0f - 0.5f*formant_fac; + + return formant_fac; +} + +/*-------------------------------------------------------------------* + * GenShapedSHBExcitation() + * + * Synthesize spectrally shaped highband excitation signal + *-------------------------------------------------------------------*/ + +void GenShapedSHBExcitation( + float *excSHB, /* o : synthesized shaped shb excitation */ + const float *lpc_shb, /* i : lpc coefficients */ + float *White_exc16k_FB, /* o : white excitation for the Fullband extension */ + float *mem_csfilt, /* i/o: memory */ + float *mem_genSHBexc_filt_down_shb,/* i/o: memory */ + float *state_lpc_syn, /* i/o: memory */ + const short coder_type, /* i : coding type */ + const float *bwe_exc_extended, /* i : bandwidth extended excitation */ + short bwe_seed[], /* i/o: random number generator seed */ + float voice_factors[], /* i : voicing factor*/ + const short extl, /* i : extension layer */ + float *tbe_demph, /* i/o: de-emphasis memory */ + float *tbe_premph, /* i/o: pre-emphasis memory */ + float *lpc_shb_sf, /* i: LP coefficients */ + float *shb_ener_sf, + float *shb_res_gshape, + float *shb_res, + short *vf_ind, + const float formant_fac, /* i : Formant sharpening factor [0..1] */ + float fb_state_lpc_syn[], /* i/o: memory */ + float *fb_tbe_demph, /* i/o: fb de-emphasis memory */ + const long bitrate, /* i : bitrate */ + const short prev_bfi /* i : previous frame was concealed */ +) +{ + short i, j, k; + float wht_fil_mem[LPC_WHTN_ORDER]; + float lpc_whtn[LPC_WHTN_ORDER + 1]; + float R[LPC_WHTN_ORDER + 2]; + float exc32k[L_FRAME32k], exc16k[L_FRAME16k]; + float pow1, pow22, scale, temp1, temp2; + float excTmp2[L_FRAME16k]; + short nbSubFr; + float excNoisyEnv[ L_FRAME16k]; + float csfilt_num2[1] = {0.2f}; + float csfilt_den2[2] = {1.0f, -0.8f}; + float varEnvShape; + float ervec[LPC_WHTN_ORDER+2]; + float exc16kWhtnd[L_FRAME16k]; + float temp = 0.0f; + float *White_exc16k; + float voiceFacEst[NB_SUBFR16k]; + float syn_shb_ener_sf[4], tempSHB[80]; + float zero_mem[LPC_SHB_ORDER]; + float vf_tmp; + float White_exc16k_FB_temp[L_FRAME16k]; + float fb_deemph_fac = 0.48f; + + set_f( zero_mem, 0, LPC_SHB_ORDER); + set_f( wht_fil_mem, 0, LPC_WHTN_ORDER ); + + for(i = 0; i < L_FRAME32k; i++) + { + exc32k[i] = ((i%2)==0)?(-bwe_exc_extended[i]):(bwe_exc_extended[i]); + } + + /* Decimate by 2 */ + Decimate_allpass_steep( exc32k, mem_genSHBexc_filt_down_shb, 2*L_FRAME16k, exc16k ); + + autocorr( exc16k, R, LPC_WHTN_ORDER+1, L_FRAME16k, win_flatten, 0, 1, 1 ); + + /* Ensure R[0] isn't zero when entering Levinson-Durbin */ + R[0] = max(R[0], 1.0e-8f); + for( i = 0; i <= LPC_WHTN_ORDER; i++ ) + { + R[i] = R[i] * wac[i]; + } + + /* Ensure R[0] isn't zero when entering Levinson-Durbin */ + R[0] += 1.0e-8f; + lev_dur( lpc_whtn, R, LPC_WHTN_ORDER, ervec ); + + fir( exc16k, lpc_whtn, exc16kWhtnd, wht_fil_mem, L_FRAME16k, LPC_WHTN_ORDER, 0 ); + + if( bitrate >= ACELP_24k40 ) + { + for(i = 0; i < L_FRAME16k; i++) + { + exc16kWhtnd[i] *= shb_res_gshape[(short)(i/80)]; + } + } + + for( k=0, pow1=0.00001f; k= ACELP_7k20) + { + varEnvShape = mean(voice_factors, 4); + } + else + { + varEnvShape = mean(voice_factors, 5); + } + + if ( extl == FB_TBE) + { + fb_deemph_fac = max((0.68f - (float)pow(varEnvShape, 3)), 0.48f); + } + + varEnvShape = 1.09875f - 0.49875f * varEnvShape; + varEnvShape = min( max(varEnvShape, 0.6f), 0.999f); + csfilt_num2[0] = 1.0f - varEnvShape; + csfilt_den2[1] = - varEnvShape; + + if (*mem_csfilt == 0 && ( bitrate == ACELP_9k60 || bitrate == ACELP_16k40 || bitrate == ACELP_24k40 ) ) + { + /* pre-init smoothing avoid energy drop outs */ + float tmp_scale = 0; + for (i=0; i= ACELP_24k40 ) + { + if( *vf_ind == 20 ) /* encoder side */ + { + Estimate_mix_factors( shb_res, exc16kWhtnd, White_exc16k, pow1, pow22, voiceFacEst, vf_ind ); + temp = (voiceFacEst[0] > 0.7f)? 1.0f : 0.8f; + } + else /* decoder side */ + { + temp = ((*vf_ind * 0.125f) > 0.7f)? 1.0f : 0.8f; + } + for(i = 0; i < NB_SUBFR16k; i++) + { + voice_factors[i] *= temp; + } + } + + mvr2r( White_exc16k, White_exc16k_FB, L_FRAME16k ); + deemph( White_exc16k, PREEMPH_FAC, L_FRAME16k, tbe_demph ); + + if( coder_type == UNVOICED ) + { + scale = sqrt( pow1/pow22 ); + if (pow22 == 0.f) scale = 0; + for( k=0; k ths ) + { + en_abs = 1; + } + + + + + + p_out = output + NL_BUFF_OFFSET; /* NL_BUFF_OFFSET = 12 */ + /* update buffer memory */ + mvr2r( old_bwe_exc_extended, output, NL_BUFF_OFFSET ); + + for (i=j=0; i max) + { + max = temp; + j = i; + } + } + + if (max > 1.0f) + { + scale = 0.67f / max; + } + else + { + scale = 0.67f; + } + + + if ( *prev_scale <= 0.0 || *prev_scale > 1024.0f * scale ) + { + scale_step = 1.0; + *prev_scale = scale; + } + else + { + scale_step = 1.0f; + if(j != 0) + { + scale_step = (float) exp(1.0f / (float) j * (float) log(scale / *prev_scale)); + } + } + + for (i=0; i= 0.0) + { + *p_out++ = (input[i] * input[i]) **prev_scale; + } + else + { + if (en_abs) + { + *p_out++ = 1.0f * (input[i] * input[i]) **prev_scale; + } + else + { + *p_out++ = -1.0f * (input[i] * input[i]) **prev_scale; + } + + } + + if (i < j) + { + *prev_scale *= scale_step; + } + } + + max = 0.0f; + for (i=j=length/2; i max) + { + max = temp; + j = i; + } + } + + if (max > 1.0f) + { + scale = 0.67f / max; + } + else + { + scale = 0.67f; + } + + + if ( *prev_scale <= 0.0 || *prev_scale > 1024.0f * scale ) + { + scale_step = 1.0; + *prev_scale = scale; + } + else + { + scale_step = 1.0f; + if(j != length/2) + { + scale_step = (float) exp(1.0f / (float) (j - length/2) * (float) log(scale / *prev_scale)); + } + } + + for (i=length/2; i= 0.0) + { + *p_out++ = (input[i] * input[i]) **prev_scale; + } + else + { + if (en_abs) + { + *p_out++ = 1.0f * (input[i] * input[i]) **prev_scale; + } + else + { + *p_out++ = -1.0f * (input[i] * input[i]) **prev_scale; + } + } + + if (i < j) + { + *prev_scale *= scale_step; + } + } + + /* update buffer memory */ + mvr2r( output + L_FRAME32k, old_bwe_exc_extended, NL_BUFF_OFFSET ); + + return; +} + + +/*-------------------------------------------------------------------* + * create_random_vector() + * + * creates random number vector + * -------------------------------------------------------------------*/ + +void create_random_vector( + float output[], /* o : output random vector */ + const short length, /* i : length of random vector */ + short seed[] /* i/o: start seed */ +) +{ + short i, j, k; + float scale1, scale2; + + j = (short) (own_random(&seed[0]) * 0.0078f); + j = abs(j) & 0xff; + k = (short) (own_random(&seed[1]) * 0.0078f); + k = abs(k) & 0xff; + + while( k==j ) + { + k = (short)(own_random(&seed[1]) * 0.0078f); + k = abs(k) & 0xff; + } + + if( own_random(&seed[0]) < 0 ) + { + scale1 = -563.154f; /* -200.00f * 0.35f/0.1243f; */ + } + else + { + scale1 = 563.154f; /* 200.00f * 0.35f/0.1243f; */ + } + + if( own_random(&seed[1]) < 0 ) + { + scale2 = -225.261f; /* -80.00f * 0.35f/0.1243f; */ + } + else + { + scale2 = 225.261f; /* 80.00f * 0.35f/0.1243f; */ + } + + for( i=0; i 115.5f) && core_brate > ACELP_8k00 ) + { + tmp = 1.0f; + *voice_factors *= tmp; + } + + *voice_factors = min( max(0.000001f, *voice_factors), 0.999999f); + + if( L_frame == L_FRAME ) + { + interp_code_5over2( code, tmp_code, L_SUBFR ); + + for( i = 0; i < L_SUBFR * HIBND_ACB_L_FAC; i++ ) + { + bwe_exc[i + i_subfr * HIBND_ACB_L_FAC] = gain_pit * bwe_exc[i + i_subfr * HIBND_ACB_L_FAC] + + gain_code * tmp_code[i]; + } + } + else + { + for( i = 0; i < L_SUBFR; i++ ) + { + tmp_code_preInt[i] = gain_code * code[i] + 2 * gain_preQ * code_preQ[i]; + } + + interp_code_4over2( tmp_code_preInt, tmp_code, L_SUBFR ); + + for( i = 0; i < L_SUBFR * 2; i++ ) + { + bwe_exc[i + i_subfr * 2] = gain_pit * bwe_exc[i + i_subfr * 2] + tmp_code[i]; + } + } + + return; +} + + +/*-------------------------------------------------------------------* + * get_tbe_bits() * + * * + * Determine TBE bit consumption per frame from bit rate * + *-------------------------------------------------------------------*/ + +short get_tbe_bits( + short bitrate, + short bandwidth, + short rf_mode +) +{ + short i, bits = 0; + + if( rf_mode ) + { + /* TBE bits for core, primary frame */ + if( bandwidth == WB && bitrate == ACELP_13k20 ) + { + /* Gain frame: 4, Gain shapes: 0, and LSFs: 2 */ + bits = NUM_BITS_SHB_FrameGain_LBR_WB + NUM_BITS_LBR_WB_LSF; + } + else if( bandwidth == SWB && bitrate == ACELP_13k20 ) + { + /* Gain frame: 5, Gain shapes: 5, and lowrate LSFs: 8 */ + bits = NUM_BITS_SHB_FRAMEGAIN + NUM_BITS_SHB_SUBGAINS + 8; + } + } + else + { + if( bandwidth == WB && bitrate == ACELP_9k60 ) + { + bits = NUM_BITS_LBR_WB_LSF + NUM_BITS_SHB_FrameGain_LBR_WB; + } + else if( bandwidth == SWB || bandwidth == FB ) + { + if( bitrate == ACELP_9k60 ) + { + bits = NUM_BITS_SHB_FRAMEGAIN + NUM_BITS_SHB_SUBGAINS + 8; + } + else if( bitrate >= ACELP_13k20 && bitrate <= ACELP_32k ) + { + bits = NUM_BITS_SHB_SUBGAINS + NUM_BITS_SHB_FRAMEGAIN + NUM_LSF_GRID_BITS + MIRROR_POINT_BITS; + + for( i=0; i= ACELP_24k40 ) + { + bits += NUM_BITS_SHB_ENER_SF + NUM_BITS_SHB_VF + NUM_BITS_SHB_RES_GS*NB_SUBFR16k; + } + + if( bandwidth == SWB && (bitrate == ACELP_16k40 || bitrate == ACELP_24k40) ) + { + bits += BITS_TEC + BITS_TFA; + } + + if( bandwidth == FB ) + { + /* fullband slope */ + bits += 4; + } + } + } + + return bits; +} diff --git a/src/libs/libevs/lib_com/swb_tbe_com_fx.cpp b/src/libs/libevs/lib_com/swb_tbe_com_fx.cpp deleted file mode 100755 index 9461c911..00000000 --- a/src/libs/libevs/lib_com/swb_tbe_com_fx.cpp +++ /dev/null @@ -1,3612 +0,0 @@ -/*==================================================================================== - EVS Codec 3GPP TS26.442 Apr 03, 2018. Version 12.11.0 / 13.6.0 / 14.2.0 - ====================================================================================*/ - - -#include -#include "options.h" -#include "cnst_fx.h" -#include "prot_fx.h" -#include "rom_com_fx.h" -#include "stl.h" -#include "basop_util.h" - -/*-----------------------------------------------------------------* -* Local functions -*-----------------------------------------------------------------*/ - -static void create_random_vector_fx( Word16 output[], const Word16 length, Word16 seed[] ); - -static void flip_spectrum_fx( const Word16 input[], Word16 output[], const Word16 length ); - -static void Calc_st_filt_tbe(Word16 * apond2,Word16 * apond1,Word16 * parcor0,Word16 * sig_ltp_ptr,Word16 * mem_zero ); - -static void Hilbert_transform_fx( Word32 tmp_R[], Word32 tmp_I[], Word32 *tmpi_R, Word32 *tmpi_I, const Word16 length, const Word16 HB_stage_id ); - -static void Hilbert_transform_sp_fx( Word16 tmp_R[], Word16 tmp_I[], Word32 *tmpi_R, Word32 *tmpi_I, const Word16 length, const Word16 HB_stage_id ); - -void Estimate_mix_factors_fx( const Word16 *shb_res, const Word16 Q_shb, const Word16 *exc16kWhtnd, const Word16 Q_bwe_exc, const Word16 *White_exc16k_frac, - const Word16 Q_frac, const Word32 pow1, const Word16 Q_pow1, const Word32 pow22, const Word16 Q_pow22, Word16 *vf_modified, Word16 *vf_ind ); - -/*-------------------------------------------------------------------* -* swb_tbe_reset() -* -* Reset the SWB TBE encoder -*-------------------------------------------------------------------*/ - - -void swb_tbe_reset_fx( - Word32 mem_csfilt[], - Word16 mem_genSHBexc_filt_down_shb[], - Word16 state_lpc_syn[], - Word16 syn_overlap[], - Word16 state_syn_shbexc[], - Word16* tbe_demph, - Word16* tbe_premph, - Word16 mem_stp_swb[], - Word16* gain_prec_swb -) -{ - set32_fx( mem_csfilt, 0, 2 ); - set16_fx( mem_genSHBexc_filt_down_shb, 0, (2*ALLPASSSECTIONS_STEEP+1)); - set16_fx( state_lpc_syn, 0, LPC_SHB_ORDER ); - - set16_fx( syn_overlap, 0, L_SHB_LAHEAD ); - set16_fx( state_syn_shbexc, 0, L_SHB_LAHEAD ); - - *tbe_demph = 0; - move16(); - *tbe_premph = 0; - move16(); - - set16_fx(mem_stp_swb, 0, LPC_SHB_ORDER); - *gain_prec_swb = 16384; - move16();/*Q14 = 1 */ - - return; -} - - -/*-------------------------------------------------------------------* -* swb_tbe_reset_synth() -* -* Reset the extra parameters needed for synthesis of the SWB TBE output -*-------------------------------------------------------------------*/ - - -void swb_tbe_reset_synth_fx( - Word32 genSHBsynth_Hilbert_Mem[], - Word16 genSHBsynth_state_lsyn_filt_shb_local_fx[] ) -{ - - set32_fx( genSHBsynth_Hilbert_Mem, 0, HILBERT_MEM_SIZE ); - set16_fx( genSHBsynth_state_lsyn_filt_shb_local_fx, 0, 2*ALLPASSSECTIONS_STEEP ); - - return; -} - - -/*-------------------------------------------------------------------* - * fb_tbe_reset_synth_fx() - * - * reset of FB TBE memories - *-------------------------------------------------------------------*/ - -void fb_tbe_reset_synth_fx( - Word32 fbbwe_hpf_mem_fx[][4], - Word16 fbbwe_hpf_mem_fx_Q[], - Word16 *prev_fbbwe_ratio_fx -) -{ - set32_fx( fbbwe_hpf_mem_fx[0], 0, 4 ); - set32_fx( fbbwe_hpf_mem_fx[1], 0, 4 ); - set32_fx( fbbwe_hpf_mem_fx[2], 0, 4 ); - set32_fx( fbbwe_hpf_mem_fx[3], 0, 4 ); - set16_fx( fbbwe_hpf_mem_fx_Q, 0, 4 ); - *prev_fbbwe_ratio_fx = 1; - move16(); /*should be set to 1.0f, scaling unknown */ - - return; -} - - -/*-------------------------------------------------------------------* - * tbe_celp_exc_offset() - * - * Compute tbe bwe celp excitation offset - *-------------------------------------------------------------------*/ - -Word16 tbe_celp_exc_offset( - const Word16 T0_fx, /* i : Integer pitch */ - const Word16 T0_frac_fx, /* i : Fractional part of the pitch */ - const Word16 L_frame /* i : frame lenght */ -) -{ - Word16 offset_fx, tmp_fx, tmp1_fx, tmp2_fx, tmp_fac; - tmp_fac = 320; - move16(); /*2.5 in Q7*/ - if(sub(L_frame, L_FRAME16k) == 0) - { - tmp_fac = 256; - move16(); /*2.0 in Q7*/ - } - tmp_fx = extract_l(L_mult(T0_frac_fx,32));/*Q8, 0.25 in Q7*/ - tmp_fx = add(512,tmp_fx);/*Q8; 2 in Q8*/ - tmp_fx = mult_r(tmp_fx,tmp_fac);/*Q16->Q0; 2.5 in Q7 or 2.0 in Q7 */ - - tmp1_fx = sub(T0_fx,2);/*Q0*/ - - tmp2_fx = shl(tmp1_fx,1);/*Q0 */ - - IF(sub(L_frame, L_FRAME) == 0) - { - tmp2_fx = add(shl(tmp1_fx,1),shr(tmp1_fx,1));/*Q0; (5/2 = 2 + 1/2)*/ - } - - offset_fx = add(tmp_fx,tmp2_fx);/*Q0*/ - - return offset_fx; -} - -/*-------------------------------------------------------------------* -* swb_tbe_celp_exc() -* -* Compute tbe bwe celp excitation -*-------------------------------------------------------------------*/ -void tbe_celp_exc( - const Word16 L_frame_fx, /* i : Frame lenght */ - const Word16 i_subfr_fx, /* i : sub frame */ - const Word16 T0_fx, /* i : Integer pitch */ - const Word16 T0_frac_fx, /* i : Fractional part of the pitch */ - Word16 *error_fx, /* i/o: Error */ - Word16 *bwe_exc_fx /* i/o: bandwitdh extension signal */ -) -{ - Word16 offset_fx, tmp_fx, i; - IF( sub(L_frame_fx,L_FRAME) == 0 ) - { - /*offset = T0 * HIBND_ACB_L_FAC + (int) ((float) T0_frac * 0.25f * HIBND_ACB_L_FAC + 2 * HIBND_ACB_L_FAC + 0.5f) - 2 * HIBND_ACB_L_FAC; - for (i=0; i0) - { - tmp_fx = shr(*error_fx,5);/*Q0*/ - } - ELSE - { - tmp_fx = negate(shr(abs_s(*error_fx),5));/*Q0*/ - } - - FOR (i=0; i0) - { - tmp_fx = shr(*error_fx,5);/*Q0*/ - } - ELSE - { - tmp_fx = negate(shr(abs_s(*error_fx),5));/*Q0*/ - } - - FOR (i=0; i= period ) - { - *phase_state = 0; - move16(); - } - - i = 0; - move16(); - j = *phase_state; - move16(); - - WHILE ( i < length ) - { - WHILE ( ( j < period ) && ( i < length ) ) - { - L_tmp = Mult_32_16( tmp_R[i + 4], local_cos_table[j] ); /*//Qx+16 */ - L_tmp = Madd_32_16( L_tmp, tmp_I[i + 4], local_negsin_table[j] ); /*Qx+16 */ - output[i] = round_fx( L_tmp ); /*Qx */ - i++ ; - j++ ; - } - - if ( j >= period ) - { - j = 0; - move16(); - } - } - - *phase_state = j; - move16(); - return; -} - - -/*---------------------------------------------- - * Hilbert transform - Double precision - *------------------------------------------------*/ -static void Hilbert_transform_fx( Word32 tmp_R[], /* i: Real component of HB */ - Word32 tmp_I[], /* i: Real component of HB */ - Word32 tmpi_R[], /* o: Real component of HB */ - Word32 tmpi_I[], /* o: Imag. component of HB */ - const Word16 length, /* i: input length */ - const Word16 HB_stage_id /* i: HB transform stage */ - ) -{ - Word16 i, hb_filter_stage, offset; - Word32 L_tmp; - - hb_filter_stage = 2*HB_stage_id; - offset = 0; - move16(); - if( HB_stage_id == 0 ) - { - offset = 1; - move16(); - } - - test(); - test(); - IF (HB_stage_id == 0 || HB_stage_id == 2) - { - FOR ( i = 0; i < length; i++ ) - { - L_tmp = Mult_32_16( tmp_R[i + 4], Hilbert_coeffs_fx[hb_filter_stage][0 + offset] ); /*Qx+15 */ - L_tmp = Madd_32_16( L_tmp, tmp_R[i + 2], Hilbert_coeffs_fx[hb_filter_stage][2 + offset] ); /*Qx+15 */ - L_tmp = Madd_32_16( L_tmp, tmp_R[i] , Hilbert_coeffs_fx[hb_filter_stage][4 + offset] );/*Qx+15 */ - tmpi_R[i] = L_shl( L_tmp, 1 ); - move32(); /*Qx+16 */ - - L_tmp = Mult_32_16( tmp_I[i + 4 + offset], Hilbert_coeffs_fx[hb_filter_stage+1][0] ); /*Qx+15 */ - L_tmp = Madd_32_16( L_tmp, tmp_I[i + 2 + offset], Hilbert_coeffs_fx[hb_filter_stage+1][2] ); /*Qx+15 */ - L_tmp = Madd_32_16( L_tmp, tmp_I[i + offset] , Hilbert_coeffs_fx[hb_filter_stage+1][4] ); /*Qx+15 */ - tmpi_I[i] = L_shl( L_tmp, 1 ); - move32(); /*Qx+16 */ - } - } - ELSE IF (HB_stage_id == 1 || HB_stage_id == 3) - { - FOR ( i = 0; i < length; i++ ) - { - - L_tmp = Mult_32_16( tmpi_R[i + 2], Hilbert_coeffs_fx[hb_filter_stage][2] ); /*Qx+15 */ - L_tmp = Madd_32_16( L_tmp, tmpi_R[i] , Hilbert_coeffs_fx[hb_filter_stage][4] ); /*Qx+15 */ - tmpi_R[i + 4] = L_sub( tmp_R[i], L_shl( L_tmp, 1 ) ); - move32();/*Qx+16 */ - - L_tmp = Mult_32_16( tmpi_I[i + 2], Hilbert_coeffs_fx[hb_filter_stage+1][2] ); /*Qx+15 */ - L_tmp = Madd_32_16( L_tmp, tmpi_I[i] , Hilbert_coeffs_fx[hb_filter_stage+1][4] ); /*Qx+15 */ - tmpi_I[i + 4] = L_sub( tmp_I[i], L_shl( L_tmp, 1 ) ); - move32(); /*Qx+16 */ - } - } -} - - -/*---------------------------------------------- -* Hilbert transform - Single precision Stage 0 -*------------------------------------------------*/ -static void Hilbert_transform_sp_fx( Word16 tmp_R[], /* i: Real component of HB */ - Word16 tmp_I[], /* i: Real component of HB */ - Word32 tmpi_R[], /* o: Real component of HB */ - Word32 tmpi_I[], /* o: Imag. component of HB */ - const Word16 length, /* i: input length */ - const Word16 HB_stage_id /* i: HB transform stage */ - ) -{ - Word16 i, hb_filter_stage, offset; - Word32 L_tmp; - - hb_filter_stage = shl(HB_stage_id,1); - offset = 0; - move16(); - if( HB_stage_id == 0 ) - { - offset = 1; - move16(); - } - - /* Hilbert single precision stage 0 */ - FOR ( i = 0; i < length; i++ ) - { - L_tmp = L_mult( tmp_R[i + 4], Hilbert_coeffs_fx[hb_filter_stage][0 + offset] ); /*Qx */ - L_tmp = L_mac ( L_tmp, tmp_R[i + 2], Hilbert_coeffs_fx[hb_filter_stage][2 + offset] ); /*Qx */ - L_tmp = L_mac ( L_tmp, tmp_R[i] , Hilbert_coeffs_fx[hb_filter_stage][4 + offset] ); /*Qx */ - tmpi_R[i] = L_shl ( L_tmp, 1 ); - move32(); /*Qx+16 */ - - L_tmp = L_mult( tmp_I[i + 4 + offset], Hilbert_coeffs_fx[hb_filter_stage+1][0] ); /*Qx */ - L_tmp = L_mac ( L_tmp, tmp_I[i + 2 + offset], Hilbert_coeffs_fx[hb_filter_stage+1][2] ); /*Qx */ - L_tmp = L_mac ( L_tmp, tmp_I[i + offset] , Hilbert_coeffs_fx[hb_filter_stage+1][4] ); /*Qx */ - tmpi_I[i] = L_shl ( L_tmp, 1 ); - move32(); /*Qx+16 */ - } - - return; -} - - -/*---------------------------------------------- - * flip_spectrum_fx - *----------------------------------------------*/ -void flip_spectrum_fx( - const Word16 input[], /* i : input spectrum */ - Word16 output[], /* o : output spectrum */ - const Word16 length /* i : vector length */ -) -{ - Word16 i; - - FOR ( i = 0; i < length; i = i + 2 ) - { - output[i] = negate( input[i] ); - move16(); - output[i + 1] = input[i + 1]; - move16(); - } - - return; -} - - -/*---------------------------------------------------------------------------- - * calc_rc0_h - * - * computes 1st parcor from composed filter impulse response - *---------------------------------------------------------------------------*/ -void Calc_rc0_h( - Word16 * h, /* i : impulse response of composed filter */ - Word16 * rc0 /* o : 1st parcor */ -) -{ - Word32 L_acc; - Word16 *ptrs; - Word16 acf0, acf1; - Word16 temp, sh_acf; - Word16 i; - - /* computation of the autocorrelation function acf */ - L_acc = L_mult(h[0], h[0]); - FOR(i = 1; i < LONG_H_ST; i++) - { - L_acc = L_mac(L_acc, h[i], h[i]); - } - sh_acf = norm_l(L_acc); - L_acc = L_shl(L_acc, sh_acf); - acf0 = extract_h(L_acc); - - ptrs = h; - - temp = *ptrs++; - move16(); - L_acc = L_mult(temp, *ptrs); - FOR(i = 1; i < LONG_H_ST - 1; i++) - { - temp = *ptrs++; - move16(); - L_acc = L_mac(L_acc, temp, *ptrs); - } - L_acc = L_shl(L_acc, sh_acf); - acf1 = extract_h(L_acc); - - /* Compute 1st parcor */ - if (acf0 == 0) - { - *rc0 = 0; - move16(); - return; - } - - IF (sub(acf0, abs_s(acf1)) < 0) - { - *rc0 = 0; - move16(); - return; - } - *rc0 = div_s(abs_s(acf1), acf0); - move16(); - if (acf1 > 0) - { - *rc0 = negate(*rc0); - move16(); - } -} - -static void Calc_st_filt_tbe( - Word16 * apond2, /* i : coefficients of numerator */ - Word16 * apond1, /* i : coefficients of denominator */ - Word16 * parcor0, /* o : 1st parcor calcul. on composed filter */ - Word16 * sig_ltp_ptr, /* i/o: i of 1/A(gamma1) : scaled by 1/g0 */ - Word16 * mem_zero /* i : All zero memory */ -) -{ - Word32 L_g0; - - Word16 h[LONG_H_ST]; - - Word16 g0, temp; - Word16 i; - temp = sub( 2, norm_s( apond2[0] ) ); - /* compute i.r. of composed filter apond2 / apond1 */ - Syn_filt_s(temp, apond1, LPC_SHB_ORDER, apond2, h, LONG_H_ST, mem_zero, 0); - /* compute 1st parcor */ - Calc_rc0_h(h, parcor0); - - /* compute g0 */ - L_g0 = L_mult0(1, abs_s(h[0])); - FOR (i = 1; i < LONG_H_ST; i++) - { - L_g0 = L_mac0(L_g0, 1, abs_s(h[i])); - } - g0 = extract_h(L_shl(L_g0, 14)); - - /* Scale signal i of 1/A(gamma1) */ - IF (sub(g0, 1024) > 0) - { - temp = div_s(1024, g0); /* temp = 2**15 / gain0 */ - FOR (i = 0; i < L_SUBFR16k; i++) - { - sig_ltp_ptr[i] = mult_r(sig_ltp_ptr[i], temp); - move16(); - } - } -} - -static void filt_mu_fx( - const Word16 *sig_in, /* i : signal (beginning at sample -1) */ - Word16 *sig_out, /* o : output signal */ - const Word16 parcor0, /* i : parcor0 (mu = parcor0 * gamma3) */ - Word16 SubFrameLength /* i : the length of subframe */ -) -{ - Word16 n; - Word16 mu, ga, temp; - const Word16 *ptrs; - Word16 tmp,exp; - - - IF ( SubFrameLength == L_SUBFR ) - { - IF (parcor0 > 0) - { - mu = mult_r(parcor0 , GAMMA3_PLUS_FX); - } - ELSE - { - mu = mult_r(parcor0 , GAMMA3_MINUS_FX); - } - } - ELSE - { - IF(parcor0 > 0) - { - mu = mult_r( parcor0 , GAMMA3_PLUS_WB_FX); - } - ELSE - { - mu = mult_r( parcor0 , GAMMA3_MINUS_WB_FX); - } - } - - tmp = abs_s(mu); - tmp = sub(32767 , tmp); - exp = norm_s(tmp); - tmp = div_s(shl(1,sub(14,exp)),tmp);/*(14 - exp) */ - ga = shl(tmp ,exp);/*Q14 */ - - - /* ga = (float) 1. / ((float) 1. - (float) fabs (mu)); */ - - ptrs = sig_in; /* points on sig_in(-1) */ - - FOR (n = 0; n < SubFrameLength; n++) - { - temp = mult_r(mu , (*ptrs++)); - temp = add (temp ,*ptrs );/*Q12 */ - sig_out[n] = shl(mult_r( ga , temp),1); - move16();/*Q12 */ - } - - return; -} - -static void scale_st_swb( - const Word16 * sig_in_fx, /* i : postfilter i signal */ - Word16 * sig_out_fx, /* i/o: postfilter o signal */ - Word16 * gain_prec_fx, /* i/o: last value of gain for subframe */ - Word16 SubFrameLength -) -{ - Word16 i; - Word16 agc_fac1_para_fx; - Word16 agc_fac_para_fx; - Word32 L_acc,L_temp; - Word16 g0_fx, gain_fx; - Word16 scal_in, scal_out; - Word16 s_g_in, s_g_out,sh_g0,temp; - - - IF( SubFrameLength == L_SUBFR ) - { - agc_fac1_para_fx = AGC_FAC1_FX; - move16(); - agc_fac_para_fx = AGC_FAC_FX; - move16(); - } - ELSE /*IF( SubFrameLength == L_SUBFR16k ) */ - { - agc_fac1_para_fx = AGC_FAC1_WB_FX; - move16(); - agc_fac_para_fx = AGC_FAC_WB_FX; - move16(); - } - - /* compute input gain */ - L_acc = L_mult0(1, abs_s(sig_in_fx[0]));/*0 +Q_bwe_exc-1 */ - FOR (i = 1; i < SubFrameLength; i++) - { - L_acc = L_mac0(L_acc, 1, abs_s(sig_in_fx[i])); /*Q_bwe_exc-1 */ - } - - g0_fx = 0; - move16(); - IF (L_acc != 0L) - { - scal_in = norm_l(L_acc); - L_acc = L_shl(L_acc, scal_in); - s_g_in = extract_h(L_acc); /* normalized */ - - /* Compute o gain */ - L_acc = L_mult0(1, abs_s(sig_out_fx[0])); - FOR (i = 1; i < SubFrameLength; i++) - { - L_acc = L_mac0(L_acc, 1, abs_s(sig_out_fx[i])); - } - IF (L_acc == 0L) - { - *gain_prec_fx = 0; - move16(); - - return; - } - - scal_out = norm_l(L_acc); - L_acc = L_shl(L_acc, scal_out); - s_g_out = extract_h(L_acc); /* normalized */ - - - sh_g0 = add(scal_in, 1); - sh_g0 = sub(sh_g0, scal_out); /* scal_in - scal_out + 1 */ - IF (sub(s_g_in, s_g_out) < 0) - { - g0_fx = div_s(s_g_in, s_g_out); /* s_g_in/s_g_out in Q15 */ - } - ELSE - { - temp = sub(s_g_in, s_g_out); /* sufficient since normalized */ - g0_fx = shr(div_s(temp, s_g_out), 1); - g0_fx = add(g0_fx, (Word16) 0x4000); /* s_g_in/s_g_out in Q14 */ - sh_g0 = sub(sh_g0, 1); - } - /* L_gain_in/L_gain_out in Q14 */ - /* overflows if L_gain_in > 2 * L_gain_out */ - g0_fx = shr(g0_fx, sh_g0); /* sh_g0 may be >0, <0, or =0 */ - - g0_fx = mult_r(g0_fx, agc_fac1_para_fx); /* L_gain_in/L_gain_out * AGC_FAC1_FX */ - } - /* compute gain(n) = AGC_FAC gain(n-1) + (1-AGC_FAC)gain_in/gain_out */ - /* sig_out(n) = gain(n) sig_out(n) */ - gain_fx = *gain_prec_fx; - move16(); /*14 */ - FOR (i = 0; i < SubFrameLength; i++) - { - temp = mult_r(agc_fac_para_fx, gain_fx);/*15 +14 -15 =14 */ - gain_fx = add(temp, g0_fx); /* in Q14 */ - L_temp = L_mult(gain_fx, sig_out_fx[i]);/*14 + Q_bwe_exc-1 +1 = 14 + Q_bwe_exc */ - L_temp = L_shl(L_temp, 1); /*14 + Q_bwe_exc +1 */ - sig_out_fx[i] = round_fx(L_temp); /*Q_bwe_exc +15 -16 = Q_bwe_exc-1 */ - } - *gain_prec_fx =gain_fx; - move16(); - - return; -} - -void PostShortTerm_fx( - Word16 *sig_in, /* i : input signal (pointer to current subframe */ - Word16 *lpccoeff, /* i : LPC coefficients for current subframe */ - Word16 *sig_out, /* o : postfiltered output */ - Word16 *mem_stp, /* i/o: postfilter memory*/ - Word16 *ptr_mem_stp, /* i/o: pointer to postfilter memory*/ - Word16 *ptr_gain_prec, /* i/o: for gain adjustment*/ - Word16 *mem_zero, /* i/o: null memory to compute h_st*/ - Word16 formant_fac_fx /* i : Strength of post-filter*/ -) -{ - Word16 apond1_fx[LPC_SHB_ORDER+1]; /* denominator coeff.*/ - Word16 apond2_fx[LONG_H_ST]; /* numerator coeff. */ - Word16 sig_ltp_fx[L_SUBFR16k +1]; /* residual signal */ - /*Word16 lpccoeff_fx[LPC_SHB_ORDER+1];//Q12 */ - Word16 g1_fx,g2_fx,parcor0_fx; /*Q15 */ - Word16 tmp; - - parcor0_fx = 0; - move16(); - set16_fx( apond1_fx, 0, LPC_SHB_ORDER+1 ); - set16_fx( apond2_fx, 0, LONG_H_ST ); - set16_fx( sig_ltp_fx, 0, L_SUBFR16k+1 ); - - /* Obtain post-filter weights */ - tmp = extract_h(L_mult(GAMMA_SHARP_FX,formant_fac_fx));/*Q15 */ - g1_fx = add(GAMMA0_FX,tmp);/*Q15 */ - g2_fx = sub(GAMMA0_FX,tmp);/*Q15 */ - - /* Compute weighted LPC coefficients */ - weight_a_fx(lpccoeff, apond1_fx, g1_fx, LPC_SHB_ORDER); - weight_a_fx(lpccoeff, apond2_fx, g2_fx, LPC_SHB_ORDER); - /* o: apond1_fx, apond2_fx in Q12 */ - - /* Compute A(gamma2) residual */ - Residu3_10_fx( apond2_fx, sig_in, sig_ltp_fx+1, L_SUBFR16k, 0 ); - /* o: sig_ltp_fx in Q_bwe_exc */ - - /* Save last output of 1/A(gamma1) */ - sig_ltp_fx[0] = *ptr_mem_stp; - move16(); - - /* Control short term pst filter gain and compute parcor0 */ - Calc_st_filt_tbe(apond2_fx, apond1_fx, &parcor0_fx, sig_ltp_fx+1, mem_zero); - /* o: parcor0 in Q15 */ - /* i/o: sig_ltp_fx in Q_bwe_exc */ - - /* 1/A(gamma1) filtering, mem_stp is updated */ - Syn_filt_s(0,apond1_fx,LPC_SHB_ORDER,sig_ltp_fx+1,sig_ltp_fx+1,L_SUBFR16k,mem_stp,1); - - /* (1 + mu z-1) tilt filtering */ - filt_mu_fx(sig_ltp_fx, sig_out, parcor0_fx, L_SUBFR16k); - /* o: sig_out in Q_bwe_exc */ - - /* gain control */ - scale_st_swb(sig_in, sig_out, ptr_gain_prec, L_SUBFR16k ); - - return; -} - -void flip_spectrum_and_decimby4_fx( - const Word16 input[], /* i : input spectrum Q_inp */ - Word16 output[], /* o : output spectrum Q_inp */ - const Word16 length, /* i : vector length */ - Word16 mem1[], /* i/o : memory Q_inp */ - Word16 mem2[], /* i/o : memory Q_inp */ - const Word16 - ramp_flag /*i: flag to trigger slow ramp-up of output following change of core (HQ to ACELP or 12k8 to 16k ACELP) */ ) -{ - Word16 i; - Word16 factor, tmp[L_FRAME16k/2]; - Word16 tmp1, tmp2; - Word16 input_change[L_FRAME16k]; - - IF ( ramp_flag ) - { - factor = div_s( 4, length ); /* Q15 */ - FOR ( i = 0; i < length / 4; i += 2) - { - tmp1 = extract_l( L_mult0( i, factor ) ); /* Q15 */ - tmp2 = extract_l( L_mult0( add( i, 1 ), factor ) ); /*Q15 */ - input_change[i] = negate( mult_r( input[i], tmp1 ) ); - move16(); - input_change[i + 1] = mult_r( input[i + 1], tmp2 ); - move16(); - } - } - ELSE - { - i = 0; - move16(); - } - - FOR (; i < length; i = i + 2 ) - { - input_change[i] = negate( input[i] ); - move16(); - input_change[i + 1] = input[i + 1]; - move16(); - } - - Decimate_allpass_steep_fx( input_change, mem1, L_FRAME16k, tmp ); - Decimate_allpass_steep_fx( tmp, mem2, L_FRAME16k / 2, output ); - - return; -} - - -/*==========================================================================*/ -/* FUNCTION : void GenShapedWBExcitation_fx () */ -/*--------------------------------------------------------------------------*/ -/* PURPOSE : Synthesize spectrally shaped highband excitation signal for the wideband */ -/*--------------------------------------------------------------------------*/ -/* INPUT ARGUMENTS : */ -/* _Word16 *lpc_shb i : lpc coefficients Q12 */ -/* _Word16 coder_type i : coding type */ -/* _Word16 *bwe_exc_extended i : bandwidth extended exciatation Q_bwe_exc*/ -/* _Word16 Q_bwe_exc i : Q format */ -/* _Word16 voice_factors[] i : voicing factor Q15 */ -/*--------------------------------------------------------------------------*/ -/* OUTPUT ARGUMENTS : */ -/* _Word16 *excSHB o : synthesized shaped shb exctiation Q_bwe_exc*/ -/* _Word16 *exc4kWhtnd o : whitened synthesized shb excitation Q_bwe_exc*/ -/*--------------------------------------------------------------------------*/ -/* INPUT/OUTPUT ARGUMENTS : */ -/* _Word32 *mem_csfilt i/o : memory Q_bwe_exc+16*/ -/* _Word16 *mem_genSHBexc_filt_down1 i/o : memory Q_bwe_exc */ -/* _Word16 *mem_genSHBexc_filt_down2 i/o : memory Q_bwe_exc */ -/* _Word16 *mem_genSHBexc_filt_down3 i/o : memory Q_bwe_exc */ -/* _Word16 *state_lpc_syn i/o : memory Q_bwe_exc */ -/* _Word16 bwe_seed[] i/o : random number generator seed */ -/*--------------------------------------------------------------------------*/ -/* RETURN ARGUMENTS : */ -/* _ None */ -/*--------------------------------------------------------------------------*/ -/* CALLED FROM : */ -/*==========================================================================*/ -void GenShapedWBExcitation_fx( Word16* excSHB, /* o : synthesized shaped shb exctiation Q_bwe_exc*/ - const Word16* lpc_shb, /* i : lpc coefficients Q12*/ - Word16* exc4kWhtnd, /* o : whitened synthesized shb excitation Q_bwe_exc*/ - Word32* mem_csfilt, /* i/o : memory Q_bwe_exc+16*/ - Word16* mem_genSHBexc_filt_down1, /* i/o : memory Q_bwe_exc*/ - Word16* mem_genSHBexc_filt_down2, /* i/o : memory Q_bwe_exc*/ - Word16* mem_genSHBexc_filt_down3, /* i/o : memory Q_bwe_exc*/ - Word16* state_lpc_syn, /* i/o : memory Q_bwe_exc*/ - const Word16 coder_type, /* i : coding type */ - const Word16* bwe_exc_extended, /* i : bandwidth extended exciatation Q_bwe_exc*/ - const Word16 Q_bwe_exc, Word16 bwe_seed[], /* i/o : random number generator seed */ - const Word16 voice_factors[], /* i : voicing factor Q15*/ - const Word16 uv_flag /* i : unvoiced flag */ - , const Word16 igf_flag - ) -{ - Word16 i, j, k; - Word16 wht_fil_mem [ LPC_WHTN_ORDER_WB ]; - Word16 lpc_whtn[ LPC_WHTN_ORDER_WB + 1]; - Word16 R_h[LPC_WHTN_ORDER_WB + 2], R_l[LPC_WHTN_ORDER_WB + 2]; - Word16 Q_R; - Word16 excTmp[ L_FRAME16k]; - Word16 excTmp2[ L_FRAME16k / 4]; - Word16 excTmp2_frac[ L_FRAME16k / 4]; - Word16 exc4k[ L_FRAME16k / 4]; - Word16 exc4k_frac[ L_FRAME16k / 4]; - Word32 exc4k_32[ L_FRAME16k / 4]; - Word32 pow1, pow22; - Word16 scale; - Word32 excNoisyEnv[ L_FRAME16k / 4]; - Word16 csfilt_num2[1] = {1638}; /* Q15*/ - Word16 neg_csfilt_den2[2] = {-32768, 31457}; /* Q15 */ - Word32 L_tmp, Ltemp1, Ltemp2; - Word16 temp1, temp2, exp; - Word32 Lmax; - Word16 max, n1, n2, sc; - Word32 LepsP[LPC_WHTN_ORDER_WB+1]; - Word16 tmp_vfac; - Word16 avg_voice_fac; - - /*0.25f*sum_f(voice_factors, NB_SUBFR)*/ - L_tmp = L_mult(voice_factors[0], 8192); - FOR (i=1; i 0 ) ) /*Q15 -> 0.35f*/ - { - csfilt_num2[0] = 6554; - move16(); /*Q15 -> 0.2f*/ - neg_csfilt_den2[1] = 26214; - move16(); /*Q15 -> 0.8f*/ - } - ELSE IF( igf_flag != 0 && ( sub(coder_type, UNVOICED) == 0 || sub( avg_voice_fac, 6654 ) < 0 ) ) /*Q15 -> 0.2f*/ - { - csfilt_num2[0] = 328; - move16(); /*Q15 -> 0.01f*/ - neg_csfilt_den2[1] = 32440; - move16(); /*Q15 -> 0.99f*/ - } - set16_fx( wht_fil_mem, 0, LPC_WHTN_ORDER_WB ); - Decimate_allpass_steep_fx( bwe_exc_extended, mem_genSHBexc_filt_down1, L_FRAME32k, excTmp ); - flip_spectrum_and_decimby4_fx( excTmp, exc4k, L_FRAME16k, mem_genSHBexc_filt_down2, mem_genSHBexc_filt_down3, 0 ); - - IF ( uv_flag ) - { - create_random_vector_fx( exc4kWhtnd, L_FRAME16k / 4, bwe_seed ); - IF ( sub( Q_bwe_exc, 5 ) < 0 ) - { - - FOR ( i = 0; i < L_FRAME16k / 4; i++ ) - { - exc4kWhtnd[i] = shl_r( exc4kWhtnd[i], sub( Q_bwe_exc, 5 ) );/*Q(Q_bwe_exc)/Q5(if Q_bwe_exc > 5) */ - } - } - } - ELSE - { - autocorr_fx( exc4k, LPC_WHTN_ORDER_WB + 1, R_h, R_l, &Q_R, - L_FRAME16k / 4, win_flatten_4k_fx, 0, 1 ); - - /* Ensure R[0] isn't zero when entering Levinson Durbin */ - R_l[0] = s_max( R_l[0], 1 ); - move16(); - FOR ( i = 1; i <= LPC_WHTN_ORDER_WB; i++ ) - { - L_tmp = Mpy_32( R_h[i], R_l[i], wac_h[i - 1], wac_l[i - 1] ); - L_Extract( L_tmp, &R_h[i], &R_l[i] ); - } - - E_LPC_lev_dur(R_h, R_l, lpc_whtn, LepsP, LPC_WHTN_ORDER_WB, NULL); - - Copy_Scale_sig( lpc_whtn, lpc_whtn, LPC_WHTN_ORDER_WB+1, sub(norm_s(lpc_whtn[0]),2) ); - - fir_fx( exc4k, lpc_whtn, exc4kWhtnd, wht_fil_mem, L_FRAME16k / 4, - LPC_WHTN_ORDER_WB, 0, 3 ); - - /* Ensure pow1 is greater than zero when computing normalization */ - max = 0; - FOR ( i = 0; i < L_FRAME16k / 4; i++ ) - { - excTmp2[i] = abs_s( exc4kWhtnd[i] ); - move16(); /* Q_bwe_exc */ - max = s_max( max, excTmp2[i] ); - move16(); - } - - IF ( max == 0 ) - { - pow1 = 1; - move16(); - n1 = 0; - move16(); - } - ELSE - { - n1 = norm_s( max ); - FOR ( i = 0; i < L_FRAME16k / 4; i++ ) - { - excTmp2_frac[i] = shl( excTmp2[i], n1 ); - move16(); /* Q14 */ - } - n1 = sub( sub( 14, n1 ), Q_bwe_exc ); - pow1 = 1; - FOR ( i = 0; i < L_FRAME16k / 4; i++ ) - { - L_tmp = L_mult( excTmp2_frac[i], excTmp2_frac[i] ); /* Q29 */ - pow1 = L_add( pow1, L_shr( L_tmp, 7 ) ); /* Q22 */ - } - } - - FOR ( i = 0; i < L_FRAME16k / 4; i++ ) - { - excNoisyEnv[i] = L_add( *mem_csfilt, L_mult( csfilt_num2[0], excTmp2[i] ) ); - move32(); /* Q_bwe_exc+16 */ - *mem_csfilt = Mult_32_16( excNoisyEnv[i], neg_csfilt_den2[1] ); - move32(); /* Q_bwe_exc+16 */ - } - - create_random_vector_fx( exc4k, L_FRAME16k / 4, bwe_seed ); - - /* Ensure pow22 is greater than zero when computing normalization */ - Lmax = 0; - FOR ( i = 0; i < L_FRAME16k / 4; i++ ) - { - exc4k_32[i] = Mult_32_16( excNoisyEnv[i], exc4k[i] ); - move32();/* Q_bwe_exc+6 */ - Lmax = L_max( Lmax, L_abs( exc4k_32[i] ) ); - } - - IF ( Lmax == 0 ) - { - pow22 = 1; - move16(); - n2 = 0; - move16(); - set16_fx( exc4k_frac, 0, L_FRAME16k / 4 ); - } - ELSE - { - n2 = norm_l( Lmax ); - FOR ( i = 0; i < L_FRAME16k / 4; i++ ) - { - exc4k_frac[i] = extract_h( L_shl( exc4k_32[i], n2 ) ); /* Q(14-n2) */ - } - n2 = 30 - n2 - ( Q_bwe_exc + 6 ); - pow22 = 1; - FOR ( i = 0; i < L_FRAME16k / 4; i++ ) - { - L_tmp = L_mult( exc4k_frac[i], exc4k_frac[i] ); /* Q29 */ - pow22 = L_add( pow22, L_shr( L_tmp, 7 ) ); /* Q22 */ - } - } - - test(); - test(); - IF( sub(coder_type, UNVOICED) == 0 || ( igf_flag != 0 && sub( avg_voice_fac, 6654 ) < 0 ) ) - { - L_tmp = root_a_over_b_fx( pow1, sub( 22, shl( n1, 1 ) ), pow22, sub( 22, shl( n2, 1 ) ), &exp ); - scale = round_fx( L_shl( L_tmp, exp ) ); /*Q15 */ - - sc = sub( add( n2, Q_bwe_exc ), 14 ); - FOR ( i = 0; i < L_FRAME16k / 4; i++ ) - { - exc4kWhtnd[i] = round_fx( L_shl( L_mult( exc4k_frac[i], scale ), sc ) ); /* Q_bwe_exc+n2-10+16+ Q_bwe_exc + n2 -14 -16 = //Q_bwe_exc */ - } - } - ELSE - { - sc = sub( add( n2, Q_bwe_exc ), 14 ); /* Q_bwe_exc+n2-14*/ - - k = 0; - FOR ( i = 0; i < 4; i++ ) - { - test(); - IF( igf_flag != 0 && sub(coder_type, VOICED) == 0 ) - { - /*tmp_vfac = 2*voice_factors[i]; - tmp_vfac = min(1, tmp_vfac);*/ - BASOP_SATURATE_WARNING_OFF - tmp_vfac = shl(voice_factors[i], 1); - BASOP_SATURATE_WARNING_ON - } - ELSE - { - tmp_vfac = voice_factors[i]; - move16(); - } - - Ltemp1 = root_a_fx( L_deposit_h( tmp_vfac ), 31, &exp ); - temp1 = round_fx( L_shl( Ltemp1, exp ) ); /* Q15 */ - - L_tmp = Mult_32_16( pow1, sub( 32767, tmp_vfac ) ); /* Q22*/ - Ltemp2 = root_a_over_b_fx( L_tmp, sub( 22, shl( n1, 1 ) ), pow22, sub( 22, shl( n2, 1 ) ), &exp ); - temp2 = round_fx( L_shl( Ltemp2, exp ) ); /* Q15 */ - - FOR ( j = 0; j < L_FRAME16k / 16; j++ ) - { - L_tmp = L_mult( temp1, exc4kWhtnd[k] );/* Q(16+Q_bwe_exc) */ - L_tmp = L_add( L_tmp, L_shl( L_mult( temp2, exc4k_frac[k] ), sc ) ); /* Q(16+Q_bwe_exc) */ - exc4kWhtnd[k] = round_fx( L_tmp ); /* Q_bwe_exc */ - k++; - } - } - } - } - - Syn_filt_s( 0, lpc_shb, LPC_SHB_ORDER_WB, exc4kWhtnd, excSHB, L_FRAME16k / 4, state_lpc_syn, 1 ); - - - - return; -} - - -/*-------------------------------------------------------------------* -* GenWBSynth() -* -* Generate 16 KHz sampled highband component from synthesized highband -*-------------------------------------------------------------------*/ - -void GenWBSynth_fx( - const Word16* input_synspeech, /* i : input synthesized speech Qx*/ - Word16* shb_syn_speech_16k, /* o : output highband compnent Qx*/ - Word16* state_lsyn_filt_shb1, /* i/o: memory Qx*/ - Word16* state_lsyn_filt_shb2 /* i/o: memory Qx*/ ) -{ - Word16 speech_buf_16k1[L_FRAME16k], speech_buf_16k2[L_FRAME16k]; - Word16 i, maxm, nor; - Word16 input_synspeech_temp[L_FRAME16k / 4]; - - maxm = 0; - move16(); - FOR(i = 0; i low freq), -ve or neutral Q12 */ -/*--------------------------------------------------------------------------------------*/ -/* INPUT/OUTPUT ARGUMENTS : */ -/* _(Word16*)mem_csfilt :memory */ -/* _(Word16*)mem_genSHBexc_filt_down_shb :memory */ -/* _(Word16*)state_lpc_syn :memory */ -/* _(Word16[]) bwe_seed :random number generator seed */ -/* _(Word16[]) lpf_14k_mem :memory */ -/* _(Word32[])Hilbert_Mem :memory */ -/*--------------------------------------------------------------------------------------*/ -/* RETURN ARGUMENTS : */ -/* _ None */ -/*--------------------------------------------------------------------------------------*/ -/* CALLED FROM : RX */ -/*======================================================================================*/ -void GenShapedSHBExcitation_fx( - Word16 *excSHB, /* o : synthesized shaped shb excitation Q_bwe_exc*/ - const Word16 *lpc_shb, /* i : lpc coefficients Q12*/ - Word16 *White_exc16k_FB, /* o : white excitation for the Fullband extension Q_bwe_exc */ - Word32 *mem_csfilt, /* i/o: memory */ - Word16 *mem_genSHBexc_filt_down_shb, /* i/o: memory */ - Word16 *state_lpc_syn, /* i/o: memory */ - const Word16 coder_type, /* i : coding type */ - const Word16 *bwe_exc_extended, /* i : bandwidth extended excitation */ - Word16 bwe_seed[], /* i/o: random number generator seed */ - Word16 voice_factors[], /* i : voicing factor*/ - const Word16 extl, /* i : extension layer */ - Word16 *tbe_demph, /* i/o: de-emphasis memory */ - Word16 *tbe_premph, /* i/o: pre-emphasis memory */ - Word16 *lpc_shb_sf, /* i: LP coefficients */ - const Word32 shb_ener_sf_32, /* i: input shb ener, Q31 */ - Word16 *shb_res_gshape, /* i: input res gain shape, Q14 */ - Word16 *shb_res, - Word16 *vf_ind, - const Word16 formant_fac, /* i : Formant sharpening factor [0..1] */ - Word16 fb_state_lpc_syn[], /* i/o: memory */ - Word16 *fb_tbe_demph, /* i/o: fb de-emphasis memory */ - Word16 *Q_bwe_exc, - Word16 *Q_bwe_exc_fb, - const Word16 Q_shb, - Word16 n_mem2, /* i : n_mem2 scale factor to adjust 24.4/32kbps memories */ - Word16 prev_Q_bwe_syn, /* i : st_fx->prev_Q_bwe_syn */ - const Word32 bitrate, - const Word16 prev_bfi -) -{ - Word16 i, j, k; - Word16 wht_fil_mem[LPC_WHTN_ORDER]; - Word16 lpc_whtn[LPC_WHTN_ORDER + 1]; - Word16 R_h[LPC_WHTN_ORDER+ 2]; /* Autocorrelations of windowed speech MSB */ - Word16 R_l[LPC_WHTN_ORDER+ 2]; /* Autocorrelations of windowed speech LSB */ - Word16 Q_R; - Word32 LepsP[LPC_WHTN_ORDER+1]; - Word16 exc32k[L_FRAME32k], exc16k[L_FRAME16k]; - Word32 pow1, pow22; - Word16 scale, temp1, temp2; - - Word16 excTmp2[L_FRAME16k]; - Word16 *White_exc16k; - Word16 excNoisyEnv[L_FRAME16k]; - Word16 csfilt_num2[1] = {6554}; /*0.2 in Q15 */ - Word16 neg_csfilt_den2[2] = {-32767, 26214}; /* {1.0f, -0.8f} */ - Word16 varEnvShape; - Word16 fb_deemph_fac = 15729; /*0.48f in Q15 */ - Word16 exc16kWhtnd[L_FRAME16k]; - - Word32 L_tmp; - Word16 vf_tmp; - Word16 tmp, exp, tmp2; - Word16 voiceFacEst[NB_SUBFR16k]; - Word16 zero_mem[LPC_SHB_ORDER]; - Word32 syn_shb_ener_sf[4]; - Word16 tempSHB[80]; - Word16 Q_pow1, Q_pow22; - - Word32 L_tmp2, L_tmp3, L_tmp4; - Word16 temp; - - Word16 White_exc16k_FB_temp[L_FRAME16k]; - Word32 White_exc16k_32[L_FRAME16k]; - Word16 Q_temp; - Word16 prev_Q_bwe_exc_fb; - - set16_fx( zero_mem, 0, LPC_SHB_ORDER ); - set16_fx( wht_fil_mem, 0, LPC_WHTN_ORDER ); - - FOR(i = 0; i < L_FRAME32k; i=i+2) - { - exc32k[i] = negate(bwe_exc_extended[i]); - move16(); - exc32k[i+1] = bwe_exc_extended[i+1]; - move16(); - } - - /* Decimate by 2 */ - Decimate_allpass_steep_fx( exc32k, mem_genSHBexc_filt_down_shb, 2*L_FRAME16k, exc16k ); - /* i: exc32k in Q_bwe_exc */ - /* o: exc16k in Q_bwe_exc */ - - autocorr_fx( exc16k, LPC_WHTN_ORDER + 1, R_h, R_l, &Q_R, L_FRAME16k, win_flatten_fx, 0, 1 ); - /* Ensure R[0] isn't zero when entering Levinson Durbin */ - R_l[0] = s_max( R_l[0], 1 ); - move16(); - FOR ( i = 1; i <= LPC_WHTN_ORDER; i++ ) - { - L_tmp = Mpy_32( R_h[i], R_l[i], wac_h[i - 1], wac_l[i - 1] ); - L_Extract( L_tmp, &R_h[i], &R_l[i] ); - } - E_LPC_lev_dur(R_h, R_l, lpc_whtn, LepsP, LPC_WHTN_ORDER, NULL); - Copy_Scale_sig( lpc_whtn, lpc_whtn, LPC_WHTN_ORDER+1, sub(norm_s(lpc_whtn[0]),2) ); - fir_fx( exc16k, lpc_whtn, exc16kWhtnd, wht_fil_mem, L_FRAME16k, LPC_WHTN_ORDER, 0, 3 ); - - /* i: exc16k in Q_bwe_exc */ - /* o: exc16kWhtnd in Q_bwe_exc */ - - IF( L_sub(bitrate, ACELP_24k40) >= 0) - { - temp2 = 0; - move16(); - FOR(j = 0; j < 4; j++) - { - temp1 = shb_res_gshape[j]; - move16(); - FOR(i = 0; i < 80; i++) - { - exc16kWhtnd[temp2 + i] = round_fx(L_shl(L_mult( exc16kWhtnd[temp2 + i], temp1 ), 1)); - /* exc16kWhtnd in Q_bwe_exc, shb_res_gshape in Q14 */ - } - temp2 = add(temp2, 80); - } - } - - /* Estimate pow1 associated with Low band nonlinear extended excitation */ - /* pow1=0.00001f */ - tmp = sub(shl(*Q_bwe_exc, 1), 31); - pow1 = L_shl(21475l/*0.00001f Q31*/, tmp); /* 0.00001f in 2*(Q_bwe_exc) */ - FOR( k = 0; k < L_FRAME16k; k++) - { - /*excTmp2[k ] = (float)(fabs(exc16kWhtnd[k]));*/ - excTmp2[k] = abs_s( exc16kWhtnd[k] ); - move16(); - - /* pow1 += exc16kWhtnd[k] * exc16kWhtnd[k]; */ - pow1 = L_mac0( pow1, exc16kWhtnd[k], exc16kWhtnd[k] ); /* 2*Q_bwe_exc */ - } - Q_pow1 = shl(*Q_bwe_exc,1); - - test(); - IF( (L_sub( bitrate, ACELP_13k20 ) <= 0) && (L_sub( bitrate, ACELP_7k20 ) >= 0) ) - { - /* varEnvShape = mean_fx(voice_factors, 4); */ - /* unroll the loop */ - L_tmp = L_mult(voice_factors[0], 8192); - L_tmp = L_mac(L_tmp, voice_factors[1], 8192 ); - L_tmp = L_mac(L_tmp, voice_factors[2], 8192 ); - varEnvShape = mac_r(L_tmp, voice_factors[3], 8192 ); /* varEnvShape in Q15 */ - } - ELSE /* 16k core */ - { - /* varEnvShape = mean_fx(voice_factors, 5); */ - /* unroll the loop */ - L_tmp = L_mult(voice_factors[0], 6554); - L_tmp = L_mac(L_tmp, voice_factors[1], 6554 ); - L_tmp = L_mac(L_tmp, voice_factors[2], 6554 ); - L_tmp = L_mac(L_tmp, voice_factors[3], 6554 ); - varEnvShape = mac_r(L_tmp, voice_factors[4], 6554 ); /* varEnvShape in Q15 */ - } - - IF ( sub(extl, FB_TBE) == 0 ) - { - /*pow(varEnvShape,3) */ - tmp = mult_r(varEnvShape, varEnvShape); - tmp = mult_r(tmp, varEnvShape); - - /* max((0.68f - (float)pow(varEnvShape, 3)), 0.48f); */ - fb_deemph_fac = sub(22282/*0.68f Q15*/, tmp); - fb_deemph_fac = s_max(fb_deemph_fac, 15729/*0.48f Q15*/); - } - - /*varEnvShape = 1.09875f - 0.49875f * varEnvShape; */ - varEnvShape = msu_r(1179773824l/*0.549375f Q31*/, 8172/*0.249375f Q15*/, varEnvShape); - - /*varEnvShape = min( max(varEnvShape, 0.6f), 0.999f); */ - varEnvShape = s_max(varEnvShape, 9830/*0.3f Q15*/); - varEnvShape = s_min(varEnvShape, 16368/*0.4995f Q15*/); - varEnvShape = shl(varEnvShape, 1); - csfilt_num2[0] = sub(MAX_16, varEnvShape); - move16(); - neg_csfilt_den2[1] = varEnvShape; - move16(); - - test(); - test(); - test(); - IF ( *mem_csfilt == 0 && ( (L_sub( bitrate, ACELP_9k60 ) == 0) || (L_sub( bitrate, ACELP_16k40 ) == 0) || (L_sub( bitrate, ACELP_24k40 ) == 0) ) ) - { - /* pre-init smoothing filter to avoid energy drop outs */ - L_tmp = L_mult(excTmp2[0], 1638); - FOR (i = 1; i < L_SUBFR16k/4; i++) - { - L_tmp = L_mac(L_tmp, excTmp2[i], 1638); /*1638 = 1/20 in Q15*/ - } - /*L_tmp = sum(excTmp2, L_SUBFR16k/4)*(1/20) where L_SUBFR16k/4 =20 */ - - /* don't apply for FB in case the FB start-frame was potentially lost - White_exc16k is very sensitive to enery mismatch between enc - dec */ - /* rather stick to the more conservative approach, to avoid potential clippings */ - test(); - IF( !(prev_bfi && sub(extl, FB_TBE) == 0) ) - { - /* use weak smoothing for 1st frame after switching to make filter recover more quickly */ - varEnvShape = 26214/*0.8f Q15*/; - move16(); - csfilt_num2[0] = sub(MAX_16, varEnvShape); - move16(); - neg_csfilt_den2[1] = varEnvShape; - move16(); - } - - *mem_csfilt = Mult_32_16( L_tmp, varEnvShape ); - move32(); - } - - /* Track the low band envelope */ - L_tmp = *mem_csfilt; - move32(); - FOR ( i = 0; i < L_FRAME16k; i++ ) - { - excNoisyEnv[i] = mac_r( L_tmp, csfilt_num2[0], excTmp2[i] ); - move16(); - /* excNoisyEnv : Q_bwe_exc, - *mem_csfilt: Q_bwe_exc+16, excTmp2: Q_bwe_exc, csfilt_num2[0] Q15 */ - L_tmp = L_mult( excNoisyEnv[i], neg_csfilt_den2[1] ); /* Q_bwe_exc+16 */ - } - *mem_csfilt = L_tmp; - move32(); - - /* create a random excitation - Reuse exc16k memory */ - White_exc16k = exc16k; - create_random_vector_fx( White_exc16k, 256, bwe_seed ); - create_random_vector_fx( White_exc16k + 256, L_FRAME16k - 256, bwe_seed ); - - L_tmp = L_deposit_l(0); - tmp = add(*Q_bwe_exc, 1); - FOR ( k = 0; k < L_FRAME16k; k++ ) - { - L_tmp4 = L_shl(L_deposit_l(White_exc16k[k]), tmp); - if(excNoisyEnv[k] != 0) - { - L_tmp4 = L_mult(excNoisyEnv[k], White_exc16k[k]);/* (Q_bwe_exc) +5 +1*/ - } - White_exc16k_32[k] = L_tmp4; - move32(); - L_tmp = L_max(L_tmp, L_abs(White_exc16k_32[k])); - } - Q_temp = norm_l( L_tmp ); - if(L_tmp == 0) - { - Q_temp = 31; - } - /*Copy_Scale_sig( White_exc16k, White_exc16k, L_FRAME16k, sub(NOISE_QFAC, 5) );)*/ - /* White_exc16k in Q6 */ - - /* calculate pow22 */ - /* pow22=0.00001f */ - tmp = sub(shl(sub(*Q_bwe_exc, NOISE_QADJ), 1), 31); - pow22 = L_shl(21475l/*0.00001f Q31*/, tmp); /* 0.00001f in 2*(Q_bwe_exc-NOISE_QADJ) */ - tmp = sub(NOISE_QFAC, 5); - FOR ( k = 0; k < L_FRAME16k; k++ ) - { - /* White_exc16k[k] *= excNoisyEnv[k]; */ - White_exc16k[k] = mult_r( excNoisyEnv[k], shl(White_exc16k[k], tmp) ); - move16(); - /* i: excNoisyEnv in (Q_bwe_exc) */ - /* i: White_exc16k in Q6 */ - /* o: White_exc16k in (Q_bwe_exc-NOISE_QADJ) */ - /* pow22 += White_exc16k[k] * White_exc16k[k]; */ - pow22 = L_mac0( pow22, White_exc16k[k], White_exc16k[k] ); /* 2*(Q_bwe_exc-NOISE_QADJ)*/ - } - /*Q_pow22 = sub( shl(*Q_bwe_exc,1), 18 );*/ - Q_pow22 = shl( sub( *Q_bwe_exc, NOISE_QADJ ), 1); - - - IF( L_sub(bitrate, ACELP_24k40) >= 0) - { - IF( sub(*vf_ind,20) == 0) /* encoder side */ - { - Estimate_mix_factors_fx(shb_res, Q_shb, exc16kWhtnd, *Q_bwe_exc, - White_exc16k, (*Q_bwe_exc-NOISE_QADJ), pow1, Q_pow1, - pow22, Q_pow22, voiceFacEst, vf_ind); - tmp = voiceFacEst[0]; - } - ELSE /* decoder side */ - { - /* *vf_ind is an integer scale by 0.125f*/ - tmp = shl( *vf_ind, (15-3) ); - } - tmp2 = MAX_16; - if( sub(tmp, 22938/*0.7f Q15*/) <= 0) - { - tmp2 = 26214/*0.8f Q15*/; - } - voice_factors[0] = mult_r(voice_factors[0], tmp2); - move16(); - voice_factors[1] = mult_r(voice_factors[1], tmp2); - move16(); - voice_factors[2] = mult_r(voice_factors[2], tmp2); - move16(); - voice_factors[3] = mult_r(voice_factors[3], tmp2); - move16(); - voice_factors[4] = mult_r(voice_factors[4], tmp2); - move16(); - } - - { - tmp = sub(Q_temp, 3); - } - FOR ( k = 0; k < L_FRAME16k; k++ ) - { - White_exc16k_FB[k] = round_fx(L_shl(White_exc16k_32[k], tmp)); /* Q_bwe_exc +5 +1 +Q_temp -16 -3 */ - } - prev_Q_bwe_exc_fb = *Q_bwe_exc_fb; - *Q_bwe_exc_fb = sub(add(*Q_bwe_exc, Q_temp), 13); - - deemph_fx( White_exc16k, PREEMPH_FAC, L_FRAME16k, tbe_demph ); - /* i/o: White_exc16k (Q_bwe_exc-NOISE_QADJ) */ - /* i: tbe_demph (Q_bwe_exc-NOISE_QADJ) */ - - IF ( sub(coder_type, UNVOICED) == 0 ) - { - L_tmp = root_a_over_b_fx( pow1, Q_pow1, pow22, Q_pow22, &exp ); - scale = round_fx( L_shl( L_tmp, exp ) ); /*Q15 */ - - FOR ( k = 0; k < L_FRAME16k; k++ ) - { - /* White_exc16k: (Q_bwe_exc-NOISE_QADJ), scale: Q15 */ - L_tmp = L_mult( White_exc16k[k], scale ); - /* L_tmp: (Q_bwe_exc-NOISE_QADJ) + 15 + 1 */ - exc16kWhtnd[k] = round_fx( L_shl(L_tmp, NOISE_QADJ) ); - /* exc16kWhtnd: Q_bwe_exc */ - } - preemph_fx( exc16kWhtnd, PREEMPH_FAC, L_FRAME16k, tbe_premph ); - /* i/o: exc16kWhtnd (Q_bwe_exc) */ - /* i/o: tbe_premph (Q_bwe_exc) */ - } - ELSE - { - Word16 nbSubFr, lSubFr; - Word16 tempQ15; - Word32 tempQ31; - /*nbSubFr = ( bitrate < ACELP_24k40 )? NB_SUBFR : NB_SUBFR16k;*/ - nbSubFr = NB_SUBFR16k; - lSubFr = (L_FRAME16k/NB_SUBFR16k); - IF(L_sub(bitrate, ACELP_24k40) < 0) - { - nbSubFr = NB_SUBFR; - move16(); - lSubFr = (L_FRAME16k/NB_SUBFR); - move16(); - } - k = 0; - FOR( i = 0; i < nbSubFr; i++ ) - { - test(); - IF( sub(coder_type, VOICED) == 0 && ( L_sub(bitrate, ACELP_24k40) < 0 ) ) - { - exp = 0; - tempQ15 = Sqrt16(voice_factors[i], &exp); /* Q15 */ - temp = shl(tempQ15, exp); /* Q15 exc16kWhtnd scale factor */ - exp = 0; - tempQ15 = Sqrt16(temp, &exp); /* Q15 */ - temp1 = shl(tempQ15, exp); /* Q15 exc16kWhtnd scale factor */ - - /*temp2 = root_a_over_b_fx( pow1 * (1.0f - temp), pow22 ); */ - temp = sub(MAX_16, temp); - tempQ31 = Mult_32_16(pow1, temp); - L_tmp = root_a_over_b_fx( tempQ31, Q_pow1, pow22, Q_pow22, &exp ); - temp2 = round_fx(L_shl(L_tmp, exp)); /* Q15 whiteEnvShapedExc scale factor */ - } - ELSE - { - /* Adjust noise mixing for formant sharpening filter */ - tempQ15 = mult_r(SWB_NOISE_MIX_FAC_FX, formant_fac); - /* vf_tmp = voice_factors[i] * (1.0f - vf_tmp); */ - vf_tmp = sub(MAX_16, tempQ15); - vf_tmp = mult_r(voice_factors[i], vf_tmp); - - exp = 0; - tempQ15 = Sqrt16(vf_tmp, &exp); /* Q15 */ - temp1 = shl(tempQ15, exp); /* Q15 exc16kWhtnd scale factor */ - - /*temp2 = root_a_over_b(pow1 * (1.0f - vf_tmp), pow22); */ - temp = sub(MAX_16, vf_tmp); - tempQ31 = Mult_32_16(pow1, temp); - L_tmp = root_a_over_b_fx( tempQ31, Q_pow1, pow22, Q_pow22, &exp ); - temp2 = round_fx(L_shl(L_tmp, exp)); /* Q15 whiteEnvShapedExc scale factor */ - } - - FOR( j = 0; j < lSubFr; j++) - { - /*exc16kWhtnd[k+j] = temp1 * exc16kWhtnd[k+j] + temp2 * White_exc16k[k+j]; */ - L_tmp = L_mult(temp2, White_exc16k[k+j]); /* 16+(Q_bwe_exc-NOISE_QADJ)*/ - L_tmp = L_shl(L_tmp, NOISE_QADJ); /* 16+(Q_bwe_exc) */ - exc16kWhtnd[k+j] = mac_r(L_tmp, temp1, exc16kWhtnd[k+j]); - move16(); - /* Q_bwe_exc */ - } - k = add(k, lSubFr); - - /* estimate the pre-emph factor */ - tempQ15 = sub(MAX_16, voice_factors[i]); - exp = 0; - temp = Sqrt16(tempQ15, &exp); - temp = shl(temp, exp-1); - - temp2 = add( temp, shl(temp1, -1) ); /* shift right by 1 to avoid overflow */ - temp = div_s( temp, temp2 ); /* Q15 */ - temp = mult_r( PREEMPH_FAC, temp ); - - preemph_fx( &exc16kWhtnd[i*lSubFr], temp, lSubFr, tbe_premph ); - /* exc16kWhtnd: Q_bwe_exc; - tbe_premph: Q_bwe_exc*/ - } - } - - - IF ( L_sub(bitrate, ACELP_24k40) < 0 ) - { - Syn_filt_s(0, lpc_shb, LPC_SHB_ORDER, exc16kWhtnd, excSHB, L_FRAME16k, state_lpc_syn, 1 ); - /* i: exc16kWhtnd in Q_bwe_exc */ - /* o: excSHB in Q_bwe_exc */ - } - ELSE - { - set16_fx( zero_mem, 0, LPC_SHB_ORDER); - - Syn_filt_s(0, lpc_shb_sf, LPC_SHB_ORDER, exc16kWhtnd, tempSHB, 80, zero_mem, 1); - syn_shb_ener_sf[0] = L_shr(sum2_fx(tempSHB, 80),3); - move32(); - - Syn_filt_s(0, lpc_shb_sf+(LPC_SHB_ORDER+1), LPC_SHB_ORDER, exc16kWhtnd+ 80, tempSHB, 80, zero_mem, 1 ); - syn_shb_ener_sf[1] = L_shr(sum2_fx(tempSHB, 80),3); - move32(); - - Syn_filt_s(0, lpc_shb_sf+2*(LPC_SHB_ORDER+1), LPC_SHB_ORDER, exc16kWhtnd+160, tempSHB, 80, zero_mem, 1 ); - syn_shb_ener_sf[2] = L_shr(sum2_fx(tempSHB, 80),3); - move32(); - - Syn_filt_s(0, lpc_shb_sf+3*(LPC_SHB_ORDER+1), LPC_SHB_ORDER, exc16kWhtnd+240, tempSHB, 80, zero_mem, 1 ); - syn_shb_ener_sf[3] = L_shr(sum2_fx(tempSHB, 80),3); - move32(); - - /* i: exc16kWhtnd in Q_bwe_exc */ - /* o: tempSHB in Q_bwe_exc */ - /* o: syn_shb_ener_sf in (2*Q_bwe_exc+1) */ - IF(L_sub(bitrate,ACELP_32k) <= 0) - { - L_tmp = sum32_fx(syn_shb_ener_sf, 4); - - /* find root_a(tempSHB[0]) = root_a_over_b(shb_ener_sf[0]), L_tmp) */ - tmp = shl(Q_shb, 1); - tmp2 = add(shl(*Q_bwe_exc, 1), 1); - L_tmp2 = root_a_over_b_fx(shb_ener_sf_32, tmp, L_tmp, tmp2, &exp); /* L_tmp2 in (Q31-exp) */ - - *Q_bwe_exc = sub(*Q_bwe_exc, exp); - move16(); /* compensate for the exp shift */ - tmp2 = add( prev_Q_bwe_syn, n_mem2 ); - IF( sub( *Q_bwe_exc, tmp2) > 0 ) - { - L_tmp2 = L_shl(L_tmp2, sub(tmp2, *Q_bwe_exc)); - *Q_bwe_exc = tmp2; - move16(); - } - FOR(i = 0; i < L_FRAME16k; i++) - { - L_tmp3 = Mult_32_16(L_tmp2, exc16kWhtnd[i]); /* *Q_bwe_exc + (31-exp) - 15 */ - exc16kWhtnd[i] = round_fx(L_tmp3); /* *Q_bwe_exc - exp */ - } - } - /* i: L_tmp2 in (Q31-exp) */ - /* i: exc16kWhtnd in Q_bwe_exc */ - /* o: exc16kWhtnd in Q_bwe_exc: (Q_bwe_exc-exp) */ - - /* Rescale the past memories: LP synth and SHB look ahead buffers */ - tmp = sub(*Q_bwe_exc, prev_Q_bwe_syn); - FOR( i = 0; i < LPC_SHB_ORDER; i++ ) - { - state_lpc_syn[i] = shl( state_lpc_syn[i], tmp ); - move16(); - } - FOR( i = -L_SHB_LAHEAD; i < 0; i++ ) - { - excSHB[i] = shl(excSHB[i], tmp); - move16(); - } - /* Do mem_stp_swb_fx scaling before PostShortTerm_fx */ - - Syn_filt_s(0, lpc_shb_sf, LPC_SHB_ORDER, exc16kWhtnd, excSHB, 80, state_lpc_syn, 1 ); - Syn_filt_s(0, lpc_shb_sf+(LPC_SHB_ORDER+1), LPC_SHB_ORDER, exc16kWhtnd+ 80, excSHB+ 80, 80, state_lpc_syn, 1 ); - Syn_filt_s(0, lpc_shb_sf+2*(LPC_SHB_ORDER+1), LPC_SHB_ORDER, exc16kWhtnd+160, excSHB+160, 80, state_lpc_syn, 1 ); - Syn_filt_s(0, lpc_shb_sf+3*(LPC_SHB_ORDER+1), LPC_SHB_ORDER, exc16kWhtnd+240, excSHB+240, 80, state_lpc_syn, 1 ); - /* i: exc16kWhtnd in (Q_bwe_exc) */ - /* o: excSHB in (Q_bwe_exc) */ - } - - IF ( sub(extl, FB_TBE) == 0) - { - tmp = sub( add(*Q_bwe_exc_fb, 20), prev_Q_bwe_exc_fb ); - Scale_sig( fb_state_lpc_syn, LPC_SHB_ORDER, tmp ); - Scale_sig( fb_tbe_demph, 1, tmp ); - Syn_filt_s(0, lpc_shb, LPC_SHB_ORDER, White_exc16k_FB, White_exc16k_FB_temp, L_FRAME16k, fb_state_lpc_syn, 1 ); - /* i: White_exc16k_FB in (14-n2) */ - /* o: White_exc16k_FB_temp in (14-n2) */ - - FOR( i=0; i<10; i++ ) - { - FOR( j=0; j<32; ++j ) - { - White_exc16k_FB_temp[i*32+j] = mult_r(White_exc16k_FB_temp[i*32+j], cos_fb_exc_fx[j]); - move16(); - } - } - - *Q_bwe_exc_fb = add(*Q_bwe_exc_fb, 20); - move16(); /**Q_bwe_exc_fb +35 +1 -16*/ - flip_spectrum_fx( White_exc16k_FB_temp, White_exc16k_FB, L_FRAME16k ); - - deemph_fx( White_exc16k_FB, fb_deemph_fac, L_FRAME16k, fb_tbe_demph ); - - } - ELSE - { - set16_fx( White_exc16k_FB, 0, L_FRAME16k); - } - - return; -} - - -/*====================================================================================*/ -/* FUNCTION : void GenSHBSynth_fx() */ -/*------------------------------------------------------------------------------------*/ -/* PURPOSE :Generate 32 KHz sampled highband component from synthesized highband*/ -/*------------------------------------------------------------------------------------*/ -/* INPUT ARGUMENTS */ -/* _(Word16*)input_synspeech :input synthesized speech */ -/* _(Word16) L_frame :ACELP frame length */ -/*------------------------------------------------------------------------------------*/ -/* OUTPUT ARGUMENTS : */ -/* _(Word16*)shb_syn_speech_32k : output highband component */ -/*------------------------------------------------------------------------------------*/ -/* INPUT/OUTPUT ARGUMENTS : */ -/* _(Word16[]) allpass_mem : memory */ -/* _(Word32[]) Hilbert_Mem : memory */ -/*------------------------------------------------------------------------------------*/ -/* RETURN ARGUMENTS : */ -/* _ None */ -/*------------------------------------------------------------------------------------*/ - -void GenSHBSynth_fx( - const Word16* input_synspeech, /* i : input synthesized speech */ - Word16* shb_syn_speech_32k, /* o : output highband component */ - Word32 Hilbert_Mem[], /* i/o: memory */ - Word16 allpass_mem[], /* i/o: memory */ - const Word16 L_frame, /* i : ACELP frame length */ - Word16* syn_dm_phase -) -{ - Word16 i, speech_buf_32k[L_FRAME32k]; - Word16 maxm, nor, nor32, shift; - Word16 input_synspeech_temp[L_FRAME16k]; - Word32 maxm32; - - - maxm = 0; - move16(); - maxm32 = L_deposit_l(0); - FOR(i = 0; i (Q_bwe_exc + Q_gFr_norm - 13) */ - - /* check for headroom of previous buff memories: overlap, Hilbert, and interp all-pass mem */ - tmpQ15 = add( prev_Q_bwe_syn2, n_mem3 ); - if( sub( *Q_bwe_exc, tmpQ15) > 0 ) - { - *Q_bwe_exc = tmpQ15; - move16(); - } - - *Qx = *Q_bwe_exc; - - /* rescale the overlap memory */ - FOR( i = 0; i < L_SHB_LAHEAD; i++ ) - { - temp2 = 1; - if( overlap[i] < 0 ) - { - temp2 = -1; - } - temp1 = abs_s(overlap[i]); - temp1 = shl( temp1, (*Q_bwe_exc - prev_Q_bwe_syn2) ); - move16(); /* Q_bwe_exc + Q_gFr_norm - 13 */ - overlap[i] = i_mult(temp1, temp2); - } - - FOR ( i = 0; i < l_shb_lahead; i++ ) - { - L_tmp = Mult_32_16(mod_syn[i], gain_frame_Q16); /* Q_bwe_exc + 16 + Q_gFr_norm + 2 - 15 */ - L_tmp2 = Mult_32_16(L_tmp, win[i]); /* (Q_bwe_exc + 16 + Q_gFr_norm + 2 - 15) + 15 + (1-16) */ - synSHB[i] = mac_r(L_tmp2, overlap[i], MAX_16); - move16(); /* Q_bwe_exc + Q_gFr_norm - 13 */ - synSHB[i+l_shb_lahead] = round_fx(L_tmp); /* Q_bwe_exc + Q_gFr_norm - 13 */ - } - - FOR ( ; i < l_frame; i++ ) - { - L_tmp = Mult_32_16( mod_syn[i], gain_frame_Q16); /* Q_bwe_exc + 16 + Q_gFr_norm + 2 - 15 */ - synSHB[i] = round_fx( L_tmp ); /* Q_bwe_exc + Q_gFr_norm - 13 */ - } - - l_frame_tmp = add(l_frame, l_shb_lahead); - FOR ( ; i < l_frame_tmp; i++ ) - { - L_tmp = Mult_32_16( mod_syn[i], gain_frame_Q16); /* Q_bwe_exc + 16 + Q_gFr_norm + 2 - 15 */ - L_tmp = Mult_32_16(L_tmp, win[l_frame + l_shb_lahead - 1 - i]); /* (Q_bwe_exc + 16 + Q_gFr_norm + 2 - 15) + 15 + (1-16) */ - overlap[i - l_frame] = round_fx( L_tmp ); /* Q_bwe_exc + Q_gFr_norm - 13 */ - } - - return; -} - - -void ScaleShapedWB_fx( - const Word16 length, /* i : SHB overlap length */ - Word16* synSHB, /* i/o : synthesized shb signal Q_bwe_exc/Qx */ - Word16* overlap, /* i/o : buffer for overlap-add Q_bwe_exc/Qx */ - const Word16* subgain, /* i : subframe gain Q15*/ - const Word32 frame_gain, /* i : frame gain Q18 */ - const Word16* win, /* i : window Q15*/ - const Word16* subwin, /* i : subframes window Q15*/ - const Word16 Q_bwe_exc - ,Word16 L_frame /* i : Frame length - determines whether 12.8 or 16kHz core in-use */ - ,Word16 dynQ /* i : indicate whether output is dynamic Q, or Q0 */ - ,Word16* Qx /* o : newly computed Q factor for synSHB */ - ,Word16 prev_Qx /* i : prev_Qx for memory scaling */ - ,Word32* Hilbert_Mem /* i : Hilbert memory used for computing Qx */ -) -{ - const Word16* skip; - Word16 i, j, k, l_shb_lahead, l_frame, l_frame_tmp; - Word16 join_length, num_join; - Word32 mod_syn[L_FRAME16k+L_SHB_LAHEAD]; - Word16 sum_gain; - Word32 L_tmp; - Word16 max, abs_sig, sc1, sc2, shift, max_headroom, min_shift, max_shift, max_shift2; - /* Init */ - set32_fx( mod_syn, 0, L_FRAME16k+L_SHB_LAHEAD ); - - /* apply gain for each subframe, and store noise output signal using overlap-add */ - IF ( sub(length,SHB_OVERLAP_LEN / 2 ) == 0) - { - /* WB Gain shape and gain frame application with overlap */ - skip = skip_bands_WB_TBE; - move16(); - l_frame = L_FRAME16k / 4; - move16(); - l_shb_lahead = L_SHB_LAHEAD / 4; - move16(); - - sum_gain = 0; - move16(); - FOR ( k = 0; k < length / 2; k++ ) - { - sum_gain = mult_r( subwin[2 * k + 2], subgain[0] ); /* Q15 */ - mod_syn[skip[0] + k] = L_mult( sum_gain, synSHB[skip[0] + k] ); - move32();/* Q_bwe_exc + 16 */ - mod_syn[skip[0] + k + length / 2] = L_mult( subgain[0], synSHB[skip[0] + k + length / 2] ); - move32();/* Q_bwe_exc + 16 */ - } - FOR ( i = 1; i < NUM_SHB_SUBFR / 2; i++ ) - { - FOR ( k = 0; k < length; k++ ) - { - L_tmp = L_mult0( subwin[k + 1], subgain[i] ); /* Q30 */ - sum_gain = round_fx( L_mac0( L_tmp, subwin[length - k - 1], subgain[i - 1] ) ); /* Q14 */ - mod_syn[skip[i] + k] = L_shl( L_mult( sum_gain, synSHB[skip[i] + k] ), 1 ); - move32(); /* Q_bwe_exc + 16 */ - } - } - FOR ( k = 0; k < length / 2; k++ ) - { - sum_gain = mult_r( subwin[length - 2 * k - 2], subgain[i - 1] ); /* Q15 */ - mod_syn[skip[i] + k] = L_mult( sum_gain, synSHB[skip[i] + k] ); - move32();/* Q_bwe_exc + 16 */ - } - } - ELSE - { - /* SWB Gain shape and gain frame application with overlap */ - l_frame = L_FRAME16k; - move16(); - l_shb_lahead = L_SHB_LAHEAD; - move16(); - skip = skip_bands_SWB_TBE; - move16(); - - num_join = NUM_SHB_SUBFR / NUM_SHB_SUBGAINS; - move16(); - join_length = i_mult2( num_join, length ); - j = 0; /* ptr*/ - FOR ( k = 0; k < length; k++ ) - { - sum_gain = mult_r( subwin[k + 1], subgain[0] ); /* Q15 */ - mod_syn[j] = L_mult( synSHB[j], sum_gain ); - move32(); /* Q_bwe_exc + 16 */ - j++; - } - - FOR ( i = 0; i < NUM_SHB_SUBGAINS - 1; i++ ) - { - FOR ( k = 0; k < join_length - length; k++ ) - { - mod_syn[j] = L_mult( synSHB[j], subgain[i * num_join] ); - move32(); /* Q_bwe_exc + 16 */ - j++; - } - - FOR ( k = 0; k < length; k++ ) - { - L_tmp = L_mult0( subwin[k + 1], subgain[i_mult2(( i + 1 ), num_join)] ); /* Q30 */ - sum_gain = round_fx( L_mac0( L_tmp, subwin[length - k - 1], subgain[i_mult2(i, num_join)] ) );/*Q14 */ - mod_syn[j] = L_shl( L_mult( sum_gain, synSHB[j] ), 1 ); - move32(); /* Q_bwe_exc + 16 */ - j++; - } - } - FOR ( k = 0; k < join_length - length; k++ ) - { - mod_syn[j] = L_mult( synSHB[j], subgain[( NUM_SHB_SUBGAINS - 1 ) * num_join] ); - move32(); /* Q_bwe_exc + 16 */ - j++; - } - FOR ( k = 0; k < length; k++ ) - { - sum_gain = mult_r( subwin[length - k - 1], subgain[( NUM_SHB_SUBGAINS - 1 ) *num_join] ); /* Q15 */ - mod_syn[j] = L_mult( synSHB[j], sum_gain ); - move32(); /* Q_bwe_exc + 16 */ - j++; - } - } - - - - max = 0; - move16(); - FOR( i = 0; i < l_frame + l_shb_lahead; i++ ) - { - abs_sig = abs_s( round_fx(mod_syn[i]) ); - if(sub(abs_sig,max)>0) - { - max = abs_sig; - move16(); - } - } - - FOR( i = 0; i < HILBERT_MEM_SIZE; i++ ) - { - abs_sig = abs_s( round_fx(Hilbert_Mem[i]) ); - if(sub(abs_sig,max)>0) - { - max = abs_sig; - move16(); - } - } - - sc1 = norm_s( max ); /* max headroom in mod_syn[] */ - sc2 = norm_s( round_fx(frame_gain));/* headroom in GainFrame */ - - IF(dynQ == 0 ) - { - shift = sub(13, Q_bwe_exc); /* earlier = (10 - Q_bwe_exc) but we changed GainFrame Q21 to Q18 */ - *Qx = 0; - } - ELSE IF (sub(L_frame,L_FRAME) == 0) /* 12.8k core */ - { - max_headroom = sub(add(sc1,sc2),4); /* Max headroom after multiplying = sc1 + sc2 -3 (keep 3 bit extra headroom) */ - /* 12.8k core needs extra headroom than 16k core */ - /* otherwise Hilbert transform inside flip_and_downmix have saturation, causes ringing in output */ - - /* Qx = (Q_bwe_exc+3) + shift - 16 */ - /* make sure 14 > Qx > 2 */ - min_shift = 2-(Q_bwe_exc+3-16); - max_shift = 13-(Q_bwe_exc+3-16); - max_shift2 = s_min(max_shift,max_headroom); /* avoid shifting more than the available max headroom to avoid overflow */ - - shift = s_min(min_shift,max_shift2); - *Qx = (Q_bwe_exc+3) + shift - 16; - } - ELSE /* 16k core */ - { - max_headroom = sub(add(sc1,sc2),1); /* Max headroom after multiplying = sc1 + sc2 -1 (keep 1 bit extra headroom) */ - - /* Qx = (Q_bwe_exc+3) + shift - 16 */ - /* make sure 14 > Qx > 3 */ - min_shift = 3-(Q_bwe_exc+3-16); - max_shift = 13-(Q_bwe_exc+3-16); - max_shift2 = s_min(max_shift,max_headroom); /* avoid shifting more than the available max headroom to avoid overflow */ - - shift = s_min(min_shift,max_shift2); - *Qx = (Q_bwe_exc+3) + shift - 16; - } - - /* bring memory st_fx->syn_overlap_fx[] = overlap[i] to new Q = Qx to prepare for addition */ - FOR ( i = 0; i < l_shb_lahead; i++ ) - { - overlap[i] = shl(overlap[i], (*Qx - prev_Qx)); - } - - FOR ( i = 0; i < l_shb_lahead; i++ ) - { - /* mod_syn in (16+Q_bwe_exc), frame_gain in Q18 */ - L_tmp = Mult_32_32( mod_syn[i], frame_gain ); /* L_tmp in (Q_bwe_exc+3) */ - synSHB[i] = round_fx( L_shl( Mult_32_16( L_tmp, win[i] ), shift) ); /* Qx */ - synSHB[i] = add( synSHB[i], overlap[i] ); - move16(); /* Qx */ - synSHB[i + l_shb_lahead] = round_fx( L_shl( L_tmp, shift) ); /* Qx */ - } - - FOR ( ; i < l_frame; i++ ) - { - L_tmp = Mult_32_32( mod_syn[i], frame_gain); /* L_tmp in (Q_bwe_exc+3) */ - synSHB[i] = round_fx( L_shl(L_tmp, shift) ); /* Qx; */ - } - - l_frame_tmp = add(l_frame, l_shb_lahead); - FOR ( ; i < l_frame_tmp; i++ ) - { - L_tmp = Mult_32_32( mod_syn[i], frame_gain ); /* (Q_bwe_exc+3) */ - overlap[i - l_frame] = round_fx( L_shl( Mult_32_16( L_tmp, win[l_frame + l_shb_lahead - 1 - i] ), shift ) ); /* Qx */ - } - - return; -} - -static Word32 non_linearity_scaled_copy( - const Word16 input[], - Word16 j, - Word16 length, - Word32 output[], - Word32 prev_scale, - Word16 scale_step, - Word16 en_abs -) -{ - Word16 i; - Word32 L_tmp; - - IF (en_abs) - { - FOR ( i = 0; i < j; i++ ) - { - L_tmp = L_mult( input[i], input[i] ); /* 2*Q_inp+1 */ - L_tmp = Mult_32_32( L_tmp, prev_scale ); /* 2*Q_inp */ - output[i] = L_tmp; - move32(); - - L_tmp = Mult_32_16( prev_scale, scale_step ); /* Q29 */ - prev_scale = L_shl( L_tmp, 1 ); /* Q30 */ - } - FOR ( ; i < length; i++ ) - { - L_tmp = L_mult( input[i], input[i] ); /* 2*Q_inp+1 */ - L_tmp = Mult_32_32( L_tmp, prev_scale ); /* 2*Q_inp */ - output[i] = L_tmp; - move32(); - } - } - ELSE - { - FOR ( i = 0; i < j; i++ ) - { - L_tmp = L_mult( input[i], input[i] ); /* 2*Q_inp+1 */ - L_tmp = Mult_32_32( L_tmp, prev_scale ); /* 2*Q_inp */ - - if ( input[i] < 0 ) - { - L_tmp = L_negate(L_tmp); - } - output[i] = L_tmp; - move32(); - - L_tmp = Mult_32_16( prev_scale, scale_step ); /* Q29 */ - prev_scale = L_shl( L_tmp, 1 ); /* Q30 */ - } - - FOR ( ; i < length; i++ ) - { - L_tmp = L_mult( input[i], input[i] ); /* 2*Q_inp+1 */ - L_tmp = Mult_32_32( L_tmp, prev_scale ); /* 2*Q_inp */ - - if ( input[i] < 0 ) - { - L_tmp = L_negate(L_tmp); - } - output[i] = L_tmp; - move32(); - } - } - return prev_scale; -} - -/*==========================================================================*/ -/* FUNCTION : void non_linearity() */ -/*--------------------------------------------------------------------------*/ -/* PURPOSE : Apply a non linearity to the SHB excitation */ -/*--------------------------------------------------------------------------*/ -/* INPUT ARGUMENTS : */ -/* Word16 input[] i : input signal Q_inp */ -/* Word16 length i : input length */ -/*--------------------------------------------------------------------------*/ -/* OUTPUT ARGUMENTS : */ -/* Word32 output[] o : output signal 2*Q_inp */ -/*--------------------------------------------------------------------------*/ -/* INPUT/OUTPUT ARGUMENTS : */ -/* Word32 *prev_scale i/o: memory Q30 */ -/*--------------------------------------------------------------------------*/ -/* RETURN ARGUMENTS : */ -/* _ None */ -/*--------------------------------------------------------------------------*/ -/* CALLED FROM : */ -/*==========================================================================*/ - -void non_linearity_fx( - const Word16 input[], /* i : input signal Q_inp */ - Word32 output[], /* o : output signal 2*Q_inp */ - const Word16 length, /* i : input length */ - Word32* pPrevScale, /* i/o: memory Q30 */ - Word16 Q_inp - ,Word16 coder_type, /* i : Coder Type */ - Word16 *voice_factors, /* i : Voice Factors */ - const Word16 L_frame /* i : ACELP frame length */ - -) -{ - Word16 i, j; - Word16 max=0; - Word32 scale; - Word16 scale_step; - Word16 exp, tmp; - Word16 e_tmp, f_tmp; - Word16 frac; - Word32 L_tmp; - Word32 L_tmp1; - - Word16 en_abs = 0; - Word16 v_fac = 0; - Word16 ths; - Word16 nframes; - Word32 prev_scale; - Word16 length_half; - - - IF ( sub(L_frame, L_FRAME16k ) == 0 ) - { - nframes = 5; - move16(); - ths = 17817; - move16(); /* 0.87*5 in Q12 */ - } - ELSE - { - nframes = 4; - move16(); - ths = 15400; - move16(); /* 0.94*4 in Q12 */ - } - - - FOR ( i = 0; i < nframes; i++ ) - { - v_fac = add( v_fac, shr( voice_factors[i], 3 ) ); /* Q12 */ - } - - test(); - if ( sub( coder_type, VOICED )==0 && sub( v_fac, ths ) > 0 ) - { - en_abs = 1; - move16(); - } - - length_half = shr(length, 1); - prev_scale = *pPrevScale; - move32(); - - - - /* Delay Alignment in FX is done inside swb_tbe_enc_fx() */ - - FOR ( i = j = 0; i < length_half; i++ ) - { - tmp = abs_s(input[i]); - if(sub(tmp,max)>0) - { - j = i; - move16(); - } - max = s_max(max, tmp); - - } - - - IF ( sub(max, shl(1,Q_inp)) > 0 ) - { - exp = norm_s( max ); - tmp = div_s( shl(1, sub( 14, exp)), max ); /* Q(29-exp-Q_inp) */ - scale = L_shl( L_mult( 21955, tmp ), add(exp, sub(Q_inp,14)) ); /* Q31 */ - } - ELSE - { - scale = 1438814044; - move32(); /* Q31; 0.67 in Q31 */ - } - - test(); - IF ( prev_scale <= 0 || L_sub( Mult_32_16( prev_scale, 32 ), scale ) > 0 ) - { - scale_step = 16384; - move16(); /* Q14 */ - prev_scale = L_shr( scale, 1 ); /* Q30 */ - } - ELSE - { - - /* Computing log2(scale) */ - IF ( j == 0 ) - { - scale_step = 32767; - move16(); - } - ELSE - { - e_tmp = norm_l( scale ); - f_tmp = Log2_norm_lc( L_shl( scale, e_tmp ) ); - e_tmp = sub(-1, e_tmp); - L_tmp = Mpy_32_16( e_tmp, f_tmp, 32767 ); /* Q16 */ - - /* Computing log2(prev_scale) */ - e_tmp = norm_l( prev_scale ); - f_tmp = Log2_norm_lc( L_shl( prev_scale, e_tmp ) ); - e_tmp = negate(e_tmp); - L_tmp1 = Mpy_32_16( e_tmp, f_tmp, 32767 ); /* Q16 */ - - /* log2(scale / prev_scale) = log2(scale) - log2(prev_scale) */ - L_tmp = L_sub( L_tmp, L_tmp1 ); /* Q16 */ - - /* Computing 1/j */ - exp = norm_s( j ); - tmp = div_s( shl(1, sub( 14, exp)), j ); /* Q(29-exp) */ - - /* (log2(scale / prev_scale))/length */ - L_tmp = L_shl( Mult_32_16( L_tmp, tmp ), sub(exp, 14) ); /* Q(16+29-exp+1-16+exp-14)->Q16 */ - - frac = L_Extract_lc( L_tmp, &exp ); /* Extract exponent of L_tmp */ - - tmp = extract_l( Pow2( 14, frac ) ); - scale_step = shl( tmp, exp ); /* Q14 */ - } - } - - prev_scale = non_linearity_scaled_copy( input, j, length_half, output, prev_scale, scale_step, en_abs ); - - max = 0; - move16(); - j = shr(length, 1); - FOR ( i = length_half; i < length; i++ ) - { - tmp = abs_s(input[i]); - if(sub(tmp,max)>0) - { - j = i; - move16(); - } - max = s_max(max, tmp); - } - - IF ( sub( max, shl( 1, Q_inp ) ) > 0 ) - { - exp = norm_s( max ); - tmp = div_s( shl(1, sub( 14, exp)), max ); /* Q(29-exp-Q_inp) */ - scale = L_shl( L_mult( 21955, tmp ), add(exp, sub(Q_inp, 14)) ); /* Q31 */ - } - ELSE - { - scale = 1438814044; - move32(); /* Q31; 0.67 in Q31 */ - } - - test(); - IF ( prev_scale <= 0 || L_sub( Mult_32_16( prev_scale, 32 ), scale ) > 0 ) - { - scale_step = 16384; - move16(); /*Q14 */ - prev_scale = L_shr( scale, 1 ); /*Q30 */ - } - ELSE - { - /*scale_step = (float) exp(1.0f / (float) (j - length/2) * (float) log(scale / prev_scale)); */ - /* Computing log2(scale) */ - IF ( sub(j,length_half) == 0 ) - { - scale_step = 32767; - move16();/*Q14 */ - } - ELSE - { - e_tmp = norm_l( scale ); - f_tmp = Log2_norm_lc( L_shl( scale, e_tmp ) ); - e_tmp = sub(-e_tmp, 1); - L_tmp = Mpy_32_16( e_tmp, f_tmp, 32767 ); /* Q16 */ - - /* Computing log2(prev_scale) */ - e_tmp = norm_l( prev_scale ); - f_tmp = Log2_norm_lc( L_shl( prev_scale, e_tmp ) ); - e_tmp = negate(e_tmp); - L_tmp1 = Mpy_32_16( e_tmp, f_tmp, 32767 ); /* Q16 */ - - /* log2(scale / prev_scale) = log2(scale) - log2(prev_scale) */ - L_tmp = L_sub( L_tmp, L_tmp1 ); /* Q16 */ - - /* Computing 1/(j - length/2) */ - - tmp = sub( j, length_half ); - exp = norm_s( tmp ); - - - tmp = div_s( shl(1, sub( 14, exp)), tmp ); /* Q(29-exp) */ - - /* (log2(scale / prev_scale))/length */ - L_tmp = L_shl( Mult_32_16( L_tmp, tmp ), sub(exp,14) ); /*Q(16+29-exp+1-16+exp-14)->Q16 */ - - frac = L_Extract_lc( L_tmp, &exp ); /* Extract exponent of L_tmp */ - - tmp = extract_l( Pow2( 14, frac ) ); - scale_step = shl( tmp, exp ); /*Q14 */ - } - } - - prev_scale = non_linearity_scaled_copy( input+length_half, sub(j, length_half), sub(length, length_half), output+length_half, prev_scale, scale_step, en_abs ); - - *pPrevScale = prev_scale; - move32(); - - /* Delay Alignment in FX is done inside swb_tbe_enc_fx() */ - - return; -} - - - - -/*-------------------------------------------------------------------* -* create_random_vector() -* -* creates random number vector -* Note: the abs(max) value coming out of create_random_vector should -* fit into the precision of Q6. -* -------------------------------------------------------------------*/ - -void create_random_vector_fx( - Word16 output[], /* o : output random vector Q5*/ - const Word16 length, /* i : length of random vector */ - Word16 seed[] /* i/o: start seed */ -) -{ - Word16 i, j, k; - Word16 scale1, scale2; - Word32 L_tmp; - - L_tmp = L_abs( Mult_32_16( 2144047674, Random( &seed[0] ) ) );/*Q23 */ - j = extract_l( L_shr( L_tmp, 23 ) ); - j = s_and( j, 0xff ); - - L_tmp = L_abs( Mult_32_16( 2144047674, Random( &seed[1] ) ) );/*Q23 */ - k = extract_l( L_shr( L_tmp, 23 ) ); - k = s_and( k, 0xff ); - - WHILE ( sub(k,j) == 0 ) - { - L_tmp = L_abs( Mult_32_16( 2144047674, Random( &seed[1] ) ) );/*Q23 */ - k = extract_l( L_shr( L_tmp, 23 ) ); - k = s_and( k, 0xff ); - } - - scale1 = 18021; - move16(); /* 200.00f * 0.35f/0.1243f; */ - if ( Random( &seed[0] ) < 0 ) - { - scale1 = -18021; - move16(); /*Q5 */ /* -200.00f * 0.35f/0.1243f; */ - } - - scale2 = 7208; - move16(); /* 80.00f * 0.35f/0.1243f; */ - if ( Random( &seed[1] ) < 0 ) - { - scale2 = -7208; - move16(); /*Q5 */ /* -80.00f * 0.35f/0.1243f; */ - } - - FOR ( i = 0; i < length; i++ ) - { - j = s_and( j, 0xff ); - k = s_and( k, 0xff ); - output[i] = round_fx( L_add( L_mult( scale1, gaus_dico_swb_fx[j] ), L_mult( scale2, gaus_dico_swb_fx[k] ) ) ); /*Q5 */ - j++; - k++; - } - - return; -} - - -/*======================================================================================*/ -/* FUNCTION : interp_code_5over2_fx() */ -/*--------------------------------------------------------------------------------------*/ -/* PURPOSE : Used to interpolate the excitation from the core sample rate */ -/* of 12.8 kHz to 32 kHz. */ -/* Simple linear interpolator - No need FOR precision here. */ -/*--------------------------------------------------------------------------------------*/ -/* INPUT ARGUMENTS : */ -/* _ (Word16[]) inp_code_fx : input vector (Q12) */ -/* _ (Word16) inp_length : length of input vector */ -/*--------------------------------------------------------------------------------------*/ -/* OUTPUT ARGUMENTS : */ -/* _ (Word16[]) interp_code_fx : output vector (Q12) */ -/*--------------------------------------------------------------------------------------*/ -/* INPUT/OUTPUT ARGUMENTS : */ -/* _ None */ -/*--------------------------------------------------------------------------------------*/ - -/* _ None */ -/*--------------------------------------------------------------------------------------*/ -/* RETURN ARGUMENTS : */ -/* _ None */ -/*======================================================================================*/ - -void interp_code_5over2_fx( - const Word16 inp_code_fx[], /* i : input vector Qx*/ - Word16 interp_code_fx[], /* o : output vector Qx*/ - const Word16 inp_length /* i : length of input vector */ -) -{ - Word16 i, kk, kkp1, i_len2; - Word32 Ltemp; - Word16 factor_i_fx[5] = {6554, 19661, 32767, 19661, 6554}; - Word16 factor_j_fx[5] = {26214, 13107, 0, 13107, 26214}; - - interp_code_fx[0] = inp_code_fx[0]; - move16();/* Qx */ - - Ltemp = L_mult( inp_code_fx[0], factor_i_fx[3] );/* Q(16+x) */ - Ltemp = L_mac( Ltemp, inp_code_fx[1], factor_j_fx[3] );/* Q(16+x) */ - interp_code_fx[1] = round_fx( Ltemp );/*Qx */ - - Ltemp = L_mult( inp_code_fx[0], factor_i_fx[4] );/*Q(16+x) */ - Ltemp = L_mac( Ltemp, inp_code_fx[1], factor_j_fx[4] );/*Q(16+x) */ - interp_code_fx[2] = round_fx( Ltemp ); /* Qx */ - - kk = 1; - move16(); - kkp1 = 2; - move16(); - i = 3; - move16(); - /*i_len2 = ( inp_length - 2 ) * HIBND_ACB_L_FAC; */ /*HIBND_ACB_L_FAC == 5/2 */ - i_len2 = sub(inp_length, 2); - i_len2 = shr(add(shl(i_len2, 2),i_len2),1); /* rounding below during shr makes it non BE*/ - - FOR ( ; i < i_len2; i += 5 ) - { - Ltemp = L_mult( inp_code_fx[kk], factor_j_fx[0] );/*Q(16+x) */ - Ltemp = L_mac( Ltemp, inp_code_fx[kkp1], factor_i_fx[0] );/*Q(16+x) */ - interp_code_fx[i] = round_fx( Ltemp );/*Qx */ - - Ltemp = L_mult( inp_code_fx[kk], factor_j_fx[1] );/*Q(16+x) */ - Ltemp = L_mac( Ltemp, inp_code_fx[kkp1], factor_i_fx[1] );/*Q(16+x) */ - interp_code_fx[i + 1] = round_fx( Ltemp );/*Qx */ - - Ltemp = L_mult( inp_code_fx[kkp1], factor_i_fx[2] );/*Q(16+x) */ - interp_code_fx[i + 2] = round_fx( Ltemp );/*Qx */ - - kk++; - kkp1++; - - Ltemp = L_mult( inp_code_fx[kk], factor_i_fx[3] );/*Q(16+x) */ - Ltemp = L_mac( Ltemp, inp_code_fx[kkp1], factor_j_fx[3] );/*Q(16+x) */ - interp_code_fx[i + 3] = round_fx( Ltemp ); /*Qx */ - - Ltemp = L_mult( inp_code_fx[kk], factor_i_fx[4] );/*Q(16+x) */ - Ltemp = L_mac( Ltemp, inp_code_fx[kkp1], factor_j_fx[4] );/*Q(16+x) */ - interp_code_fx[i + 4] = round_fx( Ltemp ); /*Qx */ - - kk++; - kkp1++; - } - - Ltemp = L_mult( inp_code_fx[kk], factor_j_fx[0] );/*Q(16+x) */ - interp_code_fx[i] = round_fx( Ltemp ); /*Qx */ - - Ltemp = L_mult( inp_code_fx[kk], factor_j_fx[1] );/*Q(16+x) */ - interp_code_fx[i + 1] = round_fx( Ltemp ); /*Qx */ - - return; -} - - - -/*======================================================================================*/ -/* FUNCTION : interp_code_4over2_fx() */ -/*--------------------------------------------------------------------------------------*/ -/* PURPOSE : Used to interpolate the excitation from the core sample rate */ -/* of 16 kHz to 32 kHz. */ -/* Simple linear interpolator - No need for precision here. */ -/*--------------------------------------------------------------------------------------*/ -/* INPUT ARGUMENTS : */ -/* _ (Word16[]) inp_code_fx : input vector (Qx) */ -/* _ (Word16) inp_length : length of input vector */ -/*--------------------------------------------------------------------------------------*/ -/* OUTPUT ARGUMENTS : */ -/* _ (Word16[]) interp_code_fx : output vector (Qx) */ -/*--------------------------------------------------------------------------------------*/ -/* INPUT/OUTPUT ARGUMENTS : */ -/* _ None */ -/*--------------------------------------------------------------------------------------*/ - -/* _ None */ -/*--------------------------------------------------------------------------------------*/ -/* RETURN ARGUMENTS : */ -/* _ None */ -/*======================================================================================*/ - -void interp_code_4over2_fx( - const Word16 inp_code_fx[], /* i : input vector Qx*/ - Word16 interp_code_fx[], /* o : output vector Qx*/ - const Word16 inp_length /* i : length of input vector */ -) -{ - Word16 i, j; - j = 0; - move16(); - FOR ( i = 0; i < inp_length - 1; i++ ) - { - interp_code_fx[j] = inp_code_fx[i]; - move16();/*Qx */ - interp_code_fx[j + 1] = add( shr( inp_code_fx[i], 1 ), shr( inp_code_fx[i + 1], 1 ) ); - move16(); - move16();/*Qx */ - j = add( j, 2 ); - } - - interp_code_fx[j] = inp_code_fx[i]; - move16(); - interp_code_fx[j + 1] = shr( inp_code_fx[i], 1 ); - move16();/*Qx */ - - return; -} - - -/*-------------------------------------------------------------------* -* wb_tbe_extras_reset_synth() -* -* Reset the extra parameters only required for WB TBE synthesis -*-------------------------------------------------------------------*/ - -void wb_tbe_extras_reset_synth_fx( Word16 state_lsyn_filt_shb[], Word16 state_lsyn_filt_dwn_shb[], - Word16 state_32and48k_WB_upsample[] - ,Word16 state_resamp_HB[] - ) -{ - set16_fx( state_lsyn_filt_shb, 0, 2 * ALLPASSSECTIONS_STEEP ); - set16_fx( state_lsyn_filt_dwn_shb, 0, 2 * ALLPASSSECTIONS_STEEP ); - set16_fx( state_32and48k_WB_upsample, 0, 2 * ALLPASSSECTIONS_STEEP ); - set16_fx( state_resamp_HB, 0, INTERP_3_1_MEM_LEN ); - - return; -} - -/*-------------------------------------------------------------------* - * elliptic_bpf_48k_generic() - * - * 18th-order elliptic bandpass filter at 14.0 to 20 kHz sampled at 48 kHz - * Implemented as 3 fourth order sections cascaded. - *-------------------------------------------------------------------*/ - -void elliptic_bpf_48k_generic_fx( - const Word16 input_fx[], /* i : input signal */ - Word16 *Q_input_fx, - Word16 output_fx[], /* o : output signal */ - Word32 memory_fx2[][4], /* i/o: 4 arrays of 4 for memory */ - Word16 memory_fx_Q[], - const Word16 full_band_bpf_fx[][5] /* i : filter coefficients b0,b1,b2,a0,a1,a2 Q13 */ -) -{ - Word16 i,j; - Word16 memory_fx0[4][4], memory_fx[4][4], Q_temp, Q_temp2; - Word32 L_tmp[L_FRAME48k], L_tmp2[L_FRAME48k], L_output[L_FRAME48k], L_tmpX, memory2_fx[4][4], L_tmpMax; - Word32 memory2_fx_2[4], memory2_fx_3[4]; - - FOR( i=0; i<4; i++ ) - { - memory_fx0[0][i] = extract_l(memory_fx2[0][i]); - memory_fx[0][i] =shl(memory_fx0[0][i],sub(*Q_input_fx,memory_fx_Q[0])); - memory2_fx[1][i] =L_shl(memory_fx2[1][i],sub(add(*Q_input_fx,11),memory_fx_Q[1])); - memory2_fx[2][i] =L_shl(memory_fx2[2][i],sub(add(*Q_input_fx,6),memory_fx_Q[2])); - memory2_fx[3][i] =L_shl(memory_fx2[3][i],sub(add(*Q_input_fx,1),memory_fx_Q[3])); - } - - L_tmpX = L_shr(L_mult(memory_fx[0][0],full_band_bpf_fx[0][4]),3);/*Q_input_fx + 13 + 1 - 3*/ - L_tmpX = L_add(L_shr(L_mult(memory_fx[0][1],full_band_bpf_fx[0][3]),3),L_tmpX);/*Q_input_fx + 13 + 1 - 3*/ - L_tmpX = L_add(L_shr(L_mult(memory_fx[0][2],full_band_bpf_fx[0][2]),3),L_tmpX);/*Q_input_fx + 13 + 1 - 3*/ - L_tmpX = L_add(L_shr(L_mult(memory_fx[0][3],full_band_bpf_fx[0][1]),3),L_tmpX);/*Q_input_fx + 13 + 1 - 3*/ - L_tmpX = L_add(L_shr(L_mult(input_fx[0],full_band_bpf_fx[0][0]),3),L_tmpX);/*Q_input_fx + 13 + 1 - 3*/ - L_tmpX = L_sub(L_tmpX,L_shl(Mult_32_16(memory2_fx[1][3],full_band_bpf_fx[3][1]),2));/*Q_input_fx + 11 + 13 -15 +2*/ - L_tmpX = L_sub(L_tmpX,L_shl(Mult_32_16(memory2_fx[1][2],full_band_bpf_fx[3][2]),2));/*Q_input_fx + 11 + 13 -15 +2*/ - L_tmpX = L_sub(L_tmpX,L_shl(Mult_32_16(memory2_fx[1][1],full_band_bpf_fx[3][3]),2));/*Q_input_fx + 11 + 13 -15 +2*/ - L_tmp[0] = L_sub(L_tmpX,L_shl(Mult_32_16(memory2_fx[1][0],full_band_bpf_fx[3][4]),2));/*Q_input_fx + 11 + 13 -15 +2*/ move32(); - - L_tmpX = L_shr(L_mult(memory_fx[0][1],full_band_bpf_fx[0][4]),3);/*Q_input_fx + 13 + 1 - 3*/ - L_tmpX = L_add(L_shr(L_mult(memory_fx[0][2],full_band_bpf_fx[0][3]),3),L_tmpX);/*Q_input_fx + 13 + 1 - 3*/ - L_tmpX = L_add(L_shr(L_mult(memory_fx[0][3],full_band_bpf_fx[0][2]),3),L_tmpX);/*Q_input_fx + 13 + 1 - 3*/ - L_tmpX = L_add(L_shr(L_mult(input_fx[0],full_band_bpf_fx[0][1]),3),L_tmpX);/*Q_input_fx + 13 + 1 - 3*/ - L_tmpX = L_add(L_shr(L_mult(input_fx[1],full_band_bpf_fx[0][0]),3),L_tmpX);/*Q_input_fx + 13 + 1 - 3*/ - L_tmpX = L_sub(L_tmpX,L_shl(Mult_32_16(L_tmp[0],full_band_bpf_fx[3][1]),2));/*Q_input_fx + 11 + 13 -15 +2*/ - L_tmpX = L_sub(L_tmpX,L_shl(Mult_32_16(memory2_fx[1][3],full_band_bpf_fx[3][2]),2));/*Q_input_fx + 11 + 13 -15 +2*/ - L_tmpX = L_sub(L_tmpX,L_shl(Mult_32_16(memory2_fx[1][2],full_band_bpf_fx[3][3]),2));/*Q_input_fx + 11 + 13 -15 +2*/ - L_tmp[1] = L_sub(L_tmpX,L_shl(Mult_32_16(memory2_fx[1][1],full_band_bpf_fx[3][4]),2));/*Q_input_fx + 11 + 13 -15 +2*/ move32(); - - L_tmpX = L_shr(L_mult(memory_fx[0][2],full_band_bpf_fx[0][4]),3);/*Q_input_fx + 13 + 1 - 3*/ - L_tmpX = L_add(L_shr(L_mult(memory_fx[0][3],full_band_bpf_fx[0][3]),3),L_tmpX);/*Q_input_fx + 13 + 1 - 3*/ - L_tmpX = L_add(L_shr(L_mult(input_fx[0],full_band_bpf_fx[0][2]),3),L_tmpX);/*Q_input_fx + 13 + 1 - 3*/ - L_tmpX = L_add(L_shr(L_mult(input_fx[1],full_band_bpf_fx[0][1]),3),L_tmpX);/*Q_input_fx + 13 + 1 - 3*/ - L_tmpX = L_add(L_shr(L_mult(input_fx[2],full_band_bpf_fx[0][0]),3),L_tmpX);/*Q_input_fx + 13 + 1 - 3*/ - L_tmpX = L_sub(L_tmpX,L_shl(Mult_32_16(L_tmp[1],full_band_bpf_fx[3][1]),2));/*Q_input_fx + 11 + 13 -15 +2*/ - L_tmpX = L_sub(L_tmpX,L_shl(Mult_32_16(L_tmp[0],full_band_bpf_fx[3][2]),2));/*Q_input_fx + 11 + 13 -15 +2*/ - L_tmpX = L_sub(L_tmpX,L_shl(Mult_32_16(memory2_fx[1][3],full_band_bpf_fx[3][3]),2));/*Q_input_fx + 11 + 13 -15 +2*/ - L_tmp[2] = L_sub(L_tmpX,L_shl(Mult_32_16(memory2_fx[1][2],full_band_bpf_fx[3][4]),2));/*Q_input_fx + 11 + 13 -15 +2*/ move32(); - - L_tmpX = L_shr(L_mult(memory_fx[0][3],full_band_bpf_fx[0][4]),3);/*Q_input_fx + 13 + 1 - 3*/ - L_tmpX = L_add(L_shr(L_mult(input_fx[0],full_band_bpf_fx[0][3]),3),L_tmpX);/*Q_input_fx + 13 + 1 - 3*/ - L_tmpX = L_add(L_shr(L_mult(input_fx[1],full_band_bpf_fx[0][2]),3),L_tmpX);/*Q_input_fx + 13 + 1 - 3*/ - L_tmpX = L_add(L_shr(L_mult(input_fx[2],full_band_bpf_fx[0][1]),3),L_tmpX);/*Q_input_fx + 13 + 1 - 3*/ - L_tmpX = L_add(L_shr(L_mult(input_fx[3],full_band_bpf_fx[0][0]),3),L_tmpX);/*Q_input_fx + 13 + 1 - 3*/ - L_tmpX = L_sub(L_tmpX,L_shl(Mult_32_16(L_tmp[2],full_band_bpf_fx[3][1]),2));/*Q_input_fx + 11 + 13 -15 +2*/ - L_tmpX = L_sub(L_tmpX,L_shl(Mult_32_16(L_tmp[1],full_band_bpf_fx[3][2]),2));/*Q_input_fx + 11 + 13 -15 +2*/ - L_tmpX = L_sub(L_tmpX,L_shl(Mult_32_16(L_tmp[0],full_band_bpf_fx[3][3]),2));/*Q_input_fx + 11 + 13 -15 +2*/ - L_tmp[3] = L_sub(L_tmpX,L_shl(Mult_32_16(memory2_fx[1][3],full_band_bpf_fx[3][4]),2));/*Q_input_fx + 11 + 13 -15 +2*/ move32(); - - FOR( i=4; i 0) - { - tmp2 = shr(tmp2, 1); - exp = add(exp, 1); - } - IF( 0 != tmp3 ) - { - tmp3 = div_s(tmp2, tmp3); - L_tmp = L_deposit_h(tmp3); - L_tmp = Isqrt_lc(L_tmp, &exp); /*Q(31-exp)*/ - ratio2 = Mult_32_16(L_tmp,ratio);/*Q(31-exp+0-15 = 16-exp)*/ - } - ELSE - { - ratio2 = 0; - } - - IF( !bfi ) - { - *prev_fbbwe_ratio = ratio; - move16(); - } - ELSE - { - /**prev_fbbwe_ratio = ratio*0.5f;*/ - *prev_fbbwe_ratio = shr(ratio,1); - move16(); - } - tmp3 = add(sub(Qout, add(sub(1,exp),exp_tmp)),16);/*Qout - (1 -exp +exp_tmp) + 16 */ - FOR( i=0; i0) - { - expa = norm_l(temp_p1_p3); - fraca = extract_h(L_shl(temp_p1_p3,expa)); - expa = sub(30,expa); - - expb = norm_l(temp_p1_p2); - fracb = round_fx(L_shl(temp_p1_p2,expb)); - expb = sub(30,expb); - - num_flag = 0; - move16(); - IF(fraca<0) - { - num_flag = 1; - move16(); - fraca = negate(fraca); - } - - den_flag = 0; - move16(); - IF(fracb<0) - { - den_flag = 1; - move16(); - fracb = negate(fracb); - } - - scale = shr(sub(fraca,fracb),15); - fracb = shl(fracb,scale); - expb = sub(expb,scale); - - tmp = div_s(fracb,fraca); - exp1 = sub(expb,expa); - tmp = shl(tmp,exp1); - - if(sub(num_flag,den_flag) != 0) - { - tmp = negate(tmp); - } - } - ELSE - { - tmp = 0; - } - - vf_modified[0] = s_min(s_max(tmp, 3277 /* 0.1f in Q15*/), 32440 /* 0.99f in Q15 */); - move16(); - - *vf_ind = usquant_fx(vf_modified[0], &tmp1, 4096 /* 0.125 in Q15 */, 2048 /* 0.125 in Q14 */, shl(1,NUM_BITS_SHB_VF)); - move16(); - - vf_modified[0] = tmp1; - move16(); - vf_modified[1] = tmp1; - move16(); - vf_modified[2] = tmp1; - move16(); - vf_modified[3] = tmp1; - move16(); - vf_modified[4] = tmp1; - move16(); - - /* vf_modified in Q15 */ - - return; -} - -/*======================================================================================*/ -/* FUNCTION : prep_tbe_exc_fx() */ -/*--------------------------------------------------------------------------------------*/ -/* PURPOSE : Prepare TBE excitation */ -/*--------------------------------------------------------------------------------------*/ -/* INPUT ARGUMENTS : */ -/* _ (Word16) L_frame_fx : length of the frame */ -/* _ (Word16) i_subfr_fx : subframe index */ -/* _ (Word16) gain_pit_fx : Pitch gain (14) */ -/* _ (Word32) gain_code_fx : algebraic codebook gain (Q(16+Q_exc)) */ -/* _ (Word16*[]) code_fx : algebraic excitation (Q9) */ -/* _ (Word16) voice_fac_fx : voicing factor (Q15) */ -/* _ (Word16) gain_preQ_fx : prequantizer excitation gain */ -/* _ (Word16[]) code_preQ_fx : prequantizer excitation */ -/*--------------------------------------------------------------------------------------*/ -/* OUTPUT ARGUMENTS : */ -/* _ (Word16*[]) voice_factors_fx : TBE voicing factor (Q15) */ -/*--------------------------------------------------------------------------------------*/ -/* INPUT/OUTPUT ARGUMENTS : */ -/* _ (Word16[]) bwe_exc_fx : excitation for TBE (Q_exc) */ -/*--------------------------------------------------------------------------------------*/ - -/* _ None */ -/*--------------------------------------------------------------------------------------*/ -/* RETURN ARGUMENTS : */ -/* _ None */ -/*======================================================================================*/ - -void prep_tbe_exc_fx( - const Word16 L_frame_fx, /* i : length of the frame */ - const Word16 i_subfr_fx, /* i : subframe index */ - const Word16 gain_pit_fx, /* i : Pitch gain Q14*/ - const Word32 gain_code_fx, /* i : algebraic codebook gain 16+Q_exc*/ - const Word16 code_fx[], /* i : algebraic excitation Q9*/ - const Word16 voice_fac_fx, /* i : voicing factor Q15*/ - Word16 *voice_factors_fx, /* o : TBE voicing factor Q15*/ - Word16 bwe_exc_fx[], /* i/o: excitation for TBE Q_exc*/ - const Word16 gain_preQ_fx, /* i : prequantizer excitation gain */ - const Word16 code_preQ_fx[], /* i : prequantizer excitation */ - const Word16 Q_exc, /* i : Excitation, bwe_exc Q-factor */ - Word16 T0, /* i : integer pitch variables Q0 */ - Word16 T0_frac, /* i : Fractional pitch variables Q0*/ - const Word16 coder_type, /* i : coding type */ - Word32 core_brate /* i :core bitrate */ -) -{ - Word16 i; - Word16 tmp_code_fx[L_SUBFR * HIBND_ACB_L_FAC]; - Word16 tmp_code_preInt_fx[L_SUBFR]; - Word16 gain_code16 = 0; - Word16 tmp /*, tmp1, tmp2*/; - /*Word16 random_code[L_SUBFR * HIBND_ACB_L_FAC];*/ - Word16 pitch; - - Word32 L_tmp, Ltemp1, Ltemp2; - Word32 tempQ31; - Word16 tempQ15; - - /**voice_factors = VF_0th_PARAM + VF_1st_PARAM * voice_fac + VF_2nd_PARAM * voice_fac * voice_fac; - = VF_0th_PARAM + voice_fac * (VF_1st_PARAM + VF_2nd_PARAM * voice_fac ) - *voice_factors = min( max(0.0f, *voice_factors), 1.0f); */ - tempQ31 = L_deposit_h( VF_1st_PARAM_FX ); - tempQ15 = mac_r(tempQ31, VF_2nd_PARAM_FX, voice_fac_fx); - tempQ31 = L_deposit_h( VF_0th_PARAM_FX ); - *voice_factors_fx = mac_r(tempQ31, voice_fac_fx, tempQ15); - - tmp = 32767; - move16(); - - pitch = shl( add( shl( T0, 2 ), T0_frac ), 5 ); /* Q7 */ - - test(); - test(); - IF ( ( ( sub(coder_type,VOICED) == 0 ) || ( sub( pitch, 14784 ) > 0 ) ) && ( L_sub(core_brate,ACELP_8k00) > 0 ) ) - { - tmp = MAX_16; - move16(); - *voice_factors_fx = mult_r( *voice_factors_fx, tmp ); - } - - *voice_factors_fx = s_min(s_max(*voice_factors_fx, 0), MAX_16); - move16(); - - IF ( sub(L_frame_fx,L_FRAME) == 0 ) - { - interp_code_5over2_fx( code_fx, tmp_code_fx, L_SUBFR ); /* code: Q9, tmp_code: Q9 */ - gain_code16 = round_fx( L_shl( gain_code_fx, Q_exc ) ); /*Q_exc */ - FOR ( i = 0; i < L_SUBFR * HIBND_ACB_L_FAC; i++ ) - { - L_tmp = L_mult( gain_code16, tmp_code_fx[i] ); /* Q9 + Q_exc + 1*/ - L_tmp = L_shl( L_tmp, 5 ); /* Q9 + Q_exc + Q6*/ - L_tmp = L_mac( L_tmp, gain_pit_fx, bwe_exc_fx[i + i_subfr_fx * HIBND_ACB_L_FAC] ); /*Q15+Q_exc */ - L_tmp = L_shl( L_tmp, 1 ); /*16+Q_exc */ /* saturation can occur here */ - bwe_exc_fx[i + i_subfr_fx * HIBND_ACB_L_FAC] = round_fx( L_tmp ); /*Q_exc */ - } - } - ELSE - { - IF( gain_preQ_fx != 0 ) - { - FOR( i = 0; i < L_SUBFR; i++ ) - { - /*code in the encoder is Q9 and there is no <<1 with Mult_32_16 Q16 * Q9 -> Q9 */ - Ltemp1 = Mult_32_16(gain_code_fx, code_fx[i]); /* Q16 + Q9 + 1 - 16 = Q10 */ - Ltemp2 = L_mult(gain_preQ_fx, code_preQ_fx[i]); /*Q2 * Q10 -> Q12 */ - - Ltemp1 = L_shl( Ltemp1, Q_exc+6 /*Q_exc+16-19*/) ; /*Q_exc+16 */ - Ltemp2 = L_shl( Ltemp2, Q_exc+4 /*Q_exc+16-13*/ ) ; /*Q_exc+16 */ - - tmp_code_preInt_fx[i] = round_fx(L_add(Ltemp1, Ltemp2)); /* Q_exc */ - } - } - ELSE - { - FOR( i = 0; i < L_SUBFR; i++ ) - { - /*code in the encoder is Q9 and there is no <<1 with Mult_32_16 Q16 * Q9 -> Q9 */ - Ltemp1 = Mult_32_16(gain_code_fx, code_fx[i]); /* Q16 + Q9 + 1 - 16 = Q10 */ - Ltemp1 = L_shl( Ltemp1, Q_exc+6 /*Q_exc+16-19*/) ; /*Q_exc+16 */ - tmp_code_preInt_fx[i] = round_fx(Ltemp1); /* Q_exc */ - } - } - - interp_code_4over2_fx( tmp_code_preInt_fx, tmp_code_fx, L_SUBFR ); /* o: tmp_code in Q_exc */ - FOR ( i = 0; i < L_SUBFR * 2; i++ ) - { - L_tmp = L_mult(gain_pit_fx, bwe_exc_fx[i + i_subfr_fx*2]); /*Q14+Q_exc+1 */ - tmp = round_fx(L_shl(L_tmp, 1 /* (Q_exc+16)-(14+Q_exc+1)*/ )); /* tmp in Q_exc */ - bwe_exc_fx[i + i_subfr_fx * 2] = add(tmp, tmp_code_fx[i]); /*Q_exc */ move16(); - } - } - - return; -} - - -/*=============================================================================*/ -/* FUNCTION : void swb_formant_fac_fx ( ) */ -/*------------------------------------------------------------------------------*/ -/* PURPOSE : * Find strength of adaptive formant postfilter using tilt */ -/* of the high band. The 2nd lpc coefficient is used as a tilt approximation. */ -/*------------------------------------------------------------------------------*/ -/* INPUT ARGUMENTS : */ -/* const Word16 lpc_shb2 : 2nd HB LPC coefficient Q12 */ -/*------------------------------------------------------------------------------*/ -/*INPUT/OUTPUT ARGUMENTS : */ -/* Word16 *tilt_mem Q12 */ -/* OUTPUT ARGUMENTS : */ -/*------------------------------------------------------------------------------*/ -/* RETURN ARGUMENTS : */ -/* formant_fac :Formant filter strength [0,1] Q15 */ -/*------------------------------------------------------------------------------*/ -/* CALLED FROM : */ -/*==============================================================================*/ - -Word16 swb_formant_fac_fx( /* o : Formant filter strength [0,1] */ - const Word16 lpc_shb2, /* Q12 i : 2nd HB LPC coefficient */ - Word16* tilt_mem /* i/o: Tilt smoothing memory (Q12) */ -) -{ - Word16 formant_fac; - Word16 tmp; - - /* Smoothen tilt value */ - /* tmp = 0.5f * (float)fabs(lpc_shb2) + 0.5f * *tilt_mem; */ - tmp = mult_r( 16384, abs_s( lpc_shb2 ) ); - tmp = add( tmp, mult_r( 16384, *tilt_mem ) ); /* Q12 */ - *tilt_mem = tmp; - move16();/*Q12 */ - /* Map to PF strength */ - /* formant_fac = (tmp - SWB_TILT_LOW)*SWB_TILT_DELTA; */ - tmp = sub( tmp, SWB_TILT_LOW_FX ); /* Q12 */ - formant_fac = mult_r( tmp, SWB_TILT_DELTA_FX ); /* Q12 */ - - - IF ( sub( formant_fac, 4096 ) > 0 ) - { - formant_fac = 4096; - move16(); - } - ELSE if ( formant_fac < 0 ) - { - formant_fac = 0; - move16(); - } - /* now formant_fac in Q12 */ - - /* formant_fac = 1.0f - 0.5f*formant_fac */ - tmp = mult_r(16384, formant_fac); /* 0.5 in Q12 */ - formant_fac = shl(sub(4096,tmp),3); - - return formant_fac; /*Q15 */ -} - - -void wb_tbe_extras_reset_fx( - Word16 mem_genSHBexc_filt_down_wb2[], - Word16 mem_genSHBexc_filt_down_wb3[] ) -{ - set16_fx( mem_genSHBexc_filt_down_wb2, 0, 2*ALLPASSSECTIONS_STEEP+1 ); - set16_fx( mem_genSHBexc_filt_down_wb3, 0, 2*ALLPASSSECTIONS_STEEP+1 ); - - return; -} - - - -Word16 get_tbe_bits_fx( - Word32 bitrate, - Word16 bandwidth - ,Word16 rf_mode -) -{ - Word16 i, bits = 0; - - IF( sub(rf_mode,1)==0 ) - { - /* TBE bits for core, primary frame */ - test(); - test(); - IF( (sub(bandwidth, WB ) == 0) && (L_sub(bitrate, ACELP_13k20) == 0) ) - { - /* Gain frame: 4, Gain shapes: 0, and LSFs: 2 */ - bits = NUM_BITS_SHB_FrameGain_LBR_WB + NUM_BITS_LBR_WB_LSF; - move16(); - } - ELSE IF( (sub(bandwidth, SWB ) == 0) && (L_sub(bitrate, ACELP_13k20) == 0) ) - { - /* Gain frame: 5, Gain shapes: 5, and lowrate LSFs: 8 */ - bits = NUM_BITS_SHB_FRAMEGAIN + NUM_BITS_SHB_SUBGAINS + 8; - move16(); - } - } - ELSE - { - test(); - test(); - IF( (sub(bandwidth, WB ) == 0) && (L_sub(bitrate, ACELP_9k60) == 0) ) - { - bits = NUM_BITS_LBR_WB_LSF + NUM_BITS_SHB_FrameGain_LBR_WB; - move16(); - } - ELSE IF( (sub( bandwidth, SWB ) == 0) || (sub( bandwidth, FB ) == 0) ) - { - test(); - IF( L_sub(bitrate, ACELP_9k60) == 0 ) - { - bits = NUM_BITS_SHB_FRAMEGAIN + NUM_BITS_SHB_SUBGAINS + 8; - move16(); - } - ELSE IF( (L_sub( bitrate, ACELP_13k20 ) >= 0 ) && (L_sub( bitrate, ACELP_32k ) <= 0 ) ) - { - bits = NUM_BITS_SHB_SUBGAINS + NUM_BITS_SHB_FRAMEGAIN + NUM_LSF_GRID_BITS + MIRROR_POINT_BITS; - move16(); - - FOR ( i=0; i= 0 ) - { - bits = add( bits, NUM_BITS_SHB_ENER_SF + NUM_BITS_SHB_VF + NUM_BITS_SHB_RES_GS*NB_SUBFR16k ); - } - - test(); - test(); - if( sub(bandwidth, SWB) == 0 && (L_sub(bitrate, ACELP_16k40) == 0 || L_sub(bitrate, ACELP_24k40) == 0) ) - { - bits = add( bits, BITS_TEC+BITS_TFA ); - } - - if ( sub(bandwidth, FB) == 0 ) - { - /* full band slope */ - bits = add( bits, 4 ); - } - } - } - - return bits; -} diff --git a/src/libs/libevs/lib_com/syn_12k8.cpp b/src/libs/libevs/lib_com/syn_12k8.cpp new file mode 100644 index 00000000..2d76af9b --- /dev/null +++ b/src/libs/libevs/lib_com/syn_12k8.cpp @@ -0,0 +1,35 @@ +/*==================================================================================== + EVS Codec 3GPP TS26.443 Nov 13, 2018. Version 12.11.0 / 13.7.0 / 14.3.0 / 15.1.0 + ====================================================================================*/ + +#include "options.h" +#include "cnst.h" +#include "prot.h" + +/*------------------------------------------------------------------ + * syn_12k8() + * + * perform the synthesis filtering 1/A(z) + *------------------------------------------------------------------*/ + +void syn_12k8( + const short L_frame, /* i : length of the frame */ + const float *Aq, /* i : LP filter coefficients */ + const float *exc, /* i : input signal */ + float *synth, /* o : output signal */ + float *mem, /* i/o: initial filter states */ + const short update_m /* i : update memory flag: 0 --> no memory update */ +) /* 1 --> update of memory */ +{ + const float *p_Aq; + short i_subfr; + + p_Aq = Aq; /* pointer to interpolated LPC parameters */ + for ( i_subfr=0; i_subfrL_frame :length of the frame */ -/* _ (Word16[]) Aq : LP filter coefficients Q12 */ -/* _ (Word16) exc : input signal Q_exc */ -/* _ (Word16) update_m : update memory flag: 0-->no memory update */ -/* 1 --> update of memory */ -/* _ (Word16) Q_exc : Excitation scaling */ -/* _ (Word16) Q_syn : Synthesis scaling */ -/*---------------------------------------------------------------------------*/ -/* INPUT OUTPUT ARGUMENTS : */ -/*---------------------------------------------------------------------------*/ -/* OUTPUT ARGUMENTS : */ -/* _ (Word16[]) synth : initial filter states Q_syn */ -/*---------------------------------------------------------------------------*/ - -/* _ (Word16[]) st_fx->mem_syn2_fx: initial filter states Q_syn */ -/*---------------------------------------------------------------------------*/ -/* RETURN ARGUMENTS : */ -/* _ None */ -/*===========================================================================*/ -void syn_12k8_fx( - Word16 L_frame, - const Word16 *Aq, /* i : LP filter coefficients Q12 */ - const Word16 *exc, /* i : input signal Q_exc */ - Word16 *synth, /* o : output signal Q_syn */ - Word16 *mem, /* i/o: initial filter states Q_syn */ - const Word16 update_m, /* i : update memory flag: 0 --> no memory update Q0 */ - /* 1 --> update of memory */ - const Word16 Q_exc, /* i : Excitation scaling Q0 */ - const Word16 Q_syn /* i : Synthesis scaling Q0 */ -) -{ - const Word16 *p_Aq; - Word16 i_subfr; - Word16 shift; - - shift = sub(Q_exc, Q_syn); - p_Aq = Aq; - move16(); - FOR (i_subfr = 0; i_subfr < L_frame; i_subfr += L_SUBFR) - { - Syn_filt_s(shift, p_Aq, M, &exc[i_subfr], &synth[i_subfr], L_SUBFR, mem, update_m); - p_Aq += (M+1); - move16(); /* interpolated LPC parameters for next subframe */ - } - return; -} diff --git a/src/libs/libevs/lib_com/syn_filt.cpp b/src/libs/libevs/lib_com/syn_filt.cpp new file mode 100644 index 00000000..bc6e5ec9 --- /dev/null +++ b/src/libs/libevs/lib_com/syn_filt.cpp @@ -0,0 +1,122 @@ +/*==================================================================================== + EVS Codec 3GPP TS26.443 Nov 13, 2018. Version 12.11.0 / 13.7.0 / 14.3.0 / 15.1.0 + ====================================================================================*/ + +#include +#include "options.h" +#include "cnst.h" +#include "prot.h" +#include "rom_com.h" + +/*------------------------------------------------------------------* + * syn_filt() + * + * perform the synthesis filtering 1/A(z) + *------------------------------------------------------------------*/ + +void syn_filt( + const float a[], /* i : LP filter coefficients */ + const short m, /* i : order of LP filter */ + const float x[], /* i : input signal */ + float y[], /* o : output signal */ + const short l, /* i : size of filtering */ + float mem[], /* i/o: initial filter states */ + const short update_m /* i : update memory flag: 0 --> no memory update */ +) /* 1 --> update of memory */ +{ + short i, j; +#if !defined(TCXLTP_LTP_ORDER) + float buf[L_FRAME48k + L_FRAME48k/2 + M]; /* temporary synthesis buffer */ +#else + float buf[L_FRAME48k + L_FRAME48k/2 + TCXLTP_LTP_ORDER]; /* temporary synthesis buffer */ +#endif + float s, *yy; + + yy = &buf[0]; + + /*------------------------------------------------------------------* + * copy initial filter states into synthesis buffer and do synthesis + *------------------------------------------------------------------*/ + + for (i = 0; i < m; i++) + { + *yy++ = mem[i]; + } + + /*-----------------------------------------------------------------------* + * Do the filtering + *-----------------------------------------------------------------------*/ + + for (i = 0; i < l; i++) + { + s = x[i]; + for (j = 1; j <= m; j++) + { + s -= a[j]*yy[i-j]; + } + + yy[i] = s; + y[i] = s; + } + + /*------------------------------------------------------------------* + * Update memory if required + *------------------------------------------------------------------*/ + + if (update_m) + { + for (i = 0; i < m; i++) + { + mem[i] = yy[l-m+i]; + } + } + + return; +} + + +/*-------------------------------------------------------------------* + * synth_mem_updt2() + * + * Update of synthesis filter memories in case of ACELP@12k8 <-> ACELP@16k switching + *--------------------------------------------------------------------*/ + +void synth_mem_updt2( + const short L_frame, /* i : frame length */ + const short last_L_frame, /* i : frame length */ + float old_exc[], /* i/o: excitation buffer */ + float mem_syn_r[], /* i/o: synthesis filter memory */ + float mem_syn2[], /* o : synthesis filter memory for find_target */ + float mem_syn[], /* o : synthesis filter memory for find_target */ + const short dec /* i : flag for decoder indication */ +) +{ + short mem_syn_r_size_old, mem_syn_r_size_new; + + /* Residual and update old_exc */ + if( dec == DEC ) + { + lerp( old_exc+L_EXC_MEM_DEC-(last_L_frame+last_L_frame/2), old_exc+L_EXC_MEM_DEC-(L_frame+L_frame/2), L_frame+L_frame/2, last_L_frame+last_L_frame/2 ); + } + else + { + lerp( old_exc+L_EXC_MEM-last_L_frame, old_exc+L_EXC_MEM-L_frame, L_frame, last_L_frame ); + } + + /*Resamp memory*/ + /*Size of LPC syn memory*/ + mem_syn_r_size_old = (short)(1.25*last_L_frame/20.f); + mem_syn_r_size_new = (short)(1.25*L_frame/20.f); + + lerp( mem_syn_r + L_SYN_MEM - mem_syn_r_size_old, mem_syn_r + L_SYN_MEM - mem_syn_r_size_new, mem_syn_r_size_new, mem_syn_r_size_old ); + + mvr2r( mem_syn_r+L_SYN_MEM-M, mem_syn2, M ); + + if( mem_syn != NULL ) + { + mvr2r( mem_syn2, mem_syn, M ); + } + + return; +} + diff --git a/src/libs/libevs/lib_com/syn_filt_fx.cpp b/src/libs/libevs/lib_com/syn_filt_fx.cpp deleted file mode 100755 index e82a7e55..00000000 --- a/src/libs/libevs/lib_com/syn_filt_fx.cpp +++ /dev/null @@ -1,275 +0,0 @@ -/*==================================================================================== - EVS Codec 3GPP TS26.442 Apr 03, 2018. Version 12.11.0 / 13.6.0 / 14.2.0 - ====================================================================================*/ - -#include -#include "options.h" /* Compilation switches */ -#include "cnst_fx.h" /* Common constants */ -#include "basop_util.h" -#include "prot_fx.h" /* Function prototypes */ -#include "rom_com_fx.h" /* Static table prototypes */ -#include "stl.h" - -static Word32 syn_kern_2(Word32 L_tmp, const Word16 a[], const Word16 y[]) -{ - L_tmp = L_msu(L_tmp, y[-1], a[1]); - return L_msu(L_tmp, y[-2], a[2]); -} - -static Word32 syn_kern_4(Word32 L_tmp, const Word16 a[], const Word16 y[]) -{ - L_tmp = syn_kern_2(L_tmp, a, y); - return syn_kern_2(L_tmp, a+2, y-2); -} - -static Word32 syn_kern_6(Word32 L_tmp, const Word16 a[], const Word16 y[]) -{ - L_tmp = syn_kern_4(L_tmp, a, y); - return syn_kern_2(L_tmp, a+4, y-4); -} - -static Word32 syn_kern_8(Word32 L_tmp, const Word16 a[], const Word16 y[]) -{ - L_tmp = syn_kern_4(L_tmp, a, y); - return syn_kern_4(L_tmp, a+4, y-4); -} - -static Word32 syn_kern_10(Word32 L_tmp, const Word16 a[], const Word16 y[]) -{ - L_tmp = syn_kern_8(L_tmp, a, y); - return syn_kern_2(L_tmp, a+8, y-8); -} - -Word32 syn_kern_16(Word32 L_tmp, const Word16 a[], const Word16 y[]) -{ - L_tmp = syn_kern_8(L_tmp, a, y); - return syn_kern_8(L_tmp, a+8, y-8); -} - -static Word32 syn_kern_24(Word32 L_tmp, const Word16 a[], const Word16 y[]) -{ - L_tmp = syn_kern_16(L_tmp, a, y); - return syn_kern_8(L_tmp, a+16, y-16); -} - -/*------------------------------------------------------------------* - * Syn_filt_s_lc: - * - * perform the synthesis filtering 1/A(z). - * Optimized Version when No Memory, Past is Set to 0 - *------------------------------------------------------------------*/ -void syn_filt_s_lc_fx( - const Word16 shift, /* i : scaling to apply Q0 */ - const Word16 a[], /* i : LP filter coefficients Q12 */ - const Word16 x[], /* i : input signal Qx */ - Word16 y[], /* o : output signal Qx-s */ - const Word16 lg /* i : size of filtering Q0 */ -) -{ - Word16 i, j; - Word32 L_tmp; - Word16 a0; - Word16 q; - - - q = add( norm_s(a[0]), 1 ); - a0 = shr(a[0], shift); /* input / 2^shift */ - - /*-----------------------------------------------------------------------* - * Do the filtering - *-----------------------------------------------------------------------*/ - FOR (i = 0; i < M; i++) - { - L_tmp = L_mult(*x++, a0); - /* Stop at i to Avoid Mults with Zeros */ - FOR (j = 1; j <= i; j++) - { - L_tmp = L_msu(L_tmp, y[-j], a[j]); - } - - L_tmp = L_shl(L_tmp, q); - *y++ = round_fx(L_tmp); - } - - FOR (; i < lg; i++) - { - L_tmp = syn_kern_16(L_mult(*x++, a0), a, y); - L_tmp = L_shl(L_tmp, q); - *y++ = round_fx(L_tmp); - } -} - -/*------------------------------------------------------------------* - * Syn_filt_s: - * - * perform the synthesis filtering 1/A(z). - *------------------------------------------------------------------*/ -void Syn_filt_s( - const Word16 shift, /* i : scaling to apply Q0 */ - const Word16 a[], /* i : LP filter coefficients Q12 */ - const Word16 m, /* i : order of LP filter Q0 */ - const Word16 x[], /* i : input signal Qx */ - Word16 y[], /* o : output signal Qx-s */ - const Word16 lg, /* i : size of filtering Q0 */ - Word16 mem[], /* i/o: memory associated with this filtering. Qx-s */ - const Word16 update /* i : 0=no update, 1=update of memory. Q0 */ -) -{ - E_UTIL_synthesis(shift, a, x, y, lg, mem, update, m); -} - - -/* - * E_UTIL_synthesis - * - * Parameters: - * shift i : scaling to apply for a[0] Q0 - * a[] i : LP filter coefficients Qx - * x[] i : input signal Qx - * y[] o : output signal Qx-s - * lg i : size of filtering Q0 - * mem[] i/o: memory associated with this filtering. Qx-s - * update i : 0=no update, 1=update of memory. Q0 - * m i : order of LP filter Q0 - * - * Function: - * Perform the synthesis filtering 1/A(z). - * Memory size is always M. - * - * Returns: - * void - */ -void E_UTIL_synthesis(const Word16 shift, const Word16 a[], const Word16 x[], Word16 y[], - const Word16 lg, Word16 mem[], const Word16 update, const Word16 m - ) -{ - Word16 i, j, a0; - Word32 L_tmp; - Word16 q; - Word32 (*syn_kern)(Word32 L_tmp, const Word16 a[], const Word16 y[]) = NULL; - - if (sub(m, 6) == 0) - { - syn_kern = syn_kern_6; - } - if (sub(m, 10) == 0) - { - syn_kern = syn_kern_10; - } - if (sub(m, 16) == 0) - { - syn_kern = syn_kern_16; - } - if (sub(m, 24) == 0) - { - syn_kern = syn_kern_24; - } - assert(syn_kern != NULL); - q = add( norm_s(a[0]), 1 ); - - - - /*-----------------------------------------------------------------------* - * Set Memory Pointer at End for Backward Access - *-----------------------------------------------------------------------*/ - mem += m; /*move16();*/ - - a0 = shr(a[0], shift); /* input / 2^shift */ - - /*-----------------------------------------------------------------------* - * Do the filtering - *-----------------------------------------------------------------------*/ - /* Filtering Only from Input + Memory */ - L_tmp = syn_kern(L_mult(a0, *x++), a, mem); - L_tmp = L_shl(L_tmp, q); - *y++ = round_fx(L_tmp); - - /* Filtering from Input + Mix of Memory & Output Signal Past */ - FOR (i = 1; i < m; i++) - { - L_tmp = L_mult(a0, *x++); - /* Process Output Signal Past */ - FOR (j = 1; j <= i; j++) - { - L_tmp = L_msu(L_tmp, a[j], y[-j]); - } - /* Process Memory */ - FOR (; j <= m; j++) - { - L_tmp = L_msu(L_tmp, a[j], mem[i-j]); - } - L_tmp = L_shl(L_tmp, q); - *y++ = round_fx(L_tmp); - } - - /* Filtering from Input + Output Signal Past */ - FOR (; i < lg; i++) - { - L_tmp = syn_kern(L_mult(a0, *x++), a, y); - L_tmp = L_shl(L_tmp, q); - *y++ = round_fx(L_tmp); - } - - /*-----------------------------------------------------------------------* - * Update memory if required - *-----------------------------------------------------------------------*/ - IF (update != 0) - { - FOR (i = 0; i < m; i++) - { - *--mem = *--y; - move16(); - } - } - - return; -} - - - -/*-------------------------------------------------------------------* - * synth_mem_updt2() - * - * Update of synthesis filter memories in case of ACELP@12k8 <-> ACELP@16k switching - *--------------------------------------------------------------------*/ - -void synth_mem_updt2( - const Word16 L_frame, /* i : frame length */ - const Word16 last_L_frame, /* i : frame length */ - Word16 old_exc[], /* i/o: excitation buffer */ - Word16 mem_syn_r[], /* i/o: synthesis filter memory */ - Word16 mem_syn2[], /* o : synthesis filter memory for find_target */ - Word16 mem_syn[], /* o : synthesis filter memory for find_target */ - const Word16 dec /* i : flag for decoder indication */ -) -{ - Word16 mem_syn_r_size_old, mem_syn_r_size_new; - - /* Residual and update old_exc */ - IF( sub(dec, DEC) == 0 ) - { - lerp( old_exc+L_EXC_MEM_DEC-(last_L_frame+last_L_frame/2), old_exc+L_EXC_MEM_DEC-(L_frame+L_frame/2), L_frame+L_frame/2, last_L_frame+last_L_frame/2 ); - } - ELSE - { - lerp( old_exc+L_EXC_MEM-last_L_frame, old_exc+L_EXC_MEM-L_frame, L_frame, last_L_frame ); - } - - /*Resamp memory*/ - /*Size of LPC syn memory*/ - /* 1.25/20.0 = 1.0/16.0 -> shift 4 to the right. */ - mem_syn_r_size_old = shr(last_L_frame, 4); - mem_syn_r_size_new = shr(L_frame, 4); - - lerp( mem_syn_r + L_SYN_MEM - mem_syn_r_size_old, mem_syn_r + L_SYN_MEM - mem_syn_r_size_new, mem_syn_r_size_new, mem_syn_r_size_old ); - - Copy( mem_syn_r+L_SYN_MEM-M, mem_syn2, M ); - - IF( mem_syn != NULL ) - { - Copy( mem_syn2, mem_syn, M ); - } - -} - - diff --git a/src/libs/libevs/lib_com/tcq_position_arith.cpp b/src/libs/libevs/lib_com/tcq_position_arith.cpp new file mode 100644 index 00000000..78845d4f --- /dev/null +++ b/src/libs/libevs/lib_com/tcq_position_arith.cpp @@ -0,0 +1,2016 @@ +/*==================================================================================== + EVS Codec 3GPP TS26.443 Nov 13, 2018. Version 12.11.0 / 13.7.0 / 14.3.0 / 15.1.0 + ====================================================================================*/ + +#include +#include +#include +#include +#include "options.h" +#include "prot.h" +#include "rom_com.h" +#include "basop_util.h" +#include "basop_proto_func.h" + +void bitstream_save_bit(PBITSTREAM pBS, int bit); +unsigned int bitstream_load_bit(PBITSTREAM pBS); +void bitstream_rollback(PBITSTREAM pBS, int numBits); + + +static int ar_make_model( const short *freq, short *model, int len ); +static int ar_decode( PARCODEC arInst, const short *model ); +static void ar_encode( PARCODEC arInst, const short *model, int symbol ); +static void ar_encode_uniform( PARCODEC arInst, unsigned int data, int bits ); + + +/* 32x16 multiply: */ +Word32 Mult_32_16(Word32 a, Word16 b) +{ + Word32 result; + UWord16 lo; + /* use Mpy_32_16_ss(): */ + Mpy_32_16_ss(a, b, &result, &lo); + return result; +} + +/* 32x32 multiply: */ +Word32 Mult_32_32(Word32 a, Word32 b) +{ + Word32 result; + UWord32 lo; + /* use Mpy_32_32_ss(): */ + Mpy_32_32_ss(a, b, &result, &lo); + return result; +} + +static +void set16_fx( + Word16 y[], /* i/o: Vector to set */ + const Word16 a, /* i : Value to set the vector to */ + const Word16 N /* i : Lenght of the vector */ +) +{ + Word16 i; + + for (i=0 ; i= 0) + { + num = L_shl(num, 1); + varout = L_add(varout, 1); + } + else + { + num = L_add(num, denum); + num = L_shl(num, 1); + } + } + } + + if( sign != 0) + { + varout = L_negate(varout); + } + + return varout; +} + +void srt_vec_ind_fx ( + const Word32 *linear, /* linear input */ + Word32 *srt, /* sorted output*/ + Word16 *I, /* index for sorted output */ + Word16 length +) +{ + Word16 pos,npos; + Word16 idxMem; + Word32 valMem; + + /*initilize */ + for (pos = 0; pos < length; pos++) + { + I[pos] = pos; + } + + for( pos = 0; pos < length; pos++ ) + { + srt[pos] = linear[pos]; + } + + /* now iterate */ + for (pos = 0; pos < (length - 1); pos++) + { + for (npos = (pos + 1); npos < length; npos++) + { + if (L_sub(srt[npos], srt[pos]) < 0) + { + idxMem = I[pos]; + I[pos] = I[npos]; + I[npos] = idxMem; + + valMem = srt[pos]; + srt[pos] = srt[npos]; + srt[npos] = valMem; + } + } + } + + return; +} + +static Word32 GetBitsFromPulses_fx(Word16 m, Word16 n) +{ + Word16 i, integer_fx, temp_fx1, temp_fx2, exp1, exp2; + Word32 temp32; + Word32 frac_fx32; + Word32 logCoeff_fx; + Word16 exp = 0; + Word32 mantissa_fx = 0; + + if (m == 0) + { + return 0; + } + + for (i = 0; i < min(m, n); i++) + { + logCoeff_fx = L_add(L_shl(i + 1, 16), L_sub(table_logcum_fx[n+1], L_add(table_logcum_fx[i + 2], table_logcum_fx[n - i]))); + logCoeff_fx = L_add(logCoeff_fx, L_sub(table_logcum_fx[m], L_add(table_logcum_fx[i + 1], table_logcum_fx[m - i])));/*Q16 */ + + integer_fx = extract_h(logCoeff_fx);/*Q0 */ + frac_fx32 = L_sub(logCoeff_fx, L_shl(integer_fx, 16));/*Q16 */ + + /*ln2, 0.987, ln2 * ln2, 0.977 */ + /*temp1 = (int) (frac / 0.0625); */ + /*temp2 = frac - (float)temp1 * 0.0625f; */ + + /* frac = pow(2.0, temp1 * 0.0625) * (1 + 0.693 * temp2 + 0.480 * temp2 * temp2 * 0.5);*/ + /*frac = pow_getbitsfrompulses[temp1] * (1 + 0.693f * temp2 + 0.480f * temp2 * temp2 * 0.5f); */ + + temp_fx1 = extract_h(L_shl(frac_fx32, 4)); + temp_fx2 = extract_l(L_and(frac_fx32, 0xfff));/*Q16 */ + + frac_fx32 =L_add(L_mult(temp_fx2, 22708), Mult_32_16(L_mult0(temp_fx2, temp_fx2), 7864));/*Q32 */ + frac_fx32 = L_add(0x40000000, L_shr(frac_fx32, 2));/*30 */ + + exp1 = norm_l(pow_getbitsfrompulses_fx[temp_fx1]); + exp2 = norm_l(frac_fx32); + frac_fx32 = Mult_32_32(L_shl(pow_getbitsfrompulses_fx[temp_fx1], exp1), L_shl(frac_fx32, exp2));/*21 + exp1 + 30 + exp2 - 31 */ + frac_fx32 = L_shr(frac_fx32, exp1 + exp2) + 1;/*20 */ + + if (sub(exp, integer_fx) < 0) + { + mantissa_fx = L_shr(mantissa_fx, sub(integer_fx, exp)); + mantissa_fx = L_add(mantissa_fx, frac_fx32); + + exp = integer_fx; + } + else + { + mantissa_fx = L_add(mantissa_fx, L_shr(frac_fx32, sub(exp, integer_fx))); + } + if (L_sub(mantissa_fx, 0x200000) >= 0) + { + exp++; + + mantissa_fx = L_shr(mantissa_fx, 1); + } + } + + mantissa_fx = L_shl(mantissa_fx, 2);/*22 */ + temp_fx1 = extract_h(mantissa_fx); + temp32 = L_shl(L_sub(mantissa_fx, L_deposit_h(temp_fx1)), 15);/*31 */ + exp1 = sub(norm_l(temp32), 1); + temp32 = ar_div(L_shl(temp32, exp1), temp_fx1); /*31 + exp1 */ + temp32 = L_shr(temp32, exp1 + 1);/*30 */ + + frac_fx32 = L_sub(0x40000000, L_shr(temp32, 1));/*30 */ + frac_fx32 = Mult_32_32(frac_fx32, temp32);/*29 */ + frac_fx32 = L_shr(frac_fx32, 13);/*16 */ + exp1 = norm_l(temp_fx1); + temp_fx1 = Log2_norm_lc(L_shl(temp_fx1, exp1));/*15 */ + frac_fx32 = frac_fx32 + Mult_32_32(frac_fx32, 950680361); /* frac_fx32 *= 1/ln(2) */ + return L_add(L_deposit_h(exp), L_add(L_shl(temp_fx1, 1), frac_fx32)); +} + +void decode_position_ari_fx(PARCODEC pardec, Word16 size, Word16 npulses, Word16* nz, Word32* position) +{ + Word16 i, nzp; + Word16 mode_num_nz[TCQ_MAX_BAND_SIZE]; + Word16 prob[TCQ_MAX_BAND_SIZE]; + + Word32 btcq_fx, pnzp_fx; + Word16 integer, frac; + + Word32 cp, scp, fxone, fxp1; + Word16 stpos = 0, pos, ovrflag, temppos, storepos; + + fxone = 32768; + fxp1 = 512*32768; + temppos = 0; + storepos = 0; + ovrflag = 0; + + + set16_fx( mode_num_nz, 0, TCQ_MAX_BAND_SIZE ); + set16_fx( prob, 0, TCQ_MAX_BAND_SIZE ); + + for (i = 0; i < size; i++) + { + position[i] = 0; + } + + if (L_sub(npulses, 1) > 0) + { + btcq_fx = GetBitsFromPulses_fx(npulses, size); + for (i = 0; i < L_min(npulses, size); i++) + { + /*calculate the probability of #nz */ + + pnzp_fx = L_sub(L_deposit_h(add(i, 1)), btcq_fx); + pnzp_fx = L_add(pnzp_fx, L_add(L_sub(table_logcum_fx[size + 1], L_add(table_logcum_fx[i + 2], table_logcum_fx[size - i])), + L_sub(table_logcum_fx[npulses], L_add(table_logcum_fx[i + 1], table_logcum_fx[npulses - i])))); + pnzp_fx = L_add(pnzp_fx, 917498);/*16 */ + if( L_sub( pnzp_fx, 0) > 0) + { + integer = extract_h(pnzp_fx); + frac = extract_l(L_shr(L_sub(pnzp_fx, L_deposit_h(integer)), 1));/*15 */ + prob[i] = extract_h(L_shl(Pow2(integer, frac), 16));/*0 */ + if (prob[i] == 0) + { + prob[i] = 1; + } + } + else + { + prob[i] = 1; + } + } + + ar_make_model(prob, mode_num_nz, min(npulses, size)); + *nz = add(1, ar_decode(pardec, mode_num_nz));/*get #nz */ + nzp = *nz; + + if( nzp == 1 ) + { + mode_num_nz[0] = MAX_AR_FREQ; + for (i = 0; i < size; i ++) + { + mode_num_nz[i+1] = round_fx( L_shr( L_deposit_h( div_l( L_deposit_h(size - i - 1), size)), 1) ); + } + + position[ ar_decode(pardec, mode_num_nz) ] = 1; + } + else + { + mode_num_nz[0] = MAX_AR_FREQ; + + for( ; nzp > 0; nzp-- ) + { + scp = fxp1; + temppos = 0; + storepos = 0; + + for( i = stpos; i < size; i++) + { + ovrflag = 0; + + if( nzp == (size - i) ) + { + cp = 0; + } + else + { + cp = L_sub( fxone, div_l( L_deposit_h(nzp), (size - i)) ); + } + scp = Mult_32_16( scp, extract_l(cp) ); + mode_num_nz[i+1-storepos-stpos] = round_fx( L_shl( scp, 6) ); + + if( (mode_num_nz[i+1-storepos-stpos] == 0 && scp > 0) || mode_num_nz[i-storepos-stpos] == mode_num_nz[i+1-storepos-stpos] ) + { + ovrflag = 1; + temppos = ar_decode(pardec, mode_num_nz); + storepos += temppos; + scp = fxp1; + + if( temppos == i-stpos) /* esc transmitted */ + { + i--; + } + else + { + break; + } + } + } + if( !ovrflag ) + { + pos = ar_decode(pardec, mode_num_nz) + storepos; + } + else + { + pos = storepos; + } + + position[ stpos + pos] = 1; + stpos += pos + 1; + } + } + + } + else if (L_sub(npulses, 1) == 0) + { + *nz = npulses; + nzp = *nz; + mode_num_nz[0] = MAX_AR_FREQ; + for (i = 0; i < size; i ++) + { + mode_num_nz[i+1] = round_fx( L_shr( L_deposit_h( div_l( L_deposit_h(size - i - 1), size)), 1) ); + } + + position[ ar_decode(pardec, mode_num_nz) ] = 1; + } + else + { + *nz = 0; + } + + return; +} +void decode_magnitude_usq_fx(ARCODEC* pardec, Word16 size, Word16 npulses, Word16 nzpos, Word32* positions, Word32* out) +{ + Word16 i, magnp, magnzp; + Word16 magns[TCQ_MAX_BAND_SIZE], magncout = 0; + + Word16 storemagn, ovrflag, pos, tempmagn = 0, mmodel[MAX_PULSES+2]; + Word32 cp, scp, fxone, fxp1; + + fxone = 32768; + fxp1 = 512*32768; + ovrflag = 0; + + + set16_fx( magns, 1, TCQ_MAX_BAND_SIZE ); + if (sub(nzpos, npulses) == 0) + { + for (i = 0; i < size; i++) + { + out[i] = positions[i]; + } + return; + } + else if (sub(nzpos, 1) == 0) + { + for (i = 0; i < size; i++) + { + if ( positions[i] != 0 ) + { + out[i] = npulses; + return; + } + } + } + + magnzp = sub(nzpos, 1); + magnp = sub(npulses, 1); + + magncout = 0; + + set32_fx( out, 0, size ); + set16_fx( mmodel, 0, MAX_PULSES+2 ); + + mmodel[0] = MAX_AR_FREQ; + magncout = 0; + for( pos = 0; pos < size; pos++) + { + scp = fxp1; + if( positions[pos] != 0) + { + storemagn = 0; + + for( i = 0; i < magnp; i++) + { + ovrflag = 0; + + if( magnzp == (magnp-i) ) + { + cp = 0; + } + else + { + cp = L_sub( fxone, div_l( L_deposit_h(magnzp), magnp-i) ); + } + + if( cp == fxone ) + { + break; + } + + scp = Mult_32_16( scp, extract_l(cp) ); + mmodel[i+1-storemagn] = round_fx( L_shl( scp, 6) ); + + if( (mmodel[i+1- storemagn] == 0 && scp > 0) || mmodel[i- storemagn] == mmodel[i+1- storemagn] ) + { + mmodel[i+1-storemagn] = 0; + /* read data */ + tempmagn = ar_decode( pardec, mmodel ); + storemagn += tempmagn; + + if( tempmagn < i ) + { + /* just magnitude */ + ovrflag = 1; + break; + } + else + { + /* esc code */ + scp = fxp1; + i--; + } + } + } + + if( ovrflag ) + { + out[magncout] = storemagn + 1; + } + else + { + out[magncout] = ar_decode( pardec, mmodel ) + storemagn + 1; + } + magnp -= out[magncout]; + magnzp--; + magncout++; + + if (magnzp == 0) /* last magnitude generation */ + { + for( pos = pos+1; pos < size; pos++) + { + if( positions[pos] != 0) + { + out[magncout] = magnp + 1; + return; + } + else + { + out[magncout] = 0; + magncout++; + } + } + } + else if(magnzp == magnp) /* rest magnitudes generation */ + { + for( pos = pos+1; pos < size; pos++) + { + out[magncout] = positions[pos]; + magncout++; + } + return; + } + } + else + { + out[magncout] = 0; + magncout++; + } + } + + return; +} + +static Word16 quantize_fx( Word16 val, Word16 D) +{ + Word16 qval4_fx; + Word16 retval_fx; + + qval4_fx = shr(abs_s(add(val, 512)), 12); + retval_fx = add(shl(qval4_fx, 2), DDP_fx[D]); + /* 2nd zero check */ + if (D == 0) + { + if (sub(abs_s(sub(shl(abs_s(retval_fx), 10), abs_s(val))), abs_s(val)) > 0) + { + retval_fx = 0; + } + } + return retval_fx; +} + +void decode_mangitude_tcq_fx(ARCODEC* pardec, Word16 size, Word16 npulses, Word16 nzpos, Word32* positions, Word32* out, Word32* surplus_fx) +{ + Word32 tcq_bits_fx, bits_fx/*, surplus_fx*/; + Word16 prob0_fx, prob1_fx, num, denum, quantum1_fx, quantum2_fx; + Word16 exp, exp1, exp2, tmp16; + Word32 tmp32; + + Word16 i, j, symbol, st; + Word16 leftp = npulses;/*pulsesnum; */ + Word16 leftnz = nzpos; /*nzpos; */ + Word16 magn_mode[3] = {MAX_AR_FREQ, 0, 0}; + + bits_fx = 0; + tcq_bits_fx = L_sub(table_logcum_fx[npulses], L_add(table_logcum_fx[nzpos], table_logcum_fx[npulses - (nzpos - 1)])); + + if (sub(nzpos, npulses) == 0) + { + for (i = 0; i < size; i++) + { + out[i] = positions[i]; + } + + return; + } + else if (sub(nzpos, 1) == 0) + { + for (i = 0; i < size; i++) + { + if ( positions[i] != 0 ) + { + out[i] = npulses; + return; + } + } + } + st = 0; + for (i = 0; i < size && leftnz > 1; i++) + { + out[i] = positions[i]; + if (positions[i] != 0) + { + /*generate the trellis path */ + symbol = 0; + for (j = 0; j < leftp; j++) + { + num = sub(leftnz, 1); + denum = sub(leftp, add(j, 1)); + if (sub(num, denum) >= 0) + { + prob1_fx = MAX_16; + prob0_fx = 0; + } + else + { + exp1 = sub(norm_s(num), 1); + exp2 = norm_s(denum); + prob1_fx = div_s(shl(num, exp1), shl(denum, exp2));/*15 + exp1 - exp2 */ + exp = 15 + exp1 - exp2; + prob1_fx = shl(prob1_fx, sub(15, exp)); + prob0_fx = sub(MAX_16, prob1_fx); + } + if (L_sub(sub(leftp, j), leftnz) == 0) + { + symbol = add(j, 1); + break; + } + + quantum1_fx = quantize_fx(shl(add(j, 1), 10), ddec[st][0]); + quantum2_fx = quantize_fx(shl(add(j, 1), 10), ddec[st][1]); + + if (sub(quantum1_fx, add(j, 1)) != 0 && sub(quantum2_fx, add(j, 1)) != 0) + { + prob0_fx = MAX_16; + move16(); + prob1_fx = 0; + move16(); + } + if (sub(prob0_fx, MAX_16) == 0 || sub(prob1_fx, MAX_16) == 0) + { + symbol = add(j, 1); + continue; + } + + /*magn_mode[1] = (short)(prob1 * MAX_AR_FREQ); */ + magn_mode[1] = mult(prob1_fx, MAX_AR_FREQ); + + if (ar_decode(pardec, magn_mode)) + { + exp1 = norm_s(prob1_fx); + tmp32 = L_deposit_h(shl(prob1_fx, exp1));/*exp1 + 15 + 16 */ + tmp16 = Log2_norm_lc(tmp32);/*15 */ + bits_fx = L_sub(bits_fx, L_sub(tmp16, L_shl(add(exp1, 1), 15)));/*15 */ + + symbol = add(j, 1); + break; + } + else + { + exp1 = norm_s(prob0_fx); + tmp32 = L_deposit_h(shl(prob0_fx, exp1));/*exp1 + 15 + 16 */ + tmp16 = Log2_norm_lc(tmp32);/*15 */ + bits_fx = L_sub(bits_fx, L_sub(tmp16, L_shl(add(exp1, 1), 15)));/*15 */ + } + } + out[i] = symbol; + /*leftp -= symbol; */ + leftp = sub(leftp, symbol); + leftnz--; + } + + quantum1_fx = quantize_fx(out[i], ddec[st][0]); + quantum2_fx = quantize_fx(out[i], ddec[st][1]); + + /*generate the next state */ + if (sub(quantum1_fx, out[i]) == 0) + { + st = nextstate[st][0]; + } + else + { + st = nextstate[st][1]; + } + } + + /*generate the magnitudes */ + for (; i < size; i++) + { + out[i] = 0; + if (positions[i] != 0) + { + out[i] = add(sub(leftp, leftnz), 1); + } + + } + + if (sub(nzpos, npulses) != 0 && sub(nzpos, 1) > 0) + { + /*update the surplus */ + *surplus_fx = L_add(*surplus_fx, L_sub(tcq_bits_fx, L_shl(bits_fx, 1))); + } + + return; +} + +Word16 GetScale_fx( Word16 blen, Word32 bits_fx/*Q16*/, Word32 *surplus_fx/*Q16*/) +{ + Word16 pulses = MAX_PULSES, p_est, exp, exp1, exp2, magicnum; + Word32 t, a, b, ab, estbits_fx = 0; + + magicnum = 24773; /*Q17: 0.188992013101951f; */ + + t = L_shr( L_mult( magicnum, blen), 2); + exp = norm_l(t); + a = L_shl( 14 - exp, 15) + Log2_norm_lc( L_shl( t, exp ) ); + + exp1 = sub( norm_l(bits_fx), 1); + exp2 = norm_s( blen - 1 ); + b = L_shr( L_deposit_l( div_l( L_shl( bits_fx, exp1), shl( blen - 1, exp2) ) ), exp1-exp2 ); + + ab = L_add( a, b); + + p_est = extract_h(L_shl(Pow2( extract_l( L_shr(ab,15) ), ab&0x7FFF ),16)); /* enable saturation of pow2 result */ + + pulses = min( p_est, MAX_PULSES ); + + for( ; pulses >= 0; pulses--) + { + estbits_fx = GetBitsFromPulses_fx( pulses, blen); + if( L_sub( bits_fx, estbits_fx) >= 0) + { + break; + } + } + + if ( surplus_fx != 0 ) + { + *surplus_fx = L_add(*surplus_fx, L_sub(bits_fx, estbits_fx)); + } + + return pulses; +} + +void decode_signs_fx(ARCODEC* pardec, Word16 size, Word32* out) +{ + Word16 i; + + for ( i = 0; i < size; i++) + { + if ( out[i] != 0 ) + { + out[i] = ( ar_decode( pardec, uniform_model ) > 0) ? out[i] : -out[i]; + } + } + + return; +} + +Word32 encode_position_ari_fx(PARCODEC parenc, float* quants, Word16 size, Word32* est_bits_frame_fx) +{ + Word16 i; + Word16 nz = 0, pulses = 0; + Word16 prob[TCQ_MAX_BAND_SIZE]; + Word16 model_num_nz[TCQ_MAX_BAND_SIZE]; + float *cur_quants = quants; + Word16 integer, frac; + Word32 /*est_bits_frame_fx, */btcq_fx = 0, bits_fx = 0, pnzp_fx; + Word32 cp, scp, fxone, fxp1; + Word16 pos; + + fxone = 32768; + fxp1 = 512*32768; + + set16_fx( prob, 0, TCQ_MAX_BAND_SIZE ); + set16_fx( model_num_nz, 0, TCQ_MAX_BAND_SIZE ); + + for (i = 0; i < size; i ++) + { + pulses = add(pulses, abs_s((short)cur_quants[i])); + if (cur_quants[i] != 0) + { + nz++; + } + } + + btcq_fx = GetBitsFromPulses_fx(pulses, size); + /* Estimate TCQ bits */ + bits_fx = L_sub(table_logcum_fx[size + 1], L_add(table_logcum_fx[nz + 1], table_logcum_fx[size - nz + 1])); + bits_fx = L_add(bits_fx, L_sub(btcq_fx, L_sub(table_logcum_fx[size + 1], L_add(table_logcum_fx[nz + 1], table_logcum_fx[size - nz + 1])))); + bits_fx = L_sub(bits_fx, L_sub(table_logcum_fx[pulses], L_add(table_logcum_fx[nz], table_logcum_fx[pulses - (nz - 1)]))); + + bits_fx = L_sub(bits_fx, nz); + *est_bits_frame_fx = L_add(*est_bits_frame_fx, bits_fx); + + /*caculate the #nz probability */ + for (i = 0; i < min(pulses, size); i++) + { + pnzp_fx = L_sub(L_deposit_h(add(i, 1)), btcq_fx); + + pnzp_fx = L_add(pnzp_fx, L_add(L_sub(table_logcum_fx[size + 1], L_add(table_logcum_fx[i + 2], table_logcum_fx[size - i])), + L_sub(table_logcum_fx[pulses], L_add(table_logcum_fx[i + 1], table_logcum_fx[pulses - i])))); + pnzp_fx = L_add(pnzp_fx, 917498);/*16 */ + if( L_sub( pnzp_fx, 0) > 0) + { + integer = extract_h(pnzp_fx); + frac = extract_l(L_shr(L_sub(pnzp_fx, L_deposit_h(integer)), 1));/*15 */ + prob[i] = extract_h(L_shl(Pow2(integer, frac), 16));/*0 */ + + /*zero probability will incur problems in ar_make_model() */ + if (prob[i] == 0) + { + prob[i] = 1; + } + } + else + { + prob[i] = 1; + } + } + + ar_make_model(prob, model_num_nz, min(pulses, size)); + + if (sub(nz, 1) > 0) + { + ar_encode( parenc, model_num_nz, nz - 1);/*encode #nz */ + + scp = fxp1; + pos = 0; + for( i = 0; i < size && nz > 0; i++) + { + if( nz == (size - i) ) + { + cp = 0; + } + else + { + cp = L_sub( fxone, div_l( L_deposit_h(nz), (size - i)) ); + } + scp = Mult_32_16( scp, extract_l(cp) ); + model_num_nz[pos+1] = round_fx( L_shl( scp, 6) ); + + if( (model_num_nz[pos+1] == 0 && scp > 0) || model_num_nz[pos] == model_num_nz[pos+1] ) + { + model_num_nz[pos+1] = 0; + ar_encode( parenc, model_num_nz, pos ); + i--; + scp = fxp1; + pos = 0; + continue; + } + + if( cur_quants[i] != 0 ) + { + ar_encode( parenc, model_num_nz, pos ); + pos = 0; + scp = fxp1; + nz--; + } + else + { + pos++; + } + } + } + else if (sub(nz, 1) == 0) + { + if (sub(pulses, 1) > 0) + { + /*temp -= log2_f((float)(model_num_nz[nz-1] - model_num_nz[nz]) / MAX_AR_FREQ); */ + ar_encode(parenc, model_num_nz, 0);/*encode #nz */ + } + + pos = 0; + for( i = 0; i < size; i++) + { + model_num_nz[i+1] = round_fx( L_shr( L_deposit_h( div_l( L_deposit_h(size - i - 1), size)), 1) ); + + if( cur_quants[i] != 0 ) + { + pos = i; + } + } + ar_encode( parenc, model_num_nz, pos ); /* encode pos */ + } + return bits_fx; +} + +Word32 encode_magnitude_tcq_fx(ARCODEC* parenc, float* magn_fx, Word16 size, Word16 npulses, Word16 nzpos, Word32* savedstates, Word32* est_frame_bits_fx) +{ + Word32 tcq_bits_fx, bits_fx/*, est_frame_bits_fx*/; + Word16 prob0_fx, prob1_fx, num, denum, quantum1_fx, quantum2_fx; + Word16 exp, exp1, exp2; + + Word16 i, j; + Word32 st; + Word16 magn_mode[3] = {MAX_AR_FREQ, 0, 0}; + + Word16 leftp = npulses;/*pulsesnum; */ + Word16 leftnz = nzpos;/*nzpos; */ + + bits_fx = 0; + + tcq_bits_fx = L_sub(table_logcum_fx[npulses], L_add(table_logcum_fx[nzpos], table_logcum_fx[npulses - (nzpos - 1)])); + + *est_frame_bits_fx = L_add(*est_frame_bits_fx, tcq_bits_fx); + + if (sub(nzpos, npulses) == 0 || sub(nzpos, 1) == 0) + { + return bits_fx; + } + + st = 0; + for ( i = 0; i < size && leftnz > 1; i++) + { + st = savedstates[i]; + if (magn_fx[i] != 0) + { + for ( j = 0; j < leftp; j++) + { + /*calculate the two path probs point to next two states */ + num = sub(leftnz, 1); + denum = sub(leftp, add(j, 0x1)); + if (sub(num, denum) >= 0) + { + prob1_fx = MAX_16; + prob0_fx = 0; + } + else + { + exp1 = sub(norm_s(num), 1); + exp2 = norm_s(denum); + prob1_fx = div_s(shl(num, exp1), shl(denum, exp2));/*15 + exp1 - exp2 */ + exp = 15 + exp1 - exp2; + prob1_fx = shl(prob1_fx, sub(15, exp)); + prob0_fx = sub(MAX_16, prob1_fx); + } + + quantum1_fx = quantize_fx(shl(add(j, 1), 10), ddec[st][0]); + quantum2_fx = quantize_fx(shl(add(j, 1), 10), ddec[st][1]); + + if (sub(quantum1_fx, add(j, 1)) != 0 && sub(quantum2_fx, add(j, 1)) != 0) + { + prob0_fx = MAX_16; + prob1_fx = 0; + } + if (sub(prob0_fx, MAX_16) == 0 || sub(prob1_fx, MAX_16) == 0) + { + continue; + } + + magn_mode[1] = mult(prob1_fx, MAX_AR_FREQ); + if (sub(j, sub(abs_s( (short)magn_fx[i] ), 1)) < 0) + { + ar_encode(parenc, magn_mode, 0); + } + else + { + if (sub(leftp, j) > leftnz) + { + ar_encode(parenc, magn_mode, 1); + } + break; + } + } + + leftnz--; + leftp = sub(leftp, abs_s( (short)magn_fx[i] )); + } + } + + return bits_fx; +} + +Word32 encode_signs_fx(ARCODEC* parenc, float* magn, Word16 size, Word16 npos, Word32* est_frame_bits_fx) +{ + Word32 i, sign; + + *est_frame_bits_fx = L_add(*est_frame_bits_fx, L_deposit_h(npos)); + for (i = 0; i < size; i++) + { + if (magn[i] != 0) + { + sign = (magn[i] > 0) ? 1 : 0; + ar_encode_uniform(parenc, sign, 1); + } + } + + return L_deposit_h(npos); +} + +Word32 encode_magnitude_usq_fx(ARCODEC* parenc, float* magn_fx, Word16 size, Word16 npulses, Word16 nzpos, Word32* est_frame_bits_fx) +{ + Word16 i, j, k, magnp, magnzp; + Word16 magn_position[MAX_PULSES]; + Word32 /*est_frame_bits_fx, */bits_fx; + + Word16 pos, model_m[MAX_PULSES + 2]; + Word32 fxone, fxp1, cp, scp; + + fxone = 32768; + fxp1 = 512*32768; + + /*estimate fac bits */ + bits_fx = L_sub(table_logcum_fx[npulses], L_add(table_logcum_fx[nzpos], table_logcum_fx[npulses - nzpos + 1])); + + *est_frame_bits_fx = L_add(*est_frame_bits_fx, bits_fx); + + if (sub(npulses, nzpos) == 0 || sub(nzpos, 1) == 0) + { + return bits_fx; + } + magnp = sub(npulses, 1); + magnzp = sub(nzpos, 1); + + /*generate the binary sequences of magnitudes */ + k = 0; + for (i = 0; i < size; i++) + { + if (magn_fx[i] != 0) + { + for (j = 0; j < abs_s((short)magn_fx[i]) - 1; j++) + { + magn_position[k++] = 0; + } + magn_position[k++] = 1; + } + } + + set16_fx( model_m, 0, MAX_PULSES + 2); + scp = fxp1; + model_m[0] = MAX_AR_FREQ; + pos = 0; + for( i = 0; i < npulses-1 && magnzp > 0; i++ ) + { + if( magnzp == magnp ) + { + cp = 0; + } + else + { + cp = L_sub( fxone, div_l( L_deposit_h(magnzp), magnp) ); + } + scp = Mult_32_16( scp, extract_l(cp) ); + model_m[pos+1] = round_fx( L_shl( scp, 6) ); + + if( (model_m[pos+1] == 0 && scp > 0) || model_m[pos] == model_m[pos+1] ) + { + model_m[pos+1] = 0; + + ar_encode( parenc, model_m, pos ); + pos = 0; + i--; + scp = fxp1; + continue; + } + + if( magn_position[i] != 0 ) + { + ar_encode( parenc, model_m, pos ); + pos = 0; + magnzp--; + scp = fxp1; + } + else + { + pos++; + } + + magnp--; + } + return bits_fx; +} + + +static void transmission_bits( PARCODEC arInst, int bit ) +{ + bitstream_save_bit( arInst->bsInst, bit ); + arInst->num_bits++; + bit = !bit; + + for( ; arInst->bits_to_follow > 0 && arInst->num_bits < arInst->max_bits; arInst->bits_to_follow --) + { + bitstream_save_bit( arInst->bsInst, bit ); + arInst->num_bits++; + } + + return; +} + +void ar_encoder_start( PARCODEC arInst, PBITSTREAM bsInst, int max_bits + ) +{ + arInst->bsInst = bsInst; + + arInst->low = 0; + arInst->high = AR_TOP; + arInst->bits_to_follow = 0; + + arInst->num_bits = 0; + arInst->max_bits = max_bits; +} + + +static void ar_encode( PARCODEC arInst, const short *model, int symbol ) +{ + unsigned int range, high, low; + + high = arInst->high; + low = arInst->low; + + symbol ++; + range = high - low + 1; + + high = low + ( range * model[symbol - 1]) / model[0] - 1; + low = low + ( range * model[symbol] ) / model[0]; + + for( ; ; ) + { + if( high < AR_HALF ) + { + transmission_bits( arInst, 0 ); + } + else + { + if( low >= AR_HALF ) + { + transmission_bits( arInst, 1 ); + + low -= AR_HALF; + high -= AR_HALF; + } + else + { + if( low >= AR_FIRST && high < AR_THIRD ) + { + arInst->bits_to_follow ++; + + low -= AR_FIRST; + high -= AR_FIRST; + } + else + { + break; + } + } + } + + low = low << 1; + high = ( high << 1 ) + 1; + } + + arInst->high = high; + arInst->low = low; + + return; +} + + +static void ar_encode_uniform( PARCODEC arInst, unsigned int data, int bits ) +{ + int i; + + for( i = 0 ; i < bits ; i ++ ) + { + ar_encode( arInst, uniform_model, data & 0x1 ); + data >>= 1; + } + + return; +} + + +void ar_encoder_done( PARCODEC arInst ) +{ + arInst->bits_to_follow ++; + transmission_bits( arInst, arInst->low >= AR_FIRST ); + + return; +} + + +void ar_decoder_start( PARCODEC arInst, PBITSTREAM bsInst ) +{ + int i; + + arInst->bsInst = bsInst; + + arInst->low = 0; + arInst->high = AR_TOP; + arInst->value = 0; + + for( i = 0; i < AR_BITS ; i ++ ) + { + arInst->value = ( arInst->value << 1 ) + bitstream_load_bit( arInst->bsInst ); + } + + return; +} + + +static int ar_decode( PARCODEC arInst, const short *model ) +{ + unsigned int range; + short cum; + int symbol; + + range = (unsigned int)( arInst->high - arInst->low ) + 1; + cum = (short)( ( ( (unsigned int)( arInst->value - arInst->low ) + 1 ) * model[0] - 1 ) / range ); + + for( symbol = 1 ; model[symbol] > cum ; symbol ++ ); + + arInst->high = arInst->low + ( range * model[symbol - 1] ) / model[0] - 1; + arInst->low = arInst->low + ( range * model[symbol] ) / model[0]; + + for( ; ; ) + { + if( arInst->high >= AR_HALF ) + { + if( arInst->low >= AR_HALF) + { + arInst->value -= AR_HALF; + arInst->low -= AR_HALF; + arInst->high -= AR_HALF; + } + else + { + if( arInst->low >= AR_FIRST && arInst->high < AR_THIRD ) + { + arInst->value -= AR_FIRST; + arInst->low -= AR_FIRST; + arInst->high -= AR_FIRST; + } + else + { + break; + } + } + } + arInst->low <<= 1; + arInst->high = ( arInst->high << 1 ) + 1; + arInst->value = ( arInst->value << 1 ) + bitstream_load_bit( arInst->bsInst ); + } + + return (symbol - 1); +} + +void ar_decoder_done( PARCODEC arInst ) +{ + bitstream_rollback( arInst->bsInst, AR_BITS - 2 ); + + return; +} + + +static int ar_make_model( const short *freq, short *model, int len ) +{ + short dist; + unsigned int sum = 0; + unsigned int cum = 0; + int i; + + for( i = 0 ; i < len ; i ++ ) + { + sum += freq[i]; + } + + if( sum == 0 ) + { + return 0; + } + + for( i = len ; ; i -- ) + { + model[i] = (short)( ( cum * MAX_AR_FREQ ) / sum ); + + if( !i ) + { + break; + } + + cum += freq[i - 1]; + } + + + for( i = 0 ; i < len - 1 ; i ++ ) + { + dist = model[i] - model[i + 1]; + + if( dist <= 0 ) + { + model[i + 1] += dist - 1; + } + } + + for( i = len ; i ; i -- ) + { + dist = model[i - 1] - model[i]; + + if( dist <= 0 ) + { + model[i - 1] -= dist - 1; + } + } + + return (model[0] > model[1]); +} + +void bitstream_save_bit(PBITSTREAM pBS, int bit) +{ + unsigned char cur; + + cur = pBS->buf[pBS->numByte]; + + + cur = (unsigned char)(cur | (bit << pBS->curPos--)); + pBS->buf[pBS->numByte] = cur; + pBS->numbits++; + + if (pBS->curPos < 0) + { + pBS->curPos = 7; + pBS->numByte++; + } + + return; +} + + +unsigned int bitstream_load_bit(PBITSTREAM pBS) +{ + unsigned int bit; + signed char * curPos; + + /* safety check in case of bit errors */ + if( pBS->numByte >= pBS->maxBytes ) + { + return 0; + } + + curPos = &pBS->curPos; + bit = (( pBS->buf[pBS->numByte] >> (*curPos)--) & 0x00000001); + + if (*curPos < 0) + { + pBS->numByte++; + *curPos = 7; + } + + return bit; +} + + +void bitstream_rollback(PBITSTREAM pBS, int numBits) +{ + + while (numBits > 0) + { + pBS->curPos++; + pBS->numbits--; + if (pBS->curPos == 8) + { + pBS->curPos = 0; + pBS->numByte--; + } + numBits--; + } + + return; +} + + +static float quantize( float val, int D) +{ + int qval4; + float retval;/* = qval4*4.0f + DD[D]; */ + + qval4 = (int)fabs( (val + 0.5)/4.0 ); + retval = qval4*4.0f + DDP[D]; + + /* 2nd zero check */ + if( D == 0 ) + { + if( fabs( fabs(retval) - fabs( val ) ) > fabs( val ) ) + { + retval = 0; + } + } + + return retval; +} + + +static void TCQnew( float *v, float scale, int length, float *vout, int pulses, int *pulsesout, int* nzposout, int *savedstates, int * lasttrellislevel, int terminate) +{ + short i, st, dminpos, position, pulsesnum, nzpos = 0; + float dmin, quantum1, quantum2, curdist1, curdist2, newdist1, newdist2, signq; + + float metric[STATES][TCQ_MAX_BAND_SIZE]; + short path[STATES][TCQ_MAX_BAND_SIZE]; + short quant[STATES][TCQ_MAX_BAND_SIZE]; + short pused[STATES][TCQ_MAX_BAND_SIZE]; + + set_f( *metric, 0.0f, STATES*TCQ_MAX_BAND_SIZE ); + set_s( *path, 0, STATES*TCQ_MAX_BAND_SIZE ); + set_s( *quant, 0, STATES*TCQ_MAX_BAND_SIZE ); + set_s( *pused, 0, STATES*TCQ_MAX_BAND_SIZE ); + + /* Initialize metric */ + for( st = 1; st < STATES; st++) + { + metric[st][0] = 1000; + } + for( st = 2; st < STATES; st++) + { + metric[st][1] = 1000; + } + for( st = 4; st < STATES; st++) + { + metric[st][2] = 1000; + } + + /* Viterbi for input sequence */ + for( i = 0; i < length; i++) /* cycle over symbols */ + { + for( st = 0; st < STATES; st++) /* cycle over conditions */ + { + curdist1 = metric[ step_tcq[st][0]][i]; + curdist2 = metric[ step_tcq[st][1]][i]; + + /* step 1 */ + quantum1 = quantize( v[i]*scale, denc[st][0]); + newdist1 = (float)( quantum1 - fabs(v[i])*scale ); + newdist1 *= newdist1; + + if( quantum1 + pused[ step_tcq[st][0]][i] > pulses && terminate) + { + newdist1 = 10000.0f; /* pulses check */ + } + + /* step 2 */ + quantum2 = quantize( v[i]*scale, denc[st][1]); + newdist2 = (float)( quantum2 - fabs(v[i])*scale ); + newdist2 *= newdist2; + + if( quantum2 + pused[ step_tcq[st][1]][i] > pulses && terminate) + { + newdist2 = 10000.0f; /* pulses check */ + } + + /* decision */ + if( curdist1 + newdist1 < curdist2 + newdist2 ) + { + path[st][i+1] = step_tcq[st][0]; + metric[st][i+1] = curdist1 + newdist1; + quant[st][i+1] = (int)quantize( v[i]*scale, denc[st][0]); + pused[st][i+1] = (int)(pused[ step_tcq[st][0]][i] + abs( quant[st][i+1] )); + } + else + { + path[st][i+1] = step_tcq[st][1]; + metric[st][i+1] = curdist2 + newdist2; + quant[st][i+1] = (int)quantize( v[i]*scale, denc[st][1]); + pused[st][i+1] = (int)(pused[ step_tcq[st][1]][i] + abs( quant[st][i+1] )); + } + } + } + + /* Find path with minimal metric */ + dminpos = 0; + dmin = metric[ dminpos][ length]; + for( i = 1; i < STATES; i++) + { + if( (dmin > metric[ i][ length] && pused[i][ length] == pulses) || + ( pused[dminpos][ length] != pulses && pused[i][ length] == pulses) ) + { + dmin = metric[ i][ length]; + dminpos = i; + } + } + + /* Trace back to get output */ + pulsesnum = 0; + position = dminpos; + + for( i = length; i > 0; i--) + { + signq = ( v[i-1] > 0.0f )?(1.0f):(-1.0f); + vout[i-1] = signq*quant[position][i]; + + position = path[position][i]; + savedstates[i-1] = position; + + /* calculate output pulses number & nz */ + pulsesnum += (int)fabs(vout[i-1]);/*quant[position][i]; */ + if( fabs(vout[i-1]) > 0.0f ) + { + if( nzpos == 0 ) *lasttrellislevel = i; + + nzpos++; + } + } + + if( pulsesout != 0 ) + { + *pulsesout = pulsesnum; + } + if( nzposout != 0 ) + { + *nzposout = nzpos; + } + + return; +} + + +float GetISCScale( float *quants, int size, Word32 bits_fx, float *magn, float *qscale, Word32 *surplus_fx, float *pulses, int* savedstates, + int noTCQ, int *nzpout, short *bcount, float *abuffer, float *mbuffer, float *sbuffer) +{ + float scale, m, t, actualt, magnbits = 0.0f; + int pulsesnum, pos, terminate, leftp, leftnz, trellislevel, st; + int i, j, nzpos, direction, pulsescurr, nzposcurr, lasttrellislevel; + float dist[TCQ_MAX_BAND_SIZE]; + float aquants[TCQ_MAX_BAND_SIZE]; + float dmin, prob0, prob1, quantum1, quantum2; + float sx2 = 0, sy2 = 0, sxy = 0, g; + int pn = 0; + float pt = 0.f; + int diff; + int sign, m_int; + int flag_g1; + + set_f( dist, 0.0f, TCQ_MAX_BAND_SIZE ); + set_f( aquants, 0.0f, TCQ_MAX_BAND_SIZE ); + + if( bits_fx < 0 ) + { + pulsesnum = 0; + + if( surplus_fx != 0 ) + { + *surplus_fx = L_add( *surplus_fx, bits_fx); + } + } + else + { + pulsesnum = GetScale_fx( size, bits_fx, surplus_fx); + } + *nzpout = 0; + + if( pulses != 0 ) + { + *pulses = (float)pulsesnum; + } + + if( pulsesnum > 0 ) + { + /* Initial quantization */ + for( i = 0, m = 0; i < size; i++) + { + aquants[ i] = (float)fabs( quants[i] ); + m += aquants[i]; + } + + scale = (pulsesnum + EPSILON) / (m + EPSILON); + + for( i = 0, t = 0.0f; i < size; i++) + { + magn[i] = (float)((int)( 0.5f + aquants[ i] * scale)); + + t += magn[i]; + } + + /* Pulses redistribution */ + while( t != pulsesnum ) + { + pn = 0; + pt = 0.f; + + + for( i = 0, nzpos = 0; i < size; i++) + { + if( magn[i] > 0.0f ) + { + pn += (int)magn[i]; + pt += aquants[i]; + } + } + + direction = ( pulsesnum - t > 0 )?(1):(-1); + + /* new alg */ + { + for( i = 0; i < size; i++) + { + sxy += aquants[ i]*magn[ i]; + sx2 += aquants[ i]*aquants[ i]; + sy2 += magn[ i]*magn[ i]; + } + for( i = 0; i < size; i++) + { + if( magn[i] > 0.0f ) + { + g = (pt)/(pn + direction + EPSILON); + } + else + { + g = (pt + aquants[ i])/(pn + direction + EPSILON); + } + + dist[i] = sx2 - 2.0f*(sxy + direction*aquants[i])*g + g*g*(sy2 + 2.0f*magn[i]*direction + 1.0f); + } + } + + { + pos = 0; + dmin = dist[0]; + + /* find min */ + for( i = 1; i < size; i++) + { + if( dmin > dist[i] ) + { + pos = i; + dmin = dist[i]; + } + } + + magn[pos] += direction; + t += direction; + } + } + + /* calculate actual nz positions */ + actualt = 0.0f; + for( i = 0, nzpos = 0; i < size; i++) + { + if( magn[i] > 0.0f ) + { + if (quants[i] < 0) + { + magn[i] *= -1; + } + + actualt += aquants[i]; + nzpos++; + } + } + + /* calculate scale */ + if( actualt > 0) + { + scale = pulsesnum / actualt; + } + else + { + scale = FLT_MAX; + } + *qscale = scale; + *nzpout = nzpos; + + if( (nzpos != pulsesnum && nzpos > 1) && noTCQ == 0 ) + { + terminate = 1; + TCQnew( quants, scale, size, magn, pulsesnum, &pulsescurr, &nzposcurr, savedstates, &lasttrellislevel, terminate); + + if( pulsesnum > pulsescurr ) + { + scale *= 1.1f; + } + + if( pulsesnum < pulsescurr ) + { + scale *= 0.9f; + } + if( pulsesnum > pulsescurr ) + { + diff = pulsesnum - pulsescurr; + + for( i = size-1; i >=0; i--) + { + if( fabs(magn[i]) > 0 ) + { + sign = (magn[i]>0)?(1) : (-1); + magn[i] = (float)(sign*( fabs(magn[i]) + diff)); + + break; + } + } + } + else if( pulsesnum < pulsescurr ) + { + diff = pulsescurr - pulsesnum; + + for( i = size-1; i >=0 && diff > 0; i--) + { + if( fabs(magn[i]) > 0 ) + { + sign = (magn[i]>0)?(1) : (-1); + m_int = (int)fabs(magn[i]); + + if( diff < m_int ) + { + magn[i] = (float)(sign*( fabs(magn[i]) - diff)); + break; + } + else + { + diff = diff - m_int; + magn[i] = 0; + nzposcurr--; + } + } + } + } + + pulsescurr = pulsesnum; + + /* Magnitudes coding */ + { + leftp = pulsescurr;/*pulsesnum; */ + leftnz = nzposcurr; /*nzpos; */ + trellislevel = 0; + + for( i = 0; i < size && leftnz > 1; i++) + { + if( magn[i] != 0.0f ) + { + for( j = 0; j < leftp; j++) + { + prob1 = (leftnz - 1.0f) / (leftp - j - 1.0f); + prob0 = 1.0f - prob1; + + st = savedstates[ trellislevel ]; + quantum1 = (float)quantize( (float)(j + 1), ddec[st][ 0 ]); + quantum2 = (float)quantize( (float)(j + 1), ddec[st][ 1 ]); + + if( quantum1 != (j+1) && quantum2 != (j+1) ) + { + /* this magnitude is not possible so set probabilities */ + prob0 = 1.0f; + prob1 = 0.0f; + } + + if( j < fabs(magn[i]) - 1 ) + { + magnbits -= log2_f( prob0 ); + } + else + { + magnbits -= log2_f( prob1 ); + break; + } + } + + leftnz--; + leftp -= (int)fabs( magn[i] ); + } + + trellislevel++; + } + + /* Update actual occured surplus */ + *nzpout = nzposcurr; + } + } + + if( *nzpout > 1 && bcount != 0 ) + { + flag_g1 = 0; + + for( i = 0; i < size; i++) + { + if( fabs(magn[i]) > 1.0f ) + { + flag_g1 = 1; + } + } + /* prepare vector for TCQ */ + for( i = 0; i < size && flag_g1 && *bcount < 2*TCQ_AMP; i++) + { + if( fabs(magn[i]) > 0.0f ) + { + abuffer[*bcount] = quants[i]; + mbuffer[*bcount] = magn[i]; + sbuffer[*bcount] = scale; + + (*bcount)++; + + } + } + } + + if( actualt > 0) + { + *qscale = pulsesnum / actualt; + } + else + { + *qscale = FLT_MAX; + } + } + + return magnbits; +} + + +void InitLSBTCQ(short *bcount) +{ + *bcount = 0; + + return; +} + + +void TCQLSB(short bcount, float *abuffer, float *mbuffer, float *sbuffer, short *dpath) + +{ + short i, st, dminpos, position; + float q = QTCQ; + float dmin, curdist1, curdist2, newdist1, newdist2; + float metric[STATES_LSB][TCQ_LSB_SIZE]; + short path[STATES_LSB][TCQ_LSB_SIZE]; + short quant[STATES_LSB][TCQ_LSB_SIZE]; + short dquant[STATES_LSB][TCQ_LSB_SIZE]; + short qout[TCQ_LSB_SIZE]; + float q1, q2, s1, s2, a1, a2, sign1, sign2; + float dbuffer[MAX_PULSES]; + + set_f( *metric, 0.0f, STATES_LSB*TCQ_LSB_SIZE ); + set_s( *path, 0, STATES_LSB*TCQ_LSB_SIZE ); + set_s( *quant, 0, STATES_LSB*TCQ_LSB_SIZE ); + set_s( *dquant, 0, STATES_LSB*TCQ_LSB_SIZE ); + set_s( qout, 0, TCQ_LSB_SIZE ); + set_f( dbuffer, 0.0f, MAX_PULSES ); + + metric[1][0] = 16777216.0f; + metric[2][0] = 16777216.0f; + metric[3][0] = 16777216.0f; + + for( i = 0; i < 2*TCQ_AMP; i+=2 ) + { + q1 = mbuffer[i]; + q2 = mbuffer[i + 1]; + + s1 = sbuffer[i]; + s2 = sbuffer[i + 1]; + + a1 = abuffer[i]; + a2 = abuffer[i + 1]; + + /* cycle over conditions */ + for( st = 0; st < 4; st++) + { + curdist1 = metric[ step_LSB[st][0] ][i/2]; + curdist2 = metric[ step_LSB[st][1] ][i/2]; + + /* step 1 */ + sign1 = (denc_LSB[st][0] & 0x1)?(q):(-q); + sign2 = (denc_LSB[st][0] & 0x2)?(q):(-q); + newdist1 = (a1 - (q1+sign1)/s1)*(a1 - (q1+sign1)/s1) + (a2 - (q2+sign2)/s2)*(a2 - (q2+sign2)/s2); + + /* step 2 */ + sign1 = (denc_LSB[st][1] & 0x1)?(q):(-q); + sign2 = (denc_LSB[st][1] & 0x2)?(q):(-q); + newdist2 = (a1 - (q1+sign1)/s1)*(a1 - (q1+sign1)/s1) + (a2 - (q2+sign2)/s2)*(a2 - (q2+sign2)/s2); + + /* decision */ + if( curdist1 + newdist1 < curdist2 + newdist2 ) + { + path[st][i/2+1] = step_LSB[st][0]; + metric[st][i/2+1] = curdist1 + newdist1; + quant[st][i/2+1] = 0; + dquant[st][i/2+1] = dqnt_LSB[ step_LSB[st][0] ][st]; + } + else + { + path[st][i/2+1] = step_LSB[st][1]; + metric[st][i/2+1] = curdist2 + newdist2; + quant[st][i/2+1] = 1; + dquant[st][i/2+1] = dqnt_LSB[ step_LSB[st][0] ][st]; + } + } + + } + + /* Find path with minimal metric */ + dminpos = 0; + dmin = metric[ dminpos][ i/2]; + for( st = 1; st < 4; st++) + { + if( dmin > metric[ st][ i/2] ) + { + dmin = metric[ st][ i/2]; + dminpos = st; + } + } + + /* Trace back to get output */ + position = dminpos; + + for( ; i >= 0; i-=2) + { + qout[i/2] = quant[position][ i/2+1 ]; + dpath[i/2] = dquant[position][ i/2+1 ]; + + dbuffer[i] = (denc_LSB[position][qout[i/2]] & 0x1)?(q):(-q); + dbuffer[i + 1] = (denc_LSB[position][qout[i/2]] & 0x2)?(q):(-q); + + position = path[position][i/2+1]; + } + + /* add decoded sequence to quanta */ + for( i = 0; i < bcount; i++ ) + { + mbuffer[i] += dbuffer[i]; + } + + return; +} + +void TCQLSBdec( short *dpath, float *mbuffer, short bcount ) +{ + float q = QTCQ; + int i, state = 0; + + for( i = 0; i < bcount/2; i++) + { + mbuffer[2*i] = ( ddec_LSB[state][dpath[i]] & 0x1)?(q):(-q); + mbuffer[2*i + 1] = ( ddec_LSB[state][dpath[i]] & 0x2)?(q):(-q); + + state = dstep_LSB[state][dpath[i]]; + } + + return; +} + +void SaveTCQdata( PARCODEC arInst, short *dpath, short bcount) +{ + int i; + for( i = 0; i < bcount; i++) + { + ar_encode_uniform( arInst, dpath[i], 1); + } + + return; +} + +void LoadTCQdata( PARCODEC arInst, short *dpath, short bcount) +{ + int i; + for( i = 0; i < bcount; i++) + { + dpath[i] = ar_decode( arInst, uniform_model ); + } + + return; +} + +void RestoreTCQdec( int * magn, int size, short *bcount, float *mbuffer) +{ + int i, nzpos = 0, flag_g1 = 0; + + /* calculate actual nz positions */ + for( i = 0, nzpos = 0; i < size; i++) + { + if( magn[i] != 0 ) + { + nzpos++; + if( abs(magn[i]) > 1 ) + { + flag_g1 = 1; + } + magn[i] *= (1.0f/QTCQ); + } + } + + if( nzpos > 1) + { + for( i = 0; i < size && flag_g1 && *bcount < 2*TCQ_AMP; i++) + { + if( magn[i] != 0 ) + { + mbuffer[*bcount] = magn[i] + (1.0f/QTCQ)*mbuffer[*bcount]; + magn[i] = round_f( mbuffer[*bcount] ); + (*bcount)++; + } + } + } + + return; +} + + +void RestoreTCQ( float * magn, int size, short *bcount, float *mbuffer) +{ + int i, nzpos = 0, flag_g1 = 0; + + /* calculate actual nz positions */ + for( i = 0, nzpos = 0; i < size; i++) + { + if( magn[i] != 0.0f ) + { + nzpos++; + if( fabs(magn[i]) > 1.0f ) + { + flag_g1 = 1; + } + } + } + + if( nzpos > 1) + { + for( i = 0; i < size && flag_g1 && *bcount < 2*TCQ_AMP; i++) + { + if( fabs(magn[i]) > 0.0f ) + { + magn[i] = mbuffer[*bcount]; + (*bcount)++; + } + } + } + + return; +} + diff --git a/src/libs/libevs/lib_com/tcq_position_arith_fx.cpp b/src/libs/libevs/lib_com/tcq_position_arith_fx.cpp deleted file mode 100755 index da2ce96c..00000000 --- a/src/libs/libevs/lib_com/tcq_position_arith_fx.cpp +++ /dev/null @@ -1,2566 +0,0 @@ -/*==================================================================================== - EVS Codec 3GPP TS26.442 Apr 03, 2018. Version 12.11.0 / 13.6.0 / 14.2.0 - ====================================================================================*/ - -#include -#include -#include -#include -#include "options.h" /* Compilation switches */ -#include "stl.h" - -#include "rom_com_fx.h" -#include "prot_fx.h" - -Word32 ar_div(Word32 num, Word32 denum) -{ - Word16 exp1, exp2, exp, i; - Word32 varout; - Word32 sign; - - sign = L_and(L_xor(num, denum), 0x80000000); - - num = L_abs(num); - denum = L_abs(denum); - - test(); - IF (L_sub(num, denum) < 0 || denum == 0) - { - return 0; - } - ELSE IF (L_sub(num, denum) == 0) - { - return 1; - } - ELSE - { - exp1 = norm_l(num); - exp2 = norm_l(denum); - exp = sub(exp2, exp1); - denum = L_shl(denum, exp); - exp = add(exp, 1); - varout = L_deposit_l(0); - FOR (i = 0; i < exp; i++) - { - num = L_sub(num, denum); - varout = L_shl(varout, 1); - IF (num >= 0) - { - num = L_shl(num, 1); - varout = L_add(varout, 1); - } - ELSE - { - num = L_add(num, denum); - num = L_shl(num, 1); - } - } - } - - if(sign != 0) - { - varout = L_negate(varout); - } - - return varout; -} - -static void bitstream_save_bit(PBITSTREAM_FX pBS, Word32 bit) -{ - UWord8 cur; - - cur = pBS->buf[pBS->numByte]; - move16(); - - - cur = (UWord8)(cur | L_shl(bit,pBS->curPos)); - move16(); - pBS->curPos = sub(pBS->curPos,1); - pBS->buf[pBS->numByte] = cur; - move16(); - pBS->numbits = L_add(pBS->numbits, 1); - - IF (pBS->curPos < 0) - { - pBS->curPos = 7; - move16(); - pBS->numByte = L_add(pBS->numByte, 1); - } - - return; -} - -static UWord32 bitstream_load_bit(PBITSTREAM_FX pBS) -{ - UWord32 bit; - Word16 *curPos; - - /* safety check in case of bit errors */ - IF( L_sub(pBS->numByte, pBS->maxBytes) >= 0 ) - { - return 0; - } - - curPos = &pBS->curPos; - move16(); - bit = (( pBS->buf[pBS->numByte] >> (*curPos)--) & 0x00000001); - move16(); - move16(); - move16(); - - IF (*curPos < 0) - { - pBS->numByte = L_add(pBS->numByte, 1); - *curPos = 7; - move16(); - } - - return bit; -} - -static void bitstream_rollback(PBITSTREAM_FX pBS, Word32 numBits) -{ - - FOR ( ; numBits > 0; numBits--) - { - pBS->curPos++; - move16(); - pBS->numbits = L_sub(pBS->numbits, 1); - IF (sub(pBS->curPos, 8) == 0) - { - pBS->curPos = 0; - move16(); - pBS->numByte = L_sub(pBS->numByte, 1); - } - } - - return; -} -static void transmission_bits( PARCODEC_FX arInst, Word32 bit ) -{ - bitstream_save_bit( arInst->bsInst, bit ); - arInst->num_bits = L_add(arInst->num_bits, 1); - bit = !bit; - move32(); - - FOR ( ; arInst->bits_to_follow > 0 && arInst->num_bits < arInst->max_bits; arInst->bits_to_follow --) - { - bitstream_save_bit( arInst->bsInst, bit ); - arInst->num_bits = L_add(arInst->num_bits, 1); - } - - return; -} - -static Word32 ar_make_model_fx( const Word16 *freq, Word16 *model, Word16 len ) -{ - Word16 dist; - Word32 sum = 0; - Word32 cum = 0; - Word16 i, tmp; - - FOR ( i = 0 ; i < len ; i ++ ) - { - sum = L_add(sum, freq[i]); - } - - IF ( sum == 0 ) - { - return 0; - } - - FOR ( i = len ; i >= 0; i -- ) - { - /*model[i] = (short)( ( cum * MAX_AR_FREQ ) / sum ); */ - model[i] = extract_l(ar_div(cum * MAX_AR_FREQ, sum)); - - if (i) cum = L_add(cum, freq[i - 1]); - } - - tmp = sub(len, 1); - FOR ( i = 0 ; i < tmp ; i ++ ) - { - dist = sub(model[i], model[i + 1]); - - IF ( dist <= 0 ) - { - model[i + 1] = add(model[i + 1], sub(dist, 1)); - move16(); - } - } - - FOR ( i = len ; i > 0 ; i -- ) - { - dist = sub(model[i - 1], model[i]); - - IF ( dist <= 0 ) - { - model[i - 1] = sub(model[i - 1], sub(dist, 1)); - move16(); - } - } - - return (model[0] > model[1]); -} - -void ar_encoder_start_fx( PARCODEC_FX arInst, PBITSTREAM_FX bsInst, Word32 max_bits ) -{ - arInst->bsInst = bsInst; - move32(); - - arInst->low = L_deposit_l(0); - arInst->high = AR_TOP; - move32(); - arInst->bits_to_follow = 0; - move16(); - - arInst->num_bits = L_deposit_l(0); - arInst->max_bits = max_bits; - move32(); -} - -static void ar_encode_fx( PARCODEC_FX arInst, Word16 const *model, Word32 symbol ) -{ - Word32 range, high, low; - - high = L_add(arInst->high, 0); - low = L_add(arInst->low, 0); - - symbol = L_add(symbol, 1); - range = L_add(L_sub(high, low), 1); - - high = L_sub(L_add(low, ar_div(range * model[symbol - 1], model[0])), 1); - low = L_add(low, ar_div(range * model[symbol], model[0])); - - FOR( ; ; ) - { - IF ( L_sub(high, AR_HALF) < 0 ) - { - transmission_bits( arInst, 0 ); - } - ELSE - { - IF (L_sub(low, AR_HALF) >= 0 ) - { - transmission_bits( arInst, 1 ); - - low = L_sub(low, AR_HALF); - high = L_sub(high, AR_HALF); - } - ELSE - { - test(); - IF (L_sub(low, AR_FIRST) >= 0 && L_sub(high, AR_THIRD) < 0 ) - { - arInst->bits_to_follow ++; - move16(); - - low = L_sub(low, AR_FIRST); - high = L_sub(high, AR_FIRST); - } - ELSE - { - BREAK; - } - } - } - - low = L_shl(low, 1); - high = L_add(L_shl(high, 1 ), 1); - } - - arInst->high = high; - move32(); - arInst->low = low; - move32(); - - return; -} - -static void ar_encode_uniform_fx( PARCODEC_FX arInst, UWord32 data, Word32 bits ) -{ - Word32 i; - - FOR ( i = 0 ; i < bits ; i ++ ) - { - ar_encode_fx( arInst, uniform_model_fx, data & 0x1 ); - data = L_lshr(data, 1); - } - - return; -} - -void ar_encoder_done_fx( PARCODEC_FX arInst ) -{ - arInst->bits_to_follow ++; - move16(); - transmission_bits( arInst, arInst->low >= AR_FIRST ); - - return; -} - -void ar_decoder_start_fx( PARCODEC_FX arInst, PBITSTREAM_FX bsInst ) -{ - Word16 i; - - arInst->bsInst = bsInst; - move32(); - - arInst->low = L_deposit_l(0); - arInst->high = AR_TOP; - move32(); - arInst->value = L_deposit_l(0); - - FOR ( i = 0; i < AR_BITS ; i ++ ) - { - arInst->value = L_add(L_shl( arInst->value, 1), bitstream_load_bit( arInst->bsInst )); - } - - return; -} - -static Word16 ar_decode_fx( PARCODEC_FX arInst, Word16 const *model ) -{ - Word32 range, high, low, value, i; - Word16 cum; - Word16 symbol; - - high = L_add(arInst->high, 0); - low = L_add(arInst->low, 0); - value = L_add(arInst->value, 0); - - range = L_add(L_sub( high, low ), 1); - /*cum = (short)( ( ( (unsigned int)( arInst->value - arInst->low ) + 1 ) * model[0] - 1 ) / range ); */ - cum = extract_l(ar_div(L_sub(L_add(L_sub( value, low ), 1 ) * model[0], 1), range)); - - symbol = 1; - move16(); - WHILE ( sub(model[symbol], cum) > 0 ) - { - symbol = add(symbol, 1); - } - - high = L_sub(L_add(low, ar_div(range * model[symbol - 1], model[0])), 1); - low = L_add(low, ar_div(range * model[symbol], model[0])); - - FOR (i = 0; i < 0x7FFF; i++) - { - Word32 L_msb_diff, L_msb_low, L_msb_high; - - L_msb_high = L_shr(high,14); - L_msb_low = L_shr(low,14); - L_msb_diff = L_sub(L_msb_high, L_msb_low); - IF (L_sub(L_msb_diff,2) >= 0) - { - BREAK; - } - assert (tab_ari_qnew[L_msb_high][L_msb_low] != 0x0CCC); - assert (tab_ari_qnew[L_msb_high][L_msb_low] != 0x0BBB); - low = L_msu(low,1,tab_ari_qnew[L_msb_high][L_msb_low]); - low = L_shl(low,1); - high = L_msu(high,1,tab_ari_qnew[L_msb_high][L_msb_low]); - high = L_add(L_shl(high, 1), 1); - value = L_msu(value,1,tab_ari_qnew[L_msb_high][L_msb_low]); - value = L_add(L_shl(value, 1), bitstream_load_bit( arInst->bsInst )); - } - - arInst->low = low; - move32(); - arInst->high = high; - move32(); - arInst->value = value; - move32(); - - return (symbol - 1); -} - -void ar_decoder_done_fx( PARCODEC_FX arInst ) -{ - bitstream_rollback( arInst->bsInst, AR_BITS - 2 ); - - return; -} - -static Word16 quantize_fx( Word16 val, Word16 D) -{ - Word16 qval4_fx; - Word16 retval_fx; - - val = s_min(val, 32255); /* limit input by (2^15 - 1)-2^9 */ - qval4_fx = shr(abs_s(add(val, 512)), 12); - retval_fx = add(shl(qval4_fx, 2), DDP_fx[D]); - /* 2nd zero check */ - IF (D == 0) - { - if (sub(abs_s(sub(shl(abs_s(retval_fx), 10), abs_s(val))), abs_s(val)) > 0) - { - retval_fx = 0; - move16(); - } - } - /*return retval; */ - return retval_fx; -} - -static Word32 GetBitsFromPulses_fx(Word16 m, Word16 n) -{ - Word16 i, tmp, integer_fx, temp_fx1, temp_fx2, exp1, exp2; - Word32 temp32; - Word32 frac_fx32; - Word32 logCoeff_fx; - Word16 exp = 0; - Word32 mantissa_fx = 0; - move16(); - move32(); - - IF (m == 0) - { - return 0; - } - - tmp = s_min(m, n); - FOR (i = 0; i < tmp; i++) - { - logCoeff_fx = L_add(L_shl(i + 1, 16), L_sub(table_logcum_fx[n+1], L_add(table_logcum_fx[i + 2], table_logcum_fx[n - i]))); - logCoeff_fx = L_add(logCoeff_fx, L_sub(table_logcum_fx[m], L_add(table_logcum_fx[i + 1], table_logcum_fx[m - i])));/*Q16 */ - integer_fx = extract_h(logCoeff_fx);/*Q0 */ - frac_fx32 = L_sub(logCoeff_fx, L_shl(integer_fx, 16));/*Q16 */ - - /*ln2, 0.987, ln2 * ln2, 0.977 */ - /*temp1 = (int) (frac / 0.0625); */ - /*temp2 = frac - (float)temp1 * 0.0625f; */ - - /* frac = pow(2.0, temp1 * 0.0625) * (1 + 0.693 * temp2 + 0.480 * temp2 * temp2 * 0.5);*/ - /*frac = pow_getbitsfrompulses[temp1] * (1 + 0.693f * temp2 + 0.480f * temp2 * temp2 * 0.5f); */ - - temp_fx1 = extract_h(L_shl(frac_fx32, 4)); - temp_fx2 = extract_l(L_and(frac_fx32, 0xfff));/*Q16 */ - - frac_fx32 =L_mac(Mult_32_16(L_mult0(temp_fx2, temp_fx2), 7864), temp_fx2, 22708);/*Q32 */ - frac_fx32 = L_add(0x40000000, L_shr(frac_fx32, 2));/*30 */ - - exp1 = norm_l(pow_getbitsfrompulses_fx[temp_fx1]); - exp2 = norm_l(frac_fx32); - frac_fx32 = Mult_32_32(L_shl(pow_getbitsfrompulses_fx[temp_fx1], exp1), L_shl(frac_fx32, exp2));/*21 + exp1 + 30 + exp2 - 31 */ - frac_fx32 = L_shr(frac_fx32, exp1 + exp2) + 1;/*20 */ - - IF (sub(exp, integer_fx) < 0) - { - mantissa_fx = L_shr(mantissa_fx, sub(integer_fx, exp)); - mantissa_fx = L_add(mantissa_fx, frac_fx32); - - exp = integer_fx; - move16(); - } - ELSE - { - mantissa_fx = L_add(mantissa_fx, L_shr(frac_fx32, sub(exp, integer_fx))); - } - IF (L_sub(mantissa_fx, 0x200000) >= 0) - { - exp++; - move16(); - - mantissa_fx = L_shr(mantissa_fx, 1); - } - } - - mantissa_fx = L_shl(mantissa_fx, 2);/*22 */ - temp_fx1 = extract_h(mantissa_fx); - /*temp_fx2 = extract_h(L_shl(L_sub(mantissa_fx, L_deposit_h(temp_fx1)), 15)); // 15 */ - temp32 = L_shl(L_sub(mantissa_fx, L_deposit_h(temp_fx1)), 15);/*31 */ - exp1 = sub(norm_l(temp32), 1); - temp32 = ar_div(L_shl(temp32, exp1), temp_fx1); /*31 + exp1 */ - temp32 = L_shr(temp32, exp1 + 1);/*30 */ - - frac_fx32 = L_sub(0x40000000, L_shr(temp32, 1));/*30 */ - frac_fx32 = Mult_32_32(frac_fx32, temp32);/*29 */ - frac_fx32 = L_shr(frac_fx32, 13);/*16 */ - exp1 = norm_l(temp_fx1); - temp_fx1 = Log2_norm_lc(L_shl(temp_fx1, exp1));/*15 */ - frac_fx32 = frac_fx32 + Mult_32_32(frac_fx32, 950680361); /* frac_fx32 *= 1/ln(2) */ - return L_add(L_deposit_h(exp), L_add(L_shl(temp_fx1, 1), frac_fx32)); - /*return exp + (float)temp_fx1 / pow(2.0, 15) + (float)frac_fx32 / pow(2.0, 16); */ -} - -static -void TCQnew_fx( Word32 *v_fx, Word32 scale_fx, Word16 Qscale, - Word16 length, Word16 *vout_fx, Word16 pulses, Word16 *pulsesout, Word16* nzposout, Word32 *savedstates, Word32 * lasttrellislevel, Word32 terminate) -{ - Word16 i, st, dminpos, position; - Word16 pulsesnum, nzpos = 0; - - Word32 metric_fx[STATES][TCQ_MAX_BAND_SIZE]; - Word16 path_fx[STATES][TCQ_MAX_BAND_SIZE]; - Word16 quant_fx[STATES][TCQ_MAX_BAND_SIZE]; - Word16 pused_fx[STATES][TCQ_MAX_BAND_SIZE]; - Word16 quantum1_fx, quantum2_fx, newdist1_fx, newdist2_fx/*, signq_fx*/; - Word32 /*scale_fx, */tmp32, dmin_fx, curdist1_fx, curdist2_fx; - Word16 value_fx, exp; - Word16 exp1, exp2; - - set32_fx(*metric_fx, 0, STATES * TCQ_MAX_BAND_SIZE); - set16_fx( *path_fx, 0, STATES*TCQ_MAX_BAND_SIZE ); - set16_fx( *quant_fx, 0, STATES*TCQ_MAX_BAND_SIZE ); - set16_fx( *pused_fx, 0, STATES*TCQ_MAX_BAND_SIZE ); - - /* Initialize metric */ - FOR ( st = 1; st < STATES; st++) - { - metric_fx[st][0] = MAX_32>>1; - move32(); - } - FOR ( st = 2; st < STATES; st++) - { - metric_fx[st][1] = MAX_32>>1; - move32(); - } - FOR ( st = 4; st < STATES; st++) - { - metric_fx[st][2] = MAX_32>>1; - move32(); - } - /* Viterbi for input sequence */ - FOR ( i = 0; i < length; i++) /* cycle over symbols */ - { - FOR ( st = 0; st < STATES; st++) /* cycle over conditions */ - { - curdist1_fx = L_add(metric_fx[ step_tcq_fx[st][0]][i], 0); - curdist2_fx = L_add(metric_fx[ step_tcq_fx[st][1]][i], 0); - - exp = norm_l(scale_fx); - tmp32 = L_shl(scale_fx, exp); - tmp32 = Mult_32_16(v_fx[i], extract_h(tmp32));/*12 + 20 + exp - 16 - 15 + Qscale */ - exp1 = 26-(exp-19+Qscale); - exp2 = norm_l(tmp32); - IF( sub(exp2, exp1) >= 0 ) - { - value_fx = extract_h(L_shl(tmp32, sub(26, add(sub(exp, 19), Qscale))));/*exp -19 + Qscale*/ /*10*/ - } - ELSE - { - value_fx = extract_h(L_shl(tmp32, exp2));/*exp -19 + Qscale*/ /*10*/ - } - /* step 1 */ - quantum1_fx = quantize_fx(value_fx, denc_fx[st][0]); - newdist1_fx = sub(shl(quantum1_fx, 10), abs_s(value_fx));/*10*/ - newdist1_fx = mult(newdist1_fx, newdist1_fx); /* 5 */ - - test(); - if (sub(add(quantum1_fx , pused_fx[step_tcq_fx[st][0]][i]), pulses) > 0 && terminate) - { - newdist1_fx = MAX_16; - move16(); - } - /* step 2 */ - quantum2_fx = quantize_fx(value_fx, denc_fx[st][1]); - newdist2_fx = sub(shl(quantum2_fx, 10), abs_s(value_fx));/*10*/ - newdist2_fx = mult(newdist2_fx, newdist2_fx);/*5*/ - - test(); - if (sub(add(quantum2_fx , pused_fx[step_tcq_fx[st][1]][i]), pulses) > 0 && terminate) - { - newdist2_fx = MAX_16; - move16(); - } - - /* decision */ - IF (L_sub(L_add(curdist1_fx, newdist1_fx), L_add(curdist2_fx, newdist2_fx)) < 0) - { - path_fx[st][i+1] = step_tcq_fx[st][0]; - move16(); - metric_fx[st][i+1] = L_add(curdist1_fx, newdist1_fx); - move32(); - quant_fx[st][i+1] = quantize_fx(value_fx, denc_fx[st][0]); - move16(); - pused_fx[st][i+1] = add(pused_fx[ step_tcq_fx[st][0]][i], abs_s( quant_fx[st][i+1] )); - move16(); - } - ELSE - { - path_fx[st][i+1] = step_tcq_fx[st][1]; - move16(); - metric_fx[st][i+1] = L_add(curdist2_fx, newdist2_fx); - move32(); - quant_fx[st][i+1] = quantize_fx(value_fx, denc_fx[st][1]); - move16(); - pused_fx[st][i+1] = add(pused_fx[ step_tcq_fx[st][1]][i], abs_s( quant_fx[st][i+1] )); - move16(); - } - } - } - - /* Find path with minimal metric */ - dminpos = 0; - move16(); - dmin_fx = L_add(metric_fx[dminpos][ length], 0); - FOR ( i = 1; i < STATES; i++) - { - test(); - test(); - test(); - IF ( (L_sub(dmin_fx, metric_fx[ i][ length]) > 0 && sub(pused_fx[i][ length], pulses) == 0) || - (sub(pused_fx[dminpos][ length], pulses) != 0 && sub(pused_fx[i][ length], pulses) == 0) ) - { - dmin_fx = L_add(metric_fx[ i][ length], 0); - dminpos = i; - move16(); - } - } - /* Trace back to get output */ - nzpos = 0; - move16(); - pulsesnum = 0; - move16(); - position = dminpos; - move16(); - FOR ( i = length; i > 0; i--) - { - vout_fx[i-1] = quant_fx[position][i]; - move16(); - if (v_fx[i-1] <= 0) - { - vout_fx[i-1] = - quant_fx[position][i]; - move16(); - } - position = path_fx[position][i]; - move16(); - savedstates[i-1] = position; - move32(); - - /* calculate output pulses number & nz */ - pulsesnum = add(pulsesnum, abs_s(vout_fx[i-1]));/*quant[position][i]; */ - IF ( abs_s(vout_fx[i-1]) > 0 ) - { - if ( nzpos == 0 ) - { - *lasttrellislevel = i; - move32(); - } - - nzpos = add(nzpos, 1); - } - } - - if ( pulsesout != 0 ) - { - *pulsesout = pulsesnum; - move16(); - } - if ( nzposout != 0 ) - { - *nzposout = nzpos; - move16(); - } - - return; -} - -Word32 GetISCScale_fx( Word32 *quants_fx, Word16 size, Word32 bits_fx, Word16 *magn_fx, Word32 *qscale_fx, Word32 *surplus_fx, Word16 *pulses, Word32* savedstates, Word32 noTCQ, - Word16 *nzpout, Word16 *bcount, Word32 *abuffer, Word16 *mbuffer, Word32 *sbuffer) -{ - Word32 pos, terminate, trellislevel, st; - Word32 lasttrellislevel; - Word16 i, j, m_int, leftp, leftnz, nzpos, direction, pulsesnum, diff, pulsescurr, nzposcurr; - Word16 sign; - Word16 flag_g1; - Word32 t32; - Word16 SafeExp; - - Word32 magnbits_fx = 0, tcqmagnbits_fx/*, surplus_fx, bits_fx*/; - Word16 prob0_fx, prob1_fx, num, denum, quantum1_fx, quantum2_fx; - Word32 dmin_fx, scale_fx32; - Word32 actualt_fx; - Word32 pt_fx, sxy_fx = 0, sy2_fx = 0; - Word16 pn_fx, g_fx, scale_fx; - Word16 tmp16, exp, exp1, exp2, Q_temp, hi, lo; - Word32 m_fx, tmp32; - Word32 /*quants_fx[TCQ_MAX_BAND_SIZE], */aquants_fx[TCQ_MAX_BAND_SIZE], dist_fx[TCQ_MAX_BAND_SIZE]; - Word16 exp_dist[TCQ_MAX_BAND_SIZE]; - Word16 /*magn_fx[TCQ_MAX_BAND_SIZE], */t_fx; - Word16 Qscale; - Word16 Qsxy=4; - - exp = 0; /* to avoid compilation warnings */ - Qscale = 0; /* to avoid compilation warnings */ - - set32_fx( dist_fx, 0, size ); - set16_fx(exp_dist, 31, size ); - set32_fx( aquants_fx, 0, size ); - - IF( bits_fx < 0 ) - { - pulsesnum = 0; - move16(); - - IF( surplus_fx != 0 ) - { - /* *surplus_fx += bits_fx; */ - *surplus_fx = L_add(*surplus_fx, bits_fx); - move32(); - } - } - ELSE - { - pulsesnum = GetScale_fx(size, bits_fx, surplus_fx); - } - *nzpout = 0; - move16(); - - if ( pulses != 0 ) - { - *pulses = pulsesnum; - move16(); - } - - IF ( pulsesnum > 0 ) - { - /* Initial quantization */ - m_fx = L_deposit_l(0); - FOR (i = 0; i < size; i++) - { - aquants_fx[i] = L_abs(quants_fx[i]);/*Q12 */ move32(); - m_fx = L_add(m_fx, L_shr( aquants_fx[i], 2) );/*Q12 - 2*/ - } - - IF (m_fx == 0) - { - scale_fx = 0; - move16(); - FOR (i = 0; i < size; i++) - { - magn_fx[i] = 0; - move16(); - } - t_fx = 0; - move16(); - } - ELSE - { - exp1 = sub(norm_s(pulsesnum), 1); - exp2 = norm_l(m_fx); - scale_fx = div_s(shl(pulsesnum, exp1), extract_h(L_shl(m_fx, exp2)));/*15 + exp1 - (exp2 + 12 - 16) */ - - exp = 15 + exp1 - (exp2 + 12 - 16) + 2; - move16(); - t_fx = 0; - move16(); - FOR (i = 0; i < size; i++) - { - tmp32 = Mult_32_16(aquants_fx[i], scale_fx);/*12 + exp - 15 */ - tmp32 = L_shl(tmp32, sub(16, 12 + exp - 15));/*16 */ - magn_fx[i] = extract_h(L_add(32768, tmp32)); - t_fx = add(t_fx, magn_fx[i]); - } - } - - /* Pulses redistribution */ - WHILE (sub(t_fx, pulsesnum) != 0 ) - { - pn_fx = 0; - move16(); - pt_fx = L_deposit_l(0); - - nzpos = 0; - move16(); - FOR (i = 0; i < size; i++) - { - IF (magn_fx[i] > 0) - { - pn_fx = add(pn_fx, magn_fx[i]);/*0 */ - pt_fx = L_add(pt_fx, L_shr( aquants_fx[i], 2) );/*12 */ - } - } - - direction = -1; - move16(); - if ( sub(pulsesnum, t_fx) > 0 ) - { - direction = 1; - move16(); - } - - /* new alg */ - { - FOR ( i = 0; i < size; i++) - { - sxy_fx = L_add(sxy_fx, L_shl(Mult_32_16(aquants_fx[i], magn_fx[i]), Qsxy+3)); /* 12+0-15 +9 -> 6 */ - sy2_fx = L_add(sy2_fx, L_mult0(magn_fx[i], magn_fx[i]));/*0 */ - } - Q_temp = 32; - move16(); - FOR ( i = 0; i < size; i++) - { - IF (magn_fx[i] > 0) - { - tmp16 = add(pn_fx, direction); - tmp32 = L_add(pt_fx, 0); - } - ELSE - { - tmp16 = add(pn_fx, direction); - tmp32 = L_add(pt_fx, L_shr( aquants_fx[i], 2) ); - } - - IF (tmp32 == 0) - { - g_fx = 0; - move16(); - } - ELSE - { - exp1 = sub(norm_l(tmp32), 1); - exp2 = norm_s(tmp16); - tmp32 = L_shl(tmp32, exp1); - IF (tmp16 == 0) - { - tmp16 = 1; - move16(); - exp2 = 16; - move16(); - } - ELSE - { - tmp16 = shl(tmp16, exp2); - } - g_fx = div_s(extract_h(tmp32), tmp16);/*15 + 12 + exp1 - 16 - exp2; */ - exp = 15 + 12 + exp1 - 16 - exp2 - 2; - move16(); - } - - IF (g_fx == 0) - { - dist_fx[i] = L_deposit_l(0); - } - ELSE - { - IF (direction > 0) - { - tmp32 = L_add(sxy_fx, L_shr(aquants_fx[i], 12-Qsxy));/*Qsxy */ - t32 = L_add( sy2_fx, L_add( 1, L_deposit_l( shl(magn_fx[i], 1) ) ) ); - - IF( sub(norm_l(t32), 15) < 0 ) - { - SafeExp = sub(16, norm_l(t32)); - tmp16 = extract_l( L_shr( t32, SafeExp) ); - } - ELSE - { - SafeExp = 0; - move16(); - tmp16 = extract_l( t32 ); - } - } - ELSE - { - tmp32 = L_sub(sxy_fx, L_shr(aquants_fx[i], 12-Qsxy));/*Qsxy */ - t32 = L_add( sy2_fx, L_sub( 1, L_deposit_l( shl(magn_fx[i], 1) ) ) ); - SafeExp = norm_l(t32); - - IF( sub(norm_l(t32), 15) <= 0 ) - { - SafeExp = sub(16, norm_l(t32)); - tmp16 = extract_l( L_shr( t32, SafeExp) ); - } - ELSE - { - SafeExp = 0; - move16(); - tmp16 = extract_l( t32 ); - } - } - tmp32 = L_shl(tmp32, 1-SafeExp); /* *2 */ - tmp32 = L_sub(L_shl(L_mult0(g_fx, tmp16), sub(Qsxy, exp)), tmp32);/*Qsxy */ - dist_fx[i] = Mult_32_16(tmp32, g_fx);/*Qsxy + exp - 15 */ move32(); - exp_dist[i] = add(Qsxy-15, exp); - move16(); - if (sub(exp_dist[i], Q_temp) < 0) - { - Q_temp = exp_dist[i]; - move16(); - } - } - - } - FOR (i = 0; i < size; i++) - { - dist_fx[i] = L_shr(dist_fx[i], s_min(sub(exp_dist[i], Q_temp), 31)); - move32(); - } - } - - { - /* find min */ - pos = L_deposit_l(0); - dmin_fx = L_add(dist_fx[0], 0); - FOR (i = 1; i < size; i++) - { - IF (L_sub(dmin_fx, dist_fx[i]) > 0) - { - pos = L_deposit_l(i); - dmin_fx = L_add(dist_fx[i], 0); - } - } - /*IF (magn_fx[i] == 0 && direction < 0) */ - test(); - IF (magn_fx[pos] == 0 && direction < 0) - { - pos = L_deposit_l(0); - FOR (i = 0; i < size; i++) - { - IF (magn_fx[i] != 0) - { - pos = L_deposit_l(i); - BREAK; - } - } - dmin_fx = L_add(dist_fx[i], 0); - FOR (; i < size; i++) - { - test(); - IF (magn_fx[i] != 0 && L_sub(dmin_fx, dist_fx[i]) < 0) - { - pos = L_deposit_l(i); - dmin_fx = L_add(dist_fx[i], 0); - } - } - } - - magn_fx[pos] = add(magn_fx[pos], direction); - move16(); - t_fx = add(t_fx, direction); - } - } - - /* calculate actual nz positions */ - actualt_fx = L_deposit_l(0); - nzpos = 0; - move16(); - FOR (i = 0; i < size; i++) - { - IF (magn_fx[i] > 0) - { - if (quants_fx[i] < 0) - { - magn_fx[i] = negate(magn_fx[i]); - move16(); - } - actualt_fx = L_add(actualt_fx, L_shr( aquants_fx[i], 2) );/*12 */ - nzpos++; - } - /*magn[i] = (float)magn_fx[i]; */ - } - - /* calculate scale */ - IF (actualt_fx == 0) - { - scale_fx32 = L_add(MAX_32, 0); - } - ELSE - { - exp1 = norm_l(actualt_fx); - exp2 = sub(norm_l(pulsesnum), 1); - lo = L_Extract_lc(L_shl(actualt_fx, exp1), &hi); - scale_fx32 = Div_32(L_shl(pulsesnum, exp2), hi, lo);/*31 + exp2 - exp1 - 12 */ - Qscale = 31 + exp2 - exp1 - 12 + 2; - move16(); - } - - *qscale_fx = scale_fx32; - move32(); - *nzpout = nzpos; - move16(); - - - test(); - test(); - IF ( (sub(nzpos, pulsesnum) != 0 && sub(nzpos, 1) > 0) && noTCQ == 0 ) - { - terminate = L_deposit_l(1); - /*TCQnew( quants, scale, size, magn, pulsesnum, &pulsescurr, &nzposcurr, savedstates, &lasttrellislevel, terminate); */ - TCQnew_fx(quants_fx, scale_fx32, Qscale, - size, magn_fx, pulsesnum, &pulsescurr, &nzposcurr, savedstates, &lasttrellislevel, terminate); - IF (sub(pulsesnum, pulsescurr) > 0 ) - { - Word32 L_tmp; - IF( L_sub( 1952247030, scale_fx32) > 0 ) - { - scale_fx32 = L_add(scale_fx32, Mult_32_16(scale_fx32, 3277)); - } - ELSE - { - L_tmp = L_shr(scale_fx32, 1); - scale_fx32 = L_add(L_tmp, Mult_32_16(L_tmp, 3277)); - Qscale = sub(Qscale, 1); - } - } - - if(sub(pulsesnum, pulsescurr) < 0 ) - { - scale_fx32 = Mult_32_16(scale_fx32, 29491); - } - IF (sub(pulsesnum, pulsescurr) > 0) - { - diff = sub(pulsesnum, pulsescurr); - - FOR ( i = size-1; i >=0; i--) - { - IF ( abs_s(magn_fx[i]) > 0 ) - { - sign = -1; - move16(); - if( magn_fx[i] > 0 ) - { - sign = 1; - move16(); - } - /*magn_fx[i] = sign * abs_s(add(magn_fx[i], diff)); move32(); */ - IF (sign > 0) - { - magn_fx[i] = abs_s(add(magn_fx[i], diff)); - move16(); - } - ELSE - { - magn_fx[i] = -abs_s(add(magn_fx[i], diff)); - move16(); - } - - BREAK; - } - } - } - ELSE IF(sub(pulsesnum, pulsescurr) < 0) - { - diff = sub(pulsescurr, pulsesnum); - - FOR ( i = size-1; i >=0; i--) - { - IF (diff <= 0) - { - BREAK; - } - - IF ( abs_s(magn_fx[i]) > 0 ) - { - sign = -1; - move16(); - if( magn_fx[i] > 0 ) - { - sign = 1; - move16(); - } - m_int = abs_s(magn_fx[i]); - - IF (sub(diff, m_int) < 0) - { - /*magn_fx[i] = sign * sub(abs_s(magn_fx[i]), diff); move16(); */ - IF (sign > 0) - { - magn_fx[i] = sub(abs_s(magn_fx[i]), diff); - move16(); - } - ELSE - { - magn_fx[i] = - sub(abs_s(magn_fx[i]), diff); - move16(); - } - BREAK; - } - ELSE - { - diff = sub(diff, m_int); - magn_fx[i] = 0; - move16(); - nzposcurr = sub(nzposcurr, 1); - } - } - } - } - - pulsescurr = pulsesnum; - move16(); - - /* Magnitudes coding */ - { - leftp = pulsescurr; - move16();/*pulsesnum; */ - leftnz = nzposcurr; - move16(); /*nzpos; */ - trellislevel = L_deposit_l(0); - - FOR ( i = 0; i < size; i++) - { - IF (sub(leftnz, 1) <= 0) - { - BREAK; - } - - IF ( magn_fx[i] != 0 ) - { - FOR ( j = 0; j < leftp; j++) - { - num = sub(leftnz, 1); - denum = sub(leftp, add(j, 1)); - IF (sub(num, denum) >= 0) - { - prob1_fx = MAX_16; - move16(); - prob0_fx = 0; - move16(); - } - ELSE - { - exp1 = sub(norm_s(num), 1); - exp2 = norm_s(denum); - prob1_fx = div_s(shl(num, exp1), shl(denum, exp2));/*15 + exp1 - exp2 */ - exp = 15 + exp1 - exp2; - move16(); - prob1_fx = shl(prob1_fx, sub(15, exp)); - prob0_fx = sub(MAX_16, prob1_fx); - } - - st = L_add(savedstates[ trellislevel ], 0); - quantum1_fx = quantize_fx(shl(add(j, 1), 10), ddec_fx[st][0]); - quantum2_fx = quantize_fx(shl(add(j, 1), 10), ddec_fx[st][1]); - - test(); - IF(sub(quantum1_fx, add(j, 1)) != 0 && sub(quantum2_fx, add(j, 1)) != 0 ) - { - /* this magnitude is not possible so set probabilities */ - prob0_fx = MAX_16; - move16(); - prob1_fx = 0; - move16(); - } - - IF (sub(j, sub(abs_s(magn_fx[i]), 1)) < 0 ) - { - exp1 = norm_s(prob0_fx); - tmp32 = L_deposit_h(shl(prob0_fx, exp1));/*exp1 + 15 + 16 */ - tmp16 = Log2_norm_lc(tmp32);/*15 */ - magnbits_fx = L_sub(magnbits_fx, L_sub(tmp16, L_shl(add(exp1, 1), 15)));/*15 */ - } - ELSE - { - exp1 = norm_s(prob1_fx); - tmp32 = L_deposit_h(shl(prob1_fx, exp1));/*exp1 + 15 + 16 */ - tmp16 = Log2_norm_lc(tmp32);/*15 */ - magnbits_fx = L_sub(magnbits_fx, L_sub(tmp16, L_shl(add(exp1, 1), 15)));/*15 */ - BREAK; - } - } - - leftnz--; - move16(); - leftp = sub(leftp, abs_s(magn_fx[i])); - } - - trellislevel = L_add(trellislevel, 1); - } - - /* Update actual occurred surplus */ - tcqmagnbits_fx = L_sub(L_sub(table_logcum_fx[pulsescurr], table_logcum_fx[nzposcurr]), table_logcum_fx[pulsescurr - (nzposcurr - 1)]); - *surplus_fx = L_add(*surplus_fx, L_sub(tcqmagnbits_fx, L_shl(magnbits_fx, 1))); - - *nzpout = nzposcurr; - move16(); - }/*magnitude coding */ - }/*TCQ */ - - IF (actualt_fx == 0) - { - scale_fx32 = L_add(MAX_32, 0); - } - ELSE - { - exp1 = norm_l(actualt_fx); - exp2 = sub(norm_l(pulsesnum), 1); - lo = L_Extract_lc(L_shl(actualt_fx, exp1), &hi); - scale_fx32 = Div_32(L_shl(pulsesnum, exp2), hi, lo);/*31 + exp2 - exp1 - 12 */ - Qscale = 31 + exp2 - exp1 - 12; - move16(); - } - test(); - IF ( *nzpout > 1 && bcount != 0 ) - { - flag_g1 = 0; - move16(); - - FOR ( i = 0; i < size; i++) - { - if( abs_s(magn_fx[i]) > 1 ) - { - flag_g1 = 1; - move16(); - } - } - /* prepare vector for TCQ */ - FOR ( i = 0; i < size; i++) - { - test(); - IF (flag_g1 == 0 || sub(*bcount, 2*TCQ_AMP) >= 0) - { - BREAK; - } - - IF ( abs_s(magn_fx[i]) > 0 ) - { - abuffer[*bcount] = quants_fx[i]; - move32(); - mbuffer[*bcount] = magn_fx[i]; - move16(); - /*sbuffer[*bcount] = scale_fx32;*/ - exp = norm_s(pulsesnum); - tmp16 = div_l( actualt_fx, shl( pulsesnum, exp-1) ); - tmp32 = L_shl( L_deposit_l(tmp16), exp); - /*sbuffer[*bcount] = 1/((float)tmp32/pow(2.0, 12));*/ - sbuffer[*bcount] = tmp32;/*Q12*/ move32(); - /*sbuffer[*bcount] = (float)scale_fx32 / pow(2.0, Qscale);*/ - - (*bcount)++; - - } - } - } - *qscale_fx = scale_fx32; - move32(); - } - - return L_shl(magnbits_fx, 1); -} - -void TCQLSB_fx(Word16 bcount, Word32 *abuffer_fx, Word16 *mbuffer_fx, Word32 *sbuffer_fx, Word16 *dpath) -{ - Word16 i, st, dminpos, position; - Word16 q_fx = 6554;/*Q15*/ - Word32 dmin_fx, curdist1_fx, curdist2_fx, newdist1_fx, newdist2_fx; - Word16 path[STATES_LSB][TCQ_LSB_SIZE]; - Word16 quant[STATES_LSB][TCQ_LSB_SIZE]; - Word16 dquant[STATES_LSB][TCQ_LSB_SIZE]; - Word16 qout[TCQ_LSB_SIZE]; - Word32 s1_fx, s2_fx, a1_fx, a2_fx; - Word16 s1_fx16, s2_fx16; - Word16 q1_fx, q2_fx, sign1_fx, sign2_fx; - Word16 dbuffer_fx[MAX_PULSES]; - - Word32 tmp1, tmp2; - Word16 exp1, exp2; - Word32 metric_fx[STATES_LSB][TCQ_LSB_SIZE]; - Word32 MaxPath; - - set32_fx(*metric_fx, 0, STATES_LSB*TCQ_LSB_SIZE); - set16_fx( *path, 0, STATES_LSB*TCQ_LSB_SIZE ); - set16_fx( *quant, 0, STATES_LSB*TCQ_LSB_SIZE ); - set16_fx( *dquant, 0, STATES_LSB*TCQ_LSB_SIZE ); - set16_fx( qout, 0, TCQ_LSB_SIZE ); - - metric_fx[1][0] = MAX_32>>8; - move32(); - metric_fx[2][0] = MAX_32>>8; - move32(); - metric_fx[3][0] = MAX_32>>8; - move32(); - - FOR( i = 0; i < 2*TCQ_AMP; i+=2 ) - { - q1_fx = mbuffer_fx[i]; - move16(); - q2_fx = mbuffer_fx[i + 1]; - move16(); - - s1_fx= L_add(sbuffer_fx[i], 0); /*12*/ - s2_fx = L_add(sbuffer_fx[i + 1], 0); /*12*/ - exp1 = norm_l(s1_fx); - exp2 = norm_l(s2_fx); - s1_fx16 = extract_h(L_shl(s1_fx, exp1));/*12 + exp1 - 16*/ - s2_fx16 = extract_h(L_shl(s2_fx, exp2));/*12 + exp2 - 16*/ - exp1 = 12 + exp1 - 16; - move16(); - exp2 = 12 + exp2 - 16; - move16(); - - a1_fx = L_add(abuffer_fx[i], 0); - a2_fx = L_add(abuffer_fx[i + 1], 0); - - MaxPath = L_add(MAX_32, 0); - - /* cycle over conditions */ - FOR ( st = 0; st < 4; st++) - { - curdist1_fx = L_add(metric_fx[ step_LSB_fx[st][0] ][i/2], 0); - curdist2_fx = L_add(metric_fx[ step_LSB_fx[st][1] ][i/2], 0); - - /* step 1 */ - /*sign1_fx = (denc_LSB[st][0] & 0x1)?(q_fx):(-q_fx);*/ - IF (s_and(denc_LSB_fx[st][0], 0x1)) - { - sign1_fx = q_fx; - move16(); - } - ELSE - { - sign1_fx = negate(q_fx); - } - /*sign2_fx = (denc_LSB[st][0] & 0x2)?(q_fx):(-q_fx);*/ - IF (s_and(denc_LSB_fx[st][0], 0x2)) - { - sign2_fx = q_fx; - move16(); - } - ELSE - { - sign2_fx = negate(q_fx); - } - tmp1 = L_sub(a1_fx, L_shl(Mult_32_16(L_add(L_shl(q1_fx, 15), sign1_fx), s1_fx16), sub(12+2, exp1)));/*12*/ - tmp2 = L_sub(a2_fx, L_shl(Mult_32_16(L_add(L_shl(q2_fx, 15), sign2_fx), s2_fx16), sub(12+2, exp2)));/*12*/ - newdist1_fx = L_add(Mult_32_32(tmp1, tmp1), Mult_32_32(tmp2, tmp2)); /* -7 */ - - /* step 2 */ - /*sign1_fx = (denc_LSB[st][1] & 0x1)?(q_fx):(-q_fx);*/ - IF (s_and(denc_LSB_fx[st][1], 0x1)) - { - sign1_fx = q_fx; - move16(); - } - ELSE - { - sign1_fx = negate(q_fx); - } - /*sign2_fx = (denc_LSB[st][1] & 0x2)?(q_fx):(-q_fx);*/ - IF (s_and(denc_LSB_fx[st][1], 0x2)) - { - sign2_fx = q_fx; - move16(); - } - ELSE - { - sign2_fx = negate(q_fx); - } - tmp1 = L_sub(a1_fx, L_shl(Mult_32_16(L_add(L_shl(q1_fx, 15), sign1_fx), s1_fx16), sub(12+2, exp1)));/*12*/ - tmp2 = L_sub(a2_fx, L_shl(Mult_32_16(L_add(L_shl(q2_fx, 15), sign2_fx), s2_fx16), sub(12+2, exp2)));/*12*/ - newdist2_fx = L_add(Mult_32_32(tmp1, tmp1), Mult_32_32(tmp2, tmp2));/*-7*/ - - /* decision */ - IF ( L_sub(L_add(curdist1_fx, newdist1_fx), L_add(curdist2_fx, newdist2_fx)) < 0 ) - { - path[st][i/2+1] = step_LSB_fx[st][0]; - move16(); - metric_fx[st][i/2+1] = L_add(curdist1_fx, newdist1_fx); - move32(); - quant[st][i/2+1] = 0; - move16(); - dquant[st][i/2+1] = dqnt_LSB_fx[ step_LSB_fx[st][0] ][st]; - move16(); - } - ELSE - { - path[st][i/2+1] = step_LSB_fx[st][1]; - move16(); - metric_fx[st][i/2+1] = L_add(curdist2_fx, newdist2_fx); - move32(); - quant[st][i/2+1] = 1; - move16(); - dquant[st][i/2+1] = dqnt_LSB_fx[ step_LSB_fx[st][0] ][st]; - move16(); - } - - if( L_sub( MaxPath, metric_fx[st][i/2+1]) > 0 ) - { - MaxPath = L_add(metric_fx[st][i/2+1], 0); - } - } - /* Metric renormalization to prevent overflow */ - FOR ( st = 0; st < 4; st++) - { - metric_fx[st][i/2+1] = L_sub( metric_fx[st][i/2+1], MaxPath ); - move32(); - } - } - - /* Find path with minimal metric */ - dminpos = 0; - move16(); - dmin_fx = L_add(metric_fx[ dminpos][ i/2], 0); - FOR ( st = 1; st < 4; st++) - { - IF ( L_sub(dmin_fx, metric_fx[ st][ i/2]) > 0 ) - { - dmin_fx = L_add(metric_fx[ st][ i/2], 0); - dminpos = st; - move16(); - } - } - - /* Trace back to get output */ - position = dminpos; - move16(); - - FOR ( ; i >= 0; i-=2) - { - qout[i/2] = quant[position][ i/2+1 ]; - move16(); - dpath[i/2] = dquant[position][ i/2+1 ]; - move16(); - - IF (s_and(denc_LSB_fx[position][qout[i/2]], 0x1)) - { - dbuffer_fx[i] = 1; - move16(); - } - ELSE - { - dbuffer_fx[i] = -1; - move16(); - } - IF (s_and(denc_LSB_fx[position][qout[i/2]], 0x2)) - { - dbuffer_fx[i + 1] = 1; - move16(); - } - ELSE - { - dbuffer_fx[i + 1] = -1; - move16(); - } - - position = path[position][i/2+1]; - move16(); - } - - /* add decoded sequence to quanta */ - FOR ( i = 0; i < bcount; i++ ) - { - mbuffer_fx[i] = add(add(mbuffer_fx[i], shl(mbuffer_fx[i], 2)), dbuffer_fx[i]); - } - - return; -} -void TCQLSBdec_fx( Word16 *dpath, Word16 *mbuffer, Word16 bcount ) -{ - /*float q = QTCQ;*/ - Word16 q = 1;/*x5*/ - Word16 i, tmp, state = 0; - - tmp = shr(bcount, 1); - FOR ( i = 0; i < tmp; i++) - { - IF (s_and(ddec_LSB_fx[state][dpath[i]], 0x1)) - { - mbuffer[2*i] = q; - move16(); - } - ELSE - { - mbuffer[2*i] = negate(q); - } - - IF (s_and(ddec_LSB_fx[state][dpath[i]], 0x2)) - { - mbuffer[2*i + 1] = q; - move16(); - } - ELSE - { - mbuffer[2*i + 1] = negate(q); - } - - state = dstep_LSB_fx[state][dpath[i]]; - move16(); - } - - return; -} -void RestoreTCQ_fx( Word16 * magn, Word16 size, Word16 *bcount, Word16 *mbuffer) -{ - Word16 i, nzpos = 0, flag_g1 = 0; - - /* calculate actual nz positions */ - nzpos = 0; - move16(); - FOR ( i = 0; i < size; i++) - { - IF ( magn[i] != 0 ) - { - nzpos = add(nzpos, 1); - if ( sub(abs_s(magn[i]), 5) > 0 ) - { - flag_g1 = 1; - move16(); - } - } - } - - IF ( sub(nzpos, 1) > 0) - { - FOR( i = 0; i < size; i++) - { - test(); - IF (flag_g1 == 0 || sub(*bcount, 2*TCQ_AMP) >= 0) - { - BREAK; - } - - IF( abs_s(magn[i]) > 0 ) - { - magn[i] = mbuffer[*bcount]; - move16(); - *bcount = add(*bcount, 1); - } - } - } - - return; -} -void RestoreTCQdec_fx( Word16 * magn, Word16 size, Word16 *bcount, Word16 *mbuffer) -{ - Word16 i, nzpos = 0, flag_g1 = 0; - - /* calculate actual nz positions */ - nzpos = 0; - move16(); - FOR ( i = 0; i < size; i++) - { - IF( magn[i] != 0 ) - { - nzpos = add(nzpos, 1); - if ( sub(abs_s(magn[i]), 1) > 0 ) - { - flag_g1 = 1; - move16(); - } - magn[i] = extract_l(L_mult0(magn[i], 5)); - } - } - - IF( sub(nzpos, 1) > 0) - { - FOR ( i = 0; i < size; i++) - { - test(); - IF (!(flag_g1 && sub(*bcount, 2*TCQ_AMP) < 0)) - { - BREAK; - } - - IF ( magn[i] != 0 ) - { - mbuffer[*bcount] = add(magn[i], mbuffer[*bcount]); - move16(); - magn[i] = mbuffer[*bcount]; - move16(); - *bcount = add(*bcount, 1); - } - } - } - - return; -} - -void InitLSBTCQ_fx(Word16 *bcount) -{ - *bcount = 0; - move16(); - - return; -} -void SaveTCQdata_fx( PARCODEC_FX arInst, Word16 *dpath, Word16 bcount) -{ - Word16 i; - FOR ( i = 0; i < bcount; i++) - { - ar_encode_uniform_fx( arInst, dpath[i], 1); - } - - return; -} -void LoadTCQdata_fx( PARCODEC_FX arInst, Word16 *dpath, Word16 bcount) -{ - Word32 i; - FOR ( i = 0; i < bcount; i++) - { - dpath[i] = ar_decode_fx( arInst, uniform_model_fx ); - } - - return; -} - - -Word32 encode_position_ari_fx(PARCODEC_FX parenc, Word16* quants, Word16 size, Word32* est_bits_frame_fx) -{ - Word16 i, tmp; - Word16 nz = 0, pulses = 0; - Word16 prob[TCQ_MAX_BAND_SIZE]; - Word16 model_num_nz[TCQ_MAX_BAND_SIZE]; - Word16 *cur_quants = quants; - Word16 integer, frac; - Word32 /*est_bits_frame_fx, */btcq_fx = 0, bits_fx = 0, pnzp_fx; - - Word32 cp, scp, fxone, fxp1; - Word16 pos; - - fxone = 32768; - move32(); - fxp1 = 512*32768; - move32(); - - - - set16_fx( prob, 0, TCQ_MAX_BAND_SIZE ); - set16_fx( model_num_nz, 0, TCQ_MAX_BAND_SIZE ); - - FOR (i = 0; i < size; i ++) - { - pulses = add(pulses, abs_s(cur_quants[i])); - if (cur_quants[i] != 0) - { - nz = add(nz, 1); - } - } - - btcq_fx = GetBitsFromPulses_fx(pulses, size); - /* Estimate TCQ bits */ - bits_fx = L_sub(table_logcum_fx[size + 1], L_add(table_logcum_fx[nz + 1], table_logcum_fx[size - nz + 1])); - bits_fx = L_add(bits_fx, L_sub(btcq_fx, L_sub(table_logcum_fx[size + 1], L_add(table_logcum_fx[nz + 1], table_logcum_fx[size - nz + 1])))); - bits_fx = L_sub(bits_fx, L_sub(table_logcum_fx[pulses], L_add(table_logcum_fx[nz], table_logcum_fx[pulses - (nz - 1)]))); - bits_fx = L_sub(bits_fx, nz); - *est_bits_frame_fx = L_add(*est_bits_frame_fx, bits_fx); - - /*caculate the #nz probability */ - tmp = s_min(pulses, size); - FOR (i = 0; i < tmp; i++) - { - pnzp_fx = L_sub(L_deposit_h(add(i, 1)), btcq_fx); - pnzp_fx = L_add(pnzp_fx, L_add(L_sub(table_logcum_fx[size + 1], L_add(table_logcum_fx[i + 2], table_logcum_fx[size - i])), - L_sub(table_logcum_fx[pulses], L_add(table_logcum_fx[i + 1], table_logcum_fx[pulses - i])))); - pnzp_fx = L_add(pnzp_fx, 917498);/*16 */ - IF( L_sub( pnzp_fx, 0) > 0) - { - integer = extract_h(pnzp_fx); - frac = extract_l(L_shr(L_sub(pnzp_fx, L_deposit_h(integer)), 1));/*15 */ - prob[i] = extract_h(L_shl(Pow2(integer, frac), 16));/*0 */ - - /*zero probability will incur problems in ar_make_model() */ - if (prob[i] == 0) - { - prob[i] = 1; - move16(); - } - } - ELSE - { - prob[i] = 1; - move16(); - } - } - - ar_make_model_fx(prob, model_num_nz, s_min(pulses, size)); - - IF (sub(nz, 1) > 0) - { - ar_encode_fx(parenc, model_num_nz, nz - 1);/*encode #nz */ - scp = L_add(fxp1, 0); - pos = 0; - move16(); - FOR( i = 0; i < size; i++) - { - IF (nz <= 0) - { - BREAK; - } - - IF( nz == (size - i) ) - { - cp = L_deposit_l(0); - } - ELSE - { - cp = L_sub( fxone, div_l( L_deposit_h(nz), (size - i)) ); - } - scp = Mult_32_16( scp, extract_l(cp) ); - model_num_nz[pos+1] = round_fx( L_shl( scp, 6) ); - - test(); - test(); - IF( (model_num_nz[pos+1] == 0 && scp > 0) || model_num_nz[pos] == model_num_nz[pos+1] ) - { - model_num_nz[pos+1] = 0; - move16(); - ar_encode_fx( parenc, model_num_nz, pos ); - i--; - move16(); - scp = L_add(fxp1, 0); - pos = 0; - move16(); - CONTINUE; - } - - IF( cur_quants[i] != 0 ) - { - ar_encode_fx( parenc, model_num_nz, pos ); - pos = 0; - move16(); - scp = L_add(fxp1, 0); - nz--; - move16(); - } - ELSE - { - pos++; - move16(); - } - } - } - ELSE IF (sub(nz, 1) == 0) - { - IF (sub(pulses, 1) > 0) - { - /*temp -= log2_f((float)(model_num_nz[nz-1] - model_num_nz[nz]) / MAX_AR_FREQ); */ - ar_encode_fx(parenc, model_num_nz, 0);/*encode #nz */ - } - pos = 0; - move16(); - FOR( i = 0; i < size; i++) - { - model_num_nz[i+1] = round_fx( L_shr( L_deposit_h( div_l( L_deposit_h(size - i - 1), size)), 1) ); - - if( cur_quants[i] != 0 ) - { - pos = i; - move16(); - } - } - ar_encode_fx( parenc, model_num_nz, pos ); /* encode pos */ - } - return bits_fx; -} -Word32 encode_magnitude_usq_fx(ARCODEC_FX* parenc, Word16* magn_fx, Word16 size, Word16 npulses, Word16 nzpos, Word32* est_frame_bits_fx) -{ - Word16 i, j, k, tmp, magnp, magnzp; - Word16 magn_position[MAX_PULSES]; - Word32 /*est_frame_bits_fx, */bits_fx; - Word16 pos, model_m[MAX_PULSES + 2]; - Word32 fxone, fxp1, cp, scp; - - fxone = 32768; - move32(); - fxp1 = 512*32768; - move32(); - - - /*estimate fac bits */ - bits_fx = L_sub(table_logcum_fx[npulses], L_add(table_logcum_fx[nzpos], table_logcum_fx[npulses - nzpos + 1])); - *est_frame_bits_fx = L_add(*est_frame_bits_fx, bits_fx); - - test(); - IF (sub(npulses, nzpos) == 0 || sub(nzpos, 1) == 0) - { - return bits_fx; - } - magnp = sub(npulses, 1); - magnzp = sub(nzpos, 1); - - /*generate the binary sequences of magnitudes */ - k = 0; - move16(); - FOR (i = 0; i < size; i++) - { - IF (magn_fx[i] != 0) - { - tmp = sub(abs_s(magn_fx[i]), 1); - FOR (j = 0; j < tmp; j++) - { - magn_position[k++] = 0; - move16(); - } - magn_position[k++] = 1; - move16(); - } - } - - set16_fx( model_m, 0, MAX_PULSES + 2); - scp = L_add(fxp1, 0); - model_m[0] = MAX_AR_FREQ; - move16(); - pos = 0; - move16(); - tmp = sub(npulses, 1); - FOR( i = 0; i < tmp; i++ ) - { - IF (magnzp <= 0) - { - BREAK; - } - - IF( magnzp == magnp ) - { - cp = L_deposit_l(0); - } - ELSE - { - cp = L_sub( fxone, div_l( L_deposit_h(magnzp), magnp) ); - } - scp = Mult_32_16( scp, extract_l(cp) ); - model_m[pos+1] = round_fx( L_shl( scp, 6) ); - - test(); - test(); - IF( (model_m[pos+1] == 0 && scp > 0) || model_m[pos] == model_m[pos+1] ) - { - model_m[pos+1] = 0; - move16(); - - ar_encode_fx( parenc, model_m, pos ); - pos = 0; - move16(); - i--; - move16(); - scp = L_add(fxp1, 0); - CONTINUE; - } - - IF( magn_position[i] != 0 ) - { - ar_encode_fx( parenc, model_m, pos ); - pos = 0; - move16(); - magnzp--; - move16(); - scp = L_add(fxp1, 0); - } - ELSE - { - pos++; - move16(); - } - - magnp--; - move16(); - } - return bits_fx; -} -Word32 encode_magnitude_tcq_fx(ARCODEC_FX* parenc, Word16* magn_fx, Word16 size, Word16 npulses, Word16 nzpos, Word32* savedstates, Word32* est_frame_bits_fx) -{ - Word32 tcq_bits_fx, bits_fx/*, est_frame_bits_fx*/; - Word16 prob0_fx, prob1_fx, num, denum, quantum1_fx, quantum2_fx; - Word16 exp, exp1, exp2; - - Word16 i, j; - Word32 st; - Word16 magn_mode[3] = {MAX_AR_FREQ, 0, 0}; - - Word16 leftp = npulses;/*pulsesnum; */ - Word16 leftnz = nzpos;/*nzpos; */ - move16(); - move16(); - - bits_fx = L_deposit_l(0); - tcq_bits_fx = L_sub(table_logcum_fx[npulses], L_add(table_logcum_fx[nzpos], table_logcum_fx[npulses - (nzpos - 1)])); - *est_frame_bits_fx = L_add(*est_frame_bits_fx, tcq_bits_fx); - - test(); - IF (sub(nzpos, npulses) == 0 || sub(nzpos, 1) == 0) - { - return bits_fx; - } - - st = L_deposit_l(0); - FOR ( i = 0; i < size; i++) - { - IF (sub(leftnz, 1) <= 0) - { - BREAK; - } - - st = L_add(savedstates[i], 0); - IF (magn_fx[i] != 0) - { - FOR ( j = 0; j < leftp; j++) - { - /*calculate the two path probs point to next two states */ - num = sub(leftnz, 1); - denum = sub(leftp, add(j, 0x1)); - IF (sub(num, denum) >= 0) - { - prob1_fx = MAX_16; - move16(); - prob0_fx = 0; - move16(); - } - ELSE - { - exp1 = sub(norm_s(num), 1); - exp2 = norm_s(denum); - prob1_fx = div_s(shl(num, exp1), shl(denum, exp2));/*15 + exp1 - exp2 */ - exp = 15 + exp1 - exp2; - move16(); - prob1_fx = shl(prob1_fx, sub(15, exp)); - prob0_fx = sub(MAX_16, prob1_fx); - } - - quantum1_fx = quantize_fx(shl(add(j, 1), 10), ddec_fx[st][0]); - quantum2_fx = quantize_fx(shl(add(j, 1), 10), ddec_fx[st][1]); - - test(); - IF (sub(quantum1_fx, add(j, 1)) != 0 && sub(quantum2_fx, add(j, 1)) != 0) - { - prob0_fx = MAX_16; - move16(); - prob1_fx = 0; - move16(); - } - - test(); - IF (sub(prob0_fx, MAX_16) == 0 || sub(prob1_fx, MAX_16) == 0) - { - CONTINUE; - } - - magn_mode[1] = mult(prob1_fx, MAX_AR_FREQ); - IF (sub(j, sub(abs_s(magn_fx[i]), 1)) < 0) - { - ar_encode_fx(parenc, magn_mode, 0); - } - ELSE - { - IF (sub(leftp, j) > leftnz) - { - ar_encode_fx(parenc, magn_mode, 1); - } - BREAK; - } - } - - leftnz--; - move16(); - leftp = sub(leftp, abs_s( magn_fx[i] )); - } - } - - return bits_fx; -} -Word32 encode_signs_fx(ARCODEC_FX* parenc, Word16* magn, Word16 size, Word16 npos, Word32* est_frame_bits_fx) -{ - Word32 i, sign; - - *est_frame_bits_fx = L_add(*est_frame_bits_fx, L_deposit_h(npos)); - FOR (i = 0; i < size; i++) - { - IF (magn[i] != 0) - { - sign = L_deposit_l(0); - if (magn[i] > 0) - { - sign = L_deposit_l(1); - } - ar_encode_uniform_fx(parenc, sign, 1); - } - } - - return L_deposit_h(npos); -} -void decode_position_ari_fx(PARCODEC_FX pardec, Word16 size, Word16 npulses, Word16* nz, Word16* position) -{ - Word16 i, tmp, nzp; - Word16 mode_num_nz[TCQ_MAX_BAND_SIZE]; - Word16 prob[TCQ_MAX_BAND_SIZE]; - - Word32 btcq_fx, pnzp_fx; - Word16 integer, frac; - Word32 cp, scp, fxone, fxp1; - Word16 stpos = 0, pos, ovrflag = 0, temppos, storepos; - - fxone = 32768; - move32(); - fxp1 = 512*32768; - move32(); - temppos = 0; - move16(); - storepos = 0; - move16(); - - set16_fx( mode_num_nz, 0, TCQ_MAX_BAND_SIZE ); - set16_fx( prob, 0, TCQ_MAX_BAND_SIZE ); - - FOR (i = 0; i < size; i++) - { - position[i] = 0; - move16(); - } - - IF (L_sub(npulses, 1) > 0) - { - btcq_fx = GetBitsFromPulses_fx(npulses, size); - tmp = s_min(npulses, size); - FOR (i = 0; i < tmp; i++) - { - /*calculate the probability of #nz */ - - pnzp_fx = L_sub(L_deposit_h(add(i, 1)), btcq_fx); - pnzp_fx = L_add(pnzp_fx, L_add(L_sub(table_logcum_fx[size + 1], L_add(table_logcum_fx[i + 2], table_logcum_fx[size - i])), - L_sub(table_logcum_fx[npulses], L_add(table_logcum_fx[i + 1], table_logcum_fx[npulses - i])))); - pnzp_fx = L_add(pnzp_fx, 917498);/*16 */ - IF( L_sub( pnzp_fx, 0) > 0) - { - integer = extract_h(pnzp_fx); - frac = extract_l(L_shr(L_sub(pnzp_fx, L_deposit_h(integer)), 1));/*15 */ - prob[i] = extract_h(L_shl(Pow2(integer, frac), 16));/*0 */ - if (prob[i] == 0) - { - prob[i] = 1; - move16(); - } - } - ELSE - { - prob[i] = 1; - move16(); - } - } - - ar_make_model_fx(prob, mode_num_nz, s_min(npulses, size)); - *nz = add(1, ar_decode_fx(pardec, mode_num_nz));/*get #nz */ - nzp = *nz; - move16(); - IF( nzp == 1 ) - { - mode_num_nz[0] = MAX_AR_FREQ; - move16(); - FOR (i = 0; i < size; i ++) - { - mode_num_nz[i+1] = round_fx( L_shr( L_deposit_h( div_l( L_deposit_h(size - i - 1), size)), 1) ); - } - - position[ ar_decode_fx(pardec, mode_num_nz) ] = 1; - move16(); - } - ELSE - { - mode_num_nz[0] = MAX_AR_FREQ; - move16(); - - FOR( ; nzp > 0; nzp-- ) - { - scp = L_add(fxp1, 0); - temppos = 0; - move16(); - storepos = 0; - move16(); - - FOR( i = stpos; i < size; i++) - { - ovrflag = 0; - move16(); - - IF( nzp == (size - i) ) - { - cp = L_deposit_l(0); - } - ELSE - { - cp = L_sub( fxone, div_l( L_deposit_h(nzp), (size - i)) ); - } - scp = Mult_32_16( scp, extract_l(cp) ); - mode_num_nz[i+1-storepos-stpos] = round_fx( L_shl( scp, 6) ); - - test(); - test(); - IF( (mode_num_nz[i+1-storepos-stpos] == 0 && scp > 0) || mode_num_nz[i-storepos-stpos] == mode_num_nz[i+1-storepos-stpos] ) - { - mode_num_nz[i+1-storepos-stpos] = 0; - move16(); - ovrflag = 1; - move16(); - temppos = ar_decode_fx(pardec, mode_num_nz); - move16(); - storepos += temppos; - move16(); - scp = L_add(fxp1, 0); - - IF( temppos == i-stpos) /* esc transmitted */ - { - i--; - move16(); - } - ELSE - { - BREAK; - } - } - } - IF( !ovrflag ) - { - pos = ar_decode_fx(pardec, mode_num_nz) + storepos; - move16(); - } - ELSE - { - pos = storepos; - move16(); - } - - position[ stpos + pos] = 1; - move16(); - stpos += pos + 1; - move16(); - } - } - } - ELSE IF (L_sub(npulses, 1) == 0) - { - *nz = npulses; - move16(); - nzp = *nz; - move16(); - mode_num_nz[0] = MAX_AR_FREQ; - move16(); - FOR (i = 0; i < size; i ++) - { - mode_num_nz[i+1] = round_fx( L_shr( L_deposit_h( div_l( L_deposit_h(size - i - 1), size)), 1) ); - } - - position[ ar_decode_fx(pardec, mode_num_nz) ] = 1; - move16(); - } - ELSE - { - *nz = 0; - move16(); - } - - return; -} -void decode_magnitude_usq_fx(ARCODEC_FX* pardec, Word16 size, Word16 npulses, Word16 nzpos, Word16* positions, Word16* out) -{ - Word16 i, magnp, magnzp; - Word16 magns[TCQ_MAX_BAND_SIZE], magncout = 0; - Word16 storemagn, ovrflag = 0, pos, tempmagn = 0, mmodel[MAX_PULSES+2]; - Word32 cp, scp, fxone, fxp1; - - fxone = 32768; - move32(); - fxp1 = 512*32768; - move32(); - - set16_fx( magns, 1, TCQ_MAX_BAND_SIZE ); - IF (sub(nzpos, npulses) == 0) - { - FOR (i = 0; i < size; i++) - { - out[i] = positions[i]; - move16(); - } - return; - } - ELSE IF (sub(nzpos, 1) == 0) - { - FOR (i = 0; i < size; i++) - { - IF ( positions[i] != 0 ) - { - out[i] = npulses; - move16(); - return; - } - } - } - - magnzp = sub(nzpos, 1); - magnp = sub(npulses, 1); - - magncout = 0; - move16(); - - set16_fx( out, 0, size ); - set16_fx( mmodel, 0, MAX_PULSES+2 ); - - mmodel[0] = MAX_AR_FREQ; - move16(); - magncout = 0; - move16(); - FOR( pos = 0; pos < size; pos++) - { - scp = L_add(fxp1, 0); - IF( positions[pos] != 0) - { - storemagn = 0; - move16(); - - FOR( i = 0; i < magnp; i++) - { - ovrflag = 0; - move16(); - - IF( magnzp == (magnp-i) ) - { - cp = L_deposit_l(0); - } - ELSE - { - cp = L_sub( fxone, div_l( L_deposit_h(magnzp), magnp-i) ); - } - - IF( cp == fxone ) - { - BREAK; - } - - scp = Mult_32_16( scp, extract_l(cp) ); - mmodel[i+1-storemagn] = round_fx( L_shl( scp, 6) ); - - test(); - test(); - IF( (mmodel[i+1- storemagn] == 0 && scp > 0) || mmodel[i- storemagn] == mmodel[i+1- storemagn] ) - { - mmodel[i+1-storemagn] = 0; - move16(); - /* read data */ - tempmagn = ar_decode_fx( pardec, mmodel ); - storemagn += tempmagn; - move16(); - - IF( tempmagn < i ) - { - /* just magnitude */ - ovrflag = 1; - move16(); - BREAK; - } - ELSE - { - /* esc code */ - scp = L_add(fxp1, 0); - i--; - move16(); - } - } - } - - IF( ovrflag ) - { - out[magncout] = storemagn + 1; - move16(); - } - ELSE - { - out[magncout] = ar_decode_fx( pardec, mmodel ) + storemagn + 1; - move16(); - } - magnp -= out[magncout]; - move16(); - magnzp--; - move16(); - magncout++; - move16(); - - IF (magnzp == 0) /* last magnitude generation */ - { - FOR( pos = add(pos,1); pos < size; pos++) - { - IF( positions[pos] != 0) - { - out[magncout] = magnp + 1; - move16(); - return; - } - ELSE - { - out[magncout] = 0; - move16(); - magncout++; - move16(); - } - } - } - ELSE IF(magnzp == magnp) /* rest magnitudes generation */ - { - FOR( pos = add(pos,1); pos < size; pos++) - { - out[magncout] = positions[pos]; - move16(); - magncout++; - move16(); - } - return; - } - } - ELSE - { - out[magncout] = 0; - move16(); - magncout++; - move16(); - } - } - - return; -} -void decode_mangitude_tcq_fx(ARCODEC_FX* pardec, Word16 size, Word16 npulses, Word16 nzpos, Word16* positions, Word16* out, Word32* surplus_fx) -{ - Word32 tcq_bits_fx, bits_fx/*, surplus_fx*/; - Word16 prob0_fx, prob1_fx, num, denum, quantum1_fx, quantum2_fx; - Word16 exp, exp1, exp2, tmp16; - Word32 tmp32; - - Word16 i, j, symbol, st; - Word16 leftp = npulses;/*pulsesnum; */ - Word16 leftnz = nzpos; /*nzpos; */ - Word16 magn_mode[3] = {MAX_AR_FREQ, 0, 0}; - - bits_fx = L_deposit_l(0); - tcq_bits_fx = L_sub(table_logcum_fx[npulses], L_add(table_logcum_fx[nzpos], table_logcum_fx[npulses - (nzpos - 1)])); - - IF (sub(nzpos, npulses) == 0) - { - FOR (i = 0; i < size; i++) - { - out[i] = positions[i]; - move16(); - } - - return; - } - ELSE IF (sub(nzpos, 1) == 0) - { - FOR (i = 0; i < size; i++) - { - IF ( positions[i] != 0 ) - { - out[i] = npulses; - move16(); - return; - } - } - } - st = 0; - move16(); - FOR (i = 0; i < size; i++) - { - IF (sub(leftnz, 1) <= 0) - { - BREAK; - } - - out[i] = positions[i]; - IF (positions[i] != 0) - { - /*generate the trellis path */ - symbol = 0; - move16(); - FOR (j = 0; j < leftp; j++) - { - num = sub(leftnz, 1); - denum = sub(leftp, add(j, 1)); - IF (sub(num, denum) >= 0) - { - prob1_fx = MAX_16; - move16(); - prob0_fx = 0; - move16(); - } - ELSE - { - exp1 = sub(norm_s(num), 1); - exp2 = norm_s(denum); - prob1_fx = div_s(shl(num, exp1), shl(denum, exp2));/*15 + exp1 - exp2 */ - exp = 15 + exp1 - exp2; - prob1_fx = shl(prob1_fx, sub(15, exp)); - prob0_fx = sub(MAX_16, prob1_fx); - } - IF (L_sub(sub(leftp, j), leftnz) == 0) - { - symbol = add(j, 1); - BREAK; - } - - quantum1_fx = quantize_fx(shl(add(j, 1), 10), ddec_fx[st][0]); - quantum2_fx = quantize_fx(shl(add(j, 1), 10), ddec_fx[st][1]); - - test(); - IF (sub(quantum1_fx, add(j, 1)) != 0 && sub(quantum2_fx, add(j, 1)) != 0) - { - prob0_fx = MAX_16; - move16(); - prob1_fx = 0; - move16(); - } - - test(); - IF (sub(prob0_fx, MAX_16) == 0 || sub(prob1_fx, MAX_16) == 0) - { - symbol = add(j, 1); - CONTINUE; - } - - /*magn_mode[1] = (short)(prob1 * MAX_AR_FREQ); */ - magn_mode[1] = mult(prob1_fx, MAX_AR_FREQ); - - IF (ar_decode_fx(pardec, magn_mode)) - { - exp1 = norm_s(prob1_fx); - tmp32 = L_deposit_h(shl(prob1_fx, exp1));/*exp1 + 15 + 16 */ - tmp16 = Log2_norm_lc(tmp32);/*15 */ - bits_fx = L_sub(bits_fx, L_sub(tmp16, L_shl(add(exp1, 1), 15)));/*15 */ - - symbol = add(j, 1); - BREAK; - } - ELSE - { - exp1 = norm_s(prob0_fx); - tmp32 = L_deposit_h(shl(prob0_fx, exp1));/*exp1 + 15 + 16 */ - tmp16 = Log2_norm_lc(tmp32);/*15 */ - bits_fx = L_sub(bits_fx, L_sub(tmp16, L_shl(add(exp1, 1), 15)));/*15 */ - } - } - out[i] = symbol; - move16(); - /*leftp -= symbol; */ - leftp = sub(leftp, symbol); - leftnz = sub(leftnz, 1); - } - - quantum1_fx = quantize_fx(out[i], ddec_fx[st][0]); - quantum2_fx = quantize_fx(out[i], ddec_fx[st][1]); - - /*generate the next state */ - IF (sub(quantum1_fx, out[i]) == 0) - { - st = nextstate[st][0]; - move16(); - } - ELSE - { - st = nextstate[st][1]; - move16(); - } - } - - /*generate the magnitudes */ - FOR (; i < size; i++) - { - out[i] = 0; - move16(); - IF (positions[i] != 0) - { - out[i] = add(sub(leftp, leftnz), 1); - } - - } - - test(); - IF (sub(nzpos, npulses) != 0 && sub(nzpos, 1) > 0) - { - /*update the surplus */ - *surplus_fx = L_add(*surplus_fx, L_sub(tcq_bits_fx, L_shl(bits_fx, 1))); - } - - return; -} - -void decode_signs_fx(ARCODEC_FX* pardec, Word16 size, Word16* out) -{ - Word16 i; - - FOR ( i = 0; i < size; i++) - { - IF ( out[i] != 0 ) - { - Word16 tmp; - tmp = ar_decode_fx( pardec, uniform_model_fx ); - - if( tmp <= 0 ) - { - out[i] = negate(out[i]); - } - } - } - - return; -} - -Word16 GetScale_fx( Word16 blen, Word32 bits_fx/*Q16*/, Word32 *surplus_fx/*Q16*/) -{ - Word16 pulses = MAX_PULSES, p_est, exp, exp1, exp2, magicnum; - Word32 t, a, b, ab, estbits_fx = 0; - - magicnum = 24773; - move16(); /*Q17: 0.188992013101951f; */ - - t = L_shr( L_mult( magicnum, blen), 2); - exp = norm_l(t); - a = L_shl( 14 - exp, 15) + Log2_norm_lc( L_shl( t, exp ) ); - - exp1 = sub( norm_l(bits_fx), 1); - exp2 = norm_s( blen - 1 ); - b = L_shr( L_deposit_l( div_l( L_shl( bits_fx, exp1), shl( blen - 1, exp2) ) ), exp1-exp2 ); - - ab = L_add( a, b); - - p_est = extract_h(L_shl(Pow2( extract_l( L_shr(ab,15) ), ab&0x7FFF ),16)); /* enable saturationof pow2 result */ - - pulses = s_min( p_est, MAX_PULSES ); - - FOR( ; pulses >= 0; pulses--) - { - estbits_fx = GetBitsFromPulses_fx( pulses, blen); - IF( L_sub( bits_fx, estbits_fx) >= 0) - { - BREAK; - } - } - - IF ( surplus_fx != 0 ) - { - *surplus_fx = L_add(*surplus_fx, L_sub(bits_fx, estbits_fx)); - } - - return pulses; -} - -void srt_vec_ind_fx ( - const Word32 *linear, /* linear input */ - Word32 *srt, /* sorted output*/ - Word16 *I, /* index for sorted output */ - Word16 length -) -{ - Word16 pos,npos,tmp; - Word16 idxMem; - Word32 valMem; - - /*initilize */ - FOR (pos = 0; pos < length; pos++) - { - I[pos] = pos; - move16(); - } - - Copy32(linear, srt, length); - - /* now iterate */ - tmp = sub(length, 1); - FOR (pos = 0; pos < tmp; pos++) - { - FOR (npos = add(pos, 1); npos < length; npos++) - { - IF (L_sub(srt[npos], srt[pos]) < 0) - { - idxMem = I[pos]; - move16(); - I[pos] = I[npos]; - move16(); - I[npos] = idxMem; - move16(); - - valMem = L_add(srt[pos], 0); - srt[pos] = srt[npos]; - move32(); - srt[npos] = valMem; - move32(); - } - } - } - - return; -} diff --git a/src/libs/libevs/lib_com/tcx_ltp.cpp b/src/libs/libevs/lib_com/tcx_ltp.cpp old mode 100755 new mode 100644 index 3fea3a88..070e0560 --- a/src/libs/libevs/lib_com/tcx_ltp.cpp +++ b/src/libs/libevs/lib_com/tcx_ltp.cpp @@ -1,103 +1,84 @@ /*==================================================================================== - EVS Codec 3GPP TS26.442 Apr 03, 2018. Version 12.11.0 / 13.6.0 / 14.2.0 + EVS Codec 3GPP TS26.443 Nov 13, 2018. Version 12.11.0 / 13.7.0 / 14.3.0 / 15.1.0 ====================================================================================*/ -#include #include "options.h" -#include "prot_fx.h" -#include "stl.h" -#include "cnst_fx.h" -#include "basop_util.h" -#include "rom_com_fx.h" - -#define ALPHA 27853/*0.85f Q15*/ +#include "prot.h" +#include "rom_com.h" +#include "assert.h" -void tcx_ltp_get_lpc(Word16 *x, Word16 L, Word16 *A, Word16 order) +/*------------------------------------------------------------------- + * Local constants + *-------------------------------------------------------------------*/ + +#define ALPHA 0.85f + + +/*------------------------------------------------------------------- + * tcx_ltp_get_lpc() + * + * + *-------------------------------------------------------------------*/ + +static void tcx_ltp_get_lpc( + float *input, + int length, + float *A, + int lpcorder +) { - Word16 i, j, s, s2, tmp; - Word32 r, L_tmp; + int i, j; + float s, r[TCXLTP_LTP_ORDER+1]; - Word16 tmpbuf[L_FRAME_MAX], *p = x; - Word16 r_l[TCXLTP_LTP_ORDER+1], r_h[TCXLTP_LTP_ORDER+1]; - - - assert(L <= L_FRAME_MAX); - - /* calc r[0], determine shift */ - s = 0; - move16(); - r = L_deposit_l(0); - FOR (j = 0; j < L; j++) + for (i = 0; i <= lpcorder; i++) { - L_tmp = L_sub(r, 0x40000000); - if (L_tmp > 0) s = sub(s, 1); - if (L_tmp > 0) r = L_shr(r, 2); + s = 0.0; - tmp = shl(x[j], s); - r = L_mac0(r, tmp, tmp); - } - r = L_max(r, L_shl(100, shl(s, 1))); - r = Mpy_32_16_1(r, 16386/*1.0001f Q14*/); - s2 = norm_l(r); - r = L_shl(r, s2); - s2 = sub(s2, 1); - r_l[0] = L_Extract_lc(r, &r_h[0]); - move16(); - move16(); - - IF (s < 0) - { - /* shift buffer by s, recompute r[0] to reduce risk of instable LPC */ - r = L_deposit_l(0); - tmp = lshl((Word16)0x8000, s); /* factor corresponding to right shift by -s */ - - FOR (j = 0; j < L; j++) + for (j = 0; j < length-i; j++) { - tmpbuf[j] = mult_r(x[j], tmp); - move16(); - r = L_mac0(r, tmpbuf[j], tmpbuf[j]); + s += input[j]*input[j+i]; } - r = L_max(r, L_shl(100, shl(s, 1))); - r = Mpy_32_16_1(r, 16386/*1.0001f Q14*/); - s2 = norm_l(r); - r = L_shl(r, s2); - s2 = sub(s2, 1); - r_l[0] = L_Extract_lc(r, &r_h[0]); - move16(); - move16(); - - p = tmpbuf; + r[i] = s; } - /* calc r[1...] */ - FOR (i = 1; i <= order; i++) + if (r[0] < 100.0f) { - r = L_deposit_l(0); - - tmp = sub(L, i); - FOR (j = 0; j < tmp; j++) - { - r = L_mac0(r, p[j], p[j+i]); - } - r = L_shl(r, s2); - r_l[i] = L_Extract_lc(r, &r_h[i]); - move16(); - move16(); + r[0] = 100.0f; } + r[0] *= 1.0001f; - E_LPC_lev_dur(r_h, r_l, A, NULL, order, NULL); + lev_dur( A, r, lpcorder, NULL ); + return; } -static void tcx_ltp_get_zir( Word16 *zir, Word16 length, Word16 *synth_ltp, Word16 *synth, Word16 *A, Word16 lpcorder, Word16 gain, Word16 pitch_int, Word16 pitch_fr, Word16 pitres, Word16 filtIdx ) + +/*------------------------------------------------------------------- + * tcx_ltp_get_zir() + * + * + *-------------------------------------------------------------------*/ + +static void tcx_ltp_get_zir( + float *zir, + int length, + float *synth_ltp, + float *synth, + float *A, + int lpcorder, + float gain, + int pitch_int, + int pitch_fr, + int pitres, + int filtIdx +) { - Word16 buf[TCXLTP_LTP_ORDER], alpha, step; - Word16 *x0, *x1; - Word16 *y0, *y1; - Word32 s, s2; - const Word16 *w0, *w1, *v0, *v1; - Word16 i, j, k, L; + float buf[TCXLTP_LTP_ORDER], alpha, step; + float *x0, *x1, s; + float *y0, *y1, s2; + const float *w0, *w1, *v0, *v1; + int i, j, k, L; x0 = &synth_ltp[-pitch_int]; x1 = x0 - 1; @@ -107,30 +88,23 @@ static void tcx_ltp_get_zir( Word16 *zir, Word16 length, Word16 *synth_ltp, Word assert(filtIdx >= 0); w0 = &tcxLtpFilters[filtIdx].filt[pitch_fr]; - w1 = &tcxLtpFilters[filtIdx].filt[sub(pitres, pitch_fr)]; + w1 = &tcxLtpFilters[filtIdx].filt[pitres - pitch_fr]; v0 = &tcxLtpFilters[filtIdx].filt[0]; v1 = &tcxLtpFilters[filtIdx].filt[pitres]; L = tcxLtpFilters[filtIdx].length; - move16(); - FOR (j = 0; j < lpcorder; j++) + for (j = 0; j < lpcorder; j++) { - s = L_deposit_l(0); - s2 = L_deposit_l(0); - k = 0; - move16(); - FOR (i = 0; i < L; i++) + s = 0; + s2 = 0; + for (i = 0, k = 0; i < L; i++, k += pitres) { - s = L_mac(L_mac(s, w0[k], x0[i]), w1[k], x1[-i]); - s2 = L_mac(L_mac(s2, v0[k], y0[i]), v1[k], y1[-i]); - k = add(k, pitres); + s += w0[k] * x0[i] + w1[k] * x1[-i]; + s2 += v0[k] * y0[i] + v1[k] * y1[-i]; } + s2 *= ALPHA; - /* s2 *= ALPHA; - buf[j] = ( synth[j] - gain * s2 ) - ( synth_ltp[j] - gain * s ); */ - i = sub(round_fx(s), mult_r(round_fx(s2), ALPHA)); - buf[j] = add(sub(synth[j], synth_ltp[j]), mult_r(gain, i)); - move16(); + buf[j] = ( synth[j] - gain * s2 ) - ( synth_ltp[j] - gain * s ); x0++; x1++; @@ -138,94 +112,95 @@ static void tcx_ltp_get_zir( Word16 *zir, Word16 length, Word16 *synth_ltp, Word y1++; } - set16_fx(zir, 0, length); + set_f( zir, 0.0f, length ); - E_UTIL_synthesis(0, A, zir, zir, length, buf, 0, lpcorder); + syn_filt( A, lpcorder, zir, zir, length, buf, 0); - alpha = 0x7FFF; - move16(); - /* step = 1.f/(float)(length/2); */ - step = shl(4, norm_s(length)); - if (s_and(length, sub(length, 1)) != 0) + alpha = 1.f; + step = 1.f/(float)(length/2); + + for ( j=length/2; j 0) +/*------------------------------------------------------------------- + * tcx_ltp_synth_filter() + * + * + *-------------------------------------------------------------------*/ + +static void tcx_ltp_synth_filter( + float *synth_ltp, + float *synth, + int length, + int pitch_int, + int pitch_fr, + float gain, + int pitch_res, + short filtIdx +) +{ + float *x0, *x1, s; + float *y0, *y1, s2; + const float *v0, *v1; + const float *w0, *w1; + int i, j, k, L; + + if ( gain > 0.f ) { x0 = &synth_ltp[-pitch_int]; x1 = x0 - 1; @@ -235,67 +210,25 @@ static void tcx_ltp_synth_filter( Word16 *synth_ltp, assert(filtIdx >= 0); w0 = &tcxLtpFilters[filtIdx].filt[pitch_fr]; - w1 = &tcxLtpFilters[filtIdx].filt[sub(pitch_res, pitch_fr)]; + w1 = &tcxLtpFilters[filtIdx].filt[pitch_res - pitch_fr]; v0 = &tcxLtpFilters[filtIdx].filt[0]; v1 = &tcxLtpFilters[filtIdx].filt[pitch_res]; L = tcxLtpFilters[filtIdx].length; - move16(); - alpha = 0; - move16(); - IF (fade != 0) + + for (j = 0; j < length; j++) { - if (fade < 0) + s = 0; + s2 = 0; + for (i = 0, k = 0; i < L; i++, k += pitch_res) { - alpha = 0x7FFF; - move16(); + s += w0[k] * x0[i] + w1[k] * x1[-i]; + s2 += v0[k] * y0[i] + v1[k] * y1[-i]; } - /* step = 1.f/(float)(length); */ - step = shl(2, norm_s(length)); - if (s_and(length, sub(length, 1)) != 0) - { - step = mult_r(step, 26214/*64.f/80.f Q15*/); - } - if (sub(length, 240) == 0) - { - step = 137/*1.f/240.f Q15*/; - move16(); - } - - if (fade < 0) step = negate(step); - } - - FOR (j = 0; j < length; j++) - { - s = L_deposit_l(0); - s2 = L_deposit_l(0); - k = 0; - move16(); - FOR (i = 0; i < L; i++) - { - s = L_mac(L_mac(s, w0[k], x0[i]), w1[k], x1[-i]); - s2 = L_mac(L_mac(s2, v0[k], y0[i]), v1[k], y1[-i]); - k = add(k, pitch_res); - } - - /* s2 *= ALPHA; - normal: synth_ltp[j] = synth[j] - gain * s2 + gain * s; - zir: synth_ltp[j] = synth[j] - gain * s2 + gain * s - zir[j]; - fade-in/out: synth_ltp[j] = synth[j] - alpha * gain * s2 + alpha * gain * s; */ - i = sub(round_fx(s), mult_r(round_fx(s2), ALPHA)); - k = mult_r(gain, i); - if (fade != 0) k = mult_r(k, alpha); - k = add(synth[j], k); - if (zir != NULL) k = sub(k, zir[j]); - - synth_ltp[j] = k; - move16(); - - BASOP_SATURATE_WARNING_OFF; - if (fade != 0) alpha = add(alpha, step); - BASOP_SATURATE_WARNING_ON; + s2 *= ALPHA; + synth_ltp[j] = synth[j] - gain * s2 + gain * s; x0++; x1++; @@ -303,413 +236,516 @@ static void tcx_ltp_synth_filter( Word16 *synth_ltp, y1++; } } - ELSE + else { - Copy( synth, synth_ltp, length ); + mvr2r( synth, synth_ltp, length ); } + + return; } -Word16 tcx_ltp_decode_params( Word16 *ltp_param, - Word16 *pitch_int, - Word16 *pitch_fr, - Word16 *gain, - Word16 pitmin, - Word16 pitfr1, - Word16 pitfr2, - Word16 pitmax, - Word16 pitres - ) + +/*------------------------------------------------------------------- + * tcx_ltp_synth_filter_zir() + * + * + *-------------------------------------------------------------------*/ + +static void tcx_ltp_synth_filter_zir( + float *synth_ltp, + float *synth, + int length, + int pitch_int, + int pitch_fr, + float gain, + int pitch_res, + float *zir, + short filtIdx +) { - Word16 tmp, tmp2; + float *x0, *x1, s; + float *y0, *y1, s2; + const float *v0, *v1; + const float *w0, *w1; + int i, j, k, L; + + x0 = &synth_ltp[-pitch_int]; + x1 = x0 - 1; + y0 = synth; + y1 = y0 - 1; + + assert(filtIdx >= 0); + + w0 = &tcxLtpFilters[filtIdx].filt[pitch_fr]; + w1 = &tcxLtpFilters[filtIdx].filt[pitch_res - pitch_fr]; + v0 = &tcxLtpFilters[filtIdx].filt[0]; + v1 = &tcxLtpFilters[filtIdx].filt[pitch_res]; + L = tcxLtpFilters[filtIdx].length; + + for (j = 0; j < length; j++) + { + s = 0; + s2 = 0; + + for (i = 0, k = 0; i < L; i++, k += pitch_res) + { + s += w0[k] * x0[i] + w1[k] * x1[-i]; + s2 += v0[k] * y0[i] + v1[k] * y1[-i]; + } + + s2 *= ALPHA; + + synth_ltp[j] = ( synth[j] - gain * s2 + gain * s ) -zir[j]; + + x0++; + x1++; + y0++; + y1++; + } + + return; +} +/*------------------------------------------------------------------- + * tcx_ltp_synth_filter_fadein() + * + * + *-------------------------------------------------------------------*/ + +static void tcx_ltp_synth_filter_fadein( + float *synth_ltp, + float *synth, + int length, + int pitch_int, + int pitch_fr, + float gain, + int pitch_res, + short filtIdx +) +{ + float *x0, *x1, s; + float *y0, *y1, s2; + const float *v0, *v1; + const float *w0, *w1; + int i, j, k, L; + float alpha, step; + + if ( gain > 0.f ) + { + x0 = &synth_ltp[-pitch_int]; + x1 = x0 - 1; + y0 = synth; + y1 = y0 - 1; + + assert(filtIdx >= 0); + + w0 = &tcxLtpFilters[filtIdx].filt[pitch_fr]; + w1 = &tcxLtpFilters[filtIdx].filt[pitch_res - pitch_fr]; + v0 = &tcxLtpFilters[filtIdx].filt[0]; + v1 = &tcxLtpFilters[filtIdx].filt[pitch_res]; + L = tcxLtpFilters[filtIdx].length; + + alpha = 0.f; + step = 1.f/(float)(length); + + + for (j = 0; j < length; j++) + { + s = 0; + s2 = 0; + + for (i = 0, k = 0; i < L; i++, k += pitch_res) + { + s += w0[k] * x0[i] + w1[k] * x1[-i]; + s2 += v0[k] * y0[i] + v1[k] * y1[-i]; + } + + s2 *= ALPHA; + + synth_ltp[j] = synth[j] - alpha * gain * s2 + alpha * gain * s; + + alpha += step; + + x0++; + x1++; + y0++; + y1++; + } + } + else + { + mvr2r( synth, synth_ltp, length ); + } + + return; +} + + +/*------------------------------------------------------------------- + * tcx_ltp_synth_filter_fadeout() + * + * + *-------------------------------------------------------------------*/ + +static void tcx_ltp_synth_filter_fadeout( + float *synth_ltp, + float *synth, + int length, + int pitch_int, + int pitch_fr, + float gain, + int pitch_res, + short filtIdx +) +{ + float *x0, *x1, s; + float *y0, *y1, s2; + const float *v0, *v1; + const float *w0, *w1; + int i, j, k, L; + float alpha, step; + + if ( gain > 0.f ) + { + x0 = &synth_ltp[-pitch_int]; + x1 = x0 - 1; + y0 = synth; + y1 = y0 - 1; + + assert(filtIdx >= 0); + + w0 = &tcxLtpFilters[filtIdx].filt[pitch_fr]; + w1 = &tcxLtpFilters[filtIdx].filt[pitch_res - pitch_fr]; + v0 = &tcxLtpFilters[filtIdx].filt[0]; + v1 = &tcxLtpFilters[filtIdx].filt[pitch_res]; + L = tcxLtpFilters[filtIdx].length; + + alpha = 1.f; + step = 1.f/(float)(length); + + for (j = 0; j < length; j++) + { + s = 0; + s2 = 0; + + for (i = 0, k = 0; i < L; i++, k += pitch_res) + { + s += w0[k] * x0[i] + w1[k] * x1[-i]; + s2 += v0[k] * y0[i] + v1[k] * y1[-i]; + } + + s2 *= ALPHA; + synth_ltp[j] = synth[j] - alpha * gain * s2 + alpha * gain * s; + alpha -= step; + + x0++; + x1++; + y0++; + y1++; + } + } + else + { + mvr2r( synth, synth_ltp, length ); + } + + return; +} + + +/*------------------------------------------------------------------- + * tcx_ltp_decode_params() + * + * + *-------------------------------------------------------------------*/ +int tcx_ltp_decode_params( + int *ltp_param, + int *pitch_int, + int *pitch_fr, + float *gain, + int pitmin, + int pitfr1, + int pitfr2, + int pitmax, + int pitres +) +{ + int gainbits = 2; /* Decode Pitch and Gain */ - test(); - IF (ltp_param != 0 && ltp_param[0] != 0) + if ((ltp_param) && (ltp_param[0])) { - tmp = imult1616(sub(pitfr2, pitmin), pitres); - - IF ( sub(ltp_param[1], tmp) < 0 ) + if ( ltp_param[1] < ((pitfr2-pitmin)*pitres) ) { - tmp2 = idiv1616U(ltp_param[1], pitres); - - *pitch_int = add(pitmin, tmp2); - move16(); - *pitch_fr = sub(ltp_param[1], imult1616(tmp2, pitres)); - move16(); + *pitch_int = pitmin + (ltp_param[1]/pitres); + *pitch_fr = ltp_param[1] - (*pitch_int - pitmin)*pitres; } - ELSE + else if (ltp_param[1] < ( (pitfr2-pitmin)*pitres + (pitfr1-pitfr2)*(pitres>>1)) ) { - pitres = shr(pitres, 1); - tmp2 = imult1616(sub(pitfr1, pitfr2), pitres); - - IF ( sub(ltp_param[1], add(tmp, tmp2)) < 0 ) - { - tmp2 = idiv1616U(sub(ltp_param[1], tmp), pitres); - - *pitch_int = add(pitfr2, tmp2); - move16(); - *pitch_fr = shl( sub(sub(ltp_param[1], tmp), imult1616(tmp2, pitres)), 1 ); - move16(); - } - ELSE - { - *pitch_int = sub(add(ltp_param[1], pitfr1), add(tmp, tmp2)); - move16(); - *pitch_fr = 0; - move16(); - } + *pitch_int = pitfr2 + ((ltp_param[1]-(pitfr2-pitmin)*pitres)/(pitres>>1)); + *pitch_fr = (ltp_param[1]-(pitfr2-pitmin)*pitres) - (*pitch_int - pitfr2)*(pitres>>1); + *pitch_fr = *pitch_fr << 1; /* was *= (pitres>>1); */ } - - *gain = imult1616(add(ltp_param[2], 1), 0x1400); - move16(); - - IF( sub(*pitch_int,PIT_MIN_SHORTER) < 0 ) + else + { + *pitch_int = ltp_param[1] + pitfr1 - ((pitfr2-pitmin)*pitres) - ((pitfr1-pitfr2)*(pitres>>1)); + *pitch_fr = 0; + } + *gain = (float)(ltp_param[2] + 1) * 0.625f/(float)(1< 0 ) + if(*pitch_int>PIT_MAX_MAX) { /*pitch out of range due to bit error */ *pitch_int = PIT_MAX_MAX; - move16(); return 1; } } - ELSE + else { *pitch_int = pitmax; - move16(); *pitch_fr = 0; - move16(); - *gain = 0; - move16(); + *gain = 0.0f; } - return 0; } -void tcx_ltp_post( Word8 tcxltp_on, - Word16 core, - Word16 L_frame, - Word16 L_frame_core, - Word16 delay, - Word16 *sig, - Word16 *tcx_buf, - Word16 tcx_buf_len, - Word16 bfi, - Word16 pitch_int, - Word16 pitch_fr, - Word16 gain, - Word16 *pitch_int_past, - Word16 *pitch_fr_past, - Word16 *gain_past, - Word16 *filtIdx_past, - Word16 pitres, - Word16 *pitres_past, - Word16 damping, - Word16 SideInfoOnly, - Word16 *mem_in, - Word16 *mem_out, - Word32 bitrate - ) -{ - Word16 tmp, L_transition, lpcorder, filtIdx; - Word16 gain2; - Word32 tmp32; - Word16 zir[L_FRAME_PLUS/4], A[TCXLTP_LTP_ORDER+1]; - Word16 buf_in[TCXLTP_MAX_DELAY+L_FRAME48k+TCXLTP_MAX_DELAY], buf_out[2*L_FRAME48k]; - Word16 *sig_in, *sig_out; - filtIdx = 0; /* just to avoid comilation warnings */ +/*------------------------------------------------------------------- + * tcx_ltp_post() + * + * + *-------------------------------------------------------------------*/ + +void tcx_ltp_post( + int tcxltp_on, + short core, + int L_frame, + int L_frame_core, + int delay, + float *sig, + float *tcx_buf, + short tcx_buf_len, + int bfi, + int pitch_int, + int pitch_fr, + float gain, + int *pitch_int_past, + int *pitch_fr_past, + float *gain_past, + int *filtIdx_past, + int pitres, + int *pitres_past, + float damping, + int SideInfoOnly, + float *mem_in, + float *mem_out, + int bitrate +) +{ + int tmp, L_transition, lpcorder, filtIdx; + float gain2; + float zir[L_FRAME_PLUS/4], A[TCXLTP_LTP_ORDER+1]; + float buf_in[TCXLTP_MAX_DELAY+L_FRAME48k+TCXLTP_MAX_DELAY], buf_out[2*L_FRAME48k]; + float *sig_in, *sig_out; + + + filtIdx = 0; /* just to avoid compilation warnings */ /******** Init ********/ - /* Parameters */ - L_transition = shr(L_frame, 2); + L_transition = L_frame/4; lpcorder = TCXLTP_LTP_ORDER; - move16(); /* Input buffer */ sig_in = buf_in + tcx_buf_len; - Copy( mem_in, buf_in, tcx_buf_len ); - Copy( sig, buf_in+tcx_buf_len, L_frame ); - IF ( core > ACELP_CORE ) + mvr2r( mem_in, buf_in, tcx_buf_len ); + mvr2r( sig, buf_in+tcx_buf_len, L_frame ); + if ( core > ACELP_CORE ) { - Copy( tcx_buf, sig_in+L_frame, tcx_buf_len ); + mvr2r( tcx_buf, sig_in+L_frame, tcx_buf_len ); } - Copy( sig+L_frame-tcx_buf_len, mem_in, tcx_buf_len ); + mvr2r( sig+L_frame-tcx_buf_len, mem_in, tcx_buf_len ); /* Output buffer */ sig_out = buf_out + L_frame; - Copy( mem_out, buf_out, L_frame ); + mvr2r( mem_out, buf_out, L_frame ); /* TCX-LTP parameters: integer pitch, fractional pitch, gain */ - test(); - test(); - IF ( !(SideInfoOnly != 0 || tcxltp_on != 0) || sub(core, ACELP_CORE) == 0 ) + + if ( !(SideInfoOnly || tcxltp_on) || core==ACELP_CORE ) { /* No LTP */ pitch_int = 0; - move16(); pitch_fr = 0; - move16(); - gain = 0; - move16(); + gain = 0.f; } - ELSE IF (bfi == 0) + else if ( !bfi ) { /* LTP and good frame */ - IF (sub(L_frame, L_frame_core) != 0) + if (L_frame != L_frame_core) { - tmp = div_s(L_frame, shl(L_frame_core, 2)); /* Q13 */ - tmp32 = L_mult0(add(imult1616(pitch_int, pitres), pitch_fr), tmp); /* Q13 */ - tmp = round_fx(L_shl(tmp32, 3)); /* Q0 */ - pitch_int = idiv1616U(tmp, pitres); - pitch_fr = sub(tmp, imult1616(pitch_int, pitres)); + tmp = pitch_int * pitres + pitch_fr; + tmp = (tmp * L_frame + L_frame_core/2) / L_frame_core; + pitch_int = tmp / pitres; + pitch_fr = tmp % pitres; } - test(); - test(); - IF ( L_sub(bitrate, 48000) == 0 && sub(L_frame_core, L_FRAME16k) == 0 ) + + if ( bitrate == HQ_48k && L_frame_core == L_FRAME16k ) { - gain = mult_r(gain, 10486/*0.32f Q15*/); + gain *= 0.32f; } - ELSE IF ( L_sub(bitrate, 48000) == 0 && sub(L_frame_core, 512) == 0 ) + else if ( bitrate == HQ_48k && L_frame_core == 512 ) { - gain = mult_r(gain, 13107/*0.40f Q15*/); + gain *= 0.40f; } - ELSE + else { - gain = mult_r(gain, 20972/*0.64f Q15*/); + gain *= 0.64f; } + } - ELSE + else { /* PLC: [TCX: Fade-out] * PLC: LTP and bad frame (concealment) */ + pitch_int = *pitch_int_past; - move16(); pitch_fr = *pitch_fr_past; - move16(); - gain = shl(mult_r(*gain_past, damping), 1); + gain = *gain_past * damping; pitres = *pitres_past; } - - IF ( SideInfoOnly != 0 ) + if ( SideInfoOnly ) { - gain = 0; - move16(); - if ( bfi != 0 ) + gain = 0.f; + if ( bfi ) { - *gain_past = 0; - move16(); + *gain_past = 0.f; } } gain2 = gain; - move16(); - IF (sub(L_frame_core, L_FRAME) == 0) + if (L_frame_core == L_FRAME) { - SWITCH ( L_frame ) + switch ( L_frame ) { case L_FRAME8k: filtIdx = 0; - move16(); - BREAK; + break; case L_FRAME16k: filtIdx = 1; - move16(); - BREAK; + break; case L_FRAME32k: filtIdx = 2; - move16(); - BREAK; + break; case L_FRAME48k: filtIdx = 3; - move16(); - BREAK; + break; default: assert(0); + break; } } - ELSE IF (sub(L_frame_core, L_FRAME16k) == 0) + else if (L_frame_core == L_FRAME16k) { - SWITCH ( L_frame ) + switch ( L_frame ) { case L_FRAME8k: filtIdx = 4; - move16(); - BREAK; + break; case L_FRAME16k: filtIdx = 5; - move16(); - BREAK; + break; case L_FRAME32k: filtIdx = 6; - move16(); - BREAK; + break; case L_FRAME48k: filtIdx = 7; - move16(); - BREAK; + break; default: assert(0); + break; } } - ELSE IF (sub(L_frame_core, 512) == 0) + else if (L_frame_core == 512) { - SWITCH ( L_frame ) + switch ( L_frame ) { case L_FRAME8k: filtIdx = 8; - move16(); - BREAK; + break; case L_FRAME16k: filtIdx = 9; - move16(); - BREAK; + break; case L_FRAME32k: filtIdx = 10; - move16(); - BREAK; + break; case L_FRAME48k: filtIdx = 11; - move16(); - BREAK; + break; default: assert(0); + break; } } - ELSE + else { filtIdx = -1; - move16(); } /******** Previous-frame part ********/ - - tcx_ltp_synth_filter( sig_out, - sig_in, - delay, - *pitch_int_past, - *pitch_fr_past, - *gain_past, - *pitres_past, - NULL, - 0, - *filtIdx_past - ); + tcx_ltp_synth_filter( sig_out, sig_in, delay, *pitch_int_past, *pitch_fr_past, *gain_past, *pitres_past, *filtIdx_past ); /******** Transition part ********/ - - test(); - test(); - test(); - IF ( gain==0 && *gain_past==0 ) + if ( gain==0.f && *gain_past==0.f ) { - Copy( sig_in+delay, sig_out+delay, L_transition ); + mvr2r( sig_in+delay, sig_out+delay, L_transition ); } - ELSE IF ( *gain_past==0 ) + else if ( *gain_past==0.f ) { - tcx_ltp_synth_filter( sig_out+delay, - sig_in+delay, - L_transition, - pitch_int, - pitch_fr, - gain, - pitres, - NULL, - 1, - filtIdx - ); + tcx_ltp_synth_filter_fadein( sig_out+delay, sig_in+delay, L_transition, pitch_int, pitch_fr, gain, pitres, filtIdx ); } - ELSE IF ( gain==0 ) + else if ( gain==0.f ) { - tcx_ltp_synth_filter( sig_out+delay, - sig_in+delay, - L_transition, - *pitch_int_past, - *pitch_fr_past, - *gain_past, - *pitres_past, - NULL, - -1, - *filtIdx_past - ); + tcx_ltp_synth_filter_fadeout( sig_out+delay, sig_in+delay, L_transition, *pitch_int_past, *pitch_fr_past, *gain_past, *pitres_past, *filtIdx_past ); } - ELSE IF ( sub(gain, *gain_past) == 0 && sub(pitch_int, *pitch_int_past) == 0 && sub(pitch_fr, *pitch_fr_past) == 0 ) + else if ( gain==*gain_past && pitch_int==*pitch_int_past && pitch_fr==*pitch_fr_past ) { - tcx_ltp_synth_filter( sig_out+delay, - sig_in+delay, - L_transition, - pitch_int, - pitch_fr, - gain, - pitres, - NULL, - 0, - filtIdx - ); + tcx_ltp_synth_filter( sig_out+delay, sig_in+delay, L_transition, pitch_int, pitch_fr, gain, pitres, filtIdx ); } - ELSE + else { tcx_ltp_get_lpc( sig_out+delay-L_frame, L_frame, A, lpcorder ); tcx_ltp_get_zir( zir, L_transition, sig_out+delay-lpcorder, sig_in+delay-lpcorder, A, lpcorder, gain, pitch_int, pitch_fr, pitres, filtIdx ); - tcx_ltp_synth_filter( sig_out+delay, - sig_in+delay, - L_transition, - pitch_int, - pitch_fr, - gain, - pitres, - zir, - 0, - filtIdx - ); + tcx_ltp_synth_filter_zir( sig_out+delay, sig_in+delay, L_transition, pitch_int, pitch_fr, gain, pitres, zir, filtIdx ); } /******** Current-frame part ********/ - - tcx_ltp_synth_filter( sig_out+(delay+L_transition), - sig_in+(delay+L_transition), - L_frame-(delay+L_transition), - pitch_int, - pitch_fr, - gain, - pitres, - NULL, - 0, - filtIdx - ); - + tcx_ltp_synth_filter( sig_out+(delay+L_transition), sig_in+(delay+L_transition), L_frame-(delay+L_transition), + pitch_int, pitch_fr, gain, pitres, filtIdx ); /******** Output ********/ - /* copy to output */ - - Copy( sig_out, sig, L_frame ); + mvr2r( sig_out, sig, L_frame ); /* Update */ *pitch_int_past = pitch_int; - move16(); *pitch_fr_past = pitch_fr; - move16(); *gain_past = gain2; - move16(); *filtIdx_past = filtIdx; - move16(); *pitres_past = pitres; - Copy( sig_out, mem_out, L_frame ); + mvr2r( sig_out, mem_out, L_frame ); + return; } diff --git a/src/libs/libevs/lib_com/tcx_mdct.cpp b/src/libs/libevs/lib_com/tcx_mdct.cpp old mode 100755 new mode 100644 index 8187c041..0adbfef9 --- a/src/libs/libevs/lib_com/tcx_mdct.cpp +++ b/src/libs/libevs/lib_com/tcx_mdct.cpp @@ -1,219 +1,136 @@ /*==================================================================================== - EVS Codec 3GPP TS26.442 Apr 03, 2018. Version 12.11.0 / 13.6.0 / 14.2.0 + EVS Codec 3GPP TS26.443 Nov 13, 2018. Version 12.11.0 / 13.7.0 / 14.3.0 / 15.1.0 ====================================================================================*/ #include #include #include -#include "cnst_fx.h" -#include "prot_fx.h" -#include "basop_util.h" -#include "stl.h" +#include "cnst.h" +#include "prot.h" -static Word16 TCX_MDCT_GetScaleFactor(Word16 L, Word16 *factor_e) + +/*-------------------------------------------------------------------* + * TCX_MDCT() + * + * + *-------------------------------------------------------------------*/ + +void TCX_MDCT( + float const *x, + float *y, + int l, + int m, + int r +) { - - Word16 factor; - - IF(sub(L, NORM_MDCT_FACTOR) == 0) - { - factor = 32767; - move16(); - *factor_e = 0; - move16(); - } - ELSE IF(sub(L, 2*NORM_MDCT_FACTOR) == 0) - { - factor = 23170; - move16(); - *factor_e = 0; - move16(); - } - ELSE IF(sub(L, 4*NORM_MDCT_FACTOR) == 0) - { - factor = 16384; - move16(); - *factor_e = 0; - move16(); - } - ELSE - { - - factor = mult_r(shl(L, 4), 26214 /*128.f / NORM_MDCT_FACTOR*/); /* 4Q11 */ - *factor_e = 4; - move16(); - - factor = ISqrt16(factor, factor_e); - } - - return factor; -} - -static Word16 TCX_MDCT_Inverse_GetScaleFactor(Word16 L, Word16 *factor_e) -{ - - Word16 factor; - - IF(sub(L, NORM_MDCT_FACTOR) == 0) - { - factor = 32767; - move16(); - *factor_e = 0; - move16(); - } - ELSE IF(sub(L, 2*NORM_MDCT_FACTOR) == 0) - { - factor = 23170; - move16(); - *factor_e = 1; - move16(); - } - ELSE IF(sub(L, 4*NORM_MDCT_FACTOR) == 0) - { - factor = 32767; - move16(); - *factor_e = 1; - move16(); - } - ELSE - { - factor = mult_r(shl(L, 4), 26214 /*128.f / NORM_MDCT_FACTOR*/); /* 4Q11 */ - *factor_e = 4; - move16(); - - factor = Sqrt16(factor, factor_e); - } - - return factor; -} - - -void TCX_MDCT(const Word16 *x, Word32 *y, Word16* y_e, Word16 l, Word16 m, Word16 r) -{ - - Word16 i; - Word16 factor, neg_factor; - Word16 factor_e; - - factor = TCX_MDCT_GetScaleFactor(add(add(shr(l, 1), m), shr(r, 1)), &factor_e); - *y_e = add(*y_e, factor_e); - - neg_factor = negate(factor); - + short i; + float dctInBuffer[N_MAX]; /* Init */ - FOR(i=0; i> 1, R2 = r >> 1; + float f; - Word16 i, fac, negfac, s; - Word16 L2 = l, R2 = r; - Word32 tmp_buf[N_MAX+L_MDCT_OVLP_MAX/2]; - Word16 fac_e; + edct( x, y + L2, L2 + m + R2 ); - L2 = shr(l, 1); - R2 = shr(r, 1); - - x_e = sub(15, x_e); - edct_fx(x, tmp_buf + L2, l/2 + m + r/2, &x_e); - x_e = sub(15, x_e); - - fac = TCX_MDCT_Inverse_GetScaleFactor(add(add(shr(l, 1), m), shr(r, 1)), &fac_e); - x_e = add(x_e, fac_e); - - negfac = negate(fac); - - s = x_e; - move16(); - - FOR (i = 0; i < R2; i++) + for (i = 0; i < R2; i++) { - y[l + m + R2 + i] = round_fx(L_shl(Mpy_32_16_1(tmp_buf[L2 + i], negfac), s)); /* fold out right end of DCT */ + y[l + m + R2 + i] = -1.0f * y[L2 + i]; /* fold out right end of DCT */ } - FOR (i=0; i> 1); i++) { - y[i] = round_fx(L_shl(Mpy_32_16_1(tmp_buf[L2 + m + R2 + i], fac), s)); /* negate, fold out left end of DCT */ + f = y[L2 + i]; + y[L2 + i] = -1.0f * y[l + m + R2 - 1 - i]; /* time-reverse mid of DCT */ + y[l + m + R2 - 1 - i] = -1.0f * f; } - FOR (i = 0; i < shr(add(L2,add(m,R2)),1); i++) - { - Word16 f; - f = round_fx(L_shl(Mpy_32_16_1(tmp_buf[L2 + i], negfac), s)); - - y[L2 + i] = round_fx(L_shl(Mpy_32_16_1(tmp_buf[l + m + R2 - 1 - i], negfac), s)); /* time-reverse mid of DCT */ - - move16(); - y[l + m + R2 - 1 - i] = f; - } + v_multc( y, (float)sqrt((float)(l/2 + m + r/2) / NORM_MDCT_FACTOR), y, l + m + r ); + return; } - - diff --git a/src/libs/libevs/lib_com/tcx_mdct_window.cpp b/src/libs/libevs/lib_com/tcx_mdct_window.cpp old mode 100755 new mode 100644 index d7d6143a..260af2e4 --- a/src/libs/libevs/lib_com/tcx_mdct_window.cpp +++ b/src/libs/libevs/lib_com/tcx_mdct_window.cpp @@ -1,208 +1,188 @@ /*==================================================================================== - EVS Codec 3GPP TS26.442 Apr 03, 2018. Version 12.11.0 / 13.6.0 / 14.2.0 + EVS Codec 3GPP TS26.443 Nov 13, 2018. Version 12.11.0 / 13.7.0 / 14.3.0 / 15.1.0 ====================================================================================*/ - +#include #include #include "options.h" -#include "cnst_fx.h" -#include "basop_util.h" -#include "rom_basop_util.h" -#include "prot_fx.h" -#include "stl.h" - -void mdct_window_sine(const PWord16 **window, const Word16 n) -{ - *window = getSineWindowTable(n); -} +#include "cnst.h" +#include "prot.h" +#include "rom_com.h" -extern const Word16 window_48kHz_fx[]; -extern const Word16 window_256kHz[]; -extern const Word16 window_8_16_32kHz_fx[]; +/*------------------------------------------------------------------- + * mdct_window_sine() + * + * + *-------------------------------------------------------------------*/ -void mdct_window_aldo( - Word16 *window1, - PWord16 *window1_trunc, - PWord16 *window2, - Word16 n +void mdct_window_sine( + float *window, + int n ) { - Word16 i, n0, n1, n2, d, tmp; - const Word16 *p1, *p2; + int i; + float c; + + c = EVS_PI / ( 2.0f * (float)n ); + + for ( i = 0 ; i < n ; i++ ) + { + window[i] = (float)sin( c * ( 0.5f + (float)i ) ); + } + + return; + +} + +/*------------------------------------------------------------------- + * mdct_window_aldo() + * + * + *-------------------------------------------------------------------*/ + +void mdct_window_aldo( + float *window1, + float *window2, + int n +) +{ + int i, n1, n2, d; + const float *p1, *p2; /* set table pointers and decimation factor */ - SWITCH (n) + switch (n) { case 320/2: - p1 = window_48kHz_fx + 2; - p2 = window_48kHz_fx + 1110 - 3; + p1 = window_48kHz + 2; + p2 = window_48kHz + 1110 - 3; d = 6; - BREAK; + break; case 512/2: p1 = window_256kHz; p2 = window_256kHz + 592 - 1; d = 2; - BREAK; + break; case 640/2: - p1 = window_48kHz_fx + 1; - p2 = window_48kHz_fx + 1110 - 2; + p1 = window_48kHz + 1; + p2 = window_48kHz + 1110 - 2; d = 3; - BREAK; + break; case 1024/2: p1 = window_256kHz; p2 = window_256kHz + 592 - 1; d = 1; - BREAK; + break; case 1280/2: - p1 = window_48kHz_fx + 1; - p2 = window_48kHz_fx + 1110 - 2; + p1 = window_48kHz + 1; + p2 = window_48kHz + 1110 - 2; d = 3; - BREAK; + break; case 1920/2: - p1 = window_48kHz_fx; - p2 = window_48kHz_fx + 1110 - 1; + p1 = window_48kHz; + p2 = window_48kHz + 1110 - 1; d = 1; - BREAK; + break; default: assert(0); return; } /* set lengths */ - n0 = shr(imult1616(n, 9), 5); - n1 = shr(imult1616(n, 23), 5); /* left slope length */ - n2 = shr(imult1616(n, 14), 5); /* right slope length */ + n1 = n * 23 / 32; /* left slope length */ + n2 = n * 14 / 32; /* right slope length */ /* first part (long slope) */ - IF (sub(n, 1280/2) != 0) + if (n != 1280/2) { - FOR (i = 0; i < n0; i++) + for (i = 0; i < n/2; i++) { *window1 = *p1; - move16(); window1++; p1 += d; } - tmp = shr(n, 1); - FOR ( ; i < tmp; i++) - { - window1_trunc->v.im = *p1; - move16(); - window1_trunc++; - p1 += d; - } + if ((n == 512/2) || (n == 320 / 2)) p1++; - test(); - if (sub(n, 512/2) == 0 || sub(n, 320/2) == 0) p1++; - - FOR ( ; i < n1; i++) + for ( ; i < n1; i++) { - window1_trunc--; - window1_trunc->v.re = *p1; - move16(); + *window1 = *p1; + window1++; p1 += d; } } - ELSE + else { - const Word16 *pi = window_8_16_32kHz_fx; + const float *pi = window_8_16_32kHz; - FOR (i = 0; i < n0; i+=2) + for (i = 0; i < n/2; i+=2) { *window1 = *p1; - move16(); window1++; p1 += d; *window1 = *pi; - move16(); window1++; pi++; } - - tmp = shr(n, 1); - FOR ( ; i < tmp; i+=2) + for ( ; i < n1; i+=2) { - window1_trunc->v.im = *p1; - move16(); - window1_trunc++; - p1 += d; - - window1_trunc->v.im = *pi; - move16(); - window1_trunc++; - pi++; - } - - FOR ( ; i < n1; i+=2) - { - window1_trunc--; - window1_trunc->v.re = *pi; - move16(); + *window1 = *pi; + window1++; pi++; - window1_trunc--; - window1_trunc->v.re = *p1; - move16(); + *window1 = *p1; + window1++; p1 += d; } } /* second part (short slope) */ - IF (sub(n, 1280/2) != 0) + + if (n != 1280/2) { - tmp = shr(n2, 1); - FOR (i = 0; i < tmp; i++) + for (i = 0; i < n2/2; i++) { - window2->v.im = *p2; - move16(); + *window2 = *p2; window2++; p2 -= d; } - test(); - if (sub(n, 512/2) == 0 || sub(n, 320/2) == 0) p2--; + if ((n == 512/2) || (n == 320 / 2)) p2--; - FOR ( ; i < n2; i++) + for ( ; i < n2; i++) { - window2--; - window2->v.re = *p2; - move16(); + *window2 = *p2; + window2++; p2 -= d; } } - ELSE + else { - const Word16 *pi = window_8_16_32kHz_fx + 370 - 1; + const float *pi = window_8_16_32kHz + 370 - 1; - tmp = shr(n2, 1); - FOR (i = 0; i < tmp; i+=2) + for (i = 0; i < n2/2; i+=2) { - window2->v.im = *p2; - move16(); + *window2 = *p2; window2++; p2 -= d; - window2->v.im = *pi; - move16(); + *window2 = *pi; window2++; pi--; } - FOR ( ; i < n2; i+=2) + for ( ; i < n2; i+=2) { - window2--; - window2->v.re = *pi; - move16(); + *window2 = *pi; + window2++; pi--; - window2--; - window2->v.re = *p2; - move16(); + *window2 = *p2; + window2++; p2 -= d; } } + + return; } - diff --git a/src/libs/libevs/lib_com/tcx_utils.cpp b/src/libs/libevs/lib_com/tcx_utils.cpp old mode 100755 new mode 100644 index 538eee95..9e92bcde --- a/src/libs/libevs/lib_com/tcx_utils.cpp +++ b/src/libs/libevs/lib_com/tcx_utils.cpp @@ -1,249 +1,234 @@ /*==================================================================================== - EVS Codec 3GPP TS26.442 Apr 03, 2018. Version 12.11.0 / 13.6.0 / 14.2.0 + EVS Codec 3GPP TS26.443 Nov 13, 2018. Version 12.11.0 / 13.7.0 / 14.3.0 / 15.1.0 ====================================================================================*/ #include #include +#include #include -#include "stl.h" #include "options.h" -#include "prot_fx.h" -#include "rom_com_fx.h" -#include "rom_basop_util.h" -#include "basop_util.h" +#include "cnst.h" +#include "prot.h" -#define inv_int InvIntTable - - -Word16 getInvFrameLen(Word16 L_frame) /* returns 1/L_frame in Q21 format */ -{ - Word16 idx, s; - - s = norm_s(L_frame); - idx = shl(L_frame, s); - - assert((idx == 0x4000) || (idx == 0x4B00) || (idx == 0x5000) || (idx == 0x5A00) || (idx == 0x6000) || (idx == 0x6400) || (idx == 0x7800)); - - idx = mult_r(idx, 0x10); /* idx = shr(add(idx, 0x0400), 11); */ - idx = s_and(idx, 7); - - - return shl(L_frame_inv[idx], sub(s, 7)); -} +/*-------------------------------------------------------------------* +* tcx_get_windows() +* +* +*-------------------------------------------------------------------*/ static void tcx_get_windows( - TCX_config const * tcx_cfg, /* i: TCX configuration */ - Word16 left_mode, /* i: overlap mode of left window half */ - Word16 right_mode, /* i: overlap mode of right window half */ - Word16 *left_overlap, /* o: left overlap length */ - PWord16 const **left_win, /* o: left overlap window */ - Word16 *right_overlap, /* o: right overlap length */ - PWord16 const **right_win, /* o: right overlap window */ - Word8 fullband /* i: fullband flag */ + TCX_config const * tcx_cfg, /* i: TCX configuration */ + const short left_mode, /* i: overlap mode of left window half */ + const short right_mode, /* i: overlap mode of right window half */ + int *left_overlap, /* o: left overlap length */ + float const **left_win, /* o: left overlap window */ + int *right_overlap, /* o: right overlap length */ + float const **right_win, /* o: right overlap window */ + int fullband /* i: fullband flag */ ) { - IF (fullband == 0) + if (!fullband) { /* Left part */ - SWITCH (left_mode) + + if (left_mode == TRANSITION_OVERLAP) { - case TRANSITION_OVERLAP: /* ACELP->TCX transition */ + /* ACELP->TCX transition */ *left_overlap = tcx_cfg->tcx_mdct_window_trans_length; - move16(); *left_win = tcx_cfg->tcx_mdct_window_trans; - BREAK; - case MIN_OVERLAP: + } + else if (left_mode == MIN_OVERLAP) + { *left_overlap = tcx_cfg->tcx_mdct_window_min_length; - move16(); *left_win = tcx_cfg->tcx_mdct_window_minimum; - BREAK; - case HALF_OVERLAP: + } + else if (left_mode == HALF_OVERLAP) + { *left_overlap = tcx_cfg->tcx_mdct_window_half_length; - move16(); *left_win = tcx_cfg->tcx_mdct_window_half; - BREAK; - case FULL_OVERLAP: + } + else if (left_mode == FULL_OVERLAP) + { *left_overlap = tcx_cfg->tcx_mdct_window_length; - move16(); *left_win = tcx_cfg->tcx_aldo_window_1_trunc; - BREAK; - default: + } + else + { assert(!"Not supported overlap"); } /* Right part */ - SWITCH (right_mode) + + if (right_mode == MIN_OVERLAP) { - case MIN_OVERLAP: *right_overlap = tcx_cfg->tcx_mdct_window_min_length; - move16(); *right_win = tcx_cfg->tcx_mdct_window_minimum; - BREAK; - case HALF_OVERLAP: + } + else if (right_mode == HALF_OVERLAP) + { *right_overlap = tcx_cfg->tcx_mdct_window_half_length; - move16(); *right_win = tcx_cfg->tcx_mdct_window_half; - BREAK; - case FULL_OVERLAP: + } + else if (right_mode == FULL_OVERLAP) + { *right_overlap = tcx_cfg->tcx_mdct_window_delay; - move16(); *right_win = tcx_cfg->tcx_aldo_window_2; - BREAK; - default: + } + else + { assert(!"Not supported overlap"); } } - ELSE + else { /* Left part */ - SWITCH (left_mode) + + if (left_mode == TRANSITION_OVERLAP) { - case TRANSITION_OVERLAP: /* ACELP->TCX transition */ + /* ACELP->TCX transition */ *left_overlap = tcx_cfg->tcx_mdct_window_trans_lengthFB; - move16(); *left_win = tcx_cfg->tcx_mdct_window_transFB; - BREAK; - case MIN_OVERLAP: + } + else if (left_mode == MIN_OVERLAP) + { *left_overlap = tcx_cfg->tcx_mdct_window_min_lengthFB; - move16(); *left_win = tcx_cfg->tcx_mdct_window_minimumFB; - BREAK; - case HALF_OVERLAP: + } + else if (left_mode == HALF_OVERLAP) + { *left_overlap = tcx_cfg->tcx_mdct_window_half_lengthFB; - move16(); *left_win = tcx_cfg->tcx_mdct_window_halfFB; - BREAK; - case RECTANGULAR_OVERLAP: + } + else if (left_mode == RECTANGULAR_OVERLAP) + { *left_overlap = 0; - move16(); *left_win = NULL; - BREAK; - case FULL_OVERLAP: + } + else if (left_mode == FULL_OVERLAP) + { *left_overlap = tcx_cfg->tcx_mdct_window_lengthFB; - move16(); *left_win = tcx_cfg->tcx_aldo_window_1_FB_trunc; - BREAK; - default: + } + else + { assert(!"Not supported overlap"); } /* Right part */ - SWITCH (right_mode) + + if (right_mode == MIN_OVERLAP) { - case MIN_OVERLAP: *right_overlap = tcx_cfg->tcx_mdct_window_min_lengthFB; - move16(); *right_win = tcx_cfg->tcx_mdct_window_minimumFB; - BREAK; - case HALF_OVERLAP: + } + else if (right_mode == HALF_OVERLAP) + { *right_overlap = tcx_cfg->tcx_mdct_window_half_lengthFB; - move16(); *right_win = tcx_cfg->tcx_mdct_window_halfFB; - BREAK; - case RECTANGULAR_OVERLAP: + } + else if (right_mode == RECTANGULAR_OVERLAP) + { *right_overlap = 0; - move16(); *right_win = NULL; - BREAK; - case FULL_OVERLAP: + } + else if (right_mode == FULL_OVERLAP) + { *right_overlap = tcx_cfg->tcx_mdct_window_delayFB; - move16(); *right_win = tcx_cfg->tcx_aldo_window_2_FB; - BREAK; - default: + } + else + { assert(!"Not supported overlap"); } } + + return; } -static void tcx_windowing_analysis( - Word16 const *signal, /* i: signal vector */ - Word16 L_frame, /* i: frame length */ - Word16 left_overlap, /* i: left overlap length */ - PWord16 const *left_win, /* i: left overlap window */ - Word16 right_overlap, /* i: right overlap length */ - PWord16 const *right_win, /* i: right overlap window */ - Word16 *output /* o: windowed signal vector */ +/*-------------------------------------------------------------------* +* tcx_windowing_analysis() +* +* +*-------------------------------------------------------------------*/ + +void tcx_windowing_analysis( + float const *signal, /* i: signal vector */ + int L_frame, /* i: frame length */ + int left_overlap, /* i: left overlap length */ + float const *left_win, /* i: left overlap window */ + int right_overlap, /* i: right overlap length */ + float const *right_win, /* i: right overlap window */ + float *output /* o: windowed signal vector */ ) { - Word16 w, n; + int w; /* Left overlap */ - n = shr(left_overlap, 1); - FOR (w = 0; w < n; w++) + for (w = 0; w < left_overlap; w++) { - *output++ = mult_r(*signal++, left_win[w].v.im); - move16(); - } - FOR (w = 0; w < n; w++) - { - *output++ = mult_r(*signal++, left_win[n-1-w].v.re); - move16(); + *output++ = *signal++ * left_win[w]; } /* Non overlapping region */ - n = sub(L_frame, shr(add(left_overlap, right_overlap), 1)); - FOR (w = 0; w < n; w++) + for (w = 0; w < L_frame-(left_overlap+right_overlap)/2; w++) { *output++ = *signal++; - move16(); } /* Right overlap */ - n = shr(right_overlap, 1); - FOR (w = 0; w < n; w++) + for (w = 0; w < right_overlap; w++) { - *output++ = mult_r(*signal++, right_win[w].v.re); - move16(); - } - FOR (w = 0; w < n; w++) - { - *output++ = mult_r(*signal++, right_win[n-1-w].v.im); - move16(); + *output++ = *signal++ * right_win[right_overlap-1-w]; } + + return; } + +/*-------------------------------------------------------------------* +* WindowSignal() +* +* +*-------------------------------------------------------------------*/ + void WindowSignal( TCX_config const *tcx_cfg, /* input: configuration of TCX */ - Word16 offset, /* input: left folding point offset relative to the input signal pointer */ - Word16 left_overlap_mode, /* input: overlap mode of left window half */ - Word16 right_overlap_mode, /* input: overlap mode of right window half */ - Word16 * left_overlap_length, /* output: TCX window left overlap length */ - Word16 * right_overlap_length, /* output: TCX window right overlap length */ - Word16 const in[], /* input: input signal */ - Word16 * L_frame, /* input/output: frame length */ - Word16 out[] /* output: output windowed signal */ - ,Word8 fullband /* input: fullband flag */ + int offset, /* input: left folding point offset relative to the input signal pointer */ + const short left_overlap_mode, /* input: overlap mode of left window half */ + const short right_overlap_mode, /* input: overlap mode of right window half */ + int * left_overlap_length, /* output: TCX window left overlap length */ + int * right_overlap_length, /* output: TCX window right overlap length */ + float const in[], /* input: input signal */ + int * L_frame, /* input/output: frame length */ + float out[], /* output: output windowed signal */ + int fullband /* input: fullband flag */ ) { - Word16 l, r; - PWord16 const * left_win; - PWord16 const * right_win; - + int l, r; + float const * left_win; + float const * right_win; /*-----------------------------------------------------------* * Init * *-----------------------------------------------------------*/ - tcx_get_windows(tcx_cfg, left_overlap_mode, right_overlap_mode, &l, &left_win, &r, &right_win, fullband); + tcx_get_windows(tcx_cfg, left_overlap_mode, right_overlap_mode, &l, &left_win, &r, &right_win, fullband ); /* Init lengths */ /* if past frame is ACELP */ - IF (sub(left_overlap_mode, TRANSITION_OVERLAP) == 0) + if (left_overlap_mode == TRANSITION_OVERLAP) { /* Increase frame size for 5ms */ - IF (fullband == 0) + if (!fullband) { - *L_frame = add(*L_frame, tcx_cfg->tcx5Size); - move16(); - offset = negate(shr(tcx_cfg->tcx_mdct_window_trans_length, 1)); + *L_frame += tcx_cfg->tcx5Size; + offset = -tcx_cfg->tcx_mdct_window_trans_length/2; } - ELSE + else { - *L_frame = add(*L_frame, tcx_cfg->tcx5SizeFB); - move16(); - offset = negate(shr(tcx_cfg->tcx_mdct_window_trans_lengthFB, 1)); + *L_frame += tcx_cfg->tcx5SizeFB; + offset = -tcx_cfg->tcx_mdct_window_trans_lengthFB/2; } } @@ -251,1380 +236,706 @@ void WindowSignal( * Windowing * *-----------------------------------------------------------*/ - tcx_windowing_analysis(in-shr(l,1)+offset, *L_frame, l, left_win, r, right_win, out); + tcx_windowing_analysis(in-l/2+offset, *L_frame, l, left_win, r, right_win, out); - IF (sub(left_overlap_mode, FULL_OVERLAP) == 0) + if (left_overlap_mode == FULL_OVERLAP) { /* fade truncated ALDO window to avoid discontinuities */ - Word16 i, tmp; - const PWord16 *p; - - p = tcx_cfg->tcx_mdct_window_minimum; - tmp = shr(tcx_cfg->tcx_mdct_window_min_length, 1); - IF (fullband != 0) + if (!fullband) { - p = tcx_cfg->tcx_mdct_window_minimumFB; - tmp = shr(tcx_cfg->tcx_mdct_window_min_lengthFB, 1); + v_mult(out, tcx_cfg->tcx_mdct_window_minimum, out, tcx_cfg->tcx_mdct_window_min_length); } - - FOR (i = 0; i < tmp; i++) + else { - out[i] = mult_r(out[i], p[i].v.im); - move16(); - } - FOR (i = 0; i < tmp; i++) - { - out[i+tmp] = mult_r(out[i+tmp], p[tmp-1-i].v.re); - move16(); + v_mult(out, tcx_cfg->tcx_mdct_window_minimumFB, out, tcx_cfg->tcx_mdct_window_min_lengthFB); } } *left_overlap_length = l; - move16(); *right_overlap_length = r; - move16(); + return; } + +/*-------------------------------------------------------------------* +* tcx_windowing_synthesis_current_frame() +* +* +*-------------------------------------------------------------------*/ + void tcx_windowing_synthesis_current_frame( - Word16 *signal, /* i/o: signal vector */ - const PWord16 *window, /* i: TCX window vector */ - const PWord16 *window_half, /* i: TCX window vector for half-overlap window */ - const PWord16 *window_min, /* i: TCX minimum overlap window */ - Word16 window_length, /* i: TCX window length */ - Word16 window_half_length, /* i: TCX half window length */ - Word16 window_min_length, /* i: TCX minimum overlap length */ - Word16 left_rect, /* i: left part is rectangular */ - Word16 left_mode, /* i: overlap mode of left window half */ - Word16 *acelp_zir, /* i: acelp ZIR */ - Word16 *old_syn, - Word16 *syn_overl, - Word16 *A_zir, - const PWord16 *window_trans, - Word16 acelp_zir_len, - Word16 acelp_mem_len, - Word16 last_core_bfi, /* i : last core */ - Word8 last_is_cng - ,Word16 fullbandScale + float *signal, /* i/o: signal vector */ + float *window, /* i: TCX window vector */ + float *window_half, /* i: TCX window vector for half-overlap window */ + float *window_min, /* i: TCX minimum overlap window */ + int window_length, /* i: TCX window length */ + int window_half_length, /* i: TCX half window length */ + int window_min_length, /* i: TCX minimum overlap length */ + int left_rect, /* i: left part is rectangular */ + int left_mode, /* i: overlap mode of left window half */ + float *acelp_zir, /* i: acelp ZIR */ + float *old_syn, /* i: old synthesis */ + float *syn_overl, /* i: overlap synthesis */ + float *A_zir, + float *window_trans, + int acelp_zir_len, + int acelp_mem_len, + int last_core_bfi, /* i: last mode */ + int last_is_cng, + int fullbandScale ) { - - Word16 i, overlap, n, tmp, tmp2; - Word16 tmp_buf[L_FRAME_MAX/2]; - Word32 L_tmp; + int i, overlap; + float tmp[L_FRAME_MAX/2]; /* Init */ - - overlap = shr(window_length, 1); + overlap = window_length>>1; /* Past-frame is TCX concealed as CNG and current-frame is TCX */ - test(); - test(); - test(); - test(); - IF ( sub(last_is_cng, 1)==0 && left_rect==0 ) + if ( last_is_cng==1 && left_rect==0 ) { - IF (!fullbandScale) + if (!fullbandScale) { - set16_fx(acelp_zir, 0, acelp_zir_len); - E_UTIL_synthesis(0, A_zir, acelp_zir, acelp_zir, acelp_zir_len, signal+overlap+acelp_mem_len-M, 0, M); + set_zero(acelp_zir, acelp_zir_len); + syn_filt(A_zir, M,acelp_zir, acelp_zir, acelp_zir_len, signal+overlap+acelp_mem_len-M, 0); } - ELSE + else { - lerp(acelp_zir, tmp_buf, acelp_zir_len, idiv1616U(shl(acelp_zir_len, LD_FSCALE_DENOM), fullbandScale)); - acelp_zir = tmp_buf; + lerp(acelp_zir, tmp, acelp_zir_len, acelp_zir_len*FSCALE_DENOM/fullbandScale); + acelp_zir = tmp; } - FOR (i = 0; i < acelp_zir_len; i++) + for (i = 0; i < acelp_zir_len; i++) { - /*signal[i] *= (float)(i)/(float)(acelp_zir_len); - signal[i] += acelp_zir[i]*(float)(acelp_zir_len-i)/(float)(acelp_zir_len);*/ - move16(); - signal[i] = add(mult_r(signal[i], div_s(i, acelp_zir_len)), mult_r(acelp_zir[i], div_s(sub(acelp_zir_len, i), acelp_zir_len))); + signal[i] *= (float)(i)/(float)(acelp_zir_len); + signal[i] += acelp_zir[i]*(float)(acelp_zir_len-i)/(float)(acelp_zir_len); } } - /* Rectangular window (past-frame is ACELP) */ - ELSE IF ( sub(left_rect, 1)==0 && last_core_bfi==ACELP_CORE ) + else if ( left_rect==1 && last_core_bfi==ACELP_CORE ) /* Rectangular window (past-frame is ACELP) */ { - tmp = sub(overlap,acelp_mem_len); - FOR (i=0; i< tmp ; i++) + for (i=0; i= 0 ) + if(acelp_zir_len >= 2.0f * 64) { /* apply a simple low-pass to the ZIR, to avoid potentially unmasked HF content */ - FOR(i=2; i=0; i--) + acelp_zir[acelp_zir_len-1] = 0.40 * acelp_zir[acelp_zir_len-1] + 0.35f * acelp_zir[acelp_zir_len-1] + 0.25f * acelp_zir[acelp_zir_len-2]; + acelp_zir[acelp_zir_len-2] = 0.40 * acelp_zir[acelp_zir_len-2] + 0.35f * acelp_zir[acelp_zir_len-1] + 0.25f * acelp_zir[acelp_zir_len-1]; + for(i=acelp_zir_len-3; i>=0; i--) { - L_tmp = L_mult(acelp_zir[i], 13107); - L_tmp = L_mac(L_tmp, acelp_zir[i+1], 11469); - acelp_zir[i] = mac_r(L_tmp, acelp_zir[i+2], 8192); - move16(); + acelp_zir[i] = 0.40f * acelp_zir[i] + 0.35f * acelp_zir[i+1] + 0.25f * acelp_zir[i+2]; } } } - FOR (i = 0; i < acelp_zir_len; i++) + for (i = 0; i < acelp_zir_len; i++) { /*remove reconstructed ZIR and add ACELP ZIR*/ - move16(); - signal[i+overlap+acelp_mem_len] = sub(signal[i+overlap+acelp_mem_len], mult_r(acelp_zir[i], div_s(sub(acelp_zir_len, i), acelp_zir_len))); + signal[i+overlap+acelp_mem_len] -= acelp_zir[i]*(float)(acelp_zir_len-i)/(float)acelp_zir_len; } } - /* Rectangular window (past-frame is TCX) */ - ELSE IF ( left_rect==1 && last_core_bfi!=ACELP_CORE ) + else if ( left_rect==1 && last_core_bfi!=0 ) /* Rectangular window (past-frame is TCX) */ { - n = add(overlap, acelp_mem_len); - FOR (i=0; ican be skipped*/ - + return; } + +/*-------------------------------------------------------------------* +* tcx_windowing_synthesis_past_frame() +* +* +*-------------------------------------------------------------------*/ + void tcx_windowing_synthesis_past_frame( - Word16 *signal, /* i/o: signal vector */ - const PWord16 *window, /* i: TCX window vector */ - const PWord16 *window_half, /* i: TCX window vector for half-overlap window */ - const PWord16 *window_min, /* i: TCX minimum overlap window */ - Word16 window_length, /* i: TCX window length */ - Word16 window_half_length, /* i: TCX half window length */ - Word16 window_min_length, /* i: TCX minimum overlap length */ - Word16 right_mode /* i: overlap mode (left_mode of current frame) */ + float *signal, /* i/o: signal vector */ + float *window, /* i: TCX window vector */ + float *window_half, /* i: TCX window vector for half-overlap window */ + float *window_min, /* i: TCX minimum overlap window */ + int window_length, /* i: TCX window length */ + int window_half_length, /* i: TCX half window length */ + int window_min_length, /* i: TCX minimum overlap length */ + int right_mode /* i: overlap mode (left_mode of current frame) */ ) { + int i; - Word16 i, n; - - - IF ( sub(right_mode, 2) == 0 ) /* min. overlap */ + if (right_mode == MIN_OVERLAP) { - signal += shr(sub(window_length, window_min_length), 1); - - n = shr(window_min_length, 1); - FOR (i = 0; i < n; i++) + /* min. overlap */ + int w; + for (i = (window_length - window_min_length)/2, w = 0; w < window_min_length; i++, w++) { - *signal = mult_r(*signal, window_min[i].v.re); - move16(); - signal++; + signal[i] *= window_min[window_min_length-1-w]; } - FOR (i = 0; i < n; i++) + for (; i < window_length; i++) { - *signal = mult_r(*signal, window_min[n-1-i].v.im); - move16(); - signal++; - } - - n = shr(sub(window_length, window_min_length), 1); - FOR (i = 0; i < n; i++) - { - *signal = 0; - move16(); - signal++; + signal[i] = 0.0f; } } - ELSE IF ( sub(right_mode,3) == 0) /* half OL */ + else if (right_mode == HALF_OVERLAP) { - Word16 w; - - i = shr(sub(window_length, window_half_length),1); - n = shr(window_half_length,1); - FOR (w=0 ; w < n; w++) + /* half OL */ + int w; + for (i = (window_length-window_half_length)/2, w = 0; w < window_half_length; i++, w++) { - signal[i] = mult_r(signal[i], window_half[w].v.re); - move16(); - i = add(i,1); + signal[i] *= window_half[window_half_length-1-w]; } - FOR (w=0 ; w < n; w++) + for (; i < window_length; i++) { - signal[i] = mult_r(signal[i], window_half[window_half_length/2-1-w].v.im); - move16(); - i = add(i,1); - } - FOR (; i < window_length; i++) - { - move16(); - signal[i] = 0; + signal[i] = 0.0f; } } - ELSE /* normal full/maximum overlap */ + else if(right_mode == FULL_OVERLAP) { - - n = shr(window_length,1); - FOR (i = 0; i < n; i++) + /* normal full/maximum overlap */ + for (i = 0; i < window_length; i++) { - move16(); - signal[i] = mult_r(signal[i], window[i].v.re); - move16(); - signal[window_length-1-i] = mult_r(signal[window_length-1-i], window[i].v.im); + signal[i] *= window[window_length-1-i]; } } + return; } -void lpc2mdct(Word16 *lpcCoeffs, Word16 lpcOrder, - Word16 *mdct_gains, Word16 *mdct_gains_exp, - Word16 *mdct_inv_gains, Word16 *mdct_inv_gains_exp) + +/*-------------------------------------------------------------------* +* lpc2mdct() +* +* +*-------------------------------------------------------------------*/ + +void lpc2mdct( + float *lpcCoeffs, + int lpcOrder, + float *mdct_gains +) { - Word32 RealData[FDNS_NPTS]; - Word32 ImagData[FDNS_NPTS]; - Word16 i, j, k, sizeN, step, scale, s, tmp16; - Word16 g, g_e, ig, ig_e; - Word32 tmp32; - const PWord16 *ptwiddle; - Word32 workBuffer[2*BASOP_CFFT_MAX_LENGTH]; + float RealData[2*FDNS_NPTS]; + float ImagData[2*FDNS_NPTS]; + float tmp; + int i, sizeN; - - - sizeN = shl(FDNS_NPTS, 1); - - BASOP_getTables(NULL, &ptwiddle, &step, sizeN); + sizeN = 2*FDNS_NPTS; /*ODFT*/ - assert(lpcOrder < FDNS_NPTS); - - /* pre-twiddle */ - FOR (i=0; i<=lpcOrder; i++) + for(i=0; iv.re); - move32(); - ImagData[i] = L_negate(L_mult(lpcCoeffs[i], ptwiddle->v.im)); - move32(); - ptwiddle += step; + tmp = (float)(((float)i)*EVS_PI/(float)(sizeN)); + RealData[i] = (float)( lpcCoeffs[i]*cos(tmp)); + ImagData[i] = (float)(-lpcCoeffs[i]*sin(tmp)); } - /* zero padding */ - FOR ( ; i 0) pg = shr(pg, tmp); - if (tmp < 0) g = shl(g, tmp); - e = s_max(gains_exp[j], gains_exp[jp]); - - tmp = mac_r(L_mult(pg, 12288/*0.375f Q15*/), g, 20480/*0.625f Q15*/); - x[i] = L_shl(Mpy_32_16_1(x[i], tmp), e); - move32(); - - tmp = mac_r(L_mult(pg, 4096/*0.125f Q15*/), g, 28672/*0.875f Q15*/); - x[i+1] = L_shl(Mpy_32_16_1(x[i+1], tmp), e); - move32(); - - /* common exponent for g and ng */ - g = gains[j]; - move16(); - tmp = sub(gains_exp[j], gains_exp[jn]); - if (tmp > 0) ng = shr(ng, tmp); - if (tmp < 0) g = shl(g, tmp); - e = s_max(gains_exp[j], gains_exp[jn]); - - tmp = mac_r(L_mult(g, 28672/*0.875f Q15*/), ng, 4096/*0.125f Q15*/); - x[i+2] = L_shl(Mpy_32_16_1(x[i+2], tmp), e); - move32(); - - tmp = mac_r(L_mult(g, 20480/*0.625f Q15*/), ng, 12288/*0.375f Q15*/); - x[i+3] = L_shl(Mpy_32_16_1(x[i+3], tmp), e); - move32(); - - jp = j; - move16(); - j = jn; - move16(); - jn = s_min(add(jn, 1), FDNS_NPTS-1); - } - } - ELSE IF (sub(k, 5) == 0) - { - jp = 0; - move16(); - j = 0; - move16(); - jn = 1; - move16(); - - FOR (i = 0; i < lg; i += 5) - { - pg = gains[jp]; - move16(); - g = gains[j]; - move16(); - ng = gains[jn]; - move16(); - - /* common exponent for pg and g */ - tmp = sub(gains_exp[j], gains_exp[jp]); - if (tmp > 0) pg = shr(pg, tmp); - if (tmp < 0) g = shl(g, tmp); - e = s_max(gains_exp[j], gains_exp[jp]); - - tmp = mac_r(L_mult(pg, 13107/*0.40f Q15*/), g, 19661/*0.60f Q15*/); - x[i] = L_shl(Mpy_32_16_1(x[i], tmp), e); - move32(); - - tmp = mac_r(L_mult(pg, 6554/*0.20f Q15*/), g, 26214/*0.80f Q15*/); - x[i+1] = L_shl(Mpy_32_16_1(x[i+1], tmp), e); - move32(); - - - x[i+2] = L_shl(Mpy_32_16_1(x[i+2], gains[j]), gains_exp[j]); - move32(); - - /* common exponent for g and ng */ - g = gains[j]; - move16(); - tmp = sub(gains_exp[j], gains_exp[jn]); - if (tmp > 0) ng = shr(ng, tmp); - if (tmp < 0) g = shl(g, tmp); - e = s_max(gains_exp[j], gains_exp[jn]); - - tmp = mac_r(L_mult(g, 26214/*0.80f Q15*/), ng, 6554/*0.20f Q15*/); - x[i+3] = L_shl(Mpy_32_16_1(x[i+3], tmp), e); - move32(); - - tmp = mac_r(L_mult(g, 19661/*0.60f Q15*/), ng, 13107/*0.40f Q15*/); - x[i+4] = L_shl(Mpy_32_16_1(x[i+4], tmp), e); - move32(); - - jp = j; - move16(); - j = jn; - move16(); - jn = s_min(add(jn, 1), FDNS_NPTS-1); - } - } - ELSE /* no interpolation */ - { - FOR (i = 0; i < FDNS_NPTS; i++) - { - FOR (l = 0; l < k; l++) - { - *x = L_shl(Mpy_32_16_1(*x, *gains), *gains_exp); - move32(); - x++; - } - - gains++; - gains_exp++; - } - } - } - -} - -void PsychAdaptLowFreqDeemph(Word32 x[], - const Word16 lpcGains[], const Word16 lpcGains_e[], - Word16 lf_deemph_factors[] - ) -{ - Word16 i; - Word16 max, max_e, fac, min, min_e, tmp, tmp_e; - Word32 L_tmp; - - - - assert(lpcGains[0] >= 0x4000); - - max = lpcGains[0]; - move16(); - max_e = lpcGains_e[0]; - move16(); - min = lpcGains[0]; - move16(); - min_e = lpcGains_e[0]; - move16(); - - /* find minimum (min) and maximum (max) of LPC gains in low frequencies */ - FOR (i = 1; i < 9; i++) - { - IF (compMantExp16Unorm(lpcGains[i], lpcGains_e[i], min, min_e) < 0) - { - min = lpcGains[i]; - move16(); - min_e = lpcGains_e[i]; - move16(); - } - - IF (compMantExp16Unorm(lpcGains[i], lpcGains_e[i], max, max_e) > 0) - { - max = lpcGains[i]; - move16(); - max_e = lpcGains_e[i]; - move16(); - } - } - - min_e = add(min_e, 5); /* min *= 32.0f; */ - - test(); - IF ((compMantExp16Unorm(max, max_e, min, min_e) < 0) && (min > 0)) - { - /* fac = tmp = (float)pow(max / min, 0.0078125f); */ - tmp_e = min_e; - move16(); - tmp = Inv16(min, &tmp_e); - L_tmp = L_shl(L_mult(tmp, max), add(tmp_e, max_e)); /* Q31 */ - L_tmp = BASOP_Util_Log2(L_tmp); /* Q25 */ - L_tmp = L_shr(L_tmp, 7); /* 0.0078125f = 1.f/(1<<7) */ - L_tmp = BASOP_Util_InvLog2(L_tmp); /* Q31 */ - tmp = round_fx(L_tmp); /* Q15 */ - fac = tmp; /* Q15 */ move16(); - - /* gradual lowering of lowest 32 bins; DC is lowered by (max/tmp)^1/4 */ - FOR (i = 31; i >= 0; i--) - { - x[i] = Mpy_32_16_1(x[i], fac); - move32(); - if (lf_deemph_factors != NULL) - { - lf_deemph_factors[i] = mult_r(lf_deemph_factors[i], fac); - move16(); - } - fac = mult_r(fac, tmp); - } - } - -} - -void AdaptLowFreqDeemph(Word32 x[], Word16 x_e, - Word16 tcx_lpc_shaped_ari, - Word16 lpcGains[], Word16 lpcGains_e[], - const Word16 lg, - Word16 lf_deemph_factors[] - ) -{ - - Word16 i, i_max, i_max_old, lg_4; - Word32 v2, v4, tmp32; - - tmp32 = 0; /* to avoid compilation warnings */ - - - IF (tcx_lpc_shaped_ari == 0) - { - v2 = L_shl(2, sub(31, x_e)); /* 2.0 */ - v4 = L_shl(v2, 1); /* 4.0 */ - lg_4 = shr(lg, 2); /* lg/4 */ - - /* 1. find first magnitude maximum in lower quarter of spectrum */ - i_max = -1; - move16(); - - FOR (i = 0; i < lg_4; i++) - { - IF (L_sub(L_abs(x[i]), v4) >= 0) - { - - /* Debug initialization to catch illegal x[i] values. */ - tmp32 = 0; - - if (x[i] < 0) tmp32 = L_add(x[i], v2); - if (x[i] > 0) tmp32 = L_sub(x[i], v2); - - assert(tmp32 != 0); - - x[i] = tmp32; - move32(); - i_max = i; - move16(); - BREAK; - } - } - - /* 2. expand value range of all xi up to i_max: two extra steps */ - FOR (i = 0; i < i_max; i++) - { - x[i] = L_shr(x[i], 1); - move32(); - lf_deemph_factors[i] = shr(lf_deemph_factors[i], 1); - move16(); - } - - /* 3. find first magnitude maximum in lower quarter of spectrum */ - i_max_old = i_max; - move16(); - - IF (i_max_old >= 0) - { - i_max = -1; - move16(); - - FOR (i = 0; i < lg_4; i++) - { - IF (L_sub(L_abs(x[i]), v4) >= 0) - { - assert(x[i] != 0); - if (x[i] < 0) tmp32 = L_add(x[i], v2); - if (x[i] >= 0) tmp32 = L_sub(x[i], v2); - x[i] = tmp32; - move32(); - i_max = i; - move16(); - BREAK; - } - } - } - - /* 4. expand value range of all xi up to i_max: two extra steps */ - FOR (i = 0; i < i_max; i++) - { - x[i] = L_shr(x[i], 1); - move32(); - lf_deemph_factors[i] = shr(lf_deemph_factors[i], 1); - move16(); - } - - /* 5. always expand two lines; lines could be at index 0 and 1! */ - i_max = s_max(i_max, i_max_old); - i = add(i_max, 1); - - IF (x[i] < 0) - { - tmp32 = L_sub(x[i], L_negate(v4)); - - if (tmp32 > 0) - { - lf_deemph_factors[i] = shr(lf_deemph_factors[i], 1); - move16(); - } - if (tmp32 <= 0) - { - x[i] = L_add(x[i], v2); - move32(); - } - if (tmp32 > 0) - { - x[i] = L_shr(x[i], 1); - move32(); - } - } - ELSE - { - tmp32 = L_sub(x[i], v4); - - if (tmp32 < 0) - { - lf_deemph_factors[i] = shr(lf_deemph_factors[i], 1); - move16(); - } - if (tmp32 >= 0) - { - x[i] = L_sub(x[i], v2); - move32(); - } - if (tmp32 < 0) - { - x[i] = L_shr(x[i], 1); - move32(); - } - } - i = add(i, 1); - - IF (x[i] < 0) - { - tmp32 = L_sub(x[i], L_negate(v4)); - - if (tmp32 > 0) - { - lf_deemph_factors[i] = shr(lf_deemph_factors[i], 1); - move16(); - } - if (tmp32 <= 0) - { - x[i] = L_add(x[i], v2); - move32(); - } - if (tmp32 > 0) - { - x[i] = L_shr(x[i], 1); - move32(); - } - } - ELSE - { - tmp32 = L_sub(x[i], v4); - - if (tmp32 < 0) - { - lf_deemph_factors[i] = shr(lf_deemph_factors[i], 1); - move16(); - } - if (tmp32 >= 0) - { - x[i] = L_sub(x[i], v2); - move32(); - } - if (tmp32 < 0) - { - x[i] = L_shr(x[i], 1); - move32(); - } - } - } - ELSE /*if(!tcx_lpc_shaped_ari)*/ - { - PsychAdaptLowFreqDeemph(x, lpcGains, lpcGains_e, lf_deemph_factors); - }/*if(!tcx_lpc_shaped_ari)*/ - -} - -void tcx_noise_filling( - Word32 *Q, - Word16 Q_e, - Word16 seed, - Word16 iFirstLine, - Word16 lowpassLine, - Word16 nTransWidth, - Word16 L_frame, - Word16 tiltCompFactor, - Word16 fac_ns, - Word16 *infoTCXNoise +void mdct_noiseShaping( + float x[], + int lg, + const float gains[] ) { - Word16 i, m, segmentOffset; - Word16 win; /* window coefficient */ - Word16 tilt_factor; - Word32 nrg; - Word16 tmp1, tmp2, s; - Word32 tmp32; + int i, j, k, l; + float g; + int m, n, k1, k2; - /* get inverse frame length */ - tmp1 = getInvFrameLen(L_frame); + j = 0; + k = lg/FDNS_NPTS; + m = lg%FDNS_NPTS; - /* tilt_factor = (float)pow(max(0.375f, tiltCompFactor), 1.0f/(float)L_frame); */ - tmp32 = BASOP_Util_Log2(L_deposit_h(s_max(0x3000, tiltCompFactor))); /* 6Q25 */ - tmp32 = L_shr(Mpy_32_16_1(tmp32, tmp1), 6); - BASOP_SATURATE_WARNING_OFF; - tilt_factor = round_fx(BASOP_Util_InvLog2(tmp32)); - BASOP_SATURATE_WARNING_ON; + if (m) + { + if ( m <= (FDNS_NPTS/2) ) + { + n = FDNS_NPTS/m; + k1 = k; + k2 = k + 1; + } + else + { + n = FDNS_NPTS/(FDNS_NPTS-m); + k1 = k + 1; + k2 = k; + } + + for (i=0; i lpcGains[i]) + { + tmp = lpcGains[i]; + } + if (max < lpcGains[i]) + { + max = lpcGains[i]; + } + } + + tmp *= 32.0f; + + if ((max < tmp) && (tmp > FLT_MIN)) + { + fac = tmp = (float)pow(max / tmp, 0.0078125f); + + if (lf_deemph_factors) + { + /* gradual lowering of lowest 32 bins; DC is lowered by (max/tmp)^1/4 */ + for (i = 31; i >= 0; i--) + { + x[i] *= fac; + lf_deemph_factors[i] *= fac; + fac *= tmp; + } + } + else + { + /* gradual lowering of lowest 32 bins; DC is lowered by (max/tmp)^1/4 */ + for (i = 31; i >= 0; i--) + { + x[i] *= fac; + fac *= tmp; + } + } + } + + return; +} + + +/*-------------------------------------------------------------------* +* AdaptLowFreqDeemph() +* +* +*-------------------------------------------------------------------*/ + +void AdaptLowFreqDeemph( + float x[], + short tcx_lpc_shaped_ari, + const float lpcGains[], + const int lg, + float lf_deemph_factors[] +) +{ + + int i, i_max_old,i_max; + + if(!tcx_lpc_shaped_ari) + { + /* 1. find first magnitude maximum in lower quarter of spectrum */ + i_max = -1; + + for (i = 0; i < lg/4; i++) + { + if ((x[i] <= -4.0f) || (x[i] >= 4.0f)) + { + x[i] += (x[i] < 0.0f) ? 2.0f : -2.0f; + i_max = i; + break; + } + } + /* 2. expand value range of all xi up to i_max: two extra steps */ + + for (i = 0; i < i_max; i++) + { + x[i] *= 0.5f; + lf_deemph_factors[i] *= 0.5f; + } + /* 3. find first magnitude maximum in lower quarter of spectrum */ + i_max_old = i_max; + + if (i_max_old > -1) + { + i_max = -1; + + for (i = 0; i < lg/4; i++) + { + if ((x[i] <= -4.0f) || (x[i] >= 4.0f)) + { + x[i] += (x[i] < 0.0f) ? 2.0f : -2.0f; + i_max = i; + break; + } + } + } + /* 4. expand value range of all xi up to i_max: two extra steps */ + for (i = 0; i < i_max; i++) + { + x[i] *= 0.5f; + lf_deemph_factors[i] *= 0.5f; + } + /* 5. always expand two lines; lines could be at index 0 and 1! */ + if (i_max < i_max_old) + { + i_max = i_max_old; + } + i = i_max + 1; + if (x[i] < 0.0f) + { + if (x[i] > -4.0f) + { + lf_deemph_factors[i] *= 0.5f; + } + x[i] = (x[i] <= -4.0f) ? x[i] + 2.0f : x[i] * 0.5f; + } + else + { + if (x[i] < 4.0f) + { + lf_deemph_factors[i] *= 0.5f; + } + x[i] = (x[i] >= 4.0f) ? x[i] - 2.0f : x[i] * 0.5f; + } + i++; + if (x[i] < 0.0f) + { + if (x[i] > -4.0f) + { + lf_deemph_factors[i] *= 0.5f; + } + x[i] = (x[i] <= -4.0f) ? x[i] + 2.0f : x[i] * 0.5f; + } + else + { + if (x[i] < 4.0f) + { + lf_deemph_factors[i] *= 0.5f; + } + x[i] = (x[i] >= 4.0f) ? x[i] - 2.0f : x[i] * 0.5f; + } + } + else + { + /*if(!tcx_lpc_shaped_ari)*/ + PsychAdaptLowFreqDeemph(x, lpcGains, lf_deemph_factors); + }/*if(!tcx_lpc_shaped_ari)*/ + + return; +} + + +/*-------------------------------------------------------------------* +* tcx_noise_filling() +* +* +*-------------------------------------------------------------------*/ + +void tcx_noise_filling( + float *Q, + const int noiseFillSeed, + const int iFirstLine, + const int lowpassLine, + const int nTransWidth, + const int L_frame, + float tiltCompFactor, + float fac_ns, + unsigned char *infoTCXNoise +) +{ + int i, m, segmentOffset; + int win; /* window coefficient */ + Word16 seed; + float tilt_factor, nrg, tmp1, tmp2; + + /* 16-bit random number generator seed for generating filled lines */ + seed = (Word16)noiseFillSeed; + + tilt_factor = (float)pow(max(0.375f, tiltCompFactor), 1.0f/(float)L_frame); + fac_ns /= (float)(nTransWidth * nTransWidth); /* find last nonzero line below iFirstLine, use it as start offset */ - tmp1 = shr(iFirstLine, 1); - FOR (i = iFirstLine; i > tmp1; i--) + for (i = iFirstLine; i > (iFirstLine >> 1); i--) { - IF (Q[i] != 0) + if (Q[i] != 0.0f) { - BREAK; + break; } } - /* fac_ns *= (float)pow(tilt_factor, (float)i); */ - FOR (m = 0; m < i; m++) - { - fac_ns = mult_r(fac_ns, tilt_factor); - } + fac_ns *= (float)pow(tilt_factor, (float)i); - nrg = L_deposit_l(1); + nrg = 1e-9f; win = 0; - move16(); - i = add(i, 1); - segmentOffset = i; - move16(); + segmentOffset = ++i; - FOR (; i < lowpassLine; i++) + for (; i < lowpassLine; i++) { - fac_ns = mult_r(fac_ns, tilt_factor); + fac_ns *= tilt_factor; - IF (Q[i] != 0) + if (Q[i] != 0.0f) { - IF (win > 0) + if (win > 0) { /* RMS-normalize current noise-filled segment */ - tmp1 = BASOP_Util_Divide3216_Scale(nrg, sub(i, segmentOffset), &s); /* mean */ - s = add(s, 9-15); /* scaling */ - tmp1 = ISqrt16(tmp1, &s); /* 1/RMS */ - tmp1 = mult_r(tmp1, inv_int[nTransWidth]); /* compensate win */ - s = add(s, sub(16, Q_e)); /* scaling */ + tmp1 = (float)sqrt((i - segmentOffset) / nrg); + tmp2 = tmp1 * (float)nTransWidth; - tmp2 = sub(i, win); - IF (sub(segmentOffset, tmp2) < 0) + for (m = segmentOffset; m < i-win; m++) { - FOR (m = segmentOffset; m < tmp2; m++) - { - Q[m] = L_shl(Mpy_32_16_1(Q[m], tmp1), s); - move32(); - } + Q[m] *= tmp2; } - tmp2 = mult(tmp1, inv_int[nTransWidth]); - tmp1 = extract_l(L_mult0(tmp2, win)); - FOR (m = sub(i, win); m < i; m++) + for (; win > 0; win--) { - Q[m] = L_shl(Mpy_32_16_1(Q[m], tmp1), s); - move32(); - win = sub(win, 1); - tmp1 = sub(tmp1, tmp2); + Q[m++] *= tmp1 * (float)win; } - - nrg = L_deposit_l(1); /* start new segment: reset noise segment energy */ + nrg = 1e-9f; /* start new segment: reset noise segment energy */ } - segmentOffset = add(i, 1); + segmentOffset = i + 1; } - ELSE /* line is zero, so fill line and update window and energy */ + else { - if (sub(win, nTransWidth) < 0) + /* line is zero, so fill line and update window and energy */ + if (win < nTransWidth) { - win = add(win, 1); + win++; } + tmp1 = (float)own_random(&seed); + nrg += tmp1 * tmp1; /* sum up energy of current noise segment */ + Q[i] = tmp1 * (float)win * fac_ns; - seed = own_random2_fx(seed); - Q[i] = L_mult0(mult(seed, fac_ns), win); - move32(); - - tmp1 = shr(seed, 4); - nrg = L_mac0(nrg, tmp1, tmp1); /* sum up energy of current noise segment */ - - if(infoTCXNoise) /* set noiseflags for IGF */ + if(infoTCXNoise) { + /* set noiseflags for IGF */ infoTCXNoise[i] = 1; - move16(); } } } - IF (win > 0) + if (win > 0) { /* RMS-normalize uppermost noise-filled segment */ - tmp1 = BASOP_Util_Divide3216_Scale(nrg, sub(lowpassLine, segmentOffset), &s); /* mean */ - s = add(s, 9-15); /* compensate energy scaling */ - tmp1 = ISqrt16(tmp1, &s); /* 1/RMS */ - tmp1 = mult_r(tmp1, inv_int[nTransWidth]); /* compensate win */ - s = add(s, sub(16, Q_e)); /* compensate noise scaling */ + tmp1 = (float)sqrt((lowpassLine - segmentOffset) / nrg); + tmp2 = tmp1 * (float)nTransWidth; - FOR (m = segmentOffset; m < lowpassLine; m++) + for (m = segmentOffset; m < lowpassLine; m++) { - Q[m] = L_shl(Mpy_32_16_1(Q[m], tmp1), s); - move32(); + Q[m] *= tmp2; } } + return; } +/*-------------------------------------------------------------------* +* InitTnsConfigs() +* +* +*-------------------------------------------------------------------*/ -/*--------------------------------------------------------------- - * Residual Quantization - *--------------------------------------------------------------*/ - - -void InitTnsConfigs(Word32 nSampleRate, Word16 L_frame, - STnsConfig tnsConfig[2][2] - ,Word16 igfStopFreq - ,Word32 bitrate - ) +void InitTnsConfigs( + int nSampleRate, + int L_frame, + STnsConfig tnsConfig[2][2], + int igfStopFreq, + int bitrate +) { - IF (L_sub(bitrate,ACELP_32k) > 0) + if (bitrate > ACELP_32k) { - InitTnsConfiguration(nSampleRate, shr(L_frame,1), &tnsConfig[0][0], igfStopFreq, bitrate); + InitTnsConfiguration(nSampleRate, L_frame/2, &tnsConfig[0][0], igfStopFreq, bitrate); } InitTnsConfiguration(nSampleRate, L_frame, &tnsConfig[1][0], igfStopFreq, bitrate); - InitTnsConfiguration(nSampleRate, add(L_frame, shr(L_frame,2)), &tnsConfig[1][1], igfStopFreq, bitrate); + InitTnsConfiguration(nSampleRate, L_frame +L_frame/4, &tnsConfig[1][1], igfStopFreq, bitrate); + + return; } -void SetTnsConfig(TCX_config * tcx_cfg, Word8 isTCX20, Word8 isAfterACELP) + +/*-------------------------------------------------------------------* +* SetTnsConfig() +* +* +*-------------------------------------------------------------------*/ + +void SetTnsConfig( + TCX_config * tcx_cfg, + int isTCX20, + int isAfterACELP +) { - move16(); tcx_cfg->pCurrentTnsConfig = &tcx_cfg->tnsConfig[isTCX20][isAfterACELP]; assert(tcx_cfg->pCurrentTnsConfig != NULL); -} - - -void tcx_get_gain(Word32 *x, /* i: spectrum 1 */ - Word16 x_e, /* i: spectrum 1 exponent */ - Word32 *y, /* i: spectrum 2 */ - Word16 y_e, /* i: spectrum 2 exponent */ - Word16 n, /* i: length */ - Word16 *gain, /* o: gain */ - Word16 *gain_e, /* o: gain exponent */ - Word32 *en_y, /* o: energy of y (optional) */ - Word16 *en_y_e /* o: energy of y exponent (optional) */ - ) -{ - Word32 maxX, minX, maxY, minY; - Word32 corr, ener; - Word16 sx, sy, corr_e, ener_e; - Word16 i, tmp; - - - maxX = L_deposit_l(1); - maxY = L_deposit_l(1); - minX = L_deposit_l(-1); - minY = L_deposit_l(-1); - FOR (i = 0; i < n; i++) - { - if (x[i] > 0) maxX = L_max(maxX, x[i]); - if (x[i] < 0) minX = L_min(minX, x[i]); - - if (y[i] > 0) maxY = L_max(maxY, y[i]); - if (y[i] < 0) minY = L_min(minY, y[i]); - } - sx = s_min(norm_l(maxX), norm_l(minX)); - sy = s_min(norm_l(maxY), norm_l(minY)); - sx = sub(sx, 4); - sy = sub(sy, 4); - - ener = L_deposit_l(0); - corr = L_deposit_l(0); - FOR (i = 0; i < n; i++) - { - tmp = round_fx(L_shl(y[i], sy)); - ener = L_mac0(ener, tmp, tmp); - corr = L_mac0(corr, tmp, round_fx(L_shl(x[i], sx))); - } - - if (ener == 0) ener = L_deposit_l(1); - - ener_e = add(shl(sub(y_e, sy), 1), 1); - corr_e = add(sub(add(x_e, y_e), add(sx, sy)), 1); - - tmp = sub(norm_l(corr), 1); - corr = L_shl(corr, tmp); - corr_e = sub(corr_e, tmp); - - tmp = norm_l(ener); - ener = L_shl(ener, tmp); - ener_e = sub(ener_e, tmp); - - tmp = div_s(abs_s(round_fx(corr)), round_fx(ener)); - if (corr < 0) tmp = negate(tmp); - - *gain = tmp; - move16(); - *gain_e = sub(corr_e, ener_e); - move16(); - - if (en_y != NULL) - { - *en_y = ener; - move32(); - } - if (en_y_e != NULL) - { - *en_y_e = ener_e; - move16(); - } - -} - -void init_TCX_config(TCX_config *tcx_cfg, - Word16 L_frame, - Word16 fscale - ,Word16 L_frameTCX - ,Word16 fscaleFB - ) -{ - /* Initialize the TCX MDCT windows */ - tcx_cfg->tcx_mdct_window_length = extract_l(L_shr(L_mult0(L_LOOK_12k8, fscale), LD_FSCALE_DENOM)); - tcx_cfg->tcx_mdct_window_delay = tcx_cfg->tcx_mdct_window_length; - move16(); - - tcx_cfg->tcx_mdct_window_half_length = extract_l(L_shr(L_mult0(L_LOOK_12k8 - NS2SA(12800, 5000000L), fscale), LD_FSCALE_DENOM)); - - tcx_cfg->tcx_mdct_window_min_length = shr(L_frame, 4); /* 1.25ms */ - tcx_cfg->tcx_mdct_window_trans_length = shr(L_frame, 4); /* 1.25ms */ - - tcx_cfg->tcx5Size = shr(L_frame, 2); /* 5ms */ - - tcx_cfg->tcx_mdct_window_lengthFB = extract_l(L_shr(L_mult0(L_LOOK_12k8, fscaleFB), LD_FSCALE_DENOM)); - tcx_cfg->tcx_mdct_window_delayFB = tcx_cfg->tcx_mdct_window_lengthFB; - move16(); - - tcx_cfg->tcx_mdct_window_half_lengthFB = extract_l(L_shr(L_mult0(L_LOOK_12k8 - NS2SA(12800, 5000000L), fscaleFB), LD_FSCALE_DENOM)); - - tcx_cfg->tcx_mdct_window_min_lengthFB = shr(L_frameTCX, 4); /* 1.25ms */ - tcx_cfg->tcx_mdct_window_trans_lengthFB = shr(L_frameTCX, 4); /* 1.25ms */ - - tcx_cfg->tcx5SizeFB = shr(L_frameTCX, 2); /* 5ms */ - - mdct_window_sine( &tcx_cfg->tcx_mdct_window, tcx_cfg->tcx_mdct_window_length ); - mdct_window_sine( &tcx_cfg->tcx_mdct_window_half, tcx_cfg->tcx_mdct_window_half_length ); - mdct_window_sine( &tcx_cfg->tcx_mdct_window_minimum, tcx_cfg->tcx_mdct_window_min_length ); - mdct_window_sine( &tcx_cfg->tcx_mdct_window_trans, tcx_cfg->tcx_mdct_window_trans_length ); - - mdct_window_sine( &tcx_cfg->tcx_mdct_windowFB, tcx_cfg->tcx_mdct_window_lengthFB ); - mdct_window_sine( &tcx_cfg->tcx_mdct_window_halfFB, tcx_cfg->tcx_mdct_window_half_lengthFB ); - mdct_window_sine( &tcx_cfg->tcx_mdct_window_minimumFB, tcx_cfg->tcx_mdct_window_min_lengthFB ); - mdct_window_sine( &tcx_cfg->tcx_mdct_window_transFB, tcx_cfg->tcx_mdct_window_trans_lengthFB ); - - /*ALDO windows for MODE2*/ - mdct_window_aldo(tcx_cfg->tcx_aldo_window_1, tcx_cfg->tcx_aldo_window_1_trunc, tcx_cfg->tcx_aldo_window_2, L_frame); - mdct_window_aldo(tcx_cfg->tcx_aldo_window_1_FB, tcx_cfg->tcx_aldo_window_1_FB_trunc, tcx_cfg->tcx_aldo_window_2_FB, L_frameTCX); + + return; } diff --git a/src/libs/libevs/lib_com/tec_com.cpp b/src/libs/libevs/lib_com/tec_com.cpp old mode 100755 new mode 100644 index 948b2017..11b88e91 --- a/src/libs/libevs/lib_com/tec_com.cpp +++ b/src/libs/libevs/lib_com/tec_com.cpp @@ -1,1511 +1,929 @@ /*==================================================================================== - EVS Codec 3GPP TS26.442 Apr 03, 2018. Version 12.11.0 / 13.6.0 / 14.2.0 + EVS Codec 3GPP TS26.443 Nov 13, 2018. Version 12.11.0 / 13.7.0 / 14.3.0 / 15.1.0 ====================================================================================*/ +#include #include #include #include -#include "stl.h" -#include "basop_util.h" -#include "prot_fx.h" -#include "cnst_fx.h" +#include "rom_com.h" +#include "prot.h" +#include "stat_dec.h" +/*------------------------------------------------------------------- + * Local constants + *-------------------------------------------------------------------*/ -#ifndef EPS -#define EPS ( 1e-12f) -#endif +#define LOBUF_NO_SMOOTHING_MODE 1 -#define ENV_SCALE_OFFSET_1_FX 1515133568l/*90.309f/128.0 Q31*/ /* 10*log10(2^30) */ /* scaled by 1/128.0 */ -#define MAX_TEC_BW_LO (12) -#define MAX_NB_TEC_LOW_BAND ( 3) +#define EPS (1e-12f) +#define ENV_SCALE_OFFSET_1 90.309f /* 10*log10(2^30) */ +#define MAX_TEC_BW_LO (12) +#define MAX_NB_TEC_LOW_BAND (3) -static const Word16 TecSmoothingDeg = 5; -static const Word16 NbTecLowBand = 3; +const float TecSC[] = {0.3662f, 0.1078f, 0.1194f, 0.1289f, 0.1365f, 0.1412f}; +const int TecLowBandTable[] = {0, 2, 4, 6}; -#define LOBUF_NO_SMOOTHING_MODE 1 +#define TecSmoothingDeg 5 +#define NbTecLowBand 3 -void -resetTecDec_Fx( - HANDLE_TEC_DEC_FX hTecDec +#define ratioHiLoFac 1.5894f +#define thRatio 0.3649f +#define thRatio2 2.0288f +#define thCorrCoef 0.8795f +#define ratioHiLoFacDec (1.5894f * 0.75f) + +/*------------------------------------------------------------------- + * calcLoBufferDec() + * + * + *-------------------------------------------------------------------*/ + +static void calcLoBufferDec( + float **pCldfbReal, + float **pCldfbImag, + float* loBuffer, + int startPos, + int stopPos, + int bandOffsetBottom, + float scaleOffset ) { + int slot, k, lb, li, ui; + float nrg, tmp; - set16_fx(hTecDec->pGainTemp_m, 0, CLDFB_NO_COL_MAX); - set16_fx(hTecDec->pGainTemp_e, 0, CLDFB_NO_COL_MAX); - - set16_fx(hTecDec->loBuffer, 0, CLDFB_NO_COL_MAX + MAX_TEC_SMOOTHING_DEG); - - return; -} - - -void -resetTecEnc_Fx(HANDLE_TEC_ENC_FX hTecEnc, Word16 flag) -{ - IF (flag == 0) + /* calc loTempEnv */ + for (slot = startPos; slot < stopPos; slot++) { - set16_fx(hTecEnc->loBuffer, 0, CLDFB_NO_COL_MAX + MAX_TEC_SMOOTHING_DEG + DELAY_TEMP_ENV_BUFF_TEC); - set16_fx(hTecEnc->loTempEnv, 0, CLDFB_NO_COL_MAX); - set16_fx(hTecEnc->loTempEnv_ns, 0, CLDFB_NO_COL_MAX); - set16_fx(hTecEnc->hiTempEnv, 0, CLDFB_NO_COL_MAX + DELAY_TEMP_ENV_BUFF_TEC + EXT_DELAY_HI_TEMP_ENV); - } - ELSE - { - set16_fx(hTecEnc->loBuffer, 0, MAX_TEC_SMOOTHING_DEG); - } - return; -} + tmp = 0; - -static Word32 calcVar_Fix(const Word32 in[], Word32 len, Word32* x) -{ - Word32 xx; - Word32 i; - Word16 exp1; - Word32 ans; - Word16 r_sft; - Word32 tmpX; - - xx = L_deposit_l(0); - *x = L_deposit_l(0); - FOR(i=0; i 0 ) - { - IF ( L_sub(tmp32,1006632960l/*0.46875 Q31*/) >= 0 ) - { - s = add(s,sub(WORD32_BITS,norm_l(BASOP_Util_InvLog2(L_sub(tmp32,1006632960l/*0.46875 Q31*/))))); - s = add(s,30); - } - ELSE - { - s = add(s,sub(WORD32_BITS,norm_l(BASOP_Util_InvLog2(tmp32)))); - } - - /* scalefactor for logarithmic domain */ - logScaleFactor = L_shl(L_mult0(512/*1.0/(1<pGainTemp, 0, CLDFB_NO_COL_MAX); + + set_f(hTecDec->loBuffer, 0.f, CLDFB_NO_COL_MAX + MAX_TEC_SMOOTHING_DEG); + + return; +} + + +/*------------------------------------------------------------------- + * calcLoTempEnv_TBE() + * + * + *-------------------------------------------------------------------*/ + +static void calcLoTempEnv_TBE( + float* loBuffer, + int noCols, + float* loTempEnv, + float adjFac +) +{ + int slot, i; + int delay = 1; + + for (slot = 0; slot < noCols; slot++) + { + loTempEnv[slot] = TecSC[0] * loBuffer[slot - delay]; + + for (i = 1; i < TecSmoothingDeg + 1; i++) + { + loTempEnv[slot] += TecSC[i] * loBuffer[slot - delay - i]; + } + + loTempEnv[slot] *= adjFac; + } + + return; +} + + +/*------------------------------------------------------------------- + * set_TEC_TFA_code() + * + * + *-------------------------------------------------------------------*/ + +void set_TEC_TFA_code( + const short corrFlag, + short* tec_flag, + short* tfa_flag +) +{ + *tec_flag = 0; + if (*tfa_flag == 0) + { + if (corrFlag == 1) + { + *tec_flag = 1; + } + else if (corrFlag == 2) + { + *tec_flag = 1; + *tfa_flag = 1; + } + } + + return; +} + + +/*------------------------------------------------------------------- + * calcLoTempEnv_ns_TBE() + * + * + *-------------------------------------------------------------------*/ + +static void calcLoTempEnv_ns_TBE( + float* loBuffer, + int noCols, + float* loTempEnv +) +{ + int slot; + int delay = 1; + float fac = 1.4f; + + for (slot = 0; slot < noCols; slot++) + { + loTempEnv[slot] = fac * loBuffer[slot - delay]; + } + + return; +} + + +/*------------------------------------------------------------------- + * calcLoTempEnv_ns() + * + * + *-------------------------------------------------------------------*/ + +static void calcLoTempEnv_ns( + float* loBuffer, + int noCols, + float* loTempEnv +) +{ + int slot; + + for (slot = 0; slot < noCols; slot++) + { + loTempEnv[slot] = loBuffer[slot]; + } + + return; +} + +/*------------------------------------------------------------------- + * calcGainLinear_TBE() + * + * + *-------------------------------------------------------------------*/ + +static void calcGainLinear_TBE( + const float* loTempEnv, + const int startPos, + const int stopPos, + float* pGainTemp +) +{ + int timeIndex; + float ftmp; + + for (timeIndex = startPos; timeIndex < stopPos; timeIndex++) + { + ftmp = loTempEnv[timeIndex]; + pGainTemp[timeIndex] = (float) pow(10.0, 0.1 * ftmp); + } + + return; +} + + +/*------------------------------------------------------------------- + * calcGainTemp_TBE() + * + * + *-------------------------------------------------------------------*/ + +void calcGainTemp_TBE( + float** pCldfbRealSrc, + float** pCldfbImagSrc, + float* loBuffer, + int startPos, /*!< Start position of the current envelope. */ + int stopPos, /*!< Stop position of the current envelope. */ + int lowSubband, /* lowSubband */ + float* pGainTemp, + short code +) +{ + float loTempEnv[16]; + const int BW_LO = TecLowBandTable[NbTecLowBand]; + int slot; + /*int lowSubband = pFreqBandTable[0];*/ + int noCols = stopPos - startPos; + int bandOffset = 0; + float scaleOffset = 0; assert(lowSubband >= BW_LO); - calcLoBufferDec_Fx( - pCldfbRealSrc_Fx, - pCldfbImagSrc_Fx, - loBuffer_Fx+MAX_TEC_SMOOTHING_DEG, - startPos, - stopPos, - bandOffset, - 15 - cldfb_exp - ); - IF (code > 0) + bandOffset = lowSubband - BW_LO; + + calcLoBufferDec( pCldfbRealSrc, pCldfbImagSrc, loBuffer + MAX_TEC_SMOOTHING_DEG, startPos, stopPos, bandOffset, scaleOffset ); + + if (code > 0) { - IF (sub(code, 2) != 0) + if (code != 2) { - calcLoTempEnv_TBE_Fx(loBuffer_Fx + MAX_TEC_SMOOTHING_DEG, noCols, - loTempEnv_Fx, 19531/*0.5f * ratioHiLoFacDec Q15*/); + calcLoTempEnv_TBE(loBuffer + MAX_TEC_SMOOTHING_DEG, noCols, loTempEnv, ratioHiLoFacDec); } - ELSE + else { - calcLoTempEnv_ns_TBE_Fx(loBuffer_Fx + MAX_TEC_SMOOTHING_DEG, noCols, loTempEnv_Fx); + calcLoTempEnv_ns_TBE(loBuffer + MAX_TEC_SMOOTHING_DEG, noCols, loTempEnv); } - calcGainLinear_TBE_Fx(loTempEnv_Fx, startPos, stopPos, - pGainTemp_m, pGainTemp_e); + calcGainLinear_TBE(loTempEnv, startPos, stopPos, pGainTemp); } - FOR (slot = 0; slot < MAX_TEC_SMOOTHING_DEG; slot++) + + for (slot = 0; slot < MAX_TEC_SMOOTHING_DEG; slot++) { - loBuffer_Fx[slot] = loBuffer_Fx[slot + stopPos]; - move16(); - } -} - -static void setSubfrConfig_Fix(Word16 i_offset, Word16* k_offset, Word16* n_subfr - , Word16 l_subfr - ) -{ - *n_subfr = sub((Word16)N_TEC_TFA_SUBFR,i_offset); - *k_offset = i_mult(i_offset,l_subfr); -} - -static Word16 calcSum_Fx(Word16* vec_m, /*Q0*/ - Word16* vec_e, /*Q0*/ - const Word16 len, - Word16* sum16_m /*Q0*/) -{ - Word16 slot; - Word16 sum16_e; /* Q0 */ - - *sum16_m = 0; - sum16_e = 0; - FOR (slot=0; slot 0) - { - Word16 tmp; - s = norm_l(nrg32); - tmp = extract_h(L_shl(nrg32, s)); - enr_m[i] = tmp; - move16(); - enr_e[i] = - s; - move16(); - } - ELSE - { - enr_m[i] = 0; - move16(); - enr_e[i] = - 15; - move16(); - } + enr_all += enr[i]; } - sum16_e = enr_e[i_offset]; - *sum16_m = enr_m[i_offset]; - FOR (i=i_offset+1; i 0) - { - BASOP_Util_Divide_MantExp(enr_ave_m, enr_ave_e, - enr_m[i], enr_e[i], - &inv_curr_enr_m[i], &inv_curr_enr_e[i]); - } - ELSE - { - /* 1.0e+12 */ - inv_curr_enr_m[i] = 28282/*0.8631 Q15*/; - move16(); - inv_curr_enr_e[i] = 39; - move16(); - } - - s = norm_s(inv_curr_enr_m[i]); - inv_curr_enr_m[i] = shl(inv_curr_enr_m[i], s); - move16(); - inv_curr_enr_e[i] = sub(inv_curr_enr_e[i], s); - move16(); - - IF (gain_m[i] > 0) - { - BASOP_Util_Divide_MantExp(gain_m[i], gain_e[i], - gain_ave_m, gain_ave_e, - &gain_m[i], &gain_e[i]); - } - ELSE - { - return exp_syn; - } - } - - /* find the maximum of inv_curr_enr */ - max_inv_curr_enr_e = inv_curr_enr_e[i_offset]; - move16(); - max_inv_curr_enr_m = inv_curr_enr_m[i_offset]; - move16(); - - FOR (i=i_offset+1; i 0) || (sub(lower_limit_gain_e, min_curr_enr_e) == 0 && sub(lower_limit_gain_m, min_curr_enr_m) > 0) ) - { - lower_limit_gain_m = min_curr_enr_m; - move16(); - lower_limit_gain_e = sub(min_curr_enr_e, 1); - move16(); - } - - /* upper_limit_gain */ - upper_limit_gain_m = 19661/*0.6f Q15*/; /* norm = 0 */ move16(); - upper_limit_gain_e = 1; - move16(); - IF (sub(code, LOBUF_NO_SMOOTHING_MODE) == 0) - { - upper_limit_gain_m = 24576/*0.75f Q15*/; /* norm = 0 */ move16(); - upper_limit_gain_e = 2; - move16(); - } - - min_shift = 15; /* min_shift <= 15 */ move16(); - - k = k_offset; - move16(); - FOR (i=i_offset; i 0) || (sub(lower_limit_gain_e, gain_e[i]) == 0 && sub(lower_limit_gain_m, gain_m[i]) > 0)) - { - gain_m[i] = lower_limit_gain_m; - move16(); - gain_e[i] = lower_limit_gain_e; - move16(); - } - - gain_m[i] = mult_r(gain_m[i], inv_curr_enr_m[i]); - gain_e[i] = add(gain_e[i], inv_curr_enr_e[i]); - - s = norm_s(gain_m[i]); - gain_m[i] = shl(gain_m[i], s); - move16(); - gain_e[i] = sub(gain_e[i], s); - move16(); - - test(); - test(); - IF ( (sub(upper_limit_gain_e, gain_e[i]) < 0) || (sub(upper_limit_gain_e, gain_e[i]) == 0 && sub(upper_limit_gain_m, gain_m[i]) < 0)) - { - - gain_m[i] = upper_limit_gain_m; - move16(); - gain_e[i] = upper_limit_gain_e; - move16(); - } - - gain_m[i] = Sqrt16(gain_m[i], &gain_e[i]); - move16(); - s = norm_s(gain_m[i]); - gain_m[i] = shl(gain_m[i], s); - move16(); - gain_e[i] = sub(gain_e[i], s); - move16(); - - FOR(j=0; j 0) - { - min_shift = shift[k]; - move16(); - } - k = add(k, 1); - } - } - - s = exp_syn; - move16(); - - exp_syn = sub(s, min_shift); - if (exp_syn > 15) - { - exp_syn = 15; - move16(); - } - - if (exp_syn < 0) - { - exp_syn = 0; - move16(); - } - - min_shift = sub(s, exp_syn); /* exp_syn(old) - exp_syn(new) */ - - k = k_offset; - FOR (i=i_offset; i 0) - { - hb_synth_Fx[k] = shr(hb_synth_Fx[k], s); - move16(); - } - k = add(k, 1); - } - } - - return exp_syn; -} - -static Word16 procTfa_Fx(Word16* hb_synth_Fx, - Word16 exp_syn, - Word16 i_offset, - Word16 l_subfr - ) -{ - Word16 i,j,k; - Word16 k_offset, n_subfr; - - Word16 enr_m[N_TEC_TFA_SUBFR]; - Word16 enr_e[N_TEC_TFA_SUBFR]; - - Word16 enr_ave_m; - Word16 enr_ave_e; - - Word16 inv_n_subfr; - - Word16 s; - Word16 shift[L_FRAME_MAX]; - Word16 min_shift; - - Word16 gain_m[N_TEC_TFA_SUBFR]; - Word16 gain_e[N_TEC_TFA_SUBFR]; - - setSubfrConfig_Fix(i_offset, &k_offset, &n_subfr, l_subfr); - - assert(8 /* = 2^3 */ < n_subfr); - inv_n_subfr = getNormReciprocalWord16Scale(n_subfr, 3); - - enr_ave_e = calcSubfrNrg_Fx(hb_synth_Fx, - exp_syn, - i_offset, - enr_m, - enr_e, - k_offset, - &enr_ave_m - ,l_subfr - ); - - enr_ave_m = mult_r(enr_ave_m, inv_n_subfr); - enr_ave_e = sub(enr_ave_e, 3); - - min_shift = 15; /* min_shift <= 15 */ move16(); - - k = k_offset; - move16(); - FOR (i=i_offset; i 0) - { - BASOP_Util_Divide_MantExp(enr_ave_m, enr_ave_e, - enr_m[i], enr_e[i], - &gain_m[i], &gain_e[i]); - } - ELSE - { - /* gain = 1 */ - gain_m[i] = 32767; - move16(); - gain_e[i] = 0; - move16(); - } - - gain_m[i] = Sqrt16(gain_m[i], &gain_e[i]); - move16(); - - s = norm_s(gain_m[i]); - gain_m[i] = shl(gain_m[i], s); - move16(); - gain_e[i] = sub(gain_e[i], s); - move16(); - - FOR (j=0; j 0) - { - min_shift = shift[k]; - move16(); - } - k = add(k, 1); - } - } - - /* determin new exponent for hb_synth */ - s = exp_syn; - move16(); - exp_syn = sub(s, min_shift); - if (exp_syn > 15) - { - exp_syn = 15; - move16(); - } - - if (exp_syn < 0) - { - exp_syn = 0; - move16(); - } - - min_shift = sub(s, exp_syn); /* exp_syn(old) - exp_syn(new) */ - - k = k_offset; - move16(); - FOR (i=i_offset; i 0) - { - hb_synth_Fx[k] = shr(hb_synth_Fx[k], s); - move16(); - } - k = add(k, 1); - } - } - - return exp_syn; + return enr_all; } -Word16 procTecTfa_TBE_Fx(Word16 *hb_synth_Fx, - Word16 hb_synth_fx_exp, - Word16 *gain_m, - Word16 *gain_e, - Word16 flat_flag, - Word16 last_core - , Word16 l_subfr - , Word16 code - ) +/*------------------------------------------------------------------- + * procTfa() + * + * + *-------------------------------------------------------------------*/ + +static void procTfa( + float *hb_synth, + int i_offset, + int l_subfr +) { - Word16 i_offset = 0; - Word16 exp_syn_frame = sub(15, hb_synth_fx_exp); + int i,j,k; + int k_offset, n_subfr; + float enr[N_TEC_TFA_SUBFR], enr_ave; + setSubfrConfig(i_offset, &k_offset, &n_subfr, l_subfr); - IF (flat_flag) + enr_ave = calcSubfrNrg(hb_synth, i_offset, enr, k_offset, l_subfr) / n_subfr; + + for (i=i_offset, k=k_offset; i (tmp = 1.0 / max_inv_curr_enr)) + { + lower_limit_gain = tmp * 0.5; + } + + upper_limit_gain = 1.2f; + if (code == LOBUF_NO_SMOOTHING_MODE) + { + upper_limit_gain = 3.0; + } + + for (i=i_offset, k=k_offset; i gain[i]) + { + gain[i] = lower_limit_gain; + } + gain[i] *= inv_curr_enr[i]; + + if (gain[i] > upper_limit_gain) + { + gain[i] = upper_limit_gain; + } + + gain[i] = sqrt(gain[i]); + for(j=0; jloBuffer, 0.f, CLDFB_NO_COL_MAX + MAX_TEC_SMOOTHING_DEG + DELAY_TEMP_ENV_BUFF_TEC); + set_f(hTecEnc->hiTempEnv, 0.f, CLDFB_NO_COL_MAX + DELAY_TEMP_ENV_BUFF_TEC + EXT_DELAY_HI_TEMP_ENV); + set_f(hTecEnc->loTempEnv, 0.f, CLDFB_NO_COL_MAX); + set_f(hTecEnc->loTempEnv_ns, 0.f, CLDFB_NO_COL_MAX); + } + else + { + set_f(hTecEnc->loBuffer, 0.f, MAX_TEC_SMOOTHING_DEG); + } - Word16 bandOffsetBottom; - - Word16* hiTempEnv = hiTempEnvOrig_Fix + EXT_DELAY_HI_TEMP_ENV; - - move16(); - move16(); - move16(); - bandOffsetBottom = sub(lowSubband, BW_LO); - - assert(bandOffsetBottom > 0); - assert(noCols <= CLDFB_NO_COL_MAX); - - /* ============================================================ */ - /* = calc hiTempEnv = */ - - calcHiTempEnv_Fx(pCldfbPow_Fix,sub(pCldfbPow_FixScale,30),0,noCols,lowSubband,highSubband,hiTempEnv + DELAY_TEMP_ENV_BUFF_TEC); - - /* = = */ - /* ============================================================ */ - - /* ============================================================ */ - /* = calc loBuffer = */ - - calcLoBufferEnc_Fx(pCldfbPow_Fix,sub(pCldfbPow_FixScale,30),0, noCols,bandOffsetBottom,loBuffer_Fix + MAX_TEC_SMOOTHING_DEG + DELAY_TEMP_ENV_BUFF_TEC); - - /* = = */ - /* ============================================================ */ + return; } -void -calcLoEnvCheckCorrHiLo_Fix( - Word16 noCols, - Word16* pFreqBandTable, /*!< freqbandTable. */ - Word16* loBuffer_Fix /*float* loBuffer Q8*/, - Word16* loTempEnv_Fix /*float* loTempEnv Q7*/, - Word16* loTempEnv_ns_Fix /* float* loTempEnv_ns*/, - Word16* hiTempEnvOrig_Fix /*float* hiTempEnvOrig*/, - Word16* corrFlag /*int* corrFlag*/ + +/*------------------------------------------------------------------- + * calcHiEnvLoBuff() + * + * + *-------------------------------------------------------------------*/ + +void calcHiEnvLoBuff( + int noCols, + const int* pFreqBandTable, /*!< freqbandTable. */ + int nSfb, /*!< Number of scalefactors. */ + float** pCldfbPow, + float* loBuffer, + float* hiTempEnvOrig ) { - const Word16 BW_LO = TecLowBandTable[NbTecLowBand]; - const Word16 lowSubband = pFreqBandTable[0]; - Word16 i; + const int BW_LO = TecLowBandTable[NbTecLowBand]; + const int lowSubband = pFreqBandTable[0]; + const int highSubband = pFreqBandTable[nSfb]; - Word16 bandOffsetBottom; + int bandOffsetBottom = lowSubband - BW_LO; - Word32 hiVar_Fix, loVar_Fix; - Word32 hiSum_Fix, loSum_Fix; - Word32 hiTempEnv32_Fix[CLDFB_NO_COL_MAX + DELAY_TEMP_ENV_BUFF_TEC]; - Word32 loTempEnv32_Fix[CLDFB_NO_COL_MAX + DELAY_TEMP_ENV_BUFF_TEC]; - Word32 loTempEnv32_ns_Fix[CLDFB_NO_COL_MAX + DELAY_TEMP_ENV_BUFF_TEC]; - - Word32 corrCoef_Fix; - - Word32 EQ1, EQ2, EQ3; - Word32 EQ4,EQ5,EQ6; - - Word16 code = 0; /* SET TENTATIVELY */ - Word32 loVar_ns_Fix; - Word32 diff_hi_lo_sum_Fix; - Word32 loSum_ns_Fix; - Word16* hiTempEnv = hiTempEnvOrig_Fix + EXT_DELAY_HI_TEMP_ENV; - - - move16(); - move16(); - move16(); - bandOffsetBottom = sub(lowSubband, BW_LO); + float scaleOffset = 0; + float* hiTempEnv = hiTempEnvOrig + EXT_DELAY_HI_TEMP_ENV; assert(bandOffsetBottom > 0); - assert(noCols <= CLDFB_NO_COL_MAX); + + /* calc hiTempEnv*/ + calcHiTempEnv( pCldfbPow, 0, noCols, lowSubband, highSubband, scaleOffset, hiTempEnv + DELAY_TEMP_ENV_BUFF_TEC ); + + /* calc loBuffer */ + calcLoBufferEnc( pCldfbPow, 0, noCols, bandOffsetBottom, scaleOffset, loBuffer + MAX_TEC_SMOOTHING_DEG + DELAY_TEMP_ENV_BUFF_TEC ); + + return; +} - FOR( i = 0; i < noCols+ DELAY_TEMP_ENV_BUFF_TEC; i++) - { - hiTempEnv32_Fix[i] = L_deposit_l(hiTempEnv[i]); - } - hiVar_Fix = calcVar_Fix(hiTempEnv32_Fix, (Word32)noCols, &hiSum_Fix); +/*------------------------------------------------------------------- + * calcLoEnvCheckCorrHiLo() + * + * + *-------------------------------------------------------------------*/ +void calcLoEnvCheckCorrHiLo( + int noCols, + const int* pFreqBandTable, /*!< freqbandTable. */ + float* loBuffer, + float* loTempEnv, + float* loTempEnv_ns, + float* hiTempEnvOrig, + int* corrFlag +) +{ + const int BW_LO = TecLowBandTable[NbTecLowBand]; + const int lowSubband = pFreqBandTable[0]; + int i; + float corrCoef; + int bandOffsetBottom = lowSubband - BW_LO; + float ratio; + float hiVar, loVar; + float hiSum, loSum; + short code = 0; /* SET TENTATIVELY */ + float loVar_ns; + float loSum_ns; + float diff_hi_lo_sum; - /* ============================================================ */ - /* = calc loTempEnv = */ + float* hiTempEnv = hiTempEnvOrig + EXT_DELAY_HI_TEMP_ENV; + assert(bandOffsetBottom > 0); + hiVar = calcVar(hiTempEnv, noCols, &hiSum); - calcLoTempEnv_Fx(loBuffer_Fix+MAX_TEC_SMOOTHING_DEG,noCols,loTempEnv_Fix,26041/*0.5 * ratioHiLoFac Q15*/); + /* calc loTempEnv */ + calcLoTempEnv( loBuffer + MAX_TEC_SMOOTHING_DEG, noCols, loTempEnv, ratioHiLoFac ); + calcLoTempEnv_ns( loBuffer + MAX_TEC_SMOOTHING_DEG, noCols, loTempEnv_ns ); - calcLoTempEnv_ns_Fx(loBuffer_Fix+MAX_TEC_SMOOTHING_DEG,noCols,loTempEnv_ns_Fix); + loVar_ns = calcVar(loTempEnv_ns, noCols, &loSum_ns); + diff_hi_lo_sum = loSum_ns - hiSum; - /* = = */ - /* ============================================================ */ - - - FOR( i = 0; i < noCols; i++) - { - loTempEnv32_ns_Fix[i] = L_deposit_l(loTempEnv_ns_Fix[i]); - } - loVar_ns_Fix = calcVar_Fix(loTempEnv32_ns_Fix, noCols, &loSum_ns_Fix); - - diff_hi_lo_sum_Fix = L_sub(loSum_ns_Fix,hiSum_Fix); - - EQ4 = L_sub(L_shr(hiVar_Fix,7),800); - EQ5 = L_sub(L_shr(loVar_ns_Fix,7),720);; - EQ6 = L_sub(L_shr(diff_hi_lo_sum_Fix,7),100); ; - test(); - test(); - if (EQ4 > 0 && EQ5 > 0 && EQ6 < 0) + if (hiVar > 800 && loVar_ns > 720 && diff_hi_lo_sum < 100) { code = 1; - move16(); } - - *corrFlag = 0; - move16(); assert(code == 0 || code == 1); - IF (code) + if (code) { /* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/ /* ++++ code == 1 +++++*/ /* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/ - Word16 maxPosHi, maxPosLo; - Word16 maxHiFix, maxLoFix; + int maxPosHi, maxPosLo; + float maxHi, maxLo; - maxHiFix = hiTempEnv[0]; - move16(); - maxLoFix = loTempEnv_ns_Fix[0]; - move16(); + maxHi = hiTempEnv[0]; + maxLo = loTempEnv_ns[0]; maxPosHi = maxPosLo = 0; - move16(); - FOR (i = 1; i < noCols; i++) - { - if ( sub(maxHiFix , hiTempEnv[i]) < 0) - { - maxPosHi = i; - move16(); - } - maxHiFix = s_max(maxHiFix, hiTempEnv[i]); - if ( sub(maxLoFix , loTempEnv_ns_Fix[i]) < 0) + for (i = 1; i < noCols; i++) + { + if (maxHi < hiTempEnv[i]) { - maxPosLo = i; - move16(); + maxHi = hiTempEnv[i]; + maxPosHi = i; + } + + if (maxLo < loTempEnv_ns[i]) + { + maxLo = loTempEnv_ns[i]; + maxPosLo = i; } - maxLoFix = s_max(maxLoFix, loTempEnv_ns_Fix[i]); } - if (sub(abs_s( sub(maxPosHi , maxPosLo)), 2) < 0) + if (abs(maxPosHi - maxPosLo) < 2) { *corrFlag = 2; - move16(); } { + float feature_max = 0; + int pos_feature_max = 0; + float feature[16]; - Word16 feature_max_Fix = 0; - Word16 pos_feature_max = 0; - Word16 feature_Fix[16]; - Word16 min_local_Fix, max_local_Fix; - Word16 j; - Word16 len_window = EXT_DELAY_HI_TEMP_ENV + 1; + float min_local, max_local; + int j; + int len_window = EXT_DELAY_HI_TEMP_ENV + 1; + float* curr_pos = hiTempEnv; - Word16* curr_pos_Fix = hiTempEnv; - - move16(); - move16(); - move16(); - move16(); - - feature_max_Fix = 0; - move16(); + feature_max = 0; pos_feature_max = 0; - move16(); - FOR (i = 0; i < 16; i++) + for (i = 0; i < 16; i++, curr_pos++) { - max_local_Fix = min_local_Fix = curr_pos_Fix[0]; - move16(); - move16(); + max_local = min_local = curr_pos[0]; - FOR (j = 1; j < len_window; j++) + for (j = 1; j < len_window; j++) { - if ( sub( max_local_Fix , curr_pos_Fix[-j]) < 0) + if (max_local < curr_pos[-j]) { - max_local_Fix = curr_pos_Fix[-j]; - move16(); + max_local = curr_pos[-j]; } - if ( sub(min_local_Fix, curr_pos_Fix[-j] ) > 0) + if (min_local > curr_pos[-j]) { - min_local_Fix = curr_pos_Fix[-j]; - move16(); + min_local = curr_pos[-j]; } } - feature_Fix[i] = sub(max_local_Fix , min_local_Fix); - if ( sub(feature_max_Fix , feature_Fix[i]) < 0) + feature[i] = max_local - min_local; + + if (feature_max < feature[i]) { + feature_max = feature[i]; pos_feature_max = i; - move16(); } - feature_max_Fix = s_max(feature_max_Fix, feature_Fix[i]); - curr_pos_Fix += 1; } - IF (*corrFlag > 0) + if (*corrFlag > 0) { - test(); - if ((sub(feature_max_Fix, shl(20, 7)) <= 0 || sub(abs_s(sub(pos_feature_max, maxPosHi)), 3) >= 0 )) + if (!(feature_max > 20 && abs(pos_feature_max - maxPosHi) < 3 )) { *corrFlag = 0; - move16(); } } } - } - ELSE + else { /* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/ /* ++++ code == 0 ++++*/ /* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/ + /* calc the variance of loTempEnv */ + loVar = calcVar(loTempEnv, noCols, &loSum); - /* ============================================================ */ - /* = calc the variance of loTempEnv = */ + /* calc correlation coefficient between loTempEnv and hiTempEnv */ + corrCoef = calcCorrelationCoefficient2( hiTempEnv, loTempEnv, noCols, hiVar, loVar, hiSum, loSum ); - FOR( i = 0; i < noCols; i++) - { - loTempEnv32_Fix[i] = L_deposit_l(loTempEnv_Fix[i]); - } - loVar_Fix = calcVar_Fix(loTempEnv32_Fix, noCols, &loSum_Fix); - /* = = */ - /* ============================================================ */ + ratio = hiVar / (loVar + EPS); - /* ============================================================ */ - /* = calc correlation coefficient between = */ - /* = loTempEnv and hiTempEnv = */ - corrCoef_Fix = calcCorrelationCoefficient2_Fix( - hiTempEnv32_Fix, loTempEnv32_Fix, - noCols, hiVar_Fix, loVar_Fix, hiSum_Fix, loSum_Fix); - /* = = */ - /* ============================================================ */ - - - - - EQ1 = L_sub(L_shl(corrCoef_Fix, 8),28819/*thCorrCoef Q15*/); - EQ2 = L_sub(L_shl(hiVar_Fix,0),Mpy_32_16_1(loVar_Fix,11957/*thRatio Q15*/)); - EQ3 = L_sub(L_shr(hiVar_Fix,2),Mpy_32_16_1(loVar_Fix,16620/*thRatio2 Q13*/)); - - test(); - test(); - if (EQ1 >= 0 && EQ2 > 0 /*ratio > thRatio*/ && EQ3 < 0) + if (corrCoef >= thCorrCoef && ratio > thRatio && ratio < thRatio2) { *corrFlag = 1; - move16(); } } - FOR (i = 0; i < MAX_TEC_SMOOTHING_DEG + DELAY_TEMP_ENV_BUFF_TEC; i++) + for (i = 0; i < MAX_TEC_SMOOTHING_DEG + DELAY_TEMP_ENV_BUFF_TEC; i++) { - loBuffer_Fix[i] = loBuffer_Fix[noCols + i]; - move16(); + loBuffer[i] = loBuffer[noCols + i]; } - FOR (i = 0; i < DELAY_TEMP_ENV_BUFF_TEC + EXT_DELAY_HI_TEMP_ENV; i++) + for (i = 0; i < DELAY_TEMP_ENV_BUFF_TEC + EXT_DELAY_HI_TEMP_ENV; i++) { - hiTempEnvOrig_Fix[i] = hiTempEnvOrig_Fix[noCols + i]; - move16(); + hiTempEnvOrig[i] = hiTempEnvOrig[noCols + i]; } + return; } -void tecEnc_TBE_fx(Word16* corrFlag, const Word16* voicing, Word16 coder_type) + +/*------------------------------------------------------------------- + * tecEnc_TBE() + * + * + *-------------------------------------------------------------------*/ + +void tecEnc_TBE( + int* corrFlag, + const float *voicing, + short coder_type +) { - Word16 voice_sum; - Word16 voice_diff; + float voice_sum; + float voice_diff; /*-----------------------------------------------------------------* * TEC updates *-----------------------------------------------------------------*/ - voice_sum = add(shr(voicing[0], 1), shr(voicing[1], 1)); /*voice_sum = voicing[0] + voicing[1];*/ - voice_diff = sub(voicing[0], voicing[1]); /*voice_diff = voicing[0] - voicing[1];*/ + voice_sum = voicing[0] + voicing[1]; + voice_diff = voicing[0] - voicing[1]; if( voice_diff < 0 ) { - voice_diff = negate(voice_diff);/*voice_diff *= -1.0f;*/ + voice_diff *= -1.0f; } - IF( sub(*corrFlag, 1) == 0 ) + if( *corrFlag == 1 ) { - test(); - test(); - test(); - /*if( ((voice_sum > 0.35 * 2 && voice_sum < 0.55 * 2) && (voice_diff < 0.2)) )*/ - if( sub(coder_type,INACTIVE) == 0 || ((sub(voice_sum, 11469/*0.35 Q15*/) > 0 && sub(voice_sum, 18022/*0.55 Q15*/) < 0) && (sub(voice_diff, 6554/*0.2 Q15*/ < 0))) ) + if( coder_type == INACTIVE || (((voice_sum > 0.35 * 2 && voice_sum < 0.55 * 2) && (voice_diff < 0.2))) ) { *corrFlag = 0; - move16(); } } - if( sub(voice_sum, 19661/*0.6 Q15*/) > 0 ) /*if( voice_sum > 0.6 * 2 )*/ + if( voice_sum > 0.6 * 2 ) { *corrFlag = 0; - move16(); } + + return; } - -void set_TEC_TFA_code_fx(const Word16 corrFlag, Word16* tec_flag, Word16* tfa_flag) -{ - *tec_flag = 0; - move16(); - IF (*tfa_flag == 0) - { - test(); - if (sub(corrFlag, 1) == 0 || sub(corrFlag, 2) == 0) - { - *tec_flag = 1; - move16(); - } - - if (sub(corrFlag, 2) == 0) - { - *tfa_flag = 1; - move16(); - } - } -} - diff --git a/src/libs/libevs/lib_com/tns_base.cpp b/src/libs/libevs/lib_com/tns_base.cpp old mode 100755 new mode 100644 index 08966cf1..989bac94 --- a/src/libs/libevs/lib_com/tns_base.cpp +++ b/src/libs/libevs/lib_com/tns_base.cpp @@ -1,18 +1,24 @@ /*==================================================================================== - EVS Codec 3GPP TS26.442 Apr 03, 2018. Version 12.11.0 / 13.6.0 / 14.2.0 + EVS Codec 3GPP TS26.443 Nov 13, 2018. Version 12.11.0 / 13.7.0 / 14.3.0 / 15.1.0 ====================================================================================*/ - -#include "stl.h" -#include "stat_com.h" -#include "stl.h" #include +#include #include -#include "rom_com_fx.h" -#include "prot_fx.h" -#include "basop_util.h" +#include "cnst.h" +#include "rom_com.h" +#include "prot.h" -#define HLM_MIN_NRG 32768.0f + + + +/** Inverse quantization for reflection coefficients. + * + * @param index input quantized values. + * @param parCoeff output reflection coefficients. + * @param order number of coefficients/values. + */ +static void Index2Parcor(int const index[], float parCoeff[], int order); /** Linear prediction analysis/synthesis filter definition. * @param order filter order. @@ -21,25 +27,17 @@ * @param x the current input value. * @return the output of the filter. */ -typedef Word32 (* TLinearPredictionFilter)(Word16 order, Word16 const parCoeff[], Word32 * state, Word32 x); - -/** Inverse quantization for reflection coefficients. - * - * @param index input quantized values. - * @param parCoeff output reflection coefficients. - * @param order number of coefficients/values. - */ -static void Index2Parcor(Word16 const index[], Word16 parCoeff[], Word16 order); +typedef float (* TLinearPredictionFilter)(int order, float const parCoeff[], float * state, float x); /** Linear prediction analysis filter. * See TLinearPredictionFilter for details. */ -static Word32 FIRLattice(Word16 order, const Word16 *parCoeff, Word32 *state, Word32 x); +static float FIRLattice(int order, const float *parCoeff, float *state, float x); /** Linear prediction synthesis filter. * See TLinearPredictionFilter for details. */ -static Word32 IIRLattice(Word16 order, const Word16 *parCoeff, Word32 *state, Word32 x); +static float IIRLattice(int order, const float *parCoeff, float *state, float x); /** TNS analysis/synthesis filter. * @param spectrum input spectrum values. @@ -51,105 +49,68 @@ static Word32 IIRLattice(Word16 order, const Word16 *parCoeff, Word32 *state, Wo * @param output filtered output spectrum values. Inplace operation is supported, so it can be equal to spectrum. */ -static void TnsFilter(Word32 const spectrum[], Word16 numOfLines, - Word16 const parCoeff[], Word16 order, - TLinearPredictionFilter filter, Word32 * state, - Word32 output[]); +static void TnsFilter(float const spectrum[], int numOfLines, + float const parCoeff[], int order, + TLinearPredictionFilter filter, float * state, + float output[]); -static void ITF_TnsFilter_fx( Word32 const spectrum[], - const Word16 numOfLines, - const Word16 A[], /* Q14 */ - const Word16 Q_A, - const Word16 order, - Word32 output[]); - -static void ITF_GetFilterParameters_fx(Word32 rxx[], - Word16 maxOrder, - Word16* A, /* Q14 */ - Word16* Q_A, - Word16* predictionGain); /********************************/ /* Interface functions */ /********************************/ -#define MAX_SUBDIVISIONS 3 - -Word16 InitTnsConfiguration( - Word32 nSampleRate, - Word16 frameLength, +TNS_ERROR InitTnsConfiguration( + int nSampleRate, + int frameLength, STnsConfig * pTnsConfig, - Word16 igfStopFreq, - Word32 bitrate + int igfStopFreq, + int bitrate ) { - Word16 iFilter = 0; - Word16 * startLineFilter; - Word32 L_tmp; - Word16 s1; - Word16 s2; - - - move16(); - startLineFilter = &pTnsConfig->iFilterBorders[1]; + int iFilter = 0; + short int * startLineFilter = &pTnsConfig->iFilterBorders[1]; /* Sanity checks */ assert((nSampleRate > 0) && (frameLength > 0) && (pTnsConfig != NULL)); if ((nSampleRate <= 0) || (frameLength <= 0) || (pTnsConfig == NULL)) - { return TNS_FATAL_ERROR; - } - - + /* WMOPS: All initializations are either for safety or static (tables) and thus not to be counted */ /* Initialize TNS filter flag and maximum order */ - move16(); pTnsConfig->maxOrder = TNS_MAX_FILTER_ORDER; - - IF (L_sub(bitrate, ACELP_32k) <= 0) + if (bitrate <= ACELP_32k) { - move16(); - move16(); pTnsConfig->nMaxFilters = sizeof(tnsParametersIGF32kHz_LowBR)/sizeof(tnsParametersIGF32kHz_LowBR[0]); + pTnsConfig->pTnsParameters = tnsParametersIGF32kHz_LowBR; } - ELSE + else { - test(); - IF (L_sub(nSampleRate,32000) > 0 && L_sub(nSampleRate, L_mult0(100, frameLength)) == 0) + if (nSampleRate > 32000 && nSampleRate == 100 * frameLength) { - move16(); pTnsConfig->nMaxFilters = sizeof(tnsParameters48kHz_grouped)/sizeof(tnsParameters48kHz_grouped[0]); - move16(); pTnsConfig->pTnsParameters = tnsParameters48kHz_grouped; } - ELSE - IF ( L_sub(nSampleRate,16000) > 0 ) + else if (nSampleRate > 16000) { - move16(); pTnsConfig->nMaxFilters = sizeof(tnsParameters32kHz)/sizeof(tnsParameters32kHz[0]); - - move16(); - pTnsConfig->pTnsParameters = tnsParameters32kHz; - - if ( L_sub(nSampleRate, L_mult0(100, frameLength)) == 0 ) /* sub-frame length is <= 10 ms */ + if (nSampleRate == 100 * frameLength) /* sub-frame length is <= 10 ms */ { - move16(); pTnsConfig->pTnsParameters = tnsParameters32kHz_grouped; } - } - ELSE - { - IF ( L_sub(nSampleRate, L_mult0(100, frameLength)) == 0 ) /* sub-frame length is <= 10 ms */ + else + { + pTnsConfig->pTnsParameters = tnsParameters32kHz; + } + } + else + { + if (nSampleRate == 100 * frameLength) /* sub-frame length is <= 10 ms */ { - move16(); - move16(); pTnsConfig->nMaxFilters = sizeof(tnsParameters16kHz_grouped)/sizeof(tnsParameters16kHz_grouped[0]); pTnsConfig->pTnsParameters = tnsParameters16kHz_grouped; } - ELSE + else { - move16(); - move16(); pTnsConfig->nMaxFilters = sizeof(tnsParameters16kHz)/sizeof(tnsParameters16kHz[0]); pTnsConfig->pTnsParameters = tnsParameters16kHz; } @@ -159,70 +120,43 @@ Word16 InitTnsConfiguration( assert(pTnsConfig->nMaxFilters <= TNS_MAX_NUM_OF_FILTERS); /* Set starting MDCT line for each filter based on the starting frequencies from the TNS table */ - - FOR (iFilter = 0; iFilter < pTnsConfig->nMaxFilters; iFilter++) + for (iFilter = 0; iFilter < pTnsConfig->nMaxFilters; iFilter++) { assert(pTnsConfig->pTnsParameters[iFilter].startLineFrequency < 0.5f*nSampleRate); - assert(nSampleRate <= 96000); - move16(); - startLineFilter[iFilter] = divide3232(L_mult0(frameLength, pTnsConfig->pTnsParameters[iFilter].startLineFrequency), L_shl(nSampleRate,14)); + startLineFilter[iFilter] = (frameLength * 2 * pTnsConfig->pTnsParameters[iFilter].startLineFrequency) / nSampleRate; } - - IF (igfStopFreq > 0) + if (igfStopFreq > 0) { - L_tmp = L_mult(frameLength, igfStopFreq); - s1 = sub(norm_l(L_tmp), 1); - s2 = norm_l(nSampleRate); - - move16(); - pTnsConfig->iFilterBorders[0] = shr( div_l( L_shl(L_tmp, s1), extract_h(L_shl(nSampleRate, s2)) ) , sub(WORD16_BITS-1, sub(s2, s1))); - + pTnsConfig->iFilterBorders[0] = (frameLength * 2 * igfStopFreq) / nSampleRate; } - ELSE + else { - move16(); pTnsConfig->iFilterBorders[0] = frameLength; } return TNS_NO_ERROR; } - -Word16 ApplyTnsFilter( +TNS_ERROR ApplyTnsFilter( STnsConfig const * pTnsConfig, STnsData const * pTnsData, - Word32 spectrum[], - Word8 fIsAnalysis) + float spectrum[], + int fIsAnalysis) { - Word16 result; TLinearPredictionFilter filter; - Word32 state[TNS_MAX_FILTER_ORDER]; - Word16 iFilter; - Word16 stopLine, startLine; - Word16 const * pBorders; - - - move16(); - filter = IIRLattice; - if (fIsAnalysis) - { - move16(); - filter = FIRLattice; - } - set32_fx(state, 0, TNS_MAX_FILTER_ORDER); - move16(); + float state[TNS_MAX_FILTER_ORDER]; + int iFilter; + int stopLine, startLine; + short int const * pBorders; + filter = fIsAnalysis ? FIRLattice : IIRLattice; + set_f(state, 0, TNS_MAX_FILTER_ORDER); pBorders = pTnsConfig->iFilterBorders; - - FOR (iFilter = pTnsConfig->nMaxFilters-1; iFilter >= 0; iFilter--) + for (iFilter = pTnsConfig->nMaxFilters-1; iFilter >= 0; iFilter--) { - Word16 parCoeff[TNS_MAX_FILTER_ORDER]; - STnsFilter const * pFilter; + float parCoeff[TNS_MAX_FILTER_ORDER]; + STnsFilter const * const pFilter = &pTnsData->filter[iFilter]; - - move16(); - move16(); - move16(); - pFilter = &pTnsData->filter[iFilter]; + set_f( parCoeff, 0, TNS_MAX_FILTER_ORDER ); /* WMOPS: Initialization for safety and thus not to be counted */ stopLine = pBorders[iFilter]; startLine = pBorders[iFilter+1]; @@ -234,492 +168,251 @@ Word16 ApplyTnsFilter( &spectrum[startLine]); } - - move16(); - result = TNS_NO_ERROR; - if (pTnsData->nFilters < 0) - { - move16(); - result = TNS_FATAL_ERROR; - } - - return result; + return (pTnsData->nFilters < 0) ? TNS_FATAL_ERROR : TNS_NO_ERROR; } -TNS_ERROR ITF_Apply_fx(Word32 spectrum[], - Word16 startLine, - Word16 stopLine, - const Word16* A, - Word16 Q_A, - Word16 order - ) -{ - - ITF_TnsFilter_fx(&spectrum[startLine], - (Word16)(stopLine-startLine), - A, - Q_A, - (Word16)order, - &spectrum[startLine]); - - return TNS_NO_ERROR; -} - -Word16 ITF_Detect_fx(Word32 const pSpectrum[], - Word16 startLine, - Word16 stopLine, - Word16 maxOrder, - Word16* A, - Word16* Q_A, - Word16* predictionGain, - Word16* curr_order, - Word16 Q ) -{ - Word16 const idx0 = startLine; - Word16 const idx1 = stopLine; - Word16 spectrumLength; - Word16 const nSubdivisions = MAX_SUBDIVISIONS; - Word16 iSubdivisions; - Word16 iStartLine; - Word16 iEndLine; - Word16 facs[MAX_SUBDIVISIONS]; - Word16 facs_e[MAX_SUBDIVISIONS]; /* exponents of facs[][] */ - Word16 shifts[MAX_SUBDIVISIONS]; - Word16 tmp, headroom, shift; - Word32 rxx[ITF_MAX_FILTER_ORDER+1]; - Word16 lag; - Word32 L_tmp, tmp32; - Word16 tmpbuf[325]; - Word16 n, i; - - move16(); - move16(); - move16(); - - if (maxOrder <= 0) - { - return 0; - } - - /* Calculate norms for each spectrum part */ - FOR (iSubdivisions = 0; iSubdivisions < nSubdivisions; iSubdivisions++) - { - assert((nSubdivisions == 1) || (nSubdivisions == 3)); - - tmp = sub(idx1, idx0); - iStartLine = imult1616(tmp, iSubdivisions); - iEndLine = add(iStartLine, tmp); - - if (sub(nSubdivisions, 3) == 0) iStartLine = mult(iStartLine, 0x2AAB); - iStartLine = add(iStartLine, idx0); - - if (sub(nSubdivisions, 3) == 0) iEndLine = mult(iEndLine, 0x2AAB); - iEndLine = add(iEndLine, idx0); - headroom = getScaleFactor32(pSpectrum+iStartLine-IGF_START_MN, sub(iEndLine, iStartLine)); - /* Calculate norm of spectrum band */ - L_tmp = Norm32Norm(pSpectrum+iStartLine-IGF_START_MN, headroom, sub(iEndLine, iStartLine), &shift); - - /* Check threshold HLM_MIN_NRG */ - BASOP_SATURATE_WARNING_OFF; - tmp32 = L_sub(L_shl(L_tmp, sub(shift, 24-Q)), 4194304l/*HLM_MIN_NRG Q7*/); - BASOP_SATURATE_WARNING_ON; - - /* get pre-shift for autocorrelation */ - tmp = sub(shift, norm_l(L_tmp)); /* exponent for normalized L_tmp */ - tmp = shr(sub(1, tmp), 1); /* pre-shift to apply before autocorrelation */ - shifts[iSubdivisions] = s_min(tmp, headroom); - move16(); - - /* calc normalization factor */ - facs[iSubdivisions] = 0; - move16(); - facs_e[iSubdivisions] = 0; - move16(); - - if (tmp32 > 0) - { - facs[iSubdivisions] = 0x7FFF; - move16(); /* normalization not needed for one subdivision */ - } - - test(); - IF ((tmp32 > 0) && (sub(nSubdivisions, 1) > 0)) - { - move16(); - facs_e[iSubdivisions] = shl(sub(tmp, shifts[iSubdivisions]), 1); - - tmp = sub(1, shl(tmp, 1)); /* exponent of autocorrelation */ - L_tmp = L_shl(L_tmp, sub(shift, tmp)); /* shift L_tmp to that exponent */ - - /* calc factor (with 2 bits headroom for sum of 3 subdivisions) */ - facs[iSubdivisions] = div_s(0x2000, round_fx(L_tmp)); /* L_tmp is >= 0x2000000 */ move16(); - } - - } - - /* Calculate normalized autocorrelation for spectrum subdivision and get filter parameters based on it */ -#define RXX_E (3) - { - set32_fx(rxx, 0, ITF_MAX_FILTER_ORDER+1); - - spectrumLength = sub(idx1, idx0); - - FOR (iSubdivisions = 0; iSubdivisions < nSubdivisions; iSubdivisions++) - { - IF ( facs[iSubdivisions] == 0 ) - { - BREAK; - } - - - assert((nSubdivisions == 1) || (nSubdivisions == 3)); - - iStartLine = imult1616(spectrumLength, iSubdivisions); - iEndLine = add(iStartLine, spectrumLength); - - if (sub(nSubdivisions, 3) == 0) iStartLine = mult(iStartLine, 0x2AAB); - iStartLine = add(iStartLine, idx0); - - if (sub(nSubdivisions, 3) == 0) iEndLine = mult(iEndLine, 0x2AAB); - iEndLine = add(iEndLine, idx0); - - - move16(); - shift = shifts[iSubdivisions]; - - n = sub(iEndLine, iStartLine); - assert(n < (Word16)(sizeof(tmpbuf)/sizeof(Word16))); - FOR (i = 0; i < n; i++) - { - tmpbuf[i] = round_fx(L_shl(pSpectrum[iStartLine+i-IGF_START_MN], shift)); - } - - FOR (lag = 0; lag <= maxOrder; lag++) - { - n = sub(sub(iEndLine,lag), iStartLine); - - L_tmp = L_deposit_l(0); - FOR (i = 0; i < n; i++) - { - L_tmp = L_mac0(L_tmp, tmpbuf[i], tmpbuf[i+lag]); - } - - L_tmp = Mpy_32_16_1(L_tmp, facs[iSubdivisions]); - L_tmp = L_shl(L_tmp, facs_e[iSubdivisions]); - - rxx[lag] = L_add(rxx[lag], L_tmp); - move32(); - } - - } - - IF ( sub(iSubdivisions,nSubdivisions) == 0 ) /* meaning there is no subdivision with low energy */ - { - /* Limit the maximum order to spectrum length/4 */ - ITF_GetFilterParameters_fx(rxx, s_min (maxOrder, shr(spectrumLength,2)), A, Q_A, predictionGain); - - *curr_order = maxOrder; - } - - } - - return 1; -} - - -/* Helper functions for Hufmann table coding */ +/*********************************************************************************************/ +/* Definitions of functions used in the mapping between TNS parameters and a bitstream. */ +/*********************************************************************************************/ +/* Helper functions for hufmann table coding */ /** Get number of bits from a Huffman table. * The table must be sorted by values. */ -static Word16 GetBitsFromTable(const Word16 value, const Coding codes[], const Word16 nSize) +static int GetBitsFromTable(int value, const Coding codes[], int nSize) { (void)nSize; assert((value >= 0) && (value < nSize) && (nSize >= 0) && (nSize <= 256)); - - move16(); - cast16(); - return (Word16)codes[value].nBits; + return codes[value].nBits; } /** Get the code for a value from a Huffman table. * The table must be sorted by values. */ -static Word16 EncodeUsingTable(const Word16 value, const Coding codes[], const Word16 nSize) +static int EncodeUsingTable(int value, const Coding codes[], int nSize) { (void)nSize; assert((value >= 0) && (value < nSize) && (nSize >= 0) && (nSize <= 256)); - - move16(); return codes[value].code; } - /** Decode a value from a bitstream using a Huffman table. */ -static Word16 DecodeUsingTable(Decoder_State_fx *st, Word16 * pValue, const Coding codes[], const Word16 nSize) +static int DecodeUsingTable(Decoder_State *st, int * pValue, const Coding codes[], int nSize) { - Word16 code = 0; - Word16 nBits = 0; - Word16 valueIndex; + unsigned short int code = 0; + unsigned char nBits = 0; + unsigned char valueIndex = nSize; assert((nSize >= 0) && (nSize <= 256)); - - - move16(); - valueIndex = nSize; - - - WHILE (valueIndex == nSize) + /* Variable initialization. All are required! */ + while (valueIndex == nSize) { - code = add(shl(code,1), get_next_indice_fx(st, 1)); - nBits = add(nBits,1); + code = (code << 1) + (unsigned short int)get_next_indice(st, 1); + ++nBits; if (nBits > nSize || nBits > 16) { st->BER_detect = 1; *pValue = 0; - return -1; } - - FOR (valueIndex = 0; valueIndex < nSize; valueIndex++) + for (valueIndex = 0; valueIndex < nSize; valueIndex++) { - - IF ( s_and(sub(codes[valueIndex].nBits,nBits) == 0, sub(codes[valueIndex].code,code) == 0) ) + if (codes[valueIndex].nBits == nBits) { - BREAK; + if (codes[valueIndex].code == code) + break; } } - + /* Loop condition */ } + if (valueIndex < nSize) { - *pValue = (Word16)codes[valueIndex].value; + *pValue = codes[valueIndex].value; } else { st->BER_detect = 1; *pValue = 0; - return -1; } return nBits; } - /* TNS filter coefficients */ -void const * GetTnsFilterCoeff(void const * p, Word16 index, Word16 * pValue) +void const * GetTnsFilterCoeff(void const * p, int index, int * pValue) { - *pValue = ((Word16 const *)p)[index] + INDEX_SHIFT; + *pValue = ((int const *)p)[index] + INDEX_SHIFT; return NULL; } -void * SetTnsFilterCoeff(void * p, Word16 index, Word16 value) +void * SetTnsFilterCoeff(void * p, int index, int value) { - ((Word16 *)p)[index] = sub(value, INDEX_SHIFT); + ((int *)p)[index] = value - INDEX_SHIFT; return NULL; } - -Word16 GetSWBTCX20TnsFilterCoeffBits(Word16 value, Word16 index) +int GetSWBTCX20TnsFilterCoeffBits(int value, int index) { assert((index >= 0) && (index < nTnsCoeffTables)); - return GetBitsFromTable(value, codesTnsCoeffSWBTCX20[index], nTnsCoeffCodes); } -Word16 EncodeSWBTCX20TnsFilterCoeff(Word16 value, Word16 index) +int EncodeSWBTCX20TnsFilterCoeff(int value, int index) { assert((index >= 0) && (index < nTnsCoeffTables)); - return EncodeUsingTable(value, codesTnsCoeffSWBTCX20[index], nTnsCoeffCodes); } -Word16 DecodeSWBTCX20TnsFilterCoeff(Decoder_State_fx *st, Word16 index, Word16 * pValue) +int DecodeSWBTCX20TnsFilterCoeff(Decoder_State *st, int index, int * pValue) { assert((index >= 0) && (index < nTnsCoeffTables)); - return DecodeUsingTable(st, pValue, codesTnsCoeffSWBTCX20[index], nTnsCoeffCodes); } -Word16 GetSWBTCX10TnsFilterCoeffBits(Word16 value, Word16 index) +int GetSWBTCX10TnsFilterCoeffBits(int value, int index) { assert((index >= 0) && (index < nTnsCoeffTables)); - return GetBitsFromTable(value, codesTnsCoeffSWBTCX10[index], nTnsCoeffCodes); } -Word16 EncodeSWBTCX10TnsFilterCoeff(Word16 value, Word16 index) +int EncodeSWBTCX10TnsFilterCoeff(int value, int index) { assert((index >= 0) && (index < nTnsCoeffTables)); - return EncodeUsingTable(value, codesTnsCoeffSWBTCX10[index], nTnsCoeffCodes); } -Word16 DecodeSWBTCX10TnsFilterCoeff(Decoder_State_fx *st, Word16 index, Word16 * pValue) +int DecodeSWBTCX10TnsFilterCoeff(Decoder_State *st, int index, int * pValue) { assert((index >= 0) && (index < nTnsCoeffTables)); - return DecodeUsingTable(st, pValue, codesTnsCoeffSWBTCX10[index], nTnsCoeffCodes); } -Word16 GetWBTCX20TnsFilterCoeffBits(Word16 value, Word16 index) +int GetWBTCX20TnsFilterCoeffBits(int value, int index) { assert((index >= 0) && (index < nTnsCoeffTables)); - return GetBitsFromTable(value, codesTnsCoeffWBTCX20[index], nTnsCoeffCodes); } -Word16 EncodeWBTCX20TnsFilterCoeff(Word16 value, Word16 index) +int EncodeWBTCX20TnsFilterCoeff(int value, int index) { assert((index >= 0) && (index < nTnsCoeffTables)); - return EncodeUsingTable(value, codesTnsCoeffWBTCX20[index], nTnsCoeffCodes); } -Word16 DecodeWBTCX20TnsFilterCoeff(Decoder_State_fx *st, Word16 index, Word16 * pValue) +int DecodeWBTCX20TnsFilterCoeff(Decoder_State *st, int index, int * pValue) { assert((index >= 0) && (index < nTnsCoeffTables)); - return DecodeUsingTable(st, pValue, codesTnsCoeffWBTCX20[index], nTnsCoeffCodes); } - /* TNS filter order */ -void const * GetTnsFilterOrder(void const * p, Word16 index, Word16 * pValue) +void const * GetTnsFilterOrder(void const * p, int index, int * pValue) { - move16(); *pValue = ((STnsFilter const *)p)[index].order; - - move16(); return ((STnsFilter const *)p)[index].coefIndex; } -void * SetTnsFilterOrder(void * p, Word16 index, Word16 value) +void * SetTnsFilterOrder(void * p, int index, int value) { - move16(); ((STnsFilter *)p)[index].order = value; - - move16(); return ((STnsFilter *)p)[index].coefIndex; } -Word16 GetTnsFilterOrderBitsSWBTCX20(Word16 value, Word16 index) +int GetTnsFilterOrderBitsSWBTCX20(int value, int index) { (void)index; - return GetBitsFromTable(value-1, codesTnsOrderTCX20, nTnsOrderCodes); } -Word16 EncodeTnsFilterOrderSWBTCX20(Word16 value, Word16 index) +int EncodeTnsFilterOrderSWBTCX20(int value, int index) { (void)index; - return EncodeUsingTable(value-1, codesTnsOrderTCX20, nTnsOrderCodes); } -Word16 DecodeTnsFilterOrderSWBTCX20(Decoder_State_fx *st, Word16 index, Word16 * pValue) +int DecodeTnsFilterOrderSWBTCX20(Decoder_State *st, int index, int * pValue) { (void)index; - return DecodeUsingTable(st, pValue, codesTnsOrderTCX20, nTnsOrderCodes); } -Word16 GetTnsFilterOrderBitsSWBTCX10(Word16 value, Word16 index) +int GetTnsFilterOrderBitsSWBTCX10(int value, int index) { (void)index; - return GetBitsFromTable(value-1, codesTnsOrderTCX10, nTnsOrderCodes); } -Word16 EncodeTnsFilterOrderSWBTCX10(Word16 value, Word16 index) +int EncodeTnsFilterOrderSWBTCX10(int value, int index) { (void)index; - return EncodeUsingTable(value-1, codesTnsOrderTCX10, nTnsOrderCodes); } -Word16 DecodeTnsFilterOrderSWBTCX10(Decoder_State_fx *st, Word16 index, Word16 * pValue) +int DecodeTnsFilterOrderSWBTCX10(Decoder_State *st, int index, int * pValue) { (void)index; - return DecodeUsingTable(st, pValue, codesTnsOrderTCX10, nTnsOrderCodes); } -Word16 GetTnsFilterOrderBits(Word16 value, Word16 index) +int GetTnsFilterOrderBits(int value, int index) { (void)index; - return GetBitsFromTable(value-1, codesTnsOrder, nTnsOrderCodes); } -Word16 EncodeTnsFilterOrder(Word16 value, Word16 index) +int EncodeTnsFilterOrder(int value, int index) { (void)index; - return EncodeUsingTable(value-1, codesTnsOrder, nTnsOrderCodes); } -Word16 DecodeTnsFilterOrder(Decoder_State_fx *st, Word16 index, Word16 * pValue) +int DecodeTnsFilterOrder(Decoder_State *st, int index, int * pValue) { (void)index; - return DecodeUsingTable(st, pValue, codesTnsOrder, nTnsOrderCodes); } /* Number of TNS filters */ -void const * GetNumOfTnsFilters(void const * p, Word16 index, Word16 * pValue) +void const * GetNumOfTnsFilters(void const * p, int index, int * pValue) { *pValue = ((STnsData const *)p)[index].nFilters; - return ((STnsData const *)p)[index].filter; } -void * SetNumOfTnsFilters(void * p, Word16 index, Word16 value) +void * SetNumOfTnsFilters(void * p, int index, int value) { ((STnsData *)p)[index].nFilters = value; - return ((STnsData *)p)[index].filter; } /* TNS enabled/disabled flag */ -void const * GetTnsEnabled(void const * p, Word16 index, Word16 * pValue) +void const * GetTnsEnabled(void const * p, int index, int * pValue) { - move16(); - *pValue = 0; - if (((STnsData const *)p)[index].nFilters > 0) - { - move16(); - *pValue = 1; - } + *pValue = ((STnsData const *)p)[index].nFilters > 0 ? 1 : 0; return NULL; } -void * SetTnsEnabled(void * p, Word16 index, Word16 value) +void * SetTnsEnabled(void * p, int index, int value) { (void)p,(void)index,(void)value; return NULL; } -void const * GetTnsEnabledSingleFilter(void const * p, Word16 index, Word16 * pValue) +void const * GetTnsEnabledSingleFilter(void const * p, int index, int * pValue) { - move16(); - *pValue = 0; - if (((STnsData const *)p)[index].nFilters > 0) - { - move16(); - *pValue = 1; - } + *pValue = ((STnsData const *)p)[index].nFilters > 0 ? 1 : 0; return ((STnsData const *)p)[index].filter; } -void * SetTnsEnabledSingleFilter(void * p, Word16 index, Word16 value) +void * SetTnsEnabledSingleFilter(void * p, int index, int value) { ((STnsData *)p)[index].nFilters = value; return ((STnsData *)p)[index].filter; @@ -731,16 +424,14 @@ void * SetTnsEnabledSingleFilter(void * p, Word16 index, Word16 value) void ResetTnsData(STnsData * pTnsData) { - Word16 iFilter; - + unsigned int iFilter; pTnsData->nFilters = 0; - - FOR (iFilter = 0; iFilter < (Word16) (sizeof(pTnsData->filter)/sizeof(pTnsData->filter[0])); iFilter++) + for (iFilter = 0; iFilter < sizeof(pTnsData->filter)/sizeof(pTnsData->filter[0]); iFilter++) { STnsFilter * const pTnsFilter = &pTnsData->filter[iFilter]; pTnsFilter->spectrumLength = 0; - pTnsFilter->predictionGain = 128/*1.0f Q7*/; + pTnsFilter->predictionGain = 1.0f; pTnsFilter->avgSqrCoef = 0; ClearTnsFilterCoefficients(pTnsFilter); } @@ -749,227 +440,296 @@ void ResetTnsData(STnsData * pTnsData) void ClearTnsFilterCoefficients(STnsFilter * pTnsFilter) { - move16(); pTnsFilter->order = 0; - assert(TNS_MAX_FILTER_ORDER == 8); - move16(); - move16(); - move16(); - move16(); - move16(); - move16(); - move16(); - move16(); - pTnsFilter->coefIndex[0] = 0; - pTnsFilter->coefIndex[1] = 0; - pTnsFilter->coefIndex[2] = 0; - pTnsFilter->coefIndex[3] = 0; - pTnsFilter->coefIndex[4] = 0; - pTnsFilter->coefIndex[5] = 0; - pTnsFilter->coefIndex[6] = 0; - pTnsFilter->coefIndex[7] = 0; + set_i(pTnsFilter->coefIndex, 0, (int)sizeof(pTnsFilter->coefIndex)/(int)sizeof(pTnsFilter->coefIndex[0])); } -static void Index2Parcor(const Word16 index[], Word16 parCoeff[], Word16 order) +static void Index2Parcor(const int index[], float parCoeff[], int order) { - Word16 const * values; - Word16 i; - - move16(); - values = tnsCoeff4; - - FOR (i = 0; i < order; i++) + float const * values = tnsCoeff4; + int i; + for (i = 0; i < order; i++) { - move16(); - parCoeff[i] = values[add(index[i], INDEX_SHIFT)]; + parCoeff[i] = values[index[i] + INDEX_SHIFT]; } } - - -static Word32 FIRLattice(Word16 order, const Word16 *parCoeff /*Q15*/, Word32 *state, Word32 x /* Q0 */) +static float FIRLattice(int order, const float *parCoeff, float *state, float x) { - Word16 i; - Word32 tmpSave, tmp; - - - tmpSave = L_add(x,0); - FOR (i = 0; i < order-1; i++) + int i; + float tmpSave; + tmpSave = x; + for (i = 0; i < order-1; i++) { - tmp = L_add(state[i], Mpy_32_16_1(x, parCoeff[i])); - x = L_add(x, Mpy_32_16_1(state[i], parCoeff[i])); /* exponent: 31+0 */ + float const tmp = parCoeff[i] * x + state[i]; + /* Variable initialization */ + x += parCoeff[i] * state[i]; state[i] = tmpSave; - move32(); - tmpSave = L_add(tmp,0); + tmpSave = tmp; } /* last stage: only need half operations */ - x = L_add(x, Mpy_32_16_1(state[order-1], parCoeff[order-1])); + x += parCoeff[order-1] * state[order-1]; state[order-1] = tmpSave; - move32(); - return x; } -static Word32 IIRLattice(Word16 order, const Word16 *parCoeff, Word32 *state, Word32 x) +static float IIRLattice(int order, const float *parCoeff, float *state, float x) { - Word16 i; - - + int i; /* first stage: no need to calculate state[order-1] */ - x = L_sub(x, Mpy_32_16_1(state[order-1], parCoeff[order-1])); - - FOR (i = order-2; i >= 0; i--) + x -= parCoeff[order-1] * state[order-1]; + for (i = order-2; i >= 0; i--) { - x = L_sub(x, Mpy_32_16_1(state[i], parCoeff[i])); - state[i+1] = L_add(state[i], Mpy_32_16_1(x, parCoeff[i])); - move32(); + x -= parCoeff[i] * state[i]; + state[i+1] = parCoeff[i] * x + state[i]; } - move32(); state[0] = x; return x; } -static void TnsFilter(Word32 const spectrum[], Word16 numOfLines, - Word16 const parCoeff[], Word16 order, - TLinearPredictionFilter filter, Word32 * state, - Word32 output[]) +static void TnsFilter(float const spectrum[], int numOfLines, + float const parCoeff[], int order, + TLinearPredictionFilter filter, float * state, + float output[]) { - Word16 j; - + int j; assert((order >= 0) && (order <= TNS_MAX_FILTER_ORDER)); assert((numOfLines > 0) || ((numOfLines == 0) && (order == 0))); - - IF (order == 0) + if (order == 0) { - - test(); - IF ( s_and((spectrum != output), numOfLines > 0) ) + if ((spectrum != output) && (numOfLines > 0)) { - Copy32(spectrum, output, numOfLines); + mvr2r(spectrum, output, numOfLines); } } - ELSE + else { { - - FOR (j = 0; j < numOfLines; j++) + for (j = 0; j < numOfLines; j++) { - move32(); output[j] = filter(order, parCoeff, state, spectrum[j]); } } } } -static void ITF_TnsFilter_fx( Word32 const spectrum[], - const Word16 numOfLines, - const Word16 A[], /* ifdef FIX_ITF_OVERFLOW Q_A else Q14 */ - const Word16 Q_A, - const Word16 order, - Word32 output[]) + +static void ITF_TnsFilter(float const spectrum[], int numOfLines, + const float A[], int order, + float output[]) { - Word16 i, j; - Word32 buf[ITF_MAX_FILTER_ORDER + N_MAX]; - Word32* p; - Word16 shift; + int j; assert((order >= 0) && (order <= ITF_MAX_FILTER_ORDER)); assert((numOfLines > 0) || ((numOfLines == 0) && (order == 0))); - - IF (order == 0) + if (order == 0) { - - test(); - IF ( s_and((spectrum != output), numOfLines > 0) ) + if ((spectrum != output) && (numOfLines > 0)) { - Copy32(spectrum, output, numOfLines); + mvr2r(spectrum, output, numOfLines); } } - ELSE + else { - shift = sub(15, Q_A); - - p = buf + ITF_MAX_FILTER_ORDER; - set32_fx(buf, 0, ITF_MAX_FILTER_ORDER); - Copy32(spectrum, p, numOfLines); - FOR (j = 0; j < numOfLines; j++) + int i; + float buf[ITF_MAX_FILTER_ORDER + N_MAX]; + float* p = buf + ITF_MAX_FILTER_ORDER; + set_f(buf, 0, ITF_MAX_FILTER_ORDER); + mvr2r(spectrum, p, numOfLines); + for (j = 0; j < numOfLines; j++, p++) { - Word32 L_tmp; - - L_tmp = L_add(p[0], 0); - FOR (i = 1; i < order; i++) + output[j] = p[0]; + for (i = 1; i < order; i++) { - L_tmp = L_add(L_tmp, L_shl(Mpy_32_16_1(p[-i], A[i]), shift)); + output[j] += A[i] * p[-i]; } - output[j] = L_tmp; - move32(); - ++p; } } - } -static void ITF_GetFilterParameters_fx(Word32 rxx[], - Word16 maxOrder, - Word16* A, /* ifdef FIX_ITF_OVERFLOW Q_A else Q14 */ - Word16* Q_A, - Word16* predictionGain) -{ - Word16 i, j, i_2, tmp; - Word16 parCoeff[ITF_MAX_FILTER_ORDER]; - Word32 epsP[ITF_MAX_FILTER_ORDER+1], L_tmp; - /* compute filter in ParCor form with LeRoux-Gueguen algorithm */ - L_tmp = E_LPC_schur(rxx, parCoeff, epsP, maxOrder); - BASOP_SATURATE_WARNING_OFF /* Allow saturation, this value is compared against a threshold. */ - *predictionGain = divide3232(L_shr(epsP[0], PRED_GAIN_E), L_tmp); - BASOP_SATURATE_WARNING_ON + +/*********************************************************************************************/ +/* Definitions of functions used in the mapping between TNS parameters and a bitstream. */ +/*********************************************************************************************/ + +/* Helper functions for hufmann table coding */ + +/********************************/ +/* Private functions */ +/********************************/ + +/** Autocorrelation to parcor coefficients. + * Conversion of autocorrelation to parcor/reflection coefficients. + * @param input Autocorrelation function/coefficients. + * @param parCoeff output filter (PARCOR) coefficients. + * @param order filter order. + * @return prediction gain. + */ +static float ITF_AutoToLPcoef(const float input[], float a[], int order) +{ + int i, j; + float tmp, tmp2; + float workBuffer[2*ITF_MAX_FILTER_ORDER]; + float parCoeff[ITF_MAX_FILTER_ORDER]; + float * const pWorkBuffer = &workBuffer[order]; /* temp pointer */ /* WMOPS: No need for counting as it can be realized as a separate buffer */ + + for(i=0; i Q14 */ - FOR (i=0; i HLM_MIN_NRG); iSubdivisions++) + { + float const fac = 1.0f/norms[iSubdivisions]; + int const iStartLine = idx0 + spectrumLength*iSubdivisions/nSubdivisions; + int const iEndLine = idx0 + spectrumLength*(iSubdivisions+1)/nSubdivisions; + float const * pWindow = tnsAcfWindow; + float const * pEndWindowCoeff = &tnsAcfWindow[sizeof(tnsAcfWindow)/sizeof(tnsAcfWindow[0])]; /* WMOPS: Not counted as it is used only in the assertion */ + int lag; + (void)pEndWindowCoeff; + /* For additional loop condition */ + /* Variable initialization */ + for (lag = 1; lag <= maxOrder; lag++) + { + rxx[lag] += fac * (*pWindow) * Autocorrelation(pSpectrum+iStartLine-IGF_START_MN, iEndLine-iStartLine, lag); + pWindow++; + } + } + *predictionGain = 0; + if (iSubdivisions == nSubdivisions) /* meaning there is no subdivision with low energy */ + { + rxx[0] = (float)nSubdivisions; + + /* Limit the maximum order to spectrum length/4 */ + *predictionGain = ITF_AutoToLPcoef(rxx, A, min(maxOrder, spectrumLength/4) ); + + *curr_order = maxOrder; + } + } + + return 1; } diff --git a/src/libs/libevs/lib_com/tools.cpp b/src/libs/libevs/lib_com/tools.cpp new file mode 100644 index 00000000..3d1a9702 --- /dev/null +++ b/src/libs/libevs/lib_com/tools.cpp @@ -0,0 +1,1458 @@ +/*==================================================================================== + EVS Codec 3GPP TS26.443 Nov 13, 2018. Version 12.11.0 / 13.7.0 / 14.3.0 / 15.1.0 + ====================================================================================*/ + +#include +#include +#include +#include +#include +#include +#include "options.h" +#include "prot.h" + + +/*------------------------------------------------------------------* + * own_random() + * + * Random generator + *------------------------------------------------------------------*/ + +short own_random( /* o : output random value */ + short *seed /* i/o: random seed */ +) +{ + *seed = (short) (*seed * 31821L + 13849L); + + return(*seed); +} + +/*--------------------------------------------------------------------- + * sign() + * + *---------------------------------------------------------------------*/ + +float sign( /* o : sign of x (+1/-1) */ + const float x /* i : input value of x */ +) +{ + if (x < 0.0f) + { + return -1.0f; + } + else + { + return 1.0f; + } +} + +/*--------------------------------------------------------------------- + * log2_f() + * + *---------------------------------------------------------------------*/ + +float log2_f( /* o : logarithm2 of x */ + const float x /* i : input value of x */ +) +{ + return (float)(log(x)/log(2.0f)); +} + +short norm_ul( unsigned int UL_var1) +{ + short var_out; + + if (UL_var1 == 0) + { + var_out = 0; + } + else + { + for (var_out = 0; UL_var1 < (unsigned int) 0x80000000U; var_out++) + { + UL_var1 <<= 1; + } + } + BASOP_CHECK(); + return (var_out); +} + + + + + +/*--------------------------------------------------------------------- + * sum_s() + * sum_f() + * + *---------------------------------------------------------------------*/ + +short sum_s( /* o : sum of all vector elements */ + const short *vec, /* i : input vector */ + const short lvec /* i : length of input vector */ +) +{ + short i; + short tmp; + + tmp = 0; + for( i=0; i= 0; i--) + { + y[i] = x[i]; + } + } + + return; +} + +void mvs2s( + const short x[], /* i : input vector */ + short y[], /* o : output vector */ + const short n /* i : vector size */ +) +{ + short i; + + if ( n <= 0 ) + { + /* cannot transfer vectors with size 0 */ + return; + } + + if (y < x) + { + for (i = 0; i < n; i++) + { + y[i] = x[i]; + } + } + else + { + for (i = n-1; i >= 0; i--) + { + y[i] = x[i]; + } + } + + return; +} + +unsigned int mvr2s( + const float x[], /* i : input vector */ + short y[], /* o : output vector */ + const short n /* i : vector size */ +) +{ + short i; + float temp; + unsigned int noClipping = 0; + + if ( n <= 0 ) + { + /* cannot transfer vectors with size 0 */ + return 0; + } + + if ((void*)y < (const void*)x) + { + for (i = 0; i < n; i++) + { + temp = x[i]; + temp = (float)floor(temp + 0.5f); + + if (temp > 32767.0f ) + { + temp = 32767.0f; + noClipping++; + } + else if (temp < -32768.0f ) + { + temp = -32768.0f; + noClipping++; + } + + y[i] = (short)temp; + } + } + else + { + for (i = n-1; i >= 0; i--) + { + temp = x[i]; + temp = (float)floor(temp + 0.5f); + + if (temp > 32767.0f ) + { + temp = 32767.0f; + noClipping++; + } + else if (temp < -32768.0f ) + { + temp = -32768.0f; + noClipping++; + } + + y[i] = (short)temp; + } + } + + return noClipping; +} + +void mvs2r( + const short x[], /* i : input vector */ + float y[], /* o : output vector */ + const short n /* i : vector size */ +) +{ + short i; + + if ( n <= 0 ) + { + /* cannot transfer vectors with size 0 */ + return; + } + + if ((void*)y < (const void*)x) + { + for (i = 0; i < n; i++) + { + y[i] = (float)x[i]; + } + } + else + { + for (i = n-1; i >= 0; i--) + { + y[i] = (float)x[i]; + } + } + + return; +} + + +void mvi2i( + const int x[], /* i : input vector */ + int y[], /* o : output vector */ + const int n /* i : vector size */ +) +{ + int i; + + if ( n <= 0 ) + { + /* no need to transfer vectors with size 0 */ + return; + } + + if (y < x) + { + for (i = 0; i < n; i++) + { + y[i] = x[i]; + } + } + else + { + for (i = n-1; i >= 0; i--) + { + y[i] = x[i]; + } + } + + return; +} + +/*---------------------------------------------------------------------* + * maximum() + * + * Find index and value of the maximum in a vector + *---------------------------------------------------------------------*/ + +short maximum( /* o : index of the maximum value in the input vector */ + const float *vec, /* i : input vector */ + const short lvec, /* i : length of input vector */ + float *max /* o : maximum value in the input vector */ +) +{ + short j, ind; + float tmp; + + ind = 0; + tmp = vec[0]; + + for ( j=1; j tmp ) + { + ind = j; + tmp = vec[j]; + } + } + + if ( max != 0 ) + { + *max = tmp; + } + + return ind; +} + +/*---------------------------------------------------------------------* + * minimum() + * + * Find index of a minimum in a vector + *---------------------------------------------------------------------*/ + +short minimum( /* o : index of the minimum value in the input vector */ + const float *vec, /* i : input vector */ + const short lvec, /* i : length of input vector */ + float *min /* o : minimum value in the input vector */ +) +{ + short j, ind; + float tmp; + + ind = 0; + tmp = vec[0]; + + for ( j=1 ; j *ener_max ) + { + ind = j; + *ener_max = temp; + } + } + + return ind; +} + + +/*---------------------------------------------------------------------* + * mean() + * + * Find the mean of the vector + *---------------------------------------------------------------------*/ + +float mean( /* o : mean of vector */ + const float *vec, /* i : input vector */ + const short lvec /* i : length of input vector */ +) +{ + float tmp; + + tmp = sum_f( vec, lvec ) / (float)lvec; + + return tmp; +} + +/*---------------------------------------------------------------------* + * dotp() + * + * Dot product of vector x[] and vector y[] + *---------------------------------------------------------------------*/ + +float dotp( /* o : dot product of x[] and y[] */ + const float x[], /* i : vector x[] */ + const float y[], /* i : vector y[] */ + const short n /* i : vector length */ +) +{ + short i; + float suma; + + suma = x[0] * y[0]; + + for(i=1; i= 0; d--) + { + tmp = x[d] - cb[j++]; + dist += weights[d]*(tmp*tmp); + } + + if (dist < mindist) + { + mindist = dist; + idx = c; + } + } + + if (xq == 0) + { + return idx; + } + + j = idx*dim; + for ( d = k; d >= 0; d--) + { + xq[d] = cb[j++]; + } + } + else + { + for ( c = 0; c < cbsize; c++) + { + dist = 0.0f; + + for( d = 0; d < dim; d++) + { + tmp = x[d] - cb[j++]; + dist += weights[d]*(tmp*tmp); + } + + if (dist < mindist) + { + mindist = dist; + idx = c; + } + } + + if (xq == 0) + { + return idx; + } + + j = idx*dim; + for ( d = 0; d < dim; d++) + { + xq[d] = cb[j++]; + } + } + + if (x_mean != 0) + { + for( d = 0; d < dim; d++) + { + xq[d] += x_mean[d]; + } + } + + return idx; +} + + +/*----------------------------------------------------------------------------------* + * v_sort() + * + * Sorting of vectors. This is very fast with almost ordered vectors. + *----------------------------------------------------------------------------------*/ + +void v_sort( + float *r, /* i/o: Vector to be sorted in place */ + const short lo, /* i : Low limit of sorting range */ + const short up /* I : High limit of sorting range */ +) +{ + short i, j; + float tempr; + + for ( i=up-1; i>=lo; i-- ) + { + tempr = r[i]; + for ( j=i+1; j<=up && (tempr>r[j]); j++ ) + { + r[j-1] = r[j]; + } + + r[j-1] = tempr; + } + + return; +} + +/*---------------------------------------------------------------------* + * var() + * + * Calculate the variance of a vector + *---------------------------------------------------------------------*/ + +float var( /* o: variance of vector */ + const float *x, /* i: input vector */ + const int len /* i: length of inputvector */ +) +{ + float m; + float v; + short i; + + m = mean(x, (const short)len); + + v = 0.0f; + for (i = 0; i < len; i++) + { + v += (x[i] - m)*(x[i] - m); + } + v /= len; + + return v; +} + + +/*---------------------------------------------------------------------* + * std_dev() + * + * Calculate the standard deviation of a vector + *---------------------------------------------------------------------*/ + +float std_dev( /* o: standard deviation */ + const float *x, /* i: input vector */ + const int len /* i: length of the input vector */ +) +{ + short i; + float std; + + std = 1e-16f; + for( i = 0; i < len; i++) + { + std += x[i] * x[i]; + } + + std = (float)sqrt( std / len ); + + return std; +} + + + +/*---------------------------------------------------------------------* + * dot_product_mat() + * + * Calculates dot product of type x'*A*x, where x is column vector of size m, + * and A is square matrix of size m*m + *---------------------------------------------------------------------*/ + +float dot_product_mat( /* o : the dot product x'*A*x */ + const float *x, /* i : vector x */ + const float *A, /* i : matrix A */ + const short m /* i : vector & matrix size */ +) +{ + short i,j; + float suma, tmp_sum; + const float *pt_x, *pt_A; + + pt_A = A; + suma = 0; + + for(i=0; i 1.0) + { + mod_a /= 2.0; + shift_a--; + } + + while (mod_a < 0.5) + { + mod_a *= 2.0; + shift_a++; + } + + + shift_a &= 0xfffe; + mod_a = fleft_shift(a, (int) shift_a); + + approx = 0.27f + 1.0127f * mod_a - 0.2864f * mod_a * mod_a; + + approx = fright_shift(approx, (int) (shift_a >> 1)); + + return (approx); +} + +/*--------------------------------------------------------------------------------* + * root_a_over_b() + * + * Implements an approximation to sqrt(a/b) + * Firstly a & b are normalized to lie between 0.25 & 1.0 + * by shifting the inputs left or right by an even number + * of shifts. + * Even shifts represent powers of 4 which, after the sqrt, + * become powers of 2 and are easily dealt with. + * At the heart of the algorithm is an approximation of the + * curve sqrt(a/b) for 0.25 <= a <= 1.0 & 0.25 <= b <= 1.0. + * Given the value of b, the 2nd order coefficients p0, p1 + * & p2 can be determined so that... + * Sqrt(a/b) approx = p0 + p1 * a + p2 * a^2 + * where p0 approx = 0.7176 - 0.8815 * b + 0.4429 * b^2 + * p1 approx = 2.6908 - 3.3056 * b + 1.6608 * b^2 + * p2 approx = -0.7609 + 0.9346 * b - 0.4695 * b^2 + * + *---------------------------------------------------------------------------------*/ + +float root_a_over_b(float a, float b) +{ + short int shift_a, shift_b, shift; + float mod_a, mod_b; + float p2 = -0.7609f; + float p1 = 2.6908f; + float p0 = 0.7176f; + float b_sqr; + float approx; + + if ((a <= 0.0f) || (b <= 0.0f)) + { + return 0.0; + } + + a += 0x00000001; + b += 0x00000001; + + /* This next piece of code implements a "norm" function */ + /* and returns the shift needed to scale "a" to have a */ + /* 1 in the (MSB-1) position. This is equivalent to */ + /* giving a value between 0.5 & 1.0. */ + mod_a = a; + + shift_a = 0; + while (mod_a > 1.0) + { + mod_a /= 2.0; + shift_a--; + } + + while (mod_a < 0.5) + { + mod_a *= 2.0; + shift_a++; + } + + shift_a &= 0xfffe; + mod_a = fleft_shift(a, (int) shift_a); + + /* This next piece of code implements a "norm" function */ + /* and returns the shift needed to scale "b" to have a */ + /* 1 in the (MSB-1) position. This is equivalent to */ + /* giving a value between 0.5 & 1.0. */ + mod_b = b; + + shift_b = 0; + while (mod_b > 1.0) + { + mod_b /= 2.0; + shift_b--; + } + + while (mod_b < 0.5) + { + mod_b *= 2.0; + shift_b++; + } + + shift_b &= 0xfffe; + mod_b = fleft_shift(b, (int) shift_b); + + shift = (shift_b - shift_a) >> 1; + + b_sqr = mod_b * mod_b; + + p2 += 0.9346f * mod_b + -0.4695f * b_sqr; + p1 += -3.3056f * mod_b + 1.6608f * b_sqr; + p0 += -0.8815f * mod_b + 0.4429f * b_sqr; + + approx = p0 + p1 * mod_a + p2 * mod_a * mod_a; + + approx = fleft_shift(approx, (int) shift); + + return (approx); +} + +/*--------------------------------------------------------------------------------* + * rint_new() + * + * Round to the nearest integer with mid-point exception + *---------------------------------------------------------------------------------*/ + +double rint_new( + double x +) +{ + int a; + + /* middle value point test */ + if (ceil (x + 0.5) == floor (x + 0.5)) + { + a = (int) ceil (x); + + if (a % 2 == 0) + { + return ceil (x); + } + else + { + return floor (x); + } + } + else + { + return floor (x + 0.5); + } +} + + +/*-------------------------------------------------------------------* + * anint() + * + * Round to the nearest integer. + *-------------------------------------------------------------------*/ + +double anint( + double x +) +{ + return (x)>=0?(int)((x)+0.5):(int)((x)-0.5); +} + +/*-------------------------------------------------------------------* + * is_numeric_float() + * + * Returns 0 for all NaN and Inf values defined according to IEEE 754 + * floating point number's definition. Returns 1 for numeric values. + *-------------------------------------------------------------------*/ +short is_numeric_float( + float x +) +{ + union float_int + { + float float_val; + int int_val; + } float_int; + float_int.float_val=x; + return ((float_int.int_val & 0x7f800000) != 0x7f800000); +} + + diff --git a/src/libs/libevs/lib_com/tools_fx.cpp b/src/libs/libevs/lib_com/tools_fx.cpp deleted file mode 100755 index d0726d81..00000000 --- a/src/libs/libevs/lib_com/tools_fx.cpp +++ /dev/null @@ -1,2628 +0,0 @@ -/*==================================================================================== - EVS Codec 3GPP TS26.442 Apr 03, 2018. Version 12.11.0 / 13.6.0 / 14.2.0 - ====================================================================================*/ - -#include -#include -#include "options.h" /* Compilation switches */ -#include "prot_fx.h" /* Function prototypes */ -#include "basop_util.h" -#include "rom_com_fx.h" /* Function prototypes */ -#include "cnst_fx.h" /* Function prototypes */ -#include "stl.h" - -#define INV_BANDS10 3277 /* 1/10 in Q15 */ -#define INV_BANDS9 3641 /* 1/9 in Q15 */ -#define INV_BANDS3 10923 /* 1/9 in Q15 */ - -/*-------------------------------------------------------------------* - * usdequant_fx() - * - * Uniform scalar de-quantizer routine - * - * Applies de-quantization based on scale and round operations. - *-------------------------------------------------------------------*/ -Word16 usdequant_fx( /* Qx*/ - const Word16 idx, /* i: quantizer index Q0*/ - const Word16 qlow, /* i: lowest codebook entry (index 0) Qx*/ - const Word16 delta /* i: quantization step Qx-1*/ -) -{ - Word16 g; - Word32 L_tmp; - - /*g = idx * delta + qlow;*/ - L_tmp = L_deposit_l(qlow);/*Qx */ - L_tmp = L_mac(L_tmp,idx,delta);/*Qx */ - g = round_fx(L_shl(L_tmp,16)); /*Qx */ - - return( g ); -} - -/*-------------------------------------------------------------------* - * usquant() - * - * Uniform scalar quantizer according to MMSE criterion - * (nearest neighbour in Euclidean space) - * - * Applies quantization based on scale and round operations. - * Index of the winning codeword and the winning codeword itself are returned. - *-------------------------------------------------------------------*/ -Word16 usquant_fx( /* o: index of the winning codeword */ - const Word16 x, /* i: scalar value to quantize Qx*/ - Word16 *xq, /* o: quantized value Qx*/ - const Word16 qlow, /* i: lowest codebook entry (index 0) Qx*/ - const Word16 delta, /* i: quantization step Qx-1*/ - const Word16 cbsize /* i: codebook size */ -) -{ - Word16 idx; - Word16 tmp, exp; - Word32 L_tmp; - - /* idx = (short)( (x - qlow)/delta + 0.5f); */ - exp = norm_s(delta); - tmp = div_s(shl(1,sub(14,exp)),delta); /*Q(29-exp-(Qx-1))->Q(30-exp-Qx) */ - L_tmp = L_mult(sub(x,qlow),tmp); /*Q(31-exp) */ - idx = extract_l(L_shr_r(L_add(L_tmp,shl(1,sub(30,exp))),sub(31,exp))); /*Q0 */ - - idx = s_min(idx,sub(cbsize,1)); - idx = s_max( idx, 0); - - /* *xq = idx*delta + qlow; */ - L_tmp = L_deposit_l(qlow);/*Qx */ - L_tmp = L_mac(L_tmp,idx,delta);/*Qx */ - *xq = round_fx(L_shl(L_tmp,16));/*Qx */ - - return idx; -} -/*-------------------------------------------------------------------* -* Dot_product: -* -* Compute scalar product of using accumulator. -* Performs no normalization, as opposed to Dot_product12() -*-------------------------------------------------------------------*/ -Word32 Dot_product( /* o : Sum */ - const Word16 x[], /* i : 12bits: x vector */ - const Word16 y[], /* i : 12bits: y vector */ - const Word16 lg /* i : vector length */ -) -{ - Word16 i; - Word32 L_sum; - - L_sum = L_mac(1L, x[0], y[0]); - FOR (i = 1; i < lg; i++) - { - L_sum = L_mac(L_sum, x[i], y[i]); - } - return L_sum; -} -/*---------------------------------------------------------------------* - * dotp_fx() - * - * Dot product of vector x[] and vector y[] - *---------------------------------------------------------------------*/ - -Word32 dotp_fx( /* o : dot product of x[] and y[] */ - const Word16 x[], /* i : vector x[] */ - const Word16 y[], /* i : vector y[] */ - const Word16 n, /* i : vector length */ - Word16 *exp /* (o) : exponent of result (0..+30) */ -) -{ - Word16 sft; - Word32 L_sum; - - assert(*exp == 0); - - L_sum = L_add(L_shr(Dot_product(x, y, n), 1), 1); - - /* Normalize acc in Q31 */ - - sft = norm_l(L_sum); - L_sum = L_shl(L_sum, sft); - - *exp = sub(30, sft); - move16(); /* exponent = 0..30 */ - - return L_sum; -} - -Word32 sum2_fx( /* o : sum of all squared vector elements Q(2x+1)*/ - const Word16 *vec, /* i : input vector Qx*/ - const Word16 lvec /* i : length of input vector */ -) -{ - Word16 i; - Word32 L_tmp; - L_tmp = L_deposit_l(0); - FOR( i=0; i= 0; i--) - { - y[i] = x[i]; - move16(); - } - } -} - -/*-------------------------------------------------------------------* - * Copy32: - * - * Copy vector x[] to y[] (32 bits) - *-------------------------------------------------------------------*/ -void Copy32( - const Word32 x[], /* i : input vector */ - Word32 y[], /* o : output vector */ - const Word16 L /* i : vector length */ -) -{ - Word16 i; - IF(y < x) - { - FOR (i = 0; i < L; i++) - { - y[i] = x[i]; - move32(); - } - } - ELSE - { - FOR (i = L-1; i >= 0; i--) - { - y[i] = x[i]; - move32(); - } - } -} -/*-------------------------------------------------------------------* - * set16_fx() - * set32_fx() - * - * Set the vector elements to a value - *-------------------------------------------------------------------*/ -void set16_fx( - Word16 y[], /* i/o: Vector to set */ - const Word16 a, /* i : Value to set the vector to */ - const Word16 N /* i : Lenght of the vector */ -) -{ - Word16 i; - - FOR (i=0 ; i 0) - { - FOR (i = 0; i < lg; i++) - { - x[i] = shl(x[i], exp0); - move16(); /* saturation can occur here */ - } - return; - } - IF (exp0 < 0) - { - BASOP_SATURATE_WARNING_OFF - tmp = shl(-32768, exp0); /* we use negative to correctly represent 1.0 */ - BASOP_SATURATE_WARNING_ON - FOR (i = 0; i < lg; i++) - { - x[i] = msu_r(0, x[i], tmp); - move16(); /* msu instead of mac because factor is negative */ - } - return; - } -} - -/*---------------------------------------------------------------------* - * mean() - * - *---------------------------------------------------------------------*/ -Word16 mean_fx( /* o : mean of vector */ - const Word16 *vec_fx, /* i : input vector */ - const Word16 lvec_fx /* i : length of input vector */ -) -{ - Word16 tmp; - tmp = sum16_fx(vec_fx,lvec_fx); - tmp = mult_r(tmp,div_s(1,lvec_fx)); - - return tmp; -} -/*-------------------------------------------------------------------* - * Vr_add - * - * Add two Word16 vectors together integer by integer - *-------------------------------------------------------------------*/ -void Vr_add( - const Word16 *in1, /* i : Input vector 1 */ - const Word16 *in2, /* i : Input vector 2 */ - Word16 *out, /* o : Output vector that contains vector 1 + vector 2 */ - Word16 Len /* i : Vector lenght */ -) -{ - Word16 i; - - FOR (i=0; i=lo; i--) - { - i1 = add(i, 1); - tempr = r[i]; - move16(); - move16(); /*supplementary move for the j-1 PTR initialization*/ - FOR (j=i1; j<=up; j++) - { - IF (sub(tempr, r[j]) <= 0) - { - BREAK; - } - - r[j-1] = r[j]; - move16(); - } - r[j-1] = tempr; - move16(); - } -} - -void sort_32_fx( - Word32 *r, /* i/o: Vector to be sorted in place */ - const Word16 lo, /* i : Low limit of sorting range */ - const Word16 up /* I : High limit of sorting range */ -) -{ - Word16 i, j; - Word32 tempr; - FOR ( i=sub(up, 1); i>=lo; i-- ) - { - tempr = r[i]; - move32(); - FOR ( j=add(i, 1); j<=up; j++ ) - { - IF (L_sub(tempr,r[j]) <= 0) - { - BREAK; - } - r[j-1] = r[j]; - move32(); - } - - r[j-1] = tempr; - move32(); - } - - return; -} - -Word16 minimum_fx( /* o : index of the minimum value in the input vector */ - const Word16 *vec_fx, /* i : input vector */ - const Word16 lvec_fx, /* i : length of input vector */ - Word16 *min_fx /* o : minimum value in the input vector */ -) -{ - Word16 j, ind; - Word16 tmp; - ind = 0; - move16(); - tmp = vec_fx[0]; - move16(); - - FOR ( j=1 ; j 0 ) - { - ind = j; - move16(); - } - tmp = s_max(tmp,vec_fx[j]); - } - *max_fx = tmp; - move16(); - - return ind; -} - -/*---------------------------------------------------------------------* - * minimum_32_fx() - * - * Find index and value of the minimum in a vector - *---------------------------------------------------------------------*/ - -Word16 minimum_32_fx( /* o : index of the minimum value in the input vector */ - const Word32 *vec_fx, /* i : input vector */ - const Word16 lvec_fx, /* i : length of input vector */ - Word32 *min_fx /* o : minimum value in the input vector */ -) -{ - Word16 j, ind; - Word32 tmp; - ind = 0; - move16(); - tmp = vec_fx[0]; - move16(); - - FOR ( j=1 ; j 0 ) - { - ind = j; - move16(); - } - tmp = L_max(tmp,vec[j]); - } - *max = tmp; - move32(); - - return ind; -} - -/*---------------------------------------------------------------- - *Function: - *Finds number of shifts to normalize a 16-bit array variable. - *Return value - *Number of shifts - *----------------------------------------------------------------*/ -Word16 Exp16Array( - const Word16 n, /* (i): Array size */ - const Word16 *sx /* (i): Data array */ -) -{ - Word16 k; - Word16 exp; - Word16 sMax; - Word16 sAbs; - - sMax = abs_s( sx[0] ); - move16(); - - FOR ( k = 1; k < n; k++ ) - { - sAbs = abs_s( sx[k] ); - sMax = s_max( sMax, sAbs ); - } - - exp = norm_s( sMax ); - return exp; -} - -Word16 Exp32Array( - const Word16 n, /* (i): Array size */ - const Word32 *sx /* (i): Data array */ -) -{ - Word16 k; - Word16 exp; - Word32 L_Max; - Word32 L_Abs; - - L_Max = L_abs( sx[0] ); - FOR ( k = 1; k < n; k++ ) - { - L_Abs = L_abs( sx[k] ); - L_Max = L_max( L_Max, L_Abs ); - } - exp = norm_l( L_Max ); - - if(L_Max == 0) - { - exp = 31; - move16(); - } - return exp; -} - -Word32 sum16_32_fx( /* o : sum of all vector elements Qx*/ - const Word16 *vec, /* i : input vector Qx*/ - const Word16 lvec /* i : length of input vector */ -) -{ - Word16 i; - Word32 tmp, L_var; - tmp = 0; - move16(); - FOR( i=0; i 0) - { - ind = j; - move16(); - } - emax = L_max(emax, L_tmp); - } - - *ener_max = L_shr(emax, add(Qvec, Qvec)); - move32(); - - return ind; -} -/*-------------------------------------------------------------------* - * mean32: - * - * Find the mean of a 32 bits vector - *-------------------------------------------------------------------*/ -Word32 Mean32( /* o : mean of the elements of the vector */ - const Word32 in[], /* i : input vector */ - const Word16 L /* i : length of input vector */ -) -{ - Word32 Ltmp; - Word16 inv_L; - - inv_L = INV_BANDS9; - move16(); - if (sub(L, 10) == 0) - { - inv_L = INV_BANDS10; - move16(); - } - - Ltmp = sum32_fx(in, L); - - Ltmp = Mult_32_16(Ltmp, inv_L); - - return Ltmp; -} -Word32 sum32_fx( /* o : sum of all vector elements Qx*/ - const Word32 *vec, /* i : input vector Qx*/ - const Word16 lvec /* i : length of input vector */ -) -{ - Word16 i; - Word32 tmp; - tmp = L_deposit_l(0); - FOR( i=0; i= 0) - { - expA = sub(expA, 1); - } - N = L_shl(Numer, expA); - - /* Perform Approximation of the Division - * Since 'lo' part is '0' AND 'denom' is supposed to be constant in the targeted usage - * one could import the Div32 code and pre-calc the div_s and eliminate all calcs - * with 'lo' to save some complexity */ - - Quotient = Div_32_optmz(N, D); /* takes 36 clocks */ - /* Bring Back to Q0 (minus 2 because we removed the left shift by 2 in the Div32_optmz) */ - IF(rshift) - { - Quotient = L_shr(Quotient, add(15-2, sub(expA, sub(expB,1)))); - } - ELSE - { - Quotient = L_shr(Quotient, add(15-2, sub(expA, expB))); - } - - /* Cross Check (do Quotient x Divisor) - * The Quotient is unsigned but we cannot just use extract_h because - * extract_l on the low part will get the sign of the bit #15. - * In a 32 bits value, what is in bits 0-15 is un unsigned 16 bits value. - * So, we shift left by 1, extract the hi part and mult it by 32768 (hence the L_shl by 16-1. - * Then we take 15 bits left (mask the others) and multiply by Denom. - * Technically this could overflow. But since we are mutiplying to get - * back to the Numer value that fitted in a 32 bits, doing Divisor x Quotient - * must necessarily fit in a 32 bits - * It is assumed that all are positive values. If not, one could - * check the sign of the numer and denom, turn them into abs values - * and restore the sign after*/ - TEMP = L_shl(L_mult0(extract_h(L_shl(Quotient, 1)), Denom), 16-1); - TEMP = L_mac0(TEMP, extract_l(L_and(0x7FFF, Quotient)), Denom); - - - - /* Here we test to see if the previous "Quotient x Divisor" (or TEMP) is too small - * that is the "Numer" minus TEMP is bigger or Equal to the Divisor. - * If it is then the quotient is too small. We need to increase it by 1. - * That is caused by our Div32 fractionnal division that can be off by 1 - * sometimes. - * In some cases, when the divisor is very small (like 10 or something) - * the quotient could be off by more than 1 and we would need a loop - * to check again. That is not the case here with the current divisor */ - IF(rshift) - { - TEMP = L_shl(TEMP, 1); - WHILE (L_msu0(L_sub(Numer, TEMP), 2, Denom) >= 0) - { - Quotient = L_add(Quotient, 1); - TEMP = L_shl(L_mult0(extract_h(L_shl(Quotient, 1)), Denom), 16-1); - TEMP = L_mac0(TEMP, extract_l(L_and(0x7FFF, Quotient)), Denom); - TEMP = L_shl(TEMP, 1); - } - } - ELSE - { - WHILE (L_msu0(L_sub(Numer, TEMP), 1, Denom) >= 0) - { - Quotient = L_add(Quotient, 1); - TEMP = L_shl(L_mult0(extract_h(L_shl(Quotient, 1)), Denom), 16-1); - TEMP = L_mac0(TEMP, extract_l(L_and(0x7FFF, Quotient)), Denom); - } - } - *Int_quotient = Quotient; - move32(); - IF(L_msu0(L_sub(Numer, TEMP), 1, Denom) == 0) - { - *Int_mod = 0L; - move32(); - } - ELSE - { - *Int_mod = L_sub(Numer, TEMP); - move32(); - } - - -} - -/*===================================================================*/ -/* FUNCTION : pz_filter_sp_fx () */ -/*-------------------------------------------------------------------*/ -/* PURPOSE : Generic pole-zero filter routine, with single */ -/* precision memory */ -/*-------------------------------------------------------------------*/ -/* INPUT ARGUMENTS : */ -/* */ -/* _ (Word16 []) b : zero filter coefficients (Qc). */ -/* _ (Word16 []) a : pole filter coefficients (Qc), a(0)=1 in Qc */ -/* _ (Word16 []) x : input signal (Qn). */ -/* _ (Word16) PNR : NR filter order */ -/* _ (Word16) PDR : DR filter order */ -/* _ (Word16) N : number of input samples. */ -/* _ (Word16) Qa : Q factor compensation (Qa=16-Qc) */ -/*-------------------------------------------------------------------*/ -/* OUTPUT ARGUMENTS : */ -/* */ -/* _ (Word16 []) y : output signal (Qn) */ -/*-------------------------------------------------------------------*/ -/* INPUT/OUTPUT ARGUMENTS : */ -/* */ -/* _ (Word16 []) buf : filter memory (Qn-Qa). */ -/*-------------------------------------------------------------------*/ -/* RETURN ARGUMENTS : _ None. */ -/*===================================================================*/ - -void pz_filter_sp_fx ( - const Word16 b [], - const Word16 a [], - Word16 x [], - Word16 y [], - Word16 buf [], - Word16 PNR, - Word16 PDR, - Word16 N, - Word16 Qa -) -{ - Word16 i, j; - Word16 s; - Word16 s_mem; - Word32 Ltemp1; - Word32 Lacc; - - s = negate( Qa ); - s = add( s, s ); /* s=-2Qa*/ - s = add( s, 1 ); - FOR ( i = 0; i < N; i++ ) - { - Lacc = L_deposit_h( x[i] ); /* Lacc in Q(16+Qn)*/ - Lacc = L_shl( Lacc, s ); /* Lacc=x[i] in Q(16+Qn-2Qa+1)*/ - FOR ( j = PDR - 1; j >= 0; j-- ) - Lacc = L_msu( Lacc, buf[j], a[j + 1] ); /*Q(16+Qn-2Qa+1)*/ - - - - Lacc = L_shr( Lacc, 1 ); - Ltemp1 = L_add( L_shl( Lacc, Qa ), 0x08000 ); - s_mem = extract_h( Ltemp1 ); - - Lacc = L_deposit_l(0); - FOR ( j = PNR - 1; j >= 0; j-- ) - Lacc = L_mac( Lacc, buf[j], b[j + 1] ); - Lacc = L_mac( Lacc, s_mem, b[0] ); - /* Lacc in Q(1+Qc+Qn-Qa)*/ - - FOR ( j = s_max(PDR, PNR ) - 1; j > 0; j-- ) - { - /* Update filter memory */ - buf[j] = buf[j - 1]; - move16(); - } - buf[0] = s_mem; - move16(); - - Ltemp1 = L_add( L_shr( Lacc, s ), 0x08000 ); /* Ltemp1 in Qc+Qa+Qn=Q(Qn) */ - y[i] = extract_h( Ltemp1 ); /* y[i] in Qn */ - } -} - - - -Word32 root_a_fx( - Word32 a, - Word16 Q_a, - Word16* exp_out -) -{ - Word16 exp, tmp; - Word32 L_tmp; - - if ( a <= 0 ) - { - *exp_out = 0; - return 0; - } - - exp = norm_l( a ); - tmp = extract_h( L_shl( a, exp ) ); - exp = sub( exp, sub(30, Q_a) ); - tmp = div_s( 16384, tmp ); - L_tmp = L_deposit_h( tmp ); - L_tmp = Isqrt_lc( L_tmp, &exp ); - - *exp_out = exp; - move16(); - - return L_tmp; -} - - -Word32 root_a_over_b_fx( - Word32 a, - Word16 Q_a, - Word32 b, - Word16 Q_b, - Word16* exp_out -) -{ - Word16 tmp, num, den, scale; - Word16 exp, exp_num, exp_den; - Word32 L_tmp; - test(); - if ( ( a <= 0 ) || ( b <= 0 ) ) - { - *exp_out = 0; - move16(); - return 0; - } - - exp_num = norm_l( b ); - num = round_fx( L_shl( b, exp_num ) ); - exp_num = sub( sub( 30, exp_num ), Q_b ); - - exp_den = norm_l( a ); - den = round_fx( L_shl( a, exp_den ) ); - exp_den = sub( sub( 30, exp_den ), Q_a ); - - scale = shr( sub( den, num ), 15 ); - num = shl( num, scale ); - exp_num = sub( exp_num, scale ); - - tmp = div_s( num, den ); - exp = sub( exp_num, exp_den ); - - L_tmp = L_deposit_h( tmp ); - L_tmp = Isqrt_lc( L_tmp, &exp ); - - *exp_out = exp; - move16(); - - return L_tmp; -} - -/*===================================================================*/ -/* FUNCTION : fir_fx () */ -/*-------------------------------------------------------------------*/ -/* PURPOSE : Generic FIR filter routine */ -/*-------------------------------------------------------------------*/ -/* INPUT ARGUMENTS : */ -/* */ -/* _ (Word16 []) b : filter coefficients (Qc). */ -/* _ (Word16 []) x : input signal (Qn). */ -/* _ (Word16) P : filter order. */ -/* _ (Word16) N : number of input samples. */ -/* _ (Word16) Qa : Q factor compensation (Qa=16-Qc) */ -/*-------------------------------------------------------------------*/ -/* OUTPUT ARGUMENTS : */ -/* */ -/* _ (Word16 []) y : output signal (Qn) */ -/*-------------------------------------------------------------------*/ -/* INPUT/OUTPUT ARGUMENTS : */ -/* */ -/* _ : None */ -/*-------------------------------------------------------------------*/ -/* RETURN ARGUMENTS : _ None. */ -/*===================================================================*/ -void fir_fx( const Word16 x[], /* i : input vector Qx*/ - const Word16 h[], /* i : impulse response of the FIR filter Q12*/ - Word16 y[], /* o : output vector (result of filtering) Qx*/ - Word16 mem[], /* i/o: memory of the input signal (L samples) Qx*/ - const Word16 L, /* i : input vector size */ - const Word16 K, /* i : order of the FIR filter (K+1 coefs.) */ - const Word16 upd /* i : 1 = update the memory, 0 = not */ - , Word16 shift /* i : difference between Q15 and scaling of h[] */ - ) -{ - - Word16 buf_in[L_FRAME32k+L_FILT_MAX]; - Word16 i, j; - Word32 s; - - /* prepare the input buffer (copy and update memory) */ - Copy( mem, buf_in, K ); - Copy( x, buf_in + K, L ); - IF ( upd ) - { - Copy( buf_in + L, mem, K ); - } - - /* do the filtering */ - FOR ( i = 0; i < L; i++ ) - { - s = L_mult( buf_in[K + i], h[0] ); - - FOR ( j = 1; j <= K; j++ ) - { - s = L_mac( s, h[j], buf_in[K + i - j] ); - } - s = L_shl( s, shift ); - y[i] = round_fx( s ); /*Qx */ - } -} - - -/*--------------------------------------------------------------------------------*/ -/* squant_fx() */ -/*--------------------------------------------------------------------------------*/ -Word16 squant_fx( /* o: index of the winning codeword */ - const Word16 x, /* i: scalar value to quantize */ - Word16* xq, /* o: quantized value */ - const Word16 cb[], /* i: codebook */ - const Word16 cbsize /* i: codebook size */ -) -{ - Word16 tmp; - Word16 c, idx; - Word32 L_mindist, L_dist; - - idx = 0; - move16(); - L_mindist = MAX_32; - move32(); - - FOR ( c = 0; c < cbsize; c++ ) - { - L_dist = L_deposit_l(0); - tmp = sub( x, cb[c] ); - - /*dist += tmp*tmp; */ - L_dist = L_mac( L_dist, tmp, tmp ); - - if ( L_sub( L_dist, L_mindist ) < 0 ) - { - idx = c; - move16(); - } - L_mindist = L_min(L_mindist, L_dist); - } - - *xq = cb[idx]; - move16(); - - return idx; -} - - -/*===================================================================*/ -/* FUNCTION : pz_filter_dp_fx () */ -/*-------------------------------------------------------------------*/ -/* PURPOSE : Generic pole-zero filter routine, with double */ -/* precision memory, transposed direct form II */ -/*-------------------------------------------------------------------*/ -/* INPUT ARGUMENTS : */ -/* */ -/* _ (Word16 []) b : zero filter coefficients (Qc). */ -/* _ (Word16 []) a : pole filter coefficients (Qc), a(0)=1 */ -/* _ (Word16 []) x : input signal (Qx). */ -/* _ (Word16) P : filter order. */ -/* _ (Word16) N : number of input samples. */ -/* _ (Word16) Qa : Q factor compensation (Qa=16-Qc) */ -/*-------------------------------------------------------------------*/ -/* OUTPUT ARGUMENTS : */ -/* */ -/* _ (Word16 []) y : output signal (Qx) */ -/*-------------------------------------------------------------------*/ -/* INPUT/OUTPUT ARGUMENTS : */ -/* */ -/* _ (Word32 []) buf : filter memory (Qx+Qc) */ -/*-------------------------------------------------------------------*/ -/* RETURN ARGUMENTS : _ None. */ -/*===================================================================*/ - -void pz_filter_dp_fx ( - const Word16 b [], - const Word16 a [], - Word16 x [], - Word16 y [], - Word32 buf [], - Word16 PNR, - Word16 PDR, - Word16 N, - Word16 Qa -) -{ - Word16 i, j; - Word16 s; - Word32 s_mem; - Word32 Ltemp1; - Word32 Lacc; - - s = negate( Qa ); - s = add( s, s ); /* s=-2Qa */ - s = add( s, 1 ); - FOR ( i = 0; i < N; i++ ) - { - Lacc = L_deposit_h( x[i] ); /* Lacc in Q(16+Qn)*/ - Lacc = L_shl( Lacc, s ); /* Lacc=x[i] in Q(16+Qn-2Qa+1)*/ - FOR ( j = PDR - 1; j >= 0; j-- ) - Lacc = Msub_32_16( Lacc, buf[j], a[j + 1] ); /*Q(16+Qn-2Qa+1)*/ - - s_mem = L_shl( Lacc, sub( Qa, 1 ) ); /*Qn-Qa+16=Qn+Qc*/ - - Lacc = L_deposit_l(0); - FOR ( j = PNR - 1; j >= 0; j-- ) - Lacc = Madd_32_16( Lacc, buf[j], b[j + 1] ); - Lacc = Madd_32_16( Lacc, s_mem, b[0] ); - /* Lacc in Q(1+Qc+Qn-Qa) */ - - FOR ( j = s_max( PDR, PNR ) - 1; j > 0; j-- ) - { - /* Update filter memory */ - buf[j] = buf[j - 1]; - move16(); - } - buf[0] = s_mem; - move16(); - - Ltemp1 = L_shr( Lacc, s ); /* Ltemp1 in Qc+Qa+Qn=Q(16+Qn) */ - y[i] = extract_h( Ltemp1 ); /* y[i] in Qn */ - } -} - -/*-------------------------------------------------------------------* - * Copy_Scale_sig32_16 - * - * Up/down scale a 32 bits vector and round to 16 bits vector - *-------------------------------------------------------------------*/ -void Copy_Scale_sig32_16( - const Word32 *src, /* i : signal to scale Qx */ - Word16 *dst, /* o : scaled signal Qx */ - Word16 len, /* i : size of x[] Q0 */ - Word16 exp0) /* i : exponent: x = round(x << exp) Qx ?exp */ -{ - Word16 i; - Word32 L_temp; - - IF (exp0 == 0) - { - FOR (i = 0; i < len; i++ ) - { - *dst++ = round_fx(*src++); - } - return; - } - - FOR (i = 0; i < len; i++ ) - { - L_temp = L_shl(*src++, exp0); - - *dst++ = round_fx(L_temp); - } -} - -/*-------------------------------------------------------------------* - * add_vec() - * - * Addition of two vectors sample by sample - *-------------------------------------------------------------------*/ - -void add_vec_fx( - const Word16 x1[], /* i : Input vector 1 */ - const Word16 Qx1, /* i : SCaling of input 1 */ - const Word16 x2[], /* i : Input vector 2 */ - const Word16 Qx2, /* i : SCaling of input 1 */ - Word16 y[], /* o : Output vector that contains vector 1 + vector 2 */ - const Word16 Qy, /* i : SCaling of output 1 */ - const Word16 N /* i : Vector lenght */ -) -{ - Word16 i, Qyx1, Qyx2; - Qyx1 = sub(Qx1,Qy); - Qyx2 = sub(Qx2,Qy); - IF (Qyx1 == 0) - { - FOR (i=0 ; i0: Val was Left Shifted, <0:Right Shifted) */ - Word32 L_val2, /* i: Mantisa of Val2 */ - Word16 exp2, /* i: Exp of Val2 (same as exp1) */ - Word16 *exp /* o: Exp of Result (# of 'L_shl' Req to get to Final Value) */ -) -{ - Word16 temp; - - /* Normalize Energy #1 */ - temp = norm_l(L_val1); - L_val1 = L_shl(L_val1, temp); - /* Adjust Exponent of Energy #1 */ - exp1 = add(exp1, temp); - - /* Normalize Energy #2 */ - temp = norm_l(L_val2); - L_val2 = L_shl(L_val2, temp); - /* Adjust Exponent of Energy #1 */ - exp2 = add(exp2, temp); - - /* Prepare for Inverse */ - temp = round_fx(L_val1); - temp = div_s(16384, temp); - /* Mult Now */ - L_val2 = Mult_32_16(L_val2, temp); - exp1 = add(sub(exp2, exp1), 15*2); - - /* Here Result of ('L_val2' / 2^'exp2') / ('L_val1' / 2^'exp1') is */ - /* 'L_val2' / 2^'exp1' */ - /* Which is val2/val1 instead of val1/val2 because we will use Inverted Square Root */ - /* Normalize before Square Root */ - temp = norm_l(L_val2); - L_val2 = L_shl(L_val2, temp); - exp1 = add(temp, exp1); - /* Do Sqrt */ - temp = sub(31, exp1); - L_val1 = Isqrt_lc(L_val2, &temp); - - *exp = temp; - move16(); - - return L_val1; -} - -Word16 Invert16( /* result in Q'15 + 'exp' */ - Word16 val, - Word16 *exp) -{ - Word16 temp; - - /* prevent 0 input */ - val = s_max(val,1); - /* Normalize Value */ - temp = norm_s(val); - val = shl(val, temp); - - *exp = sub(sub(15-1, *exp), temp); - move16();/* -1 because of 0x4000 is 1.0 in Q14 (and not Q15) */ - - temp = div_s(0x4000, val); - - return temp; -} - -Word16 find_rem(Word16 n, Word16 m, Word16 *r) -{ - Word16 i, q1, q2, qd; - Word32 Ltemp2; - Word32 Lacc; - - test(); - test(); - IF (n<=0 || m<=0 || n=0) - { - Lacc=L_add(L_shl(Lacc,1),1); - } - ELSE - { - Lacc=L_add(Lacc,Ltemp2); - Lacc=L_shl(Lacc,1); - } - } - q1=extract_l(Lacc); - Ltemp2=L_shr(Lacc,q2); - *r=extract_h(Ltemp2); - return(q1); -} - - -Word32 find_remd(Word32 n, Word32 m, Word32 *r) -{ - Word16 i, q1, q2, qd; - Word32 Ltemp2, qo; - Word32 Lacc; - - test(); - test(); - IF (n<=0 || m<=0 || n=0) - { - Lacc=L_shl(Lacc,1); - qo=L_add(qo,1); - } - ELSE - { - Lacc=L_add(Lacc,Ltemp2); - Lacc=L_shl(Lacc,1); - } - } - *r=L_shr(Lacc,q2); - return(qo); -} - -Word16 rint_new_fx ( - Word32 x /*Q16 */ -) -{ - Word16 a; - Word32 L_tmp; - Word16 frac, tmp; - - /* middle value point test */ - frac = lshr(extract_l(x),1); /*Q15 */ - tmp = sub(frac,0x4000); - - IF (!tmp) - { - a = add(extract_h(x),1); - - if (s_and(a,1) == 0) - { - return a; - } - if (s_and(a,1) != 0) - { - return extract_h(x); - } - return extract_h(x); - } - ELSE - { - L_tmp = L_add(x,32768); /*Q16 */ - return extract_h(L_tmp); - } -} - - -/*===================================================================*/ -/* FUNCTION : erb_diff_search_fx () */ -/*-------------------------------------------------------------------*/ -/* PURPOSE : erb amplitude VQ search for QPPP */ -/*-------------------------------------------------------------------*/ -/* INPUT ARGUMENTS : */ -/* _ (Word16 []) prev_erb : Previous erb amplitude, Q13 */ -/* _ (Word16 []) curr_erb : Current erb amplitude, Q13 */ -/* _ (Word16 []) dif_erb: erb differential, Q13 */ -/* _ (Word16 []) pow_spec : LPC power spectrum, Q7 */ -/* _ (Word16 [][]) cb_fx : differential erb codebook, Q13 */ -/* _ (Word16) cb_size : codebook size */ -/* _ (Word16) cb_dim : codebook dimension */ -/* _ (Word16) offset : index to current segment of erb array */ -/* for quantization */ -/*-------------------------------------------------------------------*/ -/* OUTPUT ARGUMENTS : */ -/* _ None */ -/*-------------------------------------------------------------------*/ -/* INPUT/OUTPUT ARGUMENTS : */ -/* _ None */ -/*-------------------------------------------------------------------*/ -/* RETURN ARGUMENTS : */ -/* _ (Word16) index: best codebook index */ -/*-------------------------------------------------------------------*/ -/* CALLED FROM : TX */ -/*===================================================================*/ - -Word16 erb_diff_search_fx(Word16 *prev_erb, const Word16 *curr_erb, Word16 *dif_erb, - Word16 *pow_spec, const Word16 *cb_fx, - Word16 cb_size, Word16 cb_dim, Word16 offset) -{ - Word16 i, j, mmseindex ; - Word16 dh, dl; - Word32 mmse; - Word32 Ltemp1; - Word32 Lacc; - - mmse = EVS_LW_MAX; - move32(); - mmseindex = -1; - move16(); - FOR (j=0; j b[3] = {0.893554687, -1.787109375, 0.893554687}; * - * a[3] = {1.000000000, 1.787109375, -0.864257812}; * - *-----------------------------------------------------------------------*/ -void hp400_12k8_fx( - Word16 signal[], /* i/o: input signal / output is divided by 16 */ - const Word16 lg, /* i : lenght of signal */ - Word16 mem[] /* i/o: filter memory [6] */ -) -{ - Word16 i; - Word16 y1_hi, y1_lo; - Word32 L_tmp, L_tmp2, L_tmp3; - - y1_hi = mem[2]; - move16(); - y1_lo = mem[3]; - move16(); - - L_tmp3 = L_mac(16384L, mem[1], a_hp400_fx[2]); /* rounding to maximize precision */ - L_tmp3 = L_mac(L_tmp3, y1_lo, a_hp400_fx[1]); - L_tmp3 = L_shr(L_tmp3, 15); - L_tmp2 = L_mac(L_tmp3, mem[0], a_hp400_fx[2]); - L_tmp2 = L_mac(L_tmp2, mem[5], b_hp400_fx[2]); - L_tmp2 = L_mac(L_tmp2, mem[4], b_hp400_fx[1]); - L_tmp3 = L_mult(mem[4], b_hp400_fx[2]); - - mem[5] = signal[lg-2]; - - FOR (i = 1; i < lg; i++) - { - /* y[i] = b[0]*x[i] + b[1]*x[i-1] + b[2]*x[i-2] */ - /* + a[1]*y[i-1] + a[2] * y[i-2] */ - - L_tmp = L_mac(L_tmp2, y1_hi, a_hp400_fx[1]); - L_tmp = L_mac(L_tmp, *signal, b_hp400_fx[0]); - - L_tmp = L_shl(L_tmp, 1); /* coeff Q12 --> Q13 */ - - L_tmp2 = L_mac(L_tmp3, y1_hi, a_hp400_fx[2]); - L_tmp2 = L_mac(L_tmp2, *signal, b_hp400_fx[1]); - L_tmp3 = L_mac(16384L, y1_lo, a_hp400_fx[2]); /* rounding to maximize precision */ - - y1_lo = L_Extract_lc(L_tmp, &y1_hi); - - L_tmp3 = L_mac(L_tmp3, y1_lo, a_hp400_fx[1]); - L_tmp3 = L_shr(L_tmp3, 15); - - L_tmp2 = L_add(L_tmp3, L_tmp2); - - L_tmp3 = L_mult(*signal, b_hp400_fx[2]); - - /* signal is divided by 16 to avoid overflow in energy computation */ - *signal++ = round_fx(L_tmp); - } - - /* y[i] = b[0]*x[i] + b[1]*x[i-1] + b[2]*x[i-2] */ - /* + a[1]*y[i-1] + a[2] * y[i-2] */ - - L_tmp = L_mac(L_tmp2, y1_hi, a_hp400_fx[1]); - - mem[4] = *signal; - move16(); - L_tmp = L_mac(L_tmp, mem[4], b_hp400_fx[0]); - - L_tmp = L_shl(L_tmp, 1); /* coeff Q12 --> Q13 */ - - mem[0] = y1_hi; - move16(); - mem[1] = y1_lo; - move16(); - L_Extract(L_tmp, &mem[2], &mem[3]); - - /* signal is divided by 16 to avoid overflow in energy computation */ - *signal++ = round_fx(L_tmp); - - return; -} - - -Word16 dot_prod_satcontr(const Word16 *x, const Word16 *y, Word16 qx, Word16 qy, Word16 *qo, Word16 len) -{ - Word16 tmp_tab_x[L_FRAME16k]; - Word16 tmp_tab_y[L_FRAME16k]; - Word16 shift, q, ener, i; - Word32 L_tmp; - Word16 *pt1, *pt2; - - - Copy( x, tmp_tab_x, len ); /* OPTIMIZE !!!!! the copy into local table is not necessary */ - Copy( y, tmp_tab_y, len ); /* could be reworked to do a 1st iteration with the original x[] and y[] */ - /* then check if there is an overflow and do a more complex 2nd, 3rd, ... processing */ - shift = 0; - move16(); - BASOP_SATURATE_WARNING_OFF - DO - { - Overflow = 0; - move16(); - L_tmp = L_shl(1, s_max(sub(add(add(qx, qy), 7), shift), 0)); - pt1 = tmp_tab_x; - pt2 = tmp_tab_y; - FOR ( i = 0; i < len; i++ ) - { - L_tmp = L_mac0(L_tmp, *pt1++, *pt2++); /*Q(qx+qy-shift) */ - } - - IF(Overflow != 0) - { - Scale_sig(tmp_tab_x, len, -2); - Scale_sig(tmp_tab_y, len, -2); - shift = add(shift, 4); - } - } - WHILE(Overflow != 0); - BASOP_SATURATE_WARNING_ON - - q = norm_l(L_tmp); - L_tmp = L_shl(L_tmp, q); /*Q(qx+qy-shift+q) */ - ener = extract_h(L_tmp); /*Q(qx+qy-shift+q-16) */ - q = add(q, add(qx, qy)); - *qo = sub(q, add(shift, 16)); - - return ener; -} - - -/* - * E_UTIL_f_convolve - * - * Parameters: - * x I: input vector <14bits - * h I: impulse response (or second input vector) (1Q14) - * y O: output vetor (result of convolution) - * - * Function: - * Perform the convolution between two vectors x[] and h[] and - * write the result in the vector y[]. All vectors are of length L. - * Only the first L samples of the convolution are considered. - * Vector size = L_SUBFR - * - * Returns: - * void - */ -void E_UTIL_f_convolve(const Word16 x[], const Word16 h[], Word16 y[], const Word16 size) -{ - Word16 i, n; - Word32 L_sum; - - - y[0] = mult_r(x[0], h[0]); - move16(); - FOR (n = 1; n < size; n++) - { - L_sum = L_mult(x[0], h[n]); - FOR (i = 1; i < n; i++) - { - L_sum = L_mac(L_sum, x[i], h[n - i]); - } - y[n] = mac_r(L_sum, x[i], h[0]); - move16(); - - } - return; -} - -/*----------------------------------------------------------------------------- - * floating_point_add: - * - * Add two floating point numbers: x <- x + y. - *----------------------------------------------------------------------------*/ -void floating_point_add( - Word32 *mx, /* io: mantissa of the addend Q31 */ - Word16 *ex, /* io: exponent of the addend Q0 */ - const Word32 my, /* i: mantissa of the adder Q31 */ - const Word16 ey /* i: exponent of the adder Q0 */ -) -{ - Word32 accX, accY; - Word16 align, expo; - /* NB: This function will not work properly if the mantissa is zero and the exponent is not 32. - It is up to the caller function to avoid this condition. */ - /* Ensure 1 bit headroom before addition. */ - accX = L_shr(*mx, 1); - accY = L_shr(my, 1); - /* First, align the Q-points of the two operands. Then, add. */ - align = sub(*ex, ey); - test(); - IF (align < 0) - { - accX = L_add(accX, L_shl(accY, align)); - } - ELSE - { - accX = L_add(accY, L_shr(accX, align)); - *ex = ey; - move16(); - } - /* Normalize the result and update the mantissa and exponent. */ - expo = norm_l(accX); - *mx = L_shl(accX, expo); - *ex = sub(add(*ex, expo), 1); /* Subtract 1 due to 1-bit down-shift above ensuring 1 bit headroom before addition. */ - return; -} - diff --git a/src/libs/libevs/lib_com/trans_direct.cpp b/src/libs/libevs/lib_com/trans_direct.cpp new file mode 100644 index 00000000..f3a033c3 --- /dev/null +++ b/src/libs/libevs/lib_com/trans_direct.cpp @@ -0,0 +1,141 @@ +/*==================================================================================== + EVS Codec 3GPP TS26.443 Nov 13, 2018. Version 12.11.0 / 13.7.0 / 14.3.0 / 15.1.0 + ====================================================================================*/ + +#include "options.h" +#include "cnst.h" +#include "prot.h" +#include "rom_com.h" + + +/*------------------------------------------------------------------- + * direct_transform() + * + * Transformation of the signal to DCT domain + *-------------------------------------------------------------------*/ + +void direct_transform( + const float *in32, /* i : input signal */ + float *out32, /* o : transformation */ + const short is_transient, /* i : is transient */ + const short L /* i : length */ +) +{ + short i; + short seg; + short segment_length; + + const float *wh; + const float *wl; + float *sh; + float *sl; + float *iseg; + float *oseg; + float dctin32[L_FRAME48k]; + float in32_r16[L_FRAME48k]; + + const float *win; + + + segment_length = L/2; + + if (is_transient) + { + if (L == L_FRAME48k) + { + win = wscw16q15; + } + else if (L == L_FRAME32k) + { + win = wscw16q15_32; + } + else if (L == L_FRAME8k) + { + win = wscw16q15_8; + } + else + { + win = wscw16q15_16; + } + + for (i = 0; i < L/2; i++) + { + in32_r16[i] = in32[L-1-i]; + in32_r16[L-1-i] = in32[i]; + } + iseg = in32_r16 - segment_length/4; + oseg = out32; + + wh = win + segment_length/4; + wl = win + segment_length/4 - 1; + sh = iseg + 3*segment_length/4; + sl = iseg + 3*segment_length/4 - 1; + for (i = 0; i < segment_length/4; i++) + { + dctin32[i] = ((*wl-- **sl--) - (*wh++ **sh++)); + } + + sl = iseg + segment_length/2 - 1; + + for (i = 0; i < segment_length/4; i++) + { + dctin32[segment_length/4 + i] = -(*sl--); + } + + edct(dctin32, oseg, segment_length/2); + + iseg = iseg + segment_length/2; + oseg = oseg + segment_length/2; + + for (seg = 1 ; seg < NUM_TIME_SWITCHING_BLOCKS-1; seg++) + { + wh = win + segment_length/4; + wl = win + segment_length/4 - 1; + sh = iseg + 3*segment_length/4; + sl = iseg + 3*segment_length/4 - 1; + for (i = 0; i < segment_length/4; i++) + { + dctin32[i] = ((*wl-- **sl--) - (*wh++ **sh++)); + } + + sh = iseg; + sl = iseg + segment_length/2 - 1; + wh = win + segment_length/2 - 1; + wl = win + 0; + + for (i = 0; i < segment_length/4; i++) + { + dctin32[segment_length/4 + i] = ((*wl++ **sl--) + (*wh-- **sh++)); + } + + edct(dctin32, oseg, segment_length/2); + + iseg = iseg + segment_length/2; + oseg = oseg + segment_length/2; + } + + sh = iseg + 3*segment_length/4 - 1; + for (i = 0; i < segment_length /4; i++) + { + dctin32[i] = -(*sh--); + } + + sh = iseg; + sl = iseg + segment_length/2 - 1; + wh = win + segment_length/2 - 1; + wl = win + 0; + + for (i = 0; i < segment_length/4; i++) + { + dctin32[segment_length/4 + i] = ((*wh-- **sh++) + (*wl++ **sl--)); + } + + edct(dctin32, oseg, segment_length/2); + } + else + { + edct(in32, out32, L); + } + + return; +} diff --git a/src/libs/libevs/lib_com/trans_direct_fx.cpp b/src/libs/libevs/lib_com/trans_direct_fx.cpp deleted file mode 100755 index 950f4ce3..00000000 --- a/src/libs/libevs/lib_com/trans_direct_fx.cpp +++ /dev/null @@ -1,204 +0,0 @@ -/*==================================================================================== - EVS Codec 3GPP TS26.442 Apr 03, 2018. Version 12.11.0 / 13.6.0 / 14.2.0 - ====================================================================================*/ - -#include "options.h" /* Compilation switches */ -#include "stl.h" -#include "cnst_fx.h" /* Common FX constants */ -#include "prot_fx.h" /* Function prototypes */ -#include "rom_com_fx.h" /* Function prototypes */ - - - -void direct_transform_fx( - const Word32 in32_fx[], - Word32 out32_fx[], - const Word16 is_transient, - const Word16 L, - Word16 *Q -) -{ - - Word16 i, k; - Word16 seg; - Word16 segment_length, segment_length2, segment_length4; - - const Word16 *wh_fx; - const Word16 *wl_fx; - const Word32 *sh_fx; - const Word32 *sl_fx2; - Word32 *sl_fx; - Word32 *iseg_fx; - Word32 *oseg_fx; - Word32 dctin32_fx[L_FRAME48k]; - Word32 in32_r16_fx[L_FRAME48k]; - - const Word16 *win_fx; - Word16 shift, Qmin = 31; - Word32 L_tmp; - Word16 Qs[NUM_TIME_SWITCHING_BLOCKS]; - - - segment_length = shr(L, 1); - segment_length2 = shr(segment_length, 1); - segment_length4 = shr(segment_length2, 1); - - IF (is_transient) - { - IF (sub(L, L_FRAME48k) == 0 ) - { - win_fx = wscw16q15_fx; - } - ELSE IF (sub(L, L_FRAME32k) == 0) - { - win_fx = wscw16q15_32_fx; - } - ELSE IF (sub(L, L_FRAME8k) == 0) - { - win_fx = wscw16q15_8_fx; - } - ELSE - { - win_fx = wscw16q15_16_fx; - } - - sh_fx = &in32_fx[L-1]; - add(0,0); - sl_fx = &in32_r16_fx[L-1]; - add(0,0); - FOR (i = 0; i < segment_length; i++) - { - in32_r16_fx[i] = (*sh_fx--); - move32(); - (*sl_fx--) = in32_fx[i]; - move32(); - } - - iseg_fx = &in32_r16_fx[-segment_length4]; - add(0,0); - oseg_fx = out32_fx; - - wh_fx = &win_fx[segment_length4]; - add(0,0); - wl_fx = wh_fx - 1; - - shift = extract_l(L_mult0(3, segment_length4)); - sh_fx = &iseg_fx[shift]; - add(0,0); - sl_fx2 = sh_fx - 1; - - - FOR (i = 0; i < segment_length4; i++) - { - L_tmp = L_negate(Mult_32_16( (*sh_fx++), (*wh_fx++) )); /*Q+15-15=Q */ - dctin32_fx[i] = Madd_32_16(L_tmp, *sl_fx2--, *wl_fx-- ); - move32();/*Q */ - } - - sl_fx2 = &iseg_fx[segment_length2 - 1]; - add(0,0); - - FOR (i = segment_length4; i < segment_length2; i++) - { - dctin32_fx[i] = L_negate(*sl_fx2--); - move32(); - } - - Qs[0] = *Q; - move16(); - edct_fx(dctin32_fx, oseg_fx, segment_length2, &Qs[0]); - Qmin = s_min(Qs[0], Qmin); - - iseg_fx += segment_length2; - add(0,0); - oseg_fx += segment_length2; - add(0,0); - - FOR (seg = 1 ; seg < NUM_TIME_SWITCHING_BLOCKS-1; seg++) - { - wh_fx = &win_fx[segment_length4]; - add(0,0); - wl_fx = wh_fx - 1; - sh_fx = &iseg_fx[shift]; - add(0,0); - sl_fx2 = sh_fx - 1; - FOR (i = 0; i < segment_length4; i++) - { - L_tmp = L_negate(Mult_32_16( (*sh_fx++), (*wh_fx++) )); /*Q+15-15=Q */ - dctin32_fx[i] = Madd_32_16(L_tmp, *sl_fx2--, *wl_fx-- ); - move32(); /*Q */ - } - - sh_fx = iseg_fx; - sl_fx2 = &iseg_fx[segment_length2 - 1]; - add(0,0); - wh_fx = &win_fx[segment_length2 - 1]; - add(0,0); - wl_fx = win_fx ; - - FOR (i = segment_length4; i < segment_length2; i++) - { - L_tmp = Mult_32_16( (*sh_fx++), (*wh_fx--) ); /*Q+15-15=Q */ - dctin32_fx[i] = Madd_32_16(L_tmp, *sl_fx2--, *wl_fx++ ); - move32(); /*Q */ - } - - Qs[seg] = *Q; - move16(); - edct_fx(dctin32_fx, oseg_fx, segment_length2, &Qs[seg]); - Qmin = s_min(Qs[seg], Qmin); - - iseg_fx += segment_length2; - add(0,0); - oseg_fx += segment_length2; - add(0,0); - } - - sh_fx = &iseg_fx[shift - 1]; - add(0,0); - FOR (i = 0; i < segment_length4; i++) - { - dctin32_fx[i] = L_negate(*sh_fx--); - move32(); - } - - - sh_fx = iseg_fx; - sl_fx2 = &iseg_fx[segment_length2 - 1]; - add(0,0); - wh_fx = &win_fx[segment_length2 - 1]; - add(0,0); - wl_fx = win_fx; - - FOR (i = segment_length4; i < segment_length2; i++) - { - L_tmp = Mult_32_16( (*sl_fx2--), (*wl_fx++) ); /*Q+15-15=Q */ - dctin32_fx[i] = Madd_32_16(L_tmp, *sh_fx++, *wh_fx-- ); - move32(); /*Q */ - } - Qs[NUM_TIME_SWITCHING_BLOCKS-1] = *Q; - move16(); - edct_fx(dctin32_fx, oseg_fx, segment_length2, &Qs[NUM_TIME_SWITCHING_BLOCKS-1]); - Qmin = s_min(Qs[NUM_TIME_SWITCHING_BLOCKS-1], Qmin); - - *Q = Qmin; - move16(); - oseg_fx = out32_fx; - FOR ( k=0; k +#include +#include "options.h" +#include "cnst.h" +#include "rom_com.h" +#include "prot.h" + +/*--------------------------------------------------------------------------* + * Local constants + *--------------------------------------------------------------------------*/ + +#define NUMSF 8 +#define LOG2_NUMSF 3 +#define INV_NUMSF (float)0.125 + +/*--------------------------------------------------------------------------* + * preecho_sb() + * + * Time-domain sub-band based pre-echo reduction + *--------------------------------------------------------------------------*/ + +void preecho_sb( + const long brate, /* i : core bit-rate */ + const float wtda_audio[], /* i : imdct signal */ + float *rec_sig, /* i : reconstructed signal, output of the imdct transform */ + const short framelength, /* i : frame length */ + float *memfilt_lb, /* i/o: memory */ + float *mean_prev_hb, /* i/o: memory */ + float *smoothmem, /* i/o: memory */ + float *mean_prev, /* i/o: memory */ + float *mean_prev_nc, /* i/o: memory */ + float *wmold_hb, /* i/o: memory */ + short *prevflag, /* i/o: flag */ + short *pastpre, /* i/o: flag */ + const short bwidth +) +{ + short i, j, len3xLp20; + float es_mdct[9]; /* 0..3 (0..7): energy of the 4 (8) subframes, 4..5: (8..10) energy of the future subframes */ + float es_mdct_hb[9]; /* 0..3 (0..7): energy of the 4 (8) subframes, 4..5: (8..10) energy of the future subframes */ + short zcr[9]; /* 0..3 (0..7): zero crossing of the 4 (8) subframes, 4..5: (8..10) zero crossing of the future subframes */ + short maxnzcr[8], cntnzcr; /* max number of samples without zero crossing */ + float plus_es_mdct[64]; /* 8*8 subsubframes */ + float imdct_mem[L_FRAME48k]; /* memory of the imdct transform, used in the next frame */ + + short maxind, stind, stind_hb, cnt2, cnt5, adv, advmem; + short ind2, ind3, pluslim; + float max_es; + float *ptr; + float min_g[13], g, gt[13]; + float min_g_hb[13], gt_hb[13]; + float preechogain[960+PREECHO_SMOOTH_LEN]; + float preechogain_hb[960]; + short subframelength, subsubframelength; + float maxcrit, savehalfe, savehalfe_hb; + float rec_sig_lb[960], rec_sig_hb[960]; /* 960 max frame length at 48 kHz */ + float eshbmean2, eshbmean3, sxyhb2, sxylb3, sxyhb3; + float *fptr1, *fptr2, *fptr3, *fptr4, *fptr5, *fptr6; + short *sptr1, *sptr2; + float wmold; + float lim16, lim32; + short limzcr, limmaxnzcr; + float max_es_hb; + short num_subsubframes, log2_num_subsubframes; + float ftmp, fattnext; + float sum_plus_es, mean_plus_es[65]; + float last2, last2_hb; + float max_plus_es_mdct; + short nb_flag, smooth_len; + short firstnzcr; + float es_mdct_half[9]; + float es_mdct_quart[9]; + double invsmoothlenp1; /*double just to have bit-exactness with the previous version, otherwise rounding difference of +-1*/ + short subframelength_s2, subframelength_s34; + float oldgain, oldgain_hb; + + if( brate <= HQ_32k ) + { + nb_flag = 0; + if( bwidth == NB ) + { + nb_flag = 1; + } + + limzcr = 16; + smooth_len = 4; + invsmoothlenp1 = 0.2; + + if( nb_flag == 1 ) + { + limzcr = 10; + smooth_len = PREECHO_SMOOTH_LEN; + invsmoothlenp1 = INV_PREECHO_SMOOTH_LENP1; + } + + limmaxnzcr = framelength/24; + num_subsubframes = 8; + log2_num_subsubframes = 3; + + if( framelength == L_FRAME8k ) + { + num_subsubframes = 4; + log2_num_subsubframes = 2; + } + len3xLp20 = framelength/2-(short)((float)framelength*N_ZERO_MDCT_NS/FRAME_SIZE_NS); + for( i = 0; i < len3xLp20; i++ ) + { + imdct_mem[i] = -wtda_audio[len3xLp20 - 1 - i]; + } + + for( i = 0; i < framelength/2; i++ ) + { + imdct_mem[len3xLp20 + i] = -wtda_audio[i]; + } + + + subframelength = framelength >> LOG2_NUMSF; + subsubframelength = subframelength >> log2_num_subsubframes; + wmold = *smoothmem; + subframelength_s2 = subframelength/2; + subframelength_s34 = subframelength*3/4; + + cntnzcr = -1; + + lim16 = 0.1f; + lim32 = 0.01f; + savehalfe = 0.0f; + savehalfe_hb = 0.0f; + + if( *pastpre == 0 ) + { + /* if past frame mean energies are not known (no preecho_sb in the past frame), limit max attenuation to 1*/ + lim16 = (float)1; + lim32 = (float)1; + } + + *pastpre = 2; + fptr1 = rec_sig_lb; + fptr2 = rec_sig; + fptr3 = rec_sig + 1; + fptr4 = rec_sig + 2; + *fptr1 = (float)(0.25*(*memfilt_lb + *fptr3) + 0.5 * *fptr2); + fptr1++; + + for(j = 1; j < framelength - 1; j++) + { + *fptr1 = (float)(0.25*(*fptr2+*fptr4)+0.5* *fptr3); + fptr1++; + fptr2++; + fptr3++; + fptr4++; + } + + *fptr1 = (float)(0.25*(*fptr2)+0.5* *fptr3); + fptr1 = rec_sig_lb; + fptr2 = rec_sig; + fptr3 = rec_sig_hb; + + for(j = 0; j < framelength; j++) + { + *fptr3 = *fptr2 - *fptr1; + fptr1++; + fptr2++; + fptr3++; + } + + fptr2--; + *memfilt_lb = *fptr2; + + /* energy of low bands 8 present and 1 future sub-frames */ + fptr1 = es_mdct; + fptr5 = es_mdct_half; + fptr6 = es_mdct_quart; + fptr4 = es_mdct_hb; + fptr2 = rec_sig; + fptr3 = rec_sig_hb; + sptr1 = zcr; + *sptr1 = 0; + sptr2 = maxnzcr; + for (j = 0; j < NUMSF; j++) /* 8 present subframes */ + { + *fptr1 = 100 + *fptr2 **fptr2; + *fptr4 = 100 + *fptr3 **fptr3; + + *sptr2 = 0; + firstnzcr = 1; + if( j == 0 ) + { + firstnzcr = 0; + } + + fptr2++; + fptr3++; + + for (i = 1; i < subframelength; i++) + { + if( i == subframelength_s2 ) + { + *fptr5 = *fptr1; + } + + if( i == subframelength_s34 ) + { + *fptr6 = *fptr1; + } + *fptr1 += *fptr2 **fptr2; + *fptr4 += *fptr3 **fptr3; + cntnzcr++; + if( *fptr2 **(fptr2-1) < 0 ) + { + (*sptr1)++; + if(cntnzcr > *sptr2) + { + *sptr2 = cntnzcr; + } + + if( (firstnzcr > 0) && (cntnzcr > maxnzcr[j-1]) ) + { + maxnzcr[j-1] = cntnzcr; + } + + firstnzcr = 0; + cntnzcr = -1; + } + fptr2++; + fptr3++; + } + + if(cntnzcr > *sptr2) + { + *sptr2 = cntnzcr; + } + fptr4++; + sptr1++; + sptr2++; + + if( (firstnzcr > 0) && (cntnzcr > maxnzcr[j-1]) ) + { + maxnzcr[j-1] = cntnzcr; + } + + *sptr1 = 0; + if((j < NUMSF-1) && ((*fptr2 **(fptr2-1) < 0))) /* zcr between 2 subframes */ + { + (*sptr1)++; /* counts for the nexte subframe */ + cntnzcr = -1; + } + + if( *fptr5 < (*fptr1)/2 ) + { + *fptr5 = 2*(*fptr1 - *fptr5); + } + else + { + *fptr5 = *fptr1; + } + fptr1++; + fptr5++; + fptr6++; + } + + fptr2 = imdct_mem; + j = NUMSF; + *fptr1 = 100 + *fptr2 **fptr2; + *sptr1 = 0; + fptr2++; + for (i = 1; i < len3xLp20; i++) /* one future subframe but 140 samples (not 80) (enough with ALDO window) */ + { + *fptr1 += *fptr2 **fptr2; + + if(*fptr2 **(fptr2-1) < 0) + { + (*sptr1)++; + } + + fptr2++; + } + + fptr2 = imdct_mem; + fptr3 = imdct_mem + 1; + fptr4 = imdct_mem + 2; + ftmp = (float)(-0.25*(rec_sig[framelength-1] + *fptr3) + 0.5 * *fptr2); + es_mdct_hb[NUMSF] = 100 + ftmp * ftmp; + + for(j = 1; j < len3xLp20 - 1; j++) + { + ftmp = (float)(-0.25*(*fptr2+*fptr4)+0.5* *fptr3); + es_mdct_hb[NUMSF] += ftmp * ftmp; + fptr2++; + fptr3++; + fptr4++; + } + + ftmp = (float)(-0.25*(*fptr2)+0.5* *fptr3); + es_mdct_hb[NUMSF] += ftmp * ftmp; + max_es_hb = es_mdct_hb[0]; /* for memorising the max energy */ + + max_es = es_mdct[0]; /* for memorising the max energy */ + maxind = 0; + for (i = 1; i <= NUMSF; i++) + { + if (es_mdct_hb[i] >= max_es_hb) /* '=' to handle the first window*/ + { + max_es_hb = es_mdct_hb[i]; /* max energy low band, 8 present and 1 future subframes */ + } + + if (es_mdct[i] >= max_es) /* '=' to handle the first window*/ + { + max_es = es_mdct[i]; /* max energy low band, 8 present and 1 future subframes */ + maxind = i; + } + } + + cnt2 = cnt5 = 0; + if( *prevflag != 0 || max_es < subframelength * 10000 ) + { + maxind = 0; + } + + if( max_es < 4 * *mean_prev ) + { + maxind = 0; + } + *prevflag = 0; + + for (i = 0; i < maxind; i++) /* only subbands before max energy subband are handled */ + { + g = 1; /* default gain */ + min_g[i] = 1; + min_g_hb[i] = 1; + if( (es_mdct_half[i] > 100*(*mean_prev_nc+500000)) || /* less then 20% energy in 3/4 of the subframe -> starting onset in the last quarter */ + ((es_mdct_half[i] > 10*(*mean_prev_nc+500000)) && + ((zcr[i] < limzcr) || (es_mdct_quart[i] < es_mdct[i]/6)) )) /* already an offset, plosif, do not touch */ + { + maxind = i; /* no preecho reduction after the first subframe with gain 1 */ + *prevflag = 1; + for(j = i-1; j >= 0; j--) + { + if (es_mdct[j] > es_mdct[i] / 2) + { + maxind = j; + } + } + } + else + { + if (es_mdct[i] < max_es / 16) + { + g = lim16; + cnt5++; + + if (es_mdct[i] < max_es / 32) + { + g = lim32; + cnt2++; + } + + min_g[i] = (float)sqrt((double)(*mean_prev / es_mdct[i])); /*limitation of attenuation gain */ + min_g_hb[i] = (float)sqrt((double)(*mean_prev_hb / es_mdct_hb[i])); /*limitation of attenuation gain */ + if( (zcr[i] < limzcr/2) || (maxnzcr[i] > limmaxnzcr) ) + { + if(min_g[i] < 1) /* *mean_prev < es_mdct[i]) */ + { + *mean_prev = es_mdct[i]; + } + min_g[i] = 1; /* not noise-like, do not touch the amplitude, but may do in HB*/ + } + + if(min_g[i] > 1) /* in fix point will be min_g = min(min_g, 1), weight 1 */ + { + min_g[i] = (float)1; + } + + if(min_g_hb[i] > 1) /* in fix point will be min_g = min(min_g, 1), weight 1 */ + { + min_g_hb[i] = (float)1; + } + } + else + { + if( i > 0 && maxind < NUMSF ) + { + *prevflag = 1; + } + maxind = i; /* no preecho reduction after the first subframe with gain 1*/ + } + } + gt[i] = g; + gt_hb[i] = g; + } + + for ( i = maxind; i <= NUMSF; i++ ) /* also for the first memory subframe */ + { + gt[i] = 1; + min_g[i] = 1; + gt_hb[i] = 1; + min_g_hb[i] = 1; + + } + + ind2 = 0; + for( i = 0; i < NUMSF; i++ ) + { + if( gt[i] < 1 ) /*gt not yet limited by min_g*/ + { + ind2 = i+1; /* first subframe with gain = 1 after last gain < 1 --> frame with the attack*/ + } + } + + if( (wmold > 0.5) && ((cnt2+cnt5) < 2) ) /* mini either 1 cnt2 (and so also cnt5) or 2 cnt5 */ + { + /* maxind = 0; false alarm, no echo reduction */ + ind2 = 0; + } + + fptr3 = gt; + fptr4 = gt_hb; + fptr5 = min_g; + fptr6 = min_g_hb; + + for (i = 0; i < ind2; i++) /* only subbands before max energy subband are handled*/ + { + if(*fptr3 < *fptr5) /* in fix point will be g = max(g, min_g), weight 1 */ + { + *fptr3 = *fptr5; + } + + if(*fptr4 < *fptr6) /* in fix point will be g = max(g, min_g), weight 1 */ + { + *fptr4 = *fptr6; + } + + fptr1 = preechogain + i*subframelength+smooth_len; + fptr2 = preechogain_hb + i*subframelength; + for(j = 0; j < subframelength; j++) + { + *fptr1 = *fptr3; + *fptr2 = *fptr4; + fptr1++; + fptr2++; + } + + fptr3++; + fptr4++; + fptr5++; + fptr6++; + } + + max_plus_es_mdct = 0; + adv = smooth_len; /* samples needed to have near 1 gain after smoothing at the beggining of the attack subframe*/ + advmem = adv; + + if( ind2 > 0 || wmold < 1 || *wmold_hb < 1 ) + { + ptr = imdct_mem; + pluslim = num_subsubframes; /* if ind2 == NUMSF */ + + if( ind2 < NUMSF ) + { + ptr = rec_sig + subframelength*ind2; + pluslim = (NUMSF-ind2)*num_subsubframes; + } + + maxcrit = *mean_prev_nc; + if( ind2 == 0 ) + { + sum_plus_es = *mean_prev_nc; /* 8 times mean sususb enenrgy (=maxcrit)*/ + pluslim = num_subsubframes; + oldgain = wmold; + oldgain_hb = *wmold_hb; + } + else /* ind2 > 0*/ + { + sum_plus_es = es_mdct[ind2-1]; /* 8 times mean sususb enenrgy (=maxcrit)*/ + oldgain = gt[ind2-1]; + oldgain_hb = gt_hb[ind2-1]; + maxcrit = es_mdct[ind2-1]*gt[ind2-1]*gt[ind2-1]; /* /1 (iso /8) : 8 times of the pevious subframe mean*/ + + if( (max_es/80 > maxcrit) && (zcr[ind2] > limzcr) ) + { + maxcrit = max_es/80; /* still 10 times smaller then mean max_es*/ + } + } + + for (j = 0; j < pluslim; j++) /* 8 sub-subframes */ + { + plus_es_mdct[j] = 100; + for (i = 0; i < subsubframelength; i++) + { + + ftmp = *ptr **ptr; + plus_es_mdct[j] += ftmp; + if( plus_es_mdct[j] > max_plus_es_mdct ) + { + max_plus_es_mdct = plus_es_mdct[j]; + } + ptr++; + } + + sum_plus_es += 4 * plus_es_mdct[j]; + mean_plus_es[j+1] = sum_plus_es / (j+2); /* 4/j could be tabulated in fixed point */ + if( mean_plus_es[j+1] < maxcrit) + { + mean_plus_es[j+1] = maxcrit; + } + } + mean_plus_es[0] = plus_es_mdct[0]; + if( mean_plus_es[0] < maxcrit) + { + mean_plus_es[0] = maxcrit; + } + mean_plus_es[pluslim] = -1; + + j = 0; + while((plus_es_mdct[j] < mean_plus_es[j]) && (plus_es_mdct[j] < max_plus_es_mdct/8 )) + { + j++; + } + + adv -= j*subsubframelength; + + if( ind2 < NUMSF ) /* onset not in future frame */ + { + fptr1 = preechogain + ind2*subframelength+smooth_len; + fptr2 = preechogain_hb + ind2*subframelength; + + for (i = 0; i < j*subsubframelength; i++) + { + *fptr1 = oldgain; /*keep the gain of the previous subframe*/ + *fptr2 = oldgain_hb; /*keep the gain of the previous subframe*/ + fptr1++; + fptr2++; + } + } + } + + if( ind2 > 0 ) + { + /* check increasing energy of preecho by regression last 3 subframes (if possible) */ + ind3 = ind2 + (j >> log2_num_subsubframes); /* return (with rounding) to subframe basis */ + if( ind3 > 1 ) + { + /* case of 3 points is simply */ + eshbmean2 = es_mdct_hb[ind3-1] + es_mdct_hb[ind3-2]; + sxyhb2 = (es_mdct_hb[ind3 - 1] - es_mdct_hb[ind3 - 2]); /* / eshbmean2 * 2; 04042013: division not needed, only sign of sxyhb2 is used*/ + + if( ind3 > 2 ) + { + eshbmean3 = (eshbmean2 + es_mdct_hb[ind3-3]) / 3; + sxylb3 = (es_mdct[ind3 - 1] - es_mdct[ind3 - 3]); /* /eslbmean3 / 2; /2 for 3 points regression calc; 04042013: division not needed, only sign of sxylb3 is used*/ + sxyhb3 = (es_mdct_hb[ind3 - 1] - es_mdct_hb[ind3 - 3])/eshbmean3 / 2; + if ((sxyhb3 < (float)0.2) || (sxylb3 < 0)) + { + ind2 = 0; + adv = advmem; + } + } + else + { + if (sxyhb2 < (float)0.0) + { + ind2 = 0; + adv = advmem; /* 04042013: small bug corection*/ + } + } + + eshbmean3 = (eshbmean2 + es_mdct_hb[ind3]) / 3; /*verif toward future subsubframe*/ + sxyhb3 = (es_mdct_hb[ind3] - es_mdct_hb[ind3 - 2])/eshbmean3 / 2; + if (sxyhb3 < (float)0.2) + { + ind2 = 0; + adv = advmem; + } + } + } + + stind = ind2*subframelength-adv; + stind_hb = stind + advmem; + if( stind < 0 ) + { + stind = 0; + } + + if( stind_hb < 0 ) + { + stind_hb = 0; + } + + fptr1 = preechogain + stind + smooth_len; + fptr2 = preechogain_hb + stind_hb; + + for (i = stind + smooth_len; i < framelength; i++) /* rest of the gains, without 4 (PREECHO_SMOOTH_LEN) 1 for fadeout */ + { + *(fptr1++) = 1; + } + + for (i = stind_hb; i < framelength; i++) /* rest of the gains*/ + { + *(fptr2++) = 1; + } + + for (i = 0; i < smooth_len; i++) + { + preechogain[i] = *smoothmem; + } + + fattnext = 1; + if( stind > framelength ) + { + fattnext = gt[ind2-1]; + } + + for (i = 0; i < smooth_len; i++) + { + preechogain[framelength + i] = fattnext; + } + + fptr1 = preechogain; + for (i = 0; i < framelength; i++) + { + fptr2 = fptr1; + for(j = 1; j <= smooth_len; j++) + { + *fptr1 += *(++fptr2); + } + + *fptr1 *= (float)invsmoothlenp1; + fptr1++; + } + + *smoothmem = fattnext; + *wmold_hb = preechogain_hb[framelength-1]; + + /* apply gain */ + fptr1 = preechogain; + fptr2 = preechogain_hb; + fptr3 = rec_sig; + fptr4 = rec_sig_lb; + fptr5 = rec_sig_hb; + + for (i = 0; i < framelength; i++) + { + *fptr3 = *fptr4 **fptr1 + *fptr5 **fptr2; + fptr1++; + fptr2++; + fptr3++; + fptr4++; + fptr5++; + } + + *mean_prev_nc = es_mdct[0]; /* compute mean not corrected by the actual gains*/ + + for (i = 1; i < NUMSF; i++) /* all present subbands */ + { + if( i == NUMSF/2 ) + { + savehalfe = *mean_prev_nc; + } + *mean_prev_nc += es_mdct[i]; + } + + if( savehalfe < *mean_prev_nc/2 ) + { + *mean_prev_nc = 2*(*mean_prev_nc - savehalfe); + } + *mean_prev_nc = *mean_prev_nc * INV_NUMSF; /* >> LOG2_NUMSF in fixpoint */ + + for( i = 0; i < ind2; i++ ) /* only subbands before max energy subband are handled*/ + { + es_mdct[i] = es_mdct[i]*gt[i]*gt[i]; + es_mdct_hb[i] = es_mdct_hb[i]*gt_hb[i]*gt_hb[i]; + } + + *mean_prev = es_mdct[0]; /* compute mean used in next frame to limit gain*/ + *mean_prev_hb = es_mdct_hb[0]; /* compute mean used in next frame to limit gain*/ + + for (i = 1; i < NUMSF; i++) /* all present subbands */ + { + if(i == NUMSF/2) + { + savehalfe = *mean_prev; + savehalfe_hb = *mean_prev_hb; + } + + *mean_prev += es_mdct[i]; + *mean_prev_hb += es_mdct_hb[i]; + } + + if( savehalfe < *mean_prev/2 ) + { + *mean_prev = 2*(*mean_prev - savehalfe); + } + + if( savehalfe_hb < *mean_prev_hb/2 ) + { + *mean_prev_hb = 2*(*mean_prev_hb - savehalfe_hb); + } + + *mean_prev = *mean_prev * INV_NUMSF; /* >> LOG2_NUMSF in fixpoint */ + *mean_prev_hb = *mean_prev_hb * INV_NUMSF; /* >> LOG2_NUMSF in fixpoint */ + last2 = (es_mdct[NUMSF-1] + es_mdct[NUMSF-2])/2; + last2_hb = (es_mdct_hb[NUMSF-1] + es_mdct_hb[NUMSF-2])/2; + + if( last2 > *mean_prev ) + { + *mean_prev = last2; + } + + if( last2_hb > *mean_prev_hb ) + { + *mean_prev_hb = last2_hb; + } + } + + return; +} + + +/*--------------------------------------------------------------------------* + * inverse_transform() + * + * Inverse transform from the DCT domain to time domain + *--------------------------------------------------------------------------*/ + +void inverse_transform( + const float *in_mdct, /* i : input MDCT vector */ + float *out, /* o : output vector */ + const short is_transient, /* i : transient flag */ + const short L, /* i : output frame length */ + const short L_inner /* i : length of the transform */ +) +{ + float out_alias[L_FRAME48k]; + float alias[MAX_SEGMENT_LENGTH]; + const float *in_segment; + float *out_segment; + float tmp; + short ta, seg; + short segment_length; + float in_mdct_modif[L_FRAME48k]; + float *in_segment_modif; + const float *win; + + segment_length = L/2; + + if (is_transient) + { + if (L == L_FRAME48k) + { + win = short_window_48kHz; + } + else if (L == L_FRAME32k) + { + win = short_window_32kHz; + } + else if( L == L_FRAME16k ) + { + win = short_window_16kHz; + } + else /* L == L_FRAME8k */ + { + win = short_window_8kHz; + } + + set_f( out_alias, 0.0f, L ); + + in_segment = in_mdct; + in_segment_modif = in_mdct_modif; + + if( L == L_inner ) + { + mvr2r( in_mdct, in_mdct_modif, L ); + } + else if( L > L_inner ) + { + for( seg = 0; seg < NUM_TIME_SWITCHING_BLOCKS; seg++ ) + { + for( ta = 0; ta < L_inner/NUM_TIME_SWITCHING_BLOCKS; ta++ ) + { + *in_segment_modif++ = *in_segment++; + } + + for( ta = 0; ta < (L-L_inner)/NUM_TIME_SWITCHING_BLOCKS; ta++ ) + { + *in_segment_modif++ = 0; + } + } + } + else /* L < L_inner */ + { + for( seg = 0; seg < NUM_TIME_SWITCHING_BLOCKS; seg++ ) + { + for( ta = 0; ta < segment_length/2; ta++ ) + { + *in_segment_modif++ = *in_segment++; + } + in_segment += (L_inner-L)/NUM_TIME_SWITCHING_BLOCKS; + } + } + + out_segment = out_alias - segment_length/4; + in_segment = in_mdct_modif; + + iedct_short( in_segment, alias, segment_length ); + + for( ta = segment_length/4; ta < segment_length/2; ta++ ) + { + out_segment[ta] = alias[ta]; + } + + for( ta = segment_length/2; ta < segment_length; ta++ ) + { + out_segment[ta] = alias[ta] * win[ta]; + } + + out_segment = out_segment + segment_length/2; + in_segment = in_segment + segment_length/2; + + for( seg = 1; seg < NUM_TIME_SWITCHING_BLOCKS-1; seg++ ) + { + iedct_short( in_segment, alias, segment_length ); + + for( ta = 0; ta < segment_length; ta++ ) + { + out_segment[ta] = out_segment[ta] + alias[ta] * win[ta]; + } + + in_segment = in_segment + segment_length/2; + out_segment = out_segment + segment_length/2; + } + + iedct_short( in_segment, alias, segment_length ); + + for (ta = 0; ta < segment_length/2; ta++) + { + out_segment[ta] = out_segment[ta] + alias[ta] * win[ta]; + } + + for (ta = segment_length/2; ta < 3*segment_length/4; ta++) + { + out_segment[ta] = alias[ta]; + } + + for (ta = 0; ta < L/2; ta++) + { + tmp = out_alias[ta]; + out[ta] = out_alias[L-1-ta]; + out[L-1-ta] = tmp; + } + } + else + { + edct( in_mdct, out, L ); + } + + return; +} + diff --git a/src/libs/libevs/lib_com/trans_inv_fx.cpp b/src/libs/libevs/lib_com/trans_inv_fx.cpp deleted file mode 100755 index 91907537..00000000 --- a/src/libs/libevs/lib_com/trans_inv_fx.cpp +++ /dev/null @@ -1,1134 +0,0 @@ -/*==================================================================================== - EVS Codec 3GPP TS26.442 Apr 03, 2018. Version 12.11.0 / 13.6.0 / 14.2.0 - ====================================================================================*/ - -#include "options.h" /* Compilation switches */ -#include "stl.h" -#include "prot_fx.h" /* Function prototypes */ -#include "rom_com_fx.h" /* Function prototypes */ -#include "rom_dec_fx.h" - - - -/*--------------------------------------------------------------------------* - * Local constants - *--------------------------------------------------------------------------*/ - -#define NUMSF 8 -#define NUMSF_M1 (NUMSF-1) -#define NUMSF_M2 (NUMSF-2) -#define NUMSF_S2 (NUMSF/2) -#define LOG2_NUMSF 3 -#define INV_NUMSF (float)0.125 - -/*--------------------------------------------------------------------------* - * preecho_sb() - * - * Time-domain sub-band based pre-echo reduction - *--------------------------------------------------------------------------*/ - -void preecho_sb_fx( - const Word32 brate, /* i Q0 : core bit-rate */ - Word32 *wtda_audio_fx, /* i q_sig32 : imdct signal, used to compute imdct_mem_fx when not 24400 bps */ - Word16 q_sig32, /* i Q value for wtda_audio_fx */ - Word16 *rec_sig_fx, /* i q_sig16 : reconstructed signal, output of the imdct transform */ - Word16 q_sig16, /* i Q value for rec_sig_fx and imdct_mem_fx */ - const Word16 framelength, /* i Q0 : frame length */ - Word16 *memfilt_lb_fx, /* i/o Q0 : memory */ - Word32 *mean_prev_hb_fx, /* i/o Q0 : memory */ - Word16 *smoothmem_fx, /* i/o Q15 : memory */ - Word32 *mean_prev_fx, /* i/o Q0 : memory */ - Word32 *mean_prev_nc_fx, /* i/o Q0 : memory */ - Word16 *wmold_hb_fx, /* i/o Q15 : memory */ - Word16 *prevflag, /* i/o Q0 : flag */ - Word16 *pastpre, /* i/o Q0 : flag */ - const Word16 bwidth /* i Q0 : bandwidth */ -) -{ - Word16 i, j, len3xLp20; - Word16 zcr[9]; /* 0..3 (0..7): zero crossing of the 4 (8) subframes, 4..5: (8..10) zero crossing of the future subframes */ - Word16 maxnzcr[8], cntnzcr; /* max number of samples without zero crossing */ - - Word16 maxind, stind, stind_hb, cnt2, cnt5, adv, advmem; - Word16 ind2, ind3, ind4, ind5, ind6, pluslim, ind2_m1, ind2_sfl, numsf_ind2; - Word16 subframelength, subsubframelength; - Word16 *ptr_fx, *fxptr1, *fxptr2, *fxptr3, *fxptr4, *fxptr5, *fxptr6/*, *fxptr7, *fxptr8*/; - Word32 *fx32ptr1, *fx32ptr4, *fx32ptr5, *fx32ptr6; - Word16 *sptr1, *sptr2, sptr1_loc, sptr2_loc; - Word16 framelength_m1; - Word16 limzcr, limmaxnzcr; - Word16 num_subsubframes, log2_num_subsubframes; - Word16 nb_flag, smooth_len; - Word16 firstnzcr; - Word16 invsmoothlenp1_fx; - Word16 subframelength_s2, subframelength_s34; - Word16 tmp_fx1, tmp_fx2, tmp_fx3; - Word32 tmp_fxL1, tmp_fxL2, tmp_fxL3; - Word32 es_mdct_fx[9]; /* 0..3 (0..7): energy of the 4 (8) subframes, 4..5: (8..10) energy of the future subframes */ - Word32 es_mdct_hb_fx[9]; /* 0..3 (0..7): energy of the 4 (8) subframes, 4..5: (8..10) energy of the future subframes */ - Word32 es_mdct_half_fx[9]; - Word32 es_mdct_quart_fx[9]; - Word32 savehalfe_fx, last2_fx, maxcrit_fx, sum_plus_es_fx, mean_plus_es_fx[65]; - Word32 savehalfe_hb_fx, last2_hb_fx; - Word32 plus_es_mdct_fx[64], max_es_fx, max_es_hb_fx, max_plus_es_mdct_fx; - Word16 imdct_mem_fx[L_FRAME48k]; /* memory of the imdct transform, used in the next frame */ - Word16 rec_sig_lb_fx[960], rec_sig_hb_fx[960]; /* 960 max frame length at 48 kHz */ - - Word16 min_g_fx[13], g_fx, gt_fx[13]; - Word16 min_g_hb_fx[13], gt_hb_fx[13]; - Word16 preechogain_fx[960+PREECHO_SMOOTH_LEN]; - Word16 preechogain_hb_fx[960]; - Word16 pre_g_ch_tab[9]; - Word32 eshbmean2_fx, eshbmean3_fx, sxyhb2_fx, sxylb3_fx; - Word16 wmold_fx; - Word16 lim16_fx, lim32_fx; - Word16 fattnext_fx; - Word16 oldgain_fx, oldgain_hb_fx; - UWord16 tmp_u16; - Word32 mean_prev_hb_fx_loc, mean_prev_nc_fx_loc, mean_prev_fx_loc; /* */ - Word16 q16p1, qmemp1, qtmp; - - q16p1 = add(q_sig16, 1); - qmemp1 = q16p1; - - IF(L_sub(brate, HQ_32k) <= 0) - { - - mean_prev_fx_loc = L_add(*mean_prev_fx, 0); - mean_prev_hb_fx_loc = L_shl(*mean_prev_hb_fx, shl(q_sig16,1)); /*Q0 to q_sig16*/ - mean_prev_nc_fx_loc = L_add(*mean_prev_nc_fx, 0); - framelength_m1 = sub(framelength, 1); - nb_flag = 0; - move16(); - if( sub(bwidth, NB) == 0 ) - { - nb_flag = 1; - move16(); - } - limzcr = 16; - move16(); - smooth_len = 4; - move16(); - invsmoothlenp1_fx = 6554; - move16(); - IF( sub(nb_flag, 1) == 0 ) - { - limzcr = 10; - move16(); - smooth_len = PREECHO_SMOOTH_LEN; - move16(); - invsmoothlenp1_fx = INV_PREECHO_SMOOTH_LENP1_FX; - move16(); - } - - limmaxnzcr = mult(framelength, 1365); /*1/24*/ - num_subsubframes = 8; - move16(); - log2_num_subsubframes = 3; - move16(); - - IF( sub(framelength, L_FRAME8k) == 0 ) - { - num_subsubframes = 4; - move16(); - log2_num_subsubframes = 2; - move16(); - } - - len3xLp20 = mult_r(framelength, 7168); /*7*framelength/32;*/ - /* len3xLp20 = framelength/2-(short)((float)framelength*N_ZERO_MDCT/FRAME_SIZE_MS); in float*/ - - fxptr1 = imdct_mem_fx; - fx32ptr1 = wtda_audio_fx + len3xLp20 - 1; - FOR( i = 0; i < len3xLp20; i++ ) - { - *fxptr1++ = negate(extract_h(L_shl(*fx32ptr1--,15-q_sig32))); - move16(); /*convert to Word16 Q-1 with saturation (saturation not a problem here) */ - } - FOR( i = 0; i < L_shr(framelength, 1); i++ ) - { - *fxptr1++ = negate(extract_h(L_shl(wtda_audio_fx[i], 15-q_sig32))); - move16(); /*convert to Word16 Q-1 with saturation (saturation not a problem here) */ - } - qmemp1 = 0; /*already in q-1*/ - - subframelength = shr(framelength, LOG2_NUMSF); - subsubframelength = shr(subframelength, log2_num_subsubframes); - wmold_fx = *smoothmem_fx; - move16(); - subframelength_s2 = shr(subframelength, 1); - subframelength_s34 = mult(subframelength, 24576); - - cntnzcr = -1; - move16(); - - lim16_fx = 3277; - move16(); - lim32_fx = 328; - move16(); - savehalfe_fx = L_deposit_l(0); - savehalfe_hb_fx = L_deposit_l(0); - - IF( *pastpre == 0 ) - { - /* if past frame mean energies are not known (no preecho_sb in the past frame), limit max attenuation to 1*/ - lim16_fx = 32767; - move16(); - lim32_fx = 32767; - move16(); - } - - *pastpre = 2; - move16(); - fxptr1 = rec_sig_lb_fx; /*q_sig16*/ - fxptr2 = rec_sig_fx; - fxptr3 = rec_sig_fx + 1; - fxptr4 = rec_sig_fx + 2; - - tmp_fxL1 = L_mult(shl(*memfilt_lb_fx, q_sig16), 8192); /* *memfilt_lb_fx in q0 */ - tmp_fxL1 = L_mac(tmp_fxL1, *fxptr3, 8192); - *fxptr1 = mac_r(tmp_fxL1, *fxptr2, 16384); - move16(); - fxptr1++; - - FOR(j = 2; j < framelength; j++) - { - tmp_fxL1 = L_mult(*fxptr2, 8192); - tmp_fxL1 = L_mac(tmp_fxL1, *fxptr4, 8192); - *fxptr1 = mac_r(tmp_fxL1, *fxptr3, 16384); - move16(); - fxptr1++; - fxptr2++; - fxptr3++; - fxptr4++; - } - - tmp_fxL1 = L_mult(*fxptr2, 8192); - *fxptr1 = mac_r(tmp_fxL1, *fxptr3, 16384); - move16(); - fxptr1 = rec_sig_lb_fx; /*q_sig16*/ - fxptr2 = rec_sig_fx; /*q_sig16*/ - fxptr3 = rec_sig_hb_fx; /*q_sig16*/ - - FOR(j = 0; j < framelength; j++) - { - *fxptr3 = sub(*fxptr2, *fxptr1); - move16(); - fxptr1++; - fxptr2++; - fxptr3++; - } - - fxptr2--; - *memfilt_lb_fx = shr(*fxptr2, q_sig16); - move16(); /* *memfilt_lb_fx in q0 */ - - /* energy of low bands 8 present and 1 future sub-frames */ - sptr1 = zcr; - sptr1_loc = 0; - move16(); - sptr2 = maxnzcr; - - fxptr2 = rec_sig_fx; - fxptr3 = rec_sig_hb_fx; - fx32ptr1 = es_mdct_fx; - fx32ptr5 = es_mdct_half_fx; - fx32ptr6 = es_mdct_quart_fx; - fx32ptr4 = es_mdct_hb_fx; - firstnzcr = 0; - move16(); - FOR (j = 0; j < NUMSF; j++) /* 8 present subframes */ - { - tmp_fx2 = sub(j, 1); - tmp_fx1 = shr(*fxptr2, q16p1); /*q-1 to avoisd saturation in energy*/ - tmp_fxL1 = L_mac0(25, tmp_fx1, tmp_fx1); - - tmp_fxL2 = L_mac0(100, *fxptr3, *fxptr3); - - sptr2_loc = 0; - move16(); - - fxptr2++; - fxptr3++; - - FOR (i = 1; i < subframelength; i++) - { - if( sub(i, subframelength_s2) == 0 ) - { - *fx32ptr5 = tmp_fxL1; - move32(); - } - - if( sub(i, subframelength_s34) == 0 ) - { - *fx32ptr6 = tmp_fxL1; - move32(); - } - tmp_fx1 = shr(*fxptr2, q16p1); /*q-1 to avoisd saturation in energy*/ - tmp_fxL1 = L_mac0(tmp_fxL1, tmp_fx1, tmp_fx1); - - tmp_fxL2 = L_mac0(tmp_fxL2, *fxptr3, *fxptr3); - cntnzcr = add(cntnzcr, 1); - IF( L_mult0(*fxptr2, *(fxptr2-1)) <= 0 ) - { - sptr1_loc = add(sptr1_loc, 1); - sptr2_loc = s_max(sptr2_loc, cntnzcr); - - test(); - if( (firstnzcr > 0) && (sub(cntnzcr, maxnzcr[tmp_fx2]) > 0) ) - { - maxnzcr[tmp_fx2] = cntnzcr; - move16(); - } - - firstnzcr = 0; - move16(); - cntnzcr = -1; - move16(); - } - fxptr2++; - fxptr3++; - } - if(sub(j, NUMSF_M1) < 0) - { - cntnzcr = add(cntnzcr, 1); - } - sptr2_loc = s_max(sptr2_loc, cntnzcr); - *fx32ptr4 = tmp_fxL2; - move32(); - fx32ptr4++; - *sptr1 = sptr1_loc; - move16(); - *sptr2 = sptr2_loc; - move16(); - sptr1++; - sptr2++; - - test(); - if( (firstnzcr > 0) && (sub(cntnzcr, maxnzcr[tmp_fx2]) > 0) ) - { - maxnzcr[tmp_fx2] = cntnzcr; - move16(); - } - - sptr1_loc = 0; - move16(); - test(); - firstnzcr = 1; - move16(); - IF((sub(j, NUMSF_M1) < 0) && (L_mult0(*fxptr2, *(fxptr2-1)) <= 0)) /* zcr between 2 subframes */ - { - sptr1_loc = add(sptr1_loc, 1); /* counts for the nexte subframe */ - cntnzcr = -1; - move16(); - firstnzcr = 0; - move16(); - } - - *fx32ptr1 = tmp_fxL1; - move32(); - if( L_sub(*fx32ptr5, L_shr(*fx32ptr1, 1)) < 0 ) - { - tmp_fxL1 = L_shl(L_sub(*fx32ptr1, *fx32ptr5),1); - } - *fx32ptr5 = tmp_fxL1; - move32(); - - fx32ptr1++; - fx32ptr5++; - fx32ptr6++; - } - - fxptr2 = imdct_mem_fx; /* q_sig16 or q-1*/ - j = NUMSF; - move16(); /* one future subframe but 96 samples (not 80) (enough with ALDO window) */ - tmp_fx1 = shr(*fxptr2, qmemp1); /* q-1 shr to avoid overflow in es_mdct_fx*/ - tmp_fxL1 = L_mac0(25, tmp_fx1, tmp_fx1); - - sptr1_loc = 0; - move16(); - fxptr2++; - tmp_fx3 = sub(len3xLp20,1); - FOR (i = 1; i < len3xLp20; i++) - { - tmp_fx1 = shr(*fxptr2, qmemp1); /*q-1 to avoisd saturation in energy*/ - tmp_fxL1 = L_mac0(tmp_fxL1, tmp_fx1, tmp_fx1); - - if(*fxptr2 **(fxptr2-1) <= 0) - { - sptr1_loc = add(sptr1_loc,1); - } - - fxptr2++; - } - *fx32ptr1 = tmp_fxL1; - move32(); - *sptr1 = sptr1_loc; - fxptr2 = imdct_mem_fx; - fxptr3 = imdct_mem_fx + 1; - fxptr4 = imdct_mem_fx + 2; - tmp_fxL1 = L_mult(rec_sig_fx[framelength_m1], -8192); - tmp_fxL1 = L_mac(tmp_fxL1, *fxptr3, -8192); - tmp_fx1 = mac_r(tmp_fxL1, *fxptr2, 16384); - - tmp_fxL2 = L_deposit_l(100); - tmp_fxL2 = L_mac0(tmp_fxL2, tmp_fx1, tmp_fx1); - - FOR(j = 1; j < tmp_fx3; j++) /* tmp_fx3 still contains subframelength*1.2-1 */ - { - tmp_fxL1 = L_mult(*fxptr2, -8192); - tmp_fxL1 = L_mac(tmp_fxL1, *fxptr4, -8192); - tmp_fx1 = mac_r(tmp_fxL1, *fxptr3, 16384); - - tmp_fxL2 = L_mac0(tmp_fxL2, tmp_fx1, tmp_fx1); - fxptr2++; - fxptr3++; - fxptr4++; - } - - tmp_fxL1 = L_mult(*fxptr2, -8192); - tmp_fx1 = mac_r(tmp_fxL1, *fxptr3, 16384); - es_mdct_hb_fx[NUMSF] = L_mac0(tmp_fxL2, tmp_fx1, tmp_fx1); - move32(); - - max_es_hb_fx = L_add(es_mdct_hb_fx[0], 0); /* for memorising the max energy */ - max_es_fx = L_add(es_mdct_fx[0], 0); /* for memorising the max energy */ - maxind = 0; - move16(); - FOR (i = 1; i <= NUMSF; i++) - { - IF (L_sub(es_mdct_hb_fx[i], max_es_hb_fx) >= 0) /* '=' to handle the first window*/ - { - max_es_hb_fx = L_add(es_mdct_hb_fx[i], 0); /* max energy low band, 8 present and 1 future subframes */ - } - - IF (L_sub(es_mdct_fx[i], max_es_fx) >= 0) /* '=' to handle the first window*/ - { - max_es_fx = L_add(es_mdct_fx[i], 0); /* max energy low band, 8 present and 1 future subframes */ - maxind = i; - move16(); - } - } - - cnt2 = cnt5 = 0; - move16(); - move16(); - test(); - if( *prevflag != 0 || L_sub(max_es_fx, L_mult0(subframelength, 2500)) < 0 ) - { - maxind = 0; - move16(); - } - - if( L_sub(max_es_fx, L_shl(mean_prev_fx_loc, 2)) < 0 ) /*OK if saturated*/ - { - maxind = 0; - move16(); - } - *prevflag = 0; - move16(); - - FOR (i = 0; i < maxind; i++) /* only subbands before max energy subband are handled */ - { - g_fx = 32767; - move16(); /* default gain */ - min_g_fx[i] = 32767; - move16(); - min_g_hb_fx[i] = 32767; - move16(); - - Mpy_32_16_ss(es_mdct_half_fx[i], 328, &tmp_fxL1, &tmp_u16); /* 328 for 1/100*/ - Mpy_32_16_ss(es_mdct_half_fx[i], 3277, &tmp_fxL2, &tmp_u16); /* 3277 for 1/10*/ - Mpy_32_16_ss(es_mdct_fx[i], 5461, &tmp_fxL3, &tmp_u16); /* 5461 for 1/6*/ - test(); - test(); - test(); - IF( ( L_sub(tmp_fxL1, L_add(mean_prev_nc_fx_loc,125000)) > 0) || /* less then 20% energy in 3/4 of the subframe -> starting onset in the last quarter */ - (( L_sub(tmp_fxL2, L_add(mean_prev_nc_fx_loc,125000)) > 0) && - ((sub(zcr[i], limzcr) < 0) || ( L_sub(es_mdct_quart_fx[i], tmp_fxL3) < 0)) )) /* already an offset, plosif, do not touch */ - { - maxind = i; - move16(); /* no preecho reduction after the first subframe with gain 1 */ - *prevflag = 1; - move16(); - FOR(j = sub(i,1); j >= 0; j--) - { - if (L_sub(es_mdct_fx[j], L_shr(es_mdct_fx[i],1)) > 0) - { - maxind = j; - move16(); - } - } - } - ELSE - { - IF (L_sub(es_mdct_fx[i], L_shr(max_es_fx, 4)) < 0) - { - g_fx = lim16_fx; - move16(); - cnt5 = add(cnt5,1); - - IF (L_sub(es_mdct_fx[i], L_shr(max_es_fx, 5)) < 0) - { - g_fx = lim32_fx; - move16(); - cnt2 = add(cnt2, 1); - } - - IF(L_sub(mean_prev_fx_loc, es_mdct_fx[i]) < 0) - { - tmp_fx1 = norm_l(es_mdct_fx[i]); - tmp_fxL1 = L_shl(es_mdct_fx[i], tmp_fx1); - tmp_fxL2 = L_shl(mean_prev_fx_loc, tmp_fx1); - tmp_fx1 = round_fx(tmp_fxL1); - tmp_fx2 = round_fx(tmp_fxL2); - tmp_fx3 = div_s(tmp_fx2, tmp_fx1); - min_g_fx[i] = Frac_sqrt(tmp_fx3); - move16(); - } - - IF(L_sub(mean_prev_hb_fx_loc, es_mdct_hb_fx[i]) < 0) - { - tmp_fx1 = norm_l(es_mdct_hb_fx[i]); - tmp_fxL1 = L_shl(es_mdct_hb_fx[i], tmp_fx1); - tmp_fxL2 = L_shl(mean_prev_hb_fx_loc, tmp_fx1); - tmp_fx1 = round_fx(tmp_fxL1); - tmp_fx2 = round_fx(tmp_fxL2); - tmp_fx3 = div_s(tmp_fx2, tmp_fx1); - min_g_hb_fx[i] = Frac_sqrt(tmp_fx3); - move16(); - } - test(); - IF( (sub(zcr[i], limzcr/2) < 0) || (sub(maxnzcr[i], limmaxnzcr) > 0) ) - { - if(sub(min_g_fx[i], 32767) < 0) /* *mean_prev < es_mdct[i]) */ - { - mean_prev_fx_loc = L_add(es_mdct_fx[i], 0); - } - min_g_fx[i] = 32767; - move16(); /* not noise-like, do not touch the amplitude, but may do in HB*/ - } - } - ELSE - { - test(); - if( i > 0 && sub(maxind, NUMSF) < 0 ) - { - *prevflag = 1; - move16(); - } - maxind = i; - move16(); /* no preecho reduction after the first subframe with gain 1*/ - } - } - gt_fx[i] = g_fx; - move16(); - gt_hb_fx[i] = g_fx; - move16(); - } - - FOR ( i = maxind; i <= NUMSF; i++ ) /* also for the first memory subframe */ - { - gt_fx[i] = 32767; - move16(); - min_g_fx[i] = 32767; - move16(); - gt_hb_fx[i] = 32767; - move16(); - min_g_hb_fx[i] = 32767; - move16(); - - } - - ind2 = 0; - move16(); - FOR( i = 0; i < NUMSF; i++ ) - { - if( sub(gt_fx[i], 32767) < 0 ) /*gt not yet limited by min_g*/ - { - ind2 = add(i, 1); /* first subframe with gain = 1 after last gain < 1 --> frame with the attack*/ - } - } - - test(); - if( (sub(wmold_fx, 16384) > 0) && (sub(add(cnt2,cnt5), 2) < 0) ) /* mini either 1 cnt2 (and so also cnt5) or 2 cnt5 */ - { - /* maxind = 0; false alarm, no echo reduction */ - ind2 = 0; - move16(); - } - ind2_m1 = sub(ind2, 1); - ind2_sfl = i_mult(subframelength,ind2); - numsf_ind2 = sub(NUMSF, ind2); - fxptr3 = gt_fx; - fxptr4 = gt_hb_fx; - fxptr5 = min_g_fx; - fxptr6 = min_g_hb_fx; - - fxptr1 = preechogain_fx + smooth_len; - pre_g_ch_tab[0] = smooth_len; - move16(); /*1st after smoothmem*/ - fxptr2 = preechogain_hb_fx; - FOR (i = 0; i < ind2; i++) /* only subbands before max energy subband are handled*/ - { - *fxptr3 = s_max(*fxptr3, *fxptr5); - move16(); - - *fxptr4 = s_max(*fxptr4, *fxptr6); - move16(); - - FOR(j = 0; j < subframelength; j++) - { - *fxptr1 = *fxptr3; - move16(); - *fxptr2 = *fxptr4; - move16(); - fxptr1++; - fxptr2++; - } - pre_g_ch_tab[add(i, 1)] = add(pre_g_ch_tab[i], subframelength); - fxptr3++; - fxptr4++; - fxptr5++; - fxptr6++; - } - - max_plus_es_mdct_fx = L_deposit_l(0); - adv = smooth_len; - move16(); /* samples needed to have near 1 gain after smoothing at the beggining of the attack subframe*/ - advmem = adv; - move16(); - - test(); - test(); - IF( ind2 > 0 || sub(wmold_fx, 32767) < 0 || sub(*wmold_hb_fx, 32767) < 0 ) - { - ptr_fx = imdct_mem_fx; - qtmp = qmemp1; - pluslim = num_subsubframes; - move16(); /* if ind2 == NUMSF */ - IF( numsf_ind2 > 0 ) - { - ptr_fx = rec_sig_fx + ind2_sfl; - qtmp = q16p1; - pluslim = i_mult(numsf_ind2, num_subsubframes); - } - - maxcrit_fx = L_add(mean_prev_nc_fx_loc, 0); - IF( ind2 == 0 ) - { - sum_plus_es_fx = L_add(mean_prev_nc_fx_loc, 0); /* 8 times mean sususb enenrgy (=maxcrit)*/ - pluslim = num_subsubframes; - move16(); - oldgain_fx = wmold_fx; - move16(); - oldgain_hb_fx = *wmold_hb_fx; - move16(); - } - ELSE /* ind2 > 0*/ - { - sum_plus_es_fx = es_mdct_fx[ind2_m1]; - move32(); /* 8 times mean sususb enenrgy (=maxcrit)*/ - oldgain_fx = gt_fx[ind2_m1]; - move16(); - oldgain_hb_fx = gt_hb_fx[ind2_m1]; - move16(); - - tmp_fx1 = mult_r(gt_fx[ind2_m1], gt_fx[ind2_m1]); - Mpy_32_16_ss(es_mdct_fx[ind2_m1], tmp_fx1, &maxcrit_fx, &tmp_u16); - Mpy_32_16_ss(max_es_fx, 410, &tmp_fxL1, &tmp_u16); /* 410 for 1/80*/ - - test(); - if( (L_sub(tmp_fxL1, maxcrit_fx) > 0) && (sub(zcr[ind2], limzcr) > 0) ) - { - maxcrit_fx = L_add(tmp_fxL1, 0); /* still 10 times smaller then mean max_es*/ - } - } - fx32ptr1 = plus_es_mdct_fx; - fx32ptr4 = mean_plus_es_fx + 1; - FOR (j = 0; j < pluslim; j++) /* 8 sub-subframes */ - { - tmp_fxL1 = 100; - move16(); - FOR (i = 0; i < subsubframelength; i++) - { - - tmp_fx1 = shr(*ptr_fx, qtmp); /* q-1, to have same shift as es_mdct_.. */ - tmp_fxL1 = L_mac0(tmp_fxL1, tmp_fx1, tmp_fx1); - ptr_fx++; - } - if( L_sub(tmp_fxL1, max_plus_es_mdct_fx) > 0 ) - { - max_plus_es_mdct_fx = L_add(tmp_fxL1, 0); - } - - sum_plus_es_fx = L_add(sum_plus_es_fx, L_shl(tmp_fxL1, 2)); - *fx32ptr1 = tmp_fxL1; - fx32ptr1++; - Mpy_32_16_ss(sum_plus_es_fx, inv_jp2[j], fx32ptr4, &tmp_u16); /* 410 for 1/80*/ - if( L_sub(*fx32ptr4, maxcrit_fx) < 0) - { - *fx32ptr4 = maxcrit_fx; - move32(); - } - fx32ptr4++; - } - *fx32ptr4 = -1; - move32(); /*mean_plus_es_fx[pluslim] = -1; */ - *mean_plus_es_fx = *plus_es_mdct_fx; - move32(); /* index [0] */ - if( L_sub(*mean_plus_es_fx, maxcrit_fx) < 0) - { - *mean_plus_es_fx = maxcrit_fx; - move32(); - } - - j = 0; - move16(); - WHILE((L_sub(plus_es_mdct_fx[j], mean_plus_es_fx[j]) < 0) && (L_sub(plus_es_mdct_fx[j], max_plus_es_mdct_fx/8) < 0 )) - { - test(); - j = add(j,1); - } - tmp_fx3 = i_mult(j,subsubframelength); - adv = sub(adv, tmp_fx3); - IF( numsf_ind2 > 0 ) /* onset not in future frame */ - { - fxptr1 = preechogain_fx + ind2_sfl+smooth_len; - fxptr2 = preechogain_hb_fx + ind2_sfl; - - FOR (i = 0; i < tmp_fx3; i++) - { - *fxptr1 = oldgain_fx; - move16(); /*keep the gain of the previous subframe*/ - *fxptr2 = oldgain_hb_fx; - move16(); /*keep the gain of the previous subframe*/ - fxptr1++; - fxptr2++; - } - } - } - - IF(ind2>0) - { - /* check increasing energy of preecho by regression last 3 subframes (if possible) */ - ind3 = add(ind2, shr(j, log2_num_subsubframes)); /* return (with rounding) to subframe basis */ - ind4 = sub(ind3, 1); - ind5 = sub(ind3, 2); - ind6 = sub(ind3, 3); - IF( ind4 > 0 ) - { - /* case of 3 points is simply */ - eshbmean2_fx = L_add(es_mdct_hb_fx[ind4], es_mdct_hb_fx[ind5]); - - sxyhb2_fx = L_sub(es_mdct_hb_fx[ind4], es_mdct_hb_fx[ind5]); /* / eshbmean2 * 2; 04042013: division not needed, only sign of sxyhb2 is used*/ - - IF( sub(ind3, 2) > 0 ) - { - tmp_fxL1 = L_add(eshbmean2_fx, es_mdct_hb_fx[ind6]); - Mpy_32_16_ss(tmp_fxL1, 4369, &eshbmean3_fx, &tmp_u16); /*10922 : 1/3*/ - sxylb3_fx = L_sub(es_mdct_fx[ind4], es_mdct_fx[ind6]); /* /eslbmean3 / 2; /2 for 3 points regression calc; 04042013: division not needed, only sign of sxylb3 is used*/ - tmp_fxL1 = L_sub(es_mdct_hb_fx[ind4], es_mdct_hb_fx[ind6]); - test(); - IF ((L_sub(tmp_fxL1, eshbmean3_fx) < 0) || (sxylb3_fx < 0)) - { - ind2 = 0; - move16(); - ind2_sfl = 0; - move16(); - adv = advmem; - move16(); - } - } - ELSE - { - IF (sxyhb2_fx < 0) - { - ind2 = 0; - move16(); - ind2_sfl = 0; - move16(); - adv = advmem; - move16();/* 04042013: small bug corection*/ - } - } - - tmp_fxL1 = L_add(eshbmean2_fx, es_mdct_hb_fx[ind3]); - Mpy_32_16_ss(tmp_fxL1, 4369, &eshbmean3_fx, &tmp_u16); /*10922 : 1/3*/ - - tmp_fxL1 = L_sub(es_mdct_hb_fx[ind3], es_mdct_hb_fx[ind5]); - IF (L_sub(tmp_fxL1, eshbmean3_fx) < 0) - { - ind2 = 0; - move16(); - ind2_sfl = 0; - move16(); - adv = advmem; - move16(); - } - } - } - - ind2_m1 = sub(ind2, 1);/*ind2_m1 needs to be recomputed as ind2 could have changed since*/ - - stind = sub(ind2_sfl, adv); - stind_hb = add(stind, advmem); - if( stind < 0 ) - { - stind = 0; - move16(); - } - - if( stind_hb < 0 ) - { - stind_hb = 0; - move16(); - } - - tmp_fx1 = add(stind, smooth_len); - fxptr1 = preechogain_fx + tmp_fx1; - fxptr2 = preechogain_hb_fx + stind_hb; - - FOR (i = tmp_fx1; i < framelength; i++) /* rest of the gains, without 4 (PREECHO_SMOOTH_LEN) 1 for fadeout */ - { - *(fxptr1++) = 32767; - move16(); - } - pre_g_ch_tab[ind2] = s_min(tmp_fx1, framelength); - move16(); - - FOR (i = stind_hb; i < framelength; i++) /* rest of the gains*/ - { - *(fxptr2++) = 32767; - move16(); - } - - fxptr1 = preechogain_fx; - FOR (i = 0; i < smooth_len; i++) - { - *(fxptr1++) = *smoothmem_fx; - move16(); - } - - fattnext_fx = 32767; - move16(); - if( sub(stind, framelength) > 0 ) - { - fattnext_fx = gt_fx[ind2_m1]; - move16(); - } - - fxptr1 = preechogain_fx + framelength; - FOR (i = 0; i < smooth_len; i++) - { - *(fxptr1++) = fattnext_fx; - move16(); - } - - FOR (i = 0; i <= ind2; i++) - { - tmp_fx1 = pre_g_ch_tab[i]; - move16(); - tmp_fx2 = sub(tmp_fx1, smooth_len); /* any index in the previous subframe*/ - tmp_fx3 = mult_r(sub(preechogain_fx[tmp_fx1], preechogain_fx[tmp_fx2]), invsmoothlenp1_fx);/*step*/ - tmp_fx1 = tmp_fx3; - move16(); /*cumulated step*/ - fxptr1 = preechogain_fx + tmp_fx2; - FOR(j = 0; j < smooth_len; j++) - { - *fxptr1 = add(*fxptr1, tmp_fx1); - move16(); - tmp_fx1 = add(tmp_fx1, tmp_fx3); - fxptr1++; - } - } - - *smoothmem_fx = fattnext_fx; - move16(); - *wmold_hb_fx = preechogain_hb_fx[framelength_m1]; - move16(); - - /* apply gain */ - fxptr1 = preechogain_fx; - fxptr2 = preechogain_hb_fx; - fxptr3 = rec_sig_fx; - fxptr4 = rec_sig_lb_fx; - fxptr5 = rec_sig_hb_fx; - FOR (i = 0; i < framelength; i++) - { - tmp_fxL1 = L_mult(*fxptr4, *fxptr1); - *fxptr3 = mac_r(tmp_fxL1, *fxptr5, *fxptr2); - move16(); - fxptr1++; - fxptr2++; - fxptr3++; - fxptr4++; - fxptr5++; - } - - mean_prev_nc_fx_loc = L_add(es_mdct_fx[0], 0); /* compute mean not corrected by the actual gains*/ - - FOR (i = 1; i < NUMSF; i++) /* all present subbands */ - { - if( sub(i, NUMSF_S2) == 0 ) - { - savehalfe_fx = L_add(mean_prev_nc_fx_loc, 0); - } - mean_prev_nc_fx_loc = L_add(mean_prev_nc_fx_loc, es_mdct_fx[i]); - } - - if( L_sub(savehalfe_fx, L_shr(mean_prev_nc_fx_loc,1) ) < 0 ) - { - mean_prev_nc_fx_loc = L_shl(L_sub(mean_prev_nc_fx_loc, savehalfe_fx), 1); - } - mean_prev_nc_fx_loc = L_shr(mean_prev_nc_fx_loc, 3); /* >> LOG2_NUMSF in fixpoint */ - - FOR( i = 0; i < ind2; i++ ) /* only subbands before max energy subband are handled*/ - { - tmp_fx1 = mult_r(gt_fx[i], gt_fx[i]); - Mpy_32_16_ss(es_mdct_fx[i], tmp_fx1, &es_mdct_fx[i], &tmp_u16); - - tmp_fx1 = mult_r(gt_hb_fx[i], gt_hb_fx[i]); - Mpy_32_16_ss(es_mdct_hb_fx[i], tmp_fx1, &es_mdct_hb_fx[i], &tmp_u16); - - } - - mean_prev_fx_loc = L_shr(es_mdct_fx[0],3); /* compute mean used in next frame to limit gain*/ - mean_prev_hb_fx_loc = L_shr(es_mdct_hb_fx[0],3); /* compute mean used in next frame to limit gain*/ - - FOR (i = 1; i < NUMSF; i++) /* all present subbands */ - { - IF(sub(i, NUMSF_S2) == 0) - { - savehalfe_fx = L_add(mean_prev_fx_loc, 0); - savehalfe_hb_fx = L_add(mean_prev_hb_fx_loc, 0); - } - - mean_prev_fx_loc = L_add(mean_prev_fx_loc, L_shr(es_mdct_fx[i], 3)); - mean_prev_hb_fx_loc = L_add(mean_prev_hb_fx_loc, L_shr(es_mdct_hb_fx[i], 3)); - } - - tmp_fxL1 = L_sub(mean_prev_fx_loc, savehalfe_fx); - if( L_sub(savehalfe_fx, L_shr(mean_prev_fx_loc, 1) ) < 0 ) - { - mean_prev_fx_loc = L_shl(tmp_fxL1, 1); - } - - tmp_fxL1 = L_sub(mean_prev_hb_fx_loc, savehalfe_hb_fx); - if( L_sub(savehalfe_hb_fx, L_shr(mean_prev_hb_fx_loc, 1) ) < 0 ) - { - mean_prev_hb_fx_loc = L_shl(tmp_fxL1, 1); - } - - last2_fx = L_shr(L_add(es_mdct_fx[NUMSF_M1], es_mdct_fx[NUMSF_M2]), 1); - last2_hb_fx = L_shr(L_add(es_mdct_hb_fx[NUMSF_M1], es_mdct_hb_fx[NUMSF_M2]), 1); - - if( L_sub(last2_fx, mean_prev_fx_loc) > 0 ) - { - mean_prev_fx_loc = L_add(last2_fx, 0); - } - - if( L_sub(last2_hb_fx, mean_prev_hb_fx_loc) > 0 ) - { - mean_prev_hb_fx_loc = L_add(last2_hb_fx, 0); - } - *mean_prev_fx = mean_prev_fx_loc; - move32(); - *mean_prev_hb_fx = L_shr(mean_prev_hb_fx_loc, shl(q_sig16,1)); - move32(); /*save in Q0*/ - *mean_prev_nc_fx = mean_prev_nc_fx_loc; - move32(); - } - - return; -} - -/*--------------------------------------------------------------------------* - * Inverse_Transform() - * - * Inverse transform from the DCT domain to time domain - *--------------------------------------------------------------------------*/ - -void Inverse_Transform( - const Word32 *in_mdct, /* i : input MDCT vector */ - Word16 *Q, /* i/o: Q value of input */ - Word32 *out, /* o : output vector */ - const Word16 is_transient, /* i : transient flag */ - const Word16 L, /* i : output frame length */ - const Word16 L_inner /* i : length of the transform */ -) -{ - Word16 ta, seg, tmp16; - Word16 segment_length; - const Word16 *win, *win2; - Word32 out_alias[L_FRAME48k]; - Word32 alias[MAX_SEGMENT_LENGTH]; - Word32 in_mdct_modif[L_FRAME48k]; - Word32 *in_segment_modif; - const Word32 *in_segment; - Word32 *out_segment; - Word16 segment_length_div2, segment_length_div4; - Word16 tmp, q_out; - Word32 L_temp; - /* This value is used to right shift all vectors returned by 'iedct_short_fx()' */ - /* to bring them to a scaling that is equal to the 1st 'Q' returned by the 1st */ - /* call to 'iedct_short_fx()' minus these guard bits. */ -#define N_GUARD_BITS (9+1) /* 9 is enough but we put one extra bit */ - - IF (is_transient) - { - segment_length = shr(L, 1); - segment_length_div2 = shr(L, 2); - segment_length_div4 = shr(L, 3); - - IF (sub(L, L_FRAME48k) == 0) - { - win = short_window_48kHz_fx; - } - ELSE IF (sub(L, L_FRAME32k) == 0) - { - win = short_window_32kHz_fx; - } - ELSE IF( sub(L, L_FRAME16k) == 0 ) - { - win = short_window_16kHz_fx; - } - ELSE /* L == L_FRAME8k */ - { - win = short_window_8kHz_fx; - } - - set32_fx(out_alias, 0, L); - - in_segment = in_mdct; - in_segment_modif = in_mdct_modif; - - tmp16 = sub(L, L_inner); - IF( tmp16 == 0 ) - { - Copy32(in_mdct, in_mdct_modif, L); - } - ELSE IF( tmp16 > 0 ) - { - FOR( seg = 0; seg < NUM_TIME_SWITCHING_BLOCKS; seg++ ) - { - FOR( ta = 0; ta < L_inner; ta += NUM_TIME_SWITCHING_BLOCKS ) - { - *in_segment_modif++ = *in_segment++; - move32(); - } - - FOR( ta = 0; ta < tmp16; ta += NUM_TIME_SWITCHING_BLOCKS ) - { - *in_segment_modif++ = 0L; - move32(); - } - } - } - ELSE /* L < L_inner */ - { - FOR( seg = 0; seg < NUM_TIME_SWITCHING_BLOCKS; seg++ ) - { - FOR( ta = 0; ta < segment_length_div2; ta++ ) - { - *in_segment_modif++ = *in_segment++; - move32(); - } - in_segment += shr(sub(L_inner, L), 2); - move32(); - } - } - - out_segment = out_alias - segment_length_div4; - in_segment = in_mdct_modif; - - tmp = *Q; - /* output of 'iedct_short_fx' has up to 'output frame length'/2 # of Elements */ - iedct_short_fx( in_segment, &tmp, alias, segment_length ); - IF (sub(tmp, N_GUARD_BITS) > 0) - { - q_out = sub(tmp, N_GUARD_BITS); - tmp = sub(tmp, q_out); - } - ELSE - { - q_out = 0; - move16(); - } - - FOR( ta = segment_length_div4; ta < segment_length_div2; ta++ ) - { - out_segment[ta] = L_shr(alias[ta], tmp); - move32(); - } - /* This previous loop fills the output buffer from [0..seg_len_div4-1] */ - - win2 = &win[segment_length_div2]; - FOR( ta = segment_length_div2; ta < segment_length; ta++ ) - { - out_segment[ta] = L_shr(Mult_32_16(alias[ta], *--win2), tmp); - move32(); - } - /* This previous loop fills the output buffer from [seg_len_div4..seg_len-seg_len_div4-1] */ - - out_segment += segment_length_div2; - in_segment += segment_length_div2; - - FOR( seg = 1; seg < NUM_TIME_SWITCHING_BLOCKS-1; seg++ ) - { - tmp = *Q; - move16(); - /* output of 'iedct_short_fx' has up to 'output frame length'/2 # of Elements */ - iedct_short_fx( in_segment, &tmp, alias, segment_length ); - tmp = sub(tmp, q_out); - - FOR( ta = 0; ta < segment_length_div2; ta++ ) - { - out_segment[ta] = L_add(out_segment[ta], L_shr(Mult_32_16(alias[ta], *win2++), tmp)); - move32(); - } - FOR( ; ta < segment_length; ta++ ) - { - out_segment[ta] = L_add(out_segment[ta], L_shr(Mult_32_16(alias[ta], *--win2), tmp)); - move32(); - } - - in_segment += segment_length_div2; - out_segment += segment_length_div2; - } - - tmp = *Q; - move16(); - iedct_short_fx( in_segment, &tmp, alias, segment_length ); - tmp = sub(tmp, q_out); - - FOR (ta = 0; ta < segment_length_div2; ta++) - { - out_segment[ta] = L_add(out_segment[ta], L_shr(Mult_32_16(alias[ta], *win2++), tmp)); - move32(); - } - - seg = add(segment_length_div2, shr(segment_length_div2, 1)); /* seg = 3*segment_length/4 */ - FOR (ta = segment_length_div2; ta < seg; ta++) - { - out_segment[ta] = L_shr(alias[ta], tmp); - move32(); - } - - FOR (ta = 0; ta < segment_length; ta++) - { - L_temp = L_add(out_alias[ta], 0); - out[ta] = out_alias[L-1-ta]; - move32(); - out[L-1-ta] = L_temp; - move32(); - } - - *Q = q_out; - move16(); - } - ELSE - { - edct_fx(in_mdct, out, L, Q); - } -} diff --git a/src/libs/libevs/basic_op/typedef.h b/src/libs/libevs/lib_com/typedef.h old mode 100755 new mode 100644 similarity index 71% rename from src/libs/libevs/basic_op/typedef.h rename to src/libs/libevs/lib_com/typedef.h index 31972be5..a91a94d3 --- a/src/libs/libevs/basic_op/typedef.h +++ b/src/libs/libevs/lib_com/typedef.h @@ -1,3 +1,7 @@ +/*==================================================================================== + EVS Codec 3GPP TS26.443 Nov 13, 2018. Version 12.11.0 / 13.7.0 / 14.3.0 / 15.1.0 + ====================================================================================*/ + /* =========================================================================== File: TYPEDEF.H v.2.3 - 30.Nov.2009 @@ -8,100 +12,83 @@ TYPE DEFINITION PROTOTYPES History: - 26.Jan.00 v1.0 Incorporated to the STL from updated G.723.1/G.729 + 26.Jan.00 v1.0 Incorporated to the STL from updated G.723.1/G.729 basic operator library (based on basic_op.h) 03 Nov 04 v2.0 Incorporation of new 32-bit / 40-bit / control - operators for the ITU-T Standard Tool Library as + operators for the ITU-T Standard Tool Library as described in Geneva, 20-30 January 2004 WP 3/16 Q10/16 TD 11 document and subsequent discussions on the wp3audio@yahoogroups.com email reflector. - March 06 v2.1 Changed to improve portability. + March 06 v2.1 Changed to improve portability. ============================================================================ */ - /*_____________________ | | | Basic types. | |_____________________| */ +#include "options.h" -#ifndef _TYPEDEF_H -#define _TYPEDEF_H "$Id $" +#ifndef TYPEDEF_H +#define TYPEDEF_H - - -#define ORIGINAL_TYPEDEF_H /* Define to get "original" version * - * of typedef.h (this file). */ - #undef ORIGINAL_TYPEDEF_H /* Undefine to get the "new" version * - * of typedef.h (see typedefs.h). */ - - - -#ifdef ORIGINAL_TYPEDEF_H /* * This is the original code from the file typedef.h */ - #if defined(__BORLANDC__) || defined(__WATCOMC__) || defined(_MSC_VER) || defined(__ZTC__) typedef signed char Word8; +typedef unsigned char UWord8; typedef short Word16; -typedef long Word32; -typedef __int64 Word40; +typedef int Word32; typedef unsigned short UWord16; -typedef unsigned long UWord32; +typedef unsigned int UWord32; +typedef __int64 Word40; typedef int Flag; #elif defined(__CYGWIN__) typedef signed char Word8; +typedef unsigned char UWord8; typedef short Word16; -typedef long Word32; -typedef long long Word40; +typedef int Word32; typedef unsigned short UWord16; -typedef unsigned long UWord32; +typedef unsigned int UWord32; +typedef long long Word40; typedef int Flag; #elif defined(__sun) typedef signed char Word8; +typedef unsigned char UWord8; typedef short Word16; typedef long Word32; /*#error "The 40-bit operations have not been tested on __sun : need to define Word40"*/ -typedef long long Word40; typedef unsigned short UWord16; typedef unsigned long UWord32; +typedef long long Word40; typedef int Flag; -#elif defined(__unix__) || defined(__unix) +#elif defined(__unix__) || defined(__unix) || defined(__APPLE__) typedef signed char Word8; +typedef unsigned char UWord8; typedef short Word16; typedef int Word32; -/*#error "The 40-bit operations have not been tested on unix : need to define Word40"*/ -typedef long long Word40; typedef unsigned short UWord16; typedef unsigned int UWord32; +/*#error "The 40-bit operations have not been tested on unix : need to define Word40"*/ +typedef long long Word40; typedef int Flag; #endif - -#else /* ifdef ORIGINAL_TYPEDEF_H */ /* not original typedef.h */ - - - - -/* - * Use (improved) type definition file typdefs.h and add a "Flag" type. - */ -#include "typedefs.h" -typedef int Flag; - - -#endif /* ifdef ORIGINAL_TYPEDEF_H */ - +typedef float Float32; #endif /* ifndef _TYPEDEF_H */ /* end of file */ + + + + diff --git a/src/libs/libevs/lib_com/vlpc_2st_com.cpp b/src/libs/libevs/lib_com/vlpc_2st_com.cpp old mode 100755 new mode 100644 index 05420a48..1c9734a5 --- a/src/libs/libevs/lib_com/vlpc_2st_com.cpp +++ b/src/libs/libevs/lib_com/vlpc_2st_com.cpp @@ -1,61 +1,57 @@ /*==================================================================================== - EVS Codec 3GPP TS26.442 Apr 03, 2018. Version 12.11.0 / 13.6.0 / 14.2.0 + EVS Codec 3GPP TS26.443 Nov 13, 2018. Version 12.11.0 / 13.7.0 / 14.3.0 / 15.1.0 ====================================================================================*/ -#include -#include #include -#include "cnst_fx.h" -#include "prot_fx.h" -#include "stl.h" -#include "control.h" -#include "basop_util.h" +#include +#include "cnst.h" +#include "prot.h" +/*------------------------------------------------------------------* +* lsf_weight_2st() +* +* +*------------------------------------------------------------------*/ + void lsf_weight_2st( - const Word16 *lsfq, /* input: quantized lsf coefficients (14Q1*1.28) */ - Word16 *w, /* output: weighting function (0Q15*1.28) */ - const Word16 mode /* input: operational mode */ + const float *lsfq, + float *w, + int mode, + float sr_core ) { - Word16 i; - Word16 d[M+1], weight; + int i; + float d[M+1]; + float freq_max = sr_core / 2.f; + float freq_div = freq_max / (float)M; /* compute lsf distance */ d[0] = lsfq[0]; - move16(); /*14Q1*1.28*/ - FOR (i=1; i0); + + if (mode == 0) + { + w[i] = (float) (60.0f / (freq_div/sqrt(d[i]*d[i+1]))); /* abs */ + } + else if (mode == 1) + { + w[i] = (float) (65.0f / (freq_div/sqrt(d[i]*d[i+1]))); /* mid */ + } + else + { + w[i] = (float) (63.0f / (freq_div/sqrt(d[i]*d[i+1]))); /* rel2 */ + } } - ELSE IF (sub(mode,1) == 0) - { - weight = W_MODE1; - move16(); /* mid */ - } - - FOR (i=0; i0); */ - - /*w[i] = (weight * sqrt(d[i]*d[i+1])));*/ - - w[i] = mult_r(weight,getSqrtWord32(L_shl(L_mult0(d[i],d[i+1]),6))); - move16(); - } - return; } diff --git a/src/libs/libevs/lib_com/weight.cpp b/src/libs/libevs/lib_com/weight.cpp new file mode 100644 index 00000000..1833733f --- /dev/null +++ b/src/libs/libevs/lib_com/weight.cpp @@ -0,0 +1,334 @@ +/*==================================================================================== + EVS Codec 3GPP TS26.443 Nov 13, 2018. Version 12.11.0 / 13.7.0 / 14.3.0 / 15.1.0 + ====================================================================================*/ + +#include +#include "options.h" +#include "cnst.h" +#include "rom_com.h" +#include "prot.h" + +/*--------------------------------------------------------------------------* + * sfm2mqb() + * + * Map sub-vectors to pbands + *--------------------------------------------------------------------------*/ + +static void sfm2mqb( + short spe[], /* i : sub-vectors */ + short spe2q[], /* o : pbands */ + const short nb_sfm /* i : number of norms */ +) +{ + short tmp, i; + + /* short groups */ + spe2q[0] = spe[0] + 3; + spe2q[1] = spe[1] + 3; + spe2q[2] = spe[2] + 3; + spe2q[3] = spe[3] + 3; + spe2q[4] = spe[4] + 3; + spe2q[5] = spe[5] + 3; + spe2q[6] = spe[6] + 3; + spe2q[7] = spe[7] + 3; + spe2q[8] = spe[8] + 3; + spe2q[9] = spe[9] + 3; + + spe2q[10] = ((spe[10] + spe[11]) >> 1) + 4; + spe2q[11] = ((spe[12] + spe[13]) >> 1) + 4; + spe2q[12] = ((spe[14] + spe[15]) >> 1) + 4; + + spe2q[13] = ((spe[16] + spe[17]) >> 1) + 5; + spe2q[14] = ((spe[18] + spe[19]) >> 1) + 5; + + tmp = 0; + for (i=20; i < 24; i++) + { + tmp += spe[i]; + } + spe2q[15] = (short)(((int)tmp * 8192L) >> 15) + 6; + + tmp = 0; + for (i=24; i < 27; i++) + { + tmp += spe[i]; + } + spe2q[16] = (short)(((int)tmp * 10923L) >> 15) + 6; + + if (nb_sfm > 27) + { + tmp = 0; + for (i=27; i < 30; i++) + { + tmp += spe[i]; + } + spe2q[17] = (short)(((int)tmp * 10923L) >> 15) + 6; + + if (nb_sfm > 30) + { + tmp = 0; + for (i=30; i < 35; i++) + { + tmp += spe[i]; + } + spe2q[18] = (short)(((int)tmp * 6553L) >> 15) + 7; + + tmp = 0; + for (i=35; i < 44; i++) + { + tmp += spe[i]; + } + spe2q[19] = (short)(((int)tmp * 3641L) >> 15) + 8; + } + } + + return; +} + +/*--------------------------------------------------------------------------* + * mqb2sfm() + * + * Map pbands to sub-vectors + *--------------------------------------------------------------------------*/ + +static void mqb2sfm( + short spe2q[], /* i : pbands */ + short spe[], /* o : sub-vectors */ + const short lnb_sfm /* i : number of norms */ +) +{ + short i; + + spe[0] = spe2q[0]; + spe[1] = spe2q[1]; + spe[2] = spe2q[2]; + spe[3] = spe2q[3]; + spe[4] = spe2q[4]; + spe[5] = spe2q[5]; + spe[6] = spe2q[6]; + spe[7] = spe2q[7]; + spe[8] = spe2q[8]; + spe[9] = spe2q[9]; + + spe[10] = spe2q[10]; + spe[11] = spe2q[10]; + + spe[12] = spe2q[11]; + spe[13] = spe2q[11]; + + spe[14] = spe2q[12]; + spe[15] = spe2q[12]; + + spe[16] = spe2q[13]; + spe[17] = spe2q[13]; + + spe[18] = spe2q[14]; + spe[19] = spe2q[14]; + for (i=20; i < 24; i++) + { + spe[i] = spe2q[15]; + } + + for (i=24; i < 27; i++) + { + spe[i] = spe2q[16]; + } + + if (lnb_sfm>SFM_N_STA_8k) + { + for (i=27; i < 30; i++) + { + spe[i] = spe2q[17]; + } + + if (lnb_sfm>SFM_N_STA_10k) + { + for (i=30; i < 35; i++) + { + spe[i] = spe2q[18]; + } + + for (i=35; i < 44; i++) + { + spe[i] = spe2q[19]; + } + } + } + + return; +} + +/*--------------------------------------------------------------------------* + * map_quant_weight() + * + * Calculate the quantization weights + *--------------------------------------------------------------------------*/ + +void map_quant_weight( + const short normqlg2[], /* i : quantized norms */ + short wnorm[], /* o : weighted norm */ + const short is_transient /* i : transient flag */ +) +{ + short sfm; + short tmp16; + short spe2q[NUM_MAP_BANDS]; + short spe[NB_SFM]; + + short spe2q_max; + short spe2q_min; + short norm_max; + short shift; + short sum; + short k; + short lnb_sfm,num_map_bands; + + if (is_transient) + { + lnb_sfm = NB_SFM; + num_map_bands = NUM_MAP_BANDS; + + for (sfm = 0; sfm < lnb_sfm; sfm+=4) + { + sum = 0; + for (k=0; k < 4; k++) + { + sum = sum + normqlg2[sfm+k]; + } + sum = sum >> 2; + for (k=0; k < 4; k++) + { + spe[sfm +k] = sum; + } + } + } + else + { + lnb_sfm = NB_SFM; + num_map_bands = NUM_MAP_BANDS; + + + for (sfm = 0; sfm < lnb_sfm; sfm++) + { + spe[sfm] = normqlg2[sfm]; + } + } + + sfm2mqb(spe, spe2q, lnb_sfm); + + for (sfm = 0; sfm < num_map_bands; sfm++) + { + spe2q[sfm] = spe2q[sfm] - 10; + } + + /* spectral smoothing */ + for (sfm = 1; sfm < num_map_bands; sfm++) + { + tmp16 = spe2q[sfm-1] - 4; + if (spe2q[sfm]= 0 ; sfm--) + { + tmp16 = spe2q[sfm+1] - 8; + if (spe2q[sfm]spe2q[sfm]) + { + spe2q_min = spe2q[sfm]; + } + } + + for (sfm = 0; sfm < num_map_bands; sfm++) + { + spe2q[sfm] = spe2q[sfm] - spe2q_min; + } + + spe2q_max = spe2q_max - spe2q_min; + + if (spe2q_max == 0) + { + norm_max = 0; + } + else + { + if (spe2q_max < 0) + { + spe2q_max = ~spe2q_max; + } + for (norm_max=0; spe2q_max<0x4000; norm_max++) + { + spe2q_max <<= 1; + } + } + + shift = norm_max - 13; + for (sfm = 0; sfm < num_map_bands ; sfm++) + { + if (shift<0) + { + spe2q[sfm] = spe2q[sfm] >> (-shift); + } + else + { + spe2q[sfm] = spe2q[sfm] << shift; + } + } + + mqb2sfm(spe2q,spe,lnb_sfm); + + if (is_transient) + { + for (sfm = 0; sfm < lnb_sfm; sfm+=4) + { + sum = 0; + for (k=0; k < 4; k++) + { + sum = sum + spe[sfm+k]; + } + + sum = sum >> 2; + + for (k=0; k < 4; k++) + { + spe[sfm +k] = sum; + } + } + } + + /* modify the norms for bit-allocation */ + for (sfm = 0; sfm < lnb_sfm ; sfm++) + { + wnorm[sfm] = spe[sfm] + normqlg2[sfm]; + } + + return; +} diff --git a/src/libs/libevs/lib_com/weight_a.cpp b/src/libs/libevs/lib_com/weight_a.cpp new file mode 100644 index 00000000..0ead2cc5 --- /dev/null +++ b/src/libs/libevs/lib_com/weight_a.cpp @@ -0,0 +1,73 @@ +/*==================================================================================== + EVS Codec 3GPP TS26.443 Nov 13, 2018. Version 12.11.0 / 13.7.0 / 14.3.0 / 15.1.0 + ====================================================================================*/ + +#include "options.h" +#include "prot.h" + +/*------------------------------------------------------------------ + * weight_a() + * + * Weighting of LP filter coefficients, ap[i] = a[i] * (gamma^i) + *------------------------------------------------------------------*/ + +void weight_a( + const float *a, /* i : LP filter coefficients */ + float *ap, /* o : weighted LP filter coefficients */ + const float gamma, /* i : weighting factor */ + const short m /* i : order of LP filter */ +) +{ + float f; + short i; + + ap[0] = a[0]; + f = gamma; + + for (i = 1; i <= m; i++) + { + ap[i] = f*a[i]; + f *= gamma; + } + + return; +} + + + +/*------------------------------------------------------------------ + * weight_a_subfr() + * + * Weighting of LP filter coefficients for multiple subframes, + * ap[i] = a[i] * (gamma^i) + *------------------------------------------------------------------*/ + +void weight_a_subfr( + const short nb_subfr, /* i : number of subframes */ + const float *A, /* i : LP filter coefficients */ + float *Aw, /* o : weighted LP filter coefficients */ + const float gamma, /* i : weighting factor */ + const short m /* i : order of LP filter */ +) +{ + short i, j; + float tmp; + + for( j=0; j - -/*------------------------------------------------------------------ - * weight_a_subfr() - * - * Weighting of LP filter coefficients for multiple subframes, - * ap[i] = a[i] * (gamma^i) - *------------------------------------------------------------------*/ - -void weight_a_subfr_fx( - const Word16 nb_subfr, /* i : number of subframes */ - const Word16 *A, /* i : LP filter coefficients Q12 */ - Word16 *Aw, /* o : weighted LP filter coefficients Q12 */ - const Word16 gamma, /* i : weighting factor */ - const Word16 order /* i : order of LP filter */ -) -{ - Word16 k, orderp1; - - /* Smoothing aka spreading aka masking envelope generation */ - orderp1 = add(order,1); - FOR (k=0; k 0) - { - tmp = 0; - move16(); - FOR (i=27; i < 30; i++) - { - tmp = add(tmp,spe[i]); - } - spe2q[17] = add(mult(tmp,10923),6); - move16(); - - IF (sub(nb_sfm, SFM_N_STA_10k) > 0) - { - tmp = 0; - move16(); - FOR (i=30; i < 35; i++) - { - tmp = add(tmp,spe[i]); - } - spe2q[18] = add(mult(tmp,6553),7); - move16(); - - tmp = 0; - move16(); - FOR (i=35; i < 44; i++) - { - tmp = add(tmp,spe[i]); - } - spe2q[19] = add(mult(tmp,3641),8); - move16(); - } - } - - return; -} - -/*--------------------------------------------------------------------------* - * mqb2sfm_fx() - * - * Map pbands to sub-vectors - *--------------------------------------------------------------------------*/ - -static void mqb2sfm_fx( - Word16 spe2q[], /* i : pbands */ - Word16 spe[], /* o : sub-vectors */ - const Word16 lnb_sfm /* i : number of norms */ -) -{ - Word16 i; - - spe[0] = spe2q[0]; - move16(); - spe[1] = spe2q[1]; - move16(); - spe[2] = spe2q[2]; - move16(); - spe[3] = spe2q[3]; - move16(); - spe[4] = spe2q[4]; - move16(); - spe[5] = spe2q[5]; - move16(); - spe[6] = spe2q[6]; - move16(); - spe[7] = spe2q[7]; - move16(); - spe[8] = spe2q[8]; - move16(); - spe[9] = spe2q[9]; - move16(); - - spe[10] = spe2q[10]; - move16(); - spe[11] = spe2q[10]; - move16(); - - spe[12] = spe2q[11]; - move16(); - spe[13] = spe2q[11]; - move16(); - - spe[14] = spe2q[12]; - move16(); - spe[15] = spe2q[12]; - move16(); - - spe[16] = spe2q[13]; - move16(); - spe[17] = spe2q[13]; - move16(); - - spe[18] = spe2q[14]; - move16(); - spe[19] = spe2q[14]; - move16(); - - FOR (i=20; i < 24; i++) - { - spe[i] = spe2q[15]; - move16(); - } - - FOR (i=24; i < 27; i++) - { - spe[i] = spe2q[16]; - move16(); - } - - IF (sub(lnb_sfm, SFM_N_STA_8k) > 0) - { - FOR (i=27; i < 30; i++) - { - spe[i] = spe2q[17]; - move16(); - } - - IF (sub(lnb_sfm, SFM_N_STA_10k) > 0) - { - FOR (i=30; i < 35; i++) - { - spe[i] = spe2q[18]; - move16(); - } - - FOR (i=35; i < 44; i++) - { - spe[i] = spe2q[19]; - move16(); - } - } - } - - return; -} - -/*--------------------------------------------------------------------------* - * map_quant_weight_fx() - * - * Calculate the quantization weights - *--------------------------------------------------------------------------*/ - -void map_quant_weight_fx( - const Word16 normqlg2[], /* i : quantized norms */ - Word16 wnorm[], /* o : weighted norm */ - const Word16 is_transient /* i : transient flag */ -) -{ - Word16 sfm; - Word16 tmp16; - Word16 spe2q[NUM_MAP_BANDS]; - Word16 spe[NB_SFM]; - - Word16 spe2q_max; - Word16 spe2q_min; - Word16 norm_max; - Word16 shift; - Word16 sum; - Word16 k; - Word16 lnb_sfm,num_map_bands; - - lnb_sfm = NB_SFM; - move16(); - num_map_bands = NUM_MAP_BANDS; - move16(); - - IF (is_transient != 0) - { - FOR (sfm = 0; sfm < lnb_sfm; sfm+=4) - { - sum = 0; - move16(); - FOR (k=0; k < 4; k++) - { - sum = add(sum,normqlg2[sfm+k]); - } - sum = shr(sum,2); - - FOR (k=0; k < 4; k++) - { - spe[sfm +k] = sum; - move16(); - } - } - } - ELSE - { - FOR (sfm = 0; sfm < lnb_sfm; sfm++) - { - spe[sfm] = normqlg2[sfm]; - move16(); - } - } - - sfm2mqb_fx(spe, spe2q, lnb_sfm); - - FOR (sfm = 0; sfm < num_map_bands; sfm++) - { - spe2q[sfm] = sub(spe2q[sfm],10); - move16(); - } - - /* spectral smoothing */ - FOR (sfm = 1; sfm < num_map_bands; sfm++) - { - tmp16 = sub(spe2q[sfm-1],4); - spe2q[sfm] = s_max(spe2q[sfm], tmp16); - move16(); - } - - FOR (sfm = num_map_bands-2 ; sfm >= 0 ; sfm--) - { - tmp16 = sub(spe2q[sfm+1],8); - spe2q[sfm] = s_max(spe2q[sfm], tmp16); - move16(); - } - - FOR (sfm = 0; sfm < num_map_bands ; sfm++) - { - spe2q[sfm] = s_max(spe2q[sfm], a_table_fx[sfm]); - move16(); - } - - /* Saturate by the Absolute Threshold of Hearing */ - spe2q_max = -32768; - move16(); - spe2q_min = MAX_16; - move16(); - - FOR (sfm = 0; sfm < num_map_bands ; sfm++) - { - spe2q[sfm] = sub(sfm_width[sfm], spe2q[sfm]); - move16(); - spe2q_max = s_max(spe2q[sfm], spe2q_max); - spe2q_min = s_min(spe2q[sfm], spe2q_min); - } - - FOR (sfm = 0; sfm < num_map_bands ; sfm++) - { - spe2q[sfm] = sub(spe2q[sfm], spe2q_min); - move16(); - } - - spe2q_max = sub(spe2q_max, spe2q_min); - - norm_max = norm_s(spe2q_max); - - shift = sub(norm_max,13); - - FOR (sfm = 0; sfm < num_map_bands ; sfm++) - { - spe2q[sfm] = shl(spe2q[sfm],shift); - move16(); - } - - mqb2sfm_fx(spe2q,spe,lnb_sfm); - - IF (is_transient != 0) - { - FOR (sfm = 0; sfm < lnb_sfm; sfm+=4) - { - sum = 0; - move16(); - FOR (k=0; k < 4; k++) - { - sum = add(sum , spe[sfm+k]); - } - sum = shr(sum,2); - FOR (k=0; k < 4; k++) - { - spe[sfm +k] = sum; - move16(); - } - } - } - - /* modify the norms for bit-allocation */ - FOR (sfm = 0; sfm < lnb_sfm ; sfm++) - { - wnorm[sfm] = add(spe[sfm], normqlg2[sfm]); - move16(); - } - - return; -} - - diff --git a/src/libs/libevs/lib_com/wi.cpp b/src/libs/libevs/lib_com/wi.cpp new file mode 100644 index 00000000..e04e1a06 --- /dev/null +++ b/src/libs/libevs/lib_com/wi.cpp @@ -0,0 +1,2251 @@ +/*==================================================================================== + EVS Codec 3GPP TS26.443 Nov 13, 2018. Version 12.11.0 / 13.7.0 / 14.3.0 / 15.1.0 + ====================================================================================*/ + +#include +#include +#include "cnst.h" +#include "prot.h" +#include "rom_com.h" + + +/*-------------------------------------------------------------------* +* Local constants +* +* +*-------------------------------------------------------------------*/ + +#define WARP_OS_RATE 8 +#define LL 256 +#define LL_OS (WARP_OS_RATE*LL) +#define OSLENGTH 12 +#define CUTFREE_ABS_RANGE 6 +#define CUTFREE_REL_RANGE 0.25 +#define WI_THRESHLD 0.8 +#define WI_SAMPLE_THLD 20 +#define ERB_CBSIZE1 64 +#define ERB_CBSIZE2 64 +#define P_CBSIZE 64 + +#define _POLY1(x, c) ((c)[0] * (x) + (c)[1]) +#define _POLY2(x, c) (_POLY1((x), (c)) * (x) + (c)[2]) +#define _POLY3(x, c) (_POLY2((x), (c)) * (x) + (c)[3]) + + +/*-------------------------------------------------------------------* +* DTFS_new() +* +* DTFS structure initialization. +*-------------------------------------------------------------------*/ + +DTFS_STRUCTURE* DTFS_new( + void +) +{ + short i ; + DTFS_STRUCTURE* dtfs = NULL; + + dtfs = (DTFS_STRUCTURE *) calloc(1,sizeof(DTFS_STRUCTURE)); + dtfs->lag = 0 ; + dtfs->nH=0; + dtfs->nH_4kHz=0; + dtfs->upper_cut_off_freq_of_interest=3300.0; + dtfs->upper_cut_off_freq=4000.0; + for(i=0; ia[i]=dtfs->b[i]=0.0 ; + } + return dtfs; /* o: DTFS structure */ +} + + +/*-------------------------------------------------------------------* +* DTFS_copy() +* +* Copy from one DTFS STRUCTURE to another. +*-------------------------------------------------------------------*/ + +void DTFS_copy( + DTFS_STRUCTURE *Xout, /* o: DTFS structure */ + DTFS_STRUCTURE Xinp /* i: DTFS structure */ +) +{ + short k; + for(k=0; ka[k]=Xinp.a[k]; + } + for(k=0; kb[k]=Xinp.b[k]; + } + Xout->lag=Xinp.lag; + Xout->nH=Xinp.nH; + Xout->nH_4kHz=Xinp.nH_4kHz; + Xout->upper_cut_off_freq_of_interest=Xinp.upper_cut_off_freq_of_interest; + Xout->upper_cut_off_freq=Xinp.upper_cut_off_freq; +} + + +/*-------------------------------------------------------------------* +* DTFS_sub() +* +* Difference of A and B coefficients in cartesian domain. +* Equivalent to time domain subtraction. +*-------------------------------------------------------------------*/ + +DTFS_STRUCTURE DTFS_sub( + DTFS_STRUCTURE X1, /* i: DTFS input 1 */ + DTFS_STRUCTURE X2 /* i: DTFS input 2 */ +) +{ + DTFS_STRUCTURE tmp ; + short i ; + for(i=0; i<=X1.lag/2; i++) + { + tmp.a[i] = X1.a[i] ; + tmp.b[i] = X1.b[i] ; + } + for(i=0; i<=X2.lag/2; i++) + { + tmp.a[i] -= X2.a[i] ; + tmp.b[i] -= X2.b[i] ; + } + tmp.lag = max(X1.lag, X2.lag) ; + tmp.nH=max(X1.nH,X2.nH); + tmp.nH_4kHz=max(X1.nH_4kHz,X2.nH_4kHz); + tmp.upper_cut_off_freq_of_interest=X1.upper_cut_off_freq_of_interest; + tmp.upper_cut_off_freq=X1.upper_cut_off_freq; + return tmp ; +} + +/*-------------------------------------------------------------------* +* DTFS_fast_fs_inv() +* +* DTFS inverse. +*-------------------------------------------------------------------*/ + +void DTFS_fast_fs_inv( + DTFS_STRUCTURE *X1_DTFS, /* i : DTFS */ + float *out, /* o : time domain output */ + int N /* i : number of output samples */ +) +{ + unsigned short i, M_2 = (unsigned short) min(X1_DTFS->lag>>1,X1_DTFS->nH), N_2 = (unsigned short) N>>1 ; + float dbuf[256+1]; /* N can't be > 256 */ + + if (Nlag) + { + N=X1_DTFS->lag; + } + + /* Populate the dbuf array */ + dbuf[1] = X1_DTFS->a[0] ; + dbuf[2] = 0.0 ; + for (i=1; ia[i] * N_2 ; + dbuf[2*i+2] =X1_DTFS->b[i] * N_2 ; + } + + if (N_2 != M_2) + { + dbuf[2*i+1] = X1_DTFS->a[i] * N_2 ; + dbuf[2*i+2] = X1_DTFS->b[i] * N_2 ; + i++; + } + + /* Zero-padding in the frequency domain */ + for ( ; i>1,X2_DTFS.nH_4kHz); k++, freq+=fdiff) + { + if(freq=lband) + { + corr += (X1_DTFS.a[k]*X2_DTFS.a[k] + X1_DTFS.b[k]*X2_DTFS.b[k]); + } + } + tmp = DTFS_getEngy_band (X1_DTFS,lband, hband)*DTFS_getEngy_band(X2_DTFS,lband, hband); + if (tmp==0.0) + { + tmp=0.001; + } + return corr/sqrt(tmp) ; +} + + +/*-------------------------------------------------------------------* +* DTFS_alignment_weight() +* +* Estimate the shift to find the best match between the reference +* DTFS and the test DTFS. +*-------------------------------------------------------------------*/ + +float DTFS_alignment_weight( + DTFS_STRUCTURE refX1_DTFS, /* i : X1 the reference DTFS to keep fixed */ + DTFS_STRUCTURE X2_DTFS, /* i : X2 the test DTFS to shift to find best match */ + float Eshift, /* i : Expected shift - coarse value */ + const float *LPC1, /* i : LPC to filter to find correlation in spch */ + const float *LPC2 /* i : LPC to filter to find correlation in spch */ +) +{ + /* Eshift is w.r.t X2 */ + short k ; + float maxcorr, corr, Adiff, diff, tmp, tmp1, fshift, n, wcorr ; + float pwf = (float) 0.7, tmplpc[M+1] ; + DTFS_STRUCTURE X1_DTFS; + + DTFS_copy (&X1_DTFS,refX1_DTFS); + DTFS_adjustLag (&X1_DTFS,X2_DTFS.lag) ; + DTFS_poleFilter (&X1_DTFS,LPC1,M+1) ; + tmp=1.0; + for(k=0,tmp=1.0; k>1,X2_DTFS.nH_4kHz); k++, tmp+=tmp1) + { + /* Not counting math function cos and sin since they will be implemented as look-up tables */ + corr += (float) ((X1_DTFS.a[k]*X2_DTFS.a[k] + X1_DTFS.b[k]*X2_DTFS.b[k])* cos(tmp)); + corr += (float) ((X1_DTFS.b[k]*X2_DTFS.a[k] - X1_DTFS.a[k]*X2_DTFS.b[k])* sin(tmp)); + } + wcorr=(float) (corr*(1.0f-0.01f* fabs(n-Eshift))) ; + if( wcorr > maxcorr ) + { + fshift = n ; + maxcorr = wcorr ; + } + } + return fshift ; /* o : shift value to shift X2_DTFS by */ +} + + +/*-------------------------------------------------------------------* +* DTFS_alignment_extract() +* +* Alignment for the best match between the reference DTFS and the test DTFS. +*-------------------------------------------------------------------*/ + +float DTFS_alignment_extract( + DTFS_STRUCTURE refX1_DTFS, /* i : X1 the reference DTFS to keep fixed */ + DTFS_STRUCTURE X2_DTFS, /* i : X2 the test DTFS to shift to find best match */ + float Eshift, /* i : Expected shift - coarse value */ + const float *LPC2 /* i : LPC to filter to find correlation in spch */ +) +{ + /* Eshift is w.r.t X2 */ + short k ; + float maxcorr, corr, Adiff, diff, tmp, tmp1, fshift, n ; + float pwf = 0.7f, tmplpc[M+1] ; + DTFS_STRUCTURE X1_DTFS; + + X1_DTFS = refX1_DTFS; /* copy into local copy */ + + DTFS_adjustLag (&X1_DTFS,X2_DTFS.lag) ; + + DTFS_poleFilter (&X1_DTFS,LPC2,M+1) ; + DTFS_poleFilter (&X2_DTFS,LPC2,M+1) ; + + for(k=0,tmp=1.0; k>1,X2_DTFS.nH_4kHz); k++, tmp+=tmp1) + + { + corr += (float) ((X1_DTFS.a[k]*X2_DTFS.a[k] + X1_DTFS.b[k]*X2_DTFS.b[k])* cos(tmp)); + corr += (float) ((X1_DTFS.b[k]*X2_DTFS.a[k] - X1_DTFS.a[k]*X2_DTFS.b[k])* sin(tmp)); + } + + if( corr*(1.0f-0.01f*fabs(n-Eshift) ) > maxcorr ) + { + fshift = n ; + maxcorr = corr ; + } + } + + return fshift ; /* o : shift value to shift X2 by */ +} + + + +/*-------------------------------------------------------------------* +* DTFS_alignment_fine_new() +* +* Shift value for DTFS finer alignment. +*-------------------------------------------------------------------*/ + +float DTFS_alignment_fine_new( + DTFS_STRUCTURE X1_DTFS, /* i : X1 the reference DTFS to keep fixed */ + DTFS_STRUCTURE X2_DTFS, /* i : X2 the test DTFS to shift to find best match */ + float Eshift /* i : Expected shift - coarse value */ +) +{ + short k ; + float maxcorr, corr, Adiff, diff, tmp, tmp1, fshift, n ; + + if (X1_DTFS.lag < X2_DTFS.lag) + { + DTFS_zeroPadd (X2_DTFS.lag,&X1_DTFS) ; + } + maxcorr = (float) -HUGE_VAL; + fshift = Eshift ; + Adiff = 20.0f ; + diff = 1.0f; + for(n=Eshift-Adiff+1; n<=Eshift+Adiff; n+=diff) + { + corr = tmp = 0.0 ; + /* bit-exact optimization - PI2/X2_DTFS.lag should be counted as a single divide outside loops */ + tmp1 = (float) (PI2*n/X2_DTFS.lag) ; + + for(k=0; k<=min(X2_DTFS.lag>>1,X2_DTFS.nH); k++, tmp+=tmp1) + { + corr += (float) ((X1_DTFS.a[k]*X2_DTFS.a[k] + X1_DTFS.b[k]*X2_DTFS.b[k])* cos(tmp)); + corr += (float) ((X1_DTFS.b[k]*X2_DTFS.a[k] - X1_DTFS.a[k]*X2_DTFS.b[k])* sin(tmp)); + } + if( corr*(1.0f-0.01f*fabs(n-Eshift) ) > maxcorr ) + { + fshift = n ; + maxcorr = corr ; + } + } + return fshift ; /* o : shift value to shift X2 by */ +} + + +/*-------------------------------------------------------------------* +* DTFS_alignment_full() +* +* Shift value for DTFS full alignment. +*-------------------------------------------------------------------*/ + +float DTFS_alignment_full( + DTFS_STRUCTURE X1_DTFS, /* i : reference DTFS */ + DTFS_STRUCTURE X2_DTFS, /* i : DTFS to shift */ + int num_steps /* i : resolution */ +) +{ + short k ; + float maxcorr, corr, tmp, tmp1, fshift, n, diff ; + + if (X1_DTFS.lag < X2_DTFS.lag) + { + DTFS_zeroPadd (X2_DTFS.lag,&X1_DTFS) ; + } + + maxcorr = (float) -HUGE_VAL; + /* bit-exact optimization - 1/num_steps can be constant => should be counted as a multiply */ + diff = (float) X2_DTFS.lag / num_steps ; + + for(fshift=n=0.0; n<(float)X2_DTFS.lag; n+=diff) + { + corr = tmp = 0.0f ; + tmp1 = (float) (PI2*n/X2_DTFS.lag) ; + + for(k=0; k<=min(X2_DTFS.lag>>1,X2_DTFS.nH_4kHz); k++, tmp+=tmp1) + + { + corr += (float) ((X1_DTFS.a[k]*X2_DTFS.a[k] + X1_DTFS.b[k]*X2_DTFS.b[k])* cos(tmp)); + corr += (float) ((X1_DTFS.b[k]*X2_DTFS.a[k] - X1_DTFS.a[k]*X2_DTFS.b[k])* sin(tmp)); + } + if(corr>maxcorr) + { + fshift = n ; + maxcorr = corr ; + } + } + return fshift ; +} + + +/*-------------------------------------------------------------------* +* DTFS_phaseShift() +* +* Phase shift the DTFS coefficients. +* ph is the amount of phase shift (between 0 and 2pi), where positive +* value indicates a shift to right, and a negative ph value indicates a +* left shift. +*-------------------------------------------------------------------*/ + +void DTFS_phaseShift( + DTFS_STRUCTURE *X, /* i/o: DTFS to shift */ + float ph /* i : phase to shift */ +) +{ + short k ; + float tmp, tmp2=0.0f ; + for(k=0; k<=min(X->lag>>1,X->nH); k++, tmp2+=ph) + { + tmp = X->a[k] ; + X->a[k] = (float) (tmp*cos(tmp2) - X->b[k]*sin(tmp2)) ; + X->b[k] = (float) (tmp*sin(tmp2) + X->b[k]*cos(tmp2)) ; + } +} + + +/*-------------------------------------------------------------------* + * DTFS_zeroPadd() + * + * Zero-pad the DTFS coefficients. + *-------------------------------------------------------------------*/ + +void DTFS_zeroPadd( + int N, /* i : Target lag */ + DTFS_STRUCTURE *X /* i/o: DTFS */ +) +{ + int i ; + float diff; + if(N == X->lag) + { + return ; + } + for(i=(X->lag>>1)+1; i<=N>>1; i++) + { + X->a[i]=X->b[i]=0.0 ; + } + X->lag = N ; + /* recompute nH for new lag */ + X->nH=(int)floor(X->upper_cut_off_freq/(12800.0/X->lag)); + diff = 12800.0f / X->lag ; + if (X->upper_cut_off_freq-(diff*X->nH)>=diff) + { + X->nH++; + } +} + + +/*-------------------------------------------------------------------* +* DTFS_to_fs() +* +* DTFS to fs conversion. +*-------------------------------------------------------------------*/ + +void DTFS_to_fs( + const float *x, /* i : time domain signal */ + int N, /* i : Length of input vector */ + DTFS_STRUCTURE *X, /* o : DTFS structure with a, b, lag */ + short Fs, /* i : sampling rate */ + short FR_flag /* i : FR flag */ +) +{ + short n; + int nH, k, nH_band, nH_4kHz; + float sum, tmp, diff; + + if (!FR_flag) + { + if (Fs==16000) + { + X->upper_cut_off_freq_of_interest=4000.0; + X->upper_cut_off_freq=6400.0; + X->Fs=INT_FS_12k8; + } + else if (Fs==8000) + { + X->upper_cut_off_freq_of_interest=3300.0; + X->upper_cut_off_freq=4000.0; + X->Fs=INT_FS_12k8; + } + } + else + { + X->upper_cut_off_freq_of_interest=8000.0; + X->upper_cut_off_freq=8000.0; + X->Fs=16000.0; + } + + X->lag = N ; + nH_band=(int)floor(X->upper_cut_off_freq/(12800.0/X->lag)); + + nH_4kHz=(int)floor(4000/(12800.0/X->lag)); + diff = 12800.0f / X->lag ; + if (X->upper_cut_off_freq-(diff*nH_band)>=diff) + { + nH_band++; + } + if (4000-(diff*nH_4kHz)>=diff) + { + nH_4kHz++; + } + /* Number of harmonics excluding the ones at 0 and at pi */ + nH = (N-1) >> 1; + /* The DC component */ + X->a[0] = 0.0 ; + X->b[0] = 0.0 ; + for( n=0; na[0] += x[n] ; + } + X->a[0] /= N ; + + /* Strictly set the DC componet to zero */ + X->a[0] = 0.0 ; + + /* The harmonics excluding the one at pi */ + for( k=1; k<=nH; k++ ) + { + X->a[k] = x[0] ; + X->b[k] = 0.0 ; + sum = tmp = (float) (PI2*k/N) ; + for( n=1; na[k] += (float) (x[n] * cos(sum)) ; + X->b[k] += (float) (x[n] * sin(sum)) ; + } + X->a[k] *= (2.0f/N) ; + X->b[k] *= (2.0f/N) ; + } + + /* The harmonic at 'pi' */ + if( N%2 == 0 ) + { + X->a[k] = 0.0 ; + tmp = 1.0 ; + for( n=0; na[k] += x[n] * tmp ; + } + X->a[k] /= N ; + X->b[k] = 0.0 ; + } + for(k=nH_band+1; k<=min((X->lag>>1),(MAXLAG_WI-1)); k++) + { + X->a[k]=0.0; + X->b[k]=0.0; + } + X->nH=nH_band; + X->nH_4kHz=nH_4kHz; +} + + +/*-------------------------------------------------------------------* +* DTFS_fs_inv() +* +* DTFS Inverse +*-------------------------------------------------------------------*/ + +void DTFS_fs_inv( + DTFS_STRUCTURE *X, /* i : DTFS input */ + float *x, /* o : time domain sig */ + int N, /* i : Output length */ + float ph0 /* i : phase shift applied to the output */ +) +{ + float phase, tmp ; + short k, n ; + + for( n=0; na[0] ; + tmp = phase = (float) (PI2*n/X->lag + ph0) ; + for( k=1; k <=min(X->lag>>1,X->nH); k++, tmp+=phase ) + { + x[n] += (float) (X->a[k]*cos(tmp) + X->b[k]*sin(tmp)) ; + } + } +} + + +/*-------------------------------------------------------------------* +* DTFS_transform() +* +* DTFS transform. +*-------------------------------------------------------------------*/ + +void DTFS_transform( + DTFS_STRUCTURE X, /* i : Starting DTFS to use in WI */ + DTFS_STRUCTURE X2, /* i : Ending DTFS to use in WI */ + const float *phase, /* i : Phase contour */ + float *out, /* o : Output time domain waveform */ + int N, /* i : Number of samples to generate */ + short FR_flag /* i : Flag to indicate called in FR context */ +) +{ + short i, j,j1; + float w, tmp ; + float x1_256[256], x2_256[256]; + float sum1, sum2; + short m, l1, k; + int N1; + float nrg_flag = 0; + float x_r_fx[L_FRAME]; + float temp_w; + + DTFS_STRUCTURE *tmp1_dtfs=DTFS_new(); + DTFS_STRUCTURE *tmp2_dtfs=DTFS_new(); + DTFS_STRUCTURE *tmp3_dtfs=DTFS_new(); + DTFS_copy (tmp1_dtfs,X); + DTFS_copy (tmp2_dtfs,X2); + DTFS_fast_fs_inv (tmp1_dtfs,x1_256,256); + DTFS_fast_fs_inv (tmp2_dtfs,x2_256,256); + tmp = (float) (log(1.0 - WI_THRESHLD) / (X.lag - N)) ; + for(i=0; i X.lag ) + { + /* pre-computed and stored in a table */ + w = (float) (1.0 - exp (- (i+1) * tmp)) ; + } + else + { + /* can be a look-up table */ + w = (float) (i+1) / N ; + } + } + else + { + if (nrg_flag) + { + w = (float) (i+1)/N; + } + else + { + if (N <= tmp2_dtfs->lag) + { + N=tmp2_dtfs->lag+1; + } + + N1 = N - tmp2_dtfs->lag; + if ( i < N1 ) + { + w = (float) (i+1)/N1; + } + else w = 1.0; + } + } + + /* add sinc interpolation of two time domain waveforms at + appropriate phase position */ + j = (LL_OS*10 + (int)rint_new (phase[i]*LL_OS/PI2)) % LL_OS; + + if (j<0) + { + j=0; + } + + k=j%WARP_OS_RATE; + l1=j/WARP_OS_RATE; + + set_f( x_r_fx, 0.0f, L_FRAME ); + + temp_w =( 1 - w ); + + for( j1=0; j1<12; j1++ ) + { + m=(1000*LL+l1-OSLENGTH/2+j1)%LL; + + if( m < 0 ) + { + m=0; + } + + x_r_fx[m] = x1_256[m]* temp_w + x2_256[m] * w; + } + + for(j1=0,sum1=sum2=0.0; j1lag) ; + for( k=0 ; k<=min(X->lag>>1,X->nH) ; k++ ) + { + tmp = tmp2 = k*tmp1 ; + /* Calculate sum1 and sum2 */ + sum1 = 1.0; + sum2 = 0.0; + for( n=0 ; na[k] ; + X->a[k] = tmp * sum1 - X->b[k] * sum2 ; + X->b[k] = X->b[k] * sum1 + tmp * sum2 ; + } +} + +/*-------------------------------------------------------------------* +* DTFS_poleFilter() +* +* DTFS pole filter response. +*-------------------------------------------------------------------*/ + +void DTFS_poleFilter( + DTFS_STRUCTURE *X, /* i/o : DTFS to poleFilter inplace */ + const float *LPC, /* i : LPCs */ + int N /* i : LPC order */ +) +{ + float tmp, tmp1, tmp2, sum1, sum2 ; + short k, n ; + tmp1 = (float) (PI2/X->lag) ; + for( k=0; k<=min(X->lag>>1,X->nH) ; k++ ) + { + tmp = tmp2 = k*tmp1 ; + /* Calculate sum1 and sum2 */ + sum1 = 1.0; + sum2 = 0.0; + for( n=0 ; na[k] ; + tmp2 = sum1 * sum1 + sum2 * sum2 ; + X->a[k] = ( tmp * sum1 + X->b[k] * sum2 ) / tmp2 ; + X->b[k] = ( -tmp * sum2 + X->b[k] * sum1 ) / tmp2 ; + } +} + + +/*-------------------------------------------------------------------* +* DTFS_adjustLag() +* +* Adjust DTFS lag based on a target lag. +*-------------------------------------------------------------------*/ + +void DTFS_adjustLag( + DTFS_STRUCTURE *X_DTFS, /* i/o : DTFS to adjust lag for */ + int N /* i : Target lag */ +) +{ + int k ; + float en,diff ; + if (N==X_DTFS->lag) + { + return ; + } + + if(N>X_DTFS->lag) + { + + DTFS_zeroPadd (N, X_DTFS) ; + } + else + { + en = DTFS_getEngy (*X_DTFS) ; + for(k=(N>>1)+1; k<=min(X_DTFS->lag>>1,X_DTFS->nH); k++) + { + X_DTFS->a[k] = 0.0 ; + X_DTFS->b[k] = 0.0 ; + } + DTFS_setEngy (X_DTFS, en) ; + X_DTFS->lag = N ; + /* recompute nH for new lag */ + X_DTFS->nH=(int)floor(X_DTFS->upper_cut_off_freq/(12800.0/X_DTFS->lag)); + + X_DTFS->nH_4kHz=(int)floor(4000.0/(12800.0/X_DTFS->lag)); + diff = 12800.0f / X_DTFS->lag ; + if (X_DTFS->upper_cut_off_freq-(diff*X_DTFS->nH)>=diff) + { + X_DTFS->nH++; + } + if (4000.0-(diff*X_DTFS->nH_4kHz)>=diff) + { + X_DTFS->nH_4kHz++; + } + } +} + + +/*-------------------------------------------------------------------* +* DTFS_getEngy() +* +* Get DTFS energy. +*-------------------------------------------------------------------*/ + +float DTFS_getEngy( + DTFS_STRUCTURE X /* i : DTFS to compute energy of */ +) +{ + short k; + float en=0.0 ; + for(k=1; k<=min((X.lag-1)>>1,X.nH); k++) + { + en += X.a[k]*X.a[k] + X.b[k]*X.b[k] ; + } + en /= 2.0 ; + en += X.a[0]*X.a[0] ; + if(X.lag%2 == 0) + { + en += X.a[k]*X.a[k] + X.b[k]*X.b[k]; + } + return en ; +} + + +/*-------------------------------------------------------------------* + * DTFS_getEngy_band() + * + * Get DTFS energy in the specified range from lband to hband. + *-------------------------------------------------------------------*/ + +float DTFS_getEngy_band( + DTFS_STRUCTURE X, /* i : DTFS to compute energy of */ + float lband, /* i : low end of band of interest */ + float hband /* i : high end of band of interest */ +) +{ + short k; + float en=0.0f, freq, fdiff=12800.0f/X.lag ; + for(freq=fdiff, k=1; k<=min((X.lag-1)>>1,X.nH_4kHz); k++, freq+=fdiff) + { + if(freq=lband) + { + en += X.a[k]*X.a[k] + X.b[k]*X.b[k] ; + } + } + en /= 2.0 ; + if(lband == 0.0) + { + en += X.a[0]*X.a[0] ; + } + if((X.lag%2 == 0) && (hband == X.upper_cut_off_freq)) + { + en += X.a[k]*X.a[k] + X.b[k]*X.b[k]; + } + return en ; +} + +/*-------------------------------------------------------------------* + * DTFS_getEngy_band_wb() + * + * Get DTFS energy in the specified range from lband to hband. + * This function is different to "DTFS_getEngy_band" as this can calculate + * lband, hband \in [1,6400] where "DTFS_getEngy_band" only upperlimited to + * 4Khz. Possibility: modify ""DTFS_getEngy_band"" and get rid of this + * function. + *-------------------------------------------------------------------*/ + +float DTFS_getEngy_band_wb( + DTFS_STRUCTURE X, /* i : DTFS to compute energy of */ + float lband, /* i : low end of band of interest */ + float hband /* i : high end of band of interest */ +) +{ + short k; + float en=0.0f, freq, fdiff=12800.0f/X.lag ; + for(freq=fdiff, k=1; k<=((X.lag-1)>>1); k++, freq+=fdiff) + { + if(freq=lband) + { + en += X.a[k]*X.a[k] + X.b[k]*X.b[k] ; + } + } + en /= 2.0 ; + if(lband == 0.0) + { + en += X.a[0]*X.a[0] ; + } + if((X.lag%2 == 0) && (hband == X.upper_cut_off_freq)) + { + en += X.a[k]*X.a[k] + X.b[k]*X.b[k]; + } + return en ; +} + + +/*-------------------------------------------------------------------* + * DTFS_setEngy() + * + * Set DTFS energy. + *-------------------------------------------------------------------*/ + +float DTFS_setEngy( + DTFS_STRUCTURE *X_DTFS, /* i/o : DTFS structure to set engy */ + float en2 /* i : Energy to set to */ +) +{ + short k ; + float en1, tmp ; + en1 = DTFS_getEngy (*X_DTFS); + if(en1 == 0.0) + { + return 0.0; + } + tmp = (float) sqrt(en2/en1) ; + for(k=0; k<=min(X_DTFS->lag>>1,X_DTFS->nH); k++) + { + X_DTFS->a[k] *= tmp ; + X_DTFS->b[k] *= tmp ; + } + return en1 ; +} + + +/*-------------------------------------------------------------------* + * DTFS_car2pol() + * + * DTFS cartesian to polar co-ordinates conversion. + *-------------------------------------------------------------------*/ + +void DTFS_car2pol( + DTFS_STRUCTURE *X /* i/o : DTFS structure a, b, lag */ +) +{ + short k ; + float tmp ; + for( k=1 ; k<=min((X->lag-1)>>1,X->nH) ; k++ ) + { + tmp = X->a[k] ; + X->a[k] = (float) (0.5f * sqrt( tmp*tmp + X->b[k]*X->b[k] )) ; + X->b[k] = (float) atan2(X->b[k], tmp) ; + } + if(X->lag%2==0) + { + tmp = X->a[k] ; + X->a[k] = (float) sqrt( tmp*tmp + X->b[k]*X->b[k] ) ; + X->b[k] = (float) atan2 (X->b[k], tmp) ; + } +} + + +/*-------------------------------------------------------------------* + * DTFS_pol2car() + * + * DTFS polar to cartesian co-ordinates conversion. + *-------------------------------------------------------------------*/ + +void DTFS_pol2car( + DTFS_STRUCTURE *X /* i/o : DTFS structure a, b, lag */ +) +{ + short k ; + float tmp ; + for( k=1 ; k<=min((X->lag-1)>>1,X->nH) ; k++ ) + { + tmp = X->b[k] ; + X->b[k] = (float) (2.0f * X->a[k] * sin(tmp)) ; + X->a[k] = (float) (2.0f * X->a[k] * cos(tmp)) ; + } + if(X->lag%2==0) + { + tmp = X->b[k] ; + X->b[k] = (float) (X->a[k] * sin(tmp)) ; + X->a[k] = (float) (X->a[k] * cos(tmp)) ; + } +} + + +/*-------------------------------------------------------------------* +* DTFS_setEngyHarm() +* +* Adjust DTFS energy based on the input target energy. +*-------------------------------------------------------------------*/ + +float DTFS_setEngyHarm( + float f1, /* i : lower band freq of input to control energy */ + float f2, /* i : upper band freq of input to control energy */ + float g1, /* i : lower band freq of output to control energy */ + float g2, /* i : upper band freq of output to control energy */ + float en2, /* i : Target Energy to set the DTFS to */ + DTFS_STRUCTURE *X /* i/o: DTFS to adjust the energy of */ +) +{ + short k, count=0; + float en1=0.0f, tmp, factor, diff=12800.0f/X->lag ; + + if(f1==0.0) + { + en1 += X->a[0]*X->a[0] ; + count ++; + } + for(k=1, tmp=diff; k<=min((X->lag-1)>>1,X->nH); k++, tmp+=diff) + { + if( X->a[k] < EPSILON ) + { + X->a[k]=0; + } + + if(tmp>f1 && tmp<=f2) + { + en1 += X->a[k]*X->a[k] ; + count ++; + } + } + + if (count <= 0.0) + { + count=1; + } + + + en1 /= count ; + + if (en2 < 0.0) + { + en2=0.0; + } + + if(en1>0.0) + { + factor = (float) sqrt(en2/en1) ; + } + else + { + factor = 0.0f ; + } + if(g1==0.0) + { + X->a[k] *= factor ; + } + for(k=1, tmp=diff; k<=min((X->lag-1)>>1,X->nH); k++, tmp+=diff) + { + if(tmp>g1 && tmp<=g2) + { + X->a[k]*=factor ; + } + } + return (float)(en1+1e-20); /* o : Return Input RMS between f1 and f2 before scaling */ +} + + +/*-------------------------------------------------------------------* + * cubicPhase() + * + * Compute coefficients of cubic phase function + *-------------------------------------------------------------------*/ +static +void cubicPhase( + float ph1, /* i : phase offset */ + float ph2, /* i : phase 2 */ + float L1, /* i : previous lag */ + float L2, /* i : current lag */ + int N, /* i : input length */ + float *phOut /* o : cubic phase output */ +) +{ + float coef[4], f1, f2, c1, c2, factor ; + short n ; + double diff; + + N -= (int) L2; + + if (N<=0) + { + N=1; + } + + /* Computation of the coefficients of the cubic phase function */ + f1 = (float) (PI2 / L1) ; + f2 = (float) (PI2 / L2) ; + ph1 = (float) fmod ((double)(ph1), PI2) ; + ph2 = (float) fmod ((double)(ph2), PI2) ; + coef[3] = ph1 ; + coef[2] = f1 ; + factor = (float) (anint (( ph1 - ph2 + 0.5*N*(f2+f1) ) / PI2 )) ; + c1 = f2-f1 ; + c2 = (float) (ph2 - ph1 - N*f1 + PI2 * factor) ; + coef[0] = (N*c1 - 2*c2 ) / (N*N*N) ; + coef[1] = (c1 - 3*N*N*coef[0]) / (2*N) ; + /* Computation of the phase value at each sample point */ + phOut[0] = ph1 ; + for(n=1; n>1,X.nH); i++, freq+=diff) + { + if (!(freq <= erb[num_erb])) + { + freq = erb[num_erb]; + } + + for( ; j 1) + { + out[i] /= count[i] ; + } + } +} + +/*-------------------------------------------------------------------* + * erb_slot() + * + * Estimation of ERB slots. + *-------------------------------------------------------------------*/ +static +void erb_slot( + int lag, /* i : input lag */ + int *out, /* o : ERB slots */ + float *mfreq, /* i : ERB frequencies */ + short num_erb /* i : number of ERBs */ +) +{ + unsigned short i, j ; + float freq, diff ; + short upper_cut_off_freq; + + const float *erb=NULL; + int nH_band; + upper_cut_off_freq=4000; + if (num_erb==NUM_ERB_NB) + { + upper_cut_off_freq=4000; + erb=&(erb_NB[0]); + } + else if (num_erb==NUM_ERB_WB) + { + upper_cut_off_freq=6400; + erb=&(erb_WB[0]); + } + nH_band=(int)floor(upper_cut_off_freq/(12800.0/lag)); + + for(i=0; i=diff) + { + nH_band++; + } + for(i=j=0, freq=0.0; i<=min(lag>>1,nH_band); i++, freq+=diff) + { + + if (!(freq <= erb[num_erb])) + { + freq = erb[num_erb]; + } + + freq = min(freq, upper_cut_off_freq) ; + + for( ; j1) + { + mfreq[j]/=out[j] ; + } + } +} + +/*-------------------------------------------------------------------* + * DTFS_erb_inv() + * + * .DTFS after ERB inverse + *-------------------------------------------------------------------*/ + +void DTFS_erb_inv( + float *in, /* i : ERB inpt */ + int *slot, /* i : ERB slots filled based on lag */ + float *mfreq, /* i : erb frequence edges */ + DTFS_STRUCTURE *X, /* o : DTFS after erb-inv */ + short num_erb /* i : Number of ERB bands */ +) +{ + short i, j, m=0 ; + float diff ; + float freq, f[NUM_ERB_WB+2], amp[NUM_ERB_WB+2] ; + short upper_cut_off_freq = 0; + + const float *erb = NULL; + + if (num_erb==NUM_ERB_NB) + { + upper_cut_off_freq=4000; + erb=&(erb_NB[0]); + } + else if (num_erb==NUM_ERB_WB) + { + upper_cut_off_freq=6400; + erb=&(erb_WB[0]); + } + + f[m]=0.0; + amp[m]=0.0; + m++; + for(i=0; ilag ; + + for(i=0, j=1, freq=0.0; i<=min(X->lag>>1,X->nH); i++, freq+=diff) + { + if (!(freq <= erb[num_erb])) + { + freq = erb[num_erb]; + } + + if (!(m<=num_erb+2)) + { + m = num_erb+2; + } + + if(freq>upper_cut_off_freq) + { + freq=upper_cut_off_freq; + } + for( ; ja[i] = amp[j]*(freq-f[j-1]) + amp[j-1]*(f[j]-freq) ; + if(f[j] != f[j-1]) + { + X->a[i] /= (f[j] - f[j-1]) ; + } + break ; + } + } + + X->a[0] = 0.0f; + } +} + + +/*-------------------------------------------------------------------* + * LPCPowSpect() + * + * LPC power spectrum + *-------------------------------------------------------------------*/ +static +void LPCPowSpect( + const float *freq, /* i : ERB frequencies */ + int Nf, /* i : Number of ERBs */ + const float *LPC, /* i : LPC coefficients */ + int Np, /* i : Number of LPCs */ + float *out /* o : LPC power spectrum */ +) +{ + float w, tmp, Re, Im ; + short i, k ; + + for(k=0; k>1,X.nH_4kHz); k++, freq+=fdiff) + { + if (X.a[k]<0.0) + { + X.a[k]=0.0; + } + + if(freq=lband) + { + Re = 1.0f ; + Im = 0.0f ; + tmp = (float) (PI2*freq/12800.0f) ; + for(i=0, w=tmp; i>1)) + { + en += X.a[k]*X.a[k] / (Re*Re + Im*Im) ; + } + else + { + en += 2.0 * X.a[k]*X.a[k] / (Re*Re + Im*Im) ; + } + } + } + return ((float) en); +} + + +/*-------------------------------------------------------------------* + * erb_diff() + * + * ERB difference + *-------------------------------------------------------------------*/ +static +void erb_diff( + const float *prev_erb, /* i : previous ERB */ + int pl, /* i : previous lag */ + const float *curr_erb, /* i : current ERB */ + int l, /* i : current lag */ + const float *curr_lsp, /* i : current LSP coefficients */ + float *out, /* o : ERB difference */ + int *index, /* i : ERB index */ + short num_erb /* i : Number of ERBs */ +) +{ + short i, j; + int pslot[NUM_ERB_WB], cslot[NUM_ERB_WB], mmseindex ; + float tmp, tmp1, t_prev_erb[NUM_ERB_WB], LPC[M+1], mfreq[NUM_ERB_WB], PowSpect[NUM_ERB_WB], mmse ; + const float (*AmpCB1)[10] = 0; + + if (num_erb==NUM_ERB_NB) + { + AmpCB1=AmpCB1_NB; + } + else if (num_erb==NUM_ERB_WB) + { + AmpCB1=AmpCB1_WB; + + } + + erb_slot (l,cslot,mfreq,num_erb); + erb_slot (pl,pslot,t_prev_erb,num_erb); + for(i=0,tmp=1.0f; il) + { + tmp = t_prev_erb[0] ; + for (i=0; ipl) + { + tmp = t_prev_erb[num_erb-1] ; + for(i=num_erb-1; i>=0; i--) + { + if (pslot[i]!=0) + { + tmp = t_prev_erb[i]; + } + else + { + t_prev_erb[i] = tmp ; + } + } + } + + for(i=0; i=0)) + { + mmseindex=0; + } + + index[0] = mmseindex ; + + /* Second Band Amplitude Search */ + mmse = (float) HUGE_VAL; + mmseindex=-1 ; + for(j=0; j=0)) + { + mmseindex=0; + } + + index[1] = mmseindex; + + return; +} + +/*-------------------------------------------------------------------* + * erb_add() + * + * Add current and past ERB + *-------------------------------------------------------------------*/ +static +void erb_add( + float *curr_erb, /* i/o: current ERB */ + int l, /* i : current lag */ + const float *prev_erb, /* i : previous ERB */ + int pl, /* i : previous lag */ + const int *index, /* i : ERB index */ + short num_erb /* i : number of ERBs */ +) +{ + int i, pslot[NUM_ERB_WB], cslot[NUM_ERB_WB] ; + float tmp, t_prev_erb[NUM_ERB_WB] ; + const float (*AmpCB1)[10] = 0; + + if (num_erb==NUM_ERB_NB) + { + AmpCB1=AmpCB1_NB; + } + else if (num_erb==NUM_ERB_WB) + { + AmpCB1=AmpCB1_WB; + } + erb_slot (l, cslot, t_prev_erb, num_erb); + erb_slot (pl, pslot, t_prev_erb, num_erb); + + for(i=0; il) + { + tmp = t_prev_erb[0] ; + for(i=0; i=0)) + { + pslot[i] = 0; + } + + if(pslot[i]!=0) + { + tmp = t_prev_erb[i] ; + } + else + { + t_prev_erb[i] = tmp ; + } + } + } + else if (l>pl) + { + tmp = t_prev_erb[num_erb-1] ; + for(i=num_erb-1; i>=0; i--) + { + if(pslot[i]!=0) + { + tmp = t_prev_erb[i] ; + } + else + { + t_prev_erb[i] = tmp ; + } + } + } + + for(i=1; i<11; i++) + { + if(cslot[i]!=0) + { + curr_erb[i] = (float) (AmpCB1[index[0]][i-1] + t_prev_erb[i]) ; + curr_erb[i] = max(0.0f, curr_erb[i]); + } + else + { + curr_erb[i] = 0.0; + } + } + for(i=11; i<(num_erb-2); i++) + { + if(cslot[i]!=0) + { + if (num_erb==NUM_ERB_NB) + { + curr_erb[i] = (float)(AmpCB2_NB[index[1]][i-11] + t_prev_erb[i]) ; + curr_erb[i] = max(0.0f, curr_erb[i]); + } + else if (num_erb==NUM_ERB_WB) + { + curr_erb[i] = (float)(AmpCB2_WB[index[1]][i-11] + t_prev_erb[i]) ; + curr_erb[i] = max(0.0f, curr_erb[i]); + } + } + else + { + curr_erb[i] = 0.0f; + } + } +} + +/*-------------------------------------------------------------------* + * DTFS_quant_cw() + * + * DTFS quantization + *-------------------------------------------------------------------*/ + +short DTFS_quant_cw( + DTFS_STRUCTURE *X, /* i/o: DTFS unquant inp, quant out */ + int pl, /* i : Previous lag */ + const float *curr_lpc, /* i : LPC */ + int *POWER_IDX, /* o : Power index */ + int *AMP_IDX, /* o : Amplitude index */ + float *lastLgainE, /* i/o: last frame lowband gain */ + float *lastHgainE, /* i/o: last frame highband gain */ + float *lasterbE /* i/o: last frame ERB vector */ +) +{ + short num_erb = 0; + const float (*PowerCB)[2]=NULL; + float G_CURR_ERB[NUM_ERB_WB]; + float G_A_POWER[2]; + float tmp, w[2], target1, target2, error, minerror ; + float mfreq[NUM_ERB_WB], diff_erb[NUM_ERB_WB], curr_erb[NUM_ERB_WB] ; + int j, slot[NUM_ERB_WB],bincount; + short returnFlag = 1; + float amperror; + + if (X->upper_cut_off_freq==4000.0) + { + num_erb=NUM_ERB_NB; + PowerCB=PowerCB_NB; + } + else if (X->upper_cut_off_freq==6400.0) + { + num_erb=NUM_ERB_WB; + PowerCB=PowerCB_WB; + } + + /* Getting the Speech Domain Energy LOG Ratio */ + w[0] = (float) max(1E-10, log10(DTFS_getSpEngyFromResAmp (*X,0.0,1104.5,curr_lpc))); + w[1] = (float) max(1E-10, log10(DTFS_getSpEngyFromResAmp (*X,1104.5,X->upper_cut_off_freq,curr_lpc))); + tmp = w[0]+w[1] ; + w[0] /= tmp; + w[1] /= tmp; + + /* Power Quantization */ + G_A_POWER[0] = (float) log10(X->lag*DTFS_setEngyHarm (92.0,1104.5,0.0,1104.5,1.0,X)); + G_A_POWER[1] = (float) log10(X->lag*DTFS_setEngyHarm (1104.5,X->upper_cut_off_freq_of_interest,1104.5,X->upper_cut_off_freq,1.0,X)); + target1 = G_A_POWER[0]-*lastLgainE ; + target2 = G_A_POWER[1]-*lastHgainE ; + minerror=(float) HUGE_VAL ; + *POWER_IDX=-1 ; + for(j=0; j=PowerCB[j][0]) && (target2>=PowerCB[j][1])) + { + error*=0.8f ; + } + if(error < minerror) + { + minerror = error ; + *POWER_IDX = j ; + } + } + DTFS_to_erb (*X,curr_erb) ; + + for(j=0; jlag, slot, mfreq,num_erb) ; + /* Amplitude Quantization */ + erb_diff (lasterbE, pl, curr_erb, X->lag, curr_lpc, diff_erb, AMP_IDX,num_erb) ; + + /* Amplitude Dequantization */ + erb_add (curr_erb, X->lag, lasterbE, pl, AMP_IDX,num_erb) ; + curr_erb[0] = curr_erb[1] * 0.3f ; + curr_erb[num_erb-2] = curr_erb[num_erb-3] * 0.3f; + curr_erb[num_erb-1] = 0; + /* Determine if the amplitude quantization is good enough */ + amperror=0.0; + bincount=0; + for(j=1; j<10; j++) + { + if(slot[j]!=0) + { + amperror += (float)(fabs(G_CURR_ERB[j]-curr_erb[j])); + bincount++; + } + } + amperror /= bincount ; + + if((amperror>0.47) && (target1>-0.4)) + { + returnFlag = 0 ; /* Bumping up */ + } + + DTFS_erb_inv (curr_erb, slot, mfreq, X,num_erb) ; + + /* Back up the lasterbE memory after power normalization */ + DTFS_setEngyHarm (92.0,1104.5,0.0,1104.5,1.0,X) ; + DTFS_setEngyHarm (1104.5,X->upper_cut_off_freq_of_interest,1104.5,X->upper_cut_off_freq,1.0,X) ; + + DTFS_to_erb(*X,lasterbE); + + /* Power Dequantization */ + *lastLgainE += (float) PowerCB[*POWER_IDX][0] ; + *lastHgainE += (float) PowerCB[*POWER_IDX][1] ; + target1 = (float) pow(10.0, (double)(*lastLgainE))/X->lag ; + + if (!(target1 >= 0.0)) + { + target1 = 0; + } + + DTFS_setEngyHarm (92.0f,1104.5f,0.0f,1104.5f,target1,X); + target2 = (float) pow(10.0, (double)(*lastHgainE))/X->lag ; + + if (!(target2 >= 0.0)) + { + target2 = 0; + } + + DTFS_setEngyHarm (1104.5,X->upper_cut_off_freq_of_interest,1104.5,X->upper_cut_off_freq,target2,X); + + return returnFlag; /* amp quant performance pass/fail */ +} + +/*-------------------------------------------------------------------* + * DTFS_dequant_cw() + * + * DTFS dequantization + *-------------------------------------------------------------------*/ + +void DTFS_dequant_cw( + int pl, /* i : Previous lag */ + int POWER_IDX, /* i : POWER index */ + const int *AMP_IDX, /* i : Amp Shape index */ + float *lastLgainD, /* i/o: low band last gain */ + float *lastHgainD, /* i/o: high band last gain */ + float *lasterbD, /* i/o: last frame ERB vector */ + DTFS_STRUCTURE *X, /* o : DTFS structure dequantized */ + short num_erb /* i : Number of ERB bands */ +) +{ + float tmp, mfreq[NUM_ERB_WB], curr_erb[NUM_ERB_WB]; + int slot[NUM_ERB_WB] ; + const float (*PowerCB)[2]=NULL; + + if (num_erb==NUM_ERB_NB) + { + PowerCB=PowerCB_NB; + } + else if (num_erb==NUM_ERB_WB) + { + PowerCB=PowerCB_WB; + } + + /* Amplitude Dequantization */ + erb_add (curr_erb, X->lag, lasterbD, pl, AMP_IDX,num_erb) ; + curr_erb[0] = curr_erb[1] * 0.3f ; + curr_erb[num_erb-2] = curr_erb[num_erb-3] * 0.3f; + curr_erb[num_erb-1] = 0; + erb_slot(X->lag, slot, mfreq,num_erb) ; + DTFS_erb_inv(curr_erb, slot, mfreq, X,num_erb) ; + + /* Back up the lasterbD memory after power normalization */ + DTFS_setEngyHarm(92.0,1104.5,0.0,1104.5,1.0,X) ; + DTFS_setEngyHarm(1104.5,X->upper_cut_off_freq_of_interest,1104.5,X->upper_cut_off_freq,1.0,X) ; + DTFS_to_erb(*X,lasterbD) ; + + /* Power Dequantization */ + *lastLgainD += (float) PowerCB[POWER_IDX][0] ; + *lastHgainD += (float) PowerCB[POWER_IDX][1] ; + tmp = (float) pow(10.0, (double)(*lastLgainD))/X->lag ; + + if (!(tmp >= 0.0)) + { + tmp = 0.0; + } + + DTFS_setEngyHarm (92.0,1104.5,0.0,1104.5,tmp,X) ; + tmp = (float) pow(10.0, (double)(*lastHgainD))/X->lag ; + + if (!(tmp >= 0.0)) + { + tmp = 0.0; + } + + DTFS_setEngyHarm (1104.5,X->upper_cut_off_freq_of_interest,1104.5,X->upper_cut_off_freq,tmp,X) ; +} + +/*-------------------------------------------------------------------* + * WI_syn() + * + * Synthesis using waveform interpolation + *-------------------------------------------------------------------*/ + +void WIsyn( + DTFS_STRUCTURE PREVCW, /* i : Prev frame DTFS */ + DTFS_STRUCTURE *CURR_CW_DTFS, /* i/o: Curr frame DTFS */ + const float *curr_lpc, /* i : LPC */ + float *ph_offset, /* i/o: Phase offset to line up at end of frame */ + float *out, /* o : Waveform Interpolated time domain signal */ + int N, /* i : Number of output samples to generate */ + int FR_flag /* i : called for post-smoothing in FR */ +) +{ + DTFS_STRUCTURE *CURRCW_DTFS; + unsigned short I=1, flag=0; + float alignment, tmp, *phase; + + phase = (float *) calloc(N,sizeof(float)); + + CURRCW_DTFS = DTFS_new(); + + DTFS_copy (CURRCW_DTFS,*CURR_CW_DTFS); + + /* Calculating the expected alignment shift */ + alignment = (float) (*ph_offset /PI2 * PREVCW.lag) ; + if(flag==1) + { + alignment *= I ; + } + /* Calculating the expected alignment shift */ + tmp = (float) fmod((N%((PREVCW.lag+CURRCW_DTFS->lag)>>1) + alignment), CURRCW_DTFS->lag) ; + + /* Compute the alignment shift */ + if (FR_flag==0) + { + alignment = DTFS_alignment_weight (PREVCW, *CURRCW_DTFS, tmp, curr_lpc, curr_lpc) ; + } + else /* FR case */ + { + alignment = DTFS_alignment_full(PREVCW, *CURRCW_DTFS, CURRCW_DTFS->lag*2); + } + + tmp = (float) (PI2*alignment/CURRCW_DTFS->lag) ; + DTFS_phaseShift (CURRCW_DTFS,tmp) ; + DTFS_phaseShift (CURR_CW_DTFS,(float) (PI2*alignment/CURR_CW_DTFS->lag)) ; + + /* Compute the cubic phase track and transform to 1-D signal */ + cubicPhase (*ph_offset, tmp, (float) PREVCW.lag , (float) CURRCW_DTFS->lag, N, phase) ; + + if (FR_flag==0) + { + DTFS_transform (PREVCW, *CURRCW_DTFS, phase, out, N,0) ; + } + else + { + DTFS_transform (PREVCW, *CURRCW_DTFS, phase, out, N,1) ; + } + + /* Adjust the phase offset and wrap it between 0 and 2pi */ + if( flag == 2 ) + { + tmp *= I ; + } + *ph_offset = (float) fmod ((double)(tmp), PI2) ; + + free(phase) ; + free(CURRCW_DTFS); +} + + +/*-------------------------------------------------------------------* + * ppp_extract_pitch_period() + * + * Pitch period extraction + *-------------------------------------------------------------------*/ + +short ppp_extract_pitch_period( + const float *in, /* i : input residual */ + float *out, /* o : output residual */ + int l, /* i : lag */ + short *out_of_bound /* o : out of bound flag */ +) +{ + int i,j,k; + int spike=0,range; + float max1=0.0; + const float *ptr=in+L_FRAME-l; + float en1=0.0, en2=0.0, tmp; + short spike_near_edge=0; + float pos_max,neg_max; + int spike_pos=0,spike_neg=0; + float x; + + pos_max = (float) -HUGE_VAL; + neg_max = 0.0; + *out_of_bound = 0; + + for(i=0; imax1) + { + max1=x; + spike=i; + } + en1 += ptr[i]*ptr[i] ; + } + + if (ptr[spike]>0) + { + spike_pos=spike; + + /* search for neg spike around the pos spike */ + for(j=spike-10; jpos_max) + { + pos_max=ptr[k]; + spike_pos=k; + } + } + } + if (((l-1-max(spike_pos,spike_neg))<=2) ||(min(spike_pos,spike_neg)<=2)) + { + *out_of_bound=1; + return spike_near_edge; + } + range=(int)anint (max(CUTFREE_REL_RANGE*l,CUTFREE_ABS_RANGE)); + if((spike-range<0) || (spike+range>=l)) + { + /* need to grab from one lag before + ensure that there is no array bound read */ + if(L_FRAME -l -l < 0) + { + *out_of_bound=1; + return spike_near_edge; + } + spike_near_edge=1; + } + if(spike-range<0) + { + for(i=0; i=l) + { + for(i=0; i=in) + { + for(ptr-=l; i= 0) + { + if(tmp>maxPosEn) + { + maxPosEn = tmp ; + } + } + else + { + if(tmp>maxNegEn) + { + maxNegEn = tmp ; + } + } + sum += tmp ; + } + + + if (sum==0.0) + { + *pos = 0.0f; + *neg = 0.0f; + } + else + { + + if (maxPosEn==0.0) + { + *pos=0.0; + } + else + { + *pos = (float) sqrt(maxPosEn*X.lag/sum); + } + + if (maxPosEn==0.0) + { + *neg=0.0; + } + else + { + *neg = (float) sqrt(maxNegEn*X.lag/sum); + } + } +} + diff --git a/src/libs/libevs/lib_com/wi_fx.cpp b/src/libs/libevs/lib_com/wi_fx.cpp deleted file mode 100755 index 49254c6c..00000000 --- a/src/libs/libevs/lib_com/wi_fx.cpp +++ /dev/null @@ -1,5354 +0,0 @@ -/*==================================================================================== - EVS Codec 3GPP TS26.442 Apr 03, 2018. Version 12.11.0 / 13.6.0 / 14.2.0 - ====================================================================================*/ - -#include -#include - -#include "options.h" -#include "prot_fx.h" -#include "rom_com_fx.h" -#include "log2.h" -#include "stl.h" - -#define WARP_OS_RATE 8 -#define LL 256 -#define LL_OS (WARP_OS_RATE*LL) -#define OSLENGTH 12 -#define CUTFREE_ABS_RANGE 6 -#define CUTFREE_REL_RANGE 0.25 -#define CUTFREE_ABS_RANGE_Q3 48 -#define CUTFREE_REL_RANGE_Q2 1 -#define WI_THRESHLD 0.8 -#define WI_SAMPLE_THLD 20 -#define ERB_CBSIZE1 64 -#define ERB_CBSIZE2 64 -#define P_CBSIZE 64 - -/*#define _POLY1(x, c) ((c)[0] * (x) + (c)[1]) */ -/*#define _POLY2(x, c) (_POLY1((x), (c)) * (x) + (c)[2]) */ -/*#define _POLY3(x, c) (_POLY2((x), (c)) * (x) + (c)[3]) */ - -/*-------------------------------------------------------------------* -* DTFS_new_fx() -* -* DTFS structure initialization. -*-------------------------------------------------------------------*/ -DTFS_STRUCTURE_FX* DTFS_new_fx(void) -{ - - Word16 i ; - - DTFS_STRUCTURE_FX* dtfs_fx = NULL; - dtfs_fx = (DTFS_STRUCTURE_FX *) calloc(1,sizeof(DTFS_STRUCTURE_FX)); - dtfs_fx->lag_fx = 0 ; - move16(); - dtfs_fx->nH_fx=0; - move16(); - dtfs_fx->nH_4kHz_fx=0; - move16(); - dtfs_fx->upper_cut_off_freq_of_interest_fx=3300; - move16(); - dtfs_fx->upper_cut_off_freq_fx=4000; - move16(); - dtfs_fx->Q = 0; - move16(); - - FOR(i=0; ia_fx[i] = 0; - move16(); - dtfs_fx->b_fx[i] = 0; - move16(); - } - - return dtfs_fx; /* o: DTFS structure_fx */ - -} -/*-------------------------------------------------------------------* -* DTFS_copy_fx() -* -* Copy from one DTFS STRUCTURE to another. -*-------------------------------------------------------------------*/ - -void DTFS_copy_fx( - DTFS_STRUCTURE_FX *Xout_fx, /* o: DTFS structure */ - DTFS_STRUCTURE_FX Xinp_fx /* i: DTFS structure */ -) - -{ - - Word16 k; - FOR(k=0; ka_fx[k]=Xinp_fx.a_fx[k]; - move16(); - } - - FOR(k=0; kb_fx[k]=Xinp_fx.b_fx[k]; - move16(); - } - - Xout_fx->lag_fx=Xinp_fx.lag_fx; - move16(); - Xout_fx->nH_fx=Xinp_fx.nH_fx; - move16(); - Xout_fx->nH_4kHz_fx=Xinp_fx.nH_4kHz_fx; - move16(); - Xout_fx->upper_cut_off_freq_of_interest_fx=Xinp_fx.upper_cut_off_freq_of_interest_fx; - move16(); - Xout_fx->upper_cut_off_freq_fx=Xinp_fx.upper_cut_off_freq_fx; - move16(); - Xout_fx->Q = Xinp_fx.Q; - move16(); -} - - -/*-------------------------------------------------------------------* -* DTFS_sub_fx() -* -* Subtract one DTFS STRUCTURE from another. -*-------------------------------------------------------------------*/ -DTFS_STRUCTURE_FX DTFS_sub_fx( - - DTFS_STRUCTURE_FX X1, /* i: DTFS input 1 */ - DTFS_STRUCTURE_FX X2 /* i: DTFS input 2 */ -) -{ - DTFS_STRUCTURE_FX tmp ; - Word16 i ,sft, tmp_loop; - sft = sub(X1.Q,X2.Q); - - IF(sft>0) - { - tmp_loop = shr(X1.lag_fx,1); - FOR(i=0; i<=tmp_loop; i++) - { - - tmp.a_fx[i] = sub(shr(X1.a_fx[i],sft),X2.a_fx[i]); - move16(); - tmp.b_fx[i] = sub(shr(X1.b_fx[i],sft),X2.b_fx[i]); - move16(); - } - tmp.Q = X2.Q; - move16(); - } - ELSE - { - tmp_loop = shr(X1.lag_fx,1); - FOR(i=0; i<=tmp_loop; i++) - { - - tmp.a_fx[i] = sub(X1.a_fx[i],shl(X2.a_fx[i],sft)); - move16(); - tmp.b_fx[i] = sub(X1.b_fx[i],shl(X2.b_fx[i],sft)); - move16(); - } - tmp.Q = X1.Q; - move16(); - } - tmp.lag_fx = s_max(X1.lag_fx, X2.lag_fx) ; - tmp.nH_fx=s_max(X1.nH_fx,X2.nH_fx); - tmp.nH_4kHz_fx=s_max(X1.nH_4kHz_fx,X2.nH_4kHz_fx); - tmp.upper_cut_off_freq_of_interest_fx=X1.upper_cut_off_freq_of_interest_fx; - move16(); - tmp.upper_cut_off_freq_fx=X1.upper_cut_off_freq_fx; - move16(); - return tmp ; -} - -void DTFS_fast_fs_inv_fx( DTFS_STRUCTURE_FX *X_fx,Word16 *out_fx, Word16 N_fx, Word16 LOG2N) -{ - Word16 i, M_2, N_2, s; - Word16 dbuf_fx[256+1]; - - M_2=s_min(shr(X_fx->lag_fx,1),X_fx->nH_fx); - move16(); - N_2=shr(N_fx,1); - s=negate(X_fx->Q); - - dbuf_fx[0]=X_fx->a_fx[0]; - move16(); - dbuf_fx[1]=0; - move16(); - - FOR (i=1; i<=M_2; i++) - { - dbuf_fx[2*i]=shl_r(X_fx->a_fx[i],s); - move16(); - dbuf_fx[2*i+1]=shl_r(X_fx->b_fx[i],s); - move16(); - } - - FOR ( ; i=0) - { - BREAK; - } - } - lk = k; - FOR (k=0; k<=HalfLag; k++) - { - freq_fx = L_mult(k, 12800); - IF (L_sub(freq_fx, L_hband)>=0) - { - BREAK; - } - } - hk = k; - move16(); - - FOR (k=lk; k0) - { - Result = L_add(L_tmp, 0); - } - ELSE - { - Result = L_negate(L_tmp); - } - *Qout = sub(30,exp); - - } - return Result; -} - -/*===================================================================*/ -/* FUNCTION : DTFS_alignment_weight_fx () */ -/*-------------------------------------------------------------------*/ -/* PURPOSE : search for alignment */ -/*-------------------------------------------------------------------*/ -/* INPUT ARGUMENTS : */ -/* _ (struct DTFS_STRUCTURE_FX) X1_fx : a/b in X1.Q */ -/* _ (struct DTFS_STRUCTURE_FX) X2_fx : a/b in X2.Q */ -/* _ (Word16) Eshift: Q7 */ -/* _ (Word16 *) LPC1: lpc coefficients. Q12 */ -/* _ (Word16 *) LPC2: lpc coefficients. Q12 */ -/* _ (Word16 *) S_fx: sin(2pi*n/(4*lag)) table, Q15 */ -/* _ (Word16 *) C_fx: cos(2pi*n/(4*lag)) table, Q15 */ -/*-------------------------------------------------------------------*/ -/* OUTPUT ARGUMENTS : */ -/* _ (Word16) fshift_fx : Q7 */ -/*-------------------------------------------------------------------*/ -/* INPUT/OUTPUT ARGUMENTS : */ -/* _ None */ -/*-------------------------------------------------------------------*/ -/* RETURN ARGUMENTS : _ None. */ -/*-------------------------------------------------------------------*/ -/* CALLED FROM : TX/RX */ -/*===================================================================*/ - -Word16 DTFS_alignment_weight_fx( DTFS_STRUCTURE_FX *X_fx, DTFS_STRUCTURE_FX X2, Word16 Eshift, const Word16 *LPC1, const Word16 *LPC2, Word16 *S_fx, Word16 *C_fx, Word16 *pf_temp1,Word16 *pf_temp2, Word16 *pf_temp, Word16 *pf_n2) -{ - /* Eshift is w.r.t X2 */ - Word16 k, HalfLag, start, end, ab1[MAXLAG_WI], ab2[MAXLAG_WI] ; - Word32 corr_fx; - Word32 maxcorr_fx, wcorr_fx, diff_corr; - DTFS_STRUCTURE_FX X1 ; - Word16 temp, temp1, Qcorr, Qmaxcorr, inv_lag, n_fx, diff_fx, fshift_fx, Adiff_fx; - Word16 tmplpc_fx[M+1]; - Word16 exp,tmp; - Word32 L_tmp; - - diff_fx = 0; /* to avoid compilation warnings */ - - - DTFS_copy_fx(&X1,*X_fx);/* X1 = *X_fx ; */ - DTFS_adjustLag_fx(&X1,X2.lag_fx) ; - - /* PORTING: Handling the functions with variable no. of arguments */ - poleFilter_setup_fx(LPC1, add(M,1), X1,S_fx,C_fx,pf_temp1,pf_temp2,pf_temp,pf_n2); - DTFS_poleFilter_fx_9(&X1, pf_temp1, pf_temp2, pf_temp, pf_n2); - FOR (k=0; k= 0) - { - diff_fx = 64; - move16(); /* Q7 of 0.5 */ - } - - HalfLag = s_min(shr(X2.lag_fx, 1),X2.nH_4kHz_fx); - exp = norm_s(X2.lag_fx); - tmp = div_s(shl(1,sub(14,exp)),X2.lag_fx); - L_tmp = L_shl(tmp,exp+6); - inv_lag = round_fx(L_tmp); - - FOR (k=0; k<=HalfLag; k++) - { - ab1[k] = round_fx(L_mac0(L_mult0(X1.a_fx[k], X2.a_fx[k]), X1.b_fx[k], X2.b_fx[k])); /* Q(-15) */ - ab2[k] = round_fx(L_msu0(L_mult0(X1.a_fx[k], X2.b_fx[k]), X1.b_fx[k], X2.a_fx[k])); /* Q(-15) */ - } - - start=sub(Eshift, Adiff_fx); - end=add(Eshift, Adiff_fx); - - FOR (n_fx=start; n_fx<=end; n_fx+=diff_fx) - { - /* Q7 */ - corr_fx = L_deposit_l(0); - temp = 0; - move16(); - temp1 = round_fx(L_shr(L_mult(inv_lag, n_fx), 2)); /* Q(19+7+1-2-16)=Q9 of n/X2.lag */ - - if (temp1<0) - { - temp1=add(temp1, 0x200); /* avoid negative, 0x200 is Q9 of 1 ( 2*pi ) */ - } - - FOR (k=0; k<=HalfLag; k++) - { - corr_fx = L_mac0(corr_fx, ab1[k], cos_table[s_and(temp,511)]); - corr_fx = L_mac0(corr_fx, ab2[k], cos_table[s_and((temp+128),511)]); - temp = add(temp, temp1); - } - temp = sub(8192, mult_r(20972, abs_s(sub(n_fx, Eshift)))); /* Q13, 20972 = Q21 of 0.01. */ - Qcorr = norm_l(corr_fx); - if(corr_fx==0) - { - Qcorr = 31; - move16(); - } - - temp1 = round_fx((Word32)L_shl(corr_fx, Qcorr)); /* Q(Qcorr-16) */ - wcorr_fx = L_mult(temp1, shl(temp, 2)); /* Q(Qcorr-16+13+2+1)=Q(Qcorr) */ - - IF (sub(Qmaxcorr,Qcorr) >= 0) - { - diff_corr = L_sub(wcorr_fx, L_shl(maxcorr_fx, sub(Qcorr, Qmaxcorr))); /* Qcorr */ - } - ELSE - { - diff_corr = L_sub(L_shl(wcorr_fx, sub(Qmaxcorr, Qcorr)), maxcorr_fx); /* Qmaxcorr */ - } - - if ( diff_corr > 0 ) - { - fshift_fx = n_fx ; - move16(); - maxcorr_fx = L_add(wcorr_fx, 0); - Qmaxcorr = Qcorr; - move16(); - } - } - - return fshift_fx ; -} -/*===================================================================*/ -/* FUNCTION : DTFS_alignment_extract_td_fx () */ -/*-------------------------------------------------------------------*/ -/* PURPOSE : search for alignment in time domain */ -/*-------------------------------------------------------------------*/ -/* INPUT ARGUMENTS : */ -/* _ (Word16 *) x1: Q? */ -/* _ (Word16 *) x2: Q? */ -/*-------------------------------------------------------------------*/ -/* OUTPUT ARGUMENTS : */ -/* _ (Word16) lag : Q0 */ -/*-------------------------------------------------------------------*/ -/* INPUT/OUTPUT ARGUMENTS : */ -/* _ None */ -/*-------------------------------------------------------------------*/ -/* RETURN ARGUMENTS : _ (Word16 *) idx: Q0 */ -/*-------------------------------------------------------------------*/ -/* CALLED FROM : TX */ -/*===================================================================*/ - -Word16 DTFS_alignment_extract_td_fx(Word16 *x1, Word16 *x2, Word16 lag) -{ - Word16 j, k, idx, Adiff_fx ; - Word32 maxcorr, corr; - - maxcorr = L_add(MIN_32, 0); - Adiff_fx = (Word16)(s_max(4, shr(lag, 3))); - - idx=0; - move16(); - FOR ( j=negate(Adiff_fx); j<=Adiff_fx; j++) - { - corr=L_deposit_l(0); - FOR (k=0; k0) - { - idx = j ; - move16(); - maxcorr = L_add(corr, 0); - } - } - return idx; -} -/*===================================================================*/ -/* FUNCTION : DTFS_alignment_fine_new_fx () */ -/*-------------------------------------------------------------------*/ -/* PURPOSE : search for alignment */ -/*-------------------------------------------------------------------*/ -/* INPUT ARGUMENTS : */ -/* _ (struct DTFS_fx) X1_fx : a/b in X1_fx.Q */ -/* _ (struct DTFS_fx) X2_fx : a/b in X2_fx.Q */ -/* _ (Word16 *) S_fx: sin(2pi*n/(4*lag)) table, Q15 */ -/* _ (Word16 *) C_fx: cos(2pi*n/(4*lag)) table, Q15 */ -/*-------------------------------------------------------------------*/ -/* OUTPUT ARGUMENTS : */ -/* _ (Word16) fshift_fx : Q2 */ -/*-------------------------------------------------------------------*/ -/* INPUT/OUTPUT ARGUMENTS : */ -/* _ None */ -/*-------------------------------------------------------------------*/ -/* RETURN ARGUMENTS : _ None. */ -/*-------------------------------------------------------------------*/ -/* CALLED FROM : TX */ -/*===================================================================*/ - -Word16 DTFS_alignment_fine_new_fx( DTFS_STRUCTURE_FX X1_fx, DTFS_STRUCTURE_FX X2_fx, Word16 *S_fx, Word16 *C_fx) -{ - Word16 temp, temp1, k, Qcorr, Qmaxcorr; - Word16 n, fshift_fx, HalfLag, ab1[MAXLAG_WI], ab2[MAXLAG_WI]; - Word32 corr_fx; - Word32 maxcorr_fx, wcorr_fx, diff_corr; - - IF (sub(X1_fx.lag_fx, X2_fx.lag_fx) < 0) - { - DTFS_zeroPadd_fx(X2_fx.lag_fx, &X1_fx) ; - } - - maxcorr_fx = L_add(MIN_32, 0); - Qmaxcorr = 0; - move16(); - HalfLag = s_min(shr(X2_fx.lag_fx, 1),X2_fx.nH_fx); - - FOR (k=0; k<=HalfLag; k++) - { - ab1[k] = round_fx(L_mac(L_mult(X1_fx.a_fx[k],X2_fx.a_fx[k]),X1_fx.b_fx[k],X2_fx.b_fx[k])); - ab2[k] = round_fx(L_msu(L_mult(X1_fx.b_fx[k],X2_fx.a_fx[k]),X1_fx.a_fx[k],X2_fx.b_fx[k])); - } - - - fshift_fx = 0; - move16(); - FOR ( n=-76; n<=80; n+=4 ) - { - /* n is Q2 */ - corr_fx = L_deposit_l(0); - temp = 0; - move16(); - temp1 = n; - move16(); - - IF (n<0) - { - temp1=add(temp1, shl(X2_fx.lag_fx, 2)); /* avoid negative */ - } - - FOR (k=0; k<=HalfLag; k++) - { - corr_fx=L_mac(corr_fx, ab1[k], C_fx[temp%(4*X2_fx.lag_fx)]); - corr_fx=L_mac(corr_fx, ab2[k], S_fx[temp%(4*X2_fx.lag_fx)]); - temp = add(temp, temp1); - } - temp=sub(32767, extract_l(L_shr(L_mult(82, abs_s(n)), 1))); /* Q15 */ - Qcorr = norm_l(corr_fx); - if(corr_fx==0) - { - Qcorr = 31; - move16(); - } - - temp1 = round_fx((Word32)L_shl(corr_fx, Qcorr)); /* Q(Qcorr-16) */ - wcorr_fx = L_mult(temp1, temp); /* Q(Qcorr-16+15+1)=Q(Qcorr) */ - - IF (sub(Qmaxcorr,Qcorr) >= 0) - { - diff_corr = L_sub(wcorr_fx, L_shl(maxcorr_fx, sub(Qcorr, Qmaxcorr))); /* Qcorr */ - } - ELSE - { - diff_corr = L_sub(L_shl(wcorr_fx, sub(Qmaxcorr, Qcorr)), maxcorr_fx); /* Qmaxcorr */ - } - - if ( diff_corr > 0 ) - { - fshift_fx = n ; - move16(); - maxcorr_fx = (Word32)L_shl(corr_fx, Qcorr) ; /* Qcorr */ - Qmaxcorr = Qcorr; - move16(); - } - } - - return fshift_fx ; -} -/*===========================================================================*/ -/* FUNCTION : DTFS_alignment_full_fx () */ -/*---------------------------------------------------------------------------*/ -/* PURPOSE : search for alignment */ -/*---------------------------------------------------------------------------*/ -/* INPUT ARGUMENTS : */ -/* _ (struct DTFS_STRUCTURE_FX) X1_DTFS_fx : a_fx/b_fx in X1_DTFS_fx.Q */ -/* _ (struct DTFS_STRUCTURE_FX) X2_DTFS_fx : a_fx/b_fx in X2_DTFS_fx.Q */ -/* _ (Word16 *) S_fx: sin(2pi*n/(4*lag)) table, Q15 */ -/* _ (Word16 *) C_fx: cos(2pi*n/(4*lag)) table, Q15 */ -/*---------------------------------------------------------------------------*/ -/* OUTPUT ARGUMENTS : */ -/* _ (Word16) fshift_fx : Q1 */ -/*---------------------------------------------------------------------------*/ -/* INPUT/OUTPUT ARGUMENTS : */ -/* _ None */ -/*---------------------------------------------------------------------------*/ -/* RETURN ARGUMENTS : _ None. */ -/*---------------------------------------------------------------------------*/ -/* CALLED FROM : TX */ -/*===========================================================================*/ - -Word16 DTFS_alignment_full_fx( DTFS_STRUCTURE_FX X1_DTFS_fx, DTFS_STRUCTURE_FX X2_DTFS_fx, Word16 ph_offset_fx,Word16 *S_fx, Word16 *C_fx - , Word16 FR_flag - ) -{ - Word16 temp, temp1, k, start, end, HalfLag, ab1[MAXLAG_WI], ab2[MAXLAG_WI] ; - Word16 n, fshift_fx; - Word32 corr_fx, maxcorr_fx; - Word16 Eshift, Adiff_fx; - - - /* Calculating the expected alignment shift */ - Eshift = mult_r(ph_offset_fx, shl(X2_DTFS_fx.lag_fx, 7)); /* confirmed I<2 by smv12.org, Q7 */ - find_rem((Word16)L_FRAME, shr(add(X2_DTFS_fx.lag_fx, X1_DTFS_fx.lag_fx), 1), &temp); - temp = add(shl(temp, 7), Eshift); /* Q7 */ - - IF (temp<0) - { - temp = add(temp, shl(X1_DTFS_fx.lag_fx, 7)); /* Q7 */ - } - find_rem(temp, shl(X1_DTFS_fx.lag_fx, 7), &Eshift); /* Q7 */ - Eshift=shl(shr(Eshift,7),1); /* Q1 but integer */ - - IF (sub(X2_DTFS_fx.lag_fx,60) > 0) - { - Adiff_fx = shl(X2_DTFS_fx.lag_fx,1-3); /* lag_fx/8 in Q1 */ - } - ELSE - { - Adiff_fx = shl(X2_DTFS_fx.lag_fx,1-2); /* lag_fx/4 in Q1 */ - } - - - IF (X1_DTFS_fx.lag_fx < X2_DTFS_fx.lag_fx) - { - DTFS_zeroPadd_fx(X2_DTFS_fx.lag_fx,&X1_DTFS_fx) ; - } - - maxcorr_fx = L_add(MIN_32, 0); - HalfLag = s_min(shr(X2_DTFS_fx.lag_fx, 1),X2_DTFS_fx.nH_4kHz_fx); - - FOR (k=0; k<=HalfLag; k++) - { - ab1[k] = round_fx(L_mac(L_mult(X1_DTFS_fx.a_fx[k], X2_DTFS_fx.a_fx[k]), X1_DTFS_fx.b_fx[k], X2_DTFS_fx.b_fx[k])); /* Q(-15); */ - ab2[k] = round_fx(L_msu(L_mult(X1_DTFS_fx.b_fx[k], X2_DTFS_fx.a_fx[k]), X1_DTFS_fx.a_fx[k], X2_DTFS_fx.b_fx[k])); /* Q(-15); */ - } - IF (FR_flag == 0) - { - start=sub(Eshift, Adiff_fx); /*Q1*/ - end=add(Eshift, Adiff_fx); /*Q1*/ - } - ELSE - { - /* - in FR mode, we cannot save and cary forward ph_offset as in VBR mode encoder "ph_offset_E_fx", - so we set ph_offset_fx = 0, as a result we cannot accurately estimate the expected alignment shift Eshift to limit the search, - so we search the full range [0 to X2_DTFS_fx.lag_fx] similar to FL - */ - start=0; /*Q1*/ - end=shl(X2_DTFS_fx.lag_fx,1); /*Q1*/ - } - - fshift_fx=start; - move16(); /*Q1*/ - - FOR (n=start; n<=end; n++) /*n in Q1*/ - { - /* Q1 */ - corr_fx = L_deposit_l(0); - temp = 0; - move16(); - temp1 = add(n,shl(X2_DTFS_fx.lag_fx,1)); /* add lag_fx in Q1to make positive */ - FOR (k=0; k<=HalfLag; k++) - { - corr_fx = L_mac(corr_fx, ab1[k], C_fx[(2*temp)%(4*X2_DTFS_fx.lag_fx)]); - corr_fx = L_mac(corr_fx, ab2[k], S_fx[(2*temp)%(4*X2_DTFS_fx.lag_fx)]); - temp = add(temp, temp1); - } - - if (L_sub(corr_fx, maxcorr_fx) > 0) - { - fshift_fx = n ; /* Q1 */ move16(); - maxcorr_fx = L_add(corr_fx, 0); - } - } - - return fshift_fx ; /*Q1*/ -} -/*===================================================================*/ -/* FUNCTION : DTFS_phaseShift_fx () */ -/*-------------------------------------------------------------------*/ -/* PURPOSE : Phase is shifted by 2pi*ph/Lag */ -/*-------------------------------------------------------------------*/ -/* INPUT ARGUMENTS : */ -/* _ (Word16) ph: shift index, Q7 */ -/* _ (Word16) Lag: Pitch Lag value as for shift */ -/* _ (Word16 *) S_fx: sin(2pi*n/(4*lag)) table, Q15 */ -/* _ (Word16 *) C_fx: cos(2pi*n/(4*lag)) table, Q15 */ -/*-------------------------------------------------------------------*/ -/* OUTPUT ARGUMENTS : */ -/* _ None. */ -/*-------------------------------------------------------------------*/ -/* INPUT/OUTPUT ARGUMENTS : */ -/* _ (struct DTFS_fx) X1 : a/b in X1.Q */ -/*-------------------------------------------------------------------*/ -/* RETURN ARGUMENTS : _ None. */ -/*-------------------------------------------------------------------*/ -/* CALLED FROM : TX/RX */ -/*===================================================================*/ - -void DTFS_phaseShift_fx( DTFS_STRUCTURE_FX *X_fx,Word16 ph, Word16 Lag, Word16 *S_fx, Word16 *C_fx) -{ - Word16 k ; - Word16 temp, HalfLag; - Word32 L_temp, L_temp2; - - L_temp2 = L_deposit_l(0); - HalfLag = s_min(shr(X_fx->lag_fx, 1),X_fx->nH_fx); - - IF (ph>0) - { - FOR (k=0; k<=HalfLag; k++) - { - temp = X_fx->a_fx[k]; - L_temp = L_shr(L_temp2, 5); /* Q2 */ - X_fx->a_fx[k] = round_fx(L_msu(L_mult(temp, C_fx[L_temp%(4*Lag)]), X_fx->b_fx[k], S_fx[L_temp%(4*Lag)])) ; /* X.Q */ - X_fx->b_fx[k] = round_fx(L_mac(L_mult(X_fx->b_fx[k], C_fx[L_temp%(4*Lag)]), temp, S_fx[L_temp%(4*Lag)])) ; - L_temp2 = L_add(L_temp2, ph); - } - } - - IF (ph<0) - { - FOR (k=0; k<=HalfLag; k++) - { - temp = X_fx->a_fx[k]; - L_temp = L_shr(L_negate(L_temp2), 5); /* Q2 */ - X_fx->a_fx[k] = round_fx(L_mac(L_mult(temp, C_fx[L_temp%(4*Lag)]), X_fx->b_fx[k], S_fx[L_temp%(4*Lag)])) ; /* X.Q */ - X_fx->b_fx[k] = round_fx(L_msu(L_mult(X_fx->b_fx[k], C_fx[L_temp%(4*Lag)]), temp, S_fx[L_temp%(4*Lag)])) ; - L_temp2 = L_add(L_temp2, ph); - } - } -} - -/*===================================================================*/ -/* FUNCTION : Q2phaseShift_fx () */ -/*-------------------------------------------------------------------*/ -/* PURPOSE : Phase is shifted by 2pi*ph/Lag */ -/*-------------------------------------------------------------------*/ -/* INPUT ARGUMENTS : */ -/* _ (Word16) ph: shift index, Q2 */ -/* _ (Word16) Lag: Pitch Lag value as for shift */ -/* _ (Word16 *) S_fx: sin(2pi*n/(4*lag)) table, Q15 */ -/* _ (Word16 *) C_fx: cos(2pi*n/(4*lag)) table, Q15 */ -/*-------------------------------------------------------------------*/ -/* OUTPUT ARGUMENTS : */ -/* _ None. */ -/*-------------------------------------------------------------------*/ -/* INPUT/OUTPUT ARGUMENTS : */ -/* _ (struct DTFS_STRUCTURE_FX) X_fx : a/b in X_fx->Q */ -/*-------------------------------------------------------------------*/ -/* RETURN ARGUMENTS : _ None. */ -/*-------------------------------------------------------------------*/ -/* CALLED FROM : TX/RX */ -/*===================================================================*/ - -void Q2phaseShift_fx( DTFS_STRUCTURE_FX *X_fx,Word16 ph, Word16 Lag, Word16 *S_fx, Word16 *C_fx) -{ - Word16 k ; - Word16 temp, HalfLag; - Word32 temp2; - - temp2 = L_deposit_l(0); - - HalfLag = s_min(shr(X_fx->lag_fx, 1),X_fx->nH_fx); - - - IF (ph>0) - { - FOR (k=0; k<=HalfLag; k++) - { - temp = X_fx->a_fx[k]; - X_fx->a_fx[k] = round_fx(L_msu(L_mult(temp, C_fx[temp2%(4*Lag)]), X_fx->b_fx[k], S_fx[temp2%(4*Lag)])) ; /* X.Q */ - X_fx->b_fx[k] = round_fx(L_mac(L_mult(X_fx->b_fx[k], C_fx[temp2%(4*Lag)]), temp, S_fx[temp2%(4*Lag)])) ; - temp2 = L_add(temp2, (Word32)ph); - } - } - - - - IF (ph<0) - { - FOR (k=0; k<=HalfLag; k++) - { - temp = X_fx->a_fx[k]; - X_fx->a_fx[k] = round_fx(L_mac(L_mult(temp, C_fx[temp2%(4*Lag)]), X_fx->b_fx[k], S_fx[temp2%(4*Lag)])) ; /* X.Q */ - X_fx->b_fx[k] = round_fx(L_msu(L_mult(X_fx->b_fx[k], C_fx[temp2%(4*Lag)]), temp, S_fx[temp2%(4*Lag)])) ; - temp2 = add((Word16)temp2, negate(ph)); - } - } -} -/*===================================================================*/ -/* FUNCTION : DTFS_zeroPadd_fx () */ -/*-------------------------------------------------------------------*/ -/* PURPOSE : zeroPadding */ -/*-------------------------------------------------------------------*/ -/* INPUT ARGUMENTS : */ -/* _ (Word16) N_fx: length , Q0 */ -/*-------------------------------------------------------------------*/ -/* OUTPUT ARGUMENTS : */ -/* _ None. */ -/*-------------------------------------------------------------------*/ -/* INPUT/OUTPUT ARGUMENTS : */ -/* _ (struct DTFS_STRUCTURE_FX) X_fx : a/b in X_fx.Q i.e Q6 */ -/* _ (Word16) lag: pitch lag of *X_fx, Q0 */ -/*-------------------------------------------------------------------*/ -/* RETURN ARGUMENTS : _ None. */ -/*-------------------------------------------------------------------*/ -/* CALLED FROM : TX/RX */ -/*===================================================================*/ - -void DTFS_zeroPadd_fx(Word16 N_fx,DTFS_STRUCTURE_FX *X_fx) -{ - Word16 i, start, end ,diff_fx,rem_fx; - - if (sub(N_fx,X_fx->lag_fx) == 0) - { - return ; - } - start = add(shr(X_fx->lag_fx,1), 1); - end = shr(N_fx, 1); - - move16(); - FOR (i=start; i<=end; i++) - { - X_fx->a_fx[i]=0; - move16(); - X_fx->b_fx[i]=0; - move16(); - } - - X_fx->lag_fx = N_fx ; - move16(); - - /* recompute nH for new lag */ - diff_fx = find_rem(12800,X_fx->lag_fx,&rem_fx); - X_fx->nH_fx = find_rem(X_fx->upper_cut_off_freq_fx,diff_fx,&rem_fx); - - if(sub(sub(X_fx->upper_cut_off_freq_fx,shr((Word16)L_mult(diff_fx,X_fx->nH_fx),1)),diff_fx)>=0) - { - X_fx->nH_fx = add(X_fx->nH_fx,1); - } -} -/*===================================================================*/ -/* FUNCTION : to_fs_fx () */ -/*-------------------------------------------------------------------*/ -/* PURPOSE : */ -/*-------------------------------------------------------------------*/ -/* INPUT ARGUMENTS : */ -/* _ (Word16 *) x: input time domain series. Q0 */ -/* _ (Word16) N: Lag */ -/* _ (struct DTFS_STRUCTURE_FX) PREVCW_FX: a/b in PREVCW_FX.Q */ -/* _ (Word16 *) S_fx: sin(2pi*n/(4*lag)) table, Q15 */ -/* _ (Word16 *) C_fx: cos(2pi*n/(4*lag)) table, Q15 */ -/*-------------------------------------------------------------------*/ -/* OUTPUT ARGUMENTS : */ -/* _ (struct DTFS_STRUCTURE_FX) (Word16 a[]) : in Q */ -/* _ (struct DTFS_STRUCTURE_FX) (Word16 b[]) : in Q */ -/* _ (struct DTFS_STRUCTURE_FX) (Word16 lag) : Q0 */ -/* _ (struct DTFS_STRUCTURE_FX) (Word16 Q ) : Q value of a/b */ -/*-------------------------------------------------------------------*/ -/* INPUT/OUTPUT ARGUMENTS : */ -/* _ None. */ -/*-------------------------------------------------------------------*/ -/* RETURN ARGUMENTS : _ None. */ -/*-------------------------------------------------------------------*/ -/* CALLED FROM : TX/RX */ -/*===================================================================*/ -void DTFS_to_fs_fx( - const Word16 *x, /* i : time domain signal */ - Word16 N, /* i : Length of input vector */ - DTFS_STRUCTURE_FX *X_fx, /* o : DTFS structure with a, b, lag */ - Word16 Fs, /* i : sampling rate */ - Word16 FR_flag, /* i : FR flag */ - Word16 *S_fx, - Word16 *C_fx -) - -{ - Word16 n,temp,temp_neg,inv_lag,sum,diff_fx; - Word16 nH, k, nH_band, nH_4kHz; - Word32 L_temp, Lx0; - Word32 L_a, L_b,L_tmp; - Word32 La[MAXLAG_WI], Lb[MAXLAG_WI], Labmax; - Word16 exp,tmp; - Word32 L_tmp1; - - - IF (!FR_flag) - { - IF (sub(Fs,16000)==0) - { - X_fx->upper_cut_off_freq_of_interest_fx=4000; - move16(); - X_fx->upper_cut_off_freq_fx=6400; - move16(); - X_fx->Fs_fx=INT_FS_FX; - move16(); - } - ELSE IF (sub(Fs,8000)==0) - { - X_fx->upper_cut_off_freq_of_interest_fx=3300; - move16(); - X_fx->upper_cut_off_freq_fx=4000; - move16(); - X_fx->Fs_fx=INT_FS_FX; - move16(); - } - } - ELSE - { - X_fx->upper_cut_off_freq_of_interest_fx=8000; - move16(); - X_fx->upper_cut_off_freq_fx=8000; - move16(); - X_fx->Fs_fx=16000; - move16(); - } - X_fx->lag_fx = N ; - move16(); - - exp = norm_s(X_fx->lag_fx); - tmp = div_s(shl(1,sub(14,exp)),X_fx->lag_fx); /* Q29-exp */ - L_tmp1 = L_mult(12800,tmp); /* Q(30-exp) */ - diff_fx = extract_h(L_shl(L_tmp1,sub(exp,14))); /* Q0 */ - - exp = norm_s(diff_fx); - tmp = div_s(shl(1,sub(14,exp)),diff_fx); /* Q29-exp */ - L_tmp1 = L_mult(X_fx->upper_cut_off_freq_fx,tmp); /* Q(30-exp) */ - nH_band = extract_h(L_shl(L_tmp1,sub(exp,14))); /* Q0 */ - - nH_4kHz = mult(10240,(X_fx->lag_fx)); /* 4000/12800 in Q15 */ - - if(sub(sub(X_fx->upper_cut_off_freq_fx,shr((Word16)L_mult(diff_fx,nH_band),1)),diff_fx)>=0) - { - nH_band = add(nH_band,1); - } - - if(sub(sub(4000,shr((Word16)L_mult(diff_fx,nH_4kHz),1)),diff_fx)>=0) - { - nH_4kHz = add(nH_4kHz,1); - } - - /* Number of harmonics excluding the ones at 0 and at pi */ - nH = shr(sub(N,1),1); - - /* The DC component */ - X_fx->a_fx[0] = 0 ; - move16(); - X_fx->b_fx[0] = 0 ; - move16(); - - exp = norm_s(N); - tmp = div_s(shl(1,(sub(14,exp))),N); - L_tmp = L_shl(tmp,add(exp,6)); - inv_lag = round_fx(L_tmp); - - Lx0 = L_deposit_h(x[0]); - Labmax = L_deposit_l(0); - FOR ( k=1; k<=nH; k++ ) - { - L_a = L_shr(Lx0,1) ; /* Q16 */ - - L_b = L_deposit_l(0); - sum = k; - move16(); - temp = k; - move16(); - FOR ( n=1; n0) - { - Labmax=L_temp; - } - L_temp=L_abs(Lb[k]); - - if (L_sub(L_temp,Labmax)>0) - { - Labmax=L_temp; - } - } - - - /* The harmonic at 'pi' */ - - /* IF ( N%2 == 0 ) */ - IF (s_and (N,1) == 0 ) - { - - L_a = L_deposit_l(0); - temp = 1 ; - move16(); - temp_neg = negate(temp); - FOR ( n=0; n0) - { - Labmax = L_add(L_temp, 0); - } - - X_fx->b_fx[k] = 0 ; - move16(); - } - - temp = norm_l(Labmax); - if (Labmax==0) - { - temp = 31; - move16(); - } - - FOR ( k=1; k<=nH; k++ ) - { - X_fx->a_fx[k]=round_fx(L_shl(La[k], temp)); /* Q(8+temp-16)=Q(temp-8) */ - X_fx->a_fx[k]=mult_r(X_fx->a_fx[k], inv_lag); - move16(); /* Q(temp-8+19+1-16)=Q(temp-4) of a[k]*2.0/N */ - X_fx->b_fx[k]=round_fx(L_shl(Lb[k], temp)); /* Q(8+temp-16)=Q(temp-8) */ - X_fx->b_fx[k]=mult_r(X_fx->b_fx[k], inv_lag); - move16(); /* Q(temp-8+19+1-16)=Q(temp-4) of b[k]*2.0/N */ - } - - /* IF ( N%2 == 0 ) */ - IF ( s_and(N,1) == 0 ) - { - X_fx->a_fx[k]=round_fx(L_shl(La[k], temp)); /* Q(8+temp-16)=Q(temp-8) */ - X_fx->a_fx[k]=mult_r(X_fx->a_fx[k], inv_lag); - move16(); /* Q(temp-8+19+1-16)=Q(temp-4) of a[k]*1.0/N */ - X_fx->b_fx[k]=0; - move16(); - } - - X_fx->Q=sub(temp, 4); - - tmp = s_min(shr(X_fx->lag_fx,1),sub(MAXLAG_WI,1)); - FOR(k=add(nH_band,1); k<=tmp; k++) - { - X_fx->a_fx[k]=0; - move16(); - X_fx->b_fx[k]=0; - move16(); - } - X_fx->nH_fx=nH_band; - move16(); - X_fx->nH_4kHz_fx=nH_4kHz; - move16(); - -} - - -/*===================================================================*/ -/* FUNCTION : DTFS_transform_fx () */ -/*-------------------------------------------------------------------*/ -/* PURPOSE : */ -/*-------------------------------------------------------------------*/ -/* INPUT ARGUMENTS : */ -/* _ (struct DTFS_STRUCTURE_FX) X_fx: a/b in X1.Q, lag in Q0 */ -/* _ (struct DTFS_STRUCTURE_FX) X2_fx. a/b in X2.Q, lag in Q0 */ -/* _ (Word16 *) phase_fx: 2pi normalized, Q12 */ -/* _ (Word16) N: length of series. */ -/*-------------------------------------------------------------------*/ -/* OUTPUT ARGUMENTS : */ -/* _ (Word16 *) out_fx: output transformed series. Q0. */ -/*-------------------------------------------------------------------*/ -/* INPUT/OUTPUT ARGUMENTS : */ -/* _ None. */ -/*-------------------------------------------------------------------*/ -/* RETURN ARGUMENTS : _ None. */ -/*-------------------------------------------------------------------*/ -/* CALLED FROM : TX/RX */ -/*===================================================================*/ -void DTFS_transform_fx( - DTFS_STRUCTURE_FX X_fx, /* i : Starting DTFS to use in WI */ - DTFS_STRUCTURE_FX X2_fx, /* i : Ending DTFS to use in WI */ - const Word32 *phase_fx, /* i : Phase contour */ - Word16 *out_fx, /* o : Output time domain waveform */ - Word16 N, /* i : Number of samples to generate */ - Word16 FR_flag /* i : Flag to indicate called in FR context */ -) -{ - - Word16 i, j ; - Word32 L_temp_fx; - Word16 w_fx; - Word16 inv1_fx, inv2_fx, inv_fx, q1, q2; - Word32 Lw_fx,temp32_fx; - Word16 x2_256_fx[256], x1_256_fx[256]; - Word16 k, m, l1; - Word32 x_r_fx[256] = { 0 }; - Word32 tmptmp3_40_fx; - Word16 temp_w; - Word16 N1; - Word16 nrg_flag = 0; - Word32 L_tmp; - Word16 tmp, tmp1, tmp2, frac, exp1, exp2; - Word16 expa, expb, fraca, fracb, scale; - - DTFS_STRUCTURE_FX *tmp2_dtfs_fx = DTFS_new_fx(); - DTFS_STRUCTURE_FX *tmp1_dtfs_fx = DTFS_new_fx(); - DTFS_STRUCTURE_FX *tmp3_dtfs_fx = DTFS_new_fx(); - DTFS_copy_fx(tmp1_dtfs_fx,X_fx); - DTFS_copy_fx(tmp2_dtfs_fx,X2_fx); - - tmp2 = 0; /* to avoid compilation warnings */ - - - DTFS_fast_fs_inv_fx(tmp1_dtfs_fx,x1_256_fx,256,8); - DTFS_fast_fs_inv_fx(tmp2_dtfs_fx,x2_256_fx,256,8); - - - - /* L_temp_fx=invert_dp((Word40)N,4,&n,1); = 1/M, Q(61-n) */ - /* inv1_fx=round_fx(L_temp_fx); = 1/M in Q(45-n) */ - /* q1=sub(n,15); */ - exp1 = norm_s(N); - inv1_fx = div_s(shl(1,sub(14,exp1)),N); /* 29-exp1 */ - q1=add(exp1,1); - - tmp1 = sub(X_fx.lag_fx,N); - exp2 = norm_s(tmp1); - - if(tmp1<0) - { - tmp2 = negate(tmp1); - } - tmp = div_s(shl(1,(14- exp2)),tmp2); /* 29-exp2 */ - L_tmp = L_shl(tmp,16); - - if(tmp1<0) - { - L_tmp = L_negate(L_tmp); - } - - q2=sub(exp2,3); - - - - /*L_temp_fx=(Word32) Mpy_32_16(extract_h(L_tmp),extract_l(L_tmp),22904); move32(); */ /* L_temp=log(0.2)*log10(e)/(lag-M), Q(61-n) */ - L_temp_fx= Mult_32_16(L_tmp,22904); /* L_temp=log(0.2)*log10(e)/(lag-M), Q(61-n) */ - inv2_fx=round_fx(L_temp_fx); /* log(0.2)*log10(e)/(lag-M), Q(45-n) */ - /* q2=sub(n,19); */ /* adjust Q factor to Q26 */ - - - IF (sub(sub(N, WI_SAMPLE_THLD), X_fx.lag_fx) > 0 ) - { - inv_fx = inv2_fx; - move16(); - } - ELSE - { - inv_fx = inv1_fx; - move16(); - exp2 = exp1; - move16(); - } - - Lw_fx = L_deposit_l(inv_fx); - - FOR (i=0; i 0 ) - { - - L_tmp = L_shl(Lw_fx,q2); /* Q29-exp2+q2 */ - L_tmp = Mult_32_16(L_tmp, 27213); /* 3.321928 in Q13 -> 16+13+1 */ /*27-exp2 */ - L_tmp = L_shl(L_tmp, sub(exp2,add(q2,11))); - frac = L_Extract_lc(L_tmp, &exp1); /* Extract exponent */ - L_temp_fx =Pow2(14, frac); - exp1 = sub(exp1,14); - L_temp_fx = L_shl(L_temp_fx,add(exp1,15)); /* Q15 */ - - w_fx=sub(16384,extract_h(L_shl(L_temp_fx,15))); /* w_fx in Q14 1- exp(- (i+1) * log(.2)/(lag-M)) */ - } - ELSE - { - w_fx=round_fx(L_shl(Lw_fx,q1)); /* Q14 */ - } - } - ELSE - { - IF (nrg_flag) - { - w_fx=round_fx(L_shl(Lw_fx,q1)); /* Q14 */ - } - ELSE - { - - N1 = sub(N , tmp2_dtfs_fx->lag_fx); - - IF (sub(i,N1) < 0) - /* w = (i+1)/N1; */ - { - - /* w = (i+1)/N1; */ - IF(N1) - { - expa = norm_s(N1); - fraca = shl(N1,expa); - expa = sub(14,expa); - - tmp = add(i,1); - expb = norm_s(tmp); - fracb = shl(tmp,expb); - expb = sub(14,expb); - - scale = shr(sub(fraca,fracb),15); - fracb = shl(fracb,scale); - expb = sub(expb,scale); - - w_fx = div_s(fracb,fraca); - exp1 = sub(expb,expa); - w_fx = shl(w_fx,exp1-1); /*Q14*/ - } - ELSE - { - w_fx = 0; - } - - Lw_fx=L_deposit_h(w_fx); - - - } - ELSE - { - w_fx = 16384; - move16(); - } - } - } - - Lw_fx=L_add(Lw_fx,inv_fx); /* (i+1)*inv */ - /* mapping phase to 8x256 length signal */ - temp32_fx = phase_fx[i]; /* Q(27-11)=Q16 due to multiplication by pow(2.0,11) */ - j = rint_new_fx(temp32_fx); - j = s_and(j,0x07ff); - - /* k=j%8; */ - k=s_and(j,7); - l1=shr(j,3); /* reminder and quotient */ - - temp_w = sub( 16384, w_fx ); - tmptmp3_40_fx = L_deposit_l(0); - - FOR (j=0; j<12; j++) - { - m=(1000*LL+l1-OSLENGTH/2+j)%LL; /* use circular addressing */ - x_r_fx[m] = L_mac( L_mult( x1_256_fx[m], temp_w), x2_256_fx[m], w_fx); - } - tmptmp3_40_fx = L_deposit_l(0); - - - FOR (j=0; j<12; j++) - { - m=(1000*LL+l1-OSLENGTH/2+j)%LL; /* use circular addressing */ - tmptmp3_40_fx=L_add(tmptmp3_40_fx, Mult_32_16(x_r_fx[m],sinc_fx[k][j])); - - } - out_fx[i] = round_fx(L_shl(tmptmp3_40_fx,2)); - } - - - free(tmp1_dtfs_fx); - free(tmp2_dtfs_fx); - free(tmp3_dtfs_fx); -} -/*===================================================================*/ -/* FUNCTION : zeroFilter_fx() */ -/*-------------------------------------------------------------------*/ -/* PURPOSE : zero filtering */ -/*-------------------------------------------------------------------*/ -/* INPUT ARGUMENTS : */ -/* _ (Word16) lpc[] : lpc coefficients in Q12 */ -/* _ (Word16) N : lpc order */ -/* _ (Word16) this->lag: in Q0 */ -/* _ (Word16 *) S_fx: sin(2pi*n/(4*lag)) table, Q15 */ -/* _ (Word16 *) C_fx: cos(2pi*n/(4*lag)) table, Q15 */ -/*-------------------------------------------------------------------*/ -/* OUTPUT ARGUMENTS : */ -/* _ None. */ -/*-------------------------------------------------------------------*/ -/* INPUT/OUTPUT ARGUMENTS : */ -/* _ (Word16) this->a[] : in Q(this->Q) */ -/* _ (Word16) this->b[] : in Q(this->Q) */ -/* _ (Word16) this->Q: in Q0 */ -/*-------------------------------------------------------------------*/ -/* RETURN ARGUMENTS : _ None. */ -/*-------------------------------------------------------------------*/ -/* CALLED FROM : TX/RX */ -/*===================================================================*/ - -void DTFS_zeroFilter_fx( DTFS_STRUCTURE_FX *X_fx,Word16 *LPC, Word16 N, Word16 *S_fx, Word16 *C_fx) -{ - Word32 sum1_fx, sum2_fx ; - Word16 k, n, HalfLag ; - Word16 temp, temp1, temp2; - Word32 L_temp1, L_temp2; - Word16 Qmin, Qab[MAXLAG_WI], na, nb; - - Qmin = 32767; - move16(); - HalfLag = s_min(shr(X_fx->lag_fx, 1),X_fx->nH_fx); - FOR ( k=0 ; k<=HalfLag ; k++ ) - { - temp = k; - move16(); - temp2 = k; - move16(); - - /* Calculate sum1 and sum2 */ - sum1_fx = L_deposit_h(4096); /* 1: Q(12+15+1) */ - sum2_fx = L_deposit_l(0); - - FOR ( n=0 ; nlag_fx)]) ; /* Q(12+15+1) */ - sum2_fx = L_mac(sum2_fx, LPC[n], S_fx[(4*temp2)%(4*X_fx->lag_fx)]) ; - temp2 = add(temp2, temp); - } - - temp1 = round_fx(sum1_fx); /* Q(12+15+1-16)=Q(12) */ - temp2 = round_fx(sum2_fx); /* Q(12) */ - - /* Calculate the circular convolution */ - L_temp1 = L_mult(temp1, X_fx->a_fx[k]); - L_temp1 = L_msu(L_temp1, temp2, X_fx->b_fx[k]); /* Q(12+Q+1) */ - L_temp2 = L_mult(temp1, X_fx->b_fx[k]); - L_temp2 = L_mac(L_temp2, temp2, X_fx->a_fx[k]); /* Q(12+Q+1) */ - - /* normalization */ - na = norm_l(L_temp1); - if (L_temp1==0) - { - na=31; - move16(); - } - nb = norm_l(L_temp2); - if (L_temp2==0) - { - nb=31; - move16(); - } - - if (sub(na, nb)<0) - { - nb=na; - move16(); - } - X_fx->a_fx[k] = round_fx((Word32)L_shl(L_temp1, nb)); /* Q(13+Q+nb-16)=Q(Q+nb-3) */ - X_fx->b_fx[k] = round_fx((Word32)L_shl(L_temp2, nb)); /* Q(Q+nb-3) */ - - Qab[k] = sub(nb, 3); - - if (sub(Qab[k], Qmin)<0) - { - Qmin = Qab[k]; - move16(); - } - } - /* bring to the same Q */ - FOR ( k=0 ; k<=HalfLag ; k++ ) - { - X_fx->a_fx[k] = shl(X_fx->a_fx[k], sub(Qmin, Qab[k])); - move16(); /* Q(Q+Qab[k]+Qmin-Qab[k]=Q(Q+Qmin) */ - X_fx->b_fx[k] = shl(X_fx->b_fx[k], sub(Qmin, Qab[k])); - move16(); /* Q(Q+Qmin) */ - } - - X_fx->Q = add(X_fx->Q, Qmin); - move16(); -} -/*===================================================================*/ -/* FUNCTION : DTFS_poleFilter_fx() */ -/*-------------------------------------------------------------------*/ -/* PURPOSE : pole filtering */ -/*-------------------------------------------------------------------*/ -/* INPUT ARGUMENTS : */ -/* _ (Word16) lpc[] : lpc coefficients in Q12 */ -/* _ (Word16) N : lpc order */ -/* _ (Word16) lag: in Q0 */ -/* _ (Word16 *) C_fx: cos(2pi*n/(4*lag)) table, Q15 */ -/* _ (Word16 *) S_fx: sin(2pi*n/(4*lag)) table, Q15 */ -/* _ (Word16 *) C_fx: cos(2pi*n/(4*lag)) table, Q15 */ -/*-------------------------------------------------------------------*/ -/* OUTPUT ARGUMENTS : */ -/* _ None */ -/*-------------------------------------------------------------------*/ -/* INPUT/OUTPUT ARGUMENTS : */ -/* _ (Word16) this->a[] : in Q(this->Q) */ -/* _ (Word16) this->b[] : in Q(this->Q) */ -/* _ (Word16) this->Q: in Q0 */ -/*-------------------------------------------------------------------*/ -/* RETURN ARGUMENTS : _ None. */ -/*-------------------------------------------------------------------*/ -/* CALLED FROM : TX/RX */ -/*===================================================================*/ - -/* PORTING: Handling the functions with variable no. of arguments */ - -void DTFS_poleFilter_fx_9( DTFS_STRUCTURE_FX *X_fx, Word16 *pf_temp1, Word16 *pf_temp2, Word16 *pf_temp, Word16 *pf_n2_temp1) -{ - Word16 temp, temp1, temp2, HalfLag ; - Word32 sum1_fx, sum2_fx; - Word32 L_temp1, L_temp2; - Word16 k,n2_temp1, na, nb; - Word16 Qmin, Qab[MAXLAG_WI]; - - Qmin = 32767; - move16(); - HalfLag = s_min(shr(X_fx->lag_fx, 1),X_fx->nH_fx); - FOR ( k=0; k<=HalfLag; k++ ) - { - temp = temp2 = k; - move16(); - move16(); - /* Calculate sum1 and sum2 */ - - n2_temp1 = pf_n2_temp1[k]; - move16(); - - temp1 = pf_temp1[k]; - move16();/* Q(12+15+1+n2-16)=Q(12+n2) */ - temp2 = pf_temp2[k]; - move16();/* Q(12+n2) */ - - /* Calculate the circular convolution */ - - L_temp1 = L_mac(L_mult(temp1, X_fx->a_fx[k]), temp2, X_fx->b_fx[k]); /* Q(12+n2+Q+1)=Q(13+n2+Q) */ - L_temp2 = L_msu(L_mult(temp1, X_fx->b_fx[k]), temp2, X_fx->a_fx[k]); /* Q(12+n2+Q+1)=Q(13+n2+Q) */ - - temp = pf_temp[k]; - move16(); /* Q(61-25-2*n2-temp1-16)=Q(20-2*n2-temp1) */ - - sum1_fx = Mult_32_16(L_temp1, temp); /* Q(13+n2+Q+15+exp-15) = Q(13+n2+Q+exp) */ - sum2_fx = Mult_32_16(L_temp2, temp); - /* normalization */ - na = norm_l(sum1_fx); - if(sum1_fx==0) - { - na = 31; - move16(); - } - nb = norm_l(sum2_fx); - if(sum2_fx==0) - { - nb = 31; - move16(); - } - - if (sub(na, nb)<0) - { - nb=na; - move16(); - } - nb=sub(nb,1); /* leave one more sign bit */ - X_fx->a_fx[k] = round_fx((Word32)L_shl(sum1_fx, nb)); /* Q(-3+n2+Q+exp+nb ) */ - X_fx->b_fx[k] = round_fx((Word32)L_shl(sum2_fx, nb)); - - Qab[k] = add(sub(nb, 3), n2_temp1); - - if (sub(Qab[k], Qmin)<0) - { - Qmin = Qab[k]; - move16(); - } - } - /* bring to the same Q */ - move16(); - FOR ( k=0; k<=HalfLag; k++ ) - { - X_fx->a_fx[k] = shl(X_fx->a_fx[k], sub(Qmin, Qab[k])); - move16(); /* Q(Q+Qab[k]+Qmin-Qab[k])=Q(Q+Qmin) */ - X_fx->b_fx[k] = shl(X_fx->b_fx[k], sub(Qmin, Qab[k])); - move16(); /* Q(Q+Qab[k]+Qmin-Qab[k])=Q(Q+Qmin) */ - } - - X_fx->Q = add(X_fx->Q, Qmin); -} -/*===================================================================*/ -/* FUNCTION : DTFS_adjustLag_fx () */ -/*-------------------------------------------------------------------*/ -/* PURPOSE : */ -/*-------------------------------------------------------------------*/ -/* INPUT ARGUMENTS : */ -/* _ (Word16) N_fx: lag value, Q0 */ -/*-------------------------------------------------------------------*/ -/* OUTPUT ARGUMENTS : */ -/* _ (struct DTFS_fx) : a/b in X1.Q */ -/*-------------------------------------------------------------------*/ -/* INPUT/OUTPUT ARGUMENTS : */ -/* _ (struct DTFS_fx) X1 : lag in Q0 */ -/*-------------------------------------------------------------------*/ -/* RETURN ARGUMENTS : _ None. */ -/*-------------------------------------------------------------------*/ -/* CALLED FROM : TX/RX */ -/*===================================================================*/ - -void DTFS_adjustLag_fx( - DTFS_STRUCTURE_FX *X_DTFS_FX, /* i/o : DTFS to adjust lag for */ - Word16 N_fx /* i : Target lag */ -) -{ - Word32 en_fx; - Word32 temp32_fx,tempnH_fx,mul1_fx,mul2_fx; - Word16 k,diff_fx; - Word16 exp,tmp; - Word32 L_tmp; - - if (sub(N_fx,X_DTFS_FX->lag_fx)==0) - { - return ; - } - - IF(sub(N_fx,X_DTFS_FX->lag_fx)>0) - { - DTFS_zeroPadd_fx(N_fx,X_DTFS_FX); - } - ELSE - { - en_fx = DTFS_getEngy_fx(X_DTFS_FX); /* Q = 2*(X_DTFS_FX->Q) */ - - tmp = s_min(shr(X_DTFS_FX->lag_fx,1),X_DTFS_FX->nH_fx); - FOR( k = add(shr(N_fx,1),1) ; k<= tmp ; k++) - { - X_DTFS_FX->a_fx[k] = 0; - move16(); - X_DTFS_FX->b_fx[k] = 0; - move16(); - } - DTFS_setEngy_fx(X_DTFS_FX,en_fx); - X_DTFS_FX->lag_fx = N_fx ; - move16(); - - - /* recompute nH for new lag */ - exp = norm_s(X_DTFS_FX->lag_fx); - tmp = div_s(shl(1,sub(14,exp)),X_DTFS_FX->lag_fx);/* 29 - exp */ - L_tmp = L_mult0(12800,tmp); - temp32_fx = L_shl(L_tmp,sub(exp,23)); - diff_fx = (Word16) L_shl(L_tmp,sub(exp,29)); - - - exp = norm_s(diff_fx); - tmp = div_s(shl(1,sub(14,exp)),diff_fx);/* 29 - exp */ - L_tmp = L_mult0(X_DTFS_FX->upper_cut_off_freq_fx,tmp); - X_DTFS_FX->nH_fx = (Word16) L_shl(L_tmp,sub(exp,29)); - - L_tmp = L_mult0(4000,tmp); - tempnH_fx = L_shl(L_tmp,sub(exp,23)); - X_DTFS_FX->nH_4kHz_fx = extract_l(L_shl(L_tmp, sub(exp,29))); - - - if(sub(sub(X_DTFS_FX->upper_cut_off_freq_fx, shr((Word16)L_mult(diff_fx,X_DTFS_FX->nH_fx),1)), diff_fx) >= 0) - { - X_DTFS_FX->nH_fx = add(X_DTFS_FX->nH_fx,1); - move16(); - } - - mul1_fx = L_shl(temp32_fx,13);/* Q19 */ - mul2_fx = L_shl((Word32)X_DTFS_FX->nH_4kHz_fx,18);/* Q18 */ - tempnH_fx = Mult_32_32(mul1_fx,mul2_fx);/* Q6 */ - tempnH_fx = L_sub((Word32)256000,tempnH_fx);/* Q6 */ - - if(L_sub(tempnH_fx,temp32_fx)>=0) - { - X_DTFS_FX->nH_4kHz_fx = add(X_DTFS_FX->nH_4kHz_fx,1); - move16(); - } - } -} -/*===================================================================*/ -/* FUNCTION : DTFS_getEngy_fx () */ -/*-------------------------------------------------------------------*/ -/* PURPOSE : */ -/*-------------------------------------------------------------------*/ -/* INPUT ARGUMENTS : */ -/* _ (struct DTFS_STRUCTURE_FX) : a/b in X_fx.Q i.e Q6, lag in Q0*/ -/*-------------------------------------------------------------------*/ -/* OUTPUT ARGUMENTS : _ None */ -/*-------------------------------------------------------------------*/ -/* INPUT/OUTPUT ARGUMENTS : _ None */ -/*-------------------------------------------------------------------*/ -/* RETURN ARGUMENTS : */ -/* _ (Word40) en_fx: output energy, 2*X1.Q */ -/*-------------------------------------------------------------------*/ -/* CALLED FROM : TX/RX */ -/*===================================================================*/ - - -Word32 DTFS_getEngy_fx( DTFS_STRUCTURE_FX *X_fx) -{ - Word16 k, HalfLag_fx; - Word32 en_fx=0; - Word16 temp_a_fx,temp_b_fx; - - HalfLag_fx = shr(sub(X_fx->lag_fx, 1), 1); - HalfLag_fx = s_min(HalfLag_fx,X_fx->nH_fx); - FOR (k=1; k<=HalfLag_fx; k++) - { - temp_a_fx = X_fx->a_fx[k]; - move16(); - temp_b_fx = X_fx->b_fx[k]; - move16(); - - en_fx = L_mac0(en_fx, temp_a_fx, temp_a_fx); - en_fx = L_mac0(en_fx, temp_b_fx, temp_b_fx); - } - - en_fx = L_shr(en_fx, 1); - temp_a_fx = X_fx->a_fx[0]; - en_fx = L_mac0(en_fx,temp_a_fx, temp_a_fx); - - /* IF (X_fx->lag_fx%2 == 0) */ - IF (s_and(X_fx->lag_fx,1) == 0) - { - temp_a_fx = X_fx->a_fx[k]; - move16(); - temp_b_fx = X_fx->b_fx[k]; - move16(); - - en_fx = L_mac0(en_fx, temp_a_fx, temp_a_fx); - en_fx = L_mac0(en_fx, temp_b_fx, temp_b_fx); - } - - return en_fx ; /* 2*X1.Q+1=Q13 */ -} - - - -/*===================================================================*/ -/* FUNCTION : DTFS_getEngy_P2A_fx () */ -/*-------------------------------------------------------------------*/ -/* PURPOSE : */ -/*-------------------------------------------------------------------*/ -/* INPUT ARGUMENTS : */ -/* _ (struct DTFS_STRUCTURE_FX) : a/b in X_fx.Q, lag in Q0 */ -/*-------------------------------------------------------------------*/ -/* OUTPUT ARGUMENTS : _ None */ -/*-------------------------------------------------------------------*/ -/* INPUT/OUTPUT ARGUMENTS : _ None */ -/*-------------------------------------------------------------------*/ -/* RETURN ARGUMENTS : */ -/* _ (Word40) en_fx: output energy, 2*X1.Q */ -/*-------------------------------------------------------------------*/ -/* CALLED FROM : TX/RX */ -/*===================================================================*/ - -Word32 DTFS_getEngy_P2A_fx( DTFS_STRUCTURE_FX *X_fx) -{ - Word16 k, HalfLag_fx; - Word32 en_fx=0; - - HalfLag_fx = shr(sub(X_fx->lag_fx, 1), 1); - HalfLag_fx = s_min(HalfLag_fx,X_fx->nH_fx); - FOR (k=1; k<=HalfLag_fx; k++) - { - en_fx = L_mac0(en_fx, X_fx->a_fx[k], X_fx->a_fx[k]); - en_fx = L_mac0(en_fx, X_fx->b_fx[k], X_fx->b_fx[k]); - } - en_fx = L_shr(en_fx, 1); - en_fx = L_mac0(en_fx,X_fx->a_fx[0], X_fx->a_fx[0]); - /* IF (X_fx->lag_fx%2 == 0) */ - IF (s_and(X_fx->lag_fx,1) == 0) - { - en_fx = L_mac0(en_fx, X_fx->a_fx[k], X_fx->a_fx[k]); - en_fx = L_mac0(en_fx, X_fx->b_fx[k], X_fx->b_fx[k]); - } - - return en_fx ; /* 2*X1.Q */ -} - - -/*=================================================================================*/ -/* FUNCTION : DTFS_getEngy_band_fx (Word16 lband, Word16 hband) */ -/*---------------------------------------------------------------------------------*/ -/* PURPOSE : compute the energy of X1.a[k] and X2.b[k] */ -/*---------------------------------------------------------------------------------*/ -/* INPUT ARGUMENTS : */ -/* _ (struct DTFS_STRUCTURE_FX) X_fx : a_fx/b_fx in X_fx.Q, lag in Q0 */ -/* _ (Word16) lband: Q0 */ -/* _ (Word16) hband: Q0 */ -/*---------------------------------------------------------------------------------*/ -/* OUTPUT ARGUMENTS : */ -/* _ (Word40) en_fx : 2*X1.Q */ -/*---------------------------------------------------------------------------------*/ -/* INPUT/OUTPUT ARGUMENTS : */ -/* _ None */ -/*---------------------------------------------------------------------------------*/ -/* RETURN ARGUMENTS : _ None. */ -/*---------------------------------------------------------------------------------*/ -/* CALLED FROM : TX */ -/*=================================================================================*/ - -/* PORTING: Handling the functions with variable no. of arguments */ - -Word32 DTFS_getEngy_band_fx(DTFS_STRUCTURE_FX X_fx,Word16 lband, Word16 hband) -{ - Word16 k, lk, hk, HalfLag ; - Word32 freq_fx, L_lband, L_hband; - Word32 en_fx=0; - - L_lband = L_mult(lband, X_fx.lag_fx); - L_hband = L_mult(hband, X_fx.lag_fx); - HalfLag = s_min(shr(sub(X_fx.lag_fx, 1), 1),X_fx.nH_4kHz_fx); - /* get lband and hband */ - FOR (k=1; k<=HalfLag; k++) - { - freq_fx = L_mult(k, 12800); - IF (L_sub(freq_fx, L_lband)>=0) - { - BREAK; - } - } - lk = k; - move16(); - FOR (k=1; k<=HalfLag; k++) - { - freq_fx = L_mult(k, 12800); - IF (L_sub(freq_fx, L_hband)>=0) - { - BREAK; - } - } - hk = k; - move16(); - - FOR (k=lk; klag_fx, 1),X_DTFS_FX->nH_fx); - move16(); - en1_fx = DTFS_getEngy_fx(X_DTFS_FX); - move16(); - - if (en1_fx == 0) - { - return 0; - } - - IF (en2_fx==0) - { - factor_fx=0; - } - ELSE - { - expa = norm_l(en2_fx); - fraca = extract_h(L_shl(en2_fx,expa)); - expa = sub(30, add(expa,shl(X_DTFS_FX->Q, 1))); - - - expb = norm_l(en1_fx); - fracb = round_fx(L_shl(en1_fx,expb)); - expb = sub(30, add(expb, shl(X_DTFS_FX->Q, 1))); - - - scale = shr(sub(fraca,fracb),15); - fracb = shl(fracb,scale); - expb = sub(expb,scale); - - tmp = div_s(fracb,fraca); - exp = sub(expb,expa); - - L_tmp = Isqrt_lc(L_deposit_h(tmp),&exp); /* Q(31-exp) */ - factor_fx = L_shr(L_tmp,1); - - } - - FOR (k=0; k<=HalfLag_fx; k++) - { - L_temp_fx = Mult_32_16(factor_fx, X_DTFS_FX->a_fx[k]); /* Q(temp+X1.Q-15) */ - X_DTFS_FX->a_fx[k] = round_fx(L_temp_fx); /* Q(temp+X1.Q-15-16)=Q(temp+X1.Q-31); */ - - L_temp_fx =Mult_32_16(factor_fx, X_DTFS_FX->b_fx[k]); /* Q(temp+X1.Q-15) */ - X_DTFS_FX->b_fx[k] = round_fx(L_temp_fx); /* Q(temp+X1.Q-15-16)=Q(temp+X1.Q-31); */ - - } - - - return en1_fx ;/* 2*X1.Q+1 = Q13 */ -} - -/*===================================================================*/ -/* FUNCTION : struct DTFS_car2pol_fx () */ -/*-------------------------------------------------------------------*/ -/* PURPOSE : Cartesian to polar representation */ -/* returning amplitudes and 0 phases */ -/*-------------------------------------------------------------------*/ -/* INPUT ARGUMENTS : */ -/* _ (struct DTFS_STRUCTURE_FX) X_fx : prototype in Cartesian domain*/ -/* (Word16) lag: length of prototype in time domain */ -/* (Word16 []) a,b: re/im of harmonics, normalized */ -/* (Word16) Q: norm factor of a/b */ -/*-------------------------------------------------------------------*/ -/* OUTPUT ARGUMENTS : */ -/* _ (struct DTFS_STRUCTURE_FX) X_fx : prototype in polar domain */ -/* (Word16) lag: length of prototype in time domain */ -/* (Word16 []) a: amplitude of harmonics, normalized */ -/* (Word16 []) b: phase of harmonics,cleared to 0 */ -/* (Word16) Q: norm factor of a */ -/*-------------------------------------------------------------------*/ -/* INPUT/OUTPUT ARGUMENTS : */ -/* _ None */ -/*-------------------------------------------------------------------*/ -/* RETURN ARGUMENTS : _ None. */ -/*-------------------------------------------------------------------*/ -/* CALLED FROM : TX/RX */ -/*===================================================================*/ -/* NOTE: output X.b (angle) is not computed and should be ignored */ -/* When phases are needed, such as in QPPP, instead uses the */ -/* Cartesian representation to avoid computing phases by arctan*/ -/*===================================================================*/ -void DTFS_car2pol_fx( - DTFS_STRUCTURE_FX *X_fx /* i/o : DTFS structure a, b, lag */ -) - -{ - Word16 k, HalfLag_fx ; - Word32 Ltemp_fx; - Word32 Lacc_fx; - Word16 exp,tmp,frac; - - HalfLag_fx = s_min(shr(sub(X_fx->lag_fx,1),1),X_fx->nH_fx); - FOR ( k=1 ; k<=HalfLag_fx; k++ ) - { - - Lacc_fx=L_mult(X_fx->a_fx[k],X_fx->a_fx[k]); /* a[k]^2, 2Q+1 */ - Lacc_fx=L_mac(Lacc_fx,X_fx->b_fx[k],X_fx->b_fx[k]); /* a[k]^2+b[k]^2, 2Q+1 */ - Lacc_fx=L_shr(Lacc_fx,3); /* Lacc=(a[k]^2+b[k]^2)/4, 2Q */ - - IF(Lacc_fx) - { - exp = norm_l(Lacc_fx); - frac = extract_h(L_shl(Lacc_fx,exp)); /* Q14 */ - exp = sub(exp, sub(30,(2*X_fx->Q))); - - tmp = div_s(16384,frac); /* Q15 */ - Ltemp_fx = Isqrt_lc(L_deposit_h(tmp),&exp); /* Q(31-exp) */ - - X_fx->a_fx[k]=extract_h(L_shl(Ltemp_fx, sub(add(X_fx->Q, exp), 15))); /* Q */ - } - ELSE - { - X_fx->a_fx[k] = 0; - move16(); - } - - X_fx->b_fx[k]= 0; - move16(); /* clear b[k] */ - } - - - IF (s_and(X_fx->lag_fx,1) == 0) - { - IF(X_fx->a_fx[k]) - { - Lacc_fx=L_mult0(X_fx->a_fx[k],X_fx->a_fx[k]); /* a[k]^2, 2Q+1 */ - Lacc_fx=L_mac0(Lacc_fx,X_fx->b_fx[k],X_fx->b_fx[k]); /* a[k]^2+b[k]^2, 2Q+1 */ - - exp = norm_l(Lacc_fx); - frac = extract_h(L_shl(Lacc_fx,exp)); /* Q14 */ - exp = sub(exp,sub(30,shl(X_fx->Q,1))); - - tmp = div_s(16384,frac); /* Q15 */ - Ltemp_fx = Isqrt_lc(L_deposit_h(tmp),&exp); /* Q(31-exp) */ - - X_fx->a_fx[k]=extract_h(L_shl(Ltemp_fx, sub(add(X_fx->Q, exp), 15))); /* Q */ - } - ELSE - { - X_fx->a_fx[k] = 0; - move16(); - } - - X_fx->b_fx[k]= 0; - move16(); /* clear b[k]; */ - } -} - - -/*==============================================================================*/ -/* FUNCTION : DTFS_setEngyHarm_fx ( ) */ -/*------------------------------------------------------------------------------*/ -/* PURPOSE : Set a band of harmonics to specified energy */ -/*----------------------------------------------------------------------- ------*/ -/* INPUT ARGUMENTS : */ -/* _ (struct DTFS_fx) : lag in Q0 */ -/* _ (Word16) f1_fx: lower bound of input, normalized by 12800, Q15 */ -/* _ (Word16) f2_fx: upper bound of input, normalized by 12800, Q15 */ -/* _ (Word16) g1_fx: lower bound of output, normalized by 12800, Q15 */ -/* _ (Word16) g2_fx: upper bound of output, normalized by 12800, Q15 */ -/* _ (Word32) en2_fx: in Q(Qen2) */ -/* _ (Word16) Qen2_fx: Q value of en2 */ -/*---------------------------------------------------------------------------- --*/ -/* OUTPUT ARGUMENTS : */ -/* _ (Word16) Qa_fx: Q value of output a[]. */ -/*----------------------------------------------------------------------------- -*/ -/* INPUT/OUTPUT ARGUMENTS : */ -/* _(struct DTFS_STRUCTURE_FX) : a_fx[] in X1_fx.Q at start, then changed to */ -/* *Qa later. */ -/*---------------------------------------------------------------------------- --*/ -/* RETURN ARGUMENTS : _ None. */ -/* _ (Word32) en1_fx: Q(2*X1.Q) */ -/*----------------------------------------------------------------------------- -*/ -/* CALLED FROM : TX/RX */ -/*============================================================================== */ -/* NOTE: This function cannot change Q because it works on a band */ -/* of harmonics, instead of the whole DTFS */ -/*============================================================================== */ -Word32 DTFS_setEngyHarm_fx( - Word16 f1_fx, /* i : lower band freq of input to control energy */ - Word16 f2_fx, /* i : upper band freq of input to control energy */ - Word16 g1_fx, /* i : lower band freq of output to control energy */ - Word16 g2_fx, /* i : upper band freq of output to control energy */ - Word32 en2_fx, /* i : Target Energy to set the DTFS to */ - Word16 Qen2_fx, /* i : Input Q format for en2 */ - Word16 *Qa_fx, /* i : Output Q format for x->a */ - DTFS_STRUCTURE_FX *X_fx /* i/o: DTFS to adjust the energy of */ -) -{ - - Word16 k, count=0, HalfLag_fx; - Word16 f_low_fx, f_high_fx, g_low_fx, g_high_fx; - Word32 L_temp_fx, factor_fx; - Word32 en1_fx; - Word32 Lacc; - Word16 exp,tmp,expa,expb,fraca,fracb,scale; - Word32 L_tmp; - Word32 Lacc_max = 0; - Word16 expp=0; - - - - f_low_fx=mult(f1_fx,X_fx->lag_fx); /* Q0 */ - f_high_fx=mult(f2_fx,X_fx->lag_fx); /* Q0 */ - g_low_fx=mult(g1_fx,X_fx->lag_fx); /* Q0 */ - g_high_fx=mult(g2_fx,X_fx->lag_fx); /* Q0 */ - HalfLag_fx = s_min(f_high_fx,shl(X_fx->nH_fx,1)); - - Lacc = L_deposit_l(0); - FOR (k=f_low_fx+1 ; k<=HalfLag_fx; k++) - { - Lacc = L_mac0(Lacc, X_fx->a_fx[k], X_fx->a_fx[k]); /* 2*X1.Q */ - Lacc_max = L_max( Lacc_max, Lacc); - - count=add(count,1); - } - - IF( L_sub( Lacc_max, 2147483647 ) >= 0 ) - { - tmp = sub(HalfLag_fx, f_low_fx); - exp = norm_s(tmp); - expp = sub(15,exp); - - Lacc = L_deposit_l(0); - FOR( k=f_low_fx+1; k<=HalfLag_fx; k++ ) - { - L_tmp = L_mult( X_fx->a_fx[k], X_fx->a_fx[k] ); - Lacc = L_add(Lacc, L_shr(L_tmp,expp)); /* 2*X1.Q-expp */ - count=add(count,1); - } - } - - if (count <= 0) - { - count = 1; - move16(); - } - - exp = norm_s(count); - tmp = div_s(shl(1,sub(14,exp)),count);/* 29 - exp */ - en1_fx = L_shl( Mult_32_16(Lacc , tmp), sub(exp,14)); - - test(); - IF (en1_fx>0 && en2_fx > 0) - { - /* factor_fx = sqrt_divide_dp((Word40)en2_fx, en1_fx, sub(Qen2_fx, shl(X_fx->Q, 1)), &temp_fx,1); : Q(temp) */ - expa = norm_l(en2_fx); - fraca = extract_h(L_shl(en2_fx,expa)); - expa = sub(30,add(expa,Qen2_fx)); - - - expb = norm_l(en1_fx); - fracb = round_fx(L_shl(en1_fx,expb)); - - IF( L_sub( Lacc_max, 2147483647 ) >= 0 ) - { - expb = sub( 30, add( expb, sub(shl(X_fx->Q, 1),expp) ) ); - } - ELSE - { - expb = sub(30, add(expb, shl(X_fx->Q, 1))); - } - - scale = shr(sub(fraca,fracb),15); - fracb = shl(fracb,scale); - expb = sub(expb,scale); - - tmp = div_s(fracb,fraca); - exp = sub(expb,expa); - - L_tmp = Isqrt_lc(L_deposit_h(tmp),&exp); /* Q(31-exp) */ - - IF( L_sub( Lacc_max, 2147483647 ) >= 0 ) - { - factor_fx = L_shr(L_tmp,add(1,s_min(2,expp))); - } - ELSE - { - factor_fx = L_shr(L_tmp,1); - } - - - } - ELSE - { - factor_fx = L_deposit_l(0); - } - - HalfLag_fx = s_min(g_high_fx,shl(X_fx->nH_fx,1)); - FOR (k=g_low_fx+1; k<=HalfLag_fx; k++) - { - /*L_temp_fx =(Word32)Mpy_32_16(extract_h(factor_fx),extract_l(factor_fx), X_fx->a_fx[k]); move32(); */ /* Q(temp+X1.Q-15) */ - L_temp_fx = Mult_32_16(factor_fx, X_fx->a_fx[k]); /* Q(temp+X1.Q-15) */ - X_fx->a_fx[k] = round_fx(L_temp_fx); /* Q(temp+X1.Q-15-16)=Q(temp+X1.Q-31); */ - } - - if ( L_sub( Lacc_max, 2147483647 ) >= 0) - { - *Qa_fx = sub( sub(X_fx->Q,add(1,s_min(2,expp))) , exp); - } - else - { - *Qa_fx = sub( sub(X_fx->Q,1) , exp); - } - - return en1_fx; /* Q(2*X1.Q) */ - - -} -/*===================================================================*/ -/* FUNCTION : cubicPhase_fx () */ -/*-------------------------------------------------------------------*/ -/* PURPOSE : Compute cubic phase track for WI synthesis */ -/*-------------------------------------------------------------------*/ -/* INPUT ARGUMENTS : */ -/* _ (Word16) ph1_fx : initial phase, Q15 (normalized by 2pi) */ -/* _ (Word16) ph2_fx : final phase, Q15 (normalized by 2pi) */ -/* _ (Word16) L1 : previous pitch lag, Q0 */ -/* _ (Word16) L2 : current pitch lag, Q0 */ -/* _ (Word16) N : length of phase track, Q0 */ -/*-------------------------------------------------------------------*/ -/* OUTPUT ARGUMENTS : */ -/* _ (Word32 []) phOut_fx : phase track, Q27 (normalized by 2pi) */ -/*-------------------------------------------------------------------*/ -/* INPUT/OUTPUT ARGUMENTS : */ -/* _ None */ -/*-------------------------------------------------------------------*/ -/* RETURN ARGUMENTS : _ None. */ -/*-------------------------------------------------------------------*/ -/* CALLED FROM : TX/RX */ -/*===================================================================*/ -/* NOTE: This function outputs phase in (-1,1) */ -/*===================================================================*/ -static -void cubicPhase_fx( - Word16 ph1_fx, Word16 ph2_fx, Word16 L1, Word16 L2, - Word16 N, Word32 *phOut_fx -) -{ - Word16 n; - Word16 n2; - Word16 f1, f2; /* invert of L1, L2, Q19 */ - Word16 factor, temp; - Word16 c0, c1, c2, c3; /* cubic polynomial coefficients */ - /* Q33, Q27, Q19, Q15 respectively */ - Word32 Ltemp1, Ltemp2, Ltemp3,Ltemp4,Ltemp; - Word16 tmp,exp; - Word32 Lacc; - Word16 expa,expb,fraca,fracb,scale; - Word32 L_tmp,L_tmp1; - Word16 num_flag,den_flag; - Word32 N2; - Word16 dbgshft; - num_flag = 0; - den_flag = 0; - - N=sub(N,L2); - - exp = norm_s(L1); - tmp = div_s(shl(1,sub(14,exp)),L1); - L_tmp = L_shl(tmp,exp+6); - f1 = round_fx(L_tmp); - - exp = norm_s(L2); - tmp = div_s(shl(1,sub(14,exp)),L2); - L_tmp = L_shl(tmp,exp+6); - Ltemp4 = inverse_table[L2]; - f2 = round_fx(L_tmp); - - c3 = ph1_fx; - move16(); /* c3 in Q15 */ - c2 = f1; - move16();/* c2 in Q19 */ - - Ltemp1 = L_sub(ph1_fx,ph2_fx); /* Ltemp1=ph1_fx-ph2_fx, Q15 */ - Ltemp2 = L_add(f1,f2); /* Ltemp2=0.5*(f1+f2), Q20 */ - temp = extract_l(Ltemp2);/* Q20 */ - - IF(temp<0) - { - L_tmp1 = L_shl(L_add(65536,temp),14); /* Q30 */ - L_tmp = Mult_32_16(L_tmp1,N); /* 30-15=15 */ - Ltemp2 = L_shl(L_tmp,1); - } - ELSE - { - Ltemp2 = (Word32)L_mult0(N,temp); /* Ltemp2=0.5*N*(f1+f2), Q20 */ - } - - Ltemp1 = L_add(L_shl(Ltemp1,5),Ltemp2); /* Ltemp1=ph1_fx - ph2_fx + 0.5*N*(f2+f1), Q16, Q20 */ - - factor = round_fx(L_shr(Ltemp1,4)); /* factor in Q0 */ - - c1 = sub(f2,f1); /* c1=f2-f1, Q19 */ - Ltemp1 = L_sub(ph2_fx,ph1_fx); /* Q15 */ - Ltemp2 = L_mult(N,f1); /* Ltemp2=N*f1, Q20 */ - Ltemp2 = L_sub(L_shl(L_deposit_h(factor),4),Ltemp2); /* Ltemp2=factor-N*f1, Q20 */ - Ltemp1 = L_add(Ltemp2,L_shl(Ltemp1,5)); /* Ltemp1 in Q20 */ - - IF(sub(N,180)>0) - { - Ltemp2 = L_shl(L_mult0(N,N),14); - Ltemp2 = L_shl(Mult_32_16(Ltemp2,N),1); - - /* IF(N%2) */ - if(s_and(N,1) == 1) - { - Ltemp2 = L_add(Ltemp2,1); - } - } - ELSE - { - Ltemp2=L_shr(L_mult(N,N),1); - Ltemp2 = L_mult0(N,extract_l(Ltemp2)); /* Ltemp2=N^3 */ - } - Ltemp3 = L_mult(N,c1); /* Q20 */ - Ltemp3 = L_sub(Ltemp3,L_shl(Ltemp1,1)); /* Ltemp3=N*c1-2*Ltemp1, Q20 */ - - - IF (L_sub(L_abs(Ltemp3),L_shl(Ltemp2,8)) >= 0) - { - Lacc = L_add(MIN_32, 0); - if (Ltemp3 > 0) - { - Lacc = L_add(MAX_32, 0); - } - - c0 = extract_h(Lacc); /* c0 in Q33 */ - } - ELSE - { - expa = norm_l(Ltemp3); - fraca = extract_h(L_shl(Ltemp3,expa)); - expa = sub(30,add(expa, 20)); - if(fraca<0) - { - num_flag = 1; - move16(); - } - - expb = norm_l(Ltemp2); - fracb = extract_h(L_shl(Ltemp2,expb)); - expb = sub(30,expb); - if(fracb<0) - { - den_flag = 1; - move16(); - } - - if(num_flag) - { - fraca = negate(fraca); - } - if(den_flag) - { - fracb = negate(fracb); - } - scale = shr(sub(fracb,fraca),15); - fraca = shl(fraca,scale); - expa = sub(expa,scale); - - tmp = div_s(fraca,fracb); /* 15-exp */ - exp = sub(expa,expb); - test(); - if(num_flag && !den_flag) - { - tmp = negate(tmp); - } - test(); - if(den_flag && !num_flag) - { - tmp = negate(tmp); - } - - Lacc = L_shl(tmp,add(exp,34)); - Lacc = L_add(Lacc,0x08000); - c0 = extract_h(Lacc); /* c0 in Q33 */ - } - - Ltemp1 = L_mult(N,N); /* Ltemp1=2*N*N */ - Ltemp1 = L_add(Ltemp1,L_shr(Ltemp1,1)); /* Ltemp1=3*N*N, max is 3*140*140 */ - - /* patch added for time warping support, where N can be more than 140 */ - dbgshft= norm_l(Ltemp1); - Ltemp1= L_shl(Ltemp1,dbgshft); - temp = extract_h(Ltemp1); - Ltemp1 = (Word32)L_shl((Word32)L_mult0(c0,temp), sub(16,dbgshft)); /* Ltemp1=3*N*N*c0, Q33 */ - /* Patch end */ - - num_flag = den_flag = 0; - move16(); - move16(); - Ltemp1 = L_sub(L_shr(L_deposit_h(c1),2),Ltemp1); /* Ltemp1=c1-3*N*N*c0, Q33 */ - - expa = norm_l(Ltemp1); - fraca = extract_h(L_shl(Ltemp1,expa)); - expa = sub(30,add(expa, 33)); - if(fraca<0) - { - num_flag = 1; - move16(); - } - - expb = norm_l(N); - fracb = extract_h(L_shl(N,expb)); - expb = sub(30,expb); - if(fracb<0) - { - den_flag = 1; - move16(); - } - - if(num_flag) - { - fraca = negate(fraca); - } - if(den_flag) - { - fracb = negate(fracb); - } - scale = shr(sub(fracb,fraca),15); - fraca = shl(fraca,scale); - expa = sub(expa,scale); - - tmp = div_s(fraca,fracb); /* 15-exp */ - exp = sub(expa,expb); - test(); - if(num_flag && !den_flag) - { - tmp = negate(tmp); - } - test(); - if(den_flag && !num_flag) - { - tmp = negate(tmp); - } - - Lacc = L_shl(tmp,exp+27); - Lacc = L_add(Lacc,0x08000); - c1 = extract_h(Lacc); /* c1 in Q27 */ - - - /* Computation of the phase value at each sample point */ - /* ph[n]= c0*n^3+c1*n^2+c2*n+c3, Q15 */ - phOut_fx[0] = L_shl(ph1_fx,11);/* Q27 */ - - IF(sub(N,181) < 0) - { - FOR (n=1; n0) - { - IF(sum_a_fx[i]<0) - { - L_temp = L_negate(sum_a_fx[i]); - } - ELSE - { - L_temp = L_add(sum_a_fx[i], 0); - } - - expb = norm_l(L_temp); - fracb = round_fx(L_shl(L_temp,expb)); - expb = sub(30, add(expb,X_fx.Q)); - - - expa = norm_l(count[i]); - fraca = extract_h(L_shl(count[i],expa)); - expa = sub(30,expa); - - scale = shr(sub(fraca,fracb),15); - fracb = shl(fracb,scale); - expb = sub(expb,scale); - - tmp = div_s(fracb,fraca); - exp = sub(expb,expa); - L_tmp = L_shl(tmp, add(exp,14)); - - out_fx[i] = round_fx(L_tmp); - } - } -} -/*===================================================================*/ -/* FUNCTION : erb_slot_fx () */ -/*-------------------------------------------------------------------*/ -/* PURPOSE : Allocate harmonics in ERB bins */ -/*-------------------------------------------------------------------*/ -/* INPUT ARGUMENTS : */ -/* _ (Word16) lag_fx : pitch lag, Q0 */ -/*-------------------------------------------------------------------*/ -/* OUTPUT ARGUMENTS : */ -/* _ (Word16 []) out_fx : number of harmonics in the ERB bins, Q0 */ -/* _ (Word16 []) mfreq_fx : frequency bounds of the ERB bins, Q15 */ -/*-------------------------------------------------------------------*/ -/* INPUT/OUTPUT ARGUMENTS : */ -/* _ None */ -/*-------------------------------------------------------------------*/ -/* RETURN ARGUMENTS : _ None. */ -/*-------------------------------------------------------------------*/ -/* CALLED FROM : TX/RX */ -/*===================================================================*/ -/* NOTE: Frequency is normalized by 12800, i.e. 1=12800Hz */ -/*===================================================================*/ -void erb_slot_fx( - Word16 lag_fx, /* i : input lag */ - Word16 *out_fx, /* o : ERB slots */ - Word16 *mfreq_fx, /* o : ERB frequencies */ - Word16 num_erb_fx /* i : number of ERBs */ -) -{ - Word16 i, j,n ; - Word16 diff_fx; - Word16 upper_cut_off_freq_fx; - Word32 Ltemp_fx; - Word32 mf_fx[NUM_ERB_WB]; - Word16 nH_band_fx; - Word16 exp,tmp; - Word32 L_tmp1,L_tmp; - Word16 fraca,fracb,expa,expb,scale; - - const Word16 *erb_fx=NULL;/*move16(); */ - - upper_cut_off_freq_fx=4000; - move16(); - - IF (sub(num_erb_fx,NUM_ERB_NB)==0) - { - upper_cut_off_freq_fx=4000; - move16(); - erb_fx=&(erb_NB_fx[0]); - move16(); - } - ELSE IF (sub(num_erb_fx,NUM_ERB_WB)==0) - { - upper_cut_off_freq_fx=6400; - move16(); - erb_fx=&(erb_WB_fx[0]); - move16(); - } - - exp = norm_s(lag_fx); - tmp = div_s(shl(1, sub(14,exp)),lag_fx); /* Q29-exp */ - L_tmp1 = L_mult(12800,tmp); /* Q(30-exp) */ - diff_fx = extract_h(L_shl(L_tmp1,sub(exp,14))); /* Q0 */ - - exp = norm_s(diff_fx); - tmp = div_s(shl(1,sub(14,exp)),diff_fx); /* Q29-exp */ - L_tmp1 = L_mult(upper_cut_off_freq_fx,tmp); /* Q(30-exp) */ - nH_band_fx = round_fx(L_shl(L_tmp1,sub(exp,14))); /* Q0 */ - - FOR (i=0; i=diff_fx)/* Q0 compare */ - { - nH_band_fx = add(nH_band_fx,1);/* Q0 */ - } - - n=s_min(shr(lag_fx,1),nH_band_fx); - exp = norm_s(lag_fx); - tmp = div_s(shl(1,sub(14,exp)),lag_fx); /* Q29-exp */ - L_tmp = L_shl(tmp, add(exp,6)); - diff_fx =round_fx(L_tmp); - - j=0; - move16(); - FOR (i=0; i<=n; i++) - { - Ltemp_fx=L_mult(diff_fx,i); /* Ltemp=i*diff, Q20 */ - /* freq=round32_16(L_shl(Ltemp,11)); : freq=i*diff, Q15 */ - - IF (sub(num_erb_fx,NUM_ERB_NB)==0) - { - Ltemp_fx=L_min(Ltemp_fx,0x050000); /* 0x50000=0.3125 in Q20 (4000Hz) */ - } - ELSE IF (sub(num_erb_fx,NUM_ERB_WB)==0) - { - Ltemp_fx=L_min(Ltemp_fx,0x080000); /* 0x80000=0.5 in Q20 (6400Hz) */ - } - - FOR ( ; j0) - { - expb = norm_l(mf_fx[j]); - fracb = round_fx(L_shl(mf_fx[j],expb)); - expb = sub(30, add(expb,20)); - - - expa = norm_l(out_fx[j]); - fraca = extract_h(L_shl(out_fx[j],expa)); - expa = sub(30,expa); - - scale = shr(sub(fraca,fracb),15); - fracb = shl(fracb,scale); - expb = sub(expb,scale); - - tmp = div_s(fracb,fraca); - exp = sub(expb,expa); - L_tmp = L_shl(tmp,add(exp,16)); - - mfreq_fx[j] = round_fx(L_tmp); - - } - } - -} -/*===================================================================*/ -/* FUNCTION : DTFS_erb_inv_fx () */ -/*-------------------------------------------------------------------*/ -/* PURPOSE : Convert erb into harmonics */ -/*-------------------------------------------------------------------*/ -/* INPUT ARGUMENTS : */ -/* _ (Word16 []) in_fx : erb output, Q13 */ -/* _ (Word16 []) slot_fx : number of harmonics in the ERB bins, Q0 */ -/* _ (Word16 []) mfreq_fx : frequency bounds of the ERB bins, Q15 */ -/* _ (struct DTFS_STRUCTURE_FX) (Word16) lag_fx: length of */ -/* prototype in time domain */ -/*-------------------------------------------------------------------*/ -/* OUTPUT ARGUMENTS : */ -/* _ (struct DTFS_STRUCTURE_FX) : prototype in polar domain */ -/* (Word16 []) a_fx: amplitude, normalized */ -/* (Word16) Q: norm factor of a */ -/*-------------------------------------------------------------------*/ -/* INPUT/OUTPUT ARGUMENTS : */ -/* _ None */ -/*-------------------------------------------------------------------*/ -/* RETURN ARGUMENTS : _ None. */ -/*-------------------------------------------------------------------*/ -/* CALLED FROM : TX/RX */ -/*===================================================================*/ - -void DTFS_erb_inv_fx( - Word16 *in_fx, /* i : ERB inpt */ - Word16 *slot_fx, /* i : ERB slots filled based on lag */ - Word16 *mfreq_fx, /* i : erb frequence edges */ - DTFS_STRUCTURE_FX *X_fx, /* o : DTFS after erb-inv */ - Word16 num_erb_fx /* i : Number of ERB bands */ -) -{ - - Word16 i, j, m_fx=0,n,HalfLag_fx; - Word16 diff_fx;/* 1/lag, Q19 */ - Word16 d1,d2, q[MAXLAG_WI], min_q=0; - Word16 d1h, d1l, d2h, d2l; - Word16 freq_fx, f_fx[NUM_ERB_WB+2], amp_fx[NUM_ERB_WB+2] ; - Word16 upper_cut_off_freq_fx = 0; - Word32 Ltemp_fx,Ltemp2_fx; - Word32 Lacc_fx; - Word16 exp,tmp; - - - IF (sub(num_erb_fx,NUM_ERB_NB)==0) - { - upper_cut_off_freq_fx=0x02800; - move16();/* 0x2800=0.3125 in Q15 (4000Hz) */ - } - ELSE IF (sub(num_erb_fx,NUM_ERB_WB)==0) - { - upper_cut_off_freq_fx=0x04000; - move16();/* 0x4000=0.5 in Q15 (6400Hz) */ - } - - f_fx[m_fx]=0; - move16(); - amp_fx[m_fx]=0; - move16(); - m_fx=add(m_fx,1); - - FOR (i=0; ilag_fx); - tmp = div_s(shl(1,sub(14,exp)),X_fx->lag_fx);/* 29-exp */ - diff_fx= shl(tmp,exp-10); /* Q19 */ - - min_q = EVS_SW_MAX; - move16(); - X_fx->a_fx[0]=0; - move16(); - - HalfLag_fx=s_min(shr(X_fx->lag_fx,1),X_fx->nH_fx); - - j=1; - move16(); - FOR (i=1 ; i<=HalfLag_fx; i++) - { - Ltemp_fx=L_mult(diff_fx,i); /* Ltemp=i*diff, Q20 */ - freq_fx=round_fx(L_shl(Ltemp_fx,11)); /* Q15 */ - - freq_fx=s_min(freq_fx,upper_cut_off_freq_fx); /* 0x4000 is 0.5 in Q15 */ - - FOR ( ; j=0) - { - d2=sub(freq_fx,f_fx[j-1]); - Ltemp_fx=L_mac(L_mult(amp_fx[j],d2),amp_fx[j-1],d1); /* Q29 */ - d2=sub(f_fx[j],f_fx[j-1]); /* Q15 */ - /* Ltemp2_fx=invert_dp((Word40)d2, 4, &n,1); : Ltemp2=1/d2, Q(61-15-n) */ - exp = norm_s(d2); - tmp = div_s(shl(1,sub(14,exp)),d2);/* 29-exp */ - /* L_tmp = L_shr(tmp,8); */ - Ltemp2_fx = L_shl(tmp,16); - n = add(exp,16); - - d1h=extract_h(Ltemp_fx); - d1l=extract_l(Ltemp_fx); - d2h=extract_h(Ltemp2_fx); - d2l=extract_l(Ltemp2_fx); - Ltemp_fx=(Word32)L_mult0(d1h,d2l); - Lacc_fx=L_mac0((Word32)Ltemp_fx,d2h,d1l); - Ltemp_fx=L_add((Word32)L_shr(Lacc_fx,15),L_mult(d1h,d2h)); /* 46-n+29-31 */ - d2h=norm_l(Ltemp_fx); /* d2h is 0 IF Ltemp=0 */ - if( Ltemp_fx == 0 ) - { - d2h = 31; - move16(); - } - X_fx->a_fx[i]=round_fx(L_shl(Ltemp_fx,d2h)); /* Q(28-n+d2h) */ - q[i]=add(sub(28,n),d2h); - min_q=s_min(min_q,q[i]); - - BREAK ; - } - } - } - /* block normalize a[i] */ - FOR (i=1; i<=HalfLag_fx; i++) - { - X_fx->a_fx[i]=shl(X_fx->a_fx[i],sub(min_q,q[i])); - move16(); - } - - X_fx->Q=min_q; -} - -/*===================================================================*/ -/* FUNCTION : LPCPowSpect_fx () */ -/*-------------------------------------------------------------------*/ -/* PURPOSE : Compute LPC power spectrum */ -/*-------------------------------------------------------------------*/ -/* INPUT ARGUMENTS : */ -/* _ (Word16 []) freq : ERB frequency bounds, Q15 */ -/* _ (Word16 []) LPC : LPC coefficients, Q12 */ -/* _ (Word16) Nf: number of ERB bins, Q0 */ -/* _ (Word16) Np : order of LPC, Q0 */ -/*-------------------------------------------------------------------*/ -/* OUTPUT ARGUMENTS : */ -/* _ (Word16 []) out : LPC power spectrum, Q7 */ -/*-------------------------------------------------------------------*/ -/* INPUT/OUTPUT ARGUMENTS : */ -/* _ None */ -/*-------------------------------------------------------------------*/ -/* RETURN ARGUMENTS : _ None. */ -/*-------------------------------------------------------------------*/ -/* CALLED FROM : TX */ -/*===================================================================*/ -/* NOTE: Frequency is normalized by 12800, i.e. 1=12800Hz */ -/*===================================================================*/ -void LPCPowSpect_fx(Word16 *freq, Word16 Nf, Word16 *LPC, Word16 Np, - Word16 *out) -{ - Word16 i, k; - Word16 w; /* Q9 */ - Word16 t1, dt; - /*Word16 t2; */ - Word16 dh, dl; - Word32 Re, Im; /* Q27 */ - Word32 Ltemp, Lw; - Word32 Lacc; - Word16 tmp,exp; - - FOR (k=0; k 0) - { - tmp = div_s(16384, tmp); /* 15+exp1 */ - } - ELSE - { - tmp = 0; - move16(); - } - Ltemp = L_deposit_h(tmp); - out[k] = round_fx(L_shl(Ltemp,negate(add(exp,8)))); - - /* out[k] = shl(tmp,-exp-8); in Q7 */ - - } -} -/*===================================================================*/ -/* FUNCTION : erb_diff_fx () */ -/*-------------------------------------------------------------------*/ -/* PURPOSE : Quantize erb amplitude for QPPP */ -/*-------------------------------------------------------------------*/ -/* INPUT ARGUMENTS : */ -/* _ (Word16) pl : previous pitch lag, Q0 */ -/* _ (Word16) l : current pitch lag, Q0 */ -/* _ (Word16 []) prev_erb : Previous erb amplitude, Q13 */ -/* _ (Word16 []) curr_erb : Current erb amplitude, Q13 */ -/* _ (Word16 []) curr_lsp : LSP coefficients, Q12 */ -/* _ (Word16 []) num_erb : Number of ERBs , Q0 */ -/*-------------------------------------------------------------------*/ -/* OUTPUT ARGUMENTS : */ -/* _ (Word16 []) index: quantized differential erb index */ -/*-------------------------------------------------------------------*/ -/* INPUT/OUTPUT ARGUMENTS : */ -/* _ None */ -/*-------------------------------------------------------------------*/ -/* RETURN ARGUMENTS : _ None. */ -/*-------------------------------------------------------------------*/ -/* CALLED FROM : TX */ -/*===================================================================*/ -static -void erb_diff_fx( - const Word16 *prev_erb, /* i : previous ERB */ - Word16 pl, /* i : previous lag */ - const Word16 *curr_erb, /* i : current ERB */ - Word16 l, /* i : current lag */ - const Word16 *curr_lsp, /* i : current LSP coefficients */ - Word16 *index, /* 0 : ERB index */ - Word16 num_erb /* i : Number of ERBs */ -) -{ - Word16 i; - Word16 pslot[NUM_ERB_WB], cslot[NUM_ERB_WB]; - Word16 tmp, t_prev_erb[NUM_ERB_WB], LPC[M+1], mfreq[NUM_ERB_WB], PowSpect[NUM_ERB_WB], dif_erb[NUM_ERB_WB] ; - const Word16 *AmpCB1_fx = NULL; - - IF (sub(num_erb,NUM_ERB_NB)==0) - { - AmpCB1_fx=AmpCB1_NB_fx; - move16(); - } - ELSE IF (sub(num_erb,NUM_ERB_WB)==0) - { - AmpCB1_fx=AmpCB1_WB_fx; - move16(); - - } - erb_slot_fx (l,cslot,mfreq,num_erb);/* cslot in Qo and mfreq in Q15 */ - erb_slot_fx (pl,pslot,t_prev_erb,num_erb); - - FOR (i=0; i0) - { - tmp = t_prev_erb[0] ; - move16(); - FOR (i=0; i0) - { - tmp = t_prev_erb[num_erb-1] ; - move16(); - - FOR(i=sub(num_erb,1); i>=0; i--) - { - IF (pslot[i]!=0) - { - tmp = t_prev_erb[i]; - move16(); - } - ELSE - { - t_prev_erb[i] = tmp ; - move16(); - } - } - } - FOR(i=0; i0) - { - tmp_fx = t_prev_erb_fx[0]; - move16(); /* Q13 */ - FOR (i=0; i0) - { - tmp_fx = t_prev_erb_fx[sub(num_erb_fx,1)]; /* Q13 */ - FOR (i=sub(num_erb_fx,1); i>=0; i--) - { - - IF (pslot_fx[i] != 0) - { - tmp_fx = t_prev_erb_fx[i]; - move16(); /* Q13 */ - } - ELSE - { - t_prev_erb_fx[i] = tmp_fx; - move16(); /* Q13 */ - } - } - } - - tmp_fx = add(shl(index_fx[0],3),shl(index_fx[0],1)); /* tmp_fx=10*index_fx[0] */ - FOR (i=1; i<11; i++) - { - - IF (cslot_fx[i]!=0) - { - curr_erb_fx[i] = add(AmpCB1_fx[sub(add(tmp_fx,i),1)],t_prev_erb_fx[i]); - move16();/* Q13+Q13=Q13 */ - curr_erb_fx[i] = s_max(0, curr_erb_fx[i]); - move16(); - } - ELSE - curr_erb_fx[i] = 0; - move16(); - } - - tmp_fx = add(shl(index_fx[1],3),index_fx[1]); /* tmp=9*index[1] */ - tmp2_fx = mult(shl(index_fx[1],6),5632);/* temp=11*index_fx[1] */ - tmp_loop = sub(num_erb_fx,2); - FOR (i=11; iupper_cut_off_freq_fx,0x2800)==0)/* 4000 hz normalized to 12800 in Q15 */ - { - num_erb=NUM_ERB_NB; - move16(); - PowerCB_fx=PowerCB_NB_fx; - move16(); - } - ELSE IF (sub(X_fx->upper_cut_off_freq_fx,0x4000)==0)/* 6400 hz normalized to 12800 in Q15 */ - { - num_erb=NUM_ERB_WB; - move16(); - PowerCB_fx=PowerCB_WB_fx; - move16(); - } - - /* Get weighting and target */ - quant_target_fx(X_fx,curr_lpc_fx, w, target, sin_tab, cos_tab); - - /* Power Quantization in log domain */ - target[0]=sub(target[0],*lastLgainE_fx); - move16(); - target[1]=sub(target[1],*lastHgainE_fx); - move16(); - - minerror = L_add(EVS_LW_MAX, 0); - *POWER_IDX = 0; - move16(); - - j=0; - move16(); - FOR (n=0; n=0 && d2>=0) - { - Ltemp= Mult_32_16(Ltemp,0x6666); /* *=0.8 */ - } - IF (L_sub(Ltemp, minerror)<0) - { - minerror = L_add(Ltemp, 0); - *POWER_IDX = j ; - move16(); - } - j = add(j,1); - } - DTFS_to_erb_fx (*X_fx,curr_erb_fx) ; - - FOR(j=0; jlag_fx, slot, mfreq,num_erb) ; - /* Amplitude Quantization */ - - - erb_diff_fx(lasterbE_fx,pl,curr_erb_fx,X_fx->lag_fx,curr_lpc_fx,AMP_IDX,num_erb); - - - /* Dequantization of prototype */ - /* PORTING: Removing the references */ - /* DTFS_dequant_cw_fx(pl, *POWER_IDX, AMP_IDX,lastLgainE_fx,lastHgainE_fx, lasterbE_fx,X_fx,num_erb,curr_erb_fx); */ - - /* Determine IF the amplitude quantization is good enough */ - erb_add_fx(curr_erb_fx,X_fx->lag_fx,lasterbE_fx,pl,AMP_IDX,num_erb); - - curr_erb_fx[0] = mult_r(curr_erb_fx[1],9830); - move16(); /* 0.3 inQ15 leaves curr_erb in Q13 */ - curr_erb_fx[sub(num_erb,2)] = mult_r(curr_erb_fx[sub(num_erb,3)],9830);/* Q13 */ - - curr_erb_fx[sub(num_erb,1)] = 0; - move16(); - flag=1; - move16(); - - Ltemp = L_deposit_l(0); - n=0; - move16(); - FOR (j=1; j<10; j++) - { - IF (slot[j]!=0) - { - Ltemp=L_add(Ltemp,abs_s(sub(erb_uq[j],curr_erb_fx[j]))); /* Q13 */ - n=add(n,1); /* n++ */ - } - } - - exp = norm_s(n); - tmp = div_s(shl(1,sub(14,exp)),n);/* 29 - exp */ - Lacc = L_shl( Mult_32_16(Ltemp , tmp), exp +4); - - tmp=round_fx(Lacc); /* tmp in Q15 */ - - test(); - if (sub(tmp,0x3C29)>0 && add(target[0],819)>0) - { - flag = 0 ; /* Bumping up */ move16(); - } - - /* mfreq normalized (2.56) in Q15 */ - DTFS_erb_inv_fx(curr_erb_fx, slot, mfreq, X_fx,num_erb) ; - - - /* Back up the lasterbD memory after power normalization */ - DTFS_setEngyHarm_fx(236,2828,0,2828,1,0,&Ql,X_fx); - DTFS_setEngyHarm_fx(2828,X_fx->upper_cut_off_freq_of_interest_fx,2828,X_fx->upper_cut_off_freq_fx,1,0,&Qh,X_fx); - - /* Need to unify the Q factors of both bands */ - X_fx->Q=s_min(Ql,Qh); /* set Q factor to be the smaller one */ - n=sub(Ql,Qh); /* compare band Q factors */ - - - /* This logic adjusts difference between Q formats of both bands */ - - IF (n<0) - rshiftHarmBand_fx(X_fx,2828, X_fx->upper_cut_off_freq_fx,n); - ELSE IF (n>0) - rshiftHarmBand_fx(X_fx,0, 2828, sub(Qh,Ql)); - - tmp=shl(*POWER_IDX,1); /* tmp=2*POWER_IDX */ - *lastLgainE_fx =add(*lastLgainE_fx, PowerCB_fx[tmp]) ; /* Q11 */ - *lastHgainE_fx =add(*lastHgainE_fx, PowerCB_fx[tmp+1]); /* Q11 */ - - Ltemp=log10_fx(X_fx->lag_fx); /* Ltemp=10*log10(lag), Q23 */ - logLag_fx= Mult_32_16(Ltemp,0x6666); /* logLag=log10(lag), Q26 */ - - Ltemp=L_sub(L_shr(L_deposit_h(*lastLgainE_fx),1),logLag_fx); /* Ltemp=Lgain-log10(lag), Q26 */ - - L_tmp=pow_10(Ltemp,&Q); /* Lacc=10^Lgain/lag, Q15 */ - n=norm_l(L_tmp); - Ltemp=(Word32)L_shl(L_tmp,n); /* Ltemp in Q(15+n) */ - - - DTFS_setEngyHarm_fx(236,2828,0,2828,Ltemp, add(Q,n),&Ql,X_fx); - - Ltemp=L_sub(L_shr(L_deposit_h(*lastHgainE_fx),1),logLag_fx); /* Ltemp=Hgain-log10(lag), Q26 */ - - /* Ltemp = L_shr(Ltemp,1); */ - L_tmp = pow_10(Ltemp,&Q); /* Lacc=10^Lgain/lag, Q15 */ - n=norm_l(L_tmp); - Ltemp=(Word32)L_shl(L_tmp,n); /* Ltemp in Q(15+n) */ - - DTFS_setEngyHarm_fx(2828,X_fx->upper_cut_off_freq_of_interest_fx,2828,X_fx->upper_cut_off_freq_fx,Ltemp,add(Q,n),&Qh,X_fx); - /* Need to unify the Q factors of both bands */ - X_fx->Q=s_min(Ql,Qh); /* set Q factor to be the smaller one */ - n=sub(Ql,Qh); /* compare band Q factors */ - - IF (n<0) - rshiftHarmBand_fx(X_fx,2828, X_fx->upper_cut_off_freq_fx,n); - ELSE IF (n>0) - rshiftHarmBand_fx(X_fx,0, 2828, sub(Qh,Ql)); - - return flag; -} -/*===================================================================*/ -/* FUNCTION : struct quant_target_fx() */ -/*-------------------------------------------------------------------*/ -/* PURPOSE : Get weighting and target for power quantization */ -/*-------------------------------------------------------------------*/ -/* INPUT ARGUMENTS : */ -/* _ (Word16 []) curr_lpc: LPC coefficients, Q12 */ -/* _ (Word16 []) sin_tab: sine table based on lag, Q15 */ -/* _ (Word16 []) cos_tab: cosine table based on lag, Q15 */ -/*-------------------------------------------------------------------*/ -/* OUTPUT ARGUMENTS : */ -/* _ (Word16[]) w: Weighting for power quantization, Q15 */ -/* _ (Word16[]) target: Power of 2 bands for quantization, Q11 */ -/*-------------------------------------------------------------------*/ -/* INPUT/OUTPUT ARGUMENTS : */ -/* _ (struct DTFS_fx) X : prototype in polar domain */ -/* (Word16) lag: length of prototype in time domain */ -/* (Word16 []) a: amplitude of harmonics, normalized */ -/* (Word16) Q: norm factor of a */ -/*-------------------------------------------------------------------*/ -/* RETURN ARGUMENTS : */ -/* _ None */ -/*-------------------------------------------------------------------*/ -/* CALLED FROM : TX */ -/*===================================================================*/ -/* NOTE: This function is used by quant_cw_fx and quant_cw_memless_fx*/ -/*===================================================================*/ -void quant_target_fx( DTFS_STRUCTURE_FX *X_fx,const Word16 *curr_lpc, Word16 *w, Word16 *target, - Word16 *sin_tab, Word16 *cos_tab) -{ - Word16 tmp, n,exp; - Word16 Ql, Qh; - Word32 Ltemp1, Ltemp, Ltemp2, logLag, Ltemp3,Lacc; - - tmp=sub(shl(X_fx->Q,1),13); /* tmp=2Q-13, Q factor of getSpEngy... output */ - Ltemp3=L_shl(L_mult(tmp,24660),9); /* Ltemp3=(2Q-13)*10log10(2), Q23, 24660=10log10(2) in Q13 */ - - Ltemp1 = getSpEngyFromResAmp_fx(X_fx,0, 2828,curr_lpc, sin_tab, cos_tab); - Ltemp1=log10_fx(Ltemp1); - - /* subtract 10log10(2)*(2Q-13), Q23 */ - Ltemp1=L_sub(Ltemp1,Ltemp3); - Ltemp1=L_max(0,Ltemp1); - Ltemp2 = getSpEngyFromResAmp_fx(X_fx,2828,X_fx->upper_cut_off_freq_fx,curr_lpc, sin_tab, cos_tab); - Ltemp2=log10_fx(Ltemp2 ); /* Ltemp1=10log10(eng_hb), Q23, need to adjust for Q factor of energy (2Q-13) */ - Ltemp2=L_sub(Ltemp2,Ltemp3); /* Ltemp2 in Q23 */ - - Ltemp2=L_max(0,Ltemp2); - - /* Getting the Speech Domain Energy LOG Ratio */ - - Lacc = L_add(Ltemp1,Ltemp2); - exp = norm_l(Lacc); - tmp = round_fx(L_shl(Lacc,exp)); - exp = sub(sub(30,exp),23); - IF(tmp) - tmp = div_s(16384,tmp); /* 15+exp1 */ - ELSE - tmp = 0; - Ltemp = L_deposit_h(tmp); - - tmp=round_fx(Ltemp); /* tmp in Q(22-n) */ - Ltemp1= Mult_32_16(Ltemp1,tmp); /* Q(30-n) */ - n=sub(8,exp); - w[0]=round_fx(L_shl(Ltemp1,n)); /* w[0] in Q15 */ - Ltemp2= Mult_32_16(Ltemp2,tmp); - w[1]=round_fx(L_shl(Ltemp2,n)); /* w[1] in Q15 */ - - logLag=log10_fx(X_fx->lag_fx); /* logLag=10*log10(lag), Q23 */ - Ltemp3=L_shl(L_mult(shl(X_fx->Q,1),24660),9); /* Ltemp3=2Q*10log10(2), Q23 */ - /* Process low band */ - Ltemp=DTFS_setEngyHarm_fx(236, 2828, 0, 2828, 1, 0, &Ql,X_fx); /* Ql is norm factor of low band a[], Ltemp is energy in 2Q */ - /* Compensate for Q factor of energy to get log10(lag*eng) */ - Ltemp=log10_fx(Ltemp); /* Ltemp=10log10(eng), Q23 */ - Ltemp=L_add(L_sub(Ltemp,Ltemp3),logLag); /* Ltemp=10*log10(lag*eng), Q23 */ - - target[0]=round_fx(L_shl(Mult_32_16(Ltemp,0x6666),1)); /* Q11 */ - - /* Process high band */ - Ltemp=DTFS_setEngyHarm_fx(2828, X_fx->upper_cut_off_freq_of_interest_fx, 2828, X_fx->upper_cut_off_freq_fx, 1, 0, &Qh,X_fx); - Ltemp=log10_fx(Ltemp); - Ltemp=L_add(L_sub(Ltemp,Ltemp3),logLag); /* Ltemp=10*log10(lag*eng), Q23 */ - target[1]=round_fx(L_shl(Mult_32_16(Ltemp,0x6666),1)); /* Q11 */ - - /* Need to unify the Q factors of both bands */ - X_fx->Q=s_min(Ql,Qh); /* set Q factor to be the smaller one */ - n=sub(Ql,Qh); /* compare band Q factors */ - - IF (n<0) rshiftHarmBand_fx(X_fx,2828, X_fx->upper_cut_off_freq_fx,n); - ELSE IF (n>0) rshiftHarmBand_fx(X_fx,0, 2828, sub(Qh,Ql)); -} -/*===================================================================*/ -/* FUNCTION : struct DTFS_fx::dequant_cw_fx () */ -/*-------------------------------------------------------------------*/ -/* PURPOSE : Dequantize QPPP prototype */ -/*-------------------------------------------------------------------*/ -/* INPUT ARGUMENTS : */ -/* _ (Word16) pl: previous lag */ -/* _ (Word16) p_idx: Power index */ -/* _ (Word16[]) a_idx: Amplitude indices, 2 words */ -/* _ (struct DTFS_fx) X : prototype in polar domain */ -/* (Word16) lag: length of prototype */ -/*-------------------------------------------------------------------*/ -/* OUTPUT ARGUMENTS : */ -/* _ (struct DTFS_fx) X : prototype in polar domain */ -/* (Word16) lag: length of prototype in time domain */ -/* (Word16 []) a: amplitude of harmonics, normalized */ -/* (Word16) Q: norm factor of a */ -/* _ (Word16[]) curr_erb: Quantized current ERB, Q13 */ -/*-------------------------------------------------------------------*/ -/* INPUT/OUTPUT ARGUMENTS : */ -/* _ (Word16[]) lasterb: ERB history for differential */ -/* quantization, Q13 */ -/* _ (Word16) Lgain: low band power history, log domain, Q11 */ -/* _ (Word16) Hgain: high band power history, log domain, Q11 */ -/*-------------------------------------------------------------------*/ -/* RETURN ARGUMENTS : _ None. */ -/*-------------------------------------------------------------------*/ -/* CALLED FROM : TX/RX */ -/*===================================================================*/ - -void DTFS_dequant_cw_fx( - Word16 pl_fx, /* i : Previous lag */ - Word16 POWER_IDX_fx, /* i : POWER index */ - const Word16 *AMP_IDX_fx, /* i : Amp Shape index */ - Word16 *lastLgainD_fx, /* i/o: low band last gain */ - Word16 *lastHgainD_fx, /* i/o: high band last gain */ - Word16 *lasterbD_fx, /* i/o: last frame ERB vector */ - DTFS_STRUCTURE_FX *X_fx, /* o : DTFS structure dequantized */ - Word16 num_erb_fx -) - -{ - Word16 tmp_fx, mfreq_fx[NUM_ERB_WB], curr_erb_fx[NUM_ERB_WB]; - const Word16 *PowerCB_fx=NULL; - Word16 slot_fx[NUM_ERB_WB]; - Word16 Ql, Qh, n; - Word32 Ltemp_fx,logLag_fx; - Word16 exp,frac,exp1; - Word32 L_tmp,L_temp; - Word32 L_tmp2; - - IF (num_erb_fx==NUM_ERB_NB) - { - PowerCB_fx=PowerCB_NB_fx; - move16(); - } - ELSE IF (num_erb_fx==NUM_ERB_WB) - { - PowerCB_fx=PowerCB_WB_fx; - move16(); - } - - /* Amplitude Dequantization */ - - erb_add_fx(curr_erb_fx,X_fx->lag_fx,lasterbD_fx,pl_fx,AMP_IDX_fx,num_erb_fx); - - curr_erb_fx[0] = mult_r(curr_erb_fx[1],9830);/* 0.3 inQ15 leaves curr_erb in Q13 */ - curr_erb_fx[sub(num_erb_fx,2)] = mult_r(curr_erb_fx[sub(num_erb_fx,3)],9830);/* Q13 */ - - move16(); - - curr_erb_fx[sub(num_erb_fx,1)] = 0; - - erb_slot_fx(X_fx->lag_fx,slot_fx,mfreq_fx,num_erb_fx); - - /* mfreq normalized (2.56) in Q15 */ - DTFS_erb_inv_fx(curr_erb_fx, slot_fx, mfreq_fx, X_fx,num_erb_fx) ; - - - /* Back up the lasterbD memory after power normalization */ - - DTFS_setEngyHarm_fx(236,2828,0,2828,1,0,&Ql,X_fx); - DTFS_setEngyHarm_fx(2828,X_fx->upper_cut_off_freq_of_interest_fx,2828,X_fx->upper_cut_off_freq_fx,1,0,&Qh,X_fx); - - /* Need to unify the Q factors of both bands */ - X_fx->Q=s_min(Ql,Qh); /* set Q factor to be the smaller one */ - n=sub(Ql,Qh); /* compare band Q factors */ - - - - - /* This logic adjusts difference between Q formats of both bands */ - IF (n<0) - rshiftHarmBand_fx(X_fx,2828, X_fx->upper_cut_off_freq_fx,n); - ELSE IF (n>0) - rshiftHarmBand_fx(X_fx,0, 2828, sub(Qh,Ql)); - - DTFS_to_erb_fx(*X_fx,lasterbD_fx); - - - /* Power Dequantization */ - - tmp_fx=shl(POWER_IDX_fx,1); /* tmp=2*POWER_IDX */ - *lastLgainD_fx =add(*lastLgainD_fx, PowerCB_fx[tmp_fx]) ; /* Q11 */ - *lastHgainD_fx =add(*lastHgainD_fx, PowerCB_fx[tmp_fx+1]); /* Q11 */ - - L_tmp = L_deposit_h(X_fx->lag_fx); /* Q16 */ - exp = norm_l(L_tmp); - L_tmp = L_shl(L_tmp,exp); - frac = Log2_norm_lc(L_tmp); - exp = sub(30,add(exp,16)); - L_tmp = Mpy_32_16(exp,frac,12330);/* Q13 */ /* 10*log10(2) in Q12*/ - Ltemp_fx = L_shl(L_tmp, 10);/* Q23 */ - - - logLag_fx= Mult_32_16(Ltemp_fx,0x6666); /* logLag=log10(lag), Q26 */ - - Ltemp_fx=L_sub(L_shr(L_deposit_h(*lastLgainD_fx),1),logLag_fx); /* Ltemp=Lgain-log10(lag), Q26 */ - - /* Lacc_fx=dsp_pow10(Ltemp_fx); : Lacc=10^Lgain/lag, Q15 */ - - L_tmp = Mult_32_16(Ltemp_fx, 27213); /* 3.321928 in Q13 */ - L_tmp = L_shr(L_tmp,8); /* Q16 */ - frac = L_Extract_lc(L_tmp, &exp1); /* Extract exponent */ - L_tmp =Pow2(14, frac); - exp1 = sub(exp1,14); - L_temp = L_shl(L_tmp, add(exp1,15) ); /* Q15 */ - - L_tmp2 = L_temp; - if( L_sub( L_temp, 2147483647 ) >= 0 ) - { - L_temp = L_shl(L_tmp, 15 ); /*Q(15-exp1) */ - } - - n=norm_l(L_temp); - Ltemp_fx=L_shl(L_temp,n); /* Ltemp in Q(15+n) or Q(15 - exp1 +n) */ - - IF( L_sub( L_tmp2, 2147483647 ) >= 0 ) - { - DTFS_setEngyHarm_fx( 236, 2828, 0, 2828, Ltemp_fx, add(15,sub(n,exp1)), &Ql, X_fx ); - } - ELSE - { - DTFS_setEngyHarm_fx( 236, 2828, 0, 2828, Ltemp_fx, add(15,n), &Ql, X_fx ); - } - - Ltemp_fx=L_sub(L_shr(L_deposit_h(*lastHgainD_fx),1),logLag_fx); /* Ltemp=Hgain-log10(lag), Q26 */ - /* Lacc_fx=dsp_pow10(Ltemp_fx); : Lacc=10^Hgain/lag, Q15 */ - L_tmp = Mult_32_16(Ltemp_fx, 27213); /* 3.321928 in Q13 */ /* Q24 */ - L_tmp = L_shr(L_tmp,8); /* Q16 */ - frac = L_Extract_lc(L_tmp, &exp1); /* Extract exponent */ - L_tmp =Pow2(14, frac); - exp1 = sub(exp1,14); - L_temp = L_shl(L_tmp,exp1 +15 ); /* Q15 */ - - L_tmp2 = L_temp; - if( L_sub( L_temp, 2147483647 ) >= 0 ) - { - L_temp = L_shl(L_tmp, 15 ); /*Q(15-exp1) */ - } - - - n=norm_l(L_temp); - Ltemp_fx=L_shl(L_temp,n); /* Ltemp in Q(15+n) or Q(15 - exp1 +n) */ - - IF( L_sub( L_tmp2, 2147483647 ) >= 0 ) - { - DTFS_setEngyHarm_fx( 2828, X_fx->upper_cut_off_freq_of_interest_fx,2828, X_fx->upper_cut_off_freq_fx, Ltemp_fx,add( 15, sub( n, exp1 )),&Qh, X_fx ); - } - ELSE - { - DTFS_setEngyHarm_fx( 2828, X_fx->upper_cut_off_freq_of_interest_fx,2828, X_fx->upper_cut_off_freq_fx, Ltemp_fx, add( 15, n ), &Qh, X_fx ); - } - - - /* Need to unify the Q factors of both bands */ - X_fx->Q=s_min(Ql,Qh); /* set Q factor to be the smaller one */ - n=sub(Ql,Qh); /* compare band Q factors */ - - - - IF (n<0) - rshiftHarmBand_fx(X_fx,2828, X_fx->upper_cut_off_freq_fx,n); - ELSE IF (n>0) - rshiftHarmBand_fx(X_fx,0, 2828, sub(Qh,Ql)); -} -/*==========================================================================*/ -/* FUNCTION : WIsyn_fx () */ -/*--------------------------------------------------------------------------*/ -/* PURPOSE : */ -/*--------------------------------------------------------------------------*/ -/* INPUT ARGUMENTS : */ -/* _ (struct DTFS_STRUCTURE_FX) PREVCW_FX: a/b in PREVCW_FX.Q */ -/* _ (struct DTFS_fx *) CURR_CW_DTFS_FX: a/b in CURR_CW_DTFS_FX->Q */ -/* _ (Word16 *) curr_lpc_fx: lpc coefficients in Q12 */ -/* _ (Word16 *) ph_offset_fx: in Q15, normalized by 2pi */ -/* _ (Word16 *) S_fx: sin(2pi*n/(4*lag)) table, Q15 */ -/* _ (Word16 *) C_fx: cos(2pi*n/(4*lag)) table, Q15 */ -/* _ (Word16 *) N: length, Q0 */ -/*--------------------------------------------------------------------------*/ -/* OUTPUT ARGUMENTS : */ -/* _ (Word16 *) out_fx: Q0 */ -/*--------------------------------------------------------------------------*/ -/* INPUT/OUTPUT ARGUMENTS : */ -/* _ (struct DTFS_STRUCTURE_FX *) CURR_CW_DTFS_FX: a/b in CURR_CW_DTFS_FX->Q*/ -/* _ (Word16 *) ph_offset_fx: in Q15, normalized by 2pi */ -/*--------------------------------------------------------------------------*/ -/* RETURN ARGUMENTS : _ None. */ -/*==========================================================================*/ - -void WIsyn_fx( - DTFS_STRUCTURE_FX PREVCW_FX, - DTFS_STRUCTURE_FX *CURR_CW_DTFS_FX, - const Word16 *curr_lpc_fx, - Word16 *ph_offset_fx, - Word16 *out_fx, - Word16 N, - Word16 FR_flag, /* i : called for post-smoothing in FR */ - Word16 * S_fx, - Word16* C_fx, - Word16 *pf_temp1, - Word16 *pf_temp2, - Word16 *pf_temp, - Word16 *pf_n2 -) -{ - Word16 i; - UWord16 I=1, flag=0; - /* Word16 *phase_fx = (Word16*)malloc(sizeof(Word16) * (2*N)); new operator used size 2*N */ - Word32 phase_fx[WI_FX_phase_fx]; - Word16 alignment_fx; - Word16 tmp_fx, temp; - Word32 L_temp; - Word16 exp,tmp; - Word32 L_tmp; - /* prev_lsp_fx; */ - - - DTFS_STRUCTURE_FX *CURRCW_DTFS_FX=DTFS_new_fx(); - - - IF (sub(PREVCW_FX.Q,CURR_CW_DTFS_FX->Q) < 0) - { - temp = sub(CURR_CW_DTFS_FX->Q, PREVCW_FX.Q); - tmp = s_min(shr(CURR_CW_DTFS_FX->lag_fx,1),CURR_CW_DTFS_FX->nH_fx); - FOR (i=0; i<=tmp; i++) - { - CURR_CW_DTFS_FX->a_fx[i] = shr(CURR_CW_DTFS_FX->a_fx[i], temp); - move16(); - CURR_CW_DTFS_FX->b_fx[i] = shr(CURR_CW_DTFS_FX->b_fx[i], temp); - move16(); - } - CURR_CW_DTFS_FX->Q=PREVCW_FX.Q; - move16(); - } - - - IF (sub(CURR_CW_DTFS_FX->Q,PREVCW_FX.Q)<0) - { - temp = sub(PREVCW_FX.Q, CURR_CW_DTFS_FX->Q); - tmp = s_min(shr(PREVCW_FX.lag_fx, 1),PREVCW_FX.nH_fx); - FOR (i=0; i<=tmp; i++) - { - PREVCW_FX.a_fx[i] = shr(PREVCW_FX.a_fx[i], temp); - move16(); - PREVCW_FX.b_fx[i] = shr(PREVCW_FX.b_fx[i], temp); - move16(); - } - PREVCW_FX.Q=CURR_CW_DTFS_FX->Q; - move16(); - } - - DTFS_copy_fx( CURRCW_DTFS_FX, *CURR_CW_DTFS_FX); - /* Calculating the expected alignment shift */ - alignment_fx = mult_r(*ph_offset_fx, shl(PREVCW_FX.lag_fx, 7)); /* confirmed I<2 by smv12.org, Q7 */ - - - IF (sub(flag,1)==0) - alignment_fx = extract_l(L_shr(L_mult(alignment_fx, I), 1)) ; /* Q7 */ - - /* Calculating the expected alignment shift */ - find_rem((Word16)N, shr(add(PREVCW_FX.lag_fx, CURRCW_DTFS_FX->lag_fx), 1), &temp); - temp = add(shl(temp, 7), alignment_fx); /* Q7 */ - - - IF (temp<0) - temp = add(temp,shl(CURRCW_DTFS_FX->lag_fx,7)); /* Q7 */ - - find_rem(temp,shl(CURRCW_DTFS_FX->lag_fx, 7),&tmp_fx); /* Q7 */ - IF (FR_flag==0) - { - alignment_fx = DTFS_alignment_weight_fx(&PREVCW_FX, *CURRCW_DTFS_FX,tmp_fx, curr_lpc_fx, curr_lpc_fx, S_fx, - C_fx, pf_temp1, pf_temp2, pf_temp, pf_n2); - move16();/* Q7 */ - } - ELSE - { - alignment_fx = DTFS_alignment_full_fx(PREVCW_FX, *CURRCW_DTFS_FX, *ph_offset_fx, S_fx, C_fx - ,FR_flag - ); - - /*alignment_fx is in Q1, we make it Q7*/ - alignment_fx = shl(alignment_fx,6); - } - - - IF (sub(alignment_fx,shl(CURRCW_DTFS_FX->lag_fx, 7))>=0) - { - temp=sub(alignment_fx, shl(CURRCW_DTFS_FX->lag_fx, 7)); - tmp = shl(CURRCW_DTFS_FX->lag_fx, 7); - exp = norm_s(tmp); - tmp = div_s(shl(1,sub(14,exp)),tmp);/* 22-exp */ - L_tmp =L_shl(L_mult(temp,tmp),exp+1); - tmp_fx = round_fx(L_tmp); - } - ELSE IF (alignment_fx<0) - { - temp=negate(alignment_fx); - tmp = shl(CURRCW_DTFS_FX->lag_fx, 7); - exp = norm_s(tmp); - tmp = div_s(shl(1,sub(14,exp)),tmp);/* 22-exp */ - L_tmp =L_shl(L_mult(temp,tmp),exp+1); - tmp_fx = negate( round_fx(L_tmp)); - } - ELSE - { - temp=alignment_fx; - move16(); - tmp = shl(CURRCW_DTFS_FX->lag_fx, 7); - exp = norm_s(tmp); - tmp = div_s(shl(1,sub(14,exp)),tmp);/* 22-exp */ - L_tmp =L_shl(L_mult(temp,tmp),exp+1); - tmp_fx = round_fx(L_tmp); - } - - DTFS_phaseShift_fx(CURRCW_DTFS_FX, alignment_fx, CURRCW_DTFS_FX->lag_fx, S_fx, C_fx) ; /* Qmin */ - DTFS_phaseShift_fx(CURR_CW_DTFS_FX, alignment_fx, CURR_CW_DTFS_FX->lag_fx, S_fx, C_fx);/* Qmin */ - - /* Compute the cubic phase track and transform to 1-D signal */ - cubicPhase_fx(*ph_offset_fx, tmp_fx, PREVCW_FX.lag_fx , CURRCW_DTFS_FX->lag_fx, N, phase_fx) ; - - temp = shr(add(PREVCW_FX.lag_fx,CURRCW_DTFS_FX->lag_fx),1); /* Q0 */ - - IF (FR_flag==0) - { - DTFS_transform_fx(PREVCW_FX,*CURRCW_DTFS_FX, phase_fx, out_fx, N, 0) ; - } - ELSE - { - DTFS_transform_fx (PREVCW_FX, *CURRCW_DTFS_FX, phase_fx, out_fx, N, 1) ; - } - - - /* Adjust the phase offset and wrap it between 0 and 2pi */ - - - - - IF (sub(flag,2)==0) - { - L_temp = L_shr(L_mult(tmp_fx, I), 1); /* Q15 */ - } - ELSE - { - L_temp = L_deposit_l(tmp_fx); /* Q15 */ - } - - - FOR ( ; L_temp < 0; L_temp += 0x8000L) - { - /* empty loop */ - } - L_temp = L_temp&0x7fff; - move16(); /* fraction part */ - *ph_offset_fx = extract_l(L_temp); - - /* free(phase_fx) ; */ - free(CURRCW_DTFS_FX); -} - - - -/*===================================================================*/ -/* FUNCTION : ppp_extract_pitch_period_fx () */ -/*-------------------------------------------------------------------*/ -/* PURPOSE : Update background noise estimate, signal energy */ -/* estimate, and band snrs */ -/*-------------------------------------------------------------------*/ -/* INPUT ARGUMENTS : */ -/* _ (Word16 []) in : residual input, Q0 */ -/* _ (Word16) l : pitch lag, Q0 */ -/*-------------------------------------------------------------------*/ -/* OUTPUT ARGUMENTS : */ -/* _ (Word16 []) out : pitch period prototype, Q0 */ -/* _ (Word16*) out_of_bound : pitch lag, Q0 */ -/*-------------------------------------------------------------------*/ -/* INPUT/OUTPUT ARGUMENTS : */ -/* _ None */ -/*-------------------------------------------------------------------*/ -/* RETURN ARGUMENTS : */ -/* _ (Word16) spike_near_edge : Q0 */ -/*===================================================================*/ -Word16 ppp_extract_pitch_period_fx( - const Word16 *in, /* i : input residual */ - Word16 *out, /* o : output residual */ - Word16 l, /* i : lag */ - Word16 *out_of_bound, /* o : out of bound flag */ - Word16 Qres - -) -{ - Word16 i,j,k; - Word16 spike=0,range; - Word16 max=0; - const Word16 *ptr=in+L_FRAME-l; - Word32 en1 = 0,Lacc,L_tmp; - Word16 spike_near_edge=0,scale; - Word16 pos_max,neg_max; - Word16 spike_pos=0,spike_neg=0; - Word16 x,tmp,expa,fraca,expb,fracb,scale1,exp; - - pos_max = -0x8000L; - move16(); - neg_max = 0; - move16(); - *out_of_bound=0; - move16(); - - en1 = L_deposit_l(0); - FOR (i=0 ; i0) - { - max=x; - move16(); - spike=i; - move16(); - } - en1 =L_mac0(en1, ptr[i], ptr[i]); /* Q0 */ - } - - IF (ptr[spike]>0) - { - spike_pos=spike; - move16(); - /* search for neg spike around the pos spike */ - FOR(j=spike-10; j0) - { - pos_max=ptr[k]; - move16(); - spike_pos=k; - move16(); - } - } - } - - test(); - IF ((sub((l-1-s_max(spike_pos,spike_neg)),2)<=0) ||(sub(s_min(spike_pos,spike_neg),2)<=0)) - { - *out_of_bound=1; - move16(); - return spike_near_edge; - } - - - tmp = (Word16)(L_max(L_mult(CUTFREE_REL_RANGE_Q2,l),CUTFREE_ABS_RANGE_Q3));/* Q3 */ - - IF(tmp>0) - tmp = add(tmp,4);/* Q3 */ - ELSE - tmp = sub(tmp,4);/* Q3 */ - range = shr(tmp,3);/* Q0 */ - - test(); - IF((sub(spike,range)<0) || (sub(add(spike,range),l)>=0)) - { - /* need to grab from one lag before - ensure that there is no array bound read */ - - IF(sub(sub(L_FRAME,l),l) < 0) - { - *out_of_bound=1; - move16(); - return spike_near_edge; - } - spike_near_edge=1; - move16(); - } - - IF(sub(spike,range)<0) - { - tmp = add(l,sub(spike,range)); - FOR(i=0; i= 0) - { - tmp = sub(spike,range); - FOR(i=0; i=in) - { - FOR(ptr-=l; i= 0) - { - if (L_sub(L_temp,maxPosEn_fx)>0) - { - maxPosEn_fx = L_temp ; /* Q(1) */ - } - } - ELSE - { - if (L_sub(L_temp,maxNegEn_fx)>0) - { - maxNegEn_fx = L_temp ; /* Q(1) */ - } - } - } - - - IF (L_sum==0) - { - *pos_fx=*neg_fx=0; - move16(); - move16(); - } - ELSE - { - IF (maxPosEn_fx==0) - { - *pos_fx=0; - *Qpos=31; - } - ELSE - { - expa = norm_l(maxPosEn_fx); - fraca = extract_h(L_shl(maxPosEn_fx,expa)); - expa = sub(30,add(expa,1)); - - - expb = norm_l(L_sum); - fracb = round_fx(L_shl(L_sum,expb)); - expb = sub(30,add(expb,shl(X_fx.Q,1))); - - - scale = shr(sub(fraca,fracb),15); - fracb = shl(fracb,scale); - expb = sub(expb,scale); - - tmp = div_s(fracb,fraca); - exp = sub(expb,expa); - - L_tmp = Isqrt_lc(L_deposit_h(tmp),&exp); /* Q(31-exp) */ - *pos_fx = L_tmp; - *Qpos = sub(31, exp); - - } - - IF (maxNegEn_fx==0) - { - *neg_fx=0; - *Qneg=31; - } - ELSE - { - - expa = norm_l(maxNegEn_fx); - fraca = extract_h(L_shl(maxNegEn_fx,expa)); - expa = 30-expa- 1; - - - expb = norm_l(L_sum); - fracb = round_fx(L_shl(L_sum,expb)); - expb = 30-expb - (2*X_fx.Q); - - - scale = shr(sub(fraca,fracb),15); - fracb = shl(fracb,scale); - expb = sub(expb,scale); - - tmp = div_s(fracb,fraca); - exp = sub(expb,expa); - - L_tmp = Isqrt_lc(L_deposit_h(tmp),&exp); /* Q(31-exp) */ - *neg_fx = L_tmp; - *Qneg = 31 - exp; - - } - - } -} - -/*===================================================================*/ -/* FUNCTION : struct DTFS_fx:: rshiftHarmBand_fx() */ -/*-------------------------------------------------------------------*/ -/* PURPOSE : Right-shift harmonics in band to align Q factor */ -/*-------------------------------------------------------------------*/ -/* INPUT ARGUMENTS : */ -/* _ (Word16) lband: lower band boundary, Q15 */ -/* _ (Word16) hband: upper band boundary, Q15 */ -/* _ (Word16) shift: right shift value, Q0 (must be <0) */ -/*-------------------------------------------------------------------*/ -/* OUTPUT ARGUMENTS : */ -/* _ None */ -/*-------------------------------------------------------------------*/ -/* INPUT/OUTPUT ARGUMENTS : */ -/* _ (struct DTFS_fx) X : prototype in polar domain */ -/* (Word16) lag: length of prototype in time domain */ -/* (Word16 []) a: amplitude of harmonics, normalized */ -/*-------------------------------------------------------------------*/ -/* RETURN ARGUMENTS : _ None. */ -/*-------------------------------------------------------------------*/ -/* CALLED FROM : TX/RX */ -/*===================================================================*/ -/* NOTE: This function should be called after two consecutive calls */ -/* to setEngyHarm_fx, because the norm factor outputs from */ -/* the two previous calls might be different */ -/*===================================================================*/ -void rshiftHarmBand_fx( DTFS_STRUCTURE_FX *X_fx,Word16 lband_fx, Word16 hband_fx, Word16 shift_fx) -{ - Word16 k_fx, HalfLag_fx; - Word16 low_fx, high_fx; - - low_fx=mult(lband_fx,X_fx->lag_fx); /* low=lband*lag, Q0 */ - high_fx=mult(hband_fx,X_fx->lag_fx); /* high=hband*lag, Q0 */ - HalfLag_fx = s_min(high_fx,shl(X_fx->nH_fx,1)); - - FOR (k_fx=low_fx+1; k_fx<=HalfLag_fx; k_fx++) - { - X_fx->a_fx[k_fx]=shl_r(X_fx->a_fx[k_fx],shift_fx); - move16(); /* right shift and round */ - } -} - -/*===================================================================*/ -/* FUNCTION : GetSinCosTab_fx () */ -/*-------------------------------------------------------------------*/ -/* PURPOSE : Compute sine & cosine table given pitch lag, */ -/* by interpolating the 512-entry cosine table. */ -/* sin(2pi/4L*n) & cos(2pi/4L*n) for n=0,1,... 4L-1 */ -/*-------------------------------------------------------------------*/ -/* INPUT ARGUMENTS : */ -/* _ (Word16) L : Pitch lag, Q0 */ -/*-------------------------------------------------------------------*/ -/* OUTPUT ARGUMENTS : */ -/* _ (Word16 []) sinTab, Q15 : sin(2pi/4L*n), n=0,1,...,4L-1 */ -/* _ (Word16 []) cosTab, Q15 : cos(2pi/4L*n), n=0,1,...,4L-1 */ -/*-------------------------------------------------------------------*/ -/* INPUT/OUTPUT ARGUMENTS : */ -/* _ None */ -/*-------------------------------------------------------------------*/ -/* RETURN ARGUMENTS : _ None. */ -/*-------------------------------------------------------------------*/ -/* CALLED FROM : TX/RX */ -/*===================================================================*/ -/* NOTE: This function interpolates cos_table for better accuracy */ -/*===================================================================*/ -void GetSinCosTab_fx(Word16 L, Word16 *sinTab, Word16 *cosTab) -{ - Word16 i, L4; - Word16 dl, t1, w, dt; - /* Word16 t2; */ - Word32 invL; /* 1/4L in Q25 */ - Word32 Ltemp, Lw; - Word32 L_tmp; - - invL = L_shr(inverse_table[L],4); - - L4=shl(L,2); - Lw = L_deposit_l(0); - FOR (i=0 ; i 0; k -= size) - { - K=add(K,1); /* K=512/size */ - } - n_2=shr(size,1); - FOR (i=1; i<=stage; i++) ii_table[i-1]=shr(size,i); - - /* Rearrange the input array in bit reversed order */ - j = 0; - move16(); - FOR (i = 0 ; i < size - 2; i = i + 2) - { - move16(); - move16(); - move16(); - move16(); - move16(); - move16(); - - IF (sub(j,i) > 0) - { - ftmp_fx = *(farray_ptr_fx + i); - *(farray_ptr_fx + i) = *(farray_ptr_fx + j); - *(farray_ptr_fx + j) = (Word16) ftmp_fx; - - ftmp_fx = *(farray_ptr_fx + i + 1); - *(farray_ptr_fx + i + 1) = *(farray_ptr_fx + j + 1); - *(farray_ptr_fx + j + 1) = (Word16)ftmp_fx; - } - - k = n_2; - move16(); - WHILE (j >= k) - { - j = sub(j, k); - k = shr(k, 1); - } - j += k; - } - - /* The FFT part */ - - - - IF (isign == 1) - { - FOR (i = 0; i < stage; i++) /* i is stage counter */ - { - jj = shl(2, i); /* FFT size */ - kk = shl(jj, 1); /* 2 * FFT size */ - - move16(); - - ii = ii_table[i]; /* 2 * number of FFT's */ - - FOR (j = 0; j < jj; j = j + 2) /* j is sample counter */ - { - ji = j * ii; /* ji is phase table index */ - - FOR (k = j; k < size; k = k + kk) /* k is butterfly top */ - { - kj = add(k, jj); /* kj is butterfly bottom */ - temp_sand = s_and((ji*K+384),511); - /* Butterfly computations */ - /* ftmp_real_fx = L_sub(L_mult(*(farray_ptr_fx + kj), cos_table[ji*K]), */ - /* L_mult(*(farray_ptr_fx + kj + 1), cos_table[(ji*K+384)%512])); */ - ftmp_real_fx = L_msu(L_mult(*(farray_ptr_fx + kj), cos_table[ji*K]), - *(farray_ptr_fx + kj + 1), cos_table[temp_sand]); - - /* ftmp_imag_fx = L_add(L_mult(*(farray_ptr_fx + kj + 1), cos_table[ji*K]), */ - /* L_mult(*(farray_ptr_fx + kj), cos_table[(ji*K+384)%512])); */ - ftmp_imag_fx = L_mac(L_mult(*(farray_ptr_fx + kj + 1), cos_table[ji*K]), - *(farray_ptr_fx + kj), cos_table[temp_sand]); - - tmp1 = round_fx(ftmp_real_fx); - tmp2 = round_fx(ftmp_imag_fx); - - tmp = sub(*(farray_ptr_fx + k), tmp1); - *(farray_ptr_fx + kj) = shr(tmp, 1); - move16(); - - tmp = sub(*(farray_ptr_fx + k + 1), tmp2); - *(farray_ptr_fx + kj + 1) = shr(tmp, 1); - move16(); - - tmp = add(*(farray_ptr_fx + k), tmp1); - *(farray_ptr_fx + k) = shr(tmp, 1); - move16(); - - tmp = add(*(farray_ptr_fx + k + 1), tmp2); - *(farray_ptr_fx + k + 1) = shr(tmp, 1); - move16(); - } - } - } - - /* The IFFT part */ - } - ELSE - { - FOR (i = 0; i < stage; i++) /* i is stage counter */ - { - jj = shl(2, i); /* FFT size */ - kk = shl(jj, 1); /* 2 * FFT size */ - ii = ii_table[i]; /* 2 * number of FFT's */ - - FOR (j = 0; j < jj; j = j + 2) /* j is sample counter */ - { - ji = j * ii; /* ji is phase table index */ - - FOR (k = j; k < size; k = k + kk) /* k is butterfly top */ - { - kj = add(k, jj); /* kj is butterfly bottom */ - temp_sand = s_and((ji*K+384),511); - /* Butterfly computations */ - /* ftmp_real_fx = L_add(L_mult(*(farray_ptr_fx + kj), cos_table[ji*K]), */ - /* L_mult(*(farray_ptr_fx + kj + 1), cos_table[(ji*K+384)%512])); */ - ftmp_real_fx = L_mac(L_mult(*(farray_ptr_fx + kj), cos_table[ji*K]), - *(farray_ptr_fx + kj + 1), cos_table[temp_sand]); - - /* ftmp_imag_fx = L_sub(L_mult(*(farray_ptr_fx + kj + 1), cos_table[ji*K]), */ - /* L_mult(*(farray_ptr_fx + kj), cos_table[(ji*K+384)%512])); */ - ftmp_imag_fx = L_msu(L_mult(*(farray_ptr_fx + kj + 1), cos_table[ji*K]), - *(farray_ptr_fx + kj), cos_table[temp_sand]); - - tmp1 = round_fx(ftmp_real_fx); - tmp2 = round_fx(ftmp_imag_fx); - - *(farray_ptr_fx + kj) = sub(*(farray_ptr_fx + k), tmp1); - move16(); - *(farray_ptr_fx + kj + 1) = sub(*(farray_ptr_fx + k + 1), tmp2); - move16(); - *(farray_ptr_fx + k) = add(*(farray_ptr_fx + k), tmp1); - move16(); - *(farray_ptr_fx + k + 1) = add(*(farray_ptr_fx + k + 1), tmp2); - move16(); - } - } - } - } - -} /* end of c_fft () */ - - -void r_fft_4_fx(Word16 * farray_ptr_fx, Word16 size, Word16 stage, Word16 isign) -{ - - Word16 ftmp1_real_fx, ftmp1_imag_fx, ftmp2_real_fx, ftmp2_imag_fx; - Word32 Lftmp1_real_fx, Lftmp1_imag_fx; - Word16 i, j,temp_sand; - Word32 Ltmp1_fx, Ltmp2_fx; - Word16 n_2, k, K; - - n_2 = shr(size,1); - K=0; - move16(); - - FOR (k = 256; k > 0; k -= size) - { - K = add(K,1); /* K=512/size */ - } - - /* The FFT part */ - IF (isign == 1) - { - /* Perform the complex FFT */ - c_fft_wi_fx(farray_ptr_fx, size, stage, isign); - - /* First, handle the DC and foldover frequencies */ - ftmp1_real_fx = *farray_ptr_fx; - ftmp2_real_fx = *(farray_ptr_fx + 1); - *farray_ptr_fx = add(ftmp1_real_fx, ftmp2_real_fx); - *(farray_ptr_fx + 1) = sub(ftmp1_real_fx, ftmp2_real_fx); - - /* Now, handle the remaining positive frequencies */ - j = size - 2; - FOR (i = 2; i <= n_2; i = i + 2 ) - { - ftmp1_real_fx = add(*(farray_ptr_fx + i), *(farray_ptr_fx + j)); - ftmp1_imag_fx = sub(*(farray_ptr_fx + i + 1), *(farray_ptr_fx + j + 1)); - ftmp2_real_fx = add(*(farray_ptr_fx + i + 1), *(farray_ptr_fx + j + 1)); - ftmp2_imag_fx = sub(*(farray_ptr_fx + j), *(farray_ptr_fx + i)); - - Lftmp1_real_fx = L_deposit_h(ftmp1_real_fx); - Lftmp1_imag_fx = L_deposit_h(ftmp1_imag_fx); - temp_sand = s_and((i*K+384),511); - /* Ltmp1_fx = L_sub(L_mult(ftmp2_real_fx, cos_table[i*K]), L_mult(ftmp2_imag_fx, cos_table[(i*K+384)%512])); */ - Ltmp1_fx = L_msu(L_mult(ftmp2_real_fx, cos_table[i*K]), ftmp2_imag_fx, cos_table[temp_sand]); - *(farray_ptr_fx + i) = round_fx(L_shr(L_add(Lftmp1_real_fx, Ltmp1_fx), 1)); - - /* Ltmp1_fx = L_add(L_mult(ftmp2_imag_fx, cos_table[i*K]), L_mult(ftmp2_real_fx, cos_table[(i*K+384)%512])); */ - Ltmp1_fx = L_mac(L_mult(ftmp2_imag_fx, cos_table[i*K]), ftmp2_real_fx, cos_table[temp_sand]); - *(farray_ptr_fx + i + 1) = round_fx(L_shr(L_add(Lftmp1_imag_fx, Ltmp1_fx), 1)); - - /* Ltmp1_fx = L_add(L_mult(ftmp2_real_fx, cos_table[j*K]), L_mult(ftmp2_imag_fx, cos_table[(j*K+384)%512])); */ - Ltmp1_fx = L_mac(L_mult(ftmp2_real_fx, cos_table[j*K]), ftmp2_imag_fx, cos_table[temp_sand]); - *(farray_ptr_fx + j) = round_fx(L_shr(L_add(Lftmp1_real_fx, Ltmp1_fx), 1)); - - /* Ltmp1_fx = L_add(L_negate(L_mult(ftmp2_imag_fx, cos_table[j*K])), L_mult(ftmp2_real_fx, cos_table[(j*K+384)%512])); */ - Ltmp1_fx = L_msu(L_mult(ftmp2_real_fx, cos_table[temp_sand]), ftmp2_imag_fx, cos_table[j*K]); - Ltmp2_fx = L_sub(Ltmp1_fx, Lftmp1_imag_fx); - *(farray_ptr_fx + j + 1) = round_fx(L_shr(Ltmp2_fx, 1)); - j = size - i; - } - - } - ELSE - { - - /* First, handle the DC and foldover frequencies */ - - move16(); - move16(); - - ftmp1_real_fx = *farray_ptr_fx; - ftmp2_real_fx = *(farray_ptr_fx + 1); - *farray_ptr_fx = shr(add(ftmp1_real_fx, ftmp2_real_fx), 1); - move16(); - *(farray_ptr_fx + 1) = shr(sub(ftmp1_real_fx, ftmp2_real_fx), 1); - move16(); - - /* Now, handle the remaining positive frequencies */ - FOR (i = 2; i <= n_2; i += 2) - { - j = sub(size, i); - - ftmp1_real_fx = add(*(farray_ptr_fx + i), *(farray_ptr_fx + j)); - ftmp1_imag_fx = sub(*(farray_ptr_fx + i + 1), *(farray_ptr_fx + j + 1)); - ftmp2_real_fx = negate(add(*(farray_ptr_fx + j + 1), *(farray_ptr_fx + i + 1))); - ftmp2_imag_fx = negate(sub(*(farray_ptr_fx + j), *(farray_ptr_fx + i))); - - Lftmp1_real_fx = L_deposit_h(ftmp1_real_fx); - Lftmp1_imag_fx = L_deposit_h(ftmp1_imag_fx); - temp_sand = s_and((i*K+384),511); - /* Ltmp1_fx = L_add(L_mult(ftmp2_real_fx, cos_table[i*K]), L_mult(ftmp2_imag_fx, cos_table[(i*K+384)%512])); */ - Ltmp1_fx = L_mac(L_mult(ftmp2_real_fx, cos_table[i*K]), ftmp2_imag_fx, cos_table[ temp_sand]); - *(farray_ptr_fx + i) = round_fx(L_shr(L_add(Lftmp1_real_fx, Ltmp1_fx), 1)); - - /* Ltmp1_fx = L_sub(L_mult(ftmp2_imag_fx, cos_table[i*K]), L_mult(ftmp2_real_fx, cos_table[(i*K+384)%512])); */ - Ltmp1_fx = L_msu(L_mult(ftmp2_imag_fx, cos_table[i*K]), ftmp2_real_fx, cos_table[ temp_sand]); - *(farray_ptr_fx + i + 1) = round_fx(L_shr(L_add(Lftmp1_imag_fx, Ltmp1_fx), 1)); - - /* Ltmp1_fx = L_sub(L_mult(ftmp2_real_fx, cos_table[j*K]), L_mult(ftmp2_imag_fx, cos_table[(j*K+384)%512])); */ - Ltmp1_fx = L_msu(L_mult(ftmp2_real_fx, cos_table[j*K]), ftmp2_imag_fx, cos_table[temp_sand]); - *(farray_ptr_fx + j) = round_fx(L_shr(L_add(Lftmp1_real_fx, Ltmp1_fx), 1)); - - /* Ltmp1_fx = L_negate(L_add(L_mult(ftmp2_imag_fx, cos_table[j*K]), L_mult(ftmp2_real_fx, cos_table[(j*K+384)%512]))); */ - Ltmp1_fx = L_negate(L_mac(L_mult(ftmp2_imag_fx, cos_table[j*K]), ftmp2_real_fx, cos_table[temp_sand])); - Ltmp2_fx = L_sub(Ltmp1_fx, Lftmp1_imag_fx); - *(farray_ptr_fx + j + 1) = round_fx(L_shr(Ltmp2_fx, 1)); - } - - /* Perform the complex IFFT */ - c_fft_wi_fx(farray_ptr_fx, size, stage, isign); - - } - -} - - -/*===================================================================*/ -/* FUNCTION : struct DTFS_fx::copy_phase_fx () */ -/*-------------------------------------------------------------------*/ -/* PURPOSE : Retain the amplitudes of a prototype X2, but copy*/ -/* the phases of another prototype X1 of same length*/ -/* over to make a new prototype */ -/*-------------------------------------------------------------------*/ -/* INPUT ARGUMENTS : */ -/* _ (struct DTFS_fx) X1 : prototype in Cartesian domain */ -/* (Word16) X1.lag: length of prototype in time domain*/ -/* (Word16 []) X1.a,b: re/im of harmonics, normalized */ -/* (Word16) X1.Q: norm factor of X2.a/b */ -/* _ (struct DTFS_fx) X2 : prototype in polar domain */ -/* (Word16) X2.lag: should be same as X1.lag */ -/* (Word16 []) X2.a:amplitude of harmonics, normalized*/ -/* (Word16 []) X2.b: phase of harmonics, don't care */ -/* (Word16) X2.Q: norm factor of X2.a */ -/*-------------------------------------------------------------------*/ -/* OUTPUT ARGUMENTS : */ -/* _ None */ -/*-------------------------------------------------------------------*/ -/* INPUT/OUTPUT ARGUMENTS : */ -/* _ None */ -/*-------------------------------------------------------------------*/ -/* RETURN ARGUMENTS : */ -/* _ (struct DTFS_fx) X : prototype in Cartesian domain */ -/* The amplitudes of this prototype are from X2 */ -/* and the phases are from X1 */ -/*-------------------------------------------------------------------*/ -/* CALLED FROM : TX/RX */ -/*===================================================================*/ -/* X.a[k]=2*X2.a[k]/sqrt(X1.a[k]^2+X1.b[k]^2)*X1.a[k] */ -/* X.b[k]=2*X2.a[k]/sqrt(X1.a[k]^2+X1.b[k]^2)*X1.b[k] */ -/*===================================================================*/ -void copy_phase_fx( DTFS_STRUCTURE_FX *X1_fx, DTFS_STRUCTURE_FX X2_fx, DTFS_STRUCTURE_FX *retX_fx) -{ - /* DTFS_fx X; */ - Word16 k, q, sn, cn, HalfLag; - Word16 d1h, d1l; - Word32 Ltemp_fx,L_tmp; - Word32 Lacc_fx; - Word16 exp,tmp,exp1; - - move16(); - - retX_fx->lag_fx=X1_fx->lag_fx; - retX_fx->Q = sub(X2_fx.Q,1); /* equivalent to 2x MIN_FX(shr(sub(X_fx->lag_fx,1),1),X_fx->nH_fx) */ - HalfLag = s_min(shr(X1_fx->lag_fx,1),X1_fx->nH_fx); - move16(); - FOR ( k=1; k<=HalfLag; k++ ) - { - Lacc_fx=L_mult(X1_fx->a_fx[k],X1_fx->a_fx[k]); - Lacc_fx = L_mac(Lacc_fx,X1_fx->b_fx[k],X1_fx->b_fx[k]); /* 2*Q+1 */ - - exp = norm_l(Lacc_fx); - tmp = extract_h(L_shl(Lacc_fx,exp)); - exp1 = sub(sub(30,exp),2*X1_fx->Q+1); - - IF(tmp) - tmp = div_s(16384,tmp); /* 15+exp1 */ - ELSE - tmp = 0; - tmp = shr(tmp,1); - q = 15+exp1+16-1; - - IF(tmp) - { - exp = norm_s(tmp); - tmp = shl(tmp, exp); - tmp = div_s(16384, tmp); - L_tmp = L_deposit_h(tmp); - Ltemp_fx = Isqrt_lc(L_tmp,&exp); /* Q(31-exp) */ - } - ELSE - Ltemp_fx = 0; - - if (s_and(q, 1)) - Ltemp_fx = Mult_32_16(Ltemp_fx, 23170); /* 23170 is 1/sqrt(2) in Q15 */ - - q = shr(q,1); /* Ltemp_fx in Q(q+16) */ - - d1h=extract_h(Ltemp_fx); - d1l=extract_l(Ltemp_fx); - Ltemp_fx = L_mult0(X1_fx->b_fx[k],d1l); - Ltemp_fx = L_add(L_shr(Ltemp_fx,15),L_mult(X1_fx->b_fx[k],d1h)); /* sin(w) in Q(q+16+Q-15) */ - sn = round_fx(L_shl(Ltemp_fx,sub(30,add(q,X1_fx->Q)))); /* Q15 */ - retX_fx->b_fx[k] = mult_r(X2_fx.a_fx[k],sn); /* X2_fx.Q */ - - Ltemp_fx = L_mult0(X1_fx->a_fx[k],d1l); - Ltemp_fx = L_add(L_shr(Ltemp_fx,15),L_mult(X1_fx->a_fx[k],d1h)); /* cos(w) in Q(q+Q+1) */ - cn = round_fx(L_shl(Ltemp_fx,sub(30,add(q,X1_fx->Q)))); /* Q15 */ - retX_fx->a_fx[k] = mult_r(X2_fx.a_fx[k],cn); /* X2_fx.Q */ - - } - k=sub(k,1); - - - IF (s_and(X1_fx->lag_fx,1)==0) - { - retX_fx->a_fx[k] = shr(retX_fx->a_fx[k],1); - move16(); - retX_fx->b_fx[k] = shr(retX_fx->b_fx[k],1); - move16(); - } -} - - - -/*===================================================================*/ -/* FUNCTION : getSpEngyFromResAmp_fx () */ -/*-------------------------------------------------------------------*/ -/* PURPOSE : Get band energy */ -/*-------------------------------------------------------------------*/ -/* INPUT ARGUMENTS : */ -/* _ (struct DTFS_STRUCTURE_FX) X_fx : prototype in polar domain */ -/* (Word16) lag: length of prototype in time domain */ -/* (Word16 []) a: amplitude of harmonics, normalized */ -/* (Word16) Q: norm factor of a */ -/* _ (Word16 []) curr_lpc: LPC coefficients, Q12 */ -/* _ (Word16) lband: lower frequency bound, Q15 */ -/* _ (Word16) hband: upper frequency bound, Q15 */ -/* _ (Word16 []) sin_tab: sine table based on lag, Q15 */ -/* _ (Word16 []) cos_tab: cosine table based on lag, Q15 */ -/*-------------------------------------------------------------------*/ -/* OUTPUT ARGUMENTS : */ -/* _ None */ -/*-------------------------------------------------------------------*/ -/* INPUT/OUTPUT ARGUMENTS : */ -/* _ None */ -/*-------------------------------------------------------------------*/ -/* RETURN ARGUMENTS : */ -/* _ (Word32) en: energy of the specified frequency band, */ -/* Q factor is 2Q-13 */ -/*-------------------------------------------------------------------*/ -/* CALLED FROM : TX */ -/*===================================================================*/ -Word32 getSpEngyFromResAmp_fx( DTFS_STRUCTURE_FX *X_fx,Word16 lband, Word16 hband, - const Word16 *curr_lpc, Word16 *sin_tab, - Word16 *cos_tab) -{ - Word16 i, k, k4, n, M_fx, HalfLag; - Word16 fdiff, freq; - Word32 Ltemp; - Word32 Lacc; - Word32 Re, Im; /* Q27 */ - Word32 en; - Word16 exp,tmp,expa,fraca,expb,fracb,scale; - Word32 L_tmp; - - en = L_deposit_l(0); - - if (sub(hband,X_fx->upper_cut_off_freq_fx)==0) - { - hband = 0x2803; - move16(); /* 4001.0/12800 in Q15 */ - } - M_fx=shl(X_fx->lag_fx,2); /* M_fx=4*lag */ - - /* Ltemp=invert_dp(X_fx->lag_fx, 4, &n,1); : Ltemp=1/lag, Q(61-n) */ - /* fdiff=round_fx(L_shl(Ltemp,sub(n,26))); : fdiff=1/lag, Q19 */ - - exp = norm_s(X_fx->lag_fx); - tmp = div_s(shl(1,sub(14,exp)),X_fx->lag_fx); - L_tmp = L_shl(tmp ,add(exp,6)); - fdiff = round_fx(L_tmp); - - HalfLag = s_min(shr(X_fx->lag_fx,1),X_fx->nH_4kHz_fx); - FOR (k=0; k<=HalfLag; k++) - { - Ltemp=L_mult(fdiff,k); /* Ltemp=k*fdiff, Q20 */ - freq=extract_h(L_shl(Ltemp,11)); /* k*fdiff in Q15 */ - - test(); - IF (sub(freq,hband)<0 && sub(freq,lband)>=0) - { - Lacc = L_add(0x10000000, 0); /* Re=1.0, Q28 */ - k4=shl(k,2); /* k4=4*k */ - - n=k4; - move16(); - FOR (i=0; ia_fx[k],X_fx->a_fx[k]); /* 2*a[k]^2 in 2Q */ - /* Ltemp=(Word32)L_sat32_40(divide_dp(Ltemp,Lacc,-19,1)); : Ltemp in Q(2Q-13) */ - - if(Lacc<0) - { - Lacc = L_negate(Lacc); - } - - IF(Lacc) - { - - expa = norm_l(Lacc); - fraca = extract_h(L_shl(Lacc,expa)); - expa = sub(30,add(expa,23)); - - - expb = norm_l(Ltemp); - fracb = round_fx(L_shl(Ltemp,expb)); - expb = sub(30,add(expb, shl(X_fx->Q,1))); - - scale = shr(sub(fraca,fracb),15); - fracb = shl(fracb,scale); - expb = sub(expb,scale); - - tmp = div_s(fracb,fraca); /* 15-exp */ - exp = sub(expb,expa); - Ltemp = L_shl(tmp, sub(add(shl(X_fx->Q,1),exp), 27)) ; - - } - ELSE - { - Ltemp = L_deposit_l(0); - } - - test(); - IF (X_fx->lag_fx%2==0 && sub(k,shr(X_fx->lag_fx,1))==0) - en=L_add(en,L_shr(Ltemp,1)); - ELSE - en=L_add(en,Ltemp); /* en in 2Q-13 */ - } - - } - return(en); /* en in 2Q-13 */ -} -/*===================================================================*/ -/* FUNCTION : DTFS_poleFilter_fx() */ -/*-------------------------------------------------------------------*/ -/* PURPOSE : pole filtering */ -/*-------------------------------------------------------------------*/ -/* INPUT ARGUMENTS : */ -/* _ (Word16) lpc[] : lpc coefficients in Q12 */ -/* _ (Word16) N : lpc order */ -/* _ (Word16) X_fx->lag_fx: in Q0 */ -/* _ (Word16 *) S_fx: sin(2pi*n/(4*lag)) table, Q15 */ -/* _ (Word16 *) C_fx: cos(2pi*n/(4*lag)) table, Q15 */ -/*-------------------------------------------------------------------*/ -/* OUTPUT ARGUMENTS : */ -/* _ None */ -/*-------------------------------------------------------------------*/ -/* INPUT/OUTPUT ARGUMENTS : */ -/* _ (Word16) X_fx->a_fx[] : in Q(X_fx->Q) */ -/* _ (Word16) X_fx->b_fx[] : in Q(X_fx->Q) */ -/* _ (Word16) X_fx->Q: in Q0 */ -/*-------------------------------------------------------------------*/ -/* RETURN ARGUMENTS : _ None. */ -/*-------------------------------------------------------------------*/ -/* CALLED FROM : TX/RX */ -/*===================================================================*/ - -void DTFS_poleFilter_fx( DTFS_STRUCTURE_FX *X_fx,Word16 *LPC, Word16 N, Word16 *S_fx, Word16 *C_fx) -{ - Word16 temp, temp1, temp2, HalfLag ; - Word32 sum1_fx, sum2_fx; - Word32 sum, L_temp1, L_temp2; - Word16 k, n, na, nb; - Word16 Qmin, Qab[MAXLAG_WI]; - Word16 exp,tmp; - - Qmin = 32767; - move16(); - HalfLag = s_min(shr(X_fx->lag_fx, 1),X_fx->nH_fx); - FOR ( k=0; k<=HalfLag; k++ ) - { - temp2 = k; - move16(); - /* Calculate sum1 and sum2 */ - sum1_fx = L_deposit_h(4096); /* 1: Q(12+15+1) */ - - sum2_fx = L_deposit_l(0); - FOR ( n=0 ; nlag_fx)]) ; /* Q(12+15+1) */ - sum2_fx = L_mac(sum2_fx, LPC[n], S_fx[(4*temp2)%(4*X_fx->lag_fx)]) ; /* Q(12+15+1) */ - temp2 = add(temp2, k); - } - - temp1 = round_fx(sum1_fx); /* Q(12+15+1-16)=Q(12) */ - temp2 = round_fx(sum2_fx); /* Q(12) */ - - /* Calculate the circular convolution */ - sum = L_mac(L_mult(temp1, temp1), temp2, temp2); /* Q(12+12+1)=Q(25) */ - - L_temp1 = L_mult(temp1, X_fx->a_fx[k]); - L_temp1 = L_mac(L_temp1, temp2, X_fx->b_fx[k]); /* Q(12+Q+1)=Q(13+Q) */ - L_temp2 = L_mult(temp1, X_fx->b_fx[k]); - L_temp2 = L_msu(L_temp2, temp2, X_fx->a_fx[k]); /* Q(12+Q+1)=Q(13+Q) */ - - IF(sum) - { - exp = norm_l(sum); - temp1 = exp; - tmp = extract_h(L_shl(sum,exp)); - exp = sub(sub(30,exp),25); - tmp = div_s(16384,tmp); /* Q(15+exp) */ - sum = L_shl(tmp ,16 ); - temp = round_fx(sum); - } - ELSE - { - sum =0; - move16(); - temp =0; - move16(); - temp1 =0; - move16(); - - } - sum1_fx = Mult_32_16(L_temp1, temp); /* Q(13+Q+20-temp1-15)=Q(Q-temp1+18) */ - sum2_fx = Mult_32_16(L_temp2, temp); /* Q(Q-temp1+18) */ - - /* normalization */ - na = norm_l(sum1_fx); - if (sum1_fx==0) - { - na = 31; - move16(); - } - nb = norm_l(sum2_fx); - if (sum2_fx==0) - { - nb = 31; - move16(); - } - - if (sub(na, nb)<0) - { - nb=na; - move16(); - } - nb=sub(nb,1); /* leave one more sign bit */ - X_fx->a_fx[k] = round_fx(L_shl(sum1_fx, nb)); /* Q(Q-temp1+22+nb-16)=Q(Q-temp1+nb+2) */ - X_fx->b_fx[k] = round_fx(L_shl(sum2_fx, nb)); /* Q(Q-temp1+nb+2) */ - - Qab[k] = add(sub(add(nb, 2), temp1),X_fx->Q); - - if (sub(Qab[k], Qmin)<0) - { - Qmin = Qab[k]; - move16(); - } - } - /* bring to the same Q */ - FOR ( k=0; k<=HalfLag; k++ ) - { - X_fx->a_fx[k] = shl(X_fx->a_fx[k], sub(Qmin, Qab[k])); - move16(); /* Q(Q+Qab[k]+Qmin-Qab[k])=Q(Q+Qmin) */ - X_fx->b_fx[k] = shl(X_fx->b_fx[k], sub(Qmin, Qab[k])); - move16(); /* Q(Q+Qab[k]+Qmin-Qab[k])=Q(Q+Qmin) */ - } - - X_fx->Q = Qmin; -} -/*===================================================================*/ -/* FUNCTION : poleFilter_setup_fx() */ -/*-------------------------------------------------------------------*/ -/* PURPOSE : Sets up pole filtering LPC dependent intermediate*/ -/* values to be used by poleFilter */ -/*-------------------------------------------------------------------*/ -/* INPUT ARGUMENTS : */ -/* _ (Word16) lpc[] : lpc coefficients in Q12 */ -/* _ (Word16) N : lpc order */ -/* _ (Word16) lag : in Q0 */ -/* _ (Word16 *) S_fx: sin(2pi*n/(4*lag)) table, Q15 */ -/* _ (Word16 *) C_fx: cos(2pi*n/(4*lag)) table, Q15 */ -/*-------------------------------------------------------------------*/ -/* OUTPUT ARGUMENTS : */ -/* _ None */ -/*-------------------------------------------------------------------*/ -/* INPUT/OUTPUT ARGUMENTS : */ -/* _ None */ -/*-------------------------------------------------------------------*/ -/* RETURN ARGUMENTS : _ None. */ -/*-------------------------------------------------------------------*/ -/* CALLED FROM : TX/RX */ -/*===================================================================*/ - -void poleFilter_setup_fx(const Word16 *LPC, Word16 N, DTFS_STRUCTURE_FX X_fx, Word16 *S_fx, Word16 *C_fx, Word16 *pf_temp1, Word16 *pf_temp2, Word16 *pf_temp, Word16 *pf_n2_temp1) -{ - Word16 temp1, temp2, HalfLag ; - Word32 sum1_fx, sum2_fx; - Word32 sum; - Word16 k, n, n1, n2; - Word16 exp,tmp; - - HalfLag = s_min(shr(X_fx.lag_fx, 1),X_fx.nH_fx); - - FOR ( k=0; k<=HalfLag; k++ ) - { - temp2 = k; - move16(); - /* Calculate sum1 and sum2 */ - sum1_fx = L_deposit_h(4096); /* 1: Q(12+15+1) */ - - sum2_fx = L_deposit_l(0); - FOR ( n=0 ; n=0) - { - BREAK; - } - } - lk = k; - move16(); - FOR (k=1; k<=HalfLag; k++) - { - freq_fx = L_mult(k, 12800); - if (L_sub(freq_fx, L_hband)>=0) - { - BREAK; - } - } - hk = k; - move16(); - - FOR (k=lk; k -#include "basop_util.h" -#include "prot_fx.h" -#include "stl.h" - -#define PI_HALF_0Q15 51472 /* ~=round(pi/2*2^15) */ -#define PI2_15Q16 0x0006487F /* ~=round(2*PI*2^16) */ -#define PI2_10Q21 13176795 /* ~=round(2*PI*2^21) */ -#define PI2_11Q20 6588397 /* ~=round(2*PI*2^20) */ -#define P54_1Q14 8847 /* ~=round(0.54*2^14) */ -#define P54_0Q15 17695 /* ~=round(0.54*2^15) */ -#define P46_0Q15 15073 /* ~=round(0.46*2^15) */ -#define P92_0Q15 30147 /* ~=round(0.92*2^15) */ +#include #include "options.h" -#include "rom_basop_util.h" +#include "prot.h" +/*------------------------------------------------------------------- + * ham_cos_window() + * + * + *-------------------------------------------------------------------*/ -void ham_cos_window(Word16 *fh, /* o: 0Q15 */ - const Word16 n1, /* i: */ - const Word16 n2 /* i: */ - ) +void ham_cos_window( + float *fh, + int n1, + int n2 +) { - Word16 i; - Word32 cte, cc; - - - - assert( n1>=102 ); /* if n1 is too low -> overflow in div_l */ - /* cte = PI2/(Float32)(2*n1 - 1); */ - BASOP_SATURATE_WARNING_OFF - move16(); - cte = L_deposit_l(div_l(PI2_10Q21,sub(shl(n1,1),1))); /*0Q15*/ - BASOP_SATURATE_WARNING_ON - cc = 0; - FOR (i = 0; i < n1; i++) + float cc, cte; + int i; + cte = PI2/(float)(2*n1 - 1); + cc = 0.0f; + for (i = 0; i < n1; i++) { - /* fh_f[i] = 0.54f - 0.46f * (Float32)cos(cc); */ - BASOP_SATURATE_WARNING_OFF - fh[i] = sub(P54_0Q15, mult_r(getCosWord16(round_fx(L_shl(cc,9))),P92_0Q15)); /*0Q15*/ move16(); - BASOP_SATURATE_WARNING_ON - cc = L_add(cc, cte); /*0Q15*/ + *fh++ = 0.54f - 0.46f * (float)cos(cc); + cc += cte; } - - assert( n2>=26 ); /* if n2 is too low -> overflow in div_l */ - /* cte = PI2/(Float32)(4*n2 - 1); */ - cte = L_deposit_l(div_l(PI2_11Q20,sub(shl(n2,2),1))); /*0Q15*/ - cc = 0; - move16(); - - add(n1,n2); - BASOP_SATURATE_WARNING_OFF - FOR (i = n1; i < n1+n2; i++) + cte = PI2/(float)(4*n2 - 1); + cc = 0.0f; + for (i = 0; i < n2; i++) { - /* fh_f[i] = (Float32)cos(cc); */ - fh[i] = shl(getCosWord16(round_fx(L_shl(cc,10))),1); /*0Q15*/ move16(); - cc = L_add(cc, cte); + *fh++ = (float)cos(cc); + cc += cte; } - BASOP_SATURATE_WARNING_ON - - return; } - diff --git a/src/libs/libevs/lib_com/window_ola.cpp b/src/libs/libevs/lib_com/window_ola.cpp new file mode 100644 index 00000000..09e49805 --- /dev/null +++ b/src/libs/libevs/lib_com/window_ola.cpp @@ -0,0 +1,436 @@ +/*==================================================================================== + EVS Codec 3GPP TS26.443 Nov 13, 2018. Version 12.11.0 / 13.7.0 / 14.3.0 / 15.1.0 + ====================================================================================*/ + +#include +#include "options.h" +#include "cnst.h" +#include "rom_com.h" +#include "prot.h" + +/*-------------------------------------------------------------------------- +* window_ola() +* +* Windowing, Overlap and Add +*--------------------------------------------------------------------------*/ + + +void window_ola( + const float *ImdctOut, /* i : input */ + float *auOut, /* o : output audio */ + float *OldauOut, /* i/o: audio from previous frame */ + const short L, /* i : length */ + const short right_mode, + const short left_mode, /* window overlap of current frame (0: full, 2: none, or 3: half) */ + const short use_bfi_win, /* i : use BFI windowing */ + const short oldHqVoicing, /* i : previous HqVoicing */ + float *oldgapsynth /* i : previous gapsynth */ +) +{ + short i, decimate, decay; + short n ,n16, windecay48, windecay16; + float win_right[R2_48]; + float win_int_left[R1_16]; + float win_left[R1_48]; + float win_int_right[R2_16]; + + + float SS2[L_FRAME48k-NS2SA(48000, N_ZERO_MDCT_NS)]; + float wret2[L_FRAME48k-NS2SA(48000, N_ZERO_MDCT_NS)]; + + float *paout; + + + n = (short)((float)L*N_ZERO_MDCT_NS/FRAME_SIZE_NS); + n16 = (short)((float)L_FRAME16k*N_ZERO_MDCT_NS/FRAME_SIZE_NS); + windecay48 = (short)(2*((float)L_FRAME48k*N_ZERO_MDCT_NS/FRAME_SIZE_NS))+R1_48; + windecay16 = (short)(2*((float)L_FRAME16k*N_ZERO_MDCT_NS/FRAME_SIZE_NS))+R1_16; + decimate = 1; + decay = 0; + + tcx_get_windows_mode1( left_mode, right_mode, win_left, win_right, win_int_left, win_int_right, L); + + if ( L == L_FRAME32k || L == L_FRAME16k ) + { + decimate = 3; + decay = 1; + } + else if ( L == L_FRAME8k ) + { + decimate = 6; + decay = 2; + } + + else if (L == 512) + { + windecay48 = (short)(2*((float)512*N_ZERO_MDCT_NS/FRAME_SIZE_NS))+R1_25; + decimate = 1; + decay = 0; + } + else if (L== 256) + { + windecay48 = (short)(2*((float)512*N_ZERO_MDCT_NS/FRAME_SIZE_NS))+R1_25; + decimate = 2; + decay = 0; + } + + paout=auOut-n; + + if( use_bfi_win ) + { + if ( L == L_FRAME32k ) + { + for (i = 0; i < L/2; i+=2) + { + wret2[L/2-n + i +1] = win_left[(L_FRAME16k/2-i/2-1)*decimate+decay]; + wret2[L/2-n + i] = win_int_left[(L_FRAME16k/2-i/2-1)]; + } + + for (i = n; i < L/2; i+=2) + { + wret2[ i -n] = win_left[(L_FRAME16k-i/2)*decimate-decay-1]; + wret2[ i +1-n] = win_int_left[L_FRAME16k-(i/2)-1]; + } + } + else + { + for (i = 0; i < L/2; i++) + { + wret2[i+L/2-n] = win_left[(L/2-i-1)*decimate+decay]; + } + + for (i =n; i < L/2; i++) + { + wret2[i-n] = win_left[(L-i)*decimate-decay-1]; + } + } + sinq(EVS_PI/(2*(L-n)), EVS_PI/(4*(L-n)), L-n, SS2); + + for (i = n; i < L/2; i++) + { + paout[i] = ImdctOut[L/2 + i]; + } + + for (i = 0; i < L/2; i++) + { + paout[L/2 + i] = -ImdctOut[L - 1 - i]; + } + + if( oldHqVoicing ) + { + for (i=0 ; i < L-n; i++) + { + auOut[i] = auOut[i]*SS2[i]+ oldgapsynth[i+n]*(SS2[L-n-i-1]); + } + } + else + { + for (i=0 ; i < L-n; i++) + { + auOut[i] =auOut[i]*SS2[i]+ OldauOut[i+n]*(SS2[L-n-i-1])/(wret2[i]+0.01f); + } + } + } + + if ( L == L_FRAME32k ) + { + if (use_bfi_win==0) + { + for (i = n; i < L/2; i+=2) + { + paout[i] = ImdctOut[L/2 + i] * win_right[(2*L_FRAME16k-(n16+(i-n)/2))*decimate-1-decay-windecay48]+OldauOut[i]; + paout[i+1] = ImdctOut[L/2 + i +1] * win_int_right[2*L_FRAME16k-(n16+(i-n)/2)-1-windecay16]+OldauOut[i+1]; + } + + for (i = 0; i < L/2-n; i+=2) + { + paout[L/2 + i +1] = -ImdctOut[L - 1 - (i+1)] * win_right[(3*L_FRAME16k/2-1-i/2)*decimate+decay-windecay48]+OldauOut[i+L/2+1]; + paout[L/2 + i ] = -ImdctOut[L - 1 - i] * win_int_right[(3*L_FRAME16k/2-1-i/2)-windecay16]+OldauOut[i+L/2]; + } + + for (i = L/2-n; i < L/2; i+=2) + { + paout[L/2 + i +1] = -ImdctOut[L - 1 - (i+1)]+OldauOut[i+L/2+1] ; + paout[L/2 + i ] = -ImdctOut[L - 1 - i]+OldauOut[i+L/2]; + } + } + + for (i = 0; i < L/2; i+=2) + { + OldauOut[L/2 + i +1] = -ImdctOut[i+1] * win_left[(L_FRAME16k/2-i/2-1)*decimate+decay]; + OldauOut[L/2 + i] = -ImdctOut[i] * win_int_left[(L_FRAME16k/2-i/2-1)]; + } + + + for (i = n; i < L/2; i+=2) + { + OldauOut[ i] = -ImdctOut[L/2 - 1 - i] *win_left[(L_FRAME16k-i/2)*decimate-decay-1]; + OldauOut[ i +1] = -ImdctOut[L/2 - 1 - (i +1)] * win_int_left[L_FRAME16k-(i/2)-1]; + } + } + else + { + if (use_bfi_win==0) + { + + for (i = n; i < L/2; i++) + { + paout[i] = ImdctOut[L/2 + i] * win_right[(2*L-i)*decimate-1-decay-windecay48]+OldauOut[i]; + } + + for (i = 0; i < L/2-n; i++) + { + paout[L/2 + i] = -ImdctOut[L - 1 - i] * win_right[(3*L/2-1-i)*decimate+decay-windecay48]+OldauOut[i+L/2]; + } + for (i = L/2-n; i < L/2; i++) + { + paout[L/2 + i] = -ImdctOut[L - 1 - i] + OldauOut[i+L/2]; + } + } + + for (i = 0; i < L/2; i++) + { + OldauOut[L/2 + i] = -ImdctOut[i] * win_left[(L/2-i-1)*decimate+decay]; + } + + + for (i = n; i < L/2; i++) + { + OldauOut[ i] = -ImdctOut[L/2 - 1 - i] * win_left[(L-i)*decimate-decay-1]; + } + + + } + + for (i = 0; i < n; i++) + { + OldauOut[i] = -ImdctOut[L/2 - 1 - i]; + } + for (i = 0; i < n; i++) + { + paout[L + i] = OldauOut[i]; + } + + return; +} + +/*---------------------------------------------------------------------* +* core_switching_OLA() +* +* modify window after HQ core decoding +* Overlap ACELP and HQ +*---------------------------------------------------------------------*/ + +void core_switching_OLA( + const float *mem_over_hp, /* i : upsampling filter memory */ + const short last_L_frame, /* i : last L_frame lengthture */ + const int output_Fs, /* i : output sampling rate */ + float *synth, /* i/o: synthesized signal from HQ core */ + const float *synth_subfr_out, /* i : synthesized signal from ACELP core */ + float *synth_subfr_bwe, /* i : synthesized BWE from ACELP core */ + const short output_frame, /* i : output frame length */ + const short bwidth /* i : output bandwidth */ +) +{ + short i, L, Loverlapp, out_filt_length, filt_delay, decimate, decay; + float tmp_buf_switch[SWITCH_MAX_GAP], tmp_buf_switch2[HQ_DELAY_COMP*HQ_DELTA_MAX+2]; + float delta; + const float *win, *win_int; + + win = window_48kHz; + win_int = window_8_16_32kHz; + decimate = 1; + decay = 0; + + if( output_frame == L_FRAME32k || output_frame == L_FRAME16k ) + { + decimate = 3; + decay = 1; + } + else if( output_frame == L_FRAME8k ) + { + decimate = 6; + decay = 2; + } + + /* set multiplication factor according to the sampling rate */ + delta = 1; + if( output_frame == L_FRAME16k ) + { + delta = 2; + } + else if( output_frame == L_FRAME32k ) + { + delta = 4; + } + else if( output_frame == L_FRAME48k ) + { + delta = 6; + } + + set_f( tmp_buf_switch, 0, SWITCH_MAX_GAP ); + set_f( tmp_buf_switch2, 0, HQ_DELAY_COMP*HQ_DELTA_MAX+2); + + Loverlapp = (short)(delta*SWITCH_OVERLAP_8k); + + mvr2r( synth_subfr_out,tmp_buf_switch, NS2SA(output_Fs, SWITCH_GAP_LENGTH_NS)); /* copy 6.25 ms subframe */ + + /* conversion from 12.8kHz to output_Fs */ + if( last_L_frame == L_FRAME) + { + /* resample filter memory */ + if( output_frame == L_FRAME8k ) + { + mvr2r( synth_subfr_out + NS2SA(output_Fs, SWITCH_GAP_LENGTH_NS), tmp_buf_switch+NS2SA(output_Fs,SWITCH_GAP_LENGTH_NS),NS2SA(output_Fs, DELAY_CLDFB_NS)); /* copy subframe to tmp buffer */ + } + else + { + out_filt_length = modify_Fs_intcub3m_sup( mem_over_hp+2, NS2SA(12800,DELAY_CLDFB_NS), 12800, tmp_buf_switch2, output_Fs , &filt_delay ); + + for( i=0; i=16000) || (bwidth > NB && output_Fs>16000) ) + { + /* mix cubic and CLDFB resampled buffers in case of resampling to higher frequency rates */ + for(i=0; i=16000) || (bwidth > NB && output_Fs>16000) ) + { + /* mix cubic and CLDFB resampled buffers in case of resampling to higher frequency rates */ + for(i=0; i 0.0001f) + { + A = (x[2]+x[0])/x[1]; + } + else + { + A = 0; + } + + for (i=3; i 0 ) - { - /*A=(x[2]+x[0])/x[1]=2*cos(tmp); here approximated by 2*(1-tmp^2/2!) */ - A32 = L_mult0(tmp,tmp); /*Q30 */ - A32 = L_add(L_sub(1073741824, A32), 1073741824); /*Q30 */ - } - ELSE - { - A32 = L_deposit_l(0); - } - - tmp_old=L_deposit_h(x[2]); /*Q31 */ - tmp_old_old=L_deposit_h(x[1]); /*Q31 */ - - FOR ( i=3; i0) - { - Copy_Scale_sig(OldauOut,OldauOut,L,sub(*Q_sig,add(*Q_old,15))); - *Q_old=sub(*Q_sig,15); - - } - ELSE IF (sub(add(*Q_old,15),*Q_sig)<0) - { - Scale_sig32(ImdctOut,L,sub(add(*Q_old,15),*Q_sig)); - *Q_sig=add(*Q_old,15); - } - - *Q_sig=*Q_old; /*fixing output to new Q_old */ - - - decimate = 1; - move16(); /* L_FRAME 48k */ - decay = 0; - move16(); - windecay48 = WINDECAY48; - move16(); - n=R1_48-R2_48; - move16(); - - test(); - IF (sub(L,L_FRAME32k)==0 || sub(L,L_FRAME16k)==0 ) - { - decimate = 3; - move16(); - decay = 1; - move16(); - n=R1_16-R2_16; - move16(); - - if(sub(L,L_FRAME32k)==0) - { - n=2*N16_CORE_SW; - move16(); - } - - } - ELSE IF (sub(L,L_FRAME8k)==0) - { - decimate = 6; - move16(); - decay = 2; - move16(); - n=(R1_16-R2_16)/2; - move16(); - - } - ELSE IF (sub(L,512)==0) - { - windecay48 = WINDECAY48_256; - move16(); - decimate = 1; - move16(); - decay = 0; - move16(); - n=R1_25-R2_25; - move16(); - - } - ELSE IF (sub(L,256)==0) - { - windecay48 = WINDECAY48_256; - move16(); - decimate = 2; - move16(); - decay = 0; - move16(); - n=(R1_25-R2_25)/2; - move16(); - } - - - paout=auOut-n; - - IF( sub(use_bfi_win,1)==0 ) - { - - temp=sub(L,n); - - tmp2 = div_s(1, temp); /*Q15 */ - tmp2 = round_fx(L_shl(L_mult(tmp2, 25736),2)); /*Q15 */ - - sinq_fx(shr(tmp2,1), shr(tmp2,2), temp, SS2); - - IF ( sub(L,L_FRAME32k)==0 ) - { - p4=SS2+sub(shr(L,1),1); - p1=wret2+sub(shr(L,1),n); - p2=win_int_left+L_FRAME16k/2-1; - p3=win_left+(L_FRAME16k/2-1)*3+1; - - temp_len = shr(L,1); - FOR (i = 0; i < temp_len; i+=2) - { - *p1++=div_s(shr(*p4--,5),add(*p2--,10)); - move16(); - *p1++=div_s(shr(*p4--,5),add(*p3,10)); /*Wret2 Q10 */ move16(); - p3-=decimate; - } - p4=SS2+sub(temp,1); - p1=wret2; - p2=win_left+(L_FRAME16k-N16_CORE_SW)*3-1-1; - p3=win_int_left+L_FRAME16k-N16_CORE_SW-1; - - temp_len = sub(shr(L,1), n); - FOR (i = 0; i < temp_len; i+=2) - { - *p1++=div_s(shr(*p4--,5),*p2); - move16(); - *p1++=div_s(shr(*p4--,5),*p3--); - move16(); - p2-=decimate; - } - - } - ELSE - { - - p2=win_left+add(i_mult2(sub(shr(L,1),1),decimate),decay); - p1=wret2+sub(shr(L,1),n); - p4=SS2+sub(shr(L,1),1); - - temp_len = shr(L,1); - FOR (i = 0; i < temp_len; i++) - { - *p1++=div_s(shr(*p4--,5),add(*p2,10)); /*Wret2 Q10 */ move16(); - p2-=decimate; - - } - - p1=wret2; - p4=SS2+sub(temp,1); - - - p2=win_left+sub(sub(i_mult2(sub(L,n),decimate),decay),1); - temp_len = sub(shr(L,1), n); - FOR (i = 0; i < temp_len; i++) - { - *p1++=div_s(shr(*p4--,5),*p2); - move16(); - p2-=decimate; - - } - - } - - - p1=paout+n; - pa=ImdctOut+add(shr(L,1),n); - - temp_len = sub(shr(L,1),n); - FOR (i = 0; i < temp_len; i++) - { - *p1++=round_fx(L_shl(*pa++,1)); - } - - /*p1=paout+shr(L,1);*/ - pa=ImdctOut+sub(L,1); - temp_len = shr(L,1); - FOR (i = 0; i < temp_len; i++) - { - *p1++ = round_fx(L_negate(L_shl(*pa--,1))); - } - - - p1=auOut; - p2=SS2; - - IF( oldHqVoicing ) - { - /* rescale oldgapsynth */ - Copy_Scale_sig( oldgapsynth, oldgapsynth, L, *Q_sig ); - p3=SS2+sub(temp,1); - p4=oldgapsynth+n; - FOR (i=0 ; i < temp; i++) - { - *p1 =add( mult(*p1,*p2),mult(*p4,*p3));/* auOut[i]*SS2[i]+ oldgapsynth[i+n]*(SS2[L-n-i-1]);*/ move16(); - p1++; - p2++; - p3--; - p4++; - } - } - ELSE - { - p3=wret2; - p4=OldauOut+n; - FOR (i=0; i < temp; i++) - { - *p1 =add( mult(*p1,*p2),shl(mult(*p4,*p3),5));/*auOut[i]*SS2[i]+ OldauOut[i+n]*(SS2[L-n-i-1])/(wret2[i]+0.01f);;*/ move16(); - p1++; - p2++; - p3++; - p4++; - } - } - } - - IF ( sub( L, L_FRAME32k)==0 ) - { - - IF (use_bfi_win==0) - { - /*decimate=3 */ - /*decay=1 */ - p1=paout+n; - pa=ImdctOut+add(shr(L,1),n); - /*p3=win_right+ sub(sub(sub(i_mult2(sub(shl(L,1),n),decimate),1),decay),WINDECAY48); */ - p3=win_right+ (2*L_FRAME16k-N16_CORE_SW)*3-1-1-WINDECAY48; - p5=win_int_right+ (2*L_FRAME16k-N16_CORE_SW)-1-WINDECAY16; - p4=OldauOut+n; - - temp_len = sub(shr(L,1),n); - FOR (i = 0; i < temp_len; i+=2) - { - *p1++=round_fx(L_add(L_shl(Mult_32_16(*pa++,*p3),1),L_deposit_h(*p4++))); /* (( Qin + Q15 -15)+1 + ( Qin - 15 + 16))-1 */ - p3-=decimate; - *p1++=round_fx(L_add(L_shl(Mult_32_16(*pa++,*p5--),1),L_deposit_h(*p4++))); /* (( Qin + Q15 -15)+1 + ( Qin - 15 + 16))-1 */ - /* paout[i] = ImdctOut[L/2 + i] * win_right[(2*L_FRAME16k-(n16+(i-n)/2))*decimate-1-decay-windecay48]+OldauOut[i]; - paout[i+1] = ImdctOut[L/2 + i +1] * win_int_right[2*L_FRAME16k-(n16+(i-n)/2)-1-windecay16]+OldauOut[i+1];*/ - } - - pa=ImdctOut+sub(L,1); - p3=win_right+ (3*L_FRAME16k/2-1)*3+1-WINDECAY48; - p5=win_int_right+ (3*L_FRAME16k/2)-1-WINDECAY16; - - temp_len = sub(shr(L,1),n); - FOR (i = 0; i < temp_len; i+=2) - { - *p1++=round_fx(L_sub(L_deposit_h(*p4++), L_shl(Mult_32_16(*pa--,*p5--),1) )); /* (( Qin + Q15 -15)+1 + ( Qin - 15 + 16))-1 */ - *p1++=round_fx(L_sub(L_deposit_h(*p4++), L_shl(Mult_32_16(*pa--,*p3),1) )); /* (( Qin + Q15 -15)+1 + ( Qin - 15 + 16))-1 */ - p3-=decimate; - /* paout[L/2 + i ] = -ImdctOut[L - 1 - i] * win_int_right[(3*L_FRAME16k/2-1-i/2)-windecay16]+OldauOut[i+L/2]; - paout[L/2 + i +1] = -ImdctOut[L - 1 - (i+1)] * win_right[(3*L_FRAME16k/2-1-i/2)*decimate+decay-windecay48]+OldauOut[i+L/2+1]; */ - } - FOR (i =0; i < n; i+=2) - { - *p1++=round_fx(L_sub(L_deposit_h(*p4++),L_shl(*pa--,1))); - *p1++=round_fx(L_sub(L_deposit_h(*p4++),L_shl(*pa--,1))); - /* paout[L/2 + i +1] = -ImdctOut[L - 1 - (i+1)]+OldauOut[i+L/2+1] ; - paout[L/2 + i ] = -ImdctOut[L - 1 - i]+OldauOut[i+L/2]; */ - } - } - - p1=OldauOut+shr(L,1); - pa=ImdctOut; - p2=win_int_left+L_FRAME16k/2-1; - p3=win_left+(L_FRAME16k/2-1)*3+1; - - temp_len = shr(L,1); - FOR (i = 0; i < temp_len; i+=2) - { - *p1++=round_fx(L_negate(L_shl(Mult_32_16(*pa++,*p2--),1))); - *p1++=round_fx(L_negate(L_shl(Mult_32_16(*pa++,*p3),1))); - p3-=decimate; - /* OldauOut[L/2 + i] = -ImdctOut[i] * win_int_left[(L_FRAME16k/2-i/2-1)]; - OldauOut[L/2 + i +1] = -ImdctOut[i+1] * win_left[(L_FRAME16k/2-i/2-1)*decimate+decay]*/; - - } - - p1=OldauOut+n; - pa=ImdctOut+sub(sub(shr(L,1),1),n); - p2=win_left+(L_FRAME16k-N16_CORE_SW)*3-1-1; - p3=win_int_left+L_FRAME16k-N16_CORE_SW-1; - temp_len = sub(shr(L,1),n); - FOR (i = 0; i < temp_len; i+=2) - { - *p1++=round_fx(L_negate(L_shl(Mult_32_16(*pa--,*p2),1))); - *p1++=round_fx(L_negate(L_shl(Mult_32_16(*pa--,*p3--),1))); - p2-=decimate; - /* OldauOut[ i] = -ImdctOut[L/2 - 1 - i] *win_left[(L_FRAME16k-i/2)*decimate-decay-1]; - OldauOut[ i +1] = -ImdctOut[L/2 - 1 - (i +1)] * win_int_left[L_FRAME16k-(i/2)-1];; */ - } - - } - ELSE - { - IF (use_bfi_win==0) - { - - p1=paout+n; - pa=ImdctOut+add(shr(L,1),n); - p3=win_right+sub(sub(sub(i_mult2(sub(shl(L,1),n),decimate),1),decay),windecay48); - p4=OldauOut+n; - - temp_len = sub(shr(L,1), n); - FOR (i = 0; i < temp_len; i++) - { - *p1++=round_fx(L_add(L_shl(Mult_32_16(*pa++,*p3),1),L_deposit_h(*p4++))); /* (( Qin + Q15 -15)+1 + ( Qin - 15 + 16))-1 */ - p3-=decimate; - /*paout[i] = ImdctOut[L/2 + i] * win_right[(2*L-i)*decimate-1-decay-windecay48]+OldauOut[i];*/ - } - - - pa=ImdctOut+sub(L,1); - p3=win_right+sub(add(i_mult2(sub(i_mult2(shr(L,1),3) ,1),decimate),decay),windecay48); - temp_len = sub(shr(L,1),n); - FOR (i = 0; i < temp_len; i++) - { - *p1++=round_fx(L_sub(L_deposit_h(*p4++), L_shl(Mult_32_16(*pa--,*p3),1) )); /* (( Qin + Q15 -15)+1 + ( Qin - 15 + 16))-1 */ - p3-=decimate; - /* paout[L/2 + i] = -ImdctOut[L - 1 - i] * win_right[(3*L/2-1-i)*decimate+decay-windecay48]+OldauOut[i+L/2]; */ - } - FOR (i =0; i < n; i++) - { - *p1++=round_fx(L_sub(L_deposit_h(*p4++),L_shl(*pa--,1))); - /* paout[L/2 + i] = -ImdctOut[L - 1 - i] + OldauOut[i+L/2]; */ - } - } - - - p1=OldauOut+shr(L,1); - pa=ImdctOut; - p2=win_left+add(i_mult2(sub(shr(L,1),1),decimate),decay); - - temp_len = shr(L, 1); - FOR (i = 0; i < temp_len; i++) - { - *p1++=round_fx(L_negate(L_shl(Mult_32_16(*pa++,*p2),1))); - p2-=decimate; - /*OldauOut[L/2 + i] = -ImdctOut[i] * win_left[(L/2-i-1)*decimate+decay]; */ - } - - p1=OldauOut+n; - pa=ImdctOut+sub(sub(shr(L,1),1),n); - p2=win_left+sub(sub(i_mult2(sub(L,n),decimate),decay),1); - temp_len = sub(shr(L,1),n); - FOR (i = 0; i < temp_len; i++) - { - *p1++=round_fx(L_negate(L_shl(Mult_32_16(*pa--,*p2),1))); - p2-=decimate; - /* OldauOut[ i] = -ImdctOut[L/2 - 1 - i] * win_left[(L-i)*decimate-decay-1]; */ - } - - - } - - p1=OldauOut; - pa=ImdctOut+sub(shr(L,1),1); - p2=paout+L; - - FOR (i = 0; i < n; i++) - { - *p1=round_fx(L_negate(L_shl(*pa--,1))); - *p2++=*p1++; - } - - /* for (i = 0; i < n; i++) - { - OldauOut[ i] = -ImdctOut[L/2 - 1 - i]; - } - for (i =0; i = 0) || (sub(bwidth, NB) > 0 && L_sub(output_Fs, 16000) > 0) ) - { - /* mix cubic and CLDFB resampled buffers in case of resampling to higher frequency rates */ - buf_offset = i_mult2(SWITCH_GAP_LENGTH_8k, delta); - divisor = getNormReciprocalWord16(out_filt_length); - FOR(i=0; i= 0) || (sub(bwidth, NB) > 0 && L_sub(output_Fs, 16000) > 0) ) - { - /* mix cubic and CLDFB resampled buffers in case of resampling to higher frequency rates */ - buf_offset = i_mult2(SWITCH_GAP_LENGTH_8k, delta); - divisor = getNormReciprocalWord16(out_filt_length); - FOR(i=0; i Q15 */ - *pt2 = shl( mult_r(*pt2,*pt4),1); - move16();/*/= win[(3*L_FRAME16k/2-1-i/2)*decimate+decay-L_FRAME48k*14/20]; */ - pt+=2; - pt2+=2; - pt5-=3; - pt4--; - - } - } - ELSE - { - - pt=synth+tmp; - pt5=on_win+210-1; - temp_len = i_mult2(shr(R2_16,2),delta); - FOR( i=0 ; i< temp_len; i++ ) - { - *pt=shl( mult_r(*pt,*pt5),1); - move16();/* /= win[(3*output_frame/2-1-i)*decimate+decay-L_FRAME48k*14/20]; */ - pt++; - pt5-=decimate; - move16(); - } - } - - - pt=synth+tmp; - move16();/*Q15 */ - pt2=synth_subfr_bwe+tmp-NS2SA(output_Fs, DELAY_CLDFB_NS); - move16(); /*Q15 */ - pt3=tmp_buf_switch+tmp; - move16(); /*Q15 */ - - FOR( i=0; i + + +/*--------------------------------------------------------------------------* +* mvr2r_inv() +* +* +*--------------------------------------------------------------------------*/ + +static void mvr2r_inv( + const float *in, + float *out, + short L, + short decimate +) +{ + short i; + + in=in+(short) ((decimate-1)/2); + out=out+L-1; + + for (i=0; i0) - { - - Copy_Scale_sig(old_wtda,old_wtda,L,sub(*Q,*Qold_wtda)); - *Qold_wtda=*Q; - move16(); - } - ELSE IF (sub(*Qold_wtda,*Q)<0) - { - Copy_Scale_sig(new_audio,new_audio,L,sub(*Qold_wtda,*Q)); - *Q=*Qold_wtda; - move16(); - } - - allsig_r = new_audio+n; - allsig_l = old_wtda+n; - } - - - - IF ( L == L_FRAME32k ) - { - - /* decimate = 3 */ - /* decay =1 */ - - pa=wtda_audio; - p1=allsig_r+L_FRAME16k-1; - p2=win_int_right+ 3*L_FRAME16k/2-1-WINDECAY16; /* 3*L/2*decimate-decimate+decay-windecay48;*/ - p3=p1+1; - p4=p2+1; - - p5=win_right+(3*L_FRAME16k/2-1)*3+1-WINDECAY48; - p6=win_right+(3*L_FRAME16k/2+1)*3-1-1-WINDECAY48; - - FOR (i=0; i -#include -#include -#include #include "options.h" -#include "stl.h" -#include "rom_com_fx.h" -#include "rom_dec_fx.h" -#include "basop_util.h" -#include "stl.h" -#include "cnst_fx.h" -#include "prot_fx.h" +#include "cnst.h" +#include "rom_com.h" +#include "prot.h" -/** - * \brief Arithmetic decoder - * \param[i/o] st - * \param[o] x - * \param[i] nt - * \param[i] nbbits - * \param[i] resQMaxBits - * \return resQBits - */ -Word16 ACcontextMapping_decode2_no_mem_s17_LC( - Decoder_State_fx *st,/* i/o: decoder state */ - Word16 *x, /* o: decoded spectrum */ - Word16 nt, /* i: size of spectrum */ - Word16 nbbits, /* i: bit budget */ - Word16 resQMaxBits, /* i: residual coding maximum bits*/ - CONTEXT_HM_CONFIG *hm_cfg /* i: context-based harmonic model configuration */ +/*-------------------------------------------------------------------* +* ACcontextMapping_decode2_no_mem_s17_LC() +* +* Arithmetic decoder +*-------------------------------------------------------------------*/ + +long ACcontextMapping_decode2_no_mem_s17_LC( /* o: resQBits */ + Decoder_State *st, /* i/o: decoder state */ + int *x, /* o: decoded spectrum */ + long nt, /* i: size of spectrum */ + int nbbits, /* i: bit budget */ + int resQMaxBits, /* i: residual coding maximum bits */ + CONTEXT_HM_CONFIG *hm_cfg /* i: context-based harmonic model configuration*/ ) { - TastatDec as; - Word16 start_bit_pos, lsbs_bit_pos, overflow_bit_pos; - Word16 a, b, t, a1, b1, a1_i, b1_i, k, L; - Word16 lev, pki, esc_nb; - Word16 rateFlag; - Word16 r, lastnz, n; - Word16 resQBits; - Word16 rest_bits, rest_bits_overflow; - Word16 tmp=0; /* initialize just to avoid compiler warning */ - Word16 nt_half; - Word16 c[2], *ctx; - Word16 p1, p2; - Word16 ii[2], idx1, idx2, idx; - Word16 numPeakIndicesOrig, numHoleIndices; - get_next_coeff_function get_next_coeff; - Word16 nbbits_m2; - Word32 La, Lb; + Tastat as; + int start_bit_pos, lsbs_bit_pos, overflow_bit_pos; + int a, b, t, a1, b1, a1_i, b1_i, k; + int lev, pki, esc_nb; + int rateFlag; + int r, lastnz, n; + int resQBits; + int rest_bits, rest_bits_overflow; + int nt_half; + int c[2], *ctx; + int p1, p2; + int ii[2], idx1, idx2, idx; + int numPeakIndicesOrig, numHoleIndices; + int nbbits_m2; - r = 0; /* to avoid compilation warnings */ move16(); - esc_nb = 0; /* to avoid compilation warnings */ move16(); - set16_fx(x, 0, nt); + set_i(x, 0, nt); /* Rate flag */ - rateFlag = 0; - move16(); - if (sub(nbbits, 400) > 0) + if (nbbits>400) { rateFlag = 2 << NBITS_CONTEXT; - move16(); + } + else + { + rateFlag = 0; } /*Decode number of ntuples*/ - start_bit_pos = st->next_bit_pos_fx; - move16(); - lsbs_bit_pos = add(start_bit_pos, sub(nbbits, 1)); + start_bit_pos = st->next_bit_pos; + lsbs_bit_pos = start_bit_pos + nbbits - 1; n = 0; - move16(); + k = 1; + nt_half = nt>>1; - L = sub(14, norm_s(negate(nt))); - n = add(get_next_indice_fx(st, L), 1); + while (k 0 || st->BER_detect) + lastnz = n << 1; + if (lastnz > nt || st->BER_detect) { st->BER_detect = 1; - move16(); return 0; } - IF (hm_cfg) /* mapped domain */ + if (hm_cfg) { + /* mapped domain */ numPeakIndicesOrig = hm_cfg->numPeakIndices; - move16(); - hm_cfg->numPeakIndices = s_min(hm_cfg->numPeakIndices, lastnz); - move16(); - numHoleIndices = sub(lastnz, hm_cfg->numPeakIndices); + hm_cfg->numPeakIndices = min(hm_cfg->numPeakIndices, lastnz ); + numHoleIndices = lastnz - hm_cfg->numPeakIndices; /* Mark hole indices beyond lastnz as pruned */ - FOR (k=numHoleIndices; knumHoleIndices; ++k) + for (k=numHoleIndices; knumHoleIndices; ++k) { - hm_cfg->holeIndices[k] = add(hm_cfg->holeIndices[k], nt); - move16(); + hm_cfg->holeIndices[k] = hm_cfg->holeIndices[k] + nt; } ii[0] = numPeakIndicesOrig; - move16(); ii[1] = 0; - move16(); - get_next_coeff = get_next_coeff_mapped; - move16(); + p1 = p2 = 0; /* to avoid compilation warnings */ } - ELSE /* unmapped domain */ + else { + /* unmapped domain */ ii[0] = 0; - move16(); - p1 = p2 = 0; - move16(); - move16(); - - get_next_coeff = get_next_coeff_unmapped; - move16(); } /* Start Decoding */ + ari_start_decoding_14bits(st, &as); + overflow_bit_pos = st->next_bit_pos; - overflow_bit_pos = st->next_bit_pos_fx; - move16(); - nbbits_m2 = add(nbbits, cbitsnew - 2); - rest_bits_overflow = rest_bits = negate(nbbits_m2); - move16(); + nbbits_m2 = nbbits + cbitsnew - 2; + rest_bits_overflow = rest_bits = -nbbits_m2; - /*Main Loop through the 2-tuples*/ - FOR (k = 0; k < lastnz; k += 2) + /* Main Loop through the 2-tuples */ + for (k=0; k 0) - { - t = add(t, 1 << NBITS_CONTEXT); - } + t = *ctx + rateFlag; + t -= ((nt_half - idx) >> (sizeof(int)*8-1)) << NBITS_CONTEXT; - test(); - IF (t < 0 || lsbs_bit_pos <= 0) + esc_nb = 0; + r = 0; + if (t < 0 || lsbs_bit_pos <= 0) { st->BER_detect = 1; - move16(); return 0; } - La = L_deposit_l(0); - Lb = L_deposit_l(0); + a = b = 0; /* MSBs decoding */ - test(); - FOR (lev = 0; lev < 15 && lsbs_bit_pos > 0; lev++) + for (lev = 0; lev < 15 && lsbs_bit_pos > 0; ++lev) { - test(); - esc_nb = s_min(lev, 3); - tmp = add(t, Tab_esc_nb[esc_nb]); - assert(tmp >= 0 && tmp < 4096); - pki = ari_lookup_s17_LC[tmp]; - move16(); - r = ari_decode_14bits_s17_ext(st, &as, ari_pk_s17_LC_ext[pki]); + esc_nb = min(lev, 3); + pki = ari_lookup_s17_LC[t + (esc_nb << (NBITS_CONTEXT + NBITS_RATEQ))]; + ari_decode_14bits_s17_ext(st,&r,&as,ari_pk_s17_LC_ext[pki]); - IF (sub(r, VAL_ESC) < 0) + if (r= 0)) || (sub(lev, 14) > 0) ) + if ( (lsbs_bit_pos < -1 && r >= VAL_ESC) || (lev > 14) ) { x[a1_i] = 0; - move16(); x[b1_i] = 0; - move16(); st->BER_detect = 1; - move16(); return 0; } - /*MSBs contributions*/ - b1 = shr(r, 2); - a1 = s_and(r, 0x3); - a = extract_l(L_mac0(La, pow2tab[lev], a1)); - b = extract_l(L_mac0(Lb, pow2tab[lev], b1)); + /* MSBs contributions */ + b1 = r>>2; + a1 = r&0x3; + a += a1 << lev; + b += b1 << lev; - /*lsbs bits sign bits*/ - rest_bits = add(rest_bits, shl(lev, 1)); + /* lsbs bits sign bits */ + rest_bits += 2*lev; - if (a > 0) - { - rest_bits = add(rest_bits, 1); - } - if (b > 0) - { - rest_bits = add(rest_bits, 1); - } + rest_bits += min(a, 1); + rest_bits += min(b, 1); - /*Dectect overflow*/ - IF (add(sub(st->next_bit_pos_fx, start_bit_pos), rest_bits) > 0) + /* Dectect overflow */ + + if (st->next_bit_pos-start_bit_pos+rest_bits>0) { /* Roll back bit-stream position to overflow_bit_pos */ - get_next_indice_tmp_fx(st, sub(overflow_bit_pos, st->next_bit_pos_fx)); + get_next_indice_tmp(st, overflow_bit_pos - st->next_bit_pos); rest_bits = rest_bits_overflow; - move16(); x[a1_i] = 0; - move16(); x[b1_i] = 0; - move16(); - BREAK; + break; } - overflow_bit_pos = st->next_bit_pos_fx; - move16(); + overflow_bit_pos = st->next_bit_pos; rest_bits_overflow = rest_bits; - move16(); /* Store decoded data */ x[a1_i] = a; - move16(); x[b1_i] = b; - move16(); /* Update context for next 2-tuple */ - IF (sub(p1, p2) == 0) /* peak-peak or hole-hole context */ + if (p1 == p2) { - lev = sub(esc_nb, 1); - if (lev > 0) t = add(12, lev); - if (lev <= 0) t = add(a1, b1); - if (lev == 0) t = add(t, t); + /* peak-peak or hole-hole context */ + lev = esc_nb - 1; - *ctx = add(shl(s_and(*ctx, 0xf), 4), add(t, 1)); - move16(); - } - ELSE /* mixed context */ - { - IF (s_and(idx1, 1)) /* update first context */ + if (lev <= 0) { - c[p1] = update_mixed_context(c[p1], a); - move16(); + t = 1 + (a1 + b1)*(lev+2); + } + else + { + t = 13 + lev; } - IF (s_and(idx2, 1)) /* update second context */ + *ctx = (*ctx & 0xf) * 16 + t; + } + else + { + /* mixed context */ + + if (idx1 & 1) { + /* update first context */ + c[p1] = update_mixed_context(c[p1], a); + } + + if (idx2 & 1) + { + /* update second context */ c[p2] = update_mixed_context(c[p2], b); - move16(); } } } /* Total number of decoded AC bits */ - get_next_indice_tmp_fx(st, -(cbitsnew - 2)); + get_next_indice_tmp(st, -(cbitsnew - 2)); - /*detect overflow*/ - IF (sub(k, lastnz) != 0) + /* detect overflow */ + + if(k!=lastnz) { - rest_bits = add(rest_bits, nbbits_m2); + rest_bits += nbbits_m2; /* Set bit-stream position to (start_bit_pos+nbbits-rest_bits) */ - get_next_indice_tmp_fx(st, sub((sub(add(start_bit_pos, nbbits), rest_bits)), st->next_bit_pos_fx)); + get_next_indice_tmp(st, (start_bit_pos+nbbits-rest_bits)-st->next_bit_pos); } - /*Decode signs*/ + /* Decode signs */ if (hm_cfg) { - tmp = nt; - move16(); + n = nt; } - if (!hm_cfg) + else { - tmp = lastnz; - move16(); + n = lastnz; } - FOR (k = 0; k < tmp; k++) + + for (k = 0; k < n; k++) { - IF (x[k] > 0) + if (x[k] > 0) { - if (get_next_indice_1_fx(st) != 0) - { - x[k] = negate(x[k]); - move16(); - } + x[k] *= 1-2*get_next_indice_1(st); } } /*Decode Residual Q*/ - resQBits = s_min(resQMaxBits, sub(add(lsbs_bit_pos,1), st->next_bit_pos_fx)); - FOR (k=0; knext_bit_pos); + + for (k=0; knext_bit_pos_fx)); + get_next_indice_tmp(st, (start_bit_pos+nbbits)-st->next_bit_pos); return resQBits; } - diff --git a/src/libs/libevs/lib_dec/EvsRXlib.cpp b/src/libs/libevs/lib_dec/EvsRXlib.cpp old mode 100755 new mode 100644 index 500ace66..313916af --- a/src/libs/libevs/lib_dec/EvsRXlib.cpp +++ b/src/libs/libevs/lib_dec/EvsRXlib.cpp @@ -1,29 +1,27 @@ /*==================================================================================== - EVS Codec 3GPP TS26.442 Apr 03, 2018. Version 12.11.0 / 13.6.0 / 14.2.0 + EVS Codec 3GPP TS26.443 Nov 13, 2018. Version 12.11.0 / 13.7.0 / 14.3.0 / 15.1.0 ====================================================================================*/ #include #include +#include +#include #include #include "options.h" -#include "prot_fx.h" +#include "prot.h" #include "EvsRXlib.h" #include "jbm_jb4sb.h" #include "jbm_pcmdsp_apa.h" #include "jbm_pcmdsp_fifo.h" - -#include "stl.h" -#include "basop_util.h" -#include "basop_util_jbm.h" - +#include "cnst.h" struct EVS_RX { - Decoder_State_fx *st; + unsigned int nSamplesFrame; + Decoder_State *st; JB4_HANDLE hJBM; - Word16 lastDecodedWasActive; - Word16 samplesPerMs; /* sampleRate / 1000 */ + unsigned int lastDecodedWasActive; PCMDSP_APA_HANDLE hTimeScaler; PCMDSP_FIFO_HANDLE hFifoAfterTimeScaler; #ifdef SUPPORT_JBM_TRACEFILE @@ -32,47 +30,41 @@ struct EVS_RX }; /* function to check if a frame contains a SID */ -static Word16 isSidFrame( Word16 size ); +static int isSidFrame( unsigned int size ); /* Opens the EVS Receiver instance. */ EVS_RX_ERROR EVS_RX_Open(EVS_RX_HANDLE* phEvsRX, - Decoder_State_fx *st, + Decoder_State *st, Word16 jbmSafetyMargin) { EVS_RX_HANDLE hEvsRX; - Word16 divScaleFac, wss, css; + uint16_t wss, css; *phEvsRX = NULL; - move16(); /* Create EVS Receiver handle */ *phEvsRX = (EVS_RX_HANDLE) calloc(1, sizeof(struct EVS_RX) ); - move16(); - IF( *phEvsRX == NULL ) + if ( *phEvsRX == NULL ) { return EVS_RX_MEMORY_ERROR; } hEvsRX = *phEvsRX; - move16(); hEvsRX->st = st; - move16(); /* do not use codec for time stretching (PLC) before initialization with first received frame */ st->codec_mode = 0; - move16(); /* open JBM */ hEvsRX->hJBM = 0; - move16(); - IF( JB4_Create(&(hEvsRX->hJBM)) != 0) + if( JB4_Create(&(hEvsRX->hJBM)) != 0) { EVS_RX_Close(phEvsRX); return EVS_RX_INIT_ERROR; } /* init JBM */ - IF(JB4_Init(hEvsRX->hJBM, jbmSafetyMargin) != 0) + if(JB4_Init(hEvsRX->hJBM, jbmSafetyMargin) != 0) { EVS_RX_Close(phEvsRX); return EVS_RX_INIT_ERROR; @@ -80,56 +72,41 @@ EVS_RX_ERROR EVS_RX_Open(EVS_RX_HANDLE* phEvsRX, hEvsRX->lastDecodedWasActive = 0; - move16(); - hEvsRX->samplesPerMs = BASOP_Util_Divide3216_Scale(st->output_Fs_fx, 1000, &divScaleFac); - hEvsRX->samplesPerMs = shl(hEvsRX->samplesPerMs, add(divScaleFac, 1)); - assert(hEvsRX->samplesPerMs == st->output_Fs_fx / 1000); + hEvsRX->nSamplesFrame = st->output_Fs / 50; - IF(L_sub(st->output_Fs_fx, 8000) == 0) + if(st->output_Fs == 8000) { wss = 1; - move16(); css = 1; - move16(); } - ELSE IF(L_sub(st->output_Fs_fx, 16000) == 0) + else if(st->output_Fs == 16000) { wss = 2; - move16(); css = 1; - move16(); } - ELSE IF(L_sub(st->output_Fs_fx, 32000) == 0) + else if(st->output_Fs == 32000) { wss = 4; - move16(); css = 2; - move16(); } - ELSE IF(L_sub(st->output_Fs_fx, 48000) == 0) + else if(st->output_Fs == 48000) { wss = 6; - move16(); css = 3; - move16(); } - ELSE + else { assert(0 || "unknown sample rate!"); wss = css = 1; /* just to avoid compiler warning */ } - /* initialize time scaler and FIFO after time scaler */ test(); - test(); - test(); - test(); - test(); - IF( apa_init( &hEvsRX->hTimeScaler ) != 0 || - apa_set_rate( hEvsRX->hTimeScaler, st->output_Fs_fx, 1 ) != 0 || - apa_set_complexity_options( hEvsRX->hTimeScaler, wss, css ) != 0 || - apa_set_quality( hEvsRX->hTimeScaler, L_deposit_h(1), 4, 4 ) != 0 || - pcmdsp_fifo_create( &hEvsRX->hFifoAfterTimeScaler ) != 0 || - pcmdsp_fifo_init( hEvsRX->hFifoAfterTimeScaler, i_mult2(4, st->output_frame_fx) /* 4 frames */, 1, 2 /* Word16 */ ) != 0 ) + /* initialize time scaler and FIFO after time scaler */ + if( apa_init( &hEvsRX->hTimeScaler ) != 0 || + apa_set_rate( hEvsRX->hTimeScaler, st->output_Fs, 1 ) != 0 || + apa_set_complexity_options( hEvsRX->hTimeScaler, wss, css) != 0 || + apa_set_quality( hEvsRX->hTimeScaler, 1, 4, 4 ) != 0 || + pcmdsp_fifo_create( &hEvsRX->hFifoAfterTimeScaler ) != 0 || + pcmdsp_fifo_init( hEvsRX->hFifoAfterTimeScaler, st->output_Fs * 4 / 50 /* 4 frames */, 1, 2 /* Word16 */ ) != 0 ) { EVS_RX_Close(phEvsRX); return EVS_RX_TIMESCALER_ERROR; @@ -163,15 +140,15 @@ EVS_RX_SetJbmTraceFileName(EVS_RX_HANDLE hEvsRX, /* Feeds one frame into the receiver. */ EVS_RX_ERROR EVS_RX_FeedFrame(EVS_RX_HANDLE hEvsRX, - UWord8 *au, - Word16 auSize, - Word16 rtpSequenceNumber, - Word32 rtpTimeStamp, - Word32 rcvTime_ms) + unsigned char *au, + unsigned int auSize, + unsigned short rtpSequenceNumber, + unsigned long rtpTimeStamp, + unsigned int rcvTime_ms) { JB4_DATAUNIT_HANDLE dataUnit; - Word16 partialCopyFrameType, partialCopyOffset; - Word16 result; + int16_t partialCopyFrameType, partialCopyOffset; + int result; assert( auSize != 0 ); assert( (auSize + 7) / 8 <= MAX_AU_SIZE ); @@ -181,56 +158,42 @@ EVS_RX_FeedFrame(EVS_RX_HANDLE hEvsRX, /* create data unit for primary copy in the frame */ dataUnit = JB4_AllocDataUnit(hEvsRX->hJBM); - copyWord8((Word8*)au, (Word8*)dataUnit->data, shr(add(auSize, 7), 3) ); + memcpy(dataUnit->data, au, (auSize + 7) / 8); dataUnit->dataSize = auSize; - move16(); dataUnit->duration = 20; - move32(); dataUnit->sequenceNumber = rtpSequenceNumber; - move16(); dataUnit->silenceIndicator = isSidFrame( dataUnit->dataSize ); dataUnit->timeScale = 1000; - move32(); dataUnit->rcvTime = rcvTime_ms; - move32(); dataUnit->timeStamp = rtpTimeStamp; - move32(); dataUnit->partial_frame = 0; - move16(); dataUnit->partialCopyOffset = partialCopyOffset; - move16(); + /* add the frame to the JBM */ result = JB4_PushDataUnit(hEvsRX->hJBM, dataUnit, rcvTime_ms); - IF(result != 0) + if(result != 0) { return EVS_RX_JBM_ERROR; } - test(); - IF(sub(partialCopyFrameType, RF_NO_DATA) != 0 && partialCopyOffset != 0) + + if(partialCopyFrameType != RF__NO_DATA && partialCopyOffset != 0) { /* create data unit for partial copy in the frame */ dataUnit = JB4_AllocDataUnit(hEvsRX->hJBM); - copyWord8((Word8*)au, (Word8*)dataUnit->data, shr(add(auSize, 7), 3) ); + memcpy(dataUnit->data, au, (auSize + 7) / 8); dataUnit->dataSize = auSize; - move16(); dataUnit->duration = 20; - move32(); dataUnit->sequenceNumber = rtpSequenceNumber; - move16(); - dataUnit->silenceIndicator = 0; /* there are no partial copies for SID frames */ move16(); + dataUnit->silenceIndicator = 0; /* there are no partial copies for SID frames */ dataUnit->timeScale = 1000; - move32(); dataUnit->rcvTime = rcvTime_ms; - move32(); - dataUnit->timeStamp = rtpTs_sub(rtpTimeStamp, L_mult0(partialCopyOffset, 20)); - assert(dataUnit->timeStamp == rtpTimeStamp - partialCopyOffset * dataUnit->duration); + dataUnit->timeStamp = rtpTimeStamp - partialCopyOffset * dataUnit->duration; dataUnit->partial_frame = 1; - move16(); dataUnit->partialCopyOffset = partialCopyOffset; - move16(); + /* add the frame to the JBM */ result = JB4_PushDataUnit(hEvsRX->hJBM, dataUnit, rcvTime_ms); - IF(result != 0) + if(result != 0) { return EVS_RX_JBM_ERROR; } @@ -238,175 +201,156 @@ EVS_RX_FeedFrame(EVS_RX_HANDLE hEvsRX, return EVS_RX_NO_ERROR; } + /* Retrieves one frame of output PCM data. */ EVS_RX_ERROR EVS_RX_GetSamples(EVS_RX_HANDLE hEvsRX, - Word16 *nOutSamples, - Word16 *pcmBuf, - Word16 pcmBufSize, - Word32 systemTimestamp_ms) + unsigned int* nOutSamples, + Word16 *pcmBuf, + unsigned int pcmBufSize, + unsigned int systemTimestamp_ms + ) { - Decoder_State_fx *st; - Word16 soundCardFrameSize, extBufferedSamples; - Word32 extBufferedTime_ms; - Word16 scale, maxScaling, nTimeScalerOutSamples; - Word16 timeScalingDone, result; + Decoder_State *st; + unsigned int soundCardFrameSize, extBufferedSamples; + uint32_t extBufferedTime_ms, scale, maxScaling; + uint16_t nTimeScalerOutSamples; + int timeScalingDone, result; JB4_DATAUNIT_HANDLE dataUnit; - Word16 tmp; + float output[3 * L_FRAME48k]; /* 'float' buffer for output synthesis */ - assert(hEvsRX->st->output_frame_fx <= pcmBufSize); - assert(hEvsRX->st->output_frame_fx <= APA_BUF); + assert(hEvsRX->nSamplesFrame <= pcmBufSize); + assert(hEvsRX->nSamplesFrame <= APA_BUF); st = hEvsRX->st; - move16(); - soundCardFrameSize = st->output_frame_fx; - move16(); + soundCardFrameSize = hEvsRX->nSamplesFrame; timeScalingDone = 0; - move16(); + /* make sure that the FIFO after decoder/scaler contains at least one sound card frame (i.e. 20ms) */ - WHILE(sub(pcmdsp_fifo_nReadableSamples(hEvsRX->hFifoAfterTimeScaler), soundCardFrameSize) < 0) + while( pcmdsp_fifo_nReadableSamples( hEvsRX->hFifoAfterTimeScaler ) < soundCardFrameSize ) { extBufferedSamples = pcmdsp_fifo_nReadableSamples( hEvsRX->hFifoAfterTimeScaler ); - extBufferedTime_ms = L_deposit_l(idiv1616U(extBufferedSamples, hEvsRX->samplesPerMs)); + extBufferedTime_ms = extBufferedSamples * 1000 / st->output_Fs; dataUnit = NULL; - move16(); /* pop one access unit from the jitter buffer */ result = JB4_PopDataUnit(hEvsRX->hJBM, systemTimestamp_ms, extBufferedTime_ms, &dataUnit, &scale, &maxScaling); - IF(result != 0) + if(result != 0) { return EVS_RX_JBM_ERROR; } - if(sub(maxScaling, 20) > 0) - { - maxScaling = 20; - move16(); - } - maxScaling = i_mult2(maxScaling, hEvsRX->samplesPerMs); - assert(maxScaling >= 0); + maxScaling = maxScaling * st->output_Fs / 1000; /* avoid time scaling multiple times in one sound card slot */ - IF(sub(scale, 100) != 0) + if( scale != 100U ) { - if( timeScalingDone != 0 ) - { + if( timeScalingDone ) scale = 100; - move16(); - } - timeScalingDone = 1; - move16(); + else + timeScalingDone = 1; } /* copy bitstream into decoder state */ - IF(dataUnit) + if(dataUnit) { - IF( sub(st->codec_mode,0) != 0 ) + if( st->codec_mode != 0 ) { - tmp = 0; - if (sub(dataUnit->partial_frame,1)==0) - { - tmp = 1; - } - read_indices_from_djb_fx( st, dataUnit->data, dataUnit->dataSize, tmp, dataUnit->nextCoderType ); - - IF(dataUnit->partial_frame != 0) + read_indices_from_djb( st, dataUnit->data, dataUnit->dataSize, (dataUnit->partial_frame==TRUE)? 1:0, dataUnit->nextCoderType ); + if(dataUnit->partial_frame != 0) { st->codec_mode = MODE2; st->use_partial_copy = 1; } } - ELSE /* initialize decoder with first received frame */ + else /* initialize decoder with first received frame */ { /* initialize, since this is needed within read_indices_from_djb, to correctly set st->last_codec_mode */ - st->ini_frame_fx = 0; + st->ini_frame = 0; st->prev_use_partial_copy = 0; /* initialize st->last_codec_mode, since this is needed for init_decoder() */ - read_indices_from_djb_fx( st, dataUnit->data, dataUnit->dataSize, 0, 0 ); + read_indices_from_djb( st, dataUnit->data, dataUnit->dataSize, 0, 0 ); + assert(st->codec_mode != 0); - init_decoder_fx( st ); + init_decoder( st ); + /* parse frame again because init_decoder() overwrites st->total_brate */ + read_indices_from_djb( st, dataUnit->data, dataUnit->dataSize, 0, 0 ); - /* parse frame again because init_decoder() overwrites st->total_brate_fx */ - read_indices_from_djb_fx( st, dataUnit->data, dataUnit->dataSize, 0, 0 ); } - } - ELSE IF( st->codec_mode != 0 ) + else if( st->codec_mode != 0 ) { - read_indices_from_djb_fx( st, NULL, 0, 0, 0 ); + read_indices_from_djb( st, NULL, 0, 0, 0 ); } /* run the main decoding routine */ - SUB_WMOPS_INIT("evs_dec"); - IF( sub(st->codec_mode, MODE1) == 0 ) + if( st->codec_mode == MODE1 ) { - IF( st->Opt_AMR_WB_fx ) + if( st->Opt_AMR_WB ) { - amr_wb_dec_fx( pcmBuf, st ); + amr_wb_dec( st, output ); } - ELSE + else { - evs_dec_fx( st, pcmBuf, FRAMEMODE_NORMAL ); + evs_dec( st, output, FRAMEMODE_NORMAL ); } } - ELSE IF( sub(st->codec_mode, MODE2) == 0 ) + else if( st->codec_mode == MODE2 ) { - IF(st->bfi_fx == 0) + if(st->bfi == 0) { - evs_dec_fx(st, pcmBuf, FRAMEMODE_NORMAL); + evs_dec(st, output, FRAMEMODE_NORMAL); /* FRAMEMODE_NORMAL */ } - ELSE IF ( sub(st->bfi_fx,2) == 0 ) + else if ( st->bfi == 2 ) { - evs_dec_fx(st, pcmBuf, FRAMEMODE_FUTURE); /* FRAMEMODE_FUTURE */ + evs_dec(st, output, FRAMEMODE_FUTURE); /* FRAMEMODE_FUTURE */ } - ELSE /* conceal */ + else /* conceal */ { - evs_dec_fx(st, pcmBuf, FRAMEMODE_MISSING); + evs_dec(st, output, FRAMEMODE_MISSING); } } - END_SUB_WMOPS; - test(); - IF( sub(st->codec_mode, MODE1) == 0 || sub(st->codec_mode, MODE2) == 0 ) + /* convert 'float' output data to 'short' */ + if( st->codec_mode == MODE1 || st->codec_mode == MODE2 ) { + syn_output( output, hEvsRX->nSamplesFrame, pcmBuf ); + /* increase the counter of initialization frames */ - if( sub(st->ini_frame_fx, MAX_FRAME_COUNTER) < 0 ) + if( st->ini_frame < MAX_FRAME_COUNTER ) { - st->ini_frame_fx = add(st->ini_frame_fx, 1); + st->ini_frame++; } } - ELSE /* codec mode to use not known yet */ + else /* codec mode to use not known yet */ { - set16_fx( pcmBuf, 0, st->output_frame_fx ); + set_s( pcmBuf, 0, hEvsRX->nSamplesFrame ); } - IF(dataUnit != NULL) + if(dataUnit) { - IF(dataUnit->partial_frame != 0) + if(dataUnit->partial_frame != 0) { hEvsRX->lastDecodedWasActive = 1; - move16(); } - ELSE + else { - hEvsRX->lastDecodedWasActive = s_xor(dataUnit->silenceIndicator, 1); + hEvsRX->lastDecodedWasActive = !dataUnit->silenceIndicator; } /* data unit memory is no longer used */ JB4_FreeDataUnit(hEvsRX->hJBM, dataUnit); } /* limit scale to range supported by time scaler */ - if(sub(scale, APA_MIN_SCALE) < 0) + if( scale < APA_MIN_SCALE ) scale = APA_MIN_SCALE; - move16(); - if(sub(scale, APA_MAX_SCALE) > 0) + else if( scale > APA_MAX_SCALE ) scale = APA_MAX_SCALE; - move16(); /* apply time scaling on decoded/concealed samples */ - IF( apa_set_scale( hEvsRX->hTimeScaler, scale ) != 0 ) + if( apa_set_scale( hEvsRX->hTimeScaler, scale ) != 0 ) { return EVS_RX_TIMESCALER_ERROR; } - result = apa_exec( hEvsRX->hTimeScaler, pcmBuf, st->output_frame_fx, + result = apa_exec( hEvsRX->hTimeScaler, pcmBuf, hEvsRX->nSamplesFrame, maxScaling, pcmBuf, &nTimeScalerOutSamples ); - IF( result != 0 ) + if( result != 0 ) { return EVS_RX_TIMESCALER_ERROR; } @@ -414,8 +358,8 @@ EVS_RX_GetSamples(EVS_RX_HANDLE hEvsRX, assert(nTimeScalerOutSamples <= APA_BUF); (void)pcmBufSize; /* append scaled samples to FIFO */ - IF( pcmdsp_fifo_write( hEvsRX->hFifoAfterTimeScaler, - (UWord8*)pcmBuf, nTimeScalerOutSamples ) != 0 ) + if( pcmdsp_fifo_write( hEvsRX->hFifoAfterTimeScaler, + (uint8_t*)pcmBuf, nTimeScalerOutSamples ) != 0 ) { return EVS_RX_TIMESCALER_ERROR; } @@ -425,20 +369,20 @@ EVS_RX_GetSamples(EVS_RX_HANDLE hEvsRX, if( hEvsRX->jbmTraceFile ) { /* the first sample of the decoded/concealed frame will be played after the samples in the ring buffer */ - double playTime = systemTimestamp_ms + extBufferedSamples * 1000.0 / st->output_Fs_fx; + double playTime = systemTimestamp_ms + extBufferedSamples * 1000.0 / st->output_Fs; /* rtpSeqNo;rtpTs;rcvTime;playTime;active\n */ if( dataUnit ) { if(dataUnit->partial_frame == 1) { fprintf( hEvsRX->jbmTraceFile, "%d;%d;%d;%f;%d;%d\n", - -1, -1, -1, playTime, (int)hEvsRX->lastDecodedWasActive, dataUnit->partialCopyOffset ); + -1, -1, -1, playTime, hEvsRX->lastDecodedWasActive, dataUnit->partialCopyOffset ); } else { fprintf( hEvsRX->jbmTraceFile, "%u;%u;%u;%f;%d\n", dataUnit->sequenceNumber, dataUnit->timeStamp, dataUnit->rcvTime, - playTime, (int)hEvsRX->lastDecodedWasActive ); + playTime, hEvsRX->lastDecodedWasActive ); } } @@ -446,7 +390,7 @@ EVS_RX_GetSamples(EVS_RX_HANDLE hEvsRX, { fprintf( hEvsRX->jbmTraceFile, "%d;%d;%d;%f;%d\n", -1, -1, -1, - playTime, (int)hEvsRX->lastDecodedWasActive ); + playTime, hEvsRX->lastDecodedWasActive ); } } #endif @@ -454,39 +398,38 @@ EVS_RX_GetSamples(EVS_RX_HANDLE hEvsRX, /* fetch one frame for the sound card from FIFO */ *nOutSamples = soundCardFrameSize; - move16(); - IF( pcmdsp_fifo_read( hEvsRX->hFifoAfterTimeScaler, *nOutSamples, (UWord8*)pcmBuf ) != 0 ) + if( pcmdsp_fifo_read( hEvsRX->hFifoAfterTimeScaler, *nOutSamples, (uint8_t*)pcmBuf ) != 0 ) { return EVS_RX_TIMESCALER_ERROR; } return EVS_RX_NO_ERROR; } -Word16 -EVS_RX_Get_FEC_offset( EVS_RX_HANDLE hEvsRX, Word16 *offset, Word16 *FEC_hi) +EVS_RX_ERROR +EVS_RX_Get_FEC_offset( EVS_RX_HANDLE hEvsRX, short *offset + , short *FEC_hi + ) { - *offset = (Word16)JB4_getFECoffset(hEvsRX->hJBM); - move16(); - *FEC_hi = (Word16)JB4_FECoffset(hEvsRX->hJBM); - move16(); - return 0; + *offset = JB4_getFECoffset(hEvsRX->hJBM); + *FEC_hi = JB4_FECoffset(hEvsRX->hJBM); + return EVS_RX_NO_ERROR; + } + + /* Returns 1 if the jitter buffer is empty, otherwise 0. */ -Word8 +unsigned int EVS_RX_IsEmpty(EVS_RX_HANDLE hEvsRX ) { - Word8 isEmpty; + unsigned int isEmpty; isEmpty = 0; - move16(); - if(JB4_bufferedDataUnits(hEvsRX->hJBM) == 0 ) - { + if(JB4_bufferedDataUnits(hEvsRX->hJBM) == 0U) isEmpty = 1; - move16(); - } + return isEmpty; } @@ -495,29 +438,22 @@ EVS_RX_ERROR EVS_RX_Close(EVS_RX_HANDLE* phRX ) { /* Free all memory */ - test(); - IF( phRX == NULL || *phRX == NULL ) + if( phRX == NULL || *phRX == NULL ) { return EVS_RX_NO_ERROR; } destroy_decoder( (*phRX)->st ); - IF( (*phRX)->hJBM ) - { + if( (*phRX)->hJBM ) JB4_Destroy( &(*phRX)->hJBM ); - } - IF( (*phRX)->hTimeScaler ) - { + if( (*phRX)->hTimeScaler ) apa_exit( &(*phRX)->hTimeScaler ); - } - IF( (*phRX)->hFifoAfterTimeScaler ) - { + if( (*phRX)->hFifoAfterTimeScaler ) pcmdsp_fifo_destroy( &(*phRX)->hFifoAfterTimeScaler ); - } #ifdef SUPPORT_JBM_TRACEFILE if( (*phRX)->jbmTraceFile ) @@ -526,27 +462,22 @@ EVS_RX_Close(EVS_RX_HANDLE* phRX ) free( *phRX ); *phRX = NULL; - move16(); phRX = NULL; - move16(); + return EVS_RX_NO_ERROR; } /* function to check if a frame contains a SID */ -static Word16 isSidFrame( Word16 size ) +static int isSidFrame( unsigned int size ) { - Word16 ret; - - ret = 0; - move16(); - if(sub(size, SID_1k75 / 50) == 0) + int ret = 0; + if(size == SID_1k75 / 50) { - ret = 1; /* AMR-WB SID */ move16(); + ret = 1; /* AMR-WB SID */ } - if(sub(size, SID_2k40 / 50) == 0) + else if(size == SID_2k40 / 50) { - ret = 1; /* EVS SID */ move16(); + ret = 1; /* EVS SID */ } return ret; } - diff --git a/src/libs/libevs/lib_dec/EvsRXlib.h b/src/libs/libevs/lib_dec/EvsRXlib.h old mode 100755 new mode 100644 index fa35de99..6b5c8d40 --- a/src/libs/libevs/lib_dec/EvsRXlib.h +++ b/src/libs/libevs/lib_dec/EvsRXlib.h @@ -1,12 +1,12 @@ /*==================================================================================== - EVS Codec 3GPP TS26.442 Apr 03, 2018. Version 12.11.0 / 13.6.0 / 14.2.0 + EVS Codec 3GPP TS26.443 Nov 13, 2018. Version 12.11.0 / 13.7.0 / 14.3.0 / 15.1.0 ====================================================================================*/ #ifndef EvsRXLIB_H #define EvsRXLIB_H /* local headers */ -#include "stat_dec_fx.h" +#include "stat_dec.h" /* * ENUMS @@ -41,7 +41,7 @@ typedef struct EVS_RX* EVS_RX_HANDLE; /*! Opens the EVS Receiver instance. */ EVS_RX_ERROR EVS_RX_Open(EVS_RX_HANDLE* phEvsRX, - Decoder_State_fx *st, + Decoder_State *st, Word16 jbmSafetyMargin); /*! Sets the name of the JBM trace file which will be created. */ @@ -52,26 +52,30 @@ EVS_RX_SetJbmTraceFileName(EVS_RX_HANDLE hEvsRX, /*! Feeds one frame into the receiver. */ EVS_RX_ERROR EVS_RX_FeedFrame(EVS_RX_HANDLE hEvsRX, - UWord8 *au, - Word16 auSize, - Word16 rtpSequenceNumber, - Word32 rtpTimeStamp, - Word32 rcvTime_ms); + unsigned char *au, + unsigned int auSize, + unsigned short rtpSequenceNumber, + unsigned long rtpTimeStamp, + unsigned int rcvTime_ms); /*! Retrieves one frame of output PCM data. */ EVS_RX_ERROR EVS_RX_GetSamples(EVS_RX_HANDLE hEvsRX, - Word16 *nOutSamples, - Word16 *pcmBuf, - Word16 pcmBufSize, - Word32 systemTimestamp_ms) ; + unsigned int* nOutSamples, + Word16 *pcmBuf, + unsigned int pcmBufSize, + unsigned int systemTimestamp_ms + ); + +EVS_RX_ERROR +EVS_RX_Get_FEC_offset( EVS_RX_HANDLE hEvsRX, short* offset + , short *FEC_hi + ); -Word16 -EVS_RX_Get_FEC_offset( EVS_RX_HANDLE hEvsRX, Word16 *offset, Word16 *FEC_hi); /*! Returns 1 if the jitter buffer is empty, otherwise 0. */ /* Intended for flushing at the end of the main loop but not during normal operation! */ -Word8 +unsigned int EVS_RX_IsEmpty(EVS_RX_HANDLE hEvsRX ); /*! Closes the receiver instance. */ diff --git a/src/libs/libevs/lib_dec/FEC.cpp b/src/libs/libevs/lib_dec/FEC.cpp new file mode 100644 index 00000000..58d79991 --- /dev/null +++ b/src/libs/libevs/lib_dec/FEC.cpp @@ -0,0 +1,533 @@ +/*==================================================================================== + EVS Codec 3GPP TS26.443 Nov 13, 2018. Version 12.11.0 / 13.7.0 / 14.3.0 / 15.1.0 + ====================================================================================*/ + +#include +#include +#include "options.h" +#include "cnst.h" +#include "rom_com.h" +#include "rom_dec.h" +#include "prot.h" + +/*-------------------------------------------------------------------* + * Local functions + *-------------------------------------------------------------------*/ + +static void gain_dec_bfi( float *past_qua_en ); +static void pulseRes_preCalc( Word16* cond1, Word16* cond2, Word32* cond3 ,Word16 new_pit, Word16 Tc, Word16 L_frame ); + + +/*-------------------------------------------------------------------* + * FEC_exc_estim() + * + * Calculation of excitation signal + *-------------------------------------------------------------------*/ + +void FEC_exc_estim( + Decoder_State *st, /* i/o: Decoder static memory */ + const short L_frame, /* i : length of the frame */ + float *exc, /* o : pointer to excitation buffer (with past) */ + float *exc2, /* o : total excitation (for synthesis) */ + float *exc_dct_in, /* o : GSC excitation in DCT domain */ + float *pitch_buf, /* o : pitch buffer for each subframe */ + float *voice_factors, /* o : voicing factors */ + float *tmp_tc, /* o : FEC pitch */ + float *bwe_exc, /* o : excitation for SWB TBE */ + float *lsf_new, /* i : ISFs at the end of the frame */ + float *tmp_noise /* o : long-term noise energy */ +) +{ + short i, Tc, new_pit; + float exc2_buf[L_FRAME16k + MODE1_L_FIR_FER-1]; + float *pt_exc, *pt1_exc, alpha, step, gain_inov, gain, gainCNG, hp_filt[5]; + float fT0, delta, ftmp; + short Diff_len; + short Len, max_len; + short last_bin; + short extrapolationFailed = 1; + float predPitchLag; + Word16 cond1, cond2; + Word32 cond3; + + /*-----------------------------------------------------------------* + * Initializations + *-----------------------------------------------------------------*/ + + gainCNG = (float)sqrt( st->lp_ener ); + + ftmp = 2.0f * st->lp_gainc; + if ( gainCNG > ftmp ) + { + gainCNG = ftmp; + } + + Diff_len = 0; + set_f( exc_dct_in, 0.0f, L_FRAME16k ); + + /*-----------------------------------------------------------------* + * Pitch extrapolation + *-----------------------------------------------------------------*/ + + /* pitch extrapolation */ + pitch_pred_linear_fit( st->nbLostCmpt, st->last_good, st->old_pitch_buf, + L_frame == L_FRAME ? &st->old_pitch_buf[2*NB_SUBFR-1] : &st->old_pitch_buf[2*NB_SUBFR16k-1], + &predPitchLag, L_frame == L_FRAME?PIT_MIN_DOUBLEEXTEND:PIT16k_MIN_EXTEND, + L_frame == L_FRAME?PIT_MAX:PIT16k_MAX, st->mem_pitch_gain, 0, 0, &extrapolationFailed, L_frame/L_SUBFR ); + + new_pit = (int)(predPitchLag+0.5f); + + /* initialize FEC pitch to the long-term pitch */ + *tmp_tc = st->bfi_pitch; + if( L_frame == L_FRAME ) + { + if( ( ( st->old_pitch_buf[2*NB_SUBFR-1] < 1.8f * st->bfi_pitch ) && + ( st->old_pitch_buf[2*NB_SUBFR-1] > 0.6f * st->bfi_pitch ) ) || /* last pitch coherent with the past */ + ( st->upd_cnt >= MAX_UPD_CNT ) ) /* or last update too far in the past */ + { + /* take the pitch value of last subframe of the previous frame */ + *tmp_tc = st->old_pitch_buf[2*NB_SUBFR-1]; + } + } + else /* L_frame == L_FRAME16k */ + { + if( ( ( st->old_pitch_buf[2*NB_SUBFR16k-1] < 1.8f * st->bfi_pitch ) && + ( st->old_pitch_buf[2*NB_SUBFR16k-1] > 0.6f * st->bfi_pitch ) ) || /* last pitch coherent with the past */ + ( st->upd_cnt >= MAX_UPD_CNT ) ) /* or last update too far in the past */ + { + /* take the pitch value of last subframe of the previous frame */ + *tmp_tc = st->old_pitch_buf[2*NB_SUBFR16k-1]; + } + } + /* convert pitch period */ + Tc = (short)(*tmp_tc + 0.5f); + + pulseRes_preCalc( &cond1, &cond2, &cond3 , (Word16)new_pit, (Word16)Tc, (Word16)L_frame ); + + if( (cond1 < 0 ) && (new_pit > 0) && (cond2 != 0) && (cond3 > 0) && extrapolationFailed == 0 ) + { + fT0 = *tmp_tc; + delta = (float)(new_pit - fT0)/(L_frame/L_SUBFR); /* # of subframes */ + for ( i=0; ilast_coder_type == UNVOICED && st->nbLostCmpt <= 3 ) + { + /* last good frame was clearly unvoiced */ + alpha = ALPHA_UU; + } + else if( st->last_coder_type == AUDIO || st->last_good == INACTIVE_CLAS ) + { + if( st->Last_GSC_pit_band_idx > 0 && st->nbLostCmpt > 1 ) + { + alpha = 0.8f; + } + else if( st->nbLostCmpt <= 5 ) + { + alpha = 0.995f; + } + else + { + alpha = 0.95f; + } + } + else if(st->last_good == UNVOICED_CLAS ) + { + if( st->nbLostCmpt <= 1 ) + { + /* If stable, do not decrease the energy, pitch gain = 0 */ + alpha = st->stab_fac * (1.0f - 2.0f*ALPHA_U) + 2.0f*ALPHA_U; /* [0.8, 1.0] */ + } + else if ( st->nbLostCmpt == 2 ) + { + alpha = ALPHA_U * 1.5f; /* 0.6 */ + } + else + { + alpha = ALPHA_U; /* 0.4 go rapidly to CNG gain, pitch gain = 0 */ + } + } + else if(st->last_good == UNVOICED_TRANSITION ) + { + alpha = ALPHA_UT; + } + else if(st->last_good == ONSET && st->nbLostCmpt <= 3 && (st->last_coder_type == GENERIC || st->last_coder_type == TRANSITION) ) + { + alpha = 0.8f; /* mild convergence to 0 for the first 3 erased frames */ + } + else if( (st->last_good == VOICED_CLAS || st->last_good == ONSET ) && st->nbLostCmpt <= 3 ) + { + alpha = ALPHA_V; /* constant for the first 3 erased frames */ + } + else if(st->last_good == SIN_ONSET ) + { + alpha = ALPHA_S; + } + + if(st->last_good >= VOICED_CLAS && st->last_good < INACTIVE_CLAS && st->last_coder_type != AUDIO ) + { + if( st->nbLostCmpt == 1 ) + { + /* if this is the first erased frame, move pitch gain towards 1 for voiced to remove energy fluctuations */ + gain = (float)sqrt(st->lp_gainp); + if( gain > 0.98f ) + { + gain = 0.98f; + } + else if( gain < 0.85f ) + { + gain = 0.85f; + } + + alpha *= gain; + } + else + { + alpha = st->lp_gainp; + } + } + + /*-----------------------------------------------------------------* + * Extrapolate past excitation signal using estimated pitch period + *-----------------------------------------------------------------*/ + + if( (st->last_good >= UNVOICED_TRANSITION && st->last_good < INACTIVE_CLAS) || + ( (st->last_coder_type == AUDIO || st->last_good == INACTIVE_CLAS) && st->Last_GSC_pit_band_idx > 0) ) + { + /* Do pitch-based extrapolation only for stable voiced and audio signals */ + + pt_exc = exc; + pt1_exc = pt_exc - Tc; + + if ( st->nbLostCmpt == 1 ) + { + /* first pitch cycle is low-pass filtered */ + for( i=0 ; i< Tc; i++ ) + { + *pt_exc++ = ( 0.18f * pt1_exc[-1] + 0.64f * pt1_exc[0] + 0.18f * pt1_exc[1] ); + pt1_exc++; + } + } + + /* last pitch cycle of the previous frame is repeatedly copied up to an extra subframe */ + while( pt_exc < exc + L_frame + L_SUBFR ) + { + *pt_exc++ = *pt1_exc++; + } + + /* resynchronization of excitation based on glottal pulse locations in the last good frame */ + if ( new_pit > 0 ) + { + if ((cond1 < 0 ) && (new_pit > 0) && (cond2 != 0) && (cond3 > 0) && extrapolationFailed == 0 ) + { + mvr2r( exc, exc-L_frame-L_SUBFR, L_frame+L_SUBFR ); + PulseResynchronization( exc-L_frame-L_SUBFR, exc, L_frame, L_frame/L_SUBFR, Tc, new_pit ); + } + } + + if(st->last_good == UNVOICED_TRANSITION && ( st->last_coder_type == GENERIC || st->last_coder_type == TRANSITION ) ) + { + /* start of the frame gain */ + gain = 0.0f; + + /* end of the frame gain */ + st->lp_gainp = 0.0f; + + step = 0.0f; + } + else + { + /* start of the frame gain */ + gain = 1.0f; + + /* end of the frame gain */ + st->lp_gainp = alpha; + + /* linearly attenuate the gain throughout the frame */ + step = (1.0f/L_frame) * (gain - st->lp_gainp); + } + + /* scaling of the harmonic part of excitation */ + for( i=0 ; i< L_frame; i++ ) + { + exc[i] *= gain; + gain -= step; + } + + if( (st->last_coder_type == AUDIO || st->last_good == INACTIVE_CLAS) && st->Last_GSC_pit_band_idx > 0 ) + { + /* in case the last frame was coded by GSC, convert the excitation signal to frequency domain */ + edct( exc, exc_dct_in, st->L_frame); + + /* Reset unvaluable part of the adaptive (pitch) excitation contribution */ + Diff_len = (short)(mfreq_loc[st->Last_GSC_pit_band_idx]/BIN_SIZE); + max_len = st->L_frame - Diff_len; + Len = min( max_len, 80 ); + + for( i=0; ilast_coder_type == AUDIO || st->last_good == INACTIVE_CLAS) && st->total_brate <= ACELP_24k40 && !st->Opt_AMR_WB ) + { + /* Replication of the last spectrum, with a slight downscaling of its dynamic */ + st->GSC_noisy_speech = st->Last_GSC_noisy_speech_flag; + gsc_dec( st, exc_dct_in, st->Last_GSC_pit_band_idx, Diff_len, 0, st->L_frame/L_SUBFR, st->last_coder_type, &last_bin, lsf_new, NULL, tmp_noise ); + + /* Transform back to time domain */ + edct( exc_dct_in, exc, st->L_frame); + } + + /*-----------------------------------------------------------------* + * Construct the random part of excitation + *-----------------------------------------------------------------*/ + + else + { + /* generate the random part of the excitation */ + for (i=0; iseed ); + } + + /* start of the frame gain */ + gain = st->lp_gainc; + + /* end of the frame gain */ + st->lp_gainc = alpha * st->lp_gainc + (1.0f - alpha) * gainCNG; + + if( st->last_good == UNVOICED_TRANSITION && ( st->last_coder_type == GENERIC || st->last_coder_type == TRANSITION ) && gainCNG > 0 ) + { + st->lp_gainc = gainCNG; + } + + /* linearly attenuate the gain throughout the frame */ + step = (1.0f/L_frame) * (gain - st->lp_gainc); + + /* calculate gain to normalize energy */ + pt_exc = exc2_buf + MODE1_L_FIR_FER/2; + + gain_inov = 1.0f / (float)sqrt( dotp( pt_exc, pt_exc, L_frame ) / L_frame + 0.01f ); + + /* attenuate somewhat on unstable unvoiced */ + if( (st->last_good == UNVOICED_CLAS || st->last_good == INACTIVE_CLAS) && st->last_coder_type != UNVOICED ) + { + gain_inov *= 0.8f; + } + + /* scaling of the random part of excitation */ + pt_exc = exc2_buf; + for( i=0; i< MODE1_L_FIR_FER/2; i++ ) + { + /* non-causal ringing of the FIR filter */ + *pt_exc++ *= (gain_inov * gain); + } + + for( i=0; i< L_frame; i++ ) + { + /* the inner part of the FIR filter */ + *pt_exc++ *= (gain_inov * gain); + gain -= step; + } + + for( i=0; i< MODE1_L_FIR_FER/2; i++ ) + { + /* causal ringing of the FIR filter */ + *pt_exc++ *= (gain_inov * gain); + } + } + + /*-----------------------------------------------------------------* + * Total excitation + *-----------------------------------------------------------------*/ + + if( (st->last_coder_type == AUDIO || st->last_good == INACTIVE_CLAS) && st->total_brate <= ACELP_24k40 && !st->Opt_AMR_WB ) + { + /* For GSC - the excitation is already computed */ + mvr2r( exc, exc2, st->L_frame); + } + else if(st->last_good >= UNVOICED_TRANSITION && st->last_good < INACTIVE_CLAS ) + { + /* For voiced and generic signals - prepare a HP filter for the random part of excitation */ + for( i=0; itilt_code) * h_high[i]; + } + + /* HP filter the random part of the excitation and add the adaptive part */ + for( i=0; i< L_frame; i++ ) + { + exc2[i] = exc[i] + dotp( &exc2_buf[i], hp_filt, MODE1_L_FIR_FER ); + } + } + else + { + /* For purely unvoiced signals - just copy the unfiltered random part of the excitation */ + mvr2r( exc2_buf + MODE1_L_FIR_FER/2, exc, L_frame ); + mvr2r( exc2_buf + MODE1_L_FIR_FER/2, exc2, L_frame ); + } + + if( L_frame == L_FRAME ) + { + interp_code_5over2( exc, bwe_exc, L_frame ); + } + else + { + interp_code_4over2( exc, bwe_exc, L_frame ); + } + + /*-----------------------------------------------------------------* + * Updates + *-----------------------------------------------------------------*/ + + /* Update voicing factors of TBE */ + if( st->last_coder_type == AUDIO || st->last_good == INACTIVE_CLAS ) + { + if(st->L_frame == L_FRAME ) + { + set_f( voice_factors, 1.0f, NB_SUBFR ); + } + else + { + set_f( voice_factors, 1.0f, NB_SUBFR16k ); + } + } + else + { + if(st->L_frame == L_FRAME ) + { + set_f( voice_factors, st->last_voice_factor, NB_SUBFR); + } + else + { + set_f( voice_factors, st->last_voice_factor, NB_SUBFR16k ); + } + } + + if( st->Opt_AMR_WB ) + { + /* update buffer of gains for the next frame */ + gain_dec_bfi(st->past_qua_en); + } + + st->bfi_pitch = pitch_buf[L_frame/L_SUBFR - 1]; + st->bfi_pitch_frame = st->L_frame; + + return; +} + + +/*-------------------------------------------------------------------* + * gain_dec_bfi() + * + * Estimate past quantized gain prediction residual to be used in + * next frame + *-------------------------------------------------------------------*/ + +static void gain_dec_bfi( + float *past_qua_en /* i/o: gain quantization memory (4 words) */ +) +{ + short i; + float av_pred_en; + + av_pred_en = 0.0f; + for (i = 0; i < GAIN_PRED_ORDER; i++) + { + av_pred_en += past_qua_en[i]; + } + + av_pred_en = (float)(av_pred_en*(1.0f/(float)GAIN_PRED_ORDER)-3.0f); + + if (av_pred_en < -14.0f) + { + av_pred_en = -14.0f; + } + + for (i=GAIN_PRED_ORDER-1; i>0; i--) + { + past_qua_en[i] = past_qua_en[i-1]; + } + + past_qua_en[0] = av_pred_en; + + return; +} + + +/*-------------------------------------------------------------------* + * pulseRes_preCalc() + * + * calculates some conditions for Pulse resynchronization to take place + *-------------------------------------------------------------------*/ + +static void pulseRes_preCalc( + Word16* cond1, + Word16* cond2, + Word32* cond3, + Word16 new_pit, + Word16 Tc, + Word16 L_frame +) +{ + Word16 tmp_pit, tmp_pit_e, tmp_frame, tmp_frame_e; + Word32 tmp_pit2; + + tmp_pit = BASOP_Util_Divide1616_Scale(new_pit/*Q0*/,Tc/*Q0*/,&tmp_pit_e)/*Q15*/; + tmp_frame = add( extract_l(L_mult0(L_frame , 64/*1.f/L_SUBFR Q12*/)/*Q12*/) , 4096/*1.f Q12*/ );/*Q12*/ + tmp_frame = BASOP_Util_Divide1616_Scale(4096/*1.f Q12*/,tmp_frame, &tmp_frame_e);/*Q15*/ + tmp_frame = shl(tmp_frame,add(tmp_frame_e,1)); + tmp_frame = sub(32767/*1.f Q15*/, tmp_frame);/*Q15*/ + + BASOP_SATURATE_WARNING_OFF + /*To calc Q15 threshold, overflow may happen - do negation and compare with negated value to check also highest possible value*/ + tmp_pit = shl(negate(tmp_pit),tmp_pit_e); + BASOP_SATURATE_WARNING_ON + + *cond1 = sub(tmp_pit, negate(tmp_frame)); + + *cond2 = sub(Tc, new_pit); + + tmp_pit_e = BASOP_Util_Add_MantExp(new_pit,15-0,negate(Tc),15-0,&tmp_pit);/*Q15*/ + tmp_pit = abs_s(tmp_pit); + tmp_pit2 = L_mult(Tc,4915/*0.15f Q15*/);/*Q16*/ + + BASOP_SATURATE_WARNING_OFF + /*To calc Q15 threshold, overflow may happen - do negation and compare with negated value to check also highest possible value*/ + tmp_pit2 = L_shl(L_negate(tmp_pit2),sub(15-16,tmp_pit_e)); + BASOP_SATURATE_WARNING_ON + + *cond3 = L_sub(L_mult0(-1, tmp_pit),tmp_pit2); + + return; +} diff --git a/src/libs/libevs/lib_dec/FEC_HQ_core.cpp b/src/libs/libevs/lib_dec/FEC_HQ_core.cpp new file mode 100644 index 00000000..bc200892 --- /dev/null +++ b/src/libs/libevs/lib_dec/FEC_HQ_core.cpp @@ -0,0 +1,1444 @@ +/*==================================================================================== + EVS Codec 3GPP TS26.443 Nov 13, 2018. Version 12.11.0 / 13.7.0 / 14.3.0 / 15.1.0 + ====================================================================================*/ + +#include +#include +#include "options.h" +#include "cnst.h" +#include "rom_dec.h" +#include "rom_com.h" +#include "prot.h" + +/*---------------------------------------------------------------------* + * Local prototypes + *---------------------------------------------------------------------*/ + +static short FEC_phase_matching( Decoder_State *st, float *ImdctOut, float *auOut, float *OldauOut, float OldauOut_pha[2][N_LEAD_NB] ); + +static void FEC_phase_matching_nextgood( const float *ImdctOut, float *auOut, float *OldauOut, + float OldauOut_pha[2][N_LEAD_NB], float mean_en_high ); + +static void FEC_phase_matching_burst( const float *ImdctOut, float *auOut, float *OldauOut, + float OldauOut_pha[2][N_LEAD_NB], float *prev_oldauOut ); + +static void Repetition_smoothing_nextgood( const float *ImdctOut, float *auOut, float *OldImdctOut, float *OldauOut, + short cur_data_use_flag, short overlap_time ); + +static int Repetition_smoothing( const float *ImdctOut, float *auOut, float *OldImdctOut, float *OldauOut, + const short L, float *prev_oldauOut, short overlap_time ); + +static void Windowing_1st_NB( float *ImdctOutWin, const float *ImdctOut, const float *win, const float *smoothingWin, short smoothing_flag ); + +static void Windowing_2nd_NB( float *ImdctOutWin, const float *ImdctOut, const float *win ); + +static void common_overlapping( float *auOut, float *ImdctOutWin, float *OldauOut, short end1, short offset1, + short start2, short end2, short offset_i2, short offset2 ); + +static void Smoothing_vector_NB( const float OldauOutnoWin[], const float ImdctOutWin[], const float SmoothingWin[], + float auOut[], const short ol_size ); + +static void Smoothing_vector_scaledown_NB( const float OldauOutnoWin[], const float ImdctOutWin[], const float SmoothingWin[], + float auOut[], const short ol_size ); + +static void Scaledown( float x[], float y[], float scale_v, const short N ); + + +/*--------------------------------------------------------------------------* + * Regression_Anal() + * + * + *--------------------------------------------------------------------------*/ + +static void Regression_Anal( + const float *values, /* i : Previous values */ + float *r_p, /* o : Output r[a b] array : y=ax+b */ + const short num_pgf /* i : Number of previous good frame */ +) +{ + short i; + float aindex[MAX_PGF+1], b_p[MAX_PGF+1]; + + /* Initialize */ + for(i=0; ienergy_MA_Curr[0] < 1.0f) + { + st->energy_MA_Curr[0] = 1.0f; /*It seems to be in Q0 the FxP*/ + } + /* Decide the start frame number for adaptive muting */ + /* Normalized energy difference between the current frame and the moving average */ + energy_diff = (float)fabs((st->energy_MA_Curr[1] - st->energy_MA_Curr[0])/st->energy_MA_Curr[0]); + + if((energy_diffprev_old_bfi == 1 && st->nbLostCmpt == 1 && output_frame == L_FRAME8k ) + { + st->nbLostCmpt++; + } + + /* Frequency-domain FEC */ + if( st->nbLostCmpt == 1 ) /* First erasure frame */ + { + if ( is_transient == 0 ) + { + if(energy_diff < ED_THRES) + { + for (i=0; i < output_frame; i++) + { + t_audio_q[i] = st->old_coeffs[i]; + } + } + else + { + for (i=0; i < output_frame; i++) + { + st->old_coeffs[i] *= SCALE_DOWN_3dB; + t_audio_q[i] = st->old_coeffs[i]; + } + } + + /* Sign prediction in 4-dim bands up to 1.6 kHz*/ + if (st->old_is_transient[1] == 0) + { + if (st->old_is_transient[2] == 0) + { + for (sfm = 0; sfm < HQ_FEC_SIGN_SFM; sfm++) + { + if (st->prev_sign_switch[sfm] >= HQ_FEC_SIGN_THRES) + { + for(i = 0; i < HQ_FEC_BAND_SIZE; i++) + { + t_audio_q[i+sfm*HQ_FEC_BAND_SIZE]*= -1.0f; + } + } + } + } + else + { + for (sfm = 0; sfm < HQ_FEC_SIGN_SFM; sfm++) + { + if (st->prev_sign_switch[sfm] >= HQ_FEC_SIGN_THRES_TRANS) + { + for(i = 0; i < HQ_FEC_BAND_SIZE; i++) + { + t_audio_q[i+sfm*HQ_FEC_BAND_SIZE]*= -1.0f; + } + } + } + } + } + else + { + for (i = RANDOM_START*8; i < output_frame; i++) + { + if( (float)own_random( &st->HQ_FEC_seed ) < 0.0f ) + { + t_audio_q[i] *= -1.0f; + } + } + } + } + else + { + if( st->old_is_transient[1] ) /* hangover */ + { + for (i=0; i < output_frame; i++) + { + st->old_coeffs[i] *= SCALE_DOWN_3dB; + t_audio_q[i] = st->old_coeffs[i]; + } + } + else + { + for (i = 0; i < RANDOM_START*8; i++) + { + st->old_coeffs[i] *= SCALE_DOWN_3dB; + t_audio_q[i] = st->old_coeffs[i]; + } + + for (i = RANDOM_START*8; i < output_frame; i++) + { + st->old_coeffs[i] *= SCALE_DOWN_3dB; + if( (float)own_random( &st->HQ_FEC_seed ) < 0.0f ) + { + t_audio_q[i] = (-st->old_coeffs[i]); + } + else + { + t_audio_q[i] = st->old_coeffs[i]; + } + } + } + } + } + else /* st->nbLostCmpt > 1 */ + { + if( energy_diff < ED_THRES && is_transient == 0 ) + { + num_pgf = 4; + } + else + { + num_pgf = 2; + } + + Num_sb_bwe = num_Sb; + if( st->nbLostCmpt == 2 ) + { + for( i=0; inbLostCmpt >= mute_start ) + { + /* Scaling */ + for ( i=0; i < output_frame; i++ ) + { + st->old_coeffs[i] *= SCALE_DOWN_3dB; + } + } + + k=0; + for( i=0; i MAX_TILT ) + { + r_p[1] = MAX_TILT; + norm_p[i] = (float)(norm_values[0]+r_p[1]*(float)(st->nbLostCmpt-1)); + } + else + { + norm_p[i] = (float)(r_p[0]+r_p[1]*(float)(st->nbLostCmpt-1+num_pgf)); + } + + if( norm_values[0] != 0.0f && norm_p[i] > 0.0f ) /* Avoid negative value of the predicted energy */ + { + tmp = norm_p[i]/norm_values[0]; /* Pred_new / Old */ + + if( tmp > 1.0f ) + { + tmp = 1.f; + } + + for( j=0; jNorm_gain[k++] = tmp; + } + } + else + { + /* Scale down the last gain with the fixed gain(-3dB) */ + for(j=0; jNorm_gain[k++] *= SCALE_DOWN_3dB; + } + } + } + + /* Scaling for core band */ + FEC_scaling( st->old_coeffs, t_audio_q, st->Norm_gain, &st->HQ_FEC_seed, nb_sfm, sfm_start, sfm_end ); + } + + return; +} + + +/*--------------------------------------------------------------------------* + * HQ_FEC_Mem_update() + * + * + *--------------------------------------------------------------------------*/ + +void HQ_FEC_Mem_update( + Decoder_State *st, /* i/o: decoder state structure */ + float *t_audio_q, + float *normq, + short *ynrm, + short *Num_bands_p, + short is_transient, + short hqswb_clas, + short c_switching_flag, + short nb_sfm, + short num_Sb, + float *mean_en_high, + short hq_core_type, /* i : normal or low-rate MDCT(HQ) core */ + short output_frame +) +{ + short i, j, k; + float tmp; + float tmp_energy = 0; + float *norm_values; + short offset; + short Min_ind; + int Min_value; + float Max_coeff; + short Max_ind; + short stat_mode_curr; + float en_high[MAX_SB_NB]; + + if (is_transient) + { + set_s(st->prev_sign_switch_2, 0, HQ_FEC_SIGN_SFM); + set_s(st->prev_sign_switch, 0, HQ_FEC_SIGN_SFM); + } + else + { + for (j = 0; j < HQ_FEC_SIGN_SFM; j++) + { + st->prev_sign_switch[j] = st->prev_sign_switch_2[j]; + st->prev_sign_switch_2[j] = 0; + + for(i = 0; i < HQ_FEC_BAND_SIZE; i++) + { + tmp = st->old_coeffs[i+j*HQ_FEC_BAND_SIZE]*t_audio_q[i+j*HQ_FEC_BAND_SIZE]; + if (tmp < 0) + { + st->prev_sign_switch[j]++; + st->prev_sign_switch_2[j]++; + } + } + } + } + + if( output_frame == L_FRAME8k ) + { + /* if LR MDCT core is used, recalculate norms from decoded MDCT spectrum (using code from hq_hr_enc()) */ + if( ( hqswb_clas == HQ_HVQ ) || ( hq_core_type == LOW_RATE_HQ_CORE ) ) + { + /* First group */ + logqnorm( t_audio_q, ynrm, 32, WID_G1, thren_HQ ); + j = ynrm[0]; + offset = WID_G1; + + for( i=1; iynrm_values[i][0]; + mvr2r( norm_values, &norm_values[1], MAX_PGF-1 ); + + tmp = 0.f; + for(j=0; jlast_core == ACELP_CORE)&&(st->core == HQ_CORE))) + { + for(i=0; iynrm_values[i][j]=st->ynrm_values[i][0]; + } + } + } + set_f(st->Norm_gain, 1.f, SFM_N_NB); + + /* st->energy_MA_Curr[1]=Energy of the current frame */ + st->energy_MA_Curr[1] = tmp_energy/(float)nb_sfm; + + /* Moving Average */ + st->energy_MA_Curr[0] = 0.8f*st->energy_MA_Curr[0]+0.2f*st->energy_MA_Curr[1]; + + st->diff_energy = (float)fabs((st->energy_MA_Curr[1] - st->energy_MA_Curr[0])/st->energy_MA_Curr[0]); + /* Classify the stationary mode : 12% */ + if((st->diff_energystat_mode_old == stat_mode_curr) + { + st->stat_mode_out = stat_mode_curr; + } + + st->stat_mode_old = stat_mode_curr; + + + /* Find max. band index (Minimum value means maximum energy) */ + Min_ind=0; + Min_value = 100; + for( i=0; iynrm[i] ) + { + Min_value = ynrm[i]; + Min_ind = i; + } + } + + /* Find max. coeff in band 0 */ + Max_ind = 0; + if(Min_ind==0) + { + Max_coeff = 0.f; + for(i=0; i<8; i++) + { + tmp = (float)fabs(t_audio_q[i]); + if(Max_coeffynrm_values[i][j+1]; + } + } + + *mean_en_high = 0.f; + for(i=k; iynrm_values[i][0]); + } + *mean_en_high /= (float)(num_Sb-k); + + if ((Min_ind<5) && ( abs(Min_ind - st->old_Min_ind)< 2) &&(st->diff_energybfi) && (!st->prev_bfi)&&(!st->prev_old_bfi) + &&(!is_transient)&&(!st->old_is_transient[1]) && (st->prev_last_core==HQ_CORE) && (st->last_core==HQ_CORE)) + { + if((Min_ind==0)&&(Max_ind<3)) + { + st->phase_mat_flag = 0; + } + else + { + st->phase_mat_flag = 1; + } + } + else + { + st->phase_mat_flag = 0; + } + + st->old_Min_ind = Min_ind; + } + + for (i=0; i < L_FRAME8k; i++) + { + st->old_coeffs[i] = t_audio_q[i]; + } + + st->old_is_transient[2] = st->old_is_transient[1]; + st->old_is_transient[1] = st->old_is_transient[0]; + st->old_is_transient[0] = is_transient; + + return; +} + +/*--------------------------------------------------------------------------* + * find_best_delay() + * + * + *--------------------------------------------------------------------------*/ + +static short find_best_delay( + float *mu_o, + float *in, + short mind1, + short maxd1, + short lin, + short delta, + short *false_flag + +) +{ + short i, d1, k; + short d1m = 0; + float min_sq_cross, min_corr; + float accA, accB; + float Rxy[MAXDELAY_FEC], Ryy[MAXDELAY_FEC]; + + for( k = 0, d1 = mind1; k < (maxd1-mind1)/delta; d1 += delta, k++ ) + { + accA = accB = 0; + for( i = 0; i < lin; i += delta ) + { + accA += mu_o[d1+i] * mu_o[d1+i]; + accB += mu_o[d1+i] * in[i]; + } + + Rxy[k] = accB; + Ryy[k] = accA; + } + + /* Obtain the best delay values */ + min_sq_cross = -FLT_MAX; + min_corr = 0; + + for( d1 = 0; d1 < (maxd1-mind1)/delta; d1++ ) + { + if( Rxy[d1] * min_corr >= min_sq_cross * Ryy[d1] ) + { + d1m = d1; + min_corr = Ryy[d1]; + min_sq_cross = Rxy[d1]; + } + } + d1m *= delta; + + + accA = min_sq_cross/min_corr; + if(accA < 0.5 || accA > 1.5) + { + *false_flag = 1; + } + else + { + *false_flag = 0; + } + + return d1m; +} + +/*--------------------------------------------------------------------------* + * Search_Max_Corr() + * + * + *--------------------------------------------------------------------------*/ + +static short Search_Max_Corr( + float *mu_o, /* i : *old_auOut_2fr */ + short old_Min_ind, /* i : * Old Minimum index */ + const short L /* i : L/2 */ +) +{ + short pos; + short pos2,delta2; + short lin, delta; + short mind1,maxd1; + float *in; + short false_flag; + + short min_d1, max_d1; + + if(old_Min_ind == 0) + { + lin = 8*L/20; /* Basic size of the block for phase matching */ + + mind1 = 0; /* min value of delay d1 to search for */ + maxd1 = 12*L/20; /* max value of delay d1 to search for */ + + in = mu_o + 2*L - lin; + + /* generate correlation */ + delta = 2; + delta2 = 1; + + pos = find_best_delay(mu_o, in, mind1, maxd1, lin, delta, &false_flag); + + if(false_flag) + { + return 0; + } + min_d1 = max(mind1,mind1+pos-delta+1); + max_d1 = min(maxd1,mind1+pos+delta); + pos2 = find_best_delay(mu_o, in, min_d1, max_d1, lin, delta2, &false_flag); + + if(mind1 > (mind1+pos-delta+1)) + { + pos = pos2; + } + else + { + pos = pos + pos2 - delta + 1 ; + } + pos = pos+lin+mind1; + } + else + { + lin = 6*L/20; + + mind1 = 9*L/20; /* min value of delay d1 to search for */ + maxd1 = 14*L/20; /* max value of delay d1 to search for */ + + in = mu_o + 2*L - lin; + + /* generate correlation */ + delta = 2; + delta2 = 1; + + pos = find_best_delay(mu_o, in, mind1, maxd1, lin, delta, &false_flag); + + if(false_flag) + { + return 0; + } + + min_d1 = max(mind1, mind1+pos-delta+1); + max_d1 = min(maxd1, mind1+pos+delta); + pos2 = find_best_delay(mu_o, in, min_d1, max_d1, lin, delta2, &false_flag); + + if(mind1 > (mind1+pos-delta+1) ) + { + pos = pos2; + } + else + { + pos = pos + pos2 - delta + 1 ; + } + + pos = pos+lin+mind1; + } + + return pos; +} + +/*--------------------------------------------------------------------------* + * FEC_phase_matching() + * + * + *--------------------------------------------------------------------------*/ + +static short FEC_phase_matching( + Decoder_State *st, /* i : Decoder State */ + float *ImdctOut, /* i : input */ + float *auOut, /* o : output audio */ + float *OldauOut, + float OldauOut_pha[2][N_LEAD_NB] +) +{ + short i; + float ImdctOutWin[2*L_FRAME8k]; + short pos, remain; + short ol_size; + float OldauOutnoWin[L_FRAME8k]; + short L_overlap, L; + float OldauOut2[L_FRAME8k]; + float pow1=0, pow22=0; + float win_NB[L_FRAME8k + 25]; + float SmoothingWin_NB3[24]; + + L = L_FRAME8k; + + for(i=0; i<3*L/20; i++) + { + SmoothingWin_NB3[i] = SmoothingWin_NB875[i*3]; + } + + for(i=0; iold_auOut_2fr, st->old_Min_ind, L); + + if(pos == 0) + { + return 1; + } + + /* Repetition */ + remain = L+N_Z_L_NB - ((2*L)-pos); + mvr2r(&st->old_auOut_2fr[pos], &ImdctOutWin[N_ZERO_NB], (2*L)-pos); + + /* OldauOut without windowing */ + for(i = N_ZERO_NB; i < L/2; i++) + { + OldauOutnoWin[i-N_ZERO_NB] = -st->oldIMDCTout[L/2 - 1 - i]; + } + for(i = 0; i < L/2; i++) + { + OldauOutnoWin[i+N_ZERO_O_NB] = -st->oldIMDCTout[i]; + } + + mvr2r(OldauOutnoWin, &ImdctOutWin[N_ZERO_NB+(2*L)-pos], remain); + + for(i = 0; i < L; i++) + { + pow1 += (float)fabs(st->old_auOut_2fr[L+i]); + pow22 += (float)fabs(ImdctOutWin[N_ZERO_NB+i]); + } + + if(pow22!=0) + { + pow1 /= pow22; + for(i = N_ZERO_NB; i < 2*L; i++) + { + ImdctOutWin[i] *= pow1; + } + } + Smoothing_vector_NB(OldauOutnoWin, &ImdctOutWin[N_ZERO_NB], SmoothingWin_NB2, auOut, ol_size); + + for (i = 0; i < L/2; i++) + { + ImdctOutWin[3*L/2 + i] *= win_NB[L/2-i-1]; + } + + for (i = N_ZERO_NB; i < L/2; i++) + { + ImdctOutWin[L + i] *= win_NB[(L-1-i)]; + } + mvr2r(&ImdctOutWin[N_Z_L_O_NB], &OldauOut_pha[0][0], N_LEAD_NB); + mvr2r(&ImdctOutWin[ol_size+N_ZERO_NB], &auOut[ol_size], N_Z_L_NB-ol_size); + mvr2r(&ImdctOutWin[L], &auOut[N_Z_L_NB], N_ZERO_NB); + mvr2r(&ImdctOutWin[L], OldauOut, L); + + for(i = 0; i < L/2; i++) + { + OldauOut2[i] = -ImdctOut[L/2 - 1 - i]; + OldauOut2[L/2+i] = -ImdctOut[i]; + } + + L_overlap = 3*L/20; + Smoothing_vector_NB(&ImdctOutWin[N_Z_L_O_NB], &OldauOut2[N_ZERO_NB], SmoothingWin_NB3, &OldauOut_pha[1][0], L_overlap); + + for(i=L_overlap; i2.f)||(mean_en_high<0.5f)) + { + oldout_pha_idx = 1; + } + else + { + oldout_pha_idx = 0; + } + + /* Overlapping with next good frame : Overlapping to remove the discontinuity */ + L_overlap = N_LEAD_NB; + OldOut_pha = OldauOut_pha[oldout_pha_idx]; + for (i = 0; i < N_LEAD_NB; i++) + { + OldOut_pha[i] *= SmoothingWin_NB875[L_overlap-i-1]; + } + + if(oldout_pha_idx == 1) + { + /* Use phase matching and overlapping with the Oldauout*/ + /* Windowing */ + Windowing_1st_NB(ImdctOutWin, ImdctOut, win_NB, NULL, 0); + Windowing_2nd_NB(ImdctOutWin, ImdctOut, win_NB); + } + else + { + /* Only use phase matching */ + /* Windowing */ + Windowing_1st_NB(ImdctOutWin, ImdctOut, win_NB, SmoothingWin_NB875, 1); + Windowing_2nd_NB(ImdctOutWin, ImdctOut, win_NB); + } + + common_overlapping(auOut, ImdctOutWin, OldOut_pha, N_LEAD_NB, 0, N_LEAD_NB, L, N_ZERO_NB, 0); + mvr2r(&ImdctOutWin[L], OldauOut, L); + + return; +} + +/*--------------------------------------------------------------------------* + * FEC_phase_matching_burst() + * + * + *--------------------------------------------------------------------------*/ + +static void FEC_phase_matching_burst( + const float *ImdctOut, /* i : input */ + float *auOut, /* o : output audio */ + float *OldauOut, /* i/o: audio from previous frame */ + float OldauOut_pha[2][N_LEAD_NB], + float *prev_oldauOut /* i : OldauOut from previous frame */ +) +{ + short i; + short L_overlap; + float OldauOut2[L_FRAME8k]; + float ImdctOutWin[2*L_FRAME8k]; + short L; + float win_NB[L_FRAME8k + 25]; + float SmoothingWin_NB3[24]; + + L = L_FRAME8k; + + for(i=0; i<3*L/20; i++) + { + SmoothingWin_NB3[i] = SmoothingWin_NB875[i*3]; + } + + for(i=0; i pow1*3) + { + return 1; + } + + /* Update the OldauOut array for next overlapping */ + mvr2r(&ImdctOutWin[L], OldauOut, L); + Scaledown(prev_oldauOut, prev_oldauOut, SCALE_DOWN_3dB, L); + + return 0; +} + + +/*--------------------------------------------------------------------------* + * Windowing_1st() + * + * + *--------------------------------------------------------------------------*/ + +static void Windowing_1st_NB( + float *ImdctOutWin, /* o : Output */ + const float *ImdctOut, /* i : Input */ + const float *win, /* i : Window */ + const float *smoothingWin, /* i : Smoothing Window */ + short smoothing_flag /* i : 1=Smoothing window, 0=Original window */ +) +{ + short i; + short L; + + L = L_FRAME8k; + if( smoothing_flag == 0 ) + { + for (i = N_ZERO_NB; i < L/2; i++) + { + ImdctOutWin[i] = ImdctOut[L/2 + i] * win[(2*L-1-i)-N_LEAD_O_NB]; + } + + for (i = 0; i < N_ZERO_O_NB; i++) + { + ImdctOutWin[L/2 + i] = -ImdctOut[L - 1 - i] * win[(3*L/2-1-i)-N_LEAD_O_NB]; + ImdctOutWin[3*L/2 + i] = -ImdctOut[i] * win[(L/2-i-1)]; + } + } + else + { + for (i = N_ZERO_NB; i < L/2; i++) + { + ImdctOutWin[i] = ImdctOut[L/2 + i] * smoothingWin[(i-N_ZERO_NB)]; /*win[(2*L-i)*decimate-1-decay-14*L_FRAME48k/20];*/ + } + + for (i = 0; i < N_ZERO_O_NB; i++) + { + ImdctOutWin[L/2 + i] = -ImdctOut[L - 1 - i] * smoothingWin[(i+N_ZERO_O_NB)]; /*win[(3*L/2-1-i)*decimate+decay-L_FRAME48k*14/20];*/ + ImdctOutWin[3*L/2 + i] = -ImdctOut[i] * win[(L/2-i-1)]; + } + } + + return; +} + +/*--------------------------------------------------------------------------* + * Windowing_2nd() + * + * + *--------------------------------------------------------------------------*/ + +static void Windowing_2nd_NB( + float *ImdctOutWin, /* o : Output */ + const float *ImdctOut, /* i : Input */ + const float *win /* i : Window */ +) +{ + short i; + short L; + + L = L_FRAME8k; + for (i = N_ZERO_O_NB; i < L/2; i++) + { + ImdctOutWin[L/2 + i] = -ImdctOut[L - 1 - i]; + ImdctOutWin[3*L/2 + i] = -ImdctOut[i] * win[L/2-i-1]; + } + + for (i = 0; i < N_ZERO_NB; i++) + { + ImdctOutWin[L + i] = -ImdctOut[L/2 - 1 - i]; + } + + for (i = N_ZERO_NB; i < L/2; i++) + { + ImdctOutWin[L + i] = -ImdctOut[L/2 - 1 - i] * win[L - 1 - i]; + } + + return; +} + +/*--------------------------------------------------------------------------* + * common_overlapping() + * + * + *--------------------------------------------------------------------------*/ + +static void common_overlapping( + float *auOut, /* i : Input */ + float *ImdctOutWin, /* o : Output */ + float *OldauOut, /* i : Window */ + short end1, /* i : Decay */ + short offset1, + short start2, + short end2, + short offset_i2, + short offset2 +) +{ + short i; + + /* Common Overlapping */ + for (i=0 ; i < end1; i++) + { + auOut[i] = ImdctOutWin[i+N_ZERO_NB] + OldauOut[i+offset1]; + } + for (i=start2 ; i < end2; i++) + { + auOut[i+offset2] = ImdctOutWin[i+offset_i2]; + } + + return; +} + + +/*--------------------------------------------------------------------------* + * Smoothing_vector() + * + * + *--------------------------------------------------------------------------*/ + +static void Smoothing_vector_NB( + const float OldauOutnoWin[], /* i : Input vector 1 */ + const float ImdctOutWin[], /* i : Input vector 2 */ + const float SmoothingWin[], /* i : Smoothing window */ + float auOut[], /* o : Output vector that contains vector 1 .* vector 2 */ + const short ol_size /* i : Overlap size */ +) +{ + short i; + float weight; + + for (i=0 ; i < ol_size; i++) + { + weight = SmoothingWin[i]; + auOut[i] = (OldauOutnoWin[i]*(1.f-weight)) + (ImdctOutWin[i]*weight); + } + + return; +} + +/*--------------------------------------------------------------------------* + * Smoothing_vector_scaledown() + * + * + *--------------------------------------------------------------------------*/ + +static void Smoothing_vector_scaledown_NB( + const float OldauOutnoWin[], /* i : Input vector 1 */ + const float ImdctOutWin[], /* i : Input vector 2 */ + const float SmoothingWin[], /* i : Smoothing window */ + float auOut[], /* o : Output vector that contains vector 1 .* vector 2 */ + const short ol_size /* i : Overlap size */ +) +{ + short i; + float weight; + + for (i=0 ; i < ol_size; i++) + { + weight = SmoothingWin[i]; + auOut[i] = (OldauOutnoWin[i]*(1.f-weight)) + (ImdctOutWin[i]*SCALE_DOWN_3dB*weight); + } + + return; +} + +/*--------------------------------------------------------------------------* + * Scaledown() + * + * + *--------------------------------------------------------------------------*/ + +static void Scaledown( + float x[], /* i : Input vector */ + float y[], /* o : Output vector that contains vector 1 .* vector 2 */ + float scale_v, + const short N /* i : Overlap size */ +) +{ + short i; + + for(i=0; inbLostCmpt==1)&&(st->phase_mat_flag==1)&&(st->phase_mat_next==0) ) + { + if (FEC_phase_matching(st, wtda_audio, out, st->old_out, st->old_out_pha) ) + { + window_ola( wtda_audio, out, st->old_out, output_frame, st->tcx_cfg.tcx_last_overlap_mode, st->tcx_cfg.tcx_curr_overlap_mode, st->prev_bfi, st->oldHqVoicing, st->oldgapsynth ); + st->phase_mat_next = 0; + } + else + { + st->phase_mat_next = 1; + } + } + else if((st->prev_bfi == 1)&&(st->bfi == 0) &&(st->phase_mat_next == 1)) + { + FEC_phase_matching_nextgood( wtda_audio, out, st->old_out, st->old_out_pha, mean_en_high); + st->phase_mat_next = 0; + } + else if((st->prev_bfi == 1)&&(st->bfi == 1) &&(st->phase_mat_next == 1)) + { + FEC_phase_matching_burst( wtda_audio, out, st->old_out, st->old_out_pha, st->prev_oldauOut); + st->phase_mat_next = 1; + } + else + { + if(st->bfi == 0 && st->prev_bfi == 1) + { + if((st->stat_mode_out==1) || (st->diff_energydiff_energyoldIMDCTout, st->old_out, st->old_bfi_cnt> 1 ? 1:0, N_LEAD_NB); + } + else if(st->old_bfi_cnt > 1) + { + Next_good_after_burst_erasures( wtda_audio, out, st->old_out, N_LEAD_NB ); + } + else + { + window_ola( wtda_audio, out, st->old_out, output_frame, st->tcx_cfg.tcx_last_overlap_mode, st->tcx_cfg.tcx_curr_overlap_mode, st->prev_bfi, st->oldHqVoicing, st->oldgapsynth ); + } + } + else /* if(st->bfi == 1) */ + { + if( (st->stat_mode_out==1) || (st->diff_energyoldIMDCTout, st->old_out, output_frame, st->prev_oldauOut, N_LEAD_NB) ) + { + window_ola( wtda_audio, out, st->old_out, output_frame, st->tcx_cfg.tcx_last_overlap_mode, st->tcx_cfg.tcx_curr_overlap_mode, st->prev_bfi, st->oldHqVoicing, st->oldgapsynth ); + } + } + else + { + window_ola( wtda_audio, out, st->old_out, output_frame, st->tcx_cfg.tcx_last_overlap_mode, st->tcx_cfg.tcx_curr_overlap_mode, st->prev_bfi, st->oldHqVoicing, st->oldgapsynth ); + } + } + + st->phase_mat_next = 0; + } + + return; +} + + +/*--------------------------------------------------------------------------*/ +/* Function Next_good_after_burst_erasures */ +/* ~~~~~~~~~~~~~~~~~~~~ */ +/* */ +/* Windowing, Overlap and Add */ +/*--------------------------------------------------------------------------*/ +/* float ImdctOut[] (i) input */ +/* short auOut[] (o) output audio */ +/* float OldauOut[] (i/o) audio from previous frame */ +/* short ol_size (i) overlap size */ +/* short L (i) length */ +/*--------------------------------------------------------------------------*/ + +void Next_good_after_burst_erasures( + const float *ImdctOut, + float *auOut, + float *OldauOut, + const short ol_size +) +{ + float ImdctOutWin[2*L_FRAME8k]; + short i, L; + float win_NB[L_FRAME8k + 25]; + + L = L_FRAME8k; + for(i=0; i -#include "options.h" /* Compilation switches */ -#include "cnst_fx.h" /* Common constants */ -#include "prot_fx.h" /* Function prototypes */ -#include "stl.h" - -#include "prot_fx.h" -#include "rom_com_fx.h" - - - - -/*--------------------------------------------------------------------------* - * Regression_Anal() - * - * - *--------------------------------------------------------------------------*/ -static void Regression_Anal_fx( - const Word32 *values_fx, /* i : Previous values */ - Word32 *r_p_fx, /* o : Output r[a b] array : y=ax+b */ - const Word16 num_pgf /* i : Number of previous good frame */ -) -{ - Word16 i; - Word16 tmp; - Word32 L_tmp1, L_tmp2; - Word16 aindex_fx[MAX_PGF+1]; - Word32 b_p_fx[MAX_PGF+1]; - - /* Initialize */ - FOR (i=0; ienergy_MA_Curr_fx[1], st_fx->energy_MA_Curr_fx[0])); - exp1 = sub(norm_s(tmp_fx), 1); - st_fx->energy_MA_Curr_fx[0] = s_max(st_fx->energy_MA_Curr_fx[0],1); - move16(); - exp2 = norm_s(st_fx->energy_MA_Curr_fx[0]); - tmp_fx = div_s(shl(tmp_fx, exp1), shl(st_fx->energy_MA_Curr_fx[0], exp2));/*15 + exp1 - exp2*/ - energy_diff_fx = shl(tmp_fx, sub(sub(exp2, exp1), 5));/*10*/ - test(); - IF ((sub(energy_diff_fx, 1024) < 0) && (is_transient==0)) /* First erasure frame */ - { - mute_start = 5; - move16(); - } - ELSE - { - mute_start = 2; - move16(); - } - test(); - test(); - if( sub(st_fx->prev_old_bfi_fx, 1) == 0 && sub(st_fx->nbLostCmpt, 1) == 0 && sub(output_frame, L_FRAME8k) == 0 ) - { - st_fx->nbLostCmpt = add(st_fx->nbLostCmpt, 1); - } - - /* Frequency-domain FEC */ - IF ( sub(st_fx->nbLostCmpt, 1) == 0 ) /* First erasure frame */ - { - IF ( is_transient == 0 ) - { - IF (sub(energy_diff_fx, 1024) < 0) - { - FOR (i=0; i < output_frame; i++) - { - t_audio_q_fx[i] = st_fx->old_coeffs_fx[i]; - move32(); - } - } - ELSE - { - FOR (i=0; i < output_frame; i++) - { - st_fx->old_coeffs_fx[i] = Mult_32_16(st_fx->old_coeffs_fx[i], 23170);/*23170, 3dB, Q15*/ - t_audio_q_fx[i] = st_fx->old_coeffs_fx[i]; - move32(); - } - } - - /* Sign prediction in 4-dim bands up to 1.6 kHz*/ - IF (st_fx->old_is_transient_fx[1] == 0) - { - IF (st_fx->old_is_transient_fx[2] == 0) - { - FOR (sfm = 0; sfm < HQ_FEC_SIGN_SFM; sfm++) - { - IF (sub(st_fx->prev_sign_switch_fx[sfm], HQ_FEC_SIGN_THRES) >= 0) - { - FOR (i = 0; i < HQ_FEC_BAND_SIZE; i++) - { - t_audio_q_fx[i+sfm*HQ_FEC_BAND_SIZE] = L_negate(t_audio_q_fx[i+sfm*HQ_FEC_BAND_SIZE]); - move32(); - } - } - } - } - ELSE - { - FOR (sfm = 0; sfm < HQ_FEC_SIGN_SFM; sfm++) - { - IF (sub(st_fx->prev_sign_switch_fx[sfm], HQ_FEC_SIGN_THRES_TRANS) >= 0) - { - FOR (i = 0; i < HQ_FEC_BAND_SIZE; i++) - { - t_audio_q_fx[i+sfm*HQ_FEC_BAND_SIZE] = L_negate(t_audio_q_fx[i+sfm*HQ_FEC_BAND_SIZE]); - move32(); - } - } - } - } - } - ELSE - { - FOR (i = RANDOM_START*8; i < output_frame; i++) - { - IF(Random(&st_fx->HQ_FEC_seed_fx) < 0) - { - t_audio_q_fx[i] = L_negate(t_audio_q_fx[i]); - move32(); - } - } - } - } - ELSE - { - IF( st_fx->old_is_transient_fx[1] ) /* hangover */ - { - FOR (i=0; i < output_frame; i++) - { - st_fx->old_coeffs_fx[i] = Mult_32_16(st_fx->old_coeffs_fx[i], 23170); - t_audio_q_fx[i] = st_fx->old_coeffs_fx[i]; - move32(); - } - } - ELSE - { - FOR (i = 0; i < RANDOM_START*8; i++) - { - st_fx->old_coeffs_fx[i] = Mult_32_16(st_fx->old_coeffs_fx[i], 23170); - t_audio_q_fx[i] = st_fx->old_coeffs_fx[i]; - move32(); - } - - FOR (i = RANDOM_START*8; i < output_frame; i++) - { - st_fx->old_coeffs_fx[i] = Mult_32_16(st_fx->old_coeffs_fx[i], 23170); - IF (Random(&st_fx->HQ_FEC_seed_fx) < 0) - { - t_audio_q_fx[i] = L_negate(st_fx->old_coeffs_fx[i]); - move32(); - } - ELSE - { - t_audio_q_fx[i] = st_fx->old_coeffs_fx[i]; - move32(); - } - } - } - } - } - ELSE /* st_fx->nbLostCmpt > 1 */ - { - test(); - IF( sub(energy_diff_fx, 1024) < 0 && is_transient == 0 ) - { - num_pgf = 4; - move16(); - } - ELSE - { - num_pgf = 2; - move16(); - } - - Num_sb_bwe = num_Sb; - move16(); - IF ( sub(st_fx->nbLostCmpt, 2) == 0 ) - { - - FOR ( i=0; inbLostCmpt, mute_start) >= 0 ) - { - /* Scaling */ - FOR ( i=0; i < output_frame; i++ ) - { - st_fx->old_coeffs_fx[i] = Mult_32_16(st_fx->old_coeffs_fx[i], 23170); - move32(); - } - } - - k = 0; - move16(); - FOR ( i=0; i 0 ) - { - r_p_fx[1] = L_deposit_l(0); - norm_p_fx[i] = L_shr(norm_values_fx[0], 7);/*5*/ move32(); - } - ELSE - { - norm_p_fx[i] = L_add(r_p_fx[0], L_mult0(extract_l(r_p_fx[1]), sub(add(st_fx->nbLostCmpt, num_pgf), 1))); - } - - test(); - IF ( norm_values_fx[0] != 0 && norm_p_fx[i] > 0 ) /* Avoid negative value of the predicted energy */ - { - exp1 = sub(norm_l(norm_p_fx[i]), 1); - exp2 = norm_l(norm_values_fx[0]); - tmp_fx = div_s(extract_h(L_shl(norm_p_fx[i], exp1)), - extract_h(L_shl(norm_values_fx[0], exp2)));/*15 + (5 + exp1 - 16) - (12 + exp2 - 16)*/ - tmp_fx = shl(tmp_fx, add(6, sub(exp2, exp1)));/*14*/ - - if (sub(tmp_fx, 16384) > 0) - { - tmp_fx = 16384; - move16(); - } - - FOR ( j=0; jNorm_gain_fx[k++] = shl(tmp_fx, 1); - move16(); - } - } - ELSE - { - /* Scale down the last gain with the fixed gain(-3dB) */ - FOR (j=0; jNorm_gain_fx[k] = mult_r(st_fx->Norm_gain_fx[k], 23170); - move16(); - k++; - } - } - } - - /* Scaling for core band */ - FEC_scaling_fx( st_fx->old_coeffs_fx, t_audio_q_fx, st_fx->Norm_gain_fx, &st_fx->HQ_FEC_seed_fx, nb_sfm, sfm_start, sfm_end ); - - } - - - return; -} - -void HQ_FEC_Mem_update_fx( - Decoder_State_fx *st_fx, /* i/o: decoder state structure */ - Word32 *t_audio_q_fx, /*Q12*/ - Word32 *normq_fx, /*Q14*/ - Word16 *ynrm, - Word16 *Num_bands_p, - Word16 is_transient, - Word16 hqswb_clas, - Word16 c_switching_flag, - Word16 nb_sfm, - Word16 num_Sb, - Word16 *mean_en_high_fx, /*Q5*/ - Word16 hq_core_type, /* i : normal or low-rate MDCT(HQ) core */ - Word16 output_frame -) -{ - Word16 Min_ind; - Word32 Min_value; - Word16 Max_ind; - Word16 stat_mode_curr; - - Word16 i, j, k; - Word16 offset; - Word16 exp, exp1, exp2, tmp_fx; - Word32* norm_values_fx; - Word32 L_tmp, tmp_energy_fx = 0, Max_coeff_fx; - Word32 en_high_fx[MAX_SB_NB]; - - - IF (is_transient) - { - set16_fx(st_fx->prev_sign_switch_2_fx, 0, HQ_FEC_SIGN_SFM); - set16_fx(st_fx->prev_sign_switch_fx, 0, HQ_FEC_SIGN_SFM); - } - ELSE - { - FOR (j = 0; j < HQ_FEC_SIGN_SFM; j++) - { - st_fx->prev_sign_switch_fx[j] = st_fx->prev_sign_switch_2_fx[j]; - move16(); - st_fx->prev_sign_switch_2_fx[j] = 0; - move16(); - - FOR (i = 0; i < HQ_FEC_BAND_SIZE; i++) - { - test(); - test(); - test(); - IF ((st_fx->old_coeffs_fx[i+j*HQ_FEC_BAND_SIZE]>0 && t_audio_q_fx[i+j*HQ_FEC_BAND_SIZE]<0) - || (st_fx->old_coeffs_fx[i+j*HQ_FEC_BAND_SIZE]<0 && t_audio_q_fx[i+j*HQ_FEC_BAND_SIZE]>0)) - { - st_fx->prev_sign_switch_fx[j] = add(st_fx->prev_sign_switch_fx[j], 1); - move16(); - st_fx->prev_sign_switch_2_fx[j] = add(st_fx->prev_sign_switch_2_fx[j], 1); - move16(); - } - } - } - } - - IF(sub(output_frame, L_FRAME8k) == 0) - { - /* if LR MDCT core is used, recalculate norms from decoded MDCT spectrum (using code from hq_hr_enc_fx()) */ - test(); - IF ( ( sub(hqswb_clas, HQ_HVQ) == 0 ) || ( sub(hq_core_type, LOW_RATE_HQ_CORE) == 0 ) ) - { - /* First group */ - logqnorm_fx(t_audio_q_fx, 12, ynrm, 32, WID_G1, (hqswb_clas == HQ_HVQ)); - j = ynrm[0]; - move16(); - offset = WID_G1; - move16(); - - FOR ( i=1; iynrm_values_fx[i][0]; - Copy32(norm_values_fx, &norm_values_fx[1], MAX_PGF-1); - - L_tmp = L_deposit_l(0); - FOR (j=0; jlast_core_fx, ACELP_CORE) == 0)&&(sub(st_fx->core_fx, HQ_CORE) == 0))) - { - FOR (i=0; iynrm_values_fx[i][j]=st_fx->ynrm_values_fx[i][0]; - move32(); - } - } - } - set16_fx(st_fx->Norm_gain_fx, 32767, SFM_N_NB);/*15*/ - /* st->energy_MA_Curr[1]=Energy of the current frame */ - tmp_fx = inv_tbl_fx[nb_sfm]; - move16();/*15*/ - L_tmp = Mult_32_16(tmp_energy_fx, tmp_fx);/*8 + 15 - 15*/ - - st_fx->energy_MA_Curr_fx[1] = extract_h(L_shl(L_tmp, 16-8)); - /* Moving Average */ - st_fx->energy_MA_Curr_fx[0] = s_max(1,add(mult_r(26214, st_fx->energy_MA_Curr_fx[0]), mult_r(6554, st_fx->energy_MA_Curr_fx[1]))); - - /*st->diff_energy = (float)fabs((st->energy_MA_Curr[1] - st->energy_MA_Curr[0])/st->energy_MA_Curr[0]); */ - st_fx->diff_energy_fx = abs_s(sub(st_fx->energy_MA_Curr_fx[1], st_fx->energy_MA_Curr_fx[0])); - exp1 = sub(norm_l(st_fx->diff_energy_fx), 1); - exp2 = norm_l(st_fx->energy_MA_Curr_fx[0]); - st_fx->diff_energy_fx = div_s(extract_h(L_shl(st_fx->diff_energy_fx, exp1)), extract_h(L_shl(st_fx->energy_MA_Curr_fx[0], exp2))); - exp = add(15, sub(exp1, exp2)); - st_fx->diff_energy_fx = shl(st_fx->diff_energy_fx, sub(11, exp));/*11*/ - - /* Classify the stationary mode : 12% */ - IF (sub(st_fx->diff_energy_fx, ED_THRES_12P_fx) < 0) - { - stat_mode_curr = 1; - move16(); - } - ELSE - { - stat_mode_curr = 0; - move16(); - } - - /* Apply Hysteresis to prevent frequent mode changing */ - IF(sub(st_fx->stat_mode_old_fx, stat_mode_curr) == 0) - { - st_fx->stat_mode_out_fx = stat_mode_curr; - move16(); - } - - st_fx->stat_mode_old_fx = stat_mode_curr; - move16(); - - /* Find max. band index (Minimum value means maximum energy) */ - Min_ind=0; - move16(); - Min_value = L_deposit_l(100); - FOR (i=0; i 0) - { - Min_value = ynrm[i]; - move16(); - Min_ind = i; - move16(); - } - } - - /* Find max. coeff in band 0 */ - Max_ind = 0; - move16(); - IF (Min_ind == 0) - { - Max_coeff_fx = L_deposit_l(0); - FOR (i=0; i<8; i++) - { - L_tmp = L_abs(t_audio_q_fx[i]); - IF (L_sub(Max_coeff_fx, L_tmp) < 0) - { - Max_coeff_fx = L_add(L_tmp, 0); - Max_ind = i; - move16(); - } - } - } - - /* Find energy difference from band 16 */ - k=1; - move16(); - - FOR (i=k; iynrm_values[i][j+1];*/ - en_high_fx[i] = L_add(en_high_fx[i], L_shr(st_fx->ynrm_values_fx[i][j+1], 1));/*Q12*/ move32(); - } - } - - *mean_en_high_fx = 0; - move16(); - FOR (i=k; iynrm_values[i][0]);*/ - exp1 = sub(norm_l(en_high_fx[i]), 1); - exp2 = norm_l(st_fx->ynrm_values_fx[i][0]); - tmp_fx = div_s(extract_h(L_shl(en_high_fx[i], exp1)), extract_h(L_shl(st_fx->ynrm_values_fx[i][0], exp2))); - exp = add(15, sub(exp1, exp2)); - *mean_en_high_fx = add(*mean_en_high_fx, shr(tmp_fx, sub(exp, 5))); - } - *mean_en_high_fx = mult(*mean_en_high_fx, inv_tbl_fx[num_Sb-k]); - - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - IF ((sub(Min_ind, 5) < 0) && (sub(abs_s(sub(Min_ind, st_fx->old_Min_ind_fx)), 2) < 0) &&(sub(st_fx->diff_energy_fx, ED_THRES_90P_fx) < 0)&&(!st_fx->bfi_fx) && (!st_fx->prev_bfi_fx)&&(!st_fx->prev_old_bfi_fx) - &&(!is_transient)&&(!st_fx->old_is_transient_fx[1]) && (st_fx->prev_last_core_fx==HQ_CORE) && (st_fx->last_core_fx==HQ_CORE)) - { - st_fx->phase_mat_flag_fx = 1; - move16(); - test(); - if ((Min_ind == 0)&&(sub(Max_ind, 3) < 0)) - { - st_fx->phase_mat_flag_fx = 0; - move16(); - } - } - ELSE - { - st_fx->phase_mat_flag_fx = 0; - move16(); - } - - st_fx->old_Min_ind_fx = Min_ind; - move16(); - } - - FOR (i=0; i < L_FRAME8k; i++) - { - st_fx->old_coeffs_fx[i] = t_audio_q_fx[i]; - move32(); - } - - st_fx->old_is_transient_fx[2] = st_fx->old_is_transient_fx[1]; - move16(); - st_fx->old_is_transient_fx[1] = st_fx->old_is_transient_fx[0]; - move16(); - st_fx->old_is_transient_fx[0] = is_transient; - move16(); - - return; -} - - -static Word16 find_best_delay_fx( - Word16 *mu_o_fx, - Word16 *in_fx, - Word16 mind1, - Word16 maxd1, - Word16 lin, - Word16 delta, - Word16 *false_flag -) -{ - Word16 i, d1, k; - Word16 d1m = 0; - - Word16 tmp, exp1, exp2; - Word32 L_tmp1, L_tmp2; - - Word32 min_sq_cross_fx, min_corr_fx; - Word32 accA_fx, accB_fx; - Word32 Rxy_fx[MAXDELAY_FEC], Ryy_fx[MAXDELAY_FEC]; - - d1 = mind1; - move16(); - FOR ( k = 0; k < (maxd1-mind1)/delta; k++ ) - { - accA_fx = L_deposit_l(0); - accB_fx = L_deposit_l(0); - FOR ( i = 0; i < lin; i += delta ) - { - accA_fx = L_add(accA_fx, L_shr(L_mult(mu_o_fx[d1+i], mu_o_fx[d1+i]),2)); - accB_fx = L_add(accB_fx, L_shr(L_mult(mu_o_fx[d1+i], in_fx[i]),2)); - } - - Rxy_fx[k] = accB_fx; - move32(); - Ryy_fx[k] = accA_fx; - move32(); - - d1 = add(d1, delta); - } - - /* Obtain the best delay values */ - min_sq_cross_fx = 0x80000000; - move32(); - min_corr_fx = L_deposit_l(0); - exp2 = 0; - move16(); - FOR ( d1 = 0; d1 < (maxd1-mind1)/delta; d1++ ) - { - IF (L_abs(Rxy_fx[d1]) > L_abs(Ryy_fx[d1])) - exp1 = norm_l(Rxy_fx[d1]); - ELSE - exp1 = norm_l(Ryy_fx[d1]); - - L_tmp1 = Mult_32_32(L_shl(Rxy_fx[d1], exp1), L_shl(min_corr_fx, exp2)); - L_tmp2 = Mult_32_32(L_shl(Ryy_fx[d1], exp1), L_shl(min_sq_cross_fx, exp2)); - IF ( L_sub(L_tmp1, L_tmp2) >= 0) - { - d1m = d1; - move16(); - min_corr_fx = L_add(Ryy_fx[d1], 0); /*12 + 12 - 31 */ - min_sq_cross_fx = L_add(Rxy_fx[d1], 0); /*12 + 12 - 31 */ - exp2 = exp1; - move16(); - } - } - - test(); - IF((min_sq_cross_fx<=0) || (min_corr_fx<=0)) - { - tmp = 0; - move16(); /* If cross correlation is negative, the division per the energy will always be negative --> tmp will be < 8192, no need to do the division per say */ - } - ELSE - { - /*d1m *= delta; */ - d1m = extract_l(L_mult0(d1m, delta)); - - exp1 = sub(norm_l(min_sq_cross_fx), 1); - exp2 = norm_l(min_corr_fx); - L_tmp1 = L_shl(min_sq_cross_fx, exp1); - L_tmp2 = L_shl(min_corr_fx, exp2); - tmp = div_s(extract_h(L_tmp1), extract_h(L_tmp2));/*15 + exp1 - exp2 */ - tmp = shl(tmp, sub(exp2, add(exp1, 1)));/*14 */ - } - - *false_flag = 0; - move16(); - test(); - if (sub(tmp, 8192) < 0 || sub(tmp, 24576) > 0) - { - *false_flag = 1; - move16(); - } - - return d1m; - -} - -static Word16 Search_Max_Corr_fx( - Word16 *mu_o_fx, /* i : *old_auOut_2fr, */ - Word16 old_Min_ind, /* i : *old_auOut_2fr, */ - const Word16 L /* i : L/2 */ -) -{ - Word16 pos; - Word16 pos2,delta2; - Word16 lin, delta; - Word16 mind1,maxd1; - Word16 false_flag; - Word16 min_d1, max_d1; - Word16 tmp1, tmp2; - Word16 *in_fx; - - IF (old_Min_ind == 0) - { - /*lin = 8*L/20; */ /* Basic size of the block for phase matching */ - lin = mult_r(L, 13107); /* Basic size of the block for phase matching */ - /*min_dist = -1e35f; */ - mind1 = 0; - move16(); /* min value of delay d1 to search for */ - /*maxd1 = 12*L/20; */ /* max value of delay d1 to search for */ - maxd1 = mult_r(L, 19661); /* max value of delay d1 to search for */ - - /*in = mu_o + 2*L -lin; */ - in_fx = mu_o_fx + 2*L - lin; - move16(); - - /* generate correlation */ - delta = 2; - move16(); - delta2 = 1; - move16(); - - pos = find_best_delay_fx(mu_o_fx, in_fx, mind1, maxd1, lin, delta, &false_flag); - - IF (false_flag) - { - return 0; - } - - tmp1 = add(mind1, sub(add(pos, 1), delta)); - tmp2 = add(mind1, add(pos, delta)); - min_d1 = s_max(mind1, tmp1); - max_d1 = s_min(maxd1, tmp2); - pos2 = find_best_delay_fx(mu_o_fx, in_fx, min_d1, max_d1, lin, delta2, &false_flag); - IF (sub(mind1, tmp1) > 0) - { - pos = pos2; - move16(); - } - ELSE - { - pos = add(pos, add(sub(pos2, delta), 1)); - } - - pos = add(pos, add(lin, mind1)); - } - ELSE - { - lin = mult_r(L, 9830); - mind1 = mult_r(L, 14746); /* min value of delay d1 to search for */ - maxd1 = mult_r(L, 22938); /* max value of delay d1 to search for */ - in_fx = mu_o_fx + 2*L - lin; - move16(); - - /* generate correlation */ - delta = 2; - move16(); - delta2 = 1; - move16(); - - pos = find_best_delay_fx(mu_o_fx, in_fx, mind1, maxd1, lin, delta, &false_flag); - - IF (false_flag) - { - return 0; - } - - tmp1 = add(mind1, add(sub(pos, delta), 1)); - tmp2 = add(mind1, add(pos, delta)); - min_d1 = s_max(mind1, tmp1); - max_d1 = s_min(maxd1, tmp2); - pos2 = find_best_delay_fx(mu_o_fx, in_fx, min_d1, max_d1, lin, delta2, &false_flag); - - IF (sub(mind1, tmp1) > 0 ) - { - pos = pos2; - move16(); - } - ELSE - { - pos = add(pos, add(sub(pos2, delta), 1)); - } - pos = add(pos, add(lin, mind1)); - } - - return pos; -} - -Word16 FEC_phase_matching_fx( - Decoder_State_fx *st_fx, /* i : Decoder State */ - Word32 *ImdctOut_fx, /* i : input */ - Word16 *auOut_fx, /* o : output audio */ - Word16 *OldauOut_fx, - Word16 OldauOut_pha_fx[2][N_LEAD_NB] -) -{ - Word16 i; - Word16 pos, remain; - Word16 ol_size; - Word16 L_overlap, L; - Word16 ImdctOutWin_fx[2*L_FRAME8k]; - Word16 OldauOutnoWin_fx[L_FRAME8k]; - Word16 OldauOut2_fx[L_FRAME8k]; - Word16 win_NB_fx[L_FRAME8k + 25]; - Word16 exp1, exp2, tmp; - Word32 pow1_fx, pow22_fx; - Word16 SmoothingWin_NB3_fx[24]; - - L = L_FRAME8k; - move16(); - ol_size = 2*L/20; - move16(); - L_overlap = 3*L/20; - move16(); - - FOR (i=0; iold_auOut_2fr_fx, st_fx->old_Min_ind_fx, L); - - IF (pos == 0) - { - return 1; - } - - /* Repetition */ - remain = L+N_Z_L_NB - ((2*L)-pos); - move16(); - Copy(&st_fx->old_auOut_2fr_fx[pos], &ImdctOutWin_fx[N_ZERO_NB], (2*L)-pos); - - /* OldauOut without windowing */ - FOR (i = N_ZERO_NB; i < L/2; i++) - { - OldauOutnoWin_fx[i-N_ZERO_NB] = extract_l( L_shr( L_negate(st_fx->oldIMDCTout_fx[L/2 - 1 - i]), 6 ) ); - } - FOR(i = 0; i < L/2; i++) - { - OldauOutnoWin_fx[i+N_ZERO_O_NB] = extract_l( L_shr( L_negate(st_fx->oldIMDCTout_fx[i]), 6 ) ); - } - - Copy(OldauOutnoWin_fx, &ImdctOutWin_fx[N_ZERO_NB+(2*L)-pos], remain); - - pow1_fx = L_deposit_l(0); - pow22_fx = L_deposit_l(0); - FOR (i = 0; i < L; i++) - { - pow1_fx = L_add(pow1_fx, shr(abs_s(st_fx->old_auOut_2fr_fx[L+i]), 1)); - pow22_fx = L_add(pow22_fx, shr(abs_s(ImdctOutWin_fx[N_ZERO_NB+i]), 1)); - } - IF(pow22_fx != 0) - { - exp1 = sub(norm_l(pow1_fx), 1); - exp2 = norm_l(pow22_fx); - tmp = div_s(extract_h(L_shl(pow1_fx, exp1)), extract_h(L_shl(pow22_fx, exp2)));/*15 + exp1 - exp2*/ - tmp = shl(tmp, sub(sub(exp2, exp1), 1));/*14*/ - FOR (i = N_ZERO_NB; i < 2*L; i++) - { - ImdctOutWin_fx[i] = shl(mult(ImdctOutWin_fx[i], tmp), 1); - } - } - Smoothing_vector_NB_fx(OldauOutnoWin_fx, &ImdctOutWin_fx[N_ZERO_NB], SmoothingWin_NB2_fx, auOut_fx, ol_size); - - FOR (i = 0; i < L/2; i++) - { - /*ImdctOutWin[3*L/2 + i] *= win_NB[L/2-i-1];*/ - ImdctOutWin_fx[3*L/2 + i] = mult(ImdctOutWin_fx[3*L/2 + i], win_NB_fx[L/2-i-1]); - move16(); - } - - FOR (i = N_ZERO_NB; i < L/2; i++) - { - /*ImdctOutWin_fx[L + i] *= win_NB_fx[(L-1-i)];*/ - ImdctOutWin_fx[L + i] = mult(ImdctOutWin_fx[L + i], win_NB_fx[(L-1-i)]); - move16(); - } - - Copy(&ImdctOutWin_fx[N_Z_L_O_NB], &OldauOut_pha_fx[0][0], N_LEAD_NB); - Copy(&ImdctOutWin_fx[ol_size+N_ZERO_NB], &auOut_fx[ol_size], N_Z_L_NB-ol_size); - Copy(&ImdctOutWin_fx[L], &auOut_fx[N_Z_L_NB], N_ZERO_NB); - Copy(&ImdctOutWin_fx[L], OldauOut_fx, L); - - FOR (i = 0; i < L/2; i++) - { - OldauOut2_fx[i] = extract_l( L_shr( L_negate(ImdctOut_fx[L/2 - 1 - i]), 6 ) ); - OldauOut2_fx[L/2+i] = extract_l( L_shr( L_negate(ImdctOut_fx[i]), 6 ) ); - } - - Smoothing_vector_NB_fx(&ImdctOutWin_fx[N_Z_L_O_NB], &OldauOut2_fx[N_ZERO_NB], SmoothingWin_NB3_fx, &OldauOut_pha_fx[1][0], L_overlap); - - FOR (i=L_overlap; i 0)||(sub(mean_en_high_fx, 16) < 0)) - { - oldout_pha_idx = 1; - move16(); - } - ELSE - { - oldout_pha_idx = 0; - move16(); - } - - /* Overlapping with next good frame : Overlapping to remove the discontinuity */ - L_overlap = N_LEAD_NB; - move16(); - OldOut_pha_fx = OldauOut_pha_fx[oldout_pha_idx]; - FOR (i = 0; i < N_LEAD_NB; i++) - { - /* OldOut_pha[i] *= SmoothingWin_NB875[L_overlap-i-1]; */ - OldOut_pha_fx[i] = mult(OldOut_pha_fx[i], SmoothingWin_NB875_fx[L_overlap-i-1]); - move16(); - } - - IF (sub(oldout_pha_idx, 1) == 0) - { - /* Use phase matching and overlapping with the Oldauout*/ - /* Windowing */ - /*Windowing_1st_NB(ImdctOutWin, ImdctOut, win_NB, NULL, 0);*/ - /*Windowing_2nd_NB(ImdctOutWin, ImdctOut, win_NB); */ - Windowing_1st_NB_fx(ImdctOutWin_fx, ImdctOut_fx, win_NB_fx, NULL, 0); - Windowing_2nd_NB_fx(ImdctOutWin_fx, ImdctOut_fx, win_NB_fx); - } - ELSE - { - /* Only use phase matching */ - /* Windowing */ - Windowing_1st_NB_fx(ImdctOutWin_fx, ImdctOut_fx, win_NB_fx, SmoothingWin_NB875_fx, 1); - Windowing_2nd_NB_fx(ImdctOutWin_fx, ImdctOut_fx, win_NB_fx); - } - /* common_overlapping(auOut, ImdctOutWin, OldOut_pha, N_LEAD_NB, 0, N_LEAD_NB, L, N_ZERO_NB, 0, L);*/ - common_overlapping_fx(auOut_fx, ImdctOutWin_fx, OldOut_pha_fx, N_LEAD_NB, 0, N_LEAD_NB, L, N_ZERO_NB, 0); - Copy(&ImdctOutWin_fx[L], OldauOut_fx, L); - - return; -} - -void FEC_phase_matching_burst_fx( - const Word32 *ImdctOut_fx, /* i : input */ - Word16 *auOut_fx, /* o : output audio */ - Word16 *OldauOut_fx, /* i/o: audio from previous frame */ - Word16 OldauOut_pha_fx[2][N_LEAD_NB], - Word16 *prev_oldauOut_fx /* i : OldauOut from previous frame */ -) -{ - Word16 i; - Word16 L_overlap; - Word16 L; - Word16 OldauOut2_fx[L_FRAME8k]; - Word16 ImdctOutWin_fx[2*L_FRAME8k]; - Word16 win_NB_fx[L_FRAME8k + 25]; - Word16 SmoothingWin_NB3_fx[24]; - - L = L_FRAME8k; - move16(); - L_overlap = 3*L/20; - move16(); - - FOR (i=0; i Q0 */ - } - FOR (i = 0; i < L/2; i++) - { - /*OldauOut[i+N_ZERO_O_NB] = -OldImdctOut[i];*/ - OldauOut_fx[i+N_ZERO_O_NB] = extract_l( L_shr( L_negate(OldImdctOut_fx[i]), 6 )); /* Q6 -> Q0 */ - } - - /* Overlapping with next good frame : Overlapping to remove the discontinuity */ - IF (cur_data_use_flag) - { - ol_size = N_LEAD_NB; - move16(); - - FOR (i = N_ZERO_NB; i < L/2; i++) - { - /* ImdctOutWin[i+L] = -ImdctOut[L/2 - 1 - i]; */ - ImdctOutWin_fx[i+L] = extract_l( L_shr( L_negate(ImdctOut_fx[L/2 - 1 - i]), 6 ) ); - } - FOR (i = 0; i < L/2; i++) - { - ImdctOutWin_fx[i+3*L/2] = extract_l( L_shr( L_negate(ImdctOut_fx[i]), 6 ) ); - } - - /*a = (float)(1./(float)(ol_size)); y = ax */ - Smoothing_vector_scaledown_NB_fx(OldauOut_fx, &ImdctOutWin_fx[N_Z_L_O_NB], SmoothingWin_NB875_fx, OldauOut_fx, ol_size); - - /* Scale down the overlapped signal */ - Scaledown_fx(&ImdctOutWin_fx[ol_size+N_Z_L_O_NB], &OldauOut_fx[ol_size], 23170, N_Z_L_NB-ol_size); - } - - L_overlap = overlap_time; - move16(); - FOR (i = 0; i < L_overlap; i++) - { - /*OldauOut[i] *= SmoothingWin_NB875[L_overlap-i-1];*/ - OldauOut_fx[i] = mult(OldauOut_fx[i], SmoothingWin_NB875_fx[L_overlap-i-1]); - move16(); - } - FOR (i=L_overlap; i < L; i++) - { - OldauOut_fx[i] = 0; - move16(); - } - - /* Windowing */ - /*Windowing_1st_NB(ImdctOutWin, ImdctOut, win_NB, SmoothingWin_NB875, 1);*/ - /*Windowing_2nd_NB(ImdctOutWin, ImdctOut, win_NB);*/ - Windowing_1st_NB_fx(ImdctOutWin_fx, ImdctOut_fx, win_NB_fx, SmoothingWin_NB875_fx, 1); - Windowing_2nd_NB_fx(ImdctOutWin_fx, ImdctOut_fx, win_NB_fx); - - /*v_add(&ImdctOutWin[N_ZERO_NB], OldauOut, auOut, L);*/ - /*mvr2r(&ImdctOutWin[L], OldauOut, L);*/ - FOR (i = 0; i < L; i++) - { - auOut_fx[i] = add(ImdctOutWin_fx[N_ZERO_NB + i], OldauOut_fx[i]); - move16(); - } - Copy(&ImdctOutWin_fx[L], OldauOut_fx, L); - - return; -} - -Word16 Repetition_smoothing_fx( - const Word32 *ImdctOut_fx, /* i : input */ - Word16 *auOut_fx, /* o : output audio */ - Word32 *OldImdctOut_fx, /* i : input */ - Word16 *OldauOut_fx, /* i/o: audio from previous frame */ - const Word16 L, /* i : length */ - Word16 *prev_oldauOut_fx, /* i : OldauOut from previous frame */ - Word16 overlap_time /* i : overlap time */ -) -{ - Word16 i; - Word32 pow1_fx; - Word32 pow22_fx; - Word16 ImdctOutWin_fx[2*L_FRAME8k]; - Word16 OldauOutnoWin_fx[L_FRAME8k]; - Word16 win_NB_fx[L_FRAME8k + 25]; - - FOR (i=0; i L_add(pow1_fx, L_shl(pow1_fx, 1))) - { - return 1; - } - - /* Update the OldauOut array for next overlapping */ - Copy(&ImdctOutWin_fx[L], OldauOut_fx, L); - Scaledown_fx(prev_oldauOut_fx, prev_oldauOut_fx, 23170, L); - - return 0; -} - -void common_overlapping_fx( - Word16 *auOut_fx, /* i : Input */ - Word16 *ImdctOutWin_fx, /* o : Output */ - Word16 *OldauOut_fx, /* i : Window */ - Word16 end1, /* i : Decay */ - Word16 offset1, - Word16 start2, - Word16 end2, - Word16 offset_i2, - Word16 offset2 -) -{ - Word16 i; - - /* Common Overlapping */ - FOR (i=0 ; i < end1; i++) - { - /*auOut_fx[i] = L_add(ImdctOutWin_fx[i+7*L/20], OldauOut_fx[i+offset1]);*/ - auOut_fx[i] = add(ImdctOutWin_fx[i+N_ZERO_NB], OldauOut_fx[i+offset1]); - move16(); - } - FOR (i=start2 ; i < end2; i++) - { - /*auOut_fx[i+offset2] = ImdctOutWin_fx[i+offset_i2]; move32();*/ - auOut_fx[i+offset2] = ImdctOutWin_fx[i+offset_i2]; - move16(); - } - - return; -} - - -void Smoothing_vector_NB_fx( - const Word16 OldauOutnoWin_fx[], /* i : Input vector 1 */ - const Word16 ImdctOutWin_fx[], /* i : Input vector 2 */ - const Word16 SmoothingWin_fx[], /* i : Smoothing window */ - Word16 auOut_fx[], /* o : Output vector that contains vector 1 .* vector 2 */ - const Word16 ol_size /* i : Overlap size */ -) -{ - Word16 i; - Word16 weight_fx; - - FOR (i=0 ; i < ol_size; i++) - { - weight_fx = SmoothingWin_fx[i]; - move16(); - auOut_fx[i] = add(mult(OldauOutnoWin_fx[i], sub(32767, weight_fx)), mult(ImdctOutWin_fx[i], weight_fx)); - move16(); - } - - return; -} - - -void Windowing_1st_NB_fx( - Word16 *ImdctOutWin_fx, /* o : Output */ - const Word32 *ImdctOut_fx, /* i : Input */ - const Word16 *win_fx, /* i : Window */ - const Word16 *smoothingWin_fx, /* i : Smoothing Window */ - Word16 smoothing_flag /* i : 1=Smoothing window, 0=Original window */ -) -{ - Word16 i; - Word16 L; - - L = L_FRAME8k; - move16(); - IF ( smoothing_flag == 0 ) - { - FOR (i = N_ZERO_NB; i < L/2; i++) - { - /*ImdctOutWin[i] = ImdctOut[L/2 + i] * win[(2*L-1-i)-N_LEAD_O_NB];*/ - ImdctOutWin_fx[i] = extract_l( L_shr( Mult_32_16(ImdctOut_fx[L/2 + i], win_fx[(2*L-1-i)-N_LEAD_O_NB]), 6 )); - } - - FOR (i = 0; i < N_ZERO_O_NB; i++) - { - /*ImdctOutWin[L/2 + i] = -ImdctOut[L - 1 - i] * win[(3*L/2-1-i)-N_LEAD_O_NB];*/ - /*ImdctOutWin[3*L/2 + i] = -ImdctOut[i] * win[(L/2-i-1)];*/ - ImdctOutWin_fx[L/2 + i] = extract_l( L_shr( Mult_32_16(L_negate(ImdctOut_fx[L - 1 - i]), win_fx[(3*L/2-1-i)-N_LEAD_O_NB]), 6 )); - ImdctOutWin_fx[3*L/2 + i] = extract_l( L_shr( Mult_32_16(L_negate(ImdctOut_fx[i]), win_fx[(L/2-i-1)]), 6 )); - } - } - ELSE - { - FOR (i = N_ZERO_NB; i < L/2; i++) - { - /*ImdctOutWin[i] = ImdctOut[L/2 + i] * smoothingWin[(i-N_ZERO_NB)];*/ /*win[(2*L-i)*decimate-1-decay-14*L_FRAME48k/20];*/ - ImdctOutWin_fx[i] = extract_l( L_shr( Mult_32_16(ImdctOut_fx[L/2 + i], smoothingWin_fx[(i-N_ZERO_NB)]), 6 )); /*win[(2*L-i)*decimate-1-decay-14*L_FRAME48k/20];*/ - } - - FOR (i = 0; i < N_ZERO_O_NB; i++) - { - /*ImdctOutWin[L/2 + i] = -ImdctOut[L - 1 - i] * smoothingWin[(i+N_ZERO_O_NB)];*/ /*win[(3*L/2-1-i)*decimate+decay-L_FRAME48k*14/20];*/ - /*ImdctOutWin[3*L/2 + i] = -ImdctOut[i] * win[(L/2-i-1)];*/ - ImdctOutWin_fx[L/2 + i] = extract_l( L_shr( Mult_32_16(L_negate(ImdctOut_fx[L - 1 - i]), smoothingWin_fx[(i+N_ZERO_O_NB)]), 6 )); /*win[(3*L/2-1-i)*decimate+decay-L_FRAME48k*14/20];*/ - ImdctOutWin_fx[3*L/2 + i] = extract_l( L_shr( Mult_32_16(L_negate(ImdctOut_fx[i]), win_fx[(L/2-i-1)]), 6 )); - } - } - - return; -} -void Windowing_2nd_NB_fx( - Word16 *ImdctOutWin_fx, /* o : Output */ - const Word32 *ImdctOut_fx, /* i : Input */ - const Word16 *win_fx /* i : Window */ -) -{ - Word16 i; - Word16 L; - - L = L_FRAME8k; - move16(); - FOR (i = N_ZERO_O_NB; i < L/2; i++) - { - /*ImdctOutWin[L/2 + i] = -ImdctOut[L - 1 - i];*/ - /*ImdctOutWin[3*L/2 + i] = -ImdctOut[i] * win[L/2-i-1];*/ - ImdctOutWin_fx[L/2 + i] = extract_l( L_shr( L_negate(ImdctOut_fx[L - 1 - i]), 6 )); - ImdctOutWin_fx[3*L/2 + i] = extract_l( L_shr( Mult_32_16(L_negate(ImdctOut_fx[i]), win_fx[L/2-i-1]), 6 )); - } - - FOR (i = 0; i < N_ZERO_NB; i++) - { - /*ImdctOutWin[L + i] = -ImdctOut[L/2 - 1 - i];*/ - ImdctOutWin_fx[L + i] = extract_l( L_shr( L_negate(ImdctOut_fx[L/2 - 1 - i]), 6 )); - } - - FOR (i = N_ZERO_NB; i < L/2; i++) - { - /*ImdctOutWin[L + i] = -ImdctOut[L/2 - 1 - i] * win[L - 1 - i];*/ - ImdctOutWin_fx[L + i] = extract_l( L_shr( Mult_32_16(L_negate(ImdctOut_fx[L/2 - 1 - i]), win_fx[L - 1 - i]), 6 )); - } - - return; -} - -void Smoothing_vector_scaledown_NB_fx( - const Word16 OldauOutnoWin_fx[], /* i : Input vector 1 */ - const Word16 ImdctOutWin_fx[], /* i : Input vector 2 */ - const Word16 SmoothingWin_fx[], /* i : Smoothing window */ - Word16 auOut_fx[], /* o : Output vector that contains vector 1 .* vector 2 */ - const Word16 ol_size /* i : Overlap size */ - -) -{ - Word16 i; - Word16 weight_fx; - - FOR (i=0 ; i < ol_size; i++) - { - weight_fx = SmoothingWin_fx[i]; - move16(); - auOut_fx[i] = add(mult(OldauOutnoWin_fx[i], sub(32767, weight_fx)), - mult(ImdctOutWin_fx[i], mult_r(23170, weight_fx))); - move16(); - } - - return; -} - - -void Scaledown_fx( - Word16 x[], /* i : Input vector */ - Word16 y[], /* o : Output vector that contains vector 1 .* vector 2 */ - Word16 scale_v, /*Q15 */ - const Word16 N /* i : Overlap size */ -) -{ - Word16 i; - - FOR (i=0; iQ_old_wtda != 0) - { - Scale_sig(st_fx->old_out_fx, output_frame, negate(st_fx->Q_old_wtda)); - st_fx->Q_old_wtda = 0; - move16(); - } - - test(); - test(); - test(); - test(); - test(); - test(); - IF( (sub(st_fx->nbLostCmpt, 1) == 0)&&(sub(st_fx->phase_mat_flag_fx, 1) == 0)&&(sub(st_fx->phase_mat_next_fx, 0) == 0) ) - { - IF (FEC_phase_matching_fx(st_fx, wtda_audio_fx, out_fx, st_fx->old_out_fx, st_fx->old_out_pha_fx) ) - { - /* window_ola( wtda_audio, out, st->old_out, output_frame, 0, 0, 0 ); */ - window_ola_fx(wtda_audio_fx, out_fx, Q_synth, st_fx->old_out_fx, &st_fx->Q_old_wtda, output_frame, ALDO_WINDOW, ALDO_WINDOW, 0, 0, 0 ); - st_fx->phase_mat_next_fx = 0; - move16(); - } - ELSE - { - st_fx->phase_mat_next_fx = 1; - move16(); - *Q_synth = 0; - move16(); - } - } - ELSE IF((sub(st_fx->prev_bfi_fx, 1) == 0)&&(st_fx->bfi_fx == 0) &&(sub(st_fx->phase_mat_next_fx, 1) == 0)) - { - FEC_phase_matching_nextgood_fx( wtda_audio_fx, out_fx, st_fx->old_out_fx, st_fx->old_out_pha_fx, mean_en_high_fx); - - st_fx->phase_mat_next_fx = 0; - move16(); - *Q_synth = 0; - move16(); - } - ELSE IF((sub(st_fx->prev_bfi_fx, 1) == 0)&&(sub(st_fx->bfi_fx, 1) == 0) &&(sub(st_fx->phase_mat_next_fx, 1) == 0)) - { - FEC_phase_matching_burst_fx( wtda_audio_fx, out_fx, st_fx->old_out_fx, st_fx->old_out_pha_fx, st_fx->prev_oldauOut_fx); - st_fx->phase_mat_next_fx = 1; - move16(); - *Q_synth = 0; - move16(); - } - ELSE - { - /*n4 = (short)(N_LEAD_MDCT*(float)(output_frame/20));*/ - test(); - IF (st_fx->bfi_fx == 0 && sub(st_fx->prev_bfi_fx, 1) == 0) - { - test(); - IF((sub(st_fx->stat_mode_out_fx, 1) == 0) || (sub(st_fx->diff_energy_fx, ED_THRES_50P_fx) < 0))/* Q11 */ - { - Word16 tmp; - - tmp = 0; - if( sub(st_fx->old_bfi_cnt_fx,1) > 0 ) - { - tmp = 1; - } - Repetition_smoothing_nextgood_fx( wtda_audio_fx, out_fx, st_fx->oldIMDCTout_fx, st_fx->old_out_fx, tmp, N_LEAD_NB); - *Q_synth = 0; - move16(); - } - ELSE IF(sub(st_fx->old_bfi_cnt_fx, 1) > 0) - { - Next_good_after_burst_erasures_fx( wtda_audio_fx, out_fx, st_fx->old_out_fx, N_LEAD_NB ); - *Q_synth = 0; - move16(); - } - ELSE - { - /*window_ola( wtda_audio, out, st->old_out, output_frame, 0, 0, 0); */ - window_ola_fx( wtda_audio_fx, out_fx, Q_synth, st_fx->old_out_fx, &st_fx->Q_old_wtda, output_frame, - st_fx->tcx_cfg.tcx_last_overlap_mode, st_fx->tcx_cfg.tcx_curr_overlap_mode, st_fx->prev_bfi_fx, st_fx->oldHqVoicing_fx , st_fx->oldgapsynth_fx ); - } - } - ELSE /* if(st->bfi_fx == 1) */ - { - test(); - IF( (sub(st_fx->stat_mode_out_fx, 1) == 0) || (sub(st_fx->diff_energy_fx, ED_THRES_50P_fx) < 0 )) - { - /* if( window_ola_bfi( wtda_audio, out, st->oldIMDCTout, st->old_out, output_frame, st->prev_oldauOut, N_LEAD_NB) ) */ - IF( Repetition_smoothing_fx( wtda_audio_fx, out_fx, st_fx->oldIMDCTout_fx, st_fx->old_out_fx, output_frame, st_fx->prev_oldauOut_fx, N_LEAD_NB) ) - { - /*window_ola( wtda_audio, out, st->old_out, output_frame, 0, 0, 0);*/ - window_ola_fx( wtda_audio_fx, out_fx, Q_synth, st_fx->old_out_fx, &st_fx->Q_old_wtda, output_frame, - st_fx->tcx_cfg.tcx_last_overlap_mode, st_fx->tcx_cfg.tcx_curr_overlap_mode, st_fx->prev_bfi_fx, st_fx->oldHqVoicing_fx , st_fx->oldgapsynth_fx ); - } - ELSE - { - *Q_synth = 0; - move16(); - } - } - ELSE - { - /*window_ola( wtda_audio, out, st->old_out, output_frame, 0, 0, 0 );*/ - window_ola_fx( wtda_audio_fx, out_fx, Q_synth, st_fx->old_out_fx, &st_fx->Q_old_wtda, output_frame, - st_fx->tcx_cfg.tcx_last_overlap_mode, st_fx->tcx_cfg.tcx_curr_overlap_mode, st_fx->prev_bfi_fx, st_fx->oldHqVoicing_fx , st_fx->oldgapsynth_fx ); - } - } - st_fx->phase_mat_next_fx = 0; - move16(); - } - - return; -} - -void Next_good_after_burst_erasures_fx( - const Word32 *ImdctOut_fx, - Word16 *auOut_fx, - Word16 *OldauOut_fx, - const Word16 ol_size -) -{ - Word16 i, L; - Word16 ImdctOutWin_fx[2*L_FRAME48k]; - Word16 win_NB_fx[L_FRAME8k + 25]; - - L = L_FRAME8k; - move16(); - FOR (i=0; i +#include "options.h" +#include "rom_dec.h" +#include "rom_com.h" +#include "cnst.h" +#include "prot.h" +#include "assert.h" + + +/*---------------------------------------------------------------------* + * Local constants + *---------------------------------------------------------------------*/ + +#define FEC_MAX 512 +#define FEC_NB_PULSE_MAX 20 +#define FEC_FFT_MAX_SIZE 512 +#define FEC_DCIM_FILT_SIZE_MAX 60 + +#define PHASE_DITH (PI2) + +#define DELTA_CORR 6 /* Range for phase correction around peak */ +#define THRESH_TR_dB 10.0f +#define THRESH_TR_LIN (float)pow(10.0f,THRESH_TR_dB/10.0f) +#define THRESH_TR_LIN_INV (float)pow(10.0f,-THRESH_TR_dB/10.0f) +#define MAX_INCREASE_GRPOW 0.0f /* maximum amplification in case of transients */ +#define MAX_INCREASE_GRPOW_LIN (float)pow(10.0f,MAX_INCREASE_GRPOW/10.0f) + +#define PHASE_DITH_SCALE (float)pow(2.0,-16.0) /* for scaling random short values to +/- pi */ + +#define BURST_PHDITH_THRESH (4-1) /* speech start phase dither with losses in a row */ +#define BURST_PHDITH_RAMPUP_LEN 2 /* speech ramp up degree of phase dither over a length of frames */ +#define BURST_ATT_THRESH (3-1) /* speech start attenuate with losses in a row */ +#define ATT_PER_FRAME 4 /* speech attenuation in dB */ +#define BETA_MUTE_THR 10 /* time threshold to start beta-noise attenuation */ +#define BETA_MUTE_FAC 0.5f /* attenuation factor per additional bad frame */ + +#define LGW32k 7 +#define LGW16k 6 +#define LGW48k LGW32k+1 /* Use the same frequency groups as for SWB + 1 */ + +#define L_TRANA_LOG32k 8 +#define L_TRANA_LOG16k 7 + +#define PFIND_SENS 0.97f /* peakfinder sensitivity */ + +/*---------------------------------------------------------------------* + * Local function + *---------------------------------------------------------------------*/ + +short rand_phase( const short seed, float *sin_F, float *cos_F ); + + +/*-------------------------------------------------------------------* + * mult_rev2() + * + * Multiplication of two vectors second vector is multiplied in reverse order + *-------------------------------------------------------------------*/ + +static void mult_rev2( + const float x1[], /* i : Input vector 1 */ + const float x2[], /* i : Input vector 2 */ + float y[], /* o : Output vector that contains vector 1 .* vector 2 */ + const short N /* i : Vector length */ +) +{ + short i,j ; + + for (i=0,j=N-1 ; i square magnitude spectrum */ + const short N /* i : Vector lenght */ +) +{ + short i, j; + + for (i = 1, j = N-1; i < N/2; i++, j--) + { + x[i] = x[i]*x[i] + x[j]*x[j]; + } + + x[0] *= x[0]; + x[N/2] *= x[N/2]; + + return; +} + +/*------------------------------------------------------------------* + * rand_phase() + * + * randomized phase in form of sin and cos components + *------------------------------------------------------------------*/ + +short rand_phase( + const short seed, + float *sin_F, + float *cos_F +) +{ + const float *sincos = sincos_t_ext + 128; + short seed2 = seed; + own_random(&seed2); + + if (seed2 & 0x40) + { + *sin_F = sincos[seed2 >> 8]; + } + else + { + *sin_F = -sincos[seed2 >> 8]; + } + + if (seed2 & 0x80) + { + *cos_F = sincos[-(seed2 >> 8)]; + } + else + { + *cos_F = -sincos[-(seed2 >> 8)]; + } + + return seed2; +} + +/*------------------------------------------------------------------* + * trans_ana() + * + * Transient analysis + *------------------------------------------------------------------*/ + +static void trans_ana( + const float *xfp, /* i : Input signal */ + float *mag_chg, /* i/o: Magnitude modification */ + float *ph_dith, /* i/o: Phase dither */ + float *mag_chg_1st, /* i/o: per band magnitude modifier for transients */ + const short output_frame, /* i : Frame length */ + const short time_offs, /* i : Time offset */ + const float est_mus_content, /* i : 0.0=speech_like ... 1.0=Music (==st->env_stab ) */ + const short last_fec, /* i : signal that previous frame was concealed with fec_alg*/ + float *alpha, /* o : Magnitude modification factors for fade to average */ + float *beta, /* o : Magnitude modification factors for fade to average */ + float *beta_mute, /* o : Factor for long-term mute */ + float Xavg[LGW_MAX] /* o : Frequency group average gain to fade to */ +) +{ + const float *w_hamm; + float grp_pow_chg, att_val, att_degree; + float xfp_left[L_TRANA48k], xfp_right[L_TRANA48k]; + float gr_pow_left[LGW_MAX], gr_pow_right[LGW_MAX]; + const float *xfp_; + short Ltrana, Ltrana_2, Lprot, LtranaLog = 0, Lgw, k, burst_len; + short att_always[LGW_MAX]; /* fixed attenuation per frequency group if set to 1*/ + short burst_phdith_thresh = BURST_PHDITH_THRESH; /* speech settings */ + short burst_att_thresh = BURST_ATT_THRESH ; + float att_per_frame = ATT_PER_FRAME; + short burst_phdith_rampup_len = BURST_PHDITH_RAMPUP_LEN; + short tr_dec[LGW_MAX]; + + /* check burst error */ + burst_len = time_offs/output_frame + 1; + + set_s(att_always,0,LGW_MAX); + *ph_dith = 0.0f; + + /* softly shift attenuation just a bit later for estimated "stable" music_content */ + burst_phdith_thresh = BURST_PHDITH_THRESH+(short)(est_mus_content*1.0f + 0.5f); + burst_att_thresh = BURST_ATT_THRESH + (short)(est_mus_content*1.0f + 0.5f); + att_per_frame = ATT_PER_FRAME - (short)(est_mus_content*1.0f + 0.5f); /* only slighty less att for music */ + att_per_frame *=0.1f; + + if ( burst_len > burst_phdith_thresh ) + { + /* increase degree of dither */ + *ph_dith = PHASE_DITH * min(1.0f,((float)burst_len - (float)burst_phdith_thresh)/(float)burst_phdith_rampup_len); + } + + att_degree = 0; + if (burst_len > burst_att_thresh) + { + set_s(att_always,1,LGW_MAX); + + /* increase degree of attenuation */ + if( burst_len - burst_att_thresh <= PH_ECU_MUTE_START ) + { + att_degree = (float)(burst_len - burst_att_thresh) * att_per_frame; + } + else + { + att_degree = (float) PH_ECU_MUTE_START * att_per_frame + (burst_len - burst_att_thresh - PH_ECU_MUTE_START) * 6.0206f; + } + } + + Lprot = ( 2* output_frame * 4)/ 5; /* 4/5==1024/1280, keep mult within short */ + Ltrana = Lprot/QUOT_LPR_LTR; + Ltrana_2 = Ltrana/2; + + if (output_frame == L_FRAME48k) + { + w_hamm = w_hamm48k_2; + Lgw = LGW48k; + } + else if (output_frame == L_FRAME32k) + { + w_hamm = w_hamm32k_2; + LtranaLog = L_TRANA_LOG32k; + Lgw = LGW32k; + } + else + { + w_hamm = w_hamm16k_2; + LtranaLog = L_TRANA_LOG16k; + Lgw = LGW16k; + } + + if (burst_len <= 1 || (burst_len == 2 && last_fec) ) + { + set_f(alpha,1.0f,LGW_MAX); + set_f(beta,0.0f,LGW_MAX); + *beta_mute = BETA_MUTE_FAC_INI; + + /* apply hamming window */ + v_mult( xfp, w_hamm, xfp_left, Ltrana_2 ); + mult_rev2( xfp+Ltrana_2, w_hamm, xfp_left+Ltrana_2, Ltrana_2 ); + + xfp_ = xfp + Lprot - Ltrana; + v_mult( xfp_, w_hamm, xfp_right, Ltrana_2 ); + mult_rev2( xfp_+Ltrana_2, w_hamm, xfp_right+Ltrana_2, Ltrana_2 ); + + /* spectrum */ + if (output_frame == L_FRAME48k) + { + fft3(xfp_left,xfp_left,Ltrana); + fft3(xfp_right,xfp_right,Ltrana); + } + else + { + fft_rel(xfp_left,Ltrana,LtranaLog); + fft_rel(xfp_right,Ltrana,LtranaLog); + } + + /* square representation */ + fft_spec2(xfp_left,Ltrana); + fft_spec2(xfp_right,Ltrana); + + /* band powers in frequency groups + exclude bin at 0 and at EVS_PI from calculation */ + xfp_left[Ltrana_2] = 0.0f; + xfp_right[Ltrana_2] = 0.0f; + } + + for ( k = 0; k < Lgw; k++ ) + { + if (burst_len <= 1 || (burst_len == 2 && last_fec) ) + { + gr_pow_left[k] = sum_f(xfp_left +gw[k],gw[k+1]-gw[k]); + gr_pow_right[k] = sum_f(xfp_right+gw[k],gw[k+1]-gw[k]); + + /* check if transient in any of the bands */ + gr_pow_left[k] += FLT_MIN; /* otherwise div by zero may occur */ + gr_pow_right[k] += FLT_MIN; + + Xavg[k] = sqrt(0.5f*(gr_pow_left[k]+gr_pow_right[k])/(float)(gw[k+1]-gw[k])); + + grp_pow_chg = gr_pow_right[k] / gr_pow_left[k]; + + /* dither phase in case of transient */ + /* separate transition detection and application of forced burst dithering */ + tr_dec[k] = (grp_pow_chg > THRESH_TR_LIN) || (grp_pow_chg < THRESH_TR_LIN_INV); + + /* magnitude modification */ + if ( tr_dec[k] || att_always[k]) + { + att_val = min(MAX_INCREASE_GRPOW_LIN,grp_pow_chg); + att_val = (float)sqrt(att_val); + mag_chg_1st[k] = att_val; + mag_chg[k] = att_val; + } + else + { + mag_chg_1st[k] = 1.0f; + mag_chg[k] = 1.0f; + } + } + else + { + if( burst_len < OFF_FRAMES_LIMIT ) + { + mag_chg[k] = mag_chg_1st[k] * (float)pow(10.0,-att_degree/20.0); + } + else + { + mag_chg[k] = 0; + } + if (burst_len > BETA_MUTE_THR) + { + *beta_mute *= BETA_MUTE_FAC; + } + alpha[k] = mag_chg[k]; + beta[k] = sqrt(1.0f - SQR(alpha[k])) **beta_mute; + if (k>=LGW32k-1) + { + beta[k] *=0.1f; + } + else if (k>=LGW16k-1) + { + beta[k] *=0.5f; + } + } + } + + return; +} + +/*------------------------------------------------------------------* + * peakfinder() + * + * Peak-picking algorithm + *------------------------------------------------------------------*/ + +static void peakfinder( + const float *x0, /* i : vector from which the maxima will be found */ + const short len0, /* i : length of input vector */ + short *plocs, /* o : the indicies of the identified peaks in x0 */ + short *cInd, /* o : number of identified peaks */ + const float sel /* i : The amount above surrounding data for a peak to be identified */ +) +{ + float minMag, tempMag, leftMin; + float dx0[L_PROT48k_2], x[L_PROT48k_2+1], peakMag[MAX_PLOCS]; + short k, i, len, tempLoc = 0, foundPeak, ii, xInd; + short *ind, indarr[L_PROT48k_2+1], peakLoc[MAX_PLOCS]; + + ind = indarr; + + /* Find derivative */ + v_sub(x0+1,x0,dx0,len0-1); + + /* This is so we find the first of repeated values */ + for (i=0; i 2) + { + /* Set initial parameters for loop */ + tempMag = minMag; + foundPeak = 0; + leftMin = minMag; + + /* Deal with first point a little differently since tacked it on + Calculate the sign of the derivative since we taked the first point + on it does not necessarily alternate like the rest. */ + + /* The first point is larger or equal to the second */ + if (x[0] >= x[1]) + { + ii = -1; + if (x[1] >= x[2]) /* x[1] is not extremum -> overwrite with x[0] */ + { + x[1] = x[0]; + ind[1] = ind[0]; + ind++; + len--; + } + } + else /* First point is smaller than the second */ + { + ii = 0; + if (x[1] < x[2]) /* x[1] is not extremum -> overwrite with x[0] */ + { + x[1] = x[0]; + ind[1] = ind[0]; + ind++; + len--; + } + } + + *cInd = 0; + + /* Loop through extrema which should be peaks and then valleys */ + while (ii < len-1) + { + ii++; /* This is a peak */ + + /*Reset peak finding if we had a peak and the next peak is bigger + than the last or the left min was small enough to reset.*/ + if (foundPeak) + { + tempMag = minMag; + foundPeak = 0; + } + + /* Make sure we don't iterate past the length of our vector */ + if (ii == len-1) + { + break; /* We assign the last point differently out of the loop */ + } + + /* Found new peak that was larger than temp mag and selectivity larger + than the minimum to its left. */ + if ((x[ii] > tempMag) && (x[ii] > leftMin + sel)) + { + tempLoc = ii; + tempMag = x[ii]; + } + + ii++; /* Move onto the valley */ + + /* Come down at least sel from peak */ + if (!foundPeak && (tempMag > sel + x[ii])) + { + foundPeak = 1; /* We have found a peak */ + leftMin = x[ii]; + peakLoc[*cInd] = tempLoc; /* Add peak to index */ + peakMag[*cInd] = tempMag; + (*cInd)++; + } + else if (x[ii] < leftMin) /* New left minimum */ + { + leftMin = x[ii]; + } + } + + /* Check end point */ + if (x[len-1] > tempMag && x[len-1] > leftMin + sel) + { + peakLoc[*cInd] = len-1; + peakMag[*cInd] = x[len-1]; + (*cInd)++; + } + else if (!foundPeak && tempMag > minMag) /* Check if we still need to add the last point */ + { + peakLoc[*cInd] = tempLoc; + peakMag[*cInd] = tempMag; + (*cInd)++; + } + + /* Create output */ + for (i=0; i<*cInd; i++) + { + plocs[i] = ind[peakLoc[i]]; + } + } + else /* This is a monotone function where an endpoint is the only peak */ + { + xInd = (x[0] > x[1]) ? 0 : 1; + peakMag[0] = x[xInd]; + if (peakMag[0] > minMag + sel) + { + plocs[0] = ind[xInd]; + *cInd=1; + } + else + { + *cInd=0; + } + } + + return; +} + +/*-------------------------------------------------------------------* + * imax() + * + * Get interpolated maximum position + *-------------------------------------------------------------------*/ + +static float imax(const float *y) +{ + float posi, y1, y2,y3,y3_y1,y2i; + /* Seek the extrema of the parabola P(x) defined by 3 consecutive points so that P([-1 0 1]) = [y1 y2 y3] */ + float ftmp_den1,ftmp_den2; + y1 = y[0]; + y2 = y[1]; + y3 = y[2]; + y3_y1 = y3-y1; + ftmp_den1 = (y1+y3-2*y2); + ftmp_den2 = (4*y2 - 2*y1 - 2*y3); + + if( ftmp_den2==0.0f || ftmp_den1==0.0f ) + { + return (0.0f); /* early exit with left-most value */ + } + + y2i = -0.125f * SQR(y3_y1) /(ftmp_den1) + y2; + /* their corresponding normalized locations */ + posi = y3_y1/(ftmp_den2); + + /* Interpolated maxima if locations are not within [-1,1], calculated extrema are ignored */ + if (posi >= 1.0f || posi <= -1.0f) + { + posi = y3 > y1 ? 1.0f : -1.0f; + } + else + { + if (y1 >= y2i) + { + posi = (y1 > y3) ? -1.0f : 1.0f; + } + else if (y3 >= y2i) + { + posi = 1.0f; + } + } + + return posi + 1.0f; +} + + +/*-------------------------------------------------------------------* + * spec_ana() + * + * Spectral analysis + *-------------------------------------------------------------------*/ + +static void spec_ana( + const float *prevsynth, /* i : Input signal */ + short *plocs, /* o : The indicies of the identified peaks */ + float *plocsi, /* o : Interpolated positions of the identified peaks */ + short *num_plocs, /* o : Number of identified peaks */ + float *X_sav, /* o : Stored fft spectrum */ + const short output_frame, /* i : Frame length */ + const short bwidth /* i : Encoded bandwidth index */ +) +{ + short i, Lprot, LprotLog2=0, hamm_len2=0, Lprot2_1, m; + const float *w_hamm = NULL; + float xfp[L_PROT48k]; + float Xmax, Xmin, sel; + short stop_band_start; + short stop_band_length; + + Lprot = 2*output_frame * L_PROT32k / 1280; + Lprot2_1 = Lprot/2+1; + + if (output_frame == L_FRAME48k) + { + w_hamm = w_hamm_sana48k_2; + hamm_len2 = L_PROT_HAMM_LEN2_48k; + } + else if (output_frame == L_FRAME32k) + { + w_hamm = w_hamm_sana32k_2; + hamm_len2 = L_PROT_HAMM_LEN2_32k; + LprotLog2 = 10; + } + else + { + w_hamm = w_hamm_sana16k_2; + hamm_len2 = L_PROT_HAMM_LEN2_16k; + LprotLog2 = 9; + } + + /* Apply hamming-rect window */ + v_mult(prevsynth,w_hamm,xfp,hamm_len2); + mvr2r(prevsynth+hamm_len2,xfp+hamm_len2,Lprot - 2*hamm_len2); + mult_rev2(prevsynth + Lprot - hamm_len2,w_hamm,xfp + Lprot - hamm_len2,hamm_len2); + + /* Spectrum */ + if (output_frame == L_FRAME48k) + { + fft3(xfp,xfp,Lprot); + } + else + { + fft_rel(xfp,Lprot,LprotLog2); + } + + /* Apply zeroing of non-coded FFT spectrum */ + if (output_frame > inner_frame_tbl[bwidth]) + { + stop_band_start = 128 << bwidth; + stop_band_length = Lprot - (stop_band_start << 1); + stop_band_start = stop_band_start + 1; + set_f( xfp + stop_band_start, 0, stop_band_length ); + } + + mvr2r(xfp,X_sav,Lprot); + + /* Magnitude representation */ + fft_spec2(xfp, Lprot); + + for (i=0; i 0) + { + delta_tmp = (plocs[m] - plocs[m-1] - 1)/2; + if (delta_tmp < DELTA_CORR) + { + delta_corr_dn = delta_tmp; + } + } + + if (m < *num_plocs-1 ) + { + delta_tmp = (plocs[m+1] - plocs[m] - 1)/2; + if ( delta_tmp < DELTA_CORR ) + { + delta_corr_up = delta_tmp; + } + } + + /* Input Xph */ + while ( i < plocs[m]-delta_corr_dn ) + { + *seed = own_random(seed); + + if (*seed & 0x40) + { + sin_F = sincos[*seed >> 8]; + } + else + { + sin_F = -sincos[*seed >> 8]; + } + + if (*seed & 0x80) + { + cos_F = sincos[-(*seed >> 8)]; + } + else + { + cos_F = -sincos[-(*seed >> 8)]; + } + + tmp = (X[i] * cos_F - X[im_ind] * sin_F); + X[im_ind] = (X[i] * sin_F + X[im_ind] * cos_F); + if (alpha[k] < 1.0f) + { + *seed = rand_phase(*seed,&sin_F,&cos_F); + X[i] = alpha[k] * tmp + beta[k] * Xavg[k] * cos_F; + X[im_ind] = alpha[k] * X[im_ind] + beta[k] * Xavg[k] * sin_F; + } + else + { + X[i] = mag_chg[k] * tmp; + X[im_ind] *= mag_chg[k]; + } + i++; + im_ind--; + if (i >= gwlpr[k+1]) + { + k++; + } + } + + e = plocs[m] + delta_corr_up; + if (e > Lprot/2 - 1) + { + e = Lprot/2 - 1; + } + + Xph = corr_phase[m]; + Xph_short = (short)(((long)(Xph * 512/EVS_PI)) % 32768) & 0x03ff; + if (Xph_short >= 512) + { + sin_F = -sincos_t_ext[Xph_short-512]; + if (Xph_short < 768) + { + cos_F = -sincos_t_ext[Xph_short-512+256]; + } + else + { + cos_F = sincos_t_ext[-Xph_short+1024+256]; + } + } + else + { + sin_F = sincos_t_ext[Xph_short]; + if (Xph_short < 256) + { + cos_F = sincos_t_ext[Xph_short+256]; + } + else + { + cos_F = -sincos_t_ext[-Xph_short+256+512]; + } + } + + while ( i <= e ) + { + mag_chg_local = mag_chg[k]; + + if( ph_dith != 0.0f ) + { + /* Call phase randomization only when needed */ + Xph = corr_phase[m]; + *seed = own_random(seed); + Xph += *seed * ph_dith * PHASE_DITH_SCALE; /* where ph_dith is 0..2PI, or -2PI (in transient), bin phase scaling factor from trans_ana */ + + if( ph_dith > 0.0f ) + { + /* up to 6 dB additional att of peaks in non_transient longer bursts, (when peak phase is randomized) */ + /* 0.5~= sqrt((float)pow(10.0,-6/10.0)); ph_dith= 0..2pi,--> scale=1.0 ...5 */ + mag_chg_local *= 0.5f + (1.0f-(1.0f/PHASE_DITH)*ph_dith)*0.5f; + } + + Xph_short = (short)((int)(Xph * 512/EVS_PI) & 0x03ff); + + if (Xph_short >= 512) + { + sin_F = -sincos_t_ext[Xph_short-512]; + if (Xph_short < 768) + { + cos_F = -sincos_t_ext[Xph_short-512+256]; + } + else + { + cos_F = sincos_t_ext[-Xph_short+1024+256]; + } + } + else + { + sin_F = sincos_t_ext[Xph_short]; + if (Xph_short < 256) + { + cos_F = sincos_t_ext[Xph_short+256]; + } + else + { + cos_F = -sincos_t_ext[-Xph_short+256+512]; + } + } + } + + tmp = (X[i] * cos_F - X[im_ind] * sin_F); + X[im_ind] = (X[i] * sin_F + X[im_ind] * cos_F); + if (alpha[k] < 1.0f) + { + float alpha_local = mag_chg_local; + float beta_local = beta_mute * sqrt(1.0f - SQR(alpha_local)); + if (k>=LGW32k-1) + { + beta_local *=0.1f; + } + else if (k>=LGW16k-1) + { + beta_local *=0.5f; + } + + *seed = rand_phase(*seed,&sin_F,&cos_F); + X[i] = alpha_local * tmp + beta_local * Xavg[k] * cos_F; + X[im_ind] = alpha_local * X[im_ind] + beta_local * Xavg[k] * sin_F; + } + else + { + X[i] = mag_chg_local * tmp; + X[im_ind] *= mag_chg_local; + } + + i++; + im_ind--; + if (i >= gwlpr[k+1]) + { + k++; + } + } + } + + while ( i < Lprot/2 ) + { + *seed = own_random(seed); + + if (*seed & 0x40) + { + sin_F = sincos[*seed >> 8]; + } + else + { + sin_F = -sincos[*seed >> 8]; + } + + if (*seed & 0x80) + { + cos_F = sincos[-(*seed >> 8)]; + } + else + { + cos_F = -sincos[-(*seed >> 8)]; + } + + + tmp = (X[i] * cos_F - X[im_ind] * sin_F); + X[im_ind] = (X[i] * sin_F + X[im_ind] * cos_F); + if (alpha[k] < 1.0f) + { + *seed = rand_phase(*seed,&sin_F,&cos_F); + X[i] = alpha[k] * tmp + beta[k] * Xavg[k] * cos_F; + X[im_ind] = alpha[k] * X[im_ind] + beta[k] * Xavg[k] * sin_F; + im_ind--; + } + else + { + X[i] = mag_chg[k] * tmp; + X[im_ind--] *= mag_chg[k]; + } + i++; + + if (i >= gwlpr[k+1]) + { + k++; + } + } + + return; +} + +/*-------------------------------------------------------------------------- + * rec_wtda() + * + * Windowing and TDA of reconstructed frame + *--------------------------------------------------------------------------*/ + +static void rec_wtda( + float *X, /* i : FFT spectrum */ + float *ecu_rec, /* o : Reconstructed frame in tda domain */ + const short output_frame, /* i : Frame length */ + const short Lprot, /* i : Prototype frame length */ + const float fs +) +{ + float old_wtda[L_FRAME48k],xinit[L_FRAME48k],xsubst_[2*L_FRAME48k]; + short timesh; + short xf_len; + short i; + float *p_ecu; + float g; + float tbl_delta; + + /* extract reconstructed frame with aldo window */ + set_f(xsubst_,0.0f,output_frame-Lprot/2); + mvr2r(X,xsubst_+output_frame-Lprot/2,Lprot); + set_f(xsubst_+output_frame+Lprot/2,0.0f,output_frame-Lprot/2); + + /* Smoothen onset of ECU frame */ + xf_len = (short)((float)output_frame*N_ZERO_MDCT_NS/FRAME_SIZE_NS) - (output_frame - Lprot/2); + p_ecu = xsubst_ + (output_frame - Lprot/2); + tbl_delta = 64.0/xf_len; /* 64 samples = 1/4 cycle in sincos_t */ + for ( i = 0; i < xf_len; i++, p_ecu++ ) + { + g = sincos_t[((short)(i * tbl_delta))]; + g *= g; + *p_ecu = g * (*p_ecu); + } + + timesh = NS2SA(fs, 10000000L - PH_ECU_ALDO_OLP2_NS); + set_f( xinit, 0, timesh ); + mvr2r( xsubst_, xinit+timesh, output_frame-timesh ); + + set_f( old_wtda,0,output_frame); + + /* warm up old_wtda */ + wtda( xinit, ecu_rec, old_wtda, ALDO_WINDOW, ALDO_WINDOW, output_frame ); + wtda( xsubst_+output_frame-timesh, ecu_rec, old_wtda, ALDO_WINDOW, ALDO_WINDOW, output_frame ); + + return; +} + + +/*-------------------------------------------------------------------------- + * rec_frame() + * + * Frame reconstruction + *--------------------------------------------------------------------------*/ + +static void rec_frame( + float *X, /* i : FFT spectrum */ + float *ecu_rec, /* o : Reconstructed frame in tda domain */ + const short output_frame /* i : Frame length */ +) +{ + short Lprot, LprotLog2=0; + float fs; + + fs = (float)output_frame*50.0f; + Lprot = 2*output_frame * L_PROT32k / 1280; + + if (output_frame == L_FRAME48k) + { + LprotLog2 = 9; + } + else if (output_frame == L_FRAME32k) + { + LprotLog2 = 10; + } + else + { + LprotLog2 = 9; + } + + /* extend spectrum and IDFT */ + if (output_frame == L_FRAME48k) + { + ifft3( X, X, Lprot ); + } + else + { + ifft_rel( X, Lprot, LprotLog2 ); + } + + rec_wtda( X, ecu_rec, output_frame, Lprot, fs ); + + return; +} + + +/*-------------------------------------------------------------------------- + * fir_dwn() + * + * + *--------------------------------------------------------------------------*/ + +static void fir_dwn( + const float x[], /* i : input vector */ + const float h[], /* i : impulse response of the FIR filter */ + float y[], /* o : output vector (result of filtering) */ + const short L, /* i : input vector size */ + const short K, /* i : order of the FIR filter (K+1 coefs.) */ + const short decimation /* i : decimation */ +) +{ + float s; + short i, j, k, mmax; + + k = 0; + + /* do the filtering */ + for ( i = K/2; i < L; i += decimation ) + { + s = x[i] * h[0]; + + if ( i < K ) + { + mmax = i; + } + else + { + mmax = K; + } + + for ( j = 1; j <= mmax; j++ ) + { + s += h[j] * x[i-j]; + } + + y[k] = s; + k++; + } + + for ( ; i < L+K/2; i += decimation ) + { + s = 0; + + for (j = i-L+1; j <= K; j++) + { + s += h[j] * x[i-j]; + } + + y[k] = s; + k++; + } + + return; +} + + +/*-------------------------------------------------------------------------- + * fec_ecu_pitch() + * + * + *--------------------------------------------------------------------------*/ + +static void fec_ecu_pitch( + const float *prevsynth, + float *prevsynth_LP, + const short L, + short *N, + float *min_corr, + short *decimatefator, + const short HqVoicing +) +{ + short i,filt_size; + float accA,accB,accC,Ryy; + short delay_ind,k,cb_start,cb_end,tmp_short,Lon20; + float Asr_LP[FEC_DCIM_FILT_SIZE_MAX+1]; + + switch(L) + { + case L_FRAME48k: + *decimatefator=6; + filt_size=60; + mvr2r(Asr_LP48,Asr_LP,filt_size+1); + break; + case L_FRAME32k: + *decimatefator=4; + filt_size=40; + mvr2r(Asr_LP32,Asr_LP,filt_size+1); + break; + case L_FRAME16k: + *decimatefator=2; + filt_size=20; + mvr2r(Asr_LP16,Asr_LP,filt_size+1); + break; + default: + *decimatefator=2; + filt_size=40; + mvr2r(Asr_LP16,Asr_LP,filt_size+1); + break; + } + + /* We need to inverse the ALDO window */ + + /* Resampling to work at 8Khz */ + fir_dwn( prevsynth,Asr_LP,prevsynth_LP,2*L,filt_size,*decimatefator ); /* resampling without delay */ + + Lon20=(short) ((L/20)/ *decimatefator); + + /* Correlation analysis */ + *min_corr=0; + accC=0; + for (k = 0; k < 6*Lon20; k++) + { + accC+=prevsynth_LP[34*Lon20+k]*prevsynth_LP[34*Lon20+k]; + } + + if (HqVoicing==1) + { + cb_start=0; + cb_end=33*Lon20; + } + else + { + cb_start=0; + cb_end=28*Lon20; + } + + tmp_short=34*Lon20; + accB=0; + delay_ind=cb_start; + for (i=cb_start; i *min_corr ) + { + *min_corr = Ryy; + delay_ind = i; + } + + if ( HqVoicing == 0 && *min_corr > 0.95f ) + { + break; + } + } + + *N = 40*Lon20-delay_ind-6*Lon20; + + return; +} + + +/*-------------------------------------------------------------------------- + * fec_ecu_dft() + * + * + *--------------------------------------------------------------------------*/ + +static void fec_ecu_dft( + const float *prevsynth_LP, /* i: */ + const short N, /* i: */ + float *Tfr, /* o: */ + float *Tfi, /* o: */ + float *sum_Tf_abs, /* o: */ + float *Tf_abs, /* o: */ + short *Nfft /* o: */ +) +{ + float target[2*L_FRAME8k],tmp; + short i, Lon20,tmp_short,N_LP,k; + + Lon20 = (short)160/20; + + for (i=0; iLon20*10 || HqVoicing ) + { + PL=1; + } + while(cpt<=N/2-1-2) + { + if(Tf_abs[cpt]>old && Tf_abs[cpt]>new_s) + { + glued=cpt; + + for (i=glued; immax) + { + mmax=Tf_abs[pulses[k]]; + indmax=pulses[k]; + } + } + cumsum += Tf_abs[indmax]; + + if (HqVoicing || cumsumtime_offs */ + *time_offs = 32767 ; /* continued muting will ensure that the now fixed seeds are not creating tones */ + } + + trans_ana( prevsynth + 2*output_frame-Lprot, mag_chg, &ph_dith, mag_chg_1st, + output_frame, *time_offs, env_stab, 0, alpha, beta, beta_mute, Xavg ); /* 1.0 stable-music, 0.0 speech-like */ + } + + mvr2r( X_sav, X, Lprot ); + + /* seed for own_rand2 */ + seed = *time_offs; + if (*num_p > 0) + { + seed += plocs[*num_p-1]; + } + + subst_spec( plocs, plocsi, num_p, *time_offs, X, mag_chg, ph_dith, old_is_transient, output_frame, &seed, alpha, beta, *beta_mute, Xavg ); + + /* reconstructed frame in tda domain */ + rec_frame( X, ecu_rec, output_frame ); + + return; +} + + +/*-------------------------------------------------------------------------- + * hq_ecu() + * + * Main routine for HQ ECU + *--------------------------------------------------------------------------*/ + +void hq_ecu( + const float *prevsynth, /* i : buffer of previously synthesized signal */ + float *ecu_rec, /* o : reconstructed frame in tda domain */ + short *time_offs, /* i/o: Sample offset for consecutive frame losses*/ + float *X_sav, /* i/o: Stored spectrum of prototype frame */ + short *num_p, /* i/o: Number of identified peaks */ + short *plocs, /* i/o: Peak locations */ + float *plocsi, /* i/o: Interpolated peak locations */ + const float env_stab, /* i : Envelope stability parameter */ + short *last_fec, /* i/o: Flag for usage of pitch dependent ECU */ + const short ph_ecu_HqVoicing, /* i : HQ Voicing flag */ + short *ph_ecu_active, /* i : Phase ECU active flag */ + float *gapsynth, /* o : Gap synthesis */ + const short prev_bfi, /* i : indicating burst frame error */ + const short old_is_transient[2], /* i : flags indicating previous transient frames*/ + float *mag_chg_1st, /* i/o: per band magnitude modifier for transients*/ + float Xavg[LGW_MAX], /* i/o: Frequency group average gain to fade to */ + float *beta_mute, /* o : Factor for long-term mute */ + const short output_frame, /* i : frame length */ + Decoder_State *st /* i/o: decoder state structure */ +) +{ + short N; + float corr = 0.0f; + short decimatefactor; + float prevsynth_LP[2*L_FRAME8k]; + + /* find pitch and R value */ + if (!(output_frame < L_FRAME16k) ) + { + fec_ecu_pitch( prevsynth+NS2SA(output_frame*50,ACELP_LOOK_NS/2-PH_ECU_LOOKAHEAD_NS), prevsynth_LP, output_frame, &N, &corr, &decimatefactor, ph_ecu_HqVoicing ); + } + else + { + corr = 0.0f; + decimatefactor=4; + N=output_frame/4; + } + + if ((st->total_brate >= 48000 && ( output_frame >= L_FRAME16k && !prev_bfi && (!old_is_transient[0] || old_is_transient[1] ) && + (ph_ecu_HqVoicing || ( ((st->env_stab_plc > 0.5) && ( corr < 0.6)) || (st->env_stab_plc < 0.5 && (corr > 0.85 )))))) || + (st->total_brate < 48000 && ( ( ph_ecu_HqVoicing || corr > 0.85 ) && !prev_bfi && (!old_is_transient[0] || old_is_transient[1]) )) ) + { + fec_alg( prevsynth+NS2SA(output_frame*50,ACELP_LOOK_NS/2-PH_ECU_LOOKAHEAD_NS), prevsynth_LP, ecu_rec, output_frame, N, decimatefactor, ph_ecu_HqVoicing, gapsynth, &st->ni_seed_forfec ); + *last_fec = 1; + *ph_ecu_active = 0; + *time_offs = output_frame; + } + else + { + hq_phase_ecu( prevsynth, ecu_rec, time_offs, X_sav, num_p, plocs, plocsi, env_stab, last_fec, + prev_bfi, old_is_transient, mag_chg_1st, Xavg, beta_mute, st->bwidth, output_frame ); + + *last_fec = 0; + *ph_ecu_active = 1; + } + + return; +} diff --git a/src/libs/libevs/lib_dec/FEC_HQ_phase_ecu_fx.cpp b/src/libs/libevs/lib_dec/FEC_HQ_phase_ecu_fx.cpp deleted file mode 100755 index 349fab68..00000000 --- a/src/libs/libevs/lib_dec/FEC_HQ_phase_ecu_fx.cpp +++ /dev/null @@ -1,2800 +0,0 @@ -/*==================================================================================== - EVS Codec 3GPP TS26.442 Apr 03, 2018. Version 12.11.0 / 13.6.0 / 14.2.0 - ====================================================================================*/ - -#include "options.h" /* Compilation switches */ -#include "rom_dec_fx.h" /* Static table prototypes */ -#include "rom_com_fx.h" /* Static table prototypes */ -#include "prot_fx.h" -#include "stl.h" -#include "basop_util.h" - -/*---------------------------------------------------------------------* - * Local constants - *---------------------------------------------------------------------*/ - -#define FEC_MAX 512 -#define FEC_NB_PULSE_MAX 20 -#define FEC_FFT_MAX_SIZE 512 -#define FEC_DCIM_FILT_SIZE_MAX 60 - -#define ENV_STAB_DEC_THR 16384 /* Q15 st->env_stab based threshold for hq-ecu technology decision */ - -#define PHASE_DITH_fx 25736 /* 2*pi in Q12 */ -#define DELTA_CORR 6 /* Tuning parameter - defining range for phase correction around peak */ -#define THRESH_TR_DB_FX 10 -#define THRESH_TR_LIN_BY2_FX (10/2) /* 10.0^(THRESH_TR_DB_FX/10.0)/2. Divided by 2 to facilitate fixed-point implementation. */ -#define MAX_INCREASE_GRPPOW_FX 0 /* max. amplification in case of transients (in dB scale) */ -#define MAX_INCREASE_GRPPOW_LIN_FX 32767 /* in Q15-- 10.0^(MAX_INCREASE_GRPPOW_FX/10.0) (in linear scale) */ - -#define PHASE_DITH_SCALE_SHIFT 16 /* The number of bit shift equivalent to multiply by PHASE_DITH_SCALE */ - -#define BURST_PHDITH_THRESH (4-1) /* speech start phase dither with losses in a row */ -#define BURST_PHDITH_RAMPUP_LEN 2 /* speech ramp up degree of phase dither over a length of frames */ -#define BURST_ATT_THRESH (3-1) /* speech start attenuate with losses in a row */ -#define ATT_PER_FRAME 4 /* speech attenuation in dB */ -#define BETA_MUTE_THR 10 /* time threshold to start beta-noise attenuation */ - -#define LGW32K 7 -#define LGW16K 6 -#define LGW48K LGW32K+1 /* Use the same frequency groups as for SWB + 1 */ - -#define LTRANALOG32K 8 -#define LTRANALOG16K 7 -#define PFIND_SENS_FX 31785 /* 0.97 in Q15 */ -#define CMPLMNT_PFIND_SENS_FX 983 /* (1.0 - pfind_sen) in Q15 */ - -#define FEC_HQ_ECU_POINT5 (0x4000) /* 0.5 in Q15. Prefix with FEC_HQ namespace to avoid naming conflict. */ -#define FEC_HQ_ECU_ROOT2 (0x5a83) /* sqrt(2) in Q14 */ -#define FEC_HQ_HAMM_A0 17695 /* 0.54 in Q15 */ -#define FEC_HQ_HAMM_A1 15073 /* 0.46 in Q15 */ -#define FEC_HQ_WIN_A0 FEC_HQ_HAMM_A0 -#define FEC_HQ_WIN_A1 FEC_HQ_HAMM_A1 - - -static Word16 sqrt2ndOrder(const Word16); - -static void windowing(const Word16*, Word16*, const Word16*, const Word16, const Word16); -static void windowing_ROM_optimized(const Word16*, Word16*, const Word16, const Word16, const Word16); -static void fft_spec2_fx(const Word16 [], Word32 [], const Word16); -static void trans_ana_fx(const Word16*, Word16*, Word16*, Word16*, const Word16, const Word16, const Word16 - ,const Word16 - ,Word16*, Word16*, Word16*, Word16* - - ); -static void peakfinder_fx(const Word16*, const Word16, Word16*, Word16*, const Word16); -static Word16 imax_fx( const Word16 *, const Word16); -static void spec_ana_fx(const Word16*, Word16*, Word32*, Word16*, Word16*, const Word16, const Word16, Word16*); -static void subst_spec_fx(const Word16*, const Word32*, Word16*, const Word16, Word16*, const Word16*, const Word16, const Word16*, const Word16, Word16* - ,const Word16*, const Word16*, Word16, const Word16* - ); -Word16 rand_phase_fx(const Word16 seed, Word16 *sin_F, Word16 *cos_F); - - -/*------------------------------------------------------------------* - * rand_phase() - * - * randomized phase in form of sin and cos components - *------------------------------------------------------------------*/ -Word16 rand_phase_fx(const Word16 seed, Word16 *sin_F, Word16 *cos_F) -{ - const Word16 *sincos = sincos_t_ext_fx + 128; - Word16 seed2 = own_random2_fx(seed); - Word16 seed2_shift = shr(seed2, 8); - - *sin_F = negate(*(sincos + seed2_shift)); - move16(); - if (s_and(seed2, 0x40) != 0) - { - *sin_F = *(sincos + seed2_shift); - move16(); - } - - *cos_F = negate(*(sincos - seed2_shift)); - move16(); - if (s_and(seed2, 0x80) != 0) - { - *cos_F = *(sincos - seed2_shift); - move16(); - } - - return seed2; -} - -/*----------------------------------------------------------------------------- - * fft_spec2_fx() - * - * Square magnitude of fft spectrum - *----------------------------------------------------------------------------*/ -static void fft_spec2_fx( - const Word16 x[], /* i : Input vector: complex spectrum */ - Word32 xMagSq[], /* o : Magnitude square spectrum */ - const Word16 N /* i : Input vector length */ -) -{ - Word16 i, l; - const Word16 *pRe, *pIm; - Word32 *pMagSq, acc; - - /* Magnitude at 0. */ - pMagSq = &xMagSq[0]; - pRe = &x[0]; - *pMagSq++ = L_mult0(*pRe, *pRe); - pRe++; /* Non-fractional multiply gives subsequent group power accumulation a bit headroom. */ - - /* From 1 to (N/2 - 1). */ - l = sub(shr(N, 1), 1); /* N/2 - 1. */ - pIm = &x[N]; - pIm--; - FOR (i = 0; i < l; i++) - { - acc = L_mult0(*pRe, *pRe); - pRe++; /* Non-fractional mode multiply. */ - *pMagSq++ = L_mac0(acc, *pIm, *pIm); - pIm--; - move32(); - } - - /* The magnitude square at N/2 */ - *pMagSq = L_mult0(*pRe, *pRe); - move32(); - return; -} - -/*----------------------------------------------------------------------------- - * trans_ana_fx() - * - * Transient analysis - *----------------------------------------------------------------------------*/ -static void trans_ana_fx( - const Word16 *xfp, /* i : Input signal Q0 */ - Word16 *mag_chg, /* o : Magnitude modification Q15 */ - Word16 *ph_dith, /* o : Phase dither, 2*PI is not included (Q15, i.e., between 0.0 and 1.0) */ - Word16 *mag_chg_1st, /* i/o: per band magnitude modifier for transients Q15 */ - const Word16 output_frame, /* i : Frame length */ - const Word16 time_offs, /* i : Time offset (integral multiple of output_frame) */ - const Word16 est_mus_content, /* i : 0.0=speech_like ... 1.0=Music (==st->env_stab ) */ - const Word16 last_fec, /* i : signal that previous frame was concealed with fec_alg */ - Word16 *alpha, /* o : Magnitude modification factors for fade to average */ - Word16 *beta, /* o : Magnitude modification factors for fade to average */ - Word16 *beta_mute, /* o : Factor for long-term mute */ - Word16 *Xavg /* o : Frequency group average gain to fade to */ -) -{ - const Word16 *w_hamm, *pFftTbl; - Word16 att_val, attDegreeFrames; - Word16 xfp_left[Ltrana48k], xfp_right[Ltrana48k]; - Word32 magSqLeft[Ltrana48k/2+1], magSqRight[Ltrana48k/2+1]; - Word32 *pLeft, *pRight, *pGrPowLeft, *pGrPowRight; - Word32 gr_pow_left[Lgw_max], gr_pow_right[Lgw_max]; - const Word16 *pXfp, *pGw; - Word16 Ltrana, Ltrana_2, Lprot, three4thLength, LtranaLogMinus1, Lgw, i, k, l, burst_len; - Word16 man, expo; - Word16 att_always = 0; /* fixed attenuation per frequency group if set to 1 */ - Word16 oneOverFrame, roundEstMusContent, tmp16, headroom, lowerEdge; - Word16 burst_phdith_thresh = BURST_PHDITH_THRESH; /*speech settings */ - Word16 burst_att_thresh = BURST_ATT_THRESH ; - Word16 att_per_frame = ATT_PER_FRAME; - Word16 burst_phdith_rampup_len = BURST_PHDITH_RAMPUP_LEN; - Word16 tr_dec[Lgw_max]; - UWord16 lsb; - Word32 acc; - - Lgw = 0; - LtranaLogMinus1 = 0; - pFftTbl = NULL; - - /* Initialisation to prevent warnings */ - oneOverFrame = 102; /* 1/320 in Q15 */ move16(); - w_hamm = w_hamm16k_2_fx; - move16(); - Lprot = 512; - move16(); - - /* check burst error */ - IF (sub(output_frame, L_FRAME48k) == 0) /* output_frame = (sampling frequency)/50 */ - { - oneOverFrame = 34; /* 1/960 in Q15 */ move16(); - w_hamm = w_hamm48k_2_fx; - move16(); - Lgw = LGW48K; - move16(); - Lprot = 1536; /* (2*output_frame)*1024/1280; */ move16(); - } - ELSE IF (sub(output_frame, L_FRAME32k) == 0) - { - oneOverFrame = 51; /* 1/640 in Q15 */ move16(); - w_hamm = w_hamm32k_2_fx; - move16(); - Lgw = LGW32K; - move16(); - Lprot = 1024; - move16(); - pFftTbl = FFT_W128; /* Table for 256 real input radix-2 FFT */ move16(); - LtranaLogMinus1 = LTRANALOG32K - 1; - move16(); - } - ELSE - { - oneOverFrame = 102; /* 1/320 in Q15 */ move16(); - w_hamm = w_hamm16k_2_fx; - move16(); - Lgw = LGW16K; - move16(); - Lprot = 512; - move16(); - pFftTbl = FFT_W64; /* Table for 128 real input radix-2 FFT */ move16(); - LtranaLogMinus1 = LTRANALOG16K - 1; - move16(); - } - burst_len = add(mult_r(time_offs, oneOverFrame), 1); - - *ph_dith = 0; - move16(); /* typical pattern is 2*pi*[0 0 .25 .50 .75 1.0 1.0 1.0 ..] */ - - IF (sub(output_frame, L_FRAME32k) >= 0) /*currently est_mus_content only calculated for SWB and FB */ - { - roundEstMusContent = 0; - move16(); - if (sub(est_mus_content, FEC_HQ_ECU_POINT5) >= 0) /* est_mus_content is in [0.0, 1.0]. */ - { - roundEstMusContent = 1; - move16(); - } - - /* softly shift attenuation just a bit later for estimated "stable" music_content */ - burst_phdith_thresh = add(BURST_PHDITH_THRESH, roundEstMusContent); - burst_att_thresh = add(BURST_ATT_THRESH, roundEstMusContent); - att_per_frame = sub(ATT_PER_FRAME, roundEstMusContent); /* only slighty less att for music */ - } - ELSE - { - /* lock to music-like stable envelope setting for now */ - burst_phdith_thresh = add(BURST_PHDITH_THRESH, 1); /* in Q0 */ - burst_att_thresh = add(BURST_ATT_THRESH, 1); /* in Q0 */ - att_per_frame = sub(ATT_PER_FRAME, 1); /* in Q0 */ - } - - IF (sub(burst_len, burst_phdith_thresh) > 0) - { - /* increase degree of dither */ -#if BURST_PHDITH_RAMPUP_LEN != 2 -#error The implementation of phase_dith=min(1.0, (burst_len - burst_phdith_thresh)/burst_phdith_rampup_len)) is incorrect -#endif - *ph_dith = 32767; /* 1.0 in Q15. N.B. 2*PI is not included. */ move16(); - tmp16 = sub(burst_len, burst_phdith_thresh); - if (sub(tmp16, burst_phdith_rampup_len) < 0) - { - *ph_dith = 16384; /* 0.5 in Q15. N.B. 2*PI is not included. */ move16(); - } - } - - attDegreeFrames = 0; - move16(); - IF (sub(burst_len, burst_att_thresh) > 0) - { - att_always = 1; - move16(); - /* increase degree of attenuation */ - - /* N.B. To facilitate the subsequent 10^(-att_degree/20) implementation - * so as to use direct table-lookup, - * (burstLen - burst_att_thresh) is NOT multiplied by "att_per_frame". */ - attDegreeFrames = sub(burst_len, burst_att_thresh); /* Not multiplied by att_per_frqme! */ - /* Furthermore, in order to minimize the size of the lookup-table required to - * implement 10^(-att_degree/10), hard limit attDegreeFrames to (30% of 50)=15. - * If attDegreeFrames is greater than 15, it means there are more than 15 successive - * bad frames. In this case, no matter what to do, the sound quality will be bad. - */ - if (sub(attDegreeFrames, OFF_FRAMES_LIMIT) > 0) - { - attDegreeFrames = OFF_FRAMES_LIMIT; /* Hard limit the no. of frames */ move16(); - } - } - - Ltrana = shr(Lprot, 2); - Ltrana_2 = shr(Ltrana, 1); - - test(); - test(); - IF (sub(burst_len, 1) <= 0 || (sub(burst_len, 2) == 0 && last_fec != 0)) - { - - set16_fx(alpha, 32767, Lgw_max); - set16_fx(beta, 0, Lgw_max); - *beta_mute = BETA_MUTE_FAC_INI; - move16(); - - /* Apply Hamming window */ - windowing(xfp, xfp_left, w_hamm, 0, Ltrana_2); /* 1st quarter */ - three4thLength = sub(Lprot, Ltrana); - pXfp = xfp + three4thLength; - windowing(pXfp, xfp_right, w_hamm, 0, Ltrana_2); /* 4th quarter */ - - /* spectrum */ - IF (sub(output_frame, L_FRAME48k) == 0) - { - fft3_fx(xfp_left, xfp_left, Ltrana); - fft3_fx(xfp_right, xfp_right, Ltrana); - } - ELSE - { - r_fft_fx_lc(pFftTbl, Ltrana, Ltrana_2, LtranaLogMinus1, xfp_left, xfp_left, 1); - r_fft_fx_lc(pFftTbl, Ltrana, Ltrana_2, LtranaLogMinus1, xfp_right, xfp_right, 1); - } - - /* square representation */ - fft_spec2_fx(xfp_left, magSqLeft, Ltrana); - fft_spec2_fx(xfp_right, magSqRight, Ltrana); - - /* band powers in frequency groups - * exclude bin at PI from calculation */ - magSqLeft[Ltrana_2] = L_deposit_l(0); - magSqRight[Ltrana_2] = L_deposit_l(0); - } - - pGrPowLeft = &gr_pow_left[0]; - pGrPowRight = &gr_pow_right[0]; - pGw = gw_fx; - FOR ( k = 0; k < Lgw; k++ ) - { - test(); - test(); - IF (sub(burst_len, 1) <= 0 || (sub(burst_len, 2) == 0 && last_fec != 0)) - { - lowerEdge = *pGw++; - move16(); - l = sub(*pGw, lowerEdge); - headroom = GR_POW_HEADROOM[k]; /* Number of bits to scale down preventing from saturation in accumulation.*/ move16(); - pLeft = magSqLeft + lowerEdge; - pRight = magSqRight + lowerEdge; - *pGrPowLeft = L_deposit_l(0); - *pGrPowRight = L_deposit_l(0); - FOR (i = 0; i < l; i++) - { - acc = L_shr(*pLeft++, headroom); /* Scale down to prevent from saturation. */ - *pGrPowLeft = L_add(*pGrPowLeft, acc); - move32(); - acc = L_shr(*pRight++, headroom); - *pGrPowRight = L_add(*pGrPowRight, acc); - move32(); - } - - /*Xavg[k] = sqrt(0.5f*(gr_pow_left[k]+gr_pow_right[k])/(float)(gw[k+1]-gw[k]));*/ - acc = L_shr(L_add(*pGrPowLeft, *pGrPowRight), 1); - acc = Mult_32_16(acc, gw_len_inv_fx[k]); /* -headroom */ - - acc = Sqrt_l(acc, &expo); /* -headroom+31+expo */ - - expo = sub(add(expo, 31), headroom); - if ( sub(s_and(expo, 1), 1) == 0) - { - acc = Mult_32_16(acc, 23170); /* 1/sqrt(2) in Q15 */ - } - expo = shr(expo, 1); - Xavg[k] = round_fx(L_shl(acc, sub(sub(16, expo), 2))); /* Q0, additional right shift by 2 to account for that Xavg is - calculated using lenght N/4 fft but is applied on a fft of length N */ - - /*dither phase in case of transient */ - /* separate transition detection and application of forced burst dithering */ - tr_dec[k] = 0; - move16(); - Mpy_32_16_ss(*pGrPowLeft, THRESH_TR_LIN_BY2_FX, &acc, &lsb); /* To facilitate fixed-point implementation, divide threshold by 2. */ - acc = L_or(L_shl(acc,16), L_and(0xffffL,lsb)); /* Equivalent to concatenate acc and lsb, and then down shift by 16 bits. */ - if (L_sub(*pGrPowRight, acc) > 0) /* gr_pow_right > thres_tr_lin*gr_pow_left */ - { - tr_dec[k] = 1; - move16(); - } - Mpy_32_16_ss(*pGrPowRight, THRESH_TR_LIN_BY2_FX, &acc, &lsb); - acc = L_or(L_shl(acc,16), L_and(0xffffL,lsb)); /* Equivalent to concatenate acc and lsb, and then down shift by 16 bits. */ - if (L_sub(*pGrPowLeft, acc) > 0) /* gr_pow_left > thres_tr_lin*gr_pow_right */ - { - tr_dec[k] = 1; - move16(); - } - - /* magnitude modification */ - IF ( add(tr_dec[k], att_always) != 0) - { - -#if MAX_INCREASE_GRPPOW_FX != 0 -#error trans_ana_fx-- The following implementation is incorrect -#endif - att_val = 32767; - move16(); - IF (L_sub(*pGrPowRight, 0) > 0) - { - IF (L_sub(*pGrPowRight, *pGrPowLeft) < 0) /* i.e., (gr_pow_right/gr_pow_left) < 1.0 */ - { - /* Compute sqrt(grp_pow_chg), where grp_pow_chg = gr_pow_right/gr_pow_left. */ - tmp16 = ratio(*pGrPowRight, *pGrPowLeft, &expo); /* tmp16 in Q14 */ - expo = sub(expo, (15-14)); /* Now, tmp16 is considered in Q15 */ - i = norm_s(tmp16); - man = shl(tmp16, i); /* Mandatory normalization before sqrtNthOrder(). */ - expo = add(expo, i); - man = sqrt2ndOrder(man); - if (s_and(expo,1) != 0) /* Check even or odd. */ - { - man = mult_r(man,FEC_HQ_ECU_ROOT2); - } - expo = shr(expo, 1); /* Divided by 2-- square root operation. */ - att_val = shr(man, expo); /* Denormalize the mantissa back to Q15. */ - } - /* ELSE do nothing because (gr_pow_right/gr_pow_left) >= 1.0 (i.e., - * max_increase_grppow_lin) */ - } - - mag_chg_1st[k] = att_val; - move16(); - mag_chg[k] = att_val; - move16(); - } - ELSE - { - mag_chg_1st[k] = 32767; - move16(); - mag_chg[k] = 32767; - move16(); /* Set to 1.0 in Q15 */ - } - } - ELSE - { - /* Since attDegreeFrames is discrete (integer) and hard limited to OFF_FRAMES_LIMIT, - * it is much easier to implement 10^(-att_degree/20.0) by a simply direct - * table-lookup. Also, att_per_frame is discrete as well and can be - * either ATT_PER_FRAME-1 or ATT_PER_FRAME and nothing else. This - * means only 2 tables of size=(OFF_FRAMES_LIMIT+1) each are required. - * To take square root into account, it is divided by 20 instead of 10. */ - IF (sub(att_per_frame, ATT_PER_FRAME) == 0) /* Select the corresponding lookup-table. */ - { - att_val = POW_ATT_TABLE0[attDegreeFrames]; /* 10^(-attDegreeFrames*(ATT_PER_FRAME)/20) */ move16(); - } - ELSE - { - att_val = POW_ATT_TABLE1[attDegreeFrames]; /* 10^(-attDegreeFrames*(ATT_PER_FRAME - 1)/20) */ move16(); - } - mag_chg[k] = mult_r(mag_chg_1st[k], att_val); /* Q15 */ - - if (sub(burst_len, BETA_MUTE_THR) > 0) - { - *beta_mute = shr(*beta_mute, 1); - } - alpha[k] = mag_chg[k]; - move16(); - /*beta[k] = sqrt(1.0f - SQR(alpha[k])) * *beta_mute;*/ - acc = L_sub(1073741824, L_mult0(alpha[k], alpha[k])); - acc = Sqrt_l(acc, &expo); - expo = add(30, add(31, expo)); - if (sub(s_and(expo, 1), 1) == 0) - { - acc = Mult_32_16(acc, 23170); /* 1/sqrt(2) in Q15 */ - } - expo = shr(expo, 1); - beta[k] = mult_r(*beta_mute, round_fx(L_shl(acc, sub(31, expo)))); - move16(); - - IF (sub(k, LGW32K-1) >= 0) - { - beta[k] = mult_r(beta[k], 3277); /* 0.1 in Q15 */ - } - ELSE IF (sub(k, LGW16K-1) >= 0) - { - beta[k] = mult_r(beta[k], 16384); /* 0.5 in Q15 */ - } - } - pGrPowLeft++; - pGrPowRight++; - } - - return; -} - -/*----------------------------------------------------------------------------- - * peakfinder_fx() - * - * Peak-picking algorithm - *----------------------------------------------------------------------------*/ -static void peakfinder_fx( - const Word16 *x0, /* i : vector from which the maxima will be found */ - const Word16 len0, /* i : length of input vector */ - Word16 *plocs, /* o : the indices of the identified peaks in x0 Q0 */ - Word16 *cInd, /* o : number of identified peaks Q0 */ - const Word16 sel /* i : The amount above surrounding data for a peak to be identified */ -) -{ - const Word16 *pX0; - Word16 minMag, tempMag, leftMin; - Word16 dx0[Lprot48k_2], x[Lprot48k_2+1], peakMag[MAX_PLOCS]; - Word16 *pDx0, *pDx01, *pX; - Word16 i, len, tempLoc, foundPeak, ii, xInd, tmp16, threshold, xAt0, xAt1, xAt2; - Word16 len0Minus1, len0Minus2, lenMinus1; - Word16 indarr[Lprot48k_2+1], peakLoc[MAX_PLOCS]; - Word16 *pInd; - - tempLoc = 0; - - /* Find derivative */ - len0Minus1 = sub(len0, 1); - pX0 = x0 + 1; - Vr_subt(pX0, x0, dx0, len0Minus1); - - FOR (i=0; i 0) - { - /* Set initial parameters for loop */ - tempMag = minMag; - move16(); - foundPeak = 0; - move16(); - leftMin = minMag; - move16(); - threshold = add(leftMin, sel); - - /* Deal with first point a little differently since tacked it on - Calculate the sign of the derivative since we took the first point - on it does not necessarily alternate like the rest. */ - - /* The first point is larger or equal to the second */ - pX = x; - xAt0 = *pX++; - move16(); - xAt1 = *pX++; - move16(); - xAt2 = *pX--; /* After decrement, pX points to x[1]. */ move16(); - IF (sub(xAt0, xAt1) >= 0) - { - ii = -1; - move16(); - IF (sub(xAt1, xAt2) >= 0) /* x[1] is not extremum -> overwrite with x[0] */ - { - *pX = xAt0; /* x[1] = x[0] */ move16(); - tmp16 = *pInd++; - move16(); - *pInd++ = tmp16; /* ind[1] = ind[0] */ move16(); - len = sub(len, 1); - } - pX--; /* After decrement, pX points to x[0]. */ - } - ELSE /* First point is smaller than the second */ - { - ii = 0; - IF (sub(xAt1, xAt2) < 0) /* x[1] is not extremum -> overwrite with x[0] */ - { - *pX = xAt0; /* x[1] = x[0] */ move16(); - tmp16 = *pInd++; - move16(); - *pInd++ = tmp16; /* ind[1] = ind[0] */ move16(); - len = sub(len, 1); - } - } - pX--; /* After decrement, pX points to either x[-1] or x[0]. */ - - *cInd = 0; - move16(); - /*Loop through extrema which should be peaks and then valleys*/ - lenMinus1 = sub(len, 1); - FOR (;;) - { - ii = add(ii, 1); /* This is a peak */ - - /* Make sure we don't iterate past the length of our vector */ - IF (sub(ii, lenMinus1) >= 0) - { - BREAK; - } - - /*Reset peak finding if we had a peak and the next peak is bigger - than the last or the left min was small enough to reset.*/ - IF (sub(foundPeak,0) > 0) - { - tempMag = minMag; - move16(); - foundPeak = 0; - move16(); - } - - /* Found new peak that was larger than temp mag and selectivity larger - than the minimum to its left. */ - IF (sub(*(++pX), tempMag) > 0) - { - IF ( sub(*pX, threshold) > 0) /* threshold = leftMin + sel */ - { - tempLoc = ii; - move16(); - tempMag = *pX; - move16(); - } - } - - ii = add(ii, 1); /* Move onto the valley */ - pX++; - - /* Come down at least sel from peak */ - IF (foundPeak == 0) - { - IF (sub(tempMag, add(sel, *pX)) > 0) - { - foundPeak = 1; /* We have found a peak */ move16(); - leftMin = *pX; - move16(); - threshold = add(leftMin, sel); - peakLoc[*cInd] = tempLoc; /* Add peak to index */ move16(); - peakMag[*cInd] = tempMag; - move16(); - *cInd = add(*cInd, 1); - } - } - IF (foundPeak == 0) /* The above IF-block has not found the peak yet. */ - { - IF (sub(*pX, leftMin) < 0)/* New left minimum */ - { - leftMin = *pX; - move16(); - threshold = add(leftMin, sel); - } - } - } - - /* Check end point */ - IF (sub(x[lenMinus1], tempMag) > 0) - { - IF (sub(x[lenMinus1], threshold) > 0) /* threshold = leftMin + sel */ - { - peakLoc[*cInd] = lenMinus1; - move16(); - peakMag[*cInd] = x[lenMinus1]; - move16(); - *cInd = add(*cInd, 1); - foundPeak = 1; - move16(); - } - } - IF (foundPeak == 0) /* Check if we still need to add the last point */ - { - IF (sub(tempMag, minMag) > 0) - { - peakLoc[*cInd] = tempLoc; - move16(); - peakMag[*cInd] = tempMag; - move16(); - *cInd = add(*cInd, 1); - } - } - - /* Create output */ - FOR (i = 0; i < *cInd; i++) - { - plocs[i] = *(indarr + peakLoc[i]); - move16(); - move16(); - } - } - ELSE /* This is a monotone function where an endpoint is the only peak */ - { - xInd = 1; - move16(); - if (sub(x[0], x[1]) > 0) - { - xInd = 0; - move16(); - } - - peakMag[0] = x[xInd]; - move16(); - IF (sub(peakMag[0], add(minMag, sel)) > 0) - { - plocs[0] = *(indarr + xInd); - move16(); - *cInd = 1; - move16(); - } - ELSE - { - *cInd = 0; - move16(); - } - } -} - -/*----------------------------------------------------------------------------- -* imax_fx() -* -* Get interpolated maximum position -*-----------------------------------------------------------------------------*/ -static Word16 imax_fx( /* o: The location, relative to the middle of the 3 given data point, of the maximum. (Q15) */ - const Word16 *y, /* i: The 3 given data points. */ - const Word16 special /* i: -1 = left edge special case, 0 = normal, +1 = right edge special case */ -) -{ - Word16 posi; - Word16 y1, y2, y3, man, expo, edge; - const Word16 *pY; - Word32 numer, denom, sign, acc, y3_y1; - - /* Seek the extremum of the parabola P(x) defined by 3 consecutive points - so that P([-1 0 1]) = [y1 y2 y3] */ - pY = y; - y1 = *pY++, y2 = *pY++, y3 = *pY; - move16(); - move16(); - move16(); - - /* The extremum value: - * y2i = -0.125f * SQR(y3_y1) / (y1+y3-2*y2)+y2 - * is not computed. Alternatively, the derivative of the parabola evaluated at y=0, - * dP/dy|y=0, is used to determine whether the extremum is maximum or not. - */ - - /* Compute the extremum location: posi = (y3 - y1)/(4*y2 - 2*y1 - 2*y3). */ - y3_y1 = L_sub(y3, y1); - acc = L_shl(y2,1); /* N.B. y2 is multiplied by 2 not 4. */ - acc = L_sub(acc, y1); /* N.B. Y1 is not multiplied by 2. */ - denom = L_sub(acc, y3); /* N.B. Y3 is not multiplied by 2. */ - sign = L_xor(y3_y1, denom); /* Preserve the sign since div_s() only takes positive arguments. */ - numer = L_abs(y3_y1); - denom = L_abs(denom); - IF (numer == 0) - { - return 0; - } - IF (denom == 0) - { - return 0; - } - /* Although the output of ratio() is in Q14, adding the missing factor of 2 (See above) - * in the denominator, the output is now considered to be in Q15. */ - man = ratio(numer, denom, &expo); /* The mantissa is considered in Q15 */ - posi = shr(man, expo); /* in Q15 (Due to saturation, it is automatically bound inside [-1.0,1.0].) */ - - if (sign < 0) /* Restore the sign. */ - { - posi = negate(posi); - } - - /* For both edges (left and right), the extremum found above may be minimum. - * It needs to reject the minimum. */ - IF (sub(special,0) != 0) /* Either edge specical case. */ - { - edge = 0x7fff; /* 1 in Q15 for the right edge special case */ move16(); - if (sub(special,0) < 0) - { - edge = 0; /* Left edge special case */ move16(); - } - - /* The derivative (slope) of the interpolating parabola = 2*A*y + B, - * where A = (y3 + y1)/2 - y2 - * and B = (y3 - y1)/2. - * Therefore, the slope at y=0 is simply B. Use this slope to determine - * if the parabola is concave upward or downward. - */ - IF (sub(posi,0) > 0) /* The extremum is in between the middle and the right given data points. */ - { - IF (sub(y3, y1) <= 0) /* Check the slope at y=0, i.e., at the middle given data point. */ - { - posi = edge; /* minimum case */ move16(); - } - ELSE - { - posi = sub(0x7fff, posi); /* maximum case */ - } - } - ELSE /* The extremum is in between the left and the middle given data points. */ - { - IF (sub(y3, y1) >= 0) - { - posi = edge; /* minimum case */ move16(); - } - ELSE - { - posi = add(0x7fff, posi); /* maximum case */ - } - } - } - return posi; /* Q15. The position either left or right relative to the index of the middle of the 3 given data points. */ -} - -/*----------------------------------------------------------------------------- -* spec_ana_fx() -* -* Spectral analysis -*-----------------------------------------------------------------------------*/ -static void spec_ana_fx( - const Word16 *prevsynth, /* i : Input signal */ - Word16 *plocs, /* o : The indicies of the identified peaks Q0 */ - Word32 *plocsi, /* o : Interpolated positions of the identified peaks Q16 */ - Word16 *num_plocs, /* o : Number of identified peaks Q0 */ - Word16 *X_sav, /* o : Stored fft spectrum */ - const Word16 output_frame, /* i : Frame length Q0 */ - const Word16 bwidth_fx, /* i : Encoded bandwidth index Q0 */ - Word16 *Q /* o : Q value of the fft spectrum */ -) -{ - Word16 Lprot, LprotLog2Minus1=0, hamm_len2=0, Lprot2, Lprot2_1, m, n; - const Word16 *pFftTbl = NULL; - Word16 xfp[Lprot48k]; - Word32 magSq[Lprot48k/2+1], *pMagSq; - Word16 *pXfp, *pXfp1, *pXsav, *pPlocs; - Word16 Xmax, Xmin, sel, man, expo, expoBy2; - Word16 sinTblOffset, rectLength, fraction, special; - Word32 *pPlocsi; - Word32 acc; - Word16 stop_band_start; - Word16 stop_band_length; - - Lprot = 512; /* 1536=(2*output_frame)*1024/1280; */ move16(); - - sinTblOffset = 0; - - IF (sub(output_frame, L_FRAME48k) == 0) - { - Lprot = Lprot48k; /* 1536=(2*output_frame)*1024/1280; */ move16(); - hamm_len2 = Lprot_hamm_len2_48k; /* half Hamming window = 288 */ move16(); - } - ELSE IF (sub(output_frame, L_FRAME32k) == 0) - { - Lprot = Lprot32k; /* 1024 */ move16(); - sinTblOffset = 4; - move16(); - hamm_len2 = Lprot_hamm_len2_32k; /* half Hamming window = 192 */ move16(); - pFftTbl = FFT_W512; /* Table for 1024-point real input FFT */ - LprotLog2Minus1 = 9; /* FFT stages for complex input FFT */ move16(); - } - ELSE - { - Lprot = 512; - move16(); - sinTblOffset = 8; - move16(); - hamm_len2 = Lprot_hamm_len2_16k; /* half Hamming window = 96 */ move16(); - pFftTbl = FFT_W256; /* Table for 512-point real input FFT */ - LprotLog2Minus1 = 8; /* FFT stages for complex input FFT */ move16(); - } - - Lprot2 = shr(Lprot, 1); - Lprot2_1 = add(Lprot2, 1); - rectLength = sub(Lprot, shl(hamm_len2,1)); /* The length of the rectangular portion of the Hamming-Rectangular window. */ - - *Q = s_max(0, sub(Exp16Array(Lprot, prevsynth), 1)); - move16(); - Copy_Scale_sig(prevsynth, xfp, Lprot, *Q); - - IF (sub(output_frame, L_FRAME48k) == 0) - { - /* Apply hamming-rect window */ - windowing(xfp, xfp, w_hamm_sana48k_2_fx, rectLength, hamm_len2); - /* Spectrum */ - fft3_fx(xfp, xfp, Lprot); - } - ELSE - { - /* Apply hamming-rect window */ - windowing_ROM_optimized(xfp, xfp, sinTblOffset, rectLength, hamm_len2); - /* Spectrum */ - r_fft_fx_lc(pFftTbl, Lprot, Lprot2, LprotLog2Minus1, xfp, xfp, 1); - } - - /* Apply zeroing of non-coded FFT spectrum */ - IF (sub(output_frame, inner_frame_tbl_fx[bwidth_fx]) > 0) - { - stop_band_start = shl(128, bwidth_fx); - stop_band_length = sub(Lprot, shl(stop_band_start,1)); - stop_band_start = add(stop_band_start, 1); - set16_fx( xfp + stop_band_start, 0, stop_band_length ); - } - - pXfp = xfp; - pXsav = X_sav; - FOR (m = 0; m < Lprot; m++) - { - *pXsav++ = *pXfp++; - move16(); - } - - /* Magnitude representation */ - fft_spec2_fx(xfp, magSq, Lprot); - - /* Compute xfp[m] = sqrt(magSq[m]) */ - pXfp = xfp; - pMagSq = magSq; - FOR (m = 0; m < Lprot2_1; m++) - { - IF (*pMagSq == 0) - { - *pXfp++ = extract_l(*pMagSq++); /* magSq[] is zero */ - } - ELSE - { - expo = norm_l(*pMagSq); /* exponent */ - man = extract_h(L_shl(*pMagSq++, expo)); /* mantissa */ - man = sqrt2ndOrder(man); - expoBy2 = shr(expo, 1); /* Divided by 2-- square root operation. */ - IF (s_and(expo,1) == 0) /* Check even or odd. */ - { - man = mult_r(man,FEC_HQ_ECU_ROOT2); /* FEC_HQ_ECU_ROOT2 is sqrt(2) in Q14 */ - expoBy2 = sub(expoBy2, 1); - } - *pXfp++ = shr(man, expoBy2); - move16();/* Denormalize the mantissa back to Q0. */ - } - } - - /* Find maximum and minimum. */ - maximum_fx(xfp, Lprot2_1, &Xmax); - minimum_fx(xfp, Lprot2_1, &Xmin); - sel = mult_r(sub(Xmax, Xmin), CMPLMNT_PFIND_SENS_FX); - peakfinder_fx(xfp, Lprot2_1, plocs, num_plocs, sel); - - /* Refine peaks */ - pPlocsi = plocsi; - pPlocs = plocs; - n = sub(*num_plocs, 1); /* -1 so as to exclude the very last peak. */ - /* Special case-- The very 1st peak if it is at 0 index position */ - IF (sub(*pPlocs, 0) == 0) /* Only the very 1st peak is possible the peak at 0 index position. */ - { - fraction = imax_fx(xfp, -1); /* -1 signifies special left edge case. */ - acc = L_deposit_h(*pPlocs++); /* N.B., (*pPlocs) must be zero here. */ - *pPlocsi++ = L_mac(acc, fraction, 1); - move32();/* in Q16 */ - n = sub(n, 1); /* This special case is taken care of-- one less to go */ - } - /* All peaks except the very last peak but including the very 1st one if it has not been taken care of. */ - pXfp1 = xfp - 1; - FOR (m = 0; m < n; m++) /* Loop through up to the last but one peak. (The last one is excluded.) */ - { - pXfp = pXfp1 + *pPlocs; - fraction = imax_fx(pXfp, 0); /* in Q15 */ - acc = L_deposit_h(*pPlocs++); - *pPlocsi++ = L_mac(acc, fraction, 1); - move32();/* in Q16. Append the fractional part to the integral part. */ - } - IF ( n >= 0 ) - { - /* Special case-- The very last peak */ - pXfp = pXfp1 + *pPlocs; - IF (sub(*pPlocs, Lprot2) == 0) /* Only the very last peak is possible the peak at Lprot2 index position. */ - { - pXfp--; /* Special case needs extra decrement */ - special = 1; /* Signify special right edge case. */ move16(); - } - ELSE - { - special = 0; - move16(); - } - fraction = imax_fx(pXfp, special); /* in Q15 */ - acc = L_deposit_h(*pPlocs); - *pPlocsi = L_mac(acc, fraction, 1); - move32();/* in Q16. Append the fractional part to the integral part. */ - } -} - -/*-------------------------------------------------------------------* -* subst_spec_fx() -* -* Substitution spectrum calculation -*-------------------------------------------------------------------*/ - -static void subst_spec_fx( - const Word16 *plocs, /* i : The indices of the identified peaks Q0 */ - const Word32 *plocsi, /* i : Interpolated positions of the identified peaks Q16 */ - Word16 *num_plocs, /* i/o : Number of identified peaks Q0 */ - const Word16 time_offs, /* i : Time offset Q0 */ - Word16 *X, /* i/o : FFT spectrum */ - const Word16 *mag_chg, /* i : Magnitude modification Q15 */ - const Word16 ph_dith, /* i : Phase dither, 2*PI is not included. (Q15, i.e., between 0.0 and 1.0) */ - const Word16 *is_trans, /* i : Transient flags (either 0 or 1) */ - const Word16 output_frame, /* i : Frame length Q0 */ - Word16 *seed, /* i/o : Random seed */ - const Word16 *alpha, /* i : Magnitude modification factors for fade to average Q15 */ - const Word16 *beta, /* i : Magnitude modification factors for fade to average Q15 */ - Word16 beta_mute, /* i : Factor for long-term mute Q15 */ - const Word16 *Xavg /* i : Frequency group averages to fade to Q0 */ -) -{ - Word16 Xph_short; - Word32 corr_phase[MAX_PLOCS], Xph; - Word32 *pCorrPhase; - Word16 cos_F, sin_F, tmp; - Word16 Lprot, m, i, e, im_ind, delta_corr_up, delta_corr_dn, delta_tmp; - UWord16 lsb; - Word16 j, re, im, *pReX, *pImX, lastPeak, lprotBy2Minus1, segmentLen; - Word16 pkLocation_1, pkLocation, pkLocation1; - const Word16 *pPlocs; - const Word32 *pPlocsi; - Word32 acc; - Word16 Lecu; - Word16 Lprot_inv; - Word16 k; - Word16 tmp2; - Word16 alpha_local; - Word16 beta_local; - Word16 expo; - - Word16 mag_chg_local; /*for peak attenuation in burst */ - - Lprot = 512; - move16(); - Lprot_inv = 8192; - move16(); - Lecu = shl(output_frame, 1); - - IF (sub(output_frame, L_FRAME48k) == 0) - { - Lprot = Lprot48k; /* 1536=(2*output_frame)*1024/1280; */ move16(); - Lprot_inv = 2731; /* Q22 */ move16(); - } - ELSE IF (sub(output_frame, L_FRAME32k) == 0) - { - Lprot = Lprot32k; /* 1024 */ move16(); - Lprot_inv = 4096; /* Q22 */ move16(); - } - ELSE - { - Lprot = 512; - move16(); - Lprot_inv = 8192; /* Q22 */ move16(); - } - - /* Correction phase of the identified peaks */ - IF (s_or(is_trans[0], is_trans[1]) != 0) - { - *num_plocs = 0; - move16(); - } - ELSE - { - tmp = NS2SA(output_frame*50,PH_ECU_ALDO_OLP2_NS-PH_ECU_LOOKAHEAD_NS); - tmp = add(tmp, sub(Lecu, shr(sub(Lecu, Lprot), 1))); - tmp = sub(tmp, shr(output_frame, 1)); - tmp = add(tmp, time_offs); - tmp = round_fx(L_shl(L_mult0(tmp, Lprot_inv), 4)); /* 0+22+4-16=10 */ - - pPlocsi = plocsi; - pCorrPhase = corr_phase; - FOR (m = 0; m < *num_plocs; m++) - { - Mpy_32_16_ss(*pPlocsi++, tmp, &acc, &lsb); /* plocsi[] in Q16, tmp in Q10 and tmp does not include 2*PI. */ - acc = L_add(L_shl(acc, 5), lshr(lsb, 11)); - *pCorrPhase++ = acc; /* in Q16. 2*PI is not included. */ move32(); - } - } - - lprotBy2Minus1 = sub(shr(Lprot, 1), 1); - i = 1; - move16(); - k = 0; - move16(); - im_ind = sub(Lprot, 1); - move16(); - pReX = X + i; - pImX = X + im_ind; - pPlocs = plocs; - pCorrPhase = corr_phase; - pkLocation = *pPlocs; /* N.B. No post-increment */ move16(); - pkLocation1 = *pPlocs++; - move16(); - lastPeak = sub(*num_plocs, 1); - FOR (m = 0; m < *num_plocs; m++) - { - delta_corr_dn = DELTA_CORR; - move16(); - delta_corr_up = DELTA_CORR; - move16(); - - pkLocation_1 = pkLocation; /* plocs[m - 1] */ move16(); - pkLocation = pkLocation1; /* plocs[m] */ move16(); - pkLocation1 = *pPlocs++; /* plocs[m + 1] */ move16(); - IF (m > 0) - { - delta_tmp = shr(sub(sub(pkLocation, pkLocation_1), 1), 1); - if (sub(delta_tmp, DELTA_CORR) < 0) - { - delta_corr_dn = delta_tmp; - move16(); - } - } - - IF (sub(m, lastPeak) < 0 ) - { - delta_tmp = shr(sub(sub(pkLocation1, pkLocation), 1), 1); - if (sub(delta_tmp, DELTA_CORR ) < 0) - { - delta_corr_up = delta_tmp; - move16(); - } - } - - /* Input Xph */ - segmentLen = sub(sub(pkLocation, delta_corr_dn), i); - /* i = add(i, segmentLen); */ - FOR (j = 0; j < segmentLen; j++) - { - *seed = rand_phase_fx(*seed, &sin_F, &cos_F); - - re = *pReX; - move16(); - im = *pImX; - move16(); - tmp = sub(mult_r(re, cos_F), mult_r(im, sin_F)); - im = add(mult_r(re, sin_F), mult_r(im, cos_F)); - IF (sub(alpha[k], 32766) < 0) - { - *seed = rand_phase_fx(*seed, &sin_F, &cos_F); - tmp2 = mult_r(beta[k], Xavg[k]); - *pReX++ = add( mult_r(alpha[k], tmp), mult_r(tmp2, cos_F) ); - move16(); - *pImX-- = add( mult_r(alpha[k], im), mult_r(tmp2, sin_F) ); - move16(); - } - ELSE - { - *pReX++ = mult_r(mag_chg[k], tmp); - move16(); - *pImX-- = mult_r(mag_chg[k], im); - move16(); - } - i = add(i, 1); - if (sub(i, gwlpr_fx[k+1]) >= 0) - { - k = add(k, 1); - } - } - - e = add(pkLocation, delta_corr_up); - if (sub(e, lprotBy2Minus1) > 0) - { - e = lprotBy2Minus1; - move16(); - } - - Xph = *pCorrPhase; - Xph_short = s_and(extract_l(L_shr(Xph, 16 - 10)), 0x3ff); /* 10 bits precision after radix point */ - IF (sub(Xph_short, 512) >=0) - { - sin_F = negate(sincos_t_ext_fx[Xph_short - 512]); - IF (sub(Xph_short, 768) < 0) - { - cos_F = negate(sincos_t_ext_fx[Xph_short - (512 - 256)]); - } - ELSE - { - cos_F = sincos_t_ext_fx[-Xph_short + (1024 + 256)]; - move16(); - } - } - ELSE - { - sin_F = sincos_t_ext_fx[Xph_short]; - move16(); - IF (sub(Xph_short, 256) < 0) - { - cos_F = sincos_t_ext_fx[Xph_short + 256]; - move16(); - } - ELSE - { - cos_F = negate(sincos_t_ext_fx[-Xph_short + (256 + 512)]); - } - } - - segmentLen = add(sub(e, i), 1); - /* i = add(i, segmentLen); */ - FOR (j = 0; j < segmentLen; j++ ) - { - mag_chg_local = mag_chg[k]; - move16(); - IF (ph_dith != 0 ) - { - Xph = *pCorrPhase; /* in Q16. 2*PI is not included. */ - *seed = own_random2_fx(*seed); /* in Q0 */ - acc = L_mult(*seed, ph_dith); /* N.B. ph_dith[i] is in Q15, i.e., in between 0 and 1.0 (2*PI not included) */ - acc = L_shr(acc, PHASE_DITH_SCALE_SHIFT); - Xph = L_add(Xph, acc); /* in Q16. */ - - IF (ph_dith > 0 ) /* up to 6 dB additional att of peaks in non_transient longer bursts, (when peak phase is randomized ) */ - { - /* mag_chg_local *= 0.5 + (1.0 - ph_dith[i])/2 where 0.5~= sqrt((float)pow(10.0,-6/10.0)) and ph_dith=0..1.0--> scale=1.0 ...5 */ - mag_chg_local = mult_r(mag_chg_local, sub(32767, shr(ph_dith, 1))); - } - Xph_short = s_and(extract_l(L_shr(Xph, 16 - 10)), 0x3ff); - IF (sub(Xph_short, 512) >= 0) - { - sin_F = negate(sincos_t_ext_fx[Xph_short - 512]); - IF (sub(Xph_short, 768) < 0) - { - cos_F = negate(sincos_t_ext_fx[Xph_short - (512 - 256)]); - } - ELSE - { - cos_F = sincos_t_ext_fx[-Xph_short + (1024 + 256)]; - move16(); - } - } - ELSE - { - sin_F = sincos_t_ext_fx[Xph_short]; - move16(); - IF (sub(Xph_short, 256) < 0) - { - cos_F = sincos_t_ext_fx[Xph_short + 256]; - move16(); - } - ELSE - { - cos_F = negate(sincos_t_ext_fx[-Xph_short + (256 + 512)]); - } - } - } - - re = *pReX; - move16(); - im = *pImX; - move16(); - tmp = sub(mult_r(re, cos_F), mult_r(im, sin_F)); - im = add(mult_r(re, sin_F), mult_r(im, cos_F)); - IF (sub(alpha[k], 32766) < 0) - { - alpha_local = mag_chg_local; - move16(); - - acc = L_sub(1073741824L, L_mult0(alpha_local, alpha_local)); - acc = Sqrt_l(acc, &expo); - expo = add(30, add(31, expo)); - if (sub(s_and(expo, 1), 1) == 0) - { - acc = Mult_32_16(acc, 23170); /* 1/sqrt(2) in Q15 */ - } - expo = shr(expo, 1); - beta_local = mult_r(beta_mute, round_fx(L_shl(acc, sub(31, expo)))); - - IF (sub(k, LGW32K-1) >= 0) - { - beta_local = mult_r(beta_local, 3277); /* 0.1 in Q15 */ - } - ELSE if (sub(k, LGW16K-1) >= 0) - { - beta_local = mult_r(beta_local, 16384); /* 0.5 in Q15 */ - } - - *seed = rand_phase_fx(*seed, &sin_F, &cos_F); - tmp2 = mult_r(beta_local, Xavg[k]); - *pReX++ = add( mult_r(alpha_local, tmp), mult_r(tmp2, cos_F) ); - move16(); - *pImX-- = add( mult_r(alpha_local, im), mult_r(tmp2, sin_F) ); - move16(); - } - ELSE - { - *pReX++ = mult_r(mag_chg_local, tmp); - move16(); - *pImX-- = mult_r(mag_chg_local, im); - move16(); - } - - i = add(i, 1); - if (sub(i, gwlpr_fx[k+1]) >= 0) - { - k = add(k, 1); - } - } - pCorrPhase++; - } - - segmentLen = sub(shr(Lprot,1), i); - FOR (j = 0; j < segmentLen; j++) - { - *seed = rand_phase_fx(*seed, &sin_F, &cos_F); - - re = *pReX; - move16(); - im = *pImX; - move16(); - tmp = sub(mult_r(re, cos_F), mult_r(im, sin_F)); - im = add(mult_r(re, sin_F), mult_r(im, cos_F)); - IF (sub(alpha[k], 32766) < 0) - { - *seed = rand_phase_fx(*seed, &sin_F, &cos_F); - tmp2 = mult_r(beta[k], Xavg[k]); - *pReX++ = add( mult_r(alpha[k], tmp), mult_r(tmp2, cos_F) ); - move16(); - *pImX-- = add( mult_r(alpha[k], im), mult_r(tmp2, sin_F) ); - move16(); - } - ELSE - { - *pReX++ = mult_r(mag_chg[k], tmp); - move16(); - *pImX-- = mult_r(mag_chg[k], im); - move16(); - } - - i = add(i, 1); - if (sub(i, gwlpr_fx[k+1]) >= 0) - { - k = add(k, 1); - } - } -} - -/*-------------------------------------------------------------------------- - * rec_wtda() - * - * Windowing and TDA of reconstructed frame - *--------------------------------------------------------------------------*/ - -static void rec_wtda_fx( - Word16 *X, /* i : FFT spectrum */ - Word32 *ecu_rec, /* o : Reconstructed frame in tda domain */ - const Word16 output_frame, /* i : Frame length */ - const Word16 Lprot, /* i : Prototype frame length */ - const Word32 fs -) -{ - Word16 l, Lprot2, timesh; - Word16 rec_buf[3*L_FRAME48k]; - Word16 *xsubst_,*out_ptr; - Word16 Qin; - Word16 xf_len; - Word16 i, idx; - Word16 *p_ecu; - Word16 g; - Word16 tbl_delta; - - xsubst_ = rec_buf + output_frame; - Lprot2 = shr(Lprot, 1); - - /* Initialize to WB constants */ - xf_len = 26; - move16(); - tbl_delta = 10082; /* Q12 */ move16(); - IF (sub(output_frame, L_FRAME48k) == 0) - { - xf_len = 78; - move16(); - tbl_delta = 3361; /* Q12 */ move16(); - } - ELSE IF (sub(output_frame, L_FRAME32k) == 0) - { - xf_len = 52; - move16(); - tbl_delta = 5041; /* Q12 */ move16(); - } - - /* extract reconstructed frame with aldo window */ - l = sub(output_frame, Lprot2); - set16_fx(xsubst_,0 , l); - Copy(X, xsubst_ + l, Lprot); - set16_fx(xsubst_ + add(output_frame, Lprot2), 0, l); - - /* Smoothen onset of ECU frame */ - p_ecu = xsubst_ + (output_frame - Lprot2); - FOR ( i = 0; i < xf_len; i++) - { - idx = extract_l(L_shr(L_mult0(i, tbl_delta), 12)); - g = sincos_t_fx[idx]; - g = mult(g, g); - *p_ecu = mult(g, (*p_ecu)); - move16(); - p_ecu++; - } - - timesh = NS2SA_fx2(fs, 10000000L - PH_ECU_ALDO_OLP2_NS); - - set16_fx(rec_buf, 0, output_frame); - Qin = 0; - out_ptr = rec_buf + sub(shl(output_frame,1), timesh); - wtda_fx(out_ptr, &Qin, ecu_rec, NULL, 0, ALDO_WINDOW, ALDO_WINDOW, /* window overlap of current frame (0: full, 2: none, or 3: half) */ - output_frame); - - return; -} - -/*-------------------------------------------------------------------------- - * rec_frame_fx() - * - * Frame reconstruction - *--------------------------------------------------------------------------*/ -static void rec_frame_fx( - Word16 *X, /* i : FFT spectrum */ - Word32 *ecu_rec, /* o : Reconstructed frame in tda domain */ - const Word16 output_frame, /* i : Frame length */ - const Word16 Q -) -{ - const Word16 *pFftTbl; - Word16 Lprot, lprotLog2Minus1; - Word32 fs; - - fs = L_mult0(output_frame, 50); - - /* Initialize to WB constants */ - Lprot = 512; - move16(); - lprotLog2Minus1 = 9 - 1; - move16(); - pFftTbl = FFT_W256; /* Table for 512-point real input FFT */ - IF (sub(output_frame, L_FRAME48k) == 0) - { - Lprot = Lprot48k; /* 1536 = (2*output_frame)*1024/1280 */ move16(); - } - ELSE IF (sub(output_frame, L_FRAME32k) == 0) - { - Lprot = Lprot32k; /* 1024 */ move16(); - lprotLog2Minus1 = 10 - 1; - move16(); - pFftTbl = FFT_W512; /* Table for 1024-point real input FFT */ - } - - /* extend spectrum and IDFT */ - IF (sub(output_frame, L_FRAME48k) == 0) - { - ifft3_fx(X, X, Lprot); - } - ELSE - { - r_fft_fx_lc(pFftTbl, Lprot, shr(Lprot, 1), lprotLog2Minus1, X, X, 0); /* Inverse FFT */ - } - Scale_sig(X, Lprot, -Q); - - rec_wtda_fx(X, ecu_rec, output_frame, Lprot, fs); - - return; -} - -static -Word32 mult_32_32_q(const Word32 a, const Word32 b, const Word16 q) -{ - Word32 hi; - UWord32 lo; - Mpy_32_32_ss(a, b, &hi, &lo); - - return L_or(L_shl(hi, 32 - q - 1), L_lshr(lo, q + 1)); -} - -static -void fir_dwn_fx( - const Word16 x[], /* i : input vector Q(x_Q) */ - const Word16 h[], /* i : impulse response of the FIR filter Q(h_Q) */ - const Word16 h_Q, /* H's Q */ - Word16 y[], /* o : output vector (result of filtering) Q~ */ - const Word16 L, /* i : input vector size */ - const Word16 K, /* i : order of the FIR filter (K+1 coefs.) */ - const Word16 decimation /* i : decimation */ -) -{ - Word32 s; - Word16 i, j; - const Word16 *ptr_h, *ptr_x; - Word16 *ptr_y; - Word16 Kdiv2; - Word16 centering; - Word16 tmp; - - centering = sub(16, h_Q); - Kdiv2 = shr(K,1); - - ptr_y = y; - /* do the filtering */ - FOR (i = Kdiv2; i < K; i+=decimation) - { - s = L_deposit_l(0); - ptr_h = h + 1; - ptr_x = x + i - 1; - move16(); - - FOR (j = 1; j <= i; j++) - { - s = L_mac0(s, *ptr_h++, *ptr_x--); - } - - *ptr_y++ = extract_h(L_shl(s, centering)); - } - FOR (i = K; i < L; i+=decimation) - { - s = L_deposit_l(0); - ptr_h = h + 1; - ptr_x = x + i - 1; - move16(); - - FOR (j = 1; j <= K; j++) - { - s = L_mac0(s, *ptr_h++, *ptr_x--); - } - - *ptr_y++ = extract_h(L_shl(s, centering)); - - } - tmp = add(L,Kdiv2); - FOR (i = i; i < tmp; i+=decimation) - { - s = L_deposit_l(0); - ptr_h = h + i - L + 1; - move16(); - ptr_x = x + L - 1; - move16(); - - FOR (j = add(sub(i,L),1); j <= K; j++) - { - s = L_mac0(s, *ptr_h++, *ptr_x--); - } - - *ptr_y++ = extract_h(L_shl(s, centering)); - } - - return; -} - -static -void fec_ecu_pitch_fx( - const Word16 *prevsynth_fx, /*Q15 16 */ - Word16 *prevsynth_LP_fx, /* Q15 16 */ - const Word16 L, - Word16 *N, - Word16 *min_corr_fx, /* Q15 16 */ - Word16 *decimatefator, - const Word16 HqVoicing -) -{ - - Word16 i,filt_size; - Word16 QAsr,Ryy,cb_start, tmpQLP; - Word32 Ryytmp; - Word32 accA,accB, accBisqrt,accC, accCisqrt; - Word16 delay_ind,k; - const Word16 *Asr_LP_fx; - Word16 *ptr_LP, *ptr_LP2, *ptr_LP3, *ptr_LP4; - Word16 cb_end; - Word16 Lmul2, Lon20mul6, Lon20mul28, Lon20mul33, Lon20mul34; - - - SWITCH(L) - { - case L_FRAME48k: - *decimatefator=6; - move16(); - filt_size=60; - move16(); - Asr_LP_fx = Asr_LP48_fx; - QAsr = 17; - move16(); - Lon20mul6 = 48; - move16(); - Lon20mul28 = 224; - move16(); - Lon20mul33 = 264; - move16(); - Lon20mul34 = 272; - move16(); - Lmul2 = 1920; - move16(); - BREAK; - - case L_FRAME32k: - *decimatefator=4; - move16(); - filt_size=40; - move16(); - Asr_LP_fx = Asr_LP32_fx; - QAsr = 15; - move16(); - Lon20mul6 = 48; - move16(); - Lon20mul28 = 224; - move16(); - Lon20mul33 = 264; - move16(); - Lon20mul34 = 272; - move16(); - Lmul2 = 1280; - move16(); - BREAK; - - case L_FRAME16k: - *decimatefator=2; - move16(); - filt_size=20; - move16(); - Asr_LP_fx = Asr_LP16_fx; - QAsr = 15; - move16(); - Lon20mul6 = 48; - move16(); - Lon20mul28 = 224; - move16(); - Lon20mul33 = 264; - move16(); - Lon20mul34 = 272; - move16(); - Lmul2 = 640; - move16(); - BREAK; - - default: - *decimatefator=2; - move16(); - filt_size=40; - move16(); - Asr_LP_fx = Asr_LP16_fx; - QAsr = 15; - move16(); - Lon20mul6 = 48; - move16(); - Lon20mul28 = 224; - move16(); - Lon20mul33 = 264; - move16(); - Lon20mul34 = 272; - move16(); - Lmul2 = 320; - move16(); - BREAK; - } - - - /* Resampling to work at 8Khz */ - fir_dwn_fx(prevsynth_fx, Asr_LP_fx, QAsr, prevsynth_LP_fx, Lmul2, filt_size, *decimatefator); /* resampling without delay */ - - - tmpQLP = Find_Max_Norm16(prevsynth_LP_fx,320); - Scale_sig(prevsynth_LP_fx,320,sub(tmpQLP,3)); /* to avoid over scaling */ - - - - /* Correlation analysis */ - *min_corr_fx = 0; - move16(); - accC = L_deposit_l(0); - - ptr_LP = prevsynth_LP_fx + Lon20mul34; - FOR (k = 0; k < Lon20mul6; k++) - { - accC = L_mac0 (accC, *ptr_LP, *ptr_LP); - ptr_LP++; - - } - - - - IF (HqVoicing==1) - { - cb_start=0; - cb_end=Lon20mul33; - } - ELSE - { - cb_start=0; - cb_end=Lon20mul28; - } - - accB=0; - delay_ind=cb_start; - - FOR (i=cb_start; i *min_corr_fx ) - { - *min_corr_fx = Ryy; - delay_ind = i; - } - - test(); - IF ( HqVoicing == 0 && *min_corr_fx > 31130) - { - BREAK; - } - } - - *N= sub(Lon20mul34, delay_ind); - - - Scale_sig(prevsynth_LP_fx,320,negate(sub(tmpQLP,3))); - return; -} - -static -void sin_cos_est_fx(Word32 phi, Word16 *cosfreq, Word16 *sinfreq) -{ - - - /* i phi : normalized frequency beteween 0 and Pi (nyquist) in Q30 */ - /* o cosfreq & sinfreq : cos(phi) and sin (phi) in Q15 */ - - Word16 i; - Word32 delta; - Word32 imin; - Word16 sinb, cosb; - Word32 sinv, cosv, tmp; - - i=0; - move16(); - FOR (imin=0; imin0 ) - { - flag = 1; - move16(); /*flag corresponds to condition sub(N, Lon20_10)>0 || HqVoicing */ - } - - - - - pt4 = pulses; - nb_pulses=0; - move16(); - PL=0; - move16(); - cpt=0; - move16(); - old=0; - move16(); - glued=1; - move16(); - new_s=Tf_abs[1]; - move16(); - if (flag ) - { - PL=1; - move16(); - } - tmp=sub(shr(N,1),3); - WHILE(sub(cpt,tmp)<=0) - { - test(); - IF(sub(Tf_abs[cpt],old)>0 && sub(Tf_abs[cpt],new_s)>0) - { - Word16 tmp2; - - glued=cpt; - move16(); - - tmp2 = add(add(cpt,PL),1); - FOR (i=glued; i0) - { - indmax = tmp; - move16(); - } - mmax = s_max(Tf_abs[tmp], mmax); - } - - *pt1++ = Tfr[indmax]; - move16(); /*L_shr(Tfr[indmax], sN); //instead shr -> scaling of a_re is Qin+sN */ - *pt2++ = Tfi[indmax]; - move16(); /*L_shr(Tfi[indmax], sN); //instead shr -> scaling of a_im is Qin+sN */ - *pt3++ = indmax; - move16(); - Tf_abs[indmax] = -1; - move16(); - } - - } - ELSE - { - DO - { - mmax = 0; - move16(); - pt4 = pulses; - FOR ( k=0; k0) - { - indmax = tmp; - move16(); - } - mmax = s_max(Tf_abs[tmp], mmax); - } - - cumsum = L_mac0(cumsum, mmax,1); - - *pt1++ = Tfr[indmax]; - move16(); /*L_shr(Tfr[indmax], sN); //instead shr -> scaling of a_re is Qin+sN */ - *pt2++ = Tfi[indmax]; - move16(); /*L_shr(Tfi[indmax], sN); //instead shr -> scaling of a_im is Qin+sN */ - *pt3++ = indmax; - move16(); - Tf_abs[indmax] = -1; - move16(); - - maxi=sub(maxi,1); - } WHILE( maxi>0 && L_sub(cumsum, L_tmp)<0); - - nb_pulses_final = sub(nb_pulses_final,maxi); - move16(); - } - - - /* sinusoidal synthesis */ - - - set32_fx(synthesis_fx,0,Len); - - exp = add(exp,sN); - - - pt1 = a_re; - pt2 = a_im; - pt3 = freqi; - q = shr_r(N,2); - if (sub(N,shl(q,2))>0) - { - q = add(q,1); - } - - inv_den = i_mult2(N,decimate_factor); /*Q0 */ - - /*tmp = div_s(12868,inv_den);*/ /*Q15 */ - - - FOR ( i=0; i 0 ) - { - tmp_fx = Random(ni_seed_forfec); - - L_tmp = L_mac(1503264768, tmp_fx ,9830); - if ( kk == 0 ) - { - L_tmp = L_mac(1073741824, tmp_fx ,6554); - } - - kk = sub(1,kk) ; - tmp_fx = round_fx(L_tmp); - Rnd_N_noise = extract_h(L_mult(N_noise, tmp_fx)); /*Q0 */ - - - tmp_fx = div_s(1, Rnd_N_noise); /*Q15 */ - tmp_fx = round_fx(L_shl(L_mult(tmp_fx, 25736),2)); /*Q15 */ - - sinq_fx( shr(tmp_fx,1), shr(tmp_fx,2), Rnd_N_noise, SS_fx); - - pt2 = &noisevect_fx[N_noise]; - pt1 = pt2 - Rnd_N_noise; - pt3 = SS_fx; - pt4 = pt3 + sub(Rnd_N_noise,1); - tmp_fx = s_min(Rnd_N_noise, flag); - FOR ( i=0 ; i 0) - { - seed = add(seed, plocs[*num_p-1]); - } - - subst_spec_fx(plocs, plocsi, num_p, *time_offs, X, mag_chg, ph_dith, old_is_transient, output_frame, &seed, - alpha, beta, *beta_mute, Xavg); - - /* reconstructed frame in tda domain */ - rec_frame_fx(X, ecu_rec, output_frame, *Q_spec); - - *last_fec = 0; - *ph_ecu_active = 1; - move16(); -} - - -/*-------------------------------------------------------------------------- - * hq_ecu() - * - * Main routine for HQ ECU - *--------------------------------------------------------------------------*/ -void hq_ecu_fx( - const Word16 *prevsynth, /* i : buffer of previously synthesized signal */ - Word32 *ecu_rec, /* o : reconstructed frame in tda domain */ - Word16 *time_offs, /* i/o: Sample offset for consecutive frame losses */ - Word16 *X_sav, /* i/o: Stored spectrum of prototype frame */ - Word16 *Q_spec, /* i/o: Q value of stored spectrum */ - Word16 *num_p, /* i/o: Number of identified peaks */ - Word16 *plocs, /* i/o: Peak locations */ - Word32 *plocsi, /* i/o: Interpolated peak locations Q16 */ - const Word16 env_stab, /* i : Envelope stability parameter */ - Word16 *last_fec, /* i/o: Flag for usage of pitch dependent ECU */ - const Word16 ph_ecu_HqVoicing, /* i : HQ Voicing flag */ - Word16 *ph_ecu_active, /* i : Phase ECU active flag */ - Word16 *gapsynth, /* o : Gap synthesis */ - const Word16 prev_bfi, /* i : indicating burst frame error */ - const Word16 old_is_transient[2], /* i : flags indicating previous transient frames */ - Word16 *mag_chg_1st, /* i/o: per band magnitude modifier for transients */ - Word16 *Xavg, /* i/o: Frequency group average gain to fade to */ - Word16 *beta_mute, /* o : Factor for long-term mute */ - const Word16 output_frame, /* i : frame length */ - Decoder_State_fx *st_fx /* i/o: decoder state structure */ -) -{ - Word16 N; - Word16 decimatefactor; - Word16 corr; /*Q15 */ - Word16 prevsynth_LP[2*L_FRAME8k]; - - /* init (values ar changed after) */ - decimatefactor=4; - N=shr(output_frame,2); - - - /* find pitch and R value */ - - IF (!(sub(output_frame,L_FRAME16k) < 0) ) - { - fec_ecu_pitch_fx( prevsynth+NS2SA(output_frame*50,ACELP_LOOK_NS/2-PH_ECU_LOOKAHEAD_NS), prevsynth_LP, output_frame, &N, &corr, &decimatefactor, ph_ecu_HqVoicing); - } - ELSE - { - corr = 0; - move16(); /* just to avoid using uninitialized value in if statement below */ - } - - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - IF ( (L_sub(st_fx->total_brate_fx,48000) >= 0 && - ( sub(output_frame, L_FRAME16k) >= 0 && !prev_bfi && (!old_is_transient[0] || old_is_transient[1] ) && (ph_ecu_HqVoicing != 0 || ( ((st_fx->env_stab_plc_fx != 0) && (sub(corr,19661)<0)) || (!(st_fx->env_stab_plc_fx != 0) && (sub(corr, 27853) > 0 )))))) || - (L_sub(st_fx->total_brate_fx,48000) < 0 && ( ( ph_ecu_HqVoicing || sub(corr, 27853) > 0 ) && !prev_bfi && (!old_is_transient[0] || old_is_transient[1]) )) ) - { - fec_alg_fx( prevsynth+NS2SA(output_frame*50,ACELP_LOOK_NS/2-PH_ECU_LOOKAHEAD_NS), prevsynth_LP, &st_fx->ni_seed_forfec, ecu_rec, output_frame, N, decimatefactor, ph_ecu_HqVoicing, gapsynth); - - *last_fec = 1; - *ph_ecu_active = 0; - move16(); - *time_offs = output_frame; - move16(); - } - ELSE - { - hq_phase_ecu_fx( prevsynth, ecu_rec, time_offs, X_sav, Q_spec, num_p, plocs, plocsi, - env_stab, last_fec, ph_ecu_active, prev_bfi, old_is_transient, - mag_chg_1st, Xavg, beta_mute, st_fx->bwidth_fx, output_frame ); - } - - return; -} - -/******************************************************************************* - * The square root of x which MUST be 0.5 <= x < 1, i.e., x must be normalized. - * sqrt(x) is approximated by a polynomial of degree n. - * - * sqrt(x) = a0 x^n + a1 x^(n-1) + a2 x^(n-2) + ... + an - * = (...((a0 x + a1) x + a2) x + ...) x + an - * - * The coefficients can be readily obtained by the following open source Octave - * (or commercial Matlab) script: - * order = 2; - * N = 400; - * x = linspace(0.5, 1.0, N); - * y = sqrt(x); - * p = polyfit(x, y, order) - * z = polyval(p, x); - * err = y - z; - * plot(err); - ******************************************************************************/ - -static Word16 sqrt2ndOrder( /* o: in Q15 (2nd order least square approx.) */ - const Word16 x /* i: x must be in between 0.5 and 1.0 (Q15). */ -) -{ - Word32 acc; - Word16 z; - - acc = 1890205600L; /* 0.880195572812922 in Q31 */ move32(); - z = mac_r(acc, x, -6506); /* -0.198537395405340 in Q15 */ - acc = 682030261L; /* 0.317595089462249 in Q31 */ move32(); - z = mac_r(acc, z, x); /* in Q15 */ - return z; -} - -/*----------------------------------------------------------------------------- - * windowing() - * - * Apply a symmetric Hamming or Hamming-Rectangular window to the signal. - * If the "rectLength" parameter is zero, it is Hamming window; otherwise, the - * rectLength signifies the length of the rectangular part of the Hamming-Rectangular - * window. - *--------------------------------------------------------------------------- */ -static void windowing( - const Word16 *x, /* i: Input signal */ - Word16 *y, /* o: Windowed output */ - const Word16 *win, /* i: Window coefficients */ - const Word16 rectLength, /* i: Offset in between the 1st and 2nd symmetric halves of the Hamming window */ - const Word16 halfLength /* i: Half of the total length of a complete Hamming window. */ -) -{ - Word16 i; - Word16 *pY; - const Word16 *pX, *pW; - pX = x; - pW = win; - pY = y; - FOR (i = 0; i < halfLength; i++) /* 1st symmetric half of the Hamming window */ - { - *pY++ = mult_r(*pX++, *pW++); - move16(); - } - FOR (i = 0; i < rectLength; i++) /* If rectLength is zero, it's a pure Hamming window; otherwise Hamming-Rectangular. */ - { - *pY++ = *pX++; - move16(); - } - FOR (i = 0; i < halfLength; i++) /* 2nd symmetric half of the Hamming window. */ - { - *pY++ = mult_r(*pX++, *(--pW)); - move16(); - } -} - -/*----------------------------------------------------------------------------- - * windowing_ROM_optimized() - * - * The coefficients of the Hamming window are derived from the sine table - * shared with fft3_fx(). - * The entire Hamming-Rectangular window is decomposed into 5 segments: - * 1. 1st half of the left half of the Hamming window - * 2. 2nd half of the left half of the Hamming window - * 3. The flat part of the rectangular region - * 4. 1st half of the right half of the Hamming window - * 5. 2nd half of the right half of the Hamming window - *----------------------------------------------------------------------------*/ -static void windowing_ROM_optimized( - const Word16 *x, /* i: Input signal */ - Word16 *y, /* o: Windowed output */ - const Word16 downSamples,/* i: Offset in accessing the sine table. */ - const Word16 rectLength, /* i: Length of the rectangular portion (excluding the Hamming window part) */ - const Word16 halfLength /* i: Half of the total length of the Hamming (excluding rectangular part) window */ -) -{ - Word16 i, hamm, quarterLen, initOffset; - Word16 *pY; - const Word16 *pX, *pSine; - Word32 acc; - - quarterLen = shr(halfLength, 1); /* 1/4 length of the entire Hamming (excluding the rectangular part) window. */ - initOffset = add(T_SIN_PI_2, shr(downSamples,1)); - pSine = sincos_t_rad3_fx + initOffset; - pX = x; - pY = y; - - /* 1st half of the left half of the Hamming window. */ - FOR (i = 0; i < quarterLen; i++) - { - pSine -= downSamples; /* Decrement address counter */ - acc = L_deposit_h(FEC_HQ_WIN_A0); /* Derive the Hamming window coefficient from the sine table. */ - hamm = msu_r(acc, *pSine, FEC_HQ_WIN_A1); - *pY++ = mult_r(hamm, *pX++); - move16(); - } - - /* 2nd half of the left half of the Hamming window. */ - FOR (i = 0; i < quarterLen; i++) - { - acc = L_deposit_h(FEC_HQ_WIN_A0); - hamm = mac_r(acc, *pSine, FEC_HQ_WIN_A1); - *pY++ = mult_r(hamm, *pX++); - move16(); - pSine += downSamples; /* Increment address counter */ - } - - /* The rectangular flat region */ - FOR (i = 0; i < rectLength; i++) - { - *pY++ = *pX++; - move16(); - } - - /* 1st half of the right half of the Hamming window. */ - FOR (i = 0; i < quarterLen; i++) - { - pSine -= downSamples; /* Decrement address counter */ - acc = L_deposit_h(FEC_HQ_WIN_A0); - hamm = mac_r(acc, *pSine, FEC_HQ_WIN_A1); - *pY++ = mult_r(hamm, *pX++); - move16(); - } - - /* 2nd half of the right half of the Hamming window. */ - FOR (i = 0; i < quarterLen; i++) - { - acc = L_deposit_h(FEC_HQ_WIN_A0); - hamm = msu_r(acc, *pSine, FEC_HQ_WIN_A1); - *pY++ = mult_r(hamm, *pX++); - move16(); - pSine += downSamples; /* Increment address counter */ - } -} diff --git a/src/libs/libevs/lib_dec/FEC_adapt_codebook.cpp b/src/libs/libevs/lib_dec/FEC_adapt_codebook.cpp new file mode 100644 index 00000000..9ba0e139 --- /dev/null +++ b/src/libs/libevs/lib_dec/FEC_adapt_codebook.cpp @@ -0,0 +1,460 @@ +/*==================================================================================== + EVS Codec 3GPP TS26.443 Nov 13, 2018. Version 12.11.0 / 13.7.0 / 14.3.0 / 15.1.0 + ====================================================================================*/ + +#include +#include +#include "options.h" +#include "cnst.h" +#include "rom_dec.h" +#include "prot.h" + + +/*------------------------------------------------------------------------- + * FEC_synchro_exc() + * + * Perform resynchronisation of the last glottal pulse in voiced frame lost + *------------------------------------------------------------------------*/ + +static short FEC_synchro_exc( /* o : do_WI flag */ + const short L_frame, /* i : length of the frame */ + float *exc, /* i/o: exc vector to modify */ + const short desire_puls_pos, /* i : Pulse position send by the encoder */ + const short true_puls_pos, /* i : Present pulse location */ + const short Old_pitch /* i : Pitch use to create temporary adaptive codebook */ +) +{ + float exc_tmp[L_FRAME16k+L_SUBFR], min_energy, *pt_exc,*pt_exc1, ftmp, fact; + short i, j, point_to_remove, point_to_add = -1, nb_min; + short min_pos[L_FRAME16k/PIT_MIN_DOUBLEEXTEND], points_by_pos[L_FRAME16k/PIT_MIN_DOUBLEEXTEND], total_point, tmp_len; + short *pt_pos, pos, start_search, tmp16; + short remaining_len; + + /* Init */ + for( i=0; i= 65536*65536.0f ) + { + return 0; + } + + /*-------------------------------------------------------------------- + * Determine the number of samples to be added or removed at each pitch + * cycle whereby less samples are added/removed at the beginning and + * more towards the end of the frame + * --------------------------------------------------------------------*/ + + if(nb_min == 1 || abs(point_to_remove) == 1) + { + nb_min = 1; + points_by_pos[0] = (short)abs(point_to_remove); + } + else + { + /* First position */ + fact = (float)abs(point_to_remove) / (nb_min*nb_min); + + total_point = (short)(fact+0.5); + points_by_pos[0] = total_point; + + for (i = 2; i <= nb_min; i++) + { + points_by_pos[i-1] = (short)(fact*(i*i) - total_point+0.5) ; + total_point += points_by_pos[i-1]; + + /* ensure a constant increase */ + if (points_by_pos[i-1] < points_by_pos[i-2]) + { + tmp16 = points_by_pos[i-2]; + points_by_pos[i-2] = points_by_pos[i-1]; + points_by_pos[i-1] = tmp16; + } + } + } + + /* -------------------------------------------------------------------- + * Sample deletion or insertion is performed in minimum energy regions. + * At the end of this section the last maximum pulse in the concealed + * excitation is forced to align to the actual maximum pulse position + * at the end of the frame which is transmitted in the future frame. + * --------------------------------------------------------------------*/ + + if ( point_to_remove > 0 ) + { + point_to_add =point_to_remove; + } + + pt_exc = exc_tmp; + pt_exc1 = exc; + + i = 0; + pt_pos = min_pos + nb_min - 1; + if ( point_to_add > 0 ) /* add some points */ + { + remaining_len = L_frame; + + for (i = 0; i < nb_min; i++) + { + /* Copy section */ + if(i == 0) + { + /* Compute len to copy */ + tmp_len = *pt_pos; + } + else + { + /* Compute len to copy */ + tmp_len = *pt_pos - *(pt_pos+1) - points_by_pos[i-1]; + } + + mvr2r( pt_exc1, pt_exc, tmp_len); + remaining_len -= tmp_len; + pt_exc1 += tmp_len; + pt_exc += tmp_len; + + /* add some points */ + ftmp = -(*pt_exc1/20); + for (j=0; j PIT_MAX && L_frame == L_FRAME ) + { + P0 = PIT_MAX; /* Should never be the case, however... */ + } + else if ( P0 > PIT16k_MAX && L_frame == L_FRAME16k ) + { + P0 = PIT16k_MAX; /* Should never be the case, however... */ + } + set_f( exc_tmp, 0, L_frame+ MODE1_L_FIR_FER); /* Reset excitation vector */ + + /*--------------------------------------------* + * Find LP filter impulse response energy + *--------------------------------------------*/ + + set_f( h1, 0, L_subfr ); /* Find the impulse response */ + set_f( mem, 0, M ); + h1[0] = 1.0f; + syn_filt(Aq, M, h1, h1, L_subfr, mem, 0); + enr_LP = dotp( h1, h1, L_subfr ) + 0.01f; /* Find the impulse response energy */ + + /*------------------------------------------------------------------------------------------* + * Construct the harmonic part as a train of low-pass filtered pulses + *------------------------------------------------------------------------------------------*/ + + pt_exc = exc_tmp + L_frame- 1 - MODE1_L_FIR_FER/2 - P0; /* beginning of the 1st pulse */ + pt_end = exc_tmp + onset_len; + + len = (short)(pt_exc - pt_end); + if( len > MODE1_L_FIR_FER ) + { + len = MODE1_L_FIR_FER; + } + if(!sign) + { + for( i=0; i< len; i++ ) + { + /* The filter response would have E=1 in full band. */ + pt_exc[i] += h_low[i]; /* As it is lp filtered, the E is somewhat lower */ + } + } + else + { + for( i=0; i< len; i++ ) + { + /* The filter response would have E=1 in full band. */ + pt_exc[i] -= h_low[i]; /* As it is lp filtered, the E is somewhat lower */ + } + } + + gain = (float)sqrt(1.5*enr_q / enr_LP); /* divide by LP filter E, scale by transmitted E */ + gain *= 0.96f; + for( i=0; i< L_frame; i++ ) + { + exc_tmp[i] *= gain; + } + + mvr2r(&exc_tmp[L_frame - L_EXC_MEM], exc, L_EXC_MEM); + + return; +} + +short FEC_enhACB( + const short L_frame, /* i : frame length */ + const short last_L_frame, /* i : frame length of last frame */ + float *exc_io, /* i/o : adaptive codebook memory */ + const short new_pit, /* i : decoded first frame pitch */ + const short puls_pos, /* i : decoder position of the last glottal pulses decoded in the previous frame */ + const float bfi_pitch /* i : pitch used for concealment */ +) +{ + short Tc, P0, sign, pit_search; + short Tlist[10], Terr, diff_pit, dist_Plast; + float ftmp; + float exc[L_FRAME16k + L_SUBFR]; + short do_WI = 1; + + set_f(exc, 0.0f, L_FRAME16k - L_EXC_MEM); + set_f(exc+L_FRAME16k, 0.0f, L_SUBFR); + mvr2r(exc_io, exc + L_FRAME16k - L_EXC_MEM, L_EXC_MEM); + + Tc = (short)bfi_pitch; + mvr2r(exc + L_FRAME16k - Tc, exc + L_FRAME16k, L_SUBFR); + + /*------------------------------------------------------------ + * Decode phase information transmitted in the bitstream + * (The position of the absolute maximum glottal pulse from + * the end of the frame and its sign) + *------------------------------------------------------------*/ + + P0 = puls_pos; + sign = 0; + if (P0 < 0) + { + sign = 1; + P0 = -P0; + } + + if( L_frame == L_FRAME ) + { + if( P0>PIT_MAX ) + { + P0 = PIT_MAX; /* Should never be the case, however... */ + } + } + else /* L_frame == L_FRAME16k */ + { + if( P0>PIT16k_MAX ) + { + P0 = PIT16k_MAX; /* Should never be the case, however... */ + } + } + + /*---------------------------------------------------------------------------------- + * Find the position of the first the maximum(minimum) lp_filtered pulse + * <----- Mem --->|<--------------------- L_frame ------------>|<----- L_SUBFR --->| + * |<-------pit_search----> | | + *----------------------------------------------------------------------------------*/ + + pit_search = Tc; + + Tlist[0] = findpulse( L_frame, exc+L_frame-pit_search , pit_search,DEC, &sign); + + Terr = (short) abs(pit_search-Tlist[0]-P0); + + dist_Plast = Tc-Tlist[0]; + + Tlist[1] = findpulse( L_frame, exc+L_frame-pit_search , pit_search+L_SUBFR,DEC, &sign); + + if(Terr > abs(Tlist[1]-Tc + P0)) + { + dist_Plast = Tc-Tlist[1]; + Terr = (short)abs(Tlist[1]-Tc + P0); + } + + diff_pit = (short)abs(new_pit - Tc); + ftmp = (float) (int)((float)L_frame/(float)Tc+0.5); + + if ( Terr <= ftmp * diff_pit + && Terr != 0 /* If Terr = 0, no resynchronization required */ + && Terr < L_SUBFR) /* prevent catastrophy search */ + { + /* perform excitation resynchronization here */ + do_WI = FEC_synchro_exc( L_frame, exc, P0, dist_Plast, Tc ); + mvr2r( exc + L_FRAME16k - L_EXC_MEM, exc_io, L_EXC_MEM ); + } + else + { + do_WI = 0; + } + + if( last_L_frame != L_FRAME16k ) + { + /* This is essential in case of bit rate switching + FEC*/ + do_WI = 0; + } + + return do_WI; +} + diff --git a/src/libs/libevs/lib_dec/FEC_adapt_codebook_fx.cpp b/src/libs/libevs/lib_dec/FEC_adapt_codebook_fx.cpp deleted file mode 100755 index df832c8b..00000000 --- a/src/libs/libevs/lib_dec/FEC_adapt_codebook_fx.cpp +++ /dev/null @@ -1,533 +0,0 @@ -/*==================================================================================== - EVS Codec 3GPP TS26.442 Apr 03, 2018. Version 12.11.0 / 13.6.0 / 14.2.0 - ====================================================================================*/ - -#include -#include "options.h" /* Compilation switches */ -#include "cnst_fx.h" /* Common constants */ -#include "rom_dec_fx.h" /* Decoder static table prototypes */ -#include "prot_fx.h" /* Function prototypes */ -#include "stl.h" - - -/*---------------------------------------------------------------------* - * FEC_SinOnset() - * - * Create an artificial onset when it is lost - *---------------------------------------------------------------------*/ -Word16 FEC_SinOnset_fx ( - Word16 *exc, /* i/o : exc vector to modify */ - Word16 puls_pos, /* i : last pulse position desired */ - const Word16 T0, /* i : Pitch information of the 1 subfr */ - Word32 enr_q, /* i : energy provide by the encoder */ - Word16 *Aq, /* i : A(z) filter Q12 */ - const Word16 L_frame /* i : frame length */ - ,const Word16 Qold -) -{ - Word16 P0, onset_len, sign, i, len, L_subfr, L_subfr2; - Word16 h1[L_SUBFR16k], mem[M], exc_tmp[L_FRAME16k+ MODE1_L_FIR_FER]; - Word16 *pt_end, *pt_exc, enr_LP, gain, H_low_s[5], exp_gain, exp2, tmp; - Word32 L_tmp; - Word16 Q_exc; - - sign = 0; - move16(); - Q_exc = Qold; - move16(); - L_subfr = L_SUBFR; - move16(); - if( sub(L_frame,L_FRAME16k) == 0 ) - { - L_subfr = L_SUBFR16k; - move16(); - } - - L_subfr2 = shl(L_subfr,1); - onset_len = s_max(T0, L_subfr2); - - P0 = puls_pos; - move16(); - - IF (P0 < 0) - { - sign = 1; - move16(); - P0 = negate(P0); - } - - test(); - test(); - IF ( sub(P0,PIT_MAX) > 0 && sub(L_frame,L_FRAME) == 0 ) - { - P0 = PIT_MAX; - move16();/* Should never be the case, however... */ - } - ELSE if ( sub(P0,PIT16k_MAX) > 0 && sub(L_frame,L_FRAME16k) == 0 ) - { - P0 = PIT16k_MAX; - move16(); /* Should never be the case, however... */ - } - set16_fx( exc_tmp, 0, add(L_frame, MODE1_L_FIR_FER)); /* Reset excitation vector */ - - /*-------------------------------------------------------------------------------* - * Find LP filter impulse response energy and Generate the scaled pulse prototype - *-------------------------------------------------------------------------------*/ - - set16_fx(h1, 0, L_subfr); /* Find the impulse response */ - set16_fx(mem, 0, M); - h1[0] = 1024; - move16(); - Syn_filt_s(1, Aq, M, h1, h1, L_subfr, mem, 0); - - - enr_LP = extract_h(Dot_product12(h1, h1, L_subfr, &exp_gain)); - exp_gain = sub(exp_gain, 10 + 10); /* h1 in Q10 */ - - /* divide by LP filter E, scaled by transmitted E */ - /* gain = (float)sqrt( enr_q / enr_LP ); */ - - enr_q = L_max(enr_q,1); - - exp2 = norm_l(enr_q); - tmp = extract_h(L_shl(enr_q, exp2)); - tmp = mult(tmp, 24576); /* multpiply by 1.5 */ - - IF(sub(tmp, 16384) < 0) - { - exp2 = add(exp2, 1); - tmp = shl(tmp, 1); - } - exp2 = sub(30, exp2); /* in Q15 */ - - - IF(sub(enr_LP, tmp) > 0) - { - enr_LP = shr(enr_LP, 1); - exp_gain = add(exp_gain, 1); - } - - tmp = div_s(enr_LP, tmp); - exp2 = sub(exp_gain, exp2); - - L_tmp = L_deposit_h(tmp); - L_tmp = Isqrt_lc(L_tmp, &exp2); - gain = round_fx(L_tmp); - - gain = mult_r(gain, 31457); /* multiply by .96 like floating point */ - exp2 = add(sub(exp2, 15), Q_exc); /* from Q15 to Q_exc */ - - /* Find if rescaling needed */ - tmp = extract_h(L_mult(H_low[2], gain)); - exp_gain = norm_s(tmp); - tmp = sub(exp_gain, exp2); /* difference */ - - IF(tmp < 0)/* Need to correct scaling */ - { - Q_exc = add(Q_exc, tmp); - exp2 = add(exp2, tmp); - } - /* Scale pulse "prototype" energy */ - /* Generate the scaled pulse */ - FOR(i = 0; i < MODE1_L_FIR_FER; i++) - { - L_tmp = L_mult(gain, H_low[i]); /* Q_exc*Q15 -> Q_exc */ - H_low_s[i] = round_fx(L_shl(L_tmp, exp2)); - } - /*------------------------------------------------------------------------------------------* - * Construct the harmonic part as a train of low-pass filtered pulses - *------------------------------------------------------------------------------------------*/ - move16(); - move16(); - move16(); - pt_exc = exc_tmp + sub(L_frame, add(add(1, MODE1_L_FIR_FER/2), P0)); /* beginning of the 1st pulse */ - pt_end = exc_tmp + onset_len; - len = (Word16) (pt_exc - pt_end); - - len = s_min(len, MODE1_L_FIR_FER); - IF(!sign) - { - - FOR(i = 0; i < len; i++) - { - /* The filter response would have E=1 in full band. */ - pt_exc[i] = add(pt_exc[i], H_low_s[i]); - move16(); - } - } - ELSE - { - FOR(i = 0; i < len; i++) - { - /* The filter response would have E=1 in full band. */ - pt_exc[i] = sub(pt_exc[i], H_low_s[i]); - move16(); - } - } - Copy(&exc_tmp[L_frame - L_EXC_MEM], exc, L_EXC_MEM); - return Q_exc; -} - -Word16 FEC_enhACB_fx( - const Word16 L_frame, /* i : frame length */ - const Word16 last_L_frame, /* i : frame length of previous frame */ - Word16 *exc_io, /* i/o : adaptive codebook memory */ - const Word16 new_pit, /* i : decoded first frame pitch */ - const Word16 puls_pos, /* i : decoder position of the last glottal pulses decoded in the previous frame */ - const Word16 bfi_pitch /* i : Q6 pitch used for concealment */ -) -{ - Word16 Tc, P0, sign, pit_search; - Word16 Tlist[10], Terr, diff_pit, dist_Plast; - Word16 tmp2; - Word16 exc[L_FRAME16k + L_SUBFR]; - Word16 Do_WI = 1; - move16(); - - - set16_fx(exc, 0, L_FRAME16k - L_EXC_MEM); - set16_fx(exc+L_FRAME16k, 0, L_SUBFR); - Copy(exc_io, exc + L_FRAME16k - L_EXC_MEM, L_EXC_MEM); - - Tc = shr(bfi_pitch,6); - Copy(exc + L_FRAME16k - Tc, exc + L_FRAME16k, L_SUBFR); - - /*------------------------------------------------------------ - * Decode phase information transmitted in the bitstream - * (The position of the absolute maximum glottal pulse from - * the end of the frame and its sign) - *------------------------------------------------------------*/ - - P0 = puls_pos; - move16(); - sign = 0; - move16(); - IF (P0 < 0) - { - sign = 1; - move16(); - P0 = negate(P0); - } - - IF( sub(L_frame,L_FRAME) == 0 ) - { - P0 = s_min(PIT_MAX, P0); - } - ELSE /* L_frame == L_FRAME16k */ - { - P0 = s_min(PIT16k_MAX, P0); - } - - /*---------------------------------------------------------------------------------- - * Find the position of the first the maximum(minimum) lp_filtered pulse - * <----- Mem --->|<--------------------- L_frame ------------>|<----- L_SUBFR --->| - * |<-------pit_search----> | | - *----------------------------------------------------------------------------------*/ - - pit_search = Tc; - move16(); - - Tlist[0] = findpulse_fx( L_frame, exc+sub(L_frame,pit_search) , pit_search,DEC, &sign); - - /*Terr = (short) abs(pit_search-Tlist[0]-P0);*/ - Terr = abs_s(sub(pit_search,add(Tlist[0],P0))); - - dist_Plast = sub(Tc,Tlist[0]); - - Tlist[1] = findpulse_fx( L_frame, exc+sub(L_frame,pit_search) , add(pit_search,L_SUBFR),DEC, &sign); - - - /*if(Terr > abs(Tlist[1]-Tc + P0))*/ - IF(sub(Terr,abs_s(add(sub(Tlist[1],Tc), P0))) > 0) - { - dist_Plast = sub(Tc,Tlist[1]); - Terr = abs_s(add(sub(Tlist[1],Tc), P0)); - } - - diff_pit = abs_s(sub(new_pit, Tc)); - /*ftmp = (float) (int)((float)L_frame/(float)Tc+0.5);*/ - tmp2 = mult_r(div_s(16, Tc), shr(L_frame,4)); - test(); - test(); - IF (sub(Terr, i_mult(tmp2, diff_pit)) <= 0 && - Terr != 0 && /* If Terr = 0, no resynchronization required */ - sub(Terr, L_SUBFR) < 0 )/* prevent catastrophy search */ - { - /* performe excitation resynchronization here */ - Do_WI = FEC_synchro_exc_fx( L_frame, exc, P0, dist_Plast, Tc ); - move16(); - Copy(exc + L_FRAME16k - L_EXC_MEM, exc_io, L_EXC_MEM); - } - ELSE - { - Do_WI = 0; - move16(); - } - - if( sub(last_L_frame, L_FRAME16k) != 0 ) - { - Do_WI = 0; - move16(); - } - - return Do_WI; -} - -Word16 FEC_synchro_exc_fx( /* o : do_WI flag */ - const Word16 L_frame, /* i : length of the frame */ - Word16 *exc, /* i/o: exc vector to modify */ - const Word16 desire_puls_pos, /* i : Pulse position send by the encoder */ - const Word16 true_puls_pos, /* i : Present pulse location */ - const Word16 Old_pitch /* i : Pitch use to create temporary adaptive codebook */ -) -{ - Word16 exc_tmp[L_FRAME16k+L_SUBFR]; - Word16 fact; - Word32 L_min_energy, L_tmp; - Word16 *pt_exc, *pt_exc1; - Word16 i, j, point_to_remove, point_to_add, nb_min; - Word16 min_pos[L_FRAME16k/PIT_MIN_DOUBLEEXTEND], points_by_pos[L_FRAME16k/PIT_MIN_DOUBLEEXTEND]; - Word16 total_point, tmp_len; - Word16 *pt_pos, pos, start_search, tmp16; - Word16 remaining_len; - - point_to_add = -1; - move16(); - - /* Init */ - FOR (i = 0; i < L_FRAME16k/PIT_MIN_DOUBLEEXTEND; i++) - { - min_pos[i] = 10000; - move16(); - points_by_pos[i] = 0; - move16(); - } - - /* Find number of point to remove and number of minimum */ - point_to_remove = sub(true_puls_pos, desire_puls_pos); /* if it is negative it means remove point else it means add point */ - - pos = sub(L_frame, true_puls_pos); - - /* Find number of minimum energy region */ - /* nb_min = (L_FRAME - true_puls_pos)/Old_pitch */ - tmp16 = shl(Old_pitch, 5); - tmp16 = div_s(pos, tmp16); - nb_min = shr(tmp16, 10); - /* if Old pitch < 128, must have at least 2 min */ - if (sub(Old_pitch, 128) <= 0) - { - nb_min = s_max(nb_min, 2); - } - /* Must have at least 1 min */ - nb_min = s_max(nb_min, 1); - - pt_exc = exc + pos; - move16(); - - /* Find starting point for minimum energy search */ - start_search = mult_r(Old_pitch, -24576); - if(sub(s_and(Old_pitch,3),1) ==0) - { - /* Only be align with integer operation -3*Old_pitch/4 */ - start_search = add(start_search,1); - } - IF (add(start_search, pos) < 0) - { - start_search = negate(pos); - IF (sub(abs_s(start_search), shr(Old_pitch, 3)) < 0) - { - /* it's not safe to remove/add point inside 1/8 of the pulse position */ - return 0; - } - } - - /* Find min energy in the first pitch section */ - /* -------------------------------------------------------------------- - * The minimum energy regions are determined by the computing the energy - * using a sliding 5-sample window. The minimum energy position is set - * at the middle of the window at which the energy is at minimum - * --------------------------------------------------------------------*/ - L_min_energy = L_add(MAX_32, 0); - L_tmp = L_mult(pt_exc[start_search], pt_exc[start_search]); - L_tmp = L_mac(L_tmp, pt_exc[start_search + 1], pt_exc[start_search + 1]); - L_tmp = L_mac(L_tmp, pt_exc[start_search + 2], pt_exc[start_search + 2]); - L_tmp = L_mac(L_tmp, pt_exc[start_search + 3], pt_exc[start_search + 3]); - L_tmp = L_mac(L_tmp, pt_exc[start_search + 4], pt_exc[start_search + 4]); - - IF (L_sub(L_tmp, L_min_energy) < 0) - { - L_min_energy = L_add(L_tmp, 0); - min_pos[0] = add(add(pos, start_search), 2); - } - - FOR (i = start_search; i < -5; i++) - { - L_tmp = L_msu(L_tmp, pt_exc[i], pt_exc[i]); - L_tmp = L_mac(L_tmp, pt_exc[i + 5], pt_exc[i + 5]); - - IF (L_sub(L_tmp, L_min_energy) < 0) - { - L_min_energy = L_add(0,L_tmp); /* sets to 'L_tmp' in 1 clock */ - min_pos[0] = add(add(pos, i), 2); - } - } - - FOR (j = 1; j < nb_min; j++) - { - min_pos[j] = sub(min_pos[j-1], Old_pitch); - /* If the first minimum is in the past, forget this minimum */ - IF (min_pos[j] < 0) - { - min_pos[j] = -10000; - move16(); - nb_min = sub(nb_min, 1); - } - } - - /* safety-measure against not properly initialized min_pos[] */ - IF( L_sub(L_min_energy, MAX_32) >= 0 ) - { - return 0; - } - - IF(sub(nb_min,16)>0) /* inv_sqi & sqi are built for a maximum of nb_min-2 = 14 values*/ - { - return 0; - } - /*-------------------------------------------------------------------- - * Determine the number of samples to be added or removed at each pitch - * cycle whereby less samples are added/removed at the beginning and - * more towards the end of the frame - * --------------------------------------------------------------------*/ - test(); - IF (sub(nb_min, 1) == 0 || sub(abs_s(point_to_remove), 1) == 0) - { - nb_min = 1; - move16(); - points_by_pos[0] = abs_s(point_to_remove); - } - ELSE - { - /* First position */ - /* fact = (float)fabs(point_to_remove) / sqi[nb_min-2]; (nb_min*nb_min) */ - fact = mult_r(shl(abs_s(point_to_remove), 7), inv_sqi[nb_min - 2]); /*Q7 */ - points_by_pos[0] = mult_r(fact, 256); /*Q7 */ - total_point = points_by_pos[0]; - move16(); - - FOR (i = 2; i <= nb_min; i++) - { - /* points_by_pos[i-1] = (Word16)(fact*(sqi[i-2]) - total_point+0.5) */ - points_by_pos[i - 1] = sub(shr(extract_l(L_mac0(64L, fact, sqi[i - 2])), 7), total_point); - total_point = add(total_point, points_by_pos[i-1]); - - /* ensure a constant increase */ - IF (sub(points_by_pos[i-1], points_by_pos[i-2]) < 0) - { - tmp16 = points_by_pos[i-2]; - move16(); - points_by_pos[i-2] = points_by_pos[i-1]; - move16(); - points_by_pos[i-1] = tmp16; - move16(); - } - } - } - /* -------------------------------------------------------------------- - * Sample deletion or insertion is performed in minimum energy regions. - * At the end of this section the last maximum pulse in the concealed - * excitation is forced to align to the actual maximum pulse position - * at the end of the frame which is transmitted in the future frame. - * --------------------------------------------------------------------*/ - if (point_to_remove > 0) - { - point_to_add = point_to_remove; - move16(); - } - - pt_exc = exc_tmp; - move16(); - pt_exc1 = exc; - move16(); - - i = 0; - move16(); - pt_pos = min_pos + sub(nb_min, 1); - - IF (point_to_add > 0)/* Samples insertion */ - { - remaining_len = L_frame; - move16(); - FOR (i = 0; i < nb_min; i++) - { - /* Copy section */ - /* Compute len to copy */ - tmp_len = *pt_pos; - move16(); - IF (i != 0) - { - /* Compute len to copy */ - tmp_len = sub(sub(*pt_pos, *(pt_pos+1)), points_by_pos[i-1]); - } - /*Copy section */ - Copy(pt_exc1, pt_exc, tmp_len); - remaining_len = sub(remaining_len, tmp_len); - pt_exc1 += tmp_len; - move16(); - pt_exc += tmp_len; - move16(); - - /* Find point to add and Add points */ - tmp16 = mult_r(*pt_exc1, -1638); - FOR (j = 0; j < points_by_pos[i]; j++) - { - *pt_exc++ = tmp16; - move16();/* repeat last point */ - tmp16 = negate(tmp16); - } - - remaining_len = sub(remaining_len, points_by_pos[i]); - pt_pos--; - } - /* Copy remaining data */ - Copy(pt_exc1, pt_exc, remaining_len); - /* Update true excitation vector */ - Copy(exc_tmp, exc, L_frame); - } - ELSE /* Samples deletion */ - { - remaining_len = L_frame; - move16(); - - FOR (i = 0; i < nb_min; i++) - { - /* Compute len to copy */ - tmp_len = *pt_pos; - move16(); - IF (i != 0) - { - /* Compute len to copy */ - tmp_len = sub(sub(*pt_pos, *(pt_pos+1)), points_by_pos[i-1]); - } - Copy(pt_exc1, pt_exc, tmp_len); - remaining_len = sub(remaining_len, tmp_len); - pt_exc1 += tmp_len; - move16(); - pt_exc += tmp_len; - move16(); - /* Remove points */ - FOR (j = 0; j < points_by_pos[i]; j++) - { - pt_exc1++; - } - pt_pos--; - } - /* Copy remaining data */ - Copy(pt_exc1, pt_exc, remaining_len); - /* Update true excitation vector */ - Copy(exc_tmp, exc, L_frame); - } - - return 1; - -} diff --git a/src/libs/libevs/lib_dec/FEC_clas_estim.cpp b/src/libs/libevs/lib_dec/FEC_clas_estim.cpp new file mode 100644 index 00000000..6625cfc8 --- /dev/null +++ b/src/libs/libevs/lib_dec/FEC_clas_estim.cpp @@ -0,0 +1,795 @@ +/*==================================================================================== + EVS Codec 3GPP TS26.443 Nov 13, 2018. Version 12.11.0 / 13.7.0 / 14.3.0 / 15.1.0 + ====================================================================================*/ + +#include +#include +#include +#include "cnst.h" +#include "options.h" +#include "prot.h" +#include "rom_com.h" +#include "stat_dec.h" + +/*-------------------------------------------------------------------* + * Local constants + *-------------------------------------------------------------------*/ + +#define K_COR_DEC 0.8547f /* <-0.29, 0.88> */ +#define C_COR_DEC 0.2479f + +#define K_TILT_DEC 0.8333f /* <-0.35, 0.85> */ +#define C_TILT_DEC 0.2917f + +#define K_ZC_DEC -0.04f /* <63, 38> */ +#define C_ZC_DEC 2.52f + +#define K_ENR_DEC 0.04f /* <-14, 11> */ +#define C_ENR_DEC 0.56f + +#define K_PC_DEC -0.0357f /* <45, 17> */ +#define C_PC_DEC 1.6071f + +/*-------------------------------------------------------------------* + * Local functions + *-------------------------------------------------------------------*/ + +static float calculate_zero_crossings( const float *synth, const short L_frame ); + +static float calculate_pitch_synchr_norm_correlation( const float *pitch, const float *synth, const short L_frame, const short L_subfr ); + +static float calculate_spectral_tilt( const float *synth, const short nbSubfr, const short L_subfr ); + +static short calculate_classification_result( short const last_good, float fmerit1, float const ener, short const codec_mode ); + +static void FEC_ClassifierCore( const float *synth, const float *pitch, short const L_frame, const short codec_mode, short *clas, float *lp_speech, float *frame_ener, + float *ener, float *enern, float *class_para, const float LTP_Gain, const int narrowBand, const SIGNAL_CLASSIFIER_MODE mode ); + +static short FEC_dec_class( Decoder_State *st, const long core_brate, const short coder_type, float *enr_q, const short last_good ); + +static void FEC_classificationMusic( const short coder_type, short *decision_hyst, short *clas ); + + +/*------------------------------------------------------------------------* + * calculate_zero_crossings() + * + * + *------------------------------------------------------------------------*/ + +static float calculate_zero_crossings( + const float *synth, + const short L_frame +) +{ + short i; + float zc_frame; + + zc_frame = 0.f; + + for ( i = 0; i < L_frame; ++i ) + { + if ( (synth[i] <= 0.0f) && (synth[i-1] > 0.0f) ) + { + zc_frame += 1.0f; + } + } + + /* Renormalization for 12.8kHz core*/ + zc_frame *= 256.0f / (float)L_frame; + + return zc_frame; +} + +/*------------------------------------------------------------------------* + * calculate_pitch_synchr_norm_correlation() + * + * + *------------------------------------------------------------------------*/ + +static float calculate_pitch_synchr_norm_correlation( + const float *pitch, + const float *synth, + const short L_frame, + const short L_subfr +) +{ + short T0, pos; + short j, i; + float cor_max[16] = {0.f}; + float enr1t, enr2t, voicing; + + T0 = (short) pitch[3]; + + if ( T0 > (3 * (L_subfr / 2) )) + { + T0 = (short) ( 0.5f * ( pitch[2] + pitch[3]) + 0.5f ); + } + + pos = L_frame; + j = 0; + + while ( pos > (L_frame/L_subfr==4?3*L_subfr:4*L_subfr) ) + { + pos -= T0; + + cor_max[j] = dotp( &synth[pos], &synth[pos-T0], T0); + enr1t = dotp( &synth[pos-T0], &synth[pos-T0], T0); + enr2t = dotp( &synth[pos], &synth[pos], T0); + + cor_max[j] *= inv_sqrt( enr1t * enr2t + 0.1f ); + + + if ( (pos - T0) < (L_frame - L_subfr) ) + { + T0 = (short) ( 0.5f * ( pitch[2] + pitch[3] ) + 0.5f ); + } + j++; + } + + voicing = cor_max[0]; + + for ( i = 1; i < j; ++i ) + { + voicing += cor_max[i]; + } + + if( j > 1 ) + { + voicing /= j; + } + + return voicing; +} + + +/*------------------------------------------------------------------------* + * calculate_spectral_tilt() + * + * + *------------------------------------------------------------------------*/ + +static float calculate_spectral_tilt( + const float *synth, + const short nbSubfr, + const short L_subfr +) +{ + short i; + float tilt; + + float enr1t = 0.0f; + float enr2t = 0.0f; + float const* pt1 = synth + L_subfr; + float const* pt2 = synth + L_subfr - 1; + + for ( i = 0; i < nbSubfr-1; ++i ) + { + enr1t += dotp( pt1, pt1, L_subfr ); + enr2t += dotp( pt1, pt2, L_subfr ); + + pt1 += L_subfr; + pt2 += L_subfr; + } + + tilt = enr2t / ( enr1t + 0.1f ); + + return tilt; +} + +/*------------------------------------------------------------------------* + * calculate_classification_result() + * + * + *------------------------------------------------------------------------*/ +static short calculate_classification_result( + short const last_good, + float fmerit1, + float const ener, + short const codec_mode +) +{ + short result = UNVOICED_CLAS; + + switch ( last_good ) + { + case VOICED_CLAS: + case ONSET: + case SIN_ONSET: + case VOICED_TRANSITION: + + if ( fmerit1 < 0.39f ) + { + result = UNVOICED_CLAS; + } + else if ( fmerit1 < 0.63f && (codec_mode == MODE2 || ener < -15.0f) ) + { + result = VOICED_TRANSITION; + } + else + { + result = VOICED_CLAS; + } + break; + + case UNVOICED_CLAS: + case UNVOICED_TRANSITION: + case INACTIVE_CLAS: /* relevant for MODE2 only */ + + if ( fmerit1 > 0.56f ) + { + result = ONSET; + } + else if ( fmerit1 > 0.45f ) + { + result = UNVOICED_TRANSITION; + } + else + { + result = UNVOICED_CLAS; + } + break; + } + + return result; +} + + +/*------------------------------------------------------------------------* + * FEC_ClassifierCore() + * + * + *------------------------------------------------------------------------*/ + +static void FEC_ClassifierCore( + const float *synth, + const float *pitch, /* i : pitch values for each subframe */ + short const L_frame, /* i : length of the frame */ + const short codec_mode, /* i : codec mode */ + short *clas, /* i/o: frame classification */ + float *lp_speech, /* i/o: long term active speech energy average */ + float *frame_ener, /* o : */ + float *ener, /* o : */ + float *enern, /* o : */ + float *class_para, /* o : classification para. fmerit1 */ + const float LTP_Gain, /* i : */ + const int narrowBand, /* i : */ + const SIGNAL_CLASSIFIER_MODE mode /* i : */ +) +{ + float zc_frame; + float tiltn, corn, zcn, pcn, fmerit1, tilt; + float voicing; + float pc = 0.0f; + + /*------------------------------------------------------------------------* + * Compute the zero crossing rate for all subframes + *------------------------------------------------------------------------*/ + + zc_frame = calculate_zero_crossings(synth, L_frame); + + /*------------------------------------------------------------------------* + * Compute the normalized correlation pitch-synch at the end of the frame + *------------------------------------------------------------------------*/ + + voicing = calculate_pitch_synchr_norm_correlation(pitch, synth, L_frame, L_SUBFR); + + /*------------------------------------------------------------------------* + * Compute pitch coherence + *------------------------------------------------------------------------*/ + + pc = 0; /* just to remove MSVC warnings */ + if (codec_mode == MODE1 || !(LTP_Gain != -1.0f && mode == CLASSIFIER_TCX) ) + { + pc = (float) fabs( pitch[3] + pitch[2] - pitch[1] - pitch[0] ) * 256.0f / (float)L_frame; + } + + /*------------------------------------------------------------------------* + * Compute spectral tilt + *------------------------------------------------------------------------*/ + + tilt = calculate_spectral_tilt(synth, L_frame/L_SUBFR, L_SUBFR ); + + /*------------------------------------------------------------------------* + * Compute pitch-synchronous energy at the frame end + *------------------------------------------------------------------------*/ + + *ener = frame_energy( L_frame, pitch, synth, *lp_speech, frame_ener ); + + /*------------------------------------------------------------------------* + * transform parameters between 0 & 1 + * find unique merit function + *------------------------------------------------------------------------*/ + + *enern = K_ENR_DEC **ener + C_ENR_DEC; + tiltn = K_TILT_DEC * tilt + C_TILT_DEC; + corn = K_COR_DEC * voicing + C_COR_DEC; + zcn = K_ZC_DEC * zc_frame + C_ZC_DEC; + + if ( codec_mode == MODE2 && LTP_Gain != -1.0f && mode == CLASSIFIER_TCX ) + { + pcn = LTP_Gain * C_PC_DEC; + } + else + { + pcn = K_PC_DEC * pc + C_PC_DEC; + } + + if( pcn > 1.0f ) + { + pcn = 1.0f; + } + else if( pcn < 0.0f ) + { + pcn = 0.0f; + } + + fmerit1 = (1.0f / 6.0f ) * ( tiltn + 2.0f * corn + zcn + pcn + *enern ); + + if( codec_mode == MODE2 && narrowBand ) + { + fmerit1 *= 0.9f; + } + + /*------------------------------------------------------------------------* + * frame classification + *------------------------------------------------------------------------*/ + + if( codec_mode == MODE1 ) + { + *class_para = fmerit1; + } + *clas = calculate_classification_result(*clas, fmerit1, *ener, codec_mode); + + return; +} + + +/*------------------------------------------------------------------------* + * FEC_clas_estim() + * + * Estimation of frame class, if not available in the bitstream + *------------------------------------------------------------------------*/ + +void FEC_clas_estim( + const float *syn, + const float *pitch, /* i : pitch values for each subframe */ + const short L_frame, /* i : length of the frame */ + const short coder_type, /* i : coder type */ + const short codec_mode, /* i : codec mode */ + float *mem_syn_clas_estim, /* i/o: memory of the synthesis signal for frame class estimation */ + short *clas, /* i/o: frame classification */ + float *lp_speech, /* i/o: long term active speech energy average */ + long const bitrate, /* i : Decoded bitrate */ + short const Opt_AMR_WB, /* i : flag indicating AMR-WB IO mode */ + short *decision_hyst, /* i/o: hysteresis of the music/speech decision */ + short *locattack, /* i/o: detection of attack (mainly to localized speech burst) */ + short *UV_cnt, /* i/o: number of consecutives frames classified as UV */ + float *LT_UV_cnt, /* i/o: long term consecutives frames classified as UV */ + float *Last_ener, /* i/o: last_energy frame */ + short *amr_io_class, /* i/o: classification for AMR-WB IO mode */ + float *lt_diff_etot, /* i/o: long-term total energy variation */ + float *class_para, /* o : classification para. fmerit1 */ + const float LTP_Gain, /* i : */ + const int narrowBand, /* i : */ + const SIGNAL_CLASSIFIER_MODE mode,/* i : */ + const int bfi, /* i : */ + const float preemph_fac, /* i : */ + const int tcxonly, /* i : */ + const int last_core_brate /* i : last core bitrate */ +) +{ + float diff_ener; + float mean_diff; + short i; + float ftmp_c, fcorr, dev; + float frame_ener = 0.0f; + float ener = 0.0f; + float enern = 0.0f; + float tmp; + float old_synth[L_SYN_CLAS_ESTIM], *synth; + + /* After Rate Switching st->last_core is reset to 0. Check for last_core_brate is needed */ + if((last_core_brate == SID_1k75 || last_core_brate == ACELP_6k60 || last_core_brate == ACELP_8k85 + || last_core_brate == ACELP_12k65 || last_core_brate == ACELP_14k25 || last_core_brate == ACELP_15k85 + || last_core_brate == ACELP_18k25 || last_core_brate == ACELP_19k85 || last_core_brate == ACELP_23k05 + || last_core_brate == ACELP_23k85) && !Opt_AMR_WB && codec_mode == MODE2 + && L_frame > L_FRAME) + { + int oldLenClasBuff, newLenClasBuff; + oldLenClasBuff = L_SYN_MEM_CLAS_ESTIM * L_FRAME/L_frame; + newLenClasBuff = L_SYN_MEM_CLAS_ESTIM; + lerp( &mem_syn_clas_estim[L_SYN_MEM_CLAS_ESTIM-oldLenClasBuff], &mem_syn_clas_estim[L_SYN_MEM_CLAS_ESTIM-newLenClasBuff], newLenClasBuff, oldLenClasBuff ); + } + + synth = old_synth + L_SYN_MEM_CLAS_ESTIM; /* Set pointer to current frame */ + mvr2r( mem_syn_clas_estim, old_synth, L_SYN_MEM_CLAS_ESTIM ); /* Copy old synthesis into local buffer */ + mvr2r( syn, synth, L_frame ); /* Copy current synthesis into local buffer */ + + /* TCX outputs non-pre-speech */ + if( codec_mode == MODE2 && mode == CLASSIFIER_TCX ) + { + tmp = syn[-1]; + preemph(synth, preemph_fac, L_frame, &tmp); + } + + /* Do the classification only + - MODE1: when the class is not transmitted in the bitstream + - MODE2: on good frames (classifier is also called for bfi=1) */ + if ((codec_mode == MODE1 && ( bitrate < ACELP_11k60 || coder_type <= UNVOICED || Opt_AMR_WB)) || + (codec_mode == MODE2 && bfi!=1 && !tcxonly )) + { + + /*------------------------------------------------------------------------* + * classification decision depending on coder_type information + *------------------------------------------------------------------------*/ + + if( coder_type == UNVOICED ) + { + *clas = UNVOICED_CLAS; + } + else if( coder_type == VOICED ) + { + *clas = VOICED_CLAS; + } + else if( coder_type == INACTIVE && !Opt_AMR_WB) + { + *clas = INACTIVE_CLAS; + } + else + { + /*------------------------------------------------------------------------* + * GC, TC and AC frames + *------------------------------------------------------------------------*/ + + FEC_ClassifierCore( synth, pitch, L_frame, codec_mode, clas, lp_speech, &frame_ener, &ener, + &enern, class_para, LTP_Gain, narrowBand, mode ); + } + + /*------------------------------------------------------------------------* + * Overwrite classification decision in case of music + *------------------------------------------------------------------------*/ + + if( codec_mode == MODE1 ) + { + FEC_classificationMusic( coder_type, decision_hyst, clas ); + } + + /*---------------------------------------------------------------------------------* + * Measure energy on active voice frames (to improve FEC performance) + *---------------------------------------------------------------------------------*/ + + if ( *clas == VOICED_CLAS ) + { + if ( ( codec_mode == MODE2 && coder_type == VOICED ) || + ( codec_mode == MODE1 && ( Opt_AMR_WB || (coder_type != GENERIC && coder_type != TRANSITION ) ) ) ) + { + enern = frame_energy( L_frame, pitch, synth, *lp_speech, &frame_ener ); + } + + *lp_speech = 0.99f * *lp_speech + 0.01f * frame_ener; + } + + if( codec_mode == MODE1 ) + { + /*---------------------------------------------------------------------------------* + * Overwrite classification decision to UNVOICED_CLAS in case of INACTIVE frame + *---------------------------------------------------------------------------------*/ + + if( coder_type == INACTIVE && *clas != INACTIVE_CLAS ) + { + *clas = UNVOICED_CLAS; + } + + /*---------------------------------------------------------------------------------* + * Classification refinement to improve noise coding (only in AMR-WB IO mode) + *---------------------------------------------------------------------------------*/ + + if( Opt_AMR_WB ) + { + *locattack = 0; + + + if( *clas == UNVOICED_CLAS + && coder_type != INACTIVE + ) + { + /* unvoiced signal but not silence */ + if( *lp_speech <= 40 ) + { + *UV_cnt = 16; + } + else + { + *UV_cnt -= 8; + } + } + else if ( + coder_type != INACTIVE + ) + { + /* neither unvoiced nor clean silence */ + (*UV_cnt)++; + } + + if( *UV_cnt > 300 ) + { + *UV_cnt = 300; + } + else if( *UV_cnt < 0 ) + { + *UV_cnt = 0; + } + + /* Update long-term average number of frames between UNVOICED */ + if( coder_type == INACTIVE ) + { + /* tends to speech if no activity */ + *LT_UV_cnt = 0.95f * *LT_UV_cnt; + + if ( *UV_cnt > 125 ) + { + *UV_cnt = 125; + } + } + else + { + *LT_UV_cnt = 0.9f * *LT_UV_cnt + 0.1f * *UV_cnt; + } + + /*-----------------------------------------------------------------------------* + * Compute frame energy difference + * IF long-term average is high and energy difference is relatively low + * classification is overwritten to AUDIO + * IF energy difference > 6.0dB + * consider an attack + *-----------------------------------------------------------------------------*/ + + diff_ener = ener - *Last_ener; + *Last_ener = ener; + *amr_io_class = *clas; + + if( *LT_UV_cnt > LT_UV_THR && diff_ener < 12.0f ) + { + *amr_io_class = AUDIO_CLAS; + } + + if( (diff_ener > 6.0f && *clas == AUDIO_CLAS) || (diff_ener > 9.0f) ) + { + *locattack = 1; + } + + /*------------------------------------------------------------------------* + * Compute statistical deviation of long-term energy variation and + * overwrite classification, if needed + *------------------------------------------------------------------------*/ + + if( coder_type != INACTIVE ) + { + /* calculate mean energy variation of past MAX_LT frames */ + mean_diff = 0.0f; + for (i = 1; i 5.0f ) + { + *amr_io_class = *clas; + *UV_cnt = (short)(80 + *UV_cnt*0.2f); + } + } + } + } + } + + /* update the memory of synthesis for frame class estimation */ + mvr2r( old_synth + L_frame, mem_syn_clas_estim, L_SYN_MEM_CLAS_ESTIM ); + + return; +} + + +/*------------------------------------------------------------------------* + * FEC_dec_class() + * + * Decode class and energy information + *------------------------------------------------------------------------*/ + +static short FEC_dec_class( + Decoder_State *st, /* i/o: decoder state structure */ + const long bitrate, /* i : core bitrate */ + const short coder_type, /* i : coder type */ + float *enr_q, /* i : decoded energy */ + const short last_good /* i : Last good FEC classification */ +) +{ + short clas, tmpS; + + clas = ONSET; + + if( coder_type != VOICED ) + { + /* decode the class */ + tmpS = (short)get_next_indice( st, FEC_BITS_CLS ); + + if( tmpS == 0 ) + { + clas = UNVOICED_CLAS; + } + else if( tmpS == 1 ) + { + if( last_good >= VOICED_TRANSITION ) + { + clas = VOICED_TRANSITION; + } + else + { + clas = UNVOICED_TRANSITION; + } + } + else if( tmpS == 2 ) + { + clas = VOICED_CLAS; + } + } + else + { + clas = VOICED_CLAS; + } + + /* decode the energy */ + if( bitrate > ACELP_13k20 && coder_type != TRANSITION && coder_type < AUDIO ) + { + tmpS = (short)get_next_indice( st, FEC_BITS_ENR ); + + /* convert from logarithmic to linear domain (the range is 0 : 1.55 : 96 dB) */ + *enr_q = (float)pow( 10.0f, ( (float)tmpS * FEC_ENR_STEP ) / 10.0f ); + } + + return clas; +} + + +/*------------------------------------------------------------------------* + * FEC_classificationMusic() + * + * + *------------------------------------------------------------------------*/ + +static void FEC_classificationMusic( + const short coder_type, /* i : coder type */ + short *decision_hyst, /* i/o: hysteresis of the music/speech decision */ + short *clas /* i/o: frame classification */ +) +{ + if( coder_type == AUDIO ) + { + (*decision_hyst) += 4; + } + else + { + (*decision_hyst)--; + } + + if( coder_type == INACTIVE ) + { + *decision_hyst -= 10; + } + + if( *decision_hyst > 200 ) + { + *decision_hyst = 200; + } + else if( *decision_hyst < 0 ) + { + *decision_hyst = 0; + } + + if( *decision_hyst > 16 && *clas < VOICED_CLAS && coder_type == AUDIO ) + { + *clas = VOICED_CLAS; + } + + return; +} + + +/*------------------------------------------------------------------------* + * FEC_pos_dec() + * + * Decode class, energy and last glottal pulse position at higher bitrates + * ( last glottal pulse position is encoded only in GENERIC frames ) + *------------------------------------------------------------------------*/ + +short FEC_pos_dec( + Decoder_State *st, /* i/o: decoder state structure */ + const short coder_type, /* i : coder type */ + const short last_good, /* i : last good classification */ + short *last_pulse_pos, /* o : last glotal pulse position in the lost ACB */ + short *clas, /* o : decoded classification */ + float *enr_q, /* o : decoded energy */ + const long core_brate /* i : decoded bitrate */ +) +{ + short pitch_index, T0, T0_frac, T0_min, T0_max; + short bit_pos_pitch_index, nBits; + + T0 = 0; + if( coder_type > UNVOICED ) + { + /* decode the clas and energy information */ + if( coder_type < AUDIO ) + { + *clas = FEC_dec_class( st, core_brate, coder_type, enr_q, last_good ); + + if( coder_type == GENERIC && *clas == VOICED_CLAS && ( last_good <= UNVOICED_CLAS || last_good == INACTIVE_CLAS) ) + { + *clas = SIN_ONSET; + } + } + + if( coder_type == GENERIC && core_brate > ACELP_24k40 ) + { + nBits = 0; + if( coder_type != AUDIO ) + { + /* find the number of bits */ + nBits = ACB_bits_16kHz_tbl[BIT_ALLOC_IDX_16KHZ(core_brate, coder_type, 0, 0)]; + } + + bit_pos_pitch_index = 71; /* 64 kbps WB,SWB and FB*/ + + if( core_brate <= ACELP_32k ) + { + bit_pos_pitch_index = 72; /* 32 kbp, WB*/ + if (st->bwidth > WB) + { + bit_pos_pitch_index = 73; /* 32 kbp, SWB, FB*/ + } + } + /* retrieve the pitch index */ + pitch_index = (short)get_indice( st, bit_pos_pitch_index, nBits ); + + /* decode pitch period */ + T0_min = PIT_MIN; + T0_max = PIT_MAX; + pit16k_Q_dec( pitch_index, 10, 1, &T0, &T0_frac, &T0_min, &T0_max, &st->BER_detect ); + + /* decode last pulse position */ + *last_pulse_pos = (short)get_next_indice( st, FEC_BITS_POS ); + + /* respect the sign */ + if (*last_pulse_pos >= 128) + { + *last_pulse_pos = -(*last_pulse_pos & 0x7F); + } + + if ( T0 >= 128 ) + { + *last_pulse_pos *= 2; + } + + if( st->BER_detect ) + { + *last_pulse_pos = 0; + } + } + } + + return T0; +} diff --git a/src/libs/libevs/lib_dec/FEC_clas_estim_fx.cpp b/src/libs/libevs/lib_dec/FEC_clas_estim_fx.cpp deleted file mode 100755 index be25ebbc..00000000 --- a/src/libs/libevs/lib_dec/FEC_clas_estim_fx.cpp +++ /dev/null @@ -1,937 +0,0 @@ -/*==================================================================================== - EVS Codec 3GPP TS26.442 Apr 03, 2018. Version 12.11.0 / 13.6.0 / 14.2.0 - ====================================================================================*/ - - -#include "options.h" /* Compilation switches */ -#include "cnst_fx.h" /* Common constants */ -#include "rom_com_fx.h" /* Static table prototypes */ -#include "prot_fx.h" /* Function prototypes */ -#include "stl.h" -#include "basop_util.h" - -/*-------------------------------------------------------------------* - * Local functions - *-------------------------------------------------------------------*/ - -static Word16 FEC_dec_class_fx( Decoder_State_fx *st_fx, const Word32 bitrate, const Word16 coder_type, Word32 *enr_q, const Word16 last_good); - -static void Corre(const Word16 *x,const Word16 *y,const Word16 l,Word16 *gain); - -/*---------------------------------------------------------------------* - * Local Constants - *---------------------------------------------------------------------*/ -#define UNS6 10923/2 -#define UNS5 13107/2 - -#define K_COR_FX 14004 /* Q14 0.8547f <-0.29, 0.88> */ -#define C_COR_FX 266180599 /* Q14+16 0.2479f */ - -#define K_TILT_FX 13653 /*Q14 0.8333f <-0.35, 0.85> */ -#define C_TILT_FX 313210491 /*Q14+16 0.2917f */ - -#define K_ZC_FX -1310 /*Q15 -0.04f <63, 38> */ -#define C_ZC_FX 2642416 /*11Q20 2.52 */ - -#define K_ENR_FX 1311 /*Q15 0.04 <-14, 11> */ -#define C_ENR_FX 9395241 /*Q8+16 0.56f */ - -#define K_PC_FX -1169 /*Q15 -0.0357f <45, 17> */ -#define C_PC_FX 105323 /*Q0+16 1.6071f */ - - - -/*======================================================================*/ -/* FUNCTION : FEC_clas_estim() */ -/*----------------------------------------------------------------------*/ -/* PURPOSE : Estimation of classification */ -/* information, if not available in the bitsream */ -/* */ -/*======================================================================*/ - -void FEC_clas_estim_fx( - Decoder_State_fx *st_fx , /* i/o: decoder state handle */ - const Word16 Opt_AMR_WB, /* i : flag indicating AMR-WB IO mode */ /*A*/ - const Word16 L_frame, /* i : length of the frame */ - Word16 *clas, /* i/o: frame classification */ - const Word16 coder_type, /* i : coder type */ - const Word16 *pitch, /* i : pitch values for each subframe (Q6)*/ - Word16 *syn, /* i : synthesis buffer */ - Word16 *lp_speech, /* i/o: long term active speech energy average Q8 */ - Word16 *decision_hyst, /* i/o: hysteresis of the music/speech decision */ /*A*/ - Word16 *UV_cnt, /* i/o: number of consecutives frames classified as UV */ /*A*/ - Word16 *LT_UV_cnt, /* i/o: long term consecutives frames classified as UV */ /*A*/ - Word16 *Last_ener, /* i/o: last_energy frame */ /*A*/ - Word16 *locattack, /* i/o: detection of attack (mainly to localized speech burst) */ /*A*/ - Word16 *lt_diff_etot, /* i/o: long-term total energy variation */ /*A*/ - Word16 *amr_io_class, /* i/o: classification for AMR-WB IO mode */ /*A*/ - const Word32 bitrate, /* i : Decoded bitrate */ /*A*/ - Word16 Q_syn, /* i : Synthesis scaling */ - Word16 *class_para, /* o : classification para. fmerit1 */ /*A*/ - Word16 *mem_syn_clas_estim, /* i/o: memory of the synthesis signal for frame class estimation */ - Word16 *Q_mem_syn, /* i/o: exponent for memory of synthesis signal for frame class estimation */ /*B*/ - Word16 LTP_Gain, /* i : LTP gain is 0..0.6 or -1 Q15 *//*B*/ - Word16 mode, /* i : signal classifier mode *//*B*/ - Word16 bfi, /* i : bad frame indicator *//*B*/ - Word32 last_core_brate /* i : bitrate of previous frame */ -) -{ - Word16 i, j, pos; - Word16 *pt1, *pt2, zc_frame, frame_ener =1 ,tmp_scale=0, tmp_scale_syn, tmp_scale_mem; - Word16 tiltn, corn, zcn, pcn, fmerit1, enern, ener = 0/*not necessary, just to quiet a warning so not cmplxty counted*/, tilt, diff_ener; - Word16 voicing, cor_max[4], *synth, tmp16, exp1, exp2; - Word32 Ltmp, Ltmp1; - Word16 tmpS, T0, pc, /*max,*/ tmp_x, tmp_y; - Word16 old_synth[L_SYN_MEM_CLAS_ESTIM + L_FRAME16k]; - Word16 nb_subfr; - Word16 pos_limit; - Word16 codec_mode, narrowBand, tcxonly,preemph_fac; - Word16 memmax; - - nb_subfr = shr(L_frame,6); - memmax = 0; - move16(); - tmp_scale_syn = 0; - move16(); - - codec_mode = st_fx->codec_mode; - tcxonly = st_fx->tcxonly; /* i : tcxonly flag *//*B*/ - narrowBand = st_fx->narrowBand; /* i : narrowband flag *//*B*/ - preemph_fac = st_fx->preemph_fac; /* i : preemphasis factor *//*B*/ - /*------------------------------------------------------------------------* - * Copy synthesized into local buffer - *------------------------------------------------------------------------*/ - - /* After Rate Switching st->last_core is reset to 0. Check for last_core_brate is needed */ - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - IF((L_sub(last_core_brate, SID_1k75)==0 || L_sub(last_core_brate, ACELP_6k60)==0 || L_sub(last_core_brate, ACELP_8k85)==0 - || L_sub(last_core_brate, ACELP_12k65)==0 || L_sub(last_core_brate, ACELP_14k25)==0 || L_sub(last_core_brate, ACELP_15k85)==0 - || L_sub(last_core_brate, ACELP_18k25)==0 || L_sub(last_core_brate, ACELP_19k85)==0 || L_sub(last_core_brate, ACELP_23k05)==0 - || L_sub(last_core_brate, ACELP_23k85)==0) && !Opt_AMR_WB && sub(codec_mode, MODE2)==0 - && sub(L_frame,L_FRAME) > 0) - { - Word16 oldLenClasBuff, newLenClasBuff; - oldLenClasBuff = extract_l(L_shr(Mpy_32_16_1(L_mult0(st_fx->last_L_frame_fx,getInvFrameLen(st_fx->L_frame_fx)/*Q21*/)/*Q21*/,L_SYN_MEM_CLAS_ESTIM/*Q0*/)/*Q6*/,6)/*Q0*/); - newLenClasBuff = L_SYN_MEM_CLAS_ESTIM; - move16(); - lerp( &mem_syn_clas_estim[L_SYN_MEM_CLAS_ESTIM-oldLenClasBuff], &mem_syn_clas_estim[L_SYN_MEM_CLAS_ESTIM-newLenClasBuff], newLenClasBuff, oldLenClasBuff ); - } - synth = old_synth + L_SYN_MEM_CLAS_ESTIM; - - /*Rescale synthesis mem buffer or synthesis buffer, if necessary - - allign them to the same scaling in case of switching MODE2->MODE1*/ - IF(sub(codec_mode, MODE2) == 0) - { - memmax=1; - move16(); - /*find maximum of mem syn*/ - FOR(i=0; i0) /*mem syn is bigger, scale it down*/ - { - tmp_scale_mem = negate(tmp_scale); - Scale_sig(mem_syn_clas_estim, L_SYN_MEM_CLAS_ESTIM, tmp_scale_mem); - } - ELSE /*synthesis is bigger, scale it down*/ - { - /*check for upscaling mem syn, first*/ - tmp_scale_mem = norm_s(sub(memmax,1)); - if (sub(memmax,1) == 0) - { - tmp_scale_mem = 14; - move16(); - } - tmp_scale_syn = sub(add(*Q_mem_syn, tmp_scale_mem), Q_syn); /*if this is negative, syn can be scaled down*/ - test(); - IF(tmp_scale_syn > 0 || sub(mode , 1/*CLASSIFIER_TCX*/) == 0) /*dont scale up syn, but scale mem_syn, adequately*/ - { - tmp_scale_mem = sub(tmp_scale_mem,tmp_scale_syn); - tmp_scale_syn = 0; - move16(); - } - - Scale_sig( mem_syn_clas_estim, L_SYN_MEM_CLAS_ESTIM, tmp_scale_mem ); - *Q_mem_syn = add(*Q_mem_syn, tmp_scale_mem); - } - - } - - tmp_scale = -1; - move16(); - - Copy_Scale_sig( mem_syn_clas_estim, old_synth, L_SYN_MEM_CLAS_ESTIM, tmp_scale ); - Copy_Scale_sig( syn, synth, L_frame, add(tmp_scale_syn, tmp_scale) ); - - /*Tell MODE2 decoder the scaling of the buffer*/ - *Q_mem_syn = add(add(Q_syn, tmp_scale_syn), tmp_scale); - - /**Q_mem_syn = *Q_syn; move16();*/ - - test(); - IF(sub(codec_mode,MODE2) == 0 && sub(mode , 1/*CLASSIFIER_TCX*/)==0 ) - { - /* TCX outputs non-pe-speech */ - move16(); - tmp16 = shl(syn[-1],tmp_scale); /*dont forget to scale the mem*/ - preemph_copy_fx(synth, synth, preemph_fac, L_frame, &tmp16); - } - - /*------------------------------------------------------------------------* - * GC, TC and AC frames - *------------------------------------------------------------------------*/ - /* Do the classification only - - MODE1: when the class is not transmitted in the bitstream - - MODE2: on good frames (classifier is also called for bfi=1) */ - test(); - test(); - test(); - test(); - test(); - test(); - IF (( sub(codec_mode , MODE1) == 0 && ( L_sub(bitrate , ACELP_11k60) < 0 - || sub(coder_type , UNVOICED) <= 0 || Opt_AMR_WB)) || - (sub(codec_mode , MODE2) == 0 && sub(bfi,1) != 0 && !tcxonly )) - - { - /*------------------------------------------------------------------------* - * Overwrite classification decision using coder_type information - *------------------------------------------------------------------------*/ - test(); - IF( sub(coder_type,VOICED) == 0 ) - { - *clas = VOICED_CLAS; - move16(); - } - ELSE IF( sub(coder_type,UNVOICED) == 0 ) - { - *clas = UNVOICED_CLAS; - move16(); - } - ELSE IF( sub(coder_type,INACTIVE) == 0 && !Opt_AMR_WB) - { - *clas = INACTIVE_CLAS; - move16(); - } - ELSE - { - /*------------------------------------------------------------------------* - * Compute the zero crossing rate for all subframes - *------------------------------------------------------------------------*/ - - pt1 = (Word16 *)synth - 1; - move16(); - tmpS = shr(*pt1, 15); /* sets 'tmpS to -1 if *pt1 < 0 */ - Ltmp = L_deposit_l(0); - FOR (j = 0; j < L_SUBFR*nb_subfr; j++) - { - tmp16 = add(1, tmpS); - pt1++; - if(*pt1 != 0) /* Do only count zero crossing, no zero touchings */ - { - tmpS = shr(*pt1, 15); /* 1Clk: >=0 ---> 0 OTHERWISE -1 */ - } - Ltmp = L_msu0(Ltmp, tmpS, tmp16); - } - - zc_frame = shl(extract_l(Ltmp),4); /* Q4 */ - - if( sub(L_frame,L_FRAME16k) == 0) - { - /*zc_frame *= 0.8f;*/ /* Renormalization for 12.8kHz core*/ - zc_frame = mult_r(zc_frame, 26214); - } - - - /*------------------------------------------------------------------------* - * Compute the normalized correlation pitch-synch. at the end of the frame - *------------------------------------------------------------------------*/ - T0 = shr(pitch[3], 6); - Ltmp1 = L_mult(pitch[3], 256); - - if (sub(T0, L_SUBFR*3/2) > 0) - { - T0 = mac_r(Ltmp1, pitch[2], 256); - } - - - pt1 = synth; - move16(); - pos = sub(L_frame, T0); /* T0 [34 231] */ - - - Corre(&pt1[pos], &pt1[pos-T0], T0, &cor_max[0]); - T0 = mult_r(add(pitch[2], pitch[3]), 256); - pos_limit = sub(L_frame, L_SUBFR); - j = s_min(1, s_max(0, sub(pos, pos_limit))); - Ltmp = L_deposit_l(cor_max[0]); - IF (j > 0) - { - j = 16384; - move16(); - pos = sub(pos, T0); /* T0 [34 231] */ - Corre(&pt1[pos], &pt1[pos-T0], T0, &cor_max[1]); - Ltmp = L_add(Ltmp, cor_max[1]); - IF (sub(pos, pos_limit) > 0) - { - j = 10923; - move16(); - pos = sub(pos, T0); /* T0 [34 231] */ - Corre(&pt1[pos], &pt1[pos-T0], T0, &cor_max[2]); - Ltmp = L_add(Ltmp, cor_max[2]); - } - IF (sub(pos, pos_limit) > 0) - { - j = 8192; - move16(); - pos = sub(pos, T0); /* T0 [34 231] */ - Corre(&pt1[pos], &pt1[pos-T0], T0, &cor_max[3]); - Ltmp = L_add(Ltmp, cor_max[3]); - } - } - - voicing = cor_max[0]; - move16(); - IF(j > 0) - { - voicing = extract_l(Mult_32_16(Ltmp, j)); - } - /*------------------------------------------------------------------------* - * Compute pitch coherence - *------------------------------------------------------------------------*/ - - pc = 0; - move16(); - test(); - test(); - IF (sub(codec_mode , MODE1) == 0 || !(sub(LTP_Gain , -32768/*-1.f Q15*/) != 0 && sub(mode , CLASSIFIER_TCX) == 0) ) - { - pc = shr(abs_s(sub(add(pitch[3], sub(pitch[2], pitch[1])), pitch[0])), 6); - - if(sub(L_frame,L_FRAME16k) == 0) - { - pc = mult_r(pc, 26214); /* Renormalization for 12.8kHz core*/ - } - } - - /*------------------------------------------------------------------------* - * Compute spectral tilt - *------------------------------------------------------------------------*/ - pt1 = (Word16 *)synth + L_SUBFR; - move16(); - pt2 = (Word16 *)synth + L_SUBFR - 1; - move16(); - Ltmp = L_mult0(*pt1, *pt1); - Ltmp1 = L_mult0(*pt1, *pt2); - FOR(j = 1; j < L_SUBFR*(nb_subfr-1); j++) - { - pt1++; - pt2++; - Ltmp = L_mac0(Ltmp, *pt1, *pt1); - Ltmp1 = L_mac0(Ltmp1, *pt1, *pt2); - } - tilt = 0; - move16(); - - IF (Ltmp != 0) - { - BASOP_SATURATE_WARNING_OFF - tmp16 = extract_l(L_or(L_shr(Ltmp1, 32), 1)); /* sets a flag -1 or 1 for sign of Ltmp1 */ - BASOP_SATURATE_WARNING_ON - Ltmp1 = L_abs(Ltmp1); - exp1 = norm_l(Ltmp1); - tmp_y = extract_h(L_shl(Ltmp1, exp1)); - exp1 = sub(31-1+3, exp1); - exp2 = norm_l(Ltmp); - tmp_x = extract_h(L_shl(Ltmp, exp2)); - exp2 = sub(31-1+3, exp2); - BASOP_SATURATE_WARNING_OFF - tmpS = shr(sub(tmp_x, tmp_y), 16); /* if tmp_x >= tmp_y tmpS = 0, -1 otherwise */ - BASOP_SATURATE_WARNING_ON - tmp_y = shl(tmp_y, tmpS); - exp1 = sub(exp1, tmpS); - - tilt = div_s(tmp_y, tmp_x); - tilt = shl(tilt, sub(exp1, exp2)); /* saturate to 1.0 */ - - tilt = i_mult2(tilt, tmp16); - } - - /*------------------------------------------------------------------------* - * Compute pitch-synchronous energy at the frame end - *------------------------------------------------------------------------*/ - ener = frame_energy_fx(L_frame, pitch, synth, *lp_speech, &frame_ener, *Q_mem_syn); - - /*------------------------------------------------------------------------* - * transform parameters between 0 & 1 - * find unique merit function - *------------------------------------------------------------------------*/ - enern = mac_r(C_ENR_FX, K_ENR_FX, ener); /*Q8*/ - - tiltn = extract_h(L_shr(L_mac(C_TILT_FX, K_TILT_FX, tilt), 6)); /*Q14 -> Q8*/ - - corn = extract_h(L_shr(L_mac(C_COR_FX, K_COR_FX, voicing), 6)); /*Q14 -> Q8*/ - - zcn = extract_h(L_shl(L_mac(C_ZC_FX, K_ZC_FX, zc_frame), 4)); /* Q4 -> Q8*/ - - BASOP_SATURATE_WARNING_OFF - tmp16 = sub(LTP_Gain , -32768/*-1.f Q15*/); - BASOP_SATURATE_WARNING_ON - test(); - test(); - IF ( sub(codec_mode , MODE2) == 0 && tmp16 != 0 && sub(mode , CLASSIFIER_TCX) == 0 ) - { - pcn = round_fx(L_shl(Mpy_32_16_1(C_PC_FX/*Q16*/, LTP_Gain/*Q15*/),8)); /*Q16*/ - } - ELSE - { - pcn = extract_h(L_shl(L_mac(C_PC_FX, K_PC_FX, pc),8)); /* Q0 -> Q8*/ - } - - pcn = s_min(256, pcn); - pcn = s_max( 0, pcn); - /* fmerit1 = (1.0f/6.0f) * (tiltn + 2.0f*corn + zcn + pcn + enern) */ - Ltmp = L_mult(tiltn, UNS6); - Ltmp = L_mac(Ltmp, corn, 2*UNS6); - Ltmp = L_mac(Ltmp, zcn, UNS6); - Ltmp = L_mac(Ltmp, pcn, UNS6); - Ltmp = L_mac(Ltmp, enern, UNS6); - BASOP_SATURATE_WARNING_OFF - fmerit1 = round_fx(L_shl(Ltmp, 15-8)); /*Q15 can saturate to 1.0 */ - BASOP_SATURATE_WARNING_ON - test(); - if ( sub(codec_mode,MODE2) == 0 && narrowBand != 0 ) - { - fmerit1 = mult_r(fmerit1, 29491/*0.9f Q15*/); /* 0.90 */ - } - IF(sub(codec_mode, MODE1) == 0) - { - *class_para = round_fx(L_shl(Ltmp, 14-8)); /*Q14 - cannot be saturated, degrades HF synthesis */ - } - - /*------------------------------------------------------------------------* - * frame classification - *------------------------------------------------------------------------*/ - test(); - test(); - if ( (sub(coder_type,VOICED) != 0 && L_sub(bitrate,ACELP_11k60) < 0) || Opt_AMR_WB ) - { - Word16 result = UNVOICED_CLAS; - move16(); - SWITCH( *clas ) - { - case VOICED_CLAS: - case ONSET: - case SIN_ONSET: - case VOICED_TRANSITION: - IF(sub(fmerit1, 12780/*0.39f Q15*/) < 0) - { - result = UNVOICED_CLAS; - move16(); - } - ELSE IF(sub(fmerit1, 20644/*0.63f Q15*/) < 0 - && (add(ener,3840) < 0 || sub(codec_mode,MODE2) == 0)) - { - result = VOICED_TRANSITION; - move16(); - } - ELSE - { - result = VOICED_CLAS; - move16(); - } - - BREAK; - - case UNVOICED_CLAS: - case UNVOICED_TRANSITION: - case INACTIVE_CLAS: - IF( sub(fmerit1, 18350/*0.56f Q15*/) > 0 ) - { - result = ONSET; - move16(); - } - ELSE IF( sub(fmerit1, 14746/*0.45f Q15*/) > 0 ) - { - result = UNVOICED_TRANSITION; - move16(); - } - ELSE - { - result = UNVOICED_CLAS; - move16(); - } - BREAK; - - } - *clas = result; - move16(); - } - } - - - - IF(sub(codec_mode,MODE1)==0) - { - /*------------------------------------------------------------------------* - * Overwrite classification decision in case of music - *------------------------------------------------------------------------*/ - IF( sub(coder_type,AUDIO) == 0 ) - { - (*decision_hyst) = add(*decision_hyst,4); - move16(); - } - ELSE - { - (*decision_hyst) = sub(*decision_hyst,1); - move16(); - } - - if( sub(coder_type,INACTIVE) == 0 ) - { - *decision_hyst = sub(*decision_hyst,10); - move16(); - } - IF( sub(*decision_hyst,200) > 0 ) - { - *decision_hyst = 200; - move16(); - } - ELSE if( *decision_hyst < 0 ) - { - *decision_hyst = 0; - move16(); - } - - test(); - test(); - if( sub(*decision_hyst,16) > 0 && sub(*clas,VOICED_CLAS) < 0 && sub(coder_type,AUDIO) == 0 ) - { - *clas = VOICED_CLAS; - move16(); - } - } /*MODE1*/ - - /*---------------------------------------------------------------------------------* - * Measure energy on active voice frames (to improve FEC performance) - *---------------------------------------------------------------------------------*/ - IF( sub(*clas,VOICED_CLAS) == 0 ) - { - test(); - test(); - test(); - test(); - test(); - IF( (sub(codec_mode,MODE2) == 0 && sub(coder_type, VOICED) == 0) - || (sub(codec_mode,MODE1) == 0 && (Opt_AMR_WB || (sub(coder_type,GENERIC) != 0 && sub(coder_type,TRANSITION) != 0) ) ) - ) - { - /* pitch-synchronous energy at the frame end */ - enern = frame_energy_fx(L_frame,pitch, synth, *lp_speech, &frame_ener, *Q_mem_syn); - } - /* update of long-term active speech energy */ - Ltmp = L_mult0(655, frame_ener); /* 0.01 */ - *lp_speech = mac_r(Ltmp, 32440, *lp_speech); - move16(); /* lp_speech update */ - } - - IF(sub(codec_mode, MODE1) == 0) - { - - /*---------------------------------------------------------------------------------* - * Overwrite classification decision to UNVOICED_CLAS in case of INACTIVE frame - *---------------------------------------------------------------------------------*/ - test(); - if( sub(coder_type, INACTIVE) == 0 && sub(*clas,INACTIVE_CLAS) != 0 ) - { - *clas = UNVOICED_CLAS; - move16(); - } - - /*---------------------------------------------------------------------------------* - * Classification refinement to improve noise coding (only in AMR-WB IO mode) - *---------------------------------------------------------------------------------*/ - IF( Opt_AMR_WB ) - { - *locattack = 0; - move16(); - - /*-----------------------------------------------------------------------------* - * Unvoiced signal but not silence - *-----------------------------------------------------------------------------*/ - - test(); - IF( sub(*clas, UNVOICED_CLAS) == 0 && sub(coder_type, INACTIVE) != 0 ) - { - IF ( sub(*lp_speech, 40*256/*Q8*/) <= 0 ) - { - *UV_cnt = 16; - move16(); - } - ELSE - { - move16(); - *UV_cnt = sub(*UV_cnt, 8); - } - } - - /*-----------------------------------------------------------------------------* - * Neither unvoiced nor clean silence - * Number of frames between UV is increased - *-----------------------------------------------------------------------------*/ - - ELSE IF ( sub(coder_type, INACTIVE) != 0 ) - { - move16(); - *UV_cnt = add(*UV_cnt, 1); - } - - /*-----------------------------------------------------------------------------* - * Maximum/minimum number of frames between UV reached - *-----------------------------------------------------------------------------*/ - - /* Range 0..300 */ move16(); - *UV_cnt = s_max(s_min(300, *UV_cnt), 0); - - /*-----------------------------------------------------------------------------* - * IF VAD = 0 (no voice activity) - * long-term average updated towards to speech - * maximum number of frames between UV is limited to 125 - * Else - * update long-term average - *-----------------------------------------------------------------------------*/ - - IF ( sub(coder_type, INACTIVE) == 0 ) - { - move16(); - *LT_UV_cnt = mult_r(31130/*0.95f*/, *LT_UV_cnt); /* tend to speech if no activity */ - *UV_cnt = s_min(125, *UV_cnt); - move16(); - } - ELSE - { - /* *LT_UV_cnt = 0.9f * *LT_UV_cnt + 0.1f * *UV_cnt */ - - Ltmp = L_mult(3277/*0.1f*/, *UV_cnt); - /* Bring to Q22 */ - Ltmp = L_shl(Ltmp, 6); - /* Add to 0.9 x *LT_UV_cnt (Already in Q6) */ - Ltmp = L_mac(Ltmp, 29491/*0.9f*/, *LT_UV_cnt); /* Q22*/ - /* Store */ - *LT_UV_cnt = round_fx(Ltmp); - } - - /*-----------------------------------------------------------------------------* - * Compute frame energy difference - * IF long-term average is high and energy difference is relatively low - * classification is overwritten to AUDIO - * IF energy difference > 6.0dB - * consider an attack - *-----------------------------------------------------------------------------*/ - - diff_ener = sub(ener, *Last_ener); - *Last_ener = ener; - move16(); - *amr_io_class = *clas; - move16(); - test(); - if ( sub(*LT_UV_cnt, LT_UV_THR_FX) > 0 && sub(diff_ener, 12*256/*Q8*/) < 0 ) - { - move16(); - *amr_io_class = AUDIO_CLAS; - } - test(); - test(); - if ( (sub(diff_ener, 6*256/*Q8*/) > 0 && sub(*clas, AUDIO_CLAS) == 0) || sub(diff_ener, 9*256/*Q8*/) > 0 ) - { - *locattack = 1; - move16(); - } - - /*------------------------------------------------------------------------* - * Find mean of the past 40 frames energy variation - *------------------------------------------------------------------------*/ - - IF( sub(coder_type, INACTIVE) != 0 ) - { - Ltmp = L_deposit_l(0); - FOR (i = 1; i 0 ) - { - *amr_io_class = *clas; - move16(); - /* *UV_cnt = (short)(80 + *UV_cnt*0.2f) */ - *UV_cnt = add(80, mult(*UV_cnt, 6554)); - move16(); - } - } - } /*if (Opt_AMR_WB)*/ - } /*if (codec_mode==MODE1)*/ - - - } /* Do the classification only - - MODE1: when the class is not transmitted in the bitstream - - MODE2: on good frames (classifier is also called for bfi=1) */ - - - - /* update the memory of synthesis for frame class estimation */ - IF(sub(codec_mode,2)==0) - { - Copy( old_synth + L_frame, mem_syn_clas_estim, L_SYN_MEM_CLAS_ESTIM ); - } - ELSE - { - Copy_Scale_sig( old_synth + L_frame, mem_syn_clas_estim, L_SYN_MEM_CLAS_ESTIM, negate(tmp_scale) ); - *Q_mem_syn = sub(add(Q_syn, tmp_scale_syn), tmp_scale); - move16(); - } - - - return; -} - -static Word16 FEC_dec_class_fx( - Decoder_State_fx *st_fx, /* i/o: decoder state structure */ - const Word32 bitrate, /* i : core bitrate */ - const Word16 coder_type, /* i : coder type */ - Word32 *enr_q, /* i : decoded energy Q0 */ - const Word16 last_good /* i : Last good FEC classification */ -) -{ - Word16 clas, tmpS; - Word16 sfrac; - Word32 L_tmp; - - clas = ONSET; - move16(); - - IF( sub(coder_type,VOICED) != 0 ) - { - /* decode the class */ - tmpS = (Word16)get_next_indice_fx( st_fx, FEC_BITS_CLS ); - - IF( tmpS == 0 ) - { - clas = UNVOICED_CLAS; - move16(); - } - ELSE IF( sub(tmpS,1) == 0 ) - { - IF( sub(last_good,VOICED_TRANSITION) >= 0 ) - { - clas = VOICED_TRANSITION; - move16(); - } - ELSE - { - clas = UNVOICED_TRANSITION; - move16(); - } - } - ELSE IF( sub(tmpS,2) == 0 ) - { - clas = VOICED_CLAS; - move16(); - } - } - ELSE - { - clas = VOICED_CLAS; - move16(); - } - - /* decode the energy */ - test(); - test(); - IF( L_sub(bitrate,ACELP_14k80) >= 0 && sub(coder_type,TRANSITION) != 0 && sub(coder_type,AUDIO) < 0 ) - { - tmpS = (Word16)get_next_indice_fx( st_fx, FEC_BITS_ENR ); - /* convert from logarithmic to linear domain (the range is 0 : 3.0 : 96 dB) */ - tmpS = mult_r(shl(tmpS,10), 24576); /* Q10*Q13->Q8 */ - L_tmp = L_mult(tmpS, 10885); /* 0.332192 in Q15 */ - L_tmp = L_shr(L_tmp, 8); /* From Q24 to Q16 */ - sfrac = L_Extract_lc(L_tmp, &tmpS); - *enr_q = Pow2(tmpS, sfrac); - move32(); - } - - return clas; -} - -Word16 FEC_pos_dec_fx( - Decoder_State_fx *st_fx, /* i/o: decoder state structure */ - const Word16 coder_type, /* i : coder type */ - const Word16 last_good, /* i : last good classfication */ - Word16 *last_pulse_pos, /* o : last glotal pulse position in the lost ACB */ - Word16 *clas, /* o : decoded classification */ - Word32 *enr_q, /* o : decoded energy in Q0 */ - const Word32 core_brate /* i : decoded bitrate */ -) -{ - Word16 pitch_index, T0, T0_frac, T0_min, T0_max; - Word16 bit_pos_pitch_index, nBits; - - T0 = 0; - move16(); - IF( sub(coder_type,UNVOICED) > 0 ) - { - /* decode the clas and energy information */ - IF( sub(coder_type,AUDIO) < 0 ) - { - *clas = FEC_dec_class_fx( st_fx, core_brate, coder_type, enr_q, last_good); - move16(); - - test(); - test(); - test(); - IF( sub(coder_type,GENERIC) == 0 && sub(*clas,VOICED_CLAS) == 0 && ( sub(last_good,UNVOICED_CLAS) <= 0 || sub(last_good,INACTIVE_CLAS) == 0) ) - { - *clas = SIN_ONSET; - move16(); - } - } - - test(); - IF( sub(coder_type,GENERIC) == 0 && L_sub(core_brate,ACELP_24k40) > 0 ) - { - nBits = 0; - move16(); - IF( sub(coder_type,AUDIO) != 0 ) - { - nBits = ACB_bits_16kHz_tbl[BIT_ALLOC_IDX_16KHZ_fx(core_brate, coder_type, 0, 0)]; - move16(); - } - - /* use the absolute position of pitch index in the bitstream (this value is hard-coded and must be udpated when it changes in the encoder) */ - bit_pos_pitch_index = 71; - move16(); /* 64 kbps WB,SWB and FB*/ - if( L_sub(core_brate,ACELP_32k) <= 0 ) - { - bit_pos_pitch_index = 72; - move16(); /* 32 kbp, WB*/ - if(sub(st_fx->bwidth_fx,WB) > 0) - { - bit_pos_pitch_index = 73; - move16(); /* 32 kbp, SWB, FB*/ - } - } - - /* retrieve the pitch index */ - pitch_index = (Word16)get_indice_fx( st_fx, bit_pos_pitch_index, nBits ); - - /* decode pitch period */ - T0_min = PIT_MIN; - move16(); - T0_max = PIT_MAX; - move16(); - pit16k_Q_dec_fx( pitch_index, 10, 1, &T0, &T0_frac, &T0_min, &T0_max, &st_fx->BER_detect ); - - /* decode last pulse position */ - *last_pulse_pos = (Word16)get_next_indice_fx( st_fx, FEC_BITS_POS ); - - /* respect the sign */ - IF (sub(*last_pulse_pos,128) >= 0) - { - *last_pulse_pos = negate(s_and(*last_pulse_pos , 0x7F)); - move16(); - } - if ( sub(T0,128) >= 0) - { - *last_pulse_pos = add(*last_pulse_pos,*last_pulse_pos); - move16(); - } - - if( st_fx->BER_detect ) - { - *last_pulse_pos = 0; - move16(); - } - } - } - - return T0; -} -/*----------------------------------------------------------------------* - * Corre: - * - * Correlation function. Signal x is compared to target signal y - * Information about the similarity between vectors is returned in *gain - *----------------------------------------------------------------------*/ -static void Corre( - const Word16 *x, /* i : vector 1 Q12 */ - const Word16 *y, /* i : vector 2 Q12 */ - const Word16 l, /* i : length of vectors */ - Word16 *gain /* o : normalized correlation gain Q15 */ -) -{ - Word16 cor, cor_exp; - Word16 den, den_exp; - Word16 den2, den2_exp; - Word32 tmp; - Word16 tmp_exp; - - /* keep Q15 normalized result */ - cor = extract_h(Dot_product12(x, y, l, &cor_exp)); - den = add(extract_h(Dot_product12(y, y, l, &den_exp)), 1); - den2 = extract_h(Dot_product12(x, x, l, &den2_exp)); - - /* keep Q31 normalized result */ - tmp = L_mult(den, den2); - tmp_exp = norm_l(tmp); - tmp = L_shl(tmp, tmp_exp); - tmp_exp = sub(add(den_exp, den2_exp), tmp_exp); - - tmp = Isqrt_lc(tmp, &tmp_exp); - /* keep Q15 result */ - gain[0] = shl(mult_r(cor, extract_h(tmp)), add(cor_exp, tmp_exp)); - move16(); -} - diff --git a/src/libs/libevs/lib_dec/FEC_fx.cpp b/src/libs/libevs/lib_dec/FEC_fx.cpp deleted file mode 100755 index dd736e8d..00000000 --- a/src/libs/libevs/lib_dec/FEC_fx.cpp +++ /dev/null @@ -1,803 +0,0 @@ -/*==================================================================================== - EVS Codec 3GPP TS26.442 Apr 03, 2018. Version 12.11.0 / 13.6.0 / 14.2.0 - ====================================================================================*/ - -#include -#include "options.h" /* Compilation switches */ -#include "cnst_fx.h" /* Common constants */ -#include "rom_com_fx.h" /* Common static table prototypes */ -#include "rom_dec_fx.h" /* Decoder static table prototypes */ -#include "prot_fx.h" /* Function prototypes */ -#include "stl.h" -#include "basop_util.h" - -/*-------------------------------------------------------------------* - * Local functions - *-------------------------------------------------------------------*/ -static void pulseRes_preCalc(Word16* cond1, Word16* cond2, Word32* cond3 ,Word16 new_pit, Word16 Tc, Word16 L_frame); -void gain_dec_bfi_fx(Word16 *past_qua_en); -/*======================================================================*/ -/* FUNCTION : FEC_exc_estim_fx() */ -/*----------------------------------------------------------------------*/ -/* PURPOSE : Calculation of excitation signal */ -/* */ -/*----------------------------------------------------------------------*/ -/* GLOBAL INPUT ARGUMENTS : */ -/* _ (Struct) st_fx : decoder static memory */ -/* _ (Word16) L_frame_fx : length of the frame Q0 */ -/* _ (Word16) st_fx->lp_ener_fx : FEC - low-pass filtered energy Q6 */ -/* _ (Word16) st_fx->lp_gainc_fx : FEC - low-pass filtered code gain Q3 */ -/* _ (Word16) st_fx->old_pitch_buf : FEC buffer of old subframe pitch valuesQ6*/ -/* _ (Word16) st_fx->last_good : FEC - clas of last good received */ -/* _ (Word16) st_fx->bfi_pitch_fx : LP filter coefficient */ -/* _ (Word16) st_fx->upd_cnt_fx : FEC counter of frames since last update*/ -/* _ (Word16) st_fx->last_coder_type_fx: previous coder type */ -/* _ (Word16) st_fx->Last_GSC_pit_band_idx_fx: AC mode (GSC)Last pitch band index*/ -/* _ (Word16) st_fx->stab_fac_fx : LSF stability factor Q15 */ -/* _ (Word16) st_fx->tilt_code : tilt of code Q15 */ -/* _ (Word16) st_fx->last_voice_factor : coding type Q12 */ -/* _ (Word16) st_fx->opt_AMR_WB_fx : coding type Q12 */ -/* _ (Word16) st_fx->lp_gainp_fx : FEC -low-pass filtered pitch gain Q14 */ -/* _ (Word16) st_fx->seed :FEC-seed for random generator for excitation*/ -/* _ (Word16) st_fx->opt_OMR_WB:flag indicating AMR-WB IO mode */ -/*-----------------------------------------------------------------------*/ -/* OUTPUT ARGUMENTS : */ -/* _ (Word16[]) exc_fx : adapt. excitation exc (Q_exc) */ -/* _ (Word16[]) exc2_fx : adapt. excitation/total exc (Q_exc) */ -/* _ (Word16[]) bwe_exc_fx : excitation for SWB TBE (Q_exc) */ -/* _ (Word16[]) pitch_buf_fx : floating pitch values for each subframe Q6*/ -/* _ (Word16[]) voice_factors_fx : frame error rate Q15 */ -/* _ (Word16[]) FEC_pitch_fx(tmp_tc): FEC pitch Q6 */ -/*-----------------------------------------------------------------------*/ - -/* _ (Word16) st_fx->lp_gainp_fx : FEC -low-pass filtered pitch gain Q14 */ -/* _ (Word16) st_fx->seed :FEC-seed for random generator for excitation*/ -/* _ (Word16) st_fx->bfi_pitch_fx : LP filter coefficient */ -/* _ (Word16) st_fx->lp_gainc_fx : FEC - low-pass filtered code gain Q3 */ -/*-----------------------------------------------------------------------*/ -/* RETURN ARGUMENTS : */ -/* _ None */ -/*=======================================================================*/ - - -void FEC_exc_estim_fx( - Decoder_State_fx *st_fx, /* i/o: Decoder static memory */ - const Word16 L_frame, /* i : length of the frame */ - Word16 *exc, /* o : pointer to excitation buffer (with past) */ - Word16 *exc2, /* o : total excitation (for synthesis) */ - Word16 exc_dct_in[], /* o : GSC excitation in DCT domain */ - Word16 *pitch_buf, /* o : Floating pitch for each subframe */ - Word16 *voice_factors, /* o : voicing factors */ - Word16 *tmp_tc, /* o : FEC pitch Q6 */ - Word16 *bwe_exc, /* o : excitation for SWB TBE */ - Word16 *lsf_new, /* i : ISFs at the end of the frame */ - Word16 *Q_exc, - Word16 *tmp_noise /* o : long-term noise energy Q0 */ -) -{ - - Word16 exc2_buf[L_FRAME16k + MODE1_L_FIR_FER-1]; - Word16 gainCNG,new_pit /*Q0*/; /* Q3*/ - Word16 exp; - Word32 L_tmp,L_tmp2; - Word16 tmp,tmp1,tmp16; - Word16 delta; - Word16 i,j; - Word16 alpha; - Word16 gain,gain_inov; - Word16 Tc; - Word16 *pt_exc,*pt1_exc; - Word16 step; - Word32 L_step; - Word16 hp_filt[5]; - Word16 Diff_len,max_len,Len; - Word16 last_bin_fx, nb_subfr; - Word16 extrapolationFailed; - Word16 cond1, cond2; - Word32 cond3; - Word32 predPitchLag; - - /* nb_subfr = L_frame/L_SUBFR */ - nb_subfr = shr(L_frame, 6); - Diff_len = 0; /* to avoid compilation flags */ - set16_fx( exc_dct_in, 0, L_FRAME16k ); - - extrapolationFailed = 1; - move16(); - - gainCNG = 0; - move16(); - IF(st_fx->lp_ener_fx != 0) - { - exp = norm_l(st_fx->lp_ener_fx); /*lp_ener in Q6*/ - tmp = extract_h(L_shl(st_fx->lp_ener_fx,exp)); - exp = sub(exp, 30-6); - - tmp = div_s(16384, tmp); - L_tmp = L_deposit_h(tmp); - L_tmp = Isqrt_lc(L_tmp, &exp); - - gainCNG = round_fx(L_shl(L_tmp, sub(exp, 12))); /* In Q3 */ - - } - tmp1 = shl(st_fx->lp_gainc_fx,1); - gainCNG = s_min(gainCNG , tmp1); - set16_fx( exc_dct_in, 0, L_FRAME16k ); - - /*-----------------------------------------------------------------* - * pitch extrapolation - *-----------------------------------------------------------------*/ - - { - Word32 *tmp_old_pitch /*15Q16*/; - Word16 tmp_pitmin, tmp_pitmax; - - /*tmp_old_pitch = L_frame == L_FRAME ? &st_fx->old_pitch_buf_fx[2*NB_SUBFR-1] : &st_fx->old_pitch_buf_fx[2*NB_SUBFR16k-1];*/ - /*tmp_pitmin = L_frame == L_FRAME?PIT_MIN_DOUBLEEXTEND:PIT16k_MIN_EXTEND;*/ - /*tmp_pitmax = L_frame == L_FRAME?PIT_MAX:PIT16k_MAX;*/ - - tmp_old_pitch = &st_fx->old_pitch_buf_fx[2*NB_SUBFR16k-1]; - tmp_pitmin = PIT16k_MIN_EXTEND; - tmp_pitmax = PIT16k_MAX; - IF(sub(L_frame, L_FRAME) == 0) - { - tmp_old_pitch = &st_fx->old_pitch_buf_fx[2*NB_SUBFR-1]; - tmp_pitmin = PIT_MIN_DOUBLEEXTEND; - move16(); - tmp_pitmax = PIT_MAX; - move16(); - } - - - pitch_pred_linear_fit( - st_fx->nbLostCmpt, - st_fx->last_good_fx, - st_fx->old_pitch_buf_fx, - tmp_old_pitch, - &predPitchLag, - tmp_pitmin, - tmp_pitmax, - st_fx->mem_pitch_gain, - 0, - 0, - &extrapolationFailed, - nb_subfr); - - new_pit/*Q0 int*/ = shl(round_fx(predPitchLag),0); - } - - - - /*-----------------------------------------------------------------* - * estimate subframe pitch values for the FEC frame - *-----------------------------------------------------------------*/ - - /* initialize pitch to the long-term pitch */ - - *tmp_tc = st_fx->bfi_pitch_fx; - move16(); /*Q6*/ - IF( sub(L_frame,L_FRAME) == 0 ) - { - test(); - test(); - IF ( (sub(round_fx(L_shl(st_fx->old_pitch_buf_fx[2*NB_SUBFR-1], 6)), shl(mult(29491, st_fx->bfi_pitch_fx), 1)) < 0 && - sub(round_fx(L_shl(st_fx->old_pitch_buf_fx[2*NB_SUBFR-1], 6)), mult(19661, st_fx->bfi_pitch_fx)) > 0) || /* last pitch coherent with the past */ - sub(st_fx->upd_cnt_fx, MAX_UPD_CNT) >= 0) /* or last update too far in the past */ - { - /* take the pitch value of last subframe of the previous frame */ - *tmp_tc = round_fx(L_shl(st_fx->old_pitch_buf_fx[2*NB_SUBFR-1], 6)); - } - } - ELSE /* L_frame == L_FRAME16k */ - { - test(); - test(); - IF ( (sub(round_fx(L_shl(st_fx->old_pitch_buf_fx[2*NB_SUBFR16k-1], 6)), shl(mult(29491, st_fx->bfi_pitch_fx), 1)) < 0 && - sub(round_fx(L_shl(st_fx->old_pitch_buf_fx[2*NB_SUBFR16k-1], 6)), mult(19661, st_fx->bfi_pitch_fx)) > 0) || /* last pitch coherent with the past */ - sub(st_fx->upd_cnt_fx, MAX_UPD_CNT) >= 0) /* or last update too far in the past */ - { - /* take the pitch value of last subframe of the previous frame */ - *tmp_tc = round_fx(L_shl(st_fx->old_pitch_buf_fx[2*NB_SUBFR16k-1], 6)); - } - } - - /* convert pitch period */ - /* Tc = (short)(tmp_tc + 0.5f) */ - Tc = shr_r(*tmp_tc,6); - - /* estimate pitch values for all subframes */ - /*calculate conditions for Pulse resynchronization to take place*/ - pulseRes_preCalc( &cond1, &cond2, &cond3 , new_pit, Tc, L_frame); - - test(); - test(); - test(); - test(); - IF ((cond1 < 0 ) - && (new_pit > 0) && (cond2 != 0) - && (cond3 > 0) - && extrapolationFailed == 0 - ) - { - tmp16 = *tmp_tc; /*Q6*/ move16(); - IF(sub(nb_subfr,4)==0) - { - delta = shr(sub(shl(new_pit,6), *tmp_tc),2 ); /* 4 sub-frames */ - } - ELSE - { - delta = mult_r(sub(shl(new_pit,6), *tmp_tc),6554); /* 5 sub-frames */ - } - FOR (i = 0; i < nb_subfr; i++) /* subframe pitch values */ - { - /* fT0 += delta */ - tmp16 = add(tmp16, delta); - /* ptch_buf[i] = (short)(fT0 + 0.5) */ - pitch_buf[i] = shl(mult_r(tmp16, 512), 6); - move16(); - } - } - ELSE - { - FOR (i = 0; i < nb_subfr; i++) /* subframe pitch values for bass postfilter */ - { - pitch_buf[i] = *tmp_tc; - move16(); - } - } - - /*-----------------------------------------------------------------* - * estimate damping factor - *-----------------------------------------------------------------*/ - - /* rapid convergence to 0 */ - alpha = _ALPHA_VT_FX; - move16(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - IF( st_fx->last_coder_type_fx == UNVOICED && sub(st_fx->nbLostCmpt, 3) <= 0 ) - { - /* last good frame was clearly unvoiced */ - alpha = _ALPHA_UU_FX; - move16(); - } - ELSE IF( sub(st_fx->last_coder_type_fx,AUDIO) == 0 || sub(st_fx->last_good_fx,INACTIVE_CLAS) == 0 ) - { - test(); - IF( st_fx->Last_GSC_pit_band_idx_fx > 0 && sub(st_fx->nbLostCmpt,1) > 0 ) - { - alpha = 26214; - move16(); - } - ELSE IF( sub(st_fx->nbLostCmpt,5) <= 0 ) - { - alpha = 32604; - move16(); - } - ELSE - { - alpha = 31130; - move16(); - } - } - ELSE IF( sub(st_fx->last_good_fx,UNVOICED_CLAS) == 0 ) - { - IF( sub(st_fx->nbLostCmpt,1) <= 0) - { - /* if stable, do not decrease the energy, pitch_gain = 0 */ - alpha = mac_r((1L<<16)*2*_ALPHA_U_FX, st_fx->stab_fac_fx, 32768-2*_ALPHA_U_FX); /*st_fx->stab_fac_fx in Q15*/ - } - ELSE IF ( sub(st_fx->nbLostCmpt,2) == 0 ) - { - alpha =_ALPHA_S_FX; - move16(); /* ALPHA_U*1.5f = 0.6 */ - } - ELSE - { - alpha = _ALPHA_U_FX; - move16(); /* 0.4 go rapidly to CNG gain, pitch gain = 0 */ - } - } - ELSE IF( sub(st_fx->last_good_fx,UNVOICED_TRANSITION) == 0 ) - { - alpha = _ALPHA_UT_FX; - move16(); - } - ELSE IF( sub(st_fx->last_good_fx,ONSET) == 0 && sub(st_fx->nbLostCmpt,3) <= 0 && (sub(st_fx->last_coder_type_fx,GENERIC) == 0 || sub(st_fx->last_coder_type_fx,TRANSITION) == 0) ) - { - alpha = 26214; - move16(); /* mild convergence to 0 for the first 3 erased frames 0.8 in Q15 */ - } - ELSE IF( ( sub(st_fx->last_good_fx,VOICED_CLAS) == 0 || sub(st_fx->last_good_fx,ONSET) == 0 ) && sub(st_fx->nbLostCmpt,3) <= 0 ) - { - alpha = _ALPHA_V_FX; - move16(); /* constant for the first 3 erased frames */ - } - ELSE IF( sub(st_fx->last_good_fx,SIN_ONSET) == 0 ) - { - alpha = _ALPHA_S_FX; - move16(); - } - test(); - test(); - IF( sub(st_fx->last_good_fx,VOICED_CLAS) >= 0 && sub(st_fx->last_good_fx,INACTIVE_CLAS) < 0 && sub(st_fx->last_coder_type_fx,AUDIO) != 0 ) - { - IF( sub(st_fx->nbLostCmpt,1) == 0 ) /* if first erased frame in a block, reset harmonic gain */ - { - /* move pitch gain towards 1 for voiced to remove energy fluctuations */ - /*gain = (float)sqrt( st_fx->lp_gainp );*/ - st_fx->lp_gainp_fx = s_max(st_fx->lp_gainp_fx, 1); - exp = norm_s(st_fx->lp_gainp_fx); - tmp = shl(st_fx->lp_gainp_fx, exp); - tmp = div_s(16384, tmp); - L_tmp = L_deposit_h(tmp); - L_tmp = Isqrt_lc(L_tmp, &exp); - - gain = extract_h(L_shl(L_tmp, exp)); - - gain = s_min(gain, 32113); /*0.98 */ - gain = s_max(gain, 27853); /*0.85 */ - - alpha = mult_r(alpha, gain); - } - ELSE - { - /* st_fx->lp_gainp_fx is in Q14 when bfi_cnt > 1 to follow floating point because lp_gainp could be > than 1 */ - alpha = st_fx->lp_gainp_fx; - move16(); - } - } - - /*-----------------------------------------------------------------* - * construct the harmonic part of excitation - *-----------------------------------------------------------------*/ - test(); - test(); - test(); - test(); - IF( (sub(st_fx->last_good_fx,UNVOICED_TRANSITION) >= 0 && sub(st_fx->last_good_fx,INACTIVE_CLAS) < 0) || - ( (sub(st_fx->last_coder_type_fx,AUDIO) == 0 || sub(st_fx->last_good_fx,INACTIVE_CLAS) == 0) && st_fx->Last_GSC_pit_band_idx_fx > 0) ) - { - - pt_exc = exc; - move16(); - pt1_exc = pt_exc - Tc; - move16(); - - IF (sub(st_fx->nbLostCmpt,1) == 0) - { - /* first pitch cycle is low-pass filtered */ - - FOR (i = 0; i < Tc; i++) /* pitch cycle is first low-pass filtered */ - { - /* *pt_exc++ = (0.18f * pt1_exc[-1] + 0.64f * pt1_exc[0] + 0.18f * pt1_exc[1]) */ - L_tmp = L_mult(5898, pt1_exc[-1]); - L_tmp = L_mac(L_tmp, 20972, pt1_exc[0]); - *pt_exc++ = mac_r(L_tmp, 5898, pt1_exc[1]); - move16(); - pt1_exc++; - } - } - - /* last pitch cycle of the previous frame is repeatedly copied up to an extra subframe */ - - tmp = (Word16)((exc + L_frame + L_SUBFR) - pt_exc); - FOR (i = 0; i < tmp; i++) - { - *pt_exc++ = *pt1_exc++; - move16(); - } - - IF (new_pit > 0 ) - { - /*calculate conditions for Pulse resynchronization to take place*/ - pulseRes_preCalc( &cond1, &cond2, &cond3 , new_pit, Tc, L_frame); - - test(); - test(); - test(); - test(); - IF ((cond1 < 0 ) - && (new_pit > 0) && (cond2 != 0) - && (cond3 > 0) - && extrapolationFailed == 0 - ) - { - Copy(exc,exc-L_frame-L_SUBFR,L_frame+L_SUBFR); - PulseResynchronization(exc-L_frame-L_SUBFR, exc, L_frame, nb_subfr, L_deposit_h(Tc/*Q0*/)/*15Q16*/, L_deposit_h(new_pit/*Q0*/)/*15Q16*/); - } - } - test(); - test(); - IF( sub(st_fx->last_good_fx,UNVOICED_TRANSITION) == 0 && ( sub(st_fx->last_coder_type_fx,GENERIC) == 0 || sub(st_fx->last_coder_type_fx,TRANSITION) == 0 ) ) - { - /* start of the frame gain */ - gain = 0; - move16(); - - /* end of the frame gain */ - st_fx->lp_gainp_fx = 0; - move16(); - step = 0; - move16(); - } - ELSE - { - - /* start of the frame gain */ - gain = 16384; - move16(); - - /* end of the frame gain */ - test(); - - IF(!(sub(st_fx->last_good_fx,VOICED_CLAS) >= 0 && sub(st_fx->last_good_fx,INACTIVE_CLAS) < 0 && sub(st_fx->last_coder_type_fx,AUDIO) != 0 && sub(st_fx->nbLostCmpt, 1) > 0 )) - { - st_fx->lp_gainp_fx = shr(alpha,1); /* alpha in Q15 */ - } - ELSE - { - st_fx->lp_gainp_fx = alpha; - move16(); /* alpha in Q14 */ - } - - IF(sub(L_frame, L_FRAME) == 0) - { - step = shr(sub(gain,st_fx->lp_gainp_fx),8); - } - ELSE /*L_frame == L_FRAME16k*/ - { - /*step = (1.0f/L_frame) * (gain - st_fx->lp_gainp);*/ - - step = shr(mult_r(26214,sub(gain,st_fx->lp_gainp_fx)),8); /*Q14*/ - } - } - - FOR( i=0 ; i< L_frame; i++ ) - { - /* exc[i] *= gain */ - exc[i] = round_fx(L_shl(L_mult(exc[i], gain), 1)); /* in Q_exc */ - /* gain -= step */ - gain = sub(gain, step); - } - test(); - test(); - IF( (sub(st_fx->last_coder_type_fx,AUDIO) == 0 || sub(st_fx->last_good_fx,INACTIVE_CLAS) == 0) && st_fx->Last_GSC_pit_band_idx_fx > 0 ) - { - Diff_len = mfreq_loc_div_25[st_fx->Last_GSC_pit_band_idx_fx]; - move16(); - - /* Transform to frequency domain */ - edct_16fx( exc, exc_dct_in, st_fx->L_frame_fx, 5 ); - - /* Reset unvaluable part of the adaptive (pitch) excitation contribution */ - max_len = sub(st_fx->L_frame_fx,Diff_len); - Len = s_min( max_len, 80 ); - - move16(); /*ptr init*/ - FOR( i=0; ilast_good >= VOICED_TRANSITION" */ - - /*-----------------------------------------------------------------* - * Replicate the last spectrum in case the last good frame was coded by GSC - *-----------------------------------------------------------------*/ - test(); - test(); - test(); - IF( sub(st_fx->last_coder_type_fx,AUDIO) == 0 || (sub(st_fx->last_good_fx,INACTIVE_CLAS) == 0 && L_sub(st_fx->total_brate_fx,ACELP_24k40) <= 0 && !st_fx->Opt_AMR_WB_fx) ) - { - st_fx->GSC_noisy_speech_fx = st_fx->Last_GSC_noisy_speech_flag_fx; - move16(); - /* Replication of the last spectrum, with a slight downscaling of its dynamic */ - gsc_dec_fx( st_fx, exc_dct_in, st_fx->Last_GSC_pit_band_idx_fx, Diff_len, 0, st_fx->L_frame_fx/L_SUBFR, st_fx->last_coder_type_fx, &last_bin_fx, lsf_new, NULL, st_fx->Q_exc ); - *tmp_noise = shr_r(st_fx->lp_gainc_fx,3); /*Q0*/ - /* Transform back to time domain */ - edct_16fx( exc_dct_in, exc, st_fx->L_frame_fx, 5 ); - } - ELSE - { - /*-----------------------------------------------------------------* - * Construct the random part of excitation - *-----------------------------------------------------------------*/ - - /* generate the random part of the excitation */ - FOR (i=0; iseed_fx ),3); - move16(); - } - - /* start of the frame gain */ - gain = st_fx->lp_gainc_fx; - move16(); - - test(); - test(); - test(); - IF(!(sub(st_fx->last_good_fx,VOICED_CLAS) >= 0 && sub(st_fx->last_good_fx,INACTIVE_CLAS) < 0 && sub(st_fx->last_coder_type_fx,AUDIO) != 0 && sub(st_fx->nbLostCmpt, 1) > 0 )) - { - /* Here alpha is in Q15 and lp_gainc_fx in Q3 */ - /* st_fx->lp_gainc = alpha * st_fx->lp_gainc + (1.0f - alpha) * gainCNG; */ - L_tmp = L_mult(alpha, st_fx->lp_gainc_fx); - - st_fx->lp_gainc_fx = msu_r(L_tmp, add(alpha, -32768), gainCNG); - } - ELSE - { /* Here alpha is in Q14, but lp_gainc still in Q3 */ - /* st_fx->lp_gainc = alpha * st_fx->lp_gainc + (1.0f - alpha) * gainCNG; */ - L_tmp = L_mult(alpha, st_fx->lp_gainc_fx); /* Q14*Q3->Q18 */ - - st_fx->lp_gainc_fx = round_fx(L_shl(L_msu(L_tmp, add(alpha, -16384), gainCNG),1));/* (Q14*Q3<<1)>>16 ->Q3 */ - } - - test(); - test(); - test(); - if( sub(st_fx->last_good_fx,UNVOICED_TRANSITION) == 0 && ( sub(st_fx->last_coder_type_fx,GENERIC) == 0 || sub(st_fx->last_coder_type_fx,TRANSITION) == 0 ) && gainCNG > 0 ) - { - st_fx->lp_gainc_fx = gainCNG; - move16(); - } - - /* linearly attenuate the gain throughout the frame */ - /* step = (1.0f/L_FRAME) * (gain - *lp_gainc); */ - step = sub(gain,st_fx->lp_gainc_fx); /* divide by L_FRAME done later */ - test(); - if(sub(L_frame,L_FRAME16k) == 0) - { - step = mult_r(step,26214); /* L_frame16k-> L_frame and division by L_frame done later*/ - } - - /* calculate gain to normalize energy */ - pt_exc = exc2_buf + MODE1_L_FIR_FER/2; - move16(); - - /* To avoid saturation split the L_frame dot product into (L_frame/L_SUBFR) dot products - and scale down before adding */ - /* gain_inov = 1.0f / (float)sqrt( dotp( pt_exc, pt_exc, L_frame ) / L_frame + 0.01f ); */ - - L_tmp = L_deposit_l(0); - FOR (i = 0; i < 2; i++) - { - L_tmp2 = L_mult0(*pt_exc, *pt_exc); - pt_exc++; - FOR (j = 1; j < shr(L_frame,1); j++) - { - L_tmp2 = L_mac0(L_tmp2, *pt_exc, *pt_exc); /* Q-5 */ - pt_exc++; - } - L_tmp = L_add(L_tmp, L_shr(L_tmp2, 1)); /* Q-7 */ - } - test(); - if(sub(L_frame,L_FRAME16k) == 0) - { - L_tmp = Mult_32_16(L_tmp, 26214); /* x0.8 to normalize to 256 samples */ - } - exp = norm_l(L_tmp); - L_tmp = L_shl(L_tmp, exp); /* Normalize */ - exp = add(exp, 8-7); /* Q0, 8 ->divide by 256 */ - exp = sub(31, exp); /* For Denormalization in Q31 */ - L_tmp = Isqrt_lc(L_tmp, &exp);/* in Q(31-exp) */ - gain_inov = round_fx(L_tmp); - - /* attenuate somewhat on unstable unvoiced */ - test(); - test(); - if( (sub(st_fx->last_good_fx,UNVOICED_CLAS) == 0 || sub(st_fx->last_good_fx,INACTIVE_CLAS) == 0) && sub(st_fx->last_coder_type_fx,UNVOICED) != 0 ) - { - gain_inov = mult_r(gain_inov, 26214); - } - - /* scaling of the random part of excitation */ - pt_exc = exc2_buf; - move16(); - L_step = L_shr(L_mult(gain_inov, step), 8); /* here is the divide by L_FRAME */ - L_tmp2 = L_mult(gain_inov, gain); /* Q15 * Q3 -> Q3 */ - tmp = round_fx(L_tmp2); - exp = add(add(exp, *Q_exc), 15); /* 3+Q_exc+15 -> Q_exc+18 */ - - FOR( i=0; i< MODE1_L_FIR_FER/2; i++ ) - { - /* non-causal ringing of the FIR filter */ - /**pt_exc++ *= (gain_inov * gain);*/ - L_tmp = L_mult(tmp, *pt_exc); /* Q_exc+18 * Q-3 -> Q_exc+16 */ - *pt_exc++ = round_fx(L_shl(L_tmp, exp)); - } - - FOR( i=0; i< L_frame; i++ ) - { - /* the inner part of the FIR filter */ - /* *pt_exc++ *= (gain_inov * gain); */ - L_tmp = L_mult(tmp, *pt_exc); - *pt_exc++ = round_fx(L_shl(L_tmp, exp)); - /* gain -= step; */ - L_tmp2 = L_sub(L_tmp2, L_step); - tmp = round_fx(L_tmp2); - - } - - FOR (i = 0 ; i < MODE1_L_FIR_FER/2; i++) /* causal ringing of the FIR filter */ - { - /* *pt_exc++ *= (gain_inov * gain) */ - L_tmp = L_mult(tmp, *pt_exc); - *pt_exc++ = round_fx(L_shl(L_tmp, exp)); - } - } - - /*-----------------------------------------------------------------* - * Total excitation - *-----------------------------------------------------------------*/ - test(); - test(); - test(); - test(); - IF( (sub(st_fx->last_coder_type_fx,AUDIO) == 0 || sub(st_fx->last_good_fx,INACTIVE_CLAS) == 0) && L_sub(st_fx->total_brate_fx,ACELP_24k40) <= 0 && !st_fx->Opt_AMR_WB_fx) - { - /* For GSC - the excitation is already computed */ - Copy( exc, exc2, st_fx->L_frame_fx ); - } - ELSE IF( sub(st_fx->last_good_fx,UNVOICED_TRANSITION) >= 0 && sub(st_fx->last_good_fx,INACTIVE_CLAS) < 0 ) - { - /* For voiced and generic signals - prepare a HP filter for the random part of excitation */ - /* tmp = -(1-tilt_code) to correctly represent 1.0000 */ - tmp = add(st_fx->tilt_code_fx, -32768); - move16(); - FOR (i = 0; i < MODE1_L_FIR_FER; i++) - { - hp_filt[i] = msu_r(0, tmp, h_high_fx[i]); - move16(); - } - - /* HP filter the random part of the excitation and add the adaptive part */ - pt_exc = exc2_buf; - move16(); - FOR( i=0; i< L_frame; i++ ) - { - /* exc2[i] = exc[i] + dotp( &exc2_buf[i], hp_filt, MODE1_L_FIR_FER );*/ - L_tmp = L_mult(hp_filt[0], pt_exc[0]); - FOR (j = 1; j < MODE1_L_FIR_FER; j++) - { - L_tmp = L_mac(L_tmp, hp_filt[j], pt_exc[j]); - } - exc2[i] = msu_r(L_tmp, -32768, exc[i]); - move16(); - pt_exc++; - } - } - ELSE - { - /* For purely unvoiced signals - just copy the unfiltered random part of the excitation */ - Copy( exc2_buf + MODE1_L_FIR_FER/2, exc, L_frame ); - Copy( exc2_buf + MODE1_L_FIR_FER/2, exc2, L_frame ); - } - - IF( sub(L_frame,L_FRAME) == 0 ) - { - - interp_code_5over2_fx( exc, bwe_exc, L_frame ); - } - ELSE - { - interp_code_4over2_fx( exc, bwe_exc, L_frame ); - } - test(); - IF( sub(st_fx->last_coder_type_fx,AUDIO) == 0 || sub(st_fx->last_good_fx,INACTIVE_CLAS) == 0 ) - { - IF( sub(st_fx->L_frame_fx,L_FRAME) == 0 ) - { - set16_fx( voice_factors, 32767, NB_SUBFR ); - } - ELSE - { - set16_fx( voice_factors, 32767, NB_SUBFR16k ); - } - } - ELSE - { - IF( sub(st_fx->L_frame_fx,L_FRAME) == 0 ) - { - set16_fx( voice_factors, st_fx->last_voice_factor_fx, NB_SUBFR); /* The factor of the last subframe is propagated forward */ - } - ELSE - { - set16_fx( voice_factors, st_fx->last_voice_factor_fx, NB_SUBFR16k ); /* The factor of the last subframe is propagated forward */ - } - } - IF( st_fx->Opt_AMR_WB_fx ) - { - gain_dec_bfi_fx(st_fx->past_qua_en_fx); - } - st_fx->bfi_pitch_fx = pitch_buf[(L_frame/L_SUBFR)-1]; - move16(); - st_fx->bfi_pitch_frame_fx = st_fx->L_frame_fx; - move16(); - return; -} - - -/*calculates some conditions for Pulse resynchronization to take place*/ -static void pulseRes_preCalc(Word16* cond1, Word16* cond2, Word32* cond3 ,Word16 new_pit, Word16 Tc, Word16 L_frame) -{ - Word16 tmp_pit, tmp_pit_e, tmp_frame, tmp_frame_e; - Word32 tmp_pit2; - - tmp_pit = BASOP_Util_Divide1616_Scale(new_pit/*Q0*/,Tc/*Q0*/,&tmp_pit_e)/*Q15*/; - tmp_frame = add( extract_l(L_mult0(L_frame , 64/*1.f/L_SUBFR Q12*/)/*Q12*/) , 4096/*1.f Q12*/ );/*Q12*/ - tmp_frame = BASOP_Util_Divide1616_Scale(4096/*1.f Q12*/,tmp_frame, &tmp_frame_e);/*Q15*/ - tmp_frame = shl(tmp_frame,add(tmp_frame_e,1)); - tmp_frame = sub(32767/*1.f Q15*/, tmp_frame);/*Q15*/ - BASOP_SATURATE_WARNING_OFF - /*To calc Q15 threshold, overflow may happen - do negation and compare with negated value to check also highest possible value*/ - tmp_pit = shl(negate(tmp_pit),tmp_pit_e); - BASOP_SATURATE_WARNING_ON - *cond1 = sub(tmp_pit, negate(tmp_frame)); - - *cond2 = sub(Tc, new_pit); - - tmp_pit_e = BASOP_Util_Add_MantExp(new_pit,15-0,negate(Tc),15-0,&tmp_pit);/*Q15*/ - tmp_pit = abs_s(tmp_pit); - tmp_pit2 = L_mult(Tc,4915/*0.15f Q15*/);/*Q16*/ - BASOP_SATURATE_WARNING_OFF - /*To calc Q15 threshold, overflow may happen - do negation and compare with negated value to check also highest possible value*/ - tmp_pit2 = L_shl(L_negate(tmp_pit2),sub(15-16,tmp_pit_e)); - BASOP_SATURATE_WARNING_ON - *cond3 = L_sub(L_mult0(-1, tmp_pit),tmp_pit2); -} - -/*-------------------------------------------------------------------* - * gain_dec_bfi() - * - * Estimate past quantized gain prediction residual to be used in - * next frame - *-------------------------------------------------------------------*/ - -void gain_dec_bfi_fx( - Word16 *past_qua_en /* i/o: gain quantization memory (4 words) */ -) -{ - Word16 i; - Word16 av_pred_en; - Word32 Lav_pred_en; - - Lav_pred_en = L_mult(past_qua_en[0], 8192); - FOR (i = 1; i < GAIN_PRED_ORDER; i++) - { - Lav_pred_en = L_mac(Lav_pred_en, past_qua_en[i], 8192); - } - - /*av_pred_en = (float)(av_pred_en*(1.0f/(float)GAIN_PRED_ORDER)-3.0f);*/ - av_pred_en = sub(round_fx(Lav_pred_en),3<<10); - - /*if (av_pred_en < -14.0f)av_pred_en = -14.0f;*/ - av_pred_en = s_max(av_pred_en, -14 * (1 << 10)); - - - FOR (i=GAIN_PRED_ORDER-1; i>0; i--) - { - past_qua_en[i] = past_qua_en[i-1]; - move16(); - } - - past_qua_en[0] = av_pred_en; - move16(); - - return; -} diff --git a/src/libs/libevs/lib_dec/FEC_lsf_estim.cpp b/src/libs/libevs/lib_dec/FEC_lsf_estim.cpp new file mode 100644 index 00000000..09823b6e --- /dev/null +++ b/src/libs/libevs/lib_dec/FEC_lsf_estim.cpp @@ -0,0 +1,56 @@ +/*==================================================================================== + EVS Codec 3GPP TS26.443 Nov 13, 2018. Version 12.11.0 / 13.7.0 / 14.3.0 / 15.1.0 + ====================================================================================*/ + +#include "options.h" +#include "cnst.h" +#include "rom_com.h" +#include "prot.h" + +/*-------------------------------------------------------------------* + * FEC_lsf_estim() + * + * - LSP calculation + * - A(z) calculation + *-------------------------------------------------------------------*/ + +void FEC_lsf2lsp_interp( + Decoder_State *st, /* i/o: Decoder static memory */ + const short L_frame, /* i : length of the frame */ + float *Aq, /* o : calculated A(z) for 4 subframes */ + float *lsf, /* o : estimated LSF vector */ + float *lsp /* o : estimated LSP vector */ +) +{ + /* convert LSFs to LSPs */ + if ( st->Opt_AMR_WB ) + { + isf2isp( lsf, lsp, M, INT_FS_12k8 ); + } + else + { + if( L_frame == L_FRAME ) + { + lsf2lsp( lsf, lsp, M, INT_FS_12k8 ); + } + else /* L_frame == L_FRAME16k */ + { + lsf2lsp( lsf, lsp, M, INT_FS_16k ); + } + } + + /*----------------------------------------------------------------------* + * Interpolate LSP vector and find A(z) + *----------------------------------------------------------------------*/ + + if ( st->Opt_AMR_WB ) + { + int_lsp( L_frame, st->lsp_old, lsp, Aq, M, interpol_isp_amr_wb, 1 ); + } + else + { + int_lsp( L_frame, st->lsp_old, lsp, Aq, M, interpol_frac_12k8, 0 ); + } + + return; +} diff --git a/src/libs/libevs/lib_dec/FEC_lsf_estim_fx.cpp b/src/libs/libevs/lib_dec/FEC_lsf_estim_fx.cpp deleted file mode 100755 index bf6feb3f..00000000 --- a/src/libs/libevs/lib_dec/FEC_lsf_estim_fx.cpp +++ /dev/null @@ -1,59 +0,0 @@ -/*==================================================================================== - EVS Codec 3GPP TS26.442 Apr 03, 2018. Version 12.11.0 / 13.6.0 / 14.2.0 - ====================================================================================*/ - - -#include "options.h" /* Compilation switches */ -#include "cnst_fx.h" /* Common constants */ -#include "rom_com_fx.h" /* Static table prototypes */ -#include "prot_fx.h" /* Function prototypes */ -#include "stl.h" - -/*-------------------------------------------------------------------* - * FEC_lsf_estim() - * - * - LSP calculation - * - A(z) calculation - *-------------------------------------------------------------------*/ - -void FEC_lsf2lsp_interp( - Decoder_State_fx *st, /* i/o: Decoder static memory */ - const Word16 L_frame, /* i : length of the frame */ - Word16 *Aq, /* o : calculated A(z) for 4 subframes */ - Word16 *lsf, /* o : estimated LSF vector */ - Word16 *lsp /* o : estimated LSP vector */ -) -{ - - /* convert LSFs to LSPs */ - IF ( st->Opt_AMR_WB_fx ) - { - E_LPC_isf_isp_conversion( lsf, lsp, M); - } - ELSE - { - IF( sub(L_frame,L_FRAME) == 0 ) - { - lsf2lsp_fx( lsf, lsp, M, INT_FS_FX ); - } - ELSE /* L_frame == L_FRAME16k */ - { - lsf2lsp_fx( lsf, lsp, M, INT_FS_16k_FX); - } - } - - /*----------------------------------------------------------------------* - * Interpolate LSP vector and find A(z) - *----------------------------------------------------------------------*/ - - IF ( st->Opt_AMR_WB_fx ) - { - int_lsp_fx( L_frame, st->lsp_old_fx, lsp, Aq, M, interpol_isp_amr_wb_fx, 1 ); - } - ELSE - { - int_lsp_fx( L_frame, st->lsp_old_fx, lsp, Aq, M, interpol_frac_fx, 0 ); - } - - return; -} diff --git a/src/libs/libevs/lib_dec/FEC_pitch_estim.cpp b/src/libs/libevs/lib_dec/FEC_pitch_estim.cpp new file mode 100644 index 00000000..c45264b1 --- /dev/null +++ b/src/libs/libevs/lib_dec/FEC_pitch_estim.cpp @@ -0,0 +1,56 @@ +/*==================================================================================== + EVS Codec 3GPP TS26.443 Nov 13, 2018. Version 12.11.0 / 13.7.0 / 14.3.0 / 15.1.0 + ====================================================================================*/ + + +#include +#include "options.h" +#include "cnst.h" +#include "prot.h" + + +/*------------------------------------------------------------------------* + * FEC_pitch_estim() + * + * Estimation of pitch for FEC + *------------------------------------------------------------------------*/ + +void FEC_pitch_estim( + const short Opt_AMR_WB, /* i : flag indicating AMR-WB IO mode */ + const short last_core, /* i : last core */ + const short L_frame, /* i : length of the frame */ + const short clas, /* i : current frame classification */ + const short last_good, /* i : last good clas information */ + const float pitch_buf[], /* i : Floating pitch for each subframe */ + const float old_pitch_buf[], /* i : buffer of old subframe pitch values */ + float *bfi_pitch, /* i/o: update of the estimated pitch for FEC */ + short *bfi_pitch_frame, /* o : frame length when pitch was updated */ + short *upd_cnt, /* i/o: update counter */ + const short coder_type /* i : coder_type */ +) +{ + if( last_core == HQ_CORE ) + { + *bfi_pitch = pitch_buf[(L_frame/L_SUBFR)-1]; + *bfi_pitch_frame = L_frame; + *upd_cnt = MAX_UPD_CNT; + } + + if( (clas == VOICED_CLAS && last_good >= VOICED_TRANSITION) || (Opt_AMR_WB && clas == VOICED_CLAS) ) + { + /* update pitch for FEC if pitch is coherent */ + if( ( (pitch_buf[3] < 1.4f * pitch_buf[1]) && (pitch_buf[3] > 0.7f * pitch_buf[1]) && + (pitch_buf[1] < 1.4f * old_pitch_buf[2*NB_SUBFR-1]) && (pitch_buf[1] > 0.7f * old_pitch_buf[2*NB_SUBFR-1]) && + (L_frame == L_FRAME) ) || + ( (pitch_buf[3] < 1.4f * pitch_buf[1]) && (pitch_buf[3] > 0.7f * pitch_buf[1]) && + (pitch_buf[1] < 1.4f * old_pitch_buf[2*NB_SUBFR16k-1]) && (pitch_buf[1] > 0.7f * old_pitch_buf[2*NB_SUBFR16k-1]) && + (L_frame == L_FRAME16k) ) || ( coder_type == TRANSITION ) ) + { + *bfi_pitch = pitch_buf[(L_frame/L_SUBFR)-1]; + *bfi_pitch_frame = L_frame; + *upd_cnt = 0; + } + } + + return; +} diff --git a/src/libs/libevs/lib_dec/FEC_pitch_estim_fx.cpp b/src/libs/libevs/lib_dec/FEC_pitch_estim_fx.cpp deleted file mode 100755 index 839bb11a..00000000 --- a/src/libs/libevs/lib_dec/FEC_pitch_estim_fx.cpp +++ /dev/null @@ -1,104 +0,0 @@ -/*==================================================================================== - EVS Codec 3GPP TS26.442 Apr 03, 2018. Version 12.11.0 / 13.6.0 / 14.2.0 - ====================================================================================*/ - -#include "options.h" /* Compilation switches */ -#include "cnst_fx.h" /* Common constants */ -#include "prot_fx.h" /* Function prototypes */ -#include "stl.h" -#include "basop_mpy.h" - -/*========================================================================*/ -/* FUNCTION : FEC_pitch_estim_fx() */ -/*------------------------------------------------------------------------*/ -/* PURPOSE : Estimation of pitch for FEC */ -/* */ -/*------------------------------------------------------------------------*/ -/* INPUT ARGUMENTS : */ -/* _ (Word16) st_fx->Opt_AMR_WB: flag indicating AMR-WB IO mode */ -/* _ (Word16) st_fx->L_frame_fx: length of the frame */ -/* _ (Word16) st_fx->clas_dec: frame classification */ -/* _ (Word16) st_fx->last_good_fx: last good clas information */ -/* _ (Word16[]) pitch : pitch values for each subframe Q6 */ -/* _ (Word16[]) old_pitch_buf:pitch values for each subframe Q6 */ -/*------------------------------------------------------------------------*/ -/* INPUT/OUTPUT ARGUMENTS : */ -/*------------------------------------------------------------------------*/ -/* OUTPUT ARGUMENTS : */ -/*------------------------------------------------------------------------*/ - -/* _ (Word16[]) st_fx->bfi_pitch : initial synthesis filter states */ -/* _ (Word16) st_fx->bfi_pitch_frame: LP filter E of last */ -/* _ (Word16) st_fx->upd_cnt_fx: update counter */ -/*------------------------------------------------------------------------*/ -/* RETURN ARGUMENTS : */ -/* _ None */ -/*========================================================================*/ -void FEC_pitch_estim_fx( - const Word16 Opt_AMR_WB, /* i : flag indicating AMR-WB IO mode */ - const Word16 last_core, /* i : last core */ - const Word16 L_frame, /* i : length of the frame */ - const Word16 clas, /* i : current frame classification */ - const Word16 last_good, /* i : last good clas information */ - const Word16 pitch_buf[], /* i : Floating pitch for each subframe */ - const Word32 old_pitch_buf[], /* i : buffer of old subframe pitch values 15Q16 */ - Word16 *bfi_pitch, /* i/o: update of the estimated pitch for FEC */ - Word16 *bfi_pitch_frame, /* o : frame length when pitch was updated */ - Word16 *upd_cnt /* i/o: update counter */ - ,const Word16 coder_type /* i : coder_type */ -) -{ - Word16 tmp,tmp1,tmp2,tmp3; - Word16 tmp16k1,tmp16k2; - - tmp = mult_r(pitch_buf[1],22938); /*Q6( 0.7f * pitch_buf[1] 0.7 in Q15)*/ - tmp1 = shl(tmp,1); /*Q6 (1.4f * pitch_buf[1])*/ - tmp2 = round_fx(L_shl(Mpy_32_16_1(old_pitch_buf[2*NB_SUBFR-1],22938), 6)); /*Q6 (0.7f * old_pitch_buf[2*NB_SUBFR-1])*/ - tmp3 = shl(tmp2,1); /*Q6 (1.4f * old_pitch_buf[2*NB_SUBFR-1])*/ - - tmp16k1 = round_fx(L_shl(Mpy_32_16_1(old_pitch_buf[2*NB_SUBFR16k-1],22938), 6)); /*Q6 0.7f * old_pitch_buf[2*NB_SUBFR16k-1]*/ - tmp16k2 = shl(tmp16k1,1); /*Q6 1.4f * old_pitch_buf[2*NB_SUBFR16k-1]*/ - - IF( sub(last_core,HQ_CORE) == 0 ) - { - *bfi_pitch = pitch_buf[shr(L_frame,6)-1]; - move16(); - *bfi_pitch_frame = L_frame; - move16(); - *upd_cnt = MAX_UPD_CNT; - move16(); - } - - test(); - test(); - test(); - IF( (sub(clas,VOICED_CLAS) == 0 && sub(last_good,VOICED_TRANSITION) >= 0) || (Opt_AMR_WB && sub(clas,VOICED_CLAS) == 0) ) - { - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - IF( ( (sub(pitch_buf[3],tmp1) < 0) && (sub(pitch_buf[3],tmp) > 0) && - (sub(pitch_buf[1],tmp3) < 0) && (sub(pitch_buf[1],tmp2) > 0) && - (sub(L_frame,L_FRAME) == 0) ) || - ( (sub(pitch_buf[3],tmp1) < 0) && (sub(pitch_buf[3],tmp) > 0) && - (sub(pitch_buf[1],tmp16k2) < 0) && (sub(pitch_buf[1],tmp16k1) > 0) && - (sub(L_frame,L_FRAME16k) == 0) ) - || (sub(coder_type, TRANSITION) == 0) ) - { - *bfi_pitch = pitch_buf[shr(L_frame,6)-1]; - move16(); - *bfi_pitch_frame = L_frame; - move16(); - *upd_cnt = 0; - move16(); - } - } -} - diff --git a/src/libs/libevs/lib_dec/FEC_scale_syn.cpp b/src/libs/libevs/lib_dec/FEC_scale_syn.cpp new file mode 100644 index 00000000..1d3acb46 --- /dev/null +++ b/src/libs/libevs/lib_dec/FEC_scale_syn.cpp @@ -0,0 +1,408 @@ +/*==================================================================================== + EVS Codec 3GPP TS26.443 Nov 13, 2018. Version 12.11.0 / 13.7.0 / 14.3.0 / 15.1.0 + ====================================================================================*/ + +#include +#include "options.h" +#include "cnst.h" +#include "prot.h" + +#define SCLSYN_LAMBDA 0.3f + +/*-------------------------------------------------------------------* + * FEC_scale_syn() + * + * Smooth speech energy evolution when recovering after erasure(s) + *-------------------------------------------------------------------*/ + +void FEC_scale_syn( + const short L_frame, /* i : length of the frame */ + short clas, /* i/o: frame classification */ + const short last_good, /* i: last good frame classification */ + float *synth, /* i/o: synthesized speech at Fs = 12k8 Hz */ + const float *pitch, /* i: pitch values for each subframe */ + float enr_old, /* i: energy at the end of previous frame */ + float enr_q, /* i: transmitted energy for current frame */ + const short coder_type, /* i: coder type */ + const short LSF_Q_prediction, /* i : LSF prediction mode */ + short *scaling_flag, /* i/o: flag to indicate energy control of syn */ + float *lp_ener_FEC_av, /* i/o: averaged voiced signal energy */ + float *lp_ener_FEC_max, /* i/o: averaged voiced signal energy */ + const short bfi, /* i: current frame BFI */ + const long total_brate, /* i: total bitrate */ + const short prev_bfi, /* i: previous frame BFI */ + const long last_core_brate, /* i: previous frame core bitrate */ + float *exc, /* i/o: excitation signal without enhancement */ + float *exc2, /* i/o: excitation signal with enhancement */ + const float Aq[], /* i: LP filter coefs */ + float *old_enr_LP, /* i/o: LP filter E of last good voiced frame */ + const float *mem_tmp, /* i: temp. initial synthesis filter states */ + float *mem_syn, /* o: initial synthesis filter states */ + int avoid_lpc_burst_on_recovery, /* i : if true the excitation energy is limited if LP has big gain */ + short force_scaling /* i: force scaling */ +) +{ + short i; + float enr1, enr2, gain1, gain2; + float scaling, ener_max, enr2_av, enr2_max; + float enr_LP; + float h1[L_FRAME/2], tilt, rr0, rr1, pitch_dist, mean_pitch; + short k; + + gain2 = 0.0f; + gain1 = 0.0f; + scaling = 1.0f; + enr_LP = 0.0f; + + /*-----------------------------------------------------------------* + * Find the synthesis filter impulse response on voiced + *-----------------------------------------------------------------*/ + + if( clas >= VOICED_TRANSITION && clas < INACTIVE_CLAS ) + { + if( L_frame == L_FRAME ) + { + enr_LP = enr_1_Az( Aq+(NB_SUBFR-1)*(M+1), L_SUBFR ); + } + else /* L_frame == L_FRAME16k */ + { + enr_LP = enr_1_Az( Aq+(NB_SUBFR16k-1)*(M+1), L_SUBFR ); + } + } + + /*-----------------------------------------------------------------* + * Define when to scale the synthesis + *-----------------------------------------------------------------*/ + + if( bfi ) + { + *scaling_flag = 1; /* Always check synthesis on bad frames */ + } + else if( prev_bfi ) + { + if( ( LSF_Q_prediction == AUTO_REGRESSIVE ) || ( LSF_Q_prediction == MOVING_AVERAGE ) ) + { + *scaling_flag = 2; /* Decoded LSFs affected */ + } + else if( coder_type != TRANSITION ) + { + *scaling_flag = 1; /* SN, but not TC mode - LSF still affected by the interpolation */ + } + else + { + *scaling_flag = 0; /* LSF still possibly affected due to interpolation */ + } + scaling = 1.5f; + } + else + { + if( (LSF_Q_prediction == AUTO_REGRESSIVE) && (*scaling_flag == 2) ) + { + *scaling_flag = 2; /* Continue with energy control till the end of AR prediction */ + } + else if( *scaling_flag > 0 ) + { + (*scaling_flag)--; /* If scaling flag was equal to 2, add one control frame to account for the LSF interpolation */ + } + scaling = 2.0f; + } + + /*-----------------------------------------------------------------* + * Find the energy/gain at the end of the frame + *-----------------------------------------------------------------*/ + + fer_energy( L_frame, clas, synth, pitch[(L_frame>>6)-1], &enr2, L_frame ); + + if( bfi || (total_brate == ACELP_7k20) || (total_brate == ACELP_8k00) ) + { + /* previous frame erased and no TC frame */ + if( *scaling_flag > 0 ) + { + enr2 += 0.01f; + + if( bfi ) /* In all bad frames, limit the gain to 1 */ + { + gain2 = (float)sqrt( enr_old / enr2 ); + if( gain2 > 1.0f ) + { + gain2 = 1.0f; + } + + /* find the energy/gain at the beginning of the frame */ + fer_energy( L_frame, clas, synth, pitch[0], &enr1, 0 ); + + enr1 += 0.1f; + gain1 = (float)sqrt( enr_old / enr1 ); + if( gain1 > 1.0f ) + { + gain1 = 1.0f; + } + } + else /* good frame */ + { + if( enr_q == 0 ) /* If E info (FEC protection bits) is not available in the bitstream */ + { + enr_q = enr2; + + set_f( h1, 0.0f, L_FRAME/2 ); + h1[0] = 1.0f; + syn_filt( Aq+(3*(M+1)), M, h1, h1, L_FRAME/2, h1+(M+1), 0 ); + rr0 = dotp( h1, h1, L_FRAME/2-1 ) + 0.001f; + rr1 = dotp( h1, h1+1, L_FRAME/2-1 ); + tilt = rr1 / rr0; + + pitch_dist = 0.0f; + mean_pitch = pitch[0]; + for( k=0; k<(NB_SUBFR - 1); k++ ) + { + pitch_dist += abs((short)(pitch[k+1]+0.5f)-(short)(pitch[k]+0.5f)); + mean_pitch += pitch[k+1]; + } + pitch_dist /= (float)(NB_SUBFR-1); + mean_pitch /= (float)(NB_SUBFR); + + if( ( tilt > 0.7f ) && /* HF resonnant filter */ + ( (pitch_dist > 8.0f) || (mean_pitch < PIT_MIN) ) && /* pitch unstable or very short */ + ( (prev_bfi) || ( (coder_type == GENERIC) && (LSF_Q_prediction == AUTO_REGRESSIVE) ) ) ) + { + if( enr_q > scaling * enr_old ) + { + enr_q = scaling * enr_old; + } + } + else + { + if( (clas <= VOICED_TRANSITION) || (clas >= INACTIVE_CLAS) ) + { + ener_max = *lp_ener_FEC_av; + } + else + { + ener_max = *lp_ener_FEC_max; + } + + if( enr_old > ener_max ) + { + ener_max = enr_old; + } + if( enr_q > scaling * ener_max ) + { + enr_q = scaling * ener_max; + } + } + } + + gain2 = (float)sqrt( enr_q / enr2 ); + + + /*-----------------------------------------------------------------* + * Find the energy/gain at the beginning of the frame to ensure smooth transition after erasure(s) + *-----------------------------------------------------------------*/ + + if( ( (last_good >= VOICED_TRANSITION && last_good < INACTIVE_CLAS && (clas == UNVOICED_CLAS || clas == INACTIVE_CLAS)) || + last_core_brate == SID_1k75 || last_core_brate == SID_2k40 || last_core_brate == FRAME__NO_DATA ) && prev_bfi ) + { + /* voiced -> unvoiced signal transition */ + /* CNG -> active signal transition */ + gain1 = gain2; + } + else + { + /* find the energy at the beginning of the frame */ + fer_energy( L_frame, clas, synth, pitch[0], &enr1, 0 ); + + enr1 += 0.1f; + gain1 = (float)sqrt( enr_old / enr1 ); + if( gain1 > 1.2f ) + { + /* prevent clipping */ + gain1 = 1.2f; + } + + /* prevent amplifying the unvoiced or inactive part of the frame in case an offset is followed by an onset */ + if( clas == ONSET && gain1 > gain2 && prev_bfi ) + { + gain1 = gain2; + } + } + + enr2 = enr_q; /* Set the end frame energy to the scaled energy, to be used in the lp_ener_FEC */ + } + + /*------------------------------------------------------------------------------* + * Smooth the energy evolution by exponentially evolving from gain1 to gain2 + *------------------------------------------------------------------------------*/ + + gain2 *= ( 1.0f - AGC ); + for( i=0; i 0.7f ) && /* HF resonnant filter */ + ( (clas == UNVOICED_CLAS) || (clas == INACTIVE_CLAS) ) ) ) /* unvoiced classification */ + { + if( enr_q > scaling * enr_old ) + { + enr_q = scaling * enr_old; + } + } + else if( last_good >= VOICED_TRANSITION && last_good < INACTIVE_CLAS && clas >= VOICED_TRANSITION && clas < INACTIVE_CLAS ) + { + /* voiced -> voiced recovery */ + if( (*old_enr_LP != 0.0f) && (enr_LP > 2 * *old_enr_LP) ) + { + enr_q /= enr_LP; + enr_q *= 2* *old_enr_LP; + } + else if (avoid_lpc_burst_on_recovery && enr_LP > 20.0f) + { + enr_q *= sqrt(20.0f / enr_LP); + } + } + + if( (last_good >= VOICED_TRANSITION && last_good < INACTIVE_CLAS && clas >= VOICED_TRANSITION && clas < INACTIVE_CLAS ) + || force_scaling) + { + if( enr_q > enr_old ) + { + enr_q = (1 - SCLSYN_LAMBDA) * enr_old + SCLSYN_LAMBDA * enr_q; + } + } + } + + gain2 = (float)sqrt( enr_q / enr2 ); + + /* do not allow E increase if enr_q index == 0 (lower end Q clipping) */ + if( enr_q < 1.1f ) + { + if( gain2 > 1.0f ) + { + gain2 = 1.0f; + } + } + else + { + if( gain2 > 1.2f ) + { + gain2 = 1.2f; + } + } + + /*-----------------------------------------------------------------* + * Find the energy/gain at the beginning of the frame to ensure smooth transition after erasure(s) + *-----------------------------------------------------------------*/ + + if( clas == SIN_ONSET ) + { + /* allow only slow increase */ + gain1 = 0.5f * gain2; + } + else if( (last_good >= VOICED_TRANSITION && last_good < INACTIVE_CLAS && (clas == UNVOICED_CLAS || clas == INACTIVE_CLAS)) || + last_core_brate == SID_1k75 || last_core_brate == SID_2k40 || last_core_brate == FRAME__NO_DATA ) + { + /* voiced -> unvoiced signal transition */ + /* CNG -> active signal transition */ + gain1 = gain2; + } + else + { + /* find the energy at the beginning of the frame */ + fer_energy( L_frame, clas, synth, pitch[0], &enr1, 0 ); + + enr1 += 0.1f; + gain1 = (float)sqrt( enr_old / enr1 ); + if( gain1 > 1.2f ) + { + /* prevent clipping */ + gain1 = 1.2f; + } + if (avoid_lpc_burst_on_recovery && (enr_LP > 20.0f) && (enr_LP <= 2 * *old_enr_LP) && (gain1 > 1.0f)) + { + gain1 = 1.0f; + } + + /* prevent amplifying the unvoiced or inactive part of the frame in case an offset is followed by an onset */ + if( clas == ONSET && gain1 > gain2 ) + { + gain1 = gain2; + } + } + + /*-----------------------------------------------------------------* + * Smooth the energy evolution by exponentially evolving from gain1 to gain2 + *-----------------------------------------------------------------*/ + + gain2 *= ( 1.0f - AGC ); + for( i=0; i= VOICED_TRANSITION && clas < INACTIVE_CLAS) ) + { + if( clas == VOICED_TRANSITION ) + { + enr2_av = enr2; + fer_energy( L_frame, VOICED_CLAS, synth, pitch[(L_frame>>6)-1], &enr2_max, L_frame ); + } + else + { + enr2_max = enr2; + fer_energy( L_frame, UNVOICED_CLAS, synth, pitch[(L_frame>>6)-1], &enr2_av, L_frame ); + } + + *lp_ener_FEC_av = 0.05f * enr2_av + 0.95f * *lp_ener_FEC_av; + *lp_ener_FEC_max = 0.05f * enr2_max + 0.95f * *lp_ener_FEC_max; + } + + /*-----------------------------------------------------------------* + * Update the LP filter energy for voiced frames + *-----------------------------------------------------------------*/ + + if( clas >= VOICED_TRANSITION && clas < INACTIVE_CLAS ) + { + *old_enr_LP = enr_LP; + } + + + return; +} diff --git a/src/libs/libevs/lib_dec/FEC_scale_syn_fx.cpp b/src/libs/libevs/lib_dec/FEC_scale_syn_fx.cpp deleted file mode 100755 index eb0459d5..00000000 --- a/src/libs/libevs/lib_dec/FEC_scale_syn_fx.cpp +++ /dev/null @@ -1,616 +0,0 @@ -/*==================================================================================== - EVS Codec 3GPP TS26.442 Apr 03, 2018. Version 12.11.0 / 13.6.0 / 14.2.0 - ====================================================================================*/ - -#include "options.h" /* Compilation switches */ -#include "cnst_fx.h" /* Common constants */ -#include "prot_fx.h" /* Function prototypes */ -#include "stl.h" -#include "basop_mpy.h" - -/*-------------------------------------------------------------------* - * Local constants - *-------------------------------------------------------------------*/ -#define AGC_FX 32113 /* 0.98f */ -#define SCLSYN_LAMBDA (9830/*0.3f Q15*/) - -/*========================================================================*/ -/* FUNCTION : FEC_scale_syn_fx() */ -/*------------------------------------------------------------------------*/ -/* PURPOSE : Smooth the speech energy evolution when */ -/* recovering after a BAD frame */ -/*------------------------------------------------------------------------*/ -/* INPUT ARGUMENTS : */ -/* _ (Word16) L_frame : length of the frame */ -/* _ (Word16) *update_flg : indication about resynthesis */ -/* _ (Word16) st_fx->clas_dec: frame classification */ -/* _ (Word16) last_good : last good frame classification */ -/* _ (Word16[]) synth : synthesized speech at Fs = 12k8 Hz Q_syn */ -/* _ (Word16[]) pitch : pitch values for each subframe Q0 */ -/* _ (Word32) L_enr_old :energy at the end of previous frame Q0 */ -/* _ (Word16) L_enr_q : transmitted energy for current frame Q0 */ -/* _ (Word16) coder_type : coder type */ -/* _ (Word16) st_fx->prev_bfi_fx: previous frame BFI */ -/* _ (Word16) st_fx->last_core_brate_fx: previous frame core bitrate */ -/* _ (Word16[]) mem_tmp : temp. initial synthesis filter states Q_syn */ -/* _ (Word16) Q_exc : quantized LSPs from frame end */ -/* _ (Word16) Q_syn : quantized LSPs from frame end */ -/*------------------------------------------------------------------------*/ -/* INPUT/OUTPUT ARGUMENTS : */ -/* _ (Word16[]) exc : excitation signal without enhancement Q_exc */ -/* _ (Word16[]) exc2 : excitation signal with enhancement Q_exc */ -/* _ (Word16[]) Aq : LP filter coefs (can be modified if BR) Q12 */ -/*------------------------------------------------------------------------*/ -/* OUTPUT ARGUMENTS : */ -/*------------------------------------------------------------------------*/ - -/* _ (Word16[]) st_fx->mem_syn2 : initial synthesis filter states Q_syn */ -/* _ (Word16) st_fx->old_enr_LP : LP filter E of last Q5 */ -/* good voiced frame */ -/*------------------------------------------------------------------------*/ -/* RETURN ARGUMENTS : */ -/* _ None */ -/*========================================================================*/ - - -void FEC_scale_syn_fx( - const Word16 L_frame, /* i : length of the frame */ - Word16 *update_flg, /* o: flag indicating re-synthesis after scaling*/ - Word16 clas, /* i/o: frame classification */ - const Word16 last_good, /* i: last good frame classification */ - Word16 *synth, /* i/o: synthesized speech at Fs = 12k8 Hz */ - const Word16 *pitch, /* i: pitch values for each subframe */ - Word32 L_enr_old, /* i: energy at the end of previous frame */ - Word32 L_enr_q, /* i: transmitted energy for current frame */ - const Word16 coder_type, /* i: coder type */ - const Word16 LSF_Q_prediction, /* i : LSF prediction mode */ - Word16 *scaling_flag, /* i/o: flag to indicate energy control of syn */ - Word32 *lp_ener_FEC_av, /* i/o: averaged voiced signal energy */ - Word32 *lp_ener_FEC_max, /* i/o: averaged voiced signal energy */ - const Word16 bfi, /* i: current frame BFI */ - const Word32 total_brate, /* i: total bitrate */ - const Word16 prev_bfi, /* i: previous frame BFI */ - const Word32 last_core_brate, /* i: previous frame core bitrate */ - Word16 *exc, /* i/o: excitation signal without enhancement */ - Word16 *exc2, /* i/o: excitation signal with enhancement */ - Word16 Aq[], /* i/o: LP filter coefs (can be modified if BR) */ - Word16 *old_enr_LP, /* i/o: LP filter E of last good voiced frame */ - const Word16 *mem_tmp, /* i: temp. initial synthesis filter states */ - Word16 *mem_syn, /* o: initial synthesis filter states */ - Word16 Q_exc, - Word16 Q_syn - , Word16 avoid_lpc_burst_on_recovery /* i : if true the excitation energy is limited if LP has big gain */ - , Word16 force_scaling /* i: force scaling */ -) -{ - Word16 i; - Word32 L_enr1, L_enr2; - Word16 gain1, gain2, enr_LP; - Word16 tmp, tmp2, exp, exp2; - Word16 tmp3; - Word32 L_tmp; - Word16 scaling; - Word32 ener_max, L_enr2_av, L_ener2_max; - Word16 h1[L_FRAME/2], tilt, pitch_dist, mean_pitch; - Word16 k; - Word32 L_mean_pitch; - enr_LP = 0; - move16(); - gain2 = 0; - move16(); - gain1 = 0; - move16(); - *update_flg = 0; - move16(); - L_enr_old = L_max(1, L_enr_old); /* to avoid division by zero (*L_enr_old is always >= 0) */ - scaling = 16384; - move16(); /* Q14*/ - - /*-----------------------------------------------------------------* - * Find the synthesis filter impulse response on voiced - *-----------------------------------------------------------------*/ - test(); - IF( sub(clas,VOICED_TRANSITION) >= 0 && sub(clas,INACTIVE_CLAS) < 0 ) - { - IF( sub(L_frame,L_FRAME) == 0 ) - { - enr_LP = Enr_1_Az_fx(Aq+(NB_SUBFR-1)*(M+1), L_SUBFR ); - } - ELSE /* L_frame == L_FRAME16k */ - { - enr_LP = Enr_1_Az_fx( Aq+(NB_SUBFR16k-1)*(M+1), L_SUBFR ); /*Q3*/ - } - } - - /*-----------------------------------------------------------------* - * Define when to scale the synthesis - *-----------------------------------------------------------------*/ - - IF( bfi ) - { - *scaling_flag = 1; - move16(); /* Always check synthesis on bad frames */ - } - ELSE IF( prev_bfi ) - { - test(); - IF( ( sub(LSF_Q_prediction,AUTO_REGRESSIVE) == 0 ) || ( sub(LSF_Q_prediction,MOVING_AVERAGE) == 0 ) ) - { - *scaling_flag = 2; - move16(); /* Decoded LSFs affected */ - } - ELSE IF( sub(coder_type,TRANSITION) != 0 ) - { - *scaling_flag = 1; - move16(); /* SN, but not TC mode - LSF still affected by the interpolation */ - } - ELSE - { - *scaling_flag = 0; - move16(); /* LSF still possibly affected due to interpolation */ - } - scaling = 24576; /*1.5 Q14*/ move16(); - } - ELSE - { - test(); - IF( (sub(LSF_Q_prediction,AUTO_REGRESSIVE) == 0) && (sub(*scaling_flag,2) == 0) ) - { - *scaling_flag = 2; - move16(); /* Continue with energy control till the end of AR prediction */ - } - ELSE IF( *scaling_flag > 0 ) - { - (*scaling_flag) = sub(*scaling_flag,1); /* If scaling flag was equal to 2, add one control frame to account for the LSF interpolation */ - } - scaling = 32767; /*2.0 Q14*/ move16(); - } - - /*-----------------------------------------------------------------* - * Find the energy/gain at the end of the frame - *-----------------------------------------------------------------*/ - - /*fer_energy( L_frame, clas, synth, pitch[(L_frame>>6)-1], &enr2, L_frame );*/ - frame_ener_fx(L_frame,clas, synth, pitch[sub(shr(L_frame,6),1)], &L_enr2/*Q0*/, 1, Q_syn, 3, 0); - - if( bfi || (L_sub(total_brate,ACELP_7k20) == 0) || (L_sub(total_brate,ACELP_8k00) == 0) ) - { - /* previous frame erased and no TC frame */ - IF( *scaling_flag > 0 ) - { - /*enr2 += 0.01f;*/ - L_enr2 = L_max(L_enr2, 1); /* L_enr2 is in Q0 */ - - IF( bfi ) /* In all bad frames, limit the gain to 1 */ - { - /* gain2 = (float)sqrt( enr_old / enr2 );*/ - L_tmp = Sqrt_Ratio32(L_enr_old, 0, L_enr2, 0, &exp2); - gain2 = round_fx(L_shl(L_tmp, sub(exp2, 1))); /* in Q14 */ - - /*if( gain2 > 1.0f )gain2 = 1.0f;*/ - gain2 = s_min(gain2, 16384); - - /* find the energy/gain at the beginning of the frame */ - frame_ener_fx(L_frame,clas, synth, pitch[0], &L_enr1/*Q0*/, 1, Q_syn, 3, 0); - - /*enr1 += 0.1f;*/ - L_enr1 = L_max(L_enr1, 1); /* L_enr2 is in Q0 */ - - /*gain1 = (float)sqrt( enr_old / enr1 );*/ - L_tmp = Sqrt_Ratio32(L_enr_old, 0, L_enr1, 0, &exp2); - gain1 = round_fx(L_shl(L_tmp, sub(exp2, 1))); /* in Q14 */ - - /*if( gain1 > 1.0f )gain1 = 1.0f;*/ - gain1 = s_min(gain1, 16384); - } - ELSE /* good frame */ - { - IF( L_enr_q == 0 ) /* If E info (FEC protection bits) is not available in the bitstream */ - { - L_enr_q = L_enr2; - set16_fx( h1, 0, L_FRAME/2 ); - h1[0] = 1024; - move16(); - /*syn_filt( Aq+(3*(M+1)), M, h1, h1, L_FRAME/2, h1+(M+1), 0 );*/ - E_UTIL_synthesis(1, Aq+(3*(M+1)), h1, h1, L_FRAME/2, h1+(M+1), 0, M); - - /*Compute tilt */ - /*rr0 = dotp( h1, h1, L_FRAME/2-1 ) + 0.1f;*/ - /*rr1 = dotp( h1, h1+1, L_FRAME/2-1 );*/ - /*tilt = rr1 / rr0;*/ - tilt = extract_h(L_shl(get_gain(h1+1, h1, L_FRAME/2-1),15)); - - pitch_dist = 0; - move16(); - L_mean_pitch = L_mult(pitch[0], 8192); - move32(); - FOR( k=0; k<(NB_SUBFR - 1); k++ ) - { - pitch_dist = add(pitch_dist, abs_s(sub(pitch[k+1],pitch[k]))); - L_mean_pitch = L_mac(L_mean_pitch, pitch[k+1], 8192); - } - /*pitch_dist /= (float)(NB_SUBFR-1); */ - pitch_dist = mult_r(shl(pitch_dist,4),10923); - /*mean_pitch /= (float)(NB_SUBFR);*/ - mean_pitch = extract_h(L_shl(L_mean_pitch,4)); - - - test(); - test(); - test(); - test(); - test(); - test(); - IF( ( sub(tilt,22938) > 0 ) && /* HF resonnant filter */ - ( (sub(pitch_dist, 8<<4) > 0) || (sub(mean_pitch,PIT_MIN<<4) < 0) ) && /* pitch unstable or very short */ - ( (prev_bfi) || ( (sub(coder_type,GENERIC) == 0) && (sub(LSF_Q_prediction,AUTO_REGRESSIVE) == 0) ) ) ) - { - /*if( enr_q > scaling * enr_old ){enr_q = scaling * enr_old;}*/ - L_enr_q = L_min(L_enr_q, L_shl(Mult_32_16(L_enr_old, scaling),1)); /* scaling in Q14*/ - } - ELSE - { - ener_max = *lp_ener_FEC_max; - move32(); - test(); - if( sub(clas,VOICED_TRANSITION) == 0 || (sub(clas,INACTIVE_CLAS) >= 0)) - { - ener_max = *lp_ener_FEC_av; - move32(); - } - /*if( enr_old > ener_max )ener_max = enr_old;*/ - ener_max = L_max(ener_max, L_enr_old); - - /*if( enr_q > scaling * ener_max ){enr_q = scaling * ener_max;}*/ - L_enr_q = L_min(L_enr_q, L_shl(Mult_32_16(ener_max, scaling),1)); /* scaling in Q14*/ - } - } - /*gain2 = (float)sqrt( enr_q / enr2 );*/ - L_enr_q = L_max(L_enr_q, 1); /* L_enr2 is in Q0 */ - L_tmp = Sqrt_Ratio32(L_enr_q, 0, L_enr2, 0, &exp2); - gain2 = round_fx(L_shl(L_tmp, sub(exp2, 1))); /* in Q14 */ - - /*-----------------------------------------------------------------* - * Find the energy/gain at the beginning of the frame to ensure smooth transition after erasure(s) - *-----------------------------------------------------------------*/ - - test(); - test(); - test(); - test(); - test(); - test(); - IF( ( (sub(last_good,VOICED_TRANSITION) >= 0 && sub(last_good,INACTIVE_CLAS) < 0 && (sub(clas,UNVOICED_CLAS) == 0 || sub(clas,INACTIVE_CLAS) == 0)) || - L_sub(last_core_brate,SID_1k75) == 0 || L_sub(last_core_brate,SID_2k40) == 0 || L_sub(last_core_brate,FRAME_NO_DATA) == 0 ) && prev_bfi ) - { - /* voiced -> unvoiced signal transition */ - /* CNG -> active signal transition */ - gain1 = gain2; - move16(); - } - ELSE - { - /* find the energy at the beginning of the frame */ - frame_ener_fx(L_frame,clas, synth, pitch[0], &L_enr1/*Q0*/, 1, Q_syn, 3, 0); - - /*enr1 += 0.1f;*/ - L_enr1 = L_max(L_enr1, 1); /* L_enr1 is in Q0 */ - - /*gain1 = (float)sqrt( enr_old / enr1 );*/ - L_tmp = Sqrt_Ratio32(L_enr_old, 0, L_enr1, 0, &exp2); - gain1 = round_fx(L_shl(L_tmp, sub(exp2, 1))); /* in Q14 */ - - /*if( gain1 > 1.2f )gain1 = 1.2f;*/ - /* prevent clipping */ - gain1 = s_min(gain1, 19661); - - /* prevent amplifying the unvoiced or inactive part of the frame in case an offset is followed by an onset */ - test(); - test(); - if( sub(clas,ONSET) == 0 && sub(gain1,gain2) > 0 && prev_bfi ) - { - gain1 = gain2; - move16(); - } - } - - L_enr2 = L_enr_q; - move32(); /* Set the end frame energy to the scaled energy, to be used in the lp_ener_FEC */ - } - - /*------------------------------------------------------------------------------* - * Smooth the energy evolution by exponentially evolving from gain1 to gain2 - *------------------------------------------------------------------------------*/ - - /*gain2 *= ( 1.0f - AGC );*/ - L_tmp = L_mult(gain2, (Word16)(32768 - AGC_FX)); - FOR( i=0; i 0 ) && /* HF resonnant filter */ - ( (sub(clas,UNVOICED_CLAS) == 0) || (sub(clas,INACTIVE_CLAS) == 0) ) ) ) /* unvoiced classification */ - { - /*if( enr_q > scaling * enr_old )enr_q = scaling * enr_old;*/ - L_enr_q = L_min(L_enr_q, L_shl(Mult_32_16(L_enr_old, scaling),1)); /* scaling in Q14*/ - } - ELSE IF( sub(last_good,VOICED_TRANSITION) >= 0 && sub(last_good,INACTIVE_CLAS) < 0 && sub(clas,VOICED_TRANSITION) >= 0 && sub(clas,INACTIVE_CLAS) < 0 ) - { - /* Voiced-voiced recovery */ - test(); - IF( *old_enr_LP != 0 && sub(enr_LP, shl(*old_enr_LP, 1)) > 0 ) - { - /* enr_q /= enr_LP */ - exp = norm_l(L_enr_q); - tmp = extract_h(L_shl(L_enr_q, exp)); - - exp2 = norm_s(enr_LP); - tmp2 = shl(enr_LP, exp2); - - exp = sub(exp2, exp); - - tmp3 = sub(tmp, tmp2); - IF (tmp3 > 0) - { - tmp = shr(tmp, 1); - exp = add(exp, 1); - } - tmp = div_s(tmp, tmp2); - - /* L_enr_q *= 2 * *old_enr_LP */ - L_enr_q = L_shl(L_mult(tmp, shl(*old_enr_LP, 1)), exp); - } - - ELSE - { - test(); - IF( avoid_lpc_burst_on_recovery && sub(enr_LP, 160) > 0 ) - { - exp = norm_s(enr_LP); - tmp = shl(enr_LP, exp); - - exp2 = 7; - move16(); - tmp2 = 160 << 7; /* 160 = 20.0f in Q3 */ - exp = sub(exp2, exp); - - IF (sub(tmp, tmp2) > 0) - { - tmp = shr(tmp, 1); - exp = add(exp, 1); - } - tmp = div_s(tmp, tmp2); /* tmp*2^exp = enr_LP/20.0 */ - L_tmp = Isqrt_lc(L_deposit_h(tmp), &exp); /* L_tmp*2^exp = sqrt(20.0/enr_LP) */ - L_enr_q = L_shl(Mpy_32_32(L_enr_q, L_tmp), exp); - } - } - - } - - test(); - test(); - test(); - IF( (sub(last_good,VOICED_TRANSITION) >= 0 && sub(last_good,INACTIVE_CLAS) < 0 && sub(clas,VOICED_TRANSITION) >= 0 && sub(clas,INACTIVE_CLAS) < 0) - || force_scaling ) - { - - IF( L_sub(L_enr_q, L_enr_old) > 0) /* Prevent energy to increase on voiced */ - { - L_enr_q = L_add(Mpy_32_16_1(L_enr_old, 32767 - SCLSYN_LAMBDA), Mpy_32_16_1(L_enr_q, SCLSYN_LAMBDA)); - } - } - } - - L_enr_q = L_max(1, L_enr_q); - - /* gain2 = (float)sqrt( enr_q / enr2 );*/ - exp = norm_l(L_enr_q); - tmp = extract_h(L_shl(L_enr_q, exp)); - - exp2 = norm_l(L_enr2); - tmp2 = extract_h(L_shl(L_enr2, exp2)); - - exp2 = sub(exp, exp2); /* Denormalize and substract */ - - tmp3 = sub(tmp2, tmp); - IF (tmp3 > 0) - { - tmp2 = shr(tmp2, 1); - exp2 = add(exp2, 1); - } - - tmp = div_s(tmp2, tmp); - - L_tmp = L_deposit_h(tmp); - L_tmp = Isqrt_lc(L_tmp, &exp2); - gain2 = round_fx(L_shl(L_tmp, sub(exp2, 1))); /* in Q14 */ - - /*-----------------------------------------------------------------* - * Clipping of the smoothing gain at the frame end - *-----------------------------------------------------------------*/ - - gain2 = s_min(gain2, 19661); /* Gain modification clipping */ - if (L_sub(L_enr_q, 2) < 0) - { - gain2 = s_min(gain2, 16384); /* Gain modification clipping */ - } - - /*-----------------------------------------------------------------* - * Find the energy/gain at the beginning of the frame to ensure smooth transition after erasure(s) - *-----------------------------------------------------------------*/ - - test(); - test(); - test(); - test(); - test(); - test(); - IF( sub(clas,SIN_ONSET) == 0 ) /* slow increase */ - { - gain1 = shr(gain2, 1); - } - /*------------------------------------------------------------* - * voiced->unvoiced transition recovery - *------------------------------------------------------------*/ - ELSE IF( (sub(last_good,VOICED_TRANSITION) >= 0 && sub(last_good,INACTIVE_CLAS) < 0 && (sub(clas,UNVOICED_CLAS) == 0 || sub(clas,INACTIVE_CLAS) == 0)) || /* voiced->unvoiced transition recovery */ - L_sub(last_core_brate,SID_1k75) == 0 || L_sub(last_core_brate,SID_2k40) == 0 || L_sub(last_core_brate,FRAME_NO_DATA) == 0) /* CNG -> active signal transition */ - { - gain1 = gain2; - move16(); - } - ELSE - { - /*--------------------------------------------------------* - * Find the energy at the beginning of the frame - *--------------------------------------------------------*/ - tmp = frame_ener_fx(L_frame,clas, synth, pitch[0], &L_enr1, 0, Q_syn, 3, 0); - - /*gain1 = (float)sqrt( enr_old / enr1 );*/ - exp = norm_l(L_enr_old); - tmp = extract_h(L_shl(L_enr_old, exp)); - exp2 = norm_l(L_enr1); - tmp2 = extract_h(L_shl(L_enr1, exp2)); - - exp2 = sub(exp, exp2); /* Denormalize and substract */ - - tmp3 = sub(tmp2, tmp); - - IF (tmp3 > 0) - { - tmp2 = shr(tmp2, 1); - exp2 = add(exp2, 1); - } - - tmp = div_s(tmp2, tmp); - - L_tmp = L_deposit_h(tmp); - L_tmp = Isqrt_lc(L_tmp, &exp2); - gain1 = round_fx(L_shl(L_tmp, sub(exp2, 1))); /* in Q14 */ - /* exp2 is always <= 1 */ - - gain1 = s_min(gain1, 19661); - - test(); - test(); - if( avoid_lpc_burst_on_recovery && (sub(enr_LP, 160) > 0) && (sub(enr_LP, shl(*old_enr_LP, 1)) <= 0) ) - { - gain1 = s_min(gain1, 16384); - } - - /*--------------------------------------------------------* - * Prevent a catastrophy in case of offset followed by onset - *--------------------------------------------------------*/ - test(); - if( ( sub(clas,ONSET) == 0 ) && (sub(gain1,gain2) > 0) ) - { - gain1 = gain2; - move16(); - } - } - /*-----------------------------------------------------------------* - * Smooth the energy evolution by exponentially evolving from - * gain1 to gain2 - *-----------------------------------------------------------------*/ - - L_tmp = L_mult(gain2, (Word16)(32768 - AGC_FX)); - - FOR( i=0; i= 0 && sub(clas,INACTIVE_CLAS) < 0) ) - { - IF( sub(clas,VOICED_TRANSITION) == 0 ) - { - L_enr2_av = L_enr2; - move32(); - frame_ener_fx(L_frame,VOICED_CLAS, synth,pitch[sub(shr(L_frame,6),1)], &L_ener2_max/*Q0*/, 1, Q_syn, 3, 0); - } - ELSE - { - L_ener2_max = L_enr2; - move32(); - frame_ener_fx(L_frame,UNVOICED_CLAS, synth, pitch[sub(shr(L_frame,6),1)], &L_enr2_av/*Q0*/, 1, Q_syn, 3, 0); - } - - /**lp_ener_FEC_av = 0.2f * enr2_av + 0.8f * *lp_ener_FEC_av; move32();*/ - *lp_ener_FEC_av = Madd_32_16(Mult_32_16(*lp_ener_FEC_av, 31130), L_enr2_av, 1638); - move32(); - /**lp_ener_FEC_max = 0.2f * enr2_max + 0.8f * *lp_ener_FEC_max; move32();*/ - *lp_ener_FEC_max = Madd_32_16(Mult_32_16(*lp_ener_FEC_max, 31130), L_ener2_max, 1638); - move32(); - } - - /*-----------------------------------------------------------------* - * Update the LP filter energy for voiced frames - *-----------------------------------------------------------------*/ - test(); - if( sub(clas,VOICED_TRANSITION) >= 0 && sub(clas,INACTIVE_CLAS) < 0 ) - { - *old_enr_LP = enr_LP; - move16(); - } - - return; - -} diff --git a/src/libs/libevs/lib_dec/LD_music_post_filter.cpp b/src/libs/libevs/lib_dec/LD_music_post_filter.cpp new file mode 100644 index 00000000..d1c808bd --- /dev/null +++ b/src/libs/libevs/lib_dec/LD_music_post_filter.cpp @@ -0,0 +1,702 @@ +/*==================================================================================== + EVS Codec 3GPP TS26.443 Nov 13, 2018. Version 12.11.0 / 13.7.0 / 14.3.0 / 15.1.0 + ====================================================================================*/ + +#include +#include "options.h" +#include "cnst.h" +#include "rom_com.h" +#include "prot.h" + +/*-------------------------------------------------------------------* + * Local constants + *-------------------------------------------------------------------*/ + +#define MAX_SNR1 45.0f +#define INV_MAX_SNR (1.f / (MAX_SNR1-1.0f)) /* max. SNR considered for noise subtraction in voiced segments */ +#define MAX_SNR_SNR1 (MAX_SNR1 * INV_MAX_SNR) /* 45 * (1 / (MAX_SNR1-1)) */ + + +#define BIN_1KHZ (short)(1000.f/BIN_16kdct) +#define BIN_2KHZ (short)(2000.f/BIN_16kdct) +#define BIN_4KHZ (short)(4000.f/BIN_16kdct) + +#define MAX_GN_R 0.2f +#define ALPH 1.00f +#define BET (1.925f-ALPH) +#define MAXX 5 + +/*-------------------------------------------------------------------* + * Local functions + *-------------------------------------------------------------------*/ + +static void spectrum_mod_dct( float data[], const float lf_E[], float lf_EO[], + const float noiseE[], const float minGain, float lp_gbin[], + const short music_flag, short min_band, const float MAX_GN, const short max_band ); + +static void analy_sp_dct( const float dct_in[], float dct_buf[], float *fr_bands, float *lf_E, float *etot ); + +static void find_enr_dct( const float data[], float band[], float *ptE, float *Etot, const short min_band, + const short max_band, float *Bin_E, const float bin_freq ); + +/*------------------------------------------------------------------------* + * LD_music_post_filter() + * + * Music post-filter + *------------------------------------------------------------------------*/ + +void LD_music_post_filter +( + const float dtc_in[], /* i : input synthesis */ + float dtc_out[], /* o : output synthesis */ + const long core_brate, /* i : core bitrate */ + short *last_music_flag, /* i/o : Previous music detection ouptut */ + float *thresh, /* i/o : Detection thresold */ + short *nb_thr_1, /* i/o : Number of consecutives frames of level 1 */ + short *nb_thr_3, /* i/o : Number of consecutives frames of level 3 */ + float *lt_diff_etot, /* i/o : Long term total energy variation */ + float *mem_etot, /* i/o : Total energy memory */ + const float min_ns_gain, /* i : minimum gain for inter-harm noise red. */ + float bckr[], /* i/o : per band bckgnd. noise energy estimate */ + float lf_EO[], /* i/o : old per bin E for previous half frame */ + float lp_gbin[], /* i/o : smoothed suppression gain, per FFT bin */ + float *filt_lfE, /* i : post filter weighting coefficient */ + short *last_nonfull_music,/* i : Number of frames sinces la "speech like" frame */ + const short coder_type /* i : Coder type : -1 in case of IO */ + ,const short Last_coder_type /* i : last Coder type */ +) +{ + float DCT_buf[DCT_L_POST]; + float fr_bands[MBANDS_GN_LD]; + float lf_E[VOIC_BINS_HR]; + float etot, ftmp; + short i, j, k; + short min_band = 0; + float local_min_gain = min_ns_gain; + short music_flag2 = 0; + float max_val; + float max_ovf_2k, max_ovf_4k, max_ovf_6k; + float min_g_2k, min_g_4k, min_g_6k; + float m_ave, old_ftmp; + float old_ftmp_1; + float tmp_lfE[DCT_L_POST]; + float MAX_GN = MAX_GN_R; + short MAX_band = MBANDS_GN_LD; + + /*------------------------------------------------------------------------* + * Frequency analysis + *------------------------------------------------------------------------*/ + + analy_sp_dct( dtc_in, DCT_buf, fr_bands, lf_E, &etot ); + + /*------------------------------------------------------------------------* + * Find signal classification + *------------------------------------------------------------------------*/ + + music_flag2 = stab_est( etot, lt_diff_etot, mem_etot, + nb_thr_3, nb_thr_1, thresh, last_music_flag, 1 ); + + if ( core_brate < ACELP_6k60 || Last_coder_type != AUDIO ) + { + /* do not perform music improvement on SID frames */ + music_flag2 = 0; + } + + if( music_flag2 < 4 ) + { + *last_nonfull_music = 0; + } + else + { + (*last_nonfull_music)++; + } + + *last_nonfull_music = min( 51, *last_nonfull_music ); + + /*------------------------------------------------------------------------* + * Remapping of bands + * Section to "remap" the minimal band and the minimum gain for our needs + *------------------------------------------------------------------------*/ + + if( music_flag2 > 3) + { + min_band = 2; + local_min_gain = 0.25119f; + } + else if( music_flag2 == 3) + { + min_band = 3; + local_min_gain = 0.25119f; + } + else if( music_flag2 == 2) + { + min_band = 4; + local_min_gain = 0.35481f; + } + else if( music_flag2 == 1) + { + min_band = 4; + local_min_gain = 0.50119f; + } + + min_band += 4; + + MAX_GN = 0.1f; + if( core_brate > ACELP_9k60 ) + { + /* overshoot not allowed, since GSC already matches the energy */ + MAX_GN = 0.0f; + } + + if( coder_type == AUDIO ) + { + /* with GSC we know for sure that we are in music */ + min_band = min( min_band, 3 ); + } + + /*------------------------------------------------------------------------* + * Approximation of the inter-harmonic noise level + * - sort the bin energy + * - compupte the average energy per band excluding the maximum energy bin + *------------------------------------------------------------------------*/ + + j = 0; + for (i = 0; i < MBANDS_GN_LD; i++) + { + m_ave = 0.0f; + max_val = 0.0f; + + for( k=j; k < mfreq_bindiv_LD[i]+j; k++ ) + { + m_ave += lf_E[k]; + max_val = max(max_val, lf_E[k]); + } + + m_ave -= max_val; + m_ave /= mfreq_bindiv_LD[i] - 1; + + bckr[i] = m_ave*sc_qnoise[i]; + j += mfreq_bindiv_LD[i]; + } + + i = maximum(lf_E, DCT_L_POST, &m_ave); + + /*------------------------------------------------------------------------* + * - Normalisation of the energy vector between [0.72, 5], with the form of pow(x,4) + * - Simple LP filtering along the frequency domain + * - LT averaging with the past and in function of the stability factor + *------------------------------------------------------------------------*/ + + m_ave = ALPH/lf_E[i]; + + ftmp = lf_E[0]*m_ave+BET; + ftmp *= ftmp; + ftmp *= ftmp; + ftmp *= ftmp; + ftmp = min(ftmp, MAXX); + old_ftmp = ftmp; + + ftmp = lf_E[1]*m_ave+BET; + ftmp *= ftmp; + ftmp *= ftmp; + ftmp *= ftmp; + ftmp = min(ftmp, MAXX); + old_ftmp_1 = ftmp; + tmp_lfE[0] = 0.5f*old_ftmp + 0.5f*ftmp; + + for(i = 1; i < DCT_L_POST-1; i++) + { + tmp_lfE[i] = 0.333f*old_ftmp + 0.333f*old_ftmp_1; + old_ftmp = old_ftmp_1; + ftmp = lf_E[i+1]*m_ave+BET; + ftmp *= ftmp; + ftmp *= ftmp; + ftmp *= ftmp; + old_ftmp_1 = min(ftmp, MAXX); + tmp_lfE[i] += 0.333f * old_ftmp_1; + } + + ftmp = lf_E[i] * m_ave + BET; + ftmp *= ftmp; + ftmp *= ftmp; + ftmp *= ftmp; + ftmp = min(ftmp, MAXX); + tmp_lfE[i] = 0.5f * old_ftmp + 0.5f * ftmp; + + for(i = 0; i < BIN_4KHZ; i++) + { + filt_lfE[i] = tmp_lfE[i] * 0.05f + 0.95f * filt_lfE[i]; + } + + for(; i < DCT_L_POST; i++) + { + filt_lfE[i] = tmp_lfE[i] * 0.15f + 0.85f * filt_lfE[i]; + } + + /*------------------------------------------------------------------------* + * Reduce inter-harmonic noise with SNR based method + * Second stage of spectral shaping modification based on the pow(x,4) energy spectrum + *------------------------------------------------------------------------*/ + + if( coder_type == AUDIO ) + { + MAX_band = 16; + } + + spectrum_mod_dct( DCT_buf, lf_E, lf_EO, bckr, local_min_gain, lp_gbin, music_flag2, min_band, MAX_GN, MAX_band ); + + i = 0; + if( music_flag2 >= 1 ) + { + for(i = 0; i < BIN_1KHZ; i++) + { + ftmp = min(1.0f, filt_lfE[i]); + DCT_buf[i] *= ftmp; + } + } + + if( *last_nonfull_music > 40 ) + { + max_ovf_2k = 1.25f; + max_ovf_4k = 1.5f; + max_ovf_6k = 1.5f; + + min_g_2k = 0.0f; + min_g_4k = 0.0f; + min_g_6k = 0.0f; + + if( coder_type == AUDIO ) + { + max_ovf_2k = 1.0f; + max_ovf_4k = 1.1f; + max_ovf_6k = 1.25f; + + min_g_2k = 0.75f; + min_g_4k = 0.5f; + min_g_6k = 0.5f; + + if( core_brate > ACELP_9k60 ) + { + max_ovf_4k = 1.0f; + max_ovf_6k = 1.15f; + + min_g_2k = 0.925f; + min_g_4k = 0.825f; + min_g_6k = 0.75f; + } + } + else if( core_brate >= ACELP_12k65 ) + { + max_ovf_2k = 1.0f; + max_ovf_4k = 1.25f; + + if( core_brate > ACELP_15k85 ) + { + max_ovf_4k = 1.0f; + max_ovf_6k = 1.25f; + + min_g_2k = 0.75f; + min_g_4k = 0.5f; + min_g_6k = 0.5f; + } + } + + for(; i < BIN_2KHZ; i++) + { + ftmp = min(max_ovf_2k, filt_lfE[i]); + ftmp = max(min_g_2k, ftmp); + DCT_buf[i] *= ftmp; + } + + for(; i < BIN_4KHZ; i++) + { + ftmp = min(max_ovf_4k, filt_lfE[i]); + ftmp = max(min_g_4k, ftmp); + DCT_buf[i] *= ftmp; + } + + if( coder_type != AUDIO || core_brate > ACELP_8k85 ) + { + /* Do not modify HF when coded with GSC at LR, because the spectrum is just noise */ + for(; i < DCT_L_POST; i++) + { + ftmp = min(max_ovf_6k, filt_lfE[i]); + ftmp = max(min_g_6k, ftmp); + DCT_buf[i] *= ftmp; + } + } + } + else if( *last_nonfull_music > 25 ) + { + /* When unsure on content type only slight clean-up allowed, no overshoot allowed */ + for(; i < DCT_L_POST; i++) + { + ftmp = min(1.f, filt_lfE[i]); + DCT_buf[i] *= ftmp; + } + } + + /* reconstruction of the enhanced synthesis */ + mvr2r( DCT_buf, dtc_out, DCT_L_POST ); +} + +/*---------------------------------------------------------------------------* + * spectrum_mod_dct() + * + * spectrum enhancement according to the output of signal_type_clas() + *---------------------------------------------------------------------------*/ + +static void spectrum_mod_dct( + float data[], /* i/o: DCT spectrum */ + const float lf_E[], /* i: per bin E for first 46 bins (without DC) */ + float lf_EO[], /* i/o: old per bin E for previous half frame */ + const float noiseE[], /* i: per band background noise energy estimate */ + const float minGain, /* i: minimum suppression gain */ + float lp_gbin[], /* i/o: Smoothed suppression gain, per FFT bin */ + const short music_flag, /* i: music ? 1:0 */ + short min_band, + const float MAX_GN, + const short MAX_band +) +{ + float maxNoise; + float binE[VOIC_BINS_HR]; + float gain, minE; + float freq; + float slope; + float inv_noise[MBANDS_GN_LD]; + float *pt_gbin, alpha, tmpN; + short i, cnt; + float *pt; + float tmp, shift; + const float *pt2; + + gain = 0.0f; + + /*-----------------------------------------------------------------* + * Compute the inverse of noise + *-----------------------------------------------------------------*/ + + for (i=0; i<=MBANDS_GN_LD-1; i++) + { + inv_noise[i] = 1.0f / noiseE[i]; + } + + /*----------------------------------------------------------------------* + * Perform noise reduction for 1 frames + *----------------------------------------------------------------------*/ + + for (i=0; i < VOIC_BINS_HR; i++) + { + binE[i] = 0.3f * lf_EO[i] + 0.7f * lf_E[i]; + } + mvr2r(lf_E, lf_EO, VOIC_BINS_HR); /* update */ + + /*----------------------------------------------------------------------* + * Find the maximum noise in a critical band + *----------------------------------------------------------------------*/ + + maxNoise = 0.0f; + for (i=0; i<=MBANDS_GN_LD-1; i++) + { + set_max(&maxNoise, noiseE[i]); + } + + /* pointer initialization */ + pt = &data[0]; + + /*-----------------------------------------------------------------* + * Initialization for active speech frames or VAD hangover frames, + * (exclude Clean speech) + *-----------------------------------------------------------------*/ + + if ( music_flag != 0 ) /* prevent subtraction on clean speech */ + { + if( maxNoise <= 10.0f) + { + minE = .5625f; + } + else + { + minE = minGain*minGain; + } + + pt2 = binE; + freq = 0; + + pt_gbin = lp_gbin; + tmp = INV_MAX_SNR; + slope = tmp - tmp * minE; + shift = MAX_SNR_SNR1 * minE - tmp; + for (i=0; i < min_band; i++) + { + for (; freq <= mfreq_loc_LD[i]; freq += BIN_16kdct) + { + pt2++; + pt++; + *pt_gbin++ = 1.0f; + } + } + + /*-----------------------------------------------------------------* + * Per Frequency MODE1_BIN processing + * For highly voiced and highly pitched speech, use per bin + * subtraction in low frequencies (maximum up to 3700 Hz, + * first 17 critical bands) + *-----------------------------------------------------------------*/ + + for (; i < MAX_band/*MBANDS_GN_LD*/; i++) + { + + tmp = INV_MAX_SNR_tab[i]; + slope = tmp - tmp * minE; + shift = MAX_SNR_SNR1_tab[i] * minE - tmp; + + tmpN = slope * inv_noise[i]; + tmp = 0.0f; + cnt = 0; + while (freq <= mfreq_loc_LD[i]) + { + gain = 1.0f; + + if (noiseE[i] >= 0.5f) /* Do not alter if noise E very low */ + { + gain = tmpN **pt2 + shift; /* limits: [x,y] = {[1, minE], [MAX_SNR1, 1]}, */ + } + + pt2++; + + if (gain < minE) + { + gain = minE; + } + + if (gain > 1.0f+MAX_GN) + { + gain = 1.0f+MAX_GN; + } + + /* the gain smoothing control: stronger lp filtering for lower gains */ + alpha = 1.0f - (float)sqrt(gain); + + *pt_gbin = gain + alpha **pt_gbin; + *pt++ *= *pt_gbin; + cnt++; + freq += BIN_16kdct; + pt_gbin++; + } + } + } + else + { + freq = BIN_16kdct; + pt_gbin = lp_gbin; + for (i=0; i < MBANDS_GN_LD; i++) + { + for (; freq <= mfreq_loc_LD[i]; freq += BIN_16kdct) + { + *pt_gbin = 0.9f* *pt_gbin + 0.1f; + pt_gbin++; + } + } + } + + return; +} + +/*----------------------------------------------------------------------------------* + * analy_sp_dct() + * + * Spectral analysis of the current synthesized frame + *----------------------------------------------------------------------------------*/ + +static void analy_sp_dct( + const float dct_in[], /* i: input DCT spectrum */ + float dct_buf[], /* i: output DCT spectrum */ + float *fr_bands, /* o: energy in critical frequency bands */ + float *lf_E, /* o: per bin E for first... */ + float *etot /* o: total input energy */ +) +{ + float Bin_E[DCT_L_POST]; + + *etot = 0.0f; + mvr2r( dct_in, dct_buf, DCT_L_POST ); + + /*-----------------------------------------------------------------* + * Windowing + * Compute spectrum + * find energy per critical frequency band and total energy in dB + *-----------------------------------------------------------------*/ + + find_enr_dct( dct_buf, fr_bands, lf_E, etot, 0, MBANDS_GN_LD, Bin_E, BIN_16kdct ); + + /* find average log total energy over both half-frames */ + *etot = 10.0f * (float)log10(*etot) - 3.0103f; + + return; +} + +/*------------------------------------------------------------------------* + * find_enr_dct) + * + * find input signal energy for each critical band and first 74 LF bins + * The energy is normalized by the number of frequency bins in a channel + *------------------------------------------------------------------------*/ + +void find_enr_dct( + const float data[], /* i : fft result, for the format see fft_rel.c */ + float band[], /* o : per band energy */ + float *ptE, /* o : per bin energy for low frequencies */ + float *Etot, /* o : total energy */ + const short min_band, /* i : minimum critical band */ + const short max_band, /* i : maximum critical band */ + float *Bin_E, /* o : Per bin energy */ + const float bin_freq /* i : Number of frequency bins */ +) +{ + short i, cnt; + float freq, tmp; + const float *ptR; + + ptR = &data[0]; /* pointer to first real coefficient */ + freq = 0; + for( i=0; i < max_band; i++ ) + { + band[i] = 0.0f; + cnt = 0; + while( freq <= mfreq_loc_LD[i] ) + { + /* energy */ + *ptE = *ptR **ptR; + + /* normalization - corresponds to FFT normalization by 2/L_FFT */ + *ptE *= 1.0f / (DCT_L_POST); + + *Bin_E = *ptE; + Bin_E++; + band[i] += *ptE++; + ptR++; + + freq += bin_freq; + cnt++; + } + + /* normalization per frequency bin */ + band[i] /= cnt; + + if ( band[i] < E_MIN ) + { + band[i] = E_MIN; + } + } + + /*-----------------------------------------------------------------* + * Find the total energy over the input bandwidth + *-----------------------------------------------------------------*/ + + tmp = *Etot; + for( i = min_band; i <= NB_LIMIT_BAND; i++ ) + { + /* total channel energy */ + tmp += band[i]; + } + + *Etot = tmp; + + return; +} + +/*------------------------------------------------------------------------* + * Prep_music_postP() + * + * Performs the steps needed to do the music post processing + *------------------------------------------------------------------------*/ + +void Prep_music_postP( + float exc_buffer_in[], /* i/o: excitation buffer */ + float dct_buffer_out[], /* o : DCT output buffer */ + float filt_lfE[], /* i/o: long term spectrum energy */ + const short last_core, /* i : last core */ + const float *pitch_buf, /* i : current frame pitch information */ + float *LDm_enh_lp_gbin /* o : smoothed suppression gain, per bin FFT */ +) +{ + short i; + float *pt1; + const float *pt2; + short s_pit, fr_pit; + + s_pit = (short)(pitch_buf[3]); + fr_pit = (short)((pitch_buf[3] - s_pit) * 4.0f); + + /*------------------------------------------------------------* + * Extrapolation of the last future part and windowing + *------------------------------------------------------------*/ + + if( last_core == HQ_CORE ) + { + set_f( filt_lfE, 1.0f, DCT_L_POST ); + set_f( LDm_enh_lp_gbin, 1.0f, VOIC_BINS_HR ); + pt1 = exc_buffer_in + OFFSET2 - 1; + pt2 = pt1 + (short)(pitch_buf[0] + 0.5f); + for( i = 0; i < OFFSET2; i++ ) + { + *pt1 = *pt2; + pt1--; + pt2--; + } + } + + pt1 = exc_buffer_in + DCT_L_POST - OFFSET2; + pred_lt4( pt1, pt1, s_pit, fr_pit, OFFSET2, inter4_2, L_INTERPOL2, PIT_UP_SAMP ); + + pt2 = post_dct_wind; + for( i = 0; i < OFFSET2; i++ ) + { + *pt1 *= *pt2; + pt1++; + pt2++; + } + + pt1 = exc_buffer_in; + pt2--; + for( i = 0; i < OFFSET2; i++ ) + { + *pt1 *= *pt2; + pt1++; + pt2--; + } + + edct( exc_buffer_in, dct_buffer_out, DCT_L_POST ); + + return; +} + +/*------------------------------------------------------------------------* + * Post_music_postP() + * + * Going back from frequency to time domain from the enhanced spectrum + * to retreive the aligned excitation and redo the synthesis + *------------------------------------------------------------------------*/ + +void Post_music_postP( + float dct_buffer_in[], /* i/o: excitation buffer */ + float exc_buffer_out[], /* o : DCT output buffer */ + float *exc2, /* i/o: Current excitation to be overwriten */ + const float *mem_tmp, /* i : previous frame synthesis memory */ + float *st_mem_syn2, /* i/o: current frame synthesis memory */ + const float *Aq, /* i : LPC filter coefficients */ + float *syn /* i/o: 12k8 synthesis */ +) +{ + edct( dct_buffer_in, exc_buffer_out, DCT_L_POST ); + + mvr2r( exc_buffer_out + OFFSET2, exc2, L_FRAME ); + mvr2r( mem_tmp, st_mem_syn2, M ); + + syn_12k8( L_FRAME, Aq, exc2, syn, st_mem_syn2, 1 ); + + return; +} + diff --git a/src/libs/libevs/lib_dec/LD_music_post_filter_fx.cpp b/src/libs/libevs/lib_dec/LD_music_post_filter_fx.cpp deleted file mode 100755 index 5966b01a..00000000 --- a/src/libs/libevs/lib_dec/LD_music_post_filter_fx.cpp +++ /dev/null @@ -1,914 +0,0 @@ -/*==================================================================================== - EVS Codec 3GPP TS26.442 Apr 03, 2018. Version 12.11.0 / 13.6.0 / 14.2.0 - ====================================================================================*/ - -#include "options.h" /* Compilation switches */ -#include "cnst_fx.h" /* Common constants */ -#include "rom_com_fx.h" /* Static table prototypes */ -#include "prot_fx.h" /* Function prototypes */ -#include "stl.h" - - -/*-------------------------------------------------------------------* - * Local constants - *-------------------------------------------------------------------*/ - -#define INV_MAX_SNR_FX 745 /* Q15 {1/(45-1)} Max. SNR considered for noise subtraction in voiced segments */ -#define MAX_SNR_SNR1_FX 16756 /* Q14 45* (1/(max_snr1-1)) */ - -#define BIN_1KHZ (short)(1000/BIN_16kdct_fx) -#define BIN_2KHZ (short)(2000/BIN_16kdct_fx) -#define BIN_4KHZ (short)(4000/BIN_16kdct_fx) - -#define MAX_GN_R_Q14_FX 3277 -#define ALPH_Q15_FX 32767 -#define BET_Q15_FX 30310 -#define MAXX_Q12_FX (20480) - -#define MAXX_FX 5 - -/*-------------------------------------------------------------------* - * Local functions - *-------------------------------------------------------------------*/ -static void analy_sp_dct_fx(const Word16 *dct_buf, Word32 *fr_bands, Word32 *lf_E, Word16 *etot, const Word16 Qdct); -static void find_enr_dct_fx(const Word16 data[], Word32 band[], Word32 *ptE, Word32 *Etot, const Word16 min_band, - const Word16 max_band, const Word16 Q_dct, const Word16 bin_freq ); -static Word16 norm_lfe(const Word32 Lfe,const Word16 m_max,const Word16 e_max); -static void spectrum_mod_dct_fx(const Word16 Qdct,Word16 data[], const Word32 lf_E[], Word32 lf_EO[], - const Word32 noiseE[], const Word16 minGain, - Word16 lp_gbin[], const Word16 music_flag, Word16 min_band, const Word16 MAX_GN, const Word16 MAX_band ); - -/*------------------------------------------------------------------------* - * LD_music_post_filter() - * - * Music post-filter - *------------------------------------------------------------------------*/ -void LD_music_post_filter_fx -( - const Word16 dtc_in[], /* i : input synthesis Qdct */ - Word16 dtc_out[], /* o : output synthesis Qdct */ - const Word32 core_brate, /* i : core bitrate Q0 */ - Word16 *last_music_flag, /* i/o : Previous music detection ouptut Q0 */ - Word16 *thresh, /* i/o : Detection thresold Q0 */ - Word16 *nb_thr_1, /* i/o : Number of consecutives frames of level 1 Q0 */ - Word16 *nb_thr_3, /* i/o : Number of consecutives frames of level 3 Q0 */ - Word16 *lt_diff_etot, /* i/o : Long term total energy variation Q8 */ - Word16 *mem_etot, /* i/o : Total energy memory Q8 */ - const Word16 min_ns_gain, /* i : minimum gain for inter-harm noise red. Q15 */ - Word32 bckr[], /* i/o : per band bckgnd. noise energy estimate */ - Word32 lf_EO[], /* i/o : old per bin E for previous half frame 2*Qdct+10 */ - Word16 lp_gbin[], /* i/o : smoothed suppression gain, per FFT bin Q15 */ - Word16 *filt_lfE, /* i : post filter weighting coefficient Q15 */ - Word16 *last_nonfull_music, /* i: Number of frames sinces la "speech like" frame Q0*/ - Word16 *Old_ener_Q, /* i/o : Old energy scaling factor */ - const Word16 coder_type, /* i : Coder type : -1 in case of IO Q0 */ - const Word16 Last_coder_type, /* i : input scaling Q0 */ - const Word16 Qdct /* i : input scaling Q0 */ -) -{ - Word32 fr_bands[MBANDS_GN_LD]; - Word32 lf_E[VOIC_BINS_HR]; - Word32 Ltmp, Ltmp_max; - Word16 LG_etot; /*Q8*/ - Word16 i, j, k; - Word16 min_band = 0; - Word16 local_min_gain = min_ns_gain; - Word16 music_flag2 = 0; - Word32 max_val; - Word16 max_ovf_2k, max_ovf_4k, max_ovf_6k; - Word16 min_g_2k, min_g_4k, min_g_6k; - Word32 m_ave; - Word16 tmp_lfE[DCT_L_POST]; /*Q12*/ - Word16 MAX_GN = MAX_GN_R_Q14_FX; - Word16 MAX_band = MBANDS_GN_LD; - Word16 mant, exp1, s_ave, tmp16, old_tmp16; - Word16 diff_sc; - Word16 old_tmp16_1; - /*------------------------------------------------------------------------* - * Frequency analysis - *------------------------------------------------------------------------*/ - - analy_sp_dct_fx( dtc_in, fr_bands, lf_E, &LG_etot, Qdct); - diff_sc = shl(sub(Qdct, *Old_ener_Q),1); - *Old_ener_Q = Qdct; - move16(); - - Scale_sig32(lf_EO, VOIC_BINS_HR, diff_sc); - - /*------------------------------------------------------------------------* - * Find signal classification - *------------------------------------------------------------------------*/ - music_flag2 = stab_est_fx( LG_etot, lt_diff_etot, mem_etot - , nb_thr_3, nb_thr_1, thresh, last_music_flag, 1 ); - - test(); - if ( L_sub(core_brate,ACELP_6k60) < 0 || sub(Last_coder_type, AUDIO) != 0 ) - { - /* do not perform music improvement on SID frames */ - music_flag2 = 0; - move16(); - } - - *last_nonfull_music = add(*last_nonfull_music,1); - move16(); - if( sub(music_flag2,4) < 0 ) - { - *last_nonfull_music = 0; - move16(); - } - - - *last_nonfull_music = s_min( 51, *last_nonfull_music ); - - /*------------------------------------------------------------------------* - * Remapping of bands - * Section to "remap" the minimal band and the minimum gain for our needs - *------------------------------------------------------------------------*/ - - IF( sub(music_flag2,3) > 0) - { - min_band = 2; - move16(); - local_min_gain = 8231; /*Q15->0.25119f;*/ move16(); - } - ELSE IF( sub(music_flag2,3) == 0) - { - min_band = 3; - move16(); - local_min_gain = 8231; /*Q15->0.25119f; */ move16(); - } - ELSE IF( sub(music_flag2,2) == 0) - { - min_band = 4; - move16(); - local_min_gain = 11626; /*Q15->0.35481f; */ move16(); - } - ELSE IF( sub(music_flag2,1) == 0) - { - min_band = 4; - move16(); - local_min_gain = 16423; /*Q15->0.50119f;*/ move16(); - } - - min_band = add(min_band, 4); - - MAX_GN = 1638; /*Q14*/ move16(); - if( L_sub(core_brate,ACELP_9k60) > 0 ) - { - /* overshoot not allowed, since GSC already matches the energy */ - MAX_GN = 0; - move16(); - } - - if( sub(coder_type,AUDIO) == 0 ) - { - /* with GSC we know for sure that we are in music */ - min_band = s_min( min_band, 3 ); - } - - /*------------------------------------------------------------------------* - * Approximation of the inter-harmonic noise level - * - sort the bin energy - * - compupte the average energy per band excluding the maximum energy bin - *------------------------------------------------------------------------*/ - - j = 0; - move16(); - Ltmp_max = L_deposit_l(0); - FOR (i = 0; i < MBANDS_GN_LD; i++) - { - Ltmp = L_deposit_l(0); - max_val = L_deposit_l(0); - - FOR( k=j; k < mfreq_bindiv_LD[i]+j; k++ ) - { - /*m_ave += lf_E[k];*/ - Ltmp = L_add(lf_E[k], Ltmp); - max_val = L_max(max_val, lf_E[k]); - } - Ltmp_max = L_max(Ltmp_max, max_val); - /*m_ave -= max_val;*/ - Ltmp = L_sub(Ltmp, max_val); - /*m_ave /=(mfreq_bindiv_LD[i]-1);*/ - m_ave = Mult_32_16(Ltmp,inv_mfreq_bindiv_LD_M1_fx[i]); - - /*bckr[i] = m_ave*sc_qnoise[i];*/ - bckr[i] = Mult_32_16(m_ave,sc_qnoise_fx[i]); - move32(); - - j+=mfreq_bindiv_LD[i]; - } - - /* This is computed inside the loop i = maximum(lf_E, DCT_L_POST, &m_ave);*/ - /*------------------------------------------------------------------------* - * - Normalisation of the energy vector between [0.72, 5], with the form of pow(x,4) - * - Simple LP filtering along the frequency domain - * - LT averaging with the past and in function of the stability factor - *------------------------------------------------------------------------*/ - /*m_ave = ALPH/lf_E[i];*/ - exp1 = norm_l(Ltmp_max); - mant = extract_h(L_shl(Ltmp_max, exp1)); - /*exp1 = sub(16,exp1);*/ - - s_ave = div_s(16384, mant); - exp1 = sub(14/*+15*/+16, exp1); /*s_ave in Q15 + exp1*/ - old_tmp16 = norm_lfe(lf_E[0], s_ave, exp1); - old_tmp16 = s_min(old_tmp16, MAXX_Q12_FX); - tmp16 = norm_lfe(lf_E[1], s_ave, exp1); - tmp16 = s_min(tmp16, MAXX_Q12_FX); - old_tmp16_1 = tmp16; - move16(); - tmp_lfE[0] = round_fx(L_mac(L_mult(16384, old_tmp16), 16384, tmp16)); - - FOR(i = 1; i < DCT_L_POST-1; i++) - { - /*tmp_lfE[i] = 0.333f*old_ftmp + 0.333f*ftmp; */ - Ltmp = L_mac(L_mult(10813, old_tmp16), 10813, old_tmp16_1); - - old_tmp16 = old_tmp16_1; - move16(); - tmp16 = norm_lfe(lf_E[i+1], s_ave, exp1); - /*ftmp = min(ftmp, MAXX); - tmp_lfE[i] += 0.333f*ftmp; */ - old_tmp16_1 = s_min(tmp16, MAXX_Q12_FX); - Ltmp = L_mac(Ltmp, 10813, old_tmp16_1); - tmp_lfE[i] = round_fx(Ltmp); - } - - tmp16 = norm_lfe(lf_E[i], s_ave, exp1); - /*ftmp = min(ftmp, MAXX); - tmp_lfE[i] = 0.5f*old_ftmp + 0.5f*ftmp;*/ - tmp16 = s_min(tmp16, MAXX_Q12_FX); - tmp_lfE[i] = round_fx(L_mac(L_mult(16384, old_tmp16), 16384, tmp16)); - - FOR(i = 0; i < BIN_4KHZ; i++) - { - /*filt_lfE[i] = tmp_lfE[i]*.05f + .95f*filt_lfE[i] ;*/ - filt_lfE[i] = round_fx(L_mac(L_mult(tmp_lfE[i],1638), 31130, filt_lfE[i])) ; - } - - FOR(; i < DCT_L_POST; i++) - { - /*filt_lfE[i] = tmp_lfE[i]*(.15f) + .85f*filt_lfE[i] ;*/ - filt_lfE[i] = round_fx(L_mac(L_mult(tmp_lfE[i],4915), 27853, filt_lfE[i])) ; - } - /*------------------------------------------------------------------------* - * - Reduce inter-harmonic noise with SNR based method - * - Second stage of spectral shaping modification based - * on the pow(x,4) energy spectrum - *------------------------------------------------------------------------*/ - - if( sub(coder_type,AUDIO) == 0 ) - { - MAX_band = 16; - move16(); - } - - Copy(dtc_in, dtc_out, DCT_L_POST); - - spectrum_mod_dct_fx( Qdct, dtc_out, lf_E, lf_EO, bckr, local_min_gain, lp_gbin, music_flag2, min_band, MAX_GN, MAX_band ); - - i = 0; - move16(); - IF( sub(music_flag2,1) >= 0 ) - { - FOR(i = 0; i < BIN_1KHZ; i++) - { - tmp16 = s_min(4096, filt_lfE[i]); - dtc_out[i] = round_fx(L_shl(L_mult(dtc_out[i], tmp16),3)); - } - } - { - IF( sub(*last_nonfull_music,40) > 0 ) - { - max_ovf_2k = 5120; /*1.25 Q12*/ move16(); - max_ovf_4k = 6144; /*1.5 Q12*/ move16(); - max_ovf_6k = 6144; /*1.5 Q12*/ move16(); - - min_g_2k = 0; - move16(); - min_g_4k = 0; - move16(); - min_g_6k = 0; - move16(); - - IF( sub(coder_type,AUDIO ) == 0) - { - max_ovf_2k = 4096; /*1.0 Q12*/ move16(); - max_ovf_4k = 4506; /*1.1 Q12*/ move16(); - max_ovf_6k = 5120; /*1.25 Q12*/ move16(); - - min_g_2k = 3072; /*0.75 Q12*/ move16(); - min_g_4k = 2048; /*0.5 Q12*/ move16(); - min_g_6k = 2048; /*0.5 Q12*/ move16(); - - IF( L_sub(core_brate,ACELP_9k60) > 0 ) - { - max_ovf_4k = 4096; /*1.0 Q12*/ move16(); - max_ovf_6k = 4710; /*1.15 Q12*/ move16(); - - min_g_2k = 3789; /*0.925 Q12*/ move16(); - min_g_4k = 3379; /*0.825 Q12*/ move16(); - min_g_6k = 3072; /*0.75 Q12*/ move16(); - } - } - ELSE IF( L_sub(core_brate,ACELP_12k65) >= 0 ) - { - max_ovf_2k = 4096; /*1.0 Q12*/ move16(); - max_ovf_4k = 5120; /*1.25 Q12*/ move16(); - - IF( L_sub(core_brate,ACELP_15k85) > 0 ) - { - max_ovf_4k = 4096; /*1.0 Q12*/ move16(); - max_ovf_6k = 5120; /*1.25 Q12*/ move16(); - - min_g_2k = 3072; /*0.75 Q12*/ move16(); - min_g_4k = 2048; /*0.5 Q12*/ move16(); - min_g_6k = 2048; /*0.5 Q12*/ move16(); - } - } - - FOR(; i < BIN_2KHZ; i++) - { - tmp16 = s_min(max_ovf_2k, filt_lfE[i]); - tmp16 = s_max(min_g_2k, tmp16); - /*DCT_buf[i] *= ftmp;*/ - dtc_out[i] = round_fx(L_shl(L_mult(dtc_out[i], tmp16),3)); - - } - - FOR(; i < BIN_4KHZ; i++) - { - tmp16 = s_min(max_ovf_4k, filt_lfE[i]); - tmp16 = s_max(min_g_4k, tmp16); - /*DCT_buf[i] *= ftmp;*/ - dtc_out[i] = round_fx(L_shl(L_mult(dtc_out[i], tmp16),3)); - } - - test(); - IF( sub(coder_type,AUDIO) != 0 || L_sub(core_brate,ACELP_8k85) > 0 ) - { - /* Do not modify HF when coded with GSC at LR, because the spectrum is just noise */ - FOR(; i < DCT_L_POST; i++) - { - tmp16 = s_min(max_ovf_6k, filt_lfE[i]); - tmp16 = s_max(min_g_6k, tmp16); - /*DCT_buf[i] *= ftmp;*/ - dtc_out[i] = round_fx(L_shl(L_mult(dtc_out[i], tmp16),3)); - } - } - } - ELSE IF( sub(*last_nonfull_music,25) > 0 ) - { - /* When unsure on content type only slight clean-up allowed, no overshoot allowed */ - FOR(; i < DCT_L_POST; i++) - { - tmp16 = s_min(4096,filt_lfE[i]); - /*DCT_buf[i] *= ftmp;*/ - dtc_out[i] = round_fx(L_shl(L_mult(dtc_out[i], tmp16),3)); - } - } - } -} - -/*---------------------------------------------------------------------------* - * spectrum_mod_dct() - * - * spectrum enhancement according to the output of signal_type_clas() - *---------------------------------------------------------------------------*/ - -static void spectrum_mod_dct_fx( - const Word16 Qdct, /* i : scaling factor Q0 */ - Word16 data[], /* i/o: dct spectrum */ - const Word32 lf_E[], /* i: per bin E for first 46 bins (without DC) 2*Qdct+10 */ - Word32 lf_EO[], /* i/o: old per bin E for previous half frame 2*Qdct+10 */ - const Word32 noiseE[], /* i: per band background noise energy estimate 2*Qdct+10 */ - const Word16 minGain, /* i: minimum suppression gain Q15 */ - Word16 lp_gbin[], /* i/o: Smoothed suppression gain, per FFT bin Q14*/ - const Word16 music_flag, /* i: music ? 1:0 */ - Word16 min_band, /* i : minimum band */ - const Word16 MAX_GN, /* i : Maximum gain overshoot */ - const Word16 MAX_band /* i : minimum band */ -) -{ - Word32 maxNoise; - Word32 binE[VOIC_BINS_HR], Lgain; - Word16 gain = 0, minE; - Word16 freq, slope, m_invno[MBANDS_GN_LD],e_invno[MBANDS_GN_LD]; - Word16 *pt_gbin, alpha, tmpN; - Word16 i; - Word32 Ltmp; - Word16 scaling; - Word16 tmp_snr; - Word16 *pt; - Word16 wtmp; - Word16 e_tmp; - Word16 m_binE, e_binE; - Word16 e_gain; - Word16 sqrt_gain; - Word32 Lshift; - Word32 dot5_scaled; - const Word32 *Lpt2; - - gain = 0; - move16(); - - /*-----------------------------------------------------------------* - * Compute the inverse of noise - *-----------------------------------------------------------------*/ - - scaling = add(shl(Qdct,1),10); - dot5_scaled = L_shl(1, sub(scaling,1)); - FOR ( i=0; i<=MBANDS_GN_LD-1; i++) - { - /*inv_noise[i] = 1.0f / noiseE[i];*/ - IF (noiseE[i] != 0) - { - e_invno[i] = norm_l(noiseE[i]); - move16(); - m_invno[i] = extract_h(L_shl(noiseE[i],e_invno[i])); - e_invno[i] = sub(14, e_invno[i]); - move16(); - m_invno[i] = div_s(16384, m_invno[i]); - move16(); - } - ELSE - { - /* noiseE[i] == 0 only if Q_new <0*/ - e_invno[i] = add(-16,Qdct); - move16(); - m_invno[i] = MAX_16; - move16(); - } - } - /*----------------------------------------------------------------------* - * Perform noise reduction for 1 frames - *----------------------------------------------------------------------*/ - FOR (i=0 ; i < VOIC_BINS_HR ; i++) - { - /*binE[i] = (float)(0.3 * lf_EO[i] + 0.7 * lf_E[i]);*/ - Ltmp = Mult_32_16(lf_EO[i], 9830); - binE[i] = Madd_32_16(Ltmp, lf_E[i], 22938); - move32(); - } - Copy32( lf_E, lf_EO, VOIC_BINS_HR ); /* update */ - /*----------------------------------------------------------------------* - * Find the maximum noise in a critical band - *----------------------------------------------------------------------*/ - - maxNoise = L_max(noiseE[0], noiseE[1]); - FOR (i=2; i<=MBANDS_GN_LD-1; i++) - { - maxNoise = L_max(maxNoise, noiseE[i]); - } - - /* pointer initialization */ - pt = &data[0]; - - /*-----------------------------------------------------------------* - * Initialization for active speech frames or VAD hangover frames, - * (exclude Clean speech) - *-----------------------------------------------------------------*/ - - IF ( music_flag != 0 ) /* prevent subtraction on clean speech */ - { - IF( L_sub(maxNoise, L_shl(10, scaling)) <= 0) - { - minE = 18432/2; /*Q14*/ move16(); - } - ELSE - { - minE = shr(mult_r(minGain, minGain),1); /*Q14*/ - } - - Lpt2 = binE; - freq = 0; - move16(); - - pt_gbin = lp_gbin; - FOR (i=0; i < min_band; i++) - { - - FOR (; freq <= mfreq_loc_LD_fx[i]; freq += BIN_16kdct_fx) - { - Lpt2++; - /* Lgain is already saturate if it's > 1*/ - pt++; - *pt_gbin = 16384; - move16(); - pt_gbin++; - } - } - /*-----------------------------------------------------------------* - * Per Frequency BIN processing - * For highly voiced and highly pitched speech, use per bin - * subtraction in low frequencies (maximum up to 3700 Hz, - * first 17 critical bands) - *-----------------------------------------------------------------*/ - - FOR (; i < MAX_band; i++) - { - - /*tmp = INV_MAX_SNR_tab[i]; - slope = tmp - tmp * minE; - shift = MAX_SNR_SNR1_tab[i] * minE - tmp;*/ - - /*tmp = 1.0f/ (MAX_SNR1 - 1.0f);*/ - tmp_snr = INV_MAX_SNR_tab_FX[i]; - move16(); - /*slope = -tmp * minE + tmp;*/ - Ltmp = L_mult(tmp_snr, 16384); - slope = msu_r(Ltmp,tmp_snr, minE); /*Q14*/ - - /*shift = MAX_SNR1 * tmp * minE - tmp;*/ - Ltmp = L_mult(MAX_SNR_SNR1_tab_FX[i], minE); /*Q14*Q14*/ - Lshift = L_msu(Ltmp, tmp_snr,8192); /*Q15*Q13+Q29*/ - Lshift = L_shl(Lshift,1); /*Q29 -> Q30*/ - - /*tmpN = slope * inv_noise[i];*/ - tmpN = mult(slope, m_invno[i]); - e_tmp = e_invno[i]; - move16(); - - /*while (freq <= mfreq_loc_LD[i])*/ - FOR (; freq <= mfreq_loc_LD_fx[i]; freq += BIN_16kdct_fx) - { - /*gain = 1.0f;*/ - Lgain = L_deposit_h(16384); - /*if (noiseE[i] >= 0.5f)*/ - IF (L_sub(noiseE[i], dot5_scaled) > 0 )/* Do not alter if noise E very low */ - { - /*gain = tmpN * *pt2 + shift;*/ /* limits: [x,y] = {[1, minE], [MAX_SNR1, 1]}, */ - e_binE = norm_l(*Lpt2); - m_binE = extract_h(L_shl(*Lpt2, e_binE)); - - e_binE = sub(e_binE,0); /* lf_e divided by 4 in anal_sp*/ - - Ltmp = L_mult(tmpN, m_binE); - e_binE = sub(add(e_tmp, e_binE),15); - Ltmp = L_shr(Ltmp, e_binE); - Lgain = L_add(Ltmp, Lshift); /*Saturation can occure here result in Q30*/ - } - - Lpt2++; - gain = round_fx(Lgain); /*gain in Q30-16 = Q14*/ - /*if (gain < minE)gain = minE;*/ - gain = s_max(gain,minE); - /*if (gain > 1.0f+MAX_GN)gain = 1.0f+MAX_GN;*/ - gain = s_min(gain,add(16384, MAX_GN)); - - /* prepare gain to find sqrt */ - e_gain = norm_s(gain); - Ltmp = L_shl(gain, add(16,e_gain)); - e_gain = negate(sub(e_gain,1)); - - Ltmp = Isqrt_lc(Ltmp, &e_gain); - wtmp = extract_h(Ltmp); - sqrt_gain = div_s(16384,wtmp); - - - /* the gain smoothing control: stronger lp filtering for lower gains */ - /*alpha = 1.0f - (float)sqrt(gain);*/ - /* keep gain in Q14*/ - sqrt_gain = shr(sqrt_gain, e_gain); - /*alpha = 1.0f - gain;*/ /* the gain smoothing control: stronger LP filtering for lower gains */ - alpha = shl(sub(16384, sqrt_gain),1); - - /**pt_gbin = gain + alpha * *pt_gbin;*/ - Ltmp = L_mult(gain, 32767); - *pt_gbin = round_fx(L_mac(Ltmp, alpha, *pt_gbin)); /*Q14*/ - /**pt++ *= *pt_gbin;*/ - *pt = round_fx(L_shl(L_mult(*pt, *pt_gbin),1)); - pt++; - pt_gbin++; - } - } - } - ELSE - { - freq = BIN_16kdct_fx; - move16(); - pt_gbin = lp_gbin; - move16(); - FOR (i=0; i < MBANDS_GN_LD; i++) - { - FOR (; freq <= mfreq_loc_LD[i]; freq += BIN_16kdct_fx) - { - /**pt_gbin = 0.9f* *pt_gbin + 0.1f;*/ - *pt_gbin = round_fx(L_mac(L_mult(29491, *pt_gbin), 32767, 1638)); - pt_gbin++; - } - } - } - - return; - -} - - -/*----------------------------------------------------------------------------------* - * analy_sp_dct() - * - * Spectral analysis of the current synthesized frame - *----------------------------------------------------------------------------------*/ - -static void analy_sp_dct_fx( - const Word16 *dct_buf, /* i input dct spectrum */ - Word32 *fr_bands, /* o: energy in critical frequency bands 2*Qdct+10 */ - Word32 *lf_E, /* o: per bin E for first... 2*Qdct+10 */ - Word16 *etot, /* o: total input energy Q8 */ - const Word16 Qdct /* i: Scaling of dct */ -) -{ - Word32 Letot = 0; - Word16 exp_etot, frac_etot; - - Letot = L_deposit_l(0); - /*-----------------------------------------------------------------* - * find energy per critical frequency band and total energy in dB - *-----------------------------------------------------------------*/ - find_enr_dct_fx(dct_buf, fr_bands, lf_E, &Letot, 0, MBANDS_GN_LD, Qdct, BIN_16kdct_fx ); - - /* find average log total energy over both half-frames */ - /**etot = 10.0f * (float)log10(*etot) - 3.0103f;*/ - exp_etot = norm_l(Letot); - frac_etot = Log2_norm_lc(L_shl(Letot, exp_etot)); - exp_etot = sub(30, exp_etot); - exp_etot = sub(exp_etot, add(shl(Qdct,1),10+1)); /* +(1) */ - Letot = Mpy_32_16(exp_etot, frac_etot, LG10); - /* Q8 Averaged the total energy over both half-frames in log10 */ - *etot = extract_l(L_shr(Letot, 14-8)); - - return; -} - -/*------------------------------------------------------------------------* - * find_enr_dct) - * - * find input signal energy for each critical band and first 74 LF bins - * The energy is normalized by the number of frequency bins in a channel - *------------------------------------------------------------------------*/ - -static void find_enr_dct_fx( - const Word16 data[], /* i : dct result, for the format Qdct*/ - Word32 band[], /* o : per band energy 2*Qdct+10*/ - Word32 *ptE, /* o : per bin energy for low frequencies 2*Qdct+10*/ - Word32 *Etot, /* o : total energy 2*Qdct+10*/ - const Word16 min_band, /* i : minimum critical band Q0 */ - const Word16 max_band, /* i : maximum critical band Q0 */ - const Word16 Q_dct, /* i : scaling factor Q0 */ - const Word16 bin_freq /* i : Number of frequency bins Q0 */ -) -{ - Word16 i; - Word16 freq; - const Word16 *ptR; - Word32 LE_min, Ltmp, Ltmp1; - - LE_min = L_max(L_shl(E_MIN_Q15, sub(shl(Q_dct,1)+10,22)),1); - - ptR = &data[0]; /* pointer to first real coefficient */ - freq = 0; - move16(); - FOR( i=0; i < max_band; i++ ) - { - band[i] = 0; - move16(); - Ltmp1 = L_deposit_l(0); - FOR(; freq <= mfreq_loc_LD_fx[i]; freq += bin_freq) - { - /* energy */ - /**ptE = *ptR * *ptR; */ - Ltmp = L_mult(*ptR, *ptR); - - /* normalization */ - /**ptE *= 1.0f / (DCT_L_POST);*/ - Ltmp = Mult_32_16(Ltmp, 26214); /*26214 = 1.0/640 ->Q15+9 --> 2*Q_dct + 9*/ - Ltmp = L_max(Ltmp, LE_min); - *ptE = Ltmp; - move32(); - - /*band[i] += *ptE++;*/ - Ltmp1 = L_add(Ltmp, Ltmp1); - - ptE++; - ptR++; - } - - /* normalization per frequency bin */ - /*band[i] /= cnt;*/ - band[i] = L_max(Mult_32_16(Ltmp1, inv_mfreq_bindiv_LD_fx[i]), LE_min); - move32(); /* 2*Q_dct + 9*/ - - } - - /*-----------------------------------------------------------------* - * Find the total energy over the input bandwidth - *-----------------------------------------------------------------*/ - - Ltmp = 0; - move16(); - FOR( i = min_band; i <= NB_LIMIT_BAND; i++ ) - { - /* total channel energy */ - Ltmp = L_add(band[i],Ltmp); - } - - *Etot = Ltmp; - move32(); - - return; -} - -/*------------------------------------------------------------------------* - * Prep_music_postP() - * - * Performs the steps needed to do the music post processing - *------------------------------------------------------------------------*/ - -void Prep_music_postP_fx( - Word16 exc_buffer_in[], /* i/o: excitation buffer Q_exc*/ - Word16 dct_buffer_out[], /* o : DCT output buffer (qdct)*/ - Word16 filt_lfE[], /* i/o: long term spectrum energy Q15?*/ - const Word16 last_core, /* i : last core */ - const Word16 *pitch_buf, /* i : current frame pitch information Q6*/ - Word16 *LDm_enh_lp_gbin, /* o : smoothed suppression gain, per dct bin Q14*/ - const Word16 Q_exc, /* i : excitation scaling */ - Word16 *qdct /* o : Scaling factor of dct coefficient */ -) -{ - Word16 i; - Word16 *pt1; - const Word16 *pt2; - Word16 s_pit, fr_pit; - - Word16 exc16[DCT_L_POST]; - Word16 *pt1_out; - - s_pit = shr(pitch_buf[3],6); - fr_pit = shr(sub(pitch_buf[3], shl(s_pit,6)),4); /* Find fractional part */ - - /*------------------------------------------------------------* - * Resetting some memories in case of switching - *------------------------------------------------------------*/ - - IF( sub(last_core,HQ_CORE) == 0 ) - { - set16_fx( filt_lfE, 4096, DCT_L_POST ); - set16_fx( LDm_enh_lp_gbin, 16384, VOIC_BINS_HR ); - pt1 = exc_buffer_in + OFFSET2 - 1; - pt2 = pt1 + shr_r(pitch_buf[0],6); - FOR( i = 0; i < OFFSET2; i++ ) - { - *pt1 = *pt2; - move16(); - pt1--; - pt2--; - } - } - - /*------------------------------------------------------------* - * Extrapolation of the last future part and windowing - *------------------------------------------------------------*/ - pt1 = exc_buffer_in + DCT_L_POST - OFFSET2; - pred_lt4(pt1, pt1, s_pit, fr_pit, OFFSET2, pitch_inter4_2, L_INTERPOL2, PIT_UP_SAMP); - /*------------------------------------------------------------* - * windowing right side - *------------------------------------------------------------*/ - pt2 = post_dct_wind_fx; - pt1_out = exc16 + DCT_L_POST - OFFSET2; - FOR( i = 0; i < OFFSET2; i++ ) - { - *pt1_out = mult_r(*pt1,*pt2); - move16(); - pt1++; - pt2++; - pt1_out++; - } - /*------------------------------------------------------------* - * windowing left side - *------------------------------------------------------------*/ - pt1 = exc_buffer_in; - pt1_out = exc16; - pt2--; - FOR( i = 0; i < OFFSET2; i++ ) - { - *pt1_out = mult_r(*pt1,*pt2); - move16(); - pt1++; - pt1_out++; - pt2--; - } - /*------------------------------------------------------------* - * Copy remaining data (Flat part) - *------------------------------------------------------------*/ - - FOR(; i < L_FRAME+OFFSET2; i++ ) - { - *pt1_out = *pt1; - move16(); - pt1++; - pt1_out++; - } - /*------------------------------------------------------------* - * EDCT and back to 16 bits - *------------------------------------------------------------*/ - - edct_16fx(exc16, dct_buffer_out, DCT_L_POST, 6); - *qdct = Q_exc; - move16(); - - return; -} -/*------------------------------------------------------------------------* - * norm_lfe() - * - * Energy bins normalisation - *------------------------------------------------------------------------*/ -static Word16 norm_lfe( - const Word32 Lfe, /* i: energy bin to normalize 2*Qdct+10 */ - const Word16 m_norm, /* i: Normalisation factor Q e_norm */ - const Word16 e_norm /* i: Exponent of the normalisation factor */ -) -{ - Word32 Ltmp; - Word16 exp2, tmp16, exp3 ; - - Ltmp = Mult_32_16(Lfe, m_norm); - Ltmp = L_add(Ltmp, L_shl(BET_Q15_FX, sub(e_norm,15))); /* Ltmp -> e_norm*/ - exp2 = norm_l(Ltmp); - tmp16 = extract_h(L_shl(Ltmp,exp2)); /* exp2 -= 16 */ - exp2 = add(e_norm,exp2); - - tmp16 = mult_r(tmp16,tmp16); /* tmp16 in Q exp2 */ - tmp16 = mult_r(tmp16,tmp16); - tmp16 = mult_r(tmp16,tmp16); - - exp3 = sub(12+16, exp2); /* tmp16 in Q exp2 */ - if(sub(exp2,31) !=0) - { - exp3 = sub(exp2, 12+16-3); /* if exp2 < 31, means that tmp >= 1.0 */ - /* Need to shl by 3 to take into account the 3 multiplications */ - } - tmp16 = shl(tmp16, exp3); /* Result in Q12 */ - - return tmp16; -} - -/*------------------------------------------------------------------------* - * Post_music_postP() - * - * Going back from frequency to time domain from the enhanced spectrum. - * Retreive the aligned excitation and redo the synthesis - *------------------------------------------------------------------------*/ - -void Post_music_postP_fx( - Word16 dct_buffer_in[], /* i/o: excitation buffer */ - Word16 *exc2, /* i/o: Current excitation to be overwriten */ - const Word16 *mem_tmp, /* i : previous frame synthesis memory */ - Word16 *st_mem_syn2, /* i/o: current frame synthesis memory */ - const Word16 *Aq, /* i : LPC filter coefficients */ - Word16 *syn, /* i/o: 12k8 synthesis */ - Word16 *Q_exc, /* i : excitation scaling */ - Word16 *prev_Q_syn, /* i : previsous frame synthesis scaling */ - Word16 *Q_syn, /* i : Current frame synthesis scaling */ - Word16 *mem_syn_clas_estim_fx, /* i : old 12k8 synthesis used for frame classification*/ - const Word16 IsIO, /* i: Flag to indicate IO mode */ - Word16 *mem_deemph, /* i/o: speech deemph filter memory */ - Word16 *st_pst_old_syn_fx, /* i/o: psfiler */ - Word16 *st_pst_mem_deemp_err_fx, /* i/o: psfiler */ - Word16 *mem_agc, - PFSTAT *pf_stat, /* i/o: All memories related to NB post filter */ - const Word16 *tmp_buffer /* tmp_buffer in Q-1 */ - ,Word16 *mem_tmp2 /* Temporary memory used with scale_syn */ -) -{ - Word16 exc16[DCT_L_POST]; - - /*------------------------------------------------------------------------* - * Go back to time domain - *------------------------------------------------------------------------*/ - - edct_16fx( dct_buffer_in, exc16, DCT_L_POST, 6); - - Copy( exc16 + OFFSET2, exc2, L_FRAME); - - Copy( mem_tmp, st_mem_syn2, M ); - - /*------------------------------------------------------------------------* - * Perform the synthesis filtering using the enhanced excitation - *------------------------------------------------------------------------*/ - IF(IsIO == 0) /* Rescaling already done in IO mode */ - { - Rescale_mem(*Q_exc, prev_Q_syn, Q_syn, st_mem_syn2,mem_syn_clas_estim_fx, 4, - mem_deemph, st_pst_old_syn_fx, st_pst_mem_deemp_err_fx, mem_agc, - pf_stat, 1, 0, tmp_buffer); - Copy( st_mem_syn2, mem_tmp2, M ); - } - - syn_12k8_fx( L_FRAME, Aq, exc2, syn, st_mem_syn2, 1 , *Q_exc, *Q_syn); - - return; -} - - diff --git a/src/libs/libevs/lib_dec/TonalComponentDetection.cpp b/src/libs/libevs/lib_dec/TonalComponentDetection.cpp old mode 100755 new mode 100644 index bce09754..57341957 --- a/src/libs/libevs/lib_dec/TonalComponentDetection.cpp +++ b/src/libs/libevs/lib_dec/TonalComponentDetection.cpp @@ -1,45 +1,33 @@ /*==================================================================================== - EVS Codec 3GPP TS26.442 Apr 03, 2018. Version 12.11.0 / 13.6.0 / 14.2.0 + EVS Codec 3GPP TS26.443 Nov 13, 2018. Version 12.11.0 / 13.7.0 / 14.3.0 / 15.1.0 ====================================================================================*/ #define _USE_MATH_DEFINES #include -#include "stl.h" - +#include +#include #include "options.h" -#include "prot_fx.h" -#include "cnst_fx.h" -#include "rom_basop_util.h" -#include "basop_util.h" +#include "prot.h" +#include "cnst.h" +#include "stat_com.h" + /***********************************************************************************/ /* forward declaration for local functions, see implementation at end of this file */ /***********************************************************************************/ -static void calcPseudoSpec(Word32 * mdctSpec, Word16 mdctSpec_exp, Word16 nSamples, Word16 floorPowerSpectrum, Word32 * powerSpec, Word16 * powerSpec_exp); -static void getEnvelope(Word16 nSamples, Word32 const * powerSpec, Word16 F0, Word32 * envelope, Word32 * smoothedSpectrum); -static void GetF0(Word16 const nSamples, - Word16 const nSamplesCore, - Word32 const * const powerSpectrum, Word32 const pitchLag, Word16 * const pOrigF0, Word16 * const pF0); -static void findStrongestHarmonics(Word16 nSamples, Word32 const * powerSpectrum, Word16 F0, Word16 nTotalHarmonics, Word16 * pHarmonicIndexes, Word16 * pnHarmonics); -static void CorrectF0(Word16 const * pHarmonicIndexes, Word16 const nHarmonics, Word16 * pF0); -static void findCandidates(Word16 nSamples, - Word32 * MDCTSpectrum, /* i: MDCT spectrum */ - Word16 MDCTSpectrum_exp, Word16 * thresholdModificationNew - ,Word16 floorPowerSpectrum /* i: lower limit for power spectrum bins */ - ); -static void modifyThreshold(Word16 i, Word16 F0, Word16 threshold, Word16 * thresholdModification); -static void modifyThresholds(Word16 F0, Word16 origF0, Word16 * thresholdModification); -static void RefineThresholdsUsingPitch(Word16 nSamples, - Word16 nSamplesCore, - Word32 const powerSpectrum[], - Word32 lastPitchLag, - Word32 currentPitchLag, - Word16 * pF0, - Word16 * thresholdModification); -static void findTonalComponents(Word16 * indexOfTonalPeak, Word16 * lowerIndex, Word16 * upperIndex, Word16 *numIndexes, Word16 nSamples, const Word32 * powerSpectrum, Word16 F0, Word16 * thresholdModification); +static void calcPseudoSpec(float const * mdctSpec, unsigned int nSamples, float floorPowerSpectrum, float * powerSpec); +static void getEnvelope(unsigned int nSamples, float const * powerSpec, float F0, float * envelope, float * smoothedSpectrum); +static void GetF0(unsigned int const nSamples, unsigned int const nSamplesCore, float const * const powerSpectrum, float const pitchLag, float * const pOrigF0, float * const pF0); +static void findStrongestHarmonics(unsigned int nSamples, float const * powerSpectrum, float F0, unsigned int nTotalHarmonics, unsigned int * pHarmonicIndexes, unsigned int * pnHarmonics); +static void CorrectF0(unsigned int const * pHarmonicIndexes, unsigned int nHarmonics, float * pF0); +static void findCandidates(unsigned int nSamples, const float * MDCTSpectrum, float * thresholdModificationNew, float floorPowerSpectrum /* i: lower limit for power spectrum bins */ ); +static void modifyThreshold(int i, float F0, float threshold, float * thresholdModification); +static void modifyThresholds(float F0, float origF0, float * thresholdModification); +static void RefineThresholdsUsingPitch(unsigned int nSamples, unsigned int nSamplesCore, float const * powerSpectrum, float lastPitchLag, float currentPitchLag, float * pF0, float * thresholdModification); +static void findTonalComponents(unsigned short int * indexOfTonalPeak, unsigned short int * lowerIndex, unsigned short int * upperIndex, unsigned int *numIndexes, unsigned int nSamples, const float * powerSpectrum, float F0, float const * thresholdModification); /*******************************************************/ /*-------------- public functions -------------------- */ @@ -49,41 +37,37 @@ static void findTonalComponents(Word16 * indexOfTonalPeak, Word16 * lowerIndex, * secondLastPowerSpectrum for the precise location of the peaks and * store them in indexOfTonalPeak. Updates lowerIndex, upperIndex, * pNumIndexes accordingly. */ -void DetectTonalComponents(Word16 indexOfTonalPeak[], - Word16 lowerIndex[], - Word16 upperIndex[], - Word16 * pNumIndexes, - Word32 lastPitchLag, Word32 currentPitchLag, - Word16 const lastMDCTSpectrum[], - Word16 lastMDCTSpectrum_exp, - Word16 const scaleFactors[], - Word16 const scaleFactors_exp[], - Word16 const scaleFactors_max_e, - Word32 const secondLastPowerSpectrum[], - Word16 nSamples - ,Word16 nSamplesCore - ,Word16 floorPowerSpectrum /* i: lower limit for power spectrum bins */ - ) +void DetectTonalComponents(unsigned short int indexOfTonalPeak[], + unsigned short int lowerIndex[], + unsigned short int upperIndex[], + unsigned int * pNumIndexes, + float lastPitchLag, float currentPitchLag, + float const lastMDCTSpectrum[], + float const scaleFactors[], + float const secondLastPowerSpectrum[], + unsigned int nSamples + ,unsigned int nSamplesCore + ,float floorPowerSpectrum /* i: lower limit for power spectrum bins */ + ) { - Word16 F0; - Word16 thresholdModification[L_FRAME_MAX]; - Word32 pScaledMdctSpectrum[L_FRAME_MAX]; + float F0; + float thresholdModification[L_FRAME_MAX]; + float * const pScaledMdctSpectrum = thresholdModification; - mdct_shaping_16(lastMDCTSpectrum, nSamplesCore, nSamples, - scaleFactors, scaleFactors_exp, - scaleFactors_max_e, pScaledMdctSpectrum); - lastMDCTSpectrum_exp = add(lastMDCTSpectrum_exp, scaleFactors_max_e); + + /* Convert from 16 bit to 32 bit */ + mvr2r(lastMDCTSpectrum, pScaledMdctSpectrum, nSamples); + mdct_noiseShaping(pScaledMdctSpectrum, nSamplesCore, scaleFactors); + v_multc(pScaledMdctSpectrum + nSamplesCore, scaleFactors[FDNS_NPTS-1], pScaledMdctSpectrum + nSamplesCore, nSamples - nSamplesCore ); /* Find peak candidates in the last frame. */ - findCandidates(nSamples, pScaledMdctSpectrum, lastMDCTSpectrum_exp, thresholdModification - , floorPowerSpectrum - ); + findCandidates(nSamples, pScaledMdctSpectrum, thresholdModification, floorPowerSpectrum ); /* Refine peak candidates using the pitch information */ RefineThresholdsUsingPitch(nSamples, nSamplesCore, secondLastPowerSpectrum, lastPitchLag, currentPitchLag, &F0, thresholdModification); - /* Find peaks in the second last frame */ findTonalComponents(indexOfTonalPeak, lowerIndex, upperIndex, pNumIndexes, nSamples, secondLastPowerSpectrum, F0, thresholdModification); + } /* When called, the tonal components are already stored in @@ -92,30 +76,26 @@ void DetectTonalComponents(Word16 indexOfTonalPeak[], * then keep in indexOfTonalPeak only the tonal components that are * again detected Updates indexOfTonalPeak, lowerIndex, upperIndex, * phaseDiff, phases, pNumIndexes accordingly. */ -void RefineTonalComponents(Word16 indexOfTonalPeak[], - Word16 lowerIndex[], - Word16 upperIndex[], - Word16 phaseDiff[], - Word16 phases[], Word16 * pNumIndexes, - Word32 lastPitchLag, Word32 currentPitchLag, - Word16 const lastMDCTSpectrum[], - Word16 const lastMDCTSpectrum_exp, - Word16 const scaleFactors[], - Word16 const scaleFactors_exp[], - Word16 const scaleFactors_max_e, - Word32 const secondLastPowerSpectrum[], - Word16 nSamples - ,Word16 nSamplesCore - ,Word16 floorPowerSpectrum /* i: lower limit for power spectrum bins */ +void RefineTonalComponents(unsigned short int indexOfTonalPeak[], + unsigned short int lowerIndex[], + unsigned short int upperIndex[], + float phaseDiff[], + float phases[], unsigned int * pNumIndexes, + float lastPitchLag, float currentPitchLag, + float const lastMDCTSpectrum[], + float const scaleFactors[], + float const secondLastPowerSpectrum[], + unsigned int nSamples + ,unsigned int nSamplesCore + ,float floorPowerSpectrum /* i: lower limit for power spectrum bins */ ) { - Word16 newIndexOfTonalPeak[MAX_NUMBER_OF_IDX]; - Word16 newLowerIndex[MAX_NUMBER_OF_IDX]; - Word16 newUpperIndex[MAX_NUMBER_OF_IDX]; - Word16 newNumIndexes, nPreservedPeaks; - Word16 iNew, iOld, j; - Word16 * pOldPhase, * pNewPhase; - + unsigned short int newIndexOfTonalPeak[MAX_NUMBER_OF_IDX]; + unsigned short int newLowerIndex[MAX_NUMBER_OF_IDX]; + unsigned short int newUpperIndex[MAX_NUMBER_OF_IDX]; + unsigned int newNumIndexes, nPreservedPeaks; + unsigned int iNew, iOld, j; + float * pOldPhase, * pNewPhase; DetectTonalComponents(newIndexOfTonalPeak, newLowerIndex, @@ -124,890 +104,673 @@ void RefineTonalComponents(Word16 indexOfTonalPeak[], lastPitchLag, currentPitchLag, lastMDCTSpectrum, - lastMDCTSpectrum_exp, scaleFactors, - scaleFactors_exp, - scaleFactors_max_e, secondLastPowerSpectrum, nSamples, nSamplesCore, - floorPowerSpectrum); + floorPowerSpectrum ); nPreservedPeaks = 0; - move16(); iNew = 0; - move16(); pOldPhase = phases; pNewPhase = phases; - - FOR (iOld = 0; iOld < *pNumIndexes; iOld++) + for (iOld = 0; iOld < *pNumIndexes; iOld++) { /* We don't want that the old peak index is at the border of the new peak region, that is why >= newUpperIndex and > newLowerIndex */ - test(); - WHILE (sub(iNew,newNumIndexes) < 0 && sub(indexOfTonalPeak[iOld],newUpperIndex[iNew]) >= 0) + while ((iNew < newNumIndexes) && (indexOfTonalPeak[iOld] >= newUpperIndex[iNew])) { - iNew = add(iNew,1); + ++iNew; } - - test(); - IF (sub(iNew,newNumIndexes) < 0 && sub(indexOfTonalPeak[iOld],newLowerIndex[iNew]) > 0) + if ((iNew < newNumIndexes) && (indexOfTonalPeak[iOld] > newLowerIndex[iNew])) { newIndexOfTonalPeak[nPreservedPeaks] = indexOfTonalPeak[iOld]; - move16(); newLowerIndex[nPreservedPeaks] = lowerIndex[iOld]; - move16(); newUpperIndex[nPreservedPeaks] = upperIndex[iOld]; - move16(); phaseDiff[nPreservedPeaks] = phaseDiff[iOld]; - move16(); - - FOR (j = lowerIndex[iOld]; j <= upperIndex[iOld]; j++) + for (j = lowerIndex[iOld]; j <= upperIndex[iOld]; j++) { *pNewPhase++ = *pOldPhase++; - move16(); } - nPreservedPeaks = add(nPreservedPeaks,1); + ++nPreservedPeaks; } - ELSE + else { - pOldPhase += sub(upperIndex[iOld],add(lowerIndex[iOld],1)); + pOldPhase += upperIndex[iOld]-lowerIndex[iOld]+1; } } - - FOR (iNew = 0; iNew < nPreservedPeaks; iNew++) + for (iNew = 0; iNew < nPreservedPeaks; iNew++) { indexOfTonalPeak[iNew] = newIndexOfTonalPeak[iNew]; - move16(); lowerIndex[iNew] = newLowerIndex[iNew]; - move16(); upperIndex[iNew] = newUpperIndex[iNew]; - move16(); } *pNumIndexes = nPreservedPeaks; - move16(); } /***************************************************** ---------------- private functions ------------------- ******************************************************/ -static void calcPseudoSpec(Word32 * mdctSpec, /* i: MDCT spectrum */ - Word16 mdctSpec_exp, /* i: exponent of MDCT spectrum */ - Word16 nSamples, /* i: frame size */ - Word16 floorPowerSpectrum, /* i: lower limit for power spectrum bins */ - Word32 * powerSpec, /* o: estimated power spectrum */ - Word16 * powerSpec_exp) /* o: exponent of estimated power spectrum */ + +static void calcPseudoSpec(float const * mdctSpec, + unsigned int nSamples, + float floorPowerSpectrum, + float * powerSpec) { - Word16 k; - Word32 x, L_tmp, L_tmp_floor; - Word16 tmp_loop; + unsigned int k; + float x; - - - *powerSpec_exp = add(add(mdctSpec_exp, mdctSpec_exp), 5); - move16(); - - k = sub(31, *powerSpec_exp); - /* If the signal is bellow floor, special care is needed for *powerSpec_exp */ - IF (sub(add(16-3, norm_s(floorPowerSpectrum)), k) < 0) /*extra 3 bits of headroom for MA filter in getEnvelope*/ + for (k = 1; k <= nSamples-2; k++) { - k = add(16-3, norm_s(floorPowerSpectrum)); /*extra 3 bits of headroom for MA filter in getEnvelope*/ - L_tmp_floor = L_shl(L_deposit_l(floorPowerSpectrum), k); - set32_fx(powerSpec, L_tmp_floor, nSamples); - *powerSpec_exp = sub(31, k); + x = (mdctSpec[k+1] - mdctSpec[k-1]); /* An MDST estimate */ + x = mdctSpec[k] * mdctSpec[k] + x * x; + powerSpec[k] = max(floorPowerSpectrum, x); } - ELSE - { - L_tmp_floor = L_shl(L_deposit_l(floorPowerSpectrum), k); - - tmp_loop = sub(nSamples, 2); - FOR (k = 1; k <= tmp_loop; k++) - { - x = L_sub(L_shr(mdctSpec[k+1], 1),L_shr(mdctSpec[k-1], 1)); /* An MDST estimate */ - - x = L_shr(Mpy_32_32(x, x), 3); - - L_tmp = Mpy_32_32(mdctSpec[k], mdctSpec[k]); - L_tmp = L_shr(L_tmp, 5); - - powerSpec[k] = L_max(L_tmp_floor, L_add(L_tmp, x)); - move32(); - } - } - - powerSpec[0] = L_shr(powerSpec[1], 1); - move32(); - powerSpec[nSamples-1] = L_shr(powerSpec[nSamples-2], 1); - move32(); + powerSpec[0] = 0.5f*powerSpec[1]; + powerSpec[nSamples-1] = 0.5f*powerSpec[nSamples-2]; } -#define LEVEL_EXP 3/*+4*/ -static void getEnvelope(Word16 nSamples, /*i: Q0 */ - Word32 const * powerSpec, /*i: powerSpec_exp */ - Word16 F0, /*i: 5Q10*/ - Word32 * envelope, /*o: powerSpec_exp + LEVEL_EXP*/ - Word32 * smoothedSpectrum /*o: powerSpec_exp + LEVEL_EXP*/ - ) +static void getEnvelope(unsigned int nSamples, + float const * powerSpec, + float F0, + float * envelope, + float * smoothedSpectrum) { - Word16 nFilterLength, nHalfFilterLength, nSecondHalfFilterLength, n1, n2; - Word16 level, inv_len; - Word16 i; - Word32 sum, tmp; + unsigned int nFilterLength, nHalfFilterLength, nSecondHalfFilterLength, n1, n2; + unsigned int i; + double sum; /* double is required to avoid precision problems in the optimized version. */ - IF (F0 == 0) + + if (F0 == 0) { nFilterLength = 15; - move16(); } - ELSE IF (F0 <= 10240/*10.0f Q10*/) + else if (F0 <= 10.0f) { nFilterLength = 11; - move16(); } - ELSE IF (F0 >= 22528/*22.0f Q10*/) + else if (F0 >= 22.0f) { /* For F0 >= 22 peak is isolated well enough with the filter length of 23. This case is however not triggered due to the limit of pit_min, but the line is left for security reasons. */ nFilterLength = 23; - move16(); } - ELSE + else { - nFilterLength = s_or(1, shr(F0,10)); /*1+2*(int)(F0/2); F0->Q10*/ move16(); + nFilterLength = 1+2*(int)(F0/2); } - - nHalfFilterLength = shr(nFilterLength,1); - - n1 = add(nHalfFilterLength,1); - - nSecondHalfFilterLength = sub(nFilterLength,nHalfFilterLength); - - n2 = sub(nSecondHalfFilterLength,1); + nHalfFilterLength = nFilterLength/2; + n1 = nHalfFilterLength+1; + nSecondHalfFilterLength = nFilterLength-nHalfFilterLength; + n2 = nSecondHalfFilterLength-1; assert((nFilterLength >= 7) && (nFilterLength <= 23) && (nFilterLength %2 == 1)); - - sum = L_deposit_l(0); - level = 31089/*LEVEL_ABOVE_ENVELOPE Q12*/; /*Q12*/ - - FOR (i = 0; i < n2; i++) + sum = 0; + for (i = 0; i < n2; i++) { - sum = L_add(sum, powerSpec[i]); + sum += LEVEL_ABOVE_ENVELOPE*powerSpec[i]; } /* No need for PTR_INIT for powerSpec[i+n2] as we continue from the previous loop */ - FOR (i = 0; i < n1; i++) + for (i = 0; i < n1; i++) { - sum = L_add(sum, powerSpec[i+n2]); - tmp = Mpy_32_16_1(sum/*Q31,powerSpec_exp*/,level/*Q12*/); /*Q28,powerSpec_exp*/ - envelope[i]/*Q28,powerSpec_exp*/ = Mpy_32_16_1(tmp/*Q28,powerSpec_exp*/, InvIntTable[i+nSecondHalfFilterLength]/*Q15*/); - move32(); + sum += LEVEL_ABOVE_ENVELOPE*powerSpec[i+n2]; + /* 1/(i+nSecondHalfFilterLength) needs to be stored in a table for each filter length */ + envelope[i] = (float)sum / (i+nSecondHalfFilterLength); } - - inv_len = mult_r(level, InvIntTable[nFilterLength]); - FOR (i = n1; i < nSamples-n2; i++) + sum /= nFilterLength; /* 1/nFilterLength is from a table */ + /* No need for PTR_INIT for powerSpec[i+n2] as we continue from the previous loop */ + for (i = n1; i < nSamples-n2; i++) { - sum = L_add(sum, L_sub(powerSpec[i+n2],powerSpec[i-n1])); - envelope[i] = Mpy_32_16_1(sum, inv_len); - move32(); + sum += LEVEL_ABOVE_ENVELOPE*(powerSpec[i+n2]-powerSpec[i-n1])/nFilterLength; /* LEVEL_ABOVE_ENVELOPE/nFilterLength is from a table */ + envelope[i] = (float)sum; } - - FOR (i = nSamples-n2; i < nSamples; i++) + sum *= nFilterLength; + /* No need for PTR_INIT for powerSpec[i-n1] as we continue from the previous loop */ + for (i = nSamples-n2; i < nSamples; i++) { - sum = L_sub(sum, powerSpec[i-n1]); - tmp = Mpy_32_16_1(sum,level); - envelope[i] = Mpy_32_16_1(tmp, InvIntTable[nSamples-(i-nHalfFilterLength)]); - move32(); + sum -= LEVEL_ABOVE_ENVELOPE*powerSpec[i-n1];; + /* 1/(nSamples-(i-nHalfFilterLength)) needs to be stored in a table for each filter length */ + envelope[i] = (float)sum / (nSamples-(i-nHalfFilterLength)); } - - FOR (i = 1; i < nSamples-1; i++) + for (i = 1; i < nSamples-1; i++) { - smoothedSpectrum[i] = L_add(L_add(Mpy_32_16_1(powerSpec[i-1],3072/*0.75f Q12*/),L_shr(powerSpec[i],LEVEL_EXP)), Mpy_32_16_1(powerSpec[i+1],3072/*0.75f Q12*/)); + smoothedSpectrum[i] = 0.75f*powerSpec[i-1]+powerSpec[i]+0.75f*powerSpec[i+1]; } - - move32(); - move32(); - smoothedSpectrum[0] = L_add(Mpy_32_16_1(powerSpec[1],3072/*0.75f Q12*/),L_shr(powerSpec[0],LEVEL_EXP)); - smoothedSpectrum[nSamples-1] = L_add(Mpy_32_16_1(powerSpec[nSamples-2],3072/*0.75f Q12*/),L_shr(powerSpec[nSamples-1],LEVEL_EXP)); + smoothedSpectrum[0] = powerSpec[0]+0.75f*powerSpec[1]; + smoothedSpectrum[nSamples-1] = 0.75f*powerSpec[nSamples-2]+powerSpec[nSamples-1]; } -static void GetF0(Word16 /*int*/ const nSamples, /*i - Q0 */ - Word16 /*int*/ const nSamplesCore, /*i - Q0 */ - Word32 /*float*/ const * const powerSpectrum, /*i - Qx */ /*is justed handed over and given back*/ - Word32 /*float*/ const pitchLag, /*i - Q16*/ - Word16 /*float*/ * const pOrigF0, /*o - Q10*/ - Word16 /*float*/ * const pF0) /*o - Q10*/ +static void GetF0(unsigned int const nSamples, /*i*/ + unsigned int const nSamplesCore, /*i*/ + float const * const powerSpectrum, /*i*/ + float const pitchLag, /*i*/ + float * const pOrigF0, /*i/o*/ + float * const pF0) /*i/o*/ { - Word16 /*float*/ tmpPitchLag; - Word16 /*int*/ rgiStrongHarmonics[MAX_PEAKS_FROM_PITCH]; - Word16 /*int*/ nTotalHarmonics, nStrongHarmonics; - Word16 tmp; + float halfPitchLag; + unsigned int rgiStrongHarmonics[MAX_PEAKS_FROM_PITCH]; + unsigned int nTotalHarmonics, nStrongHarmonics; assert(LAST_HARMONIC_POS_TO_CHECK <= nSamplesCore); /* Use only F0 >= 100 Hz */ - test(); - IF ((pitchLag > 0) && (sub(round_fx(pitchLag) , shr(nSamplesCore,1)) <= 0)) + if ((pitchLag > 0) && (pitchLag <= 0.5f*nSamplesCore)) { - - tmpPitchLag /*"halfPitchLag" in FLC - read as Q5 for comparison to halfpitchlag */ - = round_fx(L_shl(pitchLag,4)); /*no division by 2, will be done in following division - - furthermore, do a leftshift before rounding, to preserve more accuracy - - will be accommodated also in following division*/ - - /**pF0 = nSamplesCore/tmpPitchLag;*/ - BASOP_Util_Divide_MantExp(nSamplesCore,0,tmpPitchLag,-(1/*division by 2*/+4/*accommodate accuracy-prevention-leftshift*/),pF0,&tmp); /*pF0 is Q15*/ - move16(); - *pF0 = shr(*pF0,sub(5,tmp)); /*Q10 without scalingfactor*/ - move16(); - *pOrigF0 = *pF0; /*Q10*/ - move16(); - tmp = 2*LAST_HARMONIC_POS_TO_CHECK; - if (sub(nSamples , 2*LAST_HARMONIC_POS_TO_CHECK) < 0 ) + halfPitchLag = 0.5f*pitchLag; + *pF0 = nSamplesCore/halfPitchLag; + *pOrigF0 = *pF0; + if (nSamples < 2*LAST_HARMONIC_POS_TO_CHECK) { - move16(); - tmp = nSamples; + nTotalHarmonics = (unsigned int)(nSamples/(*pF0)); + } + else + { + nTotalHarmonics = (int)(2*LAST_HARMONIC_POS_TO_CHECK/(*pF0)); /* For correcting F0 we go 2 times the last harmonic position that will be used */ } - BASOP_Util_Divide_MantExp(tmp,15,*pF0,5,&nTotalHarmonics,&tmp); - nTotalHarmonics =shl(nTotalHarmonics,sub(tmp,15)); - /* Get in rgiStrongHarmonics all i for which i*F0 are the strongest harmonics */ findStrongestHarmonics(nSamples, powerSpectrum, *pF0, nTotalHarmonics, rgiStrongHarmonics, &nStrongHarmonics); - CorrectF0(rgiStrongHarmonics, nStrongHarmonics, pF0); } - ELSE + else { - move16(); - move16(); *pF0 = 0; *pOrigF0 = 0; } } - -static void findStrongestHarmonics(Word16 nSamples, - Word32 const * powerSpectrum, - Word16 F0/*5Q10*/, - Word16 nTotalHarmonics, - Word16 * pHarmonicIndexes, - Word16 * pnHarmonics) +/* This is very fast with almost ordered vectors. */ +static void sort(unsigned int *in, unsigned int n) { - Word32 peaks[MAX_PEAKS_FROM_PITCH], smallestPeak; - Word16 nPeaksToCheck, nPeaks, iSmallestPeak; - Word16 i, l, k; - (void)nSamples; + int i; + unsigned int j, tempr; - - nPeaks = 0; - move16(); - - iSmallestPeak = 0; - move16(); - smallestPeak = 0x7fffffff; - move32(); - - nPeaksToCheck = s_min(nTotalHarmonics, MAX_PEAKS_FROM_PITCH+1); - - FOR (i = 1; i < nPeaksToCheck; i++) + for (i = n-2; i >= 0; i--) { - Word32 newPeak; - - k = extract_h(L_shl(L_mult(i,F0),5)); /*k = (int)(i*F0);*/ - assert(k > 0 && k < 2*LAST_HARMONIC_POS_TO_CHECK && k < nSamples); - - newPeak = L_add(powerSpectrum[k], 0); - - peaks[nPeaks] = newPeak; - move32(); - pHarmonicIndexes[nPeaks] = i; - move16(); - - IF (L_sub(newPeak,smallestPeak) <= 0) + tempr = in[i]; + for (j = i+1; (j < n) && (tempr > in[j]); j++ ) { - iSmallestPeak = nPeaks; - move16(); - smallestPeak = L_add(newPeak, 0); + in[j-1] = in[j]; + /* (tempr > r[j]) */ } - - nPeaks = add(nPeaks,1); + in[j-1] = tempr; } - FOR (; i < nTotalHarmonics; i++) +} + +static void findStrongestHarmonics(unsigned int nSamples, float const * powerSpectrum, float F0, unsigned int nTotalHarmonics, unsigned int * pHarmonicIndexes, unsigned int * pnHarmonics) +{ + float peaks[MAX_PEAKS_FROM_PITCH], smallestPeak; + unsigned int nPeaksToCheck, nPeaks, iSmallestPeak; + unsigned int i, l, k; + (void)nSamples; + + nPeaks = 0; + iSmallestPeak = 0; + smallestPeak = FLT_MAX; + nPeaksToCheck = min(nTotalHarmonics, MAX_PEAKS_FROM_PITCH+1); + for (i = 1; i < nPeaksToCheck; i++) { - Word32 newPeak; - - k = extract_h(L_shl(L_mult(i,F0),5)); + float newPeak; + k = (int)(i*F0); assert(k > 0 && k < 2*LAST_HARMONIC_POS_TO_CHECK && k < nSamples); - - newPeak = L_add(powerSpectrum[k], 0); - - IF (L_sub(newPeak,smallestPeak) > 0) + newPeak = powerSpectrum[k]; + peaks[nPeaks] = newPeak; + pHarmonicIndexes[nPeaks] = i; + if (newPeak <= smallestPeak) + { + iSmallestPeak = nPeaks; + smallestPeak = newPeak; + } + ++nPeaks; + } + for (; i < nTotalHarmonics; i++) + { + float newPeak; + k = (int)(i*F0); + assert(k > 0 && k < 2*LAST_HARMONIC_POS_TO_CHECK && k < nSamples); + newPeak = powerSpectrum[k]; + if (newPeak > smallestPeak) { peaks[iSmallestPeak] = newPeak; - move32(); pHarmonicIndexes[iSmallestPeak] = i; - move16(); - smallestPeak = L_add(newPeak, 0); - - FOR (l = 0; l < MAX_PEAKS_FROM_PITCH; l++) + smallestPeak = newPeak; + for (l = 0; l < MAX_PEAKS_FROM_PITCH; l++) { - IF (peaks[l] <= smallestPeak) + if (peaks[l] <= smallestPeak) { iSmallestPeak = l; - move16(); - smallestPeak = L_add(peaks[l], 0); + smallestPeak = peaks[l]; } } } } - - sort_fx(pHarmonicIndexes, 0, sub(nPeaks,1)); - + sort(pHarmonicIndexes, nPeaks); *pnHarmonics = nPeaks; - move16(); } /* Use new F0, for which harmonics are most common in pHarmonicIndexes */ -static void CorrectF0(Word16 /*int*/ const * pHarmonicIndexes, /*I - Q0 */ - Word16 /*int*/ const nHarmonics, /*I - Q0 */ - Word16 /*float*/ * pF0) /*I/O - Q10 range: {0}, [4..18) */ +static void CorrectF0(unsigned int const * pHarmonicIndexes, + unsigned int nHarmonics, + float * pF0) { - Word16 /*int*/ i; - Word16 /*float*/ F0; - Word16 /*int*/ diff[MAX_PEAKS_FROM_PITCH-1], sortedDiff[MAX_PEAKS_FROM_PITCH-1]; - Word16 /*int*/ iMostCommonDiff, nMostCommonDiff, nSameDiff, iMult; - - Word16 tmp; - + unsigned int i; + float F0; + unsigned int diff[MAX_PEAKS_FROM_PITCH-1], sortedDiff[MAX_PEAKS_FROM_PITCH-1]; + unsigned int iMostCommonDiff, nMostCommonDiff, nSameDiff, iMult; F0 = *pF0; - - test(); - IF (F0 > 0 && nHarmonics != 0) + if (F0 > 0 && nHarmonics > 0) { - tmp = sub(nHarmonics, 1); - FOR (i = 0; i < tmp; i++) + for (i = 0; i < nHarmonics-1; i++) { - diff[i] = sub(pHarmonicIndexes[i+1], pHarmonicIndexes[i]); - move16(); + diff[i] = pHarmonicIndexes[i+1]-pHarmonicIndexes[i]; sortedDiff[i] = diff[i]; - move16(); } - sort_fx(sortedDiff, 0,sub(nHarmonics, 1+1)); + sort(sortedDiff, nHarmonics-1); iMostCommonDiff = sortedDiff[0]; - move16(); nSameDiff = 1; - move16(); i = 1; - move16(); - IF (sub(imult1616(sortedDiff[0],pHarmonicIndexes[0]),1) == 0) + if (sortedDiff[0]*pHarmonicIndexes[0] == 1) { /* Find how many distances between peaks have length 1 */ - FOR (; i < tmp; i++) + for (; i < nHarmonics-1; i++) { - if (sub(sortedDiff[i],1) == 0) + if (sortedDiff[i] == 1) { - nSameDiff=add(nSameDiff,1); + ++nSameDiff; } } } nMostCommonDiff = nSameDiff; - move16(); /* If there are at least 3 distances between peaks with length 1 and if the 1st harmonic is in pHarmonicIndexes then keep the original F0 */ /* Otherwise find the most common distance between peaks */ - IF (sub(nSameDiff,3) < 0) + if (nSameDiff < 3) { + /* Find the most common difference */ - FOR (i = nSameDiff; i < tmp; i++) + for (i = nSameDiff; i < nHarmonics-1; i++) { - IF (sub(sortedDiff[i], sortedDiff[i-1]) == 0 ) + if (sortedDiff[i] == sortedDiff[i-1]) { - nSameDiff=add(nSameDiff,1); + ++nSameDiff; } - ELSE + else { - IF (sub(nSameDiff, nMostCommonDiff) > 0) + if (nSameDiff > nMostCommonDiff) { nMostCommonDiff = nSameDiff; - move16(); iMostCommonDiff = sortedDiff[i-1]; - move16(); } - ELSE { - test(); - IF (sub(nSameDiff, nMostCommonDiff)==0 && (abs_s(sub(iMostCommonDiff,pHarmonicIndexes[0])) > abs_s(sub(sortedDiff[i-1],pHarmonicIndexes[0])))) + else + { + if ((nSameDiff == nMostCommonDiff) && (abs((int)iMostCommonDiff-(int)pHarmonicIndexes[0]) > abs((int)sortedDiff[i-1]-(int)pHarmonicIndexes[0]))) { nMostCommonDiff = nSameDiff; - move16(); iMostCommonDiff = sortedDiff[i-1]; - move16(); } } nSameDiff = 1; - move16(); } } - IF (sub(nSameDiff,nMostCommonDiff) > 0) + if (nSameDiff > nMostCommonDiff) { nMostCommonDiff = nSameDiff; - move16(); iMostCommonDiff = sortedDiff[nHarmonics-2]; - move16(); } } /* If there are enough peaks at the same distance */ - IF (sub(nMostCommonDiff, MAX_PEAKS_FROM_PITCH/2) >= 0) + if (nMostCommonDiff >= MAX_PEAKS_FROM_PITCH/2) { iMult = 1; - move16(); - FOR (i = 0; i < tmp; i++) + for (i = 0; i < nHarmonics-1; i++) { - IF (sub(diff[i], iMostCommonDiff) == 0) + if (diff[i] == iMostCommonDiff) { iMult = pHarmonicIndexes[i]; - move16(); - BREAK; + break; } /* for rare cases of octave mismatch or missing harmonics */ - test(); - test(); - IF (sub(sub(nHarmonics,2),i) > 0 && (sub(diff[i], diff[i+1]) == 0) && (sub(add(diff[i],diff[i+1]), iMostCommonDiff) == 0)) + if ((i < nHarmonics-2) && (diff[i] == diff[i+1]) && (diff[i]+diff[i+1] == iMostCommonDiff)) { iMult = pHarmonicIndexes[i]; - move16(); - BREAK; + break; } } /* If the real F0 is much higher than the original F0 from the pitch */ - - IF (sub(iMult, 3) <= 0) + if (iMult <= 3) { /* Use iMostCommonDiff, because the lowest pHarmonicIndexes[i] (which is equal to iMult) may not correspond to the new F0, but to it's multiple */ - F0 = round_fx(L_shl(L_mult(iMostCommonDiff /*Q0*/,F0 /*Q10*/),15)); + F0 = iMostCommonDiff*F0; } - ELSE + else { F0 = 0; } } /* Otherwise if there are at least 3 distances between peaks with length 1 and if the 1st harmonic is in pHarmonicIndexes then keep the original F0 */ /* Otherwise don't use F0 */ - ELSE + else if ((iMostCommonDiff > 1) || (nMostCommonDiff < 3)) { - test(); - if ((sub(iMostCommonDiff,1) > 0) || (sub(nMostCommonDiff,3) < 0)) - { - /* Not enough peaks at the same distance => don't use the pitch. */ - F0 = 0; - move16(); - } + /* Not enough peaks at the same distance => don't use the pitch. */ + F0 = 0; } *pF0 = F0; - move16(); } } -static void modifyThreshold(Word16 /*int*/ i, /*I - Q0 */ - Word16 /*float*/ F0, /*I - Q10*/ - Word16 /*float*/ threshold, /*I - Q10*/ - Word16* /*float*/ thresholdModification) /*I/O - Q10*/ +static void modifyThreshold(int i, + float F0, + float threshold, + float * thresholdModification) { - Word32 harmonic; - Word16 fractional /*Q15*/; - Word16 k /*Q0*/; - Word16 twoTimesFract /*Q10*/; + float harmonic, fractional, twoTimesFract; + int k; - - - harmonic = L_mult(shl(i,5),F0); /*Q0 * Q10 = 15Q16*/ - k = extract_h(harmonic); /*Q0*/ - fractional = lshr(extract_l(harmonic),1); /* Fractional part of the i*F0 */ /*Q15*/ - twoTimesFract = mult(2048/*2 in Q10*/,fractional/*Q15*/); /*Q10*/ /* threshold if the center of the peek is between k-1 and k, threshold+2 if the center of the peek is between k and k+1 */ - - move16(); - thresholdModification[k] = threshold; - move16(); - thresholdModification[k-1] = add(threshold/*Q10*/, twoTimesFract/*Q10*/); /*Q10*/ - move16(); - thresholdModification[k+1] = add(threshold/*Q10*/, sub(2048/*2 in Q10*/, twoTimesFract/*Q10*/)/*Q10*/); /*Q10*/ + harmonic = i*F0; + k = (int)harmonic; + fractional = harmonic - k; /* Fractional part of the i*F0 */ + twoTimesFract = 2.0f*fractional; /* threshold if the centar of the peek is between k-1 and k, threshold+2 if the centar of the peek is between k and k+1 */ + thresholdModification[k] = threshold; + thresholdModification[k-1] = threshold + twoTimesFract; + thresholdModification[k+1] = threshold + 2.0f - twoTimesFract; } -static void modifyThresholds(Word16 /*float*/ F0, /*I - Q10*/ - Word16 /*float*/ origF0, /*I - Q10*/ - Word16* /*float*/ thresholdModification) /*I/O - Q10*/ +static void modifyThresholds(float F0, + float origF0, + float * thresholdModification) { - Word16 /*int*/ i, /*int*/ nHarmonics; - Word16 tmp, tmpM, tmpE; + int i, nHarmonics; - - IF (origF0 > 0) + if ((F0 == 0) && (origF0 > 0)) { - IF (F0 == 0) + nHarmonics = min(MAX_PEAKS_FROM_PITCH, (int)(LAST_HARMONIC_POS_TO_CHECK/origF0)); + for (i = 1; i <= nHarmonics; i++) { - nHarmonics /*Q0*/ = s_min(MAX_PEAKS_FROM_PITCH /*Q0*/, shl((div_s(LAST_HARMONIC_POS_TO_CHECK /*Q0*/, origF0/*Q10*/) /*Q15*2^10*/),-5 /*Q0*2^-5*/) /*Q0*/); - - FOR (i = 1; i <= nHarmonics; i++) - { - modifyThreshold(i, origF0, 717/*0.7f Q10*/ /*0.7f in Q10*/, thresholdModification); - } + modifyThreshold(i, origF0, 0.7f, thresholdModification); } - IF (F0 > 0) + } + else if ((F0 > 0) && (origF0 > 0)) + { + nHarmonics = min(MAX_PEAKS_FROM_PITCH, (int)(LAST_HARMONIC_POS_TO_CHECK/F0)); + + for (i = (int)(F0/origF0+0.5f); i > 0; i--) { - nHarmonics /*Q0*/ = s_min(MAX_PEAKS_FROM_PITCH /*Q0*/, shl((div_s(LAST_HARMONIC_POS_TO_CHECK /*Q0*/, F0/*Q10*/) /*Q15*2^10*/),-5 /*Q0*2^-5*/) /*Q0*/); - - /*(int)(F0/origF0+0.5f)*/ - BASOP_Util_Divide_MantExp(F0,0,origF0,0,&tmpM,&tmpE); - tmp=round_fx(L_shl(L_deposit_l(tmpM),add(tmpE,1))); - - FOR (i = tmp; i > 0; i--) - { - modifyThreshold(i, origF0, 358/*0.35f Q10*/, thresholdModification); - } - FOR (i = 1; i <= nHarmonics; i++) - { - modifyThreshold(i, F0, 358/*0.35f Q10*/, thresholdModification); - } + modifyThreshold(i, origF0, 0.35f, thresholdModification); + } + for (i = 1; i <= nHarmonics; i++) + { + modifyThreshold(i, F0, 0.35f, thresholdModification); } } } -static void findCandidates(Word16 nSamples, /* i: frame size */ - Word32 * MDCTSpectrum, /* i: MDCT spectrum */ - Word16 MDCTSpectrum_exp, /* i: exponent of MDCT spectrum */ - Word16 * thresholdModificationNew /* o: threshold modification Q10 */ - ,Word16 floorPowerSpectrum /* i: lower limit for power spectrum bins */ +static void findCandidates(unsigned int nSamples, + const float * MDCTSpectrum, + float * thresholdModificationNew + ,float floorPowerSpectrum /* i: lower limit for power spectrum bins */ ) { - Word32 powerSpectrum[L_FRAME_MAX]; - Word16 powerSpectrum_exp; - Word32 envelope[L_FRAME_MAX]; - Word32 smoothedSpectrum[L_FRAME_MAX]; - Word16 upperIdx, lowerIdx; - Word16 k, j; - Word32 biggerNeighbor; - Word16 tmp_loop1, tmp_loop2, tmp_loop3; - - - - calcPseudoSpec(MDCTSpectrum, MDCTSpectrum_exp, nSamples, floorPowerSpectrum, powerSpectrum, &powerSpectrum_exp); + float powerSpectrum[L_FRAME_MAX]; + float envelope[L_FRAME_MAX]; + float smoothedSpectrum[L_FRAME_MAX]; + unsigned int upperIdx, lowerIdx; + unsigned int k, j; + calcPseudoSpec(MDCTSpectrum, nSamples, floorPowerSpectrum, powerSpectrum); getEnvelope(nSamples, powerSpectrum, 0, envelope, smoothedSpectrum); - set16_fx(thresholdModificationNew, UNREACHABLE_THRESHOLD, nSamples); - - k = GROUP_LENGTH/2; - move16(); - tmp_loop1 = sub(nSamples, (GROUP_LENGTH-GROUP_LENGTH/2)); - tmp_loop2 = sub(nSamples,1); - WHILE ( sub(k, tmp_loop1) <= 0) + set_f( thresholdModificationNew, UNREACHABLE_THRESHOLD, nSamples); + for (k = GROUP_LENGTH/2 ; k <= nSamples - (GROUP_LENGTH-GROUP_LENGTH/2); k++) { - IF (L_sub(smoothedSpectrum[k],envelope[k]) > 0) + if (smoothedSpectrum[k] > envelope[k]) { /* The check that bin at k is bigger than bins at k-1 and k+1 is needed to avoid deadlocks when the thresholds are low. */ /* It removes some true peaks, especially if non weighted sum is used for the smoothed spectrum. */ - biggerNeighbor = L_max(powerSpectrum[k-1], powerSpectrum[k+1]); - - IF (L_sub(powerSpectrum[k], biggerNeighbor) >= 0) + float biggerNeighbor; + biggerNeighbor = max(powerSpectrum[k-1], powerSpectrum[k+1]); + if (powerSpectrum[k] >= biggerNeighbor) { /* Find the right foot */ - upperIdx = add(k, 1); - WHILE ( sub(upperIdx,tmp_loop2) < 0 ) + for (upperIdx = k+1; upperIdx < nSamples-1; upperIdx++) { - - IF (L_sub(powerSpectrum[upperIdx],powerSpectrum[upperIdx+1]) < 0) + if (powerSpectrum[upperIdx] < powerSpectrum[upperIdx+1]) { - /* Side lobes may increase for certain amount */ - IF (L_sub( L_shl(Mpy_32_16_1(powerSpectrum[upperIdx], ALLOWED_SIDE_LOBE_FLUCTUATION), ALLOWED_SIDE_LOBE_FLUCTUATION_EXP), powerSpectrum[upperIdx+1] ) < 0 ) + /* Side lobes may increase for certain ammount */ + if (ALLOWED_SIDE_LOBE_FLUCTUATION*powerSpectrum[upperIdx] < powerSpectrum[upperIdx+1]) { - BREAK; + break; } /* Check for further decrease after a side lobe increase */ - FOR (j = add(upperIdx,1); j < tmp_loop2; j++) + for (j = upperIdx+1; j < nSamples-1; j++) { - IF (L_sub( powerSpectrum[j], L_shl(Mpy_32_16_1(powerSpectrum[j+1], ALLOWED_SIDE_LOBE_FLUCTUATION), ALLOWED_SIDE_LOBE_FLUCTUATION_EXP) ) < 0) + if (powerSpectrum[j] < ALLOWED_SIDE_LOBE_FLUCTUATION*powerSpectrum[j+1]) { - BREAK; + break; } } /* Side lobe increase must be 2 times smaller than the decrease to the foot */ /* Eq. to 2.0f*powerSpectrum[lowerIdx-1]/powerSpectrum[lowerIdx] > powerSpectrum[lowerIdx]/powerSpectrum[j] */ - IF ( L_sub( Mpy_32_32(L_shl(powerSpectrum[upperIdx+1],1),powerSpectrum[j]), Mpy_32_32(powerSpectrum[upperIdx], powerSpectrum[upperIdx]) ) > 0 ) + if (2.0f*powerSpectrum[upperIdx+1]*powerSpectrum[j] > powerSpectrum[upperIdx]*powerSpectrum[upperIdx]) { - BREAK; + break; } - upperIdx = sub(j,1); + upperIdx = j-1; /* Reinitialize pointers due to the change of upperIdx */ } - upperIdx = add(upperIdx, 1); } /* left foot */ - lowerIdx = sub(k,1); - WHILE ( lowerIdx > 0 ) + for (lowerIdx = k-1; lowerIdx > 0; lowerIdx--) { - - IF (L_sub(powerSpectrum[lowerIdx], powerSpectrum[lowerIdx-1]) < 0) + if (powerSpectrum[lowerIdx] < powerSpectrum[lowerIdx-1]) { - /* Side lobes may increase for certain amount */ - IF (L_sub( L_shl(Mpy_32_16_1(powerSpectrum[lowerIdx], ALLOWED_SIDE_LOBE_FLUCTUATION), ALLOWED_SIDE_LOBE_FLUCTUATION_EXP), powerSpectrum[lowerIdx-1]) < 0 ) + /* Side lobes may increase for certain ammount */ + if (ALLOWED_SIDE_LOBE_FLUCTUATION*powerSpectrum[lowerIdx] < powerSpectrum[lowerIdx-1]) { - BREAK; + break; } /* Check for further decrease after a side lobe increase */ - FOR (j = sub(lowerIdx,1); j > 0; j--) + for (j = lowerIdx-1; j > 0; j--) { - IF (L_sub (powerSpectrum[j], L_shl(Mpy_32_16_1(powerSpectrum[j-1], ALLOWED_SIDE_LOBE_FLUCTUATION), ALLOWED_SIDE_LOBE_FLUCTUATION_EXP) ) < 0) + if (powerSpectrum[j] < ALLOWED_SIDE_LOBE_FLUCTUATION*powerSpectrum[j-1]) { - BREAK; + break; } } /* Side lobe increase must be 2 times smaller than the decrease to the foot */ /* Eq. to 2.0f*powerSpectrum[lowerIdx-1]/powerSpectrum[lowerIdx] > powerSpectrum[lowerIdx]/powerSpectrum[j] */ - IF (L_sub ( Mpy_32_32(L_shl(powerSpectrum[lowerIdx-1],1), powerSpectrum[j]), Mpy_32_32(powerSpectrum[lowerIdx], powerSpectrum[lowerIdx])) > 0 ) + if (2.0f*powerSpectrum[lowerIdx-1]*powerSpectrum[j] > powerSpectrum[lowerIdx]*powerSpectrum[lowerIdx]) { - BREAK; + break; } - lowerIdx = add(j,1); + lowerIdx = j+1; /* Reinitialize pointers due to the change of lowerIdx */ } - lowerIdx = sub(lowerIdx, 1); } /* Check if there is a bigger peak up to the next peak foot */ - tmp_loop3 = s_min(upperIdx, tmp_loop1); - FOR (j = s_max(GROUP_LENGTH/2, lowerIdx); j <= tmp_loop3; j++) + for (j = max(GROUP_LENGTH/2, lowerIdx); j <= min(upperIdx, nSamples - (GROUP_LENGTH-GROUP_LENGTH/2)); j++) { - if (L_sub(powerSpectrum[j], powerSpectrum[k]) > 0) + if (powerSpectrum[j] > powerSpectrum[k]) { - k = j; - move16(); + k = j; /* PTR_INIT for powerSpectrum[k] */ } } /* Modify thresholds for the following frame */ - tmp_loop3 = add(k,2); - FOR (j = sub(k,1); j < tmp_loop3; j++) + for (j = k-1; j < k+2; j++) { - thresholdModificationNew[j] = BIG_THRESHOLD; - move16(); - - if (L_sub(smoothedSpectrum[j], envelope[j]) > 0) + if (smoothedSpectrum[j] > envelope[j]) { thresholdModificationNew[j] = SMALL_THRESHOLD; - move16(); } - + else + { + thresholdModificationNew[j] = BIG_THRESHOLD; + } } /* Jump to the next foot of the peak. */ - k = upperIdx; - move16(); + k = upperIdx; /* Reinitialize pointers due to the change of k */ } } - k = add(k, 1); } } -static void RefineThresholdsUsingPitch(Word16 nSamples, - Word16 nSamplesCore, - Word32 const powerSpectrum[], - Word32 lastPitchLag, - Word32 currentPitchLag, - Word16 * pF0, - Word16 * thresholdModification) +static void RefineThresholdsUsingPitch(unsigned int nSamples, + unsigned int nSamplesCore, + float const * powerSpectrum, + float lastPitchLag, + float currentPitchLag, + float * pF0, + float * thresholdModification) { - Word16 pitchIsStable; - Word16 origF0; - Word32 L_tmp; + int pitchIsStable; + float origF0; - /*pitchIsStable = (fabs(lastPitchLag-currentPitchLag) < 0.25f);*/ - pitchIsStable = 0; - move16(); - L_tmp = L_abs(L_sub(lastPitchLag, currentPitchLag)); - if (L_sub(L_tmp, 16384l/*0.25f Q16*/) < 0) - { - pitchIsStable = 1; - move16(); - } - - IF (pitchIsStable) + pitchIsStable = (fabs(lastPitchLag-currentPitchLag) < 0.25f); + if (pitchIsStable) { GetF0(nSamples, nSamplesCore, powerSpectrum, lastPitchLag, &origF0, pF0); - modifyThresholds(*pF0, origF0, thresholdModification); } - ELSE + else { *pF0 = 0; - move16(); } } -static void findTonalComponents(Word16 * indexOfTonalPeak, /* OUT */ - Word16 * lowerIndex, /* OUT */ - Word16 * upperIndex, /* OUT */ - Word16 *numIndexes, /* OUT */ - Word16 nSamples, /* IN */ - const Word32 * powerSpectrum, /* IN */ - Word16 F0, /* IN */ - Word16 * thresholdModification) /* IN */ +static void findTonalComponents(unsigned short int * indexOfTonalPeak, /* OUT */ + unsigned short int * lowerIndex, /* OUT */ + unsigned short int * upperIndex, /* OUT */ + unsigned int * numIndexes, /* OUT */ + unsigned int nSamples, /* IN */ + const float * powerSpectrum, /* IN */ + float F0, /* IN */ + float const * thresholdModification) /* IN */ { - Word32 envelope[L_FRAME_MAX]; - Word32 smoothedSpectrum[L_FRAME_MAX]; - Word16 nrOfFIS; - Word16 upperIdx, lowerIdx, lowerBound; - Word16 k, j, m; - Word32 biggerNeighbor; - Word16 tmp_loop1, tmp_loop2, tmp_loop3; + float envelope[L_FRAME_MAX]; + float smoothedSpectrum[L_FRAME_MAX]; + + unsigned int nrOfFIS; + unsigned int upperIdx, lowerIdx, lowerBound; + unsigned int k, j; getEnvelope(nSamples, powerSpectrum, F0, envelope, smoothedSpectrum); - - nrOfFIS = 0; - move16(); lowerBound = 0; - move16(); - - k = GROUP_LENGTH/2; - move16(); - tmp_loop1 = sub(nSamples, (GROUP_LENGTH-GROUP_LENGTH/2)); - tmp_loop2 = sub(nSamples,1); - WHILE ( sub(k, tmp_loop1) <= 0) + for (k = GROUP_LENGTH/2 ; k <= nSamples - (GROUP_LENGTH-GROUP_LENGTH/2); k++) { - /* There is 3 bits headroom in envelope and max of thresholdModification is 16384, so shifting left for 4 would produce overflow only when the result is anyhow close to 1 */ - IF (L_sub(L_shr(smoothedSpectrum[k], 1), L_shl(Mpy_32_16_1(envelope[k]/*Q28,powerSpec_exp*/, thresholdModification[k]/*Q10*/), 4)) > 0) + if (smoothedSpectrum[k] > envelope[k]*thresholdModification[k]) { /* The check that bin at k is bigger than bins at k-1 and k+1 is needed to avoid deadlocks when the thresholds are low. */ /* It removes some true peaks, especially if non weighted sum is used for the smoothed spectrum. */ - biggerNeighbor = L_max(powerSpectrum[k-1], powerSpectrum[k+1]); - - IF (L_sub(powerSpectrum[k], biggerNeighbor) >= 0 ) + float biggerNeighbor; + biggerNeighbor = max(powerSpectrum[k-1], powerSpectrum[k+1]); + if (powerSpectrum[k] >= biggerNeighbor) { /* Find the right foot */ - upperIdx = add(k, 1); - WHILE (sub(upperIdx, tmp_loop2) < 0) + for (upperIdx = k+1; upperIdx < nSamples-1; upperIdx++) { - IF (L_sub(powerSpectrum[upperIdx], powerSpectrum[upperIdx+1]) < 0) + if (powerSpectrum[upperIdx] < powerSpectrum[upperIdx+1]) { - /* Side lobes may increase for certain amount */ - IF (L_sub( L_shl(Mpy_32_16_1(powerSpectrum[upperIdx], ALLOWED_SIDE_LOBE_FLUCTUATION), ALLOWED_SIDE_LOBE_FLUCTUATION_EXP), powerSpectrum[upperIdx+1]) < 0) + /* Side lobes may increase for certain ammount */ + if (ALLOWED_SIDE_LOBE_FLUCTUATION*powerSpectrum[upperIdx] < powerSpectrum[upperIdx+1]) { - BREAK; + break; } /* Check for further decrease after a side lobe increase */ - FOR (j = add(upperIdx, 1); j < tmp_loop2; j++) + for (j = upperIdx+1; j < nSamples-1; j++) { - IF (L_sub( powerSpectrum[j], L_shl(Mpy_32_16_1(powerSpectrum[j+1], ALLOWED_SIDE_LOBE_FLUCTUATION), ALLOWED_SIDE_LOBE_FLUCTUATION_EXP)) < 0) + if (powerSpectrum[j] < ALLOWED_SIDE_LOBE_FLUCTUATION*powerSpectrum[j+1]) { - BREAK; + break; } } /* Side lobe increase must be 2 times smaller than the decrease to the foot */ /* Eq. to 2.0f*powerSpectrum[lowerIdx-1]/powerSpectrum[lowerIdx] > powerSpectrum[lowerIdx]/powerSpectrum[j] */ - IF (L_sub( Mpy_32_32(L_shl(powerSpectrum[upperIdx+1], 1), powerSpectrum[j]), Mpy_32_32(powerSpectrum[upperIdx], powerSpectrum[upperIdx])) > 0) + if (2.0f*powerSpectrum[upperIdx+1]*powerSpectrum[j] > powerSpectrum[upperIdx]*powerSpectrum[upperIdx]) { - BREAK; + break; } - upperIdx = sub(j, 1); + upperIdx = j-1; /* Reinitialize pointers due to the change of upperIdx */ } - upperIdx = add(upperIdx, 1); } /* left foot */ - lowerIdx = sub(k, 1); - WHILE (sub(lowerIdx, lowerBound) > 0) + for (lowerIdx = k-1; lowerIdx > lowerBound; lowerIdx--) { - IF (L_sub(powerSpectrum[lowerIdx], powerSpectrum[lowerIdx-1]) < 0) + if (powerSpectrum[lowerIdx] < powerSpectrum[lowerIdx-1]) { - /* Side lobes may increase for certain amount */ - IF ( L_sub(L_shl(Mpy_32_16_1(powerSpectrum[lowerIdx], ALLOWED_SIDE_LOBE_FLUCTUATION), ALLOWED_SIDE_LOBE_FLUCTUATION_EXP), powerSpectrum[lowerIdx-1]) < 0) + /* Side lobes may increase for certain ammount */ + if (ALLOWED_SIDE_LOBE_FLUCTUATION*powerSpectrum[lowerIdx] < powerSpectrum[lowerIdx-1]) { - BREAK; + break; } /* Check for further decrease after a side lobe increase */ - FOR (j = sub(lowerIdx, 1); j > 0; j--) + for (j = lowerIdx-1; j > 0; j--) { - IF (L_sub(powerSpectrum[j], L_shl(Mpy_32_16_1(powerSpectrum[j-1], ALLOWED_SIDE_LOBE_FLUCTUATION), ALLOWED_SIDE_LOBE_FLUCTUATION_EXP)) < 0) + if (powerSpectrum[j] < ALLOWED_SIDE_LOBE_FLUCTUATION*powerSpectrum[j-1]) { - BREAK; + break; } } /* Side lobe increase must be 2 times smaller than the decrease to the foot */ /* Eq. to 2.0f*powerSpectrum[lowerIdx-1]/powerSpectrum[lowerIdx] > powerSpectrum[lowerIdx]/powerSpectrum[j] */ - IF ( L_sub( Mpy_32_32(L_shl(powerSpectrum[lowerIdx-1], 1), powerSpectrum[j]), Mpy_32_32(powerSpectrum[lowerIdx], powerSpectrum[lowerIdx])) > 0) + if (2.0f*powerSpectrum[lowerIdx-1]*powerSpectrum[j] > powerSpectrum[lowerIdx]*powerSpectrum[lowerIdx]) { - BREAK; + break; } - lowerIdx = add(j, 1); + lowerIdx = j+1; /* Reinitialize pointers due to the change of lowerIdx */ } - lowerIdx = sub(lowerIdx, 1); } - lowerBound = upperIdx; - move16(); /* Check if there is a bigger peak up to the next peak foot */ - tmp_loop3 = s_min(upperIdx, tmp_loop1); - FOR (j = s_max(GROUP_LENGTH/2, lowerIdx); j <= tmp_loop3; j++) + for (j = max(GROUP_LENGTH/2, lowerIdx); j <= min(upperIdx, nSamples - (GROUP_LENGTH-GROUP_LENGTH/2)); j++) { - if (L_sub(powerSpectrum[j],powerSpectrum[k]) > 0) + if (powerSpectrum[j] > powerSpectrum[k]) { - - k = j; - move16(); + k = j; /* PTR_INIT for powerSpectrum[k] */ } } assert((nrOfFIS == 0) || (indexOfTonalPeak[nrOfFIS-1] < k)); - - lowerIndex[nrOfFIS] = sub(k, GROUP_LENGTH/2); - move16(); - - upperIndex[nrOfFIS] = add(k,(GROUP_LENGTH-GROUP_LENGTH/2-1)); - move16(); - - test(); - IF ((nrOfFIS > 0) && (sub(lowerIndex[nrOfFIS], upperIndex[nrOfFIS-1]) <= 0)) + lowerIndex[nrOfFIS] = k-GROUP_LENGTH/2; + upperIndex[nrOfFIS] = k+(GROUP_LENGTH-GROUP_LENGTH/2-1); + if ((nrOfFIS > 0) && (lowerIndex[nrOfFIS] <= upperIndex[nrOfFIS-1])) { - m = shr(add(k, indexOfTonalPeak[nrOfFIS-1]), 1); + int m = (k+indexOfTonalPeak[nrOfFIS-1])/2; upperIndex[nrOfFIS-1] = m; - move16(); - lowerIndex[nrOfFIS] = add(m, 1); - move16(); + lowerIndex[nrOfFIS] = m+1; } - indexOfTonalPeak[nrOfFIS++] = k; - move16(); - - IF (sub(nrOfFIS, MAX_NUMBER_OF_IDX) == 0 ) + if (nrOfFIS == MAX_NUMBER_OF_IDX) { - BREAK; + break; } /* Jump to the next foot of the peak. */ - k = upperIdx; - move16(); + k = upperIdx; /* Reinitialize pointers due to the change of k */ } } - k = add(k, 1); } - *numIndexes = nrOfFIS; - move16(); } diff --git a/src/libs/libevs/lib_dec/acelp_core_dec.cpp b/src/libs/libevs/lib_dec/acelp_core_dec.cpp new file mode 100644 index 00000000..64b26996 --- /dev/null +++ b/src/libs/libevs/lib_dec/acelp_core_dec.cpp @@ -0,0 +1,919 @@ +/*==================================================================================== + EVS Codec 3GPP TS26.443 Nov 13, 2018. Version 12.11.0 / 13.7.0 / 14.3.0 / 15.1.0 + ====================================================================================*/ + +#include "options.h" +#include "cnst.h" +#include "rom_com.h" +#include "prot.h" + +/*-------------------------------------------------------------------* + * acelp_core_dec() + * + * ACELP core decoder + *-------------------------------------------------------------------*/ + +void acelp_core_dec( + Decoder_State *st, /* i/o: decoder state structure */ + float synth[], /* o : synthesis */ + float bwe_exc_extended[], /* i/o: bandwidth extended excitation */ + float *voice_factors, /* o : voicing factors */ + float old_syn_12k8_16k[], /* o : intermediate ACELP synthesis at 12.8kHz or 16kHz to be used by SWB BWE */ + short coder_type, /* i : coder type */ + short sharpFlag, /* i : formant sharpening flag */ + float pitch_buf[NB_SUBFR16k], /* o : floating pitch for each subframe*/ + short *unbits, /* o : number of unused bits */ + short *sid_bw /* o : 0-NB/WB, 1-SWB SID */ +) +{ + float old_exc[L_EXC_DEC], *exc; /* excitation signal buffer */ + float syn_tmp[L_FRAME16k+L_SUBFR], *syn; /* synthesis signal buffer */ + short output_frame; /* frame length at output sampling freq. */ + float lsf_new[M]; /* LSFs at the end of the frame */ + float lsp_new[M]; /* LSPs at the end of the frame */ + float lsp_mid[M]; /* LSPs in the middle of the frame */ + float Aq[NB_SUBFR16k*(M+1)]; /* A(q) quantized for the 4 subframes */ + float old_exc2[L_FRAME16k + L_EXC_MEM], *exc2; /* total excitation buffer */ + float mem_tmp[M]; /* temporary synthesis filter memory */ + float enr_q; /* E information for FER protection */ + float tmp_noise; /* Long term temporary noise energy */ + float Es_pred; /* predicted scaled innov. energy */ + float FEC_pitch; /* FEC pitch */ + float old_bwe_exc[((PIT16k_MAX + (L_FRAME16k+1) + L_SUBFR16k) * 2)]; /* excitation buffer */ + float *bwe_exc; /* Excitation for SWB TBE */ + short i, int_fs; + short tc_subfr; + short allow_cn_step; + float temp_buf[L_FRAME16k + L_SYN_MEM]; + short last_pulse_pos; + short T0_tmp; + short do_WI; + float dct_buffer[DCT_L_POST]; + float exc_buffer[DCT_L_POST]; + float dct_exc_tmp[L_FRAME16k]; + float bpf_error_signal[L_FRAME16k]; + short nb_bits; /* number of bits */ + int indice; /* parameter indices to write */ + float gain_buf[NB_SUBFR16k]; + float q_env[20]; + float exc3[L_FRAME16k]; + float syn1_tmp[L_FRAME16k+2], *syn1; + float *realBuffer[CLDFB_NO_COL_MAX], *imagBuffer[CLDFB_NO_COL_MAX]; + float realBufferTmp[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX]; + float imagBufferTmp[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX]; + short LSF_Q_prediction; /* o : LSF prediction mode */ + float tmpF; + + /* open CLDFB buffer up to CLDFB_NO_CHANNELS_MAX bands for 48kHz */ + for( i=0; ioutput_Fs / 50); + + st->bpf_off = 0; + if( st->last_core == HQ_CORE ) + { + /* in case of HQ->ACELP switching, do not apply BPF */ + st->bpf_off = 1; + + /* in case of core switching, rest post-filter memories */ + st->pfstat.on = 0; + + /* reset the GSC pre echo energy threshold in case of switching */ + st->Last_frame_ener = (float)MAX_32; + } + + if( st->prev_bfi > 0 ) + { + /* reset the GSC pre echo energy threshold in case of FEC */ + st->Last_frame_ener = (float)MAX_32; + } + + st->clas_dec = st->last_good; + enr_q = 0.0f; + Es_pred = 0.0f; + tmp_noise = 0.0f; + + mvr2r(st->old_exc, old_exc, L_EXC_MEM_DEC ); + exc = old_exc + L_EXC_MEM_DEC; + mvr2r( st->old_exc2, old_exc2, L_EXC_MEM ); + exc2 = old_exc2 + L_EXC_MEM; + mvr2r( st->old_bwe_exc, old_bwe_exc, PIT16k_MAX * 2); + bwe_exc = old_bwe_exc + PIT16k_MAX * 2; + + last_pulse_pos = 0; + do_WI = 0; + st->GSC_noisy_speech = 0; + st->relax_prev_lsf_interp = 0; + set_zero( gain_buf, NB_SUBFR16k ); + + if( st->L_frame == L_FRAME ) + { + st->gamma = GAMMA1; + st->preemph_fac = PREEMPH_FAC; + int_fs = INT_FS_12k8; + } + else + { + st->gamma = GAMMA16k; + st->preemph_fac = PREEMPH_FAC_16k; + int_fs = INT_FS_16k; + } + + /* reset post-filter in case of switching */ + if( st->pfstat.on == 0 ) + { + st->pfstat.reset = 1; + } + + /*----------------------------------------------------------------* + * Updates in case of internal sampling rate switching + *----------------------------------------------------------------*/ + + if( st->last_L_frame != st->L_frame && st->last_core != HQ_CORE ) + { + if( st->pfstat.on != 0 ) + { + short mem_syn_r_size_old, mem_syn_r_size_new; + + mem_syn_r_size_old = (short)(1.25*st->last_L_frame/20.f); + mem_syn_r_size_new = (short)(1.25*st->L_frame/20.f); + lerp( st->pfstat.mem_stp+L_SYN_MEM-mem_syn_r_size_old, st->pfstat.mem_stp+L_SYN_MEM-mem_syn_r_size_new, mem_syn_r_size_new, mem_syn_r_size_old ); + lerp( st->pfstat.mem_pf_in+L_SYN_MEM-mem_syn_r_size_old, st->pfstat.mem_pf_in+L_SYN_MEM-mem_syn_r_size_new, mem_syn_r_size_new, mem_syn_r_size_old ); + } + + /* convert quantized LSP vector */ + st->rate_switching_reset = lsp_convert_poly( st->lsp_old, st->L_frame, 0 ); + + /* convert old quantized LSF vector */ + lsp2lsf( st->lsp_old, st->lsf_old, M, int_fs ); + + /* FEC - update adaptive LSF mean vector */ + mvr2r( st->lsf_old, st->lsfoldbfi1, M ); + mvr2r( st->lsf_old, st->lsfoldbfi0, M ); + mvr2r( st->lsf_old, st->lsf_adaptive_mean, M ); + + /* Reset LPC mem */ + if( st->sr_core == 16000 ) + { + mvr2r( GEWB2_Ave, st->mem_AR, M ); + } + else + { + mvr2r( GEWB_Ave, st->mem_AR, M ); + } + set_zero( st->mem_MA, M ); + + /* update synthesis filter memories */ + synth_mem_updt2( st->L_frame, st->last_L_frame, st->old_exc, st->mem_syn_r, st->mem_syn2, NULL, DEC ); + mvr2r( st->old_exc, old_exc, L_EXC_MEM_DEC ); + mvr2r( st->mem_syn2, st->mem_syn1, M ); + mvr2r( st->mem_syn2, st->mem_syn3, M ); + + } + + /* update buffer of old subframe pitch values */ + if( st->last_L_frame != st->L_frame ) + { + if( st->L_frame == L_FRAME ) + { + if( st->last_L_frame == L_FRAME32k ) + { + tmpF = (float)12800/(float)32000; + } + else if( st->last_L_frame == 512 ) + { + tmpF = (float)12800/(float)25600; + } + else /* st->last_L_frame == L_FRAME16k */ + { + tmpF = (float)12800/(float)16000; + } + + for( i=NB_SUBFR16k-NB_SUBFR; iold_pitch_buf[i-1] = tmpF * st->old_pitch_buf[i]; + } + + for( i=2*NB_SUBFR16k-NB_SUBFR; i<2*NB_SUBFR16k; i++ ) + { + st->old_pitch_buf[i-2] = tmpF * st->old_pitch_buf[i]; + } + } + else + { + + if( st->last_L_frame == L_FRAME32k ) + { + tmpF = (float)16000/(float)32000; + } + else if( st->last_L_frame == 512 ) + { + tmpF = (float)16000/(float)25600; + } + else /* st->last_L_frame == L_FRAME12k8 */ + { + tmpF = (float)16000/(float)12800; + } + + for( i=2*NB_SUBFR-1; i>=NB_SUBFR; i-- ) + { + st->old_pitch_buf[i+2] = tmpF * st->old_pitch_buf[i]; + } + st->old_pitch_buf[NB_SUBFR+1] = st->old_pitch_buf[NB_SUBFR+2]; + + for( i=NB_SUBFR-1; i>=0; i-- ) + { + st->old_pitch_buf[i+1] = tmpF * st->old_pitch_buf[i]; + } + st->old_pitch_buf[0] = st->old_pitch_buf[1]; + } + } + + if( st->bfi_pitch_frame != st->L_frame ) + { + if( st->L_frame == L_FRAME ) + { + if( st->bfi_pitch_frame == L_FRAME32k ) + { + tmpF = (float)12800/(float)32000; + } + else if( st->bfi_pitch_frame == 512 ) + { + tmpF = (float)12800/(float)25600; + } + else /* st->bfi_pitch_frame == L_FRAME16k */ + { + tmpF = (float)12800/(float)16000; + } + st->bfi_pitch *= tmpF; + st->bfi_pitch_frame = L_FRAME; + } + else + { + if( st->bfi_pitch_frame == L_FRAME32k ) + { + tmpF = (float)16000/(float)32000; + } + else if( st->bfi_pitch_frame == 512 ) + { + tmpF = (float)16000/(float)25600; + } + else /* st->bfi_pitch_frame == L_FRAME12k8 */ + { + tmpF = (float)16000/(float)12800; + } + st->bfi_pitch *= tmpF; + st->bfi_pitch_frame = L_FRAME16k; + } + } + + if( st->last_bwidth == NB && st->bwidth != NB && st->ini_frame != 0 ) + { + st->rate_switching_reset = 1; + } + + /*----------------------------------------------------------------------* + * GOOD frame + *----------------------------------------------------------------------*/ + + if( !st->bfi ) + { + + /*----------------------------------------------------------------* + * Decoding of TC subframe clasification + *----------------------------------------------------------------*/ + + tc_subfr = -1; + if( coder_type == TRANSITION ) + { + tc_subfr = tc_classif( st, st->L_frame ); + } + + /*----------------------------------------------------------------* + * Decoding of inactive CNG frames + *----------------------------------------------------------------*/ + + if ( st->core_brate == FRAME__NO_DATA || st->core_brate == SID_2k40 ) + { + /* decode CNG parameters */ + if( st->cng_type == LP_CNG ) + { + CNG_dec( st, st->L_frame, Aq, st->core_brate, lsp_new, lsf_new, &allow_cn_step, sid_bw, q_env ); + + /* comfort noise generation */ + CNG_exc( st->core_brate, st->L_frame, &st->Enew, &st->cng_seed, exc, exc2, &st->lp_ener, st->last_core_brate, + &st->first_CNG, &(st->cng_ener_seed), bwe_exc, allow_cn_step, &st->last_allow_cn_step, st->num_ho, + q_env, st->lp_env, st->old_env, st->exc_mem, st->exc_mem1, sid_bw, &st->cng_ener_seed1, exc3 ,st->Opt_AMR_WB ); + } + else + { + if( st->core_brate == SID_2k40 ) + { + FdCng_decodeSID( st ); + *sid_bw = 0; + } + + generate_comfort_noise_dec( NULL, NULL, st ); + + FdCng_exc( st->hFdCngDec->hFdCngCom, &st->CNG_mode, st->L_frame, st->lsp_old, st->first_CNG, st->lspCNG, Aq, lsp_new,lsf_new, exc, exc2, bwe_exc ); + + mvr2r( exc2, exc3, st->L_frame ); + } + + /* update past excitation signals for LD music post-filter */ + mvr2r( st->dct_post_old_exc + L_FRAME, st->dct_post_old_exc, DCT_L_POST-L_FRAME-OFFSET2 ); + mvr2r( exc2, st->dct_post_old_exc + (DCT_L_POST-L_FRAME-OFFSET2), L_FRAME ); + + /* synthesis at 12.8kHz sampling rate */ + syn_12k8( st->L_frame, Aq, exc2, syn, st->mem_syn2, 1 ); + syn_12k8( st->L_frame, Aq, exc3, syn1, st->mem_syn3, 1 ); + + /* reset the decoder */ + CNG_reset_dec( st, pitch_buf, voice_factors ); + + /* update st->mem_syn1 for ACELP core switching */ + mvr2r( st->mem_syn3, st->mem_syn1, M ); + + /* update old synthesis for classification */ + mvr2r( syn1 + st->L_frame - L_SYN_MEM_CLAS_ESTIM, st->mem_syn_clas_estim, L_SYN_MEM_CLAS_ESTIM ); + + /* Update music post processing values */ + /* Filter energies update */ + for( i = 0; i < DCT_L_POST; i++ ) + { + st->filt_lfE[i] = 0.3f + 0.7f*st->filt_lfE[i]; + } + + /* save and delay synthesis to be used by SWB BWE */ + save_old_syn( st->L_frame, syn1, old_syn_12k8_16k, st->old_syn_12k8_16k, st->preemph_fac, &st->mem_deemph_old_syn ); + } + /*----------------------------------------------------------------* + * Decoding of all other frames + *----------------------------------------------------------------*/ + + else + { + /*-----------------------------------------------------------------* + * After CNG period, use the most up-to-date LSPs + *-----------------------------------------------------------------*/ + + if( st->last_core_brate == FRAME__NO_DATA || st->last_core_brate == SID_2k40 ) + { + mvr2r( st->lspCNG, st->lsp_old, M ); + + lsp2lsf( st->lspCNG, st->lsf_old, M, int_fs ); + } + + /*-----------------------------------------------------------------* + * Reset higher ACELP pre-quantizer in case of switching + *-----------------------------------------------------------------*/ + + if( !st->use_acelp_preq ) + { + st->mem_preemp_preQ = 0.0f; + st->last_nq_preQ = 0; + } + st->use_acelp_preq = 0; + + /*-----------------------------------------------------------------* + * LSF de-quantization and interpolation + *-----------------------------------------------------------------*/ + + lsf_dec( st, tc_subfr, st->L_frame, coder_type, st->bwidth, Aq, &LSF_Q_prediction, lsf_new, lsp_new, lsp_mid ); + + /*-----------------------------------------------------------------* + * FEC - first good frame after lost frame(s) (possibility to correct the ACB) + *-----------------------------------------------------------------*/ + + if( st->core_brate >= ACELP_11k60 ) + { + last_pulse_pos = 0; + + /* decode the last glottal pulse position */ + T0_tmp = FEC_pos_dec( st, coder_type, st->last_good, &last_pulse_pos, &st->clas_dec, &enr_q, st->core_brate ); + + if( st->last_core != HQ_CORE || (st->last_core == HQ_CORE && st->last_con_tcx) ) + { + if( st->clas_dec == SIN_ONSET && last_pulse_pos != 0 && st->prev_bfi == 1 ) + { + FEC_SinOnset( old_exc+L_EXC_MEM_DEC-L_EXC_MEM, last_pulse_pos, T0_tmp, enr_q, Aq, st->L_frame); + } + else if( (coder_type == GENERIC || coder_type == VOICED) && last_pulse_pos != 0 && st->old_bfi_cnt == 1 && output_frame == L_FRAME16k ) + { + do_WI = FEC_enhACB(st->L_frame, st->last_L_frame, old_exc+L_EXC_MEM_DEC-L_EXC_MEM, T0_tmp, last_pulse_pos, st->bfi_pitch ); + } + } + } + + /*------------------------------------------------------------* + * In case of first frame after an erasure and transition from voiced to unvoiced or inactive + * redo the LPC interpolation + *------------------------------------------------------------*/ + + if( st->stab_fac == 0 && st->old_bfi_cnt > 0 && st->clas_dec != VOICED_CLAS && st->clas_dec != ONSET && st->relax_prev_lsf_interp == 0 ) + { + int_lsp4( st->L_frame, st->lsp_old, lsp_mid, lsp_new, Aq, M, 2 ); + } + + /*---------------------------------------------------------------* + * Decoding of the scaled predicted innovation energy + *---------------------------------------------------------------*/ + + if( ( coder_type != UNVOICED && coder_type != AUDIO && coder_type != INACTIVE && !(st->core_brate <= ACELP_8k00 && coder_type != TRANSITION) ) + || (coder_type == INACTIVE && st->total_brate >= ACELP_32k) ) + { + nb_bits = Es_pred_bits_tbl[BIT_ALLOC_IDX(st->core_brate, coder_type, -1, -1)]; + indice = (short)get_next_indice( st, nb_bits ); + Es_pred_dec( &Es_pred, indice, nb_bits, 0 ); + } + + /*------------------------------------------------------------* + * Decode excitation according to coding type + *------------------------------------------------------------*/ + + if( st->nelp_mode_dec ) + { + /* SC-VBR - NELP frames */ + decod_nelp( st, coder_type, &tmp_noise, pitch_buf, exc, exc2, voice_factors, bwe_exc, st->bfi, gain_buf ); + } + else if( coder_type == UNVOICED ) + { + /* UNVOICED frames */ + decod_unvoiced( st, Aq, coder_type, &tmp_noise, pitch_buf, voice_factors, exc, exc2, bwe_exc, gain_buf ); + } + else if( st->ppp_mode_dec ) + { + /* SC-VBR - PPP frames */ + decod_ppp( st, Aq, pitch_buf, exc, exc2, voice_factors, bwe_exc, gain_buf, st->bfi ); + } + else if( coder_type == TRANSITION ) + { + decod_tran( st, st->L_frame, tc_subfr, Aq, coder_type, Es_pred, pitch_buf, voice_factors, exc, exc2, bwe_exc, unbits, sharpFlag, gain_buf ); + } + else if( coder_type == AUDIO || ( coder_type == INACTIVE && st->core_brate <= ACELP_24k40 ) ) + { + /* AUDIO and INACTIVE frames (coded by GSC technology) */ + decod_audio( st, dct_exc_tmp, Aq, coder_type, &tmp_noise, pitch_buf, voice_factors, exc, exc2, bwe_exc, lsf_new, gain_buf ); + } + else + { + /* GENERIC, VOICED and INACTIVE frames (coded by AVQ technology) */ + decod_gen_voic( st, st->L_frame, sharpFlag, Aq, coder_type, Es_pred, do_WI, pitch_buf, voice_factors, exc, exc2, bwe_exc, unbits, gain_buf ); + } + + /* synthesis for ACELP core switching and SWB BWE */ + syn_12k8( st->L_frame, Aq, exc, temp_buf, st->mem_syn1, 1 ); + + /* save and delay synthesis to be used by SWB BWE */ + save_old_syn( st->L_frame, temp_buf, old_syn_12k8_16k, st->old_syn_12k8_16k, st->preemph_fac, &st->mem_deemph_old_syn ); + + /*-----------------------------------------------------------------* + * Apply energy matching when switching to inactive frames + *-----------------------------------------------------------------*/ + + inact_switch_ematch( exc2, dct_exc_tmp, st->lt_ener_per_band, coder_type, st->L_frame, st->core_brate, st->bfi, st->last_core, st->last_codec_mode ); + + /*------------------------------------------------------------* + * Decode information and modify the excitation signal of stationary unvoiced frames + *------------------------------------------------------------*/ + + if( st->nelp_mode_dec != 1 ) + { + stat_noise_uv_dec( st, coder_type, lsp_new, lsp_mid, Aq, exc2 ); + } + + /*------------------------------------------------------------* + * Save filter memory in case the synthesis is redone after scaling + * Synthesis at 12k8 Hz sampling rate + *------------------------------------------------------------*/ + + /* update past excitation signals for LD music post-filter */ + mvr2r( st->dct_post_old_exc + L_FRAME, st->dct_post_old_exc, DCT_L_POST-L_FRAME-OFFSET2 ); + mvr2r( exc2, st->dct_post_old_exc + (DCT_L_POST-L_FRAME-OFFSET2), L_FRAME ); + mvr2r( st->dct_post_old_exc, exc_buffer, DCT_L_POST-OFFSET2 ); + + if( coder_type == AUDIO && !st->GSC_noisy_speech ) + { + /* Extrapolation of the last future part, windowing and high resolution DCT transform */ + Prep_music_postP( exc_buffer, dct_buffer, st->filt_lfE, st->last_core, pitch_buf, st->LDm_enh_lp_gbin ); + + /* LD music post-filter */ + LD_music_post_filter( dct_buffer, dct_buffer, st->core_brate, &st->LDm_last_music_flag, + st->LDm_thres, &st->LDm_nb_thr_1, &st->LDm_nb_thr_3, st->LDm_lt_diff_etot, + &st->LDm_mem_etot, st->LDm_enh_min_ns_gain, st->LDm_bckr_noise, st->LDm_enh_lf_EO, + st->LDm_enh_lp_gbin, st->filt_lfE, &st->last_nonfull_music, AUDIO, st->last_coder_type ); + + /* Inverse DCT transform, retrieval of the aligned excitation, re-synthesis */ + mvr2r( st->mem_syn2, mem_tmp, M ); + Post_music_postP( dct_buffer, exc_buffer, exc2, st->mem_syn2, st->mem_syn2, Aq, syn ); + } + else + { + /* Core synthesis at 12.8kHz or 16kHz */ + mvr2r( st->mem_syn2, mem_tmp, M ); + syn_12k8( st->L_frame, Aq, exc2, syn, st->mem_syn2, 1 ); + + for( i = 0; i < DCT_L_POST; i++ ) + { + st->filt_lfE[i] = 0.3f + 0.7f * st->filt_lfE[i]; + } + } + + /*------------------------------------------------------------* + * FEC - Estimate the classification information + *------------------------------------------------------------*/ + + FEC_clas_estim( syn, pitch_buf, st->L_frame, coder_type, st->codec_mode, st->mem_syn_clas_estim, &st->clas_dec, + &st->lp_ener_bfi, st->core_brate, st->Opt_AMR_WB, &st->decision_hyst, NULL, NULL, NULL, + NULL, NULL, NULL, temp_buf, 0, 0, (SIGNAL_CLASSIFIER_MODE)0, + 0, 0, 0, st->last_core_brate ); + + /*------------------------------------------------------------* + * FEC - Estimate pitch + *------------------------------------------------------------*/ + + FEC_pitch_estim( st->Opt_AMR_WB, st->last_core, st->L_frame, st->clas_dec, st->last_good, pitch_buf, st->old_pitch_buf, + &st->bfi_pitch, &st->bfi_pitch_frame, &st->upd_cnt, coder_type ); + + /*------------------------------------------------------------* + * FEC - Smooth the speech energy evolution when recovering after a BAD frame + * (smoothing is performed in the excitation domain and signal is resynthesized after) + *------------------------------------------------------------*/ + + FEC_scale_syn( st->L_frame, st->clas_dec, st->last_good, syn, pitch_buf, st->enr_old, enr_q, coder_type, + LSF_Q_prediction, &st->scaling_flag, &st->lp_ener_FEC_av, &st->lp_ener_FEC_max, st->bfi, + st->total_brate, st->prev_bfi, st->last_core_brate, exc, exc2, Aq, &st->old_enr_LP, mem_tmp, st->mem_syn2, + st->last_con_tcx && (st->L_frameTCX_past != st->L_frame) && (st->last_core != 0), 0 ); + + /* estimate the pitch-synchronous speech energy per sample to be used when normal operation recovers */ + if( (st->total_brate == ACELP_7k20) || (st->total_brate == ACELP_8k00) ) + { + fer_energy( st->L_frame, st->clas_dec, syn, pitch_buf[((st->L_frame)>>6)-1], &st->enr_old, st->L_frame ); + } + } + + } /* End of GOOD FRAME */ + /*----------------------------------------------------------------* + * BAD frame + *----------------------------------------------------------------*/ + + else + { + /* SC-VBR */ + if( st->last_nelp_mode_dec == 1 ) + { + st->nelp_mode_dec = 1; + } + + /* long burst frame erasures */ + if( st->nbLostCmpt > 5 && st->clas_dec >= VOICED_CLAS && st->clas_dec < INACTIVE_CLAS ) + { + st->last_good = VOICED_TRANSITION; + } + + /* LSF estimation and A(z) calculation */ + lsf_dec_bfi( MODE1, lsf_new, st->lsf_old, st->lsf_adaptive_mean, NULL, st->mem_MA, st->mem_AR, + st->stab_fac, st->last_coder_type, st->L_frame, st->last_good, + st->nbLostCmpt, 0, NULL, NULL, NULL, st->Last_GSC_pit_band_idx, st->Opt_AMR_WB, st->bwidth ); + + FEC_lsf2lsp_interp( st, st->L_frame, Aq, lsf_new, lsp_new ); + + if( st->nelp_mode_dec == 1 ) + { + /* SC-VBR */ + decod_nelp( st, coder_type, &tmp_noise, pitch_buf, exc, exc2, voice_factors, bwe_exc, st->bfi, gain_buf ); + FEC_pitch = pitch_buf[3]; + } + else + { + /* calculation of excitation signal */ + FEC_exc_estim( st, st->L_frame, exc, exc2, dct_exc_tmp, pitch_buf, voice_factors, &FEC_pitch, bwe_exc, lsf_new, &tmp_noise ); + + tmp_noise = st->lp_gainc; + + /* SC-VBR */ + st->prev_gain_pit_dec = st->lp_gainp; + } + + /* synthesis for ACELP core switching and SWB BWE */ + syn_12k8( st->L_frame, Aq, exc, temp_buf, st->mem_syn1, 1 ); + + /* save and delay synthesis to be used by SWB BWE */ + save_old_syn( st->L_frame, temp_buf, old_syn_12k8_16k, st->old_syn_12k8_16k, st->preemph_fac, &st->mem_deemph_old_syn ); + + /* Apply energy matching when switching to inactive frames */ + inact_switch_ematch( exc2, dct_exc_tmp, st->lt_ener_per_band, coder_type, st->L_frame, st->core_brate, st->bfi, st->last_core, st->last_codec_mode ); + + /* update past excitation signals for LD music post-filter */ + mvr2r( st->dct_post_old_exc + L_FRAME, st->dct_post_old_exc, DCT_L_POST-L_FRAME-OFFSET2 ); + mvr2r( exc2, st->dct_post_old_exc + (DCT_L_POST-L_FRAME-OFFSET2), L_FRAME ); + + /* synthesis at 12k8 Hz sampling rate */ + if( (st->total_brate == ACELP_7k20) || (st->total_brate == ACELP_8k00) ) + { + mvr2r( st->mem_syn2, mem_tmp, M ); + } + syn_12k8( st->L_frame, Aq, exc2, syn, st->mem_syn2, 1 ); + + /* update buffer for classifier */ + mvr2r( exc2 + st->L_frame - L_EXC_MEM, st->old_exc2, L_EXC_MEM ); + mvr2r( syn + st->L_frame - L_EXC_MEM, st->old_syn2, L_EXC_MEM ); + mvr2r( syn + st->L_frame - L_SYN_MEM_CLAS_ESTIM, st->mem_syn_clas_estim, L_SYN_MEM_CLAS_ESTIM ); + + /* Update music post processing values */ + /* Filter energies update */ + for( i = 0; i < DCT_L_POST; i++ ) + { + st->filt_lfE[i] = 0.3f + 0.7f*st->filt_lfE[i]; + } + /* Update circular buffer, keep last energy difference unchanged */ + for (i = 1; iLDm_lt_diff_etot[i-1] = st->LDm_lt_diff_etot[i]; + } + + /*------------------------------------------------------------* + * FEC - Smooth the speech energy evolution when recovering after a BAD frame + * (smoothing is performed in the excitation domain and signal is resynthesized after) + *------------------------------------------------------------*/ + + if( (st->total_brate == ACELP_7k20) || (st->total_brate == ACELP_8k00) ) + { + FEC_scale_syn( st->L_frame, st->clas_dec, st->last_good, syn, pitch_buf, st->enr_old, enr_q, coder_type, + LSF_Q_prediction, &st->scaling_flag, &st->lp_ener_FEC_av, &st->lp_ener_FEC_max, st->bfi, + st->total_brate, st->prev_bfi, st->last_core_brate, exc, exc2, Aq, &st->old_enr_LP, mem_tmp, st->mem_syn2, + st->last_con_tcx && (st->L_frameTCX_past != st->L_frame) && (st->last_core != 0), 0 ); + } + + /* estimate the pitch-synchronous speech energy per sample to be used when normal operation recovers */ + fer_energy( st->L_frame, st->last_good, syn, FEC_pitch, &st->enr_old, st->L_frame ); + + if( st->nelp_mode_dec !=1 ) + { + /* modify the excitation signal of stationary unvoiced frames */ + stat_noise_uv_mod( coder_type, 0, st->lsp_old, lsp_new, lsp_new, Aq, exc2, 1, &st->ge_sm, &st->uv_count, &st->act_count, + st->lspold_s, &st->noimix_seed, &st->min_alpha, &st->exc_pe, st->core_brate, st->bwidth ); + } + /* SC-VBR */ + st->FadeScale = st->FadeScale*0.75; + } + + + if( st->L_frame == L_FRAME ) + { + mvr2r( Aq+2*(M+1), st->cur_sub_Aq, (M+1) ); + } + else + { + mvr2r( Aq+3*(M+1), st->cur_sub_Aq, (M+1) ); + } + + /*--------------------------------------------------------* + * Apply NB postfilter in case of 8kHz output + *--------------------------------------------------------*/ + + if( st->last_bwidth == NB ) + { + if( st->bwidth == NB ) + { + st->pfstat.on = 1; + nb_post_filt( st->L_frame, L_SUBFR, &(st->pfstat), &st->psf_lp_noise, tmp_noise, syn, Aq, pitch_buf, coder_type, st->BER_detect, 0 ); + } + else + { + st->pfstat.on = 0; + nb_post_filt( st->L_frame, L_SUBFR, &(st->pfstat), &st->psf_lp_noise, tmp_noise, syn, Aq, pitch_buf, AUDIO, st->BER_detect, 0 ); + } + } + else + { + st->psf_lp_noise = st->lp_noise; + } + + /*------------------------------------------------------------------* + * Perform fixed deemphasis through 1/(1 - g*z^-1) + *-----------------------------------------------------------------*/ + + /* update old synthesis buffer - needed for ACELP internal sampling rate switching */ + mvr2r( syn + st->L_frame - L_SYN_MEM, st->mem_syn_r, L_SYN_MEM ); + deemph( syn, st->preemph_fac, st->L_frame, &(st->mem_deemph) ); + AGC_dec(syn, st->agc_mem2, st->L_frame); + + mvr2r( syn+st->L_frame/2, st->old_syn_Overl, st->L_frame/2 ); + mvr2r( syn+st->L_frame-M-1, st->syn, M+1 ); + + + /*------------------------------------------------------------------* + * Formant post-filter + *-----------------------------------------------------------------*/ + + if( st->last_bwidth>=WB && st->core_brate > ACELP_24k40 && st->core_brate <= ACELP_32k ) + { + mvr2r( syn, temp_buf + L_SYN_MEM, L_FRAME16k ); + + st->pfstat.on = 1; + formant_post_filt( &(st->pfstat), temp_buf + L_SYN_MEM, Aq, syn, L_FRAME16k, L_SUBFR, st->lp_noise, st->total_brate, 0 ); + } + else if( st->last_bwidth >= WB ) + { + if( st->pfstat.on ) + { + mvr2r( st->pfstat.mem_pf_in+L_SYN_MEM-M, temp_buf, M ); + mvr2r( syn, temp_buf+M, L_SUBFR ); + residu ( Aq, M, temp_buf+M,temp_buf+M+L_SUBFR, L_SUBFR ); + syn_filt ( Aq, M, temp_buf+M+L_SUBFR, temp_buf, L_SUBFR, st->pfstat.mem_stp+L_SYN_MEM-M, 0 ); + scale_st ( syn, temp_buf, &st->pfstat.gain_prec, L_SUBFR, -1 ); + mvr2r( temp_buf, syn, L_SUBFR/2 ); + blend_subfr2( temp_buf + L_SUBFR/2, syn + L_SUBFR/2, syn + L_SUBFR/2 ); + + } + st->pfstat.on = 0; + } + + /*----------------------------------------------------------------* + * Comfort noise addition + *----------------------------------------------------------------*/ + + if( st->flag_cna || (st->cng_type == FD_CNG && st->total_brate <= ACELP_32k) || (st->cng_type == LP_CNG && st->core_brate <= SID_2k40) ) + { + /*VAD only for non inactive frame*/ + st->VAD = st->VAD && (coder_type != INACTIVE); + + /*Noisy speech detector*/ + noisy_speech_detection( st->VAD, syn, st->hFdCngDec->hFdCngCom->frameSize, st->hFdCngDec->msNoiseEst, st->hFdCngDec->psize_shaping, + st->hFdCngDec->nFFTpart_shaping, &(st->hFdCngDec->lp_noise), &(st->hFdCngDec->lp_speech), &(st->hFdCngDec->hFdCngCom->flag_noisy_speech) ); + + st->hFdCngDec->hFdCngCom->likelihood_noisy_speech = 0.99f*st->hFdCngDec->hFdCngCom->likelihood_noisy_speech + 0.01f*(float)st->hFdCngDec->hFdCngCom->flag_noisy_speech; + st->lp_noise = st->hFdCngDec->lp_noise; + + /*Noise estimate*/ + ApplyFdCng( syn, realBuffer, imagBuffer, st->hFdCngDec, st->m_frame_type, st, 0, + ( coder_type == AUDIO && !st->GSC_noisy_speech ) ); + + /* CNA: Generate additional comfort noise to mask potential coding artefacts */ + if( st->flag_cna && coder_type != AUDIO ) + { + generate_masking_noise( syn, st->hFdCngDec->hFdCngCom, st->hFdCngDec->hFdCngCom->frameSize, 0 ); + } + else if( st->flag_cna && coder_type == AUDIO && st->last_core == ACELP_CORE && st->last_coder_type != AUDIO ) + { + v_multc( st->hFdCngDec->hFdCngCom->olapBufferSynth2+5*st->hFdCngDec->hFdCngCom->frameSize/4, (float)(st->hFdCngDec->hFdCngCom->fftlen/2), temp_buf, st->hFdCngDec->hFdCngCom->frameSize/2); + v_add( temp_buf, syn, syn, st->hFdCngDec->hFdCngCom->frameSize/2); + } + } + + if( st->flag_cna == 0 && st->L_frame == L_FRAME16k && st->last_flag_cna == 1 && ( (st->last_core == ACELP_CORE && st->last_coder_type != AUDIO) || st->last_core == AMR_WB_CORE) ) + { + v_multc( st->hFdCngDec->hFdCngCom->olapBufferSynth2+5*st->L_frame/4, 256.f, temp_buf, st->L_frame/2 ); + v_add( temp_buf, syn, syn, st->L_frame/2 ); + } + + if( st->flag_cna == 0 || coder_type == AUDIO ) + { + set_f( st->hFdCngDec->hFdCngCom->olapBufferSynth2, 0.f, st->hFdCngDec->hFdCngCom->fftlen ); + } + + /*----------------------------------------------------------------* + * Resample to the output sampling rate (8/16/32/48 kHz) + * Bass post-filter + *----------------------------------------------------------------*/ + + /* check if the CLDFB works on the right sample rate */ + if( (st->cldfbAna->no_channels * st->cldfbAna->no_col) != st->L_frame ) + { + resampleCldfb( st->cldfbAna, st->L_frame*50 ); + resampleCldfb( st->cldfbBPF, st->L_frame*50 ); + + if( st->ini_frame > 0 ) + { + st->cldfbSyn->bandsToZero = st->cldfbSyn->no_channels - st->cldfbAna->no_channels; + } + } + + if( st->L_frame != st->last_L_frame && st->last_codec_mode != MODE2 ) + { + if( st->L_frame == L_FRAME ) + { + retro_interp5_4( st->pst_old_syn ); + } + else if( st->L_frame == L_FRAME16k ) + { + retro_interp4_5( syn, st->pst_old_syn ); + } + } + + /* bass post-filter */ + bass_psfilter( st->Opt_AMR_WB, syn, st->L_frame, pitch_buf, st->pst_old_syn, &st->pst_mem_deemp_err, &st->pst_lp_ener, st->bpf_off, st->stab_fac, + &st->stab_fac_smooth, st->mem_mean_pit, st->Track_on_hist, st->vibrato_hist, &st->psf_att, coder_type, bpf_error_signal ); + + /* analysis of the synthesis at internal sampling rate */ + cldfbAnalysis( syn, realBuffer, imagBuffer, -1, st->cldfbAna ); + + /* analysis and add the BPF error signal */ + addBassPostFilter( bpf_error_signal, st->bpf_off?0:-1, realBuffer, imagBuffer, st->cldfbBPF ); + + /* set output mask for upsampling */ + if( st->bwidth == NB ) + { + /* set NB mask for upsampling */ + st->cldfbSyn->bandsToZero = st->cldfbSyn->no_channels - 10; + } + else if( st->cldfbSyn->bandsToZero != st->cldfbSyn->no_channels - st->cldfbAna->no_channels ) + { + /* in case of BW switching, re-init to default */ + st->cldfbSyn->bandsToZero = st->cldfbSyn->no_channels - st->cldfbAna->no_channels; + } + + /*WB/SWB-FD_CNG*/ + if( ( st->core_brate == FRAME__NO_DATA || st->core_brate == SID_2k40 ) && ( st->cng_type == FD_CNG ) && ( st->hFdCngDec->hFdCngCom->numCoreBands < st->cldfbSyn->no_channels ) ) + { + generate_comfort_noise_dec_hf( realBuffer,imagBuffer, st ); + + if( st->hFdCngDec->hFdCngCom->regularStopBand < st->cldfbSyn->no_channels ) + { + st->cldfbSyn->bandsToZero = st->cldfbSyn->no_channels - st->hFdCngDec->hFdCngCom->regularStopBand; + } + else + { + st->cldfbSyn->bandsToZero = 0; + } + } + + /* synthesis of the combined signal */ + cldfbSynthesis( realBuffer, imagBuffer, synth, -1, st->cldfbSyn ); + + /* save synthesis - needed in case of core switching */ + mvr2r( synth, st->previoussynth, output_frame ); + + /*-----------------------------------------------------------------* + * Bandwidth extension 6kHz-7kHz (only for 16kHz input signals) + *-----------------------------------------------------------------*/ + + if( (st->L_frame == L_FRAME && st->bwidth != NB && output_frame >= L_FRAME16k && + ( st->extl == -1 || st->extl == SWB_CNG || (st->extl == WB_BWE && st->extl_brate == 0 && coder_type != AUDIO) ) ) ) + { + hf_synth( st->core_brate, output_frame, Aq, exc2, syn, synth, &st->seed2, st->mem_hp400, + st->mem_syn_hf, st->mem_hf, st->delay_syn_hf, st->mem_hp_interp ); + } + else + { + hf_synth_reset( &st->seed2, st->mem_hf, st->mem_syn_hf, st->mem_hp400, st->mem_hp_interp, st->delay_syn_hf ); + } + + /*-----------------------------------------------------------------* + * Populate parameters for SWB TBE + *-----------------------------------------------------------------*/ + + if( ( !st->bfi && st->prev_bfi) || (st->last_vbr_hw_BWE_disable_dec == 1 && st->vbr_hw_BWE_disable_dec == 0) || ((st->extl == SWB_TBE || st->extl == WB_TBE || st->extl == FB_TBE)&&st->last_extl != SWB_TBE && st->last_extl != WB_TBE && st->last_extl != FB_TBE) ) + { + st->bwe_non_lin_prev_scale = 0.0f; + set_f( st->old_bwe_exc_extended, 0.0f, NL_BUFF_OFFSET ); + } + + if( !st->ppp_mode_dec ) + { + non_linearity( bwe_exc, bwe_exc_extended, st->old_bwe_exc_extended, L_FRAME32k, &st->bwe_non_lin_prev_scale, coder_type, voice_factors, st->L_frame ); + } + + if( st->core_brate == FRAME__NO_DATA || st->core_brate == SID_2k40 ) + { + st->bwe_non_lin_prev_scale = 0.0f; + } + + /*----------------------------------------------------------------------* + * Updates + *----------------------------------------------------------------------*/ + + updt_dec( st, st->L_frame, coder_type, old_exc, pitch_buf, Es_pred, Aq, lsf_new, lsp_new, voice_factors, old_bwe_exc, gain_buf ); + + if( st->core_brate > SID_2k40 ) + { + /* update CNG parameters in active frames */ + cng_params_upd( lsp_new, exc, st->L_frame, &st->ho_circ_ptr, st->ho_ener_circ, + &st->ho_circ_size, st->ho_lsp_circ, DEC, st->ho_env_circ, NULL, + NULL, NULL, st->last_active_brate ); + + /* Set 16k LSP flag for CNG buffer */ + st->ho_16k_lsp[st->ho_circ_ptr] = (st->L_frame == L_FRAME ? 0 : 1 ); + } + + return; +} diff --git a/src/libs/libevs/lib_dec/acelp_core_dec_fx.cpp b/src/libs/libevs/lib_dec/acelp_core_dec_fx.cpp deleted file mode 100755 index 5b63398d..00000000 --- a/src/libs/libevs/lib_dec/acelp_core_dec_fx.cpp +++ /dev/null @@ -1,1247 +0,0 @@ -/*==================================================================================== - EVS Codec 3GPP TS26.442 Apr 03, 2018. Version 12.11.0 / 13.6.0 / 14.2.0 - ====================================================================================*/ - -#include -#include "options.h" /* Compilation switches */ -#include "cnst_fx.h" /* Common constants */ -#include "rom_com_fx.h" /* Static table prototypes */ -#include "prot_fx.h" /* Function prototypes */ -#include "stl.h" -#include "basop_mpy.h" - -/*==========================================================================*/ -/* FUNCTION : void acelp_core_dec_fx () */ -/*--------------------------------------------------------------------------*/ -/* PURPOSE : ACELP core decoder */ -/*--------------------------------------------------------------------------*/ -/* INPUT ARGUMENTS : */ -/* _ Word16 coder_type_fx i : coder type */ - -/*--------------------------------------------------------------------------*/ -/* OUTPUT ARGUMENTS : */ -/* _ Word16 *voice_factors o : voicing factors Q15 */ -/* _ Word16 old_syn_12k8_16k[] o : intermediate ACELP Q_syn2-1 */ -/* synthesis at 12.8kHz or 16kHz to be used by SWB BWE */ -/* _ Word16 synth_out[] o : synthesis Q_syn2-1 */ -/*--------------------------------------------------------------------------*/ -/* INPUT/OUTPUT ARGUMENTS : */ -/* _ Decoder_State_fx *st_fx: */ -/* _ Word16 bwe_exc_extended[] i/o: bandwidth extended excitation Q0*/ -/*--------------------------------------------------------------------------*/ -/* RETURN ARGUMENTS : */ -/* _ None */ -/*--------------------------------------------------------------------------*/ -/* CALLED FROM : RX */ -/*==========================================================================*/ - -void acelp_core_dec_fx( - Decoder_State_fx *st_fx, /* i/o: decoder state structure */ - Word16 synth_out[], /* o : synthesis */ - Word32 bwe_exc_extended[], /* i/o: bandwidth extended excitation */ - Word16 *voice_factors, /* o : voicing factors */ - Word16 old_syn_12k8_16k[], /* o : intermediate ACELP synthesis for SWB BWE */ - Word16 coder_type_fx, /* i : coder type */ - Word16 sharpFlag, - Word16 pitch_buf_fx[NB_SUBFR16k], /* o : floating pitch for each subframe */ - Word16 *unbits, /* o : number of unused bits */ - Word16 *sid_bw /* o : 0-NB/WB, 1-SWB SID */ -) -{ - Word16 old_exc_fx[L_EXC_DEC] = {0}, *exc_fx; /* excitation signal buffer (Q0) */ - Word16 syn_fx_tmp[L_FRAME_16k+L_SUBFR], *syn_fx; /* synthesis signal buffer */ - Word16 temp_buf[L_FRAME16k + L_SYN_MEM]; - Word16 output_frame; /* frame length at output sampling freq. */ - Word16 mem_tmp_fx[M]; /* temporary synthesis filter memory */ - Word32 enr_q_fx; /* E information for FER protection */ - Word16 tmp_noise_fx; /* Long term temporary noise energy */ - Word16 i, int_fs; - Word16 tc_subfr_fx; - Word16 allow_cn_step_fx; - Word16 temp_buf_fx[L_FRAME16k + L_SYN_MEM]; - - Word16 Aq_fx[NB_SUBFR16k*(M+1)]= {0}; /*Q12*/ - Word16 Es_pred_fx; /*Q8*/ - Word16 old_bwe_exc_fx[((PIT16k_MAX + (L_FRAME16k+1) + L_SUBFR16k) * 2)] = {0}; /* excitation buffer */ - Word16 old_exc2_fx[L_FRAME16k + L_EXC_MEM], *exc2_fx; /* total excitation buffer */ - Word16 *bwe_exc_fx; - Word16 lsf_new_fx[M]; /* LSFs at the end of the frame */ - Word16 lsp_new_fx[M]; /* LSPs at the end of the frame */ - Word16 lsp_mid_fx[M]; /* LSPs in the middle of the frame */ - Word16 FEC_pitch_fx; /*Q6*/ - Word16 last_pulse_pos; - Word16 T0_tmp; - Word16 do_WI_fx; - Word16 dct_buffer_fx[DCT_L_POST]; - Word16 exc_buffer_fx[DCT_L_POST]; - Word16 dct_exc_tmp[L_FRAME16k]; - Word16 qdct; - Word16 delta_mem_scale; - Word16 bpf_error_signal[L_FRAME16k]; - CLDFB_SCALE_FACTOR scaleFactor; - Word32 workBuffer[128*3]; - Word32 q_env[20]; - Word16 exc3_fx[L_FRAME16k]; - Word16 syn1_fx_tmp[L_FRAME16k+2], *syn1_fx; - Word32 *realBuffer[CLDFB_NO_COL_MAX], *imagBuffer[CLDFB_NO_COL_MAX]; - Word16 gain_buf[NB_SUBFR16k]; /*Q14*/ - Word16 syn_fx_tmp2[L_FRAME_16k]; - Word16 pitch_buf_tmp[NB_SUBFR16k]; - Word16 k; - Word16 update_flg; - Word32 realBufferTmp[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX]; - Word32 imagBufferTmp[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX]; - Word16 LSF_Q_prediction; /* o : LSF prediction mode */ - Word16 avoid_lpc_burst_on_recovery; - - FOR( i=0; ioutput_Fs_fx / 50); move16();*/ - output_frame = st_fx->output_frame_fx; - move16(); - st_fx->bpf_off_fx = 0; - move16(); - if( sub(st_fx->last_core_fx,HQ_CORE) == 0 ) - { - /* in case of HQ->ACELP switching, do not apply BPF */ - st_fx->bpf_off_fx = 1; - move16(); - /* in case of core switching, reset post-filter memories */ - st_fx->pfstat.on = 0; - move16(); - /* reset the GSC pre echo energy threshold in case of switching */ - st_fx->Last_frame_ener_fx = MAX_32; - move32(); - } - if(st_fx->prev_bfi_fx > 0) - { - /* reset the GSC pre echo energy threshold in case of FEC */ - st_fx->Last_frame_ener_fx = MAX_32; - move32(); - } - st_fx->clas_dec = st_fx->last_good_fx; - move16(); - enr_q_fx = 0; - move16(); - Es_pred_fx = 0; - move16(); - tmp_noise_fx = 0; - - Copy( st_fx->old_exc_fx, old_exc_fx, L_EXC_MEM_DEC ); - exc_fx = old_exc_fx + L_EXC_MEM_DEC; - move16(); - Copy( st_fx->old_exc2_fx, old_exc2_fx, L_EXC_MEM ); - exc2_fx = old_exc2_fx + L_EXC_MEM; - Copy( st_fx->old_bwe_exc_fx, old_bwe_exc_fx, PIT16k_MAX * 2); - bwe_exc_fx = old_bwe_exc_fx + PIT16k_MAX * 2; - move16(); - last_pulse_pos = 0; - move16(); - do_WI_fx = 0; - move16(); - st_fx->GSC_noisy_speech_fx = 0; - move16(); - st_fx->relax_prev_lsf_interp_fx = 0; - move16(); - - set16_fx( gain_buf, 0, NB_SUBFR16k ); - IF( sub(st_fx->L_frame_fx,L_FRAME) == 0 ) - { - st_fx->gamma = GAMMA1; - move16(); - st_fx->preemph_fac = PREEMPH_FAC; - move16(); - int_fs = INT_FS_FX; - move16(); - } - ELSE - { - st_fx->gamma = GAMMA16k; - move16(); - st_fx->preemph_fac = PREEMPH_FAC_16k; - move16(); - int_fs = INT_FS_16k; - move16(); - } - - /* reset post-filter in case post-filtering was off in previous frame */ - if( st_fx->pfstat.on == 0 ) - { - st_fx->pfstat.reset = 1; - move16(); - } - - avoid_lpc_burst_on_recovery = 0; - move16(); - test(); - test(); - if( st_fx->last_con_tcx && sub(st_fx->L_frameTCX_past, st_fx->L_frame_fx) != 0 && st_fx->last_core_fx != 0 ) - { - avoid_lpc_burst_on_recovery = 1; - move16(); - } - - /*----------------------------------------------------------------* - * Updates in case of internal sampling rate switching - *----------------------------------------------------------------*/ - test(); - IF( sub(st_fx->last_L_frame_fx,st_fx->L_frame_fx) != 0 && sub(st_fx->last_core_fx, HQ_CORE) != 0 ) - { - if( st_fx->pfstat.on != 0 ) - { - Word16 mem_syn_r_size_old, mem_syn_r_size_new; - - mem_syn_r_size_old = shr(st_fx->last_L_frame_fx, 4); - mem_syn_r_size_new = shr(st_fx->L_frame_fx, 4); - lerp( st_fx->pfstat.mem_stp+L_SYN_MEM-mem_syn_r_size_old, st_fx->pfstat.mem_stp+L_SYN_MEM-mem_syn_r_size_new, mem_syn_r_size_new, mem_syn_r_size_old ); - lerp( st_fx->pfstat.mem_pf_in+L_SYN_MEM-mem_syn_r_size_old, st_fx->pfstat.mem_pf_in+L_SYN_MEM-mem_syn_r_size_new, mem_syn_r_size_new, mem_syn_r_size_old ); - } - - /* convert quantized LSP vector */ - st_fx->rate_switching_reset=lsp_convert_poly_fx( st_fx->lsp_old_fx, st_fx->L_frame_fx, 0); - /* convert old quantized LSF vector */ - lsp2lsf_fx( st_fx->lsp_old_fx, st_fx->lsf_old_fx, M, int_fs ); - - /* FEC - update adaptive LSF mean vector */ - Copy( st_fx->lsf_old_fx, st_fx->lsfoldbfi1_fx, M ); - Copy( st_fx->lsf_old_fx, st_fx->lsfoldbfi0_fx, M ); - Copy( st_fx->lsf_old_fx, st_fx->lsf_adaptive_mean_fx, M ); - - /* Reset LPC mem */ - IF( L_sub(st_fx->sr_core,16000) == 0 ) - { - Copy( GEWB2_Ave_fx, st_fx->mem_AR_fx, M ); - } - ELSE - { - Copy( GEWB_Ave_fx, st_fx->mem_AR_fx, M ); - } - set16_fx( st_fx->mem_MA_fx,0, M ); - - /* update synthesis filter memories */ - synth_mem_updt2( st_fx->L_frame_fx, st_fx->last_L_frame_fx, st_fx->old_exc_fx, st_fx->mem_syn_r, st_fx->mem_syn2_fx, NULL, DEC ); - Copy( st_fx->old_exc_fx, old_exc_fx, L_EXC_MEM_DEC ); - Copy_Scale_sig(st_fx->mem_syn2_fx, st_fx->mem_syn1_fx, M, sub(-1,st_fx->Q_syn)); /*Q-1*/ - - Copy( st_fx->mem_syn2_fx, st_fx->mem_syn3_fx, M ); - - } - - IF( sub(st_fx->last_L_frame_fx,st_fx->L_frame_fx) != 0 ) - { - /* update buffer of old subframe pitch values */ - IF( sub(st_fx->L_frame_fx,L_FRAME) == 0 ) - { - move16(); - IF( sub(st_fx->last_L_frame_fx,L_FRAME32k) == 0 ) - { - /* (float)12800/(float)32000; */ - k = 13107; - } - ELSE IF( sub(st_fx->last_L_frame_fx,512) == 0 ) - { - /* (float)12800/(float)25600; */ - k = 16384; - } - ELSE /* st->last_L_frame == L_FRAME16k */ - { - /* (float)12800/(float)16000; */ - k = 26214; - } - - FOR( i=NB_SUBFR16k-NB_SUBFR; iold_pitch_buf_fx[i-1] = Mpy_32_16_1(st_fx->old_pitch_buf_fx[i], k); - move32(); - } - - FOR( i=2*NB_SUBFR16k-NB_SUBFR; i<2*NB_SUBFR16k; i++ ) - { - st_fx->old_pitch_buf_fx[i-2] = Mpy_32_16_1(st_fx->old_pitch_buf_fx[i], k); - move32(); - } - } - ELSE - { - move16(); - IF( sub(st_fx->last_L_frame_fx,L_FRAME32k) == 0 ) - { - /* (float)16000/(float)32000; */ - k = -16384; - } - ELSE IF( sub(st_fx->last_L_frame_fx,512) == 0 ) - { - /* tmpF = (float)16000/(float)25600; */ - k = -12288; - } - ELSE /* st->last_L_frame == L_FRAME12k8 */ - { - /* tmpF = (float)16000/(float)12800; */ - k = 8192; - } - - FOR( i=2*NB_SUBFR-1; i>=NB_SUBFR; i-- ) - { - st_fx->old_pitch_buf_fx[i+2] = L_add(st_fx->old_pitch_buf_fx[i], Mpy_32_16_1(st_fx->old_pitch_buf_fx[i], k)); - move32(); - } - st_fx->old_pitch_buf_fx[NB_SUBFR+1] = st_fx->old_pitch_buf_fx[NB_SUBFR+2]; - move32(); - - FOR( i=NB_SUBFR-1; i>=0; i-- ) - { - st_fx->old_pitch_buf_fx[i+1] = L_add(st_fx->old_pitch_buf_fx[i], Mpy_32_16_1(st_fx->old_pitch_buf_fx[i], k)); - move32(); - } - st_fx->old_pitch_buf_fx[0] = st_fx->old_pitch_buf_fx[1]; - move32(); - } - } - - IF( sub(st_fx->bfi_pitch_frame_fx, st_fx->L_frame_fx) != 0 ) - { - IF( sub(st_fx->L_frame_fx,L_FRAME) == 0 ) - { - move16(); - IF( sub(st_fx->bfi_pitch_frame_fx,L_FRAME32k) == 0 ) - { - /* (float)12800/(float)32000; */ - k = 13107; - } - ELSE IF( sub(st_fx->bfi_pitch_frame_fx,512) == 0 ) - { - /* (float)12800/(float)25600; */ - k = 16384; - } - ELSE /* st->bfi_pitch_frame_fx == L_FRAME16k */ - { - /* (float)12800/(float)16000; */ - k = 26214; - } - st_fx->bfi_pitch_fx = mult_r(k, st_fx->bfi_pitch_fx); - st_fx->bfi_pitch_frame_fx = L_FRAME; - move16(); - } - ELSE - { - move16(); - IF( sub(st_fx->bfi_pitch_frame_fx,L_FRAME32k) == 0 ) - { - /* (float)16000/(float)32000; */ - k = -16384; - } - ELSE IF( sub(st_fx->bfi_pitch_frame_fx,512) == 0 ) - { - /* tmpF = (float)16000/(float)25600; */ - k = -12288; - } - ELSE /* st->bfi_pitch_frame_fx == L_FRAME12k8 */ - { - /* tmpF = (float)16000/(float)12800; */ - k = 8192; - } - st_fx->bfi_pitch_fx = add(st_fx->bfi_pitch_fx, mult_r(st_fx->bfi_pitch_fx,k)); - st_fx->bfi_pitch_frame_fx = L_FRAME16k; - move16(); - } - } - - test(); - test(); - if( sub(st_fx->last_bwidth_fx,NB)==0 && sub(st_fx->bwidth_fx,NB)!=0 && st_fx->ini_frame_fx!=0 ) - { - st_fx->rate_switching_reset=1; - move16(); - } - - /*----------------------------------------------------------------------* - * GOOD frame - *----------------------------------------------------------------------*/ - - IF( !st_fx->bfi_fx ) - { - - /*----------------------------------------------------------------* - * Decoding of TC subframe clasification - *----------------------------------------------------------------*/ - - tc_subfr_fx = -1; - move16(); - if( sub(coder_type_fx,TRANSITION) == 0 ) - { - tc_subfr_fx = tc_classif_fx( st_fx, st_fx->L_frame_fx ); - move16(); - } - - /*----------------------------------------------------------------* - * Decoding of inactive CNG frames - *----------------------------------------------------------------*/ - test(); - IF ( st_fx->core_brate_fx == FRAME_NO_DATA || L_sub(st_fx->core_brate_fx,SID_2k40) == 0 ) - { - /* decode CNG parameters */ - IF ( sub(st_fx->cng_type_fx,LP_CNG) == 0 ) - { - - CNG_dec_fx( st_fx, st_fx->L_frame_fx, Aq_fx, st_fx->core_brate_fx, lsp_new_fx, lsf_new_fx, &allow_cn_step_fx, sid_bw, q_env ); - - /* comfort noise generation */ - CNG_exc_fx( st_fx->core_brate_fx, st_fx->L_frame_fx, &st_fx->Enew_fx, &st_fx->cng_seed_fx, exc_fx, exc2_fx, &st_fx->lp_ener_fx, st_fx->last_core_brate_fx, - &st_fx->first_CNG_fx, &(st_fx->cng_ener_seed_fx), bwe_exc_fx, allow_cn_step_fx, &st_fx->last_allow_cn_step_fx, st_fx->prev_Q_exc, st_fx->Q_exc, st_fx->num_ho_fx, - q_env, st_fx->lp_env_fx, st_fx->old_env_fx, st_fx->exc_mem_fx, st_fx->exc_mem1_fx, sid_bw, &st_fx->cng_ener_seed1_fx, exc3_fx ,st_fx->Opt_AMR_WB_fx ); - } - ELSE - { - IF( L_sub(st_fx->core_brate_fx,SID_2k40) == 0 ) - { - FdCng_decodeSID(st_fx->hFdCngDec_fx->hFdCngCom, st_fx); - *sid_bw=0; - move16(); - } - - generate_comfort_noise_dec( NULL, NULL, NULL, st_fx, &(st_fx->Q_exc), 2 ); - - FdCng_exc(st_fx->hFdCngDec_fx->hFdCngCom, &st_fx->CNG_mode_fx, st_fx->L_frame_fx, st_fx->lsp_old_fx, st_fx->first_CNG_fx, st_fx->lspCNG_fx, Aq_fx, lsp_new_fx, lsf_new_fx, exc_fx, exc2_fx, bwe_exc_fx); - - Copy( exc2_fx, exc3_fx, st_fx->L_frame_fx ); - } - - delta_mem_scale = 3; - move16(); - test(); - if( L_sub(st_fx->lp_ener_fx,40) < 0 && sub(st_fx->cng_type_fx,LP_CNG) == 0 ) /* very low energy frames, less than 0.3125 */ - { - delta_mem_scale = 0; - move16(); - } - i = st_fx->Q_exc; - Rescale_exc( st_fx->dct_post_old_exc_fx, exc_fx, bwe_exc_fx, st_fx->last_exc_dct_in_fx, st_fx->L_frame_fx, - st_fx->L_frame_fx* HIBND_ACB_L_FAC, 0, &(st_fx->Q_exc), st_fx->Q_subfr, NULL, 0, INACTIVE); - - Rescale_mem( st_fx->Q_exc, &st_fx->prev_Q_syn, &st_fx->Q_syn, st_fx->mem_syn2_fx, st_fx->mem_syn_clas_estim_fx, delta_mem_scale, - &st_fx->mem_deemph_fx, st_fx->pst_old_syn_fx,&st_fx->pst_mem_deemp_err_fx, &st_fx->agc_mem_fx[1], &st_fx->pfstat, 0, 0, NULL ); - Copy_Scale_sig(exc2_fx, exc2_fx, st_fx->L_frame_fx, sub(st_fx->Q_exc, i)); - - /* update past excitation signals for LD music post-filter */ - Copy( st_fx->dct_post_old_exc_fx + L_FRAME, st_fx->dct_post_old_exc_fx, DCT_L_POST-L_FRAME-OFFSET2 ); - Copy( exc2_fx, st_fx->dct_post_old_exc_fx + (DCT_L_POST-L_FRAME-OFFSET2), L_FRAME ); - - /* synthesis at 12.8kHz sampling rate */ - syn_12k8_fx( st_fx->L_frame_fx, Aq_fx, exc2_fx, syn_fx, st_fx->mem_syn2_fx, 1, st_fx->Q_exc, st_fx->Q_syn ); - syn_12k8_fx( st_fx->L_frame_fx, Aq_fx, exc3_fx, syn1_fx, st_fx->mem_syn3_fx, 1, st_fx->Q_exc, st_fx->Q_syn ); - - /* reset the decoder */ - CNG_reset_dec_fx( st_fx, pitch_buf_fx, voice_factors ); - - /* update st_fx->mem_syn1 for ACELP core switching */ - Copy( st_fx->mem_syn3_fx, st_fx->mem_syn1_fx, M ); - - /* update old synthesis for classification */ - Copy( syn1_fx + st_fx->L_frame_fx - L_SYN_MEM_CLAS_ESTIM, st_fx->mem_syn_clas_estim_fx, L_SYN_MEM_CLAS_ESTIM ); - - /* Update music post processing values */ - /* Filter energies update */ - FOR( i = 0; i < DCT_L_POST; i++ ) - { - /*st_fx->filt_lfE_fx[i] = 0.3f + 0.7f * st_fx->filt_lfE_fx[i];*/ - st_fx->filt_lfE_fx[i] = round_fx(L_mac((1228<<(16)), 22938, st_fx->filt_lfE_fx[i])); - } - - /* save and delay synthesis to be used by SWB BWE */ - Copy_Scale_sig( syn1_fx, temp_buf_fx, st_fx->L_frame_fx, sub(-1,st_fx->Q_syn)); - save_old_syn_fx( st_fx->L_frame_fx, temp_buf_fx, old_syn_12k8_16k, st_fx->old_syn_12k8_16k_fx, st_fx->preemph_fac, &st_fx->mem_deemph_old_syn_fx); - } - - /*----------------------------------------------------------------* - * Decoding of all other frames - *----------------------------------------------------------------*/ - - ELSE - { - /*-----------------------------------------------------------------* - * After CNG period, use the most up-to-date LSPs - *-----------------------------------------------------------------*/ - - test(); - IF ( st_fx->last_core_brate_fx == FRAME_NO_DATA || L_sub(st_fx->last_core_brate_fx,SID_2k40) == 0 ) - { - Copy( st_fx->lspCNG_fx, st_fx->lsp_old_fx, M ); - - lsp2lsf_fx( st_fx->lspCNG_fx, st_fx->lsf_old_fx, M, int_fs ); - } - - /*-----------------------------------------------------------------* - * Reset higher ACELP pre-quantizer in case of switching - *-----------------------------------------------------------------*/ - - IF( !st_fx->use_acelp_preq ) - { - st_fx->mem_preemp_preQ_fx = 0; - move16(); - st_fx->last_nq_preQ_fx = 0; - move16(); - } - - st_fx->use_acelp_preq = 0; - move16(); - - /*-----------------------------------------------------------------* - * LSF de-quantization and interpolation - *-----------------------------------------------------------------*/ - - lsf_dec_fx( st_fx, tc_subfr_fx, st_fx->L_frame_fx, coder_type_fx, st_fx->bwidth_fx, Aq_fx, - &LSF_Q_prediction, lsf_new_fx, lsp_new_fx, lsp_mid_fx ); - - /*-----------------------------------------------------------------* - * FEC - first good frame after lost frame(s) (possibility to correct the ACB) - *-----------------------------------------------------------------*/ - - IF( L_sub(st_fx->core_brate_fx,ACELP_11k60) >= 0 ) - { - last_pulse_pos = 0; - move16(); - - /* decode the last glottal pulse position */ - T0_tmp = FEC_pos_dec_fx( st_fx, coder_type_fx, st_fx->last_good_fx, &last_pulse_pos, &st_fx->clas_dec, &enr_q_fx, st_fx->core_brate_fx ); - move16(); - - test(); - test(); - IF( sub(st_fx->last_core_fx,HQ_CORE) != 0 || (sub(st_fx->last_core_fx,HQ_CORE) == 0 && st_fx->last_con_tcx) ) - { - test(); - test(); - test(); - test(); - test(); - test(); - IF( sub(st_fx->clas_dec,SIN_ONSET) == 0 && last_pulse_pos != 0 && sub(st_fx->prev_bfi_fx,1) == 0 ) - { - st_fx->Q_exc = - FEC_SinOnset_fx( old_exc_fx+L_EXC_MEM_DEC-L_EXC_MEM, last_pulse_pos, T0_tmp, enr_q_fx, Aq_fx, st_fx->L_frame_fx, st_fx->Q_exc ); - } - ELSE IF( (sub(coder_type_fx,GENERIC) == 0 || sub(coder_type_fx,VOICED) == 0) && last_pulse_pos != 0 && sub(st_fx->old_bfi_cnt_fx,1) == 0 && sub(output_frame,L_FRAME16k) == 0) - { - do_WI_fx = FEC_enhACB_fx( st_fx->L_frame_fx, st_fx->last_L_frame_fx, old_exc_fx+L_EXC_MEM_DEC-L_EXC_MEM , T0_tmp, last_pulse_pos, st_fx->bfi_pitch_fx ); - } - } - } - - /*------------------------------------------------------------* - * In case of first frame after an erasure and transition from voiced to unvoiced or inactive - * redo the LPC interpolation - *------------------------------------------------------------*/ - test(); - test(); - test(); - test(); - IF( st_fx->stab_fac_fx == 0 && st_fx->old_bfi_cnt_fx > 0 && sub(st_fx->clas_dec,VOICED_CLAS) != 0 && sub(st_fx->clas_dec,ONSET) != 0 && st_fx->relax_prev_lsf_interp_fx == 0 ) - { - int_lsp4_fx(st_fx->L_frame_fx, st_fx->lsp_old_fx, lsp_mid_fx, lsp_new_fx, Aq_fx, M, 2 ); - } - - /*---------------------------------------------------------------* - * Decoding of the scaled predicted innovation energy - *---------------------------------------------------------------*/ - - test(); - test(); - test(); - test(); - test(); - test(); - test(); - IF( ( sub(coder_type_fx,UNVOICED) != 0 && - sub(coder_type_fx,AUDIO) != 0 && - sub(coder_type_fx,INACTIVE) != 0 && - !(L_sub(st_fx->core_brate_fx,ACELP_8k00) <= 0 && sub(coder_type_fx,TRANSITION) != 0) ) || - (sub(coder_type_fx,INACTIVE) == 0 && L_sub(st_fx->total_brate_fx,ACELP_32k) >= 0) - ) - { - Es_pred_dec_fx( st_fx, &Es_pred_fx, coder_type_fx, st_fx->core_brate_fx ); - } - - /*------------------------------------------------------------* - * Decode excitation according to coding type - *------------------------------------------------------------*/ - - test(); - test(); - IF( sub(st_fx->nelp_mode_dec_fx,1) == 0) - { - /* SC-VBR - NELP frames */ - Scale_sig(exc_fx-L_EXC_MEM, L_EXC_MEM, -st_fx->Q_exc); - st_fx->Q_exc = 0; - move16(); - - decod_nelp_fx( st_fx, coder_type_fx, &tmp_noise_fx, pitch_buf_fx, exc_fx, exc2_fx, - voice_factors, bwe_exc_fx, &st_fx->Q_exc, st_fx->bfi_fx, gain_buf ); - - Rescale_exc(st_fx->dct_post_old_exc_fx, exc_fx, NULL, st_fx->last_exc_dct_in_fx, L_FRAME, 0, (Word32)0, &(st_fx->Q_exc), st_fx->Q_subfr, exc2_fx, L_FRAME, coder_type_fx); - } - ELSE IF( sub(coder_type_fx,UNVOICED) == 0) - { - /* UNVOICED frames */ - decod_unvoiced_fx( st_fx, Aq_fx, coder_type_fx, &tmp_noise_fx, pitch_buf_fx, voice_factors, exc_fx, exc2_fx, bwe_exc_fx, gain_buf ); - } - ELSE IF ( sub(st_fx->ppp_mode_dec_fx,1) == 0 ) - { - Scale_sig(exc_fx-L_EXC_MEM, L_EXC_MEM, -st_fx->Q_exc); - st_fx->Q_exc = 0; - /* SC-VBR - PPP frames */ - decod_ppp_fx( st_fx, Aq_fx, pitch_buf_fx, exc_fx, exc2_fx, st_fx->bfi_fx, gain_buf, voice_factors, bwe_exc_fx ); - - Rescale_exc( st_fx->dct_post_old_exc_fx, exc_fx, NULL, st_fx->last_exc_dct_in_fx, L_FRAME, 0, (Word32)0, &(st_fx->Q_exc), st_fx->Q_subfr, exc2_fx, L_FRAME, coder_type_fx ); - } - ELSE IF( sub(coder_type_fx,TRANSITION ) == 0) - { - decod_tran_fx( st_fx, st_fx->L_frame_fx, tc_subfr_fx, Aq_fx, coder_type_fx, Es_pred_fx, pitch_buf_fx, voice_factors, exc_fx, exc2_fx, bwe_exc_fx, unbits, sharpFlag, gain_buf ); - } - ELSE IF( sub(coder_type_fx,AUDIO) == 0|| ( sub(coder_type_fx,INACTIVE) == 0 && L_sub(st_fx->core_brate_fx,ACELP_24k40) <= 0) ) - { - decod_audio_fx( st_fx, dct_exc_tmp, Aq_fx, coder_type_fx, pitch_buf_fx, voice_factors, exc_fx, exc2_fx, bwe_exc_fx, lsf_new_fx, gain_buf ); - tmp_noise_fx = shr_r(st_fx->lp_gainc_fx,3); /*Q0*/ - } - ELSE - { - decod_gen_voic_fx( st_fx, st_fx->L_frame_fx, sharpFlag, Aq_fx, coder_type_fx, Es_pred_fx, do_WI_fx, pitch_buf_fx, voice_factors, exc_fx, exc2_fx, bwe_exc_fx, unbits, gain_buf ); - } - - /* synthesis for ACELP core switching and SWB BWE */ - syn_12k8_fx( st_fx->L_frame_fx, Aq_fx, exc_fx, temp_buf_fx, st_fx->mem_syn1_fx, 1, st_fx->Q_exc, -1 ); - /* save and delay synthesis to be used by SWB BWE */ - save_old_syn_fx( st_fx->L_frame_fx, temp_buf_fx, old_syn_12k8_16k, st_fx->old_syn_12k8_16k_fx, st_fx->preemph_fac, &st_fx->mem_deemph_old_syn_fx ); - - - /*-----------------------------------------------------------------* - * Apply energy matching when switching to inactive frames - *-----------------------------------------------------------------*/ - - Inac_swtch_ematch_fx( exc2_fx, dct_exc_tmp, st_fx->lt_ener_per_band_fx, coder_type_fx, st_fx->L_frame_fx, st_fx->core_brate_fx, st_fx->Q_exc, st_fx->bfi_fx, st_fx->last_core_fx, st_fx->last_codec_mode ); - - /*------------------------------------------------------------* - * Decode information and modify the excitation signal of stationary unvoiced frames - *------------------------------------------------------------*/ - - IF ( sub(st_fx->nelp_mode_dec_fx,1) != 0 ) - { - stat_noise_uv_dec_fx( st_fx, coder_type_fx, lsp_new_fx, lsp_mid_fx, Aq_fx, exc2_fx ); - } - - /*------------------------------------------------------------* - * Save filter memory in case the synthesis is redone after scaling - * Synthesis at 12k8 Hz sampling rate - *------------------------------------------------------------*/ - - /* update past excitation signals for LD music post-filter */ - Copy( st_fx->dct_post_old_exc_fx + L_FRAME, st_fx->dct_post_old_exc_fx, DCT_L_POST-L_FRAME-OFFSET2 ); - Copy( exc2_fx, st_fx->dct_post_old_exc_fx + (DCT_L_POST-L_FRAME-OFFSET2), L_FRAME ); - Copy( st_fx->dct_post_old_exc_fx, exc_buffer_fx, DCT_L_POST-OFFSET2 ); - - test(); - IF( sub(coder_type_fx, AUDIO )== 0 && st_fx->GSC_noisy_speech_fx == 0 ) - { - - /* Extrapolation of the last future part, windowing and high resolution DCT transform */ - qdct = 0; - Prep_music_postP_fx( exc_buffer_fx, dct_buffer_fx, st_fx->filt_lfE_fx, st_fx->last_coder_type_fx, pitch_buf_fx, - st_fx->LDm_enh_lp_gbin_fx, st_fx->Q_exc, &qdct ); - - /* LD music post-filter */ - LD_music_post_filter_fx( dct_buffer_fx, dct_buffer_fx, st_fx->core_brate_fx, &st_fx->LDm_last_music_flag_fx, - st_fx->LDm_thres_fx, &st_fx->LDm_nb_thr_1_fx, &st_fx->LDm_nb_thr_3_fx, st_fx->LDm_lt_diff_etot_fx, - &st_fx->LDm_mem_etot_fx, st_fx->LDm_enh_min_ns_gain_fx, st_fx->LDm_bckr_noise_fx, - st_fx->LDm_enh_lf_EO_fx, st_fx->LDm_enh_lp_gbin_fx, st_fx->filt_lfE_fx, &st_fx->last_nonfull_music_fx, - &st_fx->Old_ener_Q, AUDIO, st_fx->last_coder_type_fx, qdct ); - - /* Inverse DCT transform, retrieval of the aligned excitation, re-synthesis */ - Post_music_postP_fx( dct_buffer_fx, exc2_fx, st_fx->mem_syn2_fx, st_fx->mem_syn2_fx, Aq_fx, syn_fx, &st_fx->Q_exc, &st_fx->prev_Q_syn, - &st_fx->Q_syn, st_fx->mem_syn_clas_estim_fx,0, &st_fx->mem_deemph_fx, st_fx->pst_old_syn_fx, - &st_fx->pst_mem_deemp_err_fx, &st_fx->agc_mem_fx[1], &st_fx->pfstat, temp_buf_fx, mem_tmp_fx ); - } - ELSE - { - /* Core synthesis at 12.8kHz or 16kHz */ - i = 1; - move16(); - if( sub(coder_type_fx,INACTIVE) == 0 ) - { - i = 0; - move16(); - } - /* add extra headroom in case a CNA addition is likely (i.e. st_fx->psf_lp_noise_fx is close to the threshold) */ - k = 0; - move16(); - test(); - test(); - if( sub(coder_type_fx, INACTIVE) == 0 && st_fx->flag_cna && sub(round_fx(L_shl(st_fx->lp_noise,1)), 15<<7) >= 0 ) - { - k = 1; - move16(); - } - - Rescale_mem( st_fx->Q_exc, &st_fx->prev_Q_syn, &st_fx->Q_syn, st_fx->mem_syn2_fx, st_fx->mem_syn_clas_estim_fx, 4, &st_fx->mem_deemph_fx, - st_fx->pst_old_syn_fx, &st_fx->pst_mem_deemp_err_fx, &st_fx->agc_mem_fx[1], &st_fx->pfstat, i, k, temp_buf_fx ); - - Copy( st_fx->mem_syn2_fx, mem_tmp_fx, M ); - - syn_12k8_fx( st_fx->L_frame_fx, Aq_fx, exc2_fx, syn_fx, st_fx->mem_syn2_fx, 1 , st_fx->Q_exc, st_fx->Q_syn); - - FOR( i = 0; i < DCT_L_POST; i++ ) - { - /*st_fx->filt_lfE_fx[i] = 0.3f + 0.7f * st_fx->filt_lfE_fx[i];*/ - st_fx->filt_lfE_fx[i] = round_fx(L_mac((1228<<(16)), 22938, st_fx->filt_lfE_fx[i])); - } - } - - /*------------------------------------------------------------* - * FEC - Estimate the classification information - *------------------------------------------------------------*/ - - FEC_clas_estim_fx( st_fx, st_fx->Opt_AMR_WB_fx, st_fx->L_frame_fx, &st_fx->clas_dec, coder_type_fx, pitch_buf_fx, - syn_fx, &st_fx->lp_ener_FER_fx, &st_fx->decision_hyst_fx, - NULL, NULL, NULL, NULL, 0, NULL, st_fx->core_brate_fx, st_fx->Q_syn, temp_buf_fx, - st_fx->mem_syn_clas_estim_fx, &st_fx->classifier_Q_mem_syn, - 0, 0, 0, st_fx->last_core_brate_fx ); - - /*------------------------------------------------------------* - * FEC - Estimate pitch - *------------------------------------------------------------*/ - - FEC_pitch_estim_fx( st_fx->Opt_AMR_WB_fx, st_fx->last_core_fx, st_fx->L_frame_fx, st_fx->clas_dec, st_fx->last_good_fx, pitch_buf_fx, st_fx->old_pitch_buf_fx, - &st_fx->bfi_pitch_fx, &st_fx->bfi_pitch_frame_fx, &st_fx->upd_cnt_fx, coder_type_fx ); - - /*------------------------------------------------------------* - * FEC - Smooth the speech energy evolution when recovering after a BAD frame - * (smoothing is performed in the excitation domain and signal is resynthesized after) - *------------------------------------------------------------*/ - - k = 0; - move16(); - FOR (i = 0; i < st_fx->L_frame_fx; i += L_SUBFR) - { - pitch_buf_tmp[k] = mult_r(pitch_buf_fx[k], 512); - move16(); - k++; - } - - FEC_scale_syn_fx( st_fx->L_frame_fx, &update_flg, st_fx->clas_dec, st_fx->last_good_fx, syn_fx, pitch_buf_tmp, st_fx->enr_old_fx, enr_q_fx, coder_type_fx, LSF_Q_prediction, - &st_fx->scaling_flag, &st_fx->lp_ener_FEC_av, &st_fx->lp_ener_FEC_max, st_fx->bfi_fx, st_fx->total_brate_fx, st_fx->prev_bfi_fx, st_fx->last_core_brate_fx, - exc_fx, exc2_fx, Aq_fx, &st_fx->old_enr_LP, mem_tmp_fx, st_fx->mem_syn2_fx, st_fx->Q_exc, st_fx->Q_syn , avoid_lpc_burst_on_recovery, 0 ); - - test(); - if( (L_sub(st_fx->total_brate_fx,ACELP_7k20) == 0) || (L_sub(st_fx->total_brate_fx,ACELP_8k00) == 0) ) - { - frame_ener_fx( st_fx->L_frame_fx, st_fx->clas_dec, syn_fx, pitch_buf_tmp[sub(shr(st_fx->L_frame_fx,6),1)], &st_fx->enr_old_fx, st_fx->L_frame_fx, st_fx->Q_syn, 3, 0 ); - } - } - - } /* End of GOOD FRAME */ - - /*----------------------------------------------------------------* - * BAD frame - *----------------------------------------------------------------*/ - ELSE - { - /* SC-VBR */ - if ( sub(st_fx->last_nelp_mode_dec_fx,1) == 0 ) - { - st_fx->nelp_mode_dec_fx = 1; - move16(); - } - - /* long burst frame erasures */ - test(); - test(); - if( sub(st_fx->nbLostCmpt,5) > 0 && sub(st_fx->clas_dec,VOICED_CLAS) >= 0 && sub(st_fx->clas_dec,INACTIVE_CLAS) < 0 ) - { - st_fx->last_good_fx = VOICED_TRANSITION; - move16(); - } - - /* LSF estimation and A(z) calculation */ - lsf_dec_bfi( MODE1, lsf_new_fx, st_fx->lsf_old_fx, st_fx->lsf_adaptive_mean_fx, NULL, st_fx->mem_MA_fx, st_fx->mem_AR_fx, - st_fx->stab_fac_fx, st_fx->last_coder_type_fx, st_fx->L_frame_fx, st_fx->last_good_fx, - st_fx->nbLostCmpt, 0, NULL, NULL, NULL, st_fx->Last_GSC_pit_band_idx_fx, st_fx->Opt_AMR_WB_fx, 0, st_fx->bwidth_fx); - - FEC_lsf2lsp_interp( st_fx, st_fx->L_frame_fx, Aq_fx, lsf_new_fx, lsp_new_fx ); - - IF ( st_fx->nelp_mode_dec_fx == 1 ) - { - /* SC-VBR */ - Scale_sig(exc_fx-L_EXC_MEM, L_EXC_MEM, -st_fx->Q_exc); - st_fx->Q_exc = 0; - move16(); - - decod_nelp_fx( st_fx, coder_type_fx, &tmp_noise_fx, pitch_buf_fx, exc_fx, exc2_fx, - voice_factors, bwe_exc_fx, &st_fx->Q_exc, st_fx->bfi_fx, gain_buf ); - - FEC_pitch_fx = pitch_buf_fx[3]; - move16(); - - Rescale_exc( st_fx->dct_post_old_exc_fx, exc_fx, NULL, st_fx->last_exc_dct_in_fx, L_FRAME, 0, (Word32)0, &(st_fx->Q_exc), st_fx->Q_subfr, exc2_fx, L_FRAME, coder_type_fx ); - } - ELSE - { - /* calculation of excitation signal */ - - FEC_exc_estim_fx( st_fx, st_fx->L_frame_fx, exc_fx, exc2_fx, dct_exc_tmp, pitch_buf_fx, voice_factors, &FEC_pitch_fx, bwe_exc_fx, lsf_new_fx, &st_fx->Q_exc, &tmp_noise_fx ); - - Rescale_exc( NULL, exc_fx, bwe_exc_fx, st_fx->last_exc_dct_in_fx, st_fx->L_frame_fx, L_FRAME32k, (Word32)0, - &(st_fx->Q_exc), st_fx->Q_subfr, exc2_fx, st_fx->L_frame_fx, st_fx->last_coder_type_fx ); - - tmp_noise_fx = shr_r(st_fx->lp_gainc_fx,3); /*Q0*/ - - /* SC-VBR */ - st_fx->prev_gain_pit_dec_fx = st_fx->lp_gainp_fx; - move16(); /*Q14*/ - } - - /* synthesis for ACELP core switching and SWB BWE */ - syn_12k8_fx( st_fx->L_frame_fx, Aq_fx, exc_fx, temp_buf_fx, st_fx->mem_syn1_fx, 1, st_fx->Q_exc, -1 ); /*old_syn_12k8_16k directly in q-1*/ - - /* save and delay synthesis to be used by SWB BWE */ - save_old_syn_fx( st_fx->L_frame_fx, temp_buf_fx, old_syn_12k8_16k, st_fx->old_syn_12k8_16k_fx, st_fx->preemph_fac, &st_fx->mem_deemph_old_syn_fx ); - - /* Apply energy matching when switching to inactive frames */ - Inac_swtch_ematch_fx( exc2_fx, dct_exc_tmp, st_fx->lt_ener_per_band_fx, coder_type_fx, st_fx->L_frame_fx, st_fx->core_brate_fx, st_fx->Q_exc, st_fx->bfi_fx, st_fx->last_core_fx, st_fx->last_codec_mode ); - - /* udate past excitation signals for LD music post-filter */ - Copy( st_fx->dct_post_old_exc_fx + L_FRAME, st_fx->dct_post_old_exc_fx, DCT_L_POST-L_FRAME-OFFSET2 ); - Copy( exc2_fx, st_fx->dct_post_old_exc_fx + (DCT_L_POST-L_FRAME-OFFSET2), L_FRAME ); - - /* synthesis at 12k8 Hz sampling rate */ - /* add extra headroom in case a CNA addition is likely (i.e. st_fx->psf_lp_noise_fx is close to the threshold) */ - k = 0; - move16(); - test(); - test(); - if( sub(coder_type_fx, INACTIVE) == 0 && st_fx->flag_cna && sub(round_fx(L_shl(st_fx->lp_noise,1)), 15<<7) >= 0 ) - { - k = 1; - move16(); - } - - Rescale_mem( st_fx->Q_exc, &st_fx->prev_Q_syn, &st_fx->Q_syn, st_fx->mem_syn2_fx, st_fx->mem_syn_clas_estim_fx, 4, &st_fx->mem_deemph_fx, - st_fx->pst_old_syn_fx, &st_fx->pst_mem_deemp_err_fx, &st_fx->agc_mem_fx[1], &st_fx->pfstat, 1, k, temp_buf_fx ); - - if( (L_sub(st_fx->total_brate_fx,ACELP_7k20) == 0) || (L_sub(st_fx->total_brate_fx,ACELP_8k00) == 0) ) - { - Copy( st_fx->mem_syn2_fx, mem_tmp_fx, M ); - } - syn_12k8_fx( st_fx->L_frame_fx, Aq_fx, exc2_fx, syn_fx, st_fx->mem_syn2_fx, 1, st_fx->Q_exc, st_fx->Q_syn); - - /* update buffer for classifier */ - Copy( exc2_fx + st_fx->L_frame_fx - L_EXC_MEM, st_fx->old_exc2_fx, L_EXC_MEM ); - Copy( syn_fx + st_fx->L_frame_fx - L_EXC_MEM, st_fx->old_syn2_fx, L_EXC_MEM ); - st_fx->prev_Q_exc_fr = st_fx->Q_exc; - st_fx->prev_Q_syn_fr = st_fx->Q_syn; - - Copy( syn_fx + st_fx->L_frame_fx - L_SYN_MEM_CLAS_ESTIM, st_fx->mem_syn_clas_estim_fx, L_SYN_MEM_CLAS_ESTIM ); - - /* Update music post processing values */ - /* Filter energies update */ - FOR( i = 0; i < DCT_L_POST; i++ ) - { - /*st_fx->filt_lfE_fx[i] = 0.3f + 0.7f * st_fx->filt_lfE_fx[i];*/ - st_fx->filt_lfE_fx[i] = round_fx(L_mac((1228<<(16)), 22938, st_fx->filt_lfE_fx[i])); - } - /* Update circular buffer, keep last energy difference unchanged */ - FOR( i = 1; iLDm_lt_diff_etot_fx[i-1] = st_fx->LDm_lt_diff_etot_fx[i]; - move16(); - } - - if( (L_sub(st_fx->total_brate_fx,ACELP_7k20) == 0) || (L_sub(st_fx->total_brate_fx,ACELP_8k00) == 0) ) - { - k = 0; - move16(); - FOR (i = 0; i < st_fx->L_frame_fx; i += L_SUBFR) - { - pitch_buf_tmp[k] = mult_r(pitch_buf_fx[k], 512); - move16(); - k++; - } - - /*------------------------------------------------------------* - * FEC - Smooth the speech energy evolution when recovering after a BAD frame - * (smoothing is performed in the excitation domain and signal is resynthesized after) - *------------------------------------------------------------*/ - - FEC_scale_syn_fx( st_fx->L_frame_fx, &update_flg, st_fx->clas_dec, st_fx->last_good_fx, syn_fx, pitch_buf_tmp, st_fx->enr_old_fx, enr_q_fx, coder_type_fx, LSF_Q_prediction, - &st_fx->scaling_flag, &st_fx->lp_ener_FEC_av, &st_fx->lp_ener_FEC_max, st_fx->bfi_fx, st_fx->total_brate_fx, st_fx->prev_bfi_fx, st_fx->last_core_brate_fx, - exc_fx, exc2_fx, Aq_fx, &st_fx->old_enr_LP, mem_tmp_fx, st_fx->mem_syn2_fx, st_fx->Q_exc, st_fx->Q_syn, avoid_lpc_burst_on_recovery, 0 ); - } - - /* estimate the pitch-synchronous speech energy per sample to be used when normal operation recovers */ - /* fer_energy( st_fx->L_frame_fx, st_fx->last_good_fx, syn_fx, FEC_pitch_fx, &st_fx->enr_old_fx, st_fx->L_frame_fx ); */ - frame_ener_fx( st_fx->L_frame_fx, st_fx->last_good_fx, syn_fx, shr(add(FEC_pitch_fx,32),6), &st_fx->enr_old_fx, st_fx->L_frame_fx, st_fx->Q_syn, 3, 0 ); - - IF ( st_fx->nelp_mode_dec_fx !=1 ) - { - /* modify the excitation signal of stationary unvoiced frames */ - stat_noise_uv_mod_fx( coder_type_fx, 0, st_fx->lsp_old_fx, lsp_new_fx, lsp_new_fx, Aq_fx, exc2_fx, st_fx->Q_exc, 1, &st_fx->ge_sm_fx, - &st_fx->uv_count_fx, &st_fx->act_count_fx, st_fx->lspold_s_fx, &st_fx->noimix_seed_fx, &st_fx->min_alpha_fx, - &st_fx->exc_pe_fx, st_fx->core_brate_fx,st_fx->bwidth_fx, &st_fx->Q_stat_noise, &st_fx->Q_stat_noise_ge ); - } - - /* SC-VBR */ - st_fx->FadeScale_fx = mult(st_fx->FadeScale_fx,24576); /*24576 in Q15*/ - } - - IF (sub(st_fx->L_frame_fx,L_FRAME) == 0) - { - Copy( Aq_fx+2*(M+1), st_fx->cur_sub_Aq_fx, (M+1) ); - } - ELSE - { - Copy( Aq_fx+3*(M+1), st_fx->cur_sub_Aq_fx, (M+1) ); - } - - /*--------------------------------------------------------* - * Apply NB postfilter in case of 8kHz output - *--------------------------------------------------------*/ - - IF( sub(st_fx->last_bwidth_fx,NB) == 0 ) - { - k = 0; - move16(); - FOR (i = 0; i < st_fx->L_frame_fx; i += L_SUBFR) - { - pitch_buf_tmp[k] = mult_r(pitch_buf_fx[k], 512); - move16(); - k++; - } - - IF(sub(st_fx->bwidth_fx,NB) == 0) - { - st_fx->pfstat.on = 1; - move16(); - nb_post_filt( st_fx->L_frame_fx, &(st_fx->pfstat), &st_fx->psf_lp_noise_fx, tmp_noise_fx, syn_fx, Aq_fx, pitch_buf_tmp, coder_type_fx, st_fx->BER_detect, 0 ); - } - ELSE - { - st_fx->pfstat.on = 0; - move16(); - nb_post_filt( st_fx->L_frame_fx, &(st_fx->pfstat), &st_fx->psf_lp_noise_fx, tmp_noise_fx, syn_fx, Aq_fx, pitch_buf_tmp, AUDIO, st_fx->BER_detect, 0 ); - } - } - ELSE - { - st_fx->psf_lp_noise_fx = round_fx(L_shl(st_fx->lp_noise,1)); - } - - /*------------------------------------------------------------------* - * Perform fixed deemphasis through 1/(1 - g*z^-1) - *-----------------------------------------------------------------*/ - - /* Update old synthesis buffer - needed for ACELP internal sampling rate switching */ - Copy( syn_fx + st_fx->L_frame_fx - L_SYN_MEM, st_fx->mem_syn_r, L_SYN_MEM ); - deemph_fx( syn_fx, st_fx->preemph_fac, st_fx->L_frame_fx, &(st_fx->mem_deemph_fx) ); - - unscale_AGC( syn_fx, st_fx->Q_syn, syn_fx_tmp2, st_fx->agc_mem_fx, st_fx->L_frame_fx ); - Copy(syn_fx_tmp2, syn_fx, st_fx->L_frame_fx); - - /* Update MODE2 memories*/ - Copy_Scale_sig( syn_fx + st_fx->L_frame_fx/2, st_fx->old_syn_Overl, st_fx->L_frame_fx/2, sub(-1,st_fx->Q_syn)); /*Q-1*/ - Copy_Scale_sig( syn_fx + st_fx->L_frame_fx-M-1, st_fx->syn, M+1, sub(0,st_fx->Q_syn)); /*Q0*/ - - /*------------------------------------------------------------------* - * Formant post-filter - *-----------------------------------------------------------------*/ - - test(); - test(); - IF( sub(st_fx->last_bwidth_fx,WB) >= 0 && L_sub(st_fx->core_brate_fx,ACELP_24k40) > 0 && L_sub(st_fx->core_brate_fx,ACELP_32k) <= 0) - { - Copy( syn_fx, temp_buf + L_SYN_MEM, L_FRAME16k ); - st_fx->pfstat.on = 1; - move16(); - formant_post_filt( &(st_fx->pfstat), temp_buf + L_SYN_MEM, Aq_fx, syn_fx, L_FRAME16k, st_fx->lp_noise, st_fx->total_brate_fx, 0); - } - ELSE IF( sub(st_fx->last_bwidth_fx,WB) >= 0 ) - { - if( st_fx->pfstat.on ) - { - Copy( st_fx->pfstat.mem_pf_in+L_SYN_MEM-M, temp_buf, M ); - Copy( syn_fx, temp_buf + M, L_SUBFR ); - Residu3_fx ( Aq_fx, temp_buf + M, temp_buf+M+L_SUBFR, L_SUBFR, 1 ); - E_UTIL_synthesis ( 1, Aq_fx, temp_buf+M+L_SUBFR, temp_buf, L_SUBFR, st_fx->pfstat.mem_stp+L_SYN_MEM-M, 0, M ); - scale_st ( syn_fx, temp_buf, &st_fx->pfstat.gain_prec, L_SUBFR ); - Copy( temp_buf, syn_fx, L_SUBFR/2 ); - blend_subfr2( temp_buf + L_SUBFR/2, syn_fx + L_SUBFR/2, syn_fx + L_SUBFR/2 ); - } - st_fx->pfstat.on = 0; - move16(); - } - - /*----------------------------------------------------------------* - * Comfort noise addition - *----------------------------------------------------------------*/ - - test(); - test(); - test(); - test(); - IF( st_fx->flag_cna || (sub(st_fx->cng_type_fx,FD_CNG) == 0 && L_sub(st_fx->total_brate_fx,ACELP_32k) <= 0) || (sub(st_fx->cng_type_fx,LP_CNG) == 0 && L_sub(st_fx->total_brate_fx, SID_2k40) <= 0) ) - { - /*VAD only for non inactive frame*/ - test(); - st_fx->VAD = st_fx->VAD && (coder_type_fx != INACTIVE); - - /*Noisy speech detector*/ - noisy_speech_detection( st_fx->VAD, syn_fx, st_fx->L_frame_fx, st_fx->Q_syn, st_fx->hFdCngDec_fx->msNoiseEst, st_fx->hFdCngDec_fx->msNoiseEst_exp, - st_fx->hFdCngDec_fx->psize_shaping_norm, st_fx->hFdCngDec_fx->psize_shaping_norm_exp, st_fx->hFdCngDec_fx->nFFTpart_shaping, - &(st_fx->hFdCngDec_fx->lp_noise), &(st_fx->hFdCngDec_fx->lp_speech), &(st_fx->hFdCngDec_fx->hFdCngCom->flag_noisy_speech) ); - - st_fx->hFdCngDec_fx->hFdCngCom->likelihood_noisy_speech = mult_r(st_fx->hFdCngDec_fx->hFdCngCom->likelihood_noisy_speech, 32440/*0.99 Q15*/); - IF ( st_fx->hFdCngDec_fx->hFdCngCom->flag_noisy_speech != 0 ) - { - st_fx->hFdCngDec_fx->hFdCngCom->likelihood_noisy_speech = add(st_fx->hFdCngDec_fx->hFdCngCom->likelihood_noisy_speech, 328/*0.01 Q15*/); - move16(); - } - st_fx->lp_noise = st_fx->hFdCngDec_fx->lp_noise; - move32(); - - /*Noise estimate*/ - test(); - test(); - ApplyFdCng( syn_fx, st_fx->Q_syn, realBuffer, imagBuffer, 0, st_fx->hFdCngDec_fx, st_fx->m_frame_type, st_fx, 0, - (sub(coder_type_fx, AUDIO )== 0 && st_fx->GSC_noisy_speech_fx == 0) ); - - /* CNA: Generate additional comfort noise to mask potential coding artefacts */ - test(); - test(); - test(); - test(); - IF( st_fx->flag_cna && sub(coder_type_fx,AUDIO) != 0 ) - { - generate_masking_noise( syn_fx, st_fx->Q_syn, st_fx->hFdCngDec_fx->hFdCngCom, st_fx->hFdCngDec_fx->hFdCngCom->frameSize, 0 ); - } - ELSE IF( st_fx->flag_cna && coder_type_fx == AUDIO && st_fx->last_core_fx == ACELP_CORE && st_fx->last_coder_type_fx != AUDIO ) - { - FOR (i=0; i < st_fx->hFdCngDec_fx->hFdCngCom->frameSize/2; i++) - { - syn_fx[i] = add( syn_fx[i], shr_r( mult_r( st_fx->hFdCngDec_fx->hFdCngCom->olapBufferSynth2[i+5*st_fx->hFdCngDec_fx->hFdCngCom->frameSize/4], st_fx->hFdCngDec_fx->hFdCngCom->fftlenFac ), -st_fx->Q_syn ) ); - move16(); - } - } - } - - IF( st_fx->flag_cna == 0 && sub(st_fx->L_frame_fx,L_FRAME16k) == 0 && st_fx->last_flag_cna == 1 && ( (st_fx->last_core_fx == ACELP_CORE && st_fx->last_coder_type_fx != AUDIO) || st_fx->last_core_fx == AMR_WB_CORE) ) - { - FOR (i=0; i < st_fx->L_frame_fx/2; i++) - { - syn_fx[i] = add( syn_fx[i], shr_r( st_fx->hFdCngDec_fx->hFdCngCom->olapBufferSynth2[i+5*st_fx->L_frame_fx/4], -st_fx->Q_syn ) ); - move16(); - } - } - - test(); - IF( st_fx->flag_cna == 0 || sub(coder_type_fx,AUDIO) == 0 ) - { - set16_fx( st_fx->hFdCngDec_fx->hFdCngCom->olapBufferSynth2, 0, st_fx->hFdCngDec_fx->hFdCngCom->fftlen ); - } - - /*----------------------------------------------------------------* - * Resample to the output sampling rate (8/16/32/48 kHz) - * Bass post-filter - *----------------------------------------------------------------*/ - - /* check if the CLDFB works on the right sample rate */ - IF( (st_fx->cldfbAna_fx->usb * st_fx->cldfbAna_fx->no_col) != st_fx->L_frame_fx ) - { - /* resample to ACELP internal sampling rate */ - Word16 newCldfbBands = CLDFB_getNumChannels(L_mult0(st_fx->L_frame_fx,50)); - resampleCldfb( st_fx->cldfbAna_fx, newCldfbBands, st_fx->L_frame_fx, 0 ); - resampleCldfb( st_fx->cldfbBPF_fx, newCldfbBands, st_fx->L_frame_fx, 0 ); - - if( st_fx->ini_frame_fx > 0 ) - { - st_fx->cldfbSyn_fx->bandsToZero = sub(st_fx->cldfbSyn_fx->no_channels,st_fx->cldfbAna_fx->no_channels); - } - } - - test(); - IF( sub(st_fx->L_frame_fx,st_fx->last_L_frame_fx) != 0 && sub(st_fx->last_codec_mode,MODE2) != 0 ) - { - IF( sub(st_fx->L_frame_fx,L_FRAME) == 0 ) - { - retro_interp5_4_fx( st_fx->pst_old_syn_fx ); - } - ELSE IF( sub(st_fx->L_frame_fx,L_FRAME16k) == 0 ) - { - retro_interp4_5_fx( syn_fx, st_fx->pst_old_syn_fx ); - } - } - - bass_psfilter_fx( st_fx->Opt_AMR_WB_fx, syn_fx, st_fx->L_frame_fx, pitch_buf_fx, st_fx->pst_old_syn_fx, - &st_fx->pst_mem_deemp_err_fx, &st_fx->pst_lp_ener_fx, st_fx->bpf_off_fx, st_fx->stab_fac_fx, &st_fx->stab_fac_smooth_fx, - st_fx->mem_mean_pit_fx, st_fx->Track_on_hist_fx, st_fx->vibrato_hist_fx, &st_fx->psf_att_fx, coder_type_fx, st_fx->Q_syn, bpf_error_signal ); - - /* analysis of the synthesis at internal sampling rate */ - cldfbAnalysisFiltering( st_fx->cldfbAna_fx, realBuffer, imagBuffer, &scaleFactor, syn_fx, negate(st_fx->Q_syn), CLDFB_NO_COL_MAX, workBuffer); - - scaleFactor.hb_scale = scaleFactor.lb_scale; - move16(); - - /* analysis and add the BPF error signal */ - i = 0; - move16(); - if( st_fx->bpf_off_fx == 0 ) - { - i = CLDFB_NO_COL_MAX; - move16(); - } - addBassPostFilterFx( bpf_error_signal, realBuffer, imagBuffer, st_fx->cldfbBPF_fx, workBuffer, negate(st_fx->Q_syn), - i, st_fx->cldfbAna_fx->no_col, st_fx->cldfbAna_fx->no_channels, &scaleFactor ); - - /* set output mask for upsampling */ - IF( sub(st_fx->bwidth_fx,NB) == 0 ) - { - /* set NB mask for upsampling */ - st_fx->cldfbSyn_fx->bandsToZero = sub(st_fx->cldfbSyn_fx->no_channels,10); - } - ELSE if( sub(st_fx->cldfbSyn_fx->bandsToZero,sub(st_fx->cldfbSyn_fx->no_channels,st_fx->cldfbAna_fx->no_channels)) != 0 ) - { - /* in case of BW switching, re-init to default */ - st_fx->cldfbSyn_fx->bandsToZero = sub(st_fx->cldfbSyn_fx->no_channels, st_fx->cldfbAna_fx->no_channels); - } - - /*WB/SWB-FD_CNG*/ - scaleFactor.hb_scale = scaleFactor.lb_scale; - move16(); - - test(); - test(); - test(); - IF( ( L_sub(st_fx->core_brate_fx,FRAME_NO_DATA) == 0 || L_sub(st_fx->core_brate_fx,SID_2k40) == 0 ) && ( sub(st_fx->cng_type_fx,FD_CNG) == 0 ) && ( sub(st_fx->hFdCngDec_fx->hFdCngCom->numCoreBands,st_fx->cldfbSyn_fx->no_channels) < 0 ) ) - { - generate_comfort_noise_dec_hf( realBuffer, imagBuffer, &scaleFactor.hb_scale, st_fx ); - - st_fx->cldfbSyn_fx->bandsToZero = 0; - move16(); - if( sub(st_fx->hFdCngDec_fx->hFdCngCom->regularStopBand, st_fx->cldfbSyn_fx->no_channels) < 0 ) - { - st_fx->cldfbSyn_fx->bandsToZero = sub(st_fx->cldfbSyn_fx->no_channels, st_fx->hFdCngDec_fx->hFdCngCom->regularStopBand); - } - st_fx->cldfbSyn_fx->lsb = st_fx->cldfbAna_fx->no_channels; - move16(); - } - - /* synthesis of the combined signal */ - st_fx->Q_syn2 = st_fx->Q_syn; - move16(); - cldfbSynthesisFiltering(st_fx->cldfbSyn_fx, realBuffer, imagBuffer, &scaleFactor, synth_out, negate(st_fx->Q_syn2), CLDFB_NO_COL_MAX, workBuffer); - - /* Bring CLDFB output to Q0 */ - Scale_sig(synth_out, output_frame, negate(st_fx->Q_syn2)); - st_fx->Q_syn2 = 0; - move16(); - - /* save synthesis - needed in case of core switching */ - Copy( synth_out, st_fx->previoussynth_fx, output_frame ); - - /*-----------------------------------------------------------------* - * Bandwidth extension 6kHz-7kHz (only for 16kHz input signals) - *-----------------------------------------------------------------*/ - - test(); - test(); - test(); - test(); - test(); - test(); - test(); - IF( (sub(st_fx->L_frame_fx,L_FRAME) == 0 && sub(st_fx->bwidth_fx,NB) != 0 && sub(output_frame,L_FRAME16k) >= 0 && - ( sub(st_fx->extl_fx,-1) == 0 || sub(st_fx->extl_fx,SWB_CNG) == 0 || (sub(st_fx->extl_fx,WB_BWE) == 0 && st_fx->extl_brate_fx == 0 && sub(coder_type_fx,AUDIO) != 0)) ) ) - { - hf_synth_fx( st_fx->core_brate_fx, output_frame, Aq_fx, exc2_fx, syn_fx, synth_out, &st_fx->seed2_fx, - st_fx->mem_hp400_fx, st_fx->mem_syn_hf_fx, st_fx->mem_hf_fx, st_fx->Q_exc, - st_fx->Q_syn2, st_fx->delay_syn_hf_fx, &st_fx->memExp1, st_fx->mem_hp_interp_fx, st_fx->extl_fx, st_fx->CNG_mode_fx ); - } - ELSE - { - hf_synth_reset_fx( &st_fx->seed2_fx, st_fx->mem_hf_fx, st_fx->mem_syn_hf_fx, st_fx->mem_hp400_fx, st_fx->mem_hp_interp_fx, st_fx->delay_syn_hf_fx ); - } - - /*-----------------------------------------------------------------* - * Populate parameters for SWB TBE - *-----------------------------------------------------------------*/ - - /* Apply a non linearity to the SHB excitation */ - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - IF( ( !st_fx->bfi_fx && ( st_fx->prev_bfi_fx )) || ((sub(st_fx->last_vbr_hw_BWE_disable_dec_fx,1) == 0) && (st_fx->vbr_hw_BWE_disable_dec_fx == 0)) || ((sub(st_fx->extl_fx,SWB_TBE)==0 || sub(st_fx->extl_fx,WB_TBE)==0 || sub(st_fx->extl_fx,FB_TBE)==0) && sub(st_fx->last_extl_fx,SWB_TBE)!=0 && sub(st_fx->last_extl_fx,WB_TBE)!=0 && sub(st_fx->last_extl_fx,FB_TBE)!=0) ) - { - st_fx->bwe_non_lin_prev_scale_fx = L_deposit_l(0); - set16_fx( st_fx->old_bwe_exc_extended_fx, 0, NL_BUFF_OFFSET ); - } - - - IF( !st_fx->ppp_mode_dec_fx ) - { - non_linearity_fx( bwe_exc_fx, bwe_exc_extended, L_FRAME32k, &st_fx->bwe_non_lin_prev_scale_fx, st_fx->Q_exc , - coder_type_fx, voice_factors, st_fx->L_frame_fx ); - } - - test(); - if( L_sub(st_fx->core_brate_fx,FRAME_NO_DATA) == 0 || L_sub(st_fx->core_brate_fx,SID_2k40) == 0 ) - { - st_fx->bwe_non_lin_prev_scale_fx = L_deposit_l(0); - } - - /*----------------------------------------------------------------------* - * Updates - *----------------------------------------------------------------------*/ - - updt_dec_fx( st_fx, st_fx->L_frame_fx, coder_type_fx, old_exc_fx, pitch_buf_fx, Es_pred_fx, Aq_fx, lsf_new_fx, lsp_new_fx, voice_factors, old_bwe_exc_fx, gain_buf ); - - IF( L_sub(st_fx->core_brate_fx,SID_2k40) > 0 ) - { - /* update CNG parameters in active frames */ - cng_params_upd_fx( lsp_new_fx, exc_fx, st_fx->L_frame_fx, &st_fx->ho_circ_ptr_fx, st_fx->ho_ener_circ_fx, &st_fx->ho_circ_size_fx, st_fx->ho_lsp_circ_fx, - st_fx->Q_exc, DEC, st_fx->ho_env_circ_fx, NULL, NULL, NULL, NULL, st_fx->last_active_brate_fx ); - - /* Set 16k LSP flag for CNG buffer */ - st_fx->ho_16k_lsp_fx[st_fx->ho_circ_ptr_fx] = 0; - move16(); - if( sub(st_fx->L_frame_fx, L_FRAME) != 0 ) - { - st_fx->ho_16k_lsp_fx[st_fx->ho_circ_ptr_fx] = 1; - move16(); - } - } - - return; -} diff --git a/src/libs/libevs/lib_dec/acelp_core_switch_dec.cpp b/src/libs/libevs/lib_dec/acelp_core_switch_dec.cpp new file mode 100644 index 00000000..6ee78ceb --- /dev/null +++ b/src/libs/libevs/lib_dec/acelp_core_switch_dec.cpp @@ -0,0 +1,560 @@ +/*==================================================================================== + EVS Codec 3GPP TS26.443 Nov 13, 2018. Version 12.11.0 / 13.7.0 / 14.3.0 / 15.1.0 + ====================================================================================*/ + +#include "options.h" +#include "cnst.h" +#include "rom_com.h" +#include "prot.h" + + +/*---------------------------------------------------------------------* + * Local functions + *---------------------------------------------------------------------*/ + +static void decod_gen_voic_core_switch( Decoder_State *st, const short L_frame, const short sharpFlag, const float *Aq, + const short coder_type, float *exc, const long core_brate ); + +/*-------------------------------------------------------------------* + * acelp_core_switch_dec() + * + * ACELP core decoder in the first ACELP->HQ switching frame + *-------------------------------------------------------------------*/ + +void acelp_core_switch_dec( + Decoder_State *st, /* i/o: decoder state structure */ + float *synth_subfr_out, /* o : synthesized ACELP subframe */ + float *tmp_synth_bwe, /* o : synthesized ACELP subframe BWE */ + const short output_frame, /* i : input frame legth */ + const short core_switching_flag,/* i : core switching flag */ + float *mem_synth /* o : synthesis to overlap */ +) +{ + short i, delta, L_frame_for_cs, decode_bwe; + short d1m, ind1, fdelay, gapsize; + long cbrate; + float synth_intFreq[2*L_SUBFR]; + float old_exc[L_EXC_DEC], *exc; + float tmp_mem2[2*L_FILT48k], gain; + float hb_synth_tmp[NS2SA(48000, 10000000L)]; + const float *hp_filter; + float Aq[2*(M+1)]; + float bpf_error_signal[2*L_SUBFR]; + float *realBuffer[CLDFB_NO_COL_MAX_SWITCH], *imagBuffer[CLDFB_NO_COL_MAX_SWITCH]; + float realBufferTmp[CLDFB_NO_COL_MAX_SWITCH][CLDFB_NO_CHANNELS_MAX], imagBufferTmp[CLDFB_NO_COL_MAX_SWITCH][CLDFB_NO_CHANNELS_MAX]; + + /*----------------------------------------------------------------* + * Initializations + *----------------------------------------------------------------*/ + + /* open CLDFB buffer up to CLDFB_NO_CHANNELS_MAX bands for 48kHz */ + for( i=0; iold_Aq_12_8, Aq, M+1 ); + mvr2r( st->old_Aq_12_8, Aq + (M+1), M+1 ); + + set_f(mem_synth, 0, NS2SA(16000, DELAY_CLDFB_NS)+2 ); + + /* set multiplication factor according to the sampling rate */ + delta = 1; + if( output_frame == L_FRAME32k ) + { + delta = 2; + } + else if( output_frame == L_FRAME48k ) + { + delta = 3; + } + + /*----------------------------------------------------------------* + * set switching frame bit-rate + *----------------------------------------------------------------*/ + + if( core_switching_flag && st->last_L_frame == st->last_L_frame_ori && (st->last_core == ACELP_CORE || st->last_core == AMR_WB_CORE) ) + { + exc = old_exc + L_EXC_MEM_DEC; + mvr2r(st->old_exc, old_exc, L_EXC_MEM_DEC ); + + if( st->last_L_frame == L_FRAME ) + { + if( st->core_brate > ACELP_24k40 ) + { + cbrate = ACELP_24k40; + } + else + { + cbrate = st->core_brate; + } + + L_frame_for_cs = L_FRAME; + } + else + { + if( st->core_brate <= ACELP_8k00 ) + { + cbrate = ACELP_8k00; + } + else if( st->core_brate <= ACELP_14k80 ) + { + cbrate = ACELP_14k80; + } + else + { + cbrate = min(st->core_brate, ACELP_22k60 ); + } + + L_frame_for_cs = L_FRAME16k; + } + + /*----------------------------------------------------------------* + * Excitation decoding + *----------------------------------------------------------------*/ + + decod_gen_voic_core_switch( st, L_frame_for_cs, 0, Aq, GENERIC, exc, cbrate ); + + /*----------------------------------------------------------------* + * synthesis, deemphasis, postprocessing and resampling + *----------------------------------------------------------------*/ + + /* synthesis and deemphasis */ + syn_12k8( 2*L_SUBFR, Aq, exc, synth_intFreq, st->mem_syn2, 1 ); + + if( st->pfstat.on && st->last_bwidth == NB ) + { + float tmp_noise, pitch_buf_tmp[2]; + tmp_noise = 0; + + for( i=0; i<2; i++ ) + { + pitch_buf_tmp[i] = L_SUBFR; + } + + nb_post_filt( 2*L_SUBFR, L_SUBFR, &(st->pfstat), &tmp_noise, 0, synth_intFreq, Aq, pitch_buf_tmp, AUDIO, st->BER_detect, 0 ); + } + + if( L_frame_for_cs == L_FRAME ) + { + deemph( synth_intFreq, PREEMPH_FAC, 2*L_SUBFR, &st->mem_deemph ); + } + else + { + deemph( synth_intFreq, PREEMPH_FAC_16k, 2*L_SUBFR, &st->mem_deemph ); + } + + AGC_dec( synth_intFreq, st->agc_mem2, 2*L_SUBFR ); + + if( st->pfstat.on && st->last_bwidth != NB ) + { + mvr2r( st->pfstat.mem_pf_in+L_SYN_MEM-M, bpf_error_signal, M ); /*bpf_error_signal used as temporary buffer*/ + mvr2r( synth_intFreq, bpf_error_signal+M, L_SUBFR ); + residu( Aq, M, bpf_error_signal+M,old_exc, L_SUBFR ); + syn_filt( Aq, M, old_exc, bpf_error_signal, L_SUBFR, st->pfstat.mem_stp+L_SYN_MEM-M, 0 ); + scale_st( synth_intFreq, bpf_error_signal, &st->pfstat.gain_prec, L_SUBFR, -1 ); + mvr2r( bpf_error_signal, synth_intFreq, L_SUBFR/2 ); + blend_subfr2( bpf_error_signal + L_SUBFR/2, synth_intFreq + L_SUBFR/2, synth_intFreq + L_SUBFR/2 ); + } + st->pfstat.on = 0; + + if( st->flag_cna ) + { + generate_masking_noise( synth_intFreq, st->hFdCngDec->hFdCngCom, 2*L_SUBFR, 0 ); + } + + /*----------------------------------------------------------------* + * Resample to the output sampling rate (8/16/32/48 kHz) + * Bass post-filter + *----------------------------------------------------------------*/ + + /* bass post-filter */ + bass_psfilter( st->Opt_AMR_WB, synth_intFreq, 2*L_SUBFR, NULL, st->pst_old_syn, + &st->pst_mem_deemp_err, &st->pst_lp_ener, st->bpf_off, st->stab_fac, &st->stab_fac_smooth, + st->mem_mean_pit, st->Track_on_hist, st->vibrato_hist, &st->psf_att, GENERIC, bpf_error_signal ); + + /* CLDFB analysis of the synthesis at internal sampling rate */ + cldfb_save_memory( st->cldfbAna ); + cldfbAnalysis( synth_intFreq, realBuffer, imagBuffer, NS2SA(50*L_frame_for_cs, SWITCH_GAP_LENGTH_NS+DELAY_CLDFB_NS), st->cldfbAna ); + cldfb_restore_memory( st->cldfbAna ); + + /* CLDFB analysis and add the BPF error signal */ + cldfb_save_memory( st->cldfbBPF ); + addBassPostFilter( bpf_error_signal, st->bpf_off?0:NS2SA(50*L_frame_for_cs, SWITCH_GAP_LENGTH_NS+DELAY_CLDFB_NS), realBuffer, imagBuffer, st->cldfbBPF ); + cldfb_restore_memory( st->cldfbBPF ); + + /* CLDFB synthesis of the combined signal */ + cldfb_save_memory( st->cldfbSyn ); + cldfbSynthesis( realBuffer, imagBuffer, synth_subfr_out, NS2SA(st->output_Fs, SWITCH_GAP_LENGTH_NS+DELAY_CLDFB_NS), st->cldfbSyn ); + cldfb_restore_memory( st->cldfbSyn ); + + mvr2r( synth_intFreq + NS2SA(L_frame_for_cs * 50, SWITCH_GAP_LENGTH_NS-DELAY_CLDFB_NS)-2, mem_synth, NS2SA(L_frame_for_cs * 50, DELAY_CLDFB_NS)+2 ); /* need for switching (-2 is due to 0 delay filtering) */ + + /*----------------------------------------------------------------* + * BWE decoding + *----------------------------------------------------------------*/ + + decode_bwe = 0; + if( !((inner_frame_tbl[st->bwidth] == L_FRAME16k && st->last_L_frame == L_FRAME16k) || inner_frame_tbl[st->bwidth] == L_FRAME8k) ) + { + /* Decoding of BWE */ + d1m = (short)get_next_indice(st, AUDIODELAYBITS); + ind1 = (short)get_next_indice(st, NOOFGAINBITS1); + gain = usdequant( ind1, MINVALUEOFFIRSTGAIN, DELTAOFFIRSTGAIN ); + decode_bwe = 1; + } + + + + if( decode_bwe && !((output_frame == L_FRAME16k && st->last_L_frame == L_FRAME16k) || output_frame == L_FRAME8k) ) + { + set_f( tmp_mem2, 0, 2*L_FILT48k ); + + hp_filter = hp16000_48000; + fdelay = 48; + if( st->output_Fs == 16000 ) + { + if( st->last_L_frame == L_FRAME ) + { + hp_filter = hp12800_16000; + fdelay = 20; + } + } + else if( st->output_Fs == 32000 ) + { + + if( st->last_L_frame == L_FRAME ) + { + hp_filter = hp12800_32000; + fdelay = 40; + } + else + { + hp_filter = hp16000_32000; + fdelay = 32; + } + } + else if( st->last_L_frame == L_FRAME ) + { + hp_filter = hp12800_48000; + fdelay = 60; + } + + /* safety check in case of bit errors */ + i = MAX_D1M_16k; + if( st->last_L_frame == L_FRAME ) + { + i = MAX_D1M_12k8; + } + + if( d1m >= i ) + { + d1m = i - 1; + gain = 0; /* force muting */ + st->BER_detect = 1; + } + + i = NS2SA(st->output_Fs, FRAME_SIZE_NS-ACELP_LOOK_NS-DELAY_BWE_TOTAL_NS); + mvr2r( st->old_synth_sw, hb_synth_tmp, i ); + set_f( hb_synth_tmp + i, 0, NS2SA(st->output_Fs, 10000000L) - i ); + fir( hb_synth_tmp, hp_filter, hb_synth_tmp, tmp_mem2, output_frame>>1, fdelay, 0 ); /* put the 40 past samples into the memory */ + set_f( tmp_synth_bwe, 0, SWITCH_MAX_GAP ); + + gapsize = delta * (NS2SA(16000,SWITCH_GAP_LENGTH_NS)); + for( i=0; iHQ switching frame in case of BAD frame + *-------------------------------------------------------------------*/ + +void acelp_core_switch_dec_bfi( + Decoder_State *st, /* i/o: decoder state structure */ + float synth_out[], /* o : synthesis */ + const short coder_type /* i : coder type */ +) +{ + short i; + float old_exc[L_EXC_DEC], *exc; /* excitation signal buffer */ + float syn[L_FRAME16k]; /* synthesis signal buffer */ + float lsf_new[M]; /* LSFs at the end of the frame */ + float lsp_new[M]; /* LSPs at the end of the frame */ + float Aq[NB_SUBFR16k*(M+1)]; /* A(q) quantized for the 4 subframes */ + float old_exc2[L_FRAME16k + L_EXC_MEM], *exc2; /* total excitation buffer */ + float tmp_noise; /* Long term temporary noise energy */ + float FEC_pitch; /* FEC pitch */ + float old_bwe_exc[((PIT16k_MAX + (L_FRAME16k+1) + L_SUBFR16k) * 2)]; /* excitation buffer */ + float *bwe_exc; /* Excitation for SWB TBE */ + float tmp_float[NBPSF_PIT_MAX]; + float tmp_float2[M]; + float tmp_float3; + float tmp_float4[L_TRACK_HIST]; + short tmp_float5[L_TRACK_HIST]; + short tmp_float6[L_TRACK_HIST]; + float tmp_float7; + float voice_factors[NB_SUBFR16k]; + float pitch_buf[NB_SUBFR16k]; + float *realBuffer[CLDFB_NO_COL_MAX_SWITCH_BFI], *imagBuffer[CLDFB_NO_COL_MAX_SWITCH_BFI]; + float realBufferTmp[CLDFB_NO_COL_MAX_SWITCH_BFI][CLDFB_NO_CHANNELS_MAX], imagBufferTmp[CLDFB_NO_COL_MAX_SWITCH_BFI][CLDFB_NO_CHANNELS_MAX]; + + /*----------------------------------------------------------------* + * Initialization + *----------------------------------------------------------------*/ + + /* initialize CLDFB buffer up to CLDFB_NO_CHANNELS_MAX bands for 48kHz */ + for( i=0; ibpf_off = 1; + st->clas_dec = st->last_good; + tmp_noise = 0.0f; + + mvr2r( st->old_exc, old_exc, L_EXC_MEM_DEC ); + exc = old_exc + L_EXC_MEM_DEC; + mvr2r( st->old_exc2, old_exc2, L_EXC_MEM ); + exc2 = old_exc2 + L_EXC_MEM; + mvr2r( st->old_bwe_exc, old_bwe_exc, PIT16k_MAX * 2); + bwe_exc = old_bwe_exc + PIT16k_MAX * 2; + st->GSC_noisy_speech = 0; + st->relax_prev_lsf_interp = 0; + + /* SC-VBR */ + if( st->last_nelp_mode_dec == 1 ) + { + st->nelp_mode_dec = 1; + } + + mvr2r( st->mem_AR, tmp_float, M ); + mvr2r( st->mem_MA, tmp_float2, M ); + + /* LSF estimation and A(z) calculation */ + lsf_dec_bfi( MODE1, lsf_new, st->lsf_old, st->lsf_adaptive_mean, NULL, st->mem_MA, st->mem_AR, + st->stab_fac, st->last_coder_type, st->L_frame, st->last_good, + st->nbLostCmpt, 0, NULL, NULL, NULL, st->Last_GSC_pit_band_idx, st->Opt_AMR_WB, st->bwidth ); + + FEC_lsf2lsp_interp( st, st->L_frame, Aq, lsf_new, lsp_new ); + + mvr2r( tmp_float, st->mem_AR, M ); + mvr2r( tmp_float2, st->mem_MA, M ); + + /*----------------------------------------------------------------* + * Excitation decoding + *----------------------------------------------------------------*/ + + if( st->nelp_mode_dec == 1 ) + { + /* SC-VBR */ + decod_nelp( st, coder_type, &tmp_noise, pitch_buf, exc, exc2, voice_factors, bwe_exc, st->bfi, tmp_float2 ); + FEC_pitch = pitch_buf[3]; + } + else + { + tmp_float[0] = st->bfi_pitch; + tmp_float[1] = (float)st->bfi_pitch_frame; + tmp_float[2] = st->lp_gainp; + tmp_float[3] = st->lp_gainc; + tmp_float[4] = st->upd_cnt; + tmp_float[5] = st->seed; + + /* calculation of excitation signal */ + FEC_exc_estim( st, st->L_frame, exc, exc2, syn /* dummy buffer */, pitch_buf, voice_factors, &FEC_pitch, bwe_exc, lsf_new, &tmp_noise ); + + st->seed = (short)tmp_float[5]; + st->bfi_pitch = tmp_float[0]; + st->bfi_pitch_frame = (short)tmp_float[1]; + st->lp_gainp = tmp_float[2]; + st->lp_gainc = tmp_float[3]; + st->upd_cnt = (short)tmp_float[4]; + } + + /*------------------------------------------------------------------* + * Synthesis + *-----------------------------------------------------------------*/ + + mvr2r( st->mem_syn2, tmp_float, M ); + syn_12k8( st->L_frame, Aq, exc2, syn, tmp_float, 1 ); + + tmp_float[0] = st->enr_old; + fer_energy( st->L_frame, st->last_good, syn, FEC_pitch, tmp_float, st->L_frame ); + + /*------------------------------------------------------------------* + * Perform fixed deemphasis through 1/(1 - g*z^-1) + *-----------------------------------------------------------------*/ + + mvr2r( &(st->mem_deemph), tmp_float, 1 ); + if( st->L_frame == L_FRAME ) + { + deemph( syn, PREEMPH_FAC, L_FRAME, tmp_float ); + } + else + { + deemph( syn, PREEMPH_FAC_16k, L_FRAME16k, tmp_float ); + } + + /*----------------------------------------------------------------* + * Bass post-filter + *----------------------------------------------------------------*/ + + st->bpf_off = 1; + mvr2r( st->pst_old_syn, tmp_float, NBPSF_PIT_MAX ); + tmp_float3 = st->stab_fac_smooth; + mvr2r( st->mem_mean_pit, tmp_float4, L_TRACK_HIST ); + mvs2s( st->Track_on_hist, tmp_float5, L_TRACK_HIST ); + mvs2s( st->vibrato_hist, tmp_float6, L_TRACK_HIST ); + tmp_float7 = st->psf_att; + + /* apply bass post-filter */ + bass_psfilter( st->Opt_AMR_WB, syn, st->L_frame, pitch_buf, tmp_float, &st->pst_mem_deemp_err, &st->pst_lp_ener, st->bpf_off, + st->stab_fac, &tmp_float3, tmp_float4, tmp_float5, tmp_float6, &tmp_float7, coder_type, old_exc /* tmp buffer */ ); + + /*----------------------------------------------------------------* + * Resampling to the output sampling frequency + *----------------------------------------------------------------*/ + + /* CLDFB analysis of the synthesis at internal sampling rate */ + cldfb_save_memory( st->cldfbAna ); + cldfbAnalysis ( syn, realBuffer, imagBuffer, st->L_frame/2, st->cldfbAna ); + cldfb_restore_memory( st->cldfbAna ); + + /* CLDFB synthesis of the combined signal */ + cldfb_save_memory( st->cldfbSyn ); + cldfbSynthesis ( realBuffer, imagBuffer, synth_out, st->output_Fs*0.01, st->cldfbSyn ); + cldfb_restore_memory( st->cldfbSyn ); + + return; +} + + +/*-------------------------------------------------------------------* + * decod_gen_voic_core_switch() + * + * Decode excitation signal in teh first ACELP->HQ switching frame + *-------------------------------------------------------------------*/ + +static void decod_gen_voic_core_switch( + Decoder_State *st, /* i/o: decoder static memory */ + const short L_frame, /* i : length of the frame */ + const short sharpFlag, /* i : flag for formant sharpening */ + const float *Aq, /* i : LP filter coefficient */ + const short coder_type, /* i : coding type */ + float *exc, /* i/o: adapt. excitation exc */ + const long core_brate /* i : switching frame bit-rate */ +) +{ + short T0, T0_frac, T0_min, T0_max;/* integer pitch variables */ + float gain_pit; /* pitch gain */ + float gain_code; /* gain/normalized gain of the algebraic excitation */ + float norm_gain_code; /* normalized gain of the algebraic excitation */ + float gain_inov; /* Innovation gain */ + float voice_fac; /* voicing factor */ + float code[L_SUBFR]; /* algebraic codevector */ + float pitch; /* pointer to floating pitch */ + short i; /* tmp variables */ + short pitch_limit_flag; + float tmpF; + + /* initializations */ + if( L_frame == L_FRAME ) + { + T0_max = PIT_MAX; + T0_min = PIT_MIN; + } + else /* L_frame == L_FRAME16k */ + { + T0_max = PIT16k_MAX; + T0_min = PIT16k_MIN; + } + + /*----------------------------------------------------------------------* + * Decode pitch lag + *----------------------------------------------------------------------*/ + + pitch = pit_decode( st, core_brate, 0, L_frame, 0, coder_type, &pitch_limit_flag, &T0, &T0_frac, &T0_min, &T0_max, L_SUBFR ); + + /*--------------------------------------------------------------* + * Find the adaptive codebook vector. + *--------------------------------------------------------------*/ + + pred_lt4( &exc[0], &exc[0], T0, T0_frac, L_SUBFR+1, inter4_2, L_INTERPOL2, PIT_UP_SAMP ); + + /*--------------------------------------------------------------* + * LP filtering of the adaptive excitation + *--------------------------------------------------------------*/ + + lp_filt_exc_dec( st, MODE1, core_brate,0, coder_type, 0, L_SUBFR, L_frame, 0, exc ); + + /*--------------------------------------------------------------* + * Innovation decoding + *--------------------------------------------------------------*/ + + inov_decode( st, core_brate, 0, L_frame, coder_type, sharpFlag, 0, -1, Aq, st->tilt_code, pitch, code ); + + /*--------------------------------------------------------------* + * Gain decoding + * Estimate spectrum tilt and voicing + *--------------------------------------------------------------*/ + + if( L_frame == L_FRAME ) + { + gain_dec_mless( st, core_brate, L_frame, TRANSITION, 0, -1, code, st->old_Es_pred, &gain_pit, &gain_code, &gain_inov, &norm_gain_code ); + } + else + { + gain_dec_mless( st, core_brate, L_frame, coder_type, 0, -1, code, st->old_Es_pred, &gain_pit, &gain_code, &gain_inov, &norm_gain_code ); + } + + st->tilt_code = est_tilt( exc, gain_pit, code, gain_code, &voice_fac, L_SUBFR, 0 ); + + /*----------------------------------------------------------------------* + * Find the total excitation + *----------------------------------------------------------------------*/ + + if( st->prev_bfi ) + { + gain_code = min( gain_code, 0.5f*gain_code+0.5f*st->lp_gainc ); + } + + for( i = 0; i < L_SUBFR; i++ ) + { + tmpF = gain_pit * exc[i]; + exc[i] = tmpF + gain_code * code[i]; + } + + /*-----------------------------------------------------------------* + * long term prediction on the 2nd sub frame + *-----------------------------------------------------------------*/ + + pred_lt4( &exc[L_SUBFR], &exc[L_SUBFR], T0, T0_frac, L_SUBFR+1, inter4_2, L_INTERPOL2, PIT_UP_SAMP ); + + for( i = 0; i < L_SUBFR; i++ ) + { + exc[i+L_SUBFR] *= gain_pit; + } + + return; +} diff --git a/src/libs/libevs/lib_dec/acelp_core_switch_dec_fx.cpp b/src/libs/libevs/lib_dec/acelp_core_switch_dec_fx.cpp deleted file mode 100755 index 1d99e38b..00000000 --- a/src/libs/libevs/lib_dec/acelp_core_switch_dec_fx.cpp +++ /dev/null @@ -1,677 +0,0 @@ -/*==================================================================================== - EVS Codec 3GPP TS26.442 Apr 03, 2018. Version 12.11.0 / 13.6.0 / 14.2.0 - ====================================================================================*/ - -#include -#include "options.h" /* Compilation switches */ -#include "cnst_fx.h" /* Common constants */ -#include "rom_com_fx.h" /* Static table prototypes */ -#include "prot_fx.h" /* Function prototypes */ -#include "stl.h" /* required for wmc_tool */ - -/*---------------------------------------------------------------------* -* Local functions -*---------------------------------------------------------------------*/ - -static void decod_gen_voic_core_switch_fx( Decoder_State_fx *st_fx, const Word16 L_frame, const Word16 sharpFlag, const Word16 *Aq, const Word16 coder_type, - Word16 *exc, const Word32 core_brate, Word16 *Q_exc ); - -/*-------------------------------------------------------------------* -* acelp_core_switch_dec() -* -* ACELP core decoder in the first ACELP->HQ switching frame -*-------------------------------------------------------------------*/ - -void acelp_core_switch_dec_fx( - Decoder_State_fx *st_fx, /* i/o: decoder state structure */ - Word16 *synth_subfr_out, /* o : synthesized ACELP subframe Q_syn*/ - Word16 *tmp_synth_bwe, /* o : synthesized ACELP subframe BWE Q_syn*/ - const Word16 output_frame, /* i : input frame length */ - const Word16 core_switching_flag, /* i : core switching flag */ - Word16 *mem_synth, /* o : synthesis to overlap */ - Word16 *Q_syn -) -{ - Word16 i, delta, L_frame_for_cs, decode_bwe, tmp; - Word16 d1m, ind1, fdelay, gapsize; - Word32 cbrate; - Word16 synth_intFreq[2*L_SUBFR]; - CLDFB_SCALE_FACTOR scaleFactor; - Word32 workBuffer[128*3]; - Word16 old_exc[L_EXC_DEC], *exc; - Word16 tmp_mem2[2*L_FILT48k], gain; - Word16 hb_synth_tmp[NS2SA(48000,10000000)]; - const Word16 *hp_filter; - Word16 Aq[2*(M+1)]; - Word16 bpf_error_signal[2*L_SUBFR]; - Word16 *pt1, *pt2; - Word16 syn_fx_tmp[L_FRAME_16k]; - Word32 *realBuffer[CLDFB_NO_COL_MAX_SWITCH], *imagBuffer[CLDFB_NO_COL_MAX_SWITCH]; - Word32 realBufferTmp[CLDFB_NO_COL_MAX_SWITCH][CLDFB_NO_CHANNELS_MAX], imagBufferTmp[CLDFB_NO_COL_MAX_SWITCH][CLDFB_NO_CHANNELS_MAX]; - - FOR( i=0; iold_Aq_12_8_fx, Aq, M+1 ); - Copy( st_fx->old_Aq_12_8_fx, Aq + (M+1), M+1 ); - - set16_fx( mem_synth, 0, NS2SA(16000, DELAY_CLDFB_NS)+2 ); - set16_fx( synth_subfr_out, 0, SWITCH_MAX_GAP ); /* avoid valgrind complaining about uninitialized memory in core_switching_OLA_fx() */ - - /* set multiplication factor according to the sampling rate */ - delta = 1; - if( sub(output_frame, L_FRAME16k) > 0 ) - { - delta = shr(output_frame,8); - } - - /*----------------------------------------------------------------* - * set switching frame bit-rate - *----------------------------------------------------------------*/ - - test(); - test(); - test(); - IF( core_switching_flag && sub(st_fx->last_L_frame_fx, st_fx->last_L_frame_ori_fx) == 0 && ( (sub(st_fx->last_core_fx, ACELP_CORE) == 0) || (sub(st_fx->last_core_fx, AMR_WB_CORE) == 0) ) ) - { - exc = old_exc + L_EXC_MEM_DEC; - Copy( st_fx->old_exc_fx, old_exc, L_EXC_MEM_DEC ); /*scaling of exc from previous frame*/ - - IF( sub(st_fx->last_L_frame_fx, L_FRAME) == 0 ) - { - cbrate = L_add(st_fx->core_brate_fx, 0); - if( L_sub(cbrate, ACELP_24k40) > 0 ) - { - cbrate = L_add(ACELP_24k40, 0); - } - - L_frame_for_cs = L_FRAME; - move16(); - } - ELSE - { - IF( L_sub(st_fx->core_brate_fx, ACELP_8k00) <= 0 ) - { - cbrate = L_add(ACELP_8k00, 0); - } - ELSE IF( L_sub(st_fx->core_brate_fx, ACELP_14k80) <= 0 ) - { - cbrate = L_add(ACELP_14k80, 0); - } - ELSE - { - cbrate = L_min(st_fx->core_brate_fx, ACELP_22k60 ); - } - - L_frame_for_cs = L_FRAME16k; - move16(); - } - - /*----------------------------------------------------------------* - * Excitation decoding - *----------------------------------------------------------------*/ - - decod_gen_voic_core_switch_fx( st_fx, L_frame_for_cs, 0, Aq, GENERIC, exc, cbrate, &st_fx->Q_exc ); - - /*----------------------------------------------------------------* - * synthesis, deemphasis, postprocessing and resampling - *----------------------------------------------------------------*/ - - /* Core synthesis at 12.8kHz or 16kHz */ - Rescale_mem( st_fx->Q_exc, &st_fx->prev_Q_syn, &st_fx->Q_syn, st_fx->mem_syn2_fx, st_fx->mem_syn_clas_estim_fx, - 4, &st_fx->mem_deemph_fx, st_fx->pst_old_syn_fx, &st_fx->pst_mem_deemp_err_fx,&st_fx->agc_mem_fx[1], &st_fx->pfstat , 1, 0, NULL ); - - syn_12k8_fx( 2*L_SUBFR, Aq, exc, synth_intFreq, st_fx->mem_syn2_fx, 1, st_fx->Q_exc, st_fx->Q_syn ); - - IF(st_fx->pfstat.on && (sub(st_fx->last_bwidth_fx,NB) == 0)) - { - Word16 tmp_noise, pitch_buf_tmp[2]; - tmp_noise = 0; - FOR( i=0; i<2; i++ ) - { - pitch_buf_tmp[i] = L_SUBFR; - move16(); - } - nb_post_filt( 2*L_SUBFR, &(st_fx->pfstat), &tmp_noise, 0, synth_intFreq, Aq, pitch_buf_tmp, AUDIO, st_fx->BER_detect, 0 ); - } - - IF( sub(L_frame_for_cs,L_FRAME)==0 ) - { - deemph_fx( synth_intFreq, PREEMPH_FAC, 2*L_SUBFR, &(st_fx->mem_deemph_fx) ); - } - ELSE - { - deemph_fx( synth_intFreq, PREEMPH_FAC_16k, 2*L_SUBFR, &(st_fx->mem_deemph_fx) ); - } - - unscale_AGC( synth_intFreq, st_fx->Q_syn, syn_fx_tmp+M, st_fx->agc_mem_fx, 2*L_SUBFR ); - Copy( syn_fx_tmp+M, synth_intFreq, 2*L_SUBFR ); - - test(); - IF( st_fx->pfstat.on && (sub(st_fx->last_bwidth_fx,NB) != 0) ) - { - Copy( st_fx->pfstat.mem_pf_in+L_SYN_MEM-M, bpf_error_signal, M ); - Copy( synth_intFreq, bpf_error_signal + M, L_SUBFR ); - Residu3_fx ( Aq, bpf_error_signal + M, exc, L_SUBFR, 1 ); - E_UTIL_synthesis ( 1, Aq, exc, bpf_error_signal, L_SUBFR, st_fx->pfstat.mem_stp+L_SYN_MEM-M, 0, M ); - scale_st ( synth_intFreq, bpf_error_signal, &st_fx->pfstat.gain_prec, L_SUBFR ); - Copy( bpf_error_signal, synth_intFreq, L_SUBFR/2 ); - blend_subfr2( bpf_error_signal + L_SUBFR/2, synth_intFreq + L_SUBFR/2, synth_intFreq + L_SUBFR/2 ); - } - st_fx->pfstat.on = 0; - move16(); - - IF ( st_fx->flag_cna != 0 ) - { - generate_masking_noise( synth_intFreq, st_fx->Q_syn, st_fx->hFdCngDec_fx->hFdCngCom, 2*L_SUBFR, 0); - } - - /*----------------------------------------------------------------* - * Resample to the output sampling rate (8/16/32/48 kHz) - * Bass post-filter - *----------------------------------------------------------------*/ - - bass_psfilter_fx( st_fx->Opt_AMR_WB_fx, synth_intFreq, 2*L_SUBFR, NULL, st_fx->pst_old_syn_fx, - &st_fx->pst_mem_deemp_err_fx, &st_fx->pst_lp_ener_fx, st_fx->bpf_off_fx, st_fx->stab_fac_fx, &st_fx->stab_fac_smooth_fx, - st_fx->mem_mean_pit_fx, st_fx->Track_on_hist_fx, st_fx->vibrato_hist_fx, &st_fx->psf_att_fx, GENERIC, - st_fx->Q_syn, bpf_error_signal ); - - cldfb_save_memory( st_fx->cldfbAna_fx ); - cldfbAnalysisFiltering( st_fx->cldfbAna_fx, realBuffer, imagBuffer, &scaleFactor, synth_intFreq, - negate(st_fx->Q_syn), CLDFB_NO_COL_MAX_SWITCH, workBuffer); - cldfb_restore_memory( st_fx->cldfbAna_fx ); - - /* CLDFB synthesis of the combined signal */ - scaleFactor.hb_scale = scaleFactor.lb_scale; - move16(); - - /* CLDFB analysis and add the BPF error signal */ - cldfb_save_memory( st_fx->cldfbBPF_fx ); - i = 0; - move16(); - if( st_fx->bpf_off_fx == 0 ) - { - i = CLDFB_NO_COL_MAX_SWITCH; - move16(); - } - addBassPostFilterFx( bpf_error_signal, realBuffer, imagBuffer, st_fx->cldfbBPF_fx, workBuffer, negate(st_fx->Q_syn), - i, CLDFB_NO_COL_MAX_SWITCH, st_fx->cldfbAna_fx->no_channels, &scaleFactor ); - cldfb_restore_memory( st_fx->cldfbBPF_fx ); - - /* CLDFB synthesis of the combined signal */ - scaleFactor.hb_scale = scaleFactor.lb_scale; - - cldfb_save_memory( st_fx->cldfbSyn_fx ); - cldfbSynthesisFiltering(st_fx->cldfbSyn_fx, realBuffer, imagBuffer, &scaleFactor, synth_subfr_out, 0, CLDFB_NO_COL_MAX_SWITCH, workBuffer); - cldfb_restore_memory( st_fx->cldfbSyn_fx ); - *Q_syn = 0; - move16(); - - Copy_Scale_sig( synth_intFreq+ NS2SA(L_frame_for_cs * 50, SWITCH_GAP_LENGTH_NS-DELAY_CLDFB_NS)-2, mem_synth, NS2SA(L_frame_for_cs * 50, DELAY_CLDFB_NS)+2, negate(st_fx->Q_syn) ); /* Copy mem with Q0 */ - - /*----------------------------------------------------------------* - * BWE decoding - *----------------------------------------------------------------*/ - - decode_bwe = 0; - move16(); - test(); - test(); - IF( !(( sub(inner_frame_tbl[st_fx->bwidth_fx], L_FRAME16k) == 0 && sub(st_fx->last_L_frame_fx, L_FRAME16k) == 0) || sub(inner_frame_tbl[st_fx->bwidth_fx], L_FRAME8k) == 0) ) - { - /* Decoding of BWE */ - d1m = (Word16)get_next_indice_fx(st_fx, AUDIODELAYBITS); - ind1 = (Word16)get_next_indice_fx(st_fx, NOOFGAINBITS1); - gain = usdequant_fx( ind1, MINVALUEOFFIRSTGAIN_FX, shr(DELTAOFFIRSTGAIN_FX,3) ); /*Q13*/ - decode_bwe = 1; - move16(); - } - - test(); - test(); - test(); - IF( decode_bwe && !(( sub(output_frame, L_FRAME16k) == 0 && sub(st_fx->last_L_frame_fx, L_FRAME16k) == 0) || sub(output_frame, L_FRAME8k) == 0) ) - { - set16_fx( tmp_mem2, 0, 2*L_FILT48k ); - - hp_filter = hp16000_48000_fx; - fdelay = 48; - move16(); - IF ( L_sub(st_fx->output_Fs_fx, 16000) == 0 ) - { - IF( sub(st_fx->last_L_frame_fx, L_FRAME) == 0 ) - { - hp_filter = hp12800_16000_fx; - fdelay = 20; - move16(); - } - } - ELSE IF( L_sub(st_fx->output_Fs_fx, 32000) == 0 ) - { - IF( sub(st_fx->last_L_frame_fx, L_FRAME) == 0 ) - { - hp_filter = hp12800_32000_fx; - fdelay = 40; - move16(); - } - ELSE - { - hp_filter = hp16000_32000_fx; - fdelay = 32; - move16(); - } - } - ELSE IF( sub(st_fx->last_L_frame_fx, L_FRAME) == 0 ) - { - hp_filter = hp12800_48000_fx; - fdelay = 60; - move16(); - } - - /* safety check in case of bit errors */ - i = MAX_D1M_16k; - move16(); - if( sub(st_fx->last_L_frame_fx,L_FRAME) == 0 ) - { - i = MAX_D1M_12k8; - move16(); - } - - IF( sub(d1m,i) >= 0 ) - { - d1m = sub(i,1); - gain = 0; /* force muting */ move16(); - st_fx->BER_detect = 1; - move16(); - } - - i = NS2SA_fx2(st_fx->output_Fs_fx, FRAME_SIZE_NS-ACELP_LOOK_NS-DELAY_BWE_TOTAL_NS); - move16(); - Copy( st_fx->old_synth_sw_fx, hb_synth_tmp, i ); - set16_fx( hb_synth_tmp + i, 0, NS2SA_fx2(st_fx->output_Fs_fx, 10000000L) - i ); - fir_fx( hb_synth_tmp, hp_filter, hb_synth_tmp, tmp_mem2, shr(output_frame,1), fdelay, 1, 0 ); - - set16_fx( tmp_synth_bwe, 0, SWITCH_MAX_GAP ); - - gapsize = i_mult2(delta, (NS2SA(16000,SWITCH_GAP_LENGTH_NS))); - - pt1 = tmp_synth_bwe; - tmp = add(i_mult(d1m,delta),fdelay); - pt2 = &hb_synth_tmp[tmp]; - FOR( i=0; iHQ switching frame in case of BAD frame -*-------------------------------------------------------------------*/ - -void acelp_core_switch_dec_bfi_fx( - Decoder_State_fx *st_fx, /* i/o: decoder state structure */ - Word16 synth_out[], /* o : synthesis Q_syn */ - const Word16 coder_type /* i : coder type */ -) -{ - Word16 old_exc[L_EXC_DEC], *exc; /* excitation signal buffer */ - Word16 syn[L_FRAME16k]; /* synthesis signal buffer */ - Word16 lsf_new[M]; /* LSFs at the end of the frame */ - Word16 lsp_new[M]; /* LSPs at the end of the frame */ - Word16 Aq[NB_SUBFR16k*(M+1)]; /* A(q) quantized for the 4 subframes */ - Word16 old_exc2[L_FRAME16k + L_EXC_MEM], *exc2; /* total excitation buffer */ - Word16 tmp_noise; /* Long term temporary noise energy */ - Word16 FEC_pitch; /* FEC pitch */ - Word16 old_bwe_exc[((PIT16k_MAX + (L_FRAME16k+1) + L_SUBFR16k) * 2)]; /* excitation buffer */ - Word16 *bwe_exc; /* Excitation for SWB TBE */ - Word16 tmp_float[NBPSF_PIT_MAX]; - Word16 tmp_float2[M]; - Word16 tmp_float3; - Word16 tmp_float4[L_TRACK_HIST]; - Word16 tmp_float5[L_TRACK_HIST]; - Word16 tmp_float6[L_TRACK_HIST]; - Word16 tmp_float7; - Word32 tmp_float32; - Word16 voice_factors[NB_SUBFR16k]; - Word16 pitch_buf[NB_SUBFR16k]; - Word16 Q_exc; - Word32 *realBuffer[CLDFB_NO_COL_MAX_SWITCH_BFI], *imagBuffer[CLDFB_NO_COL_MAX_SWITCH_BFI]; - Word32 realBufferTmp[CLDFB_NO_COL_MAX_SWITCH_BFI][CLDFB_NO_CHANNELS_MAX], imagBufferTmp[CLDFB_NO_COL_MAX_SWITCH_BFI][CLDFB_NO_CHANNELS_MAX]; - Word16 i; - CLDFB_SCALE_FACTOR scaleFactor; - Word32 workBuffer[128*3]; - - FOR( i=0; iQ_exc; - move16(); - st_fx->bpf_off_fx = 1; - move16(); - st_fx->clas_dec = st_fx->last_good_fx; - move16(); - tmp_noise = 0; - move16(); - - Copy( st_fx->old_exc_fx, old_exc, L_EXC_MEM_DEC ); - exc = old_exc + L_EXC_MEM_DEC; - Copy( st_fx->old_exc2_fx, old_exc2, L_EXC_MEM ); - exc2 = old_exc2 + L_EXC_MEM; - Copy( st_fx->old_bwe_exc_fx, old_bwe_exc, PIT16k_MAX * 2); - bwe_exc = old_bwe_exc + PIT16k_MAX * 2; - st_fx->GSC_noisy_speech_fx = 0; - move16(); - st_fx->relax_prev_lsf_interp_fx = 0; - move16(); - - /* SC-VBR */ - if( sub(st_fx->last_nelp_mode_dec_fx, 1) == 0 ) - { - st_fx->nelp_mode_dec_fx = 1; - move16(); - } - - Copy(st_fx->mem_AR_fx,tmp_float,M); - Copy(st_fx->mem_MA_fx,tmp_float2,M); - - /* LSF estimation and A(z) calculation */ - lsf_dec_bfi( MODE1, lsf_new, st_fx->lsf_old_fx, st_fx->lsf_adaptive_mean_fx, NULL, st_fx->mem_MA_fx, st_fx->mem_AR_fx, - st_fx->stab_fac_fx, st_fx->last_coder_type_fx, st_fx->L_frame_fx, st_fx->last_good_fx, - st_fx->nbLostCmpt, 0, NULL, NULL, NULL, st_fx->Last_GSC_pit_band_idx_fx, st_fx->Opt_AMR_WB_fx, 0, st_fx->bwidth_fx); - - FEC_lsf2lsp_interp( st_fx, st_fx->L_frame_fx, Aq, lsf_new, lsp_new); - - Copy( tmp_float, st_fx->mem_AR_fx, M ); - Copy( tmp_float2, st_fx->mem_MA_fx, M ); - - /*----------------------------------------------------------------* - * Excitation decoding - *----------------------------------------------------------------*/ - - IF( sub(st_fx->nelp_mode_dec_fx, 1) == 0 ) - { - Word16 gain_buf[NB_SUBFR16k]; - Scale_sig(exc-L_EXC_MEM, L_EXC_MEM, -st_fx->Q_exc); - st_fx->Q_exc = 0; - /* SC-VBR */ - decod_nelp_fx( st_fx, coder_type, &tmp_noise, pitch_buf, exc, exc2, voice_factors, bwe_exc, &Q_exc, st_fx->bfi_fx, gain_buf ); - FEC_pitch = pitch_buf[3]; - move16(); - Rescale_exc( st_fx->dct_post_old_exc_fx, exc, NULL, st_fx->last_exc_dct_in_fx, L_FRAME, 0, (Word32)0, &Q_exc, st_fx->Q_subfr, exc2, L_FRAME, coder_type); - st_fx->Q_exc = Q_exc; - } - ELSE - { - tmp_float[0] = st_fx->bfi_pitch_fx; - move16(); - tmp_float[1] = st_fx->bfi_pitch_frame_fx; - move16(); - tmp_float[2] = st_fx->lp_gainp_fx; - move16(); - tmp_float[3] = st_fx->lp_gainc_fx; - move16(); - tmp_float[4] = st_fx->upd_cnt_fx; - move16(); - tmp_float[5] = st_fx->seed_fx; - move16(); - - /* calculation of excitation signal */ - FEC_exc_estim_fx( st_fx, st_fx->L_frame_fx, exc, exc2, syn /* dummy buffer */, pitch_buf, voice_factors, &FEC_pitch, bwe_exc, lsf_new, &Q_exc, &tmp_noise ); - Rescale_exc( NULL, exc, bwe_exc, st_fx->last_exc_dct_in_fx, st_fx->L_frame_fx, L_FRAME32k, (Word32)0, - &Q_exc, st_fx->Q_subfr, exc2, st_fx->L_frame_fx, st_fx->last_coder_type_fx); - st_fx->seed_fx = tmp_float[5]; - move16(); - st_fx->bfi_pitch_fx = tmp_float[0]; - move16(); - st_fx->bfi_pitch_frame_fx = tmp_float[1]; - move16(); - st_fx->lp_gainp_fx = tmp_float[2]; - move16(); - st_fx->lp_gainc_fx = tmp_float[3]; - move16(); - st_fx->upd_cnt_fx = tmp_float[4]; - move16(); - } - - /*------------------------------------------------------------------* - * Synthesis - *-----------------------------------------------------------------*/ - - Rescale_mem( Q_exc, &st_fx->prev_Q_syn, &st_fx->Q_syn, st_fx->mem_syn2_fx, st_fx->mem_syn_clas_estim_fx, 4, &st_fx->mem_deemph_fx, - st_fx->pst_old_syn_fx, &st_fx->pst_mem_deemp_err_fx, &st_fx->agc_mem_fx[1], &st_fx->pfstat, 1, 0, NULL ); - Copy( st_fx->mem_syn2_fx,tmp_float,M); - syn_12k8_fx( st_fx->L_frame_fx, Aq, exc2, syn, tmp_float, 1, Q_exc, st_fx->Q_syn ); - - tmp_float32 = st_fx->enr_old_fx; - frame_ener_fx( st_fx->L_frame_fx, st_fx->last_good_fx, syn, shr(add(FEC_pitch,32),6), &tmp_float32, st_fx->L_frame_fx, st_fx->Q_syn, 3, 0 ); - - /*------------------------------------------------------------------* - * Perform fixed deemphasis through 1/(1 - g*z^-1) - *-----------------------------------------------------------------*/ - tmp_float[0] = st_fx->mem_deemph_fx; - move16(); /*if in acelp_core_dec_fx deemph_fx is used*/ - /*tmp_float = shr(st_fx->mem_deemph_fx, sub(st_fx->Q_syn,1)); if in acelp_core_dec_fx Deemph2 is used*/ - - IF(sub(st_fx->L_frame_fx,L_FRAME )==0) - { - deemph_fx( syn, PREEMPH_FAC, L_FRAME, &tmp_float[0] ); /*Q0*/ - } - ELSE - { - deemph_fx( syn, PREEMPH_FAC_16k, L_FRAME16k, &tmp_float[0] ); /*Q0*/ - } - - /*----------------------------------------------------------------* - * Bass post-filter - *----------------------------------------------------------------*/ - - st_fx->bpf_off_fx=1; - move16(); - Copy( st_fx->pst_old_syn_fx,tmp_float,NBPSF_PIT_MAX); - - tmp_float3 = st_fx->stab_fac_smooth_fx; - move16(); - Copy( st_fx->mem_mean_pit_fx,tmp_float4, L_TRACK_HIST); - Copy( st_fx->Track_on_hist_fx,tmp_float5, L_TRACK_HIST); - Copy( st_fx->vibrato_hist_fx,tmp_float6, L_TRACK_HIST); - tmp_float7 = st_fx->psf_att_fx; - move16(); - - bass_psfilter_fx( st_fx->Opt_AMR_WB_fx, syn, st_fx->L_frame_fx, pitch_buf, tmp_float, - &st_fx->pst_mem_deemp_err_fx, &st_fx->pst_lp_ener_fx, st_fx->bpf_off_fx, st_fx->stab_fac_fx, &tmp_float3, - tmp_float4, tmp_float5, tmp_float6, &tmp_float7, coder_type, st_fx->Q_syn, old_exc /* tmp buffer*/); - - /*----------------------------------------------------------------* - * Resamping to the output sampling frequency - *----------------------------------------------------------------*/ - /* CLDFB analysis of the synthesis at internal sampling rate */ - cldfb_save_memory( st_fx->cldfbAna_fx ); - cldfbAnalysisFiltering( st_fx->cldfbAna_fx, realBuffer, imagBuffer, &scaleFactor, syn, - negate(st_fx->Q_syn), CLDFB_NO_COL_MAX_SWITCH_BFI, workBuffer); - cldfb_restore_memory( st_fx->cldfbAna_fx ); - - scaleFactor.hb_scale = scaleFactor.lb_scale; - - /* CLDFB synthesis of the combined signal */ - cldfb_save_memory( st_fx->cldfbSyn_fx ); - cldfbSynthesisFiltering( st_fx->cldfbSyn_fx, realBuffer, imagBuffer, &scaleFactor, synth_out, - negate(st_fx->Q_syn), CLDFB_NO_COL_MAX_SWITCH_BFI, workBuffer ); - - /* output to Q0 */ - Scale_sig(synth_out,L_FRAME48k, negate(st_fx->Q_syn)); - - cldfb_restore_memory( st_fx->cldfbSyn_fx ); - - return; -} - - -/*-------------------------------------------------------------------* -* decod_gen_voic_core_switch() -* -* Decode excitation signal in teh first ACELP->HQ switching frame -*-------------------------------------------------------------------*/ - -static void decod_gen_voic_core_switch_fx( - Decoder_State_fx *st_fx, /* i/o: decoder static memory */ - const Word16 L_frame, /* i : length of the frame */ - const Word16 sharpFlag, /* i : flag for formant sharpening */ - const Word16 *Aq, /* i : LP filter coefficient */ - const Word16 coder_type, /* i : coding type */ - Word16 *exc, /* i/o: adapt. excitation exc */ - const Word32 core_brate, /* i : switching frame bit-rate */ - Word16 *Q_exc -) -{ - Word16 T0, T0_frac, T0_min, T0_max;/* integer pitch variables */ - Word16 gain_pit,gain_code16; /* pitch gain */ - Word32 gain_code,L_tmp; /* gain/normalized gain of the algebraic excitation */ - Word32 norm_gain_code; /* normalized gain of the algebraic excitation */ - Word16 gain_inov; /* Innovation gain */ - Word16 voice_fac; /* voicing factor */ - Word16 code[L_SUBFR]; /* algebraic codevector */ - Word16 pitch; /* pointer to floating pitch */ - Word16 i; /* tmp variables */ - Word16 pitch_limit_flag; - Word16 *pt1; - - /*----------------------------------------------------------------------* - * initializations - *----------------------------------------------------------------------*/ - - IF( sub(L_frame, L_FRAME) == 0 ) - { - T0_max = PIT_MAX; - move16(); - T0_min = PIT_MIN; - move16(); - } - ELSE /* L_frame == L_FRAME16k */ - { - T0_max = PIT16k_MAX; - move16(); - T0_min = PIT16k_MIN; - move16(); - } - - /*----------------------------------------------------------------------* - * Decode pitch lag - *----------------------------------------------------------------------*/ - - pitch = pit_decode_fx( st_fx, core_brate, 0, L_frame, 0, coder_type, &pitch_limit_flag, &T0, &T0_frac, &T0_min, &T0_max, L_SUBFR ); /*Q6*/ - - /*--------------------------------------------------------------* - * Find the adaptive codebook vector. - *--------------------------------------------------------------*/ - - pred_lt4( &exc[0], &exc[0], T0, T0_frac, L_SUBFR+1, pitch_inter4_2, L_INTERPOL2, PIT_UP_SAMP ); - - /*--------------------------------------------------------------* - * LP filtering of the adaptive excitation - *--------------------------------------------------------------*/ - - lp_filt_exc_dec_fx( st_fx, MODE1, core_brate,0, coder_type, 0, L_SUBFR, L_frame, 0, exc); /*Scaling of exc doesn't change*/ - - /*--------------------------------------------------------------* - * Innovation decoding - *--------------------------------------------------------------*/ - - inov_decode_fx( st_fx, core_brate, 0, L_frame, coder_type, sharpFlag, 0, -1, Aq, st_fx->tilt_code_fx, pitch, code); /*code in Q9*/ - - /*--------------------------------------------------------------* - * Gain decoding - * Estimate spectrum tilt and voicing - *--------------------------------------------------------------*/ - - IF( sub(L_frame, L_FRAME) == 0 ) - { - gain_dec_mless_fx( st_fx, core_brate, L_frame, TRANSITION, 0, -1, code, st_fx->old_Es_pred_fx, &gain_pit, &gain_code, &gain_inov, &norm_gain_code ); - } - ELSE - { - gain_dec_mless_fx( st_fx, core_brate, L_frame, coder_type, 0, -1, code, st_fx->old_Es_pred_fx, &gain_pit, &gain_code, &gain_inov, &norm_gain_code ); - } - - /* _ (Word16*) gain_pit : quantized pitch gain (Q14) */ - /* _ (Word32*) gain_code : quantized codebook gain (Q16) */ - /* _ (Word16*) gain_inov : gain of the innovation (used for normalization) (Q12) */ - /* _ (Word32*) norm_gain_code : norm. gain of the codebook excitation (Q16) */ - st_fx->tilt_code_fx = est_tilt_fx( exc, gain_pit, code, gain_code, &voice_fac, *Q_exc ); /*Q15*/ - - /*----------------------------------------------------------------------* - * Find the total excitation - *----------------------------------------------------------------------*/ - - /* Rescaling for 12.8k core */ - IF ( sub(L_frame,L_FRAME) == 0 ) - { - Rescale_exc( NULL, &exc[0], NULL, st_fx->last_exc_dct_in_fx, L_SUBFR, L_SUBFR * HIBND_ACB_L_FAC, gain_code, &(st_fx->Q_exc), st_fx->Q_subfr, NULL, 0, GENERIC ); - } - /* Rescaling for 16k core */ - ELSE - { - Rescale_exc(NULL, &exc[0], NULL, st_fx->last_exc_dct_in_fx, L_SUBFR, L_SUBFR * 2, gain_code, &(st_fx->Q_exc), st_fx->Q_subfr, NULL, 0, GENERIC); - } - - gain_code16 = round_fx(L_shl(gain_code,st_fx->Q_exc)); /*Q_exc*/ - IF( st_fx->prev_bfi_fx ) - { - /*gain_code = min(gain_code, 0.5f*gain_code+0.5f*st->lp_gainc);*/ - gain_code16 = s_min(gain_code16, mac_r(L_mult(16384,gain_code16),shl(16384>>3, st_fx->Q_exc), st_fx->lp_gainc_fx)); /* st_fx->lp_gainc_fx in Q3 >>3 to bring it to Q0 as gain_code16 */ - } - - FOR (i = 0; i < L_SUBFR; i++) - { - L_tmp = L_shl(L_mult(gain_pit, exc[i]), 1); /*Q16+Q_exc*/ - /*exc2_fx[i+i_subfr] = round_fx(L_tmp);*/ /*Q_exc*/ - L_tmp = L_add(L_tmp, L_shl(L_mult(gain_code16, code[i]), 6)); /*Q16+Q_exc*/ - exc[i] = round_fx(L_tmp); /*Q_exc*/ - } - - /*-----------------------------------------------------------------* - * long term prediction on the 2nd sub frame - *-----------------------------------------------------------------*/ - - pred_lt4(&exc[L_SUBFR], &exc[L_SUBFR], T0, T0_frac, L_SUBFR+1, pitch_inter4_2, L_INTERPOL2, PIT_UP_SAMP); - pt1 = exc+L_SUBFR; - - FOR( i = 0; i < L_SUBFR; i++ ) - { - (*pt1) = round_fx(L_shl(L_mult(*pt1, gain_pit),1)); /*Q_exc + Q14 +1 +1 -16*/ - pt1++; - } - - return; -} diff --git a/src/libs/libevs/lib_dec/amr_wb_dec.cpp b/src/libs/libevs/lib_dec/amr_wb_dec.cpp new file mode 100644 index 00000000..4bdbfe18 --- /dev/null +++ b/src/libs/libevs/lib_dec/amr_wb_dec.cpp @@ -0,0 +1,865 @@ +/*==================================================================================== + EVS Codec 3GPP TS26.443 Nov 13, 2018. Version 12.11.0 / 13.7.0 / 14.3.0 / 15.1.0 + ====================================================================================*/ + +#include "options.h" +#include "cnst.h" +#include "rom_com.h" +#include "prot.h" + + +/*------------------------------------------------------------------* + * amr_wb_dec() + * + * AMR-WB decoder + *------------------------------------------------------------------*/ + +void amr_wb_dec( + Decoder_State *st, /* i/o: decoder state structure */ + float *output /* o : synthesis output */ +) +{ + short i; + short vad_flag; + short coder_type; + float ftmp; + float old_exc[L_EXC_DEC], *exc; /* excitation signal buffer */ + float syn_tmp[L_FRAME+2], *syn; /* synthesis signal buffer */ + float synth_out[L_FRAME48k]; /* synthesis output */ + short output_frame; /* frame length at output sampling freq. */ + float lsf_new[M]; /* LSFs at the end of the frame */ + float lsp_new[M]; /* LSPs at the end of the frame */ + float Aq[NB_SUBFR*(M+1)]; /* A(q) quantized for the 4 subframes */ + float exc2[L_FRAME]; /* total excitation buffer */ + float mem_tmp[M]; /* temporary synthesis filter memory */ + float pitch_buf[NB_SUBFR]; /* floating pitch for each subframe */ + float enr_q; /* E information for FER protection */ + float tmp_noise; /* Long term temporary noise energy */ + float FEC_pitch; /* FEC pitch */ + float dummy_buf[L_FRAME32k]; /* dummy buffer - no usage */ + short allow_cn_step; + short locattack, amr_io_class; + short tmps; + float xsp_tmp[M]; + float tmp_buffer[L_FRAME48k]; + float dct_buffer[DCT_L_POST]; + float frame_e; + float exc_buffer[DCT_L_POST]; + float class_para; + float voice_factors[NB_SUBFR]; + short hf_gain[NB_SUBFR]; + short delay_comp; + short nZeros; + float tmp; + short last_core_ori; + short sid_bw = 0; + float bpf_error_signal[L_FRAME]; + float ng_ener; + float gain_buf[NB_SUBFR16k]; + float q_env[20]; + float exc3[L_FRAME]; + float *realBuffer[CLDFB_NO_COL_MAX], *imagBuffer[CLDFB_NO_COL_MAX]; + float realBufferTmp[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX], imagBufferTmp[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX]; + short flag_cna; + short waveadj_rec = 0; + + + /*------------------------------------------------------------------* + * Initialization + *------------------------------------------------------------------*/ + + syn_tmp[0] = 0; + syn_tmp[1] = 0; + syn = syn_tmp+2; + + for( i=0; iuse_partial_copy = 0; + st->rf_flag = 0; + st->rf_flag_last = 0; + + st->L_frame = L_FRAME; + st->nb_subfr = NB_SUBFR; + st->core = AMR_WB_CORE; + st->core_brate = st->total_brate; + st->extl = -1; + st->bwidth = WB; + coder_type = GENERIC; + output_frame = (short)(st->output_Fs / 50); /* frame length of the input signal */ + + st->bpf_off = 0; + if( st->last_core == HQ_CORE ) + { + st->bpf_off = 1; + st->pfstat.on = 0; + } + st->igf = 0; + + st->sr_core = st->L_frame*50; + st->fscale_old = st->fscale; + st->fscale = sr2fscale(st->sr_core); + + /* Initialization in case that the first frame is the good received AMR-WB (IO) frame */ + if( st->ini_frame == 0 ) + { + st->last_core = AMR_WB_CORE; + mvr2r( mean_isf_amr_wb, st->lsf_old, M ); + isf2isp( st->lsf_old, st->lsp_old, M, INT_FS_12k8 ); + } + + /* Updates in case of EVS primary mode -> AMR-WB IO mode switching */ + if( st->last_core != AMR_WB_CORE ) + { + updt_IO_switch_dec( output_frame, st ); + } + + /* Updates in case of HQ -> AMR-WB IO switching */ + core_switching_pre_dec( st, output_frame ); + + last_core_ori = st->last_core; + set_s( hf_gain, 0, NB_SUBFR ); + + enr_q = 0.0f; + tmp_noise = 0.0f; + amr_io_class = UNVOICED_CLAS; + + mvr2r( st->old_exc, old_exc, L_EXC_MEM_DEC ); + exc = old_exc + L_EXC_MEM_DEC; + + /* reset post-filter in case of switching */ + if( st->pfstat.on == 0 ) + { + st->pfstat.reset = 1; + } + + if( st->bfi ) + { + st->nbLostCmpt++; + } + else + { + st->nbLostCmpt = 0; + } + + /* PLC: [TCX: Fade-out-recovery] + * PLC: overlapping part needs to be attenuated for first good frame */ + if (!st->bfi && st->prev_bfi && (st->last_codec_mode == MODE2) && (st->last_core_bfi == TCX_20_CORE || st->last_core_bfi == TCX_10_CORE)) + { + v_multc( st->old_out, st->plcInfo.recovery_gain, st->old_out, st->L_frameTCX ); + } + + /*-----------------------------------------------------------------* + * switching from ACELP@16k core to AMR-WB IO mode + *-----------------------------------------------------------------*/ + + st->rate_switching_reset = 0; + + if( st->last_core != AMR_WB_CORE && st->last_L_frame == L_FRAME16k && st->last_core != HQ_CORE ) + { + /* in case of switching, do not apply BPF */ + st->bpf_off = 1; + if( st->pfstat.on != 0 ) + { + short mem_syn_r_size_old, mem_syn_r_size_new; + + mem_syn_r_size_old = (short)(1.25*st->last_L_frame/20.f); + mem_syn_r_size_new = (short)(1.25*st->L_frame/20.f); + lerp( st->pfstat.mem_stp+L_SYN_MEM-mem_syn_r_size_old, st->pfstat.mem_stp+L_SYN_MEM-mem_syn_r_size_new, mem_syn_r_size_new, mem_syn_r_size_old ); + lerp( st->pfstat.mem_pf_in+L_SYN_MEM-mem_syn_r_size_old, st->pfstat.mem_pf_in+L_SYN_MEM-mem_syn_r_size_new, mem_syn_r_size_new, mem_syn_r_size_old ); + } + + /* convert old quantized LSP vector */ + st->rate_switching_reset = lsp_convert_poly( st->lsp_old, L_FRAME, 1 ); + + /* convert old quantized LSF vector */ + lsp2lsf( st->lsp_old, st->lsf_old, M, INT_FS_12k8 ); + + /* FEC - update adaptive LSF mean vector */ + mvr2r( st->lsf_old, st->lsfoldbfi1, M ); + mvr2r( st->lsf_old, st->lsfoldbfi0, M ); + mvr2r( st->lsf_old, st->lsf_adaptive_mean, M ); + + /* Reset LPC mem */ + mvr2r( GEWB_Ave, st->mem_AR, M ); + set_zero( st->mem_MA, M ); + + /* update synthesis filter memories */ + synth_mem_updt2( L_FRAME, st->last_L_frame, st->old_exc, st->mem_syn_r, st->mem_syn2, NULL, DEC ); + mvr2r( st->old_exc, old_exc, L_EXC_MEM_DEC ); + mvr2r( st->mem_syn2, st->mem_syn1, M ); + mvr2r( st->mem_syn2, st->mem_syn3, M ); + + /* LSP -> ISP */ + mvr2r( stable_ISP, xsp_tmp, M ); + lsp2isp( st->lsp_old, st->lsp_old, xsp_tmp, M ); + + } + + /* update buffer of old subframe pitch values */ + if( st->last_L_frame != L_FRAME ) + { + if( st->last_L_frame == L_FRAME32k ) + { + tmp = (float)12800/(float)32000; + } + else if( st->last_L_frame == 512 ) + { + tmp = (float)12800/(float)25600; + } + else /* st->last_L_frame == L_FRAME16k */ + { + tmp = (float)12800/(float)16000; + } + + for( i=NB_SUBFR16k-NB_SUBFR; iold_pitch_buf[i-1] = tmp * st->old_pitch_buf[i]; + } + + for( i=2*NB_SUBFR16k-NB_SUBFR; i<2*NB_SUBFR16k; i++ ) + { + st->old_pitch_buf[i-2] = tmp * st->old_pitch_buf[i]; + } + } + + if( st->bfi_pitch_frame != L_FRAME ) + { + if( st->bfi_pitch_frame == L_FRAME32k ) + { + tmp = (float)12800/(float)32000; + } + else if( st->bfi_pitch_frame == 512 ) + { + tmp = (float)12800/(float)25600; + } + else /* st->bfi_pitch_frame == L_FRAME16k */ + { + tmp = (float)12800/(float)16000; + } + + st->bfi_pitch *= tmp; + st->bfi_pitch_frame = L_FRAME; + } + + + if( st->last_core != AMR_WB_CORE ) + { + /* reset the unvoiced/audio signal improvement memories */ + isp2a( st->lsp_old, st->old_Aq, M ); + mvr2r( st->old_Aq, st->old_Aq + (M+1), M+1 ); + mvr2r( st->old_Aq, st->old_Aq + 2*(M+1), M+1 ); + mvr2r( st->old_Aq, st->old_Aq + 3*(M+1), M+1 ); + } + + if( st->last_bwidth == NB && st->ini_frame != 0 ) + { + st->rate_switching_reset = 1; + } + + /*----------------------------------------------------------------------* + * GOOD frame + *----------------------------------------------------------------------*/ + + if( !st->bfi ) + { + /*----------------------------------------------------------------* + * Processing of FRAME__NO_DATA frames + * Decoding of SID frames + *----------------------------------------------------------------*/ + + if ( st->core_brate == FRAME__NO_DATA || st->core_brate == SID_1k75 ) + { + /* decode CNG parameters */ + CNG_dec( st, L_FRAME, Aq, st->core_brate, lsp_new, lsf_new, &allow_cn_step, &sid_bw, q_env ); + + /* comfort noise generation */ + CNG_exc( st->core_brate, L_FRAME, &st->Enew, &st->cng_seed, exc, exc2, &st->lp_ener, st->last_core_brate, + &st->first_CNG, &st->cng_ener_seed, dummy_buf, allow_cn_step, &st->last_allow_cn_step, st->num_ho, + q_env, st->lp_env, st->old_env, st->exc_mem, st->exc_mem1, &sid_bw, &st->cng_ener_seed1, exc3, st->Opt_AMR_WB ); + + set_f( voice_factors, 1.0f, NB_SUBFR ); + class_para = 0.0f; + + if ( st->first_CNG == 0 ) + { + st->first_CNG = 1; + } + + /* update past excitation signals for LD music post-filter */ + mvr2r( st->dct_post_old_exc + L_FRAME, st->dct_post_old_exc, DCT_L_POST-L_FRAME-OFFSET2 ); + mvr2r( exc2, st->dct_post_old_exc + (DCT_L_POST-L_FRAME-OFFSET2), L_FRAME ); + + /* synthesis at 12k8 Hz sampling rate */ + syn_12k8( L_FRAME, Aq, exc2, syn, st->mem_syn2, 1 ); + syn_12k8( st->L_frame, Aq, exc2, dummy_buf, st->mem_syn3, 1 ); + + /* reset the decoder */ + CNG_reset_dec( st, pitch_buf, dummy_buf+L_FRAME ); + + /* update st->mem_syn1 for ACELP core switching */ + mvr2r( st->mem_syn3, st->mem_syn1, M ); + if( output_frame != L_FRAME8k ) + { + frame_e = 10.0f * (float) log10( dotp( syn, syn, L_FRAME ) / (float) L_FRAME ); + st->psf_lp_noise = 0.99f * st->psf_lp_noise + 0.01f * frame_e; + } + + /* update old synthesis for classification */ + mvr2r( syn + L_FRAME - L_SYN_MEM_CLAS_ESTIM, st->mem_syn_clas_estim, L_SYN_MEM_CLAS_ESTIM ); + + /* Update music post processing values */ + /* Filter energies update */ + for( i = 0; i < DCT_L_POST; i++ ) + { + st->filt_lfE[i] = 0.3f + 0.7f*st->filt_lfE[i]; + } + + vad_flag = 0; + } + + /*----------------------------------------------------------------* + * Decoding of all other frames + *----------------------------------------------------------------*/ + + else + { + /*-----------------------------------------------------------------* + * After CNG period, use the most up-to-date ISPs + *-----------------------------------------------------------------*/ + + if( st->last_core_brate == FRAME__NO_DATA || st->last_core_brate == SID_1k75 ) + { + mvr2r( st->lspCNG, st->lsp_old, M ); + isp2isf( st->lspCNG, st->lsf_old, M, INT_FS_12k8 ); + set_f( old_exc, 0, L_EXC_MEM_DEC ); + } + + /*------------------------------------------------------------* + * Extracts VAD information from the bitstream in AMR-WB IO mode + *------------------------------------------------------------*/ + + vad_flag = (short)get_next_indice( st, 1 ); + + if( vad_flag == 0 ) + { + coder_type = INACTIVE; + } + else + { + coder_type = GENERIC; + } + + /*-----------------------------------------------------------------* + * ISF de-quantization and interpolation + *-----------------------------------------------------------------*/ + + isf_dec_amr_wb( st, Aq, lsf_new, lsp_new ); + + /*------------------------------------------------------------* + * Decode excitation + *------------------------------------------------------------*/ + + decod_amr_wb( st, Aq, pitch_buf, exc, exc2, hf_gain, voice_factors, gain_buf ); + + /* synthesis for ACELP core switching and SWB BWE */ + syn_12k8( L_FRAME, Aq, exc, tmp_buffer, st->mem_syn1, 1 ); + + /*------------------------------------------------------------* + * Update long-term energies for FEC + * Update ISP vector for CNG + *------------------------------------------------------------*/ + + if( coder_type == INACTIVE ) + { + if( st->unv_cnt > 20 ) + { + ftmp = st->lp_gainc * st->lp_gainc; + st->lp_ener = 0.7f * st->lp_ener + 0.3f * ftmp; + for( i=0; ilspCNG[i] = (float)(0.9f * st->lspCNG[i] + 0.1f * lsp_new[i]); + } + } + else + { + st->unv_cnt++; + } + } + else + { + st->unv_cnt = 0; + } + + /*------------------------------------------------------------* + * Save filter memory in case the synthesis is redone after scaling + * Core synthesis at 12k8 Hz + *------------------------------------------------------------*/ + + mvr2r( st->mem_syn2, mem_tmp, M ); + syn_12k8( L_FRAME, Aq, exc2, syn, st->mem_syn2, 1 ); + + /*------------------------------------------------------------* + * FEC - Estimate the classification information + *------------------------------------------------------------*/ + + FEC_clas_estim( syn, pitch_buf, st->L_frame, coder_type, st->codec_mode, st->mem_syn_clas_estim, &st->clas_dec, + &st->lp_ener_bfi, st->core_brate, st->Opt_AMR_WB, &st->decision_hyst, &locattack, &st->UV_cnt, + &st->LT_UV_cnt, &st->Last_ener, &amr_io_class, st->lt_diff_etot, &class_para, 0, 0, (SIGNAL_CLASSIFIER_MODE)0, + 0, 0, 0, st->last_core_brate ); + + /* update past excitation signals for LD music post-filter */ + mvr2r( st->dct_post_old_exc + L_FRAME, st->dct_post_old_exc, DCT_L_POST-L_FRAME-OFFSET2 ); + mvr2r( exc2, st->dct_post_old_exc + (DCT_L_POST-L_FRAME-OFFSET2), L_FRAME ); + mvr2r( st->dct_post_old_exc, exc_buffer, DCT_L_POST-OFFSET2 ); + + if( output_frame != L_FRAME8k ) + { + if ( coder_type == INACTIVE ) + { + frame_energy( L_FRAME, pitch_buf, syn, 0.0f, &frame_e ); + st->psf_lp_noise = 0.99f * st->psf_lp_noise + 0.01f * frame_e; + } + } + + if( amr_io_class != UNVOICED_CLAS && coder_type != INACTIVE && st->psf_lp_noise < 15.0f ) + { + short tmp_coder_type = AUDIO; + if( st->last_coder_type == INACTIVE || st->last_coder_type == UNVOICED ) + { + tmp_coder_type = INACTIVE; + } + /* Extrapolation of the last future part, windowing and high resolution DCT transform */ + Prep_music_postP( exc_buffer, dct_buffer, st->filt_lfE, st->last_core, pitch_buf, st->LDm_enh_lp_gbin ); + + /* LD music post-filter */ + LD_music_post_filter( dct_buffer, dct_buffer, st->core_brate, &st->LDm_last_music_flag, + st->LDm_thres, &st->LDm_nb_thr_1, &st->LDm_nb_thr_3, st->LDm_lt_diff_etot, + &st->LDm_mem_etot, st->LDm_enh_min_ns_gain, st->LDm_bckr_noise, st->LDm_enh_lf_EO, + st->LDm_enh_lp_gbin, st->filt_lfE, &st->last_nonfull_music, -1, tmp_coder_type ); + + /* Inverse DCT transform, retrieval of the aligned excitation, re-synthesis */ + Post_music_postP( dct_buffer, exc_buffer, exc2, mem_tmp, st->mem_syn2, Aq, syn ); + } + else + { + /*------------------------------------------------------------* + * Improvement for unvoiced and audio signals + *------------------------------------------------------------*/ + + improv_amr_wb_gs( amr_io_class, coder_type, st->core_brate, &st->seed_tcx, st->old_Aq, st->mem_syn2, st->lt_voice_fac, + locattack, Aq, exc2, mem_tmp, syn, pitch_buf, st->Last_ener, st->rate_switching_reset, st->last_coder_type ); + + for( i = 0; i < DCT_L_POST; i++ ) + { + st->filt_lfE[i] = 0.3f + 0.7f * st->filt_lfE[i] ; + } + } + + /*------------------------------------------------------------* + * FEC - Estimate pitch + *------------------------------------------------------------*/ + + FEC_pitch_estim( 1, st->last_core, L_FRAME, st->clas_dec, st->last_good, pitch_buf, st->old_pitch_buf, + &st->bfi_pitch, &st->bfi_pitch_frame, &st->upd_cnt, GENERIC ); + + /*------------------------------------------------------------* + * FEC - Smooth the speech energy evolution when recovering after a BAD frame + * (smoothing is performed in the excitation domain and signal is resynthesized after) + *------------------------------------------------------------*/ + + FEC_scale_syn( L_FRAME, st->clas_dec, st->last_good, syn, pitch_buf, st->enr_old, enr_q, -1, + MOVING_AVERAGE, &st->scaling_flag, &st->lp_ener_FEC_av, &st->lp_ener_FEC_max, st->bfi, + st->total_brate, st->prev_bfi, st->last_core_brate, exc, exc2, Aq, &st->old_enr_LP, mem_tmp, st->mem_syn2, + st->last_con_tcx && (st->L_frameTCX_past != st->L_frame) && (st->last_core != 0), 0 ); + + /* estimate the pitch-synchronous speech energy per sample to be used when normal operation recovers */ + fer_energy( L_FRAME, st->clas_dec, syn, pitch_buf[3], &st->enr_old, L_FRAME ); + } + + } /* End of GOOD FRAME */ + + /*----------------------------------------------------------------* + * BAD frame + *----------------------------------------------------------------*/ + + else + { + /* long burst frame erasures */ + if( st->nbLostCmpt > 5 && st->clas_dec >= VOICED_CLAS ) + { + st->last_good = VOICED_TRANSITION; + } + + vad_flag = st->last_vad; + amr_io_class = st->last_good; + class_para = 0.0f; + + /* LSF estimation and A(z) calculation */ + lsf_dec_bfi( MODE1, lsf_new, st->lsf_old, st->lsf_adaptive_mean, NULL, st->mem_MA, st->mem_AR, + st->stab_fac, st->last_coder_type, L_FRAME, st->last_good, + st->nbLostCmpt, 0, NULL, NULL, NULL, st->Last_GSC_pit_band_idx, st->Opt_AMR_WB, st->bwidth ); + + FEC_lsf2lsp_interp( st, L_FRAME, Aq, lsf_new, lsp_new ); + + /* calculation of excitation signal */ + FEC_exc_estim( st, L_FRAME, exc, exc2, tmp_buffer, pitch_buf, voice_factors, &FEC_pitch, dummy_buf, lsf_new, &tmp_noise ); + + /* synthesis for ACELP core switching and SWB BWE */ + syn_12k8( L_FRAME, Aq, exc, tmp_buffer, st->mem_syn1, 1 ); + + /* update past excitation signals */ + mvr2r( st->dct_post_old_exc + L_FRAME, st->dct_post_old_exc, DCT_L_POST-L_FRAME-OFFSET2 ); + mvr2r( exc2, st->dct_post_old_exc + (DCT_L_POST-L_FRAME-OFFSET2), L_FRAME ); + + /* Update music post processing values */ + /* Update circular buffer, keep last energy difference unchanged */ + for (i = 1; iLDm_lt_diff_etot[i-1] = st->LDm_lt_diff_etot[i]; + } + /* Filter energies update */ + for( i = 0; i < DCT_L_POST; i++ ) + { + st->filt_lfE[i] = 0.3f + 0.7f * st->filt_lfE[i]; + } + + /* synthesis at 12k8 Hz sampling rate */ + mvr2r( st->mem_syn2, mem_tmp, M ); + syn_12k8( L_FRAME, Aq, exc2, syn, st->mem_syn2, 1 ); + + /* update old synthesis for classification */ + mvr2r( syn + L_FRAME - L_SYN_MEM_CLAS_ESTIM, st->mem_syn_clas_estim, L_SYN_MEM_CLAS_ESTIM ); + + + /*------------------------------------------------------------* + * FEC - Smooth the speech energy evolution when recovering after a BAD frame + * (smoothing is performed in the excitation domain and signal is resynthesized after) + *------------------------------------------------------------*/ + + FEC_scale_syn( L_FRAME, st->clas_dec, st->last_good, syn, pitch_buf, st->enr_old, enr_q, -1, + MOVING_AVERAGE, &st->scaling_flag, &st->lp_ener_FEC_av, &st->lp_ener_FEC_max, st->bfi, + st->total_brate, st->prev_bfi, st->last_core_brate, exc, exc2, Aq, &st->old_enr_LP, mem_tmp, st->mem_syn2, + 0,0 ); + + /* estimate the pitch-synchronous speech energy per sample to be used when normal operation recovers */ + fer_energy( L_FRAME, st->last_good, syn, FEC_pitch, &st->enr_old, L_FRAME ); + } + + /*--------------------------------------------------------* + * NB post-filter + *--------------------------------------------------------*/ + + if( output_frame == L_FRAME8k || st->last_bwidth == NB ) + { + if( output_frame == L_FRAME8k ) + { + st->pfstat.on = 1; + nb_post_filt( L_FRAME, L_SUBFR, &(st->pfstat), &st->psf_lp_noise, tmp_noise, syn, Aq, pitch_buf, coder_type, st->BER_detect, 0 ); + } + else + { + st->pfstat.on = 0; + nb_post_filt( L_FRAME, L_SUBFR, &(st->pfstat), &st->psf_lp_noise, tmp_noise, syn, Aq, pitch_buf, AUDIO, st->BER_detect, 0); + } + } + + /*------------------------------------------------------------------* + * Perform fixed deemphasis through 1/(1 - g*z^-1) + *-----------------------------------------------------------------*/ + + /* update old synthesis buffer - needed for ACELP internal sampling rate switching */ + mvr2r( syn + L_FRAME - L_SYN_MEM, st->mem_syn_r, L_SYN_MEM ); + + + deemph( syn, PREEMPH_FAC, L_FRAME, &(st->mem_deemph) ); + AGC_dec( syn, st->agc_mem2, L_FRAME ); + mvr2r( syn+L_FRAME/2, st->old_syn_Overl, L_FRAME/2 ); + mvr2r( syn+L_FRAME-M-1, st->syn, M+1 ); + + /*------------------------------------------------------------------* + * Formant post-filter + *-----------------------------------------------------------------*/ + + mvr2r( syn, tmp_buffer + L_SYN_MEM, L_FRAME ); + + if( output_frame != L_FRAME8k && st->last_bwidth != NB ) + { + st->pfstat.on = 1; + formant_post_filt( &(st->pfstat), tmp_buffer + L_SYN_MEM, Aq, syn, L_FRAME, L_SUBFR, st->psf_lp_noise, st->total_brate, amr_io_class == AUDIO_CLAS ); + } + + /*----------------------------------------------------------------* + * Comfort Noise Addition + *----------------------------------------------------------------*/ + + flag_cna = 0; + if( (st->psf_lp_noise >= 15.f) || (coder_type == INACTIVE) ) + { + /*VAD only for non inactive frame*/ + st->VAD = (st->VAD && (coder_type != INACTIVE)); + + ApplyFdCng( syn, NULL, NULL, st->hFdCngDec, st->m_frame_type, st, 0, 0 ); + + st->hFdCngDec->hFdCngCom->frame_type_previous = st->m_frame_type; + + /*Noisy speech detector*/ + noisy_speech_detection( st->VAD, syn, st->hFdCngDec->hFdCngCom->frameSize, st->hFdCngDec->msNoiseEst, st->hFdCngDec->psize_shaping, + st->hFdCngDec->nFFTpart_shaping, &(st->hFdCngDec->lp_noise), &(st->hFdCngDec->lp_speech), &(st->hFdCngDec->hFdCngCom->flag_noisy_speech)); + + st->hFdCngDec->hFdCngCom->likelihood_noisy_speech = 0.99f*st->hFdCngDec->hFdCngCom->likelihood_noisy_speech + 0.01f*(float)st->hFdCngDec->hFdCngCom->flag_noisy_speech; + st->lp_noise = st->hFdCngDec->lp_noise; + + if( st->flag_cna && (st->psf_lp_noise >= 15.f) ) + { + flag_cna = 1; + generate_masking_noise( syn, st->hFdCngDec->hFdCngCom, st->hFdCngDec->hFdCngCom->frameSize, AMR_WB_CORE ); + } + else if ( st->flag_cna ) + { + generate_masking_noise_update_seed(st->hFdCngDec->hFdCngCom); + } + } + else if ( st->flag_cna ) + { + generate_masking_noise_update_seed(st->hFdCngDec->hFdCngCom); + } + + if( flag_cna == 0 ) + { + if( st->last_flag_cna == 1 && ( (st->last_core == ACELP_CORE && st->last_coder_type != AUDIO) || st->last_core == AMR_WB_CORE) ) + { + v_multc( st->hFdCngDec->hFdCngCom->olapBufferSynth2+5*L_FRAME/4, 256.f, tmp_buffer, L_FRAME/2 ); + v_add( tmp_buffer, syn, syn, L_FRAME/2 ); + } + set_f( st->hFdCngDec->hFdCngCom->olapBufferSynth2, 0.f, L_FRAME*2 ); + } + + /*----------------------------------------------------------------* + * Change the sampling frequency to 8/16/32 kHz + * Bass post-filter + *----------------------------------------------------------------*/ + + /* check if the cldfb works on the right sample rate */ + if( (st->cldfbAna->no_channels * st->cldfbAna->no_col) != L_FRAME ) + { + /* resample to ACELP internal sampling rate */ + resampleCldfb (st->cldfbAna, INT_FS_12k8); + resampleCldfb (st->cldfbBPF, INT_FS_12k8); + + if( st->ini_frame > 0 ) + { + st->cldfbSyn->bandsToZero = st->cldfbSyn->no_channels - st->cldfbAna->no_channels; + } + } + + /* bass post-filter */ + bass_psfilter( st->Opt_AMR_WB, syn, L_FRAME, pitch_buf, st->pst_old_syn, + &st->pst_mem_deemp_err, &st->pst_lp_ener, st->bpf_off, st->stab_fac, &st->stab_fac_smooth, + st->mem_mean_pit, st->Track_on_hist, st->vibrato_hist, &st->psf_att, GENERIC, bpf_error_signal ); + + /* analysis of the synthesis at internal sampling rate */ + cldfbAnalysis( syn, realBuffer, imagBuffer, -1, st->cldfbAna ); + + /* analysis and add the BPF error signal */ + addBassPostFilter( bpf_error_signal, st->bpf_off?0:-1, realBuffer, imagBuffer, st->cldfbBPF ); + + if( st->cldfbSyn->bandsToZero != st->cldfbSyn->no_channels - st->cldfbAna->no_channels ) + { + /* in case of BW switching, re-init to default */ + st->cldfbSyn->bandsToZero = st->cldfbSyn->no_channels-st->cldfbAna->no_channels; + } + + cldfb_synth_set_bandsToZero( st, realBuffer, imagBuffer, CLDFB_NO_COL_MAX ); + + /* synthesis of the combined signal */ + cldfbSynthesis( realBuffer, imagBuffer, synth_out, -1, st->cldfbSyn ); + + /* save synthesis - needed in case of core switching */ + mvr2r( synth_out, st->previoussynth, output_frame ); + + /*--------------------------------------------------------* + * calculate the average frame energy + *--------------------------------------------------------*/ + + fer_energy( L_FRAME, st->clas_dec, syn, pitch_buf[3], &ng_ener, L_FRAME ); + + /*--------------------------------------------------------* + * optimized for NO_S@-26dBov with street noise @ SNR=25dB + *--------------------------------------------------------*/ + + ng_ener = 10.0f * (float)log10(ng_ener + 0.01f) - 90.3087f + 15; + st->ng_ener_ST = 0.7f * st->ng_ener_ST + 0.3f * ng_ener; + + /*-----------------------------------------------------------------* + * Bandwidth extension 6kHz-8kHz + *-----------------------------------------------------------------*/ + if( output_frame >= L_FRAME16k && ((st->cldfbSyn->bandsToZero - st->cldfbSyn->no_channels + 10 ) != 0 || st->last_flag_filter_NB != 1) ) + { + hf_synth_amr_wb( st->core_brate, output_frame, Aq, exc2, syn, st->mem_syn_hf, st->delay_syn_hf, &st->prev_r, &st->fmerit_w_sm, &amr_io_class, st->mem_hp_interp, + synth_out, class_para, hf_gain, voice_factors, pitch_buf, st->ng_ener_ST, lsf_new, &st->frame_count, &st->ne_min, &st->fmerit_m_sm, &st->voice_fac_amr_wb_hf, + &st->unvoicing, &st->unvoicing_sm, &st->unvoicing_flag, &st->voicing_flag, &st->start_band_old, &st->OptCrit_old ); + } + else + { + hf_synth_amr_wb_reset( &st->seed2, st->mem_syn_hf, st->mem_hp_interp, &st->prev_r, &st->fmerit_w_sm, st->delay_syn_hf, + &st->frame_count, &st->ne_min, &st->fmerit_m_sm, &st->voice_fac_amr_wb_hf, &st->unvoicing, + &st->unvoicing_sm, &st->unvoicing_flag, &st->voicing_flag, &st->start_band_old, &st->OptCrit_old ); + } + /*----------------------------------------------------------------------* + * Updates + *----------------------------------------------------------------------*/ + + updt_dec( st, L_FRAME, coder_type, old_exc, pitch_buf, 0, Aq, lsf_new, lsp_new, voice_factors, dummy_buf, gain_buf ); + + /* update old_Aq[] - needed in improv_amr_wb_gs_fx() */ + mvr2r( Aq, st->old_Aq, NB_SUBFR * (M+1) ); + + if( !st->bfi + && st->prev_bfi + && st->last_total_brate >= HQ_48k + && st->last_codec_mode == MODE2 + && (st->last_core_bfi == TCX_20_CORE || st->last_core_bfi == TCX_10_CORE) + && st->plcInfo.concealment_method == TCX_NONTONAL + && st->plcInfo.nbLostCmpt < 4 ) + { + waveadj_rec = 1; + } + + /* update main codec parameters */ + st->last_core = st->core; + st->last_extl = -1; + st->last_L_frame = L_FRAME; + st->last_core_brate = st->core_brate; + st->last_codec_mode = st->codec_mode; + st->last_bwidth = WB; + st->last_total_brate_ber = st->total_brate; + if( !st->bfi ) + { + st->last_total_brate = st->total_brate; + st->last_good = st->clas_dec; + } + st->last_vad = vad_flag; + st->last_flag_cna = flag_cna; + + /*----------------------------------------------------------------* + * Overlap of ACELP synthesis with old MDCT memory + *----------------------------------------------------------------*/ + + if( st->bfi ) + { + /* calculate another loss frame to fill gap in case of switching frame loss */ + acelp_core_switch_dec_bfi( st, st->fer_samples, coder_type ); + } + + delay_comp = NS2SA(st->output_Fs, DELAY_CLDFB_NS); + if( last_core_ori == HQ_CORE ) + { + nZeros = (short)(NS2SA(st->output_Fs,N_ZERO_MDCT_NS)); + + if( st->prev_bfi && st->HqVoicing ) + { + mvr2r( st->fer_samples, st->old_out+nZeros, NS2SA(st->output_Fs,6000000) ); + } + + /* copy the HQ/ACELP delay synchroniation buffer to the beginning of ACELP frame */ + mvr2r( st->delay_buf_out, synth_out, delay_comp ); + + tmp = 1.0f/(float)NS2SA(st->output_Fs,6000000); + for( i=0; ioutput_Fs,6000000); i++ ) + { + synth_out[i+delay_comp] = (1-tmp*(float)i)*st->old_out[i+nZeros] + tmp*(float)i*synth_out[i+delay_comp]; + } + } + + st->prev_bfi = st->bfi; + st->last_con_tcx = st->con_tcx; + + if( st->core_brate > SID_1k75 ) + { + st->last_active_brate = st->total_brate; + } + + if ( st->core_brate > SID_1k75 && st->first_CNG ) + { + if( st->act_cnt >= BUF_DEC_RATE ) + { + st->act_cnt = 0; + } + + st->act_cnt++; + + if( st->act_cnt == BUF_DEC_RATE && st->ho_hist_size > 0 ) + { + st->ho_hist_size--; + } + + if( ++(st->act_cnt2) >= MIN_ACT_CNG_UPD ) + { + st->act_cnt2 = MIN_ACT_CNG_UPD; + } + } + + st->prev_bws_cnt = 0; + st->bws_cnt = 0; + st->bws_cnt1 = 0; + + /*----------------------------------------------------------------* + * HP filtering + * Final synthesis output + *----------------------------------------------------------------*/ + + /* Delay ACELP synthesis by DELAY_BWE_TOTAL_NS - DELAY_CLDFB_NS delay */ + if ( output_frame >= L_FRAME16k ) + { + tmps = NS2SA(st->output_Fs, DELAY_BWE_TOTAL_NS - DELAY_CLDFB_NS); + mvr2r( synth_out, tmp_buffer, output_frame ); + mvr2r( st->prev_synth_buffer, synth_out, tmps ); + mvr2r( tmp_buffer, synth_out + tmps, output_frame - tmps ); + mvr2r( tmp_buffer + output_frame - tmps, st->prev_synth_buffer, tmps ); + } + + if (waveadj_rec) + { + tmps = 0; + if( output_frame >= L_FRAME16k ) + { + tmps = NS2SA(st->output_Fs, DELAY_BWE_TOTAL_NS); + } + waveform_adj2(st->tonalMDCTconceal.secondLastPcmOut, + synth_out+tmps, + st->plcInfo.data_noise, + &st->plcInfo.outx_new_n1, + &st->plcInfo.nsapp_gain, + &st->plcInfo.nsapp_gain_n, + &st->plcInfo.recovery_gain, st->plcInfo.step_concealgain, + st->plcInfo.Pitch, st->plcInfo.FrameSize, + tmps, st->plcInfo.nbLostCmpt + 1, st->bfi ); + } + + /* HP filter */ + hp20( synth_out, output_frame, st->mem_hp20_out, st->output_Fs ); + + /* save synthesis for core switching */ + mvr2r( synth_out + NS2SA(st->output_Fs,ACELP_LOOK_NS+DELAY_BWE_TOTAL_NS), st->old_synth_sw, NS2SA(st->output_Fs,FRAME_SIZE_NS-ACELP_LOOK_NS-DELAY_BWE_TOTAL_NS) ); + + /* TCX-LTP Postfilter: used in AMR-WB IO to update memories and to avoid discontinuities when the past frame was TCX */ + tcx_ltp_post( st->tcxltp, ACELP_CORE, output_frame, st->L_frame_past, 0, synth_out, NULL, NS2SA( st->output_Fs, TCXLTP_DELAY_NS ), + 0, 0, 0, 0.f, &st->tcxltp_pitch_int_post_prev, &st->tcxltp_pitch_fr_post_prev, &st->tcxltp_gain_post_prev, + &st->tcxltp_filt_idx_prev, st->pit_res_max, &st->pit_res_max_past, 0.f, 0, st->tcxltp_mem_in, st->tcxltp_mem_out, st->total_brate ); + + /* final output of synthesis signal */ + mvr2r( synth_out, output, output_frame ); + + + + + return; +} diff --git a/src/libs/libevs/lib_dec/amr_wb_dec_fx.cpp b/src/libs/libevs/lib_dec/amr_wb_dec_fx.cpp deleted file mode 100755 index ee7f179b..00000000 --- a/src/libs/libevs/lib_dec/amr_wb_dec_fx.cpp +++ /dev/null @@ -1,1135 +0,0 @@ -/*==================================================================================== - EVS Codec 3GPP TS26.442 Apr 03, 2018. Version 12.11.0 / 13.6.0 / 14.2.0 - ====================================================================================*/ - -#include -#include "options.h" -#include "cnst_fx.h" -#include "rom_com_fx.h" -#include "prot_fx.h" -#include "stl.h" -#include "basop_mpy.h" -#include "basop_util.h" /* Function prototypes */ - -/*-------------------------------------------------------------------* - * amr_wb_dec() - * - * AMR-WB decoder - *-------------------------------------------------------------------*/ - -void amr_wb_dec_fx( - Word16 output_sp[], /* o : synthesis output */ - Decoder_State_fx *st_fx /* o : Decoder static variables structure */ -) -{ - Word16 i; - Word16 vad_flag; - Word16 coder_type; - Word16 output_frame; /* frame length at output sampling freq. */ - Word16 allow_cn_step; - Word16 locattack, amr_io_class; - Word16 tmps; - Word16 synth_out_fx[L_FRAME48k]; - - Word16 class_para_fx, hf_gain_fx[NB_SUBFR], voice_factors_fx[NB_SUBFR]; - Word16 delay_comp; - Word16 last_core_ori; - Word16 tmp_buffer_fx[L_FRAME48k]; - Word16 dct_buffer_fx[DCT_L_POST]; - Word16 frame_e_fx; - Word16 exc_buffer_fx[DCT_L_POST]; - Word16 lsp_new_fx[M]; /* LSPs at the end of the frame */ - Word16 lsf_new_fx[M]; /* LSFs at the end of the frame */ - Word16 xsp_tmp[M]; - Word16 Aq_fx[NB_SUBFR*(M+1)]; /* A(q) quantized for the 4 subframes */ - Word16 exc2_fx[L_FRAME]; /* total excitation buffer */ - Word16 mem_tmp_fx[M]; /* temporary synthesis filter memory */ - Word32 L_enr_q_fx; /* E information for FER protection */ - Word16 tmp_noise_fx; /* Long term temporary noise energy */ - Word16 FEC_pitch_fx; /* FEC pitch */ - Word16 dummy_buf_fx[L_FRAME32k]; /* dummy buffer - no usage */ - Word16 old_exc_fx[L_EXC_DEC], *exc_fx; /* excitation signal buffer */ - Word16 syn_tmp_fx[L_FRAME+2], *syn_fx; /* synthesis signal buffer */ - Word32 L_tmp, L_tmp1; - Word16 pitch_buf_fx[NB_SUBFR], Qdct, tmp_coder_type; /* floating pitch for each subframe (Q6) */ - Word16 tmp16; - Word16 sid_bw = 0; - Word32 L_Ng_ener; - Word16 exp2, ng_ener; - - Word16 bpf_error_signal[L_FRAME]; - CLDFB_SCALE_FACTOR scaleFactor; - Word32 workBuffer[128*3]; - Word32 q_env[20]; - Word16 exc3[L_FRAME]; - Word16 gain_buf[NB_SUBFR16k]; - - Word32 *realBuffer[CLDFB_NO_COL_MAX], *imagBuffer[CLDFB_NO_COL_MAX]; - Word32 realBufferTmp[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX], imagBufferTmp[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX]; - Word16 syn_fx_tmp2[L_FRAME]; - - Word16 pitch_buf_tmp[NB_SUBFR]; - Word16 update_flg; - Word8 flag_cna; - - Word8 waveadj_rec = 0; - - Word16 avoid_lpc_burst_on_recovery; - Word16 delta_mem_scale; - - /*------------------------------------------------------------------* - * Initialization - *------------------------------------------------------------------*/ - - syn_tmp_fx[0] = 0; - move16(); - syn_tmp_fx[1] = 0; - move16(); - syn_fx = syn_tmp_fx+2; - - FOR( i=0; iuse_partial_copy = 0; - move16(); - st_fx->rf_flag = 0; - move16(); - st_fx->rf_flag_last = 0; - move16(); - - st_fx->L_frame_fx = L_FRAME; - move16(); - st_fx->nb_subfr = NB_SUBFR; - move16(); - st_fx->core_fx = AMR_WB_CORE; - move16(); - st_fx->core_brate_fx = st_fx->total_brate_fx; - move16(); - st_fx->extl_fx = -1; - move16(); - st_fx->bwidth_fx = WB; - move16(); - coder_type = GENERIC; - move16(); - output_frame = st_fx->output_frame_fx; - move16(); /* frame length of the input signal */ - - st_fx->bpf_off_fx = 0; - move16(); - if( sub(st_fx->last_core_fx,HQ_CORE) == 0 ) - { - st_fx->bpf_off_fx = 1; - move16(); - st_fx->pfstat.on = 0; - move16(); - } - st_fx->igf = 0; - move16(); - - st_fx->sr_core = i_mult(st_fx->L_frame_fx,50); - st_fx->fscale_old = st_fx->fscale; - st_fx->fscale = sr2fscale(st_fx->sr_core); - - /* Initialization in case that the first frame is the good received AMR-WB (IO) frame */ - IF( st_fx->ini_frame_fx == 0 ) - { - st_fx->last_core_fx = AMR_WB_CORE; - move16(); - Copy( mean_isf_amr_wb_fx, st_fx->lsf_old_fx, M ); - E_LPC_isf_isp_conversion( st_fx->lsf_old_fx, st_fx->lsp_old_fx, M ); - } - - /* Updates in case of EVS primary mode -> AMR-WB IO mode switching */ - IF( sub(st_fx->last_core_fx,AMR_WB_CORE) != 0 ) - { - updt_IO_switch_dec_fx( output_frame, st_fx ); - } - - /* Updates in case of EVS -> AMR-WB IO switching */ - core_switching_pre_dec_fx( st_fx, output_frame ); - - last_core_ori = st_fx->last_core_fx; - move16(); - set16_fx( hf_gain_fx, 0, NB_SUBFR); - - amr_io_class = UNVOICED_CLAS; - move16(); - L_enr_q_fx = L_deposit_l(0); - tmp_noise_fx = 0; - move16(); - - Copy( st_fx->old_exc_fx, old_exc_fx, L_EXC_MEM_DEC ); - exc_fx = old_exc_fx + L_EXC_MEM_DEC; - /* reset post-filter in case of switching */ - if( st_fx->pfstat.on == 0 ) - { - st_fx->pfstat.reset = 1; - move16(); - } - IF( st_fx->bfi_fx > 0 ) - { - st_fx->nbLostCmpt = add(st_fx->nbLostCmpt,1); - } - ELSE - { - st_fx->nbLostCmpt = 0; - move16(); - } - - /* PLC: [TCX: Fade-out-recovery] - * PLC: overlapping part needs to be attenuated for first good frame */ test(); - test(); - test(); - test(); - IF (!st_fx->bfi_fx - && st_fx->prev_bfi_fx - && (sub(st_fx->last_codec_mode, MODE2) == 0) - && (sub(st_fx->last_core_bfi, TCX_20_CORE) == 0 - || sub(st_fx->last_core_bfi, TCX_10_CORE) == 0)) - { - /* v_multc(st_fx->old_out_fx, st_fx->plcInfo.recovery_gain, */ - /* st_fx->old_out_fx, st_fx->L_frameTCX); */ - FOR( i = 0; i < st_fx->L_frameTCX; i++ ) - { - st_fx->old_out_fx[i] = shl(mult_r(st_fx->old_out_fx[i], st_fx->plcInfo.recovery_gain), 1); - } - } - - avoid_lpc_burst_on_recovery = 0; - move16(); - test(); - test(); - if (st_fx->last_con_tcx && (sub(st_fx->L_frameTCX_past, st_fx->L_frame_fx) != 0) && (st_fx->last_core_fx != 0)) - { - avoid_lpc_burst_on_recovery = 1; - move16(); - } - - /*-----------------------------------------------------------------* - * switching from ACELP@16k core to AMR-WB IO mode - *-----------------------------------------------------------------*/ - st_fx->rate_switching_reset=0; - move16(); - test(); - test(); - IF( sub(st_fx->last_core_fx,AMR_WB_CORE) != 0 && sub(st_fx->last_L_frame_fx,L_FRAME16k ) == 0 && sub(st_fx->last_core_fx,HQ_CORE) != 0) - { - /* in case of switching, do not apply BPF */ - st_fx->bpf_off_fx = 1; - move16(); - - if(st_fx->pfstat.on!=0) - { - Word16 mem_syn_r_size_old, mem_syn_r_size_new; - - mem_syn_r_size_old = shr(st_fx->last_L_frame_fx, 4); - mem_syn_r_size_new = shr(st_fx->L_frame_fx, 4); - lerp( st_fx->pfstat.mem_stp+L_SYN_MEM-mem_syn_r_size_old, st_fx->pfstat.mem_stp+L_SYN_MEM-mem_syn_r_size_new, mem_syn_r_size_new, mem_syn_r_size_old ); - lerp( st_fx->pfstat.mem_pf_in+L_SYN_MEM-mem_syn_r_size_old, st_fx->pfstat.mem_pf_in+L_SYN_MEM-mem_syn_r_size_new, mem_syn_r_size_new, mem_syn_r_size_old ); - } - - st_fx->rate_switching_reset=lsp_convert_poly_fx( st_fx->lsp_old_fx, L_FRAME, 1 ); - /* convert old quantized LSF vector */ - lsp2lsf_fx( st_fx->lsp_old_fx, st_fx->lsf_old_fx, M, INT_FS_FX ); - - /* FEC - update adaptive LSF mean vector */ - Copy( st_fx->lsf_old_fx, st_fx->lsfoldbfi1_fx, M ); - Copy( st_fx->lsf_old_fx, st_fx->lsfoldbfi0_fx, M ); - Copy( st_fx->lsf_old_fx, st_fx->lsf_adaptive_mean_fx, M ); - - /* Reset LPC mem */ - Copy( GEWB_Ave_fx, st_fx->mem_AR_fx, M ); - set16_fx( st_fx->mem_MA_fx,0, M ); - - /* update synthesis filter memories */ - synth_mem_updt2( L_FRAME, st_fx->last_L_frame_fx, st_fx->old_exc_fx, st_fx->mem_syn_r, st_fx->mem_syn2_fx, NULL, DEC ); - Copy( st_fx->old_exc_fx, old_exc_fx, L_EXC_MEM_DEC ); - Copy_Scale_sig(st_fx->mem_syn2_fx, st_fx->mem_syn1_fx, M, sub(-1,st_fx->Q_syn)); /*Q-1*/ - Copy( st_fx->mem_syn2_fx, st_fx->mem_syn3_fx, M ); - - /* LSP -> ISP */ - Copy( stable_ISP_fx, xsp_tmp, M ); - lsp2isp_fx( st_fx->lsp_old_fx, st_fx->lsp_old_fx, xsp_tmp, M ); - - } - - /* update buffer of old subframe pitch values */ - IF( sub(st_fx->last_L_frame_fx,L_FRAME) != 0 ) - { - move16(); - IF( sub(st_fx->last_L_frame_fx,L_FRAME32k) == 0 ) - { - /* (float)12800/(float)32000; */ - tmp16 = 13107; - } - ELSE IF( sub(st_fx->last_L_frame_fx,512) == 0 ) - { - /* (float)12800/(float)25600; */ - tmp16 = 16384; - } - ELSE /* st->last_L_frame == L_FRAME16k */ - { - /* (float)12800/(float)16000; */ - tmp16 = 26214; - } - - FOR( i=NB_SUBFR16k-NB_SUBFR; iold_pitch_buf_fx[i-1] = Mpy_32_16_1(st_fx->old_pitch_buf_fx[i], tmp16); - move32(); - } - - FOR( i=2*NB_SUBFR16k-NB_SUBFR; i<2*NB_SUBFR16k; i++ ) - { - st_fx->old_pitch_buf_fx[i-2] = Mpy_32_16_1(st_fx->old_pitch_buf_fx[i], tmp16); - move32(); - } - } - - IF( sub(st_fx->bfi_pitch_frame_fx, L_FRAME) != 0 ) - { - move16(); - IF( sub(st_fx->bfi_pitch_frame_fx,L_FRAME32k) == 0 ) - { - /* (float)12800/(float)32000; */ - tmp16 = 13107; - } - ELSE IF( sub(st_fx->bfi_pitch_frame_fx,512) == 0 ) - { - /* (float)12800/(float)25600; */ - tmp16 = 16384; - } - ELSE /* st->bfi_pitch_frame_fx == L_FRAME16k */ - { - /* (float)12800/(float)16000; */ - tmp16 = 26214; - } - st_fx->bfi_pitch_fx = mult_r(tmp16, st_fx->bfi_pitch_fx); - st_fx->bfi_pitch_frame_fx = L_FRAME; - move16(); - } - - IF( sub(st_fx->last_core_fx,AMR_WB_CORE) != 0 ) - { - /* reset the unvoiced/audio signal improvement memories */ - E_LPC_f_isp_a_conversion( st_fx->lsp_old_fx, st_fx->old_Aq_fx, M ); - Copy( st_fx->old_Aq_fx, st_fx->old_Aq_fx + (M+1), M+1 ); - Copy( st_fx->old_Aq_fx, st_fx->old_Aq_fx + 2*(M+1), M+1 ); - Copy( st_fx->old_Aq_fx, st_fx->old_Aq_fx + 3*(M+1), M+1 ); - } - - test(); - if( sub(st_fx->last_bwidth_fx,NB)==0 && st_fx->ini_frame_fx!=0 ) - { - st_fx->rate_switching_reset=1; - move16(); - } - - /*----------------------------------------------------------------------* - * GOOD frame - *----------------------------------------------------------------------*/ - - IF( !st_fx->bfi_fx ) - { - /*----------------------------------------------------------------* - * Processing of FRAME_NO_DATA frames - * Decoding of SID frames - *----------------------------------------------------------------*/ - - test(); - IF ( L_sub(st_fx->core_brate_fx,FRAME_NO_DATA) == 0 || L_sub(st_fx->core_brate_fx,SID_1k75) == 0 ) - { - /* decode CNG parameters */ - CNG_dec_fx( st_fx, L_FRAME, Aq_fx, st_fx->core_brate_fx, lsp_new_fx, lsf_new_fx, &allow_cn_step, &sid_bw, q_env ); - - /* comfort noise generation */ - CNG_exc_fx( st_fx->core_brate_fx, L_FRAME, &st_fx->Enew_fx, &st_fx->cng_seed_fx, exc_fx, exc2_fx, &st_fx->lp_ener_fx, st_fx->last_core_brate_fx, - &st_fx->first_CNG_fx, &st_fx->cng_ener_seed_fx, dummy_buf_fx, allow_cn_step, &st_fx->last_allow_cn_step_fx, st_fx->prev_Q_exc, st_fx->Q_exc , st_fx->num_ho_fx, - q_env, st_fx->lp_env_fx, st_fx->old_env_fx, st_fx->exc_mem_fx, st_fx->exc_mem1_fx, &sid_bw, &st_fx->cng_ener_seed1_fx, exc3, st_fx->Opt_AMR_WB_fx ); - - set16_fx( voice_factors_fx, 32767, NB_SUBFR ); - class_para_fx = 0; - move16(); - - if( st_fx->first_CNG_fx == 0 ) - { - st_fx->first_CNG_fx = 1; - move16(); - } - - - delta_mem_scale = 3; - move16(); - test(); - if( L_sub(st_fx->lp_ener_fx,40) < 0 ) /* very low energy frames, less than 0.3125 */ - { - delta_mem_scale = 0; - move16(); - } - - i = st_fx->Q_exc; - Rescale_exc( st_fx->dct_post_old_exc_fx, exc_fx, NULL, st_fx->last_exc_dct_in_fx, st_fx->L_frame_fx, - st_fx->L_frame_fx* HIBND_ACB_L_FAC, 0, &(st_fx->Q_exc), st_fx->Q_subfr, NULL, 0, INACTIVE); - - Rescale_mem( st_fx->Q_exc, &st_fx->prev_Q_syn, &st_fx->Q_syn, st_fx->mem_syn2_fx, st_fx->mem_syn_clas_estim_fx, delta_mem_scale, - &st_fx->mem_deemph_fx, st_fx->pst_old_syn_fx,&st_fx->pst_mem_deemp_err_fx, &st_fx->agc_mem_fx[1], &st_fx->pfstat, 0, 0, NULL ); - Copy_Scale_sig(exc2_fx, exc2_fx, st_fx->L_frame_fx, sub(st_fx->Q_exc, i)); - - /* update past excitation signals for LD music post-filter */ - Copy( st_fx->dct_post_old_exc_fx + L_FRAME, st_fx->dct_post_old_exc_fx, DCT_L_POST-L_FRAME-OFFSET2 ); - Copy( exc2_fx, st_fx->dct_post_old_exc_fx + (DCT_L_POST-L_FRAME-OFFSET2), L_FRAME ); - - /* synthesis at 12k8 Hz sampling rate */ - syn_12k8_fx( L_FRAME, Aq_fx, exc2_fx, syn_fx, st_fx->mem_syn2_fx, 1, st_fx->Q_exc, st_fx->Q_syn ); - syn_12k8_fx( L_FRAME, Aq_fx, exc2_fx, dummy_buf_fx, st_fx->mem_syn3_fx, 1, st_fx->Q_exc, st_fx->Q_syn ); - - /* reset the decoder */ - CNG_reset_dec_fx( st_fx, pitch_buf_fx, dummy_buf_fx+L_FRAME ); - - /* update st_fx->mem_syn1 for ACELP core switching */ - Copy_Scale_sig( st_fx->mem_syn3_fx, st_fx->mem_syn1_fx, M, sub(-1,st_fx->Q_syn) ); /*Q-1*/ - IF( sub(output_frame,L_FRAME8k) != 0 ) - { - Word16 pitch_temp[4]; - pitch_temp[2] = shl(L_FRAME, 6); - move16(); - pitch_temp[3] = shl(L_FRAME, 6); - move16(); - frame_energy_fx( L_FRAME, pitch_temp, syn_fx, 0, &frame_e_fx, st_fx->Q_syn ); - /*st->psf_lp_noise = 0.99f * st->psf_lp_noise + 0.01f * frame_e; */ - st_fx->psf_lp_noise_fx = round_fx(L_mac(L_mult(32440, st_fx->psf_lp_noise_fx), 328, frame_e_fx)); /*Q8*/ - } - /* update old synthesis for classification */ - Copy( syn_fx + L_FRAME - L_SYN_MEM_CLAS_ESTIM, st_fx->mem_syn_clas_estim_fx, L_SYN_MEM_CLAS_ESTIM ); - - /* Update music post processing values */ - /* Filter energies update */ - FOR( i = 0; i < DCT_L_POST; i++ ) - { - /*st->filt_lfE[i] = 0.3f + 0.7f * st->filt_lfE[i];*/ - st_fx->filt_lfE_fx[i] = round_fx(L_mac(L_deposit_h(1229), 22938, st_fx->filt_lfE_fx[i])); - } - - vad_flag = 0; - move16(); - } - - /*----------------------------------------------------------------* - * Decoding of all other frames - *----------------------------------------------------------------*/ - - ELSE - { - /*-----------------------------------------------------------------* - * After CNG period, use the most up-to-date ISPs - *-----------------------------------------------------------------*/ - - test(); - IF ( L_sub(st_fx->last_core_brate_fx,FRAME_NO_DATA) == 0 || L_sub(st_fx->last_core_brate_fx,SID_1k75) == 0 ) - { - Copy( st_fx->lspCNG_fx, st_fx->lsp_old_fx, M ); - E_LPC_isp_isf_conversion( st_fx->lspCNG_fx, st_fx->lsf_old_fx, M ); - set16_fx( old_exc_fx, 0, L_EXC_MEM_DEC ); - } - - /*------------------------------------------------------------* - * Extracts VAD information from the bitstream in AMR-WB IO mode - *------------------------------------------------------------*/ - - vad_flag = (Word16)get_next_indice_fx( st_fx, 1 ); - - coder_type = GENERIC; - move16(); - if ( vad_flag == 0 ) - { - coder_type = INACTIVE; - move16(); - } - - /*-----------------------------------------------------------------* - * ISF de-quantization and interpolation - *-----------------------------------------------------------------*/ - - isf_dec_amr_wb_fx( st_fx, Aq_fx, lsf_new_fx, lsp_new_fx ); - - /*------------------------------------------------------------* - * Decode excitation - *------------------------------------------------------------*/ - - decod_amr_wb_fx( st_fx, Aq_fx, pitch_buf_fx, exc_fx, exc2_fx, hf_gain_fx, voice_factors_fx, gain_buf ); - - /* synthesis for ACELP core switching and SWB BWE */ - syn_12k8_fx( L_FRAME, Aq_fx, exc_fx, tmp_buffer_fx, st_fx->mem_syn1_fx, 1, st_fx->Q_exc, -1 ); - - /*------------------------------------------------------------* - * Update long-term energies for FEC - * Update ISP vector for CNG - *------------------------------------------------------------*/ - - IF( sub(coder_type,INACTIVE) == 0 ) - { - IF( sub(st_fx->unv_cnt_fx,20) > 0 ) - { - /*ftmp = st->lp_gainc * st->lp_gainc;*/ - L_tmp1 = L_mult0(st_fx->lp_gainc_fx, st_fx->lp_gainc_fx); /* Q3*Q3 -> Q6*/ - /*st->lp_ener = 0.7f * st->lp_ener + 0.3f * ftmp;*/ - L_tmp = Mult_32_16(st_fx->lp_ener_fx, 22938); - st_fx->lp_ener_fx = L_add(L_tmp, Mult_32_16(L_tmp1, 9830)); /*Q6 + Q6*/ - FOR( i=0; ilspCNG_fx[i] = round_fx(L_mac(L_tmp, 29491, st_fx->lspCNG_fx[i])); - } - } - ELSE - { - st_fx->unv_cnt_fx = add(st_fx->unv_cnt_fx,1); - } - } - ELSE - { - st_fx->unv_cnt_fx = 0; - move16(); - } - - /*------------------------------------------------------------* - * Save filter memory in case the synthesis is redone after scaling - * Core synthesis at 12k8 Hz - *------------------------------------------------------------*/ - - /* add extra headroom in case a CNA addition is likely (i.e. st_fx->psf_lp_noise_fx is close to the threshold) */ - tmp16 = 0; - move16(); - test(); - test(); - if(sub(coder_type,INACTIVE) == 0 && st_fx->flag_cna && sub(st_fx->psf_lp_noise_fx,15<<7) >= 0) - { - tmp16 = 1; - move16(); - } - Rescale_mem( st_fx->Q_exc, &st_fx->prev_Q_syn, &st_fx->Q_syn, st_fx->mem_syn2_fx, st_fx->mem_syn_clas_estim_fx, 5, &st_fx->mem_deemph_fx, - st_fx->pst_old_syn_fx, &st_fx->pst_mem_deemp_err_fx, &st_fx->agc_mem_fx[1], &st_fx->pfstat, vad_flag, tmp16, tmp_buffer_fx ); - Copy( st_fx->mem_syn2_fx, mem_tmp_fx, M ); - syn_12k8_fx( L_FRAME, Aq_fx, exc2_fx, syn_fx, st_fx->mem_syn2_fx, 1, st_fx->Q_exc, st_fx->Q_syn ); - - /*------------------------------------------------------------* - * FEC - Estimate the classification information - *------------------------------------------------------------*/ - - FEC_clas_estim_fx( st_fx, 1, L_FRAME, &st_fx->clas_dec, coder_type, pitch_buf_fx, - syn_fx, &st_fx->lp_ener_FER_fx, - &st_fx->decision_hyst_fx, &st_fx->UV_cnt_fx, &st_fx->LT_UV_cnt_fx, &st_fx->Last_ener_fx, &locattack, st_fx->lt_diff_etot_fx, - &amr_io_class, st_fx->core_brate_fx, st_fx->Q_syn, &class_para_fx, st_fx->mem_syn_clas_estim_fx, &st_fx->classifier_Q_mem_syn, - 0, 0, 0, st_fx->last_core_brate_fx ); - - /* update past excitation signals for LD music post-filter */ - Copy( st_fx->dct_post_old_exc_fx + L_FRAME, st_fx->dct_post_old_exc_fx, DCT_L_POST-L_FRAME-OFFSET2 ); - Copy( exc2_fx, st_fx->dct_post_old_exc_fx + (DCT_L_POST-L_FRAME-OFFSET2), L_FRAME ); - Copy( st_fx->dct_post_old_exc_fx, exc_buffer_fx, DCT_L_POST-OFFSET2 ); - - IF( sub(output_frame,L_FRAME8k) != 0 ) - { - IF ( sub(coder_type,INACTIVE) == 0 ) - { - frame_energy_fx( L_FRAME, pitch_buf_fx, syn_fx, 0, &frame_e_fx, st_fx->Q_syn ); - /*st->psf_lp_noise = 0.99f * st->psf_lp_noise + 0.01f * frame_e; */ - st_fx->psf_lp_noise_fx = round_fx(L_mac(L_mult(32440, st_fx->psf_lp_noise_fx), 328, frame_e_fx)); /*Q8*/ - } - } - - test(); - test(); - IF( sub(amr_io_class,UNVOICED_CLAS) != 0 && sub(coder_type,INACTIVE) != 0 && sub(st_fx->psf_lp_noise_fx,15<<8) < 0 ) - { - tmp_coder_type = AUDIO; - move16(); - test(); - if (sub(st_fx->last_coder_type_fx,INACTIVE) == 0 || sub(st_fx->last_coder_type_fx,UNVOICED) == 0) - { - tmp_coder_type = INACTIVE; - move16(); - } - /* Extrapolation of the last future part, windowing and high resolution DCT transform */ - Prep_music_postP_fx( exc_buffer_fx, dct_buffer_fx, st_fx->filt_lfE_fx, st_fx->last_core_fx, pitch_buf_fx, st_fx->LDm_enh_lp_gbin_fx, st_fx->Q_exc, &Qdct ); - - /* LD music post-filter */ - LD_music_post_filter_fx( dct_buffer_fx, dct_buffer_fx, st_fx->core_brate_fx, &st_fx->LDm_last_music_flag_fx, - st_fx->LDm_thres_fx, &st_fx->LDm_nb_thr_1_fx, &st_fx->LDm_nb_thr_3_fx, st_fx->LDm_lt_diff_etot_fx, - &st_fx->LDm_mem_etot_fx, st_fx->LDm_enh_min_ns_gain_fx, st_fx->LDm_bckr_noise_fx, - st_fx->LDm_enh_lf_EO_fx, st_fx->LDm_enh_lp_gbin_fx, st_fx->filt_lfE_fx, &st_fx->last_nonfull_music_fx, - &st_fx->Old_ener_Q, -1, tmp_coder_type, Qdct ); - - /* Inverse DCT transform, retrieval of the aligned excitation, re-synthesis */ - Post_music_postP_fx( dct_buffer_fx, exc2_fx, mem_tmp_fx, st_fx->mem_syn2_fx, Aq_fx, syn_fx, &st_fx->Q_exc, &st_fx->prev_Q_syn, - &st_fx->Q_syn, st_fx->mem_syn_clas_estim_fx, 1, &st_fx->mem_deemph_fx, st_fx->pst_old_syn_fx, - &st_fx->pst_mem_deemp_err_fx, &st_fx->agc_mem_fx[1], &st_fx->pfstat, NULL, NULL ); - } - ELSE - { - /*------------------------------------------------------------* - * Improvement for unvoiced and audio signals - *------------------------------------------------------------*/ - - improv_amr_wb_gs_fx( amr_io_class, coder_type, st_fx->core_brate_fx, &st_fx->seed_tcx_fx, st_fx->old_Aq_fx, st_fx->mem_syn2_fx, st_fx->lt_voice_fac_fx, - locattack, Aq_fx, exc2_fx, st_fx->Q_exc, mem_tmp_fx, syn_fx, st_fx->Q_syn, pitch_buf_fx, st_fx->Last_ener_fx, st_fx->rate_switching_reset, st_fx->last_coder_type_fx ); - - FOR( i = 0; i < DCT_L_POST; i++ ) - { - /*st->filt_lfE[i] = 0.3f + 0.7f * st->filt_lfE[i] ;*/ - st_fx->filt_lfE_fx[i] = round_fx(L_mac(L_deposit_h(1229), 22938, st_fx->filt_lfE_fx[i])); - } - } - - /*------------------------------------------------------------* - * FEC - Estimate pitch - *------------------------------------------------------------*/ - - FEC_pitch_estim_fx( 1, st_fx->last_core_fx, L_FRAME, st_fx->clas_dec, st_fx->last_good_fx, pitch_buf_fx, st_fx->old_pitch_buf_fx, &st_fx->bfi_pitch_fx, - &st_fx->bfi_pitch_frame_fx, &st_fx->upd_cnt_fx, GENERIC ); - - /*------------------------------------------------------------* - * FEC - Smooth the speech energy evolution when recovering after a BAD frame - * (smoothing is performed in the excitation domain and signal is resynthesized after) - *------------------------------------------------------------*/ - - FOR( i=0; iclas_dec, st_fx->last_good_fx, syn_fx, pitch_buf_tmp, st_fx->enr_old_fx, L_enr_q_fx, -1, MOVING_AVERAGE, - &st_fx->scaling_flag, &st_fx->lp_ener_FEC_av, &st_fx->lp_ener_FEC_max, st_fx->bfi_fx, st_fx->total_brate_fx, st_fx->prev_bfi_fx, st_fx->last_core_brate_fx, - exc_fx, exc2_fx, Aq_fx, &st_fx->old_enr_LP, mem_tmp_fx, st_fx->mem_syn2_fx, st_fx->Q_exc, st_fx->Q_syn, avoid_lpc_burst_on_recovery, 0 ); - - frame_ener_fx( L_FRAME, st_fx->clas_dec, syn_fx, pitch_buf_tmp[3], &st_fx->enr_old_fx, L_FRAME, st_fx->Q_syn, 3, 0 ); - } - - } /* End of GOOD FRAME */ - - /*----------------------------------------------------------------* - * BAD frame - *----------------------------------------------------------------*/ - ELSE - { - /* long burst frame erasures */ - test(); - if( sub(st_fx->nbLostCmpt,5) > 0 && sub(st_fx->clas_dec,VOICED_CLAS) >= 0 ) - { - st_fx->last_good_fx = VOICED_TRANSITION; - move16(); - } - vad_flag = st_fx->last_vad_fx; - move16(); - amr_io_class = st_fx->last_good_fx; - move16(); - class_para_fx = 0; - move16(); - - /* LSF estimation and A(z) calculation */ - lsf_dec_bfi( MODE1, lsf_new_fx, st_fx->lsf_old_fx, st_fx->lsf_adaptive_mean_fx, NULL, st_fx->mem_MA_fx, st_fx->mem_AR_fx, - st_fx->stab_fac_fx, st_fx->last_coder_type_fx, st_fx->L_frame_fx, st_fx->last_good_fx, - st_fx->nbLostCmpt, 0, NULL, NULL, NULL, st_fx->Last_GSC_pit_band_idx_fx, st_fx->Opt_AMR_WB_fx, 0, st_fx->bwidth_fx); - - FEC_lsf2lsp_interp( st_fx, st_fx->L_frame_fx, Aq_fx, lsf_new_fx, lsp_new_fx ); - /* calculation of excitation signal */ - FEC_exc_estim_fx( st_fx, L_FRAME, exc_fx, exc2_fx, tmp_buffer_fx, pitch_buf_fx, voice_factors_fx, - &FEC_pitch_fx, dummy_buf_fx, lsf_new_fx, &st_fx->Q_exc, &tmp_noise_fx); - - /* synthesis for ACELP core switching and SWB BWE */ - syn_12k8_fx( L_FRAME, Aq_fx, exc_fx, tmp_buffer_fx, st_fx->mem_syn1_fx, 1, st_fx->Q_exc, -1 ); - - /* update past excitation signals */ - Copy( st_fx->dct_post_old_exc_fx + L_FRAME, st_fx->dct_post_old_exc_fx, DCT_L_POST-L_FRAME-OFFSET2 ); - Copy( exc2_fx, st_fx->dct_post_old_exc_fx + (DCT_L_POST-L_FRAME-OFFSET2), L_FRAME ); - - /* Update music post processing values */ - /* Update circular buffer, keep last energy difference unchanged */ - FOR( i = 1; iLDm_lt_diff_etot_fx[i-1] = st_fx->LDm_lt_diff_etot_fx[i]; - move16(); - } - /* Filter energies update */ - FOR( i = 0; i < DCT_L_POST; i++ ) - { - /*st->filt_lfE[i] = 0.3f + 0.7f * st->filt_lfE[i];*/ - st_fx->filt_lfE_fx[i] = round_fx(L_mac(L_deposit_h(1229), 22938, st_fx->filt_lfE_fx[i])); - } - - Rescale_mem( st_fx->Q_exc, &st_fx->prev_Q_syn, &st_fx->Q_syn, st_fx->mem_syn2_fx, st_fx->mem_syn_clas_estim_fx, 4, &st_fx->mem_deemph_fx, - st_fx->pst_old_syn_fx, &st_fx->pst_mem_deemp_err_fx, &st_fx->agc_mem_fx[1], &st_fx->pfstat, 1, 0, tmp_buffer_fx ); - - Copy( st_fx->mem_syn2_fx, mem_tmp_fx, M ); - /* synthesis at 12k8 Hz sampling rate */ - syn_12k8_fx( L_FRAME, Aq_fx, exc2_fx, syn_fx, st_fx->mem_syn2_fx, 1 , st_fx->Q_exc, st_fx->Q_syn ); - - /* update old synthesis for classification */ - Copy( syn_fx + L_FRAME - L_SYN_MEM_CLAS_ESTIM, st_fx->mem_syn_clas_estim_fx, L_SYN_MEM_CLAS_ESTIM ); - - - FOR( i=0; iclas_dec, st_fx->last_good_fx, syn_fx, pitch_buf_tmp, st_fx->enr_old_fx, L_enr_q_fx, -1, - MOVING_AVERAGE, &st_fx->scaling_flag, &st_fx->lp_ener_FEC_av, &st_fx->lp_ener_FEC_max, st_fx->bfi_fx, st_fx->total_brate_fx, - st_fx->prev_bfi_fx, st_fx->last_core_brate_fx, exc_fx, exc2_fx, Aq_fx, &st_fx->old_enr_LP, mem_tmp_fx, st_fx->mem_syn2_fx, - st_fx->Q_exc, st_fx->Q_syn, 0, 0 ); - - /* estimate the pitch-synchronous speech energy per sample to be used when normal operation recovers */ - frame_ener_fx( L_FRAME, st_fx->last_good_fx, syn_fx, shr(FEC_pitch_fx, 6), &st_fx->enr_old_fx, L_FRAME, st_fx->Q_syn, 3, 0 ); - } - - /*--------------------------------------------------------* - * NB post-filter - *--------------------------------------------------------*/ - test(); - IF( sub(output_frame,L_FRAME8k) == 0 || sub(st_fx->last_bwidth_fx,NB) == 0) - { - FOR( i=0; ipfstat.on = 1; - move16(); - nb_post_filt( L_FRAME, &(st_fx->pfstat), &st_fx->psf_lp_noise_fx, tmp_noise_fx, syn_fx, Aq_fx, pitch_buf_tmp, coder_type, st_fx->BER_detect, 0 ); - } - ELSE - { - st_fx->pfstat.on = 0; - move16(); - nb_post_filt( L_FRAME, &(st_fx->pfstat), &st_fx->psf_lp_noise_fx, tmp_noise_fx, syn_fx, Aq_fx, pitch_buf_tmp, AUDIO, st_fx->BER_detect, 0 ); - } - } - - /*------------------------------------------------------------------* - * Perform fixed deemphasis through 1/(1 - g*z^-1) - *-----------------------------------------------------------------*/ - - /* update old synthesis buffer - needed for ACELP internal sampling rate switching */ - Copy( syn_fx + L_FRAME - L_SYN_MEM, st_fx->mem_syn_r, L_SYN_MEM ); - - deemph_fx( syn_fx, PREEMPH_FAC, L_FRAME, &(st_fx->mem_deemph_fx) ); - - unscale_AGC( syn_fx, st_fx->Q_syn, syn_fx_tmp2, st_fx->agc_mem_fx, L_FRAME ); - Copy( syn_fx_tmp2, syn_fx, L_FRAME ); - - /* TCX=Q-1, ACELP2 Q0 */ - Copy_Scale_sig( syn_fx + L_FRAME/2, st_fx->old_syn_Overl, L_FRAME/2, sub(-1,st_fx->Q_syn)); /*Q_syn*/ - Copy_Scale_sig( syn_fx + L_FRAME-M-1, st_fx->syn, M+1, sub(0,st_fx->Q_syn)); /*Q0*/ - - /*------------------------------------------------------------------* - * Formant post-filter - *-----------------------------------------------------------------*/ - - Copy( syn_fx, tmp_buffer_fx + L_SYN_MEM, L_FRAME ); - IF( sub(output_frame,L_FRAME8k) != 0 && sub(st_fx->last_bwidth_fx,NB) != 0) - { - st_fx->pfstat.on = 1; - move16(); - test(); - formant_post_filt( &(st_fx->pfstat), tmp_buffer_fx + L_SYN_MEM, Aq_fx, syn_fx, L_FRAME, L_shl(st_fx->psf_lp_noise_fx,15), st_fx->total_brate_fx, sub(amr_io_class,AUDIO_CLAS) == 0); - } - - /*----------------------------------------------------------------* - * Comfort Noise Addition - *----------------------------------------------------------------*/ - - flag_cna = 0; - move16(); - test(); - IF( (sub(st_fx->psf_lp_noise_fx,15<<8) >= 0) || (coder_type == INACTIVE) ) - { - /*VAD only for non inactive frame*/ - test(); - IF( sub(st_fx->VAD, 1) == 0 && sub(coder_type,INACTIVE) != 0 ) - { - st_fx->VAD = 1; - move16(); - } - ELSE - { - st_fx->VAD = 0; - move16(); - } - ApplyFdCng( syn_fx, st_fx->Q_syn, NULL, NULL, 0, st_fx->hFdCngDec_fx, st_fx->m_frame_type, st_fx, 0, 0 ); - - st_fx->hFdCngDec_fx->hFdCngCom->frame_type_previous = st_fx->m_frame_type; - - /*Noisy speech detector*/ - noisy_speech_detection( st_fx->VAD, syn_fx, L_FRAME, st_fx->Q_syn, st_fx->hFdCngDec_fx->msNoiseEst, st_fx->hFdCngDec_fx->msNoiseEst_exp, - st_fx->hFdCngDec_fx->psize_shaping_norm, st_fx->hFdCngDec_fx->psize_shaping_norm_exp, st_fx->hFdCngDec_fx->nFFTpart_shaping, - &(st_fx->hFdCngDec_fx->lp_noise), &(st_fx->hFdCngDec_fx->lp_speech), &(st_fx->hFdCngDec_fx->hFdCngCom->flag_noisy_speech) ); - - st_fx->hFdCngDec_fx->hFdCngCom->likelihood_noisy_speech = mult_r(st_fx->hFdCngDec_fx->hFdCngCom->likelihood_noisy_speech, 32440/*0.99 Q15*/); - IF ( st_fx->hFdCngDec_fx->hFdCngCom->flag_noisy_speech != 0 ) - { - st_fx->hFdCngDec_fx->hFdCngCom->likelihood_noisy_speech = add(st_fx->hFdCngDec_fx->hFdCngCom->likelihood_noisy_speech, 328/*0.01 Q15*/); - move16(); - } - st_fx->lp_noise = st_fx->hFdCngDec_fx->lp_noise; - move16(); - - test(); - IF( st_fx->flag_cna && sub(st_fx->psf_lp_noise_fx,15<<8) >= 0 ) - { - flag_cna = 1; - move16(); - generate_masking_noise( syn_fx, st_fx->Q_syn, st_fx->hFdCngDec_fx->hFdCngCom, st_fx->hFdCngDec_fx->hFdCngCom->frameSize, AMR_WB_CORE ); - } - ELSE IF ( st_fx->flag_cna ) - { - generate_masking_noise_update_seed( st_fx->hFdCngDec_fx->hFdCngCom ); - } - - /*Copy(syn+L_FRAME-M-1, st_fx->syn, M+1);*/ - } - ELSE IF ( st_fx->flag_cna ) - { - generate_masking_noise_update_seed( st_fx->hFdCngDec_fx->hFdCngCom ); - } - - - IF( flag_cna == 0 ) - { - test(); - test(); - test(); - IF( sub(st_fx->last_flag_cna,1) == 0 && ( (sub(st_fx->last_core_fx,ACELP_CORE) == 0 && sub(st_fx->last_coder_type_fx,AUDIO) != 0) || sub(st_fx->last_core_fx,AMR_WB_CORE) == 0 ) ) - { - FOR (i=0; i < L_FRAME/2; i++) - { - syn_fx[i] = add( syn_fx[i], shr_r( st_fx->hFdCngDec_fx->hFdCngCom->olapBufferSynth2[i+5*L_FRAME/4], -st_fx->Q_syn ) ); - move16(); - } - } - set16_fx( st_fx->hFdCngDec_fx->hFdCngCom->olapBufferSynth2, 0, shl(L_FRAME,1) ); - } - - /*----------------------------------------------------------------* - * Change the sampling frequency to 8/16/32 kHz - * Bass post-filter - *----------------------------------------------------------------*/ - - /* check if the CLDFB works on the right sample rate */ - IF( (st_fx->cldfbAna_fx->usb * st_fx->cldfbAna_fx->no_col) != L_FRAME ) - { - /* resample to ACELP internal sampling rate */ - Word16 newCldfbBands = CLDFB_getNumChannels(INT_FS_FX); - - resampleCldfb( st_fx->cldfbAna_fx, newCldfbBands, L_FRAME, 0 ); - resampleCldfb( st_fx->cldfbBPF_fx, newCldfbBands, L_FRAME, 0 ); - - if( st_fx->ini_frame_fx > 0 ) - { - st_fx->cldfbSyn_fx->bandsToZero = sub(st_fx->cldfbSyn_fx->no_channels,st_fx->cldfbAna_fx->no_channels); - } - } - - bass_psfilter_fx( st_fx->Opt_AMR_WB_fx, syn_fx, L_FRAME, pitch_buf_fx, st_fx->pst_old_syn_fx, - &st_fx->pst_mem_deemp_err_fx, &st_fx->pst_lp_ener_fx, st_fx->bpf_off_fx, st_fx->stab_fac_fx, &st_fx->stab_fac_smooth_fx, - st_fx->mem_mean_pit_fx, st_fx->Track_on_hist_fx, st_fx->vibrato_hist_fx, &st_fx->psf_att_fx, GENERIC, st_fx->Q_syn, bpf_error_signal); - - cldfbAnalysisFiltering( st_fx->cldfbAna_fx, realBuffer, imagBuffer, &scaleFactor, syn_fx, - negate(st_fx->Q_syn), CLDFB_NO_COL_MAX, workBuffer ); - - scaleFactor.hb_scale = scaleFactor.lb_scale; - move16(); - - /* CLDFB analysis and add the BPF error signal */ - i = 0; - move16(); - if( st_fx->bpf_off_fx == 0 ) - { - i = CLDFB_NO_COL_MAX; - move16(); - } - addBassPostFilterFx( bpf_error_signal, realBuffer, imagBuffer, st_fx->cldfbBPF_fx, workBuffer, negate(st_fx->Q_syn), - i, st_fx->cldfbAna_fx->no_col, st_fx->cldfbAna_fx->no_channels, &scaleFactor ); - st_fx->Q_syn2 = st_fx->Q_syn; - move16(); - - if( sub(st_fx->cldfbSyn_fx->bandsToZero,sub(st_fx->cldfbSyn_fx->no_channels,st_fx->cldfbAna_fx->no_channels)) != 0 ) - { - /* in case of BW switching, re-init to default */ - st_fx->cldfbSyn_fx->bandsToZero = sub(st_fx->cldfbSyn_fx->no_channels, st_fx->cldfbAna_fx->no_channels); - } - cldfb_synth_set_bandsToZero( st_fx, realBuffer, imagBuffer, CLDFB_NO_COL_MAX, scaleFactor ); - /* CLDFB synthesis of the combined signal */ - cldfbSynthesisFiltering( st_fx->cldfbSyn_fx, realBuffer, imagBuffer, &scaleFactor, synth_out_fx, negate(st_fx->Q_syn2), CLDFB_NO_COL_MAX, workBuffer ); - - /* Bring CLDFB output to Q-1 */ - Scale_sig( synth_out_fx, output_frame, negate(st_fx->Q_syn2) ); - st_fx->Q_syn2 = 0; - move16(); - - /* save synthesis - needed in case of core switching */ - Copy( synth_out_fx, st_fx->previoussynth_fx, output_frame ); - st_fx->Q_syn2 = 0; - move16(); - - /*--------------------------------------------------------* - * calculate the average frame energy - *--------------------------------------------------------*/ - frame_ener_fx( L_FRAME, st_fx->clas_dec, syn_fx, mult_r(pitch_buf_fx[3],512), &L_Ng_ener, L_FRAME, st_fx->Q_syn, 3, 0 ); - /*--------------------------------------------------------* - * optimized for NO_S@-26dBov with street noise @ SNR=25dB - *--------------------------------------------------------*/ - - /* ng_ener = 10.0f * (float)log10(ng_ener + 0.01f) - 90.3087f + 15; */ - L_Ng_ener = L_max(1, L_Ng_ener); - tmp16 = norm_l(L_Ng_ener); - exp2 = Log2_norm_lc(L_shl(L_Ng_ener, tmp16)); - tmp16 = sub(30, tmp16); - ng_ener = mac_r(L_shl(L_mac(-1233858L, tmp16, 24660), 8+2), exp2, 771); - /* st_fx->ng_ener_ST = 0.7f * st_fx->ng_ener_ST + 0.3f * ng_ener; */ - st_fx->Ng_ener_ST_fx = mac_r(L_mult(st_fx->Ng_ener_ST_fx, 22938), ng_ener, 9830); - move16(); - - /*-----------------------------------------------------------------* - * Bandwidth extension 6kHz-8kHz - *-----------------------------------------------------------------*/ - - test(); - test(); - IF( sub(output_frame,L_FRAME16k) >= 0 && (sub(st_fx->cldfbSyn_fx->bandsToZero, sub( st_fx->cldfbSyn_fx->no_channels, 10 )) != 0 || sub(st_fx->last_flag_filter_NB, 1) != 0 ) ) - { - hf_synth_amr_wb_fx( st_fx->core_brate_fx, output_frame, Aq_fx, exc2_fx, syn_fx, st_fx->mem_syn_hf_fx, - st_fx->delay_syn_hf_fx, &st_fx->prev_r_fx, &st_fx->fmerit_w_sm_fx, &amr_io_class, st_fx->mem_hp_interp_fx, synth_out_fx, - class_para_fx, hf_gain_fx, voice_factors_fx, pitch_buf_fx, st_fx->Ng_ener_ST_fx, lsf_new_fx, - &st_fx->frame_count_fx, &st_fx->ne_min_fx, &st_fx->fmerit_m_sm_fx, &st_fx->voice_fac_amr_wb_hf, &st_fx->unvoicing_fx, &st_fx->unvoicing_sm_fx, - &st_fx->unvoicing_flag_fx, &st_fx->voicing_flag_fx, &st_fx->start_band_old_fx, &st_fx->OptCrit_old_fx, st_fx->Q_exc, st_fx->Q_syn2 ); - } - ELSE - { - hf_synth_amr_wb_reset_fx( &st_fx->seed2_fx, st_fx->mem_syn_hf_fx, st_fx->mem_hp_interp_fx, - &st_fx->prev_r_fx, &st_fx->fmerit_w_sm_fx, st_fx->delay_syn_hf_fx, &st_fx->frame_count_fx, - &st_fx->ne_min_fx, &st_fx->fmerit_m_sm_fx, &st_fx->voice_fac_amr_wb_hf, - &st_fx->unvoicing_fx, &st_fx->unvoicing_sm_fx, &st_fx->unvoicing_flag_fx, - &st_fx->voicing_flag_fx, &st_fx->start_band_old_fx, &st_fx->OptCrit_old_fx ); - } - - /*----------------------------------------------------------------------* - * Updates - *----------------------------------------------------------------------*/ - - updt_dec_fx( st_fx, L_FRAME, coder_type, old_exc_fx, pitch_buf_fx, 0, Aq_fx , lsf_new_fx, lsp_new_fx, voice_factors_fx, dummy_buf_fx, gain_buf ); - - /* update old_Aq[] - needed in improv_amr_wb_gs_fx() */ - Copy( Aq_fx, st_fx->old_Aq_fx, NB_SUBFR * (M+1) ); - - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - if (!st_fx->bfi_fx - && st_fx->prev_bfi_fx - && L_sub(st_fx->last_total_brate_fx, HQ_48k) >= 0 - && sub(st_fx->last_codec_mode, MODE2) == 0 - && (sub(st_fx->last_core_bfi, TCX_20_CORE) == 0 || sub(st_fx->last_core_bfi, TCX_10_CORE) == 0) - && st_fx->plcInfo.concealment_method == TCX_NONTONAL - && L_sub(st_fx->plcInfo.nbLostCmpt, 4) < 0 ) - { - waveadj_rec = 1; - move16(); - } - - /* update main codec parameters */ - st_fx->last_core_fx = st_fx->core_fx; - move16(); - st_fx->last_extl_fx = -1; - move16(); - st_fx->last_codec_mode = st_fx->codec_mode; - move16(); - st_fx->last_L_frame_fx = L_FRAME; - move16(); - st_fx->last_core_brate_fx = st_fx->core_brate_fx; - move16(); - st_fx->last_codec_mode = st_fx->codec_mode; - move16(); - st_fx->last_bwidth_fx = WB; - move16(); - st_fx->last_total_brate_ber_fx = st_fx->total_brate_fx; - move32(); - st_fx->prev_Q_exc = st_fx->Q_exc; - move16(); - if ( !st_fx->bfi_fx ) - { - st_fx->last_total_brate_fx = st_fx->total_brate_fx; - move32(); - st_fx->last_good_fx = st_fx->clas_dec; - move16(); - } - st_fx->last_vad_fx = vad_flag; - move16(); - st_fx->last_flag_cna = flag_cna; - move16(); - - /*----------------------------------------------------------------* - * Overlap of ACELP synthesis with old MDCT memory - *----------------------------------------------------------------*/ - - if( st_fx->bfi_fx ) - { - /* calculate another loss frame to fill gap in case of switching frame loss */ - acelp_core_switch_dec_bfi_fx( st_fx, st_fx->fer_samples_fx, coder_type ); - } - - delay_comp = NS2SA_fx2(st_fx->output_Fs_fx, DELAY_CLDFB_NS); - Scale_sig(st_fx->delay_buf_out_fx, delay_comp, sub(st_fx->Q_syn2,st_fx->Q_old_postdec)); - st_fx->Q_old_postdec=st_fx->Q_syn2; - move16(); - IF( sub(last_core_ori,HQ_CORE) == 0 ) - { - Word16 step, alpha,nz; - - Scale_sig(st_fx->old_out_fx, L_FRAME48k, sub(st_fx->Q_syn2,st_fx->Q_old_wtda)); - st_fx->Q_old_wtda=st_fx->Q_syn2; - move16(); - - Copy( st_fx->delay_buf_out_fx,synth_out_fx, delay_comp ); /* copy the HQ/ACELP delay synchroniation buffer at the beginning of ACELP frame */ - - i = 15; - move16(); - tmps = NS2SA_fx2(st_fx->output_Fs_fx, 6000000L); - nz = NS2SA_fx2(st_fx->output_Fs_fx, N_ZERO_MDCT_NS); - step = Inv16(tmps, &i); - step = shl(step, i); - alpha = 0; - move16(); - - test(); - IF( st_fx->prev_bfi_fx && st_fx->HqVoicing_fx ) - { - Copy_Scale_sig( st_fx->fer_samples_fx, &st_fx->old_out_fx[nz], tmps,negate(st_fx->Q_syn2)); - } - - FOR (i = 0; i < tmps; i++) - { - synth_out_fx[i+delay_comp] = msu_r(L_mult(synth_out_fx[i+delay_comp], alpha), st_fx->old_out_fx[i+nz], add(alpha, -32768)); - move16(); - alpha = add(alpha, step); - } - } - - st_fx->prev_bfi_fx = st_fx->bfi_fx; - st_fx->last_con_tcx = st_fx->con_tcx; - - if( L_sub(st_fx->core_brate_fx,SID_1k75) > 0 ) - { - st_fx->last_active_brate_fx = st_fx->total_brate_fx; - move32(); - } - - test(); - IF( L_sub(st_fx->core_brate_fx,SID_1k75) > 0 && st_fx->first_CNG_fx ) - { - if( sub(st_fx->act_cnt_fx,BUF_DEC_RATE) >= 0 ) - { - st_fx->act_cnt_fx = 0; - move16(); - } - - st_fx->act_cnt_fx = add(st_fx->act_cnt_fx,1); - - test(); - if( sub(st_fx->act_cnt_fx,BUF_DEC_RATE) == 0 && st_fx->ho_hist_size_fx > 0 ) - { - st_fx->ho_hist_size_fx = sub(st_fx->ho_hist_size_fx,1); - } - - st_fx->act_cnt2_fx = add(st_fx->act_cnt2_fx,1); - st_fx->act_cnt2_fx = s_min(st_fx->act_cnt2_fx,MIN_ACT_CNG_UPD); - } - st_fx->prev_bws_cnt_fx = 0; - st_fx->bws_cnt_fx = 0; - st_fx->bws_cnt1_fx = 0; - /*----------------------------------------------------------------* - * HP filtering - * Final synthesis output - *----------------------------------------------------------------*/ - - /* Delay ACELP synthesis by DELAY_BWE_TOTAL_NS - DELAY_CLDFB_NS delay */ - IF ( sub(output_frame,L_FRAME16k) >= 0 ) - { - tmps = NS2SA_fx2(st_fx->output_Fs_fx, DELAY_BWE_TOTAL_NS - DELAY_CLDFB_NS); - Scale_sig( st_fx->prev_synth_buffer_fx, tmps, sub(st_fx->Q_syn2, st_fx->Qprev_synth_buffer_fx) ); - - Copy( synth_out_fx, tmp_buffer_fx, output_frame ); - Copy( st_fx->prev_synth_buffer_fx, synth_out_fx, tmps ); - Copy( tmp_buffer_fx, synth_out_fx + tmps, output_frame - tmps ); - Copy( tmp_buffer_fx + output_frame - tmps, st_fx->prev_synth_buffer_fx, tmps ); - } - - if (waveadj_rec) - { - tmps = 0; - IF( sub(output_frame,L_FRAME16k) >= 0 ) - { - tmps = NS2SA_fx2(st_fx->output_Fs_fx, DELAY_BWE_TOTAL_NS); - } - - waveform_adj2_fix(st_fx->tonalMDCTconceal.secondLastPcmOut, - synth_out_fx+tmps, - st_fx->plcInfo.data_noise, - &st_fx->plcInfo.outx_new_n1_fx, - &st_fx->plcInfo.nsapp_gain_fx, - &st_fx->plcInfo.nsapp_gain_n_fx, - &st_fx->plcInfo.recovery_gain, - st_fx->plcInfo.step_concealgain_fx, - st_fx->plcInfo.Pitch_fx, - st_fx->plcInfo.FrameSize, - tmps, - add(extract_l(st_fx->plcInfo.nbLostCmpt), 1), - st_fx->bfi_fx); - } - - /* HP filter */ - Scale_sig32( st_fx->L_mem_hp_out_fx, 4, sub(st_fx->Q_syn2, st_fx->Qprev_synth_buffer_fx) ); - st_fx->Qprev_synth_buffer_fx = st_fx->Q_syn2; - hp20( synth_out_fx, 1/*stride*/, output_frame, st_fx->L_mem_hp_out_fx, L_mult0(output_frame, 50) ); - - /* save synthesis for core switching */ - Copy_Scale_sig( synth_out_fx+NS2SA_fx2( st_fx->output_Fs_fx,ACELP_LOOK_NS+DELAY_BWE_TOTAL_NS), st_fx->old_synth_sw_fx, NS2SA_fx2(st_fx->output_Fs_fx,FRAME_SIZE_NS-ACELP_LOOK_NS-DELAY_BWE_TOTAL_NS), sub(st_fx->Q_old_postdec, st_fx->Q_syn2) ); - - { - /* TCX-LTP Postfilter: used in AMR-WB IO to update memories and to avoid discontinuities when the past frame was TCX */ - Word16 delta = NS2SA_fx2( st_fx->output_Fs_fx, TCXLTP_DELAY_NS ); - Scale_sig(st_fx->tcxltp_mem_in, delta, sub(st_fx->Q_syn2, st_fx->Qprev_synth_buffer_fx)); - Scale_sig(st_fx->tcxltp_mem_out, output_frame, sub(st_fx->Q_syn2, st_fx->Qprev_synth_buffer_fx)); - tcx_ltp_post( st_fx->tcxltp, ACELP_CORE, output_frame, st_fx->L_frame_past, 0, synth_out_fx, NULL, - delta, 0, 0, 0, 0, &st_fx->tcxltp_pitch_int_post_prev, - &st_fx->tcxltp_pitch_fr_post_prev, &st_fx->tcxltp_gain_post_prev, - &st_fx->tcxltp_filt_idx_prev, st_fx->pit_res_max, - &st_fx->pit_res_max_past, - 0, 0, st_fx->tcxltp_mem_in, - st_fx->tcxltp_mem_out, st_fx->total_brate_fx ); - } - - /* final output of synthesis signal */ - syn_output_fx( st_fx->codec_mode, synth_out_fx, output_frame, output_sp, st_fx->Q_syn2 ); - - - return; -} diff --git a/src/libs/libevs/lib_dec/ari_dec.cpp b/src/libs/libevs/lib_dec/ari_dec.cpp old mode 100755 new mode 100644 index 438a538c..77c4dd95 --- a/src/libs/libevs/lib_dec/ari_dec.cpp +++ b/src/libs/libevs/lib_dec/ari_dec.cpp @@ -1,75 +1,110 @@ /*==================================================================================== - EVS Codec 3GPP TS26.442 Apr 03, 2018. Version 12.11.0 / 13.6.0 / 14.2.0 + EVS Codec 3GPP TS26.443 Nov 13, 2018. Version 12.11.0 / 13.7.0 / 14.3.0 / 15.1.0 ====================================================================================*/ +#include #include +#include "cnst.h" +#include "prot.h" +#include "stat_com.h" #include "assert.h" -#include "stl.h" -#include "basop_mpy.h" -#include "cnst_fx.h" -#include "rom_com_fx.h" -#include "prot_fx.h" +#include "basop_util.h" + + /*--------------------------------------------------------------- * Ari decode 14 bits routines -------------------------------------------------------------*/ -Word16 ari_decode_overflow(TastatDec *s) -{ - return L_sub(L_sub(s->high, 1), s->low) <= 0; -} - /** * \brief Start ArCo decoding * * \param[i/o] st * \param[o] s + * + * \return bit consumption */ -void ari_start_decoding_14bits(Decoder_State_fx *st, TastatDec *s) +void ari_start_decoding_14bits(Decoder_State *st,Tastat *s) { - Word32 val; + long val; - val = L_and(L_deposit_l(get_next_indice_fx(st, cbitsnew)), 0xffffL); + val = get_next_indice(st, cbitsnew); - s->low = L_deposit_l(0); - s->high = ari_q4new+1; - move32(); - s->vobf = val; - move32(); + s->low = 0; + s->high = ari_q4new; + s->vobf=val; } -Word16 ari_start_decoding_14bits_prm(const Word16 *ptr, Word16 bp, TastatDec *s) +/** + * \brief Start ArCo decoding + * + * \param[o] prm + * \param[i] bp + * \param[o] s + * + * \return bit consumption + */ +long ari_start_decoding_14bits_prm(const int *ptr,long bp,Tastat *s) { - Word32 val; - Word16 i; - const Word16 *p; + long val; + long i; + const int *p; - val = L_deposit_l(0); - p = ptr+bp; - FOR (i=0; ilow = L_deposit_l(0); - s->high = ari_q4new+1; - move32(); - s->vobf = val; - move32(); - return add(bp,i); + s->low = 0; + s->high = ari_q4new; + s->vobf=val; + + bp=bp+i; + + + return bp; } -static Word16 ari_lookup_s17(Word32 cum, Word32 range, UWord16 const *cum_freq) + + +/** + * \brief Only for 17 symbols with new extended Tables: + * based on tri's optimization + * based on extended Tables which need less branches for coding + * + * \param[i/o] st + * \param[o] res + * \param[i/o] s + * \param[i] cum_freq + * + * \return bit consumption + */ +void ari_decode_14bits_s17_ext(Decoder_State *st, + int *res, + Tastat *s, + const unsigned short *cum_freq) { - Word32 tmp; - const UWord16 *p; - Word16 range_l, range_h; + unsigned long symbol; + unsigned long low, high, range, value; + unsigned long cum; + unsigned short const *p; + + + + + /* read s->low,high,vobf sequentially */ + low = s->low; + high = s->high; + value = s->vobf; + + range = high-low+1; /* keep: tmp=low-1 */ + cum =((((int) (value-low+1))<cum) p = tmp_p; */ - /* max value in p[x] is 16384 => 14 bits */ - range_l = extract_l(L_and(range,0x7FFF)); - range_h = extract_l(L_shr(range,15)); - - tmp = L_multi31x16_X2(range_h, range_l,p[8]); - if (L_sub(tmp,cum) > 0) + /* */ + if(p[8]*range>cum) { - p = p + 8; + p+= 8; } - - tmp = L_multi31x16_X2(range_h, range_l,p[4]); - if (L_sub(tmp,cum) > 0) + /* */ + if(p[4]*range>cum) { - p = p + 4; + p+= 4; } - - - tmp = L_multi31x16_X2(range_h, range_l,p[2]); - if (L_sub(tmp,cum) > 0) + /* */ + if(p[2]*range>cum) { - p = p + 2; + p+= 2; } - - tmp = L_multi31x16_X2(range_h, range_l,p[1]); - IF (L_sub(tmp,cum) > 0) + /* */ + if(p[1]*range>cum) { - p = p + 1; - - tmp = L_multi31x16_X2(range_h, range_l,p[1]); - test(); - if ( ((Word32)(&cum_freq[15] - p) == 0) && (L_sub(tmp,cum) > 0) ) + p+= 1; + if((p==cum_freq+15) && (p[1]*range>cum)) { - p = p + 1; + p+=1; } } - /* return extract_l(L_shr(L_sub((Word32)p,(Word32)cum_freq),1)); */ - L_sub(0,0); - L_shr(0,0); /* pointer subtraction */ - return extract_l(p - cum_freq); + symbol = p-cum_freq; + + high = low + mul_sbc_14bits(range,cum_freq[symbol]) - 1; + low += mul_sbc_14bits(range,cum_freq[symbol+1]); + + for (;;) + { + if ( high>=ari_q2new ) + { + if ( low>=ari_q2new ) + { + value -= ari_q2new; + low -= ari_q2new; + high -= ari_q2new; + } + else + { + if ( low>=ari_q1new && highlow = low; + s->high = high; + s->vobf = value; + + *res=symbol; } -static Word16 ari_lookup_s27(Word32 cum, Word32 range, UWord16 const *cum_freq) +/** + * \brief Only for 27 symbols with new extended Tables: + * based on tri's optimization + * based on extended Tables which need less branches for coding + * copied from ari_decode_14bits_s17_ext, with changes marked + * + * \param[i/o] st + * \param[o] res + * \param[i/o] s + * \param[i] cum_freq + */ +void ari_decode_14bits_s27_ext(Decoder_State *st, + int *res, + Tastat *s, + const unsigned short *cum_freq) { - Word32 tmp; - Word16 range_l, range_h; - Word16 il, ih, im; + unsigned long symbol; + unsigned long low, high, range, value; + unsigned long cum; + unsigned long il, ih, im; + + + + + /* read s->low,high,vobf sequentially */ + low = s->low; + high = s->high; + value = s->vobf; + + range = high-low+1; /* keep: tmp=low-1 */ + cum =((((int) (value-low+1))<cum) p = tmp_p; */ - /* max value in p[x] is 16384 => 14 bits */ - range_l = extract_l(L_and(range,0x7FFF)); - range_h = extract_l(L_shr(range,15)); - /* begin change when compared with ari_decode_14bits_s17_ext, - starting with line: tmp = L_multi31x16_X2(range_h, range_l, p[8]); */ + starting with line: if (p[8] * range > cum) { */ il = 0; - move16(); ih = 27; - move16(); /* do a five step binary search, using the interval [il, ih) */ - im = 13; - move16(); /* (il + ih) >> 1 */ - tmp = L_multi31x16_X2(range_h, range_l, cum_freq[im]); - tmp = L_sub(tmp, cum); - if (tmp > 0) + im = 13; /* (il + ih) >> 1 */ + if (cum_freq[im] * range > cum) { il = im; - move16(); } - if (tmp <= 0) + else { ih = im; - move16(); } - im = shr(add(il, ih), 1); - tmp = L_multi31x16_X2(range_h, range_l, cum_freq[im]); - tmp = L_sub(tmp, cum); - if (tmp > 0) + im = (il + ih) >> 1; + if (cum_freq[im] * range > cum) { il = im; - move16(); } - if (tmp <= 0) + else { ih = im; - move16(); } - im = shr(add(il, ih), 1); - tmp = L_multi31x16_X2(range_h, range_l, cum_freq[im]); - tmp = L_sub(tmp, cum); - if (tmp > 0) + im = (il + ih) >> 1; + if (cum_freq[im] * range > cum) { il = im; - move16(); } - if (tmp <= 0) + else { ih = im; - move16(); } - im = shr(add(il, ih), 1); - tmp = L_multi31x16_X2(range_h, range_l, cum_freq[im]); - tmp = L_sub(tmp, cum); - if (tmp > 0) + im = (il + ih) >> 1; + if (cum_freq[im] * range > cum) { il = im; - move16(); } - if (tmp <= 0) + else { ih = im; - move16(); } - IF (sub(sub(ih, il), 1) > 0) /* if the interval has more than one symbol */ + if (ih - il > 1) /* if the interval has more than one symbol */ { /* here, only ih == il + 2 is possible, which means two symbols in the interval */ - im = add(il, 1); /* (il + ih) >> 1 */ - tmp = L_multi31x16_X2(range_h, range_l, cum_freq[im]); - tmp = L_sub(tmp, cum); - if (tmp > 0) + im = il + 1; /* (il + ih) >> 1 */ + if (cum_freq[im] * range > cum) { il = im; - move16(); } } - return il; -} + symbol = il; + /* end change when compared with ari_decode_14bits_s17_ext, + ending with line: symbol = p - cum_freq; */ -static Word16 ari_lookup_bit(Word32 cum, Word32 range, UWord16 const *cum_freq) -{ - Word16 symbol = 0; /* initialize just to avoid compiler warning */ + high = low + mul_sbc_14bits(range,cum_freq[symbol]) - 1; + low += mul_sbc_14bits(range,cum_freq[symbol+1]); - (void)cum_freq; - - range = L_shl(range, 13); /* L_multi31x16_X2(range_h, range_l, 8192) */ - cum = L_sub(range, cum); - - if (cum > 0) + for (;;) { - symbol = 1; - move16(); - } - if (cum <= 0) - { - symbol = 0; - move16(); - } - - return symbol; -} - -static Word16 ari_decode_14bits_ext( - Decoder_State_fx *st, - TastatDec *s, - UWord16 const *cum_freq, - Word16 (*lookup_fn)(Word32 cum, Word32 range, UWord16 const *cum_freq) -) -{ - Word32 cum; - Word16 symbol; - Word32 low; - Word32 high; - Word32 range; - Word32 value; - Word16 i; - - low = L_add(0,s->low); - high = L_add(0,s->high); - value = L_add(0,s->vobf); - - range = L_sub(high, low); - - cum = L_add(L_shl(L_sub(value, low), stat_bitsnew), sub(shl(1,stat_bitsnew),1)); - if (cum < 0) - { - cum = L_add(0,0x7fffffff); - } - - symbol = lookup_fn(cum, range, cum_freq); - - high = L_add(low,mul_sbc_14bits(range,cum_freq[symbol])); - low = L_add(low,mul_sbc_14bits(range,cum_freq[symbol+1])); - - FOR (i = 0; i < 0x7FFF; i++) - { - Word32 L_msb_diff, L_msb_low, L_msb_high; - - L_msb_high = L_shr(L_sub(high,1),14); - L_msb_low = L_shr(low,14); - L_msb_diff = L_sub(L_msb_high, L_msb_low); - IF (L_sub(L_msb_diff,2) >= 0) + if ( high>=ari_q2new ) { - BREAK; + if ( low>=ari_q2new ) + { + value -= ari_q2new; + low -= ari_q2new; + high -= ari_q2new; + } + else + { + if ( low>=ari_q1new && highlow = low; - move32(); + s->low = low; s->high = high; - move32(); s->vobf = value; - move32(); - return symbol; -} - - -/** - * \brief Only for 17 symbols with new extended Tables - */ -Word16 ari_decode_14bits_s17_ext(Decoder_State_fx *st, TastatDec *s, UWord16 const *cum_freq) -{ - return ari_decode_14bits_ext(st, s, cum_freq, ari_lookup_s17); -} - -/** - * \brief Only for 27 symbols with new extended Tables - */ -Word16 ari_decode_14bits_s27_ext(Decoder_State_fx *st, TastatDec *s, UWord16 const *cum_freq) -{ - return ari_decode_14bits_ext(st, s, cum_freq, ari_lookup_s27); + *res=symbol; } /** * \brief Only for decoding one bit with uniform probability: + * based on tri's optimization + * copied from ari_decode_14bits_s17_ext, with changes marked * the equivalent cum_freq table used is {16384, 8192, 0} + * + * \param[i/o] st + * \param[o] res + * \param[i/o] s */ -Word16 ari_decode_14bits_bit_ext(Decoder_State_fx *st, TastatDec *s) +void ari_decode_14bits_bit_ext(Decoder_State *st, + int *res, + Tastat *s + ) { - static const UWord16 cum_freq[3] = {16384, 8192, 0}; - return ari_decode_14bits_ext(st, s, cum_freq, ari_lookup_bit); -} + unsigned long symbol; + unsigned long low, high, range, value; + unsigned long cum; -static Word16 ari_lookup_pow(TastatDec *s, Word16 base) -{ - Word32 cum, range; - Word16 symbol; - Word16 range_h, range_l; - Word16 pows[12]; /* "base" to the power of 2, 4, 8,... 2^12 */ - Word16 lowlim, highlim, testval; - Word16 k; - range = L_sub(s->high, s->low); - cum = L_add(L_shl(L_sub(s->vobf, s->low), stat_bitsnew), sub(shl(1,stat_bitsnew),1)); - range_h = extract_l(L_shr(range,15)); - range_l = extract_l(L_and(range,0x7FFF)); + /* read s->low,high,vobf sequentially */ + low = s->low; + high = s->high; + value = s->vobf; + + range = high-low+1; /* keep: tmp=low-1 */ + cum =((((int) (value-low+1))<cum) p = tmp_p; */ + + /* begin change when compared with ari_decode_14bits_s17_ext, + starting with line: if (p[8] * range > cum) { */ symbol = 0; - move16(); - lowlim = shr(base, 1); - highlim = 16384; - move16(); - /* search for the interval where "cum" fits */ - IF (L_sub(L_multi31x16_X2(range_h, range_l, lowlim), cum) > 0) /* below pow-1 */ - { - pows[0] = base; - move16(); - testval = base; - move16(); - /* increase exponent until it is smaller than "cum" */ - FOR (k = 1; k < 12; k++) - { - highlim = testval; - move16(); - pows[k] = mult_r(pows[k-1], pows[k-1]); - move16(); - testval = mult_r(pows[k], base); - - IF (L_sub(L_multi31x16_X2(range_h, range_l, shr(testval, 1)), cum) <= 0) /* found! big range is [lowlim,testval], (now narrow it down) */ - { - lowlim = testval; - move16(); - k = sub(k, 1); - symbol = shl(1, k); - BREAK; - } - } - assert(k < 12); /* maximum 2^10-1*/ - - /* narrow the range down */ - FOR (k = sub(k, 2); k >= 0; k--) - { - testval = mult_r(highlim, pows[k+1]); - - IF (L_sub(L_multi31x16_X2(range_h, range_l, shr(testval, 1)), cum) <= 0) - { - lowlim = testval; - move16(); - symbol = sub(symbol, shl(1, k)); - } - ELSE - { - highlim = testval; - move16(); - } - } - - highlim = shr(highlim, 1); - lowlim = shr(lowlim, 1); - } - - s->high = L_add(s->low, mul_sbc_14bits(range, highlim)); - move32(); - s->low = L_add(s->low, mul_sbc_14bits(range, lowlim)); - move32(); - - return symbol; -} - -static Word16 ari_lookup_sign(TastatDec *s, Word16 base) -{ - Word32 cum, range; - Word16 symbol; - - (void)base; - - range = L_sub(s->high, s->low); - cum = L_sub(s->vobf, s->low); - range = L_shr(range, 1); - - IF (L_sub(range, cum) > 0) + if ((range << 13) > cum) { symbol = 1; - move16(); - s->high = L_add(s->low, range); - move32(); - } - ELSE - { - symbol = 0; - move16(); - s->low = L_add(s->low, range); - move32(); } - return symbol; -} - -static Word16 ari_decode_14bits_notbl( - Word16 *ptr, - Word16 bp, - Word16 bits, - Word16 *res, - TastatDec *s, - Word16 base, - Word16 (*lookup_fn)(TastatDec *s, Word16 base) -) -{ - Word16 symbol; - Word32 low, high, value; - - symbol = lookup_fn(s, base); - - low = L_add(s->low, 0); - high = L_add(s->high, 0); - value = L_add(s->vobf, 0); - - FOR (; bp> 1); + } + else + { + high = low + (range >> 1) - 1; + /* low is unchanged */ + } + /* end change when compared with ari_decode_14bits_s17_ext, + ending with line: low += mul_sbc_14bits(range, cum_freq[symbol + 1]); */ - L_msb_high = L_shr(L_sub(high,1),14); - L_msb_low = L_shr(low,14); - L_msb_diff = L_sub(L_msb_high, L_msb_low); - IF (L_sub(L_msb_diff,2) >= 0) + + for (;;) + { + if ( high>=ari_q2new ) { - BREAK; + if ( low>=ari_q2new ) + { + value -= ari_q2new; + low -= ari_q2new; + high -= ari_q2new; + } + else + { + if ( low>=ari_q1new && highlow, low) == 0) && (L_sub(s->high, L_sub(high,1)) == 0) && (L_sub(s->vobf, value) == 0)))) - { - /* This should not happen except of bit errors. */ - s->high = 0; - move32(); - s->low = 0; - move32(); - *res = 0; - move16(); - return -1; + value = (value<<1) | get_next_indice_1(st); /* */ } s->low = low; - move32(); s->high = high; - move32(); s->vobf = value; - move32(); - *res = symbol; - move16(); - - return bp; + *res=symbol; } /*------------------------------------------------------------------------ @@ -513,18 +421,219 @@ static Word16 ari_decode_14bits_notbl( * p(x = q>0) = exp(- (q-0.5)*base* 2) - exp(- (q+0.5)*base*2 ) * *-------------------------------------------------------------------------*/ -Word16 ari_decode_14bits_pow(Word16 *ptr, Word16 bp, Word16 bits, Word16 *res, TastatDec *s, Word16 base) +long ari_decode_14bits_pow(const int *ptr, long bp, long bits, int *res, Tastat *s, unsigned base) { - return ari_decode_14bits_notbl(ptr, bp, bits, res, s, base, ari_lookup_pow); + unsigned long symbol; + unsigned long low, high, range, value; + unsigned long cum; + Word16 pows[12]; /* "base" to the power of 2, 4, 8,... 2^12 */ + Word16 lowlim, highlim=0, testval; + int k; + + + + low = s->low; + high = s->high + 1; + value = s->vobf; + lowlim = 0; + symbol = 0; + + range = high - low; + + /* the value read from bit-stream */ + assert(value >= low); + cum = ((((int) (value - low)) << stat_bitsnew) + (1 << stat_bitsnew) - 1); + + /* search for the interval where "cum" fits */ + if (((base >> 1) * range) > cum) /* below pow-1 */ + { + pows[0] = testval = base; + /* increase exponent until it is smaller than "cum" */ + for (k=1; k<12; k++) + { + highlim = testval; + pows[k] = mult_r(pows[k-1], pows[k-1]); + move16(); + testval = mult_r(pows[k], base); + if (((testval >> 1) * range) <= cum) /* found! big range is [lowlim,testval], (now narrow it down) */ + { + lowlim = testval; + k--; + symbol = 1<0; k--) + { + testval = mult_r(highlim, pows[k]); + if (((testval >> 1) * range) <= cum) + { + lowlim = testval; + symbol -= 1<<(k-1); + } + else + { + highlim = testval; + } + + + } + highlim >>= 1; + lowlim >>= 1; + } + else /* trivial case, above pow-1, that is, first symbol */ + { + symbol = 0; + lowlim = base >> 1; + highlim = 16384; + } + + + high = low + mul_sbc_14bits(range, highlim); + + low += mul_sbc_14bits(range, lowlim); + + /*ptr init for ptr*/ + for (; bp < bits;) + { + if (high > ari_q2new) + { + if (low >= ari_q2new) + { + value -= ari_q2new; + low -= ari_q2new; + high -= ari_q2new; + } + else + { + if (low >= ari_q1new && high <= ari_q3new) + { + value -= ari_q1new; + low -= ari_q1new; + high -= ari_q1new; + } + else + { + break; + } + } + } + low += low; + high += high; + + value = (value << 1) | ptr[bp++]; + } + + if( !(bp != bits || ! ((s->low == (int) low) && (s->high == (int) high) && (s->vobf == (int) value)) ) ) + { + /* This should not happen except of bit errors. */ + s->high = s->low = 0; + *res = 0; + return -1; + } + + s->low = low; + s->high = high - 1; + s->vobf = value; + + *res = symbol; + + + return bp; } + + /*------------------------------------------------------------------------ * Function: ari_decode_14bits_sign * * Decode a sign with equal probabilities. *-------------------------------------------------------------------------*/ -Word16 ari_decode_14bits_sign(Word16 *ptr, Word16 bp, Word16 bits, Word16 *res, TastatDec *s) +long ari_decode_14bits_sign(const int *ptr, long bp, long bits, int *res, Tastat *s) { - return ari_decode_14bits_notbl(ptr, bp, bits, res, s, 0, ari_lookup_sign); + unsigned long symbol; + unsigned long low, high, range, value; + unsigned long cum; + + + + low = s->low; + high = s->high + 1; + value = s->vobf; + + range = high - low; + + if (bp < bits) + { + assert(value >= low); + cum = ((((int) (value - low)) << stat_bitsnew) + (1 << stat_bitsnew) - 1); + if (8192 * range > cum) + { + symbol = 2; + high = low + (range >> 1); + } + else + { + symbol = 1; + low += range >> 1; + } + + /*ptr init for ptr*/ + for (; bp < bits;) + { + if (high > ari_q2new) + { + if (low >= ari_q2new) + { + value -= ari_q2new; + low -= ari_q2new; + high -= ari_q2new; + } + else + { + if (low >= ari_q1new && high <= ari_q3new) + { + value -= ari_q1new; + low -= ari_q1new; + high -= ari_q1new; + } + else + { + break; + } + } + } + low += low; + high += high; + + value = (value << 1) | ptr[bp++]; + } + } + else + { + cum = value-low; + range >>= 1; + if (range > cum) + { + symbol = 2; + high = low + range; + } + else + { + symbol = 1; + low += range; + } + } + + s->low = low; + s->high = high - 1; + s->vobf = value; + + *res = symbol; + + + return bp; } diff --git a/src/libs/libevs/lib_dec/ari_hm_dec.cpp b/src/libs/libevs/lib_dec/ari_hm_dec.cpp old mode 100755 new mode 100644 index 7ca73e98..f7db14ba --- a/src/libs/libevs/lib_dec/ari_hm_dec.cpp +++ b/src/libs/libevs/lib_dec/ari_hm_dec.cpp @@ -1,152 +1,127 @@ /*==================================================================================== - EVS Codec 3GPP TS26.442 Apr 03, 2018. Version 12.11.0 / 13.6.0 / 14.2.0 + EVS Codec 3GPP TS26.443 Nov 13, 2018. Version 12.11.0 / 13.7.0 / 14.3.0 / 15.1.0 ====================================================================================*/ - -#include -#include -#include -#include +#include "cnst.h" #include "stl.h" -#include "cnst_fx.h" #include "basop_util.h" -#include "rom_com_fx.h" -#include "prot_fx.h" +#include +#include +#include "prot.h" +#include "rom_com.h" -Word16 -DecodeIndex( - Decoder_State_fx *st, - Word16 Bandwidth, - Word16 *PeriodicityIndex) +/*-------------------------------------------------------------------* + * DecodeIndex() + * + * + *-------------------------------------------------------------------*/ + +int DecodeIndex( + Decoder_State *st, + int Bandwidth, + int *PeriodicityIndex) { - test(); - IF ( (st->tcx_hm_LtpPitchLag > 0) && sub(st->tcxltp_gain, kLtpHmGainThr) > 0) + if ((st->tcx_hm_LtpPitchLag > 0) && (st->tcxltp_gain > kLtpHmGainThr)) { - Word16 LtpPitchIndex = sub(mult_r(st->tcx_hm_LtpPitchLag, 1 << (15-kLtpHmFractionalResolution)), 2); - + int LtpPitchIndex = ((st->tcx_hm_LtpPitchLag + (1 << (kLtpHmFractionalResolution - 1))) >> kLtpHmFractionalResolution) - 2; *PeriodicityIndex = kLtpHmFlag; - move16(); - *PeriodicityIndex = s_or(*PeriodicityIndex, get_next_indice_fx(st, NumRatioBits[Bandwidth][LtpPitchIndex])); - *PeriodicityIndex = add(*PeriodicityIndex, 1); - move16(); - *PeriodicityIndex = s_or(*PeriodicityIndex, shl(LtpPitchIndex, 9)); - move16(); - + *PeriodicityIndex |= get_next_indice(st, NumRatioBits[Bandwidth][LtpPitchIndex]); + ++*PeriodicityIndex; + *PeriodicityIndex |= LtpPitchIndex << 9; return NumRatioBits[Bandwidth][LtpPitchIndex]; } - ELSE + else { - *PeriodicityIndex = get_next_indice_fx(st, 8); - move16(); + *PeriodicityIndex = get_next_indice(st, 8); return 8; } } -static Word16 tcx_hm_dequantize_gain( - Word16 coder_type, /* i : coder type Q0 */ - Word16 gain_idx, /* i: quantization index Q0 */ - Word16 *gain /* o: dequantized gain Q11 */ + +/*-------------------------------------------------------------------* + * tcx_hm_dequantize_gain() + * + * + *-------------------------------------------------------------------*/ + +static int tcx_hm_dequantize_gain( + int coder_type, /* i: GC/VC mode */ + int gain_idx, /* i: quantization index */ + Word16 *gain /* o: dequantized gain (Q11) */ ) { - assert(0 <= coder_type && coder_type <= 1); /* safety check in case of bit errors */ - test(); - IF(!(0 <= gain_idx && sub(gain_idx,(1 << kTcxHmNumGainBits)) < 0)) + if( !(0 <= gain_idx && gain_idx < (1 << kTcxHmNumGainBits)) ) { *gain = 0; return 1; } *gain = qGains[coder_type][gain_idx]; - move16(); return 0; } + +/*-------------------------------------------------------------------* + * tcx_hm_decode() + * + * + *-------------------------------------------------------------------*/ + void tcx_hm_decode( - Word16 L_frame, /* i: number of spectral lines Q0 */ - Word32 env[], /* i/o: envelope shape Q16 */ - Word16 targetBits, /* i: target bit budget Q0 */ - Word16 coder_type, /* i: coder_type Q0 */ - Word16 prm_hm[], /* i: HM parameters Q0 */ - Word16 LtpPitchLag, /* i: LTP pitch lag or -1 if none Q0 */ - Word16 *hm_bits /* o: bit consumption Q0 */ + int L_frame, /* i: number of spectral lines */ + Word32 env[], /* i/o: envelope shape (Q16) */ + int targetBits, /* i: target bit budget */ + int coder_type, /* i: GC/VC mode */ + const int prm_hm[],/* i: HM parameters */ + short LtpPitchLag, /* i: LTP pitch lag or -1 if none */ + float LtpGain, /* i: LTP gain */ + int *hm_bits /* o: bit consumption */ ) { - Word16 NumTargetBits; - Word16 fract_res; - Word32 lag; - Word16 gain; - Word16 L_frame_m_256; - Word16 p[2*kTcxHmParabolaHalfWidth+1]; - - + int NumTargetBits, fract_res, lag; + Word16 p[2*kTcxHmParabolaHalfWidth+1], gain; *hm_bits = 0; - move16(); - L_frame_m_256 = sub(L_frame,256); - - test(); - IF( !(sub(coder_type,VOICED) == 0 || sub(coder_type,GENERIC) == 0) ) + if( !(coder_type == VOICED || coder_type == GENERIC) ) { /* A bit error was encountered */ *hm_bits = -1; - move16(); return; } - NumTargetBits = CountIndexBits( (L_frame_m_256 >= 0), prm_hm[1] ); + NumTargetBits = CountIndexBits( L_frame >= 256, prm_hm[1]) + targetBits; - NumTargetBits = add(NumTargetBits,targetBits); - - if ( sub(coder_type,VOICED) == 0 ) + if (coder_type == VOICED) { - NumTargetBits = add(NumTargetBits,kTcxHmNumGainBits); + NumTargetBits += kTcxHmNumGainBits; } - - *hm_bits = add(sub(NumTargetBits, targetBits), 1); - move16(); + *hm_bits = NumTargetBits - targetBits + 1; /* Convert the index to lag */ - UnmapIndex( - prm_hm[1], - (L_frame_m_256 >= 0), - LtpPitchLag, - (( sub(NumTargetBits,kSmallerLagsTargetBitsThreshold) <= 0 ) || ( L_frame_m_256 < 0 )), - &fract_res, - &lag - ); - test(); - test(); + UnmapIndex( prm_hm[1], L_frame >= 256, LtpPitchLag, (NumTargetBits <= kSmallerLagsTargetBitsThreshold) || (L_frame < 256), &fract_res, &lag ); /* Render the harmonic model */ - IF( tcx_hm_render( lag, fract_res, p ) ) + if( tcx_hm_render( lag, fract_res, LtpGain, p ) ) { /* A bit error was encountered */ *hm_bits = -1; - move16(); return; } /* Dequantize gain */ - IF( tcx_hm_dequantize_gain(sub(coder_type,VOICED) == 0,prm_hm[2],&gain) ) + + if( tcx_hm_dequantize_gain( coder_type==VOICED,prm_hm[2],&gain ) ) { /* A bit error was encountered */ *hm_bits = -1; return; } + tcx_hm_modify_envelope( gain, lag, fract_res, p, env, L_frame ); - tcx_hm_modify_envelope( - gain, - lag, - fract_res, - p, - env, - L_frame - ); - + return; } - diff --git a/src/libs/libevs/lib_dec/arith_coder_dec.cpp b/src/libs/libevs/lib_dec/arith_coder_dec.cpp old mode 100755 new mode 100644 index 982660ed..4916b6b4 --- a/src/libs/libevs/lib_dec/arith_coder_dec.cpp +++ b/src/libs/libevs/lib_dec/arith_coder_dec.cpp @@ -1,232 +1,182 @@ /*==================================================================================== - EVS Codec 3GPP TS26.442 Apr 03, 2018. Version 12.11.0 / 13.6.0 / 14.2.0 + EVS Codec 3GPP TS26.443 Nov 13, 2018. Version 12.11.0 / 13.7.0 / 14.3.0 / 15.1.0 ====================================================================================*/ -#include -#include -#include +#include #include - #include "options.h" -#include "cnst_fx.h" -#include "rom_com_fx.h" -#include "stl.h" -#include "prot_fx.h" +#include "cnst.h" +#include "prot.h" +#include "rom_com.h" +#include "basop_util.h" +#include "basop_proto_func.h" -/* Returns: number of bits consumed */ -static Word16 tcx_arith_decode( - Word16 L_frame, /* i: number of spectral lines Q0 */ - const Word16 envelope[], /* i: scaled envelope Q15-e */ - Word16 envelope_e, /* i: scaled envelope exponent Q0 */ - Word16 target_bits, /* i: target bit budget Q0 */ - Word16 prm[], /* i: bit-stream Q0 */ - Word32 q_spectrum[], /* o: scalar quantized spectrum Q31-e */ - Word16 *q_spectrum_e, /* o: spectrum exponent Q0 */ - Word16 *nf_seed /* o: noise filling seed Q0 */ + +/*-------------------------------------------------------* + * tcx_arith_decode() + * + * + *-------------------------------------------------------*/ + +static int tcx_arith_decode( /* o: number of bits consumed */ + int L_frame, /* i: number of spectral lines */ + const Word16 envelope[], /* i: scaled envelope (Q15-e) */ + Word16 envelope_e, /* i: scaled envelope exponent (Q0) */ + int target_bits, /* i: target bit budget */ + const int prm[], /* i: bit-stream */ + float q_spectrum[] /* o: scalar quantized spectrum */ ) { - Word16 bp, k, q, s; - TastatDec as; - Word16 exp_k; + int bp, k, q, s; + Tastat as; + unsigned int exp_k; Word16 tmp; - Word32 L_tmp, Q; + bp = ari_start_decoding_14bits_prm(prm, 0, &as); + tmp = sub(envelope_e, 1); - tmp = sub(envelope_e, 1+15); - L_tmp = L_deposit_l(0); - FOR (k = 0; k < L_frame; k++) + for (k=0; k 0 || sub(target_bits, (ACELP_13k20/50)) > 0 || (target_bits <= 0) ) + if( L_spec > N_MAX_ARI || (target_bits > (ACELP_13k20/50)) || (target_bits <= 0) ) { /* this could happen in case of bit errors */ st->BER_detect = 1; - move16(); L_spec = N_MAX_ARI; - move16(); *signaling_bits = 0; - move16(); *arith_bits = 0; - move16(); - set32_fx( q_spectrum, 0, L_frame ); + set_zero( q_spectrum, L_frame ); return; } - tcx_cfg = &st->tcx_cfg; *signaling_bits = 0; - move16(); + assert(st->enableTcxLpc); - gamma_w = 32767/*1.0f Q15*/; - move16(); - gamma_uw = st->inv_gamma; - move16(); + gamma_w = 1.0f; + gamma_uw = 1.0f/st->gamma; - tcx_arith_render_envelope( - A_ind, - L_frame, - L_spec, - tcx_cfg->preemph_fac, - gamma_w, - gamma_uw, - env - ); + tcx_arith_render_envelope( A_ind, L_frame, L_spec, FL2WORD16(tcx_cfg->preemph_fac), FL2WORD16(gamma_w), FL2WORD16(0.5f*gamma_uw), env ); - IF (use_hm != 0) + if (use_hm) { - IF (prm_hm[0] != 0) + if (prm_hm[0]) { - tcx_hm_decode( - L_spec, - env, - target_bits, - tcx_cfg->coder_type, - prm_hm, - tcxltp_pitch, - &hm_bits - ); + tcx_hm_decode( L_spec, env, target_bits, coder_type, prm_hm, tcxltp_pitch, tcxltp_gain, &hm_bits ); - IF (hm_bits < 0) + if (hm_bits < 0) { st->BER_detect = 1; - move16(); *signaling_bits = 0; - move16(); *arith_bits = 0; - move16(); - set32_fx( q_spectrum, 0, L_frame ); + set_zero( q_spectrum, L_frame ); + return; } } - ELSE + else { hm_bits = 1; - move16(); } - *signaling_bits = add(*signaling_bits, hm_bits); - move16(); - } - ELSE - { - prm_hm[0] = 0; /* just to be sure */ move16(); + *signaling_bits += hm_bits; } L_spec_core = L_spec; - move16(); if (st->igf) { - L_spec_core = s_min(L_spec_core, st->hIGFDec.infoIGFStartLine); + L_spec_core = min(L_spec_core, st->hIGFDec.infoIGFStartLine); } envelope = (Word16*)env; + tcx_arith_scale_envelope( L_spec, L_spec_core, env, target_bits, low_complexity, envelope, &envelope_e ); - tcx_arith_scale_envelope( - L_spec, - L_spec_core, - env, - target_bits, - low_complexity, - envelope, - &envelope_e - ); - - *arith_bits = tcx_arith_decode( - L_spec, - envelope, - envelope_e, - target_bits, - prm, - q_spectrum, - q_spectrum_e, - nf_seed - ); - move16(); + *arith_bits = tcx_arith_decode( L_spec, envelope, envelope_e, target_bits, prm, q_spectrum ); /* safety check in case of bit errors */ - IF( *arith_bits < 0 ) + if( *arith_bits < 0 ) { st->BER_detect = 1; - move16(); - set32_fx(q_spectrum, 0, L_frame); + set_zero( q_spectrum, L_frame ); } - set32_fx(q_spectrum + L_spec, 0, sub(L_frame, L_spec)); + for (k=L_spec; k +#include "options.h" +#include "prot.h" +#include "options.h" +#include "cnst.h" + + +/*-----------------------------------------------------------------* + * AVQ_demuxdec() + * + * Demultiplex and decode subvectors using + * split algebraic vector dequantizer based on RE8 latice. + *-----------------------------------------------------------------*/ + +void AVQ_demuxdec( + Decoder_State *st, /* i/o: decoder state structure */ + int xriq[], /* o: decoded subvectors [0..8*Nsv-1] */ + short *nb_bits, /* i/o: number of allocated bits */ + const short Nsv, /* i: number of subvectors */ + short nq_out[] /* i/o: AVQ nq index */ +) +{ + short i,j, bits, order_v; + long I[NSV_MAX]; + int nq[NSV_MAX], *kv, code[8]; + + kv = xriq; /* reuse vector to save memory */ + bits = *nb_bits; + + for(i = 0; i 8 ) + { + /* read the unary code including the stop bit for nq[i] */ + nq[i] = -1; + do + { + (nq[i])++; + + if (5 * nq[i] + 4 == bits) + { + break; + } + } + while ( get_next_indice_1( st ) ); + + if( 5*nq[i]+4 == bits ) /* check the overflow */ + { + bits++; /* overflow stop bit */ + } + + /* check for potential bit errors */ + if( nq[i] > NB_SPHERE ) + { + st->BER_detect = 1; + set_i( xriq, 0, Nsv*8 ); + set_s( nq_out, 0, Nsv ); + *nb_bits = 0; + + return; + } + + bits -= (short)nq[i]; + bits--; /* count the stop bit */ + + if( nq[i] > 0 ) + { + nq[i]++; + } + + /* read codebook indices (rank I and event. Voronoi index kv) */ + if( nq[i] == 0 ) /* Q0 */ + { + /* nothing to read */ + } + else if( nq[i] < 5 ) /* Q2, Q3, Q4 */ + { + I[i] = get_next_indice( st, (short)(4*nq[i]) ); + bits -= (short)(4*nq[i]); + } + else if( nq[i]%2 == 0 ) /* Q4 + Voronoi extensions r=1,2,3,... */ + { + I[i] = get_next_indice( st, 4*4 ); + bits -= 4*4; + order_v = (short)(nq[i]/2) - 2; + + for( j=0; j<8; j++ ) + { + kv[i*8+j] = get_next_indice( st, order_v ); + } + bits -= 8*order_v; + } + else /* Q3 + Voronoi extensions r=1,2,3,... */ + { + I[i] = get_next_indice( st, 4*3 ); + bits -= 4*3; + order_v = (short)(nq[i]/2) - 1; + + for( j=0; j<8; j++ ) + { + kv[i*8+j] = get_next_indice( st, order_v ); + } + bits -= 8*order_v; + } + } + } /* for */ + + /* decode all subvectors */ + for( i=0; i=0; l-- ) + { + nq = indx[l]; /* quantizer number (0,2,3..n) */ + + nk = 0; + n = nq; + + if( nq > 4 ) + { + nk = (nq-3)>>1; + n = nq - nk*2; + } + + /* read n groups of 4-bit for Voronoi index (k[]) */ + for( i=0; i<8; i++) + { + kv[i] = 0; + } + + while( nk-- > 0 ) + { + ival = (indx[pos--] & 0x0F); + ival <<= 4; + ival += (indx[pos--] & 0x0F); + + for( i=7; i>=0; i-- ) + { + kv[i] <<= 1; + kv[i] += (ival & 0x01); + ival >>= 1; + } + } + + /* read n groups of 4-bit for base codebook index (I) */ + I = 0; + while( n-- > 0 ) + { + I <<= 4; + I += (indx[pos--] & 0x0F); + } + + /* multi-rate RE8 decoder */ + re8_dec( nq, I, kv, c ); + + /* write decoded RE8 vector */ + for( i=0; i<8; i++ ) + { + nvecq[(l*8)+i] = c[i]; + } + } + + return; +} diff --git a/src/libs/libevs/lib_dec/avq_dec_fx.cpp b/src/libs/libevs/lib_dec/avq_dec_fx.cpp deleted file mode 100755 index ad02fa39..00000000 --- a/src/libs/libevs/lib_dec/avq_dec_fx.cpp +++ /dev/null @@ -1,241 +0,0 @@ -/*==================================================================================== - EVS Codec 3GPP TS26.442 Apr 03, 2018. Version 12.11.0 / 13.6.0 / 14.2.0 - ====================================================================================*/ - -#include "options.h" /* Compilation switches */ -#include "cnst_fx.h" /* Common constants */ -#include "rom_com_fx.h" /* Static table prototypes */ -#include "prot_fx.h" /* Function prototypes */ -#include "stl.h" - -/*-----------------------------------------------------------------* - * Function AVQ_Demuxdec_Bstr * - * ~~~~~~~~~~~~~~~~~~ * - * Read indexes from one bitstream and decode subvectors. * - *-----------------------------------------------------------------*/ - -void AVQ_demuxdec_fx( - Decoder_State_fx *st_fx, /* i/o: decoder state structure */ - Word16 xriq[], /* o: decoded subvectors [0..8*Nsv-1] */ - Word16 *nb_bits, /* i/o: number of allocated bits */ - const Word16 Nsv, /* i: number of subvectors */ - Word16 nq_out[] /* i/o: AVQ nq index */ -) -{ - Word16 i,j, bits, order_v; - UWord16 I[NSV_MAX]; - Word16 nq[NSV_MAX], *kv, code[8]; - Word16 tmp16; - - set16_fx( (Word16*)I, 0, NSV_MAX ); - set16_fx( code, 0, 8 ); - - kv = xriq; /* reuse vector to save memory */ - bits = *nb_bits; - move16(); - - FOR( i=0; i 0 ) - { - /* read the unary code including the stop bit for nq[i] */ - nq[i] = -1; - move16(); - tmp16 = 0; - move16(); - DO - { - nq[i] = add(nq[i], 1); - move16(); - - tmp16 = extract_l(L_mac0(4,nq[i],5)); - tmp16 = sub(tmp16,bits); - IF( tmp16 == 0 ) - { - BREAK; - } - } - WHILE( get_next_indice_1_fx(st_fx) != 0 ); - - if( tmp16 == 0 ) /* check the overflow */ - { - bits = add(bits,1); /* overflow stop bit */ - } - - /* check for potential bit errors */ - IF( sub(nq[i], NB_SPHERE) > 0 ) - { - st_fx->BER_detect = 1; - move16(); - set16_fx( xriq, 0, shl(Nsv,3) ); - set16_fx( nq_out, 0, Nsv ); - *nb_bits = 0; - move16(); - - return; - } - - bits = sub(bits,nq[i]); - bits = sub(bits,1); /* count the stop bit */ - - if( nq[i] > 0 ) - { - nq[i] = add(nq[i],1); - move16(); - } - - /* read codebook indices (rank I and event. Voronoi index kv) */ - IF( nq[i] != 0 ) /* for Q0 nothing to read */ - { - IF( sub(nq[i], 5) < 0 ) /* Q2, Q3, Q4 */ - { - tmp16 = shl(nq[i], 2); - order_v = 0; - move16(); - } - ELSE /* for Q3/Q4 + Voronoi extensions r=1,2 */ - { - j = 1; - move16(); - if( s_and(nq[i], 1) == 0 ) - { - j = add(j,1); - } - order_v = sub(shr(nq[i], 1), j); /* Voronoi order determination */ - tmp16 = shl(add(j, 2), 2); - } - - I[i] = get_next_indice_fx(st_fx, tmp16 ); - move16(); - bits = sub(bits, tmp16); - - IF( order_v > 0 ) - { - tmp16 = shl(i, 3); - FOR( j=0; j<8; j++ ) - { - kv[tmp16+j] = (Word16)get_next_indice_fx(st_fx, order_v ); - move16(); - } - bits = sub(bits, shl(order_v, 3)); - } - } - } - } - - /* decode all subvectors */ - FOR( i=0; i=0; l--) - { - nq = indx[l]; /* quantizer number (0,2,3..n) */ move16(); - - nk = 0; - move16(); - n = nq; - move16(); - - IF (sub(nq, 4) > 0) - { - nk = shr(sub(nq, 3), 1); - n = sub(nq, shl(nk, 1)); - } - - /* read n groups of 4-bit for Voronoi index (k[]) */ - - FOR (i=0; i<8; i++) - { - kv[i] = 0; - move16(); - } - - FOR ( ; nk > 0; nk--) - { - ival = s_and(indx[pos--], 0x0F); - ival = shl(ival, 4); - ival = add(ival, s_and(indx[pos--], 0x0F)); - - FOR (i=7; i>=0; i--) - { - kv[i] = shl(kv[i], 1); - kv[i] = add(kv[i], s_and(ival, 0x01)); - move16(); - ival = shr(ival, 1); - } - } - - /* read n groups of 4-bit for base codebook index (I) */ - I = L_deposit_l(0); - FOR (; n > 0; n--) - { - I = L_shl(I, 4); - I = L_add(I, (Word32) s_and(indx[pos--], 0x0F)); - } - - /* multi-rate RE8 decoder */ - I16 = (UWord16)extract_l(I); - cast16(); - re8_dec_fx(nq, I16, kv, c); - - /* write decoded RE8 vector */ - FOR (i=0; i<8; i++) - { - nvecq[(l*8)+i] = c[i]; - move16(); - } - } - - return; -} diff --git a/src/libs/libevs/lib_dec/basop_util_jbm.cpp b/src/libs/libevs/lib_dec/basop_util_jbm.cpp deleted file mode 100755 index 73e9f226..00000000 --- a/src/libs/libevs/lib_dec/basop_util_jbm.cpp +++ /dev/null @@ -1,38 +0,0 @@ -/*==================================================================================== - EVS Codec 3GPP TS26.442 Apr 03, 2018. Version 12.11.0 / 13.6.0 / 14.2.0 - ====================================================================================*/ - -/*! @file basop_util_jbm.c basop utility functions for JBM. */ - -#include "basop_util.h" -#include "basop_util_jbm.h" -#include "options.h" -#include "stl.h" - -/* Adds two uint32_t values with overflow like plain C. */ -Word32 rtpTs_add( Word32 ts1, Word32 ts2 ) -{ - Word32 ret; - - Carry = 0; - ret = L_add_c(ts1, ts2); - Carry = 0; - Overflow = 0; - - return ret; -} - -/* Subtracts two uint32_t values with overflow like plain C. */ -Word32 rtpTs_sub( Word32 ts1, Word32 ts2 ) -{ - Word32 ret; - - BASOP_SATURATE_WARNING_OFF - Carry = 1; - ret = L_sub_c(ts1, ts2); - BASOP_SATURATE_WARNING_ON - Carry = 0; - Overflow = 0; - - return ret; -} diff --git a/src/libs/libevs/lib_dec/basop_util_jbm.h b/src/libs/libevs/lib_dec/basop_util_jbm.h deleted file mode 100755 index 8832730b..00000000 --- a/src/libs/libevs/lib_dec/basop_util_jbm.h +++ /dev/null @@ -1,18 +0,0 @@ -/*==================================================================================== - EVS Codec 3GPP TS26.442 Apr 03, 2018. Version 12.11.0 / 13.6.0 / 14.2.0 - ====================================================================================*/ - -/*! @file basop_util_jbm.h basop utility functions for JBM. */ - -#ifndef BASOP_UTIL_JBM_H -#define BASOP_UTIL_JBM_H - -#include "typedef.h" - -/*! Adds two uint32_t values with overflow like plain C. */ -Word32 rtpTs_add( Word32 ts1, Word32 ts2 ); - -/*! Subtracts two uint32_t values with overflow like plain C. */ -Word32 rtpTs_sub( Word32 ts1, Word32 ts2 ); - -#endif diff --git a/src/libs/libevs/lib_dec/bass_psfilter.cpp b/src/libs/libevs/lib_dec/bass_psfilter.cpp new file mode 100644 index 00000000..7ab090d6 --- /dev/null +++ b/src/libs/libevs/lib_dec/bass_psfilter.cpp @@ -0,0 +1,470 @@ +/*==================================================================================== + EVS Codec 3GPP TS26.443 Nov 13, 2018. Version 12.11.0 / 13.7.0 / 14.3.0 / 15.1.0 + ====================================================================================*/ + +#include +#include +#include "prot.h" +#include "cnst.h" +#include "rom_com.h" +#include "options.h" +#include + +/*---------------------------------------------------------------------* + * Local constants + *---------------------------------------------------------------------*/ + +#define NBPSF_L_EXTRA 120 + +#define BPF_STOP_STOPBAND_16 16 + + +/*---------------------------------------------------------------------* + * Local functions + *---------------------------------------------------------------------*/ + +static short Pit_track( float syn[], short T ); + +/*---------------------------------------------------------------------* + * bass_psfilter_init() + * + * Initialisation of postfiltering variables + *---------------------------------------------------------------------*/ + +void bass_psfilter_init( + float old_syn[], /* o : Old synthesis buffer 1 */ + float *mem_deemph_err, /* o : Error deemphasis memory */ + float *lp_ener /* o : long_term error signal energy */ +) +{ + /* post-filter memories */ + *mem_deemph_err = 0.0f; + *lp_ener = 0.0f; + set_f( old_syn, 0, NBPSF_PIT_MAX ); + + return; +} + +/*---------------------------------------------------------------------* + * bass_psfilter() + * + * Perform low-frequency postfiltering + *---------------------------------------------------------------------*/ + +void bass_psfilter( + const short Opt_AMR_WB, /* i : AMR-WB IO flag */ + const float synth_in[], /* i : input synthesis (at 16kHz) */ + const short L_frame, /* i : length of the last frame */ + const float pitch_buf[], /* i : pitch for every subfr [0,1,2,3] */ + float old_syn[], /* i/o: NBPSF_PIT_MAX */ + float *mem_deemph_err, /* i/o: Error deemphasis memory */ + float *lp_ener, /* i/o: long_term error signal energy */ + const short bpf_off, /* i : do not use BPF when set to 1 */ + float v_stab, /* i : stability factor */ + float *v_stab_smooth, /* i/o: smoothed stability factor */ + float *mem_mean_pit, /* i/o: average pitch memory */ + short *Track_on_hist, /* i/o: History of half frame usage */ + short *vibrato_hist, /* i/o: History of frames declared as vibrato*/ + float *psf_att, /* i/o: Post filter attenuation factor */ + const short coder_type, /* i : coder_type */ + float bpf_noise_buf[] /* o : BPF error signal (at int_fs) */ +) +{ + short i, i_subfr, T; + float gain, alpha, corr, ener; + float syn_buf[NBPSF_PIT_MAX+L_FRAME16k+NBPSF_PIT_MAX], *syn; + float syn2_buf[L_FRAME16k], *syn2; + float err[L_HALFR16k]; + short T_sf[NB_SUBFR16k]; + short nb_subfr, T_update; + float delta_v_stab; + short dist_pit_diff, idx_pit_min, idx_pit_max, vibrato, Track_on; + float loc_pit_max, loc_pit_min, diff_pit; + float TrackOnR, vibratR, alp_tmp; + + Track_on = 0; + T_update = 01; + vibrato = 0; + nb_subfr = L_frame/L_SUBFR; + + /*------------------------------------------------------- + * Initialize pointers to various synthesis buffers + * + * |--------------------syn_buf--------------------------------| + * |-----old_syn-----|-------synth_in--------|----extrapol---- | + * |--NBPSF_PIT_MAX--| sf1 | sf2 | sf3 | sf4 |--NBPSF_PIT_MAX--| + * |------syn2_buf---------| + * |------L_frame----------| + * |----bpf_noise_buf------| + * + *-------------------------------------------------------*/ + + mvr2r( old_syn, syn_buf, NBPSF_PIT_MAX ); + mvr2r( synth_in, syn_buf + NBPSF_PIT_MAX, L_frame ); + + if( !(pitch_buf == NULL || bpf_off) ) + { + for(i = L_TRACK_HIST-1; i > 0; i--) + { + mem_mean_pit[i] = mem_mean_pit[i-1]; + } + + mem_mean_pit[i] = mean( pitch_buf, nb_subfr ); + } + + idx_pit_min = minimum(mem_mean_pit, L_TRACK_HIST, &loc_pit_min); + idx_pit_max = maximum(mem_mean_pit, L_TRACK_HIST, &loc_pit_max); + + dist_pit_diff = (short)abs(idx_pit_max - idx_pit_min); + diff_pit = loc_pit_max-loc_pit_min; + + if( L_frame == L_FRAME16k ) + { + diff_pit *= 0.8f; + } + + if( coder_type != INACTIVE && diff_pit >= 2.0f && diff_pit < 10 && dist_pit_diff>= 3) + { + vibrato = 1; + } + + TrackOnR = (float)sum_s(Track_on_hist,L_TRACK_HIST)/L_TRACK_HIST; + vibratR = (float)sum_s(vibrato_hist,L_TRACK_HIST); + alp_tmp = 1.0f-TrackOnR; + + if( vibrato ) + { + vibratR = vibratR * vibratR * -0.009f + 1.0f; + alp_tmp *= vibratR; + } + + alp_tmp = max( 0.1f, alp_tmp ); + + if( alp_tmp > *psf_att ) + { + *psf_att = 0.05f * alp_tmp + 0.95f * *psf_att; + } + else + { + *psf_att = 0.4f * alp_tmp + 0.6f * *psf_att; + } + + if( pitch_buf == NULL || bpf_off ) + { + /* do not use BPF for HQ core */ + T_update = 80; + set_s( T_sf, 0, 5 ); + syn = &syn_buf[NBPSF_PIT_MAX+L_frame]; + for (i=0; i NBPSF_PIT_MAX ) + { + T_sf[i] = NBPSF_PIT_MAX; + } + } + else + { + if( T_sf[i] > PIT_MAX ) + { + T_sf[i] = PIT_MAX; + } + } + } + + T = T_sf[nb_subfr-1]; + syn = &syn_buf[NBPSF_PIT_MAX+L_frame]; + for( i=0; i=PIT_MIN && Opt_AMR_WB ) + { + T = Pit_track( syn, T ); + + if( T != T_sf[i_subfr/L_SUBFR] ) + { + Track_on = 1; + } + } + + /* symetric pitch prediction : phase is opposite between harmonic */ + for( i=0; i 0.5f) + { + alpha = 0.5f; + } + + alpha *= (*psf_att); + if (alpha > 0.3f && Track_on) + { + alpha = 0.3f; + } + else if (alpha > 0.4f && vibrato ) + { + alpha = 0.4f; + } + + if( alpha < 0.0f ) + { + alpha = 0.0f; + } + + *v_stab_smooth = 0.8f * v_stab + 0.2f * (*v_stab_smooth); + delta_v_stab = (float) fabs(*v_stab_smooth - v_stab); + v_stab = (float) pow(v_stab, 0.5f); + alpha = (1.0f + 0.15f*v_stab - 2.0f*delta_v_stab) * alpha; + + for (i=0; i 0; i-- ) + { + Track_on_hist[i] = Track_on_hist[i-1]; + vibrato_hist[i] = vibrato_hist[i-1]; + } + + Track_on_hist[i] = Track_on; + vibrato_hist[i] = vibrato; + + mvr2r( syn_buf+L_frame, old_syn, NBPSF_PIT_MAX ); + + return; +} + + +/*---------------------------------------------------------------------* + * Pit_track() + * + * Perform pitch tracking and test pitch/2 to avoid continuous pitch doubling + *---------------------------------------------------------------------*/ + +static short Pit_track(/* o : Pitch */ + float syn[], /* i : synthesis [-NBPSF_PIT_MAX..L_HALFR16k] */ + short T /* i : pitch period (>= PIT_MIN) */ +) +{ + short i, T2; + float tmp, corr, ener, cn; + float *v1, *v2; + + /*----------------------------------------------------------------* + * Test pitch/2 to avoid continuous pitch doubling + * (short pitch is limited to PIT_MIN (34 = 376Hz) by the encoder + *----------------------------------------------------------------*/ + + T2 = T>>1; + + v1 = &syn[-NBPSF_L_EXTRA]; + v2 = &syn[-T2-NBPSF_L_EXTRA]; + + ener = 0.01f; + for (i=0; i 0.95f) + { + T = T2; + } + + return(T); +} + + +/*---------------------------------------------------------------------* + * addBassPostFilter() + * + * Add BPF component in cldfb domain + *---------------------------------------------------------------------*/ + +void addBassPostFilter( + const float *harm_timeIn, + int samplesToProcess, + float **rAnalysis, + float **iAnalysis, + HANDLE_CLDFB_FILTER_BANK cldfb +) +{ + float *tmp_R[CLDFB_NO_COL_MAX]; + float *tmp_I[CLDFB_NO_COL_MAX]; + float cldfbBufferReal[CLDFB_NO_COL_MAX][20]; + float cldfbBufferImag[CLDFB_NO_COL_MAX][20]; + short i, b; + int maxBand; + const float *weights; + int nCol = cldfb->no_col; + int nColToProcess = nCol; + int nChan = cldfb->no_channels; + + if( samplesToProcess > -1 ) + { + nColToProcess = ((samplesToProcess + cldfb->no_channels - 1) / cldfb->no_channels); + } + + assert(nCol == 16); + + weights = bpf_weights_16; + + if( nChan > BPF_STOP_STOPBAND_16 ) + { + maxBand = BPF_STOP_STOPBAND_16; + } + else + { + maxBand = nChan; + } + + for (i=0; i < nColToProcess; i++) + { + tmp_R[i] = cldfbBufferReal[i]; + tmp_I[i] = cldfbBufferImag[i]; + } + + /* do the analysis of filtered signal */ + cldfbAnalysis( harm_timeIn, tmp_R, tmp_I, samplesToProcess, cldfb ); + + /* now do the subtraction */ + for( i = 0; i < nColToProcess; i++ ) + { + /* loop over low frequency bands */ + for( b = 0; b < maxBand; b++ ) + { + rAnalysis[i][b] -= weights[b] * tmp_R[i][b]; + iAnalysis[i][b] -= weights[b] * tmp_I[i][b]; + } + } + + return; +} diff --git a/src/libs/libevs/lib_dec/bass_psfilter_fx.cpp b/src/libs/libevs/lib_dec/bass_psfilter_fx.cpp deleted file mode 100755 index 1c40769a..00000000 --- a/src/libs/libevs/lib_dec/bass_psfilter_fx.cpp +++ /dev/null @@ -1,868 +0,0 @@ -/*==================================================================================== - EVS Codec 3GPP TS26.442 Apr 03, 2018. Version 12.11.0 / 13.6.0 / 14.2.0 - ====================================================================================*/ - -#include -#include -#include "options.h" /* Compilation switches */ -#include "prot_fx.h" /* Function prototypes */ -#include "cnst_fx.h" /* Common constants */ -#include "rom_com_fx.h" /* Static table prototypes */ -#include "rom_dec_fx.h" /* Static table prototypes */ - -#include "stl.h" -#include "basop_mpy.h" -#include "basop_util.h" - -/*---------------------------------------------------------------------* - * Local constants - *---------------------------------------------------------------------*/ - -#define NBPSF_L_EXTRA 120 -#define BPF_STOP_STOPBAND_16 16 - -/*---------------------------------------------------------------------* - * Local functions - *---------------------------------------------------------------------*/ -static Word16 Pit_track_fx(Word16 syn[], Word16 T); - -/*---------------------------------------------------------------------* - * bass_psfilter_init() - * - * Initialisation of postfiltering variables - *---------------------------------------------------------------------*/ -void bass_psfilter_init_fx( - Word16 old_syn[], /* o : Old synthesis buffer 1 */ - Word16 *mem_deemph_err, /* o : Error deemphasis memory */ - Word16 *lp_ener /* o : long_term error signal energy */ -) -{ - /* post-filter memories */ - *mem_deemph_err = 0; - move16(); - *lp_ener = 0; - move16();/*0 in Q8 */ - set16_fx(old_syn, 0, NBPSF_PIT_MAX); - - return; -} - -/*=========================================================================*/ -/* FUNCTION : void bass_psfilter_fx () */ -/*-------------------------------------------------------------------------*/ -/* PURPOSE : */ -/*-------------------------------------------------------------------------*/ -/* INPUT ARGUMENTS : */ -/* _ Word16 synth_in_fx[], Q_syn2-1 i :input synthesis (at 16kHz) */ -/* _ const Word16 L_frame, i : length of the last frame */ -/* _ Word16 pitch_buf_fx[],Q6 i : pitch for every subfr [0,1,2,3] */ -/* _ const Word16 bpf_off, i : do not use BPF when set to 1 */ -/* _ Word16 v_stab_fx, Q15 i : stability factor */ -/* _ Word16 Q_syn i : Q format of synth_in_fx */ -/*-------------------------------------------------------------------------*/ -/* OUTPUT ARGUMENTS : */ -/* _ Word16 *mem_deemph_err, Q_syn2-1 */ -/* o : Error deemphasis memory */ -/* _ Word16 *lp_ener, Q8 o : long_term error signal energy */ -/*-------------------------------------------------------------------------*/ -/* INPUT/OUTPUT ARGUMENTS : */ -/* _ Word16 old_syn_fx[], Q_syn2-1 i/o: NBPSF_PIT_MAX */ -/* _ Word16 *v_stab_smooth_fx,Q15 i/o: smoothed stability factor */ -/*-------------------------------------------------------------------------*/ -/* RETURN ARGUMENTS : */ -/* _ None */ -/*-------------------------------------------------------------------------*/ -/* CALLED FROM : TX/RX */ -/*=========================================================================*/ - -void bass_psfilter_fx( - const Word16 Opt_AMR_WB, /* i : AMR-WB IO flag */ - Word16 synth_in_fx[], /* i : input synthesis (at 16kHz) */ - const Word16 L_frame, /* i : length of the last frame */ - Word16 pitch_buf_fx[], /* i : pitch for every subfr [0,1,2,3] */ - Word16 old_syn_fx[], /* i/o: NBPSF_PIT_MAX */ - Word16 *mem_deemph_err, /* o : Error deemphasis memory */ - Word16 *lp_ener, /* o : long_term error signal energy */ - const Word16 bpf_off, /* i : do not use BPF when set to 1 */ - Word16 v_stab_fx, /* i : stability factor */ - Word16 *v_stab_smooth_fx, /* i/o: smoothed stability factor */ - Word16 *mem_mean_pit, /* i/o: average pitch memory */ - Word16 *Track_on_hist, /* i/o: History of half frame usage */ - Word16 *vibrato_hist, /* i/o: History of frames declared as vibrato*/ - Word16 *psf_att, /* i/o: Post filter attenuation factor */ - const Word16 coder_type, /* i : coder_type */ - Word16 Q_syn, - Word16 bpf_noise_buf[] /* o : BPF error signal (at int_fs) */ -) -{ - Word16 i, j, i_subfr, T, exp, exp2; - Word16 tmp, gain, alpha, tmp2; - Word32 Lcorr, Lener; - Word32 Lcorr0,Lener0,Ltmp; - Word16 syn_buf_fx[NBPSF_PIT_MAX+L_FRAME16k+NBPSF_PIT_MAX], *syn_fx; - Word16 syn2_buf_fx[L_FRAME16k], *syn2_fx; - Word16 err[L_HALFR16k], *sigPtr, *sigPtr1; - Word16 T_sf[NB_SUBFR16k]; - Word16 subfr_pos; - Word16 nb_subfr; - Word16 delta_v_stab; - Word16 T_update = 0; - Word16 dist_pit_diff, idx_pit_min, idx_pit_max, vibrato, Track_on; - Word16 loc_pit_max, loc_pit_min, diff_pit; - Word16 TrackOnR, vibratR, alp_tmp; - Word16 Q_syn2x; - - - Track_on = 0; - move16(); - vibrato = 0; - move16(); - - nb_subfr = shr(L_frame,6); - move16(); - - /*------------------------------------------------------- - * Initialize pointers to various synthesis buffers - * - * |--------------------syn_buf--------------------------------| - * |-----old_syn-----|-------synth_in--------|----extrapol---- | - * |--NBPSF_PIT_MAX--| sf1 | sf2 | sf3 | sf4 |--NBPSF_PIT_MAX--| - * |------syn2_buf---------| - * |------L_frame----------| - * |----bpf_noise_buf------| - * - *-------------------------------------------------------*/ - Q_syn2x = shl(Q_syn, 1); - move16(); - - Copy(old_syn_fx, syn_buf_fx, NBPSF_PIT_MAX); - Copy(synth_in_fx, syn_buf_fx+NBPSF_PIT_MAX, L_frame); - - test(); - IF( !(pitch_buf_fx == NULL || bpf_off) ) - { - FOR(i = L_TRACK_HIST-1; i > 0; i--) - { - mem_mean_pit[i] = mem_mean_pit[i-1]; - move16(); /*Q6 */ - } - Ltmp = L_deposit_l(0); - FOR(j=0; j Q4*/ - if(sub(nb_subfr,5)==0) - { - tmp = mult_r(tmp, 26214); /* multiply by 0.8 for case where L_frame == L_FRAME16k*/ - } - mem_mean_pit[i] = tmp; /*Q4 */ move16(); - } - idx_pit_min = minimum_fx(mem_mean_pit, L_TRACK_HIST, &loc_pit_min); - idx_pit_max = maximum_fx(mem_mean_pit, L_TRACK_HIST, &loc_pit_max); - - dist_pit_diff = abs_s(sub(idx_pit_max,idx_pit_min)); - diff_pit = sub(loc_pit_max,loc_pit_min); /*Q4 */ - - if( sub(L_frame,L_FRAME16k) == 0) - { - diff_pit = mult_r(diff_pit,26214); /*Q4 */ - } - - test(); - test(); - test(); - if( coder_type != INACTIVE && sub(diff_pit,2<<4) >= 0 && sub(diff_pit,10<<4) < 0 && sub(dist_pit_diff,3)>= 0) - { - vibrato = 1; - move16(); - } - - tmp = sum16_fx(Track_on_hist,L_TRACK_HIST); - TrackOnR = round_fx(L_shl(L_mult0(tmp,3277),16)); /*Q15 */ - - vibratR = sum16_fx(vibrato_hist,L_TRACK_HIST); /*Q0 */ - - alp_tmp = sub(32767,TrackOnR); /*Q15 */ - - IF( vibrato ) - { - /* vibratR = vibratR * vibratR * -0.009f + 1.0f;move16(); */ - tmp = round_fx(L_shl(L_mult0(vibratR,vibratR),16)); /*Q0 */ - tmp = round_fx(L_shl(L_mult(tmp,18874),9)); /*Q15 */ - vibratR = sub(32767,tmp); /*Q15 */ - alp_tmp = mult_r(alp_tmp,vibratR); /*Q15 */ - } - - alp_tmp = s_max( 3277, alp_tmp ); - - IF( sub(alp_tmp,*psf_att) > 0 ) - { - /**psf_att = add(mult_r(1638,alp_tmp),mult_r(31130,*psf_att)); //Q15 */ - *psf_att = round_fx(L_mac(L_mult(1638,alp_tmp),31130,*psf_att)); /*Q15 */ - } - ELSE - { - /**psf_att = add(mult_r(13107,alp_tmp),mult_r(19661,*psf_att)); //Q15 */ - *psf_att = round_fx(L_mac(L_mult(13107,alp_tmp),19661,*psf_att)); /*Q15 */ - } - test(); - IF( pitch_buf_fx == NULL || bpf_off ) - { - /* do not use BPF for HQ core */ - T_update = 80; - move16(); - set16_fx( T_sf, 0, 5 ); - syn_fx = &syn_buf_fx[NBPSF_PIT_MAX+L_frame]; - sigPtr = syn_fx-T_update; - FOR (i=0; i=0 && Opt_AMR_WB ) - { - T = Pit_track_fx(syn_fx, T); - - if(sub(T,T_sf[subfr_pos]) != 0) - { - Track_on = 1; - move16(); - } - } - - /* symetric pitch prediction : phase is opposite between harmonic */ - sigPtr = syn_fx - T; - sigPtr1 = syn_fx + T; - FOR (i=0; i 0) - { - exp = sub(exp, 1); - } - exp2 = sub(exp, exp2); /* exponent num - exponent denom */ - /* gain = corr / ener */ - gain = div_s(round_fx(L_shl(Ltmp, exp)), tmp2); - if (Lcorr < 0) - { - gain = sub(0, gain); - } - - /* error of prediction for noise estimator */ - FOR (i=0; i 0) - { - exp = sub(exp, 1); - } - exp2 = sub(exp, exp2); /* exponent num - exponent denom */ - /* alpha = corr / ener */ - alpha = shr(div_s(round_fx(L_shl(Ltmp, exp)), tmp2), exp2); /*Q15 */ - if (Lcorr < 0) - { - alpha = sub(0, alpha); - } - - alpha = s_min(alpha, 16384);/*Q15 */ - - alpha = mult_r(alpha,*psf_att); - test(); - test(); - IF (sub(alpha,9830) > 0 && Track_on) - { - alpha = 9830; - move16(); - } - ELSE if (sub(alpha,13107) > 0 && vibrato ) - { - alpha = 13107; - move16(); - } - - alpha = s_max(alpha, 0); - - /**v_stab_smooth_fx = 0.8f * v_stab_fx + 0.2f * (*v_stab_smooth_fx); */ - tmp = mult(*v_stab_smooth_fx,6554); /*Q15 and 6554 is 0.2 in Q15 */ - tmp2= mult(v_stab_fx,26214);/*Q15 and 26214 is 0.8 in Q15 */ - *v_stab_smooth_fx = add(tmp2,tmp); - move16(); - - /*delta_v_stab = (float) fabs(*v_stab_smooth_fx - v_stab_fx); */ - tmp = sub(*v_stab_smooth_fx,v_stab_fx); /*Q15 */ - delta_v_stab = abs_s(tmp); - - /*v_stab_fx = (float) pow(v_stab_fx, 0.5f); */ - v_stab_fx = Frac_sqrt(v_stab_fx); - - /*alpha = (1.0f + 0.15f*v_stab_fx - 2.0f*delta_v_stab) * alpha; */ - tmp = mult(2458,v_stab_fx);/*Q14 */ - tmp = add(16384,tmp);/*Q14 */ - tmp = sub(tmp,delta_v_stab);/*Q14 */ - alpha = mult(tmp,alpha);/*Q14 */ - - FOR (i=0; i 0) - { - exp = sub(exp, 1); - } - exp2 = sub(exp, exp2); /* exponent num - exponent denom */ - /* gain = corr / ener */ - gain = div_s(round_fx(L_shl(Ltmp, exp)), tmp2); - if (Lcorr < 0) - { - gain = sub(0, gain); - } - - /* error of prediction for noise estimator */ - FOR (i=0; i 0) - { - exp = sub(exp, 1); - } - exp2 = sub(exp, exp2); /* exponent num - exponent denom */ - alpha = 0; - move16(); - - /**v_stab_smooth_fx = 0.8f * v_stab_fx + 0.2f * (*v_stab_smooth_fx); */ - tmp = mult(*v_stab_smooth_fx,6554);/*Q15 and 6554 is 0.2 in Q15 */ - tmp2= mult(v_stab_fx,26214);/*Q15 and 26214 is 0.8 in Q15 */ - - *v_stab_smooth_fx = add(tmp2,tmp); - move16(); - - FOR (i=0; i 0; i-- ) - { - Track_on_hist[i] = Track_on_hist[i-1]; - move16(); - vibrato_hist[i] = vibrato_hist[i-1]; - move16(); - } - - Track_on_hist[i] = Track_on; - move16(); - vibrato_hist[i] = vibrato; - move16(); - - Copy( syn_buf_fx+L_frame, old_syn_fx, NBPSF_PIT_MAX ); - - - return; -} - -/*==============================================================================*/ -/* FUNCTION : Word16 Pit_track_fx ( ) */ -/*------------------------------------------------------------------------------*/ -/* PURPOSE : */ -/*------------------------------------------------------------------------------*/ -/* INPUT ARGUMENTS : */ -/* Word16 syn[], st_fx->Q_syn2 i : synthesis [-PIT_MAX..L_SUBFR] */ -/* Word16 T Q0 i : pitch period (>= PIT_MIN) */ -/*------------------------------------------------------------------------------*/ -/* RETURN ARGUMENTS : */ -/* Word16 T Q0 */ -/*------------------------------------------------------------------------------*/ -/* CALLED FROM : TX/RX */ -/*==============================================================================*/ - -static Word16 Pit_track_fx( /* o : Pitch */ - Word16 syn[], /* i : synthesis [-PIT_MAX..L_SUBFR] */ - Word16 T /* i : pitch period (>= PIT_MIN) */ -) -{ - Word16 T2; - Word16 i, j; - Word32 Ltmp, Lcorr, Lener; - Word32 Ltmp0, Lcorr0, Lener0; - Word16 *v1, *v2; - Word16 exp1, exp2; - - /*----------------------------------------------------------------* - * Test pitch/2 to avoid continuous pitch doubling - * (short pitch is limited to PIT_MIN (34 = 376Hz) by the encoder - *----------------------------------------------------------------*/ - - T2 = shr(T, 1); - - v1 = &syn[-NBPSF_L_EXTRA]; - v2 = &syn[add(-T2, -NBPSF_L_EXTRA)]; - - Lener = L_deposit_h(-32768); - Ltmp = L_deposit_h(-32768); - Lcorr = L_deposit_l(2); - /* by using the maximum negative value - it is possible to gain another bit - of range for the 'Lener' sum. - It cannot be done for Lcorr - because it is a signed sum. */ - FOR (j = 0; j < 14; j++) - { - BASOP_SATURATE_WARNING_OFF - Lener0 = L_mult0(*v1, *v1); - Ltmp0 = L_mult0(*v2, *v2); - Lcorr0 = L_mult0(*v1++, *v2++); - FOR (i = 1; i < (L_HALFR16k+NBPSF_L_EXTRA)/14; i++) - { - Lener0 = L_mac0(Lener0, *v1, *v1); - Ltmp0 = L_mac0(Ltmp0, *v2, *v2); - Lcorr0 = L_mac0(Lcorr0, *v1++, *v2++); - } - BASOP_SATURATE_WARNING_ON - test(); - test(); - test(); - IF (L_sub(Lener0, 2147483647L) == 0 || - L_sub(Ltmp0, 2147483647L) == 0 || - L_sub(Lcorr0, 2147483647L) == 0 || L_sub(Lcorr0, -2147483647-1L) == 0) - { - v1 -= i; - move16(); - v2 -= i; - move16(); - FOR (i = 0; i < (L_HALFR16k+NBPSF_L_EXTRA)/14; i++) - { - Lener = L_add(Lener, L_shr(L_mult0(*v1, *v1), 6)); - Ltmp = L_add(Ltmp, L_shr(L_mult0(*v2, *v2), 6)); - Lcorr = L_add(Lcorr, L_shr(L_mult0(*v1++, *v2++), 6)); - } - } - ELSE - { - Lener = L_add(Lener, L_shr(Lener0, 6)); - Ltmp = L_add(Ltmp, L_shr(Ltmp0, 6)); - Lcorr = L_add(Lcorr, L_shr(Lcorr0, 6)); - } - } - - Lener = L_shr(Lener, 1); - Lener = L_add(Lener, 0x40000001L); - Ltmp = L_shr(Ltmp, 1); - Ltmp = L_add(Ltmp, 0x40000001L); - Lcorr = L_shr(Lcorr, 1); - /* 'Lener', 'Ltmp' & 'Lcorr' are divided by 2 */ - - /* cn = corr / (float)sqrt(ener*tmp) */ - exp1 = norm_l(Lener); - exp2 = norm_l(Ltmp); - /* Multiply the Most Significant 16 bits */ - Ltmp = L_mult0(round_fx(L_shl(Lener, exp1)), round_fx(L_shl(Ltmp, exp2))); - exp1 = add(exp1, exp2); - /* Correct if Odd # of Shifts */ - exp2 = s_and(exp1, 1); - exp1 = sub(exp1, exp2); - Ltmp = L_shr(Ltmp, exp2); - /* Call the Integer Square Root (it will normalize again if req.) */ - Ltmp = Isqrt(Ltmp); - /* We now do corr * 1 / sqrt(1/product) with high part of ratio only */ - exp1 = mac_r((16-1)*65536L-0x8000L, exp1, 16384); - exp2 = norm_l(Ltmp); - Ltmp = L_shl(Ltmp, exp2); - exp1 = sub(exp1, exp2); - exp2 = norm_l(Lcorr); - Lcorr= L_shl(Lcorr, exp2); - exp1 = sub(exp1, exp2); - Ltmp = Mpy_32_16_1(Lcorr, round_fx(Ltmp)); - /* Go to Q31 */ - Ltmp = L_shl(Ltmp, exp1); - - /* cn = normalized correlation of pitch/2 */ - if (L_sub(Ltmp, 2040109466L) > 0) /* 0.95f in Q31 */ - { - T = T2; - move16(); - } - - return T; -} - -/*---------------------------------------------------------------------* - * addBassPostFilter() - * - * Add BPF component in cldfb domain - *---------------------------------------------------------------------*/ - -void addBassPostFilterFx (const Word16 *harm_timeIn_Fx, - Word32 **rAnalysis_Fx, - Word32 **iAnalysis_Fx, - HANDLE_CLDFB_FILTER_BANK cldfbBank_bpf_Fx, - Word32 *workBuffer, - const Word16 timeIn_e, - const Word16 nTimeSlots, - const Word16 nTimeSlotsTotal, - const Word16 nBandsTotal, - CLDFB_SCALE_FACTOR *cldfb_scale - ) -{ - Word16 i, scale1, scale2; - Word16 b; - Word16 maxBand; - Word16 nChan; - CLDFB_SCALE_FACTOR scale; - const Word16 *weights_Fx; - Word32 *tmp_R_Fx[CLDFB_NO_COL_MAX]; - Word32 *tmp_I_Fx[CLDFB_NO_COL_MAX]; - Word32 cldfbBufferReal[CLDFB_NO_COL_MAX][20]; - Word32 cldfbBufferImag[CLDFB_NO_COL_MAX][20]; - - nChan = cldfbBank_bpf_Fx->no_channels; - scale1 = scale2 = 0; - move16(); - move16(); - - weights_Fx = bpf_weights_16_Fx; - maxBand = s_min(nChan, BPF_STOP_STOPBAND_16); - - assert(nChan <= 20); - - FOR (i=0; i < nTimeSlots; i++) - { - tmp_R_Fx[i] = cldfbBufferReal[i]; - tmp_I_Fx[i] = cldfbBufferImag[i]; - } - - /* do the CLDFB anlysis of filtered signal */ - cldfbAnalysisFiltering( cldfbBank_bpf_Fx, - tmp_R_Fx, - tmp_I_Fx, - &scale, - harm_timeIn_Fx, - timeIn_e, - nTimeSlots, - workBuffer - ); - - /* now do the subtraction */ - - IF (nTimeSlots > 0) - { - /* Find common scale. */ - b = s_max(cldfb_scale->lb_scale, scale.lb_scale); - scale1 = limitScale32(sub(cldfb_scale->lb_scale, b)); - scale2 = limitScale32(sub(scale.lb_scale, b)); - cldfb_scale->lb_scale = b; - move16(); - /* Rescale time slots which do not have BPF contribution. */ - FOR (i=nTimeSlots; i < nTimeSlotsTotal; i++) - { - Scale_sig32(rAnalysis_Fx[i], nBandsTotal, scale1); - Scale_sig32(iAnalysis_Fx[i], nBandsTotal, scale1); - } - } - - FOR (i=0; i < nTimeSlots; i++) - { - /* Compensate first bpf_weights coefficient which is scaled by 0.5 */ - rAnalysis_Fx[i][0] = L_sub(L_shl(rAnalysis_Fx[i][0],scale1),L_shl(Mpy_32_16_1(tmp_R_Fx[i][0],weights_Fx[0]),add(1, scale2))); - move32(); - iAnalysis_Fx[i][0] = L_sub(L_shl(iAnalysis_Fx[i][0],scale1),L_shl(Mpy_32_16_1(tmp_I_Fx[i][0],weights_Fx[0]),add(1, scale2))); - move32(); - - /* loop over remaining low frequency bands */ - FOR (b=1; b < maxBand; b++) - { - rAnalysis_Fx[i][b] = L_sub(L_shl(rAnalysis_Fx[i][b],scale1),L_shr(Mpy_32_16_1(tmp_R_Fx[i][b],weights_Fx[b]), scale2)); - move32(); - iAnalysis_Fx[i][b] = L_sub(L_shl(iAnalysis_Fx[i][b],scale1),L_shr(Mpy_32_16_1(tmp_I_Fx[i][b],weights_Fx[b]), scale2)); - move32(); - } - - /* Rescale Bands with no BPF contribution. */ - Scale_sig32(rAnalysis_Fx[i]+maxBand, sub(nBandsTotal, maxBand), scale1); - Scale_sig32(iAnalysis_Fx[i]+maxBand, sub(nBandsTotal, maxBand), scale1); - } - - return; -} diff --git a/src/libs/libevs/lib_dec/cng_dec.cpp b/src/libs/libevs/lib_dec/cng_dec.cpp new file mode 100644 index 00000000..b79ead99 --- /dev/null +++ b/src/libs/libevs/lib_dec/cng_dec.cpp @@ -0,0 +1,694 @@ +/*==================================================================================== + EVS Codec 3GPP TS26.443 Nov 13, 2018. Version 12.11.0 / 13.7.0 / 14.3.0 / 15.1.0 + ====================================================================================*/ + +#include +#include "options.h" +#include "cnst.h" +#include "prot.h" +#include "rom_com.h" + +/*---------------------------------------------------------------------* + * Local function + *---------------------------------------------------------------------*/ + +static void shb_CNG_decod( Decoder_State *st, const float *synth, float *shb_synth, const short sid_bw ); + + +/*---------------------------------------------------------------------* + * CNG_dec() + * + * Decoding of CNG parameters + *---------------------------------------------------------------------*/ + +void CNG_dec( + Decoder_State *st, /* i/o: State structure */ + const short L_frame, /* i : length of the frame */ + float Aq[], /* o : LP coefficients */ + const long core_brate, /* i : core bitrate */ + float *lsp_new, /* i/o: current frame LSPs */ + float *lsf_new, /* i/o: current frame LSFs */ + short *allow_cn_step /* o : allow CN step */ + ,short *sid_bw /* i : 0-NB/WB, 1-SWB SID */ + ,float *q_env +) +{ + float step; + short i, enr_index; + short num_bits; + float enr, weights; + short m = 0; + short ptr, j, k; + short m1; + float tmp[HO_HIST_SIZE*M]; + short burst_ho_cnt = 0; + short ll, s_ptr; + float lsf_tmp[M]; + float C[M]; + float max[2]; + short max_idx[2]; + float ftmp; + float lsp_tmp[M]; + float dev; + float max_dev; + float dist; + short env_idx[2]; + float enr1; + float env[NUM_ENV_CNG]; + float tmp_env[HO_HIST_SIZE*NUM_ENV_CNG]; + short LSF_Q_prediction; /* o : LSF prediction mode - just temporary variable in CNG */ + + /*-----------------------------------------------------------------* + * Decode CNG spectral envelope (only in SID frame) + *-----------------------------------------------------------------*/ + + if ( core_brate == SID_1k75 || core_brate == SID_2k40 ) + { + /* de-quantize the LSF vector */ + if ( st->Opt_AMR_WB ) + { + isf_dec_amr_wb( st, Aq, lsf_new, lsp_new ); + } + else + { + lsf_dec( st, 0, L_frame, INACTIVE, -1, Aq, &LSF_Q_prediction, lsf_new, lsp_new, 0 ); + } + } + else + { + /* Use old LSP vector */ + mvr2r( st->lsp_old, lsp_new, M ); + mvr2r( st->lsf_old, lsf_new, M ); + } + + /* Initialize the CNG spectral envelope in case of the very first CNG frame */ + if( st->first_CNG == 0 ) + + { + mvr2r( st->lsp_old, st->lspCNG, M ); + } + + /*-----------------------------------------------------------------* + * Decode residual signal energy + *-----------------------------------------------------------------*/ + + *allow_cn_step = 0; + if( core_brate == SID_1k75 || core_brate == SID_2k40 ) + { + if( core_brate == SID_2k40 ) + { + step = STEP_SID; + } + else + { + step = STEP_AMR_WB_SID; + } + + /* intialize the energy quantization parameters */ + if( !st->Opt_AMR_WB ) + { + num_bits = 7; + } + else + { + num_bits = 6; + } + + /* decode the energy index */ + enr_index = (short) get_next_indice( st, num_bits ); + + if ( st->last_core_brate > SID_2k40 && + st->first_CNG != 0 && + st->old_enr_index >= 0 && + enr_index > st->old_enr_index + 1 + ) + { + *allow_cn_step = 1; + } + st->old_enr_index = enr_index; + if ( enr_index == 0 ) + { + enr_index = -5; + } + st->Enew = enr_index / step - 2.0f; + + /* find the new energy value */ + st->Enew = (float)( pow( 2.0, st->Enew ) ); + + /* decode SID type */ + if( core_brate == SID_2k40 ) + { + burst_ho_cnt = (short) get_next_indice( st, 3 ); + + *sid_bw = (short) get_next_indice( st, 1 ); + if ( *sid_bw == 0 ) + { + env_idx[0] = (short) get_next_indice( st, 6 ); + + /* get quantized res_env_details */ + for ( i=0; ibwidth == WB && st->first_CNG && st->L_frame != st->last_CNG_L_frame ) + { + st->ho_hist_size = 0; + } + } + + /*---------------------------------------------------------------------* + * CNG spectral envelope update + * Find A(z) coefficients + *---------------------------------------------------------------------*/ + + if( st->last_core_brate == FRAME__NO_DATA || st->last_core_brate == SID_1k75 || st->last_core_brate == SID_2k40 ) + { + /* Reset hangover counter if not first SID period */ + if( st->core_brate > FRAME__NO_DATA ) + { + st->num_ho = 0; + } + + /* Update LSPs if last SID energy not outlier or insufficient number of hangover frames */ + if( st->num_ho < 3 || st->Enew < 1.5f * st->lp_ener ) + { + for( i=0; ilspCNG[i] = CNG_ISF_FACT * st->lspCNG[i] + (1-CNG_ISF_FACT) * lsp_new[i]; + } + } + } + else + { + /* Update CNG_mode, if allowed */ + if( ( st->Opt_AMR_WB || st->bwidth == WB ) && ( !st->first_CNG || st->act_cnt2 >= MIN_ACT_CNG_UPD ) ) + { + if( st->last_active_brate > ACELP_16k40 ) + { + st->CNG_mode = -1; + } + else if( st->last_active_brate > ACELP_13k20 ) + { + st->CNG_mode = 4; + } + else if( st->last_active_brate > ACELP_9k60 ) + { + st-> CNG_mode = 3; + } + else if( st->last_active_brate > ACELP_8k00 ) + { + st->CNG_mode = 2; + } + else if( st->last_active_brate > ACELP_7k20 ) + { + st->CNG_mode = 1; + } + else + { + st->CNG_mode = 0; + } + } + + /* If first sid after active burst update LSF history from circ buffer */ + burst_ho_cnt = min(burst_ho_cnt, st->ho_circ_size); + st->act_cnt = 0; + s_ptr = st->ho_circ_ptr-burst_ho_cnt+1; + if( s_ptr < 0 ) + { + s_ptr += st->ho_circ_size; + } + + for( ll= (short) burst_ho_cnt ; ll > 0 ; ll-- ) + { + if( ++(st->ho_hist_ptr) == HO_HIST_SIZE ) + { + st->ho_hist_ptr = 0; + } + /* Conversion between 12.8k and 16k LSPs */ + if( ( L_frame == L_FRAME16k && st->ho_16k_lsp[s_ptr] == 0 ) || ( L_frame == L_FRAME && st->ho_16k_lsp[s_ptr] == 1 ) ) + { + lsp_convert_poly( &st->ho_lsp_circ[s_ptr*M], L_frame, 0 ); + } + + /* update circular buffers */ + mvr2r(&(st->ho_lsp_circ[s_ptr*M]), &(st->ho_lsp_hist[st->ho_hist_ptr*M]), M ); + mvr2r(&(st->ho_ener_circ[s_ptr]), &(st->ho_ener_hist[st->ho_hist_ptr]), 1 ); + st->ho_sid_bw = ( st->ho_sid_bw & 0x3fffffffL ) << 1; + mvr2r(&(st->ho_env_circ[s_ptr*NUM_ENV_CNG]), &(st->ho_env_hist[st->ho_hist_ptr*NUM_ENV_CNG]), NUM_ENV_CNG ); + + st->ho_hist_size++; + if (st->ho_hist_size > HO_HIST_SIZE) + { + st->ho_hist_size = HO_HIST_SIZE; + } + + s_ptr++; + + if( s_ptr == st->ho_circ_size ) + { + s_ptr = 0; + } + } + if( st->ho_hist_size > 0) + { + *allow_cn_step |= ( st->ho_ener_hist[st->ho_hist_ptr] > 4.0f * st->lp_ener ); + } + + if ( !*allow_cn_step && st->ho_hist_size > 0 ) + { + ptr = st->ho_hist_ptr; + mvr2r( &(st->ho_lsp_hist[ptr*M]), tmp, M ); + m1 = 0; + if( (st->ho_sid_bw & 0x1L) == 0 ) + { + mvr2r( &st->ho_env_hist[ptr*NUM_ENV_CNG], tmp_env, NUM_ENV_CNG ); + m1 = 1; + } + enr = W_DTX_HO[0] * st->ho_ener_hist[ptr]; + weights = W_DTX_HO[0]; + m = 1; + for( k=1; kho_hist_size; k++ ) + { + ptr--; + if( ptr < 0 ) + { + ptr = HO_HIST_SIZE - 1; + } + + if ( st->ho_ener_hist[ptr] < st->ho_ener_hist[st->ho_hist_ptr] * BUF_H_NRG && + st->ho_ener_hist[ptr] > st->ho_ener_hist[st->ho_hist_ptr] * BUF_L_NRG ) + { + enr += W_DTX_HO[k] * st->ho_ener_hist[ptr]; + weights += W_DTX_HO[k]; + mvr2r( &st->ho_lsp_hist[ptr*M], &tmp[m*M], M ); + if( (st->ho_sid_bw & (0x1L << k)) == 0 ) + { + mvr2r( &st->ho_env_hist[ptr*NUM_ENV_CNG], &tmp_env[m1*NUM_ENV_CNG], NUM_ENV_CNG ); + m1++; + } + m++; + } + } + + enr /= weights; + st->lp_ener = enr; + + set_f( max, 0.0f, 2 ); + set_s( max_idx, 0, 2 ); + + for( i=0; iL_frame == L_FRAME ) + { + lsp2lsf( &tmp[i*M], lsf_tmp, M, INT_FS_12k8 ); + ftmp = 6400.0f / (M+1); + C[i] = (6400.0f - lsf_tmp[M-1] - ftmp) * (6400.0f - lsf_tmp[M-1] - ftmp); + } + else + { + lsp2lsf( &tmp[i*M], lsf_tmp, M, INT_FS_16k ); + ftmp = 8000.0f / (M+1); + C[i] = (8000.0f - lsf_tmp[M-1] - ftmp) * (8000.0f - lsf_tmp[M-1] - ftmp); + } + + C[i] += (lsf_tmp[0] - ftmp) * (lsf_tmp[0] - ftmp); + + for ( j=0; j max[0] ) + { + max[1] = max[0]; + max_idx[1] = max_idx[0]; + max[0] = C[i]; + max_idx[0] = i; + } + else if ( C[i] > max[1] ) + { + max[1] = C[i]; + max_idx[1] = i; + } + } + + if ( m == 1 ) + { + mvr2r( tmp, lsp_tmp, M ); + } + else if ( m < 4 ) + { + for ( i=0; i max_dev ) + { + max_dev = dev; + } + } + + if ( dist > 0.4f || max_dev > 0.1f ) + { + for( i=0; ilspCNG[i] = lsp_tmp[i]; + } + } + else + { + for( i=0; ilspCNG[i] = 0.8f * lsp_tmp[i] + (1-0.8f) * lsp_new[i]; + } + } + if( m1 > 0 ) + { + for ( i=0; ilp_ener; + } + mvr2r(env, st->lp_env, NUM_ENV_CNG); + } + } + else + { + mvr2r( lsp_new, st->lspCNG, M ); /* use newly analyzed parameters */ + } + } + + if( core_brate == SID_1k75 || core_brate == SID_2k40 ) + { + /* Update hangover memory during CNG */ + if ( !*allow_cn_step && (st->Enew < 1.5f * st->lp_ener) ) + { + /* update the pointer to circular buffer of old LSP vectors */ + if( ++(st->ho_hist_ptr) == HO_HIST_SIZE ) + { + st->ho_hist_ptr = 0; + } + + /* update the circular buffer of old LSP vectors with the new LSP vector */ + mvr2r( lsp_new, &(st->ho_lsp_hist[(st->ho_hist_ptr)*M]), M ); + + /* update the hangover energy buffer */ + st->ho_ener_hist[st->ho_hist_ptr] = st->Enew; + if ( core_brate == SID_2k40 && *sid_bw == 0 ) + { + enr1 = (float)log10( st->Enew*L_frame + 0.1f ) / (float)log10( 2.0f ); + for ( i=0; iEnew; + } + st->ho_sid_bw = ( st->ho_sid_bw & 0x3fffffffL ) << 1; + mvr2r( env, &(st->ho_env_hist[(st->ho_hist_ptr)*NUM_ENV_CNG]), NUM_ENV_CNG ); + } + else if( *sid_bw != 0 ) + { + st->ho_sid_bw = ( st->ho_sid_bw & 0x3fffffffL ) << 1; + st->ho_sid_bw |= 0x1L; + } + if(++(st->ho_hist_size) > HO_HIST_SIZE) + { + st->ho_hist_size = HO_HIST_SIZE; + } + } + + /* Update the frame length memory */ + st->last_CNG_L_frame = st->L_frame; + + if( core_brate != SID_1k75 ) + { + st->num_ho = m; + } + } + + if ( st->Opt_AMR_WB ) + { + isp2a( st->lspCNG, Aq, M ); + } + else + { + lsp2a_stab( st->lspCNG, Aq, M ); + } + + for( i=1; icore_brate == FRAME__NO_DATA || st->core_brate == SID_2k40 ) + { + /* SHB SID decoding and CNG */ + if ( st->cng_type == LP_CNG && st->extl == SWB_CNG ) + { + shb_CNG_decod( st, synth, shb_synth, sid_bw ); + } + st->last_vad = 0; + st->burst_cnt = 0; + } + else + { + st->last_vad = 1; + st->burst_cnt++; + if ( st->burst_cnt > 10 ) + { + st->burst_cnt = 0; + } + } + + return; +} + +/*---------------------------------------------------------------------* + * shb_CNG_decod() + * + * Main routine of SHB SID decoding and CNG + *---------------------------------------------------------------------*/ + +static void shb_CNG_decod( + Decoder_State *st, /* i/o: State structure */ + const float *synth, /* i : ACELP core synthesis at 32kHz */ + float *shb_synth, /* o : high-band CNG synthesis */ + const short sid_bw /* i : 0-NB/WB, 1-SWB SID */ +) +{ + short i; + short idx_ener; + float shb_lpcCNG[LPC_SHB_ORDER+1]; + float shb_lspCNG[LPC_SHB_ORDER]; + float excTmp[L_FRAME16k]; + float excSHB[L_FRAME16k]; + float ener_excSHB; + float wb_ener; + float gain; + float shb_syn16k[L_FRAME16k]; + float ftmp; + float step; + float interp; + float ener; + short allow_cn_step=0; + + if( !st->bfi ) + { + if ( st->core_brate == SID_2k40 && sid_bw == 1 ) + { + idx_ener = (short) get_next_indice( st, 4 ); + + if ( idx_ener == 0 ) + { + idx_ener = -15; + } + + /* de-quantization of SHB CNG parameters */ + st->last_shb_cng_ener = ((float)idx_ener/0.9f - 6.0f) * (float)log10(2.0f) * 10.0f; + } + } + + /* SHB spectrum estimation */ + interp = ((float)st->shb_dtx_count)/32; + interp = min( interp, 1.0f ); + for ( i=0; ilsp_shb_prev[i]; + shb_lspCNG[i] += (1 - interp) * st->lsp_shb_prev_prev[i]; + } + + if( st->shb_dtx_count < 1000 ) + { + st->shb_dtx_count++; + } + + lsp2a ( shb_lpcCNG, shb_lspCNG, LPC_SHB_ORDER ); + shb_lpcCNG[0] = 1.0f; + + /* SHB energy estimation */ + wb_ener = 0.001f; + for ( i=0; ifirst_CNG == 0 ) + { + st->wb_cng_ener = wb_ener; + } + if ( fabs(wb_ener - st->wb_cng_ener) > 12.0f ) + { + allow_cn_step = 1; + } + + if ( allow_cn_step == 1 ) + { + st->wb_cng_ener = wb_ener; + } + else + { + ftmp = wb_ener - st->wb_cng_ener; + st->wb_cng_ener += 0.9f * ftmp; + } + if ( st->core_brate == SID_2k40 && sid_bw == 1 && !st->bfi ) + { + st->last_wb_cng_ener = st->wb_cng_ener; + + if ( st->first_CNG == 0 ) + { + st->shb_cng_ener = st->last_shb_cng_ener; + } + } + + gain = st->wb_cng_ener - st->last_wb_cng_ener; + if ( gain > 15 ) + { + gain = 15; + } + step = gain + st->last_shb_cng_ener - st->shb_cng_ener; + if ( allow_cn_step == 1 || st->last_core_brate > SID_2k40 ) + { + st->shb_cng_ener += step; + } + else + { + st->shb_cng_ener += 0.25f * step; + } + /* generate white noise excitation */ + for ( i=0; iswb_cng_seed ); + } + + /* synthesis filtering */ + syn_filt( shb_lpcCNG, LPC_SHB_ORDER, excTmp, excSHB, L_FRAME16k, st->state_lpc_syn , 1 ); + + /* synthesis signal gain shaping */ + ener_excSHB = 0.001f; + for ( i=0; ilast_vad == 1 ) + { + if ( st->burst_cnt > 3 && st->last_core != HQ_CORE ) + { + st->trans_cnt = 5; + } + else + { + st->trans_cnt = 0; + } + } + + if ( st->trans_cnt > 0 ) + { + i = (short)((float)st->trans_cnt / 15.0f * 255); + ener = st->shb_cng_ener + sin_table256[i] * (st->last_shb_ener - st->shb_cng_ener); + st->trans_cnt--; + } + else + { + ener = st->shb_cng_ener; + } + + gain = (float)sqrt( pow(10, 0.1f*ener)*L_FRAME16k/ener_excSHB ); + + for ( i=0; igenSHBsynth_Hilbert_Mem, st->genSHBsynth_state_lsyn_filt_shb_local, st->L_frame, &(st->syn_dm_phase) ); + + if ( st->output_Fs == 48000 ) + { + interpolate_3_over_2_allpass( shb_synth, L_FRAME32k, shb_synth, st->interpol_3_2_cng_dec, allpass_poles_3_ov_2 ); + } + ResetSHBbuffer_Dec( st ); + return; +} diff --git a/src/libs/libevs/lib_dec/cng_dec_fx.cpp b/src/libs/libevs/lib_dec/cng_dec_fx.cpp deleted file mode 100755 index 916f2962..00000000 --- a/src/libs/libevs/lib_dec/cng_dec_fx.cpp +++ /dev/null @@ -1,936 +0,0 @@ -/*==================================================================================== - EVS Codec 3GPP TS26.442 Apr 03, 2018. Version 12.11.0 / 13.6.0 / 14.2.0 - ====================================================================================*/ - -#include "options.h" /* Compilation switches */ - -#include "stl.h" -#include "prot_fx.h" -#include "cnst_fx.h" -#include "rom_com_fx.h" -#include "basop_mpy.h" -#include - -/*Temporary location to be move in prot* when merge is done*/ -void E_LPC_f_isp_a_conversion(const Word16 *isp, Word16 *a, const Word16 m); -void E_LPC_f_lsp_a_conversion(const Word16 *isp, Word16 *a, const Word16 m); - -/*-----------------------------------------------------------------* - * Local functions - *-----------------------------------------------------------------*/ - -static void shb_CNG_decod_fx( Decoder_State_fx *st_fx, const Word16 *synth_fx, Word16 *shb_synth_fx, const Word16 sid_bw - ,const Word16 Qsyn - ); - -/*-----------------------------------------------------------------* - * Decode residual signal energy - *-----------------------------------------------------------------*/ - -void CNG_dec_fx( - Decoder_State_fx *st_fx, /* i/o: State structure */ - const Word16 L_frame, /* i : length of the frame Q0 */ - Word16 Aq[], /* o : LP coefficients Q12 */ - const Word32 core_brate, /* i : core bitrate Q0 */ - Word16 *lsp_new, /* i/o: current frame LSPs Q15 */ - Word16 *lsf_new, /* i/o: current frame LSFs Qlog2(2.56) */ - Word16 *allow_cn_step, /* o : allow CN step Q0 */ - Word16 *sid_bw /* i : 0-NB/WB, 1-SWB SID */ - ,Word32 *q_env -) -{ - Word16 istep; - Word16 i, L_enr_index; - Word32 L_ener; - Word16 ener_fra,ener_int; - Word16 num_bits; - Word16 weights, ptr, j, k; - Word16 m1; - Word16 m = 0; - Word16 tmp[HO_HIST_SIZE*M]; - Word16 burst_ho_cnt = 0; - Word16 ll,s_ptr; - Word32 L_enr,L_tmp1; - Word16 tmp1,exp; - Word16 lsf_tmp[M]; - Word32 C[M]; - Word32 max[2]; - Word16 max_idx[2]; - Word16 ftmp_fx; - Word16 lsp_tmp[M]; - Word16 dev; - Word16 max_dev; - Word16 dist; - Word16 tmpv; - Word16 env_idx[2]; - Word32 enr1; - Word32 env[NUM_ENV_CNG]; - Word32 tmp_env[HO_HIST_SIZE*NUM_ENV_CNG]; - Word32 L_tmp; - Word16 fra; - Word16 temp_lo_fx, temp_hi_fx; - Word16 exp_pow; - Word16 tmp_loop; - Word16 LSF_Q_prediction; /* o : LSF prediction mode - just temporary variable in CNG */ - - m = 0; - move16(); - /*-----------------------------------------------------------------* - * Decode CNG spectral envelope (only in SID frame) - *-----------------------------------------------------------------*/ - test(); - IF ( L_sub(core_brate,SID_1k75) == 0 || L_sub(core_brate, SID_2k40) == 0 ) - { - /* de-quantize the LSF vector */ - IF ( st_fx->Opt_AMR_WB_fx != 0 ) - { - /* Flt function */ - isf_dec_amr_wb_fx( st_fx, Aq, lsf_new, lsp_new); - } - ELSE - { - lsf_dec_fx( st_fx, 0, L_frame, INACTIVE, -1, Aq, &LSF_Q_prediction, lsf_new, lsp_new, 0 ); - } - } - ELSE - { - /* Use old LSP vector */ - Copy( st_fx->lsp_old_fx, lsp_new, M ); - Copy( st_fx->lsf_old_fx, lsf_new, M ); - } - - /* Initialize the CNG spectral envelope in case of the very first CNG frame */ - IF( st_fx->first_CNG_fx == 0 ) - { - Copy( st_fx->lsp_old_fx, st_fx->lspCNG_fx, M ); - } - - /*-----------------------------------------------------------------* - * Decode residual signal energy - *-----------------------------------------------------------------*/ - - *allow_cn_step = 0; - move16(); - test(); - IF( L_sub(core_brate,SID_1k75) == 0 || L_sub(core_brate, SID_2k40) == 0 ) - { - istep = ISTEP_AMR_WB_SID_FX; - move16(); - if( L_sub(core_brate,SID_2k40) == 0 ) - { - istep = ISTEP_SID_FX; - move16(); - } - - /* intialize the energy quantization parameters */ - num_bits = 6; - move16(); - if( st_fx->Opt_AMR_WB_fx == 0 ) - { - num_bits = 7; - move16(); - } - - /* decode the energy index */ - L_enr_index = get_next_indice_fx( st_fx, num_bits ); - - test(); - test(); - test(); - if (L_sub(st_fx->last_core_brate_fx,SID_1k75) > 0 && - st_fx->first_CNG_fx != 0 && - st_fx->old_enr_index_fx >= 0 && - sub(L_enr_index, add(st_fx->old_enr_index_fx,1)) > 0) - { - *allow_cn_step = 1; - move16(); - } - - st_fx->old_enr_index_fx = L_enr_index; - move16(); - if ( L_enr_index == 0 ) - { - L_enr_index = -5; - move16(); - } - /* st_fx->Enew = L_enr_index / step - 2.0f;*/ - L_ener = L_mult(L_enr_index, istep); /* Q16 (0+15) */ - /* substract by 2 not done to leave Energy in Q2 */ - - /* extract integral and fractional parts */ - ener_fra = L_Extract_lc(L_ener, &ener_int); - ener_int = add(ener_int, 4); /* Q2 to Q6 */ - - /* find the new energy value */ - st_fx->Enew_fx = Pow2(ener_int, ener_fra); - - IF( L_sub(core_brate,SID_2k40) == 0 ) - { - burst_ho_cnt = get_next_indice_fx( st_fx, 3 ); /* 3bit */ - - *sid_bw = get_next_indice_fx( st_fx, 1 ); - IF ( *sid_bw == 0 ) - { - env_idx[0] = get_next_indice_fx( st_fx, 6 ); - move16(); - - /* get quantized res_env_details */ - FOR ( i=0; ibwidth_fx,WB) == 0 && st_fx->first_CNG_fx != 0 && sub(st_fx->L_frame_fx,st_fx->last_CNG_L_frame_fx) != 0 ) - { - st_fx->ho_hist_size_fx = 0; - move16(); - } - } - - /*---------------------------------------------------------------------* - * CNG spectral envelope update - * Find A(z) coefficients - *---------------------------------------------------------------------*/ - test(); - test(); - test(); - IF( st_fx->last_core_brate_fx <= SID_2k40 ) - { - /* Reset hangover counter if not first SID period */ - if( L_sub(st_fx->core_brate_fx,FRAME_NO_DATA) > 0 ) - { - st_fx->num_ho_fx = 0; - move16(); - } - /* Update LSPs if last SID energy not outlier or insufficient number of hangover frames */ - test(); - IF( sub(st_fx->num_ho_fx,3) < 0 || L_sub(Mult_32_16(st_fx->Enew_fx,21845 /*1/1.5f, Q15*/), st_fx->lp_ener_fx) < 0 ) - { - FOR( i=0; ilspCNG_fx[i] = mac_r(L_mult(CNG_ISF_FACT_FX, st_fx->lspCNG_fx[i]), 32768-CNG_ISF_FACT_FX, lsp_new[i]); - move16(); /* Q15 (15+15+1-16) */ - } - } - } - ELSE - { - /* Update CNG_mode if allowed */ - test(); - test(); - test(); - IF( ( st_fx->Opt_AMR_WB_fx || sub(st_fx->bwidth_fx,WB) == 0 ) - && ( !st_fx->first_CNG_fx || sub(st_fx->act_cnt2_fx,MIN_ACT_CNG_UPD) >= 0 ) ) - { - IF( L_sub(st_fx->last_active_brate_fx,ACELP_16k40) > 0) - { - st_fx->CNG_mode_fx = -1; - move16(); - } - ELSE IF( L_sub(st_fx->last_active_brate_fx,ACELP_13k20) > 0 ) - { - st_fx->CNG_mode_fx = 4; - move16(); - } - ELSE IF( L_sub(st_fx->last_active_brate_fx,ACELP_9k60) > 0 ) - { - st_fx->CNG_mode_fx = 3; - move16(); - } - ELSE IF( L_sub(st_fx->last_active_brate_fx,ACELP_8k00) > 0 ) - { - st_fx->CNG_mode_fx = 2; - move16(); - } - ELSE IF( L_sub(st_fx->last_active_brate_fx,ACELP_7k20) > 0 ) - { - st_fx->CNG_mode_fx = 1; - move16(); - } - ELSE - { - st_fx->CNG_mode_fx = 0; - move16(); - } - } - - /* If first sid after active burst update LSF history from circ buffer */ - burst_ho_cnt = s_min(burst_ho_cnt, st_fx->ho_circ_size_fx); /* MODE1_DTX_IN_CODEC_B_FIX */ - st_fx->act_cnt_fx = 0; - move16(); - s_ptr = add(sub(st_fx->ho_circ_ptr_fx, burst_ho_cnt),1); - move16(); - if( s_ptr < 0 ) - { - s_ptr = add(s_ptr,st_fx->ho_circ_size_fx); - } - - FOR( ll = burst_ho_cnt; ll > 0; ll-- ) - { - st_fx->ho_hist_ptr_fx = add(st_fx->ho_hist_ptr_fx,1); - if( sub(st_fx->ho_hist_ptr_fx, HO_HIST_SIZE) == 0 ) - { - st_fx->ho_hist_ptr_fx = 0; - move16(); - } - - /* Conversion between 12.8k and 16k LSPs */ - test(); - test(); - test(); - IF( ( sub(L_frame,L_FRAME16k) == 0 && st_fx->ho_16k_lsp_fx[s_ptr] == 0 ) || ( sub(L_frame,L_FRAME) == 0 && sub(st_fx->ho_16k_lsp_fx[s_ptr],1) == 0 ) ) - { - /* Conversion from 16k LPSs to 12k8 */ - lsp_convert_poly_fx( &(st_fx->ho_lsp_circ_fx[s_ptr*M]), L_frame, 0 ); - } - /* update the circular buffers */ - Copy(&(st_fx->ho_lsp_circ_fx[s_ptr*M]), &(st_fx->ho_lsp_hist_fx[st_fx->ho_hist_ptr_fx*M]), M ); - Copy32(&(st_fx->ho_ener_circ_fx[s_ptr]), &(st_fx->ho_ener_hist_fx[st_fx->ho_hist_ptr_fx]), 1 ); - st_fx->ho_sid_bw_fx = L_shl(L_and(st_fx->ho_sid_bw_fx, (Word32) 0x3fffffffL ), 1); - Copy32(&(st_fx->ho_env_circ_fx[s_ptr*NUM_ENV_CNG]), &(st_fx->ho_env_hist_fx[st_fx->ho_hist_ptr_fx*NUM_ENV_CNG]), NUM_ENV_CNG ); - - st_fx->ho_hist_size_fx = add(st_fx->ho_hist_size_fx,1); - - if (sub(st_fx->ho_hist_size_fx, HO_HIST_SIZE) > 0) - { - st_fx->ho_hist_size_fx = HO_HIST_SIZE; - move16(); - } - - s_ptr = add(s_ptr,1); - if( sub(s_ptr, st_fx->ho_circ_size_fx) == 0 ) - { - s_ptr = 0; - move16(); - } - } - - IF( st_fx->ho_hist_size_fx > 0 ) /* can be -1 at init MODE1_DTX_IN_CODEC_B_FIX */ - { - /* *allow_cn_step |= ( st_fx->ho_ener_hist[st_fx->ho_hist_ptr] > 4.0f * st_fx->lp_ener );*/ - L_tmp1 = L_shr(st_fx->ho_ener_hist_fx[st_fx->ho_hist_ptr_fx], 2); - L_tmp1 = L_sub(L_tmp1, st_fx->lp_ener_fx); - - if(L_tmp1 > 0) - { - *allow_cn_step = s_or(*allow_cn_step,1); - } - } - test(); - IF ( *allow_cn_step == 0 && st_fx->ho_hist_size_fx > 0 ) - { - /* Use average of energies below last energy */ - ptr = st_fx->ho_hist_ptr_fx; - move16(); - Copy( &(st_fx->ho_lsp_hist_fx[ptr*M]), tmp, M ); - m1 = 0; - move16(); - IF( L_and(st_fx->ho_sid_bw_fx, (Word32) 0x1) == 0 ) - { - Copy32( &st_fx->ho_env_hist_fx[ptr*NUM_ENV_CNG], tmp_env, NUM_ENV_CNG ); - m1 = 1; - move16(); - } - L_enr = Mult_32_16(st_fx->ho_ener_hist_fx[ptr],W_DTX_HO_FX[0]) ;/* Q6+15-15->Q6 */ - - weights = W_DTX_HO_FX[0]; /* Q15 */ - - m = 1; - move16(); - FOR( k=1; kho_hist_size_fx; k++ ) - { - ptr = sub(ptr,1); - if( ptr < 0 ) - { - ptr = HO_HIST_SIZE - 1; - move16(); - } - - test(); - IF ( L_sub(Mult_32_16(st_fx->ho_ener_hist_fx[ptr],ONE_OVER_BUF_H_NRG_FX),st_fx->ho_ener_hist_fx[st_fx->ho_hist_ptr_fx]) < 0 && - L_sub(st_fx->ho_ener_hist_fx[ptr],Mult_32_16(st_fx->ho_ener_hist_fx[st_fx->ho_hist_ptr_fx], BUF_L_NRG_FX)) > 0 ) - { - /*enr += W_DTX_HO[k] * st_fx->ho_ener_hist[ptr];*/ - L_tmp1 = Mult_32_16(st_fx->ho_ener_hist_fx[ptr],W_DTX_HO_FX[k]) ; /* Q6+15-15->Q6 */ - L_enr = L_add(L_enr,L_tmp1); /* Q6 */ - - /*weights += W_DTX_HO[k];*/ - weights = add( weights, W_DTX_HO_FX[k]); /* Q15 */ - - Copy( &st_fx->ho_lsp_hist_fx[ptr*M], &tmp[m*M], M ); - IF( L_and(st_fx->ho_sid_bw_fx, L_shl((Word32)0x1,k)) == 0 ) - { - Copy32( &st_fx->ho_env_hist_fx[ptr*NUM_ENV_CNG], &tmp_env[m1*NUM_ENV_CNG], NUM_ENV_CNG ); - m1 = add(m1,1); - } - m = add(m,1); - } - } - - /*enr /= weights;*/ - exp = norm_s(weights); - tmp1 = div_s(shl(1,sub(14,exp)),weights); /* Q(15+14-exp-15) */ - L_tmp1 = Mult_32_16(L_enr,tmp1); /* Q(14-exp+6-15)->Q(5-exp) */ - L_enr = L_shl(L_tmp1,exp+1); /* Q6 */ - - st_fx->lp_ener_fx = L_enr; /* Q6 */ - - set32_fx( max, 0, 2 ); - set16_fx( max_idx, 0, 2 ); - - FOR( i=0; iL_frame_fx,L_FRAME) == 0 ) - { - lsp2lsf_fx( &tmp[i*M], lsf_tmp, M, INT_FS_FX ); - ftmp_fx = 964; - move16();/*X2.56 */ - tmpv = sub(16384,add(lsf_tmp[M-1],ftmp_fx)); /*QX2.56*/ - L_tmp = L_mult0(tmpv,tmpv); /*QX6.5536*/ - } - ELSE - { - lsp2lsf_fx( &tmp[i*M], lsf_tmp, M, INT_FS_16k_FX ); - ftmp_fx = 1205; - move16();/*QX2.56*/ - tmpv = sub(20480,add(lsf_tmp[M-1],ftmp_fx)); /*QX2.56*/ - L_tmp = L_mult0(tmpv,tmpv); /*QX6.5536*/ - } - - tmpv = sub(lsf_tmp[0],ftmp_fx); /*QX2.56*/ - L_tmp = L_mac0(L_tmp,tmpv,tmpv); /*QX6.5536*/ - FOR ( j=0; j 0 ) - { - max[1] = max[0]; - move32(); - max_idx[1] = max_idx[0]; - move16(); - max[0] = C[i]; - move32(); - max_idx[0] = i; - move16(); - } - ELSE IF ( L_sub(C[i],max[1]) > 0 ) - { - max[1] = C[i]; - move32(); - max_idx[1] = i; - move16(); - } - } - - IF ( sub(m,1) == 0 ) - { - Copy(tmp, lsp_tmp, M); - } - ELSE IF ( sub(m,4) < 0 ) - { - FOR ( i=0; i 0 ) - { - max_dev = dev; - move16(); - } - } - - test(); - IF ( sub(dist,13107) > 0 || sub(max_dev,3277) > 0 ) - { - FOR( i=0; ilspCNG_fx[i] = lsp_tmp[i]; - move16(); /*Q15*/ - } - } - ELSE - { - FOR( i=0; ilspCNG_fx[i] = add(mult_r(26214,lsp_tmp[i]),mult_r(6554,lsp_new[i])); - } - } - IF( m1 > 0 ) - { - FOR ( i=0; ilp_ener_fx; */ - IF(sub(m1,1) == 0) - { - L_tmp = L_sub(L_tmp,L_add(st_fx->lp_ener_fx,st_fx->lp_ener_fx)); - } - ELSE - { - tmp1 = div_s(1,m1); - L_tmp = Mult_32_16(L_tmp,tmp1); - L_tmp = L_sub(L_tmp,L_add(st_fx->lp_ener_fx,st_fx->lp_ener_fx)); - } - env[i] = L_tmp; - move32(); - } - - Copy32(env, st_fx->lp_env_fx, NUM_ENV_CNG); - } - } - ELSE - { - Copy( lsp_new, st_fx->lspCNG_fx, M ); /* use newly analyzed ISFs */ - } - } - - test(); - IF( L_sub(st_fx->core_brate_fx, SID_1k75) == 0 || L_sub(st_fx->core_brate_fx, SID_2k40) == 0 ) - { - /* Update hangover memory during CNG */ - test(); - IF ( *allow_cn_step == 0 && L_sub(st_fx->Enew_fx,L_add(st_fx->lp_ener_fx,L_shr(st_fx->lp_ener_fx,1))) < 0) - { - /* update the pointer to circular buffer of old LSP vectors */ - st_fx->ho_hist_ptr_fx = add(st_fx->ho_hist_ptr_fx, 1); - if( sub(st_fx->ho_hist_ptr_fx,HO_HIST_SIZE) == 0 ) - { - st_fx->ho_hist_ptr_fx = 0; - move16(); - } - - /* update the circular buffer of old LSP vectors with the new LSP vector */ - Copy( lsp_new, &(st_fx->ho_lsp_hist_fx[(st_fx->ho_hist_ptr_fx)*M]), M ); - - /* update the hangover energy buffer */ - st_fx->ho_ener_hist_fx[st_fx->ho_hist_ptr_fx] = st_fx->Enew_fx; - move32(); - test(); - IF ( L_sub(core_brate,SID_2k40) == 0 && *sid_bw == 0 ) - { - /* enr1 = (float)log10( st->Enew*L_frame + 0.1f ) / (float)log10( 2.0f );*/ - exp = norm_l(st_fx->Enew_fx); - L_tmp = L_shl(st_fx->Enew_fx,exp);/*Q(exp+6)*/ - L_tmp = Mult_32_16(L_tmp,shl(L_frame,5));/*Q(exp+6+5-15=exp-4)*/ - L_tmp = L_shr(L_tmp,sub(exp,10));/*Q6*/ - - exp = norm_l(L_tmp); - fra = Log2_norm_lc(L_shl(L_tmp,exp)); - exp = sub(sub(30,exp),6); - L_tmp = L_Comp(exp,fra); - enr1 = L_shr(L_tmp,10);/* Q6 */ - - FOR ( i=0; iEnew;*/ - L_tmp = L_sub(enr1,q_env[i]);/* Q6 */ - L_tmp = L_shl(L_tmp, 10);/* 16 */ - temp_lo_fx = L_Extract_lc(L_tmp, &temp_hi_fx); - - exp_pow = sub(14, temp_hi_fx); - L_tmp = Pow2(14, temp_lo_fx); /* Qexp_pow */ - env[i] = L_shl(L_tmp, sub(6, exp_pow)); /* Q6 */ - L_tmp = L_add(st_fx->Enew_fx,st_fx->Enew_fx); - env[i] = L_add(env[i],L_tmp); /* Q6 */ move32(); - } - st_fx->ho_sid_bw_fx = L_shl(L_and(st_fx->ho_sid_bw_fx, (Word32) 0x3fffffffL ), 1); - Copy32( env, &(st_fx->ho_env_hist_fx[(st_fx->ho_hist_ptr_fx)*NUM_ENV_CNG]), NUM_ENV_CNG ); - } - ELSE IF( *sid_bw != 0 ) - { - st_fx->ho_sid_bw_fx = L_shl(L_and(st_fx->ho_sid_bw_fx, (Word32) 0x3fffffffL ), 1); - st_fx->ho_sid_bw_fx = L_or(st_fx->ho_sid_bw_fx, 0x1L); - } - - st_fx->ho_hist_size_fx = add(st_fx->ho_hist_size_fx,1); - if( sub(st_fx->ho_hist_size_fx,HO_HIST_SIZE) > 0 ) - { - st_fx->ho_hist_size_fx = HO_HIST_SIZE; - move16(); - } - } - /* Update the frame length memory */ - st_fx->last_CNG_L_frame_fx = st_fx->L_frame_fx; - move16(); - - if( L_sub(core_brate,SID_1k75) != 0 ) - { - st_fx->num_ho_fx = m; - move16(); - } - } - - /* Update the frame length memory */ - st_fx->last_CNG_L_frame_fx = st_fx->L_frame_fx; - - if( L_sub(core_brate,SID_1k75) != 0 ) - { - st_fx->num_ho_fx = m; - move16(); - } - - IF ( st_fx->Opt_AMR_WB_fx ) - { - E_LPC_f_isp_a_conversion( st_fx->lspCNG_fx, Aq, M ); - } - ELSE - { - E_LPC_f_lsp_a_conversion( st_fx->lspCNG_fx, Aq, M ); - } - - tmp_loop = shr(L_frame,6); - FOR( i=1; icore_brate_fx == FRAME_NO_DATA || L_sub(st_fx->core_brate_fx, SID_2k40) == 0 ) - { - /* SHB SID decoding and CNG */ - test(); - IF (st_fx->cng_type_fx == LP_CNG && sub(st_fx->extl_fx, SWB_CNG) == 0) - { - shb_CNG_decod_fx( st_fx, synth_fx, shb_synth_fx, sid_bw, Qsyn ); - } - st_fx->last_vad_fx = 0; - move16(); - st_fx->burst_cnt_fx = 0; - move16(); - } - ELSE - { - st_fx->last_vad_fx = 1; - move16(); - st_fx->burst_cnt_fx = add(st_fx->burst_cnt_fx, 1); - if ( sub(st_fx->burst_cnt_fx, 10) > 0 ) - { - st_fx->burst_cnt_fx = 0; - move16(); - } - } - - return; -} - -/*---------------------------------------------------------------------* - * shb_CNG_decod() - * - * Main routine of SHB SID decoding and CNG - *---------------------------------------------------------------------*/ -static void shb_CNG_decod_fx( - Decoder_State_fx *st_fx, /* i/o: State structure */ - const Word16 *synth_fx, /* i : ACELP core synthesis at 32kHz */ - Word16 *shb_synth_fx, /* o : high-band CNG synthesis */ - const Word16 sid_bw /* i : 0-NB/WB, 1-SWB SID */ - ,const Word16 Qsyn /* i : Q value of ACELP core synthesis */ -) -{ - Word16 i; - Word16 idx_ener_fx; - Word16 shb_lpcCNG_fx[LPC_SHB_ORDER+1]; - Word16 shb_lspCNG_fx[LPC_SHB_ORDER]; - Word16 excTmp_fx[L_FRAME16k]; - Word16 excSHB_fx[L_FRAME16k]; - Word16 tmp_lsp[LPC_SHB_ORDER]; - Word16 ener_excSHB_fx; - Word32 wb_ener_fx; - Word16 wb_ener16_fx; - Word32 L_gain_fx; - Word16 gain_fx; - Word16 shb_syn16k_fx[L_FRAME16k]; - Word16 tmp; - Word16 step_fx; - Word16 interp_fx; - Word16 ener_fx; - Word16 exp,exp1; - Word16 fra; - Word32 L_tmp; - Word16 tmp2; - Word16 allow_cn_step_fx=0; - Word16 q; - - - IF ( st_fx->bfi_fx == 0 ) - { - test(); - IF ( L_sub(st_fx->core_brate_fx, SID_2k40) == 0 && sub(sid_bw, 1) == 0 ) - { - idx_ener_fx = get_next_indice_fx(st_fx, 4); - - if ( idx_ener_fx == 0 ) - { - idx_ener_fx = -15; - move16(); - } - - /* de-quantization of SHB CNG parameters */ - L_tmp = L_mult(idx_ener_fx, 27400); /*Q14*/ - st_fx->last_shb_cng_ener_fx = extract_l(L_shr(L_sub(L_tmp, 295924), 6)); /*Q8 */ - } - } - - /* SHB spectrum estimation */ - - - interp_fx = s_min(st_fx->shb_dtx_count_fx,32); - interp_fx = shl(interp_fx, 10); /*Q15*/ - - FOR ( i=0; ilsp_shb_prev_fx[i]); /*Q14*/ - tmp = mult(sub(32767, interp_fx), st_fx->lsp_shb_prev_prev_fx[i]); /*Q14*/ - shb_lspCNG_fx[i] = add(tmp2, tmp); - move16(); /*Q14*/ - } - - if ( sub(st_fx->shb_dtx_count_fx, 1000) < 0 ) - { - st_fx->shb_dtx_count_fx = add(st_fx->shb_dtx_count_fx, 1); - } - - E_LPC_lsf_lsp_conversion(shb_lspCNG_fx, tmp_lsp, LPC_SHB_ORDER); /*Q14*/ - E_LPC_f_lsp_a_conversion(tmp_lsp, shb_lpcCNG_fx, LPC_SHB_ORDER); - - Copy_Scale_sig( shb_lpcCNG_fx, shb_lpcCNG_fx, LPC_SHB_ORDER+1, sub(norm_s(shb_lpcCNG_fx[0]),2) ); /* Q12 */ - - - - /* SHB energy estimation */ - wb_ener_fx = L_deposit_l(1);/*Q1 */ - FOR ( i=0; ifirst_CNG_fx == 0 ) - { - st_fx->wb_cng_ener_fx = wb_ener16_fx; - move16();/*Q8 */ - } - if ( sub(abs_s(sub(wb_ener16_fx,st_fx->wb_cng_ener_fx)),3072) > 0 ) - { - allow_cn_step_fx = 1; - move16(); - } - - IF ( sub(allow_cn_step_fx, 1) == 0 ) - { - st_fx->wb_cng_ener_fx = wb_ener16_fx; - move16(); /*Q8 */ - } - ELSE - { - tmp = sub(wb_ener16_fx, st_fx->wb_cng_ener_fx); /*Q8 */ - tmp = mult_r(tmp, 29491); /*Q8 */ - st_fx->wb_cng_ener_fx = add(st_fx->wb_cng_ener_fx, tmp); /*Q8 */ - } - test(); - test(); - IF ( L_sub(st_fx->core_brate_fx, SID_2k40) == 0 && sub(sid_bw, 1) == 0 && st_fx->bfi_fx == 0 ) - { - st_fx->last_wb_cng_ener_fx = st_fx->wb_cng_ener_fx; - move16(); - - if ( st_fx->first_CNG_fx == 0 ) - { - st_fx->shb_cng_ener_fx = st_fx->last_shb_cng_ener_fx; - move16(); - } - } - - gain_fx = sub(st_fx->wb_cng_ener_fx, st_fx->last_wb_cng_ener_fx); /*8 */ - if (sub(gain_fx, 15) > 0) - { - gain_fx = 15; - move16(); - } - step_fx = sub(add(gain_fx, st_fx->last_shb_cng_ener_fx), st_fx->shb_cng_ener_fx); /*Q8 */ - test(); - IF ( sub(allow_cn_step_fx,1) == 0 || L_sub(st_fx->last_core_brate_fx,SID_2k40) > 0 ) - { - st_fx->shb_cng_ener_fx = add(st_fx->shb_cng_ener_fx, step_fx); - } - ELSE - { - st_fx->shb_cng_ener_fx = add(st_fx->shb_cng_ener_fx, mult(8192, step_fx)); /*Q8 */ - } - /* generate white noise excitation */ - FOR ( i=0; iswb_cng_seed_fx), 8); - move16();/*Q-8*/ - } - - /* synthesis filtering */ - Syn_filt_s( 0, shb_lpcCNG_fx, LPC_SHB_ORDER, excTmp_fx, excSHB_fx, L_FRAME16k, st_fx->state_lpc_syn_fx, 1 ); - - - /* synthesis signal gain shaping */ - L_tmp = 0; - FOR ( i=0; ilast_vad_fx, 1) == 0 ) - { - st_fx->trans_cnt_fx = 0; - move16(); - test(); - if ( sub(st_fx->burst_cnt_fx, 3) > 0 && sub(st_fx->last_core_fx, HQ_CORE) != 0 ) - { - st_fx->trans_cnt_fx = 5; - move16(); - } - } - - ener_fx = st_fx->shb_cng_ener_fx; - move16();/*Q8 */ - IF ( st_fx->trans_cnt_fx > 0 ) - { - i = extract_l(L_mult0(st_fx->trans_cnt_fx, 17)); /*Q0 */ - ener_fx = add(st_fx->shb_cng_ener_fx, mult(sin_table256_fx[i], sub(st_fx->last_shb_ener_fx, st_fx->shb_cng_ener_fx))); /*Q8 */ - st_fx->trans_cnt_fx = sub(st_fx->trans_cnt_fx, 1); - } - - tmp = mult(3277, ener_fx); /*Q8 */ - L_tmp = L_mult(27213, tmp); /*Q22, 27213=3.321928 in Q13 */ - L_tmp = L_shr(L_tmp, 6); /*Q16 */ - L_tmp = L_add(L_tmp, 10<<16); - if( L_tmp < 0 ) - { - L_tmp = 0; - move32(); - } - fra = L_Extract_lc(L_tmp, &exp); - L_tmp = L_shl(Pow2(exp, fra), 5); /*Q5 */ - L_tmp = L_shr(L_tmp, 10); - if( L_tmp == 0 ) - { - L_tmp = 1; /*Q5 */ - } - exp = norm_l(L_tmp); - L_tmp = L_shl(L_tmp, exp); /*Q31*/ - tmp = extract_h(L_tmp); /*Q15*/ - exp = sub(exp, 16); - exp1 = norm_s(ener_excSHB_fx); - fra = shl(ener_excSHB_fx, exp1); /*Q15*/ - - IF ( sub(fra,tmp) > 0 ) - { - fra = shr(fra, 1); /*Q15*/ - exp1 = sub(exp1, 1); - } - tmp = div_s(fra, tmp); /*Q15*/ - - L_tmp = L_deposit_h(tmp); /*Q31 */ - tmp = -(q+exp1)+(5+exp); - L_gain_fx = Isqrt_lc(L_tmp, &tmp); /*Q31-Qtmp */ - FOR ( i=0; ilast_extl_fx, SWB_TBE) == 0 || sub(st_fx->last_extl_fx, FB_TBE) == 0 ) - { - /* rescale the Hilbert memories to Q0 */ - FOR(i = 0; i < HILBERT_MEM_SIZE ; i++) - { - st_fx->genSHBsynth_Hilbert_Mem_fx[i] = L_shr(st_fx->genSHBsynth_Hilbert_Mem_fx[i], st_fx->prev_Q_bwe_syn2); - move32(); - } - - FOR(i = 0; i < 2*ALLPASSSECTIONS_STEEP; i++ ) - { - st_fx->genSHBsynth_state_lsyn_filt_shb_local_fx[i] = shr(st_fx->genSHBsynth_state_lsyn_filt_shb_local_fx[i], st_fx->prev_Q_bwe_syn2); - } - - } - GenSHBSynth_fx( shb_syn16k_fx, shb_synth_fx, st_fx->genSHBsynth_Hilbert_Mem_fx, st_fx->genSHBsynth_state_lsyn_filt_shb_local_fx, st_fx->L_frame_fx, &(st_fx->syn_dm_phase_fx) ); - - IF ( L_sub(st_fx->output_Fs_fx,48000) == 0 ) - { - interpolate_3_over_2_allpass_fx( shb_synth_fx, L_FRAME32k, shb_synth_fx, st_fx->interpol_3_2_cng_dec_fx, allpass_poles_3_ov_2 ); - } - ResetSHBbuffer_Dec_fx( st_fx ); - - return; -} - - - diff --git a/src/libs/libevs/lib_dec/core_dec_init.cpp b/src/libs/libevs/lib_dec/core_dec_init.cpp old mode 100755 new mode 100644 index 0b5a162d..5961380e --- a/src/libs/libevs/lib_dec/core_dec_init.cpp +++ b/src/libs/libevs/lib_dec/core_dec_init.cpp @@ -1,17 +1,13 @@ /*==================================================================================== - EVS Codec 3GPP TS26.442 Apr 03, 2018. Version 12.11.0 / 13.6.0 / 14.2.0 + EVS Codec 3GPP TS26.443 Nov 13, 2018. Version 12.11.0 / 13.7.0 / 14.3.0 / 15.1.0 ====================================================================================*/ #include -#include -#include -#include -#include "prot_fx.h" -#include "basop_util.h" -#include "rom_com_fx.h" #include "options.h" -#include "stl.h" -#include "cnst_fx.h" /* for MIN_CNG_LEV */ +#include "stat_com.h" +#include "cnst.h" +#include "prot.h" +#include "rom_com.h" /*-----------------------------------------------------------------------* * open_decoder_LPD() @@ -19,770 +15,656 @@ * Initialization of state variables *-----------------------------------------------------------------------*/ -void open_decoder_LPD( Decoder_State_fx *st, Word32 bit_rate, Word16 bandwidth_mode ) +void open_decoder_LPD( + Decoder_State *st, + const int bit_rate, + const int bandwidth +) { - Word16 i; - Word16 mem_syn_r_size_new; - Word16 mem_syn_r_size_old; - Word16 fscaleFB; + short i; + short mdctWindowLength; + short mem_syn_r_size_old; + short mem_syn_r_size_new; + short fscaleFB; + short mdctWindowLengthFB; + short encoderLookahead, encoderLookaheadFB; - - - st->total_brate_fx = bit_rate; - st->fscale_old = st->fscale; - st->sr_core = getCoreSamplerateMode2(st->total_brate_fx, bandwidth_mode, st->rf_flag); - st->fscale = sr2fscale(st->sr_core); - fscaleFB = sr2fscale(st->output_Fs_fx); + st->total_brate = bit_rate; + st->fscale_old = st->fscale; + st->sr_core = getCoreSamplerateMode2(st->total_brate, bandwidth, st->rf_flag); + st->fscale = sr2fscale(st->sr_core); + fscaleFB = sr2fscale(st->output_Fs); /* initializing variables for frame lengths etc. right in the beginning */ - st->L_frame_fx = extract_l(Mult_32_16(st->sr_core , 0x0290)); - st->L_frameTCX = extract_l(Mult_32_16(st->output_Fs_fx , 0x0290)); - - IF (st->ini_frame_fx == 0) + st->L_frame = st->sr_core / 50; + st->L_frameTCX = st->output_Fs / 50; + if (st->ini_frame == 0) { - st->last_L_frame_fx = st->L_frame_past = st->L_frame_fx; - move16(); - move16(); - st->L_frameTCX_past = st->L_frameTCX; - move16(); + st->last_L_frame = st->L_frame_past = st->L_frame; + st->L_frameTCX_past = st->L_frameTCX; } - st->tcxonly = getTcxonly(st->total_brate_fx); - move16(); + st->tcxonly = getTcxonly(bit_rate); /* the TD TCX PLC in MODE1 still runs with 80ms subframes */ - st->nb_subfr = NB_SUBFR; - move16(); - test(); - test(); - test(); - test(); - if ( (sub(st->L_frame_fx,L_FRAME16k) == 0 && L_sub(st->total_brate_fx,32000) <= 0 ) || - (st->tcxonly != 0 && (L_sub(st->sr_core,32000)==0 || L_sub(st->sr_core,16000)==0) ) - ) + if ( (st->L_frame == L_FRAME16k && st->total_brate <= ACELP_32k) || (st->tcxonly && (st->sr_core == 32000 || st->sr_core == 16000))) { st->nb_subfr = NB_SUBFR16k; - move16(); } - - /* (float)st->L_frame/(float)st->fscale * (float)FSCALE_DENOM/128.0f * (float)st->total_brate_fx */ - st->bits_frame = extract_l(L_shr(Mpy_32_16_1( L_shl(st->total_brate_fx, 1) , 20972), 6)); /* 20972 = 0.01 * 64 * 32768 */ - - assert(FSCALE_DENOM == 512); - assert(st->fscale == 2 * st->L_frame_fx); /* this assumption is true if operated in 20ms frames with FSCALE_DENOM == 512, which is the current default */ - assert(st->bits_frame == (int)( (float)st->L_frame_fx/(float)st->fscale * (float)FSCALE_DENOM/128.0f * (float)st->total_brate_fx/100.0f + 0.49f )); - - st->TcxBandwidth = getTcxBandwidth(bandwidth_mode); - st->narrowBand = 0; - move16(); - if (sub(bandwidth_mode, NB) == 0) + else { - st->narrowBand = 1; - move16(); + st->nb_subfr = NB_SUBFR; } + st->bits_frame = (int) ( ((float)st->L_frame/(float)st->fscale) * (float)FSCALE_DENOM/128.0f * (float)bit_rate /100.0f +0.49f); - st->pit_res_max = initPitchLagParameters(st->sr_core, &st->pit_min, &st->pit_fr1, &st->pit_fr1b, &st->pit_fr2, &st->pit_max); - IF ( st->ini_frame_fx == 0) + st->TcxBandwidth = getTcxBandwidth(bandwidth); + st->narrowBand = (bandwidth == NB)?1:0; + encoderLookahead = (L_LOOK_12k8*st->fscale)/FSCALE_DENOM; + encoderLookaheadFB = (L_LOOK_12k8*fscaleFB)/FSCALE_DENOM; + + st->pit_res_max = initPitchLagParameters(st->sr_core, &st->pit_min, &st->pit_fr1, &st->pit_fr1b, &st->pit_fr2, &st->pit_max); + if ( st->ini_frame == 0) { st->pit_res_max_past = st->pit_res_max; } - i = mult_r(st->L_frameTCX, getInvFrameLen(st->L_frame_fx)); - st->pit_max_TCX = extract_l(L_shr(L_mult(st->pit_max, i), 7)); - st->pit_min_TCX = extract_l(L_shr(L_mult(st->pit_min, i), 7)); + st->pit_max_TCX = st->pit_max * st->output_Fs / st->sr_core; + st->pit_min_TCX = st->pit_min * st->output_Fs / st->sr_core; /*Preemphasis param*/ - st->preemph_fac = PREEMPH_FAC_SWB; /*SWB*/ move16(); - IF ( sub(st->fscale, (16000*FSCALE_DENOM)/12800) < 0) + if (st->fscale < (16000*FSCALE_DENOM)/12800) { - st->preemph_fac = PREEMPH_FAC; /*WB*/ move16(); + st->preemph_fac = PREEMPH_FAC; /*NB*/ } - ELSE if ( sub(st->fscale, (24000*FSCALE_DENOM)/12800) < 0) + else if (st->fscale < (24000*FSCALE_DENOM)/12800) { - st->preemph_fac = PREEMPH_FAC_16k; /*WB*/ move16(); + st->preemph_fac = PREEMPH_FAC_16k; /*WB*/ + } + else + { + st->preemph_fac = PREEMPH_FAC_SWB; /*SWB*/ } - st->gamma = GAMMA1; - move16(); - st->inv_gamma = GAMMA1_INV; - move16(); - IF ( L_sub(st->sr_core, 16000) == 0 ) + if( st->sr_core==16000 ) { st->gamma = GAMMA16k; - move16(); - st->inv_gamma = GAMMA16k_INV; - move16(); + } + else + { + st->gamma = GAMMA1; } /* LPC quantization */ - st-> lpcQuantization = 0; - move16(); - test(); - if( st->tcxonly == 0 && L_sub(st->sr_core, 16000) <= 0) + if ( st->sr_core <= 16000 && st->tcxonly==0 ) { st->lpcQuantization = 1; } + else + { + st->lpcQuantization = 0; + } - st->numlpc = 2; - move16(); if ( st->tcxonly==0 ) { st->numlpc = 1; - move16(); + } + else + { + st->numlpc = 2; } /* Initialize TBE */ - st->prev_coder_type_fx = GENERIC; - set16_fx( st->prev_lsf_diff_fx,16384,LPC_SHB_ORDER-2 ); - st->prev_tilt_para_fx = 0; - set16_fx( st->cur_sub_Aq_fx, 0, M+1 ); + st->prev_coder_type = GENERIC; + set_f( st->prev_lsf_diff, 0.5f, LPC_SHB_ORDER-2 ); + st->prev_tilt_para = 0.0f; + set_zero( st->cur_sub_Aq, M+1 ); /*TCX config*/ - st->tcx_cfg.preemph_fac = st->preemph_fac; - move16(); - st->tcx_cfg.tcx_mdct_window_length_old = st->tcx_cfg.tcx_mdct_window_length; - move16(); + st->tcx_cfg.preemph_fac=st->preemph_fac; + st->tcx_cfg.tcx_mdct_window_length_old=st->tcx_cfg.tcx_mdct_window_length; + mdctWindowLength = getMdctWindowLength(st->fscale); + mdctWindowLengthFB = getMdctWindowLength(fscaleFB); - init_TCX_config( &st->tcx_cfg, st->L_frame_fx, st->fscale, st->L_frameTCX, fscaleFB ); + /* Initialize the TCX MDCT window */ + st->tcx_cfg.tcx_mdct_window_delay = mdctWindowLength; + st->tcx_cfg.tcx_mdct_window_delayFB = mdctWindowLengthFB; + st->tcx_cfg.tcx_mdct_window_length = mdctWindowLength; + st->tcx_cfg.tcx_mdct_window_lengthFB = mdctWindowLengthFB; - IF (st->ini_frame_fx == 0) + mdct_window_sine( st->tcx_cfg.tcx_mdct_window, st->tcx_cfg.tcx_mdct_window_length ); + mdct_window_sine( st->tcx_cfg.tcx_mdct_windowFB, st->tcx_cfg.tcx_mdct_window_lengthFB ); + set_zero(st->tcx_cfg.tcx_mdct_window + st->tcx_cfg.tcx_mdct_window_length, L_MDCT_OVLP_MAX - st->tcx_cfg.tcx_mdct_window_length); + set_zero(st->tcx_cfg.tcx_mdct_windowFB + st->tcx_cfg.tcx_mdct_window_lengthFB, L_MDCT_OVLP_MAX - st->tcx_cfg.tcx_mdct_window_lengthFB); + + mdct_window_sine( st->tcx_cfg.tcx_mdct_window_half, st->tcx_cfg.tcx_mdct_window_length/2 ); + mdct_window_sine( st->tcx_cfg.tcx_mdct_window_halfFB, st->tcx_cfg.tcx_mdct_window_lengthFB/2 ); + + /* minimum overlap 1.25 ms */ + st->tcx_cfg.tcx_mdct_window_min_length = st->sr_core / 800; + st->tcx_cfg.tcx_mdct_window_min_lengthFB = st->output_Fs / 800; + + mdct_window_sine( st->tcx_cfg.tcx_mdct_window_minimum, st->tcx_cfg.tcx_mdct_window_min_length ); + mdct_window_sine( st->tcx_cfg.tcx_mdct_window_minimumFB, st->tcx_cfg.tcx_mdct_window_min_lengthFB ); + + /*ALDO windows for MODE2*/ + mdct_window_aldo(st->tcx_cfg.tcx_aldo_window_1, st->tcx_cfg.tcx_aldo_window_2, st->L_frame); + mdct_window_aldo(st->tcx_cfg.tcx_aldo_window_1_FB, st->tcx_cfg.tcx_aldo_window_2_FB, NS2SA(st->output_Fs, FRAME_SIZE_NS)); + st->tcx_cfg.tcx_aldo_window_1_trunc = st->tcx_cfg.tcx_aldo_window_1 + NS2SA(st->sr_core, N_ZERO_MDCT_NS); + st->tcx_cfg.tcx_aldo_window_1_FB_trunc = st->tcx_cfg.tcx_aldo_window_1_FB + NS2SA(st->output_Fs, N_ZERO_MDCT_NS); + + /*1.25ms transition window for ACELP->TCX*/ + mdct_window_sine( st->tcx_cfg.tcx_mdct_window_trans, (st->L_frame>>1)-st->tcx_cfg.tcx_mdct_window_length); + mdct_window_sine( st->tcx_cfg.tcx_mdct_window_transFB, (st->L_frameTCX>>1)-st->tcx_cfg.tcx_mdct_window_lengthFB); + + /*Mid-OLA*/ + /*compute minimum length for "half" window: lookahead - 5ms. It must be also multiple of 2*/ + st->tcx_cfg.tcx_mdct_window_half_length = 2*((encoderLookahead-(int)(0.005f*st->sr_core+0.5f))>>1); + st->tcx_cfg.tcx_mdct_window_half_lengthFB = 2*((encoderLookaheadFB-(int)(0.005f*st->output_Fs+0.5f))>>1); + assert( (st->tcx_cfg.tcx_mdct_window_half_length>16) && "Half window can not be large enough!"); + + mdct_window_sine( st->tcx_cfg.tcx_mdct_window_half, st->tcx_cfg.tcx_mdct_window_half_length ); + mdct_window_sine( st->tcx_cfg.tcx_mdct_window_halfFB, st->tcx_cfg.tcx_mdct_window_half_lengthFB ); + if (st->ini_frame == 0) { st->tcx_cfg.tcx_last_overlap_mode = st->tcx_cfg.tcx_curr_overlap_mode = ALDO_WINDOW; - move16(); - move16(); } /* TCX Offset */ - st->tcx_cfg.tcx_offset = shr(st->tcx_cfg.tcx_mdct_window_delay, 1); - st->tcx_cfg.tcx_offsetFB = shr(st->tcx_cfg.tcx_mdct_window_delayFB, 1); - - /* Initialize FAC */ - st->tcx_cfg.lfacNext = sub(st->tcx_cfg.tcx_offset,shr(st->L_frame_fx,2)); - st->tcx_cfg.lfacNextFB = sub(st->tcx_cfg.tcx_offsetFB,shr(st->L_frameTCX,2)); + st->tcx_cfg.tcx_offset = (st->tcx_cfg.tcx_mdct_window_delay>>1); + st->tcx_cfg.tcx_offsetFB = (st->tcx_cfg.tcx_mdct_window_delayFB>>1); + /*<0 rectangular transition with optimized window size = L_frame+L_frame/4*/ + st->tcx_cfg.lfacNext = st->tcx_cfg.tcx_offset - st->L_frame/4; + st->tcx_cfg.lfacNextFB = st->tcx_cfg.tcx_offsetFB - st->L_frameTCX/4; /* set number of coded lines */ - st->tcx_cfg.tcx_coded_lines = getNumTcxCodedLines(st->bwidth_fx); + st->tcx_cfg.tcx_coded_lines = getNumTcxCodedLines(bandwidth); /* TNS in TCX */ st->tcx_cfg.pCurrentTnsConfig = NULL; - st->tcx_cfg.fIsTNSAllowed = getTnsAllowed(st->total_brate_fx, st->igf); + st->tcx_cfg.fIsTNSAllowed = getTnsAllowed( st->total_brate, st->igf ); - IF (st->tcx_cfg.fIsTNSAllowed != 0) + if (st->tcx_cfg.fIsTNSAllowed) { - InitTnsConfigs(bwMode2fs[st->bwidth_fx], st->tcx_cfg.tcx_coded_lines, st->tcx_cfg.tnsConfig, st->hIGFDec.infoIGFStopFreq, st->total_brate_fx); + InitTnsConfigs( bwMode2fs[bandwidth], st->tcx_cfg.tcx_coded_lines, st->tcx_cfg.tnsConfig, st->hIGFDec.infoIGFStopFreq, st->total_brate ); } - resetTecDec_Fx( &(st->tecDec_fx) ); + resetTecDec( &(st->tecDec) ); /* Initialize decoder delay */ /*Constraint for adaptive BPF, otherwise parameter estimation and post-processing not time aligned*/ - if ( st->tcxonly==0 ) + if( st->tcxonly == 0 ) { - assert(0 == (st->tcx_cfg.lfacNext>0 ? st->tcx_cfg.lfacNext : 0) ); + i = st->tcx_cfg.lfacNext>0?st->tcx_cfg.lfacNext:0; + assert( 0==i ); } - st->flag_cna = 0; - move16(); - IF( st->ini_frame_fx == 0 ) + if( st->ini_frame == 0 ) { st->last_flag_cna = 0; - move16(); } /* Static vectors to zero */ - IF (st->ini_frame_fx == 0) + if (st->ini_frame == 0) { - st->last_is_cng = 0; - move16(); st->rate_switching_reset = 0; - move16(); - set16_fx(st->old_syn_Overl, 0, L_FRAME32k/2); + set_zero(st->old_syn_Overl, L_FRAME32k/2); - set16_fx(st->syn_Overl_TDAC, 0, L_FRAME32k/2); - set16_fx(st->syn_OverlFB, 0, L_FRAME_MAX/2); - set16_fx(st->syn_Overl_TDACFB, 0, L_FRAME_MAX/2); + set_zero(st->syn_Overl_TDAC, L_FRAME32k/2); + set_zero(st->syn_OverlFB, L_FRAME_MAX/2); + set_zero(st->syn_Overl_TDACFB, L_FRAME_MAX/2); - set16_fx(st->syn_Overl, 0, L_FRAME32k/2); + set_zero(st->syn_Overl, L_FRAME32k/2); - set16_fx(st->old_synth, 0, OLD_SYNTH_INTERNAL_DEC); - set16_fx( st->synth_history_fx, 0, Lprot48k + L_FRAME_MAX); + set_zero(st->old_synth, OLD_SYNTH_INTERNAL_DEC); - set16_fx(st->syn, 0, M+1); + set_zero( st->synth_history, L_PROT48k + L_FRAME_MAX); - set16_fx(st->mem_syn_r, 0, L_SYN_MEM); + set_zero( st->syn, M+1 ); + + set_zero( st->mem_syn_r, L_SYN_MEM ); mem_syn_r_size_old = 0; /* just to avoid MSVC warnings */ mem_syn_r_size_new = 0; /* just to avoid MSVC warnings */ st->con_tcx = 0; } - ELSE + else { - /* Reset old_synth in case of core sampling rate switching and codec switching*/ - test(); - IF( (sub(st->L_frame_fx, st->last_L_frame_fx) != 0) || (sub(st->last_codec_mode,MODE1)==0) ) + /* Reset old_synth in case of core sampling rate switching and Mode 1/2 switching*/ + if( (st->L_frame != st->last_L_frame) || (st->last_codec_mode == MODE1) ) { - set16_fx(st->old_synth, 0, OLD_SYNTH_INTERNAL_DEC); + set_zero(st->old_synth, OLD_SYNTH_INTERNAL_DEC); } - /*Size of LPC syn memory*/ - /* 1.25/20.0 = 1.0/16.0 -> shift 4 to the right. */ - mem_syn_r_size_old = shr(st->last_L_frame_fx, 4); - mem_syn_r_size_new = shr(st->L_frame_fx, 4); + /*Compute size of old and new memories*/ + mem_syn_r_size_old=(int)(1.25*st->last_L_frame/20.f); + mem_syn_r_size_new=(int)(1.25*st->L_frame/20.f); /*Reset LPC mem*/ - test(); - test(); - IF( (sub(st->L_frame_fx,st->last_L_frame_fx)!=0) || (sub(st->last_core_fx,AMR_WB_CORE)==0) - || sub(st->last_core_fx,HQ_CORE) == 0 ) + if( (st->L_frame != st->last_L_frame) || (st->last_core == AMR_WB_CORE) || (st->last_core == HQ_CORE) ) { - /*LPC quant. mem*/ - set16_fx(st->mem_MA_fx, 0, M); - IF( L_sub(st->sr_core,16000) == 0 ) + set_zero( st->mem_MA, M ); + if( st->sr_core == 16000 ) { - Copy( GEWB2_Ave_fx, st->mem_AR_fx, M ); + mvr2r( GEWB2_Ave, st->mem_AR, M ); } - ELSE + else { - Copy( GEWB_Ave_fx, st->mem_AR_fx, M ); + mvr2r( GEWB_Ave, st->mem_AR, M ); } } - /*Codec switching*/ - IF( sub(st->last_codec_mode,MODE1)==0 ) + /*Mode 1/2 switching*/ + if( st->last_codec_mode == MODE1 ) { - Copy( st->lsp_old_fx, st->lspold_uw, M ); - Copy( st->lsf_old_fx, st->lsfold_uw, M ); - set16_fx( st->syn, 0, M ); + mvr2r( st->lsp_old, st->lspold_uw, M ); + mvr2r( st->lsf_old, st->lsfold_uw, M ); + set_zero( st->syn, M ); } - IF( sub(st->last_core_fx,AMR_WB_CORE)==0 ) + if( st->last_core == AMR_WB_CORE ) { - st->last_core_fx = ACELP_CORE; - move16(); + st->last_core = ACELP_CORE; st->last_core_bfi = ACELP_CORE; - move16(); } - /*Codec switching from ACELP-A */ - test(); - IF( sub(st->last_codec_mode, MODE1)==0 && sub(st->last_core_fx, ACELP_CORE)==0 ) + if( st->last_codec_mode == MODE1 && st->last_core == ACELP_CORE ) { + /* Switching from Mode 1 ACELP */ st->last_core_bfi = ACELP_CORE; - move16(); /*PLC*/ - IF(st->prev_bfi_fx!=0) + if( st->prev_bfi != 0 ) { - PWord16 const *w; - Word16 W1,W2,nz,delay_comp; + float *w; + short W1,nz,delay_comp; W1 = st->tcx_cfg.tcx_mdct_window_lengthFB; - move16(); - W2 = shr(st->tcx_cfg.tcx_mdct_window_lengthFB,1); - w = st->tcx_cfg.tcx_mdct_windowFB; /*pointer - no need to instrument*/ + w = st->tcx_cfg.tcx_mdct_windowFB; - nz = NS2SA_fx2(st->output_Fs_fx, N_ZERO_MDCT_NS); - delay_comp = NS2SA_fx2(st->output_Fs_fx, DELAY_CLDFB_NS); /*CLDFB delay*/ - - Copy(st->fer_samples_fx+delay_comp, st->syn_OverlFB, shr(st->L_frameTCX,1)); - - lerp(st->fer_samples_fx+delay_comp, st->syn_Overl , shr(st->L_frame_fx,1), shr(st->L_frameTCX,1)); /*Q0: ACELP(bfi)->TCX(rect)*/ + nz = NS2SA(st->output_Fs, N_ZERO_MDCT_NS); + delay_comp = NS2SA(st->output_Fs, DELAY_CLDFB_NS); /*CLDFB delay*/ + mvr2r(st->fer_samples+delay_comp, st->syn_OverlFB, st->L_frameTCX/2); + lerp (st->fer_samples+delay_comp, st->syn_Overl , st->L_frame /2, st->L_frameTCX/2); /*ACELP(bfi)->TCX(rect)*/ /*old_out needed for MODE1 routine and syn_Overl_TDAC for MODE2 routine*/ - st->Q_old_wtda=-1; - set16_fx(st->old_out_fx, 0, nz); - Copy_Scale_sig(st->fer_samples_fx+delay_comp, st->old_out_fx+nz,W1, st->Q_old_wtda); /*Q-1*/ + set_f(st->old_out, 0, nz); + mvr2r(st->fer_samples+delay_comp, st->old_out+nz,W1); - FOR (i=0; i < W2; i++) + for (i = 0; i < W1; i++) { - st->old_out_fx[i+nz] = round_fx(Mpy_32_16_1(L_mult(w[i].v.re,w[i].v.re),st->old_out_fx[i+nz])); + st->old_out[i+nz] *= w[W1-1-i]*w[W1-1-i]; } - FOR ( ; i < W1; i++) - { - st->old_out_fx[i+nz] = round_fx(Mpy_32_16_1(L_mult(w[W2-1-(i-W2)].v.im,w[W2-1-(i-W2)].v.im),st->old_out_fx[i+nz])); - } - set16_fx(&st->old_out_fx[W1+nz], 0, nz); + set_f(&st->old_out[W1+nz], 0, nz); - lerp(st->old_out_fx , st->old_out_LB_fx , st->L_frame_fx , st->L_frameTCX); + lerp (st->old_out , st->old_outLB , st->L_frame , st->L_frameTCX); - Copy(st->old_out_fx +nz, st->syn_Overl_TDACFB, shr(st->L_frameTCX,1)); - nz = NS2SA_fx2(st->sr_core, N_ZERO_MDCT_NS); - Copy(st->old_out_LB_fx+nz, st->syn_Overl_TDAC , shr(st->L_frame_fx,1)); - st->Q_old_wtda_LB = st->Q_old_wtda; + mvr2r(st->old_out +nz, st->syn_Overl_TDACFB, st->L_frameTCX/2); + nz = NS2SA(st->sr_core, N_ZERO_MDCT_NS); + mvr2r(st->old_outLB+nz, st->syn_Overl_TDAC , st->L_frame /2); } } - test(); - test(); - test(); - test(); - test(); - test(); - test(); - IF( sub(st->last_codec_mode,MODE2) == 0 && - sub(st->L_frame_fx, st->last_L_frame_fx) != 0 && - ( ( sub(st->m_frame_type, SID_FRAME) == 0 && sub(st->last_core_fx, ACELP_CORE) > 0 ) || - ( sub(st->last_core_fx, ACELP_CORE) > 0 && sub(st->core_fx, ACELP_CORE) > 0) || - st->prev_bfi_fx ) ) + if ( st->last_codec_mode == MODE2 && + st->L_frame != st->last_L_frame && + ( ( st->m_frame_type == SID_FRAME && st->last_core > ACELP_CORE ) || + (st->last_core > ACELP_CORE && st->core > ACELP_CORE) || st->prev_bfi ) ) { - lerp(st->old_out_LB_fx, st->old_out_LB_fx, st->L_frame_fx, st->last_L_frame_fx); + lerp(st->old_outLB, st->old_outLB, st->L_frame, st->last_L_frame); } /* Rate switching */ - test(); - test(); - test(); - IF( sub(st->last_codec_mode,MODE1)==0 && sub(st->last_core_fx,HQ_CORE)==0 ) + if( st->last_codec_mode == MODE1 && st->last_core == HQ_CORE ) { - /*Codec switching from MDCT */ + /* Switching from MDCT */ /*Reset of ACELP memories*/ - move16(); - move16(); st->rate_switching_reset=1; - st->tilt_code_fx = TILT_CODE; - set16_fx(st->old_exc_fx, 0, L_EXC_MEM_DEC); - set16_fx(st->syn, 0, 1+M); - set16_fx(st->mem_syn2_fx, 0, M); + st->tilt_code = TILT_CODE; + set_zero(st->old_exc, L_EXC_MEM_DEC); + set_zero(st->syn, 1+M); + set_zero(st->mem_syn2, M); /*OLA -> zero */ - set16_fx(st->old_syn_Overl, 0, L_FRAME32k/2); /*HQ-CORE(bfi)->TCX don't need it*/ - set16_fx(st->syn_Overl_TDAC, 0, L_FRAME32k/2); /*HQ-CORE(bfi)->TCX don't need it*/ - set16_fx(st->syn_Overl_TDACFB, 0, L_FRAME_MAX/2); /*HQ-CORE(bfi)->TCX don't need it*/ - set16_fx(st->syn_Overl, 0, L_FRAME32k/2); /*HQ-CORE(bfi)->TCX don't need it*/ - - Copy_Scale_sig(st->old_out_fx+NS2SA(st->output_Fs_fx, N_ZERO_MDCT_NS), st->syn_OverlFB, st->tcx_cfg.tcx_mdct_window_lengthFB, negate(add(st->Q_old_wtda, TCX_IMDCT_HEADROOM))); - - move16(); - move16(); + set_zero(st->old_syn_Overl, L_FRAME32k/2); + set_zero(st->syn_Overl_TDAC, L_FRAME32k/2); + set_zero(st->syn_Overl, L_FRAME32k/2); + set_zero(st->syn_Overl_TDACFB, L_FRAME_MAX/2); + mvr2r(st->old_out+NS2SA(st->output_Fs, N_ZERO_MDCT_NS), st->syn_OverlFB, st->tcx_cfg.tcx_mdct_window_lengthFB); st->tcx_cfg.last_aldo=1; /*It was previously ALDO*/ st->tcx_cfg.tcx_curr_overlap_mode = ALDO_WINDOW; - /*OLA for MDCT-LB always reset in codec switching cases*/ - set16_fx( st->old_out_LB_fx, 0, st->L_frame_fx ); - move16(); - st->last_core_bfi = TCX_20_CORE; + /*OLA for Mode 2 TCX always reset in Mode switching cases*/ + set_f( st->old_outLB, 0, st->L_frame ); + st->last_core_bfi = TCX_20_CORE; st->pfstat.on=0; - move16(); /* reset CLDFB memories */ - cldfb_reset_memory( st->cldfbAna_fx ); - cldfb_reset_memory( st->cldfbBPF_fx ); - cldfb_reset_memory( st->cldfbSyn_fx ); + cldfb_reset_memory( st->cldfbAna ); + cldfb_reset_memory( st->cldfbBPF ); + cldfb_reset_memory( st->cldfbSyn ); } - ELSE IF( (sub(st->L_frame_fx,st->last_L_frame_fx)!=0) && (sub(st->L_frame_fx,L_FRAME16k)<=0) && (sub(st->last_L_frame_fx,L_FRAME16k)<=0)) /* Rate switching between 12.8 and 16 kHz*/ + else if( (st->L_frame!=st->last_L_frame) && (st->L_frame<=L_FRAME16k) && (st->last_L_frame <=L_FRAME16k)) /* Rate switching between 12.8 and 16 kHz*/ { /*Interpolation of ACELP memories*/ /* convert quantized LSP vector */ - st->rate_switching_reset=lsp_convert_poly_fx( st->lsp_old_fx, st->L_frame_fx, 0 ); - IF( st->tcxonly == 0 ) - { - lsp2lsf_fx( st->lsp_old_fx, st->lsf_old_fx, M, st->sr_core ); - } - ELSE - { - E_LPC_lsp_lsf_conversion( st->lsp_old_fx, st->lsf_old_fx, M ); - } - E_LPC_f_lsp_a_conversion(st->lsp_old_fx, st->old_Aq_12_8_fx, M); + st->rate_switching_reset= lsp_convert_poly( st->lsp_old, st->L_frame, 0 ); + lsp2a_stab( st->lsp_old, st->old_Aq_12_8, M ); + lsp2lsf( st->lsp_old, st->lsf_old, M, st->sr_core ); + mvr2r( st->lsp_old, st->lspold_uw, M ); + mvr2r( st->lsf_old, st->lsfold_uw, M ); - Copy( st->lsp_old_fx, st->lspold_uw, M ); - Copy( st->lsf_old_fx, st->lsfold_uw, M ); - - IF( !st->last_con_tcx ) + if( !st->last_con_tcx ) { - synth_mem_updt2( st->L_frame_fx, st->last_L_frame_fx, st->old_exc_fx, st->mem_syn_r, st->mem_syn2_fx, NULL, DEC ); + synth_mem_updt2( st->L_frame, st->last_L_frame, st->old_exc, st->mem_syn_r, st->mem_syn2, NULL, DEC ); } /*mem of deemphasis stayed unchanged.*/ } - ELSE IF( sub(st->L_frame_fx,st->last_L_frame_fx)!=0 ) /* Rate switching involving TCX only modes */ + else if( st->L_frame!=st->last_L_frame ) /* Rate switching involving TCX only modes */ { /*Partial reset of ACELP memories*/ st->rate_switching_reset = 1; /*reset partly some memories*/ - st->tilt_code_fx = TILT_CODE; - IF( !st->last_con_tcx ) + st->tilt_code = TILT_CODE; + if( !st->last_con_tcx ) { - set16_fx( st->old_exc_fx, 0, L_EXC_MEM_DEC ); + set_zero( st->old_exc, L_EXC_MEM_DEC ); } - set16_fx( st->old_Aq_12_8_fx, 0, M+1 ); + set_zero( st->old_Aq_12_8, M+1 ); /*Resamp others memories*/ /*Size of LPC syn memory*/ lerp( st->mem_syn_r+L_SYN_MEM-mem_syn_r_size_old, st->mem_syn_r+L_SYN_MEM-mem_syn_r_size_new, mem_syn_r_size_new, mem_syn_r_size_old ); - Copy( st->mem_syn_r+L_SYN_MEM-M, st->mem_syn2_fx, M ); - - /*Untouched memories : st->syn */ - } - ELSE IF( !st->tcxonly && sub(st->L_frame_fx,L_FRAME16k) == 0 && L_sub(st->last_total_brate_fx,ACELP_32k) > 0 ) - { - lsp2lsf_fx( st->lsp_old_fx, st->lsf_old_fx, M, st->sr_core ); + mvr2r( st->mem_syn_r+L_SYN_MEM-M, st->mem_syn2, M ); } + /* update of lsf_old only needed in BASOP */ + /* else if( !st->tcxonly && (st->L_frame == L_FRAME16k) && (st->last_total_brate > ACELP_32k) ) */ + /* { */ + /* lsp2lsf( st->lsp_old, st->lsf_old, M, st->sr_core ); */ + /* } */ } - test(); - test(); - if(sub(st->last_bwidth_fx,NB)==0 && sub(st->bwidth_fx,NB)!=0 && st->ini_frame_fx!=0) + if( st->last_bwidth == NB && st->bwidth != NB && st->ini_frame != 0 ) { st->rate_switching_reset=1; - move16(); } - st->old_synth_len = shl(st->L_frame_fx, 1); - st->old_synth_lenFB = shl(st->L_frameTCX, 1); + st->old_synth_len = 2*st->L_frame; + st->old_synth_lenFB = 2*st->L_frameTCX; /* bass pf reset */ st->bpf_gain_param = 0; - move16(); - set16_fx( st->pst_old_syn_fx, 0, NBPSF_PIT_MAX ); + set_f( st->pst_old_syn, 0, NBPSF_PIT_MAX ); /* Formant postfilter */ - IF ( st->ini_frame_fx==0 ) + if (st->ini_frame == 0) { - /*do nothing*/ + /* do nothing */ } - ELSE IF( sub(st->last_codec_mode,MODE2)==0) + else if( st->last_codec_mode == MODE2 ) { - IF (st->tcxonly==0) + if( !st->tcxonly ) { - IF ( st->pfstat.on!=0 ) + if( st->pfstat.on ) { lerp( st->pfstat.mem_stp+L_SYN_MEM-mem_syn_r_size_old, st->pfstat.mem_stp+L_SYN_MEM-mem_syn_r_size_new, mem_syn_r_size_new, mem_syn_r_size_old ); lerp( st->pfstat.mem_pf_in+L_SYN_MEM-mem_syn_r_size_old, st->pfstat.mem_pf_in+L_SYN_MEM-mem_syn_r_size_new, mem_syn_r_size_new, mem_syn_r_size_old ); } - ELSE + else { - set16_fx( st->pfstat.mem_stp, 0,L_SYN_MEM ); - set16_fx( st->pfstat.mem_pf_in, 0,L_SYN_MEM ); - st->pfstat.reset = 1; - st->pfstat.gain_prec = 16384; - move16(); + set_zero( st->pfstat.mem_stp, L_SYN_MEM ); + set_zero( st->pfstat.mem_pf_in, L_SYN_MEM ); + st->pfstat.reset = 1.f; + st->pfstat.gain_prec = 1.f; } } - ELSE IF ( st->pfstat.on!=0 ) + else if( st->pfstat.on ) { lerp( st->pfstat.mem_stp+L_SYN_MEM-mem_syn_r_size_old, st->pfstat.mem_stp+L_SYN_MEM-mem_syn_r_size_new, mem_syn_r_size_new, mem_syn_r_size_old ); lerp( st->pfstat.mem_pf_in+L_SYN_MEM-mem_syn_r_size_old, st->pfstat.mem_pf_in+L_SYN_MEM-mem_syn_r_size_new, mem_syn_r_size_new, mem_syn_r_size_old ); } } - ELSE + else { - /*codec switching*/ + /*codec mode switching*/ + /*reset post-filter except for Narrowband*/ - IF ( L_sub(st->output_Fs_fx,8000)!=0 ) + if ( ((short)(st->output_Fs / 50)) != L_FRAME8k ) { st->pfstat.reset = 1; - if(st->pfstat.on!=0) + if( st->pfstat.on != 0 ) { st->pfstat.reset = 0; - Scale_sig(st->pfstat.mem_pf_in, L_SUBFR, negate(st->Q_syn)); /* WB post_filter mem */ - Scale_sig(st->pfstat.mem_stp, L_SUBFR, negate(st->Q_syn)); /* WB post_filter mem */ lerp( st->pfstat.mem_stp+L_SYN_MEM-mem_syn_r_size_old, st->pfstat.mem_stp+L_SYN_MEM-mem_syn_r_size_new, mem_syn_r_size_new, mem_syn_r_size_old ); lerp( st->pfstat.mem_pf_in+L_SYN_MEM-mem_syn_r_size_old, st->pfstat.mem_pf_in+L_SYN_MEM-mem_syn_r_size_new, mem_syn_r_size_new, mem_syn_r_size_old ); } } - ELSE{ - Scale_sig(st->pfstat.mem_pf_in, L_SUBFR, negate(st->Q_syn)); /* NB post_filter mem */ - Scale_sig(st->pfstat.mem_res2, DECMEM_RES2, negate(st->Q_syn)); /* NB post_filter mem */ - Scale_sig(st->pfstat.mem_stp, L_SUBFR, negate(st->Q_syn)); /* NB post_filter mem */ + else + { /*feed last value old_synth as it is used for pre-emphasis mem*/ st->old_synth[st->old_synth_len-1]=st->syn[M]; - move16(); - st->pst_old_syn_fx[NBPSF_PIT_MAX-1]=st->syn[M]; - move16(); + st->pst_old_syn[NBPSF_PIT_MAX-1]=st->syn[M]; } } /* lsf and lsp initialization */ - IF ( st->ini_frame_fx == 0 ) + if (st->ini_frame == 0 ) { - Copy(st->lsp_old_fx, st->lspold_uw, M); - Copy(st->lsf_old_fx, st->lsfold_uw, M); + mvr2r( st->lsp_old, st->lspold_uw, M ); + mvr2r( st->lsf_old, st->lsfold_uw, M ); - set16_fx(st->lsf_cng, 0, M); + set_zero( st->lsf_cng, M ); } st->seed_tcx_plc = 21845; - move16(); - st->past_gpit = 0; - move16(); - st->past_gcode = L_deposit_l(0); - st->gc_threshold_fx = L_deposit_l(0); + st->past_gpit = 0.0f; + st->past_gcode = 0.0f; + st->gc_threshold = 0.0f; - E_LPC_lsf_lsp_conversion(st->lsf_cng, st->lspold_cng, M); - E_LPC_f_lsp_a_conversion(st->lspold_cng, st->Aq_cng, M); + lsf2lsp(st->lsf_cng, st->lspold_cng, M, INT_FS_12k8); + lsp2a_stab(st->lspold_cng, st->Aq_cng, M); st->plcBackgroundNoiseUpdated = 0; - move16(); - Copy(st->lsf_old_fx, st->lsf_q_cng, M); - Copy(st->lsf_old_fx, st->old_lsf_q_cng, M); - Copy(st->lsp_old_fx, st->lsp_q_cng, M); - Copy(st->lsp_old_fx, st->old_lsp_q_cng, M); - set16_fx(st->mem_syn_unv_back, 0, M); + mvr2r(st->lsf_old, st->lsf_q_cng, M); + mvr2r(st->lsf_old, st->old_lsf_q_cng, M); + mvr2r(st->lsp_old, st->lsp_q_cng, M); + mvr2r(st->lsp_old, st->old_lsp_q_cng, M); + set_zero(st->mem_syn_unv_back, M); + st->last_gain_syn_deemph = 1.f; - st->last_gain_syn_deemph = 32768/2; - move16(); - st->last_gain_syn_deemph_e = 1; - move16(); - test(); - IF( sub(st->last_codec_mode,MODE1) == 0 || st->ini_frame_fx == 0 ) + if( st->last_codec_mode == MODE1 || st->ini_frame == 0 ) { /* this assumes that MODE1 fades out in the frequency domain - - otherwise some data from MODE1 would be needed here */ - st->last_concealed_gain_syn_deemph = 32768/2; - move16(); - st->last_concealed_gain_syn_deemph_e = 1; - move16(); - st->conceal_eof_gain = 32768/2;/*Q14*/ move16(); - + otherwise some data from MODE1 would be needed here */ + st->last_concealed_gain_syn_deemph = 1.f; + st->conceal_eof_gain = 1.0f; } - /* Post processing */ - set16_fx(st->mem_Aq,0,NB_SUBFR16k*(M+1)); - st->lp_ener_FER_fx = 15360; - move16(); /*60 in Q8*/ - IF (st->ini_frame_fx == 0) + set_zero(st->mem_Aq, NB_SUBFR16k*(M+1)); + + st->lp_ener_bfi = 60.0f; + if( st->ini_frame == 0 ) { - st->prev_bfi_fx = 0; - move16(); + st->prev_bfi = 0; st->last_core_bfi = -1; - move16(); + st->tcxConceal_recalc_exc = 0; } - st->prev_old_bfi_fx = 0; - move16(); + st->prev_old_bfi = 0; st->nbLostCmpt = 0; - move16(); - /*st->noise_filling_index = 0;*/ /* not in BASOP */ + st->noise_filling_index = 0; - Copy(st->lsf_old_fx, st->lsf_adaptive_mean_fx, M); - Copy(st->lsf_old_fx, st->lsfoldbfi0_fx, M); - Copy(st->lsf_old_fx, st->lsfoldbfi1_fx, M); + mvr2r(st->lsf_old, st->lsf_adaptive_mean, M); + mvr2r(st->lsf_old, st->lsfoldbfi0, M); + mvr2r(st->lsf_old, st->lsfoldbfi1, M); st->clas_dec = UNVOICED_CLAS; - move16(); - move16(); - IF (!st->last_con_tcx) + + if (!st->last_con_tcx) { - move16(); - st->old_enr_LP = 0; /* LP filter E of last good voiced frame or local LP filter E in TD TCX PLC */ + st->old_enr_LP = 0.0f; /* LP filter E of last good voiced frame or local LP filter E in TD TCX PLC */ } - IF (st->prev_bfi_fx) + if (st->prev_bfi) { /* calculate energy at the end of the previous frame */ - test(); - IF( sub(st->core_fx,ACELP_CORE) == 0 && sub(st->last_core_fx,HQ_CORE) == 0 ) + if( st->core == ACELP_CORE && st->last_core == HQ_CORE ) { - frame_ener_fx( st->output_frame_fx, UNVOICED_CLAS, st->previoussynth_fx, -1, &st->enr_old_fx, 1, 0, 0, 0 ); + fer_energy( st->L_frameTCX, UNVOICED_CLAS, st->previoussynth, -1, &st->enr_old, 1 ); } } - ELSE + else { - st->last_good_fx = UNVOICED_CLAS; /* last good received frame for concealment */ move16(); - st->enr_old_fx = L_deposit_l(0); /* energy at the end of the previous frame */ + st->last_good = UNVOICED_CLAS; /* last good received frame for concealment */ + st->enr_old = 0.0f; /* energy at the end of the previous frame */ } - st->Mode2_lp_gainc = L_deposit_l(0); - st->Mode2_lp_gainp = L_deposit_l(0); + st->lp_gainc = 0.0f; + st->lp_gainp = 0.0f; st->prev_widow_left_rect = 0; - move16(); - st->conCngLevelBackgroundTrace = PLC_MIN_CNG_LEV; /*Q15*/ move16(); - st->conNoiseLevelIndex = PLC_MIN_STAT_BUFF_SIZE-1; - move16(); - st->conCurrLevelIndex = 0; - move16(); - st->conLastFrameLevel = PLC_MIN_CNG_LEV; /*Q15*/ move16(); - set16_fx(st->conNoiseLevelMemory, PLC_MIN_CNG_LEV, PLC_MIN_STAT_BUFF_SIZE); /*Q15*/ - set16_fx(st->conNoiseLevelMemory_e, 0, PLC_MIN_STAT_BUFF_SIZE); - st->conLastFrameLevel_e = 0; - st->conCngLevelBackgroundTrace_e = 0; + st->CngLevelBackgroundTrace_bfi = PLC_MIN_CNG_LEV; + st->NoiseLevelIndex_bfi = PLC_MIN_STAT_BUFF_SIZE-1; + st->CurrLevelIndex_bfi = 0; + st->LastFrameLevel_bfi = PLC_MIN_CNG_LEV; + set_f( st->NoiseLevelMemory_bfi, PLC_MIN_CNG_LEV, PLC_MIN_STAT_BUFF_SIZE); - st->cummulative_damping_tcx = 32767/*1.0f Q15*/; - move16(); - st->cummulative_damping = 32767/*1.0f Q15*/; - move16(); + st->cummulative_damping_tcx = 1.0f; + st->cummulative_damping = 1.0f; - FOR ( i=0; i<2*NB_SUBFR16k+2; i++ ) + for( i=0; i<2*NB_SUBFR16k+2; i++ ) { - st->old_pitch_buf_fx[i] = L_deposit_h(st->pit_min); + st->old_pitch_buf[i] = (float)st->pit_min; } - FOR ( i=0; i<2*NB_SUBFR16k+2; i++ ) + for( i=0; i<2*NB_SUBFR16k+2; i++ ) { - st->mem_pitch_gain[i] = 16384/*1.f Q14*/;/*Q14*/ + st->mem_pitch_gain[i] = 1.f; } - - st->old_fpitch = L_deposit_h(st->pit_min); - st->old_fpitchFB = L_deposit_h(st->pit_min_TCX); + st->old_fpitch = (float)st->pit_min; + st->old_fpitchFB = (float)st->pit_min_TCX; st->rate_switching_init = 1; - move16(); st->reset_mem_AR = 0; - move16(); /* For phase dispersion */ - st->dm_fx.prev_gain_code = L_deposit_l(0); - set16_fx(st->dm_fx.prev_gain_pit, 0, 6); - st->dm_fx.prev_state = 0; - move16(); + set_zero(st->dispMem,8); - st->voice_fac = -1; /* purely unvoiced */ move16(); + st->voice_fac = -1; /* purely unvoiced */ /* TCX-LTP */ st->tcxltp = getTcxLtp(st->sr_core); - move16(); - - test(); - IF ( st->ini_frame_fx == 0 || sub(st->last_codec_mode,MODE1)==0) + if( st->ini_frame == 0 || st->last_codec_mode == MODE1 ) { st->tcxltp_pitch_int = st->pit_max; - move16(); st->tcxltp_pitch_fr = 0; - move16(); - st->tcxltp_last_gain_unmodified = 0; - move16(); - IF ( st->ini_frame_fx == 0) + st->tcxltp_last_gain_unmodified = 0.f; + if (st->ini_frame == 0) { - set16_fx( st->tcxltp_mem_in, 0, TCXLTP_MAX_DELAY ); - set16_fx( st->tcxltp_mem_out, 0, L_FRAME48k ); + set_f( st->tcxltp_mem_in, 0.0f, TCXLTP_MAX_DELAY ); + set_f( st->tcxltp_mem_out, 0.0f, L_FRAME48k ); st->tcxltp_pitch_int_post_prev = 0; - move16(); st->tcxltp_pitch_fr_post_prev = 0; - move16(); - st->tcxltp_gain_post_prev = 0; - move16(); + st->tcxltp_gain_post_prev = 0.f; st->tcxltp_filt_idx_prev = -1; - move16(); } } - /* in floating point implementation, different buffers are used: lp_error_ener <-> pst_lp_ener, mem_error <-> pst_mem_deemp_err */ - st->lp_error_ener = Mpy_32_16_1(L_shl(st->pst_lp_ener_fx, 8), 0x2a86); /* convert from 7Q8 10*log10 -> 15Q16, log2 */ - st->mem_error = L_deposit_l(0); - st->tcx_cfg.ctx_hm = getCtxHm (st->total_brate_fx, st->rf_flag); + st->pst_mem_deemp_err = 0.0f; + st->tcx_cfg.ctx_hm = getCtxHm(st->total_brate, st->rf_flag); st->last_ctx_hm_enabled = 0; - move16(); - st->tcx_cfg.resq = getResq(st->total_brate_fx); - move16(); + st->tcx_cfg.resq = getResq(st->total_brate); + st->tcx_cfg.sq_rounding = 0.375f; /*deadzone of 1.25->rounding=1-1.25/2 (No deadzone=0.5)*/ - st->tcx_cfg.sq_rounding = 12288/*0.375f Q15*/; /*deadzone of 1.25->rounding=1-1.25/2 (No deadzone=0.5)*/ move16(); - - st->tcx_lpc_shaped_ari = getTcxLpcShapedAri( - st->total_brate_fx, - bandwidth_mode - ,st->rf_flag - ); + st->tcx_lpc_shaped_ari = getTcxLpcShapedAri( st->total_brate, bandwidth, st->rf_flag ); st->envWeighted = 0; - move16(); - st->p_bpf_noise_buf = NULL; - if (st->tcxonly == 0) + if( st->tcxonly ) + { + st->p_bpf_noise_buf = NULL; + } + else { st->p_bpf_noise_buf = st->bpf_noise_buf; } - st->tec_tfa = 0; - move16(); - test(); - test(); - if ( sub(bandwidth_mode, SWB) == 0 && - (L_sub(st->total_brate_fx, ACELP_16k40) == 0 || L_sub(st->total_brate_fx, ACELP_24k40) == 0) ) + if( bandwidth == SWB && (st->total_brate == ACELP_16k40 || st->total_brate == ACELP_24k40) ) { st->tec_tfa = 1; - move16(); + } + else + { + st->tec_tfa = 0; } st->tec_flag = 0; - move16(); st->tfa_flag = 0; - move16(); + /* needed in decoder to read the bitstream */ st->enableGplc = 0; - move16(); st->flagGuidedAcelp = 0; - move16(); st->T0_4th = L_SUBFR; - move16(); st->guidedT0 = st->T0_4th; - move16(); - test(); - test(); - test(); - st->enablePlcWaveadjust = 0; - move16(); - IF(L_sub(st->total_brate_fx, 48000) >= 0 ) + + if( st->total_brate >= HQ_48k ) { st->enablePlcWaveadjust = 1; - move16(); - test(); - test(); - test(); - IF (st->ini_frame_fx == 0 || L_sub(st->last_total_brate_fx, HQ_48k) < 0 || sub(st->last_codec_mode, MODE1) == 0 || st->force_lpd_reset ) + if( st->ini_frame == 0 || st->last_total_brate < HQ_48k || st->last_codec_mode == MODE1 || st->force_lpd_reset ) { - concealment_init_x( st->L_frameTCX, &st->plcInfo ); + concealment_init( st->L_frameTCX, &st->plcInfo ); } } + else + { + st->enablePlcWaveadjust = 0; + } /* PLC: [TCX: Tonal Concealment] */ st->tonalMDCTconceal.nScaleFactors = 0; - move16(); st->tonalMDCTconceal.nSamples = 0; - move16(); st->tonalMDCTconceal.lastPcmOut = 0x0; - move16(); st->tonalMDCTconceal.lastBlockData.tonalConcealmentActive = 0; - move16(); st->tonalMDCTconceal.lastBlockData.nSamples = 0; - move16(); - TonalMDCTConceal_Init(&st->tonalMDCTconceal, - st->L_frameTCX, - st->L_frame_fx, - FDNS_NPTS, - &(st->tcx_cfg) + TonalMDCTConceal_Init( &st->tonalMDCTconceal, + st->L_frameTCX, + st->L_frame, FDNS_NPTS, + &st->tcx_cfg ); st->last_tns_active = 0; st->second_last_tns_active = 0; st->second_last_core = -1; st->tcxltp_second_last_pitch = st->old_fpitch; - move16(); st->tcxltp_third_last_pitch = st->old_fpitch; - move16(); - move16(); - st->dec_glr = 0; - test(); - test(); - test(); - if( (L_sub(st->total_brate_fx, 9600)==0)||( L_sub(st->total_brate_fx, 16400)==0)|| - (L_sub(st->total_brate_fx, 24400)==0)) + + if( st->total_brate == ACELP_9k60 || st->total_brate == ACELP_16k40 || st->total_brate == ACELP_24k40 ) { - move16(); st->dec_glr = 1; } - move16(); + else + { + st->dec_glr = 0; + } + st->dec_glr_idx = 0; st->enableTcxLpc = 1; st->VAD = 0; - st->old_gaintcx_bfi = 0; - st->old_gaintcx_bfi_e = 0 ; - st->tcx_cfg.na_scale = 32767/*1.0f Q15*/; + st->old_gaintcx_bfi=0.0f; + st->tcx_cfg.na_scale = 1.f; st->tcx_hm_LtpPitchLag = -1; - st->tcxltp_gain = 0; - + st->tcxltp_gain = 0.0f; return; } diff --git a/src/libs/libevs/lib_dec/core_dec_reconf.cpp b/src/libs/libevs/lib_dec/core_dec_reconf.cpp old mode 100755 new mode 100644 index fe155e69..bbcd9084 --- a/src/libs/libevs/lib_dec/core_dec_reconf.cpp +++ b/src/libs/libevs/lib_dec/core_dec_reconf.cpp @@ -1,32 +1,40 @@ /*==================================================================================== - EVS Codec 3GPP TS26.442 Apr 03, 2018. Version 12.11.0 / 13.6.0 / 14.2.0 + EVS Codec 3GPP TS26.443 Nov 13, 2018. Version 12.11.0 / 13.7.0 / 14.3.0 / 15.1.0 ====================================================================================*/ #include #include #include -#include "basop_util.h" -#include "prot_fx.h" +#include #include "options.h" -#include "stl.h" -#include "rom_com_fx.h" +#include "prot.h" +#include "rom_com.h" +#include "rom_dec.h" +/*---------------------------------------------------------------------* + * reconfig_decoder_LPD() + * + * + *---------------------------------------------------------------------*/ -void reconfig_decoder_LPD( Decoder_State_fx *st, Word16 bits_frame, Word16 bandwidth_mode, Word32 bitrate, Word16 L_frame_old) +void reconfig_decoder_LPD( + Decoder_State *st, + int bits_frame, + int bandwidth, + int bitrate, + int L_frame_old +) { + short i; + st->bits_frame = bits_frame; - move16(); - st->bits_frame=bits_frame; - - IF (bandwidth_mode==0) + if( bandwidth == NB ) { - move16(); st->narrowBand = 1; } - ELSE if (bandwidth_mode>0) + else if( bandwidth > NB ) { - move16(); st->narrowBand = 0; } @@ -43,127 +51,100 @@ void reconfig_decoder_LPD( Decoder_State_fx *st, Word16 bits_frame, Word16 bandw st->acelp_cfg_rf.formant_enh_num = FORMANT_SHARPENING_G1; st->acelp_cfg_rf.formant_enh_den = FORMANT_SHARPENING_G2; - - st->flag_cna = getCnaPresent(bitrate, bandwidth_mode); - move16(); + st->flag_cna = getCnaPresent(bitrate, bandwidth); /* TCX-LTP */ st->tcxltp = getTcxLtp(st->sr_core); - move16(); + /*Scale TCX for non-active frames to adjust loudness with ACELP*/ + st->tcx_cfg.na_scale = 1.f; + + if( bandwidth < SWB && !(st->tcxonly) ) { - Word16 i; - - /*Scale TCX for non-active frames to adjust loudness with ACELP*/ - st->tcx_cfg.na_scale=32767/*1.0f Q15*/; - - test(); - IF ((sub(bandwidth_mode,SWB)<0) && !(st->tcxonly)) + int scaleTableSize = sizeof (scaleTcxTable) / sizeof (scaleTcxTable[0]); + for (i = 0 ; i < scaleTableSize ; i++) { - Word16 scaleTableSize = sizeof (scaleTcxTable) / sizeof (scaleTcxTable[0]); /* is a constant */ - - FOR (i = 0 ; i < scaleTableSize ; i++) + if ( (bandwidth == scaleTcxTable[i].bwmode) && + (bitrate >= scaleTcxTable[i].bitrateFrom) && + (bitrate < scaleTcxTable[i].bitrateTo) ) { - test(); - test(); - IF ( (sub (bandwidth_mode,scaleTcxTable[i].bwmode) == 0) && - (L_sub (bitrate,scaleTcxTable[i].bitrateFrom) >= 0) && - (L_sub (bitrate,scaleTcxTable[i].bitrateTo) < 0 ) - ) + if( st->rf_flag ) { - if( st->rf_flag ) - { - i--; - } - st->tcx_cfg.na_scale=scaleTcxTable[i].scale; - BREAK; + i--; } + st->tcx_cfg.na_scale = scaleTcxTable[i].scale; + break; } } } /*if its not the first frame resample overlap buffer to new sampling rate */ - IF ( st->ini_frame_fx != 0 ) + if( st->ini_frame != 0 ) { - test(); - test(); - test(); - IF( sub (st->fscale,st->fscale_old) != 0 - && ! (st->last_codec_mode == MODE1 - && st->last_core_fx == ACELP_CORE - && st->prev_bfi_fx != 0)) - /* no resempling is needed here when recovering from mode 1 - acelp plc, since the buffers are already sampled with the - correct sampling rate in open_decoder_LPD() */ + if( st->fscale!=st->fscale_old + && ! (st->last_codec_mode == MODE1 + && st->last_core == ACELP_CORE + && st->prev_bfi != 0)) + /* no resempling is needed here when recovering from mode 1 + acelp plc, since the buffers are already sampled with the + correct sampling rate in open_decoder_LPD() */ { - Word16 newLen; - Word16 oldLen; + unsigned short newLen; + unsigned short oldLen; newLen = st->tcx_cfg.tcx_mdct_window_length; - move16(); oldLen = st->tcx_cfg.tcx_mdct_window_length_old; - move16(); - test(); - test(); - IF( (st->prev_bfi_fx && sub(st->last_core_bfi,ACELP_CORE)==0) || sub(st->last_core_fx,ACELP_CORE)==0 ) + if( (st->prev_bfi && st->last_core_bfi == ACELP_CORE) || st->last_core == ACELP_CORE ) { - newLen = shr(st->L_frame_fx,1); - oldLen = shr(L_frame_old,1); + newLen = st->L_frame/2; + oldLen = L_frame_old/2; } lerp( st->old_syn_Overl, st->old_syn_Overl, newLen, oldLen ); lerp( st->syn_Overl, st->syn_Overl, newLen, oldLen ); - test(); - IF( st->prev_bfi_fx && sub(st->last_core_bfi,ACELP_CORE)==0 ) + if( st->prev_bfi && st->last_core_bfi == ACELP_CORE ) { lerp( st->syn_Overl_TDAC, st->syn_Overl_TDAC, newLen, oldLen ); } } - - IF (sub(st->L_frame_fx,L_FRAME16k) <= 0) + if (st->L_frame <= L_FRAME16k) { - IF (sub(st->last_L_frame_fx,L_FRAME16k) <= 0) + if( st->last_L_frame <= L_FRAME16k ) { - IF (sub(st->L_frame_fx,st->last_L_frame_fx) != 0) + if( st->L_frame!=st->last_L_frame ) { - Word16 oldLenClasBuff; - Word16 newLenClasBuff; - IF (sub(st->L_frame_fx,st->last_L_frame_fx) > 0) + unsigned short oldLenClasBuff; + unsigned short newLenClasBuff; + + if( st->L_frame > st->last_L_frame ) { - oldLenClasBuff = extract_l(L_shr(Mpy_32_16_1(L_mult0(st->last_L_frame_fx,getInvFrameLen(st->L_frame_fx)/*Q21*/)/*Q21*/,L_SYN_MEM_CLAS_ESTIM/*Q0*/)/*Q6*/,6)/*Q0*/); - + oldLenClasBuff = L_SYN_MEM_CLAS_ESTIM * st->last_L_frame/st->L_frame; newLenClasBuff = L_SYN_MEM_CLAS_ESTIM; - move16(); - } - ELSE + else { oldLenClasBuff = L_SYN_MEM_CLAS_ESTIM; - newLenClasBuff = extract_l(L_shr(Mpy_32_16_1(L_mult0(st->L_frame_fx,getInvFrameLen(st->last_L_frame_fx)/*Q21*/)/*Q21*/,L_SYN_MEM_CLAS_ESTIM/*Q0*/)/*Q6*/,6)/*Q0*/); + newLenClasBuff = L_SYN_MEM_CLAS_ESTIM * st->L_frame/st->last_L_frame; } - lerp( &st->mem_syn_clas_estim_fx[L_SYN_MEM_CLAS_ESTIM-oldLenClasBuff], &st->mem_syn_clas_estim_fx[L_SYN_MEM_CLAS_ESTIM-newLenClasBuff], newLenClasBuff, oldLenClasBuff ); + lerp( &st->mem_syn_clas_estim[L_SYN_MEM_CLAS_ESTIM-oldLenClasBuff], &st->mem_syn_clas_estim[L_SYN_MEM_CLAS_ESTIM-newLenClasBuff], newLenClasBuff, oldLenClasBuff ); } } - ELSE + else { - set16_fx(st->mem_syn_clas_estim_fx, 0, L_SYN_MEM_CLAS_ESTIM); - st->classifier_Q_mem_syn = 0; - move16(); + set_zero( st->mem_syn_clas_estim, L_SYN_MEM_CLAS_ESTIM ); } } } - test(); - test(); + st->enableTcxLpc = (st->numlpc == 1) && (st->lpcQuantization == 1) && (bitrate <= LOWRATE_TCXLPC_MAX_BR || st->rf_flag); - if (st->ini_frame_fx == 0) + if( st->ini_frame == 0 ) { st->envWeighted = 0; } - return; } diff --git a/src/libs/libevs/lib_dec/core_dec_switch.cpp b/src/libs/libevs/lib_dec/core_dec_switch.cpp old mode 100755 new mode 100644 index 3c032fb3..b0d208b0 --- a/src/libs/libevs/lib_dec/core_dec_switch.cpp +++ b/src/libs/libevs/lib_dec/core_dec_switch.cpp @@ -1,227 +1,178 @@ /*==================================================================================== - EVS Codec 3GPP TS26.442 Apr 03, 2018. Version 12.11.0 / 13.6.0 / 14.2.0 + EVS Codec 3GPP TS26.443 Nov 13, 2018. Version 12.11.0 / 13.7.0 / 14.3.0 / 15.1.0 ====================================================================================*/ #include #include #include -#include "basop_util.h" -#include "prot_fx.h" -#include "stl.h" +#include #include "options.h" -#include "rom_com_fx.h" +#include "prot.h" +#include "rom_com.h" -void mode_switch_decoder_LPD( Decoder_State_fx *st, Word16 bandwidth, Word32 bitrate, Word16 frame_size_index - ) +/*-------------------------------------------------------------* + * mode_switch_decoder_LPD() + * + * + *-------------------------------------------------------------*/ + +void mode_switch_decoder_LPD( + Decoder_State *st, + int bandwidth, + int bitrate, + int frame_size_index +) { - Word16 fscale, switchWB; - Word32 sr_core; - Word8 bSwitchFromAmrwbIO; - Word16 frame_size; - + int fscale, switchWB, sr_core; + int bSwitchFromAmrwbIO; + int frame_size; switchWB = 0; - move16(); bSwitchFromAmrwbIO = 0; - move16(); - - if (sub(st->last_core_fx,AMR_WB_CORE)==0) + if(st->last_core == AMR_WB_CORE) { bSwitchFromAmrwbIO = 1; - move16(); } - sr_core = getCoreSamplerateMode2(bitrate, bandwidth, st->rf_flag); - fscale = sr2fscale(sr_core); - move16(); /* set number of coded lines */ st->tcx_cfg.tcx_coded_lines = getNumTcxCodedLines(bandwidth); - test(); - test(); - IF (( (sub(bandwidth, WB) >= 0) && (sub(fscale, (FSCALE_DENOM*16000)/12800) == 0) && (sub(fscale, st->fscale) == 0) )) + if ( (bandwidth>=WB) && (fscale==(FSCALE_DENOM*16000)/12800) && (fscale == st->fscale) ) { - test(); - test(); - test(); - if ( ((L_sub(bitrate, 32000) > 0) && (st->tcxonly == 0)) || ((L_sub(bitrate, 32000) <= 0) && (st->tcxonly != 0)) ) + if ( ((bitrate > ACELP_32k) && (st->tcxonly==0)) || ((bitrate <= ACELP_32k) && (st->tcxonly==1)) ) { switchWB = 1; - move16(); } } - test(); - if( sub(st->last_L_frame_fx,L_FRAME16k) >0 && L_sub(st->total_brate_fx,ACELP_32k) <=0 ) + if( st->last_L_frame > L_FRAME16k && st->total_brate <= ACELP_32k ) { - switchWB = 1; - move16(); + switchWB = 1; /*force init when coming from MODE1*/ } - - st->igf = getIgfPresent(bitrate, bandwidth, st->rf_flag); + st->igf = getIgfPresent(bitrate, bandwidth, st->rf_flag ); st->hIGFDec.infoIGFStopFreq = -1; - move16(); - IF( st->igf ) + if( st->igf ) { /* switch IGF configuration */ - IGFDecSetMode( &st->hIGFDec, st->total_brate_fx, bandwidth, -1, -1, st->rf_flag); - + IGFDecSetMode( &st->hIGFDec, st->total_brate, bandwidth, -1, -1, st->rf_flag ); } - test(); - test(); - test(); - test(); - IF ( sub(fscale, st->fscale) != 0 || switchWB != 0 || bSwitchFromAmrwbIO != 0 || sub(st->last_codec_mode,MODE1)==0 || st->force_lpd_reset ) + if( fscale != st->fscale || switchWB || bSwitchFromAmrwbIO || st->last_codec_mode == MODE1 || st->force_lpd_reset ) { open_decoder_LPD( st, bitrate, bandwidth ); } - ELSE + else { assert(fscale > (FSCALE_DENOM/2)); - st->fscale_old = st->fscale; - move16(); st->fscale = fscale; - move16(); - st->L_frame_fx = extract_l(Mult_32_16(st->sr_core , 0x0290)); - st->L_frameTCX = extract_l(Mult_32_16(st->output_Fs_fx , 0x0290)); + st->L_frame = st->sr_core / 50; + st->L_frameTCX = st->output_Fs / 50; st->tcx_cfg.ctx_hm = getCtxHm(bitrate, st->rf_flag); st->tcx_cfg.resq = getResq(bitrate); - move16(); - st->tcx_lpc_shaped_ari = getTcxLpcShapedAri( - bitrate, - bandwidth - ,st->rf_flag - ); + st->tcx_lpc_shaped_ari = getTcxLpcShapedAri( bitrate, bandwidth, st->rf_flag ); - st->narrowBand = 0; - move16(); - if ( sub(bandwidth, NB) == 0 ) + if ( bandwidth == NB ) { st->narrowBand = 1; - move16(); + } + else + { + st->narrowBand = 0; } st->TcxBandwidth = getTcxBandwidth(bandwidth); st->tcx_cfg.pCurrentTnsConfig = NULL; - st->tcx_cfg.fIsTNSAllowed = getTnsAllowed(bitrate, st->igf ); - move16(); - - IF (st->tcx_cfg.fIsTNSAllowed != 0) + st->tcx_cfg.fIsTNSAllowed = getTnsAllowed(st->total_brate, st->igf); + if( st->tcx_cfg.fIsTNSAllowed ) { - InitTnsConfigs(bwMode2fs[bandwidth], st->tcx_cfg.tcx_coded_lines, st->tcx_cfg.tnsConfig, st->hIGFDec.infoIGFStopFreq, st->total_brate_fx); + InitTnsConfigs( bwMode2fs[bandwidth], st->tcx_cfg.tcx_coded_lines, st->tcx_cfg.tnsConfig, st->hIGFDec.infoIGFStopFreq, st->total_brate ); } } frame_size = FrameSizeConfig[frame_size_index].frame_net_bits; - move16(); - reconfig_decoder_LPD( st, frame_size, bandwidth, bitrate, st->last_L_frame_fx ); + reconfig_decoder_LPD( st, frame_size, bandwidth, bitrate, st->last_L_frame ); - test(); - IF (st->envWeighted != 0 && st->enableTcxLpc == 0) + if (st->envWeighted && !st->enableTcxLpc) { - Copy(st->lspold_uw, st->lsp_old_fx, M); - Copy(st->lsfold_uw, st->lsf_old_fx, M); + mvr2r(st->lspold_uw, st->lsp_old, M); + mvr2r(st->lsfold_uw, st->lsf_old, M); st->envWeighted = 0; - move16(); } /* update PLC LSF memories */ - IF( st->tcxonly == 0 ) - { - lsp2lsf_fx( st->lsp_old_fx, st->lsfoldbfi1_fx, M, extract_l(st->sr_core) ); - } - ELSE - { - E_LPC_lsp_lsf_conversion( st->lsp_old_fx, st->lsfoldbfi1_fx, M ); - } - mvr2r_Word16(st->lsfoldbfi1_fx, st->lsfoldbfi0_fx,M); - mvr2r_Word16(st->lsfoldbfi1_fx, st->lsf_adaptive_mean_fx,M); + lsp2lsf( st->lsp_old, st->lsfoldbfi1, M, st->sr_core ); + mvr2r(st->lsfoldbfi1, st->lsfoldbfi0,M); + mvr2r(st->lsfoldbfi1, st->lsf_adaptive_mean,M); - IF( st->igf != 0 ) + if( st->igf ) { - test(); - test(); - test(); - test(); - test(); - IF( (sub(st->bwidth_fx, WB)==0 && sub(st->last_extl_fx, WB_TBE)!=0) || - (sub(st->bwidth_fx, SWB)==0 && sub(st->last_extl_fx, SWB_TBE)!=0) || - (sub(st->bwidth_fx, FB)==0 && sub(st->last_extl_fx,FB_TBE)!=0) ) + /* reset TBE */ + if( ( st->bwidth == WB && st->last_extl != WB_TBE ) || + ( st->bwidth == SWB && st->last_extl != SWB_TBE ) || + ( st->bwidth == FB && st->last_extl != FB_TBE ) ) { - TBEreset_dec_fx(st, st->bwidth_fx); + TBEreset_dec( st, st->bwidth ); } - ELSE + else { - set16_fx( st->state_lpc_syn_fx, 0, LPC_SHB_ORDER ); - set16_fx( st->state_syn_shbexc_fx, 0, L_SHB_LAHEAD ); - set16_fx( st->mem_stp_swb_fx, 0, LPC_SHB_ORDER ); - set16_fx( st->mem_zero_swb_fx, 0, LPC_SHB_ORDER ); - st->gain_prec_swb_fx = 16384; - move16(); /*Q14 = 1 */ + set_f( st->state_lpc_syn, 0.0f, LPC_SHB_ORDER ); + set_f( st->state_syn_shbexc, 0.0f, L_SHB_LAHEAD ); + set_f( st->mem_stp_swb, 0.0f, LPC_SHB_ORDER ); + set_f( st->mem_zero_swb, 0, LPC_SHB_ORDER ); + st->gain_prec_swb = 1.0f; } } - test(); - test(); - IF( (sub(bandwidth, SWB) == 0) && - (L_sub(st->total_brate_fx, ACELP_16k40) == 0 || L_sub(st->total_brate_fx, ACELP_24k40) == 0) - ) + if( bandwidth == SWB && (st->total_brate == ACELP_16k40 || st->total_brate == ACELP_24k40) ) { - IF (st->tec_tfa == 0) + if(st->tec_tfa == 0) { - set16_fx(st->tecDec_fx.loBuffer, 0, MAX_TEC_SMOOTHING_DEG); + set_zero(st->tecDec.loBuffer, MAX_TEC_SMOOTHING_DEG); } st->tec_tfa = 1; - move16(); } - ELSE + else { st->tec_tfa = 0; - move16(); } st->tec_flag = 0; - move16(); st->tfa_flag = 0; - move16(); /* needed in decoder to read the bitstream */ - st->enableGplc = 0; - move16(); - test(); - test(); - test(); - test(); - test(); - if( (sub(bandwidth, WB ) == 0 && L_sub(bitrate, 24400) == 0) || - (sub(bandwidth, SWB) == 0 && L_sub(bitrate, 24400) == 0 )|| - (sub(bandwidth, FB) == 0 && L_sub(bitrate, 24400) == 0 ) ) + if ( + ( bandwidth == FB && bitrate == ACELP_24k40 ) || + ( bandwidth == WB && bitrate == ACELP_24k40 ) || + ( bandwidth == SWB && bitrate == ACELP_24k40 ) + ) { st->enableGplc = 1; - move16(); } - move16(); - st->dec_glr = 0; - test(); - test(); - if( (L_sub(st->total_brate_fx, 9600)==0)||( L_sub(st->total_brate_fx, 16400)==0)|| - (L_sub(st->total_brate_fx, 24400)==0)) + else + { + st->enableGplc = 0; + } + + if( st->total_brate == ACELP_9k60 || st->total_brate == ACELP_16k40 || st->total_brate == ACELP_24k40 ) { st->dec_glr = 1; - move16(); } - move16(); + else + { + st->dec_glr = 0; + } + st->dec_glr_idx = 0; -} + return; +} diff --git a/src/libs/libevs/lib_dec/core_switching_dec.cpp b/src/libs/libevs/lib_dec/core_switching_dec.cpp new file mode 100644 index 00000000..91bc20a1 --- /dev/null +++ b/src/libs/libevs/lib_dec/core_switching_dec.cpp @@ -0,0 +1,824 @@ +/*==================================================================================== + EVS Codec 3GPP TS26.443 Nov 13, 2018. Version 12.11.0 / 13.7.0 / 14.3.0 / 15.1.0 + ====================================================================================*/ + +#include +#include +#include "options.h" +#include "cnst.h" +#include "rom_com.h" +#include "prot.h" + +/*---------------------------------------------------------------------* + * core_switching_pre_dec() + * + * Preprocessing/preparation for ACELP/HQ core switching + *---------------------------------------------------------------------*/ + +void core_switching_pre_dec( + Decoder_State *st, /* i/o: decoder state structure */ + const short output_frame /* i : frame length */ +) +{ + short oldLenClasBuff, newLenClasBuff; + + + /* Codec mode switching */ + if( st->last_codec_mode == MODE2 ) + { + mvr2r( st->mem_syn2, st->mem_syn1, M ); + set_f( st->agc_mem2, 0, 2 ); + st->mem_deemph = st->syn[M]; + st->bpf_off = 1; + set_f( st->pst_old_syn, 0, NBPSF_PIT_MAX); + st->pst_mem_deemp_err = 0; + st->psf_lp_noise = st->lp_noise; + + /* reset old HB synthesis buffer */ + if( st->last_L_frame == L_FRAME ) + { + st->old_bwe_delay = NS2SA( st->output_Fs, MAX_DELAY_TBE_NS - DELAY_SWB_TBE_12k8_NS ); + } + else + { + st->old_bwe_delay = NS2SA( st->output_Fs, MAX_DELAY_TBE_NS - DELAY_SWB_TBE_16k_NS ); + } + set_f( st->hb_prev_synth_buffer, 0, NS2SA(48000, DELAY_BWE_TOTAL_NS) ); + + /* reset upd_cnt */ + st->upd_cnt = MAX_UPD_CNT; + st->igf = 0; + + if( st->last_core != ACELP_CORE ) + { + /* reset BWE memories */ + set_f( st->old_bwe_exc, 0, PIT16k_MAX*2 ); + st->bwe_non_lin_prev_scale = 0.0f; + } + + if( st->output_Fs >= 16000 ) + { + hf_synth_reset( &st->seed2, st->mem_hf, st->mem_syn_hf, st->mem_hp400, st->mem_hp_interp, st->delay_syn_hf ); + } + set_f( st->old_syn_12k8_16k, 0, NS2SA(16000, DELAY_FD_BWE_ENC_NS) ); + + set_f( st->prev_env, 0, SFM_N_WB ); + set_f( st->prev_normq, 0, SFM_N_WB ); + + set_f( st->last_ni_gain, 0, BANDS_MAX ); + set_f( st->last_env, 0, BANDS_MAX ); + st->last_max_pos_pulse = 0; + + if( st->output_Fs > 16000 ) + { + set_f( st->prev_coeff_out, 0, L_HQ_WB_BWE ); + } + + /* pre-echo */ + st->pastpre = 0; + /* reset the GSC pre echo energy threshold in case of switching */ + st->Last_frame_ener = (float)MAX_32; + + if( st->last_core == TCX_20_CORE || st->last_core == TCX_10_CORE ) + { + st->last_core = HQ_CORE; + mvr2r( st->FBTCXdelayBuf, st->prev_synth_buffer, NS2SA(st->output_Fs, DELAY_BWE_TOTAL_NS - DELAY_CLDFB_NS)); + set_f( st->last_ni_gain, 0, BANDS_MAX ); + set_f( st->last_env, 0, BANDS_MAX ); + st->last_max_pos_pulse = 0; + + set_s( st->prev_SWB_peak_pos, 0, SPT_SHORTEN_SBNUM ); + st->prev_frm_hfe2 = 0; + st->prev_stab_hfe2 = 0; + } + + if( st->prev_bfi != 0 ) + { + short delay_comp; + + /*switch off Hq Voicing as it was not uodated in MODE2*/ + st->oldHqVoicing = 0; + st->HqVoicing = 0; + + delay_comp = NS2SA(st->output_Fs, DELAY_CLDFB_NS); + + if( !st->last_con_tcx && st->last_core_bfi == ACELP_CORE && st->core == HQ_CORE ) + { + short i; + float *realBuffer[CLDFB_NO_COL_MAX], *imagBuffer[CLDFB_NO_COL_MAX]; + float realBufferTmp[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX], imagBufferTmp[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX]; + + for( i=0; icldfbAna ); + cldfbAnalysis( st->syn_Overl, realBuffer, imagBuffer, delay_comp, st->cldfbAna ); + cldfb_restore_memory( st->cldfbAna ); + + /* CLDFB synthesis of the combined signal */ + cldfb_save_memory( st->cldfbSyn ); + cldfbSynthesis( realBuffer, imagBuffer, st->fer_samples, delay_comp, st->cldfbSyn ); + cldfb_restore_memory( st->cldfbSyn ); + } + + if( !st->last_con_tcx && st->last_core_bfi == ACELP_CORE && st->core == HQ_CORE ) + { + lerp(st->syn_Overl, st->fer_samples+delay_comp,output_frame/2, st->last_L_frame/2); + /*Set to zero the remaining part*/ + set_f( st->fer_samples+delay_comp+output_frame/2, 0, (output_frame/2)-delay_comp); + } + } + + st->use_acelp_preq = 0; + st->reset_mem_AR=0; + } + + /*FEC*/ + if( st->L_frame <= L_FRAME16k ) + { + if( st->last_L_frame <= L_FRAME16k && st->core != HQ_CORE ) + { + if( st->L_frame!=st->last_L_frame ) + { + if (st->L_frame>st->last_L_frame) + { + oldLenClasBuff = L_SYN_MEM_CLAS_ESTIM * st->last_L_frame/st->L_frame; + newLenClasBuff = L_SYN_MEM_CLAS_ESTIM; + } + else + { + oldLenClasBuff = L_SYN_MEM_CLAS_ESTIM; + newLenClasBuff = L_SYN_MEM_CLAS_ESTIM * st->L_frame/st->last_L_frame; + } + lerp( &st->mem_syn_clas_estim[L_SYN_MEM_CLAS_ESTIM-oldLenClasBuff], &st->mem_syn_clas_estim[L_SYN_MEM_CLAS_ESTIM-newLenClasBuff], newLenClasBuff, oldLenClasBuff ); + } + } + else + { + set_zero( st->mem_syn_clas_estim, L_SYN_MEM_CLAS_ESTIM ); + } + } + + /* Here we only handle cases where last_ppp and last_nelp not updated when coming from CodecB or other cores + within ACELP_CORE if switching from another bitarate to vbr, last_ppp and last_nelp is always updated in the previous frame */ + if( st->core == ACELP_CORE && (st->last_core != ACELP_CORE || st->last_codec_mode == MODE2 ) ) + { + st->last_ppp_mode_dec = 0; + st->last_nelp_mode_dec =0; + } + + /* Handle state reset of stat_noise_uv_mod memory */ + if( st->core == ACELP_CORE && (st->last_core != ACELP_CORE || st->last_codec_mode == MODE2 || st->last_total_brate <= PPP_NELP_2k80 ) ) + { + st->act_count = 3; + st->uv_count = 0; + } + + if( (st->core == ACELP_CORE || st->core == AMR_WB_CORE ) && st->last_core == HQ_CORE ) + { + if( st->L_frame == L_FRAME16k ) + { + mvr2r( TRWB2_Ave, st->lsf_old, M ); /* init of LSP */ + mvr2r( TRWB2_Ave, st->lsfoldbfi1, M ); + mvr2r( TRWB2_Ave, st->lsfoldbfi0, M ); + mvr2r( TRWB2_Ave, st->lsf_adaptive_mean, M ); + lsf2lsp( st->lsf_old, st->lsp_old, M, INT_FS_16k ); + } + else + { + mvr2r( TRWB_Ave, st->lsf_old, M ); /* init of LSP */ + mvr2r( TRWB_Ave, st->lsfoldbfi1, M ); + mvr2r( TRWB_Ave, st->lsfoldbfi0, M ); + mvr2r( TRWB_Ave, st->lsf_adaptive_mean, M ); + lsf2lsp( st->lsf_old, st->lsp_old, M, INT_FS_12k8 ); + } + + set_f( st->agc_mem2, 0, 2 ); + st->mem_deemph = 0; + if( !st->last_con_tcx ) + { + set_f( st->mem_syn2, 0.0f, M ); + } + set_f( st->mem_syn1, 0.0f, M ); + st->bwe_non_lin_prev_scale = 0.0f; + + /* Reset ACELP parameters */ + set_zero( st->mem_MA, M ); + if( st->sr_core == 16000 ) + { + mvr2r( GEWB2_Ave, st->mem_AR, M ); + } + else + { + mvr2r( GEWB_Ave, st->mem_AR, M ); + } + st->tilt_code = 0.0f; + st->gc_threshold = 0.0f; + set_f( st->dispMem, 0, 8 ); + + st->last_coder_type = GENERIC; + + fer_energy( output_frame, UNVOICED_CLAS, st->previoussynth, -1, &st->enr_old, 1 ); + st->lp_gainp = 0.0f; + st->lp_gainc = (float)sqrt( st->lp_ener ); + + + st->last_voice_factor = 0; + st->Last_GSC_noisy_speech_flag = 0; + + /* reset CLDFB memories */ + cldfb_reset_memory( st->cldfbAna ); + cldfb_reset_memory( st->cldfbBPF ); + cldfb_reset_memory( st->cldfbSyn ); + + /* reset TBE memories */ + if( !st->last_con_tcx ) + { + set_f( st->old_exc,0, L_EXC_MEM_DEC ); + } + else if( st->L_frame < L_FRAME16k ) + { + /* resample from 16kHz to 12.8kHZ */ + synth_mem_updt2( st->L_frame, L_FRAME16k, st->old_exc, st->mem_syn_r, st->mem_syn2, NULL, DEC ); + } + + set_f( st->old_bwe_exc, 0, PIT16k_MAX*2 ); + + if( st->output_Fs >= 16000 ) + { + hf_synth_reset( &st->seed2, st->mem_hf, st->mem_syn_hf, st->mem_hp400, st->mem_hp_interp, st->delay_syn_hf ); + } + set_f( st->old_syn_12k8_16k, 0, NS2SA(16000, DELAY_FD_BWE_ENC_NS) ); + } + + if( st->core == HQ_CORE && (st->last_core == ACELP_CORE || st->last_core == AMR_WB_CORE) ) + { + set_f( st->prev_env, 0, SFM_N_WB ); + set_f( st->prev_normq, 0, SFM_N_WB ); + + set_f( st->last_ni_gain, 0, BANDS_MAX ); + set_f( st->last_env, 0, BANDS_MAX ); + st->last_max_pos_pulse = 0; + + set_s( st->prev_SWB_peak_pos, 0, SPT_SHORTEN_SBNUM ); + st->prev_frm_hfe2 = 0; + st->prev_stab_hfe2 = 0; + + if( st->output_Fs > 16000 ) + { + set_f( st->prev_coeff_out, 0, L_HQ_WB_BWE ); + } + + set_f( st->old_out, 0, output_frame ); + } + + /* handle switching cases where preecho_sb was not called in the last frame (memory not up to date) */ + st->pastpre--; + if( st->pastpre <= 0 ) + { + reset_preecho_dec(st); + } + + + if( st->core_brate == FRAME__NO_DATA ) + { + st->VAD = 0; + st->m_frame_type = ZERO_FRAME; + } + else if( st->core_brate <= SID_2k40 ) + { + st->VAD = 0; + st->m_frame_type = SID_FRAME; + } + else + { + st->VAD = 1; + st->m_frame_type = ACTIVE_FRAME; + } + + /*switch on CNA on active frames*/ + if( st->core != AMR_WB_CORE && st->VAD && st->total_brate <= CNA_MAX_BRATE ) + { + st->flag_cna = 1; + } + else if( st->core == AMR_WB_CORE && st->VAD && st->total_brate <= ACELP_8k85 ) + { + st->flag_cna = 1; + } + else if( st->VAD || ((st->cng_type==FD_CNG) && (st->L_frame == L_FRAME16k))) + { + st->flag_cna = 0; + } + + if( st->core == AMR_WB_CORE ) + { + st->cng_type = LP_CNG; + } + + /* Reconfigure CNG */ + if ( st->hFdCngDec && ((st->last_L_frame!=st->L_frame ) || + (st->hFdCngDec->hFdCngCom->frameSize!=st->L_frame) || + st->ini_frame == 0 || st->bwidth != st->last_bwidth)) + { + /* || st->last_core == AMR_WB_CORE || st->last_codec_mode == MODE2)){*/ + if( st->core != AMR_WB_CORE ) + { + configureFdCngDec( st->hFdCngDec, st->bwidth, st->rf_flag==1&&st->total_brate==13200?9600:st->total_brate, st->L_frame ); + } + else + { + configureFdCngDec( st->hFdCngDec, WB, ACELP_8k00, st->L_frame ); + + if( st->VAD ) + { + st->hFdCngDec->hFdCngCom->CngBitrate = st->total_brate; + } + } + if( st->last_L_frame!=st->L_frame && st->L_frame<=320 && st->last_L_frame<=320 ) + { + lerp( st->hFdCngDec->hFdCngCom->olapBufferSynth2, st->hFdCngDec->hFdCngCom->olapBufferSynth2, st->L_frame*2, st->last_L_frame*2 ); + if( st->total_brate<=SID_2k40 && st->last_total_brate<=SID_2k40 ) + { + lerp( st->hFdCngDec->hFdCngCom->olapBufferSynth, st->hFdCngDec->hFdCngCom->olapBufferSynth, st->L_frame*2, st->last_L_frame*2 ); + if( st->L_frame==L_FRAME ) + { + short n; + for (n=0; n < st->L_frame*2; n++) + { + st->hFdCngDec->hFdCngCom->olapBufferSynth[n] = st->hFdCngDec->hFdCngCom->olapBufferSynth[n]*0.6250f; + } + } + else + { + short n; + for (n=0; n < st->L_frame*2; n++) + { + st->hFdCngDec->hFdCngCom->olapBufferSynth[n] =st->hFdCngDec->hFdCngCom->olapBufferSynth[n]*1.6f; + } + } + } + } + } + + + return; +} + +/*---------------------------------------------------------------------* + * core_switching_post_dec() + * + * Postprocessing for ACELP/HQ core switching + *---------------------------------------------------------------------*/ + +void core_switching_post_dec( + Decoder_State *st, /* i/o: decoder state structure */ + float *synth, /* i/o: output synthesis */ + const short output_frame, /* i : frame length */ + const short core_switching_flag, /* i : ACELP->HQ switching flag */ + const short coder_type /* i : ACELP coder type */ +) +{ + short i, delay_comp, delta; + float tmpF; + float tmpDelta; + float synth_subfr_out[SWITCH_MAX_GAP], synth_subfr_bwe[SWITCH_MAX_GAP]; + float mem_synth[NS2SA(16000, DELAY_CLDFB_NS)+2]; + short nZeros; + + + if( st->core == ACELP_CORE && st->bfi ) + { + acelp_core_switch_dec_bfi( st, st->fer_samples, coder_type ); + } + + /* set multiplication factor according to the sampling rate */ + delta = 1; + if( output_frame == L_FRAME16k ) + { + delta = 2; + } + else if( output_frame == L_FRAME32k ) + { + delta = 4; + } + else if( output_frame == L_FRAME48k ) + { + delta = 6; + } + + /* set delay compensation between HQ synthesis and ACELP synthesis */ + delay_comp = delta * HQ_DELAY_COMP; + + if( st->core == HQ_CORE ) + { + st->use_acelp_preq = 0; + st->mem_deemph_old_syn = 0.0f; + + if( core_switching_flag && st->last_L_frame == st->last_L_frame_ori && (st->last_core == ACELP_CORE || st->last_core == AMR_WB_CORE)) + { + acelp_core_switch_dec( st, synth_subfr_out, synth_subfr_bwe, output_frame, core_switching_flag, mem_synth ); + } + + if( core_switching_flag && st->last_core == HQ_CORE && st->prev_bfi ) + { + mvr2r( st->delay_buf_out, synth_subfr_out, delay_comp ); + } + + /* delay HQ synthesis to synchronize with ACELP synthesis */ + mvr2r( synth, synth + delay_comp, output_frame); + mvr2r( st->delay_buf_out, synth, delay_comp ); + mvr2r( synth + output_frame, st->delay_buf_out, delay_comp ); + + if( core_switching_flag && st->last_L_frame == st->last_L_frame_ori && (st->last_core == ACELP_CORE || st->last_core == AMR_WB_CORE)) + { + core_switching_OLA( mem_synth, st->last_L_frame, st->output_Fs, synth, synth_subfr_out, synth_subfr_bwe, output_frame, st->bwidth ); + } + else if( core_switching_flag && st->last_core == HQ_CORE && st->prev_bfi ) /* HQ | ACELP | TRANSITION with ACELP frame lost */ + { + nZeros = (short)(NS2SA(st->output_Fs,N_ZERO_MDCT_NS)); + /* Overlapp between old->out[] (stocked in st->fer_samples[]) and good HQ frame on L/2 */ + tmpDelta = 1.0f/(float)(output_frame>>1); + for( i=0; i>1; i++ ) + { + tmpF = (float)i * tmpDelta; + synth[i+delay_comp] = (1-tmpF) * st->fer_samples[i+nZeros] + synth[i+delay_comp] * tmpF; + } + } + else if ( ( !core_switching_flag && st->core == HQ_CORE && (st->last_core == ACELP_CORE || st->last_core == AMR_WB_CORE) ) || /* ACELP | TRANSITION | HQ with TRANSITION lost */ + ( core_switching_flag && st->prev_bfi && st->last_L_frame != st->last_L_frame_ori ) ) /* ACELP@12k8 | ACELP@16k | TRANSITION with ACELP@16k lost */ + { + /* Overlapp between CELP estimation (BFI) and good HQ frame on L/2 */ + tmpDelta = 1.0f/(float)(output_frame>>1); + for( i=0; i<(output_frame>>1); i++ ) + { + tmpF = (float)i * tmpDelta; + synth[i] = synth[i] * tmpF + (1-tmpF) * st->fer_samples[i]; + } + } + + st->bwe_non_lin_prev_scale = 0.0; + if ( !(inner_frame_tbl[st->bwidth] == L_FRAME16k && st->core_brate == HQ_32k ) ) + { + set_f( st->prev_env, 0, SFM_N_WB ); + set_f( st->prev_normq, 0, SFM_N_WB ); + } + + mvr2r( synth, st->previoussynth, output_frame ); + + /*Set post-filtering flag to zero*/ + st->pfstat.on = 0; + } + else + { + /* MDCT to ACELP transition */ + if( st->last_core == HQ_CORE ) + { + nZeros = (short)(NS2SA(st->output_Fs,N_ZERO_MDCT_NS)); + mvr2r( st->delay_buf_out, synth, delay_comp ); /* copy the HQ/ACELP delay synchroniation buffer at the beginning of ACELP frame */ + + if(st->prev_bfi && st->HqVoicing) + { + mvr2r( st->fer_samples, st->old_out+nZeros, NS2SA(st->output_Fs,3000000) ); + } + + tmpF = 1.0f/(float)NS2SA(st->output_Fs,3000000); + for( i=0; ioutput_Fs,3000000); i++ ) + { + synth[i+delay_comp] = (1-tmpF*(float)i)*st->old_out[i+nZeros] + tmpF*(float)i*synth[i+delay_comp]; + } + } + + set_f( st->delay_buf_out, 0, HQ_DELTA_MAX*HQ_DELAY_COMP ); + st->oldHqVoicing = 0; + } + + /* reset SWB BWE buffers */ + if ( st->bws_cnt == 0 || ( st->bws_cnt > 0 && coder_type != INACTIVE && coder_type != AUDIO ) ) + { + st->attenu1 = 0.1f; + } + if( ( st->last_extl != SWB_BWE && st->extl == SWB_BWE ) || ( st->last_extl != FB_BWE && st->extl == FB_BWE ) || + ((st->last_core == HQ_CORE || st->last_extl == SWB_TBE) && st->extl < 0 && st->core != HQ_CORE) + || (st->last_core == ACELP_CORE && st->core == ACELP_CORE + && ((st->prev_coder_type != INACTIVE && coder_type != INACTIVE) || (st->prev_coder_type != AUDIO && coder_type == AUDIO)) + && st->bws_cnt >0) + ) + { + set_f(st->old_wtda_swb, 0, output_frame); + + if( st->last_extl != WB_BWE ) + { + st->prev_mode = NORMAL; + } + + st->prev_Energy = 0.0f; + st->prev_L_swb_norm = 8; + st->prev_frica_flag = 0; + set_f( st->mem_imdct, 0, L_FRAME48k ); + st->prev_td_energy = 0.0f; + st->prev_weight = 0.2f; + st->prev_fb_ener_adjust = 0.0f; + } + + /* reset WB BWE buffers */ + if( st->last_extl != WB_BWE && st->extl == WB_BWE ) + { + set_f(st->old_wtda_swb, 0, output_frame); + if ( st->last_extl != SWB_BWE && st->last_extl != FB_BWE ) + { + st->prev_mode = NORMAL; + } + st->prev_Energy_wb = 0.0f; + st->prev_L_swb_norm = 8; + set_f( st->mem_imdct, 0, L_FRAME48k ); + st->prev_flag = 0; + } + + /* reset SWB TBE buffers */ + if( (( st->extl == SWB_TBE || st->extl == FB_TBE || st->extl == SWB_CNG ) && + (st->L_frame != st->last_L_frame || ( st->last_extl != SWB_TBE && st->last_extl != FB_TBE ) || st->last_core == HQ_CORE )) || + ( st->bwidth < st->last_bwidth && st->last_extl != SWB_TBE ) || st->old_ppp_mode + || ((st->prev_coder_type == AUDIO || st->prev_coder_type == INACTIVE) && st->bws_cnt > 0 ) + || (st->bws_cnt == 0 && st->prev_bws_cnt == N_WS2N_FRAMES) + ) + { + swb_tbe_reset( st->mem_csfilt, st->mem_genSHBexc_filt_down_shb, st->state_lpc_syn, + st->syn_overlap, st->state_syn_shbexc, &(st->tbe_demph), &(st->tbe_premph), st->mem_stp_swb, &(st->gain_prec_swb) ); + + /* reset GainShape delay for SWB TBE FEC */ + set_f( st->GainShape_Delay, 0, NUM_SHB_SUBFR/2 ); + + swb_tbe_reset_synth( st->genSHBsynth_Hilbert_Mem, st->genSHBsynth_state_lsyn_filt_shb_local ); + + if( output_frame == L_FRAME16k ) + { + set_f( st->mem_resamp_HB_32k, 0, 2*ALLPASSSECTIONS_STEEP+1 ); /* reset in case that SWB TBE layer is transmitted, but the output is 16kHz sampled */ + } + + set_f(st->int_3_over_2_tbemem_dec, 0.0f, INTERP_3_2_MEM_LEN); + } + else if( (st->extl == SWB_TBE || st->extl == FB_TBE) && + ( (st->last_total_brate != st->total_brate) || (st->last_bwidth != st->bwidth) || + (st->last_codec_mode != MODE1) || (st->rf_flag != st->rf_flag_last) ) ) + { + set_f( st->state_lpc_syn, 0.0f, LPC_SHB_ORDER ); + set_f( st->state_syn_shbexc, 0.0f, L_SHB_LAHEAD ); + set_f( st->mem_stp_swb, 0.0f, LPC_SHB_ORDER ); + set_f( st->mem_zero_swb, 0, LPC_SHB_ORDER ); + st->gain_prec_swb = 1.0f; + } + + /* Interp_3_2 CNG buffers reset */ + if(st->output_Fs == 48000 && ((st->last_core_brate > SID_2k40) && (st->core_brate == FRAME__NO_DATA || st->core_brate == SID_2k40)) ) + { + set_f(st->interpol_3_2_cng_dec, 0.0f, INTERP_3_2_MEM_LEN); + } + + /* reset FB TBE buffers */ + if( (st->L_frame != st->last_L_frame || st->last_extl != FB_TBE ) && st->extl == FB_TBE ) + { + set_f(st->fb_state_lpc_syn, 0, LPC_SHB_ORDER); + st->fb_tbe_demph = 0; + fb_tbe_reset_synth( st->fbbwe_hpf_mem,&st->prev_fbbwe_ratio ); + } + + /* reset WB TBE buffers */ + if( st->last_extl != WB_TBE && st->extl == WB_TBE ) + { + wb_tbe_extras_reset( st->mem_genSHBexc_filt_down_wb2, st->mem_genSHBexc_filt_down_wb3 ); + wb_tbe_extras_reset_synth( st->state_lsyn_filt_shb, st->state_lsyn_filt_dwn_shb, st->mem_resamp_HB ); + + set_f( st->state_syn_shbexc, 0, L_SHB_LAHEAD / 4 ); + set_f( st->syn_overlap, 0, L_SHB_LAHEAD ); + set_f( st->mem_csfilt, 0, 2 ); + } + + + return; +} + + +/*---------------------------------------------------------------------* + * core_switching_hq_prepare_dec() + * + * Preprocessing in the first HQ frame after ACELP frame + * Modify bit allocation for HQ core by removing ACELP subframe budget +*---------------------------------------------------------------------*/ + +void core_switching_hq_prepare_dec( + Decoder_State *st, /* i/o: encoder state structure */ + short *num_bits, /* i/o: bit budget update */ + const short output_frame /* i : output frame length */ +) +{ + long cbrate; + + if( st->last_core == HQ_CORE && st->prev_bfi ) + { + mvr2r( st->old_out, st->fer_samples, output_frame ); + } + + /* set switching frame bit-rate */ + if( st->last_L_frame == L_FRAME ) + { + if( st->core_brate > ACELP_24k40 ) + { + cbrate = ACELP_24k40; + } + else + { + cbrate = st->core_brate; + } + + /* subtract ACELP switching frame bits */ + if( st->core_brate >= ACELP_11k60 ) + { + (*num_bits)--; /* LP_FLAG bit */ + } + + *num_bits -= ACB_bits_tbl[BIT_ALLOC_IDX(cbrate, GENERIC, 0, 0)]; /* pitch bits*/ + *num_bits -= gain_bits_tbl[BIT_ALLOC_IDX(cbrate, TRANSITION, 0, 0)]; /* gain bits */ + *num_bits -= FCB_bits_tbl[BIT_ALLOC_IDX(cbrate, GENERIC, 0, 0)]; /* FCB bits */ + } + else /* L_frame == L_FRAME16k */ + { + if( st->core_brate <= ACELP_8k00 ) + { + cbrate = ACELP_8k00; + } + else if( st->core_brate <= ACELP_14k80 ) + { + cbrate = ACELP_14k80; + } + else + { + cbrate = min(st->core_brate,ACELP_22k60); + } + + /* subtract ACELP switching frame bits */ + if( st->core_brate >= ACELP_11k60 ) + { + /* subtract one bit for LP filtering flag */ + (*num_bits)--; + } + *num_bits -= ACB_bits_16kHz_tbl[BIT_ALLOC_IDX_16KHZ(cbrate, GENERIC, 0, 0)]; /* pitch bits*/ + *num_bits -= gain_bits_16kHz_tbl[BIT_ALLOC_IDX_16KHZ(cbrate, GENERIC, 0, 0)]; /* gain bits */ + *num_bits -= FCB_bits_16kHz_tbl[BIT_ALLOC_IDX_16KHZ(cbrate, GENERIC, 0, 0)]; /* FCB bits */ + } + + /* subtract BWE bits */ + if( !( (inner_frame_tbl[st->bwidth] == L_FRAME16k && st->last_L_frame==L_FRAME16k) || inner_frame_tbl[st->bwidth]==L_FRAME8k ) ) + { + *num_bits -= (NOOFGAINBITS1 + AUDIODELAYBITS); + } + + /* reset state of old_out if switching */ + set_f( st->old_out, 0.0f, output_frame ); + + return; + +} + + +/*---------------------------------------------------------------------* + * bandwidth_switching_detect() + * + * Classification for band-width switching + *---------------------------------------------------------------------*/ + +void bandwidth_switching_detect( + Decoder_State *st /* i/o: encoder state structure */ +) +{ + /* update band-width switching counter */ + if( st->bws_cnt1 >= N_NS2W_FRAMES ) + { + st->bws_cnt1 = 0; + } + else if( st->total_brate > ACELP_9k60 && st->last_core_brate < ACELP_9k60 && st->bwidth == SWB && st->last_bwidth == WB ) + { + st->bws_cnt1++; + } + else if( st->bws_cnt1 > 0 ) + { + st->bws_cnt = st->bwidth < st->last_bwidth ? 2*(N_NS2W_FRAMES - st->bws_cnt1)-1 : 0; + st->bws_cnt1 = st->bwidth < st->last_bwidth ? 0 : ((st->bwidth == SWB) ? st->bws_cnt1+1 : 0); ; + } + + /* update band-width switching counter */ + if( st->bws_cnt >= N_WS2N_FRAMES ) + { + st->bws_cnt = 0; + } + else if( st->total_brate < ACELP_9k60 && st->last_core_brate > ACELP_9k60 && st->bwidth < st->last_bwidth && st->bwidth == WB ) + { + st->bws_cnt++; + } + else if( st->bws_cnt > 0 ) + { + st->bws_cnt1 = st->bwidth > st->last_bwidth ? ((N_WS2N_FRAMES - st->bws_cnt) >> 1) : 0; + st->bws_cnt = st->bwidth > st->last_bwidth ? 0 :(( st->bwidth == WB) ? st->bws_cnt+1 : 0); + } + + return; +} + + +/*---------------------------------------------------------------------* + * bw_switching_pre_proc() + * + * Band-width switching pre-processing + *---------------------------------------------------------------------*/ + +void bw_switching_pre_proc( + Decoder_State *st, /* i/o: decoder state structure */ + const float *old_syn_12k8_16k /* i : ACELP core synthesis at 12.8kHz or 16kHz */ +) +{ + short i; + float syn_dct[L_FRAME]; + + if( st->core == ACELP_CORE ) + { + /*----------------------------------------------------------------------* + * Calculate tilt of the ACELP core synthesis + *----------------------------------------------------------------------*/ + calc_tilt_bwe( old_syn_12k8_16k, &st->tilt_wb, st->L_frame); + /*-------------------------------------------------------------------------------* + * Calculate frequency energy of 0~3.2kHz and 3.2~6.4kHz the ACELP core synthesis + *-------------------------------------------------------------------------------*/ + + edct( old_syn_12k8_16k, syn_dct, L_FRAME ); + + st->enerLL = EPSILON; + for ( i=0; ienerLL += syn_dct[i] * syn_dct[i]; + } + st->enerLL = (float)sqrt(st->enerLL/128); + + st->enerLH = EPSILON; + for (; ienerLH += syn_dct[i] * syn_dct[i]; + } + st->enerLH = (float)sqrt(st->enerLH/128); + } + else + { + if( st->old_is_transient[0] ) + { + st->enerLL = EPSILON; + for ( i=0; i<32; i++ ) + { + st->enerLL += st->t_audio_q[i] * st->t_audio_q[i]; + } + st->enerLL = (float)sqrt(st->enerLL/32); + + st->enerLH = EPSILON; + for (; i<64; i++ ) + { + st->enerLH += st->t_audio_q[i] * st->t_audio_q[i]; + } + st->enerLH = (float)sqrt(st->enerLH/32); + } + else + { + st->enerLL = EPSILON; + for ( i=0; ienerLL += st->t_audio_q[i] * st->t_audio_q[i]; + } + st->enerLL = (float)sqrt(st->enerLL/128); + + st->enerLH = EPSILON; + for (; ienerLH += st->t_audio_q[i] * st->t_audio_q[i]; + } + st->enerLH = (float)sqrt(st->enerLH/128); + } + } + + if( st->last_bwidth == 0 && st->extl <= SWB_CNG ) + { + st->prev_ener_shb = 0.0f; + set_f(st->prev_SWB_fenv, 0, SWB_FENV); + } + else if( ((st->core == ACELP_CORE && st->last_core == HQ_CORE) || (st->core == st->last_core && st->extl != st->last_extl)) && st->last_bwidth >= SWB ) + { + st->attenu1 = 0.1f; + } + if( st->last_core == HQ_CORE || ( st->last_core == ACELP_CORE && !(st->last_extl == WB_TBE || st->last_extl == SWB_TBE || st->last_extl == FB_TBE ) && st->core_brate > ACELP_8k00) ) + { + st->prev_fractive = 0; + } + + return; +} diff --git a/src/libs/libevs/lib_dec/core_switching_dec_fx.cpp b/src/libs/libevs/lib_dec/core_switching_dec_fx.cpp deleted file mode 100755 index bdceb516..00000000 --- a/src/libs/libevs/lib_dec/core_switching_dec_fx.cpp +++ /dev/null @@ -1,1181 +0,0 @@ -/*==================================================================================== - EVS Codec 3GPP TS26.442 Apr 03, 2018. Version 12.11.0 / 13.6.0 / 14.2.0 - ====================================================================================*/ - -#include -#include "options.h" /* Compilation switches */ -#include "cnst_fx.h" /* Common constants */ -#include "rom_com_fx.h" /* Static table prototypes */ -#include "prot_fx.h" /* Function prototypes */ -#include "stl.h" /* required for wmc_tool */ -#include "basop_mpy.h" /*required for CodeB_Mpy_32_16()*/ -#include "basop_util.h" /* Function prototypes */ - - -/*---------------------------------------------------------------------* - * bandwidth_switching_detect_fx() - * - * - *---------------------------------------------------------------------*/ - -void bandwidth_switching_detect_fx( - Decoder_State_fx *st_fx /* i/o: encoder state structure */ -) -{ - /* update band-width switching counter */ - test(); - test(); - test(); - IF( sub(st_fx->bws_cnt1_fx, N_NS2W_FRAMES) >= 0 ) - { - st_fx->bws_cnt1_fx = 0; - move16(); - } - ELSE IF( L_sub(st_fx->total_brate_fx, ACELP_9k60) > 0 && L_sub(st_fx->last_core_brate_fx, ACELP_9k60) < 0 - && sub(st_fx->bwidth_fx, SWB) == 0 && sub(st_fx->last_bwidth_fx, WB) == 0 ) - { - st_fx->bws_cnt1_fx = add(st_fx->bws_cnt1_fx,1); - move16(); - } - ELSE IF( st_fx->bws_cnt1_fx > 0 ) - { - IF( sub(st_fx->bwidth_fx, st_fx->last_bwidth_fx) < 0 ) - { - st_fx->bws_cnt_fx = sub( shl(sub(N_NS2W_FRAMES, st_fx->bws_cnt1_fx), 1), 1 ); - move16(); - } - ELSE - { - st_fx->bws_cnt_fx = 0; - move16(); - } - - IF( sub(st_fx->bwidth_fx, st_fx->last_bwidth_fx) < 0 ) - { - st_fx->bws_cnt1_fx = 0; - move16(); - } - ELSE - { - IF(sub(st_fx->bwidth_fx, SWB) == 0) - { - st_fx->bws_cnt1_fx = add(st_fx->bws_cnt1_fx,1); - move16(); - } - ELSE - { - st_fx->bws_cnt1_fx = 0; - move16(); - } - } - } - - /* update band-width switching counter */ - test(); - test(); - test(); - IF( sub(st_fx->bws_cnt_fx, N_WS2N_FRAMES) >= 0 ) - { - st_fx->bws_cnt_fx = 0; - move16(); - } - ELSE IF( L_sub(st_fx->total_brate_fx, ACELP_9k60) < 0 && L_sub(st_fx->last_core_brate_fx, ACELP_9k60) > 0 - && sub(st_fx->bwidth_fx, st_fx->last_bwidth_fx) < 0 && sub(st_fx->bwidth_fx, WB) == 0 ) - { - st_fx->bws_cnt_fx = add(st_fx->bws_cnt_fx,1); - move16(); - } - ELSE IF( st_fx->bws_cnt_fx > 0 ) - { - IF( sub(st_fx->bwidth_fx, st_fx->last_bwidth_fx) > 0 ) - { - st_fx->bws_cnt1_fx = shr(sub(N_WS2N_FRAMES, st_fx->bws_cnt_fx), 1); - move16(); - } - ELSE - { - st_fx->bws_cnt1_fx = 0; - move16(); - } - - IF( sub(st_fx->bwidth_fx, st_fx->last_bwidth_fx) > 0 ) - { - st_fx->bws_cnt_fx = 0; - move16(); - } - ELSE - { - IF( sub(st_fx->bwidth_fx, WB) == 0 ) - { - st_fx->bws_cnt_fx = add(st_fx->bws_cnt_fx,1); - move16(); - } - ELSE - { - st_fx->bws_cnt_fx = 0; - move16(); - } - } - } - - return; -} - -/*---------------------------------------------------------------------* - * Calc_freq_ener() - * - * - *---------------------------------------------------------------------*/ - -static Word32 Calc_freq_ener(Word32 L_tmp, const Word16 Q_syn2) -{ - Word32 enerLL_fx; - Word16 exp, tmp; - IF(L_tmp == 0) - { - enerLL_fx = L_deposit_l(0); - } - ELSE - { - exp = norm_l(L_tmp); - tmp = extract_h(L_shl(L_tmp, exp)); - exp = sub(exp, sub(30,shl(Q_syn2,1))); - - tmp = div_s(16384, tmp); - L_tmp = L_deposit_h(tmp); - L_tmp = Isqrt_lc(L_tmp, &exp); /*31-exp*/ - - enerLL_fx = L_shr(L_tmp, sub(sub(31, exp), Q_syn2)); /*st_fx->Q_syn2-1*/ - } - return enerLL_fx; -} - -/*---------------------------------------------------------------------* - * bw_switching_pre_proc_fx() - * - * - *---------------------------------------------------------------------*/ - -void bw_switching_pre_proc_fx( - const Word16 *old_syn_12k8_16k_fx, /* i : ACELP core synthesis at 12.8kHz or 16kHz */ - Decoder_State_fx *st_fx /* i/o: decoder state structure */ -) -{ - Word16 i; - Word16 syn_dct_fx[L_FRAME]; - Word32 L_tmp; - IF( sub(st_fx->core_fx, ACELP_CORE) == 0 ) - { - /*----------------------------------------------------------------------* - * Calculate tilt of the ACELP core synthesis - *----------------------------------------------------------------------*/ - - st_fx->tilt_wb_fx = round_fx(L_shl(calc_tilt_bwe_fx(old_syn_12k8_16k_fx, -1, st_fx->L_frame_fx), 3)); - - /*-------------------------------------------------------------------------------* - * Calculate frequency energy of 0~3.2kHz and 3.2~6.4kHz the ACELP core synthesis - *-------------------------------------------------------------------------------*/ - - edct_16fx(old_syn_12k8_16k_fx, syn_dct_fx, L_FRAME, 6); - - L_tmp = L_deposit_l(0); - FOR ( i=0; i < L_FRAME/2; i++ ) - { - L_tmp = L_mac0(L_tmp, syn_dct_fx[i], syn_dct_fx[i]); - } - L_tmp = L_shr(L_tmp, 7); /*2*(st_fx->Q_syn2-1)*/ - st_fx->enerLL_fx = Calc_freq_ener(L_tmp, shl(st_fx->Q_syn2,1)); - L_tmp = L_deposit_l(0); - FOR (; iQ_syn2-1)*/ - st_fx->enerLH_fx = Calc_freq_ener(L_tmp, shl(st_fx->Q_syn2,1)); - } - ELSE - { - IF( st_fx->old_is_transient_fx[0] ) - { - L_tmp = L_deposit_l(0); - FOR ( i=0; i<32; i++ ) - { - L_tmp = L_mac0(L_tmp, st_fx->t_audio_q_fx[i], st_fx->t_audio_q_fx[i]); - } - L_tmp = L_shr(L_tmp, 5); /*st_fx->Q_syn2-1*/ - st_fx->enerLL_fx = Calc_freq_ener(L_tmp, shl(st_fx->Q_syn2,1)); - L_tmp = L_deposit_l(0); - FOR (; i<64; i++ ) - { - L_tmp = L_mac0(L_tmp, st_fx->t_audio_q_fx[i], st_fx->t_audio_q_fx[i]); - } - L_tmp = L_shr(L_tmp, 5); /*st_fx->Q_syn2-1*/ - st_fx->enerLH_fx = Calc_freq_ener(L_tmp, shl(st_fx->Q_syn2,1)); - } - ELSE - { - L_tmp = L_deposit_l(0); - FOR ( i=0; i < L_FRAME/2; i++ ) - { - L_tmp = L_mac0(L_tmp, st_fx->t_audio_q_fx[i], st_fx->t_audio_q_fx[i]); - } - L_tmp = L_shr(L_tmp, 7); /*st_fx->Q_syn2-1*/ - st_fx->enerLL_fx = Calc_freq_ener(L_tmp, shl(st_fx->Q_syn2,1)); - L_tmp = L_deposit_l(0); - FOR (; it_audio_q_fx[i], st_fx->t_audio_q_fx[i]); - } - L_tmp = L_shr(L_tmp, 7); /*st_fx->Q_syn2-1*/ - st_fx->enerLH_fx = Calc_freq_ener(L_tmp, shl(st_fx->Q_syn2,1)); - - } - } - - - test(); - test(); - test(); - test(); - test(); - IF( st_fx->last_bwidth_fx == 0 && sub(st_fx->extl_fx, SWB_CNG) <= 0 ) - { - st_fx->prev_ener_shb_fx = 0; - move16(); - set16_fx(st_fx->prev_SWB_fenv_fx, 0, SWB_FENV); - } - ELSE if(((sub(st_fx->core_fx, ACELP_CORE) == 0 && sub(st_fx->last_core_fx, HQ_CORE) == 0) || (sub(st_fx->core_fx, st_fx->last_core_fx) == 0 && sub(st_fx->extl_fx, st_fx->last_extl_fx) != 0)) && sub(st_fx->last_bwidth_fx, SWB) >= 0) - { - st_fx->attenu_fx = 3277; - move16(); - } - - test(); - test(); - test(); - test(); - IF(sub(st_fx->last_core_fx, HQ_CORE) == 0 - || ( sub(st_fx->last_core_fx, ACELP_CORE) == 0 - && !(sub(st_fx->last_extl_fx, WB_TBE) == 0 || sub(st_fx->last_extl_fx, SWB_TBE) == 0 || sub(st_fx->last_extl_fx, FB_TBE) == 0) && L_sub(st_fx->core_brate_fx, ACELP_8k00) > 0)) - { - st_fx->prev_fractive_fx = 0; - move16(); - } - return; -} - - -/*---------------------------------------------------------------------* -* core_switching_pre_dec_fx() -* -* Preprocessing/preparation for ACELP/HQ core switching -*---------------------------------------------------------------------*/ - -void core_switching_pre_dec_fx( - Decoder_State_fx *st_fx, /* i/o: decoder state structure */ - const Word16 output_frame /* i : frame length */ -) -{ - Word16 oldLenClasBuff, newLenClasBuff; - - /* Codec switching */ - IF( sub(st_fx->last_codec_mode,MODE2)==0 ) - { - st_fx->mem_deemph_fx = st_fx->syn[M]; - move16(); - set16_fx( st_fx->agc_mem_fx, 0, 2 ); - Scale_sig(&(st_fx->mem_deemph_fx), 1, st_fx->Q_syn); /* Brings mem_deemph to Qsyn */ - - Copy_Scale_sig(st_fx->mem_syn2_fx, st_fx->mem_syn1_fx, M, sub(-1,st_fx->Q_syn)); /*Q-1*/ - - st_fx->bpf_off_fx = 1; - move16(); - Scale_sig(st_fx->pfstat.mem_pf_in, L_SUBFR, st_fx->Q_syn); /* Post_filter mem */ - Scale_sig(st_fx->pfstat.mem_res2, DECMEM_RES2, st_fx->Q_syn); /* NB post_filter mem */ - Scale_sig(st_fx->pfstat.mem_stp, L_SUBFR, st_fx->Q_syn); /* Post_filter mem */ - set16_fx( st_fx->pst_old_syn_fx, 0, NBPSF_PIT_MAX ); /* BPF mem*/ - st_fx->pst_lp_ener_fx = round_fx(L_shl(Mpy_32_16_1(st_fx->lp_error_ener, 0x6054), 2+8)); /* convert from 15Q16, log2 -> 7Q8 10*log10 */ - st_fx->pst_mem_deemp_err_fx = 0; - move16(); - st_fx->psf_lp_noise_fx = round_fx(L_shl(st_fx->lp_noise,1)); - - /* reset old HB synthesis buffer */ - IF( sub(st_fx->last_L_frame_fx,L_FRAME) == 0 ) - { - st_fx->old_bwe_delay_fx = NS2SA_fx2( st_fx->output_Fs_fx, MAX_DELAY_TBE_NS - DELAY_SWB_TBE_12k8_NS ); - } - ELSE - { - st_fx->old_bwe_delay_fx = NS2SA_fx2( st_fx->output_Fs_fx, MAX_DELAY_TBE_NS - DELAY_SWB_TBE_16k_NS ); - } - set16_fx( st_fx->hb_prev_synth_buffer_fx, 0, NS2SA(48000, DELAY_BWE_TOTAL_NS) ); - st_fx->prev_hb_synth_fx_exp = 31; - move16(); - - /* reset upd_cnt */ - st_fx->upd_cnt_fx = MAX_UPD_CNT; - move16(); - st_fx->igf = 0; - move16(); - - IF( sub(st_fx->last_core_fx,ACELP_CORE) != 0 ) - { - /* reset BWE memories */ - set16_fx( st_fx->old_bwe_exc_fx, 0, PIT16k_MAX*2 ); - st_fx->bwe_non_lin_prev_scale_fx = L_deposit_l(0); - } - - IF( L_sub(st_fx->output_Fs_fx,16000) >= 0 ) - { - hf_synth_reset_fx( &st_fx->seed2_fx, st_fx->mem_hf_fx, st_fx->mem_syn_hf_fx, st_fx->mem_hp400_fx, st_fx->mem_hp_interp_fx, st_fx->delay_syn_hf_fx ); - } - set16_fx( st_fx->old_syn_12k8_16k_fx, 0, NS2SA(16000, DELAY_FD_BWE_ENC_NS) ); - - set32_fx( st_fx->prev_env_fx, 0, SFM_N_WB ); - set32_fx( st_fx->prev_normq_fx, 0, SFM_N_WB ); - - set32_fx( st_fx->last_ni_gain_fx, 0, BANDS_MAX ); - set16_fx( st_fx->last_env_fx, 0, BANDS_MAX ); - st_fx->last_max_pos_pulse_fx = 0; - move16(); - - IF( L_sub(st_fx->output_Fs_fx,16000)>0 ) - { - set32_fx( st_fx->prev_coeff_out_fx, 0, L_HQ_WB_BWE ); - } - - /* pre-echo */ - st_fx->pastpre_fx = 0; - move16(); - /* reset the GSC pre echo energy threshold in case of switching */ - st_fx->Last_frame_ener_fx = MAX_32; - move32(); - - test(); - IF( sub(st_fx->last_core_fx,TCX_20_CORE)==0 || sub(st_fx->last_core_fx,TCX_10_CORE)==0 ) - { - st_fx->last_core_fx = HQ_CORE; - move16(); - Copy( st_fx->FBTCXdelayBuf, st_fx->prev_synth_buffer_fx, NS2SA(st_fx->output_Fs_fx, DELAY_BWE_TOTAL_NS - DELAY_CLDFB_NS)); - set32_fx( st_fx->last_ni_gain_fx, 0, BANDS_MAX ); - set16_fx( st_fx->last_env_fx, 0, BANDS_MAX ); - st_fx->last_max_pos_pulse_fx = 0; - move16(); - - set16_fx( st_fx->prev_SWB_peak_pos_fx, 0, SPT_SHORTEN_SBNUM ); - st_fx->prev_frm_hfe2_fx = 0; - move16(); - st_fx->prev_stab_hfe2_fx = 0; - move16(); - } - - IF(st_fx->prev_bfi_fx!=0) - { - Word16 delay_comp; - - /*switch off Hq Voicing as it was not uodated in MODE2*/ - st_fx->oldHqVoicing_fx=0; - st_fx->HqVoicing_fx=0; - move16(); - - delay_comp = NS2SA_fx2(st_fx->output_Fs_fx, DELAY_CLDFB_NS); - - IF( !st_fx->last_con_tcx && st_fx->last_core_bfi == ACELP_CORE && sub(st_fx->core_fx,HQ_CORE)==0 ) - { - - Word16 i, no_col; - Word32 *realBuffer[CLDFB_NO_COL_MAX], *imagBuffer[CLDFB_NO_COL_MAX]; - Word32 realBufferTmp[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX], imagBufferTmp[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX]; - CLDFB_SCALE_FACTOR scaleFactor; - Word32 workBuffer[128*3]; - - FOR( i=0; icldfbAna_fx->no_col, idiv1616(sub(add(delay_comp, st_fx->cldfbAna_fx->no_channels),1) , st_fx->cldfbAna_fx->no_channels)); - - /* CLDFB analysis of the synthesis at internal sampling rate */ - cldfb_save_memory( st_fx->cldfbAna_fx ); - cldfbAnalysisFiltering( st_fx->cldfbAna_fx, realBuffer, imagBuffer, &scaleFactor, st_fx->syn_Overl, 0, no_col, workBuffer); - cldfb_restore_memory( st_fx->cldfbAna_fx ); - - scaleFactor.hb_scale = scaleFactor.lb_scale; - move16(); - - /* CLDFB synthesis of the combined signal */ - cldfb_save_memory( st_fx->cldfbSyn_fx ); - cldfbSynthesisFiltering(st_fx->cldfbSyn_fx, realBuffer, imagBuffer, &scaleFactor, st_fx->fer_samples_fx, 0, no_col, workBuffer); - cldfb_restore_memory( st_fx->cldfbSyn_fx ); - } - - IF( !st_fx->last_con_tcx && st_fx->last_core_bfi == ACELP_CORE && sub(st_fx->core_fx,HQ_CORE)==0 ) - { - lerp(st_fx->syn_Overl, st_fx->fer_samples_fx+delay_comp,shr(st_fx->output_frame_fx,1), shr(st_fx->last_L_frame_fx,1)); - /*Set to zero the remaining part*/ - set16_fx( st_fx->fer_samples_fx+delay_comp+shr(st_fx->output_frame_fx,1), 0, shr(st_fx->output_frame_fx,1)-delay_comp); - } - } - - st_fx->use_acelp_preq = 0; - move16(); - st_fx->reset_mem_AR=0; - move16(); - - } - - /*FEC*/ - IF( sub(st_fx->L_frame_fx,L_FRAME16k)<=0 ) - { - test(); - IF( sub(st_fx->last_L_frame_fx,L_FRAME16k)<=0 && sub(st_fx->core_fx, HQ_CORE)!=0 ) - { - IF( sub(st_fx->L_frame_fx,st_fx->last_L_frame_fx)!=0 ) - { - IF (sub(st_fx->L_frame_fx,st_fx->last_L_frame_fx)>0) - { - oldLenClasBuff = extract_l(L_shr(Mpy_32_16_1(L_mult0(st_fx->last_L_frame_fx,getInvFrameLen(st_fx->L_frame_fx)/*Q21*/)/*Q21*/,L_SYN_MEM_CLAS_ESTIM/*Q0*/)/*Q6*/,6)/*Q0*/); - newLenClasBuff = L_SYN_MEM_CLAS_ESTIM; - move16(); - } - ELSE - { - oldLenClasBuff = L_SYN_MEM_CLAS_ESTIM; - move16(); - newLenClasBuff = extract_l(L_shr(Mpy_32_16_1(L_mult0(st_fx->L_frame_fx,getInvFrameLen(st_fx->last_L_frame_fx)/*Q21*/)/*Q21*/,L_SYN_MEM_CLAS_ESTIM/*Q0*/)/*Q6*/,6)/*Q0*/); - } - lerp( &st_fx->mem_syn_clas_estim_fx[L_SYN_MEM_CLAS_ESTIM-oldLenClasBuff], &st_fx->mem_syn_clas_estim_fx[L_SYN_MEM_CLAS_ESTIM-newLenClasBuff], newLenClasBuff, oldLenClasBuff ); - } - } - ELSE - { - set16_fx( st_fx->mem_syn_clas_estim_fx, 0,L_SYN_MEM_CLAS_ESTIM ); - st_fx->classifier_Q_mem_syn = 0; - move16(); - } - } - - /* Here we only handle cases where last_ppp and last_nelp not updated when coming from CodecB or other cores - within ACELP_CORE if switching from another bitarate to vbr, last_ppp and last_nelp is always updated in the previous frame */ - test(); - test(); - IF( sub(st_fx->core_fx, ACELP_CORE) == 0 && ( sub(st_fx->last_core_fx, ACELP_CORE) != 0 || sub(st_fx->last_codec_mode,MODE2) == 0 )) - { - st_fx->last_ppp_mode_dec_fx = 0; - move16(); - st_fx->last_nelp_mode_dec_fx =0; - move16(); - } - - test(); - test(); - test(); - IF( sub(st_fx->core_fx, ACELP_CORE) == 0 && ( sub(st_fx->last_core_fx, ACELP_CORE) != 0 || sub(st_fx->last_codec_mode,MODE2) == 0 || L_sub(st_fx->last_total_brate_fx, PPP_NELP_2k80) <= 0 )) - { - st_fx->act_count_fx = 3; - move16(); - st_fx->uv_count_fx = 0; - move16(); - } - - test(); - test(); - IF( (sub(st_fx->core_fx,ACELP_CORE)==0 || sub(st_fx->core_fx, AMR_WB_CORE)==0 ) && sub( st_fx->last_core_fx,HQ_CORE)==0 ) - { - IF(sub(st_fx->L_frame_fx, L_FRAME16k)==0 ) - { - Copy( TRWB2_Ave_fx, st_fx->lsf_old_fx, M ); - Copy( TRWB2_Ave_fx, st_fx->lsfoldbfi1_fx, M ); - Copy( TRWB2_Ave_fx, st_fx->lsfoldbfi0_fx, M ); - Copy( TRWB2_Ave_fx, st_fx->lsf_adaptive_mean_fx, M ); - lsf2lsp_fx( st_fx->lsf_old_fx, st_fx->lsp_old_fx, M, INT_FS_16k ); - } - ELSE - { - Copy( TRWB_Ave_fx, st_fx->lsf_old_fx, M ); /* init of LSP */ - Copy( TRWB_Ave_fx, st_fx->lsfoldbfi1_fx, M ); - Copy( TRWB_Ave_fx, st_fx->lsfoldbfi0_fx, M ); - Copy( TRWB_Ave_fx, st_fx->lsf_adaptive_mean_fx, M ); - lsf2lsp_fx( st_fx->lsf_old_fx, st_fx->lsp_old_fx, M, INT_FS_FX ); - } - - set16_fx( st_fx->agc_mem_fx, 0, 2 ); - st_fx->mem_deemph_fx = 0; - move16(); - IF( !st_fx->last_con_tcx ) - { - set16_fx( st_fx->mem_syn2_fx, 0, M ); - } - set16_fx( st_fx->mem_syn1_fx, 0, M ); - st_fx->bwe_non_lin_prev_scale_fx = 0; - move16(); - - /* Reset ACELP parameters */ - set16_fx( st_fx->mem_MA_fx,0, M ); - IF( L_sub(st_fx->sr_core,16000) == 0 ) - { - Copy( GEWB2_Ave_fx, st_fx->mem_AR_fx, M ); - } - ELSE - { - Copy( GEWB_Ave_fx, st_fx->mem_AR_fx, M ); - } - st_fx->tilt_code_fx = 0; - move16(); - st_fx->gc_threshold_fx = 0; - move16(); - st_fx->dm_fx.prev_gain_code = L_deposit_l(0); - set16_fx(st_fx->dm_fx.prev_gain_pit, 0, 6); - st_fx->dm_fx.prev_state = 0; - move16(); - - st_fx->last_coder_type_fx = GENERIC; - move16(); - - frame_ener_fx( output_frame, UNVOICED_CLAS, st_fx->previoussynth_fx, -1, &st_fx->enr_old_fx, 1, 0, 0, 0 ); - st_fx->lp_gainp_fx = 0; - move16(); - - /* the sqrt below needs to be changed to use basop Sqrt16 */ - /*st_fx->lp_gainc_fx = (float)sqrt( st_fx->lp_ener_fx ); */ - IF( st_fx->lp_ener_fx != 0 ) - { - Word32 L_tmp; - Word16 tmp, exp; - exp = norm_l(st_fx->lp_ener_fx); /* In Q6 */ - tmp = extract_h(L_shl(st_fx->lp_ener_fx, exp)); - exp = sub(exp, 30-6); - - tmp = div_s(16384, tmp); - L_tmp = L_deposit_h(tmp); - L_tmp = Isqrt_lc(L_tmp, &exp); - - st_fx->lp_gainc_fx = round_fx(L_shl(L_tmp, sub(exp, 12))); /* In Q3 */ - } - - - st_fx->last_voice_factor_fx = 0; - move16(); - st_fx->Last_GSC_noisy_speech_flag_fx = 0; - move16(); - - /* reset CLDFB memories */ - cldfb_reset_memory( st_fx->cldfbAna_fx ); - cldfb_reset_memory( st_fx->cldfbBPF_fx ); - cldfb_reset_memory( st_fx->cldfbSyn_fx ); - - /* reset TBE memories */ - test(); - IF (!st_fx->last_con_tcx) - { - set16_fx(st_fx->old_exc_fx,0, L_EXC_MEM_DEC ); - } - ELSE IF (sub(st_fx->L_frame_fx,L_FRAME16k) < 0) - { - /* resample from 16kHz to 12.8kHZ */ - synth_mem_updt2( st_fx->L_frame_fx, L_FRAME16k, st_fx->old_exc_fx, st_fx->mem_syn_r, st_fx->mem_syn2_fx, NULL, DEC ); - } - - set16_fx( st_fx->old_bwe_exc_fx, 0, PIT16k_MAX*2 ); - - IF( L_sub(st_fx->output_Fs_fx, 16000L)>=0 ) - { - hf_synth_reset_fx( &st_fx->seed2_fx, st_fx->mem_hf_fx, st_fx->mem_syn_hf_fx, st_fx->mem_hp400_fx, st_fx->mem_hp_interp_fx, st_fx->delay_syn_hf_fx ); - } - set16_fx( st_fx->old_syn_12k8_16k_fx, 0, NS2SA(16000, DELAY_FD_BWE_ENC_NS) ); - } - - test(); - test(); - IF( sub(st_fx->core_fx,HQ_CORE)==0 && (sub(st_fx->last_core_fx,ACELP_CORE)==0 || st_fx->last_core_fx == AMR_WB_CORE) ) - { - set32_fx( st_fx->prev_env_fx, 0, SFM_N_WB ); - set32_fx( st_fx->prev_normq_fx, 0, SFM_N_WB ); - - set32_fx( st_fx->last_ni_gain_fx, 0, BANDS_MAX ); - set16_fx( st_fx->last_env_fx, 0, BANDS_MAX ); - st_fx->last_max_pos_pulse_fx = 0; - - set16_fx( st_fx->prev_SWB_peak_pos_fx, 0, SPT_SHORTEN_SBNUM ); - st_fx->prev_frm_hfe2_fx = 0; - st_fx->prev_stab_hfe2_fx = 0; - - IF( L_sub(st_fx->output_Fs_fx,16000) > 0 ) - { - set32_fx( st_fx->prev_coeff_out_fx, 0, L_HQ_WB_BWE ); - } - - set16_fx( st_fx->old_out_fx, 0, output_frame ); - st_fx->Q_old_wtda_LB = 15; - st_fx->Q_old_wtda = 15; - } - - /* handle switching cases where preecho_sb was not called in the last frame (memory not up to date) */ - st_fx->pastpre_fx--; - IF( st_fx->pastpre_fx <= 0 ) - { - reset_preecho_dec_fx( st_fx ); - } - - IF( L_sub(st_fx->core_brate_fx,FRAME_NO_DATA) == 0 ) - { - st_fx->VAD = 0; - move16(); - st_fx->m_frame_type = ZERO_FRAME; - move16(); - } - ELSE IF( L_sub(st_fx->core_brate_fx,SID_2k40) <= 0 ) - { - st_fx->VAD = 0; - move16(); - st_fx->m_frame_type = SID_FRAME; - move16(); - } - ELSE - { - st_fx->VAD = 1; - move16(); - st_fx->m_frame_type = ACTIVE_FRAME; - move16(); - } - - /*switch on CNA on active frames*/ - test(); - test(); - test(); - test(); - IF( sub(st_fx->core_fx,AMR_WB_CORE) != 0 && st_fx->VAD && L_sub(st_fx->total_brate_fx,CNA_MAX_BRATE) <= 0 ) - { - st_fx->flag_cna = 1; - move16(); - } - ELSE IF( sub(st_fx->core_fx,AMR_WB_CORE) == 0 && st_fx->VAD && L_sub(st_fx->total_brate_fx,ACELP_8k85) <= 0 ) - { - st_fx->flag_cna = 1; - move16(); - } - ELSE IF( st_fx->VAD || ( sub(st_fx->cng_type_fx,FD_CNG) == 0 && sub(st_fx->L_frame_fx,L_FRAME16k) == 0 ) ) - { - st_fx->flag_cna = 0; - move16(); - } - - if( sub(st_fx->core_fx,AMR_WB_CORE) == 0 ) - { - st_fx->cng_type_fx = LP_CNG; - move16(); - } - - test(); - test(); - test(); - test(); - IF( st_fx->hFdCngDec_fx && ((sub(st_fx->last_L_frame_fx,st_fx->L_frame_fx) != 0) || - (sub(st_fx->hFdCngDec_fx->hFdCngCom->frameSize,st_fx->L_frame_fx)!=0) || - st_fx->ini_frame_fx == 0 || sub(st_fx->bwidth_fx, st_fx->last_bwidth_fx) != 0)) - { - - IF( sub(st_fx->core_fx,AMR_WB_CORE) != 0 ) - { - Word32 tmp; - - tmp = st_fx->total_brate_fx; - move32(); - test(); - if( sub(st_fx->rf_flag,1) == 0 && L_sub(st_fx->total_brate_fx,ACELP_13k20) == 0 ) - { - tmp = ACELP_9k60; - move32(); - } - configureFdCngDec(st_fx->hFdCngDec_fx, st_fx->bwidth_fx, tmp, st_fx->L_frame_fx ); - } - ELSE - { - configureFdCngDec(st_fx->hFdCngDec_fx, 1, ACELP_8k00, st_fx->L_frame_fx ); - - if( st_fx->VAD ) - { - st_fx->hFdCngDec_fx->hFdCngCom->CngBitrate = st_fx->total_brate_fx; - move32(); - } - } - - test(); - test(); - IF ( sub(st_fx->last_L_frame_fx,st_fx->L_frame_fx) != 0 && sub(st_fx->L_frame_fx,L_FRAME16k) <= 0 && sub(st_fx->last_L_frame_fx,L_FRAME16k) <= 0 ) - { - lerp( st_fx->hFdCngDec_fx->hFdCngCom->olapBufferSynth2, st_fx->hFdCngDec_fx->hFdCngCom->olapBufferSynth2, st_fx->L_frame_fx*2, st_fx->last_L_frame_fx*2 ); - test(); - IF( L_sub(st_fx->total_brate_fx,SID_2k40) <= 0 && L_sub(st_fx->last_total_brate_fx,SID_2k40) <= 0 ) - { - lerp( st_fx->hFdCngDec_fx->hFdCngCom->olapBufferSynth, st_fx->hFdCngDec_fx->hFdCngCom->olapBufferSynth, st_fx->L_frame_fx*2, st_fx->last_L_frame_fx*2 ); - IF( sub(st_fx->L_frame_fx, L_FRAME) == 0 ) - { - Word16 n; - FOR( n=0; n < st_fx->L_frame_fx*2; n++ ) - { - st_fx->hFdCngDec_fx->hFdCngCom->olapBufferSynth[n] = mult_r( st_fx->hFdCngDec_fx->hFdCngCom->olapBufferSynth[n], 20480 ); - } - } - ELSE - { - Word16 n; - FOR( n=0; n < st_fx->L_frame_fx*2; n++ ) - { - st_fx->hFdCngDec_fx->hFdCngCom->olapBufferSynth[n] = mult_r( shl(st_fx->hFdCngDec_fx->hFdCngCom->olapBufferSynth[n],1), 26214 ); - } - } - } - } - } - - return; -} - -/*---------------------------------------------------------------------* - * core_switching_post_dec() - * - * Postprocessing for ACELP/HQ core switching - *---------------------------------------------------------------------*/ - -void core_switching_post_dec_fx( - Decoder_State_fx *st_fx, /* i/o: decoder state structure */ - Word16 *synth, /* i/o: output synthesis Qsynth */ - const Word16 output_frame, /* i : frame length */ - const Word16 core_switching_flag, /* i : ACELP->HQ switching flag */ - const Word16 coder_type, /* i : ACELP coder type */ - Word16 *Qsynth /* i/o: Scaling of ACELP exit (Q_syn2-1) or HQ exit (Qsynth); changes after this function */ -) -{ - Word16 i, delay_comp, delta; - Word16 tmpF, tmp, Fs_kHz, shift, *ptmp1, *ptmp2; - Word32 L_tmp; - Word16 synth_subfr_out[SWITCH_MAX_GAP], synth_subfr_bwe[SWITCH_MAX_GAP]; - Word16 mem_synth[NS2SA(16000, DELAY_CLDFB_NS)+2]; - Word16 Qtmp; - Word16 Qsubfr; - - /* Rescale synthesis in Q0 to avoid multiple rescaling after */ - tmp = Find_Max_Norm16(synth,output_frame); - Scale_sig(synth,output_frame,tmp); - *Qsynth=add(*Qsynth,tmp); - - test(); - IF( sub(st_fx->core_fx, ACELP_CORE) == 0 && st_fx->bfi_fx ) - { - acelp_core_switch_dec_bfi_fx( st_fx, st_fx->fer_samples_fx, coder_type ); /*the output at Q0*/ - } - - /* set multiplication factor according to the sampling rate */ - tmp = extract_l(L_shr(st_fx->output_Fs_fx,13)); - Fs_kHz = shl(add(tmp,1),3); - - delta = 1; - move16(); - if ( sub(output_frame, L_FRAME16k) >= 0) - { - delta = shr(Fs_kHz, 3); - } - - /* set delay compensation between HQ synthesis and ACELP synthesis */ - delay_comp = i_mult2(delta, HQ_DELAY_COMP); - - IF( sub(st_fx->core_fx, HQ_CORE) == 0 ) - { - st_fx->use_acelp_preq = 0; - move16(); - /* rescaling to the min exp of the 2 */ - /* Qtmp=s_min(*Qsynth,st_fx->Q_old_postdec); - Scale_sig(synth, output_frame, sub(Qtmp,*Qsynth)); - Scale_sig(st_fx->delay_buf_out_fx, delay_comp, sub(Qtmp,st_fx->Q_old_postdec));*/ - - st_fx->mem_deemph_old_syn_fx = 0; - move16(); - - test(); - test(); - test(); - IF ( core_switching_flag && sub(st_fx->last_L_frame_fx, st_fx->last_L_frame_ori_fx) == 0 && ( sub(st_fx->last_core_fx, ACELP_CORE) == 0 || sub(st_fx->last_core_fx, AMR_WB_CORE) == 0 )) - { - acelp_core_switch_dec_fx( st_fx, synth_subfr_out, synth_subfr_bwe, output_frame, core_switching_flag, mem_synth, &Qsubfr ); - } - test(); - test(); - IF( core_switching_flag && sub(st_fx->last_core_fx, HQ_CORE) == 0 && st_fx->prev_bfi_fx ) - { - Copy( st_fx->delay_buf_out_fx, synth_subfr_out, delay_comp ); - Qsubfr=st_fx->Q_old_postdec; - } - - /* delay HQ synthesis to synchronize with ACELP synthesis */ - /* rescaling to the min exp of the 2 */ - Qtmp=s_min(*Qsynth,st_fx->Q_old_postdec); - Scale_sig(synth, output_frame, sub(Qtmp,*Qsynth)); - *Qsynth=Qtmp; - move16(); - Scale_sig(st_fx->delay_buf_out_fx, delay_comp, sub(Qtmp,st_fx->Q_old_postdec)); - st_fx->Q_old_postdec=Qtmp; - move16(); - - Copy( synth, &synth[delay_comp], output_frame); - Copy( st_fx->delay_buf_out_fx, synth, delay_comp ); - Copy( &synth[output_frame], st_fx->delay_buf_out_fx, delay_comp ); - - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - IF ( core_switching_flag && sub(st_fx->last_L_frame_fx, st_fx->last_L_frame_ori_fx) == 0 && ( sub(st_fx->last_core_fx, ACELP_CORE) == 0 || sub(st_fx->last_core_fx, AMR_WB_CORE) == 0 )) - { - /* mem_over_hp_fx : Qsubfr */ - core_switching_OLA_fx( mem_synth, st_fx->last_L_frame_fx, st_fx->output_Fs_fx, synth, synth_subfr_out, synth_subfr_bwe, output_frame, st_fx->bwidth_fx, Qsynth, &Qsubfr ); - } - ELSE IF ( core_switching_flag && sub(st_fx->last_core_fx, HQ_CORE) == 0 && st_fx->prev_bfi_fx ) /* HQ | ACELP | TRANSITION with ACELP frame lost */ - { - /* Overlapp between old->out (stocked in st_fx->fer_samples)and good HQ frame on L/2 */ - ptmp1 = &synth[delay_comp]; - shift = i_mult2(Fs_kHz, 10); - tmp = i_mult2(delta,shr(N16_CORE_SW,1)); - - Scale_sig(st_fx->fer_samples_fx, output_frame, *Qsynth); - ptmp2 = &st_fx->fer_samples_fx[tmp]; - tmp = div_s(1, shift); /*Q15*/ - tmpF = 0; - move16(); - - FOR( i=0; icore_fx, HQ_CORE) == 0 && (sub(st_fx->last_core_fx, ACELP_CORE) == 0 || sub(st_fx->last_core_fx,AMR_WB_CORE) == 0) ) /* ACELP | TRANSITION | HQ with TRANSITION lost */ - || (core_switching_flag && st_fx->prev_bfi_fx && sub(st_fx->last_L_frame_fx, st_fx->last_L_frame_ori_fx) != 0) ) - { - /* Overlapp between CELP estimation (BFI) and good HQ frame on L/2 */ - shift = i_mult2(Fs_kHz, 10); - tmp = div_s(1, shift); /*Q15*/ - tmpF = 0; - move16(); - ptmp1 = synth; - Scale_sig(st_fx->fer_samples_fx, output_frame, *Qsynth); - ptmp2 = st_fx->fer_samples_fx; - FOR( i=0; ibwe_non_lin_prev_scale_fx = L_deposit_l(0); - IF ( !(sub(inner_frame_tbl[st_fx->bwidth_fx], L_FRAME16k) == 0 && L_sub(st_fx->core_brate_fx, HQ_32k) == 0 ) ) - { - set32_fx( st_fx->prev_env_fx, 0, SFM_N_WB ); - set32_fx( st_fx->prev_normq_fx, 0, SFM_N_WB ); - } - Copy_Scale_sig( synth, st_fx->previoussynth_fx, output_frame, negate(*Qsynth) ); /*scaling of st_fx->previoussynth_fx set at Q0*/ - - /*Set post-filtering flag to zero*/ - st_fx->pfstat.on = 0; - move16(); - } - ELSE - { - IF ( sub(st_fx->last_core_fx, HQ_CORE) == 0 ) /* MDCT to ACELP transition */ - { - Qtmp = s_min(s_min(*Qsynth, st_fx->Q_old_postdec), st_fx->Q_old_wtda); - - Scale_sig(synth, output_frame, sub(Qtmp,*Qsynth)); - Scale_sig(st_fx->delay_buf_out_fx, delay_comp, sub(Qtmp,st_fx->Q_old_postdec)); - Scale_sig(st_fx->old_out_fx, L_FRAME48k, sub(Qtmp, st_fx->Q_old_wtda)); - *Qsynth = Qtmp; - move16(); - st_fx->Q_old_postdec=Qtmp; - move16(); - st_fx->Q_old_wtda=Qtmp; - move16(); - - Copy( st_fx->delay_buf_out_fx, synth, delay_comp ); /* copy the HQ/ACELP delay synchroniation buffer at the beginning of ACELP frame */ - - tmp = i_mult2(delta, N_ZERO_8); - shift = i_mult2(Fs_kHz, 3); - test(); - IF( st_fx->prev_bfi_fx && st_fx->HqVoicing_fx ) - { - Copy_Scale_sig( st_fx->fer_samples_fx, &st_fx->old_out_fx[tmp], shift, *Qsynth ); - } - - ptmp2 = &st_fx->old_out_fx[tmp]; - tmp = div_s(1, shift); - ptmp1 = &synth[delay_comp]; - tmpF = 0; - move16(); - FOR( i=0; idelay_buf_out_fx, 0, HQ_DELTA_MAX*HQ_DELAY_COMP ); - st_fx->oldHqVoicing_fx = 0; - move16(); - - set16_fx(st_fx->prev_SWB_peak_pos_fx, 0, SPT_SHORTEN_SBNUM); - st_fx->prev_frm_hfe2_fx = 0; - move16(); - st_fx->prev_stab_hfe2_fx = 0; - move16(); - } - - /* reset SWB BWE buffers */ - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - IF(st_fx->bws_cnt_fx == 0 || (st_fx->bws_cnt_fx > 0 && sub(coder_type, INACTIVE) != 0 && sub(coder_type,AUDIO) != 0)) - { - st_fx->attenu_fx = 3277; - move16(); - } - - IF( ( sub(st_fx->last_extl_fx, SWB_BWE) != 0 && sub(st_fx->extl_fx, SWB_BWE) == 0 ) || ( sub(st_fx->last_extl_fx, FB_BWE) != 0 && sub(st_fx->extl_fx, FB_BWE) == 0 ) || - ((sub(st_fx->last_core_fx, HQ_CORE) == 0 || sub(st_fx->last_extl_fx, SWB_TBE) == 0) && st_fx->extl_fx < 0 && sub(st_fx->core_fx, HQ_CORE) != 0) - || (sub(st_fx->last_core_fx,ACELP_CORE) == 0 && sub(st_fx->core_fx,ACELP_CORE) == 0 - && ((sub(st_fx->prev_coder_type_fx,INACTIVE) != 0 && sub(coder_type,INACTIVE) == 0) || (sub(st_fx->prev_coder_type_fx,AUDIO) != 0 && sub(coder_type,AUDIO) == 0)) - && st_fx->bws_cnt_fx > 0) - ) - { - set16_fx( st_fx->L_old_wtda_swb_fx, 0, output_frame ); - st_fx->old_wtda_swb_fx_exp = 0; - move16(); - if( sub(st_fx->last_extl_fx, WB_BWE) != 0 ) - { - st_fx->prev_mode_fx = NORMAL; - move16(); - } - - st_fx->prev_Energy_fx = 0; - move16(); - st_fx->prev_L_swb_norm_fx = 8; - move16(); - st_fx->prev_frica_flag_fx = 0; - move16(); - set16_fx( st_fx->mem_imdct_fx, 0, L_FRAME48k ); - st_fx->prev_td_energy_fx = 0; - move16(); - st_fx->prev_weight_fx = 6554; - move16(); /*0.2 in Q15*/ - st_fx->prev_fb_ener_adjust_fx = 0; - move16(); - } - - /* reset WB BWE buffers */ - test(); - IF( sub(st_fx->last_extl_fx, WB_BWE) != 0 && sub(st_fx->extl_fx, WB_BWE) == 0 ) - { - set16_fx(st_fx->L_old_wtda_swb_fx, 0, output_frame); - - test(); - if ( sub(st_fx->last_extl_fx, SWB_BWE) != 0 && sub(st_fx->last_extl_fx, FB_BWE) != 0 ) - { - st_fx->prev_mode_fx = NORMAL; - move16(); - } - st_fx->prev_Energy_wb_fx = 0; - move16(); - st_fx->prev_L_swb_norm_fx = 8; - move16(); - set16_fx( st_fx->mem_imdct_fx, 0, L_FRAME48k ); - st_fx->prev_flag_fx = 0; - move16(); - } - - /* reset SWB TBE buffers */ - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - IF( (( sub(st_fx->extl_fx, SWB_TBE) == 0 || sub(st_fx->extl_fx, FB_TBE) == 0 || sub(st_fx->extl_fx, SWB_CNG) == 0) && - ( sub(st_fx->L_frame_fx, st_fx->last_L_frame_fx) != 0 || ( sub(st_fx->last_extl_fx, SWB_TBE) != 0 && sub(st_fx->last_extl_fx, FB_TBE) != 0 ) || sub(st_fx->last_core_fx, HQ_CORE) == 0 )) || - ( sub(st_fx->bwidth_fx, st_fx->last_bwidth_fx) < 0 && sub(st_fx->last_extl_fx, SWB_TBE) != 0 ) || st_fx->old_ppp_mode_fx - || ((sub(st_fx->prev_coder_type_fx, AUDIO) == 0 || sub(st_fx->prev_coder_type_fx, INACTIVE) == 0) && st_fx->bws_cnt_fx > 0) - || (st_fx->bws_cnt_fx == 0 && sub(st_fx->prev_bws_cnt_fx, N_WS2N_FRAMES) == 0) ) - { - swb_tbe_reset_fx( st_fx->mem_csfilt_fx, st_fx->mem_genSHBexc_filt_down_shb_fx, st_fx->state_lpc_syn_fx, - st_fx->syn_overlap_fx, st_fx->state_syn_shbexc_fx, &(st_fx->tbe_demph_fx), &(st_fx->tbe_premph_fx) - ,st_fx->mem_stp_swb_fx, &(st_fx->gain_prec_swb_fx) ); - - set16_fx( st_fx->GainShape_Delay, 0, NUM_SHB_SUBFR/2 ); - swb_tbe_reset_synth_fx( st_fx->genSHBsynth_Hilbert_Mem_fx, st_fx->genSHBsynth_state_lsyn_filt_shb_local_fx ); - - IF( sub(output_frame, L_FRAME16k) == 0 ) - { - /* reset in case that SWB TBE layer is transmitted, but the output is 16kHz sampled */ - set16_fx( st_fx->mem_resamp_HB_32k_fx, 0, 2*ALLPASSSECTIONS_STEEP+1 ); - } - set16_fx(st_fx->int_3_over_2_tbemem_dec_fx, 0, INTERP_3_2_MEM_LEN); - } - ELSE IF( ( sub(st_fx->extl_fx, SWB_TBE) == 0 || sub(st_fx->extl_fx, FB_TBE) == 0 ) && - ( L_sub(st_fx->last_total_brate_fx, st_fx->total_brate_fx) != 0 || sub(st_fx->last_bwidth_fx, st_fx->bwidth_fx) != 0 || - sub(st_fx->last_codec_mode, MODE1) != 0 || sub(st_fx->rf_flag, st_fx->rf_flag_last) != 0 ) ) - { - set16_fx( st_fx->state_lpc_syn_fx, 0, LPC_SHB_ORDER ); - set16_fx( st_fx->state_syn_shbexc_fx, 0, L_SHB_LAHEAD ); - set16_fx( st_fx->mem_stp_swb_fx, 0, LPC_SHB_ORDER ); - set16_fx( st_fx->mem_zero_swb_fx, 0, LPC_SHB_ORDER ); - st_fx->gain_prec_swb_fx = 16384; - move16(); /*Q14 = 1 */ - } - - /* Interp_3_2 CNG buffers reset */ - test(); - test(); - test(); - IF(L_sub(st_fx->output_Fs_fx,48000)==0 && ( (L_sub(st_fx->last_core_brate_fx,SID_2k40)>0 ) && (L_sub(st_fx->core_brate_fx,FRAME_NO_DATA)==0 || L_sub(st_fx->core_brate_fx,SID_2k40)==0)) ) - { - set16_fx( st_fx->interpol_3_2_cng_dec_fx, 0, INTERP_3_2_MEM_LEN ); - } - - /* reset FB TBE buffers */ - test(); - test(); - IF( sub(st_fx->extl_fx, FB_TBE) == 0 && ( sub(st_fx->last_extl_fx, FB_TBE) != 0 || sub(st_fx->L_frame_fx, st_fx->last_L_frame_fx) != 0 ) ) - { - set16_fx( st_fx->fb_state_lpc_syn_fx, 0, LPC_SHB_ORDER ); - st_fx->fb_tbe_demph_fx = 0; - fb_tbe_reset_synth_fx( st_fx->fbbwe_hpf_mem_fx, st_fx->fbbwe_hpf_mem_fx_Q,&st_fx->prev_fbbwe_ratio_fx ); - } - - /* reset WB TBE buffers */ - test(); - IF( sub(st_fx->last_extl_fx, WB_TBE) != 0 && sub(st_fx->extl_fx, WB_TBE) == 0 ) - { - wb_tbe_extras_reset_fx( st_fx->mem_genSHBexc_filt_down_wb2_fx, st_fx->mem_genSHBexc_filt_down_wb3_fx ); - wb_tbe_extras_reset_synth_fx( st_fx->state_lsyn_filt_shb_fx, st_fx->state_lsyn_filt_dwn_shb_fx, st_fx->state_32and48k_WB_upsample_fx, st_fx->mem_resamp_HB_fx ); - - set16_fx( st_fx->state_syn_shbexc_fx, 0, L_SHB_LAHEAD / 4 ); - set16_fx( st_fx->syn_overlap_fx, 0, L_SHB_LAHEAD ); - set32_fx( st_fx->mem_csfilt_fx, 0, 2 ); - } - - return; -} - -/*---------------------------------------------------------------------* -* core_switching_hq_prepare_dec() -* -* Preprocessing in the first HQ frame after ACELP frame -* - modify bit allocation for HQ core by removing CELP subframe budget -*---------------------------------------------------------------------*/ - -void core_switching_hq_prepare_dec_fx( - Decoder_State_fx *st_fx, /* i/o: encoder state structure */ - Word16 *num_bits, /* i/o: bit budget update */ - const Word16 output_frame /* i : output frame length */ -) -{ - Word32 cbrate; - - test(); - IF( sub(st_fx->last_core_fx, HQ_CORE) == 0 && st_fx->prev_bfi_fx ) - { - Copy_Scale_sig( st_fx->old_out_fx, st_fx->fer_samples_fx, output_frame, negate(st_fx->Q_old_wtda) ); /*Q0*/ - } - - /* set switching frame bit-rate */ - IF( sub(st_fx->last_L_frame_fx, L_FRAME) == 0 ) - { - cbrate = L_add(st_fx->core_brate_fx, 0); - if( L_sub(st_fx->core_brate_fx, ACELP_24k40) > 0 ) - { - cbrate = L_add(ACELP_24k40, 0); - } - - /* subtract ACELP switching frame bits */ - if( L_sub(st_fx->core_brate_fx, ACELP_11k60) >= 0 ) - { - (*num_bits) = sub((*num_bits), 1); /* LP_FLAG bit */ - } - *num_bits = sub( (*num_bits), ACB_bits_tbl[BIT_ALLOC_IDX_fx(cbrate, GENERIC, 0, 0)] ); /* pitch bits*/ - *num_bits = sub( (*num_bits), gain_bits_tbl[BIT_ALLOC_IDX_fx(cbrate, TRANSITION, 0, 0)] ); /* gain bits */ - *num_bits = sub( (*num_bits), FCB_bits_tbl[BIT_ALLOC_IDX_fx(cbrate, GENERIC, 0, 0)] ); /* FCB bits */ - } - ELSE /* L_frame_fx == L_FRAME16k */ - { - IF( L_sub(st_fx->core_brate_fx, ACELP_8k00) <= 0 ) - { - cbrate = L_add(ACELP_8k00, 0); - } - ELSE IF( L_sub(st_fx->core_brate_fx, ACELP_14k80) <= 0 ) - { - cbrate = L_add(ACELP_14k80, 0); - } - ELSE - { - cbrate = L_min(st_fx->core_brate_fx, ACELP_22k60); - } - - /* subtract ACELP switching frame bits */ - if( L_sub(st_fx->core_brate_fx, ACELP_11k60) >= 0 ) - { - (*num_bits) = sub((*num_bits), 1); /* LP_FLAG bit */ - } - *num_bits = sub((*num_bits), ACB_bits_16kHz_tbl[BIT_ALLOC_IDX_16KHZ_fx(cbrate, GENERIC, 0, 0)]); /* pitch bits*/ - *num_bits = sub((*num_bits), gain_bits_16kHz_tbl[BIT_ALLOC_IDX_16KHZ_fx(cbrate, GENERIC, 0, 0)]); /* gain bits */ - *num_bits = sub((*num_bits), FCB_bits_16kHz_tbl[BIT_ALLOC_IDX_16KHZ_fx(cbrate, GENERIC, 0, 0)]); /* FCB bits */ - } - - /* subtract BWE bits */ - test(); - test(); - IF( !( ( sub(inner_frame_tbl_fx[st_fx->bwidth_fx], L_FRAME16k) == 0 && sub(st_fx->last_L_frame_fx, L_FRAME16k) == 0 ) || sub(inner_frame_tbl_fx[st_fx->bwidth_fx], L_FRAME8k) == 0 ) ) - { - *num_bits = sub((*num_bits), (NOOFGAINBITS1 + AUDIODELAYBITS)); - } - - /* reset state of old_out if switching */ - set16_fx( st_fx->old_out_fx, 0, output_frame ); - - return; - -} diff --git a/src/libs/libevs/lib_dec/d_gain2p.cpp b/src/libs/libevs/lib_dec/d_gain2p.cpp old mode 100755 new mode 100644 index 80c9df3b..ec9e016a --- a/src/libs/libevs/lib_dec/d_gain2p.cpp +++ b/src/libs/libevs/lib_dec/d_gain2p.cpp @@ -1,53 +1,17 @@ /*==================================================================================== - EVS Codec 3GPP TS26.442 Apr 03, 2018. Version 12.11.0 / 13.6.0 / 14.2.0 + EVS Codec 3GPP TS26.443 Nov 13, 2018. Version 12.11.0 / 13.7.0 / 14.3.0 / 15.1.0 ====================================================================================*/ -/*-------------------------------------------------------------------* - * Decoding of pitch and codebook gains (see q_gain2_plus.c) * - *-------------------------------------------------------------------*/ +#include #include #include -#include "prot_fx.h" -#include "basop_util.h" -#include "stl.h" -#include "rom_com_fx.h" +#include "options.h" +#include "typedef.h" +#include "prot.h" +#include "cnst.h" +#include "rom_com.h" -/********************* - * private functions * - *********************/ -static Word32 calc_gcode0( - Word16 *gcode0, - Word16 *exp_gcode0 -) -{ - Word32 L_tmp; - - /*gcode0 = (float)pow(10.0,(gcode0)*0.05);*/ /* predicted gain */ - - L_tmp = L_mult(*gcode0, 5443/*0.166096f Q15*/); - *exp_gcode0 = add(1,extract_l(L_shr(L_tmp, 24))); - L_tmp = L_lshl(L_tmp, 7); - L_tmp = L_and(0x7FFFFFFF, L_tmp); - - L_tmp = Pow2(30,round_fx(L_tmp)); - *gcode0 = round_fx(L_tmp); - - return L_tmp; -} - -static Word32 calc_gain_code(Word16 g_code, Word16 gcode0, Word16 exp_gcode0) -{ - Word32 L_tmp; - - L_tmp = L_mult(g_code, gcode0); /* Q11*Q15 -> Q27 */ - exp_gcode0 = add(exp_gcode0,-11); - L_tmp = L_shl(L_tmp, exp_gcode0); /* Q27 -> Q16 */ - - - return L_tmp; -} - /*--------------------------------------------------------------------------* * Mode2_gain_dec_mless * @@ -55,89 +19,91 @@ static Word32 calc_gain_code(Word16 g_code, Word16 gcode0, Word16 exp_gcode0) *-------------------------------------------------------------------------*/ static void Mode2_gain_dec_mless( - Word16 index, /* i : Quantization index vector Q0 */ - Word16 *code, /* i : algebraic code excitation Q9 */ - Word16 lcode, /* i : Subframe size Q0 */ - Word16 *gain_pit, /* o : Quantized pitch gain 1Q14 */ - Word32 *gain_code, /* o : Quantized codebook gain Q16 */ - Word16 mean_ener, /* i : mean_ener defined in open-loop Q8 */ - Word16 *past_gpit, /* i/o: past gain of pitch 1Q14 */ - Word32 *past_gcode, /* i/o: past energy of code Q16 */ - Word16 *gain_inov, /* o : unscaled innovation gain 3Q12 */ - Word16 coder_type /* i : coder type for number of bits */ + int index, /* (i) : index of quantizer */ + float code[], /* (i) : Innovative code vector */ + int lcode, /* (i) : Subframe size */ + float *gain_pit, /* (o) : Quantized pitch gain */ + float *gain_code, /* (o) : Quantized codebook gain */ + float mean_ener, /* (i) : mean_ener defined in open-loop (2 bits) */ + float *past_gpit, /* (i/o): past gain of pitch */ + float *past_gcode, /* (i/o): past energy of code */ + float *gain_inov, /* (o) : un-scaled innovation gain */ + short coder_type /* (i) : coder type for number of bits */ ) { - - Word16 ener_code; + short i; + float ener_code,gcode0; const Word16 *t_qua_gain; - Word16 exp_L_tmp1; - Word16 gcode0, exp_gcode0; - Word32 L_tmp, L_tmp1; + ener_code = 0.0f; + if( coder_type == 0 ) + { + *gain_inov = 1.0f / (float)sqrt( ( dotp( code, code, lcode ) + 0.01f ) / lcode); + } + else + { + ener_code = 0.01f; - /**gain_inov = 1.0f / (float)sqrt( ( dot_product( code, code, lcode ) + 0.01f ) / lcode);*/ - L_tmp = calc_gain_inov(code, lcode, &L_tmp1, &exp_L_tmp1); - move16(); - *gain_inov = round_fx(L_shl(L_tmp, 15-3)); /* gain_inov in Q12 */ + for(i=0; i Q5 */ - L_tmp1 = L_deposit_h(BASOP_Util_Divide3216_Scale(L_tmp,*gain_inov,&exp_L_tmp1)); - *past_gcode = L_shl(L_tmp1,sub(exp_L_tmp1,15-12)); - - + *past_gcode = *gain_code / *gain_inov; return; } + /*---------------------------------------------------------------------* * gain_dec_uv * @@ -145,262 +111,149 @@ static void Mode2_gain_dec_mless( *---------------------------------------------------------------------*/ static void gain_dec_uv( - Word16 index, /* i : Quantization index vector Q0 */ - Word16 *code, /* i : algebraic code excitation Q9 */ - Word16 lcode, /* i : Subframe size Q0 */ - Word16 *gain_pit, /* o : Quantized pitch gain 1Q14 */ - Word32 *gain_code, /* o : Quantized codebook gain Q16 */ - Word16 *past_gpit, /* i/o: past gain of pitch 1Q14 */ - Word32 *past_gcode, /* i/o: past energy of code Q16 */ - Word16 *gain_inov /* o : unscaled innovation gain 3Q12 */ + int index, /* i/o: Quantization index vector */ + float *code, /* i : algebraic code excitation */ + int lcode, /* i : Subframe size */ + float *gain_pit, /* o : Quantized pitch gain */ + float *gain_code, /* o : Quantized codebook gain */ + float *past_gpit, /* i/o: past gain of pitch */ + float *past_gcode, /* i/o: past energy of code */ + float *gain_inov /* o : unscaled innovation gain */ ) { - Word16 i, exp_L_tmp1; - Word32 L_tmp, L_tmp1; - - /*-----------------------------------------------------------------* * Innovation energy (without gain) *-----------------------------------------------------------------*/ - /* *gain_inov = 1.0f / (float)sqrt( ( dot_product( code, code, lcode ) + 0.01f ) / lcode );*/ - L_tmp = calc_gain_inov(code, lcode, &L_tmp1, &exp_L_tmp1); - move16(); - *gain_inov = round_fx(L_shl(L_tmp, 15-3)); /* gain_inov in Q12 */ + + *gain_inov = 1.0f / (float)sqrt( ( dotp( code, code, lcode ) + 0.01f ) / lcode ); /*-----------------------------------------------------------------* * Decode pitch gain *-----------------------------------------------------------------*/ - *gain_pit = 0; - move16(); + *gain_pit = 0.0f; /*-----------------------------------------------------------------* * Decode codebook gain *-----------------------------------------------------------------*/ - /* *gain_code= (float)pow(10.f,(((index*1.9f)-30.f)/20.f));*/ - L_tmp = L_mac(-167197708l/*-0.166096*30.0f Q25*/,shl(index, 16-7), 10341/*0.166096f*1.9f Q15*/); - i = add(1,extract_l(L_shr(L_tmp, 25))); - L_tmp = L_lshl(L_tmp, 6); - L_tmp = L_and(0x7FFFFFFF, L_tmp); - - L_tmp = Pow2(30,round_fx(L_tmp)); - L_tmp = L_shl(L_tmp, i-(31-16)); /* Q16 */ + *gain_code= (float)pow(10.f,(((index*1.9f)-30.f)/20.f)); /*-----------------------------------------------------------------* * past gains for error concealment *-----------------------------------------------------------------*/ - *past_gpit = *gain_pit; - *past_gcode = L_tmp; - L_tmp = L_shl(Mpy_32_16_1(L_tmp, *gain_inov), 3); /* Q16*Q12 -> Q13 -> Q16 */ - *gain_code = L_tmp; - move32(); + *past_gpit = *gain_pit; + *past_gcode = *gain_code; + *gain_code *= *gain_inov; return; } + /*---------------------------------------------------------------------* * gain_dec_gacelp_uv * * Decoding of pitch and codebook gains for Unvoiced mode *---------------------------------------------------------------------*/ - static void gain_dec_gacelp_uv( - Word16 index, /* i : Quantization index vector Q0 */ - Word16 *code, /* i : algebraic code excitation Q9 */ - Word16 *code2, /* i : algebraic code excitation Q9 */ - Word16 mean_ener, /* i : Q8 */ - Word16 lcode, /* i : Subframe size Q0 */ - Word16 *gain_pit, /* o : Quantized pitch gain 1Q14 */ - Word32 *gain_code, /* o : Quantized codebook gain Q16 */ - Word32 *gain_code2, /* o : Quantized codebook gain Q16 */ - Word16 *past_gpit, /* i/o: past gain of pitch 1Q14 */ - Word32 *past_gcode, /* i/o: past energy of code Q16 */ - Word16 *gain_inov /* o : unscaled innovation gain 3Q12 */ + int index, /* i/o: Quantization index vector */ + float *code, /* i : algebraic code excitation */ + float *code2, /* i : algebraic code excitation */ + float mean_ener, /* i : mean energy */ + int lcode, /* i : Subframe size */ + float *gain_pit, /* o : Quantized pitch gain */ + float *gain_code, /* o : Quantized codebook gain */ + float *gain_code2, /* o : Quantized codebook gain */ + float *past_gpit, /* i/o: past gain of pitch */ + float *past_gcode, /* i/o: past energy of code */ + float *gain_inov /* o : unscaled innovation gain */ ) { - Word16 i, exp_L_tmp1; - Word16 exp_gcode; - Word16 g_code; - Word32 L_tmp, L_tmp1; - Word32 pred_nrg_frame; - Word16 exp_gcode2, g_code2, norm_code2; - Word16 index2, s; + float pred_nrg_frame,norm_code2; + float gcode, gcode2; + short index2; - - - - /* pred_nrg_frame = (float)pow(10.0,mean_ener/20.0); */ - L_tmp = L_mult(mean_ener, 10885/*0.166096f * 2 Q15*/); /* 6Q25 */ - pred_nrg_frame = BASOP_Util_InvLog2(L_sub(L_tmp, 503316480l/*15.f Q25*/)); /* 15Q16 */ + pred_nrg_frame = (float)pow(10.0,mean_ener/20.0); /*-----------------------------------------------------------------* * Prediction gains *-----------------------------------------------------------------*/ - /* gain_inov = 1.0f / sqrt((dot_product(code, code, L_SUBFR) + 0.01) / L_SUBFR) */ - L_tmp = calc_gain_inov(code, lcode, NULL, NULL); - *gain_inov = round_fx(L_shl(L_tmp, 15-3)); /* gain_inov in Q12 */ - /* gcode = pred_nrg_frame * (*gain_inov); */ - L_tmp = Mpy_32_16_1(pred_nrg_frame, *gain_inov); /* 18Q13 */ - i = norm_l(L_tmp); - g_code = round_fx(L_shl(L_tmp, i)); - exp_gcode = sub(18, i); + *gain_inov = 1.0f / (float)sqrt( ( dotp( code, code, lcode ) + 0.01f ) / lcode ); + gcode=pred_nrg_frame*(*gain_inov); - /* norm_code2 = 1.0f / sqrt((dot_product(code2, code2, lcode) + 0.01f) / lcode); */ - L_tmp = calc_gain_inov(code2, lcode, NULL, NULL); - norm_code2 = round_fx(L_shl(L_tmp, 15-3)); /* Q12 */ - - /* g_code2 = pred_nrg_frame * norm_code2; */ - L_tmp = Mpy_32_16_1(pred_nrg_frame, norm_code2); /* 18Q13 */ - i = norm_l(L_tmp); - g_code2 = round_fx(L_shl(L_tmp, i)); - exp_gcode2 = sub(18, i); + norm_code2 = 1.0f/ (float)sqrt( ( dotp( code2, code2, lcode ) + 0.01f ) / lcode ); + gcode2=pred_nrg_frame*(norm_code2); /*-----------------------------------------------------------------* * Decode pitch gain *-----------------------------------------------------------------*/ - *gain_pit = 0; - move16(); + + *gain_pit = 0.0f; *past_gpit = *gain_pit; - move16(); /*-----------------------------------------------------------------* * past gains for error concealment *-----------------------------------------------------------------*/ - index2=shr(index,5); - index=s_and(index,0x1F); - /**gain_code= (float)pow(10.f,(((index*1.25f)-20.f)/20.f))*gcode;*/ + index2=index>>5; + index=index&0x1F; - L_tmp = L_mac(-111465139l/*-0.166096*20.0f Q25*/,shl(index, 16-7), 6803/*0.166096f*1.25f Q15*/); - - i = add(1,extract_l(L_shr(L_tmp, 25))); - L_tmp = L_lshl(L_tmp, 6); - L_tmp = L_and(0x7FFFFFFF, L_tmp); - - L_tmp = Pow2(30,round_fx(L_tmp)); - L_tmp = L_shl(L_tmp, i-(31-16)); /* Q16 */ - - /* *past_gcode = L_tmp * pred_nrg_frame; */ - i = norm_l(L_tmp); - L_tmp1 = L_shl(L_tmp, i); - exp_L_tmp1 = sub(15, i); - - i = norm_l(pred_nrg_frame); - L_tmp1 = Mpy_32_32(L_tmp1, L_shl(pred_nrg_frame, i)); - exp_L_tmp1 = add(exp_L_tmp1, sub(15, i)); - - *past_gcode = L_shl(L_tmp1, sub(exp_L_tmp1, 15)); /* Q16 */ move32(); - - *gain_code = L_shl(Mpy_32_16_1(*past_gcode, *gain_inov), 3); - move32(); - - - L_tmp = Mpy_32_16_1(*gain_code, BASOP_Util_Divide1616_Scale(g_code2, g_code, &s)); - L_tmp = L_shl(L_tmp, sub(sub(add(s, exp_gcode2), exp_gcode), 2)); /* Q16 */ - L_tmp1 = L_add(L_tmp, 0); - FOR (i = 0; i < index2; i++) - { - L_tmp1 = L_add(L_tmp1, L_tmp); - } - *gain_code2 = L_tmp1; + *gain_code= (float)pow(10.f,(((index*1.25f)-20.f)/20.f))*gcode; + *gain_code2 = (float) (index2*0.25f+0.25f)*(*gain_code*(gcode2/gcode)); + *past_gcode=*gain_code/ *gain_inov; /*unscaled gain*/ return; } -/********************* - * public functions * - *********************/ + +/*---------------------------------------------------------------------* + * decode_acelp_gains + * + * + *---------------------------------------------------------------------*/ void decode_acelp_gains( - Word16 *code, /* i : algebraic code excitation Q9 */ - Word16 gains_mode, - Word16 mean_ener_code, /* i : mean_ener defined in open-loop Q8 */ - Word16 *gain_pit, /* o : Quantized pitch gain 1Q14 */ - Word32 *gain_code, /* o : Quantized codebook gain Q16 */ - Word16 **pt_indice, - Word16 *past_gpit, /* i/o: past gain of pitch 1Q14 */ - Word32 *past_gcode, /* i/o: past energy of code Q16 */ - Word16 *gain_inov, /* o : unscaled innovation gain 3Q12 */ - Word16 L_subfr, /* i : Subframe size Q0 */ - Word16 *code2, /* i : algebraic code excitation Q9 */ - Word32 *gain_code2 /* o : Quantized codebook gain Q16 */ + float *code, + int gains_mode, + float mean_ener_code, + float *gain_pit, + float *gain_code, + int **pt_indice, + float *past_gpit, + float *past_gcode, + float *gain_inov, + int L_subfr, + float *code2, + float *gain_code2 ) { - Word16 index = 0; - + int index = 0; index = **pt_indice; (*pt_indice)++; - IF ( s_and(gains_mode > 0, sub(gains_mode, 4) < 0) ) + if (((gains_mode > 0) && (gains_mode < 4))) { - /* ACELP gains quantizer (5bits/subfr) */ + /* EVS gains quantizer (5bits/subfr) */ Mode2_gain_dec_mless(index, code, L_subfr, gain_pit, gain_code, mean_ener_code, past_gpit, past_gcode, gain_inov, gains_mode-1 ); } - ELSE IF (s_or(sub(gains_mode,4) == 0, sub(gains_mode,5) == 0)) - { - /* AMR-WB gains quantizer (6bits/subfr (mode 2) or 7bits/subfr (mode 3)) */ - assert(0); - } - ELSE IF ( sub(gains_mode,6) == 0) + else if(gains_mode == 6) { /* UV gains quantizer (6bits/subfr) */ - gain_dec_uv( index, code, L_subfr, gain_pit, gain_code, past_gpit, past_gcode, gain_inov ); + gain_dec_uv(index, code, L_subfr, gain_pit, gain_code, past_gpit, past_gcode, gain_inov ); } - ELSE IF (sub(gains_mode,7) == 0) + else if(gains_mode == 7) { /* GACELP_UV gains quantizer (7=5-2bits/subfr) */ - gain_dec_gacelp_uv( index, code, code2, mean_ener_code, L_subfr, gain_pit, gain_code, gain_code2, past_gpit, past_gcode, gain_inov ); + gain_dec_gacelp_uv(index, code, code2, mean_ener_code, L_subfr, gain_pit, gain_code, gain_code2, past_gpit, past_gcode, gain_inov ); } - ELSE + else { fprintf(stderr, "invalid gains coding for acelp!\n"); assert(0); } -} - - -/*---------------------------------------------------------------------* - * d_gain_pred : - * - * decode the predicted value for the scaled - * innovation energy in all subframes - *---------------------------------------------------------------------*/ -void d_gain_pred( - Word16 nrg_mode, /* i : NRG moe */ - Word16 *Es_pred, /* o : predicted scaled innovation energy Q8 */ - Word16 **pt_indice /* i/o: pointer to the buffer of indices */ -) -{ - Word16 indice; - - indice = (Word16)**pt_indice; - (*pt_indice)++; - - *Es_pred = 0; - move16(); - - if( sub(nrg_mode,1) == 0 ) - { - *Es_pred = Es_pred_qua[indice]; - move16(); - } - - if( sub(nrg_mode,2) == 0 ) - { - *Es_pred = Es_pred_qua_2[indice]; - move16(); - } - - IF( sub(nrg_mode,2) > 0 ) - { - move16(); - *Es_pred= extract_l(L_mac(-335544320l/* -20.f Q24*/, indice, 224/* 1.75f Q7*/)); /*(Q8 - ((Q0*Q7)=Q8))*/ - } - return; } diff --git a/src/libs/libevs/lib_dec/dec2t32.cpp b/src/libs/libevs/lib_dec/dec2t32.cpp new file mode 100644 index 00000000..26779324 --- /dev/null +++ b/src/libs/libevs/lib_dec/dec2t32.cpp @@ -0,0 +1,90 @@ +/*==================================================================================== + EVS Codec 3GPP TS26.443 Nov 13, 2018. Version 12.11.0 / 13.7.0 / 14.3.0 / 15.1.0 + ====================================================================================*/ + +#include "options.h" +#include "cnst.h" +#include "prot.h" + + +/*----------------------------------------------------------------------------------* + * dec_acelp_2t32() + * + * 12 bits algebraic codebook decoder. + * 2 track x 32 positions per track = 64 samples. + * + * 12 bits --> 2 pulses in a frame of 64 samples. + * + * All pulses can have two (2) possible amplitudes: +1 or -1. + * Each pulse can have 32 possible positions. + * + * See cod2t32.c for more details of the algebraic code. + *----------------------------------------------------------------------------------*/ + +void dec_acelp_2t32( + Decoder_State *st, /* i/o: decoder state structure */ + float code[] /* o: algebraic (fixed) codebook excitation */ +) +{ + short index, i0, i1; + + index = (short) get_next_indice( st, 12 ); + + set_f( code, 0.0f, L_SUBFR ); + + /*-----------------------------------------------------------------* + * decode the positions and signs of pulses and build the codeword + *-----------------------------------------------------------------*/ + + i0 = ((index>>6) & (NB_POS_FCB_2T-1)) * NB_TRACK_FCB_2T; + i1 = ((index & (NB_POS_FCB_2T-1)) * NB_TRACK_FCB_2T) + 1; + code[i0] = -1.0f; + if ((index & 0x800) == 0) + { + code[i0] = 1.0f; + } + + code[i1] = -1.0f; + if ((index & 0x20) == 0) + { + code[i1] = 1.0f; + } + + return; +} + + +/*----------------------------------------------------------------------------------* + * dec_acelp_1t64() + * + * 7 bits algebraic codebook. + * 1 track x 64 positions per track = 64 samples. + * + * The pulse can have 64 possible positions and two (2) possible amplitudes: +1 or -1. + *----------------------------------------------------------------------------------*/ + +void dec_acelp_1t64( + Decoder_State *st, /* i/o: decoder state structure */ + float code[] /* o: algebraic (fixed) codebook excitation */ +) +{ + short pos, sgn; + + /*-----------------------------------------------------------------* + * decode the positions and signs of pulses and build the codeword + *-----------------------------------------------------------------*/ + + pos = (short)get_next_indice( st, 7 ); + + sgn = -1; + if( pos >= L_SUBFR ) + { + pos -= L_SUBFR; + sgn = 1; + } + + set_f( code, 0.0f, L_SUBFR ); + code[pos] = sgn; + + return; +} diff --git a/src/libs/libevs/lib_dec/dec2t32_fx.cpp b/src/libs/libevs/lib_dec/dec2t32_fx.cpp deleted file mode 100755 index 545c7e5e..00000000 --- a/src/libs/libevs/lib_dec/dec2t32_fx.cpp +++ /dev/null @@ -1,125 +0,0 @@ -/*==================================================================================== - EVS Codec 3GPP TS26.442 Apr 03, 2018. Version 12.11.0 / 13.6.0 / 14.2.0 - ====================================================================================*/ - -#include "options.h" /* Compilation switches */ -#include "cnst_fx.h" /* Common constants */ -#include "prot_fx.h" /* Function prototypes */ -#include "stl.h" - - -/*==========================================================================*/ -/* FUNCTION : void dec_acelp_2t32_fx () */ -/*--------------------------------------------------------------------------*/ -/* PURPOSE : */ -/* * 12 bits algebraic codebook decoder. */ -/* * 2 track x 32 positions per track = 64 samples. */ -/* * 12 bits --> 2 pulses in a frame of 64 samples. */ -/* * All pulses can have two (2) possible amplitudes: +1 or -1. */ -/* * Each pulse can have 32 possible positions. */ -/* * See cod2t32.c for more details of the algebraic code. */ -/*--------------------------------------------------------------------------*/ -/* INPUT ARGUMENTS : */ -/* _Word16 i_subfr, i : subframe index */ -/*--------------------------------------------------------------------------*/ -/* OUTPUT ARGUMENTS : */ -/* _Word16 code[] o : algebraic (fixed) codebook excitation Q12 */ -/*--------------------------------------------------------------------------*/ -/* INPUT/OUTPUT ARGUMENTS : */ -/*--------------------------------------------------------------------------*/ -/* RETURN ARGUMENTS : */ -/* _ None */ -/*--------------------------------------------------------------------------*/ -/* CALLED FROM : */ -/*==========================================================================*/ - - -void dec_acelp_2t32_fx( - Decoder_State_fx *st_fx, /* i/o: decoder state structure */ - Word16 code[] /* o: algebraic (fixed) codebook excitation */ -) -{ - - Word16 index, i0, i1; - - index = (Word16) get_next_indice_fx( st_fx, 12 ); - move16(); - - set16_fx( code, 0, L_SUBFR ); - - /*------------------------------------------------------------------------------------------* - * decode the positions and signs of pulses and build the codeword - *------------------------------------------------------------------------------------------*/ - - i0 = shl(s_and(shr(index, 6), NB_POS_FCB_2T-1), 1); - - i1 = add(shl(s_and(index, NB_POS_FCB_2T-1), 1), 1); - - - code[i0] = -512; - move16(); - if (s_and(index, 0x800) == 0) - { - code[i0] = 512; - move16(); - } - - code[i1] = -512; - move16(); - if (s_and(index, 0x20) == 0) - { - code[i1] = 512; - move16(); - } - -} - - -/*==========================================================================*/ -/* FUNCTION : void dec_acelp_1t64_fx () */ -/*--------------------------------------------------------------------------*/ -/* PURPOSE : * 7 bits algebraic codebook. */ -/* * 1 track x 64 positions per track = 64 samples. */ -/* * The pulse can have 64 possible positions and two (2) possible amplitudes: +1 or -1.*/ -/*--------------------------------------------------------------------------*/ -/* INPUT ARGUMENTS : */ -/* _Word16 i_subfr, i : subframe index */ -/*--------------------------------------------------------------------------*/ -/* OUTPUT ARGUMENTS : */ -/* _Word16 code[] o : algebraic (fixed) codebook excitation Q12 */ -/*--------------------------------------------------------------------------*/ -/* INPUT/OUTPUT ARGUMENTS : */ -/*--------------------------------------------------------------------------*/ -/* RETURN ARGUMENTS : */ -/* _ None */ -/*--------------------------------------------------------------------------*/ -/* CALLED FROM : */ -/*==========================================================================*/ -void dec_acelp_1t64_fx( - Decoder_State_fx *st_fx, /* i/o: decoder state structure */ - Word16 code[] /* o: algebraic (fixed) codebook excitation Q12*/ -) -{ - Word16 pos,sgn; - - /*-----------------------------------------------------------------* - * decode the positions and signs of pulses and build the codeword - *-----------------------------------------------------------------*/ - pos = (Word16)get_next_indice_fx( st_fx, 7 ); - move16(); - - sgn = -512; - move16(); - IF( sub(pos,L_SUBFR) >= 0) - { - pos = sub(pos, L_SUBFR); - move16(); - sgn = 512; - move16(); - } - set16_fx(code, 0, L_SUBFR); - code[pos] = sgn; - move16(); - return; - -} diff --git a/src/libs/libevs/lib_dec/dec4t64.cpp b/src/libs/libevs/lib_dec/dec4t64.cpp new file mode 100644 index 00000000..61060a8b --- /dev/null +++ b/src/libs/libevs/lib_dec/dec4t64.cpp @@ -0,0 +1,737 @@ +/*==================================================================================== + EVS Codec 3GPP TS26.443 Nov 13, 2018. Version 12.11.0 / 13.7.0 / 14.3.0 / 15.1.0 + ====================================================================================*/ + +#include "options.h" +#include "cnst.h" +#include "prot.h" +#include "rom_com.h" + + +/*-------------------------------------------------------------------* + * Local functions + *-------------------------------------------------------------------*/ + +static void add_pulses(const short pos[], const short nb_pulse, const short track, float code[]); +static void dec_1p_N1(const long index, const short N, const short offset, short pos[]); +static void dec_2p_2N1(const long index, const short N, const short offset, short pos[]); +static void dec_3p_3N1(const long index, const short N, const short offset, short pos[]); +static void dec_4p_4N1(const long index, const short N, const short offset, short pos[]); +static void dec_4p_4N(const long index, const short N, const short offset, short pos[]); +static void dec_5p_5N(const long index, const short N, const short offset, short pos[]); +static void dec_6p_6N2(const long index, const short N, const short offset, short pos[]); +static int fcb_decode_PI( int code_index, short sector_6p[], int pulse_num ); + +/*----------------------------------------------------------------------------------* + * dec_acelp_4t64() + * + * 20, 36 bits algebraic codebook decoder. + * 4 tracks x 16 positions per track = 64 samples. + * + * 20 bits --> 4 pulses in a frame of 64 samples. + * 36 bits --> 8 pulses in a frame of 64 samples. + * + * All pulses can have two (2) possible amplitudes: +1 or -1. + * Each pulse can have sixteen (16) possible positions. + * + * See cod4t64.c for more details of the algebraic code. + *----------------------------------------------------------------------------------*/ + +void dec_acelp_4t64( + Decoder_State *st, /* i/o: decoder state structure */ + short nbbits, /* i : number of bits per codebook */ + float code[], /* o : algebraic (fixed) codebook excitation */ + const short Opt_AMR_WB /* i : flag indicating AMR-WB IO mode */ +) +{ + short i, k, pos[7]; + long L_index; + long ind1[NB_TRACK_FCB_4T], ind2[NB_TRACK_FCB_4T]; + PulseConfig config; + int indexing_indices[6], wordcnt, bitcnt; + + if ( !Opt_AMR_WB ) + { + switch (nbbits) + { + case 20: + config.nb_pulse = 4; + break; + + case 28: + config.nb_pulse = 6; + break; + + case 36: + config.nb_pulse = 8; + break; + + case 43: + config.nb_pulse = 10; + break; + + case 50: + config.nb_pulse = 12; + break; + + case 62: + config.nb_pulse = 16; + break; + + + case 87: + config.nb_pulse = 26; + break; + } + + config.bits = nbbits; + config.codetrackpos = TRACKPOS_FIXED_FIRST; + + + wordcnt = nbbits >> 4; + bitcnt = nbbits & 15; + for ( i = 0; i < wordcnt; i++ ) + { + indexing_indices[i] = get_next_indice( st, 16 ); + } + if ( bitcnt ) + { + indexing_indices[i] = get_next_indice( st, bitcnt ); + } + + D_ACELP_indexing( code, config, NB_TRACK_FCB_4T, indexing_indices, &st->BER_detect ); + } + else + { + for (i=0; i> N) & 1; + + if (i == 1) + { + pos1 += NB_POS_FCB_4T; + } + + pos[0] = pos1; + + return; +} + +/*-------------------------------------------------------* + * dec_2p_2N1() + * + * Decode 2 pulses with 2*N+1 bits: + *-------------------------------------------------------*/ + +void dec_2p_2N1( + const long index, /* i: quantization index */ + const short N, /* i: nb. of bits */ + const short offset, /* i: pulse position offset */ + short pos[] /* o: pulse position */ +) +{ + short i, pos1, pos2; + long mask; + + mask = ((1<> N) & mask) + offset; + i = (short)(index >> (2*N)) & 1; + pos2 = (short)(index & mask) + offset; + if ((pos2 - pos1) < 0) + { + if (i == 1) + { + pos1 += NB_POS_FCB_4T; + } + else + { + pos2 += NB_POS_FCB_4T; + } + } + else + { + if (i == 1) + { + pos1 += NB_POS_FCB_4T; + pos2 += NB_POS_FCB_4T; + } + } + + pos[0] = pos1; + pos[1] = pos2; + + return; +} + +/*-------------------------------------------------------* + * dec_3p_3N1() + * + * Decode 3 pulses with 3*N+1 bits: + *-------------------------------------------------------*/ + +static void dec_3p_3N1( + const long index, /* i: quantization index */ + const short N, /* i: nb. of bits */ + const short offset, /* i : pulse position offset */ + short pos[] /* o : pulse position */ +) +{ + short j; + long idx, mask; + + mask = ((1 << ((2 * N) - 1)) - 1); + idx = index & mask; + j = offset; + + if(((index >> ((2 * N) - 1)) & 1) == 1) + { + j += (1 << (N - 1)); + } + + dec_2p_2N1(idx, N - 1, j, pos); + mask = ((1 << (N + 1)) - 1); + idx = (index >> (2 * N)) & mask; + dec_1p_N1(idx, N, offset, pos + 2); + + return; +} + +/*-------------------------------------------------------* + * dec_4p_4N1() + * + * Decode 4 pulses with 4*N+1 bits: + *-------------------------------------------------------*/ + +static void dec_4p_4N1( + const long index, /* i : quantization index */ + const short N, /* i : nb. of bits */ + const short offset, /* i : pulse position offset */ + short pos[] /* o : pulse position */ +) +{ + short j; + long mask, idx; + + mask = ((1 << ((2 * N) - 1)) - 1); + idx = index & mask; + j = offset; + + if(((index >> ((2 * N) - 1)) & 1) == 1) + { + j += (1 << (N - 1)); + } + + dec_2p_2N1(idx, N - 1, j, pos); + mask = ((1 << ((2 * N) + 1)) - 1); + idx = (index >> (2 * N)) & mask; + dec_2p_2N1(idx, N, offset, pos + 2); + + return; +} + +/*-------------------------------------------------------* + * dec_4p_4N() + * + * Decode 4 pulses with 4*N bits: + *-------------------------------------------------------*/ + +static void dec_4p_4N( + const long index, /* i : quantization index */ + const short N, /* i : nb. of bits */ + const short offset, /* i : pulse position offset */ + short pos[] /* o : pulse position */ +) +{ + short j, n_1; + + n_1 = N - 1; + j = offset + (1 << n_1); + switch((index >> ((4 * N) - 2)) & 3) + { + case 0: + { + if(((index >> ((4 * n_1) + 1)) & 1) == 0) + { + dec_4p_4N1(index, n_1, offset, pos); + } + else + { + dec_4p_4N1(index, n_1, j, pos); + } + break; + } + case 1: + { + dec_1p_N1((index >> ((3 * n_1) + 1)), n_1, offset, pos); + dec_3p_3N1(index, n_1, j, pos + 1); + break; + } + case 2: + { + dec_2p_2N1((index >> ((2 * n_1) + 1)), n_1, offset, pos); + dec_2p_2N1(index, n_1, j, pos + 2); + break; + } + case 3: + { + dec_3p_3N1((index >> (n_1 + 1)), n_1, offset, pos); + dec_1p_N1(index, n_1, j, pos + 3); + break; + } + } + + return; +} + +/*-------------------------------------------------------* + * dec_5p_5N() + * + * Decode 5 pulses with 5*N bits: + *-------------------------------------------------------*/ + +static void dec_5p_5N( + const long index, /* i : quantization index */ + const short N, /* i : nb. of bits */ + const short offset, /* i : pulse position offset */ + short pos[] /* o : pulse position */ +) +{ + short j, n_1; + long idx; + + n_1 = N - 1; + j = offset + (1 << n_1); + idx = (index >> ((2 * N) + 1)); + + if(((index >> ((5 * N) - 1)) & 1) == 0) + { + dec_3p_3N1(idx, n_1, offset, pos); + dec_2p_2N1(index, N, offset, pos + 3); + } + else + { + dec_3p_3N1(idx, n_1, j, pos); + dec_2p_2N1(index, N, offset, pos + 3); + } + + return; +} + +/*-------------------------------------------------------* + * dec_6p_6N2() + * + * Decode 6 pulses with 6*N+2 bits: + *-------------------------------------------------------*/ + +static void dec_6p_6N2( + const long index, /* i : quantization index */ + const short N, /* i : nb. of bits */ + const short offset, /* i : pulse position offset */ + short pos[] /* o : pulse position */ +) +{ + short j, n_1, offsetA, offsetB; + + n_1 = N - 1; + j = offset + (1 << n_1); + offsetA = offsetB = j; + if(((index >> ((6 * N) - 5)) & 1) == 0) + { + offsetA = offset; + } + else + { + offsetB = offset; + } + + switch((index >> ((6 * N) - 4)) & 3) + { + case 0: + { + dec_5p_5N(index >> N, n_1, offsetA, pos); + dec_1p_N1(index, n_1, offsetA, pos + 5); + break; + } + + case 1: + { + dec_5p_5N(index >> N, n_1, offsetA, pos); + dec_1p_N1(index, n_1, offsetB, pos + 5); + break; + } + + case 2: + { + dec_4p_4N(index >> ((2 * n_1) + 1), n_1, offsetA, pos); + dec_2p_2N1(index, n_1, offsetB, pos + 4); + break; + } + + case 3: + { + dec_3p_3N1(index >> ((3 * n_1) + 1), n_1, offset, pos); + dec_3p_3N1(index, n_1, j, pos + 3); + break; + } + } + + return; +} + +/*---------------------------------------------------------------------* + * fcb_decode_class_all_p() + * + * Get the position number and the pulse number on every position + *---------------------------------------------------------------------*/ + +static int fcb_decode_class_all_p( /* o: The index of pulse positions */ + int *code_index, /* i: fcb index information */ + short sector_6p_num[], /* o: Number of pulses for each position */ + int pulse_num, /* i: Number of pulses on a track. */ + int *pos_num /* o: Number of positions which have pulses on the track.*/ +) +{ + int i,j,k; + int mn9; + int pulse_pos_num; + for (i=1; i<=pulse_num; i++) + { + if ((*code_index) < PI_offset[pulse_num][i]) + { + break; + } + } + + (*code_index) -= PI_offset[pulse_num][i-1]; + + pulse_pos_num = pulse_num - i + 2; + j = (*code_index)>>pulse_pos_num; + + k = j/PI_select_table[16][pulse_pos_num]; + mn9 = j - k * PI_select_table[16][pulse_pos_num]; + if ( ( pulse_pos_num < pulse_num ) && ( pulse_pos_num > 1 ) ) + { + for (i=0; i= k; l+=2); + + if (k > PI_select_table[17-l][temp]) + { + l--; + } + + k = PI_select_table[17-l][temp--] - k ; + pos_vector[i] = (short)(l-1); + } + pos_vector[i] = (short)(l+k); + + return; +} + +/*---------------------------------------------------------------------* + * fcb_decode_PI() + * + * decode fcb pulse index + *---------------------------------------------------------------------*/ + +static int fcb_decode_PI( /* o: return pulse position number */ + int code_index, /* i: fcb index information */ + short sector_6p[], /* o: decoded pulse position */ + int pulse_num /* i: pulse number for the track */ +) +{ + int i,l; + int mn9; + int pulse_pos_num; + short sector_6p_temp[7], sector_6p_num_temp[7]; + short *sector_6p_ptr0; + short *sector_6p_ptr1; + + /*get the position number and the pulse number on every position */ + mn9 = fcb_decode_class_all_p(&code_index, sector_6p_num_temp, pulse_num, &pulse_pos_num); + + /* rebuild the vector*/ + /* decode the pulse position not same to the others*/ + fcb_decode_position(mn9, sector_6p_temp, pulse_pos_num); + for (i=pulse_pos_num-1; i>=0; i--) + { + sector_6p_temp[i] += ((code_index&0x1)<<4) ; + code_index = code_index>>1; + } + + /* decode the pulse position maybe some pulse position same to other pulse */ + sector_6p_ptr0 = §or_6p[pulse_num]; + sector_6p_ptr1 = §or_6p_temp[pulse_pos_num]; + for (i=0; i> 9 ); + joint_index = ( ( idxs[2] << 16 ) + idxs[1] ) >> 2; + + if ( joint_index >= joint_offset) + { + joint_index = joint_index - joint_offset; + } + + ps[0] = joint_index/5472; + ps[1] = joint_index - ps[0]*5472; + fcb_decode_PI(ps[0], pos, 3); + add_pulses(pos, pulsestrack[0], 0, code); + fcb_decode_PI(ps[1], pos, 3); + add_pulses(pos, pulsestrack[1], 1, code); + + dec_2p_2N1(ps[2], 4, 0, pos); + add_pulses(pos, pulsestrack[2], 2, code); + dec_2p_2N1(ps[3], 4, 0, pos); + add_pulses(pos, pulsestrack[3], 3, code); + + return; +} + diff --git a/src/libs/libevs/lib_dec/dec4t64_fx.cpp b/src/libs/libevs/lib_dec/dec4t64_fx.cpp deleted file mode 100755 index b2e45a09..00000000 --- a/src/libs/libevs/lib_dec/dec4t64_fx.cpp +++ /dev/null @@ -1,800 +0,0 @@ -/*==================================================================================== - EVS Codec 3GPP TS26.442 Apr 03, 2018. Version 12.11.0 / 13.6.0 / 14.2.0 - ====================================================================================*/ - -#include "options.h" /* Compilation switches */ -#include "cnst_fx.h" /* Common constants */ -#include "prot_fx.h" /* Function prototypes */ -#include "rom_com_fx.h" /* Static table prototypes */ -#include "assert.h" /* Static table prototypes */ -#include "stl.h" - -/*-------------------------------------------------------------------* - * Local functions - *-------------------------------------------------------------------*/ -static void add_pulses_fx(const Word16 pos[],const Word16 nb_pulse, const Word16 track,Word16 code[]); -static void dec_1p_N1_fx(const Word32 index, const Word16 N, const Word16 offset, Word16 pos[] ); -static void dec_2p_2N1_fx(const Word32 index, const Word16 N, const Word16 offset, Word16 pos[] ); -static void dec_3p_3N1_fx(const Word32 index, const Word16 N, const Word16 offset, Word16 pos[] ); -static void dec_4p_4N1_fx(const Word32 index, const Word16 N, const Word16 offset, Word16 pos[] ); -static void dec_4p_4N_fx(const Word32 index, const Word16 N, const Word16 offset, Word16 pos[]); -static void dec_5p_5N_fx(const Word32 index,const Word16 N,const Word16 offset,Word16 pos[]); -static void dec_6p_6N2_fx(const Word32 index,const Word16 N,const Word16 offset,Word16 pos[]); -static Word32 fcb_decode_PI_fx(Word32 code_index,Word16 sector_6p[],Word16 pulse_num); - - -/*==========================================================================*/ -/* FUNCTION : void dec_acelp_4t64_fx () */ -/*--------------------------------------------------------------------------*/ -/* PURPOSE : */ -/* * 20, 36 bits algebraic codebook decoder. */ -/* * 4 tracks x 16 positions per track = 64 samples. */ -/* * 20 bits --> 4 pulses in a frame of 64 samples. */ -/* * 36 bits --> 8 pulses in a frame of 64 samples. */ -/* * All pulses can have two (2) possible amplitudes: +1 or -1. */ -/* * Each pulse can have sixteen (16) possible positions. */ -/* * See cod4t64.c for more details of the algebraic code. */ -/*--------------------------------------------------------------------------*/ -/* INPUT ARGUMENTS : */ -/* _Word16 i_subfr i : subframe index */ -/* _Word16 nbbits i : number of bits per codebook */ -/* _Word16 FCB_5Sx4T_fla i : 5Sx4Track flag for PI */ -/*--------------------------------------------------------------------------*/ -/* OUTPUT ARGUMENTS : */ -/* _Word16 code[] o : algebraic (fixed) codebook excitation Q12 */ -/* _Word16 index_buf_4T[] o : 5Sx4Track buffer for PI */ -/*--------------------------------------------------------------------------*/ -/* INPUT/OUTPUT ARGUMENTS : */ -/*--------------------------------------------------------------------------*/ -/* RETURN ARGUMENTS : */ -/* _ None */ -/*--------------------------------------------------------------------------*/ -/* CALLED FROM : */ -/*==========================================================================*/ -void dec_acelp_4t64_fx( - Decoder_State_fx *st_fx, /* i/o: decoder state structure */ - Word16 nbbits, /* i : number of bits per codebook */ - Word16 code[], /* o : algebraic (fixed) codebook excitation Q9*/ - const Word16 Opt_AMR_WB -) -{ - Word16 i, k, pos[7]; - Word32 L_index; - Word32 ind1[NB_TRACK_FCB_4T]; - PulseConfig config; - Word16 indexing_indices[6], wordcnt, bitcnt, index2; - - IF ( !Opt_AMR_WB ) - { - SWITCH (nbbits) - { - case 20: - config.nb_pulse = 4; - move16(); - BREAK; - - case 28: - config.nb_pulse = 6; - move16(); - BREAK; - - case 36: - config.nb_pulse = 8; - move16(); - BREAK; - - case 43: - config.nb_pulse = 10; - move16(); - BREAK; - - case 50: - config.nb_pulse = 12; - move16(); - BREAK; - - case 62: - config.nb_pulse = 16; - move16(); - BREAK; - - case 87: - config.nb_pulse = 26; - move16(); - BREAK; - } - - config.bits = nbbits; - move16(); - config.codetrackpos = TRACKPOS_FIXED_FIRST; - move16(); - - - wordcnt = shr(nbbits, 4); - bitcnt = s_and(nbbits, 15); - FOR ( i = 0; i < wordcnt; i++ ) - { - indexing_indices[i] = get_next_indice_fx( st_fx, 16 ); - move16(); - } - IF ( bitcnt ) - { - indexing_indices[i] = get_next_indice_fx( st_fx, bitcnt ); - move16(); - } - - D_ACELP_indexing( code, config, NB_TRACK_FCB_4T, indexing_indices, &st_fx->BER_detect ); - } - ELSE - { - FOR (i=0; i> N) & 1); */ - i = L_shr(index, N) & 1L; - - if (i != 0) - { - pos1 = add(pos1, NB_POS_FCB_4T); - } - pos[0] = pos1; - move16(); -} -/*-------------------------------------------------------* - * dec_2p_2N1() - * - * Decode 2 pulses with 2*N+1 bits: - *-------------------------------------------------------*/ - -void dec_2p_2N1_fx( - const Word32 index, /* i: quantization index */ - const Word16 N, /* i: nb. of bits */ - const Word16 offset, /* i: pulse position offset */ - Word16 pos[] /* o: pulse position */ -) -{ - - Word16 pos1, pos2, tmp; - Word32 mask, i; - - mask = L_deposit_l(sub(shl(1, N), 1)); /* mask = ((1<> N) & mask) + offset); */ - logic16(); - pos1 = extract_l(L_add((L_shr(index, N) & mask), L_deposit_l(offset))); - - /* i = (index >> (2*N)) & 1; */ - tmp = shl(N, 1); - i = L_and(L_shr(index, tmp), 1L); - - /* pos2 = ((index & mask) + offset); */ - pos2 = add(extract_l(index & mask), offset); - logic16(); - - - IF (sub(pos2, pos1) < 0) - { - IF (i != 0) - { - pos1 = add(pos1, NB_POS_FCB_4T); - } - ELSE - { - pos2 = add(pos2, NB_POS_FCB_4T); - } - } - ELSE - { - IF (i != 0) - { - pos1 = add(pos1, NB_POS_FCB_4T); - pos2 = add(pos2, NB_POS_FCB_4T); - } - } - - pos[0] = pos1; - move16(); - pos[1] = pos2; - move16(); - - return; - -} -/*-------------------------------------------------------* -* Dec_3p_3N1 -* -* Decode 3 pulses with 3*N+1 bits: -*-------------------------------------------------------*/ -static void dec_3p_3N1_fx( - const Word32 index, /* i : quantization index */ - const Word16 N, /* i : nb. of bits */ - const Word16 offset, /* i : pulse position offset */ - Word16 pos[] /* o : pulse position */ -) -{ - Word16 j, tmp; - Word32 mask, idx; - - tmp = sub(shl(N, 1), 1); /* mask = ((1<<((2*N)-1))-1); */ - mask = L_sub(L_shl(1L, tmp), 1L); - - idx = L_and(index, mask); - j = offset; - move16(); - tmp = sub(shl(N, 1), 1); - - logic16(); - IF ((L_shr(index, tmp) & 1L) != 0) - { - /* IF (((index >> ((2*N)-1)) & 1) == 1){ */ - j = add(j, shl(1, sub(N, 1))); /* j += (1<<(N-1)); */ - } - dec_2p_2N1_fx(idx, sub(N, 1), j, pos); - - mask = sub(shl(1, add(N, 1)), 1); /* mask = ((1<<(N+1))-1); */ - tmp = shl(N, 1); /* idx = (index >> (2*N)) & mask; */ - idx = L_shr(index, tmp) & mask; - logic16(); - - dec_1p_N1_fx(idx, N, offset, pos + 2); -} - -/*-------------------------------------------------------* - * Dec_4p_4N1 - * - * Decode 4 pulses with 4*N+1 bits: - *-------------------------------------------------------*/ -static void dec_4p_4N1_fx( - const Word32 index, /* i : quantization index */ - const Word16 N, /* i : nb. of bits */ - const Word16 offset, /* i : pulse position offset */ - Word16 pos[] /* o : pulse position */ -) -{ - Word16 j, tmp; - Word32 mask, idx; - - tmp = sub(shl(N, 1), 1); /* mask = ((1<<((2*N)-1))-1); */ - mask = L_sub(L_shl(1L, tmp), 1L); - idx = L_and(index, mask); - j = offset; - move16(); - tmp = sub(shl(N, 1), 1); - - logic16(); - IF((L_shr(index, tmp) & 1L) != 0L) - { - /* (((index >> ((2*N)-1)) & 1) == 1) */ - j = add(j, shl(1, sub(N, 1))); /* j += (1<<(N-1)); */ - } - dec_2p_2N1_fx(idx, sub(N, 1), j, pos); - - - tmp = add(shl(N, 1), 1); /* mask = ((1<<((2*N)+1))-1); */ - mask = L_sub(L_shl(1L, tmp), 1L); - idx = L_shr(index, shl(N, 1)) & mask; - logic16();/* idx = (index >> (2*N)) & mask; */ - dec_2p_2N1_fx(idx, N, offset, pos + 2); /* Dec_2p_2N1(idx, N, offset, pos+2); */ -} - - -/*-------------------------------------------------------* -* Dec_4p_4N -* -* Decode 4 pulses with 4*N bits: -*-------------------------------------------------------*/ -static void dec_4p_4N_fx( - const Word32 index, /* i : quantization index */ - const Word16 N, /* i : nb. of bits */ - const Word16 offset, /* i : pulse position offset */ - Word16 pos[] /* o : pulse position */ -) -{ - Word16 j, n_1, tmp; - - n_1 = sub(N, 1); - j = add(offset, shl(1, n_1)); /* j = offset + (1 << n_1) */ - - tmp = sub(shl(N, 2), 2); - logic16(); - SWITCH (L_shr(index, tmp) & 3) - { - /* ((index >> ((4*N)-2)) & 3) */ - case 0: - tmp = add(shl(n_1, 2), 1); - - logic16(); - IF((L_shr(index, tmp) & 1) == 0) - { - /* (((index >> ((4*n_1)+1)) & 1) == 0) */ - dec_4p_4N1_fx(index, n_1, offset, pos); - } - ELSE - { - dec_4p_4N1_fx(index, n_1, j, pos); - } - BREAK; - case 1: - tmp = add(extract_l(L_shr(L_mult(3, n_1), 1)), 1); /* Dec_1p_N1((index>>((3*n_1)+1)), n_1, offset, pos) */ - dec_1p_N1_fx(L_shr(index, tmp), n_1, offset, pos); - dec_3p_3N1_fx(index, n_1, j, pos + 1); - move16(); - BREAK; - case 2: - tmp = add(shl(n_1, 1), 1); /* Dec_2p_2N1((index>>((2*n_1)+1)), n_1, offset, pos) */ - dec_2p_2N1_fx(L_shr(index, tmp), n_1, offset, pos); - dec_2p_2N1_fx(index, n_1, j, pos + 2); - move16(); - BREAK; - case 3: - tmp = add(n_1, 1); /* Dec_3p_3N1((index>>(n_1+1)), n_1, offset, pos) */ - dec_3p_3N1_fx(L_shr(index, tmp), n_1, offset, pos); - dec_1p_N1_fx(index, n_1, j, pos + 3); - move16(); - BREAK; - } -} - - -/*-------------------------------------------------------* - * Dec_5p_5N - * - * Decode 5 pulses with 5*N bits: - *-------------------------------------------------------*/ -static void dec_5p_5N_fx( - const Word32 index, /* i : quantization index */ - const Word16 N, /* i : nb. of bits */ - const Word16 offset, /* i : pulse position offset */ - Word16 pos[] /* o : pulse position */ -) -{ - Word16 j, n_1, tmp; - Word32 idx; - - n_1 = sub(N, 1); - j = add(offset, shl(1, n_1)); /* j = offset + (1 << n_1); */ - tmp = add(shl(N, 1), 1); /* idx = (index >> ((2*N)+1)); */ - idx = L_shr(index, tmp); - tmp = sub(extract_l(L_shr(L_mult(5, N), 1)), 1); /* ((5*N)-1)) */ - - logic16(); - IF ((L_shr(index, tmp) & 1) == 0) /* ((index >> ((5*N)-1)) & 1) */ - { - dec_3p_3N1_fx(idx, n_1, offset, pos); - dec_2p_2N1_fx(index, N, offset, pos + 3); - move16(); - } - ELSE - { - dec_3p_3N1_fx(idx, n_1, j, pos); - dec_2p_2N1_fx(index, N, offset, pos + 3); - move16(); - } -} - -/*-------------------------------------------------------* - * Dec_6p_6N_2 - * - * Decode 6 pulses with 6*N+2 bits: - *-------------------------------------------------------*/ -static void dec_6p_6N2_fx( - const Word32 index, /* i : quantization index */ - const Word16 N, /* i : nb. of bits */ - const Word16 offset, /* i : pulse position offset */ - Word16 pos[] /* o : pulse position */ -) -{ - Word16 j, n_1, offsetA, offsetB, n_6; - - n_1 = sub(N, 1); - j = add(offset, shl(1, n_1)); /* j = offset + (1 << n_1); */ - n_6 = extract_l(L_mult0(N, 6)); - - /* !! N and n_1 are constants -> it doesn't need to be operated by Basic Operators */ - - offsetA = offsetB = j; - move16(); - logic16(); - IF ((L_shr(index, sub(n_6, 5)) & 1L) == 0) - { - /* IF (((index >> ((6*N)-5)) & 1) == 0) */ - offsetA = offset; - move16(); - } - ELSE - { - offsetB = offset; - move16(); - } - - - logic16(); - SWITCH (L_shr(index, sub(n_6, 4)) & 3) - { - /* (index >> ((6*N)-4)) & 3 */ - case 0: - dec_5p_5N_fx(L_shr(index, N), n_1, offsetA, pos); /* Dec_5p_5N(index>>N, n_1, offsetA, pos); */ - dec_1p_N1_fx(index, n_1, offsetA, pos + 5); - move16(); - BREAK; - case 1: - dec_5p_5N_fx(L_shr(index, N), n_1, offsetA, pos); /* Dec_5p_5N(index>>N, n_1, offsetA, pos); */ - dec_1p_N1_fx(index, n_1, offsetB, pos + 5); - move16(); - BREAK; - case 2: - dec_4p_4N_fx(L_shr(index, add(shl(n_1,1),1)), n_1, offsetA, pos); /* Dec_4p_4N(index>>((2*n_1)+1 ), n_1, offsetA, pos); */ - dec_2p_2N1_fx(index, n_1, offsetB, pos + 4); - move16(); - BREAK; - case 3: - dec_3p_3N1_fx(L_shr(index, add(add(shl(n_1, 1),n_1), 1)), n_1, offset, pos); /* Dec_3p_3N1(index>>((3*n_1)+ 1), n_1, offset, pos); */ - dec_3p_3N1_fx(index, n_1, j, pos + 3); - move16(); - BREAK; - } -} - -static Word32 fcb_decode_class_all_p_fx( /* o: The index of pulse positions */ - Word32 *code_index, /* i: fcb index information */ - Word16 sector_6p_num[], /* o: Number of pulses for each position */ - Word16 pulse_num, /* i: Number of pulses on a track. */ - Word16 *pos_num /* o: Number of positions which have pulses on the track.*/ -) -{ - Word16 i; - Word32 mn9,j,k; - Word16 pulse_pos_num; - Word32 L_tmp, L_tmp1; - FOR (i=1; i<=pulse_num; i++) - { - IF (L_sub((*code_index),PI_offset_fx[pulse_num][i]) < 0) - { - BREAK; - } - } - - /* (*code_index) -= PI_offset_fx[pulse_num][i-1];*/ - (*code_index) = L_sub((*code_index),PI_offset_fx[pulse_num][i-1]); - - /*pulse_pos_num = pulse_num - i + 2;*/ - pulse_pos_num = add(sub(pulse_num , i) , 2); - - /* j = (*code_index)>>pulse_pos_num;*/ - j = L_shr((*code_index) , pulse_pos_num); - IF(L_sub(j,PI_select_table_fx[16][pulse_pos_num]) < 0) - { - k = L_deposit_l(0); - mn9 = L_add(j, 0); - } - ELSE - { - L_tmp = L_deposit_l(0); - L_tmp1 = L_add(j, 0); - WHILE(L_sub(L_tmp1,PI_select_table_fx[16][pulse_pos_num]) >= 0) - { - L_tmp = L_add(L_tmp,1); - L_tmp1 = L_sub(L_tmp1,PI_select_table_fx[16][pulse_pos_num]); - } - k = L_add(L_tmp, 0); - mn9 = L_add(L_tmp1, 0); - } - /* mn9 = Mult_32_32(sub(j , k) , PI_select_table_fx[16][pulse_pos_num]);*/ - - test(); - IF ( (sub( pulse_pos_num,pulse_num) < 0 ) && ( sub(pulse_pos_num,1) > 0 ) ) - { - FOR (i=0; i= k; l+=2); - - if (L_sub(k,PI_select_table_fx[L_sub(17,l)][temp]) > 0) - { - l = L_sub(l,1); - } - - /* k = PI_select_table_fx[17-l][temp--] - k ;*/ - k = L_sub(PI_select_table_fx[L_sub(17,l)][temp--] , k); - pos_vector[i] = extract_l(L_sub(l,1)); - } - pos_vector[i] = extract_l(L_add(l,k)); - - return; -} - -static Word32 fcb_decode_PI_fx( /* o: return pulse position number */ - Word32 code_index, /* i: fcb index information */ - Word16 sector_6p[], /* o: decoded pulse position */ - Word16 pulse_num /* i: pulse number for the track */ -) -{ - Word16 i,l, j; - Word32 mn9; - Word16 pulse_pos_num; - Word16 sector_6p_temp[7], sector_6p_num_temp[7]; - Word16 *sector_6p_ptr0; - Word16 *sector_6p_ptr1; - - /*get the position number and the pulse number on every position */ - mn9 = fcb_decode_class_all_p_fx(&code_index, sector_6p_num_temp, pulse_num, &pulse_pos_num); - - /* rebuild the vector*/ - /* decode the pulse position not same to the others*/ - fcb_decode_position_fx(mn9, sector_6p_temp, pulse_pos_num); - FOR (i=pulse_pos_num-1; i>=0; i--) - { - /*sector_6p_temp[i] += ((code_index&0x1)<<4) ;*/ - sector_6p_temp[i] = add(sector_6p_temp[i],extract_l(L_shl((code_index&0x1),4))) ; - move16(); - /*code_index = code_index>>1;*/ - code_index = L_shr(code_index , 1); - - } - - /* decode the pulse position maybe some pulse position same to other pulse */ - sector_6p_ptr0 = §or_6p[pulse_num]; - sector_6p_ptr1 = §or_6p_temp[pulse_pos_num]; - FOR (i=0; i= 0) - { - joint_index = L_sub(joint_index, joint_offset); - } - - iDiv_and_mod_32(joint_index, 5472, &ps[0], &ps[1], 0); - fcb_decode_PI_fx(ps[0], pos, 3); - add_pulses_fx(pos, pulsestrack[0], 0, code); - fcb_decode_PI_fx(ps[1], pos, 3); - add_pulses_fx(pos, pulsestrack[1], 1, code); - - dec_2p_2N1_fx(ps[2], 4, 0, pos); - add_pulses_fx(pos, pulsestrack[2], 2, code); - dec_2p_2N1_fx(ps[3], 4, 0, pos); - add_pulses_fx(pos, pulsestrack[3], 3, code); - - return; -} - diff --git a/src/libs/libevs/lib_dec/dec_LPD.cpp b/src/libs/libevs/lib_dec/dec_LPD.cpp old mode 100755 new mode 100644 index 6cb6e97d..542c2ad9 --- a/src/libs/libevs/lib_dec/dec_LPD.cpp +++ b/src/libs/libevs/lib_dec/dec_LPD.cpp @@ -1,18 +1,18 @@ /*==================================================================================== - EVS Codec 3GPP TS26.442 Apr 03, 2018. Version 12.11.0 / 13.6.0 / 14.2.0 + EVS Codec 3GPP TS26.443 Nov 13, 2018. Version 12.11.0 / 13.7.0 / 14.3.0 / 15.1.0 ====================================================================================*/ - #include #include #include -#include "prot_fx.h" -#include "basop_util.h" -#include "rom_com_fx.h" +#include #include "options.h" -#include "stl.h" +#include "prot.h" +#include "rom_com.h" +#include "cnst.h" +#include "basop_proto_func.h" +#include "stat_com.h" -/* #if defined(_WIN32) && (_MSC_VER <= 1200) /\* disable global optimizations to overcome an internal compiler error *\/ */ #if defined(_MSC_VER) && (_MSC_VER <= 1200) /* disable global optimizations to overcome an internal compiler error */ #pragma optimize("g", off) #endif @@ -24,111 +24,90 @@ *--------------------------------------------------------------------*/ void decoder_LPD( - Word16 signal_out[], /* output: signal with LPD delay (7 subfrs) */ - Word16 signal_outFB[], - Word16 *total_nbbits, /* i/o: number of bits / decoded bits */ - Decoder_State_fx *st, - Word16 * bpf_noise_buf, - Word16 bfi, - Word16 *bitsRead, - Word16 *coder_type, - Word16 param[], - Word16 *pitch_buf, - Word16 *voice_factors, - Word16 *ptr_bwe_exc + float signal_out[], /* output: signal with LPD delay (7 subfrs) */ + float signal_outFB[], + short *total_nbbits, /* i/o: number of bits / decoded bits */ + Decoder_State *st, /* i/o: decoder memory state pointer */ + float *bpf_noise_buf, /* i/o: BPF noise buffer */ + short bfi, /* i : BFI flag */ + short *bitsRead, /* o : number of read bits */ + short *coder_type, /* o : coder type */ + int param[], /* o : buffer of parameters */ + float *pitch_buf, /* i/o: floating pitch values for each subfr*/ + float *voice_factors, /* o : voicing factors */ + float *ptr_bwe_exc /* o : excitation for SWB TBE */ ) { - Word16 *param_lpc; - Word16 synth_buf[OLD_SYNTH_SIZE_DEC+L_FRAME_PLUS+M]; - Word16 *synth; - Word16 synth_bufFB[OLD_SYNTH_SIZE_DEC+L_FRAME_PLUS+M]; - Word16 *synthFB; - Word16 lsf[(NB_DIV+1)*M],lsp[(NB_DIV+1)*M],lspmid[M],lsfmid[M]; - Word16 Aq[(NB_SUBFR16k+1)*(M+1)]; /* Dyn RAM: it can be reduced by M+1 if insert branch for nb_subfr==5*/ - Word16 pitch[NB_SUBFR16k]; - Word16 pit_gain[NB_SUBFR16k]; - Word16 i, k, *prm; - Word16 L_frame,nb_subfr; - Word16 L_frameTCX; + int *prm, param_lpc[NPRM_LPC_NEW]; + float synth_buf[OLD_SYNTH_SIZE_DEC+L_FRAME_PLUS+M]; + float *synth; + float synth_bufFB[OLD_SYNTH_SIZE_DEC+L_FRAME_PLUS+M]; + float *synthFB; + float lsf[(NB_DIV+1)*M], lsp[(NB_DIV+1)*M], lspmid[M], lsfmid[M]; + float Aq[(NB_SUBFR16k+1)*(M+1)]; + int pitch[NB_SUBFR16k]; + float pit_gain[NB_SUBFR16k]; + short i, k; + short past_core_mode; + short L_frame, nb_subfr, L_frameTCX; Word16 Aind[M+1], lspind[M]; - Word16 tmp_old[M+1], tmp_new[M+1], enr_old, enr_new; - Word16 xspnew_uw[NB_DIV*M], xsfnew_uw[NB_DIV*M]; - Word16 const* xsfBase; /* base for differential XSF coding */ - Word16 past_core_mode; + float tmp_old[M+1], tmp_new[M+1], enr_old, enr_new; + float lspnew_uw[NB_DIV*M], lsfnew_uw[NB_DIV*M]; + float lsf_q_1st_rf[M], lsf_q_rf[M], lsp_q_rf[M]; + float lsp_diff; + short LSF_Q_prediction; /* o : LSF prediction mode */ + short tcx_last_overlap_mode, tcx_current_overlap_mode; - Word16 lsf_q_1st_rf[M], lsf_q_rf[M], lsp_q_rf[M]; - Word32 lsp_diff; - Word16 LSF_Q_prediction; - Word16 tcx_last_overlap_mode, tcx_current_overlap_mode; - - st->core_fx = 0; /* to avoid compilation warnings */ - prm = NULL; /* to avoid compilation warnings */ /*--------------------------------------------------------------------------------* - * INIT + * Initializations *--------------------------------------------------------------------------------*/ - enr_old = 0; - move16(); - enr_new = 0; - move16(); + prm = param; /* to avoid compilation warnings */ + LSF_Q_prediction = -1; /* to avoid compilation warnings */ + enr_old = 0.0f; + enr_new = 0.0f; - LSF_Q_prediction= -1; - move16(); - - param_lpc = param+DEC_NPRM_DIV*NB_DIV; - - past_core_mode = st->last_core_bfi; - move16(); - - test(); - test(); - if(st->use_partial_copy && sub(st->rf_frame_type, RF_TCXFD) >= 0 && sub(st->rf_frame_type, RF_TCXTD2) <= 0) + if ( st->use_partial_copy && st->rf_frame_type >= RF_TCXFD && st->rf_frame_type <= RF_TCXTD2 ) { - bfi = st->bfi_fx; - move16(); + bfi = st->bfi; } + past_core_mode = st->last_core_bfi; + /*Adjust bit per frame*/ - if (bfi == 0) + if( !bfi ) { - st->bits_frame_core = sub(st->bits_frame, bitsRead[0]); + st->bits_frame_core = st->bits_frame - (*bitsRead); } /* Framing parameters */ - L_frame = st->L_frame_fx; - move16(); + L_frame = st->L_frame; L_frameTCX = st->L_frameTCX; - move16(); nb_subfr = st->nb_subfr; - move16(); - /* Initialize pointers */ synth = synth_buf + st->old_synth_len; - /*st->old_synth: Q_0*/ - Copy(st->old_synth, synth_buf, st->old_synth_len); - set16_fx(synth, 0, L_FRAME_PLUS + M); - synthFB = synth_bufFB + st->old_synth_lenFB; - Copy(st->old_synthFB_fx, synth_bufFB, st->old_synth_lenFB); - set16_fx(synthFB, 0, L_FRAME_PLUS + M); + mvr2r( st->old_synth, synth_buf, st->old_synth_len ); + mvr2r( st->old_synthFB, synth_bufFB, st->old_synth_lenFB ); + set_zero( synth, L_FRAME_PLUS+M ); + set_zero( synthFB, L_FRAME_PLUS+M ); + /*For post-processing (post-filtering+blind BWE)*/ - IF (st->tcxonly==0) + if( st->tcxonly == 0 ) { /* for bass postfilter */ - set16_fx(pitch, L_SUBFR, nb_subfr); - - set16_fx(pit_gain, 0, nb_subfr); + set_i( pitch, L_SUBFR, nb_subfr ); + set_zero( pit_gain, nb_subfr ); } /* PLC: [Common: Memory update] * PLC: Update the number of lost frames */ - IF ( bfi != 0) + if( bfi ) { - move16(); - st->nbLostCmpt = add(st->nbLostCmpt, 1); + st->nbLostCmpt++; } @@ -136,512 +115,404 @@ void decoder_LPD( * BITSTREAM DECODING *--------------------------------------------------------------------------------*/ - IF (bfi == 0) + + if( !bfi ) { - /* PLC: [TCX: Tonal Concealment] */ - st->second_last_core = st->last_core_fx; - move16(); + st->second_last_core = st->last_core; tcx_last_overlap_mode = st->tcx_cfg.tcx_last_overlap_mode; - move16(); tcx_current_overlap_mode = st->tcx_cfg.tcx_curr_overlap_mode; - move16(); - dec_prm(&(st->core_fx), &(st->last_core_fx), coder_type, param, param_lpc, total_nbbits, st, L_frame, bitsRead); - IF(!st->rate_switching_init && sub((st->last_codec_mode), MODE2) == 0 && st->BER_detect) + + dec_prm( &(st->core), &(st->last_core), coder_type, param, param_lpc, total_nbbits, st, L_frame, bitsRead ); + + if(!st->rate_switching_init && (st->last_codec_mode) == MODE2 && st->BER_detect) { - *coder_type = st->last_coder_type_fx; - move16(); - st->last_core_fx = st->second_last_core; - move16(); + *coder_type= st->last_coder_type; + st->last_core = st->second_last_core; st->tcx_cfg.tcx_last_overlap_mode = tcx_last_overlap_mode; - move16(); st->tcx_cfg.tcx_curr_overlap_mode = tcx_current_overlap_mode; - move16(); - st->bfi_fx = 1; - move16(); + st->bfi = 1; bfi = 1; - move16(); st->flagGuidedAcelp = 0; - move16(); st->nbLostCmpt++; - move16(); - st->core_brate_fx = st->last_core_brate_fx; - move16(); - st->core_fx = GetPLCModeDecision( st ); + st->core_brate = st->last_core_brate; + st->core = GetPLCModeDecision( st ); } } - ELSE + else { - - test(); - test(); - IF( st->use_partial_copy && sub(st->rf_frame_type, RF_TCXFD) >= 0 && sub(st->rf_frame_type, RF_TCXTD2) <= 0 ) + if( st->use_partial_copy && st->rf_frame_type >= RF_TCXFD && st->rf_frame_type <= RF_TCXTD2 ) { - dec_prm( &(st->core_fx), &(st->last_core_fx), coder_type, param, param_lpc, total_nbbits, st, L_frame, bitsRead ); + dec_prm( &(st->core), &(st->last_core), coder_type, param, param_lpc, total_nbbits, st, L_frame, bitsRead ); } - if (sub(st->nbLostCmpt, 1) > 0) + if( st->nbLostCmpt > 1 ) { st->flagGuidedAcelp = 0; - move16(); } + /* PLC: [Common: mode decision] + * PLC: Decide which Concealment to use. Update pitch lags if needed */ + st->core = GetPLCModeDecision( st ); } - /* PLC: [Common: mode decision] - * PLC: Decide which Concealment to use. Update pitch lags if needed */ - IF ( bfi!=0 ) + /* PLC: [Common: Memory update] + * PLC: Update the number of lost frames */ + if( !bfi ) { - st->core_fx = GetPLCModeDecision(st); - } - - IF ( bfi == 0 ) - { - IF( sub(st->prev_bfi_fx, 1)==0 ) + if( st->prev_bfi == 1 ) { st->prev_nbLostCmpt = st->nbLostCmpt; - move16(); } - ELSE + else { st->prev_nbLostCmpt = 0; - move16(); } - move16(); + st->nbLostCmpt = 0; } + /*--------------------------------------------------------------------------------* * LPC PARAMETERS *--------------------------------------------------------------------------------*/ - test(); - test(); - test(); - test(); - IF( (bfi == 0 ) || ( bfi != 0 && st->use_partial_copy != 0 && sub(st->rf_frame_type,RF_TCXFD) == 0) ) + + if( (bfi == 0 ) || ( bfi == 1 && st->use_partial_copy && st->rf_frame_type == RF_TCXFD) ) { - test(); - test(); - test(); - test(); - test(); - IF(sub(st->use_partial_copy,1)==0 && ( sub(st->rf_frame_type, RF_TCXFD) < 0 || sub(st->rf_frame_type, RF_TCXTD2) > 0)) + if(st->use_partial_copy && ( st->rf_frame_type < RF_TCXFD || st->rf_frame_type > RF_TCXTD2)) { - IF( sub((Word16)st->envWeighted,1)==0 ) + if( st->envWeighted ) { - Copy( st->lspold_uw, st->lsp_old_fx, M ); - Copy( st->lsfold_uw, st->lsf_old_fx, M ); + mvr2r( st->lspold_uw, st->lsp_old, M ); + mvr2r( st->lsfold_uw, st->lsf_old, M ); st->envWeighted = 0; - move16(); } /* first stage VQ, 8 bits; reuse TCX high rate codebook */ - set16_fx(lsf_q_1st_rf, 0, M); - vlpc_1st_dec(param_lpc[0], lsf_q_1st_rf ); + set_f(lsf_q_1st_rf, 0.0f, M); + vlpc_1st_dec(param_lpc[0], lsf_q_1st_rf, st->sr_core ); /* second stage vq */ - /* quantized lsf from two stages */ - /*v_add(lsf_q_1st_rf, lsf_q_diff_cb_8b_rf + M * param_lpc[1], lsf_q_rf, M);*/ - FOR (i=0; isr_core ); + reorder_lsf( lsf_q_rf, LSF_GAP, M, st->sr_core ); - /* current n-th ACELP frame and its corresponding partial copy */ - /*lsf2lsp( lsf_q_rf, lsp_q_rf, M, st->sr_core );*/ - E_LPC_lsf_lsp_conversion( lsf_q_rf, lsp_q_rf, M ); + /* current n-th ACELP frame and its corresponding partial copy */ + lsf2lsp( lsf_q_rf, lsp_q_rf, M, st->sr_core ); - /* copy the old and current lsfs and lsps into the lsf[] and lsp[] buffer for interpolation */ - Copy(st->lsf_old_fx, &lsf[0], M); - Copy(st->lsp_old_fx, &lsp[0], M); - Copy(lsf_q_rf, &lsf[M], M); - Copy(lsp_q_rf, &lsp[M], M); - lsp_diff = 0; - FOR( i=0; i < M; i++ ) + /* copy the old and current lsfs and lsps into the lsf[] and lsp[] buffer for interpolation */ + mvr2r(st->lsf_old, &lsf[0], M); + mvr2r(st->lsp_old, &lsp[0], M); + mvr2r(lsf_q_rf, &lsf[M], M); + mvr2r(lsp_q_rf, &lsp[M], M); + lsp_diff = 0.0f; + + for( i = 0; i < M; i++ ) { - lsp_diff = L_add(lsp_diff,(Word32)abs_s(sub(lsp[i+M],lsp[i]))); + lsp_diff += (float)fabs(lsp[i+M] - lsp[i]); } - IF( sub(st->core_fx,ACELP_CORE) == 0 && sub(st->last_core_fx,ACELP_CORE) == 0 - && L_sub(lsp_diff, 52428 ) < 0 && L_sub(lsp_diff,3932) >0 && sub(st->next_coder_type,GENERIC ) == 0 - && !st->prev_use_partial_copy && sub(st->last_coder_type_fx,UNVOICED) == 0 && sub(st->rf_frame_type,RF_GENPRED) >= 0 ) + if( st->core == ACELP_CORE && st->last_core == ACELP_CORE + && lsp_diff < 1.6f && lsp_diff > 0.12f && st->next_coder_type == GENERIC + && !st->prev_use_partial_copy && st->last_coder_type == UNVOICED && st->rf_frame_type >= RF_GENPRED) { - Copy( &lsp[0], &lsp[M], M ); + mvr2r( &lsp[0], &lsp[M], M ); } - /* update mem_MA and mem_AR memories */ - lsf_update_memory( (Word16)st->narrowBand, &lsf[M], st->mem_MA_fx, st->mem_MA_fx, M ); - Copy(&lsf[M], st->mem_AR_fx, M); + /* update mem_MA and mem_AR memories */ + lsf_update_memory( st->narrowBand, &lsf[M], st->mem_MA, st->mem_MA ); + mvr2r(&lsf[M], st->mem_AR, M); - FOR( k=0; knumlpc; ++k ) + for( k=0; knumlpc; ++k ) { - Copy( &lsp[(k+1)*M], &xspnew_uw[k*M], M ); - Copy( &lsf[(k+1)*M], &xsfnew_uw[k*M], M ); + mvr2r( &lsp[(k+1)*M], &lspnew_uw[k*M], M ); + mvr2r( &lsf[(k+1)*M], &lsfnew_uw[k*M], M ); } } - ELSE - IF ((st->enableTcxLpc !=0 && sub(st->core_fx , ACELP_CORE)!= 0) || (bfi && st->use_partial_copy && st->rf_frame_type == RF_TCXFD)) + else if( (st->enableTcxLpc && st->core != ACELP_CORE) || (bfi && st->use_partial_copy && st->rf_frame_type == RF_TCXFD) ) { - Word16 tcx_lpc_cdk; - IF(bfi && st->use_partial_copy && sub(st->rf_frame_type, RF_TCXFD) == 0) + int tcx_lpc_cdk; + + if( bfi && st->use_partial_copy && st->rf_frame_type == RF_TCXFD ) { tcx_lpc_cdk = tcxlpc_get_cdk(GENERIC); } - ELSE + else { - tcx_lpc_cdk = tcxlpc_get_cdk(*coder_type); /* inlined */ + tcx_lpc_cdk = tcxlpc_get_cdk(*coder_type); } - Copy(st->lsf_old_fx, &lsf[0], M); - Copy(st->lsp_old_fx, &lsp[0], M); + mvr2r( st->lsf_old, &lsf[0], M ); + mvr2r( st->lsp_old, &lsp[0], M ); - D_lsf_tcxlpc( param_lpc, &lsf[M], lspind, st->narrowBand, tcx_lpc_cdk, st->mem_MA_fx ); + D_lsf_tcxlpc( param_lpc, &lsf[M], lspind, st->narrowBand, tcx_lpc_cdk, st->mem_MA ); - E_LPC_lsf_lsp_conversion( &lsf[M], &lsp[M], M ); - - lsf_update_memory( (Word16)st->narrowBand, &lsf[M], st->mem_MA_fx, st->mem_MA_fx, M ); - Copy(&lsf[M], st->mem_AR_fx, M); + lsf2lsp( &lsf[M], &lsp[M], M, st->sr_core ); + lsf_update_memory( st->narrowBand, &lsf[M], st->mem_MA, st->mem_MA ); + mvr2r(&lsf[M], st->mem_AR, M); st->envWeighted = 1; - move16(); - E_LPC_lsp_unweight( &lsp[M], xspnew_uw, xsfnew_uw, st->inv_gamma, M ); + E_LPC_lsp_unweight( &lsp[M], lspnew_uw, lsfnew_uw, 1.0f/st->gamma ); } - ELSE + else { - - IF (st->envWeighted) + if( st->envWeighted ) { - Copy(st->lspold_uw, st->lsp_old_fx, M); - Copy(st->lsfold_uw, st->lsf_old_fx, M); + mvr2r( st->lspold_uw, st->lsp_old, M ); + mvr2r( st->lsfold_uw, st->lsf_old, M ); st->envWeighted = 0; - move16(); } - IF (sub(st->core_fx, TCX_20_CORE) == 0) + + /* Unquantize LPC */ + if( st->core == TCX_20_CORE ) { - lpc_unquantize( st, st->lsf_old_fx, st->lsp_old_fx, lsf, lsp, M, st->lpcQuantization, param_lpc, st->numlpc, st->core_fx, - st->mem_MA_fx, st->mem_AR_fx, lspmid, lsfmid, AUDIO, st->acelp_cfg.midLpc, st->narrowBand, &(st->seed_acelp), - st->sr_core, &st->mid_lsf_int_fx, st->prev_bfi_fx, &LSF_Q_prediction, &st->safety_net_fx ); + lpc_unquantize( st, st->lsf_old, st->lsp_old, lsf, lsp, st->lpcQuantization, param_lpc, st->numlpc, st->core, st->mem_MA, + lspmid, lsfmid, AUDIO, st->acelp_cfg.midLpc, st->narrowBand, &(st->seed_acelp), st->sr_core, + &st->mid_lsf_int, st->prev_bfi, &LSF_Q_prediction, &st->safety_net ); } - ELSE + else { - lpc_unquantize( st, st->lsf_old_fx, st->lsp_old_fx, lsf, lsp, M, st->lpcQuantization, param_lpc, st->numlpc, st->core_fx, - st->mem_MA_fx, st->mem_AR_fx, lspmid, lsfmid, *coder_type, st->acelp_cfg.midLpc, st->narrowBand, &(st->seed_acelp), - st->sr_core, &st->mid_lsf_int_fx, st->prev_bfi_fx, &LSF_Q_prediction, &st->safety_net_fx ); - IF(sub(st->prev_use_partial_copy,1)==0 && sub(st->last_core_fx,ACELP_CORE) == 0 && sub(st->core_fx,ACELP_CORE) == 0 - && sub(st->prev_rf_frame_type, RF_GENPRED) >= 0 && sub(*coder_type,UNVOICED) == 0 ) + lpc_unquantize( st, st->lsf_old, st->lsp_old, lsf, lsp, st->lpcQuantization, param_lpc, st->numlpc, st->core, st->mem_MA, + lspmid, lsfmid, *coder_type, st->acelp_cfg.midLpc, st->narrowBand, &(st->seed_acelp), st->sr_core, + &st->mid_lsf_int, st->prev_bfi, &LSF_Q_prediction, &st->safety_net ); + + if( st->prev_use_partial_copy && st->last_core == ACELP_CORE && st->core == ACELP_CORE && st->prev_rf_frame_type >= RF_GENPRED && *coder_type == UNVOICED ) { - IF ( st->lpcQuantization && st->acelp_cfg.midLpc ) + if( st->lpcQuantization && st->acelp_cfg.midLpc ) { - Copy(lspmid, &lsp[0], M ); - Copy(&lsp[M], lspmid, M ); + mvr2r( lspmid, &lsp[0], M ); + mvr2r( &lsp[M], lspmid, M ); } } } - FOR(k=0; knumlpc; ++k) + for( k=0; knumlpc; ++k ) { - Copy(&lsp[(k+1)*M], &xspnew_uw[k*M], M); - Copy(&lsf[(k+1)*M], &xsfnew_uw[k*M], M); + mvr2r( &lsp[(k+1)*M], &lspnew_uw[k*M], M ); + mvr2r( &lsf[(k+1)*M], &lsfnew_uw[k*M], M ); } } - /* PLC: [LPD: LPC concealment] - * built the moving average for the LPC concealment */ - - FOR (k=0; knumlpc; k++) + /* PLC: [LPD: LPC concealment] built the moving average for the LPC concealment */ + for( k=0; knumlpc; k++ ) { - FOR (i=0; ilsf_adaptive_mean_fx[i] = add(add(mult_r(st->lsfoldbfi1_fx[i], 10923/*1.0f/3.0f Q15*/), mult_r(st->lsfoldbfi0_fx[i], 10923/*1.0f/3.0f Q15*/)), mult_r(xsfnew_uw[k*M+i], 10923/*1.0f/3.0f Q15*/)); - move16(); - st->lsfoldbfi1_fx[i] = st->lsfoldbfi0_fx[i]; - move16(); - st->lsfoldbfi0_fx[i] = xsfnew_uw[k*M+i]; + st->lsf_adaptive_mean[i] = (st->lsfoldbfi1[i]+st->lsfoldbfi0[i]+lsfnew_uw[k*M+i])/3; + st->lsfoldbfi1[i] = st->lsfoldbfi0[i]; + st->lsfoldbfi0[i] = lsfnew_uw[k*M+i]; } } } - ELSE + else { - /* PLC: [LPD: LPC concealment] - * Conceal the LPC from the lost frame */ - st->numlpc = 2; - move16(); - test(); - if ( st->tcxonly == 0 || sub(st->core_fx, TCX_10_CORE) < 0 ) + /* PLC: [LPD: LPC concealment] Conceal the LPC from the lost frame */ + float const* lsfBase; /* base for differential lsf coding */ + + if( st->tcxonly == 0 || st->core < TCX_10_CORE ) { - move16(); st->numlpc = 1; } - IF(sub(st->nbLostCmpt,1)==0) + else { - Copy(st->lsf_old_fx, st->old_lsf_q_cng, M); - Copy(st->lsp_old_fx, st->old_lsp_q_cng, M); + st->numlpc = 2; } - move16(); - xsfBase = PlcGetLsfBase (st->lpcQuantization, - (Word16)st->narrowBand, - st->sr_core); - dlpc_bfi( st->L_frame_fx, - xsfnew_uw, - st->lsfold_uw, - st->last_good_fx, - st->nbLostCmpt, - st->mem_MA_fx, - st->mem_AR_fx, - &(st->stab_fac_fx), - st->lsf_adaptive_mean_fx, - st->numlpc, - st->lsf_cng, - st->plcBackgroundNoiseUpdated, - st->lsf_q_cng, - st->old_lsf_q_cng, - xsfBase, - st->tcxonly - ); + if( st->nbLostCmpt == 1) + { + mvr2r( st->lsf_old, st->old_lsf_q_cng, M ); + mvr2r( st->lsp_old, st->old_lsp_q_cng, M ); + } + + + lsfBase = PlcGetlsfBase( st->lpcQuantization, st->narrowBand, st->sr_core ); + + dlpc_bfi( st->L_frame, lsfnew_uw, st->lsfold_uw, st->last_good, st->nbLostCmpt, st->mem_MA, st->mem_AR, &(st->stab_fac), + st->lsf_adaptive_mean, st->numlpc, st->lsf_cng, st->plcBackgroundNoiseUpdated, st->lsf_q_cng, st->old_lsf_q_cng, lsfBase); st->envWeighted = 0; - move16(); - Copy( st->lspold_uw, lsp, M ); - Copy( st->lsfold_uw, lsf, M ); + mvr2r( st->lspold_uw, lsp, M ); + mvr2r( st->lsfold_uw, lsf, M ); - FOR ( k = 0; k < st->numlpc; k++ ) + for( k = 0; k < st->numlpc; k++ ) { - Copy( &xsfnew_uw[k*M], &lsf[(k+1)*M], M ); + mvr2r( &lsfnew_uw[k*M], &lsf[(k+1)*M], M ); - IF ( st->tcxonly ) - { - E_LPC_lsf_lsp_conversion(&lsf[(k+1)*M], &lsp[(k+1)*M], M); - E_LPC_lsf_lsp_conversion(st->lsf_q_cng, st->lsp_q_cng, M); - } - ELSE - { - lsf2lsp_fx( &lsf[(k+1)*M], &lsp[(k+1)*M], M, st->sr_core ); - lsf2lsp_fx( st->lsf_q_cng, st->lsp_q_cng, M, st->sr_core ); - } + lsf2lsp( &lsf[(k+1)*M], &lsp[(k+1)*M], M, st->sr_core ); + lsf2lsp( st->lsf_q_cng, st->lsp_q_cng, M, st->sr_core ); - Copy( &lsp[(k+1)*M], &xspnew_uw[k*M], M ); + mvr2r( &lsp[(k+1)*M], &lspnew_uw[k*M], M ); } } + /*--------------------------------------------------------------* - * Rate switching - *---------------------------------------------------------------*/ - IF( st->rate_switching_reset!=0 ) + * Rate switching + *---------------------------------------------------------------*/ + if( st->rate_switching_reset ) { - Copy( &(lsf[M]),&(lsf[0]), M ); - Copy( &(lsp[M]),&(lsp[0]), M ); - Copy( &(lsf[M]),st->lsf_old_fx, M ); - Copy( &(lsp[M]),st->lsp_old_fx, M ); - Copy( &(lsf[M]),lsfmid, M ); - Copy( &(lsp[M]),lspmid, M ); - E_LPC_f_lsp_a_conversion(st->lsp_old_fx, st->old_Aq_12_8_fx, M); + mvr2r( &(lsf[M]),&(lsf[0]), M ); + mvr2r( &(lsp[M]),&(lsp[0]), M ); + mvr2r( &(lsf[M]),st->lsf_old, M ); + mvr2r( &(lsp[M]),st->lsp_old, M ); + mvr2r( &(lsf[M]),lsfmid, M ); + mvr2r( &(lsp[M]),lspmid, M ); + lsp2a_stab( st->lsp_old, st->old_Aq_12_8, M ); } - - IF(st->enablePlcWaveadjust) + if(st->enablePlcWaveadjust) { - if(sub(st->core_fx, ACELP_CORE) == 0) + if (st->core == ACELP_CORE) { st->tonality_flag = 0; - move16(); } - if(bfi) + if (bfi) { st->plcInfo.nbLostCmpt++; - move16(); } } /*--------------------------------------------------------------------------------* * ACELP *--------------------------------------------------------------------------------*/ - test(); - test(); - test(); - IF( (st->prev_bfi_fx!=0) && (bfi==0) && (sub(*coder_type,VOICED)==0) && sub(st->prev_nbLostCmpt,4)>0 ) + + + if( (st->prev_bfi!=0) && (bfi==0) && (*coder_type==VOICED) && (st->prev_nbLostCmpt>4) ) { st->dec_glr_idx = 1; - move16(); st->reset_mem_AR = 1; - move16(); } - IF ( st->core_fx == ACELP_CORE ) + if( st->core == ACELP_CORE ) { - IF (st->tcxonly==0) + if( !st->tcxonly ) { /* Set pointer to parameters */ prm = param; /* Stability Factor */ - IF ( bfi == 0 ) + if( !bfi ) { - st->stab_fac_fx = lsf_stab_fx(&lsf[M], &lsf[0], 0, st->L_frame_fx); + st->stab_fac = lsf_stab( &lsf[M], &lsf[0], 0, st->L_frame ); } - test(); - IF( bfi==0 && st->prev_bfi_fx != 0 ) + if( !bfi && st->prev_bfi ) { /* check if LSP interpolation can be relaxed or if LPC power can be diffused*/ - E_LPC_f_lsp_a_conversion(&lsp[0], tmp_old, M); - enr_old = Enr_1_Az_fx(tmp_old, 2*L_SUBFR); + lsp2a_stab( &lsp[0], tmp_old, M); + enr_old = enr_1_Az( tmp_old, 2*L_SUBFR ); - E_LPC_f_lsp_a_conversion(&lsp[M], tmp_new, M); - enr_new = Enr_1_Az_fx(tmp_new, 2*L_SUBFR); + lsp2a_stab( &lsp[M], tmp_new, M); + enr_new = enr_1_Az( tmp_new, 2*L_SUBFR ); } - test(); - test(); - test(); - test(); - IF( (bfi == 0) && ((sub(st->dec_glr_idx, 1) == 0) || ((st->safety_net_fx==0) && (shr(enr_new,11) > 0) && (sub(shr(enr_new,1),enr_old)>0))) && (st->prev_bfi_fx != 0 ) ) + if( !bfi && (st->dec_glr_idx == 1 || (!(st->safety_net) && enr_new>=256.f && enr_new > 2*enr_old)) && st->prev_bfi ) { - Word16 reset_q = 0; - if( sub(st->dec_glr_idx, 1) == 0 ) - { - reset_q = 1; - move16(); - } - RecLpcSpecPowDiffuseLc( &lsp[M], &lsp[0], &lsf[M], st, reset_q); - - int_lsp_fx( L_frame, &lsp[0], &lsp[M], Aq, M, interpol_frac_fx, 0 ); - - Copy(&lsf[M], xsfnew_uw, M); + RecLpcSpecPowDiffuseLc( &lsp[M], &lsp[0], &lsf[M], st, st->dec_glr_idx == 1 ? 1 : 0 ); + int_lsp( L_frame, &lsp[0], &lsp[M], Aq, M, interpol_frac_12k8, 0 ); + mvr2r( &lsf[M], lsfnew_uw, M ); } - ELSE + else { /* LPC Interpolation for ACELP */ - test(); - IF ( bfi==0 && st->acelp_cfg.midLpc ) + if( !bfi && st->acelp_cfg.midLpc ) { - st->relax_prev_lsf_interp_fx = 0; - move16(); - IF (st->prev_bfi_fx) + st->relax_prev_lsf_interp = 0; + + if( st->prev_bfi ) { /* check if LSP interpolation can be relaxed */ - IF ( sub(enr_new, shr(enr_old, 2)) < 0 ) + if ( enr_new < (0.25f * enr_old) ) { - st->relax_prev_lsf_interp_fx = -1; - move16(); - test(); - test(); - test(); - test(); - if ( sub(st->clas_dec, UNVOICED_CLAS) == 0 || sub(st->clas_dec, SIN_ONSET) == 0 || sub(st->clas_dec, INACTIVE_CLAS) == 0 || sub(*coder_type, GENERIC) == 0 || sub(*coder_type, TRANSITION) == 0 ) + /* don't use safety_net as this is getting impacted with lsf_restruct */ + if ( (st->clas_dec == UNVOICED_CLAS) || (st->clas_dec == SIN_ONSET) || (st->clas_dec == INACTIVE_CLAS) || (*coder_type == GENERIC) || (*coder_type == TRANSITION) ) { - st->relax_prev_lsf_interp_fx = 1; - move16(); + st->relax_prev_lsf_interp = 1; + } + else + { + st->relax_prev_lsf_interp = -1; } } } - test(); - test(); - test(); - test(); - if (st->stab_fac_fx == 0 && st->old_bfi_cnt_fx > 0 && sub(st->clas_dec, VOICED_CLAS) != 0 && sub(st->clas_dec, ONSET) != 0 && st->relax_prev_lsf_interp_fx == 0 ) + if( st->stab_fac == 0 && st->old_bfi_cnt > 0 && st->clas_dec != VOICED_CLAS && st->clas_dec != ONSET && st->relax_prev_lsf_interp == 0 ) { - st->relax_prev_lsf_interp_fx = 2; - move16(); + st->relax_prev_lsf_interp = 2; } - int_lsp4_fx( L_frame, &lsp[0], lspmid, &lsp[M], Aq, M, st->relax_prev_lsf_interp_fx ); + int_lsp4( L_frame, &lsp[0], lspmid, &lsp[M], Aq, M, st->relax_prev_lsf_interp ); } - ELSE + else { - int_lsp_fx( L_frame, &lsp[0], &lsp[M], Aq, M, interpol_frac_fx, 0 ); - int_lsp_fx( L_frame, st->old_lsp_q_cng, st->lsp_q_cng, st->Aq_cng, M, interpol_frac_fx, 0 ); + int_lsp( L_frame, &lsp[0], &lsp[M], Aq, M, interpol_frac_12k8, 0 ); + int_lsp( L_frame, st->old_lsp_q_cng, st->lsp_q_cng, st->Aq_cng, M, interpol_frac_12k8, 0 ); } } } - test(); - IF (bfi!=0 && st->last_core_fx != ACELP_CORE) + if( bfi && st->last_core != ACELP_CORE ) { /* PLC: [TCX: TD PLC] */ con_tcx( st, &synthFB[0] ); - lerp( synthFB, synth, st->L_frame_fx, st->L_frameTCX ); + lerp(synthFB, synth, st->L_frame, st->L_frameTCX); st->con_tcx = 1; - move16(); - set16_fx (st->mem_pitch_gain+2,round_fx(L_shl(st->Mode2_lp_gainp , 1)), st->nb_subfr); + set_f( &st->mem_pitch_gain[2], st->lp_gainp, st->nb_subfr); } - ELSE + else { /* ACELP decoder */ - IF (sub(st->L_frame_fx,L_FRAME)== 0) + if (st->L_frame == L_FRAME) { - Copy(Aq+2*(M+1), st->cur_sub_Aq_fx, (M+1)); + mvr2r(Aq+2*(M+1), st->cur_sub_Aq, (M+1)); } - ELSE + else { - Copy(Aq+3*(M+1), st->cur_sub_Aq_fx, (M+1)); + mvr2r(Aq+3*(M+1), st->cur_sub_Aq, (M+1)); } - IF ( bfi != 0 ) + + if( bfi ) { /* PLC: [ACELP: general] * PLC: Use the ACELP like concealment */ - con_acelp(Aq, - st->core_ext_mode, - &synth[0], - pitch, - pit_gain, - st->stab_fac_fx, - st, - &st->Q_exc, - &st->Q_syn, /*Q format of st->mem_syn*/ - pitch_buf, - voice_factors, - ptr_bwe_exc - ); - - Copy(&st->mem_pitch_gain[2], &st->mem_pitch_gain[st->nb_subfr+2], st->nb_subfr); - set16_fx(&st->mem_pitch_gain[2],0,st->nb_subfr); + con_acelp( Aq, st->core_ext_mode, &synth[0], pitch, pit_gain, st->stab_fac, st, pitch_buf, voice_factors, ptr_bwe_exc ); + mvr2r( &st->mem_pitch_gain[2], &st->mem_pitch_gain[st->nb_subfr+2], st->nb_subfr ); + set_zero( &st->mem_pitch_gain[2],st->nb_subfr ); } - ELSE + else { - decoder_acelp(st, *coder_type, prm, Aq, st->acelp_cfg, &synth[0], - pitch, pit_gain, st->stab_fac_fx, pitch_buf, voice_factors, LSF_Q_prediction, ptr_bwe_exc); - IF(st->flagGuidedAcelp > 0) + decoder_acelp( st, *coder_type, prm, Aq, st->acelp_cfg, &synth[0], pitch, pit_gain, st->stab_fac, pitch_buf, voice_factors, LSF_Q_prediction, ptr_bwe_exc ); + + if( st->flagGuidedAcelp > 0 ) { - st->guidedT0 = s_max(s_min(add(st->T0_4th, st->guidedT0), NBPSF_PIT_MAX), PIT_MIN_16k); + st->guidedT0 = max(min(st->T0_4th + st->guidedT0, NBPSF_PIT_MAX), PIT_MIN_16k); } - FOR (i=0; inb_subfr; i++) + for (i = 0; i < st->nb_subfr; i++) { - move16(); - move16(); st->mem_pitch_gain[2+(2*st->nb_subfr-1)-i] = st->mem_pitch_gain[2+ (st->nb_subfr-1) -i]; st->mem_pitch_gain[2+(st->nb_subfr-1)-i] = pit_gain[i]; } } } - /* LPC for ACELP/BBWE */ - test(); - test(); - IF( st->narrowBand || (L_sub(st->sr_core, 12800) == 0) || (L_sub(st->sr_core, 16000) == 0) ) + if( st->narrowBand || st->sr_core==12800 || st->sr_core==16000 ) { - Copy(Aq, st->mem_Aq, nb_subfr*(M+1)); + mvr2r( Aq, st->mem_Aq, nb_subfr*(M+1) ); } /* PLC: [TCX: Tonal Concealment] */ /* Signal that this frame is not TCX */ - TonalMDCTConceal_UpdateState(&st->tonalMDCTconceal, 0, 0, 0, 0); + TonalMDCTConceal_UpdateState( &st->tonalMDCTconceal, 0, 0, 0, 0 ); - IF (bfi==0) + if( !bfi ) { st->second_last_tns_active = st->last_tns_active; st->last_tns_active = 0; - st->tcxltp_last_gain_unmodified = 0; - move16(); + st->tcxltp_last_gain_unmodified = 0.0f; } } @@ -652,77 +523,54 @@ void decoder_LPD( * TCX20 *--------------------------------------------------------------------------------*/ - IF ( sub(st->core_fx, TCX_20_CORE) == 0 ) + + if( st->core == TCX_20_CORE ) { /* Set pointer to parameters */ prm = param; /* Stability Factor */ - IF ( bfi == 0 ) + if( !bfi ) { - IF ( st->tcxonly != 0 ) - { - st->stab_fac_fx = lsf_stab_fx(&lsf[M], &lsf[0],0, L_FRAME); - } - ELSE - { - st->stab_fac_fx = lsf_stab_fx(&lsf[M], &lsf[0],0, st->L_frame_fx); - } + st->stab_fac = lsf_stab( &lsf[M], &lsf[0], 0, st->L_frame ); } - IF (st->enableTcxLpc) + if (st->enableTcxLpc) { - /* Convert quantized xSP to A */ - E_LPC_f_lsp_a_conversion(&lsp[M], Aq, M); + /* Convert quantized lsp to A */ + lsp2a_stab( &lsp[M], Aq, M ); } - ELSE + else { - IF (st->tcxonly == 0) + if (!st->tcxonly) { - test(); - test(); - test(); - IF( (bfi == 0) && (st->prev_bfi_fx != 0 ) && (st->safety_net_fx==0) && (st->rate_switching_reset != 0) ) + if( !bfi && st->prev_bfi && !(st->safety_net) && st->rate_switching_reset ) { /* diffuse LPC power on rate switching*/ RecLpcSpecPowDiffuseLc( &lsp[M], &lsp[0], &lsf[M], st, 0 ); - int_lsp_fx( L_frame, &lsp[0], &lsp[M], Aq, M, interpol_frac_fx, 0 ); - Copy(&lsf[M], xsfnew_uw, M); + int_lsp( L_frame, &lsp[0], &lsp[M], Aq, M, interpol_frac_12k8, 0 ); + mvr2r( &lsf[M], lsfnew_uw, M ); } - ELSE + else { /* LPC Interpolation for TCX */ - E_LPC_int_lpc_tcx(&lsp[0], &lsp[M], Aq); + E_LPC_int_lpc_tcx( &lsp[0], &lsp[M], Aq ); } } - ELSE + else { - E_LPC_f_lsp_a_conversion(&lsp[M], Aq, M); + lsp2a_stab( &lsp[M], Aq, M ); } } - test(); - IF ( bfi == 0 && st->tcx_lpc_shaped_ari != 0 ) + if( !bfi && st->tcx_lpc_shaped_ari ) { - E_LPC_f_lsp_a_conversion(lspind, Aind, M); + basop_E_LPC_f_lsp_a_conversion(lspind, Aind, M); } /* TCX decoder */ - decoder_tcx(&st->tcx_cfg, - prm, - Aq, - Aind, - L_frame, - L_frameTCX, - st->tcx_cfg.tcx_coded_lines, - &synth[0], - &synthFB[0], - st, - *coder_type, - bfi, - 0, - st->stab_fac_fx - ); + decoder_tcx( &st->tcx_cfg, prm, Aq, Aind, L_frame, L_frameTCX, st->tcx_cfg.tcx_coded_lines, + &synth[0], &synthFB[0], st, *coder_type, bfi, 0, st->stab_fac ); } @@ -730,291 +578,205 @@ void decoder_LPD( * TCX10 *--------------------------------------------------------------------------------*/ - IF ( sub(st->core_fx, TCX_10_CORE) == 0 ) + if( st->core == TCX_10_CORE ) { - FOR (k=0; k<2; k++) - { + prm = NULL; /* just to avoid MSVC warnings */ + for (k=0; k<2; k++) + { /* Set pointer to parameters */ prm = param + (k*DEC_NPRM_DIV); /* Stability Factor */ - IF ( bfi==0 ) + if( !bfi ) { - st->stab_fac_fx = lsf_stab_fx(&lsf[(k+1)*M], &lsf[k*M],0, L_FRAME); + st->stab_fac = lsf_stab( &lsf[(k+1)*M], &lsf[k*M], 0, st->L_frame ); } - E_LPC_f_lsp_a_conversion(&lsp[(k+1)*M], Aq, M); + lsp2a_stab( &lsp[(k+1)*M], Aq, M ); + IGFDecRestoreTCX10SubFrameData( &st->hIGFDec, k ); /* TCX decoder */ - - IGFDecRestoreTCX10SubFrameData( &st->hIGFDec, k ); - decoder_tcx(&st->tcx_cfg, - prm, - Aq, - Aind, - shr(L_frame, 1), - shr(L_frameTCX, 1), - shr(st->tcx_cfg.tcx_coded_lines, 1), - &synth[k*L_frame/2], - &synthFB[k*L_frameTCX/2], - st, - *coder_type, - bfi, - k, - st->stab_fac_fx - ); + decoder_tcx( &st->tcx_cfg, prm, Aq, Aind, L_frame/2, L_frameTCX/2, st->tcx_cfg.tcx_coded_lines/2, + &synth[k*L_frame/2], &synthFB[k*L_frameTCX/2], st, *coder_type, bfi, k, st->stab_fac ); } } - - test(); - IF (sub(st->core_fx, TCX_10_CORE) == 0 || sub(st->core_fx, TCX_20_CORE) == 0) + if (st->core == TCX_10_CORE || st->core == TCX_20_CORE) { - test(); - test(); - IF(st->enablePlcWaveadjust || /* bfi */ - (L_sub(st->last_total_brate_fx, HQ_48k) >= 0 && /* recovery */ - sub(st->last_codec_mode, MODE2) == 0) ) + if( st->enablePlcWaveadjust || /* bfi */ + ( st->last_total_brate >= HQ_48k && /* recovery */ + st->last_codec_mode == MODE2 ) ) { /* waveform adjustment */ - concealment_signal_tuning_fx( bfi, st->core_fx, - synthFB, &st->plcInfo, st->nbLostCmpt, st->prev_bfi_fx, - st->tonalMDCTconceal.secondLastPcmOut, - past_core_mode,st->tonalMDCTconceal.lastPcmOut, st ); - test(); - test(); - test(); - IF ((bfi || st->prev_bfi_fx) && st->plcInfo.Pitch_fx && (sub(st->plcInfo.concealment_method, TCX_NONTONAL) == 0)) + concealment_signal_tuning( bfi, st->core, synthFB, &st->plcInfo, st->nbLostCmpt, st->prev_bfi, + st->tonalMDCTconceal.secondLastPcmOut, past_core_mode,st->tonalMDCTconceal.lastPcmOut, st ); + + if( (bfi || st->prev_bfi) && st->plcInfo.Pitch && st->plcInfo.concealment_method == TCX_NONTONAL ) { lerp( synthFB, synth, L_frame, L_frameTCX ); - test(); - if( !bfi && st->prev_bfi_fx ) + + if( !bfi && st->prev_bfi ) { - st->plcInfo.Pitch_fx = 0; - move16(); + st->plcInfo.Pitch = 0; } } } - IF (!bfi) + if (!bfi) { TonalMDCTConceal_SaveTimeSignal( &st->tonalMDCTconceal, synthFB, L_frameTCX ); } + decoder_tcx_post( st, synth, synthFB, Aq, bfi ); - IF (sub(st->core_fx, TCX_20_CORE) == 0) + if( st->core == TCX_20_CORE ) { /* LPC Interpolation for BBWE/post-processing */ - test(); - test(); - IF( st->narrowBand || (L_sub(st->sr_core, 12800) == 0) || (L_sub(st->sr_core, 16000) == 0) ) + if( st->narrowBand || st->sr_core==12800 || st->sr_core==16000 ) { - int_lsp_fx( L_frame, st->lspold_uw, xspnew_uw, Aq, M, interpol_frac_fx, 0 ); - Copy(Aq, st->mem_Aq, nb_subfr*(M+1)); + int_lsp( L_frame, st->lspold_uw, lspnew_uw, Aq, M, interpol_frac_12k8, 0 ); + mvr2r( Aq, st->mem_Aq, nb_subfr*(M+1) ); } } } + /* PLC: [Common: Classification] */ - - IF( L_sub( st->sr_core, 16000) <= 0 ) + /* the classifier buffer is always updated if the sr is at + 16000 or below - the classification itself is just performed if(!st->tcxonly ) */ + if( st->sr_core <= 16000 ) { - test(); - test(); - test(); - IF ( sub(st->core_fx, TCX_20_CORE) == 0 || sub(st->core_fx, TCX_10_CORE) == 0 || (st->tcxonly && st->bfi_fx) ) + if( st->core == TCX_20_CORE || st->core == TCX_10_CORE || (st->tcxonly && st->bfi) ) { - Word16 pitch_C[NB_SUBFR16k]; - Word16 core_ext_mode, LTP_Gain; + float pitch_C[4]; - set16_fx(pitch_C, shl(round_fx(st->old_fpitch), 6), NB_SUBFR16k); - - core_ext_mode = GENERIC; - move16(); - if(st->tcxonly == 0) - { - core_ext_mode = st->core_ext_mode; - move16(); - } - - LTP_Gain = -32768/*-1.0f Q15*/; - if(st->tcxltp) - { - LTP_Gain = st->tcxltp_last_gain_unmodified; - move16(); - } - - - FEC_clas_estim_fx( - st, - /*Opt_AMR_WB*/0, /*A*/ - st->L_frame_fx, - &(st->clas_dec), - core_ext_mode, - pitch_C, - synth, - &st->lp_ener_FER_fx, - /**decision_hyst*/NULL, /* i/o: hysteresis of the music/speech decision */ - /**UV_cnt*/ NULL, /* i/o: number of consecutive frames classified as */ - /**LT_UV_cnt*/ NULL, /* i/o: long term consecutive frames classified as UV */ - /**Last_ener*/ NULL, /* i/o: last_energy frame */ - /**locattack*/ NULL, /* i/o: detection of attack (mainly to localized speech burst) */ - /**lt_diff_etot*/NULL, /* i/o: long-term total energy variation */ - /**amr_io_class*/ NULL, /* i/o: classification for AMR-WB IO mode */ - /*bitrate*/ 0 , /* i : Decoded bitrate */ - 0, /* i : Synthesis scaling */ - /**class_para*/ NULL, /* o : classification para. fmerit1 */ - st->mem_syn_clas_estim_fx, /* i/o: memory of the synthesis signal for frame class estimation */ - &st->classifier_Q_mem_syn, /* i/o: exponent for memory of synthesis signal for frame class estimation */ - LTP_Gain, /* i : means LTP Gain */ - 1 /*CLASSIFIER_TCX*/, /* i : signal classifier mode */ - bfi, /* i : bad frame indicator */ - st->last_core_brate_fx /* i : bitrate of previous frame */ - ); + /* note: the classifier needs the pitch only for tcx_only == 0 , i.e. not for TCX10 */ + pitch_C[0] = pitch_C[1] = pitch_C[2] = pitch_C[3] = (float)floor(st->old_fpitch+0.5f); + FEC_clas_estim( synth, pitch_C, st->L_frame, st->tcxonly? GENERIC : st->core_ext_mode, st->codec_mode, st->mem_syn_clas_estim, + &st->clas_dec, &st->lp_ener_bfi, st->core_brate, 0, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, + st->tcxltp ? st->tcxltp_last_gain_unmodified : -1.0f, st->narrowBand, (SIGNAL_CLASSIFIER_MODE)1, + bfi, st->preemph_fac, st->tcxonly, st->last_core_brate ); } } + + + /*--------------------------------------------------------------------------------* - * END + * Updates *--------------------------------------------------------------------------------*/ - test(); - IF( bfi && sub(st->last_core_bfi , ACELP_CORE) != 0 ) + + if( bfi && st->last_core != ACELP_CORE ) { /* Update FEC_scale_syn parameters */ - IF(st->tcxltp_gain == 0) + if (st->tcxltp_gain == 0) { - frame_ener_fx( L_frame, UNVOICED_CLAS, synth, shr(L_frame,1), &st->enr_old_fx, L_frame, 0, 0, 0 ); + fer_energy( L_frame, UNVOICED, synth, L_frame/2, &st->enr_old, L_frame ); } - ELSE + else { - Word16 pitch_Q0; - pitch_Q0 = round_fx(st->old_fpitch); - frame_ener_fx( L_frame, st->clas_dec, synth, pitch_Q0, &st->enr_old_fx, L_frame, 0, 0, 0 ); + fer_energy( L_frame, st->clas_dec, synth, st->old_fpitch, &st->enr_old, L_frame ); } } - - test(); - test(); - IF(!bfi && sub(st->clas_dec, VOICED_TRANSITION) >= 0 && sub(st->clas_dec, INACTIVE_CLAS) < 0) + if( !bfi && st->clas_dec >= VOICED_TRANSITION && st->clas_dec < INACTIVE_CLAS) { - Word16 offset; + short offset; - IF(sub(st->core_fx, ACELP_CORE)==0) + if( st->core == ACELP_CORE ) { - offset = sub(st->nb_subfr,1); - offset = imult1616(offset,add(M,1)); + offset = (st->nb_subfr-1)*(M+1); } - ELSE + else { + /* TCX */ offset = 0; - move16(); } + /* use latest LPC set */ - st->old_enr_LP = Enr_1_Az_fx(Aq+offset, L_SUBFR); /*Q3*/ + st->old_enr_LP = enr_1_Az( Aq+offset, L_SUBFR ); } /* Update */ - Copy(synth_buf+L_frame, st->old_synth, st->old_synth_len); + mvr2r( synth_buf+L_frame, st->old_synth, st->old_synth_len ); + mvr2r( st->old_synthFB + L_frameTCX - NS2SA(st->output_Fs, PH_ECU_MEM_NS), st->synth_history, NS2SA(st->output_Fs, PH_ECU_MEM_NS) ); + mvr2r( synth_bufFB+L_frameTCX, st->old_synthFB, st->old_synth_lenFB ); + mvr2r( st->old_out+NS2SA(st->output_Fs,N_ZERO_MDCT_NS), st->old_synthFB+st->old_synth_lenFB, NS2SA(st->output_Fs, PH_ECU_LOOKAHEAD_NS)); - Copy( st->old_synthFB_fx + L_frameTCX - NS2SA_fx2(st->output_Fs_fx, PH_ECU_MEM_NS), st->synth_history_fx, NS2SA_fx2(st->output_Fs_fx, PH_ECU_MEM_NS) ); - Copy(synth_bufFB+L_frameTCX, st->old_synthFB_fx, st->old_synth_lenFB); - Copy_Scale_sig( st->old_out_fx+NS2SA_fx2(st->output_Fs_fx, N_ZERO_MDCT_NS), st->old_synthFB_fx+st->old_synth_lenFB, NS2SA_fx2(st->output_Fs_fx, PH_ECU_LOOKAHEAD_NS), negate(st->Q_old_wtda)); + mvr2r( &lspnew_uw[(st->numlpc-1)*M], st->lspold_uw, M ); + mvr2r( &lsfnew_uw[(st->numlpc-1)*M], st->lsfold_uw, M ); - - Copy(&xspnew_uw[(st->numlpc-1)*M], st->lspold_uw, M); - Copy(&xsfnew_uw[(st->numlpc-1)*M], st->lsfold_uw, M); - - IF (bfi) + if( bfi == 1 ) { - Copy(st->lspold_uw, st->lsp_old_fx, M); /* for recovery */ - Copy(st->lsfold_uw, st->lsf_old_fx, M); /* for recovery */ + mvr2r( st->lspold_uw, st->lsp_old, M ); /* for recovery */ + mvr2r( st->lsfold_uw, st->lsf_old, M ); /* for recovery */ } - ELSE + else { - Copy(&lsp[st->numlpc*M], st->lsp_old_fx, M); - Copy(&lsf[st->numlpc*M], st->lsf_old_fx, M); + mvr2r( &lsp[st->numlpc*M], st->lsp_old, M ); + mvr2r( &lsf[st->numlpc*M], st->lsf_old, M ); } - Copy(st->lsp_q_cng, st->old_lsp_q_cng, M); - Copy(st->lsf_q_cng, st->old_lsf_q_cng, M); + mvr2r( st->lsp_q_cng, st->old_lsp_q_cng, M ); + mvr2r( st->lsf_q_cng, st->old_lsf_q_cng, M ); - /* Update LP_CNG parameters */ - IF( st->tcxonly == 0 ) + /* Update MODE1 CNG parameters */ + if( !st->tcxonly ) { /* update CNG parameters in active frames */ - IF (sub(st->bwidth_fx,NB) == 0 && st->enableTcxLpc !=0 && sub(st->core_fx , ACELP_CORE)!= 0) + if ( st->bwidth == NB && st->enableTcxLpc && st->core != ACELP_CORE ) { - Word16 buf[L_LP], res[L_FRAME], A[M+1], Qexc, r_l[M+1], r_h[M+1], lsptmp[M], Q_r, tmp; - - assert(st->L_frame_fx==L_FRAME); - Copy(synth+L_FRAME-L_LP, buf, L_LP); + float buf[L_LP], res[L_FRAME], A[M+1], r[M+1], tmp, lsptmp[M]; + assert(st->L_frame==L_FRAME); + mvr2r(synth+L_FRAME-L_LP, buf, L_LP); tmp = synth[L_FRAME-L_LP-1]; - Qexc = E_UTIL_f_preemph3(buf, st->preemph_fac, L_LP, &tmp, 1); - autocorr_fx( buf, M, r_h, r_l, &Q_r, L_LP, Assym_window_W16fx, 0, 0 ); - lag_wind(r_h, r_l, M, INT_FS_FX, LAGW_WEAK); - E_LPC_lev_dur(r_h, r_l, A, NULL, M, NULL); - E_LPC_a_lsp_conversion(A, lsptmp, &xspnew_uw[0], M); - Residu3_fx(A, buf+L_LP-L_FRAME, res, L_FRAME, 1); - cng_params_upd_fx( lsptmp, res, st->L_frame_fx, &st->ho_circ_ptr_fx, - st->ho_ener_circ_fx, &st->ho_circ_size_fx, st->ho_lsp_circ_fx, - Qexc, DEC, st->ho_env_circ_fx, NULL, NULL, NULL, NULL, st->last_active_brate_fx ); + preemph(buf, st->preemph_fac, L_LP, &tmp); + autocorr( buf, r, M, L_LP, LP_assym_window, 0, 0, 0 ); + lag_wind(r, M, INT_FS_12k8, LAGW_WEAK); + lev_dur( A, r, M, NULL ); + a2lsp_stab( A, lsptmp, &lspnew_uw[0] ); + residu(A, M, buf+L_LP-L_FRAME, res, L_FRAME ); + + cng_params_upd( lsptmp, res, st->L_frame, &st->ho_circ_ptr, st->ho_ener_circ, &st->ho_circ_size, st->ho_lsp_circ, + DEC, st->ho_env_circ, NULL, NULL, NULL, st->last_active_brate ); } - ELSE + else { - cng_params_upd_fx( &lsp[M], st->old_exc_fx+L_EXC_MEM_DEC-st->L_frame_fx, - st->L_frame_fx, &st->ho_circ_ptr_fx, st->ho_ener_circ_fx, - &st->ho_circ_size_fx, st->ho_lsp_circ_fx, st->Q_exc, DEC, - st->ho_env_circ_fx, NULL, NULL, NULL, NULL, st->last_active_brate_fx ); + cng_params_upd( &lsp[M], st->old_exc+L_EXC_MEM_DEC-st->L_frame, st->L_frame, &st->ho_circ_ptr, st->ho_ener_circ, + &st->ho_circ_size, st->ho_lsp_circ, DEC, st->ho_env_circ, NULL, NULL, NULL, st->last_active_brate ); } /* Set 16k LSP flag for CNG buffer */ - st->ho_16k_lsp_fx[st->ho_circ_ptr_fx] = 1; - move16(); - if ( sub(st->L_frame_fx,L_FRAME) == 0 ) - { - st->ho_16k_lsp_fx[st->ho_circ_ptr_fx] = 0; - move16(); - } + st->ho_16k_lsp[st->ho_circ_ptr] = (st->L_frame == L_FRAME ? 0 : 1 ); } - move16(); st->last_is_cng = 0; /* Postfiltering */ - post_decoder( st, - *coder_type, - synth_buf, - pit_gain, - pitch, - signal_out, - bpf_noise_buf - ); + post_decoder( st, *coder_type, synth_buf, pit_gain, pitch, signal_out, bpf_noise_buf ); - IF( signal_outFB ) + if( signal_outFB ) { - Copy( synthFB, signal_outFB, L_frameTCX ); + mvr2r( synthFB, signal_outFB, L_frameTCX ); } - IF( st->enablePlcWaveadjust) + if( st->enablePlcWaveadjust) { if(!bfi) { - st->plcInfo.nbLostCmpt = L_deposit_l(0); + st->plcInfo.nbLostCmpt = 0; } - IF (st->core_fx == 0) + if( st->core == ACELP_CORE ) /* may happen only if bfi==1 */ { - set_state(st->plcInfo.Transient, st->core_fx, MAX_POST_LEN); + set_state( st->plcInfo.Transient, st->core, MAX_POST_LEN ); } } return; } - - diff --git a/src/libs/libevs/lib_dec/dec_ace.cpp b/src/libs/libevs/lib_dec/dec_ace.cpp old mode 100755 new mode 100644 index 340793f8..71392495 --- a/src/libs/libevs/lib_dec/dec_ace.cpp +++ b/src/libs/libevs/lib_dec/dec_ace.cpp @@ -1,16 +1,15 @@ /*==================================================================================== - EVS Codec 3GPP TS26.442 Apr 03, 2018. Version 12.11.0 / 13.6.0 / 14.2.0 + EVS Codec 3GPP TS26.443 Nov 13, 2018. Version 12.11.0 / 13.7.0 / 14.3.0 / 15.1.0 ====================================================================================*/ -/*BASOp version info: This file is up to date with trunk rev. 39929 */ - #include #include +#include #include +#include "prot.h" #include "options.h" -#include "prot_fx.h" -#include "basop_util.h" -#include "stl.h" +#include "rom_com.h" + /*-------------------------------------------------------------------* * decoder_acelp() @@ -19,216 +18,171 @@ *-------------------------------------------------------------------*/ void decoder_acelp( - Decoder_State_fx *st, - Word16 coder_type, /* i : coder type */ - Word16 prm[], /* i : parameters */ - Word16 A[], /* i : coefficients NxAz[M+1] */ - ACELP_config acelp_cfg, /* i : ACELP config */ - Word16 synth[], /* i/o: synth[-2*LFAC..L_DIV] Q0 */ - Word16 *pT, /* o : pitch for all subframe Q0 */ - Word16 *pgainT, /* o : pitch gain for all subfr 1Q14 */ - Word16 stab_fac, /* i : stability of isf */ - Word16 *pitch_buffer, /* o : pitch values for each subfr. */ - Word16 *voice_factors, /* o : voicing factors */ - const Word16 LSF_Q_prediction, /* i : LSF prediction mode */ - Word16 *bwe_exc /* o : excitation for SWB TBE */ + Decoder_State *st, /* i/o: coder memory state */ + const short coder_type, /* i : coder type */ + int prm[], /* i : parameters */ + const float A[], /* i : coefficients NxAz[M+1] */ + ACELP_config acelp_cfg, /* i : ACELP config */ + float synth[], /* i/o: synthesis */ + int *pT, /* o : pitch for all subframe */ + float *pgainT, /* o : pitch gain for all subfr */ + const float stab_fac, /* i : stability of isf */ + float *pitch_buffer, /* i/o: pitch values for each subfr.*/ + float *voice_factors, /* o : voicing factors */ + const short LSF_Q_prediction,/* i : LSF prediction mode */ + float *bwe_exc /* o : excitation for SWB TBE */ ) { - Word16 i, j, i_subfr; - Word16 T0, T0_frac, T0_min, T0_min_frac, T0_max, T0_max_frac, T0_res; - Word16 tmp, tmp2, gain_pit/*Q14*/, Es_pred, tmp_deemph; - Word32 Ltmp, Ltmp2, gain_code; - Word16 code[L_SUBFR]; - Word16 mem_syn[M]; - Word16 *syn, syn_buf[M+L_DIV_MAX+L_DIV_MAX/2]; - Word16 *exc, exc_buf[L_EXC_MEM_DEC+L_DIV_MAX+1]; - Word16 exc2[L_FRAME_16k]; - Word16 *p_A; - Word32 pitch_buf[NB_SUBFR16k]; - Word16 dummy_pitch_buf[NB_SUBFR16k]; - Word16 gain_inov; - Word16 mem_back[M]; - Word16 update_flg; - Word16 Q_mem_back; /*Q format of mem_back*/ - Word16 h1[L_FRAME_16k/4+1]; - Word16 mem[M]; - Word16 *pA; + short i, i_subfr, L_frame; + int T0, T0_frac, T0_min, T0_min_frac, T0_max, T0_max_frac, T0_res; + float tmp, gain_pit, gain_code, Es_pred; + float code[L_SUBFR]; + float mem_syn[M], *syn, syn_buf[M+L_FRAME16k+L_FRAME16k/2]; + float *exc, exc_buf[L_EXC_MEM_DEC+L_FRAME16k+1]; + float exc2[L_FRAME16k]; + const float *p_A; + float *pt_pitch, pitch_buf[NB_SUBFR16k]; + float gain_inov; + float mem_back[M]; + float h1[L_FRAME16k/4+1]; + float mem[M]; + const float *pA; + float gain_code2; + float code2[L_SUBFR]; + short lp_flag; + int offset; + float error = 0.0f; + float gain_preQ = 0; /* Gain of prequantizer excitation */ + float code_preQ[L_SUBFR]; /* Prequantizer excitation */ PulseConfig config; - Word16 weights[5]; /* Q15 */ + float weights[5]; - Word16 reScaleLen_fx; /* rescaling length for the BWE buffers */ - Word16 reSampLen; + float prev_gain_pit; + float tmp_noise; /* Long term temporary noise energy */ - /*Q formats of buffers */ - Word16 prev_Q_syn; - Word32 gain_code2=0; - Word16 code2[L_SUBFR]; - Word16 error = 0; - Word16 gain_preQ = 0; /* Gain of prequantizer excitation */ - Word16 code_preQ[L_SUBFR]; /* Prequantizer excitation */ - Word16 lp_flag; - - - Word16 prev_gain_pit; - Word16 tmp_noise; /* Long term temporary noise energy */ - Word32 gain_code_tmp; - Word16 gain_pit_tmp; - Word32 gain_code_pre; - Word16 avoid_lpc_burst_on_recovery; - Word16 force_scale_syn; - - - gain_code_pre = 0; - move16(); - - - set16_fx(code_preQ, 0, L_SUBFR); + float gain_code_tmp; + float gain_pit_tmp; + float gain_code_pre; gain_inov = 0; /* to avoid compilation warnings */ T0 = 0; /* to avoid compilation warnings */ T0_frac = 0; /* to avoid compilation warnings */ T0_res = 0; /* to avoid compilation warnings */ - prev_Q_syn = st->prev_Q_syn = st->Q_syn; - move16(); - move16(); - move16(); - move16(); + + /*------------------------------------------------------------------------* + * Initializations * + *------------------------------------------------------------------------*/ + + gain_code_pre = 0; + set_f( code_preQ, 0.f, L_SUBFR ); + gain_pit = 0; gain_code = 0; - move16(); - move16(); - move16(); - update_flg = 0; - move16(); - gain_code2=0; + gain_code2 = 0.f; prev_gain_pit = 0; tmp_noise = 0; - IF(sub(st->nb_subfr,4)==0) + if( st->nb_subfr == NB_SUBFR ) { - move16(); - move16(); - move16(); - move16(); - weights[0] = 3277/*0.1f Q15*/; - weights[1] = 6554/*0.2f Q15*/; - weights[2] = 9830/*0.3f Q15*/; - weights[3] = 13107/*0.4f Q15*/; + weights[0] = 0.1f; + weights[1] = 0.2f; + weights[2] = 0.3f; + weights[3] = 0.4f; } - ELSE /*nb_subfr == 5*/ + else /*nb_subfr == NB_SUBFR16k */ { - move16(); - move16(); - move16(); - move16(); - move16(); - weights[0] = 2185/*(float)1/15 Q15*/; - weights[1] = 4369/*(float)2/15 Q15*/; - weights[2] = 6554/*(float)3/15 Q15*/; - weights[3] = 8738/*(float)4/15 Q15*/; - weights[4] = 10923/*(float)5/15 Q15*/; - } - st->Mode2_lp_gainp = L_deposit_l(0); - st->Mode2_lp_gainc = L_deposit_l(0); - - avoid_lpc_burst_on_recovery = 0; - move16(); - test(); - test(); - if (st->last_con_tcx && (sub(st->L_frameTCX_past, st->L_frame_fx) != 0) && (st->last_core_fx != 0)) - { - avoid_lpc_burst_on_recovery = 1; - move16(); + weights[0] = (float)1/15; + weights[1] = (float)2/15; + weights[2] = (float)3/15; + weights[3] = (float)4/15; + weights[4] = (float)5/15; } + st->lp_gainp = 0; + st->lp_gainc = 0; + + + /* Framing parameters */ + L_frame = st->L_frame; /*------------------------------------------------------------------------* * Previous frame is TCX * *------------------------------------------------------------------------*/ - - /* Reset phase dispersion */ - IF ( st->last_core_bfi > ACELP_CORE ) + + if( st->last_core_bfi > ACELP_CORE ) { - st->dm_fx.prev_gain_code = L_deposit_l(0); - set16_fx(st->dm_fx.prev_gain_pit, 0, 6); - st->dm_fx.prev_state = 0; - move16(); + set_zero( st->dispMem, 8 ); } /* Update of synthesis filter memories in case of 12k8 core */ - test(); - test(); - IF ( st->prev_bfi_fx && st->last_con_tcx && sub(st->L_frame_fx, L_FRAME16k) < 0 ) + if( st->prev_bfi && st->last_con_tcx && st->L_frame < L_FRAME16k ) { - synth_mem_updt2( st->L_frame_fx, L_FRAME16k, st->old_exc_fx, st->mem_syn_r, st->mem_syn2_fx, NULL, DEC ); + synth_mem_updt2( st->L_frame, L_FRAME16k, st->old_exc, st->mem_syn_r, st->mem_syn2, NULL, DEC ); } - IF( st->last_con_tcx && st->old_enr_LP ) + if( st->last_con_tcx && st->old_enr_LP ) { - Word16 enr_LP, ratio; + float enr_LP, ratio; /* rescale excitation buffer if LPC energies differs too much */ - enr_LP = Enr_1_Az_fx( A, L_SUBFR ); + enr_LP = enr_1_Az( A, L_SUBFR ); - IF(sub(st->old_enr_LP, enr_LP) < 0) + ratio = st->old_enr_LP/enr_LP; + if (ratio < 0.8) { - ratio = div_s(st->old_enr_LP,enr_LP); /* Q15 */ - IF (sub(ratio, 26215) < 0) - { - FOR (i = 0; i < L_EXC_MEM_DEC; i++) - { - st->old_exc_fx[i] = mult_r(st->old_exc_fx[i], ratio); - } - } + v_multc( st->old_exc, ratio, st->old_exc, L_EXC_MEM_DEC); } } /*------------------------------------------------------------------------* * Initialize buffers * *------------------------------------------------------------------------*/ - Copy( st->mem_syn2_fx, mem_back, M); - move16(); - Q_mem_back = st->Q_syn; + + mvr2r( st->mem_syn2, mem_back, M ); + /* set ACELP synthesis memory */ - Copy( st->mem_syn2_fx, mem_syn, M ); + mvr2r( st->mem_syn2, mem_syn, M ); /* set excitation memory*/ exc=exc_buf+L_EXC_MEM_DEC; - Copy( st->old_exc_fx, exc_buf, L_EXC_MEM_DEC); - *(exc+st->L_frame_fx) = 0; + mvr2r( st->old_exc, exc_buf, L_EXC_MEM_DEC ); + *(exc+L_frame) = 0.f; /* Init syn buffer */ syn = syn_buf + M; - Copy( st->mem_syn2_fx, syn_buf, M ); + mvr2r( st->mem_syn2, syn_buf, M ); /*------------------------------------------------------------------------* * Fast recovery flag *------------------------------------------------------------------------*/ - test(); - if(st->prev_bfi_fx && sub(coder_type,VOICED)==0) + + if( st->prev_bfi && coder_type == VOICED ) { /*Force BPF to be applied fully*/ - st->bpf_gain_param=3; - move16(); + st->bpf_gain_param = 3; } /*------------------------------------------------------------------------* * - decode mean_ener_code for gain decoder (d_gain2.c) * *------------------------------------------------------------------------*/ - Es_pred = 0; - move16(); - IF ( acelp_cfg.nrg_mode>0 ) + + if ( acelp_cfg.nrg_mode > 0 ) { - d_gain_pred(acelp_cfg.nrg_mode, &Es_pred, &prm ); + Es_pred_dec( &Es_pred, prm[0], acelp_cfg.nrg_bits,acelp_cfg.nrg_mode>1 ); + prm++; + } + else + { + Es_pred = 0.f; } /*------------------------------------------------------------------------* * Loop for every subframe in the analysis frame * *------------------------------------------------------------------------* * To find the pitch and innovation parameters. The subframe size is * - * L_subfr and the loop is repeated L_ACELP/L_subfr times. * + * L_SUBFR and the loop is repeated L_frame/L_SUBFR times. * * - compute impulse response of weighted synthesis filter (h1[]) * * - compute the target signal for pitch search * * - find the closed-loop pitch parameters * @@ -244,35 +198,30 @@ void decoder_acelp( *------------------------------------------------------------------------*/ p_A = A; + pt_pitch = pitch_buf; - FOR (i_subfr = 0; i_subfr < st->L_frame_fx; i_subfr += L_SUBFR) + for( i_subfr = 0; i_subfr < L_frame; i_subfr += L_SUBFR ) { - - test(); - IF( sub(st->use_partial_copy,1)== 0 && sub(st->rf_frame_type,RF_NELP) == 0 ) + if( st->use_partial_copy && st->rf_frame_type == RF_NELP ) { - IF( i_subfr == 0 ) + if( i_subfr == 0 ) { - decod_nelp_fx( st, UNVOICED, &tmp_noise, dummy_pitch_buf, exc, exc2, voice_factors, bwe_exc, &st->Q_exc, st->bfi_fx, pgainT ); - - set32_fx(pitch_buf, L_SUBFR_Q16, NB_SUBFR); - set16_fx(pitch_buffer, 4096, NB_SUBFR); /* L_SUBFR_Q16 in Q6 */ + decod_nelp( st, UNVOICED, &tmp_noise, pt_pitch, exc, exc2, voice_factors, bwe_exc, 0 /*st->bfi*/, pgainT ); + set_f(pitch_buffer, L_SUBFR, NB_SUBFR); } } - ELSE + else { - /*-------------------------------------------------------* * - Decode adaptive codebook. * *-------------------------------------------------------*/ - test(); - IF( sub(st->use_partial_copy,1)== 0 && st->acelp_cfg.gains_mode[i_subfr/L_SUBFR] == 0 ) + if( st->use_partial_copy && st->acelp_cfg.gains_mode[i_subfr/L_SUBFR] == 0 ) { gain_pit = prev_gain_pit; } - IF ( acelp_cfg.ltp_bits != 0 ) + if( acelp_cfg.ltp_bits != 0 ) { /*if( st->use_partial_copy && st->rf_frame_type == RF_GENPRED @@ -283,490 +232,318 @@ void decoder_acelp( else*/ { /* pitch lag decoding */ - pitch_buf[i_subfr/L_SUBFR] = Mode2_pit_decode( acelp_cfg.ltp_mode, - i_subfr, - L_SUBFR, - &prm, - &T0, - &T0_frac, - &T0_res, - &T0_min, - &T0_min_frac, - &T0_max, - &T0_max_frac, - st->pit_min, - st->pit_fr1, - st->pit_fr1b, - st->pit_fr2, - st->pit_max, - st->pit_res_max); + *pt_pitch = Mode2_pit_decode( acelp_cfg.ltp_mode, i_subfr, L_SUBFR, &prm, &T0, &T0_frac, &T0_res, + &T0_min, &T0_min_frac, &T0_max, &T0_max_frac, st->pit_min, + st->pit_fr1, st->pit_fr1b, st->pit_fr2, st->pit_max, st->pit_res_max ); } + /* find pitch excitation */ - test(); - IF( sub(st->pit_res_max,6) == 0 && !(st->use_partial_copy) ) + if( st->pit_res_max == 6 && !(st->use_partial_copy) ) { - IF ( sub(T0_res, shr(st->pit_res_max, 1)) == 0) + if ( T0_res == (st->pit_res_max>>1) ) { - pred_lt4( &exc[i_subfr], &exc[i_subfr], T0, shl(T0_frac,1), L_SUBFR+1, pitch_inter6_2, PIT_L_INTERPOL6_2, PIT_UP_SAMP6 ); + pred_lt4( &exc[i_subfr], &exc[i_subfr], T0, T0_frac<<1, L_SUBFR+1, inter6_2, PIT_L_INTERPOL6_2, PIT_UP_SAMP6 ); } - ELSE + else { - pred_lt4( &exc[i_subfr],&exc[i_subfr], T0, T0_frac, L_SUBFR+1, pitch_inter6_2, PIT_L_INTERPOL6_2, PIT_UP_SAMP6 ); + pred_lt4( &exc[i_subfr], &exc[i_subfr], T0, T0_frac, L_SUBFR+1, inter6_2, PIT_L_INTERPOL6_2, PIT_UP_SAMP6 ); } } - ELSE + else { - IF ( sub(T0_res, shr(st->pit_res_max, 1)) == 0) + if( T0_res == (st->pit_res_max>>1) ) { - pred_lt4( &exc[i_subfr], &exc[i_subfr], T0, shl(T0_frac,1), L_SUBFR+1, pitch_inter4_2, L_INTERPOL2, PIT_UP_SAMP ); + pred_lt4( &exc[i_subfr], &exc[i_subfr], T0, T0_frac<<1, L_SUBFR+1, inter4_2, L_INTERPOL2, PIT_UP_SAMP ); } - ELSE + else { - pred_lt4( &exc[i_subfr], &exc[i_subfr], T0, T0_frac, L_SUBFR+1, pitch_inter4_2, L_INTERPOL2, PIT_UP_SAMP ); + pred_lt4( &exc[i_subfr], &exc[i_subfr], T0, T0_frac, L_SUBFR+1, inter4_2, L_INTERPOL2, PIT_UP_SAMP ); } } /* LP filtering of the adaptive excitation*/ lp_flag = acelp_cfg.ltf_mode; - move16(); - IF( sub(acelp_cfg.ltf_mode, NORMAL_OPERATION) == 0 ) + if( acelp_cfg.ltf_mode == NORMAL_OPERATION ) { lp_flag = *prm; - move16(); prm++; } - lp_filt_exc_dec_fx( st, MODE2, st->core_brate_fx, 0, coder_type, i_subfr, L_SUBFR, st->L_frame_fx, lp_flag, exc ); - + lp_filt_exc_dec( st, MODE2, st->core_brate, 0, coder_type, i_subfr, L_SUBFR, L_frame, lp_flag, exc ); } - ELSE + else { /* No adaptive codebook (UC) */ - set16_fx(&exc[i_subfr], 0, L_SUBFR); + set_zero( exc + i_subfr, L_SUBFR ); T0 = L_SUBFR; T0_frac = 0; T0_res = 1; - pitch_buf[i_subfr/L_SUBFR] = L_deposit_h(L_SUBFR); + pitch_buf[i_subfr/L_SUBFR] = (float)L_SUBFR; } - IF( st->igf != 0 ) + if( st->igf ) { - tbe_celp_exc(st->L_frame_fx, i_subfr, T0, T0_frac, &error, bwe_exc); + if( st->sr_core == 12800 ) + { + offset = T0 * HIBND_ACB_L_FAC + (int) ((float) T0_frac * 0.25f * HIBND_ACB_L_FAC + 2 * HIBND_ACB_L_FAC + 0.5f) - 2 * HIBND_ACB_L_FAC; + for (i = 0; i < L_SUBFR * HIBND_ACB_L_FAC; i++) + { + bwe_exc[i + i_subfr * HIBND_ACB_L_FAC] = bwe_exc[i + i_subfr * HIBND_ACB_L_FAC - offset + (int) error]; + } + error += (float) offset - (float) T0 * HIBND_ACB_L_FAC - 0.25f * HIBND_ACB_L_FAC * (float) T0_frac; + } + else + { + offset = T0 * 2 + (int) ((float) T0_frac * 0.5f + 4 + 0.5f) - 4; + for (i=0; iuse_partial_copy,1)==0 && - ( sub(st->rf_frame_type,RF_ALLPRED) == 0 || - ( sub(st->rf_frame_type,RF_GENPRED) == 0 && - ( sub(i_subfr,L_SUBFR) == 0 || sub(i_subfr,3*L_SUBFR) == 0 )) ) ) + + if( st->use_partial_copy && ( st->rf_frame_type == RF_ALLPRED || ( st->rf_frame_type == RF_GENPRED && ( i_subfr == L_SUBFR || i_subfr == 3*L_SUBFR )) ) ) { - set16_fx(code, 0, L_SUBFR); + set_f(code, 0.0f, L_SUBFR); } - ELSE + else { config = PulseConfTable[acelp_cfg.fixed_cdk_index[i_subfr/L_SUBFR]]; D_ACELP_indexing( code, config, NB_TRACK_FCB_4T, prm, &st->BER_detect ); (prm) += 8; - /*-------------------------------------------------------* - * - Add the fixed-gain pitch contribution to code[]. * - *-------------------------------------------------------*/ - cb_shape_fx( acelp_cfg.pre_emphasis, acelp_cfg.pitch_sharpening, acelp_cfg.phase_scrambling, acelp_cfg.formant_enh, acelp_cfg.formant_tilt, - acelp_cfg.formant_enh_num, acelp_cfg.formant_enh_den, p_A, code, st->tilt_code_fx, extract_h(L_add(pitch_buf[i_subfr/L_SUBFR],26216)), 1 ); + /*-------------------------------------------------------* + * - Add the fixed-gain pitch contribution to code[]. * + *-------------------------------------------------------*/ + + cb_shape( acelp_cfg.pre_emphasis, acelp_cfg.pitch_sharpening, acelp_cfg.phase_scrambling, acelp_cfg.formant_enh, + acelp_cfg.formant_tilt, acelp_cfg.formant_enh_num, acelp_cfg.formant_enh_den, p_A, code, st->tilt_code, pitch_buf[i_subfr/L_SUBFR] ); } + /*-------------------------------------------------------* * - Generate Gaussian excitation * *-------------------------------------------------------*/ - test(); - IF( sub(acelp_cfg.gains_mode[i_subfr/L_SUBFR],7)==0 && !st->use_partial_copy ) + + if( acelp_cfg.gains_mode[i_subfr/L_SUBFR] == 7 && !st->use_partial_copy ) { - gaus_L2_dec( code2, st->tilt_code_fx, p_A, acelp_cfg.formant_enh_num, &(st->seed_acelp) ); + gaus_L2_dec( code2, st->tilt_code, p_A, acelp_cfg.formant_enh_num, &(st->seed_acelp) ); } - ELSE + else { - gain_code2 = L_deposit_l(0); - set16_fx(code2,0,L_SUBFR); + gain_code2 = 0.f; + set_zero( code2, L_SUBFR ); } /*-------------------------------------------------* * - Decode codebooks gains. * *-------------------------------------------------*/ - IF( st->acelp_cfg.gains_mode[i_subfr/L_SUBFR] != 0 ) - { - decode_acelp_gains( code, - acelp_cfg.gains_mode[i_subfr/L_SUBFR], - Es_pred, - &gain_pit, - &gain_code, - &prm, - &(st->past_gpit), - &(st->past_gcode), - &gain_inov, - L_SUBFR, - code2, - &gain_code2 - ); - } - IF(st->use_partial_copy && st->rf_frame_type == RF_ALLPRED) st->past_gcode = 0; - IF(st->use_partial_copy && st->rf_frame_type == RF_NOPRED ) st->past_gpit = 67; - IF( st->igf != 0 ) - { - /* Rescaling for 12.8k and 16k cores related to BWE */ - IF ( sub(st->L_frame_fx, L_FRAME) == 0 ) - { - /* 5/2 times resampled past memories*/ - reScaleLen_fx = add(shl(i_subfr, 1), shr(i_subfr, 1)); - reSampLen = (L_SUBFR * HIBND_ACB_L_FAC); - } - ELSE - { - /* 2 times resampled past memories*/ - reScaleLen_fx = shl(i_subfr, 1); - reSampLen = (L_SUBFR * 2); - } - Rescale_exc(NULL, &exc[i_subfr], &bwe_exc[reScaleLen_fx], - NULL, L_SUBFR, reSampLen, gain_code, &(st->Q_exc), st->Q_subfr, - exc2, i_subfr, GENERIC); - } - ELSE + if( st->acelp_cfg.gains_mode[i_subfr/L_SUBFR] != 0 ) { - Rescale_exc(NULL, &exc[i_subfr], NULL, NULL, L_SUBFR, 0, - gain_code, &(st->Q_exc), st->Q_subfr, exc2, i_subfr, GENERIC); + decode_acelp_gains( code, acelp_cfg.gains_mode[i_subfr/L_SUBFR], Es_pred, &gain_pit, &gain_code, + &prm, &(st->past_gpit), &(st->past_gcode), &gain_inov, L_SUBFR, code2, &gain_code2 ); + } + + if( st->use_partial_copy && st->rf_frame_type == RF_ALLPRED ) + { + st->past_gcode = 0.0f; + } + + if( st->use_partial_copy && st->rf_frame_type == RF_NOPRED ) + { + st->past_gpit = 0.004089f; } /*----------------------------------------------------------* * Update parameters for the next subframe. * * - tilt of code: 0.0 (unvoiced) to 0.5 (voiced) * *----------------------------------------------------------*/ - E_UTIL_voice_factor( exc, - i_subfr, - code, - gain_pit, - gain_code, - &(st->voice_fac), - &(st->tilt_code_fx), - L_SUBFR, - acelp_cfg.voice_tilt, - st->Q_exc, - 0 - ); + + st->tilt_code = est_tilt( exc+i_subfr, gain_pit, code, gain_code, &(st->voice_fac), L_SUBFR, acelp_cfg.voice_tilt ); pgainT[i_subfr/L_SUBFR] = gain_pit; - move16(); /*-------------------------------------------------------* * - Find the total excitation. * *-------------------------------------------------------*/ + gain_code_tmp = gain_code; gain_pit_tmp = gain_pit; - IF( i_subfr == 0 ) + if ( st->core == ACELP_CORE && st->last_core == ACELP_CORE && ( st->use_partial_copy || st->prev_use_partial_copy)) { - gain_code_pre = 0; - } - IF ( sub(st->core_fx,ACELP_CORE) == 0 && sub(st->last_core_fx,ACELP_CORE) == 0 && ( sub(st->use_partial_copy,1) == 0|| sub(st->prev_use_partial_copy, 1) == 0)) - { - IF( i_subfr > 0 && sub(gain_pit,20152) > 0 && sub(st->prev_tilt_code_dec_fx,6553) > 0 && sub(st->next_coder_type,VOICED) == 0 - &&( sub(st->use_partial_copy,1) == 0 || sub(st->prev_use_partial_copy, 1) ==0 ) ) + if ( i_subfr > 0 && gain_pit > 1.23f && st->prev_tilt_code_dec > 0.2f && st->next_coder_type == VOICED && (st->use_partial_copy || st->prev_use_partial_copy ) ) { - gain_pit = mult(gain_pit,sub(26214, mult(i_subfr,51))); + gain_pit *= (0.8f - i_subfr/640.0f); } - ELSE IF( !st->prev_use_partial_copy && sub(st->last_coder_type_fx,UNVOICED) == 0 && sub(st->next_coder_type,UNVOICED) != 0 && L_sub(gain_code,gain_code_pre)< 0) + else if( !st->prev_use_partial_copy && st->last_coder_type == UNVOICED && st->next_coder_type != UNVOICED && gain_code < gain_code_pre) { - gain_code = 0; + gain_code = 0.0f; } } + gain_code_pre = gain_code; - st->tilt_code_dec_fx[i_subfr/L_SUBFR] = st->tilt_code_fx; + st->tilt_code_dec[i_subfr/L_SUBFR] = st->tilt_code; - - tmp2 = shr(L_SUBFR, 1); - FOR (j = 0; j < 2; j++) + for( i = 0; i < L_SUBFR; i++ ) { - FOR (i = sub(tmp2, shr(L_SUBFR, 1)); i < tmp2; i++) - { - /* code in Q9, gain_pit in Q14, gain_code in Q16; exc Q_new */ - Ltmp = Mpy_32_16_1(gain_code2, code2[i]); - Ltmp = L_shl(Ltmp, add(5,st->Q_exc)); - Ltmp = L_mac(Ltmp, gain_pit, exc[i+i_subfr]); - exc2[i + i_subfr] = round_fx(L_shl(Ltmp, 1)); - - Ltmp2 = Mpy_32_16_1(gain_code, code[i]); - Ltmp2 = L_shl(Ltmp2, add(5,st->Q_exc)); - Ltmp = L_add(Ltmp, Ltmp2); - BASOP_SATURATE_WARNING_OFF - Ltmp = L_shl(Ltmp, 1); /* saturation can occur here */ - BASOP_SATURATE_WARNING_ON - exc[i + i_subfr] = round_fx(Ltmp); - } - tmp2 = L_SUBFR; - move16(); + exc2[i+i_subfr] = gain_pit*exc[i+i_subfr]; + exc2[i+i_subfr] += gain_code2*code2[i]; + exc[i+i_subfr] = exc2[i+i_subfr] + gain_code*code[i]; } /*-----------------------------------------------------------------* * Prepare TBE excitation *-----------------------------------------------------------------*/ + gain_code = gain_code_tmp; gain_pit = gain_pit_tmp; - IF( st->igf != 0 ) + + if( st->igf != 0 ) { - prep_tbe_exc_fx( st->L_frame_fx, - i_subfr, - gain_pit, - gain_code, - code, - st->voice_fac, - &voice_factors[i_subfr/L_SUBFR], - bwe_exc, - gain_preQ, - code_preQ, - st->Q_exc, - T0, - T0_frac, - coder_type, - st->core_brate_fx); + prep_tbe_exc( L_frame, i_subfr, gain_pit, gain_code, code, st->voice_fac, &voice_factors[i_subfr/L_SUBFR], + bwe_exc, gain_preQ, code_preQ, T0, coder_type, st->core_brate ); } /*---------------------------------------------------------* * Enhance the excitation * *---------------------------------------------------------*/ - E_UTIL_enhancer( st->voice_fac, - stab_fac, - st->past_gcode, - gain_inov, - &(st->gc_threshold_fx), - code, - &exc2[i_subfr], - gain_pit, - &st->dm_fx.prev_gain_code, - st->dm_fx.prev_gain_pit, - &st->dm_fx.prev_state, - coder_type, - acelp_cfg.fixed_cdk_index[i_subfr/L_SUBFR], - L_SUBFR, - st->L_frame_fx, - st->Q_exc - ); + + enhancer( MODE2, -1, acelp_cfg.fixed_cdk_index[i_subfr/L_SUBFR], 0, coder_type, L_frame, st->voice_fac, stab_fac, + st->past_gcode, gain_inov, &(st->gc_threshold), code, &exc2[i_subfr], gain_pit, st->dispMem ); } /* !RF_NELP frame partial copy */ + /*----------------------------------------------------------* * - compute the synthesis speech * *----------------------------------------------------------*/ - rescale_mem(&st->Q_exc, &prev_Q_syn, &st->Q_syn, mem_syn, syn, M, i_subfr); - E_UTIL_synthesis(sub(st->Q_exc,st->Q_syn), p_A, &exc2[i_subfr], &syn[i_subfr], L_SUBFR, mem_syn, 1, M); + syn_filt( p_A, M,&exc2[i_subfr], &syn[i_subfr], L_SUBFR, mem_syn, 1 ); /*-----------------------------------------------------------------* * update lp_filtered gains for the case of frame erasure *-----------------------------------------------------------------*/ - st->Mode2_lp_gainp = L_add(st->Mode2_lp_gainp, L_mult0(st->past_gpit, weights[i_subfr/L_SUBFR])); /* 2Q29=1Q14*Q15 */ move32(); - st->Mode2_lp_gainc = L_add(st->Mode2_lp_gainc, Mpy_32_16_1(st->past_gcode, weights[i_subfr/L_SUBFR])); /* 15Q16=15Q16*Q15 */ move32(); + st->lp_gainp += weights[i_subfr/L_SUBFR] * st->past_gpit; + st->lp_gainc += weights[i_subfr/L_SUBFR] * st->past_gcode; /*----------------------------------------------------------* * - update pitch lag for guided ACELP * *----------------------------------------------------------*/ - test(); - if( st->enableGplc && sub( shr(i_subfr,6), sub(st->nb_subfr,1) )==0 ) + + if( st->enableGplc && (i_subfr/L_SUBFR) == (L_frame/L_SUBFR)-1 ) { st->T0_4th = T0; - move16(); } /*----------------------------------------------------------* * - Update LPC coeffs * *----------------------------------------------------------*/ - p_A += (M+1); + p_A += (M+1); + pt_pitch++; /* copy current gain for next subframe use, in case there is no explicit encoding */ prev_gain_pit = gain_pit; + } /* end of subframe loop */ - IF(st->BER_detect) + if(st->BER_detect) { - FOR (i=0; iL_frame_fx; i++) + for (i=0; iold_lsp_q_cng, st->lsp_q_cng, st->Aq_cng, M, interpol_frac_12k8, 0 ); + + p_A =st->Aq_cng; + if(st->last_good < UNVOICED_TRANSITION ) + { + mvr2r(st->mem_syn2, mem_syn, M ); + } + else + { + set_zero( mem_syn, M ); } - int_lsp_fx( st->L_frame_fx, st->old_lsp_q_cng, st->lsp_q_cng, st->Aq_cng, M, interpol_frac_fx, 0 ); - - p_A = st->Aq_cng; - IF(st->last_good_fx < UNVOICED_TRANSITION ) + for (i_subfr = 0; i_subfr < L_frame; i_subfr += L_SUBFR) { - Copy(st->mem_syn2_fx, mem_syn, M ); - } - ELSE - { - set16_fx( mem_syn, 0, M ); - } - - FOR (i_subfr = 0; i_subfr < st->L_frame_fx; i_subfr += L_SUBFR) - { - E_UTIL_synthesis(sub(st->Q_exc,st->Q_syn), p_A, &exc[i_subfr], &syn[i_subfr], L_SUBFR, mem_syn, 1, M); + syn_filt(p_A, M,&exc[i_subfr], &syn[i_subfr], L_SUBFR, mem_syn, 1); p_A += (M+1); } } tmp = 0; - move16(); - pA = A+(st->nb_subfr-1)*(M+1); - set16_fx(h1, 0, add(L_SUBFR,1)); - set16_fx(mem, 0, M); - h1[0] = 32768/32; - move16(); - E_UTIL_synthesis(0, pA, h1, h1, L_SUBFR, mem, 0, M); /* impulse response of LPC */ - deemph_fx(h1, st->preemph_fac, L_SUBFR, &tmp); /* impulse response of deemph */ + pA = A + (st->nb_subfr-1)*(M+1); + set_zero( h1, L_SUBFR+1 ); + set_zero( mem, M ); + h1[0] = 1.0f; + syn_filt( pA, M,h1, h1, L_SUBFR, mem, 0); /* impulse response of LPC */ + deemph( h1, st->preemph_fac, L_SUBFR, &tmp); /* impulse response of deemph */ /* impulse response level = gain introduced by synthesis+deemphasis */ - Ltmp = Dot_productSq16HQ( 0, h1, L_SUBFR, &st->last_gain_syn_deemph_e); - st->last_gain_syn_deemph_e= add(st->last_gain_syn_deemph_e,10/*scaling of h1[0] and E_UTIL_synthesis * 2*/); - st->last_gain_syn_deemph = round_fx(Sqrt32(Ltmp,&st->last_gain_syn_deemph_e)); + st->last_gain_syn_deemph = (float)sqrt(dotp( h1, h1, L_SUBFR) ); + + /*-----------------------------------------------------------* + * PLC: [ACELP: Fade-out] + * PLC: update the background level + *-----------------------------------------------------------*/ /* Do the classification */ - { - Word16 pit16[NB_SUBFR16k]; - Word16 k; - FOR(k = 0 ; k < st->nb_subfr ; k++) - { - pit16[k] = shl(extract_h(pitch_buf[k]),6);/*Q6*/ - } - - FEC_clas_estim_fx( - st, - /*Opt_AMR_WB*/0, /*A*/ - st->L_frame_fx, - &(st->clas_dec), - st->core_ext_mode, - pit16, - syn, - &st->lp_ener_FER_fx, - /**decision_hyst*/NULL, /* i/o: hysteresis of the music/speech decision */ - /**UV_cnt*/ NULL, /* i/o: number of consecutives frames classified as UV */ - /**LT_UV_cnt*/ NULL, /* i/o: long term consecutives frames classified as UV */ - /**Last_ener*/ NULL, /* i/o: last_energy frame */ - /**locattack*/ NULL, /* i/o: detection of attack (mainly to localized speech burst) */ - /**lt_diff_etot*/NULL, /* i/o: long-term total energy variation */ - /**amr_io_class*/ NULL, /* i/o: classification for AMR-WB IO mode */ - /*bitrate*/ 0 , /* i : Decoded bitrate */ - st->Q_syn, /* i : Synthesis scaling */ - /**class_para*/ NULL, /* o : classification para. fmerit1 */ - st->mem_syn_clas_estim_fx, /* i/o: memory of the synthesis signal for frame class estimation */ - &st->classifier_Q_mem_syn, /* i/o: exponent for memory of synthesis signal for frame class estimation */ - -32768/*-1.f Q15*/, /* i : LTP Gain */ - 0/*CLASSIFIER_ACELP*/, /* i : signal classifier mode */ - 0/*bfi*/, /* i : bad frame indicator */ - st->last_core_brate_fx /* i : bitrate of previous frame */ - ); - } + FEC_clas_estim( syn, pitch_buf, st->L_frame, st->core_ext_mode, st->codec_mode, st->mem_syn_clas_estim, &st->clas_dec, + &st->lp_ener_bfi, st->core_brate, 0, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, -1.0f, + st->narrowBand, (SIGNAL_CLASSIFIER_MODE)0, + 0, st->preemph_fac, st->tcxonly, st->last_core_brate ); /* Update Pitch Lag memory */ + mvr2r( &st->old_pitch_buf[L_frame/L_SUBFR], st->old_pitch_buf, L_frame/L_SUBFR ); + mvr2r( pitch_buf, &st->old_pitch_buf[L_frame/L_SUBFR], L_frame/L_SUBFR ); - Copy32(&st->old_pitch_buf_fx[st->nb_subfr], st->old_pitch_buf_fx, st->nb_subfr); - Copy32(pitch_buf, &st->old_pitch_buf_fx[st->nb_subfr], st->nb_subfr); + FEC_scale_syn( st->L_frame, st->clas_dec, st->last_good, syn, pitch_buf, st->enr_old, 0, coder_type, + LSF_Q_prediction, &st->scaling_flag, &st->lp_ener_FEC_av, &st->lp_ener_FEC_max, st->bfi, + st->total_brate, st->prev_bfi, st->last_core_brate, exc, exc2, A, &st->old_enr_LP, mem_back, mem_syn + , st->last_con_tcx && (st->L_frameTCX_past != st->L_frame) && (st->last_core != 0) + , (st->clas_dec == ONSET || (st->last_good >= VOICED_TRANSITION && st->last_good < INACTIVE_CLAS) ) ); - - { - Word16 pBuf_scaleSyn[NB_SUBFR16k]; - - FOR(i=0; i<(st->L_frame_fx/L_SUBFR); i++) - { - pBuf_scaleSyn[i] = round_fx(pitch_buf[i]); - } - - Scale_sig(mem_back, M, sub(st->Q_syn,Q_mem_back)); - - force_scale_syn = 0; - move16(); - test(); - test(); - test(); - IF ( (sub(st->clas_dec,ONSET) == 0) || ((sub(st->last_good_fx,VOICED_TRANSITION) >= 0) && (sub(st->last_good_fx,INACTIVE_CLAS) < 0)) ) - { - force_scale_syn = 1; - move16(); - } - - FEC_scale_syn_fx( st->L_frame_fx, - &update_flg, - st->clas_dec, - st->last_good_fx, - syn, - pBuf_scaleSyn, - st->enr_old_fx, - 0, - coder_type, - LSF_Q_prediction, - &st->scaling_flag, - &st->lp_ener_FEC_av, - &st->lp_ener_FEC_max, - st->bfi_fx, - st->total_brate_fx, - st->prev_bfi_fx, - st->last_core_brate_fx, - exc, - exc2, - A, - &(st->old_enr_LP), - mem_back, - mem_syn, - st->Q_exc, - st->Q_syn - , avoid_lpc_burst_on_recovery - , force_scale_syn - ); - } /* update ACELP synthesis memory */ - Copy( mem_syn, st->mem_syn2_fx, M ); - Copy( syn+st->L_frame_fx-L_SYN_MEM, st->mem_syn_r, L_SYN_MEM ); + mvr2r( mem_syn, st->mem_syn2, M ); + mvr2r( syn+L_frame-L_SYN_MEM, st->mem_syn_r, L_SYN_MEM ); - /* Deemphasis and output synth and ZIR */ - tmp_deemph = st->syn[M]; - move16(); - E_UTIL_deemph2(st->Q_syn, syn, st->preemph_fac, st->L_frame_fx, &tmp_deemph); /* tmp_deemph and syn in Q0 starting from here*/ + tmp = st->syn[M]; + deemph( syn, st->preemph_fac, L_frame, &tmp ); + mvr2r( syn+L_frame-(L_frame/2), st->old_syn_Overl, L_frame/2 ); + mvr2r( syn+L_frame-M-1, st->syn, M+1 ); + mvr2r( syn, synth, L_frame ); - bufferCopyFx(syn+st->L_frame_fx- st->L_frame_fx/2, st->old_syn_Overl, shr(st->L_frame_fx, 1),0 /*Qf_syn*/, -1 /*Qf_old_xnq*/, 0 , 0 /*Q_old_xnq*/); - - Copy(syn+st->L_frame_fx-M-1, st->syn, 1+M); /*Q0*/ - - Copy(syn, synth, st->L_frame_fx); - - Copy( syn, st->old_core_synth_fx, st->L_frame_fx ); + mvr2r( syn, st->old_core_synth, L_frame ); - /* update old_Aq */ - Copy(exc_buf+st->L_frame_fx, st->old_exc_fx, L_EXC_MEM_DEC); + /* update old_exc */ + mvr2r( exc_buf+L_frame, st->old_exc, L_EXC_MEM_DEC ); /* Output pitch parameters for bass post-filter */ - FOR (i_subfr = 0; i_subfr < st->L_frame_fx; i_subfr += L_SUBFR) + for (i_subfr = 0; i_subfr < L_frame; i_subfr += L_SUBFR ) { - *pT++ = round_fx(pitch_buf[i_subfr/L_SUBFR]); + *pT++ = (int)( pitch_buf[i_subfr/L_SUBFR] + 0.5f); } - - st->tcxltp_last_gain_unmodified = 0; + /* Update TCX-LTP */ + st->tcxltp_last_gain_unmodified = 0.f; /*Update MODE1*/ - Copy( p_A-(M+1), st->old_Aq_12_8_fx, M+1 ); - st->old_Es_pred_fx = Es_pred; + mvr2r( p_A-(M+1), st->old_Aq_12_8, M+1 ); + st->old_Es_pred = Es_pred; st->tcxltp_third_last_pitch = st->tcxltp_second_last_pitch; st->tcxltp_second_last_pitch = st->old_fpitch; - st->old_fpitch = pitch_buf[(st->L_frame_fx/L_SUBFR) - 1]; - move32(); - + st->old_fpitch = pitch_buf[(L_frame/L_SUBFR) - 1]; return; } - diff --git a/src/libs/libevs/lib_dec/dec_acelp.cpp b/src/libs/libevs/lib_dec/dec_acelp.cpp old mode 100755 new mode 100644 index 477f20b6..47297632 --- a/src/libs/libevs/lib_dec/dec_acelp.cpp +++ b/src/libs/libevs/lib_dec/dec_acelp.cpp @@ -1,19 +1,19 @@ /*==================================================================================== - EVS Codec 3GPP TS26.442 Apr 03, 2018. Version 12.11.0 / 13.6.0 / 14.2.0 + EVS Codec 3GPP TS26.443 Nov 13, 2018. Version 12.11.0 / 13.7.0 / 14.3.0 / 15.1.0 ====================================================================================*/ #include #include -#include "stl.h" -#include "basop_util.h" -#include "prot_fx.h" -#include "rom_com_fx.h" -#include "prot_fx.h" -#include "rom_basop_util.h" +#include "typedef.h" +#include "prot.h" +#include "rom_com.h" -#define _1_CODE 0x200 /*codebook excitation Q9 */ -static void D_ACELP_decode_arithtrack(Word16 v[], Word32 s, Word16 p, Word16 trackstep, Word16 tracklen); +/*---------------------------------------------------------------------* +* Local functions +*---------------------------------------------------------------------*/ + +static void D_ACELP_decode_arithtrack( float v[], long unsigned s, int p, int trackstep, int tracklen ); /*---------------------------------------------------------------------* * Function D_ACELP_indexing() @@ -21,352 +21,312 @@ static void D_ACELP_decode_arithtrack(Word16 v[], Word32 s, Word16 p, Word16 tra *---------------------------------------------------------------------*/ void D_ACELP_indexing( - Word16 code[], + Float32 code[], PulseConfig config, - Word16 num_tracks, - Word16 index[] - ,Word16 *BER_detect + int num_tracks, + int index[] + ,short *BER_detect ) { - Word16 track, pulses, k, pulsestrack[NB_TRACK_FCB_4T]; - Word32 s; - Word16 trackpos; - UWord16 *idxs; - UWord32 idxs32[4], index_n[NB_TRACK_FCB_4T]; - Word16 restpulses, wordcnt, wordcnt32; + int track, pulses, k, pulsestrack[NB_TRACK_FCB_4T]; + long unsigned s; + long unsigned index_n[NB_TRACK_FCB_4T]; + unsigned short trackpos, idxs[MAX_IDX_LEN]; + int restpulses, wordcnt; assert(num_tracks == NB_TRACK_FCB_4T); - wordcnt = shr(add(config.bits,15),4); /* ceil(bits/16) */ + wordcnt = (config.bits + 15) >> 4; /* ceil(bits/16) */ /* check if some tracks have more pulses */ - restpulses = s_and((Word16)config.nb_pulse, sub(num_tracks, 1)); + restpulses = config.nb_pulse & (num_tracks-1); /* cast to short */ - idxs= (UWord16 *)idxs32; - FOR (k=0; k>2)+1,4); + pulsestrack[trackpos]--; /* this one has less pulses */ + break; case TRACKPOS_FREE_ONE: /* Find track with more pulses */ - trackpos = s_and(idxs[0], 3); - longshr(idxs32,2,wordcnt32); + trackpos = idxs[0] & 3; + longshiftright(idxs,2,idxs,wordcnt,wordcnt); /* set number of pulses per track */ - set16_fx(pulsestrack, shr((Word16)config.nb_pulse,2),4); - cast16(); - pulsestrack[trackpos] = add(pulsestrack[trackpos],1); /* this one has less pulses */ move16(); - BREAK; + set_i( pulsestrack,(config.nb_pulse>>2),4); + pulsestrack[trackpos]++; /* this one has more pulses */ + break; case TRACKPOS_FIXED_EVEN: /* Pulses on even tracks */ - pulsestrack[0] = shr(add((Word16)config.nb_pulse,1), 1); - cast16(); - move16(); + pulsestrack[0] = (config.nb_pulse+1) >> 1; pulsestrack[1] = 0; - move16(); - pulsestrack[2] = shr((Word16)config.nb_pulse, 1); - cast16(); - move16(); + pulsestrack[2] = config.nb_pulse >> 1; pulsestrack[3] = 0; - move16(); - BREAK; + break; case TRACKPOS_FIXED_FIRST: /* set number of pulses per track */ - set16_fx(pulsestrack, shr((Word16)config.nb_pulse,2),4); - cast16(); - FOR (k=0; k>2),4); + pulsestrack[trackpos]++; + trackpos++; + trackpos &= 3; + pulsestrack[trackpos]++; + break; default: assert(0); - BREAK; + break; } } - ELSE + else { /* set number of pulses per track */ - set16_fx(pulsestrack, shr((Word16)config.nb_pulse,2),4); - cast16(); + set_i( pulsestrack,(config.nb_pulse/num_tracks),num_tracks); } - IF (sub(config.bits, 43) == 0) + if (config.bits == 43) { D_ACELP_decode_43bit(idxs, code, pulsestrack); } - ELSE + else { + fcb_pulse_track_joint_decode(idxs, wordcnt, index_n, pulsestrack, num_tracks); - FOR (track = num_tracks - 1; track >=1; track--) + + for (track=num_tracks-1; track >=1; track--) { pulses = pulsestrack[track]; - move16(); - IF (pulses) + if (pulses) { - /* divide by number of possible states: rest is actual state and - * the integer part goes to next track */ s = index_n[track]; + /* decode state to actual pulse positions on track */ + /*D_ACELP_decode_arithtrack_old(code+track, s, pulses, 4); */ D_ACELP_decode_arithtrack(code+track, s, pulses, num_tracks, 16); } - ELSE /* track is empty */ + else { - FOR (k=track; k < 16*num_tracks; k+=num_tracks) + /* track is empty */ + for (k=track; k < 16*num_tracks; k+=num_tracks) { - code[k] = 0; - move16(); + code[k] = 0.0f; } } } - - s = L_add(index_n[0], 0); + s = index_n[0]; pulses = pulsestrack[0]; - move16(); - /* safety check in case of bit errors */ - IF( L_sub(s,pulsestostates[16][pulses-1]) >= 0 ) + if (s >= pulsestostates[16][pulses-1]) { - set16_fx( code, 0, L_SUBFR ); + set_f( code, 0.0f, L_SUBFR ); *BER_detect = 1; - move16(); return; } - - IF (pulses) + if (pulses) { D_ACELP_decode_arithtrack(code, s, pulses, num_tracks, 16); } - ELSE {/* track is empty */ - FOR (k=0; k < 16*num_tracks; k+=num_tracks) - { - code[k] = 0; - move16(); - } - } - } -} - -static void D_ACELP_decode_arithtrack(Word16 v[], Word32 s, Word16 p, Word16 trackstep, Word16 tracklen) -{ - Word16 k, idx; - - /*initialy s was UWords32 but it seems that s is never greater then 0x80000000*/ - /*this assumption reduces complexity but if it is not true than exit*/ - assert(s >= 0); - - FOR (k=(tracklen)-1; k>= 0; k--) - { - idx = imult1616(k,trackstep); - v[idx] = 0; /* default: there is no pulse here */ move16(); - - FOR(; p; p--) /* one pulse placed, so one less left */ + else { - IF (L_sub(s, pulsestostates[k][p-1]) < 0) + /* track is empty */ + for (k=0; k < 16*num_tracks; k+=num_tracks) { - BREAK; - } - - s = L_sub(s, pulsestostates[k][p-1]); - - IF (v[idx] != 0) /* there is a pulse here already = sign is known */ - { - if (v[idx] > 0) - { - v[idx] = add(v[idx],_1_CODE); /* place one more pulse here */ move16(); - } - if (v[idx] <= 0) - { - v[idx] = sub(v[idx],_1_CODE); /* place one more pulse here */ move16(); - } - } - ELSE /* this is the first pulse here -> determine sign */ - { - v[idx] = +_1_CODE; /* place a negative pulse here */ move16(); - if (L_and(s, 0x1) != 0) - { - v[idx] = -_1_CODE; /* place a negative pulse here */ move16(); - } - s = L_lshr(s,1); + code[k] = 0.0f; } } } -} - -void fcb_pulse_track_joint_decode(UWord16 *idxs, Word16 wordcnt, UWord32 *index_n, Word16 *pulse_num, Word16 track_num) -{ - Word16 hi_to_low[10] = { 0, 0, 0, 3, 9, 5, 3, 1, 8, 8}; - - UWord32 index; - Word32 indx_tmp; - Word16 indx_flag, indx_flag_1; - Word16 track, track_num1, pulse_num0, pulse_num1; - Word32 div_tmp; - Word16 indx_flag_2; - - indx_flag = 0; - move16(); - indx_flag_1 = 0; - move16(); - indx_flag_2 = 0; - move16(); - - FOR (track = 0; track < track_num; track++) - { - indx_flag = add(indx_flag, shr(pulse_num[track], 2)); - indx_flag_1 = add(indx_flag_1, shr(pulse_num[track], 1)); - indx_flag_2 = add(indx_flag_2, shr(pulse_num[track], 3)); - } - - hi_to_low[4] = 1; - move16(); - if (sub(indx_flag, track_num) >= 0) - { - hi_to_low[4] = 9; - move16(); - } - - hi_to_low[7] = 1; - move16(); - if (sub(indx_flag_2, 1) >= 0) - { - hi_to_low[7] = 9; - move16(); - } - - IF (sub(indx_flag_1, track_num) >= 0) - { - IF (sub(indx_flag, track_num) >= 0) - { - index = L_deposit_l(0); - IF (sub(indx_flag_2, 1) >= 0) - { - FOR (track = sub(wordcnt, 1); track >= 6; track--) - { - index = L_add(L_lshl(index, 16), (UWord32) idxs[track]); - } - index_n[3] = L_add(L_lshl(idxs[5], 8), L_and(L_lshr(idxs[4], 8), 0xFF)); - move32(); - index_n[2] = L_and(L_add(L_lshl(idxs[4], 16), idxs[3]), 0xFFFFFF); - move32(); - index_n[1] = L_add(L_lshl(idxs[2], 8), L_and(L_lshr(idxs[1], 8), 0xFF)); - move32(); - index_n[0] = L_and(L_add(L_lshl(idxs[1], 16), idxs[0]), 0xFFFFFF); - move32(); - } - ELSE - { - FOR (track = (wordcnt-1); track >= track_num; track--) - { - index = L_add(L_lshl(index, 16), (UWord32) idxs[track]); - } - FOR (track = 0; track < track_num; track++) - { - index_n[track] = (UWord32) idxs[track]; - move32(); - } - } - } - ELSE - { - index = L_deposit_l(0); - FOR (track = (wordcnt-1); track >= 2; track--) - { - index = L_add(L_lshl(index, 16), (UWord32) idxs[track]); - } - - index_n[3] = L_and((Word32) idxs[1], 0xFF); - move32(); - index_n[2] = L_lshr((Word32) idxs[1], 8); - move32(); - index_n[1] = L_and((Word32) idxs[0], 0xFF); - move32(); - index_n[0] = L_lshr((Word32) idxs[0], 8); - move32(); - } - - track_num1 = sub(track_num, 1); - pulse_num1 = pulse_num[track_num1]; - move16(); - index = L_add(L_lshl(index, hi_to_low[pulse_num1]), L_lshr(index_n[track_num1], low_len[pulse_num1])); - FOR (track = (track_num-1); track > 0; track--) - { - track_num1 = sub(track, 1); - pulse_num0 = pulse_num[track_num1]; - move16(); - pulse_num1 = pulse_num[track]; - move16(); - index = L_add(L_lshl(index, hi_to_low[pulse_num0]), L_lshr(index_n[track_num1], low_len[pulse_num0])); - - iDiv_and_mod_32(index, indx_fact[pulse_num1], &div_tmp, &indx_tmp, 0); - index_n[track] = L_add(L_and(index_n[track], low_mask[pulse_num1]), L_lshl(indx_tmp, low_len[pulse_num1])); - index = L_add(div_tmp, 0); - } - pulse_num1 = pulse_num[0]; - move16(); - index_n[0] = L_add(L_and(index_n[0], low_mask[pulse_num1]), L_lshl(index, low_len[pulse_num1])); - move32(); - } - ELSE - { - index = L_deposit_l(0); - FOR (track = (wordcnt-1); track >= 0; track--) - { - index = L_add(L_lshl(index, 16), (UWord32) idxs[track]); - } - FOR (track = 3; track > 0; track--) - { - pulse_num1 = pulse_num[track]; - move16(); - index_n[track] = L_and(index, index_mask_ACELP[pulse_num1]); - move32(); - index = L_lshr(index, index_len[pulse_num1]); - } - index_n[0] = index; - move32(); - } return; } + +static void D_ACELP_decode_arithtrack( + float v[], + long unsigned s, + int p, + int trackstep, + int tracklen +) +{ + int k; + + for (k=(tracklen)-1; k>= 0; k--) + { + v[k*trackstep] = 0.0f; /* default: there is no pulse here */ + while((p) && (s >= pulsestostates[k][p-1] )) + { + s -= pulsestostates[k][p-1]; + if (v[k*trackstep]) + { + /* there is a pulse here already = sign is known */ + if (v[k*trackstep] > 0.0f) + { + v[k*trackstep]++; /* place one more pulse here */ + } + else + { + v[k*trackstep]--; /* place one more pulse here */ + } + } + else + { + /* this is the first pulse here -> determine sign */ + if (s & 1) + { + v[k*trackstep] = -1.0f; /* place a negative pulse here */ + } + else + { + v[k*trackstep] = +1.0f; /* place a negative pulse here */ + } + s >>= 1; + } + p--; /* one pulse placed, so one less left */ + } + } + + return; +} + + +void fcb_pulse_track_joint_decode(unsigned short *idxs, int wordcnt, long unsigned *index_n, int *pulse_num, int track_num) +{ + int hi_to_low[10] = { 0, 0, 0, 3, 9, 5, 3, 1, 8, 8}; + + unsigned long long index; + int indx_tmp,indx_flag,indx_flag_1; + int track,track_num1,pulse_num0,pulse_num1; + int div_tmp; + int indx_flag_2; + + indx_flag=0; + indx_flag_1=0; + indx_flag_2 = 0; + for (track=0; track < track_num; track++) + { + indx_flag += (pulse_num[track]>>2); + indx_flag_1 += (pulse_num[track]>>1); + indx_flag_2 += (pulse_num[track]>>3); + } + + if (indx_flag >= track_num) + { + hi_to_low[4] = 9; + } + else + { + hi_to_low[4] = 1; + } + + if (indx_flag_2 >= 1) + { + hi_to_low[7] = 9; + } + else + { + hi_to_low[7] = 1; + } + if (indx_flag_1>=track_num) + { + if (indx_flag>=track_num) + { + index = 0; + if (indx_flag_2 >= 1) + { + for (track=(wordcnt-1); track >= 6; track--) + { + index = ( index << 16 ) + idxs[track] ; + } + index_n[3] = ( ((unsigned int)idxs[5]) << 8 ) + ( ( idxs[4] >> 8 ) & 0xff ); + index_n[2] = ( ( ((unsigned int)idxs[4]) << 16 ) + idxs[3] ) & 0xffffffUL; + index_n[1] = ( ((unsigned int)idxs[2]) << 8 ) + ( ( idxs[1] >> 8 ) & 0xff ); + index_n[0] = ( ( ((unsigned int) idxs[1]) << 16 ) + idxs[0] ) & 0xffffffUL; + } + else + { + for (track=(wordcnt-1); track >= track_num; track--) + { + index = ( index << 16 ) + idxs[track] ; + } + for (track=0; track < track_num; track++) + { + index_n[track] = idxs[track]; + } + } + } + else + { + index = 0; + for (track=(wordcnt-1); track >= 2; track--) + { + index = ( index << 16 ) + idxs[track] ; + } + + index_n[3] = idxs[1] & 0xff; + index_n[2] = idxs[1] >> 8; + index_n[1] = idxs[0] & 0xff; + index_n[0] = idxs[0] >> 8; + } + + track_num1 = track_num - 1; + pulse_num1 = pulse_num[track_num1]; + index = ( index << hi_to_low[pulse_num1] ) + ( index_n[track_num1] >> low_len[pulse_num1] ); + for (track=(track_num-1); track > 0; track--) + { + track_num1 = track - 1; + pulse_num0 = pulse_num[track_num1]; + pulse_num1 = pulse_num[track]; + index = ( index << hi_to_low[pulse_num0] ) + ( index_n[track_num1] >> low_len[pulse_num0] ); + + div_tmp = index / indx_fact[pulse_num1]; + indx_tmp = index - div_tmp * indx_fact[pulse_num1]; + index_n[track] = ( index_n[track] & low_mask[pulse_num1]) + ( indx_tmp << low_len[pulse_num1] ); + index = div_tmp; + } + pulse_num1 = pulse_num[0]; + index_n[0] = ( index_n[0] & low_mask[pulse_num1]) + ( index << low_len[pulse_num1] ); + } + else + { + index = 0; + for (track=(wordcnt-1); track >= 0; track--) + { + index = ( index << 16 ) + idxs[track]; + } + for (track=3; track > 0; track--) + { + pulse_num1 = pulse_num[track]; + index_n[track] = index & index_mask_ACELP[pulse_num1]; + index = index >> index_len[pulse_num1]; + } + index_n[0] = index; + } + + return; +} diff --git a/src/libs/libevs/lib_dec/dec_acelp_tcx_main.cpp b/src/libs/libevs/lib_dec/dec_acelp_tcx_main.cpp old mode 100755 new mode 100644 index f63e1b8f..d061c2e0 --- a/src/libs/libevs/lib_dec/dec_acelp_tcx_main.cpp +++ b/src/libs/libevs/lib_dec/dec_acelp_tcx_main.cpp @@ -1,183 +1,152 @@ /*==================================================================================== - EVS Codec 3GPP TS26.442 Apr 03, 2018. Version 12.11.0 / 13.6.0 / 14.2.0 + EVS Codec 3GPP TS26.443 Nov 13, 2018. Version 12.11.0 / 13.7.0 / 14.3.0 / 15.1.0 ====================================================================================*/ - #include -#include "rom_com_fx.h" -#include "stat_com.h" +#include "stat_dec.h" +#include "prot.h" +#include "rom_com.h" #include "options.h" -#include "stl.h" -#include "prot_fx.h" -#include "basop_util.h" -static -void decode_frame_type(Decoder_State_fx *st) + +/*-------------------------------------------------------------------* +* decode_frame_type() +* +* +*--------------------------------------------------------------------*/ + +static void decode_frame_type +( + Decoder_State *st +) { - Word32 L_tmp; - Word16 num_bits; - UWord16 lsb; - Word16 frame_size_index; - Word16 n; - Word32 total_brate; - Word16 frame_len_indicator; + int frame_size_index, n, total_brate; frame_size_index = 0; - move16(); - total_brate = st->total_brate_fx; - move16(); - - Mpy_32_16_ss(st->total_brate_fx, 5243, &L_tmp, &lsb); /* 5243 is 1/50 in Q18. (0+18-15=3) */ - num_bits = extract_l(L_shr(L_tmp, 3)); /* Q0 */ - + total_brate = st->total_brate; /* Get Frame Type (NULL,SID,ACTIVE) and Frame Mode (2kbps, 4kbps,...) */ - IF (sub(st->mdct_sw, MODE1) == 0) + if (st->mdct_sw == MODE1) { st->m_frame_type = ACTIVE_FRAME; - move16(); - FOR (n=0; ntotal_brate/50) { frame_size_index = n; - move16(); - BREAK; + break; } } } - ELSE + else { /* ZERO Frame */ - IF ( L_sub(st->total_brate_fx, FRAME_NO_DATA) == 0 ) + if( st->total_brate == FRAME__NO_DATA ) { - st->bwidth_fx = st->last_bwidth_fx; - move16(); + st->bwidth = st->last_bwidth; st->m_frame_type = ZERO_FRAME; - move16(); } /* SID frame */ - ELSE IF ( L_sub(st->total_brate_fx, SID_2k40) == 0 ) + else if( st->total_brate == SID_2k40 ) { - st->cng_type_fx = get_next_indice_fx(st, 1); - if( sub(st->cng_type_fx, FD_CNG) != 0 ) + unsigned short frame_len_indicator; + st->cng_type = get_next_indice(st, 1); + if( st->cng_type != FD_CNG ) { st->BER_detect = 1; + st->cng_type = FD_CNG; } st->m_frame_type = SID_FRAME; - move16(); frame_size_index = 1; - move16(); - st->bwidth_fx = get_next_indice_fx(st, 2); - move16(); + st->bwidth = get_next_indice(st, 2); - frame_len_indicator = get_next_indice_fx(st, 1); - IF ( sub(st->bwidth_fx, NB) == 0 ) + frame_len_indicator = get_next_indice(st, 1); + if( st->bwidth == NB ) { if( frame_len_indicator ) { st->BER_detect = 1; - move16(); } frame_len_indicator = 0; - move16(); } - IF ( frame_len_indicator == 0 ) + if( frame_len_indicator == 0 ) { - st->L_frame_fx = L_FRAME; - st->total_brate_fx = 9600; + st->L_frame = L_FRAME; + st->total_brate = 9600; } - ELSE + else { - st->L_frame_fx = L_FRAME16k; - IF ( st->last_total_brate_fx==16400 || st->last_total_brate_fx==24400 ) + st->L_frame = L_FRAME16k; + if ( st->last_total_brate==16400 || st->last_total_brate==24400 ) { - st->total_brate_fx = st->last_total_brate_fx; + st->total_brate = st->last_total_brate; } - ELSE + else { - st->total_brate_fx = 16400; + st->total_brate = 16400; } } - Mpy_32_16_ss(st->total_brate_fx, 5243, &L_tmp, &lsb); /* 5243 is 1/50 in Q18. (0+18-15=3) */ - num_bits = extract_l(L_shr(L_tmp, 3)); /* Q0 */ - FOR (n=0; ntotal_brate/50) { frame_size_index = n; - move16(); - BREAK; + break; } } } - /* EVS MODES */ - ELSE + else { /* Get Frame mode */ st->m_frame_type = ACTIVE_FRAME; - move16(); - FOR (n=0; ntotal_brate/50 ) { frame_size_index = n; - move16(); - BREAK; + break; } } - IF (st->rf_flag == 0) + if (st->rf_flag == 0) { - /* Get bandwidth mode */ - st->bwidth_fx = get_next_indice_fx(st, FrameSizeConfig[frame_size_index].bandwidth_bits); - - st->bwidth_fx = add(st->bwidth_fx, FrameSizeConfig[frame_size_index].bandwidth_min); - + st->bwidth = get_next_indice(st, FrameSizeConfig[frame_size_index].bandwidth_bits); + st->bwidth += FrameSizeConfig[frame_size_index].bandwidth_min; } - ELSE + else { - st->bwidth_fx += FrameSizeConfig[frame_size_index].bandwidth_min; + st->bwidth += FrameSizeConfig[frame_size_index].bandwidth_min; } - IF (sub(st->bwidth_fx, FB) > 0) + if (st->bwidth > FB) { - st->bwidth_fx = FB; - move16(); + st->bwidth = FB; st->BER_detect = 1; - move16(); } - test(); - IF ( sub(st->bwidth_fx, SWB) > 0 && L_sub(st->total_brate_fx, ACELP_16k40) < 0 ) + if (st->bwidth > SWB && st->total_brate < ACELP_16k40) { - st->bwidth_fx = SWB; - move16(); + st->bwidth = SWB; st->BER_detect = 1; - move16(); } - /* Get reserved bits */ - IF (FrameSizeConfig[frame_size_index].reserved_bits && st->rf_flag == 0) + /* Get reserved bit */ + if (FrameSizeConfig[frame_size_index].reserved_bits && st->rf_flag == 0) { - Word16 dummyBit; - dummyBit = (Word8)get_next_indice_fx(st, 1); - move16(); - if (dummyBit != 0) + int dummy = get_next_indice(st, 1); + if (dummy != 0) { st->BER_detect = 1; - move16(); } assert( FrameSizeConfig[frame_size_index].reserved_bits == 1); } @@ -185,352 +154,289 @@ void decode_frame_type(Decoder_State_fx *st) } st->rate_switching_init = 0; - move16(); if( st->last_codec_mode != MODE2 || !st->BER_detect ) { /* Mode or Rate Change */ - test(); - test(); - test(); - IF ( (sub(st->m_frame_type, ACTIVE_FRAME) == 0 || sub(st->m_frame_type, SID_FRAME) == 0) && (s_or(s_or(s_or(s_or(L_sub(st->total_brate_fx, st->last_total_brate_fx)!=0, sub(st->bwidth_fx,st->last_bwidth_fx)!=0), sub(st->last_codec_mode, MODE1) == 0), sub(st->rf_flag, st->rf_flag_last) != 0),st->force_lpd_reset)) ) + if( (st->m_frame_type == ACTIVE_FRAME || st->m_frame_type == SID_FRAME) && ( (st->total_brate != st->last_total_brate) || (st->bwidth!=st->last_bwidth ) || (st->last_codec_mode == MODE1) || (st->rf_flag !=st->rf_flag_last) || st->force_lpd_reset) ) { + st->rate_switching_init = 1; - move16(); - /* Reconf Core */ - mode_switch_decoder_LPD( st, st->bwidth_fx, st->total_brate_fx, frame_size_index ); + mode_switch_decoder_LPD( st, st->bwidth, st->total_brate, frame_size_index ); - /* Reconf CLDFB */ - IF( sub (i_mult(st->cldfbAna_fx->no_channels,st->cldfbAna_fx->no_col), st->L_frame_fx) != 0 ) + /* Reconf. CLDFB: check if the CLDFB works on the right sample rate */ + if ( (st->cldfbAna->no_channels * st->cldfbAna->no_col) != st->L_frame ) { - Word16 newCldfbBands = CLDFB_getNumChannels(L_mult0(st->L_frame_fx,50)); - - resampleCldfb( st->cldfbAna_fx, newCldfbBands, st->L_frame_fx, 0 ); - IF ( sub (st->L_frame_fx,L_FRAME16k) <= 0 ) + resampleCldfb (st->cldfbAna, (st->L_frame * 50)); + if( st->L_frame <= L_FRAME16k ) { - resampleCldfb( st->cldfbBPF_fx, newCldfbBands, st->L_frame_fx, 0 ); + resampleCldfb (st->cldfbBPF, (st->L_frame * 50)); } } - IF ( sub(st->bwidth_fx,NB)==0 ) + + if (st->bwidth == NB) { - st->cldfbSyn_fx->bandsToZero = sub (st->cldfbSyn_fx->no_channels,10); + short nBand_nb = (8000*st->cldfbSyn->no_channels / st->output_Fs); + st->cldfbSyn->bandsToZero = st->cldfbSyn->no_channels - nBand_nb; } - ELSE + else { - st->cldfbSyn_fx->bandsToZero = 0; + st->cldfbSyn->bandsToZero = 0; } - /* Reconf FD-CNG */ - L_tmp = st->total_brate_fx; - move32(); - test(); - if( sub(st->rf_flag,1) == 0 && L_sub(st->total_brate_fx,ACELP_13k20) == 0 ) + /*Reconf Frequency-domain based CNG*/ + configureFdCngDec( st->hFdCngDec, st->bwidth, st->rf_flag==1&&st->total_brate==13200?9600:st->total_brate, st->L_frame ); + if ( st->last_L_frame!=st->L_frame && st->L_frame<=320 && st->last_L_frame<=320 ) { - L_tmp = ACELP_9k60; - move32(); - } - configureFdCngDec( st->hFdCngDec_fx, st->bwidth_fx, L_tmp, st->L_frame_fx ); - test(); - test(); - IF ( (sub(st->last_L_frame_fx,st->L_frame_fx)!=0) && (sub(st->L_frame_fx,320)<=0) && (sub(st->last_L_frame_fx,320)<=0) ) - { - lerp( st->hFdCngDec_fx->hFdCngCom->olapBufferSynth2, st->hFdCngDec_fx->hFdCngCom->olapBufferSynth2, st->L_frame_fx*2, st->last_L_frame_fx*2 ); - test(); - IF ( sub(st->m_frame_type, SID_FRAME) == 0 && sub(st->hFdCngDec_fx->hFdCngCom->frame_type_previous, ACTIVE_FRAME) != 0 ) + lerp( st->hFdCngDec->hFdCngCom->olapBufferSynth2, st->hFdCngDec->hFdCngCom->olapBufferSynth2, st->L_frame*2, st->last_L_frame*2 ); + if ( st->m_frame_type==SID_FRAME && st->hFdCngDec->hFdCngCom->frame_type_previous!= ACTIVE_FRAME ) { - lerp( st->hFdCngDec_fx->hFdCngCom->olapBufferSynth, st->hFdCngDec_fx->hFdCngCom->olapBufferSynth, st->L_frame_fx*2, st->last_L_frame_fx*2 ); - - IF( sub(st->L_frame_fx, L_FRAME) == 0 ) + lerp( st->hFdCngDec->hFdCngCom->olapBufferSynth, st->hFdCngDec->hFdCngCom->olapBufferSynth, st->L_frame*2, st->last_L_frame*2 ); + if( st->L_frame==L_FRAME) { - FOR( n=0; n < st->L_frame_fx*2; n++ ) + for (n=0; n < st->L_frame*2; n++) { - st->hFdCngDec_fx->hFdCngCom->olapBufferSynth[n] = mult_r( st->hFdCngDec_fx->hFdCngCom->olapBufferSynth[n], 20480 ); + st->hFdCngDec->hFdCngCom->olapBufferSynth[n] = st->hFdCngDec->hFdCngCom->olapBufferSynth[n]*1.25f; } } - ELSE + else { - FOR( n=0; n < st->L_frame_fx*2; n++ ) + for (n=0; n < st->L_frame*2; n++) { - st->hFdCngDec_fx->hFdCngCom->olapBufferSynth[n] = mult_r( shl(st->hFdCngDec_fx->hFdCngCom->olapBufferSynth[n],1), 26214 ); + st->hFdCngDec->hFdCngCom->olapBufferSynth[n] = st->hFdCngDec->hFdCngCom->olapBufferSynth[n]/1.25f; } } } } - IF ( sub(st->bwidth_fx,st->last_bwidth_fx)!=0 ) + if ( st->bwidth!=st->last_bwidth ) { - st->hFdCngDec_fx->hFdCngCom->msFrCnt_init_counter = 0; - st->hFdCngDec_fx->hFdCngCom->init_old = 32767; + st->hFdCngDec->hFdCngCom->msFrCnt_init_counter = 0; + st->hFdCngDec->hFdCngCom->init_old = FLT_MAX; } - /* Reconf BPF */ - st->p_bpf_noise_buf=NULL; - IF (st->tcxonly == 0) + if( st->tcxonly ) + { + st->p_bpf_noise_buf = NULL; + } + else { st->p_bpf_noise_buf = st->bpf_noise_buf; } } } - st->total_brate_fx = total_brate; + st->total_brate = total_brate; + + return; } -Word16 dec_acelp_tcx_frame(Decoder_State_fx *st, - Word16 *coder_type, - Word16 *concealWholeFrame, - Word16 *pcmBuf, - Word16 * bpf_noise_buf, - Word16 * pcmbufFB, - Word32 bwe_exc_extended[], /* i/o: bandwidth extended excitation */ - Word16 *voice_factors, /* o : voicing factors */ - Word16 pitch_buf[] /* o : floating pitch for each subframe */ - ) +/*-------------------------------------------------------------------* +* dec_acelp_tcx_frame() +* +* Main decoding function +*--------------------------------------------------------------------*/ + +void dec_acelp_tcx_frame( + Decoder_State *st, /* i/o: encoder state structure */ + short *coder_type, /* o : coder type */ + short *concealWholeFrame, /* i/o: concealment flag */ + float *output, /* o : synthesis */ + float *bpf_noise_buf, /* i/o: BPF noise buffer */ + float *pcmbufFB, + float bwe_exc_extended[], /* i/o: bandwidth extended excitation */ + float *voice_factors, /* o : voicing factors */ + float pitch_buf[] /* o : floating pitch for each subframe */ +) { - Word16 num_bits; - Word32 L_tmp; - UWord16 lsb; - Word16 bitsRead; - Word16 tmp; - Word16 i; - Word16 start_bit_pos; - Word16 param[DEC_NPRM_DIV*NB_DIV+NPRM_LPC_NEW]; - Word16 old_bwe_exc[(PIT16k_MAX + (L_FRAME16k + 1) + L_SUBFR16k) * 2]; /* excitation buffer */ - Word16 *ptr_bwe_exc; /* pointer to BWE excitation signal in the current frame */ + short i; + int start_bit_pos; + short tmp; + short bitsRead; + int param[DEC_NPRM_DIV*NB_DIV]; - Mpy_32_16_ss(st->total_brate_fx, 5243, &L_tmp, &lsb); /* 5243 is 1/50 in Q18. (0+18-15=3) */ - num_bits = extract_l(L_shr(L_tmp, 3)); /* Q0 */ - - /* -------------------------------------------------------------- */ - /* Set the bit-stream */ - /* -------------------------------------------------------------- */ + float old_bwe_exc[(PIT16k_MAX + (L_FRAME16k + 1) + L_SUBFR16k) * 2]; /* excitation buffer */ + float *ptr_bwe_exc; /* pointer to BWE excitation signal in the current frame */ - start_bit_pos = st->next_bit_pos_fx; - move16(); - - if( sub(st->rf_flag,1) == 0 ) + start_bit_pos = st->next_bit_pos; + if( st->rf_flag == 1 ) { - start_bit_pos = sub(start_bit_pos,2); + start_bit_pos -= 2; } + /* -------------------------------------------------------------- */ /* IDENTIFY FRAME TYPE */ /* -------------------------------------------------------------- */ st->m_old_frame_type = st->m_frame_type; - move16(); - IF ( *concealWholeFrame == 0) + if( *concealWholeFrame == 0 ) { - Word16 m_frame_type = st->m_frame_type; - Word16 bwidth = st->bwidth_fx; - Word16 cng_type = st->cng_type_fx; - Word16 L_frame = st->L_frame_fx; - Word32 total_brate = st->last_total_brate_fx; + unsigned char m_frame_type = st->m_frame_type; + short bwidth = st->bwidth; + short cng_type = st->cng_type; + short L_frame = st->L_frame; + long total_brate = st->last_total_brate; decode_frame_type( st ); st->force_lpd_reset = 0; - test(); - test(); - test(); - test(); - IF( (sub(st->last_codec_mode, MODE2) == 0) && (st->BER_detect || (st->prev_bfi_fx && (sub(st->m_frame_type, ZERO_FRAME) == 0) && (sub(st->m_old_frame_type, ACTIVE_FRAME) == 0) ) ) ) + if( (st->last_codec_mode) == MODE2 && (st->BER_detect || (st->prev_bfi && st->m_frame_type == ZERO_FRAME && st->m_old_frame_type == ACTIVE_FRAME))) { /* Copy back parameters from previous frame, because there is a high risk they are corrupt - * DO concealment with configuration used in previous frame */ + * Do concealment with configuration used in previous frame */ st->m_frame_type = m_frame_type; - move16(); - st->bwidth_fx = bwidth; - move16(); - st->cng_type_fx = cng_type; - move16(); - st->L_frame_fx = L_frame; - move16(); - if( st->ini_frame_fx != 0 ) + st->bwidth = bwidth; + st->cng_type = cng_type; + st->L_frame = L_frame; + if( st->ini_frame != 0 ) { - st->total_brate_fx = total_brate; - move32(); + st->total_brate = total_brate; } *concealWholeFrame = 1; - move16(); st->m_decodeMode = DEC_CONCEALMENT_EXT; - move16(); st->BER_detect = 0; - move16(); - test(); - test(); - IF( (sub(st->bwidth_fx, st->last_bwidth_fx) != 0 ) || (sub(st->rf_flag, st->rf_flag_last) != 0) || (L_sub(st->total_brate_fx, st->last_total_brate_fx) != 0) ) + if( (st->bwidth != st->last_bwidth ) || (st->rf_flag != st->rf_flag_last) || (st->total_brate != st->last_total_brate) ) { st->force_lpd_reset = 1; - move16(); } - st->core_brate_fx = st->last_core_brate_fx; - move32(); - st->bfi_fx = 1; - move16(); - IF(st->ini_frame_fx == 0 ) + st->core_brate = st->last_core_brate; + st->bfi = 1; + if(st->ini_frame == 0 ) { st->tcx_cfg.tcx_coded_lines = getNumTcxCodedLines(SWB); } } - ELSE + else { - st->core_brate_fx = st->total_brate_fx; - move32(); + st->core_brate = st->total_brate; bpf_noise_buf = st->p_bpf_noise_buf; - move16(); } } - IF( *concealWholeFrame != 0 ) + if( *concealWholeFrame != 0 ) { /* add two zero bytes for arithmetic coder flush */ - FOR( i=0; i<8*2; i++ ) + for( i=0; i<8*2; i++ ) { - st->bit_stream_fx[i] = 0; + st->bit_stream[i] = 0; } } - IF ( s_and(sub(st->m_frame_type,SID_FRAME) != 0, sub(st->m_frame_type,ZERO_FRAME) != 0) ) /* test */ + if( !(st->m_frame_type == SID_FRAME || st->m_frame_type == ZERO_FRAME) ) { /* -------------------------------------------------------------- */ /* DECODE CORE */ /* -------------------------------------------------------------- */ - tmp = sub(num_bits, sub(st->next_bit_pos_fx, start_bit_pos)); - bitsRead = 0; - move16(); - - set16_fx( old_bwe_exc + PIT16k_MAX * 2, 0, ((L_FRAME16k + 1) + L_SUBFR16k) * 2 ); - ptr_bwe_exc = old_bwe_exc + PIT16k_MAX * 2; - Copy( st->old_bwe_exc_fx, old_bwe_exc, PIT16k_MAX * 2 ); - - IF ( sub(st->m_decodeMode, DEC_NO_FRAM_LOSS) == 0 ) + if( *concealWholeFrame ) { - decoder_LPD(pcmBuf, - pcmbufFB, - &tmp, - st, - bpf_noise_buf, - 0, - &bitsRead, - coder_type, - param, - pitch_buf, - voice_factors, - ptr_bwe_exc - ); - test(); - test(); - test(); - test(); - test(); - IF( st->rate_switching_init == 0 && sub((st->last_codec_mode), MODE2) == 0 && !(st->use_partial_copy && sub(st->rf_frame_type, RF_TCXFD) >= 0 && sub(st->rf_frame_type, RF_TCXTD2) <= 0) && sub(st->bfi_fx, 1) == 0 ) + tmp = 0; /*to avoid empty counting */ + } + + tmp = st->total_brate/50 - (st->next_bit_pos - start_bit_pos); + + bitsRead = 0; + + /* update old BWE excitation buffer */ + set_f( old_bwe_exc + PIT16k_MAX * 2, 0.f, ((L_FRAME16k + 1) + L_SUBFR16k) * 2 ); + ptr_bwe_exc = old_bwe_exc + PIT16k_MAX * 2; + mvr2r( st->old_bwe_exc, old_bwe_exc, PIT16k_MAX * 2 ); + + /* Decode the LPD data */ + if( st->m_decodeMode == DEC_NO_FRAM_LOSS ) + { + decoder_LPD( output, pcmbufFB, &tmp, st, bpf_noise_buf, 0, + &bitsRead, coder_type, param, pitch_buf, voice_factors, ptr_bwe_exc ); + if( !st->rate_switching_init && (st->last_codec_mode) == MODE2 && !(st->use_partial_copy && st->rf_frame_type >= RF_TCXFD && st->rf_frame_type <= RF_TCXTD2) && st->bfi ) { *concealWholeFrame = 1; - move16(); st->m_decodeMode = DEC_CONCEALMENT_EXT; - move16(); st->BER_detect = 0; - move16(); } } - ELSE IF (sub(st->m_decodeMode, DEC_CONCEALMENT_EXT) == 0) + else if( st->m_decodeMode == DEC_CONCEALMENT_EXT ) { - /* Decode the LPD data */ - decoder_LPD( pcmBuf, - pcmbufFB, - NULL, - st, - bpf_noise_buf, - 1, - &bitsRead, - coder_type, - NULL, - pitch_buf, - voice_factors, - ptr_bwe_exc - ); + decoder_LPD( output, pcmbufFB, NULL, st, bpf_noise_buf, 1, /* bfi - st->bfi can be 0 here - MODE2 stays in PLC when DTX appears after a loss */ + &bitsRead, coder_type, NULL, pitch_buf, voice_factors, ptr_bwe_exc ); } - test(); - test(); - test(); - test(); - IF( ( st->bfi_fx == 0 && (sub(st->prev_bfi_fx, 1) == 0 || sub(st->prev_use_partial_copy,1) == 0)) || ((sub(st->last_vbr_hw_BWE_disable_dec_fx,1) == 0) && (st->vbr_hw_BWE_disable_dec_fx == 0)) ) + + if( ( !st->bfi && (st->prev_bfi || st->prev_use_partial_copy )) || ((st->last_vbr_hw_BWE_disable_dec==1) && (st->vbr_hw_BWE_disable_dec==0)) ) { - st->bwe_non_lin_prev_scale_fx = 0; - set16_fx( st->old_bwe_exc_extended_fx, 0, NL_BUFF_OFFSET ); + st->bwe_non_lin_prev_scale = 0.0f; + set_f( st->old_bwe_exc_extended, 0.0f, NL_BUFF_OFFSET ); } - test(); - test(); - IF( st->core_fx == ACELP_CORE && st->igf != 0 && st->con_tcx == 0) + if( st->core == ACELP_CORE && st->igf && st->con_tcx == 0 ) { - non_linearity_fx( ptr_bwe_exc, bwe_exc_extended, L_FRAME32k, &st->bwe_non_lin_prev_scale_fx, st->Q_exc, - *coder_type, voice_factors, st->L_frame_fx - ); + non_linearity( ptr_bwe_exc, bwe_exc_extended, st->old_bwe_exc_extended, L_FRAME32k, &st->bwe_non_lin_prev_scale, *coder_type, voice_factors, st->L_frame ); /* update the old BWE exe memory */ - Copy( &old_bwe_exc[L_FRAME32k], st->old_bwe_exc_fx, PIT16k_MAX * 2 ); + mvr2r( &old_bwe_exc[L_FRAME32k], st->old_bwe_exc, PIT16k_MAX * 2 ); } - ELSE + else { - set16_fx( st->old_bwe_exc_extended_fx, 0, NL_BUFF_OFFSET ); - set16_fx( st->old_bwe_exc_fx, 0, PIT16k_MAX * 2 ); - st->bwe_non_lin_prev_scale_fx = 0; - move32(); + set_f( st->old_bwe_exc_extended, 0, NL_BUFF_OFFSET ); + set_f( st->old_bwe_exc, 0, PIT16k_MAX * 2 ); /* reset old non_linear exc during igf frames */ + st->bwe_non_lin_prev_scale = 0.0f; } /* for ACELP mode, skip core data to read TD-BWE side info */ - test(); - test(); - IF( (!st->bfi_fx) && sub(st->core_fx,ACELP_CORE) == 0 && st->total_brate_fx > 0) + if( (!st->bfi) && st->core == ACELP_CORE && st->total_brate > 0) { - /* target bs-position "-3": -2 as earlier "start_bit_pos -= 2;" are included in st->rf_target_bits - -1 as flag-bit not considered in rf_target_bits */ - IF (sub(st->rf_flag, 1)==0) + /* target bs-position "-2", because of earlier "start_bit_pos -= 2;", which are included in "st->rf_target_bits"*/ + /* from "-2" to "-3" as flag-bit not considered in rf_target_bits */ + if (st->rf_flag) { - get_next_indice_tmp_fx(st, start_bit_pos + num_bits - st->rf_target_bits - 3 - get_tbe_bits_fx(st->total_brate_fx, st->bwidth_fx, st->rf_flag) - st->next_bit_pos_fx); + get_next_indice_tmp(st, start_bit_pos + st->total_brate/50 - st->rf_target_bits - 3 - get_tbe_bits(st->total_brate, st->bwidth, st->rf_flag) - st->next_bit_pos); } - ELSE + else { - get_next_indice_tmp_fx(st, start_bit_pos + num_bits - st->rf_target_bits - get_tbe_bits_fx(st->total_brate_fx, st->bwidth_fx, st->rf_flag) - st->next_bit_pos_fx); + get_next_indice_tmp(st, start_bit_pos + st->total_brate/50 - st->rf_target_bits - get_tbe_bits(st->total_brate, st->bwidth, st->rf_flag) - st->next_bit_pos); } - tbe_read_bitstream_fx(st); + tbe_read_bitstream(st); + } + + if( *concealWholeFrame ) + { + /*"LPD dec - All BFI"*/ + + tmp = 0; /*to avoid empty counting */ } /* updates */ - st->last_voice_factor_fx = voice_factors[st->nb_subfr-1];; - move16(); - st->last_coder_type_fx = *coder_type; - + st->last_voice_factor = voice_factors[st->nb_subfr-1]; + st->last_coder_type = *coder_type; } - ELSE + else { - IF ( sub(st->m_frame_type,SID_FRAME) == 0) + + if( st->m_frame_type == SID_FRAME ) { - FdCng_decodeSID(st->hFdCngDec_fx->hFdCngCom, st); + /* Decode the FD-CNG bitstream */ + FdCng_decodeSID( st ); } /* updates */ - st->last_voice_factor_fx = 0; - move16(); - st->last_coder_type_fx = INACTIVE; - move16(); + st->last_voice_factor = 0; + st->last_coder_type = INACTIVE; + + } - return 0; + return; } diff --git a/src/libs/libevs/lib_dec/dec_amr_wb.cpp b/src/libs/libevs/lib_dec/dec_amr_wb.cpp new file mode 100644 index 00000000..8ae36482 --- /dev/null +++ b/src/libs/libevs/lib_dec/dec_amr_wb.cpp @@ -0,0 +1,124 @@ +/*==================================================================================== + EVS Codec 3GPP TS26.443 Nov 13, 2018. Version 12.11.0 / 13.7.0 / 14.3.0 / 15.1.0 + ====================================================================================*/ + +#include "options.h" +#include "cnst.h" +#include "rom_com.h" +#include "prot.h" + + +/*---------------------------------------------------------------------* + * decod_amr_wb() + * + * Decode excitation signal in AMR-WB IO mode + *---------------------------------------------------------------------*/ + +void decod_amr_wb( + Decoder_State *st, /* i/o: decoder static memory */ + const float *Aq, /* i : LP filter coefficients */ + float *pitch_buf, /* o : floating pitch values for each subframe */ + float *exc, /* i/o: adapt. excitation exc */ + float *exc2, /* i/o: adapt. excitation/total exc */ + short hf_gain[NB_SUBFR], /* o : decoded HF gain */ + float *voice_factors /* o : voicing factors */ + , float *gain_buf +) +{ + short T0, T0_frac, T0_min, T0_max;/* integer pitch variables */ + float gain_pit; /* pitch gain */ + float gain_code; /* gain/normalized gain of the algebraic excitation */ + float norm_gain_code; /* normalized gain of the algebraic excitation */ + float gain_inov; /* Innovation gain */ + float voice_fac; /* voicing factor */ + float code[L_SUBFR]; /* algebraic codevector */ + const float *p_Aq; /* Pointer to frame LP coefficient */ + float *pt_pitch; /* pointer to floating pitch */ + short i_subfr, i; /* tmp variables */ + short pitch_limit_flag; + + /*------------------------------------------------------------------* + * ACELP subframe loop + *------------------------------------------------------------------*/ + + p_Aq = Aq; /* pointer to interpolated LPC parameters */ + pt_pitch = pitch_buf; /* pointer to the pitch buffer */ + st->lt_voice_fac = 0.0f; + pitch_limit_flag = 0; /* always restrained pitch Q range in IO mode */ + + for( i_subfr = 0; i_subfr < L_FRAME; i_subfr += L_SUBFR ) + { + /*----------------------------------------------------------------------* + * Decode pitch lag + *----------------------------------------------------------------------*/ + + *pt_pitch = pit_decode( st, st->core_brate, 1, L_FRAME, i_subfr, -1, &pitch_limit_flag, &T0, &T0_frac, &T0_min, &T0_max, L_SUBFR ); + + /*--------------------------------------------------------------* + * Find the adaptive codebook vector + *--------------------------------------------------------------*/ + + pred_lt4( &exc[i_subfr], &exc[i_subfr], T0, T0_frac, L_SUBFR+1, inter4_2, L_INTERPOL2, PIT_UP_SAMP ); + + /*--------------------------------------------------------------* + * LP filtering of the adaptive excitation + *--------------------------------------------------------------*/ + + lp_filt_exc_dec( st, MODE1, st->core_brate, 1, -1, i_subfr, L_SUBFR, L_FRAME, 0,exc ); + + /*--------------------------------------------------------------* + * Innovation decoding + *--------------------------------------------------------------*/ + + inov_decode( st, st->core_brate, 1, L_FRAME, -1, 0, i_subfr, -1, p_Aq, st->tilt_code, *pt_pitch, code ); + + /*--------------------------------------------------------------* + * Gain decoding + * Estimate spectrum tilt and voicing + *--------------------------------------------------------------*/ + + gain_dec_amr_wb( st, st->core_brate, &gain_pit, &gain_code, st->past_qua_en, &gain_inov, code, &norm_gain_code ); + + /* update LP filtered gains for the case of frame erasures */ + lp_gain_updt( i_subfr, gain_pit, norm_gain_code, &st->lp_gainp, &st->lp_gainc, L_FRAME ); + + st->tilt_code = est_tilt( exc+i_subfr, gain_pit, code, gain_code, &voice_fac, L_SUBFR, 0 ); + + /*----------------------------------------------------------------------* + * Find the total excitation + *----------------------------------------------------------------------*/ + + for (i = 0; i < L_SUBFR; i++) + { + exc2[i+i_subfr] = gain_pit*exc[i+i_subfr]; + exc[i+i_subfr] = exc2[i+i_subfr] + gain_code*code[i]; + } + + /*----------------------------------------------------------------* + * Excitation enhancements + *----------------------------------------------------------------*/ + + enhancer( MODE1, st->core_brate, -1, 1, -1, L_FRAME, voice_fac, st->stab_fac, + norm_gain_code, gain_inov, &st->gc_threshold, code, exc2 + i_subfr, gain_pit, st->dispMem ); + + /*-----------------------------------------------------------------* + * HF gain modification factors at 23.85 kbps + *-----------------------------------------------------------------*/ + + if ( st->core_brate == ACELP_23k85 ) + { + hf_gain[i_subfr/L_SUBFR] = (short)get_next_indice( st,4); + } + + voice_fac = VF_0th_PARAM + VF_1st_PARAM * voice_fac + VF_2nd_PARAM * voice_fac * voice_fac; + voice_factors[i_subfr/L_SUBFR] = min( max(0.0f, voice_fac), 1.0f); + + p_Aq += (M+1); + pt_pitch++; + + st->lt_voice_fac += 0.25f*voice_fac; + gain_buf[i_subfr/L_SUBFR] = gain_pit; + } + + return; +} diff --git a/src/libs/libevs/lib_dec/dec_amr_wb_fx.cpp b/src/libs/libevs/lib_dec/dec_amr_wb_fx.cpp deleted file mode 100755 index bb1b344b..00000000 --- a/src/libs/libevs/lib_dec/dec_amr_wb_fx.cpp +++ /dev/null @@ -1,139 +0,0 @@ -/*==================================================================================== - EVS Codec 3GPP TS26.442 Apr 03, 2018. Version 12.11.0 / 13.6.0 / 14.2.0 - ====================================================================================*/ - -#include "options.h" /* Compilation switches */ -#include "cnst_fx.h" /* Common constants */ -#include "rom_com_fx.h" /* Static table prototypes */ -#include "prot_fx.h" /* Function prototypes */ -#include "stl.h" - - -/*---------------------------------------------------------------------* - * decod_amr_wb() - * - * Decode excitation signal in AMR-WB IO mode - *---------------------------------------------------------------------*/ - -void decod_amr_wb_fx( - Decoder_State_fx *st_fx, /* i/o: decoder static memory */ - const Word16 *Aq_fx, /* i : LP filter coefficients */ - Word16 *pitch_buf_fx, /* o : floating pitch values for each subframe */ - Word16 *exc_fx, /* i/o: adapt. excitation exc */ - Word16 *exc2_fx, /* i/o: adapt. excitation/total exc */ - Word16 hf_gain_fx[NB_SUBFR], /* o : decoded HF gain */ - Word16 *voice_factors_fx, /* o : voicing factors */ - Word16 *gain_buf /* o : Q14 */ -) -{ - Word16 T0, T0_frac, T0_min, T0_max; /* integer pitch variables */ - Word16 gain_pit_fx, gain_code16; /* pitch gain */ - Word32 L_gain_code_fx; /* gain/normalized gain of the algebraic excitation */ - Word32 L_norm_gain_code_fx; /* normalized gain of the algebraic excitation */ - Word16 gain_inov_fx; /* Innovation gain */ - Word16 voice_fac_fx; /* voicing factor */ - Word16 code_fx[L_SUBFR]; /* algebraic codevector */ - const Word16 *p_Aq_fx; /* Pointer to frame LP coefficient */ - Word16 *pt_pitch_fx; /* pointer to floating pitch */ - Word16 i_subfr; /* tmp variables */ - Word16 pitch_limit_flag; - Word32 L_Voice_fac_ave, L_tmp; - - /*------------------------------------------------------------------* - * Initializations - *------------------------------------------------------------------*/ - - p_Aq_fx = Aq_fx; /* pointer to interpolated LPC parameters */ - pt_pitch_fx = pitch_buf_fx; /* pointer to the pitch buffer */ - L_Voice_fac_ave = L_deposit_l(0); - pitch_limit_flag = 0; - move16(); /* always restrained pitch Q range in IO mode */ - - /*------------------------------------------------------------------* - * ACELP subframe loop - *------------------------------------------------------------------*/ - - FOR( i_subfr = 0; i_subfr < L_FRAME; i_subfr += L_SUBFR ) - { - /*----------------------------------------------------------------------* - * Decode pitch lag - *----------------------------------------------------------------------*/ - - *pt_pitch_fx = pit_decode_fx( st_fx, st_fx->core_brate_fx, 1, L_FRAME, i_subfr, -1, &pitch_limit_flag, &T0, &T0_frac, &T0_min, &T0_max, L_SUBFR ); - - /*--------------------------------------------------------------* - * Find the adaptive codebook vector - *--------------------------------------------------------------*/ - - pred_lt4(&exc_fx[i_subfr],&exc_fx[i_subfr], T0, T0_frac, L_SUBFR+1, pitch_inter4_2, L_INTERPOL2, PIT_UP_SAMP); - - /*--------------------------------------------------------------* - * LP filtering of the adaptive excitation - *--------------------------------------------------------------*/ - - lp_filt_exc_dec_fx( st_fx, MODE1, st_fx->core_brate_fx, 1, -1, i_subfr, L_SUBFR, L_FRAME, 0, exc_fx ); - - /*--------------------------------------------------------------* - * Innovation decoding - *--------------------------------------------------------------*/ - - inov_decode_fx( st_fx, st_fx->core_brate_fx, 1, L_FRAME, -1, 0, i_subfr, -1, p_Aq_fx, st_fx->tilt_code_fx, *pt_pitch_fx, code_fx); - - /*--------------------------------------------------------------* - * Gain decoding - * Estimate spectrum tilt and voicing - *--------------------------------------------------------------*/ - - gain_dec_amr_wb_fx( st_fx, st_fx->core_brate_fx, &gain_pit_fx, &L_gain_code_fx, st_fx->past_qua_en_fx, &gain_inov_fx, code_fx, &L_norm_gain_code_fx ); - - /* update LP filtered gains for the case of frame erasures */ - lp_gain_updt_fx( i_subfr, gain_pit_fx, L_norm_gain_code_fx, &st_fx->lp_gainp_fx, &st_fx->lp_gainc_fx, L_FRAME ); - - st_fx->tilt_code_fx = est_tilt_fx( exc_fx+i_subfr, gain_pit_fx, code_fx, L_gain_code_fx, &voice_fac_fx, st_fx->Q_exc ); - - Rescale_exc( st_fx->dct_post_old_exc_fx, &exc_fx[i_subfr], NULL, st_fx->last_exc_dct_in_fx, L_SUBFR, 0, - L_gain_code_fx, &(st_fx->Q_exc), st_fx->Q_subfr, exc2_fx, i_subfr, -1 ); - - gain_code16 = round_fx(L_shl(L_gain_code_fx,st_fx->Q_exc)); /*Q_exc*/ - - /*----------------------------------------------------------------------* - * Find the total excitation - *----------------------------------------------------------------------*/ - - Acelp_dec_total_exc( exc_fx, exc2_fx, gain_code16, gain_pit_fx, i_subfr, code_fx ); - - /*----------------------------------------------------------------* - * Excitation enhancements - *----------------------------------------------------------------*/ - - enhancer_fx( st_fx->core_brate_fx, 1, -1, i_subfr, L_FRAME, voice_fac_fx, st_fx->stab_fac_fx, - L_norm_gain_code_fx, gain_inov_fx, &st_fx->gc_threshold_fx, code_fx, exc2_fx, gain_pit_fx, &(st_fx->dm_fx),st_fx->Q_exc ); - - /*-----------------------------------------------------------------* - * HF gain modification factors at 23.85 kbps - *-----------------------------------------------------------------*/ - - IF ( L_sub(st_fx->core_brate_fx,ACELP_23k85) == 0 ) - { - hf_gain_fx[shr(i_subfr,6)] = (Word16)get_next_indice_fx(st_fx, 4); - } - - /*voice_fac = VF_0th_PARAM + VF_1st_PARAM * voice_fac + VF_2nd_PARAM * voice_fac * voice_fac;*/ - L_tmp = L_mult(VF_2nd_PARAM_FX, mult_r(voice_fac_fx, voice_fac_fx)); - L_tmp = L_mac(L_tmp, VF_1st_PARAM_FX, voice_fac_fx); - voice_fac_fx = mac_r(L_tmp, VF_0th_PARAM_FX, 32767); - - /*voice_factors[i_subfr/L_SUBFR] = min( max(0.0f, voice_fac), 1.0f);*/ - voice_factors_fx[i_subfr/L_SUBFR] = s_min(s_max(0, voice_fac_fx),32767); - move16(); - p_Aq_fx += (M+1); - pt_pitch_fx++; - - L_Voice_fac_ave = L_mac(L_Voice_fac_ave, 8192, voice_fac_fx); - gain_buf[i_subfr/L_SUBFR] = gain_pit_fx; - } - - st_fx->lt_voice_fac_fx = round_fx(L_Voice_fac_ave); - - return; -} diff --git a/src/libs/libevs/lib_dec/dec_gen_voic.cpp b/src/libs/libevs/lib_dec/dec_gen_voic.cpp new file mode 100644 index 00000000..990a1586 --- /dev/null +++ b/src/libs/libevs/lib_dec/dec_gen_voic.cpp @@ -0,0 +1,267 @@ +/*==================================================================================== + EVS Codec 3GPP TS26.443 Nov 13, 2018. Version 12.11.0 / 13.7.0 / 14.3.0 / 15.1.0 + ====================================================================================*/ + +#include +#include +#include "options.h" +#include "cnst.h" +#include "rom_com.h" +#include "prot.h" + + +/*---------------------------------------------------------------------* + * decod_gen_voic() + * + * Decode generic (GC), voiced (VC) and AMR-WB IO frames + *---------------------------------------------------------------------*/ + +void decod_gen_voic( + Decoder_State *st, /* i/o: decoder static memory */ + const short L_frame, /* i : length of the frame */ + const short sharpFlag, /* i : formant sharpening flag */ + const float *Aq, /* i : LP filter coefficient */ + const short coder_type, /* i : coding type */ + const float Es_pred, /* i : predicted scaled innov. energy */ + const short do_WI, /* i : FEC fast recovery flag */ + float *pitch_buf, /* o : floating pitch values for each subframe */ + float *voice_factors, /* o : voicing factors */ + float *exc, /* i/o: adapt. excitation exc */ + float *exc2, /* i/o: adapt. excitation/total exc */ + float *bwe_exc, /* o : excitation for SWB TBE */ + short *unbits, /* number of unused bits */ + float *gain_buf +) +{ + short T0 = PIT_MIN, T0_frac = 0, T0_min, T0_max;/* integer pitch variables */ + float gain_pit = 0.0f; /* pitch gain */ + float gain_code = 0.0f; /* gain/normalized gain of the algebraic excitation */ + float norm_gain_code = 0.0f; /* normalized gain of the algebraic excitation */ + float gain_inov = 0; /* Innovation gain */ + float gains_mem[2*(NB_SUBFR-1)];/* pitch gain and code gain from previous subframes */ + float voice_fac; /* voicing factor */ + float code[L_SUBFR]; /* algebraic codevector */ + + const float *p_Aq; /* Pointer to frame LP coefficient */ + float *pt_pitch; /* pointer to floating pitch */ + short i_subfr, i; /* tmp variables */ + int offset; + float error = 0.0f; + float gain_preQ = 0; /* Gain of prequantizer excitation */ + float code_preQ[L_SUBFR]; /* Prequantizer excitation */ + float norm_gain_preQ; + short pitch_limit_flag; + + DTFS_STRUCTURE *PREVP, *CURRP; + short shft_prev = 0, shft_curr = 0; + float ph_offset, dummy2[2], out[L_FRAME16k], enratio = 0.0f; + float sp_enratio, curr_spch_nrg, prev_spch_nrg, curr_res_nrg, prev_res_nrg, syn_tmp[L_FRAME16k], mem_tmp[M]; + short harm_flag_acelp; + + /* read harmonicity flag */ + harm_flag_acelp = 0; + if( st->core_brate > ACELP_24k40 && st->core_brate <= ACELP_32k && coder_type == GENERIC ) + { + harm_flag_acelp = (short)get_next_indice( st, 1 ); + } + + /*------------------------------------------------------------------* + * ACELP subframe loop + *------------------------------------------------------------------*/ + + p_Aq = Aq; /* pointer to interpolated LPC parameters */ + pt_pitch = pitch_buf; /* pointer to the pitch buffer */ + norm_gain_preQ = 0.0f; + gain_preQ = 0; + set_f( code_preQ, 0, L_SUBFR ); + + for( i_subfr = 0; i_subfr < L_frame; i_subfr += L_SUBFR ) + { + + /*----------------------------------------------------------------------* + * Decode pitch lag + *----------------------------------------------------------------------*/ + + *pt_pitch = pit_decode( st, st->core_brate, 0, L_frame, i_subfr, coder_type, &pitch_limit_flag, &T0, &T0_frac, &T0_min, &T0_max, L_SUBFR ); + + /*--------------------------------------------------------------* + * Find the adaptive codebook vector + *--------------------------------------------------------------*/ + + pred_lt4( &exc[i_subfr], &exc[i_subfr], T0, T0_frac, L_SUBFR+1, inter4_2, L_INTERPOL2, PIT_UP_SAMP ); + + if( L_frame == L_FRAME ) + { + offset = tbe_celp_exc_offset(T0, T0_frac); + for (i=0; icore_brate, 0, coder_type, i_subfr, L_SUBFR, L_frame, 0, exc ); + + /*-----------------------------------------------------------------* + * Transform-domain contribution decoding (active frames) + *-----------------------------------------------------------------*/ + + if( st->core_brate > ACELP_24k40 && coder_type != INACTIVE ) + { + gain_code = 0.0f; + transf_cdbk_dec( st, st->core_brate, coder_type, harm_flag_acelp, i_subfr, -1, Es_pred, + gain_code, &st->mem_preemp_preQ, &gain_preQ, &norm_gain_preQ, code_preQ, unbits ); + } + + /*--------------------------------------------------------------* + * Innovation decoding + *--------------------------------------------------------------*/ + + inov_decode( st, st->core_brate, 0, L_frame, coder_type, sharpFlag, i_subfr, -1, p_Aq, st->tilt_code,*pt_pitch, code ); + + /*--------------------------------------------------------------* + * Gain decoding + * Estimate spectrum tilt and voicing + *--------------------------------------------------------------*/ + + if ( st->core_brate <= ACELP_8k00 ) + { + gain_dec_lbr( st, st->core_brate, coder_type, i_subfr, code, &gain_pit, &gain_code, &gain_inov, &norm_gain_code, gains_mem ); + } + else if ( st->core_brate > ACELP_32k ) + { + gain_dec_SQ( st, st->core_brate, coder_type, i_subfr, -1, code, Es_pred, &gain_pit, &gain_code, &gain_inov, &norm_gain_code ); + } + else + { + gain_dec_mless( st, st->core_brate, L_frame, coder_type, i_subfr, -1, code, Es_pred, &gain_pit, &gain_code, &gain_inov, &norm_gain_code ); + } + + st->tilt_code = est_tilt( exc+i_subfr, gain_pit, code, gain_code, &voice_fac,L_SUBFR,0 ); + + /*-----------------------------------------------------------------* + * Transform-domain contribution decoding (inactive frames) + *-----------------------------------------------------------------*/ + + if( st->core_brate > ACELP_24k40 && coder_type == INACTIVE ) + { + transf_cdbk_dec( st, st->core_brate, coder_type, 0, i_subfr, -1, Es_pred, gain_code, + &st->mem_preemp_preQ, &gain_preQ, &norm_gain_preQ, code_preQ, unbits ); + } + + /* update LP filtered gains for the case of frame erasures */ + lp_gain_updt( i_subfr, gain_pit, norm_gain_code + norm_gain_preQ, &st->lp_gainp, &st->lp_gainc, L_frame ); + + /*----------------------------------------------------------------------* + * Find the total excitation + *----------------------------------------------------------------------*/ + + for (i = 0; i < L_SUBFR; i++) + { + exc2[i+i_subfr] = gain_pit*exc[i+i_subfr]; + exc[i+i_subfr] = exc2[i+i_subfr] + gain_code*code[i]; + } + + /*-----------------------------------------------------------------* + * Add the ACELP pre-quantizer contribution + *-----------------------------------------------------------------*/ + + if( st->core_brate > ACELP_24k40 ) + { + for ( i = 0; i < L_SUBFR; i++ ) + { + exc2[i+i_subfr] += gain_preQ * code_preQ[i]; + exc[i+i_subfr] += gain_preQ * code_preQ[i]; + } + } + + /*-----------------------------------------------------------------* + * Prepare TBE excitation + *-----------------------------------------------------------------*/ + + prep_tbe_exc( L_frame, i_subfr, gain_pit, gain_code, code, voice_fac, &voice_factors[i_subfr/L_SUBFR], bwe_exc, + gain_preQ, code_preQ, T0, coder_type, st->core_brate ); + + /*----------------------------------------------------------------* + * Excitation enhancements (update of total excitation signal) + *----------------------------------------------------------------*/ + if( st->core_brate > ACELP_32k || coder_type == INACTIVE ) + { + mvr2r( exc+i_subfr, exc2+i_subfr, L_SUBFR ); + } + else + { + enhancer( MODE1, st->core_brate, -1, 0, coder_type, L_frame, voice_fac, st->stab_fac, + norm_gain_code, gain_inov, &st->gc_threshold, code, exc2 + i_subfr, gain_pit, st->dispMem ); + } + + p_Aq += (M+1); + pt_pitch++; + gain_buf[i_subfr/L_SUBFR] = gain_pit; + st->tilt_code_dec[i_subfr/L_SUBFR] = st->tilt_code; + } + + /* FEC fast recovery */ + if ( do_WI ) + { + shft_prev = L_EXC_MEM - (short) rint_new(st->bfi_pitch); + prev_res_nrg = sum2_f( st->old_exc2+shft_prev, (short) rint_new(st->bfi_pitch) ) + 1e-6f; + prev_spch_nrg = sum2_f( st->old_syn2+shft_prev, (short) rint_new(st->bfi_pitch) ) + 1e-6f; + + mvr2r( st->mem_syn2, mem_tmp, M ); + syn_12k8( st->L_frame, Aq, exc2, syn_tmp, mem_tmp, 1 ); + + shft_curr = st->L_frame - (short) rint_new(pitch_buf[NB_SUBFR16k-1]); + curr_res_nrg = sum2_f(exc2+shft_curr, (short) rint_new(pitch_buf[NB_SUBFR16k-1])); + curr_spch_nrg = sum2_f(syn_tmp+shft_curr,(short) rint_new(pitch_buf[NB_SUBFR16k-1])); + + enratio = curr_res_nrg/prev_res_nrg; + sp_enratio = curr_spch_nrg/prev_spch_nrg; + + if ( enratio > 0.25f && + enratio < 15.0f && + sp_enratio > 0.15f && + st->bfi_pitch < 150 && + pitch_buf[NB_SUBFR16k-1] < 150 ) + { + PREVP = DTFS_new(); + CURRP = DTFS_new(); + + DTFS_to_fs( st->old_exc2+shft_prev, (short)rint_new( st->bfi_pitch ), PREVP, (short)st->output_Fs, do_WI ); + DTFS_to_fs( exc2+shft_curr, (short)rint_new( pitch_buf[NB_SUBFR16k-1] ), CURRP, (short)st->output_Fs, do_WI ); + + ph_offset = 0.0f; + WIsyn( *PREVP, CURRP, dummy2, &ph_offset, out, st->L_frame, 1 ); + + mvr2r( out, exc2, st->L_frame); + mvr2r( exc2, exc, st->L_frame); + + /* update bwe_exc for SWB-TBE */ + for (i_subfr = 0; i_subfr < L_frame; i_subfr += L_SUBFR) + { + interp_code_4over2( exc + i_subfr, bwe_exc + (i_subfr*2), L_SUBFR ); + } + + free(PREVP); + free(CURRP); + } + } + + /* SC-VBR */ + st->prev_gain_pit_dec = gain_pit; + + return; +} diff --git a/src/libs/libevs/lib_dec/dec_gen_voic_fx.cpp b/src/libs/libevs/lib_dec/dec_gen_voic_fx.cpp deleted file mode 100755 index e6ee5c36..00000000 --- a/src/libs/libevs/lib_dec/dec_gen_voic_fx.cpp +++ /dev/null @@ -1,443 +0,0 @@ -/*==================================================================================== - EVS Codec 3GPP TS26.442 Apr 03, 2018. Version 12.11.0 / 13.6.0 / 14.2.0 - ====================================================================================*/ - -#include -#include "options.h" /* Compilation switches */ -#include "cnst_fx.h" /* Common constants */ -#include "rom_com_fx.h" /* Static table prototypes */ -#include "prot_fx.h" /* Function prototypes */ -#include "stl.h" -#include "basop_util.h" - - -/*======================================================================*/ -/* FUNCTION : decod_gen_voic_fx() */ -/*----------------------------------------------------------------------*/ -/* PURPOSE : Decode generic (GC), voiced (VC) and AMR-WB IO frames */ -/* */ -/*----------------------------------------------------------------------*/ -/* GLOBAL INPUT ARGUMENTS : */ -/* _ (Struct) st_fx : decoder static memory */ -/* _ (Word16) L_frame_fx : length of the frame */ - -/* _ (Word16[]) Aq_fx : LP filter coefficient Q12 */ -/* _ (Word16) coder_type_fx : coding type Q12 */ -/* _ (Word16) Es_pred_fx : predicted scaled innov. energy Q8 */ -/* _ (Word16[]) pitch_buf_fx : floating pitch values for each subframe Q6*/ -/* _ (Word16[]) voice_factors_fx: frame error rate Q15 */ -/*----------------------------------------------------------------------*/ -/* OUTPUT ARGUMENTS : */ -/* _ (Word16[]) exc_fx : adapt. excitation exc (Q_exc) */ -/* _ (Word16[]) exc2_fx : adapt. excitation/total exc (Q_exc) */ -/*----------------------------------------------------------------------*/ - - -/*----------------------------------------------------------------------*/ -/* RETURN ARGUMENTS : */ -/* _ None */ -/*======================================================================*/ - -void decod_gen_voic_fx( - Decoder_State_fx *st_fx, /* i/o: decoder static memory */ - const Word16 L_frame_fx, /* i : length of the frame */ - const Word16 sharpFlag_fx, /* i : formant sharpening flag */ - const Word16 *Aq_fx, /* i : LP filter coefficient */ - const Word16 coder_type_fx, /* i : coding type */ - const Word16 Es_pred_fx, /* i : predicted scaled innov. energy */ - const Word16 do_WI_fx, /* i : do interpolation after a FER */ - Word16 *pitch_buf_fx, /* o : floating pitch values for each subframe */ - Word16 *voice_factors_fx, /* o : voicing factors */ - Word16 *exc_fx, /* i/o: adapt. excitation exc */ - Word16 *exc2_fx, /* i/o: adapt. excitation/total exc */ - Word16 *bwe_exc_fx, /* o : excitation for SWB TBE */ - Word16 *unbits, /* number of unused bits */ - Word16 *gain_buf -) -{ - - - Word16 T0_fx, T0_frac_fx, T0_min_fx, T0_max_fx;/* integer pitch variables */ - Word16 gain_pit_fx = 0; /* pitch gain Q14 */ - Word32 gain_code_fx=0; /* gain/normalized gain of the algebraic excitation Q16 */ - Word32 norm_gain_code_fx=0; /* normalized gain of the algebraic excitation Q16 */ - Word16 gain_inov_fx=0; /* Innovation gain Q12 */ - Word32 gc_mem[NB_SUBFR-1]; /* gain_code from previous subframes */ - Word16 gp_mem[NB_SUBFR-1]; /* gain_pitch from previous subframes */ - Word16 voice_fac_fx; /* voicing factor Q15 */ - Word16 code_fx[L_SUBFR]; /* algebraic codevector Q12 */ - - const Word16 *p_Aq_fx; /* Pointer to frame LP coefficient Q12 */ - Word16 *pt_pitch_fx; /* pointer to floating pitch Q6 */ - Word16 i_subfr_fx, i; /* tmp variables */ - Word16 error_fx = 0; - Word16 gain_preQ_fx = 0; /* Gain of prequantizer excitation */ - Word16 code_preQ_fx[L_SUBFR]; /* Prequantizer excitation */ - Word32 norm_gain_preQ_fx; - Word16 pitch_limit_flag_fx; - - Word16 tmp1_fx,gain_code16; - Word32 L_tmp_GC; - Word32 L_tmp; - - Word16 harm_flag_acelp; - - Word16 shft_prev, ph_offset_fx; - Word32 prev_res_nrg; - Word32 prev_spch_nrg; - Word32 curr_res_nrg; - Word32 curr_spch_nrg; - Word16 rint_bfi_pitch, rint_pitch; - Word16 fraca, fracb, expa, expb, scale, exp1; - Word16 *p_exc; - Word16 mem_tmp_fx[M]; - Word16 syn_tmp_fx[L_FRAME16k]; - Word16 shft_curr; - Word16 *p_syn; - Word16 sp_enratio, Qsp_enratio; - Word16 enratio, Qenratio; - DTFS_STRUCTURE_FX *PREVP, *CURRP; - Word16 S_fx[PIT_MAX*4+1], C_fx[PIT_MAX*4+1]; - Word16 dummy2[2]; - Word16 out_fx[L_FRAME16k]; - - Word16 pf_temp1[MAXLAG_WI]; /*may not need more than MAXLAG_WI/2+1 */ - Word16 pf_temp2[MAXLAG_WI]; - Word16 pf_temp[MAXLAG_WI]; - Word16 pf_n2[MAXLAG_WI]; - - - - T0_fx = PIT_MIN; - move16(); - T0_frac_fx = 0; - move16(); - - /* read harmonicity flag */ - harm_flag_acelp = 0; - move16(); - test(); - test(); - IF( (L_sub(st_fx->core_brate_fx,ACELP_24k40) > 0 && L_sub(st_fx->core_brate_fx,ACELP_32k) <= 0) && sub(coder_type_fx,GENERIC) == 0 ) - { - harm_flag_acelp = (Word16)get_next_indice_fx( st_fx, 1 ); - } - - /*------------------------------------------------------------------* - * ACELP subframe loop - *------------------------------------------------------------------*/ - - p_Aq_fx = Aq_fx; - move16(); /* pointer to interpolated LPC parameters */ - pt_pitch_fx = pitch_buf_fx; - move16(); /* pointer to the pitch buffer */ - norm_gain_preQ_fx = 0; - move16(); - gain_preQ_fx = 0; - move16(); - set16_fx( code_preQ_fx, 0, L_SUBFR ); - - FOR( i_subfr_fx = 0; i_subfr_fx < L_frame_fx; i_subfr_fx += L_SUBFR ) - { - /*----------------------------------------------------------------------* - * Decode pitch lag - *----------------------------------------------------------------------*/ - - *pt_pitch_fx = pit_decode_fx( st_fx, st_fx->core_brate_fx, 0, L_frame_fx, i_subfr_fx, coder_type_fx, &pitch_limit_flag_fx, - &T0_fx, &T0_frac_fx, &T0_min_fx, &T0_max_fx, L_SUBFR ); - move16(); /*Q6*/ - - /*--------------------------------------------------------------* - * Find the adaptive codebook vector - *--------------------------------------------------------------*/ - - pred_lt4( &exc_fx[i_subfr_fx], &exc_fx[i_subfr_fx], T0_fx, T0_frac_fx, L_SUBFR+1, pitch_inter4_2, L_INTERPOL2, PIT_UP_SAMP ); - - tbe_celp_exc( L_frame_fx,i_subfr_fx,T0_fx, T0_frac_fx, &error_fx, bwe_exc_fx ); - - /*--------------------------------------------------------------* - * LP filtering of the adaptive excitation - *--------------------------------------------------------------*/ - - lp_filt_exc_dec_fx( st_fx, MODE1, st_fx->core_brate_fx, 0, coder_type_fx, i_subfr_fx, L_SUBFR, L_frame_fx, 0, exc_fx ); - - /*-----------------------------------------------------------------* - * Transform-domain contribution decoding (active frames) - *-----------------------------------------------------------------*/ - - test(); - IF( L_sub(st_fx->core_brate_fx,ACELP_24k40) > 0 && sub(coder_type_fx,INACTIVE) != 0 ) - { - gain_code_fx = 0; - move16(); - transf_cdbk_dec_fx( st_fx, st_fx->core_brate_fx, coder_type_fx, harm_flag_acelp, i_subfr_fx, -1, Es_pred_fx, gain_code_fx, &st_fx->mem_preemp_preQ_fx, - &gain_preQ_fx, &norm_gain_preQ_fx, code_preQ_fx, unbits ); - } - - /*--------------------------------------------------------------* - * Innovation decoding - *--------------------------------------------------------------*/ - - inov_decode_fx( st_fx, st_fx->core_brate_fx, 0, L_frame_fx, coder_type_fx, - sharpFlag_fx, i_subfr_fx, -1, p_Aq_fx, st_fx->tilt_code_fx, *pt_pitch_fx, code_fx ); - - /*--------------------------------------------------------------* - * Gain decoding - * Estimate spectrum tilt and voicing - *--------------------------------------------------------------*/ - - IF( L_sub(st_fx->core_brate_fx,ACELP_8k00) <= 0) - { - gain_dec_lbr_fx( st_fx, st_fx->core_brate_fx, coder_type_fx, i_subfr_fx, code_fx, &gain_pit_fx, &gain_code_fx, &gain_inov_fx, &norm_gain_code_fx, gc_mem, gp_mem ); - } - ELSE IF( L_sub(st_fx->core_brate_fx,ACELP_32k) > 0 ) - { - gain_dec_SQ_fx( st_fx, st_fx->core_brate_fx, coder_type_fx, i_subfr_fx, -1, code_fx, Es_pred_fx, &gain_pit_fx, &gain_code_fx, &gain_inov_fx, &norm_gain_code_fx ); - } - ELSE - { - gain_dec_mless_fx( st_fx, st_fx->core_brate_fx, L_frame_fx, coder_type_fx, i_subfr_fx, -1, code_fx, Es_pred_fx, &gain_pit_fx, &gain_code_fx, &gain_inov_fx, &norm_gain_code_fx ); - } - st_fx->tilt_code_fx = est_tilt_fx( exc_fx+i_subfr_fx, gain_pit_fx, code_fx, gain_code_fx, &voice_fac_fx, st_fx->Q_exc ); - - /*-----------------------------------------------------------------* - * Transform domain contribution decoding - *-----------------------------------------------------------------*/ - test(); - IF( L_sub( st_fx->core_brate_fx,ACELP_24k40) > 0 && sub(coder_type_fx,INACTIVE) == 0 ) - { - transf_cdbk_dec_fx( st_fx, st_fx->core_brate_fx, coder_type_fx, harm_flag_acelp, i_subfr_fx, -1, Es_pred_fx, gain_code_fx, &st_fx->mem_preemp_preQ_fx, - &gain_preQ_fx, &norm_gain_preQ_fx, code_preQ_fx, unbits ); - } - - /* update LP filtered gains for the case of frame erasures */ - lp_gain_updt_fx( i_subfr_fx, gain_pit_fx, L_add(norm_gain_code_fx,norm_gain_preQ_fx), &st_fx->lp_gainp_fx, &st_fx->lp_gainc_fx, L_frame_fx ); - - /*----------------------------------------------------------------------* - * Find the total excitation - *----------------------------------------------------------------------*/ - - IF ( sub(L_frame_fx,L_FRAME) == 0 ) /* Rescaling for 12.8k core */ - { - Rescale_exc( st_fx->dct_post_old_exc_fx, &exc_fx[i_subfr_fx], &bwe_exc_fx[i_subfr_fx * HIBND_ACB_L_FAC], st_fx->last_exc_dct_in_fx, - L_SUBFR, L_SUBFR * HIBND_ACB_L_FAC, gain_code_fx, &(st_fx->Q_exc), st_fx->Q_subfr, exc2_fx, i_subfr_fx, coder_type_fx ); - - } - ELSE /* Rescaling for 16k core */ - { - L_tmp_GC = L_max(gain_code_fx, L_shl(gain_preQ_fx,16)); /* Chose the maximum of gain_code or the prequantizer excitation x4 to keep some room*/ - Rescale_exc( st_fx->dct_post_old_exc_fx, &exc_fx[i_subfr_fx], &bwe_exc_fx[i_subfr_fx * 2], st_fx->last_exc_dct_in_fx, - L_SUBFR, L_SUBFR * 2, L_tmp_GC, &(st_fx->Q_exc), st_fx->Q_subfr, exc2_fx, i_subfr_fx, coder_type_fx ); - } - - gain_code16 = round_fx(L_shl(gain_code_fx,st_fx->Q_exc)); /*Q_exc*/ - - /*-----------------------------------------------------------------* - * Add the ACELP pre-quantizer contribution - *-----------------------------------------------------------------*/ - - IF( L_sub(st_fx->core_brate_fx,ACELP_24k40) > 0 ) - { - tmp1_fx = add(15-Q_AVQ_OUT_DEC-2,st_fx->Q_exc); - FOR( i = 0; i < L_SUBFR; i++ ) - { - Word32 Ltmp1; - /* Contribution from AVQ layer */ - Ltmp1 = L_mult(gain_preQ_fx, code_preQ_fx[i]); /* Q2 + Q6 -> Q9*/ - Ltmp1 = L_shl(Ltmp1,tmp1_fx); /* Q16 + Q_exc */ - - /* Compute exc2 */ - L_tmp = L_shl(L_mult(gain_pit_fx,exc_fx[i+i_subfr_fx]),1); - exc2_fx[i+i_subfr_fx] = round_fx(L_add(L_tmp, Ltmp1)); - - /* code in Q9, gain_pit in Q14 */ - L_tmp = L_mult(gain_code16, code_fx[i]); - L_tmp = L_shl(L_tmp, 5); - L_tmp = L_mac(L_tmp, exc_fx[i + i_subfr_fx], gain_pit_fx); - L_tmp = L_shl(L_tmp, 1); /* saturation can occur here */ - - exc_fx[i+i_subfr_fx] = round_fx(L_add(L_tmp, Ltmp1)); - } - } - ELSE - { - Acelp_dec_total_exc( exc_fx, exc2_fx, gain_code16, gain_pit_fx, i_subfr_fx, code_fx ); - } - - /*-----------------------------------------------------------------* - * Prepare TBE excitation - *-----------------------------------------------------------------*/ - - prep_tbe_exc_fx( L_frame_fx, i_subfr_fx, gain_pit_fx, gain_code_fx, code_fx, voice_fac_fx, - &voice_factors_fx[i_subfr_fx/L_SUBFR], bwe_exc_fx, gain_preQ_fx, code_preQ_fx, - st_fx->Q_exc, T0_fx, T0_frac_fx, coder_type_fx, st_fx->core_brate_fx ); - - - /*----------------------------------------------------------------* - * Excitation enhancements (update of total excitation signal) - *----------------------------------------------------------------*/ - - test(); - IF( L_sub(st_fx->core_brate_fx,ACELP_32k) > 0 || sub(coder_type_fx,INACTIVE) == 0 ) - { - Copy( exc_fx+i_subfr_fx, exc2_fx+i_subfr_fx, L_SUBFR ); - } - ELSE - { - enhancer_fx( st_fx->core_brate_fx, 0, coder_type_fx, i_subfr_fx, L_frame_fx, voice_fac_fx, st_fx->stab_fac_fx, - norm_gain_code_fx, gain_inov_fx, &st_fx->gc_threshold_fx, code_fx, exc2_fx, gain_pit_fx, &(st_fx->dm_fx), st_fx->Q_exc ); - } - - p_Aq_fx += (M+1); - move16(); - pt_pitch_fx++; - gain_buf[i_subfr_fx/L_SUBFR] = gain_pit_fx; - move16(); - } - - /* FEC fast recovery */ - - IF( do_WI_fx ) - { - /* shft_prev = L_EXC_MEM - rint_new_fx(st_fx->bfi_pitch_fx);*/ - L_tmp = L_shl(L_deposit_l(st_fx->bfi_pitch_fx),10); /*Q16*/ - rint_bfi_pitch = rint_new_fx(L_tmp); /*Q0*/ - shft_prev = sub( L_EXC_MEM, rint_bfi_pitch ); /*Q0*/ - - p_exc = st_fx->old_exc2_fx + shft_prev; - move16(); - p_syn = st_fx->old_syn2_fx + shft_prev; - move16(); - - prev_res_nrg = L_deposit_l(1); - prev_spch_nrg = L_deposit_l(1); - FOR( i=0; iprev_Q_exc_fr */ - prev_spch_nrg = L_mac0(prev_spch_nrg, *p_syn, *p_syn); /* 2*st_fx->prev_Q_syn_fr */ - p_exc++; - p_syn++; - } - - Copy( st_fx->mem_syn2_fx, mem_tmp_fx, M ); - - syn_12k8_fx( st_fx->L_frame_fx, Aq_fx, exc2_fx, syn_tmp_fx, mem_tmp_fx, 1, st_fx->Q_exc, st_fx->Q_syn ); - - L_tmp = L_shl(L_deposit_l(pitch_buf_fx[NB_SUBFR16k-1]),10); /*Q16*/ - rint_pitch = rint_new_fx(L_tmp); /*Q0*/ - shft_curr = sub( st_fx->L_frame_fx, rint_pitch ); /*Q0*/ - - p_exc = exc2_fx + shft_curr; - move16(); - p_syn = syn_tmp_fx + shft_curr; - move16(); - - curr_res_nrg = L_deposit_l(1); - curr_spch_nrg = L_deposit_l(1); - FOR( i=0; iQ_exc */ - curr_spch_nrg = L_mac0(curr_spch_nrg, *p_syn, *p_syn); /* 2*st_fx->Q_syn */ - p_exc++; - p_syn++; - } - - /* enratio = (curr_res_nrg / prev_res_nrg); */ - IF(prev_res_nrg>0) - { - expa = norm_l(prev_res_nrg); - fraca = extract_h(L_shl(prev_res_nrg,expa)); - expa = sub(30,expa+(2*st_fx->prev_Q_exc_fr)); - - expb = norm_l(curr_res_nrg); - fracb = round_fx(L_shl(curr_res_nrg,expb)); - expb = sub(30,expb+(2*st_fx->Q_exc)); - - scale = shr(sub(fraca,fracb),15); - fracb = shl(fracb,scale); - expb = sub(expb,scale); - - enratio = div_s(fracb,fraca); - exp1 = sub(expb,expa); - Qenratio = 15-exp1; - } - ELSE - { - enratio = 0; - Qenratio = 0; - } - - /* sp_enratio = curr_spch_nrg/prev_spch_nrg */ - IF(prev_spch_nrg>0) - { - expa = norm_l(prev_spch_nrg); - fraca = extract_h(L_shl(prev_spch_nrg,expa)); - expa = sub(30,expa+(2*st_fx->prev_Q_syn_fr)); - - expb = norm_l(curr_spch_nrg); - fracb = round_fx(L_shl(curr_spch_nrg,expb)); - expb = sub(30,expb+(2*st_fx->Q_syn)); - - scale = shr(sub(fraca,fracb),15); - fracb = shl(fracb,scale); - expb = sub(expb,scale); - - sp_enratio = div_s(fracb,fraca); - exp1 = sub(expb,expa); - Qsp_enratio = 15-exp1; - } - ELSE - { - sp_enratio = 0; - Qsp_enratio = 0; - } - - test(); - test(); - test(); - test(); - IF ( sub(shl_r(enratio,15-Qenratio), 8192) > 0 && /*compare with 0.25 in Q15*/ - sub(shl_r(enratio,10-Qenratio), 15360) < 0 && /*compare with 15.0 in Q10*/ - sub(shl_r(sp_enratio,15-Qsp_enratio), 4915) > 0 &&/*compare with 0.15 in Q15*/ - st_fx->bfi_pitch_fx < 9600 && /*Q6*/ - pitch_buf_fx[ sub( NB_SUBFR16k, 1 ) ] < 9600 ) /*Q6*/ - { - PREVP = DTFS_new_fx(); - CURRP = DTFS_new_fx(); - - GetSinCosTab_fx(rint_bfi_pitch,S_fx,C_fx); - DTFS_to_fs_fx( st_fx->old_exc2_fx + shft_prev, rint_bfi_pitch, PREVP, (Word16)st_fx->output_Fs_fx, do_WI_fx, S_fx, C_fx); - PREVP->Q = add(PREVP->Q, st_fx->prev_Q_exc_fr); - - GetSinCosTab_fx(rint_pitch,S_fx,C_fx); - DTFS_to_fs_fx( exc2_fx + shft_curr, rint_pitch, CURRP, (Word16)st_fx->output_Fs_fx, do_WI_fx, S_fx, C_fx); - CURRP->Q = add(CURRP->Q, st_fx->Q_exc); - - ph_offset_fx = 0; - move16(); - WIsyn_fx(*PREVP, CURRP, dummy2, &(ph_offset_fx), out_fx, (Word16)st_fx->L_frame_fx, 1, S_fx, C_fx, pf_temp1, pf_temp2, pf_temp, pf_n2); - - - Copy_Scale_sig( out_fx, exc2_fx, st_fx->L_frame_fx, st_fx->Q_exc ); - Copy_Scale_sig( out_fx, exc_fx, st_fx->L_frame_fx, st_fx->Q_exc ); - - /* update bwe_exc for SWB-TBE */ - FOR (i_subfr_fx = 0; i_subfr_fx < L_frame_fx; i_subfr_fx += L_SUBFR) - { - interp_code_4over2_fx( exc_fx + i_subfr_fx, bwe_exc_fx + (i_subfr_fx*2), L_SUBFR ); - } - - free(PREVP); - free(CURRP); - } - - } - - /* SC-VBR */ - st_fx->prev_gain_pit_dec_fx = gain_pit_fx; - move16(); /*Q14*/ - st_fx->prev_tilt_code_dec_fx = st_fx->tilt_code_fx; - move16(); /*Q15*/ - - return; -} diff --git a/src/libs/libevs/lib_dec/dec_higher_acelp.cpp b/src/libs/libevs/lib_dec/dec_higher_acelp.cpp new file mode 100644 index 00000000..2c0d690e --- /dev/null +++ b/src/libs/libevs/lib_dec/dec_higher_acelp.cpp @@ -0,0 +1,168 @@ +/*==================================================================================== + EVS Codec 3GPP TS26.443 Nov 13, 2018. Version 12.11.0 / 13.7.0 / 14.3.0 / 15.1.0 + ====================================================================================*/ + +#include +#include "options.h" +#include "cnst.h" +#include "prot.h" +#include "rom_com.h" + +/*-----------------------------------------------------------------* + * Transform domain contribution decoding + *-----------------------------------------------------------------*/ + +void transf_cdbk_dec( + Decoder_State *st, /* i/o: decoder state structure */ + const long core_brate, /* i : core bitrate */ + const short coder_type, /* i : coding type */ + const short harm_flag_acelp,/* i : harmonic flag for higher rates ACELP */ + const short i_subfr, /* i : subframe index */ + const short tc_subfr, /* i : TC subframe index */ + const float Es_pred, /* i : predicited scaled innovation energy */ + const float gain_code, /* i : innovative excitation gain */ + float *mem_preemp, /* i/o: dequantizer preemhasis memory */ + float *gain_preQ, /* o : prequantizer excitation gain */ + float *norm_gain_preQ,/* o : normalized prequantizer excitation gain */ + float code_preQ[], /* o : prequantizer excitation */ + short *unbits /* o : number of AVQ unused bits */ +) +{ + short i, index, nBits, Nsv; + int x_norm[L_SUBFR]; + float Ecode; + short nq[L_SUBFR/WIDTH_BAND]; + + /*--------------------------------------------------------------* + * Set bit-allocation + *--------------------------------------------------------------*/ + + Nsv = 8; + nBits = AVQ_bits_16kHz_tbl[BIT_ALLOC_IDX_16KHZ(core_brate, coder_type, i_subfr, TC_SUBFR2IDX_16KHZ(tc_subfr))]; + + /* increase # of AVQ allocated bits by unused bits from the previous subframe */ + nBits += (*unbits); + + /*--------------------------------------------------------------* + * Dequantize prequantizer excitation gain + *--------------------------------------------------------------*/ + + index = (short)get_next_indice( st, G_AVQ_BITS ); + + if( coder_type == INACTIVE ) + { + if( core_brate == ACELP_64k ) + { + *gain_preQ = usdequant( index, G_AVQ_MIN_INACT_64k, G_AVQ_DELTA_INACT_64k ); + } + else if( core_brate == ACELP_48k ) + { + *gain_preQ = usdequant( index, G_AVQ_MIN_INACT_48k, G_AVQ_DELTA_INACT_48k ); + } + else + { + *gain_preQ = usdequant( index, G_AVQ_MIN_INACT, G_AVQ_DELTA_INACT ); + } + + *gain_preQ *= gain_code; + } + else + { + if( core_brate > ACELP_24k40 && core_brate <= ACELP_32k ) + { + *gain_preQ = gain_dequant( index, 0.1f*G_AVQ_MIN, G_AVQ_MAX, G_AVQ_BITS ); + } + else + { + *gain_preQ = gain_dequant( index, G_AVQ_MIN, G_AVQ_MAX, G_AVQ_BITS ); + } + if( Es_pred < 0 ) + { + *gain_preQ *= 0.25f * fabs(Es_pred); + } + else + { + *gain_preQ *= Es_pred; + } + } + + /*--------------------------------------------------------------* + * Encode and multiplex subvectors into bit-stream + *--------------------------------------------------------------*/ + + AVQ_demuxdec( st, x_norm, &nBits, Nsv, nq ); + + /* save # of AVQ unused bits for next subframe */ + *unbits = nBits; + + /*--------------------------------------------------------------* + * iDCT transform + *--------------------------------------------------------------*/ + + set_f( code_preQ, 0.0f, L_SUBFR ); + for( i=0; i ACELP_32k || harm_flag_acelp ) + { + edct2( L_SUBFR, 1, code_preQ, code_preQ, ip_edct2_64, w_edct2_64 ); + } + + /*--------------------------------------------------------------* + * Preemphasise + *--------------------------------------------------------------*/ + + /* in extreme cases at subframe boundaries, lower the preemphasis memory to avoid a saturation */ + if( (nq[7] != 0) && (st->last_nq_preQ - nq[0] > 7) ) + { + *mem_preemp /= 16; + } + + st->last_nq_preQ = nq[7]; + + preemph( code_preQ, FAC_PRE_AVQ, L_SUBFR, mem_preemp ); + + /*--------------------------------------------------------------* + * Compute normalized prequantizer excitation gain for FEC + *--------------------------------------------------------------*/ + + Ecode = (sum2_f( code_preQ, L_SUBFR ) + 0.01f) / L_SUBFR; + + /* somewhat attenuate pre-quantizer normalized gain for FEC */ + *norm_gain_preQ = 0.8f * (*gain_preQ) * (float)sqrt( Ecode ); + + st->use_acelp_preq = 1; + + return; + +} + +/*-----------------------------------------------------------* + * gain_dequant() + * + * Returns decoded gain quantized between the specified + * range using the specified number of levels. + *-----------------------------------------------------------*/ + +float gain_dequant( /* o: decoded gain */ + short index, /* i: quantization index */ + const float min, /* i: value of lower limit */ + const float max, /* i: value of upper limit */ + const short bits /* i: number of bits to dequantize */ +) +{ + float gain, c_min, c_mult; + short levels; + + levels = 1<>1 ); - } - ELSE IF( L_sub(core_brate,ACELP_48k) == 0 ) - { - gain16 = usdequant_fx( index, G_AVQ_MIN_INACT_48k_Q12, G_AVQ_DELTA_INACT_48k_Q12>>1 ); - } - ELSE - { - gain16 = usdequant_fx( index, G_AVQ_MIN_INACT_Q12, G_AVQ_DELTA_INACT_Q12>>1 ); - } - - L_tmp = Mult_32_16(gain_code,gain16); /* Q16 * Q12 - 15 -> Q13*/ - L_tmp = L_shl(L_tmp,5); /* Q13 -> Q18*/ - *gain_preQ = round_fx(L_tmp); /* Q2*/ - } - ELSE - { - IF( L_sub(core_brate,ACELP_32k) <= 0 ) - { - gain16 = gain_dequant_fx( index, G_AVQ_MIN_32kbps_Q15, G_AVQ_MAX_Q0, G_AVQ_BITS, &exp16 ); - } - ELSE - { - gain16 = gain_dequant_fx( index, G_AVQ_MIN_Q15, G_AVQ_MAX_Q0, G_AVQ_BITS, &exp16 ); - } - - IF( Es_pred < 0 ) - { - tmp16 = shr(negate(Es_pred),2); - L_tmp = L_mult(gain16,tmp16); /* Q0*Q8 -> Q9*/ - } - ELSE - { - L_tmp = L_mult(gain16,Es_pred); /* Q0*Q8 -> Q9*/ - } - L_tmp = L_shl(L_tmp,add(exp16,9)); /* Q18*/ - *gain_preQ = round_fx(L_tmp); /* Q2*/ - } - - /*--------------------------------------------------------------* - * Demultiplex and decode subvectors from bit-stream - *--------------------------------------------------------------*/ - - AVQ_demuxdec_fx(st_fx, code_preQ, &nBits, 8, nq ); - - FOR( i=0; i 0 || harm_flag_acelp ) - { - qdct = 0; - move16(); - edct2_fx( L_SUBFR, 1, code_preQ, dct_code32, &qdct, ip_edct2_64_fx, w_edct2_64_fx ); - /*qdct = sub(Q_AVQ_OUT_DEC,qdct+Q_AVQ_OUT_DEC);*/ - qdct = negate(qdct); - Copy_Scale_sig_32_16(dct_code32, code_preQ, L_SUBFR, qdct); /* Output in Q_AVQ_OUT_DEC */ - /*qdct = Q_AVQ_OUT_DEC;*/ - } - - /*--------------------------------------------------------------* - * Preemphasise - *--------------------------------------------------------------*/ - /* in extreme cases at subframe boundaries, lower the preemphasis memory to avoid a saturation */ - test(); - if( (nq[7] != 0) && (sub( sub(st_fx->last_nq_preQ_fx, nq[0]), 7) > 0) ) - { - /* *mem_preemp /= 16; */ - *mem_preemp = shr(*mem_preemp,4); - move16(); - } - st_fx->last_nq_preQ_fx = nq[7]; - move16(); - - preemph_fx( code_preQ, FAC_PRE_AVQ_FX, L_SUBFR, mem_preemp ); - - /*--------------------------------------------------------------* - * Compute normalized prequantizer excitation gain for FEC - * - * somewhat attenuate pre-quantizer normalized gain for FEC - *--------------------------------------------------------------*/ - - /*Ecode = (sum2_f( code_preQ, L_SUBFR ) + 0.01f) / L_SUBFR;*/ - /*norm_gain_preQ = 0.8f * (*gain_preQ) * (float)sqrt( Ecode );*/ - - L_tmp = Dot_product12(code_preQ, code_preQ, L_SUBFR, &exp16); - - IF( L_sub(L_tmp,L_shl(1,sub(30,exp16))) == 0 ) - { - /* pre-quantizer contribution is zero */ - *norm_gain_preQ = 1; - move16(); - } - ELSE - { - exp16 = sub(exp16, Q_AVQ_OUT_DEC*2 + 6); /* exp: (code_preQ in Q_AVQ_OUT_DEC), -6 (/L_SUBFR) */ - L_tmp = Isqrt_lc(L_tmp, &exp16); - tmp16 = extract_h(L_tmp); - exp16 = 15 - 10 - exp16; /* tmp16 in Q10+exp16*/ - tmp16 = div_s(16384,tmp16); /* Q15+Q14-(Q10+Qexp16) = Q19-exp16*/ - - L_tmp = L_mult(*gain_preQ,tmp16); /* Q2+Q19-exp16+1 -> Q22-exp16 */ - L_tmp = Mult_32_16(L_tmp, 26214 ); /* Q22-Qexp16+Q15+1-16 -> Q22-exp16*/ - *norm_gain_preQ = L_shr(L_tmp,6-exp16); - move32(); /* Q22-exp16 -> Q16*/ - } - - - st_fx->use_acelp_preq = 1; - move16(); - - return; - -} - -/*==========================================================================*/ -/* FUNCTION : Word16 gain_dequant_fx () */ -/*--------------------------------------------------------------------------*/ -/* PURPOSE : */ -/* * Returns decoded gain quantized between the specified */ -/* * range using the specified number of levels. */ -/*--------------------------------------------------------------------------*/ -/* INPUT ARGUMENTS : */ -/* Word16 index i: quantization index */ -/* Word16 min i : value of lower limit */ -/* Word16 max i : value of upper limit */ -/* Word16 bits i : number of bits to dequantize */ -/*--------------------------------------------------------------------------*/ -/* OUTPUT ARGUMENTS : */ -/* _Word16 *expg o : */ -/*--------------------------------------------------------------------------*/ -/* INPUT/OUTPUT ARGUMENTS : */ -/*--------------------------------------------------------------------------*/ -/* RETURN ARGUMENTS : */ -/* Word16 gain Q0 */ -/*--------------------------------------------------------------------------*/ -/* CALLED FROM : */ -/*==========================================================================*/ -Word16 gain_dequant_fx( /* o: decoded gain */ - Word16 index, /* i: quantization index */ - const Word16 min, /* i: value of lower limit */ - const Word16 max, /* i: value of upper limit */ - const Word16 bits, /* i: number of bits to dequantize */ - Word16 *expg -) -{ - Word16 gain, c_min, c_max; - Word16 levels; - Word16 e_tmp, f_tmp; - Word16 tmp, frac; - Word32 L_tmp; - levels = 1<Q16*/ - - frac = L_Extract_lc(L_tmp, expg); /* Extract exponent of gcode0 */ - - gain = extract_l(Pow2(14, frac));/* Put 14 as exponent so that */ - /* output of Pow2() will be: */ - /* 16384 < Pow2() <= 32767 */ - *expg = sub(*expg, 14); - - return( gain ); -} diff --git a/src/libs/libevs/lib_dec/dec_nelp.cpp b/src/libs/libevs/lib_dec/dec_nelp.cpp new file mode 100644 index 00000000..5422a3f1 --- /dev/null +++ b/src/libs/libevs/lib_dec/dec_nelp.cpp @@ -0,0 +1,57 @@ +/*==================================================================================== + EVS Codec 3GPP TS26.443 Nov 13, 2018. Version 12.11.0 / 13.7.0 / 14.3.0 / 15.1.0 + ====================================================================================*/ + +#include "options.h" +#include "cnst.h" +#include "prot.h" + +/*-------------------------------------------------------------------* +* decod_nelp() +* +* Decode unvoiced NELP +*-------------------------------------------------------------------*/ + +void decod_nelp( + Decoder_State *st, /* i/o: decoder static memory */ + const short coder_type, /* i : coding type */ + float *tmp_noise, /* o : long term temporary noise energy */ + float *pitch_buf, /* o : floating pitch values for each subframe */ + float *exc, /* o : adapt. excitation exc */ + float *exc2, /* o : adapt. excitation/total exc */ + float *voice_factors, /* o : voicing factors */ + float *bwe_exc, /* o : excitation for SWB TBE */ + const short bfi, /* i : bad frame indicator */ + float *gain_buf +) +{ + short i; + float exc_nelp[L_FRAME]; + + *tmp_noise = 0; + + nelp_decoder( st,exc_nelp,exc,bfi,coder_type, gain_buf ); + + mvr2r( exc_nelp, exc, L_FRAME ); + mvr2r( exc_nelp, exc2, L_FRAME ); + + st->tilt_code = 0.0f; /* purely unvoiced */ + set_f( st->tilt_code_dec, 0, NB_SUBFR16k ); + st->prev_tilt_code_dec = st->tilt_code; + + st->dispMem[0] = 0; + st->prev_gain_pit_dec = 0.0; + st->dispMem[2] = st->prev_gain_pit_dec; + + for(i=3; i<7; i++) + { + st->dispMem[i] = st->dispMem[i-1]; + } + + set_f(pitch_buf, L_SUBFR, NB_SUBFR); + interp_code_5over2( exc2, bwe_exc, L_FRAME ); + + set_f( voice_factors, 0.0f, NB_SUBFR16k ); + + return; +} diff --git a/src/libs/libevs/lib_dec/dec_nelp_fx.cpp b/src/libs/libevs/lib_dec/dec_nelp_fx.cpp deleted file mode 100755 index b5d210c0..00000000 --- a/src/libs/libevs/lib_dec/dec_nelp_fx.cpp +++ /dev/null @@ -1,92 +0,0 @@ -/*==================================================================================== - EVS Codec 3GPP TS26.442 Apr 03, 2018. Version 12.11.0 / 13.6.0 / 14.2.0 - ====================================================================================*/ - -#include "options.h" /* Compilation switches */ -#include "cnst_fx.h" /* Common constants */ -#include "prot_fx.h" /* Function prototypes */ -#include "stl.h" - -/*======================================================================*/ -/* FUNCTION : decod_nelp_fx() */ -/*-----------------------------------------------------------------------*/ -/* PURPOSE : Decode unvoiced NELP */ -/* */ -/*-----------------------------------------------------------------------*/ -/* GLOBAL INPUT ARGUMENTS : */ -/* _ (Struct) st_fx : decoder static memory */ -/* _ (Word16) coder_type : coding type */ -/* _ (Word16[]) tmp_noise_fx : long term temporary noise energy */ -/* _ (Word16[]) pitch_buf_fx : floating pitch values for each - subframe(Q6) */ -/* _ (Word16[]) exc_fx : adapt. excitation exc (Q_exc) */ -/* _ (Word16[]) exc2_fx : adapt. excitation/total exc (Q_exc) */ -/* _ (Word16) bfi : frame error rate */ -/*-----------------------------------------------------------------------*/ -/* OUTPUT ARGUMENTS : */ -/* _ (Word16[]) exc_fx : adapt. excitation exc (Q_exc) */ -/* _ (Word16[]) exc2_fx : adapt. excitation/total exc (Q_exc) */ -/*-----------------------------------------------------------------------*/ - -/* _ (Word16[]) tmp_noise_fx : long term temporary noise energy - (Q0) */ -/* _ (Word16[]) pitch_buf_fx : floating pitch values for each - subframe (Q6) */ -/* _ (Word16[]) st_fx->dispMem : Noise enhancer - phase dispersion - algorithm memory (Q14) */ -/* _ (Word16) st_fx->tilt_code : tilt of code (Q15) */ -/* _ (Word16) st_fx->prev_gain_pit_dec */ -/*-----------------------------------------------------------------------*/ -/* RETURN ARGUMENTS : */ -/* _ None */ -/*=======================================================================*/ - -void decod_nelp_fx( - Decoder_State_fx *st_fx, - const Word16 coder_type, - Word16 *tmp_noise_fx, - Word16 *pitch_buf_fx, - Word16 *exc_fx, - Word16 *exc2_fx, - Word16 *voice_factors, - Word16 *bwe_exc_fx, - Word16 *Q_exc, Word16 bfi - , Word16 *gain_buf -) -{ - Word16 i; - Word16 exc_nelp_fx[L_FRAME]; - - *tmp_noise_fx = 0; - move16(); - - nelp_decoder_fx(st_fx, exc_nelp_fx, exc_fx, Q_exc, bfi, coder_type - , gain_buf - - ); - - Copy(exc_nelp_fx, exc_fx, L_FRAME); - Copy(exc_nelp_fx, exc2_fx, L_FRAME); - - st_fx->tilt_code_fx = 0; - move16();/* purely unvoiced */ /* Q15 */ - set16_fx(st_fx->tilt_code_dec_fx, 0, NB_SUBFR16k); - - st_fx->dm_fx.prev_state = 0; - move16();/* Q0 */ - st_fx->prev_gain_pit_dec_fx = 0; - move16(); /* Q14 */ - st_fx->dm_fx.prev_gain_pit[0]= st_fx->prev_gain_pit_dec_fx; - move16(); /* Q16 */ - - FOR(i=1; i<5; i++) - { - st_fx->dm_fx.prev_gain_pit[i] = st_fx->dm_fx.prev_gain_pit[i-1]; - move16(); /* Q14 */ - } - - set16_fx(pitch_buf_fx, L_SUBFR_Q6, NB_SUBFR); /* L_SUBFR = 64, Q6 */ - set16_fx(voice_factors, 0, NB_SUBFR16k); - interp_code_5over2_fx( exc2_fx, bwe_exc_fx, L_FRAME ); - return; -} diff --git a/src/libs/libevs/lib_dec/dec_pit_exc.cpp b/src/libs/libevs/lib_dec/dec_pit_exc.cpp new file mode 100644 index 00000000..4c517eb8 --- /dev/null +++ b/src/libs/libevs/lib_dec/dec_pit_exc.cpp @@ -0,0 +1,196 @@ +/*==================================================================================== + EVS Codec 3GPP TS26.443 Nov 13, 2018. Version 12.11.0 / 13.7.0 / 14.3.0 / 15.1.0 + ====================================================================================*/ + +#include "options.h" +#include "cnst.h" +#include "rom_com.h" +#include "prot.h" + + +/*-------------------------------------------------------------------* + * dec_pit_exc() + * + * Decode pitch-only contribution (used by the GSC technology) + *-------------------------------------------------------------------*/ + +void dec_pit_exc( + Decoder_State *st, /* i/o: decoder static memory */ + const short L_frame, /* i : length of the frame */ + const float *Aq, /* i : LP filter coefficient */ + const float Es_pred, /* i : predicted scaled innov. energy */ + float *pitch_buf, /* o : floating pitch values for each subframe */ + float *code, /* o : innovation */ + float *exc, /* i/o: adapt. excitation exc */ + const short nb_subfr, /* i : Number of subframe considered */ + float *gain_buf +) +{ + short T0, T0_frac, T0_min, T0_max;/* integer pitch variables */ + float gain_pit; /* pitch gain */ + float gain_code; /* gain/normalized gain of the algebraic excitation */ + float norm_gain_code; /* normalized gain of the algebraic excitation */ + float gain_inov; /* Innovation gain */ + float voice_fac; /* voicing factor */ + short L_subfr, pit_idx; + const float *p_Aq; /* Pointer to frame LP coefficient */ + float *pt_pitch; /* pointer to floating pitch */ + short i_subfr, i; /* tmp variables */ + short Local_BR, Pitch_BR, Pitch_CT; + short pitch_limit_flag; + short nbits; + float *pt_gain; /* Pointer to floating gain values for each subframe */ + + if( st->GSC_noisy_speech ) + { + Local_BR = ACELP_7k20; + Pitch_CT = GENERIC; + Pitch_BR = ACELP_7k20; + } + else + { + Local_BR = ACELP_7k20; + Pitch_CT = AUDIO; + Pitch_BR = st->core_brate; + } + + gain_code = 0; + pitch_limit_flag = 1; /* always extended pitch Q range */ + + /*------------------------------------------------------------------* + * ACELP subframe loop + *------------------------------------------------------------------*/ + + L_subfr = st->L_frame/nb_subfr; + p_Aq = Aq; /* pointer to interpolated LPC parameters */ + pt_pitch = pitch_buf; /* pointer to the pitch buffer */ + pt_gain = gain_buf; /* pointer to the gain buffer */ + + for ( i_subfr = 0; i_subfr < L_FRAME; i_subfr += L_subfr ) + { + /*----------------------------------------------------------------------* + * Decode pitch lag + *----------------------------------------------------------------------*/ + + *pt_pitch = pit_decode( st, Pitch_BR, 0, L_frame, i_subfr, Pitch_CT, &pitch_limit_flag, &T0, &T0_frac, &T0_min, &T0_max, L_subfr ); + + /*--------------------------------------------------------------* + * Find the adaptive codebook vector. + *--------------------------------------------------------------*/ + + pred_lt4( &exc[i_subfr], &exc[i_subfr], T0, T0_frac, L_subfr+1, inter4_2, L_INTERPOL2, PIT_UP_SAMP ); + + /*--------------------------------------------------------------* + * Innovation decoding + *--------------------------------------------------------------*/ + + if( st->GSC_noisy_speech ) + { + inov_decode( st, Local_BR, 0, L_frame, LOCAL_CT, 1, i_subfr, -1, p_Aq, st->tilt_code, *pt_pitch, code ); + + /*--------------------------------------------------------------* + * Gain decoding + * Estimate spectrum tilt and voicing + *--------------------------------------------------------------*/ + + gain_dec_mless( st, Local_BR, L_frame, LOCAL_CT, i_subfr, -1, code, Es_pred, &gain_pit, &gain_code, &gain_inov, &norm_gain_code ); + + st->tilt_code = est_tilt( exc+i_subfr, gain_pit, code, gain_code, &voice_fac,L_SUBFR,0 ); + } + else + { + nbits = 4; + + set_f(code, 0, L_SUBFR); + gain_code = 0.0f; + st->tilt_code = 0.0f; + + pit_idx = (short)get_next_indice( st, nbits ); + + gain_pit = 0.5853f + dic_gp[pit_idx]; + + if( st->BER_detect ) /* Bitstream is corrupted, use the past pitch gain */ + { + gain_pit = st->lp_gainp; + } + } + + /*----------------------------------------------------------------------* + * Find the total excitation + *----------------------------------------------------------------------*/ + + if( st->GSC_noisy_speech ) + { + for (i = 0; i < L_subfr; i++) + { + exc[i+i_subfr] = gain_pit * exc[i+i_subfr] + gain_code * code[i]; + } + } + else + { + for (i = 0; i < L_subfr; i++) + { + exc[i+i_subfr] = gain_pit * exc[i+i_subfr]; + } + } + + if( L_subfr == 2*L_SUBFR ) + { + p_Aq += 2*(M+1); + pt_pitch++; + *pt_pitch = *(pt_pitch-1); + pt_pitch++; + *pt_gain = gain_pit; + pt_gain++; + *pt_gain = *(pt_gain-1); + pt_gain++; + + if( i_subfr == 0 ) + { + /* update gains for FEC - equivalent to lp_gain_updt() */ + st->lp_gainp = (3.0f/10.0f) * gain_pit; + st->lp_gainc = 0; + } + else + { + /* update gains for FEC - equivalent to lp_gain_updt() */ + st->lp_gainp = (7.0f/10.0f) * gain_pit; + st->lp_gainc = 0; + } + } + else if( L_subfr == 4*L_SUBFR ) + { + pt_pitch++; + *pt_pitch = *(pt_pitch-1); + pt_pitch++; + *pt_pitch = *(pt_pitch-1); + pt_pitch++; + *pt_pitch = *(pt_pitch-1); + pt_pitch++; + *pt_gain = gain_pit; + pt_gain++; + *pt_gain = *(pt_gain-1); + pt_gain++; + *pt_gain = *(pt_gain-1); + pt_gain++; + *pt_gain = *(pt_gain-1); + pt_gain++; + p_Aq += 4*(M+1); + + /* update gains for FEC - equivalent to lp_gain_updt() */ + st->lp_gainp = gain_pit; + st->lp_gainc = 0; + } + else + { + p_Aq += (M+1); + pt_pitch++; + *pt_gain = gain_pit; + pt_gain++; + + lp_gain_updt( i_subfr, gain_pit, 0, &st->lp_gainp, &st->lp_gainc, L_frame ); + } + } + + return; +} diff --git a/src/libs/libevs/lib_dec/dec_pit_exc_fx.cpp b/src/libs/libevs/lib_dec/dec_pit_exc_fx.cpp deleted file mode 100755 index b0893171..00000000 --- a/src/libs/libevs/lib_dec/dec_pit_exc_fx.cpp +++ /dev/null @@ -1,260 +0,0 @@ -/*==================================================================================== - EVS Codec 3GPP TS26.442 Apr 03, 2018. Version 12.11.0 / 13.6.0 / 14.2.0 - ====================================================================================*/ - -#include "options.h" /* Compilation switches */ -#include "cnst_fx.h" /* Common constants */ -#include "rom_com_fx.h" /* Static table prototypes */ -#include "prot_fx.h" /* Function prototypes */ -#include "stl.h" - - -/*==========================================================================*/ -/* FUNCTION : void dec_pit_exc_fx() */ -/*--------------------------------------------------------------------------*/ -/* PURPOSE : Decode pitch only contribution */ -/*--------------------------------------------------------------------------*/ -/* INPUT ARGUMENTS : */ -/* _ (Word16*) Aq_fx : LP filter coefficient Q12 */ -/* _ (Word16) coder_type_fx : coding type Q0 */ -/* _ (Word16) nb_subfr_fx :Number of subframe considered */ -/* _ (Word16) Es_pred_fx :predicted scaled innov. energy */ -/*--------------------------------------------------------------------------*/ -/* OUTPUT ARGUMENTS : */ -/* _ (Word16*) pitch_buf_fx : floating pitch values for each subframe Q6 */ -/* _ (Word16*) code_fx : innovation */ -/*--------------------------------------------------------------------------*/ -/* INPUT/OUTPUT ARGUMENTS : */ -/* Decoder_State_fx *st_fx : decoder state structure */ -/* _ (Word16*) exc_fx : adapt. excitation exc */ -/*--------------------------------------------------------------------------*/ -/* RETURN ARGUMENTS : */ -/* _ None */ -/*==========================================================================*/ -void dec_pit_exc_fx( - Decoder_State_fx *st_fx, /* i/o: decoder static memory */ - const Word16 *Aq_fx, /* i : LP filter coefficient */ - const Word16 coder_type_fx, /* i : coding type */ - const Word16 Es_pred_fx, /* i : predicted scaled innov. energy */ - Word16 *pitch_buf_fx, /* o : floating pitch values for each subframe */ - Word16 *code_fx, /* o : innovation */ - Word16 *exc_fx, /* i/o: adapt. excitation exc */ - Word16 *bwe_exc_fx, /* o : excitation for SWB TBE */ - const Word16 nb_subfr_fx /* i : Number of subframe considered */ - , Word16 *gain_buf /*Q14*/ -) -{ - Word16 T0_fx, T0_frac_fx, T0_min_fx, T0_max_fx;/* integer pitch variables */ - Word16 gain_pit_fx = 0; /* pitch gain Q14 */ - Word32 gain_code_fx; /* gain/normalized gain of the algebraic excitation Q16 */ - Word32 norm_gain_code_fx; /* normalized gain of the algebraic excitation Q16 */ - Word16 gain_inov_fx; /* Innovation gain Q12 */ - Word16 voice_fac_fx; /* voicing factor Q15 */ - Word16 L_subfr_fx,pit_idx_fx; - const Word16 *p_Aq_fx; /* Pointer to frame LP coefficient Q12 */ - Word16 *pt_pitch_fx; /* pointer to floating pitch Q6 */ - Word16 i_subfr_fx, i; /* tmp variables */ - Word16 Local_BR_fx, Pitch_BR_fx, Pitch_CT_fx; - Word16 pitch_limit_flag; - Word16 exc2_bidon[L_SUBFR]; - Word16 *pt_gain; /* Pointer to floating gain values for each subframe */ - - Word16 gain_code16,gain_pitx2; - Word32 L_tmp; - Word16 nbits; - - IF( sub(st_fx->GSC_noisy_speech_fx,1) == 0 ) - { - Local_BR_fx = ACELP_7k20; - move16(); - Pitch_CT_fx = GENERIC; - move16(); - Pitch_BR_fx = ACELP_7k20; - move16(); - } - ELSE - { - Local_BR_fx = ACELP_7k20; - move16(); - Pitch_CT_fx = AUDIO; - move16(); - Pitch_BR_fx = extract_l(st_fx->core_brate_fx); - } - gain_code_fx = 0; - move16(); - pitch_limit_flag = 1; - move16();/* always extended pitch Q range */ - - /*------------------------------------------------------------------* - * ACELP subframe loop - *------------------------------------------------------------------*/ - L_subfr_fx = mult_r(L_FRAME,div_s(1,nb_subfr_fx)); - p_Aq_fx = Aq_fx; /* pointer to interpolated LPC parameters */ - pt_pitch_fx = pitch_buf_fx; /* pointer to the pitch buffer */ - pt_gain = gain_buf; /* pointer to the gain buffer */ - FOR ( i_subfr_fx = 0; i_subfr_fx < L_FRAME; i_subfr_fx += L_subfr_fx ) - { - /*----------------------------------------------------------------------* - * Decode pitch lag - *----------------------------------------------------------------------*/ - - *pt_pitch_fx = pit_decode_fx( st_fx, Pitch_BR_fx, 0, L_FRAME, i_subfr_fx, Pitch_CT_fx, &pitch_limit_flag, &T0_fx, &T0_frac_fx, &T0_min_fx, &T0_max_fx, L_subfr_fx ); - move16(); - - /*--------------------------------------------------------------* - * Find the adaptive codebook vector. - *--------------------------------------------------------------*/ - - pred_lt4( &exc_fx[i_subfr_fx], &exc_fx[i_subfr_fx], T0_fx, T0_frac_fx, L_subfr_fx+1, pitch_inter4_2, L_INTERPOL2, PIT_UP_SAMP ); - - /*--------------------------------------------------------------* - * Innovation decoding - *--------------------------------------------------------------*/ - - IF( sub(st_fx->GSC_noisy_speech_fx,1) == 0) - { - inov_decode_fx( st_fx, Local_BR_fx, 0, L_FRAME, LOCAL_CT, 1, i_subfr_fx, -1, p_Aq_fx, st_fx->tilt_code_fx, *pt_pitch_fx, code_fx ); - /*--------------------------------------------------------------* - * Gain decoding - * Estimate spectrum tilt and voicing - *--------------------------------------------------------------*/ - - gain_dec_mless_fx( st_fx, Local_BR_fx, L_FRAME, LOCAL_CT, i_subfr_fx, -1, code_fx, Es_pred_fx, &gain_pit_fx, &gain_code_fx, &gain_inov_fx, &norm_gain_code_fx ); - - st_fx->tilt_code_fx = est_tilt_fx( exc_fx+i_subfr_fx, gain_pit_fx, code_fx, gain_code_fx, &voice_fac_fx,0 ); - } - ELSE - { - nbits = 4; - move16(); - - set16_fx(code_fx, 0, L_SUBFR); - gain_code_fx = L_deposit_l(0); - st_fx->tilt_code_fx = 0; - move16(); - pit_idx_fx = (Word16)get_next_indice_fx( st_fx, nbits ); - move16(); - - gain_pit_fx = add(9590,dic_gp_fx[pit_idx_fx]); - move16(); /*Q14 0.5853 in Q14 9590*/ - - if( st_fx->BER_detect ) /* Bitstream is corrupted, use the past pitch gain */ - { - gain_pit_fx = st_fx->lp_gainp_fx; - move16(); - } - gain_code_fx = L_mult0(s_max(sub(32767, shl(gain_pit_fx,1)), 16384), st_fx->lp_gainc_fx); /* Use gain pitch and past gain code as an indicator to help finding the best scaling value. gain_code_fx used a temp var*/ - } - - /*----------------------------------------------------------------------* - * Find the total excitation - *----------------------------------------------------------------------*/ - - Rescale_exc( st_fx->dct_post_old_exc_fx, &exc_fx[i_subfr_fx], &bwe_exc_fx[i_subfr_fx * HIBND_ACB_L_FAC], st_fx->last_exc_dct_in_fx, - L_subfr_fx, L_subfr_fx * HIBND_ACB_L_FAC, gain_code_fx, &(st_fx->Q_exc), st_fx->Q_subfr, NULL, i_subfr_fx, coder_type_fx); - - gain_code16 = round_fx(L_shl(gain_code_fx,st_fx->Q_exc)); /*Q_exc*/ - - IF( sub(st_fx->GSC_noisy_speech_fx,1) == 0) - { - Acelp_dec_total_exc( exc_fx, exc2_bidon-i_subfr_fx, gain_code16, gain_pit_fx, i_subfr_fx, code_fx ); - } - ELSE - { - IF (norm_s(s_or(gain_pit_fx, 1)) == 0) - { - FOR (i = 0; i < L_subfr_fx; i++) - { - L_tmp = L_shl(L_mult(gain_pit_fx, exc_fx[i+i_subfr_fx]), 1); /*Q16+Q_exc*/ - exc_fx[i+i_subfr_fx] = round_fx(L_tmp); /*Q_exc*/ - } - } - ELSE - { - gain_pitx2 = shl(gain_pit_fx, 1); /*Q15*/ - - FOR (i = 0; i < L_subfr_fx; i++) - { - L_tmp = L_mult(gain_pitx2, exc_fx[i+i_subfr_fx]); /*Q16+Q_exc*/ - exc_fx[i+i_subfr_fx] = round_fx(L_tmp); /*Q_exc*/ - } - } - } - IF( sub(L_subfr_fx,128) == 0) /*2*L_SUBFR*/ - { - p_Aq_fx += 2*(M+1); - move16(); - pt_pitch_fx++; - *pt_pitch_fx = *(pt_pitch_fx-1); - move16(); - pt_pitch_fx++; - *pt_gain = gain_pit_fx; - move16(); - pt_gain++; - *pt_gain = *(pt_gain-1); - move16(); - pt_gain++; - IF( i_subfr_fx == 0 ) - { - /* update gains for FEC - equivalent to lp_gain_updt() */ - st_fx->lp_gainp_fx = extract_h(L_mult(9830,gain_pit_fx)); /*Q14 (3/10 in Q15 9830)*/ - st_fx->lp_gainc_fx = 0; - move16(); - } - ELSE - { - /* update gains for FEC - equivalent to lp_gain_updt() */ - st_fx->lp_gainp_fx = extract_h(L_mult(22938,gain_pit_fx)); /*Q14 (7/10 in Q15 22938)*/ - st_fx->lp_gainc_fx = 0; - move16(); - } - } - ELSE IF( sub(L_subfr_fx,256) == 0) /*4*L_SUBFR*/ - { - pt_pitch_fx++; - *pt_pitch_fx = *(pt_pitch_fx-1); - move16(); - pt_pitch_fx++; - *pt_pitch_fx = *(pt_pitch_fx-1); - move16(); - pt_pitch_fx++; - *pt_pitch_fx = *(pt_pitch_fx-1); - move16(); - pt_pitch_fx++; - *pt_gain = gain_pit_fx; - move16(); - pt_gain++; - *pt_gain = *(pt_gain-1); - move16(); - pt_gain++; - *pt_gain = *(pt_gain-1); - move16(); - pt_gain++; - *pt_gain = *(pt_gain-1); - move16(); - pt_gain++; - p_Aq_fx += 4*(M+1); - move16(); - - /* update gains for FEC - equivalent to lp_gain_updt() */ - st_fx->lp_gainp_fx = gain_pit_fx; - move16(); - st_fx->lp_gainc_fx = 0; - move16(); - } - ELSE - { - p_Aq_fx += (M+1); - move16(); - pt_pitch_fx++; - move16(); - *pt_gain = gain_pit_fx; - move16(); - pt_gain++; - - lp_gain_updt_fx( i_subfr_fx, gain_pit_fx, 0, &st_fx->lp_gainp_fx, &st_fx->lp_gainc_fx, L_FRAME ); - } - } - - return; -} diff --git a/src/libs/libevs/lib_dec/dec_post.cpp b/src/libs/libevs/lib_dec/dec_post.cpp old mode 100755 new mode 100644 index 09b8d90a..ab7daad8 --- a/src/libs/libevs/lib_dec/dec_post.cpp +++ b/src/libs/libevs/lib_dec/dec_post.cpp @@ -1,52 +1,52 @@ /*==================================================================================== - EVS Codec 3GPP TS26.442 Apr 03, 2018. Version 12.11.0 / 13.6.0 / 14.2.0 + EVS Codec 3GPP TS26.443 Nov 13, 2018. Version 12.11.0 / 13.7.0 / 14.3.0 / 15.1.0 ====================================================================================*/ #include +#include #include "options.h" -#include "prot_fx.h" -#include "basop_util.h" -#include "stl.h" /* Weighted mops computation related code */ -#include "rom_dec_fx.h" -#include "cnst_fx.h" +#include "cnst.h" +#include "rom_com.h" +#include "prot.h" + +/*---------------------------------------------------------------------* + * Local constants + *---------------------------------------------------------------------*/ + +#define FORMAT_POST_FILT_G1 0.75f /*0.75f*/ /*denominator 0.9,0.75,0.15,0.9*/ -#define FORMAT_POST_FILT_G1 24576/*0.75f Q15*/ /*0.75f*/ /*denominator 0.9,0.75,0.15,0.9*/ -#define FORMAT_POST_FILT_G2 22938/*0.7f Q15*/ /*0.7f*/ /*numerator 0.75,0.7,0.1,0.7*/ -#define FORMAT_POST_FILT_G1_MAX 26214/*0.8f Q15*/ /*for low bit-rates on clean speech*/ -#define FORMAT_POST_FILT_G1_MIN 24576/*0.75f Q15*/ /*for high bit-rates on clean speech and noisy speech*/ /*-------------------------------------------------------------------------- * Local functions *--------------------------------------------------------------------------*/ -static void Dec_postfilt( PFSTAT * pfstat, const Word16 t0, const Word16 *signal_ptr, const Word16 *coeff, - Word16 *sig_out, const Word16 gamma1, const Word16 gamma2, const Word16 Gain_factor, const Word16 disable_hpf ); +static void Dec_postfilt( const short L_subfr, PFSTAT *pfstat, const int t0, const float *signal_ptr, const float *coeff, + float *sig_out, const float gamma1, const float gamma2, const float gain_factor, const short disable_hpf ); -static void pst_ltp( Word16 t0, Word16 * ptr_sig_in, Word16 * ptr_sig_pst0, Word16 gain_factor ); +static void pst_ltp( const int t0, const float *ptr_sig_in, float *ptr_sig_pst0, float gain_factor, const short L_subfr ); -static void search_del( Word16 t0, Word16 * ptr_sig_in, Word16 * ltpdel, Word16 * phase, Word16 * num_gltp, Word16 * den_gltp, - Word16 * sh_num_gltp, Word16 * sh_den_gltp, Word16 * y_up, Word16 * off_yup ); +static void search_del( const int t0, const float *ptr_sig_in, int *ltpdel, int *phase, float *num_gltp, float *den_gltp, + float *y_up, int *off_yup, const short L_subfr ); -static void filt_plt( Word16 * s_in, Word16 * s_ltp, Word16 * s_out, Word16 gain_plt ); +static void filt_plt( const float *s_in, const float *s_ltp, float *s_out, const float gain_plt, const short L_subfr ); -static void compute_ltp_l( Word16 * s_in, Word16 ltpdel, Word16 phase, Word16 * y_up, Word16 * num, Word16 * den, Word16 * sh_num, Word16 * sh_den ); +static void compute_ltp_l( const float *s_in, const int ltpdel, const int phase, float *y_up, float *num, float *den, const short L_subfr ); -static Word16 select_ltp( Word16 num1, Word16 den1, Word16 sh_num1, Word16 sh_den1, Word16 num2, Word16 den2, Word16 sh_num2, Word16 sh_den2 ); +static int select_ltp( const float num1, const float den1, const float num2, const float den2 ); -static void calc_st_filt( Word16 * apond2, Word16 * apond1, Word16 * parcor0, Word16 * sig_ltp_ptr, Word16 * mem_zero ); +static void modify_pst_param( const float psf_lp_noise, float *g1, float *g2, const short coder_type, float *gain_factor ); -static void modify_pst_param( const Word16 lp_noise, Word16 *g1, Word16 *g2, const Word16 coder_type, Word16 *gain_factor ); +static void Dec_formant_postfilt( PFSTAT *pfstat, const float *signal_ptr, const float *coeff, float *sig_out, + const float gamma1, const float gamma2, const short l_subfr ); -static void Dec_formant_postfilt( PFSTAT *pfstat, Word16 *signal_ptr, Word16 *coeff, Word16 *sig_out, Word16 gamma1, Word16 gamma2 ); - - -/*-------------------------------------------------------------------------- - * Init_post_filter +/*--------------------------------------------------------------------------* + * Function Init_post_filter() * - * post filter initialization + * Post-filter initialization *--------------------------------------------------------------------------*/ + void Init_post_filter( - PFSTAT * pfstat /* i : core decoder parameters */ + PFSTAT * pfstat /* i : post-filter state memories */ ) { /* It is off by default */ @@ -56,108 +56,218 @@ void Init_post_filter( pfstat->reset = 0; /* Initialize arrays and pointers */ - set16_fx(pfstat->mem_pf_in, 0, L_SUBFR); + set_zero( pfstat->mem_pf_in, L_SUBFR ); /* res2 = A(gamma2) residual */ - set16_fx(pfstat->mem_res2, 0, DECMEM_RES2); + set_zero( pfstat->mem_res2, DECMEM_RES2 ); /* 1/A(gamma1) memory */ - set16_fx(pfstat->mem_stp, 0, L_SUBFR); + set_zero( pfstat->mem_stp, L_SUBFR ); /* null memory to compute i.r. of A(gamma2)/A(gamma1) */ - set16_fx(pfstat->mem_zero, 0, M); + set_zero( pfstat->mem_zero, M ); /* for gain adjustment */ - pfstat->gain_prec = 16384; /*Q14*/ move16(); + pfstat->gain_prec = 1.0f; return; } + /*-------------------------------------------------------------------------- - * NB_post_filt: + * nb_post_filt() * - * Main routine to perform post filtering on NB synthesis + * Main routine to perform post filtering of NB signals *--------------------------------------------------------------------------*/ + void nb_post_filt( - const Word16 L_frame, /* i : frame length */ - PFSTAT *Pfstat, /* i/o: Post filter related memories */ - Word16 *psf_lp_noise, /* i : Long term noise Q8 */ - const Word16 tmp_noise, /* i : noise energy Q0 */ - Word16 *Synth, /* i : 12k8 synthesis Qsyn */ - const Word16 *Aq, /* i : LP filter coefficient Q12 */ - const Word16 *Pitch_buf, /* i : Fractionnal subframe pitch buffer Q6 */ - const Word16 coder_type, /* i : coder_type */ - const Word16 BER_detect, /* i : BER detect flag */ - const Word16 disable_hpf /* i : flag to diabled HPF */ + const short L_frame, /* i : frame length */ + const short L_subfr, /* i : sub-frame length */ + PFSTAT *pfstat, /* i/o: Post filter related memories */ + float *psf_lp_noise, /* i/o: long term noise energy */ + const float tmp_noise, /* i : noise energy */ + float *synth, /* i/o: synthesis */ + const float *Aq, /* i : LP filter coefficient */ + const float *pitch_buf, /* i : floating pitch for each subframe */ + const short coder_type, /* i : coder_type */ + const short BER_detect, /* i : BER detect flag */ + const short disable_hpf /* i : flag to disabled HPF */ ) { - Word16 i, j, Post_G1, Post_G2, Gain_factor; - Word16 T0_first, *Pf_in; - const Word16 *p_Aq; - Word16 pf_in_buffer[M+L_FRAME16k]; + short t0_first, i, j; + const float *p_Aq; + float *pf_in, post_G1, post_G2, gain_factor; + float pf_in_buffer[M+L_FRAME16k]; - IF( BER_detect == 0 ) + if(!BER_detect) { /* update long-term background noise energy during inactive frames */ - IF( sub(coder_type,INACTIVE) == 0 ) + if( coder_type == INACTIVE ) { - *psf_lp_noise = round_fx(L_mac(L_mult(31130, *psf_lp_noise), 26214 /*0.05 Q19*/, shl(tmp_noise,4))); /*Q8*Q15 + Q19*Q4 -> Q8 */ + *psf_lp_noise = 0.95f * *psf_lp_noise + 0.05f * tmp_noise; } } - modify_pst_param( *psf_lp_noise, &Post_G1, &Post_G2, coder_type, &Gain_factor ); + /* set post-filter input */ + modify_pst_param( *psf_lp_noise, &post_G1, &post_G2, coder_type, &gain_factor ); - if(Pfstat->reset) + + if( pfstat->reset ) { - set16_fx(Pfstat->mem_res2, 0, DECMEM_RES2); - Copy( &Synth[L_frame-L_SYN_MEM], Pfstat->mem_pf_in, L_SYN_MEM); - Copy( &Synth[L_frame-L_SYN_MEM], Pfstat->mem_stp, L_SYN_MEM ); - Pfstat->gain_prec = 16384; - move16(); - Pfstat->reset = 0; - move16(); + set_zero( pfstat->mem_res2, DECMEM_RES2 ); + mvr2r( &synth[L_frame-L_SYN_MEM], pfstat->mem_pf_in, L_SYN_MEM ); + mvr2r( &synth[L_frame-L_SYN_MEM], pfstat->mem_stp, L_SYN_MEM ); + pfstat->gain_prec = 1.0f; + pfstat->reset = 0; return; } - Pf_in = &pf_in_buffer[M]; - Copy( Pfstat->mem_pf_in+L_SYN_MEM-M, &Pf_in[-M], M ); - Copy( Synth, Pf_in, L_frame ); - Copy( &Synth[L_frame - L_SYN_MEM], Pfstat->mem_pf_in, L_SYN_MEM ); - /* deactivation of the post filter in case of AUDIO because it causes problems to singing sequences */ - if( sub(coder_type,AUDIO) == 0 ) - { - Post_G1 = 32767; - move16(); - Post_G2 = 32767; - move16(); - Gain_factor = 32767; - move16(); - } + pf_in = &pf_in_buffer[M]; + mvr2r( pfstat->mem_pf_in+L_SYN_MEM-M, &pf_in[-M], M ); + mvr2r( synth, pf_in, L_frame ); + mvr2r( &synth[L_frame - L_SYN_MEM], pfstat->mem_pf_in, L_SYN_MEM ); + + /* deactivation of the post filter in case of AUDIO because it causes problems to singing sequences */ + if( coder_type == AUDIO ) + { + post_G1 = 1.f; + post_G2 = 1.f; + gain_factor = 1.f; + } /* run the post filter */ p_Aq = Aq; - move16(); - j = 0; - move16(); - FOR (i = 0; i < L_frame; i += L_SUBFR) + for( i=0, j=0; i= LP_NOISE_THRESH ) + { + post_G1 = 0.76f; + } + else if( rate == ACELP_13k20 ) + { + post_G1 = 0.82f; + } + else if( rate == ACELP_16k40 ) + { + post_G1 = 0.80f; + } + else if( rate == ACELP_24k40 || rate == ACELP_32k ) + { + post_G1 = 0.78f; + } + else + { + post_G1 = 0.76f; + } + } + + /* Switch off post-filter*/ + if( off_flag ) + { + post_G1 = post_G2; + } + + /* Reset post filter */ + if( pfstat->reset ) + { + pfstat->reset = 0; + mvr2r( &synth_in[L_frame-L_SYN_MEM], pfstat->mem_pf_in, L_SYN_MEM); + mvr2r( &synth_in[L_frame-L_SYN_MEM], pfstat->mem_stp, L_SYN_MEM ); + pfstat->gain_prec = 1.f; + mvr2r( synth_in,synth_out, L_frame ); + + return; + } + + /* input memory*/ + mvr2r( pfstat->mem_pf_in, synth_in-L_SYN_MEM, L_SYN_MEM); + mvr2r( &synth_in[L_frame-L_SYN_MEM], pfstat->mem_pf_in, L_SYN_MEM); + + /* run the post filter */ + p_Aq = Aq; + for( i_subfr=0; i_subfr0 - * Long term postfilter : + * Long-term postfilter : * harmonic postfilter : H0(z) = gl * (1 + b * z-p) * b = gamma_g * gain_ltp * gl = 1 / 1 + b @@ -176,213 +286,80 @@ void nb_post_filt( * 1. search around 1st subframe delay (3 integer values) * 2. search around best integer with fract. delays (1/8) *----------------------------------------------------------------------------*/ + static void Dec_postfilt( - PFSTAT * pfstat, /* i/o: states strucure */ - const Word16 t0, /* i : pitch delay given by coder */ - const Word16 * signal_ptr, /* i : input signal (pointer to current subframe */ - const Word16 * coeff, /* i : LPC coefficients for current subframe */ - Word16 * sig_out, /* o : postfiltered output */ - const Word16 gamma1, /* i : short term postfilt. den. weighting factor */ - const Word16 gamma2, /* i : short term postfilt. num. weighting factor */ - const Word16 Gain_factor, /* i : Gain Factor (Q15) */ - const Word16 disable_hpf + const short L_subfr, /* i : sub-frame length */ + PFSTAT *pfstat, /* i/o: Post filter related memories */ + const int t0, /* i : pitch delay given by coder */ + const float *signal_ptr, /* i : input signal (pointer to current subframe */ + const float *coeff, /* i : LPC coefficients for current subframe */ + float *sig_out, /* o : postfiltered output */ + const float gamma1, /* i : short term postfilt. den. weighting factor*/ + const float gamma2, /* i : short term postfilt. num. weighting factor*/ + const float gain_factor, /* i : Gain Factor */ + const short disable_hpf /* i : flag to disable HPF */ ) { - /* Local variables and arrays */ - Word16 apond1[M+1]; /* s.t. denominator coeff. */ - Word16 apond2[LONG_H_ST]; - Word16 sig_ltp[L_SUBFR+1]; /* H0 output signal */ - Word16 res2[SIZ_RES2]; - - Word16 *sig_ltp_ptr; - Word16 *res2_ptr; - Word16 *ptr_mem_stp; - - Word16 parcor0; - + float apond1[M+1]; /* s.t. denominator coeff. */ + float apond2[LONG_H_ST]; + float sig_ltp[L_SUBFR+1]; /* H0 output signal */ + float res2[SIZ_RES2]; + float *sig_ltp_ptr; + float *res2_ptr; + float *ptr_mem_stp; + float parcor0; /* Init pointers and restore memories */ res2_ptr = res2 + DECMEM_RES2; ptr_mem_stp = pfstat->mem_stp + L_SYN_MEM - 1; - Copy(pfstat->mem_res2, res2, DECMEM_RES2); + mvr2r( pfstat->mem_res2, res2, DECMEM_RES2 ); /* Compute weighted LPC coefficients */ - weight_a_fx(coeff, apond1, gamma1, M); - weight_a_fx(coeff, apond2, gamma2, M); - set16_fx(&apond2[M+1], 0, LONG_H_ST-(M+1)); + weight_a( coeff, apond1, gamma1, M ); + weight_a( coeff, apond2, gamma2, M ); + set_f( &apond2[M+1], 0, LONG_H_ST-(M+1) ); /* Compute A(gamma2) residual */ - Residu3_fx(apond2, signal_ptr, res2_ptr, L_SUBFR, 1); + residu( apond2, M, signal_ptr, res2_ptr, L_subfr ); /* Harmonic filtering */ sig_ltp_ptr = sig_ltp + 1; - IF (disable_hpf == 0) + if( !disable_hpf ) { - pst_ltp( t0, res2_ptr, sig_ltp_ptr, Gain_factor ); + pst_ltp( t0, res2_ptr, sig_ltp_ptr, gain_factor, L_subfr ); } - ELSE + else { - Copy(res2_ptr, sig_ltp_ptr, L_SUBFR); + mvr2r( res2_ptr, sig_ltp_ptr, L_subfr ); } - /* Save last output of 1/A(gamma1) */ - /* (from preceding subframe) */ + /* Save last output of 1/A(gamma1) */ + /* (from preceding subframe) */ sig_ltp[0] = *ptr_mem_stp; - move16(); - /* Controls short term pst filter gain and compute parcor0 */ - calc_st_filt(apond2, apond1, &parcor0, sig_ltp_ptr, pfstat->mem_zero ); + /* Controls short term pst filter gain and compute parcor0 */ + calc_st_filt( apond2, apond1, &parcor0, sig_ltp_ptr, pfstat->mem_zero, L_subfr, -1 ); - E_UTIL_synthesis(1, apond1, sig_ltp_ptr, sig_ltp_ptr, L_SUBFR, pfstat->mem_stp+L_SYN_MEM-M, 0, M); - Copy( sig_ltp_ptr+L_SUBFR-L_SYN_MEM, pfstat->mem_stp, L_SYN_MEM ); + syn_filt( apond1, M,sig_ltp_ptr, sig_ltp_ptr, L_subfr, pfstat->mem_stp+L_SYN_MEM-M, 0 ); + mvr2r( sig_ltp_ptr+L_SUBFR-L_SYN_MEM, pfstat->mem_stp, L_SYN_MEM ); /* Tilt filtering */ - Filt_mu(sig_ltp, sig_out, parcor0, L_SUBFR); + filt_mu( sig_ltp, sig_out, parcor0, L_subfr, -1 ); /* Gain control */ - scale_st(signal_ptr, sig_out, &pfstat->gain_prec, L_SUBFR); + scale_st( signal_ptr, sig_out, &(pfstat->gain_prec), L_subfr, -1 ); /* Update for next subframe */ - Copy(&res2[L_SUBFR], pfstat->mem_res2, DECMEM_RES2); - + mvr2r( &res2[L_subfr], pfstat->mem_res2, DECMEM_RES2 ); return; } -/*-------------------------------------------------------------------------- - * formant_post_filt: - * - * Main routine to perform formant post filtering - *--------------------------------------------------------------------------*/ -void formant_post_filt( - PFSTAT *pfstat, /* i/o: Post filter related memories */ - Word16 *synth_in, /* i : 12k8 synthesis */ - Word16 *Aq, /* i : LP filter coefficient */ - Word16 *synth_out, /* i/o: input signal */ - Word16 L_frame, - Word32 lp_noise, /* (i) : background noise energy (15Q16) */ - Word32 rate, /* (i) : bit-rate */ - const Word16 off_flag /* i : off flag */ -) -{ - Word16 i_subfr; - Word16 *p_Aq; - Word16 post_G1, post_G2; - /*default parameter for noisy speech and high bit-rates*/ - IF (sub(L_frame, L_FRAME) == 0) - { - post_G2 = 22938/*0.7f Q15*/; - move16(); - IF (L_sub(lp_noise, LP_NOISE_THRESH) < 0) - { - /*Clean speech*/ - IF (L_sub(rate, ACELP_13k20) < 0) - { - /*Low rates*/ - - post_G1 = 26214/*0.8f Q15*/; - move16(); - } - ELSE IF (L_sub(rate, ACELP_24k40) < 0) - { - /*Low rates*/ - - post_G1 = 24576/*0.75f Q15*/; - move16(); - } - ELSE - { - post_G1 = 23593/*0.72f Q15*/; - move16(); - } - } - ELSE /*Noisy speech*/ - { - post_G1 = 22938/*0.7f Q15*/; - move16(); - if (L_sub(rate, ACELP_15k85) < 0) - { - /*Low rates*/ - post_G1 = 24576/*0.75f Q15*/; - move16(); - } - } - } - ELSE - { - post_G2 = 24904/*0.76f Q15*/; - move16(); - test(); - IF (L_sub(lp_noise, LP_NOISE_THRESH) >= 0) - { - post_G1 = 24904/*0.76f Q15*/; - } - ELSE IF (L_sub(rate, ACELP_13k20) == 0) - { - post_G1 = 26870/*0.82f Q15*/; - move16(); - } - ELSE IF (L_sub(rate, ACELP_16k40) == 0) - { - post_G1 = 26214/*0.80f Q15*/; - move16(); - } - ELSE IF (L_sub(rate, ACELP_24k40) == 0 || L_sub(rate, ACELP_32k) == 0) - { - post_G1 = 25559/*0.78f Q15*/; - move16(); - } - ELSE - { - post_G1 = 24904/*0.76f Q15*/; - move16(); - } - } - - /* Switch off post-filter */ - if( off_flag != 0 ) - { - post_G1 = post_G2; - move16(); - } - - /* Reset post filter */ - if( pfstat->reset != 0 ) - { - post_G1 = MAX16B; - move16(); - post_G2 = MAX16B; - move16(); - pfstat->reset = 0; - move16(); - Copy( &synth_in[L_frame-L_SYN_MEM], pfstat->mem_pf_in, L_SYN_MEM); - Copy( &synth_in[L_frame-L_SYN_MEM], pfstat->mem_stp, L_SYN_MEM ); - pfstat->gain_prec = 16384; - move16(); - Copy( synth_in,synth_out, L_frame ); - - return; - } - - /* input memory*/ - Copy( pfstat->mem_pf_in, synth_in-L_SYN_MEM, L_SYN_MEM); - Copy( &synth_in[L_frame-L_SYN_MEM], pfstat->mem_pf_in, L_SYN_MEM); - - move16(); - p_Aq = Aq; - FOR (i_subfr = 0; i_subfr < L_frame; i_subfr += L_SUBFR ) - { - Dec_formant_postfilt( pfstat, &synth_in[i_subfr], p_Aq, &synth_out[i_subfr], post_G1, post_G2 ); - p_Aq += (M+1); - } - -} - /*---------------------------------------------------------------------------- - * Dec_postfilt + * Dec_formant_postfilt * * Post - adaptive postfilter main function * Short term postfilter : @@ -396,1137 +373,594 @@ void formant_post_filt( * k1 = 1st parcor calculated on {hi} * gamma3 = gamma3_minus if k1<0, gamma3_plus if k1>0 *----------------------------------------------------------------------------*/ + static void Dec_formant_postfilt( - PFSTAT *pfstat, /* i/o: states strucure */ - Word16 *signal_ptr, /* i : input signal (pointer to current subframe */ - Word16 *coeff, /* i : LPC coefficients for current subframe */ - Word16 *sig_out, /* o : postfiltered output */ - Word16 gamma1, /* i : short term postfilt. den. weighting factor*/ - Word16 gamma2 /* i : short term postfilt. num. weighting factor*/ + PFSTAT *pfstat, /* i/o: states strucure */ + const float *signal_ptr, /* i : input signal (pointer to current subframe */ + const float *coeff, /* i : LPC coefficients for current subframe */ + float *sig_out, /* o : postfiltered output */ + const float gamma1, /* i : short term postfilt. den. weighting factor*/ + const float gamma2, /* i : short term postfilt. num. weighting factor*/ + const short l_subfr /* i : subframe length */ ) { /* Local variables and arrays */ - Word16 apond1[M+1]; /* s.t. denominator coeff. */ - Word16 apond2[LONG_H_ST]; - Word16 res2[L_SUBFR]; - Word16 resynth[L_SUBFR+1]; - Word16 parcor0; - Word16 i, max; - Word16 scale_down; + float apond1[M+1]; /* s.t. denominator coeff. */ + float apond2[LONG_H_ST]; + float res2[L_SUBFR]; + float resynth[L_SUBFR+1]; + float parcor0; /* Compute weighted LPC coefficients */ - weight_a_fx(coeff, apond1, gamma1, M); - weight_a_fx(coeff, apond2, gamma2, M); - set16_fx(&apond2[M+1], 0, LONG_H_ST-(M+1)); + weight_a( coeff, apond1, gamma1, M ); + weight_a( coeff, apond2, gamma2, M ); - max = abs_s(signal_ptr[0]); - FOR (i = 1; i < L_SUBFR; i++) - { - max = s_max(max, abs_s(signal_ptr[i])); - } - scale_down = 0; - move16(); - if (sub(max, 16384) > 0) - { - scale_down = 1; - move16(); - } + set_zero( &apond2[M+1], LONG_H_ST-(M+1) ); /* Compute A(gamma2) residual */ - IF (!scale_down) - { - Residu3_fx(apond2, signal_ptr, res2, L_SUBFR, 1); - } - ELSE - { - Residu3_fx(apond2, signal_ptr, res2, L_SUBFR, 0); - Scale_sig(pfstat->mem_stp, L_SYN_MEM, -1); - } + residu( apond2, M, signal_ptr, res2, l_subfr ); /* Controls short term pst filter gain and compute parcor0 */ - calc_st_filt(apond2, apond1, &parcor0, res2, pfstat->mem_zero ); + calc_st_filt( apond2, apond1, &parcor0, res2, pfstat->mem_zero, l_subfr, -1 ); /* 1/A(gamma1) filtering, mem_stp is updated */ - resynth[0] = *(pfstat->mem_stp + sub(L_SYN_MEM, 1)); - move16(); + resynth[0] = *(pfstat->mem_stp + L_SYN_MEM - 1); - E_UTIL_synthesis(1, apond1, res2, &(resynth[1]), L_SUBFR, pfstat->mem_stp+L_SYN_MEM-M, 0, M); + syn_filt( apond1, M,res2, &(resynth[1]), l_subfr, pfstat->mem_stp+L_SYN_MEM-M, 0 ); - IF (!scale_down) - { - Copy( &(resynth[1])+L_SUBFR-L_SYN_MEM, pfstat->mem_stp, L_SYN_MEM ); - } - ELSE - { - Copy_Scale_sig( &(resynth[1])+L_SUBFR-L_SYN_MEM, pfstat->mem_stp, L_SYN_MEM, 1 ); - } + mvr2r( &(resynth[1])+l_subfr-L_SYN_MEM, pfstat->mem_stp, L_SYN_MEM); /* Tilt filtering */ - Filt_mu(resynth, sig_out, parcor0, L_SUBFR); - IF (scale_down) - { - Scale_sig(sig_out, L_SUBFR, 1); - } + filt_mu( resynth, sig_out, parcor0, l_subfr, -1 ); /* Gain control */ - scale_st(signal_ptr, sig_out, &pfstat->gain_prec, L_SUBFR); - + scale_st( signal_ptr, sig_out, &pfstat->gain_prec, l_subfr, -1 ); return; } -/*------------------------------------------------------------------------------------ - * modify_pst_param() - * - * Modify gamma1 and gamma2 values in function of the long term noise level - *-----------------------------------------------------------------------------------*/ - -static void modify_pst_param( - const Word16 lp_noise, /* i : Long term noise energy Q8 */ - Word16 *g1, /* o : Gamma1 used in post filter Q15 */ - Word16 *g2, /* o : Gamma1 used in post filter Q15 */ - const Word16 coder_type, /* i : Vad information decoded in UV frame */ - Word16 *gain_factor /* o : Gain factor applied in post filtering */ -) -{ - Word16 tmp; - Word16 lp_noiseQ12; - Word32 L_tmp; - - - test(); - IF( sub(coder_type,INACTIVE) != 0 && sub(lp_noise, LP_NOISE_THR_FX) < 0 ) - { - lp_noiseQ12 = shl(lp_noise, 4); /* to go from Q8 to Q12 */ - - /* ftmp = lp_noise*BG1_FX + CG1_FX */ - tmp = mac_r(CG1_FX*65536L, lp_noiseQ12, BG1_FX*8); /* x8 to go from Q12 to Q15 */ - tmp = s_min(tmp, POST_G1_FX ); - tmp = s_max(tmp, GAMMA1_PST12K_MIN_FX ); - - *g1 = tmp; - move16(); - - /* ftmp = lp_noise*BG2_FX + CG2_FX */ - L_tmp = L_mac0(CG2_FX/2*65536L, lp_noiseQ12, BG2_FX*8);/* L_mac0 and /2 to go from Q12 to Q14 */ - /* we go to Q30 to avoid overflow CG2_FX*/ - - L_tmp = L_min(L_tmp, POST_G2_FX*65536L/2); /* /2 because L_tmp is Q30 */ - L_tmp = L_max(L_tmp, GAMMA2_PST12K_MIN_FX*65536L/2); - - *g2 = extract_h(L_shl(L_tmp, 1)); /* Q30=>Q31=>Q15 */ - } - ELSE - { - *g1 = GAMMA1_PST12K_NOIS_FX; - move16(); - *g2 = GAMMA2_PST12K_NOIS_FX; - move16(); - } - - /* Set gain_factor of the harmonic filtering*/ - /* ftmp = (lp_noise - K_LP_NOISE)*C_LP_NOISE_FX */ - L_tmp = L_mac(-CK_LP_NOISE_FX, lp_noise, C_LP_NOISE_FX); /* tmp is in Q24 (from Q8) */ - - L_tmp = L_min(L_tmp, 64*65536L); /* 0.25 in Q24 */ - L_tmp = L_max(L_tmp, 0); - - *gain_factor = extract_h(L_shl(L_tmp, 7)); /* Q24=>Q31=>Q15 */ - - - return; -} - /*---------------------------------------------------------------------------- - * pst_ltp + * pst_ltp() * * Perform harmonic postfilter *----------------------------------------------------------------------------*/ + static void pst_ltp( - Word16 t0, /* i : pitch delay given by coder */ - Word16 * ptr_sig_in, /* i : postfilter i filter (residu2) */ - Word16 * ptr_sig_pst0, /* o : harmonic postfilter o */ - Word16 gain_factor /* i : Gain Factor (Q15) */ + const int t0, /* i : pitch delay given by coder */ + const float *ptr_sig_in, /* i : postfilter input filter (residu2) */ + float *ptr_sig_pst0, /* o : harmonic postfilter output */ + float gain_factor, /* i : gain factor */ + const short L_subfr /* i : sub-frame length */ ) { - Word32 L_temp; + int ltpdel, phase; + float num_gltp, den_gltp; + float num2_gltp, den2_gltp; + float gain_plt; + float y_up[SIZ_Y_UP]; + const float *ptr_y_up; + int off_yup; - Word16 y_up[SIZ_Y_UP]; - Word16 sig_cadr[SIZ_RES2]; + /* Suboptimal delay search */ + search_del( t0, ptr_sig_in, <pdel, &phase, &num_gltp, &den_gltp, y_up, &off_yup, L_subfr ); - Word16 *ptr_y_up; - Word16 *ptr_sig; - Word16 *ptr_sig_cadr; - - Word16 i; - Word16 temp; - Word16 ltpdel, phase; - Word16 num_gltp, den_gltp; - Word16 num2_gltp, den2_gltp; - Word16 sh_num, sh_den; - Word16 sh_num2, sh_den2; - Word16 gain_plt; - Word16 off_yup; - Word16 nb_sh_sig; - - - - /* i signal justified on 13 bits */ - ptr_sig = ptr_sig_in - DECMEM_RES2; - nb_sh_sig = getScaleFactor16(ptr_sig, add(DECMEM_RES2, L_SUBFR)); - nb_sh_sig = sub(3, nb_sh_sig); - - FOR (i = 0; i < DECMEM_RES2+L_SUBFR; i++) + if( num_gltp == 0.0f ) { - /* nb_sh_sig may be >0, <0 or =0 */ - sig_cadr[i] = shr(ptr_sig[i], nb_sh_sig); - move16(); + mvr2r( ptr_sig_in, ptr_sig_pst0, L_subfr ); } - ptr_sig_cadr = sig_cadr + DECMEM_RES2; - - /* Sub optimal delay search */ - search_del(t0, ptr_sig_cadr, <pdel, &phase, &num_gltp, &den_gltp, &sh_num, &sh_den, y_up, &off_yup); - - - IF (num_gltp == 0) + else { - Copy(ptr_sig_in, ptr_sig_pst0, L_SUBFR); - } - ELSE - { - IF (phase == 0) + if( phase == 0 ) { ptr_y_up = ptr_sig_in - ltpdel; } - ELSE + else { - /* Filtering with long filter */ - compute_ltp_l(ptr_sig_cadr, ltpdel, phase, ptr_sig_pst0, &num2_gltp, &den2_gltp, &sh_num2, &sh_den2); + /* filtering with long filter */ + compute_ltp_l( ptr_sig_in, ltpdel, phase, ptr_sig_pst0, &num2_gltp, &den2_gltp, L_subfr ); - - IF (sub(select_ltp(num_gltp, den_gltp, sh_num, sh_den, num2_gltp, den2_gltp, sh_num2, sh_den2), 1) == 0) + if( select_ltp( num_gltp, den_gltp, num2_gltp, den2_gltp ) == 1 ) { /* select short filter */ - temp = sub(phase, 1); - L_temp = L_mult0(temp, L_SUBFR + 1); - temp = extract_l(L_temp); - temp = add(temp, off_yup); - - /* ptr_y_up = y_up + (phase-1) * (L_SUBFR+1) + off_yup */ - ptr_y_up = y_up + temp; + ptr_y_up = y_up + ((phase - 1) * (L_subfr+1) + off_yup); } - ELSE + else { /* select long filter */ num_gltp = num2_gltp; - move16(); den_gltp = den2_gltp; - move16(); - sh_num = sh_num2; - move16(); - sh_den = sh_den2; - move16(); ptr_y_up = ptr_sig_pst0; } - - /* rescale y_up */ - FOR (i = 0; i < L_SUBFR; i++) - { - /* nb_sh_sig may be >0, <0 or =0 */ - ptr_y_up[i] = shl(ptr_y_up[i], nb_sh_sig); - move16(); - } } - temp = sub(sh_num, sh_den); - IF (temp >= 0) - { - den_gltp = shr(den_gltp, temp); - } - ELSE - { - num_gltp = shl(num_gltp, temp); /* >> (-temp) */ - } - IF (sub(num_gltp, den_gltp) >= 0) + if( num_gltp >= den_gltp ) { /* beta bounded to 1 */ - gain_plt = MIN_GPLT_FX; - move16(); + gain_plt = MIN_GPLT; } - ELSE + else { - /* GAMMA_G = 0.5 */ - /* gain_plt = den_gltp x 2**15 / (den_gltp + 0.5 num_gltp) */ - /* shift 1 bit to avoid overflows in add */ - num_gltp = shr(num_gltp, 2); - den_gltp = shr(den_gltp, 1); - temp = add(den_gltp, num_gltp); - gain_plt = div_s(den_gltp, temp); /* Q15 */ + gain_plt = den_gltp / (den_gltp + ((float)0.5) * num_gltp); } /* decrease gain in noisy condition */ - /* gain_plt += (1.0f-gain_plt) * gain_factor */ - /* gain_plt = gain_plt + gain_factor - gain_plt*gain_factor */ - gain_plt = msu_r(L_msu(L_deposit_h(gain_plt), gain_plt, gain_factor), -32768, gain_factor); + gain_plt += ((1.0f-gain_plt)*gain_factor); - /** filtering by H0(z) = harmonic filter **/ - filt_plt(ptr_sig_in, ptr_y_up, ptr_sig_pst0, gain_plt); + /* filtering by H0(z) = harmonic filter */ + filt_plt( ptr_sig_in, ptr_y_up, ptr_sig_pst0, gain_plt, L_subfr ); } + return; } /*---------------------------------------------------------------------------- - * search_del: + * search_del() * * Computes best (shortest) integer LTP delay + fine search *---------------------------------------------------------------------------*/ + static void search_del( - Word16 t0, /* i : pitch delay given by coder */ - Word16 * ptr_sig_in, /* i : i signal (with delay line) */ - Word16 * ltpdel, /* o : delay = *ltpdel - *phase / f_up */ - Word16 * phase, /* o : phase */ - Word16 * num_gltp, /* o : 16 bits numerator of LTP gain */ - Word16 * den_gltp, /* o : 16 bits denominator of LTP gain */ - Word16 * sh_num_gltp, /* o : justification for num_gltp */ - Word16 * sh_den_gltp, /* o : justification for den_gltp */ - Word16 * y_up, /* o : LT delayed signal if fract. delay */ - Word16 * off_yup /* o : offset in y_up */ + const int t0, /* i : pitch delay given by coder */ + const float *ptr_sig_in, /* i : input signal (with delay line) */ + int *ltpdel, /* o : delay = *ltpdel - *phase / f_up */ + int *phase, /* o : phase */ + float *num_gltp, /* o : numerator of LTP gain */ + float *den_gltp, /* o : denominator of LTP gain */ + float *y_up, /* o : LT delayed signal if fract. delay*/ + int *off_yup, /* o : offset in y_up */ + const short L_subfr /* i : sub-frame length */ ) { - Word32 L_den0[F_UP_PST - 1]; - Word32 L_den1[F_UP_PST - 1]; - - Word32 *ptr_L_den0, *ptr_L_den1; - - Word32 L_num_int, L_den_int, L_den_max; - Word32 L_temp0, L_temp1; - Word32 L_acc; - Word32 L_temp; - - const Word16 *ptr_h; - Word16 *ptr_sig_past, *ptr_sig_past0; - Word16 *ptr1, *ptr_y_up; - - Word16 i, n; - Word16 num, den0, den1; - Word16 den_max, num_max; - Word32 L_numsq_max; - Word16 ener; - Word16 sh_num, sh_den, sh_ener; - Word16 i_max, lambda, phi, phi_max, ioff; - Word16 temp; - + const float *ptr_h; + float tab_den0[F_UP_PST - 1], tab_den1[F_UP_PST - 1]; + float *ptr_den0, *ptr_den1; + const float *ptr_sig_past, *ptr_sig_past0; + const float *ptr1; + int i, n, ioff, i_max; + float ener, num, numsq, den0, den1; + float den_int, num_int; + float den_max, num_max, numsq_max; + int phi_max; + int lambda, phi; + float temp0, temp1; + float *ptr_y_up; /*------------------------------------- * Computes energy of current signal *-------------------------------------*/ - L_acc = L_mult(ptr_sig_in[0], ptr_sig_in[0]); - FOR(i = 1; i < L_SUBFR; i++) + ener = 0.0f; + for (i = 0; i < L_subfr; i++) { - L_acc = L_mac(L_acc, ptr_sig_in[i], ptr_sig_in[i]); + ener += ptr_sig_in[i] * ptr_sig_in[i]; } - IF (L_acc == 0) + + if (ener < 0.1f) { - *num_gltp = 0; - move16(); - *den_gltp = 1; - move16(); + *num_gltp = 0.0f; + *den_gltp = 1.0f; *ltpdel = 0; - move16(); *phase = 0; - move16(); return; } - sh_ener = sub(16, norm_l(L_acc)); - /* save energy for final decision */ - sh_ener = s_max(0, sh_ener); - ener = extract_l(L_shr(L_acc, sh_ener)); /*------------------------------------- * Selects best of 3 integer delays * Maximum of 3 numerators around t0 *-------------------------------------*/ - lambda = sub(t0, 1); + + lambda = t0 - 1; ptr_sig_past = ptr_sig_in - lambda; - L_num_int = L_deposit_l(-1); + num_int = -1.0e30f; + i_max = 0; - /* initialization used only to suppress Microsoft Visual C++ warnings */ - i_max = (Word16) 0; - move16(); - - FOR (i = 0; i < 3; i++) + for (i = 0; i < 3; i++) { - L_acc = L_mult(ptr_sig_in[0], ptr_sig_past[0]); - FOR (n = 1; n < L_SUBFR; n++) + num = 0.0f; + for (n = 0; n < L_subfr; n++) { - L_acc = L_mac(L_acc, ptr_sig_in[n], ptr_sig_past[n]); + num += ptr_sig_in[n] * ptr_sig_past[n]; } - - - L_acc = L_max(L_acc, 0); - L_temp = L_sub(L_acc, L_num_int); - if (L_temp > 0L) + if (num > num_int) { - i_max = (Word16) i; - move16(); + i_max = i; + num_int = num; } - L_num_int = L_max(L_num_int, L_acc); ptr_sig_past--; } - IF (L_num_int == 0) + if (num_int <= 0.0f) { - *num_gltp = 0; - move16(); - *den_gltp = 1; - move16(); + *num_gltp = 0.0f; + *den_gltp = 1.0f; *ltpdel = 0; - move16(); *phase = 0; - move16(); return; } - /* Compute den for i_max */ - lambda = add(lambda, (Word16) i_max); + /* Calculates denominator for i_max */ + lambda += i_max; ptr_sig_past = ptr_sig_in - lambda; - temp = *ptr_sig_past++; - move16(); - L_acc = L_mult(temp, temp); - FOR (i = 1; i < L_SUBFR; i++) + den_int = (float) 0.; + for (n = 0; n < L_subfr; n++) { - temp = *ptr_sig_past++; - move16(); - L_acc = L_mac(L_acc, temp, temp); + den_int += ptr_sig_past[n] * ptr_sig_past[n]; } - IF (L_acc == 0L) - { - *num_gltp = 0; - move16(); - *den_gltp = 1; - move16(); - *ltpdel = 0; - move16(); - *phase = 0; - move16(); + if (den_int < (float) 0.1) + { + *num_gltp = (float) 0.; + *den_gltp = (float) 1.; + *ltpdel = 0; + *phase = 0; return; } - L_den_int = L_add(0, L_acc); /* sets to 'L_acc' in 1 clock */ /*---------------------------------- * Select best phase around lambda - *---------------------------------- * Compute y_up & denominators *----------------------------------*/ ptr_y_up = y_up; - L_den_max = L_add(0, L_den_int); /* sets to 'L_acc' in 1 clock */ - ptr_L_den0 = L_den0; - ptr_L_den1 = L_den1; - ptr_h = Tab_hup_s; - temp = sub(lambda, LH_UP_S - 1); - ptr_sig_past0 = ptr_sig_in - temp; + den_max = den_int; + ptr_den0 = tab_den0; + ptr_den1 = tab_den1; + ptr_h = tab_hup_s; + ptr_sig_past0 = ptr_sig_in + LH_UP_S - 1 - lambda; /* points on lambda_max+1 */ - /* Loop on phase */ - FOR (phi = 1; phi < F_UP_PST; phi++) + /* loop on phase */ + for (phi = 1; phi < F_UP_PST; phi++) { - /* Compute y_up for lambda+1 - phi/F_UP_PST */ - /* and lambda - phi/F_UP_PST */ - + /* Computes criterion for (lambda+1) - phi/F_UP_PST */ + /* and lambda - phi/F_UP_PST */ ptr_sig_past = ptr_sig_past0; - FOR (n = 0; n <= L_SUBFR; n++) + /* computes y_up[n] */ + for (n = 0; n <= L_subfr; n++) { ptr1 = ptr_sig_past++; - - L_acc = L_mult(ptr_h[0], ptr1[0]); - FOR (i = 1; i < LH2_S; i++) + temp0 = (float) 0.; + for (i = 0; i < LH2_S; i++) { - L_acc = L_mac(L_acc, ptr_h[i], ptr1[-i]); + temp0 += ptr_h[i] * ptr1[-i]; } - ptr_y_up[n] = round_fx(L_acc); + ptr_y_up[n] = temp0; } /* compute den0 (lambda+1) and den1 (lambda) */ - /* part common to den0 and den1 */ - L_acc = L_mult(ptr_y_up[1], ptr_y_up[1]); - FOR (n = 2; n < L_SUBFR; n++) + temp0 = (float) 0.; + for (n = 1; n < L_subfr; n++) { - L_acc = L_mac(L_acc, ptr_y_up[n], ptr_y_up[n]); + temp0 += ptr_y_up[n] * ptr_y_up[n]; } - L_temp0 = L_add(0, L_acc); /* sets to 'L_acc' in 1 clock (saved for den1) */ /* den0 */ - L_acc = L_mac(L_acc, ptr_y_up[0], ptr_y_up[0]); - *ptr_L_den0 = L_acc; - move32(); + den0 = temp0 + ptr_y_up[0] * ptr_y_up[0]; + *ptr_den0++ = den0; /* den1 */ - L_acc = L_mac(L_temp0, ptr_y_up[L_SUBFR], ptr_y_up[L_SUBFR]); - *ptr_L_den1 = L_acc; - move32(); - - IF (sub(abs_s(ptr_y_up[0]), abs_s(ptr_y_up[L_SUBFR])) > 0) + den1 = temp0 + ptr_y_up[L_subfr] * ptr_y_up[L_subfr]; + *ptr_den1++ = den1; + if (fabs (ptr_y_up[0]) > fabs (ptr_y_up[L_subfr])) { - L_den_max = L_max(*ptr_L_den0, L_den_max); + if (den0 > den_max) + { + den_max = den0; + } } - ELSE + else { - L_den_max = L_max(*ptr_L_den1, L_den_max); + if (den1 > den_max) + { + den_max = den1; + } } - ptr_L_den0++; - ptr_L_den1++; - ptr_y_up += (L_SUBFR+1); + ptr_y_up += (L_subfr+1); ptr_h += LH2_S; } - - IF (L_den_max == 0) + if (den_max < 0.1f) { - *num_gltp = 0; - move16(); - *den_gltp = 1; - move16(); + *num_gltp = 0.0f; + *den_gltp = 1.0f; *ltpdel = 0; - move16(); *phase = 0; - move16(); - return; } - sh_den = sub(16, norm_l(L_den_max)); - /* if sh_den <= 0 : dynamic between current frame */ - /* and delay line too high */ - IF (sh_den <= 0) - { - *num_gltp = 0; - move16(); - *den_gltp = 1; - move16(); - *ltpdel = 0; - move16(); - *phase = 0; - move16(); - - return; - } - - /* search sh_num to justify correlations */ - /* sh_num = Max(sh_den, sh_ener) */ - sh_num = sh_ener; - move16(); - if (sub(sh_den, sh_ener) >= 0) - { - sh_num = sh_den; - move16(); - } - - /* Computation of the numerators */ - /* and selection of best num*num/den */ - /* for non null phases */ + /* Computation of the numerators */ + /* and selection of best num*num/den */ + /* for non null phases */ /* Initialize with null phase */ - L_acc = L_shr(L_den_int, sh_den); /* sh_den > 0 */ - den_max = extract_l(L_acc); - L_acc = L_shr(L_num_int, sh_num); /* sh_num > 0 */ - num_max = extract_l(L_acc); - L_numsq_max = L_mult(num_max, num_max); - + num_max = num_int; + den_max = den_int; + numsq_max = num_max * num_max; phi_max = 0; - move16(); ioff = 1; - move16(); - ptr_L_den0 = L_den0; - ptr_L_den1 = L_den1; + ptr_den0 = tab_den0; + ptr_den1 = tab_den1; ptr_y_up = y_up; - /* if den_max = 0 : will be selected and declared unvoiced */ /* if num!=0 & den=0 : will be selected and declared unvoiced */ /* degenerated seldom cases, switch off LT is OK */ /* Loop on phase */ - FOR (phi = 1; phi < F_UP_PST; phi++) + for (phi = 1; phi < F_UP_PST; phi++) { - /* compute num for lambda+1 - phi/F_UP_PST */ - L_acc = L_mult(ptr_sig_in[0], ptr_y_up[0]); - FOR (n = 1; n < L_SUBFR; n++) - { - L_acc = L_mac(L_acc, ptr_sig_in[n], ptr_y_up[n]); - } - L_acc = L_shr(L_acc, sh_num); /* sh_num > 0 */ - L_acc = L_max(0, L_acc); - num = extract_l(L_acc); - /* selection if num**2/den0 max */ - L_temp1 = L_mult(num, num); - L_temp0 = Mpy_32_16_1(L_temp1, den_max); - L_acc = L_add(*ptr_L_den0++, 0); - L_acc = L_shr(L_acc, sh_den); /* sh_den > 0 */ - den0 = extract_l(L_acc); - L_temp = Msub_32_16(L_temp0, L_numsq_max, den0); - IF (L_temp > 0L) + /* computes num for lambda+1 - phi/F_UP_PST */ + num = 0.0f; + for (n = 0; n < L_subfr; n++) + { + num += ptr_sig_in[n] * ptr_y_up[n]; + } + if (num < 0.0f) + { + num = 0.0f; + } + numsq = num * num; + + /* selection if num/sqrt(den0) max */ + den0 = *ptr_den0++; + temp0 = numsq * den_max; + temp1 = numsq_max * den0; + if (temp0 > temp1) { num_max = num; - move16(); - L_numsq_max = L_add(0, L_temp1); /* sets to 'L_temp1' in 1 clock */ + numsq_max = numsq; den_max = den0; - move16(); ioff = 0; - move16(); phi_max = phi; - move16(); } - /* compute num for lambda - phi/F_UP_PST */ + /* computes num for lambda_max - phi/F_UP_PST */ ptr_y_up++; - - L_acc = L_mult(ptr_sig_in[0], ptr_y_up[0]); - FOR (n = 1; n < L_SUBFR; n++) + num = (float) 0.; + for (n = 0; n < L_subfr; n++) { - L_acc = L_mac(L_acc, ptr_sig_in[n], ptr_y_up[n]); + num += ptr_sig_in[n] * ptr_y_up[n]; } - L_acc = L_shr(L_acc, sh_num); /* sh_num > 0 */ - L_acc = L_max(0, L_acc); - num = extract_l(L_acc); + if (num < (float) 0.) + { + num = (float) 0.; + } + numsq = num * num; - /* selection if num**2/den1 max */ - L_temp1 = L_mult(num, num); - L_temp0 = Mpy_32_16_1(L_temp1, den_max); - L_acc = L_add(*ptr_L_den1++, 0); - L_acc = L_shr(L_acc, sh_den); /* sh_den > 0 */ - den1 = extract_l(L_acc); - L_temp = Msub_32_16(L_temp0, L_numsq_max, den1); - IF (L_temp > 0L) + /* selection if num/sqrt(den1) max */ + den1 = *ptr_den1++; + temp0 = numsq * den_max; + temp1 = numsq_max * den1; + if (temp0 > temp1) { num_max = num; - move16(); - L_numsq_max = L_add(0, L_temp1); /* sets to 'L_temp1' in 1 clock */ + numsq_max = numsq; den_max = den1; - move16(); ioff = 1; - move16(); phi_max = phi; - move16(); } - - ptr_y_up += L_SUBFR; + ptr_y_up += L_subfr; } /*--------------------------------------------------- * test if normalized crit0[iopt] > THRESHCRIT *--------------------------------------------------*/ - test(); - IF (num_max == 0 || sub(den_max, 1) <= 0) - { - *num_gltp = 0; - move16(); - *den_gltp = 1; - move16(); - *ltpdel = 0; - move16(); - *phase = 0; - move16(); + if ((num_max == 0.0f) || (den_max <= 0.1f)) + { + *num_gltp = 0.0f; + *den_gltp = 1.0f; + *ltpdel = 0; + *phase = 0; return; } - /* compare num**2 */ - /* to ener * den * 0.5 */ - /* (THRESHCRIT = 0.5) */ - L_temp1 = L_mult(den_max, ener); - - /* temp = 2 * sh_num - sh_den - sh_ener + 1 */ - /* 16 bits with no overflows */ - temp = shl(sh_num, 1); - temp = sub(temp, sh_den); - temp = sub(temp, sh_ener); - temp = add(temp, 1); - IF (temp < 0) + /* comparison num * num */ + /* with ener * den x THRESCRIT */ + temp1 = den_max * ener * THRESCRIT; + if (numsq_max >= temp1) { - temp = negate(temp); /* no overflow */ - L_numsq_max = L_shr(L_numsq_max, temp); - } - ELSE - { - if (temp > 0) - { - L_temp1 = L_shr(L_temp1, temp); - } - } - L_temp = L_sub(L_numsq_max, L_temp1); - IF (L_temp >= 0L) - { - temp = add(lambda, 1); - *ltpdel = sub(temp, ioff); + *ltpdel = lambda + 1 - ioff; *off_yup = ioff; - move16(); *phase = phi_max; - move16(); *num_gltp = num_max; - move16(); *den_gltp = den_max; - move16(); - *sh_den_gltp = sh_den; - move16(); - *sh_num_gltp = sh_num; - move16(); } - ELSE + else { - *num_gltp = 0; - move16(); - *den_gltp = 1; - move16(); + *num_gltp = 0.0f; + *den_gltp = 1.0f; *ltpdel = 0; - move16(); *phase = 0; - move16(); } - return; } /*---------------------------------------------------------------------------- - * filt_plt: + * filt_plt() * * Perform long term postfilter *----------------------------------------------------------------------------*/ + static void filt_plt( - Word16 * s_in, /* i : i signal with past */ - Word16 * s_ltp, /* i : filtered signal with gain 1 */ - Word16 * s_out, /* o : signal */ - Word16 gain_plt /* i : filter gain */ + const float *s_in, /* i : input signal with past */ + const float *s_ltp, /* i : filtered signal with gain 1 */ + float *s_out, /* o : output signal */ + const float gain_plt, /* i : filter gain */ + const short L_subfr /* i : the length of subframe */ ) { + int n; + float gain_plt_1; - /* Local variables */ - Word32 L_acc; + gain_plt_1 = (float) 1. - gain_plt; - Word16 n; - Word16 gain_plt_1; - - - gain_plt_1 = sub(32767, gain_plt); - gain_plt_1 = add(gain_plt_1, 1); /* 2**15 (1 - g) */ - - FOR (n = 0; n < L_SUBFR; n++) + for (n = 0; n < L_subfr; n++) { - /* s_out(n) = gain_plt x s_in(n) + gain_plt_1 x s_ltp(n) */ - L_acc = L_mult(gain_plt, s_in[n]); - s_out[n] = mac_r(L_acc, gain_plt_1, s_ltp[n]); - move16(); /* no overflow */ + s_out[n] = gain_plt * s_in[n] + gain_plt_1 * s_ltp[n]; } - return; } - /*---------------------------------------------------------------------------- - * compute_ltp_l : + * compute_ltp_l() * * compute delayed signal, num & den of gain for fractional delay * with long interpolation filter *----------------------------------------------------------------------------*/ + static void compute_ltp_l( - Word16 * s_in, /* i/o: signal with past */ - Word16 ltpdel, /* i : delay factor */ - Word16 phase, /* i : phase factor */ - Word16 * y_up, /* i : delayed signal */ - Word16 * num, /* i : numerator of LTP gain */ - Word16 * den, /* i : denominator of LTP gain */ - Word16 * sh_num, /* i : justification factor of num */ - Word16 * sh_den /* i : justification factor of den */ + const float *s_in, /* i : input signal with past */ + const int ltpdel, /* i : delay factor */ + const int phase, /* i : phase factor */ + float *y_up, /* o : delayed signal */ + float *num, /* o : numerator of LTP gain */ + float *den, /* o : denominator of LTP gain */ + const short L_subfr /* i : the length of subframe */ ) { - Word32 L_acc; - Word16 *ptr2; - const Word16 *ptr_h; - Word16 n, i; - Word16 temp; + const float *ptr_h; + int n, i; + const float *ptr2; + float temp; - temp = sub(phase, 1); - temp = shl(temp, L2_LH2_L); - ptr_h = Tab_hup_l + temp; /* Tab_hup_l + LH2_L * (phase-1) */ - - temp = sub(LH_UP_L, ltpdel); - ptr2 = s_in + temp; + /* Filtering with long filter */ + ptr_h = tab_hup_l + (phase - 1) * LH2_L; + ptr2 = s_in - ltpdel + LH_UP_L; /* Compute y_up */ - FOR (n = 0; n < L_SUBFR; n++) + for (n = 0; n < L_subfr; n++) { - L_acc = L_mult(ptr_h[0], *ptr2--); - - FOR (i = 1; i < LH2_L; i++) + temp = 0.0f; + for (i = 0; i < LH2_L; i++) { - L_acc = L_mac(L_acc, ptr_h[i], *ptr2--); + temp += ptr_h[i] **ptr2--; } - y_up[n] = round_fx(L_acc); + y_up[n] = temp; ptr2 += LH2_L_P1; } /* Compute num */ - L_acc = L_mult(y_up[0], s_in[0]); - FOR (n = 1; n < L_SUBFR; n++) + *num = 0.0f; + for (n = 0; n < L_subfr; n++) { - L_acc = L_mac(L_acc, y_up[n], s_in[n]); + *num += y_up[n] * s_in[n]; } - IF (L_acc < 0L) + + if (*num < 0.0f) { - *num = 0; - move16(); - *sh_num = 0; - move16(); - } - ELSE - { - temp = sub(16, norm_l(L_acc)); - temp = s_max(temp, 0); - L_acc = L_shr(L_acc, temp); /* with temp >= 0 */ - *num = extract_l(L_acc); - *sh_num = temp; - move16(); + *num = 0.0f; } /* Compute den */ - L_acc = L_mult(y_up[0], y_up[0]); - FOR (n = 1; n < L_SUBFR; n++) + *den = 0.0f; + for (n = 0; n < L_subfr; n++) { - L_acc = L_mac(L_acc, y_up[n], y_up[n]); + *den += y_up[n] * y_up[n]; } - temp = sub(16, norm_l(L_acc)); - temp = s_max(temp, 0); - L_acc = L_shr(L_acc, temp); /* with temp >= 0 */ - *den = extract_l(L_acc); - *sh_den = temp; - move16(); - return; } /*---------------------------------------------------------------------------- - * select_ltp: + * select_ltp() * * selects best of (gain1, gain2) * with gain1 = num1 * 2** sh_num1 / den1 * 2** sh_den1 * and gain2 = num2 * 2** sh_num2 / den2 * 2** sh_den2 *----------------------------------------------------------------------------*/ -static Word16 select_ltp( /* o : 1 = 1st gain, 2 = 2nd gain */ - Word16 num1, /* i : numerator of gain1 */ - Word16 den1, /* i : denominator of gain1 */ - Word16 sh_num1, /* i : just. factor for num1 */ - Word16 sh_den1, /* i : just. factor for den1 */ - Word16 num2, /* i : numerator of gain2 */ - Word16 den2, /* i : denominator of gain2 */ - Word16 sh_num2, /* i : just. factor for num2 */ - Word16 sh_den2 /* i : just. factor for den2 */ + +static int select_ltp( /* o : 1 = 1st gain, 2 = 2nd gain */ + const float num1, /* i : numerator of gain1 */ + const float den1, /* i : denominator of gain1 */ + const float num2, /* i : numerator of gain2 */ + const float den2 /* i : denominator of gain2 */ ) { - Word32 L_temp1, L_temp2; - Word32 L_temp; - - Word16 temp1, temp2; - - - IF (den2 == 0) + if (den2 == (float) 0.) { - return 1; + return (1); } - /* compares criteria = num**2/den */ - L_temp1 = L_mult(num1, num1); - L_temp1 = Mpy_32_16_1(L_temp1, den2); - - L_temp2 = L_mult(num2, num2); - L_temp2 = Mpy_32_16_1(L_temp2, den1); - - /* temp1 = sh_den2 + 2 * sh_num1 */ - temp1 = shl(sh_num1, 1); - temp1 = add(temp1, sh_den2); - /* temp2 = sh_den1 + 2 * sh_num2; */ - temp2 = shl(sh_num2, 1); - temp2 = add(temp2, sh_den1); - - temp2 = sub(temp2, temp1); - if (temp2 > 0) + if (num2 * num2 * den1 > num1 * num1 * den2) { - L_temp1 = L_shr(L_temp1, temp2); /* temp2 > 0 */ + return (2); } - if (temp2 < 0) + else { - L_temp2 = L_shl(L_temp2, temp2); /* temp2 < 0 */ + return (1); } - - L_temp = L_sub(L_temp2, L_temp1); - temp1 = 1; - move16(); - if (L_temp > 0L) - { - temp1 = 2; - move16(); - } - - return temp1; -} - -/*---------------------------------------------------------------------------- - * calc_st_filt - * - * computes impulse response of A(gamma2) / A(gamma1) - * controls gain : computation of energy impulse response as - * SUMn (abs (h[n])) and computes parcor0 - *---------------------------------------------------------------------------- */ -static void calc_st_filt( - Word16 * apond2, /* i : coefficients of numerator */ - Word16 * apond1, /* i : coefficients of denominator */ - Word16 * parcor0, /* o : 1st parcor calcul. on composed filter */ - Word16 * sig_ltp_ptr, /* i/o: i of 1/A(gamma1) : scaled by 1/g0 */ - Word16 * mem_zero /* i : All zero memory */ -) -{ - Word32 L_g0; - - Word16 h[LONG_H_ST]; - - Word16 g0, temp; - Word16 i; - - - temp = sub( 2, norm_s( apond2[0] ) ); - - /* compute i.r. of composed filter apond2 / apond1 */ - E_UTIL_synthesis(temp, apond1, apond2, h, LONG_H_ST, mem_zero, 0, M); - - /* compute 1st parcor */ - Calc_rc0_h(h, parcor0); - - /* compute g0 */ - L_g0 = L_mult0(1, abs_s(h[0])); - FOR (i = 1; i < LONG_H_ST; i++) - { - L_g0 = L_mac0(L_g0, 1, abs_s(h[i])); - } - g0 = extract_h(L_shl(L_g0, 14)); - - /* Scale signal i of 1/A(gamma1) */ - IF (sub(g0, 1024) > 0) - { - temp = div_s(1024, g0); /* temp = 2**15 / gain0 */ - FOR (i = 0; i < L_SUBFR; i++) - { - sig_ltp_ptr[i] = mult_r(sig_ltp_ptr[i], temp); - move16(); - } - } - - - return; -} - -/*---------------------------------------------------------------------------- - * filt_mu - * - * tilt filtering with : (1 + mu z-1) * (1/1-|mu|) - * computes y[n] = (1/1-|mu|) (x[n]+mu*x[n-1]) - *---------------------------------------------------------------------------*/ -void Filt_mu( - Word16 * sig_in, /* i : signal (beginning at sample -1) */ - Word16 * sig_out, /* o : signal with tilt */ - Word16 parcor0, /* i : parcor0 (mu = parcor0 * gamma3) */ - Word16 L_subfr /* i : the length of subframe */ -) -{ - Word32 L_acc, L_temp, L_fact; - - Word16 *ptrs; - - Word16 n; - Word16 mu, mu2, ga, temp; - Word16 fact, sh_fact; - - - IF (parcor0 > 0) - { - mu = mult_r(parcor0, GAMMA3_PLUS_FX); - /* GAMMA3_PLUS_FX < 0.5 */ - sh_fact = 14; - move16(); /* sh_fact */ - fact = (Word16) 0x4000; - move16(); /* 2**sh_fact */ - L_fact = (Word32) L_deposit_l(0x2000); /* fact >> 1 */ - } - ELSE - { - mu = mult_r(parcor0, GAMMA3_MINUS_FX); - /* GAMMA3_MINUS_FX < 0.9375 */ - sh_fact = 11; - move16(); /* sh_fact */ - fact = (Word16) 0x0800; - move16(); /* 2**sh_fact */ - L_fact = (Word32) L_deposit_l(0x0400); /* fact >> 1 */ - } - - temp = sub(1, abs_s(mu)); - BASOP_SATURATE_WARNING_OFF; - mu2 = add(32767, temp); /* 2**15 (1 - |mu|) */ - BASOP_SATURATE_WARNING_ON; - ga = div_s(fact, mu2); /* 2**sh_fact / (1 - |mu|) */ - - ptrs = sig_in; /* points on sig_in(-1) */ - - sh_fact = sub(sh_fact,16); /* to remove the saturate(), should shl by 16 before rounding */ - - FOR (n = 0; n < L_subfr; n++) - { - L_acc = L_mult0(mu, *ptrs++); - L_temp = L_mac(L_acc, 16384, *ptrs); /* sig_in(n) * 2**15 */ - - L_temp = Madd_32_16(L_fact, L_temp, ga); - L_temp = L_shr(L_temp, sh_fact); /* mult. temp x ga */ - - BASOP_SATURATE_WARNING_OFF; - /*sig_out[n] = saturate(L_temp); move16();*/ - sig_out[n] = round_fx(L_temp); - BASOP_SATURATE_WARNING_ON; - } - - - return; } -/*---------------------------------------------------------------------------- - * scale_st() +/*------------------------------------------------------------------------------------ + * modify_pst_param() * - * control of the subframe gain - * gain[n] = AGC_FAC_FX * gain[n-1] + (1 - AGC_FAC_FX) g_in/g_out - *---------------------------------------------------------------------------*/ -void scale_st( - const Word16 * sig_in, /* i : postfilter i signal */ - Word16 * sig_out, /* i/o: postfilter o signal */ - Word16 * gain_prec, /* i/o: last value of gain for subframe */ - Word16 L_subfr + * Modify gamma1 and gamma2 values in function of the long-term noise level + *-----------------------------------------------------------------------------------*/ + +static void modify_pst_param( + const float psf_lp_noise, /* i : Long term noise energy */ + float *g1, /* o : Gamma1 used in post filter */ + float *g2, /* o : Gamma2 used in post filter */ + const short coder_type, /* i : coder type */ + float *gain_factor /* o : Gain factor applied in post filtering */ ) { - Word32 L_acc, L_temp; + float ftmp; - Word16 i; - Word16 scal_in, scal_out; - Word16 s_g_in, s_g_out, temp, sh_g0, g0; - Word16 gain = 0; - - - /* compute i gain */ - L_acc = L_deposit_l(0); - FOR (i = 0; i < L_subfr; i++) + if( coder_type != INACTIVE && psf_lp_noise < LP_NOISE_THR ) { - if(sig_in[i] > 0) + ftmp = psf_lp_noise*BG1 + CG1; + if( ftmp > POST_G1 ) { - L_acc = L_mac0(L_acc, 1, sig_in[i]); + ftmp = POST_G1; } - if(sig_in[i] < 0) + else if( ftmp < POST_G1_MIN ) { - L_acc = L_msu0(L_acc, 1, sig_in[i]); + ftmp = POST_G1_MIN; } + *g1 = ftmp; + + ftmp = psf_lp_noise*BG2 + CG2; + if( ftmp > POST_G2 ) + { + ftmp = POST_G2; + } + else if( ftmp < POST_G2_MIN ) + { + ftmp = POST_G2_MIN; + } + *g2 = ftmp; + } + else + { + *g1 = POST_G1_NOIS; + *g2 = POST_G2_NOIS; } - g0 = 0; - move16(); - IF (L_acc != 0L) + /* Set gain_factor of the harmonic filtering */ + ftmp = (psf_lp_noise - K_LP_NOISE) * C_LP_NOISE; + + if( ftmp >= 0.25f ) { - scal_in = norm_l(L_acc); - L_acc = L_shl(L_acc, scal_in); - s_g_in = extract_h(L_acc); /* normalized */ - - /* Compute o gain */ - L_acc = L_mult0(1, abs_s(sig_out[0])); - FOR (i = 1; i < L_subfr; i++) - { - L_acc = L_mac0(L_acc, 1, abs_s(sig_out[i])); - } - IF (L_acc == 0L) - { - *gain_prec = 0; - move16(); - - return; - } - scal_out = norm_l(L_acc); - L_acc = L_shl(L_acc, scal_out); - s_g_out = extract_h(L_acc); /* normalized */ - - sh_g0 = add(scal_in, 1); - sh_g0 = sub(sh_g0, scal_out); /* scal_in - scal_out + 1 */ - IF (sub(s_g_in, s_g_out) < 0) - { - g0 = div_s(s_g_in, s_g_out); /* s_g_in/s_g_out in Q15 */ - } - ELSE - { - temp = sub(s_g_in, s_g_out); /* sufficient since normalized */ - g0 = shr(div_s(temp, s_g_out), 1); - g0 = add(g0, (Word16) 0x4000); /* s_g_in/s_g_out in Q14 */ - sh_g0 = sub(sh_g0, 1); - } - /* L_gain_in/L_gain_out in Q14 */ - /* overflows if L_gain_in > 2 * L_gain_out */ - g0 = shr(g0, sh_g0); /* sh_g0 may be >0, <0, or =0 */ - - g0 = mult_r(g0, AGC_FAC1_FX); /* L_gain_in/L_gain_out * AGC_FAC1_FX */ + /* the noise is really high */ + *gain_factor = 0.25f; } - - /* gain(n) = AGC_FAC gain(n-1) + AGC_FAC1 gain_in/gain_out */ - /* sig_out(n) = gain(n) sig_out(n) */ - gain = *gain_prec; - move16(); - FOR (i = 0; i < L_subfr; i++) + else if ( ftmp < 0 ) { - temp = mult_r(AGC_FAC_FX, gain); - gain = add(temp, g0); /* in Q14 */ - L_temp = L_mult(gain, sig_out[i]); - L_temp = L_shl(L_temp, 1); - sig_out[i] = round_fx(L_temp); + *gain_factor = 0.0f; } - *gain_prec = gain; - move16(); - - - return; -} - -/*---------------------------------------------------------------------------- - * blend_subfr2() - * - * - *---------------------------------------------------------------------------*/ - -void blend_subfr2( - Word16 *sigIn1, - Word16 *sigIn2, - Word16 *sigOut -) -{ - Word16 fac1 = 32768 - 512; - Word16 fac2 = 0 + 512; - Word16 step = 1024; - Word16 i; - - FOR( i=0; i +#include "options.h" +#include "cnst.h" +#include "prot.h" + +/*------------------------------------------------------------------- + * decod_ppp() + * + * PPP decoder + *-------------------------------------------------------------------*/ + +void decod_ppp( + Decoder_State *st, /* i/o: state structure */ + const float Aq[], /* i : 12k8 Lp coefficient */ + float *pitch_buf, /* i/o: floating pitch values for each subframe */ + float *exc, /* i/o: current non-enhanced excitation */ + float *exc2, /* i/o: current enhanced excitation */ + float *voice_factors, /* o : voicing factors */ + float *bwe_exc /* o : excitation for SWB TBE */ + , float *gain_buf + , short bfi +) +{ + short k; + float p_Aq_old[M+1], excQ_ppp[L_FRAME], p_Aq_curr[M], LPC_de_old[M+1]; + float LPC_de_curr[M+1], pitch[NB_SUBFR]; + + /* call voiced decoder at this point */ + for( k=0; klsp_old, p_Aq_old, M ); + + deemph_lpc( p_Aq_curr, p_Aq_old, LPC_de_curr, LPC_de_old + ,0 + ); + + /* last frame-end lpc and curr frame-end lpc */ + ppp_voiced_decoder( st, excQ_ppp, LPC_de_curr, exc, pitch + ,bfi + ); + + st->tilt_code = st->prev_tilt_code_dec; + + mvr2r( excQ_ppp, exc, L_FRAME ); + mvr2r( exc, exc2, L_FRAME ); + + st->dispMem[0] = 2; + st->dispMem[2] = st->prev_gain_pit_dec; + + for(k=3; k<7; k++) + { + st->dispMem[k] = st->dispMem[k-1]; + } + + mvr2r( pitch, pitch_buf, NB_SUBFR ); + + interp_code_5over2( exc2, bwe_exc, L_FRAME ); + set_f( voice_factors, 0.0f, NB_SUBFR16k ); + set_f(gain_buf,0,NB_SUBFR16k); + + return; +} diff --git a/src/libs/libevs/lib_dec/dec_ppp_fx.cpp b/src/libs/libevs/lib_dec/dec_ppp_fx.cpp deleted file mode 100755 index 4c5e7e8d..00000000 --- a/src/libs/libevs/lib_dec/dec_ppp_fx.cpp +++ /dev/null @@ -1,106 +0,0 @@ -/*==================================================================================== - EVS Codec 3GPP TS26.442 Apr 03, 2018. Version 12.11.0 / 13.6.0 / 14.2.0 - ====================================================================================*/ - -#include -#include "options.h" /* Compilation switches */ -#include "prot_fx.h" /* Function prototypes */ -#include "stl.h" - -/*===================================================================*/ -/* FUNCTION : void decod_ppp_fx () */ -/*-------------------------------------------------------------------*/ -/* PURPOSE : decode highly voiced frames using PPP */ -/*-------------------------------------------------------------------*/ -/* INPUT ARGUMENTS : */ -/* _ const Word16 Aq_fx[] - Q12 12k8 Lp coefficient */ -/* _ Word16 bfi_fx - Q0 bad frame indicator */ -/*-------------------------------------------------------------------*/ -/* OUTPUT ARGUMENTS : */ -/* _ Decoder_State_fx *st_fx: */ -/* _ lastLgainD_fx - Q11 */ -/* _ lastHgainD_fx - Q11 */ -/* _ lasterbD_fx - Q13 */ -/*-------------------------------------------------------------------*/ -/* INPUT/OUTPUT ARGUMENTS : */ -/* _ Decoder_State_fx *st_fx: */ -/* _ lsp_old_fx - Q15 */ -/* _ st_fx->dtfs_dec_xxxx */ -/* _ a nd b in st_fx->dtfs_dec_Q */ -/* rest all in Q0 */ -/* _ gainp_ppp Q14 */ -/* _ FadeScale_fx - Q15 */ -/* _ tilt_code_fx - Q15 */ -/* _ prev_tilt_code_dec_fx - Q15 */ -/* _ prev_gain_pit_dec_fx - Q14 */ -/* _ dm_fx.prev_state - Q0 */ -/* _ dm_fx.prev_gain_code - Q16 */ -/* _ .dm_fx.prev_gain_pit - Q14 */ -/* _ prev_gain_pit_dec - Q14 */ -/* _ Word16 *pitch_buf_fx - Q6 fixed pitch values for each subframe */ -/* _ Word16 *exc_fx - Q_exc current non-enhanced excitation */ -/* _ Word16 *exc2_fx - Q_exc current enhanced excitation */ -/*-------------------------------------------------------------------*/ -/* RETURN ARGUMENTS : */ -/* _ None */ -/*-------------------------------------------------------------------*/ -/* CALLED FROM : RX */ -/*===================================================================*/ - -void decod_ppp_fx( - Decoder_State_fx *st_fx, /* i/o: state structure */ - const Word16 Aq_fx[], /* i : 12k8 Lp coefficient */ - Word16 *pitch_buf_fx, /* i/o: fixed pitch values for each subframe */ - Word16 *exc_fx, /* i/o: current non-enhanced excitation */ - Word16 *exc2_fx, /* i/o: current enhanced excitation */ - Word16 bfi /* i : bad frame indicator */ - , Word16 *gain_buf - ,Word16 *voice_factors, /* o : voicing factors */ - Word16 *bwe_exc_fx /* o : excitation for SWB TBE */ -) -{ - Word16 k; - - Word16 LPC_de_curr_fx[M+1], p_Aq_curr_fx[M], p_Aq_old_fx[M+1]; - Word16 excQ_ppp_fx[L_FRAME], pitch_fx[NB_SUBFR], LPC_de_old_fx[M+1]; - - /* call voiced decoder at this point */ - FOR( k=0; ktilt_code_fx = st_fx->tilt_code_dec_fx[3]; - move16(); - - Copy(excQ_ppp_fx, exc_fx, L_FRAME); - Copy(exc_fx, exc2_fx, L_FRAME); - - st_fx->dm_fx.prev_state = 2; - move16(); - - st_fx->dm_fx.prev_gain_pit[0] = st_fx->prev_gain_pit_dec_fx; - move16();/*Q14 */ - - FOR(k=3; k<7; k++) - { - st_fx->dm_fx.prev_gain_pit[k-2] = st_fx->dm_fx.prev_gain_pit[k-3]; - move16();/*Q14 */ - } - - Copy(pitch_fx, pitch_buf_fx, NB_SUBFR);/*Q6 */ - - interp_code_5over2_fx( exc2_fx, bwe_exc_fx, L_FRAME ); - set16_fx( voice_factors, 0, NB_SUBFR16k ); - - - - set16_fx(gain_buf,0,NB_SUBFR16k); - return; -} diff --git a/src/libs/libevs/lib_dec/dec_prm.cpp b/src/libs/libevs/lib_dec/dec_prm.cpp old mode 100755 new mode 100644 index 6b15b2a9..e6269bab --- a/src/libs/libevs/lib_dec/dec_prm.cpp +++ b/src/libs/libevs/lib_dec/dec_prm.cpp @@ -1,644 +1,541 @@ /*==================================================================================== - EVS Codec 3GPP TS26.442 Apr 03, 2018. Version 12.11.0 / 13.6.0 / 14.2.0 + EVS Codec 3GPP TS26.443 Nov 13, 2018. Version 12.11.0 / 13.7.0 / 14.3.0 / 15.1.0 ====================================================================================*/ - - #include #include +#include #include #include -#include "rom_com_fx.h" -#include "stl.h" -#include "prot_fx.h" -#include "basop_util.h" +#include "options.h" +#include "cnst.h" +#include "rom_com.h" +#include "prot.h" + +/*-----------------------------------------------------------------* + * dec_prm_hm() + * + * + *-----------------------------------------------------------------*/ static void dec_prm_hm( - Decoder_State_fx *st, - Word16 *prm_hm, - Word16 L_frame + Decoder_State *st, + int *prm_hm, + const short L_frame ) { - Word16 tmp; - /* Disable HM for non-GC,VC modes */ - test(); - IF (sub(st->tcx_cfg.coder_type, VOICED) != 0 && sub(st->tcx_cfg.coder_type, GENERIC) != 0) + if( st->tcx_cfg.coder_type != VOICED && st->tcx_cfg.coder_type != GENERIC ) { prm_hm[0] = 0; - move16(); - return; } prm_hm[1] = -1; - move16(); prm_hm[2] = 0; - move16(); /* Flag */ - prm_hm[0] = get_next_indice_fx(st, 1); - move16(); + prm_hm[0] = get_next_indice(st, 1); - IF (prm_hm[0] != 0) + if (prm_hm[0]) { - tmp = 0; - move16(); - if (sub(L_frame, 256) >= 0) - { - tmp = 1; - move16(); - } /* Periodicity index */ - DecodeIndex(st, tmp, &prm_hm[1]); + DecodeIndex( st, L_frame >= 256, &prm_hm[1] ); /* Gain index */ - IF (sub(st->tcx_cfg.coder_type, VOICED) == 0) + if( st->tcx_cfg.coder_type == VOICED ) { - prm_hm[2] = get_next_indice_fx(st, kTcxHmNumGainBits); - move16(); + prm_hm[2] = get_next_indice(st, kTcxHmNumGainBits ); } } + + return; } + /*-----------------------------------------------------------------* - * Funtion dec_prm() * + * Function dec_prm() * * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ * * * SQ is used for TCX modes * * decode parameters according to selected mode * *-----------------------------------------------------------------*/ + void dec_prm( - Word16 *core, /* (0) : current frame mode */ - Word16 *last_core, /* (0) : last frame mode */ - Word16 *coder_type, - Word16 param[], /* (o) : decoded parameters */ - Word16 param_lpc[], /* (o) : LPC parameters */ - Word16 *total_nbbits, /* i/o : number of bits / decoded bits */ - Decoder_State_fx *st, - Word16 L_frame, - Word16 *bitsRead + short *core, /* o : current frame mode */ + short *last_core, /* o : last frame mode */ + short *coder_type, /* o : coder type */ + int param[], /* o : decoded parameters */ + int param_lpc[], /* o : LPC parameters */ + Word16 *total_nbbits, /* i/o : number of bits / decoded bits */ + Decoder_State *st, /* i/o: decoder memory state */ + const int L_frame, + short *bitsRead ) { - Word16 j, k, n, sfr, *prm; - Word16 lg; - Word16 lgFB; - Word16 start_bit_pos; - Word16 acelp_target_bits=-1; - Word16 tmp; - Word16 nTnsParams; - Word16 nTnsBits; - Word16 nb_subfr; - Word16 nbits_tcx; - Word16 ix, j_old, wordcnt, bitcnt; - Word16 hm_size; - Word16 *prms; + short j, k, n, sfr; + int *prm; + int lg; + int lgFB; + int start_bit_pos, bits_common; + int acelp_target_bits=-1; + int tmp; + int nTnsParams; + int nTnsBits; + int nb_subfr; + int nbits_tcx; + int ix, j_old, wordcnt, bitcnt; + int hm_size; + int *prms; CONTEXT_HM_CONFIG hm_cfg; - CONTEXT_HM_CONFIG * phm_cfg; - Word16 indexBuffer[N_MAX+1]; - Word8 flag_ctx_hm; - Word32 L_tmp; - Word16 num_bits; - UWord16 lsb; - Word16 ltp_mode, gains_mode; - Word16 ind; - Word16 prm_ltp[LTPSIZE]; + int indexBuffer[N_MAX+1]; + short flag_ctx_hm; + short ind; + short ltp_mode, gains_mode; + int prm_ltp[LTPSIZE]; /*--------------------------------------------------------------------------------* * INIT *--------------------------------------------------------------------------------*/ hm_cfg.indexBuffer = indexBuffer; - move16(); - IF (sub(st->mdct_sw, MODE1) == 0) + if (st->mdct_sw == MODE1) { - start_bit_pos = 0; /* count from frame start */ move16(); + start_bit_pos = 0; /* count from frame start */ /* Adjust st->bits_frame_core not to subtract MODE2 bandwidth signaling */ - FOR (n=0; ntotal_brate_fx, 5243, &L_tmp, &lsb); /* 5243 is 1/50 in Q18. (0+18-15=3) */ - num_bits = extract_l(L_shr(L_tmp, 3)); /* Q0 */ - assert(num_bits == st->total_brate_fx/50); - IF (sub(FrameSizeConfig[n].frame_bits, num_bits) == 0) + if (FrameSizeConfig[n].frame_bits == st->total_brate/50) { - st->bits_frame_core = add(st->bits_frame_core, FrameSizeConfig[n].bandwidth_bits); - BREAK; + st->bits_frame_core += FrameSizeConfig[n].bandwidth_bits; + break; } } } - ELSE + else { - IF( sub(st->rf_flag,1) == 0 ) + if( st->rf_flag == 1 ) { /*Inherent adjustment to accommodate the compact packing used in the RF mode*/ - start_bit_pos = sub(st->next_bit_pos_fx,2); + start_bit_pos = st->next_bit_pos - 2; } - ELSE + else { - start_bit_pos = st->next_bit_pos_fx; + start_bit_pos = st->next_bit_pos; } } /* Framing parameters */ nb_subfr = st->nb_subfr; - move16(); /* Initialize pointers */ prm = param; /* Init counters */ j = 0; - move16(); /* Init LTP data */ st->tcx_hm_LtpPitchLag = -1; - move16(); - st->tcxltp_gain = 0; - move16(); + st->tcxltp_gain = 0.0f; + /*--------------------------------------------------------------------------------* - * HEADER + * EVS HEADER *--------------------------------------------------------------------------------*/ /* Modes (ACE_GC, ACE_UC, TCX20, TCX10...) */ - IF ( st->tcxonly ) + if ( st->tcxonly ) { - tmp = get_next_indice_fx(st, 1); - move16(); - *core = add(tmp, 1); - move16(); + tmp = get_next_indice(st, 1); + *core = tmp+1; + + ind = get_next_indice(st, 2); + st->clas_dec = ONSET; + if( ind == 0 ) { - ind = get_next_indice_fx(st, 2); - st->clas_dec = ONSET; - move16(); - IF( ind == 0 ) + st->clas_dec = UNVOICED_CLAS; + } + else if( ind == 1 ) + { + if( st->last_good >= VOICED_TRANSITION ) { - st->clas_dec = UNVOICED_CLAS; - move16(); + st->clas_dec = VOICED_TRANSITION; } - ELSE IF( sub(ind, 1) == 0 ) + else { st->clas_dec = UNVOICED_TRANSITION; - move16(); - if( sub(st->last_good_fx, VOICED_TRANSITION) >= 0 ) - { - st->clas_dec = VOICED_TRANSITION; - move16(); - } - } - ELSE if( sub(ind, 2) == 0 ) - { - st->clas_dec = VOICED_CLAS; - move16(); } } + else if( ind == 2 ) + { + st->clas_dec = VOICED_CLAS; + } *coder_type = INACTIVE; st->VAD = 0; - move16(); } - ELSE + else { - IF (sub(st->mdct_sw, MODE1) == 0) + if (st->mdct_sw == MODE1) { /* 2 bits instead of 3 as TCX is already signaled */ *core = TCX_20_CORE; - move16(); - st->tcx_cfg.coder_type = get_next_indice_fx(st, 2); - move16(); + st->tcx_cfg.coder_type = get_next_indice(st, 2); *coder_type = st->tcx_cfg.coder_type; - move16(); } - ELSE + else { - IF (sub(st->mdct_sw_enable, MODE2) == 0) + if (st->mdct_sw_enable == MODE2) { - IF (get_next_indice_1_fx(st) != 0) /* TCX */ + if (get_next_indice_1(st)) /* TCX */ { - tmp = get_next_indice_fx(st, 3); + tmp = get_next_indice(st, 3); assert(!(tmp & 4) || !"HQ_CORE encountered in dec_prm"); *core = TCX_20_CORE; - move16(); st->tcx_cfg.coder_type = tmp; - move16(); *coder_type = st->tcx_cfg.coder_type; - move16(); } - ELSE /* ACELP */ + else /* ACELP */ { *core = ACELP_CORE; - move16(); - *coder_type = get_next_indice_fx(st, 2); - move16(); + *coder_type = get_next_indice(st, 2); } } - ELSE + else { - IF(sub(st->rf_flag,1) == 0) + if(st->rf_flag == 1) { - IF( !( st->use_partial_copy ) ) + if( !( st->use_partial_copy ) ) { - tmp = get_next_indice_fx(st, 1); - IF(tmp == 0) + tmp = get_next_indice(st, 1); + if(tmp == 0) { *core = ACELP_CORE; - move16(); } - ELSE + else { *core = TCX_20_CORE; - move16(); st->tcx_cfg.coder_type = *coder_type; - move16(); } } } - ELSE + else { - *core = ACELP_CORE; - move16(); - *coder_type = get_next_indice_fx(st, 3); - move16(); - IF ( sub(*coder_type, ACELP_MODE_MAX) >= 0) + tmp = get_next_indice(st, 3); + if( tmp < ACELP_MODE_MAX ) + { + *core = ACELP_CORE; + *coder_type = tmp; + } + else { *core = TCX_20_CORE; - move16(); - *coder_type=sub(*coder_type,ACELP_MODE_MAX); - st->tcx_cfg.coder_type = *coder_type; - move16(); + st->tcx_cfg.coder_type = tmp-ACELP_MODE_MAX; + *coder_type = st->tcx_cfg.coder_type; } } } } - test(); - IF ( st->igf != 0 && *core == 0 ) + if( st->igf && *core == ACELP_CORE ) { - st->bits_frame_core = sub( st->bits_frame_core, get_tbe_bits_fx(st->total_brate_fx, st->bwidth_fx, st->rf_flag) ); + st->bits_frame_core -= get_tbe_bits(st->total_brate, st->bwidth, st->rf_flag ); } - IF( sub(st->rf_flag,1)==0) + if( st->rf_flag ) { - st->bits_frame_core = sub(st->bits_frame_core, add(st->rf_target_bits, 1)); /* +1 as flag-bit not considered in rf_target_bits */ + st->bits_frame_core -= (st->rf_target_bits+1); /* +1 as flag-bit not considered in rf_target_bits */ } /* Inactive frame detection on non-DTX mode */ - st->VAD = 1; - move16(); - if( sub(*coder_type, INACTIVE) == 0 ) + if( *coder_type == INACTIVE ) { st->VAD = 0; - move16(); + } + else + { + st->VAD = 1; } } /*Core extended mode mapping for correct PLC classification*/ - st->core_ext_mode = *coder_type; - move16(); - - if( sub(*coder_type, INACTIVE) == 0 ) + st->core_ext_mode=*coder_type; + if( *coder_type == INACTIVE ) { st->core_ext_mode = UNVOICED; - move16(); } /* Decode previous mode for error concealment */ - tmp = 0; - move16(); - test(); - test(); - IF( ( *core != ACELP_CORE || st->tcx_cfg.lfacNext > 0 ) && st->use_partial_copy == 0 ) + if( !(*core==0 && st->tcx_cfg.lfacNext<=0) && !st->use_partial_copy ) { - tmp = get_next_indice_fx(st, 1); - move16(); - + tmp = get_next_indice(st, 1); *last_core = tmp; - move16(); - /*for TCX 10 force last_core to be TCX since ACELP as previous core is forbidden*/ - if( sub(*core, TCX_10_CORE) == 0 ) - { - *last_core = TCX_20_CORE; - move16(); - } - test(); - IF( st->prev_bfi_fx == 0 && sub(st->last_core_fx,*last_core) != 0 ) + /*for TCX 10 force last_core to be TCX since ACELP as previous core is forbidden*/ + if(*core==TCX_10_CORE) + { + *last_core = 1; + } + if((st->prev_bfi == 0) && (st->last_core != *last_core)) { st->BER_detect = 1; - move16(); } } - test(); - test(); - IF(sub(st->rf_flag,1)==0 && sub(st->use_partial_copy,1)==0 && !st->tcxonly) + if(st->rf_flag && st->use_partial_copy && !st->tcxonly) { st->bits_frame_core = st->rf_target_bits; /* offset the indices to read the acelp partial copy */ - Mpy_32_16_ss(st->total_brate_fx, 5243, &L_tmp, &lsb); /* 5243 is 1/50 in Q18. (0+18-15=3) */ - num_bits = extract_l(L_shr(L_tmp, 3)); /* Q0 */ - - get_next_indice_tmp_fx(st, start_bit_pos + num_bits - st->rf_target_bits - 3 - st->next_bit_pos_fx); + get_next_indice_tmp(st, start_bit_pos + st->total_brate/50 - st->rf_target_bits - 3 - st->next_bit_pos); } - IF( st->use_partial_copy == 0 ) + if( !st->use_partial_copy ) { + int overlap_code; + /* Set the last overlap mode based on the previous and current frame type and coded overlap mode */ - test(); - IF ((sub(*last_core, ACELP_CORE) == 0) || (sub(*last_core, AMR_WB_CORE) == 0)) + if ((*last_core == ACELP_CORE) || (*last_core == AMR_WB_CORE)) { st->tcx_cfg.tcx_last_overlap_mode = TRANSITION_OVERLAP; - move16(); } - ELSE + else if ((*core == TCX_10_CORE) && (st->tcx_cfg.tcx_curr_overlap_mode == ALDO_WINDOW)) { - test(); - IF ((sub(*core, TCX_10_CORE) == 0) && (sub(st->tcx_cfg.tcx_curr_overlap_mode, ALDO_WINDOW) == 0)) - { - st->tcx_cfg.tcx_last_overlap_mode = FULL_OVERLAP; - move16(); - } - ELSE - { - st->tcx_cfg.tcx_last_overlap_mode = st->tcx_cfg.tcx_curr_overlap_mode; - move16(); - test(); - if ((sub(*core, TCX_10_CORE) != 0) && (sub(st->tcx_cfg.tcx_curr_overlap_mode, FULL_OVERLAP) == 0)) - { - st->tcx_cfg.tcx_last_overlap_mode = ALDO_WINDOW; - move16(); - } - } + st->tcx_cfg.tcx_last_overlap_mode = FULL_OVERLAP; } + else if ((*core != TCX_10_CORE) && (st->tcx_cfg.tcx_curr_overlap_mode == FULL_OVERLAP)) + { + st->tcx_cfg.tcx_last_overlap_mode = ALDO_WINDOW; + } + else + { + st->tcx_cfg.tcx_last_overlap_mode = st->tcx_cfg.tcx_curr_overlap_mode; + } + /* Set the current overlap mode based on the current frame type and coded overlap mode */ st->tcx_cfg.tcx_curr_overlap_mode = ALDO_WINDOW; - move16(); - IF (sub(*core, ACELP_CORE) != 0) + if( *core != ACELP_CORE ) { - tmp = 0; - move16(); - /* if current TCX mode is not 0 (full overlap), read another bit */ - IF (get_next_indice_fx(st, 1)) + overlap_code = 0; + if (get_next_indice(st, 1)) { - tmp = add(2, get_next_indice_fx(st, 1)); + overlap_code = 2 + get_next_indice(st, 1); } - st->tcx_cfg.tcx_curr_overlap_mode = tmp; - move16(); + assert(MIN_OVERLAP == 2 && HALF_OVERLAP == 3); + st->tcx_cfg.tcx_curr_overlap_mode = overlap_code; - /* TCX10 : always symmetric windows */ - test(); - test(); - test(); - if ((sub(*core, TCX_20_CORE) == 0) && (tmp == 0) && (sub(*last_core, ACELP_CORE) != 0) && (sub(*last_core, AMR_WB_CORE) != 0)) + /*TCX10 : always symmetric windows*/ + if ((*core == TCX_20_CORE) && (overlap_code == 0) && + (*last_core != ACELP_CORE) && (*last_core != AMR_WB_CORE)) { st->tcx_cfg.tcx_curr_overlap_mode = ALDO_WINDOW; - move16(); } } - /* SIDE INFO. DECODING */ - IF(st->enableGplc) + if( st->enableGplc ) + /* SIDE INFO. DECODING */ { - Word16 pitchDiff; - Word16 bits_per_subfr, search_range; + short pitchDiff; + short bits_per_subfr, search_range; bits_per_subfr = 4; - move16(); search_range = 8; - move16(); - - st->flagGuidedAcelp = get_next_indice_fx(st, 1); - move16(); + st->flagGuidedAcelp = get_next_indice(st, 1); pitchDiff = 0; - move16(); - IF(st->flagGuidedAcelp) + if( st->flagGuidedAcelp ) { - pitchDiff = get_next_indice_fx(st, bits_per_subfr); - move16(); - st->guidedT0 = sub(pitchDiff, search_range); - move16(); + pitchDiff = get_next_indice(st, bits_per_subfr); + st->guidedT0 = (pitchDiff - search_range); } - test(); - if( (pitchDiff == 0) && st->flagGuidedAcelp) + if( pitchDiff==0 && st->flagGuidedAcelp ) { st->flagGuidedAcelp = 0; - move16(); } } - ELSE + else { st->flagGuidedAcelp = 0; - move16(); } - IF( st->dec_glr ) + if( st->dec_glr ) { - move16(); - st->dec_glr_idx = -1; - IF(*core == ACELP_CORE) + if( *core == ACELP_CORE ) { - st->dec_glr_idx = get_next_indice_fx(st, G_LPC_RECOVERY_BITS); + st->dec_glr_idx = get_next_indice(st, G_LPC_RECOVERY_BITS); + } + else + { + st->dec_glr_idx = -1; } } } + /*--------------------------------------------------------------------------------* * LPC PARAMETERS *--------------------------------------------------------------------------------*/ /*Initialization of LPC Mid flag*/ - st->acelp_cfg.midLpc = st->acelp_cfg.midLpc_enable; - move16(); - test(); - test(); - IF( (sub(st->lpcQuantization, 1) == 0 && (sub(*coder_type, VOICED) == 0) ) || (st->use_partial_copy)) + if( (st->lpcQuantization == 1 && *coder_type == VOICED) || (st->use_partial_copy)) { - st->acelp_cfg.midLpc = 0; - move16(); + (&(st->acelp_cfg))->midLpc = 0; + } + else + { + (&(st->acelp_cfg))->midLpc = st->acelp_cfg.midLpc_enable; } - IF( st->use_partial_copy == 0 ) + if( st->use_partial_copy == 0 ) { /* Number of sets of LPC parameters (does not include mid-lpc) */ - st->numlpc = 2; - move16(); - test(); - if ( st->tcxonly==0 || sub(*core, TCX_10_CORE) < 0 ) + if ( st->tcxonly==0 || *core < TCX_10_CORE ) { st->numlpc = 1; - move16(); + } + else + { + st->numlpc = 2; } /* Decode LPC parameters */ - test(); - IF (st->enableTcxLpc && *core != ACELP_CORE) + if( st->enableTcxLpc && *core != ACELP_CORE ) { - Word16 tcx_lpc_cdk; - tcx_lpc_cdk = tcxlpc_get_cdk(*coder_type); - dec_lsf_tcxlpc(st, ¶m_lpc, st->narrowBand, tcx_lpc_cdk); + int tcx_lpc_cdk; + tcx_lpc_cdk = tcxlpc_get_cdk( *coder_type ); + dec_lsf_tcxlpc( st, ¶m_lpc, st->narrowBand, tcx_lpc_cdk ); } - ELSE + else { - IF (st->lpcQuantization==0) + if( st->lpcQuantization == 0 ) { decode_lpc_avq( st, st->numlpc, param_lpc ); - move16(); } - ELSE IF (sub(st->lpcQuantization, 1) == 0) + else if( st->lpcQuantization == 1 ) { - test(); - test(); - IF(L_sub(st->sr_core, 16000) == 0 && sub(*coder_type, VOICED) == 0 && sub(*core, ACELP_CORE) == 0) + if(st->sr_core == 16000 && *coder_type == VOICED && *core == ACELP_CORE) { lsf_bctcvq_decprm(st, param_lpc); } - ELSE + else { - lsf_msvq_ma_decprm( st, param_lpc, *core, *coder_type, st->acelp_cfg.midLpc, - st->narrowBand, st->sr_core ); + lsf_msvq_ma_decprm( st, param_lpc, *core, *coder_type, st->acelp_cfg.midLpc, st->narrowBand, st->sr_core ); } - } - ELSE - { - assert(0 && "LPC quant not supported!"); - } - } - } - ELSE - { - st->numlpc = 1; - move16(); - - test(); - IF( sub(st->rf_frame_type, RF_TCXFD) == 0 ) - { - param_lpc[0] = 0; - move16(); - param_lpc[1] = get_next_indice_fx(st, lsf_numbits[0]); /* VQ 1 */ - param_lpc[2] = get_next_indice_fx(st, lsf_numbits[1]); /* VQ 2 */ - param_lpc[3] = get_next_indice_fx(st, lsf_numbits[2]); /* VQ 3 */ - } - ELSE IF( sub(st->rf_frame_type, RF_ALLPRED) >= 0 && sub(st->rf_frame_type, RF_NELP) <= 0 ) - { - /* LSF indices */ - param_lpc[0] = get_next_indice_fx(st, 8); /* VQ 1 */ - param_lpc[1] = get_next_indice_fx(st, 8); /* VQ 2 */ - } - } - - st->bits_common = sub(st->next_bit_pos_fx, start_bit_pos); - move16(); - - - /*--------------------------------------------------------------------------------* - * ACELP - *--------------------------------------------------------------------------------*/ - test(); - test(); - IF( sub(*core,ACELP_CORE) == 0 && st->use_partial_copy == 0 ) - { - /* Target Bits */ - acelp_target_bits = sub(st->bits_frame_core, st->bits_common); - - { - Word16 acelp_bits; - move16(); - acelp_bits = BITS_ALLOC_config_acelp( acelp_target_bits, *coder_type, &(st->acelp_cfg), st->narrowBand, st->nb_subfr ); - - /*Sanity check (not instrumented)*/ - if(acelp_bits<0) + else { assert(0); } } + } + else + { + st->numlpc = 1; + + if( st->rf_frame_type == RF_TCXFD ) + { + param_lpc[0] = 0; + param_lpc[1] = get_next_indice(st, lsf_numbits[0]); /* VQ 1 */ + param_lpc[2] = get_next_indice(st, lsf_numbits[1]); /* VQ 2 */ + param_lpc[3] = get_next_indice(st, lsf_numbits[2]); /* VQ 3 */ + } + else if( st->rf_frame_type >= RF_ALLPRED && st->rf_frame_type <= RF_NELP ) + { + /* LSF indices */ + param_lpc[0] = get_next_indice(st, 8); /* VQ 1 */ + param_lpc[1] = get_next_indice(st, 8); /* VQ 2 */ + } + } + + bits_common = st->next_bit_pos - start_bit_pos; + + /*--------------------------------------------------------------------------------* + * ACELP + *--------------------------------------------------------------------------------*/ + + if( *core == ACELP_CORE && st->use_partial_copy == 0 ) + { + /* Target Bits */ + + /* needed in decoder to read the bitstream */ + acelp_target_bits = st->bits_frame_core - bits_common; + + /*Configure ACELP*/ + BITS_ALLOC_config_acelp( acelp_target_bits, *coder_type, &(st->acelp_cfg), st->narrowBand, st->nb_subfr ); + /* Adaptive BPF (2 bits)*/ - n=ACELP_BPF_BITS[st->acelp_cfg.bpf_mode]; - move16(); - - st->bpf_gain_param = shl(st->acelp_cfg.bpf_mode, 1); - IF( n != 0) + n = ACELP_BPF_BITS[st->acelp_cfg.bpf_mode]; + if( n!=0 ) { - st->bpf_gain_param = get_next_indice_fx(st, n); - move16(); + st->bpf_gain_param = get_next_indice(st, n); + } + else + { + st->bpf_gain_param=(st->acelp_cfg.bpf_mode)*2; } /* Mean energy (2 or 3 bits) */ n = ACELP_NRG_BITS[st->acelp_cfg.nrg_mode]; - move16(); - IF( n != 0 ) + if( n!=0 ) { - prm[j++] = get_next_indice_fx(st, n); - move16(); + prm[j++] = get_next_indice(st, n); } /* Subframe parameters */ - FOR (sfr=0; sfracelp_cfg.ltp_mode][sfr]; - move16(); - IF(n!=0) + if( n!=0 ) { - prm[j++] = get_next_indice_fx(st, n); - move16(); + prm[j] = get_next_indice(st, n); + j++; } /* Adaptive codebook filtering (1 bit) */ - IF ( sub(st->acelp_cfg.ltf_mode, 2) == 0) + if( st->acelp_cfg.ltf_mode == 2 ) { - prm[j++] = get_next_indice_fx(st, 1); - move16(); + prm[j] = get_next_indice(st, 1); + j++; } /* Innovative codebook */ { /* Decode pulse positions. */ j_old = j; - move16(); - wordcnt = shr(ACELP_FIXED_CDK_BITS(st->acelp_cfg.fixed_cdk_index[sfr]), 4); - bitcnt = s_and(ACELP_FIXED_CDK_BITS(st->acelp_cfg.fixed_cdk_index[sfr]), 0xF); + wordcnt = ACELP_FIXED_CDK_BITS(st->acelp_cfg.fixed_cdk_index[sfr])/16; + bitcnt = ACELP_FIXED_CDK_BITS(st->acelp_cfg.fixed_cdk_index[sfr]) & 15; - /* sanity check for testing - not instrumented */ - test(); - if ( sub(st->acelp_cfg.fixed_cdk_index[sfr], ACELP_FIXED_CDK_NB) >= 0 || (st->acelp_cfg.fixed_cdk_index[sfr] < 0)) + /* sanity check - can happen in case of bit errors */ + if ((st->acelp_cfg.fixed_cdk_index[sfr] >= ACELP_FIXED_CDK_NB) || (st->acelp_cfg.fixed_cdk_index[sfr] < 0)) { st->acelp_cfg.fixed_cdk_index[sfr] = 0; - move16(); st->BER_detect = 1; - move16(); } - FOR (ix = 0; ix < wordcnt; ix++) + for (ix = 0; ix < wordcnt; ix++) { - prm[j++] = get_next_indice_fx(st, 16); - move16(); + prm[j] = get_next_indice(st, 16); + j++; } - IF (bitcnt) + + if( bitcnt ) { - prm[j] = get_next_indice_fx(st, bitcnt); - move16(); + prm[j] = get_next_indice(st, bitcnt); } - j = add(j_old, 8); - + j = j_old + 8; } /* Gains (5b, 6b or 7b / subfr) */ n = ACELP_GAINS_BITS[st->acelp_cfg.gains_mode[sfr]]; - move16(); - - prm[j++] = get_next_indice_fx(st, n); - move16(); + prm[j++] = get_next_indice(st, n); }/*end of subfr loop*/ } - - ELSE IF( sub(st->rf_frame_type,RF_ALLPRED) >= 0 && st->use_partial_copy ) + else if ( st->rf_frame_type >= RF_ALLPRED && st->use_partial_copy ) { BITS_ALLOC_config_acelp( st->rf_target_bits, /* target bits ranges from 56 to 72 depending on rf_type */ st->rf_frame_type, /* already offset by 4 to parse the config elements for partial copy */ @@ -647,202 +544,150 @@ void dec_prm( st->nb_subfr ); /* rf_frame_type NELP: 7 */ - IF(sub(st->rf_frame_type,RF_NELP) == 0) + if(st->rf_frame_type == RF_NELP) { /* NELP gain indices */ - st->rf_indx_nelp_iG1 = get_next_indice_fx( st, 5 ); - st->rf_indx_nelp_iG2[0] = get_next_indice_fx( st, 6 ); - st->rf_indx_nelp_iG2[1] = get_next_indice_fx( st, 6 ); + st->rf_indx_nelp_iG1 = get_next_indice( st, 5 ); + st->rf_indx_nelp_iG2[0] = get_next_indice( st, 6 ); + st->rf_indx_nelp_iG2[1] = get_next_indice( st, 6 ); /* NELP filter selection index */ - st->rf_indx_nelp_fid = get_next_indice_fx( st, 2 ); + st->rf_indx_nelp_fid = get_next_indice( st, 2 ); /* tbe gainFr */ - st->rf_indx_tbeGainFr = get_next_indice_fx( st, 5 ); + st->rf_indx_tbeGainFr = get_next_indice( st, 5 ); } - ELSE + else { /* rf_frame_type ALL_PRED: 4, NO_PRED: 5, GEN_PRED: 6*/ /* ES pred */ - prm[j++] = get_next_indice_fx(st, 3); + prm[j++] = get_next_indice(st, 3); ltp_mode = ACELP_LTP_MODE[1][1][st->rf_frame_type]; gains_mode = ACELP_GAINS_MODE[1][1][st->rf_frame_type]; /* Subframe parameters */ - FOR( sfr = 0; sfr < nb_subfr; sfr++ ) + for( sfr = 0; sfr < nb_subfr; sfr++ ) { /* Pitch lag (5, or 8 bits) */ n = ACELP_LTP_BITS_SFR[ltp_mode][sfr]; - IF (n != 0) + if (n != 0) { - prm[j++] = get_next_indice_fx(st, n); + prm[j++] = get_next_indice(st, n); } + /*Innovative codebook*/ - test(); - test(); - test(); - IF( sub(st->rf_frame_type,RF_NOPRED) == 0 - || ( sub(st->rf_frame_type,RF_GENPRED) == 0 && (sfr == 0 || sub(sfr,2) == 0)) ) + if( (st->rf_frame_type == RF_NOPRED) + || ( st->rf_frame_type == RF_GENPRED && (sfr == 0 || sfr == 2)) ) { /* NOTE: FCB actual bits need to be backed up as well */ /*n = ACELP_FIXED_CDK_BITS(st->rf_indx_fcb[fec_offset][sfr]) & 15;*/ - prm[j] = get_next_indice_fx(st, 7); - j = add(j,8); + prm[j] = get_next_indice(st, 7); + j = j + 8; } /* Gains (5b, 6b or 7b / subfr) */ - test(); - IF( sfr == 0 || sub(sfr,2) == 0) + if( sfr == 0 || sfr == 2) { n = ACELP_GAINS_BITS[gains_mode]; - prm[j++] = get_next_indice_fx(st, n); + prm[j++] = get_next_indice(st, n); } } - - st->rf_indx_tbeGainFr = get_next_indice_fx( st, 2 ); + st->rf_indx_tbeGainFr = get_next_indice( st, 2 ); } } /*--------------------------------------------------------------------------------* * TCX20 *--------------------------------------------------------------------------------*/ - test(); - IF( sub(*core, TCX_20_CORE) == 0 && st->use_partial_copy == 0 ) + + if( *core == TCX_20_CORE && st->use_partial_copy == 0 ) { flag_ctx_hm = 0; - move16(); - IF (st->enablePlcWaveadjust) + if( st->enablePlcWaveadjust ) { - st->tonality_flag = get_next_indice_fx(st, 1); - move16(); + st->tonality_flag = get_next_indice(st, 1); } /* TCX Gain = 7 bits */ - prm[j++] = get_next_indice_fx(st, 7); - move16(); + prm[j++] = get_next_indice(st, 7); /* TCX Noise Filling = NBITS_NOISE_FILL_LEVEL bits */ - prm[j++] = get_next_indice_fx(st, NBITS_NOISE_FILL_LEVEL); - move16(); + prm[j++] = get_next_indice(st, NBITS_NOISE_FILL_LEVEL); /* LTP data */ - /* PLC pitch info for HB */ - test(); - IF (st->tcxltp != 0 || L_sub(st->sr_core, 25600) > 0) + if ( st->tcxltp || st->sr_core > 25600 ) /* PLC pitch info for HB */ { - prm[j] = get_next_indice_fx(st, 1); - move16(); - - IF ( prm[j] ) + prm[j] = get_next_indice(st, 1); + if( prm[j] ) { - prm[j+1] = get_next_indice_fx(st, 9); - move16(); - prm[j+2] = get_next_indice_fx(st, 2); - move16(); + prm[j+1] = get_next_indice(st, 9); + prm[j+2] = get_next_indice(st, 2); } - st->BER_detect = st->BER_detect | - tcx_ltp_decode_params(&prm[j], - &(st->tcxltp_pitch_int), - &(st->tcxltp_pitch_fr), - &(st->tcxltp_gain), - st->pit_min, - st->pit_fr1, - st->pit_fr2, - st->pit_max, - st->pit_res_max); - - st->tcx_hm_LtpPitchLag = -1; - move16(); + tcx_ltp_decode_params( + &prm[j], &(st->tcxltp_pitch_int), &(st->tcxltp_pitch_fr), &(st->tcxltp_gain), + st->pit_min, st->pit_fr1, st->pit_fr2, st->pit_max, st->pit_res_max ); st->tcxltp_last_gain_unmodified = st->tcxltp_gain; - move16(); - - test(); - IF ((st->tcxonly == 0) && (sub(st->tcxltp_pitch_int, L_frame) < 0)) - { - Word32 tmp32 = L_shl(L_mult0(st->L_frame_fx, st->pit_res_max), 1+kLtpHmFractionalResolution+1); - Word16 tmp1 = add(imult1616(st->tcxltp_pitch_int, st->pit_res_max), st->tcxltp_pitch_fr); - st->tcx_hm_LtpPitchLag = div_l(tmp32, tmp1); - } + st->tcx_hm_LtpPitchLag = ((!st->tcxonly) && (st->tcxltp_pitch_int < L_frame) + ? (((2 * st->L_frame * st->pit_res_max) << kLtpHmFractionalResolution) / (st->tcxltp_pitch_int * st->pit_res_max + st->tcxltp_pitch_fr)) + : -1); } - j = add(j, 3); + j += 3; /* TCX spectral data */ lg = L_frame; - move16(); lgFB = st->tcx_cfg.tcx_coded_lines; - move16(); - IF (*last_core == ACELP_CORE ) + if( *last_core == ACELP_CORE ) { /* ACE->TCX transition */ - lg = add(lg, st->tcx_cfg.tcx_offset); - if(st->tcx_cfg.lfacNext < 0) - { - lg = sub(lg,st->tcx_cfg.lfacNext); - } + lg += st->tcx_cfg.tcx_offset; + lgFB += lgFB >> 2; - lgFB = add(lgFB, shr(lgFB, 2)); + if( st->tcx_cfg.lfacNext < 0 ) + { + lg -= st->tcx_cfg.lfacNext; + } } /* TNS data */ nTnsParams = 0; - move16(); nTnsBits = 0; - move16(); - IF (st->tcx_cfg.fIsTNSAllowed) + if( st->tcx_cfg.fIsTNSAllowed ) { SetTnsConfig(&st->tcx_cfg, 1, *last_core == ACELP_CORE); + ReadTnsData(st->tcx_cfg.pCurrentTnsConfig, st, &nTnsBits, prm+j, &nTnsParams); - j = add(j, nTnsParams); - } - hm_size = shl(mult(st->TcxBandwidth, lg), 1); - - test(); - IF (st->tcx_lpc_shaped_ari != 0 && sub(*last_core, ACELP_CORE) != 0) - { - dec_prm_hm(st, &prm[j], hm_size); + j += nTnsParams; } - nbits_tcx = sub(st->bits_frame_core, sub(st->next_bit_pos_fx, start_bit_pos)); - if (st->enableGplc != 0) + hm_size = (int)(2.0f*st->TcxBandwidth*(float)lg); + + if( st->tcx_lpc_shaped_ari && *last_core != ACELP_CORE) { - nbits_tcx = sub(nbits_tcx, 7); + dec_prm_hm(st, &prm[j], hm_size ); } + nbits_tcx = ( st->bits_frame_core - (st->next_bit_pos - start_bit_pos) ); + /*Context HM flag*/ - test(); - IF ( st->tcx_cfg.ctx_hm && sub(*last_core, ACELP_CORE) != 0 ) + if ( st->tcx_cfg.ctx_hm && (*last_core != ACELP_CORE) ) { - prm[j] = get_next_indice_fx(st, 1); - move16(); - nbits_tcx = sub(nbits_tcx, 1); + prm[j] = get_next_indice(st, 1); + nbits_tcx--; - IF (prm[j]) + if( prm[j] ) { - Word16 NumIndexBits; + int NumIndexBits = DecodeIndex( st, hm_size >= 256, prm+j+1 ); - tmp = 0; - move16(); - if(sub(hm_size, 256) >= 0) - { - tmp = 1; - move16(); - } - - NumIndexBits = DecodeIndex(st, - tmp, - prm+j+1); - - flag_ctx_hm = 1; - move16(); + flag_ctx_hm=1; ConfigureContextHm( lgFB, @@ -851,124 +696,92 @@ void dec_prm( st->tcx_hm_LtpPitchLag, &hm_cfg); - nbits_tcx = sub(nbits_tcx, NumIndexBits); + nbits_tcx-=NumIndexBits; } } - j = add(j, NPRM_CTX_HM); - + j += NPRM_CTX_HM; /* read IGF payload */ - IF (st->igf) + if (st->igf) { + n = st->next_bit_pos; + IGFDecReadLevel( &st->hIGFDec, st, (st->last_core == ACELP_CORE)?IGF_GRID_LB_TRAN:IGF_GRID_LB_NORM, 1 ); - n = st->next_bit_pos_fx; - move16(); - IF (sub(st->last_core_fx, ACELP_CORE) == 0) - { - IGFDecReadLevel( &st->hIGFDec, st, IGF_GRID_LB_TRAN, 1 ); - IGFDecReadData( &st->hIGFDec, st, IGF_GRID_LB_TRAN, 1 ); - - } - ELSE - { - IGFDecReadLevel( &st->hIGFDec, st, IGF_GRID_LB_NORM, 1 ); - IGFDecReadData( &st->hIGFDec, st, IGF_GRID_LB_NORM, 1 ); - } - - nbits_tcx = sub(nbits_tcx, sub(st->next_bit_pos_fx, n)); + IGFDecReadData( &st->hIGFDec, st, (st->last_core == ACELP_CORE)?IGF_GRID_LB_TRAN:IGF_GRID_LB_NORM, 1 ); + nbits_tcx -= (st->next_bit_pos - n); } - nbits_tcx = sub(st->bits_frame_core, sub(st->next_bit_pos_fx, start_bit_pos)); - IF (st->tcx_lpc_shaped_ari != 0) + + nbits_tcx = ( st->bits_frame_core - (st->next_bit_pos - start_bit_pos) ); + if( st->tcx_lpc_shaped_ari ) { - prm[j++] = nbits_tcx; /* store length of buffer */ move16(); + prm[j++] = nbits_tcx; /* store length of buffer */ prms = &prm[j]; - FOR (ix = 0; ix < nbits_tcx; ix++) + for (ix = 0; ix < nbits_tcx; ix++) { - prms[ix] = get_next_indice_1_fx(st); - move16(); + prms[ix] = get_next_indice_1(st); } - set16_fx(prms+nbits_tcx, 1, 32); - j = add(j, nbits_tcx); + for (ix = 0; ix < 32; ix++) + { + prms[ix+nbits_tcx] = 1; + } + j += nbits_tcx; } - ELSE + else { - phm_cfg = NULL; - move16(); - if (flag_ctx_hm) - { - phm_cfg = &hm_cfg; - move16(); - } - st->resQBits[0] = ACcontextMapping_decode2_no_mem_s17_LC(st, - prm+j, - lgFB, - nbits_tcx, - NPRM_RESQ*st->tcx_cfg.resq, - phm_cfg); - move16(); - j = add(j, lg); + + st->resQBits[0] = ACcontextMapping_decode2_no_mem_s17_LC( st, prm+j,lgFB, + nbits_tcx, NPRM_RESQ*st->tcx_cfg.resq, flag_ctx_hm ? &hm_cfg : NULL ); + j += lg; } } - - test(); - test(); - IF( sub(st->rf_frame_type,RF_TCXFD) >= 0 && sub(st->rf_frame_type,RF_TCXTD2) <= 0 && sub(st->use_partial_copy,1) == 0 ) + if( st->rf_frame_type >= RF_TCXFD && st->rf_frame_type <= RF_TCXTD2 && st->use_partial_copy == 1 ) { /* classification */ - ind = get_next_indice_fx(st, 2); + ind = get_next_indice(st, 2); st->clas_dec = ONSET; - move16(); - - IF( ind == 0 ) + if( ind == 0 ) { st->clas_dec = UNVOICED_CLAS; - move16(); } - ELSE IF( sub(ind, 1) == 0 ) + else if( ind == 1 ) { - IF( sub(st->last_good_fx, VOICED_TRANSITION) >= 0 ) + if( st->last_good >= VOICED_TRANSITION ) { st->clas_dec = VOICED_TRANSITION; - move16(); } - ELSE + else { st->clas_dec = UNVOICED_TRANSITION; - move16(); } } - ELSE IF( sub(ind, 2) == 0 ) + else if( ind == 2 ) { st->clas_dec = VOICED_CLAS; - move16(); } - IF( sub(st->rf_frame_type, RF_TCXFD) == 0 ) + if( st->rf_frame_type == RF_TCXFD ) { /* TCX Gain = 7 bits */ - st->old_gaintcx_bfi = get_next_indice_fx(st, 7); + st->old_gaintcx_bfi = get_next_indice(st, 7); } - ELSE + else { /* LTP data */ - IF( st->tcxltp != 0 ) + if( st->tcxltp ) { - IF( sub(st->rf_frame_type, RF_TCXTD2) == 0 || sub(st->rf_frame_type, RF_TCXTD1) == 0) + if( st->rf_frame_type == RF_TCXTD2 || st->rf_frame_type == RF_TCXTD1 ) { - prm_ltp[0] = 1; - move16(); /* LTP active*/ - prm_ltp[1] = get_next_indice_fx(st, 9); - prm_ltp[2] = 3; - move16(); /* max ampl. quantizer output (2bits), anyway not used later*/ + prm_ltp[0] = 1; /* LTP active*/ + prm_ltp[1] = get_next_indice(st, 9); + prm_ltp[2] = 3; /* max ampl. quantizer output (2bits), anyway not used later*/ - IF( st->prev_bfi_fx == 0 ) + if(!st->prev_bfi) { st->BER_detect = st->BER_detect | - tcx_ltp_decode_params(&prm_ltp[0], &(st->tcxltp_pitch_int), &(st->tcxltp_pitch_fr), &(st->tcxltp_gain), - st->pit_min, st->pit_fr1, st->pit_fr2, st->pit_max, st->pit_res_max ); + tcx_ltp_decode_params(&prm_ltp[0], &(st->tcxltp_pitch_int), &(st->tcxltp_pitch_fr), &(st->tcxltp_gain), + st->pit_min, st->pit_fr1, st->pit_fr2, st->pit_max, st->pit_res_max ); st->tcxltp_last_gain_unmodified = st->tcxltp_gain; - move16(); } } } @@ -980,174 +793,123 @@ void dec_prm( * TCX10 *--------------------------------------------------------------------------------*/ - IF ( sub(*core, TCX_10_CORE) == 0) + if( *core == TCX_10_CORE ) { - Word16 tcxltp_prm_0 = 0; - Word16 tcxltp_prm_1 = 0; - Word16 tcxltp_prm_2 = 0; - Word16 nbits_igf = 0; - move16(); - move16(); - move16(); - move16(); - move16(); + int tcxltp_prm_0 = 0; + int tcxltp_prm_1 = 0; + int tcxltp_prm_2 = 0; + int nbits_igf = 0; /* read IGF payload */ - IF (st->igf) + if (st->igf) { + for (k = 0; k < 2; k++) + { + n = st->next_bit_pos; - n = st->next_bit_pos_fx; - move16(); + IGFDecReadLevel( &st->hIGFDec, st, IGF_GRID_LB_SHORT, k == 0 ? 1 : 0 ); - IGFDecReadLevel( &st->hIGFDec, st, IGF_GRID_LB_SHORT, 1); - IGFDecReadData( &st->hIGFDec, st, IGF_GRID_LB_SHORT, 1); - IGFDecStoreTCX10SubFrameData( &st->hIGFDec, 0 ); + IGFDecReadData( &st->hIGFDec, st, IGF_GRID_LB_SHORT, k == 0 ? 1 : 0 ); - IGFDecReadLevel( &st->hIGFDec, st, IGF_GRID_LB_SHORT, 0); - IGFDecReadData( &st->hIGFDec, st, IGF_GRID_LB_SHORT, 0); - IGFDecStoreTCX10SubFrameData( &st->hIGFDec, 1 ); - - nbits_igf = sub(st->next_bit_pos_fx, n); + IGFDecStoreTCX10SubFrameData( &st->hIGFDec, k ); + nbits_igf += st->next_bit_pos - n; + } } - FOR (k = 0; k < 2; k++) + + for( k = 0; k < 2; k++ ) { flag_ctx_hm = 0; - move16(); prm = param + (k*DEC_NPRM_DIV); j = 0; - move16(); + nbits_tcx = st->next_bit_pos - start_bit_pos; - nbits_tcx = sub(st->next_bit_pos_fx, start_bit_pos); - - test(); - IF (st->enablePlcWaveadjust && k) + if(st->enablePlcWaveadjust && k) { - st->tonality_flag = get_next_indice_fx(st, 1); - move16(); + st->tonality_flag = get_next_indice(st, 1); } /* TCX Gain = 7 bits */ - prm[j++] = get_next_indice_fx(st, 7); - move16(); + prm[j++] = get_next_indice(st, 7); /* TCX Noise Filling = NBITS_NOISE_FILL_LEVEL bits */ - prm[j++] = get_next_indice_fx(st, NBITS_NOISE_FILL_LEVEL); - move16(); + prm[j++] = get_next_indice(st, NBITS_NOISE_FILL_LEVEL); /* LTP data */ - test(); - test(); - IF ( (k == 0) && ((st->tcxltp != 0) || (L_sub(st->sr_core, 25600) > 0)) ) + if( (k == 0) && ( st->tcxltp || (st->sr_core > 25600) ) ) /* PLC pitch info for HB */ { - prm[j] = get_next_indice_fx(st, 1); - move16(); + prm[j] = get_next_indice(st, 1); - IF ( prm[j] ) + if( prm[j] ) { - - prm[j+1] = get_next_indice_fx(st, 9); - move16(); - prm[j+2] = get_next_indice_fx(st, 2); - move16(); + prm[j+1] = get_next_indice(st, 9); + prm[j+2] = get_next_indice(st, 2); tcxltp_prm_0 = prm[j]; - move16(); tcxltp_prm_1 = prm[j+1]; - move16(); tcxltp_prm_2 = prm[j+2]; - move16(); } st->BER_detect = st->BER_detect | - tcx_ltp_decode_params(&prm[j], - &(st->tcxltp_pitch_int), - &(st->tcxltp_pitch_fr), - &(st->tcxltp_gain), - st->pit_min, - st->pit_fr1, - st->pit_fr2, - st->pit_max, - st->pit_res_max); + tcx_ltp_decode_params( + &prm[j], &(st->tcxltp_pitch_int), &(st->tcxltp_pitch_fr), &(st->tcxltp_gain), + st->pit_min, st->pit_fr1, st->pit_fr2, st->pit_max, st->pit_res_max ); st->tcxltp_last_gain_unmodified = st->tcxltp_gain; - move16(); st->tcx_hm_LtpPitchLag = -1; - move16(); - - j = add(j, 3); + j += 3; } - ELSE + else { prm[j++] = tcxltp_prm_0; - move16(); prm[j++] = tcxltp_prm_1; - move16(); prm[j++] = tcxltp_prm_2; - move16(); } - /* TCX spectral data */ - lg = shr(L_frame, 1); - lgFB = shr(st->tcx_cfg.tcx_coded_lines, 1); - test(); - IF ( k == 0 && *last_core == ACELP_CORE ) + /* TCX spectral data */ + lgFB = st->tcx_cfg.tcx_coded_lines >> 1;; + + if( k==0 && *last_core == ACELP_CORE ) { /* ACE->TCX transition */ - lg = add(lg, st->tcx_cfg.tcx_offset); - if(st->tcx_cfg.lfacNext<0) - { - lg = sub(lg,st->tcx_cfg.lfacNext); - } - - lgFB = add(lgFB, shr(lgFB, 1)); + lgFB += lgFB >> 1; } /* TNS data */ nTnsParams = 0; - move16(); nTnsBits = 0; - move16(); - IF (st->tcx_cfg.fIsTNSAllowed) + if( st->tcx_cfg.fIsTNSAllowed ) { - IF( sub(*last_core, ACELP_CORE) == 0 && (k == 0)) + if((*last_core == ACELP_CORE) && (k == 0)) { st->BER_detect = 1; *last_core = 1; } - test(); - test(); - SetTnsConfig(&st->tcx_cfg, 0, (*last_core == ACELP_CORE) && (k == 0)); + SetTnsConfig(&st->tcx_cfg, 0, 0 /*(*last_core == ACELP_CORE) && (k == 0)*/); /* lcm : tnsConfig[0][1] does not exist !!! */ ReadTnsData(st->tcx_cfg.pCurrentTnsConfig, st, &nTnsBits, prm+j, &nTnsParams); - j = add(j, nTnsParams); + j += nTnsParams; } - hm_size = shl(mult(st->TcxBandwidth, lgFB), 1); + hm_size = (int)(2.0f*st->TcxBandwidth*(float)lgFB); /*compute target bits*/ - nbits_tcx = sub(shr(sub(add(sub(sub(st->bits_frame_core, st->bits_common), nbits_igf), 1), k), 1), sub(sub(st->next_bit_pos_fx, start_bit_pos), nbits_tcx)); + nbits_tcx = (( st->bits_frame_core - bits_common - nbits_igf + 1 - k) >> 1 ) - ( (st->next_bit_pos - start_bit_pos) - nbits_tcx); /*Context HM flag*/ - test(); - test(); - IF ( st->tcx_cfg.ctx_hm && !(*last_core == ACELP_CORE && k == 0) ) + if( st->tcx_cfg.ctx_hm && !(*last_core == ACELP_CORE && k == 0) ) { - prm[j] = get_next_indice_fx(st, 1); - move16(); - nbits_tcx = sub(nbits_tcx, 1); - move16(); + prm[j] = get_next_indice(st, 1); + nbits_tcx--; - IF (prm[j]) /* Read PeriodicityIndex */ + if( prm[j] ) { - Word16 NumIndexBits = DecodeIndex(st, - hm_size >= 256, - prm+j+1); + /* Read PeriodicityIndex */ + int NumIndexBits = DecodeIndex( st, hm_size >= 256, prm+j+1 ); flag_ctx_hm = 1; - move16(); ConfigureContextHm( lgFB, @@ -1156,40 +918,28 @@ void dec_prm( -1, &hm_cfg); - nbits_tcx = sub(nbits_tcx, NumIndexBits); + nbits_tcx -= NumIndexBits; } } - j = add(j, NPRM_CTX_HM); - phm_cfg = NULL; - move16(); - if (flag_ctx_hm) - { - phm_cfg = &hm_cfg; - move16(); - } - st->resQBits[k] = ACcontextMapping_decode2_no_mem_s17_LC(st, prm+j, + j += NPRM_CTX_HM; + + st->resQBits[k] = ACcontextMapping_decode2_no_mem_s17_LC( st, prm+j, lgFB, - nbits_tcx, - NPRM_RESQ*st->tcx_cfg.resq, - phm_cfg); - move16(); - j = add(j, lgFB); + nbits_tcx, NPRM_RESQ*st->tcx_cfg.resq, flag_ctx_hm ? &hm_cfg : NULL ); + j += lgFB; } /* k, window index */ } - IF(!st->use_partial_copy) + + if(!st->use_partial_copy) { - IF (sub(sub(*total_nbbits, bitsRead[0]), sub(st->next_bit_pos_fx, start_bit_pos)) < 0) + if (*total_nbbits-bitsRead[0] < (st->next_bit_pos - start_bit_pos)) { st->BER_detect = 1; - move16(); - st->next_bit_pos_fx = add(start_bit_pos, sub(*total_nbbits, bitsRead[0])); + st->next_bit_pos = start_bit_pos + *total_nbbits - bitsRead[0]; } - bitsRead[0] = sub(st->next_bit_pos_fx, start_bit_pos); - move16(); + bitsRead[0] = st->next_bit_pos - start_bit_pos; } - return; } - diff --git a/src/libs/libevs/lib_dec/dec_tcx.cpp b/src/libs/libevs/lib_dec/dec_tcx.cpp old mode 100755 new mode 100644 index a27cde46..3d50c874 --- a/src/libs/libevs/lib_dec/dec_tcx.cpp +++ b/src/libs/libevs/lib_dec/dec_tcx.cpp @@ -1,697 +1,432 @@ /*==================================================================================== - EVS Codec 3GPP TS26.442 Apr 03, 2018. Version 12.11.0 / 13.6.0 / 14.2.0 + EVS Codec 3GPP TS26.443 Nov 13, 2018. Version 12.11.0 / 13.7.0 / 14.3.0 / 15.1.0 ====================================================================================*/ #include #include +#include #include -#include "prot_fx.h" -#include "basop_util.h" -#include "stl.h" +#include "prot.h" #include "options.h" -#include "prot_fx.h" +#include "stat_com.h" +#include "cnst.h" -extern const Word16 T_DIV_L_Frame[];/*0Q15 * 2^-7 */ -static Word32 CalculateAbsEnergy( /* o : normalized result Q31 */ - const Word32 L_off, /* i : initial sum value Qn */ - const Word16 x[], /* i : x vector Qn */ - const Word16 lg, /* i : vector length, range [0..7FFF] Q0 */ - Word16 * exp /* o : exponent of result in [-32,31] Q0 */ -); +/*-----------------------------------------------------------------* + * Local functions + *-----------------------------------------------------------------*/ -static void IMDCT(Word32 *x, Word16 x_e, - Word16 *old_syn_overl, - Word16 *syn_Overl_TDAC, - Word16 *xn_buf, - const Word16 *tcx_aldo_window_1, - const PWord16 *tcx_aldo_window_1_trunc, - const PWord16 *tcx_aldo_window_2, - const PWord16 *tcx_mdct_window_half, - const PWord16 *tcx_mdct_window_minimum, - const PWord16 *tcx_mdct_window_trans, - Word16 tcx_mdct_window_half_length, - Word16 tcx_mdct_window_min_length, - Word16 index, - Word16 left_rect, - Word16 tcx_offset, - Word16 overlap, - Word16 L_frame, - Word16 L_frameTCX, - Word16 L_spec_TCX5, - Word16 L_frame_glob, - Word16 frame_cnt, - Word16 bfi, - Word16 *old_out, - Word16 *Q_old_wtda, - Decoder_State_fx *st - ,Word16 fullbandScale - ,Word16 *acelp_zir - ); +static void IMDCT( float *x, float *old_syn_overl, float *syn_Overl_TDAC, float *xn_buf, float *tcx_aldo_window_1_trunc, float *tcx_aldo_window_2, + float *tcx_mdct_window_half, float *tcx_mdct_window_minimum, float *tcx_mdct_window_trans, int tcx_mdct_window_half_length, + int tcx_mdct_window_min_length, int index, int left_rect, int tcx_offset, int overlap, int L_frame, int L_frameTCX, int L_spec_TCX5, + int L_frame_glob, + int frame_cnt, int bfi, float *old_out, short FB_flag, Decoder_State *st, int fullband, float *acelp_zir ); +/*-----------------------------------------------------------------* + * decoder_tcx() + * + * + *-----------------------------------------------------------------*/ void decoder_tcx( - TCX_config *tcx_cfg, /* input: configuration of TCX */ - Word16 prm[], /* input: parameters */ - Word16 A[], /* input: coefficients NxAz[M+1] */ + TCX_config *tcx_cfg, /* input: configuration of TCX */ + int prm[], /* input: parameters */ + float A[], /* input: coefficients NxAz[M+1] */ Word16 Aind[], /* input: frame-independent coefficients Az[M+1] */ - Word16 L_frame_glob, /* input: frame length */ - Word16 L_frameTCX_glob, - Word16 L_spec, - Word16 synth[], /* in/out: synth[-M-LFAC..L_frame] */ - Word16 synthFB[], - Decoder_State_fx *st, - Word16 coder_type, /* input : coder type */ - Word16 bfi, /* input: Bad frame indicator */ - Word16 frame_cnt, /* input: frame counter in the super frame */ - Word16 stab_fac /* input: stability of isf (1Q14) */ + int L_frame_glob, /* input: frame length */ + int L_frameTCX_glob, + int L_spec, + float synth[], /* in/out: synth[-M..L_frame] */ + float synthFB[], + Decoder_State *st, /* in/out: coder memory state */ + const short coder_type, /* input: coder type */ + int bfi, /* input: Bad frame indicator */ + int frame_cnt, /* input: frame counter in the super frame */ + float stab_fac /* input: stability of isf */ ) { - Word16 i, index, L_frame, tcx_offset; - Word16 L_frameTCX, tcx_offsetFB; - Word16 firstLine; - Word16 gain_tcx, gain_tcx_e, fac_ns; - Word16 Ap[M+2]; - Word32 x[N_MAX]; - Word16 x_e; - Word16 *xn_buf; - Word16 xn_bufFB[L_MDCT_OVLP_MAX+L_FRAME_PLUS+L_MDCT_OVLP_MAX]; - Word32 xn_buf32[N_MAX]; - Word16 overlap; - Word16 overlapFB; - Word16 noiseFillingSize; - Word16 noiseTransWidth; - Word16 tnsSize; /* number of tns parameters put into prm */ - Word8 fUseTns; /* flag that is set if TNS data is present */ + short i, index, L_frame, tcx_offset; + short L_frameTCX, tcx_offsetFB; + short firstLine; + float gain_tcx, fac_ns; + float Ap[M+2]; + float x[N_MAX]; + int overlap; + short overlapFB; + short noiseFillingSize; + short noiseTransWidth = MIN_NOISE_FILLING_HOLE; + int tnsSize = 0; /* number of tns parameters put into prm */ + int fUseTns = 0; /* flag that is set if TNS data is present */ STnsData tnsData; - Word16 left_rect; - Word16 gainlpc2[FDNS_NPTS]; - Word16 gainlpc2_e[FDNS_NPTS]; - Word16 noiseTiltFactor; - Word16 nf_seed; - Word16 tmp1, tmp2, s, *tmpP16; - Word8 tmp8; - Word32 tmp32; - Word16 gamma1; - Word16 gamma; - Word16 gainCompensate, gainCompensate_e; - Word16 h1[L_FRAME_MAX/4+1]; - Word16 mem[M]; - Word16 temp_concealment_method = 0; - Word16 arith_bits, signaling_bits; - Word16 *prm_ltp, *prm_tns, *prm_hm, *prm_sqQ, *prm_target; - Word16*pInfoTCXNoise; - Word16 acelp_zir[L_FRAME_MAX/2]; - Word16 noise_filling_index; - Word16 infoIGFStartLine; + short left_rect; + float gainlpc2[FDNS_NPTS]; + float gamma1; + float gamma; + short nf_seed = 0; + float gainCompensate = 1.f; + float h1[L_FRAME_MAX/4+1]; + float mem[M]; + float tmp2; + int arith_bits, signaling_bits; + const int *prm_ltp, *prm_tns, *prm_hm, *prm_sqQ, *prm_target; + float xn_buf[L_MDCT_OVLP_MAX+L_FRAME_PLUS+L_MDCT_OVLP_MAX]; + float xn_bufFB[L_MDCT_OVLP_MAX+L_FRAME_PLUS+L_MDCT_OVLP_MAX]; + float acelp_zir[L_FRAME_MAX/2]; + int sum_word32; + short temp_concealment_method = 0; /* to avoid compilation warnings */ + int infoIGFStartLine; - prm_target = NULL; /* just to suppress MSVC warnigs */ + prm_target = (const int *)NULL; /* just to suppress MSVC warnigs */ - x_e = 0; /* to avoid compilation warnings */ - nf_seed = 0; /* to avoid compilation warnings */ - - - - /* Overlay xn_buf32 with xn_buf */ - xn_buf = (Word16 *) xn_buf32; - - noiseTransWidth = MIN_NOISE_FILLING_HOLE; - move16(); - tnsSize = 0; - move16(); - fUseTns = 0; - move16(); - gainCompensate = 32768/2; - move16(); - gainCompensate_e = 1; - move16(); - FOR (i=0 ; i < (L_MDCT_OVLP_MAX+L_FRAME_PLUS+L_MDCT_OVLP_MAX)/2; i++) - { - xn_buf32[i] = L_deposit_l(0); - } - + /*-----------------------------------------------------------------* + * Initializations + *-----------------------------------------------------------------*/ /* Init lengths */ - overlap = tcx_cfg->tcx_mdct_window_length; - move16(); overlapFB = tcx_cfg->tcx_mdct_window_lengthFB; - move16(); - /* Modified the overlap to the delay in case of short blocks*/ tcx_offset = tcx_cfg->tcx_offset; - move16(); tcx_offsetFB = tcx_cfg->tcx_offsetFB; - move16(); gamma1 = st->gamma; - move16(); - if (st->enableTcxLpc != 0) + if (st->enableTcxLpc) { - gamma1 = 0x7FFF; - move16(); + gamma1 = 1.0f; } - IF (bfi != 0) + if( bfi ) { /* PLC: [TCX: Memory update] * PLC: Init buffers */ assert(st->L_frame_past > 0); L_frame = st->L_frame_past; - move16(); L_frameTCX = st->L_frameTCX_past; - move16(); left_rect = st->prev_widow_left_rect; - move16(); - IF (left_rect != 0) + if( left_rect ) { tcx_offset = tcx_cfg->lfacNext; - move16(); tcx_offsetFB = tcx_cfg->lfacNextFB; - move16(); - L_spec = add(L_spec, shr(st->tcx_cfg.tcx_coded_lines, 2)); - + L_spec += st->tcx_cfg.tcx_coded_lines >> 2; } } - ELSE + else { - test(); - IF ( frame_cnt == 0 && st->last_core_fx == ACELP_CORE ) + if ( frame_cnt == 0 && st->last_core == ACELP_CORE ) { - if (st->prev_bfi_fx == 0) + if (!st->prev_bfi) { tcx_cfg->last_aldo = 0; - move16(); } /* if past frame is ACELP */ - L_frame = add(L_frame_glob, tcx_offset); - L_frameTCX = add(L_frameTCX_glob, tcx_offsetFB); - L_spec = add(L_spec, shr(st->tcx_cfg.tcx_coded_lines, 2)); - assert(tcx_cfg->lfacNext<=0); - L_frame = sub(L_frame , tcx_cfg->lfacNext); - L_frameTCX = sub(L_frameTCX, tcx_cfg->lfacNextFB); - tcx_offset = tcx_cfg->lfacNext; - move16(); - tcx_offsetFB = tcx_cfg->lfacNextFB; - move16(); - left_rect = 1; - move16(); - st->prev_widow_left_rect = 1; - move16(); - } - ELSE - { + L_frame = L_frame_glob + tcx_offset; + L_frameTCX = L_frameTCX_glob + tcx_offsetFB; + L_spec += st->tcx_cfg.tcx_coded_lines >> 2; + assert(tcx_cfg->lfacNext<=0); + L_frame -= tcx_cfg->lfacNext; + L_frameTCX -= tcx_cfg->lfacNextFB; + tcx_offset = tcx_cfg->lfacNext; + tcx_offsetFB = tcx_cfg->lfacNextFB; + + left_rect = 1; + st->prev_widow_left_rect = 1; + } + else + { L_frame = L_frame_glob; - move16(); L_frameTCX = L_frameTCX_glob; - move16(); left_rect = 0; - move16(); st->prev_widow_left_rect = 0; - move16(); } st->L_frame_past = L_frame; - move16(); st->L_frameTCX_past = L_frameTCX; - move16(); } - test(); - IF ( (sub(L_frame, shr(st->L_frame_fx, 1)) == 0) && (st->tcxonly)) + if( (L_frame == st->L_frame >> 1) && (st->tcxonly) ) { - IGFDecUpdateInfo( - &st->hIGFDec, - IGF_GRID_LB_SHORT - ); + IGFDecUpdateInfo( &st->hIGFDec, IGF_GRID_LB_SHORT ); } - ELSE + else { - test(); - test(); - IF ((sub(st->last_core_fx, ACELP_CORE) == 0) || (left_rect && st->bfi_fx)) - { - IGFDecUpdateInfo( - &st->hIGFDec, - IGF_GRID_LB_TRAN - ); - } - ELSE - { - IGFDecUpdateInfo( - &st->hIGFDec, - IGF_GRID_LB_NORM - ); - } + IGFDecUpdateInfo( &st->hIGFDec, (st->last_core == ACELP_CORE || (left_rect && st->bfi))?IGF_GRID_LB_TRAN:IGF_GRID_LB_NORM ); } - IF (0 == st->igf) + if( st->igf == 0 ) { - IF (st->narrowBand == 0) + if( st->narrowBand == 0 ) { /* minimum needed for output with sampling rates lower then the nominal sampling rate */ - infoIGFStartLine = s_min(L_frameTCX, L_frame); - move16(); + infoIGFStartLine = min(L_frameTCX, L_frame); } - ELSE + else { infoIGFStartLine = L_frameTCX; - move16(); } } - ELSE + else { - infoIGFStartLine = s_min(st->hIGFDec.infoIGFStartLine,L_frameTCX); - move16(); + infoIGFStartLine = min(st->hIGFDec.infoIGFStartLine,L_frameTCX); } noiseFillingSize = L_spec; - move16(); - if (st->igf != 0) + if( st->igf ) { noiseFillingSize = st->hIGFDec.infoIGFStartLine; - move16(); } - prm_ltp = &prm[1+NOISE_FILL_RANGES]; - move16(); prm_tns = prm_ltp + LTPSIZE; - move16(); /*-----------------------------------------------------------* * Read TCX parameters * *-----------------------------------------------------------*/ index = 0; - move16(); - IF (bfi == 0) + if( !bfi ) { - index = prm[0]; - move16(); /* read noise level (fac_ns) */ - - noise_filling_index = prm[1]; - move16(); - - fac_ns = extract_l(L_shr(L_mult0(noise_filling_index, 0x6000), NBITS_NOISE_FILL_LEVEL)); - } - ELSE - { - fac_ns = 0; - move16(); + st->noise_filling_index = prm[1]; } + fac_ns = (float)st->noise_filling_index * 0.75f / (1<fIsTNSAllowed != 0)) + if( !bfi && tcx_cfg->fIsTNSAllowed ) { - cast16(); - fUseTns = (Word8)DecodeTnsData(tcx_cfg->pCurrentTnsConfig, - prm_tns, - &tnsSize, - &tnsData); + fUseTns = DecodeTnsData( tcx_cfg->pCurrentTnsConfig, prm_tns, &tnsSize, &tnsData ); } - ELSE + else { fUseTns = 0; - move16(); } prm_hm = prm_tns + tnsSize; - move16(); prm_sqQ = prm_hm + NPRM_CTX_HM; - move16(); /*-----------------------------------------------------------* * Spectrum data * *-----------------------------------------------------------*/ - IF (bfi == 0) + if( !bfi) { - /*-----------------------------------------------------------* - * Context HM * + * Context HM * *-----------------------------------------------------------*/ - test(); - test(); - IF(tcx_cfg->ctx_hm != 0 && ( (st->last_core_fx != ACELP_CORE) || (frame_cnt > 0) ) ) + + if(tcx_cfg->ctx_hm && ( (st->last_core != ACELP_CORE) || (frame_cnt > 0) ) ) { st->last_ctx_hm_enabled = prm_hm[0]; - move16(); { - FOR (i = 0; i < L_spec; i++) /* no context harmonic model, copy MDCT coefficients to x */ + for (i = 0; i < L_spec; i++) { - - x[i] = L_mult(prm_sqQ[i], - 1 << (30 - SPEC_EXP_DEC)); - move32(); + /* no context harmonic model, copy MDCT coefficients to x */ + x[i] = (float)prm_sqQ[i]; } } - x_e = SPEC_EXP_DEC; - move16(); } - ELSE /* tcx_cfg->ctx_hm == 0 */ + else /* tcx_cfg->ctx_hm == 0 */ { - - IF (st->tcx_lpc_shaped_ari != 0) /* low rates: new arithmetic coder */ + if( st->tcx_lpc_shaped_ari ) /* low rates: envelope based arithmetic coder */ { prm_target = prm_sqQ; - move16(); prm_sqQ = prm_target + 1; - move16(); - tmp8 = 1; - move16(); - if (sub(st->last_core_fx, ACELP_CORE) == 0) + tcx_arith_decode_envelope( x, L_frame, L_spec, st, coder_type, Aind, st->tcxltp_gain, *prm_target, prm_sqQ, st->last_core != ACELP_CORE, + prm_hm, /* HM parameter area */ st->tcx_hm_LtpPitchLag, &arith_bits, &signaling_bits ,(st->bwidth > WB)?1:0 ); + + st->resQBits[frame_cnt] = *prm_target - arith_bits; + + /* Noise filling seed */ + for (i=0; itcx_hm_LtpPitchLag, - &arith_bits, - &signaling_bits, - &nf_seed - , shr(st->bwidth_fx, 1) /* equivalent to: (st->bwidth_fx > WB)?1:0 */ - ); - - st->resQBits[frame_cnt] = sub(*prm_target, arith_bits); - move16(); } - ELSE /* TCX-only: old arithmetic coder */ + else /* TCX-only: context based arithmetic coder */ { - FOR (i = 0; i < L_spec; i++) + for (i = 0; i < L_spec; i++) { - - x[i] = L_mult(prm_sqQ[i], - 1 << (30 - SPEC_EXP_DEC)); - move32(); + x[i] = (float)prm_sqQ[i]; } - set32_fx(x+L_spec, 0, sub(L_frameTCX, L_spec)); - - x_e = SPEC_EXP_DEC; - move16(); + for (i=L_spec ; i < L_frameTCX; i++) + { + x[i] = 0.0f; + } } } /* else of if tcx_cfg->ctx_hm */ - tmp1 = s_max(L_frame, L_frameTCX); - set32_fx(x+L_spec, 0, sub(tmp1, L_spec)); + for( i=L_spec ; i < max(L_frame, L_frameTCX); i++ ) + { + x[i] = 0.0f; + } /*-----------------------------------------------------------* * adaptive low frequency deemphasis. * *-----------------------------------------------------------*/ - weight_a_fx(A, Ap, gamma1, M); - - lpc2mdct(Ap, M, NULL, NULL, gainlpc2, gainlpc2_e); - + weight_a( A, Ap, gamma1, M ); + lpc2mdct( Ap, M, gainlpc2 ); /* initialize LF deemphasis factors in xn_buf */ - tmp1 = s_max(L_spec, L_frameTCX); - set16_fx(xn_buf, 0x4000, tmp1); - - IF (st->tcxonly == 0) + for( i = 0; i < max(L_spec, L_frameTCX); i++ ) { - AdaptLowFreqDeemph( x, x_e, st->tcx_lpc_shaped_ari, gainlpc2, gainlpc2_e, - L_frame, xn_buf /* LF deemphasis factors */ ); + xn_buf[i] = 1.0f; + } + + if( !st->tcxonly ) + { + AdaptLowFreqDeemph( x, st->tcx_lpc_shaped_ari, gainlpc2, L_frame, xn_buf /* LF deemphasis factors */ ); } } - /* Global Gain */ - st->damping = 0; + st->damping = 0.f; - IF(bfi==0) + if( bfi == 0 ) { /*-----------------------------------------------------------* * Compute global gain * *-----------------------------------------------------------*/ - tmp32 = L_shl(L_mult0(index, 0x797D), 7); /* 6Q25; 0x797D -> log2(10)/28 (Q18) */ - gain_tcx_e = add(extract_l(L_shr(tmp32, 25)), 1); /* get exponent */ - gain_tcx = round_fx(BASOP_Util_InvLog2(L_or(tmp32, 0xFE000000))); - - tmp1 = mult_r(shl(L_spec, 5), 26214/*128.f/NORM_MDCT_FACTOR Q15*/); - s = 15-5-7; - if(L_spec>=1024) /*reduce precision for avoiding overflow*/ - { - tmp1 = mult_r(shl(L_spec, 4), 26214/*128.f/NORM_MDCT_FACTOR Q15*/); - s = 15-4-7; - } - tmp1 = ISqrt16(tmp1, &s); - - gain_tcx = mult(gain_tcx, tmp1); - gain_tcx_e = add(gain_tcx_e, s); + gain_tcx = (float)pow(10.0f, index/28.0f) * (float)sqrt((float)NORM_MDCT_FACTOR / (float)L_spec); st->old_gaintcx_bfi = gain_tcx; - move16(); - st->old_gaintcx_bfi_e = gain_tcx_e; - move16(); - st->cummulative_damping_tcx = 32767/*1.0f Q15*/; - move16(); + st->cummulative_damping_tcx = 1.0f; } - ELSE /* bfi = 1 */ + else /* bfi = 1 */ { /* PLC: [TCX: Fade-out] * derivation of damping factor */ - - - IF( st->use_partial_copy != 0 ) + if( st->use_partial_copy ) { - IF( sub(st->rf_frame_type, RF_TCXFD) == 0 ) + if( st->rf_frame_type == RF_TCXFD ) { - tmp32 = L_shl(L_mult0(st->old_gaintcx_bfi, 0x797D), 7); /* 6Q25; 0x797D -> log2(10)/28 (Q18) */ - gain_tcx_e = add(extract_l(L_shr(tmp32, 25)), 1); /* get exponent */ - gain_tcx = round_fx(BASOP_Util_InvLog2(L_or(tmp32, 0xFE000000))); - - tmp1 = mult_r(shl(L_spec, 5), 26214/*128.f/NORM_MDCT_FACTOR Q15*/); - s = 15-5-7; - tmp1 = ISqrt16(tmp1, &s); - - gain_tcx = mult(gain_tcx, tmp1); - gain_tcx_e = add(gain_tcx_e, s); - + gain_tcx = (float)pow(10.0f, (int)st->old_gaintcx_bfi/28.0f) * (float)sqrt((float)NORM_MDCT_FACTOR / (float)L_spec); st->old_gaintcx_bfi = gain_tcx; - move16(); - st->old_gaintcx_bfi_e = gain_tcx_e; - move16(); } - ELSE + else { gain_tcx = st->old_gaintcx_bfi; - move16(); - gain_tcx_e = st->old_gaintcx_bfi_e; - move16(); } - st->damping = 16384/*1.f Q14*/; /*Q14*/ move16(); + st->damping = 1; } - ELSE + else { - st->damping = Damping_fact(coder_type, st->nbLostCmpt, st->last_good_fx, stab_fac, &(st->Mode2_lp_gainp), st->last_core_fx); gain_tcx = st->old_gaintcx_bfi; - move16(); - gain_tcx_e = st->old_gaintcx_bfi_e; - move16(); + st->damping = Damping_fact( coder_type, st->nbLostCmpt, st->last_good, stab_fac, &(st->lp_gainp), st->last_core ); } - st->cummulative_damping_tcx = shl(mult(st->cummulative_damping_tcx,st->damping),1);/*shl(Q15*Q14,1)=shl(Q14,1) = Q15*/ - + st->cummulative_damping_tcx *= st->damping; } - { - IF(bfi) + if( bfi ) + { + if( bfi && st->envWeighted ) + { + gamma = st->gamma; + } + else { gamma = gamma1; - move16(); - if (st->envWeighted) - { - gamma = st->gamma; - move16(); - } - - /* PLC: [TCX: Fade-out] - * PLC: invert LPC weighting in case of PLC */ - IF (st->enableTcxLpc != 0) - { - gamma = add(mult_r(st->cummulative_damping_tcx,sub(st->gamma, 32767/*1.0f Q15*/)), 32767/*1.0f Q15*/); - } - ELSE - { - gamma = add(mult_r(st->cummulative_damping_tcx,sub(gamma1, 32767/*1.0f Q15*/)), 32767/*1.0f Q15*/); - } - weight_a_fx(A, Ap, gamma, M); - - lpc2mdct(Ap, M, NULL, NULL, gainlpc2, gainlpc2_e); - } - tmp2 = 0; - move16(); - set16_fx(h1, 0, add(L_SUBFR,1)); - set16_fx(mem, 0, M); - h1[0] = 32768/32; - move16(); - E_UTIL_synthesis(0,Ap, h1, h1, L_SUBFR, mem, 0, M ); - deemph_fx(h1, st->preemph_fac, L_SUBFR, &tmp2); - /* impulse response level = gain introduced by synthesis+deemphasis */ - test(); - IF (bfi==0) + /* PLC: [TCX: Fade-out] + * PLC: invert LPC weighting in case of PLC */ + if( bfi ) { - /* st->last_gain_syn_deemph = (float)sqrt(dot_product( h1, h1, L_SUBFR)); */ - tmp32 = Dot_productSq16HQ( 0, h1, L_SUBFR, &st->last_gain_syn_deemph_e)/*Q15, st->last_gain_syn_deemph_e*/; - st->last_gain_syn_deemph_e = add(st->last_gain_syn_deemph_e,10/*scaling of h1[0] and E_UTIL_synthesis * 2*/); - tmp32 = Sqrt32(tmp32,&st->last_gain_syn_deemph_e); - st->last_gain_syn_deemph = round_fx(tmp32); - /*for avoiding compiler warnings*/ - st->gainHelper = 32768/2; - move16(); - st->gainHelper_e = 1; - move16(); - st->stepCompensate = 0; - move16(); - st->stepCompensate_e = 0; - move16(); - } - /* not instrumenting the additional test() here seems to be common practice */ - ELSE IF (sub(TCX_20_CORE, st->core_fx)== 0 || sub(frame_cnt, 1) == 0 ) - { - /* gainCompensate = st->last_gain_syn_deemph/(float)sqrt(dot_product( h1, h1, L_SUBFR)); */ - tmp32 = Dot_productSq16HQ( 0, h1, L_SUBFR, &gainCompensate_e)/*Q15, gainCompensate_e*/; - gainCompensate_e = add(gainCompensate_e,10/*scaling of h1[0] and E_UTIL:synthesis*/); - gainCompensate = round_fx(Sqrt32(tmp32,&gainCompensate_e))/*Q15, gainCompensate_e*/; - BASOP_Util_Divide_MantExp ( st->last_gain_syn_deemph, - st->last_gain_syn_deemph_e, - gainCompensate, - gainCompensate_e, - &gainCompensate, - &gainCompensate_e); - - tmp1 = T_DIV_L_Frame[L_shl(L_mac(-28000,st->L_frame_fx,95),1-15)]; - - IF (sub(st->nbLostCmpt,1)==0) + if (st->enableTcxLpc) { - /* stepCompensate = (1.f - gainCompensate)/st->L_frame_fx; */ - st->stepCompensate_e = BASOP_Util_Add_MantExp( - tmp1, - -7, - negate(mult(gainCompensate,tmp1)), - add(-7,gainCompensate_e), - &st->stepCompensate); - - st->gainHelper = 32768/2; - move16(); - st->gainHelper_e = 1; - move16(); + gamma = st->cummulative_damping_tcx * (st->gamma - 1) + 1; } - ELSE + else { - /* stepCompensate = (st->last_concealed_gain_syn_deemph - gainCompensate)/st->L_frame_fx; */ - st->stepCompensate_e = BASOP_Util_Add_MantExp( - mult(tmp1,st->last_concealed_gain_syn_deemph), - add(-7, st->last_concealed_gain_syn_deemph_e), - negate(mult(tmp1,gainCompensate)), - add(-7, gainCompensate_e), - &st->stepCompensate); - move16(); - move16(); - st->gainHelper = st->last_concealed_gain_syn_deemph; - st->gainHelper_e = st->last_concealed_gain_syn_deemph_e; + gamma = st->cummulative_damping_tcx * (gamma1 - 1) + 1; } - move16(); - move16(); - st->last_concealed_gain_syn_deemph = gainCompensate; - st->last_concealed_gain_syn_deemph_e = gainCompensate_e; } + weight_a( A, Ap, gamma, M ); + lpc2mdct( Ap, M, gainlpc2 ); } + tmp2 = 0; + set_zero( h1, L_SUBFR+1 ); + set_zero( mem, M ); + h1[0] = 1.0f; + syn_filt( Ap, M,h1, h1, L_SUBFR, mem, 0 ); /* impulse response of LPC */ + deemph( h1, st->preemph_fac, L_SUBFR, &tmp2 ); /* impulse response of deemph */ + + /* impulse response level = gain introduced by synthesis+deemphasis */ + if( !bfi ) + { + st->last_gain_syn_deemph = (float)sqrt(dotp( h1, h1, L_SUBFR) ); + /*for avoiding compiler warnings*/ + st->gainHelper = 1.f; + st->stepCompensate=0.f; + } + else if (TCX_20_CORE == st->core || 1 == frame_cnt ) + { + gainCompensate = st->last_gain_syn_deemph/(float)sqrt(dotp( h1, h1, L_SUBFR) ); + if (st->nbLostCmpt==1) + { + st->stepCompensate = (1.f - gainCompensate)/st->L_frame; + st->gainHelper = 1.f; + } + else + { + st->stepCompensate = (st->last_concealed_gain_syn_deemph - gainCompensate)/st->L_frame; + st->gainHelper = st->last_concealed_gain_syn_deemph; + } + st->last_concealed_gain_syn_deemph = gainCompensate; + } /*-----------------------------------------------------------* * Residual inv. Q. * *-----------------------------------------------------------*/ - test(); - IF ((bfi == 0) && (tcx_cfg->resq != 0)) + + if (!bfi && tcx_cfg->resq ) { - - IF (st->tcx_lpc_shaped_ari != 0) /* new arithmetic coder */ + if( st->tcx_lpc_shaped_ari ) { - - Word16 *prm_resq; - - prm_resq = prm_sqQ - + *prm_target /* = targetBits */ - - st->resQBits[frame_cnt]; - - i = tcx_ari_res_invQ_spec(x, x_e, L_spec, - prm_resq, - st->resQBits[frame_cnt], - 0, - tcx_cfg->sq_rounding, - xn_buf /* LF deemphasis factors */ ); + /* envelope based arithmetic coder */ + const int *prm_resq; + prm_resq = prm_sqQ + *prm_target /* = targetBits */ - st->resQBits[frame_cnt]; + i = tcx_ari_res_invQ_spec( x, L_spec, prm_resq, st->resQBits[frame_cnt], 0, tcx_cfg->sq_rounding, xn_buf /* LF deemphasis factors */ ); } - ELSE /* old arithmetic coder */ + else { - i = tcx_res_invQ_gain(&gain_tcx, &gain_tcx_e, - &prm_sqQ[L_spec], - st->resQBits[frame_cnt]); - - tmpP16 = xn_buf; - if (st->tcxonly != 0) tmpP16 = NULL; - - tcx_res_invQ_spec(x, x_e, L_spec, - &prm_sqQ[L_spec], - st->resQBits[frame_cnt], - i, - tcx_cfg->sq_rounding, - tmpP16 /* LF deemphasis factors */ ); - } - } - test(); - IF (bfi == 0 && st->tcxonly != 0) - { - test(); - test(); - IF (st->tcxltp && (st->tcxltp_gain > 0) && !fUseTns) - { - - PsychAdaptLowFreqDeemph(x, gainlpc2, gainlpc2_e, NULL); + /* context based arithmetic coder */ + i = tcx_res_invQ_gain(&gain_tcx, &prm_sqQ[L_spec], st->resQBits[frame_cnt] ); + tcx_res_invQ_spec( x, L_spec, &prm_sqQ[L_spec], st->resQBits[frame_cnt], i, tcx_cfg->sq_rounding, st->tcxonly ? NULL : xn_buf /* LF deemphasis factors */ ); } } - /* for FAC */ - - test(); - IF (bfi == 0 && st->tcxonly == 0) + if( !bfi && st->tcxonly ) { + if( st->tcxltp && (st->tcxltp_gain > 0.0f) && !fUseTns ) + { + PsychAdaptLowFreqDeemph(x, gainlpc2, NULL); + } + } - + if( !bfi && !st->tcxonly ) + { /* Replication of ACELP formant enhancement for low rates */ - IF (L_sub(st->total_brate_fx, ACELP_13k20) < 0 || st->rf_flag != 0 ) + if (st->bits_frame < 256) { - tcxFormantEnhancement(xn_buf, gainlpc2, gainlpc2_e, x, &x_e, L_frame, L_frameTCX); + tcxFormantEnhancement( xn_buf, gainlpc2, x, L_frame ); } } @@ -699,572 +434,357 @@ void decoder_tcx( * Add gain to the lpc gains * *-----------------------------------------------------------*/ - if(st->VAD==0 ) + if( st->VAD == 0 ) { - gain_tcx = mult_r(gain_tcx, tcx_cfg->na_scale); + gain_tcx *= tcx_cfg->na_scale; } - i = norm_s(gain_tcx); - gain_tcx = shl(gain_tcx, i); - gain_tcx_e = sub(gain_tcx_e, i); - FOR (i = 0; i < FDNS_NPTS; i++) - { - gainlpc2[i] = mult_r(gainlpc2[i], gain_tcx); - move16(); - } + v_multc( gainlpc2, gain_tcx, gainlpc2, FDNS_NPTS); /*-----------------------------------------------------------* * Noise filling. * *-----------------------------------------------------------*/ - test(); - IF (bfi==0 && (fac_ns > 0)) + if( !bfi && (fac_ns > 0.0f) ) { + float noiseTiltFactor; - tmp1 = 0; - move16(); - test(); - if ( sub(st->bits_frame, 256) >= 0 && st->rf_flag == 0 ) + firstLine = tcxGetNoiseFillingTilt( A, L_frame, (st->bits_frame >= 256 && !st->rf_flag), &noiseTiltFactor ); + + if( st->tcxonly ) { - tmp1 = 1; - move16(); - } + noiseTransWidth = HOLE_SIZE_FROM_LTP(max(st->tcxltp_gain,(tcx_cfg->ctx_hm && st->last_core != 0) ? 0.3125f*st->last_ctx_hm_enabled : 0)); - firstLine = tcxGetNoiseFillingTilt( A, M, L_frame, tmp1, &noiseTiltFactor ); - - IF (st->tcxonly != 0) - { - tmp1 = 0; - move16(); - test(); - test(); - if ((tcx_cfg->ctx_hm != 0) && (st->last_core_fx != ACELP_CORE) && (st->last_ctx_hm_enabled != 0)) + if (L_frame == st->L_frame >> 1) { - tmp1 = 10240/*0.3125f Q15*/; - move16(); - } - noiseTransWidth = HOLE_SIZE_FROM_LTP(s_max(st->tcxltp_gain, tmp1)); - - if (sub(L_frame, shr(st->L_frame_fx, 1)) == 0) - { - noiseTransWidth = 3; /* minimum transition fading for noise filling in TCX-10 */ move16(); + noiseTransWidth = 3; /* minimum transition fading for noise filling in TCX-10 */ } } - - IF (st->tcx_lpc_shaped_ari == 0) /* old arithmetic coder */ + if (!st->tcx_lpc_shaped_ari) { + /* context based arithmetic coder */ /* noise filling seed */ - tmp32 = L_deposit_l(0); - FOR (i = 0; i < L_spec; i++) + for (i = 0; i < L_spec; i++) { - tmp32 = L_macNs(tmp32, abs_s(prm_sqQ[i]), i); + nf_seed += (short)(abs(prm_sqQ[i]) * i * 2); } - nf_seed = extract_l(tmp32); } - tmp1 = nf_seed; - move16(); - pInfoTCXNoise = NULL; - if (st->igf) - { - pInfoTCXNoise = st->hIGFDec.infoTCXNoise; - move16(); - } - tcx_noise_filling(x, x_e, - tmp1 /* seed */, - firstLine, - noiseFillingSize, - noiseTransWidth, - L_frame, - noiseTiltFactor, - fac_ns, - pInfoTCXNoise - ); - st->seed_tcx_plc = tmp1; - move16(); + tcx_noise_filling( x, nf_seed, firstLine, noiseFillingSize, noiseTransWidth, + L_frame, noiseTiltFactor, fac_ns, (st->igf)?st->hIGFDec.infoTCXNoise:NULL ); + st->seed_tcx_plc = nf_seed; } - IF (st->enablePlcWaveadjust) + if( st->enablePlcWaveadjust ) { - IF (bfi) + if( bfi ) { - IF (sub(st->nbLostCmpt, 1) == 0) + if( st->nbLostCmpt == 1 ) { st->plcInfo.concealment_method = TCX_NONTONAL; - move16(); /* tonal/non-tonal decision */ - test(); - test(); - IF (0 == sub(st->plcInfo.Transient[0],1) - && 0 == sub(st->plcInfo.Transient[1], 1) - && 0 == sub(st->plcInfo.Transient[2], 1)) + if (st->plcInfo.Transient[0] == 1 && st->plcInfo.Transient[1] == 1 && st->plcInfo.Transient[2] == 1) { - Word16 sum_word16 = 0; - move16(); + sum_word32 = 0; - FOR (i = 9; i >= 0; i--) + for (i = 9; i >= 0; i--) { - sum_word16 = add(sum_word16, st->plcInfo.TCX_Tonality[i]); + sum_word32 += st->plcInfo.TCX_Tonality[i]; } - if(sub(sum_word16, 6) >= 0 ) + if (sum_word32 >= 6) { st->plcInfo.concealment_method = TCX_TONAL; - move16(); } } - if(st->tonal_mdct_plc_active) + if (st->tonal_mdct_plc_active) { st->plcInfo.concealment_method = TCX_TONAL; - move16(); } } - if (sub(L_frameTCX, st->L_frameTCX) > 0) + if (L_frameTCX > st->L_frameTCX ) { st->plcInfo.concealment_method = TCX_TONAL; - move16(); } temp_concealment_method = st->plcInfo.concealment_method; - move16(); - if (0 == sub(st->core_fx, TCX_10_CORE)) + if (st->core == TCX_10_CORE) { temp_concealment_method = TCX_TONAL; - move16(); } } + /* get the starting location of the subframe in the frame */ - IF (0 ==sub(st->core_fx, TCX_10_CORE)) + if (st->core == TCX_10_CORE) { - st->plcInfo.subframe_fx =extract_l( L_mult0(frame_cnt,L_frameTCX_glob)); + st->plcInfo.subframe = frame_cnt*L_frameTCX_glob; } } /* PLC: [TCX: Tonal Concealment] */ /* PLC: [TCX: Fade-out] * PLC: Fade out to white noise */ - - IF (bfi == 0) + if( !bfi ) { - TonalMDCTConceal_SaveFreqSignal(&st->tonalMDCTconceal, - x, x_e, - L_frameTCX, - L_frame, - gainlpc2, gainlpc2_e, - gain_tcx_e); + TonalMDCTConceal_SaveFreqSignal( &st->tonalMDCTconceal, x, L_frameTCX, L_frame, gainlpc2 ); } - ELSE + else { - test(); - IF( !st->enablePlcWaveadjust || sub(temp_concealment_method, TCX_TONAL) == 0 ) + if( !st->enablePlcWaveadjust || (temp_concealment_method == TCX_TONAL)) { - Word16 f, tmp; - /* set f to 1 to not fade out */ /* set f to 0 to immediately switch to white noise */ - f = st->cummulative_damping_tcx; - move16(); - if (0 != st->tcxonly) + float f; + float noiseTiltFactor; + + if (st->tcxonly) { - f = 32767/*1.0f Q15*/; - move16(); + f = 1.0f; + } + else + { + f = st->cummulative_damping_tcx; } - test(); - test(); - IF ( (frame_cnt == 0) && (sub(L_frameTCX, shr(st->L_frameTCX, 1)) == 0) - && (st->tcxonly) && (!st->tonal_mdct_plc_active) && (sub(st->nbLostCmpt, 1) == 0) - && (tcx_cfg->tcx_last_overlap_mode != FULL_OVERLAP) - && (tcx_cfg->tcx_curr_overlap_mode != FULL_OVERLAP) ) + if( (frame_cnt == 0) && (L_frameTCX == st->L_frameTCX >> 1) + && (st->tcxonly) && (!st->tonal_mdct_plc_active) && (st->nbLostCmpt == 1) + && (tcx_cfg->tcx_last_overlap_mode != FULL_OVERLAP) + && (tcx_cfg->tcx_curr_overlap_mode != FULL_OVERLAP) ) { - Word16 exp1, exp2; - Word32 E_2ndlast, E_last; + float E_2ndlast, E_last; - E_2ndlast = CalculateAbsEnergy(1, &(st->tonalMDCTconceal.lastBlockData.spectralData[0]), infoIGFStartLine, &exp2); - E_last = CalculateAbsEnergy(1, &(st->tonalMDCTconceal.lastBlockData.spectralData[1]), infoIGFStartLine, &exp1); - - BASOP_Util_Divide_MantExp(extract_h(E_2ndlast), exp2, extract_h(E_last), exp1, &tmp1, &tmp2); - - tmp1 = shr(tmp1,2); /*Q13*/ - tmp1 = shl(tmp1,tmp2); - test(); - test(); - /* replace higher energy TCX5 frame by lower one to avoid energy fluctuation */ - IF(sub(tmp1,16384 /*2 in Q13*/) > 0) + E_2ndlast = E_last = EPSILON; + for( i=0; itonalMDCTconceal.lastBlockData.spectralData[i] *st->tonalMDCTconceal.lastBlockData.spectralData[i]; + E_last += st->tonalMDCTconceal.lastBlockData.spectralData[i+1]*st->tonalMDCTconceal.lastBlockData.spectralData[i+1]; + } + tmp2 = E_2ndlast/E_last; + + /* replace higher energy TCX5 frame by lower one to avoid energy fluctuation */ + if( tmp2 > 2 ) + { + for( i=0; itonalMDCTconceal.lastBlockData.spectralData[i] = st->tonalMDCTconceal.lastBlockData.spectralData[i+1]; } } - ELSE IF(sub(tmp1,4096/*0.5 in Q13*/) < 0) + else if( tmp2 < 0.5 ) { - FOR(i=0; itonalMDCTconceal.lastBlockData.spectralData[i+1] = st->tonalMDCTconceal.lastBlockData.spectralData[i]; } } } - noiseTiltFactor = 32767/*1.0f Q15*/; - move16(); + noiseTiltFactor = 1.0f; - tmp = 0; - move16(); - test(); - IF( sub(st->bits_frame, 256) >= 0 && st->rf_flag == 0) - { - tmp = 1; - move16(); - } + tcxGetNoiseFillingTilt( A, L_frame, (st->bits_frame >= 256 && !st->rf_flag), &noiseTiltFactor ); - tcxGetNoiseFillingTilt( A, M, L_frame, tmp, &noiseTiltFactor ); - - TonalMDCTConceal_InsertNoise(&st->tonalMDCTconceal, - x, - &x_e, - st->tonal_mdct_plc_active, - &st->seed_tcx_plc, - noiseTiltFactor, - f, - infoIGFStartLine - ); + TonalMDCTConceal_InsertNoise( &st->tonalMDCTconceal, x, st->tonal_mdct_plc_active, + &st->seed_tcx_plc, noiseTiltFactor, f, infoIGFStartLine ); } } - - IF (sub(L_spec, L_frame) < 0) + if( L_spec < L_frame ) { - set32_fx(x+L_spec, 0, sub(L_frame,L_spec)); + set_zero( x+L_spec, L_frame-L_spec ); } - ELSE IF (sub(L_spec, L_frameTCX) > 0) + else if( L_spec > L_frameTCX ) { - set32_fx(x+L_frameTCX, 0, sub(L_spec,L_frameTCX)); + set_zero( x+L_frameTCX, L_spec-L_frameTCX ); } - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - IF ( bfi && (!st->enablePlcWaveadjust || sub(temp_concealment_method, TCX_TONAL) == 0) - && st->igf && (frame_cnt == 0) && (sub(L_frameTCX, shr(st->L_frameTCX, 1)) == 0) - && (st->tcxonly) && (!st->tonal_mdct_plc_active) && (sub(st->nbLostCmpt, 1) == 0) - && (tcx_cfg->tcx_last_overlap_mode != FULL_OVERLAP) - && (tcx_cfg->tcx_curr_overlap_mode != FULL_OVERLAP) ) + if( bfi && (!st->enablePlcWaveadjust || (temp_concealment_method == TCX_TONAL)) + && st->igf && (frame_cnt == 0) && (L_frameTCX == st->L_frameTCX >> 1) + && (st->tcxonly) && (!st->tonal_mdct_plc_active) && (st->nbLostCmpt == 1) + && (tcx_cfg->tcx_last_overlap_mode != FULL_OVERLAP) + && (tcx_cfg->tcx_curr_overlap_mode != FULL_OVERLAP) ) { - IGFDecCopyLPCFlatSpectrum( - &st->hIGFDec, - x, - x_e, - IGF_GRID_LB_SHORT - ); - Copy(st->hIGFDec.igfData.igf_curr_subframe[0][0], st->hIGFDec.igfData.igf_curr_subframe[1][0], IGF_MAX_SFB); + IGFDecCopyLPCFlatSpectrum( &st->hIGFDec, x, IGF_GRID_LB_SHORT ); + mvi2i(st->hIGFDec.igfData.igf_curr_subframe[0][0], st->hIGFDec.igfData.igf_curr_subframe[1][0], IGF_MAX_SFB); } /*-----------------------------------------------------------* * Noise shaping in frequency domain (1/Wz) * *-----------------------------------------------------------*/ - test(); - IF(st->igf && ! bfi) - { - test(); - IF ( (sub(L_frame, shr(st->L_frame_fx, 1)) == 0) && (st->tcxonly)) - { - IGFDecCopyLPCFlatSpectrum( - &st->hIGFDec, - x, - x_e, - IGF_GRID_LB_SHORT - ); - } - ELSE - { - IF (sub(st->last_core_fx, ACELP_CORE) == 0) - { - IGFDecCopyLPCFlatSpectrum( - &st->hIGFDec, - x, - x_e, - IGF_GRID_LB_TRAN - ); - } - ELSE - { - IGFDecCopyLPCFlatSpectrum( - &st->hIGFDec, - x, - x_e, - IGF_GRID_LB_NORM - ); - } + if( st->igf && ! bfi ) + { + if ((L_frame == st->L_frame >> 1) && (st->tcxonly)) + { + IGFDecCopyLPCFlatSpectrum( &st->hIGFDec, x, IGF_GRID_LB_SHORT ); + } + else + { + IGFDecCopyLPCFlatSpectrum( &st->hIGFDec, x, (st->last_core == ACELP_CORE)?IGF_GRID_LB_TRAN:IGF_GRID_LB_NORM ); } } - /* LPC gains already available */ - test(); - test(); - IF(!st->enablePlcWaveadjust || !bfi || (sub(temp_concealment_method, TCX_TONAL) == 0)) + + if( !st->enablePlcWaveadjust || !bfi || (temp_concealment_method == TCX_TONAL) ) { - x_e = add(x_e, gain_tcx_e); - mdct_shaping(x, L_frame, gainlpc2, gainlpc2_e); - IF ( bfi == 0 ) + mdct_noiseShaping( x, L_frame, gainlpc2 ); + + if( !bfi ) { - FOR (i = L_frame; i < L_spec; i++) - { - x[i] = L_shl(Mpy_32_16_1(x[i], gainlpc2[FDNS_NPTS-1]), gainlpc2_e[FDNS_NPTS-1]); - move32(); - } + v_multc( x+L_frame, gainlpc2[FDNS_NPTS-1], x+L_frame, L_spec-L_frame ); } - set32_fx(x+L_spec, 0, sub(L_frameTCX, L_spec)); - test(); - test(); - IF (( bfi != 0) && ( !st->enablePlcWaveadjust || sub(temp_concealment_method, TCX_TONAL) == 0 )) - { - scale_sig32(x+infoIGFStartLine, sub(L_spec, infoIGFStartLine), negate(gain_tcx_e)); - } + set_zero( x+L_spec, L_frameTCX-L_spec ); } /* PLC: [TCX: Tonal Concealment] */ - IF( bfi && st->tonal_mdct_plc_active ) + if( bfi && st->tonal_mdct_plc_active ) { - TonalMDCTConceal_Apply(&st->tonalMDCTconceal, x, &x_e); + TonalMDCTConceal_Apply( &st->tonalMDCTconceal, x ); } - tmp32 = L_deposit_h(0); - if(st->tcxltp_last_gain_unmodified > 0) - { - tmp32 = L_add(st->old_fpitch, 0); - } - tmp8 = 0; - move16(); - test(); - if(bfi && st->tonal_mdct_plc_active) - { - tmp8 = 1; - move16(); - } - TonalMDCTConceal_UpdateState(&st->tonalMDCTconceal, - L_frameTCX, - tmp32, - bfi, - tmp8); + TonalMDCTConceal_UpdateState( &st->tonalMDCTconceal, L_frameTCX, (st->tcxltp_last_gain_unmodified > 0) ? st->old_fpitch : 0, + bfi, bfi && st->tonal_mdct_plc_active ); - IF (st->enablePlcWaveadjust) + + if( st->enablePlcWaveadjust ) { - Word16 core; - core = st->core_fx; - move16(); + int core; + core = st->core; + /* spectrum concealment */ - IF (bfi && (sub(temp_concealment_method, TCX_NONTONAL) == 0)) + if (bfi && temp_concealment_method == TCX_NONTONAL) { - /* x_e =31-x_scale; */ - concealment_decode_fix(core, x, &x_e, &st->plcInfo); + concealment_decode( core, x, &st->plcInfo ); } + /* update spectrum buffer, tonality flag, etc. */ - concealment_update_x(bfi, core, st->tonality_flag, x, &x_e, &st->plcInfo); + concealment_update( bfi, core, st->tonality_flag, x, &st->plcInfo ); } /*-----------------------------------------------------------* - * IGF * - *-----------------------------------------------------------*/ - test(); - test(); - IF (st->igf && !((sub(L_frame, shr(st->L_frame_fx, 1)) == 0) && (st->tcxonly))) + * IGF * + *-----------------------------------------------------------*/ + + if (st->igf && !((L_frame == st->L_frame >> 1) && (st->tcxonly))) { - Word16 igfGridIdx; + /* copy low spectrum to IGF des buffer */ + st->hIGFDec.igfData.igfInfo.nfSeed = (short)(nf_seed * 31821L + 13849L); - test(); - test(); - IF ((sub(st->last_core_fx, ACELP_CORE) == 0) || (left_rect && bfi)) - { - /* packet loss after first TCX must be handled like transition frame */ - igfGridIdx = IGF_GRID_LB_TRAN; - } - ELSE - { - igfGridIdx = IGF_GRID_LB_NORM; - } + IGFDecApplyMono( &st->hIGFDec, x, (st->last_core == ACELP_CORE || (left_rect && bfi))?IGF_GRID_LB_TRAN:IGF_GRID_LB_NORM, bfi ); - st->hIGFDec.igfData.igfInfo.nfSeed = extract_l(L_mac0(13849L, nf_seed, 31821)); - - IGFDecApplyMono( - &st->hIGFDec, - x, - &x_e, - igfGridIdx, - bfi - ); - } - test(); - test(); - IF (st->igf && ((sub(L_frame, shr(st->L_frame_fx, 1)) == 0) && (st->tcxonly))) - { - st->hIGFDec.igfData.igfInfo.nfSeed = extract_l(L_mac0(13849L, nf_seed, 31821)); - IGFDecApplyMono( - &st->hIGFDec, - x, - &x_e, - IGF_GRID_LB_SHORT, - bfi - ); + /* IGF Decoder - All */ } - index = tcx_cfg->tcx_last_overlap_mode; /* backup last TCX overlap mode */ move16(); - - /* normalize spectrum to minimize IMDCT noise */ - tmp1 = s_max(s_max(L_frame,L_frameTCX), L_spec); - s = s_max(0, sub(getScaleFactor32(x, tmp1), 4)); /* Keep 4 bits headroom for TNS */ - Scale_sig32(x, tmp1, s); - x_e = sub(x_e, s); - - IF(st->igf) + if (st->igf && ((L_frame == st->L_frame >> 1) && (st->tcxonly))) { - test(); - IF(st->hIGFDec.flatteningTrigger != 0 && fUseTns == 0) + /* copy low spectrum to IGF des buffer */ + st->hIGFDec.igfData.igfInfo.nfSeed = (short)(nf_seed * 31821L + 13849L); + + IGFDecApplyMono( &st->hIGFDec, x, IGF_GRID_LB_SHORT, bfi ); + + /* IGF Decoder - All */ + } + + index = tcx_cfg->tcx_last_overlap_mode; /* backup last TCX overlap mode */ + + if( st->igf ) + { + int proc = st->hIGFDec.flatteningTrigger; + if( proc && fUseTns != 0 ) { - Word16 startLine = st->hIGFDec.infoIGFStartLine; - Word16 endLine = st->hIGFDec.infoIGFStopLine; - Word32 x_itf[N_MAX_TCX-IGF_START_MN]; - Word16 j; + proc = 0; + } - const Word16* chk_sparse = st->hIGFDec.flag_sparse; - const Word32* virtualSpec = st->hIGFDec.virtualSpec; + if( proc ) + { + short int startLine = st->hIGFDec.infoIGFStartLine; + short int endLine = st->hIGFDec.infoIGFStopLine; + float x_itf[N_MAX_TCX-IGF_START_MN]; + int j; - const Word16 maxOrder = 8; - Word16 curr_order = 0; /* not counted */ - Word16 A_itf[ITF_MAX_FILTER_ORDER+1]; - Word16 Q_A_itf; - Word16 predictionGain = 0; /* not counted */ + const int* chk_sparse = st->hIGFDec.flag_sparse; + const float* virtualSpec = st->hIGFDec.virtualSpec; - move16(); - move16(); + const int maxOrder = 8; + int curr_order = 0; + float A_itf[ITF_MAX_FILTER_ORDER+1]; + float predictionGain = 0; - move16(); - - FOR (j = startLine; j < endLine; j++) + for (j = startLine; j < endLine; j++) { - IF (sub(chk_sparse[j-IGF_START_MN], 2) == 0) + if( chk_sparse[j-IGF_START_MN] == 2 ) { x_itf[j-IGF_START_MN] = x[j]; - move32(); x[j] = virtualSpec[j-IGF_START_MN]; - move32(); } } - ITF_Detect_fx(x+IGF_START_MN, startLine, endLine, maxOrder, A_itf, &Q_A_itf, &predictionGain, &curr_order, shl(x_e, 1)); - s = getScaleFactor32(&x[startLine], sub(endLine, startLine)); - s = sub(s, 2); - FOR(j = startLine; j < endLine; j++) - { - x[j] = L_shl(x[j], s); - move32(); - } - ITF_Apply_fx(x, startLine, endLine, A_itf, Q_A_itf, curr_order); + ITF_Detect( x+IGF_START_MN, startLine, endLine, maxOrder, A_itf, &predictionGain, &curr_order ); - FOR(j = startLine; j < endLine; j++) - { - x[j] = L_shr(x[j], s); - move32(); - } + ITF_Apply(x, startLine, endLine, A_itf, curr_order); - FOR (j = startLine; j < endLine; j++) + for (j = startLine; j < endLine; j++) { - if (sub(chk_sparse[j-IGF_START_MN],2) == 0) + if( chk_sparse[j-IGF_START_MN] == 2 ) { x[j] = x_itf[j-IGF_START_MN]; - move32(); } } } + else + { + + } } - test(); - IF ((sub(L_frame, shr(st->L_frame_fx, 1)) == 0) && (st->tcxonly != 0)) + if( (L_frame == st->L_frame >> 1) && st->tcxonly ) { - Word16 L = L_frameTCX; - move16(); - - test(); - test(); - test(); - if ((tcx_cfg->fIsTNSAllowed != 0 && fUseTns != 0 && bfi == 0) || (sub(L_spec, L_frameTCX) > 0)) + int L = L_frameTCX; + if( (tcx_cfg->fIsTNSAllowed && fUseTns != 0 && bfi!= 1) || (L_spec > L_frameTCX) ) { L = L_spec; - move16(); } - - tcxInvertWindowGrouping(tcx_cfg, - xn_buf32, - x, - L, - fUseTns, - st->last_core_fx, - index, - frame_cnt, - bfi - ); + tcxInvertWindowGrouping( tcx_cfg, xn_buf, x, L, fUseTns, st->last_core, index, frame_cnt, bfi ); } - /*-----------------------------------------------------------* * Temporal Noise Shaping Synthesis * *-----------------------------------------------------------*/ - - test(); - test(); - IF ((tcx_cfg->fIsTNSAllowed != 0) && (fUseTns != 0) && bfi == 0 ) + if( tcx_cfg->fIsTNSAllowed && fUseTns != 0 && bfi!= 1 ) { /* Apply TNS to get the reconstructed signal */ - test(); - test(); - SetTnsConfig(tcx_cfg, L_frame_glob == st->L_frame_fx, (st->last_core_fx == ACELP_CORE) && (frame_cnt == 0)); + + SetTnsConfig(tcx_cfg, L_frame_glob == st->L_frame, (st->last_core == ACELP_CORE) && (frame_cnt == 0)); ApplyTnsFilter(tcx_cfg->pCurrentTnsConfig, &tnsData, x, 0); - test(); - IF ((sub(L_frame, shr(st->L_frame_fx, 1)) == 0) && (st->tcxonly != 0)) + if ((L_frame == st->L_frame >> 1) && (st->tcxonly)) { - - test(); - test(); - test(); - IF ((tcx_cfg->tcx_last_overlap_mode != FULL_OVERLAP) || - ((tcx_cfg->tcx_curr_overlap_mode == FULL_OVERLAP) && (frame_cnt == 0) && (index == 0)) - ) + if ((tcx_cfg->tcx_last_overlap_mode != FULL_OVERLAP) || + ((tcx_cfg->tcx_curr_overlap_mode == FULL_OVERLAP) && (frame_cnt == 0) && (index == 0)) ) { - tmp1 = shr(tcx_cfg->tnsConfig[0][0].iFilterBorders[0], 1); + const int L_win = tcx_cfg->tnsConfig[0][0].iFilterBorders[0] >> 1; /* undo rearrangement of LF sub-window lines for TNS synthesis filtering */ - IF (s_max(L_frameTCX, L_spec) > tcx_cfg->tnsConfig[0][0].iFilterBorders[0]) + if (L_frameTCX > 2*L_win) { - tmp2 = shr(s_max(L_frameTCX, L_spec), 1); - Copy32(x+tmp1+8, x+tmp2+8, sub(tmp1, 8)); - Copy32(x+8, x+tmp2, 8); - Copy32(x+16, x+8, sub(tmp1, 8)); - set32_fx(x+tmp1, 0, sub(tmp2, tmp1)); - set32_fx(x+tmp2+tmp1, 0, sub(tmp2, tmp1)); + const int L_win2 = L_frameTCX >> 1; + mvr2r( x + L_win + 8, x + L_win2 + 8, L_win - 8 ); + mvr2r( x + 8, x + L_win2, 8 ); + mvr2r( x + 16, x + 8, L_win - 8 ); + set_zero( x + L_win, L_win2 - L_win ); + set_zero( x + L_win2 + L_win, L_win2 - L_win ); } - ELSE + else { - Copy32(x+8, xn_buf32, 8); - Copy32(x+16, x+8, sub(tmp1,8)); - Copy32(xn_buf32, x+tmp1, 8); + mvr2r(x+8, xn_buf, L_win ); + mvr2r( xn_buf, x+L_win, 8 ); + mvr2r( xn_buf+8, x+8, L_win-8 ); } } @@ -1273,466 +793,288 @@ void decoder_tcx( /*-----------------------------------------------------------* + * Prepare OLA buffer after waveadjustment. * * Compute inverse MDCT of x[]. * *-----------------------------------------------------------*/ + mvr2r( x, xn_bufFB, max(L_spec, max(L_frame, L_frameTCX)) ); - Copy32(x, xn_buf32, s_max(s_max(L_frame,L_frameTCX), L_spec)); - - IF(st->igf != 0) + if( st->igf ) { - set32_fx( xn_buf32+st->hIGFDec.infoIGFStartLine, 0, sub(L_frameTCX, st->hIGFDec.infoIGFStartLine) ); + set_zero(xn_bufFB+st->hIGFDec.infoIGFStartLine, L_frameTCX-st->hIGFDec.infoIGFStartLine); } - IMDCT(xn_buf32, x_e, - st->syn_Overl, - st->syn_Overl_TDAC, - xn_buf, - tcx_cfg->tcx_aldo_window_1, - tcx_cfg->tcx_aldo_window_1_trunc, - tcx_cfg->tcx_aldo_window_2, - st->tcx_cfg.tcx_mdct_window_half, - tcx_cfg->tcx_mdct_window_minimum, - st->tcx_cfg.tcx_mdct_window_trans, - st->tcx_cfg.tcx_mdct_window_half_length, - tcx_cfg->tcx_mdct_window_min_length, - index, - left_rect, - tcx_offset, - overlap, - L_frame, - L_frameTCX, - shr(s_max(L_frameTCX, L_spec), 1), - L_frame_glob, - frame_cnt, - bfi, - st->old_out_LB_fx, - &st->Q_old_wtda_LB, - st, - 0, - acelp_zir); + + IMDCT( xn_bufFB, + st->syn_Overl, + st->syn_Overl_TDAC, + xn_buf, + tcx_cfg->tcx_aldo_window_1_trunc, + tcx_cfg->tcx_aldo_window_2, + tcx_cfg->tcx_mdct_window_half, + tcx_cfg->tcx_mdct_window_minimum, + tcx_cfg->tcx_mdct_window_trans, + tcx_cfg->tcx_mdct_window_half_length, + tcx_cfg->tcx_mdct_window_min_length, + index, + left_rect, + tcx_offset, + overlap, + L_frame, + L_frameTCX, + max(L_frameTCX, L_spec) >> 1, + L_frame_glob, + frame_cnt, + bfi, + st->old_outLB, + 0, + st, + 0, + acelp_zir ); /* Generate additional comfort noise to mask potential coding artefacts */ - IF ( st->flag_cna != 0 ) + if( st->flag_cna) { - generate_masking_noise_mdct (x, - &x_e, - st->hFdCngDec_fx->hFdCngCom, - s_max(s_max(L_frame,L_frameTCX), L_spec) - ); + generate_masking_noise_mdct(x, st->hFdCngDec->hFdCngCom); } - IMDCT(x, x_e, - st->syn_OverlFB, - st->syn_Overl_TDACFB, - xn_bufFB, - tcx_cfg->tcx_aldo_window_1_FB, - tcx_cfg->tcx_aldo_window_1_FB_trunc, - tcx_cfg->tcx_aldo_window_2_FB, - tcx_cfg->tcx_mdct_window_halfFB, - tcx_cfg->tcx_mdct_window_minimumFB, - tcx_cfg->tcx_mdct_window_transFB, - tcx_cfg->tcx_mdct_window_half_lengthFB, - tcx_cfg->tcx_mdct_window_min_lengthFB, - index, - left_rect, - tcx_offsetFB, - overlapFB, - L_frameTCX, - L_frameTCX, - shr(s_max(L_frameTCX, L_spec), 1), - L_frameTCX_glob, - frame_cnt, - bfi, - st->old_out_fx, - &st->Q_old_wtda, - st, - div_l(L_mult(FSCALE_DENOM, L_frameTCX_glob), L_frame_glob), - acelp_zir - ); - - - + IMDCT( x, + st->syn_OverlFB, + st->syn_Overl_TDACFB, + xn_bufFB, + tcx_cfg->tcx_aldo_window_1_FB_trunc, + tcx_cfg->tcx_aldo_window_2_FB, + tcx_cfg->tcx_mdct_window_halfFB, + tcx_cfg->tcx_mdct_window_minimumFB, + tcx_cfg->tcx_mdct_window_transFB, + tcx_cfg->tcx_mdct_window_half_lengthFB, + tcx_cfg->tcx_mdct_window_min_lengthFB, + index, + left_rect, + tcx_offsetFB, + overlapFB, + L_frameTCX, + L_frameTCX, + max(L_frameTCX, L_spec) >> 1, + L_frameTCX_glob, + frame_cnt, + bfi, + st->old_out, + 1, + st, + FSCALE_DENOM * L_frameTCX_glob / L_frame_glob, + acelp_zir ); /* PLC: [TCX: Tonal Concealment] */ - - IF (!bfi) + if (!bfi) { - st->second_last_tns_active = st->last_tns_active; - st->last_tns_active = 0; - move16(); - test(); - if ( tcx_cfg->fIsTNSAllowed && fUseTns) - { - st->last_tns_active = 1; - move16(); - } + st->second_last_tns_active = st->last_tns_active; + st->last_tns_active = tcx_cfg->fIsTNSAllowed & fUseTns; st->tcxltp_third_last_pitch = st->tcxltp_second_last_pitch; - move32(); st->tcxltp_second_last_pitch = st->old_fpitch; - move32(); - st->old_fpitch = L_add(L_deposit_h(st->tcxltp_pitch_int), L_mult( st->tcxltp_pitch_fr, div_s(1,st->pit_res_max) /*Q16*/)); - st->old_fpitchFB = Mpy_32_16_1(st->old_fpitch/*Q16*/, mult_r(L_frameTCX/*Q0*/,getInvFrameLen(L_frame)/*Q21*/)/*Q6*/)/*Q7*/; - st->old_fpitchFB = L_shr(st->old_fpitchFB,7-16);/*->Q16*/ + st->old_fpitch = st->tcxltp_pitch_int + st->tcxltp_pitch_fr/(float)st->pit_res_max; + st->old_fpitchFB = st->old_fpitch * (float)L_frameTCX / (float)L_frame; } - /* Update old_syn_overl */ - IF (st->tcx_cfg.last_aldo == 0) + if (!tcx_cfg->last_aldo) { - Copy(xn_buf+L_frame, st->syn_Overl, overlap); - Copy(xn_bufFB+L_frameTCX, st->syn_OverlFB, overlapFB); + mvr2r(xn_buf+L_frame, st->syn_Overl, overlap); + mvr2r(xn_bufFB+L_frameTCX, st->syn_OverlFB, overlapFB); } /* Output */ - Copy(xn_buf+shr(overlap,1)-tcx_offset, synth, L_frame_glob); - Copy(xn_bufFB+shr(overlapFB,1)-tcx_offsetFB, synthFB, L_frameTCX_glob); + mvr2r( xn_buf+(overlap>>1)-tcx_offset, synth, L_frame_glob ); + mvr2r( xn_bufFB+(overlapFB>>1)-tcx_offsetFB, synthFB, L_frameTCX_glob ); + return; } +/*-------------------------------------------------------------------* + * decoder_tcx_post() + * + * + *-------------------------------------------------------------------*/ -void decoder_tcx_post(Decoder_State_fx *st_fx, - Word16 *synth, - Word16 *synthFB, - Word16 *A, - Word16 bfi - ) +void decoder_tcx_post( + Decoder_State *st, + float *synth, + float *synthFB, + float *A, + int bfi +) { - Word16 i; - Word16 level_syn; - Word16 level_syn_e; - Word32 step; - Word16 gainCNG,gainCNG_e; - Word16 xn_buf[L_FRAME_MAX]; - Word16 tmp1, tmp2, s; - Word32 tmp32; - Word32 tmp32_1, tmp32_2; + int i; + float level_syn, gainCNG = 0.0f, step; + float xn_buf[L_FRAME_MAX]; /* TCX output */ - Copy( synth, xn_buf, st_fx->L_frame_fx ); + mvr2r( synth, xn_buf, st->L_frame ); /* first TCX frame after ACELP; overwrite ltp initialization done during acelp PLC */ - test(); - test(); - if (!st_fx->bfi_fx && st_fx->prev_bfi_fx && sub(st_fx->last_core_fx,ACELP_CORE) == 0) + if( !bfi && st->prev_bfi && !st->last_core ) { - st_fx->tcxltp_last_gain_unmodified = 0; - move16(); + st->tcxltp_last_gain_unmodified = 0.0f; } - IF (bfi != 0 && st_fx->use_partial_copy == 0) + + if (bfi && !st->use_partial_copy) { - test(); /* run lpc gain compensation not for waveform adjustment */ - IF ( 0 == st_fx->enablePlcWaveadjust || sub(st_fx->plcInfo.concealment_method,TCX_TONAL) == 0 ) + if (!st->enablePlcWaveadjust || st->plcInfo.concealment_method == TCX_TONAL ) { - UWord32 dmy; - tmp32_1 /*gainHelperFB*/ = L_shl_r(L_deposit_h(st_fx->gainHelper) ,sub(st_fx->gainHelper_e, 31-28));/*Q28*/ - tmp32_2 /*stepCompensateFB*/= L_shl_r(L_deposit_h(st_fx->stepCompensate),sub(st_fx->stepCompensate_e,31-28));/*Q28*/ + float gainHelperFB = st->gainHelper; + float stepCompensateFB = st->stepCompensate * st->L_frame / st->L_frameTCX; - Mpy_32_32_ss(tmp32_2/*Q28*/, - L_shl(L_mult0(st_fx->L_frame_fx, - getInvFrameLen(st_fx->L_frameTCX)/*Q21*/)/*Q21*/, - 8)/*Q29*/, - &tmp32_2, - &dmy ); /*Q26*/ - - tmp32_2 = L_shl(tmp32_2,3-1); /*Q28*/ - - FOR( i=0; i < st_fx->L_frameTCX; i++ ) + for( i=0; i < st->L_frameTCX; i++ ) { - tmp32 = L_shl(tmp32_1/*Q28*/,-(28-15)); /*16Q15*/ - synthFB[i] = round_fx(L_shl(Mpy_32_16_1(tmp32,synthFB[i]), 16)); - move16(); - tmp32_1 = L_sub(tmp32_1 , tmp32_2); + synthFB[i] *= gainHelperFB; + gainHelperFB -= stepCompensateFB; } } - tmp32_1 /*gainHelper*/ = L_shl_r(L_deposit_h(st_fx->gainHelper) ,sub(st_fx->gainHelper_e, 31-28));/*Q28*/ - tmp32_2 /*stepCompensate*/= L_shl_r(L_deposit_h(st_fx->stepCompensate),sub(st_fx->stepCompensate_e,31-28));/*Q28*/ - FOR( i=0; i < st_fx->L_frame_fx; i++ ) + + for( i=0; i < st->L_frame; i++ ) { - tmp32 = L_shl(tmp32_1/*Q28*/,-(28-15)); /*16Q15*/ - xn_buf[i] = extract_l(Mpy_32_16_1(tmp32,xn_buf[i])); - move16(); - tmp32_1 = L_sub(tmp32_1 , tmp32_2); + xn_buf[i] *= st->gainHelper; + st->gainHelper -= st->stepCompensate; } } /* PLC: [TCX: Fade-out] * PLC: estimate and update CNG energy */ + level_syn = (float)sqrt(( dotp(synthFB, synthFB, st->L_frameTCX)) / st->L_frameTCX); - /* level_syn = (float)sqrt(( dot_product(synthFB, synthFB, L_frame)) / L_frame ); */ - s = sub(getScaleFactor16(synthFB, st_fx->L_frameTCX), 4); - tmp32 = L_deposit_l(0); - FOR (i = 0; i < st_fx->L_frameTCX; i++) - { - tmp1 = shl(synthFB[i], s); - tmp32 = L_mac0(tmp32, tmp1, tmp1); - } - tmp32 = Mpy_32_16_1(tmp32, getInvFrameLen(st_fx->L_frameTCX)); - tmp2 = norm_l(tmp32); - tmp1 = round_fx(L_shl(tmp32, tmp2)); - s = sub(sub(sub(1, shl(s, 1)), 6/*table lookup for inverse framelength*/), tmp2); - tmp1 = Sqrt16(tmp1, &s); - move16(); - level_syn = tmp1; /*Q0*/ /* PLC: [TCX: Fade-out] - * PLC: estimate and update CNG energy */ - - level_syn_e = add(s,15); - test(); - test(); - IF (bfi == 0 && st_fx->tcxonly != 0 && sub(st_fx->clas_dec , UNVOICED_CLAS) == 0) + * PLC: update or retrieve the background level */ + if( bfi == 0 && st->tcxonly && st->clas_dec == UNVOICED_CLAS ) { - - Word16 Qnew_levelBackgroundTrace; - Qnew_levelBackgroundTrace = 0; - move16(); - minimumStatistics(st_fx->conNoiseLevelMemory, /*Q15*/ - &st_fx->conNoiseLevelIndex, /*Q0 */ - &st_fx->conCurrLevelIndex, /*Q0 */ - &st_fx->conCngLevelBackgroundTrace, /*Q15*/ - &st_fx->conLastFrameLevel, /*Q15*/ - level_syn, /*Q15*/ - st_fx->conNoiseLevelMemory_e, - st_fx->conCngLevelBackgroundTrace_e, - &Qnew_levelBackgroundTrace, - &st_fx->conLastFrameLevel_e, - level_syn_e /*scaling of level_syn*/ - ); - - /*note: All parameters being different from Q0 have to have the same Q-format*/ - - st_fx->conCngLevelBackgroundTrace_e = Qnew_levelBackgroundTrace; - move16(); + minimumStatistics( st->NoiseLevelMemory_bfi, &st->NoiseLevelIndex_bfi, &st->CurrLevelIndex_bfi, &st->CngLevelBackgroundTrace_bfi, + &st->LastFrameLevel_bfi, level_syn, PLC_MIN_CNG_LEV, PLC_MIN_STAT_BUFF_SIZE); } /* PLC: [TCX: Fade-out] * PLC: fade-out in time domain */ - IF (bfi != 0) + if( bfi ) { - Word32 conceal_eof_gain32; - Word32 conceal_eof_gainFB; - move16(); - move16(); - gainCNG = 1; - gainCNG_e = 14+15+6; /*gainCNG is 2`097`152 - should be enough in case tracinglevel =~0 */ - IF (st_fx->tcxonly != 0) - { - /*gainCNG = st_fx->conCngLevelBackgroundTrace/(tracingLevel+0.01f);*/ + float conceal_eof_gainFB; - IF(level_syn != 0) - { - BASOP_Util_Divide_MantExp ( - st_fx->conCngLevelBackgroundTrace, - st_fx->conCngLevelBackgroundTrace_e, - level_syn, - level_syn_e, - &gainCNG, - &gainCNG_e); - } - } - ELSE + if( st->tcxonly ) { - /*gainCNG = st_fx->cngTDLevel/(tracingLevel+0.01f);*/ - IF(level_syn != 0) + gainCNG = st->CngLevelBackgroundTrace_bfi/(level_syn+0.01f); + } + else + { + gainCNG = st->cngTDLevel/(level_syn+0.01f); + } + if( st->nbLostCmpt == 1 ) + { + st->conceal_eof_gain = 1.0f; + } + + step = (st->conceal_eof_gain - ( st->conceal_eof_gain * st->damping + gainCNG * (1 - st->damping) )) / st->L_frame; + { + float stepFB = step * st->L_frame / st->L_frameTCX; + conceal_eof_gainFB = st->conceal_eof_gain; + + for( i=0; i < st->L_frameTCX; i++ ) { - BASOP_Util_Divide_MantExp ( - st_fx->cngTDLevel, - st_fx->cngTDLevel_e, - level_syn, - level_syn_e, - &gainCNG, - &gainCNG_e); + synthFB[i] *= conceal_eof_gainFB; + conceal_eof_gainFB -= stepFB; } } - if ((sub(st_fx->nbLostCmpt, 1) == 0)) + for( i=0; i < st->L_frame; i++ ) { - st_fx->conceal_eof_gain = 16384/*1.0f Q14*/; /*Q14*/ move16(); + xn_buf[i] *= st->conceal_eof_gain; + st->conceal_eof_gain -= step; } - /* step = (st_fx->conceal_eof_gain - ( st_fx->conceal_eof_gain * st_fx->damping + gainCNG * (1 - st_fx->damping) )) / st_fx->L_frame_fx; */ - tmp2 = BASOP_Util_Add_MantExp( - mult_r(st_fx->conceal_eof_gain /*Q14*/, - st_fx->damping /*Q14*/), - 15-13/*->Q15*/, - mult_r(gainCNG/*Q15*/,sub(0x4000,st_fx->damping/*Q14*/)) /*Q14*/, - add(gainCNG_e,15-14)/*->Q15*/, - &tmp1); - tmp2 = BASOP_Util_Add_MantExp(st_fx->conceal_eof_gain, 15-14, negate(tmp1), tmp2, &tmp1); - - step = L_shl(L_mult(tmp1, getInvFrameLen(st_fx->L_frame_fx)), sub(tmp2,6/*scaling from table lookup*/ +1/*go to Q30*/)); /*Q30*/ + /* run lpc gain compensation not for waveform adjustment */ + if( (!st->enablePlcWaveadjust || st->plcInfo.concealment_method == TCX_TONAL ) && !st->use_partial_copy ) { - Word32 stepFB; - UWord32 dmy; - conceal_eof_gainFB = L_deposit_h(st_fx->conceal_eof_gain); /*Q30*/ - Mpy_32_32_ss(step,L_shl(L_mult0(st_fx->L_frame_fx, getInvFrameLen(st_fx->L_frameTCX)),8),&stepFB ,&dmy ); - stepFB = L_shl(stepFB,3-1); /*Q30*/ - - FOR( i=0; i < st_fx->L_frameTCX; i++ ) - { - synthFB[i] = round_fx(L_shl(Mpy_32_16_1(conceal_eof_gainFB, synthFB[i]),1)); - move16(); - conceal_eof_gainFB = L_sub(conceal_eof_gainFB, stepFB); - } + st->plcInfo.recovery_gain = conceal_eof_gainFB * st->last_concealed_gain_syn_deemph; } - conceal_eof_gain32 = L_deposit_h(st_fx->conceal_eof_gain); /*Q30*/ - FOR( i=0; i < st_fx->L_frame_fx; i++ ) + else { - xn_buf[i] = round_fx(L_shl(Mpy_32_16_1(conceal_eof_gain32 /*Q30*/, xn_buf[i]),1)); - move16(); - conceal_eof_gain32 = L_sub(conceal_eof_gain32,step); + st->plcInfo.recovery_gain = conceal_eof_gainFB; } - st_fx->conceal_eof_gain = round_fx(conceal_eof_gain32); /*Q14*/ move16(); - /* run lpc gain compensation not for waveform adjustment */ test(); - IF ( 0 == st_fx->enablePlcWaveadjust || sub(st_fx->plcInfo.concealment_method,TCX_TONAL) == 0 ) - { - st_fx->plcInfo.recovery_gain = extract_h(L_shl(Mpy_32_16_1(conceal_eof_gainFB, - st_fx->last_concealed_gain_syn_deemph), - st_fx->last_concealed_gain_syn_deemph_e - ));/*Q30->Q14*/ - } - ELSE - { - st_fx->plcInfo.recovery_gain = extract_h(conceal_eof_gainFB); /*Q14*/ - } - st_fx->plcInfo.step_concealgain_fx = - round_fx(L_shl(L_mult0( - round_fx(step), - round_fx(L_shl(L_mult0(st_fx->L_frame_fx, getInvFrameLen(st_fx->L_frameTCX)),8))),3)); /*Q15*/ + st->plcInfo.step_concealgain = step * st->L_frame / st->L_frameTCX; } + /*-----------------------------------------------------------* * Memory update * *-----------------------------------------------------------*/ - /* Update synth, exc and old_Aq */ - tcx_decoder_memory_update(xn_buf, /*Q0*/ - synth, /*Q0*/ - st_fx->L_frame_fx, - A, - st_fx, - st_fx->syn, /*Q0*/ - 0 - ); - + /* Update synth, exc and old_Aq */ + tcx_decoder_memory_update( xn_buf, synth, st->L_frame, A, st, st->syn ); /* PLC: [TCX: Memory update] */ + st->old_pitch_buf[0] = st->old_pitch_buf[st->nb_subfr]; + st->old_pitch_buf[1] = st->old_pitch_buf[st->nb_subfr+1]; + mvr2r( &st->old_pitch_buf[st->nb_subfr+2], &st->old_pitch_buf[2], st->nb_subfr ); + set_f( &st->old_pitch_buf[st->nb_subfr+2], st->old_fpitch, st->nb_subfr ); + st->bfi_pitch = st->old_fpitch; + st->bfi_pitch_frame = st->L_frame; - st_fx->old_pitch_buf_fx[0] = st_fx->old_pitch_buf_fx[st_fx->nb_subfr]; - move32(); - st_fx->old_pitch_buf_fx[1] = st_fx->old_pitch_buf_fx[st_fx->nb_subfr+1]; - move32(); - Copy32(&st_fx->old_pitch_buf_fx[st_fx->nb_subfr+2], &st_fx->old_pitch_buf_fx[2], st_fx->nb_subfr); - set32_fx(&st_fx->old_pitch_buf_fx[st_fx->nb_subfr+2], st_fx->old_fpitch, st_fx->nb_subfr); - st_fx->bfi_pitch_fx = shl(round_fx(st_fx->old_fpitch),6); - st_fx->bfi_pitch_frame_fx = st_fx->L_frame_fx; - move16(); + st->mem_pitch_gain[2*st->nb_subfr+1] = st->mem_pitch_gain[st->nb_subfr+1]; + st->mem_pitch_gain[2*st->nb_subfr] = st->mem_pitch_gain[st->nb_subfr]; - st_fx->mem_pitch_gain[2*st_fx->nb_subfr+1] = st_fx->mem_pitch_gain[st_fx->nb_subfr+1]; - move16(); - st_fx->mem_pitch_gain[2*st_fx->nb_subfr] = st_fx->mem_pitch_gain[st_fx->nb_subfr]; - move16(); - - FOR (i = 0; i < st_fx->nb_subfr; i++) + for( i = 0; i < st->nb_subfr; i++ ) { - st_fx->mem_pitch_gain[2*st_fx->nb_subfr-1 - i] = st_fx->mem_pitch_gain[st_fx->nb_subfr-1 - i]; - move16(); - st_fx->mem_pitch_gain[st_fx->nb_subfr-1 - i] = st_fx->tcxltp_last_gain_unmodified; - move16(); + st->mem_pitch_gain[2*st->nb_subfr-1 - i] = st->mem_pitch_gain[st->nb_subfr-1 - i]; + st->mem_pitch_gain[st->nb_subfr-1 - i] = st->tcxltp_last_gain_unmodified; } + + return; } +/*-------------------------------------------------------------------* + * IMDCT() + * + * + *-------------------------------------------------------------------*/ -static Word32 CalculateAbsEnergy( /* o : normalized result Q31 */ - const Word32 L_off, /* i : initial sum value Qn */ - const Word16 x[], /* i : x vector Qn */ - const Word16 lg, /* i : vector length, range [0..7FFF] Q0 */ - Word16 * exp /* o : exponent of result in [-32,31] Q0 */ +static void IMDCT( + float *x, + float *old_syn_overl, + float *syn_Overl_TDAC, + float *xn_buf, + float *tcx_aldo_window_1_trunc, + float *tcx_aldo_window_2, + float *tcx_mdct_window_half, + float *tcx_mdct_window_minimum, + float *tcx_mdct_window_trans, + int tcx_mdct_window_half_length, + int tcx_mdct_window_min_length, + int index, + int left_rect, + int tcx_offset, + int overlap, + int L_frame, + int L_frameTCX, + int L_spec_TCX5, + int L_frame_glob, + int frame_cnt, + int bfi, + float *old_out, + short FB_flag, + Decoder_State *st, + int fullbandScale, + float *acelp_zir ) { - Word16 i; - Word32 L_sum, L_c; - /* Clear carry flag and init sum */ - Carry = 0; - L_c = L_add(0,0); - L_sum = L_macNs(L_off,0,0); - if (L_sum > 0) - L_c = L_macNs(L_c,0,0); - if (L_sum < 0) - L_c = L_msuNs(L_c,0,0); + short i, nz, aldo; + TCX_config *tcx_cfg = &st->tcx_cfg; - FOR (i=0; i < lg; i+=2) - { - Carry = 0; - BASOP_SATURATE_WARNING_OFF /*multiplication of -32768 * -32768 throws an overflow, but is not critical*/ - L_sum = L_macNs(L_sum, x[i], x[i]); - BASOP_SATURATE_WARNING_ON - Overflow = 0; /* to avoid useless warning in L_macNs calling L_mult */ - L_c = L_macNs(L_c,0,0); - } - L_sum = norm_llQ31(L_c,L_sum,exp); - return L_sum; -} - - -static void IMDCT(Word32 *x, Word16 x_e, - Word16 *old_syn_overl, - Word16 *syn_Overl_TDAC, - Word16 *xn_buf, - const Word16 *tcx_aldo_window_1, - const PWord16 *tcx_aldo_window_1_trunc, - const PWord16 *tcx_aldo_window_2, - const PWord16 *tcx_mdct_window_half, - const PWord16 *tcx_mdct_window_minimum, - const PWord16 *tcx_mdct_window_trans, - Word16 tcx_mdct_window_half_length, - Word16 tcx_mdct_window_min_length, - Word16 index, - Word16 left_rect, - Word16 tcx_offset, - Word16 overlap, - Word16 L_frame, - Word16 L_frameTCX, - Word16 L_spec_TCX5, - Word16 L_frame_glob, - Word16 frame_cnt, - Word16 bfi, - Word16 *old_out, - Word16 *Q_old_wtda, - Decoder_State_fx *st, - Word16 fullbandScale, - Word16 *acelp_zir) -{ - const TCX_config *tcx_cfg = &st->tcx_cfg; - Word16 tmp_offset; - Word16 tmp1, tmp2, tmp3, *tmpP16; - Word32 tmp32; - Word8 tmp8; - Word16 i; - Word16 nz; - Word16 aldo=0; + aldo = 0; /* number of zero for ALDO windows*/ - tmp32 = L_add(st->sr_core, 0); - if (fullbandScale != 0) - { - tmp32 = L_add(st->output_Fs_fx, 0); - } - nz = NS2SA_fx2(tmp32, N_ZERO_MDCT_NS); + nz = NS2SA(st->output_Fs, N_ZERO_MDCT_NS)*L_frame/L_frameTCX; - tmp_offset = 0; - move16(); - if (tcx_offset < 0) - { - tmp_offset = negate(tcx_offset); - } - - test(); - IF ((sub(L_frameTCX, shr(st->L_frameTCX, 1)) == 0) && (st->tcxonly != 0)) + if( (L_frameTCX == st->L_frameTCX >> 1) && (st->tcxonly) ) { /* Mode decision in PLC @@ -1748,643 +1090,235 @@ static void IMDCT(Word32 *x, Word16 x_e, 3 2 2x TCX-5 2x TCX-5 3 3 2x TCX-5 2x TCX-5 */ - test(); - test(); - test(); - test(); - test(); - test(); - IF ((bfi == 0 && tcx_cfg->tcx_last_overlap_mode != FULL_OVERLAP) || (bfi!=0 && (tcx_cfg->tcx_last_overlap_mode != FULL_OVERLAP) && (tcx_cfg->tcx_curr_overlap_mode != FULL_OVERLAP))) + + if( (!bfi && tcx_cfg->tcx_last_overlap_mode != FULL_OVERLAP) || (bfi && (tcx_cfg->tcx_last_overlap_mode != FULL_OVERLAP) && (tcx_cfg->tcx_curr_overlap_mode != FULL_OVERLAP)) ) { /* minimum or half overlap, two transforms, grouping into one window */ - Word16 win[(L_FRAME_PLUS+L_MDCT_OVLP_MAX)/2]; - Word16 w; - Word16 L_win, L_ola; + float win[(L_FRAME_PLUS+L_MDCT_OVLP_MAX)/2]; + const int L_win = L_frame >> 1; + const int L_ola = (tcx_cfg->tcx_last_overlap_mode == MIN_OVERLAP) ? tcx_mdct_window_min_length : tcx_mdct_window_half_length; + int w; - L_win = shr(L_frame, 1); - L_ola = tcx_mdct_window_half_length; - move16(); - if (sub(tcx_cfg->tcx_last_overlap_mode, MIN_OVERLAP) == 0) + set_f( win, 0, (L_FRAME_PLUS+L_MDCT_OVLP_MAX)/2 ); + set_zero(xn_buf, tcx_offset+(L_ola>>1)); /* zero left end of buffer */ + + for (w = 0; w < 2; w++) { - L_ola = tcx_mdct_window_min_length; - move16(); - } + TCX_MDCT_Inverse(x+w*L_spec_TCX5, win, L_ola, L_win-L_ola, L_ola); - set16_fx(xn_buf, 0, add(tcx_offset,shr(L_ola,1))); /* zero left end of buffer */ - set16_fx(win, 0, (L_FRAME_PLUS+L_MDCT_OVLP_MAX)/2); + tcx_windowing_synthesis_current_frame( win, tcx_aldo_window_2, tcx_mdct_window_half, tcx_mdct_window_minimum, L_ola, tcx_mdct_window_half_length, tcx_mdct_window_min_length, + (w > 0) ? 0 : left_rect, (w > 0) || (w == 0 && index == 2) ? MIN_OVERLAP : tcx_cfg->tcx_last_overlap_mode, + acelp_zir, st->old_syn_Overl, syn_Overl_TDAC, st->old_Aq_12_8, tcx_mdct_window_trans, L_win, tcx_offset<0?-tcx_offset:0, + (w > 0) || (frame_cnt > 0) ? 1 : st->last_core_bfi, (w > 0) || (frame_cnt > 0) ? 0 : st->last_is_cng, fullbandScale ); - FOR (w = 0; w < 2 ; w++) - { - - TCX_MDCT_Inverse(x+L_mult0(w,L_spec_TCX5), sub(x_e,TCX_IMDCT_SCALE+TCX_IMDCT_HEADROOM),win, L_ola, sub(L_win,L_ola), L_ola); - - tmp1 = left_rect; - move16(); - tmp2 = tcx_cfg->tcx_last_overlap_mode; - move16(); - tmp3 = st->last_core_bfi; - move16(); - tmp8 = st->last_is_cng; - move16(); - IF (w > 0) + if( w > 0 ) { - tmp1 = 0; - move16(); - tmp2 = MIN_OVERLAP; - move16(); - tmp3 = 1; - move16(); - tmp8 = (Word8)0; - move16(); - } - test(); - if(w == 0 && sub(index,2) == 0) - { - tmp2 = MIN_OVERLAP; - move16(); - } - IF (frame_cnt>0) - { - tmp3 = 1; - move16(); - tmp8 = (Word8)0; - move16(); + tcx_windowing_synthesis_past_frame( xn_buf+tcx_offset-(L_ola>>1)+w*L_win, tcx_aldo_window_1_trunc, tcx_mdct_window_half, + tcx_mdct_window_minimum, L_ola, tcx_mdct_window_half_length, tcx_mdct_window_min_length, MIN_OVERLAP ); } - tcx_windowing_synthesis_current_frame(win, - tcx_aldo_window_2, - tcx_mdct_window_half, - tcx_mdct_window_minimum, - L_ola, - tcx_mdct_window_half_length, - tcx_mdct_window_min_length, - tmp1, - tmp2, - acelp_zir, - st->old_syn_Overl, - syn_Overl_TDAC, - st->old_Aq_12_8_fx, - tcx_mdct_window_trans, - L_win, - tmp_offset, - tmp3, - tmp8, - fullbandScale - ); - - IF (w > 0) - { - tcx_windowing_synthesis_past_frame(xn_buf+tcx_offset-shr(L_ola , 1)+ imult1616(w,L_win), - tcx_aldo_window_1_trunc, - tcx_mdct_window_half, - tcx_mdct_window_minimum, - L_ola, - tcx_mdct_window_half_length, - tcx_mdct_window_min_length, - MIN_OVERLAP - ); - } /* add part of current sub-window overlapping with previous window */ - Vr_add(win, - xn_buf+tcx_offset-shr(L_ola,1)+w*L_win, /*instrumented only shr because in fact, its only L_win+L_win+L_win...*/ - xn_buf+tcx_offset-shr(L_ola,1)+w*L_win, - L_ola); + v_add( win, xn_buf+tcx_offset-(L_ola>>1)+w*L_win, xn_buf+tcx_offset-(L_ola>>1)+w*L_win, L_ola ); + /* copy new sub-window region not overlapping with previous window */ - Copy( - win+L_ola, - xn_buf+tcx_offset+shr(L_ola,1)+w*L_win, - L_win); + mvr2r( win+L_ola, xn_buf+tcx_offset+(L_ola>>1)+w*L_win, L_win ); } /* To assure that no garbage values are passed to overlap */ - set16_fx(xn_buf+L_frame+tcx_offset+shr(L_ola,1), 0, overlap-tcx_offset-shr(L_ola,1)); + set_zero( xn_buf+L_frame+tcx_offset+(L_ola>>1), overlap-tcx_offset-(L_ola>>1) ); } - ELSE IF ( bfi == 0 && (frame_cnt == 0) && (tcx_cfg->tcx_curr_overlap_mode == FULL_OVERLAP)) + else if (!bfi && (frame_cnt == 0) && (tcx_cfg->tcx_curr_overlap_mode == FULL_OVERLAP)) { - Word16 win[(L_FRAME_PLUS+L_MDCT_OVLP_MAX)/2]; - Word16 L_win, L_ola, w; - /* special overlap attempt, two transforms, grouping into one window */ - L_win = shr(L_frame, 1); - L_ola = tcx_mdct_window_min_length; - move16(); + float win[(L_FRAME_PLUS+L_MDCT_OVLP_MAX)/2]; + const int L_win = L_frame >> 1; + const int L_ola = tcx_mdct_window_min_length; + int w; - set16_fx(win, 0, (L_FRAME_PLUS+L_MDCT_OVLP_MAX)/2); + set_f( win, 0, (L_FRAME_PLUS+L_MDCT_OVLP_MAX)/2 ); /* 1st TCX-5 window, special MDCT with minimum overlap on right side */ + TCX_MDCT_Inverse(x, win+L_win, 0, L_win-(L_ola>>1), L_ola); - TCX_MDCT_Inverse(x, sub(x_e, TCX_IMDCT_SCALE+TCX_IMDCT_HEADROOM), - win + L_win, - 0, sub(L_win, shr(L_ola, 1)), L_ola); + set_zero(xn_buf, (overlap>>1)); - set16_fx(xn_buf, 0, shr(overlap,1)); /* copy new sub-window region not overlapping with previous window */ - Copy(win+L_win, xn_buf+shr(overlap,1), add(L_win,shr(L_ola,1)) ); + mvr2r(win+L_win, xn_buf+(overlap>>1), L_win+(L_ola>>1)); /* 2nd TCX-5 window, regular MDCT with minimum overlap on both sides */ - TCX_MDCT_Inverse(x + L_spec_TCX5, sub(x_e, TCX_IMDCT_SCALE+TCX_IMDCT_HEADROOM), - win, - L_ola, sub(L_win, L_ola), L_ola); + TCX_MDCT_Inverse(x+L_spec_TCX5, win, L_ola, L_win-L_ola, L_ola); - tcx_windowing_synthesis_current_frame(win, - tcx_aldo_window_2, - tcx_mdct_window_half, - tcx_mdct_window_minimum, - L_ola, - tcx_mdct_window_half_length, - tcx_mdct_window_min_length, - 0, /* left_rect */ - MIN_OVERLAP, /* left_mode */ - acelp_zir, - st->old_syn_Overl, - syn_Overl_TDAC, - st->old_Aq_12_8_fx, - tcx_mdct_window_trans, - L_win, - tmp_offset, - 1, /* st->last_core_bfi */ - 0, /* st->last_is_cng */ - fullbandScale - ); + tcx_windowing_synthesis_current_frame( win, tcx_aldo_window_2, tcx_mdct_window_half, tcx_mdct_window_minimum, L_ola, tcx_mdct_window_half_length, tcx_mdct_window_min_length, 0, + /* left_rect */ MIN_OVERLAP, /* left_mode */ acelp_zir, st->old_syn_Overl, syn_Overl_TDAC, st->old_Aq_12_8, tcx_mdct_window_trans, L_win, + tcx_offset<0?-tcx_offset:0, + 1, /* st->last_mode_bfi */ 0, /* st->last_is_cng */ fullbandScale ); - tmpP16 = xn_buf + add(sub(L_win, shr(L_ola, 1)), shr(overlap,1)); - - tcx_windowing_synthesis_past_frame(tmpP16, - tcx_aldo_window_1_trunc, - tcx_mdct_window_half, - tcx_mdct_window_minimum, - L_ola, - tcx_mdct_window_half_length, - tcx_mdct_window_min_length, - MIN_OVERLAP - ); + tcx_windowing_synthesis_past_frame( xn_buf+(overlap>>1)+L_win-(L_ola>>1), tcx_aldo_window_1_trunc, tcx_mdct_window_half, tcx_mdct_window_minimum, + L_ola, tcx_mdct_window_half_length, tcx_mdct_window_min_length, 2 ); /* add part of current sub-window overlapping with previous window */ - FOR (i = 0; i < L_ola; i++) - { - tmpP16[i] = add(tmpP16[i], win[i]); - move16(); - } + v_add(win, xn_buf+(overlap>>1)+L_win-(L_ola>>1), xn_buf+(overlap>>1)+L_win-(L_ola>>1), L_ola); /* copy new sub-window region not overlapping with previous window */ - Copy(win + L_ola, - xn_buf + add(add(shr(overlap,1), shr(L_ola, 1)), L_win), - L_win); + mvr2r(win+L_ola, xn_buf+(overlap>>1)+L_win+(L_ola>>1), L_win); /* extra folding-out on left side of win, for perfect reconstruction */ - FOR (w = shr(overlap,1); w < overlap; w++) + for (w = (overlap>>1); w < overlap; w++) { - xn_buf[overlap-1-w] = negate(xn_buf[w]); - move16(); + xn_buf[overlap-1-w] = -1.0f * xn_buf[w]; } - tcx_windowing_synthesis_current_frame(xn_buf, - tcx_aldo_window_2, - tcx_mdct_window_half, - tcx_mdct_window_minimum, - overlap, - tcx_mdct_window_half_length, - tcx_mdct_window_min_length, - left_rect, - 0, /* left_mode */ - acelp_zir, - st->old_syn_Overl, - syn_Overl_TDAC, - st->old_Aq_12_8_fx, - tcx_mdct_window_trans, - shl(L_win,1), - tmp_offset, - st->last_core_bfi, - st->last_is_cng, - fullbandScale - ); - + tcx_windowing_synthesis_current_frame( xn_buf, tcx_aldo_window_2, tcx_mdct_window_half, tcx_mdct_window_minimum, overlap, tcx_mdct_window_half_length, + tcx_mdct_window_min_length, left_rect, 0, /* left_mode */ acelp_zir, st->old_syn_Overl, syn_Overl_TDAC, st->old_Aq_12_8, + tcx_mdct_window_trans, 2*L_win, tcx_offset<0?-tcx_offset:0, + st->last_core_bfi, st->last_is_cng, fullbandScale ); } - ELSE /* default i.e. maximum overlap, single transform, no grouping */ + else { + /* default, i.e. maximum overlap, single transform, no grouping */ - TCX_MDCT_Inverse(x, sub(x_e, TCX_IMDCT_SCALE+TCX_IMDCT_HEADROOM), - xn_buf, - overlap, sub(L_frame, overlap), overlap); + TCX_MDCT_Inverse(x, xn_buf, overlap, L_frame-overlap, overlap); - tmp1 = index; - move16(); - test(); - test(); - test(); - if ( bfi==0 && (frame_cnt > 0) && (index == 0) && (st->last_core_fx != ACELP_CORE)) - { - tmp1 = MIN_OVERLAP; - move16(); - } + tcx_windowing_synthesis_current_frame( xn_buf, tcx_aldo_window_2, tcx_mdct_window_half, tcx_mdct_window_minimum, overlap, tcx_mdct_window_half_length, + tcx_mdct_window_min_length, left_rect, !bfi && (frame_cnt > 0) && (index == 0) && ( st->last_core != ACELP_CORE) ? MIN_OVERLAP : index, + acelp_zir, st->old_syn_Overl, syn_Overl_TDAC, st->old_Aq_12_8, tcx_mdct_window_trans, L_frame_glob >> 1, + tcx_offset<0?-tcx_offset:0, + (frame_cnt > 0 /*|| (st->last_con_tcx )*/) ? 1 : st->last_core_bfi, (frame_cnt > 0) ? 0 : st->last_is_cng, fullbandScale ); - tmp3 = st->last_core_bfi; - move16(); - if (frame_cnt > 0) - { - tmp3 = 1; - move16(); - } - - tmp8 = st->last_is_cng; - move16(); - if (frame_cnt > 0) - { - tmp8 = 0; - move16(); - } - - tcx_windowing_synthesis_current_frame(xn_buf, - tcx_aldo_window_2, - tcx_mdct_window_half, - tcx_mdct_window_minimum, - overlap, - tcx_mdct_window_half_length, - tcx_mdct_window_min_length, - left_rect, - tmp1, - acelp_zir, - st->old_syn_Overl, - syn_Overl_TDAC, - st->old_Aq_12_8_fx, - tcx_mdct_window_trans, - shr(L_frame_glob, 1), - tmp_offset, - tmp3, - tmp8, - fullbandScale - ); - } + } /* tcx_last_overlap_mode != FULL_OVERLAP */ } - ELSE /* frame is TCX-20 or not TCX-only */ + else { + /* frame is TCX-20 or not TCX-only */ assert(frame_cnt == 0); - - IF (sub(st->tcx_cfg.tcx_last_overlap_mode, TRANSITION_OVERLAP) != 0) + if (st->tcx_cfg.tcx_last_overlap_mode != TRANSITION_OVERLAP) { - Word32 tmp_buf[L_FRAME_PLUS]; - Word16 Q; - - /* DCT */ - Q = sub(31, x_e); - edct_fx(x, tmp_buf, L_frame, &Q); - - /* scale by sqrt(L / NORM_MDCT_FACTOR) */ - tmp1 = mult_r(shl(L_frame, 4), 26214/*128.f / NORM_MDCT_FACTOR Q15*/); /* 4Q11 */ - tmp2 = 4; - move16(); - tmp1 = Sqrt16(tmp1, &tmp2); - - FOR (i = 0; i < L_frame; i++) - { - tmp_buf[i] = Mpy_32_16_1(tmp_buf[i], tmp1); - move32(); - } - Q = sub(Q, tmp2); - - - window_ola_fx(tmp_buf, - xn_buf, - &Q, - old_out, - Q_old_wtda, - L_frame, - tcx_cfg->tcx_last_overlap_mode, - tcx_cfg->tcx_curr_overlap_mode, - 0, - 0, - NULL); - - /* scale output */ - IF (Q <= 0) - { - FOR (i = 0; i < L_frame; i++) - { - xn_buf[i] = shr(xn_buf[i], Q); - move16(); - } - } - ELSE - { - tmp1 = shr(0x4000, sub(Q,1)); - - FOR (i = 0; i < L_frame; i++) - { - xn_buf[i] = mult_r(xn_buf[i], tmp1); - move16(); - } - } + float tmp[L_FRAME_PLUS]; + edct(x, xn_buf+overlap/2+nz, L_frame); + v_multc( xn_buf+overlap/2+nz, (float)sqrt((float)L_frame / NORM_MDCT_FACTOR), tmp, L_frame); + window_ola( tmp, xn_buf, old_out, L_frame, tcx_cfg->tcx_last_overlap_mode, tcx_cfg->tcx_curr_overlap_mode, 0, 0, NULL ); aldo = 1; - move16(); + } - ELSE + else { - - TCX_MDCT_Inverse(x, sub(x_e, TCX_IMDCT_SCALE+TCX_IMDCT_HEADROOM), - xn_buf, overlap, sub(L_frame, overlap), overlap); - + TCX_MDCT_Inverse(x, xn_buf, overlap, L_frame-overlap, overlap); /*-----------------------------------------------------------* * Windowing, overlap and add * *-----------------------------------------------------------*/ - /* Window current frame */ - tmp3 = st->last_core_bfi; - move16(); - - tmp8 = st->last_is_cng; - move16(); - tcx_windowing_synthesis_current_frame( xn_buf, - tcx_aldo_window_2, - tcx_mdct_window_half, - tcx_mdct_window_minimum, - overlap, - tcx_mdct_window_half_length, - tcx_mdct_window_min_length, - left_rect, - tcx_cfg->tcx_last_overlap_mode, - acelp_zir, - st->old_syn_Overl, - syn_Overl_TDAC, - st->old_Aq_12_8_fx, - tcx_mdct_window_trans, - shr(L_frame_glob, 1), - tmp_offset, - tmp3, - tmp8, - fullbandScale - ); - } /* TRANSITION_OVERLAP */ + tcx_windowing_synthesis_current_frame( xn_buf, tcx_aldo_window_2, tcx_mdct_window_half, tcx_mdct_window_minimum, overlap, tcx_mdct_window_half_length, tcx_mdct_window_min_length, + left_rect, tcx_cfg->tcx_last_overlap_mode, acelp_zir, st->old_syn_Overl, syn_Overl_TDAC, st->old_Aq_12_8, tcx_mdct_window_trans, L_frame_glob >> 1, + tcx_offset<0?-tcx_offset:0, + st->last_core_bfi, + st->last_is_cng, + fullbandScale ); + } } /* TCX-20 and TCX-only */ /* Window and overlap-add past frame if past frame is TCX */ - test(); - IF ((frame_cnt != 0) || (st->last_core_bfi > ACELP_CORE)) + if( (frame_cnt != 0) || (st->last_core_bfi > ACELP_CORE) ) { - test(); - test(); - IF (((sub(L_frameTCX, shr(st->L_frameTCX, 1)) == 0) && (st->tcxonly != 0)) || (sub(st->tcx_cfg.tcx_last_overlap_mode, TRANSITION_OVERLAP) == 0)) + if (((L_frameTCX == st->L_frameTCX >> 1) && (st->tcxonly)) || (st->tcx_cfg.tcx_last_overlap_mode == TRANSITION_OVERLAP)) { - test(); - test(); - test(); - test(); - if ((bfi == 0) && (frame_cnt > 0) && (index == 0) && - (tcx_cfg->tcx_curr_overlap_mode == FULL_OVERLAP) && (st->last_core_fx != ACELP_CORE)) + if (!bfi && (frame_cnt > 0) && (index == 0) && (tcx_cfg->tcx_curr_overlap_mode == FULL_OVERLAP) && (st->last_core != ACELP_CORE)) { - index = MIN_OVERLAP; /* use minimum overlap between the two TCX-10 windows */ move16(); + index = MIN_OVERLAP; /* use minimum overlap between the two TCX-10 windows */ } - IF (tcx_cfg->last_aldo != 0) + if( tcx_cfg->last_aldo ) { - Word16 tmp4; - - tmp2 = add(*Q_old_wtda, TCX_IMDCT_HEADROOM); - tmp4 = sub(shr(overlap, 1), tcx_offset); - - FOR (i = 0; i < tmp4; i++) + for (i=0; i < overlap - tcx_mdct_window_min_length; i++) { - xn_buf[i] = shl(xn_buf[i], TCX_IMDCT_HEADROOM); - move16(); - } - - tmp1 = sub(overlap, tcx_mdct_window_min_length); - FOR (i=0; i < tmp1; i++) - { - xn_buf[i+tmp4] = shl(add(xn_buf[i+tmp4], shr(old_out[i+nz], tmp2)), TCX_IMDCT_HEADROOM); - move16(); + xn_buf[i+overlap/2-tcx_offset] += old_out[i+nz]; } /* fade truncated ALDO window */ - tmp1 = sub(overlap, shr(tcx_mdct_window_min_length, 1)); - FOR ( ; i < tmp1; i++) + for ( ; i < overlap; i++) { - tmp3 = mult_r(shr(old_out[i+nz], tmp2), tcx_mdct_window_minimum[i-overlap+tcx_mdct_window_min_length].v.re); - xn_buf[i+tmp4] = shl(add(xn_buf[i+tmp4], tmp3), TCX_IMDCT_HEADROOM); - move16(); - } - FOR ( ; i < overlap; i++) - { - tmp3 = mult_r(shr(old_out[i+nz], tmp2), tcx_mdct_window_minimum[overlap-1-i].v.im); - xn_buf[i+tmp4] = shl(add(xn_buf[i+tmp4], tmp3), TCX_IMDCT_HEADROOM); - move16(); - } - - FOR (i = add(i, tmp4) ; i < L_frame; i++) - { - xn_buf[i] = shl(xn_buf[i], TCX_IMDCT_HEADROOM); - move16(); + xn_buf[i+overlap/2-tcx_offset] += old_out[i+nz] * tcx_mdct_window_minimum[overlap-1-i]; } } - ELSE + else { - tmp1 = index; - move16(); - test(); - if ((index == 0) || (sub(tcx_cfg->tcx_last_overlap_mode, MIN_OVERLAP) == 0)) - { - tmp1 = tcx_cfg->tcx_last_overlap_mode; - move16(); - } - tcx_windowing_synthesis_past_frame( old_syn_overl - , - tcx_aldo_window_1_trunc, - tcx_mdct_window_half, - tcx_mdct_window_minimum, - overlap, - tcx_mdct_window_half_length, - tcx_mdct_window_min_length, - tmp1 - ); - - BASOP_SATURATE_WARNING_OFF; - IF ( bfi ) + , + tcx_aldo_window_1_trunc, tcx_mdct_window_half, tcx_mdct_window_minimum, + overlap, tcx_mdct_window_half_length, tcx_mdct_window_min_length, + (index == 0 || tcx_cfg->tcx_last_overlap_mode == MIN_OVERLAP) ? tcx_cfg->tcx_last_overlap_mode : index ); + if (bfi) { - tmp1 = sub(shr(overlap, 1), tcx_offset); - tmp3 = shr(tcx_mdct_window_half_length, 1); - FOR (i=0; i < tmp1; i++) + for (i=0; i>1)] += old_syn_overl[i]; } } - BASOP_SATURATE_WARNING_ON; } } - /* aldo must not become 0 unless for TCX10 and frames after tansistion frames */ - assert( aldo != 0 || - (L_frameTCX == st->L_frameTCX >> 1 && st->tcxonly) || - st->tcx_cfg.tcx_last_overlap_mode == TRANSITION_OVERLAP); - } - ELSE - { - IF (aldo == 0) - { - BASOP_SATURATE_WARNING_OFF; - FOR (i = 0; i < L_frame; i++) - { - xn_buf[i] = shl(xn_buf[i], TCX_IMDCT_HEADROOM); - move16(); - } - BASOP_SATURATE_WARNING_ON; - } } - test(); - test(); - test(); - IF ( (aldo == 0) && - ((sub(L_frameTCX, shr(st->L_frameTCX, 1)) == 0 && frame_cnt > 0) || - sub(L_frameTCX, shr(st->L_frameTCX, 1)) != 0) ) + if( !aldo && (((L_frameTCX == st->L_frameTCX >> 1)&&frame_cnt > 0) || L_frameTCX != (st->L_frameTCX >> 1)) ) { /*Compute windowed synthesis in case of switching to ALDO windows in next frame*/ - FOR (i = 0; i < nz; i++) - { - old_out[i] = shr(xn_buf[L_frame-nz+i], TCX_IMDCT_HEADROOM); - move16(); - } - Copy(xn_buf+L_frame, old_out+nz, overlap); - set16_fx(old_out+nz+overlap, 0, nz); + mvr2r( xn_buf+L_frame-nz, old_out, nz+overlap ); + set_zero( old_out+nz+overlap, nz ); - tcx_windowing_synthesis_past_frame( old_out+nz, - tcx_aldo_window_1_trunc, - tcx_mdct_window_half, - tcx_mdct_window_minimum, - overlap, - tcx_mdct_window_half_length, - tcx_mdct_window_min_length, - tcx_cfg->tcx_curr_overlap_mode - ); + tcx_windowing_synthesis_past_frame( old_out+nz, tcx_aldo_window_1_trunc, tcx_mdct_window_half, tcx_mdct_window_minimum, + overlap, tcx_mdct_window_half_length, tcx_mdct_window_min_length, tcx_cfg->tcx_curr_overlap_mode ); /* If current overlap mode = FULL_OVERLAP -> ALDO_WINDOW */ - IF (sub(tcx_cfg->tcx_curr_overlap_mode, FULL_OVERLAP) == 0) + if( tcx_cfg->tcx_curr_overlap_mode == FULL_OVERLAP ) { - FOR (i=0; itcx_cfg.last_aldo = aldo; - move16(); + tcx_cfg->last_aldo = aldo; } /* Smoothing between the ACELP PLC and TCX Transition frame. Using the shape of the half overlap window for the crossfading. */ - test(); - test(); - test(); - IF (left_rect && (frame_cnt == 0) && (st->last_core_bfi == ACELP_CORE) - && st->prev_bfi_fx) + if( left_rect && (frame_cnt == 0) && (st->last_core_bfi == ACELP_CORE) && st->prev_bfi ) { - - IF (fullbandScale) + if( FB_flag ) { - tmp1 = sub(shr(overlap, 1), tcx_offset); - tmp3 = shr(tcx_mdct_window_half_length, 1); - FOR (i = 0; i < tmp3; i++) + for (i=0; isyn_OverlFB[i], mult_r( tcx_mdct_window_half[i].v.re, tcx_mdct_window_half[i].v.re ) ) ); - move16(); - } - FOR ( ; i < tcx_mdct_window_half_length; i++) - { - xn_buf[i+tmp1] = mult_r( xn_buf[i+tmp1], tcx_mdct_window_half[tcx_mdct_window_half_length-1-i].v.re ); - xn_buf[i+tmp1] = add( xn_buf[i+tmp1], mult_r( st->syn_OverlFB[i], mult_r( tcx_mdct_window_half[tcx_mdct_window_half_length-1-i].v.im, tcx_mdct_window_half[tcx_mdct_window_half_length-1-i].v.im ) ) ); - move16(); + xn_buf[i+overlap/2-tcx_offset] *= tcx_mdct_window_half[i]; + xn_buf[i+overlap/2-tcx_offset] += st->syn_OverlFB[i] * tcx_mdct_window_half[tcx_mdct_window_half_length-1-i] * tcx_mdct_window_half[tcx_mdct_window_half_length-1-i]; } } - ELSE + else { - tmp1 = sub(shr(overlap, 1), tcx_offset); - tmp3 = shr(tcx_mdct_window_half_length, 1); - FOR (i = 0; i < tmp3; i++) + for (i=0; isyn_Overl[i], mult_r( tcx_mdct_window_half[i].v.re, tcx_mdct_window_half[i].v.re ) ) ); - move16(); - } - FOR ( ; i < tcx_mdct_window_half_length; i++) - { - xn_buf[i+tmp1] = mult_r( xn_buf[i+tmp1], tcx_mdct_window_half[tcx_mdct_window_half_length-1-i].v.re ); - xn_buf[i+tmp1] = add( xn_buf[i+tmp1], mult_r( st->syn_Overl[i], mult_r( tcx_mdct_window_half[tcx_mdct_window_half_length-1-i].v.im, tcx_mdct_window_half[tcx_mdct_window_half_length-1-i].v.im ) ) ); - move16(); + xn_buf[i+overlap/2-tcx_offset] *= tcx_mdct_window_half[i]; + xn_buf[i+overlap/2-tcx_offset] += st->syn_Overl[i] * tcx_mdct_window_half[tcx_mdct_window_half_length-1-i] * tcx_mdct_window_half[tcx_mdct_window_half_length-1-i]; } } } -} + return; +} diff --git a/src/libs/libevs/lib_dec/dec_tran.cpp b/src/libs/libevs/lib_dec/dec_tran.cpp new file mode 100644 index 00000000..f36d127a --- /dev/null +++ b/src/libs/libevs/lib_dec/dec_tran.cpp @@ -0,0 +1,166 @@ +/*==================================================================================== + EVS Codec 3GPP TS26.443 Nov 13, 2018. Version 12.11.0 / 13.7.0 / 14.3.0 / 15.1.0 + ====================================================================================*/ + +#include "options.h" +#include "cnst.h" +#include "prot.h" + +/*-------------------------------------------------------------------* + * decod_tran() + * + * Decode transition (TC) frames + *-------------------------------------------------------------------*/ + +void decod_tran( + Decoder_State *st, /* i/o: decoder static memory */ + const short L_frame, /* i : length of the frame */ + const short tc_subfr, /* i : TC subframe index */ + const float *Aq, /* i : LP filter coefficient */ + const short coder_type, /* i : coding type */ + const float Es_pred, /* i : predicted scaled innov. energy */ + float *pitch_buf, /* o : floating pitch values for each subframe*/ + float *voice_factors, /* o : voicing factors */ + float *exc, /* i/o: adapt. excitation exc */ + float *exc2, /* i/o: adapt. excitation/total exc */ + float *bwe_exc, /* i/o: excitation for SWB TBE */ + short *unbits, /* i/o: number of unused bits */ + const short sharpFlag, /* i : formant sharpening flag */ + float *gain_buf +) +{ + short T0, T0_frac, T0_min, T0_max; /* integer pitch variables */ + float gain_code; /* Quantized algebraic codeebook gain */ + float norm_gain_code; /* normalized algebraic codeebook gain */ + float gain_pit = 0; /* Quantized pitch gain */ + float voice_fac; /* Voicing factor */ + float gain_inov; /* inovation gain */ + float code[L_SUBFR]; /* algebraic codevector */ + const float *p_Aq; /* pointer to lp filter coefficient */ + float *pt_pitch; /* pointer to floating pitch */ + short i_subfr, i; /* tmp variables */ + short position; /* TC related flag */ + float gain_preQ = 0; /* Gain of prequantizer excitation */ + float code_preQ[L_SUBFR]; /* Prequantizer excitation */ + short Jopt_flag; /* flag indicating zero adaptive contribtuion */ + float norm_gain_preQ; + + gain_preQ = 0; + set_f( code_preQ, 0, L_SUBFR ); + /*----------------------------------------------------------------* + * ACELP subframe loop + *----------------------------------------------------------------*/ + + p_Aq = Aq; + pt_pitch = pitch_buf; + Jopt_flag = 0; + norm_gain_preQ = 0.0f; + + for (i_subfr = 0; i_subfr < L_frame; i_subfr += L_SUBFR) + { + /*------------------------------------------------------------* + * TC : subframe determination & + * adaptive/glottal part of excitation construction + *------------------------------------------------------------*/ + + transition_dec( st, st->core_brate, 0, L_frame, i_subfr, coder_type, tc_subfr, &Jopt_flag, exc, + &T0, &T0_frac, &T0_min, &T0_max, &pt_pitch, &position, bwe_exc ); + + /*-----------------------------------------------------------------* + * Transform domain contribution decoding - active frames + *-----------------------------------------------------------------*/ + + if( st->core_brate > ACELP_24k40 ) + { + transf_cdbk_dec( st, st->core_brate, coder_type, 0, i_subfr, tc_subfr, Es_pred, 0, + &st->mem_preemp_preQ, &gain_preQ, &norm_gain_preQ, code_preQ, unbits ); + } + + /*-----------------------------------------------------------------* + * ACELP codebook search + pitch sharpening + *-----------------------------------------------------------------*/ + + inov_decode( st, st->core_brate, 0, L_frame, coder_type, sharpFlag, i_subfr, tc_subfr, p_Aq, st->tilt_code, *pt_pitch, code ); + + /*-----------------------------------------------------------------* + * De-quantize the gains + * Update tilt of code: 0.0 (unvoiced) to 0.5 (voiced) + *-----------------------------------------------------------------*/ + + if( Jopt_flag == 0 ) + { + /* 2/3-bit decoding */ + gain_dec_tc( st, st->core_brate, L_frame, i_subfr, tc_subfr, Es_pred, code, &gain_pit, &gain_code, &gain_inov, &norm_gain_code ); + } + else + { + /* 5-bit decoding */ + if ( st->core_brate > ACELP_32k ) + { + gain_dec_SQ( st, st->core_brate, coder_type, i_subfr, tc_subfr, code, Es_pred, &gain_pit, &gain_code, &gain_inov, &norm_gain_code ); + } + else + { + gain_dec_mless( st, st->core_brate, L_frame, coder_type, i_subfr, tc_subfr, code, Es_pred, &gain_pit, &gain_code, &gain_inov, &norm_gain_code ); + } + } + + /* update LP filtered gains for the case of frame erasures */ + lp_gain_updt( i_subfr, gain_pit, norm_gain_code + norm_gain_preQ, &st->lp_gainp, &st->lp_gainc, L_frame ); + + st->tilt_code = est_tilt( exc+i_subfr, gain_pit, code, gain_code, &voice_fac,L_SUBFR,0 ); + + /*----------------------------------------------------------------------* + * Find the total excitation + *----------------------------------------------------------------------*/ + + for (i = 0; i < L_SUBFR; i++) + { + exc2[i+i_subfr] = gain_pit*exc[i+i_subfr]; + exc[i+i_subfr] = exc2[i+i_subfr] + gain_code*code[i]; + } + + /*-----------------------------------------------------------------* + * Add the ACELP pre-quantizer contribution + *-----------------------------------------------------------------*/ + + if( st->core_brate > ACELP_24k40 ) + { + for ( i = 0; i < L_SUBFR; i++ ) + { + exc2[i+i_subfr] += gain_preQ * code_preQ[i]; + exc[i+i_subfr] += gain_preQ * code_preQ[i]; + } + } + + /*-----------------------------------------------------------------* + * Prepare TBE excitation + *-----------------------------------------------------------------*/ + + prep_tbe_exc( L_frame, i_subfr, gain_pit, gain_code, code, voice_fac, &voice_factors[i_subfr/L_SUBFR], + bwe_exc, gain_preQ, code_preQ, T0, coder_type, st->core_brate ); + + /*----------------------------------------------------------------* + * Excitation enhancements (update of total excitation signal) + *----------------------------------------------------------------*/ + if( st->core_brate > ACELP_32k ) + { + mvr2r( exc+i_subfr, exc2+i_subfr, L_SUBFR ); + } + else + { + enhancer( MODE1, st->core_brate, -1, 0, coder_type, L_frame, voice_fac, st->stab_fac, + norm_gain_code, gain_inov, &st->gc_threshold, code, exc2 + i_subfr, gain_pit, st->dispMem ); + } + + p_Aq += (M+1); + pt_pitch++; + st->tilt_code_dec[i_subfr/L_SUBFR] = st->tilt_code; + gain_buf[i_subfr/L_SUBFR] = gain_pit; + } + + /* SC-VBR */ + st->prev_gain_pit_dec = gain_pit; + + return; +} diff --git a/src/libs/libevs/lib_dec/dec_tran_fx.cpp b/src/libs/libevs/lib_dec/dec_tran_fx.cpp deleted file mode 100755 index 82698a60..00000000 --- a/src/libs/libevs/lib_dec/dec_tran_fx.cpp +++ /dev/null @@ -1,230 +0,0 @@ -/*==================================================================================== - EVS Codec 3GPP TS26.442 Apr 03, 2018. Version 12.11.0 / 13.6.0 / 14.2.0 - ====================================================================================*/ - -#include "options.h" /* Compilation switches */ -#include "cnst_fx.h" /* Common constants */ -#include "prot_fx.h" /* Function prototypes */ -#include "stl.h" - -/*======================================================================*/ -/* FUNCTION : decod_tran_fx() */ -/*----------------------------------------------------------------------*/ -/* PURPOSE : Decode transition (TC) frames */ -/* */ -/*----------------------------------------------------------------------*/ -/* GLOBAL INPUT ARGUMENTS : */ -/* _ (Struct) st_fx : decoder static memory */ -/* _ (Word16) L_frame_fx : length of the frame Q0 */ -/* _ (Word16[]) Aq_fx : LP filter coefficient Q12 */ -/* _ (Word16) coder_type_fx : coding type Q12 */ -/* _ (Word16) Es_pred_fx : predicted scaled innov. energy Q8 */ -/* _ (Word16[]) pitch_buf_fx : floating pitch values for each subframe Q6*/ -/* _ (Word16[]) voice_factors_fx: frame error rate Q15 */ -/*-----------------------------------------------------------------------*/ -/* OUTPUT ARGUMENTS : */ -/* _ (Word16[]) exc_fx : adapt. excitation exc (Q_exc) */ -/* _ (Word16[]) exc2_fx : adapt. excitation/total exc (Q_exc) */ -/*-----------------------------------------------------------------------*/ - - -/*-----------------------------------------------------------------------*/ -/* RETURN ARGUMENTS : */ -/* _ None */ -/*=======================================================================*/ - -void decod_tran_fx( - Decoder_State_fx *st_fx, /* i/o: decoder static memory */ - const Word16 L_frame_fx, /* i : length of the frame */ - const Word16 tc_subfr_fx, /* i : TC subframe index */ - const Word16 *Aq_fx, /* i : LP filter coefficient */ - const Word16 coder_type_fx, /* i : coding type */ - const Word16 Es_pred_fx, /* i : predicted scaled innov. energy */ - Word16 *pitch_buf_fx, /* o : floating pitch values for each subframe*/ - Word16 *voice_factors_fx, /* o : voicing factors */ - Word16 *exc_fx, /* i/o: adapt. excitation exc */ - Word16 *exc2_fx, /* i/o: adapt. excitation/total exc */ - Word16 *bwe_exc_fx, /* i/o: excitation for SWB TBE */ - Word16 *unbits, /* i/o: number of unused bits */ - const Word16 sharpFlag, /* i : formant sharpening flag */ - Word16 *gain_buf -) -{ - Word16 T0, T0_frac, T0_min, T0_max; /* integer pitch variables */ - Word32 gain_code_fx=0; /* Quantized algebraic codeebook gain */ - Word32 norm_gain_code_fx=0; /* normalized algebraic codeebook gain */ - Word16 gain_pit_fx = 0; /* Quantized pitch gain */ - Word16 voice_fac_fx; /* Voicing factor */ - Word16 gain_inov_fx=0; /* inovation gain */ - Word16 code_fx[L_SUBFR]; /* algebraic codevector */ - const Word16 *p_Aq_fx; /* pointer to lp filter coefficient */ - Word16 *pt_pitch_fx; /* pointer to floating pitch */ - Word16 i_subfr, i; /* tmp variables */ - Word16 position; /* TC related flag */ - Word16 gain_preQ_fx = 0; /* Gain of prequantizer excitation */ - Word16 code_preQ_fx[L_SUBFR]; /* Prequantizer excitation */ - Word16 Jopt_flag; /* flag indicating zero adaptive contribtuion */ - Word32 norm_gain_preQ_fx; - Word16 gain_code16; - Word32 L_tmp; - Word16 tmp16, tmp1_fx, tmp_fx; - gain_preQ_fx = 0; - move16(); - set16_fx( code_preQ_fx, 0, L_SUBFR ); - /*----------------------------------------------------------------* - * ACELP subframe loop - *----------------------------------------------------------------*/ - - p_Aq_fx = Aq_fx; - move16(); - pt_pitch_fx = pitch_buf_fx; - move16(); - Jopt_flag = 0; - move16(); - norm_gain_preQ_fx = 0; - move16(); - - FOR( i_subfr = 0; i_subfr < L_frame_fx; i_subfr += L_SUBFR ) - { - /*------------------------------------------------------------* - * TC : subframe determination & - * adaptive/glottal part of excitation construction - *------------------------------------------------------------*/ - - test(); - IF( i_subfr == 0 && sub(st_fx->Q_exc,2) > 0 ) - { - tmp16 = sub(2, st_fx->Q_exc); - Scale_sig(exc_fx-L_EXC_MEM, L_EXC_MEM, tmp16); - Scale_sig(bwe_exc_fx-PIT16k_MAX*2, PIT16k_MAX*2, tmp16); - Scale_sig(st_fx->last_exc_dct_in_fx, L_FRAME, tmp16); - st_fx->Q_exc = add(st_fx->Q_exc,tmp16); - } - - transition_dec_fx( st_fx, st_fx->core_brate_fx, 0, L_frame_fx, i_subfr, coder_type_fx, tc_subfr_fx, &Jopt_flag, exc_fx, - &T0, &T0_frac, &T0_min, &T0_max, &pt_pitch_fx, &position, bwe_exc_fx, &st_fx->Q_exc ); - - /*-----------------------------------------------------------------* - * Transform domain contribution decoding - active frames - *-----------------------------------------------------------------*/ - - IF( L_sub(st_fx->core_brate_fx,ACELP_24k40) > 0 ) - { - gain_code_fx = 0; - move16(); - transf_cdbk_dec_fx( st_fx, st_fx->core_brate_fx, coder_type_fx, 0, i_subfr, tc_subfr_fx, - Es_pred_fx, gain_code_fx, &st_fx->mem_preemp_preQ_fx, &gain_preQ_fx, &norm_gain_preQ_fx, code_preQ_fx, unbits); - } - - /*-----------------------------------------------------------------* - * ACELP codebook search + pitch sharpening - *-----------------------------------------------------------------*/ - - inov_decode_fx( st_fx, st_fx->core_brate_fx, 0, L_frame_fx, coder_type_fx, - sharpFlag, i_subfr, tc_subfr_fx, p_Aq_fx, st_fx->tilt_code_fx, *pt_pitch_fx, code_fx ); - - /*-----------------------------------------------------------------* - * De-quantize the gains - * Update tilt of code: 0.0 (unvoiced) to 0.5 (voiced) - *-----------------------------------------------------------------*/ - - IF( Jopt_flag == 0 ) - { - /* 2/3-bit decoding */ - gain_dec_tc_fx( st_fx, st_fx->core_brate_fx, code_fx, L_frame_fx, i_subfr, tc_subfr_fx, Es_pred_fx, &gain_pit_fx, &gain_code_fx, &gain_inov_fx, &norm_gain_code_fx ); - } - ELSE - { - /* 5-bit decoding */ - IF( L_sub(st_fx->core_brate_fx,ACELP_32k) > 0 ) - { - gain_dec_SQ_fx( st_fx, st_fx->core_brate_fx, coder_type_fx, i_subfr, tc_subfr_fx, code_fx, Es_pred_fx, &gain_pit_fx, &gain_code_fx, &gain_inov_fx, &norm_gain_code_fx ); - } - ELSE - { - gain_dec_mless_fx( st_fx, st_fx->core_brate_fx, L_frame_fx, coder_type_fx, i_subfr, tc_subfr_fx , code_fx, - Es_pred_fx, &gain_pit_fx, &gain_code_fx, &gain_inov_fx, &norm_gain_code_fx ); - - } - } - - /* update LP filtered gains for the case of frame erasures */ - lp_gain_updt_fx( i_subfr, gain_pit_fx, L_add(norm_gain_code_fx,norm_gain_preQ_fx), &st_fx->lp_gainp_fx, &st_fx->lp_gainc_fx, L_frame_fx ); - - st_fx->tilt_code_fx = est_tilt_fx( exc_fx+i_subfr, gain_pit_fx, code_fx, gain_code_fx,&voice_fac_fx,st_fx->Q_exc); - - /*----------------------------------------------------------------------* - * Find the total excitation - *----------------------------------------------------------------------*/ - - IF ( sub(L_frame_fx,L_FRAME) == 0 ) /* Rescaling for 12.8k core */ - { - Rescale_exc( st_fx->dct_post_old_exc_fx, &exc_fx[i_subfr], &bwe_exc_fx[i_subfr * HIBND_ACB_L_FAC], st_fx->last_exc_dct_in_fx, - L_SUBFR, L_SUBFR * HIBND_ACB_L_FAC, gain_code_fx, &(st_fx->Q_exc), st_fx->Q_subfr, exc2_fx, i_subfr, coder_type_fx ); - } - ELSE /* Rescaling for 16k core */ - { - Rescale_exc( st_fx->dct_post_old_exc_fx, &exc_fx[i_subfr], &bwe_exc_fx[i_subfr * 2], st_fx->last_exc_dct_in_fx, - L_SUBFR, L_SUBFR * 2, gain_code_fx, &(st_fx->Q_exc), st_fx->Q_subfr, exc2_fx, i_subfr, coder_type_fx ); - } - - gain_code16 = round_fx(L_shl(gain_code_fx,st_fx->Q_exc)); /*Q_exc*/ - Acelp_dec_total_exc( exc_fx, exc2_fx, gain_code16, gain_pit_fx, i_subfr, code_fx ); - - /*-----------------------------------------------------------------* - * Add the ACELP pre-quantizer contribution - *-----------------------------------------------------------------*/ - - IF( L_sub(st_fx->core_brate_fx,ACELP_24k40) > 0 ) - { - tmp1_fx = add(15-Q_AVQ_OUT_DEC-2,st_fx->Q_exc); - FOR( i = 0; i < L_SUBFR; i++ ) - { - L_tmp = L_mult(gain_preQ_fx, code_preQ_fx[i]); /* Q2 + Q10 -> Q13*/ - L_tmp = L_shl(L_tmp,tmp1_fx); /* Q16 + Q_exc */ - tmp_fx = round_fx(L_tmp); - - exc2_fx[i+i_subfr] = add(exc2_fx[i+i_subfr],tmp_fx); - move16(); - exc_fx[i+i_subfr] = add(exc_fx[i+i_subfr],tmp_fx); - move16(); - } - } - - /*-----------------------------------------------------------------* - * Prepare TBE excitation - *-----------------------------------------------------------------*/ - - prep_tbe_exc_fx( L_frame_fx, i_subfr, gain_pit_fx, gain_code_fx, code_fx, voice_fac_fx, - &voice_factors_fx[i_subfr/L_SUBFR], bwe_exc_fx, gain_preQ_fx, code_preQ_fx, - st_fx->Q_exc, T0, T0_frac, coder_type_fx, st_fx->core_brate_fx ); - - /*----------------------------------------------------------------* - * Excitation enhancements (update of total excitation signal) - *----------------------------------------------------------------*/ - - IF( L_sub(st_fx->core_brate_fx,ACELP_32k) > 0 ) - { - Copy( exc_fx+i_subfr, exc2_fx+i_subfr, L_SUBFR ); - } - ELSE - { - enhancer_fx( st_fx->core_brate_fx, 0, coder_type_fx, i_subfr, L_frame_fx, voice_fac_fx, st_fx->stab_fac_fx, - norm_gain_code_fx, gain_inov_fx, &st_fx->gc_threshold_fx, code_fx, exc2_fx, gain_pit_fx, &(st_fx->dm_fx), st_fx->Q_exc ); - } - - p_Aq_fx += (M+1); - move16(); - pt_pitch_fx++; - st_fx->tilt_code_dec_fx[i_subfr/L_SUBFR] = st_fx->tilt_code_fx; - move16(); - gain_buf[i_subfr/L_SUBFR] = gain_pit_fx; - move16(); - } - - /* SC-VBR */ - st_fx->prev_gain_pit_dec_fx = gain_pit_fx; - move16(); /*Q14*/ - - return; -} diff --git a/src/libs/libevs/lib_dec/dec_uv.cpp b/src/libs/libevs/lib_dec/dec_uv.cpp old mode 100755 new mode 100644 index 112906db..20534432 --- a/src/libs/libevs/lib_dec/dec_uv.cpp +++ b/src/libs/libevs/lib_dec/dec_uv.cpp @@ -1,11 +1,11 @@ /*==================================================================================== - EVS Codec 3GPP TS26.442 Apr 03, 2018. Version 12.11.0 / 13.6.0 / 14.2.0 + EVS Codec 3GPP TS26.443 Nov 13, 2018. Version 12.11.0 / 13.7.0 / 14.3.0 / 15.1.0 ====================================================================================*/ -#include "options.h" /* Compilation switches */ -#include "cnst_fx.h" /* Common constants */ -#include "prot_fx.h" /* Function prototypes */ -#include "stl.h" +#include +#include +#include +#include "prot.h" /*-------------------------------------------------------------------* * decod_unvoiced() @@ -13,77 +13,70 @@ * Decode unvoiced (UC) frames *-------------------------------------------------------------------*/ -void decod_unvoiced_fx( - Decoder_State_fx *st_fx, /* i/o: decoder static memory */ - const Word16 *Aq_fx, /* Q12 i : LP filter coefficient */ - const Word16 coder_type_fx, /* Q0 i : coding type */ - Word16 *tmp_noise_fx, /* Q0 o : long term temporary noise energy */ - Word16 *pitch_buf_fx, /* Q6 o : floating pitch values for each subframe*/ - Word16 *voice_factors_fx, /* Q15 o : voicing factors */ - Word16 *exc_fx, /* Q_X o : adapt. excitation exc */ - Word16 *exc2_fx, /* Q_X o : adapt. excitation/total exc */ - Word16 *bwe_exc_fx /* Q_X i/o: excitation for SWB TBE */ - ,Word16 *gain_buf +void decod_unvoiced( + Decoder_State *st, /* i/o: decoder static memory */ + const float *Aq, /* i : LP filter coefficient */ + const short coder_type, /* i : coding type */ + float *tmp_noise, /* o : long term temporary noise energy */ + float *pitch_buf, /* o : floating pitch values for each subframe */ + float *voice_factors, /* o : voicing factors */ + float *exc, /* o : adapt. excitation exc */ + float *exc2, /* o : adapt. excitation/total exc */ + float *bwe_exc /* i/o: excitation for SWB TBE */ + , float *gain_buf ) { - Word16 gain_pit_fx = 0; /* Quantized pitch gain */ - Word32 gain_code_fx; /* Quantized algebraic codeebook gain */ - Word16 gain_inov_fx; /* inovation gain */ - Word32 norm_gain_code_fx; /* normalized algebraic codeebook gain */ - Word16 voice_fac_fx; /* Voicing factor */ - Word16 code_fx[L_SUBFR]; /* algebraic codevector */ - Word16 i_subfr_fx; - const Word16 *p_Aq_fx; - Word16 *pt_pitch_fx; + float gain_pit = 0; /* Quantized pitch gain */ + float gain_code; /* Quantized algebraic codeebook gain */ + float gain_inov; /* inovation gain */ + float norm_gain_code; /* normalized algebraic codeebook gain */ + float voice_fac; /* Voicing factor */ + float code[L_SUBFR]; /* algebraic codevector */ + short i_subfr; + float *pt_pitch; + const float *p_Aq; - test(); - IF ( sub(st_fx->last_ppp_mode_dec_fx,1) == 0 || sub(st_fx->last_nelp_mode_dec_fx,1) == 0 ) + if( st->last_ppp_mode_dec == 1 || st->last_nelp_mode_dec == 1 ) { /* SC_VBR - reset the decoder, to avoid memory not updated issue for this unrealistic case */ - CNG_reset_dec_fx( st_fx, pitch_buf_fx, voice_factors_fx ); + CNG_reset_dec( st, pitch_buf, voice_factors ); } - p_Aq_fx = Aq_fx; - move16(); /*Q12*/ /* pointer to interpolated LPC parameters */ - pt_pitch_fx = pitch_buf_fx; - move16(); /* pointer to the pitch buffer */ + p_Aq = Aq; /* pointer to interpolated LPC parameters */ + pt_pitch = pitch_buf; /* pointer to the pitch buffer */ - FOR( i_subfr_fx=0; i_subfr_fxcore_brate_fx, i_subfr_fx, code_fx, &norm_gain_code_fx, - &st_fx->lp_gainp_fx, &st_fx->lp_gainc_fx, &gain_inov_fx, &st_fx->tilt_code_fx, - &voice_fac_fx, &gain_pit_fx, pt_pitch_fx, exc_fx, &gain_code_fx, exc2_fx, bwe_exc_fx,&(st_fx->Q_exc),st_fx->Q_subfr ); + gaus_dec( st, st->core_brate, i_subfr, code, &norm_gain_code, + &st->lp_gainp, &st->lp_gainc, &gain_inov, &st->tilt_code, + &voice_fac, &gain_pit, pt_pitch, exc, &gain_code, exc2 ); - *tmp_noise_fx = extract_h(norm_gain_code_fx); /*Q16*/ + *tmp_noise = norm_gain_code; /*----------------------------------------------------------------* * Excitation enhancements (update of total excitation signal) *----------------------------------------------------------------*/ - enhancer_fx( st_fx->core_brate_fx, 0, coder_type_fx, i_subfr_fx, L_FRAME, voice_fac_fx, st_fx->stab_fac_fx, - norm_gain_code_fx, gain_inov_fx, &st_fx->gc_threshold_fx, code_fx, exc2_fx, gain_pit_fx, &(st_fx->dm_fx), st_fx->Q_exc ); + enhancer( MODE1, st->core_brate, -1, 0, coder_type, L_FRAME, voice_fac, st->stab_fac, + norm_gain_code, gain_inov, &st->gc_threshold, code, exc2 + i_subfr, gain_pit, st->dispMem ); - voice_factors_fx[i_subfr_fx/L_SUBFR] = 0; - move16(); + voice_factors[i_subfr/L_SUBFR] = 0.0f; - interp_code_5over2_fx( &exc_fx[i_subfr_fx], &bwe_exc_fx[i_subfr_fx * HIBND_ACB_L_FAC], L_SUBFR ); + interp_code_5over2( &exc[i_subfr], &bwe_exc[i_subfr * HIBND_ACB_L_FAC], L_SUBFR ); - p_Aq_fx += (M+1); - move16(); - pt_pitch_fx++; - st_fx->tilt_code_dec_fx[i_subfr_fx/L_SUBFR] = st_fx->tilt_code_fx; - move16(); + p_Aq += (M+1); + pt_pitch++; + st->tilt_code_dec[i_subfr/L_SUBFR] = st->tilt_code; } /* SC-VBR */ - st_fx->prev_gain_pit_dec_fx = gain_pit_fx; - move16(); + st->prev_gain_pit_dec = gain_pit; - set16_fx( gain_buf, 0, NB_SUBFR ); + set_f( gain_buf, 0, NB_SUBFR ); return; } diff --git a/src/libs/libevs/lib_dec/decision_matrix_dec.cpp b/src/libs/libevs/lib_dec/decision_matrix_dec.cpp new file mode 100644 index 00000000..7e2deaf6 --- /dev/null +++ b/src/libs/libevs/lib_dec/decision_matrix_dec.cpp @@ -0,0 +1,525 @@ +/*==================================================================================== + EVS Codec 3GPP TS26.443 Nov 13, 2018. Version 12.11.0 / 13.7.0 / 14.3.0 / 15.1.0 + ====================================================================================*/ + +#include +#include "options.h" +#include "stat_dec.h" +#include "rom_com.h" +#include "prot.h" + +/*-----------------------------------------------------------------* + * decision_matrix_dec() + * + * ACELP/HQ core selection + * Read ACELP signalling bits from the bitstream + * Set extension layers + *-----------------------------------------------------------------*/ + +void decision_matrix_dec( + Decoder_State *st, /* i/o: decoder state structure */ + short *coder_type, /* o : coder type */ + short *sharpFlag, /* o : formant sharpening flag */ + short *hq_core_type, /* o : HQ core type */ + short *core_switching_flag/* o : ACELP->HQ switching frame flag */ +) +{ + short start_idx; + short ppp_nelp_mode; + long ind; + short nBits; + short tmp; + st->core = -1; + st->core_brate = 0; + st->extl = -1; + st->extl_brate = 0; + st->ppp_mode_dec = 0; + st->nelp_mode_dec = 0; + st->igf = 0; + + if( st->total_brate > ACELP_8k00 ) + { + st->vbr_hw_BWE_disable_dec = 0; + } + + if( st->mdct_sw == MODE2 ) + { + st->core = HQ_CORE; + } + else + { + if ( st->total_brate == FRAME__NO_DATA || st->total_brate == SID_2k40 ) + { + st->core = ACELP_CORE; + st->core_brate = st->total_brate; + + if( st->total_brate != FRAME__NO_DATA ) + { + st->cng_type = get_next_indice( st, 1 ); + + if( st->cng_type == LP_CNG ) + { + st->L_frame = L_FRAME; + + if( get_next_indice( st, 1 ) == 1 ) + { + st->L_frame = L_FRAME16k; + } + } + else + { + st->bwidth = get_next_indice(st, 2); + + if( get_next_indice(st, 1) == 0 ) + { + st->L_frame = L_FRAME; + } + else + { + st->L_frame = L_FRAME16k; + } + } + } + + if( st->output_Fs >= 32000 && st->bwidth >= SWB ) + { + st->extl = SWB_CNG; + } + if ( st->total_brate == FRAME__NO_DATA && st->prev_bfi && !st->bfi && st->L_frame > L_FRAME16k) + { + st->L_frame = st->last_CNG_L_frame; + } + + return; + } + + /* SC-VBR */ + else if ( st->total_brate == PPP_NELP_2k80 ) + { + st->core = ACELP_CORE; + st->core_brate = PPP_NELP_2k80; + st->L_frame = L_FRAME; + st->fscale = sr2fscale(INT_FS_12k8); + + if( st->ini_frame == 0 ) + { + /* avoid switching of internal ACELP Fs in the very first frame */ + st->last_L_frame = st->L_frame; + st->last_core = st->core; + st->last_core_brate = st->core_brate; + st->last_extl = st->extl; + } + + st->vbr_hw_BWE_disable_dec = 1; + + get_next_indice( st, 1 ); + + ppp_nelp_mode = (short) get_next_indice( st, 2 ); + + /* 0 - PPP_NB, 1 - PPP_WB, 2 - NELP_NB, 3 - NELP_WB */ + if ( ppp_nelp_mode == 0 ) + { + st->ppp_mode_dec = 1; + *coder_type = VOICED; + st->bwidth = NB; + } + else if ( ppp_nelp_mode == 1 ) + { + st->ppp_mode_dec = 1; + *coder_type = VOICED; + st->bwidth = WB; + } + else if ( ppp_nelp_mode == 2 ) + { + st->nelp_mode_dec = 1; + *coder_type = UNVOICED; + st->bwidth = NB; + } + else if ( ppp_nelp_mode == 3 ) + { + st->nelp_mode_dec = 1; + *coder_type = UNVOICED; + st->bwidth = WB; + } + + return; + } + + /*---------------------------------------------------------------------* + * ACELP/HQ core selection + *---------------------------------------------------------------------*/ + + if ( st->total_brate < ACELP_24k40 ) + { + st->core = ACELP_CORE; + } + else if ( st->total_brate >= ACELP_24k40 && st->total_brate <= ACELP_64k ) + { + /* read the ACELP/HQ core selection bit */ + tmp = (short) get_next_indice( st, 1 ); + + if( tmp == 0 ) + { + st->core = ACELP_CORE; + } + else + { + st->core = HQ_CORE; + } + } + } + + /*-----------------------------------------------------------------* + * Read ACELP signalling bits from the bitstream + *-----------------------------------------------------------------*/ + + if( st->core == ACELP_CORE ) + { + /* find the section in the ACELP signalling table corresponding to bitrate */ + start_idx = 0; + while ( acelp_sig_tbl[start_idx] != st->total_brate ) + { + start_idx++; + if( start_idx >= MAX_ACELP_SIG ) + { + st->BER_detect = 1; + start_idx--; + break; + } + } + + /* skip the bitrate */ + start_idx += 1; + + /* retrieve the number of bits */ + nBits = (short) acelp_sig_tbl[start_idx++]; + + start_idx += get_next_indice( st, nBits ); + if( start_idx >= MAX_ACELP_SIG ) + { + ind = 0; + st->BER_detect = 1; + } + else + { + /* retrieve the signalling indice */ + ind = acelp_sig_tbl[start_idx]; + + /* convert signalling indice into signalling information */ + *coder_type = ind & 0x7; + if ( *coder_type == LR_MDCT ) + { + st->core = HQ_CORE; + st->bwidth = (ind >> 3) & 0x7; + } + else + { + st->bwidth = (ind >> 3) & 0x7; + *sharpFlag = (ind >> 6) & 0x1; + } + } + + /* detect corrupted signalling (due to bit errors) */ + if( ( st->BER_detect ) || + ( ind >= 1<<7 ) || + ( st->total_brate <= ACELP_13k20 && st->bwidth == FB ) || + ( st->total_brate >= ACELP_32k && st->bwidth == NB ) || + ( st->total_brate >= ACELP_32k && !(*coder_type == GENERIC || *coder_type == TRANSITION || *coder_type == INACTIVE ) ) || + ( st->total_brate < ACELP_13k20 && st->bwidth != NB && *coder_type == LR_MDCT ) || + ( st->total_brate >= ACELP_13k20 && *coder_type == UNVOICED ) || + ( st->total_brate >= ACELP_13k20 && *coder_type == AUDIO && st->bwidth == NB ) + ) + { + st->BER_detect = 0; + st->bfi = 1; + if( st->ini_frame == 0 ) + { + st->core = ACELP_CORE; + st->L_frame = L_FRAME; + st->last_core = st->core; + st->last_core_brate = st->core_brate; + } + else if( st->last_total_brate == -1 ) /* can happen in case of BER when no good frame was received before */ + { + *coder_type = st->last_coder_type; + st->bwidth = st->last_bwidth; + st->total_brate = st->last_total_brate_ber; + if( st->last_core == AMR_WB_CORE ) + { + st->core = ACELP_CORE; + st->codec_mode = MODE1; + } + else if( st->last_core_bfi == TCX_20_CORE || st->last_core_bfi == TCX_10_CORE ) + { + st->core = st->last_core_bfi; + st->codec_mode = MODE2; + } + else + { + st->core = st->last_core; + st->codec_mode = MODE1; + } + st->core_brate = st->last_core_brate; + st->extl = st->last_extl; + st->extl_brate = st->total_brate - st->core_brate; + } + else + { + *coder_type = st->last_coder_type; + st->bwidth = st->last_bwidth; + st->total_brate = st->last_total_brate; + if( st->last_core == AMR_WB_CORE ) + { + st->core = ACELP_CORE; + st->codec_mode = MODE1; + } + else if( st->last_core == TCX_20_CORE || st->last_core == TCX_10_CORE ) + { + st->core = st->last_core; + st->codec_mode = MODE2; + } + else + { + st->core = st->last_core; + st->codec_mode = MODE1; + } + st->core_brate = st->last_core_brate; + st->extl = st->last_extl; + st->extl_brate = st->total_brate - st->core_brate; + } + return; + } + } + + /*-----------------------------------------------------------------* + * Set extension layers + *-----------------------------------------------------------------*/ + + if ( st->core == ACELP_CORE && st->bwidth == WB && st->total_brate < ACELP_9k60 ) + { + if ( st->vbr_hw_BWE_disable_dec == 0 ) + { + st->extl = WB_BWE; + } + } + else if ( st->core == ACELP_CORE && st->bwidth == WB && st->total_brate >= ACELP_9k60 && st->total_brate <= ACELP_16k40 ) + { + /* read the WB TBE/BWE selection bit */ + if ( get_next_indice( st, 1 ) ) + { + st->extl = WB_BWE; + st->extl_brate = WB_BWE_0k35; + } + else + { + st->extl = WB_TBE; + st->extl_brate = WB_TBE_1k05; + } + } + else if ( st->core == ACELP_CORE && (st->bwidth == SWB || st->bwidth == FB) && st->total_brate >= ACELP_13k20 ) + { + if (st->total_brate >= ACELP_48k) + { + st->extl = SWB_BWE_HIGHRATE; + if( st->bwidth == FB ) + { + st->extl = FB_BWE_HIGHRATE; + } + + st->extl_brate = SWB_BWE_16k; + } + + /* read the SWB TBE/BWE selection bit */ + else + { + tmp = get_next_indice( st, 1 ); + + if( tmp ) + { + st->extl = SWB_BWE; + st->extl_brate = SWB_BWE_1k6; + } + else + { + st->extl = SWB_TBE; + st->extl_brate = SWB_TBE_1k6; + if( st->total_brate >= ACELP_24k40 ) + { + st->extl_brate = SWB_TBE_2k8; + } + } + } + + /* set FB TBE and FB BWE extension layers */ + if ( st->bwidth == FB && st->total_brate >= ACELP_24k40 ) + { + if ( st->extl == SWB_BWE ) + { + st->extl = FB_BWE; + st->extl_brate = FB_BWE_1k8; + } + else if ( st->extl == SWB_TBE ) + { + st->extl = FB_TBE; + st->extl_brate = FB_TBE_3k0; + } + } + } + + /* set core bitrate */ + st->core_brate = st->total_brate - st->extl_brate; + + /*-----------------------------------------------------------------* + * Read HQ signalling bits from the bitstream + * Set HQ core type + *-----------------------------------------------------------------*/ + + + if ( st->core == HQ_CORE ) + { + if( st->mdct_sw != MODE2 ) + { + /* skip the HQ/TCX core switching flag */ + get_next_indice_tmp( st, 1 ); + } + + /* read ACELP->HQ core switching flag */ + *core_switching_flag = (short)get_next_indice( st, 1 ); + + if( *core_switching_flag == 1 ) + { + st->last_L_frame_ori = st->last_L_frame; + + /* read ACELP L_frame info */ + if( get_next_indice( st, 1 ) == 0 ) + { + st->last_L_frame = L_FRAME; + } + else + { + st->last_L_frame = L_FRAME16k; + } + } + + if( st->mdct_sw != MODE2 ) + { + /* read/set band-width (needed for different I/O sampling rate support) */ + if( st->total_brate > ACELP_16k40 ) + { + ind = get_next_indice( st, 2 ); + + if( ind == 0 ) + { + st->bwidth = NB; + } + else if( ind == 1 ) + { + st->bwidth = WB; + } + else if( ind == 2 ) + { + st->bwidth = SWB; + } + else + { + st->bwidth = FB; + } + } + } + + /* detect bit errors in signalling */ + if( ( st->total_brate >= ACELP_24k40 && st->bwidth == NB ) || + ( st->core == HQ_CORE && st->total_brate <= LRMDCT_CROSSOVER_POINT && st->bwidth == FB) + ) + { + st->bfi = 1; + + st->core_brate = st->total_brate; + st->extl = -1; + st->extl_brate = 0; + if( st->last_core == AMR_WB_CORE ) + { + st->core = ACELP_CORE; + st->L_frame = L_FRAME; + st->codec_mode = MODE1; + st->last_L_frame = L_FRAME; + + if( st->total_brate >= ACELP_16k40 ) + { + st->total_brate = ACELP_13k20; + st->core_brate = st->total_brate; + } + } + else + { + /* make sure, we are in a valid configuration wrt to bandwidth */ + st->bwidth = WB; + } + } + + /* set HQ core type */ + *hq_core_type = NORMAL_HQ_CORE; + if( (st->bwidth == SWB || st->bwidth == WB) && st->total_brate <= LRMDCT_CROSSOVER_POINT ) + { + *hq_core_type = LOW_RATE_HQ_CORE; + } + else if( st->bwidth == NB ) + { + *hq_core_type = LOW_RATE_HQ_CORE; + } + } + + /*-----------------------------------------------------------------* + * Set ACELP frame length + *-----------------------------------------------------------------*/ + + if( st->core_brate == FRAME__NO_DATA ) + { + /* prevent "L_frame" changes in CNG segments */ + st->L_frame = st->last_L_frame; + } + else if ( st->core_brate == SID_2k40 && st->bwidth == WB && st->first_CNG && st->act_cnt2 < MIN_ACT_CNG_UPD ) + { + /* prevent "L_frame" changes in SID frame after short segment of active frames */ + st->L_frame = st->last_CNG_L_frame; + } + else if ( ( st->core_brate == SID_2k40 && st->total_brate >= ACELP_9k60 && st->bwidth == WB ) || + ( st->total_brate > ACELP_24k40 && st->total_brate < HQ_96k ) || ( st->total_brate == ACELP_24k40 && st->bwidth >= WB ) ) + { + st->L_frame = L_FRAME16k; + } + else + { + st->L_frame = L_FRAME; + } + + if ( st->L_frame == L_FRAME16k ) + { + st->nb_subfr = NB_SUBFR16k; + } + else + { + st->nb_subfr = NB_SUBFR; + } + + if( st->output_Fs == 8000 ) + { + st->extl = -1; + } + else if( st->output_Fs == 16000 && st->L_frame == L_FRAME16k ) + { + st->extl = -1; + st->extl_brate = 0; + } + + if ( st->ini_frame == 0 ) + { + /* avoid switching of internal ACELP Fs in the very first frame */ + st->last_L_frame = st->L_frame; + st->last_core = st->core; + st->last_core_brate = st->core_brate; + st->last_extl = st->extl; + } + + return; +} diff --git a/src/libs/libevs/lib_dec/decision_matrix_dec_fx.cpp b/src/libs/libevs/lib_dec/decision_matrix_dec_fx.cpp deleted file mode 100755 index c7a96440..00000000 --- a/src/libs/libevs/lib_dec/decision_matrix_dec_fx.cpp +++ /dev/null @@ -1,708 +0,0 @@ -/*==================================================================================== - EVS Codec 3GPP TS26.442 Apr 03, 2018. Version 12.11.0 / 13.6.0 / 14.2.0 - ====================================================================================*/ - -#include -#include -#include "options.h" -#include "prot_fx.h" -#include "stat_dec_fx.h" -#include "rom_com_fx.h" -#include "stl.h" - - -/*-----------------------------------------------------------------* - * decision_matrix_dec() - * - * ACELP/HQ core selection - * Read ACELP signalling bits from the bitstream - * Set extension layers - *-----------------------------------------------------------------*/ - -void decision_matrix_dec_fx( - Decoder_State_fx *st, /* i/o: decoder state structure */ - Word16 *coder_type, /* o : coder type */ - Word16 *sharpFlag, /* o : formant sharpening flag */ - Word16 *hq_core_type, /* o : HQ core type */ - Word16 *core_switching_flag/* o : ACELP->HQ switching frame flag */ -) -{ - Word16 start_idx; - Word16 ppp_nelp_mode; - Word32 ind; - Word16 nBits; - Word16 tmp16, temp_core; - - st->core_fx = -1; - move16(); - st->core_brate_fx = L_deposit_l(0); - st->extl_fx = -1; - move16(); - st->extl_brate_fx = 0; - move16(); - st->ppp_mode_dec_fx = 0; - move16(); - st->nelp_mode_dec_fx = 0; - move16(); - st->igf = 0; - move16(); - - if( L_sub(st->total_brate_fx,ACELP_8k00) > 0 ) - { - st->vbr_hw_BWE_disable_dec_fx = 0; - move16(); - } - - IF (sub(st->mdct_sw, MODE2) == 0) - { - st->core_fx = HQ_CORE; - move16(); - } - ELSE - { - test(); - IF( L_sub(st->total_brate_fx,FRAME_NO_DATA) == 0 || L_sub(st->total_brate_fx,SID_2k40) == 0 ) - { - st->core_fx = ACELP_CORE; - move16(); - st->core_brate_fx = st->total_brate_fx; - move32(); - - IF( L_sub(st->total_brate_fx,FRAME_NO_DATA) != 0 ) - { - st->cng_type_fx = get_next_indice_fx( st, 1 ); - - IF( sub(st->cng_type_fx,LP_CNG) == 0 ) - { - st->L_frame_fx = L_FRAME; - move16(); - - tmp16 = get_next_indice_fx( st, 1 ); - if( sub(tmp16,1) == 0 ) - { - st->L_frame_fx = L_FRAME16k; - move16(); - } - } - ELSE - { - st->bwidth_fx = get_next_indice_fx(st, 2); - - tmp16 = get_next_indice_fx(st, 1); - move16(); - - st->L_frame_fx = L_FRAME16k; - move16(); - if( tmp16 == 0 ) - { - st->L_frame_fx = L_FRAME; - move16(); - } - } - } - - test(); - if( L_sub(st->output_Fs_fx,32000) >= 0 && sub(st->bwidth_fx,SWB) >= 0 ) - { - st->extl_fx = SWB_CNG; - move16(); - } - - test(); - test(); - test(); - if( L_sub(st->total_brate_fx,FRAME_NO_DATA) == 0 && st->prev_bfi_fx && !st->bfi_fx && sub(st->L_frame_fx,L_FRAME16k) > 0 ) - { - st->L_frame_fx = st->last_CNG_L_frame_fx; - move16(); - } - - return; - } - - /* SC-VBR */ - ELSE IF( L_sub(st->total_brate_fx,PPP_NELP_2k80) == 0 ) - { - st->core_fx = ACELP_CORE; - move16(); - st->core_brate_fx = PPP_NELP_2k80; - move32(); - st->L_frame_fx = L_FRAME; - move16(); - st->fscale = sr2fscale(INT_FS_FX); - move16(); - - IF ( st->ini_frame_fx == 0 ) - { - /* avoid switching of internal ACELP Fs in the very first frame */ - st->last_L_frame_fx = st->L_frame_fx; - st->last_core_fx = st->core_fx; - st->last_core_brate_fx = st->core_brate_fx; - st->last_extl_fx = st->extl_fx; - } - - st->vbr_hw_BWE_disable_dec_fx = 1; - move16(); - get_next_indice_fx( st, 1 ); - - ppp_nelp_mode = get_next_indice_fx( st, 2 ); - - /* 0 - PPP_NB, 1 - PPP_WB, 2 - NELP_NB, 3 - NELP_WB */ - IF( ppp_nelp_mode == 0 ) - { - st->ppp_mode_dec_fx = 1; - move16(); - *coder_type = VOICED; - move16(); - st->bwidth_fx = NB; - move16(); - } - ELSE IF( sub(ppp_nelp_mode,1) == 0 ) - { - st->ppp_mode_dec_fx = 1; - move16(); - *coder_type = VOICED; - move16(); - st->bwidth_fx = WB; - move16(); - } - ELSE IF( sub(ppp_nelp_mode,2) == 0 ) - { - st->nelp_mode_dec_fx = 1; - move16(); - *coder_type = UNVOICED; - move16(); - st->bwidth_fx = NB; - move16(); - } - ELSE IF( sub(ppp_nelp_mode,3) == 0 ) - { - st->nelp_mode_dec_fx = 1; - move16(); - *coder_type = UNVOICED; - move16(); - st->bwidth_fx = WB; - move16(); - } - - - return; - } - - /*---------------------------------------------------------------------* - * ACELP/HQ core selection - *---------------------------------------------------------------------*/ - - test(); - IF( L_sub(st->total_brate_fx,ACELP_24k40) < 0 ) - { - st->core_fx = ACELP_CORE; - move16(); - } - ELSE IF( L_sub(st->total_brate_fx,ACELP_24k40) >= 0 && L_sub(st->total_brate_fx,ACELP_64k) <= 0 ) - { - /* read the ACELP/HQ core selection bit */ - temp_core = get_next_indice_fx( st, 1 ); - - st->core_fx = HQ_CORE; - move16(); - if( temp_core == 0 ) - { - st->core_fx = ACELP_CORE; - move16(); - } - } - } - - /*-----------------------------------------------------------------* - * Read ACELP signalling bits from the bitstream - *-----------------------------------------------------------------*/ - - IF( sub(st->core_fx,ACELP_CORE) == 0 ) - { - /* find the section in the ACELP signalling table corresponding to bitrate */ - start_idx = 0; - move16(); - WHILE( L_sub(acelp_sig_tbl[start_idx],st->total_brate_fx) != 0 ) - { - start_idx = add(start_idx,1); - IF( sub(start_idx,MAX_ACELP_SIG) >= 0 ) - { - st->BER_detect = 1; - move16(); - start_idx = sub(start_idx,1); - break; - } - } - - /* skip the bitrate */ - start_idx = add(start_idx,1); - - /* retrieve the number of bits */ - nBits = extract_l(acelp_sig_tbl[start_idx]); - start_idx = add(start_idx,1); - - start_idx = add(start_idx,get_next_indice_fx( st, nBits )); - IF( start_idx >= MAX_ACELP_SIG ) - { - ind = 0; - move16(); - st->BER_detect = 1; - move16(); - } - ELSE - { - /* retrieve the signalling indice */ - ind = acelp_sig_tbl[start_idx]; - - /* convert signalling indice into signalling information */ - *coder_type = extract_l(L_and(ind,0x7L)); - - IF( sub(*coder_type,LR_MDCT) == 0 ) - { - st->core_fx = HQ_CORE; - move16(); - st->bwidth_fx = extract_l(L_shr(ind,3) & 0x7L); - } - ELSE - { - st->bwidth_fx = extract_l(L_and(L_shr(ind,3),0x7L)); - *sharpFlag = extract_l(L_and(L_shr(ind,6),0x1L)); - - } - } - - /* detect corrupted signalling (due to bit errors) */ - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - IF( ( st->BER_detect ) || - ( L_sub(ind,1<<7) >= 0 ) || - ( L_sub(st->total_brate_fx,ACELP_13k20) <= 0 && sub(st->bwidth_fx,FB) == 0 ) || - ( L_sub(st->total_brate_fx,ACELP_32k) >= 0 && sub(st->bwidth_fx,NB) == 0 ) || - ( L_sub(st->total_brate_fx,ACELP_32k) >= 0 && !(sub(*coder_type,GENERIC) == 0 || sub(*coder_type,TRANSITION) == 0 || sub(*coder_type,INACTIVE) == 0 ) ) || - ( L_sub(st->total_brate_fx,ACELP_13k20) < 0 && sub(st->bwidth_fx,NB) != 0 && sub(*coder_type,LR_MDCT) == 0 ) || - ( L_sub(st->total_brate_fx,ACELP_13k20) >= 0 && sub(*coder_type,UNVOICED) == 0 ) || - ( L_sub(st->total_brate_fx,ACELP_13k20) >= 0 && sub(*coder_type,AUDIO) == 0 && sub(st->bwidth_fx,NB) == 0 ) - ) - { - st->BER_detect = 0; - move16(); - st->bfi_fx = 1; - move16(); - - IF( st->ini_frame_fx == 0 ) - { - st->core_fx = ACELP_CORE; - move16(); - st->L_frame_fx = L_FRAME; - move16(); - st->last_core_fx = st->core_fx; - move16(); - st->last_core_brate_fx = st->core_brate_fx; - move32(); - } - ELSE IF( L_sub(st->last_total_brate_fx, -1) == 0 ) /* can happen in case of BER when no good frame was received before */ - { - *coder_type = st->last_coder_type_fx; - move16(); - st->bwidth_fx = st->last_bwidth_fx; - move16(); - st->total_brate_fx = st->last_total_brate_ber_fx; - move32(); - test(); - IF( sub(st->last_core_fx, AMR_WB_CORE) == 0 ) - { - st->core_fx = ACELP_CORE; - move16(); - st->codec_mode = MODE1; - move16(); - } - ELSE IF( sub(st->last_core_bfi, TCX_20_CORE) == 0 || sub(st->last_core_bfi, TCX_10_CORE) == 0 ) - { - st->core_fx = st->last_core_bfi; - move16(); - st->codec_mode = MODE2; - move16(); - } - ELSE - { - st->core_fx = st->last_core_fx; - move16(); - st->codec_mode = MODE1; - move16(); - } - st->core_brate_fx = st->last_core_brate_fx; - move32(); - st->extl_fx = st->last_extl_fx; - move16(); - st->extl_brate_fx = L_sub(st->total_brate_fx, st->core_brate_fx); - move32(); - } - ELSE - { - *coder_type = st->last_coder_type_fx; - move16(); - st->bwidth_fx = st->last_bwidth_fx; - move16(); - st->total_brate_fx = st->last_total_brate_fx; - move16(); - - test(); - IF( sub(st->last_core_fx,AMR_WB_CORE) == 0 ) - { - st->core_fx = ACELP_CORE; - move16(); - st->codec_mode = MODE1; - move16(); - } - ELSE IF( sub(st->last_core_fx,TCX_20_CORE) == 0 || sub(st->last_core_fx,TCX_10_CORE) == 0 ) - { - st->core_fx = st->last_core_fx; - move16(); - st->codec_mode = MODE2; - move16(); - } - ELSE - { - st->core_fx = st->last_core_fx; - move16(); - st->codec_mode = MODE1; - move16(); - } - st->core_brate_fx = st->last_core_brate_fx; - move32(); - st->extl_fx = st->last_extl_fx; - move16(); - st->extl_brate_fx = L_sub(st->total_brate_fx,st->core_brate_fx); - } - - return; - } - } - - /*-----------------------------------------------------------------* - * Set extension layers - *-----------------------------------------------------------------*/ - - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - IF( sub(st->core_fx,ACELP_CORE) == 0 && sub(st->bwidth_fx,WB) == 0 && L_sub(st->total_brate_fx,ACELP_9k60) < 0 ) - { - if( st->vbr_hw_BWE_disable_dec_fx == 0 ) - { - st->extl_fx = WB_BWE; - move16(); - } - } - ELSE IF( sub(st->core_fx,ACELP_CORE) == 0 && sub(st->bwidth_fx,WB) == 0 && L_sub(st->total_brate_fx,ACELP_9k60) >= 0 && L_sub(st->total_brate_fx,ACELP_16k40) <= 0 ) - { - /* read the WB TBE/BWE selection bit */ - tmp16 = get_next_indice_fx( st, 1 ); - IF( sub(tmp16,1) == 0 ) - { - st->extl_fx = WB_BWE; - move16(); - st->extl_brate_fx = WB_BWE_0k35; - move32(); - } - ELSE - { - st->extl_fx = WB_TBE; - move16(); - st->extl_brate_fx = WB_TBE_1k05; - move32(); - } - } - ELSE IF( sub(st->core_fx,ACELP_CORE) == 0 && (sub(st->bwidth_fx,SWB) == 0 || sub(st->bwidth_fx,FB) == 0) && L_sub(st->total_brate_fx,ACELP_13k20) >= 0 ) - { - IF( L_sub(st->total_brate_fx,ACELP_48k) >=0 ) - { - st->extl_fx = SWB_BWE_HIGHRATE; - move16(); - if( sub(st->bwidth_fx,FB) == 0 ) - { - st->extl_fx = FB_BWE_HIGHRATE; - move16(); - } - - st->extl_brate_fx = SWB_BWE_16k; - move32(); - } - - /* read the SWB TBE/BWE selection bit */ - ELSE - { - tmp16 = get_next_indice_fx( st, 1 ); - IF( tmp16 ) - { - st->extl_fx = SWB_BWE; - move16(); - st->extl_brate_fx = SWB_BWE_1k6; - move32(); - } - ELSE - { - st->extl_fx = SWB_TBE; - move16(); - st->extl_brate_fx = SWB_TBE_1k6; - move32(); - if( L_sub(st->total_brate_fx,ACELP_24k40) >= 0 ) - { - st->extl_brate_fx = SWB_TBE_2k8; - move32(); - } - } - } - - /* set FB TBE and FB BWE extension layers */ - test(); - IF( sub(st->bwidth_fx,FB) == 0 && L_sub(st->total_brate_fx,ACELP_24k40) >= 0 ) - { - IF( sub(st->extl_fx,SWB_BWE) == 0 ) - { - st->extl_fx = FB_BWE; - move16(); - st->extl_brate_fx = FB_BWE_1k8; - move32(); - } - ELSE IF( sub(st->extl_fx,SWB_TBE) == 0 ) - { - st->extl_fx = FB_TBE; - move16(); - { - st->extl_brate_fx = FB_TBE_3k0; - move32(); - } - } - } - } - - /* set core bitrate */ - st->core_brate_fx = L_sub(st->total_brate_fx,st->extl_brate_fx); - - /*-----------------------------------------------------------------* - * Read HQ signalling bits from the bitstream - * Set HQ core type - *-----------------------------------------------------------------*/ - - - IF( sub(st->core_fx,HQ_CORE) == 0 ) - { - IF( sub(st->mdct_sw, MODE2) != 0 ) - { - /* skip the HQ/TCX core switching flag */ - get_next_indice_tmp_fx( st, 1 ); - } - - /* read ACELP->HQ core switching flag */ - *core_switching_flag = get_next_indice_fx( st, 1 ); - - IF( sub(*core_switching_flag,1) == 0 ) - { - st->last_L_frame_ori_fx = st->last_L_frame_fx; - move16(); - - /* read ACELP L_frame info */ - st->last_L_frame_fx = L_FRAME16k; - move16(); - tmp16 = get_next_indice_fx( st, 1 ); - if( tmp16 == 0 ) - { - st->last_L_frame_fx = L_FRAME; - move16(); - } - } - - IF( sub(st->mdct_sw, MODE2) != 0 ) - { - - /* read/set band-width (needed for different I/O sampling rate support) */ - IF( L_sub(st->total_brate_fx,ACELP_16k40) > 0 ) - { - tmp16 = get_next_indice_fx( st, 2 ); - - IF( tmp16 == 0 ) - { - st->bwidth_fx = NB; - move16(); - } - ELSE IF( sub(tmp16,1) == 0 ) - { - st->bwidth_fx = WB; - move16(); - } - ELSE IF( sub(tmp16,2) == 0 ) - { - st->bwidth_fx = SWB; - move16(); - } - ELSE - { - st->bwidth_fx = FB; - move16(); - } - } - } - - /* detect bit errors in signalling */ - test(); - test(); - test(); - test(); - IF( ( L_sub(st->total_brate_fx,ACELP_24k40) >= 0 && sub(st->bwidth_fx,NB) == 0 ) || - ( sub(st->core_fx,HQ_CORE) == 0 && L_sub(st->total_brate_fx,LRMDCT_CROSSOVER_POINT) <= 0 && sub(st->bwidth_fx,FB) == 0) - ) - { - st->bfi_fx = 1; - move16(); - - st->core_brate_fx = st->total_brate_fx; - move32(); - st->extl_fx = -1; - move16(); - st->extl_brate_fx = 0; - move32(); - IF( sub(st->last_core_fx,AMR_WB_CORE) == 0 ) - { - st->core_fx = ACELP_CORE; - move16(); - st->L_frame_fx = L_FRAME; - move16(); - st->codec_mode = MODE1; - move16(); - st->last_L_frame_fx = L_FRAME; - move16(); - - IF( L_sub(st->total_brate_fx,ACELP_16k40) >= 0 ) - { - st->total_brate_fx = ACELP_13k20; - move32(); - st->core_brate_fx = st->total_brate_fx; - move32(); - } - } - ELSE - { - /* make sure, we are in a valid configuration wrt to bandwidth */ - st->bwidth_fx = WB; - move16(); - } - } - - /* set HQ core type */ - *hq_core_type = NORMAL_HQ_CORE; - move16(); - - test(); - test(); - IF( (sub(st->bwidth_fx,SWB) == 0 || sub(st->bwidth_fx,WB) == 0) && L_sub(st->total_brate_fx,LRMDCT_CROSSOVER_POINT) <= 0 ) - { - *hq_core_type = LOW_RATE_HQ_CORE; - move16(); - } - ELSE IF( sub(st->bwidth_fx,NB) == 0 ) - { - *hq_core_type = LOW_RATE_HQ_CORE; - move16(); - } - } - - /*-----------------------------------------------------------------* - * Set ACELP frame lnegth - *-----------------------------------------------------------------*/ - - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - IF( L_sub(st->core_brate_fx,FRAME_NO_DATA) == 0 ) - { - /* prevent "L_frame" changes in CNG segments */ - st->L_frame_fx = st->last_L_frame_fx; - move16(); - } - ELSE IF( L_sub(st->core_brate_fx,SID_2k40) == 0 && sub(st->bwidth_fx,WB) == 0 && st->first_CNG_fx && sub(st->act_cnt2_fx,MIN_ACT_CNG_UPD) < 0 ) - { - /* prevent "L_frame" changes in SID frame after short segment of active frames */ - st->L_frame_fx = st->last_CNG_L_frame_fx; - move16(); - } - ELSE IF( ( L_sub(st->core_brate_fx,SID_2k40) == 0 && L_sub(st->total_brate_fx,ACELP_9k60) >= 0 && sub(st->bwidth_fx,WB) == 0 ) || - ( L_sub(st->total_brate_fx,ACELP_24k40) > 0 && L_sub(st->total_brate_fx,HQ_96k) < 0 ) || ( L_sub(st->total_brate_fx,ACELP_24k40) == 0 && sub(st->bwidth_fx,WB) >= 0 ) ) - { - st->L_frame_fx = L_FRAME16k; - move16(); - } - ELSE - { - st->L_frame_fx = L_FRAME; - move16(); - } - - st->nb_subfr = NB_SUBFR; - move16(); - if ( sub(st->L_frame_fx,L_FRAME16k) == 0) - { - st->nb_subfr = NB_SUBFR16k; - move16(); - } - - test(); - IF( L_sub(st->output_Fs_fx,8000) == 0 ) - { - st->extl_fx = -1; - move16(); - } - ELSE IF( L_sub(st->output_Fs_fx,16000) == 0 && sub(st->L_frame_fx,L_FRAME16k) == 0 ) - { - st->extl_fx = -1; - move16(); - st->extl_brate_fx = L_deposit_l(0); - } - - IF( st->ini_frame_fx == 0 ) - { - /* avoid switching of internal ACELP Fs in the very first frame */ - st->last_L_frame_fx = st->L_frame_fx; - move16(); - st->last_core_fx = st->core_fx; - move16(); - st->last_core_brate_fx = st->core_brate_fx; - move32(); - st->last_extl_fx = st->extl_fx; - move16(); - } - - return; -} diff --git a/src/libs/libevs/lib_dec/decoder.cpp b/src/libs/libevs/lib_dec/decoder.cpp deleted file mode 100755 index 179c903c..00000000 --- a/src/libs/libevs/lib_dec/decoder.cpp +++ /dev/null @@ -1,258 +0,0 @@ -/*==================================================================================== - EVS Codec 3GPP TS26.442 Apr 03, 2018. Version 12.11.0 / 13.6.0 / 14.2.0 - ====================================================================================*/ - -#include -#include -#include -#include -#include -#include "options.h" -#include "stl.h" -#include "stat_dec_fx.h" -#include "prot_fx.h" -#include "g192.h" -#include "disclaimer.h" - -#include "EvsRXlib.h" - -/*------------------------------------------------------------------------------------------* - * Global variables - *------------------------------------------------------------------------------------------*/ -long frame = 0; /* Counter of frames */ - - -int main(int argc, char *argv[]) -{ - Decoder_State_fx *st_fx; /* decoder state structure */ - Word16 zero_pad, dec_delay,output_frame; - FILE *f_stream; /* input bitstream file */ - FILE *f_synth; /* output synthesis file */ - UWord16 bit_stream[MAX_BITS_PER_FRAME+16]; - Word16 output[L_FRAME48k]; /* buffer for output synthesis */ -#ifdef SUPPORT_JBM_TRACEFILE - char *jbmTraceFileName = NULL; /* VOIP tracefile name */ -#endif - Word16 quietMode = 0; - Word16 noDelayCmp = 0; - char *jbmFECoffsetFileName = NULL; /* FEC offset file name */ - - - BASOP_init - - - - - /*------------------------------------------------------------------------------------------* - * Allocation of memory for static variables - * - I/O initializations - * - Decoder variables initialization - * - Find frame length - *------------------------------------------------------------------------------------------*/ - - if ( (st_fx = (Decoder_State_fx *) calloc(1, sizeof(Decoder_State_fx) ) ) == NULL ) - { - } - - /*------------------------------------------------------------------------------------------* - * I/O initializations - * Decoder variables initialization - *------------------------------------------------------------------------------------------*/ - - st_fx->bit_stream_fx = bit_stream; - - io_ini_dec_fx( argc, argv, &f_stream, &f_synth, - &quietMode, - &noDelayCmp, - st_fx, -#ifdef SUPPORT_JBM_TRACEFILE - &jbmTraceFileName, -#endif - &jbmFECoffsetFileName - ); - - /*output_frame = (short)(st_fx->output_Fs / 50);*/ - st_fx->output_frame_fx = extract_l(Mult_32_16(st_fx->output_Fs_fx , 0x0290)); - - srand((unsigned int)time(0)); - - reset_indices_dec_fx(st_fx); - - IF(st_fx->Opt_VOIP_fx) - { -#ifdef SUPPORT_JBM_TRACEFILE - IF( decodeVoip(st_fx, f_stream, f_synth, jbmTraceFileName, jbmFECoffsetFileName, quietMode ) != 0 ) -#else - IF( decodeVoip(st_fx, f_stream, f_synth, jbmFECoffsetFileName, quietMode ) != 0 ) -#endif - { - free( st_fx ); - fclose( f_synth ); - fclose( f_stream ); - return -1; - } - } - ELSE - { - /*------------------------------------------------------------------------------------------* - * Regular EVS decoder with ITU-T G.192 bitstream - *------------------------------------------------------------------------------------------*/ - - init_decoder_fx(st_fx); - - /* output frame length */ - output_frame = st_fx->output_frame_fx; - - if( noDelayCmp == 0) - { - /* calculate the compensation (decoded signal aligned with original signal) */ - /* the number of first output samples will be reduced by this amount */ - dec_delay = NS2SA_fx2(st_fx->output_Fs_fx, get_delay_fx(DEC, st_fx->output_Fs_fx)); - } - else - { - dec_delay = 0; - } - - zero_pad = dec_delay; - - /*------------------------------------------------------------------------------------------* - * Loop for every packet (frame) of bitstream data - * - Read the bitstream packet - * - Run the decoder - * - Write the synthesized signal into output file - *------------------------------------------------------------------------------------------*/ - if (quietMode == 0) - { - fprintf( stdout, "\n------ Running the decoder ------\n\n" ); - fprintf( stdout, "Frames processed: " ); - } - else { - fprintf( stdout, "\n-- Start the decoder (quiet mode) --\n\n" ); - } - BASOP_end_noprint; - BASOP_init; -#if (WMOPS) - Init_WMOPS_counter(); - Reset_WMOPS_counter(); - setFrameRate(48000, 960); -#endif - - /*----- loop: decode-a-frame -----*/ - WHILE( st_fx->bitstreamformat==G192 ? read_indices_fx( st_fx, f_stream, 0 ) : read_indices_mime( st_fx, f_stream, 0) ) - { -#if (WMOPS) - fwc(); - Reset_WMOPS_counter(); -#endif - - - SUB_WMOPS_INIT("evs_dec"); - - /* run the main encoding routine */ - IF(sub(st_fx->codec_mode, MODE1) == 0) - { - IF ( st_fx->Opt_AMR_WB_fx ) - { - amr_wb_dec_fx( output,st_fx); - } - ELSE - { - evs_dec_fx( st_fx, output, FRAMEMODE_NORMAL); - } - } - ELSE - { - IF(st_fx->bfi_fx == 0) - { - evs_dec_fx( st_fx, output, FRAMEMODE_NORMAL); - } - ELSE /* conceal */ - { - evs_dec_fx( st_fx, output, FRAMEMODE_MISSING); - } - } - - END_SUB_WMOPS; - - - - /* increase the counter of initialization frames */ - - if( sub(st_fx->ini_frame_fx,MAX_FRAME_COUNTER) < 0 ) - { - st_fx->ini_frame_fx = add(st_fx->ini_frame_fx,1); - } - - /* write the synthesized signal into output file */ - /* do final delay compensation */ - IF ( dec_delay == 0 ) - { - fwrite( output, sizeof(Word16), output_frame, f_synth ); - } - ELSE - { - IF ( sub(dec_delay , output_frame) <= 0 ) - { - fwrite( output +dec_delay, sizeof(Word16), sub(output_frame , dec_delay), f_synth ); - dec_delay = 0; - move16(); - } - ELSE - { - dec_delay = sub(dec_delay, output_frame); - } - } - - - frame++; - if (quietMode == 0) - { - fprintf( stdout, "%-8ld\b\b\b\b\b\b\b\b", frame); - } - } - - /*----- decode-a-frame-loop end -----*/ - - fflush( stderr ); - if (quietMode == 0) - { - fprintf( stdout, "\n\n" ); - printf("Decoding finished\n\n"); - } - else - { - printf("Decoding of %ld frames finished\n\n", frame); - } - fprintf( stdout, "\n\n" ); - fflush(stdout); - - - - fflush(stdout); - fflush(stderr); - - /* end of WMOPS counting */ -#if (WMOPS) - fwc(); - printf("\nDecoder complexity\n"); - WMOPS_output(0); - printf("\n"); -#endif - - /* add zeros at the end to have equal length of synthesized signals */ - set16_fx( output, 0, zero_pad ); - fwrite( output, sizeof(Word16), zero_pad, f_synth ); - BASOP_init - destroy_decoder( st_fx ); - BASOP_end_noprint - } - - /* free memory etc. */ - free( st_fx ); - fclose( f_synth ); - fclose( f_stream ); - - - return 0; -} diff --git a/src/libs/libevs/lib_dec/decoder.excluded b/src/libs/libevs/lib_dec/decoder.excluded new file mode 100644 index 00000000..3f65e968 --- /dev/null +++ b/src/libs/libevs/lib_dec/decoder.excluded @@ -0,0 +1,232 @@ +/*==================================================================================== + EVS Codec 3GPP TS26.443 Nov 13, 2018. Version 12.11.0 / 13.7.0 / 14.3.0 / 15.1.0 + ====================================================================================*/ + +#include +#include +#include +#include +#include +#include "options.h" +#include "prot.h" +#include "cnst.h" +#include "rom_com.h" +#include "g192.h" + +/*------------------------------------------------------------------------------------------* + * Global variables + *------------------------------------------------------------------------------------------*/ +long frame = 0; /* Counter of frames */ + + + + + +/*------------------------------------------------------------------------------------------* + * Main decoder function + *------------------------------------------------------------------------------------------*/ + +int main( int argc, char *argv[] ) +{ + FILE *f_stream; /* input bitstream file */ + FILE *f_synth; /* output synthesis file */ + Decoder_State *st; /* decoder state structure */ + short output_frame, dec_delay, zero_pad; + short quietMode = 0; + short noDelayCmp = 0; + float output[L_FRAME48k]; /* 'float' buffer for output synthesis */ + short data[L_FRAME48k]; /* 'short' buffer for output synthesis */ +#ifdef SUPPORT_JBM_TRACEFILE + char *jbmTraceFileName = NULL; /* VOIP tracefile name */ +#endif + char *jbmFECoffsetFileName = NULL; /* VOIP tracefile name */ + + + + + + /*------------------------------------------------------------------------------------------* + * Allocate memory for static variables + * Processing of command-line parameters + * Decoder initialization + *------------------------------------------------------------------------------------------*/ + + if ( (st = (Decoder_State *) malloc( sizeof(Decoder_State) ) ) == NULL ) + { + fprintf(stderr, "Can not allocate memory for decoder state structure\n"); + exit(-1); + } + /* set to NULL, to avoid reading of uninitialized memory in case of early abort */ + st->cldfbAna = st->cldfbBPF = st->cldfbSyn = NULL; + st->hFdCngDec = NULL; + + io_ini_dec( argc, argv, &f_stream, &f_synth, + &quietMode, &noDelayCmp, st, +#ifdef SUPPORT_JBM_TRACEFILE + &jbmTraceFileName, +#endif + &jbmFECoffsetFileName + ); + + /*------------------------------------------------------------------------------------------* + * VOIP client + *------------------------------------------------------------------------------------------*/ + + if( st->Opt_VOIP ) + { + if( decodeVoip( st, f_stream, f_synth, +#ifdef SUPPORT_JBM_TRACEFILE + jbmTraceFileName, +#endif + jbmFECoffsetFileName, + quietMode + ) != 0 ) + { + free( st ); + fclose( f_synth ); + fclose( f_stream ); + return -1; + } + } + + /*------------------------------------------------------------------------------------------* + * Regular EVS decoder with ITU-T G.192 bitstream + *------------------------------------------------------------------------------------------*/ + + else + { + /*------------------------------------------------------------------------------------------* + * Allocate memory for static variables + * Decoder initialization + *------------------------------------------------------------------------------------------*/ + + init_decoder( st ); + reset_indices_dec( st ); + + srand( (unsigned int) time(0) ); + + /* output frame length */ + output_frame = (short)(st->output_Fs / 50); + + if( noDelayCmp == 0 ) + { + /* calculate the delay compensation to have the decoded signal aligned with the original input signal */ + /* the number of first output samples will be reduced by this amount */ + dec_delay = NS2SA(st->output_Fs, get_delay(DEC, st->output_Fs) + 0.5f); + } + else + { + dec_delay = 0; + } + zero_pad = dec_delay; + + /*------------------------------------------------------------------------------------------* + * Loop for every packet (frame) of bitstream data + * - Read the bitstream packet + * - Run the decoder + * - Write the synthesized signal into output file + *------------------------------------------------------------------------------------------*/ + + if( quietMode == 0 ) + { + fprintf( stdout, "\n------ Running the decoder ------\n\n" ); + fprintf( stdout, "Frames processed: " ); + } + else + { + fprintf( stdout, "\n-- Start the decoder (quiet mode) --\n\n" ); + } + + + + while( st->bitstreamformat==G192 ? read_indices( st, f_stream, 0 ) : read_indices_mime( st, f_stream, 0) ) + { + /* run the main decoding routine */ + if ( st->codec_mode == MODE1 ) + { + if ( st->Opt_AMR_WB ) + { + amr_wb_dec( st, output ); + } + else + { + evs_dec( st, output, FRAMEMODE_NORMAL ); + } + } + else + { + if( !st->bfi ) + { + evs_dec( st, output, FRAMEMODE_NORMAL ); + } + else + { + evs_dec( st, output, FRAMEMODE_MISSING ); + } + } + + /* convert 'float' output data to 'short' */ + syn_output( output, output_frame, data ); + /* increase the counter of initialization frames */ + if( st->ini_frame < MAX_FRAME_COUNTER ) + { + st->ini_frame++; + } + + /* write the synthesized signal into output file */ + /* do final delay compensation */ + if ( dec_delay == 0 ) + { + fwrite( data, sizeof(short), output_frame, f_synth ); + } + else + { + if ( dec_delay <= output_frame ) + { + fwrite( &data[dec_delay], sizeof(short), output_frame - dec_delay, f_synth ); + dec_delay = 0; + } + else + { + dec_delay -= output_frame; + } + } + + frame++; + if( quietMode == 0 ) + { + fprintf( stdout, "%-8ld\b\b\b\b\b\b\b\b", frame ); + } + + + + } + + + fflush( stderr ); + if (quietMode == 0) + { + fprintf( stdout, "\n\n" ); + fprintf(stdout, "Decoding finished\n\n"); + } + else + { + fprintf(stdout, "Decoding of %ld frames finished\n\n", frame); + } + fprintf( stdout, "\n\n" ); + + + /* add zeros at the end to have equal length of synthesized signals */ + set_s( data, 0, zero_pad ); + fwrite( data, sizeof(short), zero_pad, f_synth ); + destroy_decoder( st ); + } + + free( st ); + + fclose( f_synth ); + fclose( f_stream ); + + return 0; +} + diff --git a/src/libs/libevs/lib_dec/dlpc_avq.cpp b/src/libs/libevs/lib_dec/dlpc_avq.cpp old mode 100755 new mode 100644 index 127651db..f6e666b6 --- a/src/libs/libevs/lib_dec/dlpc_avq.cpp +++ b/src/libs/libevs/lib_dec/dlpc_avq.cpp @@ -1,274 +1,246 @@ /*==================================================================================== - EVS Codec 3GPP TS26.442 Apr 03, 2018. Version 12.11.0 / 13.6.0 / 14.2.0 + EVS Codec 3GPP TS26.443 Nov 13, 2018. Version 12.11.0 / 13.7.0 / 14.3.0 / 15.1.0 ====================================================================================*/ - -/* Header files */ #include +#include "prot.h" #include #include -#include "stl.h" -#include "prot_fx.h" -/* Constants */ -#define M 16 /* length of LPC */ -#define BFI_FAC 29491/*0.9f Q15*/ +/*------------------------------------------------------------------* +* dlpc_avq() +* +* Variable bit-rate multiple LPC un-quantizer +*------------------------------------------------------------------*/ -/***********************************************/ -/* Variable bit-rate multiple LPC un-quantizer */ -/***********************************************/ - -Word16 dlpc_avq( - Word16 *index, /* (i) Quantization indices */ - Word16 *LSF_Q, /* (o) Quantized LSF vectors */ - Word16 numlpc, /* (i) Number of sets of lpc */ - Word32 sr_core +int dlpc_avq( + int *index, /* (i) Quantization indices */ + float *LSF_Q, /* (o) Quantized LSF vectors */ + int numlpc, /* (i) Number of sets of lpc */ + float sr_core ) { - Word16 i, nbi, last; - Word16 *p_index, q_type; - + int i, nbi, last; + int *p_index, q_type; /* Last LPC index */ - move16(); - last = 0; - if ( sub(numlpc,1)!=0 ) + if ( numlpc==1 ) + { + last = 0; + } + else { - move16(); last = M; } - move16(); p_index = index; /* Decode last LPC */ - - FOR (i=0; inext_bit_pos_fx; + start_bit_pos = st->next_bit_pos; /* Index bits */ - - move16(); *ind = 0; - WHILE ((get_next_indice_1_fx(st) != 0) && !st->BER_detect) + + while (get_next_indice_1(st) && !st->BER_detect) { - move16(); - *ind = add(*ind,1); + *ind += 1; } if (*ind != 0) { - move16(); - *ind = add(*ind, 1); + *ind += 1; } - return sub(st->next_bit_pos_fx, start_bit_pos); + return st->next_bit_pos - start_bit_pos; } -static Word16 pack4bits(Word16 nbits, Decoder_State_fx *st, Word16 *prm) + +/*------------------------------------------------------------------* +* pack4bits() +* +* +*------------------------------------------------------------------*/ + +static int pack4bits( + int nbits, + Decoder_State *st, + int *prm +) { - Word16 i; + int i; - - move16(); i=0; - FOR ( ; nbits > 4; nbits -= 4 ) + while (nbits > 4) { - move16(); - prm[i] = get_next_indice_fx(st, 4); - i = add(i,1); - - + prm[i] = get_next_indice(st, 4); + nbits -= 4; + i++; } - prm[i] = get_next_indice_fx(st, nbits); - move16(); - i = add(i,1); + prm[i] = get_next_indice(st, nbits); + i++; return(i); } -Word16 decode_lpc_avq( Decoder_State_fx *st, Word16 numlpc, Word16 *param_lpc ) + +/*------------------------------------------------------------------* +* decode_lpc_avq() +* +* +*------------------------------------------------------------------*/ + +int decode_lpc_avq( + Decoder_State *st, + int numlpc, + int *param_lpc +) { - Word16 k,j; - Word16 nb, qn1, qn2, avqBits, q_type; - Word16 start_bit_pos; + int k,j; + int nb, qn1, qn2, avqBits, q_type; + int start_bit_pos; + - move16(); - move16(); j = 0; - start_bit_pos = st->next_bit_pos_fx; + start_bit_pos = st->next_bit_pos; - FOR (k=0; k 0 ) + if (qn1 > 4) { nb = unary_decode(st, &qn1); - if ( sub(nb,1) == 0 ) - { - qn1 = add(qn1, 5); - } - if (sub(nb,2) == 0) - { - qn1 = add(qn1, 4); - } - if ( sub(nb,3) == 0 ) - { - move16(); - qn1 = 0; - } - if ( sub(nb,3) > 0 ) - { - qn1 = add(qn1, 3); - } + if (nb == 1) qn1 += 5; + else if (nb == 2) qn1 += 4; + else if (nb == 3) qn1 = 0; + else qn1 += 3; } - IF ( sub(qn2,4) > 0 ) + if (qn2 > 4) { nb = unary_decode(st, &qn2); - if ( sub(nb,1) == 0 ) - { - qn2 = add(qn2, 5); - } - if (sub(nb,2) == 0) - { - qn2 = add(qn2, 4); - } - if ( sub(nb,3) == 0 ) - { - move16(); - qn2 = 0; - } - if ( sub(nb,3) > 0 ) - { - qn2 = add(qn2, 3); - } + if (nb == 1) qn2 += 5; + else if (nb == 2) qn2 += 4; + else if (nb == 3) qn2 = 0; + else qn2 += 3; } /* check for potential bit errors */ - test(); - IF( (sub(qn1, NB_SPHERE) > 0) || (sub(qn2, NB_SPHERE) > 0) ) + if( qn1 > NB_SPHERE || qn2 > NB_SPHERE ) { qn1 = 0; - move16(); qn2 = 0; - move16(); st->BER_detect = 1; - move16(); } - move16(); param_lpc[j] = qn1; - j = add(j, 1); - move16(); + j++; param_lpc[j] = qn2; - j = add(j, 1); + j++; /* Decode Split-by-2 algebraic VQ */ - avqBits = shl(qn1,2); - + avqBits = 4*qn1; pack4bits(avqBits, st, ¶m_lpc[j]); - j = add(j, qn1); + j += qn1; - avqBits = shl(qn2,2); + avqBits = 4*qn2; pack4bits(avqBits, st, ¶m_lpc[j]); - j = add(j, qn2); + j += qn2; } - return sub(st->next_bit_pos_fx, start_bit_pos); + return st->next_bit_pos - start_bit_pos; } diff --git a/src/libs/libevs/lib_dec/dlpc_stoch.cpp b/src/libs/libevs/lib_dec/dlpc_stoch.cpp old mode 100755 new mode 100644 index 8e2e7385..548050d3 --- a/src/libs/libevs/lib_dec/dlpc_stoch.cpp +++ b/src/libs/libevs/lib_dec/dlpc_stoch.cpp @@ -1,121 +1,105 @@ /*==================================================================================== - EVS Codec 3GPP TS26.442 Apr 03, 2018. Version 12.11.0 / 13.6.0 / 14.2.0 + EVS Codec 3GPP TS26.443 Nov 13, 2018. Version 12.11.0 / 13.7.0 / 14.3.0 / 15.1.0 ====================================================================================*/ - -/* Header files */ #include #include #include -#include "stl.h" -#include "basop_util.h" -#include "prot_fx.h" - -/* Constants */ -#define M 16 - -#define BFI_FAC 0.9f +#include "options.h" +#include "prot.h" +#include "rom_com.h" +#include "basop_proto_func.h" +/*------------------------------------------------------------------* +* lpc_unquantize() +* +* +*------------------------------------------------------------------*/ void lpc_unquantize( - Decoder_State_fx * st, - Word16 *lsfold, - Word16 *lspold, - Word16 *lsf, - Word16 *lsp, - const Word16 m, - const Word16 lpcQuantization, - Word16 *param_lpc, - const Word16 numlpc, - const Word16 core, - Word16 *mem_MA, - Word16 * mem_AR, - Word16 *lspmid, - Word16 *lsfmid, - Word16 coder_type, - Word16 acelp_midLpc, - Word8 narrow_band, - Word16 *seed_acelp, - Word32 sr_core, - Word16 *mid_lsf_int, - Word16 prev_bfi, - Word16 *LSF_Q_prediction, /* o : LSF prediction mode */ - Word16 *safety_net + Decoder_State * st, + float *lsfold, + float *lspold, + float *lsf, + float *lsp, + int lpcQuantization, + int *param_lpc, + int numlpc, + int core, + float *mem_MA, + float *lspmid, + float *lsfmid, + short coder_type, + int acelp_midLpc, + int narrow_band, + short *seed_acelp, + int sr_core, + short *mid_lsf_int, + short prev_bfi, + short *LSF_Q_prediction, /* o : LSF prediction mode */ + short *safety_net ) { - Word16 nb_indices, k; - Word16 i; + int nb_indices=0, k; - nb_indices = 0; /* to avoid compilation warnings */ + mvr2r(lsfold, &lsf[0], M); + mvr2r(lspold, &lsp[0], M); - - Copy(lsfold, &lsf[0], m); - Copy(lspold, &lsp[0], m); - - IF( lpcQuantization == 0 ) + if( lpcQuantization == 0 ) { - nb_indices = dlpc_avq(param_lpc, &lsf[m], numlpc, st->sr_core); - FOR ( k=0; kbwidth */ , 31, &lsf[m], mem_AR, mem_MA, sr_core, st->core_brate_fx, - &st->offset_scale1_fx[0][0], &st->offset_scale2_fx[0][0], &st->offset_scale1_p_fx[0][0], &st->offset_scale2_p_fx[0][0], - &st->no_scales_fx[0][0], &st->no_scales_p_fx[0][0], &st->safety_net_fx, param_lpc, LSF_Q_prediction, &nb_indices ); + lsf_end_dec( st, GENERIC, 1-narrow_band /* st->bwidth */ , ENDLSF_NBITS, &lsf[M], st->mem_AR, mem_MA, sr_core, st->core_brate, + &st->offset_scale1[0][0], &st->offset_scale2[0][0], &st->offset_scale1_p[0][0], &st->offset_scale2_p[0][0], + &st->no_scales[0][0], &st->no_scales_p[0][0], &st->safety_net, param_lpc, LSF_Q_prediction, &nb_indices); } - ELSE + else { - IF (sub(st->core_fx, TCX_20_CORE)==0) + if (st->core == TCX_20_CORE) { - lsf_end_dec_fx( st, 1, AUDIO, sub(1, narrow_band) /* st->bwidth */ , 31, &lsf[m], mem_AR, mem_MA, sr_core, st->core_brate_fx, - &st->offset_scale1_fx[0][0], &st->offset_scale2_fx[0][0], &st->offset_scale1_p_fx[0][0], &st->offset_scale2_p_fx[0][0], - &st->no_scales_fx[0][0], &st->no_scales_p_fx[0][0], &st->safety_net_fx, param_lpc, LSF_Q_prediction, &nb_indices); + lsf_end_dec( st, AUDIO, 1-narrow_band /* st->bwidth */ , ENDLSF_NBITS, &lsf[M], st->mem_AR, mem_MA, sr_core, st->core_brate, + &st->offset_scale1[0][0], &st->offset_scale2[0][0], &st->offset_scale1_p[0][0], &st->offset_scale2_p[0][0], + &st->no_scales[0][0], &st->no_scales_p[0][0], &st->safety_net, param_lpc, LSF_Q_prediction, &nb_indices); } - ELSE + else { - lsf_end_dec_fx( st, 1, coder_type, sub(1, narrow_band) /* st->bwidth */ , 31, &lsf[m], mem_AR, mem_MA, sr_core, st->core_brate_fx, - &st->offset_scale1_fx[0][0], &st->offset_scale2_fx[0][0], &st->offset_scale1_p_fx[0][0], &st->offset_scale2_p_fx[0][0], - &st->no_scales_fx[0][0], &st->no_scales_p_fx[0][0], &st->safety_net_fx, param_lpc, LSF_Q_prediction, &nb_indices); + lsf_end_dec( st, coder_type, 1-narrow_band /* st->bwidth */ , 31, &lsf[M], st->mem_AR, mem_MA, sr_core, st->core_brate, + &st->offset_scale1[0][0], &st->offset_scale2[0][0], &st->offset_scale1_p[0][0], &st->offset_scale2_p[0][0], + &st->no_scales[0][0], &st->no_scales_p[0][0], &st->safety_net, param_lpc, LSF_Q_prediction, &nb_indices); } } - lsf2lsp_fx(&lsf[m], &lsp[m], M, sr_core); + lsf2lsp(&lsf[M], &lsp[M], M, sr_core); } - ELSE + else { assert(0); } *seed_acelp=0; - move16(); - FOR(i=nb_indices-1; i>=0; i--) + for(k=nb_indices-1; k>=0; k--) { - *seed_acelp = extract_l(L_mac0(L_mac0(13849, shr(*seed_acelp, 1), 31821), param_lpc[i], 31821)); + /* rightshift before *seed_acelp+param_lpc[i] to avoid overflows*/ + *seed_acelp=(short)((((*seed_acelp)>>1)+param_lpc[k]) * 31821L + 13849L); } - /* Decoded mid-frame isf */ - test(); - test(); - test(); - IF ( lpcQuantization && acelp_midLpc && core==ACELP_CORE && st->rate_switching_reset==0) + /* Decoded mid-frame lsf */ + if( lpcQuantization && acelp_midLpc && core == ACELP_CORE && st->rate_switching_reset == 0 ) { - midlsf_dec ( &lsf[0], &lsf[m], param_lpc[nb_indices], lsfmid - ,coder_type - ,mid_lsf_int, - prev_bfi, - *safety_net - ); - reorder_lsf_fx( lsfmid, LSF_GAP_MID_FX, M, sr_core ); - lsf2lsp_fx(lsfmid, lspmid, M, sr_core); + midlsf_dec( &lsf[0], &lsf[M], (short)param_lpc[nb_indices], lsfmid, M, coder_type, mid_lsf_int, prev_bfi, *safety_net ); + + reorder_lsf( lsfmid, LSF_GAP_MID, M, sr_core ); + lsf2lsp( lsfmid, lspmid, M, sr_core ); } return; } - diff --git a/src/libs/libevs/lib_dec/er_dec_acelp.cpp b/src/libs/libevs/lib_dec/er_dec_acelp.cpp old mode 100755 new mode 100644 index 14fde430..4fe464e9 --- a/src/libs/libevs/lib_dec/er_dec_acelp.cpp +++ b/src/libs/libevs/lib_dec/er_dec_acelp.cpp @@ -1,190 +1,141 @@ /*==================================================================================== - EVS Codec 3GPP TS26.442 Apr 03, 2018. Version 12.11.0 / 13.6.0 / 14.2.0 + EVS Codec 3GPP TS26.443 Nov 13, 2018. Version 12.11.0 / 13.7.0 / 14.3.0 / 15.1.0 ====================================================================================*/ -/*VERSIONINFO: File up to date with trunk rev. 39929*/ - - #include #include +#include #include -#include "prot_fx.h" -#include "basop_util.h" -#include "rom_dec_fx.h" +#include "prot.h" #include "options.h" -#include "stl.h" - -extern const Word16 T_DIV_L_Frame[];/*0Q15 * 2^-7 */ - -/*Table 2^7 * 1/L_frame */ - -#define L_SYN_BUF M+L_DIV_MAX+L_DIV_MAX -#define L_EXC_BUF OLD_EXC_SIZE_DEC_16k+L_DIV_MAX+L_SUBFR+1+L_DIV_MAX/2 - -/*LOCAL FUNCTIONS*/ -static void memsynPrecission(Word16 nbLostCmpt,Word16* mem_syn, Word16* exc, Word16 len, Word16*s_16); - -/*************************************************************** - * \brief Main concealment function for ACELP - * - * -****************************************************************/ +/*-------------------------------------------------------------------* +* con_acelp() +* +* Concealment function for ACELP and TD-TCX +*--------------------------------------------------------------------*/ void con_acelp( - const Word16 A[], /*mem_syn >rescaling done */ - Word16 *pitch_buffer, - Word16 *voice_factors, - Word16 *bwe_exc + float A[], /* input: coefficients NxAz[M+1] */ + int coder_type, /* input: ACELP coder type */ + float synth[], /* i/o: synthesis */ + int *pT, /* out: pitch for all subframe */ + float *pgainT, /* out: pitch gain for all subfr */ + float stab_fac, /* input: stability of isf */ + Decoder_State *st, /* i/o : coder memory state */ + float pitch_buffer[], /* i/o: floating pitch values for each subframe */ + float *voice_factors, /* o : voicing factors */ + float *bwe_exc /* o : excitation for SWB TBE */ ) { + int i, i_subfr, L_frame, T0; + float tmp_deemph; + float mem_syn[M], mem_syn2[M], mem[M], *syn; + float *noise_buf; + float *exc, *harmonic_exc_buf, buf[L_EXC_MEM_DEC+M+L_FRAME16k+L_FRAME16k/2], *p_A; + float pitch_buf[NB_SUBFR16k]; + float alpha = 0.0f; + float step, gain, gainCNG, gain_inov, ftmp; + float *pt_exc,tmp_tc,predPitchLag; + float pc = 0.f; + short extrapolationFailed,tmpSeed,Tc; + float *pt1_exc; + float *w = st->tcx_cfg.tcx_mdct_window; + int W1, W2, j; + int l_fir_fer = L_FIR_FER; + float lpFiltAdapt[3]; + float hp_filt[3]; + int nSubframes; + float exc_unv[L_FRAME16k+L_FRAME16k/2]; + float syn_unv[L_FRAME16k+L_FRAME16k/2]; + float mem_syn_unv[M]; + float gain_lpc[NB_SUBFR16k]; + float h1[L_SUBFR+1]; + float gainSynthDeemph; + float tmp = 0.f; + int fUseExtrapolatedPitch; - Word16 i_subfr, i, T0; /*Q0*/ - Word16 tmp, tmp2, tmp_deemph; - Word16 mem_syn[M], mem_syn2[M], *syn; - Word16 *noise_buf; - Word16 *exc, *harmonic_exc_buf, buf[L_EXC_MEM_DEC+M+L_FRAME_16k+L_FRAME_16k/2]; /*Qf_exc*/ - const Word16 *p_A; - Word32 pitch_buf[NB_SUBFR16k] /*15Q16*/; - Word16 alpha; /*Q14*/ - Word16 step, gain, gainCNG,ftmp; - Word16 *pt_exc; - Word16 gain_inov; - Word16 gainCNG_e ; /*scaling Factor (exponent) of gainCNG*/ - Word16 Qf_syn; /*Q format and exponent of new synthesis*/ - Word16 *pt1_exc; - Word32 tmp_tc; /*15Q16*/ - Word16 extrapolationFailed; - Word32 predPitchLag; /*15Q16*/ - Word32 pc; /*float 15Q16*/ - Word16 fUseExtrapolatedPitch;/*int*/ - Word16 tmpSeed, Tc; /*Q0*/ - Word16 s_32; - Word16 synthScaling; - PWord16 const *w = st->tcx_cfg.tcx_mdct_window; - Word16 W1, W2; - Word16 nSubframes; - Word16 s_16, s_gain_inov, s2; - Word16 tmp_16, gain_16; - Word32 tmp_32, gain_32, step_32; - Word16 l_fir_fer; - Word16 lpFiltAdapt[3]; - Word16 hp_filt[3]; - Word16 Qf_syn_new; - Word16 exc_unv[L_FRAME_16k+L_FRAME_16k/2]; - Word16 syn_unv[L_FRAME_16k+L_FRAME_16k/2]; - Word16 mem_syn_unv[M]; - Word16 gain_lpc[NB_SUBFR16k]; - Word16 gain_lpc_e[NB_SUBFR16k]; - Word16 mem[M]; - Word16 h1[L_FRAME_16k/4+1]; - Word16 gainSynthDeemph; - Word16 gainSynthDeemph_e; - Word16 l; - Word16 g, g_e; - Word16 n; - const Word16 scale_h1 = 5; + /* Framing parameters */ - /*Inits*/ - move16(); - l_fir_fer = L_FIR_FER; + L_frame = st->L_frame; fUseExtrapolatedPitch = 0; - move16(); extrapolationFailed = 1; - move16(); - - move16(); - move16(); - move16(); - alpha = 0; - /*st->Mode2_lp_gainc = L_shl(st->Mode2_lp_gainc,7);*/ /*rudiment, could be changed in the whole file but should work also*/ - pc=L_deposit_l(0); /*------------------------------------------------------------------------* * Initialize buffers * *------------------------------------------------------------------------*/ /* set ACELP synthesis memory */ - Copy( st->mem_syn2_fx, mem_syn, M); + mvr2r( st->mem_syn2, mem_syn, M); /* set excitation memory*/ harmonic_exc_buf = buf+M; exc = harmonic_exc_buf+L_EXC_MEM_DEC; - Copy( st->old_exc_fx, harmonic_exc_buf, L_EXC_MEM_DEC); - exc[st->L_frame_fx] = 0; - move16(); + mvr2r(st->old_exc, harmonic_exc_buf, L_EXC_MEM_DEC); + exc[L_frame] = 0.0f; /*------------------------------------------------------------------------* * PLC: [ACELP:Extrapolate Pitch Lag] *------------------------------------------------------------------------*/ - if (sub(st->flagGuidedAcelp, 1) == 0) + if (st->flagGuidedAcelp == 1) { T0 = st->guidedT0; - move16(); } - pitch_pred_linear_fit(st->nbLostCmpt, st->last_good_fx, - st->old_pitch_buf_fx, - &st->old_fpitch, - &predPitchLag, st->pit_min, st->pit_max, st->mem_pitch_gain, 0, - st->plc_use_future_lag, &extrapolationFailed, st->nb_subfr); - T0 = round_fx(predPitchLag); + pitch_pred_linear_fit( st->nbLostCmpt, st->last_good, st->old_pitch_buf, &st->old_fpitch, + &predPitchLag, st->pit_min, st->pit_max, st->mem_pitch_gain, 0, + st->plc_use_future_lag, &extrapolationFailed, st->nb_subfr ); + T0 = (int)(predPitchLag+0.5f); - IF (extrapolationFailed != 0) + if( extrapolationFailed ) { /*------------------------------------------------------------------------* * - Construct adaptive codebook from side information * *------------------------------------------------------------------------*/ - IF (st->flagGuidedAcelp == 0) + if( st->flagGuidedAcelp == 0) { nSubframes = 0; - move16(); } - ELSE + else { nSubframes = 2; - move16(); /* Construct adaptive codebook with T0, T0_frac, T0_res, gain_pit for 2 sub-frames */ - l = shl(L_SUBFR,1); - FOR (i = 0; i < l; i++) + for( i=0; i<2*L_SUBFR; i++ ) { - exc[i] = exc[sub(i,st->guidedT0)]; - move16(); + exc[i] = exc[i-st->guidedT0]; } } } - ELSE + else { nSubframes = 0; - move16(); } - tmp_tc = st->old_fpitch; - move16(); /* take the previous frame last pitch*/ + if( nSubframes > 0 ) { - tmp_tc = L_deposit_h(st->guidedT0); /* take the transmit pitch*/ + tmp_tc = (float)st->guidedT0; /* take the transmit pitch*/ + } + else + { + tmp_tc = st->old_fpitch; /* take the previous frame last pitch*/ } /* PLC: [ACELP: Fade-out] * PLC: calculate damping factor */ - alpha = Damping_fact(coder_type, st->nbLostCmpt, st->last_good_fx, stab_fac, &(st->Mode2_lp_gainp), 0); /*Q14*/ - st->cummulative_damping = shl(mult(st->cummulative_damping,alpha),1);/*shl(Q15*Q14,1)=shl(Q14,1) = Q15*/ - if (sub(st->nbLostCmpt,1)==0) + alpha = Damping_fact(coder_type, st->nbLostCmpt, st->last_good, stab_fac, &(st->lp_gainp), 0); + + if (st->nbLostCmpt==1) { - st->cummulative_damping = 32767/*1.f Q15*/; /*Q15*/ + st->cummulative_damping = 1.0f; + } + else + { + st->cummulative_damping *= alpha; } /*-----------------------------------------------------------------* @@ -192,74 +143,54 @@ void con_acelp( * PLC: Construct the harmonic part of excitation *-----------------------------------------------------------------*/ - IF( sub(st->last_good_fx , UNVOICED_TRANSITION ) >= 0) + if( st->last_good >= UNVOICED_TRANSITION ) { /*---------------------------------------------------------------* * Last pitch cycle of the previous frame is repeatedly copied. * *---------------------------------------------------------------*/ - Tc = round_fx(tmp_tc); - BASOP_SATURATE_WARNING_OFF /*if this ever saturates, it doesn't matter*/ - tmp = sub(shl(abs_s(sub(T0,Tc)),6) , mult(19661/*0.15f Q17*/,shl(Tc,4)) /*Q6*/); - BASOP_SATURATE_WARNING_ON - test(); - test(); - test(); - if ((T0 > 0) && (sub(T0 , Tc) != 0 ) - && ( tmp < 0 ) - && extrapolationFailed == 0 ) + Tc = (short)(tmp_tc + 0.5f); + + if ((T0 > 0) && (T0 != Tc) && (abs(T0-Tc) < 0.15f*Tc) && extrapolationFailed == 0 ) { fUseExtrapolatedPitch = 1; - move16(); } - pt_exc = exc; - if (st->enableGplc != 0) + if(st->enableGplc) { pt_exc = &exc[nSubframes*L_SUBFR]; } + else + { + pt_exc = exc; + } pt1_exc = pt_exc - Tc; - IF (fUseExtrapolatedPitch != 0) + if (fUseExtrapolatedPitch != 0) { /* Required because later pt1_exc[1] used in filtering points to exc[0]. To make it safe also for GPL pt_exc is used instead of exc */ pt_exc[0] = 0; - move16(); pt_exc = harmonic_exc_buf; assert(pt_exc < pt1_exc-1); } - IF (sub(st->nbLostCmpt, 1) == 0) + if( st->nbLostCmpt == 1 ) { /* pitch cycle is first low-pass filtered */ - /*get filter coefficients*/ - genPlcFiltBWAdap( - st->sr_core, /*W32 Q0*/ - &lpFiltAdapt[0] /*Q15*/, - 0, - st->cummulative_damping /*Q15*/ - ); - FOR( i=0 ; i< Tc; i++ ) + genPlcFiltBWAdap(st->sr_core, &lpFiltAdapt[0], 0, st->cummulative_damping); + for( i=0 ; i< Tc; i++ ) { - - /* *pt_exc++ = ( lpFiltAdapt[0] * pt1_exc[-1] + lpFiltAdapt[1] * pt1_exc[0] + lpFiltAdapt[2] * pt1_exc[1]);*/ - tmp_32 = L_mult( lpFiltAdapt[0] , pt1_exc[-1]) ; - tmp_32 = L_mac(tmp_32, lpFiltAdapt[1] , pt1_exc[0]) ; - tmp_16 = mac_r(tmp_32, lpFiltAdapt[2] , pt1_exc[1]); - move16(); - *pt_exc = tmp_16; - pt_exc++; + *pt_exc++ = ( lpFiltAdapt[0] * pt1_exc[-1] + lpFiltAdapt[1] * pt1_exc[0] + lpFiltAdapt[2] * pt1_exc[1]); pt1_exc++; } } - ELSE + else { /* copy the first pitch cycle without low-pass filtering */ - FOR( i=0 ; i< Tc; i++ ) + for( i=0 ; i< Tc; i++ ) { - move16(); *pt_exc++ = *pt1_exc++; } } @@ -269,10 +200,8 @@ void con_acelp( pt1_exc = harmonic_exc_buf; } - l = add(st->L_frame_fx,sub(imult1616(L_SUBFR,sub(1,nSubframes)),Tc)); - FOR( i= 0; i < l; i++ ) + for (i = 0; i < L_frame+(1-nSubframes)*L_SUBFR-Tc; i++) { - move16(); *pt_exc++ = *pt1_exc++; } @@ -281,36 +210,32 @@ void con_acelp( * PLC: Resync pulse positions. *-------------------------------------------------------*/ - IF( nSubframes > 0 ) + if( nSubframes > 0 ) { - move16(); - move16(); - pitch_buf[0] = L_deposit_h(st->guidedT0); - pitch_buf[1] = L_deposit_h(st->guidedT0); + pitch_buf[0] = (float)st->guidedT0; + pitch_buf[1] = (float)st->guidedT0; } - IF (nSubframes>0) + if (nSubframes>0) { - move16(); - move16(); pitch_buf[3] = pitch_buf[2] = pitch_buf[1]; /* do not resync on second half of frame */ - if (sub(st->nb_subfr, 5) == 0) + if(st->nb_subfr == 5) { - /* for guided acelp cases and nSubframes=2, set pitch_buf[4] to avoid memory_access issues in post_decoder() */ + /* for guidedacelp cases and nSubframes=2, set pitch_buf[4] to avoid memory_access issues in post_decoder() */ pitch_buf[4] = pitch_buf[3]; - move16(); } } - ELSE + else { - IF (fUseExtrapolatedPitch != 0) + if (fUseExtrapolatedPitch != 0) { - get_subframe_pitch(st->nb_subfr, st->old_fpitch, predPitchLag, pitch_buf); - PulseResynchronization(harmonic_exc_buf, exc, st->L_frame_fx, st->nb_subfr, st->old_fpitch, predPitchLag); + + PulseResynchronization(harmonic_exc_buf, exc, L_frame, st->nb_subfr, st->old_fpitch, predPitchLag); } - ELSE { - set32_fx(pitch_buf, st->old_fpitch, st->nb_subfr); + else + { + set_f( pitch_buf, st->old_fpitch, st->nb_subfr); } } @@ -318,17 +243,13 @@ void con_acelp( * PLC: [ACELP: adaptive codebook] * PLC: Create the harmonic part needed for the overlap-add. *------------------------------------------------------------*/ - pt_exc = exc+st->L_frame_fx; - pt1_exc = pt_exc - T0; - if (T0 == 0) - { - pt1_exc = pt_exc - Tc; - } - l = shr(st->L_frame_fx, 1); - FOR (i = 0; i < l; i++) + + pt_exc = exc+L_frame; + pt1_exc = pt_exc - ((T0 == 0) ? Tc : T0); + + for (i = 0; i < L_frame/2; i++) { *pt_exc++ = *pt1_exc++; - move16(); } /*-------------------------------------------------------* @@ -336,13 +257,16 @@ void con_acelp( * PLC: update the floating point pitch for consecutive loss *-------------------------------------------------------*/ - IF (fUseExtrapolatedPitch != 0) + if (fUseExtrapolatedPitch != 0) { - move32(); - st->old_fpitch = predPitchLag; - if (sub(st->flagGuidedAcelp ,1) == 0) + + if (st->flagGuidedAcelp == 1) { - st->old_fpitch = L_deposit_h(T0); + st->old_fpitch = (float) T0; + } + else + { + st->old_fpitch = predPitchLag; } } @@ -351,363 +275,198 @@ void con_acelp( * PLC: Accommodate the BPF *-------------------------------------------------------*/ - st->bpf_gain_param = 3 ; /*full BPF*/ move16(); + st->bpf_gain_param = 3 ; /*full BPF*/ /*-------------------------------------------------------* * PLC: [ACELP: adaptive codebook] * PLC: Calculate the initial gain and fade out step. *-------------------------------------------------------*/ - /* Compute pitch coherence (copied from decoder classifier)*/ + pc = (float) fabs( pitch_buf[3] + pitch_buf[2] - pitch_buf[1] - pitch_buf[0] ) * 256.0f / (float)L_frame; - pc = L_abs(L_sub(L_add(pitch_buf[3], L_sub(pitch_buf[2], pitch_buf[1])), pitch_buf[0])); /*9Q6*/ /*> 15Q16*/ - - /* mapping: floor(( 0.824[15Q15]-x[15Q0]*0.0733[0Q15] )*4) */ - - pc = Mpy_32_16_1( L_shl(pc,1)/*precompensate Q14 from table*/, /*15Q16*/ - T_256DIV_L_Frame[L_shr(L_msu0(54000,shr(st->L_frame_fx,5),2402),15-2)]); - - test(); - test();/*test();*/ - IF (sub(st->last_good_fx , UNVOICED_TRANSITION) <= 0 - && (sub(coder_type , GENERIC ) == 0) - && L_sub(pc , 6*2*32768/*6(15Q16)*/ ) > 0 /*&& (stab_fac <= 0.5f)*/ - ) + if ((st->last_good <= UNVOICED_TRANSITION) && (coder_type == GENERIC) && (pc > 6)) { - gain = 0; - move16(); - st->Mode2_lp_gainp = L_deposit_l(0); + gain = 0.0f; + st->lp_gainp = 0.0f; } - ELSE + else { - gain = 0x4000 /*1 (1Q14)*/; /* start-of-the-frame gain */ - st->Mode2_lp_gainp = L_shl(L_deposit_l(alpha),15); /*1Q14->2Q29*/ + gain = 1.0f; /* start-of-the-frame gain */ + st->lp_gainp = alpha; } - tmp_16 = extract_l(L_shl(L_mac(-28000,st->L_frame_fx,95),1-15)); - tmp_16 = T_DIV_L_Frame[tmp_16]; - tmp_32 = L_mult0(tmp_16 , sub(gain , alpha));/* 0Q15 * 2^-7 * 1Q14 -> 2Q29 * 2^-7*/ - tmp_32 = L_shr(tmp_32,6); /*-> 1Q30*/ - step = round_fx(tmp_32); /*->1Q14*/ - - /*FLC: step: 6.25e-5 .. 0.0045*/ /*-> s_step = -7*/ - /*lp_gainp : 0..0.2856..0.98*/ + step = (1.0f/L_frame) * (gain - st->lp_gainp); /*-------------------------------------------------------* * PLC: [ACELP: Fade-out] * Apply fade out *-------------------------------------------------------*/ - tmp_16 = 0; - move16(); - l = 0; - move16(); - FOR (i_subfr = 0; i_subfr < st->nb_subfr; i_subfr++) + for (i_subfr = 0; i_subfr < st->nb_subfr; i_subfr++) { - pgainT[i_subfr] = gain; /*Q14*/ move16(); - i = l; - move16(); - l = add(l, L_SUBFR); - FOR (; i < l; i++) + pgainT[i_subfr] = gain; + + for (i = i_subfr*L_SUBFR; i < (i_subfr+1)*L_SUBFR; i++) { - move16(); - BASOP_SATURATE_WARNING_OFF - exc[i] = mult_r(exc[i] , shl(gain,1)); /*overflow is first iteration because gain may be 1 after shift*/ - BASOP_SATURATE_WARNING_ON - gain = sub(gain , step); + exc[i] *= gain; + gain -= step; } } - l = add(st->L_frame_fx,shr(st->L_frame_fx,1)); - FOR (; i < l; i++ ) + for ( ; i < L_frame+(L_frame/2); i++ ) { - move16(); - BASOP_SATURATE_WARNING_OFF - exc[i] = mult_r(exc[i] , shl(gain,1)); /*overflow is first iteration because gain may become 1 due to shift*/ - BASOP_SATURATE_WARNING_ON - gain = sub(gain , step); + exc[i] *= gain; + gain -= step; } - FOR (i = 0; i < st->nb_subfr; i ++) + for (i = 0; i < st->nb_subfr; i ++) { - pT[i] = round_fx(pitch_buf[i]); /*Q0*/ - pitch_buffer[i] = round_fx(pitch_buf[i]); + pT[i] = (int)( pitch_buf[i] + 0.5f); + pitch_buffer[i] = pitch_buf[i]; } /* update old exc without random part*/ - Copy(harmonic_exc_buf+st->L_frame_fx, st->old_exc_fx, L_EXC_MEM_DEC); + mvr2r(harmonic_exc_buf+L_frame, st->old_exc, L_EXC_MEM_DEC); + } - ELSE + else { /* No harmonic part */ - assert( (int)(sizeof(buf)/sizeof(buf[0])) - M - L_EXC_MEM_DEC >= st->L_frame_fx + st->L_frame_fx/2); - set16_fx(&exc[0], 0, add(st->L_frame_fx, shr(st->L_frame_fx,1))); + set_zero(&exc[0], L_frame+L_frame/2); - FOR (i = 0; i < st->nb_subfr; i ++) + for (i = 0; i < st->nb_subfr; i ++) { - pitch_buf[i] = L_deposit_h(st->pit_max); /*15Q16*/ - pgainT[i] = 0; - move16(); + pitch_buf[i] = st->pit_max; + pgainT[i] = 0.f; pT[i] = L_SUBFR; - move16(); pitch_buffer[i] = L_SUBFR; - move16(); } - st->bpf_gain_param = 0; /*no BPF*/ move16(); + st->bpf_gain_param = 0; /*no BPF*/ } /*-----------------------------------------------------------------* - * Construct the random part of excitation (5/2 st->L_frame_fx + 2L_FIR_FER - 2) - * - * This is done in Q0 and will be corrected to current Q format of excitation - * when doing "non-causal ringing of the FIR filter" - * - * search for "Scale from randomized buffer to excitation buffer" + * Construct the random part of excitation *-----------------------------------------------------------------*/ noise_buf = buf; - move16(); tmpSeed = st->seed_acelp; - move16(); - l = add(st->L_frame_fx,sub(l_fir_fer,1)); - FOR (i = 0; i < l; i++) - { - tmpSeed = own_random2_fx(tmpSeed); - noise_buf[i] = tmpSeed; /*Q0*/ move16(); - } - st->seed_acelp = tmpSeed; - move16(); - l = add(add(st->L_frame_fx,shr(st->L_frame_fx,1)),sub(l_fir_fer,1)); - FOR ( ; i < l; i++) + for (i = 0; i < L_frame+l_fir_fer-1; i++) { - tmpSeed = own_random2_fx(tmpSeed); - noise_buf[i] = tmpSeed; /*Q0*/ move16(); + noise_buf[i] = (float)own_random(&tmpSeed); + } + st->seed_acelp = tmpSeed; + + for ( ; i < L_frame+(L_frame/2)+l_fir_fer-1; i++) + { + noise_buf[i] = (float)own_random(&tmpSeed); } /*get filter coefficients*/ - genPlcFiltBWAdap(st->sr_core, /*W32 Q0*/ - &hp_filt[0], /*Q15*/ - 1, - st->cummulative_damping); /*Q15*/ + genPlcFiltBWAdap(st->sr_core, &hp_filt[0], 1, st->cummulative_damping); /* PLC: [ACELP: Fade-out] * PLC: retrieve background level */ + tmp = 1.0f; + gainSynthDeemph=getLevelSynDeemph( &(tmp), A, L_SUBFR, st->preemph_fac, L_frame/L_SUBFR); + gainCNG = st->cngTDLevel/gainSynthDeemph; - tmp2 = shl(div_s(st->L_frame_fx,shl(L_SUBFR,3)),3-15); + gain = st->lp_gainc; /* start-of-the-frame gain */ + ftmp = 2.0f * gain; - tmp = 32767/*1.0f Q15*/; - gainSynthDeemph=getLevelSynDeemph(&(tmp), - A, - M, - L_SUBFR, - st->preemph_fac, - tmp2, - &gainSynthDeemph_e); - - - - /*gainCNG=st->cngTDLevel/gainSynthDeemph;*/ - BASOP_Util_Divide_MantExp(st->cngTDLevel, st->cngTDLevel_e, gainSynthDeemph, gainSynthDeemph_e,&gainCNG, &gainCNG_e); - gainCNG_e=sub(gainCNG_e,15-5);/*Q15->Q5*/ - if(gainCNG==0) + if (gainCNG > ftmp) { - gainCNG_e = 0; - move16(); + gainCNG = ftmp; } - gain_32 = st->Mode2_lp_gainc; /*15Q16 *//* start-of-the-frame gain */ move16(); + st->lp_gainc = alpha * st->lp_gainc + (1.0f - alpha) * gainCNG; /* end-of-the-frame gain */ - ftmp = round_fx(L_shl(gain_32,1));/*Q0*/ - - BASOP_SATURATE_WARNING_OFF - tmp_16 = sub(shl(gainCNG,sub(gainCNG_e,5/*Q5*/)),ftmp); - /*in case of overflow:*/ - test(); - if ((sub(shl(ftmp,sub(gainCNG_e,1)),MAXVAL_WORD16) == 0) && (gainCNG == MAXVAL_WORD16)) + if( (st->last_good == UNVOICED_TRANSITION) && (coder_type == GENERIC)) { - move16(); - tmp_16 = 1; - } - BASOP_SATURATE_WARNING_ON - - IF (tmp_16 > 0 ) - { - gainCNG = ftmp/*Q0*/; - gainCNG_e = 5; /*-> Q5*/ - s_16 = norm_s(gainCNG); - gainCNG = shl(gainCNG,s_16); - gainCNG_e = sub(gainCNG_e,s_16); + st->lp_gainc = gainCNG; } - /* end-of-the-frame gain */ - /* st->Mode2_lp_gainc = alpha * st->Mode2_lp_gainc + (1.0f - alpha) * gainCNG;*/ - tmp_32 = Mpy_32_16_1(st->Mode2_lp_gainc /*Q16*/,alpha/*Q14*/);/*Q31-16 = Q15*/ - s_32 = norm_l(tmp_32); - tmp_32 = L_shl(tmp_32,s_32); - tmp_16 = round_fx(tmp_32); - s_16 = negate(s_32); - s_16 = sub(s_16,-1-15); /*->Q15*/ - - tmp2 = sub(16384/*1 in Q14*/,alpha); /*Q14*/ - tmp2 = mult(tmp2,gainCNG); /*Q14+Q5 +1 -16 = Q4*/ - s2 = norm_s(tmp2); - tmp2 = shl(tmp2,s2); - s2 = add(negate(s2),gainCNG_e); - s2 = sub(s2,4-15);/*->Q15*/ - - s_16 = BASOP_Util_Add_MantExp(tmp_16,s_16,tmp2,s2,&tmp_16); - st->Mode2_lp_gainc = L_shl(L_deposit_l(tmp_16),add(s_16,1)); - test(); - IF( (sub(st->last_good_fx, UNVOICED_TRANSITION)==0 ) && (sub(coder_type,GENERIC)==0) ) - { - st->Mode2_lp_gainc = L_deposit_h(gainCNG);/*Q21*/ - st->Mode2_lp_gainc = L_shr(st->Mode2_lp_gainc,sub(5,gainCNG_e)); /*15Q16, no scaling*/ - } - - highPassFiltering(st->last_good_fx, add(st->L_frame_fx,shr(l_fir_fer,1)), noise_buf, hp_filt, l_fir_fer); + highPassFiltering(st->last_good, L_frame+ l_fir_fer/2, noise_buf, hp_filt, l_fir_fer); + /* Find energy normalization factor */ pt_exc = noise_buf + l_fir_fer/2; - - /*** Find energy normalization factor ***/ - /*gain_inov = 1.0f / (float)sqrt( dot_product( pt_exc, pt_exc, st->L_frame_fx ) / st->L_frame_fx );*//* normalize energy */ /*<--- FLC*/ - - BASOP_SATURATE_WARNING_OFF /*norm_llQ31 at the end of Dot_productSq16HQ may throw an overflow, but result is okay*/ - tmp_32 = Dot_productSq16HQ(0,pt_exc,st->L_frame_fx,&s_32); - BASOP_SATURATE_WARNING_ON - s_32 = add(s_32, 31-1); - /*scalingfactor is twice the headroom (at noise insertion onto the buffer), -1 (because of mult) +31 (Result is Q31) +s_32 (output scalingfactor of dot_product)*/ - - tmp_16 = T_DIV_L_Frame[L_shl(L_mac(-28000,st->L_frame_fx,95),1-15)]; - tmp_32 = Mpy_32_16_1(tmp_32,tmp_16 ); /* Q31 * 2^s_32 * 0Q15 * 2^-7 */ - - s_32 = sub(s_32,7); /*tmp_32 is Q31 * 2^s_32 */ - - /*assure doing Isqrt not for 0*/ - IF (tmp_32 != 0) - { - s_gain_inov = s_32; - tmp_32 = ISqrt32(tmp_32, &s_gain_inov); - } - ELSE - { - s_gain_inov = 0; - tmp_32 = 0; - } - - - gain_inov = round_fx(tmp_32);/*Inverse sqrt*/ /* Q15 * 2^s_gain_inov */ + gain_inov = 1.0f / (float)sqrt( dotp( pt_exc, pt_exc, L_frame ) / L_frame + 0.01f ); /* PLC: [ACELP: Fade-out] * PLC: Linearly attenuate the gain through the frame */ + step = (1.0f/L_frame) * (gain - st->lp_gainc); - step_32 = L_sub(gain_32, st->Mode2_lp_gainc); /* 15Q16 */ - tmp_16 = extract_l(L_shl(L_mac(-28000,st->L_frame_fx,95),1-15)); - step_32 = Mpy_32_16_1(step_32, T_DIV_L_Frame[tmp_16]); /* 15Q16 * 2^-7 = 15Q16 * Q15 * 2^-7 */ - step_32 = L_shr(step_32, 7); /* 15Q16 */ - - test(); - if ((sub(st->last_good_fx ,UNVOICED_CLAS)==0) && (sub(coder_type,UNVOICED)!= 0)) /* Attenuate somewhat on unstable unvoiced */ + if ((st->last_good == UNVOICED_CLAS) && (coder_type!=UNVOICED)) /* Attenuate somewhat on unstable unvoiced */ { - gain_inov = mult_r(gain_inov, 26214/*0.8f Q15*/); /*Q15 * 2^s_gain_inov*/ + gain_inov *= 0.8f; } - IF ( sub(st->last_good_fx , UNVOICED_TRANSITION)>=0 ) + if (st->last_good >= UNVOICED_TRANSITION) { - Word16 tilt_code; + float tilt_code; - /*tilt_code = (float)(0.10f*(1.0f + st->voice_fac));*/ - tilt_code = mac_r(214748368l/*0.1f Q31*/, 3277/*0.1f Q15*/ , st->voice_fac); - - gain_inov = mult_r(gain_inov, sub(32767/*1.0f Q15*/, tilt_code)); /* Q15 * 2^s_gain_inov */ + tilt_code = (float)(0.10f*(1.0f + st->voice_fac)); + gain_inov *= (1.f - tilt_code); } pt_exc = noise_buf; /* non-causal ringing of the FIR filter */ - /* gain_16 = gain_32 = gain_inov * gain */ - gain_32 = Mpy_32_16_1(gain_32, gain_inov); /* 15Q16 * Q15 * 2^s_gain_inov */ - gain_32 = L_shl(gain_32, add(15, s_gain_inov)); /* Q31 */ - gain_16 = round_fx(gain_32); /* Q15 */ - - /* step_32 = gain_inov * step */ - step_32 = Mpy_32_16_1(step_32, gain_inov); /* 15Q16 * Q15 * 2^s_gain_inov */ - step_32 = L_shl(step_32, add(15, s_gain_inov)); /* Q31 */ - - g_e = norm_s(round_fx(L_shl(Mpy_32_16_1(st->Mode2_lp_gainc, gain_inov), add(15, s_gain_inov)))); /* norm_s for gain*gain_inov at the end of the following loops */ - g_e = s_min(norm_s(gain_16), g_e); - gain_16 = shl(gain_16, g_e); - gain_32 = L_shl(gain_32, g_e); - step_32 = L_shl(step_32, g_e); - l = shr(l_fir_fer,1); - FOR( i=0 ; i < l; i++ ) + for( i=0 ; i< l_fir_fer/2; i++ ) { - /* *pt_exc++ *= (gain_inov * gain); <=> *pt_exc++ *= gain_16; */ /*<-- FLC*/ - *pt_exc = mult_r(*pt_exc , gain_16); /* Q0 = Q0 * Q15 */ move16(); - pt_exc++; + *pt_exc++ *= (gain_inov * gain); } - /* gain -= step; gain is updated after the loop and inside the loop gain_16 = gain_inov * gain is modified using gain_inov * (gain-step) = gain_inov * gain - gain_inov * step */ /*<-- FLC*/ - FOR( i=0 ; i < st->L_frame_fx; i++ ) - { - /* *pt_exc++ *= (gain_inov * gain); <=> *pt_exc++ *= gain_16; */ /*<-- FLC*/ - *pt_exc = mult_r(*pt_exc , gain_16); /* Q0 = Q0 * Q15 */ move16(); - pt_exc++; + /* Actual filtered random part of excitation */ - gain_32 = L_sub(gain_32, step_32); - gain_16 = round_fx(gain_32); + for( i=0 ; i< L_frame; i++ ) + { + *pt_exc++ *= (gain_inov * gain); + gain -= step; } - l = add(shr(st->L_frame_fx,1),l_fir_fer/2); - FOR( i=0 ; i < l; i++ ) + for( i=0 ; i< (L_frame/2)+l_fir_fer/2; i++ ) { - /* *pt_exc++ *= (gain_inov * gain); <=> *pt_exc++ *= gain_16; */ /*<-- FLC*/ - *pt_exc = mult_r(*pt_exc , gain_16); /* Q0 = Q0 * Q15 */ move16(); - pt_exc++; + *pt_exc++ *= (gain_inov * gain); } - /*store st->past_gcode*/ - /* at this point gain is equal to st->Mode2_lp_gainc, so we don't need to calculate gain at all */ - st->past_gcode = st->Mode2_lp_gainc; /*15Q16 */ move16(); + st->past_gcode = gain; - /*-----------------------------------------------------------------* - * PLC: [ACELP: general] - * PLC: Construct the total excitation - *-----------------------------------------------------------------*/ - - IF( st->last_good_fx < UNVOICED_TRANSITION ) + if( st->last_good < UNVOICED_TRANSITION ) { - bufferCopyFx(noise_buf+l_fir_fer/2, exc, add(st->L_frame_fx,shr(st->L_frame_fx,1)), 0, *Qf_exc, negate(g_e), 0); /*copy between different formats*/ - Copy(harmonic_exc_buf+st->L_frame_fx, st->old_exc_fx, L_EXC_MEM_DEC); - Copy(exc, exc_unv, add(st->L_frame_fx, shr(st->L_frame_fx,1))); /* Update exc_unv */ + mvr2r(noise_buf+l_fir_fer/2, exc, L_frame+L_frame/2); + mvr2r(harmonic_exc_buf+L_frame, st->old_exc, L_EXC_MEM_DEC); + mvr2r( exc, exc_unv, L_frame+ (L_frame/2)); /* Update exc_unv */ } - ELSE + else { - /* Update exc_unv */ - bufferCopyFx(noise_buf+l_fir_fer/2, exc_unv, add(st->L_frame_fx,shr(st->L_frame_fx,1)), 0, *Qf_exc, negate(g_e), 0); /*copy between different formats*/ + mvr2r( noise_buf+l_fir_fer/2, exc_unv, L_frame+ (L_frame/2)); /* Update exc_unv */ } /* Compute total excitation in noisebuffer to save memories */ - IF( sub( st->last_good_fx, UNVOICED_TRANSITION ) >= 0 ) + if(st->last_good >= UNVOICED_TRANSITION) { - Vr_add(exc, exc_unv, noise_buf, add(st->L_frame_fx, 1)); + for( i=0 ; i< L_frame+1; i++ ) + { + noise_buf[i] = exc[i]+exc_unv[i]; + } } - ELSE + else { noise_buf = exc_unv; } - IF( sub( st->L_frame_fx, L_FRAME ) == 0 ) + if(L_frame == L_FRAME) { - interp_code_5over2_fx(noise_buf, bwe_exc, st->L_frame_fx); - set16_fx(voice_factors, st->last_voice_factor_fx, NB_SUBFR); + interp_code_5over2(noise_buf, bwe_exc, L_frame); + set_f(voice_factors, st->last_voice_factor, NB_SUBFR); } - ELSE + else { - interp_code_4over2_fx(noise_buf, bwe_exc, st->L_frame_fx); - set16_fx(voice_factors, st->last_voice_factor_fx, NB_SUBFR16k); + interp_code_4over2(noise_buf, bwe_exc, L_frame); + set_f(voice_factors, st->last_voice_factor, NB_SUBFR16k); } /*----------------------------------------------------------* @@ -716,411 +475,218 @@ void con_acelp( /* Init syn buffer */ syn = buf + M; - Copy(st->mem_syn2_fx, buf, M ); + mvr2r(st->mem_syn2, buf, M ); - IF (sub(st->nbLostCmpt,1) == 0) + if (st->nbLostCmpt == 1) { - IF( st->last_good_fx < UNVOICED_TRANSITION ) + + if(st->last_good < UNVOICED_TRANSITION ) { - Copy(st->mem_syn2_fx, mem_syn_unv, M ); + mvr2r(st->mem_syn2, mem_syn_unv, M ); } - ELSE + else { - set16_fx( mem_syn_unv, 0, M ); + set_zero( mem_syn_unv, M ); } } - ELSE + else { - Copy( st->mem_syn_unv_back, mem_syn_unv, M ); + mvr2r( st->mem_syn_unv_back, mem_syn_unv, M ); } /* voiced synth */ - IF(st->last_good_fx >= UNVOICED_TRANSITION) + + if(st->last_good >= UNVOICED_TRANSITION) { p_A = A; - FOR (i_subfr = 0; i_subfr < st->L_frame_fx; i_subfr += L_SUBFR) + + for (i_subfr = 0; i_subfr < L_frame; i_subfr += L_SUBFR) { tmp = 0; - move16(); - set16_fx(h1, 0, L_SUBFR+1); - set16_fx(mem, 0, M); - h1[0] = 1024/*1.0f/((float)(1 << scale_h1)) Q15*/; - move16(); - E_UTIL_synthesis(0, p_A, h1, h1, L_SUBFR, mem, 0, M); /* impulse response of LPC */ - deemph_fx(h1, st->preemph_fac, L_SUBFR, &tmp); /* impulse response of deemph */ - + set_zero( h1, L_SUBFR+1 ); + set_zero( mem, M ); + h1[0] = 1.0f; + syn_filt(p_A, M,h1, h1, L_SUBFR, mem, 0); /* impulse response of LPC */ + deemph(h1, st->preemph_fac, L_SUBFR, &tmp); /* impulse response of deemph */ /* impulse response level = gain introduced by synthesis+deemphasis */ - /* gain_lpc[i_subfr/L_SUBFR] = 1.f/(float)sqrt(dotp( h1, h1, L_SUBFR)); */ - tmp_32 = Dot_productSq16HQ(0, h1, L_SUBFR, &gain_lpc_e[i_subfr/L_SUBFR]); - tmp_32 = L_max(tmp_32, 1); - gain_lpc_e[i_subfr/L_SUBFR] = add(gain_lpc_e[i_subfr/L_SUBFR], 2*scale_h1); - move16(); - gain_lpc[i_subfr/L_SUBFR] = round_fx(ISqrt32(tmp_32, &gain_lpc_e[i_subfr/L_SUBFR])); - - p_A += (M+1); /* Pointer move */ - } - - g = 0; - move16(); - FOR (i_subfr = 0; i_subfr < st->L_frame_fx; i_subfr += L_SUBFR) - { - - g = mult_r(st->last_gain_syn_deemph, gain_lpc[i_subfr/L_SUBFR]); - g_e = add(st->last_gain_syn_deemph_e, gain_lpc_e[i_subfr/L_SUBFR]); - g = shl(g, g_e); - FOR (i=0; i < L_SUBFR; i++) - { - /* exc[i_subfr + i] *= st->last_gain_syn_deemph*gain_lpc[j]; */ - exc[i_subfr + i] = mult_r(exc[i_subfr + i], g); - move16(); - } - } - l = add(st->L_frame_fx, shr(st->L_frame_fx, 1)); - FOR (i = st->L_frame_fx; i < l; i++) - { - exc[i] = mult_r(exc[i], g); - move16(); - } - - /*Rescale the synthesis memory*/ - Qf_syn_new = *Qf_mem_syn; - move16(); - Qf_syn = *Qf_mem_syn; - move16(); - rescale_mem(Qf_exc, &Qf_syn_new, &Qf_syn, mem_syn, NULL, M, st->L_frame_fx); - synthScaling = sub(*Qf_exc,Qf_syn); - - p_A = A; - - /*in case of more than 5 consecutive concealed frames, improve precision of synthesis*/ - memsynPrecission(st->nbLostCmpt,mem_syn, exc, st->L_frame_fx, &s_16); - FOR (i_subfr = 0; i_subfr < st->L_frame_fx; i_subfr += L_SUBFR) - { - - - E_UTIL_synthesis(synthScaling, p_A, &exc[i_subfr], &syn[i_subfr], L_SUBFR, mem_syn, 1, M); + gain_lpc[i_subfr/L_SUBFR] = 1.f/(float)sqrt(dotp( h1, h1, L_SUBFR)); p_A += (M+1); } - Copy( mem_syn, mem_syn2, M ); + + j=0; + for (i_subfr = 0; i_subfr < L_frame; i_subfr += L_SUBFR) + { + + for (i=0; ilast_gain_syn_deemph*gain_lpc[j]; + } + j++; + } + + for (i=L_frame; ilast_gain_syn_deemph*gain_lpc[3]; + } + p_A = A; + + for (i_subfr = 0; i_subfr < L_frame; i_subfr += L_SUBFR) + { + syn_filt(p_A, M,&exc[i_subfr], &syn[i_subfr], L_SUBFR, mem_syn, 1); + p_A += (M+1); + } + + mvr2r( mem_syn, mem_syn2, M ); + /* synthesize ola*/ - E_UTIL_synthesis(synthScaling, p_A-(M+1), &exc[i_subfr], &syn[i_subfr], (st->L_frame_fx/2), mem_syn2, 0, M); + syn_filt(p_A-(M+1), M, &exc[L_frame], &syn[L_frame], (L_frame/2), mem_syn2, 0); } - test(); - IF(sub(st->nbLostCmpt,5)>0 && (s_16 > 0) ) - { - /*scale back mem_syn, exc and synthesis*/ - Scale_sig(mem_syn,M,negate(s_16)); - Scale_sig(syn, add(shr(st->L_frame_fx,1),st->L_frame_fx) ,negate(s_16)); - /*Scale_sig(exc, add(shr(st->L_frame_fx,1),st->L_frame_fx) ,negate(s_16));*/ - } - - /* unvoiced synth */ - tmp = 0; - move16(); p_A = st->Aq_cng; - FOR (i_subfr = 0; i_subfr < st->L_frame_fx; i_subfr += L_SUBFR) + for (i_subfr = 0; i_subfr < L_frame; i_subfr += L_SUBFR) { - set16_fx(h1, 0, L_SUBFR+1); - set16_fx(mem, 0, M); - h1[0] = 1024/*1.0f/((float)(1 << scale_h1)) Q15*/; - move16(); - E_UTIL_synthesis(0, p_A, h1, h1, L_SUBFR, mem, 0, M); /* impulse response of LPC */ - deemph_fx(h1, st->preemph_fac, L_SUBFR, &tmp); /* impulse response of deemph */ - + set_zero(h1, L_SUBFR+1); + set_zero(mem, M); + h1[0] = 1.0f; + syn_filt(p_A, M,h1, h1, L_SUBFR, mem, 0); /* impulse response of LPC */ + deemph(h1, st->preemph_fac, L_SUBFR, &tmp); /* impulse response of deemph */ /* impulse response level = gain introduced by synthesis+deemphasis */ - /* gain_lpc[i_subfr/L_SUBFR] = 1.f/(float)sqrt(dotp( h1, h1, L_SUBFR)); */ - tmp_32 = Dot_productSq16HQ(0, h1, L_SUBFR, &gain_lpc_e[i_subfr/L_SUBFR]); - tmp_32 = L_max(tmp_32, 1); - gain_lpc_e[i_subfr/L_SUBFR] = add(gain_lpc_e[i_subfr/L_SUBFR], 2*scale_h1); - move16(); - gain_lpc[i_subfr/L_SUBFR] = round_fx(ISqrt32(tmp_32, &gain_lpc_e[i_subfr/L_SUBFR])); - - p_A += (M+1); /* Pointer move */ - } - - g = 0; - move16(); - FOR (i_subfr = 0; i_subfr < st->L_frame_fx; i_subfr += L_SUBFR) - { - g = mult_r(st->last_gain_syn_deemph, gain_lpc[i_subfr/L_SUBFR]); - g_e = add(st->last_gain_syn_deemph_e, gain_lpc_e[i_subfr/L_SUBFR]); - g = shl(g, g_e); - FOR (i=0; i < L_SUBFR; i++) - { - /* exc[i_subfr + i] *= st->last_gain_syn_deemph*gain_lpc[j]; */ - exc_unv[i_subfr + i] = mult_r(exc_unv[i_subfr + i], g); - move16(); - } - } - l = add(st->L_frame_fx, shr(st->L_frame_fx, 1)); - FOR (i = st->L_frame_fx; i < l; i++) - { - exc_unv[i] = mult_r(exc_unv[i], g); - move16(); - } - - /* Update Qf_syn */ - Qf_syn_new = *Qf_mem_syn; - move16(); - Qf_syn = *Qf_mem_syn; - move16(); - rescale_mem(Qf_exc, &Qf_syn_new, &Qf_syn, mem_syn_unv, NULL, M, st->L_frame_fx); - synthScaling = sub(*Qf_exc,Qf_syn); - *Qf_mem_syn = Qf_syn; - - p_A = st->Aq_cng; - - /*in case of more than 5 consecutive concealed frames, improve precision of synthesis*/ - memsynPrecission(st->nbLostCmpt,mem_syn_unv, exc_unv, st->L_frame_fx, &s_16); - - FOR (i_subfr = 0; i_subfr < st->L_frame_fx; i_subfr += L_SUBFR) - { - E_UTIL_synthesis(synthScaling, p_A, &exc_unv[i_subfr], &syn_unv[i_subfr], L_SUBFR, mem_syn_unv, 1, M); + gain_lpc[i_subfr/L_SUBFR] = 1.f/(float)sqrt(dotp( h1, h1, L_SUBFR)); p_A += (M+1); } - Copy(mem_syn_unv,st->mem_syn_unv_back,M); - IF(sub(st->last_good_fx,UNVOICED_TRANSITION) < 0) + j=0; + for (i_subfr = 0; i_subfr < L_frame; i_subfr += L_SUBFR) { - Copy(mem_syn_unv,mem_syn,M); - /* unvoiced for ola */ - E_UTIL_synthesis(synthScaling, p_A-(M+1), &exc_unv[i_subfr], &syn_unv[i_subfr], shr(st->L_frame_fx,1), mem_syn_unv, 0, M); + + for (i=0; ilast_gain_syn_deemph*gain_lpc[j]; + } + j++; } - test(); - IF(sub(st->nbLostCmpt,5)>0 && (s_16 > 0) ) + for (i=L_frame; ilast_good_fx,UNVOICED_TRANSITION) < 0) - { - Scale_sig(mem_syn,M,negate(s_16)); - Scale_sig(syn_unv, add(shr(st->L_frame_fx,1),st->L_frame_fx) ,negate(s_16)); - } - ELSE - { - Scale_sig(syn_unv, st->L_frame_fx ,negate(s_16)); - } - - Scale_sig(st->mem_syn_unv_back,M,negate(s_16)); - - /*Scale_sig(exc_unv, add(shr(st->L_frame_fx,1),st->L_frame_fx) ,negate(s_16));*/ + exc_unv[i] *= st->last_gain_syn_deemph*gain_lpc[j-1]; } + p_A = st->Aq_cng; + + for (i_subfr = 0; i_subfr < L_frame; i_subfr += L_SUBFR) + { + syn_filt(p_A, M,&exc_unv[i_subfr], &syn_unv[i_subfr], L_SUBFR, mem_syn_unv, 1); + p_A += (M+1); + } + + mvr2r(mem_syn_unv,st->mem_syn_unv_back,M); + + if(st->last_good < UNVOICED_TRANSITION) + { + mvr2r(mem_syn_unv,mem_syn,M); + } + + /* unvoiced for ola */ + syn_filt(p_A-(M+1), M,&exc_unv[i_subfr], &syn_unv[i_subfr], (L_frame/2), mem_syn_unv, 0); /* add separate synthesis buffers */ - IF (sub(st->last_good_fx,UNVOICED_TRANSITION) >= 0) + if(st->last_good >= UNVOICED_TRANSITION) { - FOR( i=0 ; i < st->L_frame_fx; i++ ) + for( i=0 ; i < L_frame; i++ ) { - syn[i] = add(syn[i], syn_unv[i]); - move16(); + syn[i] += syn_unv[i]; } } - ELSE + else { - Copy(syn_unv,syn,add(st->L_frame_fx, shr(st->L_frame_fx,1))); + mvr2r(syn_unv,syn,L_frame+L_frame/2); } /* update buffer for the classification */ - { - Word16 pit16[NB_SUBFR16k]; - Word16 k; - FOR(k = 0 ; k < st->nb_subfr; k++) - { - pit16[k] = shl(extract_h(pitch_buf[k]),6);/*Q6*/ - } - - FEC_clas_estim_fx( - st, - /*Opt_AMR_WB*/0, /*A*/ - st->L_frame_fx, - &(st->clas_dec), - coder_type, - pit16, - syn, - &st->lp_ener_FER_fx, - /**decision_hyst*/NULL, /* i/o: hysteresis of the music/speech decision */ - /**UV_cnt*/ NULL, /* i/o: number of consecutives frames classified as UV */ - /**LT_UV_cnt*/ NULL, /* i/o: long term consecutives frames classified as UV */ - /**Last_ener*/ NULL, /* i/o: last_energy frame */ - /**locattack*/ NULL, /* i/o: detection of attack (mainly to localized speech burst) */ - /**lt_diff_etot*/NULL, /* i/o: long-term total energy variation */ - /**amr_io_class*/ NULL, /* i/o: classification for AMR-WB IO mode */ - /*bitrate*/ 0 , /* i : Decoded bitrate */ - Qf_syn, /* i : Synthesis scaling */ - /**class_para*/ NULL, /* o : classification para. fmerit1 */ - st->mem_syn_clas_estim_fx, /* i/o: memory of the synthesis signal for frame class estimation */ - &st->classifier_Q_mem_syn, /*i/o : exponent for memory of synthesis signal for frame class estimation */ - -32768/*-1.f Q15*/, /* i : LTP Gain */ - 0/*CLASSIFIER_ACELP*/, /* i : signal classifier mode */ - 1/*bfi*/, /* i : bad frame indicator */ - st->last_core_brate_fx /* i : bitrate of previous frame */ - ); - } + FEC_clas_estim( syn, pitch_buf, st->L_frame, coder_type, st->codec_mode, st->mem_syn_clas_estim, &(st->clas_dec), + &st->lp_ener_bfi, st->core_brate, 0, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, -1.0f, st->narrowBand, (SIGNAL_CLASSIFIER_MODE)0, + 1, st->preemph_fac, st->tcxonly, st->last_core_brate ); /* Update Pitch Lag memory */ - Copy32(&st->old_pitch_buf_fx[st->nb_subfr], st->old_pitch_buf_fx, st->nb_subfr); - Copy32(pitch_buf, &st->old_pitch_buf_fx[st->nb_subfr], st->nb_subfr); + mvr2r( &st->old_pitch_buf[L_frame/L_SUBFR], st->old_pitch_buf, L_frame/L_SUBFR ); + mvr2r( pitch_buf, &st->old_pitch_buf[L_frame/L_SUBFR], L_frame/L_SUBFR ); /*updating enr_old parameters*/ - frame_ener_fx( st->L_frame_fx, st->last_good_fx, syn, round_fx(tmp_tc), &(st->enr_old_fx), 1, 0, 0, 0 ); - - st->enr_old_fx = L_shl(st->enr_old_fx,shl(negate(Qf_syn),1)); + fer_energy(L_frame, st->last_good, syn, tmp_tc, &(st->enr_old), 1); /* update ACELP synthesis memory */ - Copy(mem_syn, st->mem_syn2_fx , M); - Copy(syn+st->L_frame_fx-L_SYN_MEM, st->mem_syn_r , L_SYN_MEM); + mvr2r( mem_syn, st->mem_syn2, M ); + mvr2r( syn+L_frame-L_SYN_MEM, st->mem_syn_r, L_SYN_MEM ); - /*Q_mem_syn_new = Q_mem_syn;*//*NOT "+synthScaling", cause mem_syn format is not changed*/ /* Deemphasis and output synth */ tmp_deemph = st->syn[M]; + deemph(syn, st->preemph_fac, L_frame+L_frame/2, &tmp_deemph); - E_UTIL_deemph2(*Qf_mem_syn, syn, st->preemph_fac, add(st->L_frame_fx,shr(st->L_frame_fx,1)), &tmp_deemph); + mvr2r(syn, synth, L_frame); + mvr2r(syn+L_frame-L_frame/2, st->old_syn_Overl, L_frame/2); - Copy(syn, synth, st->L_frame_fx); - - bufferCopyFx(syn+st->L_frame_fx-st->L_frame_fx/2, st->old_syn_Overl, shr(st->L_frame_fx,1),0 /*Qf_syn*/, -1 /*Qf_old_xnq*/, 0 , 0 /*Q_old_xnq*/); /* save last half frame if next frame is TCX */ - bufferCopyFx(syn+st->L_frame_fx, st->syn_Overl_TDAC, shr(st->L_frame_fx,1),0 /*Qf_syn*/, -1 /*Qf_old_xnq*/, 0 , 0 /*Q_old_xnq*/ ); - Copy(syn+st->L_frame_fx-M-1, st->syn, add(1,M)); + mvr2r(syn+L_frame, st->syn_Overl_TDAC, L_frame/2); + mvr2r(syn+L_frame-M-1, st->syn, 1+M); /* update old_Aq */ - Copy(p_A-(M+1), st->old_Aq_12_8_fx, add(M,1)); + mvr2r(p_A-(M+1), st->old_Aq_12_8, M+1); - Copy(syn+st->L_frame_fx, st->syn_Overl, shr(st->L_frame_fx,1)); + mvr2r(syn+L_frame, st->syn_Overl, L_frame/2); + + W1 = st->tcx_cfg.tcx_mdct_window_length; + W2 = st->tcx_cfg.tcx_mdct_window_length/2; + + st->tcx_cfg.tcx_curr_overlap_mode = FULL_OVERLAP; + { + short n = (short)((float)L_frame*N_ZERO_MDCT_NS/FRAME_SIZE_NS); + + mvr2r(syn+L_frame-n, st->old_outLB, L_frame-n); + + for (i=0; iold_outLB[i+n] *= w[W1-1-i]*w[W1-1-i]; + } + set_zero(&st->old_outLB[W1+n], n); + } /* create aliasing and windowing */ - W1 = st->tcx_cfg.tcx_mdct_window_length; - move16(); - W2 = shr(W1,1); - - st->tcx_cfg.tcx_curr_overlap_mode = FULL_OVERLAP; - move16(); - - n = extract_h(L_mult(st->L_frame_fx,9216/*(float)N_ZERO_MDCT_NS/(float)FRAME_SIZE_NS Q15*/)); - - st->Q_old_wtda_LB = getScaleFactor16(syn+st->L_frame_fx-n, - sub(st->L_frame_fx,n)); - move16(); - - bufferCopyFx(syn+st->L_frame_fx-n, st->old_out_LB_fx, sub(st->L_frame_fx, n), 0, 0, st->Q_old_wtda_LB, 0); - FOR (i=0; i < W2; i++) + for (i=0; iold_out_LB_fx[i+n] = round_fx(Mpy_32_16_1(L_mult(w[i].v.re,w[i].v.re),st->old_out_LB_fx[i+n])); - } - FOR ( ; i < W1; i++) - { - st->old_out_LB_fx[i+n] = round_fx(Mpy_32_16_1(L_mult(w[W2-1-(i-W2)].v.im,w[W2-1-(i-W2)].v.im),st->old_out_LB_fx[i+n])); - } - set16_fx(&st->old_out_LB_fx[W1+n], 0, n); - - st->Q_old_wtda = st->Q_old_wtda_LB; - - - - FOR (i=0; isyn_Overl_TDAC[i],w[i].v.re); - - } - FOR(; isyn_Overl_TDAC[i],w[W1-1-i].v.im); + buf[i] = st->syn_Overl_TDAC[i]*w[W1-1-i]; } - - FOR (i=0; isyn_Overl_TDAC[i] = add(buf[i],buf[W1-1-i]); /* A-D */ - } - /*-2*/ - FOR (i=0; isyn_Overl_TDAC[W2+i] = add(buf[W2+i],buf[W1-1-W2-i]);/* B-C */ + st->syn_Overl_TDAC[i] = buf[i]+buf[W1-1-i]; /* A-D */ } - - FOR (i=0; isyn_Overl_TDAC[i] = mult_r(st->syn_Overl_TDAC[i],w[i].v.re); + st->syn_Overl_TDAC[W2+i] = buf[W2+i]+buf[W1-1-W2-i]; /* B-C */ } - FOR(; isyn_Overl_TDAC[i] = mult_r(st->syn_Overl_TDAC[i],w[W1-1-i].v.im); + st->syn_Overl_TDAC[i] *= w[W1-1-i]; } /* update memory for full band */ - lerp(st->syn_Overl_TDAC, st->syn_Overl_TDACFB, shr(st->L_frameTCX, 1), shr(st->L_frame_fx, 1)); - lerp(st->syn_Overl, st->syn_OverlFB, shr(st->L_frameTCX, 1), shr(st->L_frame_fx, 1)); - lerp(st->old_out_LB_fx, st->old_out_fx, st->L_frameTCX, st->L_frame_fx); + lerp(st->syn_Overl_TDAC, st->syn_Overl_TDACFB, st->L_frameTCX/2, L_frame/2); + lerp(st->syn_Overl, st->syn_OverlFB, st->L_frameTCX/2, L_frame/2); + lerp(st->old_outLB, st->old_out, st->L_frameTCX, L_frame); /* copy total excitation exc2 as 16kHz for acelp mode1 decoding */ - lerp(exc, st->old_exc2_fx, L_EXC_MEM, st->L_frame_fx); - lerp(syn, st->old_syn2_fx, L_EXC_MEM, st->L_frame_fx); - st->bfi_pitch_fx = shl(round_fx(pitch_buf[st->nb_subfr-1]),6); - move16(); - st->bfi_pitch_frame_fx = st->L_frame_fx; - move16(); + lerp(exc, st->old_exc2, L_EXC_MEM, L_frame); + lerp(syn, st->old_syn2, L_EXC_MEM, L_frame); + st->bfi_pitch = pitch_buf[st->nb_subfr-1]; + st->bfi_pitch_frame = L_frame; return; } - -static void memsynPrecission(Word16 nbLostCmpt,Word16* mem_syn, Word16* exc, Word16 len, Word16*s_16) -{ - IF(sub(nbLostCmpt,5)>0 ) - { - Word16 sf_mem_syn, sf_exc,k, tmp_loop, max, tmp, i; - tmp = 0; - move16(); - *s_16 = 0; - move16(); - max = 0; - move16(); - - /*check energy of mem_syn*/ - FOR(i=0; i 0 ) - { - sf_mem_syn = getScaleFactor16(mem_syn,M); - /*sf_exc = getScaleFactor16(exc, add(shr(len,1),len));*/ /*this returns 0 if signal is 0*/ - tmp_loop = add(shr(len,1),len); - FOR(k=0; k #include +#include #include #include "options.h" -#include "prot_fx.h" -#include "basop_util.h" -#include "rom_dec_fx.h" -#include "stl.h" +#include "prot.h" +#include "rom_dec.h" -/***************************************************** - calcGainc calculates st->lp_gainc -******************************************************/ -static void calcGainc(Word16* exc, Word16 Q_exc, Word32 old_fpitch, Word16 L_subfr, Word32 lp_gainp, Word32* lp_gainc) -{ - Word32 L_c ; - Word16 tmp16, tmp16_2, tmp16_3, tmp_e, tmp2_e, tmp_loop, i; - Word32 L_acc, L_tmp; - - - L_acc = L_deposit_l(0); - L_c = L_deposit_l(0); - Overflow = 0; - Carry = 0; - - tmp16 = round_fx(old_fpitch);/*Q0*/ - tmp_loop = shl(L_subfr,1); - BASOP_SATURATE_WARNING_OFF - tmp16_2 = round_fx(L_shl(lp_gainp,2)); /*Q31->Q15, no severe saturation, because st->lp_gainp here is [0,1]*/ - BASOP_SATURATE_WARNING_ON - - FOR ( i=0; i< tmp_loop; i++ ) - { - /*st->lp_gainc += ( exc[i-2*L_subfr] - st->Mode2_lp_gainp * exc[i-2*L_subfr-(int)(st->old_fpitch+0.5f)] ) * - ( exc[i-2*L_subfr] - st->Mode2_lp_gainp * exc[i-2*L_subfr-(int)(st->old_fpitch+0.5f)] );*/ - tmp16_3 = sub - ( - exc[i-2*L_subfr] /*Q1*/, - mult_r(tmp16_2 /*Q15*/, exc[i-2*L_subfr-tmp16]/*Q1*/)/*Q1*/ - ); - L_acc = L_macNs(L_acc,tmp16_3,tmp16_3); /*Q3*/ - Overflow = 0; - L_c = L_macNs(L_c,0,0); /*Accumulate Carrys*/ - Carry = 0; - } - L_tmp = norm_llQ31(L_c,L_acc,&tmp_e);/*Q3,norm,tmp_e*/ - tmp_e = add(tmp_e,31-(add(shl(Q_exc,1),1))); /*L_tmp is Q31, now*/ - tmp16 = BASOP_Util_Divide3216_Scale(L_tmp/*Q31,norm,tmp_e*/,shl(L_subfr,1)/*Q15,15*/,&tmp2_e)/*Q15,tmp2_e+tmp_e-15*/; - tmp_e = sub(add(tmp2_e,tmp_e), 15); - - IF (tmp16 != 0) - { - tmp16 = Sqrt16(tmp16,&tmp_e); /*Q15,norm,tmp_e*/ - } - *lp_gainc = L_shl(L_deposit_l(tmp16),add(tmp_e,1)); /*15Q16*/ - -} - -static void calcGainc2(Word16 *exc, Word16 Q_exc, Word16 L_subfr, Word32* lp_gainc) -{ - Word16 i, cnt, tmp16 , tmp_e, tmp2_e; - Word32 L_c, L_acc, L_tmp; - - - Carry = 0; - Overflow = 0; - - L_c = L_deposit_l(0); - L_acc = L_deposit_l(0); - - cnt = shl(L_subfr,1); - - FOR (i=0; i < cnt; i++) - { - /* *gainc += ( exc[i-2*L_subfr] ) * ( exc[i-2*L_subfr]); */ - L_acc = L_macNs(L_acc, exc[i-2*L_subfr] /*Q1*/, exc[i-2*L_subfr] /*Q1*/); /*Q3*/ - Overflow = 0; - L_c = L_macNs(L_c,0,0); /* Accumulate Carrys */ - Carry = 0; - } - - L_tmp = norm_llQ31(L_c,L_acc,&tmp_e); /*Q3,norm,tmp_e*/ - tmp_e = add(tmp_e,31-(add(shl(Q_exc,1),1))); /*L_tmp is Q31, now*/ - tmp16 = BASOP_Util_Divide3216_Scale(L_tmp/*Q31,norm,tmp_e*/,shl(L_subfr,1)/*Q15,15*/,&tmp2_e)/*Q15,tmp2_e+tmp_e-15*/; - tmp_e = sub(add(tmp2_e,tmp_e), 15); - - IF ( tmp16 != 0 ) - { - tmp16 = Sqrt16(tmp16,&tmp_e); /*Q15,norm,tmp_e*/ - } - *lp_gainc = L_shl(L_deposit_l(tmp16),add(tmp_e,1)); /*15Q16*/ move32(); - -} - -/****************************************************** - -con_tcx - -\brief main function in time domain TCX concealment - -*******************************************************/ +/*-----------------------------------------------------------------* + * con_tcx() + * + * + *-----------------------------------------------------------------*/ void con_tcx( - Decoder_State_fx *st, /* i/o: coder memory state */ - Word16 synth[] /* i/o: synth[] *//*Q0 */ + Decoder_State* st, /* i/o: coder memory state */ + float synth[] /* i/o: synth[] */ ) { - Word16 i, s, c, L_frame, L_subfr, fLowPassFilter, T0; - Word16 n, mem_syn_r_size_old, mem_syn_r_size_new; - Word16 *noise; - Word16 mem_syn[M], *syn; - Word16 *exc, buf[OLD_EXC_SIZE_DEC+L_FRAME_MAX+L_FRAME_MAX/NB_SUBFR+1+L_FRAME_MAX/2]; - Word16 pre_emph_buf; - Word16 hp_filt[L_FIR_FER2]; - Word16 alpha; - Word16 tmp_deemph, gain, gainCNG, gain_inov; - Word16 *pt_exc, *pt1_exc; - Word16 Tc, tmpSeed; - Word16 fUseExtrapolatedPitch; - Word16 *ana_window; - Word16 r_h[M+1], A_local[M+1], mem, r_l[M+1]; - PWord16 const *w; - Word16 W1, W2, W12; - Word16 Q_r; - Word16 tmp16, tmp16_2, tmp_loop, tmp_e, gain_tmp; - Word16 gainCNG_e, noise_e, gain_inov_e ;/*Exponents for gainCNG, noise, gain_inov*/ - Word16 Q_syn; /*Q format of temporary synthesis buffer syn*/ - Word32 L_tmp, L_tmp2, step32_tmp; - Word32 predPitchLag, pitch_buf[NB_SUBFR16k], step32, gain32; - Word16 extrapolationFailed; - Word16 gainSynthDeemph; - Word16 gainSynthDeemph_e; - Word32 old_pitch_buf[2*NB_SUBFR16k+2]; - Word16 Q_exc, new_Q, exp_scale; - Word16 offset; - - /* inits */ - alpha = 0; - move16(); - fUseExtrapolatedPitch = 0; - move16(); - extrapolationFailed = 1; - move16(); - - noise_e = 0; - move16(); - Q_syn = -1; /*Q format of temporary synthesis buffer syn*/ move16(); - offset = 0; - move16(); + short i, n, L_frame, L_subfr, fLowPassFilter, T0; + int offset = 0; + int mem_syn_r_size_old, mem_syn_r_size_new; + float *noise; + float mem_syn[M], *syn; + float *exc, buf[OLD_EXC_SIZE_DEC+L_FRAME_MAX+L_FRAME_MAX/NB_SUBFR+1+L_FRAME_MAX/2]; + float pre_emph_buf; + float pitch_buf[NB_SUBFR16k], hp_filt[L_FIR_FER2]; + float predPitchLag, alpha = 0.0f; + float tmp_deemph, step, gain, gainCNG, gain_inov, ftmp; + float *pt_exc, *pt1_exc; + short Tc, tmpSeed; + short fUseExtrapolatedPitch=0; + float *ana_window; + float r[M+1], A_local[M+1], mem; + float *w; + short W1, W2; + short extrapolationFailed=1; + float gainSynthDeemph; + float tmp=0.f; + float old_pitch_buf[2*NB_SUBFR16k+2]; /* Framing parameters */ L_frame = st->L_frameTCX; - move16(); - /* L_subfr = st->L_frameTCX/st->nb_subfr */ - L_subfr = mult_r(st->L_frameTCX,div_s(1,st->nb_subfr)); - assert( L_subfr == st->L_frameTCX/st->nb_subfr ); - move32(); - w = st->tcx_cfg.tcx_mdct_windowFB; /*pointer - no need to instrument*/ + L_subfr = st->L_frameTCX/st->nb_subfr; + w = st->tcx_cfg.tcx_mdct_windowFB; W1 = st->tcx_cfg.tcx_mdct_window_lengthFB; - move16(); - W2 = shr(st->tcx_cfg.tcx_mdct_window_lengthFB,1); - W12 = shr(W1,1); + W2 = st->tcx_cfg.tcx_mdct_window_lengthFB/2; /* take the previous frame last pitch */ - Tc = round_fx(st->old_fpitchFB); + Tc = (short)(st->old_fpitchFB + 0.5f); - set16_fx(buf,0,shr(sizeof(buf),1)); /* initialize buf with 0 */ + set_zero(buf,sizeof(buf)/sizeof(buf[0])); - c = BASOP_Util_Divide1616_Scale( - L_frame, - st->L_frame_fx, - &s - ); - - FOR (i=0; i < (2*NB_SUBFR16k+2); i++) - { - old_pitch_buf[i] = L_shl(Mpy_32_16_1(st->old_pitch_buf_fx[i],c),s); - move32(); - } + v_multc(st->old_pitch_buf, (float)L_frame / st->L_frame, old_pitch_buf, 2*NB_SUBFR16k+2); /* set excitation memory*/ exc = buf+OLD_EXC_SIZE_DEC; - tmp_deemph = synth[-1]; - move16(); - pre_emph_buf = synth[-1]; - move16(); - test(); - IF ( (sub( st->nbLostCmpt, 1 ) == 0) || st->tcxConceal_recalc_exc ) + tmp_deemph = synth[-1]; + pre_emph_buf = synth[-1]; + + if( st->nbLostCmpt == 1 || st->tcxConceal_recalc_exc ) { /* apply pre-emphasis to the signal */ - mem = synth[-((shr(L_frame,1))+st->pit_max_TCX+M+M)-1]; - Q_exc = E_UTIL_f_preemph3(&(synth[-((shr(L_frame,1))+st->pit_max_TCX+2*M)]), st->preemph_fac, add(add(shr(L_frame,1),st->pit_max_TCX),shl(M,1)), &mem,1); - st->Mode2_lp_gainc = L_deposit_l(0); + mem = synth[-(L_frame/2+st->pit_max_TCX+2*M)-1]; - st->Mode2_lp_gainp = get_gain2( synth-2*L_subfr, synth-2*L_subfr-Tc, shl(L_subfr,1) ); - move32(); + preemph(&synth[-(L_frame/2+st->pit_max_TCX+2*M)], st->preemph_fac, L_frame/2+st->pit_max_TCX+2*M, &mem); + st->lp_gainc = 0.0f; - st->Mode2_lp_gainp = L_max(st->Mode2_lp_gainp,0); - st->Mode2_lp_gainp = L_min(st->Mode2_lp_gainp,65536l/*1.0f Q16*/); - st->Mode2_lp_gainp = L_shl(st->Mode2_lp_gainp, 13); + st->lp_gainp = get_gain( synth-2*L_subfr, synth-2*L_subfr-Tc, 2*L_subfr, NULL ); + if(st->lp_gainp < 0.0f) + { + st->lp_gainp = 0.0f; + } + + if(st->lp_gainp > 1.0f) + { + st->lp_gainp = 1.0f; + } ana_window = buf; - ham_cos_window(ana_window, mult(L_frame,24576/*0.75f Q15*/), shr(L_frame,2)); + ham_cos_window(ana_window, 3*L_frame/4, L_frame/4); /* Autocorrelation */ - autocorr_fx(&(synth[-L_frame-1]), M, r_h ,r_l , &Q_r , L_frame, ana_window, 0, 0); + autocorr( &(synth[-L_frame-1]), r, M, L_frame, ana_window, 0, 0, 0 ); /* Lag windowing */ - lag_wind( r_h,r_l, M, st->output_Fs_fx, LAGW_STRONG ); + lag_wind( r, M, st->output_Fs, LAGW_STRONG ); /* Levinson Durbin */ - E_LPC_lev_dur(r_h, r_l, A_local, NULL, M, NULL); + lev_dur(A_local, r, M, NULL); /* copy for multiple frame loss */ - Copy(A_local, st->old_Aq_12_8_fx, M+1); + mvr2r( A_local, st->old_Aq_12_8, M+1 ); /* Residu */ assert((2*L_subfr+Tc+1+M) <= st->old_synth_lenFB); - - BASOP_SATURATE_WARNING_OFF /*saturation possible in case of spiky synthesis*/ - Residu3_fx( - A_local, - &(synth[-(2*L_subfr+Tc+1+M)]), /*Qx = Q0*/ - &(exc[-(2*L_subfr+Tc+1+M)]), /*Qx+1 = Q1*/ - add(add(add(shl(L_subfr,1),Tc),1),M), - 1); - BASOP_SATURATE_WARNING_ON + residu(A_local, M, &(synth[-(2*L_subfr+Tc+1+M)]), &(exc[-(2*L_subfr+Tc+1+M)]), 2*L_subfr+Tc+1+M); } - ELSE + else { /* apply pre-emphasis to the signal */ mem = synth[-L_frame-1]; - Q_exc = E_UTIL_f_preemph3(&(synth[-L_frame]), st->preemph_fac, L_frame, &mem, 1); - Copy(st->old_Aq_12_8_fx, A_local, M+1); - offset = shr(L_frame,1); - IF(sub(st->last_good_fx, UNVOICED_TRANSITION) >= 0 ) + preemph(&synth[-L_frame], st->preemph_fac, L_frame, &mem); + mvr2r( st->old_Aq_12_8, A_local, M+1 ); + offset = L_frame/2; + + if(st->last_good >= UNVOICED_TRANSITION ) { - tmp16 = s_max(Tc - shr(L_frame,1), 0); - Copy_Scale_sig(st->old_excFB_fx, &(exc[-tmp16]), offset+tmp16, Q_exc-st->Q_exc); + i = max(Tc - L_frame/2, 0); + mvr2r(st->old_excFB, &(exc[-i]), offset+i); } - ELSE { - Copy_Scale_sig(st->old_excFB_fx, &(exc[-2*L_subfr]), 2*L_subfr+offset, Q_exc-st->Q_exc); + else + { + mvr2r(st->old_excFB, &(exc[-2*L_subfr]), 2*L_subfr+offset); } } @@ -254,659 +126,424 @@ void con_tcx( * PLC: Construct the harmonic part of excitation *-----------------------------------------------------------------*/ - test(); - test(); - IF( sub(st->last_good_fx, UNVOICED_CLAS) > 0 && !(sub(st->last_good_fx, UNVOICED_TRANSITION) == 0 && sub(st->core_ext_mode, GENERIC) == 0) ) + if(st->last_good != UNVOICED_CLAS && !((st->last_good == UNVOICED_TRANSITION) && (st->core_ext_mode == GENERIC)) ) { - - IF ( sub(st->nbLostCmpt,1) == 0 || st->tcxConceal_recalc_exc ) + if ( st->nbLostCmpt == 1 || st->tcxConceal_recalc_exc ) { - calcGainc( exc, Q_exc, st->old_fpitchFB, L_subfr, st->Mode2_lp_gainp, &(st->Mode2_lp_gainc)); + st->lp_gainc = 0.0f; + + for ( i=0; i<2*L_subfr; i++ ) + { + st->lp_gainc += ( exc[i-2*L_subfr] - st->lp_gainp * exc[i-2*L_subfr-Tc] ) * ( exc[i-2*L_subfr] - st->lp_gainp * exc[i-2*L_subfr-Tc] ); + } + st->lp_gainc = (float)sqrt(st->lp_gainc / (2.0f*L_subfr) ); } - - tmp16 = 0; - move16(); - if (L_sub(st->output_Fs_fx , 25600) > 0) + if( ( st->nbLostCmpt == 1 ) && st->rf_frame_type >= RF_TCXFD && st->rf_frame_type <= RF_TCXTD2 && st->use_partial_copy ) { - tmp16 = 1; - move16(); - } + predPitchLag = (st->tcxltp_pitch_int + st->tcxltp_pitch_fr/(float)st->pit_res_max) * (float)st->L_frameTCX / (float)st->L_frame; + T0 = (int)(predPitchLag+0.5f); - test(); - test(); - test(); - test(); - IF( ((sub(st->nbLostCmpt,1) == 0) || st->tcxConceal_recalc_exc) && sub(st->rf_frame_type,RF_TCXFD) >= 0 && sub(st->rf_frame_type,RF_TCXTD2) <= 0 && st->use_partial_copy ) - { - Word32 tcxltp_pitch_tmp = L_add(L_deposit_h(st->tcxltp_pitch_int), L_shl(L_deposit_l(div_s(st->tcxltp_pitch_fr,st->pit_res_max)),1)); /*15Q16*/ - Word16 scale_tmp = mult_r(st->L_frameTCX, getInvFrameLen(st->L_frame_fx)); /*getInvFrameLen()->9Q6*/ - Word16 tmp_shift = norm_s(scale_tmp); - predPitchLag = L_shl(Mpy_32_16_1(tcxltp_pitch_tmp, shl(scale_tmp, tmp_shift)), sub(9, tmp_shift)); - - T0 = round_fx(predPitchLag); - - test(); - test(); - test(); - if ( (T0 > 0) - && (sub(T0,Tc) != 0) - && (L_sub(L_deposit_h(abs_s(sub(T0,Tc)))/*Q16*/ , L_mult(4915/*.15f Q15*//*Q15*/,Tc/*Q0*/) /*Q16*/ ) < 0) - ) + if ((T0 > 0) && (T0 != Tc) && ((float)abs(T0-Tc) < 0.15f*Tc) ) { fUseExtrapolatedPitch = 1; - move16(); } } - ELSE + else { + pitch_pred_linear_fit( st->nbLostCmpt, st->last_good, old_pitch_buf, &(st->old_fpitchFB), + &predPitchLag, st->pit_min_TCX, st->pit_max_TCX, st->mem_pitch_gain, + st->output_Fs > 25600, st->plc_use_future_lag, &extrapolationFailed, st->nb_subfr); - pitch_pred_linear_fit( - st->nbLostCmpt, - st->last_good_fx, - old_pitch_buf, - &(st->old_fpitchFB), - &predPitchLag, - st->pit_min_TCX, - st->pit_max_TCX, - st->mem_pitch_gain, - tmp16, - st->plc_use_future_lag, - &extrapolationFailed, - st->nb_subfr - ); + T0 = (int)(predPitchLag+0.5f); - T0 = round_fx(predPitchLag); - test(); - test(); - test(); - if ( (T0 > 0) - && (sub(T0,Tc) != 0) - && (L_sub(L_deposit_h(abs_s(sub(T0,Tc)))/*Q16*/ , L_mult(4915/*.15f Q15*//*Q15*/,Tc/*Q0*/) /*Q16*/ ) < 0) - && (extrapolationFailed == 0) - ) + if ((T0 > 0) && (T0 != Tc) && ((float)abs(T0-Tc) < 0.15f*Tc) && extrapolationFailed == 0 ) { fUseExtrapolatedPitch = 1; - move16(); } } - fLowPassFilter = 0; - move16(); pt_exc = exc + offset; + pt1_exc = pt_exc - Tc; if (fUseExtrapolatedPitch != 0) { pt_exc = buf; } - test(); - IF( sub(st->stab_fac_fx ,32767/*1.f Q15*/) < 0 && sub(st->nbLostCmpt , 1) == 0 ) + + if(st->stab_fac < 1 && st->nbLostCmpt == 1 ) { /* pitch cycle is first low-pass filtered */ - - IF (L_sub(st->output_Fs_fx , 16000) <= 0) + for( i=0 ; i< Tc; i++ ) { - FOR( i=0 ; i< Tc; i++ ) + if (st->output_Fs <= 16000) { - move16(); - *pt_exc++ = mac_r(L_mac(L_mac(L_mac(L_mac(L_mac(L_mac(L_mac(L_mac(L_mac( - L_mult(174/* 0.0053f Q15*/, pt1_exc[-5]), - 0/* 0.0000f Q15*/, pt1_exc[-4]), - -1442/*-0.0440f Q15*/, pt1_exc[-3]), - 0/* 0.0000f Q15*/, pt1_exc[-2]), - 8641/* 0.2637f Q15*/, pt1_exc[-1]), - 18022/* 0.5500f Q15*/, pt1_exc[0] ), - 8641/* 0.2637f Q15*/, pt1_exc[1] ), - 0/* 0.0000f Q15*/, pt1_exc[2] ), - -1442/*-0.0440f Q15*/, pt1_exc[3] ), - 0/* 0.0000f Q15*/, pt1_exc[4] ), - 174/* 0.0053f Q15*/, pt1_exc[5] ); - pt1_exc++; + *pt_exc++ = ( 0.0053f * pt1_exc[-5] + + 0.0000f * pt1_exc[-4] + + -0.0440f * pt1_exc[-3] + + 0.0000f * pt1_exc[-2] + + 0.2637f * pt1_exc[-1] + + 0.5500f * pt1_exc[0] + + 0.2637f * pt1_exc[1] + + 0.0000f * pt1_exc[2] + + -0.0440f * pt1_exc[3] + + 0.0000f * pt1_exc[4] + + 0.0053f * pt1_exc[5]); } - } - ELSE /*(st->output_Fs_fx >= 32000)*/ - { - FOR( i=0 ; i< Tc; i++ ) + else /*(st->output_Fs >= 32000)*/ { - move16(); - *pt_exc++ = mac_r(L_mac(L_mac(L_mac(L_mac(L_mac(L_mac(L_mac(L_mac(L_mac( - L_mult(-174/*-0.0053f Q15*/, pt1_exc[-5]), - -121/*-0.0037f Q15*/, pt1_exc[-4]), - -459/*-0.0140f Q15*/, pt1_exc[-3]), - 590/* 0.0180f Q15*/, pt1_exc[-2]), - 8743/* 0.2668f Q15*/, pt1_exc[-1]), - 16355/* 0.4991f Q15*/, pt1_exc[0] ), - 8743/* 0.2668f Q15*/, pt1_exc[1] ), - 590/* 0.0180f Q15*/, pt1_exc[2] ), - -459/*-0.0140f Q15*/, pt1_exc[3] ), - -121/*-0.0037f Q15*/, pt1_exc[4] ), - -174/*-0.0053f Q15*/, pt1_exc[5] ); - pt1_exc++; + *pt_exc++ = (-0.0053f * pt1_exc[-5] + + -0.0037f * pt1_exc[-4] + + -0.0140f * pt1_exc[-3] + + 0.0180f * pt1_exc[-2] + + 0.2668f * pt1_exc[-1] + + 0.4991f * pt1_exc[0] + + 0.2668f * pt1_exc[1] + + 0.0180f * pt1_exc[2] + + -0.0140f * pt1_exc[3] + + -0.0037f * pt1_exc[4] + + -0.0053f * pt1_exc[5]); } + pt1_exc++; } - fLowPassFilter = 1; - move16(); } - ELSE + else { /* copy the first pitch cycle without low-pass filtering */ - FOR( i=0 ; i < Tc; i++ ) + for( i=0 ; i< Tc; i++ ) { *pt_exc++ = *pt1_exc++; - move16(); } fLowPassFilter = 1; - move16(); } if (fUseExtrapolatedPitch != 0) { pt1_exc = buf; } - tmp16 = add(sub(L_frame,imult1616(fLowPassFilter,Tc)),L_subfr); - FOR (i = 0; i < tmp16; i++) + + for (i = 0; i < L_frame-fLowPassFilter*Tc+L_subfr; i++) { *pt_exc++ = *pt1_exc++; - move16(); } - IF (fUseExtrapolatedPitch != 0) + if (fUseExtrapolatedPitch != 0) { - get_subframe_pitch(st->nb_subfr, - st->old_fpitch, - /* predPitchLag * L_frame/st->L_frame, */ - L_shr(Mpy_32_16_1(predPitchLag/*Q16*/, - mult_r(st->L_frame_fx/*Q0*/, - getInvFrameLen(L_frame)/*Q21*/ - )/*Q6*/ - )/*Q7*/, - 7-16)/*Q16*/, - pitch_buf); + get_subframe_pitch(st->nb_subfr, st->old_fpitch, predPitchLag * st->L_frame/L_frame, pitch_buf); PulseResynchronization(buf, exc, L_frame, st->nb_subfr, st->old_fpitchFB, predPitchLag); } - ELSE + else { - set32_fx( pitch_buf, st->old_fpitch, st->nb_subfr); + set_f(pitch_buf, st->old_fpitch, st->nb_subfr); } - IF ( sub(st->nbLostCmpt , 1) == 0 ) + if ( st->nbLostCmpt == 1 ) { pt_exc = exc+L_frame; - IF (T0 == 0) - { - pt1_exc = pt_exc - Tc; - } - ELSE - { - pt1_exc = pt_exc - T0; - } + pt1_exc = pt_exc - ((T0 == 0) ? Tc : T0); - tmp_loop = shr(L_frame,1); - FOR (i = 0; i < tmp_loop; i++) + for (i = 0; i < L_frame/2; i++) { *pt_exc++ = *pt1_exc++; - move16(); } } if (fUseExtrapolatedPitch != 0) { st->old_fpitchFB = predPitchLag; - move16(); } st->bpf_gain_param = 0; - move16(); /* PLC: calculate damping factor */ - alpha = Damping_fact(st->core_ext_mode, st->nbLostCmpt, st->last_good_fx, st->stab_fac_fx, &(st->Mode2_lp_gainp), 0);/*Q14*/ + alpha = Damping_fact(st->core_ext_mode, st->nbLostCmpt, st->last_good, st->stab_fac, &(st->lp_gainp), 0 ); - IF ( sub(st->nbLostCmpt , 1) == 0 ) + if( st->nbLostCmpt == 1 ) { - st->cummulative_damping = 32767/*1.f Q15*/; - move16(); + st->cummulative_damping = 1; } - ELSE + else { - st->cummulative_damping = shl(mult_r(st->cummulative_damping/*Q15*/,alpha/*Q14*/),1)/*Q15*/; + st->cummulative_damping *= alpha; } - gain32 = L_add(2147483647l/*1.f Q31*/, 0); /*Q31*/ - gain = 32767/*1.f Q15*/; /*Q15*/ move16(); - if( sub(st->rf_frame_type, RF_TCXTD1) == 0 && sub(st->use_partial_copy, 1) == 0 ) + gain = 1.0f; + if( st->rf_frame_type == RF_TCXTD1 && st->use_partial_copy == 1 ) { - gain32 = 1073741824l/*0.5f Q31*/; - gain = 16384/*0.5f Q15*/; + gain = 0.5f; } - /*step = (1.0f/(L_frame+(L_frame/2))) * (gain - alpha);*/ - tmp16 = shr(imult1616(3,L_frame),1); - tmp_e = norm_s(tmp16); - tmp16 = shl(tmp16,tmp_e); - tmp16 = div_s(16384/*1.f Q14*/,tmp16);/*Q15,1+tmp_e-15*/ - tmp16_2 = sub(shr(gain,1),alpha)/*Q14*/; - step32 = L_shl(L_mult(tmp16,tmp16_2)/*Q30, 1+tmp_e-15*/,add(1-14,tmp_e))/*Q31*/; + step = (1.0f/(L_frame+(L_frame/2))) * (gain - alpha); /* PLC: Apply fade out */ - tmp_loop = shr(imult1616(L_frame,3),1); - FOR ( i=offset; i < tmp_loop; i++ ) + for( i=offset; i < L_frame+(L_frame/2); i++ ) { - exc[i] = mult_r(exc[i],round_fx(gain32))/*Q1*/; - move16(); - gain32 = L_sub(gain32 , step32); + exc[i] *= gain; + gain -= step; } - /* update old exc without random part */ - offset = s_max(round_fx(st->old_fpitchFB) - shr(L_frame,1), 0); - Copy(exc+L_frame-offset, st->old_excFB_fx, shr(L_frame,1)+offset); + offset = max(((short)(st->old_fpitchFB + 0.5f)) - L_frame/2, 0); + mvr2r(exc+L_frame-offset, st->old_excFB, L_frame/2+offset); + /* copy old_exc as 16kHz for acelp decoding */ - IF ( sub(st->nbLostCmpt, 1) == 0 ) + if(st->nbLostCmpt == 1) { - lerp(exc - shr(L_frame,1), st->old_exc_fx, L_EXC_MEM_DEC, add(L_frame, shr(L_frame,1))); + lerp(exc-L_frame/2, st->old_exc, L_EXC_MEM_DEC, L_frame+L_frame/2); } - ELSE + else { - Copy(st->old_exc_fx+L_FRAME16k, st->old_exc_fx, L_FRAME16k/2); - lerp(exc, st->old_exc_fx+L_FRAME16k/2, L_FRAME16k, L_frame); + mvr2r(st->old_exc+L_FRAME16k, st->old_exc, L_FRAME16k/2); + lerp(exc, st->old_exc+L_FRAME16k/2, L_FRAME16k, L_frame); } - st->Q_exc = Q_exc; } - ELSE + else { /* No harmonic part */ - set16_fx(&exc[0], 0, add(L_frame,shr(L_frame,1))); - IF ( sub(st->nbLostCmpt , 1) == 0 ) + set_zero(&exc[0], L_frame+L_frame/2); + + if ( st->nbLostCmpt == 1 ) { - calcGainc2(&exc[0], Q_exc, L_subfr, &(st->Mode2_lp_gainc)); + st->lp_gainc = 0.0f; + + for ( i=0; i<2*L_subfr; i++ ) + { + st->lp_gainc += ( exc[i-2*L_subfr] ) * ( exc[i-2*L_subfr]); + } + st->lp_gainc = (float)sqrt(st->lp_gainc / (2.0f*L_subfr) ); } - set32_fx( pitch_buf, L_deposit_h(L_SUBFR), st->nb_subfr); + + set_f( pitch_buf, (float)L_SUBFR, st->nb_subfr); + /* PLC: calculate damping factor */ - alpha = Damping_fact(st->core_ext_mode, st->nbLostCmpt, st->last_good_fx, st->stab_fac_fx, &(st->Mode2_lp_gainp), 0);/*Q14*/ + alpha = Damping_fact(st->core_ext_mode, st->nbLostCmpt, st->last_good, st->stab_fac, &(st->lp_gainp), 0); } /*-----------------------------------------------------------------* * Construct the random part of excitation *-----------------------------------------------------------------*/ - tmpSeed = st->seed_acelp; - move16(); - noise = buf; - noise_e = 1;/*set exponent of noise to 1*/ move16(); - tmp_loop = add(L_frame,L_FIR_FER2-1); - FOR (i = 0; i < tmp_loop; i++) + tmpSeed = st->seed_acelp; + noise = buf; + + for (i = 0; i < L_frame+L_FIR_FER2-1; i++) { - tmpSeed = own_random2_fx(tmpSeed); - noise[i] = shr(tmpSeed,noise_e); - move16(); + noise[i] = (float)own_random(&tmpSeed); } st->seed_acelp = tmpSeed; - move16(); - tmp_loop = add(add(L_frame,shr(L_frame,1)) ,shl(L_FIR_FER2,1)); - FOR ( ; i < tmp_loop; i++) + for ( ; i < L_frame+(L_frame/2)+2*L_FIR_FER2; i++) { - tmpSeed = own_random2_fx(tmpSeed); - noise[i] = shr(tmpSeed,noise_e); - move16(); + noise[i] = (float)own_random(&tmpSeed); } - test(); - IF (sub(st->last_good_fx , VOICED_CLAS)==0 || sub(st->last_good_fx , ONSET)==0) - { - tmp16 = 19661/*0.6f Q15*/; - move16(); - if ( L_sub(st->output_Fs_fx,16000) <= 0 ) - { - tmp16 = 6554/*0.2f Q15*/; - move16(); - } + if (st->last_good == VOICED_CLAS || st->last_good == ONSET) + { mem = noise[0]; - move16(); - preemph_copy_fx(&noise[1], &noise[1], tmp16, L_frame+(L_frame/2)+L_FIR_FER2, &mem); + preemph(&noise[1], st->output_Fs<=16000 ? 0.2f : 0.6f, L_frame+(L_frame/2)+L_FIR_FER2, &mem); } + /* high rate filter tuning */ - IF ( L_sub(st->output_Fs_fx,16000) <= 0 ) + if(st->output_Fs<=16000) { - FOR( i=0; i< L_FIR_FER2; i++ ) + for( i=0; i< L_FIR_FER2; i++ ) { hp_filt[i] = h_high3_16[i]; - move16(); } } - ELSE /*(st->output_Fs_fx==32000)*/ + else /*(st->output_Fs==32000)*/ { - FOR( i=0; i< L_FIR_FER2; i++ ) + for( i=0; i< L_FIR_FER2; i++ ) { hp_filt[i] = h_high3_32[i]; - move16(); } } - IF ( sub(st->nbLostCmpt,1) == 0 ) - { - highPassFiltering(st->last_good_fx, add(add(L_frame, shr(L_frame,1)),L_FIR_FER2), noise, hp_filt, L_FIR_FER2); - } - ELSE - { - IF(sub( st->last_good_fx , UNVOICED_TRANSITION) > 0 ) - { - tmp_loop = add(add(L_frame,shr(L_frame,1)),L_FIR_FER2); - gain_tmp = negate(add(-32768,st->cummulative_damping));/*Q15*/ - FOR( i=0 ; i < tmp_loop; i++ ) - { - /*noise[i] = (1-st->cummulative_damping)*noise[i] + st->cummulative_damping*dot_product(&noise[i], hp_filt, L_FIR_FER2);*/ - move16(); - L_tmp2 = L_mac(0, noise[i+L_FIR_FER2-11], hp_filt[0+L_FIR_FER2-11]); - L_tmp2 = L_mac(L_tmp2, noise[i+L_FIR_FER2-10], hp_filt[0+L_FIR_FER2-10]); - L_tmp2 = L_mac(L_tmp2, noise[i+L_FIR_FER2-9], hp_filt[0+L_FIR_FER2-9]); - L_tmp2 = L_mac(L_tmp2, noise[i+L_FIR_FER2-8], hp_filt[0+L_FIR_FER2-8]); - L_tmp2 = L_mac(L_tmp2, noise[i+L_FIR_FER2-7], hp_filt[0+L_FIR_FER2-7]); - L_tmp2 = L_mac(L_tmp2, noise[i+L_FIR_FER2-6], hp_filt[0+L_FIR_FER2-6]); - L_tmp2 = L_mac(L_tmp2, noise[i+L_FIR_FER2-5], hp_filt[0+L_FIR_FER2-5]); - L_tmp2 = L_mac(L_tmp2, noise[i+L_FIR_FER2-4], hp_filt[0+L_FIR_FER2-4]); - L_tmp2 = L_mac(L_tmp2, noise[i+L_FIR_FER2-3], hp_filt[0+L_FIR_FER2-3]); - L_tmp2 = L_mac(L_tmp2, noise[i+L_FIR_FER2-2], hp_filt[0+L_FIR_FER2-2]); - L_tmp2 = L_mac(L_tmp2, noise[i+L_FIR_FER2-1], hp_filt[0+L_FIR_FER2-1]); - L_tmp2 = Mpy_32_16_1(L_tmp2, st->cummulative_damping/*Q15*/);/*Q0, noise_e*/ - noise[i] = mac_r(L_tmp2, gain_tmp,noise[i]);/*Q15, noise_e*/ + if ( st->nbLostCmpt == 1 ) + { + highPassFiltering(st->last_good, L_frame+L_frame/2+L_FIR_FER2, noise, hp_filt, L_FIR_FER2); + } + else + { + if(st->last_good > UNVOICED_TRANSITION ) + { + for( i=0 ; i< L_frame+L_frame/2+L_FIR_FER2; i++ ) + { + noise[i] = (1-st->cummulative_damping)*noise[i]+ st->cummulative_damping*dotp(&noise[i], hp_filt, L_FIR_FER2 ); } } } /* PLC: [TCX: Fade-out] retrieve background level */ - tmp16 = 32767; - move16(); - gainSynthDeemph = getLevelSynDeemph(&(tmp16), - A_local, - M, - shr(L_frame,2), - st->preemph_fac, - 1, - &gainSynthDeemph_e); - IF (0 != st->tcxonly) + tmp = 1.0f; + gainSynthDeemph = getLevelSynDeemph(&(tmp), A_local, L_frame/4, st->preemph_fac, 1); + if (st->tcxonly) { - /* gainCNG = st->conCngLevelBackgroundTrace/gainSynthDeemph; */ - BASOP_Util_Divide_MantExp(st->conCngLevelBackgroundTrace, - st->conCngLevelBackgroundTrace_e, - gainSynthDeemph, gainSynthDeemph_e, - &gainCNG, &gainCNG_e); + gainCNG = st->CngLevelBackgroundTrace_bfi/gainSynthDeemph; } - ELSE + else { - /* gainCNG = st->cngTDLevel/gainSynthDeemph; */ - BASOP_Util_Divide_MantExp(st->cngTDLevel, - st->cngTDLevel_e, - gainSynthDeemph, gainSynthDeemph_e, - &gainCNG, &gainCNG_e); + gainCNG = st->cngTDLevel/gainSynthDeemph; + } + gain = st->lp_gainc; /* start-of-the-frame gain */ + + if( st->rf_frame_type == RF_TCXTD1 && st->use_partial_copy == 1 ) + { + gain *= 0.7f; } - gain32 = L_add(st->Mode2_lp_gainc, 0); /* start-of-the-frame gain - Q16*/ - if( sub(st->rf_frame_type, RF_TCXTD1) == 0 && sub(st->use_partial_copy, 1) == 0 ) - { - gain32 = Mpy_32_16_1(gain32, 22938/*0.7f Q15*/); - } - L_tmp = L_shl(gain32,1); + ftmp = 2.0f * gain; - IF (L_sub(L_shl(L_deposit_h(gainCNG),sub(gainCNG_e,31-16)/*Q16*/) , L_tmp) > 0) + if (gainCNG > ftmp) { - gainCNG_e = sub(15+1,norm_l(L_tmp)); - gainCNG = extract_l(L_shr(L_tmp,gainCNG_e));/*Q15,gainCNG_e*/ - gainCNG_e = sub(gainCNG_e,1); + gainCNG = ftmp; } - /* st->Mode2_lp_gainc = alpha * (st->Mode2_lp_gainc) + (1.0f - alpha) * gainCNG;*/ /* end-of-the-frame gain */ - - L_tmp = Mpy_32_16_1(st->Mode2_lp_gainc,alpha)/*Q15*/; - L_tmp2 = L_mult(sub(16384/*1.f Q14*/,alpha)/*Q14*/,gainCNG/*Q15,gainCNG_e*/);/*Q30,gainCNG_e*/ - st->Mode2_lp_gainc = BASOP_Util_Add_Mant32Exp(L_tmp,31-15,L_tmp2,add(gainCNG_e,31-30),&tmp_e);/*Q31*/ move32(); - st->Mode2_lp_gainc = L_shl(st->Mode2_lp_gainc,sub(tmp_e,31-16)); - move32(); + st->lp_gainc = alpha * st->lp_gainc + (1.0f - alpha) * gainCNG; /* end-of-the-frame gain */ /* PLC: [TCX: Fade-out] Linearly attenuate the gain through the frame */ - /*step = (1.0f/L_frame) * (gain - (st->Mode2_lp_gainc));*/ - L_tmp = L_sub(gain32,st->Mode2_lp_gainc);/*Q16*/ - tmp_e = norm_l(L_tmp); - L_tmp = L_shl(L_tmp,tmp_e);/*Q16,-tmp_e*/ - step32 = Mpy_32_16_1(L_tmp/*Q16,-tmp_e*/,getInvFrameLen(L_frame)/*W16Q21*/);/*Q22,-tmp_e*/ - step32 = L_shl(step32,sub((25-22),tmp_e));/*Q25*/ - + step = (1.0f/L_frame) * (gain - st->lp_gainc); pt_exc = noise + L_FIR_FER2/2; - /*gain_inov = 1.0f / (float)sqrt( dot_product( pt_exc, pt_exc, L_frame ) / L_frame + 0.01f );*//* normalize energy */ - L_tmp = Dot_productSq16HQ(0,pt_exc/*Q0,15+1*/,L_frame,&tmp_e)/*Q31,tmp_e+16+16*/; - L_tmp = Mpy_32_16_1(L_tmp,getInvFrameLen(L_frame)/*W16Q21*/)/*W32Q37,tmp_e+16+16*//*Q5,tmp_e*/; - tmp_e = add(tmp_e,31-5);/*-->Q31*/ - gain_inov = round_fx(ISqrt32(L_tmp,&tmp_e));/*Q15,tmp_e*/ - gain_inov_e = tmp_e; - move16(); - test(); - test(); - IF (sub(st->last_good_fx , UNVOICED_CLAS) == 0 && sub(st->core_ext_mode , UNVOICED) != 0) - { - gain_inov = mult_r(gain_inov,26214/*0.8f Q15*/); - } - ELSE IF (!( sub(st->last_good_fx , UNVOICED_CLAS) == 0 || sub(st->last_good_fx , UNVOICED_TRANSITION) == 0 )) - { - /*gain_inov *= (1.1f- 0.75*st->lp_gainp);*/ - L_tmp = Mpy_32_16_1(L_sub(590558016l/*1.1f Q29*/, Mpy_32_16_1(st->Mode2_lp_gainp,24576))/*Q29*/,gain_inov/*Q15,gain_inov_e*/);/*Q29,gain_inov_e*/ - tmp_e = norm_l(L_tmp); - L_tmp = L_shl(L_tmp,tmp_e); - gain_inov_e = add(sub(gain_inov_e,tmp_e),31-29);/*->Q31*/ - gain_inov = round_fx(L_tmp);/*Q15,gain_inov_e*/ - } + gain_inov = 1.0f / (float)sqrt( dotp( pt_exc, pt_exc, L_frame ) / L_frame + 0.01f );/* normalize energy */ - st->Mode2_lp_gainp = L_shr(L_deposit_h(alpha/*Q14*/)/*Q14+16*/,1);/*Q29*/ + if ((st->last_good == UNVOICED_CLAS) && (st->core_ext_mode != UNVOICED)) + { + gain_inov *= 0.8f; + } + else if (!((st->last_good == UNVOICED_CLAS) || (st->last_good == UNVOICED_TRANSITION))) + { + gain_inov *= (1.1f- 0.75*st->lp_gainp); + } + st->lp_gainp = alpha; pt_exc = noise; /* non-causal ringing of the FIR filter */ - tmp_e = norm_l(gain32); - tmp_e = sub(tmp_e,5); /*5 Bit additional Headroom for the gain - should be enough*/ - gain32 = L_shl(gain32,tmp_e);/*Q16,-tmp_e*/ - L_tmp = Mpy_32_16_1(gain32/*Q16,-tmp_e*/, gain_inov/*Q15,gain_inov_e*/)/*Q16,gain_inov_e-tmp_e*/; + for( i=0 ; i< L_FIR_FER2/2; i++ ) + { + *pt_exc++ *= (gain_inov * gain); + } - gain_tmp = round_fx(L_tmp);/*Q0, gain_inov_e-tmp_e*/ + for( i=0 ; i< L_frame+L_FIR_FER2/2; i++ ) /* Actual filtered random part of excitation */ + { + *pt_exc++ *= (gain_inov * gain); + gain -= step; + } - FOR( i=0 ; i< L_FIR_FER2/2; i++ ) + for( i=0 ; i< (L_frame/2); i++ ) /* causal ringing of the FIR filter */ { - *pt_exc = mult_r(*pt_exc,gain_tmp);/*Q-15,noise_e+gain_inov_e-tmp_e*/ move16(); - pt_exc++; + *pt_exc++ *= (gain_inov * gain); } - tmp16 = add(L_frame,L_FIR_FER2/2); - step32_tmp = L_shl(step32/*Q25*/,sub(tmp_e,(25-16)));/*Q16,-tmp_e*/ - FOR( i=0 ; i< tmp16; i++ ) /* Actual filtered random part of excitation */ - { - *pt_exc = mult_r(*pt_exc, gain_tmp); - move16(); - pt_exc++; - gain32 = L_sub(gain32/*Q16,-tmp_e*/,step32_tmp);/*Q16,-tmp_e*/ - gain_tmp = mult_r(round_fx(gain32/*Q16,-tmp_e*/)/*Q0*/, gain_inov/*Q15,gain_inov_e*/)/*Q0,gain_inov_e-tmp_e*/; - } - tmp16 = shr(L_frame,1); - FOR( i=0 ; i< tmp16; i++ ) /* causal ringing of the FIR filter */ - { - *pt_exc = mult_r(*pt_exc , gain_tmp); - move16(); - pt_exc++; - } - noise_e = add(sub(add(noise_e,gain_inov_e),tmp_e),15);/*--> noise is Q0, noise_e*/ - /*buf[0;L_FIR_FER2 + L_Frame + L_Frame/2] Q0, noise_e*/ /*-----------------------------------------------------------------* * Construct the total excitation *-----------------------------------------------------------------*/ - IF( sub(st->last_good_fx , UNVOICED_TRANSITION) >= 0 ) + if(st->last_good >= UNVOICED_TRANSITION ) { - tmp16 = add(L_frame,shr(L_frame,1)); - FOR( i=0 ; i< tmp16; i++ ) + for( i=0 ; i< (L_frame+L_frame/2); i++ ) { - exc[i] = add(exc[i] , shl(noise[i+(L_FIR_FER2/2)],Q_exc+noise_e));/*Q1*/ move16(); + exc[i] += noise[i+(L_FIR_FER2/2)]; } } - ELSE + else { - bufferCopyFx(noise+L_FIR_FER2/2, exc, add(L_frame , shr(L_frame,1)),0/*Q_noise*/, noise_e, Q_exc, 0/*exc_e*/); - Copy(exc+L_frame-2*L_subfr, st->old_excFB_fx, 2*L_subfr+shr(L_frame,1)); + mvr2r(noise+L_FIR_FER2/2, exc, L_frame+L_frame/2); + mvr2r(exc+L_frame-2*L_subfr, st->old_excFB, 2*L_subfr+L_frame/2); + /* copy old_exc as 16kHz for acelp decoding */ - IF ( sub(st->nbLostCmpt, 1) == 0 ) + if(st->nbLostCmpt == 1) { - lerp(exc, st->old_exc_fx, L_EXC_MEM_DEC, add(L_frame, shr(L_frame,1))); + lerp(exc, st->old_exc, L_EXC_MEM_DEC, L_frame+L_frame/2); } - ELSE { - Copy(st->old_exc_fx+L_FRAME16k, st->old_exc_fx, L_FRAME16k/2); - lerp(exc, st->old_exc_fx+L_FRAME16k/2, L_FRAME16k, L_frame); + else + { + mvr2r(st->old_exc+L_FRAME16k, st->old_exc, L_FRAME16k/2); + lerp(exc, st->old_exc+L_FRAME16k/2, L_FRAME16k, L_frame); } - st->Q_exc = Q_exc; } - /*buf[0;L_FIR_FER2 + L_Frame + L_Frame/2] Q0, noise_e*/ - /*buf[OLD_EXC_SIZE_DEC;3/2 L_frame] Q1*/ /* Update Pitch Lag memory */ - Copy32( &st->old_pitch_buf_fx[st->nb_subfr], st->old_pitch_buf_fx, st->nb_subfr ); - Copy32( pitch_buf, &st->old_pitch_buf_fx[st->nb_subfr], st->nb_subfr ); + mvr2r( &st->old_pitch_buf[st->nb_subfr], st->old_pitch_buf, st->nb_subfr ); + mvr2r( pitch_buf, &st->old_pitch_buf[st->nb_subfr], st->nb_subfr ); /*----------------------------------------------------------* * - compute the synthesis speech * *----------------------------------------------------------*/ syn = buf + M; - Copy(synth-M, buf, M); + mvr2r(synth-M, buf, M); + mvr2r( buf, mem_syn, M); - new_Q = sub(Q_exc, 3); - new_Q = s_max(new_Q, -1); + syn_filt(A_local, M, &exc[0], &syn[0], L_frame+ (L_frame/2), mem_syn, 1); - tmp16 = s_min(new_Q, st->prev_Q_syn); - st->prev_Q_syn = new_Q; - move16(); - - exp_scale = sub(tmp16, Q_exc-1); - Q_syn = tmp16; - move16(); - - Copy_Scale_sig(buf, mem_syn, M, exp_scale); - - tmp_deemph = shl(tmp_deemph,Q_syn); - st->Q_syn = Q_syn; - - /*buf[OLD_EXC_SIZE_DEC;3/2 L_frame] Q1: exc*/ - /*buf[0;M] Q0: mem_syn*/ - - E_UTIL_synthesis( - sub(Q_exc, Q_syn), - A_local, - &exc[0], - &syn[0], - add(L_frame, shr(L_frame,1)), - mem_syn, - 1, - M); - - /*buf[OLD_EXC_SIZE_DEC;3/2 L_frame-1] Q1: exc*/ - /*buf[0;M-1] Q0: mem_syn*/ - /*buf[M;3/2 L_frame-1] Q-1: syn*/ - - n = extract_h(L_mult(L_frame,9216/*(float)N_ZERO_MDCT_NS/(float)FRAME_SIZE_NS Q15*/)); + n = (short)((float)L_frame*N_ZERO_MDCT_NS/FRAME_SIZE_NS); /* update ACELP synthesis memory */ - mem_syn_r_size_old = shr(L_frame,4); /* replace 1.25/20.0 by shr(4) */ - /* copy mem_syn as 16kHz */ - mem_syn_r_size_new = shr(L_FRAME16k,4); /* replace 1.25/20.0 by shr(4) */ + mem_syn_r_size_old=(int)(1.25*L_frame/20.f); - Copy(syn+L_frame-L_SYN_MEM, st->mem_syn_r, L_SYN_MEM); - lerp(st->mem_syn_r+L_SYN_MEM-mem_syn_r_size_old, st->mem_syn_r+L_SYN_MEM-mem_syn_r_size_new, mem_syn_r_size_new, mem_syn_r_size_old); - Copy(st->mem_syn_r+L_SYN_MEM-M, st->mem_syn2_fx, M); + /* copy mem_syn as 16kHz */ + mem_syn_r_size_new=(int)(1.25*L_FRAME16k/20.f); + mvr2r(syn+L_frame-L_SYN_MEM, st->mem_syn_r, L_SYN_MEM); + lerp( st->mem_syn_r+L_SYN_MEM-mem_syn_r_size_old, st->mem_syn_r+L_SYN_MEM-mem_syn_r_size_new, mem_syn_r_size_new, mem_syn_r_size_old ); + mvr2r( st->mem_syn_r+L_SYN_MEM-M, st->mem_syn2, M ); /* Deemphasis and output synth and ZIR */ - deemph_fx(syn, st->preemph_fac, add(L_frame,shr(L_frame,1)), &tmp_deemph); - bufferCopyFx(syn+L_frame-M-1, st->syn, 1+M, Q_syn, 0, 0, 0); + deemph(syn, st->preemph_fac, L_frame+L_frame/2, &tmp_deemph); + mvr2r(syn+L_frame-M-1, st->syn, 1+M); - lerp( syn+L_frame-shr(L_frame, 1), st->old_syn_Overl, shr(st->L_frame_fx, 1), shr(L_frame, 1) ); - Copy(syn+L_frame-n, st->old_out_fx, sub(L_frame,n)); + lerp( syn+L_frame-L_frame/2, st->old_syn_Overl, st->L_frame/2, L_frame/2 ); + mvr2r(syn+L_frame-n, st->old_out, L_frame-n); - FOR (i=0; i < W12; i++) + for (i = 0; i < W1; i++) { - st->old_out_fx[i+n] = round_fx(Mpy_32_16_1(L_mult(w[i].v.re,w[i].v.re),st->old_out_fx[i+n])); - } - FOR ( ; i < W1; i++) - { - st->old_out_fx[i+n] = round_fx(Mpy_32_16_1(L_mult(w[W12-1-(i-W12)].v.im,w[W12-1-(i-W12)].v.im),st->old_out_fx[i+n])); + st->old_out[i+n] *= w[W1-1-i]*w[W1-1-i]; } + set_zero(&st->old_out[W1+n], n); - set16_fx(&st->old_out_fx[W1+n], 0, n); + mvr2r(syn, synth, L_frame); - st->Q_old_wtda = Q_syn; - move16(); + mvr2r(syn+L_frame, st->syn_OverlFB, L_frame/2); - /* As long as there is no synth scaling factor introduced, which - is given to the outside, there might occur overflows here */ - BASOP_SATURATE_WARNING_OFF - bufferCopyFx(syn, synth, L_frame, Q_syn, 0, 0, 0); - BASOP_SATURATE_WARNING_ON - - Copy_Scale_sig(syn+L_frame, st->syn_OverlFB, shr(L_frame,1), negate(Q_syn)); - - /* copy total excitation exc2 as 16kHz for acelp mode1 decoding */ - lerp(exc, st->old_exc2_fx, L_EXC_MEM, L_frame); - lerp(syn, st->old_syn2_fx, L_EXC_MEM, L_frame); - st->bfi_pitch_fx/*Q6*/ = round_fx(L_shl(pitch_buf[st->nb_subfr-1]/*15Q16*/,6/*Q6*/)); - move16(); - st->bfi_pitch_frame_fx = st->L_frame_fx; - move16(); + /* copy total excitation exc2 as 16kHz for ACELP MODE1 decoding */ + lerp( exc, st->old_exc2, L_EXC_MEM, L_frame ); + lerp( syn, st->old_syn2, L_EXC_MEM, L_frame ); + st->bfi_pitch = pitch_buf[st->nb_subfr-1]; + st->bfi_pitch_frame = st->L_frame; /* create aliasing and windowing need for transition to TCX10/5 */ - bufferCopyFx(syn+L_frame, st->syn_Overl_TDACFB, shr(L_frame,1),Q_syn,0,-1,0); + mvr2r(syn+L_frame, st->syn_Overl_TDACFB, L_frame/2); - FOR (i=0 ; i < W12 ; i++) + for (i=0; isyn_Overl_TDACFB[i] , w[i].v.re); - move16(); - } - FOR ( ; i syn_Overl_TDACFB[i],w[W12-1-(i-W12)].v.im); - move16(); + buf[i] = st->syn_Overl_TDACFB[i]*w[W1-1-i]; } - - FOR (i=0; isyn_Overl_TDACFB[i] = add(buf[i] , buf[W1-1-i]); - move16(); + st->syn_Overl_TDACFB[i] = buf[i]+buf[W1-1-i]; /* A-D */ } - FOR (i=0; isyn_Overl_TDACFB[W2+i] = add(buf[W2+i] , buf[W1-1-W2-i]); - move16(); + st->syn_Overl_TDACFB[W2+i] = buf[W2+i]+buf[W1-1-W2-i];/* B-C */ } - FOR (i=0 ; i < W12 ; i++) + for (i=0; isyn_Overl_TDACFB[i] = mult_r(st->syn_Overl_TDACFB[i],w[i].v.re); - move16(); - } - FOR ( ; i syn_Overl_TDACFB[i] = mult_r(st->syn_Overl_TDACFB[i],w[W12-1-(i-W12)].v.im); - move16(); + st->syn_Overl_TDACFB[i] *= w[W1-1-i]; } st->tcx_cfg.tcx_curr_overlap_mode = FULL_OVERLAP; - synth[-1] = pre_emph_buf; - move16(); - /* update memory for low band */ - Scale_sig(st->old_syn_Overl, shr(st->L_frame_fx, 1), sub(-1, Q_syn)); - lerp( st->syn_OverlFB, st->syn_Overl, shr(st->L_frame_fx, 1), shr(L_frame, 1) ); - lerp( st->syn_Overl_TDACFB, st->syn_Overl_TDAC, shr(st->L_frame_fx, 1), shr(L_frame, 1) ); - lerp( st->old_out_fx, st->old_out_LB_fx, st->L_frame_fx, L_frame ); + lerp( st->syn_OverlFB, st->syn_Overl, st->L_frame/2, L_frame/2 ); + lerp( st->syn_Overl_TDACFB, st->syn_Overl_TDAC, st->L_frame/2, L_frame/2 ); + lerp( st->old_out, st->old_outLB, st->L_frame, L_frame ); - st->old_enr_LP = Enr_1_Az_fx(A_local, L_SUBFR); /*Q3*/ + st->old_enr_LP = enr_1_Az( A_local, L_SUBFR ); return; } - diff --git a/src/libs/libevs/lib_dec/er_scale_syn.cpp b/src/libs/libevs/lib_dec/er_scale_syn.cpp old mode 100755 new mode 100644 index 031336d4..96132f26 --- a/src/libs/libevs/lib_dec/er_scale_syn.cpp +++ b/src/libs/libevs/lib_dec/er_scale_syn.cpp @@ -1,15 +1,14 @@ /*==================================================================================== - EVS Codec 3GPP TS26.442 Apr 03, 2018. Version 12.11.0 / 13.6.0 / 14.2.0 + EVS Codec 3GPP TS26.443 Nov 13, 2018. Version 12.11.0 / 13.7.0 / 14.3.0 / 15.1.0 ====================================================================================*/ -/*This file is up to date with trunk rev 36531*/ - #include #include -#include "prot_fx.h" -#include "basop_util.h" -#include "cnst_fx.h" -#include "stl.h" +#include "prot.h" +#include "cnst.h" + + + /*----------------------------------------------------------------------------------* @@ -18,112 +17,87 @@ * Estimate damping factor *----------------------------------------------------------------------------------*/ -/*This BASOP version was ported based on trunk rev. 27621 and updated based on trunk rev. 29287, re-updated based on trunk rev. 32244 */ -Word16 Damping_fact( /* o : damping factor *//*Q14*/ - const Word16 coder_type, /* i : coding type in last good received frame */ - const Word16 nbLostCmpt, /* i : counter of consecutive bfi frames */ - const Word16 last_good, /* i : last good frame class */ - const Word16 stab_fac, /* i : ISF stability factor *//*Q15*/ - Word32 *lp_gainp, /*i/o: damped pitch gain *//*2Q29 Word32!*/ - const Word16 core /* i : current coding mode */ -) +float Damping_fact( const short coder_type, int nbLostCmpt, short last_good, float stab_fac, float *lp_gainp, int core) { - Word16 alpha; /*Q14*/ - Word16 gain; /*Q14*/ - Word32 lp_tmp; - Word16 s_gainp; - Word32 gain32; + float alpha, gain; - IF (core == ACELP_CORE) + if(core == ACELP_CORE) { - alpha = mult_r(_ALPHA_VT_FX,16384); /* rapid convergence to 0 *//*Q14*/ - test(); - test(); - test();/*ELSEIF*/ - test(); - test();/*ELSEIF*/ - IF( ( sub(coder_type, UNVOICED) == 0) && (sub(nbLostCmpt, 3) <= 0)) /* Clear unvoiced last good frame */ + alpha = ALPHA_VT;/* rapid convergence to 0 */ + if( ( coder_type == UNVOICED) && (nbLostCmpt <= 3)) /* Clear unvoiced last good frame */ { - alpha = mult_r(_ALPHA_UU_FX,16384); /*Q14*/ + alpha = ALPHA_UU; } - ELSE IF( sub(last_good, UNVOICED_CLAS) == 0 ) + else if( last_good == UNVOICED_CLAS ) { - IF( sub(nbLostCmpt,1) == 0 ) + if( nbLostCmpt == 1 ) { /* If stable, do not decrease the energy, pitch gain = 0 */ - /* * (1.0f - 2.0f*_ALPHA_U_FX) + 2.0f*MODE2_ALPHA_U; */ /* [0.8, 1.0] */ - alpha = add(mult_r(stab_fac,sub(16384,_ALPHA_U_FX)),_ALPHA_U_FX); + alpha = stab_fac * (1.0f - 2.0f*ALPHA_U) + 2.0f*ALPHA_U; /* [0.8, 1.0] */ } - ELSE IF (sub(nbLostCmpt, 2) == 0 ) + else if (nbLostCmpt == 2 ) { - /*alpha = _ALPHA_U_FX * 1.5f;*/ /* 0.6 */ - alpha = mult_r(_ALPHA_U_FX, 24576/*1.5f Q14*/); /*Q14*/ + alpha = ALPHA_U*1.5f; /* 0.6 */ } - ELSE + else { - alpha = mult_r(_ALPHA_U_FX,16384); /*Q14*/ /* 0.4 go rapidly to CNG gain, pitch gain = 0 */ + alpha = ALPHA_U; /* 0.4 go rapidly to CNG gain, pitch gain = 0 */ } } - ELSE IF( sub(last_good, UNVOICED_TRANSITION) == 0 ) + else if( last_good == UNVOICED_TRANSITION ) { - alpha = mult_r(_ALPHA_UT_FX,16384); /*Q14*/ + alpha = ALPHA_UT; } - ELSE IF( (sub(last_good, ONSET) == 0) && (sub(nbLostCmpt, 3) <= 0 ) && (sub(coder_type, GENERIC) == 0)) + else if( (last_good == ONSET) && (nbLostCmpt <= 3) && (coder_type == GENERIC)) { - alpha = 13107/*0.8f Q14*/; /*Q14*/ + alpha = 0.8f; } - ELSE if( ( (sub(last_good, VOICED_CLAS) == 0) || (sub(last_good,ONSET) == 0) ) && (sub(nbLostCmpt, 3) <= 0) ) + else if( ( (last_good == VOICED_CLAS) || (last_good == ONSET) ) && (nbLostCmpt <= 3) ) { - alpha = mult_r(_ALPHA_V_FX,16384); /* constant for the first 3 erased frames */ + alpha = ALPHA_V; /* constant for the first 3 erased frames */ } - - IF (sub(last_good, VOICED_CLAS) >= 0 ) + if(last_good >= VOICED_CLAS) { - move16(); - lp_tmp = *lp_gainp; - - IF( sub(nbLostCmpt, 1) == 0 ) /* if first erased frame in a block, reset harmonic gain */ + if( nbLostCmpt == 1 ) /* if first erased frame in a block, reset harmonic gain */ { - /*lp_gainp_E = 1;*/ /*For sqrt, because *lp_gain is Q14 */ + gain = (float)sqrt( *lp_gainp ); /* move pitch gain towards 1 for voiced to remove energy fluctuations */ - /*gain = (float)sqrt( *lp_gainp );*/ /* move pitch gain towards 1 for voiced to remove energy fluctuations */ - /*BASOP_Util_Sqrt_MantExp(lp_gainp,&lp_gainp_E);*/ - s_gainp = 31-29; - move16(); - gain32 = Sqrt32(lp_tmp, &s_gainp); - - gain = round_fx(L_shl(gain32,s_gainp)); /* Q15*/ - gain = s_min(gain, 32113/*0.98f Q15*/); /*Q15*/ - gain = s_max(gain, 27853/*0.85f Q15*/); /*Q15*/ - alpha = mult_r(alpha , gain); /*Q14*/ + if( gain > 0.98f ) + { + gain = 0.98f; + } + else if( gain < 0.85f ) + { + gain = 0.85f; + } + alpha *= gain; } - ELSE IF ( sub(nbLostCmpt, 2) == 0 ) + else if( nbLostCmpt == 2 ) { - /*0.6 + 0.35*stab_fac*/ - alpha = mult_r(mac_r(1288490240l/*0.6f Q31*/, 11469/*0.35f Q15*/, stab_fac), round_fx(L_shl(lp_tmp,1))); + alpha = (0.6f+0.35f*stab_fac)**lp_gainp; } - ELSE + else { - /*0.7 + 0.2*stab_fac*/ move16(); - lp_tmp = Mpy_32_16_1(lp_tmp, mac_r(1503238528l/*0.7f Q31*/, 6554/*0.2f Q15*/, stab_fac)); /*2Q29*/ - alpha = round_fx(L_shl(lp_tmp,1)); /*1Q14*/ + *lp_gainp *= (0.7f+0.2f*stab_fac); + alpha = *lp_gainp; } - move16(); - *lp_gainp = lp_tmp; /*store*/ } } - ELSE + else { - alpha = mac_r(375809632l/*0.35f Q30*/,6554/*0.4f Q14*/,stab_fac); /*Q14*/ - if (sub(nbLostCmpt,2)< 0 ) + if (nbLostCmpt < 2) { - alpha = mac_r(751619264l/*0.70f Q30*/,4915/*0.3f Q14*/,stab_fac); /*Q14*/ + alpha = (0.7f+0.3f*stab_fac); } - if (sub(nbLostCmpt, 2)==0) + else if (nbLostCmpt == 2) { - alpha = mac_r(483183808l/*0.45f Q30*/,6554/*0.4f Q14*/,stab_fac); /*Q14*/ + alpha = (0.45f+0.4f*stab_fac); + } + else + { + alpha = 0.35f+0.4f*stab_fac; } - } return alpha; } + diff --git a/src/libs/libevs/lib_dec/er_sync_exc.cpp b/src/libs/libevs/lib_dec/er_sync_exc.cpp old mode 100755 new mode 100644 index 942ccf21..ae77a834 --- a/src/libs/libevs/lib_dec/er_sync_exc.cpp +++ b/src/libs/libevs/lib_dec/er_sync_exc.cpp @@ -1,16 +1,18 @@ /*==================================================================================== - EVS Codec 3GPP TS26.442 Apr 03, 2018. Version 12.11.0 / 13.6.0 / 14.2.0 + EVS Codec 3GPP TS26.443 Nov 13, 2018. Version 12.11.0 / 13.7.0 / 14.3.0 / 15.1.0 ====================================================================================*/ -/*This BASOP port is up to date with trunk rev. 36554*/ -#include "cnst_fx.h" -#include "stl.h" -#include "prot_fx.h" +#include "cnst.h" +#include "prot.h" +#include "cnst.h" #include +#include #include -#include "basop32.h" -#include "basop_util.h" +#include + + +#define NB_PULSES_MAX 15 /*------------------------------------------------------------------------- * @@ -20,98 +22,62 @@ /** Get the location of the minimum energy in the given signal. + * @param x Input signal. + * @param length The length of the input signal. + * @param filterLength the length of the filter length used for the energy calculation. * @returns Index of the position of the minimum energy, that is the position i where filter(x[i-filterLength/2],...,x[i+(filterLength-filterLength/2)-1]) is at maximum. */ -static Word16 GetMinimumPosition( - Word16 const * x, /* Input signal. Qx*/ - Word16 length, /* The length of the input signal. Q0*/ - Word16 filterLength /* the length of the filter length used for the energy calculation. Q0*/ -) +static int GetMinimumPosition(float const * x, int length, int filterLength) { - Word16 iMinEnergyPos, center, i; - Word16 cnt, tmp_e, tmp16; - Word32 energy, energy_old, tmptest; + int iMinEnergyPos, center, i; + float energy, minEnergy; - - filterLength = s_min(filterLength, length); - center = shr(filterLength,1); + filterLength = min(filterLength, length); + center = filterLength/2; iMinEnergyPos = center; - move16(); - - IF (filterLength > 0) + if (filterLength > 0) { - center = add(center,1); - energy = L_deposit_l(0); - energy_old = L_deposit_l(0); - - cnt = sub(length,filterLength); - - tmp_e = 0; - move16(); - FOR (i = 0; i < cnt; i++) + minEnergy = sum2_f(x, filterLength); + energy = 0; + center += 1; /* To avoid adding 1 in the loop */ + for (i = 0; i < length-filterLength; i++) { - tmp16 = shr(x[i],tmp_e); - energy = L_msu(energy_old,tmp16,tmp16); - tmp16 = shr(x[i+filterLength],tmp_e); - BASOP_SATURATE_WARNING_OFF /*Saturation will be handled*/ - energy = L_mac(energy,tmp16,tmp16); - BASOP_SATURATE_WARNING_ON - - /*if (energy == MAXVAL_WORD32)*/ - BASOP_SATURATE_WARNING_OFF /*saturates if energy < 0*/ - tmptest = L_sub(energy,MAXVAL_WORD32); - BASOP_SATURATE_WARNING_ON - IF (tmptest == 0) + energy -= x[i]*x[i]; + energy += x[i+filterLength]*x[i+filterLength]; + if (energy < 0) { - tmp_e = add(tmp_e,1); - energy = L_shr(energy_old,2); - tmp16 = shr(x[i],tmp_e); - energy = L_msu(energy,tmp16,tmp16); - tmp16 = shr(x[i+filterLength],tmp_e); - energy = L_mac(energy,tmp16,tmp16); - } - - IF (energy < 0) - { - iMinEnergyPos = add(i,center); - tmp_e = 0; - move16(); + minEnergy += energy; energy = 0; - move16(); + iMinEnergyPos = i+center; } - energy_old = L_add(energy, 0); } - } return iMinEnergyPos; } -/*! - * \brief FindMaxPeak - Get the location of the maximum peak in the given signal. - * - * \returns Index of the position of the maximum peak, that is the position i where abs(x[i]) has it's maximum. +/** Get the location of the maximum peak in the given signal. + * @param x Input signal. + * @param length The length of the input signal. + * @returns Index of the position of the maximum peak, that is the position i where abs(x[i]) has it's maximum. */ - -static Word16 FindMaxPeak -( - Word16 /*float*/ const * x, /*0) + float const absVal = (float)fabs(x[i]); + if (absVal > maxVal) { - move16(); + maxVal = absVal; iMax = i; } } @@ -119,419 +85,212 @@ static Word16 FindMaxPeak return iMax; } -static void AddSamples( - Word16 const * const old_exc, /*Qx*/ - Word16 * const new_exc, /*Qx*/ - Word16 const L_frame, /*Q0*/ - Word16 const n_samples_to_add, /*Q0*/ - Word16 const min_pos[], /*Q0*/ - Word16 const points_by_pos[], /*Q0*/ - Word16 const nb_min /*Q0*/ -) +static void AddSamples(float const * old_exc, float * new_exc, int L_frame, int n_samples_to_add, int const min_pos[], int const points_by_pos[], int nb_min) { - Word16 * pt_dest; - Word16 const * pt_src; - Word16 last_min_pos, i, j; - Word16 ftmp; + float * pt_dest; + float const * pt_src; + int last_min_pos, i, j; pt_dest = new_exc; - move16(); pt_src = old_exc; - move16(); last_min_pos = 0; - move16(); - - FOR (i = 0; i < nb_min; i++) + for (i = 0; i < nb_min; i++) { + float ftmp; /* Copy section */ - FOR (j = min_pos[i] - last_min_pos; j > 0; j--) + for (j = min_pos[i] - last_min_pos; j > 0; j--) { *pt_dest++ = *pt_src++; - move16(); } /* Add some samples */ - ftmp = negate(mult(*pt_src,1638/*.05f Q15*/)); - - FOR (j = 0; j < points_by_pos[i]; j++) + ftmp = -(*pt_src/20); + for (j = 0; j < points_by_pos[i]; j++) { *pt_dest++ = ftmp; - move16(); - ftmp = negate(ftmp); + ftmp = -ftmp; } /* Prepare for the next loop iteration */ last_min_pos = min_pos[i]; - move16(); } /* Copy remaining length */ - FOR (j = sub(L_frame , add(n_samples_to_add , last_min_pos)); j > 0; j--) + for (j = L_frame-n_samples_to_add-last_min_pos; j > 0; j--) { *pt_dest++ = *pt_src++; - move16(); } } -static void RemoveSamples( - Word16 /*float*/const * const old_exc, /*i : Qx */ - Word16 /*float*/ * const new_exc, /*o : Qx */ - Word16 /*int*/ const L_frame, /*i : Q0 */ - Word16 /*int*/ const n_samples_to_add, /*i : Q0 */ - Word16 /*int*/ const min_pos[], /*i : Q0 */ - Word16 /*int*/ const points_by_pos[], /*i : Q0 */ - Word16 /*int*/ const nb_min /*i : Q0*/ -) +static void RemoveSamples(float const * old_exc, float * new_exc, int L_frame, int n_samples_to_add, int const min_pos[], int const points_by_pos[], int nb_min) { - Word16 /*float*/ * pt_dest; - Word16 /*float*/ const * pt_src; - Word16 /*int*/ last_min_pos, i, j; - + float * pt_dest; + float const * pt_src; + int last_min_pos, i, j; pt_dest = new_exc+L_frame; - last_min_pos = sub(L_frame,n_samples_to_add); - - FOR(i = sub(nb_min,1); i >= 0; i--) + last_min_pos = L_frame-n_samples_to_add; + for(i = nb_min-1; i >= 0; i--) { /* Compute len to copy */ /* Copy section, removing some samples */ pt_src = old_exc+last_min_pos; - - FOR (j = sub(last_min_pos , add(min_pos[i],points_by_pos[i])); j > 0; j--) + for (j = last_min_pos - (min_pos[i]+points_by_pos[i]); j > 0; j--) { *--pt_dest = *--pt_src; - move16(); } /* Prepare for the next loop iteration */ last_min_pos = min_pos[i]; - move16(); } /* Copy remaining length */ pt_src = old_exc+last_min_pos; - - FOR (j = last_min_pos; j > 0; j--) + for (j = last_min_pos; j > 0; j--) { *--pt_dest = *--pt_src; - move16(); } } -/** Resynchronize glotal pulse positions of the signal in src_exc and store it in dst_exc. +/** Resynchronize glottal pulse positions of the signal in src_exc and store it in dst_exc. * src_exc holds on call the harmonic part of the signal with the constant pitch, constructed by repeating the last pitch cycle of length pitchStart. * dst_exc holds on return the harmonic part of the signal with the pitch changing from pitchStart to pitchEnd. * src_exc and dst_exc can overlap, but src_exc < dst_exc must be fullfiled. + * @param src_exc Input excitation buffer. + * @param dst_exc Output excitation buffer. + * @param nFrameLength Length of the frame, that is the length of the valid data in the excitation buffer on return. + * @param nSubframes Number of subframes in the excitation buffer. nFrameLength must be divisible by nSubframes. + * @param pitchStart Pitch at the end of the last frame. + * @param pitchEnd Pitch at the end of the current frame. */ -/*This BASOP port is up to date with trunk rev 8779(svnext2)*/ -void PulseResynchronization( - Word16 /*float*/ const * const src_exc, /* 0) - || (L_sub(Mpy_32_16_1(pitchEnd,add(nSubframes,1)),Mpy_32_16_1(pitchStart,sub(nSubframes,1))) <= 0) - || (src_exc-dst_exc >= 0)) - { - /* This is error handling and recovery that should never occur. */ - test(); - IF (src_exc != dst_exc && sub(nFrameLength, 1200) <= 0) - { - Copy(src_exc, dst_exc, nFrameLength); - } - return; - } + assert((nFrameLength > 0) && (nFrameLength > pitchStart) && (nSubframes > 1) && (nSubframes <= 5) && (nFrameLength%nSubframes == 0) && (pitchStart > 0) && (pitchEnd > 0) && (pitchEnd/pitchStart > 1-2.0f/(nSubframes+1)) && (src_exc != NULL) && (dst_exc != NULL) && (src_exc < dst_exc)); - roundedPitchStart = round_fx(pitchStart); /*Q0*/ - - /* freqStart = 1.0f/roundedPitchStart; */ - freqStart_e = 15; - move16(); - freqStart = Inv16(roundedPitchStart, &freqStart_e); /*Q15,freqStart_e*/ + pitchDelta = (pitchEnd - pitchStart)/nSubframes; + roundedPitchStart = (int)(pitchStart+0.5f); + freqStart = 1.0f/roundedPitchStart; /* Calculate number of samples to be removed (if negative) or added (if positive) */ - /*samplesDelta = 0.5f*pitchDelta*nFrameLength*(nSubframes+1)*freqStart;*/ - /* pitchDelta*freqStart = ((pitchEnd - pitchStart)/roundedPitchStart)/nSubframes */ - tmp16 = shl(roundedPitchStart, 2); /*Q0*/ - if (sub(nSubframes, 5) == 0) - { - tmp16 = add(tmp16, roundedPitchStart);/*Q0*/ /*tmp16=roundedPitchStart*nSubframes*/ - } - tmp_e = norm_s(tmp16); - tmp16 = shl(tmp16, tmp_e);/*Q0,-tmp_e*/ /*tmp16=roundedPitchStart*nSubframes*/ - tmp_e = sub(15, tmp_e); - tmp16 = Inv16(tmp16, &tmp_e); /*Q15,tmp_e*/ /*tmp16=1.0/(roundedPitchStart*nSubframes)*/ - tmp32 = L_sub(pitchEnd,pitchStart); - tmp2_e = norm_l(tmp32); - tmp32 = L_shl(tmp32, tmp2_e);/*Q16,-tmp2_e*/ - tmp32 = Mpy_32_16_1(tmp32, tmp16);/*Q16,tmp_e-tmp2_e*/ /*tmp32=pitchDelta*freqStart*/ - tmp_e = sub(tmp_e, tmp2_e); /* sum up all the scalings for tmp32 */ - - tmp16 = imult1616(nFrameLength,add(nSubframes,1));/*Q0*//*tmp16=nFrameLength*(nSubframes+1)*/ - tmp2_e = norm_s(tmp16); - tmp16 = shl(tmp16,tmp2_e); - - tmp32 = Mpy_32_16_1(tmp32,tmp16);/*Q1 scaling (tmp_e-tmp2_e-1), -1 because of 0.5f*/ /*tmp32=0.5f*pitchDelta*nFrameLength*(nSubframes+1)*freqStart*/ - tmp_e = sub(sub(tmp_e,tmp2_e),1); /* sum up all the scalings for tmp32 */ - tmp_e = add(tmp_e,31-1); /* tmp32 is now regarded as Q31 with scaling tmp_e */ - - /*samplesDelta -= nFrameLength*(1.0f-pitchStart*freqStart);*/ - tmp2_e = norm_l(pitchStart); - tmp32_a = L_shl(pitchStart,tmp2_e); - tmp32_a = Mpy_32_16_1(tmp32_a/*Q16,-tmp2_e*/,freqStart/*Q15,freqStart_e*/);/*Q16, scaling (freqStart_e-tmp2_e)*/ /*tmp32_a=pitchStart*freqStart*/ - tmp16 = norm_l(tmp32_a); - tmp32_a = L_shl(tmp32_a,tmp16); - tmp2_e = sub(sub(freqStart_e,tmp16),tmp2_e); /* sum up all scalings for tmp32_a */ - tmp2_e = add(tmp2_e,31-16); /* tmp32_a is now regarded as Q31 with scaling tmp2_e */ - - tmp3_e = tmp2_e; - tmp32_a = L_negate(tmp32_a); - tmp32_a = L_add(L_shl(1, sub(31, tmp3_e)), tmp32_a); /*Q31,tmp3_e*//*tmp32_a= 1.0f-pitchStart*freqStart*/ - tmp2_e = norm_s(nFrameLength); - tmp16_a = shl(nFrameLength,tmp2_e); - tmp32_a = Mpy_32_16_1(tmp32_a/*Q31,tmp3_e*/,tmp16_a/*Q0,-tmp2_e*/);/*Q16,tmp3_e-tmp2_e*/ /*tmp32_a= nFrameLength*(1.0f-pitchStart*freqStart)*/ - tmp2_e = add(sub(tmp3_e, tmp2_e), 15); - samplesDelta = BASOP_Util_Add_Mant32Exp(tmp32, tmp_e, L_negate(tmp32_a), tmp2_e, &samplesDelta_e); /*Q31,samplesDelta_e*/ - + samplesDelta = 0.5f*pitchDelta*nFrameLength*(nSubframes+1)*freqStart; + samplesDelta -= nFrameLength*(1.0f-pitchStart*freqStart); /* To have enough samples in the buffer of length nFrameLength*(nSubframes+1)/nSubframes, pitchEnd/pitchEnd must be bigger than (nSubframes-1)/(nSubframes+1)=1-2/(nSubframes+1) */ /* Thus nSubframes must be bigger than 1 */ - nSamplesDelta = round_fx(L_shl(samplesDelta,sub(samplesDelta_e,31-16))); /*Q0*/ - nSamplesDeltaRemain = abs_s(nSamplesDelta); + nSamplesDelta = (int)floor(samplesDelta+0.5f); + nSamplesDeltaRemain = abs(nSamplesDelta); /* Find the location of the glottal pulse */ - T0 = FindMaxPeak(src_exc, roundedPitchStart); /*Q0*/ + T0 = FindMaxPeak(src_exc, roundedPitchStart); /* Get the index of the last pulse in the resynchronized frame */ - /*k = (int)ceil((nFrameLength-nSamplesDelta-T0)*freqStart - 1);*/ - tmp32 = BASOP_Util_Add_Mant32Exp(L_mult(sub(nFrameLength,add(nSamplesDelta,T0)),freqStart)/*Q16*/,add(freqStart_e,31-16),0x80000000/*-1.f Q31*/,0,&tmp_e); - tmp32 = L_shl(tmp32,sub(tmp_e,31-16))/*Q16*/; - tmp32 = L_add(tmp32,65536l/*1.f Q16*/); - k=extract_h(tmp32); - test(); - IF ((k >= 0) && sub(add(k,1) , NB_PULSES_MAX)<=0) + k = (int)ceil((nFrameLength-nSamplesDelta-T0)*freqStart - 1); + if ((k >= 0) && (k+1 <= NB_PULSES_MAX)) { - absPitchDiff = L_abs(L_sub(L_deposit_h(roundedPitchStart),pitchEnd));/*Q16*/ - + absPitchDiff = (float)fabs(roundedPitchStart-pitchEnd); /* Calculate the delta of the samples to be added/removed between consecutive cycles */ - /*perCycleDeltaDelta = (absPitchDiff*(nFrameLength-samplesDelta) - (float)fabs(samplesDelta)*roundedPitchStart) - / ((k+1)*(T0+0.5f*k*roundedPitchStart));*/ - tmp32 = L_sub(L_deposit_h(nFrameLength),L_shl(samplesDelta,sub(samplesDelta_e,31-16)));/*Q16*/ - tmp_e = 15; /*tmp32 = Q31,tmp_e*/ move16(); - tmp2_e = norm_l(tmp32); - tmp32 = L_shl(tmp32,tmp2_e); - tmp_e = sub(tmp_e,tmp2_e); /*tmp32 = Q31,tmp_e*/ - tmp2_e = norm_l(absPitchDiff); - tmp32_b = L_shl(absPitchDiff,tmp2_e); - tmp_e = sub(tmp_e,tmp2_e); - tmp32 = Mpy_32_16_1(tmp32_b,round_fx(tmp32));/*Q16,tmp_e*/ /*tmp32 = absPitchDiff*(nFrameLength-samplesDelta)*/ - tmp32_a = Mpy_32_16_1(L_abs(samplesDelta)/*Q31,samplesDelta_e*/,roundedPitchStart/*Q0*/);/*Q16,samplesDelta_e*/ /*tmp32_a=fabs(samplesDelta)*roundedPitchStart*/ - tmp32 = BASOP_Util_Add_Mant32Exp(tmp32, add(tmp_e,31-16), L_negate(tmp32_a), add(samplesDelta_e,31-16),&tmp_e);/*Q31,tmp_e*/ /*tmp32=absPitchDiff*(nFrameLength-samplesDelta)-fabs(samplesDelta)*roundedPitchStart*/ - tmp16 = imult1616(add(k,1),add(shl(T0,1),imult1616(k,roundedPitchStart)));/*Q0,-1*/ /*tmp16=(k+1)*(T0+0.5f*k*roundedPitchStart)*/ - perCycleDeltaDelta = BASOP_Util_Divide3216_Scale(tmp32/*Q31,tmp_e*/,tmp16/*Q0,-1*/,&perCycleDeltaDelta_e); /*Q15,perCycleDeltaDelta_e*/ - perCycleDeltaDelta_e = add(perCycleDeltaDelta_e,sub(tmp_e,-1+15)); - tmp_e = norm_s(perCycleDeltaDelta); - perCycleDeltaDelta_e = sub(perCycleDeltaDelta_e,tmp_e); - perCycleDeltaDelta = shl(perCycleDeltaDelta,tmp_e);/*Q15,perCycleDeltaDelta_e*/ - - + perCycleDeltaDelta = (absPitchDiff*(nFrameLength-samplesDelta) - (float)fabs(samplesDelta)*roundedPitchStart) + / ((k+1)*(T0+0.5f*k*roundedPitchStart)); /* Calculate the integer number of samples to be added/removed in each pitch cycle */ - /*cycleDelta = max(0, (absPitchDiff-(k+1)*perCycleDeltaDelta)*T0*freqStart); */ - tmp_e = norm_s(k+1); - tmp32 = L_mult(perCycleDeltaDelta/*Q15,perCycleDeltaDelta_e*/,shl(add(k,1),tmp_e)/*Q0, tmp_e*/)/*Q0+16, perCycleDeltaDelta_e-tmp_e*/; - tmp32 = BASOP_Util_Add_Mant32Exp(absPitchDiff/*Q16*/,31-16,L_negate(tmp32),add(sub(perCycleDeltaDelta_e,tmp_e),31-16),&tmp_e);/*Q31,tmp_e*/ - tmp32 = Mpy_32_16_1(tmp32,T0/*Q0*/);/*Q16,tmp_e*/ - tmp32 = Mpy_32_16_1(tmp32/*Q16,tmp_e*/,freqStart/*Q15,freqStart_e*/)/*Q16, tmp_e+(freqStart_e)*/; - tmp32 = L_max(0,tmp32); - cycleDelta_e = add(tmp_e,freqStart_e); - tmp32_a = L_shl(tmp32,cycleDelta_e); - roundedCycleDelta = extract_h(L_abs(tmp32_a)); - if (tmp32<0) + cycleDelta = max(0, (absPitchDiff-(k+1)*perCycleDeltaDelta)*T0*freqStart); + roundedCycleDelta = (int)(cycleDelta); + iDeltaSamples[0] = roundedCycleDelta; + fractionalLeft = cycleDelta-roundedCycleDelta; + nSamplesDeltaRemain -= roundedCycleDelta; + for (i = 1; i <= k; i++) { - roundedCycleDelta = negate(roundedCycleDelta); - } - fractionalLeft = lshr(extract_l(tmp32_a),1);/*Q15*/ - tmp_e = sub(15,norm_l(tmp32)); - cycleDelta_e = add(cycleDelta_e,tmp_e); - tmp32 = L_shr(tmp32,sub(tmp_e,15));/*Q31 frac, cycleDelta_e*/ - cycleDelta = round_fx(tmp32);/*Q15, cycleDelta_e*/ - if (cycleDelta == 0) - { - move16(); - cycleDelta_e = 0; - } - - /*roundedCycleDelta = (int)(cycleDelta); */ /*done above*/ - move16(); - iDeltaSamples[0] = roundedCycleDelta;/*Q0*/ - /*fractionalLeft = cycleDelta-roundedCycleDelta;*/ /*done above*/ - nSamplesDeltaRemain = sub(nSamplesDeltaRemain,roundedCycleDelta);/*Q0*/ - - tmp_e = (s_max(2,k)); - tmp_e = norm_s(tmp_e);/*maximum norming factor for following loop*/ - - - FOR (i = 1; i <= k; i++) - { - /*cycleDelta = (absPitchDiff-(k+1-i)*perCycleDeltaDelta) + fractionalLeft; */ - tmp32 = L_mult(perCycleDeltaDelta/*Q15,perCycleDeltaDelta_e*/,shl(sub(add(k,1),i),tmp_e)/*Q0, tmp_e*/)/*Q0+16, perCycleDeltaDelta_e-tmp_e*/; /*calcultion of base for first iteration*/ - tmp32 = L_shl(tmp32,sub(perCycleDeltaDelta_e,tmp_e));/*Q16*/ - tmp32_a = L_sub(absPitchDiff,tmp32); - tmp32_b = L_lshl(L_deposit_l(fractionalLeft/*Q15*/),1)/*Q16*/; - cycleDelta32 = L_add(tmp32_a,tmp32_b);/*Q16*/ - cycleDelta32 = L_max(0, cycleDelta32); - + cycleDelta = (absPitchDiff-(k+1-i)*perCycleDeltaDelta) + fractionalLeft; + cycleDelta = max(0, cycleDelta); /* Make sure that the number of samples increases */ - IF (L_sub(L_deposit_h(roundedCycleDelta), cycleDelta32) > 0) + if (roundedCycleDelta > cycleDelta) { iDeltaSamples[i] = roundedCycleDelta; - move16(); - roundedCycleDelta = extract_h(cycleDelta32); /* cycleDelta32 should never be < 0 here */ + roundedCycleDelta = (int)(cycleDelta); iDeltaSamples[i-1] = roundedCycleDelta; - move16(); } - ELSE + else { - roundedCycleDelta = extract_h(cycleDelta32); /* cycleDelta32 should never be < 0 here */ + roundedCycleDelta = (int)(cycleDelta); iDeltaSamples[i] = roundedCycleDelta; - move16(); } - /*fractionalLeft = cycleDelta-roundedCycleDelta = cycleDelta-(int)cycleDelta;*/ - fractionalLeft = lshr(extract_l(cycleDelta32),1); /*Q15*/ /* cycleDelta32 should never be < 0 here */ - nSamplesDeltaRemain = sub(nSamplesDeltaRemain,roundedCycleDelta); + fractionalLeft = cycleDelta-roundedCycleDelta; + nSamplesDeltaRemain -= roundedCycleDelta; } - iDeltaSamples[k+1] = s_max(0, nSamplesDeltaRemain); - move16(); - maxDeltaSamples = s_max(iDeltaSamples[k], iDeltaSamples[k+1]);/*Q0*/ + iDeltaSamples[k+1] = max(0, nSamplesDeltaRemain); + maxDeltaSamples = max(iDeltaSamples[k], iDeltaSamples[k+1]); /* Find the location of the minimum energy between the first two pulses */ - - /*iMinPos1 = T0+GetMinimumPosition(src_exc+T0, min(roundedPitchStart, (nSubframes+1)*nFrameLength/nSubframes-T0), maxDeltaSamples);*/ - BASOP_Util_Divide_MantExp(add(nSubframes,1),15,nSubframes,15,&tmp16,&tmp_e); - tmp32 = L_mult(nFrameLength/*Q0*/,tmp16/*Q15,tmp_e*/);/*Q16,tmp_e*/ - tmp16 = round_fx(L_shl(tmp32,tmp_e)); - tmp16 = sub(tmp16,T0); - tmp16 = s_min(roundedPitchStart,tmp16); - - iMinPos1 = GetMinimumPosition( - src_exc+T0, /*Qx*/ - tmp16, /*Q0*/ - maxDeltaSamples /*Q0*/ - ); - iMinPos1 = add(iMinPos1,T0); - - - IF (nSamplesDelta < 0) + iMinPos1 = T0+GetMinimumPosition(src_exc+T0, min(roundedPitchStart, (nSubframes+1)*nFrameLength/nSubframes-T0), maxDeltaSamples); + if (nSamplesDelta < 0) { /* Find the location of the minimum energy before the first pulse */ - - IF (sub(iMinPos1 , add(roundedPitchStart , shr(iDeltaSamples[0],1))) > 0 ) + if (iMinPos1 > roundedPitchStart + iDeltaSamples[0]/2) { - iMinPos[0] = sub(iMinPos1 , sub(roundedPitchStart , shr(iDeltaSamples[0],1))); - move16(); + iMinPos[0] = iMinPos1 - roundedPitchStart - iDeltaSamples[0]/2; } - ELSE + else { - move16(); - iMinPos[0] = sub(GetMinimumPosition(src_exc, T0, iDeltaSamples[0]) , shr(iDeltaSamples[0],1)); + iMinPos[0] = GetMinimumPosition(src_exc, T0, iDeltaSamples[0]) - iDeltaSamples[0]/2; } - /* Find the location of the minimum energy between the pulses */ - FOR (i = 1; i <= k; i++) + for (i = 1; i <= k; i++) { - move16(); - iMinPos[i] = add(iMinPos1 , sub(imult1616(sub(i,1),roundedPitchStart) , shr(iDeltaSamples[i],1))); + iMinPos[i] = iMinPos1 + (i-1)*roundedPitchStart - iDeltaSamples[i]/2; } /* Find the location of the minimum energy after the last pulse */ - - IF (sub(add(iMinPos1 , add(imult1616(k,roundedPitchStart) , sub(iDeltaSamples[k+1] , shr(iDeltaSamples[k+1],1)))) , sub(nFrameLength,nSamplesDelta) ) < 0) + if (iMinPos1 + k*roundedPitchStart + iDeltaSamples[k+1] - iDeltaSamples[k+1]/2 < nFrameLength-nSamplesDelta) { - move16(); - iMinPos[k+1] = add(iMinPos1 , sub(imult1616(k,roundedPitchStart) , shr(iDeltaSamples[k+1],1))); + iMinPos[k+1] = iMinPos1 + k*roundedPitchStart - iDeltaSamples[k+1]/2; } - ELSE + else { - /*iMinPos[k+1] = T0+k*roundedPitchStart + iMinPos[k+1] = T0+k*roundedPitchStart + GetMinimumPosition(src_exc+T0+k*roundedPitchStart, nFrameLength-nSamplesDelta-(T0+k*roundedPitchStart), iDeltaSamples[k+1]) - - iDeltaSamples[k+1]/2; */ - tmp16 = GetMinimumPosition(src_exc+T0+k*roundedPitchStart, sub(nFrameLength,add(nSamplesDelta,add(T0,imult1616(k,roundedPitchStart)))), iDeltaSamples[k+1]); - tmp16 = add(add(T0,imult1616(k,roundedPitchStart)),tmp16); - tmp16 = sub(tmp16,shr(iDeltaSamples[k+1],1)); - iMinPos[k+1] = tmp16; - move16(); + - iDeltaSamples[k+1]/2; } - - IF (sub(add(iMinPos[k+1],iDeltaSamples[k+1]) , sub(nFrameLength,nSamplesDelta)) > 0 ) + if (iMinPos[k+1]+iDeltaSamples[k+1] > nFrameLength-nSamplesDelta) { - iDeltaSamples[k] += add(iMinPos[k+1] , sub(iDeltaSamples[k+1] , sub(nFrameLength,nSamplesDelta))); - iDeltaSamples[k+1] = sub(nFrameLength , add(nSamplesDelta , iMinPos[k+1])); + iDeltaSamples[k] += iMinPos[k+1]+iDeltaSamples[k+1] - (nFrameLength-nSamplesDelta); + iDeltaSamples[k+1] = nFrameLength-nSamplesDelta-iMinPos[k+1]; } - /* Remove samples at the given positions */ RemoveSamples(src_exc, dst_exc, nFrameLength, nSamplesDelta, iMinPos, iDeltaSamples, k+2); } - ELSE + else { /* Find the location of the minimum energy before the first pulse */ - IF (sub(iMinPos1 , roundedPitchStart) > 0 ) + if (iMinPos1 > roundedPitchStart) { - iMinPos[0] = sub(iMinPos1 , roundedPitchStart); - move16(); + iMinPos[0] = iMinPos1 - roundedPitchStart; } - ELSE + else { iMinPos[0] = GetMinimumPosition(src_exc, T0, iDeltaSamples[0]); - move16(); } /* Find the location of the minimum energy between the pulses */ - - FOR (i = 1; i <= k; i++) + for (i = 1; i <= k; i++) { iMinPos[i] = iMinPos1; - move16(); - iMinPos1 = add(iMinPos1,roundedPitchStart); + iMinPos1 += roundedPitchStart; } - /* Find the location of the minimum energy after the last pulse */ - IF (sub(iMinPos1 , sub(nFrameLength,nSamplesDelta)) < 0) + if (iMinPos1 < nFrameLength-nSamplesDelta) { iMinPos[k+1] = iMinPos1; - move16(); } - ELSE + else { - - tmp16 = GetMinimumPosition(src_exc+T0+k*roundedPitchStart, sub(nFrameLength,add(nSamplesDelta,add(T0,imult1616(k,roundedPitchStart)))), iDeltaSamples[k+1]); - tmp16 = add(add(tmp16,T0),imult1616(k,roundedPitchStart)); - iMinPos[k+1] = tmp16; - move16(); + iMinPos[k+1] = T0+k*roundedPitchStart + + GetMinimumPosition(src_exc+T0+k*roundedPitchStart, nFrameLength-nSamplesDelta-(T0+k*roundedPitchStart), iDeltaSamples[k+1]); } - - IF (sub(add(iMinPos[k+1],iDeltaSamples[k+1]) , sub(nFrameLength,nSamplesDelta)) > 0 ) + if (iMinPos[k+1]+iDeltaSamples[k+1] > nFrameLength-nSamplesDelta) { - move16(); - move16(); - iDeltaSamples[k] = add(iDeltaSamples[k] , add(iMinPos[k+1] , sub(iDeltaSamples[k+1] , sub(nFrameLength,nSamplesDelta)))); - iDeltaSamples[k+1] = sub(sub(nFrameLength, nSamplesDelta),iMinPos[k+1]); + iDeltaSamples[k] += iMinPos[k+1]+iDeltaSamples[k+1] - (nFrameLength-nSamplesDelta); + iDeltaSamples[k+1] = nFrameLength-nSamplesDelta-iMinPos[k+1]; } /* Add samples at the given positions */ AddSamples(src_exc, dst_exc, nFrameLength, nSamplesDelta, iMinPos, iDeltaSamples, k+2); @@ -540,3 +299,4 @@ void PulseResynchronization( } + diff --git a/src/libs/libevs/lib_dec/er_util.cpp b/src/libs/libevs/lib_dec/er_util.cpp old mode 100755 new mode 100644 index 1d3966cd..b7c5fb5a --- a/src/libs/libevs/lib_dec/er_util.cpp +++ b/src/libs/libevs/lib_dec/er_util.cpp @@ -1,320 +1,169 @@ /*==================================================================================== - EVS Codec 3GPP TS26.442 Apr 03, 2018. Version 12.11.0 / 13.6.0 / 14.2.0 + EVS Codec 3GPP TS26.443 Nov 13, 2018. Version 12.11.0 / 13.7.0 / 14.3.0 / 15.1.0 ====================================================================================*/ - -#include "options.h" -#include "stl.h" -#include "prot_fx.h" -#include "basop_util.h" #include - - -#define MODE_DECISION_BASED_ON_PEAK_DETECTION - - -/* static void setnoiseLevelMemory() - * - * Helper function - updates buffer for minimumStatistics function - */ -static void setnoiseLevelMemory(Word16 f, Word16* new_noiseEstimate_e, Word16* noiseLevelMemory_e, Word16* noiseLevelMemory, Word16* currLevelIndex) -{ - noiseLevelMemory[*currLevelIndex] = f; - move16(); - noiseLevelMemory_e[*currLevelIndex] = *new_noiseEstimate_e; - move16(); -} +#include "options.h" +#include "prot.h" +#include "cnst.h" +#include "stat_com.h" /* PLC: [Common: Fade-out] * PLC: and for PLC fade out */ -void minimumStatistics(Word16* noiseLevelMemory, /* Qx, internal state */ - Word16* noiseLevelIndex, /* Q0, internal state */ - Word16* currLevelIndex, /* Q0, internal state (circular buffer) */ - Word16* noiseEstimate, /* Qx, previous estimate of background noise */ - Word16* lastFrameLevel, /* Qx, level of the last frame */ - Word16 currentFrameLevel, /* Qx, level of the current frame */ - Word16* noiseLevelMemory_e, /* scaling factor for noiseLevelMemory */ - Word16 const noiseEstimate_e, /* exponent of noiseEstimate */ - Word16* new_noiseEstimate_e, /* new exponent of noise Estimate*/ - Word16* const lastFrameLevel_e, /* exponent of lastFrameLevel */ - Word16 currentFrameLevel_e) /* exponent of currentFrameLevel */ +void minimumStatistics( + float* noiseLevelMemory, + int* noiseLevelIndex, + int* currLevelIndex, + float* noiseEstimate, + float* lastFrameLevel, + float currentFrameLevel, + float const minLev, + int const buffSize +) { - Word16 aOpt, aOpt_e; - Word16 f, p, i; - Word16 tmp,tmp2, tmp_e; - Word32 tmp32; - move16(); - aOpt_e = 0; + float aOpt; + float f; + int p; + int i; - - BASOP_SATURATE_WARNING_OFF - IF (sub(shl(currentFrameLevel, currentFrameLevel_e),PLC_MIN_CNG_LEV) < 0) + if (currentFrameLevel < minLev) { - BASOP_SATURATE_WARNING_ON - currentFrameLevel = PLC_MIN_CNG_LEV; - move16(); - move16(); - currentFrameLevel_e = 0; + currentFrameLevel = minLev; } - BASOP_SATURATE_WARNING_ON - /* compute optimal factor aOpt for recursive smoothing of frame minima */ - tmp2 = BASOP_Util_Add_MantExp(*lastFrameLevel,*lastFrameLevel_e,negate(*noiseEstimate),noiseEstimate_e,&tmp); - IF (tmp >= 0) + if (*lastFrameLevel >= *noiseEstimate) { - /* aOpt = *noiseEstimate / *lastFrameLevel; */ - aOpt = BASOP_Util_Divide1616_Scale(*noiseEstimate, *lastFrameLevel, &aOpt_e); - aOpt_e = add(aOpt_e, sub(noiseEstimate_e, *lastFrameLevel_e)); + aOpt = *noiseEstimate / *lastFrameLevel; } - ELSE + else { - /* aOpt = *lastFrameLevel / *noiseEstimate; */ - aOpt = BASOP_Util_Divide1616_Scale(*lastFrameLevel, *noiseEstimate, &aOpt_e); - aOpt_e = add(aOpt_e, sub(*lastFrameLevel_e, noiseEstimate_e)); + aOpt = *lastFrameLevel / *noiseEstimate; } - aOpt = mult_r(aOpt, aOpt); /* Q15 */ - aOpt_e = shl(aOpt_e,1); - if (aOpt == 0) - { - move16(); - aOpt_e = 0; - } - + aOpt *= aOpt; *lastFrameLevel = currentFrameLevel; - move16(); - move16(); - *lastFrameLevel_e = currentFrameLevel_e; - /* recursively compute smoothed frame minima using optimal factor aOpt */ - tmp = *currLevelIndex; - move16(); - move16(); - if (tmp == 0) - { - tmp = PLC_MIN_STAT_BUFF_SIZE; - move16(); - - } - /*f = msu_r(L_mult(aOpt, noiseLevelMemory[sub(tmp, 1)]), add(aOpt, 0x8000), currentFrameLevel);*/ - /*f = (aOpt * noiseLevelMemory[tmp-1]) - (currentFrameLevel * (aOpt-1))*/ - /*tmp32*/ /*tmp*/ - - tmp32 = L_mult(aOpt,noiseLevelMemory[tmp-1]); /*Q_tmp32 = aOpt_e + noiseLevelMemory_e[tmp - 1]*/ - move16(); - tmp_e = tmp; - - - tmp2 = BASOP_Util_Add_MantExp(aOpt,aOpt_e,negate(32768/2),1,&tmp); - tmp = mult_r(tmp,currentFrameLevel); /*Q_tmp = tmp2 + currentFrameLevel_e*/ - tmp2 = add(tmp2,currentFrameLevel_e); - - *new_noiseEstimate_e = BASOP_Util_Add_MantExp(round_fx(tmp32),add(aOpt_e,noiseLevelMemory_e[tmp_e - 1]),negate(s_max(tmp,-32767)/*to avoid negate(-32768)*/),tmp2,&f); - - assert(f >= 0); - + f = currentFrameLevel * (1.0f - aOpt); + f += aOpt * noiseLevelMemory[(*currLevelIndex ? *currLevelIndex : buffSize)-1]; /* if current frame min is a new local min, set index to current index */ p = *noiseLevelIndex; - move16(); - tmp2 = BASOP_Util_Add_MantExp(noiseLevelMemory[p],noiseLevelMemory_e[p],negate(f),*new_noiseEstimate_e,&tmp); - IF (tmp >= 0) + if (noiseLevelMemory[p] >= f) { - - /*rescale noiseLevelMemory*/ - - setnoiseLevelMemory(f,new_noiseEstimate_e,noiseLevelMemory_e, noiseLevelMemory, currLevelIndex); + noiseLevelMemory[*currLevelIndex] = f; p = *currLevelIndex; - move16(); } - ELSE + else { - move16(); - - setnoiseLevelMemory(f,new_noiseEstimate_e, noiseLevelMemory_e, noiseLevelMemory, currLevelIndex); - + noiseLevelMemory[*currLevelIndex] = f; /* current min is not a new min, so check if min must be re-searched */ - IF (sub(p, *currLevelIndex) != 0) + if (p != *currLevelIndex) { f = noiseLevelMemory[p]; /* min is still in memory, so return it */ - move16(); - *new_noiseEstimate_e = noiseLevelMemory_e[p]; } - ELSE { + else + { /* p == currLevelIndex; min was removed from memory, re-search min */ - FOR (i = 0; i < PLC_MIN_STAT_BUFF_SIZE; i++) + for (i = *currLevelIndex + 1; i < buffSize; i++) { - tmp2 = BASOP_Util_Add_MantExp(noiseLevelMemory[p],noiseLevelMemory_e[p],negate(noiseLevelMemory[i]),noiseLevelMemory_e[i],&tmp); - if ( tmp > 0) + if (f >= noiseLevelMemory[i]) { + f = noiseLevelMemory[i]; + p = i; + } + } + for (i = 0; i <= *currLevelIndex; i++) + { + if (f >= noiseLevelMemory[i]) + { + f = noiseLevelMemory[i]; p = i; - move16(); } } - f = noiseLevelMemory[p]; - move16(); - *new_noiseEstimate_e = noiseLevelMemory_e[p]; } } - /* update local-minimum-value index and current circular-buffer index */ *noiseLevelIndex = p; - move16(); - p = add(*currLevelIndex,1); - *currLevelIndex = add(*currLevelIndex, 1); - move16(); - if (sub(*currLevelIndex, PLC_MIN_STAT_BUFF_SIZE) == 0) - { - *currLevelIndex = 0; - move16(); - } + p = *currLevelIndex + 1; + *currLevelIndex = (p == buffSize) ? 0 : p; *noiseEstimate = f; - move16(); + + return; } + /*----------------------------------------------------------------------* * PLC: [ACELP: Fade-out] * PLC: getLevelSynDeemph: derives on frame or subframe basis the level * of LPC synthesis and deeemphasis based on the given input *----------------------------------------------------------------------*/ -Word16 getLevelSynDeemph( /*10Q5*/ - Word16 h1Init[], /* i: input value or vector to be processed */ /* Q15 */ - Word16 const A[], /* i: LPC coefficients */ /* Qx */ - Word16 const lpcorder, /* i: LPC order */ /* Q0 */ - Word16 const lenLpcExc, /* i: length of the LPC excitation buffer */ /* Q0 */ - Word16 const preemph_fac, /* i: preemphasis factor */ /* Q15 */ - Word16 const numLoops, /* i: number of loops */ /* Q0 */ - Word16 *Exp /* o: exponent of return value Q15 */ -) +float getLevelSynDeemph(float const h1Init[], /* i: input value or vector to be processed */ + float const A[], /* i: LPC coefficients */ + int const lenLpcExc, /* i: length of the LPC excitation buffer */ + float const preemph_fac, /* i: preemphasis factor */ + int const numLoops) /* i: number of loops */ { - Word32 levelSynDeemphSub; - Word32 levelSynDeemph ; - Word16 h1[L_FRAME_PLUS/4]; /*Q15*/ - Word16 mem[M]; - Word16 tmp; - Word16 loop; - Word16 s16, tmp16, Hr16; - Word16 Q_h1; + float levelSynDeemphSub; + float levelSynDeemph = 0; + float h1[L_FRAME_PLUS/4]; + float mem[M]; + float tmp = 0; + int loop; - - levelSynDeemphSub = L_deposit_l(0); - levelSynDeemph = L_deposit_l(0); - tmp = 0; - Q_h1 = 9; /*synthesis scaling for */ move16(); - - /*calculate headroom for dotproduct*/ - Hr16 = sub(15,norm_s(lenLpcExc)); - - Q_h1 = s_max(sub(Q_h1,Hr16),0); /*compensate synthesis scaling with Headroom as much as possible to retain as much precision as possible*/ - - /*Factor to be multiplied in order to calculate dotproduct with headroom*/ - tmp16 = shr(32768/2,sub(Hr16,1)); - - /*moved from inside loop, before synthesis*/ - h1Init[0] = mult_r(h1Init[0],tmp16); - move16(); - - FOR (loop = 0; loop < numLoops; loop++) + for (loop = 0; loop < numLoops; loop++) { - set16_fx(h1, 0, lenLpcExc); - set16_fx(mem, 0, lpcorder); + set_zero(h1, lenLpcExc); + set_zero(mem, M); - Copy(h1Init, h1, 1); - /*h1 will be scaled down, Q_h1 */ - E_UTIL_synthesis(Q_h1, A, h1, h1, lenLpcExc, mem, 0, lpcorder); - deemph_fx(h1, preemph_fac, lenLpcExc, &tmp); + h1[0] = *h1Init; + + syn_filt(A, M, h1, h1, lenLpcExc, mem, 0); + deemph(h1, preemph_fac, lenLpcExc, &tmp); A += (M+1); /* gain introduced by synthesis+deemphasis */ - /*levelSynDeemphSub = (float)sqrt(dot_product( h1, h1, lenLpcExc));*/ - levelSynDeemphSub = Dot_product12_offs(h1, h1, lenLpcExc, &s16, 0); - s16 = sub(shl(add(Q_h1,Hr16),1), sub(30, s16)); - - levelSynDeemphSub = Sqrt32(levelSynDeemphSub,&s16); /*Q31*/ - - /* mean of the above across all subframes -- moved outta loop*/ - /*levelSynDeemph += (1.0/(float)numLoops) * levelSynDeemphSub;*/ - tmp16 = 32767/*1.0f Q15*/; - move16(); - - if (sub(numLoops , 1) > 0) - { - tmp16 = div_s(1,numLoops); - } - - levelSynDeemph = L_add(levelSynDeemph , L_shl(Mpy_32_16_1(levelSynDeemphSub,tmp16),sub(s16,10))); /*10Q21*/ + levelSynDeemphSub = (float)sqrt(dotp( h1, h1, lenLpcExc)); + /* mean of the above across all subframes */ + levelSynDeemph += (1.0f/(float)numLoops) * levelSynDeemphSub; } - s16 = norm_l(levelSynDeemph); - levelSynDeemph = L_shl(levelSynDeemph, s16); - move16(); - *Exp = sub(10,s16); /*Set exponent in order to transform returnvalue to Q15*/ - - return round_fx(levelSynDeemph); /*Q15*/ + return levelSynDeemph; } -/* BASOP version: up to date with rev 7422 */ -void genPlcFiltBWAdap(const Word32 sr_core, Word16 *lpFiltAdapt, const Word16 type, const Word16 alpha +void genPlcFiltBWAdap(int const sr_core, /* i: core sampling rate */ + float* lpFiltAdapt, /* o: filter coefficients for filtering codebooks in case of flc */ + int const type, /* i: type of filter, either 0 : lowpass or 1 : highpass */ + float const alpha /* i: fade out factor [0 1) used decrease filter tilt */ ) { - Word16 a, b, exp; - - - assert(type == 0 || type == 1); - - IF ( L_sub(sr_core, 16000) == 0 ) + float a; + switch (sr_core) { - IF (type == 0) - { - move16(); - move16(); - move16(); - *lpFiltAdapt++ = 7282/* 0.4000f/(2.f*0.4000f+1.f) Q15*/; - *lpFiltAdapt++ = 18204/* 1.f/(2.f*0.4000f+1.f) Q15*/; - *lpFiltAdapt = 7282/* 0.4000f/(2.f*0.4000f+1.f) Q15*/; - } - ELSE - { - a = mult_r(13107/*0.4000f Q15*/, alpha); - exp = 0; - move16(); - b = Inv16(add(a, 16384/*0.5f Q15*/), &exp); - b = shr(b, sub(1, exp)); - a = negate(mult_r(a, b)); - move16(); - move16(); - move16(); - *lpFiltAdapt++ = a; - *lpFiltAdapt++ = b; - *lpFiltAdapt = a; - } + case 16000 : + a = 0.4000f; + break; + default : + a = 0.2813f; /*sr_core = 12800*/ + break; } - ELSE + switch (type) { - IF (type == 0) - { - move16(); - move16(); - move16(); - *lpFiltAdapt++ = 5899/* 0.2813f/(2.f*0.2813f+1.f) Q15*/; - *lpFiltAdapt++ = 20970/* 1.f/(2.f*0.2813f+1.f) Q15*/; - *lpFiltAdapt = 5899/* 0.2813f/(2.f*0.2813f+1.f) Q15*/; - } - ELSE { - a = mult_r(9218/*0.2813f Q15*/, alpha); - exp = 0; - move16(); - b = Inv16(add(a, 16384/*0.5f Q15*/), &exp); - b = shr(b, sub(1, exp)); - a = negate(mult_r(a, b)); - move16(); - move16(); - move16(); - *lpFiltAdapt++ = a; - *lpFiltAdapt++ = b; - *lpFiltAdapt = a; - } + case 0 : + *lpFiltAdapt++ = a/(2.f*a+1.f); + *lpFiltAdapt++ = 1.f/(2.f*a+1.f); + *lpFiltAdapt = a/(2.f*a+1.f); + break; + case 1 : + a *= alpha; + *lpFiltAdapt++ = -a/(2.f*a+1.f); + *lpFiltAdapt++ = 1.f/(2.f*a+1.f); + *lpFiltAdapt = -a/(2.f*a+1.f); + break; + default : + fprintf(stderr,"PLC: Filter type neither lowpass nor highpass.\n"); + assert(0); + break; } } @@ -324,147 +173,111 @@ void genPlcFiltBWAdap(const Word32 sr_core, Word16 *lpFiltAdapt, const Word16 ty * PLC: [ACELP: general] * PLC: high pass filtering *-----------------------------------------------------------------*/ -/*VERSIONINFO: This port is up to date with trunk rev. 32434*/ -void highPassFiltering( - const Word16 last_good, /* i: short last classification type */ - const Word16 L_buffer, /* i: int buffer length */ - Word16 exc2[], /* i/o: Qx unvoiced excitation before the high pass filtering */ - const Word16 hp_filt[], /* i: Q15 high pass filter coefficients */ - const Word16 l_fir_fer) /* i: high pass filter length */ - +void highPassFiltering(const short last_good, /* i: last classification type */ + const int L_buffer, /* i: buffer length */ + float exc2[], /* i/o: unvoiced excitation before the high pass filtering */ + const float hp_filt[], /* i: high pass filter coefficients */ + const int l_fir_fer) /* i: high pass filter length */ { - Word16 i; /*int*/ + int i; - IF( sub(last_good , UNVOICED_TRANSITION)> 0 ) + if( last_good > UNVOICED_TRANSITION ) { - - FOR( i=0 ; i< L_buffer; i++ ) + for( i=0 ; i< L_buffer; i++ ) { - exc2[i] = round_fx(L_sub(Dot_product(&exc2[i], hp_filt, l_fir_fer), 1)); + exc2[i] = dotp(&exc2[i], hp_filt, l_fir_fer); } } } + /*----------------------------------------------------------------------------------* * PLC: [Common: mode decision] * PLC: Decide which Concealment to use. Update pitch lags if needed *----------------------------------------------------------------------------------*/ -Word16 GetPLCModeDecision( - Decoder_State_fx *st /* i/o: decoder memory state pointer */ -) +int GetPLCModeDecision(Decoder_State *st /* i/o: decoder memory state pointer */ + ) { - Word16 /*int*/ core; - Word16 numIndices = 0; - - - IF( sub(st->flagGuidedAcelp,1) == 0 ) + int core; + int numIndices = 0; + if( st->flagGuidedAcelp == 1 ) { - st->old_pitch_buf_fx[2*st->nb_subfr] = L_deposit_h(st->guidedT0); - st->old_pitch_buf_fx[2*st->nb_subfr+1] = L_deposit_h(st->guidedT0); - st->mem_pitch_gain[0] = st->mem_pitch_gain[1] = 16384/*1.f Q14*/;/*Q14*/ + /* update mem_lag according to info available on future frame */ + st->old_pitch_buf[2*st->nb_subfr] = (float)st->guidedT0; + st->old_pitch_buf[2*st->nb_subfr+1] = (float)st->guidedT0; + st->mem_pitch_gain[0] = st->mem_pitch_gain[1] = 1.f; } - st->plc_use_future_lag = 0; - move16(); - test(); - test(); - if(( st->last_core_fx > ACELP_CORE && st->tcxltp_last_gain_unmodified!=0 ) - || ( sub(st->flagGuidedAcelp,1) == 0 ) - ) + if(( st->last_core > ACELP_CORE && st->tcxltp_last_gain_unmodified != 0 ) || ( st->flagGuidedAcelp == 1 )) { /* no updates needed here, because already updated in last good frame */ st->plc_use_future_lag = 1; - move16(); } - - IF (sub(st->last_core_fx,-1) == 0) + else { - core = TCX_20_CORE; - move16(); - st->last_core_fx = ACELP_CORE; - move16(); - if(st->Opt_AMR_WB_fx) + st->plc_use_future_lag = 0; + } + if (st->last_core == -1) + { + if (st->Opt_AMR_WB) { - core = ACELP_CORE; - move16(); + core = 0; } + else + { + core = 1; + } + st->last_core = ACELP_CORE; st->tonal_mdct_plc_active = 0; - move16(); } - ELSE + else { - core = ACELP_CORE; - move16(); - if (sub(st->nbLostCmpt,1) > 0) + core = 0; + if (st->nbLostCmpt > 1) { core = st->last_core_bfi; - move16(); } - IF (sub(st->nbLostCmpt,1) == 0) + + /* no FD TCX PLC after a TCX transition frame: the appropriate framing is not implemented */ + if (st->nbLostCmpt == 1) { st->tonal_mdct_plc_active = 0; - move16(); - test(); - test(); - test(); - IF ( !(st->rf_flag && st->use_partial_copy && (sub(st->rf_frame_type, RF_TCXTD1) == 0 || sub(st->rf_frame_type, RF_TCXTD2) == 0))) + if ( !(st->rf_flag && st->use_partial_copy && (st->rf_frame_type == RF_TCXTD1 || st->rf_frame_type == RF_TCXTD2))) { - test(); - test(); - test(); - test(); - test(); - test(); - IF ((sub(st->last_core_fx,TCX_20_CORE) == 0) && (sub(st->second_last_core,TCX_20_CORE) == 0) - && ((L_sub(st->old_fpitch,L_deposit_h(shr(st->L_frame_fx,1)))) <= 0 - || (sub(st->tcxltp_last_gain_unmodified,13107/*0.4f Q15*/) <= 0)) - /* it is fine to call the detection even if no ltp information - is available, meaning that st->old_fpitch == - st->tcxltp_second_last_pitch == st->L_frame */ - && (L_sub(st->old_fpitch, st->tcxltp_second_last_pitch) == 0) - && !st->last_tns_active && !st->second_last_tns_active) + if ((st->last_core == TCX_20_CORE) + && (st->second_last_core == TCX_20_CORE) + && ((st->old_fpitch <= 0.5f*st->L_frame) || (st->tcxltp_last_gain_unmodified <= 0.4f)) + /* it is fine to call the detection even if no ltp information + is available, meaning that st->old_fpitch == + st->tcxltp_second_last_pitch == st->L_frame */ + && (st->old_fpitch == st->tcxltp_second_last_pitch) + && !st->last_tns_active + && !st->second_last_tns_active) { - Word32 pitch; - - pitch = L_deposit_h(0); - if(st->tcxltp_last_gain_unmodified > 0) - { - pitch = L_add(st->old_fpitch, 0); - } TonalMDCTConceal_Detect(&st->tonalMDCTconceal, - pitch, + (st->tcxltp_last_gain_unmodified > 0) ? st->old_fpitch : 0, &numIndices); - - test(); - test(); - test(); - test(); - test(); - test(); - IF ((sub(numIndices,10) > 0) - || ((sub(numIndices,5) > 0) - && (L_sub(L_abs(L_sub(st->tcxltp_third_last_pitch,st->tcxltp_second_last_pitch)),32768l/*0.5f Q16*/) < 0)) - || ((numIndices > 0) && ((sub(st->last_good_fx,UNVOICED_TRANSITION) <= 0) || (sub(st->tcxltp_last_gain_unmodified,13107/*0.4f Q15*/) <= 0)) - && (L_sub(L_abs(L_sub(st->tcxltp_third_last_pitch,st->tcxltp_second_last_pitch)),32768l/*0.5f Q16*/) < 0))) + if ((numIndices > 10) + || ((numIndices > 5) + && (fabs(st->tcxltp_third_last_pitch-st->tcxltp_second_last_pitch) < 0.5f) + ) + || ((numIndices > 0) && ((st->last_good <= UNVOICED_TRANSITION) || (st->tcxltp_last_gain_unmodified <= 0.4f)) + && (fabs(st->tcxltp_third_last_pitch-st->tcxltp_second_last_pitch) < 0.5f) + )) { - core = TCX_20_CORE; - move16(); + core = 1; st->tonal_mdct_plc_active = 1; - move16(); } - ELSE IF (sub(st->last_good_fx,UNVOICED_TRANSITION) <= 0 || sub(st->tcxltp_last_gain_unmodified,13107/*0.4f Q15*/)<=0) + else if (st->last_good <= UNVOICED_TRANSITION || st->tcxltp_last_gain_unmodified <= 0.4f) { - core = TCX_20_CORE; - move16(); + core = 1; } } - ELSE IF (st->last_core_fx != ACELP_CORE) + else if (st->last_core != ACELP_CORE) { - test(); - if (sub(st->last_good_fx,UNVOICED_TRANSITION) <= 0 || sub(st->tcxltp_last_gain_unmodified,13107/*0.4f Q15*/)<=0) + if (st->last_good <= UNVOICED_TRANSITION || st->tcxltp_last_gain_unmodified <= 0.4f) { - core = st->last_core_fx; - move16(); + core = st->last_core; } } } diff --git a/src/libs/libevs/lib_dec/evs_dec.cpp b/src/libs/libevs/lib_dec/evs_dec.cpp new file mode 100644 index 00000000..f5cae6e1 --- /dev/null +++ b/src/libs/libevs/lib_dec/evs_dec.cpp @@ -0,0 +1,1024 @@ +/*==================================================================================== + EVS Codec 3GPP TS26.443 Nov 13, 2018. Version 12.11.0 / 13.7.0 / 14.3.0 / 15.1.0 + ====================================================================================*/ + +#include "options.h" +#include "cnst.h" +#include "rom_com.h" +#include "prot.h" + +/*--------------------------------------------------------------------------* + * evs_dec() + * + * Principal decoder routine + *--------------------------------------------------------------------------*/ + +void evs_dec( + Decoder_State *st, /* i/o: Decoder state structure */ + float *output, /* o : output synthesis signal */ + frameMode frameMode /* i : Decoder frame mode */ +) +{ + short i, output_frame, coder_type; + short sharpFlag; + float synth[L_FRAME48k + HQ_DELTA_MAX*HQ_DELAY_COMP]; + float hb_synth[L_FRAME48k]; + float tmp_buffer[L_FRAME48k]; + short tmps, incr; + float bwe_exc_extended[L_FRAME32k+NL_BUFF_OFFSET]; + float voice_factors[NB_SUBFR16k]; + float fb_exc[L_FRAME16k]; + short core_switching_flag; + float old_syn_12k8_16k[L_FRAME16k]; + float tmp; + float pitch_buf[NB_SUBFR16k]; + short unbits; + short hq_core_type; + short post_hq_delay; + short sid_bw; + short delay_comp, delta, delay_tdbwe; + float tmpF; + short concealWholeFrame; /* status after decoding */ + short concealWholeFrameTmp; + float pcmbufFB[L_FRAME_MAX]; + + + /*------------------------------------------------------------------* + * Initialization + *-----------------------------------------------------------------*/ + + delay_tdbwe=0; + sid_bw = -1; + concealWholeFrameTmp = -1; + if( !st->bfi ) + { + st->extl = -1; + } + + output_frame = (short)(st->output_Fs / 50); + + core_switching_flag = 0; + sharpFlag = 0; + unbits = 0; + + st->use_partial_copy = 0; + st->rf_flag = 0; + + if( st->bfi == 1 ) + { + hq_core_type = st->last_hq_core_type; + coder_type = st->last_coder_type; + } + else + { + hq_core_type = -1; + coder_type = INACTIVE; + } + + /* PLC: [TCX: Fade-out-recovery] + * PLC: overlapping part needs to be attenuated for first good frame */ + if (!st->bfi && st->prev_bfi && (st->last_codec_mode == MODE2) && (st->last_core_bfi == TCX_20_CORE || st->last_core_bfi == TCX_10_CORE)) + { + v_multc( st->old_out, st->plcInfo.recovery_gain, st->old_out, st->L_frameTCX ); + v_multc( st->old_outLB, st->plcInfo.recovery_gain, st->old_outLB, st->L_frame ); + + if( !st->tcx_cfg.last_aldo ) + { + v_multc( st->syn_OverlFB, st->plcInfo.recovery_gain, st->syn_OverlFB, st->tcx_cfg.tcx_mdct_window_lengthFB ); + v_multc( st->syn_Overl, st->plcInfo.recovery_gain, st->syn_Overl, st->tcx_cfg.tcx_mdct_window_length ); + } + } + + set_f( voice_factors, 0.f, NB_SUBFR16k ); + set_f( hb_synth, 0.0f, output_frame ); + + st->rate_switching_reset = 0; + + if(!st->bfi) + { + st->flagGuidedAcelp = 0; + } + + /*----------------------------------------------------------------* + * Updates in case of AMR-WB IO mode -> EVS primary mode switching + *----------------------------------------------------------------*/ + + if( st->last_core == AMR_WB_CORE ) + { + updt_IO_switch_dec( output_frame, st ); + } + + if( frameMode != FRAMEMODE_MISSING ) /* frame mode normal or future frame */ + { + getPartialCopyInfo(st, &coder_type, &sharpFlag); + + frameMode = static_cast(st->bfi); + } + + if( st->rf_frame_type == RF__NO_DATA && st->use_partial_copy ) + { + /* the partial copy is a RF FRAME__NO_DATA frame and should follow the concealment path*/ + st->bfi = 1; + st->codec_mode = st->last_codec_mode; + frameMode = FRAMEMODE_MISSING; + st->use_partial_copy = 0; + } + + /* if previous frame was concealed via ACELP, drop TCX partial copy info and continue ACELP concealment */ + if( st->use_partial_copy && st->core == TCX_20_CORE && st->prev_bfi && st->last_core == ACELP_CORE ) + { + st->bfi = 1; + st->codec_mode = st->last_codec_mode; + frameMode = FRAMEMODE_MISSING; + st->use_partial_copy = 0; + st->core = ACELP_CORE; + } + + /*------------------------------------------------------------------* + * Decoding + *-----------------------------------------------------------------*/ + + if( st->codec_mode == MODE1 ) + { + /*------------------------------------------------------------------* + * Decision matrix (selection of technologies) + *-----------------------------------------------------------------*/ + + /* decision matrix (selection of technologies) */ + if( st->bfi != 1 ) + { + decision_matrix_dec( st, &coder_type, &sharpFlag, &hq_core_type, &core_switching_flag ); + + if( st->bfi != 1 ) + { + st->sr_core = 50*st->L_frame; + st->fscale_old = st->fscale; + st->fscale = sr2fscale(st->sr_core); + } + else + { + frameMode = FRAMEMODE_MISSING; + } + } + } + + + if( st->codec_mode == MODE1 ) + { + /*------------------------------------------------------------------* + * Initialization + *-----------------------------------------------------------------*/ + + if( st->bfi == 1 ) + { + st->nbLostCmpt++; + } + else + { + st->nbLostCmpt = 0; + } + st->enablePlcWaveadjust = 0; + + /*---------------------------------------------------------------------* + * Detect bandwidth switching + *---------------------------------------------------------------------*/ + + bandwidth_switching_detect( st ); + + /*---------------------------------------------------------------------* + * Preprocessing (preparing) for ACELP/HQ core switching + *---------------------------------------------------------------------*/ + + core_switching_pre_dec( st, output_frame ); + + /*---------------------------------------------------------------------* + * ACELP core decoding + * HQ core decoding + *---------------------------------------------------------------------*/ + + if ( st->core == ACELP_CORE ) + { + /* ACELP core decoder */ + acelp_core_dec( st, synth, bwe_exc_extended, voice_factors, old_syn_12k8_16k, coder_type, sharpFlag, pitch_buf, &unbits, &sid_bw ); + } + else + { + /* HQ core decoder */ + hq_core_dec( st, synth, output_frame, hq_core_type, core_switching_flag ); + } + + /*---------------------------------------------------------------------* + * Postprocessing for ACELP/HQ core switching + *---------------------------------------------------------------------*/ + + core_switching_post_dec( st, synth, output_frame, core_switching_flag, coder_type ); + + /*---------------------------------------------------------------------* + * Pre-processing for bandwidth switching + *---------------------------------------------------------------------*/ + + bw_switching_pre_proc( st, old_syn_12k8_16k ); + + /*---------------------------------------------------------------------* + * WB TBE decoding + * WB BWE decoding + *---------------------------------------------------------------------*/ + + + if( st->extl == WB_TBE ) + { + /* WB TBE decoder */ + wb_tbe_dec( st, coder_type, bwe_exc_extended, voice_factors, hb_synth ); + } + + if( st->extl == WB_BWE && st->bws_cnt == 0 ) + { + /* WB BWE decoder */ + wb_bwe_dec( synth, hb_synth, output_frame, st, coder_type, voice_factors, pitch_buf ); + } + + /*---------------------------------------------------------------------* + * SWB(FB) TBE decoding + * SWB(FB) BWE decoding + *---------------------------------------------------------------------*/ + + if( st->extl == SWB_TBE || st->extl == FB_TBE + ||( coder_type != AUDIO && coder_type != INACTIVE && st->core_brate >= SID_2k40 && st->core == ACELP_CORE + && st->output_Fs >= 32000 && st->bwidth > NB && st->bws_cnt > 0 && !st->ppp_mode_dec && !( st->nelp_mode_dec == 1 && st->bfi == 1 ) ) ) + + { + /* SWB TBE decoder */ + swb_tbe_dec( st, coder_type, bwe_exc_extended, voice_factors,old_syn_12k8_16k, fb_exc, hb_synth, pitch_buf ); + + /* FB TBE decoder */ + if( output_frame == L_FRAME48k && st->extl == FB_TBE ) + { + fb_tbe_dec( st, fb_exc, hb_synth ); + } + } + else if( st->extl == SWB_BWE || st->extl == FB_BWE || (st->output_Fs >= 32000 && st->core == ACELP_CORE && st->bwidth > NB + && st->bws_cnt > 0 && !st->ppp_mode_dec && !( st->nelp_mode_dec == 1 && st->bfi == 1 ) ) ) + + { + /* SWB BWE decoder */ + swb_bwe_dec( st, synth, hb_synth, output_frame, coder_type ); + } + else if( st->extl == SWB_BWE_HIGHRATE || st->extl == FB_BWE_HIGHRATE ) + { + swb_bwe_dec_hr( st, old_syn_12k8_16k, hb_synth, output_frame, unbits, pitch_buf ); + } + + /*---------------------------------------------------------------------* + * FEC - recovery after lost HQ core (smoothing of the BWE component) + *---------------------------------------------------------------------*/ + + if( st->prev_bfi && st->last_core == HQ_CORE && st->extl != -1 ) + { + tmp = FRAC_BWE_SMOOTH/output_frame; + + for (i = 0; i < output_frame/FRAC_BWE_SMOOTH; i++) + { + hb_synth[i] *= (i*tmp); + } + } + + /*---------------------------------------------------------------------* + * SWB CNG + *---------------------------------------------------------------------*/ + + if( output_frame >= L_FRAME32k ) + { + /* SHB CNG decoder */ + swb_CNG_dec( st, synth, hb_synth, sid_bw ); + } + + + /*----------------------------------------------------------------* + * Delay ACELP core synthesis to be synchronized with the components of bandwidth extension layers + *----------------------------------------------------------------*/ + + if ( output_frame >= L_FRAME16k ) + { + tmps = NS2SA(st->output_Fs, DELAY_BWE_TOTAL_NS - DELAY_CLDFB_NS); + mvr2r( synth, tmp_buffer, output_frame ); + mvr2r( st->prev_synth_buffer, synth, tmps ); + mvr2r( tmp_buffer, synth + tmps, output_frame - tmps ); + mvr2r( tmp_buffer + output_frame - tmps, st->prev_synth_buffer, tmps ); + } + + if( st->core == ACELP_CORE + && !st->bfi && st->prev_bfi + && st->last_total_brate >= HQ_48k + && st->last_codec_mode == MODE2 + && (st->last_core_bfi == TCX_20_CORE || st->last_core_bfi == TCX_10_CORE) + && st->plcInfo.concealment_method == TCX_NONTONAL + && st->plcInfo.nbLostCmpt < 4 ) + { + tmps = 0; + if( output_frame >= L_FRAME16k ) + { + tmps = NS2SA(st->output_Fs, DELAY_BWE_TOTAL_NS); + } + + waveform_adj2( st->tonalMDCTconceal.secondLastPcmOut, + synth+tmps, + st->plcInfo.data_noise, + &st->plcInfo.outx_new_n1, + &st->plcInfo.nsapp_gain, + &st->plcInfo.nsapp_gain_n, + &st->plcInfo.recovery_gain, + st->plcInfo.step_concealgain, + st->plcInfo.Pitch, + st->plcInfo.FrameSize, + tmps, + st->plcInfo.nbLostCmpt + 1, + st->bfi ); + st->plcInfo.Pitch = 0; + } + + /*----------------------------------------------------------------* + * Addition of BWE components to the ACELP core synthesis + *----------------------------------------------------------------*/ + + if( st->extl != -1 || (st->bws_cnt > 0 && st->core == ACELP_CORE) ) + { + /* Calculate an additional delay of extension layer components to be synchronized with ACELP synthesis */ + if (st->L_frame == L_FRAME ) + { + /* TBE on top of ACELP@12.8kHz */ + tmps = NS2SA( st->output_Fs, MAX_DELAY_TBE_NS - DELAY_SWB_TBE_12k8_NS ); + } + else + { + if( st->extl == SWB_BWE_HIGHRATE || st->extl == FB_BWE_HIGHRATE ) + { + /* HR SWB BWE on top of ACELP@16kHz */ + tmps = NS2SA(st->output_Fs, DELAY_BWE_TOTAL_NS); + } + else + { + /* TBE on top of ACELP@16kHz */ + tmps = NS2SA( st->output_Fs, MAX_DELAY_TBE_NS - DELAY_SWB_TBE_16k_NS ); + } + } + + /* Smooth transitions when switching between different technologies */ + if( (st->extl != st->last_extl || (st->extl == st->last_extl && (st->core ^ st->last_core) == HQ_CORE)) && !(st->extl == SWB_CNG && st->last_extl == SWB_TBE) ) + { + /* switching between BWE and TBE technologies */ + incr = (short) ( L_FRAME / (tmps + 0.5f) ); + for (i=0; ihb_prev_synth_buffer, 0.0f, tmps ); + } + else if( tmps < st->old_bwe_delay ) + { + /* the previous frame was TBE on top of ACELP@16kHz and the current frame is TBE on top of ACELP@12.8kHz */ + incr = (short) ( L_FRAME / (tmps + 0.5f) ); + for (i=0; ihb_prev_synth_buffer[i] * sin_table256[255 - i * incr] + + st->hb_prev_synth_buffer[st->old_bwe_delay - 1 - i] * sin_table256[i * incr]; + } + + mvr2r( tmp_buffer, st->hb_prev_synth_buffer, tmps ); + } + else if( tmps > st->old_bwe_delay ) + { + /* the previous frame was TBE on top of ACELP@12.8kHz and the current frame is TBE on top of ACELP@16kHz */ + incr = (short)( L_FRAME / (st->old_bwe_delay + 0.5f) ); + for( i=0; iold_bwe_delay; i++ ) + { + tmp_buffer[i] = st->hb_prev_synth_buffer[i] * sin_table256[255 - i * incr]; + } + + for( ; iold_bwe_delay; i++ ) + { + tmp_buffer[tmps - 1 - i] += st->hb_prev_synth_buffer[st->old_bwe_delay - 1 - i] * sin_table256[i * incr]; + } + + mvr2r( tmp_buffer, st->hb_prev_synth_buffer, tmps ); + } + + /* Delay hb_synth */ + mvr2r( hb_synth, tmp_buffer, output_frame ); + mvr2r( st->hb_prev_synth_buffer, hb_synth, tmps ); + mvr2r( tmp_buffer, hb_synth + tmps, output_frame - tmps ); + mvr2r( tmp_buffer + output_frame - tmps, st->hb_prev_synth_buffer, tmps ); + + st->old_bwe_delay = tmps; + if( ( st->ppp_mode_dec || ( st->nelp_mode_dec == 1 && st->bfi == 1 ) ) && st->L_frame == st->last_L_frame && (st->bws_cnt > 1 || st->last_extl != -1) ) + + { + mvr2r( st->old_hb_synth, hb_synth, output_frame ); + } + else + { + mvr2r( hb_synth, st->old_hb_synth, output_frame ); + } + + /* Add the delayed hb_synth component to the delayed ACELP synthesis */ + v_add( synth, hb_synth, synth, output_frame ); + + /* SWB CNG/DTX - calculate SHB energy */ + if ( output_frame >= L_FRAME32k && st->extl > SWB_CNG ) + { + st->last_shb_ener = 0.001f; + for ( i=0; ilast_shb_ener += hb_synth[i] * hb_synth[i]; + } + st->last_shb_ener /= (float)output_frame; + st->last_shb_ener = 10 * (float)log10(st->last_shb_ener); + } + } + + /* TCX-LTP Postfilter: used in Mode 1 to update memories and to avoid discontinuities when the past frame was TCX */ + tcx_ltp_post( st->tcxltp, ACELP_CORE, output_frame, st->L_frame_past, 0, synth, NULL, NS2SA( st->output_Fs, TCXLTP_DELAY_NS ), + 0, 0, 0, 0.f, &st->tcxltp_pitch_int_post_prev, &st->tcxltp_pitch_fr_post_prev, &st->tcxltp_gain_post_prev, + &st->tcxltp_filt_idx_prev, st->pit_res_max, &st->pit_res_max_past, 0.f, 0, st->tcxltp_mem_in, st->tcxltp_mem_out, st->total_brate ); + + /* final output of synthesis signal */ + mvr2r( synth, output, output_frame ); + } + else /* Mode 2 */ + { + + /* -------------------------------------------------------------- * + * Mode 2 concealment + * -------------------------------------------------------------- */ + + concealWholeFrame = 0; + + if( frameMode == FRAMEMODE_NORMAL ) + { + st->m_decodeMode = DEC_NO_FRAM_LOSS; + } + + if( frameMode == FRAMEMODE_MISSING ) + { + if( st->use_partial_copy && st->rf_frame_type >= RF_TCXFD && st->rf_frame_type <= RF_TCXTD2 ) + { + st->m_decodeMode = DEC_NO_FRAM_LOSS; + } + else + { + st->m_decodeMode = DEC_CONCEALMENT_EXT; + } + } + + if( st->m_decodeMode == DEC_CONCEALMENT_EXT ) + { + concealWholeFrame = 1; + } + + /* -------------------------------------------------------------- * + * Decode core + * -------------------------------------------------------------- */ + + dec_acelp_tcx_frame( st, &coder_type, &concealWholeFrame, output, + st->p_bpf_noise_buf, pcmbufFB, bwe_exc_extended, voice_factors, pitch_buf ); + + concealWholeFrameTmp = concealWholeFrame; + if(st->bfi) + { + frameMode = FRAMEMODE_MISSING; + } + + if( st->igf ) + { + /* TBE for Mode 2 interface */ + if( (st->bfi == 0 || st->last_core == ACELP_CORE) && st->core == ACELP_CORE ) + { + switch( st->bwidth ) + { + case WB: + st->extl = WB_TBE; + st->extl_brate = WB_TBE_0k35; + break; + case SWB: + st->extl = SWB_TBE; + st->extl_brate = SWB_TBE_1k6; + break; + + case FB: + st->extl = FB_TBE; + st->extl_brate = FB_TBE_1k8; + break; + } + } + else + { + st->extl = IGF_BWE; + st->extl_brate = 0; + } + + if( st->output_Fs == 8000 || ( st->output_Fs == 16000 && st->L_frame == L_FRAME16k ) ) + { + st->extl = -1; + } + + st->core_brate = st->total_brate - st->extl_brate; + + st->bws_cnt = 0; + st->bws_cnt1 = 0; + st->tilt_wb = 0; + + if( st->m_frame_type == ACTIVE_FRAME ) + { + if( (st->bfi == 0 || st->last_core == ACELP_CORE) && st->core == ACELP_CORE ) + { + if( st->extl == WB_TBE ) + { + wb_tbe_dec( st, coder_type, bwe_exc_extended, voice_factors, hb_synth ); + } + else if( st->extl == SWB_TBE || st->extl == FB_TBE ) + { + /* SWB TBE decoder */ + swb_tbe_dec( st, coder_type, bwe_exc_extended, voice_factors, st->old_core_synth, fb_exc, hb_synth, pitch_buf ); + + if( st->extl == FB_TBE && output_frame == L_FRAME48k ) + { + fb_tbe_dec( st, fb_exc, hb_synth ); + } + } + mvr2r( hb_synth, st->old_hb_synth, output_frame ); + } + else + { + if( st->last_core == ACELP_CORE ) + { + if( ( st->bwidth == SWB || st->bwidth == FB ) && + (( st->last_extl == SWB_TBE || st->last_extl == FB_TBE) && st->last_codec_mode == MODE2 ) ) + { + GenTransition( st->syn_overlap, st->old_tbe_synth, 2*NS2SA(st->output_Fs, DELAY_BWE_TOTAL_NS), hb_synth, + st->genSHBsynth_Hilbert_Mem, st->genSHBsynth_state_lsyn_filt_shb_local, &(st->syn_dm_phase), + st->output_Fs, st->int_3_over_2_tbemem_dec, st->rf_flag, st->total_brate ); + } + else if ( st->bwidth == WB && st->last_extl == WB_TBE ) + { + GenTransition_WB( st->syn_overlap, st->old_tbe_synth, 2*NS2SA(st->output_Fs, DELAY_BWE_TOTAL_NS), hb_synth, + st->state_lsyn_filt_shb, st->state_lsyn_filt_dwn_shb, st->output_Fs, st->mem_resamp_HB ); + } + + TBEreset_dec( st, st->bwidth ); + } + else if( st->last_codec_mode == MODE1 ) + { + swb_tbe_reset( st->mem_csfilt, st->mem_genSHBexc_filt_down_shb, st->state_lpc_syn, + st->syn_overlap, st->state_syn_shbexc, &(st->tbe_demph), &(st->tbe_premph), st->mem_stp_swb, &(st->gain_prec_swb) ); + if( sub(st->extl, FB_TBE) == 0 ) + { + set_f( st->fb_state_lpc_syn, 0, LPC_SHB_ORDER ); + st->fb_tbe_demph = 0; + fb_tbe_reset_synth( st->fbbwe_hpf_mem, &st->prev_fbbwe_ratio ); + } + swb_tbe_reset_synth( st->genSHBsynth_Hilbert_Mem, st->genSHBsynth_state_lsyn_filt_shb_local ); + } + } + } + } + + + if( st->m_frame_type != ACTIVE_FRAME ) + { + st->extl = -1; + st->extl_brate = 0; + } + + /* -------------------------------------------------------------- * + * Postprocessing + * -------------------------------------------------------------- */ + + { + float *realBuffer[CLDFB_NO_COL_MAX], *imagBuffer[CLDFB_NO_COL_MAX]; + float realBufferTmp[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX], imagBufferTmp[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX]; + + for( i=0; icldfbSyn->nab = min( st->cldfbAna->no_channels, st->cldfbSyn->no_channels ); + st->cldfbAna->nab = 0; + + if( st->hFdCngDec != NULL && (st->sr_core == 8000 || st->sr_core == 12800 || st->sr_core == 16000) && st->total_brate <= ACELP_32k ) + { + /* -------------------------------------------------------------- * + * In CLDFB domain: + * - perform noise estimation during active frames + * - do CNG during inactive frames + * -------------------------------------------------------------- */ + + noisy_speech_detection( st->VAD && st->m_frame_type==ACTIVE_FRAME, output, st->hFdCngDec->hFdCngCom->frameSize, + st->hFdCngDec->msNoiseEst, st->hFdCngDec->psize_shaping, st->hFdCngDec->nFFTpart_shaping, + &(st->hFdCngDec->lp_noise), &(st->hFdCngDec->lp_speech), &(st->hFdCngDec->hFdCngCom->flag_noisy_speech) ); + + st->hFdCngDec->hFdCngCom->likelihood_noisy_speech = 0.99f*st->hFdCngDec->hFdCngCom->likelihood_noisy_speech + 0.01f*(float)st->hFdCngDec->hFdCngCom->flag_noisy_speech; + + st->lp_noise = st->hFdCngDec->lp_noise; + + ApplyFdCng( output, realBuffer, imagBuffer, st->hFdCngDec, st->m_frame_type, st, concealWholeFrame, 0 ); + + /* Generate additional comfort noise to mask potential coding artefacts */ + if( st->m_frame_type == ACTIVE_FRAME && st->flag_cna ) + { + generate_masking_noise( output, st->hFdCngDec->hFdCngCom, st->hFdCngDec->hFdCngCom->frameSize, 0 ); + } + } + + if( st->flag_cna == 0 && st->L_frame == L_FRAME16k && st->last_flag_cna == 1 && ( (st->last_core == ACELP_CORE && st->last_coder_type != AUDIO) || st->last_core == TCX_20_CORE || st->last_core == AMR_WB_CORE ) ) + { + v_multc( st->hFdCngDec->hFdCngCom->olapBufferSynth2+5*st->L_frame/4, 256.f, tmp_buffer, st->L_frame/2 ); + v_add( tmp_buffer, output, output, st->L_frame/2 ); + } + + if( st->m_frame_type == ACTIVE_FRAME ) + { + cldfbAnalysis( output, realBuffer, imagBuffer, -1, st->cldfbAna ); + } + else + { + float timeDomainBuffer[L_FRAME16k]; + float A[M+1]; + + mvr2r( st->hFdCngDec->hFdCngCom->timeDomainBuffer, timeDomainBuffer, st->L_frame ); + mvr2r( st->hFdCngDec->hFdCngCom->A_cng, A, M+1 ); + + update_decoder_LPD_cng( st, coder_type, timeDomainBuffer, A, st->p_bpf_noise_buf ); + + /* Generate additional comfort noise to mask potential coding artefacts */ + if( st->flag_cna ) + { + generate_masking_noise( timeDomainBuffer, st->hFdCngDec->hFdCngCom, st->hFdCngDec->hFdCngCom->frameSize, 0 ); + } + else if( st->L_frame == L_FRAME16k && st->last_flag_cna == 1 && ( (st->last_core == ACELP_CORE && st->last_coder_type != AUDIO) || st->last_core == TCX_20_CORE || st->last_core == AMR_WB_CORE ) ) + { + v_multc( st->hFdCngDec->hFdCngCom->olapBufferSynth2+5*st->L_frame/4, 256.f, tmp_buffer, st->L_frame/2 ); + v_add( tmp_buffer, timeDomainBuffer, timeDomainBuffer, st->L_frame/2 ); + } + + /* check if the CLDFB works on the right sample rate */ + if( (st->cldfbAna->no_channels * st->cldfbAna->no_col) != st->L_frame ) + { + resampleCldfb (st->cldfbAna, (st->L_frame * 50)); + resampleCldfb (st->cldfbBPF, (st->L_frame * 50)); + + } + + st->cldfbSyn->bandsToZero = 0; + if( st->bwidth == NB && st->cldfbSyn->no_channels > 10 ) + { + st->cldfbSyn->bandsToZero = st->cldfbSyn->no_channels - 10; + } + else if( st->hFdCngDec->hFdCngCom->regularStopBand < st->cldfbSyn->no_channels ) + { + st->cldfbSyn->bandsToZero = st->cldfbSyn->no_channels - st->hFdCngDec->hFdCngCom->regularStopBand; + } + cldfbAnalysis( timeDomainBuffer, realBuffer, imagBuffer, -1, st->cldfbAna ); + } + + if( st->flag_cna == 0 ) + { + set_f( st->hFdCngDec->hFdCngCom->olapBufferSynth2, 0.f, st->hFdCngDec->hFdCngCom->fftlen ); + } + + if( st->p_bpf_noise_buf ) + { + addBassPostFilter( st->p_bpf_noise_buf, -1, realBuffer, imagBuffer, st->cldfbBPF ); + } + + if (st->output_Fs > 8000) + { + calcGainTemp_TBE( realBuffer, imagBuffer, st->tecDec.loBuffer, 0, + st->cldfbAna->no_col, st->cldfbAna->no_channels, st->tecDec.pGainTemp, st->tec_flag ); + } + + /* set high band buffers to zero. Covering the current frame and the overlap area. */ + if( st->m_frame_type == ACTIVE_FRAME ) + { + for( i = 0; i < CLDFB_NO_COL_MAX; i++ ) + { + set_f( &realBuffer[i][st->cldfbSyn->nab], 0.f, st->cldfbSyn->no_channels - st->cldfbSyn->nab ); + set_f( &imagBuffer[i][st->cldfbSyn->nab], 0.f, st->cldfbSyn->no_channels - st->cldfbSyn->nab ); + } + } + + cldfbSynthesis( realBuffer, imagBuffer, output, -1, st->cldfbSyn ); + + /* set multiplication factor according to the sampling rate */ + delay_comp = NS2SA(st->output_Fs, DELAY_CLDFB_NS); + delay_tdbwe= NS2SA(st->output_Fs, DELAY_BWE_TOTAL_NS- DELAY_CLDFB_NS); + + /* MODE1 MDCT to ACELP 2 transition */ + if( st->last_codec_mode == MODE1 && st->last_core_bfi > ACELP_CORE ) + { + mvr2r( st->delay_buf_out, output, delay_comp ); /* copy the HQ/ACELP delay synchronization buffer at the beginning of ACELP frame */ + + if( st->core == ACELP_CORE ) + { + tmpF = 1.0f/(float)NS2SA(st->output_Fs, 3000000); + if(st->prev_bfi && st->HqVoicing ) + { + mvr2r( st->fer_samples, st->old_out+NS2SA(st->output_Fs, N_ZERO_MDCT_NS), NS2SA(st->output_Fs,3000000) ); + } + for( i=0; ioutput_Fs, 3000000); i++ ) + { + output[i+delay_comp] = (1-tmpF*(float)i)*st->old_out[i+NS2SA(st->output_Fs, N_ZERO_MDCT_NS)] + tmpF*(float)i*output[i+delay_comp]; + } + } + else + { + if( st->output_Fs == 8000 ) + { + mvr2r( st->delay_buf_out, st->FBTCXdelayBuf, delay_comp ); + } + else + { + mvr2r( st->prev_synth_buffer, st->FBTCXdelayBuf, delay_tdbwe ); + mvr2r( st->delay_buf_out, st->FBTCXdelayBuf + delay_tdbwe, delay_comp ); + } + } + } + + /* set delay compensation between HQ synthesis and ACELP synthesis */ + if( st->core == ACELP_CORE && !st->con_tcx ) + { + set_f( st->delay_buf_out, 0, delay_comp ); + mvr2r( output, st->previoussynth, output_frame ); + } + else + { + mvr2r( st->old_synthFB+st->old_synth_lenFB-delay_comp, st->delay_buf_out, delay_comp ); + + if( st->output_Fs == 8000 ) + { + mvr2r( st->FBTCXdelayBuf, st->previoussynth, delay_comp ); + } + else + { + mvr2r( st->FBTCXdelayBuf + delay_tdbwe, st->previoussynth, delay_comp ); + } + + mvr2r( pcmbufFB, st->previoussynth + delay_comp, output_frame - delay_comp ); + } + + /* Delay compensation for TBE */ + if( output_frame >= L_FRAME16k ) + { + mvr2r( output, tmp_buffer, output_frame ); + mvr2r( st->prev_synth_buffer, output, delay_tdbwe ); + mvr2r( tmp_buffer, output + delay_tdbwe, output_frame - delay_tdbwe ); + mvr2r( tmp_buffer + output_frame - delay_tdbwe, st->prev_synth_buffer, delay_tdbwe ); + } + + if( st->igf && st->m_frame_type == ACTIVE_FRAME ) + { + if( !st->bfi && st->core == ACELP_CORE && (st->tec_flag || st->tfa_flag) && (st->output_Fs > 8000) ) + { + procTecTfa_TBE( hb_synth, st->tecDec.pGainTemp, st->tfa_flag, st->last_core, (int)(output_frame / N_TEC_TFA_SUBFR), st->tec_flag == 2 ? 1 : 0 ); + } + + if( (((!st->bfi || st->last_core == ACELP_CORE) && st->core == ACELP_CORE) || + (st->last_core == ACELP_CORE && st->bwidth != NB && st->last_codec_mode == MODE2)) + && (st->output_Fs > 8000) ) + { + /* Add the delayed hb_synth component to the delayed core synthesis */ + v_add( output, hb_synth, output, output_frame ); + } + } + } + + /* set delay */ + if( st->output_Fs == 8000 ) + { + tmps = NS2SA( st->output_Fs, DELAY_CLDFB_NS ); + } + else + { + tmps = NS2SA( st->output_Fs, DELAY_BWE_TOTAL_NS ); + } + delta = NS2SA( st->output_Fs, TCXLTP_DELAY_NS ); + + /* TCX/ACELP/HQ-CORE->TCX */ + if( (st->bfi && st->last_core > ACELP_CORE) || st->core > ACELP_CORE ) + { + /* TCX / HQ-CORE / TD-TCX-PLC -> TCX / TD-TCX-PLC */ + if( st->last_core_bfi > ACELP_CORE || (st->bfi && st->last_core > ACELP_CORE) || (st->prev_bfi && st->last_con_tcx)) + { + mvr2r( st->FBTCXdelayBuf, output, tmps ); + mvr2r( pcmbufFB, output + tmps, st->L_frameTCX - tmps ); + } + /* ACELP -> TCX */ + else + { + /*cross-fading between LB-TCX and FB-TCX over 2.3125ms*/ + for( i = 0; i < tmps; i++ ) + { + output[i+tmps] = (output[i+tmps] * (tmps-i) + pcmbufFB[i] * i) / tmps; + } + mvr2r( pcmbufFB+tmps, output + 2*tmps, st->L_frameTCX - 2*tmps ); + } + + mvr2r( pcmbufFB + st->L_frameTCX - tmps, st->FBTCXdelayBuf, tmps ); + + if( st->bfi && st->last_core > ACELP_CORE ) + { + if( st->output_Fs == 8000 ) + { + mvr2r(st->FBTCXdelayBuf, st->delay_buf_out, NS2SA(st->output_Fs, DELAY_CLDFB_NS)); + } + else + { + mvr2r( st->FBTCXdelayBuf, st->prev_synth_buffer, NS2SA(st->output_Fs, DELAY_BWE_TOTAL_NS - DELAY_CLDFB_NS) ); + mvr2r( st->FBTCXdelayBuf + NS2SA(st->output_Fs, DELAY_BWE_TOTAL_NS - DELAY_CLDFB_NS), st->delay_buf_out, NS2SA(st->output_Fs, DELAY_CLDFB_NS) ); + } + } + } + /* TCX/TD TCX PLC->ACELP */ + else if( st->last_codec_mode == MODE2 && st->last_core > ACELP_CORE ) + { + mvr2r( st->FBTCXdelayBuf, output, delta ); + for( i = delta; i < tmps; i++ ) + { + output[i] = (output[i] * (i-delta) + st->FBTCXdelayBuf[i] * (tmps-i)) / (tmps-delta); + } + } + + tcx_ltp_post( st->tcxltp, st->core, output_frame, st->L_frame, NS2SA( st->output_Fs, ACELP_LOOK_NS ) + tmps, output, + st->FBTCXdelayBuf, delta, st->bfi, st->tcxltp_pitch_int, st->tcxltp_pitch_fr, st->tcxltp_gain, + &st->tcxltp_pitch_int_post_prev, &st->tcxltp_pitch_fr_post_prev, &st->tcxltp_gain_post_prev, &st->tcxltp_filt_idx_prev, + st->pit_res_max, &st->pit_res_max_past, st->damping, st->total_brate >= HQ_96k, st->tcxltp_mem_in, st->tcxltp_mem_out, st->total_brate ); + } /* end of Mode 2 */ + + /*----------------------------------------------------------------* + * Save synthesis for HQ FEC + *----------------------------------------------------------------*/ + + post_hq_delay = NS2SA( st->output_Fs, POST_HQ_DELAY_NS ); + if( st->codec_mode == MODE1 ) + { + mvr2r( st->synth_history+output_frame, st->synth_history, output_frame-post_hq_delay+NS2SA( st->output_Fs, PH_ECU_MEM_NS )); + mvr2r( output, st->old_synthFB+output_frame-post_hq_delay, output_frame ); + /* reset the remaining buffer, which is read in TCX concealment the necessary samples to fill + this buffer are not available for all cases, the impact on the output is limited */ + set_f( st->old_synthFB+2*output_frame-post_hq_delay, 0.f, post_hq_delay ); + + if ( output_frame >= L_FRAME16k ) + { + mvr2r( st->prev_synth_buffer, st->old_synthFB+2*output_frame-NS2SA(st->output_Fs, DELAY_BWE_TOTAL_NS), NS2SA(st->output_Fs, DELAY_BWE_TOTAL_NS - DELAY_CLDFB_NS)); + } + + if (st->core != ACELP_CORE) + { + if ( output_frame >= L_FRAME16k ) + { + mvr2r( synth+output_frame, st->old_synthFB+2*output_frame-NS2SA(st->output_Fs, DELAY_CLDFB_NS), NS2SA(st->output_Fs, DELAY_CLDFB_NS)); + mvr2r( st->old_out+NS2SA(st->output_Fs, N_ZERO_MDCT_NS), st->old_synthFB+2*output_frame, NS2SA(st->output_Fs, PH_ECU_LOOKAHEAD_NS)); + } + else + { + mvr2r( synth+output_frame, st->old_synthFB+2*output_frame-NS2SA(st->output_Fs, DELAY_BWE_TOTAL_NS), NS2SA(st->output_Fs, DELAY_CLDFB_NS)); + mvr2r( st->old_out+NS2SA(st->output_Fs, N_ZERO_MDCT_NS), st->old_synthFB+2*output_frame-NS2SA(st->output_Fs, DELAY_BWE_TOTAL_NS - DELAY_CLDFB_NS), NS2SA(st->output_Fs, PH_ECU_LOOKAHEAD_NS)); + } + } + } + + /*----------------------------------------------------------------* + * HP filtering + *----------------------------------------------------------------*/ + + hp20( output, output_frame, st->mem_hp20_out, st->output_Fs ); + + + /*--------------------------------------------------------* + * Updates + *--------------------------------------------------------*/ + + if( st->last_is_cng == 0 && st->codec_mode == MODE2 ) + { + st->bfi = 0; + if( st->use_partial_copy && st->rf_frame_type >= RF_TCXFD && st->rf_frame_type <= RF_TCXTD2 ) + { + if( frameMode == FRAMEMODE_MISSING ) + { + st->bfi = 1; + } + } + else if( st->m_decodeMode == DEC_CONCEALMENT_EXT ) + { + st->bfi = 1; + } + + updt_dec_common( st, -1, output ); + } + else + { + if( st->codec_mode == MODE2 ) + { + st->bfi = 0; + } + updt_dec_common( st, hq_core_type, output ); + } + + if( st->codec_mode == MODE2 ) + { + if( st->use_partial_copy && st->rf_frame_type == RF_NELP ) + { + st->last_nelp_mode_dec = 1; + } + else + { + st->last_nelp_mode_dec = 0; + } + } + + st->prev_use_partial_copy = st->use_partial_copy; + + st->prev_tilt_code_dec = 0.0f; + for( i=0; iprev_tilt_code_dec += st->tilt_code_dec[i]*0.25f; + } + + if( st->core == HQ_CORE ) + { + st->prev_coder_type = GENERIC; + } + else + { + st->prev_coder_type = coder_type; + } + + if( st->core_brate > SID_2k40 && st->first_CNG == 1 ) + { + if( st->act_cnt >= BUF_DEC_RATE ) + { + st->act_cnt = 0; + } + + st->act_cnt++; + + if( st->act_cnt == BUF_DEC_RATE && st->ho_hist_size > 0 ) + { + st->ho_hist_size--; + } + + if( ++(st->act_cnt2) >= MIN_ACT_CNG_UPD ) + { + st->act_cnt2 = MIN_ACT_CNG_UPD; + } + } + + if( st->core_brate <= SID_2k40 && st->first_CNG == 0 && st->cng_type == LP_CNG ) + { + st->first_CNG = 1; + } + + /* update bandwidth switching parameters */ + if( st->codec_mode == MODE1 ) + { + updt_bw_switching( st, output ); + } + else + { + st->last_bwidth = st->bwidth; + } + + /* synchronisation of CNG seeds */ + if( st->bfi || (st->core_brate != FRAME__NO_DATA && st->core_brate != SID_2k40) ) + { + own_random( &(st->cng_seed) ); + own_random( &(st->cng_ener_seed) ); + } + + if( st->enablePlcWaveadjust && !concealWholeFrameTmp ) + { + /* update the parameters used in waveform adjustment */ + concealment_update2( output, &st->plcInfo, st->L_frameTCX ); + } + + st->last_total_brate_ber = st->total_brate; + if( !st->bfi ) + { + st->last_total_brate = st->total_brate; + } + + st->last_flag_cna = st->flag_cna; + st->hFdCngDec->hFdCngCom->frame_type_previous = st->m_frame_type; + + st->prev_bws_cnt = st->bws_cnt; + + return; +} diff --git a/src/libs/libevs/lib_dec/evs_dec_fx.cpp b/src/libs/libevs/lib_dec/evs_dec_fx.cpp deleted file mode 100755 index d77b7508..00000000 --- a/src/libs/libevs/lib_dec/evs_dec_fx.cpp +++ /dev/null @@ -1,1494 +0,0 @@ -/*==================================================================================== - EVS Codec 3GPP TS26.442 Apr 03, 2018. Version 12.11.0 / 13.6.0 / 14.2.0 - ====================================================================================*/ - -#include "options.h" /* Compilation switches */ -#include "cnst_fx.h" /* Common constants */ -#include "rom_com_fx.h" /* Static table prototypes */ -#include "prot_fx.h" /* Function prototypes */ -#include "basop_util.h" /* Function prototypes */ -#include "stl.h" /* required for wmc_tool */ - -#include /* Debug prototypes */ - -/*--------------------------------------------------------------------------* - * evs_dec() - * - * Principal decoder routine - *--------------------------------------------------------------------------*/ - -void evs_dec_fx( - Decoder_State_fx *st_fx, /* i/o : Decoder state structure */ - Word16 output_sp[], /* o : output synthesis signal */ - frameMode_fx frameMode /* i : Decoder frame mode */ -) -{ - Word16 i, j, output_frame, coder_type; - Word16 sharpFlag; - Word16 tmps, incr; - Word16 core_switching_flag; - Word16 unbits; - Word16 hq_core_type; - Word16 post_hq_delay; - Word32 bwe_exc_extended_fx[L_FRAME32k+NL_BUFF_OFFSET]; - Word16 voice_factors_fx[NB_SUBFR16k]; - Word16 hb_synth_fx[L_FRAME48k]; - Word16 hb_synth_fx_exp; - Word32 L_tmp; - Word16 exp,fra; - Word16 tmp_buffer_fx[L_FRAME48k]; - Word16 tmp16,tmp16_2; - Word16 synth_fx[L_FRAME48k + HQ_DELTA_MAX*HQ_DELAY_COMP]; - Word16 fb_exc_fx[L_FRAME16k]; - Word16 pitch_buf_fx[NB_SUBFR16k]; - Word16 Q_fb_exc; - Word16 old_syn_12k8_16k_fx[L_FRAME16k]; - Word16 sid_bw=-1; - Word16 pcmbufFB[L_FRAME_MAX]; - Word32 workBuffer[128*3]; - Word16 delta; - Word16 nab; - Word16 concealWholeFrame; - Word16 concealWholeFrameTmp = -1; - Word16 delay_comp, delay_tdbwe; - - Word16 Qpostd; - Word16 Q_synth; - Word16 Qpostd_prev; - - Word32 *realBuffer[CLDFB_NO_COL_MAX], *imagBuffer[CLDFB_NO_COL_MAX]; - Word32 realBufferTmp[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX], imagBufferTmp[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX]; - Word16 timeIn_e; - - timeIn_e = 0; - move16(); - - delay_tdbwe = 0; /* for compiler warning*/ - Qpostd = 0; - move16(); /* default and used for MODE2 */ - concealWholeFrame = -1; - move16(); - - /*------------------------------------------------------------------* - * Initialization - *-----------------------------------------------------------------*/ - FOR( i=0; ibfi_fx == 0 ) - { - st_fx->extl_fx = -1; - move16(); - } - - output_frame = st_fx->output_frame_fx; - move16(); - - core_switching_flag = 0; - move16(); - sharpFlag = 0; - move16(); - unbits = 0; - move16(); - - st_fx->use_partial_copy = 0; - move16(); - st_fx->rf_flag = 0; - move16(); - - Qpostd_prev = st_fx->Qprev_synth_buffer_fx; - move16(); - - IF( sub(st_fx->bfi_fx,1) == 0 ) - { - hq_core_type = st_fx->last_hq_core_type_fx; - move16(); - coder_type = st_fx->last_coder_type_fx; - move16(); - } - ELSE - { - hq_core_type = -1; - move16(); - coder_type = INACTIVE; - move16(); - } - - - /* PLC: [TCX: Fade-out-recovery] - * PLC: overlapping part needs to be attenuated for first good frame */ test(); - test(); - test(); - test(); - IF (!st_fx->bfi_fx - && st_fx->prev_bfi_fx - && (sub(st_fx->last_codec_mode, MODE2) == 0) - && (sub(st_fx->last_core_bfi, TCX_20_CORE) == 0 - || sub(st_fx->last_core_bfi, TCX_10_CORE) == 0)) - { - /* v_multc(st_fx->old_out_fx, st_fx->plcInfo.recovery_gain, */ - /* st_fx->old_out_fx, st_fx->L_frameTCX); */ - FOR( i = 0; i < st_fx->L_frameTCX; i++ ) - { - st_fx->old_out_fx[i] = shl(mult_r(st_fx->old_out_fx[i] , st_fx->plcInfo.recovery_gain), 1); - } - FOR( i = 0; i < st_fx->L_frame_fx; i++ ) - { - st_fx->old_out_LB_fx[i] = shl(mult_r(st_fx->old_out_LB_fx[i], st_fx->plcInfo.recovery_gain), 1); - } - /* attenuate PLC buffers, if no aldo window - is used and if no sid or zero frame is received */ - IF ( 0 == st_fx->tcx_cfg.last_aldo ) - { - Word32 f; - Word16 s; - Word16 tmp1; - f = L_deposit_l(st_fx->conceal_eof_gain); /*Q14*/ - s = norm_l(f); - s = sub(16,s); - tmp1 = extract_l(L_shr_r(f,s)); - FOR( i=0; i < st_fx->tcx_cfg.tcx_mdct_window_lengthFB; i++ ) - { - - st_fx->syn_OverlFB[i] = shl(mult(tmp1,st_fx->syn_OverlFB[i]), add(s,1)); - move16(); - - } - s = norm_l(f); - s = sub(16,s); - tmp1 = extract_l(L_shr_r(f,s)); - FOR( i=0; i < st_fx->tcx_cfg.tcx_mdct_window_length; i++ ) - { - st_fx->syn_Overl[i] = shl(mult(tmp1,st_fx->syn_Overl[i]),s); - move16(); - } - } - } - - set16_fx( voice_factors_fx, 0, NB_SUBFR16k ); - set16_fx( hb_synth_fx, 0, output_frame ); - hb_synth_fx_exp = 0; - move16(); - - st_fx->rate_switching_reset = 0; - move16(); - - if(!st_fx->bfi_fx) - { - st_fx->flagGuidedAcelp = 0; - } - - /*----------------------------------------------------------------* - * Updates in case of AMR-WB IO mode -> EVS primary switching - *----------------------------------------------------------------*/ - - IF( sub(st_fx->last_core_fx,AMR_WB_CORE) == 0 ) - { - updt_IO_switch_dec_fx( output_frame, st_fx ); - } - - IF( sub(frameMode,FRAMEMODE_MISSING) != 0 ) /* frame mode normal or future frame */ - { - getPartialCopyInfo(st_fx, &coder_type, &sharpFlag); - - frameMode = (frameMode_fx)st_fx->bfi_fx; - } - - test(); - IF( sub(st_fx->rf_frame_type,RF_NO_DATA) == 0 && sub(st_fx->use_partial_copy,1)==0 ) - { - /* the partial copy is a RF FRAME_NO_DATA frame and should follow the concealment path*/ - st_fx->bfi_fx = 1; - move16(); - st_fx->codec_mode = st_fx->last_codec_mode; - move16(); - frameMode = FRAMEMODE_MISSING; - move16(); - st_fx->use_partial_copy = 0; - move16(); - } - - /* if previous frame was concealed via ACELP, drop TCX partial copy info and continue ACELP concealment */ - test(); - test(); - test(); - IF( sub(st_fx->use_partial_copy,1)==0 && sub(st_fx->core_fx,TCX_20_CORE)==0 && - sub(st_fx->prev_bfi_fx,1)==0 && sub(st_fx->last_core_fx,ACELP_CORE)==0 ) - { - st_fx->bfi_fx = 1; - move16(); - st_fx->codec_mode = st_fx->last_codec_mode; - move16(); - frameMode = FRAMEMODE_MISSING; - move16(); - st_fx->use_partial_copy = 0; - move16(); - st_fx->core_fx = ACELP_CORE; - move16(); - } - - - /*------------------------------------------------------------------* - * Decoding - *-----------------------------------------------------------------*/ - - IF( sub(st_fx->codec_mode,MODE1) == 0 ) - { - /*------------------------------------------------------------------* - * Decision matrix (selection of technologies) - *-----------------------------------------------------------------*/ - - IF ( sub(st_fx->bfi_fx,1) != 0 ) - { - decision_matrix_dec_fx( st_fx, &coder_type, &sharpFlag, &hq_core_type, &core_switching_flag ); - - IF( sub(st_fx->bfi_fx,1) != 0 ) - { - st_fx->sr_core = i_mult(st_fx->L_frame_fx,50); - st_fx->fscale_old = st_fx->fscale; - st_fx->fscale = sr2fscale(st_fx->sr_core); - } - ELSE - { - frameMode = FRAMEMODE_MISSING; - move16(); - } - } - } - - IF( sub(st_fx->codec_mode,MODE1) == 0 ) - { - /*------------------------------------------------------------------* - * Initialization - *-----------------------------------------------------------------*/ - - IF( sub(st_fx->bfi_fx,1) == 0 ) - { - st_fx->nbLostCmpt = add(st_fx->nbLostCmpt,1); - } - ELSE - { - st_fx->nbLostCmpt = 0; - move16(); - } - st_fx->enablePlcWaveadjust = 0; - move16(); - - /*---------------------------------------------------------------------* - * Detect bandwidth switching - *---------------------------------------------------------------------*/ - - bandwidth_switching_detect_fx(st_fx); - - /*---------------------------------------------------------------------* - * Preprocessing (preparing) for ACELP/HQ core switching - *---------------------------------------------------------------------*/ - - core_switching_pre_dec_fx( st_fx, output_frame ); - - /*---------------------------------------------------------------------* - * ACELP core decoding - * HQ core decoding - *---------------------------------------------------------------------*/ - IF ( sub(st_fx->core_fx,ACELP_CORE) == 0 ) - { - /* ACELP core decoder */ - acelp_core_dec_fx( st_fx, synth_fx, bwe_exc_extended_fx, voice_factors_fx, old_syn_12k8_16k_fx, coder_type, sharpFlag, pitch_buf_fx, &unbits, &sid_bw ); - Qpostd = st_fx->Q_syn2; - move16(); - } - ELSE - { - hq_core_dec_fx( st_fx, synth_fx, &Q_synth, output_frame, hq_core_type, core_switching_flag ); - Qpostd = Q_synth; - move16(); - } - - /*---------------------------------------------------------------------* - * Postprocessing for ACELP/HQ core switching - *---------------------------------------------------------------------*/ - - core_switching_post_dec_fx( st_fx, synth_fx, output_frame, core_switching_flag, coder_type, &Qpostd ); - - /*---------------------------------------------------------------------* - * Pre-processing for bandwidth switching - *---------------------------------------------------------------------*/ - - bw_switching_pre_proc_fx( old_syn_12k8_16k_fx, st_fx ); - - /*---------------------------------------------------------------------* - * WB TBE decoding - * WB BWE decoding - *---------------------------------------------------------------------*/ - - IF ( sub(st_fx->extl_fx,WB_TBE) == 0 ) - { - /* WB TBE decoder */ - wb_tbe_dec_fx( st_fx, coder_type, bwe_exc_extended_fx, st_fx->Q_exc, voice_factors_fx, hb_synth_fx, &hb_synth_fx_exp ); - } - ELSE IF ( sub(st_fx->extl_fx,WB_BWE) == 0 && st_fx->bws_cnt_fx == 0) - { - /* WB BWE decoder */ - hb_synth_fx_exp = wb_bwe_dec_fx( synth_fx, hb_synth_fx, output_frame, coder_type, voice_factors_fx, pitch_buf_fx, st_fx, &Qpostd ); - } - - /*---------------------------------------------------------------------* - * SWB TBE decoding - * SWB BWE decoding - * FB TBE decoding - *---------------------------------------------------------------------*/ - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - IF ( sub(st_fx->extl_fx,SWB_TBE) == 0 || sub(st_fx->extl_fx,FB_TBE) == 0 - || (sub(coder_type,AUDIO) != 0 && sub(coder_type,INACTIVE) != 0 && L_sub(st_fx->core_brate_fx,SID_2k40) > 0 && sub(st_fx->core_fx,ACELP_CORE) == 0 - && L_sub(st_fx->output_Fs_fx,32000) >= 0 && sub(st_fx->bwidth_fx,NB) > 0 && st_fx->bws_cnt_fx > 0 && !st_fx->ppp_mode_dec_fx - && !( sub( st_fx->nelp_mode_dec_fx, 1) == 0 && sub( st_fx->bfi_fx, 1) == 0 ) ) ) - - { - swb_tbe_dec_fx( st_fx, coder_type, bwe_exc_extended_fx, st_fx->Q_exc, voice_factors_fx, - old_syn_12k8_16k_fx, fb_exc_fx, &Q_fb_exc, hb_synth_fx, &hb_synth_fx_exp, pitch_buf_fx ); - - /* FB TBE decoder/synthesis */ - test(); - IF ( sub(output_frame,L_FRAME48k) == 0 && sub(st_fx->extl_fx,FB_TBE) == 0 ) - { - fb_tbe_dec_fx( st_fx, fb_exc_fx, Q_fb_exc, hb_synth_fx, hb_synth_fx_exp); - } - } - ELSE IF( sub(st_fx->extl_fx,SWB_BWE) == 0 || sub(st_fx->extl_fx,FB_BWE) == 0 || - (L_sub(st_fx->output_Fs_fx,32000) >= 0 && sub(st_fx->core_fx,ACELP_CORE) == 0 && sub(st_fx->bwidth_fx,NB) > 0 && st_fx->bws_cnt_fx > 0 && !st_fx->ppp_mode_dec_fx - && !( sub( st_fx->nelp_mode_dec_fx, 1) == 0 && sub( st_fx->bfi_fx, 1) == 0 ) ) ) - { - /* SWB BWE decoder */ - hb_synth_fx_exp = swb_bwe_dec_fx( st_fx, synth_fx, hb_synth_fx, output_frame, &Qpostd, coder_type ); - } - ELSE IF( sub(st_fx->extl_fx,SWB_BWE_HIGHRATE) == 0 || sub(st_fx->extl_fx,FB_BWE_HIGHRATE) == 0 ) - { - hb_synth_fx_exp = swb_bwe_dec_hr_fx( st_fx, old_syn_12k8_16k_fx, Qpostd, hb_synth_fx, output_frame, unbits, pitch_buf_fx ); - } - - /*---------------------------------------------------------------------* - * FEC - recovery after lost HQ core (smoothing of the BWE component) - *---------------------------------------------------------------------*/ - - test(); - test(); - IF ( st_fx->prev_bfi_fx && sub(st_fx->last_core_fx,HQ_CORE) == 0 && sub(st_fx->extl_fx,-1) != 0 ) - { - /*tmp = FRAC_BWE_SMOOTH/output_frame;*/ - tmp16 = shr(410,shr(output_frame,8)); - if(sub(output_frame, L_FRAME48k)==0) - { - tmp16 = 68; - move16(); - } - /*output_frame/FRAC_BWE_SMOOTH*/ - j = shr(output_frame,1); - tmp16_2 = 0; - move16(); - FOR (i = 0; i < j; i++) - { - /*hb_synth[i] *= (i*tmp);*/ - hb_synth_fx[i] = mult_r(hb_synth_fx[i], tmp16_2); - move16(); - tmp16_2 = add(tmp16_2, tmp16); - } - } - - /*---------------------------------------------------------------------* - * SWB CNG - *---------------------------------------------------------------------*/ - IF( sub(output_frame,L_FRAME32k) >= 0 ) - { - /* SHB CNG decoder */ - swb_CNG_dec_fx( st_fx, synth_fx, hb_synth_fx, sid_bw, Qpostd ); - - test(); - if( L_sub(st_fx->core_brate_fx, SID_2k40) <= 0 && st_fx->bws_cnt_fx == 0 ) - { - hb_synth_fx_exp = 3; - move16(); - } - } - - /*----------------------------------------------------------------* - * Delay ACELP core synthesis to be synchronized with the components of bandwidth extension layers - *----------------------------------------------------------------*/ - - IF ( sub(output_frame,L_FRAME16k) >= 0 ) - { - tmps = NS2SA_fx2(st_fx->output_Fs_fx, DELAY_BWE_TOTAL_NS - DELAY_CLDFB_NS); - - exp=s_min(Qpostd, st_fx->Qprev_synth_buffer_fx); - Scale_sig(synth_fx, output_frame, sub(exp,Qpostd)); - Qpostd=exp; - move16(); - Scale_sig(st_fx->prev_synth_buffer_fx, tmps, sub(exp, st_fx->Qprev_synth_buffer_fx)); - st_fx->Qprev_synth_buffer_fx=exp; - move16(); - Copy(synth_fx, tmp_buffer_fx, output_frame); - Copy(st_fx->prev_synth_buffer_fx, synth_fx, tmps); - Copy(tmp_buffer_fx, synth_fx + tmps, output_frame - tmps); - Copy(tmp_buffer_fx + output_frame - tmps, st_fx->prev_synth_buffer_fx, tmps); - } - ELSE - { - exp=s_min(Qpostd, st_fx->Qprev_synth_buffer_fx); - Scale_sig(synth_fx, output_frame, sub(exp,Qpostd)); - Qpostd=exp; - move16(); - st_fx->Qprev_synth_buffer_fx=exp; - move16(); - } - - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - IF (sub(st_fx->core_fx,ACELP_CORE) == 0 - && !st_fx->bfi_fx - && st_fx->prev_bfi_fx - && L_sub(st_fx->last_total_brate_fx, HQ_48k) >= 0 - && sub(st_fx->last_codec_mode, MODE2) == 0 - && (sub(st_fx->last_core_bfi, TCX_20_CORE) == 0 || sub(st_fx->last_core_bfi, TCX_10_CORE) == 0) - && st_fx->plcInfo.concealment_method == TCX_NONTONAL - && L_sub(st_fx->plcInfo.nbLostCmpt, 4) < 0 ) - { - tmps = 0; - IF( sub(output_frame,L_FRAME16k) >= 0 ) - { - tmps = NS2SA_fx2(st_fx->output_Fs_fx, DELAY_BWE_TOTAL_NS); - } - - waveform_adj2_fix(st_fx->tonalMDCTconceal.secondLastPcmOut, - synth_fx+tmps, - st_fx->plcInfo.data_noise, - &st_fx->plcInfo.outx_new_n1_fx, - &st_fx->plcInfo.nsapp_gain_fx, - &st_fx->plcInfo.nsapp_gain_n_fx, - &st_fx->plcInfo.recovery_gain, - st_fx->plcInfo.step_concealgain_fx, - st_fx->plcInfo.Pitch_fx, - st_fx->plcInfo.FrameSize, - tmps, - add(extract_l(st_fx->plcInfo.nbLostCmpt), 1), - st_fx->bfi_fx); - st_fx->plcInfo.Pitch_fx = 0; - } - - /*----------------------------------------------------------------* - * Addition of BWE components to the ACELP core synthesis - *----------------------------------------------------------------*/ - - test(); - test(); - IF ( sub(st_fx->extl_fx,-1) != 0 || (st_fx->bws_cnt_fx > 0 && sub(st_fx->core_fx,ACELP_CORE) == 0) ) - { - /* Calculate an additional delay of extension layer components to be synchronized with ACELP synthesis */ - IF ( sub(st_fx->L_frame_fx,L_FRAME) == 0 ) - { - /* TBE on top of ACELP@12.8kHz */ - tmps = NS2SA_fx2( st_fx->output_Fs_fx, MAX_DELAY_TBE_NS - DELAY_SWB_TBE_12k8_NS ); - } - ELSE - { - test(); - IF( sub(st_fx->extl_fx,SWB_BWE_HIGHRATE) == 0 || sub(st_fx->extl_fx,FB_BWE_HIGHRATE) == 0 ) - { - /* HR SWB BWE on top of ACELP@16kHz */ - tmps = NS2SA_fx2( st_fx->output_Fs_fx, DELAY_BWE_TOTAL_NS ); - } - ELSE - { - /* TBE on top of ACELP@16kHz */ - tmps = NS2SA_fx2( st_fx->output_Fs_fx, MAX_DELAY_TBE_NS - DELAY_SWB_TBE_16k_NS ); - } - } - - /* Smooth transitions when switching between different technologies */ - test(); - test(); - test(); - test(); - IF ( (sub(st_fx->extl_fx,st_fx->last_extl_fx) != 0 || (sub(st_fx->extl_fx,st_fx->last_extl_fx) == 0 && sub((st_fx->core_fx ^ st_fx->last_core_fx),HQ_CORE) == 0)) - && !(sub(st_fx->extl_fx,SWB_CNG) == 0 && sub(st_fx->last_extl_fx,SWB_TBE) == 0) ) - { - /*incr = (short) ( L_FRAME / (tmps + 0.5f) );*/ - incr = idiv1616(L_FRAME*2, add(shl(tmps,1),1)); - tmp16 = 0; - move16(); - FOR (i=0; ihb_prev_synth_buffer_fx, 0, tmps ); - } - ELSE IF ( sub(tmps,st_fx->old_bwe_delay_fx) < 0 ) - { - /* the previous frame was TBE on top of ACELP@16kHz and the current frame is TBE on top of ACELP@12.8kHz */ - /*incr = (short) ( L_FRAME / (tmps + 0.5f) );*/ - incr = idiv1616(L_FRAME*2, add(shl(tmps,1),1)); - tmp16 = 0; - move16(); - FOR (i=0; ihb_prev_synth_buffer_fx[i], sin_table256_fx[255 - tmp16]), - st_fx->hb_prev_synth_buffer_fx[st_fx->old_bwe_delay_fx - 1 - i], sin_table256_fx[tmp16])); - tmp16 = add(tmp16, incr); - } - Copy(tmp_buffer_fx, st_fx->hb_prev_synth_buffer_fx, tmps); - } - ELSE IF (sub(tmps,st_fx->old_bwe_delay_fx) > 0) - { - /* the previous frame was TBE on top of ACELP@12.8kHz and the current frame is TBE on top of ACELP@16kHz */ - /*incr = (short)( L_FRAME / (st->old_bwe_delay + 0.5f) );*/ - incr = idiv1616(L_FRAME*2, add(shl(st_fx->old_bwe_delay_fx,1),1)); - tmp16 = 0; - move16(); - FOR (i=0; iold_bwe_delay_fx; i++) - { - tmp_buffer_fx[i] = mult_r(st_fx->hb_prev_synth_buffer_fx[i], sin_table256_fx[255 - tmp16]); - move16(); - tmp16 = add(tmp16, incr); - - } - FOR (; iold_bwe_delay_fx; i++) - { - /*tmp_buffer[tmps - 1 - i] += st->hb_prev_synth_buffer[st->old_bwe_delay - 1 - i] * sin_table256[i * incr];*/ - tmp_buffer_fx[tmps - 1 - i] = round_fx(L_mac(L_mult(tmp_buffer_fx[tmps - 1 - i], 32767), st_fx->hb_prev_synth_buffer_fx[st_fx->old_bwe_delay_fx - 1 - i], sin_table256_fx[tmp16/*i * incr*/])); - tmp16 = add(tmp16, incr); - } - - Copy( tmp_buffer_fx, st_fx->hb_prev_synth_buffer_fx, tmps ); - } - /* Delay hb_synth */ - tmp16 = sub(hb_synth_fx_exp, st_fx->prev_hb_synth_fx_exp); - IF ( tmp16 != 0 ) - { - Scale_sig(st_fx->hb_prev_synth_buffer_fx, tmps, tmp16 ); - } - Copy( hb_synth_fx, tmp_buffer_fx, output_frame ); - Copy( st_fx->hb_prev_synth_buffer_fx, hb_synth_fx, tmps ); - Copy( tmp_buffer_fx, hb_synth_fx + tmps, output_frame - tmps ); - Copy( tmp_buffer_fx + output_frame - tmps, st_fx->hb_prev_synth_buffer_fx, tmps ); - - st_fx->old_bwe_delay_fx = tmps; - move16(); - - test(); - test(); - test(); - test(); - test(); - test(); - IF( ( st_fx->ppp_mode_dec_fx || (sub(st_fx->nelp_mode_dec_fx,1) == 0 && sub( st_fx->bfi_fx, 1 ) == 0 ) ) && sub(st_fx->L_frame_fx, st_fx->last_L_frame_fx) == 0 && (st_fx->bws_cnt_fx > 1 || st_fx->last_extl_fx != -1) ) - - { - Copy( st_fx->old_hb_synth_fx, hb_synth_fx, output_frame ); - IF(sub(st_fx->prev_hb_synth_fx_exp, 14) < 0) - { - hb_synth_fx_exp = add(st_fx->prev_hb_synth_fx_exp, 1); - } - ELSE - { - hb_synth_fx_exp = 14; - } - } - ELSE - { - Copy( hb_synth_fx, st_fx->old_hb_synth_fx, output_frame ); - } - - add_vec_fx( synth_fx, Qpostd, hb_synth_fx, hb_synth_fx_exp, synth_fx, Qpostd, output_frame ); - - /* SWB CNG/DTX - calculate SHB energy */ - test(); - IF ( sub(output_frame, L_FRAME32k) >= 0 && sub(st_fx->extl_fx, SWB_CNG) > 0 ) - { - SWITCH (output_frame) - { - case L_FRAME8k: - tmp16 = 205; - BREAK; /*Q15*/ - case L_FRAME16k: - tmp16 = 102; - BREAK; /*Q15*/ - case L_FRAME32k: - tmp16 = 51; - BREAK; /*Q15*/ - case L_FRAME48k: - tmp16 = 34; - BREAK; /*Q15*/ - } - - L_tmp = L_deposit_l(1); /*Q2*hb_synth_fx_exp*/ - FOR ( i=0; ilast_shb_ener_fx = round_fx(L_shl(L_tmp, 10)); /*Q8*/ - } - } - st_fx->prev_hb_synth_fx_exp = hb_synth_fx_exp; - move16(); - - /* TCX-LTP Postfilter: used in MODE1 to update memories and to avoid discontinuities when the past frame was TCX */ - delta = NS2SA_fx2( st_fx->output_Fs_fx, TCXLTP_DELAY_NS ); - Scale_sig(st_fx->tcxltp_mem_in, delta, sub(Qpostd, Qpostd_prev)); - Scale_sig(st_fx->tcxltp_mem_out, output_frame, sub(Qpostd, Qpostd_prev)); - tcx_ltp_post( st_fx->tcxltp, ACELP_CORE, output_frame, st_fx->L_frame_past, 0, synth_fx, NULL, - delta, 0, 0, 0, 0, &st_fx->tcxltp_pitch_int_post_prev, - &st_fx->tcxltp_pitch_fr_post_prev, &st_fx->tcxltp_gain_post_prev, - &st_fx->tcxltp_filt_idx_prev, st_fx->pit_res_max, - &st_fx->pit_res_max_past, - 0, 0, st_fx->tcxltp_mem_in, - st_fx->tcxltp_mem_out, st_fx->total_brate_fx ); - - - /* final output of synthesis signal */ - Copy( synth_fx, output_sp, output_frame ); - - - } - ELSE /* MODE2 PART */ - { - - /* -------------------------------------------------------------- */ - /* CONCEALMENT */ - /* -------------------------------------------------------------- */ - - concealWholeFrame = 0; - move16(); - - if( sub(frameMode, FRAMEMODE_NORMAL) == 0 ) - { - st_fx->m_decodeMode = DEC_NO_FRAM_LOSS; - move16(); - } - - IF( sub(frameMode, FRAMEMODE_MISSING) == 0 ) - { - test(); - test(); - IF( st_fx->use_partial_copy && sub(st_fx->rf_frame_type, RF_TCXFD) >= 0 && sub(st_fx->rf_frame_type, RF_TCXTD2) <= 0) - { - st_fx->m_decodeMode = DEC_NO_FRAM_LOSS; - move16(); - } - ELSE - { - st_fx->m_decodeMode = DEC_CONCEALMENT_EXT; - move16(); - } - } - - SWITCH( st_fx->m_decodeMode ) - { - case DEC_NO_FRAM_LOSS: - BREAK; - case DEC_CONCEALMENT_EXT: - concealWholeFrame = 1; - move16(); - BREAK; - } - - - /* -------------------------------------------------------------- */ - /* DECODE CORE */ - /* -------------------------------------------------------------- */ - - dec_acelp_tcx_frame( st_fx, &coder_type, &concealWholeFrame, output_sp, - st_fx->p_bpf_noise_buf, pcmbufFB, bwe_exc_extended_fx, voice_factors_fx, pitch_buf_fx ); - - concealWholeFrameTmp = concealWholeFrame; - move16(); - if(st_fx->bfi_fx) - { - frameMode = FRAMEMODE_MISSING; - move16(); - } - IF( st_fx->igf ) - { - - /* TBE interface */ - test(); - test(); - IF( (st_fx->bfi_fx == 0 || st_fx->last_core_fx == ACELP_CORE) && st_fx->core_fx == ACELP_CORE ) - { - test(); - test(), test(); - SWITCH (st_fx->bwidth_fx) - { - case WB: - st_fx->extl_fx = WB_TBE; - move16(); - st_fx->extl_brate_fx = WB_TBE_0k35; - move32(); - BREAK; - - case SWB: - st_fx->extl_fx = SWB_TBE; - move16(); - st_fx->extl_brate_fx = SWB_TBE_1k6; - move32(); - BREAK; - - case FB: - st_fx->extl_fx = FB_TBE; - move16(); - st_fx->extl_brate_fx = FB_TBE_1k8; - move32(); - BREAK; - } - } - ELSE - { - st_fx->extl_fx = IGF_BWE; - move16(); - st_fx->extl_brate_fx = L_deposit_l(0); - } - - test(); - test(); - if( L_sub(st_fx->output_Fs_fx,8000) == 0 || ( L_sub(st_fx->output_Fs_fx,16000) == 0 && sub(st_fx->L_frame_fx,L_FRAME16k) == 0 ) ) - { - st_fx->extl_fx = -1; - move16(); - } - - st_fx->core_brate_fx = L_sub(st_fx->total_brate_fx, st_fx->extl_brate_fx); - - st_fx->bws_cnt_fx = 0; - move16(); - st_fx->bws_cnt1_fx = 0; - move16(); - st_fx->tilt_wb_fx = 0; - move16(); - - IF( sub(st_fx->m_frame_type, ACTIVE_FRAME) == 0 ) - { - test(); - test(); - IF( ( st_fx->bfi_fx == 0 || st_fx->last_core_fx == ACELP_CORE ) && st_fx->core_fx == ACELP_CORE ) - { - test(); - IF( sub(st_fx->extl_fx, WB_TBE) == 0 ) - { - wb_tbe_dec_fx( st_fx, coder_type, bwe_exc_extended_fx, st_fx->Q_exc, voice_factors_fx, hb_synth_fx, &hb_synth_fx_exp ); - } - ELSE IF( sub(st_fx->extl_fx, SWB_TBE) == 0 || sub(st_fx->extl_fx, FB_TBE) == 0 ) - { - /* SWB TBE decoder */ - swb_tbe_dec_fx( st_fx, coder_type, bwe_exc_extended_fx, st_fx->Q_exc, voice_factors_fx, st_fx->old_core_synth_fx, - fb_exc_fx, &Q_fb_exc, hb_synth_fx, &hb_synth_fx_exp, pitch_buf_fx ); - - test(); - IF( sub(st_fx->extl_fx, FB_TBE) == 0 && sub(output_frame, L_FRAME48k) == 0 ) - { - fb_tbe_dec_fx( st_fx, fb_exc_fx, Q_fb_exc, hb_synth_fx, hb_synth_fx_exp ); - } - } - Copy( hb_synth_fx, st_fx->old_hb_synth_fx, output_frame ); - } - ELSE - { - IF( sub(st_fx->last_core_fx,ACELP_CORE) == 0 ) - { - test(); - test(); - test(); - test(); - IF( ( sub(st_fx->bwidth_fx, SWB) == 0 || sub(st_fx->bwidth_fx, FB) == 0 ) && - (( sub(st_fx->last_extl_fx, SWB_TBE) == 0 || sub(st_fx->last_extl_fx, FB_TBE) == 0) && sub(st_fx->last_codec_mode, MODE2) == 0 ) ) - { - GenTransition_fx( st_fx->syn_overlap_fx, st_fx->old_tbe_synth_fx, 2*NS2SA(st_fx->output_Fs_fx, DELAY_BWE_TOTAL_NS), hb_synth_fx, - st_fx->genSHBsynth_Hilbert_Mem_fx, st_fx->genSHBsynth_state_lsyn_filt_shb_local_fx, &(st_fx->syn_dm_phase_fx), - st_fx->output_Fs_fx, st_fx->int_3_over_2_tbemem_dec_fx, st_fx->rf_flag, st_fx->total_brate_fx ); - - hb_synth_fx_exp = st_fx->prev_Q_bwe_syn2; - move16(); - } - ELSE IF ( st_fx->bwidth_fx == WB && st_fx->last_extl_fx == WB_TBE ) - { - GenTransition_WB_fx( st_fx->syn_overlap_fx, st_fx->old_tbe_synth_fx, st_fx->prev_Qx, 2*NS2SA(st_fx->output_Fs_fx, DELAY_BWE_TOTAL_NS), hb_synth_fx, - st_fx->state_lsyn_filt_shb_fx, st_fx->state_lsyn_filt_dwn_shb_fx, st_fx->output_Fs_fx, st_fx->mem_resamp_HB_fx ); - - hb_synth_fx_exp = st_fx->prev_Qx; - move16(); - } - - TBEreset_dec_fx( st_fx, st_fx->bwidth_fx ); - } - ELSE IF ( sub(st_fx->last_codec_mode,MODE1)==0) - { - swb_tbe_reset_fx( st_fx->mem_csfilt_fx, st_fx->mem_genSHBexc_filt_down_shb_fx, st_fx->state_lpc_syn_fx, - st_fx->syn_overlap_fx, st_fx->state_syn_shbexc_fx, &(st_fx->tbe_demph_fx), &(st_fx->tbe_premph_fx), st_fx->mem_stp_swb_fx, &(st_fx->gain_prec_swb_fx) ); - IF( sub(st_fx->extl_fx, FB_TBE) == 0 ) - { - set16_fx( st_fx->fb_state_lpc_syn_fx, 0, LPC_SHB_ORDER ); - st_fx->fb_tbe_demph_fx = 0; - fb_tbe_reset_synth_fx( st_fx->fbbwe_hpf_mem_fx, st_fx->fbbwe_hpf_mem_fx_Q,&st_fx->prev_fbbwe_ratio_fx ); - } - swb_tbe_reset_synth_fx( st_fx->genSHBsynth_Hilbert_Mem_fx, st_fx->genSHBsynth_state_lsyn_filt_shb_local_fx ); - } - } - } - } - - IF( sub(st_fx->m_frame_type,ACTIVE_FRAME) != 0 ) - { - st_fx->extl_fx = -1; - move16(); - st_fx->extl_brate_fx = L_deposit_l(0); - } - - /* -------------------------------------------------------------- */ - /* APPLY POSTPROC */ - /* -------------------------------------------------------------- */ - - { - nab = s_min( st_fx->cldfbAna_fx->no_channels, st_fx->cldfbSyn_fx->no_channels ); - st_fx->cldfbSyn_fx->lsb = s_min(st_fx->cldfbAna_fx->no_channels, st_fx->cldfbSyn_fx->no_channels); - move16(); - st_fx->cldfbSyn_fx->usb = st_fx->cldfbSyn_fx->no_channels; - move16(); - st_fx->cldfbAna_fx->lsb = st_fx->cldfbAna_fx->no_channels; - move16(); - st_fx->cldfbAna_fx->usb = st_fx->cldfbAna_fx->no_channels; - move16(); - - test(); - test(); - test(); - test(); - IF ( st_fx->hFdCngDec_fx != NULL && (L_sub(st_fx->sr_core,8000) == 0 || L_sub(st_fx->sr_core,12800) == 0 || L_sub(st_fx->sr_core,16000) == 0) && L_sub(st_fx->total_brate_fx,ACELP_32k) <= 0 ) - { - /*************************************** - In CLDFB domain: - - perform noise estimation during active frames - - do CNG during inactive frames - ****************************************/ - HANDLE_FD_CNG_DEC hFdCngDec = st_fx->hFdCngDec_fx; - move16(); - - noisy_speech_detection( st_fx->VAD && st_fx->m_frame_type==ACTIVE_FRAME, output_sp, st_fx->L_frame_fx, 0, hFdCngDec->msNoiseEst, hFdCngDec->msNoiseEst_exp, - hFdCngDec->psize_shaping_norm, hFdCngDec->psize_shaping_norm_exp, hFdCngDec->nFFTpart_shaping, - &(hFdCngDec->lp_noise), &(hFdCngDec->lp_speech), &(hFdCngDec->hFdCngCom->flag_noisy_speech) ); - - hFdCngDec->hFdCngCom->likelihood_noisy_speech = mult_r(hFdCngDec->hFdCngCom->likelihood_noisy_speech, 32440/*0.99 Q15*/); - IF ( hFdCngDec->hFdCngCom->flag_noisy_speech != 0 ) - { - hFdCngDec->hFdCngCom->likelihood_noisy_speech = add(hFdCngDec->hFdCngCom->likelihood_noisy_speech, 328/*0.01 Q15*/); - move16(); - } - st_fx->lp_noise = hFdCngDec->lp_noise; - move32(); - ApplyFdCng( output_sp, 0, realBuffer, imagBuffer, &st_fx->scaleFactor.hb_scale, hFdCngDec, st_fx->m_frame_type, st_fx, concealWholeFrame, 0); - - /* Generate additional comfort noise to mask potential coding artefacts */ - test(); - IF( sub(st_fx->m_frame_type,ACTIVE_FRAME) == 0 && st_fx->flag_cna ) - { - generate_masking_noise( output_sp, 0, hFdCngDec->hFdCngCom, hFdCngDec->hFdCngCom->frameSize, 0 ); - } - - } - - test(); - test(); - test(); - test(); - test(); - test(); - IF( st_fx->flag_cna == 0 && sub(st_fx->L_frame_fx,L_FRAME16k) == 0 && sub(st_fx->last_flag_cna,1) == 0 - && ( (st_fx->last_core_fx == ACELP_CORE && sub(st_fx->last_coder_type_fx,AUDIO) != 0) || sub(st_fx->last_core_fx,TCX_20_CORE) == 0 || sub(st_fx->last_core_fx,AMR_WB_CORE) == 0 ) ) - { - FOR (i=0; i < st_fx->L_frame_fx/2; i++) - { - output_sp[i] = add( output_sp[i], st_fx->hFdCngDec_fx->hFdCngCom->olapBufferSynth2[i+5*st_fx->L_frame_fx/4] ); - move16(); - } - } - - IF( sub(st_fx->m_frame_type,ACTIVE_FRAME) == 0 ) - { - timeIn_e = s_max(0, sub(getScaleFactor16( output_sp, st_fx->L_frame_fx ), 3)); - IF( sub(st_fx->core_fx,ACELP_CORE) != 0 ) - { - timeIn_e = s_max(0, s_min(sub(getScaleFactor16( pcmbufFB, st_fx->L_frameTCX ), 3),timeIn_e)); - } - Scale_sig( output_sp, st_fx->L_frame_fx, timeIn_e ); - timeIn_e = negate( timeIn_e ); - cldfbAnalysisFiltering( st_fx->cldfbAna_fx, realBuffer, imagBuffer, &st_fx->scaleFactor, output_sp, timeIn_e, CLDFB_NO_COL_MAX, workBuffer ); - st_fx->scaleFactor.hb_scale = st_fx->scaleFactor.lb_scale; - move16(); - } - ELSE - { - Word16 timeDomainBuffer[L_FRAME16k]; - Word16 A[M+1]; - - Copy( st_fx->hFdCngDec_fx->hFdCngCom->timeDomainBuffer, timeDomainBuffer, st_fx->L_frame_fx ); - Copy( st_fx->hFdCngDec_fx->hFdCngCom->A_cng, A, M+1 ); - - update_decoder_LPD_cng( st_fx, coder_type, timeDomainBuffer, A, st_fx->p_bpf_noise_buf ); - - /* Generate additional comfort noise to mask potential coding artefacts */ - IF( st_fx->flag_cna ) - { - generate_masking_noise( timeDomainBuffer, 0, st_fx->hFdCngDec_fx->hFdCngCom, st_fx->hFdCngDec_fx->hFdCngCom->frameSize, 0 ); - } - ELSE IF( sub(st_fx->L_frame_fx,L_FRAME16k) == 0 && sub(st_fx->last_flag_cna,1) == 0 && ( (sub(st_fx->last_core_fx,ACELP_CORE) == 0 && sub(st_fx->last_coder_type_fx,AUDIO) != 0 ) || sub(st_fx->last_core_fx,TCX_20_CORE) == 0 || sub(st_fx->last_core_fx,AMR_WB_CORE) == 0) ) - { - FOR( i=0; i < st_fx->L_frame_fx/2; i++ ) - { - timeDomainBuffer[i] = add( timeDomainBuffer[i], st_fx->hFdCngDec_fx->hFdCngCom->olapBufferSynth2[i+5*st_fx->L_frame_fx/4] ); - move16(); - } - } - /* check if the CLDFB works on the right sample rate */ - IF( sub((st_fx->cldfbAna_fx->no_channels * st_fx->cldfbAna_fx->no_col),st_fx->L_frame_fx) != 0 ) - { - Word16 newCldfbBands = CLDFB_getNumChannels(L_mult0(st_fx->L_frame_fx, 50)); - - resampleCldfb( st_fx->cldfbAna_fx, newCldfbBands, st_fx->L_frame_fx, 0 ); - resampleCldfb( st_fx->cldfbBPF_fx, newCldfbBands, st_fx->L_frame_fx, 0 ); - } - - st_fx->cldfbSyn_fx->bandsToZero = 0; - move16(); - test(); - IF ( sub( st_fx->bwidth_fx, NB ) == 0 && sub( st_fx->cldfbSyn_fx->no_channels, 10 ) > 0 ) - { - st_fx->cldfbSyn_fx->bandsToZero = sub( st_fx->cldfbSyn_fx->no_channels, 10 ); - } - ELSE IF ( st_fx->hFdCngDec_fx->hFdCngCom->regularStopBand < st_fx->cldfbSyn_fx->no_channels ) - { - st_fx->cldfbSyn_fx->bandsToZero = st_fx->cldfbSyn_fx->no_channels - st_fx->hFdCngDec_fx->hFdCngCom->regularStopBand; - } - - timeIn_e = 2; - move16(); - Scale_sig(timeDomainBuffer, st_fx->L_frame_fx, timeIn_e); - IF ( st_fx->p_bpf_noise_buf ) - { - Scale_sig(st_fx->p_bpf_noise_buf, st_fx->L_frame_fx, timeIn_e); - } - - timeIn_e = negate(timeIn_e); - cldfbAnalysisFiltering( st_fx->cldfbAna_fx, realBuffer, imagBuffer, &st_fx->scaleFactor, timeDomainBuffer, timeIn_e, CLDFB_NO_COL_MAX, workBuffer) ; - } - - if( st_fx->flag_cna == 0 ) - { - set16_fx( st_fx->hFdCngDec_fx->hFdCngCom->olapBufferSynth2, 0, st_fx->hFdCngDec_fx->hFdCngCom->fftlen ); - } - - IF( st_fx->p_bpf_noise_buf ) - { - Word16 timeInBpf_e = timeIn_e; - move16(); - if( sub(st_fx->m_frame_type,ACTIVE_FRAME) == 0 ) - { - timeInBpf_e = 0; - move16(); - } - - addBassPostFilterFx( st_fx->p_bpf_noise_buf, realBuffer, imagBuffer, st_fx->cldfbBPF_fx, workBuffer, - timeInBpf_e, CLDFB_NO_COL_MAX, st_fx->cldfbAna_fx->no_col, st_fx->cldfbAna_fx->no_channels, &st_fx->scaleFactor ); - - IF( sub(st_fx->m_frame_type,ACTIVE_FRAME) != 0 ) - { - Scale_sig(st_fx->p_bpf_noise_buf, st_fx->L_frame_fx, timeIn_e); - } - - } - - IF (L_sub(st_fx->output_Fs_fx, 8000) > 0) - { - st_fx->tecDec_fx.cldfbExp = add(15, st_fx->scaleFactor.lb_scale); - - calcGainTemp_TBE_Fx( realBuffer, imagBuffer, st_fx->tecDec_fx.cldfbExp, st_fx->tecDec_fx.loBuffer, - 0, /*startPos,*//*!< Start position of the current envelope. */ - st_fx->cldfbAna_fx->no_col, /*stopPos,*/ /*!< Stop position of the current envelope. */ - st_fx->cldfbAna_fx->no_channels, /*lowSubband*/ - st_fx->tecDec_fx.pGainTemp_m, st_fx->tecDec_fx.pGainTemp_e, st_fx->tec_flag - ); - } - - /* set high band buffers to zero. Covering the current frame and the overlap area. */ - IF( sub(st_fx->m_frame_type,ACTIVE_FRAME) == 0 ) - { - FOR( i = 0; i < 16; i++ ) - { - set32_fx( &realBuffer[i][nab], 0, sub(st_fx->cldfbSyn_fx->no_channels,nab) ); - set32_fx( &imagBuffer[i][nab], 0, sub(st_fx->cldfbSyn_fx->no_channels,nab) ); - } - } - - timeIn_e = s_min(0, add(timeIn_e, 2)); - cldfbSynthesisFiltering(st_fx->cldfbSyn_fx, realBuffer, imagBuffer, &st_fx->scaleFactor, output_sp, timeIn_e, CLDFB_NO_COL_MAX, workBuffer ); - /*CLDFB output always in timeIn_e*/ - - /* MODE1 MDCT to ACELP 2 transition */ - delay_comp = NS2SA_fx2(st_fx->output_Fs_fx, DELAY_CLDFB_NS); - Scale_sig(st_fx->delay_buf_out_fx, delay_comp, negate(st_fx->Q_old_postdec)); - st_fx->Q_old_postdec = 0; - move16(); - delay_tdbwe= NS2SA_fx2(st_fx->output_Fs_fx, DELAY_BWE_TOTAL_NS- DELAY_CLDFB_NS); - IF( sub(output_frame,L_FRAME16k) >= 0 ) - { - Scale_sig(st_fx->prev_synth_buffer_fx, delay_tdbwe, sub(Qpostd, st_fx->Qprev_synth_buffer_fx)); - } - - test(); - IF( sub(st_fx->last_codec_mode,MODE1) == 0 && sub(st_fx->last_core_bfi,ACELP_CORE) > 0 ) - { - Copy_Scale_sig( st_fx->delay_buf_out_fx, output_sp, delay_comp, negate(timeIn_e) ); /* copy the HQ/ACELP delay synchronization buffer at the beginning of ACELP frame */ - IF( sub(st_fx->core_fx,ACELP_CORE) == 0 ) - { - Word16 step, alpha, nz; - - i = 15; - move16(); - tmps = NS2SA_fx2(st_fx->output_Fs_fx, 3000000L); - nz = NS2SA_fx2(st_fx->output_Fs_fx, N_ZERO_MDCT_NS); - step = Inv16(tmps, &i); - step = shl(step, i); - alpha = 0; - move16(); - - test(); - IF( st_fx->prev_bfi_fx && st_fx->HqVoicing_fx ) - { - Copy( st_fx->fer_samples_fx, &st_fx->old_out_fx[nz], tmps); - } - ELSE - { - Scale_sig(st_fx->old_out_fx, nz+tmps, negate(st_fx->Q_old_wtda)); - } - st_fx->Q_old_wtda = 0; - move16(); - - FOR (i = 0; i < tmps; i++) - { - output_sp[i+delay_comp] = msu_r(L_mult(output_sp[i+delay_comp], alpha), shr(st_fx->old_out_fx[i+nz], timeIn_e), add(alpha, -32768)); - move16(); - alpha = add(alpha, step); - } - } - ELSE - { - IF( L_sub(st_fx->output_Fs_fx,8000) == 0 ) - { - Copy(st_fx->delay_buf_out_fx, st_fx->FBTCXdelayBuf, delay_comp); - } - ELSE - { - Copy( st_fx->prev_synth_buffer_fx, st_fx->FBTCXdelayBuf, delay_tdbwe ); - Copy( st_fx->delay_buf_out_fx, st_fx->FBTCXdelayBuf + delay_tdbwe, delay_comp ); - } - } - } - - /* set delay compensation between HQ synthesis and ACELP synthesis */ - test(); - IF( sub(st_fx->core_fx,ACELP_CORE) == 0 && !(st_fx->con_tcx) ) - { - set16_fx( st_fx->delay_buf_out_fx, 0, delay_comp ); - Copy_Scale_sig( output_sp, st_fx->previoussynth_fx, output_frame, timeIn_e ); - } - ELSE - { - Copy( st_fx->old_synthFB_fx+st_fx->old_synth_lenFB-delay_comp, st_fx->delay_buf_out_fx, delay_comp ); - IF( L_sub(st_fx->output_Fs_fx, 8000) == 0 ) - { - Copy(st_fx->FBTCXdelayBuf, st_fx->previoussynth_fx, delay_comp); - } - ELSE - { - Copy( st_fx->FBTCXdelayBuf + delay_tdbwe, st_fx->previoussynth_fx, delay_comp ); - } - Copy(pcmbufFB, st_fx->previoussynth_fx + delay_comp, sub(output_frame, delay_comp)); - } - } - - /* Delay compensation for TD-BWE*/ - IF( sub(output_frame,L_FRAME16k) >= 0 ) - { - Copy( output_sp, tmp_buffer_fx, output_frame ); - Copy_Scale_sig( st_fx->prev_synth_buffer_fx, output_sp, delay_tdbwe, negate(timeIn_e) ); - Copy( tmp_buffer_fx, output_sp + delay_tdbwe, output_frame - delay_tdbwe ); - Copy_Scale_sig( tmp_buffer_fx + output_frame - delay_tdbwe, st_fx->prev_synth_buffer_fx, delay_tdbwe, timeIn_e); - } - - test(); - IF( st_fx->igf != 0 && sub( st_fx->m_frame_type, ACTIVE_FRAME ) == 0 ) - { - test(); - test(); - test(); - test(); - IF( st_fx->bfi_fx == 0 && sub(st_fx->core_fx, ACELP_CORE) == 0 && (st_fx->tec_flag != 0 || st_fx->tfa_flag != 0) && L_sub( st_fx->output_Fs_fx, 8000 ) > 0 ) - { - tmp16 = 0; - move16(); - if (sub(st_fx->tec_flag, 2) == 0) - { - tmp16 = 1; - move16(); - } - - hb_synth_fx_exp = procTecTfa_TBE_Fx( hb_synth_fx, hb_synth_fx_exp, st_fx->tecDec_fx.pGainTemp_m, st_fx->tecDec_fx.pGainTemp_e, - st_fx->tfa_flag, st_fx->last_core_fx, shr(output_frame, 4 ), tmp16 ); - } - - test(); - test(); - test(); - test(); - test(); - test(); - IF( (( ( st_fx->bfi_fx == 0 || st_fx->last_core_fx == ACELP_CORE ) && st_fx->core_fx == ACELP_CORE ) || - ( ( sub(st_fx->last_core_fx, ACELP_CORE) == 0 ) && (sub(st_fx->bwidth_fx, NB) != 0 && sub(st_fx->last_codec_mode, MODE2) == 0) )) - && (L_sub( st_fx->output_Fs_fx, 8000 ) > 0) ) - { - add_vec_fx( output_sp, negate(timeIn_e), hb_synth_fx, hb_synth_fx_exp, output_sp, negate(timeIn_e), output_frame ); - } - } - - - IF( L_sub( st_fx->output_Fs_fx, 8000 ) == 0 ) - { - tmps = NS2SA_fx2(st_fx->output_Fs_fx, DELAY_CLDFB_NS ); - } - ELSE - { - tmps = NS2SA_fx2(st_fx->output_Fs_fx, DELAY_BWE_TOTAL_NS ); - } - delta = NS2SA_fx2( st_fx->output_Fs_fx, TCXLTP_DELAY_NS ); - - test(); - test(); - test(); - IF ( (st_fx->bfi_fx && sub(st_fx->last_core_fx, ACELP_CORE) > 0) || sub(st_fx->core_fx, ACELP_CORE) > 0) - { - test(); - test(); - test(); - test(); - IF ( sub(st_fx->last_core_bfi, ACELP_CORE) > 0 || (st_fx->bfi_fx && st_fx->last_core_fx > ACELP_CORE) || (st_fx->prev_bfi_fx && st_fx->last_con_tcx)) - { - Copy_Scale_sig(st_fx->FBTCXdelayBuf, output_sp, tmps, negate(timeIn_e)); - Copy_Scale_sig(pcmbufFB, output_sp + tmps, sub(st_fx->L_frameTCX, tmps), negate(timeIn_e)); - } - ELSE - { - Word16 step, alpha; - - i = 15; - move16(); - step = Inv16(tmps, &i); - step = shl(step, i); - alpha = 0; - move16(); - - FOR (i = 0; i < tmps; i++) - { - output_sp[i+tmps] = msu_r(L_mult(shr(pcmbufFB[i], timeIn_e), alpha), output_sp[i+tmps], add(alpha, -32768)); - move16(); - alpha = add(alpha, step); - } - Copy_Scale_sig( pcmbufFB + tmps, output_sp + shl(tmps,1), sub(st_fx->L_frameTCX, shl(tmps,1)), negate(timeIn_e) ); - } - - Copy( pcmbufFB + st_fx->L_frameTCX - tmps, st_fx->FBTCXdelayBuf, tmps ); - - test(); - IF( st_fx->bfi_fx && sub(st_fx->last_core_fx, ACELP_CORE) > 0 ) - { - IF( L_sub(st_fx->output_Fs_fx, 8000) == 0 ) - { - Copy(st_fx->FBTCXdelayBuf, st_fx->delay_buf_out_fx, NS2SA(st_fx->output_Fs_fx, DELAY_CLDFB_NS)); - } - ELSE - { - Copy( st_fx->FBTCXdelayBuf, st_fx->prev_synth_buffer_fx, NS2SA(st_fx->output_Fs_fx, DELAY_BWE_TOTAL_NS - DELAY_CLDFB_NS) ); - Copy( st_fx->FBTCXdelayBuf + NS2SA(st_fx->output_Fs_fx, DELAY_BWE_TOTAL_NS - DELAY_CLDFB_NS), st_fx->delay_buf_out_fx, NS2SA(st_fx->output_Fs_fx, DELAY_CLDFB_NS) ); - } - } - } - ELSE IF( (sub(st_fx->last_codec_mode,MODE2)==0) && (sub(st_fx->last_core_fx, ACELP_CORE) > 0) ) - { - Word16 step, alpha; - - Copy_Scale_sig(st_fx->FBTCXdelayBuf, output_sp, delta, negate(timeIn_e)); - - i = 15; - move16(); - step = Inv16(sub(tmps,delta), &i); - step = shl(step, i); - alpha = 0; - move16(); - - FOR (i = delta; i < tmps; i++) - { - output_sp[i] = msu_r(L_mult(output_sp[i], alpha), shr(st_fx->FBTCXdelayBuf[i], timeIn_e), add(alpha, -32768)); - move16(); - alpha = add(alpha, step); - } - } - - Scale_sig(st_fx->tcxltp_mem_in, delta, sub(Qpostd, Qpostd_prev)); - Scale_sig(st_fx->tcxltp_mem_out, output_frame, sub(Qpostd, Qpostd_prev)); - test(); - - Scale_sig( output_sp, output_frame, timeIn_e ); - - tcx_ltp_post( st_fx->tcxltp, st_fx->core_fx, st_fx->L_frameTCX, st_fx->L_frame_fx, NS2SA_fx2( st_fx->output_Fs_fx, ACELP_LOOK_NS ) + tmps, - output_sp, st_fx->FBTCXdelayBuf, delta, st_fx->bfi_fx, st_fx->tcxltp_pitch_int, st_fx->tcxltp_pitch_fr, st_fx->tcxltp_gain, - &st_fx->tcxltp_pitch_int_post_prev, &st_fx->tcxltp_pitch_fr_post_prev, &st_fx->tcxltp_gain_post_prev, &st_fx->tcxltp_filt_idx_prev, - st_fx->pit_res_max, - &st_fx->pit_res_max_past, - st_fx->damping, L_sub(st_fx->total_brate_fx, 96000) >= 0, st_fx->tcxltp_mem_in, st_fx->tcxltp_mem_out, st_fx->total_brate_fx ); - Copy( output_sp, synth_fx, output_frame ); - - } /* end of MODE2 */ - - - /*----------------------------------------------------------------* - * Save synthesis for HQ FEC - *----------------------------------------------------------------*/ - post_hq_delay = NS2SA_fx2( st_fx->output_Fs_fx, POST_HQ_DELAY_NS ); - IF (sub(st_fx->codec_mode, MODE1) == 0) - { - - Copy( st_fx->synth_history_fx+output_frame, st_fx->synth_history_fx, output_frame-post_hq_delay+NS2SA_fx2( st_fx->output_Fs_fx, PH_ECU_MEM_NS )); - Copy_Scale_sig( synth_fx, st_fx->old_synthFB_fx+output_frame-post_hq_delay, output_frame,negate(Qpostd)); /* output_sp not initialized yet */ - /* reset the remaining buffer, which is read in TCX concealment the necessary samples to fill - this buffer are not available for all cases, the impact on the output is limited */ - set16_fx( st_fx->old_synthFB_fx+2*output_frame-post_hq_delay, 0, post_hq_delay ); - - IF( sub(output_frame, L_FRAME16k) >= 0 ) - { - - Copy_Scale_sig( st_fx->prev_synth_buffer_fx, st_fx->old_synthFB_fx+2*output_frame-NS2SA_fx2(st_fx->output_Fs_fx, DELAY_BWE_TOTAL_NS), NS2SA_fx2(st_fx->output_Fs_fx, DELAY_BWE_TOTAL_NS - DELAY_CLDFB_NS),negate(st_fx->Qprev_synth_buffer_fx)); - } - IF( sub(st_fx->core_fx,ACELP_CORE) != 0 ) - { - IF( sub(output_frame, L_FRAME16k) >= 0 ) - { - - Copy_Scale_sig( synth_fx+output_frame, st_fx->old_synthFB_fx+2*output_frame-NS2SA_fx2(st_fx->output_Fs_fx, DELAY_CLDFB_NS), NS2SA_fx2(st_fx->output_Fs_fx, DELAY_CLDFB_NS),negate(Qpostd)); - Copy_Scale_sig( st_fx->old_out_fx+NS2SA_fx2(st_fx->output_Fs_fx, N_ZERO_MDCT_NS), st_fx->old_synthFB_fx+2*output_frame, NS2SA_fx2(st_fx->output_Fs_fx, PH_ECU_LOOKAHEAD_NS), negate(st_fx->Q_old_wtda)); - } - ELSE - { - - Copy_Scale_sig( synth_fx+output_frame, st_fx->old_synthFB_fx+2*output_frame-NS2SA_fx2(st_fx->output_Fs_fx, DELAY_BWE_TOTAL_NS), NS2SA_fx2(st_fx->output_Fs_fx, DELAY_CLDFB_NS),negate(Qpostd)); - Copy_Scale_sig( st_fx->old_out_fx+NS2SA_fx2(st_fx->output_Fs_fx, N_ZERO_MDCT_NS), st_fx->old_synthFB_fx+2*output_frame-NS2SA_fx2(st_fx->output_Fs_fx, DELAY_BWE_TOTAL_NS - DELAY_CLDFB_NS), NS2SA_fx2(st_fx->output_Fs_fx, PH_ECU_LOOKAHEAD_NS), negate(st_fx->Q_old_wtda)); - } - } - } - - /*----------------------------------------------------------------* - * HP filtering - *----------------------------------------------------------------*/ - - st_fx->Qprev_synth_buffer_fx=Qpostd; - move16(); - Scale_sig32(st_fx->L_mem_hp_out_fx, 4, sub(Qpostd, Qpostd_prev)); - hp20(synth_fx, 1/*stride*/, output_frame, st_fx->L_mem_hp_out_fx, L_mult0(output_frame, 50)); - - /*----------------------------------------------------------------* - * Synthesis output - *----------------------------------------------------------------*/ - - IF( sub(st_fx->codec_mode,MODE1) == 0 ) - { - /* final output of synthesis signal */ - syn_output_fx( st_fx->codec_mode, synth_fx, output_frame, output_sp, Qpostd ); - } - ELSE - { - Copy( synth_fx, output_sp, output_frame ); - } - - /*--------------------------------------------------------* - * Updates - *--------------------------------------------------------*/ - - test(); - IF( st_fx->last_is_cng == 0 && sub(st_fx->codec_mode,MODE2) == 0 ) - { - st_fx->bfi_fx = 0; - move16(); - IF( st_fx->use_partial_copy && sub(st_fx->rf_frame_type, RF_TCXFD) >= 0 && sub(st_fx->rf_frame_type, RF_TCXTD2) <= 0) - { - if( sub(frameMode, FRAMEMODE_MISSING) == 0 ) - { - st_fx->bfi_fx = 1; - move16(); - } - } - ELSE IF( sub(st_fx->m_decodeMode, DEC_CONCEALMENT_EXT) == 0 ) - { - st_fx->bfi_fx = 1; - move16(); - } - updt_dec_common_fx( st_fx, -1, output_sp ); - } - ELSE - { - if( sub(st_fx->codec_mode,MODE2) == 0 ) - { - st_fx->bfi_fx = 0; - move16(); - } - updt_dec_common_fx( st_fx, hq_core_type, output_sp ); - } - IF( sub(st_fx->codec_mode,MODE2) == 0 ) - { - test(); - IF(sub(st_fx->use_partial_copy,1)==0 && sub(st_fx->rf_frame_type,RF_NELP) == 0) - { - st_fx->last_nelp_mode_dec_fx = 1; - } - ELSE - { - st_fx->last_nelp_mode_dec_fx = 0; - } - } - - st_fx->prev_use_partial_copy = st_fx->use_partial_copy; - move16(); - - st_fx->prev_tilt_code_dec_fx = 0; - move16(); - - st_fx->prev_Q_exc = st_fx->Q_exc; - move16(); - - L_tmp = L_mult(st_fx->tilt_code_dec_fx[0], 4096); - FOR( i=1; itilt_code_dec_fx[i], 4096); - } - st_fx->prev_tilt_code_dec_fx = round_fx(L_tmp); - - st_fx->prev_coder_type_fx = coder_type; - move16(); - if( sub(st_fx->core_fx,HQ_CORE) == 0 ) - { - st_fx->prev_coder_type_fx = GENERIC; - move16(); - } - - test(); - IF ( L_sub(st_fx->core_brate_fx,SID_2k40) > 0 && sub(st_fx->first_CNG_fx,1) == 0 ) - { - if( sub(st_fx->act_cnt_fx,BUF_DEC_RATE) >= 0 ) - { - st_fx->act_cnt_fx = 0; - move16(); - } - - st_fx->act_cnt_fx = add(st_fx->act_cnt_fx, 1); - - test(); - if( (sub(st_fx->act_cnt_fx,BUF_DEC_RATE)==0) && (st_fx->ho_hist_size_fx > 0) ) - { - st_fx->ho_hist_size_fx = sub(st_fx->ho_hist_size_fx,1); - } - - st_fx->act_cnt2_fx = add(st_fx->act_cnt2_fx,1); - if( sub(st_fx->act_cnt2_fx,MIN_ACT_CNG_UPD) >= 0 ) - { - st_fx->act_cnt2_fx = MIN_ACT_CNG_UPD; - move16(); - } - } - - test(); - test(); - if ( L_sub(st_fx->core_brate_fx,SID_2k40) <= 0 && st_fx->first_CNG_fx == 0 && sub(st_fx->cng_type_fx,LP_CNG) == 0 ) - { - st_fx->first_CNG_fx = 1; - move16(); - } - - /* update bandwidth switching parameters */ - IF( sub(st_fx->codec_mode, MODE1) == 0 ) - { - updt_bw_switching_fx( st_fx, synth_fx, Qpostd ); - } - ELSE - { - st_fx->last_bwidth_fx = st_fx->bwidth_fx; - move32(); - } - - /* synchronisation of CNG seeds*/ - test(); - test(); - IF( st_fx->bfi_fx || (L_sub(st_fx->core_brate_fx,FRAME_NO_DATA) != 0 && L_sub(st_fx->core_brate_fx,SID_2k40) != 0) ) - { - Random( &(st_fx->cng_seed_fx) ); - Random( &(st_fx->cng_ener_seed_fx) ); - } - - test(); - IF( st_fx->enablePlcWaveadjust && !concealWholeFrameTmp ) - { - /* update the parameters used in waveform adjustment */ - concealment_update2_x( output_sp, &st_fx->plcInfo, st_fx->L_frameTCX ); - } - - st_fx->last_total_brate_ber_fx = st_fx->total_brate_fx; - move32(); - if( st_fx->bfi_fx == 0 ) - { - st_fx->last_total_brate_fx = st_fx->total_brate_fx; - move32(); - } - - st_fx->last_flag_cna = st_fx->flag_cna; - move16(); - st_fx->hFdCngDec_fx->hFdCngCom->frame_type_previous = st_fx->m_frame_type; - move16(); - st_fx->prev_last_core_fx = st_fx->last_core_fx; - st_fx->prev_bws_cnt_fx = st_fx->bws_cnt_fx; - - return; -} diff --git a/src/libs/libevs/lib_dec/fd_cng_dec.cpp b/src/libs/libevs/lib_dec/fd_cng_dec.cpp old mode 100755 new mode 100644 index 3d4adc7f..222d9a7b --- a/src/libs/libevs/lib_dec/fd_cng_dec.cpp +++ b/src/libs/libevs/lib_dec/fd_cng_dec.cpp @@ -1,40 +1,25 @@ /*==================================================================================== - EVS Codec 3GPP TS26.442 Apr 03, 2018. Version 12.11.0 / 13.6.0 / 14.2.0 + EVS Codec 3GPP TS26.443 Nov 13, 2018. Version 12.11.0 / 13.7.0 / 14.3.0 / 15.1.0 ====================================================================================*/ - #include -#include "rom_com_fx.h" -#include "stat_dec_fx.h" -#include "stl.h" +#include +#include "typedef.h" #include "options.h" -#include "prot_fx.h" -#include "basop_util.h" -#include "rom_basop_util.h" +#include "prot.h" +#include "rom_com.h" +#define DELTA_MASKING_NOISE 1e-20f +/*------------------------------------------------------------------- + * createFdCngDec() + * + * Create an instance of type FD_CNG + *-------------------------------------------------------------------*/ - - - -/******************************** -* External tables * -********************************/ - -extern const Word16 T_DIV_L_Frame[]; /* format: 0Q15 * 2^-7 */ - - -/* - createFdCngDec - - Parameters: - - hFdCngDec i/0 : pointer to cng decoder structure - - Function: - create an instance of type FD_CNG -*/ -void createFdCngDec (HANDLE_FD_CNG_DEC *hFdCngDec) +void createFdCngDec( + HANDLE_FD_CNG_DEC* hFdCngDec +) { HANDLE_FD_CNG_DEC hs; @@ -45,1931 +30,974 @@ void createFdCngDec (HANDLE_FD_CNG_DEC *hFdCngDec) createFdCngCom(&(hs->hFdCngCom)); *hFdCngDec = hs; + + return; } -Word16 initFdCngDec (HANDLE_FD_CNG_DEC hs, Word16 scale) + +/*------------------------------------------------------------------- + * initFdCngDec() + * + * Initialize an instance of type FD_CNG + *-------------------------------------------------------------------*/ + +void initFdCngDec( + HANDLE_FD_CNG_DEC hs, /* i/o: Contains the variables related to the FD-based CNG process */ + float scale +) { /* Initialize common */ - initFdCngCom( hs->hFdCngCom, scale ); - set16_fx( hs->olapBufferAna, 0, 320 ); - hs->hFdCngCom->olapBufferAna = hs->olapBufferAna; - move16(); - set16_fx( hs->olapBufferSynth2, 0, FFTLEN ); - hs->hFdCngCom->olapBufferSynth2 = hs->olapBufferSynth2; - move16(); /* Set some counters and flags */ + hs->flag_dtx_mode = 0; + hs->lp_noise = -20.f; + hs->lp_speech = 25.f; - hs->flag_dtx_mode = 0; - move16(); - hs->lp_noise = -167772160l/*-20.f Q23*/; /* format: Q8.24 */ - hs->lp_speech = 209715200l/* 25.f Q23*/; /* format: Q8.24 */ - - /* Initialization of the noise estimation algorithm */ - - set32_fx( hs->bandNoiseShape, 0, FFTLEN2 ); - set16_fx( &hs->bandNoiseShape_exp, 0, 1); - - set32_fx (hs->partNoiseShape, 0, NPART ); - set16_fx( &hs->partNoiseShape_exp, 0, 1); - - set32_fx( hs->msPeriodog, 0, NPART_SHAPING ); - set16_fx( &hs->msPeriodog_exp, 0, 1); - - set32_fx( hs->msAlpha, 0, NPART_SHAPING ); - - set32_fx( hs->msBminWin, 0, NPART_SHAPING ); - - set32_fx( hs->msBminSubWin, 0, NPART_SHAPING ); - - set16_fx( hs->msPsd, 0, NPART_SHAPING ); - set16_fx( hs->msNoiseFloor, 0, NPART_SHAPING ); - - set32_fx( hs->msNoiseEst, 0, NPART_SHAPING ); - set16_fx( &hs->msNoiseEst_exp, 0, 1); - - set32_fx( hs->msMinBuf, 2147483647l/*1.0 Q31*/, MSNUMSUBFR*NPART_SHAPING ); - - set32_fx( hs->msCurrentMin, 2147483647l/*1.0 Q31*/, NPART_SHAPING ); - - set32_fx( hs->msCurrentMinOut, 2147483647l/*1.0 Q31*/, NPART_SHAPING ); - - set32_fx( hs->msCurrentMinSubWindow, 2147483647l/*1.0 Q31*/, NPART_SHAPING ); - - set16_fx( hs->msLocalMinFlag, 0, NPART_SHAPING ); - set16_fx( hs->msNewMinFlag, 0, NPART_SHAPING ); - - set16_fx( hs->msPsdFirstMoment, 0, NPART_SHAPING ); - - set32_fx( hs->msPsdSecondMoment, 0, NPART_SHAPING ); - set16_fx( hs->msPeriodogBuf, 0, MSBUFLEN*NPART_SHAPING ); - + /* Initialize noise estimation algorithm */ + set_f( hs->bandNoiseShape, 0.0f, FFTLEN2 ); + set_f( hs->partNoiseShape, 0.0f, NPART ); + set_f( hs->msPeriodog, 0.0f, NPART_SHAPING ); + set_f( hs->msAlpha, 0.0f, NPART_SHAPING ); + set_f( hs->msBminWin, 0.0f, NPART_SHAPING ); + set_f( hs->msBminSubWin, 0.0f, NPART_SHAPING ); + set_f( hs->msPsd, 0.0f, NPART_SHAPING ); + set_f( hs->msNoiseFloor, 0.0f, NPART_SHAPING ); + set_f( hs->msNoiseEst, 0.0f, NPART_SHAPING ); + set_f( hs->msMinBuf, FLT_MAX, MSNUMSUBFR*NPART_SHAPING ); + set_f( hs->msCurrentMin, FLT_MAX, NPART_SHAPING ); + set_f( hs->msCurrentMinOut, FLT_MAX, NPART_SHAPING ); + set_f( hs->msCurrentMinSubWindow, FLT_MAX, NPART_SHAPING ); + set_i( hs->msLocalMinFlag, 0, NPART_SHAPING ); + set_i( hs->msNewMinFlag, 0, NPART_SHAPING ); + set_f( hs->msPsdFirstMoment, 0.0f, NPART_SHAPING ); + set_f( hs->msPsdSecondMoment, 0.0f, NPART_SHAPING ); hs->msPeriodogBufPtr = 0; - move16(); + set_f( hs->msPeriodogBuf, 0.0f, MSBUFLEN*NPART_SHAPING ); + set_f( hs->msLogPeriodog, 0.0f, NPART_SHAPING ); + set_f( hs->msLogNoiseEst, 0.0f, NPART_SHAPING ); - set16_fx( hs->msLogPeriodog, 0, NPART_SHAPING ); - set16_fx( hs->msLogNoiseEst, 0, NPART_SHAPING ); - - - return 0; + return; } -/* - configureFdCngDec - Parameters: +/*------------------------------------------------------------------- + * configureFdCngDec() + * + * Configure an instance of type FD_CNG + *-------------------------------------------------------------------*/ - hs i/o: Contains the variables related to the FD-based CNG process - numSlots i : Number of time slots in CLDFB matrix - numCoreBands i : Number of core bands - regularStopBand i : Number of CLDFB bands to be considered - CLDFBscale i : cldfb scale factor - - Function: - configure FD_CNG - - Returns: - void -*/ -void configureFdCngDec (HANDLE_FD_CNG_DEC hsDec, /* i/o: Contains the variables related to the CLDFB-based CNG process */ - Word16 bandwidth, - Word32 bitrate, - Word16 L_frame - ) +void configureFdCngDec( + HANDLE_FD_CNG_DEC hsDec, /* i/o: Contains the variables related to the FD-based CNG process */ + short bandwidth, + int bitrate, + short L_frame +) { - Word16 j, stopBandFR; + int j, stopBandFR; HANDLE_FD_CNG_COM hsCom = hsDec->hFdCngCom; - hsCom->CngBandwidth = bandwidth; - IF ( sub( hsCom->CngBandwidth, FB ) == 0 ) + if ( hsCom->CngBandwidth == FB ) { hsCom->CngBandwidth = SWB; } - test(); - if ( bitrate != FRAME_NO_DATA && L_sub(bitrate, SID_2k40) != 0 ) + if ( bitrate != FRAME__NO_DATA && bitrate != SID_2k40 ) { - hsCom->CngBitrate = L_add(bitrate, 0); + hsCom->CngBitrate = bitrate; } hsCom->numSlots = 16; - move16(); /* NB configuration */ - IF ( bandwidth == NB ) + if ( bandwidth == NB ) { hsCom->FdCngSetup = FdCngSetup_nb; hsCom->numCoreBands = 16; - move16(); hsCom->regularStopBand = 16; - move16(); } /* WB configuration */ - ELSE IF ( sub(bandwidth, WB) == 0 ) + else if ( bandwidth == WB ) { /* FFT 6.4kHz, no CLDFB */ - test(); - test(); - IF ( L_sub(hsCom->CngBitrate, ACELP_8k00) <= 0 - && sub(L_frame,L_FRAME)==0 - ) + if ( hsCom->CngBitrate <= ACELP_8k00 && L_frame==L_FRAME ) { hsCom->FdCngSetup = FdCngSetup_wb1; hsCom->numCoreBands = 16; - move16(); hsCom->regularStopBand = 16; - move16(); } /* FFT 6.4kHz, CLDFB 8.0kHz */ - ELSE IF ( L_sub(hsCom->CngBitrate, ACELP_13k20) <= 0 - || sub(L_frame,L_FRAME)==0 - ) + else if ( hsCom->CngBitrate <= ACELP_13k20 || L_frame==L_FRAME ) { hsCom->FdCngSetup = FdCngSetup_wb2; hsCom->numCoreBands = 16; - move16(); hsCom->regularStopBand = 20; - move16(); - IF ( - sub(L_frame,L_FRAME16k)==0 - ) + if ( L_frame==L_FRAME16k ) { hsCom->FdCngSetup = FdCngSetup_wb2; hsCom->numCoreBands = 20; - move16(); hsCom->regularStopBand = 20; - move16(); hsCom->FdCngSetup.fftlen = 640; - move16(); hsCom->FdCngSetup.stopFFTbin = 256; - move16(); } } /* FFT 8.0kHz, no CLDFB */ - ELSE + else { hsCom->FdCngSetup = FdCngSetup_wb3; hsCom->numCoreBands = 20; - move16(); hsCom->regularStopBand = 20; - move16(); } } /* SWB/FB configuration */ - ELSE + else { /* FFT 6.4kHz, CLDFB 14kHz */ - IF ( - sub(L_frame,L_FRAME)==0 - ) + if ( L_frame==L_FRAME ) { hsCom->FdCngSetup = FdCngSetup_swb1; hsCom->numCoreBands = 16; - move16(); hsCom->regularStopBand = 35; - move16(); } /* FFT 8.0kHz, CLDFB 16kHz */ - ELSE + else { hsCom->FdCngSetup = FdCngSetup_swb2; hsCom->numCoreBands = 20; - move16(); hsCom->regularStopBand = 40; - move16(); } } hsCom->fftlen = hsCom->FdCngSetup.fftlen; - move16(); hsCom->stopFFTbin = hsCom->FdCngSetup.stopFFTbin; - move16(); - /* Configure the SID quantizer and the Confort Noise Generator */ + /* Configure the SID quantizer and the Comfort Noise Generator */ hsCom->startBand = 2; - move16(); - hsCom->stopBand = add( hsCom->FdCngSetup.sidPartitions[hsCom->FdCngSetup.numPartitions-1], 1 ); - initPartitions(hsCom->FdCngSetup.sidPartitions, hsCom->FdCngSetup.numPartitions, hsCom->startBand, hsCom->stopBand, hsCom->part, &hsCom->npart, hsCom->midband, hsCom->psize, hsCom->psize_norm, &hsCom->psize_norm_exp, hsCom->psize_inv, 0); - - hsCom->nFFTpart = 21; - move16(); - if ( sub(hsCom->stopFFTbin, 256) == 0 ) - { - hsCom->nFFTpart = 20; - move16(); - } - if ( sub(hsCom->stopFFTbin, 160) == 0 ) + hsCom->stopBand = hsCom->FdCngSetup.sidPartitions[hsCom->FdCngSetup.numPartitions-1] + 1; + initPartitions(hsCom->FdCngSetup.sidPartitions, hsCom->FdCngSetup.numPartitions, hsCom->startBand, hsCom->stopBand, hsCom->part, &hsCom->npart, hsCom->midband, hsCom->psize, hsCom->psize_inv, 0); + if ( hsCom->stopFFTbin == 160 ) { hsCom->nFFTpart = 17; - move16(); } - - hsCom->nCLDFBpart = sub( hsCom->npart, hsCom->nFFTpart ); - FOR(j=0; jnCLDFBpart; j++) + else if ( hsCom->stopFFTbin == 256 ) { - hsCom->CLDFBpart[j] = sub( hsCom->part[j+hsCom->nFFTpart], (hsCom->stopFFTbin-hsCom->startBand) ); - move16(); + hsCom->nFFTpart = 20; + } + else + { + hsCom->nFFTpart = 21; + } + hsCom->nCLDFBpart = hsCom->npart - hsCom->nFFTpart; + for(j=0; jnCLDFBpart; j++) + { + hsCom->CLDFBpart[j] = hsCom->part[j+hsCom->nFFTpart] - (hsCom->stopFFTbin-hsCom->startBand); hsCom->CLDFBpsize_inv[j] = hsCom->psize_inv[j+hsCom->nFFTpart]; - move16(); } - stopBandFR = 1000/25; - if ( sub(stopBandFR, hsCom->stopFFTbin) > 0 ) + stopBandFR = (int)floor( 1000.f/*Hz*/ / 25.f/*Hz/Bin*/ ); + if ( stopBandFR > hsCom->stopFFTbin ) { stopBandFR = hsCom->stopFFTbin; - move16(); } initPartitions(hsCom->FdCngSetup.shapingPartitions, hsCom->FdCngSetup.numShapingPartitions, hsCom->startBand, hsCom->stopFFTbin, hsDec->part_shaping, &hsDec->npart_shaping, hsDec->midband_shaping, - hsDec->psize_shaping, hsDec->psize_shaping_norm, &hsDec->psize_shaping_norm_exp, hsDec->psize_inv_shaping, - stopBandFR ); - hsDec->nFFTpart_shaping = hsDec->npart_shaping; - move16(); + hsDec->psize_shaping, hsDec->psize_inv_shaping, stopBandFR ); - SWITCH (hsCom->fftlen) + hsDec->nFFTpart_shaping = hsDec->npart_shaping; + + switch (hsCom->fftlen) { case 512: - hsCom->fftlenShift = 8; - move16(); - hsCom->fftlenFac = 32767/*1.0 Q15*/; - move16(); - BREAK; + hsCom->fftSineTab = NULL; + hsCom->olapWinAna = olapWinAna512; + hsCom->olapWinSyn = olapWinSyn256; + break; case 640: - hsCom->fftlenShift = 9; - move16(); - hsCom->fftlenFac = 20480/*0.625 Q15*/; - move16(); - BREAK; + hsCom->fftSineTab = fftSineTab640; + hsCom->olapWinAna = olapWinAna640; + hsCom->olapWinSyn = olapWinSyn320; + break; default: assert(!"Unsupported FFT length for FD-based CNG"); - BREAK; + break; } - BASOP_getTables( &hsCom->olapWinAna, NULL, NULL, shr(hsCom->fftlen, 1)); - BASOP_getTables( &hsCom->olapWinSyn, NULL, NULL, shr(hsCom->fftlen, 2)); - hsCom->frameSize = shr(hsCom->fftlen,1); + hsCom->frameSize = hsCom->fftlen >> 1; + return; } -/* - deleteFdCngDec +/*------------------------------------------------------------------- + * deleteFdCngDec() + * + * Delete the instance of type FD_CNG + *-------------------------------------------------------------------*/ - Parameters: - - hFdCngDec i/0 : pointer to cng decoder structure - - Function: - delete the instance of type FD_CNG - - Returns: - void -*/ -void deleteFdCngDec (HANDLE_FD_CNG_DEC *hFdCngDec) +void deleteFdCngDec( + HANDLE_FD_CNG_DEC * hFdCngDec +) { - HANDLE_FD_CNG_DEC hsDec = *hFdCngDec; - IF ( hsDec != NULL ) + HANDLE_FD_CNG_DEC hsDec = *hFdCngDec; + if (hsDec != NULL) { - deleteFdCngCom (&(hsDec->hFdCngCom)); + deleteFdCngCom(&(hsDec->hFdCngCom)); free(hsDec); *hFdCngDec = NULL; } + + return; } -/* - ApplyFdCng +/*------------------------------------------------------------------- + * ApplyFdCng() + * + * Apply the CLDFB-based CNG at the decoder + *-------------------------------------------------------------------*/ - Parameters: - - timeDomainInput, i : pointer to time domain input - cldfbBufferReal i/o: real part of the CLDFB buffer - cldfbBufferImag i/o: imaginary part of the CLDFB buffer - cldfbBufferScale o : pointer to the scalefactor for real and imaginary part of the CLDFB buffer - st i/o: pointer to FD_CNG structure containing all buffers and variables - m_frame_type i : type of frame at the decoder side - stcod i : pointer to Coder_State structure - stdec i : pointer to Decoder_State structure - bitrate i : bitrate - concealWholeFrame i : binary flag indicating frame loss - - Function: - apply the CLDFB-based CNG at the decoder - - Returns: - error -*/ -Word16 ApplyFdCng (Word16 *timeDomainInput, /* i : pointer to time domain input */ - Word16 Q, - Word32 **cldfbBufferReal, /* i/o: real part of the CLDFB buffer */ - Word32 **cldfbBufferImag, /* i/o: imaginary part of the CLDFB buffer */ - Word16 *cldfbBufferScale, /* o : pointer to the scalefactor for real and imaginary part of the CLDFB buffer */ - HANDLE_FD_CNG_DEC st, /* i/o: pointer to FD_CNG structure containing all buffers and variables */ - Word16 m_frame_type, /* i : type of frame at the decoder side */ - Decoder_State_fx *stdec, - const Word16 concealWholeFrame, /* i : binary flag indicating frame loss */ - Word16 is_music - ) +void ApplyFdCng( + float * timeDomainInput, + float ** realBuffer, /* i/o: Real part of the buffer */ + float ** imagBuffer, /* i/o: Imaginary part of the buffer */ + HANDLE_FD_CNG_DEC st, /* i/o: FD_CNG structure containing all buffers and variables */ + unsigned char m_frame_type, /* i : Type of frame at the decoder side */ + Decoder_State *stdec, + const int concealWholeFrame, + short is_music +) { - Word16 j, k, nBins; - Word16 s, s1, s2, num, denom; - Word32 *cngNoiseLevel; - Word16 *cngNoiseLevel_exp; - Word32 L_tmp; - Word16 L_tmp_exp; - Word16 facTab[NPART]; - Word16 facTabExp[NPART]; - Word16 tmp_loop; - Word32 L_c; - Word16 lsp_cng[M]; + float* cngNoiseLevel = st->hFdCngCom->cngNoiseLevel; + float* sidNoiseEst = st->hFdCngCom->sidNoiseEst; + int j,k; + float factor; + float lsp_cng[M]; - - if(sub(st->hFdCngCom->frame_type_previous,ACTIVE_FRAME)==0) + if( st->hFdCngCom->frame_type_previous == ACTIVE_FRAME ) { st->hFdCngCom->inactive_frame_counter = 0; - move16(); } - cngNoiseLevel = st->hFdCngCom->cngNoiseLevel; - cngNoiseLevel_exp = &st->hFdCngCom->cngNoiseLevelExp; - - nBins = sub(st->hFdCngCom->stopFFTbin,st->hFdCngCom->startBand); - - SWITCH ( m_frame_type ) + switch (m_frame_type) { - case ACTIVE_FRAME: + case ACTIVE_FRAME: /************************** * ACTIVE_FRAME at DECODER * **************************/ st->hFdCngCom->inactive_frame_counter = 0; - move16(); st->hFdCngCom->sid_frame_counter = 0; - move16(); - /* set noise estimation inactive during concealment, as no update with noise generated by concealment should be performed. */ - /* set noise estimation inactive during concealment, no update with noise generated by concealment should be performed. */ - - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - IF( - (concealWholeFrame == 0) && - (*timeDomainInput < MAXVAL_WORD16) && (*timeDomainInput > MINVAL_WORD16) && (*(timeDomainInput+st->hFdCngCom->frameSize-1) < MAXVAL_WORD16) && (*(timeDomainInput+st->hFdCngCom->frameSize-1) > MINVAL_WORD16) - && ( ((st->flag_dtx_mode == 0) && (stdec->VAD != 0)) == 0 ) - && ( ((stdec->cng_type_fx == LP_CNG) && (st->flag_dtx_mode != 0)) == 0) - && ( is_music == 0 ) - && (stdec->BER_detect == 0) - ) + /* set noise estimation inactive when we have bit errors, as no update with noise generated by corrupt frame (biterror) should be performed. */ + if ( concealWholeFrame==0 && + *timeDomainInput(-FLT_MAX) && + *(timeDomainInput+st->hFdCngCom->frameSize-1)hFdCngCom->frameSize-1)>(-FLT_MAX) + && + !(!st->flag_dtx_mode&&stdec->VAD) + && !(stdec->cng_type==LP_CNG && st->flag_dtx_mode) + && ( is_music == 0 ) + && (!stdec->BER_detect) + ) { /* Perform noise estimation at the decoder */ - perform_noise_estimation_dec ( - timeDomainInput, - Q, - st - ); - - - /* Update the shaping parameters */ - scalebands ( - st->msNoiseEst, - st->part_shaping, - st->nFFTpart_shaping, - st->midband_shaping, - st->nFFTpart_shaping, - nBins, - st->bandNoiseShape, - 1 - ); - - st->bandNoiseShape_exp = st->msNoiseEst_exp; - move16(); - - - /* Update CNG levels */ - test(); - IF ( st->flag_dtx_mode != 0 && stdec->cng_type_fx == FD_CNG ) - { - /* This needs to be done only once per inactive phase */ - bandcombinepow ( - st->bandNoiseShape, - st->bandNoiseShape_exp, - nBins, - st->hFdCngCom->part, - st->hFdCngCom->nFFTpart, - st->hFdCngCom->psize_inv, - st->partNoiseShape, - &st->partNoiseShape_exp - ); - - - j = 0; - move16(); - s2 = -(WORD32_BITS-1); - move16(); - FOR (k=0; k < st->hFdCngCom->nFFTpart; k++) - { - assert(st->partNoiseShape[k]>=0); - assert(st->hFdCngCom->sidNoiseEst[k]>=0); - - /* add DELTA as it is done in FLC version, in order to avoid num > denom */ - facTab[k] = 0; - move16(); - IF ( st->partNoiseShape[k] != 0) - { - s1 = norm_l(st->hFdCngCom->sidNoiseEst[k]); - L_tmp = L_shl(st->hFdCngCom->sidNoiseEst[k], s1); - L_tmp_exp = sub(st->hFdCngCom->sidNoiseEstExp, s1); - L_tmp = BASOP_Util_Add_Mant32Exp(L_tmp, L_tmp_exp, DELTA_MANTISSA_W32, DELTA_EXPONENT, &L_tmp_exp); - L_tmp = L_shr(L_tmp, 1); - s = add(L_tmp_exp, 1); - num = extract_h(L_tmp); - - s1 = norm_l(st->partNoiseShape[k]); - L_tmp = L_shl(st->partNoiseShape[k], s1); - L_tmp_exp = sub(st->partNoiseShape_exp, s1); - L_tmp = BASOP_Util_Add_Mant32Exp(L_tmp, L_tmp_exp, DELTA_MANTISSA_W32, DELTA_EXPONENT, &L_tmp_exp); - s = sub(s, L_tmp_exp); - denom = extract_h(L_tmp); - - facTab[k] = div_s(num,denom); - move16(); - facTabExp[k] = s; - move16(); - } - /* Set unique exponent, if mantissa is equal to zero */ - if (facTab[k] == 0) - { - facTabExp[k] = -(WORD32_BITS-1); - move16(); - } - s2 = s_max(s2,facTabExp[k]); - } - - FOR (k=0; k < st->hFdCngCom->nFFTpart; k++) - { - s = sub(facTabExp[k],s2); - s = s_max(s_min(s,WORD32_BITS-1),-(WORD32_BITS-1)); - FOR ( ; j <= st->hFdCngCom->part[k]; j++) - { - cngNoiseLevel[j] = L_shl(Mpy_32_16_1(st->bandNoiseShape[j],facTab[k]),s); - move32(); - } - } - - /* adapt scaling for rest of the buffer */ - IF (sub(s2,-(WORD32_BITS-1)) != 0) - { - s = sub(*cngNoiseLevel_exp,add(st->bandNoiseShape_exp,s2)); - FOR ( ; k < st->hFdCngCom->npart; k++) - { - FOR( ; j <= st->hFdCngCom->part[k]; j++) - { - cngNoiseLevel[j] = L_shl(cngNoiseLevel[j],s); - move32(); - } - } - - *cngNoiseLevel_exp = add(st->bandNoiseShape_exp,s2); - move16(); - } - } - ELSE - { - /* This sets the new CNG levels until a SID update overwrites it */ - Copy32 ( - st->bandNoiseShape, - cngNoiseLevel, - nBins - ); - - *cngNoiseLevel_exp = st->bandNoiseShape_exp; - move16(); - } - /*stdec->cngTDLevel = (float)sqrt( (sumFLOAT(cngNoiseLevel, st->hFdCngCom->stopFFTbin - st->hFdCngCom->startBand) / 2 * st->hFdCngCom->fftlen) / stdec->Mode2_L_frame);*/ - tmp_loop = sub(st->hFdCngCom->stopFFTbin , st->hFdCngCom->startBand); - L_tmp = L_deposit_h(0); - L_c = L_deposit_h(0); - FOR(j = 0 ; j < tmp_loop; j++) - { - - Carry = 0; - L_tmp = L_add_c(L_tmp,*(cngNoiseLevel+j)); - Overflow = 0; - - if(*(cngNoiseLevel+j) < 0) - { - L_c = L_msuNs(L_c,0,0); - } - if(*(cngNoiseLevel+j) >= 0) - { - L_c = L_macNs(L_c,0,0); - } - } - L_tmp = norm_llQ31(L_c,L_tmp,&L_tmp_exp); - L_tmp_exp = sub(add(L_tmp_exp,*cngNoiseLevel_exp),1); - - L_tmp = Mpy_32_16_1(L_tmp,st->hFdCngCom->fftlen); /*Q16*/ - - L_tmp = Mpy_32_16_1(L_tmp,T_DIV_L_Frame[L_shl(L_mac(-28000,stdec->L_frame_fx,95),1-15)]);/*Q16,exp -7*/ - L_tmp_exp = add(L_tmp_exp,-7); /*->Q16, L_tmp_exp */ - L_tmp_exp = add(L_tmp_exp,31-16); /*->Q31, L_tmp_exp*/ - - stdec->cngTDLevel = round_fx(Sqrt32(L_tmp, &L_tmp_exp)); - stdec->cngTDLevel_e = L_tmp_exp; - move16(); - - - } - test(); - test(); - L_tmp = 0; - FOR( j=st->hFdCngCom->startBand; jhFdCngCom->stopFFTbin; j++ ) - { - L_tmp = L_add(L_tmp,L_shr(cngNoiseLevel[j],16)); - } - L_tmp_exp = add(*cngNoiseLevel_exp,16); - IF (sub(concealWholeFrame,1)==0 && sub(stdec->nbLostCmpt,1)==0 && (L_shl(L_tmp,L_tmp_exp)>21474836 /*0.01f Q31*/)) - { - /* update isf cng estimate for concealment. Do that during concealment, in order to avoid addition clean channel complexity*/ - lpc_from_spectrum(cngNoiseLevel, *cngNoiseLevel_exp, st->hFdCngCom->startBand, st->hFdCngCom->stopFFTbin, st->hFdCngCom->fftlen, st->hFdCngCom->A_cng, - M, 0); - E_LPC_a_lsp_conversion( st->hFdCngCom->A_cng, lsp_cng, stdec->lspold_cng, M ); - Copy( lsp_cng, stdec->lspold_cng, M); - - lsp2lsf_fx( lsp_cng, stdec->lsf_cng, M, stdec->sr_core ); - stdec->plcBackgroundNoiseUpdated = 1; - move16(); - } - BREAK; - - case SID_FRAME: - - st->flag_dtx_mode = 1; - move16(); - /* no break */ - - case ZERO_FRAME: - - test(); - IF(stdec!=NULL && stdec->cng_type_fx==LP_CNG) - { - /* Perform noise estimation on inactive phase at the decoder */ - perform_noise_estimation_dec(timeDomainInput, Q, st - ); + perform_noise_estimation_dec(timeDomainInput, st ); /* Update the shaping parameters */ scalebands(st->msNoiseEst, st->part_shaping, st->nFFTpart_shaping, st->midband_shaping, st->nFFTpart_shaping, st->hFdCngCom->stopFFTbin-st->hFdCngCom->startBand, st->bandNoiseShape, 1); - st->bandNoiseShape_exp = st->msNoiseEst_exp; - move16(); - /* This sets the new CNG levels until a SID update overwrites it */ - Copy32(st->bandNoiseShape, cngNoiseLevel, st->hFdCngCom->stopFFTbin-st->hFdCngCom->startBand); /* This sets the new CNG levels until a SID update overwrites it */ - *cngNoiseLevel_exp = st->bandNoiseShape_exp; - move16(); - /*stdec->cngTDLevel = (float)sqrt( (sumFLOAT(cngNoiseLevel, st->hFdCngCom->stopFFTbin - st->hFdCngCom->startBand) / 2 * st->hFdCngCom->fftlen) / stdec->Mode2_L_frame);*/ - tmp_loop = sub(st->hFdCngCom->stopFFTbin , st->hFdCngCom->startBand); - L_tmp = L_deposit_h(0); - L_c = L_deposit_h(0); - FOR(j = 0 ; j < tmp_loop; j++) + /* Update CNG levels */ + if ( st->flag_dtx_mode && stdec->cng_type == FD_CNG ) { + bandcombinepow(st->bandNoiseShape, st->hFdCngCom->stopFFTbin-st->hFdCngCom->startBand, st->hFdCngCom->part, st->hFdCngCom->nFFTpart, st->hFdCngCom->psize_inv, st->partNoiseShape); /* This needs to be done only once per inactive phase */ - Carry = 0; - L_tmp = L_add_c(L_tmp,*(cngNoiseLevel+j)); - Overflow = 0; - - if(*(cngNoiseLevel+j) < 0) + j = 0; + for(k=0 ; khFdCngCom->nFFTpart ; k++) { - L_c = L_msuNs(L_c,0,0); - } - if(*(cngNoiseLevel+j) >= 0) - { - L_c = L_macNs(L_c,0,0); + factor = (st->hFdCngCom->sidNoiseEst[k]+DELTA)/(st->partNoiseShape[k]+DELTA); + for(; j<=st->hFdCngCom->part[k] ; j++) + { + cngNoiseLevel[j] = st->bandNoiseShape[j] * factor; + } } } - L_tmp = norm_llQ31(L_c,L_tmp,&L_tmp_exp); - L_tmp_exp = sub(add(L_tmp_exp,*cngNoiseLevel_exp),1); + else + { + /* This sets the new CNG levels until a SID update overwrites it */ + mvr2r(st->bandNoiseShape, cngNoiseLevel, st->hFdCngCom->stopFFTbin-st->hFdCngCom->startBand); /* This sets the new CNG levels until a SID update overwrites it */ + } - L_tmp = Mpy_32_16_1(L_tmp,st->hFdCngCom->fftlen); /*Q16*/ - - L_tmp = Mpy_32_16_1(L_tmp,T_DIV_L_Frame[L_shl(L_mac(-28000,stdec->L_frame_fx,95),1-15)]);/*Q16,exp -7*/ - L_tmp_exp = add(L_tmp_exp,-7); /*->Q16, L_tmp_exp */ - L_tmp_exp = add(L_tmp_exp,31-16); /*->Q31, L_tmp_exp*/ - - stdec->cngTDLevel = round_fx(Sqrt32(L_tmp, &L_tmp_exp)); - stdec->cngTDLevel_e = L_tmp_exp; - move16(); - - BREAK; + stdec->cngTDLevel = (float)sqrt( (sum_f(cngNoiseLevel, st->hFdCngCom->stopFFTbin - st->hFdCngCom->startBand) / 2 * st->hFdCngCom->fftlen) / stdec->L_frame); } - st->hFdCngCom->inactive_frame_counter = add(st->hFdCngCom->inactive_frame_counter,1); - move16(); + if ((concealWholeFrame==1) && (stdec->nbLostCmpt==1) + && sum_f(cngNoiseLevel+st->hFdCngCom->startBand, st->hFdCngCom->stopFFTbin - st->hFdCngCom->startBand)>0.01f) + { + /* update lsf cng estimate for concealment. Do that during concealment, in order to avoid addition clean channel complexity*/ + lpc_from_spectrum( cngNoiseLevel, st->hFdCngCom->startBand, st->hFdCngCom->stopFFTbin, st->hFdCngCom->fftlen, st->hFdCngCom->fftSineTab, st->hFdCngCom->A_cng, 0 ); + + a2lsp_stab( st->hFdCngCom->A_cng, lsp_cng, stdec->lspold_cng ); + mvr2r( lsp_cng, stdec->lspold_cng, M ); + + lsp2lsf( lsp_cng, stdec->lsf_cng, M, stdec->sr_core ); + stdec->plcBackgroundNoiseUpdated = 1; + } + break; + + case SID_FRAME: + st->flag_dtx_mode = 1; + + case ZERO_FRAME: + + if( stdec!=NULL && stdec->cng_type == LP_CNG ) + { + /* Perform noise estimation on inactive phase at the decoder */ + perform_noise_estimation_dec(timeDomainInput, st ); + + /* Update the shaping parameters */ + scalebands(st->msNoiseEst, st->part_shaping, st->nFFTpart_shaping, st->midband_shaping, st->nFFTpart_shaping, st->hFdCngCom->stopFFTbin-st->hFdCngCom->startBand, st->bandNoiseShape, 1); + + /* This sets the new CNG levels until a SID update overwrites it */ + mvr2r(st->bandNoiseShape, cngNoiseLevel, st->hFdCngCom->stopFFTbin-st->hFdCngCom->startBand); /* This sets the new CNG levels until a SID update overwrites it */ + + stdec->cngTDLevel = (float)sqrt( (sum_f(cngNoiseLevel, st->hFdCngCom->stopFFTbin - st->hFdCngCom->startBand) / 2 * st->hFdCngCom->fftlen) / stdec->L_frame); + break; + } + + st->hFdCngCom->inactive_frame_counter++; /************************************* * SID_FRAME or ZERO_FRAME at DECODER * *************************************/ /* Detect first non-active frame */ - IF ( sub(st->hFdCngCom->inactive_frame_counter,1) == 0 ) + if (st->hFdCngCom->inactive_frame_counter == 1) { /* Compute the fine spectral structure of the comfort noise shape using the decoder-side noise estimates */ - bandcombinepow ( - st->bandNoiseShape, - st->bandNoiseShape_exp, - nBins, - st->hFdCngCom->part, - st->hFdCngCom->nFFTpart, - st->hFdCngCom->psize_inv, - st->partNoiseShape, - &st->partNoiseShape_exp - ); + bandcombinepow(st->bandNoiseShape, st->hFdCngCom->stopFFTbin-st->hFdCngCom->startBand, st->hFdCngCom->part, st->hFdCngCom->nFFTpart, st->hFdCngCom->psize_inv, st->partNoiseShape); } - - IF ( sub(m_frame_type,SID_FRAME) == 0 ) + if (m_frame_type == SID_FRAME) { - IF ( L_sub(st->hFdCngCom->msFrCnt_init_counter,L_deposit_l(st->hFdCngCom->msFrCnt_init_thresh)) < 0 ) + if (st->hFdCngCom->msFrCnt_init_counter < st->hFdCngCom->msFrCnt_init_thresh) { /* At initialization, interpolate the bin/band-wise levels from the partition levels */ - scalebands ( - st->hFdCngCom->sidNoiseEst, - st->hFdCngCom->part, - st->hFdCngCom->npart, - st->hFdCngCom->midband, - st->hFdCngCom->nFFTpart, - sub(st->hFdCngCom->stopBand,st->hFdCngCom->startBand), - cngNoiseLevel, - 1 - ); - *cngNoiseLevel_exp = st->hFdCngCom->sidNoiseEstExp; - move16(); + scalebands(sidNoiseEst, st->hFdCngCom->part, st->hFdCngCom->npart, st->hFdCngCom->midband, st->hFdCngCom->nFFTpart, st->hFdCngCom->stopBand-st->hFdCngCom->startBand, cngNoiseLevel, 1); } - ELSE + else { /* Interpolate the CLDFB band levels from the SID (partition) levels */ - IF ( sub( st->hFdCngCom->regularStopBand, st->hFdCngCom->numCoreBands ) > 0 ) + if (st->hFdCngCom->regularStopBand>st->hFdCngCom->numCoreBands) { - scalebands ( - st->hFdCngCom->sidNoiseEst, - st->hFdCngCom->part, - st->hFdCngCom->npart, - st->hFdCngCom->midband, - st->hFdCngCom->nFFTpart, - sub(st->hFdCngCom->stopBand,st->hFdCngCom->startBand), - cngNoiseLevel, - 0 - ); - - *cngNoiseLevel_exp = st->hFdCngCom->sidNoiseEstExp; - move16(); + scalebands(sidNoiseEst, st->hFdCngCom->part, st->hFdCngCom->npart, st->hFdCngCom->midband, st->hFdCngCom->nFFTpart, st->hFdCngCom->stopBand-st->hFdCngCom->startBand, cngNoiseLevel, 0); } - - s2 = -(WORD32_BITS-1); - move16(); /* Shape the SID noise levels in each FFT bin */ j = 0; - move16(); - FOR (k=0; k < st->hFdCngCom->nFFTpart ; k++) + for(k=0 ; khFdCngCom->nFFTpart ; k++) { - assert(st->partNoiseShape[k]>=0); - - /* add DELTA as it is done in FLC version, in order to avoid num > denom */ - facTab[k] = 0; - move16(); - IF ( st->partNoiseShape[k] != 0) + factor = (sidNoiseEst[k]+DELTA)/(st->partNoiseShape[k]+DELTA); + for(; j<=st->hFdCngCom->part[k] ; j++) { - s1 = norm_l(st->hFdCngCom->sidNoiseEst[k]); - L_tmp = L_shl(st->hFdCngCom->sidNoiseEst[k], s1); - L_tmp_exp = sub(st->hFdCngCom->sidNoiseEstExp, s1); - L_tmp = BASOP_Util_Add_Mant32Exp(st->hFdCngCom->sidNoiseEst[k], st->hFdCngCom->sidNoiseEstExp, DELTA_MANTISSA_W32, DELTA_EXPONENT, &L_tmp_exp); - L_tmp = L_shr(L_tmp, 1); - s = add(L_tmp_exp, 1); - num = extract_h(L_tmp); - - s1 = norm_l(st->partNoiseShape[k]); - L_tmp = L_shl(st->partNoiseShape[k], s1); - L_tmp_exp = sub(st->partNoiseShape_exp, s1); - L_tmp = BASOP_Util_Add_Mant32Exp(L_tmp, L_tmp_exp, DELTA_MANTISSA_W32, DELTA_EXPONENT, &L_tmp_exp); - s = sub(s, L_tmp_exp); - denom = extract_h(L_tmp); - - facTab[k] = div_s(num,denom); - move16(); - facTabExp[k] = s; - move16(); - } - /* Set unique exponent, if mantissa is equal to zero */ - if (facTab[k] == 0) - { - facTabExp[k] = -(WORD32_BITS-1); - move16(); - } - s2 = s_max(s2,facTabExp[k]); - } - - FOR (k=0; k < st->hFdCngCom->nFFTpart; k++) - { - s = sub(facTabExp[k],s2); - s = s_max(s_min(s,WORD32_BITS-1),-(WORD32_BITS-1)); - FOR( ; j <= st->hFdCngCom->part[k]; j++) - { - cngNoiseLevel[j] = L_shl(Mpy_32_16_1(st->bandNoiseShape[j],facTab[k]),s); - move32(); + cngNoiseLevel[j] = st->bandNoiseShape[j] * factor; } } - /* adapt scaling for rest of the buffer */ - s = sub(*cngNoiseLevel_exp,add(st->bandNoiseShape_exp,s2)); - FOR ( ; k < st->hFdCngCom->npart; k++) - { - FOR( ; j <= st->hFdCngCom->part[k]; j++) - { - cngNoiseLevel[j] = L_shl(cngNoiseLevel[j],s); - move32(); - } - } - *cngNoiseLevel_exp = add(st->bandNoiseShape_exp,s2); - move16(); } } - - IF ( sub(stdec->codec_mode, MODE2) == 0 ) + if( stdec->codec_mode == MODE2 ) { /* Generate comfort noise during SID or zero frames */ - generate_comfort_noise_dec ( - cldfbBufferReal, - cldfbBufferImag, - cldfbBufferScale, - stdec, - &(stdec->Q_exc), - 2 - ); + generate_comfort_noise_dec(realBuffer, imagBuffer, stdec); } - BREAK; + break; default: - return -1; + break; } - - return 0; -} - - -/* - perform_noise_estimation_dec - - Parameters: - - timeDomainInput, i: pointer to time domain input - bitrate, i: bitrate - st i/o: FD_CNG structure containing all buffers and variables - - Function: - perform noise estimation - - Returns: - void -*/ -void perform_noise_estimation_dec (const Word16 *timeDomainInput, /* i: pointer to time domain input */ - Word16 Q, - HANDLE_FD_CNG_DEC st /* i/o: FD_CNG structure containing all buffers and variables */ - ) -{ - Word16 i, tmp_r, tmp_i, fac, fftBuffer_exp; - Word16 s, len, npart, nFFTpart; - Word16 startBand, stopFFTbin; - - Word16 *part, *psize_inv, *psize_norm; - Word32 tmp, *fftBuffer, *periodog, *ptr_per, *ptr_r, *ptr_i; - - - - /* pointer initialization */ - periodog = st->hFdCngCom->periodog; - fftBuffer = st->hFdCngCom->fftBuffer; - - part = st->part_shaping; - psize_inv = st->psize_inv_shaping; - psize_norm = st->psize_shaping_norm; - - /* variable initialization */ - startBand = st->hFdCngCom->startBand; - move16(); - stopFFTbin = st->hFdCngCom->stopFFTbin; - move16(); - - npart = st->npart_shaping; - move16(); - nFFTpart = st->nFFTpart_shaping; - move16(); - - /* Perform STFT analysis */ - AnalysisSTFT ( - timeDomainInput, - Q, - fftBuffer, - &fftBuffer_exp, - st->hFdCngCom - ); - - fftBuffer_exp = add(fftBuffer_exp,WORD16_BITS-1); - - - assert(startBand != 0); - - len = sub(stopFFTbin, startBand); - - s = getScaleFactor32 (&fftBuffer[2*startBand], 2*len); - s = sub(s,1); - - ptr_per = periodog; - IF ( startBand == 0 ) - { - /* DC component */ - tmp_r = extract_h(L_shl(fftBuffer[0],s)); - - tmp = L_mult(tmp_r, tmp_r); - *ptr_per = tmp; - - ptr_per++; - ptr_r = fftBuffer + 2; - len = sub(len, 1); - } - ELSE - { - ptr_r = fftBuffer + shl(startBand, 1); - } - - ptr_i = ptr_r+1; - FOR (i=0; i < len; i++) - { - tmp_r = extract_h(L_shl(*ptr_r,s)); - tmp_i = extract_h(L_shl(*ptr_i,s)); - - tmp = L_mac(L_mult(tmp_r, tmp_r),tmp_i, tmp_i); - *ptr_per = tmp; - - ptr_r += 2; - ptr_i += 2; - ptr_per++; - } - - st->hFdCngCom->periodog_exp = shl(sub(fftBuffer_exp,s),1); - - /* Rescale */ - assert( (st->hFdCngCom->fftlen == 640) || (st->hFdCngCom->fftlen == 512) || (st->hFdCngCom->fftlen == 320) ); - - fac = 20972/*0.64 Q15*/; - move16(); - if( sub(st->hFdCngCom->fftlen,512) == 0 ) - { - fac = 16384/*0.5 Q15*/; - move16(); - } - - if ( sub(st->hFdCngCom->fftlen,640) == 0 ) - { - s = 18; - move16(); - } - if ( sub(st->hFdCngCom->fftlen,512) == 0 ) - { - s = 17; - move16(); - } - if ( sub(st->hFdCngCom->fftlen,320) == 0 ) - { - s = 16; - move16(); - } - - len = sub(stopFFTbin, startBand); - FOR (i=0; i < len; i++) - { - st->hFdCngCom->periodog[i] = Mpy_32_16_1(st->hFdCngCom->periodog[i],fac); - } - st->hFdCngCom->periodog_exp = add(st->hFdCngCom->periodog_exp,sub(2,s)); - - - /* Adjust to the desired frequency resolution by averaging over spectral partitions for SID transmission */ - bandcombinepow(periodog, st->hFdCngCom->periodog_exp, sub(stopFFTbin,startBand), part, npart, psize_inv, st->msPeriodog, &st->msPeriodog_exp); - - - st->msPeriodog_exp_fft = st->msPeriodog_exp; - move16(); - st->msPeriodog_exp_cldfb = st->msPeriodog_exp; - move16(); - - - /* Compress MS inputs */ - compress_range(st->msPeriodog, st->msPeriodog_exp, st->msLogPeriodog, npart); - - /* Call the minimum statistics routine for noise estimation */ - minimum_statistics ( - npart, - nFFTpart, - psize_norm, - st->msLogPeriodog, - st->msNoiseFloor, - st->msLogNoiseEst, - st->msAlpha, - st->msPsd, - st->msPsdFirstMoment, - st->msPsdSecondMoment, - st->msMinBuf, - st->msBminWin, - st->msBminSubWin, - st->msCurrentMin, - st->msCurrentMinOut, - st->msCurrentMinSubWindow, - st->msLocalMinFlag, - st->msNewMinFlag, - st->msPeriodogBuf, - &(st->msPeriodogBufPtr), - st->hFdCngCom - ); - - /* Expand MS outputs */ - expand_range(st->msLogNoiseEst, st->msNoiseEst, &st->msNoiseEst_exp, npart); - -} - - - -/* - FdCng_decodeSID - - Parameters: - - st i/o: FD_CNG structure containing all buffers and variables - bs_word16 i : Bitstream - amrwb_io i : amr wideband mode - preemph_fac i : preemphase factor - - Function: - decode the FD-CNG bitstream - - Returns: - void -*/ -void FdCng_decodeSID (HANDLE_FD_CNG_COM st, Decoder_State_fx *corest) -{ - Word16 i, N, index; - Word32 *sidNoiseEst; - - Word16 indices[32], v16[32]; - Word32 v[32], gain; - - Word32 tmp, maxVal, E_ExpLd64; - Word16 sidNoiseEst_Exp; - - Word16 preemph_fac; - - - sidNoiseEst = st->sidNoiseEst; - move16(); - preemph_fac = corest->preemph_fac; - move16(); - - N = st->npart; - move16(); - - st->sid_frame_counter = add(st->sid_frame_counter,1); - move16(); - - /* Read bitstream */ - FOR (i=0; i= 0; maxVal -= 33554432l/*0.015625 Q31*/) - { - sidNoiseEst_Exp = add(sidNoiseEst_Exp,1); - } - st->sidNoiseEstExp = sidNoiseEst_Exp; - move16(); - E_ExpLd64 = L_shl(sidNoiseEst_Exp, WORD32_BITS-1-LD_DATA_SCALE); - - /* format v: Q9.23, format sidNoiseEst: Q6.26, 0.66438561897 = log10(10)/log10(2.0) / 10.0 * 2.0 */ - FOR (i=0; isidNoiseEst[i] = BASOP_Util_InvLog2(tmp); - move32(); - } - - /* NB last band energy compensation */ - IF ( st->CngBandwidth == NB ) - { - st->sidNoiseEst[N-1] = Mpy_32_16_1(st->sidNoiseEst[N-1], NB_LAST_BAND_SCALE); - move32(); - } - - test(); - if ( st->CngBandwidth == SWB && st->CngBitrate <= ACELP_13k20 ) - { - st->sidNoiseEst[N-1] = Mpy_32_16_1(st->sidNoiseEst[N-1], SWB_13k2_LAST_BAND_SCALE); - } - - - scalebands (sidNoiseEst, st->part, st->npart, st->midband, st->nFFTpart, st->stopBand-st->startBand, st->cngNoiseLevel, 1); - st->cngNoiseLevelExp = st->sidNoiseEstExp; - move16(); - - - lpc_from_spectrum (st->cngNoiseLevel, st->cngNoiseLevelExp, st->startBand, st->stopFFTbin, st->fftlen, st->A_cng, M, preemph_fac); - - -} - - -/* - noisy_speech_detection - - Parameters: - - vad i : VAD decision - Etot i : total channel E - Etot_exp i : exponent for total channel E - totalNoise i : noise estimate over all critical bands - totalNoise_exp i : exponent for noise estimate over all critical bands - lp_noise i/o: pointer to long term total Noise energy average - lp_speech i/o: pointer to long term active speech energy average - - Function: - detector for noisy speech, lp_noise and lp_speech are scaled by LD_DATA_SCALE+2 bits - - Returns: flag, that indicates whether noisy speech has been detected - - void -*/ -void noisy_speech_detection (const Word16 vad, - const Word16 *ftimeInPtr, /* i : input time-domain frame */ - const Word16 frameSize, /* i : frame size */ - const Word16 Q, - const Word32 *msNoiseEst, /* i : noise estimate over all critical bands */ - const Word16 msNoiseEst_exp, /* i : exponent for noise estimate over all critical bands */ - const Word16 *psize_norm, - const Word16 psize_norm_exp, - const Word16 nFFTpart, /* i : Number of partitions taken into account */ - Word32 *lp_noise, /* i/o: pointer to long term total Noise energy average */ - Word32 *lp_speech, /* i/o: pointer to long term active speech energy average */ - Word16 *flag_noisy_speech - ) -{ - Word16 i; - Word32 tmp; - Word32 Etot; - Word16 Etot_exp; - Word32 logEtot; - Word32 logEtotExp; - Word32 totalNoise; - Word16 totalNoise_exp; - Word32 logTotalNoise; - Word32 logTotalNoiseExp; - - - IF ( vad == 0 ) - { - totalNoise = dotWord32_16_Mant32Exp(msNoiseEst, msNoiseEst_exp, psize_norm, psize_norm_exp, nFFTpart, &totalNoise_exp); - - /* - - logTotalNoise is scaled by LD_DATA_SCALE+2 - - logTotalNoise = 10.0 * log10(totalNoise + DELTA); - - constant: -0.78125 = 10.0*log10(DELTA)/(1<<(LD_DATA_SCALE+2)) - - constant: 0.75257498916 = 10.0 * log10(2.0)/log10(10.0)/(1<<2) - */ - IF ( totalNoise == 0 ) - { - logTotalNoise = L_add(-1677721600l/*-0.78125 Q31*/, 0); - } - ELSE - { - logTotalNoise = BASOP_Util_Log2(totalNoise); - logTotalNoiseExp = L_shl(L_deposit_l(totalNoise_exp),WORD32_BITS-1-LD_DATA_SCALE); - logTotalNoise = Mpy_32_16_1(L_add(logTotalNoise,logTotalNoiseExp),24660/*0.75257498916 Q15*/); - } - - *lp_noise = L_add(Mpy_32_16_1(*lp_noise,32604/*0.995 Q15*/),L_shr(Mpy_32_16_1(logTotalNoise,20972/*0.64 Q15*/),7)); - move32(); - } - ELSE - { - Etot = 0; - Etot_exp = 31; - FOR( i = 0; i < frameSize ; i++ ) - { - tmp = L_shr_r( L_mult0( ftimeInPtr[i], ftimeInPtr[i] ), sub( Etot_exp, 31 ) ); - IF( L_sub( maxWord32, tmp ) < Etot ) - { - Etot_exp = add( Etot_exp, 1 ); - Etot = L_shr_r( Etot, 1 ); - tmp = L_shr_r( tmp, 1 ); - } - Etot = L_add( Etot, tmp ); - } - Etot_exp = sub( Etot_exp, shl( Q, 1 ) ); - - /* - - logEtot is scaled by LD_DATA_SCALE+2 - - logEtot = 10.0 * log10(totalNoise + DELTA); - - constant: -0.78125 = 10.0*log10(DELTA)/(1<<(LD_DATA_SCALE+2)) - - constant: 0.75257498916 = 10.0 * log10(2.0)/log10(10.0)/(1<<2) - */ - IF ( Etot == 0 ) - { - logEtot = L_add(-1677721600l/*-0.78125 Q31*/, 0); - } - ELSE - { - logEtot = BASOP_Util_Log2(Etot); - logEtotExp = L_shl(L_deposit_l(Etot_exp),WORD32_BITS-1-LD_DATA_SCALE); - logEtot = Mpy_32_16_1(L_add(logEtot,logEtotExp),24660/*0.75257498916 Q15*/); - IF ( sub( frameSize, L_FRAME16k ) == 0 ) - { - logEtot = L_add( logEtot, -184894985l/*-0.086098436822497 Q31*/ ); - } - ELSE - { - logEtot = L_add( logEtot, -176765584l/*-0.082312889439370 Q31*/ ); - } - } - - *lp_speech = L_add(Mpy_32_16_1(*lp_speech,32604/*0.995 Q15*/),L_shr(Mpy_32_16_1(logEtot,20972/*0.64 Q15*/),7)); - move32(); - } - - tmp = L_sub(*lp_speech,377487360l/*45.0 Q23*/); - - if ( L_sub(*lp_noise,tmp) < 0 ) - { - *lp_noise = tmp; - move32(); - } - - *flag_noisy_speech = 0; - move16(); - if ( L_sub(L_sub(*lp_speech,*lp_noise),234881024l/*28.0 Q23*/) < 0 ) - { - *flag_noisy_speech = 1; - move16(); - } - - return; } -void -generate_comfort_noise_dec (Word32 **bufferReal, /* o : matrix to real part of input bands */ - Word32 **bufferImag, /* o : matrix to imaginary part of input bands */ - Word16 *bufferScale, /* o : pointer to scalefactor for real and imaginary part of input bands */ - Decoder_State_fx *stdec, - Word16 *Q_new, - Word16 gen_exc - ) +/*------------------------------------------------------------------- + * perform_noise_estimation_dec() + * + * Perform noise estimation at the decoder + *-------------------------------------------------------------------*/ + +void perform_noise_estimation_dec( + const float * timeDomainInput, + HANDLE_FD_CNG_DEC st /* i/o: FD_CNG structure containing all buffers and variables */ +) { - Word16 i, j, s, sc, sn, cnt; - Word16 startBand2; - Word16 stopFFTbin2; - Word16 scaleCLDFB; - Word16 preemph_fac; - Word32 sqrtNoiseLevel; - Word16 randGaussExp; - Word16 fftBufferExp; - Word16 cngNoiseLevelExp; - Word16 *seed; - Word16 *timeDomainOutput; - Word32 *ptr_r, *ptr_i; - Word32 *cngNoiseLevel; - Word32 *ptr_level; - Word32 *fftBuffer; - Word16 old_syn_pe_tmp[16]; - Word16 tcx_transition = 0; - HANDLE_FD_CNG_DEC std = stdec->hFdCngDec_fx; + float * ptr_r; + float * ptr_i; + int startBand = st->hFdCngCom->startBand; + int stopFFTbin = st->hFdCngCom->stopFFTbin; + float * fftBuffer = st->hFdCngCom->fftBuffer; + float * periodog = st->hFdCngCom->periodog; + float * ptr_per = periodog; + float * msPeriodog = st->msPeriodog; + float * msNoiseEst = st->msNoiseEst; + + float * msLogPeriodog = st->msLogPeriodog; + float * msLogNoiseEst = st->msLogNoiseEst; + + int * part = st->part_shaping; + int npart = st->npart_shaping; + int nFFTpart = st->nFFTpart_shaping; + float * psize = st->psize_shaping; + float * psize_inv = st->psize_inv_shaping; + + /* Perform STFT analysis */ + AnalysisSTFT(timeDomainInput, fftBuffer, st->hFdCngCom); + + /* Compute the squared magnitude in each FFT bin */ + if( startBand == 0 ) + { + (*ptr_per) = fftBuffer[0]*fftBuffer[0]; /* DC component */ + ptr_per++; + ptr_r = fftBuffer + 2; + } + else + { + ptr_r = fftBuffer + 2*startBand; + } + + ptr_i = ptr_r+1; + + for( ; ptr_per < periodog+stopFFTbin-startBand ; ptr_per++) + { + (*ptr_per) = (*ptr_r)*(*ptr_r) + (*ptr_i)*(*ptr_i); + ptr_r += 2; + ptr_i += 2; + } + /* Nyquist frequency is discarded */ + + /* Rescale to get energy/sample: it should be 2*(1/N)*(2/N), parseval relation with 1/N,*2 for nrg computed till Nyquist only, 2/N as windowed samples correspond to half a frame*/ + v_multc( periodog, 4.f/(float)(st->hFdCngCom->fftlen*st->hFdCngCom->fftlen), periodog, stopFFTbin-startBand); + + /* Adjust to the desired frequency resolution by averaging over spectral partitions for SID transmission */ + bandcombinepow( periodog, stopFFTbin-startBand, part, npart, psize_inv, msPeriodog ); + + /* Compress MS inputs */ + compress_range( msPeriodog, msLogPeriodog, npart ); + + /* Call the minimum statistics routine for noise estimation */ + minimum_statistics( npart, nFFTpart, psize, msLogPeriodog, st->msNoiseFloor, msLogNoiseEst, st->msAlpha, st->msPsd, st->msPsdFirstMoment, st->msPsdSecondMoment, + st->msMinBuf, st->msBminWin, st->msBminSubWin, st->msCurrentMin, st->msCurrentMinOut, st->msCurrentMinSubWindow, + st->msLocalMinFlag, st->msNewMinFlag, st->msPeriodogBuf, &(st->msPeriodogBufPtr), st->hFdCngCom ); + + /* Expand MS outputs */ + expand_range(msLogNoiseEst, msNoiseEst, npart); + + return; +} + + +/*------------------------------------------------------------------- + * FdCng_decodeSID() + * + * Decode the FD-CNG bitstream + *-------------------------------------------------------------------*/ + +void FdCng_decodeSID( + Decoder_State *corest /* i/o: decoder state structure */ +) +{ + int N; + float* sidNoiseEst; + float gain; + float preemph_fac; + + int i, index; + float v[32]; + int indices[32]; + HANDLE_FD_CNG_COM st; + + st = (corest->hFdCngDec)->hFdCngCom; + + sidNoiseEst = st->sidNoiseEst; + preemph_fac = corest->preemph_fac; + + N = st->npart; + gain = 0.0f; + st->sid_frame_counter++; + + /* Read bitstream */ + for ( i=0; iCngBandwidth == NB) + { + sidNoiseEst[N-1] *= NB_LAST_BAND_SCALE; + } + + if ( st->CngBandwidth == SWB && st->CngBitrate <= ACELP_13k20 ) + { + sidNoiseEst[N-1] *= SWB_13k2_LAST_BAND_SCALE; + } + + scalebands(sidNoiseEst, st->part, st->npart, st->midband, st->nFFTpart, st->stopBand-st->startBand, st->cngNoiseLevel, 1); + + lpc_from_spectrum(st->cngNoiseLevel, st->startBand, st->stopFFTbin, st->fftlen, st->fftSineTab, st->A_cng, preemph_fac ); + + return; +} + + +/*------------------------------------------------------------------- + * noisy_speech_detection() + * + * + *-------------------------------------------------------------------*/ + +void noisy_speech_detection( + const short vad, + const float * ftimeInPtr, /* i : input time-domain frame */ + const int frameSize, /* i : frame size */ + const float * msNoiseEst, /* i : noise estimate over all critical bands */ + const float * psize, /* i : partition sizes */ + const int nFFTpart, /* i : Number of partitions taken into account */ + float *lp_noise, /* i/o: long term total Noise energy average */ + float *lp_speech, /* i/o: long term active speech energy average */ + short *flag_noisy_speech +) +{ + float tmp; + + if( vad == 0 ) + { + tmp = dotp(msNoiseEst, psize, nFFTpart); + *lp_noise = 0.995f * *lp_noise + 0.005f * 10.f*(float)log10( tmp + DELTA); + } + else + { + tmp = dotp(ftimeInPtr, ftimeInPtr, frameSize) * 2.f/frameSize; + *lp_speech = 0.995f * *lp_speech + 0.005f * 10.f*(float)log10( tmp + DELTA ); + } + + tmp = *lp_speech - 45.f; + if (*lp_noisehFdCngDec; HANDLE_FD_CNG_COM st = std->hFdCngCom; - - - - /* Warning fix */ - s = 0; - - /* pointer initialization */ - - cngNoiseLevel = st->cngNoiseLevel; - cngNoiseLevelExp = st->cngNoiseLevelExp; - ptr_level = cngNoiseLevel; - seed = &(st->seed); - fftBuffer = st->fftBuffer; - timeDomainOutput = st->timeDomainBuffer; - - /* scaleCLDFB: CLDFBinvScalingFactor_EXP + 1 */ - scaleCLDFB = mult(st->invScalingFactor,CLDFB_SCALING); + float * cngNoiseLevel = st->cngNoiseLevel; + float * ptr_level = cngNoiseLevel; + short * seed = &(st->seed); + float scale = 1.f; + float scaleCldfb = CLDFB_SCALING / st->scalingFactor; + float * fftBuffer = st->fftBuffer; + float * timeDomainOutput = st->timeDomainBuffer; + float preemph_fac = stdec->preemph_fac; + int tcx_transition = 0; + float enr, att; + short bwidth = stdec->bwidth; + short CNG_mode = stdec->CNG_mode; /* Generate Gaussian random noise in real and imaginary parts of the FFT bins Amplitudes are adjusted to the estimated noise level cngNoiseLevel in each bin - scaling Gaussian random noise: format Q3.29 */ - sn = 0; - move16(); - IF ( s_and(cngNoiseLevelExp,1) != 0 ) + if (st->startBand==0) { - sn = add(sn,1); - cngNoiseLevelExp = add(cngNoiseLevelExp,sn); - move16(); - } - - randGaussExp = CNG_RAND_GAUSS_SHIFT; - move16(); - cnt = sub(st->stopFFTbin, st->startBand); - IF ( st->startBand == 0 ) - { - /* DC component in FFT */ - s = 0; - move16(); - sqrtNoiseLevel = Sqrt32(L_shr(*ptr_level,sn), &s); - - fftBuffer[0] = L_shl(Mpy_32_32(rand_gauss(seed),sqrtNoiseLevel),s); - move32(); - - /* Nyquist frequency is discarded */ - fftBuffer[1] = L_deposit_l(0); - - ptr_level = ptr_level + 1; + rand_gauss(&fftBuffer[0], seed); + fftBuffer[0] *= (float)sqrt(scale **ptr_level); /* DC component in FFT */ + ptr_level++; ptr_r = fftBuffer + 2; - cnt = sub(cnt, 1); } - ELSE + else { - startBand2 = shl(st->startBand,1); - set32_fx(fftBuffer, 0, startBand2); - ptr_r = fftBuffer + startBand2; + fftBuffer[0] = 0.f; + set_f( fftBuffer+2, 0.0f, 2*(st->startBand-1) ); + ptr_r = fftBuffer + 2*st->startBand; } - - sn = add(sn,1); ptr_i = ptr_r + 1; - FOR (i=0; i < cnt; i++) + for( ; ptr_level < cngNoiseLevel+st->stopFFTbin-st->startBand ; ptr_level++) { - s = 0; - move16(); - sqrtNoiseLevel = Sqrt32(L_shr(*ptr_level,sn), &s); - /* Real part in FFT bins */ - *ptr_r = L_shl(Mpy_32_32(rand_gauss(seed),sqrtNoiseLevel),s); - move32(); - + rand_gauss(ptr_r, seed); + (*ptr_r) *= (float)sqrt((scale **ptr_level)*0.5f); + ptr_r += 2; /* Imaginary part in FFT bins */ - *ptr_i = L_shl(Mpy_32_32(rand_gauss(seed),sqrtNoiseLevel),s); - move32(); - - ptr_r = ptr_r + 2; - ptr_i = ptr_i + 2; - ptr_level = ptr_level + 1; + rand_gauss(ptr_i, seed); + (*ptr_i) *= (float)sqrt((scale **ptr_level)*0.5f); + ptr_i += 2; } /* Remaining FFT bins are set to zero */ - stopFFTbin2 = shl(st->stopFFTbin,1); - set32_fx(fftBuffer+stopFFTbin2, 0, sub(st->fftlen,stopFFTbin2)); + set_f( fftBuffer+2*st->stopFFTbin, 0.0f, st->fftlen-2*st->stopFFTbin); - fftBufferExp = add(shr(cngNoiseLevelExp,1),randGaussExp); + /* Nyquist frequency is discarded */ + fftBuffer[1] = 0.f; /* If previous frame is active, reset the overlap-add buffer */ - IF ( st->frame_type_previous == ACTIVE_FRAME ) + if( st->frame_type_previous==ACTIVE_FRAME ) { - set16_fx(st->olapBufferSynth, 0, st->fftlen); - test(); - test(); - if ( ( stdec->last_core_bfi > ACELP_CORE && stdec->codec_mode == MODE2 ) || stdec->codec_mode == MODE1 ) + set_f( st->olapBufferSynth, 0.0f, st->fftlen); + if( (stdec->core > 0 && stdec->codec_mode == MODE2) || stdec->codec_mode == MODE1 ) { tcx_transition = 1; - move16(); } } /* Perform STFT synthesis */ - SynthesisSTFT (fftBuffer, fftBufferExp, timeDomainOutput, st->olapBufferSynth, st->olapWinSyn, - tcx_transition, - st, gen_exc, Q_new); + SynthesisSTFT(fftBuffer, timeDomainOutput, st->olapBufferSynth, st->olapWinSyn, tcx_transition, st ); + /* update CNG excitation energy for LP_CNG */ + + /* calculate the residual signal energy */ + enr = dotp( st->exc_cng, st->exc_cng, st->frameSize ) / st->frameSize; + + /* convert log2 of residual signal energy */ + enr = (float)log10( enr + 0.1f ) / (float)log10( 2.0f ); + + /* decrease the energy in case of WB input */ + if( bwidth != NB ) { - Word32 Lener, att; - Word16 exp; - /* update CNG excitation energy for LP_CNG */ - - /* calculate the residual signal energy */ - /*enr = dotp( st->exc_cng, st->exc_cng, st->frameSize ) / st->frameSize;*/ - Lener = Dot_productSq16HQ(1,st->exc_cng,stdec->L_frame_fx,&exp); - exp = add(sub(shl(sub(15,*Q_new),1),8),exp); /*8 = log2(256)*/ - - /* convert log2 of residual signal energy */ - /*(float)log10( enr + 0.1f ) / (float)log10( 2.0f );*/ - Lener = BASOP_Util_Log2(Lener); - Lener = L_add(Lener,L_shl(L_deposit_l(exp),WORD32_BITS-1-LD_DATA_SCALE)); /*Q25*/ - if(stdec->L_frame_fx == L_FRAME16k) + if( bwidth == WB ) { - Lener = L_sub(Lener, 10802114l/*0.3219280949f Q25*/); /*log2(320) = 8.3219280949f*/ + if( CNG_mode >= 0 ) + { + /* Bitrate adapted attenuation */ + att = ENR_ATT[CNG_mode]; + } + else + { + /* Use least attenuation for higher bitrates */ + att = ENR_ATT[4]; + } } - /* decrease the energy in case of WB input */ - IF( sub(stdec->bwidth_fx, NB) != 0 ) + else { - IF( sub(stdec->bwidth_fx,WB) == 0 ) - { - IF( stdec->CNG_mode_fx >= 0 ) - { - /* Bitrate adapted attenuation */ - att = L_shl(L_deposit_l(ENR_ATT_fx[stdec->CNG_mode_fx]),17); - } - ELSE - { - /* Use least attenuation for higher bitrates */ - att = L_shl(L_deposit_l(ENR_ATT_fx[4]),17); - } - } - ELSE - { - att = 384<<17; - move16();/*1.5 Q8<<17=Q25*/ - } - Lener = L_sub(Lener, att ); + att = 1.5f; } - /*stdec->lp_ener = 0.8f * stcod->lp_ener + 0.2f * pow( 2.0f, enr );*/ - Lener = BASOP_util_Pow2(Lener, 6, &exp); - Lener = Mult_32_16(Lener, 6554/*0.2f Q15*/); - exp = sub(25,exp); - Lener = L_shr(Lener, exp); /*Q6*/ - stdec->lp_ener_fx = L_add(Mult_32_16(stdec->lp_ener_fx, 26214/*0.8f Q15*/), Lener); /*Q6*/ + + enr -= att; } + stdec->lp_ener = 0.8f * stdec->lp_ener + 0.2f * pow( 2.0f, enr ); + /* Generate Gaussian random noise in real and imaginary parts of the CLDFB bands Amplitudes are adjusted to the estimated noise level cngNoiseLevel in each band */ - test(); - IF ( bufferReal!=NULL && (sub(st->numCoreBands,st->regularStopBand) < 0) ) + if (bufferReal!=NULL && st->numCoreBands < st->regularStopBand) { - - sn = sub(sn,1); - sc = add(shr(add(cngNoiseLevelExp,CLDFBinvScalingFactor_EXP+1-1),1),randGaussExp); - move16(); - assert( ((cngNoiseLevelExp+CLDFBinvScalingFactor_EXP+1-1)&1) == 0); - - FOR (j=st->numCoreBands; jregularStopBand; j++) + for(j=st->numCoreBands ; jregularStopBand ; j++) { - /* scaleCLDFB: CLDFBinvScalingFactor_EXP + 1 */ - s = 0; - move16(); - sqrtNoiseLevel = Sqrt32(L_shr(Mpy_32_16_1(*ptr_level,scaleCLDFB),sn), &s); - - FOR (i=0; inumSlots; i++) + for(i=0 ; inumSlots ; i++) { /* Real part in CLDFB band */ - bufferReal[i][j] = L_shl(Mpy_32_32(rand_gauss(seed),sqrtNoiseLevel),s); - move32(); - /*fprintf(pFile,"%13.10f\n",WORD322FL_SCALE(bufferReal[i][j],sc));*/ - + rand_gauss(&bufferReal[i][j], seed); + bufferReal[i][j] *= (float)sqrt((scaleCldfb **ptr_level)*0.5f); /* Imaginary part in CLDFB band */ - bufferImag[i][j] = L_shl(Mpy_32_32(rand_gauss(seed),sqrtNoiseLevel),s); - move32(); - /*fprintf(pFile,"%13.10f\n",WORD322FL_SCALE(bufferImag[i][j],sc));*/ + rand_gauss(&bufferImag[i][j], seed); + bufferImag[i][j] *= (float)sqrt((scaleCldfb **ptr_level)*0.5f); } - ptr_level = ptr_level + 1; + ptr_level++; } - *bufferScale = sub(sc,15); - move16(); } /* Overlap-add when previous frame is active */ - test(); - IF ( st->frame_type_previous == ACTIVE_FRAME && stdec->codec_mode == MODE2 ) + if( st->frame_type_previous == ACTIVE_FRAME && stdec->codec_mode == MODE2 ) { - Word32 old_exc_ener, gain, noise32; - Word16 seed_loc, lpcorder, old_syn, tmp, gain16, N, N2, N4, N8; - Word16 old_exc_ener_exp, gain_exp; - Word16 normFacE, normShiftE, normShiftEM1; - Word16 normFacG, normShiftG, normShiftGM1; - Word16 noiseExp, *old_exc, *old_Aq, *old_syn_pe; - Word16 noise[640], normShiftP2; - Word16 Q_exc, Q_syn; + float noise[2048], old_exc_ener = 0.f, gain = 0.f, tmp; + int N = st->frameSize; + short seed_loc = st->seed; + float *old_exc, old_Aq[M+1], *old_syn_pe, old_syn; - - assert(st->frameSize <= 640); - - seed_loc = st->seed; - move16(); - N = st->frameSize; - move16(); - N2 = shr(st->frameSize,1); - - IF ( stdec->last_core_bfi > ACELP_CORE ) + if( stdec->core > ACELP_CORE ) { - Word16 left_overlap_mode; - left_overlap_mode = stdec->tcx_cfg.tcx_last_overlap_mode; - move16(); - if (sub(left_overlap_mode, ALDO_WINDOW) == 0) - { - left_overlap_mode = FULL_OVERLAP; - move16(); - } + tcx_windowing_synthesis_current_frame( timeDomainOutput, stdec->tcx_cfg.tcx_mdct_window, /*Keep sine windows for limiting Time modulation*/ + stdec->tcx_cfg.tcx_mdct_window_half, stdec->tcx_cfg.tcx_mdct_window_minimum, stdec->tcx_cfg.tcx_mdct_window_length, + stdec->tcx_cfg.tcx_mdct_window_half_length, stdec->tcx_cfg.tcx_mdct_window_min_length, 0, + stdec->tcx_cfg.tcx_last_overlap_mode==ALDO_WINDOW?FULL_OVERLAP:stdec->tcx_cfg.tcx_last_overlap_mode, + NULL, NULL, NULL, NULL, NULL, N/2, stdec->tcx_cfg.tcx_offset<0?-stdec->tcx_cfg.tcx_offset:0, + 1, 0, 0 ); - tcx_windowing_synthesis_current_frame( timeDomainOutput, - stdec->tcx_cfg.tcx_mdct_window, /*Keep sine windows for limiting Time modulation*/ - stdec->tcx_cfg.tcx_mdct_window_half, - stdec->tcx_cfg.tcx_mdct_window_minimum, - stdec->tcx_cfg.tcx_mdct_window_length, - stdec->tcx_cfg.tcx_mdct_window_half_length, - stdec->tcx_cfg.tcx_mdct_window_min_length, - 0, - left_overlap_mode, - NULL, - NULL, - NULL, - NULL, - NULL, - N/2, - shr(sub(abs_s(stdec->tcx_cfg.tcx_offset), stdec->tcx_cfg.tcx_offset), 1), /* equivalent to: stdec->tcx_cfg.tcx_offset<0?-stdec->tcx_cfg.tcx_offset:0 */ - 1, - 0, - 0 - ); - - IF (stdec->tcx_cfg.last_aldo != 0) + if( stdec->tcx_cfg.last_aldo ) { - FOR (i=0; iframeSize,NS2SA(stdec->sr_core, N_ZERO_MDCT_NS)); i++) + for (i=0; i<(st->frameSize-NS2SA(stdec->sr_core, N_ZERO_MDCT_NS)); i++) { - timeDomainOutput[i] = add(timeDomainOutput[i], shr_r(stdec->old_out_LB_fx[i+NS2SA(stdec->sr_core, N_ZERO_MDCT_NS)],stdec->Q_old_wtda_LB)); + timeDomainOutput[i] += stdec->old_outLB[i+NS2SA(stdec->sr_core, N_ZERO_MDCT_NS)]; } } - ELSE + else { tcx_windowing_synthesis_past_frame( stdec->syn_Overl, - stdec->tcx_cfg.tcx_mdct_window, - stdec->tcx_cfg.tcx_mdct_window_half, - stdec->tcx_cfg.tcx_mdct_window_minimum, - stdec->tcx_cfg.tcx_mdct_window_length, - stdec->tcx_cfg.tcx_mdct_window_half_length, - stdec->tcx_cfg.tcx_mdct_window_min_length, - stdec->tcx_cfg.tcx_last_overlap_mode - ); + stdec->tcx_cfg.tcx_mdct_window, + stdec->tcx_cfg.tcx_mdct_window_half, + stdec->tcx_cfg.tcx_mdct_window_minimum, stdec->tcx_cfg.tcx_mdct_window_length, stdec->tcx_cfg.tcx_mdct_window_half_length, + stdec->tcx_cfg.tcx_mdct_window_min_length, stdec->tcx_cfg.tcx_last_overlap_mode ); - FOR (i=0; itcx_cfg.tcx_mdct_window_length; i++) + for (i=0; itcx_cfg.tcx_mdct_window_length; i++) { - timeDomainOutput[i] += shl(stdec->syn_Overl[i],TCX_IMDCT_HEADROOM); + timeDomainOutput[i] += stdec->syn_Overl[i]; } } } - ELSE + else { - /* - - the scaling of the LPCs (e.g. old_Aq) is always Q12 (encoder or decoder) + mvr2r(stdec->old_Aq_12_8, old_Aq,M+1); + old_exc = stdec->old_exc+L_EXC_MEM_DEC-(N/2); + old_syn_pe = stdec->mem_syn2; + old_syn = stdec->syn[M]; - - the scaling of the deemphasized signals (e.g. old_syn) is always Q0 (encoder or decoder) - - - the scaling of the excitation signals in the encoder (e.g. old_exc) is Q_new - - the scaling of the preemphasized signals in the encoder (e.g. old_syn_pe) is Q_new-1 - - - the scaling of the excitation signals in the decoder (e.g. old_exc) is Q_exc (or stdec->Q_exc) - - the scaling of the preemphasized signals in the decoder (e.g. old_syn_pe) is Q_syn (or stdec->Q_syn) - */ - - lpcorder = M; - move16(); - old_Aq = stdec->old_Aq_12_8_fx; - old_exc = stdec->old_exc_fx+sub(L_EXC_MEM_DEC,N2); - old_syn_pe = stdec->mem_syn2_fx; - old_syn = stdec->syn[lpcorder]; - move16(); - preemph_fac = stdec->preemph_fac; - move16(); - Q_exc = stdec->Q_exc; - move16(); - Q_syn = stdec->Q_syn; - move16(); - - /* shift to be in the range of values supported by getNormReciprocalWord16() */ - N8 = shr(N2, CNG_NORM_RECIPROCAL_RANGE_SHIFT); - - assert( N2 == (N8<olapWinSyn[i].v.re); - timeDomainOutput[i] = add(timeDomainOutput[i],tmp); - move16(); - tmp = mult(noise[i+N4],st->olapWinSyn[N4-1-i].v.im); - timeDomainOutput[i+N4] = add(timeDomainOutput[i+N4],tmp); - move16(); + timeDomainOutput[i] += noise[i] * st->olapWinSyn[N/2+i]; } } } + return; } -void -generate_comfort_noise_dec_hf (Word32 **bufferReal, /* o : matrix to real part of input bands */ - Word32 **bufferImag, /* o : matrix to imaginary part of input bands */ - Word16 *bufferScale, /* o : pointer to scalefactor for real and imaginary part of input bands */ - Decoder_State_fx *stdec - ) +/*------------------------------------------------------------------- + * generate_comfort_noise_dec_hf() + * + * Generate the comfort noise based on the target noise level for the CLDFB part + *-------------------------------------------------------------------*/ + +void generate_comfort_noise_dec_hf( + float ** bufferReal, /* o : Real part of input bands */ + float ** bufferImag, /* o : Imaginary part of input bands */ + Decoder_State *stdec +) { - Word16 i, j, s, sc, sn; - Word16 scaleCLDFB; - Word32 sqrtNoiseLevel; - Word16 randGaussExp; - Word16 cngNoiseLevelExp; - Word16 *seed; - Word32 *cngNoiseLevel; - Word32 *ptr_level; - HANDLE_FD_CNG_COM st = stdec->hFdCngDec_fx->hFdCngCom; + short i,j; + float * ptr_level; + HANDLE_FD_CNG_COM st = stdec->hFdCngDec->hFdCngCom; + short * seed = &(st->seed); + float scale = CLDFB_SCALING / st->scalingFactor; - cngNoiseLevel = st->cngNoiseLevel+st->stopFFTbin-st->startBand; - cngNoiseLevelExp = st->cngNoiseLevelExp; - ptr_level = cngNoiseLevel; - seed = &(st->seed); - - /* scaleCLDFB: CLDFBinvScalingFactor_EXP + 1 */ - scaleCLDFB = mult(st->invScalingFactor,CLDFB_SCALING); - - sn = 0; - move16(); - IF ( s_and(cngNoiseLevelExp,1) != 0 ) + ptr_level=st->cngNoiseLevel+st->stopFFTbin-st->startBand; + /* + Generate Gaussian random noise in real and imaginary parts of the CLDFB bands + Amplitudes are adjusted to the estimated noise level cngNoiseLevel in each band + */ + if (st->numCoreBands < st->regularStopBand) { - sn = add(sn,1); - cngNoiseLevelExp = add(cngNoiseLevelExp,sn); - move16(); - } - - randGaussExp = CNG_RAND_GAUSS_SHIFT; - move16(); - - IF ( sub(st->numCoreBands,st->regularStopBand) < 0 ) - { - - sc = add(shr(add(cngNoiseLevelExp,CLDFBinvScalingFactor_EXP+1-1),1),randGaussExp); - move16(); - assert( ((cngNoiseLevelExp+CLDFBinvScalingFactor_EXP+1-1)&1) == 0); - - FOR (j=st->numCoreBands; jregularStopBand; j++) + for(j=st->numCoreBands ; jregularStopBand ; j++) { - /* scaleCLDFB: CLDFBinvScalingFactor_EXP + 1 */ - s = 0; - move16(); - sqrtNoiseLevel = Sqrt32(L_shr(Mpy_32_16_1(*ptr_level,scaleCLDFB),sn), &s); - - FOR (i=0; inumSlots; i++) + for(i=0 ; inumSlots ; i++) { /* Real part in CLDFB band */ - bufferReal[i][j] = L_shl(Mpy_32_32(rand_gauss(seed),sqrtNoiseLevel),s); - move32(); - /*fprintf(pFile,"%13.10f\n",WORD322FL_SCALE(bufferReal[i][j],sc));*/ - + rand_gauss(&bufferReal[i][j], seed); + bufferReal[i][j] *= (float)sqrt((scale **ptr_level)*0.5f); /* Imaginary part in CLDFB band */ - bufferImag[i][j] = L_shl(Mpy_32_32(rand_gauss(seed),sqrtNoiseLevel),s); - move32(); - /*fprintf(pFile,"%13.10f\n",WORD322FL_SCALE(bufferImag[i][j],sc));*/ + rand_gauss(&bufferImag[i][j], seed); + bufferImag[i][j] *= (float)sqrt((scale **ptr_level)*0.5f); } - ptr_level = ptr_level + 1; + ptr_level++; } - *bufferScale = sub(sc,15); - move16(); } + + return; } -/* - generate_masking_noise +/*------------------------------------------------------------------- + * generate_masking_noise() + * + * Generate additional comfort noise (kind of noise filling) + *-------------------------------------------------------------------*/ - Parameters: - - timeDomainBuffer i/o : pointer to time domain output buffer 15Q0 - st i/o : pointer to FD_CNG_COM structure - bitrate i : bitrate - - Function: - Generate additional comfort noise (kind of noise filling) - - Returns: none - - void -*/ -void generate_masking_noise (Word16 *timeDomainBuffer, /* i/o : pointer to time domain output buffer 15Q0 */ - Word16 Q, - HANDLE_FD_CNG_COM st /* i/o : pointer to FD_CNG_COM structure */ - ,Word16 length - ,Word16 core - ) +void generate_masking_noise( + float * timeDomainBuffer, /* i/o: time-domain signal */ + HANDLE_FD_CNG_COM st, /* i/o: FD_CNG structure containing all buffers and variables */ + short length, + short core +) { - Word16 i, s, s1, s2, sq, cnt, startBand2, stopFFTbin2; - Word16 scaleExp,fftBufferExp,cngNoiseLevelExp; - Word16 scale, scaleTableSize; - Word16 maskingNoise[L_FRAME16k]; - Word32 sqrtNoiseLevel; - Word32 *cngNoiseLevel; - Word32 *fftBuffer; - Word16 *seed; + float * cngNoiseLevel = st->cngNoiseLevel; + float * fftBuffer = st->fftBuffer; + short i; + float maskingNoise[L_FRAME16k]; + float * ptr_r; + float * ptr_i; + float * ptr_level = cngNoiseLevel; + int startBand = st->startBand; + short * seed = &(st->seed); + float scale = 1.f; + int scaleTableSize; - - - /* pointer initializations */ - cngNoiseLevel = st->cngNoiseLevel; - fftBuffer = st->fftBuffer; - seed = &(st->seed); - - /* Compute additional CN level */ - cngNoiseLevelExp = st->cngNoiseLevelExp; - move16(); - - IF(core!=AMR_WB_CORE) + /* skip noise generating if level is very low, to avoid problems with possibly running into denormals */ + if( st->likelihood_noisy_speech > DELTA_MASKING_NOISE ) { - scaleTableSize = 18; - move16(); - assert( scaleTableSize == (sizeof (scaleTable_cn_only) / sizeof (scaleTable_cn_only[0])) ); - scale = -1; - move16(); - FOR (i=0; i < scaleTableSize; i++) + if( core != AMR_WB_CORE ) { - test(); - test(); - IF ( ( sub(st->CngBandwidth,scaleTable_cn_only[i].bwmode) == 0 ) - && ( L_sub(st->CngBitrate,scaleTable_cn_only[i].bitrateFrom) >= 0 ) - && ( L_sub(st->CngBitrate,scaleTable_cn_only[i].bitrateTo) < 0 ) - ) + /* Compute additional CN level */ + scaleTableSize = sizeof (scaleTable_cn_only) / sizeof (scaleTable_cn_only[0]); + + for (i = 0 ; i < scaleTableSize ; i++) { - scale = scaleTable_cn_only[i].scale; - move16(); - BREAK; + if ( (st->CngBandwidth == scaleTable_cn_only[i].bwmode) && + (st->CngBitrate >= scaleTable_cn_only[i].bitrateFrom) && + (st->CngBitrate < scaleTable_cn_only[i].bitrateTo) ) + { + break; + } + } + + scale *= (float)pow( 10.f,-scaleTable_cn_only[i].scale/10.f ) - 1.f; + } + else + { + /* Compute additional CN level */ + scaleTableSize = sizeof (scaleTable_cn_only_amrwbio) / sizeof (scaleTable_cn_only_amrwbio[0]); + + for (i = 0 ; i < scaleTableSize ; i++) + { + if (st->CngBitrate >= scaleTable_cn_only_amrwbio[i][0]) + { + break; + } + } + + if(i= 0); - } - ELSE - { - scaleTableSize = 3; - move16(); - assert( scaleTableSize == (sizeof (scaleTable_cn_only_amrwbio) / sizeof (scaleTable_cn_only_amrwbio[0])) ); - scale = 0; - move16(); - FOR (i=0; i < scaleTableSize; i++) - { - IF ( L_sub(st->CngBitrate,scaleTable_cn_only_amrwbio[i][0]) >= 0 ) - { - scale = scaleTable_cn_only_amrwbio[i][1]; - move16(); - BREAK; - } - } - } + /* Exclude clean speech */ + scale *= st->likelihood_noisy_speech; - /* Exclude clean speech */ - - s1 = norm_s(scale); - s2 = norm_s(st->likelihood_noisy_speech); - - /* scaleTable_cn_only[i].scale is scaled by 1 bit */ - scaleExp = sub(1,add(s1,s2)); - scale = mult_r(shl(scale,s1),shl(st->likelihood_noisy_speech,s2)); - - { - /* add exponent of scale and cngNoiseLevel */ - fftBufferExp = add(scaleExp,cngNoiseLevelExp); - - /* even scalefactor needed for sqrt calculation */ - s = s_and(fftBufferExp,1); - fftBufferExp = add(fftBufferExp,s); - - /* sqrt calculation => shift exponent */ - fftBufferExp = shr(fftBufferExp,1); - - /* consider scaling of random noise */ - fftBufferExp = add(fftBufferExp,CNG_RAND_GAUSS_SHIFT); - - cnt = sub(st->stopFFTbin,st->startBand); /* Generate Gaussian random noise in real and imaginary parts of the FFT bins Amplitudes are adjusted to the estimated noise level cngNoiseLevel in each bin */ - IF ( st->startBand == 0 ) + if (startBand==0) { - /* random noise is scaled by CNG_RAND_GAUSS_SHIFT bits */ - - /* DC component in FFT */ - - /* -s => consider scalefactor adaptation for sqrt calculation */ - sq = sub(0,s); - sqrtNoiseLevel = Sqrt32(Mpy_32_16_1(*cngNoiseLevel,scale),&sq); - st->fftBuffer[0] = L_shl(Mpy_32_32(rand_gauss(seed),sqrtNoiseLevel),sq); - move32(); - st->fftBuffer[1] = 0; - move32(); - - fftBuffer = st->fftBuffer + 2; - cngNoiseLevel++; - - cnt = sub(cnt,1); + rand_gauss(&fftBuffer[0], seed); + ptr_r = fftBuffer + 2; + fftBuffer[0] *= (float)sqrt(scale **ptr_level ); /* DC component in FFT */ + ptr_level++; } - ELSE + else { - startBand2 = shl(st->startBand,1); - set32_fx(st->fftBuffer,0,startBand2); - fftBuffer = st->fftBuffer + startBand2; + fftBuffer[0] = 0.f; + set_f( fftBuffer+2, 0.0f, 2*(startBand-1) ); + ptr_r = fftBuffer + 2*startBand; + } + ptr_i = ptr_r + 1; + + for( ; ptr_level < cngNoiseLevel+st->stopFFTbin-startBand ; ptr_level++) + { + /* Real part in FFT bins */ + rand_gauss(ptr_r, seed); + (*ptr_r) *= (float)sqrt((scale **ptr_level )*0.5f); + ptr_r += 2; + /* Imaginary part in FFT bins */ + rand_gauss(ptr_i, seed); + (*ptr_i) *= (float)sqrt((scale **ptr_level )*0.5f); + ptr_i += 2; } - FOR (i=0; i weighting with 0.5, -s => consider scalefactor adaptation for sqrt calculation */ - sq = sub(-1,s); - sqrtNoiseLevel = Sqrt32(Mpy_32_16_1(*cngNoiseLevel,scale),&sq); + /* Remaining FFT bins are set to zero */ + set_f( fftBuffer+2*st->stopFFTbin, 0.0f, st->fftlen-2*st->stopFFTbin); + /* Nyquist frequency is discarded */ + fftBuffer[1] = 0.f; - /* real part in FFT bins */ + } + else + { + /* very low level case - update random seeds and reset FFT buffer; don't fully skip SynthesisSTFT(), because of the buffer updates done there... */ + generate_masking_noise_update_seed( st ); - /* random noise is scaled by CNG_RAND_GAUSS_SHIFT bits */ - *fftBuffer = L_shl(Mpy_32_32(rand_gauss(seed),sqrtNoiseLevel),sq); - move32(); - fftBuffer++; - - /* imaginary part in FFT bins */ - - /* random noise is scaled by CNG_RAND_GAUSS_SHIFT bits */ - *fftBuffer = L_shl(Mpy_32_32(rand_gauss(seed),sqrtNoiseLevel),sq); - move32(); - fftBuffer++; - - cngNoiseLevel++; - } - - /* remaining FFT bins are set to zero */ - stopFFTbin2 = shl(st->stopFFTbin,1); - set32_fx(st->fftBuffer+stopFFTbin2, 0, sub(st->fftlen,stopFFTbin2)); - - - /* perform STFT synthesis */ - assert(st->olapBufferSynth2 != NULL); - SynthesisSTFT(st->fftBuffer, fftBufferExp, maskingNoise, st->olapBufferSynth2, st->olapWinSyn, - 0, - st, 0, NULL); - - - /* add some comfort noise on top of decoded signal */ - IF ( st->frameSize > length ) - { - FOR (i=0; iframeSize; i++) - { - timeDomainBuffer[i] = add(timeDomainBuffer[i],shr_r(maskingNoise[i],-Q)); - move16(); - } - } + set_f( fftBuffer, 0.f, st->fftlen ); } + /* Perform STFT synthesis */ + SynthesisSTFT( fftBuffer, maskingNoise, st->olapBufferSynth2, st->olapWinSyn, 0, st ); + + /* Add some comfort noise on top of decoded signal */ + v_add(maskingNoise, timeDomainBuffer, timeDomainBuffer, min(st->frameSize,length)); + + return; } + /*------------------------------------------------------------------- * generate_masking_noise_update_seed() * @@ -1977,201 +1005,129 @@ void generate_masking_noise (Word16 *timeDomainBuffer, /* i/o : pointer to time * not called based on signal statistics *-------------------------------------------------------------------*/ -void generate_masking_noise_update_seed ( - HANDLE_FD_CNG_COM st /* i/o : pointer to FD_CNG_COM structure */ +void generate_masking_noise_update_seed( + HANDLE_FD_CNG_COM st /* i/o: FD_CNG structure containing all buffers and variables */ ) { - Word16 *seed; - Word16 cnt, i; - - /* pointer initializations */ - seed = &(st->seed); - - cnt = sub(st->stopFFTbin, st->startBand); - - IF ( st->startBand == 0 ) - { - rand_gauss(seed); - cnt = sub(cnt,1); - } - - FOR (i=0; icngNoiseLevel; - seed = &(st->seed); - - /* Compute additional CN level */ - cngNoiseLevelExp = st->cngNoiseLevelExp; - move16(); - - /* Compute additional CN level */ - scaleTableSize = 18; - move16(); - assert( scaleTableSize == (sizeof (scaleTable_cn_only) / sizeof (scaleTable_cn_only[0])) ); - - scale = -1; - move16(); - FOR (i=0; i < scaleTableSize; i++) - { - test(); - test(); - IF ( ( sub(st->CngBandwidth,scaleTable_cn_only[i].bwmode) == 0 ) - && ( L_sub(st->CngBitrate,scaleTable_cn_only[i].bitrateFrom) >= 0 ) - && ( L_sub(st->CngBitrate,scaleTable_cn_only[i].bitrateTo) < 0 ) - ) - { - scale = scaleTable_cn_only[i].scale; - move16(); - BREAK; - } - } - assert(scale >= 0); - - /* Exclude clean speech */ - s1 = norm_s(scale); - s2 = norm_s(st->likelihood_noisy_speech); - - /* scaleTable_cn_only[i].scale is scaled by 1 bit */ - scaleExp = sub(1,add(s1,s2)); - scale = mult_r(shl(scale,s1),shl(st->likelihood_noisy_speech,s2)); - - /* add exponent of scale and cngNoiseLevel */ - maskingNoiseExp = add(scaleExp,cngNoiseLevelExp); - - /* even scalefactor needed for sqrt calculation */ - s = s_and(maskingNoiseExp,1); - maskingNoiseExp = add(maskingNoiseExp,s); - - /* sqrt calculation => shift exponent */ - maskingNoiseExp = shr(maskingNoiseExp,1); - - /* consider scaling of random noise */ - maskingNoiseExp = add(maskingNoiseExp,CNG_RAND_GAUSS_SHIFT); - - cnt = sub(st->stopFFTbin,st->startBand); + float * cngNoiseLevel = st->cngNoiseLevel; + float * ptr_level = cngNoiseLevel; + int startBand = st->startBand; + short * seed = &(st->seed); + float tmp = 0; /* Generate Gaussian random noise in real and imaginary parts of the FFT bins Amplitudes are adjusted to the estimated noise level cngNoiseLevel in each bin */ - IF ( st->startBand == 0 ) + if (startBand==0) { - /* random noise is scaled by CNG_RAND_GAUSS_SHIFT bits */ - - /* DC component in FFT */ - - /* -1 => weighting with 0.5, -s => consider scalefactor adaptation for sqrt calculation */ - sq = sub(-1,s); - sqrtNoiseLevel = Sqrt32(Mpy_32_16_1(*cngNoiseLevel,scale),&sq); - maskingNoise[0] = L_shl(Mpy_32_32(rand_gauss(seed),sqrtNoiseLevel),sq); - move32(); - - pMaskingNoise = &maskingNoise[1]; - cngNoiseLevel++; - - cnt = sub(cnt,1); - } - ELSE - { - set32_fx(maskingNoise,0,st->startBand); - pMaskingNoise = maskingNoise + st->startBand; + rand_gauss(&tmp, seed); + ptr_level++; } - FOR (i=0; istopFFTbin-startBand ; ptr_level++) { - /* -1 => weighting with 0.5, -s => consider scalefactor adaptation for sqrt calculation */ - sq = sub(-1,s); - sqrtNoiseLevel = Sqrt32(Mpy_32_16_1(*cngNoiseLevel,scale),&sq); - - /* real part in FFT bins */ - - /* random noise is scaled by CNG_RAND_GAUSS_SHIFT bits */ - *pMaskingNoise = L_shl(Mpy_32_32(rand_gauss(seed),sqrtNoiseLevel),sq); - move32(); - pMaskingNoise++; - - cngNoiseLevel++; - } - - /* re-normalization of energy level - 16 * 0.79056941504 = sqrt(NORM_MDCT_FACTOR) - */ - assert( NORM_MDCT_FACTOR == 160 ); - - /* do weighting with factor 0.79056941504 later */ - maskingNoiseExp = add(maskingNoiseExp,4); - - s = s_max(*mdctBuffer_e,maskingNoiseExp); - s1 = sub(s,*mdctBuffer_e); - s2 = sub(s,maskingNoiseExp); - - /* avoid rescaling of mdct samples if no comfort noise is added */ - IF ( scale != 0 ) - { - /* Add some comfort noise on top of decoded signal */ - IF ( s1 == 0 ) - { - FOR (i=0; i < st->stopFFTbin; i++) - { - /* If shifting negative noise values the lowest result is -1 but never 0. - Shift positive noise values to avoid unwanted amplification of these small values later */ - noise = L_shr(Mpy_32_16_1(L_abs(maskingNoise[i]),25905/*0.79056941504 Q15*/),s2); - - if ( maskingNoise[i] < 0 ) - { - noise = L_negate(noise); - } - - mdctBuffer[i] = L_add(mdctBuffer[i], noise); - move32(); - } - } - ELSE - { - FOR (i=0; i < st->stopFFTbin; i++) - { - mdctBuffer[i] = L_add(L_shr(mdctBuffer[i],s1), - Mpy_32_16_1(maskingNoise[i],25905/*0.79056941504 Q15*/)); - move32(); - } - FOR (i=st->stopFFTbin; i < L_frame; i++) - { - mdctBuffer[i] = L_shr(mdctBuffer[i],s1); - move32(); - } - *mdctBuffer_e = s; - move16(); - } + /* Real part in FFT bins */ + rand_gauss(&tmp, seed); + rand_gauss(&tmp, seed); } + return; +} + + +/*------------------------------------------------------------------- + * generate_masking_noise_mdct() + * + * Generate additional comfort noise (kind of noise filling) + *-------------------------------------------------------------------*/ + +void generate_masking_noise_mdct( + float * mdctBuffer, /* i/o: time-domain signal */ + HANDLE_FD_CNG_COM st /* i/o: FD_CNG structure containing all buffers and variables */ +) +{ + + float * cngNoiseLevel = st->cngNoiseLevel; + short i; + float maskingNoise[2*L_FRAME16k]; + float * ptr_r; + + float * ptr_level = cngNoiseLevel; + int startBand = st->startBand; + short * seed = &(st->seed); + float scale = 1.f; + int scaleTableSize; + + /* skip noise generating if level is very low, to avoid problems with possibly running into denormals */ + if( st->likelihood_noisy_speech > DELTA_MASKING_NOISE ) + { + + /* Compute additional CN level */ + scaleTableSize = sizeof (scaleTable_cn_only) / sizeof (scaleTable_cn_only[0]); + + for (i = 0 ; i < scaleTableSize ; i++) + { + if ( (st->CngBandwidth == scaleTable_cn_only[i].bwmode) && + (st->CngBitrate >= scaleTable_cn_only[i].bitrateFrom) && + (st->CngBitrate < scaleTable_cn_only[i].bitrateTo) ) + { + break; + } + } + + scale *= (float)pow( 10.f,-scaleTable_cn_only[i].scale/10.f ) - 1.f; + + /* Exclude clean speech */ + scale *= st->likelihood_noisy_speech; + + /* + Generate Gaussian random noise in real and imaginary parts of the FFT bins + Amplitudes are adjusted to the estimated noise level cngNoiseLevel in each bin + */ + if (startBand==0) + { + rand_gauss(&maskingNoise[0], seed); + maskingNoise[0] *= (float)sqrt(scale **ptr_level * 0.5f ); /* DC component in FFT */ + ptr_level++; + ptr_r = maskingNoise + 1; + } + else + { + maskingNoise[0] = 0.f; + set_f( maskingNoise+1, 0.0f, (startBand-1) ); + ptr_r = maskingNoise + startBand; + } + + for( ; ptr_level < cngNoiseLevel+st->stopFFTbin-startBand ; ptr_level++) + { + /* MDCT bins */ + rand_gauss(ptr_r, seed); + (*ptr_r) *= (float)sqrt(scale **ptr_level * 0.5f ); + ptr_r += 1; + } + + /*re-normalization of energy level: M/sqrt(2)*/ + v_multc(maskingNoise, (float)sqrt(NORM_MDCT_FACTOR), maskingNoise, st->stopFFTbin); + + /* Add some comfort noise on top of decoded signal */ + v_add(maskingNoise, mdctBuffer, mdctBuffer, st->stopFFTbin); + + } + else + { + /* very low level case - just update random seeds */ + if ( startBand == 0 ) + { + rand_gauss(&maskingNoise[0], seed); + ptr_level++; + } + + for( ; ptr_level < cngNoiseLevel+st->stopFFTbin-startBand ; ptr_level++ ) + { + rand_gauss(&maskingNoise[0], seed); + } + } + + return; } diff --git a/src/libs/libevs/lib_dec/gain_dec.cpp b/src/libs/libevs/lib_dec/gain_dec.cpp new file mode 100644 index 00000000..7c6c3cac --- /dev/null +++ b/src/libs/libevs/lib_dec/gain_dec.cpp @@ -0,0 +1,652 @@ +/*==================================================================================== + EVS Codec 3GPP TS26.443 Nov 13, 2018. Version 12.11.0 / 13.7.0 / 14.3.0 / 15.1.0 + ====================================================================================*/ + +#include +#include "options.h" +#include "cnst.h" +#include "rom_com.h" +#include "prot.h" + + +/*---------------------------------------------------------------------* + * Es_pred_dec() + * + * Decoding of scaled predicted innovation energy to be used in all subframes + *---------------------------------------------------------------------*/ + +void Es_pred_dec( + float *Es_pred, /* o : predicited scaled innovation energy */ + const int enr_idx, /* i : indice */ + const short nb_bits, /* i : number of bits */ + const short no_ltp /* i : no LTP flag */ +) +{ + if( !no_ltp ) + { + switch ( nb_bits ) + { + case 5: + *Es_pred = Es_pred_qua_5b[enr_idx]; + break; + case 4: + *Es_pred = Es_pred_qua_4b[enr_idx]; + break; + case 3: + *Es_pred = Es_pred_qua_3b[enr_idx]; + break; + default: + *Es_pred = Es_pred_qua_5b[enr_idx]; + break; + } + } + else + { + *Es_pred = Es_pred_qua_4b_no_ltp[enr_idx]; + } + + return; +} + + +/*--------------------------------------------------------------------------* + * lp_gain_updt() + * + * Update of LP pitch and code gains (FEC) + *-------------------------------------------------------------------------*/ + +void lp_gain_updt( + const short i_subfr, /* i : subframe number */ + const float gain_pit, /* i : Decoded gain pitch */ + const float norm_gain_code, /* i : Normalised gain code */ + float *lp_gainp, /* i/o: LP-filtered pitch gain(FEC) */ + float *lp_gainc, /* i/o: LP-filtered code gain (FEC) */ + const short L_frame /* i : length of the frame */ +) +{ + if( L_frame == L_FRAME ) + { + if( i_subfr == 0 ) + { + *lp_gainp = 0.1f * gain_pit; + *lp_gainc = 0.1f * norm_gain_code; + } + else if( i_subfr == L_SUBFR ) + { + *lp_gainp += 0.2f * gain_pit; + *lp_gainc += 0.2f * norm_gain_code; + } + else if( i_subfr == 2*L_SUBFR ) + { + *lp_gainp += 0.3f * gain_pit; + *lp_gainc += 0.3f * norm_gain_code; + } + else /* i_subfr == 3*L_SUBFR */ + { + *lp_gainp += 0.4f * gain_pit; + *lp_gainc += 0.4f * norm_gain_code; + } + } + else + { + if( i_subfr == 0 ) + { + *lp_gainp = (1.0f/15.0f) * gain_pit; + *lp_gainc = (1.0f/15.0f) * norm_gain_code; + } + else if( i_subfr == L_SUBFR ) + { + *lp_gainp += (2.0f/15.0f) * gain_pit; + *lp_gainc += (2.0f/15.0f) * norm_gain_code; + } + else if( i_subfr == 2*L_SUBFR ) + { + *lp_gainp += (3.0f/15.0f) * gain_pit; + *lp_gainc += (3.0f/15.0f) * norm_gain_code; + } + else if( i_subfr == 3*L_SUBFR ) + { + *lp_gainp += (4.0f/15.0f) * gain_pit; + *lp_gainc += (4.0f/15.0f) * norm_gain_code; + } + else /* i_subfr == 4*L_SUBFR */ + { + *lp_gainp += (5.0f/15.0f) * gain_pit; + *lp_gainc += (5.0f/15.0f) * norm_gain_code; + } + } + + return; +} + + +/*---------------------------------------------------------------------* + * gain_dec_tc() + * + * Decoding of pitch and codebook gains and updating long term energies + *---------------------------------------------------------------------*/ + +void gain_dec_tc( + Decoder_State *st, /* i/o: decoder state structure */ + const long core_brate, /* i : core bitrate */ + const short L_frame, /* i : length of the frame */ + const short i_subfr, /* i : subframe number */ + const short tc_subfr, /* i : TC subframe index */ + const float Es_pred, /* i : predicted scaled innov. energy */ + const float *code, /* i : algebraic code excitation */ + float *gain_pit, /* o : pitch gain */ + float *gain_code, /* o : Quantized codeebook gain */ + float *gain_inov, /* o : unscaled innovation gain */ + float *norm_gain_code /* o : norm. gain of the codebook excit. */ +) +{ + short index, nBits; + float Ecode, gcode0; + float Ei; + + *gain_pit = 0; + + /*----------------------------------------------------------------* + * find number of bits for gain dequantization + *----------------------------------------------------------------*/ + + if( L_frame == L_FRAME ) + { + nBits = gain_bits_tbl[BIT_ALLOC_IDX(core_brate, TRANSITION, i_subfr, TC_SUBFR2IDX(tc_subfr))]; + } + else /* L_frame == L_FRAME16k */ + { + nBits = gain_bits_16kHz_tbl[BIT_ALLOC_IDX_16KHZ(core_brate, TRANSITION, i_subfr, TC_SUBFR2IDX_16KHZ(tc_subfr))]; + } + + /*-----------------------------------------------------------------* + * calculate the predicted gain code + *-----------------------------------------------------------------*/ + + Ecode = (dotp( code, code, L_SUBFR) + 0.01f) / L_SUBFR; + *gain_inov = 1.0f / (float)sqrt( Ecode ); + Ei = 10 * (float)log10( Ecode ); + gcode0 = (float) pow(10, 0.05 * (Es_pred - Ei)); + + /*------------------------------------------------------------------------------------------* + * Select the gain quantization table and dequantize the gain + *------------------------------------------------------------------------------------------*/ + + index = (short)get_next_indice( st, nBits ); + + if( nBits > 3 ) + { + *gain_code = gain_dequant( index, G_CODE_MIN, G_CODE_MAX, nBits ); + } + else /* nBits == 3 */ + { + *gain_code = tbl_gain_code_tc[index]; + } + + /*-----------------------------------------------------------------* + * decode normalized codebook gain + *-----------------------------------------------------------------*/ + + *gain_code *= gcode0; + *norm_gain_code = *gain_code / *gain_inov; + + return; +} + +/*---------------------------------------------------------------------* + * gain_dec_amr_wb() + * + * Decoding of pitch and fixed codebook gains (used also in AMR-WB IO mode) + *---------------------------------------------------------------------*/ + +void gain_dec_amr_wb( + Decoder_State *st, /* i/o: decoder state structure */ + const long core_brate, /* i : core bitrate */ + float *gain_pit, /* o : Quantized pitch gain */ + float *gain_code, /* o : Quantized codeebook gain */ + float *past_qua_en, /* i/o: gain quantization memory (4 words) */ + float *gain_inov, /* o : unscaled innovation gain */ + const float *code, /* i : algebraic code excitation */ + float *norm_gain_code /* o : norm. gain of the codebook excitation */ +) +{ + short i, index; + short nbits; + float gcode0, qua_en; + const float *t_qua_gain; + + *gain_inov = 1.0f/ (float)sqrt( ( dotp( code, code, L_SUBFR ) + 0.01f ) / L_SUBFR ); + + /*-----------------------------------------------------------------* + * Select the gain quantization table + *-----------------------------------------------------------------*/ + + if( core_brate < ACELP_12k65) + { + nbits = 6; + t_qua_gain = t_qua_gain6b; + } + else + { + nbits = 7; + t_qua_gain = t_qua_gain7b; + } + + /*-----------------------------------------------------------------* + * predicted code gain + *-----------------------------------------------------------------*/ + + /* start with predicting code energy in dB */ + gcode0 = MEAN_ENER; + for (i=0; i0; i--) + { + past_qua_en[i] = past_qua_en[i-1]; + } + past_qua_en[0] = (float)(20.0*log10(qua_en)); + + /*-----------------------------------------------------------------* + * Normalized code gain + *-----------------------------------------------------------------*/ + + *norm_gain_code = *gain_code / *gain_inov; + + return; +} + +/*--------------------------------------------------------------------------* + * gain_dec_mless() + * + * Decoding of pitch and codebook gains without updating long term energies + *-------------------------------------------------------------------------*/ + +void gain_dec_mless( + Decoder_State *st, /* i/o: decoder state structure */ + const long core_brate, /* i : core bitrate */ + const short L_frame, /* i : length of the frame */ + const short coder_type, /* i : coding type */ + const short i_subfr, /* i : subframe number */ + const short tc_subfr, /* i : TC subframe index */ + const float *code, /* i : algebraic code excitation */ + const float Es_pred, /* i : predicted scaled innov. energy */ + float *gain_pit, /* o : Quantized pitch gain */ + float *gain_code, /* o : Quantized codeebook gain */ + float *gain_inov, /* o : unscaled innovation gain */ + float *norm_gain_code /* o : norm. gain of the codebook excitation */ +) +{ + short index, nBits; + float gcode0, Ei, Ecode; + const float *qua_table; + + /*-----------------------------------------------------------------* + * decode pitch gain + *-----------------------------------------------------------------*/ + + if( L_frame == L_FRAME ) + { + nBits = gain_bits_tbl[BIT_ALLOC_IDX(core_brate, coder_type, i_subfr, TC_SUBFR2IDX(tc_subfr))]; + } + else /* L_frame == L_FRAME16k */ + { + nBits = gain_bits_16kHz_tbl[BIT_ALLOC_IDX_16KHZ(core_brate, coder_type, i_subfr, TC_SUBFR2IDX_16KHZ(tc_subfr))]; + } + + if( (tc_subfr == 3*L_SUBFR && i_subfr == 3*L_SUBFR && L_frame == L_FRAME) || + (tc_subfr == 4*L_SUBFR && i_subfr == 4*L_SUBFR && L_frame == L_FRAME16k) ) + { + /* decode pitch gain */ + index = (short)get_next_indice( st, nBits >> 1 ); + Ei = (G_PITCH_MAX_TC192 - G_PITCH_MIN_TC192) / ((1 << (nBits >> 1)) - 1); /* set quantization step */ + *gain_pit = usdequant( index, G_PITCH_MIN_TC192, Ei ); + + /* calculate the predicted gain code */ + Ecode = (dotp( code, code, L_SUBFR) + 0.01f) / L_SUBFR; + *gain_inov = 1.0f / (float)sqrt( Ecode ); + Ei = 10 * (float)log10( Ecode ); + gcode0 = (float) pow(10, 0.05 * (Es_pred - Ei)); + + /* decode normalized codebook gain */ + index = (short)get_next_indice( st, (nBits+1)>>1 ); + *gain_code = gain_dequant( index, G_CODE_MIN_TC192, G_CODE_MAX_TC192, (nBits+1)>>1 ); + *gain_code *= gcode0; + } + else + { + switch ( nBits ) + { + case 7: + { + qua_table = gain_qua_mless_7b; + break; + } + case 6: + { + qua_table = gain_qua_mless_6b; + break; + } + case 5: + { + qua_table = gain_qua_mless_5b; + break; + } + default: + { + qua_table = gain_qua_mless_6b; + break; + } + } + + if( coder_type == INACTIVE && nBits == 6 ) + { + nBits--; + } + + index = (short)get_next_indice( st, nBits ); + + *gain_pit = qua_table[index * 2]; + Ecode = (dotp( code, code, L_SUBFR) + 0.01f) / L_SUBFR; + *gain_inov = 1.0f / (float)sqrt( Ecode ); + Ei = 10 * (float)log10( Ecode ); + + /*-----------------------------------------------------------------* + * calculate the predicted gain code + *-----------------------------------------------------------------*/ + + gcode0 = (float) pow(10, 0.05 * (Es_pred - Ei)); + + /*-----------------------------------------------------------------* + * decode normalized codebook gain + *-----------------------------------------------------------------*/ + + *gain_code = qua_table[index * 2 + 1] * gcode0; + } + + *norm_gain_code = *gain_code / *gain_inov; + + return; +} + +/*--------------------------------------------------------------------------* + * gain_dec_lbr() + * + * Decoding of pitch and codebook gains in ACELP at 6.6 and 7.5 kbps + *-------------------------------------------------------------------------*/ + +void gain_dec_lbr( + Decoder_State *st, /* i/o: decoder state structure */ + const long core_brate, /* i : core bitrate */ + const short coder_type, /* i : coding type */ + const short i_subfr, /* i : subframe index */ + const float *code, /* i : algebraic excitation */ + float *gain_pit, /* o : quantized pitch gain */ + float *gain_code, /* o : quantized codebook gain */ + float *gain_inov, /* o : gain of the innovation (used for normalization) */ + float *norm_gain_code, /* o : norm. gain of the codebook excitation */ + float gains_mem[] /* i/o: pitch gain and code gain from previous subframes */ +) +{ + short index, nBits, n_pred, ctype; + float gcode0, aux[10], Ecode; + const float *b, *cdbk = 0; + + Ecode = ( dotp( code, code, L_SUBFR ) + 0.01f ) / L_SUBFR; + *gain_inov = 1.0f / (float)sqrt(Ecode); + + /*-----------------------------------------------------------------* + * select the codebook, size and number of bits + * set the gains searching range + *-----------------------------------------------------------------*/ + + nBits = gain_bits_tbl[BIT_ALLOC_IDX(core_brate, coder_type, i_subfr, 0)]; + ctype = 2*(coder_type - 1); + + /*-----------------------------------------------------------------* + * calculate prediction of gcode + * search for the best codeword + *-----------------------------------------------------------------*/ + + if (i_subfr == 0) + { + b = b_1sfr; + n_pred = 2; + + switch ( nBits ) + { + case 8: + { + cdbk = gp_gamma_1sfr_8b; + break; + } + case 7: + { + cdbk = gp_gamma_1sfr_7b; + break; + } + case 6: + { + cdbk = gp_gamma_1sfr_6b; + break; + } + } + + /* calculate predicted gain */ + aux[0] = 1.0f; + aux[1] = ctype; + gcode0 = (float)pow(10, dotp(b, aux, n_pred) - 0.5f * (float)log10(Ecode)); + + /* retrieve the codebook index and calculate both gains */ + index = (short)get_next_indice( st, nBits ); + *gain_pit = cdbk[index * 2]; + *gain_code = cdbk[index * 2 + 1] * gcode0; + gains_mem[0] = *gain_code; + gains_mem[3] = *gain_pit; + } + else if (i_subfr == L_SUBFR) + { + b = b_2sfr; + n_pred = 4; + + switch ( nBits ) + { + case 7: + { + cdbk = gp_gamma_2sfr_7b; + break; + } + case 6: + { + cdbk = gp_gamma_2sfr_6b; + break; + } + } + + /* calculate predicted gain */ + aux[0] = 1.0f; + aux[1] = ctype; + aux[2] = (float)log10(gains_mem[0]); + aux[3] = gains_mem[3]; + gcode0 = (float)pow(10, dotp(b, aux, n_pred)); + + /* retrieve the codebook index and calculate both gains */ + index = (short)get_next_indice( st, nBits ); + *gain_pit = cdbk[index * 2]; + *gain_code = cdbk[index * 2 + 1] * gcode0; + gains_mem[1] = *gain_code; + gains_mem[4] = *gain_pit; + } + else if (i_subfr == 2*L_SUBFR) + { + b = b_3sfr; + n_pred = 6; + + cdbk = gp_gamma_3sfr_6b; + + /* calculate predicted gain */ + aux[0] = 1.0f; + aux[1] = ctype; + aux[2] = (float)log10(gains_mem[0]); + aux[3] = (float)log10(gains_mem[1]); + aux[4] = gains_mem[3]; + aux[5] = gains_mem[4]; + gcode0 = (float)pow(10, dotp(b, aux, n_pred)); + + /* retrieve the codebook index and calculate both gains */ + index = (short)get_next_indice( st, nBits ); + *gain_pit = cdbk[index * 2]; + *gain_code = cdbk[index * 2 + 1] * gcode0; + + gains_mem[2] = *gain_code; + gains_mem[5] = *gain_pit; + } + else if (i_subfr == 3*L_SUBFR) + { + b = b_4sfr; + n_pred = 8; + + cdbk = gp_gamma_4sfr_6b; + + /* calculate predicted gain */ + aux[0] = 1.0f; + aux[1] = ctype; + aux[2] = (float)log10(gains_mem[0]); + aux[3] = (float)log10(gains_mem[1]); + aux[4] = (float)log10(gains_mem[2]); + aux[5] = gains_mem[3]; + aux[6] = gains_mem[4]; + aux[7] = gains_mem[5]; + gcode0 = (float)pow(10, dotp(b, aux, n_pred)); + + /* retrieve the codebook index and calculate both gains */ + index = (short)get_next_indice( st, nBits ); + *gain_pit = cdbk[index * 2]; + *gain_code = cdbk[index * 2 + 1] * gcode0; + } + + *norm_gain_code = *gain_code / *gain_inov; + + return; +} + +/*--------------------------------------------------------------------------* + * gain_dec_SQ() + * + * Decoding of pitch and codebook gains using scalar quantizers + *-------------------------------------------------------------------------*/ + +void gain_dec_SQ( + Decoder_State *st, /* i/o: decoder state structure */ + const long core_brate, /* i : core bitrate */ + const short coder_type, /* i : coding type */ + const short i_subfr, /* i : subframe number */ + const short tc_subfr, /* i : TC subframe index */ + const float *code, /* i : algebraic code excitation */ + const float Es_pred, /* i : predicted scaled innov. energy */ + float *gain_pit, /* o : Quantized pitch gain */ + float *gain_code, /* o : Quantized codeebook gain */ + float *gain_inov, /* o : unscaled innovation gain */ + float *norm_gain_code /* o : norm. gain of the codebook excitation */ +) +{ + short index, nBits; + float gcode0, Ei, Ecode; + short tmp16; + /*-----------------------------------------------------------------* + * get number of bits + *-----------------------------------------------------------------*/ + + nBits = gain_bits_16kHz_tbl[ BIT_ALLOC_IDX_16KHZ(core_brate, coder_type, i_subfr, TC_SUBFR2IDX_16KHZ(tc_subfr)) ]; + + /*-----------------------------------------------------------------* + * decode pitch gain + *-----------------------------------------------------------------*/ + + index = (short)get_next_indice( st, nBits>>1 ); + /*Ei = (G_PITCH_MAX - G_PITCH_MIN) / ((1 << (nBits>>1)) - 1);*/ /* set quantization step */ + tmp16 = div_s(1,((1 << (nBits>>1)) - 1) ); /* Q15*/ + Ei = (float)mult_r((short)(G_PITCH_MAX*8192.0f+0.5f),tmp16)/8192.0f; + + *gain_pit = usdequant( index, G_PITCH_MIN, Ei ); + + /*-----------------------------------------------------------------* + * calculate the predicted gain code + *-----------------------------------------------------------------*/ + + Ecode = (dotp( code, code, L_SUBFR) + 0.01f) / L_SUBFR; + *gain_inov = 1.0f / (float)sqrt( Ecode ); + Ei = 10 * (float)log10( Ecode ); + gcode0 = (float) pow(10, 0.05 * (Es_pred - Ei)); + + /*-----------------------------------------------------------------* + * decode normalized codebook gain + *-----------------------------------------------------------------*/ + + index = (short)get_next_indice( st, (nBits+1)>>1 ); + *gain_code = gain_dequant( index, G_CODE_MIN, G_CODE_MAX, (nBits+1)>>1 ); + *gain_code *= gcode0; + *norm_gain_code = *gain_code / *gain_inov; + + return; +} + + +/*-------------------------------------------------* + * gain_dec_gaus() + * + * Decoding of gains for Gaussian codebook + *-------------------------------------------------*/ + +float gain_dec_gaus( /* o : quantized codebook gain */ + const short index, /* i : quantization index */ + const short bits, /* i : number of bits to quantize */ + const float lowBound, /* i : lower bound of quantizer (dB) */ + const float topBound, /* i : upper bound of quantizer (dB) */ + const float gain_inov, /* i : unscaled innovation gain */ + float *norm_gain_code /* o : gain of normalized gaus. excit. */ +) +{ + float gain, enr, stepSize; + + /*-----------------------------------------------------------------* + * quantize linearly the log E + *-----------------------------------------------------------------*/ + + stepSize = (topBound - lowBound)/((float)(1< Q26 */ - L_tmp = L_shr(L_tmp, 10); /* From Q26 to Q16 */ - frac = L_Extract_lc(L_tmp, &exp_gcode0); /* Extract exponent of gcode0 */ - gcode0_fx = extract_l(Pow2(14, frac));/* Put 14 as exponent so that */ - /* output of Pow2() will be: */ - /* 16384 < Pow2() <= 32767 */ - exp_gcode0 = sub(exp_gcode0, 14); - /*------------------------------------------------------------------------------------------* - * Select the gain quantization table and dequantize the gain - *------------------------------------------------------------------------------------------*/ - - /* index = (Word16)get_indice( st_fx,"gain_code", i_subfr_fx, ACELP_CORE);move16();*/ - index = (Word16)get_next_indice_fx( st_fx, nBits ); - move16(); - - - IF( sub(nBits,3) > 0 ) - { - wgain_code = gain_dequant_fx( index, G_CODE_MIN_TC_Q15, G_CODE_MAX_TC_Q0, nBits, &expg ); - wgain_code = shl(wgain_code,add(expg,13)); /* wgain_code in Q13*/ - } - ELSE /* nBits == 3 */ - { - wgain_code = tbl_gain_code_tc_fx[index]; - move16(); - } - - /*-----------------------------------------------------------------* - * decode normalized codebook gain - *-----------------------------------------------------------------*/ - - /* *gain_code *= gcode0;*/ - L_tmp = L_mult(wgain_code, gcode0_fx); /* Q13*Q0 -> Q14 */ - *gain_code_fx= L_shl(L_tmp, add(exp_gcode0, 2)); - move32(); /* Q14 -> Q16 */ - - /**norm_gain_code = *gain_code / *gain_inov;*/ - expg = sub(norm_s(*gain_inov_fx),1); - expg = s_max(expg, 0); - - tmp_fx = div_s(shr(8192,expg),*gain_inov_fx); - *norm_gain_code_fx = L_shr(Mult_32_16(*gain_code_fx, tmp_fx),sub(1,expg)); - move32(); - - return; -} -/*======================================================================================*/ -/* FUNCTION : gain_dec_mless_fx() */ -/*--------------------------------------------------------------------------------------*/ -/* PURPOSE : Decoding of pitch and codebook gains without updating long term energies */ -/*--------------------------------------------------------------------------------------*/ -/* INPUT ARGUMENTS : */ -/* _ (Word32) core_brate_fx : core bitrate */ -/* _ (Word16) L_frame_fx : length of the frame */ -/* _ (Word16) coder_type_fx : coding type */ -/* _ (Word16) i_subfr_fx : subframe index */ -/* _ (Word16) tc_subfr_fx : TC subframe index */ -/* _ (Word16*[]) code_fx : algebraic code excitation (Q12) */ -/* _ (Word16) Es_pred_fx : predicted scaled innov. energy (Q8) */ -/*--------------------------------------------------------------------------------------*/ -/* OUTPUT ARGUMENTS : */ -/* _ (Word16*) gain_pit_fx : quantized pitch gain (Q14) */ -/* _ (Word32*) gain_code_fx : quantized codebook gain (Q16) */ -/* _ (Word16*) gain_inov_fx : gain of the innovation (used for normalization) (Q12) */ -/* _ (Word32*) norm_gain_code_fx : norm. gain of the codebook excitation (Q16) */ -/*--------------------------------------------------------------------------------------*/ -/* INPUT/OUTPUT ARGUMENTS : */ -/* _ None */ -/*--------------------------------------------------------------------------------------*/ - -/* _ None */ -/*--------------------------------------------------------------------------------------*/ -/* RETURN ARGUMENTS : */ -/* _ None */ -/*======================================================================================*/ -void gain_dec_mless_fx( - Decoder_State_fx *st_fx, /* i/o: decoder state structure */ - const Word32 core_brate_fx, /* i : core bitrate */ - const Word16 L_frame_fx, /* i : length of the frame */ - const Word16 coder_type_fx, /* i : coding type */ - const Word16 i_subfr_fx, /* i : subframe number */ - const Word16 tc_subfr_fx, /* i : TC subframe index */ - const Word16 *code_fx, /* i : algebraic code excitation */ - const Word16 Es_pred_fx, /* i : predicted scaled innov. energy */ - Word16 *gain_pit_fx, /* o : Quantized pitch gain Q14*/ - Word32 *gain_code_fx, /* o : Quantized codeebook gain Q16*/ - Word16 *gain_inov_fx, /* o : unscaled innovation gain Q12*/ - Word32 *norm_gain_code_fx /* o : norm. gain of the codebook excitation Q16*/ -) -{ - Word16 index, nBits; - Word16 gcode0_fx, Ei_fx, gain_code16; - const Word16 *qua_table_fx; - Word16 expg, expg2, e_tmp, f_tmp, exp_gcode0, tmp_fx, frac; - Word32 L_tmp, L_tmp1; - - /*-----------------------------------------------------------------* - * decode pitch gain - *-----------------------------------------------------------------*/ - IF( sub(L_frame_fx,L_FRAME) == 0) - { - nBits = gain_bits_tbl[BIT_ALLOC_IDX_fx(core_brate_fx, coder_type_fx, i_subfr_fx, TC_SUBFR2IDX_fx(tc_subfr_fx))]; - move16(); - } - ELSE /* L_frame == L_FRAME16k */ - { - nBits = gain_bits_16kHz_tbl[BIT_ALLOC_IDX_16KHZ_fx(core_brate_fx, coder_type_fx, i_subfr_fx, TC_SUBFR2IDX_16KHZ_fx(tc_subfr_fx))]; - move16(); - } - test(); - test(); - test(); - test(); - test(); - IF( (sub(tc_subfr_fx,3*L_SUBFR ) == 0 && sub(i_subfr_fx,3*L_SUBFR) == 0 && sub(L_frame_fx,L_FRAME) == 0) || - (sub(tc_subfr_fx,4*L_SUBFR ) == 0 && sub(i_subfr_fx,4*L_SUBFR) == 0 && sub(L_frame_fx,L_FRAME16k) == 0) ) - { - /* decode pitch gain */ - index = (Word16)get_next_indice_fx( st_fx, shr(nBits,1) ); - move16(); - - /*Ei = (G_PITCH_MAX_TC192 - G_PITCH_MIN_TC192) / ((1 << (nBits>>1)) - 1);*/ /* set quantization step */ - tmp_fx = div_s(1,sub(shl(1,shr(nBits,1)),1)); /*Q15*/ - Ei_fx = mult_r(G_PITCH_MAX_MINUS_MIN_TC192_Q13,tmp_fx); /*Q13*/ - - /**gain_pit = usdequant( index, G_PITCH_MIN_TC192, Ei );*/ - *gain_pit_fx = usdequant_fx( index, G_PITCH_MIN_TC192_Q14, Ei_fx ); - move16(); /*Q14*/ - - /* calculate the predicted gain code */ - /*Ecode = (dotp( code, code, L_SUBFR) + 0.01f) / L_SUBFR; - *gain_inov = 1.0f / (float)sqrt( Ecode );*/ - L_tmp = Dot_product12(code_fx, code_fx, L_SUBFR, &expg); - expg = sub(expg, 18 + 6); /* exp: -18 (code in Q12), -6 (/L_SUBFR) */ - expg2 = expg; - move16(); - L_tmp1 = L_add(0,L_tmp); /* sets to 'L_tmp' in 1 clock */ - L_tmp = Isqrt_lc(L_tmp, &expg); - - *gain_inov_fx = extract_h(L_shl(L_tmp, sub(expg, 3))); /* gain_inov in Q12 */ - - /*Ei = 10 * (float)log10( Ecode );*/ - e_tmp = norm_l(L_tmp1); - f_tmp = Log2_norm_lc(L_shl(L_tmp1, e_tmp)); - e_tmp = sub(expg2,add(1,e_tmp)); - L_tmp1 = Mpy_32_16(e_tmp, f_tmp, 12330); /* Q13 */ /* 10*log10(2) in Q12*/ - Ei_fx = round_fx(L_shl(L_tmp1, 11)); /* Q8 */ - - /*-----------------------------------------------------------------* - * calculate the predicted gain code - *-----------------------------------------------------------------*/ - - /*gcode0 = (float) pow(10, 0.05 * (Es_pred - Ei));*/ - gcode0_fx = sub(Es_pred_fx, Ei_fx); /* Q8 */ - - /*-----------------------------------------------------------------* - * gcode0 = pow(10.0, gcode0/20) - * = pow(2, 3.321928*gcode0/20) - * = pow(2, 0.166096*gcode0) - *-----------------------------------------------------------------*/ - L_tmp = L_mult(gcode0_fx, 21771); /* *0.166096 in Q17 -> Q26 */ - L_tmp = L_shr(L_tmp, 10); /* From Q26 to Q16 */ - frac = L_Extract_lc(L_tmp, &exp_gcode0); /* Extract exponent of gcode0 */ - - gcode0_fx = extract_l(Pow2(14, frac));/* Put 14 as exponent so that */ - /* output of Pow2() will be: */ - /* 16384 < Pow2() <= 32767 */ - exp_gcode0 = sub(exp_gcode0, 14); - - /* decode normalized codebook gain */ - /*index = (short)get_indice( st_fx, "gain_code", i_subfr_fx, ACELP_CORE );move16();*/ - index = (Word16)get_next_indice_fx( st_fx, shr(add(nBits,1),1) ); - move16(); - - /**gain_code = gain_dequant( index, G_CODE_MIN_TC192, G_CODE_MAX_TC192, (nBits+1)>>1 );*/ - gain_code16 = gain_dequant_fx( index, G_CODE_MIN_TC192_Q15, G_CODE_MAX_TC192_Q0, shr(add(nBits,1),1), &expg ); - move16(); - - /**gain_code *= gcode0;*/ - L_tmp = L_mult(gain_code16,gcode0_fx); /*Q0*Q0 -> Q1*/ - *gain_code_fx = L_shl(L_tmp,add(add(expg,exp_gcode0),15)); - move32(); /*Q16*/ - } - ELSE - { - SWITCH ( nBits ) - { - case 7: - { - qua_table_fx = gain_qua_mless_7b_fx; - move16(); - BREAK; - } - case 6: - { - qua_table_fx = gain_qua_mless_6b_fx; - move16(); - BREAK; - } - case 5: - { - qua_table_fx = gain_qua_mless_5b_fx; - move16(); - BREAK; - } - default: - { - qua_table_fx = gain_qua_mless_6b_fx; - move16(); - BREAK; - } - } - - test(); - if( sub(coder_type_fx,INACTIVE) == 0&& sub(nBits,6) == 0 ) - { - nBits = sub(nBits, 1); - } - - index = (Word16)get_next_indice_fx( st_fx, nBits ); - move16(); - - *gain_pit_fx = qua_table_fx[index * 2]; - move16(); - - /*Ecode = (dotp( code, code, L_SUBFR) + 0.01f) / L_SUBFR; - *gain_inov = 1.0f / (float)sqrt( Ecode );*/ - - L_tmp = Dot_product12(code_fx, code_fx, L_SUBFR, &expg); - expg = sub(expg, 18 + 6); /* exp: -18 (code in Q9), -6 (/L_SUBFR) */ - expg2 = expg; - move16(); - L_tmp1 = L_add(0,L_tmp); /* sets to 'L_tmp' in 1 clock */ - L_tmp = Isqrt_lc(L_tmp, &expg); - - *gain_inov_fx = extract_h(L_shl(L_tmp, sub(expg, 3))); /* gain_inov in Q12 */ - - /*Ei = 10 * (float)log10( Ecode );*/ - e_tmp = norm_l(L_tmp1); - f_tmp = Log2_norm_lc(L_shl(L_tmp1, e_tmp)); - e_tmp = sub(expg2,add(1,e_tmp)); - L_tmp1 = Mpy_32_16(e_tmp, f_tmp, 12330); /* Q13 */ /* 10*log10(2) in Q12*/ - Ei_fx = round_fx(L_shl(L_tmp1, 11)); /* Q8 */ - - /*-----------------------------------------------------------------* - * calculate the predicted gain code - *-----------------------------------------------------------------*/ - - /*gcode0 = (float) pow(10, 0.05 * (Es_pred - Ei));*/ - gcode0_fx = sub(Es_pred_fx, Ei_fx); /* Q8 */ - - /*-----------------------------------------------------------------* - * gcode0 = pow(10.0, gcode0/20) - * = pow(2, 3.321928*gcode0/20) - * = pow(2, 0.166096*gcode0) - *-----------------------------------------------------------------*/ - L_tmp = L_mult(gcode0_fx, 21771); /* *0.166096 in Q17 -> Q26 */ - L_tmp = L_shr(L_tmp, 10); /* From Q26 to Q16 */ - frac = L_Extract_lc(L_tmp, &exp_gcode0); /* Extract exponent of gcode0 */ - - gcode0_fx = extract_l(Pow2(14, frac));/* Put 14 as exponent so that */ - /* output of Pow2() will be: */ - /* 16384 < Pow2() <= 32767 */ - exp_gcode0 = sub(exp_gcode0, 14); - - /*-----------------------------------------------------------------* - * decode normalized codebook gain - *-----------------------------------------------------------------*/ - - /**gain_code = qua_table[index * 2 + 1] * gcode0;*/ - L_tmp = L_mult(qua_table_fx[add(shl(index,1),1)] , gcode0_fx); /* Q9*Q0 -> Q10 */ - *gain_code_fx = L_shl(L_tmp, add(exp_gcode0, 6)); - move32(); /* Q10 -> Q16*/ - } - - /**norm_gain_code = *gain_code / *gain_inov;*/ - expg = sub(norm_s(*gain_inov_fx),1); - expg = s_max(expg, 0); - - tmp_fx = div_s(shr(8192,expg),*gain_inov_fx); - *norm_gain_code_fx = L_shr(Mult_32_16(*gain_code_fx, tmp_fx),sub(1,expg)); - move32(); - - return; -} - -/*==================================================================================*/ -/* FUNCTION : gain_dec_lbr_fx() */ -/*----------------------------------------------------------------------------------*/ -/* PURPOSE : Decoding of pitch and codebook gains in ACELP at 6.6 and 7.5 kbps */ -/*----------------------------------------------------------------------------------*/ -/* INPUT ARGUMENTS : */ -/* _ (Word32) core_brate : core bitrate */ -/* _ (Word16) coder_type : coding type */ -/* _ (Word16) i_subfr : subframe index */ -/* _ (Word16*[]) code_fx : algebraic excitation (Q12) */ -/*----------------------------------------------------------------------------------*/ -/* OUTPUT ARGUMENTS : */ -/* _ (Word16*) gain_pit_fx : quantized pitch gain (Q14) */ -/* _ (Word32*) gain_code_fx : quantized codebook gain (Q16) */ -/* _ (Word16*) gain_inov_fx : gain of the innovation (used for normalization) (Q12) */ -/* _ (Word32*) norm_gain_code_fx : norm. gain of the codebook excitation (Q12) */ -/*----------------------------------------------------------------------------------*/ -/* INPUT/OUTPUT ARGUMENTS : */ -/* _ None */ -/*----------------------------------------------------------------------------------*/ - -/* _ None */ -/*----------------------------------------------------------------------------------*/ -/* RETURN ARGUMENTS : */ -/* _ None */ -/*==================================================================================*/ -void gain_dec_lbr_fx( - Decoder_State_fx *st_fx, /* i/o: decoder state structure */ - const Word32 core_brate, /* i : core bitrate */ - const Word16 coder_type, /* i : coding type */ - const Word16 i_subfr, /* i : subframe index */ - const Word16 *code_fx, /* i : algebraic excitation Q9 */ - Word16 *gain_pit_fx, /* o : quantized pitch gain Q14*/ - Word32 *gain_code_fx, /* o : quantized codebook gain Q16*/ - Word16 *gain_inov_fx, /* o : gain of the innovation (used for normalization) Q12*/ - Word32 *norm_gain_code_fx, /* o : norm. gain of the codebook excitation Q16*/ - Word32 gc_mem[], /* i/o: gain_code from previous subframes */ - Word16 gp_mem[] /* i/o: gain_pitch from previous subframes */ -) -{ - Word16 index, nBits, n_pred, ctype; - Word16 gcode0_fx, aux_fx[10]; - Word32 L_tmp, L_tmp1, L_tmp2; - Word16 expg, expg2, e_tmp, exp_gcode0, f_tmp, frac, tmp_fx; - const Word16 *b_fx ,*cdbk_fx = 0; - /* Ecode = ( dotp( code, code, L_SUBFR ) + 0.01f ) / L_SUBFR; - *gain_inov = 1.0f / (float)sqrt(Ecode); */ - - L_tmp = Dot_product12(code_fx, code_fx, L_SUBFR, &expg); - expg = sub(expg, 18 + 6); /* exp: -18 (code in Q9), -6 (/L_SUBFR) */ - expg2 = expg; - move16(); - L_tmp2 = L_add(0,L_tmp); /* sets to 'L_tmp' in 1 clock */ - L_tmp = Isqrt_lc(L_tmp, &expg); - - *gain_inov_fx = extract_h(L_shl(L_tmp, sub(expg, 3))); /* gain_inov in Q12 */ - - - /*-----------------------------------------------------------------* - * select the codebook, size and number of bits - * set the gains searching range - *-----------------------------------------------------------------*/ - - nBits = gain_bits_tbl[BIT_ALLOC_IDX_fx(core_brate, coder_type, i_subfr, 0)]; - move16(); - - ctype = shl(sub(coder_type, 1),1); - - /*-----------------------------------------------------------------* - * calculate prediction of gcode - * search for the best codeword - *-----------------------------------------------------------------*/ - IF (i_subfr == 0) - { - b_fx = b_1sfr_fx; - move16(); - n_pred = 2; - move16(); - cdbk_fx = gp_gamma_1sfr_6b_fx; - SWITCH ( nBits ) - { - case 8: - { - cdbk_fx = gp_gamma_1sfr_8b_fx; /* Q14/Q9*/ - move16(); - BREAK; - } - case 7: - { - cdbk_fx = gp_gamma_1sfr_7b_fx; /* Q14/Q9*/ - move16(); - BREAK; - } - case 6: - { - cdbk_fx = gp_gamma_1sfr_6b_fx; /* Q14/Q9*/ - move16(); - BREAK; - } - } - - /* calculate predicted gain */ - aux_fx[0] = 4096; - move16(); - aux_fx[1] = shl(ctype,12); - - /* gcode0 = (float)pow(10, dotp(b, aux, n_pred) - 0.5f * (float)log10(Ecode)); - gcode0 = (float)pow(10, dotp(b, aux, n_pred) - 0.05f * 10 * (float)log10(Ecode)); - gcode0 = (float)pow(10, 0.05(20 * dotp(b, aux, n_pred) - 10 * (float)log10(Ecode))); */ - - e_tmp = norm_l(L_tmp2); - f_tmp = Log2_norm_lc(L_shl(L_tmp2, e_tmp)); - e_tmp = sub(expg2,add(1,e_tmp)); - L_tmp1 = Mpy_32_16(e_tmp, f_tmp, 12330); /* Q13 */ /* 10*log10(2) in Q12*/ - - L_tmp = Dot_product(b_fx, aux_fx, n_pred); /*Q25*/ - L_tmp = Mult_32_16(L_tmp,160);/*Q13, 20 in Q3*/ - L_tmp = L_sub(L_tmp,L_tmp1);/*Q13*/ - - gcode0_fx = round_fx(L_shl(L_tmp, 11)); /* Q8 */ - - - /*-----------------------------------------------------------------* - * gcode0 = pow(10.0, gcode0/20) - * = pow(2, 3.321928*gcode0/20) - * = pow(2, 0.166096*gcode0) - *-----------------------------------------------------------------*/ - - L_tmp = L_mult(gcode0_fx, 21771); /* *0.166096 in Q17 -> Q26 */ - L_tmp = L_shr(L_tmp, 10); /* From Q26 to Q16 */ - frac = L_Extract_lc(L_tmp, &exp_gcode0); /* Extract exponent of gcode0 */ - - gcode0_fx = extract_l(Pow2(14, frac));/* Put 14 as exponent so that */ - /* output of Pow2() will be: */ - /* 16384 < Pow2() <= 32767 */ - exp_gcode0 = sub(exp_gcode0, 14); - - /* retrieve the codebook index and calculate both gains */ - /*index = (Word16)get_indice( st_fx,"gain", i_subfr, ACELP_CORE);move16();*/ - index = (Word16)get_next_indice_fx( st_fx, nBits ); - move16(); - - *gain_pit_fx = cdbk_fx[index * 2]; - move16(); - - L_tmp = L_mult(cdbk_fx[add(shl(index,1),1)] , gcode0_fx); /* Q9*Q0 -> Q10 */ - *gain_code_fx = L_shl(L_tmp, add(exp_gcode0, 6)); - move16(); /* Q10 -> Q16*/ - - gc_mem[0] = *gain_code_fx; - move32(); /*Q16*/ - gp_mem[0] = *gain_pit_fx; - move16(); /*Q14*/ - } - ELSE IF (sub(i_subfr,L_SUBFR) == 0) - { - b_fx = b_2sfr_fx; - move16(); - n_pred = 4; - move16(); - - cdbk_fx = gp_gamma_1sfr_6b_fx; - SWITCH ( nBits ) - { - case 7: - { - cdbk_fx = gp_gamma_2sfr_7b_fx; /* Q14/Q9*/ - move16(); - BREAK; - } - case 6: - { - cdbk_fx = gp_gamma_2sfr_6b_fx; /* Q14/Q9*/ - move16(); - BREAK; - } - } - - /* calculate predicted gain */ - aux_fx[0] = 4096; - move16(); - aux_fx[1] = shl(ctype,12); - - /*aux_fx[2] = (float)log10(gc_mem[0]); - = log2(gc_mem[0])*log10(2);*/ - e_tmp = norm_l(gc_mem[0]); - f_tmp = Log2_norm_lc(L_shl(gc_mem[0], e_tmp)); - e_tmp = sub(sub(30,e_tmp),16); /*Q_format(gc_mem[0])=16*/ - L_tmp1 = Mpy_32_16(e_tmp, f_tmp, 9864); /* Q16 */ - aux_fx[2] = round_fx(L_shl(L_tmp1, 12)); /* Q12 */ - - aux_fx[3] = shr(gp_mem[0],2); /*Q12*/ - - /*-----------------------------------------------------------------* - * gcode0 = pow(10.0, dotp(b, aux, n_pred) - * = pow(2, 3.321928*dotp(b, aux, n_pred) - *-----------------------------------------------------------------*/ - L_tmp = Dot_product(b_fx, aux_fx, n_pred); /*Q25*/ - L_tmp = Mult_32_16(L_tmp, 27213); /* *3.321928 in Q13 -> Q23 */ - L_tmp = L_shr(L_tmp, 7); /* From Q23 to Q16 */ - frac = L_Extract_lc(L_tmp, &exp_gcode0); /* Extract exponent of gcode0 */ - - gcode0_fx = extract_l(Pow2(14, frac));/* Put 14 as exponent so that */ - /* output of Pow2() will be: */ - /* 16384 < Pow2() <= 32767 */ - exp_gcode0 = sub(exp_gcode0, 14); - - /* retrieve the codebook index and calculate both gains */ - index = (Word16)get_next_indice_fx( st_fx, nBits ); - move16(); - - *gain_pit_fx = cdbk_fx[index * 2]; - move16(); - - L_tmp = L_mult(cdbk_fx[add(shl(index,1),1)] , gcode0_fx); /* Q9*Q0 -> Q10 */ - *gain_code_fx = L_shl(L_tmp, add(exp_gcode0, 6)); - move16(); /* Q10 -> Q16*/ - - gc_mem[1] = *gain_code_fx; - move32(); - gp_mem[1] = *gain_pit_fx; - move16(); - } - ELSE IF (sub(i_subfr,2*L_SUBFR) == 0) - { - b_fx = b_3sfr_fx; - move16(); - n_pred = 6; - move16(); - - cdbk_fx = gp_gamma_3sfr_6b_fx; - move16(); /* Q14/Q9*/ - - /* calculate predicted gain */ - aux_fx[0] = 4096; - move16(); - aux_fx[1] = shl(ctype,12); - move16(); - - /*aux_fx[2] = (float)log10(gc_mem[0]); - = log2(gc_mem[0])*log10(2);*/ - e_tmp = norm_l(gc_mem[0]); - f_tmp = Log2_norm_lc(L_shl(gc_mem[0], e_tmp)); - e_tmp = sub(sub(30,e_tmp),16); /*Q_format(gc_mem[0])=16*/ - L_tmp1 = Mpy_32_16(e_tmp, f_tmp, 9864); /* Q16 */ - aux_fx[2] = round_fx(L_shl(L_tmp1, 12)); /* Q12 */ - - /*aux[3] = (float)log10(gc_mem[1]); - = log2(gc_mem[1])*log10(2);*/ - e_tmp = norm_l(gc_mem[1]); - f_tmp = Log2_norm_lc(L_shl(gc_mem[1], e_tmp)); - e_tmp = sub(sub(30,e_tmp),16); /*Q_format(gc_mem[1])=16*/ - L_tmp1 = Mpy_32_16(e_tmp, f_tmp, 9864); /* Q16 */ - aux_fx[3] = round_fx(L_shl(L_tmp1, 12)); /* Q12 */ - - aux_fx[4] = shr(gp_mem[0],2); - move16(); - aux_fx[5] = shr(gp_mem[1],2); - move16(); - - /*-----------------------------------------------------------------* - * gcode0 = pow(10.0, dotp(b, aux, n_pred) - * = pow(2, 3.321928*dotp(b, aux, n_pred) - *-----------------------------------------------------------------*/ - L_tmp = Dot_product(b_fx, aux_fx, n_pred); /*Q25*/ - L_tmp = Mult_32_16(L_tmp, 27213); /* *3.321928 in Q13 -> Q23 */ - L_tmp = L_shr(L_tmp, 7); /* From Q23 to Q16 */ - frac = L_Extract_lc(L_tmp, &exp_gcode0); /* Extract exponent of gcode0 */ - - gcode0_fx = extract_l(Pow2(14, frac));/* Put 14 as exponent so that */ - /* output of Pow2() will be: */ - /* 16384 < Pow2() <= 32767 */ - exp_gcode0 = sub(exp_gcode0, 14); - - /* retrieve the codebook index and calculate both gains */ - index = (Word16)get_next_indice_fx( st_fx, nBits ); - move16(); - - *gain_pit_fx = cdbk_fx[index * 2]; - move16(); - - L_tmp = L_mult(cdbk_fx[add(shl(index,1),1)] , gcode0_fx); /* Q9*Q0 -> Q10 */ - *gain_code_fx = L_shl(L_tmp, add(exp_gcode0, 6)); /* Q10 -> Q16*/ - - gc_mem[2] = *gain_code_fx; - move32(); - gp_mem[2] = *gain_pit_fx; - move16(); - } - ELSE IF (sub(i_subfr,3*L_SUBFR) == 0) - { - b_fx = b_4sfr_fx; - move16(); - n_pred = 8; - move16(); - - cdbk_fx = gp_gamma_4sfr_6b_fx; - move16(); /* Q14/Q9*/ - - /* calculate predicted gain */ - aux_fx[0] = 4096; - move16(); - aux_fx[1] = shl(ctype,12); - move16(); - - /*aux[2] = (float)log10(gc_mem[0]); - = log2(gc_mem[0])*log10(2);*/ - e_tmp = norm_l(gc_mem[0]); - f_tmp = Log2_norm_lc(L_shl(gc_mem[0], e_tmp)); - e_tmp = sub(sub(30,e_tmp),16); /*Q_format(gc_mem[0])=16*/ - L_tmp1 = Mpy_32_16(e_tmp, f_tmp, 9864); /* Q16 */ - aux_fx[2] = round_fx(L_shl(L_tmp1, 12)); /* Q12 */ - - /*aux[3] = (float)log10(gc_mem[1]); - = log2(gc_mem[1])*log10(2);*/ - e_tmp = norm_l(gc_mem[1]); - f_tmp = Log2_norm_lc(L_shl(gc_mem[1], e_tmp)); - e_tmp = sub(sub(30,e_tmp),16); /*Q_format(gc_mem[1])=16*/ - L_tmp1 = Mpy_32_16(e_tmp, f_tmp, 9864); /* Q16 */ - aux_fx[3] = round_fx(L_shl(L_tmp1, 12)); /* Q12 */ - - /*aux[4] = (float)log10(gc_mem[2]); - = log2(gc_mem[2])*log10(2);*/ - e_tmp = norm_l(gc_mem[2]); - f_tmp = Log2_norm_lc(L_shl(gc_mem[2], e_tmp)); - e_tmp = sub(sub(30,e_tmp),16); /*Q_format(gc_mem[2])=16*/ - L_tmp1 = Mpy_32_16(e_tmp, f_tmp, 9864); /* Q16 */ - aux_fx[4] = round_fx(L_shl(L_tmp1, 12)); /* Q12 */ - - aux_fx[5] = shr(gp_mem[0],2);/*Q12*/ move16(); - aux_fx[6] = shr(gp_mem[1],2);/*Q12*/ move16(); - aux_fx[7] = shr(gp_mem[2],2);/*Q12*/ move16(); - - /*-----------------------------------------------------------------* - * gcode0 = pow(10.0, dotp(b, aux, n_pred) - * = pow(2, 3.321928*dotp(b, aux, n_pred) - *-----------------------------------------------------------------*/ - L_tmp = Dot_product(b_fx, aux_fx, n_pred); /*Q25*/ - L_tmp = Mult_32_16(L_tmp, 27213); /* *3.321928 in Q13 -> Q23 */ - L_tmp = L_shr(L_tmp, 7); /* From Q23 to Q16 */ - frac = L_Extract_lc(L_tmp, &exp_gcode0); /* Extract exponent of gcode0 */ - - gcode0_fx = extract_l(Pow2(14, frac));/* Put 14 as exponent so that */ - /* output of Pow2() will be: */ - /* 16384 < Pow2() <= 32767 */ - exp_gcode0 = sub(exp_gcode0, 14); - - /* retrieve the codebook index and calculate both gains */ - index = (Word16)get_next_indice_fx( st_fx, nBits ); - move16(); - *gain_pit_fx = cdbk_fx[index * 2]; - move16(); - - L_tmp = L_mult(cdbk_fx[add(shl(index,1),1)] , gcode0_fx); /* Q9*Q0 -> Q10 */ - *gain_code_fx = L_shl(L_tmp, add(exp_gcode0, 6)); - move32(); /* Q10 -> Q16*/ - } - - /* *norm_gain_code = *gain_code / *gain_inov; */ - expg = sub(norm_s(*gain_inov_fx),1); - expg = s_max(expg, 0); - - tmp_fx = div_s(shr(8192,expg),*gain_inov_fx); - *norm_gain_code_fx = L_shr(Mult_32_16(*gain_code_fx, tmp_fx),sub(1,expg)); - move32(); - - return; -} - -/*====================================================================== */ -/* FUNCTION : lp_gain_updt_fx() */ -/*-----------------------------------------------------------------------*/ -/* PURPOSE : Update of LP pitch and code gains (FEC) */ -/* */ -/*-----------------------------------------------------------------------*/ -/* INPUT ARGUMENTS : */ -/* _ (Word16) i_subfr : subframe number Q0 */ -/* _ (Word16) gain_pit : Decoded gain pitch Q14 */ -/* _ (Word32) norm_gain_code : Normalised gain code Q16 */ -/* _ (Word16) L_frame : length of the frame Q0 */ -/*-----------------------------------------------------------------------*/ -/* OUTPUT ARGUMENTS : */ -/* _ (Word16 *) T0 : close loop integer pitch */ -/* _ (Word16 *) T0_frac : close loop fractional part of the pitch */ -/* _ (Word16 ) pitch : pitch value Q6 */ -/*-----------------------------------------------------------------------*/ -/* INPUT OUTPUT ARGUMENTS */ -/* _ (Word16 *) lp_gainp : LP-filtered pitch gain(FEC) Q14 */ -/* _ (Word16 *) lp_gainc : LP-filtered code gain (FEC) Q3 */ -/*-----------------------------------------------------------------------*/ - -/*-----------------------------------------------------------------------*/ -/* RETURN ARGUMENTS : */ -/* _ None */ -/*=======================================================================*/ - - -void lp_gain_updt_fx( - const Word16 i_subfr, /* i : subframe number Q0 */ - const Word16 gain_pit, /* i : Decoded gain pitch Q14 */ - const Word32 norm_gain_code, /* i : Normalised gain code Q16 */ - Word16 *lp_gainp, /* i/o: LP-filtered pitch gain(FEC) Q14 */ - Word16 *lp_gainc, /* i/o: LP-filtered code gain (FEC) Q3 */ - const Word16 L_frame /* i : length of the frame */ -) -{ - Word16 tmp; - - tmp = extract_h(L_shl(norm_gain_code,3)); /*(16+3)-16 -> Q3*/ - IF( sub(L_frame,L_FRAME) == 0) - { - IF(i_subfr == 0) - { - *lp_gainp = mult(3277,gain_pit); - move16(); /*0.1 in Q15 = 3277 , (15+14)-15 -> Q14*/ - *lp_gainc = mult_r(3277,tmp); - move16(); /* (15+3)-15 -> Q3*/ - } - ELSE IF( sub(i_subfr,L_SUBFR) == 0) - { - *lp_gainp = add(*lp_gainp, mult(6554, gain_pit)); - move16(); /*Q14 (0.2 in Q15 = 6554)*/ - *lp_gainc = mac_r(L_deposit_h(*lp_gainc), 6554, tmp); - move16(); /*Q3*/ - } - ELSE IF( sub(i_subfr,2*L_SUBFR) == 0) - { - *lp_gainp = add( *lp_gainp, mult(9830, gain_pit)); - move16(); /*Q14 (0.3 in Q15 = 9830)*/ - *lp_gainc = mac_r(L_deposit_h(*lp_gainc), 9830, tmp); - move16(); /*Q3*/ - } - ELSE /* i_subfr == 3*L_SUBFR */ - { - *lp_gainp = add( *lp_gainp, mult(13107, gain_pit)); - move16(); /*Q14 (0.4 in Q15 = 13107)*/ - *lp_gainc = mac_r(L_deposit_h(*lp_gainc), 13107, tmp); - move16(); /*Q3*/ - } - } - ELSE - { - IF( i_subfr == 0 ) - { - *lp_gainp = mult(2185,gain_pit); - move16(); /*(1.0/15.0) in Q15 = 2185 , (15+14)-15 -> Q14*/ - *lp_gainc = mult_r(2185,tmp); - move16(); /* (15+3)-15 -> Q3*/ - } - ELSE IF( sub(i_subfr,L_SUBFR ) == 0) - { - *lp_gainp = add(*lp_gainp, mult(4369, gain_pit)); - move16(); /*Q14 (2.0/15.0 in Q15 = 4369)*/ - *lp_gainc = mac_r(L_deposit_h(*lp_gainc), 4369, tmp); - move16(); /*Q3*/ - } - ELSE IF( sub(i_subfr,2*L_SUBFR) == 0) - { - *lp_gainp = add(*lp_gainp, mult(6554, gain_pit)); - move16(); /*Q14 (3.0/15.0 in Q15 = 6554)*/ - *lp_gainc = mac_r(L_deposit_h(*lp_gainc), 6554, tmp); - move16(); /*Q3*/ - } - ELSE IF( sub(i_subfr,3*L_SUBFR) == 0) - { - *lp_gainp = add(*lp_gainp, mult(8738, gain_pit)); - move16(); /*Q14 (4.0/15.0 in Q15 = 8738)*/ - *lp_gainc = mac_r(L_deposit_h(*lp_gainc), 8738, tmp); - move16(); /*Q3*/ - } - ELSE /* i_subfr == 4*L_SUBFR */ - { - *lp_gainp = add(*lp_gainp, mult(10923, gain_pit)); - move16(); /*Q14 (5.0/15.0 in Q15 = 10923)*/ - *lp_gainc = mac_r(L_deposit_h(*lp_gainc), 10923, tmp); - move16(); /*Q3*/ - } - } - return; - -} - -/*-------------------------------------------------* - * Gain_dec_gaus_vbr - * - * Decode gains of purely unvoiced sounds - *-------------------------------------------------*/ -Word32 gain_dec_gaus_fx( /* o : quantized codebook gain Q16 */ - Word16 index, /* i : quantization index */ - const Word16 bits, /* i : number of bits to quantize */ - const Word16 lowBound, /* i : lower bound of quantizer (dB) */ - const Word16 topBound, /* i : upper bound of quantizer (dB) */ - const Word16 inv_gain_inov, /* o : unscaled innovation gain Q12 */ - Word32 *L_norm_gain_code /* o : gain of normalized gaussian excitation Q16 */ -) -{ - Word16 stepSize, gain, expg, frac, expi, tmp_igi; - Word32 L_tmp, L_enr_q, L_gain; - - /*------------------------------------------------------------------------------------------* - * Quantize linearly the log E - *------------------------------------------------------------------------------------------*/ - - stepSize = shl(sub(topBound,lowBound),sub(14, bits)); /* Q14 */ - - /*------------------------------------------------------------------------------------------* - * Gaussian codebook gain - *------------------------------------------------------------------------------------------*/ - - /* enr_q = (float)index*stepSize ,lowBound); */ - L_enr_q = L_mult(index, stepSize); /* Q0 * Q14 -> Q15 */ - L_enr_q = L_shl(L_enr_q, 9); /* Q15 -> Q24 */ - L_enr_q = L_add(L_enr_q, L_shl(L_deposit_h(lowBound),8)); /* Q24 */ - - /*------------------------------------------------------------* - * gain = pow(10.0, enr/20) - * = pow(2, 3.321928*enr/20) - * = pow(2, 0.166096*enr) - *------------------------------------------------------------*/ - - /* gain = (float)pow( 10.0f, enr/20.0f ); quantized codebook gain */ - L_tmp = Mult_32_16(L_enr_q, 21771); /* *0.166096 in Q17 -> Q26 */ - L_tmp = L_shr(L_tmp, 10); /* From Q26 to Q16 */ - frac = L_Extract_lc(L_tmp, &expg); /* Extract exponent of enr */ - L_gain = Pow2(30, frac); /* Put 30 as exponent so that the */ - expg = add(expg, 16-30); /* output of Pow2() will be */ - /* Normalized, set result in Q16 */ - gain = round_fx(L_gain); - L_gain = L_shl(L_gain, expg); /* In Q16*/ - /* *norm_gain_code = gain / *inv_gain_inov;*/ - expi = norm_s(inv_gain_inov); - tmp_igi = shl(inv_gain_inov, expi); - L_tmp = div_s(shr(gain,1), tmp_igi); - L_tmp = L_shl(L_tmp, add(1,expi)); - *L_norm_gain_code = L_shl(L_tmp, add(expg,13)); /* Q16 */ move32(); - - return L_gain; -} - -/*--------------------------------------------------------------------------* -* gain_dec_SQ() -* -* Decoding of pitch and codebook gains using scalar quantizers -*-------------------------------------------------------------------------*/ - -void gain_dec_SQ_fx( - Decoder_State_fx *st_fx, /* i/o: decoder state structure */ - const Word32 core_brate, /* i : core bitrate */ - const Word16 coder_type, /* i : coding type */ - const Word16 i_subfr, /* i : subframe number */ - const Word16 tc_subfr, /* i : TC subframe index */ - const Word16 *code, /* i : algebraic code excitation Q9*/ - const Word16 Es_pred, /* i : predicted scaled innov. energy Q8 */ - Word16 *gain_pit, /* o : Quantized pitch gain Q14*/ - Word32 *gain_code, /* o : Quantized codeebook gain Q16*/ - Word16 *gain_inov, /* o : unscaled innovation gain Q12*/ - Word32 *norm_gain_code /* o : norm. gain of the codebook excitation Q16*/ -) -{ - Word16 index, nBits; - Word16 gcode0, Ei; - Word16 tmp16, expg, expg2, e_tmp, f_tmp, exp_gcode0, frac; - Word32 L_tmp, L_tmp1; - - /*-----------------------------------------------------------------* - * get number of bits - *-----------------------------------------------------------------*/ - - nBits = gain_bits_16kHz_tbl[BIT_ALLOC_IDX_16KHZ_fx(core_brate, coder_type, i_subfr, TC_SUBFR2IDX_16KHZ_fx(tc_subfr)) ]; - move16(); - - /*-----------------------------------------------------------------* - * decode pitch gain - *-----------------------------------------------------------------*/ - - index = (Word16)get_next_indice_fx(st_fx, shr(nBits,1) ); - - /*Ei = (G_PITCH_MAX - G_PITCH_MIN) / ((1 << (nBits>>1)) - 1); set quantization step */ - tmp16 = div_s(1,sub(shl(1,shr(nBits,1)),1)); /* Q15*/ - Ei = mult_r(G_PITCH_MAX_MINUS_MIN_Q13,tmp16); /* Q13*/ - - /**gain_pit = usdequant( index, G_PITCH_MIN, Ei );*/ - *gain_pit = usdequant_fx( index, G_PITCH_MIN_Q14, Ei ); - move16(); /*Q14 */ - - /*-----------------------------------------------------------------* - * calculate the predicted gain code - *-----------------------------------------------------------------*/ - - /*Ecode = (dotp( code, code, L_SUBFR) + 0.01f) / L_SUBFR;*/ - /**gain_inov = 1.0f / (float)sqrt( Ecode );*/ - - L_tmp = Dot_product12(code, code, L_SUBFR, &expg); - expg = sub(expg, 18 + 6); /* exp: -18 (code in Q9), -6 (/L_SUBFR) */ - expg2 = expg; - move16(); - L_tmp1 = L_add(0,L_tmp); /* sets to 'L_tmp' in 1 clock */ - L_tmp = Isqrt_lc(L_tmp, &expg); - - *gain_inov = extract_h(L_shl(L_tmp, sub(expg, 3))); /* gain_inov in Q12 */ - - /*Ei = 10 * (float)log10( Ecode );*/ - e_tmp = norm_l(L_tmp1); - f_tmp = Log2_norm_lc(L_shl(L_tmp1, e_tmp)); - e_tmp = sub(expg2,add(1,e_tmp)); - L_tmp1 = Mpy_32_16(e_tmp, f_tmp, 12330); /* Q13 */ /* 10*log10(2) in Q12*/ - Ei = round_fx(L_shl(L_tmp1, 11)); /* Q8 */ - - /*gcode0 = (float) pow(10, 0.05 * (Es_pred - Ei));*/ - gcode0 = sub(Es_pred, Ei); /* Q8 */ - - /* gcode0 = pow(10.0, gcode0/20) = pow(2, 3.321928*gcode0/20) = pow(2, 0.166096*gcode0) */ - L_tmp = L_mult(gcode0, 21771); /* *0.166096 in Q17 -> Q26 */ - L_tmp = L_shr(L_tmp, 10); /* From Q26 to Q16 */ - frac = L_Extract_lc(L_tmp, &exp_gcode0); /* Extract exponent of gcode0 */ - - gcode0 = extract_l(Pow2(14, frac));/* Put 14 as exponent so that output of Pow2() will be: 16384 < Pow2() <= 32767 */ - exp_gcode0 = sub(exp_gcode0, 14); - - /*-----------------------------------------------------------------* - * decode normalized codebook gain - *-----------------------------------------------------------------*/ - - index = (Word16)get_next_indice_fx(st_fx, shr(add(nBits,1),1) ); - - tmp16 = gain_dequant_fx( index, G_CODE_MIN_TC_Q15, G_CODE_MAX_TC_Q0, shr(add(nBits,1),1), &expg ); - - /**gain_code *= gcode0;*/ - L_tmp = L_mult(tmp16,gcode0); /* Q0*Q0 -> Q1*/ - /**gain_code = L_shl(L_tmp,add(expg,15)); Q16*/ - *gain_code = L_shl(L_tmp,add(add(expg,exp_gcode0),15)); - move32(); /*Q16*/ - - /**norm_gain_code = *gain_code / *gain_inov;*/ - expg = sub(norm_s(*gain_inov),1); - expg = s_max(expg, 0); - - tmp16 = div_s(shr(8192,expg),*gain_inov); - *norm_gain_code = L_shr(Mult_32_16(*gain_code,tmp16),sub(1,expg)); - move32(); - - return; -} - -/*---------------------------------------------------------------------* - * gain_dec_amr_wb() - * - * Decoding of pitch and fixed codebook gains (used also in AMR-WB IO mode) - *---------------------------------------------------------------------*/ - -void gain_dec_amr_wb_fx( - Decoder_State_fx *st_fx, /* i/o: decoder state structure */ - const Word32 core_brate, /* i : core bitrate */ - Word16 *gain_pit, /* o : Quantized pitch gain */ - Word32 *gain_code, /* o : Quantized codeebook gain */ - Word16 *past_qua_en, /* i/o: gain quantization memory (4 words) */ - Word16 *gain_inov, /* o : unscaled innovation gain */ - const Word16 *code, /* i : algebraic code excitation */ - Word32 *norm_gain_code /* o : norm. gain of the codebook excitation */ -) -{ - Word16 i, index, index2; - Word16 nbits; - Word16 gcode0, qua_en; - const Word16 *t_qua_gain; - Word16 tmp; - Word32 L_tmp; - Word16 expg, exp_gcode0, fracg; - - /**gain_inov = 1.0f/ (float)sqrt( ( dotp( code, code, L_SUBFR ) + 0.01f ) / L_SUBFR );*/ - - L_tmp = Dot_product12(code, code, L_SUBFR, &expg); - expg = sub(expg, 18 + 6); /* exp: -18 (code in Q9), -6 (/L_SUBFR) */ - L_tmp = Isqrt_lc(L_tmp, &expg); - - *gain_inov = extract_h(L_shl(L_tmp, sub(expg, 3))); /* gain_inov in Q12 */ - - /*-----------------------------------------------------------------* - * Select the gain quantization table - *-----------------------------------------------------------------*/ - nbits = 7; - move16(); - t_qua_gain = t_qua_gain7b_fx; - - IF( L_sub(core_brate,ACELP_12k65) < 0) - { - nbits = 6; - move16(); - t_qua_gain = t_qua_gain6b_fx; - } - - /*-----------------------------------------------------------------* - * predicted code gain - *-----------------------------------------------------------------*/ - - /* start with predicting code energy in dB */ - /**for (i=0; i Q25 */ - } - - /* predicted codebook gain */ - gcode0 = extract_h(L_tmp); /* From Q25 to Q9 */ - - /*-----------------------------------------------------------------* - * gcode0 = pow(10.0, gcode0/20) - * = pow(2, 3.321928*gcode0/20) - * = pow(2, 0.166096*gcode0) - *-----------------------------------------------------------------*/ - L_tmp = L_mult(gcode0, 21771); /* *0.166096 in Q17 -> Q27 */ - L_tmp = L_shr(L_tmp, 9+2); /* From Q27 to Q16 */ - L_Extract(L_tmp, &exp_gcode0, &fracg); /* Extract exponent of gcode0 */ - - gcode0 = extract_l(Pow2(14, fracg));/* Put 14 as exponent so that */ - /* output of Pow2() will be: */ - /* 16384 < Pow2() <= 32767 */ - exp_gcode0 = sub(exp_gcode0, 14); - - /*-----------------------------------------------------------------* - * Decode pitch gain - *-----------------------------------------------------------------*/ - - index = (Word16)get_next_indice_fx( st_fx, nbits ); - index2 = shl(index,1); - *gain_pit = t_qua_gain[index2]; - move16(); - - /*-----------------------------------------------------------------* - * Decode code gain - *-----------------------------------------------------------------*/ - qua_en = t_qua_gain[add(index2,1)]; - move16(); - - /* *gain_code = t_qua_gain[indice*2+1] * gcode0; */ - L_tmp = L_mult(qua_en, gcode0); /* Q11*Q0 -> Q12 */ - tmp = round_fx(L_tmp); - move16(); /* Q-4 */ - *gain_code = L_shl(L_tmp, add(exp_gcode0, 4)); - move32(); /* Q12 -> Q16 */ - - /* adjust gain according to energy of code */ - L_tmp = Mult_32_16(*gain_code, *gain_inov); - *gain_code = L_shl(L_tmp, 3); - move32(); /* gcode_inov in Q12*/ - - /*-----------------------------------------------------------------* - * update table of past quantized energies - *-----------------------------------------------------------------*/ - - FOR (i=GAIN_PRED_ORDER-1; i>0; i--) - { - past_qua_en[i] = past_qua_en[i-1]; - move16(); - } - /*past_qua_en[0] = (float)(20.0*log10(qua_en));*/ - /*----------------------------------------------------------* - * past_qua_en[0] = 20*log10(t_qua_gain[indice*2+1]) - * = 6.0206*log2(t_qua_gain[indice*2+1]) - * = 6.0206*(log2(t_qua_gain[indice*2+1]Q11 -11) - *----------------------------------------------------------*/ - tmp = norm_l(qua_en); - fracg = Log2_norm_lc(L_shl(qua_en, tmp)); - expg = sub(30,tmp); - expg = sub(expg, 11); - L_tmp = Mpy_32_16(expg, fracg, 24660); /* x 6.0206 in Q12 */ - qua_en = extract_h(L_shl(L_tmp, 13)); /* result in Q10 */ - - past_qua_en[0] = qua_en; - move16(); /* in Q10 */ - - /*-----------------------------------------------------------------* - * Normalized code gain - *-----------------------------------------------------------------*/ - /**norm_gain_code = *gain_code / *gain_inov;*/ - expg = sub(norm_s(*gain_inov),1); - expg = s_max(expg, 0); - - tmp = div_s(shr(8192,expg),*gain_inov); - *norm_gain_code = L_shr(Mult_32_16(*gain_code,tmp),sub(1,expg)); - move32(); - - return; -} diff --git a/src/libs/libevs/lib_dec/gaus_dec.cpp b/src/libs/libevs/lib_dec/gaus_dec.cpp new file mode 100644 index 00000000..1e8947fa --- /dev/null +++ b/src/libs/libevs/lib_dec/gaus_dec.cpp @@ -0,0 +1,234 @@ +/*==================================================================================== + EVS Codec 3GPP TS26.443 Nov 13, 2018. Version 12.11.0 / 13.7.0 / 14.3.0 / 15.1.0 + ====================================================================================*/ + +#include +#include "options.h" +#include "cnst.h" +#include "rom_com.h" +#include "prot.h" + +/*---------------------------------------------------------------------* + * Local functions + *---------------------------------------------------------------------*/ + +static void gaus_dec2v( Decoder_State *st, float *code, const short lg, const short nb_bits ); +static void dec_2pos( short index, short *ind1, short *ind2, float *sign1, float *sign2, const short n ); + +/*---------------------------------------------------------------------* + * gaus_dec() + * + * no adaptive excitation constructed + * - decode the codebook indices, + * - find the excitation + *---------------------------------------------------------------------*/ + +void gaus_dec( + Decoder_State *st, /* i/o: decoder state structure */ + const long core_brate, /* i : core bitrate */ + const short i_subfr, /* i: subframe index */ + float *code, /* o: unvoiced excitation */ + float *norm_gain_code, /* o: gain of the normalized gaussian excitation */ + float *lp_gainp, /* i/o: LP-filtered pitch gain (FEC) */ + float *lp_gainc, /* i/o: LP-filtered code gain (FEC) */ + float *gain_inov, /* o: unscaled innovation gain */ + float *tilt_code, /* o: synthesis excitation spectrum tilt */ + float *voice_fac, /* o: estimated voicing factor */ + float *gain_pit, /* o: pitch gain */ + float *pt_pitch, /* o: floating pitch buffer */ + float *exc, /* o: excitation signal frame */ + float *gain_code, /* o: gain of the gaussian excitation */ + float *exc2 /* o : Scaled excitation signal frame */ +) +{ + short i, idx, nb_bits; + + /*----------------------------------------------------------------* + * Decode Gaussian excitation + *----------------------------------------------------------------*/ + + nb_bits = FCB_bits_tbl[BIT_ALLOC_IDX(core_brate, UNVOICED, i_subfr, TC_SUBFR2IDX(-1))]; + + gaus_dec2v( st, code, L_SUBFR, nb_bits>>1 ); + + /*-----------------------------------------------------------------* + * Decode gain of Gaussian excitation and normalized Gaussian excitation + *-----------------------------------------------------------------*/ + + *gain_inov = 1.0f / (float)sqrt( ( dotp( code, code, L_SUBFR ) + 0.01f ) / L_SUBFR ); + + nb_bits = gain_bits_tbl[BIT_ALLOC_IDX(core_brate, UNVOICED, i_subfr, TC_SUBFR2IDX(-1))]; + idx = (short)get_next_indice( st, nb_bits ); + + /* safety check in case of bit errors */ + if( idx > 78 ) + { + idx = 78; + st->BER_detect = 1; + } + + *gain_code = gain_dec_gaus( idx, nb_bits, -30.0f, 190.0f, *gain_inov, norm_gain_code ); + + /* update LP filtered gains for the case of frame erasures */ + lp_gain_updt( i_subfr, 0.0f, *norm_gain_code, lp_gainp, lp_gainc, L_FRAME ); /* supposes that gain_dec_gaus() is used for ACELP@12k8 only */ + + /*-----------------------------------------------------------------* + * Updates + *-----------------------------------------------------------------*/ + + *tilt_code = 0.0f; + *voice_fac = -1.0f; /* only unvoiced */ + *gain_pit = 0.0f; /* needed for BASS postfitler */ + *pt_pitch = (float)L_SUBFR; /* floating pitch buffer */ + + /*-----------------------------------------------------------------* + * Construct scaled excitation + *-----------------------------------------------------------------*/ + + set_f(&exc2[i_subfr], 0, L_SUBFR); + for (i = 0; i < L_SUBFR; i++) + { + exc[i+i_subfr] = *gain_code * code[i]; + } + + return; +} + +/*-----------------------------------------------------* + * gaus_dec2v() + * + * decoder of Gaussian Codebook for unvoiced + * consisting of addition of 2 Gaussian vectors + * + * One Gaussian vector of 190 values + *-----------------------------------------------------*/ + +static void gaus_dec2v( + Decoder_State *st, /* i/o: decoder state structure */ + float *code, /* o: decoded gaussian codevector */ + const short lg, /* i: codevector length */ + const short nb_bits /* i: nb ob bits per track (max 6)*/ +) +{ + short i, ind1, ind2, idx, index_delta; + short nvec, step; + float sign1, sign2; + float *pt1, *pt2; + float gaus_dico2[190]; + float delta; + + nvec = 1 << nb_bits; + step = 0x80 >> nb_bits; + + idx = (short)get_next_indice( st, 2*nb_bits+1 ); + index_delta = (short)get_next_indice( st, 3 ); + + dec_2pos( idx, &ind1, &ind2, &sign1, &sign2, nvec ); + + delta = STEP_DELTA * (float)(index_delta); + if( delta > 0.0f ) + { + gaus_dico2[0] = gaus_dico[0]; + for (i=1; i<190; i++) + { + gaus_dico2[i] = (gaus_dico[i] - delta*gaus_dico[i-1])/(1 + delta*delta); + } + } + else + { + for (i=0; i<190; i++) + { + gaus_dico2[i] = gaus_dico[i]; + } + } + + pt1 = &gaus_dico2[ind1 * step]; + pt2 = &gaus_dico2[ind2 * step]; + + for(i=0; i>1; + + *ind1 = index/n; + *ind2 = index -(*ind1*n); + if( *ind1 > *ind2) + { + *sign2 = -*sign1; + } + else + { + *sign2 = *sign1; + } + + return; +} + + + + + +/*-----------------------------------------------------* + * gaus_L2_dec : + * + * decoder of Gaussian Codebook for unvoiced as Layer 2 + * + * One Gaussian vector + *-----------------------------------------------------*/ + +void gaus_L2_dec( + float *code, /* o: decoded gaussian codevector */ + float tilt_code, + const float *Aq, + float formant_enh_num, + short *seed_acelp /*i/o: random seed */ +) +{ + short i; + + /*Generate white gaussian noise using central limit theorem method (N only 4 as E_util_random is not purely uniform)*/ + for( i=0; i 0 ) - { - idx = 78; - move16(); - st_fx->BER_detect = 1; - move16(); - } - - *L_gain_code = gain_dec_gaus_fx( idx, nb_bits,-30,190, *inv_gain_inov, L_norm_gain_code ); - - /* update LP filtered gains for the case of frame erasures */ - lp_gain_updt_fx( i_subfr, 0, *L_norm_gain_code, lp_gainp, lp_gainc, L_FRAME ); /* supposes that gain_dec_gaus() is used for ACELP@12k8 only */ - - /*------------------------------------------------------------------------------------------* - * Updates - *------------------------------------------------------------------------------------------*/ - - *tilt_code = 0; - move16(); - *voice_fac = -32768; /* only unvoiced */ move16(); - *gain_pit = 0; /* needed for BASS postfitler */ move16(); - *pt_pitch_1 = 4096; /* floating pitch buffer Q6 */ move16(); - - /*------------------------------------------------------------------------------------------* - * Construct scaled excitation - *------------------------------------------------------------------------------------------*/ - - set16_fx(&exc[i_subfr],0, L_SUBFR); - set16_fx(&exc2[i_subfr],0, L_SUBFR); - - IF( sub(st_fx->L_frame_fx,L_FRAME) == 0 ) - { - Rescale_exc( st_fx->dct_post_old_exc_fx, &exc[i_subfr], &bwe_exc_fx[i_subfr * HIBND_ACB_L_FAC], st_fx->last_exc_dct_in_fx, - L_SUBFR, L_SUBFR* HIBND_ACB_L_FAC, *L_gain_code, sQ_exc, sQsubfr, exc2, i_subfr, UNVOICED ); - } - ELSE - { - Rescale_exc( st_fx->dct_post_old_exc_fx, &exc[i_subfr], &bwe_exc_fx[i_subfr * 2], st_fx->last_exc_dct_in_fx, - L_SUBFR, L_SUBFR* 2, *L_gain_code, sQ_exc, sQsubfr, exc2, i_subfr, UNVOICED ); - } - - gain_code = round_fx(L_shl(*L_gain_code, *sQ_exc)); - FOR (i = 0; i < L_SUBFR; i++) - { - L_tmp = L_shl(L_mult(gain_code, code[i]), 6/*3*/); - exc[i+i_subfr] = round_fx(L_tmp); - } - - return; -} - - - -/*-----------------------------------------------------* - * gaus_dec2v() - * - * decoder of Gaussian Codebook for unvoiced - * consisting of addition of 2 Gaussian vectors - * - * One Gaussian vector of 190 values - *-----------------------------------------------------*/ - -void gaus_dec2v_fx( - Decoder_State_fx *st_fx, /* i/o: decoder state structure */ - Word16 *code, /* o : decoded gaussian vector Q12-exp */ - const Word16 lg, /* i : codevector length Q0 */ - const Word16 nb_bits /* i : nb ob bits per track (max 6) */ -) -{ - Word16 i, ind1, ind2,idx; - Word16 step; - Word16 sign1, sign2; - Word16 delta, delta2, inv_delta; - Word16 gaus_dico2_fx[190]; - Word16 tmp16; - const Word16 *pt1, *pt2; - Word16 index_delta; - - step = shr(0x80, nb_bits); - - idx = (Word16)get_next_indice_fx( st_fx, add(shl(nb_bits,1),1) ); - index_delta = (Word16)get_next_indice_fx( st_fx, 3 ); - - dec_2pos_fx( idx, &ind1, &ind2, &sign1, &sign2, nb_bits ); - - delta = shl(index_delta, STEP_DELTA_FX); - delta2 = mac_r(16384*65536, shr(delta,1), delta); - inv_delta = div_s(16384, delta2); - - IF (delta > 0) - { - gaus_dico2_fx[0] = gaus_dico_fx[0]; - move16(); /*Q12 */ - FOR (i=1; i<190; i++) - { - /* gaus_dico2[i] = (gaus_dico_fx[i] - delta*gaus_dico_fx[i-1])/(1+delta*delta) */ - tmp16 = msu_r(L_deposit_h(gaus_dico_fx[i]), delta, gaus_dico_fx[i-1]); - gaus_dico2_fx[i] = mult_r(tmp16, inv_delta); - } - } - ELSE - { - FOR (i=0; i<190; i++) - { - gaus_dico2_fx[i] = gaus_dico_fx[i]; - move16(); /*Q12 */ - } - } - - pt1 = &gaus_dico2_fx[i_mult2(ind1, step)]; - move16(); - pt2 = &gaus_dico2_fx[i_mult2(ind2, step)]; - move16(); - - FOR (i = 0; i < lg; i++) - { - /* code is Q9, Gaussian codebook is Q12 */ - /* code[i] = pt1[i] * sign1 + pt2[i] * sign2 */ - code[i] = add(mult(pt1[i], sign1), mult(pt2[i], sign2)); - } - - return; -} - - -/*-----------------------------------------------------* - * dec_2pos() - * - * Decode the codevectors positions and signs - *-----------------------------------------------------*/ -static void dec_2pos_fx( - Word16 index, /* i : quantization index Q0 */ - Word16 *ind1, /* o : 1st vector index Q0 */ - Word16 *ind2, /* o : 2nd vector index Q0 */ - Word16 *sign1, /* o : 1st vector sign Q0 */ - Word16 *sign2, /* o : 2nd vector sign Q0 */ - Word16 log2_n /* i : Log2(number of vector) Q0 */ -) -{ - Word16 i; - - i = s_and(index, 1); - *sign1 = (-32768); /* -1 (Q15) */ move16(); - if (i == 0) - { - *sign1 = MAX_16; /* 1 (Q15) */ move16(); - } - *sign1 = shr(*sign1,3); - move16(); /* To have code dec in Q9 instead of Q12 */ - - index = shr(index, 1); - - *ind1 = shr(index, log2_n); - move16(); - *ind2 = sub(index, shl(*ind1, log2_n)); - move16(); - *sign2 = *sign1; - move16(); - if (sub(*ind1, *ind2) > 0) - { - *sign2 = negate(*sign1); - move16(); - } - return; -} - - - -/*-----------------------------------------------------* - * gaus_L2_dec : - * - * decoder of Gaussian Codebook for unvoiced as Layer 2 - * - * One Gaussian vector - *-----------------------------------------------------*/ -void gaus_L2_dec( - Word16 *code, /* o : decoded gaussian codevector Q9 */ - Word16 tilt_code, /* i : tilt of code Q15 */ - const Word16 *A, /* i : quantized LPCs Q12 */ - Word16 formant_enh, /* i : formant enhancement factor Q15 */ - Word16 *seed_acelp /*i/o : random seed Q0 */ -) -{ - Word16 i, seed; - Word32 tmp32; - - /*Generate white gaussian noise using central limit theorem method (N only 4 as E_util_random is not purely uniform)*/ - seed = *seed_acelp; - move16(); - FOR (i = 0; i < L_SUBFR; i++) - { - seed = own_random2_fx(seed); - tmp32 = L_mac(0, seed, 1<<9); - - seed = own_random2_fx(seed); - tmp32 = L_mac(tmp32, seed, 1<<9); - - seed = own_random2_fx(seed); - code[i] = mac_r(tmp32, seed, 1<<9); - move16(); - } - *seed_acelp = seed; - move16(); - - /*Shape the gaussian excitation*/ - cb_shape_fx( 1, 0, 0, 1, 0, formant_enh, FORMANT_SHARPENING_G2, A, code, tilt_code, 0, 1 ); - - - return; -} - diff --git a/src/libs/libevs/lib_dec/gs_dec.cpp b/src/libs/libevs/lib_dec/gs_dec.cpp new file mode 100644 index 00000000..beac5220 --- /dev/null +++ b/src/libs/libevs/lib_dec/gs_dec.cpp @@ -0,0 +1,513 @@ +/*==================================================================================== + EVS Codec 3GPP TS26.443 Nov 13, 2018. Version 12.11.0 / 13.7.0 / 14.3.0 / 15.1.0 + ====================================================================================*/ + +#include +#include "options.h" +#include "cnst.h" +#include "rom_com.h" +#include "prot.h" + +/*-------------------------------------------------------------------* + * decod_audio() + * + * Decode audio (AC) frames + *-------------------------------------------------------------------*/ + +void decod_audio( + Decoder_State *st, /* i/o: decoder static memory */ + float dct_epit[], /* o : GSC excitation in DCT domain */ + const float *Aq, /* i : LP filter coefficient */ + const short coder_type, /* i : coding type */ + float *tmp_noise, /* o : long term temporary noise energy */ + float *pitch_buf, /* o : floating pitch values for each subframe */ + float *voice_factors, /* o : voicing factors */ + float *exc, /* i/o: adapt. excitation exc */ + float *exc2, /* i/o: adapt. excitation/total exc */ + float *bwe_exc, /* o : excitation for SWB TBE */ + float *lsf_new, /* i : ISFs at the end of the frame */ + float *gain_buf +) +{ + short tmp_nb_bits_tot, pit_band_idx; + float code[L_SUBFR]; + short Diff_len, nb_subfr, i; + short nb_frame_flg; + float Es_pred = 0.0f; + short Len, max_len; + short attack_flag; + float low_pit; + short last_bin; + short nbits; + float exc_wo_nf[L_FRAME]; + + short nb_bits; /* number of bits */ + int indice; /* parameter indices to read */ + + /*---------------------------------------------------------------* + * Initialization + *---------------------------------------------------------------*/ + + Diff_len = 0; + + /* decode GSC attack flag (used to reduce possible pre-echo) */ + attack_flag = (short) get_next_indice( st, 1 ); + + /* decode GSC SWB speech flag */ + if( coder_type != INACTIVE && st->total_brate >= ACELP_13k20 ) + { + st->GSC_noisy_speech = (short) get_next_indice( st, 1 ); + } + + /* safety check in case of bit errors */ + if( st->GSC_noisy_speech && st->bwidth != SWB ) + { + st->BER_detect = 1; + st->GSC_noisy_speech = 0; + } + + /*---------------------------------------------------------------* + * Decode energy dynamics + *---------------------------------------------------------------*/ + + if( st->GSC_noisy_speech ) + { + nb_subfr = NB_SUBFR; + st->cor_strong_limit = 0; + st->noise_lev = NOISE_LEVEL_SP3; + } + else + { + if( st->core_brate <= ACELP_8k00 ) + { + st->noise_lev = (short)get_next_indice( st, 2 ) + NOISE_LEVEL_SP2; + } + else + { + st->noise_lev = (short)get_next_indice( st, 3 ) + NOISE_LEVEL_SP0; + } + + /*---------------------------------------------------------------* + * Decode number of subframes + *---------------------------------------------------------------*/ + + st->cor_strong_limit = 1; + nb_subfr = SWNB_SUBFR; + if( st->core_brate >= ACELP_9k60 ) + { + nbits = 1; + + nb_frame_flg = (short)get_next_indice( st, nbits ); + + if( (nb_frame_flg & 0x1) == 0) + { + nb_subfr = 2*SWNB_SUBFR; + st->cor_strong_limit = 0; + } + } + } + + /*---------------------------------------------------------------* + * Decode the last band where the adaptive (pitch) contribution is significant + *---------------------------------------------------------------*/ + + if( st->core_brate < CFREQ_BITRATE ) + { + if( st->core_brate < ACELP_9k60 && coder_type == INACTIVE ) + { + nbits = 1; + } + else + { + nbits = 3; + } + } + else + { + nbits = 4; + } + + if( st->core_brate < ACELP_9k60 && coder_type != INACTIVE ) + { + pit_band_idx = 1; + } + else + { + pit_band_idx = (short)get_next_indice( st, nbits ); + } + + if( pit_band_idx != 0 ) + { + if( st->core_brate < ACELP_9k60 ) + { + pit_band_idx = 7+BAND1k2; /* At low rate, if pitch model is chosen, then for to be use on extented and constant frequency range */ + } + else + { + pit_band_idx += BAND1k2; + } + + /* detect bit errors in the bitstream */ + if( pit_band_idx > 13 ) /* The maximum decodable index is 10 + BAND1k2 (3) = 13 */ + { + pit_band_idx = 13; + st->BER_detect = 1; + } + + Diff_len = (short)(mfreq_loc[pit_band_idx]/BIN_SIZE); + } + + st->Last_GSC_pit_band_idx = pit_band_idx; + + /*--------------------------------------------------------------------------------------* + * Decode adaptive (pitch) excitation contribution + * Reset unvaluable part of the adaptive (pitch) excitation contribution + *--------------------------------------------------------------------------------------*/ + + if( pit_band_idx > BAND1k2 ) + { + /*---------------------------------------------------------------* + * Decode adaptive (pitch) excitation contribution + *---------------------------------------------------------------*/ + + if( st->GSC_noisy_speech && nb_subfr == NB_SUBFR ) + { + nb_bits = Es_pred_bits_tbl[BIT_ALLOC_IDX(st->core_brate, GENERIC, -1, -1)]; + indice = (short)get_next_indice( st, nb_bits ); + Es_pred_dec(&Es_pred, indice, nb_bits, 0); + } + + dec_pit_exc( st, L_FRAME, Aq, Es_pred, pitch_buf, code, exc, nb_subfr, gain_buf ); + + if( st->core_brate < ACELP_9k60 ) + { + minimum( pitch_buf, L_FRAME>>6, &low_pit); + + if( low_pit < 64 ) + { + pit_band_idx = 9+BAND1k2; + if(st->bwidth == NB) + { + pit_band_idx = 7+BAND1k2; + } + } + else if( low_pit < 128 ) + { + pit_band_idx = 5+BAND1k2; + } + else + { + pit_band_idx = 3+BAND1k2; + } + + Diff_len = (short)(mfreq_loc[pit_band_idx]/BIN_SIZE); + st->Last_GSC_pit_band_idx = pit_band_idx; + } + + /*---------------------------------------------------------------* + * DCT transform + *---------------------------------------------------------------*/ + + edct( exc, dct_epit, L_FRAME ); + + /*---------------------------------------------------------------* + * Reset unvaluable part of the adaptive (pitch) excitation contribution + *---------------------------------------------------------------*/ + + max_len = L_FRAME - Diff_len; + if(st->bwidth == NB) + { + max_len = 160-Diff_len; + } + + Len = 80; + if( max_len < 80 ) + { + Len = max_len; + } + + if(st->core_brate == ACELP_8k00 && st->bwidth != NB ) + { + for (i=0; i < max_len; i++) + { + dct_epit[i+Diff_len] = 0.0f; + } + } + else + { + for (i = 0; i < Len; i++) + { + dct_epit[i+Diff_len] *= sm_table[i]; + } + for (; i < max_len; i++) + { + dct_epit[i+Diff_len] = 0.0f; + } + } + + st->bfi_pitch = (short)(mean(pitch_buf, nb_subfr)+0.5f); + st->bfi_pitch_frame = L_FRAME; + + Diff_len++; + st->bpf_off = 0; + } + else + { + /* No adaptive (pitch) excitation contribution */ + st->bpf_off = 1; + set_f( dct_epit, 0.0f, L_FRAME ); + set_f( pitch_buf, (float)L_SUBFR, NB_SUBFR ); + + set_f( gain_buf, 0.f, NB_SUBFR16k); + + st->bfi_pitch = L_SUBFR; + st->bfi_pitch_frame = L_FRAME; + st->lp_gainp = 0.0f; + st->lp_gainc = 0.0f; + st->tilt_code = 0; + pit_band_idx = 0; + Diff_len = 0; + } + + /*--------------------------------------------------------------------------------------* + * GSC decoder + *--------------------------------------------------------------------------------------*/ + + /* find the current total number of bits used */ + tmp_nb_bits_tot = st->next_bit_pos; + + if( st->extl_brate > 0 ) + { + /* subtract 1 bit for TBE/BWE BWE flag (bit counted in extl_brate) */ + tmp_nb_bits_tot--; + } + + if( coder_type == INACTIVE && st->core_brate <= ACELP_9k60 ) + { + tmp_nb_bits_tot += 5; /* for noisiness */ + } + + gsc_dec( st, dct_epit, pit_band_idx, Diff_len, tmp_nb_bits_tot, nb_subfr, coder_type, &last_bin, lsf_new, exc_wo_nf, tmp_noise ); + + /*--------------------------------------------------------------------------------------* + * iDCT transform + *--------------------------------------------------------------------------------------*/ + + edct( dct_epit, exc, L_FRAME ); + edct( exc_wo_nf, exc_wo_nf, L_FRAME ); + + /*----------------------------------------------------------------------* + * Remove potential pre-echo in case an onset has been detected + *----------------------------------------------------------------------*/ + + pre_echo_att( &st->Last_frame_ener, exc, attack_flag, st->last_coder_type ); + + /*--------------------------------------------------------------------------------------* + * Update BWE excitation + *--------------------------------------------------------------------------------------*/ + + set_f( voice_factors, 0.0f, NB_SUBFR16k ); + interp_code_5over2( exc, bwe_exc, L_FRAME ); + + /*--------------------------------------------------------------------------------------* + * Updates + *--------------------------------------------------------------------------------------*/ + + mvr2r( exc, exc2, L_FRAME ); + mvr2r( exc_wo_nf, exc, L_FRAME ); + + /*--------------------------------------------------------------------------------------* + * Channel aware mode parameters + *--------------------------------------------------------------------------------------*/ + + set_f( st->tilt_code_dec, 0, NB_SUBFR16k ); + + return; +} + + + +/*-------------------------------------------------------------------* + * gsc_dec() + * + * Generic audio signal decoder + *-------------------------------------------------------------------*/ + +void gsc_dec( + Decoder_State *st, /* i/o: State structure */ + float exc_dct_in[], /* i/o: dct of pitch-only excitation / total excitation */ + const short pit_band_idx, /* i : bin position of the cut-off frequency */ + const short Diff_len, /* i : Lenght of the difference signal (before pure spectral)*/ + const short bits_used, /* i : Number of bit used before frequency Q */ + const short nb_subfr, /* i : Number of subframe considered */ + const short coder_type, /* i : coding type */ + short *last_bin, /* i : last bin of bit allocation */ + float *lsf_new, /* i : ISFs at the end of the frame */ + float *exc_wo_nf, /* o : excitation (in f domain) without noisefill */ + float *tmp_noise /* o : long-term noise energy */ +) +{ + short i, j, bit, nb_subbands, pvq_len; + short bitallocation_band[MBANDS_GN]; + short bitallocation_exc[2]; + float Ener_per_bd_iQ[MBANDS_GN]; + short max_ener_band[MBANDS_GN]; + float exc_diffQ[L_FRAME]; + short bits_per_bands[MBANDS_GN]; /*Q3*/ + float concat_out[L_FRAME]; + short npulses[NB_SFM]; + short maxpulse[NB_SFM]; + float mean_gain; + short Mbands_gn = 16; + short seed_init; + + /*--------------------------------------------------------------------------------------* + * Initialization + *--------------------------------------------------------------------------------------*/ + + bit = bits_used; + set_f( exc_diffQ, 0.0f, L_FRAME ); + + /*--------------------------------------------------------------------------------------* + * Gain decoding + *--------------------------------------------------------------------------------------*/ + + if( st->bfi || st->BER_detect ) + { + /* copy old gain */ + mvr2r( st->old_y_gain, Ener_per_bd_iQ, Mbands_gn ); + mean_gain = st->lp_gainc/10.0f; + for( i=0; ilp_gainc *= 0.98f; + } + else + { + mean_gain = gsc_gaindec( st, Ener_per_bd_iQ, st->core_brate, st->old_y_gain, coder_type, st->bwidth ); + + st->lp_gainc = 10.0f * mean_gain; + } + + *tmp_noise = st->lp_gainc; + + *last_bin = 0; + if( st->core_brate == ACELP_8k00 && st->bwidth != NB ) + { + bitallocation_exc[0] = 0; + bitallocation_exc[1] = 0; + } + + set_s( bitallocation_band, 0, MBANDS_GN ); + + if( st->bfi || st->BER_detect ) + { + /*--------------------------------------------------------------------------------------* + * Copy old spectrum + * reduce spectral dynamic + * save spectrum + *--------------------------------------------------------------------------------------*/ + + if(st->last_good == INACTIVE_CLAS || st->Last_GSC_noisy_speech_flag == 1) + { + for( i=0; iLast_GSC_spectrum[i] = 0.8f * own_random(&st->seed_tcx)/32768.0f+0.2f*st->Last_GSC_spectrum[i]; + } + mvr2r( st->Last_GSC_spectrum, exc_diffQ, L_FRAME ); + } + + mvr2r( st->Last_GSC_spectrum, exc_diffQ, L_FRAME ); + + for( i=0; iLast_GSC_spectrum[i] *= 0.75f; + } + } + else + { + /*--------------------------------------------------------------------------------------* + * PVQ decoder + *--------------------------------------------------------------------------------------*/ + + bands_and_bit_alloc( st->cor_strong_limit, st->noise_lev, st->core_brate, Diff_len, bit, &bit, Ener_per_bd_iQ, + max_ener_band, bits_per_bands, &nb_subbands, NULL, NULL, &pvq_len, coder_type, + st->bwidth, st->GSC_noisy_speech ); + + set_s( npulses, 0, NB_SFM ); + + pvq_core_dec( st, gsc_sfm_start, gsc_sfm_end, gsc_sfm_size, concat_out, bit, nb_subbands, bits_per_bands, NULL, npulses, maxpulse, ACELP_CORE ); + + seed_init = 0; + for( j = 0; j < nb_subbands; j++ ) + { + mvr2r( concat_out+j*16, exc_diffQ + max_ener_band[j]*16, 16); + + if( max_ener_band[j] > *last_bin ) + { + *last_bin = max_ener_band[j]; + } + + bitallocation_band[max_ener_band[j]] = 1; + + seed_init += npulses[j]; + } + if( st->last_coder_type != AUDIO /* First audio frame */ + && st->last_coder_type != UNVOICED ) /* last_coder_type == INACTIVE is overwritten in update_dec to UNVOICED */ + { + for(j = 0; j < nb_subbands*16; j++) + { + if( concat_out[j] > 0 ) + { + seed_init = (short)((int)seed_init<<3); + } + if( concat_out[j] < 0 ) + { + seed_init += 3; + } + } + + st->seed_tcx = seed_init; + } + + if( st->core_brate == ACELP_8k00 && st->bwidth != NB ) + { + if( exc_diffQ[L_FRAME8k - 2] != 0 ) + { + bitallocation_exc[0] = 1; + } + + if( exc_diffQ[L_FRAME8k - 1] != 0 ) + { + bitallocation_exc[1] = 1; + } + } + + mvr2r( exc_diffQ, st->Last_GSC_spectrum, L_FRAME ); + + /*--------------------------------------------------------------------------------------* + * Skip adaptive (pitch) contribution frequency band (no noise added over the time contribution) + * Find x pulses between 1.6-3.2kHz to code in the spectrum of the residual signal + * Gain is based on the inter-correlation gain between the pulses found and residual signal + *--------------------------------------------------------------------------------------*/ + + freq_dnw_scaling( st->cor_strong_limit, coder_type, st->noise_lev, st->core_brate, exc_diffQ ); + } + + /*--------------------------------------------------------------------------------------* + * Estimate noise level + *--------------------------------------------------------------------------------------*/ + + highband_exc_dct_in( st->core_brate, mfreq_bindiv_loc, *last_bin, Diff_len, st->noise_lev, pit_band_idx, exc_diffQ, + &st->seed_tcx, Ener_per_bd_iQ, nb_subfr, exc_dct_in, st->last_coder_type, bitallocation_band, lsf_new, + st->last_exc_dct_in, &st->last_ener, st->last_bitallocation_band, bitallocation_exc, st->bfi, coder_type, + st->bwidth, exc_wo_nf, st->GSC_noisy_speech + ,st->lt_ener_per_band + ); + + exc_dct_in[0] = 0; + + return; +} diff --git a/src/libs/libevs/lib_dec/gs_dec_amr_wb.cpp b/src/libs/libevs/lib_dec/gs_dec_amr_wb.cpp new file mode 100644 index 00000000..d98076e4 --- /dev/null +++ b/src/libs/libevs/lib_dec/gs_dec_amr_wb.cpp @@ -0,0 +1,393 @@ +/*==================================================================================== + EVS Codec 3GPP TS26.443 Nov 13, 2018. Version 12.11.0 / 13.7.0 / 14.3.0 / 15.1.0 + ====================================================================================*/ + +#include +#include "options.h" +#include "cnst.h" +#include "rom_com.h" +#include "prot.h" + + +/*-------------------------------------------------------------------* + * Local constants + *-------------------------------------------------------------------*/ + +#define BAND3k 15 +#define BIN_1k2 48 +#define BAND_2k 12 +#define BAND_0k4 4 +#define ALP 0.7f +#define MALP (1.0f-ALP) +#define ALPMY (0.86f) +#define ALPY 1.5f + +/*-------------------------------------------------------------------* + * Local functions + *-------------------------------------------------------------------*/ + +static void NoiseFill( float *exc_diffQ, short *seed_tcx, const short Mbands_gn ); +static void Ener_per_band( const float exc_diff[], float y_gain4[] ); +static void Apply_gain( float exc_diffQ[], float Ener_per_bd_iQ[], float Ener_per_bd_yQ[]); +static void normalize_spec( float fac_up, float fy_norm[], const short L_frame ); +static void gs_dec_amr_wb( const long core_brate, short *seed_tcx, const float dct_in[], + float dct_out[], const float pitch[], const float voice_fac + ,const short clas, const short coder_type + ); + + +/*-------------------------------------------------------------------* + * NoiseFill() + * + * noise fill function for unvoiced/inactive frames (used only in AMR-WB IO mode) + *-------------------------------------------------------------------*/ + +static void NoiseFill( + float *exc_diffQ, /* i/o: Noise per band */ + short *seed_tcx, /* i : Seed for noise */ + const short Mbands_gn /* i : number of bands */ +) +{ + short StartBin, NB_Qbins, i_band, k; + StartBin = 0; + NB_Qbins = 0; + + for( i_band = 0; i_band < Mbands_gn; i_band++ ) + { + StartBin += NB_Qbins; + NB_Qbins = crit_bins[i_band]; + for( k=StartBin; k= ACELP_12k65 ) + { + etmp14 *=2; + } + + mDiff_len = (short)(etmp14+0.5f); + etmp14 = 32768.0f; + j = 0; + for(i = 0; i < CRIT_NOIS_BAND; i++) + { + if( fabs(crit_bands_loc[i] - mDiff_len) < etmp14 ) + { + etmp14 = (float)fabs(crit_bands_loc[i] - mDiff_len); + j += crit_bins[i]; + } + } + + mDiff_len = j; + if( mDiff_len < BIN_1k2 ) + { + mDiff_len = BIN_1k2; + } + mvr2r(dct_in, exc_diffQ, mDiff_len); + set_f(exc_diffQ+mDiff_len, 0, L_FRAME-mDiff_len); + + /*--------------------------------------------------------------------------------------* + * normalization of the spectrum and noise fill + *--------------------------------------------------------------------------------------*/ + + normalize_spec(4, exc_diffQ , mDiff_len); + NoiseFill( exc_diffQ, seed_tcx, CRIT_NOIS_BAND); + + + /*--------------------------------------------------------------------------------------* + * Recompute energy per band of the modified excitation vector (in frequency domain) + *--------------------------------------------------------------------------------------*/ + + Ener_per_band( exc_diffQ, Ener_per_bd_yQ ); + + /*--------------------------------------------------------------------------------------* + * Compute tilt factor and amplify HF accordingly + *--------------------------------------------------------------------------------------*/ + + ftmp = (0.5f * (1.0f - voice_fac)); /* 1=unvoiced, 0=voiced */ + + for(i = 240; i < L_FRAME; i++) + { + ftmp1 = ftmp*(0.067f * i - 15.0f); + ftmp1 = max(1.0f, ftmp1); + exc_diffQ[i] *= ftmp1; + } + + /*--------------------------------------------------------------------------------------* + * Match the energy of the modified excitation vector to the decoded excitation + *--------------------------------------------------------------------------------------*/ + + Apply_gain( exc_diffQ, Ener_per_bd_iQ, Ener_per_bd_yQ); + + /*--------------------------------------------------------------------------------------* + * Copy to the output vector + *--------------------------------------------------------------------------------------*/ + + mvr2r( exc_diffQ, dct_out, L_FRAME ); + + return; +} + +/*-------------------------------------------------------------------* + * improv_amr_wb_gs() + * + * Modify the decoded excitation to increase quality of + * unvoiced and audio signals (used only in AMR-WB IO mode) + *-------------------------------------------------------------------*/ + +void improv_amr_wb_gs( + const short clas, /* i : signal frame class */ + const short coder_type, /* i : coder type */ + const long core_brate, /* i : bitrate allocated to the core */ + short *seed_tcx, /* i/o: Seed used for noise generation */ + float *old_Aq, /* i/o: old LPC filter coefficient */ + float *mem_syn2, /* i/o: synthesis memory */ + const float lt_voice_fac, /* i/o: long term voice factor */ + const short locattack, /* i : Flag for a detected attack */ + float *Aq, /* i/o: Decoded LP filter coefficient */ + float *exc2, /* i/o: Decoded complete excitation */ + float *mem_tmp, /* i/o: synthesis temporary memory */ + float *syn, /* i/o: Decoded synthesis to be updated */ + const float *pitch_buf, /* i : Decoded pitch buffer */ + const float Last_ener /* i : Last energy */ + ,const short rate_switching_reset /* i : rate switching reset flag */ + ,const short last_coder_type /* i : Last coder_type */ +) +{ + short i; + float dct_exc_in[L_FRAME], dct_exc_out[L_FRAME]; + float Aq_orig[NB_SUBFR*(M+1)], enr_LP_old, enr_LP_new; + + /*------------------------------------------------------------* + * Condition to enter the section on excitation modification + *------------------------------------------------------------*/ + + /* Enter the modification for all inactive frames and also for unvoiced frames if bit rate is below 8k85 */ + if( ( locattack == 0 && core_brate <= ACELP_12k65) && + ( (core_brate < ACELP_8k85 && clas != AUDIO_CLAS && (clas == UNVOICED_CLAS || clas == VOICED_TRANSITION)) || coder_type == INACTIVE ) ) + { + /*------------------------------------------------------------* + * two differents paths: + * unvoiced or inactive + * generic audio sound + * LP filter smoothing for inactive parts + *------------------------------------------------------------*/ + *seed_tcx = (short)((short)(pitch_buf[0]*64.0f)*(short)(pitch_buf[3]*64.0f)); + + if( coder_type == INACTIVE && Last_ener > -3.0f && last_coder_type == UNVOICED && rate_switching_reset == 0 ) + { + mvr2r( Aq, Aq_orig, NB_SUBFR*(M+1) ); + + for(i =0; i < NB_SUBFR * (M+1); i++) + { + Aq[i] = ALP*old_Aq[i] + MALP*Aq[i]; + } + + /* check the smoothed LP filter stability */ + enr_LP_old = enr_1_Az( old_Aq, L_SUBFR ); + for(i =0; i < NB_SUBFR; i++) + { + enr_LP_new = enr_1_Az( Aq+i*(M+1), L_SUBFR ); + + if( enr_LP_new > 128 * enr_LP_old ) + { + /* filter is unstable, do not modify the excitation */ + mvr2r( Aq_orig, Aq, NB_SUBFR*(M+1) ); + return; + } + + enr_LP_old = enr_LP_new; + } + } + + /*------------------------------------------------------------* + * Find frequency representation of the excitation + * Do the excitation modification according to the content + * Go back to time domain -> Overwrite excitation + *------------------------------------------------------------*/ + + edct( exc2, dct_exc_in, L_FRAME ); + set_f( exc2, 0, L_FRAME ); + set_f( dct_exc_out, 0, L_FRAME ); + + gs_dec_amr_wb( core_brate, seed_tcx, dct_exc_in, dct_exc_out, pitch_buf, lt_voice_fac, clas, coder_type ); + + edct( dct_exc_out, exc2, L_FRAME ); + + /*------------------------------------------------------------* + * Redo core synthesis at 12k8 Hz with the modified excitation + *------------------------------------------------------------*/ + + mvr2r( mem_tmp, mem_syn2, M ); + syn_12k8( L_FRAME, Aq, exc2, syn, mem_syn2, 1 ); + } + + return; +} diff --git a/src/libs/libevs/lib_dec/gs_dec_amr_wb_fx.cpp b/src/libs/libevs/lib_dec/gs_dec_amr_wb_fx.cpp deleted file mode 100755 index e9320c89..00000000 --- a/src/libs/libevs/lib_dec/gs_dec_amr_wb_fx.cpp +++ /dev/null @@ -1,454 +0,0 @@ -/*==================================================================================== - EVS Codec 3GPP TS26.442 Apr 03, 2018. Version 12.11.0 / 13.6.0 / 14.2.0 - ====================================================================================*/ - -#include "options.h" /* Compilation switches */ -#include "cnst_fx.h" /* Common constants */ -#include "rom_com_fx.h" /* Static table prototypes */ -#include "prot_fx.h" /* Function prototypes */ -#include "stl.h" - - -/*-------------------------------------------------------------------* - * Local constants - *-------------------------------------------------------------------*/ - -#define ALP_FX 22938 /* 0.70f */ -#define MALP_FX (Word16)(32768L-ALP_FX) -#define ALPMY_FX 28180 /* 0.86f */ - -#define BAND3k 15 -#define BIN_1k2 48 -#define BAND_2k 12 -#define BAND_0k4 4 - -#define NORMALIZE_SPECS_Q_OUT 6 -#define ENER_FX_Q_GUARD 1 - -/*-------------------------------------------------------------------* - * NoiseFill_fx() - * - * noise fill function for unvoiced/inactive frames (used only in AMR-WB IO mode) - *-------------------------------------------------------------------*/ - -static void NoiseFill_fx( - Word16 *exc_diffQ_fx, /* i/o: Noise per band */ - Word16 *seed_tcx, /* i : Seed for noise */ - const Word16 Mbands_gn, /* i : number of bands */ - const Word16 Q_out /* i : Q of exc_diffQ_fx[] */ -) -{ - Word16 i_band, CurBin, EndBin; - Word32 L_temp; - Word16 fact; - CurBin = 0; - move16(); - fact = shr(24576/*0.75f*/, sub(15, Q_out)); - - FOR( i_band = 0; i_band < Mbands_gn; i_band++ ) - { - EndBin = add(CurBin, crit_bins[i_band]); - FOR( ; CurBin= 0 ) - { - L_temp = L_shl(L_temp, 1); - } - - /* (Word16)(etmp14+0.5f) */ - mDiff_len = round_fx(L_temp); - - temp = 32767; - move16(); - L_temp = L_deposit_l(0); - FOR(i = 0; i < CRIT_NOIS_BAND; i++) - { - temp2 = sub(crit_bands_loc_fx[i], mDiff_len); - temp2 = abs_s(temp2); - if (sub(temp, temp2) > 0) - { - L_temp = L_msu(L_temp, crit_bins[i], -32768); - } - temp = s_min(temp, temp2); - } - - mDiff_len = s_max(round_fx(L_temp), BIN_1k2); - - Copy(dct_in_fx, exc_diffQ_fx, mDiff_len); - set16_fx(exc_diffQ_fx+mDiff_len, 0, sub(L_FRAME, mDiff_len)); - - /*--------------------------------------------------------------------------------------* - * normalization of the spectrum and noise fill - *--------------------------------------------------------------------------------------*/ - - normalize_spec_fx(4*256, exc_diffQ_fx, mDiff_len, NORMALIZE_SPECS_Q_OUT); /* Factors in Q8 */ - NoiseFill_fx( exc_diffQ_fx, seed_tcx, CRIT_NOIS_BAND, NORMALIZE_SPECS_Q_OUT); - - /*--------------------------------------------------------------------------------------* - * Recompute energy per band of the modified excitation vector (in frequency domain) - *--------------------------------------------------------------------------------------*/ - - Ener_per_band_fx( exc_diffQ_fx, NORMALIZE_SPECS_Q_OUT, Ener_per_bd_yQ_fx ); - - /*--------------------------------------------------------------------------------------* - * Compute tilt factor and amplify HF accordingly - *--------------------------------------------------------------------------------------*/ - - temp = mult_r(sub(32767, voice_fac), 16384); /* Q15 */ - FOR(i = 240; i < L_FRAME; i++) - { - temp2 = msu_r(-7680*65536, -17564, shl(i,6)) ; /*-15 in Q9; -0.067 in Q18 and i in Q6= Q9 */ - temp2 = mult_r(temp2, temp); /* Q15*Q9+1-16 -> Q9 */ - L_temp = L_mult(exc_diffQ_fx[i],s_max(temp2,512)); /*Q(Qexc_diffQ+10) */ - exc_diffQ_fx[i] = round_fx(L_shl(L_temp,16-10));/*Qexc_diffQ */ - } - - /*--------------------------------------------------------------------------------------* - * Match the energy of the modified excitation vector to the decoded excitation - *--------------------------------------------------------------------------------------*/ - Apply_gain_fx( exc_diffQ_fx, Ener_per_bd_iQ_fx, Ener_per_bd_yQ_fx,sub(NORMALIZE_SPECS_Q_OUT, Q_dct_out) ); - /*--------------------------------------------------------------------------------------* - * Copy to the output vector - *--------------------------------------------------------------------------------------*/ - - Copy(exc_diffQ_fx, dct_out_fx, L_FRAME); - - return; -} - -/*-------------------------------------------------------------------* - * improv_amr_wb_gs_fx() - * - * Modify the decoded excitation to increase quality of - * unvoiced and audio signals (used only in AMR-WB IO mode) - *-------------------------------------------------------------------*/ -void improv_amr_wb_gs_fx( - const Word16 clas, /* i : signal frame class */ - const Word16 coder_type, /* i : coder type */ - const Word32 core_brate, /* i : bitrate allocated to the core */ - Word16 *seed_tcx, /* i/o: Seed used for noise generation */ - Word16 *old_Aq_fx, /* i/o: old LPC filter coefficient */ - Word16 *mem_syn2_fx, /* i/o: synthesis memory */ - const Word16 lt_voice_fac_fx, /* i/o: long term voice factor Q14 */ - const Word16 locattack, /* i : Flag for a detected attack */ - Word16 *Aq_fx, /* i/o: Decoded LP filter coefficient */ - Word16 *exc2_fx, /* i/o: Decoded complete excitation */ - const Word16 Q_exc2, /* i : Exponent of Exc2 */ - Word16 *mem_tmp_fx, /* i/o: synthesis temporary memory */ - Word16 *syn_fx, /* o: Decoded synthesis to be updated */ - const Word16 Q_syn, /* i : Synthesis scaling Q0 */ - const Word16 *pitch_buf_fx, /* i : Decoded pitch buffer Q6 */ - const Word16 Last_ener_fx /* i : Last energy (Q8) */ - ,const Word16 rate_switching_reset /* i : rate switching reset flag */ - ,const Word16 last_coder_type_fx /* i : Last coder_type */ -) -{ - Word16 i, exp_a, exp_b, exp_diff, j; - Word16 dct_exc_in_fx[L_FRAME], dct_exc_out_fx[L_FRAME]; - Word16 Aq_orig[NB_SUBFR*(M+1)], enr_LP_old, enr_LP_new; - - /*------------------------------------------------------------* - * Condition to enter the section on excitation modification - *------------------------------------------------------------*/ - - /* Enter the modification for all inactive frames and also for unvoiced frames if bit rate is below 8k85 */ - - test(); - test(); - test(); - test(); - test(); - test(); - IF( ( locattack == 0 && L_sub(core_brate, ACELP_12k65) <= 0) && - ( (L_sub(core_brate, ACELP_8k85) < 0 && sub(clas, AUDIO_CLAS) != 0 && - (sub(clas, UNVOICED_CLAS) == 0 || sub(clas, VOICED_TRANSITION) == 0)) || sub(coder_type, INACTIVE) == 0 ) ) - { - /*------------------------------------------------------------* - * two differents paths: - * unvoiced or inactive - * generic audio sound - * LP filter smoothing for inactive parts - *------------------------------------------------------------*/ - *seed_tcx = extract_l(L_mult0(pitch_buf_fx[0],pitch_buf_fx[3])); - /* last_coder_type_fx == UNVOICED should be understand as INACTIVE, but it is forced to UNVOICED in update_dec */ - test(); - test(); - test(); - IF( sub(coder_type, INACTIVE) == 0 && sub(Last_ener_fx, -3*256) > 0 && sub(last_coder_type_fx,UNVOICED) == 0 && rate_switching_reset == 0 ) /* 3.0 x 256 to Go to Q8 */ - { - - FOR(i =0; i < NB_SUBFR; i++) - { - Copy( Aq_fx, Aq_orig, NB_SUBFR*(M+1) ); - - exp_a = norm_s(Aq_fx[i*(M+1)]); - exp_b = norm_s(old_Aq_fx[i*(M+1)]); - exp_diff = sub(exp_a, exp_b); - IF(exp_diff>0) - { - Scale_sig(&old_Aq_fx[i*(M+1)], (M+1), negate(exp_diff)); - } - ELSE - { - Scale_sig(&Aq_fx[i*(M+1)], (M+1), exp_diff); - - } - FOR(j = i*(M+1); j < (i+1)*(M+1); j++) - { - - Aq_fx[j] = round_fx(L_mac(L_mult(ALP_FX, old_Aq_fx[j]), MALP_FX, Aq_fx[j])); - } - } - - /* check the smoothed LP filter stability */ - enr_LP_old = Enr_1_Az_fx( old_Aq_fx, L_SUBFR ); - Overflow = 0; - move16(); - - FOR( i=0; i < NB_SUBFR; i++ ) - { - enr_LP_new = Enr_1_Az_fx( Aq_fx+i*(M+1), L_SUBFR ); - - IF( (shr(enr_LP_new,7) > enr_LP_old) || Overflow ) - { - /* filter is unstable, do not modify the excitation */ - Copy( Aq_orig, Aq_fx, NB_SUBFR*(M+1) ); - Overflow = 0; - move16(); - - return; - } - - enr_LP_old = enr_LP_new; - move16(); - } - } - - /*------------------------------------------------------------* - * Find frequency representation of the excitation - * Do the excitation modification according to the content - * Go back to time domain -> Overwrite exctiation - *------------------------------------------------------------*/ - edct_16fx(exc2_fx, dct_exc_in_fx, L_FRAME, 6); - gs_dec_amr_wb_fx( core_brate, seed_tcx, dct_exc_in_fx, Q_exc2, dct_exc_out_fx, Q_exc2, pitch_buf_fx, lt_voice_fac_fx, clas, coder_type ); - - edct_16fx(dct_exc_out_fx, exc2_fx, L_FRAME, 6); - /*------------------------------------------------------------* - * Redo core synthesis at 12k8 Hz with the modified excitation - *------------------------------------------------------------*/ - - Copy( mem_tmp_fx, mem_syn2_fx, M ); - syn_12k8_fx(L_FRAME, Aq_fx, exc2_fx, syn_fx, mem_syn2_fx, 1, Q_exc2, Q_syn ); - } - - return; -} diff --git a/src/libs/libevs/lib_dec/gs_dec_fx.cpp b/src/libs/libevs/lib_dec/gs_dec_fx.cpp deleted file mode 100755 index e7979006..00000000 --- a/src/libs/libevs/lib_dec/gs_dec_fx.cpp +++ /dev/null @@ -1,606 +0,0 @@ -/*==================================================================================== - EVS Codec 3GPP TS26.442 Apr 03, 2018. Version 12.11.0 / 13.6.0 / 14.2.0 - ====================================================================================*/ - -#include "stl.h" -#include "options.h" -#include "cnst_fx.h" -#include "rom_com_fx.h" -#include "prot_fx.h" - -/*=========================================================================*/ -/* FUNCTION : void decod_audio_fx(); */ -/*-------------------------------------------------------------------------*/ -/* PURPOSE : Decode audio (AC) frames */ -/*-------------------------------------------------------------------------*/ -/* INPUT ARGUMENTS : */ -/* _ (Word16[]) Aq : LP filter coefficient Q12 */ -/* _ (Word16) coder_type : coding type Q0 */ -/* _(Word16) Q_exc :Q format of excitation */ -/*-------------------------------------------------------------------------*/ -/* OUTPUT ARGUMENTS : */ -/* _ (Word16[]) pitch_buf_fx : floating pitch values for each subframe Q6*/ -/* _ (Word16[]) voice_factors_fx: frame error rate Q15 */ -/*--------------------------------------------------------------------------*/ -/* INPUT/OUTPUT ARGUMENTS : */ -/* Decoder_State_fx *st_fx : decoder memory structure */ -/* _ (Word16[]) exc_fx : adapt. excitation exc (Q_exc) */ -/* _ (Word16[]) exc2_fx : adapt. excitation/total exc (Q_exc) */ -/*--------------------------------------------------------------------------*/ -/* RETURN ARGUMENTS : */ -/* _ None */ -/*==========================================================================*/ -void decod_audio_fx( - Decoder_State_fx *st_fx, /* i/o: decoder static memory */ - Word16 dct_epit[], /* o : GSC excitation in DCT domain */ - const Word16 *Aq, /* i : LP filter coefficient */ - const Word16 coder_type, /* i : coding type */ - Word16 *pitch_buf, /* o : floating pitch values for each subframe */ - Word16 *voice_factors, /* o : voicing factors */ - Word16 *exc, /* i/o: adapt. excitation exc */ - Word16 *exc2, /* i/o: adapt. excitation/total exc */ - Word16 *bwe_exc, /* o : excitation for SWB TBE */ - Word16 *lsf_new /* i : ISFs at the end of the frame */ - , Word16 *gain_buf /*Q14*/ -) -{ - Word16 tmp_nb_bits_tot, pit_band_idx; - Word16 code[L_SUBFR]; - Word16 Diff_len, nb_subfr, i; - Word16 nb_frame_flg; - Word16 Es_pred = 0; - Word16 Len, max_len; - Word16 gsc_attack_flag; - - Word16 low_pit; - Word16 last_bin; - Word16 nbits; - - Word16 exc_wo_nf[L_FRAME]; - - - /*---------------------------------------------------------------* - * Initialization - *---------------------------------------------------------------*/ - Diff_len = 0; - move16(); - - /* decode GSC attack flag (used to reduce possible pre-echo) */ - gsc_attack_flag = (Word16) get_next_indice_fx( st_fx, 1 ); - - /* decode GSC SWB speech flag */ - test(); - IF( sub(coder_type,INACTIVE) != 0 && L_sub(st_fx->total_brate_fx,ACELP_13k20) >= 0 ) - { - st_fx->GSC_noisy_speech_fx = (Word16) get_next_indice_fx( st_fx, 1 ); - } - - /* safety check in case of bit errors */ - test(); - IF( st_fx->GSC_noisy_speech_fx && sub(st_fx->bwidth_fx,SWB) != 0 ) - { - st_fx->BER_detect = 1; - move16(); - st_fx->GSC_noisy_speech_fx = 0; - move16(); - } - - /*---------------------------------------------------------------* - * Decode energy dynamics - *---------------------------------------------------------------*/ - IF( sub(st_fx->GSC_noisy_speech_fx,1) == 0 ) - { - nb_subfr = NB_SUBFR; - move16(); - st_fx->cor_strong_limit_fx = 0; - move16(); - st_fx->noise_lev_fx = NOISE_LEVEL_SP3; - move16(); - } - ELSE - { - IF( L_sub(st_fx->core_brate_fx,ACELP_8k00) <= 0 ) - { - st_fx->noise_lev_fx = add((Word16)get_next_indice_fx( st_fx, 2 ), NOISE_LEVEL_SP2); - } - ELSE - { - st_fx->noise_lev_fx = add((Word16)get_next_indice_fx( st_fx, 3 ), NOISE_LEVEL_SP0); - } - - /*---------------------------------------------------------------* - * Decode number of subframes - *---------------------------------------------------------------*/ - - st_fx->cor_strong_limit_fx = 1; - move16(); - nb_subfr = SWNB_SUBFR; - move16(); - - IF( L_sub(st_fx->core_brate_fx,ACELP_9k60) >= 0 ) - { - nbits = 1; - move16(); - nb_frame_flg = (Word16)get_next_indice_fx( st_fx, nbits ); - - IF( s_and(nb_frame_flg,0x1) == 0) - { - nb_subfr = 2*SWNB_SUBFR; - move16(); - st_fx->cor_strong_limit_fx = 0; - move16(); - } - } - } - - /*---------------------------------------------------------------* - * Decode the last band where the adaptive (pitch) contribution is significant - *---------------------------------------------------------------*/ - - IF( L_sub(st_fx->core_brate_fx,CFREQ_BITRATE) < 0 ) - { - nbits = 3; - move16(); - test(); - if( L_sub(st_fx->core_brate_fx,ACELP_9k60) < 0 && (sub(coder_type,INACTIVE) == 0)) - { - nbits = 1; - move16(); - } - } - ELSE - { - nbits = 4; - move16(); - } - test(); - IF( L_sub(st_fx->core_brate_fx,ACELP_9k60) < 0 && sub(coder_type,INACTIVE) != 0 ) - { - pit_band_idx = 1; - move16(); - } - ELSE - { - pit_band_idx = (Word16)get_next_indice_fx( st_fx, nbits ); - } - - IF( pit_band_idx != 0 ) - { - IF( L_sub(st_fx->core_brate_fx,ACELP_9k60) < 0 ) - { - pit_band_idx = 7+BAND1k2; - move16(); /* At low rate, if pitch model is chosen, then for to be use on extented and constant frequency range */ - } - ELSE - { - pit_band_idx = add(pit_band_idx, BAND1k2); - } - - /* detect bit errors in the bitstream */ - IF( sub(pit_band_idx,13) > 0 ) /* The maximum decodable index is 10 + BAND1k2 (3) = 13 */ - { - pit_band_idx = 13; - move16(); - st_fx->BER_detect = 1; - move16(); - } - Diff_len = mfreq_loc_div_25[pit_band_idx]; - move16(); - } - st_fx->Last_GSC_pit_band_idx_fx = pit_band_idx; - move16(); - - - /*--------------------------------------------------------------------------------------* - * Decode adaptive (pitch) excitation contribution - * Reset unvaluable part of the adaptive (pitch) excitation contribution - *--------------------------------------------------------------------------------------*/ - IF( sub(pit_band_idx,BAND1k2) > 0 ) - { - /*---------------------------------------------------------------* - * Decode adaptive (pitch) excitation contribution - *---------------------------------------------------------------*/ - test(); - IF( sub(st_fx->GSC_noisy_speech_fx,1) == 0 && sub(nb_subfr,NB_SUBFR) == 0 ) - { - Es_pred_dec_fx( st_fx, &Es_pred, GENERIC, st_fx->core_brate_fx ); - } - - dec_pit_exc_fx( st_fx, Aq, coder_type, Es_pred, pitch_buf, code, exc, bwe_exc, nb_subfr - , gain_buf - ); - - IF( L_sub(st_fx->core_brate_fx,ACELP_9k60) < 0 ) - { - minimum_fx( pitch_buf, shr(L_FRAME,6), &low_pit); - low_pit = shr(low_pit, 6); /*Q6 -> Q0 */ - - IF( sub(low_pit,64) < 0) - { - pit_band_idx = 9+BAND1k2; - move16(); - if(sub(st_fx->bwidth_fx,NB) == 0) - { - pit_band_idx = 7+BAND1k2; - move16(); - } - } - ELSE IF ( sub(low_pit,128) < 0 ) - { - pit_band_idx = 5+BAND1k2; - move16(); - } - ELSE - { - pit_band_idx = 3+BAND1k2; - move16(); - } - - Diff_len = mfreq_loc_div_25[pit_band_idx]; - move16(); - st_fx->Last_GSC_pit_band_idx_fx = pit_band_idx; - move16(); - } - - /*---------------------------------------------------------------* - * DCT transform - *---------------------------------------------------------------*/ - edct_16fx( exc, dct_epit, L_FRAME, 7 ); - - /*---------------------------------------------------------------* - * Reset unvaluable part of the adaptive (pitch) excitation contribution - *---------------------------------------------------------------*/ - - max_len = sub( L_FRAME, Diff_len ); - - if(sub(st_fx->bwidth_fx,NB) == 0) - { - max_len = sub(160,Diff_len); - } - - Len = 80; - move16(); - if( max_len < 80 ) - { - Len = max_len; - move16(); - } - - test(); - IF(L_sub(st_fx->core_brate_fx,ACELP_8k00) == 0 && sub(st_fx->bwidth_fx,NB) != 0 ) - { - FOR (i=0; i < max_len; i++) - { - dct_epit[i+Diff_len] = 0; - move16(); - } - } - ELSE - { - FOR (i = 0; i < Len; i++) - { - dct_epit[i + Diff_len] = mult_r(dct_epit[i + Diff_len],sm_table_fx[i]); - move16(); - } - - FOR (; i < max_len; i++) - { - dct_epit[i + Diff_len] = 0; - move16(); - } - } - st_fx->bfi_pitch_fx = mean_fx(pitch_buf, nb_subfr); - move16(); - st_fx->bfi_pitch_frame_fx = L_FRAME; - move16(); - - Diff_len = add(Diff_len,1); - st_fx->bpf_off_fx = 0; - move16(); - } - ELSE - { - /* No adaptive (pitch) excitation contribution */ - st_fx->bpf_off_fx = 1; - move16(); - set16_fx( dct_epit, 0, L_FRAME ); - set16_fx( pitch_buf, shl(L_SUBFR,6), NB_SUBFR ); - - set16_fx( gain_buf, 0, NB_SUBFR16k); - - st_fx->bfi_pitch_fx = shl(L_SUBFR,6); - st_fx->bfi_pitch_frame_fx = L_FRAME; - move16(); - st_fx->lp_gainp_fx = 0; - move16(); - st_fx->lp_gainc_fx = 0; - move16(); - st_fx->tilt_code_fx = 0; - move16(); - pit_band_idx = 0; - move16(); - Diff_len = 0; - move16(); - } - - /*--------------------------------------------------------------------------------------* - * GSC decoder - *--------------------------------------------------------------------------------------*/ - - /* find the current total number of bits used */ - - tmp_nb_bits_tot = st_fx->next_bit_pos_fx; - move16(); - - if( st_fx->extl_brate_fx > 0 ) - { - /* subtract 1 bit for TBE/BWE BWE flag (bit counted in extl_brate) */ - tmp_nb_bits_tot = sub(tmp_nb_bits_tot, 1); - } - - - test(); - if( sub(coder_type,INACTIVE) == 0 && L_sub(st_fx->core_brate_fx,ACELP_9k60) <= 0 ) - { - tmp_nb_bits_tot = add(tmp_nb_bits_tot,5); - } - - gsc_dec_fx(st_fx, dct_epit, pit_band_idx, Diff_len, tmp_nb_bits_tot, nb_subfr, coder_type, &last_bin, lsf_new, exc_wo_nf, st_fx->Q_exc ); - - /*--------------------------------------------------------------------------------------* - * iDCT transform - *--------------------------------------------------------------------------------------*/ - - edct_16fx( dct_epit, exc, L_FRAME, 7 ); - edct_16fx( exc_wo_nf, exc_wo_nf, L_FRAME, 7 ); - /*----------------------------------------------------------------------* - * Remove potential pre-echo in case an onset has been detected - *----------------------------------------------------------------------*/ - - pre_echo_att_fx( &st_fx->Last_frame_ener_fx, exc, gsc_attack_flag - ,st_fx->Q_exc - ,st_fx->last_coder_type_fx - ); - - /*--------------------------------------------------------------------------------------* - * Update BWE excitation - *--------------------------------------------------------------------------------------*/ - - set16_fx( voice_factors, 0, NB_SUBFR16k ); - interp_code_5over2_fx( exc, bwe_exc, L_FRAME ); - - /*--------------------------------------------------------------------------------------* - * Updates - *--------------------------------------------------------------------------------------*/ - - Copy( exc, exc2, L_FRAME ); - Copy( exc_wo_nf, exc, L_FRAME ); - - /*--------------------------------------------------------------------------------------* - * Channel aware mode parameters - *--------------------------------------------------------------------------------------*/ - - set16_fx( st_fx->tilt_code_dec_fx, 0, NB_SUBFR16k ); - - return; -} - -/*==========================================================================*/ -/* FUNCTION : void gsc_dec_fx () */ -/*--------------------------------------------------------------------------*/ -/* PURPOSE : Generic audio signal decoder */ -/*--------------------------------------------------------------------------*/ -/* INPUT ARGUMENTS : */ -/* _ (Word16) pit_band_idx : bin position of the cut-off frequency Q0 */ -/* _ (Word16) Diff_len : Lenght of the difference signal Q0 */ -/* _ (Word16) coder_type : coding type Q0 */ -/* _ (Word16) bits_used : Number of bit used before frequency Q Q0 */ -/* _ (Word16) nb_subfr : Number of subframe considered Q0 */ -/* _ (Word16) Qexc : Q format of exc_dct_in */ -/*--------------------------------------------------------------------------*/ -/* OUTPUT ARGUMENTS : */ -/* _ None */ -/*--------------------------------------------------------------------------*/ -/* INPUT/OUTPUT ARGUMENTS : */ -/* Decoder_State_fx *st_fx:Decoder State Structure */ -/* _ (Word16[]) exc_dct_in : dctof pitch-only excitation / total excitation Qexc*/ -/*--------------------------------------------------------------------------*/ -/* RETURN ARGUMENTS : */ -/* _None */ -/*==========================================================================*/ -void gsc_dec_fx( - Decoder_State_fx *st_fx, /* i/o: State structure */ - Word16 exc_dct_in[], /* i/o: dct of pitch-only excitation / total excitation */ - const Word16 pit_band_idx, /* i : bin position of the cut-off frequency */ - const Word16 Diff_len, /* i : Lenght of the difference signal (before pure spectral)*/ - const Word16 bits_used, /* i : Number of bit used before frequency Q */ - const Word16 nb_subfr, /* i : Number of subframe considered */ - const Word16 coder_type, /* i : coding type */ - Word16 *last_bin, /* i : last bin of bit allocation */ - Word16 *lsf_new, /* i : ISFs at the end of the frame */ - Word16 *exc_wo_nf, /* o : excitation (in f domain) without noisefill */ - Word16 Q_exc -) -{ - Word16 i, j, bit, nb_subbands, pvq_len; - Word16 bitallocation_band[MBANDS_GN]; - Word16 bitallocation_exc[2]; - Word16 Ener_per_bd_iQ[MBANDS_GN]; - Word16 max_ener_band[MBANDS_GN]; - Word16 exc_diffQ[L_FRAME]; - Word16 bits_per_bands[MBANDS_GN]; - Word16 concat_out[L_FRAME]; - Word16 inpulses_fx[NB_SFM]; - Word16 imaxpulse_fx[NB_SFM]; - Word16 mean_gain; - Word16 Mbands_gn = 16; - Word16 Qexc_diffQ = Q_PVQ_OUT; - Word32 L_tmp; - Word16 Q_tmp; - Word16 seed_init; - - set16_fx(inpulses_fx, 0,NB_SFM); - set16_fx(imaxpulse_fx, 0,NB_SFM); - - /*--------------------------------------------------------------------------------------* - * Initialization - *--------------------------------------------------------------------------------------*/ - bit = bits_used; - move16(); - set16_fx( exc_diffQ, 0, L_FRAME ); - - /*--------------------------------------------------------------------------------------* - * Gain decoding - *--------------------------------------------------------------------------------------*/ - - test(); - IF( st_fx->bfi_fx || st_fx->BER_detect ) - { - /* copy old gain */ - Copy( st_fx->old_y_gain_fx, Ener_per_bd_iQ, Mbands_gn ); - mean_gain = mult_r(st_fx->lp_gainc_fx,3277); /*Q3*/ - FOR( i=0; ilp_gainc_fx = mult_r(st_fx->lp_gainc_fx,32112); /*Q3*/ - } - ELSE - { - mean_gain = gsc_gaindec_fx( st_fx, Ener_per_bd_iQ, st_fx->core_brate_fx, st_fx->old_y_gain_fx, coder_type, st_fx->bwidth_fx ); - - st_fx->lp_gainc_fx = mult_r(640,mean_gain); /*10 in Q6 x Q12 -> lp_gainc in Q3 */ - } - - *last_bin = 0; - move16(); - test(); - IF( L_sub(st_fx->core_brate_fx,ACELP_8k00) == 0 && sub(st_fx->bwidth_fx,NB) != 0 ) - { - bitallocation_exc[0] = 0; - move16(); - bitallocation_exc[1] = 0; - move16(); - } - - set16_fx( bitallocation_band, 0, MBANDS_GN ); - - test(); - IF( (sub(st_fx->bfi_fx,1) == 0) || st_fx->BER_detect ) - { - /*--------------------------------------------------------------------------------------* - * Copy old spectrum - * reduce spectral dynamic - * save spectrum - *--------------------------------------------------------------------------------------*/ - test(); - IF( sub(st_fx->last_good_fx,INACTIVE_CLAS) == 0 || sub(st_fx->Last_GSC_noisy_speech_flag_fx,1) == 0 ) - { - FOR( i=0; iseed_tcx_fx),26214),5); /*Q10*/ - L_tmp = L_mac(L_tmp, st_fx->Last_GSC_spectrum_fx[i],6554); - st_fx->Last_GSC_spectrum_fx[i] = round_fx(L_tmp); /*Q10*/ - } - } - - Copy( st_fx->Last_GSC_spectrum_fx, exc_diffQ, L_FRAME ); - - FOR( i=0; iLast_GSC_spectrum_fx[i] = mult_r(st_fx->Last_GSC_spectrum_fx[i],24576); /*Q10*/ move16(); - } - - } - ELSE - { - /*--------------------------------------------------------------------------------------* - * PVQ decoder - *--------------------------------------------------------------------------------------*/ - - bands_and_bit_alloc_fx( st_fx->cor_strong_limit_fx, st_fx->noise_lev_fx, st_fx->core_brate_fx, Diff_len, bit, &bit, Ener_per_bd_iQ, - max_ener_band, bits_per_bands, &nb_subbands, NULL, NULL, &pvq_len, coder_type, st_fx->bwidth_fx, st_fx->GSC_noisy_speech_fx ); - - pvq_core_dec_fx( st_fx, gsc_sfm_start, gsc_sfm_end, gsc_sfm_size, concat_out, &Q_tmp, bit, nb_subbands, bits_per_bands, NULL, inpulses_fx, imaxpulse_fx, ACELP_CORE ); - Scale_sig(concat_out, gsc_sfm_end[nb_subbands-1], sub(Q_PVQ_OUT, Q_tmp)); - - seed_init = 0; - move16(); - - /* Reorder Q bands */ - FOR(j = 0; j < nb_subbands; j++) - { - Copy( concat_out+j*16, exc_diffQ + max_ener_band[j]*16, 16); - - *last_bin = s_max(*last_bin,max_ener_band[j]); - move16(); - - bitallocation_band[max_ener_band[j]] = 1; - move16(); - - seed_init =add(seed_init,inpulses_fx[j]); - } - test(); - IF( sub(st_fx->last_coder_type_fx, AUDIO) != 0 /* First audio frame */ - && sub(st_fx->last_coder_type_fx, UNVOICED) != 0 )/* last_coder_type == INACTIVE is overwritten in update_dec to UNVOICED */ - { - FOR( j = 0; j < shl(nb_subbands,4); j++ ) - { - IF( concat_out[j] > 0 ) - { - seed_init = extract_l(L_shl(seed_init,3)); - } - IF( concat_out[j] < 0 ) - { - seed_init = add(seed_init,3); - move16(); - } - } - - st_fx->seed_tcx_fx = seed_init; - move16(); - } - test(); - IF( L_sub(st_fx->core_brate_fx,ACELP_8k00) == 0 && sub(st_fx->bwidth_fx,NB) != 0 ) - { - if( exc_diffQ[L_FRAME8k - 2] != 0 ) - { - bitallocation_exc[0] = 1; - move16(); - } - - if( exc_diffQ[L_FRAME8k - 1] != 0 ) - { - bitallocation_exc[1] = 1; - move16(); - } - } - - Copy( exc_diffQ, st_fx->Last_GSC_spectrum_fx, L_FRAME ); - - /*--------------------------------------------------------------------------------------* - * Skip adaptive (pitch) contribution frequency band (no noise added over the time contribution) - * Find x pulses between 1.6-3.2kHz to code in the spectrum of the residual signal - * Gain is based on the inter-correlation gain between the pulses found and residual signal - *--------------------------------------------------------------------------------------*/ - freq_dnw_scaling_fx( st_fx->cor_strong_limit_fx, coder_type, st_fx->noise_lev_fx, st_fx->core_brate_fx, exc_diffQ, Qexc_diffQ ); - } - - /*--------------------------------------------------------------------------------------* - * Estimate noise level - *--------------------------------------------------------------------------------------*/ - - highband_exc_dct_in_fx( st_fx->core_brate_fx, mfreq_bindiv_loc, *last_bin, Diff_len, st_fx->noise_lev_fx, pit_band_idx, exc_diffQ, - &st_fx->seed_tcx_fx, Ener_per_bd_iQ, nb_subfr, exc_dct_in, st_fx->last_coder_type_fx, bitallocation_band, lsf_new, - st_fx->last_exc_dct_in_fx, &st_fx->last_ener_fx, st_fx->last_bitallocation_band_fx, bitallocation_exc, st_fx->bfi_fx, coder_type, - st_fx->bwidth_fx, exc_wo_nf, Qexc_diffQ, Q_exc, st_fx->GSC_noisy_speech_fx - ,st_fx->lt_ener_per_band_fx - ); - - exc_dct_in[0] = 0; - move16(); - - return; - -} diff --git a/src/libs/libevs/lib_dec/hdecnrm.cpp b/src/libs/libevs/lib_dec/hdecnrm.cpp new file mode 100644 index 00000000..a3a15bc0 --- /dev/null +++ b/src/libs/libevs/lib_dec/hdecnrm.cpp @@ -0,0 +1,368 @@ +/*==================================================================================== + EVS Codec 3GPP TS26.443 Nov 13, 2018. Version 12.11.0 / 13.7.0 / 14.3.0 / 15.1.0 + ====================================================================================*/ + +#include "options.h" +#include "cnst.h" +#include "prot.h" +#include "rom_com.h" +#include "rom_dec.h" + +/*--------------------------------------------------------------------------*/ +/* Function decode_huff_context */ +/* ~~~~~~~~~~~~~~~~~ */ +/* */ +/* Context based Huffman decoding for indices of quantized norms */ +/*--------------------------------------------------------------------------*/ +/* const short *hufftab, (i) Huffman table */ +/* short *rbits (i/o) the number of read bits */ +/*--------------------------------------------------------------------------*/ +static +short decode_huff_context( + Decoder_State *st, /* i/o: decoder state structure */ + const short *hufftab, + short *rbits +) +{ + while( *hufftab > 0) + { + *rbits+=(*hufftab & 0xf); + hufftab += (*hufftab >> 4) + get_next_indice( st, *hufftab & 0xf ); + } + + return (-*hufftab); +} + + +/*--------------------------------------------------------------------------*/ +/* Function hdecnrm */ +/* ~~~~~~~~~~~~~~~~~ */ +/* */ +/* Huffman decoding for indices of quantized norms */ +/*--------------------------------------------------------------------------*/ +/* short N (i) number of norms */ +/* short *index (o) indices of quantized norms */ +/*--------------------------------------------------------------------------*/ + +void hdecnrm( + Decoder_State *st, /* i/o: decoder state structure */ + const short N, + short *index +) +{ + short i, j, k, n, m; + short temp; + short *pidx; + + pidx = index; + + m = N - 1; + for (i=0; i> j; + *index++ = huff_tab[offset[j] + k]; + } + + /* Put back unused bits */ + st->next_bit_pos -= j; + + return; +} + + +/*-------------------------------------------------------------------------- + * hdecnrm_context() + * + * Huffman decoding for indices of quantized norms + *--------------------------------------------------------------------------*/ + +void hdecnrm_context( + Decoder_State *st, /* i/o: decoder state structure */ + const short N, /* i : number of norms */ + short *index, /* o : indices of quantized norms */ + short *n_length /* o : decoded stream length */ +) +{ + short i, prevj; + + prevj = index[0] + OFFSET_NORM; + for( i=1; i < N; i++) + { + if( prevj > HTH_NORM ) + { + /* above */ + index[i] = decode_huff_context( st, hntable, n_length); + index[i] = 31 - index[i]; + } + else + { + if( prevj < LTH_NORM ) + { + /* less */ + index[i] = decode_huff_context( st, hntable, n_length ); + } + else + { + /* equal */ + index[i] = decode_huff_context( st, hetable, n_length ); + } + } + prevj = index[i]; + } + + return; +} + +void hdecnrm_resize( + Decoder_State *st, /* i/o: decoder state structure */ + const short N, + short *index +) +{ + short i, j, k, m; + short temp; + short *pidx; + + pidx = index; + + m = N - 1; + for (i=0; i 0) - { - tmp_h = shr(hufftab[hufftab_idx],4); - tmp_l = sub(hufftab[hufftab_idx],shl(tmp_h,4)); - *rbits = add(*rbits,tmp_l); - hufftab_idx = L_add(hufftab_idx, L_add(L_deposit_l(tmp_h), get_next_indice_fx( st_fx, tmp_l ) )); - } - return negate(hufftab[hufftab_idx]); -} - - -/*--------------------------------------------------------------------------*/ -/* hdecnrm_context_fx() */ -/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */ -/* */ -/* Huffman decoding for indices of quantized norms */ -/*--------------------------------------------------------------------------*/ -/* Word16 N (i) number of norms */ -/* Word16 *index (o) indices of quantized norms */ -/* Word16 *n_length (o) decoded stream length */ -/*--------------------------------------------------------------------------*/ - -void hdecnrm_context_fx( - Decoder_State_fx *st_fx, /* i/o: decoder state structure */ - const Word16 N, - Word16 *index, - Word16 *n_length -) -{ - Word16 i, prevj, tmp; - - prevj = add(index[0], OFFSET_NORM); - FOR( i=1; i < N; i++) - { - IF( sub(prevj, HTH_NORM) >0 ) - { - /* above */ - tmp = decode_huff_context_fx( st_fx, hntable_fx, n_length); - index[i] = sub(31 , tmp); - move16(); - } - ELSE - { - IF( sub(prevj, LTH_NORM) <0 ) - { - /* less */ - index[i] = decode_huff_context_fx(st_fx, hntable_fx, n_length); - move16(); - } - ELSE - { - /* equal */ - index[i] = decode_huff_context_fx(st_fx, hetable_fx, n_length); - move16(); - } - } - prevj = index[i]; - move16(); - } - return; -} - -void hdecnrm_resize_fx( - Decoder_State_fx *st_fx, /* i/o: decoder state structure */ - const Word16 N, /* (i) number of SFMs */ - Word16 *index /* (o) norm quantization index vector */ -) -{ - Word16 i, j, k, m; - Word16 temp; - Word16 *pidx; - - pidx = index; - - m = sub(N, 1); - move16(); - FOR (i=0; inext_bit_pos_fx = sub(st_fx->next_bit_pos_fx, j); - - return; -} - -/*-------------------------------------------------------------------------- - * hdecnrm_trans() - * - * Huffman decoding for indices of quantized norms - *--------------------------------------------------------------------------*/ - -void hdecnrm_tran_fx( - Decoder_State_fx *st_fx, /* i/o: decoder state structure */ - const Word16 N, /* i : number of norms */ - Word16 *index /* o : indices of quantized norms */ -) -{ - Word16 i, j, k, n, m; - Word16 temp; - Word16 *pidx; - Word16 l; - - pidx = index; - move16(); - - m = sub(N, 1); - FOR (i=0; i +#include +#include "options.h" +#include "cnst.h" +#include "prot.h" +#include "rom_com.h" + +/*---------------------------------------------------------------------* + * Local functions + *---------------------------------------------------------------------*/ + +static void hp400_12k8(float signal[], const short lg, float mem[]); + +static void filt_6k_7k(float signal[], const short lg, float mem[]); + +static void hf_synthesis( const long core_brate, const short output_frame, const float Aq[], const float exc[], + float synth[], float synth16k[], short *seed2, float *mem_hp400, float *mem_syn_hf, + float *mem_hf, float *delay_syn_hf, float *mem_hp_interp ); + +static void hf_synthesis_amr_wb( const long core_brate, const short output_subfr, const float Ap[], float exc16k[], + float synth_out[], float *mem_syn_hf, float *delay_syn_hf, float *mem_hp_interp, float p_r, + float hf_gain_i, float til, float voice_factors, const float exc[] ); + +static void envelope( const long core_brate, const float Aq[], float Ap[], float *r, float tilt0, float tilt, + float voice_factor, float *prev_r, float *voice_fac, float *unvoicing, float *unvoicing_sm, short *unvoicing_flag); + +static void AdaptiveStartBand( short *start_band, const long rate, const float *lsf, const float voicing_fac, const short clas, short *voicing_flag, + short *start_band_old, float *OptCrit_old ); + + +/*-------------------------------------------------------------------* + * hf_synth_init() + * + * hf synthesis filters initialization + * - initialization of 400 Hz high pass filter + * - initialization of band pass 6kHz to 7kHz FIR filter + *-------------------------------------------------------------------*/ + +void hf_synth_init( + float mem_hp400[], /* o : 400 Hz high pass filter memory initialization */ + float mem_hf[] /* o : band pass 6kHz to 7kHz FIR filter initialization */ +) +{ + set_f( mem_hp400, 0, 4 ); + + set_f( mem_hf, 0, (L_FIR-1) ); + + return; +} + +/*-------------------------------------------------------------------* + * hf_synth_amr_wb_init() + * + * hf synthesis filters initialization + * - initialization of 1600 Hz low pass filter + * - initialization of band pass 6kHz to 8kHz FIR filter for noise and line resampled signals + *-------------------------------------------------------------------*/ + +void hf_synth_amr_wb_init( + float *prev_r, /* o : previous sub-frame gain */ + float *fmerit_w_sm, /* o : 1 sample memory fmerit_w param */ + float mem_syn_hf[], /* o : HF LPC synthesis filter initialization */ + short *frame_count, /* o : frame counter initialization */ + float *ne_min, /* o : minimum Noise gate - short-term energy initialization*/ + float *fmerit_m_sm, /* o : 1 sample memory fmerit_m param */ + float *voice_fac, /* o : voice factor initialization */ + float *unvoicing, /* o : unvoiced parameter */ + float *unvoicing_sm, /* o : smoothed unvoiced parameter */ + short *unvoicing_flag, /* o : unvoiced flag */ + short *voicing_flag, /* o : voiced flag */ + short *start_band_old, /* o : previous start point for copying frequency band */ + float *OptCrit_old /* o : previous criterion value for deciding the start point */ +) +{ + *prev_r = 0.0f; + set_f( mem_syn_hf, 0.0f, M ); + *fmerit_w_sm = 0.0f; + *frame_count = 0; + *ne_min = -30.0f; + *fmerit_m_sm = 0.0f; + *voice_fac = 0.0f; + *unvoicing = 0.0f; + *unvoicing_sm = 1.0f; + *unvoicing_flag = 0; + *voicing_flag = 0; + *start_band_old = 160; + *OptCrit_old = 1.0f; + + return; +} + +/*-------------------------------------------------------------------* + * hf_synth_amr_wb_reset() + * + * reset of HF synthesis filters + * - needed in switching scenarios + *-------------------------------------------------------------------*/ + +void hf_synth_amr_wb_reset( + short *seed2, /* i/o: random seed for HF noise gen */ + float mem_syn_hf[], /* o : HF synthesis memory */ + float mem_hp_interp[], /* o : interpol. memory */ + float *prev_r, /* o : previous sub-frame gain */ + float *fmerit_w_sm, /* o : 1 sample memory fmerit_w param */ + float delay_syn_hf[], /* o : HF synthesis memory */ + short *frame_count, /* o : frame counter memory */ + float *ne_min, /* o : minimum Noise gate - short-term energy memory */ + float *fmerit_m_sm, /* o : 1 sample memory fmerit_m param */ + float *voice_fac, /* o : voice factor memory */ + float *unvoicing, /* o : unvoiced parameter */ + float *unvoicing_sm, /* o : smoothed unvoiced parameter */ + short *unvoicing_flag, /* o : unvoiced flag */ + short *voicing_flag, /* o : voiced flag */ + short *start_band_old, /* o : previous start point for copying frequency band */ + float *OptCrit_old /* o : previous criterion value for deciding the start point */ +) +{ + short i; + + for( i=0; i FRAME_COUNT_HF_SYNTH && *amr_io_class == UNVOICED_CLAS ) + { + *frame_count = 0; + *ne_min = -30.0f; + } + else + { + if ( *frame_count > 2*FRAME_COUNT_HF_SYNTH ) + { + *frame_count = 2*FRAME_COUNT_HF_SYNTH; + } + else + { + (*frame_count)++; + } + + if ( ng_ener_ST < *ne_min ) + { + *ne_min = ng_ener_ST; + } + } + + voice_fac = 0.0f; + for( i=0; i 0.35f ? 0.35f : (fmerit < 0.15f ? 0.15f : fmerit); + if ( core_type == 1 ) + { + fmerit_w *= 0.5f; + } + + fmerit_w *= (1.0f + voice_fac); + *fmerit_w_sm = 0.9f*(*fmerit_w_sm) + 0.1f*fmerit_w; + fmerit_w = *fmerit_w_sm; + + fmerit_m = (2.0f - (fmerit < 0.5f ? 1.0f : fmerit)); + *fmerit_m_sm = 0.5f*(*fmerit_m_sm) + 0.5f*fmerit_m; + fmerit_m = *fmerit_m_sm; + + for (i=0; i 0 ) + { + tonal_ener += hb_tonal[i]*hb_tonal[i]; + } + } + for (; i 0 ) + { + tonal_ener += hb_tonal[i]*hb_tonal[i]; + } + } + for (; i 0 ) + { + tonal_ener += hb_tonal[i]*hb_tonal[i]; + } + } + g = beta * (hb_ener-tonal_ener)/(hb_ener - beta*tonal_ener); + if (g<0.01f && g>-0.01f) + { + inv_g = sign(g)*100; + } + else + { + inv_g = 1/g; + } + ener = 0.01f; + for (i=0; i0) + { + hb_tonal[i] *= g; + } + hb_amb[i] *= inv_g; + dct_hb[i+240] = hb_tonal[i] + hb_amb[i]; + dct_hb[i+240] *= signum[i]; + ener += dct_hb[i+240]*dct_hb[i+240]; + } + scale = (float)(gamma*sqrt(hb_ener/ener)); + + if( core_brate == ACELP_6k60 ) + { + filt_weight_coeff=60; + } + else if( core_brate == ACELP_8k85 ) + { + filt_weight_coeff=40; + } + else + { + filt_weight_coeff=20; + } + + for (i=0; i255 ) + { + dct_hb[i] *= 0.59525f; + } + + if (i >= 320-filt_weight_coeff) + { + dct_hb[i] *= filt_weight[i-320+filt_weight_coeff]; + } + } + + for( i=200; i<256; i++ ) + { + dct_hb[i] *= filt_hp[i-200]; + + if( core_brate < ACELP_23k85 ) + { + dct_hb[i] *= deem_tab[i-200]; + } + } + + if ( core_brate == ACELP_23k85 ) + { + for (i=0; i 1.0f || til0 < 0.0f ) + { + mvr2r( exc2385, exc16k, L_SUBFR16k ); + } + else + { + for ( i=0; ipp */ + *voice_fac = 0.75f*(*voice_fac) + 0.25f*voice_factor; + unvoicing_tmp = ((1.0f-tilt0)/2.0f) * (1-*voice_fac) * min(tilt/1.5f, 1.0f); + *unvoicing = 0.5f*(*unvoicing) + 0.5f*unvoicing_tmp; + + if( *unvoicing_sm > *unvoicing ) + { + *unvoicing_sm = 0.9f*(*unvoicing_sm) + 0.1f*(*unvoicing); + } + else + { + *unvoicing_sm = 0.99f*(*unvoicing_sm) + 0.01f*(*unvoicing); + } + + if (*unvoicing - *unvoicing_sm > 0.1f) + { + *unvoicing_flag = 1; + } + + if (*unvoicing - *unvoicing_sm < 0.05f) + { + *unvoicing_flag = 0; + } + + return (*unvoicing_flag && qq>pp); +} + +/*-----------------------------------------------------------------------------------* + * envelope() + * + * + *-----------------------------------------------------------------------------------*/ + +static void envelope( + const long core_brate, /* i : core bitrate */ + const float Aq[], /* i : de-quant. LPC coefficents */ + float Ap[], /* o : extended LPC coefficents */ + float *sub_gain, /* o : sub-frame gain */ + float tilt0, /* i : spectrum tilt */ + float tilt, /* i : spectrum tilt */ + float voice_factor, /* i : voice factor */ + float *prev_r, /* i/o: previous sub-frame gain */ + float *voice_fac, /* i/o: smoothed voiced parameter */ + float *unvoicing, /* i/o: unvoiced parameter */ + float *unvoicing_sm, /* i/o: smoothed unvoiced parameter */ + short *unvoicing_flag /* i/o: unvoiced flag */ +) +{ + float px, py, rx, ry, pp, rr; + short i, Unvoicing_flag; + float alpha; + float est_level1, est_level2, qx, qy, qq, env_level[3]; + float As[3], k1, k2; + + /* LPC envelope weighting */ + if( core_brate == ACELP_6k60 ) + { + weight_a( Aq, Ap, 0.9f, M ); + } + else + { + weight_a( Aq, Ap, 0.6f, M ); + } + + /* LPC envelope level estimate */ + pp = 0.0f; + px = 0.0f; + py = 0.0f; + rr = 0.0f; + rx = 0.0f; + ry = 0.0f; + for ( i=0; i<17; i++ ) + { + px += Ap[i]*exp_tab_p[i]; + py += Ap[i]*exp_tab_p[33-i]; + rx += Aq[i]*exp_tab_q[i]; + ry += Aq[i]*exp_tab_q[33-i]; + } + + pp = 1.0f/((float)sqrt(px*px+py*py)); + rr = 1.0f/((float)sqrt(rx*rx+ry*ry)); + + for ( i=0; i<3; i++ ) + { + As[i] = Aq[i]; + } + + if (As[2]==-1) + { + k2 = -0.6f; + k1 = 0.99f; + if (As[1]<0) + { + k1 = -k1; + } + } + else + { + k1 = As[1]/(1+As[2]); + k2 = As[2]; + if (k2>0.6f) + { + k2=0.6f; + } + if (k2<-0.6f) + { + k2=-0.6f; + } + if (k1>0.99f) + { + k1=0.99f; + } + if (k1<-0.99f) + { + k1=-0.99f; + } + } + + As[1]=(1+k2)*k1; + As[2]=k2; + + qq = 0.0f; + qx = 0.0f; + qy = 0.0f; + for ( i=0; i<3; i++ ) + { + qx += As[i]*exp_tab_q[i]; + qy += As[i]*exp_tab_q[33-i]; + } + + qq = 1.0f/((float)sqrt(qx*qx+qy*qy)); + + Unvoicing_flag = EnhanceClass( rr, pp, tilt0, tilt, voice_factor, voice_fac, unvoicing, unvoicing_sm, unvoicing_flag ); + + alpha = 0.0f; + if ( Unvoicing_flag ) + { + if (rr > (*prev_r)) + { + rr = 0.5f*rr + 0.5f*(*prev_r); + } + + *prev_r = rr; + rr *= min(1.0f, tilt*(1.6f - voice_factor)); + qq *= max(1.0f, tilt*(1.6f - voice_factor)); + rr = min(rr,qq); + rr= max(rr,pp); + } + else + { + if (rr < 1.0f && (*prev_r) < 1.0f) + { + alpha = (1-rr*rr); + } + + rr = alpha*(*prev_r) + (1-alpha)*rr; + *prev_r = rr; + + est_level1 = qq * min(1.0f, tilt*(1.6f - voice_factor)); + env_level[0] = pp; + env_level[1] = qq; + env_level[2] = rr; + v_sort( env_level, 0, 2 ); + rr = env_level[0]; + est_level2 = rr * (1.0f + (float)fabs(tilt-1) * (1.6f - voice_factor)); + rr = min(est_level1, est_level2); + } + + *sub_gain = min(5.0f, rr/pp); + + return; +} + +/*---------------------------------------------------------------------* + * AdaptiveStartBand() + * + * adaptively select the start band of bandwidth extension + *---------------------------------------------------------------------*/ + +static void AdaptiveStartBand( + short *start_band, /* o : start point of copied band */ + const long rate, /* i : core bitrate */ + const float *lsf, /* i : lsf frequency */ + const float voicing_fac, /* i : voicing factors */ + const short clas, /* i : signal class (determined by FEC algorithm)*/ + short *voicing_flag, + short *start_band_old, + float *OptCrit_old +) +{ + float lsf_diff[M], Crit, OptCrit = 1.0f, W; + short i, pos, M2, voicing_flag_old; + short tmp1, tmp2; + + /*voicing switching flag : to avoid switching start band frequently in VOICED or AUDIO area*/ + voicing_flag_old = *voicing_flag; + if( voicing_fac > 0.4f || (voicing_fac > 0.3f && clas >= VOICED_CLAS) || clas == AUDIO_CLAS ) + { + *voicing_flag = 1; + } + + if( voicing_fac < 0.2f && clas < VOICED_CLAS ) + { + *voicing_flag = 0; + } + + /* rate adaptive start band */ + *start_band = 160; + if( rate < ACELP_23k05 ) + { + for(i=1; i<(M-1); i++) + { + lsf_diff[i] = lsf[i] - lsf[i-1]; + } + + W = SQR(1.0f*rate/ACELP_19k85) / 6000.0f; + + if (clas == AUDIO_CLAS) + { + W *= 0.75f; + } + + pos = 2; + M2 = M-2; + if( *voicing_flag == 1 ) + { + if( rate <= ACELP_8k85 ) + { + M2 = M-8; + } + else if( rate <= ACELP_12k65 ) + { + M2 = M-6; + } + else if( rate <= ACELP_15k85 ) + { + M2 = M-4; + } + } + + for(i=2; i 64 ) ) + { + *OptCrit_old = OptCrit; + if ( abs((*start_band)-(*start_band_old))<20 && *voicing_flag==1 && voicing_flag_old==1 ) + { + *start_band = *start_band_old; + } + } + else + { + if (OptCrit<(*OptCrit_old) && (*voicing_flag)==1) + { + *OptCrit_old = OptCrit; + } + + *start_band = *start_band_old; + } + + if (clas == AUDIO_CLAS) + { + *start_band = min(*start_band, 120); + } + + if( *start_band % 2 != 0 ) + { + *start_band -= 1; + } + } + + *start_band_old = *start_band; + + return; +} + + +/*-------------------------------------------------------------------* + * hf_synth_reset() + * + * Reset of HF synthesis filters (needed in switching scenarios) + *-------------------------------------------------------------------*/ + +void hf_synth_reset( + short *seed2, /* i/o: random seed for HF noise gen */ + float mem_hf[], /* o : HF band-pass filter memory */ + float mem_syn_hf[], /* o : HF synthesis memory */ + float mem_hp400[], /* o : memory of hp 400 Hz filter */ + float mem_hp_interp[], /* o : interpol. memory */ + float delay_syn_hf[] /* o : HF synthesis memory */ +) +{ + short i; + + for( i=0; i 0.8 ==> - 14 dB (voiced) + * tilt 0.5 ==> - 6 dB (voiced or noise) + * tilt < 0.0 ==> 0 dB (noise) + *-----------------------------------------------------------------------------------*/ + +static void hf_synthesis( + const long core_brate, /* i : core bitrate */ + const short output_subfr, /* i : output sub-frame length */ + const float Aq[], /* i : quantized Aq */ + const float exc[], /* i : excitation at 12.8 kHz */ + float synth[], /* i/o: 12.8kHz synthesis signal */ + float synth16k[], /* i/o: 16kHz synthesis signal */ + short *seed2, /* i/o: random seed for HF noise gen */ + float *mem_hp400, /* i/o: memory of hp 400 Hz filter */ + float *mem_syn_hf, /* i/o: HF synthesis memory */ + float *mem_hf, /* i/o: HF band-pass filter memory */ + float *delay_syn_hf, /* i/o: HF synthesis memory */ + float *mem_hp_interp /* i/o: interpol. memory */ +) +{ + short i, delay; + float tmp, ener, fac, scale; + float HF_exc[L_SUBFR16k], HF_syn[L_SUBFR16k], upsampled_HF_syn[L_FRAME48k/NB_SUBFR]; + float temp_buffer[NS2SA(16000,DELAY_CLDFB_NS) - L_FILT16k]; + float Ap[M16k+1]; + + /*-----------------------------------------------------------------* + * generate white noise vector + *-----------------------------------------------------------------*/ + + for( i=0; i 1.0f ) + { + fac = 1.0f; + } + + scale *= fac; + /*-----------------------------------------------------------------* + * modify HF excitation according to both calculated scaling factors + *-----------------------------------------------------------------*/ + + for( i=0; i 6kHz..7kHz + *-----------------------------------------------------------------*/ + + weight_a( Aq, Ap, 0.6f, M ); + syn_filt( Ap, M, HF_exc, HF_syn, L_SUBFR16k, mem_syn_hf, 1 ); + + /*-----------------------------------------------------------------* + * Add filtered HF noise to speech synthesis + *-----------------------------------------------------------------*/ + + /* delay by 5 samples @16kHz to compensate CLDFB resampling delay (20samples) and HP filtering delay (roughly 15 samples) */ + delay = NS2SA(16000,DELAY_CLDFB_NS) - 15; + mvr2r( HF_syn+L_SUBFR16k-delay, temp_buffer, delay ); + mvr2r( HF_syn, HF_syn+delay, L_SUBFR16k-delay ); + mvr2r( delay_syn_hf, HF_syn, delay ); + mvr2r( temp_buffer, delay_syn_hf, delay ); + + /* interpolate the HF synthesis */ + if( output_subfr == L_FRAME48k/NB_SUBFR ) /* 48kHz sampled output */ + { + interpolate_3_over_1_allpass( HF_syn, L_SUBFR16k, upsampled_HF_syn, mem_hp_interp, allpass_poles_3_ov_2 ); + } + else if( output_subfr == L_FRAME32k/NB_SUBFR ) /* 32kHz sampled output */ + { + Interpolate_allpass_steep( HF_syn, mem_hp_interp, L_SUBFR16k, upsampled_HF_syn ); + } + else /* 16kHz sampled output */ + { + mvr2r( HF_syn, upsampled_HF_syn, L_SUBFR16k ); + } + + v_add( synth16k, upsampled_HF_syn, synth16k, output_subfr ); + + return; +} + + +/*-----------------------------------------------------------------------* + * hp400_12k8() + * + * 2nd order Cheb2 high pass filter with cut off frequency at 400 Hz. + * Optimized for fixed-point to get the following frequency response: + * + * frequency : 0Hz 100Hz 200Hz 300Hz 400Hz 630Hz 1.5kHz 3kHz + * dB loss : -infdB -30dB -20dB -10dB -3dB +6dB +1dB 0dB + * + * Algorithm : + * + * y[i] = b[0]*x[i] + b[1]*x[i-1] + b[2]*x[i-2] + * + a[1]*y[i-1] + a[2]*y[i-2]; + * + * short b[3] = {3660, -7320, 3660}; in Q12 + * short a[3] = {4096, 7320, -3540}; in Q12 + * + * float b[3] = {0.893554687, -1.787109375, 0.893554687}; + * float a[3] = {1.000000000, 1.787109375, -0.864257812}; + *-----------------------------------------------------------------------*/ + +static void hp400_12k8( + float signal[], /* i/o: signal */ + const short lg, /* i : lenght of signal */ + float mem[] /* i/o: filter memory [4] */ +) +{ + short i; + float x0, x1, x2; + float yy0, yy1, y2; + + + yy1 = mem[0]; + y2 = mem[1]; + x0 = mem[2]; + x1 = mem[3]; + + for( i=0; i 0.8 ==> - 14 dB (voiced) - * tilt 0.5 ==> - 6 dB (voiced or noise) - * tilt < 0.0 ==> 0 dB (noise) - *-----------------------------------------------------------------------------------*/ - -static void hf_synthesis_fx( - const Word32 core_brate, /* i : core bitrate */ - const Word16 output_subfr, /* i : output sub-frame length */ - const Word16 Aq[], /* i : quantized Az Q12 */ - const Word16 exc[], /* i : excitation at 12.8 kHz Q_exc */ - const Word16 Q_exc, /* i : excitation scaling */ - Word16 synth[], /* i : 12.8kHz synthesis signal Q_syn */ - Word16 synth16k[], /* i/o: 16kHz synthesis signal Q_syn */ - Word16 *seed2, /* i/o: random seed for HF noise gen */ - Word16 *mem_hp400, /* i/o: memory of hp 400 Hz filter */ - Word16 *mem_syn_hf, /* i/o: HF synthesis memory */ - Word16 *mem_hf, /* i/o: HF band-pass filter memory */ - const Word16 Q_syn, /* i : synthesis scaling */ - Word16 *delay_syn_hf, /* i/o: HF synthesis memory Q_syn */ - Word16 *memExp1, /* o : HF excitation scaling exponent */ - Word16 *mem_hp_interp, /* i/o: interpol. memory */ - const Word16 extl, /* i : flag indicating BWE */ - const Word16 CNG_mode /* i : CNG_mode */ -) -{ - Word16 i; - Word16 HF_syn[L_SUBFR16k], upsampled_HF_syn[L_FRAME48k/NB_SUBFR]; - Word16 HF_exc[L_SUBFR16k]; - Word16 temp_buffer[NS2SA(16000,DELAY_CLDFB_NS) - L_FILT16k]; - Word16 tmp, ener, exp1, exp2, scale, delay; - Word32 L_tmp; - Word16 Ap[M16k+1]; - (void)extl; - (void)CNG_mode; - - /*-----------------------------------------------------------------* - * generate white noise vector - *-----------------------------------------------------------------*/ - - Random_Fill(seed2, L_SUBFR16k, HF_exc, 3); /* 3 = Shift Right by 3 */ - /* o: HF_exc in Q-3 */ - - /*-----------------------------------------------------------------* - * calculate energy scaling factor so that white noise would have the - * same energy as exc12k8 - *-----------------------------------------------------------------*/ - - /*ener = sum2_f( exc, L_SUBFR ) + 0.01f*/ - ener = extract_h(Dot_product12(exc, exc, L_SUBFR, &exp2)); - exp2 = sub(exp2, add(Q_exc, Q_exc)); - - /*tmp = round_fx(Dot_product12(HF_exc, HF_exc, output_subfr, &exp1)); */ - L_tmp = Dot_product12(HF_exc, HF_exc, L_SUBFR16k, &exp1); - tmp = round_fx(L_tmp); - /* tmp = (float)(sqrt(ener/tmp)) */ - /* scale is -1 if tmp > ener */ - scale = shr(sub(ener, tmp), 15); - tmp = shl(tmp, scale); - exp1 = sub(exp1, scale); - - tmp = div_s(tmp, ener); - exp1 = sub(exp1, exp2); - - L_tmp = L_deposit_h(tmp); - - L_tmp = Isqrt_lc(L_tmp, &exp1); - scale = round_fx(L_tmp);/* Q18 when Q_exc=-1, HF_exc in Q-3 */ - - exp2 = sub(*memExp1, exp1); - move16(); - *memExp1 = exp1; - move16(); - - /*-----------------------------------------------------------------* - * calculate energy scaling factor to respect tilt of synth12k8 - * (tilt: 1=voiced, -1=unvoiced) - *-----------------------------------------------------------------*/ - - hp400_12k8_fx( synth, L_SUBFR, mem_hp400 ); - /* i: mem_hp400 in Q_syn */ - /* i: synth in Q_syn */ - /* o: synth in Q_syn-3 */ - - L_tmp = L_mac(1L, synth[0], synth[0]); - FOR (i = 1; i < L_SUBFR; i++) - { - L_tmp = L_mac(L_tmp, synth[i], synth[i]); - } - tmp = norm_l(L_tmp); - ener = extract_h(L_shl(L_tmp, tmp)); /* ener = r[0] */ - /*ener in Q = 2*(Q_syn-3)+1 = Q-5 when Q_syn=0*/ - - L_tmp = L_mac(1L, synth[1], synth[0]); - FOR (i = 2; i < L_SUBFR; i++) - { - L_tmp = L_mac(L_tmp, synth[i], synth[i - 1]); - } - tmp = extract_h(L_shl(L_tmp, tmp)); /* tmp = r[1] */ - /*tmp in Q = 2*(Q_syn-3)+1 = Q-5 when Q_syn=0 */ - /*we use the same normalization factor for both ener and tmp, */ - /*if the headroom in "tmp" is less than "ener", tmp can saturate */ - /*but this is ok since below we apply some thresholds to tmp */ - - tmp = s_max(0, tmp); - if (tmp > 0) - { - tmp = div_s(tmp, ener); - } - - /*-----------------------------------------------------------------* - * modify energy of white noise according to synthesis tilt - *-----------------------------------------------------------------*/ - - /* tmp = 1.0 - fac */ - tmp = add(1, sub(32767, tmp)); - - test(); - if( L_sub(core_brate,FRAME_NO_DATA) == 0 || L_sub(core_brate,SID_2k40) == 0) - { - /* emphasize HF noise in CNG */ - /*fac *= 2.0f;*/ - tmp = add(tmp, tmp); - } - tmp = s_max(tmp, 3277); /* 0.1 in Q15 */ - - /*scale *= fac;*/ - tmp = mult_r(scale, tmp); - /*-----------------------------------------------------------------* - * modify HF excitation according to both calculated scaling factors - * high pass filtering (0.94ms of delay) - *-----------------------------------------------------------------*/ - - filt_6k_7k_scale_fx( HF_exc, L_SUBFR16k, mem_hf,tmp,exp2 ); - /* i: input HF_exc is scaled in float, here scaling is done inside this filter */ - /* i: mem_hf in Q-2 */ - /* o: HF_exc in Q0 */ - - /*-----------------------------------------------------------------* - * synthesis of noise: 4.8kHz..5.6kHz --> 6kHz..7kHz - *-----------------------------------------------------------------*/ - - /*weight_a( Aq, Ap, 0.6f, M );*/ - weight_a_lc_fx(Aq, Ap, Gamma_19661_Tbl_fx, M); - /* o: Ap in Q14 */ - - Syn_filt_s( 0, Ap, M, HF_exc, HF_syn, L_SUBFR16k, mem_syn_hf, 1 ); - - /* i: Ap in Q14 */ - /* i: HF_exc in Q0 */ - /* o: HF_syn in Q0 */ - /* i/o: mem_syn_hf in Q0 */ - - Scale_sig(HF_syn, L_SUBFR16k, (add(Q_syn, exp1))); /* bring HF_syn to (Q_syn+exp1) */ - - /*-----------------------------------------------------------------* - * add filtered HF noise to speech synthesis - *-----------------------------------------------------------------*/ - - /* delay by 5 samples @16kHz to compensate CLDFB resampling delay (20samples) and HP filtering delay (roughly 15 samples) */ - delay = NS2SA(16000,DELAY_CLDFB_NS) - 15; - Copy( HF_syn+L_SUBFR16k-delay, temp_buffer, delay ); - Copy( HF_syn, HF_syn+delay, L_SUBFR16k-delay ); - Copy( delay_syn_hf, HF_syn, delay ); - Copy( temp_buffer, delay_syn_hf, delay ); - - /* interpolate the HF synthesis */ - IF( sub(output_subfr,L_SUBFR48k) == 0 ) /* 48kHz sampled output */ - { - { - Word16 s; - s = s_max(s_min(sub(s_min(Find_Max_Norm16(HF_syn, L_SUBFR16k), Find_Max_Norm16(mem_hp_interp, INTERP_3_1_MEM_LEN - 3)), 3), - sub(Find_Max_Norm16(mem_hp_interp + INTERP_3_1_MEM_LEN - 3, 3), 1)), 0 ); - Scale_sig(HF_syn, L_SUBFR16k, s); - Scale_sig(mem_hp_interp, INTERP_3_1_MEM_LEN, s); - interpolate_3_over_1_allpass_fx( HF_syn, L_SUBFR16k, upsampled_HF_syn, mem_hp_interp, allpass_poles_3_ov_2 ); - Scale_sig(upsampled_HF_syn, 3*L_SUBFR16k, -s); - Scale_sig(mem_hp_interp, INTERP_3_1_MEM_LEN, -s); - Scale_sig(HF_syn, L_SUBFR16k, -s); - } - Scale_sig( upsampled_HF_syn, L_SUBFR48k, -1 ); - } - ELSE IF( sub(output_subfr,L_SUBFR32k) == 0 ) /* 32kHz sampled output */ - { - { - Word16 s; - s = s_max(sub(s_min(Find_Max_Norm16(HF_syn, L_SUBFR16k), Find_Max_Norm16(mem_hp_interp, 2*ALLPASSSECTIONS_STEEP)),2), 0); - Scale_sig(HF_syn, L_SUBFR16k, s); - Scale_sig(mem_hp_interp, 2*ALLPASSSECTIONS_STEEP, s); - Interpolate_allpass_steep_fx( HF_syn, mem_hp_interp, L_SUBFR16k, upsampled_HF_syn ); - Scale_sig(upsampled_HF_syn, 2*L_SUBFR16k, -s); - Scale_sig(mem_hp_interp, 2*ALLPASSSECTIONS_STEEP, -s); - Scale_sig(HF_syn, L_SUBFR16k, -s); - } - } - ELSE /* 16kHz sampled output */ - { - Copy( HF_syn, upsampled_HF_syn, L_SUBFR16k ); - } - - Vr_add( synth16k, upsampled_HF_syn, synth16k, output_subfr ); - - return; -} - - -/*-------------------------------------------------------------------* - * filt_6k_7k: - * - * 15th order band pass 6kHz to 7kHz FIR filter. - * - * frequency: 4kHz 5kHz 5.5kHz 6kHz 6.5kHz 7kHz 7.5kHz 8kHz - * dB loss: -60dB -45dB -13dB -3dB 0dB -3dB -13dB -45dB - * (gain=4.0) - *-------------------------------------------------------------------*/ -static void filt_6k_7k_scale_fx( - Word16 signal[], /* i/o: signal */ - Word16 lg, /* i : length of input */ - Word16 mem[], /* i/o: memory (size=30) */ - Word16 fact, /* i : multiply factor */ - Word16 exp /* i : Mem Exponent */ -) -{ - Word16 i, x[L_FRAME48k/NB_SUBFR+(L_FIR-1)]; - Word32 L_tmp; - - Copy_Scale_sig(mem, x, L_FIR - 1, exp); - - FOR (i = 0; i < lg; i++) - { - x[i + L_FIR - 1] = shr(mult(signal[i], fact), 2); - move16(); /* gain of filter = 4 */ - } - FOR (i = 0; i < lg; i++) - { - L_tmp = L_mult(x[i], fir_6k_7k_fx[0]); - - /* Inner Loop Unrolled */ - /* All fir_6k_7k_fx[j] could be replaced by Constants and */ - /* thus the table could be removed from rom_com_fx */ - L_tmp = L_mac(L_tmp, x[i+1], fir_6k_7k_fx[1]); - L_tmp = L_mac(L_tmp, x[i+2], fir_6k_7k_fx[2]); - L_tmp = L_mac(L_tmp, x[i+3], fir_6k_7k_fx[3]); - L_tmp = L_mac(L_tmp, x[i+4], fir_6k_7k_fx[4]); - L_tmp = L_mac(L_tmp, x[i+5], fir_6k_7k_fx[5]); - L_tmp = L_mac(L_tmp, x[i+6], fir_6k_7k_fx[6]); - /*L_tmp = L_mac(L_tmp, x[i+7], fir_6k_7k_fx[7]); Coef is 0 */ - L_tmp = L_mac(L_tmp, x[i+8], fir_6k_7k_fx[8]); - L_tmp = L_mac(L_tmp, x[i+9], fir_6k_7k_fx[9]); - L_tmp = L_mac(L_tmp, x[i+10], fir_6k_7k_fx[10]); - L_tmp = L_mac(L_tmp, x[i+11], fir_6k_7k_fx[11]); - L_tmp = L_mac(L_tmp, x[i+12], fir_6k_7k_fx[12]); - L_tmp = L_mac(L_tmp, x[i+13], fir_6k_7k_fx[13]); - L_tmp = L_mac(L_tmp, x[i+14], fir_6k_7k_fx[14]); - L_tmp = L_mac(L_tmp, x[i+15], fir_6k_7k_fx[15]); - L_tmp = L_mac(L_tmp, x[i+16], fir_6k_7k_fx[16]); - L_tmp = L_mac(L_tmp, x[i+17], fir_6k_7k_fx[17]); - L_tmp = L_mac(L_tmp, x[i+18], fir_6k_7k_fx[18]); - L_tmp = L_mac(L_tmp, x[i+19], fir_6k_7k_fx[19]); - L_tmp = L_mac(L_tmp, x[i+20], fir_6k_7k_fx[20]); - L_tmp = L_mac(L_tmp, x[i+21], fir_6k_7k_fx[21]); - L_tmp = L_mac(L_tmp, x[i+22], fir_6k_7k_fx[22]); - /*L_tmp = L_mac(L_tmp, x[i+23], fir_6k_7k_fx[23]); Coef is 0 */ - L_tmp = L_mac(L_tmp, x[i+24], fir_6k_7k_fx[24]); - L_tmp = L_mac(L_tmp, x[i+25], fir_6k_7k_fx[25]); - L_tmp = L_mac(L_tmp, x[i+26], fir_6k_7k_fx[26]); - L_tmp = L_mac(L_tmp, x[i+27], fir_6k_7k_fx[27]); - L_tmp = L_mac(L_tmp, x[i+28], fir_6k_7k_fx[28]); - L_tmp = L_mac(L_tmp, x[i+29], fir_6k_7k_fx[29]); - L_tmp = L_mac(L_tmp, x[i+30], fir_6k_7k_fx[30]); - - signal[i] = round_fx(L_tmp); - } - Copy(x + lg, mem, L_FIR - 1); -} - -/*-------------------------------------------------------------------* - * hf_synth_amr_wb_init() - * - * hf synthesis filters initialization - * - initialization of 1600 Hz low pass filter - * - initialization of band pass 6kHz to 8kHz FIR filter for noise and line resampled signals - *-------------------------------------------------------------------*/ - -void hf_synth_amr_wb_init_fx( - Word16 *prev_r, /* o : previous sub-frame gain */ - Word16 *fmerit_w_sm, /* o : 1 sample memory fmerit_w param */ - Word16 mem_syn_hf_fx[], /* HF LPC synthesis filter initialization */ - Word16 *frame_count, /* o : frame counter initialization */ - Word16 *ne_min, /* o : minimum Noise gate - short-term energy initialization*/ - Word16 *fmerit_m_sm, /* o : 1 sample memory fmerit_m param */ - Word16 *voice_fac, /* o : voice factor initialization */ - Word16 *unvoicing, /* o : unvoiced parameter */ - Word16 *unvoicing_sm, /* o : smoothed unvoiced parameter */ - Word16 *unvoicing_flag, /* o : unvoiced flag */ - Word16 *voicing_flag, /* o : voiced flag */ - Word16 *start_band_old, /* o : previous start point for copying frequency band */ - Word32 *OptCrit_old /* o : previous criterion value for deciding the start point */ -) -{ - *prev_r = 0; - move16(); - set16_fx( mem_syn_hf_fx, 0, M ); - *fmerit_w_sm = 0; - move16(); - *frame_count = 0; - move16(); - *ne_min = -7680; - move16(); /*Q8*/ - *fmerit_m_sm = 0; - move16(); - *voice_fac = 0; - move16(); - *unvoicing = 0; - move16(); - *unvoicing_sm = 32767; - move16(); /*Q15*/ - *unvoicing_flag = 0; - move16(); - *voicing_flag = 0; - move16(); - *start_band_old = 160; - move16(); - *OptCrit_old = 32768; - move32(); /*Q15*/ ; - return; -} - -/*-------------------------------------------------------------------* - * hf_synth_amr_wb_reset() - * - * reset of HF synthesis filters - * - needed in switching scenarios - *-------------------------------------------------------------------*/ - -void hf_synth_amr_wb_reset_fx( - Word16 *seed2, /* i/o: random seed for HF noise gen */ - Word16 mem_syn_hf[], /* o : HF synthesis memory */ - Word16 mem_hp_interp[], /* o : interpol. memory */ - Word16 *prev_r, /* o : previous sub-frame gain */ - Word16 *fmerit_w_sm, /* o : 1 sample memory fmerit_w param */ - Word16 delay_syn_hf[], /* o : HF synthesis memory */ - Word16 *frame_count, /* o : frame counter memory */ - Word16 *ne_min, /* o : minimum Noise gate - short-term energy memory */ - Word16 *fmerit_m_sm, /* o : 1 sample memory fmerit_m param */ - Word16 *voice_fac, /* o : voice factor memory */ - Word16 *unvoicing, /* o : unvoiced parameter */ - Word16 *unvoicing_sm, /* o : smoothed unvoiced parameter */ - Word16 *unvoicing_flag, /* o : unvoiced flag */ - Word16 *voicing_flag, /* o : voiced flag */ - Word16 *start_band_old, /* o : previous start point for copying frequency band */ - Word32 *OptCrit_old /* o : previous criterion value for deciding the start point */ -) -{ - Word16 i; - - - FOR( i=0; i30-exp */ - *pt3 = round_fx(L_shl(L_tmp, sub(exp,1))); /*13 */ - *pt4++ = *pt3++; - move16(); - - pt1 += L_SUBFR; - pt2 += L_SUBFR; - } - - output_subfr = shr(output_frame , 2); - - if( sub(*amr_io_class, 7) != 0 ) - { - core_type = 0; - move16(); - } - - /* modify LF parameters for excitation weighting or sub-frame gains calculating */ - pitch_var_cur = 0; - move16(); - pt6 = pitch_buf; - pt7 = pitch_buf+1; - FOR( i = 0; i < 3; i++ ) - { - tmp1 = abs_s(sub(*pt6++, *pt7++)); /*Q5 */ - pitch_var_cur = add(pitch_var_cur, shr(tmp1,1)); /*Q6 -> Q5 */ - } - test(); - IF( sub(*frame_count, FRAME_COUNT) > 0 && *amr_io_class == UNVOICED_CLAS ) - { - *frame_count = 0; - move16(); - *ne_min = -7680; - move16();/*Q8; */ - } - ELSE - { - tmp1 = *frame_count; - move16(); - *frame_count = add(*frame_count ,1); - if(sub(tmp1, 2*FRAME_COUNT)>0) - { - *frame_count = 2*FRAME_COUNT; - move16(); - } - if ( sub(ng_ener_ST, *ne_min) < 0 ) - { - *ne_min = ng_ener_ST; - move16();/*Q8; */ - } - } - - pt6 = voice_factors; - L_tmp = L_mult(*pt6++,4096); - FOR(i = 1; i < 4; i++) - { - L_tmp = L_mac(L_tmp, *pt6++,4096); - } - - voice_fac = round_fx(L_tmp); - - /*fmerit_w = fmerit > 5734 ? 5734 : (fmerit < 2458 ? 2458 : fmerit); //Q14 */ - - fmerit_w = s_min(fmerit,5734); - fmerit_w = s_max(fmerit_w,2458); - - if ( sub(core_type, 1) == 0 ) - { - fmerit_w = shr(fmerit_w, 1); /*Q14; */ - } - - L_tmp = L_mult(fmerit_w, add(16384, voice_fac)); - fmerit_w = extract_l(L_shr(L_tmp, 15)); /*Q14 */ - /**fmerit_w_sm = add(mult_r(*fmerit_w_sm, 29491), mult_r(fmerit_w, 3277)); //Q14 */ - *fmerit_w_sm = round_fx(L_mac(L_mult(*fmerit_w_sm, 29491), fmerit_w, 3277)); /*Q14 */ - fmerit_w = *fmerit_w_sm; - move16(); - - tmp1 = fmerit; - move16(); - if(sub(fmerit, 8192) < 0) - { - tmp1 = 16384; - move16(); - } - fmerit_m = negate(add(-32768, tmp1)); - *fmerit_m_sm = add(shr(*fmerit_m_sm, 1), shr(fmerit_m, 1)); /*Q14 */ - fmerit_m = *fmerit_m_sm; - move16(); - - pt1 = til; - FOR( i = 0; i < NB_SUBFR; i++ ) - { - tmp = sub(pitch_var_cur, 320); - tmp = s_and(tmp, *pt1); - if (tmp < 0 ) - { - *pt1 = 1638; - move16(); - } - - tmp1 = sub(8192, *pt1); - *pt1 = s_max(6554, tmp1); - move16(); - tmp1 = add(*ne_min, 7680); /*Q8 */ - tmp1 = mult_r(tmp1, 7340); /*Q20 - > 0.007 //Q13 */ - *pt1 = add(*pt1, tmp1); - move16();/*Q13 */ - - L_tmp = L_mult0(*pt1, fmerit_m); /*Q13+14 */ - *pt1++ = extract_l(L_shr(L_tmp, 14)); /*Q13 */ - } - /* predict LPC coefficents and calculate sub-frame gains */ - p_Aq = Aq; - p_Ap = Ap; - pt1 = sub_gain; - pt2 = til0; - pt3 = til; - pt6 = voice_factors; - FOR( i = 0; i < NB_SUBFR; i++ ) - { - envelope_fx( core_brate, p_Aq, p_Ap, pt1, *pt2, *pt3, *pt6, prev_r, - voice_facor_sm, unvoicing, unvoicing_sm, unvoicing_flag ); - pt1++; - pt2++; - pt3++; - pt6++; - - p_Aq += (M+1); - p_Ap += (M+1); - } - - AdaptiveStartBand_fx( &start_band, core_brate, lsf_new, voice_fac, *amr_io_class, voicing_flag, start_band_old, OptCrit_old ); - - - q_tmp = Exp16Array(L_FRAME, exc); - qdct = sub(q_tmp, 1); - Copy_Scale_sig_16_32(exc, exc32, L_FRAME, qdct); - - qdct = add(qdct, Q_exc); - edct_fx(exc32, dct_exc32, L_FRAME, &qdct); - q_tmp = Exp32Array(L_FRAME, dct_exc32); - - q_tmp = sub(q_tmp,16); - Copy_Scale_sig_32_16(dct_exc32, dct_exc, L_FRAME, q_tmp); - qdct = add(qdct, q_tmp); - - set16_fx( dct_hb, 0, L_FRAME16k); - pt1 = &dct_hb[200]; - pt2 = &dct_exc[200]; - FOR ( i = 200; i < 240; i++) - { - *pt1++ = *pt2++; - move16();/*qdct */ - } - set16_fx(signum, 1, L_SUBFR16k); - pt1 = dct_hb+240; - pt2 = dct_exc+start_band; - pt3 = signum; - FOR ( i = 240; i < L_FRAME16k; i++ ) - { - if (*pt2<0) - { - *pt3 = -1; - move16(); - } - *pt1++ = abs_s(*pt2++); - move16(); /*qdct */ - pt3++; - } - hb_ener = dot_prod_satcontr(&dct_hb[240], &dct_hb[240], qdct, qdct, &q1, L_SUBFR16k); - - L_tmp = L_shl(L_mult(start_band, 205), 14); /*Q30 */ - tmp = round_fx(L_tmp); /*Q14 */ - tmp = sub(18022, tmp); /*Q14 */ - fmerit_w = round_fx(L_shl(L_mult(fmerit_w, tmp), 1)); /*Q: 14+14+1+1-16 = 14 */ - - - L_tmp = L_deposit_l(fmerit_w); /*Q14 */ - L_tmp = Isqrt(L_tmp); /*Q(31-7) */ - tmp = round_fx(L_tmp); /*Q8 */ - q2 = norm_s(tmp); - alpha = div_s(shl(1, sub(14, q2)), tmp); /*Q(29-q2-8); */ - alpha = shl(alpha, sub(q2, 7));/*Q14 */ - - beta = sub(16384, fmerit_w); /*Q14 */ - - L_tmp = L_mult(alpha, 31130); /*Q30 */ - gamma = round_fx(L_tmp); /*Q14 */ - gamma = sub(17203, gamma); /*Q14 */ - gamma = s_min(16384, gamma); - gamma = s_max(4915, gamma); - - IF ( sub(beta, 16384) < 0) - { - L_tmp = 1; /*variable for tonal energy*/ - - pt1 = hb_amb; - pt2 = hb_tonal; - pt3 = &dct_hb[240]; - FOR (i=0; i<8; i++) - { - fn = add(i,8); - tmp1 = div_s(1, fn); /*Q15 */ - tmp = 0; - move16(); - pt4 = &dct_hb[240]; - FOR (j=0; j 0 ) - { - L_tmp = L_mac0(L_tmp, shr(*pt2,1), shr(*pt2,1)); - } - pt1++; - pt2++; - pt3++; - } - FOR (; i < L_SUBFR16k-8; i++) - { - fb = sub(i,7); - fn = add(fb,15); - tmp = 0; - pt4 = &dct_hb[fb+240]; - FOR (j=fb; j 0 ) - { - L_tmp = L_mac0(L_tmp, shr(*pt2,1), shr(*pt2,1)); - } - pt1++; - pt2++; - pt3++; - } - FOR (; i 0 ) - { - L_tmp = L_mac0(L_tmp, shr(*pt2,1), shr(*pt2,1)); /*2*qdct-2 */ - } - pt1++; - pt2++; - pt3++; - } - - /*scaling of hb_ener is q1; tonal_ener0) - { - *pt1 = mult_r(*pt1,g); /*qdct */ move16(); - } - *pt2 = round_fx(L_shl(L_mult(*pt2,inv_g),3)); /*qdct */ - *pt3 = add(*pt1, *pt2); - move16(); - *pt3 = extract_l(L_mult0(*pt3, *pt4)); /*qdct */ - pt1++; - pt2++; - pt3++; - pt4++; - } - - ener = dot_prod_satcontr(&dct_hb[240], &dct_hb[240], qdct, qdct, &q2, L_SUBFR16k); - scale = div_s(shl(1, 14), hb_ener); /*Q(29-q1) */ - L_tmp = L_mult(ener, scale); /*30-q1+q2 */ - q2 = sub(q1, q2); /*30-q2 */ - scale = round_fx(Isqrt(L_shl(L_tmp, sub(q2, 24)))); /*Q12 */ - scale = round_fx(L_shl(L_mult(scale, gamma),4)); /*Q15 */ - } - ELSE - { - scale = 32767; /*~1 in Q15 */ move16(); - } - - IF ( L_sub(core_brate, ACELP_6k60) == 0 ) - { - filt_weight_coeff = 60; - move16(); - rev_filt_weight_coeff = 555; - move16(); /* 1/(filt_weight_coeff-1) Q15 */ - } - ELSE IF ( L_sub(core_brate, ACELP_8k85) == 0 ) - { - filt_weight_coeff = 40; - move16(); - rev_filt_weight_coeff = 840; - move16(); - } - ELSE - { - filt_weight_coeff = 20; - move16(); - rev_filt_weight_coeff = 1725; - move16(); - } - - pt1 = filt_weight; - FOR ( i = 0; i < filt_weight_coeff; i++) - { - L_tmp = L_mult(-32735, rev_filt_weight_coeff); /*Q31 */ - L_tmp = L_shl(Mult_32_16(L_tmp, i), 14); /*Q16+14 */ - *pt1++ = add(round_fx(L_tmp), 16384); - move16();/*Q14 */ - } - - IF ( L_sub(core_brate, ACELP_23k85) == 0 ) - { - pt1 = dct_hb+240; - tmp = sub(filt_weight_coeff, 80); - pt3 = filt_weight+tmp; - FOR( i = 240; i < L_FRAME16k; i++ ) - { - *pt1 = mult_r(*pt1, scale); /*qdct */ move16(); - - IF ( sub(i, sub(320, filt_weight_coeff)) >= 0 ) - { - *pt1 = round_fx(L_shl(L_mult(*pt3, *pt1), 1)); /*qdct */ - } - pt1++; - pt3++; - } - pt1 = dct_hb+200; - pt6 = filt_hp_fx; - FOR( i = 200; i < 256; i++ ) - { - *pt1 = mult_r(*pt6++, *pt1); - move16(); /*qdct */ - pt1++; - } - pt1 = HF_corr_gain; - pt6 = hf_gain; - FOR ( i = 0; i < NB_SUBFR; i++) - { - tmp = *pt6++; - move16(); - *pt1++ = HP_gain_fx[tmp]; - move16(); - } - } - ELSE - { - pt1 = dct_hb+240; - tmp = sub(filt_weight_coeff, 80); - pt3 = filt_weight+tmp; - FOR( i = 240; i < L_FRAME16k; i++ ) - { - *pt1 = mult_r(*pt1, scale); /*qdct */ - IF ( sub(i, 255) > 0 ) - { - *pt1 = mult_r(19505, *pt1); - move16(); - } - - IF ( sub(i, sub(320, filt_weight_coeff)) >= 0 ) - { - *pt1 = round_fx(L_shl(L_mult(*pt3, *pt1), 1)); /*qdct */ - } - pt1++; - pt3++; - } - - pt1 = dct_hb+200; - pt6 = filt_hp_fx; - pt7 = deem_tab_fx; - FOR( i = 200; i < 256; i++ ) - { - *pt1 = mult_r(*pt6++, *pt1); - move16();/*qdct */ - *pt1 = mult_r(*pt7++, *pt1); - move16(); - pt1++; - } - } - - q_tmp = Exp16Array(L_FRAME16k, dct_hb); - qhf = sub(q_tmp, 1); - Copy_Scale_sig_16_32(dct_hb, dct_hb32, L_FRAME16k, qhf); - qhf = add(qhf, qdct); - edct_fx(dct_hb32, exc16k32, L_FRAME16k, &qhf); - q_tmp = Exp32Array(L_FRAME16k, exc16k32); - q_tmp = sub(q_tmp,16); - Copy_Scale_sig_32_16(exc16k32, exc16k, L_FRAME16k, q_tmp); - qhf = add(qhf, q_tmp); - - ener = dot_prod_satcontr(exc, exc, Q_exc, Q_exc, &q1, L_FRAME); - tmp = dot_prod_satcontr(exc16k, exc16k, qhf, qhf, &q2, L_FRAME16k); - - pt6 = exc; - pt2 = exc16k; - - FOR ( i = 0; i < NB_SUBFR; i++ ) - { - e_subfr1 = dot_prod_satcontr(pt6, pt6, Q_exc, Q_exc, &q3, L_SUBFR); - e_subfr2 = dot_prod_satcontr(pt2, pt2, qhf, qhf, &q4, L_SUBFR16k); - - L_tmp = L_mult(e_subfr1, tmp); /*Q(q2+q3+1) */ - q3 = add(add(q2, q3), 1); - shift = norm_l(L_tmp); - L_tmp = L_shl(L_tmp, shift); /*Q(q3+shift); */ - q3 = add(q3, shift); - scale = round_fx(L_tmp); /*Q(q3-16); */ - q3 = sub(q3, 16); - scale = div_s(shl(1, 14), scale); /*Q(29-q3) */ - L_tmp = L_mult(scale, ener); /*Q(29-q3+q1+1) */ - shift = norm_l(L_tmp); - L_tmp = L_shl(L_tmp, shift); /*Q(29-q3+q1+1+shift) */ - scale = round_fx(L_tmp); /*Q(29-q3+q1+1+shift-16) */ - L_tmp = L_mult(scale, e_subfr2); /*Q(29-q3+q1+1+shift-16+q4+1)=Q(15+q1-q3+q4+shift) */ - q3 = sub(15, q3); - q3 = add(q3, q1); - q3 = add(q3, shift); - q3 = add(q3, q4); - scale = round_fx(Isqrt(L_shl(L_tmp, sub(6, q3)))); /*Q12 */ - - pt6 += L_SUBFR; - FOR ( j = 0; j < L_SUBFR16k; j++ ) - { - *pt2 = round_fx(L_shl(L_mult(*pt2, scale), 2)); /*qhf-1 */ - pt2++; - } - } - qhf = sub(qhf, 1); - - p_Ap = Ap; - pt1 = exc16k; - pt2 = synth_out; - pt3 = sub_gain; - pt4 = HF_corr_gain; - pt5 = til0; - pt6 = voice_factors; - pt7 = exc; - - FOR( i = 0; i < NB_SUBFR; i++ ) - { - hf_synthesis_amr_wb_fx( core_brate, output_subfr, p_Ap, pt1, pt2, - mem_syn_hf, delay_syn_hf, mem_hp_interp, *pt3, *pt4, *pt5, *pt6, pt7, - Q_exc, Q_out, qhf); - p_Ap += (M+1); - pt1 += L_SUBFR16k; - pt2 += output_subfr; - pt3++; - pt4++; - pt5++; - pt6++; - pt7 += L_SUBFR; - } - - return; -} -static void hf_synthesis_amr_wb_fx( - const Word32 core_brate, /* i : core bitrate : Q0 */ - const Word16 output_subfr, /* i : output sub-frame length : Q0 */ - const Word16 Ap[], /* i : quantized Aq : Q12 */ - Word16 exc16k[], /* i : excitation at 16 kHz : Qhf */ - Word16 synth_out[], /* i/o: synthesis signal at output Fs : Qo */ - Word16 *mem_syn_hf, /* i/o: HF synthesis memory : Qo */ - Word16 *delay_syn_hf, /* i/o: HF synthesis memory : Qo */ - Word16 *mem_hp_interp, /* i/o: interpol. memory : Qo */ - Word16 p_r, /* i : sub-frame gain : Q12 */ - Word16 HF_corr_gain, /* i : HF gain index : Q14 */ - Word16 til, /*Q14*/ - Word16 voice_factors, /*Q14*/ - const Word16 exc[], /* i : excitation at 12.8 kHz : Qi */ - const Word16 Q_exc, /*exc scaling*/ - const Word16 Q_out, /*synth_out scaling*/ - Word16 qhf /*exc16k scaling*/ -) -{ - Word16 i, delay; - Word16 HF_syn[L_SUBFR16k], upsampled_HF_syn[L_SUBFR48k]; - Word16 temp_buffer[NS2SA(16000,DELAY_CLDFB_NS)]; - Word16 ener, tmp, scale, exc2385[L_SUBFR16k]; - Word32 L_tmp; - Word16 q1, q2,q3, shift; - Word16 *pt1, *pt2, flag; - IF ( L_sub(core_brate, ACELP_23k85) == 0 ) - { - ener = dot_prod_satcontr(exc, exc, Q_exc, Q_exc, &q1, L_SUBFR); - tmp = dot_prod_satcontr(exc16k, exc16k, qhf, qhf, &q2, L_SUBFR16k); - - L_tmp = L_mult(ener, 6554); /*Q(q1+16) */ - q3 = norm_l(L_tmp); - L_tmp = L_shl(L_tmp, q3); /*Q(q1+q3+16) */ - ener = extract_h(L_tmp); /*Q(q1+q3); */ - q1 = add(q1, q3); - - scale = div_s(shl(1, 14), ener); /*Q(29-q1) */ - L_tmp = L_mult(tmp, scale); /*30-q1+q2 */ - q2 = sub(q1, q2); /*30-q2 */ - scale = round_fx(Isqrt(L_shl(L_tmp, sub(q2, 24)))); /*Q12 */ - - pt1 = exc16k; - pt2 = exc2385; - FOR ( i = 0; i < L_SUBFR16k; i++ ) - { - L_tmp = L_mult(*pt1++, HF_corr_gain); /*qhf+15*/ - L_tmp = Mult_32_16(L_tmp, scale); /*qhf-1+12+1*/ - *pt2++ = round_fx(L_shl(L_tmp, 1)); /*qhf-3*/ - } - - pt1 = exc16k; - FOR ( i = 0; i < L_SUBFR16k; i++ ) - { - *pt1 = mult_r(*pt1, p_r); /*qhf-3*/ move16(); - pt1++; - } - - qhf = sub(qhf, 3); - - ener = dot_prod_satcontr(exc16k, exc16k, qhf, qhf, &q1, L_SUBFR16k); - tmp = dot_prod_satcontr(exc2385, exc2385, qhf, qhf, &q2, L_SUBFR16k); - L_tmp = L_mult(ener, 9830); /*Q(q1+16) */ - q3 = norm_l(L_tmp); - L_tmp = L_shl(L_tmp, q3); /*Q(q1+q3+16) */ - ener = extract_h(L_tmp); /*Q(q1+q3); */ - q1 = add(q1, q3); - - scale = div_s(shl(1, 14), ener); /*Q(29-q1) */ - L_tmp = L_mult(tmp, scale); /*30-q1+q2 */ - q2 = sub(q1, q2); /*30-q2 */ - scale = round_fx(Isqrt(L_shl(L_tmp, sub(q2, 24)))); /*Q12 */ - - flag = negate(s_and(til,-0x8000)); - if (sub(scale, 4096) > 0) - { - flag = 1; - move16(); - } - IF ( flag ) - { - Copy( exc2385, exc16k, L_SUBFR16k ); - } - ELSE - { - pt1 = exc16k; - pt2 = exc2385; - FOR ( i = 0; i < L_SUBFR16k; i++ ) - { - tmp = sub(16348, shl(til, 1));/*Q14 */ - L_tmp = L_mult(tmp, sub(26214, shr(voice_factors, 1))); /*Q29*/ - tmp = round_fx(L_shr(L_tmp, 1)); /*Q12*/ - tmp = s_min(tmp, 4096); - tmp = s_max(tmp, scale); - *pt1++ = round_fx(L_shl(L_mult(*pt2++, tmp), 3))/*qhf*/; - } - } - - } - ELSE - { - pt1 = exc16k; - FOR ( i = 0; i < L_SUBFR16k; i++ ) - { - *pt1 = mult_r(*pt1, p_r); /*qhf-3*/ move16(); - pt1++; - } - - qhf = sub(qhf, 3); - } - - shift = sub(qhf, Q_out); - Syn_filt_s( shift, Ap, M, exc16k, HF_syn, L_SUBFR16k, mem_syn_hf, 1 ); /*Q_out=qhf-shift */ - - /*-----------------------------------------------------------------* - * Resample to output sampling rate - * Synchronize LB and HB components (delay componsation) - * Add synthesised high band to speech synthesis - *-----------------------------------------------------------------*/ - - /* compensate CLDFB resampling delay */ - delay = NS2SA(16000,DELAY_CLDFB_NS); - Copy( HF_syn+L_SUBFR16k-delay, temp_buffer, delay ); - Copy( HF_syn, HF_syn+delay, L_SUBFR16k-delay ); - Copy( delay_syn_hf, HF_syn, delay ); - Copy( temp_buffer, delay_syn_hf, delay ); - - IF( sub(output_subfr, L_SUBFR48k) == 0 ) /* 48kHz sampled output */ - { - Word16 s; - s = s_max(s_min(sub(s_min(Find_Max_Norm16(HF_syn, L_SUBFR16k), Find_Max_Norm16(mem_hp_interp, INTERP_3_1_MEM_LEN - 3)), 3), - sub(Find_Max_Norm16(mem_hp_interp + INTERP_3_1_MEM_LEN - 3, 3), 1)), 0 ); - Scale_sig( HF_syn, L_SUBFR16k, s ); - Scale_sig( mem_hp_interp, INTERP_3_1_MEM_LEN, s ); - - interpolate_3_over_1_allpass_fx( HF_syn, L_SUBFR16k, upsampled_HF_syn, mem_hp_interp, allpass_poles_3_ov_2 ); - - Scale_sig( upsampled_HF_syn, L_SUBFR48k, add(-s,-1) ); - Scale_sig( mem_hp_interp, INTERP_3_1_MEM_LEN, -s ); - Scale_sig( HF_syn, L_SUBFR16k, -s ); - } - ELSE IF( sub(output_subfr, L_SUBFR32k) == 0 ) /* 32kHz sampled output */ - { - Word16 s; - s = s_max( sub(s_min(Find_Max_Norm16(HF_syn, L_SUBFR16k), Find_Max_Norm16(mem_hp_interp, 2*ALLPASSSECTIONS_STEEP)),2), 0 ); - Scale_sig( HF_syn, L_SUBFR16k, s ); - Scale_sig( mem_hp_interp, 2*ALLPASSSECTIONS_STEEP, s ); - - Interpolate_allpass_steep_fx( HF_syn, mem_hp_interp, L_SUBFR16k, upsampled_HF_syn ); - - Scale_sig( upsampled_HF_syn, 2*L_SUBFR16k, -s ); - Scale_sig( mem_hp_interp, 2*ALLPASSSECTIONS_STEEP, -s ); - Scale_sig( HF_syn, L_SUBFR16k, -s ); - } - ELSE /* 16kHz sampled output */ - { - Copy( HF_syn, upsampled_HF_syn, L_SUBFR16k ); - } - - Vr_add( synth_out, upsampled_HF_syn, synth_out, output_subfr); - - return; -} - -static Word16 EnhanceClass_fx( - const Word16 qq_fx, - const Word16 pp_fx, - const Word16 tilt0_fx, /* i : spectrum tilt */ - const Word16 tilt_fx, /* i : spectrum tilt */ - const Word16 voice_factor_fx, /* i : voice factor */ - Word16 *voice_fac_fx, /* i/o: smoothed voiced parameter */ - Word16 *unvoicing_fx, /* i/o: unvoiced parameter */ - Word16 *unvoicing_sm_fx, /* i/o: smoothed unvoiced parameter */ - Word16 *unvoicing_flag /* i/o: unvoiced flag */ -) -{ - Word16 unvoicing_tmp_fx; - Word16 tmp, tmp1; - Word32 L_tmp; - - /* Decide (*unvoicing_flag) to allow BWE enhancement when qq>pp */ - /**voice_fac_fx = add(mult_r(*voice_fac_fx, 24576), mult_r(voice_factor_fx, 8192)); //Q15 */ - *voice_fac_fx = round_fx(L_mac(L_mult(*voice_fac_fx, 24576), voice_factor_fx, 8192)); /*Q15 */ - - tmp = mult_r(sub(8192, tilt0_fx), 16384); /*Q13 */ - - L_tmp = L_sub(32768, *voice_fac_fx); /*Q15 */ - - L_tmp = Mult_32_16(L_tmp, tmp); /*Q13 */ - tmp = extract_l(L_tmp); /*Q13 */ - - tmp1 = mult_r(tilt_fx, 21845); /*Q15->1/1.5 ->Q13+15-15->Q13 */ - tmp1 = s_min(tmp1, 8192); - - L_tmp = L_mult(tmp, tmp1); /*Q13+Q13+1 */ - unvoicing_tmp_fx = extract_l(L_shr(L_tmp, 12)); /*Q15 */ - - /**unvoicing_fx = add(mult_r(16384, *unvoicing_fx), mult_r(16384, unvoicing_tmp_fx)); //Q15 */ - *unvoicing_fx = round_fx(L_mac(L_mult(16384, *unvoicing_fx), 16384, unvoicing_tmp_fx)); /*Q15 */ - - IF( sub(*unvoicing_sm_fx, *unvoicing_fx) > 0 ) - { - /**unvoicing_sm_fx = add(mult_r(29491, *unvoicing_sm_fx), mult_r(3277, *unvoicing_fx)); //Q15 */ - *unvoicing_sm_fx = round_fx(L_mac(L_mult(29491, *unvoicing_sm_fx), 3277, *unvoicing_fx)); /*Q15 */ - } - ELSE - { - /**unvoicing_sm_fx = add(mult_r(32440, *unvoicing_sm_fx), mult_r(328, *unvoicing_fx)); //Q15 */ - *unvoicing_sm_fx = round_fx(L_mac(L_mult(32440, *unvoicing_sm_fx), 328, *unvoicing_fx)); /*Q15 */ - } - - if ( sub(sub(*unvoicing_fx, *unvoicing_sm_fx),3277) > 0) - { - *unvoicing_flag = 1; - } - - if ( sub(sub(*unvoicing_fx, *unvoicing_sm_fx),1638) < 0) - { - *unvoicing_flag = 0; - } - test(); - return ( *unvoicing_flag && sub(qq_fx, pp_fx)>0 ); -} - -static void envelope_fx( - const Word32 core_brate, /* i : core bitrate */ - const Word16 Aq_dyn_scal[], /* i : de-quant. LPC coefficents, dynamic scaling */ - Word16 Ap[], /* o : extended LPC coefficents, Q12 */ - Word16 *sub_gain, /* o : sub-frame gain, Q12 */ - Word16 tilt0, /* i : spectrum tilt, Q14 */ - Word16 tilt, /* i : spectrum tilt, Q13 */ - Word16 voice_factor, /* i : voice factor, Q15 */ - Word16 *prev_r, /* i/o: previous sub-frame gain, Q10 */ - Word16 *voice_fac, /* i/o: smoothed voiced parameter, Q15 */ - Word16 *unvoicing, /* i/o: unvoiced parameter, Q15 */ - Word16 *unvoicing_sm, /* i/o: smoothed unvoiced parameter, Q15*/ - Word16 *unvoicing_flag /* i/o: unvoiced flag */ -) -{ - - Word16 px, py, rx, ry, pp, rr, qx, qy, qq; /*Q10*/ - Word16 i, Unvoicing_flag; - Word16 alpha; /*Q14*/ - Word16 est_level1, est_level2; /*Q10*/ - Word32 L_tmp; - Word16 tmp, q1, q2, q3, shift; - Word16 As[3], k1, k2; - Word16 *pt1; - const Word16 *pt2, *pt3; - Word16 Aq[M+1]; - - - /* Aq has dynamic scaling - go back to Q12 to make sure there's no overflow while calculating qx,qy*/ - shift = sub(norm_s(Aq_dyn_scal[0]),2); - Copy_Scale_sig(Aq_dyn_scal, Aq, M+1, shift); - - /* LPC envelope weighting */ - IF( L_sub(core_brate,ACELP_6k60) == 0 ) - { - weight_a_lc_fx( Aq, Ap, Gamma_29491_Tbl, M ); - } - ELSE - { - weight_a_lc_fx( Aq, Ap, Gamma_19661_Tbl_fx, M ); - } - /* Ap has dynamic scaling - go back to Q12 to make sure there's no overflow while calculating px,py*/ - shift = sub(norm_s(Ap[0]),2); - IF(shift != 0) - { - Scale_sig(Ap, M+1, shift); - } - - /* LPC envelope level estimate */ - L_tmp = L_deposit_l(0); - pt1 = Ap; - pt2 = exp_tab_p_fx; - FOR ( i = 0; i <= M; i++ ) - { - L_tmp = L_mac(L_tmp, *pt1++, *pt2++); - } - q1 = norm_l(L_tmp); - L_tmp = L_shl(L_tmp, q1);/*Q(27+q1)*/ - px = round_fx(L_shr(L_tmp, 1)); /*Q(10+q1)*/ - - L_tmp = L_deposit_l(0); - - pt1 = Ap; - pt2 = exp_tab_p_fx+33; - FOR ( i = 0; i <= M; i++ ) - { - L_tmp = L_mac(L_tmp, *pt1++, *pt2--); - } - q2 = norm_l(L_tmp); - shift = sub(q1, q2); - IF ( shift >= 0 ) - { - px = shr(px, shift); - L_tmp = L_shl(L_tmp, q2);/*Q(27+q2)*/ - q1 = q2; - move16(); - } - ELSE - { - L_tmp = L_shl(L_tmp, q1);/*Q(27+q1)*/ - } - py = round_fx(L_shr(L_tmp, 1)); /*Q(10+q1)*/ - - L_tmp = L_deposit_l(0); - pt2 = Aq; - pt3 = exp_tab_q_fx; - FOR ( i = 0; i <= M; i++ ) - { - L_tmp = L_mac(L_tmp, *pt2++, *pt3++); - } - q2 = norm_l(L_tmp); - L_tmp = L_shl(L_tmp, q2);/*Q(27+q2)*/ - rx = round_fx(L_shr(L_tmp, 1)); /*Q(10+q2)*/ - - L_tmp = L_deposit_l(0); - pt2 = Aq; - pt3 = exp_tab_q_fx+33; - FOR ( i = 0; i <= M; i++ ) - { - L_tmp = L_mac(L_tmp, *pt2++, *pt3--); - } - q3 = norm_l(L_tmp); - shift = sub(q2, q3); - IF ( shift >= 0 ) - { - rx = shr(rx, shift); - L_tmp = L_shl(L_tmp, q3);/*Q(27+q3)*/ - q2 = q3; - move16(); - } - ELSE - { - L_tmp = L_shl(L_tmp, q2);/*Q(27+q2)*/ - } - ry = round_fx(L_shr(L_tmp, 1)); /*Q(10+q2)*/ - - L_tmp = L_mult(px, px); - L_tmp = L_mac(L_tmp, py, py); /*Q(21+2*q1)*/ - pp = round_fx(Isqrt(L_shr(L_tmp, add(11, shl(q1, 1))))); /*Q10*/ - - L_tmp = L_mult(rx, rx); - L_tmp = L_mac(L_tmp, ry, ry); /*Q(21+2*q1)*/ - rr = round_fx(Isqrt(L_shr(L_tmp, add(11, shl(q2, 1))))); /*Q10*/ - - Copy(Aq, As, 3); - IF ( add(2048, shr(As[2],1)) == 0 ) - { - k2 = -2458; - move16(); - k1 = 4055; - move16(); - if (As[1]<0) - { - k1 = -k1; - move16(); - } - } - ELSE - { - k1 = add(2048, shr(As[2],1)); /*Q11 */ - q1 = 11; - move16(); - q2 = norm_s(k1); - k1 = (shl(k1, q2)); /*q1+q2 */ - tmp = abs_s(k1); - q1 = add(q1, q2); - tmp = div_s(shl(1, 14), tmp); /*Q(29-q1) */ - if ( k1 < 0 ) - { - tmp = negate(tmp); - move16(); - } - - L_tmp = L_mult(As[1], tmp); /*Q(42-q1) */ - q1 = sub(q1, 14); - k1 = round_fx(L_shl(L_tmp, q1)); /*Q12 */ - k2 = As[2]; - move16(); /*Q12 */ - if ( sub(k2, 2458) > 0 ) - { - k2 = 2458; - move16(); - } - if ( add(k2, 2458) < 0 ) - { - k2 = -2458; - move16(); - } - if ( sub(k1, 4055) > 0 ) - { - k1 = 4055; - move16(); - } - if ( add(k1, 4055) < 0 ) - { - k1 = -4055; - move16(); - } - } - As[1] = add(4096, k2); - move16(); - L_tmp = L_mult(As[1], k1); /*Q25 */ - As[1] = round_fx(L_shl(L_tmp, 3)); /*Q12 */ - As[2] = k2; - move16(); /*Q12 */ - - L_tmp = L_deposit_l(0); - pt1 = As; - pt2 = exp_tab_q_fx; - FOR ( i = 0; i < 3; i++ ) - { - L_tmp = L_mac(L_tmp, *pt1++, *pt2++); - } - q1 = norm_l(L_tmp); - L_tmp = L_shl(L_tmp, q1);/*Q(27+q1)*/ - qx = round_fx(L_shr(L_tmp, 1)); /*Q(10+q1)*/ - - - L_tmp = L_deposit_l(0); - pt1 = As; - pt2 = exp_tab_q_fx+33; - FOR ( i = 0; i < 3; i++ ) - { - L_tmp = L_mac(L_tmp, *pt1++, *pt2--); - } - q2 = norm_l(L_tmp); - shift = sub(q1, q2); - IF ( shift >= 0 ) - { - qx = shr(qx, shift); - L_tmp = L_shl(L_tmp, q2);/*Q(27+q2)*/ - q1 = q2; - move16(); - } - ELSE - { - L_tmp = L_shl(L_tmp, q1);/*Q(27+q1)*/ - } - qy = round_fx(L_shr(L_tmp, 1)); /*Q(10+q1)*/ - - - L_tmp = L_mult(qx, qx); - L_tmp = L_mac(L_tmp, qy, qy); - qq = round_fx(Isqrt(L_shr(L_tmp, add(11, shl(q1, 1))))); /*Q10*/ - - Unvoicing_flag = EnhanceClass_fx( rr, pp, tilt0, tilt, voice_factor, voice_fac, unvoicing, unvoicing_sm, unvoicing_flag ); - - alpha = 0; - move16(); - IF ( Unvoicing_flag ) - { - IF ( sub(rr, (*prev_r)) > 0 ) - { - rr = shr(add(rr, (*prev_r)), 1); - } - - *prev_r = rr; - move16(); - - L_tmp = L_mult(tilt, sub(26214, shr(voice_factor, 1))); /*Q28*/ - - L_tmp = L_min(L_tmp, 268435456); - - L_tmp = Mult_32_16(L_tmp, rr); /*Q23*/ - rr = round_fx(L_shl(L_tmp, 3)); /*Q10*/ - L_tmp = L_mult(tilt, sub(26214, shr(voice_factor, 1))); /*Q28*/ - L_tmp = L_max(L_tmp, 268435456); - L_tmp = Mult_32_16(L_tmp, qq); /*Q23*/ - qq = round_fx(L_shl(L_tmp, 3)); /*Q10*/ - rr = s_min(rr, qq); - rr= s_max(rr, pp); - } - ELSE - { - test(); - IF ( sub(rr, 1024) < 0 && sub((*prev_r), 1024) < 0 ) - { - L_tmp = L_mult(rr, rr); /*Q21*/ - tmp = round_fx(L_shl(L_tmp, 9)); /*Q14*/ - L_tmp = L_sub(2097152, L_tmp); /*Q21*/ - alpha = round_fx(L_shl(L_tmp, 9)); /*Q14*/ - L_tmp = L_mult(alpha, (*prev_r)); /*Q25*/ - L_tmp = L_mac(L_tmp, tmp, rr); /*Q25*/ - rr = round_fx(L_shl(L_tmp, 1)); /*Q10*/ - } - - *prev_r = rr; - move16(); - - L_tmp = L_mult(tilt, sub(26214, shr(voice_factor, 1))); /*Q28*/ - - L_tmp = L_min(L_tmp, 268435456); - L_tmp = Mult_32_16(L_tmp, qq); /*Q23*/ - est_level1 = round_fx(L_shl(L_tmp, 3)); /*Q10*/ - - tmp = pp; - move16(); - tmp = s_min(tmp, qq); - rr = s_min(tmp, rr); - - L_tmp = L_mult(abs_s(sub(tilt, 8192)), sub(26214, shr(voice_factor, 1))); /*Q28*/ - L_tmp = L_add(L_tmp, 268435456); - L_tmp = Mult_32_16(L_tmp, rr); /*Q23*/ - est_level2 = round_fx(L_shl(L_tmp, 3)); /*Q10*/ - - rr = s_min(est_level1, est_level2); - } - - - q1 = norm_s(pp); - tmp = div_s(shl(1, sub(14, q1)), pp); /*Q(29-q1-10) */ - L_tmp = L_mult(rr, tmp);/*Q(30-q1-10+10) */ - - *sub_gain = s_min(20480,round_fx(L_shl(L_tmp, sub(q1, 2)))); /*Q12 */ - - return; - -} - -/*---------------------------------------------------------------------* - * AdaptiveStartBand_fx() - * - * adaptively select the start band of bandwidth extension - *---------------------------------------------------------------------*/ - -void AdaptiveStartBand_fx( - Word16 *start_band, /* o : start point of copied band */ - const Word32 rate, /* i : core bitrate */ - const Word16 *lsf_fx, /* i : Q2 lsf frequency */ - const Word16 voicing_fac_fx, /* i : Q14 voicing factors */ - const Word16 clas, /* i : signal class (determined by FEC algorithm)*/ - Word16 *voicing_flag, - Word16 *start_band_old, - Word32 *OptCrit_old_fx /*i/o : Q15 */ -) -{ - Word16 i, pos, M2, voicing_flag_old; - Word16 lsf_diff_fx[M]; - Word16 W_fx; - Word16 tmp1, tmp2; - Word32 L_tmp; - Word32 OptCrit_fx = 32768, Crit_fx; - Word16 *pt1, flag; - const Word16 *pt2, *pt3; - - /*voicing switching flag : to avoid switching start band frequently in VOICED or AUDIO area*/ - voicing_flag_old = *voicing_flag; - test(); - test(); - test(); - if( sub(voicing_fac_fx, 6554) > 0 || (sub(voicing_fac_fx, 4915) > 0 && sub(clas,VOICED_CLAS) >= 0) || sub(clas,AUDIO_CLAS) == 0 ) - { - *voicing_flag = 1; - move16(); - } - - test(); - if( sub(voicing_fac_fx, 3277) < 0 && sub(clas,VOICED_CLAS) < 0 ) - { - *voicing_flag = 0; - move16(); - } - - /* rate adaptive start band */ - *start_band = 160; - move16(); - IF( L_sub(rate, ACELP_23k05) < 0 ) - { - pt1 = lsf_diff_fx+1; - pt2 = lsf_fx+1; - pt3 = lsf_fx; - FOR(i=1; i<(M-1); i++) - { - *pt1++ = sub(*pt2++, *pt3++); - move16();/*Q2 */ - } - tmp1 = extract_l(Mult_32_16(rate, 27046)); /*Q14 */ - L_tmp = L_shr(L_mult0(tmp1, 22370), 15); /*Q27->1/6000 ->Q26 */ - tmp2 = extract_l(L_tmp); /*Q26 */ - W_fx = mult_r(tmp1, tmp2); /*Q25 */ - - if (sub(clas,AUDIO_CLAS) == 0) - { - W_fx = mult_r(W_fx, 24576); /*Q25 */ - } - - pos = 2; - move16(); - M2 = sub(M, 2); - IF( sub(*voicing_flag,1) == 0 ) - { - IF( L_sub(rate, ACELP_8k85) <= 0 ) - { - M2 = sub(M, 8); - } - ELSE IF( L_sub(rate, ACELP_12k65) <= 0 ) - { - M2 = sub(M, 6); - } - ELSE IF( L_sub(rate, ACELP_15k85) <= 0 ) - { - M2 = sub(M, 4); - } - } - - /*do the procedure for i==2*/ - L_tmp = L_max(L_msu(171798692, lsf_fx[2], W_fx), 171799); /* Q2.56+25+1 */ - Crit_fx = Mult_32_16(L_tmp, lsf_diff_fx[2]); /* Q2.56+25+1+2.56-15 = Q11+2.56+2.56 */ - - OptCrit_fx = L_add(Crit_fx, 0); - pos = 2; - move16(); - /*----------------------------------------------------------------*/ - - pt2 = &lsf_fx[3]; - pt1 = &lsf_diff_fx[3]; - FOR(i=3; i 0 ) ) - { - *OptCrit_old_fx = OptCrit_fx; - move16(); - test(); - test(); - if ( sub(abs_s(sub((*start_band),(*start_band_old))), 20)<0 && sub(*voicing_flag,1)==0 && sub(voicing_flag_old,1)==0 ) - { - *start_band = *start_band_old; - move16(); - } - } - ELSE - { - test(); - if (L_sub(OptCrit_fx, (*OptCrit_old_fx))<0 && sub((*voicing_flag),1)==0) - { - *OptCrit_old_fx = OptCrit_fx; - move16(); - } - - *start_band = *start_band_old; - move16(); - } - - if (sub(clas,AUDIO_CLAS) == 0) - { - *start_band = s_min(*start_band, 120); - move16(); - } - - flag = sub(s_and(*start_band, 0x0001),1); - if (flag == 0) - { - *start_band = sub(*start_band, 1); - move16(); - } - } - - *start_band_old = *start_band; - move16(); - - return; -} - diff --git a/src/libs/libevs/lib_dec/hq_classifier_dec.cpp b/src/libs/libevs/lib_dec/hq_classifier_dec.cpp new file mode 100644 index 00000000..be0a2455 --- /dev/null +++ b/src/libs/libevs/lib_dec/hq_classifier_dec.cpp @@ -0,0 +1,64 @@ +/*==================================================================================== + EVS Codec 3GPP TS26.443 Nov 13, 2018. Version 12.11.0 / 13.7.0 / 14.3.0 / 15.1.0 + ====================================================================================*/ + +#include +#include "options.h" +#include "cnst.h" +#include "prot.h" +#include "rom_com.h" + +/*--------------------------------------------------------------------------* + * hq_classifier_dec() + * + * HQ mode selector (decision_matrix) + *--------------------------------------------------------------------------*/ + +short hq_classifier_dec( /* o : Consumed bits */ + Decoder_State *st, /* i/o: decoder state structure */ + const long core_brate, /* i : Core bit rate */ + const short length, /* i : Frame length */ + short *is_transient, /* o : Transient flag */ + short *hqswb_clas /* o : HQ class */ +) +{ + short bits; + + if( length >= L_FRAME32k && core_brate <= HQ_32k ) + { + *hqswb_clas = (short)get_next_indice( st, 2 ); + if ( length == L_FRAME48k ) + { + if ( *hqswb_clas == 0 ) + { + *hqswb_clas = HQ_GEN_FB; + } + } + } + else + { + *hqswb_clas = (short)get_next_indice( st, 1 ); + } + + *is_transient = 0; + if( *hqswb_clas == HQ_TRANSIENT ) + { + *is_transient = 1; + } + + if ( *hqswb_clas == HQ_NORMAL && length == L_FRAME32k && core_brate <= HQ_32k) + { + *hqswb_clas = HQ_GEN_SWB; + } + + if( length >= L_FRAME32k && core_brate <= HQ_32k ) + { + bits = 2; + } + else + { + bits = 1; + } + + return bits; +} diff --git a/src/libs/libevs/lib_dec/hq_classifier_dec_fx.cpp b/src/libs/libevs/lib_dec/hq_classifier_dec_fx.cpp deleted file mode 100755 index f3ca591e..00000000 --- a/src/libs/libevs/lib_dec/hq_classifier_dec_fx.cpp +++ /dev/null @@ -1,70 +0,0 @@ -/*==================================================================================== - EVS Codec 3GPP TS26.442 Apr 03, 2018. Version 12.11.0 / 13.6.0 / 14.2.0 - ====================================================================================*/ - -#include "options.h" /* Compilation switches */ -#include "prot_fx.h" /* Function prototypes */ -#include "stl.h" /* required for wmc_tool */ - -/*--------------------------------------------------------------------------* - * hq_classifier_dec() - * - * HQ mode selector (decision_matrix) - *--------------------------------------------------------------------------*/ - -Word16 hq_classifier_dec_fx( /* o : Consumed bits Q0 */ - Decoder_State_fx *st_fx, /* i/o: decoder state structure */ - const Word32 core_brate, /* i : Core bit rate Q0 */ - const Word16 length, /* i : Frame length Q0 */ - Word16 *is_transient, /* o : Transient flag Q0 */ - Word16 *hqswb_clas /* o : HQ class Q0 */ -) -{ - Word16 bits; - - test(); - IF ( sub(length, L_FRAME32k) >= 0 && L_sub(core_brate, HQ_32k) <= 0 ) - { - *hqswb_clas = get_next_indice_fx( st_fx, 2 ); - move16(); - test(); - if (( sub(length, L_FRAME48k) == 0 ) && ( sub(*hqswb_clas, HQ_NORMAL) == 0 )) - { - *hqswb_clas = HQ_GEN_FB; - move16(); - } - } - ELSE - { - *hqswb_clas = get_next_indice_fx( st_fx, 1 ); - move16(); - } - - *is_transient = 0; - move16(); - if ( sub(*hqswb_clas, HQ_TRANSIENT) == 0 ) - { - *is_transient = 1; - move16(); - } - - test(); - test(); - if ( *hqswb_clas == HQ_NORMAL && sub(length, L_FRAME32k) == 0 && L_sub(core_brate, HQ_32k) <= 0) - { - *hqswb_clas = HQ_GEN_SWB; - move16(); - } - - bits = 1; - move16(); - test(); - if ( sub(length, L_FRAME32k) >= 0 && L_sub(core_brate, HQ_32k) <= 0 ) - { - bits = 2; - move16(); - } - - return bits; -} - diff --git a/src/libs/libevs/lib_dec/hq_conf_fec.cpp b/src/libs/libevs/lib_dec/hq_conf_fec.cpp new file mode 100644 index 00000000..3bb96361 --- /dev/null +++ b/src/libs/libevs/lib_dec/hq_conf_fec.cpp @@ -0,0 +1,36 @@ +/*==================================================================================== + EVS Codec 3GPP TS26.443 Nov 13, 2018. Version 12.11.0 / 13.7.0 / 14.3.0 / 15.1.0 + ====================================================================================*/ + +#include +#include +#include "options.h" +#include "cnst.h" +#include "rom_com.h" +#include "prot.h" + + +/*--------------------------------------------------------------------------* + * hq_configure_bfi() + * + * Initialization of HQ bands and subframes + *--------------------------------------------------------------------------*/ + +void hq_configure_bfi( + short *nb_sfm, /* o : Number of sub bands */ + short *num_Sb, /* o : Number of FEC sub bands ? */ + short *num_bands_p, /* o : FEC sub bands */ + short const **sfmsize, /* o : Subband bandwidths */ + short const **sfm_start, /* o : Subband start coefficients */ + short const **sfm_end /* o : Subband end coefficients */ +) +{ + *num_Sb = MAX_SB_NB; + *nb_sfm = SFM_N_NB; + mvs2s( Num_bands_NB, num_bands_p, *num_Sb ); + *sfmsize = band_len_wb; + *sfm_start = band_start_wb; + *sfm_end = band_end_wb; + + return; +} diff --git a/src/libs/libevs/lib_dec/hq_conf_fec_fx.cpp b/src/libs/libevs/lib_dec/hq_conf_fec_fx.cpp deleted file mode 100755 index 202d5e78..00000000 --- a/src/libs/libevs/lib_dec/hq_conf_fec_fx.cpp +++ /dev/null @@ -1,39 +0,0 @@ -/*==================================================================================== - EVS Codec 3GPP TS26.442 Apr 03, 2018. Version 12.11.0 / 13.6.0 / 14.2.0 - ====================================================================================*/ - -#include -#include "options.h" -#include "rom_com_fx.h" /* Static table prototypes */ -#include "prot_fx.h" -#include "cnst_fx.h" -#include "stl.h" /* required for wmc_tool */ - - -/*--------------------------------------------------------------------------* - * hq_configure_bfi_fx() - * - * Initialization of HQ bands and subframes - *--------------------------------------------------------------------------*/ -void hq_configure_bfi_fx( - Word16 *nb_sfm, /* o : Number of sub bands Q0 */ - Word16 *num_Sb, /* o : Number of FEC sub bands ? Q0 */ - Word16 *num_bands_p, /* o : FEC sub bands Q0 */ - Word16 const **sfmsize, /* o : Subband bandwidths */ - Word16 const **sfm_start, /* o : Subband start coefficients */ - Word16 const **sfm_end /* o : Subband end coefficients */ -) -{ - *num_Sb = MAX_SB_NB; - move16(); - *nb_sfm = SFM_N_NB; - move16(); - Copy( Num_bands_NB, num_bands_p, *num_Sb ); - *sfmsize = band_len_wb; - *sfm_start = band_start_wb; - *sfm_end = band_end_wb; - - - - return; -} diff --git a/src/libs/libevs/lib_dec/hq_core_dec.cpp b/src/libs/libevs/lib_dec/hq_core_dec.cpp new file mode 100644 index 00000000..b6abfd38 --- /dev/null +++ b/src/libs/libevs/lib_dec/hq_core_dec.cpp @@ -0,0 +1,365 @@ +/*==================================================================================== + EVS Codec 3GPP TS26.443 Nov 13, 2018. Version 12.11.0 / 13.7.0 / 14.3.0 / 15.1.0 + ====================================================================================*/ + +#include +#include "options.h" +#include "cnst.h" +#include "prot.h" +#include "rom_com.h" + +/*-------------------------------------------------------------------------- + * hq_core_dec() + * + * HQ core decoder + *--------------------------------------------------------------------------*/ + +void hq_core_dec( + Decoder_State *st, /* i/o: decoder state structure */ + float synth[], /* o : output synthesis */ + const short output_frame, /* i : output frame length */ + const short hq_core_type, /* i : HQ core type */ + const short core_switching_flag /* i : ACELP->HQ switching frame flag */ +) +{ + short num_bits, is_transient, hqswb_clas, inner_frame; + short i, j, flag_uv, num_Sb, nb_sfm; + short ynrm[NB_SFM], num_bands_p[MAX_SB_NB]; + float ener_match, mean_en_high; + float t_audio_q[L_FRAME48k], wtda_audio[2*L_FRAME48k]; + short delay_comp; + float normq[NB_SFM], SWB_fenv[SWB_FENV+DIM_FB]; + const short *sfmsize, *sfm_start, *sfm_end; + float gapsynth[L_FRAME48k]; + + + /*-------------------------------------------------------------------------- + * Initializations + *--------------------------------------------------------------------------*/ + + set_f( t_audio_q, 0.0f, L_FRAME48k ); + set_f( gapsynth, 0.0f, L_FRAME48k ); + set_s( num_bands_p, 0, MAX_SB_NB ); + set_s( ynrm, 39, NB_SFM ); /* Initialize to the smallest value */ + mean_en_high = 0.0f; + sfm_start = sfm_end = NULL; + num_Sb = nb_sfm = 0; + + if (st->tcx_cfg.tcx_curr_overlap_mode == FULL_OVERLAP) + { + st->tcx_cfg.tcx_last_overlap_mode = ALDO_WINDOW; + } + else + { + st->tcx_cfg.tcx_last_overlap_mode = st->tcx_cfg.tcx_curr_overlap_mode; + } + st->tcx_cfg.tcx_curr_overlap_mode = ALDO_WINDOW; + + /*-------------------------------------------------------------------------- + * Find the number of bits for transform-domain coding + *--------------------------------------------------------------------------*/ + + /* set the total bit-budget */ + num_bits = (short)(st->total_brate / 50); + + if( !st->bfi ) + { + if( core_switching_flag ) + { + /* Preprocessing in the first HQ frame after ACELP frame */ + core_switching_hq_prepare_dec( st, &num_bits, output_frame ); + + /* During ACELP->HQ core switching, limit the HQ core bitrate to 48kbps */ + if( num_bits > HQ_48k / 50 ) + { + num_bits = (short)(HQ_48k / 50); + } + } + + /* subtract signalling bits */ + num_bits -= st->next_bit_pos; + + /* set FEC parameters */ + flag_uv = 1 - st->HqVoicing; + + /* subtract the number of bits for pitch & gain at higher bitrates */ + if ( !(core_switching_flag) && st->core_brate > MINIMUM_RATE_TO_ENCODE_VOICING_FLAG ) + { + st->HqVoicing = (short) get_next_indice( st, 1 ); + num_bits -= 1; + } + else + { + st->HqVoicing = 0; + if ( st->core_brate > MINIMUM_RATE_TO_ENCODE_VOICING_FLAG ) + { + st->HqVoicing = 1; + } + } + } + else + { + flag_uv = 0; + } + + /* set inner frame (== coded bandwidth) length */ + inner_frame = inner_frame_tbl[st->bwidth]; + + if( st->bfi == 0) + { + if( output_frame >= L_FRAME16k ) + { + st->ph_ecu_HqVoicing = st->HqVoicing; + } + else + { + st->ph_ecu_HqVoicing = 0; + } + } + + if( output_frame == L_FRAME8k ) + { + hq_configure_bfi( &nb_sfm, &num_Sb, num_bands_p, &sfmsize, &sfm_start, &sfm_end ); + } + + /*-------------------------------------------------------------------------- + * transform-domain decoding + *--------------------------------------------------------------------------*/ + + if( st->bfi ) + { + is_transient = st->old_is_transient[0]; + if( output_frame >= L_FRAME16k ) + { + hq_ecu( st->prev_good_synth, t_audio_q, &st->time_offs, st->X_sav, &st->num_p, st->plocs, st->plocsi, st->env_stab, + &st->last_fec, st->ph_ecu_HqVoicing, &st->ph_ecu_active, gapsynth, st->prev_bfi, st->old_is_transient, + st->mag_chg_1st, st->Xavg, &st->beta_mute, output_frame, st ); + } + else + { + HQ_FEC_processing( st, t_audio_q, is_transient, st->ynrm_values, st->r_p_values, num_Sb, nb_sfm, num_bands_p, + output_frame, sfm_start, sfm_end ); + } + + st->old_is_transient[2] = st->old_is_transient[1]; + st->old_is_transient[1] = st->old_is_transient[0]; + + if( output_frame >= L_FRAME16k ) + { + /* keep st->previoussynth updated as in FEC_HQ_pitch_analysis but no LP analysis */ + delay_comp = NS2SA(st->output_Fs, DELAY_CLDFB_NS); + mvr2r( st->previoussynth + delay_comp, st->previoussynth, output_frame - delay_comp ); + mvr2r( st->delay_buf_out, st->previoussynth + output_frame - delay_comp, delay_comp ); + + flag_uv = 1; /* disable costly pitch out synthesis in bfi frame */ + st->HqVoicing = 1-flag_uv; /* safety setting for HQ->ACELP switch logic */ + set_f( st->fer_samples, 0.0f, L_FRAME48k ); /* safety, create a known signal state for HQ->ACELP switch logic */ + } + } + else + { + if( hq_core_type == LOW_RATE_HQ_CORE ) + { + if(st->prev_bfi == 1 ) + { + set_f( st->last_ni_gain, 0, BANDS_MAX ); + set_f( st->last_env, 0, BANDS_MAX ); + st->last_max_pos_pulse = 0; + } + + /* HQ low rate decoder */ + hq_lr_dec( st, t_audio_q, inner_frame, num_bits, &is_transient ); + + hqswb_clas = is_transient; + } + else + { + /* HQ high rate decoder */ + hq_hr_dec( st, t_audio_q, inner_frame, num_bits, ynrm, &is_transient, &hqswb_clas, SWB_fenv ); + } + + /* scaling (coefficients are in nominal level) */ + if( output_frame != NORM_MDCT_FACTOR ) + { + ener_match = (float)sqrt((float)output_frame/(float)NORM_MDCT_FACTOR); + + for( i=0; ibws_cnt1 > 0 ) + { + ener_match = (float)st->bws_cnt1 / (float)N_NS2W_FRAMES; + + if( is_transient ) + { + for( i = 0; i < NUM_TIME_SWITCHING_BLOCKS; i++ ) + { + for( j=inner_frame_tbl[st->bwidth-1]/NUM_TIME_SWITCHING_BLOCKS; jbwidth-1]; it_audio_q, 80 ); + } + else + { + mvr2r( t_audio_q, st->t_audio_q, L_FRAME ); + } + + /*-------------------------------------------------------------------------- + * Inverse transform + * Overlap-add + * Pre-echo reduction + *--------------------------------------------------------------------------*/ + + if( output_frame == L_FRAME8k || st->bfi == 0) + { + if((output_frame != inner_frame) && (st->bfi == 1)) + { + inverse_transform( t_audio_q, wtda_audio, is_transient, output_frame, output_frame ); + } + else + { + inverse_transform( t_audio_q, wtda_audio, is_transient, output_frame, inner_frame ); + } + } + if( output_frame == L_FRAME8k ) + { + if( st->bfi == 0 && st->prev_bfi == 0 ) + { + mvr2r( st->old_out + (short)(N_ZERO_MDCT_NS*output_frame/FRAME_SIZE_NS), st->prev_oldauOut, output_frame - (short)(N_ZERO_MDCT_NS*output_frame/FRAME_SIZE_NS) ); + } + else if( st->prev_bfi == 1 ) + { + set_f( st->prev_oldauOut, 0.0f, output_frame ); + } + if( (st->prev_bfi == 1 || st->bfi == 1) && !st->old_is_transient[2] && st->last_core == HQ_CORE && st->last_codec_mode == MODE1) + { + time_domain_FEC_HQ( st, wtda_audio, synth, mean_en_high, output_frame ); + } + else + { + window_ola( wtda_audio, synth, st->old_out, output_frame, st->tcx_cfg.tcx_last_overlap_mode, st->tcx_cfg.tcx_curr_overlap_mode, st->prev_bfi, st->oldHqVoicing, st->oldgapsynth ); + st->phase_mat_next = 0; + } + + if( (!st->bfi && !st->prev_bfi) || (!(output_frame >= L_FRAME16k)) ) + { + preecho_sb( st->core_brate, wtda_audio, synth, output_frame, &st->memfilt_lb, &st->mean_prev_hb, &st->smoothmem, + &st->mean_prev, &st->mean_prev_nc, &st->wmold_hb, &st->prevflag, &st->pastpre, st->bwidth ); + } + + } + else + { + if( st->bfi && output_frame >= L_FRAME16k) + { + window_ola( t_audio_q, synth, st->old_out, output_frame, ALDO_WINDOW, ALDO_WINDOW, st->prev_bfi && !st->ph_ecu_active, st->oldHqVoicing, st->oldgapsynth ); + } + else + { + window_ola( wtda_audio, synth, st->old_out, output_frame, st->tcx_cfg.tcx_last_overlap_mode, st->tcx_cfg.tcx_curr_overlap_mode, st->prev_bfi && !st->ph_ecu_active, st->oldHqVoicing, st->oldgapsynth ); + } + + if( (!st->bfi && !st->prev_bfi) || (!(output_frame >= L_FRAME16k)) ) + { + preecho_sb( st->core_brate, wtda_audio, synth, output_frame, &st->memfilt_lb, &st->mean_prev_hb, &st->smoothmem, + &st->mean_prev, &st->mean_prev_nc, &st->wmold_hb, &st->prevflag, &st->pastpre, st->bwidth ); + } + + } + + if (!st->bfi + && st->prev_bfi + && st->last_total_brate >= HQ_48k + && st->last_codec_mode == MODE2 + && (st->last_core_bfi == TCX_20_CORE || st->last_core_bfi == TCX_10_CORE) + && st->plcInfo.concealment_method == TCX_NONTONAL + && st->plcInfo.nbLostCmpt < 4 ) + { + waveform_adj2( + st->tonalMDCTconceal.secondLastPcmOut, + synth, + st->plcInfo.data_noise, + &st->plcInfo.outx_new_n1, + &st->plcInfo.nsapp_gain, + &st->plcInfo.nsapp_gain_n, + &st->plcInfo.recovery_gain, + st->plcInfo.step_concealgain, + st->plcInfo.Pitch, + st->plcInfo.FrameSize, + 0, + st->plcInfo.nbLostCmpt + 1, + st->bfi); + } + + if ( output_frame >= L_FRAME16k ) + { + if( st->ph_ecu_HqVoicing ) + { + st->oldHqVoicing = 1; + mvr2r( gapsynth, st->oldgapsynth, L_FRAME48k ); + } + else + { + st->oldHqVoicing = 0; + } + } + else + { + st->oldHqVoicing = 0; + } + + if( st->nbLostCmpt == FRAMECTTOSTART_MDCT ) + { + st->HqVoicing = 0; + } + + if( output_frame == L_FRAME8k ) + { + mvr2r( wtda_audio, st->oldIMDCTout, L_FRAME8k/2 ); + mvr2r( st->old_auOut_2fr + output_frame, st->old_auOut_2fr, output_frame ); + mvr2r( synth, st->old_auOut_2fr + output_frame, output_frame ); + } + + + /* update buffer of old subframe pitch values */ + if( st->last_core == HQ_CORE && st->L_frame != st->last_L_frame ) + { + set_f( &st->old_pitch_buf[st->L_frame/L_SUBFR], (float)L_SUBFR, st->L_frame/L_SUBFR ); + } + mvr2r( &st->old_pitch_buf[st->L_frame/L_SUBFR], st->old_pitch_buf, st->L_frame/L_SUBFR ); + set_f( &st->old_pitch_buf[st->L_frame/L_SUBFR], (float)L_SUBFR, st->L_frame/L_SUBFR ); + mvr2r( &st->mem_pitch_gain[2], &st->mem_pitch_gain[st->L_frame/L_SUBFR+2], st->L_frame/L_SUBFR ); + set_zero( &st->mem_pitch_gain[2], st->L_frame/L_SUBFR ); + + + return; +} + diff --git a/src/libs/libevs/lib_dec/hq_core_dec_fx.cpp b/src/libs/libevs/lib_dec/hq_core_dec_fx.cpp deleted file mode 100755 index 72dcfb2e..00000000 --- a/src/libs/libevs/lib_dec/hq_core_dec_fx.cpp +++ /dev/null @@ -1,460 +0,0 @@ -/*==================================================================================== - EVS Codec 3GPP TS26.442 Apr 03, 2018. Version 12.11.0 / 13.6.0 / 14.2.0 - ====================================================================================*/ - -#include "options.h" /* Compilation switches */ -#include "cnst_fx.h" /* Common constants */ -#include "prot_fx.h" /* Function prototypes */ -#include "rom_com_fx.h" /* Static table prototypes */ -#include "stl.h" -/*-------------------------------------------------------------------------- - * hq_core_dec() - * - * HQ core decoder - *--------------------------------------------------------------------------*/ - -void hq_core_dec_fx( - Decoder_State_fx *st_fx, /* i/o: decoder state structure fx */ - Word16 synth[], /* o : output synthesis */ - Word16 *Q_synth, /* o : Q value of synth */ - const Word16 output_frame, /* i : output frame length */ - const Word16 hq_core_type, /* i : HQ core type */ - const Word16 core_switching_flag /* i : ACELP->HQ switching frame flag */ -) -{ - Word16 num_bits, is_transient, hqswb_clas, inner_frame; - Word16 i, j, flag_uv, num_Sb, nb_sfm; - Word16 ynrm[NB_SFM], num_bands_p[MAX_SB_NB]; - Word16 ener_match; /* Q13 */ - Word32 t_audio_q[L_FRAME48k]; /* Q12 */ - Word16 Q_audio; - Word32 wtda_audio[2*L_FRAME48k]; - Word16 delay_comp; - Word32 normq_fx[NB_SFM]; - Word16 mean_en_high_fx; - Word16 SWB_fenv_fx[SWB_FENV+DIM_FB]; - const Word16 *sfmsize, *sfm_start, *sfm_end; - Word16 gapsynth_fx[L_FRAME48k]; - Word16 tmp, tmp_loop; - Word32 L_tmp; - UWord16 lsb; - - /*-------------------------------------------------------------------------- - * Initializations - *--------------------------------------------------------------------------*/ - - set32_fx( t_audio_q, 0, L_FRAME48k ); - set16_fx( gapsynth_fx, 0, L_FRAME48k ); - set16_fx( num_bands_p, 0, MAX_SB_NB ); - set16_fx( ynrm, 39, NB_SFM ); /* Initialize to the smallest value */ - mean_en_high_fx = 0; - move16(); - Q_audio = 12; - move16(); - sfm_start = sfm_end = NULL; - num_Sb = nb_sfm = 0; - - st_fx->tcx_cfg.tcx_last_overlap_mode = st_fx->tcx_cfg.tcx_curr_overlap_mode; - move16(); - if (sub(st_fx->tcx_cfg.tcx_curr_overlap_mode, FULL_OVERLAP) == 0) - { - st_fx->tcx_cfg.tcx_last_overlap_mode = ALDO_WINDOW; - move16(); - } - st_fx->tcx_cfg.tcx_curr_overlap_mode = ALDO_WINDOW; - move16(); - - /*-------------------------------------------------------------------------- - * Find the number of bits for transform-domain coding - *--------------------------------------------------------------------------*/ - - /* set the total bit-budget */ - /*num_bits = (short)(st->total_brate / 50); */ - Mpy_32_16_ss(st_fx->total_brate_fx, 5243, &L_tmp, &lsb); /* 5243 is 1/50 in Q18. (0+18-15=3) */ - num_bits = extract_l(L_shr(L_tmp, 3)); /*Q0 */ - - IF( !st_fx->bfi_fx ) - { - IF ( sub(core_switching_flag, 1) == 0 ) - { - core_switching_hq_prepare_dec_fx( st_fx, &num_bits, output_frame ); - - /* During ACELP->HQ core switching, limit the HQ core bitrate to 48kbps */ - if ( sub(num_bits, HQ_48k / 50) > 0 ) - { - num_bits = (Word16)(HQ_48k / 50); - move16(); - } - } - - /* subtract signalling bits */ - num_bits = sub(num_bits, st_fx->next_bit_pos_fx); - - /* set FEC parameters */ - flag_uv = sub(1, st_fx->HqVoicing_fx); - - /* subtract the number of bits for pitch & gain at higher bitrates */ - test(); - IF ( !(core_switching_flag) && L_sub(st_fx->core_brate_fx, MINIMUM_RATE_TO_ENCODE_VOICING_FLAG) > 0 ) - { - st_fx->HqVoicing_fx = get_next_indice_fx( st_fx, 1 ); - num_bits = sub(num_bits, 1); - } - ELSE - { - st_fx->HqVoicing_fx = 0; - move16(); - if ( L_sub(st_fx->core_brate_fx, MINIMUM_RATE_TO_ENCODE_VOICING_FLAG) > 0 ) - { - st_fx->HqVoicing_fx = 1; - move16(); - } - } - } - ELSE - { - flag_uv = 0; - move16(); - } - - /* set inner frame (== coded bandwidth) length */ - inner_frame = inner_frame_tbl[st_fx->bwidth_fx]; - move16(); - - IF ( st_fx->bfi_fx == 0) - { - st_fx->ph_ecu_HqVoicing_fx = 0; - move16(); - if ( sub(output_frame, L_FRAME16k) >= 0 ) - { - st_fx->ph_ecu_HqVoicing_fx = st_fx->HqVoicing_fx; - move16(); - } - } - - IF ( sub(output_frame, L_FRAME8k) == 0 ) - { - hq_configure_bfi_fx( &nb_sfm, &num_Sb, num_bands_p, &sfmsize, &sfm_start, &sfm_end ); - } - - /*-------------------------------------------------------------------------- - * transform-domain decoding - *--------------------------------------------------------------------------*/ - - IF( sub(st_fx->bfi_fx, 1) == 0 ) - { - is_transient = st_fx->old_is_transient_fx[0]; - move16(); - IF ( sub(output_frame, L_FRAME16k) >= 0 ) /* Apply phase ecu for WB, SWB and FB */ - { - /* ecu_rec sent to OLA, env_stab passed in ph_ecu_st */ - hq_ecu_fx( st_fx->prev_good_synth_fx, t_audio_q, &st_fx->time_offs_fx, st_fx->X_sav_fx, &st_fx->Q_X_sav, &st_fx->num_p_fx, st_fx->plocs_fx, st_fx->plocsi_fx, st_fx->env_stab_fx, - &st_fx->last_fec_fx, st_fx->ph_ecu_HqVoicing_fx, &st_fx->ph_ecu_active_fx, gapsynth_fx, st_fx->prev_bfi_fx, st_fx->old_is_transient_fx, st_fx->mag_chg_1st_fx, - st_fx->Xavg_fx, &st_fx->beta_mute_fx, output_frame, st_fx ); - } - ELSE - { - HQ_FEC_processing_fx( st_fx, t_audio_q, is_transient, st_fx->ynrm_values_fx, st_fx->r_p_values_fx, num_Sb, nb_sfm, num_bands_p, - output_frame, sfm_start, sfm_end ); - } - - st_fx->old_is_transient_fx[2] = st_fx->old_is_transient_fx[1]; - move16(); - st_fx->old_is_transient_fx[1] = st_fx->old_is_transient_fx[0]; - move16(); - - IF ( sub(output_frame, L_FRAME16k) >= 0 ) - { - /* keep st->previoussynth updated as in FEC_HQ_pitch_analysis but no LP analysis */ - delay_comp = NS2SA_fx2(st_fx->output_Fs_fx, DELAY_CLDFB_NS); - - Copy( st_fx->previoussynth_fx + delay_comp, st_fx->previoussynth_fx, sub(output_frame, delay_comp) ); - Copy( st_fx->delay_buf_out_fx, st_fx->previoussynth_fx + output_frame - delay_comp, delay_comp ); - - flag_uv = 1; - move16(); /* disable costly pitch out synthesis in bfi frame */ - st_fx->HqVoicing_fx = sub(1, flag_uv); /* safety setting for HQ->ACELP switch logic */ - set16_fx( st_fx->fer_samples_fx, 0, L_FRAME48k ); /* safety, create a known signal state for HQ->ACELP switch logic */ - } - } - ELSE - { - IF( sub(hq_core_type, LOW_RATE_HQ_CORE) == 0 ) - { - IF( sub(st_fx->prev_bfi_fx, 1) == 0 ) - { - set32_fx( st_fx->last_ni_gain_fx, 0, BANDS_MAX ); - set16_fx( st_fx->last_env_fx, 0, BANDS_MAX ); - st_fx->last_max_pos_pulse_fx = 0; - move16(); - } - - /* HQ low rate decoder */ - hq_lr_dec_fx( st_fx, t_audio_q, inner_frame, num_bits, &is_transient ); - - hqswb_clas = is_transient; - move16(); - Q_audio = 12; - move16(); - } - ELSE - { - /* HQ high rate decoder */ - hq_hr_dec_fx(st_fx, t_audio_q, inner_frame, num_bits, ynrm, &is_transient, &hqswb_clas, SWB_fenv_fx); - Q_audio = 12; - move16(); - } - - /* scaling (coefficients are in nominal level) */ - IF( sub(output_frame, NORM_MDCT_FACTOR) != 0 ) - { - IF (sub(output_frame, L_FRAME32k) == 0) - { - Q_audio = sub(Q_audio, 1); /* Multiply by 2 */ - } - ELSE - { - tmp = mult_r(output_frame, 410/2); /* 1/8000 in Q15 */ - ener_match = hq_nominal_scaling_inv[tmp]; - FOR( i=0; i < inner_frame; i++ ) - { - /*t_audio_q[i] *= ener_match;*/ - Mpy_32_16_ss(t_audio_q[i], ener_match, &L_tmp, &lsb); /*12+13-15=10 */ - t_audio_q[i] = L_add(L_shl(L_tmp, 2), lshr(lsb, 14)); - move16(); /* Q12 */ - } - } - } - - HQ_FEC_Mem_update_fx( st_fx, t_audio_q, normq_fx, ynrm, num_bands_p, is_transient, hqswb_clas, - core_switching_flag, nb_sfm, num_Sb, &mean_en_high_fx, hq_core_type, output_frame ); - } - /*-------------------------------------------------------------------------- - * Attenuate HFs in case of band-width switching (from higher BW to lower BW) - *--------------------------------------------------------------------------*/ - /* attenuate HFs in case of band-width switching */ - IF( st_fx->bws_cnt1_fx > 0 ) - { - IF( sub(st_fx->bws_cnt1_fx,N_NS2W_FRAMES) == 0 ) - { - ener_match = 32767; - move16(); /*Q15*/ - } - ELSE - { - ener_match = div_s(st_fx->bws_cnt1_fx,N_NS2W_FRAMES); /*Q15*/ - } - - IF( is_transient ) - { - FOR( i = 0; i < NUM_TIME_SWITCHING_BLOCKS; i++ ) - { - tmp_loop = mult(inner_frame,8192); - FOR( j=mult(inner_frame_tbl_fx[sub(st_fx->bwidth_fx,1)],8192); jbwidth_fx,1)]; it_audio_q_fx, 80, -13); - } - ELSE - { - Copy_Scale_sig_32_16(t_audio_q, st_fx->t_audio_q_fx, L_FRAME, -13); - } - - - /*-------------------------------------------------------------------------- - * Inverse transform - * Overlap-add - * Pre-echo reduction - *--------------------------------------------------------------------------*/ - - test(); - IF (sub(output_frame, L_FRAME8k) == 0 || st_fx->bfi_fx == 0) - { - test(); - IF( sub(inner_frame, output_frame) != 0 && sub(st_fx->bfi_fx, 1) == 0 ) - { - Inverse_Transform( t_audio_q, &Q_audio, wtda_audio, is_transient, output_frame, output_frame ); - } - ELSE - { - Inverse_Transform( t_audio_q, &Q_audio, wtda_audio, is_transient, output_frame, inner_frame ); - } - *Q_synth = Q_audio; - move16(); - } - - IF ( sub(output_frame, L_FRAME8k) == 0 ) - { - test(); - IF( st_fx->bfi_fx == 0 && st_fx->prev_bfi_fx == 0) - { - Copy_Scale_sig(st_fx->old_out_fx+N_ZERO_NB, st_fx->prev_oldauOut_fx, output_frame-N_ZERO_NB, negate(st_fx->Q_old_wtda) ); - } - ELSE IF( sub(st_fx->prev_bfi_fx, 1) == 0) - { - set16_fx( st_fx->prev_oldauOut_fx, 0, output_frame ); - } - - test(); - test(); - test(); - test(); - IF( (sub(st_fx->prev_bfi_fx, 1) == 0 || sub(st_fx->bfi_fx, 1) == 0) && st_fx->old_is_transient_fx[2] == 0 && sub(st_fx->last_core_fx, HQ_CORE) == 0 && sub(st_fx->last_codec_mode,MODE1)==0) - { - time_domain_FEC_HQ_fx( st_fx, wtda_audio, synth, mean_en_high_fx, output_frame, Q_synth ); - } - ELSE - { - window_ola_fx( wtda_audio, synth, Q_synth, st_fx->old_out_fx, &st_fx->Q_old_wtda, output_frame, - st_fx->tcx_cfg.tcx_last_overlap_mode, st_fx->tcx_cfg.tcx_curr_overlap_mode, st_fx->prev_bfi_fx, st_fx->oldHqVoicing_fx , st_fx->oldgapsynth_fx ); - st_fx->phase_mat_next_fx = 0; - move16(); - } - - test(); - test(); - IF ( (st_fx->bfi_fx == 0 && st_fx->prev_bfi_fx == 0) || !(sub(output_frame, L_FRAME16k) >= 0)) - { - preecho_sb_fx( st_fx->core_brate_fx, wtda_audio, Q_audio, synth, *Q_synth, output_frame, &st_fx->memfilt_lb_fx, - &st_fx->mean_prev_hb_fx, &st_fx->smoothmem_fx, &st_fx->mean_prev_fx, &st_fx->mean_prev_nc_fx, &st_fx->wmold_hb_fx, &st_fx->prevflag_fx, &st_fx->pastpre_fx, st_fx->bwidth_fx ); - } - } - ELSE - { - test(); - IF (sub(st_fx->bfi_fx, 1) == 0 && sub(output_frame, L_FRAME16k) >= 0 ) - { - /* PHASE_ECU active */ - Q_audio = 15; - move16(); - window_ola_fx( t_audio_q, synth, &Q_audio, st_fx->old_out_fx, &st_fx->Q_old_wtda, output_frame, - ALDO_WINDOW, ALDO_WINDOW, st_fx->prev_bfi_fx && !st_fx->ph_ecu_active_fx, st_fx->oldHqVoicing_fx, st_fx->oldgapsynth_fx ); - *Q_synth = Q_audio; - move16(); - } - ELSE - { - /* no BFI or baseline PLC active */ - window_ola_fx( wtda_audio, synth, Q_synth, st_fx->old_out_fx, &st_fx->Q_old_wtda, output_frame, - st_fx->tcx_cfg.tcx_last_overlap_mode, st_fx->tcx_cfg.tcx_curr_overlap_mode, st_fx->prev_bfi_fx && !st_fx->ph_ecu_active_fx, st_fx->oldHqVoicing_fx, st_fx->oldgapsynth_fx); - } - - test(); - test(); - IF ( (st_fx->bfi_fx == 0 && st_fx->prev_bfi_fx == 0) || !(sub(output_frame, L_FRAME16k) >= 0)) - { - preecho_sb_fx( st_fx->core_brate_fx, wtda_audio, Q_audio, synth,*Q_synth, output_frame, &st_fx->memfilt_lb_fx, - &st_fx->mean_prev_hb_fx, &st_fx->smoothmem_fx, &st_fx->mean_prev_fx, &st_fx->mean_prev_nc_fx, &st_fx->wmold_hb_fx, &st_fx->prevflag_fx, &st_fx->pastpre_fx, st_fx->bwidth_fx ); - } - } - - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - IF (!st_fx->bfi_fx - && st_fx->prev_bfi_fx - && L_sub(st_fx->last_total_brate_fx, HQ_48k) >= 0 - && sub(st_fx->last_codec_mode, MODE2) == 0 - && (sub(st_fx->last_core_bfi, TCX_20_CORE) == 0 || sub(st_fx->last_core_bfi, TCX_10_CORE) == 0) - && st_fx->plcInfo.concealment_method == TCX_NONTONAL - && L_sub(st_fx->plcInfo.nbLostCmpt, 4) < 0 ) - { - st_fx->plcInfo.recovery_gain = shl(st_fx->plcInfo.recovery_gain, *Q_synth); - waveform_adj2_fix(st_fx->tonalMDCTconceal.secondLastPcmOut, - synth, - st_fx->plcInfo.data_noise, - &st_fx->plcInfo.outx_new_n1_fx, - &st_fx->plcInfo.nsapp_gain_fx, - &st_fx->plcInfo.nsapp_gain_n_fx, - &st_fx->plcInfo.recovery_gain, - st_fx->plcInfo.step_concealgain_fx, - st_fx->plcInfo.Pitch_fx, - st_fx->plcInfo.FrameSize, - 0, - add(extract_l(st_fx->plcInfo.nbLostCmpt), 1), - st_fx->bfi_fx); - } - - IF (sub(output_frame, L_FRAME16k) >= 0) - { - IF (sub(st_fx->ph_ecu_HqVoicing_fx, 1) == 0) - { - st_fx->oldHqVoicing_fx = 1; - move16(); - Copy( gapsynth_fx, st_fx->oldgapsynth_fx, L_FRAME48k ); - } - ELSE - { - st_fx->oldHqVoicing_fx = 0; - move16(); - } - } - ELSE - { - st_fx->oldHqVoicing_fx = 0; - move16(); - } - - if( sub(st_fx->nbLostCmpt, FRAMECTTOSTART_MDCT) == 0 ) - { - st_fx->HqVoicing_fx = 0; - move16(); - } - - IF( sub(output_frame, L_FRAME8k) == 0) - { - Copy32( wtda_audio, st_fx->oldIMDCTout_fx, L_FRAME8k/2 ); - Copy(&st_fx->old_auOut_2fr_fx[output_frame], st_fx->old_auOut_2fr_fx, output_frame); - Copy_Scale_sig(synth, &st_fx->old_auOut_2fr_fx[output_frame], output_frame, negate(*Q_synth)); - } - - /* prepare synthesis output buffer (as recent as possible) for HQ FEC */ - - { - Word16 nbsubfr; - /*nbsubfr = extract_l(L_mult0(st_fx->L_frame_fx,FL2WORD16(1/L_SUBFR)));*/ - nbsubfr = 4; - if(sub(st_fx->L_frame_fx,320) == 0) - { - nbsubfr = 5; - move16(); - } - - /* update buffer of old subframe pitch values */ - test(); - IF( sub(st_fx->last_core_fx,HQ_CORE) == 0 && sub(st_fx->L_frame_fx,st_fx->last_L_frame_fx) != 0 ) - { - set32_fx( &st_fx->old_pitch_buf_fx[nbsubfr], (L_SUBFR<<16), nbsubfr ); - } - Copy32( &st_fx->old_pitch_buf_fx[nbsubfr], &st_fx->old_pitch_buf_fx[0], nbsubfr ); - set32_fx( &st_fx->old_pitch_buf_fx[nbsubfr], (L_SUBFR<<16), nbsubfr ); - Copy( &st_fx->mem_pitch_gain[2], &st_fx->mem_pitch_gain[nbsubfr+2], nbsubfr ); - set16_fx( &st_fx->mem_pitch_gain[2], 0, nbsubfr ); - } - - return; -} diff --git a/src/libs/libevs/lib_dec/hq_env_dec.cpp b/src/libs/libevs/lib_dec/hq_env_dec.cpp new file mode 100644 index 00000000..16625066 --- /dev/null +++ b/src/libs/libevs/lib_dec/hq_env_dec.cpp @@ -0,0 +1,166 @@ +/*==================================================================================== + EVS Codec 3GPP TS26.443 Nov 13, 2018. Version 12.11.0 / 13.7.0 / 14.3.0 / 15.1.0 + ====================================================================================*/ + +#include +#include +#include "options.h" +#include "prot.h" +#include "rom_com.h" + +/*------------------------------------------------------------------------* + * decode_envelope_indices() + * + * Decode envelope indices + *------------------------------------------------------------------------*/ + +short decode_envelope_indices( /* o : Number of bits */ + Decoder_State *st, /* i/o: decoder state structure */ + const short start_norm, /* i : starting band index */ + const short num_sfm, /* i : Number of subbands */ + const short numnrmibits, /* i : Bitrate of fall-back coding mode */ + short *difidx, /* o : Diff indices/encoded diff indices */ + const short flag_HQ2, /* i : indicator of HQ2 core */ + const short is_transient /* i : transient flag */ +) +{ + short hcode_l; + short i; + short LCmode; + + if( flag_HQ2 == LOW_RATE_HQ_CORE || flag_HQ2 == LOW_RATE_HQ_CORE_TRAN) + { + LCmode = (short)get_next_indice( st, BITS_DE_HMODE); + difidx[start_norm] = (short)get_next_indice( st, BITS_DE_FCOMP); + } + else + { + LCmode = (short)get_next_indice( st, 2 ); + difidx[start_norm] = (short)get_next_indice( st, NORM0_BITS ); + } + + if(is_transient && flag_HQ2 == LOW_RATE_HQ_CORE_TRAN) + { + hcode_l = 0; + if(LCmode == 1 ) + { + hdecnrm_tran(st, num_sfm, &difidx[start_norm + 1] ); + for( i = start_norm + 1; i < start_norm + num_sfm; i++ ) + { + hcode_l += huffsizn_tran[difidx[i]]; + } + } + else + { + hdecnrm_context(st,num_sfm, &difidx[start_norm], &hcode_l); + } + } + else + { + hcode_l = 0; + if ( LCmode == 0 ) + { + hdecnrm_context( st, num_sfm, &difidx[start_norm], &hcode_l ); + } + else if( LCmode == 1 ) + { + hdecnrm_resize( st, num_sfm, &difidx[start_norm + 1] ); + + for( i = start_norm + 1; i < start_norm + num_sfm; i++ ) + { + hcode_l += resize_huffsizn[difidx[i]]; + } + + for( i = start_norm + 2; i< start_norm + num_sfm; i++ ) + { + if( difidx[i-1]>17 ) + { + difidx[i] = difidx[i] - min(difidx[i-1]-17,3); + } + + if( difidx[i-1]<13 ) + { + difidx[i] = difidx[i] - max(difidx[i-1]-13,-3); + } + } + } + else if ( LCmode == 2 ) + { + hdecnrm( st, num_sfm, &difidx[start_norm + 1] ); + for( i = start_norm + 1; i < start_norm + num_sfm; i++ ) + { + hcode_l += huffsizn[difidx[i]]; + } + } + else + { + for( i = start_norm + 1; i < start_norm + num_sfm; i++ ) + { + difidx[i] = (short)get_next_indice( st, NORMI_BITS ); + + } + hcode_l = numnrmibits; + } + } + + return hcode_l; +} + +/*------------------------------------------------------------------------* + * dequantize_norms() + * + * De-quantization of norms + *------------------------------------------------------------------------*/ + +void dequantize_norms( /* o : Number of bits */ + Decoder_State *st, /* i/o: decoder state structure */ + const short start_norm, /* i : First SDE encoded norm */ + const short num_sfm, /* i : Number of norms */ + const short is_transient, /* i : Transient flag */ + short *ynrm, /* o : Decoded norm indices */ + short *normqlg2 /* o : Log2 of decoded norms */ +) +{ + short i,j,k; + short idxbuf[NB_SFM]; + + /* First sub-frame */ + normqlg2[start_norm] = dicnlg2[ynrm[start_norm]]; + + /* Other sub-frames */ + if( is_transient ) + { + /* Recover quantization indices and quantized norms */ + idxbuf[0] = ynrm[0]; + for( i = 1; i < num_sfm; i++ ) + { + idxbuf[i] = ynrm[i] + idxbuf[i-1] - 15; + /* safety check in case of bit errors */ + if ( idxbuf[i] < 0 || idxbuf[i] > 39 ) + { + idxbuf[i] = 39; + st->BER_detect = 1; + } + } + + recovernorm( idxbuf, ynrm, normqlg2, num_sfm ); + } + else + { + for (i = start_norm + 1; i < start_norm + num_sfm; i++) + { + j = i - 1; + k = ynrm[j] - 15; + ynrm[i] = ynrm[i] + k; + /* safety check in case of bit errors */ + if ( ynrm[i] < 0 || ynrm[i] > 39 ) + { + ynrm[i] = 39; + st->BER_detect = 1; + } + normqlg2[i] = dicnlg2[ynrm[i]]; + } + } + + return; +} diff --git a/src/libs/libevs/lib_dec/hq_env_dec_fx.cpp b/src/libs/libevs/lib_dec/hq_env_dec_fx.cpp deleted file mode 100755 index 3caeb147..00000000 --- a/src/libs/libevs/lib_dec/hq_env_dec_fx.cpp +++ /dev/null @@ -1,216 +0,0 @@ -/*==================================================================================== - EVS Codec 3GPP TS26.442 Apr 03, 2018. Version 12.11.0 / 13.6.0 / 14.2.0 - ====================================================================================*/ - -#include -#include "options.h" /* Compilation switches */ -#include "prot_fx.h" /* Function prototypes */ -#include "rom_com_fx.h" /* Static table prototypes */ -#include "stl.h" /* required for wmc_tool */ - -/*------------------------------------------------------------------------* - * decode_envelope_indices_fx() - * - * Decode envelope indices - *------------------------------------------------------------------------*/ - -Word16 decode_envelope_indices_fx( /* o : Number of bits */ - Decoder_State_fx *st_fx, /* i/o: decoder state structure */ - const Word16 start_norm, /* i : starting band index */ - const Word16 num_sfm, /* i : Number of subbands */ - const Word16 numnrmibits, /* i : Bitrate of fall-back coding mode */ - Word16 *difidx, /* o : Diff indices/encoded diff indices */ - const Word16 flag_HQ2 /* i : indicator of HQ2 core */ - ,const Word16 is_transient /* i : indicator of HQ_TRANSIENT */ -) -{ - Word16 hcode_l; - Word16 i,j; - Word16 LCmode; - Word16 startNormPlus1,numSfmMinus1,numSfmMinus2,offset; - Word16 *pDifidx,*pDifidx1; - - test(); - IF( sub(flag_HQ2, LOW_RATE_HQ_CORE) == 0 || sub(flag_HQ2, LOW_RATE_HQ_CORE_TRAN) == 0 ) - { - LCmode = (Word16)get_next_indice_fx ( st_fx, BITS_DE_HMODE); - difidx[start_norm] = (Word16)get_next_indice_fx ( st_fx, BITS_DE_FCOMP); - } - ELSE - { - LCmode = (Word16)get_next_indice_fx( st_fx, 2 ); - difidx[start_norm] = (Word16)get_next_indice_fx( st_fx, NORM0_BITS ); - } - - test(); - IF( is_transient && sub(flag_HQ2, LOW_RATE_HQ_CORE_TRAN) == 0 ) - { - hcode_l = 0; - move16(); - IF( sub(LCmode, 1) == 0 ) - { - hdecnrm_tran_fx(st_fx, num_sfm, &difidx[start_norm + 1] ); - j = add(start_norm, num_sfm); - FOR( i = start_norm + 1; i < j; i++ ) - { - hcode_l = add(hcode_l, huffsizn_tran[difidx[i]]); - } - } - ELSE - { - hdecnrm_context_fx(st_fx, num_sfm, &difidx[start_norm], &hcode_l); - } - } - ELSE - { - hcode_l = 0; - IF( LCmode == 0 ) - { - hdecnrm_context_fx( st_fx, num_sfm, &difidx[start_norm], &hcode_l); - } - ELSE IF( LCmode == 1 ) - { - startNormPlus1 = add(start_norm, 1); - hdecnrm_resize_fx( st_fx, num_sfm, &difidx[startNormPlus1] ); - - pDifidx = &difidx[startNormPlus1]; - move16(); - numSfmMinus1 = sub(num_sfm, 1); - FOR( i = 0; i < numSfmMinus1; i++ ) - { - j = *pDifidx++; - move16(); - hcode_l = add(hcode_l, resize_huffsizn[j]); - } - - pDifidx1 = &difidx[startNormPlus1]; - move16(); - numSfmMinus2 = sub(num_sfm, 2); - FOR( i = 0; i < numSfmMinus2; i++ ) - { - pDifidx = pDifidx1++; - move16(); - IF( *pDifidx > 17 ) - { - offset = sub(*pDifidx, 17); - offset = s_min(offset, 3); - *pDifidx1 = sub(*pDifidx1, offset); - } - ELSE IF( *pDifidx < 13 ) - { - offset = sub(*pDifidx, 13); - offset = s_max(offset, -3); - *pDifidx1 = sub(*pDifidx1, offset); - } - } - } - ELSE IF( LCmode == 2 ) - { - startNormPlus1 = add(start_norm, 1); - hdecnrm_fx( st_fx, num_sfm, &difidx[start_norm + 1] ); - - pDifidx = &difidx[startNormPlus1]; - move16(); - numSfmMinus1 = sub(num_sfm, 1); - FOR( i = 0; i < numSfmMinus1; i++ ) - { - j = *pDifidx++; - move16(); - hcode_l = add(hcode_l, huffsizn[j]); - } - } - ELSE - { - startNormPlus1 = add(start_norm, 1); - numSfmMinus1 = sub(num_sfm, 1); - pDifidx = &difidx[startNormPlus1]; - FOR( i = 0; i < numSfmMinus1; i++ ) - { - *pDifidx++ = (Word16)get_next_indice_fx( st_fx, NORMI_BITS ); - move16(); - } - hcode_l = numnrmibits; - move16(); - } - } - - return hcode_l; -} - -/*------------------------------------------------------------------------* - * dequantize_norms_fx() - * - * De-quantization of norms - *------------------------------------------------------------------------*/ - -void dequantize_norms_fx( - Decoder_State_fx *st_fx, /* i/o: decoder state structure */ - const Word16 start_norm, /* i : First SDE encoded norm */ - const Word16 num_sfm, /* i : Number of norms */ - const Word16 is_transient, /* i : Transient flag */ - Word16 *ynrm, /* o : Decoded norm indices */ - Word16 *normqlg2 /* o : Log2 of decoded norms */ -) -{ - Word16 i,j; - Word16 idxbuf[NB_SFM]; - Word16 *pYnrm, *pNormqlg2; - - /* First sub-frame */ - i = ynrm[start_norm]; - move16(); - normqlg2[start_norm] = dicnlg2[i]; - move16(); - - /* Other sub-frames */ - IF ( is_transient ) - { - /* Recover quantization indices and quantized norms */ - idxbuf[0] = ynrm[0]; - move16(); - FOR ( i = 1; i < num_sfm; i++ ) - { - idxbuf[i] = sub( add(ynrm[i],idxbuf[i-1]), 15 ); - move16(); - /* safety check in case of bit errors */ - test(); - IF ( idxbuf[i] < 0 || sub( idxbuf[i], 39 ) > 0) - { - idxbuf[i] = 39; - move16(); - st_fx->BER_detect = 1; - move16(); - } - } - - recovernorm_fx( idxbuf, ynrm, normqlg2, num_sfm ); - } - ELSE - { - pYnrm = &ynrm[start_norm]; - move16(); - pNormqlg2 = &normqlg2[start_norm+1]; - move16(); - FOR ( i = 1; i < num_sfm; i++ ) - { - j = sub(*pYnrm++,15); - move16(); - *pYnrm = add(*pYnrm,j); - move16(); - /* safety check in case of bit errors */ - test(); - IF ( *pYnrm < 0 || sub( *pYnrm, 39 ) > 0) - { - *pYnrm = 39; - move16(); - st_fx->BER_detect = 1; - move16(); - } - *pNormqlg2++ = dicnlg2[*pYnrm]; - move16(); - } - } - - return; -} - diff --git a/src/libs/libevs/lib_dec/hq_hr_dec.cpp b/src/libs/libevs/lib_dec/hq_hr_dec.cpp new file mode 100644 index 00000000..a90a4eea --- /dev/null +++ b/src/libs/libevs/lib_dec/hq_hr_dec.cpp @@ -0,0 +1,271 @@ +/*==================================================================================== + EVS Codec 3GPP TS26.443 Nov 13, 2018. Version 12.11.0 / 13.7.0 / 14.3.0 / 15.1.0 + ====================================================================================*/ + +#include +#include "options.h" +#include "cnst.h" +#include "rom_com.h" +#include "prot.h" + +/*--------------------------------------------------------------------------* + * hq_pred_hb_bws() + * + * HQ core HB band-width switching handling + *--------------------------------------------------------------------------*/ + +static void hq_pred_hb_bws( + Decoder_State *st, /* i/o: decoder state structure */ + const short *ynrm, /* i : norm quantization index vector */ + const short length, /* i : frame length */ + const short hqswb_clas, /* i : HQ SWB class */ + const float *SWB_fenv /* i : SWB frequency envelopes */ +) +{ + short i; + + /* SWB switching to WB */ + if ( length >= L_FRAME32k ) /* wb switch to swb */ + { + /* calculate the switching parameters */ + if( (hqswb_clas != HQ_GEN_SWB && st->core_brate <= HQ_32k) || st->core_brate > HQ_32k ) + { + st->prev_ener_shb = 0.0f; + for( i=25; iprev_ener_shb += dicn[ynrm[i]]; + } + st->prev_ener_shb /= 6; + } + else + { + st->prev_ener_shb = 0.0f; + for( i=0; iprev_ener_shb += SWB_fenv[i]; + } + st->prev_ener_shb /= (SWB_FENV-3); + } + } + + if( st->last_inner_frame >= L_FRAME32k ) + { + set_f( st->prev_SWB_fenv, st->prev_ener_shb, SWB_FENV ); + } + + return; +} + + +/*--------------------------------------------------------------------------* + * hq_hr_dec() + * + * HQ high rate decoding routine + *--------------------------------------------------------------------------*/ + +void hq_hr_dec( + Decoder_State *st, /* i/o: decoder state structure */ + float *t_audio_q, /* o : transform-domain coefficients */ + const short length, /* i : frame length */ + short num_bits, /* i : number of available bits */ + short *ynrm, /* o : norm quantization index vector */ + short *is_transient, /* o : transient flag */ + short *hqswb_clas, /* o : HQ SWB class */ + float *SWB_fenv /* o : SWB frequency envelopes */ +) +{ + short nb_sfm; + short sum, hcode_l; + const short *sfmsize, *sfm_start, *sfm_end; + short num_sfm, numnrmibits; + short nf_idx; + short normqlg2[NB_SFM], R[NB_SFM]; + short pulses[NB_SFM], maxpulse[NB_SFM]; + float env_stab; + short Rsubband[NB_SFM]; /*Q3*/ + short start_norm, Npeaks = 0; + float noise_level[HVQ_BWE_NOISE_BANDS]; + short peak_idx[HVQ_MAX_PEAKS_32k]; + short hq_generic_offset; + short num_env_bands; + short hq_generic_exc_clas = 0; + short core_sfm; + short har_freq_est1, har_freq_est2; + short flag_dis; + const short *subband_search_offset; + short wBands[2]; + short b_delta_env; + short n_band; + + /*------------------------------------------------------------------* + * Initializations + *------------------------------------------------------------------*/ + set_s( pulses, 0, NB_SFM ); + set_s( maxpulse, 0, NB_SFM ); + flag_dis = 1; + har_freq_est1 = 0; + har_freq_est2 = 0; + set_s( peak_idx, 0, HVQ_MAX_PEAKS_32k); + + /*------------------------------------------------------------------* + * Decode classification + *------------------------------------------------------------------*/ + + num_bits -= hq_classifier_dec( st, st->core_brate, length, is_transient, hqswb_clas ); + + + /*------------------------------------------------------------------* + * set quantization parameters + *------------------------------------------------------------------*/ + + hq_configure( length, *hqswb_clas, st->core_brate, &num_sfm, &nb_sfm, &start_norm, + &num_env_bands, &numnrmibits, &hq_generic_offset, &sfmsize, &sfm_start, &sfm_end ); + + /*------------------------------------------------------------------* + * Unpacking bit-stream + *------------------------------------------------------------------*/ + + nf_idx = 0; + if( !*is_transient && *hqswb_clas != HQ_HVQ && !(length == L_FRAME16k && st->core_brate == HQ_32k)) + { + nf_idx = (short)get_next_indice( st, 2 ); + } + + + /*------------------------------------------------------------------* + * Decode envelope + *------------------------------------------------------------------*/ + + hcode_l = decode_envelope_indices( st, start_norm, num_env_bands, numnrmibits, ynrm, NORMAL_HQ_CORE, *is_transient ); + num_bits -= hcode_l + NORM0_BITS + FLAGS_BITS; + + dequantize_norms( st, start_norm, num_env_bands, *is_transient, ynrm, normqlg2 ); + + if ( *hqswb_clas == HQ_GEN_SWB || *hqswb_clas == HQ_GEN_FB ) + { + hq_generic_exc_clas = swb_bwe_gain_deq( st, HQ_CORE, NULL, SWB_fenv, st->core_brate == HQ_32k, *hqswb_clas ); + if (hq_generic_exc_clas == HQ_GENERIC_SP_EXC) + { + num_bits++; /* conditional 1 bit saving for representing FD3 BWE excitation class */ + } + map_hq_generic_fenv_norm(*hqswb_clas, SWB_fenv, ynrm, normqlg2, num_env_bands, nb_sfm, hq_generic_offset); + } + + env_stab = 0; + if( *hqswb_clas == HQ_HVQ ) + { + st->mem_env_delta = 0; + } + else if( length == L_FRAME32k ) + { + env_stab = env_stability( ynrm, SFM_N_ENV_STAB, st->mem_norm, &st->mem_env_delta ); + } + else + { + st->mem_norm[0] = 31; + st->mem_env_delta = 0; + } + + if( *hqswb_clas == HQ_HVQ ) + { + st->env_stab = 1.0f; /* stable by definition */ + } + else + { + if( length == L_FRAME32k ) + { + st->env_stab = env_stab; /* calculated stability */ + } + else + { + st->env_stab = env_stability( ynrm, SFM_N_ENV_STAB_WB, st->mem_norm_hqfec, &st->mem_env_delta_hqfec ); + } + } + st->env_stab_plc=env_stab_smo(min(st->env_stab,1.0f-stab_trans[L_STAB_TBL-1]),st->env_stab_state_p,&st->envstabplc_hocnt); + + /*------------------------------------------------------------------* + * Bit allocation + *------------------------------------------------------------------*/ + + hq_bit_allocation( st->core_brate, length, *hqswb_clas, &num_bits, normqlg2, nb_sfm, sfmsize, noise_level, + R, Rsubband, &sum, &core_sfm, num_env_bands ); + + if( st->bws_cnt1 > 0 && *hqswb_clas == HQ_GEN_SWB && st->core_brate == HQ_24k40 ) + { + if(st->L_frame == L_FRAME16k ) + { + for (n_band = 0; n_band < 4; n_band++) + { + SWB_fenv[n_band] *= (float)st->bws_cnt1 / (float)N_NS2W_FRAMES; + } + } + + for (n_band = 4; n_band < SWB_FENV; n_band++) + { + SWB_fenv[n_band] *= (float)st->bws_cnt1 / (float)N_NS2W_FRAMES; + } + } + + if ( *hqswb_clas == HQ_GEN_SWB || *hqswb_clas == HQ_GEN_FB ) + { + b_delta_env = get_nor_delta_hf(st, ynrm, Rsubband, num_env_bands, nb_sfm, core_sfm ); + sum -= b_delta_env; + } + + /*------------------------------------------------------------------* + * Decode spectral fine structure using HVQ/PVQ + *------------------------------------------------------------------*/ + + if( *hqswb_clas == HQ_HVQ ) + { + hvq_dec( st, num_bits, st->core_brate, ynrm, R, noise_level, peak_idx, &Npeaks, t_audio_q, st->core ); + } + else + { + pvq_core_dec(st, sfm_start, sfm_end, sfmsize, t_audio_q, sum, nb_sfm, Rsubband, R, pulses, maxpulse, HQ_CORE ); + } + + if( *hqswb_clas == HQ_HVQ || *hqswb_clas == HQ_HARMONIC ) + { + subband_search_offset = subband_search_offsets_13p2kbps_Har; + wBands[0] = SWB_SB_BW_LEN0_16KBPS_HAR; + wBands[1] = SWB_SB_BW_LEN1_16KBPS_HAR; + + har_est( t_audio_q, 300, &har_freq_est1, &har_freq_est2, &flag_dis, &st->prev_frm_hfe2, subband_search_offset, wBands, &st->prev_stab_hfe2 ); + + st->prev_frm_hfe2 = har_freq_est2; + } + + if( *hqswb_clas != HQ_HARMONIC || *hqswb_clas != HQ_HVQ || flag_dis == 0 ) + { + st->prev_frm_hfe2 = 0; /*reset*/ + st->prev_stab_hfe2 = 0;/*reset*/ + } + + /*------------------------------------------------------------------* + * Spectral filling + *------------------------------------------------------------------*/ + fill_spectrum( t_audio_q, R, *is_transient, ynrm, SWB_fenv, hq_generic_offset, nf_idx, length, env_stab, + &st->no_att_hangover, &st->energy_lt, &st->hq_generic_seed, hq_generic_exc_clas, + core_sfm, *hqswb_clas, noise_level, st->core_brate, st->prev_noise_level, &(st->prev_R), st->prev_coeff_out, + peak_idx, Npeaks, pulses, st->old_is_transient[0], st->prev_normq, st->prev_env, st->prev_bfi, + sfmsize, sfm_start, sfm_end, &st->prev_L_swb_norm, st->prev_hqswb_clas, num_sfm, num_env_bands ); + + enforce_zero_for_min_envelope( *hqswb_clas, ynrm, t_audio_q, nb_sfm, sfm_start, sfm_end ); + + if( *is_transient ) + { + de_interleave_spectrum( t_audio_q, length ); + } + + /*------------------------------------------------------------------* + * WB/SWB bandwidth switching + *------------------------------------------------------------------*/ + + hq_pred_hb_bws( st, ynrm, length, *hqswb_clas, SWB_fenv ); + + /* update */ + st->prev_hqswb_clas = *hqswb_clas; + + return; +} diff --git a/src/libs/libevs/lib_dec/hq_hr_dec_fx.cpp b/src/libs/libevs/lib_dec/hq_hr_dec_fx.cpp deleted file mode 100755 index 1b5c7a3f..00000000 --- a/src/libs/libevs/lib_dec/hq_hr_dec_fx.cpp +++ /dev/null @@ -1,313 +0,0 @@ -/*==================================================================================== - EVS Codec 3GPP TS26.442 Apr 03, 2018. Version 12.11.0 / 13.6.0 / 14.2.0 - ====================================================================================*/ - -#include "options.h" /* Compilation switches */ -#include "stl.h" -#include "prot_fx.h" /* Function prototypes */ -#include "rom_com_fx.h" /* Static table prototypes */ - - -void hq_pred_hb_bws_fx( - Decoder_State_fx *st_fx, /* i/o: decoder state structure */ - const Word16 *ynrm, /* i : norm quantization index vector */ - const Word16 length, /* i : frame length */ - const Word16 hqswb_clas, /* i : HQ SWB class */ - const Word16 *SWB_fenv /* i : SWB frequency envelopes Q1 */ -) -{ - Word16 i; - Word32 L_tmp; - - IF( sub(length,L_FRAME32k) >= 0) - { - /* calculate the switching parameters */ - test(); - test(); - IF( ( sub(hqswb_clas,HQ_GEN_SWB) != 0 && L_sub(st_fx->core_brate_fx,HQ_32k) <= 0 ) || L_sub(st_fx->core_brate_fx,HQ_32k) > 0 ) - { - st_fx->prev_ener_shb_fx = 0; - move16(); - L_tmp = L_deposit_l(0); - FOR(i=25; iprev_ener_shb_fx = extract_l(L_tmp);/*Q1*/ - st_fx->prev_ener_shb_fx = mult(st_fx->prev_ener_shb_fx,5461); /*Q1*/ - } - ELSE - { - st_fx->prev_ener_shb_fx = 0; - move16(); - FOR(i=0; iprev_ener_shb_fx = add(st_fx->prev_ener_shb_fx,SWB_fenv[i]);/*Q1*/ - } - st_fx->prev_ener_shb_fx = mult(st_fx->prev_ener_shb_fx, 2979); /*Q1*/ - } - } - - IF( sub(st_fx->last_inner_frame_fx,L_FRAME32k) >= 0 ) - { - set16_fx(st_fx->prev_SWB_fenv_fx, st_fx->prev_ener_shb_fx, SWB_FENV); - } - - return; - -} -/*--------------------------------------------------------------------------* - * hq_hr_dec_fx() - * - * HQ High rate decoding routine - *--------------------------------------------------------------------------*/ -void hq_hr_dec_fx( - Decoder_State_fx *st_fx, /* i/o: decoder state structure fx */ - Word32 *t_audio_q, /* o : transform-domain coefficients Q12 */ - const Word16 length, /* i : frame length Q0 */ - Word16 num_bits, /* i : number of available bits Q0 */ - Word16 *ynrm, /* o : norm quantization index vector Q0 */ - Word16 *is_transient, /* o : transient flag Q0 */ - Word16 *hqswb_clas, /* o : HQ SWB class Q0 */ - Word16 *SWB_fenv /* o : SWB frequency envelopes Q1 */ -) -{ - Word16 nb_sfm; - Word16 sum, hcode_l; - const Word16 *sfmsize, *sfm_start, *sfm_end; - Word16 num_sfm, numnrmibits; - Word16 nf_idx; - Word16 normqlg2[NB_SFM], R[NB_SFM]; - Word16 pulses[NB_SFM], maxpulse[NB_SFM]; - Word16 env_stab; /*Q15*/ - Word16 Rsubband[NB_SFM]; /*Q3*/ - Word16 start_norm, Npeaks = 0; - Word16 noise_level[HVQ_BWE_NOISE_BANDS]; /*Q15*/ - Word16 peak_idx[HVQ_MAX_PEAKS_32k]; - Word16 hq_generic_offset; - Word16 num_env_bands; - Word16 hq_generic_exc_clas = 0; - Word16 core_sfm; - Word16 har_freq_est1, har_freq_est2; - Word16 flag_dis; - const Word16 *subband_search_offset; - Word16 wBands[2]; - Word16 bits, i; - Word16 t_audio_q_norm[L_FRAME48k]; - Word16 Q_audio; - Word16 b_delta_env; - Word16 tmp,n_band; - Word16 Q_shift; - - Q_audio = 0; /* to avoid compilation warnings */ - - /*------------------------------------------------------------------* - * Initializations - *------------------------------------------------------------------*/ - - set16_fx( pulses, 0, NB_SFM ); - set16_fx( maxpulse, 0, NB_SFM ); - flag_dis = 1; - move16(); - har_freq_est1 = 0; - move16(); - har_freq_est2 = 0; - move16(); - set16_fx( peak_idx, 0, HVQ_MAX_PEAKS_32k); - - /*------------------------------------------------------------------* - * Decode classification - *------------------------------------------------------------------*/ - - bits = hq_classifier_dec_fx( st_fx, st_fx->core_brate_fx, length, is_transient, hqswb_clas); - num_bits = sub(num_bits, bits); - - /*------------------------------------------------------------------* - * set quantization parameters - *------------------------------------------------------------------*/ - - hq_configure_fx( length, *hqswb_clas, st_fx->core_brate_fx, &num_sfm, &nb_sfm, &start_norm, - &num_env_bands, &numnrmibits, &hq_generic_offset, &sfmsize, &sfm_start, &sfm_end ); - - /*------------------------------------------------------------------* - * Unpacking bit-stream - *------------------------------------------------------------------*/ - - nf_idx = 0; - move16(); - test(); - test(); - test(); - IF( !*is_transient && sub(*hqswb_clas, HQ_HVQ) != 0 && !(sub(length, L_FRAME16k) == 0 && L_sub(st_fx->core_brate_fx, HQ_32k) == 0)) - { - nf_idx = get_next_indice_fx( st_fx, 2 ); - } - - /*------------------------------------------------------------------* - * Decode envelope - *------------------------------------------------------------------*/ - - hcode_l = decode_envelope_indices_fx( st_fx, start_norm, num_env_bands, numnrmibits, ynrm, NORMAL_HQ_CORE, *is_transient ); - num_bits = sub(num_bits, add(hcode_l, NORM0_BITS + FLAGS_BITS)); - - dequantize_norms_fx( st_fx, start_norm, num_env_bands, *is_transient, ynrm, normqlg2 ); - - test(); - IF ( sub(*hqswb_clas, HQ_GEN_SWB) == 0 || sub(*hqswb_clas, HQ_GEN_FB) == 0 ) - { - hq_generic_exc_clas = swb_bwe_gain_deq_fx( st_fx, HQ_CORE, NULL, SWB_fenv, st_fx->core_brate_fx == HQ_32k, *hqswb_clas ); - if ( sub(hq_generic_exc_clas , HQ_GENERIC_SP_EXC) == 0) - { - num_bits = add(num_bits,1); /* conditional 1 bit saving for representing HQ GENERIC excitation class */ - } - map_hq_generic_fenv_norm_fx( *hqswb_clas, SWB_fenv, ynrm, normqlg2, num_env_bands, nb_sfm, hq_generic_offset ); - } - - env_stab = 0; - move16(); - IF( sub(*hqswb_clas, HQ_HVQ) == 0 ) - { - st_fx->mem_env_delta_fx = 0; - move16(); - } - ELSE IF( sub(length, L_FRAME32k) == 0 ) - { - env_stab = env_stability_fx( ynrm, SFM_N_ENV_STAB, st_fx->mem_norm_fx, &st_fx->mem_env_delta_fx ); - } - ELSE - { - st_fx->mem_norm_fx[0] = 31; - move16(); - st_fx->mem_env_delta_fx = 0; - move16(); - } - - IF ( sub(*hqswb_clas, HQ_HVQ) == 0 ) - { - st_fx->env_stab_fx = 32767; - move16(); /* 1 in Q15, stable by definition */ - } - ELSE - { - IF ( sub(length, L_FRAME32k) == 0 ) - { - st_fx->env_stab_fx = env_stab; - move16(); /* calculated stability */ - } - ELSE - { - st_fx->env_stab_fx = env_stability_fx( ynrm, SFM_N_ENV_STAB_WB, st_fx->mem_norm_hqfec_fx, &st_fx->mem_env_delta_hqfec_fx ); - } - } - st_fx->env_stab_plc_fx = env_stab_smo_fx(s_min(st_fx->env_stab_fx, sub(32767, stab_trans_fx[L_STAB_TBL-1])), st_fx->env_stab_state_p_fx, &st_fx->envstabplc_hocnt_fx); - - /*------------------------------------------------------------------* - * Bit allocation - *------------------------------------------------------------------*/ - - hq_bit_allocation_fx( st_fx->core_brate_fx, length, *hqswb_clas, &num_bits, normqlg2, nb_sfm, sfmsize, noise_level, - R, Rsubband, &sum, &core_sfm, num_env_bands ); - - test(); - test(); - IF( sub(*hqswb_clas, HQ_GEN_SWB) == 0 && st_fx->bws_cnt1_fx > 0 && L_sub(st_fx->core_brate_fx, HQ_24k40) == 0 ) - { - tmp = i_mult(st_fx->bws_cnt1_fx, 1638); - move16(); - IF( sub(st_fx->L_frame_fx, L_FRAME16k) == 0 ) - { - FOR (n_band = 0; n_band < 4; n_band++) - { - SWB_fenv[n_band] = mult_r(SWB_fenv[n_band], tmp); - move16(); - } - } - - FOR (n_band = 4; n_band < SWB_FENV; n_band++) - { - SWB_fenv[n_band] = mult_r(SWB_fenv[n_band], tmp); - move16(); - } - } - - test(); - IF ( sub(*hqswb_clas , HQ_GEN_SWB) == 0 || sub(*hqswb_clas , HQ_GEN_FB) == 0 ) - { - b_delta_env = get_nor_delta_hf_fx(st_fx, ynrm, Rsubband, num_env_bands, nb_sfm, core_sfm ); - sum = sub(sum,b_delta_env); - } - - /*------------------------------------------------------------------* - * Decode spectral fine structure using HVQ/PVQ - *------------------------------------------------------------------*/ - - IF( sub(*hqswb_clas, HQ_HVQ) == 0 ) - { - hvq_dec_fx( st_fx, num_bits, st_fx->core_brate_fx, ynrm, R, noise_level, peak_idx, &Npeaks, t_audio_q, st_fx->core_fx ); - } - ELSE - { - pvq_core_dec_fx(st_fx, sfm_start, sfm_end, sfmsize, t_audio_q_norm, &Q_audio, sum, nb_sfm, Rsubband, R, pulses, maxpulse, HQ_CORE ); - } - - test(); - IF ( sub(*hqswb_clas, HQ_HVQ) == 0 || sub(*hqswb_clas, HQ_HARMONIC) == 0 ) - { - subband_search_offset = subband_search_offsets_13p2kbps_Har_fx; - wBands[0] = SWB_SB_BW_LEN0_16KBPS_HAR; - move16(); - wBands[1] = SWB_SB_BW_LEN1_16KBPS_HAR; - move16(); - - IF (sub(*hqswb_clas, HQ_HARMONIC) == 0) - { - Q_shift = sub(SWB_BWE_LR_Qs, Q_audio); - FOR (i = 0; i < 300; i++) - { - t_audio_q[i] = L_shl(L_deposit_l(t_audio_q_norm[i]), Q_shift); /* Q12 */ - } - } - - har_est_fx( t_audio_q, 300 ,&har_freq_est1, &har_freq_est2, &flag_dis, &st_fx->prev_frm_hfe2_fx, subband_search_offset, wBands, &st_fx->prev_stab_hfe2_fx ); - - st_fx->prev_frm_hfe2_fx = har_freq_est2; - move16(); - } - - test(); - test(); - IF ( sub(*hqswb_clas, HQ_HARMONIC) != 0 || sub(*hqswb_clas, HQ_HVQ) != 0 || flag_dis == 0) - { - st_fx->prev_frm_hfe2_fx = 0; /*reset*/ move16(); - st_fx->prev_stab_hfe2_fx = 0; /*reset*/ move16(); - } - - /*------------------------------------------------------------------* - * Spectral filling - *------------------------------------------------------------------*/ - fill_spectrum_fx( t_audio_q_norm, t_audio_q, R, *is_transient, ynrm, SWB_fenv, hq_generic_offset, nf_idx, length, env_stab, - &st_fx->no_att_hangover_fx, &st_fx->energy_lt_fx, &st_fx->hq_generic_seed_fx, hq_generic_exc_clas, - core_sfm, *hqswb_clas, noise_level, st_fx->core_brate_fx, st_fx->prev_noise_level_fx, &st_fx->prev_R_fx, st_fx->prev_coeff_out_fx, peak_idx, Npeaks, pulses, st_fx->old_is_transient_fx[0], - st_fx->prev_normq_fx, st_fx->prev_env_fx, st_fx->prev_bfi_fx, sfmsize, sfm_start, sfm_end, &st_fx->prev_L_swb_norm_fx, st_fx->prev_hqswb_clas_fx, num_sfm, - st_fx->prev_env_Q, num_env_bands ); - - enforce_zero_for_min_envelope_fx( *hqswb_clas, ynrm, t_audio_q, nb_sfm, sfm_start, sfm_end ); - - - IF( sub(*is_transient, 1) == 0 ) - { - de_interleave_spectrum_fx( t_audio_q, length ); - } - - /*------------------------------------------------------------------* - * WB/SWB bandwidth switching - *------------------------------------------------------------------*/ - hq_pred_hb_bws_fx(st_fx, ynrm, length, *hqswb_clas, SWB_fenv ); - - /* update */ - st_fx->prev_hqswb_clas_fx = *hqswb_clas; - move16(); - - return; -} diff --git a/src/libs/libevs/lib_dec/hq_lr_dec.cpp b/src/libs/libevs/lib_dec/hq_lr_dec.cpp new file mode 100644 index 00000000..4419c539 --- /dev/null +++ b/src/libs/libevs/lib_dec/hq_lr_dec.cpp @@ -0,0 +1,1292 @@ +/*==================================================================================== + EVS Codec 3GPP TS26.443 Nov 13, 2018. Version 12.11.0 / 13.7.0 / 14.3.0 / 15.1.0 + ====================================================================================*/ + +#include "options.h" +#include "cnst.h" +#include "rom_com.h" +#include "rom_dec.h" +#include "prot.h" +#include "stl.h" +#include "basop_util.h" + +/*--------------------------------------------------------------------------* + * Local functions + *--------------------------------------------------------------------------*/ + +static short p2a_threshold_dequant( Decoder_State *st, short *p2a_flags, const short bands, const short p2a_bands ); + +static void mdct_spectrum_fine_gain_dec( Decoder_State *st, float y2[], const short band_start[], const short band_end[], + const short k_sort[], const short bands, const Word32 L_qint, + const short Ngq, const short gqlevs, const short gqbits ); + +static float band_energy_dequant( Decoder_State *st, float band_energy[], const short bands, const Word32 L_qint, const Word16 eref_fx, const short is_transient ); + +static void spt_shorten_domain_set_dec( Decoder_State *st, const short p2a_flags[], const short new_band_start[], + const short new_band_end[], const short new_band_width[], const short bands, + short band_start[], short band_end[], short band_width[], short *bit_budget ); + +/*-------------------------------------------------------------------* + * hq_lr_dec() + * + * HQ low rate decoding routine + *-------------------------------------------------------------------*/ + +void hq_lr_dec( + Decoder_State *st, /* i/o: decoder state structure */ + float yout[], /* o : transform-domain output coefs. */ + const short inner_frame, /* i : inner frame length */ + short num_bits, /* i : number of available bits */ + short *is_transient /* o : transient flag */ +) +{ + short i, k1, pbits, p2a_flags[BANDS_MAX], bit_budget, bands, length, gqlevs, gqbits, Ngq, p2a_bands, ni_seed; + short band_start[BANDS_MAX], band_end[BANDS_MAX], band_width[BANDS_MAX]; + short k_sort[BANDS_MAX]; + int npulses[BANDS_MAX], inp_vector[L_FRAME48k]; + float ni_coef, ni_pd_th, pd_thresh, ld_slope; + float ebits, Rk[BANDS_MAX], band_energy[BANDS_MAX], y2[L_FRAME48k], p2a_th; + Word32 Rk_fx[BANDS_MAX]; + Word32 L_qint; /* Q29 */ + Word16 eref_fx; /* Q10 */ + Word16 bit_alloc_weight_fx; /* Q13 */ + float y2_ni[L_FRAME48k],y2_org[L_FRAME48k]; + short hqswb_clas = 0; + short lowlength, highlength, har_bands = 0; + float m[L_FRAME32k]; + float Ep[BANDS_MAX], enerH = 0.0f, enerL = 0.0f; + short lowband, highband, bw_low = 0, bw_high = 20; + float Ep_tmp[BANDS_MAX]; + float band_energy_tmp[BANDS_MAX]; + short last_bitalloc_max_band[2]; + long bwe_br; + short trans_bit, p2a_flags_tmp[BANDS_MAX]; + short adjustFlag = 0; + short prev_SWB_peak_pos_tmp[SPT_SHORTEN_SBNUM]; + int j, k; + short flag_spt; + short org_band_start[SPT_SHORTEN_SBNUM]; + short org_band_end[SPT_SHORTEN_SBNUM]; + short org_band_width[SPT_SHORTEN_SBNUM]; + short new_band_start[SPT_SHORTEN_SBNUM]; + short new_band_end[SPT_SHORTEN_SBNUM]; + short new_band_width[SPT_SHORTEN_SBNUM]; + Word32 L_tmp,L_tmp2,L_tmp3; + Word16 exp,tmp,exp2,tmp1,tmp2,tmp3,alpha_fx,frac1; + Word32 enerH_fx; + Word32 enerL_fx; + Word32 Ep_fx[BANDS_MAX]; + Word32 Ep_avrg_fx, Ep_vari_fx; + Word32 Ep_avrgL_fx; + Word32 Ep_peak_fx; + Word32 Ep_tmp_fx[BANDS_MAX]; + Word16 gama_fx;/*Q15 0.85f; */ + Word16 beta_fx;/*Q14 1.05f; */ + Word32 L_band_energy[BANDS_MAX],L_band_energy_tmp[BANDS_MAX]; + UWord16 lo; + Word16 Q_band_energy; + + set_s(last_bitalloc_max_band, 0, 2); + set_f( y2, 0.0f, L_FRAME48k ); + set_i( inp_vector, 0, inner_frame ); + flag_spt = 0; + set_s(prev_SWB_peak_pos_tmp, 0, SPT_SHORTEN_SBNUM); + bwe_br = st->core_brate; + + if( st->bwidth == SWB && ( bwe_br == HQ_16k40 || bwe_br == HQ_13k20 ) ) + { + hqswb_clas = (short)get_next_indice( st,2); + num_bits -= 2; + + *is_transient = 0; + if ( hqswb_clas == HQ_TRANSIENT ) + { + *is_transient = 1; + } + } + else + { + /* decode transient flag */ + *is_transient = (short)get_next_indice( st, 1 ); + num_bits--; + } + + + /* Configure decoder for different bandwidths, bit rates, etc. */ + hq2_core_configure( inner_frame, num_bits, *is_transient, &bands, &length, band_width, band_start, band_end, &L_qint, &eref_fx, + &bit_alloc_weight_fx, &gqlevs, &Ngq, &p2a_bands, &p2a_th, &pd_thresh, &ld_slope, &ni_coef, &ni_pd_th, bwe_br ); + + highlength = band_end[bands-1]; + har_bands = bands; + + if( st->bwidth == SWB && *is_transient == 0 && (bwe_br == HQ_16k40 || bwe_br == HQ_13k20) ) + { + /* reserve bits for HQ_NORMAL and HQ_HARMONIC */ + if( hqswb_clas == HQ_NORMAL || hqswb_clas==HQ_HARMONIC) + { + num_bits -= (short)get_usebit_npswb( hqswb_clas ); + } + + if( hqswb_clas == HQ_NORMAL ) + { + flag_spt = 1; + } + } + + if( (bwe_br == HQ_16k40 || bwe_br == HQ_13k20) && st->bwidth == SWB ) + { + if( st->prev_hqswb_clas != HQ_NORMAL ) + { + j = 0; + for(k=bands-SPT_SHORTEN_SBNUM; kprev_SWB_peak_pos[j] = 0; + j++; + } + } + } + + /* Spectral energy calculation/quantization */ + ebits = band_energy_dequant( st, band_energy, bands, L_qint, eref_fx, *is_transient ); + + /* simple check: band_energy is too large, Abnormal Situation of bit errors */ + for( k=0; k 45.0f || band_energy[k] < -6.7f ) + { + st->BER_detect = 1; + set_f( yout, 0, inner_frame ); + return; + } + } + + for (i = 0; i < bands; i++) + { + L_band_energy[i] = (Word32)(band_energy[i] * pow(2.0f, SWB_BWE_LR_Qbe)); + } + + /* First pass bit budget for TCQ of spectral band information */ + gqbits = (short int) log2_f ((float) gqlevs); + bit_budget = num_bits - (short) ceil (ebits) - Ngq * gqbits; + + pbits = 0; + if( st->bwidth == SWB && (bwe_br == HQ_16k40 || bwe_br == HQ_13k20) ) + { + if ( hqswb_clas == HQ_HARMONIC) + { + set_s( p2a_flags, 1, har_bands ); + } + else + { + /* High band tonality detector based on per band peak-to-average ratio */ + pbits = p2a_threshold_dequant( st, p2a_flags, bands, p2a_bands ); + bit_budget -= pbits; + + if( hqswb_clas == HQ_NORMAL ) + { + return_bits_normal2( &bit_budget, p2a_flags, bands, bits_lagIndices_modeNormal ); + } + } + } + else + { + /* High band tonality detector based on per band peak-to-average ratio */ + pbits = p2a_threshold_dequant( st, p2a_flags, bands, p2a_bands ); + bit_budget -= pbits; + } + + if( flag_spt == 1 ) + { + /* initalize the desired parameters for SPT */ + spt_shorten_domain_band_save( bands, band_start, band_end, band_width, org_band_start, org_band_end, org_band_width ); + spt_shorten_domain_pre( band_start, band_end, st->prev_SWB_peak_pos, bands, bwe_br, new_band_start, new_band_end, new_band_width ); + spt_shorten_domain_set_dec( st, p2a_flags, new_band_start, new_band_end, new_band_width, bands, band_start, band_end, band_width, &bit_budget ); + } + + /* safety check in case of bit errors */ + if( bit_budget < 2 ) + { + st->BER_detect = 1; + set_f( yout, 0, inner_frame ); + return; + } + + /* Estimate number of bits per sub-band */ + Q_band_energy = SWB_BWE_LR_Qbe; + FOR(i = 0; i < bands; i++) + { + L_tmp = L_shl(L_band_energy[i],sub(16,Q_band_energy));/*Q16 */ + + frac1 = L_Extract_lc(L_tmp, &exp); /* Extract exponent of L_tmp */ + L_tmp = Pow2(30, frac1); + exp = sub(exp, 30); + Ep_fx[i] = L_shl(L_tmp , sub(exp,6)); /* Q -6 */ + Ep[i] = (float)(Ep_fx[i]/pow(2.0,-6)); + } + + FOR( i = 0; i < bands; i++ ) + { + L_tmp2 = Ep_fx[i]; + L_tmp = L_max(1, L_tmp2); + exp = norm_l(L_tmp); + tmp = extract_h(L_shl(L_tmp, exp)); + + L_tmp3 = (Word32)band_width[i]; + exp2 = norm_l(L_tmp3); + tmp2 = extract_h(L_shl(L_tmp3, exp2)); + + exp2 = sub(exp, exp2); /* Denormalize and substract */ + + tmp3 = sub(tmp2, tmp); + IF (tmp3 > 0) + { + tmp2 = shr(tmp2, 1); + } + IF (tmp3 > 0) + { + exp2 = add(exp2, 1); + } + tmp = div_s(tmp2, tmp); + L_tmp = L_deposit_h(tmp); + L_tmp = Isqrt_lc1(L_tmp, &exp2); + move32();/*Q(31-exp2) */ + Ep_tmp_fx[i] = L_shr(L_tmp,sub(15,exp2));/*Q13 */ + Ep_tmp[i] = (float)(Ep_tmp_fx[i]/pow(2.0,13)); + } + + if ( *is_transient == 0 && inner_frame == L_FRAME8k && st->core_brate <= ACELP_13k20) + { + /* decode the last p2a_bands-1 subbands bit-allocation index of the previous frame */ + j = 0; + for(i = 0; i < 2; i++) + { + last_bitalloc_max_band[i] = (short)get_next_indice( st, 1 ); + } + + lowband = 6; + move16(); + trans_bit = 2; + move16(); + bit_budget =sub(bit_budget,trans_bit); + gama_fx = 27852; /*Q15 0.85f;*/ + beta_fx = 17203; + move16();/*Q14 1.05f; */ + set_s( &p2a_flags_tmp[bands-trans_bit], 0, 2 ); + + IF( st->core_brate == ACELP_13k20 ) + { + beta_fx = 13107; + move16();/*14 1.25f; */ + gama_fx = 31130; + move16();/*0.95f; */ + mvs2s(&p2a_flags[sub(bands,trans_bit)], &p2a_flags_tmp[sub(bands,trans_bit)], trans_bit); + } + + /* calculate the the low band/high band energy and the variance/avrage of the envelopes */ + Ep_vari_fx = 0; + move32(); + Ep_avrg_fx = 0; + move32(); + Ep_avrgL_fx = 0; + move32(); + Ep_peak_fx = 0; + move32(); + FOR( i = 0; i < bands; i++ ) + { + IF( sub(i,lowband) >= 0) + { + Ep_vari_fx = L_add(Ep_vari_fx,L_abs(L_sub(Ep_tmp_fx[i],Ep_tmp_fx[sub(i,1)])));/*Q15 */ + Ep_avrg_fx = L_add(Ep_avrg_fx,Ep_tmp_fx[i]);/*Q15 */ + + } + ELSE + { + Ep_avrgL_fx = L_add(Ep_avrgL_fx,Ep_tmp_fx[i]);/*Q15 */ + IF(L_sub(Ep_tmp_fx[i],Ep_peak_fx) > 0) + { + Ep_peak_fx = Ep_tmp_fx[i]; + move32();/*Q15 */ + } + } + } + /* modify the last p2a_bands subbands band_energies */ + k = (int)bands; + mvi2i( L_band_energy,L_band_energy_tmp,k); /*Q_band_energy */ + Mpy_32_16_ss(Ep_peak_fx,24576,&L_tmp,&lo); + Mpy_32_16_ss(Ep_peak_fx,shl(sub(bands,lowband),9),&L_tmp2,&lo); + Mpy_32_16_ss(Ep_avrg_fx,1126,&L_tmp3,&lo); + + IF(( (L_sub(L_tmp, L_shr(Ep_avrgL_fx,1)) < 0 && st->core_brate == ACELP_13k20 ) || st->core_brate < ACELP_13k20 )&& + L_sub(L_tmp2, L_tmp3) < 0 && L_sub(L_tmp2, L_shr(Ep_avrg_fx,7)) > 0) + { + FOR(i = lowband; i < bands; i++) + { + Mpy_32_16_ss(Ep_avrg_fx,24576,&L_tmp,&lo); + IF(L_sub(L_shr(Ep_tmp_fx[i],1), L_tmp) < 0) + { + Mpy_32_16_ss(Ep_peak_fx,sub(bands,lowband),&L_tmp,&lo); + tmp = extract_h(L_shl(L_tmp,14));/*Q-4 */ + IF(tmp != 0) + { + exp = norm_s(tmp); + tmp = shl(tmp,exp);/*Q(exp) */ + tmp = div_s(16384,tmp);/*Q(15+14-exp=29-exp) */ + exp = sub(29,exp); + } + ELSE + { + tmp = 0x7fff; + move16(); + exp = 0; + move16(); + } + Mpy_32_16_ss(Ep_avrg_fx,tmp,&L_tmp,&lo); + L_tmp = L_shl(L_tmp,sub(13,exp));/*Q(13+exp-15 +13-exp +4 = 15) */ + L_tmp2 = L_add(L_tmp,13107); /*15 */ + tmp2 = extract_l(L_min(L_max(L_tmp2,16384),gama_fx)); /*15 = 15 */ + Mpy_32_16_ss(L_band_energy_tmp[i],tmp2,&L_band_energy_tmp[i],&lo); + } + } + } + ELSE + { + FOR(i = sub(bands,trans_bit); i < bands; i++) + { + alpha_fx = 16384; + move16();/*Q14 */ + IF( sub(p2a_flags_tmp[i],1) == 0) + { + Mpy_32_16_ss(Ep_tmp_fx[i],sub(bands,lowband),&L_tmp,&lo); + tmp = extract_h(L_shl(L_tmp,14));/*Q-4 */ + IF(tmp != 0) + { + exp = norm_s(tmp); + tmp = shl(tmp,exp);/*Q(exp) */ + tmp = div_s(16384,tmp);/*Q(15+14-exp=29-exp) */ + exp = sub(29,exp); + } + ELSE + { + tmp = 0x7fff; + move16(); + exp = 0; + move16(); + } + Mpy_32_16_ss(Ep_vari_fx,3277,&L_tmp,&lo); + Mpy_32_16_ss(L_tmp,tmp,&L_tmp,&lo); + L_tmp = L_shl(L_tmp,sub(12,exp));/*Q(13+exp-15 +12-exp +4 = 14) */ + + tmp2 = extract_h(Ep_avrg_fx);/*Q13-16=-3 */ + IF(tmp2 != 0) + { + exp = norm_s(tmp2); + tmp2 = shl(tmp2,exp);/*Q(exp) */ + tmp2 = div_s(16384,tmp2);/*Q(15+14-exp=29-exp) */ + exp = sub(29,exp); + } + ELSE + { + /*when the divisor is zero, happens rarely*/ + tmp2 = 0x7fff; + move16(); + exp = 0; + move16(); + } + Mpy_32_16_ss(Ep_vari_fx,6554,&L_tmp2,&lo); + Mpy_32_16_ss(L_tmp2,tmp2,&L_tmp2,&lo); + L_tmp2 = L_shl(L_tmp2,sub(13,exp));/*Q(13+exp-15 +13-exp +3 = 14) */ + L_tmp=L_min(L_tmp,L_tmp2);/*14 */ + tmp=extract_l(L_min(L_tmp,13107));/*14 */ + alpha_fx =add(16384,tmp); + + } + IF(sub(last_bitalloc_max_band[j++], 1) == 0) + { + Mpy_32_16_ss(Ep_tmp_fx[i],sub(bands,lowband),&L_tmp,&lo); + tmp = extract_h(L_shl(L_tmp,14));/*Q-2 */ + IF(tmp != 0) + { + exp = norm_s(tmp); + tmp = shl(tmp,exp);/*Q(exp) */ + tmp = div_s(16384,tmp);/*Q(15+14-exp=29-exp) */ + exp = sub(29,exp); + } + ELSE + { + tmp = 0x7fff; + move16(); + exp = 0; + move16(); + } + Mpy_32_16_ss(Ep_avrg_fx,tmp,&L_tmp,&lo); + L_tmp = L_shl(L_tmp,sub(14,exp));/*Q(13+exp-15 +14-exp+2 = 14) */ + L_tmp =L_max(L_tmp,16384); /*14 */ + tmp=extract_l(L_min(L_tmp,beta_fx)); /*14 */ + alpha_fx=shl(mult(alpha_fx,tmp),1);/*14+14-15 +1=14 */ + } + ELSE + { + tmp2 = extract_h(Ep_avrg_fx);/*13 -16 =-3 */ + IF(tmp2 != 0) + { + exp = norm_s(tmp2); + tmp2 = shl(tmp2,exp);/*Q(exp) */ + tmp2 = div_s(16384,tmp2);/*Q(15+14-exp=29-exp) */ + exp = sub(29,exp); + } + ELSE + { + /*when the divisor is zero, happens rarely*/ + tmp2 = 0x7fff; + move16(); + exp = 0; + move16(); + } + Mpy_32_16_ss(Ep_tmp_fx[i],tmp2,&L_tmp,&lo); + L_tmp = L_shl(L_tmp,sub(19,exp));/*Q(13+exp-15 +19-exp +3 = 20) */ + Mpy_32_16_ss(L_tmp,shl(sub(bands,lowband),9),&L_tmp,&lo); + L_tmp =L_max(L_tmp,13926); /*14 */ + tmp2 =extract_l(L_min(L_tmp,16384)); /*14 */ + alpha_fx=shl(mult(alpha_fx,tmp2),1);/*14+14-15+1 =14 */ + } + Mpy_32_16_ss(L_band_energy_tmp[i],alpha_fx,&L_tmp,&lo); + L_band_energy_tmp[i] = L_shl(L_tmp,1);/*Q(Q_band_energy+14-15 +1= Q_band_energy) */ + } + } + lowband = 3; + move16(); + Ep_avrg_fx = 0; + move32(); + Ep_avrgL_fx = 0; + move32(); + Ep_peak_fx = 0; + move32(); + FOR(i = 0; i < bands; i++) + { + IF(sub(i,lowband) >=0 ) + { + Ep_avrg_fx = L_add(Ep_avrg_fx,Ep_tmp_fx[i]);/*Q15 */ + } + ELSE + { + Ep_avrgL_fx = L_add(Ep_avrgL_fx,L_shr(Ep_tmp_fx[i],1));/*Q12 */ + IF(L_sub(Ep_tmp_fx[i],Ep_peak_fx) > 0) + { + Ep_peak_fx = Ep_tmp_fx[i]; + move32();/*Q13 */ + } + } + } + Mpy_32_16_ss(Ep_peak_fx,28262,&L_tmp,&lo); + Mpy_32_16_ss(Ep_avrgL_fx,24576,&L_tmp2,&lo); + IF( L_sub(L_shr(Ep_avrg_fx,2), L_tmp2) > 0 && L_sub(L_shr(Ep_avrg_fx,4), L_tmp2) < 0 && L_sub(L_tmp, Ep_avrgL_fx)>0) + { + adjustFlag = 1; + move16(); + FOR (i = 0; i < lowband; i++) + { + tmp = extract_h(Ep_avrgL_fx);/*Q-4 */ + IF(tmp != 0) + { + exp = norm_s(tmp); + tmp = shl(tmp,exp);/*Q(exp) */ + tmp = div_s(16384,tmp);/*Q(15+14-exp=29-exp) */ + exp = sub(29,exp); + } + ELSE + { + tmp = 0x7fff; + move16(); + exp = 0; + move16(); + } + Mpy_32_16_ss(Ep_peak_fx,tmp,&L_tmp,&lo); + Mpy_32_16_ss(L_tmp,lowband,&L_tmp,&lo); + Mpy_32_16_ss(L_tmp,18842,&L_tmp,&lo); + L_tmp = L_shl(L_tmp,sub(27,exp));/*Q14 0.5 */ + tmp2=extract_l(L_min(L_tmp,19661));/*14 */ + Mpy_32_16_ss(L_band_energy_tmp[i],tmp2,&L_tmp,&lo); + L_band_energy_tmp[i] = L_shl(L_tmp,1); /*Q_band_energy */ + } + } + for (i = 0; i < bands; i++) + { + band_energy_tmp[i] = (float)(L_band_energy_tmp[i]/pow(2.0f, SWB_BWE_LR_Qbe)); + } + + hq2_bit_alloc( band_energy_tmp, bands, Rk_fx, &bit_budget, p2a_flags, bit_alloc_weight_fx, + band_width, num_bits, hqswb_clas, st->bwidth, *is_transient ); + } + else if( *is_transient == 0 && inner_frame == L_FRAME16k ) + { + bit_budget = sub(bit_budget,2);/* bits in high bands to indicate the last 2 subbands is allocated bits or not */ + /* decode the last p2a_bands-1 subbands bit-allocation index of the previous frame */ + for(i = 0; i < 2; i++) + { + last_bitalloc_max_band[i] = (short)get_next_indice( st, 1 ); + } + FOR( i = 0; i < bands; i++ ) + { + Ep_tmp_fx[i] = L_shl(Ep_tmp_fx[i],2); + } + IF( st->core_brate == ACELP_13k20 ) + { + lowband = 8; + move16(); + highband = 15; + move16(); + bw_low = sub(band_start[highband],band_start[lowband]); + bw_high = sub(add(band_end[sub(bands,1)],1),band_start[highband]); + } + ELSE + { + lowband = 8; + move16(); + highband = 16; + move16(); + bw_low = sub(band_start[highband],band_start[lowband]); + bw_high = sub(add(band_end[sub(bands,1)],1),band_start[highband]); + } + /* calculate the the low band/high band energy and the variance/avrage of the envelopes */ + enerL_fx = 0; + move32(); + enerH_fx = 0; + move32(); + Ep_vari_fx = 0; + move32(); + Ep_avrg_fx = 0; + move32(); + FOR( i = 0; i < bands; i++ ) + { + IF( sub(i,lowband) >= 0 && add(sub(i,bands),p2a_bands) < 0) + { + Ep_vari_fx = L_add(Ep_vari_fx,L_abs(L_sub(Ep_tmp_fx[i],Ep_tmp_fx[sub(i,1)])));/*Q15 */ + Ep_avrg_fx = L_add(Ep_avrg_fx,Ep_tmp_fx[i]);/*Q15 */ + } + + IF(sub(i,highband) >= 0) + { + enerH_fx = L_add(enerH_fx,L_shl(Ep_fx[i],2));/*Q0 */ + } + ELSE IF(sub(i,lowband) >= 0) + { + enerL_fx = L_add(enerL_fx,L_shl(Ep_fx[i],2));/*Q0 */ + } + } + + enerL = (float)(enerL_fx/pow(2.0,-4)); + enerH = (float)(enerH_fx/pow(2.0,-4)); + /* modify the last p2a_bands subbands band_energies */ + k = (int)bands; + mvi2i( L_band_energy,L_band_energy_tmp,k); /*Q_band_energy */ + + L_tmp = L_max(enerH_fx,enerL_fx); + tmp = s_max(bw_low,bw_high); + i = norm_l(L_tmp); + j = norm_s(tmp); + Mpy_32_16_ss(L_shl(enerH_fx,i),shl(bw_low,j),&L_tmp,&lo); + Mpy_32_16_ss(L_shl(enerL_fx,i),shl(bw_high,j),&L_tmp2,&lo); + L_tmp2 = L_sub(L_tmp,L_tmp2); + + FOR( i = sub(bands,p2a_bands); i < bands; i++ ) + { + IF( sub(p2a_flags[i],1) == 0 || L_tmp2 > 0 ) + { + tmp = sub(bands,p2a_bands); + tmp = sub(tmp,lowband);/*Q0 */ + + tmp1 = extract_h(L_shl(Ep_avrg_fx,1));/*Q0 */ + IF(tmp1 != 0) + { + exp = norm_s(tmp1); + tmp1 = shl(tmp1,exp);/*Q(exp) */ + tmp1 = div_s(16384,tmp1);/*Q(15+14-exp = 29-exp) */ + exp = sub(29,exp); + } + ELSE + { + /*when the divisor is zero, happens rarely*/ + tmp1 = 0x7fff; + move16(); + exp = 0; + move16(); + } + Mpy_32_16_ss(Ep_tmp_fx[i],tmp1,&L_tmp,&lo); + Mpy_32_16_ss(L_tmp,tmp,&L_tmp,&lo); + Mpy_32_16_ss(L_tmp,16384,&L_tmp,&lo); + L_tmp = L_shl(L_tmp,sub(32,exp));/*Q15 */ + tmp = extract_l(L_min(L_tmp,6554));/*Q15 */ + Mpy_32_16_ss(Ep_vari_fx,tmp1,&L_tmp,&lo); + Mpy_32_16_ss(L_tmp,tmp,&L_tmp,&lo); + L_tmp = L_shl(L_tmp,sub(15,exp));/*Q15 */ + tmp = extract_l(L_shr(L_min(L_tmp,13107),1));/*Q14 */ + alpha_fx = add(tmp,16384);/*Q14 */ + } + ELSE + { + alpha_fx = 16384; + move16();/*Q14 */ + } + + IF(add(sub(i,bands),p2a_bands) > 0) + { + tmp = sub(bands, p2a_bands); + IF(sub(last_bitalloc_max_band[sub(i, add(tmp, 1))], 1) == 0) + { + tmp = sub(tmp,lowband); + Mpy_32_16_ss(Ep_tmp_fx[i],tmp,&L_tmp,&lo); + tmp = extract_h(L_shl(L_tmp,16));/*Q0 */ + IF(tmp != 0) + { + exp = norm_s(tmp); + tmp = shl(tmp,exp);/*Q(exp) */ + tmp = div_s(16384,tmp);/*Q(15+14-exp=29-exp) */ + exp = sub(29,exp); + } + ELSE + { + tmp = 0x7fff; + move16(); + exp = 0; + move16(); + } + Mpy_32_16_ss(Ep_avrg_fx,tmp,&L_tmp,&lo); + L_tmp = L_shl(L_tmp,sub(14,exp));/*Q14 */ + tmp = extract_l(L_min(L_max(L_tmp,16384),20480));/*Q14 */ + L_tmp = L_mult(alpha_fx,tmp);/*Q(14+14+1=29) */ + alpha_fx = extract_l(L_shr(L_tmp,15)); /*Q14 */ + } + ELSE + { + tmp = sub(tmp,lowband); + + tmp1 = extract_h(L_shl(Ep_avrg_fx,1));/*Q0 */ + IF(tmp1 != 0) + { + exp = norm_s(tmp1); + tmp1 = shl(tmp1,exp);/*Q(exp) */ + tmp1 = div_s(16384,tmp1);/*Q(15+14-exp=29-exp) */ + exp = sub(29,exp); + } + ELSE + { + /*when the divisor is zero, happens rarely*/ + tmp1 = 0x7fff; + move16(); + exp = 0; + move16(); + } + Mpy_32_16_ss(Ep_tmp_fx[i],tmp1,&L_tmp,&lo); + Mpy_32_16_ss(L_tmp,tmp,&L_tmp,&lo); + L_tmp = L_shl(L_tmp,sub(29,exp));/*Q14 */ + tmp = extract_l(L_min(L_max(L_tmp,13926),16384));/*Q14 */ + L_tmp = L_mult(alpha_fx,tmp);/*Q(14+14+1=29) */ + alpha_fx = extract_l(L_shr(L_tmp,15)); /*Q14 */ + } + } + Mpy_32_16_ss(L_band_energy_tmp[i],alpha_fx,&L_tmp,&lo); + L_band_energy_tmp[i] = L_shl(L_tmp,1);/*Q Q_band_energy */ + } + lowband = 6; + move16(); + Ep_avrg_fx = 0; + move32(); + Ep_avrgL_fx = 0; + move32(); + Ep_peak_fx = 0; + move32(); + FOR(i = 0; i < bands; i++) + { + IF(sub(i,lowband) >= 0) + { + Ep_avrg_fx = L_add(Ep_avrg_fx,Ep_tmp_fx[i]);/*Q15 */ + } + ELSE + { + Ep_avrgL_fx = L_add(Ep_avrgL_fx,Ep_tmp_fx[i]);/*Q15 */ + IF(L_sub(Ep_tmp_fx[i],Ep_peak_fx) > 0) + { + Ep_peak_fx = Ep_tmp_fx[i]; + move32();/*Q15 */ + } + } + } + + Mpy_32_16_ss(Ep_peak_fx,24576,&L_tmp,&lo); + Mpy_32_16_ss(Ep_peak_fx,19661,&L_tmp2,&lo); + Mpy_32_16_ss(Ep_avrgL_fx,24576,&L_tmp3,&lo); + + IF( (L_sub(L_shr(Ep_avrgL_fx,1), Ep_avrg_fx)>0 && L_sub(L_tmp,L_shr(Ep_avrgL_fx,2)) > 0 && L_sub(L_shr(Ep_avrgL_fx,1),L_tmp2) < 0 ) || + (L_sub(L_shr(Ep_avrg_fx,1), Ep_avrgL_fx)>0 && L_sub(L_shr(Ep_avrg_fx,3),L_tmp3) < 0 && L_sub(L_tmp,L_shr(Ep_avrgL_fx,2)) > 0 ) ) + { + adjustFlag = 1; + move16(); + FOR (i = 0; i < lowband; i++) + { + tmp = extract_h(L_shl(Ep_avrgL_fx,1));/*Q0 */ + IF(tmp != 0) + { + exp = norm_s(tmp); + tmp = shl(tmp,exp);/*Q(exp) */ + tmp = div_s(16384,tmp);/*Q(15+14-exp=29-exp) */ + exp = sub(29,exp); + } + ELSE + { + tmp = 0x7fff; + move16(); + exp = 0; + move16(); + } + Mpy_32_16_ss(Ep_peak_fx,tmp,&L_tmp,&lo); + Mpy_32_16_ss(L_tmp,lowband,&L_tmp,&lo); + L_tmp = L_shl(L_tmp,sub(28,exp));/*Q14 0.5 */ + tmp = extract_l(L_min(L_tmp,19661));/* Q14 */ + Mpy_32_16_ss(L_band_energy_tmp[i],tmp,&L_tmp,&lo); + L_band_energy_tmp[i] = L_shl(L_tmp,1); /*Q_band_energy */ + } + } + for (i = 0; i < bands; i++) + { + band_energy_tmp[i] = (float)(L_band_energy_tmp[i]/pow(2.0f, SWB_BWE_LR_Qbe)); + } + + hq2_bit_alloc( band_energy_tmp, bands, Rk_fx, &bit_budget, p2a_flags, bit_alloc_weight_fx, + band_width, num_bits, hqswb_clas, st->bwidth,*is_transient ); + } + else if( st->bwidth == SWB && hqswb_clas == HQ_HARMONIC && (bwe_br == HQ_16k40 || bwe_br == HQ_13k20) ) + { + hq2_bit_alloc_har( band_energy, bit_budget, bands, Rk_fx, p2a_bands,bwe_br,p2a_flags,band_width); + } + else + { + hq2_bit_alloc( band_energy, bands, Rk_fx, &bit_budget, p2a_flags, bit_alloc_weight_fx, + band_width, num_bits, hqswb_clas, st->bwidth, *is_transient ); + } + + if( bit_budget < 0 ) + { + st->BER_detect = 1; + bit_budget = 0; + } + + tcq_core_LR_dec( st, inp_vector, bit_budget, bands, band_start, band_width, Rk_fx, npulses, k_sort, + p2a_flags, p2a_bands, last_bitalloc_max_band, inner_frame, adjustFlag, is_transient ); + + /* Prepare floating Rk for next modules */ + for( k = 0; k < bands; k++) + { + Rk[k] = WORD322FL_SCALE( Rk_fx[k], SWB_BWE_LR_QRk - 1); + } + + /* Denormalize the coded MDCT spectrum */ + mdct_spectrum_denorm( inp_vector, y2, band_start, band_end, band_width, band_energy, npulses, bands, ld_slope, pd_thresh ); + + /* Apply fine gain to denormalized coded spectrum */ + mdct_spectrum_fine_gain_dec( st, y2, band_start, band_end, k_sort, bands, L_qint, Ngq, gqlevs, gqbits ); + + /*restore the band information */ + if( flag_spt == 1 ) + { + spt_shorten_domain_band_restore( bands, band_start, band_end, band_width, org_band_start, org_band_end, org_band_width ); + } + + mvr2r( y2, y2_org, L_FRAME32k ); + + /* Inject noise into components having relatively low pulse energy per band */ + ni_seed = npulses[0] + npulses[1] + npulses[2] + npulses[3]; + + for(i=0; ilast_ni_gain, st->last_env, &st->last_max_pos_pulse, p2a_flags, p2a_bands, hqswb_clas, st->bwidth, bwe_br ); + + if( st->bwidth == SWB && (bwe_br == HQ_16k40 || bwe_br == HQ_13k20) ) + { + if( hqswb_clas == HQ_NORMAL || hqswb_clas == HQ_HARMONIC ) + { + preset_hq2_swb( hqswb_clas, band_end, &har_bands, p2a_bands,length, bands, &lowlength, &highlength, m ); + + /*Gap filling for the core coder*/ + swb_bwe_dec_lr( st, y2, m, bwe_br , bands, band_start, band_end, band_energy, p2a_flags, hqswb_clas, lowlength, + highlength, har_bands, &st->prev_frm_hfe2, &st->prev_stab_hfe2, band_width,y2_ni, &ni_seed ); + + post_hq2_swb( m, lowlength, highlength, hqswb_clas, har_bands, bands, p2a_flags, band_start, band_end, y2, npulses ); + + if( hqswb_clas == HQ_NORMAL ) + { + spt_swb_peakpos_tmp_save( y2, bands, band_start, band_end, prev_SWB_peak_pos_tmp ); + for( k=0; klast_inner_frame >= L_FRAME16k && st->bws_cnt > 0) ) + { + k1 = *is_transient ? bands - 2 : bands - 6; + st->prev_ener_shb = 0.0f; + + for( i = k1; i < bands; i++ ) + { + st->prev_ener_shb += Ep_tmp[i]/(bands-k1); + } + } + + if( st->last_inner_frame >= L_FRAME32k ) + { + set_f(st->prev_SWB_fenv, st->prev_ener_shb, SWB_FENV); + } + + updat_prev_frm( y2, yout, bwe_br, length, inner_frame, bands, st->bwidth, *is_transient, hqswb_clas, &st->prev_hqswb_clas, + st->prev_SWB_peak_pos, prev_SWB_peak_pos_tmp, &st->prev_frm_hfe2, &st->prev_stab_hfe2, st->bws_cnt ); + + return; +} + + +/*------------------------------------------------------------------------------------ + * small_symbol_dec_tran() + * + * Huffman decoding of differential energies + *--------------------------------------------------------------------------------------*/ +static short small_symbol_dec_tran( + Decoder_State *st, /* i/o: decoder state structure */ + int *qbidx, /* o : output of dequantized differential energy */ + const short bands, /* i : number of bands */ + const short is_transient /* i : transient flag */ +) +{ + short i, bits; + short difidx[BANDS_MAX]; + + /* Decoding differential energies*/ + bits = decode_envelope_indices(st, 0, bands, 0, difidx, LOW_RATE_HQ_CORE_TRAN ,is_transient); + bits += BITS_DE_FCOMP; + + /* counting 1 bit for band_energy_huff_coding_mode */ + bits += BITS_DE_HMODE; + + /* converting to original values */ + for( i=0; i 0) + { + *rbits+=(*hufftab & 0xf); + bit = (short)get_next_indice( st, *hufftab & 0xf ); + hufftab += (*hufftab >> 4) + bit; + } + + return (-*hufftab); +} + +static short large_symbol_dec( /* o : bits */ + Decoder_State *st, /* i/o: decoder state structure */ + int *qbidx, /* o : output of dequantized differential energy */ + const short bands /* i : number of bands */ +) +{ + short i, bits; + short LSB[BANDS_MAX]; + short basic_shift,cntbits,ns2mode; + short pos_outlyer; + short ns2mode0,ns2mode1; + + cntbits = BITS_DE_8SMODE; + ns2mode = (short)get_next_indice (st, BITS_DE_8SMODE); + + if (ns2mode == 0 ) + { + ns2mode0 = (short)get_next_indice (st, BITS_DE_8SMODE_N0); + ns2mode1 = (short)get_next_indice (st, BITS_DE_8SMODE_N1); + cntbits += BITS_DE_8SMODE_N0+BITS_DE_8SMODE_N1; + + if (ns2mode0 == 0) + { + if (ns2mode1 == 1) + { + pos_outlyer = (short)get_next_indice (st, BITS_DE_8SPOS); + cntbits+=BITS_DE_8SPOS; + qbidx[pos_outlyer] = ((short)get_next_indice (st, BITS_ABS_ENG) - ABS_ENG_OFFSET); + cntbits+=BITS_ABS_ENG; + } + else + { + pos_outlyer = -1; + } + + for( i=0; i Qbe(Q14) */ + band_energy[k] = (float)(L_band_energy[k]/pow(2.0f, SWB_BWE_LR_Qbe)); + } + + if( is_transient ) + { + reverse_transient_frame_energies( band_energy, bands ); + } + + return( deng_bits ); +} + + +/*--------------------------------------------------------------------------* + * p2a_threshold_dequant() + * + * + *--------------------------------------------------------------------------*/ + +static short p2a_threshold_dequant( + Decoder_State *st, /* i/o: decoder state structure */ + short *p2a_flags, + const short bands, + const short p2a_bands +) +{ + short j, k; + + for( k = 0; k < bands - p2a_bands; k++ ) + { + p2a_flags[k] = 1; + } + + j = 0; + for( k = bands - p2a_bands; k < bands; k++ ) + { + p2a_flags[k] = (short) get_next_indice( st, 1 ); + j++; + } + + return( j ); +} + + +/*--------------------------------------------------------------------------* + * mdct_spectrum_fine_gain_dec() + * + * + *--------------------------------------------------------------------------*/ + +static void mdct_spectrum_fine_gain_dec( + Decoder_State *st, /* i/o: decoder state structure */ + float y2[], + const short band_start[], + const short band_end[], + const short k_sort[], + const short bands, + const Word32 L_qint, + const short Ngq, + const short gqlevs, + const short gqbits +) +{ + short i, k, imin; + float gamma; + float gain_table[MAX_GQLEVS]; + Word16 exp_normn, exp_normd; + Word16 delta_fx, Qdelta; + Word32 L_delta, L_q; + Word32 L_temp; + Word16 gain_table_fx[MAX_GQLEVS]; + Word16 Qgt; + Word16 temp_lo_fx, temp_hi_fx; + + /* Fine gain quantization on only the most significant energy bands */ + /*delta = qint / gqlevs; */ + exp_normn = norm_l(L_qint); + exp_normn = sub(exp_normn, 1); + exp_normd = norm_s(gqlevs); + delta_fx = div_l(L_shl(L_qint, exp_normn), shl(gqlevs, exp_normd)); + Qdelta = add(sub(exp_normn, exp_normd), 28); /* 29+exp_normn-(exp_normd)-1; */ + L_delta = L_shl(L_deposit_h(delta_fx), sub(13, Qdelta)); + /*q = (-qint + delta) / 2.0f; */ + L_q = L_shr(L_sub(L_delta, L_qint), 1); + + FOR (i = 0; i < gqlevs; i++) + { + /*gain_table[i] = (float) pow (2.0f, q * 0.5f); */ + L_temp = L_shr(L_shr(L_q, 1), sub(29, 16)); + temp_lo_fx = L_Extract_lc(L_temp, &temp_hi_fx); + Qgt = sub(14, temp_hi_fx); + gain_table_fx[i] = extract_l(Pow2(14, temp_lo_fx)); /* Qgt */ + + /*q += delta; */ + L_q = L_add(L_q, L_delta); + gain_table_fx[i] = shl(gain_table_fx[i], sub(14, Qgt)); /* Qgt -> Q14 */ + gain_table[i] = (float)(gain_table_fx[i]/pow(2.0f, 14)); + } + + for( k = bands - Ngq; k < bands; k++ ) + { + imin = (short)get_next_indice( st, gqbits ); + gamma = gain_table[imin]; + + for( i = band_start[k_sort[k]]; i <= band_end[k_sort[k]]; i++ ) + { + y2[i] *= gamma; + } + } + + return; +} + +/*--------------------------------------------------------------------------* + * spt_shorten_domain_set_dec() + * + * update the shorten band information based on p2a analysis + *--------------------------------------------------------------------------*/ + +static void spt_shorten_domain_set_dec( + Decoder_State *st, /* i: encoder state structure */ + const short p2a_flags[], /* i: p2a anlysis information */ + const short new_band_start[], /* i: new band start position */ + const short new_band_end[], /* i: new band end position */ + const short new_band_width[], /* i: new subband band width */ + const short bands, /* i: total number of subbands */ + short band_start[], /* o: band start position */ + short band_end[], /* o: band end position */ + short band_width[], /* o: sub band band width */ + short *bit_budget /* i/o: bit budget */ +) +{ + int j,k; + short kpos; + short spt_shorten_flag[SPT_SHORTEN_SBNUM]; + + kpos = 0; + j = 0; + for( k = bands - SPT_SHORTEN_SBNUM; k < bands; k++ ) + { + spt_shorten_flag[j] = 0; + if(p2a_flags[k] == 1) + { + spt_shorten_flag[j] = (short)get_next_indice (st, 1 ); + *bit_budget -= 1; + if(spt_shorten_flag[j] == 1) + { + band_start[k] = new_band_start[j]; + band_end[k] = new_band_end[j]; + band_width[k] = new_band_width[j]; + } + } + + kpos++; + j++; + } + + return; +} diff --git a/src/libs/libevs/lib_dec/hq_lr_dec_fx.cpp b/src/libs/libevs/lib_dec/hq_lr_dec_fx.cpp deleted file mode 100755 index 772e1a0c..00000000 --- a/src/libs/libevs/lib_dec/hq_lr_dec_fx.cpp +++ /dev/null @@ -1,1332 +0,0 @@ -/*==================================================================================== - EVS Codec 3GPP TS26.442 Apr 03, 2018. Version 12.11.0 / 13.6.0 / 14.2.0 - ====================================================================================*/ - -#include -#include -#include -#include "options.h" -#include "cnst_fx.h" -#include "rom_dec_fx.h" -#include "prot_fx.h" -#include "rom_com_fx.h" -#include "stl.h" /* required for wmc_tool */ -#include "basop_mpy.h" - -/*--------------------------------------------------------------------------* - * Local functions - *--------------------------------------------------------------------------*/ - -static Word16 p2a_threshold_dequant_fx( Decoder_State_fx *st_fx, Word16 *p2a_flags, const Word16 bands, const Word16 p2a_bands ); - -static void mdct_spectrum_fine_gain_dec_fx( Decoder_State_fx *st_fx, Word32 L_y2[], const Word16 band_start[], const Word16 band_end[], - const Word16 k_sort[], const Word16 bands, - const Word32 L_qint,const Word16 Ngq, const Word16 gqlevs, const Word16 gqbits ); - -static Word16 band_energy_dequant_fx( Decoder_State_fx *st_fx, Word32 L_band_energy[], const Word16 bands, - const Word32 L_qint,const Word16 eref_fx, const Word16 is_transient_fx ); - -static Word16 Calc_inv(Word32 L_tmp, Word16 *exp) -{ - Word16 exp2, tmp; - - tmp = extract_h(L_tmp); - - IF(tmp != 0) - { - exp2 = norm_s(tmp); - tmp = shl(tmp,exp2);/*Q(exp) */ - tmp = div_s(16384,tmp);/*Q(15+14-exp=29-exp) */ - *exp = sub(29,exp2); - move16(); - } - ELSE - { - tmp = 0x7fff; - move16(); - *exp = 0; - move16(); - } - return tmp; -} - -/*--------------------------------------------------------------------------* - * spt_shorten_domain_set_dec() - * - * update the shorten band information based on p2a analysis - *--------------------------------------------------------------------------*/ - -static void spt_shorten_domain_set_dec_fx( - Decoder_State_fx *st_fx, /* i: encoder state structure */ - const Word16 p2a_flags[], /* i: p2a anlysis information */ - const Word16 new_band_start[], /* i: new band start position */ - const Word16 new_band_end[], /* i: new band end position */ - const Word16 new_band_width[], /* i: new subband band width */ - const Word16 bands, /* i: total number of subbands */ - Word16 band_start[], /* o: band start position */ - Word16 band_end[], /* o: band end position */ - Word16 band_width[], /* o: sub band band width */ - Word16 *bit_budget /* i/o: bit budget */ -) -{ - Word16 j,k; - Word16 kpos; - Word16 spt_shorten_flag[SPT_SHORTEN_SBNUM]; - - kpos = 0; - move16(); - j = 0; - move16(); - FOR( k = sub(bands,SPT_SHORTEN_SBNUM); k < bands; k++ ) - { - spt_shorten_flag[j] = 0; - move16(); - IF( sub(p2a_flags[k], 1) == 0) - { - spt_shorten_flag[j] = get_next_indice_fx (st_fx, 1 ); - *bit_budget = sub(*bit_budget, 1); - IF( sub(spt_shorten_flag[j], 1) == 0) - { - band_start[k] = new_band_start[j]; - move16(); - band_end[k] = new_band_end[j]; - move16(); - band_width[k] = new_band_width[j]; - move16(); - } - } - - kpos = add(kpos, 1); - j = add(j, 1); - } - - return; -} - -/*-------------------------------------------------------------------* - * hq_lr_dec_fx() - * - * HQ low rate decoding routine - *-------------------------------------------------------------------*/ - -void hq_lr_dec_fx( - Decoder_State_fx *st_fx, /* i/o: : decoder state structure */ - Word32 L_yout[], /* o : Q12 : transform-domain output coefs. */ - const Word16 inner_frame, /* i : Q0 : inner frame length */ - Word16 num_bits, /* i : Q0 : number of available bits */ - Word16 *is_transient_fx /* o : Q0 : transient flag */ -) -{ - Word16 i, j, k; - - Word32 L_y2[L_FRAME48k]; - Word32 L_y2_ni[L_FRAME48k]; - Word32 L_y2_org[L_FRAME48k]; - Word16 inp_vector_fx[L_FRAME48k]; - Word16 flag_spt_fx; - Word32 L_m[L_FRAME48k]; - Word32 L_band_energy[BANDS_MAX]; - Word32 L_band_energy_tmp[BANDS_MAX]; - - Word16 npulses_fx[BANDS_MAX]; - Word16 lowlength_fx, highlength_fx, hqswb_clas_fx, har_bands_fx, bands_fx; - Word16 p2a_flags_fx[BANDS_MAX]; - Word32 L_bwe_br; - Word16 prev_SWB_peak_pos_tmp_fx[SPT_SHORTEN_SBNUM]; - - Word16 band_start[BANDS_MAX], band_end[BANDS_MAX], band_width[BANDS_MAX],trans_bit_fx; - - /* hq2_core_configure */ - Word32 L_qint; - /*Word16 Qqint=29;*/ - - Word16 eref_fx/*, Qeref=10*/; - Word16 bit_alloc_weight_fx/*, Qbaw=13*/; - Word16 ld_slope_fx/*, Qldslope=15*/; - Word16 p2a_th_fx/*, Qp2ath=11*/; - Word16 pd_thresh_fx/*, Qpdth=15*/; - Word16 ni_coef_fx/*, Qnicoef=14*/; - - Word32 L_Rk[BANDS_MAX]; - Word16 bit_budget_fx; - - Word16 ni_seed_fx; - Word16 length_fx; - Word16 pbits_fx; - - Word16 k1_fx; - Word16 gqlevs_fx, gqbits_fx, Ngq_fx, p2a_bands_fx; - Word16 ebits_fx; - Word16 exp_norm; - Word16 org_band_start[SPT_SHORTEN_SBNUM]; - Word16 org_band_end[SPT_SHORTEN_SBNUM]; - Word16 org_band_width[SPT_SHORTEN_SBNUM]; - - Word16 new_band_start[SPT_SHORTEN_SBNUM]; - Word16 new_band_end[SPT_SHORTEN_SBNUM]; - Word16 new_band_width[SPT_SHORTEN_SBNUM]; - - Word16 k_sort_fx[BANDS_MAX]; - Word16 last_bitalloc_max_band[2]; - Word32 L_tmp; - Word16 lowband,highband,p2a_flags_tmp[BANDS_MAX]; - Word32 L_tmp2,L_tmp3; - Word16 exp,exp2,tmp,tmp1,tmp2,tmp3,frac1,alpha_fx,Q_band_energy; - Word32 enerH_fx; - Word32 enerL_fx; - Word32 Ep_fx[BANDS_MAX]; - Word32 Ep_avrg_fx, Ep_vari_fx; - Word32 Ep_avrgL_fx; - Word32 Ep_peak_fx; - Word32 Ep_tmp_fx[BANDS_MAX]; - Word16 gama_fx;/*Q15 0.85f;// */ - Word16 beta_fx;/*Q14 1.05f; */ - Word16 adjustFlag; - Word16 bw_low, bw_high; - - tmp2 = 0; /* to avoid compilation flags */ - - set16_fx(last_bitalloc_max_band, 0, 2); - set32_fx( L_y2, 0x0L, L_FRAME48k ); - set16_fx( inp_vector_fx, 0, inner_frame ); - flag_spt_fx = 0; - move16(); - set16_fx(prev_SWB_peak_pos_tmp_fx, 0, SPT_SHORTEN_SBNUM); - adjustFlag = 0; - move16(); - bw_low = 0; - move16(); - bw_high = 20; - move16(); - enerL_fx = L_deposit_l(0); - enerH_fx = L_deposit_l(0); - - L_bwe_br = L_add(st_fx->core_brate_fx, 0); - hqswb_clas_fx = 0; - move16(); - test(); - test(); - IF( sub(st_fx->bwidth_fx, SWB) == 0 && ( L_sub(L_bwe_br, HQ_16k40) == 0 || L_sub(L_bwe_br, HQ_13k20) == 0 ) ) - { - hqswb_clas_fx = get_next_indice_fx(st_fx, 2); - num_bits = sub(num_bits, 2); - - *is_transient_fx = 0; - move16(); - if ( sub(hqswb_clas_fx, HQ_TRANSIENT) == 0 ) - { - *is_transient_fx = 1; - move16(); - } - } - ELSE - { - /* decode transient flag */ - *is_transient_fx = get_next_indice_fx(st_fx, 1); - num_bits = sub(num_bits, 1); - } - - /* Configure decoder for different bandwidths, bit rates, etc. */ - hq2_core_configure_fx( inner_frame, num_bits, *is_transient_fx, &bands_fx, &length_fx, band_width, band_start, band_end, - &L_qint, &eref_fx, &bit_alloc_weight_fx, &gqlevs_fx, &Ngq_fx, &p2a_bands_fx, &p2a_th_fx, &pd_thresh_fx, &ld_slope_fx, &ni_coef_fx - ,L_bwe_br); - - highlength_fx = band_end[bands_fx-1]; - move16(); - har_bands_fx = bands_fx; - move16(); - - test(); - test(); - test(); - IF( sub(st_fx->bwidth_fx, SWB) == 0 && *is_transient_fx == 0 && (L_sub(L_bwe_br, HQ_16k40) == 0 || L_sub(L_bwe_br, HQ_13k20) == 0) ) - { - /* reserve bits for HQ_NORMAL2 and HQ_HARMONIC modes */ - test(); - IF( sub(hqswb_clas_fx, HQ_NORMAL) == 0 || sub(hqswb_clas_fx, HQ_HARMONIC) == 0 ) - { - num_bits = sub(num_bits, get_usebit_npswb_fx(hqswb_clas_fx)); - } - if( sub(hqswb_clas_fx, HQ_NORMAL) == 0) - { - flag_spt_fx = 1; - move16(); - } - } - - test(); - test(); - IF(( L_sub(L_bwe_br, HQ_16k40) == 0 || L_sub(L_bwe_br, HQ_13k20) == 0) && sub(st_fx->bwidth_fx, SWB) == 0 ) - { - IF( sub(st_fx->prev_hqswb_clas_fx, HQ_NORMAL) != 0 ) - { - j = 0; - move16(); - FOR(k=sub(bands_fx,SPT_SHORTEN_SBNUM); kprev_SWB_peak_pos_fx[j] = 0; - move16(); - j = add(j, 1); - } - } - } - - /* Spectral energy calculation/quantization */ - ebits_fx = band_energy_dequant_fx( st_fx, L_band_energy, bands_fx, L_qint, eref_fx, *is_transient_fx ); - - /* simple check: band_energy is too large, Abnormal Situation of bit errors */ - FOR( k=0; k 0 || L_sub(L_band_energy[k], -109772L) < 0 ) - { - st_fx->BER_detect = 1; - move16(); - set32_fx( L_yout, 0x0L, inner_frame ); - return; - } - } - - /* First pass bit budget for TCQ of spectral band information */ - exp_norm = norm_s(gqlevs_fx); - gqbits_fx = sub(14, exp_norm); - - bit_budget_fx = sub(sub(num_bits, ebits_fx), round_fx(L_shl(L_mult(Ngq_fx, gqbits_fx), 15))); /* (*num_bits) - (short) ceil (ebits) - Ngq * gqbits; */ - - - pbits_fx = 0; - move16(); - test(); - test(); - IF( sub(st_fx->bwidth_fx, SWB) == 0 && (L_sub(L_bwe_br, HQ_16k40) == 0 || L_sub(L_bwe_br, HQ_13k20) == 0 ) ) - { - IF ( sub(hqswb_clas_fx, HQ_HARMONIC) == 0 ) - { - set16_fx( p2a_flags_fx, 1, har_bands_fx ); - } - ELSE - { - pbits_fx = p2a_threshold_dequant_fx( st_fx, p2a_flags_fx, bands_fx, p2a_bands_fx ); - bit_budget_fx = sub(bit_budget_fx, pbits_fx); - - IF( sub(hqswb_clas_fx, HQ_NORMAL) == 0 ) - { - return_bits_normal2_fx( &bit_budget_fx, p2a_flags_fx, bands_fx, bits_lagIndices_modeNormal_fx ); - } - } - } - ELSE - { - pbits_fx = p2a_threshold_dequant_fx( st_fx, p2a_flags_fx, bands_fx, p2a_bands_fx ); - bit_budget_fx = sub(bit_budget_fx, pbits_fx); - } - - IF( sub(flag_spt_fx, 1) == 0 ) - { - /* initalize the desired parameters for SPT */ - spt_shorten_domain_band_save_fx(bands_fx, band_start, band_end, band_width, org_band_start, org_band_end, org_band_width); - spt_shorten_domain_pre_fx(band_start, band_end, st_fx->prev_SWB_peak_pos_fx, bands_fx, L_bwe_br, new_band_start, new_band_end, new_band_width); - spt_shorten_domain_set_dec_fx(st_fx, p2a_flags_fx, new_band_start, new_band_end, new_band_width, bands_fx, band_start, band_end, band_width, &bit_budget_fx); - } - - /* safety check in case of bit errors */ - IF( sub(bit_budget_fx, 2) < 0 ) - { - st_fx->BER_detect = 1; - move16(); - set32_fx( L_yout, 0x0, inner_frame ); - return; - } - - Q_band_energy = SWB_BWE_LR_Qbe; - FOR(i = 0; i < bands_fx; i++) - { - L_tmp = L_shl(L_band_energy[i],sub(16,Q_band_energy));/*Q16 */ - - frac1 = L_Extract_lc(L_tmp, &exp); /* Extract exponent of L_tmp */ - L_tmp = Pow2(30, frac1); - exp = sub(exp, 30); - Ep_fx[i] = L_shl(L_tmp , s_max(sub(exp,6), -31)); /* Q -6 */ - } - - FOR( i = 0; i < bands_fx; i++ ) - { - L_tmp2 = Ep_fx[i]; - L_tmp = L_max(1, L_tmp2); - exp = norm_l(L_tmp); - tmp = extract_h(L_shl(L_tmp, exp)); - - L_tmp3 = (Word32)band_width[i]; - exp2 = norm_l(L_tmp3); - tmp2 = extract_h(L_shl(L_tmp3, exp2)); - - exp2 = sub(exp, exp2); /* Denormalize and substract */ - - tmp3 = sub(tmp2, tmp); - if (tmp3 > 0) - { - tmp2 = shr(tmp2, 1); - } - if (tmp3 > 0) - { - exp2 = add(exp2, 1); - } - tmp = div_s(tmp2, tmp); - L_tmp = L_deposit_h(tmp); - L_tmp = Isqrt_lc(L_tmp, &exp2);/*Q(31-exp2) */ - Ep_tmp_fx[i] = L_shr(L_tmp,sub(15,exp2));/*Q13 */ move32(); - } - - test(); - test(); - test(); - test(); - test(); - test(); - IF ( *is_transient_fx == 0 && sub(inner_frame, L_FRAME8k) == 0 && L_sub(st_fx->core_brate_fx, ACELP_13k20) <= 0 ) - { - /* decode the last p2a_bands-1 subbands bit-allocation index of the previous frame */ - j = 0; - FOR(i = 0; i < 2; i++) - { - last_bitalloc_max_band[i] = get_next_indice_fx( st_fx, 1 ); - } - lowband = 6; - move16(); - trans_bit_fx = 2; - move16(); - bit_budget_fx = sub(bit_budget_fx,trans_bit_fx); - gama_fx = 27852; - move16(); /*Q15 0.85f; */ - beta_fx = 17203; - move16(); /*Q14 1.05f; */ - - set16_fx(&p2a_flags_tmp[sub(bands_fx,trans_bit_fx)], 0, 2); - - IF( L_sub(st_fx->core_brate_fx, ACELP_13k20) == 0 ) - { - beta_fx = 13107; - move16();/*14 1.25f; */ - gama_fx = 31130; - move16();/*0.95f; */ - Copy(&p2a_flags_fx[sub(bands_fx,trans_bit_fx)], &p2a_flags_tmp[sub(bands_fx,trans_bit_fx)], trans_bit_fx); - } - - /* calculate the the low band/high band energy and the variance/avrage of the envelopes */ - Ep_vari_fx = L_deposit_l(0); - Ep_avrg_fx = L_deposit_l(0); - Ep_avrgL_fx = L_deposit_l(0); - Ep_peak_fx = L_deposit_l(0); - FOR( i = 0; i < bands_fx; i++ ) - { - IF( sub(i,lowband) >= 0) - { - Ep_vari_fx = L_add(Ep_vari_fx,L_abs(L_sub(Ep_tmp_fx[i],Ep_tmp_fx[sub(i,1)])));/*Q15 */ - Ep_avrg_fx = L_add(Ep_avrg_fx,Ep_tmp_fx[i]);/*Q15 */ - - } - ELSE - { - Ep_avrgL_fx = L_add(Ep_avrgL_fx,Ep_tmp_fx[i]);/*Q15 */ - if(L_sub(Ep_tmp_fx[i],Ep_peak_fx) > 0) - { - Ep_peak_fx = L_add(Ep_tmp_fx[i], 0); /*Q15 */ - } - } - - } - /* modify the last p2a_bands subbands band_energies */ - Copy32( L_band_energy,L_band_energy_tmp,bands_fx ); /*Q_band_energy */ - L_tmp = Mult_32_16(Ep_peak_fx,24576);/*Q(13+14-15 = 12) 1.5 lowband = 6; */ - L_tmp2 =Mult_32_16(Ep_peak_fx,shl(sub(bands_fx,lowband),9));/*Q(13+9-15 = 7) */ - L_tmp3 =Mult_32_16(Ep_avrg_fx,1126);/*Q(13+9-15 = 7) */ - - test(); - test(); - test(); - test(); - IF(( (L_sub(L_tmp, L_shr(Ep_avrgL_fx,1)) < 0 && L_sub(st_fx->core_brate_fx, ACELP_13k20) == 0 ) || L_sub(st_fx->core_brate_fx, ACELP_13k20) < 0 )&& - L_sub(L_tmp2, L_tmp3) < 0 && L_sub(L_tmp2, L_shr(Ep_avrg_fx,7)) > 0) - { - FOR(i = lowband; i < bands_fx; i++) - { - L_tmp = Mult_32_16(Ep_avrg_fx,24576);/*Q(13+14-15 = 12) 1.5 */ - IF(L_sub(L_shr(Ep_tmp_fx[i],1), L_tmp) < 0) - { - L_tmp = Mult_32_16(Ep_peak_fx,sub(bands_fx,lowband));/*Q(13+0-15 = -2) */ - tmp = Calc_inv(L_shl(L_tmp,14), &exp); - L_tmp = L_shl(Mult_32_16(Ep_avrg_fx,tmp),sub(13,exp));/*Q(13+exp-15 +13-exp +4 = 15) */ - L_tmp2 = L_add(L_tmp,13107); /*15 */ - tmp2 = extract_l(L_min(L_max(L_tmp2,16384),gama_fx)); /*15 = 15 */ - L_band_energy_tmp[i] = Mult_32_16(L_band_energy_tmp[i],tmp2);/*Q(Q_band_energy+15-15 = Q_band_energy) */ move32(); - } - } - } - ELSE - { - FOR(i = sub(bands_fx,trans_bit_fx); i < bands_fx; i++) - { - alpha_fx = 16384; - move16();/*Q14 */ - IF( sub(p2a_flags_tmp[i],1) == 0) - { - L_tmp = Mult_32_16(Ep_tmp_fx[i],sub(bands_fx,lowband));/*Q(13+0-15 = -2) */ - tmp = Calc_inv(L_shl(L_tmp,14), &exp); - L_tmp =Mult_32_16(Ep_vari_fx,3277);/*13+15-15=13 */ - L_tmp = L_shl(Mult_32_16(L_tmp,tmp),sub(12,exp));/*Q(13+exp-15 +12-exp +4 = 14) */ - - tmp2 = extract_h(Ep_avrg_fx);/*Q13-16=-3 */ - IF(tmp2 != 0) - { - exp = norm_s(tmp2); - tmp2 = shl(tmp2,exp);/*Q(exp) */ - tmp2 = div_s(16384,tmp2);/*Q(15+14-exp=29-exp) */ - exp = sub(29,exp); - } - ELSE - { - /*when the divisor is zero, happens rarely*/ - tmp2 = 0x7fff; - move16(); - exp = 0; - move16(); - } - L_tmp2 =Mult_32_16(Ep_vari_fx,6554);/*13+15-15=13 */ - L_tmp2 = L_shl(Mult_32_16(L_tmp2,tmp2),sub(13,exp));/*Q(13+exp-15 +13-exp +3 = 14) */ - L_tmp=L_min(L_tmp,L_tmp2);/*14 */ - tmp=extract_l(L_min(L_tmp,13107));/*14 */ - alpha_fx =add(16384,tmp); - - } - IF(sub(last_bitalloc_max_band[j++], 1) == 0) - { - L_tmp = Mult_32_16(Ep_tmp_fx[i],sub(bands_fx,lowband));/*Q(13+0-15 = -2) */ - tmp = Calc_inv(L_shl(L_tmp,14), &exp); - L_tmp = L_shl(Mult_32_16(Ep_avrg_fx,tmp),sub(14,exp));/*Q(13+exp-15 +14-exp+2 = 14) */ - L_tmp =L_max(L_tmp,16384); /*14 */ - tmp=extract_l(L_min(L_tmp,beta_fx)); /*14 */ - alpha_fx=shl(mult(alpha_fx,tmp),1);/*14+14-15 +1=14 */ - } - ELSE - { - tmp2 = extract_h(Ep_avrg_fx);/*13 -16 =-3 */ - IF(tmp2 != 0) - { - exp = norm_s(tmp2); - tmp2 = shl(tmp2,exp);/*Q(exp) */ - tmp2 = div_s(16384,tmp2);/*Q(15+14-exp=29-exp) */ - exp = sub(29,exp); - } - ELSE - { - /*when the divisor is zero, happens rarely*/ - tmp2 = 0x7fff; - move16(); - exp = 0; - move16(); - } - L_tmp = L_shl(Mult_32_16(Ep_tmp_fx[i],tmp2),sub(19,exp));/*Q(13+exp-15 +19-exp +3 = 20) */ - L_tmp = Mult_32_16(L_tmp,shl(sub(bands_fx,lowband),9));/*20 +9 -15 =14 */ - L_tmp =L_max(L_tmp,13926); /*14 */ - tmp2 =extract_l(L_min(L_tmp,16384)); /*14 */ - alpha_fx=shl(mult(alpha_fx,tmp2),1);/*14+14-15+1 =14 */ - } - L_band_energy_tmp[i] = L_shl(Mult_32_16(L_band_energy_tmp[i],alpha_fx),1);/*Q(Q_band_energy+14-15 +1= Q_band_energy) */ move32(); - } - } - lowband = 3; - move16(); - Ep_avrg_fx = L_deposit_l(0); - Ep_avrgL_fx = L_deposit_l(0); - Ep_peak_fx = L_deposit_l(0); - FOR(i = 0; i < bands_fx; i++) - { - IF(sub(i,lowband) >=0 ) - { - Ep_avrg_fx = L_add(Ep_avrg_fx,Ep_tmp_fx[i]);/*Q15 */ - } - ELSE - { - Ep_avrgL_fx = L_add(Ep_avrgL_fx,L_shr(Ep_tmp_fx[i],1));/*Q12 */ - if(L_sub(Ep_tmp_fx[i],Ep_peak_fx) > 0) - { - Ep_peak_fx = L_add(Ep_tmp_fx[i], 0); /*Q13 */ - } - } - } - L_tmp = Mult_32_16(Ep_peak_fx,28262);/*Q(13+14-15 = 12) 1.725 lowband = 3; */ - L_tmp2 =Mult_32_16(Ep_avrgL_fx,24576);/*Q(12+14-15 = 11) */ - test(); - test(); - IF( L_sub(L_shr(Ep_avrg_fx,2), L_tmp2) > 0 && L_sub(L_shr(Ep_avrg_fx,4), L_tmp2) < 0 && L_sub(L_tmp, Ep_avrgL_fx)>0) - { - adjustFlag = 1; - move16(); - FOR (i = 0; i < lowband; i++) - { - tmp = Calc_inv(Ep_avrgL_fx, &exp); - L_tmp = Mult_32_16(Ep_peak_fx,tmp);/*Q(13+exp-15+4 = exp+2) */ - L_tmp = Mult_32_16(L_tmp,lowband);/*Q(exp+2+0-15 = exp-13) */ - L_tmp = Mult_32_16(L_tmp,18842);/*Q(exp-13+16-16 = exp-13) */ - L_tmp = L_shl(L_tmp,sub(27,exp));/*Q14 0.5 */ - tmp2=extract_l(L_min(L_tmp,19661));/*14 */ - L_tmp = Mult_32_16(L_band_energy_tmp[i],tmp2);/*Q(Q_band_energy+14-15 = Q_band_energy-1) */ - L_band_energy_tmp[i] = L_shl(L_tmp,1); /*Q_band_energy */ move32(); - } - } - hq2_bit_alloc_fx( - L_band_energy_tmp, bands_fx, L_Rk, &bit_budget_fx, p2a_flags_fx, bit_alloc_weight_fx, band_width, - num_bits, hqswb_clas_fx, st_fx->bwidth_fx, *is_transient_fx ); - } - ELSE IF( *is_transient_fx == 0 && sub(inner_frame, L_FRAME16k) == 0 ) - { - bit_budget_fx = sub(bit_budget_fx,2);/* bits in high bands to indicate the last 2 subbands is allocated bits or not */ - - FOR(i = 0; i < 2; i++) - { - last_bitalloc_max_band[i] = get_next_indice_fx( st_fx, 1 ); - move16(); - } - FOR( i = 0; i < bands_fx; i++ ) - { - Ep_tmp_fx[i] = L_shl(Ep_tmp_fx[i],2); - move32(); - } - IF( L_sub( st_fx->core_brate_fx, ACELP_13k20 ) == 0) - { - lowband = 8; - move16(); - highband = 15; - move16(); - bw_low = sub(band_start[highband],band_start[lowband]); - bw_high = sub(add(band_end[sub(bands_fx,1)],1),band_start[highband]); - } - ELSE - { - lowband = 8; - move16(); - highband = 16; - move16(); - bw_low = sub(band_start[highband],band_start[lowband]); - bw_high = sub(add(band_end[sub(bands_fx,1)],1),band_start[highband]); - } - /* calculate the the low band/high band energy and the variance/avrage of the envelopes */ - enerL_fx = L_deposit_l(0); - enerH_fx = L_deposit_l(0); - Ep_vari_fx = L_deposit_l(0); - Ep_avrg_fx = L_deposit_l(0); - FOR( i = 0; i < bands_fx; i++ ) - { - test(); - IF( sub(i,lowband) >= 0 && add(sub(i,bands_fx),p2a_bands_fx) < 0) - { - Ep_vari_fx = L_add(Ep_vari_fx,L_abs(L_sub(Ep_tmp_fx[i],Ep_tmp_fx[sub(i,1)])));/*Q15 */ - Ep_avrg_fx = L_add(Ep_avrg_fx,Ep_tmp_fx[i]);/*Q15 */ - } - - IF(sub(i,highband) >= 0) - { - enerH_fx = L_add(enerH_fx,L_shl(Ep_fx[i],2));/*Q0 */ - } - ELSE IF(sub(i,lowband) >= 0) - { - enerL_fx = L_add(enerL_fx,L_shl(Ep_fx[i],2));/*Q0 */ - } - } - - /* modify the last p2a_bands subbands band_energies */ - Copy32( L_band_energy,L_band_energy_tmp,bands_fx ); /*Q_band_energy */ - L_tmp = L_max(enerH_fx,enerL_fx); - tmp = s_max(bw_low,bw_high); - i = norm_l(L_tmp); - j = norm_s(tmp); - L_tmp = Mult_32_16(L_shl(enerH_fx,i), shl(bw_low,j)); /* i + j -15 */ - L_tmp2 = Mult_32_16(L_shl(enerL_fx,i), shl(bw_high,j)); /*i + j -15 */ - L_tmp2 = L_sub(L_tmp,L_tmp2); - FOR( i = sub(bands_fx,p2a_bands_fx); i < bands_fx; i++ ) - { - test(); - IF( sub(p2a_flags_fx[i],1) == 0 || L_tmp2 > 0 ) - { - tmp = sub(bands_fx,p2a_bands_fx); - tmp = sub(tmp,lowband);/*Q0 */ - - tmp1 = extract_h(L_shl(Ep_avrg_fx,1));/*Q0 */ - IF(tmp1 != 0) - { - exp = norm_s(tmp1); - tmp1 = shl(tmp1,exp);/*Q(exp) */ - tmp1 = div_s(16384,tmp1);/*Q(15+14-exp = 29-exp) */ - exp = sub(29,exp); - } - ELSE - { - /*when the divisor is zero, happens rarely*/ - tmp1 = 0x7fff; - move16(); - exp = 0; - move16(); - } - L_tmp = Mult_32_16(Ep_tmp_fx[i],tmp1);/*Q(15+exp-15 = exp) */ - L_tmp = Mult_32_16(L_tmp,tmp);/*Q(exp+0-15 = exp-15) */ - L_tmp = Mult_32_16(L_tmp,16384);/*Q(exp-15+13-15 = exp-17) */ - L_tmp = L_shl(L_tmp,sub(32,exp));/*Q15 */ - tmp = extract_l(L_min(L_tmp,6554));/*Q15 */ - L_tmp = Mult_32_16(Ep_vari_fx,tmp1);/*Q(15+exp-15 = exp) */ - L_tmp = Mult_32_16(L_tmp,tmp);/*Q(exp+15-15 = exp) */ - L_tmp = L_shl(L_tmp,sub(15,exp));/*Q15 */ - tmp = extract_l(L_shr(L_min(L_tmp,13107),1));/*Q14 */ - - alpha_fx = add(tmp,16384);/*Q14 */ - } - ELSE - { - alpha_fx = 16384; - move16();/*Q14 */ - } - - IF(add(sub(i,bands_fx),p2a_bands_fx) > 0) - { - tmp = sub(bands_fx, p2a_bands_fx); - IF(sub(last_bitalloc_max_band[sub(i, add(tmp, 1))], 1) == 0) - { - tmp = sub(tmp,lowband); - L_tmp = Mult_32_16(Ep_tmp_fx[i],tmp);/*Q(15+0-15 = 0) */ - tmp = Calc_inv(L_shl(L_tmp,16), &exp); - L_tmp = Mult_32_16(Ep_avrg_fx,tmp);/*Q(15+exp-15 = exp) */ - L_tmp = L_shl(L_tmp,sub(14,exp));/*Q14 */ - tmp = extract_l(L_min(L_max(L_tmp,16384),20480));/*Q14 */ - L_tmp = L_mult(alpha_fx,tmp);/*Q(14+14+1=29) */ - alpha_fx = extract_l(L_shr(L_tmp,15)); /*Q14 */ - } - ELSE - { - tmp = sub(tmp,lowband); - - tmp1 = extract_h(L_shl(Ep_avrg_fx,1));/*Q0 */ - IF(tmp1 != 0) - { - exp = norm_s(tmp1); - tmp1 = shl(tmp1,exp);/*Q(exp) */ - tmp1 = div_s(16384,tmp1);/*Q(15+14-exp=29-exp) */ - exp = sub(29,exp); - } - ELSE - { - /*when the divisor is zero, happens rarely*/ - tmp1 = 0x7fff; - move16(); - exp = 0; - move16(); - } - L_tmp = Mult_32_16(Ep_tmp_fx[i],tmp1);/*Q(15+exp-15 = exp) */ - L_tmp = Mult_32_16(L_tmp,tmp);/*Q(exp+0-15 = exp-15) */ - L_tmp = L_shl(L_tmp,sub(29,exp));/*Q14 */ - tmp = extract_l(L_min(L_max(L_tmp,13926),16384));/*Q14 */ - L_tmp = L_mult(alpha_fx,tmp);/*Q(14+14+1=29) */ - alpha_fx = extract_l(L_shr(L_tmp,15)); /*Q14 */ - } - } - L_tmp = Mult_32_16(L_band_energy_tmp[i],alpha_fx);/*Q(Q_band_energy+14-15=Q_band_energy-1) */ - L_band_energy_tmp[i] = L_shl(L_tmp,1);/*Q Q_band_energy */ - } - lowband = 6; - move16(); - Ep_avrg_fx = L_deposit_l(0); - Ep_avrgL_fx = L_deposit_l(0); - Ep_peak_fx = L_deposit_l(0); - FOR(i = 0; i < bands_fx; i++) - { - IF(sub(i,lowband) >= 0) - { - Ep_avrg_fx = L_add(Ep_avrg_fx,Ep_tmp_fx[i]);/*Q15 */ - } - ELSE - { - Ep_avrgL_fx = L_add(Ep_avrgL_fx,Ep_tmp_fx[i]);/*Q15 */ - if(L_sub(Ep_tmp_fx[i],Ep_peak_fx) > 0) - { - Ep_peak_fx = L_add(Ep_tmp_fx[i], 0); /*Q15 */ - } - } - } - - - L_tmp = Mult_32_16(Ep_peak_fx,24576);/*Q(15+13-15 = 13) lowband = 6; */ - L_tmp2 =Mult_32_16(Ep_peak_fx,19661);/*Q(15+14-15 = 14) */ - L_tmp3 =Mult_32_16(Ep_avrgL_fx,24576);/*Q(15+12-15 = 12) */ - - test(); - test(); - test(); - test(); - test(); - IF( (L_sub(L_shr(Ep_avrgL_fx,1), Ep_avrg_fx)>0 && L_sub(L_tmp,L_shr(Ep_avrgL_fx,2)) > 0 && L_sub(L_shr(Ep_avrgL_fx,1),L_tmp2) < 0 ) || - (L_sub(L_shr(Ep_avrg_fx,1), Ep_avrgL_fx)>0 && L_sub(L_shr(Ep_avrg_fx,3),L_tmp3) < 0 && L_sub(L_tmp,L_shr(Ep_avrgL_fx,2)) > 0 ) ) - { - adjustFlag = 1; - move16(); - FOR (i = 0; i < lowband; i++) - { - tmp = Calc_inv(L_shl(Ep_avrgL_fx,1), &exp); - L_tmp = Mult_32_16(Ep_peak_fx,tmp);/*Q(15+exp-15 = exp) */ - L_tmp = Mult_32_16(L_tmp,lowband);/*Q(exp+0-15 = exp-15) */ - L_tmp = L_shl(L_tmp,sub(28,exp));/*Q14 0.5 */ - tmp = extract_l(L_min(L_tmp,19661));/*//Q14 */ - L_tmp = Mult_32_16(L_band_energy_tmp[i],tmp);/*Q(Q_band_energy+14-15 = Q_band_energy-1) */ - L_band_energy_tmp[i] = L_shl(L_tmp,1); /*Q_band_energy */ move32(); - } - } - - hq2_bit_alloc_fx( - L_band_energy_tmp, bands_fx, L_Rk, &bit_budget_fx, p2a_flags_fx, bit_alloc_weight_fx, band_width, - num_bits, hqswb_clas_fx, st_fx->bwidth_fx, *is_transient_fx ); - } - ELSE IF( sub(st_fx->bwidth_fx, SWB) == 0 && sub(hqswb_clas_fx, HQ_HARMONIC) == 0 && (L_sub(L_bwe_br, HQ_16k40) == 0 || L_sub(L_bwe_br, HQ_13k20) == 0) ) - { - hq2_bit_alloc_har_fx( L_band_energy, bit_budget_fx, bands_fx, L_Rk, p2a_bands_fx, L_bwe_br, p2a_flags_fx, band_width ); - } - ELSE - { - hq2_bit_alloc_fx( - L_band_energy, bands_fx, L_Rk, &bit_budget_fx, p2a_flags_fx, bit_alloc_weight_fx, band_width, - num_bits, hqswb_clas_fx, st_fx->bwidth_fx, *is_transient_fx ); - } - - IF( bit_budget_fx < 0 ) - { - st_fx->BER_detect = 1; - move16(); - bit_budget_fx = 0; - move16(); - } - tcq_core_LR_dec_fx( st_fx, /*inp_vector*/inp_vector_fx, bit_budget_fx, bands_fx, band_start, band_width, /*Rk, */L_Rk, npulses_fx, k_sort_fx, - p2a_flags_fx, p2a_bands_fx, last_bitalloc_max_band, inner_frame, adjustFlag, is_transient_fx ); - - /* Denormalize the coded MDCT spectrum */ - mdct_spectrum_denorm_fx( inp_vector_fx, L_y2, band_start, band_end, band_width, L_band_energy, npulses_fx, bands_fx, ld_slope_fx, pd_thresh_fx ); - - /* Apply fine gain to denormalized coded spectrum */ - mdct_spectrum_fine_gain_dec_fx( st_fx, L_y2, band_start, band_end, k_sort_fx, bands_fx, - L_qint, Ngq_fx, gqlevs_fx, gqbits_fx ); - - test(); - test(); - test(); - /* Restore the band information */ - IF( sub(flag_spt_fx, 1) == 0 ) - { - spt_shorten_domain_band_restore_fx(bands_fx, band_start, band_end, band_width, org_band_start, org_band_end, org_band_width); - } - - Copy32( L_y2, L_y2_org, L_FRAME32k ); - - /* Inject noise into components having relatively low pulse energy per band */ - ni_seed_fx = add(add(add(npulses_fx[0], npulses_fx[1]), npulses_fx[2]), npulses_fx[3]); - Copy32( L_y2, L_y2_ni, band_end[bands_fx-1]+1 ); - - hq2_noise_inject_fx( L_y2_ni, band_start, band_end, band_width, Ep_fx, L_Rk, npulses_fx, ni_seed_fx, bands_fx, 0, bw_low, bw_high, enerL_fx, enerH_fx, - st_fx->last_ni_gain_fx, st_fx->last_env_fx, &st_fx->last_max_pos_pulse_fx, p2a_flags_fx, p2a_bands_fx, - hqswb_clas_fx, st_fx->bwidth_fx, L_bwe_br ); - - test(); - test(); - IF( sub(st_fx->bwidth_fx, SWB) == 0 && (L_sub(L_bwe_br, HQ_16k40) == 0 || L_sub(L_bwe_br, HQ_13k20) == 0 ) ) - { - test(); - IF( sub(hqswb_clas_fx, HQ_NORMAL) == 0 || sub(hqswb_clas_fx, HQ_HARMONIC) == 0) - { - preset_hq2_swb_fx( hqswb_clas_fx, band_end, &har_bands_fx, p2a_bands_fx,length_fx, bands_fx, &lowlength_fx, &highlength_fx, L_m ); - - swb_bwe_dec_lr_fx( - st_fx, - L_y2, SWB_BWE_LR_Qs, L_m, - L_bwe_br, - bands_fx, band_start, band_end, - L_band_energy, SWB_BWE_LR_Qbe, - p2a_flags_fx, hqswb_clas_fx, lowlength_fx, highlength_fx, har_bands_fx, - &st_fx->prev_frm_hfe2_fx, &st_fx->prev_stab_hfe2_fx - , band_width, L_y2_ni, &ni_seed_fx - ); - - post_hq2_swb_fx( L_m, lowlength_fx, highlength_fx, hqswb_clas_fx, har_bands_fx, bands_fx, p2a_flags_fx, band_start, band_end, L_y2, npulses_fx ); - - IF( sub(hqswb_clas_fx, HQ_NORMAL) == 0 ) - { - spt_swb_peakpos_tmp_save_fx(L_y2, bands_fx, band_start, band_end, prev_SWB_peak_pos_tmp_fx); - FOR( k=0; klast_inner_frame_fx, L_FRAME16k) >= 0 && st_fx->bws_cnt_fx > 0 )) - { - k1_fx = sub(bands_fx,2); - if(sub(*is_transient_fx,1) != 0) - { - k1_fx = sub(bands_fx,6); - } - L_tmp = L_deposit_l(0); - FOR(i = k1_fx; i < bands_fx; i++) - { - tmp = div_s(1,sub(bands_fx,k1_fx));/*Q15 */ - L_tmp = L_add(L_tmp,Mult_32_16(Ep_tmp_fx[i],tmp));/*Q15 */ - } - st_fx->prev_ener_shb_fx = extract_l(L_shr(L_tmp, 14)); - } - IF( sub(st_fx->last_inner_frame_fx,L_FRAME32k) >= 0 ) - { - set16_fx(st_fx->prev_SWB_fenv_fx, st_fx->prev_ener_shb_fx ,SWB_FENV); - } - - updat_prev_frm_fx( L_y2, L_yout, L_bwe_br, length_fx, inner_frame, bands_fx, st_fx->bwidth_fx, *is_transient_fx, hqswb_clas_fx, &st_fx->prev_hqswb_clas_fx, - st_fx->prev_SWB_peak_pos_fx, prev_SWB_peak_pos_tmp_fx, &st_fx->prev_frm_hfe2_fx, &st_fx->prev_stab_hfe2_fx, st_fx->bws_cnt_fx ); - - return; -} - -/*------------------------------------------------------------------------------------ - * small_symbol_dec_tran_fx() - * - * Huffman decoding of differential energies - *--------------------------------------------------------------------------------------*/ - -static Word16 small_symbol_dec_tran_fx( - Decoder_State_fx *st_fx, /* i/o: decoder state structure */ - Word16 *qbidx, /* o : output of dequantized differential energy */ - const Word16 bands, /* i : number of bands */ - const Word16 is_transient /* i : transient flag */ -) -{ - Word16 i, bits; - Word16 difidx[BANDS_MAX]; - - /* Decoding differential energies*/ - bits = decode_envelope_indices_fx(st_fx, 0, bands, 0, difidx, LOW_RATE_HQ_CORE_TRAN ,is_transient); - bits = add(bits, BITS_DE_FCOMP); - - /* counting 1 bit for band_energy_huff_coding_mode */ - bits = add(bits, BITS_DE_HMODE); - - /* converting to original values */ - FOR( i=0; i 0 ) - { - *rbits = add(*rbits, s_and(*hufftab, 0xf)); - bit = get_next_indice_fx( st_fx, s_and(*hufftab, 0xf) ); - hufftab += add(shr(*hufftab, 4), bit); - } - - return negate(*hufftab); -} - -static Word16 large_symbol_dec_fx( /* o : bits */ - Decoder_State_fx *st_fx, /* i/o: decoder state structure */ - Word16 *qbidx, /* o : output of dequantized differential energy */ - const Word16 bands /* i : number of bands */ -) -{ - Word16 i, bits; - Word16 LSB[BANDS_MAX]; - Word16 basic_shift,cntbits,ns2mode; - Word16 pos_outlyer; - Word16 ns2mode0,ns2mode1; - - cntbits = BITS_DE_8SMODE; - move16(); - ns2mode = get_next_indice_fx (st_fx, BITS_DE_8SMODE); - - IF ( ns2mode == 0 ) - { - ns2mode0 = get_next_indice_fx (st_fx, BITS_DE_8SMODE_N0); - ns2mode1 = get_next_indice_fx (st_fx, BITS_DE_8SMODE_N1); - cntbits = add(cntbits, BITS_DE_8SMODE_N0+BITS_DE_8SMODE_N1); - - IF ( ns2mode0 == 0 ) - { - IF ( sub(ns2mode1, 1) == 0 ) - { - pos_outlyer = get_next_indice_fx (st_fx, BITS_DE_8SPOS); - cntbits = add(cntbits, BITS_DE_8SPOS); - qbidx[pos_outlyer] = sub(get_next_indice_fx (st_fx, BITS_ABS_ENG), ABS_ENG_OFFSET); - move16(); - cntbits = add(cntbits, BITS_ABS_ENG); - } - ELSE - { - pos_outlyer = -1; - move16(); - } - - FOR( i=0; i Qbe(Q14) */ - } - - IF (is_transient_fx) - { - reverse_transient_frame_energies_fx( L_band_energy, bands_fx ); - } - - return( deng_bits ); -} - - -/*--------------------------------------------------------------------------* - * p2a_threshold_dequant() - * - * - *--------------------------------------------------------------------------*/ - -static Word16 p2a_threshold_dequant_fx( - Decoder_State_fx *st_fx, /* i/o: decoder state structure */ - Word16 *p2a_flags, /* o : tonaly indicator */ - const Word16 bands, /* i : number of subbands */ - const Word16 p2a_bands /* i : number of subbnads for computing tonality */ -) -{ - Word16 j, k; - - j = sub(bands, p2a_bands); - FOR( k = 0; k < j; k++ ) - { - p2a_flags[k] = 1; - move16(); - } - - j = 0; - move16(); - FOR( k = sub(bands, p2a_bands); k < bands; k++ ) - { - p2a_flags[k] = get_next_indice_fx( st_fx, 1 ); - move16(); - j = add(j, 1); - } - - return( j ); -} - - -/*--------------------------------------------------------------------------* - * mdct_spectrum_fine_gain_dec() - * - * - *--------------------------------------------------------------------------*/ - -static void mdct_spectrum_fine_gain_dec_fx( - Decoder_State_fx *st_fx, /* i/o: decoder state structure */ - Word32 L_y2[], /* i/o: Q12 : decoded spectrum */ - const Word16 band_start[], /* i : Q0 : table of start freq for every subband */ - const Word16 band_end[], /* i : Q0 : table of end freq for every subband */ - const Word16 k_sort[], /* i : Q0 : sort table by band_energy */ - const Word16 bands, /* i : Q0 : nubmber of subbands */ - const Word32 L_qint, /* i : Q0 : */ - const Word16 Ngq, /* i : Q0 : */ - const Word16 gqlevs, /* i : Q0 : quantized level */ - const Word16 gqbits /* i : Q0 : quantized bits */ -) -{ - Word16 i, k, imin_fx; - - Word16 delta_fx, Qdelta; - Word32 L_delta; - Word32 L_q; - - Word16 gain_table_fx[MAX_GQLEVS]; - Word16 Qgt; - Word16 gamma_fx; /* Q14 */ - - Word16 exp_normn, exp_normd; - - Word32 L_temp; - Word16 temp_lo_fx, temp_hi_fx; - - /* Fine gain quantization on only the most significant energy bands */ - - exp_normn = norm_l(L_qint); - exp_normn = sub(exp_normn, 1); - exp_normd = norm_s(gqlevs); - delta_fx = div_l(L_shl(L_qint, exp_normn), shl(gqlevs, exp_normd)); - Qdelta = add(sub(exp_normn, exp_normd), 28); /* 29+exp_normn-(exp_normd)-1; */ - L_delta = L_shl(L_deposit_h(delta_fx), sub(13, Qdelta)); - - L_q = L_shr(L_sub(L_delta, L_qint), 1); - - FOR ( i=0; i Q14 */ move16(); - } - - FOR( k = sub(bands, Ngq); k < bands; k++ ) - { - imin_fx = get_next_indice_fx( st_fx, gqbits ); - - /*gamma = gain_table[imin]; */ - gamma_fx = gain_table_fx[imin_fx]; - move16(); - - FOR (i = band_start[k_sort[k]]; i <= band_end[k_sort[k]]; i++) - { - /* This IF statement for keeping same mantissa evenif y2 is plus or minus */ - IF ( L_y2[i] >= 0x0 ) - { - L_y2[i] = L_shl(Mpy_32_16_1(L_y2[i], gamma_fx), 1); - } - ELSE - { - L_y2[i] = L_negate(L_shl(Mpy_32_16_1(L_abs(L_y2[i]), gamma_fx), 1)); - } - } - } - - return; -} diff --git a/src/libs/libevs/lib_dec/igf_dec.cpp b/src/libs/libevs/lib_dec/igf_dec.cpp old mode 100755 new mode 100644 index 708ad33a..b64ff247 --- a/src/libs/libevs/lib_dec/igf_dec.cpp +++ b/src/libs/libevs/lib_dec/igf_dec.cpp @@ -1,120 +1,48 @@ /*==================================================================================== - EVS Codec 3GPP TS26.442 Apr 03, 2018. Version 12.11.0 / 13.6.0 / 14.2.0 + EVS Codec 3GPP TS26.443 Nov 13, 2018. Version 12.11.0 / 13.7.0 / 14.3.0 / 15.1.0 ====================================================================================*/ #include #include #include #include +#include +#include #include "options.h" -#include "stl.h" -#include "prot_fx.h" -#include "cnst_fx.h" -#include "stat_dec_fx.h" -#include "basop_util.h" - -/**********************************************************************/ /* -get scalefactor of an Word32 array with condition -**************************************************************************/ -static Word16 IGF_getScaleFactor32Cond( /**< out: Q0 | measured headroom in range [0..31], 0 if all x[i] == 0 */ - const Word16 *cond, /**< in: Q0 | array conating the condition */ - const Word32 *x, /**< in: Q31 | array containing 32-bit data */ - const Word16 len_x /**< in: Q0 | length of the array to scan */ -) -{ - Word16 i; - Word16 i_min; - Word16 i_max; - Word32 x_min; - Word32 x_max; - Word32 tmp32; - - - x_max = L_add(0, 0); - x_min = L_add(0, 0); - - FOR (i = 0; i < len_x; i++) - { - tmp32 = L_add(x[i], 0); /*L_and(x[i], cond[i]);*/ - - if (cond[i] == 0) - { - tmp32 = L_deposit_h(0); - } - - - if (tmp32>= 0) - { - x_max = L_max(x_max, tmp32); - } - if (tmp32< 0) - { - x_min = L_min(x_min, tmp32); - } - } - - i_max = 0x20; - move16(); - i_min = 0x20; - move16(); - - if (x_max != 0) - { - i_max = norm_l(x_max); - } - if (x_min != 0) - { - i_min = norm_l(x_min); - } - - i = s_and(s_min(i_max, i_min), 0x1F); - - return i; -} +#include "prot.h" +#include "cnst.h" +#include "stat_dec.h" /**********************************************************************/ /* measures TCX noise **************************************************************************/ -static Word16 IGF_replaceTCXNoise_1( /**< out: Q0 | number of noise bands */ - const Word32 *in, /**< in: Q31 | MDCT spectrum */ - Word16 s_l, /**< in: Q0 | noise headroom */ - const Word16 *TCXNoise, /**< in: | tcx noise indicator vector */ - const Word16 start, /**< in: Q0 | start MDCT subband index */ - const Word16 stop, /**< in: Q0 | stop MDCT subband index */ - Word32 *totalNoiseNrg /**< out: | measured noise energy */ +static int IGF_replaceTCXNoise_1( /**< out: | number of noise bands */ + const float *in, /**< in: | MDCT spectrum */ + const unsigned char *TCXNoise, /**< in: | tcx noise indicator vector */ + const int start, /**< in: | start MDCT subband index */ + const int stop, /**< in: | stop MDCT subband index */ + float *totalNoiseNrg /**< out: | measured noise energy */ ) { - Word16 sb; - Word16 tmp16; - Word16 noise; - Word32 nE; + int sb; + int noise; + float nE; + float val; - - tmp16 = 0; - move16(); noise = 0; - move16(); - s_l = sub(s_l, 5); - nE = L_add(0, 0); + nE = FLT_MIN; - FOR (sb = start; sb < stop; sb++) + for (sb = start; sb < stop; sb++) { if (TCXNoise[sb]) { - tmp16 = extract_h(L_shl(in[sb], s_l)); - } - if (TCXNoise[sb]) - { - nE = L_mac(nE, tmp16, tmp16); - } - if (TCXNoise[sb]) - { - noise = add(noise, 1); + val = in[sb]; + nE += val * val; + noise++; } } *totalNoiseNrg = nE; - move32(); return noise; } @@ -122,1126 +50,528 @@ static Word16 IGF_replaceTCXNoise_1( /**********************************************************************/ /* replaces TCX noise **************************************************************************/ -static void IGF_replaceTCXNoise_2(Word32 *in, /**< in/out: | MDCT spectrum */ - const Word16 *TCXNoise, /**< in: Q0 | tcx noise indicator vector */ - const Word16 start, /**< in: Q0 | start MDCT subband index */ - const Word16 stop, /**< in: Q0 | stop MDCT subband index */ - Word32 totalNoiseNrg, /**< in: | measured noise energy */ - const Word16 s_l, /**< in: Q0 | noise headroom */ - Word16 *nfSeed /**< in: | random generator noise seed */ +static void IGF_replaceTCXNoise_2(float *in, /**< in/out: | MDCT spectrum */ + const unsigned char *TCXNoise, /**< in: | tcx noise indicator vector */ + const int start, /**< in: | start MDCT subband index */ + const int stop, /**< in: | stop MDCT subband index */ + float totalNoiseNrg, /**< in: | measured noise energy */ + short *nfSeed /**< in: | random generator noise seed */ ) { - Word16 sb; - Word16 g; - Word16 val; - Word32 rE; - Word32 L_tmp; + int sb; + float rE; + float g; + float val; - - val = 0; - move16(); - rE = L_add(0, 0); - - FOR (sb = start; sb < stop; sb++) + rE = FLT_MIN; + for (sb = start; sb < stop; sb ++) { if (TCXNoise[sb]) { - val = Random(nfSeed); - } - if (TCXNoise[sb]) - { - in[sb] = L_deposit_l(val); - } - if (TCXNoise[sb]) - { - val = shr(val, 5); - } - if (TCXNoise[sb]) - { - rE = L_mac(rE, val, val); + val = (float)own_random(nfSeed); + in[sb] = val; + rE += val * val; } } - totalNoiseNrg = L_shr(totalNoiseNrg, 1); + g = (float)sqrt(totalNoiseNrg/rE); - - /* make sure that rE is never 0 */ - if (rE == 0) - { - rE = L_add(totalNoiseNrg, 0); /* save move32() -> use L_add(x, 0) = x; */ - } - - /* if totalNoiseNrg == 0, then rE must be at least 0x00010000, otherwise division by 0 will occur */ - if (totalNoiseNrg == 0) - { - rE = L_max(rE, 0x00010000); - } - - /* make sure that rE is never smaller than totalNoiseNrg */ - L_tmp = L_sub(rE, totalNoiseNrg); - if (L_tmp < 0) - { - rE = L_add(totalNoiseNrg, 0); /* save move32() -> use L_add(x, 0) = x; */ - } - - - g = getSqrtWord32(L_mult(divide3232(totalNoiseNrg, rE), 8192/*1.0f / 4.0f Q15*/)); - g = shl(g, 1); - - FOR (sb = start; sb < stop; sb++) + for (sb = start; sb < stop; sb ++) { if (TCXNoise[sb]) { - in[sb] = L_shr(L_mult(extract_l(in[sb]), g), s_l); - move32(); + in[sb] *= g; } } - } /**********************************************************************/ /* reads whitening levels **************************************************************************/ -static void IGF_decode_whitening_level(Decoder_State_fx *st, /**< in: | decoder state */ +static void IGF_decode_whitening_level(Decoder_State *st, /**< in: | decoder state */ IGF_DEC_PRIVATE_DATA_HANDLE hPrivateData, /**< in: | instance handle of IGF Deccoder */ - const Word16 p /**< in: Q0 | tile index, p = [0, 3] */ + const int p /**< in: | tile index, p = [0, 3] */ ) { - Word16 tmp; + int tmp; + tmp = get_next_indice(st, 1); - tmp = get_next_indice_fx(st, 1); - - IF (tmp == 0) + if (tmp == 1) { - hPrivateData->currWhiteningLevel[p] = IGF_WHITENING_MID; - move16(); - - return; + tmp = get_next_indice(st, 1); + if (tmp == 1) + { + hPrivateData->currWhiteningLevel[p] = IGF_WHITENING_STRONG; + } + else + { + hPrivateData->currWhiteningLevel[p] = IGF_WHITENING_OFF; + } } - - tmp = get_next_indice_fx(st, 1); - hPrivateData->currWhiteningLevel[p] = IGF_WHITENING_STRONG; - move16(); - - if (tmp == 0) + else { - hPrivateData->currWhiteningLevel[p] = IGF_WHITENING_OFF; - move16(); + hPrivateData->currWhiteningLevel[p] = IGF_WHITENING_MID; } - } /**********************************************************************/ /* reads flattening trigger **************************************************************************/ -static void IGF_decode_temp_flattening_trigger(Decoder_State_fx *st, /**< in: | decoder state */ +static void IGF_decode_temp_flattening_trigger(Decoder_State *st, /**< in: | decoder state */ IGF_DEC_INSTANCE_HANDLE hInstance /**< in: | instance handle of IGF Deccoder */ ) { - hInstance->flatteningTrigger = get_next_indice_fx(st, 1); + hInstance->flatteningTrigger = get_next_indice(st, 1); +} + +/**********************************************************************/ /* +square the MDCT spectrum +**************************************************************************/ +static void IGF_getMDCTSquare(const int startLine, /**< in: | start MDCT subband index */ + const int stopLine, /**< in: | stop MDCT subband index */ + const float *pSpectralData, /**< in: | MDCT spectrum */ + float *pSpecDataSqaure /**< out: | Squared MDCT spectrum */ + ) +{ + int i; + + for (i = startLine; i < stopLine; i++) + { + pSpecDataSqaure[i] = pSpectralData[i] * pSpectralData[i]; + } +} + +/**********************************************************************/ /* +calculate energy per SFB +**************************************************************************/ +static void IGF_calcSfbEnergy(const int startSfb, /**< in: | start sfb index */ + const int stopSfb, /**< in: | stop sfb index */ + const int *swb_offset, /**< in: | IGF swb offset table */ + const float *pPowerSpectrum, /**< in: | power spectrum */ + float *sfbEnergy /**< out: | SFB energies, will be initialized inside this function */ + ) +{ + int sfb; + int line; + + for (sfb = startSfb; sfb < stopSfb; sfb++) + { + sfbEnergy[sfb] = 0.f; + + for (line = swb_offset[sfb]; line < swb_offset[sfb + 1]; line++) + { + sfbEnergy[sfb] += pPowerSpectrum[line]; + } + } } /**********************************************************************/ /* set power spectrum values to zero, needed for energy calculation **************************************************************************/ -static void IGF_setLinesToZero(const Word16 startLine, /**< in: Q0 | start MDCT subband index */ - const Word16 stopLine, /**< in: Q0 | stop MDCT subband index */ - const Word32 *pSpectralData, /**< in: | original MDCT spectrum */ - Word32 *pPowerSpecIGF /**< in/out: | prepared IGF energy spectrum */ +static void IGF_setLinesToZero(const int startLine, /**< in: | start MDCT subband index */ + const int stopLine, /**< in: | stop MDCT subband index */ + const float *pSpectralData, /**< in: | original MDCT spectrum */ + float *squareSpecIGF /**< in/out: | prepared IGF energy spectrum */ ) { - Word16 i; + int i; - - /* set energy values in the IGF "power spectrum" to 0, - if there is content in the original MDCT spectrum */ - FOR (i = startLine; i < stopLine; i++) + for (i = startLine; i < stopLine; i++) { - if (pSpectralData[i] != 0) + if (pSpectralData[i] != 0.f) { - pPowerSpecIGF[i] = L_deposit_l(0); + squareSpecIGF[i] = 0.f; } } - } /**********************************************************************/ /* prepare IGF spectrum **************************************************************************/ static void IGF_prep(IGF_DEC_PRIVATE_DATA_HANDLE hPrivateData, /**< in: | IGF private data handle */ - const Word16 igfGridIdx, /**< in: Q0 | in case of CELP->TCX switching, use 1.25 framelength */ - const Word16 *TCXNoise, /**< in: Q0 | TCX noise vector */ - Word32 *igf_spec, /**< in: Q31 | prepared IGF spectrum */ - Word16 *igf_spec_e, /**< in: | array exponents of igf_spec, one exponent per tile */ - const Word32 *src_spec, /**< in: | source spectrum */ - const Word16 src_spec_e, /**< in: | exponent of src_spec, whitening off */ - const Word16 specMed_e /**< in: | exponent of medium flattening level */ + const int igfGridIdx, /**< in: | in case of CELP->TCX switching, use 1.25 framelength */ + const unsigned char *TCXNoise, /**< in: | TCX noise vector */ + float *igf_spec, /**< in: | prepared IGF spectrum */ + float *src_spec /**< in: | source spectrum */ ) { H_IGF_GRID hGrid; H_IGF_INFO hInfo; - Word16 i; - Word16 tb; - Word16 sfb; - Word16 nTiles; - Word16 n_noise_bands; - Word16 n_noise_bands_off; - Word16 strt_cpy; - Word16 startLine; - Word16 minSrcSubband; - Word16 tile_idx; - Word32 totalNoiseNrg; - Word32 totalNoiseNrg_off; - const Word32 *sel_spec; + int i; + int tb; + int sfb; + int strt_cpy; + int tile_idx; + int *swb_offset; + float *sel_spec; + hInfo = &hPrivateData->igfInfo; + hGrid = &hPrivateData->igfInfo.grid[igfGridIdx]; + swb_offset = hGrid->swb_offset; - /* initialize variables */ - hInfo = &hPrivateData->igfInfo; - hGrid = &hPrivateData->igfInfo.grid[igfGridIdx]; - n_noise_bands = hPrivateData->n_noise_bands; - move16(); - n_noise_bands_off = hPrivateData->n_noise_bands_off; - move16(); - totalNoiseNrg = hPrivateData->totalNoiseNrg; - move32(); - totalNoiseNrg_off = hPrivateData->totalNoiseNrg_off; - move32(); - nTiles = hGrid->nTiles; - move16(); - startLine = hGrid->startLine; - move16(); - minSrcSubband = hGrid->minSrcSubband; - move16(); - tile_idx = 0; - move16(); - - FOR (tile_idx = 0; tile_idx < nTiles; tile_idx++) + for (tile_idx = 0; tile_idx < hGrid->nTiles; tile_idx ++) { strt_cpy = hGrid->sbWrap[tile_idx]; - move16(); - /* strong whitening detected */ - IF (sub(IGF_WHITENING_STRONG, hPrivateData->currWhiteningLevel[tile_idx]) == 0) + if (IGF_WHITENING_STRONG == hPrivateData->currWhiteningLevel[tile_idx]) { - Word32 abs_sum; - abs_sum = L_add(0, 0); - - FOR(i = strt_cpy; i < hGrid->startLine; i++) + float abs_sum; + abs_sum = 0.f; + for(i = strt_cpy; i < hGrid->startLine; i++) { - abs_sum = L_add(abs_sum, L_abs(src_spec[i])); + abs_sum += (float) fabs(src_spec[i]); } - /* fill igf_spec with random noise */ - tb = hGrid->swb_offset[hGrid->sfbWrap[tile_idx]]; - move16(); + tb = swb_offset[hGrid->sfbWrap[tile_idx]]; - IF (abs_sum != 0) + if( abs_sum > 0.f ) { - FOR (i = strt_cpy; i < startLine; i++) + for (i = strt_cpy; i < hGrid->startLine; i++) { - igf_spec[tb++] = L_deposit_l(Random(&hInfo->nfSeed)); /* 31Q0, fill LSBs */ + igf_spec[tb++] = own_random(&hInfo->nfSeed); } } - ELSE + else { - FOR (i = strt_cpy; i < startLine; i++) + for (i = strt_cpy; i < hGrid->startLine; i++) { - igf_spec[tb++] = L_add(0, 0); + igf_spec[tb++] = 0.f; } } - - /* set exponent of the current tile, random noise is 31Q0 */ - igf_spec_e[tile_idx] = 31; - move16(); } - ELSE + else { - /* medium whitening detected */ - IF (sub(IGF_WHITENING_MID, hPrivateData->currWhiteningLevel[tile_idx]) == 0) + if (IGF_WHITENING_MID == hPrivateData->currWhiteningLevel[tile_idx]) { - IF (n_noise_bands != 0) + if (hPrivateData->n_noise_bands) { IGF_replaceTCXNoise_2(igf_spec, - TCXNoise, - - minSrcSubband, - startLine, - totalNoiseNrg, - hPrivateData->headroom_TCX_noise_white, - &hInfo->nfSeed); + TCXNoise, + hGrid->minSrcSubband, + hGrid->startLine, + hPrivateData->totalNoiseNrg, + &hInfo->nfSeed); } - - /* selected source spectrum is igf_spec, igf_spec contains the whitened signal in the core region */ sel_spec = igf_spec; - move16(); - - /* set exponent of the current tile */ - igf_spec_e[tile_idx] = specMed_e; - move16(); } - /* off whitening detectded */ - ELSE + else { - IF (n_noise_bands_off != 0) + if (hPrivateData->n_noise_bands_off) { - IGF_replaceTCXNoise_2(hPrivateData->pSpecFlat, - TCXNoise, - minSrcSubband, - startLine, - totalNoiseNrg_off, - hPrivateData->headroom_TCX_noise, - &hInfo->nfSeed); - + IGF_replaceTCXNoise_2(src_spec, + TCXNoise, + hGrid->minSrcSubband, + hGrid->startLine, + hPrivateData->totalNoiseNrg_off, + &hInfo->nfSeed); } - /* selected source spectrum is pSpecFlat, pSpecFlat contains the signal before the LPC reshaping */ sel_spec = src_spec; - move16(); - - /* set exponent of the current tile */ - igf_spec_e[tile_idx] = src_spec_e; - move16(); } - /* generate the raw IGF spectrum out if the selected spectrum */ - FOR (sfb = hGrid->sfbWrap[tile_idx]; sfb < hGrid->sfbWrap[tile_idx + 1]; sfb++) + for (sfb = hGrid->sfbWrap[tile_idx]; sfb < hGrid->sfbWrap[tile_idx + 1]; sfb++) { - FOR (tb = hGrid->swb_offset[sfb]; tb < hGrid->swb_offset[sfb + 1]; tb++) + for (tb = swb_offset[sfb]; tb < swb_offset[sfb + 1]; tb++) { igf_spec[tb] = sel_spec[strt_cpy]; - move32(); - strt_cpy = add(strt_cpy, 1); + strt_cpy++; } } } } - } /**********************************************************************/ /* calculates IGF energies **************************************************************************/ -static void IGF_calc(IGF_DEC_PRIVATE_DATA_HANDLE hPrivateData, /**< in: | IGF private data handle */ - const Word16 igfGridIdx, /**< in: Q0 | in case of CELP->TCX switching, use 1.25 framelength */ - const Word32 *spectrum, /**< in: Q31 | MDCT spectrum */ - const Word16 spectrum_e, /**< in: | exponent of pSpectralData */ - Word32 *igf_spec, /**< in: Q31 | prepared IGF spectrum */ - Word16 *igf_spec_e /**< in: | array exponents of igf_spec, one exponent per tile */ +static void IGF_calc(const IGF_DEC_PRIVATE_DATA_HANDLE hPrivateData, /**< in: | IGF private data handle */ + const int igfGridIdx, /**< in: | in case of CELP->TCX switching, use 1.25 framelength */ + const float *spectrum, /**< in: | MDCT spectrum */ + float *igf_spec /**< in: | prepared IGF spectrum */ ) { H_IGF_GRID hGrid; - Word16 i; - Word32 *igf_pN; /* Q31 | processed energy */ - Word16 *igf_pN_e; /* | exponents of igf_pN, one for each entry of igf_pN */ - Word32 *igf_sN; /* Q31 | survived energy */ - Word16 *igf_sN_e; /* | exponents of igf_sN, one for each entry of igf_sN */ - Word32 squaredSpectra[IGF_MAX_GRANULE_LEN]; /* Q31 | MDCT^2 spectra */ - Word16 squaredSpectra_e[IGF_MAX_TILES]; /* | exponents of squaredSpectra, one exponent per tile! */ - - - /* initialize variables */ - hGrid = &hPrivateData->igfInfo.grid[igfGridIdx]; - igf_pN = hPrivateData->igf_pN; - igf_pN_e = hPrivateData->igf_pN_e; - igf_sN = hPrivateData->igf_sN; - igf_sN_e = hPrivateData->igf_sN_e; - - set32_fx(squaredSpectra, 0, IGF_MAX_GRANULE_LEN); - set16_fx(squaredSpectra_e, 0, IGF_MAX_TILES); - - /* square the original spectrum */ - IGFCommonFuncsMDCTSquareSpec(hGrid->startLine, - hGrid->stopLine, - spectrum, - spectrum_e, - squaredSpectra, - squaredSpectra_e, - 0); - - /* calculate the energy per SFB of the survied subbands */ - IGFCommonFuncsCalcSfbEnergyPowerSpec(hGrid->startSfb, - hGrid->stopSfb, - hGrid->swb_offset, - squaredSpectra, - squaredSpectra_e, - igf_sN, - igf_sN_e); - - /* loop over tiles, every tile has his own exponent! */ - FOR (i = 0; i < hGrid->nTiles; i++) - { - /* square the prepared IGF spectrum */ - IGFCommonFuncsMDCTSquareSpec(hGrid->tile[i], - hGrid->tile[i + 1], - igf_spec, - igf_spec_e[i], - squaredSpectra, - &squaredSpectra_e[i], - 0); - - /* set all squared values to 0, if the core contains survied lines */ - IGF_setLinesToZero(hGrid->tile[i], - hGrid->tile[i + 1], - spectrum, - squaredSpectra); - - /* calculate the energy per SFB of the processed subbands */ - IGFCommonFuncsCalcSfbEnergyPowerSpec(hGrid->sfbWrap[i], - hGrid->sfbWrap[i + 1], - hGrid->swb_offset, - squaredSpectra, - &squaredSpectra_e[i], - igf_pN, - igf_pN_e); - } + float *igf_pN; + float *igf_sN; + float tmp[N_MAX_TCX] = {0.f}; + hGrid = &hPrivateData->igfInfo.grid[igfGridIdx]; + igf_pN = hPrivateData->igf_pN; + igf_sN = hPrivateData->igf_sN; + IGF_getMDCTSquare(hGrid->startLine, hGrid->stopLine, spectrum, tmp); + IGF_calcSfbEnergy(hGrid->startSfb, hGrid->stopSfb, hGrid->swb_offset, tmp, igf_sN); + IGF_getMDCTSquare(hGrid->startLine, hGrid->stopLine, igf_spec, tmp); + IGF_setLinesToZero(hGrid->startLine, hGrid->stopLine, spectrum, tmp); + IGF_calcSfbEnergy(hGrid->startSfb, hGrid->stopSfb, hGrid->swb_offset, tmp, igf_pN); } /**********************************************************************/ /* apply IGF **************************************************************************/ static void IGF_appl(IGF_DEC_PRIVATE_DATA_HANDLE hPrivateData, /**< in: | IGF private data handle */ - const Word16 igfGridIdx, /**< in: Q0 | in case of CELP->TCX switching, use 1.25 framelength */ - Word32 *spectrum, /**< in: Q31 | MDCT spectrum */ - Word16 *spectrum_e, /**< in: | exponent of pSpectralData */ - const Word32 *igf_spec, /**< in: Q31 | prepared IGF spectrum */ - const Word16 *igf_spec_e, /**< in: | array exponents of igf_spec, one exponent per tile */ - Word32 *virtualSpec, /**< out:Q31 | virtual IGF spectrum, used for temp flattening */ - Word16 *virtualSpec_e, /**< out: | exponent of virtualSpec */ - Word16 *flag_sparse /**< out: Q0 | temp flattening indicator */ + const int igfGridIdx, /**< in: | in case of CELP->TCX switching, use 1.25 framelength */ + float *pSpectralData, /**< in: Q31 | MDCT spectrum */ + const float *igf_spec, /**< in: Q31 | prepared IGF spectrum */ + float *virtualSpec, /**< out:Q31 | virtual IGF spectrum, used for temp flattening */ + int *flag_sparse /**< out: Q0 | temp flattening indicator */ ) { H_IGF_GRID hGrid; - Word16 i; - Word16 tb; - Word16 sfb; - Word16 shift; - Word16 s; - Word16 s_sfb; - Word16 start_sfb; - Word16 stop_sfb; - Word16 sfb_p1; - Word16 sfb_m1; - Word16 hopsize; - Word16 sum; - Word16 tileIdx; - Word16 width; /* Q0 | width of the current sfb */ - Word16 width_e; /* | exponent of widthent sfb, initialized as 15! */ - Word16 gFactor; /* 1Q14 | general SCF adaption */ - Word16 fFactor; /* 1Q14 | first SCF adaption */ - Word16 lFactor; /* 1Q14 | last SCF adaption */ - Word16 w0; /* Q15 | float value: 0.201f */ - Word16 w1; /* Q15 | float value: 0.389f */ - Word16 w2; /* Q15 | float value: 0.410f */ - Word16 dE; /* Q31 | energy below igfBgn */ - Word16 dE_e ; /* | exponent of dE */ - Word16 gn; /* Q0 | gain read from bitstream + processing */ - Word16 gn_e; /* | exponent of gn */ - Word16 maxGain_e; /* | maximal gain exponent over sfbs */ - Word16 tmp; - Word16 tmp_e; - Word16 tmp_loop; - Word32 L_tmp; - Word16 L_tmp_e; - Word32 L_tmp2; - Word32 sNlocal; - Word16 sNlocal_e; - Word32 dNlocal; - Word16 dNlocal_e; - Word32 E; - Word16 E_e; - Word32 *sN; - Word16 *sN_e; - Word32 *pN; - Word16 *pN_e; - Word16 gain[IGF_MAX_SFB]; - Word16 gain_e[IGF_MAX_SFB]; - Word16 dN[IGF_MAX_SFB + 1]; - Word16 dN_e[IGF_MAX_SFB + 1]; - Word16 dS[IGF_MAX_SFB]; - Word16 dS_e[IGF_MAX_SFB]; - Word32 energyTmp[24]; - Word32 L_c; - Word16 Hr; - + int tb; /* target subband */ + int sfb; + int s_sfb; + int start_sfb; + int stop_sfb; + int *swb_offset; + int hopsize; + float tmp; + float dE; + float dN[IGF_MAX_SFB+1]; + float gain[IGF_MAX_SFB]; + float dS[IGF_MAX_SFB]; + float width; + float sNlocal; + float E; + float sum; + float val; + float w0; + float w1; + float w2; + float *sN; + float *pN; + float gFactor; /* general SCF adaption */ + float fFactor; /* first SCF adaption */ + float lFactor; /* last SCF adaption */ /* initialize variables */ - w0 = 6586; - move16(); - w1 = 12747; - move16(); - w2 = 13435; - move16(); - dE = 0; - move16(); - dE_e = 0; - move16(); - tmp = 0; - move16(); - s = 0; - move16(); - tmp_e = 0; - move16(); - gn = 0; - move16(); - gn_e = 0; - move16(); - maxGain_e = 0; - move16(); - L_tmp_e = 0; - move16(); - dNlocal_e = 0; - move16(); - L_tmp = L_add(0, 0); - dNlocal = L_add(0, 0); + w0 = 0.201f; + w1 = 0.389f; + w2 = 0.410f; + dE = 0.f; + + set_i(flag_sparse, 0.f, N_MAX_TCX-IGF_START_MN); + set_f(virtualSpec, 0.f, N_MAX_TCX-IGF_START_MN); - set16_fx(gain, 0, IGF_MAX_SFB); - set16_fx(gain_e, 0, IGF_MAX_SFB); - set16_fx(dN, 0, add(IGF_MAX_SFB,1)); - set16_fx(dN_e, 0, add(IGF_MAX_SFB,1)); - set16_fx(dS, 0, IGF_MAX_SFB); - set16_fx(dS_e, 0, IGF_MAX_SFB); - set32_fx(energyTmp, 0, 24); /* more inits */ hGrid = &hPrivateData->igfInfo.grid[igfGridIdx]; sN = hPrivateData->igf_sN; - sN_e = hPrivateData->igf_sN_e; pN = hPrivateData->igf_pN; - pN_e = hPrivateData->igf_pN_e; start_sfb = hGrid->startSfb; - move16(); stop_sfb = hGrid->stopSfb; - move16(); gFactor = hGrid->gFactor; - move16(); fFactor = hGrid->fFactor; - move16(); lFactor = hGrid->lFactor; - move16(); - - /* reset virtual spec */ - set16_fx(flag_sparse, 0, N_MAX_TCX-IGF_START_MN); - set32_fx(virtualSpec, 0, N_MAX_TCX-IGF_START_MN); - *virtualSpec_e = *spectrum_e; - move16(); + swb_offset = hGrid->swb_offset; /* collect energy below hGrid->startLine: */ - tmp = sub(hGrid->startLine, 24); - IGFCommonFuncsMDCTSquareSpec(tmp, - hGrid->startLine, - spectrum, - *spectrum_e, - energyTmp, - &dE_e, - negate(tmp)); - - L_c = L_add(0, 0); - FOR (tb = 0; tb < 24; tb++) + for (tb = hGrid->startLine-24; tb < hGrid->startLine; tb++) { - Carry = 0; - L_tmp = L_add_c(L_tmp, energyTmp[tb]); - Overflow = 0; - L_c = L_macNs(L_c, 0, 0); + dE += pSpectralData[tb] * pSpectralData[tb]; } - L_tmp = norm_llQ31(L_c, L_tmp, &shift); - /* float: dE = (float)sqrt(dE / 24.f); basop: */ - shift = add(sub(shift, 4), dE_e); /* x/24 = (x >> 4) * 1/1.5 */ - dE = Sqrt16norm(extract_h(L_tmp), &shift); - dE = mult_r(dE, 26755/*0.81649658092772603273242802490196f Q15*/); /* 0.81649658092772603273242802490196f = sqrt(1/1.5)) */ - dE_e = shift; - move16(); + dE = (float)sqrt(dE/24.); - /* select correct hopsize for envelope refinement */ hopsize = 2; - move16(); - if (sub(hPrivateData->currWhiteningLevel[0], IGF_WHITENING_OFF) == 0) - { - hopsize = 4; - move16(); - } - if (sub(hPrivateData->currWhiteningLevel[0], IGF_WHITENING_STRONG) == 0) - { - hopsize = 1; - move16(); - } - hopsize = s_min(hopsize, hPrivateData->igfInfo.maxHopsize); + hopsize = (hPrivateData->currWhiteningLevel[0] == IGF_WHITENING_OFF) ? 4 : hopsize; + hopsize = (hPrivateData->currWhiteningLevel[0] == IGF_WHITENING_MID) ? 2 : hopsize; + hopsize = (hPrivateData->currWhiteningLevel[0] == IGF_WHITENING_STRONG) ? 1 : hopsize; + hopsize = min(hopsize, hPrivateData->igfInfo.maxHopsize); - IF (hopsize > 1) + if(hopsize > 1) { - FOR (sfb = start_sfb; sfb < stop_sfb; sfb += hopsize) + for (sfb = start_sfb; sfb < stop_sfb; sfb += hopsize) { - tmp_loop = s_min(add(sfb, hopsize), stop_sfb); - FOR (tb = add(sfb, 1); tb < tmp_loop; tb++) + for (tb = sfb+1; tb < min((sfb+hopsize),stop_sfb); tb++) { - sN[sfb] = BASOP_Util_Add_Mant32Exp(sN[sfb], - sN_e[sfb], - sN[tb], - sN_e[tb], - &sN_e[sfb]); - move32(); - pN[sfb] = BASOP_Util_Add_Mant32Exp(pN[sfb], - pN_e[sfb], - pN[tb], - pN_e[tb], - &pN_e[sfb]); - move32(); - sN[tb] = L_deposit_l(0); - pN[tb] = L_deposit_l(0); + sN[sfb] += sN[tb]; + pN[sfb] += pN[tb]; + sN[tb] = 0.f; + pN[tb] = 0.f; } } } /* IGF_rescale_SCF */ - IF (hGrid->infoIsRefined != 0) + if (hGrid->infoIsRefined) { - FOR (sfb = start_sfb; sfb < stop_sfb; sfb += 2) + for (sfb = start_sfb; sfb < stop_sfb; sfb+=2) { - /* calculate and normalize the width of the current sfb */ - width = sub(hGrid->swb_offset[sfb + 2], hGrid->swb_offset[sfb]); - shift = norm_s(width); - width = shl(width, shift); - width_e = sub(15, shift); /* initial value of width_e is 15, -> width = 15Q0 */ + width = (float)(swb_offset[sfb + 2] - swb_offset[sfb]); - /* float: gn = 0.25f * igf_curr - 4.f; basop: */ - gn = hPrivateData->igf_curr[shr(sfb,1)]; - move16(); - move16(); - gn_e = 13; /* set exponent of igf_curr to 13 = 15 - 2; -> igf_curr = igf_curr * 0.25, virtual division by 4 */ - gn = sub(gn, 16); /* 13Q2 | 4 = 16 * 2^(-15 + 13); ("4" has same exponent as igf_curr now) */ + tmp = (float)hPrivateData->igf_curr[sfb >> 1]; + tmp = (float)pow(2.0, 0.25 * tmp - 4.0); + tmp = tmp * tmp; - /* float: tmp = pow(2.f, gn); basop: */ - L_tmp = BASOP_util_Pow2(L_deposit_h(gn), gn_e, &L_tmp_e); + sNlocal = sN[sfb] + sN[sfb + 1]; + sNlocal /= width; - /* float: tmp = tmp * tmp; basop: */ - tmp = round_fx(L_tmp); - L_tmp = L_mult(tmp, tmp); - L_tmp_e = add(L_tmp_e, L_tmp_e); - - /* get sNlocal | float: sNlocal = sN[ sfb ] + sN[ sfb+ 1 ]; basop: */ - sNlocal = BASOP_Util_Add_Mant32Exp(sN[sfb], - sN_e[sfb], - sN[sfb + 1], - sN_e[sfb + 1], - &sNlocal_e); - - /* float: sNlocal /= width; basop: */ - shift = sub(norm_l(sNlocal), 1); /* leave MSB empty, so in the division sNlocal is always smaller than width */ - sNlocal = L_deposit_h(div_s(extract_h(L_shl(sNlocal, shift)), width)); - sNlocal_e = sub(sub(sNlocal_e, shift), width_e); - - /* float: tmp = max(0.001 * sNlocal, tmp - sNlocal); basop: */ - L_tmp = BASOP_Util_Add_Mant32Exp(L_tmp, - L_tmp_e, - L_negate(sNlocal), - sNlocal_e, - &L_tmp_e); /* float: tmp = tmp - sNlocal */ - - /* max(0.001 * sNlocal, L_tmp) */ - /* Build a threshold and compare with L_tmp. - Build negated threshold and compare with negated L_tmp to cover also fullscale L_tmp case */ - BASOP_SATURATE_WARNING_OFF - L_tmp2 = L_shl(L_negate(Mpy_32_16_1(sNlocal, 33/*0.001f Q15*/)), sub(sNlocal_e, L_tmp_e)); - L_tmp2 = L_sub(L_tmp2, L_negate(L_tmp)); - BASOP_SATURATE_WARNING_ON - - IF (L_tmp2 < 0) - { - L_tmp = Mpy_32_16_1( sNlocal,33/*0.001f Q15*/); - L_tmp_e = sNlocal_e; - move16(); - } - - /* calc square root of L_tmp and store result in dN */ - L_tmp = Sqrt32(L_tmp, &L_tmp_e); - dN[sfb] = round_fx(L_tmp); - dN_e[sfb] = L_tmp_e; - move16(); - dN[sfb+1] = dN[sfb]; - move16(); - dN_e[sfb+1] = dN_e[sfb]; - move16(); + tmp = max(0.001 * sNlocal, tmp - sNlocal); + dN[sfb] = (float)sqrt(tmp); + dN[sfb+1] = dN[sfb]; } } - ELSE + else { - FOR (sfb = start_sfb; sfb < stop_sfb; sfb++) + for (sfb = start_sfb; sfb < stop_sfb; sfb++) { - /* calculate and normalize the width of the current sfb */ - width = sub(hGrid->swb_offset[sfb + 1], hGrid->swb_offset[sfb]); - shift = norm_s(width); - width = shl(width, shift); - width_e = sub(15, shift); /* initial value of width_e is 15, -> width = 15Q0 */ + width = (float)(swb_offset[sfb + 1] - swb_offset[sfb]); - /* float: gn = 0.25f * igf_curr - 4.f; basop: */ - gn = hPrivateData->igf_curr[sfb]; - move16(); - move16(); - gn_e = 13; /* set exponent of igf_curr to 13 = 15 - 2; -> igf_curr = igf_curr * 0.25, virtual division by 4 */ - gn = sub(gn, 16); /* 13Q2 | 4 = 16 * 2^(-15 + 13); ("4" has same exponent as igf_curr now) */ + tmp = (float)hPrivateData->igf_curr[sfb]; + tmp = (float)pow(2.0, 0.25 * tmp - 4.0); + tmp = tmp * tmp; - /* float: tmp = pow(2.f, gn); basop: */ - L_tmp = BASOP_util_Pow2(L_deposit_h(gn), gn_e, &L_tmp_e); + sNlocal = sN[sfb]; + sNlocal /= width; - /* float: tmp = tmp * tmp; basop: */ - tmp = round_fx(L_tmp); - L_tmp = L_mult(tmp, tmp); - L_tmp_e = add(L_tmp_e, L_tmp_e); - - /* get sNlocal */ - sNlocal = sN[sfb]; - move32(); - sNlocal_e = sN_e[sfb]; - move16(); - - /* float: sNlocal /= width; basop: */ - shift = sub(norm_l(sNlocal), 1); /* leave MSB empty, so in the division sNlocal is always smaller than width */ - sNlocal = L_deposit_h(div_s(extract_h(L_shl(sNlocal, shift)), width)); - sNlocal_e = sub(sub(sNlocal_e, shift), width_e); - - /* float: tmp = max(0.001 * sNlocal, tmp - sNlocal); basop: */ - L_tmp = BASOP_Util_Add_Mant32Exp(L_tmp, - L_tmp_e, - L_negate(sNlocal), - sNlocal_e, - &L_tmp_e); /* float: tmp = tmp - sNlocal */ - - /* max(0.001 * sNlocal, L_tmp) */ - /* Build a threshold and compare with L_tmp. - Build negated threshold and compare with negated L_tmp to cover also fullscale L_tmp case */ - BASOP_SATURATE_WARNING_OFF - L_tmp2 = L_shl(L_negate(Mpy_32_16_1(sNlocal, 33/*0.001f Q15*/)), sub(sNlocal_e,L_tmp_e)); - L_tmp2 = L_sub(L_tmp2, L_negate(L_tmp)); - BASOP_SATURATE_WARNING_ON - - IF (L_tmp2 < 0 ) - { - L_tmp = Mpy_32_16_1(sNlocal,33/*0.001f Q15*/); - L_tmp_e = sNlocal_e; - } - - /* calc square root of L_tmp and store result in dN */ - L_tmp = Sqrt32(L_tmp, &L_tmp_e); - dN[sfb] = round_fx(L_tmp); - dN_e[sfb] = L_tmp_e; - move16(); + tmp = max(0.001 * sNlocal, tmp - sNlocal); + dN[sfb] = (float)sqrt(tmp); } } - dS[start_sfb] = dN[start_sfb]; - move16(); - dS_e[start_sfb] = dN_e[start_sfb]; - move16(); - + dS[start_sfb] = dN[start_sfb]; /* first value with adaption to core energy: */ - tmp_e = BASOP_Util_Add_MantExp(dE, - dE_e, - negate(dN[start_sfb]), - dN_e[start_sfb], - &tmp); /* float: tmp = dE - dN[start_sfb] */ - IF (tmp < 0) + if (dE < dN[start_sfb]) { - /* float: dS[start_sfb] = dN[start_sfb] + fFactor * (dE-dN[start_sfb]); basop: */ - L_tmp = L_mult(fFactor, tmp); - L_tmp_e = add(tmp_e, 1); /* 1Q14 | fFactor is 1Q14 */ - dS_e[start_sfb] = BASOP_Util_Add_MantExp(dN[start_sfb], - dN_e[start_sfb], - round_fx(L_tmp), - L_tmp_e, - &dS[start_sfb]); - move16(); + dS[start_sfb] = dN[start_sfb] + fFactor * (dE - dN[start_sfb]); } /* last value with less energy: */ - dS[stop_sfb - 1] = mult_r(lFactor, dN[stop_sfb - 1]); - move16(); - move16(); - dS_e[stop_sfb - 1] = add(dN_e[stop_sfb - 1], 1); /* 1Q14 | lFactor is 1Q14 */ + dS[stop_sfb - 1] = lFactor * dN[stop_sfb - 1]; - sfb_p1 = add(start_sfb, 1); - sfb_m1 = sub(stop_sfb, 1); - test(); - IF (hGrid->infoIsRefined != 0 && sub(hopsize, 1) == 0) + if (hGrid->infoIsRefined && hopsize == 1) { /* apply filter to absolute energy values: */ - FOR (sfb = sfb_p1; sfb < sfb_m1; sfb++) + for (sfb = start_sfb+1; sfb < stop_sfb-1; sfb++) { - /* float: dS[sfb] = w0 * dN[sfb-1] + w1 * dN[sfb+0] + w2 * dN[sfb+1]; basop: */ - L_tmp = L_mult(w0, dN[sfb - 1]); - dS[sfb] = round_fx(L_tmp); - move16(); - dS_e[sfb] = dN_e[sfb-1]; /* w0 is Q15, so no need to add an exponent */ - L_tmp = L_mult(w1, dN[sfb]); - dS_e[sfb] = BASOP_Util_Add_MantExp(dS[sfb], - dS_e[sfb], - round_fx(L_tmp), - dN_e[sfb], /* w1 is Q15, so no need to add an exponent */ - &tmp); - move16(); - dS[sfb] = tmp; - move16(); - L_tmp = L_mult(w2, dN[sfb + 1]); - dS_e[sfb] = BASOP_Util_Add_MantExp(dS[sfb], - dS_e[sfb], - round_fx(L_tmp), - dN_e[sfb + 1], /* w2 is Q15, so no need to add an exponent */ - &tmp); - move16(); - dS[sfb] = tmp; - move16(); + dS[sfb] = w0 * dN[sfb - 1] + w1 * dN[sfb] + w2 * dN[sfb + 1]; } } - ELSE + else { - FOR (sfb = sfb_p1; sfb < sfb_m1; sfb++) + for (sfb = start_sfb + 1; sfb < stop_sfb - 1; sfb++) { - dS[sfb] = dN[sfb]; - move16(); - dS_e[sfb] = dN_e[sfb]; - move16(); + dS[sfb] = dN[sfb]; } } - Hr = 0; - move16(); - tileIdx = -1; - move16(); - FOR (sfb = start_sfb; sfb < stop_sfb; sfb += hopsize) + for (sfb = start_sfb; sfb < stop_sfb; sfb+=hopsize) { - E = L_add(0, 0); - E_e = 0; - move16(); + E = 0.f; sum = 0; - move16(); - - FOR (tb = 0; tb < hopsize; tb++) + for (tb = 0; tb < hopsize; tb++) { - /* calculate of the current sfb width */ - width = sub(hGrid->swb_offset[s_min(add(add(sfb, tb), 1), stop_sfb)], /* 15Q0 | width is Q0 */ - hGrid->swb_offset[s_min(add(sfb, tb), stop_sfb)]); - - tmp = dS[s_min(add(sfb, tb), sub(stop_sfb, 1))]; - tmp_e = dS_e[s_min(add(sfb, tb), sub(stop_sfb, 1))]; - - /* square tmp */ - L_tmp = L_mult(tmp, tmp); - L_tmp_e = add(tmp_e, tmp_e); - - /* mult L_tmp times width */ - L_tmp = L_mult(round_fx(L_tmp), width); - L_tmp_e = add(L_tmp_e, 15); /* 15Q0 | width is Q0 */ - - /* calculate resulting energy */ - E = BASOP_Util_Add_Mant32Exp(E, - E_e, - L_tmp, - L_tmp_e, - &E_e); - sum = add(sum, width); /* 15Q0 | sum shares its exponent with width */ + width = (float)(swb_offset[min(sfb + tb + 1, stop_sfb)] - swb_offset[min(sfb + tb, stop_sfb)]); + val = dS[min(sfb + tb,stop_sfb - 1)]; + E += val * val * width; + sum += width; } - /* normalize sum for the following division */ - shift = norm_s(sum); - sum = shl(sum, shift); /* exponent of sum: sub(15, shift) */ + dS[sfb] = (float)sqrt((E * hopsize) / sum); + dN[sfb] = gFactor * dS[sfb]; - /* divide E by sum */ - tmp = div_s(shr(round_fx(E), 1), sum); /* shift E 1 bit to the right in order to make it smaller than sum */ - tmp_e = sub(add(E_e, 1), sub(15, shift)); /* 15Q0 | sum is 15Q0 */ + width = (float)(swb_offset[sfb + 1] - swb_offset[sfb]); + dN[sfb] = dN[sfb] * dN[sfb] * width; + gain[sfb] = 0.f; - /* multiply the result by the hopsize */ - L_tmp = L_mult(tmp, hopsize); - L_tmp_e = add(tmp_e, 15); /* 15Q0 | hopsize is 15Q0 */ - - /* take the square root and store the result in dS */ - L_tmp = Sqrt32(L_tmp, &L_tmp_e); - dS[sfb] = round_fx(L_tmp); - dS_e[sfb] = L_tmp_e; - move16(); - - /* calculate the new dN */ - dN[sfb] = mult_r(gFactor, dS[sfb]); - move16(); - move16(); - dN_e[sfb] = add(dS_e[sfb], 1); /* 1Q14 | gFactor is 1Q14 */ - - /* calculate of the current sfb width */ - width = sub(hGrid->swb_offset[sfb + 1], /* 15Q0 | width is Q0 */ - hGrid->swb_offset[sfb]); - - /* square dN */ - L_tmp = L_mult(dN[sfb], dN[sfb]); - L_tmp_e = add(dN_e[sfb], dN_e[sfb]); - - /* mult L_tmp times width */ - shift = norm_l(L_tmp); - L_tmp = L_shl(L_tmp, shift); - L_tmp = L_mult(round_fx(L_tmp), width); - L_tmp_e = sub(add(L_tmp_e, 15), shift); /* 15Q0 | width is Q0 */ - shift = norm_l(L_tmp); - - /* store normalized result */ - dNlocal = L_shl(L_tmp, shift); - dNlocal_e = sub(L_tmp_e, shift); - - /* gain calculation */ - gain[sfb] = 0; - move16(); - IF (pN[sfb] != 0) + if (pN[sfb] > 1.e-20f) { - tmp = BASOP_Util_Divide3232_Scale(dNlocal, pN[sfb],&s); - s = sub(add(s, dNlocal_e), pN_e[sfb]); - gain[sfb] = Sqrt16(tmp, &s); - move16(); - gain_e[sfb] = s; - move16(); - - - /* get the maximal exponent of the gain array, needed for exponent adjustment of the spectrum */ - maxGain_e = s_max(maxGain_e, gain_e[sfb]); - } - sfb_p1 = add(sfb, 1); - sfb_m1 = s_min(add(sfb, hopsize), stop_sfb); - FOR (s_sfb = sfb_p1; s_sfb < sfb_m1; s_sfb++) - { - gain[s_sfb] = gain[sfb]; - move16(); - gain_e[s_sfb] = gain_e[sfb]; - move16(); + gain[sfb] = (float)sqrt(dN[sfb] / pN[sfb]); } - /*--- check gains /spectrum exponents for possible overflows --- */ - /* get tile index */ - if (sub(hGrid->sfbWrap[tileIdx + 1], sfb) <= 0) + for (s_sfb = sfb + 1; s_sfb < min(sfb + hopsize, stop_sfb); s_sfb++) { - tileIdx = add(tileIdx, 1); + gain[s_sfb] = gain[sfb]; } - /*do a test multiplication with the highest possible value*/ - L_tmp = Mpy_32_16_1(0xFFFF8000/*igf_spec occupies only the 16LSBs */, gain[sfb]); - L_tmp_e = add(igf_spec_e[tileIdx], gain_e[sfb]); - /*check whether overflow would occur and calculate Headroom, needed*/ - shift = sub(L_tmp_e, *spectrum_e); - tmp = sub(shift , sub(norm_l(L_tmp), TCX_IMDCT_HEADROOM)); - if (tmp > 0) - { - Hr = s_max(Hr, tmp); - } - - /* disable rescaling if gain is smaler than 1 */ - /* gain < 1, if norm_s(gain[sfb]) >= gain_e[sfb] */ - tmp = sub(norm_s(gain[sfb]), gain_e[sfb]); - if (tmp >= 0) - { - Hr = 0; - move16(); - } - } - - /* Rescale spectrum if overflow may occur */ - tileIdx = -1; - move16(); - IF (Hr > 0) - { - /* rescale virtual Spec, cheap and easy: reset scalingfactor */ - *virtualSpec_e = add(*virtualSpec_e, Hr); - move16(); - - /* rescale spectrum */ - FOR (i = 0; i < hGrid->stopLine; i++) - { - spectrum[i] = L_shr(spectrum[i], Hr); - move16(); - } - *spectrum_e = add(*spectrum_e, Hr); - move16(); } /* tiling */ - tileIdx = -1; - move16(); - FOR (sfb = start_sfb; sfb < stop_sfb; sfb++) + for(sfb = start_sfb; sfb < stop_sfb; sfb++) { - /* get tile index */ - if (sub(hGrid->sfbWrap[tileIdx + 1], sfb) == 0) + + if (hPrivateData->frameLossCounter > 0) { - tileIdx = add(tileIdx, 1); - } + gain[sfb] = min(gain[sfb], 12.f); - IF (hPrivateData->frameLossCounter > 0) - { - /* normalize gain */ - tmp = norm_s(gain[sfb]); - gain[sfb] = shl(gain[sfb], tmp); - gain_e[sfb] = sub(gain_e[sfb], tmp); - - /* gain[sfb] = min(gain[sfb], 12.f); */ - BASOP_SATURATE_WARNING_OFF /* threshold, may overflow */ - tmp = shl(gain[sfb], sub(gain_e[sfb], 15 - 5)); /* 10Q5 | tmp is in 10Q5 */ - BASOP_SATURATE_WARNING_ON - - IF (tmp > 384) /* 10Q5 | 384 = 12 in 10Q5 */ + if (hPrivateData->frameLossCounter < 5) { - gain[sfb] = 384; - move16(); - gain_e[sfb] = 10; - move16(); + gain[sfb] -= gain[sfb] / 8 * hPrivateData->frameLossCounter; } - - IF (sub(hPrivateData->frameLossCounter, 5) < 0) + else { - /* gain[sfb] -= gain[sfb] / 8 * hPrivateData->frameLossCounter; -> multiply with 0Q15 -> adaption of the exponent not needed */ - IF (sub(hPrivateData->frameLossCounter, 1) == 0) - { - /* 0Q15 | >> 3 ^= * 0.125 = 1 / 8 */ - gain[sfb] = sub(gain[sfb], shr_r(gain[sfb], 3)); - move16(); - } - ELSE IF (sub(hPrivateData->frameLossCounter, 2) == 0) - { - /* 0Q15 | >> 2 ^= * 0.25 = 2 / 8 */ - gain[sfb] = sub(gain[sfb], shr_r(gain[sfb], 2)); - move16(); - } - ELSE IF (sub(hPrivateData->frameLossCounter, 3) == 0) - { - /* 0Q15 | * 12288 ^= * 0.3750 = 3 / 8 */ - gain[sfb] = sub(gain[sfb], mult_r(gain[sfb], 12288)); - move16(); - } - ELSE - { - /* 0Q15 | >> 1 ^= * 0.5 = 4 / 8 */ - gain[sfb] = sub(gain[sfb], shr_r(gain[sfb], 1)); - move16(); - } - } - ELSE - { - /* gain[sfb] /= 2; -> reduce exponent by 1 */ - gain_e[sfb] = sub(gain_e[sfb], 1); - move16(); + gain[sfb] /= 2; } } - FOR (tb = hGrid->swb_offset[sfb]; tb < hGrid->swb_offset[sfb + 1]; tb++) + for (tb = swb_offset[ sfb ]; tb < swb_offset[ sfb+1 ]; tb++) { - /* multiply the prepared IGF spectrum with the gain */ - L_tmp2 = L_add(0, 0); /* set L_tmp2 to default value */ - L_tmp = Mpy_32_16_1(igf_spec[tb], gain[sfb]); - L_tmp_e = add(igf_spec_e[tileIdx], gain_e[sfb]); - - /* store the finalized IGF spectrum */ - IF (spectrum[tb] == 0) + if(pSpectralData[tb] == 0.f) { - shift = sub(L_tmp_e, *spectrum_e); - tmp = norm_l(L_tmp) - shift - 32; - if (tmp < 0) - { - L_tmp2 = L_shl(L_tmp, shift); - } - spectrum[tb] = L_tmp2; - move32(); - flag_sparse[tb-IGF_START_MN] = 1; - move16(); + pSpectralData[tb] = igf_spec[tb] * gain[sfb]; + flag_sparse[tb-IGF_START_MN] = 1; } - ELSE + else { - shift = sub(L_tmp_e, *virtualSpec_e); - tmp = norm_l(L_tmp) - shift - 32; - if (tmp < 0) - { - L_tmp2 = L_shl(L_tmp, shift); - } - virtualSpec[tb-IGF_START_MN] = L_tmp2; - move32(); - flag_sparse[tb-IGF_START_MN] = 2; - move16(); + virtualSpec[tb-IGF_START_MN] = igf_spec[tb] * gain[sfb]; + flag_sparse[tb-IGF_START_MN] = 2; + } } } - } /**********************************************************************/ /* spectral whitening **************************************************************************/ -static void IGF_getWhiteSpectralData(const Word32 *in, /**< in: Q31 | MDCT spectrum */ - Word16 s_l, /**< in: Q0 | getScaleFactor32() of in */ - Word32 *out, /**< out: Q31| whitened spectrum */ - const Word16 start, /**< in: Q0 | start MDCT subband index */ - const Word16 stop, /**< in: Q0 | stop MDCT subband index */ - const Word16 level /**< in: Q0 | whitening strength */ +static void IGF_getWhiteSpectralData(const float *in, /**< in: | MDCT spectrum */ + float *out, /**< out: | whitened spectrum */ + const int start, /**< in: | start MDCT subband index */ + const int stop, /**< in: | stop MDCT subband index */ + const int level /**< in: | whitening strength */ ) { - Word16 j; - Word32 ak; /* moving average */ - Word32 ak_norm; - Word16 tmp_16; - Word16 div; - Word16 nrm_i; - Word16 nrm_tab[] = {2341 /* 1/14 */, 2521 /* 1/13 */, 2731 /* 1/12 */, 2979 /* 1/11 */, 3277 /* 1/10 */, 3641 /* 1/9 */, 4096 /* 1/8 */, 4681 /* 1/7 */}; - + int i; + int n; + int j; + float div; + float ak; /* inits */ div = 0; - move16(); - s_l = sub(s_l, 2); - ak = L_add(0, 0); - - FOR (j = start - level; j < start + level; j++) + for (i = start; i < stop - level; i++) { - tmp_16 = extract_h(L_shl(in[j], s_l)); - ak = L_mac(ak, tmp_16, tmp_16); - } - FOR (j = start; j < stop - level; j++) - { - tmp_16 = extract_h(L_shl(in[j + level], s_l)); - ak = L_mac(ak, tmp_16, tmp_16); - ak_norm = Mpy_32_16_r(ak, 2185); - tmp_16 = sub(31, norm_l(ak_norm)); - - if (ak == 0) + ak = 1e-3f; + for (j = i - level; j < i + level + 1; j++) { - tmp_16 = 0; - move16(); + ak += in[j] * in[j]; } + ak /= (float)(level * 2 + 1); - tmp_16 = s_min(14, sub(15, shr(tmp_16, 1))); - div = shl(1, tmp_16); - out[j] = Mpy_32_16_1(L_shl(in[j], s_l), div); - move32(); - tmp_16 = extract_h(L_shl(in[j - level], s_l)); - ak = L_msu(ak, tmp_16, tmp_16); + n = max(0.f, (int)(log(ak) * INV_LOG_2)); /* INV_LOG_2 = 1 / (float)log(2.0f)) */ + n >>= 1; /* sqrt() */ + div = (float)(pow(2.0f, (float)(21 - n))); + + + out[i] = in[i] * div; /* same as shift */ } - nrm_i = 0; - move16(); - - FOR (; j < stop; j++) + for (; i < stop; i++) { - ak_norm = Mpy_32_16_r(ak, nrm_tab[nrm_i++]); - tmp_16 = sub(31, norm_l(ak_norm)); + ak = 1e-3f; - if (ak == 0) + for (j = i - level; j < stop; j++) { - tmp_16 = 0; - move16(); + ak += in[j]*in[j]; } + ak /= (float)(stop - (i - level)); - tmp_16 = s_min(14, sub(15, shr(tmp_16, 1))); - div = shl(1, tmp_16); - if (L_sub(ak, 16) < 0) - { - div = 1; - move16(); - } + n = max(0.f,(int)(log(ak) * INV_LOG_2)); /* INV_LOG_2 = 1 / (float)log(2.0f)) */ + n >>= 1; /* sqrt() */ + div = (float)(pow(2.0f, (float)(21 - n))); - out[j] = Mpy_32_16_1(L_shl(in[j], s_l), div); - move32(); - tmp_16 = extract_h(L_shl(in[j - level], s_l)); - ak = L_msu(ak, tmp_16, tmp_16); + + out[i] = in[i] * div; /* same as shift */ } - } /**********************************************************************/ /* @@ -1250,397 +580,297 @@ refines the IGF grid static void IGF_RefineGrid(H_IGF_GRID hGrid /**< in/out: | IGF grid handle */ ) { - Word16 a[IGF_MAX_SFB+1]; - Word16 sfb; - Word16 tmp; - Word16 delta; + int a[IGF_MAX_SFB+1]; /* +1: because in for-loop one value too much will be extrapolated */ + int sfb; - - set16_fx(a, 0, IGF_MAX_SFB+1); + set_i(a, 0, IGF_MAX_SFB+1); hGrid->infoIsRefined = 1; - move16(); - FOR (sfb = 0; sfb < hGrid->swb_offset_len; sfb++) + for (sfb = 0; sfb < hGrid->swb_offset_len; sfb++) { - tmp = shl(sfb, 1); - a[tmp] = hGrid->swb_offset[sfb]; - move16(); - tmp = add(tmp, 1); - delta = sub(hGrid->swb_offset[sfb+1], hGrid->swb_offset[sfb]); - delta = mac_r(0x00195000, 29491/*0.45f Q16*/, shl(delta, 5)); - a[tmp] = add(hGrid->swb_offset[sfb], shr(delta, 6)); - move16(); - if (s_and(a[tmp], 1) != 0) + a[sfb*2 + 0] = hGrid->swb_offset[sfb]; + a[sfb*2 + 1] = round_f(hGrid->swb_offset[sfb] + 0.45f * (hGrid->swb_offset[sfb + 1] - hGrid->swb_offset[sfb])); + if (a[sfb*2 + 1] & 1) { - a[tmp] = sub(a[tmp], 1); - move16(); + a[sfb*2 + 1]--; } } - hGrid->stopSfb = shl(hGrid->stopSfb, 1); - FOR (sfb = 0; sfb <= hGrid->stopSfb; sfb++) + hGrid->stopSfb = hGrid->stopSfb * 2; + for (sfb = 0; sfb <= hGrid->stopSfb; sfb++) { hGrid->swb_offset[sfb] = a[sfb]; - move16(); } - FOR (sfb = 0; sfb <= hGrid->nTiles; sfb++) + for (sfb = 0; sfb <= hGrid->nTiles; sfb++) { - hGrid->sfbWrap[sfb] = shl(hGrid->sfbWrap[sfb], 1); - move16(); + hGrid->sfbWrap[sfb] *= 2; } - } /**********************************************************************/ /* reads whitening information from the bitstream **************************************************************************/ void IGFDecReadData(const IGF_DEC_INSTANCE_HANDLE hInstance, /**< in: | instance handle of IGF Deccoder */ - Decoder_State_fx *st, /**< in: | decoder state */ - const Word16 igfGridIdx, /**< in: Q0 | in case of CELP->TCX switching, use 1.25 framelength */ - const Word16 isIndepFrame /**< in: Q0 | if 1: arith dec force reset, if 0: no reset */ + Decoder_State *st, /**< in: | decoder state */ + const int igfGridIdx, /**< in: | in case of CELP->TCX switching, use 1.25 framelength */ + const int isIndepFrame /**< in: | if 1: arith dec force reset, if 0: no reset */ ) { IGF_DEC_PRIVATE_DATA_HANDLE hPrivateData; H_IGF_GRID hGrid; - Word16 p; - Word16 nT; - Word16 tmp; + int p; + int nT; + int tmp; - - IF (hInstance != NULL) + if (hInstance != NULL) { hPrivateData = &hInstance->igfData; hGrid = &hPrivateData->igfInfo.grid[igfGridIdx]; nT = hGrid->nTiles; - move16(); - tmp = 0; - move16(); + tmp = -1; - /* set/reset all values to default = IGF_WHITENING_OFF */ - FOR (p = 0; p < IGF_MAX_TILES; p++) + for (p = 0; p < IGF_MAX_TILES; p++) { hPrivateData->currWhiteningLevel[p] = IGF_WHITENING_OFF; - move16(); } - IF (isIndepFrame == 0) + if (isIndepFrame) { - tmp = get_next_indice_fx(st, 1); + tmp = 0; } - - IF (tmp == 1) + else { - FOR (p = 0; p < nT; p++) + tmp = get_next_indice(st, 1); + } + if (tmp == 1) + { + for (p = 0; p < nT; p++) { hPrivateData->currWhiteningLevel[p] = hPrivateData->prevWhiteningLevel[p]; - move16(); } } - ELSE + else { IGF_decode_whitening_level(st, hPrivateData, 0); - tmp = get_next_indice_fx(st, 1); - IF (tmp == 1) + tmp = (int)get_next_indice(st, 1); + if (tmp == 1) { - FOR (p = 1; p < nT; p++) + for (p = 1; p < nT; p++) { IGF_decode_whitening_level(st, hPrivateData, p); } } - ELSE + else { - FOR (p = 1; p < nT; p++) + for (p = 1; p < nT; p++) { hPrivateData->currWhiteningLevel[p] = hPrivateData->currWhiteningLevel[0]; - move16(); } } } - - /* save current level for concealment */ - FOR (p = 0; p < IGF_MAX_TILES; p++) + for (p = 0; p < IGF_MAX_TILES; p++) { hPrivateData->prevWhiteningLevel[p] = hPrivateData->currWhiteningLevel[p]; - move16(); } - - /* read flattening trigger from bitstream */ IGF_decode_temp_flattening_trigger(st, hInstance); } - } /**********************************************************************/ /* read the IGF level information from the bitsream **************************************************************************/ -void IGFDecReadLevel( /**< out: Q0 | return igfAllZero flag indicating if no envelope is transmitted */ - const IGF_DEC_INSTANCE_HANDLE hInstance, /**< in: | instance handle of IGF Decoder */ - Decoder_State_fx *st, /**< in: | decoder state */ - const Word16 igfGridIdx, /**< in: Q0 | in case of CELP->TCX switching, use 1.25 framelength */ - const Word16 isIndepFrame /**< in: Q0 | if 1: arith dec force reset, if 0: no reset */ +int IGFDecReadLevel( /**< out: | return igfAllZero flag indicating if no envelope is transmitted */ + const IGF_DEC_INSTANCE_HANDLE hInstance, /**< in: | instance handle of IGF Deccoder */ + Decoder_State *st, /**< in: | decoder state */ + const int igfGridIdx, /**< in: | in case of CELP->TCX switching, use 1.25 framelength */ + const int isIndepFrame /**< in: | if 1: arith dec force reset, if 0: no reset */ ) { IGF_DEC_PRIVATE_DATA_HANDLE hPrivateData; H_IGF_GRID hGrid; - Word16 m_igfSfbStart; - Word16 IGFAllZero; + int m_igfSfbStart; + int IGFAllZero; IGFAllZero = 1; - move16(); - IF (hInstance != NULL) + if (hInstance != NULL) { hPrivateData = &hInstance->igfData; hGrid = &hPrivateData->igfInfo.grid[igfGridIdx]; m_igfSfbStart = hGrid->startSfb; - move16(); - IGFAllZero = get_next_indice_fx(st, 1); + IGFAllZero = get_next_indice(st, 1); - IF (IGFAllZero == 0) + if (IGFAllZero == 0) { - Copy(hPrivateData->igf_curr, hPrivateData->igf_prev, hGrid->stopSfb); + mvi2i(hPrivateData->igf_curr, hPrivateData->igf_prev, hGrid->stopSfb); IGFSCFDecoderDecode(&hPrivateData->hArithSCFdec, st, - &hPrivateData->igf_curr[m_igfSfbStart], /* 0Q15, hPrivateData->igf_curr = [0, 91] */ - isIndepFrame - ); + &hPrivateData->igf_curr[m_igfSfbStart], /**< out: ptr to an array which will contain the decoded quantized coefficients */ + isIndepFrame); /**< in: if 1 on input reset will be forced, if 0 on input continue without reset */ } - ELSE + else { IGFSCFDecoderReset(&hPrivateData->hArithSCFdec); - set16_fx(&hPrivateData->igf_curr[m_igfSfbStart], 0, sub(hGrid->stopSfb, m_igfSfbStart)); + set_i(&hPrivateData->igf_curr[m_igfSfbStart], 0, hGrid->stopSfb - m_igfSfbStart); } } hInstance->infoIGFAllZero = IGFAllZero; - move16(); + return IGFAllZero; } /**********************************************************************/ /* apply the IGF decoder **************************************************************************/ void IGFDecApplyMono(const IGF_DEC_INSTANCE_HANDLE hInstance, /**< in: | instance handle of IGF Decoder */ - Word32 *spectrum, /**< in/out: | MDCT spectrum */ - Word16 *spectrum_e, /**< in/out: | exponent of spectrum */ - const Word16 igfGridIdx, /**< in: | in case of CELP->TCX switching, use 1.25 framelength */ - Word16 bfi /**< in: | frame loss == 1, frame good == 0 */ + float *spectrum, /**< in/out: | MDCT spectrum */ + const int igfGridIdx, /**< in: | in case of CELP->TCX switching, use 1.25 framelength */ + int bfi /**< in: | frame loss == 1, frame good == 0 */ ) { IGF_DEC_PRIVATE_DATA_HANDLE hPrivateData; H_IGF_GRID hGrid; - Word16 i; - Word16 whiteningLevel; - Word16 s_l; /* | headroom of pSpecFlat */ - Word16 specMed_e; /* | exponent of the medium whitened spectrum */ - Word32 igf_spec[IGF_MAX_GRANULE_LEN]; /* Q31 | prepared IGF spectrum */ - Word16 igf_spec_e[IGF_MAX_TILES]; /* | exponents of igf_spec, one exponent per tile */ - - - hPrivateData = &hInstance->igfData; - hGrid = &hPrivateData->igfInfo.grid[igfGridIdx]; + int i; + int whiteningLevel; + float igf_spec[IGF_MAX_GRANULE_LEN] = {0.f}; /* initialize variables */ - whiteningLevel = 7; - move16(); - specMed_e = 0; - move16(); - hPrivateData->n_noise_bands = 0; - move16(); - hPrivateData->n_noise_bands_off = 0; - move16(); - hPrivateData->headroom_TCX_noise_white = 0; - move16(); - hPrivateData->headroom_TCX_noise = 0; - move16(); - hPrivateData->totalNoiseNrg = L_add(0, 0); - hPrivateData->totalNoiseNrg_off = L_add(0, 0); - - set32_fx(igf_spec, 0, IGF_MAX_GRANULE_LEN); - set16_fx(igf_spec_e, 0, IGF_MAX_TILES); + whiteningLevel = 7; + hPrivateData = &hInstance->igfData; + hGrid = &hPrivateData->igfInfo.grid[igfGridIdx]; + hPrivateData->totalNoiseNrg = 0.f; + hPrivateData->n_noise_bands = 0; + hPrivateData->totalNoiseNrg_off = 0.f; + hPrivateData->n_noise_bands_off = 0; /* concealment counter */ - IF (bfi != 0) + if (bfi) { - hPrivateData->frameLossCounter = add(hPrivateData->frameLossCounter, 1); + hPrivateData->frameLossCounter++; } - ELSE + else { hPrivateData->frameLossCounter = 0; } /* skip IGF processing if all IGF levels are zero */ - IF (hInstance->infoIGFAllZero == 0) + if (!hInstance->infoIGFAllZero) { - - FOR (i = 0; i < hGrid->nTiles; i++) + for (i = 0; i < hGrid->nTiles; i++) { - IF (sub(hPrivateData->currWhiteningLevel[i], IGF_WHITENING_MID) == 0) + if (hPrivateData->currWhiteningLevel[i] == IGF_WHITENING_MID) { - s_l = getScaleFactor32(hPrivateData->pSpecFlat + hGrid->minSrcSubband - whiteningLevel, - add(sub(hGrid->startLine, hGrid->minSrcSubband), whiteningLevel)); - - specMed_e = hPrivateData->pSpecFlat_exp; - move16(); IGF_getWhiteSpectralData(hPrivateData->pSpecFlat, - s_l, igf_spec, hGrid->minSrcSubband, hGrid->startLine, whiteningLevel); - /*14 seems to be precise enough*/ - hPrivateData->headroom_TCX_noise_white = IGF_getScaleFactor32Cond(hInstance->infoTCXNoise + hGrid->minSrcSubband, - igf_spec + hGrid->minSrcSubband, - sub(hGrid->startLine, hGrid->minSrcSubband)); hPrivateData->n_noise_bands = IGF_replaceTCXNoise_1(igf_spec, - hPrivateData->headroom_TCX_noise_white, hInstance->infoTCXNoise, hGrid->minSrcSubband, hGrid->startLine, &hPrivateData->totalNoiseNrg); - - BREAK; + break; } } - FOR (i = 0; i < hGrid->nTiles; i++) + for (i = 0; i < hGrid->nTiles; i++) { - IF (hPrivateData->currWhiteningLevel[ i ] == IGF_WHITENING_OFF) + if (hPrivateData->currWhiteningLevel[i] == IGF_WHITENING_OFF) { - hPrivateData->headroom_TCX_noise = IGF_getScaleFactor32Cond(hInstance->infoTCXNoise + hGrid->minSrcSubband, - hPrivateData->pSpecFlat + hGrid->minSrcSubband, - sub(hGrid->startLine, hGrid->minSrcSubband)); - hPrivateData->n_noise_bands_off = IGF_replaceTCXNoise_1(hPrivateData->pSpecFlat, - hPrivateData->headroom_TCX_noise, hInstance->infoTCXNoise, hGrid->minSrcSubband, hGrid->startLine, &hPrivateData->totalNoiseNrg_off); - BREAK; + break; } } /* apply IGF in three steps: */ - IGF_prep(hPrivateData, - igfGridIdx, - hInstance->infoTCXNoise, - igf_spec, - igf_spec_e, - hPrivateData->pSpecFlat, - hPrivateData->pSpecFlat_exp, - specMed_e); - IGF_calc(hPrivateData, - igfGridIdx, - spectrum, - *spectrum_e, - igf_spec, - igf_spec_e); - IGF_appl(hPrivateData, - igfGridIdx, - spectrum, - spectrum_e, - igf_spec, - igf_spec_e, - hInstance->virtualSpec, - &hInstance->virtualSpec_e, - hInstance->flag_sparse); + IGF_prep(hPrivateData, igfGridIdx, hInstance->infoTCXNoise, igf_spec, hPrivateData->pSpecFlat); + IGF_calc(hPrivateData, igfGridIdx, spectrum, igf_spec); + IGF_appl(hPrivateData, igfGridIdx, spectrum, igf_spec, hInstance->virtualSpec, hInstance->flag_sparse); } /* reset TCX noise indicator vector */ - set16_fx(hInstance->infoTCXNoise, 0, IGF_START_MX); - + set_c((char*)(hInstance->infoTCXNoise), 0, IGF_START_MX); } /**********************************************************************/ /* set mode is used to init the IGF dec with a new bitrate **************************************************************************/ void IGFDecSetMode(const IGF_DEC_INSTANCE_HANDLE hInstance, /**< in: | instance handle of IGF Decoder */ - const Word32 bitRate, /**< in: Q0 | bitrate */ - const Word16 mode, /**< in: Q0 | bandwidth mode */ - const Word16 defaultStartLine, /**< in: Q0 | default start subband index */ - const Word16 defaultStopLine /**< in: Q0 | default stop subband index */ - , const Word16 rf_mode /**< in: | flag to signal the RF mode */ + const int bitRate, /**< in: | bitrate */ + const int mode, /**< in: | bandwidth mode */ + const int defaultStartLine, /**< in: | default start subband index */ + const int defaultStopLine /**< in: | default stop subband index */ + , const int rf_mode /**< in: | flag to signal the RF mode */ ) { IGF_DEC_PRIVATE_DATA_HANDLE hPrivateData; - hPrivateData = &hInstance->igfData; hInstance->isIGFActive = 0; - move16(); - IF (IGFCommonFuncsIGFConfiguration(bitRate, mode, &hPrivateData->igfInfo, rf_mode) != 0) + if (IGFCommonFuncsIGFConfiguration(bitRate, mode, &hPrivateData->igfInfo + , rf_mode + )) { IGFSCFDecoderOpen(&hPrivateData->hArithSCFdec, - sub(hPrivateData->igfInfo.grid[0].stopSfb, hPrivateData->igfInfo.grid[0].startSfb), + hPrivateData->igfInfo.grid[0].stopSfb - hPrivateData->igfInfo.grid[0].startSfb, bitRate, mode - ,rf_mode + , rf_mode ); hInstance->infoIGFStopLine = hPrivateData->igfInfo.grid[0].stopLine; - move16(); hInstance->infoIGFStartLine = hPrivateData->igfInfo.grid[0].startLine; - move16(); hInstance->infoIGFStopFreq = hPrivateData->igfInfo.grid[0].stopFrequency; - move16(); hInstance->infoIGFStartFreq = hPrivateData->igfInfo.grid[0].startFrequency; - move16(); hInstance->infoIGFAllZero = 0; - move16(); hInstance->isIGFActive = 1; - move16(); - test(); - IF ((sub(hPrivateData->igfInfo.bitRateIndex, IGF_BITRATE_SWB_48000) <= 0) || (sub(hPrivateData->igfInfo.bitRateIndex, IGF_BITRATE_FB_48000) <= 0)) + if (hPrivateData->igfInfo.bitRateIndex <= IGF_BITRATE_SWB_48000 || hPrivateData->igfInfo.bitRateIndex <= IGF_BITRATE_FB_48000) { IGF_RefineGrid(&hPrivateData->igfInfo.grid[IGF_GRID_LB_NORM]); IGF_RefineGrid(&hPrivateData->igfInfo.grid[IGF_GRID_LB_TRAN]); IGF_RefineGrid(&hPrivateData->igfInfo.grid[IGF_GRID_LB_SHORT]); } + /* IGFDecOutInformation(hInstance); */ } - ELSE + else { hInstance->infoIGFStopLine = defaultStopLine; - move16(); hInstance->infoIGFStartLine = defaultStartLine; - move16(); hInstance->infoIGFStopFreq = -1; - move16(); hInstance->infoIGFStartFreq = -1; - move16(); fprintf(stderr,"IGFDecSetMode: initialization error!\n"); } - } /**********************************************************************/ /* updates the start/stop frequency of IGF according to igfGridIdx **************************************************************************/ void IGFDecUpdateInfo(const IGF_DEC_INSTANCE_HANDLE hInstance, /**< in: | instance handle of IGF Decoder */ - const Word16 igfGridIdx /**< in: | IGF grid index */ + const int igfGridIdx /**< in: | IGF grid index */ ) { IGF_DEC_PRIVATE_DATA_HANDLE hPrivateData; H_IGF_GRID hGrid; - hPrivateData = &hInstance->igfData; - IF (hInstance->isIGFActive != 0) + if (hInstance->isIGFActive) { hGrid = &hPrivateData->igfInfo.grid[igfGridIdx]; hInstance->infoIGFStartFreq = hGrid->startFrequency; - move16(); hInstance->infoIGFStopFreq = hGrid->stopFrequency; - move16(); hInstance->infoIGFStartLine = hGrid->startLine; - move16(); hInstance->infoIGFStopLine = hGrid->stopLine; - move16(); } } @@ -1648,76 +878,68 @@ void IGFDecUpdateInfo(const IGF_DEC_INSTANCE_HANDLE hInstance, copy the LPC flat spectrum to IGF buffer **************************************************************************/ void IGFDecCopyLPCFlatSpectrum(const IGF_DEC_INSTANCE_HANDLE hInstance, /**< in: | instance handle of IGF Decoder */ - const Word32 *pSpectrumFlat, /**< in: Q31 | LPC flattend spectrum from TCX dec */ - const Word16 pSpectrumFlat_exp, /**< in: | exponent of pSpectrumFlat */ - const Word16 igfGridIdx /**< in: Q0 | IGF grid index */ + const float *pSpectrumFlat, /**< in: | LPC flattend spectrum from TCX dec */ + const int igfGridIdx /**< in: | IGF grid index */ ) { IGF_DEC_PRIVATE_DATA_HANDLE hPrivateData; H_IGF_GRID hGrid; + int i; - - IF (hInstance) + if (hInstance) { hPrivateData = &hInstance->igfData; hGrid = &hPrivateData->igfInfo.grid[igfGridIdx]; - /* pSpectrumFlat_exp has to be multiplied with 1024 = 2^10 go achive proper gain values */ - hPrivateData->pSpecFlat_exp = add(pSpectrumFlat_exp, 10); - move16(); - - Copy32(pSpectrumFlat, hPrivateData->pSpecFlat, hGrid->startLine); + for (i = hGrid->minSrcSubband - 7; i < hGrid->startLine; i++) + { + hPrivateData->pSpecFlat[i] = pSpectrumFlat[i] * 1024.f; + } } - } /**********************************************************************/ /* store the IGF bitstream information for TCX10 subframes **************************************************************************/ void IGFDecStoreTCX10SubFrameData(const IGF_DEC_INSTANCE_HANDLE hInstance, /**< in: | instance handle of IGF Decoder */ - const Word16 subFrameIdx /**< in: Q0 | index of subframe */ + const int subFrameIdx /**< in: | index of subframe */ ) { IGF_DEC_PRIVATE_DATA_HANDLE hPrivateData; - hPrivateData = &hInstance->igfData; /* store igf energies for subframe*/ - Copy(hPrivateData->igf_curr, hPrivateData->igf_curr_subframe[subFrameIdx][0], IGF_MAX_SFB); - Copy(hPrivateData->igf_prev, hPrivateData->igf_prev_subframe[subFrameIdx], IGF_MAX_SFB); + mvi2i(hPrivateData->igf_curr, hPrivateData->igf_curr_subframe[subFrameIdx][0], IGF_MAX_SFB); + mvi2i(hPrivateData->igf_prev, hPrivateData->igf_prev_subframe[subFrameIdx], IGF_MAX_SFB); /* store spectral whitening information for current subframe */ - Copy(hPrivateData->currWhiteningLevel, hPrivateData->currWhiteningLevel_subframe[subFrameIdx], IGF_MAX_TILES); - Copy(hPrivateData->prevWhiteningLevel, hPrivateData->prevWhiteningLevel_subframe[subFrameIdx], IGF_MAX_TILES); + mvi2i(hPrivateData->currWhiteningLevel, hPrivateData->currWhiteningLevel_subframe[subFrameIdx], IGF_MAX_TILES); + mvi2i(hPrivateData->prevWhiteningLevel, hPrivateData->prevWhiteningLevel_subframe[subFrameIdx], IGF_MAX_TILES); /* store flattening trigger for current subframe */ hPrivateData->igf_flatteningTrigger_subframe[subFrameIdx] = hInstance->flatteningTrigger; - move16(); - } /**********************************************************************/ /* restore the IGF bitstream information for TCX10 subframes **************************************************************************/ void IGFDecRestoreTCX10SubFrameData(const IGF_DEC_INSTANCE_HANDLE hInstance, /**< in: | instance handle of IGF Decoder */ - const Word16 subFrameIdx /**< in: Q0 | index of subframe */ + const int subFrameIdx /**< in: | index of subframe */ ) { IGF_DEC_PRIVATE_DATA_HANDLE hPrivateData; - hPrivateData = &hInstance->igfData; /* store igf energies for subframe*/ - Copy(hPrivateData->igf_curr_subframe[subFrameIdx][0], hPrivateData->igf_curr, IGF_MAX_SFB); - Copy(hPrivateData->igf_prev_subframe[subFrameIdx], hPrivateData->igf_prev, IGF_MAX_SFB); + mvi2i(hPrivateData->igf_curr_subframe[subFrameIdx][0], hPrivateData->igf_curr, IGF_MAX_SFB); + mvi2i(hPrivateData->igf_prev_subframe[subFrameIdx], hPrivateData->igf_prev, IGF_MAX_SFB); /* store spectral whitening information for current subframe */ - Copy(hPrivateData->currWhiteningLevel_subframe[subFrameIdx], hPrivateData->currWhiteningLevel, IGF_MAX_TILES); - Copy(hPrivateData->prevWhiteningLevel_subframe[subFrameIdx], hPrivateData->prevWhiteningLevel, IGF_MAX_TILES); + mvi2i(hPrivateData->currWhiteningLevel_subframe[subFrameIdx], hPrivateData->currWhiteningLevel, IGF_MAX_TILES); + mvi2i(hPrivateData->prevWhiteningLevel_subframe[subFrameIdx], hPrivateData->prevWhiteningLevel, IGF_MAX_TILES); /* restore flattening trigger for current subframe */ hInstance->flatteningTrigger = hPrivateData->igf_flatteningTrigger_subframe[subFrameIdx]; - move16(); - } + diff --git a/src/libs/libevs/lib_dec/igf_scf_dec.cpp b/src/libs/libevs/lib_dec/igf_scf_dec.cpp old mode 100755 new mode 100644 index 3f159e9a..5c792d5e --- a/src/libs/libevs/lib_dec/igf_scf_dec.cpp +++ b/src/libs/libevs/lib_dec/igf_scf_dec.cpp @@ -1,177 +1,194 @@ /*==================================================================================== - EVS Codec 3GPP TS26.442 Apr 03, 2018. Version 12.11.0 / 13.6.0 / 14.2.0 + EVS Codec 3GPP TS26.443 Nov 13, 2018. Version 12.11.0 / 13.7.0 / 14.3.0 / 15.1.0 ====================================================================================*/ #include #include #include #include +#include +#include "prot.h" #include "options.h" -#include "stl.h" -#include "prot_fx.h" -#include "stat_dec_fx.h" -#include "basop_util.h" +#include "stat_dec.h" -/**********************************************************************/ /** -initialization of an instance of this module -**************************************************************************/ +/*---------------------------------------------------------------------* + * IGFSCFDecoderOpen() + * + * initialization of an instance of this module, pass a ptr to a hPublicData + *---------------------------------------------------------------------*/ + void IGFSCFDecoderOpen( - IGFSCFDEC_INSTANCE_HANDLE hPublicData, /* i/o: handle to public data */ - Word16 scfCountLongBlock, /* i: number of SCFs for a long block */ - Word32 bitRate, /* i: bitrate in bps */ - Word16 mode /* i: operating mode */ - ,Word16 rf_mode + IGFSCFDEC_INSTANCE_HANDLE hPublicData, /**< inout: handle to public data */ + int scfCountLongBlock, + int bitRate, + int mode, + int rf_mode /**< in: flag to signal the RF mode */ ) { + hPublicData->scfCountLongBlock = scfCountLongBlock; + hPublicData->t = 0; /* protect against the invalid request of starting decoding with a dependent block */ - hPublicData->scfCountLongBlock = scfCountLongBlock; - move16(); - hPublicData->t = 0; - move16(); /* protect against the invalid request of starting decoding with a dependent block */ - - IGFCommonFuncsIGFGetCFTables( - bitRate, - mode, - rf_mode, - &hPublicData->cf_se00, - &hPublicData->cf_se01, - &hPublicData->cf_off_se01, - &hPublicData->cf_se02, - &hPublicData->cf_off_se02, - &hPublicData->cf_se10, - &hPublicData->cf_off_se10, - &hPublicData->cf_se11, - &hPublicData->cf_off_se11 - ); + IGFCommonFuncsIGFGetCFTables( bitRate, mode, rf_mode, &hPublicData->cf_se00, &hPublicData->cf_se01, &hPublicData->cf_off_se01, + &hPublicData->cf_se02, &hPublicData->cf_off_se02, &hPublicData->cf_se10, &hPublicData->cf_off_se10, + &hPublicData->cf_se11, &hPublicData->cf_off_se11 ); + return; } +/*---------------------------------------------------------------------* + * quant_ctx() + * + * + *---------------------------------------------------------------------*/ -static Word16 quant_ctx_fx( - Word16 ctx /* i: the context value to be quantized */ -) +static int quant_ctx(int ctx + ) { /* ctx ... -5 -4 -3 -2 -1 0 1 2 3 4 5 ... Q(ctx)... -3 -3 -3 -2 -1 0 1 2 3 3 3 ... */ - Word16 result; - - - result = s_min(abs_s(ctx), IGF_CTX_OFFSET); /* limit the absolute value to IGF_CTX_OFFSET */ - if (ctx < 0) /* add the sign back, if needed */ + if (abs(ctx) <= 3) { - result = negate(result); + return ctx; + } + else if (ctx > 3) + { + return 3; + } + else + { + /* ctx < -3 */ + return -3; } - return result; } -static Word16 arith_decode_bits_fx( - IGFSCFDEC_INSTANCE_HANDLE hPrivateData, /* i/o: instance handle */ - Decoder_State_fx *st, /* i/o: pointer to bitstream decoder state */ - Word16 nBits /* i: number of bits to decode */ +/*---------------------------------------------------------------------* + * arith_decode_bits() + * + * + *---------------------------------------------------------------------*/ + +static int arith_decode_bits( + IGFSCFDEC_INSTANCE_HANDLE hPrivateData, /**< instance handle */ + Decoder_State *st, /**< in: pointer to decoder state */ + int nBits /**< number of bits to decode */ ) { - Word16 i; - Word16 x; - Word16 bit; - + int i; + int x; + int bit; x = 0; - move16(); - FOR (i = 0; i < nBits; ++i) /* nBits > 0 */ + for (i = 0; i < nBits; ++i) { - x = lshl(x, 1); /* decode one bit using the new raw AC function */ - bit = ari_decode_14bits_bit_ext(st, &hPrivateData->acState); - if (bit != 0) - { - x = s_or(x, 1); - } + ari_decode_14bits_bit_ext(st, &bit, &hPrivateData->acState); + x = (x << 1) | bit; } return x; } -static Word16 arith_decode_residual_fx( - IGFSCFDEC_INSTANCE_HANDLE hPrivateData, /* i/o: instance handle */ - Decoder_State_fx *st, /* i/o: pointer to decoder state */ - const Word16 *cumulativeFrequencyTable, /* i: cumulative frequency table to be used */ - Word16 tableOffset /* i: offset used to align the table */ + +/*---------------------------------------------------------------------* + * arith_decode_residual() + * + * + *---------------------------------------------------------------------*/ + +static int arith_decode_residual( + IGFSCFDEC_INSTANCE_HANDLE hPrivateData, /**< instance handle */ + Decoder_State *st, /**< in: pointer to decoder state */ + const unsigned short* cumulativeFrequencyTable, /**< cumulative frequency table to be used */ + int tableOffset /**< offset used to align the table */ ) { - Word16 val; - Word16 x = 0; /* to avoid a compiler warning (potentially uninitialized local variable used) */ - Word16 extra; - + int val; + int x; + int extra; + int extra_tmp; /* decode one of the IGF_SYMBOLS_IN_TABLE == 27 alphabet symbols using the new raw AC function */ - val = ari_decode_14bits_s27_ext(st, &hPrivateData->acState, (const UWord16*) cumulativeFrequencyTable); + ari_decode_14bits_s27_ext(st, &val, &hPrivateData->acState, cumulativeFrequencyTable); /* meaning of the values of val: */ /* esc_{0} IGF_MIN_ENC_SEPARATE ... IGF_MAX_ENC_SEPARATE esc_{IGF_SYMBOLS_IN_TABLE - 1} */ - test(); - IF ((val != 0) && (sub(val, IGF_SYMBOLS_IN_TABLE - 1) != 0)) + if ((val != 0) && (val != IGF_SYMBOLS_IN_TABLE - 1)) { - x = add(val, - 1 + IGF_MIN_ENC_SEPARATE); /* (val - 1) + IGF_MIN_ENC_SEPARATE */ + x = (val - 1) + IGF_MIN_ENC_SEPARATE; - x = sub(x, tableOffset); - + x -= tableOffset; return x; } /* decode one of the tails of the distribution */ /* decode extra with 4 bits */ - extra = arith_decode_bits_fx(hPrivateData, st, 4); - IF (sub(extra, 15) == 0) /* escape code 15 to indicate extra >= 15 */ + extra = arith_decode_bits(hPrivateData, st, 4); + if (extra == 15) { + /* escape code 15 to indicate extra >= 15 */ /* decode addtional extra with 6 bits */ - extra = arith_decode_bits_fx(hPrivateData, st, 6); - IF (sub(extra, 63) == 0) /* escape code 63 to indicate extra >= 63 */ + extra_tmp = arith_decode_bits(hPrivateData, st, 6); + if (extra_tmp == 63) { + /* escape code 63 to indicate extra_tmp >= 63 */ /* decode safety extra with 7 bits */ - extra = arith_decode_bits_fx(hPrivateData, st, 7); - extra = add(63, extra); + extra_tmp = 63 + arith_decode_bits(hPrivateData, st, 7); } - extra = add(15, extra); + extra = 15 + extra_tmp; } if (val == 0) { /* escape code 0 to indicate x <= IGF_MIN_ENC_SEPARATE - 1 */ - x = sub(IGF_MIN_ENC_SEPARATE - 1, extra); + x = (IGF_MIN_ENC_SEPARATE - 1) - extra; } - if (sub(val, IGF_SYMBOLS_IN_TABLE - 1) == 0) + else { /* escape code (IGF_SYMBOLS_IN_TABLE - 1) to indicate x >= IGF_MAX_ENC_SEPARATE + 1 */ - x = add(IGF_MAX_ENC_SEPARATE + 1, extra); + x = (IGF_MAX_ENC_SEPARATE + 1) + extra; } - x = sub(x, tableOffset); + x -= tableOffset; return x; } -static void arith_decode_flush_fx( - Decoder_State_fx *st /* i/o: pointer to decoder state */ + +/*---------------------------------------------------------------------* + * arith_decode_flush() + * + * + *---------------------------------------------------------------------*/ + +static void arith_decode_flush( + Decoder_State *st /**< in: pointer to decoder state */ ) { + get_next_indice_tmp(st, -14); /* return back the least significant 14 bits to the bitstream */ - get_next_indice_tmp_fx(st, -14); /* return back the least significant 14 bits to the bitstream */ - + return; } -static void decode_sfe_vector_fx( - IGFSCFDEC_INSTANCE_HANDLE hPrivateData, /* i/o: instance handle */ - Decoder_State_fx *st, /* i/o: pointer to decoder state */ - Word16 t, /* i: counter reset to 0 at each independent block */ - Word16 *prev_x, /* i: previous vector */ - Word16 *x, /* o: current vector to decode */ - Word16 length /* i: number of elements to decode */ + +/*---------------------------------------------------------------------* + * decode_sfe_vector() + * + * + *---------------------------------------------------------------------*/ + +static void decode_sfe_vector( + IGFSCFDEC_INSTANCE_HANDLE hPrivateData, /**< instance handle */ + Decoder_State *st, /**< in: pointer to decoder state */ + int t, /**< frame counter reset to 0 at each independent frame */ + int *prev_x, /**< previous vector */ + int *x, /**< current vector to decode */ + int length /**< number of elements to decode */ ) { /* @@ -181,172 +198,129 @@ static void decode_sfe_vector_fx( | c b | e --> t */ - Word16 f; - Word16 pred; - Word16 res; - Word16 ctx; - Word16 ctx_f; - Word16 ctx_t; - Word16 prev_offset; - Word32 index1; - Word32 index2; + int f; + int pred; + int ctx; + int ctx_f; + int ctx_t; - - FOR (f = 0; f < length; ++f) + for (f = 0; f < length; f++) { - IF (t == 0) + if (t == 0) { - IF (f == 0) + if (f == 0) { - /* (t == 0) && (f == 0) */ /* decode one of the IGF_SYMBOLS_IN_TABLE == 27 alphabet symbols using the new raw AC function */ - res = ari_decode_14bits_s27_ext(st, &hPrivateData->acState, (const UWord16*) hPrivateData->cf_se00); - - pred = arith_decode_bits_fx(hPrivateData, st, 2); /* LSBs as 2 bit raw */ - x[f] = add(shl(res, 2), pred); - move16(); + ari_decode_14bits_s27_ext(st, &pred, &hPrivateData->acState, hPrivateData->cf_se00); + x[f] = pred << 2; + x[f] += arith_decode_bits(hPrivateData, st, 2); /* LSBs as 2 bit raw */ } - ELSE IF (sub(f, 1) == 0) + else if (f == 1) { - /* (t == 0) && (f == 1) */ - res = arith_decode_residual_fx(hPrivateData, - st, - hPrivateData->cf_se01, - hPrivateData->cf_off_se01); - x[f] = add(x[0], res); - move16(); /* f - increment is 0, pred = b */ + pred = x[f - 1]; /* pred = b */ + x[f] = pred + arith_decode_residual( hPrivateData, st, hPrivateData->cf_se01, hPrivateData->cf_off_se01 ); } - ELSE + else { - /* (t == 0) && (f >= 2) */ - prev_offset = sub(f, 1); - ctx = quant_ctx_fx(sub(x[prev_offset], x[sub(prev_offset, 1)])); /* Q(b - e) */ - /* index1 is (IGF_SYMBOLS_IN_TABLE + 1) * (CTX_OFFSET + ctx) */ - index1 = L_mac0((IGF_SYMBOLS_IN_TABLE + 1) * IGF_CTX_OFFSET, (IGF_SYMBOLS_IN_TABLE + 1), ctx); - /* index2 is IGF_CTX_OFFSET + ctx */ - index2 = L_mac0(IGF_CTX_OFFSET, 1, ctx); - res = arith_decode_residual_fx(hPrivateData, - st, - hPrivateData->cf_se02 + index1, - hPrivateData->cf_off_se02[index2]); - x[f] = add(x[prev_offset], res); - move16(); /* pred = b */ + /* f >= 2 */ + pred = x[f - 1]; /* pred = b */ + ctx = quant_ctx(x[f - 1] - x[f - 2]); /* Q(b - e) */ + x[f] = pred + arith_decode_residual( hPrivateData, st, &hPrivateData->cf_se02[(IGF_SYMBOLS_IN_TABLE + 1) * (IGF_CTX_OFFSET + ctx)], + hPrivateData->cf_off_se02[IGF_CTX_OFFSET + ctx] ); } } - ELSE + else { /* t == 1 */ - IF (f == 0) + if (f == 0) { - /* (t == 1) && (f == 0) */ - res = arith_decode_residual_fx(hPrivateData, - st, - hPrivateData->cf_se10, - hPrivateData->cf_off_se10); - x[f] = add(prev_x[f], res); - move16(); /* pred = a */ + pred = prev_x[f]; /* pred = a */ + x[f] = pred + arith_decode_residual( hPrivateData, st, hPrivateData->cf_se10, hPrivateData->cf_off_se10 ); } - ELSE + else { /* (t == 1) && (f >= 1) */ - prev_offset = sub(f, 1); - pred = add(prev_x[f], x[prev_offset]); - pred = sub(pred, prev_x[prev_offset]); /* pred = a + b - c */ - ctx_f = quant_ctx_fx(sub(prev_x[f], prev_x[prev_offset])); /* Q(a - c) */ - ctx_t = quant_ctx_fx(sub(x[prev_offset], prev_x[prev_offset])); /* Q(b - c) */ - /* index1 is (IGF_SYMBOLS_IN_TABLE + 1) * IGF_CTX_COUNT * (IGF_CTX_OFFSET + ctx_t) - + (IGF_SYMBOLS_IN_TABLE + 1) * (IGF_CTX_OFFSET + ctx_f) */ - index1 = L_mac0( - ((IGF_SYMBOLS_IN_TABLE + 1) * IGF_CTX_COUNT + (IGF_SYMBOLS_IN_TABLE + 1)) * IGF_CTX_OFFSET, - (IGF_SYMBOLS_IN_TABLE + 1) * IGF_CTX_COUNT, ctx_t); - index1 = L_mac0(index1, (IGF_SYMBOLS_IN_TABLE + 1), ctx_f); - /* index2 is IGF_CTX_COUNT * (IGF_CTX_OFFSET + ctx_t) + (IGF_CTX_OFFSET + ctx_f) */ - index2 = L_mac0((IGF_CTX_COUNT + 1) * IGF_CTX_OFFSET, IGF_CTX_COUNT, ctx_t); - index2 = L_mac0(index2, 1, ctx_f); - res = arith_decode_residual_fx(hPrivateData, - st, - hPrivateData->cf_se11 + index1, - hPrivateData->cf_off_se11[index2]); - x[f] = add(pred, res); - move16(); + pred = prev_x[f] + x[f - 1] - prev_x[f - 1]; /* pred = a + b - c */ + ctx_f = quant_ctx(prev_x[f] - prev_x[f - 1]); /* Q(a - c) */ + ctx_t = quant_ctx(x[f - 1] - prev_x[f - 1]); /* Q(b - c) */ + x[f] = pred + arith_decode_residual(hPrivateData, st, + &hPrivateData->cf_se11[(IGF_SYMBOLS_IN_TABLE + 1) * IGF_CTX_COUNT * (IGF_CTX_OFFSET + ctx_t) + (IGF_SYMBOLS_IN_TABLE + 1) * (IGF_CTX_OFFSET + ctx_f)], + hPrivateData->cf_off_se11[IGF_CTX_COUNT * (IGF_CTX_OFFSET + ctx_t) + (IGF_CTX_OFFSET + ctx_f)]); } } - - IF( x[f] < 0 ) + if (x[f] < 0) { x[f] = 0; - move16(); st->BER_detect = 1; - move16(); } - - IF (sub(x[f],91) > 0 ) + if (x[f] > 91) { x[f] = 91; - move16(); st->BER_detect = 1; - move16(); } } + return; } -/**********************************************************************/ /** -resets the internal decoder memory (context memory) -**************************************************************************/ + +/*---------------------------------------------------------------------* + * IGFSCFDecoderReset() + * + * resets the internal decoder memory (context memory) + *---------------------------------------------------------------------*/ + void IGFSCFDecoderReset( - IGFSCFDEC_INSTANCE_HANDLE hPublicData /* i/o: handle to public data */ + IGFSCFDEC_INSTANCE_HANDLE hPublicData /**< inout: handle to public data or NULL in case there was no instance created */ ) { - /* reset of coder */ - hPublicData->t = 0; /* indicate that an independent block follows */ + hPublicData->t = 0; /* we do not need to fill hPublicData->prev with zeros, because when t = 0 no previous information is used */ + return; } -/**********************************************************************/ /** -main decoder function -**************************************************************************/ + +/*---------------------------------------------------------------------* + * IGFSCFDecoderDecode() + * + * main IGF decoder function + *---------------------------------------------------------------------*/ + void IGFSCFDecoderDecode( - IGFSCFDEC_INSTANCE_HANDLE hPublicData, /* i/o: handle to public data */ - Decoder_State_fx *st, /* i/o: pointer to decoder state */ - Word16 *sfe, /* o: pointer to an array which will contain the decoded quantized SCFs */ - Word16 indepFlag /* i: 1 if the block is an independent block, 0 otherwise */ + IGFSCFDEC_INSTANCE_HANDLE hPublicData, /**< inout: handle to public data or NULL in case there was no instance created */ + Decoder_State *st, /**< inout: pointer to decoder state */ + int *sfe, /**< out: ptr to an array which will contain the decoded quantized coefficients */ + int indepFlag /**< in: if 1 on input the encoder will be forced to reset, + if 0 on input the encodder will be forced to encode without a reset */ ) { - /* insert data */ - hPublicData->bitsRead = st->next_bit_pos_fx; - move16(); + hPublicData->bitsRead = st->next_bit_pos; ari_start_decoding_14bits(st, &hPublicData->acState); /* start AC decoding */ - /* check if coder needs a reset and do it if necessary */ - IF (indepFlag != 0) + /* check if coder needs a reset and do it if neccessary */ + if (indepFlag) { /* reset of coder */ IGFSCFDecoderReset(hPublicData); } - decode_sfe_vector_fx(hPublicData, - st, - hPublicData->t, - hPublicData->prev, - sfe, - hPublicData->scfCountLongBlock - ); + decode_sfe_vector( hPublicData, st, hPublicData->t, hPublicData->prev, sfe, hPublicData->scfCountLongBlock ); - arith_decode_flush_fx(st); /* finish AC decoding */ + arith_decode_flush(st); /* finish decoding */ /* advance history */ - Copy(sfe, hPublicData->prev, hPublicData->scfCountLongBlock); - hPublicData->t = add(hPublicData->t, 1); + mvi2i(sfe, hPublicData->prev, hPublicData->scfCountLongBlock); + hPublicData->t++; - hPublicData->bitsRead = sub(st->next_bit_pos_fx, hPublicData->bitsRead); + hPublicData->bitsRead = st->next_bit_pos - hPublicData->bitsRead; + return; } diff --git a/src/libs/libevs/lib_dec/init_dec.cpp b/src/libs/libevs/lib_dec/init_dec.cpp new file mode 100644 index 00000000..89c20852 --- /dev/null +++ b/src/libs/libevs/lib_dec/init_dec.cpp @@ -0,0 +1,655 @@ +/*==================================================================================== + EVS Codec 3GPP TS26.443 Nov 13, 2018. Version 12.11.0 / 13.7.0 / 14.3.0 / 15.1.0 + ====================================================================================*/ + +#include "options.h" +#include "cnst.h" +#include "rom_com.h" +#include "prot.h" +#include + + +/*----------------------------------------------------------------------* + * init_decoder() + * + * Initialization of static variables for the decoder + *----------------------------------------------------------------------*/ + +void init_decoder( + Decoder_State *st /* o: Decoder static variables structure */ +) +{ + short i, j; + + /*-----------------------------------------------------------------* + * ACELP core parameters + *-----------------------------------------------------------------*/ + + st->codec_mode = MODE1; + st->last_codec_mode = MODE1; + st->core = ACELP_CORE; + st->L_frame = L_FRAME; + st->extl = -1; + st->total_brate = ACELP_8k00; + st->last_total_brate = -1; + st->last_total_brate_ber = -1; + st->core_brate = ACELP_8k00; + st->ini_frame = 0; + st->bwidth = NB; + st->extl_brate = 0; + + st->last_coder_type = GENERIC; + st->last_L_frame = st->L_frame; + st->last_core_brate = st->core_brate; + st->last_core = -1; + st->prev_last_core = -1; + st->last_hq_core_type = -1; + st->last_extl = st->extl; + + /* LSF initilaizations */ + mvr2r( GEWB_Ave, st->mem_AR, M ); + init_lvq( st->offset_scale1, st->offset_scale2, st->offset_scale1_p, st->offset_scale2_p, st->no_scales, st->no_scales_p ); + + set_f( st->mem_MA, 0, M ); + + set_f( st->dispMem, 0, 8 ); + + /* AMR-WB IO HF synth init */ + hf_synth_amr_wb_init( &st->prev_r, &st->fmerit_w_sm, st->mem_syn_hf, &st->frame_count, &st->ne_min, &st->fmerit_m_sm, &st->voice_fac_amr_wb_hf, + &st->unvoicing, &st->unvoicing_sm, &st->unvoicing_flag, &st->voicing_flag, &st->start_band_old, &st->OptCrit_old ); + + hf_synth_init( st->mem_hp400, st->mem_hf ); + set_f( st->mem_hp_interp, 0, INTERP_3_1_MEM_LEN ); + set_f( st->delay_syn_hf, 0, NS2SA(16000,DELAY_CLDFB_NS) ); + + st->tilt_code = 0.0f; + st->gc_threshold = 0.0f; + st->last_good = UNVOICED_CLAS; + st->clas_dec = UNVOICED_CLAS; + + st->lp_gainp = 0.0f; + st->lp_gainc = 0.0f; + + set_f( st->old_exc, 0, L_EXC_MEM_DEC ); + + /* AVQ pre-quantizer memory */ + st->mem_preemp_preQ = 0.0f; + st->last_nq_preQ = 0; + st->use_acelp_preq = 0; + + st->mem_deemph = 0.0f; + + set_f( st->mem_syn1, 0, M ); + st->mem_deemph_old_syn = 0.0f; + set_f( st->mem_syn2, 0, M ); + st->stab_fac = 0.0f; + st->stab_fac_smooth = 0.0f; + set_f( st->agc_mem2, 0, 2 ); + set_f( st->mem_hp20_out, 0.0f, 4 ); + set_f( st->mem_syn3, 0, M ); + + for (i=0; ipast_qua_en[i] = -14.0f; /* gain quantization memory (used in AMR-WB IO mode) */ + } + + mvr2r( GEWB_Ave, st->lsf_old, M ); + lsf2lsp( st->lsf_old, st->lsp_old, M, INT_FS_12k8 ); + + st->mid_lsf_int = 0; + st->safety_net = 0; + + /* parameters for AC mode (GSC) */ + st->seed_tcx = 15687; + st->GSC_noisy_speech = 0; + st->Last_GSC_noisy_speech_flag = 0; + st->cor_strong_limit = 1; + set_f( st->old_y_gain, 0, MBANDS_GN ); + st->noise_lev = NOISE_LEVEL_SP0; + set_f( st->Last_GSC_spectrum, 0.0f, L_FRAME ); + st->Last_GSC_pit_band_idx = 0; + + set_f( st->lt_ener_per_band, 1.0f, MBANDS_GN ); + set_f( st->last_exc_dct_in, 0, L_FRAME ); + st->last_ener = 0.0f; + set_s( st->last_bitallocation_band, 0, 6 ); + + /* NB post-filter */ + Init_post_filter( &(st->pfstat) ); + st->psf_lp_noise = 0.0f; + + /* FEC */ + st->scaling_flag = 0; + st->lp_ener_FEC_av = 5.0e5f; + st->lp_ener_FEC_max = 5.0e5f; + st->prev_bfi = 0; + st->lp_ener_bfi = 60.0f; + st->old_enr_LP = 0.0f; + st->lp_ener = 0.0f; + st->enr_old = 0.0f; + st->bfi_pitch = (float)L_SUBFR; + st->bfi_pitch_frame = L_FRAME; + set_f( st->mem_syn_clas_estim, 0.0f, L_SYN_MEM_CLAS_ESTIM ); + st->last_con_tcx = 0; + + for (i=0; i<2*NB_SUBFR16k; i++) + { + st->old_pitch_buf[i] = (float)L_SUBFR; + } + + st->upd_cnt = MAX_UPD_CNT; + + mvr2r( GEWB_Ave, st->lsfoldbfi0, M ); + mvr2r( GEWB_Ave, st->lsfoldbfi1, M ); + mvr2r( GEWB_Ave, st->lsf_adaptive_mean, M ); + + st->seed_acelp = RANDOM_INITSEED; + st->seed = RANDOM_INITSEED; + st->nbLostCmpt = 1; + st->decision_hyst = 0; + + /* fast recovery */ + set_f( st->old_exc2, 0, L_EXC_MEM ); + set_f( st->old_syn2, 0, L_EXC_MEM ); + + /* Stationary noise UV modification */ + st->unv_cnt = 0; + st->ge_sm = 10; + st->uv_count = 0; + st->act_count = 3; + mvr2r( st->lsp_old, st->lspold_s, M ); + st->noimix_seed = RANDOM_INITSEED; + st->min_alpha = 1; + st->exc_pe = 0; + + /*-----------------------------------------------------------------* + * LD music post-filter + *-----------------------------------------------------------------*/ + + set_f( st->dct_post_old_exc, 0, DCT_L_POST-OFFSET2 ); + st->LDm_enh_min_ns_gain = (float)pow(10.0f, -12/20.0f); + st->LDm_last_music_flag = 0; + set_f(st->LDm_lt_diff_etot, 0, MAX_LT); + st->LDm_thres[0] = TH_0_MIN; + st->LDm_thres[1] = TH_1_MIN; + st->LDm_thres[2] = TH_2_MIN; + st->LDm_thres[3] = TH_3_MIN; + st->LDm_nb_thr_1 = 0; + st->LDm_nb_thr_3 = 0; + st->LDm_mem_etot = 0.0f; + + for (i = 0; i < VOIC_BINS_HR; i++) + { + st->LDm_enh_lp_gbin[i] = 1.0f; + st->LDm_enh_lf_EO [i] = 0.01f; + } + + for (i = 0; i < MBANDS_GN_LD; i++) + { + st->LDm_bckr_noise[i] = E_MIN; + } + + set_f(st->filt_lfE, 1.0f, DCT_L_POST); + st->last_nonfull_music = 0; + + /*-----------------------------------------------------------------* + * CNG and DTX + *-----------------------------------------------------------------*/ + st->CNG = 0; /* RTXDTX handler CNG=1 nonCNG= 0,*/ + st->prev_ft_speech = 1; /* RXDTX handeler previous frametype flag for G.192 format AMRWB SID_FIRST detection */ + st->cng_seed = RANDOM_INITSEED; + st->cng_ener_seed = RANDOM_INITSEED; + st->cng_ener_seed1 = RANDOM_INITSEED; + st->old_enr_index = -1; + st->Enew = 0.0f; + st->first_CNG = 0; + mvr2r( st->lsp_old, st->lspCNG, M ); + st->last_allow_cn_step = 0; + st->shb_cng_ener = -6.02f; + st->wb_cng_ener = -6.02f; + st->last_wb_cng_ener = -6.02f; + st->last_shb_cng_ener = -6.02f; + st->swb_cng_seed = RANDOM_INITSEED; + st->ho_hist_ptr = -1; + st->ho_sid_bw = 0; + set_f( st->ho_lsp_hist, 0, HO_HIST_SIZE*M ); + set_f( st->ho_ener_hist, 0, HO_HIST_SIZE ); + set_f( st->ho_env_hist, 0, HO_HIST_SIZE*NUM_ENV_CNG ); + st->ho_hist_size = 0; + st->act_cnt = 0; + st->ho_circ_ptr = -1; + set_f( st->ho_lsp_circ, 0, HO_HIST_SIZE*M ); + set_f( st->ho_ener_circ, 0, HO_HIST_SIZE ); + set_f( st->ho_env_circ, 0, HO_HIST_SIZE*NUM_ENV_CNG ); + st->ho_circ_size = 0; + + set_s( st->ho_16k_lsp, 0, HO_HIST_SIZE ); + st->CNG_mode = -1; + st->last_active_brate = ACELP_7k20; + st->last_CNG_L_frame = L_FRAME; + st->act_cnt2 = 0; + st->num_ho = 0; + st->cng_type = -1; + st->last_cng_type = -1; + set_f( st->lp_env, 0.0f, NUM_ENV_CNG ); + set_f( st->exc_mem, 0.0f, 24 ); + set_f( st->exc_mem1, 0.0f, 30 ); + set_f( st->old_env, 0.0f, NUM_ENV_CNG ); + + for ( i=0; ilsp_shb_prev[i] = 0.5f * ((float) i)/((float) LPC_SHB_ORDER); + st->lsp_shb_prev_prev[i] = st->lsp_shb_prev[i]; + } + + st->shb_dtx_count = 0; + st->last_vad = 0; + st->trans_cnt = 0; + st->burst_cnt = 0; + st->last_shb_ener = 0.001f; + + /* HF (6-7kHz) BWE */ + st->seed2 = RANDOM_INITSEED; + + /*-----------------------------------------------------------------* + * HR SWB BWE parameters + *-----------------------------------------------------------------*/ + + set_f( st->t_audio_prev, 0, 2*END_FREQ_BWE_FULL_FB/50 - NUM_NONTRANS_START_FREQ_COEF ); + st->old_is_transient_hr_bwe = 0; + st->bwe_highrate_seed = 12345; + st->mem_EnergyLT = 0.0f; + + /*-----------------------------------------------------------------* + * HQ core parameters + *-----------------------------------------------------------------*/ + + set_f( st->old_out, 0, L_FRAME48k ); + set_f( st->old_outLB, 0, L_FRAME32k ); + set_f( st->old_coeffs, 0, L_FRAME8k ); + set_s(st->old_is_transient, 0, 3); + st->old_bfi_cnt = 0; + set_f( st->old_auOut_2fr, 0, L_FRAME8k*2 ); + set_f( st->old_out_pha[0], 0, N_LEAD_NB ); + set_f( st->old_out_pha[1], 0, N_LEAD_NB ); + st->prev_old_bfi = 0; + st->phase_mat_flag = 0; + st->phase_mat_next = 0; + st->old_Min_ind = 0; + st->diff_energy = 0.f; + set_f( st->oldIMDCTout, 0.f, L_FRAME8k/2 ); + set_f( st->prev_oldauOut, 0.f, L_FRAME8k); + st->stat_mode_out = 0; + st->stat_mode_old = 0; + st->oldHqVoicing=0; + + for( i=0; iynrm_values[i][j] = 0.f; + } + for( j=0; jr_p_values[i][j] = 0.f; + } + } + set_f( st->Norm_gain, 1.f, SFM_N_NB ); + set_f( st->energy_MA_Curr, 100.f, 2 ); + st->HQ_FEC_seed = RANDOM_INITSEED; + set_f( st->delay_buf_out, 0, HQ_DELTA_MAX*HQ_DELAY_COMP ); + set_f( st->previoussynth, 0, L_FRAME48k); + set_f( st->old_synth_sw, 0.0f, NS2SA(48000,FRAME_SIZE_NS-ACELP_LOOK_NS-DELAY_BWE_TOTAL_NS) ); + set_f( st->prev_noise_level, 0.0f, 2 ); + st->prev_R = 0; + set_f( st->prev_coeff_out, 0, L_HQ_WB_BWE ); + set_s( st->prev_SWB_peak_pos, 0, SPT_SHORTEN_SBNUM ); + + /* HQ GENERIC */ + st->hq_generic_seed = RANDOM_INITSEED; + + st->mem_norm[0] = 31; + set_s( st->mem_norm+1, 39, SFM_N_ENV_STAB-1 ); + st->mem_env_delta = 0; + st->no_att_hangover = 0; + st->energy_lt = 300.0f; + + st->HqVoicing = 0; + set_f( st->fer_samples, 0, L_FRAME48k ); + set_f( st->prev_env, 0, SFM_N_WB ); + set_f( st->prev_normq, 0, SFM_N_WB ); + st->prev_hqswb_clas = HQ_NORMAL; + + set_f( st->last_ni_gain, 0, BANDS_MAX ); + set_f( st->last_env, 0, BANDS_MAX ); + st->last_max_pos_pulse = 0; + st->prev_frm_hfe2 = 0; + st->prev_stab_hfe2 = 0; + st->prev_ni_ratio = 0.5f; + set_f(st->prev_En_sb, 0.0f, NB_SWB_SUBBANDS ); + + /* pre-echo reduction */ + reset_preecho_dec( st ); + + /*----------------------------------------------------------------------------------* + * HQ FEC + *----------------------------------------------------------------------------------*/ + + st->old_synthFB = st->synth_history + NS2SA(st->output_Fs, PH_ECU_MEM_NS); + st->prev_good_synth = st->old_synthFB + NS2SA(st->output_Fs, PH_ECU_LOOKAHEAD_NS); + + set_f( st->X_sav, 0.0f, PH_ECU_SPEC_SIZE ); + st->num_p = 0; + st->ph_ecu_active = 0; + st->ni_seed_forfec = 0; + st->last_fec = 0; + st->ph_ecu_HqVoicing = 0; + set_f( st->oldgapsynth, 0.0f, L_FRAME48k ); + st->env_stab = 0.75f; + st->mem_norm_hqfec[0] = 31; + set_s( st->mem_norm_hqfec+1, 39, SFM_N_ENV_STAB-1 ); + st->mem_env_delta_hqfec = 0; + st->env_stab_plc = 0.0f; + set_f( st->env_stab_state_p, 1.0f/NUM_ENV_STAB_PLC_STATES, NUM_ENV_STAB_PLC_STATES ); + st->envstabplc_hocnt = 0; + + set_f( st->mag_chg_1st, 1.0f, LGW_MAX ); + set_f( st->Xavg, 0.0f, LGW_MAX ); + st->beta_mute = BETA_MUTE_FAC_INI; + + set_s( st->prev_sign_switch, 0, HQ_FEC_SIGN_SFM ); + set_s( st->prev_sign_switch_2, 0, HQ_FEC_SIGN_SFM ); + + st->time_offs = 0; + st->ber_occured_in_pvq = 0; + + /*-----------------------------------------------------------------* + * SWB BWE parameters + *-----------------------------------------------------------------*/ + + set_f( st->old_wtda_swb, 0, L_FRAME48k); + set_f( st->old_syn_12k8_16k, 0, NS2SA(16000, DELAY_FD_BWE_ENC_NS) ); + st->prev_mode = NORMAL; + set_f( st->prev_SWB_fenv, 0, SWB_FENV ); + st->prev_Energy = 0.0f; + st->prev_L_swb_norm = 8; + st->Seed = 21211; + st->prev_frica_flag = 0; + set_f( st->mem_imdct, 0, L_FRAME48k ); + st->prev_td_energy = 0.0f; + st->prev_weight = 0.2f; + st->prev_flag = 0; + st->prev_coder_type = GENERIC; + st->last_wb_bwe_ener = 0.0f; + st->tilt_wb = 0.0f; + st->prev_Energy_wb = 0.0f; + + /*-----------------------------------------------------------------* + * TBE parameters + *-----------------------------------------------------------------*/ + + InitSWBdecBuffer( st ); + ResetSHBbuffer_Dec( st ); + + if( st->output_Fs == 48000 ) + { + set_f( st->fbbwe_hpf_mem[0], 0, 4 ); + set_f( st->fbbwe_hpf_mem[1], 0, 4 ); + set_f( st->fbbwe_hpf_mem[2], 0, 4 ); + set_f( st->fbbwe_hpf_mem[3], 0, 4 ); + } + + set_f( st->mem_resamp_HB, 0, INTERP_3_1_MEM_LEN ); + set_f( st->mem_resamp_HB_32k, 0, 2*ALLPASSSECTIONS_STEEP+1 ); + set_f( st->prev_synth_buffer, 0, NS2SA(48000, DELAY_BWE_TOTAL_NS - DELAY_CLDFB_NS) ); + set_f( st->hb_prev_synth_buffer, 0, NS2SA(48000, DELAY_BWE_TOTAL_NS) ); + st->old_bwe_delay = -1; + + st->tilt_mem = 0.0f; + set_f( st->prev_lsf_diff, 0.5f, LPC_SHB_ORDER-2 ); + st->prev_tilt_para = 0.0f; + set_f( st->cur_sub_Aq, 0.0f, M+1 ); + set_f( st->int_3_over_2_tbemem_dec, 0.0f, INTERP_3_2_MEM_LEN ); + set_f( st->interpol_3_2_cng_dec, 0.0f, INTERP_3_2_MEM_LEN ); + + /* TD BWE post-processing */ + st->ptr_mem_stp_swb = st->mem_stp_swb + LPC_SHB_ORDER - 1; + set_f( st->mem_zero_swb, 0, LPC_SHB_ORDER ); + + for( i=0; iswb_lsp_prev_interp[i] = (float)cos( (float)i * EVS_PI / (float)10.0f ); + } + + st->prev1_shb_ener_sf = 1.0f; + st->prev2_shb_ener_sf = 1.0f; + st->prev3_shb_ener_sf = 1.0f; + st->prev_res_shb_gshape = 0.125f; + st->prev_mixFactors = 0.5f; + st->prev_GainShape = 0.0f; + set_f(st->fb_state_lpc_syn, 0, LPC_SHB_ORDER); + st->fb_tbe_demph = 0.0f; + + /*-----------------------------------------------------------------* + * WB/SWB bandwidth switching parameters + *-----------------------------------------------------------------*/ + + st->tilt_swb = 0.0f; + st->prev_ener = 0.0f; + st->prev_ener_shb = 0.0f; + st->prev_enerLH = 0.0f; + st->enerLH = 0.0f; + st->enerLL = 0.0f; + st->prev_enerLL = 0.0f; + st->prev_fractive = 0; + st->prev_bws_cnt = 0; + st->bws_cnt = N_WS2N_FRAMES; + st->bws_cnt1 = N_NS2W_FRAMES; + st->attenu1 = 0.1f; + st->last_inner_frame = L_FRAME8k; + st->last_bwidth = 0; + + st->prev_weight1 = 0.5f; + st->GainFrame_prevfrm = 0.0f; + + /*-----------------------------------------------------------------* + * channel-aware mode parameters + *-----------------------------------------------------------------*/ + + set_f( st->tilt_code_dec, 0.0f, NB_SUBFR16k ); + + st->use_partial_copy = 0; + st->prev_use_partial_copy = 0; + st->rf_flag = 0; + st->rf_flag_last = 0; + st->prev_rf_frame_type = 0; + st->next_coder_type = 0; + + st->rf_target_bits = 0; + + st->rf_indx_nelp_fid = 0; + st->rf_indx_nelp_iG1 = 0; + st->rf_indx_nelp_iG2[0] = 0; + st->rf_indx_nelp_iG2[1] = 0; + st->rf_indx_tbeGainFr = 0; + + /*-----------------------------------------------------------------* + * Improvement of unvoiced and audio signals in AMR-WB IO mode parameters + *-----------------------------------------------------------------*/ + + st->UV_cnt = 30; + st->LT_UV_cnt = 60.0f; + set_f(st->lt_diff_etot, 0, MAX_LT); + st->Last_ener = 0.0f; + set_f(st->old_Aq, 0, NB_SUBFR * (M+1) ); + st->old_Aq[0] = 1.0f; + st->old_Aq[M+1] = 1.0f; + st->old_Aq[2*(M+1)] = 1.0f; + st->old_Aq[3*(M+1)] = 1.0f; + st->lt_voice_fac = 0.0f; + + /*-----------------------------------------------------------------* + * Bass post-filter parameters + *-----------------------------------------------------------------*/ + + bass_psfilter_init( st->pst_old_syn, &(st->pst_mem_deemp_err), &(st->pst_lp_ener) ); + st->bpf_off = 0; + set_s( st->Track_on_hist, 0, L_TRACK_HIST ); + set_s( st->vibrato_hist, 0, L_TRACK_HIST ); + set_f( st->mem_mean_pit, 80, L_TRACK_HIST ); + st->psf_att = 1.0f; + + /*-----------------------------------------------------------------* + * FD BPF & resampling tools parameters + *-----------------------------------------------------------------*/ + + /* open analysis for max. SR 48kHz */ + openCldfb ( &st->cldfbAna, CLDFB_ANALYSIS, 48000); + + /* open analysis BPF for max. SR 16kHz */ + openCldfb ( &st->cldfbBPF, CLDFB_ANALYSIS, 16000); + + /* open synthesis for output SR */ + openCldfb ( &st->cldfbSyn, CLDFB_SYNTHESIS, st->output_Fs); + + st->last_active_bandsToZero_bwdec = 0; + st->flag_NB_bwddec = 0; + st->perc_bwddec = 0.0f; + st->last_flag_filter_NB = 0; + st->active_frame_cnt_bwddec = 0; + st->total_frame_cnt_bwddec = 0; + set_s(st->flag_buffer, 0, 20); + st->avg_nrg_LT = 0.0f; + + /*-----------------------------------------------------------------* + * Noise gate parameters + *-----------------------------------------------------------------*/ + + st->ng_ener_ST = -51.0f; + + st->Last_frame_ener = (float)MAX_32; + st->old_Es_pred = 0; + set_f(st->old_Aq_12_8 + 1, 0, M ); + st->old_Aq_12_8[0] = 1; + + /*-----------------------------------------------------------------* + * SC-VBR parameters + *-----------------------------------------------------------------*/ + + st->FadeScale = 1.0f; + st->last_ppp_mode_dec = 0; + st->old_ppp_mode = 0; + st->ppp_mode_dec = 0; + st->last_nelp_mode_dec = 0; + st->nelp_mode_dec = 0; + st->nelp_dec_seed = 0; + st->firstTime_voiceddec = 1; + st->prev_gain_pit_dec = 0.0f; + st->prev_tilt_code_dec = 0.0f; + st->vbr_hw_BWE_disable_dec = 0; + st->last_vbr_hw_BWE_disable_dec = 0; + set_f( st->old_hb_synth, 0, L_FRAME48k ); + + /* DTFS variables */ + set_f( st->dtfs_dec_a, 0, MAXLAG_WI ); + set_f( st->dtfs_dec_b, 0, MAXLAG_WI ); + st->dtfs_dec_lag = 0; + st->dtfs_dec_nH = 0; + st->dtfs_dec_nH_4kHz = 0; + st->dtfs_dec_upper_cut_off_freq_of_interest = 0; + st->dtfs_dec_upper_cut_off_freq = 0; + st->ph_offset_D = 0; + st->lastLgainD = 0; + st->lastHgainD = 0; + set_f( st->lasterbD, 0, NUM_ERB_WB ); + + /* NELP decoder variables */ + set_f( st->bp1_filt_mem_nb_dec, 0, 14 ); + set_f( st->bp1_filt_mem_wb_dec, 0, 8 ); + set_f( st->shape1_filt_mem_dec, 0, 20 ); + set_f( st->shape2_filt_mem_dec, 0, 20 ); + set_f( st->shape3_filt_mem_dec, 0, 20 ); + + /*-----------------------------------------------------------------* + * Mode 2 initialization + *-----------------------------------------------------------------*/ + + /* IGF */ + st->igf = 0; + memset( &st->hIGFDec, 0, sizeof(st->hIGFDec) ); + st->hIGFDec.igfData.igfInfo.nfSeed = 9733; + + st->enablePlcWaveadjust = 0; + + /* Init Core Decoder */ + open_decoder_LPD( st, st->total_brate, st->bwidth ); + + /* PLC mode initialization */ + st->m_decodeMode = DEC_NO_FRAM_LOSS; + + /* Init bandwidth / frame_type */ + st->m_frame_type = ACTIVE_FRAME; + st->m_old_frame_type = ACTIVE_FRAME; + + resampleCldfb( st->cldfbAna, st->L_frame*50 ); + resampleCldfb( st->cldfbBPF, st->L_frame*50 ); + + /* Create FD_CNG instance */ + createFdCngDec( &st->hFdCngDec ); + + /* Init FD-CNG */ + initFdCngDec( st->hFdCngDec, st->cldfbSyn->scale ); + + st->cngTDLevel = 0.f; + + st->lp_noise = -20.0f; + + st->force_lpd_reset = 0; + + + return; +} + + +/*----------------------------------------------------------------------* + * reset_preecho_dec() + * + * Initialization of static variables for pre-echo + *----------------------------------------------------------------------*/ + +void reset_preecho_dec( + Decoder_State *st /* i/o: Decoder static variables structure */ +) +{ + st->memfilt_lb = 0; + st->mean_prev_hb = 0; + st->smoothmem = 1; + st->mean_prev = 0; + st->mean_prev_nc = 0; + st->wmold_hb = 1; + st->prevflag = 0; + st->pastpre = 0; + + return; +} + + +/*----------------------------------------------------------------------* + * destroy_decoder() + * + * Free memory which was allocated in init_decoder() + *----------------------------------------------------------------------*/ + +void destroy_decoder( + Decoder_State *st /* o: Decoder static variables structure */ +) +{ + /* CLDFB BPF & resampling tools */ + deleteCldfb( &st->cldfbAna ); /* delete analysis for max. SR 16kHz */ + deleteCldfb( &st->cldfbBPF ); /* delete analysis BPF for max. SR 16kHz */ + deleteCldfb( &st->cldfbSyn ); /* delete synthesis for output SR */ + + deleteFdCngDec( &st->hFdCngDec ); + + return; +} diff --git a/src/libs/libevs/lib_dec/init_dec_fx.cpp b/src/libs/libevs/lib_dec/init_dec_fx.cpp deleted file mode 100755 index 6f70bb6a..00000000 --- a/src/libs/libevs/lib_dec/init_dec_fx.cpp +++ /dev/null @@ -1,967 +0,0 @@ -/*==================================================================================== - EVS Codec 3GPP TS26.442 Apr 03, 2018. Version 12.11.0 / 13.6.0 / 14.2.0 - ====================================================================================*/ - -#include "options.h" /* Compilation switches */ -#include "prot_fx.h" -#include "cnst_fx.h" /* Common constants */ -#include "rom_com_fx.h" /* Static table prototypes */ -#include "stl.h" /* required for wmc_tool */ -#include "basop_util.h" - -/*----------------------------------------------------------------------* - * init_decoder() - * - * Initialization of static variables for the decoder - *----------------------------------------------------------------------*/ - -void init_decoder_fx( - Decoder_State_fx *st_fx /* o: Decoder static variables structure */ -) -{ - Word16 i, j; - Word16 f_db, e_db; - Word32 L_tmp; - Word16 newCldfbBands; - - - st_fx->total_num_bits = -1; - move16(); - - /*-----------------------------------------------------------------* - * ACELP core parameters - *-----------------------------------------------------------------*/ - - st_fx->codec_mode = MODE1; - move16(); - st_fx->last_codec_mode = MODE1; - move16(); - st_fx->core_fx = ACELP_CORE; - move16(); - st_fx->L_frame_fx = L_FRAME; - move16(); - st_fx->extl_fx = -1; - move16(); - st_fx->total_brate_fx = 8000; - move16(); - st_fx->last_total_brate_fx = -1; - move16(); - st_fx->last_total_brate_ber_fx = -1; - move32(); - st_fx->core_brate_fx = 8000; - move16(); - st_fx->ini_frame_fx = 0; - move16(); - st_fx->bwidth_fx = NB; - move16(); - st_fx->extl_brate_fx = 0; - move16(); - - - st_fx->last_coder_type_fx = GENERIC; - move16(); - st_fx->last_L_frame_fx = st_fx->L_frame_fx; - move16(); - st_fx->last_core_brate_fx = st_fx->core_brate_fx ; - move16(); - - st_fx->last_core_fx = -1; - move16(); - st_fx->prev_last_core_fx = -1; - st_fx->last_extl_fx = st_fx->extl_fx; - move16(); - st_fx->last_hq_core_type_fx = -1; - move16(); - - /* LSF initilaizations */ - Copy( GEWB_Ave_fx, st_fx->mem_AR_fx, M ); - - init_lvq_fx( st_fx->offset_scale1_fx, st_fx->offset_scale2_fx, st_fx->offset_scale1_p_fx, st_fx->offset_scale2_p_fx, st_fx->no_scales_fx, st_fx->no_scales_p_fx ); - - set16_fx( st_fx->mem_MA_fx, 0, M ); - - st_fx->dm_fx.prev_state = 0; - move16(); /* This corresponds to st_fx->dispMem in FLP */ - st_fx->dm_fx.prev_gain_code = L_deposit_l(0); - FOR(i=2; i<8; i++) - { - st_fx->dm_fx.prev_gain_pit[i-2] = 0; - move16(); - } - - /* HF synth init */ - hf_synth_amr_wb_init_fx( &st_fx->prev_r_fx, &st_fx->fmerit_w_sm_fx, st_fx->mem_syn_hf_fx, - &st_fx->frame_count_fx, &st_fx->ne_min_fx, &st_fx->fmerit_m_sm_fx, &st_fx->voice_fac_amr_wb_hf, - &st_fx->unvoicing_fx, &st_fx->unvoicing_sm_fx, &st_fx->unvoicing_flag_fx, - &st_fx->voicing_flag_fx, &st_fx->start_band_old_fx, &st_fx->OptCrit_old_fx ); - - hf_synth_init_fx( st_fx->mem_hp400_fx, st_fx->mem_hf_fx ); - set16_fx( st_fx->mem_hp_interp_fx, 0, INTERP_3_1_MEM_LEN ); - set16_fx( st_fx->delay_syn_hf_fx, 0, NS2SA_fx2(16000,DELAY_CLDFB_NS) ); - - st_fx->tilt_code_fx = 0; - move16(); - st_fx->gc_threshold_fx = L_deposit_l(0); - st_fx->last_good_fx = UNVOICED_CLAS; - move16(); - st_fx->clas_dec = UNVOICED_CLAS; - move16(); - - st_fx->lp_gainp_fx = 0; - move16(); - st_fx->lp_gainc_fx = 0; - move16(); - - set16_fx( st_fx->old_exc_fx, 0, L_EXC_MEM_DEC ); - - /* AVQ pre-quantizer memory */ - st_fx->mem_preemp_preQ_fx = 0; - move16(); - st_fx->last_nq_preQ_fx = 0; - move16(); - st_fx->use_acelp_preq = 0; - move16(); - - st_fx->mem_deemph_fx = 0; - move16(); - - set16_fx( st_fx->mem_syn1_fx, 0, M ); - st_fx->mem_deemph_old_syn_fx = 0; - move16(); - set16_fx( st_fx->mem_syn2_fx, 0, M ); - st_fx->stab_fac_fx = 0; - move16(); - st_fx->stab_fac_smooth_fx = 0; - move16(); - set16_fx( st_fx->agc_mem_fx, 0, 2 ); - set32_fx( st_fx->L_mem_hp_out_fx, 0, 5 ); - set16_fx( st_fx->mem_syn3_fx, 0, M ); - FOR (i=0; ipast_qua_en_fx[i] = -14336; - move16(); /* Q10; */ /* gain quantization memory (used also in AMR-WB IO mode) */ - } - - Copy( GEWB_Ave_fx, st_fx->lsf_old_fx, M ); - lsf2lsp_fx( st_fx->lsf_old_fx, st_fx->lsp_old_fx, M, INT_FS_FX ); - st_fx->mid_lsf_int_fx = 0; - move16(); - st_fx->safety_net_fx = 0; - move16(); - - /* parameters for AC mode (GSC) */ - st_fx->seed_tcx_fx = 15687; - move16(); /*check if it is Q0*/ - st_fx->GSC_noisy_speech_fx = 0; - move16(); - st_fx->Last_GSC_noisy_speech_flag_fx = 0; - move16(); - st_fx->cor_strong_limit_fx = 1; - move16(); - set16_fx(st_fx->old_y_gain_fx, 0 , MBANDS_GN ); - st_fx->noise_lev_fx = NOISE_LEVEL_SP0; - move16(); - set16_fx( st_fx->Last_GSC_spectrum_fx, 0, L_FRAME ); - st_fx->Last_GSC_pit_band_idx_fx = 0; - move16(); - - set16_fx( st_fx->lt_ener_per_band_fx, 4096, MBANDS_GN );/*Q12*/ - set16_fx( st_fx->last_exc_dct_in_fx, 0, L_FRAME); - st_fx->last_ener_fx = 0; - set16_fx( st_fx->last_bitallocation_band_fx, 0, 6 ); - - /* NB post-filter */ - Init_post_filter( &(st_fx->pfstat) ); - st_fx->psf_lp_noise_fx = 0; - move16(); - - /* FEC */ - st_fx->scaling_flag = 0; - move16(); - st_fx->lp_ener_FEC_av = 500000; - move32(); - st_fx->lp_ener_FEC_max = 500000; - move32(); - st_fx->prev_bfi_fx = 0; - move16(); - st_fx->lp_ener_FER_fx = 15360; - move16(); /*60 in Q8*/ - st_fx->old_enr_LP = 0; - move16(); - st_fx->lp_ener_fx = L_deposit_l(0); - st_fx->enr_old_fx = L_deposit_l(0); - st_fx->bfi_pitch_fx = L_SUBFR_Q6; - move16(); - st_fx->bfi_pitch_frame_fx = L_SUBFR; - move16(); - set16_fx( st_fx->mem_syn_clas_estim_fx, 0, L_SYN_MEM_CLAS_ESTIM ); - st_fx->classifier_Q_mem_syn = 0; - move16(); - st_fx->last_con_tcx = 0; - move16(); - - FOR (i=0; i<2*NB_SUBFR16k; i++) - { - st_fx->old_pitch_buf_fx[i] = L_SUBFR<<16; - move32(); /*15Q16*/ - } - - st_fx->upd_cnt_fx = MAX_UPD_CNT; - move16(); - Copy( GEWB_Ave_fx, st_fx->lsfoldbfi0_fx, M ); - Copy( GEWB_Ave_fx, st_fx->lsfoldbfi1_fx, M ); - Copy( GEWB_Ave_fx, st_fx->lsf_adaptive_mean_fx, M ); - - st_fx->seed_acelp = RANDOM_INITSEED; - move16(); - st_fx->seed_fx = RANDOM_INITSEED; - move16(); - st_fx->nbLostCmpt = 1; - move16(); - st_fx->decision_hyst_fx = 0; - move16(); - - /* fast recovery */ - set16_fx( st_fx->old_exc2_fx, 0, L_EXC_MEM ); - set16_fx( st_fx->old_syn2_fx, 0, L_EXC_MEM ); - - /* Stationary noise UV modification */ - st_fx->unv_cnt_fx = 0; - move16(); - st_fx->ge_sm_fx = L_deposit_l(640); /*Q(GE_SHIFT)*/ - st_fx->uv_count_fx = 0; - move16(); - st_fx->act_count_fx = 3; - move16(); - Copy( st_fx->lsp_old_fx, st_fx->lspold_s_fx, M ); - st_fx->noimix_seed_fx = RANDOM_INITSEED; - move16(); - st_fx->min_alpha_fx = 32767; - move16(); /*1; Q15*/ - st_fx->exc_pe_fx = 0; - move16(); - - st_fx->cng_ener_seed1_fx = RANDOM_INITSEED; - move16(); - set32_fx(st_fx->lp_env_fx, 0, NUM_ENV_CNG); - set16_fx(st_fx->exc_mem_fx, 0, 24); - set16_fx(st_fx->exc_mem1_fx, 0, 30); - set32_fx(st_fx->old_env_fx, 0, NUM_ENV_CNG); - /* LD music post-filter */ - set16_fx(st_fx->dct_post_old_exc_fx, 0, DCT_L_POST-OFFSET2 ); - /*st->LDm_enh_min_ns_gain = (float)pow(10.0f, -12/20.0f);*/ - L_tmp = L_mult(((-12*256)), 5443); /* *0.166096 in Q15 -> Q24 */ - L_tmp = L_shr(L_tmp, 8); /* From Q24 to Q16 */ - f_db = L_Extract_lc(L_tmp, &e_db); /* Extract exponent */ - f_db = extract_l(Pow2(14, f_db)); /* Put 14 as exponent so that */ - e_db = add(e_db, 15-14); - f_db = add(f_db, shr(1,add(e_db,1))); - st_fx->LDm_enh_min_ns_gain_fx = shl(f_db, e_db); - - st_fx->LDm_last_music_flag_fx = 0; - move16(); - set16_fx( st_fx->LDm_lt_diff_etot_fx, 0, MAX_LT ); - - st_fx->LDm_thres_fx[0] = TH_0_MIN_FX; - move16(); - st_fx->LDm_thres_fx[1] = TH_1_MIN_FX; - move16(); - st_fx->LDm_thres_fx[2] = TH_2_MIN_FX; - move16(); - st_fx->LDm_thres_fx[3] = TH_3_MIN_FX; - move16(); - - st_fx->LDm_nb_thr_1_fx = 0; - move16(); - st_fx->LDm_nb_thr_3_fx = 0; - move16(); - st_fx->LDm_mem_etot_fx = 0; - move16(); - - FOR (i = 0; i < VOIC_BINS_HR; i++) - { - st_fx->LDm_enh_lp_gbin_fx[i] = 16384; - move16(); - st_fx->LDm_enh_lf_EO_fx [i] = 328; - move16(); - } - - FOR (i = 0; i < MBANDS_GN_LD; i++) - { - st_fx->LDm_bckr_noise_fx[i] = E_MIN_Q15; - move16(); - } - - set16_fx(st_fx->filt_lfE_fx, 4096, DCT_L_POST); - move16(); - st_fx->last_nonfull_music_fx = 0; - move16(); - st_fx->Old_ener_Q = 0; - move16(); - - /* CNG and DTX */ - st_fx->CNG_fx = 0; - move16(); /* RTXDTX handler CNG=1 nonCNG= 0,*/ - st_fx->prev_ft_speech_fx = 1; - move16(); /* RXDTX handeler previous frametype flag for G.192 format AMRWB SID_FIRST detection */ - st_fx->cng_seed_fx = RANDOM_INITSEED; - move16(); - st_fx->cng_ener_seed_fx = RANDOM_INITSEED; - move16(); - st_fx->old_enr_index_fx = -1; - move16(); - st_fx->Enew_fx = L_deposit_l(0); - st_fx->first_CNG_fx = 0; - move16(); - Copy( st_fx->lsp_old_fx, st_fx->lspCNG_fx, M ); - st_fx->last_allow_cn_step_fx = 0; - move16(); - st_fx->shb_cng_ener_fx = -1541; - move16(); - st_fx->wb_cng_ener_fx = -1541; - move16(); - st_fx->last_wb_cng_ener_fx = -1541; - move16(); - st_fx->last_shb_cng_ener_fx = -1541; - move16(); - st_fx->swb_cng_seed_fx = RANDOM_INITSEED; - move16(); - st_fx->ho_hist_ptr_fx = -1; - move16(); - st_fx->ho_sid_bw_fx = L_deposit_l(0); - set16_fx( st_fx->ho_lsp_hist_fx, 0, HO_HIST_SIZE*M ); - set32_fx( st_fx->ho_ener_hist_fx, 0, HO_HIST_SIZE ); - set32_fx( st_fx->ho_env_hist_fx, 0, HO_HIST_SIZE*NUM_ENV_CNG ); - st_fx->ho_hist_size_fx = 0; - move16(); - st_fx->act_cnt_fx = 0; - move16(); - st_fx->ho_circ_ptr_fx = -1; - move16(); - set16_fx( st_fx->ho_lsp_circ_fx, 0, HO_HIST_SIZE*M ); - set32_fx( st_fx->ho_ener_circ_fx, 0, HO_HIST_SIZE ); - set32_fx( st_fx->ho_env_circ_fx, 0, HO_HIST_SIZE*NUM_ENV_CNG ); - st_fx->ho_circ_size_fx = 0; - move16(); - set16_fx( st_fx->ho_16k_lsp_fx, 0, HO_HIST_SIZE ); - st_fx->CNG_mode_fx = -1; - move16(); - st_fx->last_active_brate_fx = ACELP_7k20; - move32(); - st_fx->last_CNG_L_frame_fx = L_FRAME; - move16(); - st_fx->act_cnt2_fx = 0; - move16(); - st_fx->num_ho_fx = 0; - move16(); - st_fx->cng_type_fx = -1; - move16(); - st_fx->last_cng_type_fx = -1; - move16(); - - FOR ( i=0; ilsp_shb_prev_fx[i] = lsp_shb_prev_tbl_fx[i]; - st_fx->lsp_shb_prev_prev_fx[i] = st_fx->lsp_shb_prev_fx[i]; - } - - st_fx->shb_dtx_count_fx = 0; - move16(); - st_fx->last_vad_fx = 0; - move16(); - st_fx->trans_cnt_fx = 0; - move16(); - st_fx->burst_cnt_fx = 0; - move16(); - st_fx->last_shb_ener_fx = 0; - move16(); - - /* HF (6-7kHz) BWE */ - st_fx->seed2_fx = RANDOM_INITSEED; - move16(); - st_fx->Q_stat_noise_ge = GE_SHIFT; - move16(); - st_fx->cngTDLevel = 0; - move16(); - st_fx->cngTDLevel_e = 0; - move16(); - - /*-----------------------------------------------------------------* - * HR SWB BWE parameters - *-----------------------------------------------------------------*/ - - set16_fx( st_fx->t_audio_prev_fx, 0, 2*END_FREQ_BWE_FULL_FB/50 - NUM_NONTRANS_START_FREQ_COEF ); - set16_fx( st_fx->t_audio_prev_fx_exp, 0, NUM_TIME_SWITCHING_BLOCKS ); /* one exp per switching block */ - st_fx->old_is_transient_hr_bwe_fx = 0; - move16(); - st_fx->bwe_highrate_seed_fx = 12345; - move16(); - - st_fx->L_mem_EnergyLT_fx = L_deposit_h(16384); - st_fx->mem_EnergyLT_fx_exp = 40; - move16(); /* set to a high exponent */ - - - /*-----------------------------------------------------------------* - * HQ core parameters - *-----------------------------------------------------------------*/ - - set16_fx( st_fx->old_out_fx, 0, L_FRAME48k ); - set16_fx( st_fx->old_out_LB_fx, 0, L_FRAME32k ); - set32_fx( st_fx->old_coeffs_fx, 0, L_FRAME8k ); - st_fx->Q_old_wtda = 15; - move16(); - st_fx->Q_old_postdec = 0; - move16(); - st_fx->Qprev_synth_buffer_fx = 15; - move16(); - set16_fx( st_fx->old_is_transient_fx, 0, 3 ); - st_fx->old_bfi_cnt_fx = 0; - move16(); - set16_fx(st_fx->old_auOut_2fr_fx, 0, L_FRAME8k*2); - set16_fx(st_fx->old_out_pha_fx[0], 0, N_LEAD_NB); - set16_fx(st_fx->old_out_pha_fx[1], 0, N_LEAD_NB); - st_fx->prev_old_bfi_fx = 0; - move16(); - st_fx->phase_mat_flag_fx = 0; - move16(); - st_fx->phase_mat_next_fx = 0; - move16(); - st_fx->old_Min_ind_fx = 0; - move16(); - st_fx->diff_energy_fx = 0; - move16(); - set32_fx( st_fx->oldIMDCTout_fx, 0, L_FRAME8k/2 ); - set16_fx( st_fx->prev_oldauOut_fx, 0, L_FRAME8k ); - st_fx->stat_mode_out_fx = 0; - move16(); - st_fx->stat_mode_old_fx = 0; - move16(); - st_fx->oldHqVoicing_fx = 0; - move16(); - - FOR( i=0; i ynrm_values_fx[i][j] = 0; - move16(); - } - FOR( j=0; jr_p_values_fx[i][j] = 0; - move16(); - } - } - set16_fx(st_fx->Norm_gain_fx, 1, SFM_N_NB); /*check if it is in Q0 */ - set16_fx(st_fx->energy_MA_Curr_fx, 100, 2);/*check if it is in Q0*/ - st_fx->HQ_FEC_seed_fx = RANDOM_INITSEED; - move16(); - set16_fx( st_fx->delay_buf_out_fx, 0, HQ_DELTA_MAX*HQ_DELAY_COMP ); - set16_fx( st_fx->previoussynth_fx, 0, L_FRAME48k); - set16_fx( st_fx->old_synth_sw_fx, 0, NS2SA(48000,FRAME_SIZE_NS-ACELP_LOOK_NS-DELAY_BWE_TOTAL_NS) ); - set16_fx( st_fx->prev_noise_level_fx, 0, 2 ); - - st_fx->prev_R_fx = 0; - set32_fx( st_fx->prev_coeff_out_fx, 0, L_HQ_WB_BWE ); - set16_fx(st_fx->prev_SWB_peak_pos_fx, 0, SPT_SHORTEN_SBNUM); - - /* HQ GENERIC */ - st_fx->hq_generic_seed_fx = RANDOM_INITSEED; - move16(); - - st_fx->mem_norm_fx[0] = 31; - move16(); - set16_fx(st_fx->mem_norm_fx+1, 39, SFM_N_ENV_STAB-1); - st_fx->mem_env_delta_fx = 0; - move16(); - st_fx->no_att_hangover_fx = 0; - move16(); - st_fx->energy_lt_fx = 2457600; - move16(); /* 300 in Q13 */ - - st_fx->HqVoicing_fx = 0; - move16(); - set16_fx( st_fx->fer_samples_fx, 0, L_FRAME48k ); - set32_fx( st_fx->prev_env_fx, 0, SFM_N_WB ); - set32_fx( st_fx->prev_normq_fx, 0, SFM_N_WB ); - st_fx->prev_hqswb_clas_fx = HQ_NORMAL; - move16(); - - /* LRMDCT_DELTA_NOISE_INJECT_FX */ - set32_fx( st_fx->last_ni_gain_fx, 0x0L, BANDS_MAX ); - set16_fx( st_fx->last_env_fx, 0, BANDS_MAX ); - st_fx->last_max_pos_pulse_fx = 0; - move16(); - st_fx->prev_frm_hfe2_fx = 0; - move16(); - st_fx->prev_stab_hfe2_fx = 0; - move16(); - st_fx->prev_ni_ratio_fx = 16384; - move16(); /* 0.5 */ - set16_fx( st_fx->prev_En_sb_fx, 0, NB_SWB_SUBBANDS ); - - /* pre-echo reduction */ - reset_preecho_dec_fx( st_fx ); - - - /*----------------------------------------------------------------------------------* - * HQ FEC - *----------------------------------------------------------------------------------*/ - st_fx->old_synthFB_fx = st_fx->synth_history_fx + NS2SA_fx2(st_fx->output_Fs_fx, PH_ECU_MEM_NS); - st_fx->prev_good_synth_fx = st_fx->old_synthFB_fx + NS2SA_fx2(st_fx->output_Fs_fx, PH_ECU_LOOKAHEAD_NS); - set16_fx( st_fx->X_sav_fx, 0, PH_ECU_SPEC_SIZE ); - st_fx->Q_X_sav = 0; - move16(); - st_fx->num_p_fx = 0; - move16(); - st_fx->ph_ecu_active_fx = 0; - move16(); - st_fx->ni_seed_forfec = 0; - move16(); - st_fx->last_fec_fx = 0; - move16(); - st_fx->ph_ecu_HqVoicing_fx = 0; - move16(); - set16_fx( st_fx->oldgapsynth_fx, 0, L_FRAME48k ); - st_fx->env_stab_fx = 0x6000; /* 0.75 (Q15) */ move16(); - st_fx->mem_norm_hqfec_fx[0] = 31; - move16(); - set16_fx(st_fx->mem_norm_hqfec_fx+1, 39, SFM_N_ENV_STAB-1); - st_fx->mem_env_delta_hqfec_fx = 0; - move16(); - st_fx->env_stab_plc_fx = 0; - move16(); - set16_fx( st_fx->env_stab_state_p_fx, INV_NUM_ENV_STAB_PLC_STATES, NUM_ENV_STAB_PLC_STATES ); - st_fx->envstabplc_hocnt_fx = 0; - move16(); - set16_fx(st_fx->mag_chg_1st_fx, 32767, Lgw_max); - set16_fx(st_fx->Xavg_fx, 0, Lgw_max); - st_fx->beta_mute_fx = BETA_MUTE_FAC_INI; - move16(); - set16_fx( st_fx->prev_sign_switch_fx, 0, HQ_FEC_SIGN_SFM ); - set16_fx( st_fx->prev_sign_switch_2_fx, 0, HQ_FEC_SIGN_SFM ); - /* st->ni_seed_forfec = 0; */ - st_fx->time_offs_fx = 0; - move16(); - st_fx->ber_occured_in_pvq = 0; - move16(); - - /*-----------------------------------------------------------------* - * SWB BWE parameters - *-----------------------------------------------------------------*/ - st_fx->old_wtda_wb_fx_exp = 0; - move16(); - set16_fx( st_fx->old_syn_12k8_16k_fx, 0, NS2SA(16000, DELAY_FD_BWE_ENC_NS) ); - set16_fx( st_fx->L_old_wtda_swb_fx, 0, L_FRAME48k ); - st_fx->old_wtda_swb_fx_exp = 0; - move16(); - st_fx->mem_imdct_exp_fx = 0; - move16(); - - st_fx->prev_mode_fx = NORMAL; - move16(); - set16_fx( st_fx->prev_SWB_fenv_fx, 0, SWB_FENV ); - st_fx->prev_Energy_fx = 0; - move16(); - st_fx->prev_L_swb_norm_fx = 8; - move16(); - st_fx->Seed_fx = 21211; - move16(); - st_fx->prev_frica_flag_fx = 0; - move16(); - set16_fx( st_fx->mem_imdct_fx, 0, L_FRAME48k ); - st_fx->prev_td_energy_fx = 0; - move16(); - st_fx->prev_weight_fx = 6554; /*0.2 in Q15*/ move16(); - st_fx->prev_flag_fx = 0; - move16(); - st_fx->prev_coder_type_fx = GENERIC; - move16(); - st_fx->last_wb_bwe_ener_fx = 0; - move16(); - st_fx->prev_hb_synth_fx_exp = 0; - move16(); - st_fx->tilt_wb_fx = 0; - move16(); - - st_fx->prev_Energy_wb_fx = L_deposit_l(0); - - /*-----------------------------------------------------------------* - * TBE parameters - *-----------------------------------------------------------------*/ - - InitSWBdecBuffer_fx( st_fx ); - ResetSHBbuffer_Dec_fx(st_fx); - - IF( L_sub(st_fx->output_Fs_fx,48000) == 0 ) - { - set32_fx( st_fx->fbbwe_hpf_mem_fx[0], 0, 4 ); - set32_fx( st_fx->fbbwe_hpf_mem_fx[1], 0, 4 ); - set32_fx( st_fx->fbbwe_hpf_mem_fx[2], 0, 4 ); - set32_fx( st_fx->fbbwe_hpf_mem_fx[3], 0, 4 ); - set16_fx( st_fx->fbbwe_hpf_mem_fx_Q, 0, 4 ); - } - - set16_fx( st_fx->mem_resamp_HB_fx, 0, INTERP_3_1_MEM_LEN ); - set16_fx( st_fx->mem_resamp_HB_32k_fx, 0, 2*ALLPASSSECTIONS_STEEP+1 ); - set16_fx( st_fx->prev_synth_buffer_fx, 0, NS2SA_fx2(48000, DELAY_BWE_TOTAL_NS - DELAY_CLDFB_NS) ); - set16_fx( st_fx->hb_prev_synth_buffer_fx, 0, NS2SA_fx2(48000, DELAY_BWE_TOTAL_NS) ); - st_fx->old_bwe_delay_fx = -1; /*Q0*/ move16(); - - st_fx->tilt_mem_fx = 0; - move16(); - set16_fx( st_fx->prev_lsf_diff_fx, 16384, LPC_SHB_ORDER-2 ); - st_fx->prev_tilt_para_fx = 0; - move16(); - set16_fx( st_fx->cur_sub_Aq_fx, 0, M+1 ); - set16_fx( st_fx->int_3_over_2_tbemem_dec_fx, 0, INTERP_3_2_MEM_LEN ); - set16_fx( st_fx->interpol_3_2_cng_dec_fx, 0, INTERP_3_2_MEM_LEN ); - - /* TD BWE post-processing */ - st_fx->ptr_mem_stp_swb_fx = st_fx->mem_stp_swb_fx + LPC_SHB_ORDER - 1; - set16_fx(st_fx->mem_zero_swb_fx, 0, LPC_SHB_ORDER); - - FOR ( i=0; iswb_lsp_prev_interp_fx[i] = swb_lsp_prev_interp_init[i]; - move16(); - } - - st_fx->prev1_shb_ener_sf_fx = 32767; /* Q15*/ move16(); - st_fx->prev2_shb_ener_sf_fx = 32767; /* Q15*/ move16(); - st_fx->prev3_shb_ener_sf_fx = 32767; /* Q15*/ move16(); - st_fx->prev_res_shb_gshape_fx = 8192; /* 0.125 in Q14*/ move16(); - st_fx->prev_mixFactors_fx = 16384; /* 0.5 in Q15*/ move16(); - st_fx->prev_GainShape_fx = 0; - move16(); - st_fx->prev_Q_bwe_exc_fb = 51; - move16(); - set16_fx( st_fx->fb_state_lpc_syn_fx, 0, LPC_SHB_ORDER ); - st_fx->fb_tbe_demph_fx = 0; - move16(); - - - /*-----------------------------------------------------------------* - * WB/SWB bandwidth switching parameters - *-----------------------------------------------------------------*/ - - st_fx->tilt_swb_fx = 0; - move16(); - st_fx->prev_ener_fx = L_deposit_l(0); - st_fx->prev_ener_shb_fx = 0; - move16(); - st_fx->prev_enerLH_fx = 0; - move16(); - st_fx->enerLH_fx = L_deposit_l(0); - st_fx->enerLL_fx = L_deposit_l(0); - st_fx->prev_enerLL_fx = 0; - move16(); - st_fx->prev_fractive_fx = 0; - move16(); - st_fx->prev_bws_cnt_fx = 0; - move16(); - st_fx->bws_cnt_fx = N_WS2N_FRAMES; - move16(); - st_fx->bws_cnt1_fx = N_NS2W_FRAMES; - move16(); - st_fx->attenu_fx = 3277; - move16(); - st_fx->last_inner_frame_fx = L_FRAME8k; - move16(); - st_fx->last_bwidth_fx = 0; - move16(); - st_fx->prev_weight1_fx = 16384; - move16(); - - /*-----------------------------------------------------------------* - * channel-aware mode parameters - *-----------------------------------------------------------------*/ - - set16_fx( st_fx->tilt_code_dec_fx, 0, NB_SUBFR16k ); - - st_fx->use_partial_copy = 0; - move16(); - st_fx->prev_use_partial_copy = 0; - move16(); - st_fx->rf_flag = 0; - move16(); - st_fx->rf_flag_last = 0; - st_fx->prev_rf_frame_type = 0; - move16(); - st_fx->next_coder_type = 0; - move16(); - - st_fx->rf_target_bits = 0; - move16(); - - st_fx->rf_indx_nelp_fid = 0; - move16(); - st_fx->rf_indx_nelp_iG1 = 0; - move16(); - st_fx->rf_indx_nelp_iG2[0] = 0; - move16(); - st_fx->rf_indx_nelp_iG2[1] = 0; - move16(); - st_fx->rf_indx_tbeGainFr = 0; - move16(); - - /*-----------------------------------------------------------------* - * Improvement of unvoiced and audio signals in AMR-WB IO mode parameters - *-----------------------------------------------------------------*/ - - st_fx->UV_cnt_fx = 30; - move16(); - st_fx->LT_UV_cnt_fx = (60<<6); - move16(); - set16_fx( st_fx->lt_diff_etot_fx, 0, MAX_LT ); - st_fx->Last_ener_fx = 0; - move16(); - set16_fx(st_fx->old_Aq_fx, 0, 4*(M+1)); - st_fx->old_Aq_fx[0] = 16384; - move16(); - st_fx->old_Aq_fx[M+1] = 16384; - move16(); - st_fx->old_Aq_fx[2*(M+1)] = 16384; - move16(); - st_fx->old_Aq_fx[3*(M+1)] = 16384; - move16(); - st_fx->lt_voice_fac_fx = 0; - move16(); - - - /*-----------------------------------------------------------------* - * Postfilters - *-----------------------------------------------------------------*/ - - bass_psfilter_init_fx( st_fx->pst_old_syn_fx, &(st_fx->pst_mem_deemp_err_fx), &(st_fx->pst_lp_ener_fx) ); - st_fx->bpf_off_fx = 0; - move16(); - set16_fx( st_fx->Track_on_hist_fx, 0, L_TRACK_HIST ); - set16_fx( st_fx->vibrato_hist_fx, 0, L_TRACK_HIST ); - set16_fx( st_fx->mem_mean_pit_fx, 80, L_TRACK_HIST ); - st_fx->psf_att_fx = 32767; - move16(); - - /*-----------------------------------------------------------------* - * FD BPF & resampling tools parameters - *-----------------------------------------------------------------*/ - /* open analysis for max. SR 48kHz */ - openCldfb ( &st_fx->cldfbAna_fx, CLDFB_ANALYSIS, CLDFB_getNumChannels(48000), 320 ); - - /* open analysis BPF for max. SR 16kHz */ - openCldfb ( &st_fx->cldfbBPF_fx, CLDFB_ANALYSIS, CLDFB_getNumChannels(16000), 320 ); - - /* open synthesis for output SR */ - openCldfb ( &st_fx->cldfbSyn_fx, CLDFB_SYNTHESIS, CLDFB_getNumChannels(st_fx->output_Fs_fx), st_fx->output_frame_fx); - - move16(); - move16(); - move16(); - move16(); - move16(); - move16(); - move32(); - st_fx->last_active_bandsToZero_bwdec = 0; - st_fx->flag_NB_bwddec = 0; - st_fx->perc_bwddec = 0; - st_fx->last_flag_filter_NB = 0; - st_fx->active_frame_cnt_bwddec = 0; - st_fx->total_frame_cnt_bwddec = 0; - set16_fx(st_fx->flag_buffer, 0, 20); - st_fx->avg_nrg_LT = 0; - - st_fx->Ng_ener_ST_fx = -13056; - move16(); /*-51 IN Q8*/ - st_fx->Last_frame_ener_fx = MAX_32; - move32(); - st_fx->old_Es_pred_fx = 0; - move16(); - set16_fx(st_fx->old_Aq_12_8_fx + 1, 0, M ); - st_fx->old_Aq_12_8_fx[0] = 4096; - move16(); /*1 in Q12*/ - - /*-----------------------------------------------------------------* - * SC-VBR - *-----------------------------------------------------------------*/ - st_fx->FadeScale_fx = 32767; - move16(); /* Q15*/ - st_fx->last_ppp_mode_dec_fx = 0; - move16(); - st_fx->old_ppp_mode_fx = 0; - move16(); - st_fx->ppp_mode_dec_fx = 0; - move16(); - st_fx->last_nelp_mode_dec_fx = 0; - move16(); - st_fx->nelp_mode_dec_fx = 0; - move16(); - st_fx->nelp_dec_seed_fx = 0; - move16(); - st_fx->firstTime_voiceddec_fx = 1; - move16(); - st_fx->prev_gain_pit_dec_fx = 0; - move16(); - st_fx->prev_tilt_code_dec_fx = 0; - move16(); - st_fx->vbr_hw_BWE_disable_dec_fx = 0; - move16(); - st_fx->last_vbr_hw_BWE_disable_dec_fx = 0; - move16(); - set16_fx( st_fx->old_hb_synth_fx, 0, L_FRAME48k ); - - /* DTFS variables */ - set16_fx( st_fx->dtfs_dec_a_fx, 0, MAXLAG_WI ); - set16_fx( st_fx->dtfs_dec_b_fx, 0, MAXLAG_WI ); - st_fx->dtfs_dec_lag_fx = 0; - move16(); - st_fx->dtfs_dec_nH_fx = 0; - move16(); - st_fx->dtfs_dec_nH_4kHz_fx = 0; - move16(); - st_fx->dtfs_dec_upper_cut_off_freq_of_interest_fx = 0; - move16(); - st_fx->dtfs_dec_upper_cut_off_freq_fx = 0; - move16(); - st_fx->ph_offset_D_fx = 0; - move16(); - st_fx->lastLgainD_fx = 0; - move16(); - st_fx->lastHgainD_fx = 0; - move16(); - set16_fx( st_fx->lasterbD_fx, 0, NUM_ERB_WB ); - st_fx->dtfs_dec_Q = 0; - move16(); - - /* NELP decoder variables */ - set32_fx( st_fx->bp1_filt_mem_nb_dec_fx, 0, 14 ); - set16_fx( st_fx->bp1_filt_mem_wb_dec_fx, 0, 8 ); - set16_fx( st_fx->shape1_filt_mem_dec_fx, 0, 10 ); - set16_fx( st_fx->shape2_filt_mem_dec_fx, 0, 10 ); - set16_fx( st_fx->shape3_filt_mem_dec_fx, 0, 10 ); - /* IGF */ - st_fx->igf = 0; - move16(); - set16_fx( (Word16*)&st_fx->hIGFDec, 0, (sizeof(st_fx->hIGFDec)+1)/sizeof(Word16) ); - st_fx->hIGFDec.igfData.igfInfo.nfSeed = 9733; - move16(); - - st_fx->enablePlcWaveadjust = 0; - move16(); - - /* Init Decoder */ - open_decoder_LPD( st_fx, st_fx->total_brate_fx, st_fx->bwidth_fx); - - st_fx->m_decodeMode = DEC_NO_FRAM_LOSS; - move16(); - st_fx->m_frame_type = ACTIVE_FRAME; - move16(); - st_fx->m_old_frame_type = ACTIVE_FRAME; - move16(); - - - newCldfbBands = CLDFB_getNumChannels(L_mult0(st_fx->L_frame_fx, 50)); - - resampleCldfb( st_fx->cldfbAna_fx, newCldfbBands, st_fx->L_frame_fx, 1 ); - resampleCldfb( st_fx->cldfbBPF_fx, newCldfbBands, st_fx->L_frame_fx, 1 ); - - /* Create FD_CNG instance */ - createFdCngDec(&st_fx->hFdCngDec_fx); - - /* Init FD-CNG */ - initFdCngDec( st_fx->hFdCngDec_fx, st_fx->cldfbSyn_fx->scale ); - - st_fx->lp_noise = -167772160l/*-20.f Q23*/; - st_fx->force_lpd_reset = 0; - move16(); - - /*-----------------------------------------------------------------* - * initialzie Q values - *-----------------------------------------------------------------*/ - - st_fx->memExp1 = 0; - move16(); - st_fx->Q_syn2 = 0; - move16(); - st_fx->Q_exc = 8; - st_fx->prev_Q_exc = 0; - move16(); - st_fx->Q_syn = 0; - move16(); - st_fx->prev_Q_syn = 0; - move16(); - - FOR(i=0; iQ_subfr[i] = 8; - move16(); - } - - /* Previous frame LPC initialization for PPP */ - st_fx->prev_Q_synth = 0; - move16(); - - st_fx->prev_Q_exc_fr = 0; - move16(); - st_fx->prev_Q_syn_fr = 0; - move16(); - - return; - -} - - -/*----------------------------------------------------------------------* - * reset_preecho_dec() - * - * Initialization of static variables for pre-echo - *----------------------------------------------------------------------*/ - -void reset_preecho_dec_fx( - Decoder_State_fx *st_fx /* i/o: Decoder static variables structure */ -) -{ - st_fx->memfilt_lb_fx = 0; - move16(); - st_fx->mean_prev_hb_fx = L_deposit_l(0); - st_fx->smoothmem_fx = 32767; - move16(); - st_fx->mean_prev_fx = L_deposit_l(0); - st_fx->mean_prev_nc_fx = L_deposit_l(0); - st_fx->wmold_hb_fx = 32767; - move16(); - st_fx->prevflag_fx = 0; - move16(); - st_fx->pastpre_fx = 0; - move16(); - - return; -} - - -/*----------------------------------------------------------------------* - * destroy_decoder() - * - * Free memory which was allocated in init_decoder() - *----------------------------------------------------------------------*/ - -void destroy_decoder( - Decoder_State_fx *st_fx /* o: Decoder static variables structure */ -) -{ - - /* CLDFB BPF & resampling tools */ - - /* delete analysis for max. SR 16kHz */ - deleteCldfb(&st_fx->cldfbAna_fx); - - /* delete analysis BPF for max. SR 16kHz */ - deleteCldfb(&st_fx->cldfbBPF_fx); - - /* delete synthesis for output SR */ - deleteCldfb(&st_fx->cldfbSyn_fx); - - deleteFdCngDec( &st_fx->hFdCngDec_fx ); - - return; -} diff --git a/src/libs/libevs/lib_dec/inov_dec.cpp b/src/libs/libevs/lib_dec/inov_dec.cpp new file mode 100644 index 00000000..3cea5784 --- /dev/null +++ b/src/libs/libevs/lib_dec/inov_dec.cpp @@ -0,0 +1,109 @@ +/*==================================================================================== + EVS Codec 3GPP TS26.443 Nov 13, 2018. Version 12.11.0 / 13.7.0 / 14.3.0 / 15.1.0 + ====================================================================================*/ + +#include "options.h" +#include "cnst.h" +#include "prot.h" +#include "rom_com.h" + + +/*----------------------------------------------------------------------* + * inov_decode() + * + * Decode the algebraic innovation and do pitch sharpening + *----------------------------------------------------------------------*/ + +void inov_decode( + Decoder_State *st, /* i/o: decoder state structure */ + const long core_brate, /* i : core bitrate */ + const short Opt_AMR_WB, /* i : flag indicating AMR-WB IO mode */ + const short L_frame, /* i : length of the frame */ + const short coder_type, /* i : coding type */ + const short sharpFlag, /* i : formant sharpening flag */ + const short i_subfr, /* i : subframe index */ + const short tc_subfr, /* i : TC subframe index */ + const float *p_Aq, /* i : LP filter coefficients */ + const float tilt_code, /* i : tilt of the excitation of previous subframe */ + const float pt_pitch, /* i : pointer to current subframe fractional pitch*/ + float *code /* o : algebraic excitation */ +) +{ + short nBits; + float g1, g2; + + if ( L_frame == L_FRAME ) + { + g1 = FORMANT_SHARPENING_G1; + g2 = FORMANT_SHARPENING_G2; + } + else + { + g1 = FORMANT_SHARPENING_G1_16k; + g2 = FORMANT_SHARPENING_G2_16k; + } + + if ( !Opt_AMR_WB ) + { + if( L_frame == L_FRAME ) + { + nBits = FCB_bits_tbl[BIT_ALLOC_IDX(core_brate, coder_type, i_subfr, TC_SUBFR2IDX(tc_subfr))]; + } + else /* L_frame == L_FRAME16k */ + { + nBits = FCB_bits_16kHz_tbl[BIT_ALLOC_IDX_16KHZ(core_brate, coder_type, i_subfr, TC_SUBFR2IDX_16KHZ(tc_subfr))]; + } + + if( nBits == 7 ) + { + dec_acelp_1t64( st, code ); + } + else if( nBits == 12 ) + { + dec_acelp_2t32( st, code ); + } + else + { + dec_acelp_4t64( st, nBits, code, Opt_AMR_WB ); + } + } + else + { + if ( core_brate == ACELP_6k60 ) + { + dec_acelp_2t32( st, code ); + } + else if ( core_brate == ACELP_8k85 ) + { + dec_acelp_4t64( st, 20, code, Opt_AMR_WB ); + } + else if ( core_brate == ACELP_12k65) + { + dec_acelp_4t64( st, 36, code, Opt_AMR_WB ); + } + else if ( core_brate == ACELP_14k25) + { + dec_acelp_4t64( st, 44, code, Opt_AMR_WB ); + } + else if ( core_brate == ACELP_15k85) + { + dec_acelp_4t64( st, 52, code, Opt_AMR_WB ); + } + else if ( core_brate == ACELP_18k25) + { + dec_acelp_4t64( st, 64, code, Opt_AMR_WB ); + } + else if ( core_brate == ACELP_19k85) + { + dec_acelp_4t64( st, 72, code, Opt_AMR_WB ); + } + else + { + dec_acelp_4t64( st, 88, code, Opt_AMR_WB ); + } + } + + cb_shape( 1, 1, 0, sharpFlag, 0, g1, g2, p_Aq, code, tilt_code, pt_pitch ); + + return; +} diff --git a/src/libs/libevs/lib_dec/inov_dec_fx.cpp b/src/libs/libevs/lib_dec/inov_dec_fx.cpp deleted file mode 100755 index 70b9246d..00000000 --- a/src/libs/libevs/lib_dec/inov_dec_fx.cpp +++ /dev/null @@ -1,135 +0,0 @@ -/*==================================================================================== - EVS Codec 3GPP TS26.442 Apr 03, 2018. Version 12.11.0 / 13.6.0 / 14.2.0 - ====================================================================================*/ - -#include "options.h" /* Compilation switches */ -#include "cnst_fx.h" /* Common constants */ -#include "prot_fx.h" /* Function prototypes */ -#include "rom_com_fx.h" /* Static table prototypes */ -#include "stl.h" - -/*======================================================================*/ -/* FUNCTION : inov_decode_fx() */ -/*-----------------------------------------------------------------------*/ -/* PURPOSE : Decode the algebraic innovation and do pitch sharpening */ -/* */ -/*-----------------------------------------------------------------------*/ -/* INPUT ARGUMENTS : */ -/* _ (Word32) core_brate : Core bitrate Q0 */ -/* _ (Word16) Opt_AMR_WB : flag indicating AMR-WB IO mode Q0 */ -/* _ (Word16) L_frame : length of the frame Q0 */ -/* _ (Word16) i_subfr : length of the frame Q0 */ -/* _ (Word16) coder_type : coding type */ -/* _ (Word16) L_subfr : subframe length */ -/* _ (Word16) sharpFlag : formant sharpening flag */ -/* _ (Word16) tc_subfr : TC subframe index */ -/* _ (Word16 *) p_Aq : LP filter coefficients Q12 */ -/* _ (Word16) tilt_code : tilt of the excitation of previous subframe Q15*/ -/* _ (Word16) pt_pitch : current subframe fractional pitch Q6 */ -/*-----------------------------------------------------------------------*/ -/* OUTPUT ARGUMENTS : */ -/* _ (Word16 *[]) code : subframe length Q12 */ -/* _ (Word16 []) index_buf_4T : subframe length */ -/*-----------------------------------------------------------------------*/ -/* INPUT OUTPUT ARGUMENTS */ -/*-----------------------------------------------------------------------*/ - -/*-----------------------------------------------------------------------*/ -/* RETURN ARGUMENTS : */ -/* _ None */ -/*=======================================================================*/ - -void inov_decode_fx( - Decoder_State_fx *st_fx, /* i/o: decoder state structure */ - const Word32 core_brate, /* i : core bitrate */ - const Word16 Opt_AMR_WB, /* i : flag indicating AMR-WB IO mode */ - const Word16 L_frame, /* i : length of the frame */ - const Word16 coder_type, /* i : coding type */ - const Word16 sharpFlag, /* i : formant sharpening flag */ - const Word16 i_subfr, /* i : subframe index */ - const Word16 tc_subfr, /* i : TC subframe index */ - const Word16 *p_Aq, /* i : LP filter coefficients Q12 */ - const Word16 tilt_code, /* i : tilt of the excitation of previous subframe Q15 */ - const Word16 pt_pitch, /* i : pointer to current subframe fractional pitch Q6*/ - Word16 *code /* o : algebraic excitation */ -) -{ - Word16 nBits; - Word16 g1, g2; - - IF( sub(L_frame,L_FRAME) == 0 ) - { - g1 = FORMANT_SHARPENING_G1; - g2 = FORMANT_SHARPENING_G2; - } - ELSE - { - g1 = FORMANT_SHARPENING_G1_16k; - g2 = FORMANT_SHARPENING_G2_16k; - } - - IF ( !Opt_AMR_WB ) - { - IF( sub(L_frame, L_FRAME) == 0) - { - nBits = FCB_bits_tbl[BIT_ALLOC_IDX_fx(core_brate, coder_type, i_subfr, TC_SUBFR2IDX_fx(tc_subfr))]; - move16(); - } - ELSE /* L_frame == L_FRAME16k */ - { - nBits = FCB_bits_16kHz_tbl[BIT_ALLOC_IDX_16KHZ_fx(core_brate, coder_type, i_subfr, TC_SUBFR2IDX_16KHZ_fx(tc_subfr))]; - move16(); - } - IF(sub(nBits,7) == 0) - { - dec_acelp_1t64_fx(st_fx, code); - } - ELSE IF( sub(nBits,12) == 0) - { - dec_acelp_2t32_fx( st_fx, code ); - } - ELSE - { - dec_acelp_4t64_fx( st_fx, nBits, code, Opt_AMR_WB ); - } - } - ELSE - { - IF ( L_sub(core_brate,ACELP_6k60) == 0) - { - dec_acelp_2t32_fx( st_fx, code ); - } - ELSE IF ( L_sub(core_brate,ACELP_8k85) == 0 ) - { - dec_acelp_4t64_fx( st_fx, 20, code, Opt_AMR_WB ); - } - ELSE IF ( L_sub(core_brate,ACELP_12k65) == 0) - { - dec_acelp_4t64_fx( st_fx, 36, code, Opt_AMR_WB ); - } - ELSE IF ( L_sub(core_brate,ACELP_14k25) == 0) - { - dec_acelp_4t64_fx( st_fx, 44, code, Opt_AMR_WB ); - } - ELSE IF ( L_sub(core_brate,ACELP_15k85) == 0) - { - dec_acelp_4t64_fx( st_fx, 52, code, Opt_AMR_WB ); - } - ELSE IF ( L_sub(core_brate,ACELP_18k25) == 0) - { - dec_acelp_4t64_fx( st_fx, 64, code, Opt_AMR_WB ); - } - ELSE IF ( L_sub(core_brate,ACELP_19k85) == 0) - { - dec_acelp_4t64_fx( st_fx, 72, code, Opt_AMR_WB ); - } - ELSE - { - dec_acelp_4t64_fx( st_fx, 88, code, Opt_AMR_WB ); - } - } - - cb_shape_fx( 1, 1, 0, sharpFlag, 0, g1, g2, p_Aq, code, tilt_code, shr(add(pt_pitch,26),6), 0 ); - return; - -} diff --git a/src/libs/libevs/lib_dec/io_dec_fx.cpp b/src/libs/libevs/lib_dec/io_dec.excluded old mode 100755 new mode 100644 similarity index 63% rename from src/libs/libevs/lib_dec/io_dec_fx.cpp rename to src/libs/libevs/lib_dec/io_dec.excluded index 2116f883..d10a569b --- a/src/libs/libevs/lib_dec/io_dec_fx.cpp +++ b/src/libs/libevs/lib_dec/io_dec.excluded @@ -1,73 +1,50 @@ /*==================================================================================== - EVS Codec 3GPP TS26.442 Apr 03, 2018. Version 12.11.0 / 13.6.0 / 14.2.0 + EVS Codec 3GPP TS26.443 Nov 13, 2018. Version 12.11.0 / 13.7.0 / 14.3.0 / 15.1.0 ====================================================================================*/ #include #include #include -#include "options.h" /* Compilation switches */ -#include "stl.h" -#include "cnst_fx.h" /* Common constants */ -#include "prot_fx.h" /* Function prototypes */ -#include "disclaimer.h" /*for disclaimer*/ -#include "basop_util.h" +#include "options.h" +#include "cnst.h" +#include "prot.h" #include "mime.h" -#include -/* WMC_TOOL_SKIP_FILE */ + /*---------------------------------------------------------------------* -* Local functions -*---------------------------------------------------------------------*/ + * Local functions + *---------------------------------------------------------------------*/ static void usage_dec(void); static char *to_upper( char *str ); -static char * bit_rate_to_string(char *string, Word32 bit_rate) -{ - char *src, *dst; - /* NO_DATA is also an allowed bit rate */ - if ( bit_rate <= 0) - { - sprintf(string, "0.00"); - return string; - } - assert(bit_rate >= 100); - src = string + sprintf(string, "%i", bit_rate); - /* Insert a '.' before last two digits and remove last digit */ - /* What we want is to print %.2f of bit_rate/1000.0 */ - dst = src--; - *--dst = *--src; - *--dst = *--src; - *--dst = '.'; - return string; -} /*---------------------------------------------------------------------* * io_ini_dec() * * Processing of command line parameters *---------------------------------------------------------------------*/ -void io_ini_dec_fx( - const int argc, /* i : command line arguments number */ - char *argv[], /* i : command line arguments */ - FILE **f_stream, /* o : input bitstream file */ - FILE **f_synth, /* o : output synthesis file */ - Word16 *quietMode, /* o : limited printouts */ - Word16 *noDelayCmp, /* o : turn off delay compensation */ - Decoder_State_fx *st_fx, /* o : Decoder static variables structure */ +void io_ini_dec( + const int argc, /* i : command line arguments number */ + char *argv[], /* i : command line arguments */ + FILE **f_stream, /* o : input bitstream file */ + FILE **f_synth, /* o : output synthesis file */ + short *quietMode, /* o : limited printouts */ + short *noDelayCmp, /* o : turn off delay compensation */ + Decoder_State *st, /* o : Decoder static variables structure */ #ifdef SUPPORT_JBM_TRACEFILE - char **jbmTraceFileName, /* o : VOIP tracefilename */ + char **jbmTraceFileName, /* o : VOIP tracefilename */ #endif - char **jbmFECoffsetFileName /* : Output file for Optimum FEC offset */ + char **jbmFECoffsetFileName /* : Output file for Optimum FEC offset */ ) { short i; - char stmp[50]; Word16 evs_magic, amrwb_magic; - char bit_rate_string[14]; - print_disclaimer(stderr); + print_disclaimer( stderr ); + + st->writeFECoffset = 0; /*-----------------------------------------------------------------* * Initialization @@ -76,14 +53,17 @@ void io_ini_dec_fx( i = 1; *f_synth = NULL; *f_stream = NULL; - st_fx->Opt_AMR_WB_fx = 0; - st_fx->Opt_VOIP_fx = 0; - set_zero_Word8((Word8 *)stmp, sizeof(stmp)); + *quietMode = 0; + *noDelayCmp = 0; - st_fx->bitstreamformat = G192; - st_fx->amrwb_rfc4867_flag = -1; + st->codec_mode = 0; /* unknown before first frame */ + st->Opt_AMR_WB = 0; + st->Opt_VOIP = 0; - IF ( argc <= 1 ) + st->bitstreamformat = G192; + st->amrwb_rfc4867_flag = -1; + + if ( argc <= 1 ) { usage_dec(); } @@ -92,24 +72,24 @@ void io_ini_dec_fx( * Optional input arguments *-----------------------------------------------------------------*/ - WHILE ( i < argc-3 ) + while ( i < argc-3 ) { /*-----------------------------------------------------------------* * VOIP mode *-----------------------------------------------------------------*/ - IF ( strcmp( to_upper(argv[i]), "-VOIP") == 0) + if ( strcmp( to_upper(argv[i]), "-VOIP") == 0) { - st_fx->Opt_VOIP_fx = 1; - move16(); + st->Opt_VOIP = 1; i += 1; } + #ifdef SUPPORT_JBM_TRACEFILE /*-----------------------------------------------------------------* - * VOIP Tracefile + * VOIP tracefile *-----------------------------------------------------------------*/ - ELSE IF ( strcmp( to_upper(argv[i]), "-TRACEFILE" ) == 0 ) + else if ( strcmp( to_upper(argv[i]), "-TRACEFILE" ) == 0 ) { *jbmTraceFileName = argv[i+1]; i = i + 2; @@ -119,9 +99,9 @@ void io_ini_dec_fx( * FEC offset file *-----------------------------------------------------------------*/ - ELSE IF ( strcmp( to_upper(argv[i]), "-FEC_CFG_FILE" ) == 0 ) + else if ( strcmp( to_upper(argv[i]), "-FEC_CFG_FILE" ) == 0 ) { - st_fx->writeFECoffset = 1; + st->writeFECoffset = 1; *jbmFECoffsetFileName = argv[i+1]; i = i + 2; } @@ -130,10 +110,9 @@ void io_ini_dec_fx( * Quiet mode *-----------------------------------------------------------------*/ - ELSE IF ( strcmp( to_upper(argv[i]), "-Q" ) == 0 ) + else if ( strcmp( to_upper(argv[i]), "-Q" ) == 0 ) { *quietMode = 1; - move16(); i++; } @@ -141,7 +120,7 @@ void io_ini_dec_fx( * deactivate delay compensation *-----------------------------------------------------------------*/ - ELSE IF ( strcmp( to_upper(argv[i]), "-NO_DELAY_CMP" ) == 0 ) + else if( strcmp( to_upper(argv[i]), "-NO_DELAY_CMP" ) == 0 ) { *noDelayCmp = 1; i++; @@ -150,10 +129,10 @@ void io_ini_dec_fx( /*-----------------------------------------------------------------* * MIME input file format *-----------------------------------------------------------------*/ - ELSE IF( strcmp( to_upper(argv[i]), "-MIME" ) == 0 ) + else if( strcmp( to_upper(argv[i]), "-MIME" ) == 0 ) { - st_fx->bitstreamformat = MIME; - st_fx->amrwb_rfc4867_flag = 0; + st->bitstreamformat = MIME; + st->amrwb_rfc4867_flag = 0; i++; } @@ -161,10 +140,12 @@ void io_ini_dec_fx( * Option not recognized *-----------------------------------------------------------------*/ - ELSE + else { - fprintf(stderr, "Error: Unknown option %s\n\n", argv[i]); - usage_dec(); + { + fprintf(stderr, "Error: Unknown option %s\n\n", argv[i]); + usage_dec(); + } } } /* end of while */ @@ -180,8 +161,9 @@ void io_ini_dec_fx( if( i < argc - 2 ) { - st_fx->output_Fs_fx = (int)atoi( argv[i] ) * 1000; - if( st_fx->output_Fs_fx != 8000 && st_fx->output_Fs_fx != 16000 && st_fx->output_Fs_fx != 32000 && st_fx->output_Fs_fx != 48000 ) + st->output_Fs = (int)atoi( argv[i] ) * 1000; + + if( st->output_Fs != 8000 && st->output_Fs != 16000 && st->output_Fs != 32000 && st->output_Fs != 48000 ) { fprintf(stderr, "Error: %d kHz is not a supported sampling rate\n\n", atoi( argv[i] ) ); usage_dec(); @@ -194,6 +176,7 @@ void io_ini_dec_fx( fprintf (stderr, "Error: Sampling rate is not specified\n\n"); usage_dec(); } + /*-----------------------------------------------------------------* * Input bitstream file *-----------------------------------------------------------------*/ @@ -206,7 +189,7 @@ void io_ini_dec_fx( usage_dec(); } /* If MIME/storage format selected, scan for the magic number at the beginning of the bitstream file */ - if( st_fx->bitstreamformat == MIME ) + if( st->bitstreamformat == MIME ) { char buf[13]; evs_magic = 1 ; @@ -217,18 +200,15 @@ void io_ini_dec_fx( fprintf(stderr,"Error: input bitstream file %s cannot be read\n\n", argv[i]); usage_dec(); } - /* verify AMRWB magic number */ if ( strncmp(buf, AMRWB_MAGIC_NUMBER, strlen(AMRWB_MAGIC_NUMBER))) { amrwb_magic = 0; } - - if ( strncmp(buf, EVS_MAGIC_NUMBER, strlen(EVS_MAGIC_NUMBER))) /* strncmp safer than strcmp */ + if ( strncmp(buf, EVS_MAGIC_NUMBER, strlen(EVS_MAGIC_NUMBER))) { evs_magic = 0; } - if( evs_magic != 0 ) { if ((fread(&buf,sizeof(char), 4, *f_stream) != 4 ) || !((buf[3] == 1) && (buf[2] == 0) && (buf[1] == 0) && (buf[0] == 0)) ) @@ -248,19 +228,20 @@ void io_ini_dec_fx( if( evs_magic ) { fprintf( stderr, "Found MIME Magic number %s\n", EVS_MAGIC_NUMBER ); - st_fx->amrwb_rfc4867_flag = 0; + st->amrwb_rfc4867_flag = 0; } else { fprintf( stderr, "Found MIME Magic number %s\n",AMRWB_MAGIC_NUMBER ); - st_fx->amrwb_rfc4867_flag = 1; - st_fx->Opt_AMR_WB_fx = 1; /* needed in case first initial RFC4867 frames/ToCs are lost */ + st->amrwb_rfc4867_flag = 1; + st->Opt_AMR_WB = 1; /* needed in case first initial RFC4867 frames/ToCs are lost */ } } - else if( st_fx->Opt_VOIP_fx == 0 ) + + else if( st->Opt_VOIP == 0 ) { /* G.192 format .... preread the G.192 sync header */ - UWord16 utmp; + unsigned short utmp; if ( fread( &utmp, sizeof(unsigned short), 1, *f_stream ) != 1 ) { /* error during pre-reading */ @@ -274,7 +255,7 @@ void io_ini_dec_fx( } usage_dec(); } - if( (sub(utmp, SYNC_GOOD_FRAME) != 0) && (sub(utmp, SYNC_BAD_FRAME) != 0) ) + if( utmp != SYNC_GOOD_FRAME && utmp != SYNC_BAD_FRAME ) { /* check for a valid first G.192 synch word in Sync Header */ fprintf(stderr, "Error: input bitstream file %s does not have a valid G.192 synch word value \n\n",argv[i]); @@ -285,9 +266,9 @@ void io_ini_dec_fx( } /* JBM format */ - fprintf( stderr, "Input bitstream file: %s\n", argv[i]); - i++; + fprintf( stdout, "Input bitstream file: %s\n", argv[i]); + i++; } else { @@ -315,23 +296,26 @@ void io_ini_dec_fx( fprintf( stderr, "Error: no output synthesis file specified\n\n" ); usage_dec(); } + fprintf( stdout, "\n" ); - if( !st_fx->Opt_VOIP_fx ) + if( !st->Opt_VOIP ) { /*-----------------------------------------------------------------* * Read information from bitstream *-----------------------------------------------------------------*/ - if( st_fx->bitstreamformat == G192 ) + st->ini_frame = 0; /* initialize, since this is needed within read_indices, to correctly set st->last_codec_mode */ + if( st->bitstreamformat == G192 ) { - read_indices_fx( st_fx, *f_stream, 1 ); /* rew_flag == 1 , reads future frames */ + read_indices( st, *f_stream, 1 ); } else { - read_indices_mime( st_fx, *f_stream, 1 ); /* rew_flag == 1 , checks only very first frame */ - if( st_fx->amrwb_rfc4867_flag != 0 ) + st->total_brate=0; /* make sure total_brate is deterministic even if there are no MIME ToCs */ + read_indices_mime( st, *f_stream, 1 ); /* rew_flag == 1 , checks only very first frame */ + if( st->amrwb_rfc4867_flag != 0 ) { - fseek(*f_stream,strlen(AMRWB_MAGIC_NUMBER),SEEK_SET); /* restart after 9 bytes */ + fseek(*f_stream,strlen(AMRWB_MAGIC_NUMBER), SEEK_SET); /* restart after 9 bytes */ } else { @@ -342,35 +326,36 @@ void io_ini_dec_fx( /*-----------------------------------------------------------------* * Print info on screen *-----------------------------------------------------------------*/ + /*-----------------------------------------------------------------* * Print output sampling frequency *-----------------------------------------------------------------*/ - fprintf( stdout, "Output sampling rate: %d Hz\n", st_fx->output_Fs_fx ); + fprintf( stdout, "Output sampling rate: %d Hz\n", st->output_Fs ); /*-----------------------------------------------------------------* * Print bitrate *-----------------------------------------------------------------*/ - fprintf( stdout, "Bitrate: %s kbps\n", bit_rate_to_string(bit_rate_string, st_fx->total_brate_fx) ); - if ( st_fx->total_brate_fx <= 0 ) + fprintf( stdout, "Bitrate: %.2f kbps\n", (float)st->total_brate/1000 ); + + if( st->total_brate <= 0 ) { - if( st_fx->bitstreamformat == G192 ) + if( st->bitstreamformat == G192 ) { fprintf( stdout, "Active Bitrate not identified in bitstream file \n" ); } - else + else /* MIME */ { - /* MIME */ fprintf( stdout, "Active Bitrate not identified from first MIME frame \n" ); } } } - return; } + /*---------------------------------------------------------------------* * to_upper() * @@ -399,28 +384,32 @@ static void usage_dec( void ) fprintf(stdout,"Mandatory parameters:\n"); fprintf(stdout,"---------------------\n"); - fprintf(stdout,"Fs : Output sampling rate in kHz (8, 16, 32 or 48)\n"); - fprintf(stdout,"bitstream_file : Input bitstream filename or RTP packet filename (in VOIP mode)\n"); - fprintf(stdout,"output_file : Output speech filename \n\n"); + fprintf(stdout,"Fs : Output sampling rate in kHz (8, 16, 32 or 48)\n"); + fprintf(stdout,"bitstream_file : Input bitstream filename or RTP packet filename (in VOIP mode)\n"); + fprintf(stdout,"output_file : Output speech filename \n\n"); fprintf(stdout,"Options:\n"); fprintf(stdout,"--------\n"); - fprintf(stdout, "-VOIP : VOIP mode,\n"); -#ifdef SUPPORT_JBM_TRACEFILE - fprintf(stdout, "-Tracefile TF : Generate trace file named TF,\n"); -#endif - fprintf(stdout, "-no_delay_cmp : Turn off delay compensation\n"); - fprintf(stdout, "-fec_cfg_file : Optimal channel aware configuration computed by the JBM \n"); - fprintf(stdout, " as described in Section 6.3.1 of TS26.448. The output is \n"); - fprintf(stdout, " written into a .txt file. Each line contains the FER indicator \n"); - fprintf(stdout, " (HI|LO) and optimal FEC offset. \n"); - fprintf(stdout, "-mime : Mime input bitstream file format\n"); - fprintf(stdout, " The decoder reads both TS26.445 Annex.2.6 and RFC4867 Mime Storage Format,\n"); - fprintf(stdout, " the magic word in the mime input file is used to determine the format.\n"); - fprintf(stdout, " default input bitstream file format is G.192\n"); - fprintf(stdout, "-q : Quiet mode, no frame counter\n"); - fprintf(stdout, " default is OFF\n"); + fprintf(stdout, "-VOIP : VOIP mode\n"); +#ifdef SUPPORT_JBM_TRACEFILE + fprintf(stdout, "-Tracefile TF : Generate trace file named TF\n"); +#endif + fprintf(stdout, "-no_delay_cmp : Turn off delay compensation\n"); + fprintf(stdout, "-fec_cfg_file : Optimal channel aware configuration computed by the JBM \n"); + fprintf(stdout, " as described in Section 6.3.1 of TS26.448. The output is \n"); + fprintf(stdout, " written into a .txt file. Each line contains the FER indicator \n"); + fprintf(stdout, " (HI|LO) and optimal FEC offset. \n"); + + fprintf(stdout, "-mime : Mime bitstream file format\n"); + fprintf(stdout, " The decoder may read both TS26.445 Annex.2.6 and RFC4867 Mime Storage\n"); + fprintf(stdout, " Format files, the magic word in the mime file is used to determine\n"); + fprintf(stdout, " which of the two supported formats is in use.\n"); + fprintf(stdout, " default bitstream file format is G.192\n"); + fprintf(stdout, "-q : Quiet mode, no frame counter\n"); + fprintf(stdout, " default is OFF\n"); fprintf(stdout, "\n"); + exit(-1); } + diff --git a/src/libs/libevs/lib_dec/jbm_jb4_circularbuffer.cpp b/src/libs/libevs/lib_dec/jbm_jb4_circularbuffer.cpp old mode 100755 new mode 100644 index 65468ade..9ec52eb2 --- a/src/libs/libevs/lib_dec/jbm_jb4_circularbuffer.cpp +++ b/src/libs/libevs/lib_dec/jbm_jb4_circularbuffer.cpp @@ -1,5 +1,5 @@ /*==================================================================================== - EVS Codec 3GPP TS26.442 Apr 03, 2018. Version 12.11.0 / 13.6.0 / 14.2.0 + EVS Codec 3GPP TS26.443 Nov 13, 2018. Version 12.11.0 / 13.7.0 / 14.3.0 / 15.1.0 ====================================================================================*/ /** \file jbm_jb4_circularbuffer.c circular buffer (FIFO) with fixed capacity */ @@ -8,12 +8,10 @@ #include #include #include +#include "options.h" /* local includes */ #include "jbm_jb4_circularbuffer.h" /* instrumentation */ -#include "stl.h" -#include "options.h" -#include "basop_util.h" /** Calculates percentile by selecting greatest elements. @@ -23,8 +21,7 @@ * @param[in] capacity maximum number of elements to buffer * @param[in] newElement element to insert in buffer if great enough */ static void JB4_CIRCULARBUFFER_calcPercentile( JB4_CIRCULARBUFFER_ELEMENT *elements, - Word32 *size, Word32 capacity, JB4_CIRCULARBUFFER_ELEMENT newElement ); - + unsigned int *size, unsigned int capacity, JB4_CIRCULARBUFFER_ELEMENT newElement ); /** circular buffer (FIFO) with fixed capacity */ struct JB4_CIRCULARBUFFER @@ -32,30 +29,29 @@ struct JB4_CIRCULARBUFFER /** elements of circular buffer */ JB4_CIRCULARBUFFER_ELEMENT *data; /** maximum allowed number of elements plus one free element (to decide between full/empty buffer) */ - Word16 capacity; + unsigned int capacity; /** position of next enque operation */ - Word16 writePos; + unsigned int writePos; /** position of next deque operation */ - Word16 readPos; + unsigned int readPos; }; /* Creates a circular buffer (FIFO) */ -Word16 JB4_CIRCULARBUFFER_Create( JB4_CIRCULARBUFFER_HANDLE *ph ) +int JB4_CIRCULARBUFFER_Create( JB4_CIRCULARBUFFER_HANDLE *ph ) { - JB4_CIRCULARBUFFER_HANDLE h = (JB4_CIRCULARBUFFER_HANDLE)malloc( sizeof( struct JB4_CIRCULARBUFFER ) ); + JB4_CIRCULARBUFFER_HANDLE h = (JB4_CIRCULARBUFFER*)malloc( sizeof( struct JB4_CIRCULARBUFFER ) ); + h->data = NULL; - move16(); h->capacity = 0; - move16(); h->writePos = 0; - move16(); h->readPos = 0; - move16(); + *ph = h; - move16(); + + return 0; } @@ -64,80 +60,75 @@ void JB4_CIRCULARBUFFER_Destroy( JB4_CIRCULARBUFFER_HANDLE *ph ) { JB4_CIRCULARBUFFER_HANDLE h; - IF( !ph ) - { + + if( !ph ) return; - } h = *ph; - move16(); - IF( !h ) - { + if( !h ) return; - } if( h->data ) free( h->data ); free( h ); *ph = NULL; - move16(); + } /* Initializes a circular buffer (FIFO) with a fixed maximum allowed number of elements */ -Word16 JB4_CIRCULARBUFFER_Init( JB4_CIRCULARBUFFER_HANDLE h, Word16 capacity ) +int JB4_CIRCULARBUFFER_Init( JB4_CIRCULARBUFFER_HANDLE h, unsigned int capacity ) { - /* keep one element free to be able to decide between full/empty buffer */ - capacity = add( capacity, 1 ); + /* keep one element free to be able to decide between full/empty buffer */ + ++capacity; h->data = (JB4_CIRCULARBUFFER_ELEMENT*)malloc( capacity * sizeof( JB4_CIRCULARBUFFER_ELEMENT ) ); h->capacity = capacity; - move16(); h->writePos = 0; - move16(); h->readPos = 0; - move16(); + + return 0; } -Word16 JB4_CIRCULARBUFFER_Enque( JB4_CIRCULARBUFFER_HANDLE h, JB4_CIRCULARBUFFER_ELEMENT element ) +int JB4_CIRCULARBUFFER_Enque( JB4_CIRCULARBUFFER_HANDLE h, JB4_CIRCULARBUFFER_ELEMENT element ) { - IF( JB4_CIRCULARBUFFER_IsFull( h ) ) + if( JB4_CIRCULARBUFFER_IsFull( h ) ) { return -1; } h->data[h->writePos] = element; - move32(); - h->writePos = add( h->writePos, 1 ); - - if( sub( h->capacity, h->writePos ) == 0 ) + ++h->writePos; + if( h->writePos == h->capacity ) { h->writePos = 0; - move16(); } + + + return 0; } -Word16 JB4_CIRCULARBUFFER_Deque( JB4_CIRCULARBUFFER_HANDLE h, JB4_CIRCULARBUFFER_ELEMENT *pElement ) +int JB4_CIRCULARBUFFER_Deque( JB4_CIRCULARBUFFER_HANDLE h, JB4_CIRCULARBUFFER_ELEMENT *pElement ) { - IF( JB4_CIRCULARBUFFER_IsEmpty( h ) ) + if( JB4_CIRCULARBUFFER_IsEmpty( h ) ) { return -1; } *pElement = h->data[h->readPos]; - move32(); - h->readPos = add( h->readPos, 1 ); - - if( sub( h->capacity, h->readPos ) == 0 ) + ++h->readPos; + if( h->readPos == h->capacity ) { h->readPos = 0; - move16(); } + + + return 0; } @@ -146,277 +137,288 @@ JB4_CIRCULARBUFFER_ELEMENT JB4_CIRCULARBUFFER_Front( const JB4_CIRCULARBUFFER_HA { JB4_CIRCULARBUFFER_ELEMENT ret; - ret = L_add(h->data[h->readPos], 0); + + ret = h->data[h->readPos]; + return ret; } /* Returns the last element. */ JB4_CIRCULARBUFFER_ELEMENT JB4_CIRCULARBUFFER_Back( const JB4_CIRCULARBUFFER_HANDLE h ) { - Word16 retPos; + JB4_CIRCULARBUFFER_ELEMENT ret; - retPos = sub( h->writePos, 1 ); - if( h->writePos == 0 ) - retPos = sub( h->capacity, 1 ); - return h->data[ retPos ]; -} + if(h->writePos != 0U) + { + ret = h->data[h->writePos - 1]; + } + else + { + ret = h->data[h->capacity - 1]; + } -Word16 JB4_CIRCULARBUFFER_IsEmpty( const JB4_CIRCULARBUFFER_HANDLE h ) -{ - Word16 ret; - ret = 0; - move16(); - - if( sub( h->readPos, h->writePos ) == 0 ) - ret = 1; - move16(); return ret; } -Word16 JB4_CIRCULARBUFFER_IsFull( const JB4_CIRCULARBUFFER_HANDLE h ) +int JB4_CIRCULARBUFFER_IsEmpty( const JB4_CIRCULARBUFFER_HANDLE h ) { - Word16 ret; - Word16 writePosInc; + int ret; - writePosInc = add( h->writePos, 1 ); - /* check if writePos++ should wrap around */ - if( sub( writePosInc, h->capacity ) == 0 ) - writePosInc = 0; - move16(); - ret = 0; - move16(); - - if( sub( writePosInc, h->readPos ) == 0 ) + if(h->readPos == h->writePos) + { ret = 1; - move16(); + } + else + { + ret = 0; + } + + + return ret; } -Word16 JB4_CIRCULARBUFFER_Size( const JB4_CIRCULARBUFFER_HANDLE h ) +int JB4_CIRCULARBUFFER_IsFull( const JB4_CIRCULARBUFFER_HANDLE h ) { - Word16 ret; + int ret; + + + + if(((h->writePos + 1) % h->capacity) == h->readPos) + { + ret = 1; + } + else + { + ret = 0; + } + + return ret; +} + +unsigned int JB4_CIRCULARBUFFER_Size( const JB4_CIRCULARBUFFER_HANDLE h ) +{ + unsigned int ret; + + + if( h->readPos <= h->writePos ) + { + ret = h->writePos - h->readPos; + } + else + { + /* wrap around */ + ret = h->writePos + h->capacity - h->readPos; + } + - ret = sub( h->writePos, h->readPos ); - /* if wrap around */ - if( ret < 0 ) - ret = add( ret, h->capacity ); return ret; } /* Calculates statistics over all elements: min element */ void JB4_CIRCULARBUFFER_Min( const JB4_CIRCULARBUFFER_HANDLE h, JB4_CIRCULARBUFFER_ELEMENT *pMin ) { - Word16 upperMinElePos, lowerMinElePos; + unsigned int i; + JB4_CIRCULARBUFFER_ELEMENT minEle; - IF( JB4_CIRCULARBUFFER_IsEmpty(h) ) + + /* init output variable */ + minEle = h->data[h->readPos]; + + if( h->readPos <= h->writePos ) { - *pMin = 0; - move32(); - return; - } - BASOP_SATURATE_WARNING_OFF - IF( sub( h->writePos, h->readPos ) > 0 ) - { - /* no wraparound */ + /* no wrap around */ /* calc statistics for [readPos;writePos[ */ - upperMinElePos = findIndexOfMinWord32( &(h->data[h->readPos] ), sub( h->writePos, h->readPos ) ); - *pMin = h->data[ add( h->readPos, upperMinElePos ) ]; - move32(); - } - ELSE - { - /* find min for [readPos;capacity[ */ - upperMinElePos = findIndexOfMinWord32( &(h->data[h->readPos] ), sub( h->capacity, h->readPos ) ); - *pMin = h->data[ add( h->readPos, upperMinElePos ) ]; - move32(); - - /* special case where writePos is pointing to start of buffer then there are actually no values in - * lower region so skip lower region find() (find requires at least two elements in the region) */ - IF( h->writePos == 0 ) + for( i = h->readPos; i != h->writePos; ++i ) { - BASOP_SATURATE_WARNING_ON - return; + if( h->data[i] < minEle ) + { + minEle = h->data[i]; + } } - - /* otherwise find min for [0;writePos[ */ - lowerMinElePos = findIndexOfMinWord32( h->data, h->writePos ); - - if( L_sub( *pMin, h->data[lowerMinElePos] ) > 0 ) - *pMin = h->data[ lowerMinElePos ]; - move32(); } - BASOP_SATURATE_WARNING_ON + else + { + /* wrap around */ + /* calc statistics for [readPos;capacity[ */ + for( i = h->readPos; i != h->capacity; ++i ) + { + if( h->data[i] < minEle ) + { + minEle = h->data[i]; + } + } + /* calc statistics for [0;writePos[ */ + for( i = 0; i != h->writePos; ++i ) + { + if( h->data[i] < minEle ) + { + minEle = h->data[i]; + } + } + } + + *pMin = minEle; + } /* Calculates statistics over all elements: max element */ void JB4_CIRCULARBUFFER_Max( const JB4_CIRCULARBUFFER_HANDLE h, JB4_CIRCULARBUFFER_ELEMENT *pMax ) { - Word16 upperMaxElePos, lowerMaxElePos; + unsigned int i; + JB4_CIRCULARBUFFER_ELEMENT maxEle; - IF( JB4_CIRCULARBUFFER_IsEmpty(h) ) - { - *pMax = 0; - move32(); - return; - } - BASOP_SATURATE_WARNING_OFF - IF( sub( h->writePos, h->readPos ) > 0 ) - { - /* no wraparound */ - /* find max for [readPos;writePos[ */ - upperMaxElePos = findIndexOfMaxWord32( &(h->data[h->readPos] ), sub( h->writePos, h->readPos ) ); - *pMax = h->data[ add( h->readPos, upperMaxElePos ) ]; - move32(); - } - ELSE - { - /* find max for [readPos;capacity[ */ - upperMaxElePos = findIndexOfMaxWord32( &(h->data[h->readPos] ), sub( h->capacity, h->readPos ) ); - *pMax = h->data[ add( h->readPos, upperMaxElePos ) ]; - move32(); - /* special case where writePos is pointing to start of buffer then there are actually no values in - * lower region so skip lower region find() (find requires at least two elements in the region) */ - IF( h->writePos == 0 ) + /* init output variable */ + maxEle = h->data[h->readPos]; + if( h->readPos <= h->writePos ) + { + /* no wrap around */ + /* calc statistics for [readPos;writePos[ */ + for( i = h->readPos; i != h->writePos; ++i ) { - BASOP_SATURATE_WARNING_ON - return; + if( h->data[i] > maxEle ) + { + maxEle = h->data[i]; + } } - - /* otherwise find max for [0;writePos[ */ - lowerMaxElePos = findIndexOfMaxWord32( h->data, h->writePos ); - - if( L_sub( h->data[lowerMaxElePos], *pMax ) > 0 ) - *pMax = h->data[ lowerMaxElePos ]; - move32(); } - BASOP_SATURATE_WARNING_ON + else + { + /* wrap around */ + /* calc statistics for [readPos;capacity[ */ + for( i = h->readPos; i != h->capacity; ++i ) + { + if( h->data[i] > maxEle ) + { + maxEle = h->data[i]; + } + } + /* calc statistics for [0;writePos[ */ + for( i = 0; i != h->writePos; ++i ) + { + if( h->data[i] > maxEle ) + { + maxEle = h->data[i]; + } + } + } + + *pMax = maxEle; + } /* Calculates statistics over a considered fraction of all elements: min element and percentile */ -void JB4_CIRCULARBUFFER_MinAndPercentile( const JB4_CIRCULARBUFFER_HANDLE h, Word32 nElementsToIgnore, +void JB4_CIRCULARBUFFER_MinAndPercentile( const JB4_CIRCULARBUFFER_HANDLE h, unsigned int nElementsToIgnore, JB4_CIRCULARBUFFER_ELEMENT *pMin, JB4_CIRCULARBUFFER_ELEMENT *pPercentile ) { - JB4_CIRCULARBUFFER_ELEMENT minEle; + unsigned int i; JB4_CIRCULARBUFFER_ELEMENT maxElements[100]; - Word32 maxElementsSize; - Word32 maxElementsCapacity; - Word32 i; + unsigned int maxElementsSize; + unsigned int maxElementsCapacity; + JB4_CIRCULARBUFFER_ELEMENT minEle; + /* init output variables */ - minEle = L_add(h->data[h->readPos], 0); + minEle = h->data[h->readPos]; /* To calculate the percentile, a number of elements with the highest values are collected in maxElements in * ascending sorted order. This array has a size of nElementsToIgnore plus one. This additional element is the * lowest of all maxElements, and is called the percentile of all elements. */ - maxElementsSize = L_deposit_l(0); - maxElementsCapacity = L_add( nElementsToIgnore, 1 ); - - - BASOP_SATURATE_WARNING_OFF - IF( L_sub( h->readPos, h->writePos ) <= 0 ) + maxElementsSize = 0; + maxElementsCapacity = nElementsToIgnore + 1; + assert( maxElementsCapacity <= sizeof(maxElements) / sizeof(maxElements[0]) ); + if( h->readPos <= h->writePos ) { /* no wrap around */ /* calc statistics for [readPos;writePos[ */ - FOR( i = h->readPos; i != h->writePos; ++i ) + for( i = h->readPos; i != h->writePos; ++i ) { - if( L_sub( h->data[i], minEle ) < 0 ) + if( h->data[i] < minEle ) { - minEle = L_add(h->data[i], 0); + minEle = h->data[i]; } JB4_CIRCULARBUFFER_calcPercentile( maxElements, &maxElementsSize, maxElementsCapacity, h->data[i] ); } } - ELSE + else { /* wrap around */ /* calc statistics for [readPos;capacity[ */ - FOR( i = h->readPos; i != h->capacity; ++i ) + for( i = h->readPos; i != h->capacity; ++i ) { - if( L_sub( h->data[i], minEle ) < 0 ) + if( h->data[i] < minEle ) { - minEle = L_add(h->data[i], 0); + minEle = h->data[i]; } JB4_CIRCULARBUFFER_calcPercentile( maxElements, &maxElementsSize, maxElementsCapacity, h->data[i] ); } /* calc statistics for [0;writePos[ */ - FOR( i = 0; i != h->writePos; ++i ) + for( i = 0; i != h->writePos; ++i ) { - if( L_sub( h->data[i], minEle ) < 0 ) + if( h->data[i] < minEle ) { - minEle = L_add(h->data[i], 0); + minEle = h->data[i]; } JB4_CIRCULARBUFFER_calcPercentile( maxElements, &maxElementsSize, maxElementsCapacity, h->data[i] ); } } - BASOP_SATURATE_WARNING_ON + *pPercentile = maxElements[0]; - move32(); *pMin = minEle; - move32(); + } /* Calculates percentile by selecting greatest elements. */ static void JB4_CIRCULARBUFFER_calcPercentile( JB4_CIRCULARBUFFER_ELEMENT *elements, - Word32 *size, Word32 capacity, JB4_CIRCULARBUFFER_ELEMENT newElement ) + unsigned int *size, unsigned int capacity, JB4_CIRCULARBUFFER_ELEMENT newElement ) { - Word32 i,j; + unsigned int i; + /* insert newElement if elements buffer is not yet full */ - IF( L_sub( *size, capacity ) < 0 ) + if( *size < capacity ) { - FOR( i = 0; i != *size; ++i ) + for( i = 0; i != *size; ++i ) { - IF( L_sub( newElement, elements[i] ) <= 0 ) + if( newElement <= elements[i] ) { - /* insert newElement at index i (move all elements above insert pos up a place */ - FOR( j = *size; j >= i; --j ) - { - elements[j+1] = elements[j]; - move32(); - } - + /* insert newElement at index i */ + memmove( elements + i + 1, elements + i, ( *size - i ) * sizeof( JB4_CIRCULARBUFFER_ELEMENT ) ); elements[i] = newElement; - move32(); - *size = L_add( *size, 1 ); + ++*size; return; } } /* newElement is maximum, just append it */ elements[*size] = newElement; - move32(); - *size = L_add( *size, 1 ); + ++*size; return; } /* check if newElement is too small to be inserted in elements buffer */ - IF( L_sub( newElement, elements[0] ) <= 0 ) + if( newElement <= elements[0] ) { return; } /* select position to insert newElement to elements */ - FOR( i = *size - 1; i != 0; --i ) + for( i = *size - 1; i != 0; --i ) { - IF( L_sub( newElement, elements[i] ) > 0 ) + if( newElement >= elements[i] ) { - /* insert newElement at index i (move all elements below insert pos down a place)*/ - FOR( j = 0; j < i; j++ ) - { - elements[j] = elements[j+1]; - move32(); - } + /* insert newElement at index i */ + memmove( elements, elements + 1, i * sizeof( JB4_CIRCULARBUFFER_ELEMENT ) ); elements[i] = newElement; - move32(); return; } } /* newElement is just greater than first on in elements buffer */ elements[0] = newElement; - move32(); + } diff --git a/src/libs/libevs/lib_dec/jbm_jb4_circularbuffer.h b/src/libs/libevs/lib_dec/jbm_jb4_circularbuffer.h old mode 100755 new mode 100644 index 8614997e..1e38962a --- a/src/libs/libevs/lib_dec/jbm_jb4_circularbuffer.h +++ b/src/libs/libevs/lib_dec/jbm_jb4_circularbuffer.h @@ -1,40 +1,39 @@ /*==================================================================================== - EVS Codec 3GPP TS26.442 Apr 03, 2018. Version 12.11.0 / 13.6.0 / 14.2.0 + EVS Codec 3GPP TS26.443 Nov 13, 2018. Version 12.11.0 / 13.7.0 / 14.3.0 / 15.1.0 ====================================================================================*/ /** \file jbm_jb4_circularbuffer.h circular buffer (FIFO) with fixed capacity */ #ifndef JBM_JB4_CIRCULARBUFFER_H #define JBM_JB4_CIRCULARBUFFER_H JBM_JB4_CIRCULARBUFFER_H -#include "typedef.h" /** handle for circular buffer (FIFO) with fixed capacity */ typedef struct JB4_CIRCULARBUFFER *JB4_CIRCULARBUFFER_HANDLE; /** type of circular buffer elements */ -typedef Word32 JB4_CIRCULARBUFFER_ELEMENT; +typedef int JB4_CIRCULARBUFFER_ELEMENT; /** Creates a circular buffer (FIFO) * @param[out] ph pointer to created handle * @return 0 if succeeded */ -Word16 JB4_CIRCULARBUFFER_Create( JB4_CIRCULARBUFFER_HANDLE *ph ); +int JB4_CIRCULARBUFFER_Create( JB4_CIRCULARBUFFER_HANDLE *ph ); /** Destroys the circular buffer (FIFO) */ void JB4_CIRCULARBUFFER_Destroy( JB4_CIRCULARBUFFER_HANDLE *ph ); /** Initializes a circular buffer (FIFO) with a fixed maximum allowed number of elements * @param[in] capacity maximum allowed number of elements * @return 0 if succeeded */ -Word16 JB4_CIRCULARBUFFER_Init( JB4_CIRCULARBUFFER_HANDLE h, Word16 capacity ); +int JB4_CIRCULARBUFFER_Init( JB4_CIRCULARBUFFER_HANDLE h, unsigned int capacity ); -Word16 JB4_CIRCULARBUFFER_Enque( JB4_CIRCULARBUFFER_HANDLE h, JB4_CIRCULARBUFFER_ELEMENT element ); -Word16 JB4_CIRCULARBUFFER_Deque( JB4_CIRCULARBUFFER_HANDLE h, JB4_CIRCULARBUFFER_ELEMENT *pElement ); +int JB4_CIRCULARBUFFER_Enque( JB4_CIRCULARBUFFER_HANDLE h, JB4_CIRCULARBUFFER_ELEMENT element ); +int JB4_CIRCULARBUFFER_Deque( JB4_CIRCULARBUFFER_HANDLE h, JB4_CIRCULARBUFFER_ELEMENT *pElement ); /** Returns the first element. */ JB4_CIRCULARBUFFER_ELEMENT JB4_CIRCULARBUFFER_Front( const JB4_CIRCULARBUFFER_HANDLE h ); /** Returns the last element. */ JB4_CIRCULARBUFFER_ELEMENT JB4_CIRCULARBUFFER_Back( const JB4_CIRCULARBUFFER_HANDLE h ); -Word16 JB4_CIRCULARBUFFER_IsEmpty( const JB4_CIRCULARBUFFER_HANDLE h ); -Word16 JB4_CIRCULARBUFFER_IsFull( const JB4_CIRCULARBUFFER_HANDLE h ); -Word16 JB4_CIRCULARBUFFER_Size( const JB4_CIRCULARBUFFER_HANDLE h ); +int JB4_CIRCULARBUFFER_IsEmpty( const JB4_CIRCULARBUFFER_HANDLE h ); +int JB4_CIRCULARBUFFER_IsFull( const JB4_CIRCULARBUFFER_HANDLE h ); +unsigned int JB4_CIRCULARBUFFER_Size( const JB4_CIRCULARBUFFER_HANDLE h ); /** Calculates statistics over all elements: min element * @param[out] pMin minimum element */ @@ -46,7 +45,7 @@ void JB4_CIRCULARBUFFER_Max( const JB4_CIRCULARBUFFER_HANDLE h, JB4_CIRCULARBUFF * @param[in] nElementsToIgnore number of highest elements to ignore for percentile calculation * @param[out] pMin minimum element * @param[out] pPercentile consideredFraction percentile of the highest elements */ -void JB4_CIRCULARBUFFER_MinAndPercentile( const JB4_CIRCULARBUFFER_HANDLE h, Word32 nElementsToIgnore, +void JB4_CIRCULARBUFFER_MinAndPercentile( const JB4_CIRCULARBUFFER_HANDLE h, unsigned int nElementsToIgnore, JB4_CIRCULARBUFFER_ELEMENT *pMin, JB4_CIRCULARBUFFER_ELEMENT *pPercentile ); #endif /* JBM_JB4_CIRCULARBUFFER_H */ diff --git a/src/libs/libevs/lib_dec/jbm_jb4_inputbuffer.cpp b/src/libs/libevs/lib_dec/jbm_jb4_inputbuffer.cpp old mode 100755 new mode 100644 index 2a0e8934..7d21843b --- a/src/libs/libevs/lib_dec/jbm_jb4_inputbuffer.cpp +++ b/src/libs/libevs/lib_dec/jbm_jb4_inputbuffer.cpp @@ -1,18 +1,18 @@ /*==================================================================================== - EVS Codec 3GPP TS26.442 Apr 03, 2018. Version 12.11.0 / 13.6.0 / 14.2.0 + EVS Codec 3GPP TS26.443 Nov 13, 2018. Version 12.11.0 / 13.7.0 / 14.3.0 / 15.1.0 ====================================================================================*/ + /** \file jbm_jb4_inputbuffer.c RTP input buffer with fixed capacity. */ /* system includes */ #include #include #include +#include "options.h" /* instrumentation */ /* local includes */ -#include "options.h" #include "jbm_jb4_inputbuffer.h" -#include "stl.h" /** input buffer with fixed capacity */ @@ -21,35 +21,31 @@ struct JB4_INPUTBUFFER /** elements of input buffer */ JB4_INPUTBUFFER_ELEMENT *data; /** maximum allowed number of elements plus one free element (to decide between full/empty buffer) */ - Word16 capacity; + unsigned int capacity; /** position of next enque operation */ - Word16 writePos; + unsigned int writePos; /** position of next deque operation */ - Word16 readPos; + unsigned int readPos; /** function to compare two elements */ - Word32 (*compareFunction)( const JB4_INPUTBUFFER_ELEMENT first, const JB4_INPUTBUFFER_ELEMENT second, - Word16 *replaceWithNewElementIfEqual ); + int (*compareFunction)( const JB4_INPUTBUFFER_ELEMENT first, const JB4_INPUTBUFFER_ELEMENT second, + bool_t *replaceWithNewElementIfEqual ); }; /* Creates a input buffer */ -Word16 JB4_INPUTBUFFER_Create( JB4_INPUTBUFFER_HANDLE *ph ) +int JB4_INPUTBUFFER_Create( JB4_INPUTBUFFER_HANDLE *ph ) { - JB4_INPUTBUFFER_HANDLE h = (JB4_INPUTBUFFER_HANDLE)malloc( sizeof( struct JB4_INPUTBUFFER ) ); + JB4_INPUTBUFFER_HANDLE h = (JB4_INPUTBUFFER*)malloc( sizeof( struct JB4_INPUTBUFFER ) ); + h->data = NULL; - move16(); h->capacity = 0; - move16(); h->writePos = 0; - move16(); h->readPos = 0; - move16(); h->compareFunction = NULL; - move16(); *ph = h; - move16(); + return 0; } @@ -58,212 +54,167 @@ void JB4_INPUTBUFFER_Destroy( JB4_INPUTBUFFER_HANDLE *ph ) { JB4_INPUTBUFFER_HANDLE h; - IF( !ph ) + if( !ph ) { return; } h = *ph; - move16(); - - IF( !h ) + if( !h ) { return; } - if( h->data ) free( h->data ); free( h ); *ph = NULL; - move16(); + } /* Initializes a input buffer with a fixed maximum allowed number of elements */ -Word16 JB4_INPUTBUFFER_Init( JB4_INPUTBUFFER_HANDLE h, Word16 capacity, - Word32 (*compareFunction)( const JB4_INPUTBUFFER_ELEMENT first, const JB4_INPUTBUFFER_ELEMENT second, - Word16 *replaceWithNewElementIfEqual ) ) +int JB4_INPUTBUFFER_Init( JB4_INPUTBUFFER_HANDLE h, unsigned int capacity, + int (*compareFunction)( const JB4_INPUTBUFFER_ELEMENT first, const JB4_INPUTBUFFER_ELEMENT second, + bool_t *replaceWithNewElementIfEqual ) ) { /* keep one element free to be able to decide between full/empty buffer */ - capacity = add( capacity, 1 ); - h->data = (void**)malloc( L_mult0( capacity, sizeof( JB4_INPUTBUFFER_ELEMENT ) ) ); + ++capacity; + h->data = (JB4_INPUTBUFFER_ELEMENT*)malloc( capacity * sizeof( JB4_INPUTBUFFER_ELEMENT ) ); h->capacity = capacity; - move16(); h->writePos = 0; - move16(); h->readPos = 0; - move16(); h->compareFunction = compareFunction; - move16(); + return 0; } -Word16 JB4_INPUTBUFFER_Enque( JB4_INPUTBUFFER_HANDLE h, JB4_INPUTBUFFER_ELEMENT element, - JB4_INPUTBUFFER_ELEMENT *replacedElement ) +int JB4_INPUTBUFFER_Enque( JB4_INPUTBUFFER_HANDLE h, JB4_INPUTBUFFER_ELEMENT element, + JB4_INPUTBUFFER_ELEMENT *replacedElement ) { - Word16 size; - Word16 low, high, middle; - Word32 diff; - Word16 wrapCheck; - Word16 iterDiff; - Word16 insertPos; - Word16 canMoveRight; - Word16 canMoveLeft; - Word16 replace; - Word16 loopIter; + unsigned int size; + int low, high, middle, diff; + unsigned int insertPos; + unsigned int canMoveRight; + unsigned int canMoveLeft; + bool_t replace; *replacedElement = NULL; - move16(); size = JB4_INPUTBUFFER_Size( h ); - - IF(sub(size, sub(h->capacity, 1)) >= 0) + if(size >= h->capacity - 1) { return -1; } /* appending the first element is straight forward */ - IF( size == 0 ) + if( size == 0U ) { h->data[h->writePos] = element; - move16(); - h->writePos = add( h->writePos, 1 ); - - if( sub( h->writePos, h->capacity ) == 0 ) + ++h->writePos; + if( h->writePos == h->capacity ) { h->writePos = 0; - move16(); } return 0; } /* there's a high probability that the new element can be appended at the back */ - IF( h->compareFunction( element, JB4_INPUTBUFFER_Back( h ), &replace ) > 0 ) + if( h->compareFunction( element, JB4_INPUTBUFFER_Back( h ), &replace ) > 0 ) { h->data[h->writePos] = element; - move16(); - h->writePos = add( h->writePos, 1 ); - - if( sub( h->writePos, h->capacity ) == 0 ) + ++h->writePos; + if( h->writePos == h->capacity ) { h->writePos = 0; - move16(); } return 0; } /* out of order: use binary search to get the position to insert */ low = 0; - move16(); - high = sub( size, 1 ); - - WHILE( ( iterDiff = sub( high, low ) ) >= 0 ) + high = size - 1; + while( low <= high ) { - /* equivalent to: middle = low + ( high - low ) / 2; */ - middle = add( low, shr( iterDiff, 1 ) ); - + middle = low + ( high - low ) / 2; diff = h->compareFunction( element, JB4_INPUTBUFFER_Element( h, middle ), &replace ); - - IF( diff < 0 ) - high = sub( middle, 1 ); - ELSE IF( diff > 0 ) - low = add( middle, 1 ); - ELSE /* an element with same index is already stored */ + if( diff < 0 ) { - IF(replace != 0) + high = middle - 1; + } + else if( diff > 0 ) + { + low = middle + 1; + } + else /* an element with same index is already stored */ + { + if(replace != 0) { - insertPos = add( h->readPos, middle ); - /* check for wrap around and overwrite pos if required (previously used modulo divide) */ - wrapCheck = sub( insertPos, h->capacity ); - if( wrapCheck >= 0 ) - { - insertPos = wrapCheck; - move16(); - } - assert(insertPos == ( h->readPos + middle ) % h->capacity); - *replacedElement = h->data[insertPos]; - move16(); - h->data[insertPos] = element; - move16(); + *replacedElement = h->data[( h->readPos + middle ) % h->capacity]; + h->data[( h->readPos + middle ) % h->capacity] = element; return 0; } return 1; } } - /* the following checks are for debugging only - excluded from instrumentation */ + assert( h->compareFunction( element, JB4_INPUTBUFFER_Element( h, low ), &replace ) != 0 ); + if( low > 0 ) + assert( h->compareFunction( element, JB4_INPUTBUFFER_Element( h, low - 1 ), &replace ) > 0 ); + assert( h->compareFunction( element, JB4_INPUTBUFFER_Element( h, low ), &replace ) < 0 ); + if( (unsigned int)(low + 1) < size ) + assert( h->compareFunction( element, JB4_INPUTBUFFER_Element( h, low + 1 ), &replace ) < 0 ); - insertPos = add( h->readPos, low ); - /* check for wrap around and overwrite pos if required (previously used modulo divide) */ - wrapCheck = sub( insertPos, h->capacity ); - if( wrapCheck >= 0 ) - insertPos = wrapCheck; - move16(); - - canMoveRight = 1; - move16(); - canMoveLeft = h->readPos; - move16(); - - IF( sub( h->readPos, h->writePos ) >= 0 ) + insertPos = ( h->readPos + low ) % h->capacity; + if( h->readPos < h->writePos ) { - canMoveRight = sub( h->writePos, insertPos ); - canMoveLeft = sub( insertPos, h->writePos ); + canMoveRight = 1; + canMoveLeft = h->readPos > 0; + } + else + { + canMoveRight = insertPos < h->writePos; + canMoveLeft = insertPos > h->writePos; } - assert( canMoveRight > 0 || canMoveLeft > 0 ); + assert( canMoveRight != 0 || canMoveLeft != 0 ); (void)canMoveLeft; - - IF( canMoveRight > 0 ) + if( canMoveRight ) { /* move higher elements to the right and insert at insertPos */ - FOR( loopIter = 0; loopIter < h->writePos - insertPos; ++loopIter ) - { - iterDiff = sub( h->writePos, loopIter ); - h->data[ iterDiff ] = h->data[ sub( iterDiff, 1 ) ]; - move16(); - } + memmove( h->data + insertPos + 1, h->data + insertPos, + ( h->writePos - insertPos ) * sizeof( JB4_INPUTBUFFER_ELEMENT ) ); h->data[insertPos] = element; - move16(); - h->writePos = add( h->writePos, 1 ); - - if( sub( h->writePos, h->capacity ) == 0 ) + ++h->writePos; + if( h->writePos == h->capacity ) { h->writePos = 0; - move16(); } } - ELSE + else { /* move lower elements to the left and insert before insertPos */ - FOR( loopIter = 0; loopIter < low; ++loopIter ) - { - iterDiff = add( h->readPos, loopIter ); - h->data[ sub( iterDiff, 1 ) ] = h->data[iterDiff]; - move16(); - } + memmove( h->data + h->readPos - 1, h->data + h->readPos, + low * sizeof( JB4_INPUTBUFFER_ELEMENT ) ); h->data[insertPos-1] = element; - move16(); - h->readPos = sub( h->readPos, 1 ); - assert( h->readPos >= 0 ); + --h->readPos; + assert( h->readPos < 99999 ); } + return 0; } -Word16 JB4_INPUTBUFFER_Deque( JB4_INPUTBUFFER_HANDLE h, JB4_INPUTBUFFER_ELEMENT *pElement ) +int JB4_INPUTBUFFER_Deque( JB4_INPUTBUFFER_HANDLE h, JB4_INPUTBUFFER_ELEMENT *pElement ) { - - IF( JB4_INPUTBUFFER_IsEmpty( h ) ) + if( JB4_INPUTBUFFER_IsEmpty( h ) ) { return -1; } *pElement = h->data[h->readPos]; - h->readPos = add( h->readPos, 1 ); - - if( sub( h->readPos, h->capacity ) == 0 ) + ++h->readPos; + if( h->readPos == h->capacity ) { h->readPos = 0; - move16(); } + return 0; } @@ -272,8 +223,9 @@ JB4_INPUTBUFFER_ELEMENT JB4_INPUTBUFFER_Front( const JB4_INPUTBUFFER_HANDLE h ) { JB4_INPUTBUFFER_ELEMENT ret; + ret = h->data[h->readPos]; - move16(); + return ret; } @@ -282,74 +234,73 @@ JB4_INPUTBUFFER_ELEMENT JB4_INPUTBUFFER_Back( const JB4_INPUTBUFFER_HANDLE h ) { JB4_INPUTBUFFER_ELEMENT ret; - IF( h->writePos != 0 ) + if( h->writePos != 0U ) { - ret = h->data[ sub( h->writePos, 1 ) ]; - move16(); + ret = h->data[h->writePos - 1]; } - ELSE + else { - ret = h->data[ sub( h->capacity, 1 ) ]; - move16(); + ret = h->data[h->capacity - 1]; } + return ret; } /* Returns the element with the given index (0 means front element). */ -JB4_INPUTBUFFER_ELEMENT JB4_INPUTBUFFER_Element( const JB4_INPUTBUFFER_HANDLE h, Word16 index ) +JB4_INPUTBUFFER_ELEMENT JB4_INPUTBUFFER_Element( const JB4_INPUTBUFFER_HANDLE h, unsigned int index ) { JB4_INPUTBUFFER_ELEMENT ret; - Word16 iter; - Word16 wrapCheck; + /* return h->data[(h->readPos + index) % h->capacity] without error handling */ - iter = add( h->readPos, index ); - wrapCheck = sub( iter, h->capacity ); - if( wrapCheck >= 0 ) - iter = wrapCheck; - move16(); - ret = h->data[ iter ]; - move16(); + if( h->readPos + index < h->capacity ) + { + ret = h->data[h->readPos + index]; + } + else + { + /* wrap around */ + ret = h->data[h->readPos + index - h->capacity]; + } + return ret; } -Word16 JB4_INPUTBUFFER_IsEmpty( const JB4_INPUTBUFFER_HANDLE h ) +int JB4_INPUTBUFFER_IsEmpty( const JB4_INPUTBUFFER_HANDLE h ) { - Word16 ret; + int ret; + + ret = h->readPos == h->writePos; + + return ret; +} + +int JB4_INPUTBUFFER_IsFull( const JB4_INPUTBUFFER_HANDLE h ) +{ + int ret; ret = 0; - move16(); - if( sub( h->readPos, h->writePos ) == 0 ) + if( JB4_INPUTBUFFER_Size( h ) == h->capacity - 1 ) { ret = 1; - move16(); } return ret; } -Word16 JB4_INPUTBUFFER_IsFull( const JB4_INPUTBUFFER_HANDLE h ) +unsigned int JB4_INPUTBUFFER_Size( const JB4_INPUTBUFFER_HANDLE h ) { - Word16 ret; + unsigned int ret; - ret = 0; - move16(); - IF( sub( JB4_INPUTBUFFER_Size( h ), sub( h->capacity, 1 )) == 0 ) + if( h->readPos <= h->writePos ) { - ret = 1; - move16(); + ret = h->writePos - h->readPos; } - return ret; -} - -Word16 JB4_INPUTBUFFER_Size( const JB4_INPUTBUFFER_HANDLE h ) -{ - Word16 ret; - - ret = sub( h->writePos, h->readPos ); - - /* wrap around */ - if( sub( h->readPos, h->writePos ) > 0 ) - ret = add( ret, h->capacity ); + else + { + /* wrap around */ + ret = h->writePos + h->capacity - h->readPos; + } + return ret; } diff --git a/src/libs/libevs/lib_dec/jbm_jb4_inputbuffer.h b/src/libs/libevs/lib_dec/jbm_jb4_inputbuffer.h old mode 100755 new mode 100644 index 3456f4c6..585b396f --- a/src/libs/libevs/lib_dec/jbm_jb4_inputbuffer.h +++ b/src/libs/libevs/lib_dec/jbm_jb4_inputbuffer.h @@ -1,15 +1,13 @@ /*==================================================================================== - EVS Codec 3GPP TS26.442 Apr 03, 2018. Version 12.11.0 / 13.6.0 / 14.2.0 + EVS Codec 3GPP TS26.443 Nov 13, 2018. Version 12.11.0 / 13.7.0 / 14.3.0 / 15.1.0 ====================================================================================*/ -/** \file jbm_jb4_inputbuffer.h RTP input buffer with fixed capacity. - \note the buffer and corresponding variables have been designed - and tested up to a maximum 512 elements. */ +/** \file jbm_jb4_inputbuffer.h RTP input buffer with fixed capacity. */ #ifndef JBM_JB4_INPUTBUFFER_H #define JBM_JB4_INPUTBUFFER_H JBM_JB4_INPUTBUFFER_H -#include "typedef.h" +#include "jbm_types.h" /** Handle for RTP input buffer with fixed capacity. */ /** Implemented as priority queue using an array based sorted circular buffer. */ @@ -20,31 +18,31 @@ typedef void* JB4_INPUTBUFFER_ELEMENT; /** Creates a input buffer * @param[out] ph pointer to created handle * @return 0 if succeeded */ -Word16 JB4_INPUTBUFFER_Create( JB4_INPUTBUFFER_HANDLE *ph ); +int JB4_INPUTBUFFER_Create( JB4_INPUTBUFFER_HANDLE *ph ); /** Destroys the input buffer */ void JB4_INPUTBUFFER_Destroy( JB4_INPUTBUFFER_HANDLE *ph ); /** Initializes a input buffer with a fixed maximum allowed number of elements * @param[in] capacity maximum allowed number of elements * @param[in] function to compare two elements: newElement==arrayElement ? 0 : (newElement>arrayElement ? +1 : -1) * @return 0 if succeeded */ -Word16 JB4_INPUTBUFFER_Init( JB4_INPUTBUFFER_HANDLE h, Word16 capacity, - Word32 (*compareFunction)( const JB4_INPUTBUFFER_ELEMENT newElement, const JB4_INPUTBUFFER_ELEMENT arrayElement, - Word16 *replaceWithNewElementIfEqual ) ); +int JB4_INPUTBUFFER_Init( JB4_INPUTBUFFER_HANDLE h, unsigned int capacity, + int (*compareFunction)( const JB4_INPUTBUFFER_ELEMENT newElement, const JB4_INPUTBUFFER_ELEMENT arrayElement, + bool_t *replaceWithNewElementIfEqual ) ); /** Add an element to the buffer. * @return 0 if succeeded, -1 if buffer full, +1 if element with same index already stored. */ -Word16 JB4_INPUTBUFFER_Enque( JB4_INPUTBUFFER_HANDLE h, JB4_INPUTBUFFER_ELEMENT element, JB4_INPUTBUFFER_ELEMENT *replacedElement ); -Word16 JB4_INPUTBUFFER_Deque( JB4_INPUTBUFFER_HANDLE h, JB4_INPUTBUFFER_ELEMENT *pElement ); +int JB4_INPUTBUFFER_Enque( JB4_INPUTBUFFER_HANDLE h, JB4_INPUTBUFFER_ELEMENT element, JB4_INPUTBUFFER_ELEMENT *replacedElement ); +int JB4_INPUTBUFFER_Deque( JB4_INPUTBUFFER_HANDLE h, JB4_INPUTBUFFER_ELEMENT *pElement ); /** Returns the first element. */ JB4_INPUTBUFFER_ELEMENT JB4_INPUTBUFFER_Front( const JB4_INPUTBUFFER_HANDLE h ); /** Returns the last element. */ JB4_INPUTBUFFER_ELEMENT JB4_INPUTBUFFER_Back( const JB4_INPUTBUFFER_HANDLE h ); /** Returns the element with the given index (0 means front element). */ -JB4_INPUTBUFFER_ELEMENT JB4_INPUTBUFFER_Element( const JB4_INPUTBUFFER_HANDLE h, Word16 index ); +JB4_INPUTBUFFER_ELEMENT JB4_INPUTBUFFER_Element( const JB4_INPUTBUFFER_HANDLE h, unsigned int index ); -Word16 JB4_INPUTBUFFER_IsEmpty( const JB4_INPUTBUFFER_HANDLE h ); -Word16 JB4_INPUTBUFFER_IsFull( const JB4_INPUTBUFFER_HANDLE h ); -Word16 JB4_INPUTBUFFER_Size( const JB4_INPUTBUFFER_HANDLE h ); +int JB4_INPUTBUFFER_IsEmpty( const JB4_INPUTBUFFER_HANDLE h ); +int JB4_INPUTBUFFER_IsFull( const JB4_INPUTBUFFER_HANDLE h ); +unsigned int JB4_INPUTBUFFER_Size( const JB4_INPUTBUFFER_HANDLE h ); #endif /* JBM_JB4_INPUTBUFFER_H */ diff --git a/src/libs/libevs/lib_dec/jbm_jb4_jmf.cpp b/src/libs/libevs/lib_dec/jbm_jb4_jmf.cpp old mode 100755 new mode 100644 index c8ab31eb..0761651a --- a/src/libs/libevs/lib_dec/jbm_jb4_jmf.cpp +++ b/src/libs/libevs/lib_dec/jbm_jb4_jmf.cpp @@ -1,5 +1,5 @@ /*==================================================================================== - EVS Codec 3GPP TS26.442 Apr 03, 2018. Version 12.11.0 / 13.6.0 / 14.2.0 + EVS Codec 3GPP TS26.443 Nov 13, 2018. Version 12.11.0 / 13.7.0 / 14.3.0 / 15.1.0 ====================================================================================*/ /** \file jbm_jb4_jmf.cpp jitter measure fifo - a fifo used for windowed measure of network status */ @@ -8,24 +8,22 @@ #include #include #include -/* instrumentation */ #include "options.h" -#include "stl.h" -#include "basop_util.h" /* local includes */ #include "jbm_jb4_jmf.h" #include "jbm_jb4_circularbuffer.h" +/* instrumentation */ /** jitter measure fifo - a fifo used for windowed measure of network status */ struct JB4_JMF { /** scale of system time and RTP time stamps */ - Word16 timeScale; + int timeScale; /** the window size of the fifo as time in sysTimeScale */ - Word16 maxWindowDuration; + unsigned int maxWindowDuration; /** considered fraction in 1/1000 units, e.g. 900 ignores 10% of the highest samples */ - Word16 consideredFraction; + unsigned int consideredFraction; /** fifo containing the delay entries (ordered by receive time) */ JB4_CIRCULARBUFFER_HANDLE fifo; @@ -34,51 +32,43 @@ struct JB4_JMF /** fifo containing the RTP times of the values in offsetFifo (ordered by receive time) */ JB4_CIRCULARBUFFER_HANDLE timeStampFifo; /** flag if the first packet was already pushed */ - Word16 firstPacketPushed; + int firstPacketPushed; /** last packets system time in microseconds */ - Word32 lastSysTime; + int32_t lastSysTime; /** RTP time stamp of the last pushed packet */ - Word32 lastRtpTimeStamp; + int32_t lastRtpTimeStamp; /** last packets calculated delay value */ - Word32 lastDelay; + int32_t lastDelay; /** number of elements to ignore for percentile calculation - value set within init */ - Word16 nElementsToIgnore; - /** maximum delay to avoid overflow by clock drift - value set within init */ - Word32 maxDelay; + int16_t nElementsToIgnore; }; /** helper function to add an entry at back of the buffer */ -static void JB4_JMF_pushBack( JB4_JMF_HANDLE h, Word32 delay, Word32 offset, Word32 time ); +static void JB4_JMF_pushBack( JB4_JMF_HANDLE h, int32_t delay, int32_t offset, uint32_t time ); /** helper function to remove an entry from the front of the buffer */ static void JB4_JMF_popFront( JB4_JMF_HANDLE h ); -Word16 JB4_JMF_Create( JB4_JMF_HANDLE *ph ) +int JB4_JMF_Create( JB4_JMF_HANDLE *ph ) { - JB4_JMF_HANDLE h = (JB4_JMF_HANDLE)malloc( sizeof( struct JB4_JMF ) ); + JB4_JMF_HANDLE h = (JB4_JMF*)malloc( sizeof( struct JB4_JMF ) ); + JB4_CIRCULARBUFFER_Create( &h->fifo ); JB4_CIRCULARBUFFER_Create( &h->offsetFifo ); JB4_CIRCULARBUFFER_Create( &h->timeStampFifo ); h->timeScale = 1000; - move16(); - h->maxWindowDuration = 10000; - move16(); h->consideredFraction = 1000; - move16(); h->firstPacketPushed = 0; - move16(); - h->lastSysTime = L_deposit_l(0); - h->lastRtpTimeStamp = L_deposit_l(0); - h->lastDelay = L_deposit_l(0); + h->lastSysTime = 0; + h->lastRtpTimeStamp = 0; + h->lastDelay = 0; h->nElementsToIgnore = 0; - move16(); - h->maxDelay = L_deposit_l(0); *ph = h; - move16(); + return 0; } @@ -86,14 +76,12 @@ void JB4_JMF_Destroy( JB4_JMF_HANDLE *ph ) { JB4_JMF_HANDLE h; - IF( !ph ) + if( !ph ) { return; } h = *ph; - move16(); - - IF( !h ) + if( !h ) { return; } @@ -104,94 +92,85 @@ void JB4_JMF_Destroy( JB4_JMF_HANDLE *ph ) free( h ); *ph = NULL; - move16(); } /* function to set the window size of the fifo and the fraction which will be considered */ -Word16 JB4_JMF_Init( JB4_JMF_HANDLE h, Word16 timeScale, Word16 windowSize, - Word16 windowDuration, Word16 consideredFraction ) +int JB4_JMF_Init( JB4_JMF_HANDLE h, int timeScale, unsigned int windowSize, + unsigned int windowDuration, unsigned int consideredFraction ) { - Word16 divScaleFac; - /* check the following parameters (debug only) */ - assert( windowSize != 0U ); - /* check consideredFraction given is not too low */ - assert( consideredFraction * windowSize / 1000 >= 2 ); - /* check consideredFraction given is not too high */ - assert( consideredFraction <= 1000 ); + /* check parameters */ + if( windowSize != 0U && consideredFraction * windowSize / 1000 < 2 ) + { + return -1; + } + if( consideredFraction > 1000 ) + { + return -1; + } /* store values */ h->timeScale = timeScale; - move16(); h->maxWindowDuration = windowDuration; - move16(); h->consideredFraction = consideredFraction; - move16(); JB4_CIRCULARBUFFER_Init( h->fifo, windowSize ); JB4_CIRCULARBUFFER_Init( h->offsetFifo, windowSize ); JB4_CIRCULARBUFFER_Init( h->timeStampFifo, windowSize ); - /* calculate nElementsToIgnore so that the multi & divide occur only once, not every jitter calc. - * to retain accuracy in the division use scaled division and shift back after */ - h->nElementsToIgnore = BASOP_Util_Divide3216_Scale( L_mult0( windowSize, sub( 1000, h->consideredFraction ) ), 1000, &divScaleFac ); - h->nElementsToIgnore = shl( h->nElementsToIgnore, add( divScaleFac,1 ) ); - assert(h->nElementsToIgnore == windowSize * ( 1000 - consideredFraction ) / 1000); - /* calculate maxDelay here as to not calculate every push packet */ - h->maxDelay = L_mult0( h->timeScale, 60 ); + h->nElementsToIgnore = windowSize * ( 1000 - consideredFraction ) / 1000; return 0; } /* function to calculate delay for the current packet */ -Word16 JB4_JMF_PushPacket( JB4_JMF_HANDLE h, Word32 sysTime, Word32 rtpTimeStamp ) +int JB4_JMF_PushPacket( JB4_JMF_HANDLE h, uint32_t sysTime, uint32_t rtpTimeStamp ) { - Word32 rtpTimeDiff, sysTimeDiff; - Word32 offset, delay; + int32_t rtpTimeDiff, sysTimeDiff; + int32_t offset, delay; + /* check if this is the first entry */ - IF( h->firstPacketPushed == 0 ) + if( h->firstPacketPushed == 0 ) { h->firstPacketPushed = 1; - move16(); h->lastSysTime = sysTime; - move32(); h->lastRtpTimeStamp = rtpTimeStamp; - move32(); return 0; } - rtpTimeDiff = L_sub( rtpTimeStamp, h->lastRtpTimeStamp ); - sysTimeDiff = L_sub( sysTime, h->lastSysTime ); - offset = L_sub( sysTime, rtpTimeStamp ); + rtpTimeDiff = rtpTimeStamp - h->lastRtpTimeStamp; + sysTimeDiff = sysTime - h->lastSysTime; + offset = sysTime - rtpTimeStamp; /* get the delay (yes, signed!!!!) */ - delay = L_add( L_sub( sysTimeDiff, rtpTimeDiff ), h->lastDelay ); + delay = sysTimeDiff - rtpTimeDiff + h->lastDelay; /* remember old values */ h->lastSysTime = sysTime; - move32(); h->lastRtpTimeStamp = rtpTimeStamp; - move32(); - h->lastDelay = delay; - move32(); - /* reset delay if absolute value is greater than 60s - * to avoid overflow caused by clockdrift */ test(); - if( L_sub( delay, h->maxDelay ) > 0 || L_add( delay, h->maxDelay ) < 0 ) + * to avoid overflow caused by clockdrift */ + if( delay > 60 * h->timeScale || delay < -60 * h->timeScale ) { - h->lastDelay = L_deposit_l(0); + h->lastDelay = 0; } + else + { + h->lastDelay = delay; + } + JB4_JMF_pushBack( h, delay, offset, rtpTimeStamp ); + return 0; } /* function to get the current jitter */ -Word16 JB4_JMF_Jitter( const JB4_JMF_HANDLE h, Word32 *jitter ) +int JB4_JMF_Jitter( const JB4_JMF_HANDLE h, uint32_t *jitter ) { JB4_CIRCULARBUFFER_ELEMENT min, percentile; /* sanity check (must not be empty) and return invalid result if there is only one entry */ - IF( sub( JB4_CIRCULARBUFFER_Size( h->fifo ), 2 ) < 0 ) + if( JB4_CIRCULARBUFFER_Size( h->fifo ) < 2U ) { return -1; } @@ -199,17 +178,18 @@ Word16 JB4_JMF_Jitter( const JB4_JMF_HANDLE h, Word32 *jitter ) JB4_CIRCULARBUFFER_MinAndPercentile( h->fifo, h->nElementsToIgnore, &min, &percentile ); /* return the difference between the highest considered and the smallest value */ - *jitter = L_sub( percentile, min ); + *jitter = percentile - min; assert( percentile >= min ); + return 0; } /* function to get the minimum offset between received time and time stamp of all entries in the fifo */ -Word16 JB4_JMF_MinOffset( const JB4_JMF_HANDLE h, Word32 *offset ) +int JB4_JMF_MinOffset( const JB4_JMF_HANDLE h, int32_t *offset ) { JB4_CIRCULARBUFFER_ELEMENT min; - IF( JB4_CIRCULARBUFFER_IsEmpty( h->offsetFifo ) ) + if( JB4_CIRCULARBUFFER_IsEmpty( h->offsetFifo ) ) { return -1; } @@ -217,7 +197,7 @@ Word16 JB4_JMF_MinOffset( const JB4_JMF_HANDLE h, Word32 *offset ) JB4_CIRCULARBUFFER_Min( h->offsetFifo, &min ); *offset = min; - move32(); + return 0; } @@ -227,12 +207,14 @@ Word16 JB4_JMF_MinOffset( const JB4_JMF_HANDLE h, Word32 *offset ) *****************************************************************************/ /* helper function to add entry at back of the buffer */ -static void JB4_JMF_pushBack( JB4_JMF_HANDLE h, Word32 delay, Word32 offset, Word32 time ) +static void JB4_JMF_pushBack( JB4_JMF_HANDLE h, int32_t delay, int32_t offset, uint32_t time ) { - Word32 minTime, maxTime, duration; + int32_t minTime, maxTime; + uint32_t duration; + /* check for size and discard first entry if too big */ - IF( JB4_CIRCULARBUFFER_IsFull( h->fifo ) ) + if( JB4_CIRCULARBUFFER_IsFull( h->fifo ) ) { JB4_JMF_popFront( h ); } @@ -245,16 +227,21 @@ static void JB4_JMF_pushBack( JB4_JMF_HANDLE h, Word32 delay, Word32 offset, Wor /* check for duration and discard first entries if too long */ minTime = JB4_CIRCULARBUFFER_Front( h->timeStampFifo ); maxTime = JB4_CIRCULARBUFFER_Back( h->timeStampFifo ); - - duration = L_sub( maxTime, minTime ); - test(); - WHILE( duration > 0 && L_sub( duration, h->maxWindowDuration ) > 0 ) + if( maxTime > minTime ) { - test(); - JB4_JMF_popFront( h ); - minTime = JB4_CIRCULARBUFFER_Front( h->timeStampFifo ); - duration = L_sub( maxTime, minTime ); + duration = maxTime - minTime; + while( duration > h->maxWindowDuration ) + { + JB4_JMF_popFront( h ); + minTime = JB4_CIRCULARBUFFER_Front( h->timeStampFifo ); + if( maxTime <= minTime ) + { + break; + } + duration = maxTime - minTime; + } } + } /* helper function to remove an entry from the front of the buffer */ @@ -262,13 +249,15 @@ static void JB4_JMF_popFront( JB4_JMF_HANDLE h ) { JB4_CIRCULARBUFFER_ELEMENT tmpElement; + /* try to remove one element - fails if empty */ - IF( JB4_CIRCULARBUFFER_Deque( h->fifo, &tmpElement ) != 0 ) + if( JB4_CIRCULARBUFFER_Deque( h->fifo, &tmpElement ) != 0 ) { return; } /* also remove offset entry */ JB4_CIRCULARBUFFER_Deque( h->offsetFifo, &tmpElement ); JB4_CIRCULARBUFFER_Deque( h->timeStampFifo, &tmpElement ); + } diff --git a/src/libs/libevs/lib_dec/jbm_jb4_jmf.h b/src/libs/libevs/lib_dec/jbm_jb4_jmf.h old mode 100755 new mode 100644 index 8d6fc6d5..3b1e1f43 --- a/src/libs/libevs/lib_dec/jbm_jb4_jmf.h +++ b/src/libs/libevs/lib_dec/jbm_jb4_jmf.h @@ -1,5 +1,5 @@ /*==================================================================================== - EVS Codec 3GPP TS26.442 Apr 03, 2018. Version 12.11.0 / 13.6.0 / 14.2.0 + EVS Codec 3GPP TS26.443 Nov 13, 2018. Version 12.11.0 / 13.7.0 / 14.3.0 / 15.1.0 ====================================================================================*/ /** \file jbm_jb4_jmf.h jitter measure fifo - a fifo used for windowed measure of network status */ @@ -7,36 +7,36 @@ #ifndef JBM_JB4_JMF_H #define JBM_JB4_JMF_H JBM_JB4_JMF_H -#include "typedef.h" +#include "jbm_types.h" /** handle for jitter measure fifo - a fifo used for windowed measure of network status */ typedef struct JB4_JMF *JB4_JMF_HANDLE; /**@name functions to manage the fifo */ /**@{ */ -Word16 JB4_JMF_Create( JB4_JMF_HANDLE *ph ); +int JB4_JMF_Create( JB4_JMF_HANDLE *ph ); void JB4_JMF_Destroy( JB4_JMF_HANDLE *ph ); /** function to set the window size of the fifo and the fraction which will be considered */ -/** @param timeScale scale of system time and RTP time stamps (designed and tested up to 500 pkts) - * @param windowSize the window size of the fifo in number of packets (designed and tested up to 10000ms (500*20ms)) +/** @param timeScale scale of system time and RTP time stamps + * @param windowSize the window size of the fifo in number of packets * @param windowDuration the window size of the fifo as time in sysTimeScale * @param consideredFraction the considered fraction in 1/1000 units, e.g. 900 ignores 10% of the highest samples * @return 0 on success */ -Word16 JB4_JMF_Init( JB4_JMF_HANDLE h, Word16 timeScale, Word16 windowSize, - Word16 windowDuration, Word16 consideredFraction ); +int JB4_JMF_Init( JB4_JMF_HANDLE h, int timeScale, unsigned int windowSize, + unsigned int windowDuration, unsigned int consideredFraction ); /**@} */ /**@name functions to push packets and get the current jitter rate */ /**@{ */ /** function to calculate jitter for the current packet */ -Word16 JB4_JMF_PushPacket( JB4_JMF_HANDLE h, Word32 sysTime, Word32 rtpTimeStamp ); +int JB4_JMF_PushPacket( JB4_JMF_HANDLE h, uint32_t sysTime, uint32_t rtpTimeStamp ); /** function to get the current jitter */ -Word16 JB4_JMF_Jitter( const JB4_JMF_HANDLE h, Word32 *jitter ); +int JB4_JMF_Jitter( const JB4_JMF_HANDLE h, uint32_t *jitter ); /** function to get the minimum offset between received time and time stamp of all entries in the fifo */ /*! This value is the offset of the fastest transmitted packet of all packets currently * contained in the fifo. * @param[out] offset the minimum offset in microseconds */ -Word16 JB4_JMF_MinOffset( const JB4_JMF_HANDLE h, Word32 *offset ); +int JB4_JMF_MinOffset( const JB4_JMF_HANDLE h, int32_t *offset ); /**@} */ #endif /* JBM_JB4_JMF_H */ diff --git a/src/libs/libevs/lib_dec/jbm_jb4sb.cpp b/src/libs/libevs/lib_dec/jbm_jb4sb.cpp old mode 100755 new mode 100644 index aa4afd2f..c25fde51 --- a/src/libs/libevs/lib_dec/jbm_jb4sb.cpp +++ b/src/libs/libevs/lib_dec/jbm_jb4sb.cpp @@ -1,42 +1,34 @@ /*==================================================================================== - EVS Codec 3GPP TS26.442 Apr 03, 2018. Version 12.11.0 / 13.6.0 / 14.2.0 + EVS Codec 3GPP TS26.443 Nov 13, 2018. Version 12.11.0 / 13.7.0 / 14.3.0 / 15.1.0 ====================================================================================*/ -/*! \file jbm_jb4sb.c Jitter Buffer Management Interface */ + +/*! \file jbm_jb4sb.c EVS Jitter Buffer Management Interface */ /* system headers */ #include #include -/* instrumentation headers */ -#include "stl.h" +#include #include "options.h" -#include "basop_util.h" -#include "basop_util_jbm.h" -#include "cnst_fx.h" +/* instrumentation */ /* local headers */ #include "jbm_jb4_circularbuffer.h" #include "jbm_jb4_inputbuffer.h" #include "jbm_jb4_jmf.h" #include "jbm_jb4sb.h" -#include "prot_fx.h" +#include "prot.h" -static Word16 idiv3216(Word32 x, Word16 y) -{ - Word16 z, divScaleFac; - - z = BASOP_Util_Divide3216_Scale(x, y, &divScaleFac); - z = shl(z, add(divScaleFac,1)); - return z; -} +#define JB4_MIN(a,b) ((a)>(b) ? (b) : (a)) +#define JB4_MAX(a,b) ((a)>(b) ? (a) : (b)) #define MAXOFFSET 10 /*! Calculates the difference between two RTP timestamps - the diff is positive, if B 'later', negative otherwise */ -static Word32 JB4_rtpTimeStampDiff( Word32 tsA, Word32 tsB ); +static int32_t JB4_rtpTimeStampDiff( uint32_t tsA, uint32_t tsB ); /* function to calculate different options for the target playout delay */ -static void JB4_targetPlayoutDelay( const JB4_HANDLE h, Word32 *targetMin, - Word32 *targetMax, Word32 *targetDtx, Word32 *targetStartUp ); +static void JB4_targetPlayoutDelay( const JB4_HANDLE h, uint32_t *targetMin, + uint32_t *targetMax, uint32_t *targetDtx, uint32_t *targetStartUp ); /*! function to do playout adaptation before playing the next data unit */ /*! In case of time shrinking, data units will be dropped before the next data unit to play is returned and * in case of time stretching a empty data unit is returned and the frame should be concealed. @@ -44,41 +36,41 @@ static void JB4_targetPlayoutDelay( const JB4_HANDLE h, Word32 *targetMin, * @param[out] dataUnit the next data unit to play * @param[out] scale the scale in percent used as target for time scaling of the returned data unit * @param[out] maxScaling the maximum allowed external time scaling */ -static Word16 JB4_adaptPlayout( JB4_HANDLE h, Word32 sysTime, Word32 extBufferedTime, - JB4_DATAUNIT_HANDLE *pDataUnit, Word16 *scale, Word16 *maxScaling ); +static int JB4_adaptPlayout( JB4_HANDLE h, uint32_t sysTime, uint32_t extBufferedTime, + JB4_DATAUNIT_HANDLE *pDataUnit, uint32_t *scale, uint32_t *maxScaling ); /*! function to do playout adaptation before playing the first data unit */ /*! @param[in] now current system time * @param[out] prebuffer true, if the data unit should be prebuffered */ -static void JB4_adaptFirstPlayout( JB4_HANDLE h, Word32 sysTime, Word16 *prebuffer ); +static void JB4_adaptFirstPlayout( JB4_HANDLE h, uint32_t sysTime, bool_t *prebuffer ); /*! function for playout adaptation while active (no DTX) */ -static void JB4_adaptActivePlayout( JB4_HANDLE h, Word32 sysTime, - Word32 extBufferedTime, Word16 *scale, Word16 *maxScaling ); +static void JB4_adaptActivePlayout( JB4_HANDLE h, uint32_t sysTime, + uint32_t extBufferedTime, uint32_t *scale, uint32_t *maxScaling ); /*! function for playout adaptation while DTX */ -static void JB4_adaptDtxPlayout( JB4_HANDLE h, Word32 sysTime, Word16 *stretchTime ); +static void JB4_adaptDtxPlayout( JB4_HANDLE h, uint32_t sysTime, bool_t *stretchTime ); /*! function to look into the buffer and check if it makes sense to drop a data unit */ /*! @param[out] dropEarly true, if a data unit could be dropped early * @param[out] buffered the buffered time span in timeScale units * @return true, if a data unit could be dropped */ -static Word16 JB4_inspectBufferForDropping( const JB4_HANDLE h, Word16 *dropEarly, Word32 *buffered ); +static int JB4_inspectBufferForDropping( const JB4_HANDLE h, bool_t *dropEarly, uint32_t *buffered ); /* function to look into the buffer and check if it makes sense to drop a data unit during DTX */ -static Word16 JB4_checkDtxDropping( const JB4_HANDLE h ); +static int JB4_checkDtxDropping( const JB4_HANDLE h ); /*! function to estimate the short term jitter */ -static void JB4_estimateShortTermJitter( JB4_HANDLE h, Word32 rcvTime, Word32 rtpTimeStamp ); +static void JB4_estimateShortTermJitter( JB4_HANDLE h, uint32_t rcvTime, uint32_t rtpTimeStamp ); /*! function to pop a data unit from the buffer */ -static void JB4_popFromBuffer( JB4_HANDLE h, Word32 sysTime, JB4_DATAUNIT_HANDLE *pDataUnit ); +static void JB4_popFromBuffer( JB4_HANDLE h, uint32_t sysTime, JB4_DATAUNIT_HANDLE *pDataUnit ); /*! function to drop a data unit from the buffer - updates nShrinked */ -static void JB4_dropFromBuffer( JB4_HANDLE h, Word32 sysTime ); +static void JB4_dropFromBuffer( JB4_HANDLE h, uint32_t sysTime ); /*! function to calculate the playout delay based on the current jitter */ /*! @param[in] playTime the system time when the data unit will be played * @param[in] timeStamp the time stamp of the data unit to played * @param[out] delay the calculated playout delay */ -static Word16 JB4_playoutDelay( const JB4_HANDLE h, Word32 playTime, - Word32 rtpTimeStamp, Word32 *delay ); +static int JB4_playoutDelay( const JB4_HANDLE h, uint32_t playTime, + uint32_t rtpTimeStamp, uint32_t *delay ); /*! function to update lastPlayoutDelay and lastTargetTime after popFromBuffer() */ -static void JB4_updateLastTimingMembers( JB4_HANDLE h, Word32 playTime, Word32 rtpTimeStamp ); +static void JB4_updateLastTimingMembers( JB4_HANDLE h, uint32_t playTime, uint32_t rtpTimeStamp ); /*! function to compare the RTP time stamps of two data units: newElement==arrayElement ? 0 : (newElement>arrayElement ? +1 : -1) */ -static Word32 JB4_inputBufferCompareFunction( const JB4_INPUTBUFFER_ELEMENT newElement, - const JB4_INPUTBUFFER_ELEMENT arrayElement, Word16 *replaceWithNewElementIfEqual ); +static int JB4_inputBufferCompareFunction( const JB4_INPUTBUFFER_ELEMENT newElement, + const JB4_INPUTBUFFER_ELEMENT arrayElement, bool_t *replaceWithNewElementIfEqual ); /*! Jitter Buffer Management Interface */ @@ -87,158 +79,147 @@ struct JB4 /*! @name statistics for user */ /*@{ */ /*! the number of late lost data units */ - Word32 nLateLost; + uint32_t nLateLost; /*! the number of data units that were available (not NULL) at playout time */ - Word32 nAvailablePopped; + uint32_t nAvailablePopped; /*! the number of data units that were not available (NULL) at playout time */ - Word32 nUnavailablePopped; + uint32_t nUnavailablePopped; /*! the number of unavailable pops since the last available one - used as temp value for nLost and nStretched */ - Word32 nLostOrStretched; + uint32_t nLostOrStretched; /*! the number of data units that were lost at playout time */ - Word32 nLost; + uint32_t nLost; /*! the number of empty data units inserted for playout adaptation */ - Word32 nStretched; + uint32_t nStretched; /*! the number of data units dropped for playout adaptation */ /*! This function counts all time shrinking events, no matter if a dropped data unit was actually available. */ - Word32 nShrinked; + uint32_t nShrinked; /*! the number of data units that were returned to create comfort noice (including NULL) */ - Word32 nComfortNoice; + uint32_t nComfortNoice; /*! the number of jitter induced concealment operations (as defined in 3GPP TS 26.114) */ - Word32 jitterInducedConcealments; + uint32_t jitterInducedConcealments; /*! the target playout delay of the last returned data unit */ - Word32 targetPlayoutDelay; + uint32_t targetPlayoutDelay; /*! the target playout time of the last returned data unit */ - Word32 lastTargetTime; + uint32_t lastTargetTime; /*@} */ /*! @name internal configuration values - do not change!!! */ /*@{ */ /*! internal time scale for all calculations */ - Word16 timeScale; + int timeScale; /*! internal frame duration in timeScale units */ - Word32 frameDuration; + uint32_t frameDuration; /*@} */ /*! @name jitter buffer configuration values */ /*@{ */ /*! the allowed delay reserve in addition to network jitter to reduce late-loss [milliseconds] */ - Word32 safetyMargin; + Word32 safetyMargin; /*@} */ /*! @name data for short term jitter estimation */ /*@{ */ /*! short term jitter measure FIFO */ - JB4_JMF_HANDLE stJmf; + JB4_JMF_HANDLE stJmf; /*! FIFO of short term jitter values */ - JB4_CIRCULARBUFFER_HANDLE stJitterFifo; + JB4_CIRCULARBUFFER_HANDLE stJitterFifo; /*! FIFO of RTP time stamps for the values stored in stJitterFifo */ - JB4_CIRCULARBUFFER_HANDLE stTimeStampFifo; + JB4_CIRCULARBUFFER_HANDLE stTimeStampFifo; /*! short term jitter */ - Word32 stJitter; + uint32_t stJitter; /*@} */ /*! @name jitter buffer data */ /*@{ */ /*! true, if a data unit was already popped from the buffer */ - Word16 firstDataUnitPopped; + bool_t firstDataUnitPopped; /*! system time of the previous JB4_PopDataUnit() call */ - Word32 prevPopSysTime; + uint32_t prevPopSysTime; /*! RTP timestamp of the last played/dropped data unit that was actually available */ - Word32 lastReturnedTs; + uint32_t lastReturnedTs; /*! true, if the last popped data unit contained no active signal, i.e. silence -> hint for DTX */ - Word16 lastPoppedWasSilence; + bool_t lastPoppedWasSilence; /*! the playout time minus the minimum offset of the last played data unit in microseconds */ - Word32 lastPlayoutOffset; + int32_t lastPlayoutOffset; /*! RTP time stamp of the next data unit that is expected to be fetched from the buffer */ - Word32 nextExpectedTs; - Word16 rfOffset2Active; - Word16 rfOffset3Active; - Word16 rfOffset5Active; - Word16 rfOffset7Active; - Word32 rfDelay; + uint32_t nextExpectedTs; + Word16 rfOffset2Active; + Word16 rfOffset3Active; + Word16 rfOffset5Active; + Word16 rfOffset7Active; + Word32 rfDelay; /*! long term jitter measure FIFO */ - JB4_JMF_HANDLE ltJmf; + JB4_JMF_HANDLE ltJmf; - Word32 FecOffWinLen; - Word32 FecOffWin[10]; - Word32 optimum_offset; - Word32 totWin; - Word32 netLossRate; - /*! the number of partial copies decoded instead of PLC */ + uint32_t FecOffWinLen; + uint32_t FecOffWin[10]; + uint32_t optimum_offset; + + float netLossRate; Word32 nPartialCopiesUsed; Word32 last_nLost; Word32 last_ntot; + + uint32_t totWin; + bool_t pre_partial_frame; /*@} */ /*! @name members to store the data units */ /*@{ */ /*! the data unit buffer */ - JB4_INPUTBUFFER_HANDLE inputBuffer; - Word16 pre_partial_frame; - struct JB4_DATAUNIT memorySlots[MAX_JBM_SLOTS]; - JB4_DATAUNIT_HANDLE freeMemorySlots[MAX_JBM_SLOTS]; - Word16 nFreeMemorySlots; + JB4_INPUTBUFFER_HANDLE inputBuffer; + struct JB4_DATAUNIT memorySlots[MAX_JBM_SLOTS]; + JB4_DATAUNIT_HANDLE freeMemorySlots[MAX_JBM_SLOTS]; + unsigned int nFreeMemorySlots; /*@} */ }; /* JB4 */ -Word16 JB4_Create( JB4_HANDLE *ph ) +int JB4_Create( JB4_HANDLE *ph ) { - JB4_HANDLE h = (JB4_HANDLE)calloc( 1, sizeof( struct JB4 ) ); - - Word16 iter; + JB4_HANDLE h = (JB4*)calloc( 1, sizeof( struct JB4 ) ); + short iter; /* statistics for user */ - h->nLateLost = L_deposit_l(0); - h->nAvailablePopped = L_deposit_l(0); - h->nUnavailablePopped = L_deposit_l(0); - h->nLostOrStretched = L_deposit_l(0); - h->nLost = L_deposit_l(0); - h->nStretched = L_deposit_l(0); - h->nShrinked = L_deposit_l(0); - h->nComfortNoice = L_deposit_l(0); - h->jitterInducedConcealments = L_deposit_l(0); - h->targetPlayoutDelay = L_deposit_l(0); - h->lastTargetTime = L_deposit_l(0); + h->nLateLost = 0; + h->nAvailablePopped = 0; + h->nUnavailablePopped = 0; + h->nLostOrStretched = 0; + h->nLost = 0; + h->nStretched = 0; + h->nShrinked = 0; + h->nComfortNoice = 0; + h->jitterInducedConcealments = 0; + h->targetPlayoutDelay = 0; + h->lastTargetTime = 0; /* internal configuration values - do not change!!! */ h->timeScale = 0; - move16(); - h->frameDuration = L_deposit_l(0); + h->frameDuration = 0; /* jitter buffer configuration values: done in JB4_Init() */ /* short term jitter evaluation */ JB4_JMF_Create( &h->stJmf ); JB4_CIRCULARBUFFER_Create( &h->stJitterFifo ); JB4_CIRCULARBUFFER_Create( &h->stTimeStampFifo ); - h->stJitter = L_deposit_l(0); + h->stJitter = 0; /* jitter buffer data */ h->firstDataUnitPopped = false; - move16(); - h->prevPopSysTime = L_deposit_l(0); - h->lastReturnedTs = L_deposit_l(0); + h->prevPopSysTime = 0; + h->lastReturnedTs = 0; h->lastPoppedWasSilence = false; - move16(); - h->lastPlayoutOffset = L_deposit_l(0); - h->nextExpectedTs = L_deposit_l(0); + h->lastPlayoutOffset = 0; + h->nextExpectedTs = 0; h->rfOffset2Active = 0; - move16(); h->rfOffset3Active = 0; - move16(); h->rfOffset5Active = 0; - move16(); h->rfOffset7Active = 0; - move16(); - h->rfDelay = L_deposit_l(0); + h->rfDelay = 0; JB4_JMF_Create( &h->ltJmf ); h->pre_partial_frame = 0; h->FecOffWinLen = 0; - move32(); - FOR (iter = 0; iter < 10; iter++ ) + for (iter = 0; iter < 10; iter++ ) { h->FecOffWin[iter] = 0; - move32(); } h->optimum_offset = 3; - move32(); h->totWin = 0; - move32(); - h->netLossRate = 0; + h->netLossRate = 0.0f; move32(); h->nPartialCopiesUsed = 0; move32(); @@ -250,31 +231,27 @@ Word16 JB4_Create( JB4_HANDLE *ph ) /* members to store the data units */ JB4_INPUTBUFFER_Create( &h->inputBuffer ); /* allocate memory for data units */ - FOR(iter = 0; iter < MAX_JBM_SLOTS; ++iter) + for(iter = 0; iter < MAX_JBM_SLOTS; ++iter) { - h->memorySlots[iter].data = (UWord8*)malloc(MAX_AU_SIZE); + h->memorySlots[iter].data = (uint8_t*)malloc(MAX_AU_SIZE); h->freeMemorySlots[iter] = &h->memorySlots[iter]; - move16(); } h->nFreeMemorySlots = MAX_JBM_SLOTS; *ph = h; - move16(); return 0; } void JB4_Destroy( JB4_HANDLE *ph ) { JB4_HANDLE h; - Word16 i; + unsigned int i; - IF( !ph ) + if( !ph ) { return; } h = *ph; - move16(); - - IF( !h ) + if( !h ) { return; } @@ -292,37 +269,34 @@ void JB4_Destroy( JB4_HANDLE *ph ) free( h ); *ph = NULL; - move16(); + } -Word16 JB4_Init( JB4_HANDLE h, Word16 safetyMargin ) +int JB4_Init( JB4_HANDLE h, Word16 safetyMargin ) { - Word16 ltJmfSize, stFifoSize, stJmfSize, stJmfAllowedLateLoss; - Word16 inputBufferCapacity; + unsigned int ltJmfSize, stFifoSize, stJmfSize, stJmfAllowedLateLoss; + unsigned int inputBufferCapacity; /* internal timescale is 1000, frame duration is 20ms */ - h->timeScale = 1000; /* ms */ move16(); - h->frameDuration = L_deposit_l(20); /* ms */ + h->timeScale = 1000; /* ms */ + h->frameDuration = 20; /* ms */ /* jitter buffer configuration values */ - h->safetyMargin = L_deposit_l(safetyMargin); + h->safetyMargin = safetyMargin; /* long term jitter measure FIFO: 500 frames and 10s */ ltJmfSize = 10000; - move16(); JB4_JMF_Init( h->ltJmf, h->timeScale, ltJmfSize / 20, ltJmfSize, 1000 ); /* short term jitter evaluation */ stFifoSize = 200; - move16(); stJmfSize = 50; - move16(); - stJmfAllowedLateLoss = 940; /* (1000 - 60) = 6%, e.g. ignore three packets out of 50 */ move16(); + stJmfAllowedLateLoss = 60; /* 6%, e.g. ignore three packets out of 50 */ JB4_CIRCULARBUFFER_Init( h->stJitterFifo, stFifoSize ); JB4_CIRCULARBUFFER_Init( h->stTimeStampFifo, stFifoSize ); - JB4_JMF_Init( h->stJmf, h->timeScale, stJmfSize, h->timeScale /* 1s */, stJmfAllowedLateLoss ); + JB4_JMF_Init( h->stJmf, h->timeScale, + stJmfSize, h->timeScale /* 1s */, 1000 - stJmfAllowedLateLoss ); inputBufferCapacity = MAX_JBM_SLOTS - 2; - move16(); JB4_INPUTBUFFER_Init( h->inputBuffer, inputBufferCapacity, JB4_inputBufferCompareFunction ); return 0; } @@ -331,18 +305,15 @@ Word16 JB4_Init( JB4_HANDLE h, Word16 safetyMargin ) JB4_DATAUNIT_HANDLE JB4_AllocDataUnit( JB4_HANDLE h ) { JB4_DATAUNIT_HANDLE dataUnit; - - WHILE(h->nFreeMemorySlots == 0) + while(h->nFreeMemorySlots == 0) { assert(JB4_INPUTBUFFER_IsEmpty(h->inputBuffer) == 0); JB4_dropFromBuffer(h, 0); } - h->nFreeMemorySlots = sub(h->nFreeMemorySlots, 1); + --h->nFreeMemorySlots; dataUnit = h->freeMemorySlots[h->nFreeMemorySlots]; - move16(); h->freeMemorySlots[h->nFreeMemorySlots] = NULL; - move16(); assert(dataUnit != NULL); return dataUnit; } @@ -353,114 +324,99 @@ void JB4_FreeDataUnit( JB4_HANDLE h, JB4_DATAUNIT_HANDLE dataUnit ) assert(dataUnit != NULL); assert(h->nFreeMemorySlots < MAX_JBM_SLOTS); h->freeMemorySlots[h->nFreeMemorySlots] = dataUnit; - move16(); - h->nFreeMemorySlots = add(h->nFreeMemorySlots, 1); + h->nFreeMemorySlots++; } -Word16 JB4_PushDataUnit( JB4_HANDLE h, JB4_DATAUNIT_HANDLE dataUnit, Word32 rcvTime ) +int JB4_PushDataUnit( JB4_HANDLE h, JB4_DATAUNIT_HANDLE dataUnit, uint32_t rcvTime ) { JB4_DATAUNIT_HANDLE droppedDataUnit = NULL; - move16(); - assert( dataUnit->duration == h->frameDuration ); - assert( dataUnit->timeScale == h->timeScale ); + assert( dataUnit->duration == h->frameDuration ); + assert( dataUnit->timeScale == (unsigned int)h->timeScale ); - /* ignore frames from too far in future (3 seconds) */ test(); - IF( h->firstDataUnitPopped && - L_sub(JB4_rtpTimeStampDiff(h->lastReturnedTs, dataUnit->timeStamp), - L_mult0(50 * 3, extract_l(dataUnit->duration))) >= 0) + /* ignore frames from too far in future (3 seconds) */ + if( h->firstDataUnitPopped && JB4_rtpTimeStampDiff( h->lastReturnedTs, dataUnit->timeStamp ) >= + (int32_t) (50 * 3 * dataUnit->duration) ) { JB4_FreeDataUnit(h, dataUnit); return 0; } /* reserve space for one element to add: drop oldest if buffer is full */ - WHILE(JB4_INPUTBUFFER_IsFull(h->inputBuffer)) + while(JB4_INPUTBUFFER_IsFull(h->inputBuffer)) { JB4_dropFromBuffer(h, rcvTime); } assert(JB4_INPUTBUFFER_IsFull(h->inputBuffer) == 0); /* do statistics on partial copy offset using active primary copies to - * avoid unexpected resets because RF_NO_DATA partial copies are dropped before JBM */ - IF(dataUnit->silenceIndicator == 0 && dataUnit->partial_frame == 0) + * avoid unexpected resets because RF__NO_DATA partial copies are dropped before JBM */ + if(dataUnit->silenceIndicator == 0 && dataUnit->partial_frame == 0) { - IF(sub(dataUnit->partialCopyOffset, 0) == 0) + if(dataUnit->partialCopyOffset == 0) { - h->rfOffset2Active = s_max(sub(h->rfOffset2Active, 1), 0); - h->rfOffset3Active = s_max(sub(h->rfOffset3Active, 1), 0); - h->rfOffset5Active = s_max(sub(h->rfOffset5Active, 1), 0); - h->rfOffset7Active = s_max(sub(h->rfOffset7Active, 1), 0); + if(h->rfOffset2Active > 0) + --h->rfOffset2Active; + if(h->rfOffset3Active > 0) + --h->rfOffset3Active; + if(h->rfOffset5Active > 0) + --h->rfOffset5Active; + if(h->rfOffset7Active > 0) + --h->rfOffset7Active; } - ELSE IF(sub(dataUnit->partialCopyOffset, 2) == 0) + else if(dataUnit->partialCopyOffset == 2) { h->rfOffset2Active = 100; - move16(); h->rfOffset3Active = 0; - move16(); h->rfOffset5Active = 0; - move16(); h->rfOffset7Active = 0; - move16(); } - ELSE IF(sub(dataUnit->partialCopyOffset, 3) == 0) + else if(dataUnit->partialCopyOffset == 3) { h->rfOffset2Active = 0; - move16(); h->rfOffset3Active = 100; - move16(); h->rfOffset5Active = 0; - move16(); h->rfOffset7Active = 0; - move16(); } - ELSE IF(sub(dataUnit->partialCopyOffset, 5) == 0) + else if(dataUnit->partialCopyOffset == 5) { h->rfOffset2Active = 0; - move16(); h->rfOffset3Active = 0; - move16(); h->rfOffset5Active = 100; - move16(); h->rfOffset7Active = 0; - move16(); } - ELSE IF(sub(dataUnit->partialCopyOffset, 7) == 0) + else if(dataUnit->partialCopyOffset == 7) { h->rfOffset2Active = 0; - move16(); h->rfOffset3Active = 0; - move16(); h->rfOffset5Active = 0; - move16(); h->rfOffset7Active = 100; - move16(); } } - IF(dataUnit->partial_frame != 0) + if(dataUnit->partial_frame != 0) { - /* check for "real" late loss: a frame with higher/same timestamp was already returned to be fed into decoder */ test(); - IF( h->firstDataUnitPopped && JB4_rtpTimeStampDiff( h->lastReturnedTs, dataUnit->timeStamp ) <= 0 ) + /* check for "real" late loss: a frame with higher/same timestamp was already returned to be fed into decoder */ + if( h->firstDataUnitPopped && JB4_rtpTimeStampDiff( h->lastReturnedTs, dataUnit->timeStamp ) <= 0 ) { JB4_FreeDataUnit(h, dataUnit); return 0; } /* drop partial copy if the missing frame was already concealed */ - IF( h->firstDataUnitPopped ) + if( h->firstDataUnitPopped ) { - IF( sub(dataUnit->partialCopyOffset, 3) <= 0 && JB4_rtpTimeStampDiff( h->nextExpectedTs, dataUnit->timeStamp ) < 0) + if( dataUnit->partialCopyOffset <= 3 && JB4_rtpTimeStampDiff( h->nextExpectedTs, dataUnit->timeStamp ) < 0) { JB4_FreeDataUnit(h, dataUnit); return 0; } - ELSE IF( sub(dataUnit->partialCopyOffset, 5) == 0 && L_add(JB4_rtpTimeStampDiff( h->nextExpectedTs, dataUnit->timeStamp ), 40) < 0) + else if( dataUnit->partialCopyOffset == 5 && JB4_rtpTimeStampDiff( h->nextExpectedTs, dataUnit->timeStamp ) < -40) { JB4_FreeDataUnit(h, dataUnit); return 0; } - ELSE IF( sub(dataUnit->partialCopyOffset, 7) == 0 && L_add(JB4_rtpTimeStampDiff( h->nextExpectedTs, dataUnit->timeStamp ), 80) < 0) + else if( dataUnit->partialCopyOffset == 7 && JB4_rtpTimeStampDiff( h->nextExpectedTs, dataUnit->timeStamp ) < -80) { JB4_FreeDataUnit(h, dataUnit); return 0; @@ -468,46 +424,46 @@ Word16 JB4_PushDataUnit( JB4_HANDLE h, JB4_DATAUNIT_HANDLE dataUnit, Word32 rcvT } /* try to store partial copy - will be dropped if primary copy already available */ - IF(JB4_INPUTBUFFER_Enque( h->inputBuffer, dataUnit, (void**)&droppedDataUnit ) == 0) + if(JB4_INPUTBUFFER_Enque( h->inputBuffer, dataUnit, (void**)&droppedDataUnit ) == 0) { /* partial copy is useful, consider it in long-term jitter estimation */ - IF( sub(dataUnit->partialCopyOffset, 3) <= 0 ) + if(dataUnit->partialCopyOffset <= 3) { JB4_JMF_PushPacket( h->ltJmf, rcvTime, dataUnit->timeStamp ); } } - ELSE + else { JB4_FreeDataUnit(h, dataUnit); } - IF(droppedDataUnit != NULL) + if(droppedDataUnit != NULL) { JB4_FreeDataUnit(h, droppedDataUnit); } } - ELSE + else { /* calculate jitter */ JB4_JMF_PushPacket( h->ltJmf, rcvTime, dataUnit->timeStamp ); JB4_estimateShortTermJitter( h, rcvTime, dataUnit->timeStamp ); - /* check for "real" late loss: a frame with higher/same timestamp was already returned to be fed into decoder */ test(); - IF( h->firstDataUnitPopped && JB4_rtpTimeStampDiff( h->lastReturnedTs, dataUnit->timeStamp ) <= 0 ) + /* check for "real" late loss: a frame with higher/same timestamp was already returned to be fed into decoder */ + if( h->firstDataUnitPopped && JB4_rtpTimeStampDiff( h->lastReturnedTs, dataUnit->timeStamp ) <= 0 ) { - IF( !dataUnit->silenceIndicator ) + if( !dataUnit->silenceIndicator ) { - h->nLateLost = L_add(h->nLateLost, 1); + ++h->nLateLost; /* deletion of a speech frame because it arrived at the JBM too late */ - h->jitterInducedConcealments = L_add(h->jitterInducedConcealments, 1); + ++h->jitterInducedConcealments; } JB4_FreeDataUnit(h, dataUnit); return 0; } /* store data unit */ - IF(JB4_INPUTBUFFER_Enque( h->inputBuffer, dataUnit, (void**)&droppedDataUnit ) != 0) + if(JB4_INPUTBUFFER_Enque( h->inputBuffer, dataUnit, (void**)&droppedDataUnit) != 0) { JB4_FreeDataUnit(h, dataUnit); } - IF(droppedDataUnit != NULL) + if(droppedDataUnit != NULL) { JB4_FreeDataUnit(h, droppedDataUnit); } @@ -515,330 +471,307 @@ Word16 JB4_PushDataUnit( JB4_HANDLE h, JB4_DATAUNIT_HANDLE dataUnit, Word32 rcvT return 0; } -Word16 JB4_PopDataUnit( JB4_HANDLE h, Word32 sysTime, Word32 extBufferedTime, - JB4_DATAUNIT_HANDLE *pDataUnit, Word16 *scale, Word16 *maxScaling ) + + +int JB4_getFECoffset(JB4_HANDLE h) { - Word16 ret; + return (int)h->optimum_offset; +} +short JB4_FECoffset(JB4_HANDLE h) +{ + if ( h->netLossRate < 0.05 ) + { + return (short)0; + } + else + { + return (short)1; + } +} + + + +int JB4_PopDataUnit( JB4_HANDLE h, uint32_t sysTime, uint32_t extBufferedTime, + JB4_DATAUNIT_HANDLE *pDataUnit, uint32_t *scale, uint32_t *maxScaling ) +{ + int ret; assert( sysTime >= h->prevPopSysTime ); - if( L_sub(sysTime, L_add(h->prevPopSysTime, h->frameDuration)) > 0 ) + if( sysTime > h->prevPopSysTime + 20 ) { - h->lastPlayoutOffset = rtpTs_add(h->lastPlayoutOffset, h->frameDuration); + h->lastPlayoutOffset += 20; } h->prevPopSysTime = sysTime; - move32(); + ret = JB4_adaptPlayout( h, sysTime, extBufferedTime, pDataUnit, scale, maxScaling ); + + return ret; } /* Calculates the difference between two RTP timestamps - the diff is positive, if B 'later', negative otherwise */ -static Word32 JB4_rtpTimeStampDiff( Word32 tsA, Word32 tsB ) +static int32_t JB4_rtpTimeStampDiff( uint32_t tsA, uint32_t tsB ) { - Word32 ret; - /* no saturation wanted! */ - ret = rtpTs_sub(tsB, tsA); - assert( ret == (Word32)(tsB - tsA) ); + int32_t ret; + /* do not dare to inline this function, casting to int32_t is important here! */ + ret = (int32_t)(tsB - tsA); return ret; } /* function to get the number of data units contained in the buffer */ -Word16 JB4_bufferedDataUnits( const JB4_HANDLE h ) +unsigned int JB4_bufferedDataUnits( const JB4_HANDLE h ) { return JB4_INPUTBUFFER_Size( h->inputBuffer ); } -Word16 JB4_getFECoffset(JB4_HANDLE h) -{ - return (Word16)h->optimum_offset; -} - -Word16 JB4_FECoffset(JB4_HANDLE h) -{ - IF ( L_sub( h->netLossRate, 1634) < 0 ) - { - return (Word16)0; - } - ELSE - { - return (Word16)1; - } -} - - /***************************************************************************** **************************** private functions ****************************** *****************************************************************************/ /* function to calculate different options for the target playout delay */ -static void JB4_targetPlayoutDelay( const JB4_HANDLE h, Word32 *targetMin, - Word32 *targetMax, Word32 *targetDtx, Word32 *targetStartUp ) +static void JB4_targetPlayoutDelay( const JB4_HANDLE h, uint32_t *targetMin, + uint32_t *targetMax, uint32_t *targetDtx, uint32_t *targetStartUp ) { - Word32 ltJitter, extraDelayReserve; + uint32_t ltJitter, extraDelayReserve; /* adapt target delay to partial copy offset */ - extraDelayReserve = L_deposit_l(0); - h->rfDelay = L_deposit_l(0); - IF(h->rfOffset7Active != 0) + extraDelayReserve = 0; + h->rfDelay = 0; + if(h->rfOffset7Active != 0) { - h->rfDelay = L_deposit_l(140); + h->rfDelay = 140; } - ELSE IF(h->rfOffset5Active != 0) + else if(h->rfOffset5Active != 0) { - h->rfDelay = L_deposit_l(100); + h->rfDelay = 100; } - ELSE IF(h->rfOffset2Active == 0 && h->rfOffset3Active == 0) + else if(h->rfOffset2Active == 0 && h->rfOffset3Active == 0) { /* keep some delay reserve for RF-off */ - extraDelayReserve = L_deposit_l(15); + extraDelayReserve = 15; } /* get estimated long term jitter */ - IF( JB4_JMF_Jitter( h->ltJmf, <Jitter ) == 0 ) + if( JB4_JMF_Jitter( h->ltJmf, <Jitter ) == 0 ) { /* combine long term and short term jitter to calculate target delay values */ - *targetMax = L_add(h->stJitter, L_add(h->safetyMargin, h->rfDelay)); - *targetMin = L_min(L_add(L_add(L_add(ltJitter, 20), h->rfDelay), extraDelayReserve), *targetMax ); - *targetDtx = L_min(L_add(ltJitter, extraDelayReserve), h->stJitter ); - *targetStartUp = L_shr(L_add(L_add(*targetMin, *targetMax), L_shr(extraDelayReserve, 2)), 1); + *targetMax = h->stJitter + h->safetyMargin + h->rfDelay; + *targetMin = JB4_MIN( ltJitter + 20 + h->rfDelay + extraDelayReserve, *targetMax ); + *targetDtx = JB4_MIN( ltJitter + extraDelayReserve, h->stJitter ); + *targetStartUp = ( *targetMin + *targetMax + extraDelayReserve / 4) / 2; } - ELSE + else { /* combine long term and short term jitter to calculate target delay values */ *targetMax = h->safetyMargin; - move32(); - *targetMin = L_min( 20, *targetMax ); + *targetMin = JB4_MIN( 20, *targetMax ); *targetDtx = 0; - move16(); - *targetStartUp = L_shr(L_add(*targetMin, *targetMax), 1); + *targetStartUp = ( *targetMin + *targetMax ) / 2; } - if(L_sub(*targetStartUp, 60) < 0) + if(*targetStartUp < 60) { *targetStartUp = 60; - move32(); } } /* function to do playout adaptation before playing the next data unit */ -static Word16 JB4_adaptPlayout( JB4_HANDLE h, Word32 sysTime, Word32 extBufferedTime, - JB4_DATAUNIT_HANDLE *pDataUnit, Word16 *scale, Word16 *maxScaling ) +static int JB4_adaptPlayout( JB4_HANDLE h, uint32_t sysTime, uint32_t extBufferedTime, + JB4_DATAUNIT_HANDLE *pDataUnit, uint32_t *scale, uint32_t *maxScaling ) { - Word16 stretchTime; - - /* reset scale */ test(); - IF( scale == NULL || maxScaling == NULL ) + bool_t stretchTime; + /* reset scale */ + if( scale == NULL || maxScaling == NULL ) { return -1; } *scale = 100; - move16(); *maxScaling = 0; - move16(); stretchTime = false; - move16(); /* switch type of current playout (first one, active, DTX) */ - IF( !h->firstDataUnitPopped ) + if( !h->firstDataUnitPopped ) { JB4_adaptFirstPlayout( h, sysTime, &stretchTime ); } - ELSE IF( h->lastPoppedWasSilence ) + else if( h->lastPoppedWasSilence ) { JB4_adaptDtxPlayout( h, sysTime, &stretchTime ); } - ELSE + else { JB4_adaptActivePlayout( h, sysTime, extBufferedTime, scale, maxScaling ); } /* time shrinking done if needed, now do time stretching or pop data unit to play */ - IF( stretchTime ) + if( stretchTime ) { /* return empty data unit */ *pDataUnit = NULL; - move16(); - - IF( h->firstDataUnitPopped ) + if( h->firstDataUnitPopped ) { - h->nUnavailablePopped = L_add(h->nUnavailablePopped, 1); - IF( !h->lastPoppedWasSilence ) + ++h->nUnavailablePopped; + if( !h->lastPoppedWasSilence ) { - h->nStretched = L_add(h->nStretched, 1); + ++h->nStretched; /* jitter-induced insertion (e.g. buffer underflow) */ - h->jitterInducedConcealments = L_add(h->jitterInducedConcealments, 1); + ++h->jitterInducedConcealments; } } /* add one frame to last playout delay */ - h->lastPlayoutOffset = rtpTs_add(h->lastPlayoutOffset, h->frameDuration); + h->lastPlayoutOffset += h->frameDuration; } - ELSE + else { /* return next data unit from buffer */ JB4_popFromBuffer( h, sysTime, pDataUnit ); } + return 0; } /* function for playout adaptation while active (no DTX) */ -static void JB4_adaptActivePlayout( JB4_HANDLE h, Word32 sysTime, - Word32 extBufferedTime, Word16 *scale, Word16 *maxScaling ) +static void JB4_adaptActivePlayout( JB4_HANDLE h, uint32_t sysTime, + uint32_t extBufferedTime, uint32_t *scale, uint32_t *maxScaling ) { JB4_DATAUNIT_HANDLE nextDataUnit; - Word16 convertToLateLoss, dropEarly = 0; - Word32 targetMin, targetMax, targetDtx, targetStartUp, targetMaxStretch; - Word32 currPlayoutDelay, buffered; - Word16 gap, rate, dropGapMax, dropRateMin, dropRateMax; - Word32 minOffTicks, tsDiffToNextDataUnit; - Word32 delayWithClearedExternalBuffer; - Word32 tmp32; + bool_t convertToLateLoss, dropEarly; + uint32_t targetMin, targetMax, targetDtx, targetStartUp, targetMaxStretch; + uint32_t currPlayoutDelay, gap, buffered; + uint32_t dropGapMax, dropRateMin, dropRateMax, rate; + int32_t minOffTicks, tsDiffToNextDataUnit; JB4_targetPlayoutDelay( h, &targetMin, &targetMax, &targetDtx, &targetStartUp ); - IF( JB4_JMF_MinOffset( h->ltJmf, &minOffTicks ) != 0 ) + if( JB4_JMF_MinOffset( h->ltJmf, &minOffTicks ) != 0 ) { return; } - h->targetPlayoutDelay = L_shr(L_add(targetMin, targetMax ), 1); + h->targetPlayoutDelay = ( targetMin + targetMax ) / 2; convertToLateLoss = false; - move16(); dropEarly = false; - move16(); dropGapMax = 200; - move16(); dropRateMin = 5; - move16(); - dropRateMax = 200; /* 20% */ move16(); + dropRateMax = 200; /* 20% */ + /* calculate current playout delay */ - currPlayoutDelay = rtpTs_add(rtpTs_sub(h->lastPlayoutOffset, minOffTicks), extBufferedTime); - /* adapt it to time stretching due to empty buffer */ - IF( !JB4_INPUTBUFFER_IsEmpty( h->inputBuffer ) ) + currPlayoutDelay = h->lastPlayoutOffset - minOffTicks + extBufferedTime; + if( !JB4_INPUTBUFFER_IsEmpty( h->inputBuffer ) ) { nextDataUnit = (JB4_DATAUNIT_HANDLE)JB4_INPUTBUFFER_Front( h->inputBuffer ); tsDiffToNextDataUnit = JB4_rtpTimeStampDiff( h->nextExpectedTs, nextDataUnit->timeStamp ); - IF( tsDiffToNextDataUnit < 0 ) + if( tsDiffToNextDataUnit < 0 ) { convertToLateLoss = true; - move16(); - { - /* time stretching is expected -> increase playout delay to allow dropping the late frame */ - currPlayoutDelay = L_sub(currPlayoutDelay, tsDiffToNextDataUnit); - currPlayoutDelay = L_add(currPlayoutDelay, 1); - } + /* time stretching is expected -> increase playout delay to allow dropping the late frame */ + currPlayoutDelay -= tsDiffToNextDataUnit; + currPlayoutDelay += 1; } } /* decided between shrinking/stretching */ - IF( L_sub(currPlayoutDelay, targetMax) > 0 ) /* time shrinking */ + if( currPlayoutDelay > targetMax ) /* time shrinking */ { - gap = extract_l(L_sub(currPlayoutDelay, h->targetPlayoutDelay)); + gap = currPlayoutDelay - h->targetPlayoutDelay; /* check if gap is positive and dropping is allowed - * and buffer contains enough time (ignoring one frame) */ test(); - test(); - test(); - IF( gap > 0 && - JB4_inspectBufferForDropping( h, &dropEarly, &buffered ) == 0 && - ( convertToLateLoss || - L_sub(L_add(L_add(buffered, h->frameDuration), extBufferedTime), targetMax) > 0 ) ) + * and buffer contains enough time (ignoring one frame) */ + if( gap > 0 && + JB4_inspectBufferForDropping( h, &dropEarly, &buffered ) == 0 && + ( convertToLateLoss || + ( buffered + h->frameDuration + extBufferedTime ) > targetMax ) ) { - IF( convertToLateLoss ) - { - JB4_dropFromBuffer( h, sysTime ); - h->nLostOrStretched = L_add(h->nLostOrStretched, 1); - } - ELSE IF( dropEarly ) + if( convertToLateLoss ) { JB4_dropFromBuffer( h, sysTime ); } - ELSE + else if( dropEarly ) + { + JB4_dropFromBuffer( h, sysTime ); + ++h->nLostOrStretched; + } + else { /* limit gap to [gapMin,gapMax] and calculate current drop rate from gap */ - tmp32 = L_mult0(s_min(gap, dropGapMax), sub(dropRateMax, dropRateMin)); - assert( tmp32 == s_min(gap, dropGapMax) * ( dropRateMax - dropRateMin )); - rate = idiv3216(tmp32, dropGapMax); - assert( rate == tmp32 / dropGapMax ); - rate = add(rate, dropRateMin); - *scale = idiv1616U(sub(1000, rate), 10); - assert( *scale == (1000 - rate) / 10 ); - *maxScaling = extract_l(L_sub(currPlayoutDelay, targetMax)); + rate = JB4_MIN( (uint32_t)(gap), dropGapMax ) * + ( dropRateMax - dropRateMin ) / dropGapMax + dropRateMin; + *scale = ( 1000 - rate ) / 10; + *maxScaling = currPlayoutDelay - targetMax; } } } - ELSE /* time stretching */ + else /* time stretching */ { + uint32_t delayWithClearedExternalBuffer; /* Stretching only makes sense if we win one additional frame in the input buffer. * If too much additional delay would be required to do so, then do not scale. * Also make sure that the delay doesn't increase too much. */ - delayWithClearedExternalBuffer = L_add(L_sub(currPlayoutDelay, extBufferedTime), h->frameDuration); - targetMaxStretch = L_sub(targetMax, h->frameDuration); - IF( L_sub(L_add(delayWithClearedExternalBuffer, h->frameDuration), targetMaxStretch) <= 0 && - L_sub(currPlayoutDelay, targetMaxStretch) < 0 && L_sub(currPlayoutDelay, L_add(110, L_shr(h->rfDelay, 2))) < 0) + delayWithClearedExternalBuffer = currPlayoutDelay - extBufferedTime + h->frameDuration; + targetMaxStretch = targetMax - h->frameDuration; + if( delayWithClearedExternalBuffer + h->frameDuration <= targetMaxStretch && + currPlayoutDelay < targetMaxStretch && currPlayoutDelay < (uint32_t)(110 + h->rfDelay / 4)) { *scale = 120; - move16(); - *maxScaling = extract_l(L_sub(targetMaxStretch, currPlayoutDelay)); + *maxScaling = targetMaxStretch - currPlayoutDelay; } } } /* function for playout adaptation while DTX */ -static void JB4_adaptDtxPlayout( JB4_HANDLE h, Word32 sysTime, Word16 *stretchTime ) +static void JB4_adaptDtxPlayout( JB4_HANDLE h, uint32_t sysTime, bool_t *stretchTime ) { JB4_DATAUNIT_HANDLE firstDu; - Word32 targetMin, targetMax, targetDtx, targetStartUp; - Word32 currPlayoutDelay, headRoom; - Word32 minOffTicks, tsDiffToNextDataUnit; - + uint32_t firstTs; + uint32_t targetMin, targetMax, targetDtx, targetStartUp; + uint32_t currPlayoutDelay, headRoom; + int32_t minOffTicks, tsDiffToNextDataUnit; JB4_targetPlayoutDelay( h, &targetMin, &targetMax, &targetDtx, &targetStartUp ); - IF( JB4_JMF_MinOffset( h->ltJmf, &minOffTicks ) != 0 ) + if( JB4_JMF_MinOffset( h->ltJmf, &minOffTicks ) != 0 ) { return; } /* calculate current playout delay */ - assert( rtpTs_sub(h->lastPlayoutOffset, minOffTicks) == h->lastPlayoutOffset - minOffTicks ); - currPlayoutDelay = rtpTs_sub(h->lastPlayoutOffset, minOffTicks); + currPlayoutDelay = h->lastPlayoutOffset - minOffTicks; /* check for startup after DTX */ - IF( !JB4_INPUTBUFFER_IsEmpty( h->inputBuffer ) ) + if( !JB4_INPUTBUFFER_IsEmpty( h->inputBuffer ) ) { firstDu = (JB4_DATAUNIT_HANDLE)JB4_INPUTBUFFER_Front( h->inputBuffer ); + firstTs = firstDu->timeStamp; - tsDiffToNextDataUnit = JB4_rtpTimeStampDiff( h->nextExpectedTs, firstDu->timeStamp ); + tsDiffToNextDataUnit = JB4_rtpTimeStampDiff( h->nextExpectedTs, firstTs ); /* check if the next available data unit should already be used (time stamp order) */ if( tsDiffToNextDataUnit > 0 ) { /* time stretching is expected -> increase playout delay */ - currPlayoutDelay = L_add(currPlayoutDelay, tsDiffToNextDataUnit); + currPlayoutDelay += tsDiffToNextDataUnit; } - - IF( !firstDu->silenceIndicator ) + if( !firstDu->silenceIndicator ) { /* recalculate playout delay based on first buffered data unit */ - JB4_playoutDelay( h, sysTime, firstDu->timeStamp, &currPlayoutDelay ); + JB4_playoutDelay( h, sysTime, firstTs, &currPlayoutDelay ); /* check if the next available data unit should already be used (time stamp order) */ if( tsDiffToNextDataUnit > 0 ) { /* time stretching is expected -> increase playout delay */ - currPlayoutDelay = L_add(currPlayoutDelay, tsDiffToNextDataUnit); + currPlayoutDelay += tsDiffToNextDataUnit; } h->targetPlayoutDelay = targetStartUp; - move32(); - headRoom = L_deposit_l(12); /* 600 * 20 (h->frameDuration) / 1000 */ + headRoom = 600 * h->frameDuration / 1000; /* decided between shrinking/stretching */ - IF( L_sub(currPlayoutDelay, L_add(targetStartUp, headRoom)) > 0) /* time shrinking */ + if( currPlayoutDelay > targetStartUp + headRoom ) /* time shrinking */ { - IF( JB4_checkDtxDropping( h ) ) + if( JB4_checkDtxDropping( h ) ) { JB4_dropFromBuffer( h, sysTime ); } } - ELSE IF( L_sub(L_add(currPlayoutDelay, headRoom), targetStartUp) < 0 ) /* time stretching */ + else if( currPlayoutDelay + headRoom < targetStartUp ) /* time stretching */ { *stretchTime = true; - move16(); } return; } @@ -846,201 +779,196 @@ static void JB4_adaptDtxPlayout( JB4_HANDLE h, Word32 sysTime, Word16 *stretchTi /* adapt while DTX */ h->targetPlayoutDelay = targetDtx; - move32(); /* decided between shrinking/stretching */ - IF( L_sub(currPlayoutDelay, L_add(targetDtx, h->frameDuration)) >= 0 ) /* time shrinking */ + if( currPlayoutDelay >= targetDtx + h->frameDuration ) /* time shrinking */ { - IF( JB4_checkDtxDropping( h ) ) + if( JB4_checkDtxDropping( h ) ) { JB4_dropFromBuffer( h, sysTime ); } } - ELSE IF( L_sub(L_add(currPlayoutDelay, L_shr(h->frameDuration, 1)), targetDtx) < 0 ) /* time stretching */ + else if( currPlayoutDelay + 500 * h->frameDuration / 1000 < targetDtx ) /* time stretching */ { *stretchTime = true; - move16(); } + } /* function to do playout adaptation before playing the first data unit */ -static void JB4_adaptFirstPlayout( JB4_HANDLE h, Word32 sysTime, Word16 *prebuffer ) +static void JB4_adaptFirstPlayout( JB4_HANDLE h, uint32_t sysTime, bool_t *prebuffer ) { - Word32 currPlayoutDelay; + uint32_t currPlayoutDelay; JB4_DATAUNIT_HANDLE firstDu; - Word32 targetMin, targetMax, targetDtx, targetStartUp; - - /* get target delay */ - IF( JB4_INPUTBUFFER_IsEmpty( h->inputBuffer ) ) + uint32_t targetMin, targetMax, targetDtx, targetStartUp; + if( JB4_INPUTBUFFER_IsEmpty( h->inputBuffer ) ) { *prebuffer = true; - move16(); return; } JB4_targetPlayoutDelay( h, &targetMin, &targetMax, &targetDtx, &targetStartUp ); - - IF(L_sub(targetStartUp, h->frameDuration) < 0) + if(targetStartUp < h->frameDuration) { return; } /* calculate delay if first data unit would be played now */ firstDu = (JB4_DATAUNIT_HANDLE)JB4_INPUTBUFFER_Front( h->inputBuffer ); - - IF( JB4_playoutDelay( h, sysTime, firstDu->timeStamp, &currPlayoutDelay ) != 0 ) + if( JB4_playoutDelay( h, sysTime, firstDu->timeStamp, &currPlayoutDelay ) != 0 ) { *prebuffer = true; - move16(); return; } - - IF( L_sub(L_add(currPlayoutDelay, L_shr(h->frameDuration, 1)), targetStartUp) < 0 ) /* time stretching */ + if( currPlayoutDelay + h->frameDuration / 2 < targetStartUp ) /* time stretching */ { *prebuffer = true; - move16(); } - ELSE /* no adaptation, start playout */ + else /* no adaptation, start playout */ { *prebuffer = false; - move16(); } } /* function to look into the buffer and check if it makes sense to drop a data unit */ -static Word16 JB4_inspectBufferForDropping( const JB4_HANDLE h, Word16 *dropEarly, Word32 *buffered ) +static int JB4_inspectBufferForDropping( const JB4_HANDLE h, bool_t *dropEarly, uint32_t *buffered ) { - Word16 inputBufferSize; - Word32 tsDiff, bufferedTs, endTs; + unsigned int inputBufferSize; + int16_t seqNrDiff; + int32_t bufferedTs; + uint32_t firstTs; + uint64_t beginTs, endTs; JB4_DATAUNIT_HANDLE firstDu, secondDu, lastDu; assert( !h->lastPoppedWasSilence ); *dropEarly = false; - move16(); - *buffered = L_deposit_l(0); + *buffered = 0; inputBufferSize = JB4_INPUTBUFFER_Size( h->inputBuffer ); - - IF( inputBufferSize == 0 ) + if( inputBufferSize == 0U ) { return -1; } firstDu = (JB4_DATAUNIT_HANDLE)JB4_INPUTBUFFER_Front( h->inputBuffer ); - tsDiff = L_deposit_l(0); - /* check for loss: timestamp diff is exactly 0 in the valid case */ - IF( h->firstDataUnitPopped ) + firstTs = firstDu->timeStamp; + /* check for loss: sequence number diff is exactly 0 in the valid case */ + if( h->firstDataUnitPopped ) { - tsDiff = JB4_rtpTimeStampDiff( h->nextExpectedTs, firstDu->timeStamp ); + seqNrDiff = JB4_rtpTimeStampDiff( h->nextExpectedTs, firstTs ) / + (int32_t)(h->frameDuration); } - - IF( tsDiff <= 0 ) + else + { + seqNrDiff = 0; + } + if( seqNrDiff <= 0 ) { /* preview data unit to play after dropping */ - IF( sub(inputBufferSize, 1) <= 0 ) + if( inputBufferSize <= 1U ) { /* data unit to play missing, avoid drop followed by concealment */ return -1; } secondDu = (JB4_DATAUNIT_HANDLE)JB4_INPUTBUFFER_Element( h->inputBuffer, 1 ); - - IF( rtpTs_sub(rtpTs_add(firstDu->timeStamp, h->frameDuration), secondDu->timeStamp) != 0 ) + if( firstTs + h->frameDuration != secondDu->timeStamp ) { /* data unit to play is not available, avoid drop followed by concealment */ return -1; } /* calculate buffered time span */ - bufferedTs = L_deposit_l(0); + bufferedTs = 0; } - ELSE IF( rtpTs_sub(tsDiff, L_mult0(2, extract_l(h->frameDuration))) == 0 ) + else if( seqNrDiff == 2 ) { /* data unit to play is not available, avoid dropping followed by concealment */ return -1; } - ELSE /* seqNoDiff == 1 || seqNoDiff > 2 */ + else /* seqNoDiff == 1 || seqNoDiff > 2 */ { /* first data unit is not available -> drop it early to avoid concealment * This is very aggressive: ignores the maximum drop rate (50% drop and 50% concealment for adjacent lost), * but on the other hand, dropping sounds better than concealment. */ *dropEarly = true; - move16(); /* data unit to drop (first one) is lost */ - bufferedTs = L_deposit_l(0); + bufferedTs = 0; } /* add time stamp difference of last and first actually buffered data unit */ - IF( sub(inputBufferSize, 1) == 0 ) + if( inputBufferSize == 1U ) { - bufferedTs = rtpTs_add(bufferedTs, h->frameDuration); + bufferedTs += h->frameDuration; } - ELSE + else { lastDu = (JB4_DATAUNIT_HANDLE)JB4_INPUTBUFFER_Back( h->inputBuffer ); - endTs = rtpTs_add(lastDu->timeStamp, h->frameDuration); + beginTs = firstTs; + endTs = lastDu->timeStamp + h->frameDuration; /* check for RTP time stamp wrap around */ - /* check if sign changes from negative to positive */ test(); - IF( L_and(firstDu->timeStamp, 0x80000000) != 0 && - L_and(endTs, 0x80000000) == 0 ) + if( endTs < beginTs ) { - endTs = rtpTs_add(endTs, 0xFFFFFFFF); + endTs = endTs + 0xFFFFFFFF; } - bufferedTs = rtpTs_add(bufferedTs, rtpTs_sub(endTs, firstDu->timeStamp)); + bufferedTs += (int32_t)(endTs - beginTs); } /* the result should not be negative */ - IF( bufferedTs < 0 ) + if( bufferedTs < 0 ) { return -1; } *buffered = bufferedTs; - move32(); + return 0; } /* function to look into the buffer and check if it makes sense to drop a data unit */ -static Word16 JB4_checkDtxDropping( const JB4_HANDLE h ) +static int JB4_checkDtxDropping( const JB4_HANDLE h ) { - Word16 inputBufferSize; + unsigned int inputBufferSize; + int16_t seqNrDiff; JB4_DATAUNIT_HANDLE firstDu; - Word16 droppingAllowed; + int droppingAllowed; + assert( h->firstDataUnitPopped ); assert( h->lastPoppedWasSilence ); droppingAllowed = 1; - move16(); inputBufferSize = JB4_INPUTBUFFER_Size( h->inputBuffer ); - - IF( inputBufferSize > 0 ) + if( inputBufferSize > 0U ) { firstDu = (JB4_DATAUNIT_HANDLE)JB4_INPUTBUFFER_Front( h->inputBuffer ); - /* check for loss */ - if( JB4_rtpTimeStampDiff( h->nextExpectedTs, firstDu->timeStamp ) <= 0 ) + /* check for loss: sequence number diff is exactly 0 in the valid case */ + seqNrDiff = JB4_rtpTimeStampDiff( h->nextExpectedTs, firstDu->timeStamp ) / + (int32_t)(h->frameDuration); + if( seqNrDiff <= 0 ) { /* no not drop first active frame */ droppingAllowed = 0; - move16(); } } - /* else: buffer empty, allow dropping FRAME_NO_DATA */ + /* else: buffer empty, allow dropping FRAME__NO_DATA */ + return droppingAllowed; } /* function to estimate the short term jitter */ -static void JB4_estimateShortTermJitter( JB4_HANDLE h, Word32 rcvTime, Word32 rtpTimeStamp ) +static void JB4_estimateShortTermJitter( JB4_HANDLE h, uint32_t rcvTime, uint32_t rtpTimeStamp ) { - Word32 stOffset, ltOffset, duration, maxDuration; - Word32 jitter, minTime, maxTime; + uint32_t jitter, duration, maxDuration; + int32_t minTime, maxTime; JB4_CIRCULARBUFFER_ELEMENT maxElement, dequedElement; - jitter = L_deposit_l(0); + + jitter = 0; JB4_JMF_PushPacket( h->stJmf, rcvTime, rtpTimeStamp ); /* save delta delay */ - IF( JB4_JMF_Jitter( h->stJmf, &jitter ) == 0 ) + if( JB4_JMF_Jitter( h->stJmf, &jitter ) == 0 ) { /* compensate difference between both offsets */ + int32_t stOffset, ltOffset; JB4_JMF_MinOffset( h->stJmf, &stOffset ); JB4_JMF_MinOffset( h->ltJmf, <Offset ); - jitter = L_add(jitter, L_sub(stOffset, ltOffset)); - assert( jitter >= 0 ); - - IF( JB4_CIRCULARBUFFER_IsFull( h->stJitterFifo ) ) + jitter += stOffset - ltOffset; + assert( (int)jitter >= 0 ); + if( JB4_CIRCULARBUFFER_IsFull( h->stJitterFifo ) ) { JB4_CIRCULARBUFFER_Deque( h->stJitterFifo, &dequedElement ); JB4_CIRCULARBUFFER_Deque( h->stTimeStampFifo, &dequedElement ); @@ -1051,69 +979,72 @@ static void JB4_estimateShortTermJitter( JB4_HANDLE h, Word32 rcvTime, Word32 rt /* check for duration and discard first entries if too long */ minTime = JB4_CIRCULARBUFFER_Front( h->stTimeStampFifo ); maxTime = JB4_CIRCULARBUFFER_Back( h->stTimeStampFifo ); - - duration = rtpTs_sub(maxTime, minTime); - IF( duration > 0 ) + if( maxTime > minTime ) { - maxDuration = L_mult0(4, h->timeScale); - WHILE( rtpTs_sub(duration, maxDuration) > 0 ) + duration = maxTime - minTime; + maxDuration = 4 * h->timeScale; + while( duration > maxDuration ) { JB4_CIRCULARBUFFER_Deque( h->stJitterFifo, &dequedElement ); JB4_CIRCULARBUFFER_Deque( h->stTimeStampFifo, &dequedElement ); minTime = JB4_CIRCULARBUFFER_Front( h->stTimeStampFifo ); - duration = rtpTs_sub(maxTime, minTime); - IF( duration <= 0) + if( maxTime <= minTime ) { - BREAK; + break; } + duration = maxTime - minTime; } } } /* update h->stJitter */ - IF( !JB4_CIRCULARBUFFER_IsEmpty( h->stJitterFifo ) ) + if( !JB4_CIRCULARBUFFER_IsEmpty( h->stJitterFifo ) ) { JB4_CIRCULARBUFFER_Max( h->stJitterFifo, &maxElement ); /* round up to full frame duration */ - h->stJitter = L_add(maxElement, L_sub(h->frameDuration, 1)); - h->stJitter = L_mult0(idiv1616(extract_l(h->stJitter), extract_l(h->frameDuration)), extract_l(h->frameDuration)); + h->stJitter = (uint32_t)ceil( (double)( maxElement ) / h->frameDuration ) * + h->frameDuration; } + } /* function to pop a data unit from the buffer */ -static void JB4_popFromBuffer( JB4_HANDLE h, Word32 sysTime, JB4_DATAUNIT_HANDLE *pDataUnit ) +static void JB4_popFromBuffer( JB4_HANDLE h, uint32_t sysTime, JB4_DATAUNIT_HANDLE *pDataUnit ) { JB4_DATAUNIT_HANDLE nextDataUnit; - Word32 nStretched, tsDiff; + uint32_t nStretched; + int32_t tsDiff; JB4_DATAUNIT_HANDLE tempDataUnit; - Word32 readlen ; - Word16 i; - Word32 frameoffset; - Word32 maxval, lost, total_rec ; + unsigned int readlen ; + unsigned short i; + int frameoffset; + unsigned int maxval; + + Word32 lost, total_rec ; JB4_DATAUNIT_HANDLE partialCopyDu; - Word16 searchpos, endpos; + unsigned int searchpos, endpos; + /* check if a data unit is available */ - IF( JB4_INPUTBUFFER_IsEmpty( h->inputBuffer ) ) + if( JB4_INPUTBUFFER_IsEmpty( h->inputBuffer ) ) { /* no data unit available */ *pDataUnit = NULL; - move16(); - h->nextExpectedTs = rtpTs_add(h->nextExpectedTs, h->frameDuration); + h->nextExpectedTs += h->frameDuration; + if( h->lastPoppedWasSilence ) + { + ++h->nComfortNoice; + } + else + { + ++h->nUnavailablePopped; + ++h->nLostOrStretched; + } - IF( h->lastPoppedWasSilence ) - { - h->nComfortNoice = L_add(h->nComfortNoice, 1); - } - ELSE - { - h->nUnavailablePopped = L_add(h->nUnavailablePopped, 1); - h->nLostOrStretched = L_add(h->nLostOrStretched, 1); - } return; } @@ -1121,201 +1052,174 @@ static void JB4_popFromBuffer( JB4_HANDLE h, Word32 sysTime, JB4_DATAUNIT_HANDLE nextDataUnit = (JB4_DATAUNIT_HANDLE)JB4_INPUTBUFFER_Front( h->inputBuffer ); /* check if this is the first data unit */ - IF( !h->firstDataUnitPopped ) + if( !h->firstDataUnitPopped ) { h->firstDataUnitPopped = true; - move16(); /* adjust sequence numbers to avoid handling first packet as loss */ h->nextExpectedTs = nextDataUnit->timeStamp; - move32(); } /* check if the next available data unit should already be used (time stamp order) */ tsDiff = JB4_rtpTimeStampDiff( nextDataUnit->timeStamp, h->nextExpectedTs ); h->totWin += 1; - move16(); - test(); - IF ( ( L_sub(h->totWin , 3000) > 0) || ( L_sub( h->FecOffWinLen , 100) >0 ) ) + if ( ( h->totWin > 3000) || ( h->FecOffWinLen > 100 ) ) { maxval = h->FecOffWin[1]; - move16(); h->optimum_offset = 1; - move16(); - FOR( i = 2; i < MAXOFFSET ; i++ ) + for( i = 2; i < MAXOFFSET ; i++ ) { - IF ( L_sub( h->FecOffWin[i], maxval ) > 0 ) + if ( h->FecOffWin[i] > maxval ) { maxval = h->FecOffWin[i] ; - move16(); h->optimum_offset = i ; - move16(); } h->FecOffWin[i] = 0; - move16(); } h->FecOffWin[0] = 0; - move16(); h->FecOffWin[1] = 0; - move16(); h->totWin = 0; - move16(); h->FecOffWinLen = 0; - move16(); - lost = L_sub( L_add(h->nLost, h->nPartialCopiesUsed), h->last_nLost ); - total_rec = L_sub( L_add(h->nAvailablePopped , h->nUnavailablePopped), h->last_ntot ); - IF ( lost != 0 && total_rec != 0 ) + lost =h->nLost+ h->nPartialCopiesUsed - h->last_nLost ; + total_rec = h->nAvailablePopped + h->nUnavailablePopped - h->last_ntot ; + + if ( lost != 0 && total_rec != 0 ) { - h->netLossRate = divide3232( lost , total_rec ); + h->netLossRate = (float)lost/(float)total_rec; } - ELSE + else { - h->netLossRate = 0; + h->netLossRate = 0.0f; } h->last_nLost = L_add(h->nLost, h->nPartialCopiesUsed); h->last_ntot = L_add(h->nAvailablePopped , h->nUnavailablePopped); + } - - - IF( tsDiff < 0 ) + if( tsDiff < 0 ) { - - readlen = JB4_INPUTBUFFER_Size( h->inputBuffer ); - move16(); - FOR ( i=0; i < readlen; i++) + for ( i=0; i < readlen; i++) { tempDataUnit = (JB4_DATAUNIT_HANDLE)JB4_INPUTBUFFER_Element( h->inputBuffer, i ); - - test(); - IF ( tempDataUnit->partial_frame == 0 && h->lastPoppedWasSilence == 0 ) + if ( ! tempDataUnit->partial_frame && !h->lastPoppedWasSilence ) { - frameoffset = Mult_32_16(JB4_rtpTimeStampDiff( h->nextExpectedTs, tempDataUnit->timeStamp ), 1639 ) ; /* divide by 20 */ - test(); - IF ( frameoffset > 0 && (L_sub( frameoffset, MAXOFFSET) < 0) ) + frameoffset = JB4_rtpTimeStampDiff( h->nextExpectedTs, tempDataUnit->timeStamp )/20 ; + + if ( frameoffset > 0 && frameoffset < MAXOFFSET ) { - h->FecOffWin[frameoffset] = L_add(h->FecOffWin[frameoffset], 1); + h->FecOffWin[frameoffset] += 1; } } } - - h->FecOffWinLen = L_add (h->FecOffWinLen, 1); - + h->FecOffWinLen += 1; /* next expected data unit is missing - * -> conceal network loss, do time stretching or create comfort noice */ + * -> conceal network loss, do time stretching or create comfort noise */ *pDataUnit = NULL; /* update statistics */ - h->nextExpectedTs = rtpTs_add(h->nextExpectedTs, h->frameDuration); - - IF( h->lastPoppedWasSilence ) + h->nextExpectedTs += h->frameDuration; + if( h->lastPoppedWasSilence ) { - h->nComfortNoice = L_add(h->nComfortNoice, 1); + ++h->nComfortNoice; } - ELSE + else { - h->nUnavailablePopped = L_add(h->nUnavailablePopped, 1); - h->nLostOrStretched = L_add(h->nLostOrStretched, 1); + ++h->nUnavailablePopped; + ++h->nLostOrStretched; } return; } /* fetch the next data unit from buffer */ *pDataUnit = nextDataUnit; - move16(); nextDataUnit->nextCoderType = INACTIVE; - IF( sub(h->pre_partial_frame,1) == 0 || sub(nextDataUnit->partial_frame,1) == 0 ) + if ( h->pre_partial_frame || nextDataUnit->partial_frame ) { - IF( nextDataUnit->partial_frame ) + if ( nextDataUnit->partial_frame ) { h->pre_partial_frame = 1; } - ELSE IF( h->pre_partial_frame ) + else if ( h->pre_partial_frame ) { h->pre_partial_frame = 0; } endpos = JB4_INPUTBUFFER_Size(h->inputBuffer); - FOR(searchpos = 0; searchpos < endpos; searchpos++) + for(searchpos = 0; searchpos < endpos; searchpos++) { partialCopyDu = (JB4_DATAUNIT_HANDLE)JB4_INPUTBUFFER_Element(h->inputBuffer, searchpos); - IF ( L_sub(partialCopyDu->timeStamp,L_add(nextDataUnit->timeStamp,partialCopyDu->duration)) == 0) + if ( partialCopyDu->timeStamp == nextDataUnit->timeStamp + partialCopyDu->duration ) { - get_NextCoderType_fx( partialCopyDu->data, &nextDataUnit->nextCoderType); + get_NextCoderType( partialCopyDu->data, &nextDataUnit->nextCoderType); break; } } } JB4_INPUTBUFFER_Deque( h->inputBuffer, (void**)pDataUnit ); - - IF ( sub(nextDataUnit->partial_frame,1) == 0 ) + if ( nextDataUnit->partial_frame ) { + h->nPartialCopiesUsed += 1; - h->nPartialCopiesUsed = L_add(h->nPartialCopiesUsed, 1); readlen = JB4_INPUTBUFFER_Size( h->inputBuffer ); - move16(); - FOR ( i=0; i < readlen; i++) + for ( i=0; i < readlen; i++) { tempDataUnit = (JB4_DATAUNIT_HANDLE)JB4_INPUTBUFFER_Element( h->inputBuffer, i ); - test(); - IF ( tempDataUnit->partial_frame == 0 && h->lastPoppedWasSilence == 0 ) + if ( ! tempDataUnit->partial_frame && !h->lastPoppedWasSilence ) { - frameoffset = Mult_32_16(JB4_rtpTimeStampDiff( h->nextExpectedTs, tempDataUnit->timeStamp ), 1639 ) ; - test(); - IF ( frameoffset > 0 && (L_sub( frameoffset, MAXOFFSET) < 0) ) + frameoffset = JB4_rtpTimeStampDiff( h->nextExpectedTs, tempDataUnit->timeStamp )/20 ; + + if ( frameoffset > 0 && frameoffset < MAXOFFSET ) { - h->FecOffWin[frameoffset] = L_add(h->FecOffWin[frameoffset], 1); + h->FecOffWin[frameoffset] += 1; } } } - - h->FecOffWinLen = L_add (h->FecOffWinLen, 1); + h->FecOffWinLen += 1; } - - - /* update statistics */ - IF( h->nLostOrStretched != 0U ) + if( h->nLostOrStretched != 0U ) { assert( h->lastPoppedWasSilence == false ); /* separate concealments since last available pop in lost and stretched */ - nStretched = idiv3216(tsDiff, extract_l(h->frameDuration)); - assert( nStretched == tsDiff / h->frameDuration ); + nStretched = tsDiff / h->frameDuration; assert( h->nLostOrStretched >= nStretched ); - h->nLost = L_add(h->nLost, L_sub(h->nLostOrStretched, nStretched)); + h->nLost += h->nLostOrStretched - nStretched; /* jitter-induced insertion (e.g. buffer underflow) */ - h->jitterInducedConcealments = L_add(h->jitterInducedConcealments, nStretched); - h->nStretched = L_add(h->nStretched, nStretched); - h->nLostOrStretched = L_deposit_l(0); + h->jitterInducedConcealments += nStretched; + h->nStretched += nStretched; + h->nLostOrStretched = 0; } h->lastReturnedTs = nextDataUnit->timeStamp; - move32(); JB4_updateLastTimingMembers( h, sysTime, nextDataUnit->timeStamp ); - h->nextExpectedTs = rtpTs_add(nextDataUnit->timeStamp, h->frameDuration); - + h->nextExpectedTs = nextDataUnit->timeStamp + h->frameDuration; if( nextDataUnit->silenceIndicator ) - h->nComfortNoice = L_add(h->nComfortNoice, 1); - if( !nextDataUnit->silenceIndicator ) - h->nAvailablePopped = L_add(h->nAvailablePopped, 1); - h->lastPoppedWasSilence = nextDataUnit->silenceIndicator; - move16(); + { + h->lastPoppedWasSilence = true; + ++h->nComfortNoice; + } + else + { + h->lastPoppedWasSilence = false; + ++h->nAvailablePopped; + } } /* function to drop a data unit from the buffer - updates nShrinked */ -static void JB4_dropFromBuffer( JB4_HANDLE h, Word32 sysTime ) +static void JB4_dropFromBuffer( JB4_HANDLE h, uint32_t sysTime ) { JB4_DATAUNIT_HANDLE nextDataUnit, dataUnit; - Word32 tsDiff, nStretched; + int32_t tsDiff; + uint32_t nStretched; (void)sysTime; /* check if a data unit is available */ - IF( JB4_INPUTBUFFER_IsEmpty( h->inputBuffer ) ) + if( JB4_INPUTBUFFER_IsEmpty( h->inputBuffer ) ) { return; } @@ -1323,37 +1227,32 @@ static void JB4_dropFromBuffer( JB4_HANDLE h, Word32 sysTime ) nextDataUnit = (JB4_DATAUNIT_HANDLE)JB4_INPUTBUFFER_Front( h->inputBuffer ); /* check if this is the first data unit */ - IF( !h->firstDataUnitPopped ) + if( !h->firstDataUnitPopped ) { h->firstDataUnitPopped = true; - move16(); /* adjust sequence numbers to avoid handling first packet as loss */ h->nextExpectedTs = nextDataUnit->timeStamp; - move32(); } /* check if the next available data unit should already be used (time stamp order) */ tsDiff = JB4_rtpTimeStampDiff( nextDataUnit->timeStamp, h->nextExpectedTs ); - - IF( tsDiff < 0 ) + if( tsDiff < 0 ) { /* next expected data unit is missing, remember this data unit as popped, * but do not count it as lost, because it will not be concealed */ - h->nextExpectedTs = rtpTs_add(h->nextExpectedTs, h->frameDuration); + h->nextExpectedTs += h->frameDuration; /* substract one frame from last playout delay */ - h->lastPlayoutOffset = rtpTs_sub(h->lastPlayoutOffset, h->frameDuration); - - IF( !h->lastPoppedWasSilence ) + h->lastPlayoutOffset -= h->frameDuration; + if( !h->lastPoppedWasSilence ) { - h->nShrinked = L_add(h->nShrinked, 1); + ++h->nShrinked; /* modification of the output timeline due to link loss */ - h->nUnavailablePopped = L_add(h->nUnavailablePopped, 1); - h->nLostOrStretched = L_add(h->nLostOrStretched, 1); + ++h->nUnavailablePopped; + ++h->nLostOrStretched; } - - if( h->lastTargetTime != 0 ) + if( h->lastTargetTime != 0U ) { - h->lastTargetTime = L_add(h->lastTargetTime, h->frameDuration); + h->lastTargetTime += h->frameDuration; } return; } @@ -1361,135 +1260,128 @@ static void JB4_dropFromBuffer( JB4_HANDLE h, Word32 sysTime ) /* fetch the next data unit from buffer */ JB4_INPUTBUFFER_Deque( h->inputBuffer, (void **)&dataUnit ); /* update statistics */ - IF( h->nLostOrStretched != 0U ) + if( h->nLostOrStretched != 0U ) { assert( h->lastPoppedWasSilence == false ); /* separate concealments since last available pop in lost and stretched */ - nStretched = idiv3216(tsDiff, extract_l(h->frameDuration)); - assert( nStretched == tsDiff / h->frameDuration ); + nStretched = tsDiff / h->frameDuration; assert( h->nLostOrStretched >= nStretched ); /* convert stretching followed by shrinking to late-loss */ - IF( nStretched > 0 ) + if( nStretched > 0U ) { - nStretched = L_sub(nStretched, 1); - h->nLateLost = L_add(h->nLateLost, 1); - h->nLost = L_add(h->nLost , L_sub(h->nLostOrStretched, nStretched)); + --nStretched; + ++h->nLateLost; + h->nLost += h->nLostOrStretched - nStretched; /* jitter-induced insertion (e.g. buffer underflow) */ - h->jitterInducedConcealments = L_add(h->jitterInducedConcealments, nStretched); - + h->jitterInducedConcealments += nStretched; if( !dataUnit->silenceIndicator ) { /* JBM induced removal of a speech frame (intentional frame dropping) */ - h->jitterInducedConcealments = L_add(h->jitterInducedConcealments, 1); + ++h->jitterInducedConcealments; } - h->nStretched = L_add(h->nStretched, nStretched); + h->nStretched += nStretched; } - ELSE + else { - h->nLost = L_add(h->nLost, h->nLostOrStretched); - h->nShrinked = L_add(h->nShrinked, 1); + h->nLost += h->nLostOrStretched; + ++h->nShrinked; if( !dataUnit->silenceIndicator ) { /* JBM induced removal of a speech frame (intentional frame dropping) */ - h->jitterInducedConcealments = L_add(h->jitterInducedConcealments, 1); + ++h->jitterInducedConcealments; } } - h->nLostOrStretched = L_deposit_l(0); + h->nLostOrStretched = 0; } - ELSE IF( !dataUnit->silenceIndicator ) + else { - h->nShrinked = L_add(h->nShrinked, 1); - /* JBM induced removal of a speech frame (intentional frame dropping) */ - h->jitterInducedConcealments = L_add(h->jitterInducedConcealments, 1); + if( !dataUnit->silenceIndicator ) + { + ++h->nShrinked; + /* JBM induced removal of a speech frame (intentional frame dropping) */ + ++h->jitterInducedConcealments; + } } h->lastReturnedTs = dataUnit->timeStamp; - move32(); h->lastPoppedWasSilence = dataUnit->silenceIndicator; - move16(); - h->nextExpectedTs = rtpTs_add(dataUnit->timeStamp, h->frameDuration); + h->nextExpectedTs = dataUnit->timeStamp + h->frameDuration; /* substract one frame from last playout delay */ - h->lastPlayoutOffset = rtpTs_sub(h->lastPlayoutOffset, h->frameDuration); - - if( h->lastTargetTime != 0 ) - h->lastTargetTime = L_add(h->lastTargetTime, h->frameDuration); + h->lastPlayoutOffset -= h->frameDuration; + if( h->lastTargetTime != 0U ) + h->lastTargetTime += h->frameDuration; JB4_FreeDataUnit(h, dataUnit); } /* function to calculate the playout delay based on the current jitter */ -static Word16 JB4_playoutDelay( const JB4_HANDLE h, Word32 playTime, Word32 rtpTimeStamp, Word32 *delay ) +static int JB4_playoutDelay( const JB4_HANDLE h, uint32_t playTime, uint32_t rtpTimeStamp, uint32_t *delay ) { - Word32 minOffTicks; + int32_t minOffTicks; - IF( JB4_JMF_MinOffset( h->ltJmf, &minOffTicks ) != 0 ) + if( JB4_JMF_MinOffset( h->ltJmf, &minOffTicks ) != 0 ) { return -1; } - *delay = rtpTs_sub(rtpTs_sub(playTime, minOffTicks), rtpTimeStamp); + *delay = playTime - minOffTicks - rtpTimeStamp; + return 0; } /* function to update lastPlayoutDelay and lastTargetTime after popFromBuffer() */ -static void JB4_updateLastTimingMembers( JB4_HANDLE h, Word32 playTime, Word32 rtpTimeStamp ) +static void JB4_updateLastTimingMembers( JB4_HANDLE h, uint32_t playTime, + uint32_t rtpTimeStamp ) { - Word32 minOffTicks; + int32_t minOffTicks; - IF( JB4_JMF_MinOffset( h->ltJmf, &minOffTicks ) != 0 ) + if( JB4_JMF_MinOffset( h->ltJmf, &minOffTicks ) != 0 ) { return; } /* playoutDelay = playTime - minOffset - timeStamp */ - h->lastPlayoutOffset = rtpTs_sub(playTime, rtpTimeStamp); + h->lastPlayoutOffset = playTime - rtpTimeStamp; /* targetTime = minOffset + timeStamp + targetDelay */ - h->lastTargetTime = rtpTs_add(rtpTs_add(minOffTicks, rtpTimeStamp), h->targetPlayoutDelay); + h->lastTargetTime = (uint32_t)( minOffTicks + rtpTimeStamp + h->targetPlayoutDelay ); + } /* function to compare the RTP time stamps of two data units: newElement==arrayElement ? 0 : (newElement>arrayElement ? +1 : -1) */ -static Word32 JB4_inputBufferCompareFunction( const JB4_INPUTBUFFER_ELEMENT newElement, - const JB4_INPUTBUFFER_ELEMENT arrayElement, Word16 *replaceWithNewElementIfEqual ) +static int JB4_inputBufferCompareFunction( const JB4_INPUTBUFFER_ELEMENT newElement, + const JB4_INPUTBUFFER_ELEMENT arrayElement, bool_t *replaceWithNewElementIfEqual ) { JB4_DATAUNIT_HANDLE newDataUnit, arrayDataUnit; - Word32 diff, result; + int32_t diff; + int result; *replaceWithNewElementIfEqual = 0; - move16(); newDataUnit = (JB4_DATAUNIT_HANDLE)newElement; - move16(); arrayDataUnit = (JB4_DATAUNIT_HANDLE)arrayElement; - move16(); diff = JB4_rtpTimeStampDiff( arrayDataUnit->timeStamp, newDataUnit->timeStamp ); - - IF( diff > 0 ) + if( diff > 0 ) { - result = L_deposit_l(1); + result = 1; } - ELSE IF( diff < 0 ) + else if( diff < 0 ) { - result = L_negate(1); + result = -1; } - ELSE /* equal timestamps */ + else /* equal timestamps */ { result = 0; - move32(); - test(); - IF(newDataUnit->partial_frame == 0 && arrayDataUnit->partial_frame != 0) + if(newDataUnit->partial_frame == 0 && arrayDataUnit->partial_frame == 1) { /* replace partial copy with primary copy */ *replaceWithNewElementIfEqual = 1; - move16(); } - ELSE IF(sub(newDataUnit->partial_frame, arrayDataUnit->partial_frame) == 0 && - L_sub(newDataUnit->dataSize, arrayDataUnit->dataSize) > 0) + else if(newDataUnit->partial_frame == arrayDataUnit->partial_frame && + newDataUnit->dataSize > arrayDataUnit->dataSize) { /* if both are primary or partial: take the one with higher size (e.g. higher bitrate) */ *replaceWithNewElementIfEqual = 1; - move16(); } } return result; } - diff --git a/src/libs/libevs/lib_dec/jbm_jb4sb.h b/src/libs/libevs/lib_dec/jbm_jb4sb.h old mode 100755 new mode 100644 index a871c176..61bc6e7b --- a/src/libs/libevs/lib_dec/jbm_jb4sb.h +++ b/src/libs/libevs/lib_dec/jbm_jb4sb.h @@ -1,11 +1,13 @@ /*==================================================================================== - EVS Codec 3GPP TS26.442 Apr 03, 2018. Version 12.11.0 / 13.6.0 / 14.2.0 + EVS Codec 3GPP TS26.443 Nov 13, 2018. Version 12.11.0 / 13.7.0 / 14.3.0 / 15.1.0 ====================================================================================*/ -/** \file jbm_jb4sb.h Jitter Buffer Management Interface */ +/** \file jbm_jb4sb.h EVS Jitter Buffer Management Interface */ -#ifndef ACE_JB4SB_H -#define ACE_JB4SB_H ACE_JB4SB_H +#ifndef JBM_JB4SB_H +#define JBM_JB4SB_H JBM_JB4SB_H + +#include "jbm_types.h" /** handle for jitter buffer */ typedef struct JB4* JB4_HANDLE; @@ -14,52 +16,53 @@ typedef struct JB4* JB4_HANDLE; struct JB4_DATAUNIT { /** the RTP sequence number (16 bits) */ - Word16 sequenceNumber; + uint16_t sequenceNumber; /** the RTP time stamp (32 bits) of this chunk in timeScale() units */ - Word32 timeStamp; + uint32_t timeStamp; /** the duration of this chunk in timeScale() units */ - Word32 duration; + uint32_t duration; /** the RTP time scale, which is used for timeStamp() and duration() */ - Word32 timeScale; + uint32_t timeScale; /** the receive time of the RTP packet in milliseconds */ - Word32 rcvTime; + uint32_t rcvTime; /** true, if the data unit contains only silence */ - Word16 silenceIndicator; + bool_t silenceIndicator; /** the binary encoded access unit */ - UWord8 *data; + uint8_t *data; /** the size of the binary encoded access unit [bits] */ - Word16 dataSize; + uint32_t dataSize; /** identify if the data unit has a partial copy of a previous frame */ - Word16 partial_frame; + bool_t partial_frame; /** offset of the partial copy contained in that frame or zero */ - Word16 partialCopyOffset; - Word16 nextCoderType; + int16_t partialCopyOffset; + int16_t nextCoderType; }; /** handle for jitter buffer data units */ typedef struct JB4_DATAUNIT* JB4_DATAUNIT_HANDLE; -Word16 JB4_Create( JB4_HANDLE *ph ); +int JB4_Create( JB4_HANDLE *ph ); void JB4_Destroy( JB4_HANDLE *ph ); -Word16 JB4_Init( JB4_HANDLE h, Word16 safetyMargin ); +int JB4_Init( JB4_HANDLE h, Word16 safetyMargin ); /** Returns a memory slot to store a new data unit */ JB4_DATAUNIT_HANDLE JB4_AllocDataUnit( JB4_HANDLE h ); /** Notifies the JBM that a data unit is no longer used and the memory can be reused */ void JB4_FreeDataUnit( JB4_HANDLE h, JB4_DATAUNIT_HANDLE dataUnit ); -Word16 JB4_PushDataUnit( JB4_HANDLE h, JB4_DATAUNIT_HANDLE dataUnit, Word32 rcvTime ); -Word16 JB4_PopDataUnit( JB4_HANDLE h, Word32 sysTime, Word32 extBufferedTime, - JB4_DATAUNIT_HANDLE *pDataUnit, Word16 *scale, Word16 *maxScaling ); +int JB4_PushDataUnit( JB4_HANDLE h, JB4_DATAUNIT_HANDLE dataUnit, uint32_t rcvTime ); +int JB4_PopDataUnit( JB4_HANDLE h, uint32_t sysTime, uint32_t extBufferedTime, + JB4_DATAUNIT_HANDLE *pDataUnit, uint32_t *scale, uint32_t *maxScaling ); + +int JB4_getFECoffset(JB4_HANDLE h); + +short JB4_FECoffset(JB4_HANDLE h); + /** function to get the number of data units contained in the buffer */ -Word16 JB4_bufferedDataUnits( const JB4_HANDLE h ); +unsigned int JB4_bufferedDataUnits( const JB4_HANDLE h ); -Word16 JB4_getFECoffset(JB4_HANDLE h); - -Word16 JB4_FECoffset(JB4_HANDLE h); - -#endif /* ACE_JB4SB_H */ +#endif /* JBM_JB4SB_H */ diff --git a/src/libs/libevs/lib_dec/jbm_pcmdsp_apa.cpp b/src/libs/libevs/lib_dec/jbm_pcmdsp_apa.cpp old mode 100755 new mode 100644 index 1597559f..6452c314 --- a/src/libs/libevs/lib_dec/jbm_pcmdsp_apa.cpp +++ b/src/libs/libevs/lib_dec/jbm_pcmdsp_apa.cpp @@ -1,21 +1,22 @@ /*==================================================================================== - EVS Codec 3GPP TS26.442 Apr 03, 2018. Version 12.11.0 / 13.6.0 / 14.2.0 + EVS Codec 3GPP TS26.443 Nov 13, 2018. Version 12.11.0 / 13.7.0 / 14.3.0 / 15.1.0 ====================================================================================*/ -/*! @file pcmdsp_apa.c Adaptive Playout for Audio (apa). */ +/*! @file jbm_pcmdsp_apa.c Adaptive Playout for Audio (apa). */ /* system headers */ #include +#include #include /* malloc(), free() */ #include -/* flc header */ -#include "stl.h" +#include "options.h" /* instrumentation */ /* local headers */ #include "jbm_pcmdsp_apa.h" #include "jbm_pcmdsp_similarityestimation.h" #include "jbm_pcmdsp_window.h" -#include "options.h" +#include "jbm_types.h" +#include "cnst.h" /* @@ -30,109 +31,101 @@ /* definition of state struct */ struct apa_state_t { - /* number of right shifts to be applied to the signal before correlation functions */ - Word16 signalScaleForCorrelation; - /* scaled input samples for similarity estimation */ - Word16 frmInScaled[2*48000/50]; /* output buffer */ - Word16 buf_out[APA_BUF]; - Word16 l_buf_out; + int16_t buf_out[APA_BUF]; + uint16_t l_buf_out; /* Hann window */ - const Word16 *win; - Word16 l_halfwin; - /* subsample factor used for Hann window - * used to step over x values for lower sample rates */ - Word16 win_incrementor; + Float win[APA_BUF]; + uint16_t l_halfwin; /* sampling rate [Hz] */ - Word32 rate; + uint16_t rate; /* length of a segment [samples] */ - Word16 l_seg; + uint16_t l_seg; /* length of a frame [samples] */ - Word16 l_frm; + uint16_t l_frm; /* total number of processed input samples since apa_reset() */ - Word32 l_in_total; + uint32_t l_in_total; /* sum of inserted/removed samples since last apa_set_scale() */ - Word32 diffSinceSetScale; + int32_t diffSinceSetScale; /* number of input frames since last apa_set_scale() */ - Word16 nFramesSinceSetScale; + uint32_t nFramesSinceSetScale; - /* current and previous scaling ratio [%]. */ - Word16 scale; + /* current and previous scaling ratio [%] */ + uint16_t scale; /* minimum pitch length [samples] */ - Word16 p_min; + uint16_t p_min; /* search length [samples] */ - Word16 l_search; + uint16_t l_search; - Word16 wss; /* waveform subsampling */ - Word16 css; /* correlation subsampling */ + uint16_t wss; /* waveform subsampling */ + uint16_t css; /* correlation subsampling */ - Word32 targetQualityQ16; /* Q15.16 */ - Word16 qualityred; /* quality reduction threshold */ - Word16 qualityrise; /* quality rising for adaptive quality thresholds */ + Float targetQuality; + uint16_t qualityred; /* quality reduction threshold */ + uint16_t qualityrise; /* quality rising for adaptive quality thresholds */ - Word16 last_pitch; /* last pitch/sync position */ - Word16 bad_frame_count; /* # frames before quality threshold is lowered */ - Word16 good_frame_count; /* # scaled frames */ + uint16_t last_pitch; /* last pitch/sync position */ + uint16_t bad_frame_count; /* # frames before quality threshold is lowered */ + uint16_t good_frame_count; /* # scaled frames */ - Word16 num_channels; /* number of input/output channels */ + uint16_t num_channels; /* number of input/output channels */ }; /* prototypes for local functions */ /** Converts the correlation energy to dB. */ -Word16 apa_corrEnergy2dB(Word32 energy, Word16 energyExp, Word16 corr_len); +float apa_corrEnergy2dB(float energy, uint16_t corr_len); /** Increases the calculated quality of signals with low energy. */ -Word16 apa_getQualityIncreaseForLowEnergy(Word16 energydB); +float apa_getQualityIncreaseForLowEnergy(float energydB); -static Word8 logarithmic_search(const apa_state_t * ps, - const Word16 * signal, - Word16 s_start, - Word16 inlen, - Word16 offset, - Word16 fixed_pos, - Word16 corr_len, - Word16 wss, - Word16 css, - Word16 * synchpos); +static bool_t logarithmic_search(const apa_state_t * ps, + const int16_t * signal, + int16_t s_start, + uint16_t inlen, + uint16_t offset, + uint16_t fixed_pos, + uint16_t corr_len, + uint16_t wss, + uint16_t css, + int16_t * synchpos); -static Word16 find_synch (apa_state_t * ps, - const Word16 * in, - Word16 l_in, - Word16 s_start, - Word16 s_len, - Word16 fixed_pos, - Word16 corr_len, - Word16 offset, - Word16 * energydBQ8, - Word32 * qualityQ16, - Word16 * synch_pos); +static bool_t find_synch (apa_state_t * ps, + const int16_t * in, + uint16_t l_in, + int16_t s_start, + uint16_t s_len, + int16_t fixed_pos, + uint16_t corr_len, + uint16_t offset, + Float * energy, + Float * quality, + int16_t * synch_pos); -static Word16 copy_frm (apa_state_t * ps, - const Word16 frm_in[], - Word16 frm_out[], - Word16 * l_frm_out); +static bool_t copy_frm (apa_state_t * ps, + const int16_t frm_in[], + int16_t frm_out[], + uint16_t * l_frm_out); -static Word16 shrink_frm (apa_state_t * ps, - const Word16 frm_in[], - Word16 maxScaling, - Word16 frm_out[], - Word16 * l_frm_out); - -static Word16 extend_frm (apa_state_t * ps, - const Word16 frm_in[], - Word16 frm_out[], - Word16 * l_frm_out); +static bool_t shrink_frm (apa_state_t * ps, + const int16_t frm_in[], + uint16_t maxScaling, + int16_t frm_out[], + uint16_t * l_frm_out); +static bool_t extend_frm (apa_state_t * ps, + const int16_t frm_in[], + int16_t frm_out[], + uint16_t * l_frm_out); /* ******************************************************************************** @@ -141,28 +134,24 @@ static Word16 extend_frm (apa_state_t * ps, */ /* Allocates memory for state struct and initializes elements. */ -Word8 apa_init (apa_state_t ** pps) +uint8_t apa_init (apa_state_t ** pps) { - apa_state_t *ps; - - ps = NULL; - move16(); + apa_state_t *ps = NULL; /* make sure pointer is valid */ - IF(!pps) + if(!pps) { return 1; } /* allocate state struct */ ps = (apa_state_t *) malloc (sizeof (apa_state_t)); - IF(!ps) + if(!ps) { return 2; } apa_reset (ps); *pps = ps; - move16(); return 0; } @@ -170,74 +159,51 @@ Word8 apa_init (apa_state_t ** pps) void apa_reset (apa_state_t * ps) { /* init state struct */ - ps->signalScaleForCorrelation = 0; - move16(); ps->l_buf_out = 0; - move16(); - ps->win = NULL; - move16(); ps->l_halfwin = 0; - move16(); - ps->win_incrementor = 0; - move16(); - ps->rate = L_deposit_l(0); + ps->rate = 0; ps->l_seg = 0; - move16(); ps->l_frm = 0; - move16(); - ps->l_in_total = L_deposit_l(0); - ps->diffSinceSetScale = L_deposit_l(0); + ps->l_in_total = 0; + ps->diffSinceSetScale = 0; ps->nFramesSinceSetScale = 0; - move16(); ps->scale = 100; - move16(); ps->p_min = 0; - move16(); ps->l_search = 0; - move16(); ps->wss = 1; - move16(); ps->css = 1; - move16(); - ps->targetQualityQ16 = L_deposit_l(0); + ps->targetQuality = 0.0f; ps->qualityred = 0; - move16(); ps->qualityrise = 0; - move16(); ps->last_pitch = 0; - move16(); ps->bad_frame_count = 0; - move16(); ps->good_frame_count = 0; - move16(); ps->num_channels = 0; - move16(); } /* Sets the audio configuration. */ -Word8 apa_set_rate( apa_state_t * ps, Word32 rate, Word16 num_channels ) +bool_t apa_set_rate (apa_state_t * ps, uint16_t rate, uint16_t num_channels) { - Word16 divScaleFac; - /* make sure pointer is valid */ - IF( ps == (apa_state_t *) NULL ) + if (ps == (apa_state_t *) NULL) { return 1; } - /* assert rate is actually matching one of the supported EVS rates otherwise Hann window is wrong */ - assert( rate == 8000 || rate == 16000 || rate == 24000 || rate == 32000 || rate == 48000 ); + /* check range */ + if ((rate < APA_MIN_RATE) || (rate > APA_MAX_RATE)) + { + return 1; + } /* reset state struct */ - apa_reset( ps ); + apa_reset (ps); /* copy rate to state struct */ ps->rate = rate; - move32(); /* set number of channels */ ps->num_channels = num_channels; - move16(); /* * several other parameters depend on the sampling rate @@ -248,103 +214,66 @@ Word8 apa_set_rate( apa_state_t * ps, Word32 rate, Word16 num_channels ) * samples at 16 kHz. */ - /* set frame size */ - /* set to 320 samples at 16 kHz */ - ps->l_frm = BASOP_Util_Divide3216_Scale( L_mult0_3216( ps->rate, ps->num_channels ), 50, &divScaleFac ); - ps->l_frm = shl( ps->l_frm, add( divScaleFac,1 ) ); - /* set segment size */ /* in the order of a pitch, set to 160 samples at 16 kHz */ /* used for windowing and as the correlation length, i.e., */ /* the size of the template segment. */ - /* before basop port was originally : ps->l_seg = ( ps->rate * ps->num_channels ) / 100 ); - * but whilst frm_size is still hard-coded the seg_size can be taken from half frm_size */ - ps->l_seg = shr( ps->l_frm, 1 ); + ps->l_seg = (ps->rate / 100) * ps->num_channels; /* init Hann window */ /* Note: l_win < APA_BUF is required, which is assured */ /* because APA_MAX_RATE/100 = l_win = 441 < 2048 = APA_BUF */ - /* Length of Hann window is independent of - * number of channels - same window applied to all channels. - * sample rates 24k & 48k lookup a Hann window of length of 48000/50=960, - * where 24k subsamples (skips every second sample) */ - ps->win = pcmdsp_window_hann_640; - move16(); - ps->l_halfwin = 320; - move16(); - ps->win_incrementor = 1; - move16(); - IF(L_sub(ps->rate, 48000) == 0) - { - ps->win = pcmdsp_window_hann_960; - move16(); - ps->l_halfwin = 480; - move16(); - } - IF(L_sub(ps->rate, 24000) == 0) - { - ps->win = pcmdsp_window_hann_960; - move16(); - ps->l_halfwin = 480; - move16(); - ps->win_incrementor = 2; - move16(); - } - /* sample rates 8k, 16k & 32k use a Hann window of length of 640, - * where 8k and 16k subsample */ - if(L_sub(ps->rate, 16000) == 0) - ps->win_incrementor = 2; - move16(); - if(L_sub(ps->rate, 8000) == 0) - ps->win_incrementor = 4; - move16(); + /* Length of Hann window should be independent of + * number of channels - same window applied to all channels */ + ps->l_halfwin = ps->rate / 100; + hannWindow (ps->l_halfwin*2, ps->win); + + /* set frame size */ + /* set to 320 samples at 16 kHz */ + ps->l_frm = (ps->rate / 50) * ps->num_channels; /* set minimum pitch */ /* set to 40 samples at 16 kHz */ /* (defines min change in number of samples, i.e., abs(l_in-l_out) >= p_min) */ - /* before basop port was originally: ps->p_min = (ps->rate * ps->num_channels) / 400; - * but for simplicity can be taken as l_seg / 4 */ - ps->p_min = shr( ps->l_seg, 2 ); + ps->p_min = (ps->rate / 400) * ps->num_channels; /* set search length */ /* must cover one pitch, set to 200 samples at 16 kHz */ /* (the resulting maximum pitch is then p_min+l_search = 240 samples at 16 kHz) */ - /* the following is equivalent to: ps->l_search = (ps->rate * ps->num_channels) / 80; */ - ps->l_search = BASOP_Util_Divide3216_Scale( L_mult0_3216( ps->rate, ps->num_channels ), 80, &divScaleFac ); - ps->l_search = shl( ps->l_search, add( divScaleFac,1 ) ); - - ps->signalScaleForCorrelation = getSignalScaleForCorrelation(ps->rate); + ps->l_search = (ps->rate / 80) * ps->num_channels; return 0; } /* Set scaling. */ -Word8 apa_set_scale (apa_state_t * ps, Word16 scale) +bool_t apa_set_scale (apa_state_t * ps, uint16_t scale) { /* make sure pointer is valid */ - IF( ps == (apa_state_t *) NULL) + if (ps == (apa_state_t *) NULL) { return 1; } /* check range */ - assert( scale >= APA_MIN_SCALE && scale <= APA_MAX_SCALE ); + if ((scale < APA_MIN_SCALE) || (scale > APA_MAX_SCALE)) + { + return 1; + } /* do nothing if same scale is set multiple times */ /* (otherwise scale control is confused) */ - IF( sub(ps->scale, scale) == 0 ) + if (ps->scale == scale) { return 0; } /* copy to state struct */ ps->scale = scale; - move16(); /* reset scaling statistics */ - ps->diffSinceSetScale = L_deposit_l(0); + ps->diffSinceSetScale = 0; ps->nFramesSinceSetScale = 0; - move16(); + return 0; } @@ -371,27 +300,22 @@ Word8 apa_set_scale (apa_state_t * ps, Word16 scale) * ******************************************************************************** */ -Word8 apa_set_quality( +bool_t apa_set_quality( apa_state_t *ps, - Word32 qualityQ16, - Word16 qualityred, - Word16 qualityrise) + float quality, + uint16_t qualityred, + uint16_t qualityrise) { assert(ps != (apa_state_t *) NULL); - assert(L_sub(L_deposit_h(-2), qualityQ16) <= 0 && L_sub(qualityQ16, L_deposit_h(3)) <= 0); - assert(qualityred > 0 && sub( qualityred, 20 ) <= 0); - assert(qualityrise > 0 && sub(qualityrise, 20) <= 0); + assert(-2.0f <= quality && quality <= 3.1f); + assert(qualityred > 0 && qualityred <= 20); + assert(qualityrise > 0 && qualityrise <= 20); - ps->targetQualityQ16 = qualityQ16; - move32(); + ps->targetQuality = quality; ps->qualityred = qualityred; - move16(); ps->qualityrise = qualityrise; - move16(); ps->bad_frame_count = 0; - move16(); ps->good_frame_count = 0; - move16(); return 0; } @@ -410,17 +334,17 @@ Word8 apa_set_quality( * ******************************************************************************** */ -Word8 apa_set_complexity_options (apa_state_t * ps, Word16 wss, Word16 css) +bool_t apa_set_complexity_options (apa_state_t * ps, uint16_t wss, uint16_t css) { /* make sure pointer is valid */ - assert( ps != NULL ); - assert( wss != 0 && wss <= 1000 ); - assert( css != 0 && css <= 1000 ); - + if (ps == (apa_state_t *) NULL) + return 1; + if (wss == 0 || wss > 1000) + return 1; + if (css == 0 || css > 1000) + return 1; ps->wss = wss; - move16(); ps->css = css; - move16(); return 0; } @@ -436,10 +360,10 @@ Word8 apa_set_complexity_options (apa_state_t * ps, Word16 wss, Word16 css) * ******************************************************************************** */ -Word8 apa_exit( apa_state_t ** pps ) +bool_t apa_exit (apa_state_t ** pps) { /* ignore NULL pointer input */ - IF( *pps == (apa_state_t *) NULL ) + if (*pps == (apa_state_t *) NULL) { return 0; } @@ -448,7 +372,6 @@ Word8 apa_exit( apa_state_t ** pps ) free (*pps); /* set pointer to NULL */ *pps = NULL; - move16(); return 0; } @@ -484,139 +407,117 @@ Word8 apa_exit( apa_state_t ** pps ) * ******************************************************************************** */ -Word8 apa_exec (apa_state_t * ps, /* i/o: state struct */ - const Word16 a_in[], /* i: input samples */ - Word16 l_in, /* i: number of input samples */ - Word16 maxScaling, /* i: allowed number of inserted/removed samples */ - Word16 a_out[], /* o: output samples */ - Word16 *l_out /* o: number of output samples */) +uint8_t apa_exec (apa_state_t * ps, /* i/o: state struct */ + const int16_t a_in[], /* i: input samples */ + uint16_t l_in, /* i: number of input samples */ + uint16_t maxScaling, /* i: allowed number of inserted/removed samples */ + int16_t a_out[], /* o: output samples */ + uint16_t * l_out /* o: number of output samples */) { - Word16 i; - Word16 frm_in[APA_BUF]; - Word16 l_frm_out; - Word16 l_rem; - Word32 dl_scaled, dl_copied, l_frm_out_target; - Word32 actScaling, expScaling; - Word16 *frm_in_ptr, *buf_out_ptr, *buf_out_ptr1, *buf_out_ptr2; - Word16 statsResetThreshold, statsResetShift; + uint16_t i; + int16_t frm_in[APA_BUF]; + uint16_t l_frm_out; + int16_t l_rem; + int32_t dl_scaled, dl_copied, l_frm_out_target; + int32_t expScaling, actScaling; + uint32_t statsResetThreshold, statsResetShift; statsResetThreshold = 1637; - move16(); statsResetShift = 2; - move16(); /* make sure no invalid output is used */ *l_out = 0; - move16(); l_frm_out = 0; - move16(); /* make sure pointer is valid */ - IF( ps == (apa_state_t *) NULL ) + if (ps == (apa_state_t *) NULL) { return 1; } /* check available rate */ - IF( ps->rate == 0 ) + if (ps->rate == 0) { return 2; } /* check size of input */ - IF( L_sub( l_in, ps->l_frm ) != 0 ) + if( l_in != ps->l_frm ) { return 3; } /* get target length */ - IF(s_or(sub(ps->l_frm, 480) == 0, sub(ps->l_frm, 960) == 0)) + if(ps->scale > 100) { - /* decomposite ps->l_frm into 15<l_frm)); - /* this only works for 20ms framing */ - assert(ps->l_frm == shl(shr(ps->l_frm, i), i)); - assert(i_mult2(sub(ps->scale, 100), add(ps->nFramesSinceSetScale, 1)) == (ps->scale - 100) * (ps->nFramesSinceSetScale + 1)); - expScaling = L_shr_r(L_mult0(i_mult2(sub(ps->scale, 100), add(ps->nFramesSinceSetScale, 1)), 19661/*15*(1<<2)/100.0 Q15*/), sub(15+2, i)); + expScaling = (int32_t)((ps->l_frm * (ps->scale - 100.0f) / 100.0f) * (ps->nFramesSinceSetScale + 1) + 0.5f); } - ELSE + else if(ps->scale < 100) { - /* decomposite ps->l_frm into 5<l_frm)); - /* this only works for 20ms framing */ - assert(ps->l_frm == shl(shr(ps->l_frm, i), i)); - assert(i_mult2(sub(ps->scale, 100), add(ps->nFramesSinceSetScale, 1)) == (ps->scale - 100) * (ps->nFramesSinceSetScale + 1)); - expScaling = L_shr_r(L_mult0(i_mult2(sub(ps->scale, 100), add(ps->nFramesSinceSetScale, 1)), 13107/*5*(1<<3)/100.0 Q15*/), sub(15+3, i)); + expScaling = (int32_t)((ps->l_frm * (ps->scale - 100.0f) / 100.0f) * (ps->nFramesSinceSetScale + 1) - 0.5f); } - assert( expScaling >= (ps->l_frm * (ps->scale - 100.0f) / 100.0f) * (ps->nFramesSinceSetScale + 1LL) - 3); - assert( expScaling <= (ps->l_frm * (ps->scale - 100.0f) / 100.0f) * (ps->nFramesSinceSetScale + 1LL) + 3); - actScaling = L_sub(ps->diffSinceSetScale, L_deposit_l(ps->l_frm)); - assert( actScaling == ps->diffSinceSetScale - ps->l_frm ); - /* target number of samples for output frame */ - l_frm_out_target = L_sub(expScaling, actScaling); - assert( l_frm_out_target == expScaling - actScaling ); + else + { + expScaling = 0; + } + actScaling = ps->diffSinceSetScale - ps->l_frm; + l_frm_out_target = expScaling - actScaling; /* Wait until we have l_frm outputs samples */ /* (required to search for correlation in the past). */ /* If we don't have enough samples, simply copy input to output */ - IF( sub( ps->l_buf_out, ps->l_frm ) < 0 ) + if (ps->l_buf_out < ps->l_frm) { - FOR( i = 0; i < ps->l_frm; i++ ) + for (i = 0; i < ps->l_frm; i++) { a_out[i] = a_in[i]; - move16(); } l_frm_out = ps->l_frm; - move16(); } - ELSE + else { - buf_out_ptr = &(ps->buf_out[ sub( ps->l_buf_out, ps->l_frm ) ]); - move16(); - frm_in_ptr = &(frm_in[ps->l_frm]); - move16(); + int16_t * buf_out_ptr = &(ps->buf_out[ps->l_buf_out - ps->l_frm]); + int16_t * frm_in_ptr = &(frm_in[ps->l_frm]); /* fill input frame */ /* 1st input frame: previous output samples */ - FOR( i = 0; i < ps->l_frm; i++ ) + for (i = 0; i < ps->l_frm; i++) { frm_in[i] = buf_out_ptr[i]; - move16(); } /* 2nd input frame: new input samples */ - FOR( i = 0; i < ps->l_frm; i++ ) + for (i = 0; i < ps->l_frm; i++) { frm_in_ptr[i] = a_in[i]; - move16(); } /* no scaling */ - IF( sub( ps->scale, 100 ) == 0 ) + if (ps->scale == 100) { copy_frm (ps, frm_in, a_out, &l_frm_out); } /* shrink */ - ELSE IF( sub( ps->scale, 100 ) < 0 ) + else if (ps->scale < 100) { shrink_frm (ps, frm_in, maxScaling, a_out, &l_frm_out); } /* extend */ - ELSE { + else + { extend_frm (ps, frm_in, a_out, &l_frm_out); } /* control the amount/frequency of scaling */ - IF( sub( l_frm_out, ps->l_frm ) != 0 ) + if( l_frm_out != ps->l_frm ) { - test(); - IF( maxScaling != 0U && - sub( abs_s( sub( ps->l_frm, l_frm_out) ), maxScaling ) > 0 ) + if( maxScaling != 0U && + abs( (int16_t)(ps->l_frm - l_frm_out) ) > maxScaling ) { /* maxScaling exceeded -> discard scaled frame */ copy_frm (ps, frm_in, a_out, &l_frm_out); } - ELSE IF( L_sub( L_abs( l_frm_out_target ), L_deposit_l(ps->l_frm) ) > 0 ) /* ignore small difference */ + else if( abs(l_frm_out_target) > ps->l_frm ) /* ignore small difference */ { - dl_copied = L_sub( l_frm_out_target, L_deposit_l(ps->l_frm) ); - dl_scaled = L_sub( l_frm_out_target, L_deposit_l(l_frm_out) ); + dl_copied = l_frm_out_target - (int32_t) ps->l_frm; + dl_scaled = l_frm_out_target - (int32_t) l_frm_out; /* discard scaled frame if copied frame is closer to target length */ - IF( L_sub( L_abs( dl_copied ), L_abs( dl_scaled ) ) < 0 ) + if( abs(dl_copied) < abs(dl_scaled) ) { copy_frm (ps, frm_in, a_out, &l_frm_out); } @@ -627,62 +528,53 @@ Word8 apa_exec (apa_state_t * ps, /* i/o: state struct */ /* copy output to internal buffer */ /* avoid buffer overflow: */ /* discard old samples; always keep at least most recent l_frm samples */ - IF ( sub( add( ps->l_buf_out, l_frm_out), APA_BUF ) > 0) + if ((ps->l_buf_out + l_frm_out) > APA_BUF) { - buf_out_ptr1 = ps->buf_out; - move16(); + int16_t * buf_out_ptr1 = ps->buf_out; + int16_t * buf_out_ptr2; - l_rem = sub( ps->l_frm, l_frm_out ); - if( l_rem < 0 ) + l_rem = (ps->l_frm - l_frm_out); + if (l_rem < 0) { l_rem = 0; - move16(); } - buf_out_ptr2 = &(ps->buf_out[ sub( ps->l_buf_out, l_rem )]); - move16(); - - FOR( i = 0; i < l_rem; i++ ) + buf_out_ptr2 = &(ps->buf_out[ps->l_buf_out - l_rem]); + for (i = 0; i < l_rem; i++) { buf_out_ptr1[i] = buf_out_ptr2[i]; - move16(); } ps->l_buf_out = l_rem; - move16(); } /* append new output samples */ - IF( sub( add( ps->l_buf_out, l_frm_out), APA_BUF ) > 0) + if ((ps->l_buf_out + l_frm_out) > APA_BUF) { return 5; } { - buf_out_ptr = &(ps->buf_out[ps->l_buf_out]); - FOR( i = 0; i < l_frm_out; i++) + int16_t * buf_out_ptr = &(ps->buf_out[ps->l_buf_out]); + for (i = 0; i < l_frm_out; i++) { buf_out_ptr[i] = a_out[i]; - move16(); } } - ps->l_buf_out = add( ps->l_buf_out, l_frm_out ); + ps->l_buf_out += l_frm_out; - /* check variable l_frm_out is non-negative since l_out being returned is unsigned */ - assert( l_frm_out >= 0 ); *l_out = l_frm_out; - move16(); - /* update statistics */ - ps->l_in_total = L_add( ps->l_in_total, L_deposit_l( ps->l_frm ) ); - test(); - IF( L_sub(L_abs(ps->diffSinceSetScale), - L_sub(0x7FFFFF, L_deposit_l(sub(l_frm_out, ps->l_frm)))) < 0 && - sub(ps->nFramesSinceSetScale, statsResetThreshold) < 0 ) + /* update time */ + ps->l_in_total += ps->l_frm; + + if( abs(ps->diffSinceSetScale) < (0x7FFFFF - (l_frm_out - ps->l_frm)) && + ps->nFramesSinceSetScale < statsResetThreshold ) { - ps->diffSinceSetScale = L_add(ps->diffSinceSetScale, L_deposit_l(sub(l_frm_out, ps->l_frm))); - ps->nFramesSinceSetScale = add(ps->nFramesSinceSetScale, 1); + ps->diffSinceSetScale += l_frm_out - ps->l_frm; + ++ps->nFramesSinceSetScale; } - ELSE /* scale statistics down to avoid overflow */ + else /* scale statistics down to avoid overflow */ { - ps->diffSinceSetScale = L_shr(ps->diffSinceSetScale, statsResetShift); - ps->nFramesSinceSetScale = shr(ps->nFramesSinceSetScale, statsResetShift); + ps->diffSinceSetScale >>= statsResetShift; + ps->nFramesSinceSetScale >>= statsResetShift; } + return 0; } @@ -693,163 +585,152 @@ Word8 apa_exec (apa_state_t * ps, /* i/o: state struct */ ******************************************************************************** */ + +/* +******************************************************************************** +* +* Function : get_scaling_quality +* Tables : +* Compile Defines : +* Return : 0 on success, 1 on failure +* Information : Uses pitch, half pitch, three halves and double pitch +* to evaluate the quality of the scaled frame by checking +* periodicity. +* Silence can be detected as additional feature. This must +* be set in global struct apa_state. +* +* If search length is very narrow then use fewer points +* to evaluate periodicity and silence. +* +* Computationally not very efficient by using normalized +* cross-correlation: Using sqrt() for energy calculation +* adds complexity. +* +* 03-AUG-04 S.Doehla initial version +* +******************************************************************************** +*/ static void get_scaling_quality(const apa_state_t * ps, - const Word16 * signal, - Word16 s_len, - Word16 offset, - Word16 corr_len, - Word16 pitch, - Word16 * energydBQ8, - Word32 * qualityQ16) + const int16_t * signal, + uint16_t s_len, + uint16_t offset, + uint16_t corr_len, + uint16_t pitch, + Float * energydB, + Float * quality) { - Word32 energy, maxEnergy; - Word32 qualityOfMaxEnergy; /* we measure the quality for all channels and select the one with highest energy */ - Word16 half_pitch_cn; - Word16 pitch_cn; - Word16 three_halves_pitch_cn; - Word16 double_pitch_cn; - Word32 pitch_energy; - Word32 half_pitch_energy; - Word32 three_halves_pitch_energy; - Word32 double_pitch_energy; - Word16 i; + Float maxEnergy = 0.0f; + Float qualityOfMaxEnergy = 0.0f; /* we measure the quality for all channels and select the one with highest energy */ + Float half_pitch_cn = 0.0f; + Float pitch_cn = 0.0f; + Float three_halves_pitch_cn = 0.0f; + Float double_pitch_cn = 0.0f; - maxEnergy = L_deposit_l(0); - qualityOfMaxEnergy = L_deposit_l(0); + Float pitch_energy = 0.0f; + Float half_pitch_energy = 0.0f; + Float three_halves_pitch_energy = 0.0f; + Float double_pitch_energy = 0.0f; - FOR( i=0; i < ps->num_channels; i++ ) + uint16_t i = 0; + + for(i=0; inum_channels; i++) { + Float energy; offset = 0; - move16(); - pitch_cn = normalized_cross_correlation_self(signal, add(pitch, offset), offset, corr_len, - shl(ps->num_channels, 1), &pitch_energy); - IF(pitch_cn > 0) + pitch_cn = normalized_cross_correlation_self(signal, pitch+offset, offset, corr_len, + ps->num_channels * 2, &pitch_energy); + if(pitch_cn > 0.0f) { /* calculate correlation for double pitch */ - IF(sub(add(add(shl(pitch, 1), offset), corr_len), s_len) <= 0) + if( 2*pitch + offset + corr_len <= s_len ) { - double_pitch_cn = normalized_cross_correlation_self(signal, add(shl(pitch, 1), offset), - offset, corr_len, shl(ps->num_channels, 1), &double_pitch_energy); + double_pitch_cn = normalized_cross_correlation_self(signal, 2*pitch + offset, + offset, corr_len, ps->num_channels * 2, &double_pitch_energy); } - ELSE + else { double_pitch_cn = pitch_cn; - move16(); - double_pitch_energy = L_add(pitch_energy, 0); + double_pitch_energy = pitch_energy; } /* calculate correlation for three/half pitch */ - IF(sub(add(add(shr(i_mult2(pitch, 3), 1), offset), corr_len), s_len) <= 0) + if( (3*pitch)/2 + offset + corr_len <= s_len ) { - three_halves_pitch_cn = normalized_cross_correlation_self(signal, add(shr(i_mult2(pitch, 3), 1), - offset), offset, corr_len, shl(ps->num_channels, 1), &three_halves_pitch_energy); + three_halves_pitch_cn = normalized_cross_correlation_self(signal, (3*pitch)/2 + offset, + offset, corr_len, ps->num_channels * 2, &three_halves_pitch_energy); } - ELSE + else { three_halves_pitch_cn = pitch_cn; - move16(); - three_halves_pitch_energy = L_add(pitch_energy, 0); + three_halves_pitch_energy = pitch_energy; } /* calculate correlation for half pitch */ - IF(sub(add(add(shr(pitch, 1), offset), corr_len), s_len) <= 0) + if( pitch/2 + offset + corr_len <= s_len ) { - half_pitch_cn = normalized_cross_correlation_self(signal, add(shr(pitch, 1), offset), - offset, corr_len, shl(ps->num_channels, 1), &half_pitch_energy); + half_pitch_cn = normalized_cross_correlation_self(signal, pitch/2 + offset, + offset, corr_len, ps->num_channels * 2, &half_pitch_energy); } - ELSE + else { half_pitch_cn = pitch_cn; - move16(); - half_pitch_energy = L_add(pitch_energy, 0); + half_pitch_energy = pitch_energy; } - /* combine correlation results: Q15.16 */ - *qualityQ16 = L_shr(L_mac0(L_mult0(half_pitch_cn, three_halves_pitch_cn), - pitch_cn, double_pitch_cn), 14); - BASOP_SATURATE_WARNING_OFF - energy = L_add(L_add(L_add(pitch_energy, half_pitch_energy), three_halves_pitch_energy), double_pitch_energy); - BASOP_SATURATE_WARNING_ON + /* combine correlation results */ + *quality = (half_pitch_cn * three_halves_pitch_cn) + (pitch_cn * double_pitch_cn); + energy = pitch_energy + half_pitch_energy + three_halves_pitch_energy + double_pitch_energy; } - ELSE + else { - *qualityQ16 = L_shl(L_deposit_l(pitch_cn), 1); /* value is negative, thus pass it */ - energy = L_add(pitch_energy, 0); + *quality = pitch_cn; /* value is negative, thus pass it */ + energy = pitch_energy; } /* update the quality by the quality of the signal with the highest energy */ - IF(L_sub(energy, maxEnergy) > 0) + if(energy > maxEnergy) { - qualityOfMaxEnergy = L_add(*qualityQ16, 0); - maxEnergy = L_add(energy, 0); + qualityOfMaxEnergy = *quality; + maxEnergy = energy; } /* go to next channel */ ++signal; } - *qualityQ16 = qualityOfMaxEnergy; - move32(); + *quality = qualityOfMaxEnergy; /* increase calculated quality of signals with low energy */ - *energydBQ8 = apa_corrEnergy2dB(maxEnergy, shl(ps->signalScaleForCorrelation, 1), corr_len); - *qualityQ16 = L_add(*qualityQ16, L_shl(L_deposit_l(apa_getQualityIncreaseForLowEnergy(*energydBQ8)), 8)); + *energydB = apa_corrEnergy2dB(maxEnergy, corr_len); + *quality += apa_getQualityIncreaseForLowEnergy(*energydB); } /* Converts the correlation energy to dB. */ -Word16 apa_corrEnergy2dB(Word32 energy, Word16 energyExp, Word16 corr_len) +float apa_corrEnergy2dB(float energy, uint16_t corr_len) { - - Word16 result, tmpScale; - - /* normalise before dividing */ - tmpScale = norm_l( energy ); - energy = L_shl( energy, tmpScale ); - energyExp = sub( energyExp, tmpScale ); - - /* divide energy by corr_len */ - result = BASOP_Util_Divide3216_Scale(energy, corr_len, &tmpScale); - energyExp = add(energyExp, tmpScale); - - result = BASOP_Util_lin2dB( L_deposit_l( result ), energyExp, 1 ); - return result; + float energydB = 10.0f * (float)log10(energy / (32768.0f * 32768.0f * corr_len * 4.0f)); + return energydB; } /* Increases the calculated quality of signals with low energy. */ -Word16 apa_getQualityIncreaseForLowEnergy(Word16 energydBQ8) +float apa_getQualityIncreaseForLowEnergy(float energydB) { - Word16 qualIncreaseMinEnergy, qualIncreaseMaxEnergy, qualIncForLowEnergy; /* Q8 */ - - qualIncreaseMinEnergy = -65 * (1 << 8); - move16(); - qualIncreaseMaxEnergy = -40 * (1 << 8); - move16(); - qualIncForLowEnergy = 0; - move16(); - - /* increase calculated quality of signals with low energy */ - IF(sub(energydBQ8, qualIncreaseMaxEnergy) < 0) + const float qualIncreaseMinEnergy = -65; + const float qualIncreaseMaxEnergy = -40; + float qualIncForLowEnergy = 0; + if(energydB < qualIncreaseMaxEnergy) { - qualIncForLowEnergy = energydBQ8; - move16(); - if(sub(qualIncForLowEnergy, qualIncreaseMinEnergy) < 0) + qualIncForLowEnergy = energydB; + if(qualIncForLowEnergy < qualIncreaseMinEnergy) { qualIncForLowEnergy = qualIncreaseMinEnergy; - move16(); } - if(sub(qualIncForLowEnergy, qualIncreaseMaxEnergy) > 0) + if(qualIncForLowEnergy > qualIncreaseMaxEnergy) { qualIncForLowEnergy = qualIncreaseMaxEnergy; - move16(); } - /* -50: (-50 - -40) / (-65 - -40) * 20 - * = -10 / -25 * 20 - */ - qualIncForLowEnergy = divide1616(sub(qualIncForLowEnergy, qualIncreaseMaxEnergy), - sub(qualIncreaseMinEnergy, qualIncreaseMaxEnergy)); - /* apply factor 2 and scale back to Q8 */ - assert(qualIncForLowEnergy >= 0); - qualIncForLowEnergy = shr(qualIncForLowEnergy, 7-1); - assert(qualIncForLowEnergy >= 0 && qualIncForLowEnergy <= (2 << 8)); + qualIncForLowEnergy = (qualIncForLowEnergy - qualIncreaseMaxEnergy) / + (qualIncreaseMinEnergy - qualIncreaseMaxEnergy) * 2; + assert(qualIncForLowEnergy >= 0 && qualIncForLowEnergy <= 2); } return qualIncForLowEnergy; } @@ -874,91 +755,79 @@ Word16 apa_getQualityIncreaseForLowEnergy(Word16 energydBQ8) * ******************************************************************************** */ -static Word8 logarithmic_search(const apa_state_t * ps, - const Word16 * signal, - Word16 s_start, - Word16 inlen, - Word16 offset, - Word16 fixed_pos, - Word16 corr_len, - Word16 wss, - Word16 css, - Word16 * synchpos) +static bool_t logarithmic_search(const apa_state_t * ps, + const int16_t * signal, + int16_t s_start, + uint16_t inlen, + uint16_t offset, + uint16_t fixed_pos, + uint16_t corr_len, + uint16_t wss, + uint16_t css, + int16_t * synchpos) { - Word16 i; - Word32 coeff; - Word32 coeff_max; - Word16 s_start_old, s_len_old; - - DO + int i; + Float coeff; + Float coeff_max; + int16_t s_start_old = 0; + uint16_t s_len_old = 0; + do { - coeff_max = 0x80000000; /* will always be overwritten with result of first correlation */ move32(); - - FOR(i = s_start; i < s_start+inlen; i += css) + coeff_max = -FLT_MAX; /* will always be overwritten with result of first correlation */ + for (i = s_start; i < s_start+inlen; i += css) { - test(); - IF( sub(wss,1) == 0 && sub(ps->num_channels, 1) == 0 ) + if((wss == 1) && (ps->num_channels == 1)) { - coeff = cross_correlation_self(signal, add(i, offset), add(fixed_pos, offset), corr_len); + coeff = cross_correlation_self(signal, i+offset, fixed_pos+offset, corr_len); } - ELSE + else { - coeff = cross_correlation_subsampled_self(signal, add(i, offset), add(fixed_pos, offset), - corr_len, i_mult2(wss, ps->num_channels)); + coeff = cross_correlation_subsampled_self( signal, i+offset, fixed_pos+offset, + corr_len, wss*ps->num_channels); } /* update max corr */ - IF( sub(ps->scale, 100) < 0 ) + if( ps->scale < 100 ) { /* shrinking: prefer greater synchpos for equal coeff */ - BASOP_SATURATE_WARNING_OFF - IF(L_sub(coeff, coeff_max) >= 0) + if (coeff >= coeff_max) { - coeff_max = L_add(coeff, 0); + coeff_max = coeff; *synchpos = i; - move16(); } - BASOP_SATURATE_WARNING_ON } - ELSE + else { /* extending: prefer smaller synchpos for equal coeff */ - BASOP_SATURATE_WARNING_OFF - IF(L_sub(coeff, coeff_max) > 0) + if (coeff > coeff_max) { - coeff_max = L_add(coeff, 0); + coeff_max = coeff; *synchpos = i; - move16(); } - BASOP_SATURATE_WARNING_ON } } /* backup old search range */ s_start_old = s_start; - move16(); s_len_old = inlen; - move16(); - css = shr( css, 1 ); - inlen = shr( inlen, 1 ); - s_start_old = s_start; - move16(); - s_start = sub( *synchpos, shr( inlen, 1 ) ); - - if( sub(s_start,s_start_old) < 0 ) + css = css/2; + inlen = inlen/2; + s_start = *synchpos - inlen/2; + if(s_start < s_start_old) { s_start = s_start_old; - move16(); } - - IF( sub( add(s_start,inlen), add(s_start_old,s_len_old) ) > 0 ) + if((s_start+inlen) > (s_start_old+s_len_old)) { - inlen = add( sub( s_start_old, s_start), s_len_old ); + inlen = s_start_old - s_start + s_len_old; } - } WHILE( sub( css, 2 ) > 0 ); + } + while (css > 2); + return 0; } + /* ******************************************************************************** * @@ -969,26 +838,54 @@ static Word8 logarithmic_search(const apa_state_t * ps, * Information : Find the best match of an template segment within * a search region by similarity measures. * +* Typical example: +* +* 0 10 20 30 40 50 60 +* in[] = abcdefghijk_abcdefghijk_abcdefghijk_abcdEFGHIJk_abcdefghijk_a +* l_in = 61 +* offset = 30 | +* s_start = -20 <-------------------| +* s_len = 15 <-------------> | +* search range: *************** | +* fixed_pos = 10 |---------> +* corr_len = 6 | <----> +* template segment: | ****** +* synch_pos: -14 <-------------| +* +* All positions are given relative to offset. The +* search region starts at offset+s_start and ends +* at offset+s_start+s_len. The template segment +* starts at offset+fixed_pos and ends at +* offset+fixed_pos+corr_len. For correlation, the +* template segment (EFGHIJ) is matched against the +* segment in the search region, e.g., against (k_abcd) +* in the first search position. The search position +* with the best match (-14: EFGHIJ <-> efghij) is +* returned. +* +* 19-JUN-03 N.Faerber initial version +* 23-APR-04 S.Doehla added subsampling +* ******************************************************************************** */ -static Word16 find_synch (apa_state_t * ps, - const Word16 * in, - Word16 l_in, - Word16 s_start, - Word16 s_len, - Word16 fixed_pos, - Word16 corr_len, - Word16 offset, - Word16 * energydBQ8, - Word32 * qualityQ16, - Word16 * synch_pos) +static bool_t find_synch (apa_state_t * ps, + const int16_t * in, + uint16_t l_in, + int16_t s_start, + uint16_t s_len, + int16_t fixed_pos, + uint16_t corr_len, + uint16_t offset, + Float * energy, + Float * quality, + int16_t * synch_pos) { assert( (corr_len - 1 + s_start + s_len - 1 + offset) < l_in ); assert( (corr_len - 1 + fixed_pos + offset) < l_in); /* pass last pitch to search function as prediction value */ *synch_pos = ps->last_pitch; - move16(); + logarithmic_search(ps, in, s_start, @@ -997,16 +894,15 @@ static Word16 find_synch (apa_state_t * ps, fixed_pos, corr_len, ps->wss, - i_mult2(ps->css, ps->num_channels), + ps->css * ps->num_channels, synch_pos); /* assert synch_pos is cleanly divisible by number of channels */ assert( *synch_pos % ps->num_channels == 0 ); - *qualityQ16 = L_deposit_l(0); + *quality = 0; get_scaling_quality(ps, in, l_in, offset, corr_len, - abs_s( sub(*synch_pos, fixed_pos) ), energydBQ8, qualityQ16); + abs(fixed_pos - *synch_pos), energy, quality); ps->last_pitch = *synch_pos; - move16(); return 0; } @@ -1033,24 +929,23 @@ static Word16 find_synch (apa_state_t * ps, * ******************************************************************************** */ -static Word16 copy_frm (apa_state_t * ps, - const Word16 frm_in[], Word16 frm_out[], Word16 * l_frm_out) +static bool_t copy_frm (apa_state_t * ps, + const int16_t frm_in[], int16_t frm_out[], uint16_t * l_frm_out) { - Word16 i; + uint16_t i; /* only 2nd input frame is used */ frm_in += ps->l_frm; /* copy frame */ - FOR( i = 0; i < ps->l_frm; i++ ) + for (i = 0; i < ps->l_frm; i++) { frm_out[i] = frm_in[i]; - move16(); } /* set output length */ *l_frm_out = ps->l_frm; - move16(); + return 0; } @@ -1078,138 +973,116 @@ static Word16 copy_frm (apa_state_t * ps, * ******************************************************************************** */ -static Word16 shrink_frm (apa_state_t * ps, - const Word16 frm_in[], Word16 maxScaling, Word16 frm_out[], Word16 * l_frm_out) +static bool_t shrink_frm (apa_state_t * ps, + const int16_t frm_in[], uint16_t maxScaling, int16_t frm_out[], uint16_t * l_frm_out) { - Word16 findSynchResult; - Word16 xtract, l_rem, s_start, s_end, l_frm, l_seg; - Word16 i; - Word16 over; - Word16 energyQ8; - Word32 qualityQ16; + bool_t findSynchResult = 0; + int16_t xtract, l_rem, s_start, s_end; + uint16_t i; + uint16_t over; + Float energy, quality = 0.0f; + uint16_t l_frm; + uint16_t l_seg; - findSynchResult = 0; - move16(); l_frm = ps->l_frm; - move16(); l_seg = ps->l_seg; - move16(); /* only 2nd input frame is used */ frm_in += l_frm; /* set search range */ - s_start = ps->p_min; - move16(); - /* assumption made that number of channels limited to 2 for basop port */ - assert( ps->num_channels <= 2 ); - /* pre-basop conversion was: s_start = (s_start / nChans) * nChans; */ - IF( ps->num_channels == 2 ) + s_start = (ps->p_min / ps->num_channels) * ps->num_channels; + s_end = s_start + ps->l_search; + if ((s_end + l_seg) >= l_frm) { - s_start = shl( shr( s_start, 1 ), 1 ); - } - s_end = add( s_start, ps->l_search ); - - if( sub( add( s_end, l_seg ), l_frm ) >= 0 ) - { - s_end = sub( l_frm, l_seg ); + s_end = (l_frm - l_seg); } /* calculate overlap position */ - IF( isSilence( frm_in, l_seg, 10 ) ) + if( isSilence( frm_in, l_seg, 10 ) ) { /* maximum scaling */ - energyQ8 = -65 * (1 << 8); - move16(); - qualityQ16 = L_deposit_h(5); - - /* set to last valid element (i.e. element[len - 1] but note for stereo last element is last pair of samples) */ - xtract = sub( s_end, ps->num_channels ); - test(); - if( maxScaling != 0U && sub( s_end, add( maxScaling, 1 ) ) > 0 ) + energy = -65; + quality = 5; + if( maxScaling != 0U && s_end > maxScaling + 1 ) { xtract = maxScaling; - move16(); + } + else + { + /* set to last valid element (i.e. element[len - 1] but note for stereo last element is last pair of samples) */ + xtract = s_end - ps->num_channels; } } - ELSE + else { /* find synch */ - assert(sizeof(ps->frmInScaled)/sizeof(ps->frmInScaled[0]) >= (size_t)l_frm); - scaleSignal16( frm_in, ps->frmInScaled, l_frm, ps->signalScaleForCorrelation ); - findSynchResult = find_synch (ps, ps->frmInScaled, l_frm, - s_start, sub(s_end, s_start), 0, l_seg, 0, &energyQ8, &qualityQ16, &xtract); + findSynchResult = find_synch (ps, frm_in, l_frm, + s_start, (uint16_t) (s_end - s_start), 0, + l_seg, 0, &energy, &quality, &xtract); } /* assert synch_pos is cleanly divisible by number of channels */ assert( xtract % ps->num_channels == 0 ); /* set frame overlappable - reset if necessary */ over = 1; - move16(); /* test whether frame has sufficient quality */ - /* 6554=0.1 in Q15.16; 13107=0.2 in Q15.16 */ - IF(L_sub(qualityQ16, L_add(L_sub(ps->targetQualityQ16, - L_mult0(ps->bad_frame_count, 6554)), - L_mult0(ps->good_frame_count, 13107))) < 0) + if(quality < (ps->targetQuality - (ps->bad_frame_count * 0.1f) + (ps->good_frame_count * 0.2f))) { /* not sufficient */ over = 0; - move16(); - - if( sub( ps->bad_frame_count, ps->qualityred ) < 0 ) + if( ps->bad_frame_count < ps->qualityred ) { - ps->bad_frame_count = add( ps->bad_frame_count, 1 ); + ++ps->bad_frame_count; } - if( ps->good_frame_count > 0 ) + if( ps->good_frame_count > 0U ) { - ps->good_frame_count = sub( ps->good_frame_count, 1 ); + --ps->good_frame_count; } } - ELSE + else { /* sufficient quality */ - if( ps->bad_frame_count > 0 ) + if( ps->bad_frame_count > 0U ) { - ps->bad_frame_count = sub( ps->bad_frame_count, 1 ); + --ps->bad_frame_count; } - if( sub( ps->good_frame_count, ps->qualityrise ) < 0 ) + if( ps->good_frame_count < ps->qualityrise ) { - ps->good_frame_count = add( ps->good_frame_count, 1 ); + ++ps->good_frame_count; } } - /* Calculate output data */ test(); - IF( over != 0 && xtract != 0 ) + /* Calculate output data */ + if(over && xtract) { - IF( sub( findSynchResult, 1) == 0 ) + if (findSynchResult == 1) { return 1; } overlapAdd(frm_in, frm_in + xtract, frm_out, l_seg, ps->num_channels, - ps->win + ps->l_halfwin, ps->win, ps->win_incrementor ); + ps->win + ps->l_halfwin, ps->win); } - ELSE + else { xtract = 0; - move16(); - FOR( i = 0; i < l_seg; i++ ) + for (i = 0; i < l_seg; i++) { frm_out[i] = frm_in[i]; - move16(); } } /* append remaining samples */ - l_rem = sub( sub( l_frm, xtract ), l_seg ); - FOR( i = 0; i < l_rem; i++ ) + l_rem = l_frm - xtract - l_seg; + for (i = 0; i < l_rem; i++) { frm_out[l_seg + i] = frm_in[l_frm - l_rem + i]; - move16(); } /* set output length */ - *l_frm_out = add( l_seg, l_rem ); + *l_frm_out = l_seg + l_rem; + return 0; } @@ -1233,81 +1106,64 @@ static Word16 shrink_frm (apa_state_t * ps, * ******************************************************************************** */ -static Word16 extend_frm (apa_state_t * ps, - const Word16 frm_in[], Word16 frm_out[], Word16 * l_frm_out) +static bool_t extend_frm (apa_state_t * ps, + const int16_t frm_in[], int16_t frm_out[], uint16_t * l_frm_out) { - Word16 findSynchResult; - Word16 l_frm_out_target; - Word16 N, n, i; - Word16 s[MAXN + 2], s_max, s_min; - Word16 xtract[MAXN + 2], sync_start, s_end; - Word16 over[MAXN + 2]; - Word16 l_frm, l_seg; - Word16 s_start, l_rem; - Word16 sn_plus_search, sync_start_sub_pmin; - Word16 divScaleFac; - Word16 energyQ8; - Word32 qualityQ16; - const Word16 *fadeOut, *fadeIn; - Word16 *frmInScaled, *out; + bool_t findSynchResult = 0; + uint16_t l_frm_out_target; + uint16_t n, i; + int16_t N; + int16_t s[MAXN + 2], s_max, s_min; + int16_t xtract[MAXN + 2], sync_start, s_end; + uint16_t over[MAXN + 2]; + int16_t l_rem; + int16_t s_start = 0; + Float energy, quality = 0.0f; + uint16_t l_frm, l_seg; + const int16_t *fadeOut, *fadeIn; + int16_t *out; - findSynchResult = 0; - move16(); - s_start = 0; - move16(); - qualityQ16 = L_deposit_l(0); l_frm = ps->l_frm; - move16(); l_seg = ps->l_seg; - move16(); - frmInScaled = NULL; - move16(); /* number of segments/iterations */ - /* equivalent to l_frm_out_target = l_frm * 1.5; */ - l_frm_out_target = add( l_frm, shr( l_frm, 1 ) ); - /* equivalent to (l_frm_out_target / l_seg) - 1 */ - N = BASOP_Util_Divide3216_Scale( l_frm_out_target, l_seg, &divScaleFac ); - N = sub( shl( N, add(divScaleFac,1) ), 1 ); - - assert( (l_frm_out_target / l_seg) - 1 == N ); - - if( sub(N, 1) < 0 ) + l_frm_out_target = (uint16_t) ((Float) l_frm * 1.5f); + N = (l_frm_out_target / l_seg) - 1; + if (N < 1) { N = 1; - move16(); } - - assert( N <= MAXN ); - + if (N > MAXN) + { + return 1; + } /* calculate equally spaced search regions */ /* s[n] are given relative to 2nd frame and point to the start of */ /* the search region. The first segment (n=1) will not be moved. */ /* Hence, the iterations will start with n=2. */ - s_min = sub( negate(ps->l_search), ps->p_min ); + s_min = -(ps->l_search) - (ps->p_min); /* (make sure not to exceed array dimension) */ - if( add( l_frm, s_min ) < 0) + if (l_frm + s_min < 0) { - s_min = negate( l_frm ); + s_min = -(l_frm); } - s_max = sub( sub( l_frm, shl( l_seg, 1 ) ), ps->l_search ); - if( sub( s_max, s_min ) < 0 ) + s_max = l_frm - 2 * l_seg - ps->l_search; + if (s_max < s_min) { N = 1; - move16(); } /* for just one segment start at s_min */ - s[2] = s_min; - move16(); + if (N == 1) + { + s[2] = s_min; + } /* else, spread linear in between s_min and s_max */ /* (including s_min and s_max) */ - IF( sub( N, 1 ) != 0 ) + else { - FOR( n = 2; n <= (N + 1); n++ ) + for (n = 2; n <= (N + 1); n++) { - s[n] = BASOP_Util_Divide3216_Scale( L_mult0( sub( s_max, s_min ), sub(n,2) ), sub(N,1), &divScaleFac ); - s[n] = add( shl( s[n], add(divScaleFac,1) ), s_min ); - move16(); + s[n] = s_min + ((s_max - s_min) * (n - 2)) / (N - 1); } } @@ -1315,158 +1171,132 @@ static Word16 extend_frm (apa_state_t * ps, * Planning Phase */ - xtract[1] = negate(l_seg); /* make sync_start=0 in 1st iteration */ move16(); + xtract[1] = -(l_seg); /* make sync_start=0 in 1st iteration */ n = 2; - move16(); { /* define synch segment (to be correlated with search region) */ - sync_start = add( xtract[sub(n,1)], l_seg ); - over[n] = 1; /* will be reset if overlap is not required */ move16(); - - /* added basop port - stored results for repeated calculations */ - sn_plus_search = add( s[n], ps->l_search ); - sync_start_sub_pmin = sub( sync_start, ps->p_min ); - + sync_start = xtract[n - 1] + l_seg; + over[n] = 1; /* will be reset if overlap is not required */ /* check end of search region: should be at least p_min */ /* samples on the left of synch_start */ - /* removed basop (overwritten instead): if( sub( sn_plus_search, sub( sync_start, ps->p_min) ) < 0 */ - s_start = s[n]; - move16(); - s_end = add( s_start, ps->l_search ); - - IF( sub( sn_plus_search, sync_start_sub_pmin ) >= 0 ) + if ((s[n] + ps->l_search) < (sync_start - (ps->p_min))) + { + s_start = s[n]; + s_end = s_start + ps->l_search; + } + else { /* shrink search region to enforce minimum shift */ - s_end = sync_start_sub_pmin; - move16(); - - IF( sub( sn_plus_search, sync_start ) < 0 ) + s_end = sync_start - (ps->p_min); + if (s[n] + ps->l_search < sync_start) { - s_start = s[n]; /* just do it with normal start position */ move16(); + s_start = s[n]; /* just do it with normal start position */ } - ELSE IF( sub( n, add(N,1) ) == 0 ) /* move search region left for last segment */ + else if (n == (N + 1)) /* move search region left for last segment */ { - s_start = sub( s_end, sub( ps->l_search, ps->p_min ) ); + s_start = s_end - (ps->l_search - ps->p_min); } - ELSE + else { - over[n] = 0; /* don't search/overlap (just copy down) */ move16(); + over[n] = 0; /* don't search/overlap (just copy down) */ } } - IF( over[n] != 0 ) + if (over[n]) { /* calculate overlap position */ - IF( isSilence( frm_in, l_seg, 10 ) ) + if( isSilence( frm_in, l_seg, 10 ) ) { /* maximum scaling */ - energyQ8 = -65 * (1 << 8); - move16(); - qualityQ16 = L_deposit_h(5); - xtract[n] = add( s_start, ps->num_channels ); - move16(); + energy = -65; + quality = 5; + xtract[n] = s_start + ps->num_channels; } - ELSE + else { /* find synch */ - IF( frmInScaled == NULL ) - { - frmInScaled = ps->frmInScaled; - move16(); - assert(sizeof(ps->frmInScaled)/sizeof(ps->frmInScaled[0]) >= 2 * (size_t)l_frm); - scaleSignal16( frm_in, frmInScaled, shl( l_frm, 1 ), ps->signalScaleForCorrelation ); - } - findSynchResult = find_synch( ps, frmInScaled, shl( l_frm, 1 ), - s_start, sub( s_end, s_start ), sync_start, - l_seg, l_frm, &energyQ8, &qualityQ16, &xtract[n] ); + findSynchResult = find_synch( ps, frm_in, 2 * l_frm, + s_start, s_end - s_start, sync_start, + l_seg, l_frm, &energy, &quality, &xtract[n] ); } /* assert synch_pos is cleanly divisible by number of channels */ assert( xtract[n] % ps->num_channels == 0 ); /* test for sufficient quality */ - /* 6554=0.1 in Q15.16; 13107=0.2 in Q15.16 */ - IF(L_sub(qualityQ16, L_add(L_sub(ps->targetQualityQ16, - L_mult0(ps->bad_frame_count, 6554)), - L_mult0(ps->good_frame_count, 13107))) < 0) + if(quality < (ps->targetQuality - (ps->bad_frame_count * 0.1f) + (ps->good_frame_count * 0.2f))) { /* not sufficient */ over[n] = 0; - move16(); xtract[n] = sync_start; - move16(); - - if( sub( ps->bad_frame_count, ps->qualityred ) < 0 ) + if( ps->bad_frame_count < ps->qualityred ) { - ps->bad_frame_count = add( ps->bad_frame_count, 1 ); + ++ps->bad_frame_count; } - if( ps->good_frame_count > 0 ) + if( ps->good_frame_count > 0U ) { - ps->good_frame_count = sub( ps->good_frame_count, 1 ); + --ps->good_frame_count; } } - ELSE + else { /* sufficient quality */ - if( ps->bad_frame_count > 0 ) + if( ps->bad_frame_count > 0U ) { - ps->bad_frame_count = sub( ps->bad_frame_count, 1 ); + --ps->bad_frame_count; } - if(sub(ps->good_frame_count, ps->qualityrise) < 0) + if( ps->good_frame_count < ps->qualityrise ) { - ps->good_frame_count = add( ps->good_frame_count, 1 ); + ++ps->good_frame_count; } } - - IF( findSynchResult > 0 ) + if (findSynchResult) { return 1; } } - ELSE + else { xtract[n] = sync_start; - move16(); } } /* Calculate output data */ - FOR( n = 2; n <= N; n++ ) + for (n = 2; n <= N; n++) { - test(); - IF( over[n] != 0 && sub( add( xtract[sub(n,1)], l_seg ), xtract[n] ) != 0 ) + if (over[n] && xtract[n-1] + l_seg != xtract[n]) { /* mix 2nd half of previous segment with 1st half of current segment */ fadeOut = frm_in + l_frm + xtract[n - 1] + l_seg; fadeIn = frm_in + l_frm + xtract[n]; - out = frm_out + i_mult2(sub(n, 2), l_seg); + out = frm_out + (n - 2) * l_seg; overlapAdd(fadeOut, fadeIn, out, l_seg, ps->num_channels, - ps->win + ps->l_halfwin, ps->win, ps->win_incrementor ); + ps->win + ps->l_halfwin, ps->win); } - ELSE + else { /* just copy down 1st half of current segment (= 2nd half of previous segment) */ - Word16 *frm_out_ptr = &(frm_out[ i_mult2( sub(n,2), l_seg ) ]); - const Word16 *frm_in_ptr = &(frm_in[ add( l_frm, xtract[n] ) ]); - FOR(i = 0; i < l_seg; i++) + int16_t * frm_out_ptr; + const int16_t * frm_in_ptr; + frm_out_ptr = &(frm_out[(n - 2) * l_seg]); + frm_in_ptr = &(frm_in[l_frm + xtract[n]]); + for (i = 0; i < l_seg; i++) { frm_out_ptr[i] = frm_in_ptr[i]; - move16(); } } } /* append remaining samples */ - l_rem = sub( l_frm, add( xtract[N], l_seg ) ); - FOR( i = 0; i < l_rem; i++ ) + l_rem = l_frm - (xtract[N] + l_seg); + for (i = 0; i < l_rem; i++) { - frm_out[ add( i_mult2( sub(N,1), l_seg), i ) ] = - frm_in[ add( sub( shl( l_frm,1 ), l_rem ), i ) ]; - move16(); + frm_out[(N - 1) * l_seg + i] = frm_in[2 * l_frm - l_rem + i]; } /* set output length */ - *l_frm_out = add( i_mult2( sub(N,1), l_seg ), l_rem ); + *l_frm_out = (N - 1) * l_seg + l_rem; + return 0; } diff --git a/src/libs/libevs/lib_dec/jbm_pcmdsp_apa.h b/src/libs/libevs/lib_dec/jbm_pcmdsp_apa.h old mode 100755 new mode 100644 index 3de9a89c..ce9f7ba3 --- a/src/libs/libevs/lib_dec/jbm_pcmdsp_apa.h +++ b/src/libs/libevs/lib_dec/jbm_pcmdsp_apa.h @@ -1,14 +1,13 @@ /*==================================================================================== - EVS Codec 3GPP TS26.442 Apr 03, 2018. Version 12.11.0 / 13.6.0 / 14.2.0 + EVS Codec 3GPP TS26.443 Nov 13, 2018. Version 12.11.0 / 13.7.0 / 14.3.0 / 15.1.0 ====================================================================================*/ -/*! @file pcmdsp_apa.h Adaptive Playout for Audio (apa). */ +/*! @file jbm_pcmdsp_apa.h Adaptive Playout for Audio (apa). */ -#ifndef PCMDSP_APA_H -#define PCMDSP_APA_H PCMDSP_APA_H +#ifndef JBM_PCMDSP_APA_H +#define JBM_PCMDSP_APA_H JBM_PCMDSP_APA_H -/* instrumentation */ -#include "typedef.h" +#include "jbm_types.h" /* ******************************************************************************** @@ -17,12 +16,24 @@ */ /* size of IO buffers (a_in[], a_out[]) for apa_exec() */ -#define APA_BUF (48000/50*3) +#define APA_BUF 4096*3 + +/* min/max sampling rate [Hz] */ +#define APA_MIN_RATE 1000 +#define APA_MAX_RATE 48000 /* min/max scaling [%] */ #define APA_MIN_SCALE 50 #define APA_MAX_SCALE 150 +#define APA_SM_SURROUND 1 +#define APA_SM_LOGARITHMIC 2 +#define APA_SM_FULLSUBSAMPLED 3 + +#define APA_SIM_CCF 11 +#define APA_SIM_NCCF 12 +#define APA_SIM_AMDF 13 +#define APA_SIM_SSE 14 /* ******************************************************************************** @@ -44,7 +55,7 @@ typedef struct apa_state_t* PCMDSP_APA_HANDLE; /*! Allocates memory for state struct and initializes elements. * @return 0 on success, 1 on failure */ -Word8 apa_init(apa_state_t **s); +uint8_t apa_init(apa_state_t **s); /*! Sets state variables to initial value. */ void apa_reset(apa_state_t *s); @@ -52,42 +63,43 @@ void apa_reset(apa_state_t *s); /*! Sets the audio configuration. * Must be called once before processing can start. * If called again during processing it will reset the state struct! + * Typical sample rates: 8000, 16000, 22050, 44100. Must be in range [APA_MIN_RATE,APA_MAX_RATE]. * Will also set a number of other state variables that depend on the sampling rate. * @param[in,out] ps state * @param[in] rate sample rate [Hz] * @param[in] num_channels number of channels * @return 0 on success, 1 on failure */ -Word8 apa_set_rate( +bool_t apa_set_rate( apa_state_t *ps, - Word32 rate, - Word16 num_channels); + uint16_t rate, + uint16_t num_channels); /*! Set scaling. * The scale is given in % and will be valid until changed again. * Must be in range [APA_MIN_SCALE,APA_MAX_SCALE]. * @return 0 on success, 1 on failure */ -Word8 apa_set_scale(apa_state_t *s, Word16 scale); +bool_t apa_set_scale(apa_state_t *s, uint16_t scale); -Word8 apa_set_quality( +bool_t apa_set_complexity_options( apa_state_t *s, - Word32 qualityQ16, - Word16 qualityred, - Word16 qualityrise); + uint16_t wss, + uint16_t css); -Word8 apa_set_complexity_options( +bool_t apa_set_quality( apa_state_t *s, - Word16 wss, - Word16 css); + float quality, + uint16_t qualityred, + uint16_t qualityrise); -Word8 apa_exit( +bool_t apa_exit( apa_state_t **s); -Word8 apa_exec( +uint8_t apa_exec( apa_state_t *s, - const Word16 a_in[], - Word16 l_in, - Word16 maxScaling, - Word16 a_out[], - Word16 *l_out); + const int16_t a_in[], + uint16_t l_in, + uint16_t maxScaling, + int16_t a_out[], + uint16_t *l_out); -#endif /* PCMDSP_APA_H */ +#endif /* JBM_PCMDSP_APA_H */ diff --git a/src/libs/libevs/lib_dec/jbm_pcmdsp_fifo.cpp b/src/libs/libevs/lib_dec/jbm_pcmdsp_fifo.cpp old mode 100755 new mode 100644 index 6375bdc4..3f196ee3 --- a/src/libs/libevs/lib_dec/jbm_pcmdsp_fifo.cpp +++ b/src/libs/libevs/lib_dec/jbm_pcmdsp_fifo.cpp @@ -1,15 +1,14 @@ /*==================================================================================== - EVS Codec 3GPP TS26.442 Apr 03, 2018. Version 12.11.0 / 13.6.0 / 14.2.0 + EVS Codec 3GPP TS26.443 Nov 13, 2018. Version 12.11.0 / 13.7.0 / 14.3.0 / 15.1.0 ====================================================================================*/ -/*! @file pcmdsp_fifo.c Ringbuffer (FIFO) with fixed capacity for audio samples */ +/*! @file jbm_pcmdsp_fifo.c Ringbuffer (FIFO) with fixed capacity for audio samples */ /* system headers */ #include -/* instrumentation headers */ +#include #include "options.h" -#include "stl.h" -#include "basop_util.h" +/* instrumentation */ /* local headers */ #include "jbm_pcmdsp_fifo.h" @@ -18,45 +17,38 @@ struct PCMDSP_FIFO { /** number of currently stored samples per channel */ - Word16 size; + unsigned int size; /** maximum allowed number of samples per channel */ - Word16 capacity; + unsigned int capacity; /** sample size in bytes per channel */ - Word16 nBytesPerSampleSet; + unsigned int nBytesPerSampleSet; /** begin of the FIFO data (pointer to bytes) */ - UWord8 *dataBegin; + uint8_t *dataBegin; /** end of the FIFO data (pointer to bytes) */ - UWord8 *dataEnd; + uint8_t *dataEnd; /** position of next write operation (pointer to bytes) */ - UWord8 *dataWriteIterator; + uint8_t *dataWriteIterator; /** position of next read operation (pointer to bytes) */ - UWord8 *dataReadIterator; + uint8_t *dataReadIterator; }; /* Creates a FIFO. */ -Word16 pcmdsp_fifo_create( PCMDSP_FIFO_HANDLE *ph ) +int pcmdsp_fifo_create( PCMDSP_FIFO_HANDLE *ph ) { - PCMDSP_FIFO_HANDLE h = (PCMDSP_FIFO_HANDLE)malloc( sizeof( struct PCMDSP_FIFO ) ); + PCMDSP_FIFO_HANDLE h = (PCMDSP_FIFO*)malloc( sizeof( struct PCMDSP_FIFO ) ); h->size = 0; - move16(); h->capacity = 0; - move16(); h->nBytesPerSampleSet = 0; - move16(); h->dataBegin = NULL; - move16(); h->dataEnd = NULL; - move16(); h->dataWriteIterator = NULL; - move16(); h->dataReadIterator = NULL; - move16(); *ph = h; - move16(); + return 0; } @@ -65,148 +57,106 @@ void pcmdsp_fifo_destroy( PCMDSP_FIFO_HANDLE *ph ) { PCMDSP_FIFO_HANDLE h; - IF( !ph ) - { + if( !ph ) return; - } h = *ph; - move16(); - IF( !h ) - { + if( !h ) return; - } - IF( h->dataBegin ) - { + if( h->dataBegin ) free( h->dataBegin ); - } free( h ); *ph = NULL; - move16(); + } /* Initializes the FIFO with a fixed maximum allowed number audio samples. */ -Word16 pcmdsp_fifo_init( PCMDSP_FIFO_HANDLE h, Word16 nSamples, - Word16 nChannels, Word16 nBytesPerSample ) +int pcmdsp_fifo_init( PCMDSP_FIFO_HANDLE h, unsigned int nSamples, + unsigned int nChannels, unsigned int nBytesPerSample ) { - Word32 nDataBytes; + unsigned int nDataBytes; h->capacity = nSamples; - move16(); - h->nBytesPerSampleSet = i_mult2( nChannels, nBytesPerSample ); - nDataBytes = L_mult0( nSamples, h->nBytesPerSampleSet); - h->dataBegin = (UWord8*)malloc(nDataBytes); + h->nBytesPerSampleSet = nChannels * nBytesPerSample; + nDataBytes = nSamples * h->nBytesPerSampleSet; + h->dataBegin = (uint8_t*)malloc(nDataBytes); h->dataEnd = h->dataBegin + nDataBytes; - move16(); h->dataWriteIterator = h->dataBegin; - move16(); h->dataReadIterator = h->dataBegin; - move16(); + return 0; } /* Writes the given audio data to the FIFO. */ -Word16 pcmdsp_fifo_write( PCMDSP_FIFO_HANDLE h, const UWord8 *samples, Word16 nSamplesPerChannel ) +int pcmdsp_fifo_write( PCMDSP_FIFO_HANDLE h, const uint8_t *samples, unsigned int nSamplesPerChannel ) { - Word32 nBytesToWrite, writeIter, bytesOfFirstPart, secondSize; + unsigned int nBytesToWrite; /* check for empty input buffer */ - IF( nSamplesPerChannel == 0 ) - { + if( nSamplesPerChannel == 0U ) return 0; - } /* check, if enough space left */ - IF( sub( nSamplesPerChannel, sub( h->capacity, h->size ) ) > 0 ) - { + if( nSamplesPerChannel > h->capacity - h->size ) return -1; - } - nBytesToWrite = L_mult0( nSamplesPerChannel, h->nBytesPerSampleSet ); - - IF( h->dataWriteIterator + nBytesToWrite - h->dataEnd > 0 ) + nBytesToWrite = nSamplesPerChannel * h->nBytesPerSampleSet; + if( h->dataWriteIterator + nBytesToWrite > h->dataEnd ) { /* wrap around: writing two parts */ + unsigned int bytesOfFirstPart, secondSize; bytesOfFirstPart = h->dataEnd - h->dataWriteIterator; - secondSize = L_sub( nBytesToWrite, bytesOfFirstPart ); - - FOR( writeIter = 0; writeIter < bytesOfFirstPart; ++writeIter ) - { - *h->dataWriteIterator++ = *(samples + writeIter); - move16(); - } - h->dataWriteIterator = h->dataBegin; - move16(); - FOR( writeIter = 0; writeIter < secondSize; ++writeIter ) - { - *h->dataWriteIterator++ = *(samples + bytesOfFirstPart + writeIter ); - move16(); - } + secondSize = nBytesToWrite - bytesOfFirstPart; + memcpy( h->dataWriteIterator, samples, bytesOfFirstPart ); + memcpy( h->dataBegin, samples + bytesOfFirstPart, secondSize ); + h->dataWriteIterator = h->dataBegin + secondSize; } - ELSE + else { /* no wrap around: simple write */ - FOR( writeIter = 0; writeIter < nBytesToWrite; ++writeIter ) - { - *h->dataWriteIterator++ = *(samples + writeIter); - move16(); - } + memcpy( h->dataWriteIterator, samples, nBytesToWrite ); + h->dataWriteIterator += nBytesToWrite; } - h->size = add( h->size, nSamplesPerChannel ); + h->size += nSamplesPerChannel; + return 0; } /* Reads the given number of audio samples from the FIFO. */ -Word16 pcmdsp_fifo_read( PCMDSP_FIFO_HANDLE h, Word16 nSamplesPerChannel, UWord8 *samples ) +int pcmdsp_fifo_read( PCMDSP_FIFO_HANDLE h, unsigned int nSamplesPerChannel, uint8_t *samples ) { - Word32 nBytesToRead, readIter, nBytesOfSecondPart, bytesOfFirstPart; + unsigned int nBytesToRead; /* check for empty output buffer */ - IF( nSamplesPerChannel == 0 ) - { + if( nSamplesPerChannel == 0U ) return 0; - } /* check, if enough bytes readable */ - IF( L_sub( nSamplesPerChannel, h->size ) > 0 ) - { + if( nSamplesPerChannel > h->size ) return -1; - } - nBytesToRead = L_mult0( nSamplesPerChannel, h->nBytesPerSampleSet ); - - IF( h->dataReadIterator + nBytesToRead - h->dataEnd > 0 ) + nBytesToRead = nSamplesPerChannel * h->nBytesPerSampleSet; + if( h->dataReadIterator + nBytesToRead > h->dataEnd ) { /* wrap around: reading two parts */ + unsigned int bytesOfFirstPart, nBytesOfSecondPart; bytesOfFirstPart = h->dataEnd - h->dataReadIterator; - nBytesOfSecondPart = L_sub( nBytesToRead, bytesOfFirstPart ); - - FOR( readIter = 0; readIter < bytesOfFirstPart; ++readIter ) - { - *(samples + readIter) = *h->dataReadIterator++; - move16(); - } - h->dataReadIterator = h->dataBegin; - move16(); - FOR( readIter = 0; readIter < nBytesOfSecondPart; ++readIter ) - { - *(samples + bytesOfFirstPart + readIter) = *h->dataReadIterator++; - move16(); - } + nBytesOfSecondPart = nBytesToRead - bytesOfFirstPart; + memcpy( samples, h->dataReadIterator, bytesOfFirstPart ); + memcpy( samples + bytesOfFirstPart, h->dataBegin, nBytesOfSecondPart ); + h->dataReadIterator = h->dataBegin + nBytesOfSecondPart; } - ELSE + else { /* no wrap around: simple read */ - FOR( readIter = 0; readIter < nBytesToRead; ++readIter ) - { - *(samples + readIter) = *h->dataReadIterator++; - move16(); - } + memcpy( samples, h->dataReadIterator, nBytesToRead ); + h->dataReadIterator += nBytesToRead; } - h->size = sub( h->size, nSamplesPerChannel ); + h->size -= nSamplesPerChannel; + return 0; } /* Returns the number of samples per channel that can be read (number of currently stored samples). */ -Word16 pcmdsp_fifo_nReadableSamples( const PCMDSP_FIFO_HANDLE h ) +unsigned int pcmdsp_fifo_nReadableSamples( const PCMDSP_FIFO_HANDLE h ) { return h->size; } diff --git a/src/libs/libevs/lib_dec/jbm_pcmdsp_fifo.h b/src/libs/libevs/lib_dec/jbm_pcmdsp_fifo.h old mode 100755 new mode 100644 index 30a051a9..5e90a3d5 --- a/src/libs/libevs/lib_dec/jbm_pcmdsp_fifo.h +++ b/src/libs/libevs/lib_dec/jbm_pcmdsp_fifo.h @@ -1,44 +1,44 @@ /*==================================================================================== - EVS Codec 3GPP TS26.442 Apr 03, 2018. Version 12.11.0 / 13.6.0 / 14.2.0 + EVS Codec 3GPP TS26.443 Nov 13, 2018. Version 12.11.0 / 13.7.0 / 14.3.0 / 15.1.0 ====================================================================================*/ -/*! @file pcmdsp_fifo.h Ringbuffer (FIFO) with fixed capacity for audio samples. */ +/*! @file jbm_pcmdsp_fifo.h Ringbuffer (FIFO) with fixed capacity for audio samples. */ -#ifndef PCMDSP_FIFO_H -#define PCMDSP_FIFO_H PCMDSP_FIFO_H +#ifndef JBM_PCMDSP_FIFO_H +#define JBM_PCMDSP_FIFO_H JBM_PCMDSP_FIFO_H + +/* local headers */ +#include "jbm_types.h" -/* instrumentation headers */ -#include "typedef.h" /** handle for FIFO with fixed capacity */ typedef struct PCMDSP_FIFO *PCMDSP_FIFO_HANDLE; /** Creates a FIFO. * @param[out] ph pointer to created handle * @return 0 if succeeded */ -Word16 pcmdsp_fifo_create( PCMDSP_FIFO_HANDLE *ph ); +int pcmdsp_fifo_create( PCMDSP_FIFO_HANDLE *ph ); /** Destroys the FIFO. */ void pcmdsp_fifo_destroy( PCMDSP_FIFO_HANDLE *ph ); /** Initializes the FIFO with a fixed maximum allowed number of audio samples. * @param[in] nSamples maximum allowed number of samples per channel (capacity) - * @note Word16 gives max capacity of 34 frames @ 48000 Hz * @param[in] nChannels number of audio channels * @param[in] nBytesPerSample size in bytes per sample per channel * @return 0 if succeeded */ -Word16 pcmdsp_fifo_init( PCMDSP_FIFO_HANDLE h, Word16 nSamples, - Word16 nChannels, Word16 nBytesPerSample ); +int pcmdsp_fifo_init( PCMDSP_FIFO_HANDLE h, unsigned int nSamples, + unsigned int nChannels, unsigned int nBytesPerSample ); /** Writes the given audio data to the FIFO. * @param[in] samples pointer to audio samples to append * @param[in] nSamplesPerChannel the number of samples per channel to append * @return 0 if succeeded */ -Word16 pcmdsp_fifo_write( PCMDSP_FIFO_HANDLE h, const UWord8 *samples, Word16 nSamplesPerChannel ); +int pcmdsp_fifo_write( PCMDSP_FIFO_HANDLE h, const uint8_t *samples, unsigned int nSamplesPerChannel ); /** Reads the given number of audio samples from the FIFO. * @param[in] nSamplesPerChannel the number of samples per channel to read from the FIFO * @param[in] samples pointer where the audio samples will be copied to * @return 0 if succeeded */ -Word16 pcmdsp_fifo_read( PCMDSP_FIFO_HANDLE h, Word16 nSamplesPerChannel, UWord8 *samples ); +int pcmdsp_fifo_read( PCMDSP_FIFO_HANDLE h, unsigned int nSamplesPerChannel, uint8_t *samples ); /** Returns the number of samples per channel that can be read (number of currently stored samples). */ -Word16 pcmdsp_fifo_nReadableSamples( const PCMDSP_FIFO_HANDLE h ); +unsigned int pcmdsp_fifo_nReadableSamples( const PCMDSP_FIFO_HANDLE h ); -#endif /* PCMDSP_FIFO_H */ +#endif /* JBM_PCMDSP_FIFO_H */ diff --git a/src/libs/libevs/lib_dec/jbm_pcmdsp_similarityestimation.cpp b/src/libs/libevs/lib_dec/jbm_pcmdsp_similarityestimation.cpp old mode 100755 new mode 100644 index 2528ac9e..4ca89efa --- a/src/libs/libevs/lib_dec/jbm_pcmdsp_similarityestimation.cpp +++ b/src/libs/libevs/lib_dec/jbm_pcmdsp_similarityestimation.cpp @@ -1,202 +1,101 @@ /*==================================================================================== - EVS Codec 3GPP TS26.442 Apr 03, 2018. Version 12.11.0 / 13.6.0 / 14.2.0 + EVS Codec 3GPP TS26.443 Nov 13, 2018. Version 12.11.0 / 13.7.0 / 14.3.0 / 15.1.0 ====================================================================================*/ -/*! @file pcmdsp_similarityestimation.c Algorithms for correlation and similarity estimation. */ +/*! @file jbm_pcmdsp_similarityestimation.c Algorithms for correlation and similarity estimation. */ /* system headers */ -#include #include -/* flc header */ -#include "stl.h" -#include "basop_util.h" +#include +#include "options.h" /* local headers */ #include "jbm_pcmdsp_similarityestimation.h" -#include "options.h" - -/* Returns the number of right shifts to be applied to the signal before correlation functions. */ -Word16 getSignalScaleForCorrelation(Word32 sampleRate) -{ - Word16 ret; - - IF( L_sub(sampleRate, 16000) < 0 ) - { - ret = 2; - move16(); - } - ELSE IF( L_sub(sampleRate, 32000) >= 0 ) - { - ret = 4; - move16(); - } - ELSE - { - ret = 3; - move16(); - } - - return ret; -} - -/* Copies the right shifted signal to another buffer. */ -void scaleSignal16(const Word16 *src, Word16 *dst, Word16 n, Word16 rightShift) -{ - Word16 i; - - FOR(i = 0; i < n; i++) - { - dst[i] = shr_r(src[i], rightShift); - move16(); - } - -} /* Calculates cross correlation coefficient for template segment. */ -Word32 cross_correlation_self(const Word16 * signal, - Word16 x, Word16 y, Word16 corr_len) +Float cross_correlation_self(const int16_t * signal, + uint16_t x, uint16_t y, uint16_t corr_len) { - Word32 sum; - Word16 i; + Float c_c; + int j; - sum = L_deposit_l(0); - FOR(i = 0; i < corr_len; i++) + c_c = 0.0f; + for (j = 0; j < corr_len; j++) { - sum = L_mac0(sum, signal[x + i], signal[y + i]); + c_c += ((Float) signal[j + x] * (Float) signal[j + y]); } - - return sum; + return c_c; } /* Calculates cross correlation coefficient for template segment. */ -Word32 cross_correlation_subsampled_self(const Word16 * signal, - Word16 x, Word16 y, Word16 corr_len, Word16 subsampling) +Float cross_correlation_subsampled_self(const int16_t * signal, + uint16_t x, uint16_t y, uint16_t corr_len, uint16_t subsampling) { - Word32 sum; - Word16 i; + Float c_c; + int j; - sum = L_deposit_l(0); - FOR(i = 0; i < corr_len; i += subsampling) + c_c = 0.0f; + for (j = 0; j < corr_len; j += subsampling) { - sum = L_mac0(sum, signal[x + i], signal[y + i]); + c_c += ((Float) signal[j + x] * (Float) signal[j + y]); } - - return sum; + return c_c; } /* Calculates normalized cross correlation coefficient for template segment. */ -Word16 normalized_cross_correlation_self(const Word16 * signal, - Word16 x, Word16 y, Word16 corr_len, - Word16 subsampling, Word32 * energy) +Float normalized_cross_correlation_self(const int16_t * signal, + uint16_t x, uint16_t y, uint16_t corr_len, + uint16_t subsampling, Float * energy) { - const Word16 *signalX, *signalY; - Word32 sumXY, sumXX, sumYY, product; - Word16 sqrtXY, cc; - Word16 i, normX, normY, normXY, normCC; + Float32 c_c; + Float32 energy_xy, energy_x, energy_y; + uint16_t j; + const int16_t *signal_a, *signal_b; - signalX = &signal[x]; - signalY = &signal[y]; - sumXY = L_deposit_l(0); - sumXX = L_deposit_l(0); - sumYY = L_deposit_l(0); - - FOR(i = 0; i < corr_len; i += subsampling) + c_c = 0.0f; + energy_x = 0.0f; + energy_y = 0.0f; + signal_a = &signal[x]; + signal_b = &signal[y]; + for (j = 0; j < corr_len; j += subsampling) { - sumXY = L_mac0(sumXY, signalX[i], signalY[i]); - sumXX = L_mac0(sumXX, signalX[i], signalX[i]); - sumYY = L_mac0(sumYY, signalY[i], signalY[i]); + c_c += ((Float32) signal_a[j] * (Float32) signal_b[j]); + energy_x += ((Float32) signal_a[j]) * ((Float32) signal_a[j]); + energy_y += ((Float32) signal_b[j]) * ((Float32) signal_b[j]); + } + energy_xy = (Float32)sqrt((Float32)energy_x * (Float32)energy_y); + if(energy_xy < 1.0f) + { + energy_xy = 1.0f; /* conceal silent frames */ } - normX = norm_l(sumXX); - sumXX = L_shl(sumXX, normX); - normY = norm_l(sumYY); - sumYY = L_shl(sumYY, normY); - product = L_mult0(extract_h(sumXX), extract_h(sumYY)); - normXY = add(normX, normY); - normXY = sub(normXY, 32); - - /* change norm to factor of 2 */ - IF( s_and(normXY, 0x1) != 0 ) - { - product = L_shr(product, 1); - normXY = sub(normXY, 1); - } - sqrtXY = getSqrtWord32(product); - normXY = shr(normXY, 1); - - IF(sqrtXY != 0) - { - normCC = 0; - move16(); - cc = BASOP_Util_Divide3216_Scale(sumXY, sqrtXY, &normCC); - normCC = add(normCC, 16); - /* scale to Q15 with saturation */ - BASOP_SATURATE_WARNING_OFF - cc = shl_r(cc, add(normXY, normCC)); - BASOP_SATURATE_WARNING_ON - *energy = L_shr_r(L_deposit_l(sqrtXY), normXY); - } - ELSE /* conceal silent frames */ - { - cc = 0; - move16(); - *energy = L_deposit_l(1); - } - - return cc; /* Q15 */ + c_c = c_c / energy_xy; + *energy = energy_xy; + return c_c; } /* Splits the signal into segments and checks if all of them have very low energy. */ -Word8 isSilence(const Word16 * signal, Word16 len, Word16 segments) +bool_t isSilence(const int16_t * signal, uint32_t len, uint32_t segments) { - Word16 i, j, samplesPerSegment; - Word32 energy, maxEnergy; - Word8 ret; + uint32_t i, samplesPerSegment; + Float energy; - assert(len > 0); - assert(segments > 0); - - /* Every segment is checked using the following formula: - * 10 * log10(sum_i(signal[i]*signal[i]))) > -65 - * For simplification/complexity, this is replaced by: - * 20 * log10(sum_i(abs(signal[i]))) > -65 - */ - - ret = 1; - move16(); - energy = L_deposit_l(0); - samplesPerSegment = idiv1616U(len, segments); - /* calculate maxEnergy with factor 2 to reduce rounding error */ - maxEnergy = L_mult0(samplesPerSegment, 37); /* 37 = 2 * exp10(-65.0 / 20) * 32768 */ - maxEnergy = L_shr(maxEnergy, 1); - j = samplesPerSegment; - move16(); - /* check all but last segment */ - FOR(i = 0; i < len; i++) + energy = 0; + samplesPerSegment = len / segments; + for(i = 0; i < len; i++) { - /* division by 32768 is done later */ - energy = L_add(energy, L_abs(L_deposit_l(signal[i]))); - IF( sub(i, j) == 0 ) + energy += (signal[i] / 32768.f) * (signal[i] / 32768.f); + if( ( i != 0U && i % samplesPerSegment == 0U ) || i + 1 == len ) { /* check energy of current segment */ - /* 20 * log10(energy / 32768 / samplesPerSegment) > -65 - * => energy > samplesPerSegment * 10 ^ (-65 / 20) * 32768 */ - IF( L_sub(energy, maxEnergy) > 0 ) + energy = 10 * (Float)log10( energy / samplesPerSegment ); + if( energy > -65 ) { - ret = 0; - move16(); - BREAK; + return false; } - energy = L_deposit_l(0); - j = add(j, samplesPerSegment); + energy = 0; } } - /* check last segment */ - if( L_sub(energy, maxEnergy) > 0 ) - { - ret = 0; - move16(); - } - return ret; + return true; } diff --git a/src/libs/libevs/lib_dec/jbm_pcmdsp_similarityestimation.h b/src/libs/libevs/lib_dec/jbm_pcmdsp_similarityestimation.h old mode 100755 new mode 100644 index 5a2d75f5..8f32014d --- a/src/libs/libevs/lib_dec/jbm_pcmdsp_similarityestimation.h +++ b/src/libs/libevs/lib_dec/jbm_pcmdsp_similarityestimation.h @@ -1,20 +1,14 @@ /*==================================================================================== - EVS Codec 3GPP TS26.442 Apr 03, 2018. Version 12.11.0 / 13.6.0 / 14.2.0 + EVS Codec 3GPP TS26.443 Nov 13, 2018. Version 12.11.0 / 13.7.0 / 14.3.0 / 15.1.0 ====================================================================================*/ -/*! @file pcmdsp_similarityestimation.h Algorithms for correlation and similarity estimation. */ +/*! @file jbm_pcmdsp_similarityestimation.h Algorithms for correlation and similarity estimation. */ -#ifndef PCMDSP_SIMILARITYESTIMATION_H -#define PCMDSP_SIMILARITYESTIMATION_H PCMDSP_SIMILARITYESTIMATION_H +#ifndef JBM_PCMDSP_SIMILARITYESTIMATION_H +#define JBM_PCMDSP_SIMILARITYESTIMATION_H JBM_PCMDSP_SIMILARITYESTIMATION_H /* local headers */ -#include "stl.h" - -/*! Returns the number of right shifts to be applied to the signal before correlation functions. */ -Word16 getSignalScaleForCorrelation(Word32 sampleRate); - -/*! Copies the right shifted signal to another buffer. */ -void scaleSignal16(const Word16 *src, Word16 *dst, Word16 n, Word16 rightShift); +#include "jbm_types.h" /* ******************************************************************************** @@ -22,7 +16,7 @@ void scaleSignal16(const Word16 *src, Word16 *dst, Word16 n, Word16 rightShift); * Function : cross_correlation_self * Tables : * Compile Defines : -* Return : (float) cross correlation coefficient +* Return : (Float) cross correlation coefficient * Information : Calculate cross correlation coefficient for template * segment. * The returned value is signal-energy dependant. @@ -36,12 +30,15 @@ void scaleSignal16(const Word16 *src, Word16 *dst, Word16 n, Word16 rightShift); * ---- * j=0 * +* +* 23-JUL-04 S.Doehla initial version +* ******************************************************************************** */ -Word32 cross_correlation_self(const Word16 * signal, - Word16 x, - Word16 y, - Word16 corr_len); +Float cross_correlation_self(const int16_t * signal, + uint16_t x, + uint16_t y, + uint16_t corr_len); /* ******************************************************************************** @@ -49,7 +46,7 @@ Word32 cross_correlation_self(const Word16 * signal, * Function : cross_correlation_subsampled_self * Tables : * Compile Defines : -* Return : (float) cross correlation coefficient +* Return : (Float) cross correlation coefficient * Information : Calculate cross correlation coefficient for template * segment. * The returned value is signal-energy dependant. @@ -63,13 +60,16 @@ Word32 cross_correlation_self(const Word16 * signal, * ---- * j=0 * +* +* 23-JUL-04 S.Doehla initial version +* ******************************************************************************** */ -Word32 cross_correlation_subsampled_self(const Word16 * signal, - Word16 x, - Word16 y, - Word16 corr_len, - Word16 subsampling); +Float cross_correlation_subsampled_self(const int16_t * signal, + uint16_t x, + uint16_t y, + uint16_t corr_len, + uint16_t subsampling); /* ******************************************************************************** @@ -77,13 +77,16 @@ Word32 cross_correlation_subsampled_self(const Word16 * signal, * Function : normalized_cross_correlation_self * Tables : * Compile Defines : -* Return : (float) normalized cross correlation coefficient +* Return : (Float) normalized cross correlation coefficient * Information : Calculate normalized cross correlation coefficient * for template segment. * The returned value is signal-energy independant. * This means, no matter how loud your signal is, equal * signals will return 1.0, cross-phased signals -1.0. * +* Complexity is very high due to many floating point +* operations and using squared root! +* * This function fills parameter energy with the common * energy of signal x and signal y. This might be useful * for silence detection. @@ -95,20 +98,23 @@ Word32 cross_correlation_subsampled_self(const Word16 * signal, * \ (j+x)*(j+y) * \ __________________ * / -------------- -* / -/ (j+x)���+(j+y)��� +* / -/ (j+x)�+(j+y)� * ---- * j=0 * +* +* 23-JUL-04 S.Doehla initial version +* ******************************************************************************** */ -Word16 normalized_cross_correlation_self(const Word16 * signal, - Word16 x, - Word16 y, - Word16 corr_len, - Word16 subsampling, - Word32 * energy); +Float normalized_cross_correlation_self(const int16_t * signal, + uint16_t x, + uint16_t y, + uint16_t corr_len, + uint16_t subsampling, + Float * energy); /* Splits the signal into segments and checks if all of them have very low energy. */ -Word8 isSilence(const Word16 * signal, Word16 len, Word16 segments); +bool_t isSilence(const int16_t * signal, uint32_t len, uint32_t segments); -#endif /* PCMDSP_SIMILARITYESTIMATION_H */ +#endif /* JBM_PCMDSP_SIMILARITYESTIMATION_H */ diff --git a/src/libs/libevs/lib_dec/jbm_pcmdsp_window.cpp b/src/libs/libevs/lib_dec/jbm_pcmdsp_window.cpp old mode 100755 new mode 100644 index 2081fa39..4c89574a --- a/src/libs/libevs/lib_dec/jbm_pcmdsp_window.cpp +++ b/src/libs/libevs/lib_dec/jbm_pcmdsp_window.cpp @@ -1,41 +1,88 @@ /*==================================================================================== - EVS Codec 3GPP TS26.442 Apr 03, 2018. Version 12.11.0 / 13.6.0 / 14.2.0 + EVS Codec 3GPP TS26.443 Nov 13, 2018. Version 12.11.0 / 13.7.0 / 14.3.0 / 15.1.0 ====================================================================================*/ -/*! @file pcmdsp_window.c Window functions. */ - -/* instrumentation headers */ -/* local headers */ -#include "jbm_pcmdsp_window.h" +#include +#include #include "options.h" -#include "stl.h" +#include "jbm_pcmdsp_window.h" +#include "cnst.h" +/*-----------------------------------------------------------------------* +* hannWindow() +* +* Generates a Hann window (cos-shaped) of length n +*-----------------------------------------------------------------------*/ -/* Overlap/Add of two signal with a given window. */ -void overlapAdd(const Word16 *fadeOut, const Word16 *fadeIn, Word16 *out, - Word16 n, Word16 nChannels, const Word16 *fadeOutWin, const Word16 *fadeInWin, Word16 hannIncrementor ) +void hannWindow( + uint16_t n, + Float * w +) { - Word32 fdOutVal, fdInVal; - Word16 i, j, hannIter, combinedVal; + uint16_t i; + Float arg; + + for (i = 0; i < n/2; i++) + { + arg = ((2.0f * EVS_PI) * i) / (Float) (n); + w[i] = (Float) ((1.0f - cos (arg)) / 2.0f); + } + + for ( ; i < n; i++) + { + w[i] = 1.0f - w[i-n/2]; + } + + return; +} - FOR(j = 0; j < nChannels; j++) +/*-----------------------------------------------------------------------* +* overlapAdd() +* +* Overlap/Add of two signal with a given window +*-----------------------------------------------------------------------*/ + +void overlapAdd( + const int16_t *fadeOut, + const int16_t *fadeIn, + int16_t *out, + uint16_t n, + uint16_t nChannels, + const float *fadeOutWin, + const float *fadeInWin +) +{ + float fdOutVal, fdInVal; + int16_t i, j, hannIter; + int32_t combinedVal; + + for(j = 0; j < nChannels; j++) { /* reset Hann window iterator to beginning (both channels use same window) */ hannIter = 0; - move16(); - FOR( i = j; i < n; i += nChannels ) + for(i = j; i < n; i += nChannels) { - fdOutVal = L_mult( fadeOut[i], fadeOutWin[hannIter] ); - fdInVal = L_mult( fadeIn[i], fadeInWin[hannIter] ); - /* round to 16bit value and saturate (L_add already applies saturation) */ - combinedVal = round_fx( L_add( fdOutVal, fdInVal ) ); + fdOutVal = fadeOut[i] * fadeOutWin[hannIter]; + fdInVal = fadeIn[i] * fadeInWin[hannIter]; + /* round combinedVal value (taking care of sign) */ + combinedVal = (int32_t)( (fdInVal + fdOutVal) + 0.5 ); - out[i] = combinedVal; - move16(); - /* advance the Hann window iterator by incrementor (dependent on sample rate). */ - hannIter = add( hannIter, hannIncrementor ); + if( fdInVal + fdOutVal < 0.0 ) + combinedVal = (int32_t)( (fdInVal + fdOutVal) - 0.5 ); + /* saturate value */ + if (combinedVal > 32767) + { + combinedVal = 32767; + } + else if (combinedVal < -32768) + { + combinedVal = -32768; + } + out[i] = (int16_t) combinedVal; + hannIter++; } } -} + return; +} diff --git a/src/libs/libevs/lib_dec/jbm_pcmdsp_window.h b/src/libs/libevs/lib_dec/jbm_pcmdsp_window.h old mode 100755 new mode 100644 index b495b58c..b97e026e --- a/src/libs/libevs/lib_dec/jbm_pcmdsp_window.h +++ b/src/libs/libevs/lib_dec/jbm_pcmdsp_window.h @@ -1,16 +1,16 @@ /*==================================================================================== - EVS Codec 3GPP TS26.442 Apr 03, 2018. Version 12.11.0 / 13.6.0 / 14.2.0 + EVS Codec 3GPP TS26.443 Nov 13, 2018. Version 12.11.0 / 13.7.0 / 14.3.0 / 15.1.0 ====================================================================================*/ -/*! @file pcmdsp_window.h Window functions. */ +/*! @file jbm_jbm_pcmdsp_window.h Window functions. */ -#ifndef PCMDSP_WINDOW_H -#define PCMDSP_WINDOW_H PCMDSP_WINDOW_H +#ifndef JBM_PCMDSP_WINDOW_H +#define JBM_PCMDSP_WINDOW_H JBM_PCMDSP_WINDOW_H -/* instrumentation headers */ -#include "basop_util.h" +/* local headers */ +#include "jbm_types.h" -/*! Tables contain a Hann window (cos-shaped) of length 960 or 640. +/*! Generates a Hann window (cos-shaped) of length n. * Roughly: * * 1 __ @@ -19,8 +19,7 @@ * <------> * n */ -extern const Word16 pcmdsp_window_hann_960[960]; -extern const Word16 pcmdsp_window_hann_640[640]; +void hannWindow(uint16_t n, Float * w); /** Overlap/Add of two signal with a given window. */ /** @param[in] fadeOut signal to fade out @@ -30,7 +29,7 @@ extern const Word16 pcmdsp_window_hann_640[640]; * @param[in] nChannels number of channels * @param[in] fadeOutWin window for fade out * @param[in] fadeInWin window for fade in */ -void overlapAdd(const Word16 *fadeOut, const Word16 *fadeIn, Word16 *out, - Word16 n, Word16 nChannels, const Word16 *fadeOutWin, const Word16 *fadeInWin, Word16 hannIncrementor); +void overlapAdd(const int16_t *fadeOut, const int16_t *fadeIn, int16_t *out, + uint16_t n, uint16_t nChannels, const float *fadeOutWin, const float *fadeInWin); -#endif /* PCMDSP_WINDOW_H */ +#endif /* JBM_PCMDSP_WINDOW_H */ diff --git a/src/libs/libevs/lib_dec/jbm_types.h b/src/libs/libevs/lib_dec/jbm_types.h new file mode 100644 index 00000000..2f44448b --- /dev/null +++ b/src/libs/libevs/lib_dec/jbm_types.h @@ -0,0 +1,70 @@ +/*==================================================================================== + EVS Codec 3GPP TS26.443 Nov 13, 2018. Version 12.11.0 / 13.7.0 / 14.3.0 / 15.1.0 + ====================================================================================*/ + +/*! @file jbm_types.h Data types used for JBM. */ + +#ifndef JBM_TYPES_H +#define JBM_TYPES_H JBM_TYPES_H + +/************************** +* internally used types +***************************/ +#ifndef _WIN32 +#include /* part of C99 */ +#else + +#ifndef _UINT8_T +#define _UINT8_T +typedef unsigned char uint8_t; +#endif /* _UINT8_T */ + +#ifndef _INT8_T +#define _INT8_T +typedef signed char int8_t; +#endif /* _INT8_T */ + +#ifndef _UINT16_T +#define _UINT16_T +typedef unsigned short uint16_t; +#endif /* _UINT16_T */ + +#ifndef _INT16_T +#define _INT16_T +typedef signed short int16_t; +#endif /* _INT16_T */ + +#ifndef _UINT32_T +#define _UINT32_T +typedef unsigned int uint32_t; +#endif /* _UINT32_T */ + +#ifndef _INT32_T +#define _INT32_T +typedef signed int int32_t; +#endif /* _INT32_T */ + +#ifndef _UINT64_T +#define _UINT64_T +typedef unsigned __int64 uint64_t; +#endif /* _UINT64_T */ + +#ifndef _INT64_T +#define _INT64_T +typedef signed __int64 int64_t; +#endif /* _INT64_T */ + +#endif +#ifndef _BOOL_T +#define _BOOL_T +typedef unsigned char bool_t; +#endif /* _BOOL_T */ + +#define true (1) +#define false (0) + +typedef float Float; + +#include "typedef.h" + +#endif /* JBM_TYPES_H */ diff --git a/src/libs/libevs/lib_dec/lead_deindexing.cpp b/src/libs/libevs/lib_dec/lead_deindexing.cpp new file mode 100644 index 00000000..50eb9da7 --- /dev/null +++ b/src/libs/libevs/lib_dec/lead_deindexing.cpp @@ -0,0 +1,232 @@ +/*==================================================================================== + EVS Codec 3GPP TS26.443 Nov 13, 2018. Version 12.11.0 / 13.7.0 / 14.3.0 / 15.1.0 + ====================================================================================*/ + +#include "options.h" +#include "cnst.h" +#include "prot.h" +#include "rom_com.h" +#include "rom_dec.h" + +/*-------------------------------------------------------------------* + * Local function prototype + *-------------------------------------------------------------------*/ +static void fcb_decode_pos(int index, int pos_vector[], int pulse_num, int pos_num); + +/*-------------------------------------------------------------------* + * re8_decode_base_index + * + * Decode RE8 base index + *-------------------------------------------------------------------*/ + +void re8_decode_base_index( + int n, /* i : codebook number (*n is an integer defined in {0,2,3,4,..,n_max}) */ + long I, /* i : index of c (pointer to unsigned 16-bit word) */ + int *x /* o : point in RE8 (8-dimensional integer vector) */ +) +{ + int i,j,k1,l,m,m1,m2; + int setor_8p_temp[8],setor_8p_temp_1[8],setor_8p_temp_2[8]= {0}; + int sign_8p; + int code_level; + const int *a1,*a2; + + int ka; + int offset; + int code_index; + int element_a10,element_a11,element_a12; + + + element_a11 = 0, + element_a12 = 0; + if (n < 2) + { + for (i=0; i<8; i++) + { + x[i]=0; + } + } + else + { + if ( I > 65519L ) + { + I = 0; + } + /*-------------------------------------------------------------------* + * search for the identifier ka of the absolute leader (table-lookup) + * Q2 is a subset of Q3 - the two cases are considered in the same branch + *-------------------------------------------------------------------*/ + if ( n <= 3 ) + { + for (i=1; i> k1 ; + + m = 0; + m1 = 0; + m2 = 0; + + element_a10 = a1[0]; + switch (code_level) + { + case 4: + + m2 = 1; /*a2[4];*/ + i = code_index & 1; + if( i == 0) + setor_8p_temp_2[0] = 0; + else + setor_8p_temp_2[0] = 1; + code_index = code_index >> 1; + + case 3: + + m = a2[2]; + m1 = a2[3]; + l = select_table22[m1][m]; + j = ( code_index * mult_avq_tab[l] ) >> shift_avq_tab[l]; + code_index = code_index - j * l; + fcb_decode_pos(code_index,setor_8p_temp_1,m,m1); + code_index = j; + element_a12 = a1[2]; + + case 2: + + m = a2[2]; + fcb_decode_pos(code_index,setor_8p_temp,8,m); + element_a11 = a1[1]; + } + + for (i=0; i<8; i++) + { + x[i] = element_a10; + } + + for (i=0; i> m1 ) & 1 ) + { + x[i] *= -1; + } + m1 --; + } + } + + /*--------------------------------------------------------------------* + * recover the sign of last element if needed + *--------------------------------------------------------------------*/ + if ( k1 == 7 ) + { + m1 = 0; + + for (i=0; i<8; i++) + { + m1 += x[i] ; + } + if ( m1 & 3 ) + { + x[7] *= -1; + } + } + } + + return; +} + + +/*-------------------------------------------------------------------* + * fcb_decode_pos + * + * base function for decoding position index + *-------------------------------------------------------------------*/ + +void fcb_decode_pos( + int index, /* i : Index to decoder */ + int pos_vector[], /* o : Position vector */ + int pulse_num, /* i : Number of pulses */ + int pos_num /* i : Number of positions */ +) +{ + int i,k,l; + int temp1,temp2; + + const int *select_table23; + const int *select_table24; + + k = index; + l = 0; + temp1 = pos_num; + temp2 = pulse_num+1; + + for( i=0; i 0 ) - { - I = 0; - move16(); - } - - /*-------------------------------------------------------------------* - * search for the identifier ka of the absolute leader (table-lookup) - * Q2 is a subset of Q3 - the two cases are considered in the same branch - *-------------------------------------------------------------------*/ - IF (sub(n,3) <= 0 ) - { - FOR (i = 1; i < NB_LDQ3; i++) - { - IF (L_sub(I, I3_fx[i]) < 0) - { - BREAK; - } - } - ka = A3_fx[sub(i,1)]; - move16(); - } - ELSE - { - FOR (i = 1; i < NB_LDQ4; i++) - { - IF (L_sub(I, I4_fx[i]) < 0) - { - BREAK; - } - } - ka = A4_fx[sub(i,1)]; - move16(); - } - - /*-------------------------------------------------------* - * decode - *-------------------------------------------------------*/ - a1 = vals_a_fx[ka]; - move16(); - a2 = vals_q_fx[ka]; - move16(); - k1 = a2[0]; - move16(); - code_level = a2[1]; - move16(); - - offset = Is_fx[ka]; - move16(); - code_index = extract_l( L_sub( I, offset ) ); - - sign_8p = s_and(code_index, sub( shl(1,k1), 1 )); - - code_index = shr(code_index, k1); - - m = 0; - move16(); - m1 = 0; - move16(); - m2 = 0; - move16(); - - element_a10 = a1[0]; - move16(); - - SWITCH (code_level) - { - case 4: - - m2 = 1; - move16(); - i = s_and(code_index, 1); - setor_8p_temp_2[0] = 0; - move16(); - - if ( i ) - { - setor_8p_temp_2[0] = 1; - move16(); - } - code_index = shr(code_index, 1); - /* no break */ - - case 3: - - m = a2[2]; - move16(); - m1 = a2[3]; - move16(); - - l = select_table22_fx[m1][m]; - move16(); - j = extract_l(L_shr(L_mult0(code_index, mult_avq_tab_fx[l]), shift_avq_tab_fx[l])); - code_index = sub(code_index, extract_l(L_mult0(j, l))); - fcb_decode_pos_fx(code_index,setor_8p_temp_1, m, m1); - - code_index = j; - move16(); - element_a12 = a1[2]; - move16(); - /* no break */ - - case 2: - - m = a2[2]; - move16(); - fcb_decode_pos_fx(code_index,setor_8p_temp,8,m); - element_a11 = a1[1]; - move16(); - } - - FOR (i=0; i<8; i++) - { - x[i] = element_a10; - move16(); - } - - FOR (i=0; i= ACELP_11k60 ) + { + lp_flag = (short)get_next_indice( st, 1 ); + } + else + { + lp_flag = FULL_BAND; + } + } + + /*--------------------------------------------------------------------* + * Find pitch excitation with LP filter + *--------------------------------------------------------------------*/ + + if ( lp_flag == LOW_PASS ) + { + /* pointer positionning to avoid doing it inside the loop */ + if( codec_mode == MODE2 && L_frame == L_FRAME16k ) + { + for (i=0; i= 0) - { - lp_flag = (Word16)get_next_indice_fx( st_fx, 1 ); - move16(); - } - ELSE - { - lp_flag = FULL_BAND; - move16(); - } - } - - IF ( sub(lp_flag, LOW_PASS) == 0) - { - /* pointer positionning to avoid doing it inside the loop */ - test(); - IF(codec_type==MODE2 && L_frame==L_FRAME16k) - { - fac_n = 6881/*0.21f Q15*/; - fac_m = 19005/*0.58f Q15*/; - } - ELSE - { - fac_n = 5898/*0.18f Q15*/; - fac_m = 20972/*0.64f Q15*/; - } - - FOR (i=0; i +#include +#include "options.h" +#include "cnst.h" +#include "rom_com.h" +#include "prot.h" +#include "basop_proto_func.h" + +/*---------------------------------------------------------------------* + * Local functions + *---------------------------------------------------------------------*/ +static void lsf_mid_dec( Decoder_State *st, const float int_fs, float qlsp0[], float qlsp1[], short coder_type, float qlsp[], + const long core_brate, short ppp_mode, short nelp_mode, short prev_bfi, short *mid_lsf_int, short safety_net ); + +static void dqlsf_CNG( Decoder_State *st, float *lsf_q, unsigned int *p_offset_scale1, unsigned int *p_offset_scale2, short *p_no_scales ); + +/*---------------------------------------------------------------------* + * lsf_dec() + * + * LSF decoder + *---------------------------------------------------------------------*/ + +void lsf_dec( + Decoder_State *st, /* i/o: State structure */ + const short tc_subfr, /* i : TC subframe index */ + const short L_frame, /* i : length of the frame */ + const short coder_type, /* i : coding type */ + const short bwidth, /* i : input signal bandwidth */ + float *Aq, /* o : quantized A(z) for 4 subframes */ + short *LSF_Q_prediction, /* o : LSF prediction mode */ + float *lsf_new, /* o : de-quantized LSF vector */ + float *lsp_new, /* o : de-quantized LSP vector */ + float *lsp_mid /* o : de-quantized mid-frame LSP vector */ +) +{ + short i, nBits = 0; + float int_fs; + float tmp_old[M+1], tmp_new[M+1], enr_old = 0.0f, enr_new = 0.0f; + float lsf_diff = 0.0f; + + /* initialize */ + if( L_frame == L_FRAME ) + { + int_fs = INT_FS_12k8; + } + else /* L_frame == L_FRAME16k */ + { + int_fs = INT_FS_16k; + } + + /* Find the number of bits for LSF quantization */ + if ( st->core_brate == SID_2k40 ) + { + nBits = LSF_BITS_CNG; + } + else + { + if ( st->nelp_mode_dec == 0 && st->ppp_mode_dec == 0 ) + { + nBits = LSF_bits_tbl[LSF_BIT_ALLOC_IDX(st->core_brate, coder_type)]; + } + else if ( st->nelp_mode_dec == 1 ) + { + if ( coder_type == UNVOICED ) + { + if ( bwidth == NB ) + { + nBits = 32; + + } + else + { + nBits = 30; + + + } + } + } + else if ( st->ppp_mode_dec == 1 ) + { + nBits = 26; + + } + } + + /* LSF de-quantization */ + lsf_end_dec( st, coder_type, st->bwidth, nBits, lsf_new, st->mem_AR,st->mem_MA, int_fs, st->core_brate, + &st->offset_scale1[0][0], &st->offset_scale2[0][0], &st->offset_scale1_p[0][0], &st->offset_scale2_p[0][0], + &st->no_scales[0][0], &st->no_scales_p[0][0], &st->safety_net, NULL, LSF_Q_prediction, NULL ); + + /* convert quantized LSFs to LSPs */ + lsf2lsp( lsf_new, lsp_new, M, int_fs ); + + if( st->core_brate == SID_2k40 ) + { + /* return if SID frame (conversion to A(z) done in the calling function) */ + return; + } + + /*-------------------------------------------------------------------------------------* + * FEC - update adaptive LSF mean vector + *-------------------------------------------------------------------------------------*/ + + for ( i=0; ilsf_adaptive_mean[i] = (st->lsfoldbfi1[i] + st->lsfoldbfi0[i] + lsf_new[i]) / 3; + } + + if( st->prev_bfi && (coder_type == TRANSITION) && (tc_subfr == (L_frame-L_SUBFR)) ) + { + lsf_diff = int_fs / (float)(2*(M+1)); + st->lsf_old[0] = lsf_diff; + + for ( i=1; ilsf_old[i] = st->lsf_old[i-1] + lsf_diff; + } + lsf2lsp( st->lsf_old, st->lsp_old, M, int_fs ); + } + + /*-------------------------------------------------------------------------------------* + * Mid-frame LSF decoding + * LSP interpolation and conversion of LSPs to A(z) + *-------------------------------------------------------------------------------------*/ + if( st->rate_switching_reset ) + { + /* extrapolation in case of unstable LSF convert */ + mvr2r( lsp_new, st->lsp_old, M ); + mvr2r( lsf_new, st->lsf_old, M ); + } + + lsf_mid_dec( st, int_fs, st->lsp_old, lsp_new, coder_type, lsp_mid, st->core_brate, st->ppp_mode_dec, st->nelp_mode_dec, + st->prev_bfi, &(st->mid_lsf_int), st->safety_net ); + + if ( !( st->prev_bfi && (coder_type == TRANSITION) && (tc_subfr == (L_frame-L_SUBFR)) ) ) + { + if (st->prev_bfi) + { + /* check, if LSP interpolation can be relaxed */ + lsp2a_stab( st->lsp_old, tmp_old, M); + enr_old = enr_1_Az( tmp_old, 2*L_SUBFR ); + + lsp2a_stab( lsp_new, tmp_new, M); + enr_new = enr_1_Az( tmp_new, 2*L_SUBFR ); + } + + if (st->prev_bfi) + { + if ( enr_new/enr_old < 0.3f ) + { + st->relax_prev_lsf_interp = -1; + if ( st->clas_dec == UNVOICED_CLAS || st->clas_dec == SIN_ONSET || st->clas_dec == INACTIVE_CLAS || coder_type == GENERIC || coder_type == TRANSITION ) + { + st->relax_prev_lsf_interp = 1; + } + } + } + } + + if( st->last_core == HQ_CORE && st->core == ACELP_CORE ) + { + /* update old LSPs/LSFs in case of HQ->ACELP core switching */ + mvr2r( lsp_mid, st->lsp_old, M ); + lsp2lsf( lsp_mid, st->lsf_old, M, int_fs ); + } + + /* LSP interpolation and conversion of LSPs to A(z) */ + int_lsp4( L_frame, st->lsp_old, lsp_mid, lsp_new, Aq, M, st->relax_prev_lsf_interp ); + + /*------------------------------------------------------------------* + * Check LSF stability (distance between old LSFs and current LSFs) + *------------------------------------------------------------------*/ + + st->stab_fac = lsf_stab( lsf_new, st->lsf_old, 0, st->L_frame); + + return; +} + + + +/*------------------------------------------------------------------------------------------* + * lsf_end_dec() + * + * De-quantize frame end LSF vector + *------------------------------------------------------------------------------------------*/ + +void lsf_end_dec( + Decoder_State *st, /* i/o: decoder state structure */ + const short coder_type_org, /* i : coding type */ + const short bwidth, /* i : input signal bandwidth */ + const short nBits_in, /* i : number of bits used for ISF quantization*/ + float *qlsf, /* o : quantized LSFs in the cosine domain */ + float *mem_AR, /* i/o: quantizer memory for AR model */ + float *mem_MA, /* i/o: quantizer memory for MA model */ + const float int_fs, /* i : sampling frequency */ + long core_brate, /* i : Coding Bit Rate */ + unsigned int *p_offset_scale1, + unsigned int *p_offset_scale2, + unsigned int *p_offset_scale1_p, + unsigned int *p_offset_scale2_p, + short *p_no_scales, + short *p_no_scales_p, + short *safe_net, + int *lpc_param, + short *LSF_Q_prediction, /* o : LSF prediction mode */ + int * nb_indices +) +{ + float pred0[M]; /* Prediction for the safety-net quantizer (usually mean)*/ + float pred1[M], pred2[M]; /* Prediction for the predictive quantizer*/ + short stages0; /* Amount of stages used by safety-net quantizer*/ + short stages1; /* Amount of stages used by predictive quantizer*/ + short levels0[MAX_VQ_STAGES]; /* Sizes of different codebook stages for safety-net quantizer*/ + short levels1[MAX_VQ_STAGES]; /* Sizes of different codebook stages for predictive quantizer*/ + short i; + short TCQIdx[M/2+4]; + short bits0[MAX_VQ_STAGES], bits1[MAX_VQ_STAGES]; + int cumleft; + short lindice[MAX_VQ_STAGES+3]; /* Predictor selector needs 1 bit and the LVQ indice uses 3 shorts */ + short mode_lvq, mode_lvq_p; + short safety_net, predmode, stages, *levels; + const short *Bit_alloc1 = NULL, *bits; + short num_bits; + int * p_lpc_param; + + int nr_ind; + short nBits; + + short coder_type; + nBits = nBits_in; + + if( (coder_type_org == GENERIC) && (int_fs == INT_FS_16k) && (st->codec_mode == MODE1) ) + { + coder_type = (short)get_next_indice( st, 1 ); + coder_type += 2; + if( coder_type == GENERIC ) + { + nBits--; + } + } + else + { + coder_type = coder_type_org; + } + + /*--------------------------------------------------------------------------------* + * LSF de-quantization of SID frames + *--------------------------------------------------------------------------------*/ + + if ( core_brate == SID_2k40 ) + { + dqlsf_CNG( st, qlsf, p_offset_scale1, p_offset_scale2, p_no_scales ); + v_sort( qlsf, 0, M-1); + reorder_lsf( qlsf, MODE1_LSF_GAP, M, int_fs ); + + return; + } + + predmode = find_pred_mode(coder_type, bwidth, int_fs, &mode_lvq, &mode_lvq_p, st->total_brate); + + /*----------------------------------------------------------------* + * Calculate number of stages and levels for each stage based on the allowed bit allocation + * (subtract one bit for LSF predictor selection) + *----------------------------------------------------------------*/ + + lsf_allocate( nBits-(predmode>>1), mode_lvq, mode_lvq_p, &stages0, &stages1, levels0, levels1, bits0, bits1 ); + + /*--------------------------------------------------------------------------* + * Select safety_net or predictive mode + *--------------------------------------------------------------------------*/ + + p_lpc_param = lpc_param; + + nr_ind = 0; + if( predmode == 0 ) + { + safety_net = 1; + } + else if ( predmode == 1 ) + { + safety_net = 0; + } + else + { + if( st->codec_mode == MODE2 ) + { + nr_ind ++; + /* read from param_lpc */ + safety_net = p_lpc_param[0]; + p_lpc_param++; + } + else + { + safety_net = (short)get_next_indice( st, 1 ); + } + } + + *safe_net = safety_net; + + /*--------------------------------------------------------------------------* + * Read indices from array + *--------------------------------------------------------------------------*/ + + if ( safety_net ) + { + stages = stages0; + levels = levels0; + bits = bits0; + } + else + { + stages = stages1; + levels = levels1; + bits = bits1; + } + + if( st->codec_mode == MODE2 ) + { + /* VOICED_WB@16kHz */ + if ( int_fs == INT_FS_16k && coder_type == VOICED ) + { + *nb_indices = 10; + for(i=0; i<*nb_indices; i++) + { + TCQIdx[i] = (short)lpc_param[i]; + } + } + else + { + for ( i=0; i 0 ) + { + if ( cumleft > LEN_INDICE ) + { + cumleft -= LEN_INDICE; + num_bits = LEN_INDICE; + } + else + { + num_bits = (short)cumleft; + cumleft = 0; + } + + lindice[i+1] = *p_lpc_param++; + nr_ind++; + i++; + } + *nb_indices = nr_ind; + } + } + else + { + /* VOICED_WB@16kHz */ + if ( int_fs == INT_FS_16k && coder_type == VOICED ) + { + Bit_alloc1 = &BC_TCVQ_BIT_ALLOC_40B[1]; + TCQIdx[0] = safety_net; + for ( i=0; i 0 ) + { + if ( cumleft > LEN_INDICE ) + { + cumleft -= LEN_INDICE; + num_bits = LEN_INDICE; + } + else + { + num_bits = (short)cumleft; + cumleft = 0; + } + + lindice[i+1] = (short)get_next_indice( st, num_bits ); + i++; + } + } + } + + if( st->reset_mem_AR == 1 ) + { + for( i=0; imem_AR[i] = ModeMeans[mode_lvq][i]; + } + st->reset_mem_AR = 0; + } + + /*------------------------------------------------------------------------------------------* + * De-quantize LSF vector + *------------------------------------------------------------------------------------------*/ + + *LSF_Q_prediction = SAFETY_NET; + + /* VOICED_WB@16kHz */ + if( int_fs == INT_FS_16k && coder_type == VOICED ) + { + /* BC-TCVQ decoder */ + safety_net = qlsf_ARSN_tcvq_Dec_16k ( qlsf, TCQIdx, nBits-1 ); + + /* Update mem_MA */ + mvr2r( qlsf, mem_MA, M ); + + if( safety_net ) + { + mvr2r( ModeMeans[mode_lvq], pred0, M ); + } + else + { + for(i = 0; i < M; i++) + { + pred0[i] = ModeMeans[mode_lvq][i] + Predictors[mode_lvq_p][i]*(mem_AR[i]-ModeMeans[mode_lvq][i]); + } + *LSF_Q_prediction = AUTO_REGRESSIVE; + } + v_add( qlsf, pred0, qlsf, M ); + } + else + { + /* Safety-net */ + mvr2r( ModeMeans[mode_lvq], pred0, M ); + + /* for mem_MA update */ + for (i=0; iBER_detect = st->BER_detect | + vq_dec_lvq( 1, qlsf, &lindice[1], stages0, M, mode_lvq, levels0[stages0-1], + p_offset_scale1, p_offset_scale2, p_offset_scale1_p, p_offset_scale2_p, p_no_scales, p_no_scales_p ); + + v_add( qlsf, pred0, qlsf, M ); + v_sub( qlsf, pred1, mem_MA, M); + } + else + { + st->BER_detect = st->BER_detect | + vq_dec_lvq( 0, qlsf, &lindice[1], stages1, M, mode_lvq_p, levels1[stages1-1], + p_offset_scale1, p_offset_scale2, p_offset_scale1_p, p_offset_scale2_p, p_no_scales, p_no_scales_p ); + + if( predmode == 1 ) /* MA only */ + { + mvr2r(qlsf, mem_MA, M); + v_add( qlsf, pred1, qlsf, M ); + *LSF_Q_prediction = MOVING_AVERAGE; + } + else + { + /* AR */ + for ( i=0; imode_lvq = mode_lvq; + + + return; +} + + +/*-------------------------------------------------------------------* + * lsf_mid_dec() + * + * Decode mid-frame LSFs + *-------------------------------------------------------------------*/ + +void lsf_mid_dec( + Decoder_State *st, /* i/o: decoder state structure */ + const float int_fs, /* i : internal (ACELP) sampling frequency */ + float qlsp0[], /* i : quantized LSPs from frame beginning */ + float qlsp1[], /* i : quantized LSPs from frame end */ + short coder_type, /* i : Coder type */ + float qlsp[], /* o : quantized LSPs */ + const long core_brate, /* i : core bitrate */ + short ppp_mode, + short nelp_mode, + short prev_bfi, + short *mid_lsf_int, + short safety_net +) +{ + short j, idx; + short nb_bits; + float qlsf0[M], qlsf1[M], qlsf[M]; + const float *ratio = NULL; + short bad_spacing; + + bad_spacing = 0; + + /* Convert LSPs to LSFs */ + lsp2lsf( qlsp0, qlsf0, M, int_fs ); + lsp2lsf( qlsp1, qlsf1, M, int_fs ); + + /* Codebook selection */ + if( ppp_mode == 1 ) + { + nb_bits = 1; + ratio = &(tbl_mid_voi_wb_1b[0]); + } + else if( nelp_mode == 1 ) + { + nb_bits = 4; + ratio = &(tbl_mid_unv_wb_4b[0]); + } + else + { + nb_bits = mid_LSF_bits_tbl[LSF_BIT_ALLOC_IDX(core_brate, coder_type)]; + + /* codebook selection */ + if( coder_type == VOICED ) + { + switch ( nb_bits ) + { + case 5: + { + ratio = tbl_mid_voi_wb_5b; + break; + } + case 4: + { + ratio = tbl_mid_voi_wb_4b; + break; + } + } + } + else if( coder_type == UNVOICED ) + { + ratio = tbl_mid_unv_wb_5b; + } + else + { + /* GENERIC, TRANSITION, AUDIO and INACTIVE */ + switch ( nb_bits ) + { + case 5: + { + ratio = tbl_mid_gen_wb_5b; + break; + } + case 2: + { + ratio = tbl_mid_gen_wb_2b; + break; + } + } + } + } + + /* Retrieve mid-frame LSF index */ + idx = (short)get_next_indice( st, nb_bits ); + + /* Calculation of mid-LSF vector */ + for(j=0; j 0 && j < M && qlsf[j] < qlsf[j-1] + LSF_GAP_MID ) + { + qlsf[j] = qlsf[j-1] + LSF_GAP_MID; + } + + } + } + else + { + /* otherwise, use regular LSF spacing and ordering as in the encoder */ + for (j=0; j 0 && j < M && qlsf[j] < qlsf[j-1] + LSF_GAP_MID ) + { + qlsf[j] = qlsf[j-1] + LSF_GAP_MID; + } + + } + } + + if( prev_bfi ) + { + /* continue redoing mid-LSF interpolation with 0.4 in order not to propagate the error */ + *mid_lsf_int = 1; + } + + if( safety_net ) + { + /* safety-net encountered -> stop redoing mid-LSF interpolation with 0.4 */ + *mid_lsf_int = 0; + } + + reorder_lsf( qlsf, LSF_GAP_MID, M, int_fs ); + /* convert back to LSPs */ + lsf2lsp( qlsf, qlsp, M, int_fs ); + + return; +} + +/*----------------------------------------------------------------------------------------------* + * dqlsf_CNG() + * + * LSF de-quantizer for SID frames (uses 28 bits, 4 for VQ, 24 for LVQ) + * + * Note: + * LP-CNG LSF decoder does not need to know the sampling rate, + * the sampling rate data is embedded inside the LSF coefficients + * If the highest order LSF coefficient (lsf_q[M-1]) is smaller than 6350 then Fs=12.8kHz + * If the highest order LSF coefficient (lsf_q[M-1]) is larger than 6350 then Fs=16kHz + *----------------------------------------------------------------------------------------------*/ + +static void dqlsf_CNG( + Decoder_State *st, /* i/o: decoder state structure */ + float *lsf_q, /* o : decoded LSFs */ + unsigned int *p_offset_scale1, /* i : offset for 1st LVQ subvector */ + unsigned int *p_offset_scale2, /* i : offset for second LVQ subvector */ + short *p_no_scales /* i : number of scales for LVQ struct */ +) +{ + short indice[4]; + + indice[0] = (short)get_next_indice( st, 4 ); + indice[1] = (short)get_next_indice( st, LEN_INDICE ); + indice[2] = (short)get_next_indice( st, LSF_BITS_CNG - 4 - LEN_INDICE ); + + st->BER_detect = st->BER_detect | + deindex_lvq_cng( &indice[1], lsf_q, indice[0], LSF_BITS_CNG-4, p_offset_scale1, p_offset_scale2, p_no_scales ); + /* The sampling frequency of the LP-CNG frame can be determined by checking the value of the highest order LSF + coefficient (last coefficient of lsf_q). If the last decoded LSF coefficient (lsf_q[15]) is larger than 6350 + the decoded frame is WB2 with sampling rate of 16 kHz, otherwise it is sampled at 12.8kHz and contains + either NB or WB LSF data. */ + + v_add( lsf_q, &CNG_SN1[indice[0]*M], lsf_q, M ); + + if( ((st->L_frame == L_FRAME16k)&&(lsf_q[M-1]<=WB_LIMIT_LSF)) || ((st->L_frameWB_LIMIT_LSF)) ) + { + st->BER_detect = 1; + } + return; +} diff --git a/src/libs/libevs/lib_dec/lsf_dec_fx.cpp b/src/libs/libevs/lib_dec/lsf_dec_fx.cpp deleted file mode 100755 index f775f600..00000000 --- a/src/libs/libevs/lib_dec/lsf_dec_fx.cpp +++ /dev/null @@ -1,864 +0,0 @@ -/*==================================================================================== - EVS Codec 3GPP TS26.442 Apr 03, 2018. Version 12.11.0 / 13.6.0 / 14.2.0 - ====================================================================================*/ - -#include -#include "options.h" /* Compilation switches */ -#include "cnst_fx.h" /* Common constants */ -#include "rom_com_fx.h" /* Static table prototypes */ -#include "prot_fx.h" /* Function prototypes */ -#include "stl.h" - -/*-------------------------------------------------------------------* - * Local functions - *-------------------------------------------------------------------*/ - -/*--------------------------------------------------------------------------------------* -* dqlsf_CNG_fx() -* -* LSF de-quantizer for SID frames (uses 28 bits, 4 for VQ, 24 for LVQ) -* -* Note: -* LP-CNG LSF decoder does not need to know the sampling rate, -* the sampling rate data is embedded inside the LSF coefficients. -* If the highest order LSF coefficient (lsf_q[M-1]) is smaller than 6350 then Fs=12.8kHz -* If the highest order LSF coefficient (lsf_q[M-1]) is larger than 6350 then Fs=16kHz -----------------------------------------------------------------------------------------*/ - -static void dqlsf_CNG_fx( - Decoder_State_fx *st_fx, /* i/o: decoder state structure */ - Word16 *lsf_q, /* o : decoded LSFs */ - Word32 * p_offset_scale1, /* i : offset for 1st LVQ subvector */ - Word32 * p_offset_scale2, /* i : offset for second LVQ subvector */ - Word16 * p_no_scales /* i : number of scales for LVQ struct */ -) -{ - Word16 indice[4]; - Word16 ber_flag; - - indice[0] = (Word16)get_next_indice_fx( st_fx, 4 ); - move16(); - indice[1] = (Word16)get_next_indice_fx( st_fx, LEN_INDICE ); - move16(); - indice[2] = (Word16)get_next_indice_fx( st_fx, LSF_BITS_CNG - 4 - LEN_INDICE ); - move16(); - - /* deindex_lvq_cng decoder does not need to know the sampling rate, the sampling rate data is embedded inside the LSF coefficients */ - ber_flag= - deindex_lvq_cng_fx( &indice[1], lsf_q, indice[0], LSF_BITS_CNG-4, p_offset_scale1, p_offset_scale2, p_no_scales ); - - st_fx->BER_detect = s_or(ber_flag, st_fx->BER_detect); - - /* The sampling frequency of the LP-CNG frame can be determined by checking the value of the highest order LSF coefficient (last coefficient). - If the last decoded LSF coefficient is larger than 6350 the decoded frame is WB2 with sampling rate of 16 kHz - otherwise it is sampled at 12.8kHz and contains either NB or WB LSF data. */ - Vr_add(lsf_q, &CNG_SN1_fx[indice[0] * M], lsf_q, M); - - test(); - test(); - test(); - IF ( ((sub(st_fx->L_frame_fx, L_FRAME16k)==0)&&(sub(lsf_q[M-1],WB_LIMIT_LSF_FX)<=0)) || ((sub(st_fx->L_frame_fx, L_FRAME16k)<0)&&(sub(lsf_q[M-1],WB_LIMIT_LSF_FX)>0))) - { - st_fx->BER_detect = 1; - move16(); - } - - return; -} - -/*===========================================================================*/ -/* FUNCTION : lsf_dec_fx() */ -/*---------------------------------------------------------------------------*/ -/* PURPOSE : LSF decoder */ -/*---------------------------------------------------------------------------*/ -/* INPUT ARGUMENTS : */ -/* _ (Struct) st_fx : decoder static memory */ -/* _ (Word16) L_frame : length of the frame */ -/* _ (Word16) coder_type : coding type */ -/* _ (Word16) bwidth : input signal bandwidth */ -/*---------------------------------------------------------------------------*/ -/* OUTPUT ARGUMENTS : */ -/* _ (Word16*) Aq : LP filter coefficient Q12 */ -/* _ (Word16*) lsf_new : LP filter coefficient Q(x2.56) */ -/* _ (Word16*) lsp_new : LP filter coefficient Q15 */ -/* _ (Word16*) lsp_mid : LP filter coefficient Q15 */ -/*---------------------------------------------------------------------------*/ - -/* _ (Word16[]) st_fx->lsf_adaptive_mean_fx : FEC - adaptive mean LSF */ -/* vector for FEC Q(x2.56) */ -/* _ (Word16[]) st_fx->mem_AR_fx : AR memory of LSF quantizer */ -/* (past quantized LSFs without mean) Q(x2.56) */ -/* _ (Word16) st_fx->stab_fac_fx : LSF stability factor Q15 */ -/*---------------------------------------------------------------------------*/ -/* RETURN ARGUMENTS : */ -/* _ None */ -/*===========================================================================*/ -void lsf_dec_fx( - Decoder_State_fx *st_fx, /* i/o: State structure */ - const Word16 tc_subfr, /* i : TC subframe index */ - const Word16 L_frame, /* i : length of the frame */ - const Word16 coder_type, /* i : coding type */ - const Word16 bwidth, /* i : input signal bandwidth */ - Word16 *Aq, /* o : quantized A(z) for 4 subframes */ - Word16 *LSF_Q_prediction, /* o : LSF prediction mode */ - Word16 *lsf_new, /* o : de-quantized LSF vector */ - Word16 *lsp_new, /* o : de-quantized LSP vector */ - Word16 *lsp_mid /* o : de-quantized mid-frame LSP vector */ -) -{ - Word16 i; - Word16 int_fs; - Word32 L_tmp; - Word16 nBits = 0; - Word16 tmp_old[M+1], tmp_new[M+1]; - Word16 enr_old = 0, enr_new = 0; - Word16 lsf_diff; - /* initialize */ - int_fs = INT_FS_16k_FX; - move16(); - if( sub(L_frame,L_FRAME) == 0 ) - { - int_fs = INT_FS_FX; - move16(); - } - - /* Find the number of bits for LSF quantization */ - IF ( L_sub(st_fx->core_brate_fx,SID_2k40) == 0 ) - { - nBits = LSF_BITS_CNG; - move16(); - } - ELSE - { - test(); - IF ( st_fx->nelp_mode_dec_fx == 0 && st_fx->ppp_mode_dec_fx == 0 ) - { - nBits = LSF_bits_tbl[LSF_BIT_ALLOC_IDX_fx(st_fx->core_brate_fx, coder_type)]; - move16(); - } - ELSE IF ( sub(st_fx->nelp_mode_dec_fx,1) == 0 ) - { - IF ( sub(coder_type,UNVOICED) == 0 ) - { - nBits = 30; - move16(); - if ( sub(bwidth,NB) == 0 ) - { - nBits = 32; - move16(); - } - } - } - ELSE IF ( sub(st_fx->ppp_mode_dec_fx,1) == 0 ) - { - nBits = 26; - move16(); - } - } - - /* LSF de-quantization */ - lsf_end_dec_fx( st_fx, 0, coder_type, st_fx->bwidth_fx, nBits, lsf_new, st_fx->mem_AR_fx,st_fx->mem_MA_fx, int_fs, st_fx->core_brate_fx, - &st_fx->offset_scale1_fx[0][0], &st_fx->offset_scale2_fx[0][0], &st_fx->offset_scale1_p_fx[0][0], &st_fx->offset_scale2_p_fx[0][0], - &st_fx->no_scales_fx[0][0], &st_fx->no_scales_p_fx[0][0], &st_fx->safety_net_fx, NULL, LSF_Q_prediction, NULL ); - - /* convert quantized LSFs to LSPs */ - - lsf2lsp_fx(lsf_new, lsp_new, M ,int_fs); - IF ( L_sub(st_fx->core_brate_fx,SID_2k40) == 0 ) - { - /* return if SID frame (conversion to A(z) done in the calling function) */ - return; - } - - /*-------------------------------------------------------------------------------------* - * FEC - update adaptive LSF mean vector - *-------------------------------------------------------------------------------------*/ - - FOR (i=0; ilsfoldbfi1_fx[i], 10922); /*Q(x2.56+16)*/ - L_tmp = L_mac(L_tmp, st_fx->lsfoldbfi0_fx[i], 10922); /*Q(x2.56+16)*/ - st_fx->lsf_adaptive_mean_fx[i] = round_fx(L_tmp); /*Q(x2.56)*/ - } - - test(); - test(); - IF ( ( st_fx->prev_bfi_fx && (sub(coder_type,TRANSITION) == 0) && (sub(tc_subfr,sub(L_frame,L_SUBFR)) == 0) ) ) - { - lsf_diff = 1205; - move16(); /*int_fs / (float)(2*(M+1)); = 470.588 -> 1205 in Q2.56 */ - if( sub(L_frame,L_FRAME) == 0 ) - { - lsf_diff = 964; - move16(); /*int_fs / (float)(2*(M+1)); = 376.47 -> 964 in Q2.56 */ - } - st_fx->lsf_old_fx[0] = lsf_diff; - move16(); - - FOR ( i=1; ilsf_old_fx[i] = add(st_fx->lsf_old_fx[i-1], lsf_diff); - move16(); - } - lsf2lsp_fx( st_fx->lsf_old_fx, st_fx->lsp_old_fx, M, int_fs ); - } - /*-------------------------------------------------------------------------------------* - * Mid-frame LSF decoding - * LSP interpolation and conversion of LSPs to A(z) - *-------------------------------------------------------------------------------------*/ - if(st_fx->rate_switching_reset) - { - /*extrapolation in case of unstable LSF convert*/ - Copy(lsp_new,st_fx->lsp_old_fx,M); - Copy(lsf_new,st_fx->lsf_old_fx,M); - } - { - /* Mid-frame LSF decoding */ - lsf_mid_dec_fx( st_fx, int_fs, st_fx->lsp_old_fx, lsp_new, coder_type, lsp_mid, st_fx->core_brate_fx, st_fx->ppp_mode_dec_fx, st_fx->nelp_mode_dec_fx - ,st_fx->prev_bfi_fx, &(st_fx->mid_lsf_int_fx), st_fx->safety_net_fx); - } - test(); - test(); - IF ( !( st_fx->prev_bfi_fx && (sub(coder_type,TRANSITION) == 0) && (sub(tc_subfr,sub(L_frame,L_SUBFR)) == 0) ) ) - { - IF ( st_fx->prev_bfi_fx) - { - /* check, if LSP interpolation can be relaxed */ - E_LPC_f_lsp_a_conversion( st_fx->lsp_old_fx, tmp_old, M); - enr_old = Enr_1_Az_fx( tmp_old, 2*L_SUBFR ); - - E_LPC_f_lsp_a_conversion( lsp_new, tmp_new, M); - enr_new = Enr_1_Az_fx( tmp_new, 2*L_SUBFR ); - } - IF ( st_fx->prev_bfi_fx ) - { - IF( sub(enr_new, mult_r(9830/*0.3 Q15*/,enr_old)) < 0 ) - { - /* OLD CODE : if( st->safety_net == 1), replaced with a decision similar to MODE2 */ - st_fx->relax_prev_lsf_interp_fx = -1; - move16(); - test(); - test(); - test(); - test(); - if ( sub(st_fx->clas_dec, UNVOICED_CLAS) == 0 || sub(st_fx->clas_dec, SIN_ONSET) == 0 || sub(st_fx->clas_dec, INACTIVE_CLAS) == 0 || sub(coder_type, GENERIC) == 0 || sub(coder_type, TRANSITION) == 0 ) - { - st_fx->relax_prev_lsf_interp_fx = 1; - move16(); - } - } - } - } - test(); - IF( sub(st_fx->last_core_fx, HQ_CORE)==0 && sub(st_fx->core_fx,ACELP_CORE)==0 ) - { - /* update old LSPs/LSFs in case of HQ->ACELP core switching */ - Copy( lsp_mid, st_fx->lsp_old_fx, M ); - lsp2lsf_fx( lsp_mid, st_fx->lsf_old_fx, M, int_fs ); - } - - /* LSP interpolation and conversion of LSPs to A(z) */ - int_lsp4_fx( L_frame, st_fx->lsp_old_fx, lsp_mid, lsp_new, Aq, M, st_fx->relax_prev_lsf_interp_fx ); - - /*------------------------------------------------------------------* - * Check LSF stability (distance between old LSFs and current LSFs) - *------------------------------------------------------------------*/ - - st_fx->stab_fac_fx = lsf_stab_fx( lsf_new, st_fx->lsf_old_fx, 0, st_fx->L_frame_fx ); /*Q15*/ - - return; -} -/*========================================================================*/ -/* FUNCTION : lsf_end_dec_fx() */ -/*------------------------------------------------------------------------*/ -/* PURPOSE : De-quantize frame end LSF vector */ -/*------------------------------------------------------------------------*/ -/* INPUT ARGUMENTS : */ -/* _ (Word16) coder_type : coding type */ -/* _ (Word16) bwidth : input signal bandwidth */ -/* _ (Word16) nBits : number of bits used for ISF quantization */ -/* _ (Word32*) grid : Table of 100 grid points for evaluating */ -/* Chebyshev polynomials Q31 */ -/* _ (Word16) int_fs : sampling frequency */ -/* _ (Word32) core_brate : Coding Bit Rate */ -/* _ (Word32*) p_offset_scale1 : offsets for LSF LVQ structure 1st */ -/* 8-dim subvector Q0 */ -/* _ (Word32*) p_offset_scale2 : offsets for LSF LVQ structure 2nd */ -/* 8-dim subvector Q0 */ -/* _ (Word32*) p_offset_scale1_p : offsets for LSF LVQ structure, pred .*/ -/* case, 1st 8-dim subvector Q0 */ -/* _ (Word32*) p_offset_scale2_p : offsets for LSF LVQ structure, */ -/* pred. case, 2nd 8-dim subvector Q0 */ -/* _ (Word16*) p_no_scales : LSF LVQ structure Q0 */ -/* _ (Word16*) p_no_scales_p : LSF LVQ structure Q0 */ -/*------------------------------------------------------------------------*/ -/* INPUT/OUTPUT ARGUMENTS : */ -/* _ (Word16*) mem_AR : quantizer memory for AR model Q(x2.56) */ -/*------------------------------------------------------------------------*/ -/* OUTPUT ARGUMENTS : */ -/* _ (Word16*) qlsf : quantized LSFs in the cosine domain Q(x2.56) */ -/*------------------------------------------------------------------------*/ - -/*------------------------------------------------------------------------*/ -/* RETURN ARGUMENTS : */ -/* _ None */ -/*========================================================================*/ - -void lsf_end_dec_fx( - Decoder_State_fx * st, /* i/o: decoder state structure */ - Word16 mode2_flag, - const Word16 coder_type_org, /* i : coding type */ - const Word16 bwidth, /* i : input signal bandwidth */ - const Word16 nBits_in, /* i : number of bits used for ISF quantization*/ - Word16 *qlsf, /* o : quantized LSFs in the cosine domain */ - Word16 *mem_AR, /* i/o: quantizer memory for AR model */ - Word16 *mem_MA, /* i/o: quantizer memory for MA model */ - const Word32 int_fs, /* i : sampling frequency */ - Word32 core_brate, /* i : Coding Bit Rate */ - Word32 *p_offset_scale1, - Word32 *p_offset_scale2, - Word32 *p_offset_scale1_p, - Word32 *p_offset_scale2_p, - Word16 *p_no_scales, - Word16 *p_no_scales_p, - Word16 *safe_net, - Word16 *lpc_param, - Word16 *LSF_Q_prediction, /* o : LSF prediction mode */ - Word16 * nb_indices -) -{ - Word16 pred0[M]; /* Prediction for the safety-net quantizer (usually mean)*/ - Word16 pred1[M], pred2[M]; /* Prediction for the predictive quantizer*/ - Word16 stages0; /* Amount of stages used by safety-net quantizer*/ - Word16 stages1; /* Amount of stages used by predictive quantizer*/ - Word16 levels0[MAX_VQ_STAGES]; /* Sizes of different codebook stages for safety-net quantizer*/ - Word16 levels1[MAX_VQ_STAGES]; /* Sizes of different codebook stages for predictive quantizer*/ - Word16 i; - Word16 TCQIdx[M/2+4]; - Word16 bits0[MAX_VQ_STAGES], bits1[MAX_VQ_STAGES]; - Word16 cumleft; - Word16 lindice[MAX_VQ_STAGES+3]; /* Predictor selector needs 1 bit and the LVQ indice uses 3 shorts */ - Word16 mode_lvq, mode_lvq_p; - Word16 safety_net, predmode, stages, *levels; - const Word16 *Bit_alloc1 = NULL, *bits; - Word16 num_bits; - Word16 * p_lpc_param; - - Word16 nr_ind; - Word16 nBits; - - Word16 coder_type; - Word16 ber_flag; - nBits = nBits_in; - move16(); - - test(); - test(); - IF((sub(coder_type_org, GENERIC) == 0) && (L_sub(int_fs, INT_FS_16k) == 0) && (mode2_flag == 0)) - { - coder_type = (Word16)get_next_indice_fx( st, 1 ); - coder_type = add(coder_type,2); - if (sub(coder_type, GENERIC) == 0) - { - nBits = sub(nBits,1); - } - } - ELSE - { - coder_type = coder_type_org; - move16(); - } - - /*--------------------------------------------------------------------------------* - * LSF de-quantization of SID frames - *--------------------------------------------------------------------------------*/ - - IF ( core_brate == SID_2k40 ) - { - dqlsf_CNG_fx( st, qlsf, p_offset_scale1, p_offset_scale2, p_no_scales ); - sort_fx( qlsf, 0, M-1); - reorder_lsf_fx( qlsf, MODE1_LSF_GAP_FX, M, int_fs ); - - return; - } - - - predmode = find_pred_mode(coder_type, bwidth, int_fs, &mode_lvq, &mode_lvq_p, st->total_brate_fx); - /*----------------------------------------------------------------* - * Calculate number of stages and levels for each stage based on the allowed bit allocation - * (subtract one bit for LSF predictor selection) - *----------------------------------------------------------------*/ - lsf_allocate_fx( sub(nBits,shr(predmode,1)), mode_lvq, mode_lvq_p, &stages0, &stages1, levels0, levels1, - bits0, bits1); - - - /*--------------------------------------------------------------------------* - * Select safety_net or predictive mode - *--------------------------------------------------------------------------*/ - p_lpc_param = lpc_param; - - nr_ind = 0; - move16(); - IF ( predmode == 0 ) - { - safety_net = 1; - move16(); - } - ELSE IF ( predmode == 1 ) - { - safety_net = 0; - move16(); - } - ELSE - { - IF (sub(mode2_flag, 1) == 0) - { - nr_ind = add(nr_ind,1); - /* read from param_lpc */ - safety_net = p_lpc_param[0]; - move16(); - p_lpc_param++; - } - ELSE - { - safety_net = (Word16)get_next_indice_fx( st, 1 ); - } - } - - *safe_net = safety_net; - move16(); - - /*--------------------------------------------------------------------------* - * Read indices from array - *--------------------------------------------------------------------------*/ - - IF ( safety_net ) - { - stages = stages0; - move16(); - levels = levels0; - move16(); - bits = bits0; - move16(); - } - ELSE - { - stages = stages1; - move16(); - levels = levels1; - move16(); - bits = bits1; - move16(); - } - - IF (sub(mode2_flag, 1) == 0) - { - /* VOICED_WB@16kHz */ - test(); - IF ( L_sub(int_fs, INT_FS_16k) == 0 && sub(coder_type, VOICED) == 0 ) - { - *nb_indices = 10; - move16(); - FOR(i=0; i<*nb_indices; i++) - { - TCQIdx[i] = (Word16)lpc_param[i]; - move16(); - } - } - ELSE - { - FOR ( i=0; i 0 ) - { - IF ( sub(cumleft, LEN_INDICE) >0 ) - { - cumleft = sub(cumleft, LEN_INDICE); - num_bits = LEN_INDICE; - move16(); - } - ELSE - { - num_bits = (Word16)cumleft; - move16(); - cumleft = 0; - move16(); - } - - lindice[i+1] = *p_lpc_param++; - move16(); - nr_ind = add(nr_ind,1); - i = add(i,1); - } - *nb_indices = nr_ind; - move16(); - } - } - ELSE - { - /* VOICED_WB@16kHz */ - test(); - IF ( L_sub(int_fs, INT_FS_16k)== 0 && sub(coder_type, VOICED) == 0 ) - { - Bit_alloc1 = &BC_TCVQ_BIT_ALLOC_40B[1]; - TCQIdx[0] = safety_net; - move16(); - FOR ( i=0; i<(M/2)+3; i++ ) - { - TCQIdx[i+1] = (Word16)get_next_indice_fx( st, Bit_alloc1[i] ); - } - } - ELSE - { - FOR ( i=0; i 0 ) - { - IF ( sub(cumleft, LEN_INDICE) > 0 ) - { - cumleft = sub(cumleft, LEN_INDICE); - num_bits = LEN_INDICE; - move16(); - } - ELSE - { - num_bits = (Word16)cumleft; - move16(); - cumleft = 0; - move16(); - } - - lindice[i+1] = (Word16)get_next_indice_fx( st, num_bits ); - i = add(i,1); - } - } - } - - IF(sub(st->reset_mem_AR,1) == 0) - { - FOR( i=0; imem_AR_fx[i] = ModeMeans_fx[mode_lvq][i]; - move16(); - } - st->reset_mem_AR = 0; - } - - /*------------------------------------------------------------------------------------------* - * De-quantize LSF vector - *------------------------------------------------------------------------------------------*/ - - *LSF_Q_prediction = SAFETY_NET; - move16(); - /* VOICED_WB@16kHz */ - test(); - IF ( L_sub(int_fs, INT_FS_16k) == 0 && sub(coder_type, VOICED) == 0 ) - { - /* BC-TCVQ decoder */ - safety_net = qlsf_ARSN_tcvq_Dec_16k_fx ( qlsf, TCQIdx, nBits-1 ); - - /* Update mem_MA */ - Copy( qlsf, mem_MA, M ); - - IF (safety_net) - { - Copy(ModeMeans_fx[mode_lvq], pred0, M); - } - ELSE - { - FOR(i = 0; i < M; i++) - { - pred0[i] = add(ModeMeans_fx[mode_lvq][i], mult(Predictors_fx[mode_lvq_p][i],(sub(mem_AR[i], ModeMeans_fx[mode_lvq][i])))); /* Q(x2.56)*/ - } - *LSF_Q_prediction = AUTO_REGRESSIVE; - move16(); - } - Vr_add( qlsf, pred0, qlsf, M ); - } - ELSE - { - - /* Safety-net */ - Copy( ModeMeans_fx[mode_lvq], pred0, M ); - /* for mem_MA update */ - FOR (i=0; iBER_detect = s_or(st->BER_detect, ber_flag); - Vr_add( qlsf, pred0, qlsf, M ); - Vr_subt( qlsf, pred1, mem_MA, M); - } - ELSE - { - ber_flag = - vq_dec_lvq_fx( 0, qlsf, &lindice[1], stages1, M, mode_lvq_p, levels1[stages1-1], - p_offset_scale1, p_offset_scale2, p_offset_scale1_p, p_offset_scale2_p, - p_no_scales, p_no_scales_p ); - - st->BER_detect = s_or(st->BER_detect, ber_flag); - IF (sub(predmode, 1) == 0) /* MA only */ - { - Copy(qlsf, mem_MA, M); - Vr_add( qlsf, pred1, qlsf, M ); - *LSF_Q_prediction = MOVING_AVERAGE; - move16(); - } - ELSE - { - /* AR */ - FOR ( i=0; imode_lvq = mode_lvq; - move16(); - - - return; -} - - -/*========================================================================*/ -/* FUNCTION : lsf_mid_dec_fx() */ -/*------------------------------------------------------------------------*/ -/* PURPOSE : Decode mid-frame LSFs */ -/*------------------------------------------------------------------------*/ -/* INPUT ARGUMENTS : */ -/* _ (Word16) coder_type : Coder type */ -/* _ (Word16) int_fs : internal (ACELP) sampling frequency */ -/* _ (Word32) core_brate : core bitrate */ -/* _ (Word32) ppp_mode : PPP mode */ -/* _ (Word32) nelp_mode : NELP mode */ -/* _ (Word16[]) qlsp0 : quantized LSPs from frame beginning Q15 */ -/* _ (Word16[]) qlsp1 : quantized LSPs from frame end Q15 */ -/* _ (Word16) prev_bfi, */ -/* _ (Word16 *)mid_lsf_int, */ -/* _ (Word16) safety_net */ -/*------------------------------------------------------------------------*/ -/* INPUT/OUTPUT ARGUMENTS : */ -/*------------------------------------------------------------------------*/ -/* OUTPUT ARGUMENTS : */ -/* _ (Word16[]) qlsp : quantized LSPs Q15 */ -/*------------------------------------------------------------------------*/ - -/*------------------------------------------------------------------------*/ -/* RETURN ARGUMENTS : */ -/* _ None */ -/*========================================================================*/ -void lsf_mid_dec_fx( - Decoder_State_fx *st_fx, /* i/o: decoder state structure */ - const Word16 int_fs, /* i : internal (ACELP) sampling frequency */ - Word16 qlsp0[], /* i : quantized LSPs from frame beginning Q15*/ - Word16 qlsp1[], /* i : quantized LSPs from frame endSQ15*/ - Word16 coder_type, /* i : Coder type */ - Word16 qlsp[], /* o : quantized LSPs Q15*/ - const Word32 core_brate, /* i : core bitrate */ - Word16 ppp_mode, - Word16 nelp_mode, - Word16 prev_bfi, - Word16 *mid_lsf_int, - Word16 safety_net -) -{ - Word16 j, idx; - Word16 nb_bits; - Word16 qlsf0[M], qlsf1[M], qlsf[M]; - Word32 L_tmp; - Word16 bad_spacing; - const Word16 *ratio = NULL; - bad_spacing = 0; - move16(); - - - /* Convert LSPs to LSFs */ - lsp2lsf_fx( qlsp0, qlsf0, M, int_fs); - lsp2lsf_fx( qlsp1, qlsf1, M, int_fs); - - /* Codebook selection */ - IF ( sub(ppp_mode,1) == 0 ) - { - nb_bits = 1; - move16(); - ratio = &tbl_mid_voi_wb_1b_fx[0]; - } - ELSE IF ( sub(nelp_mode,1) == 0 ) - { - nb_bits = 4; - move16(); - ratio = &tbl_mid_unv_wb_4b_fx[0]; - } - ELSE - { - nb_bits = mid_LSF_bits_tbl[LSF_BIT_ALLOC_IDX_fx(core_brate, coder_type)]; - move16(); - - /* codebook selection */ - - IF ( sub(coder_type,VOICED) == 0 ) - { - SWITCH ( nb_bits ) - { - case 5: - { - ratio = tbl_mid_voi_wb_5b_fx; - BREAK; - } - case 4: - { - ratio = tbl_mid_voi_wb_4b_fx; - BREAK; - } - } - } - ELSE IF ( coder_type == UNVOICED ) - { - ratio = tbl_mid_unv_wb_5b_fx; - } - ELSE - { - /* GENERIC, TRANSITION, AUDIO and INACTIVE */ - SWITCH ( nb_bits ) - { - case 5: - { - ratio = tbl_mid_gen_wb_5b_fx; - BREAK; - } - case 2: - { - ratio = tbl_mid_gen_wb_2b_fx; - BREAK; - } - } - } - } - - /* Retrieve mid-frame LSF index */ - idx = (Word16)get_next_indice_fx( st_fx, nb_bits ); - - /* Calculation of mid-LSF vector */ - FOR (j=0; jQ(x2.56+14)*/ - L_tmp = L_mac(L_tmp, ratio[idx*M+j], qlsf1[j]); /*Q(x2.56+14)*/ - qlsf[j] = round_fx(L_shl(L_tmp,2)); /*Q(x2.56)*/ - } - - /* check for incorrect LSF ordering */ - IF ( sub(*mid_lsf_int, 1) == 0 ) - { - FOR (j=1; j 0 && sub(j, M) <0 && sub(qlsf[j], add( qlsf[j-1], LSF_GAP_MID_FX))<0 ) - { - qlsf[j] = add(qlsf[j-1], LSF_GAP_MID_FX); - move16(); - } - } - } - ELSE - { - /* otherwise, use regular LSF spacing and ordering as in the encoder */ - FOR (j=0; j 0 && sub(j, M) < 0 && sub(qlsf[j], add( qlsf[j-1],LSF_GAP_MID_FX))<0 ) - { - qlsf[j] = add(qlsf[j-1], LSF_GAP_MID_FX); - move16(); - } - } - } - - if ( prev_bfi ) - { - /* continue redoing mid-LSF interpolation with 0.4 in order not to propagate the error */ - *mid_lsf_int = 1; - move16(); - } - - if ( safety_net ) - { - /* safety-net encountered -> stop redoing mid-LSF interpolation with 0.4 */ - *mid_lsf_int = 0; - move16(); - } - - reorder_lsf_fx( qlsf, LSF_GAP_MID_FX, M, int_fs ); - - /* convert back to LSPs */ - lsf2lsp_fx( qlsf, qlsp, M, int_fs); - - return; -} diff --git a/src/libs/libevs/lib_dec/lsf_msvq_ma_dec.cpp b/src/libs/libevs/lib_dec/lsf_msvq_ma_dec.cpp old mode 100755 new mode 100644 index e30cb6fb..47923a51 --- a/src/libs/libevs/lib_dec/lsf_msvq_ma_dec.cpp +++ b/src/libs/libevs/lib_dec/lsf_msvq_ma_dec.cpp @@ -1,294 +1,262 @@ /*==================================================================================== - EVS Codec 3GPP TS26.442 Apr 03, 2018. Version 12.11.0 / 13.6.0 / 14.2.0 + EVS Codec 3GPP TS26.443 Nov 13, 2018. Version 12.11.0 / 13.7.0 / 14.3.0 / 15.1.0 ====================================================================================*/ +#include #include #include -#include -#include "stl.h" #include "options.h" -#include "cnst_fx.h" -#include "prot_fx.h" -#include "basop_util.h" -#include "rom_com_fx.h" +#include "cnst.h" +#include "prot.h" +#include "rom_com.h" +#include "basop_proto_func.h" +/*---------------------------------------------------------------------* + * lsf_msvq_ma_decprm() + * + * + *---------------------------------------------------------------------*/ -#define swap(x,y,type) {type u__p; u__p=x; x=y; y=u__p;} - - -Word16 lsf_msvq_ma_decprm( Decoder_State_fx * st, Word16 *param_lpc, Word16 core, Word16 acelp_mode, Word16 acelp_midLpc, - Word16 narrowBand, Word32 sr_core - ) +int lsf_msvq_ma_decprm( + Decoder_State *st, + int *param_lpc, + int core, + int acelp_mode, + int acelp_midLpc, + int narrowBand, + int sr_core +) { - Word16 i, nbits_lpc, tmp; - Word16 bits_midlpc; - Word16 bits0[MAX_VQ_STAGES], bits1[MAX_VQ_STAGES], stages0, stages1, stages, - levels0[MAX_VQ_STAGES], levels1[MAX_VQ_STAGES], * bits; - Word16 predmode, mode_lvq, mode_lvq_p, safety_net; + int i, nbits_lpc; + int bits_midlpc=5; + short bits0[MAX_VQ_STAGES], bits1[MAX_VQ_STAGES], stages0, stages1, stages, + levels0[MAX_VQ_STAGES], levels1[MAX_VQ_STAGES], * bits; + short predmode, mode_lvq, mode_lvq_p, safety_net; - bits_midlpc=5; - move16(); - test(); - IF ((L_sub(sr_core, INT_FS_16k) == 0)&&(sub(acelp_mode, UNVOICED) == 0)) + if( (sr_core==INT_FS_16k)&&(acelp_mode==UNVOICED) ) { - predmode = find_pred_mode(GENERIC, sub(1, narrowBand) /*st->bwidth*/, sr_core, - &mode_lvq, &mode_lvq_p, st->total_brate_fx); - move16(); + predmode = find_pred_mode(GENERIC, 1-narrowBand/*st->bwidth*/, sr_core, + &mode_lvq, &mode_lvq_p, st->total_brate); } - ELSE + else { - IF (sub(core, TCX_20_CORE) == 0) + if (core == TCX_20_CORE) { - predmode = find_pred_mode(AUDIO, sub(1,narrowBand)/*st->bwidth*/, sr_core, - &mode_lvq, &mode_lvq_p, st->total_brate_fx ); - move16(); + predmode = find_pred_mode(AUDIO, 1-narrowBand/*st->bwidth*/, sr_core, + &mode_lvq, &mode_lvq_p, st->total_brate ); } - ELSE + else { - predmode = find_pred_mode(acelp_mode, sub(1, narrowBand)/*st->bwidth*/, sr_core, - &mode_lvq, &mode_lvq_p, st->total_brate_fx ); - move16(); + predmode = find_pred_mode(acelp_mode, 1-narrowBand/*st->bwidth*/, sr_core, + &mode_lvq, &mode_lvq_p, st->total_brate ); } } - lsf_allocate_fx( sub(31, shr(predmode,1)), mode_lvq, mode_lvq_p, &stages0, &stages1, levels0, levels1, - bits0, bits1); + lsf_allocate( 31-(predmode>>1), mode_lvq, mode_lvq_p, &stages0, &stages1, levels0, levels1, bits0, bits1 ); nbits_lpc = 0; - move16(); - IF (sub(predmode, 2) == 0) + if (predmode == 2) { /* there is choice between SN and AR prediction */ - safety_net = get_next_indice_fx(st, 1); + safety_net = get_next_indice(st, 1); - IF (sub(safety_net,1) == 0) + if (safety_net==1) { stages = stages0; - move16(); bits = bits0; - move16(); } - ELSE + else { stages = stages1; - move16(); bits = bits1; - move16(); } *param_lpc = safety_net; - move16(); param_lpc++; nbits_lpc++; } - ELSE + else { stages = stages1; - move16(); bits = bits1; - move16(); } - - tmp = sub(stages,1); - FOR (i=0; inext_bit_pos_fx; - move16(); - FOR (i=0; inext_bit_pos; + + for (i=0; inext_bit_pos_fx, start_bit_pos); + + return st->next_bit_pos - start_bit_pos; } + diff --git a/src/libs/libevs/lib_dec/nelp_dec.cpp b/src/libs/libevs/lib_dec/nelp_dec.cpp new file mode 100644 index 00000000..0038fd50 --- /dev/null +++ b/src/libs/libevs/lib_dec/nelp_dec.cpp @@ -0,0 +1,183 @@ +/*==================================================================================== + EVS Codec 3GPP TS26.443 Nov 13, 2018. Version 12.11.0 / 13.7.0 / 14.3.0 / 15.1.0 + ====================================================================================*/ + +#include +#include +#include "options.h" +#include "cnst.h" +#include "prot.h" +#include "rom_com.h" + +/*-------------------------------------------------------------------* + * nelp_decoder() + * + * NELP decoder + *-------------------------------------------------------------------*/ + +void nelp_decoder( + Decoder_State *st, /* i/o: decoder static memory */ + float *exc_nelp, /* o : adapt. excitation/total exc*/ + float *exc, /* o : adapt. excitation exc */ + short bfi, /* i : frame error rate */ + const short coder_type, /* i : coding type */ + float *gain_buf +) +{ + int i, fid = 0; + float ptr[L_FRAME], filtRes[L_FRAME], gain_fac; + float Gains[10],Gain,E3,E2,R; + float ptr_tmp[L_FRAME]; + int iG1, iG2[2]; + + if ((st->last_nelp_mode_dec == 1) && (st->bwidth != st->last_bwidth)) + { + st->last_nelp_mode_dec = 0; + } + + if ( coder_type == UNVOICED && st->bwidth == NB ) + { + if ( st->last_nelp_mode_dec != 1 ) + { + set_f( st->bp1_filt_mem_nb_dec, 0, 7*2 ); + } + } + else if ( coder_type == UNVOICED && (st->bwidth == WB || st->bwidth == SWB) ) + { + if ( st->last_nelp_mode_dec != 1 ) + { + set_f( st->bp1_filt_mem_wb_dec, 0, 4*2 ); + } + } + + if (st->last_nelp_mode_dec != 1) + { + set_f( st->shape1_filt_mem_dec, 0, 20 ); + set_f( st->shape2_filt_mem_dec, 0, 20 ); + set_f( st->shape3_filt_mem_dec, 0, 20 ); + } + + if (bfi == 0) + { + if(st->rf_frame_type == RF_NELP && st->use_partial_copy) + { + iG1 = st->rf_indx_nelp_iG1; + iG2[0] = st->rf_indx_nelp_iG2[0]; + iG2[1] = st->rf_indx_nelp_iG2[1]; + } + else + { + /* Do Unvoiced/NELP Decoding */ + iG1 = get_next_indice( st, 5 ); + iG2[0] = get_next_indice( st, 6 ); + iG2[1] = get_next_indice( st, 6 ); + } + + if ( coder_type == UNVOICED && (st->bwidth == WB || st->bwidth == SWB) ) + { + if( st->rf_frame_type == RF_NELP && st->use_partial_copy ) + { + fid = st->rf_indx_nelp_fid; + } + else + { + fid = get_next_indice( st, 2 ); + } + } + + dequantize_uvg( iG1, iG2, Gains, st->bwidth ); + } + else + { + for (i=1,Gain=0.001f; i<=L_SUBFR; i++) + { + Gain += SQR(exc[-i]); + } + + Gain = (float) (sqrt(Gain/L_SUBFR)); + Gain *= 0.8f;/* Some scale down of energy since it is an erasure */ + + set_f(Gains, Gain, 10); + } + + if ( coder_type == UNVOICED && (st->bwidth == WB || st->bwidth == SWB) ) + { + gain_fac = 1.16f; + } + else + { + gain_fac = 1.37f; + } + + generate_nelp_excitation( &(st->nelp_dec_seed), Gains, ptr, gain_fac ); + + if ( coder_type == UNVOICED && (st->bwidth == WB || st->bwidth == SWB) ) + { + polezero_filter( ptr, ptr_tmp, L_FRAME, bp1_num_coef_wb, bp1_den_coef_wb, 4, st->bp1_filt_mem_wb_dec ); + mvr2r( ptr_tmp, ptr, L_FRAME ); + } + + if ( coder_type == UNVOICED && st->bwidth == NB ) + { + polezero_filter( ptr, ptr_tmp, L_FRAME, bp1_num_coef_nb_fx_order7, bp1_den_coef_nb_fx_order7, 7, st->bp1_filt_mem_nb_dec ); + mvr2r(ptr_tmp,ptr,L_FRAME); + } + + for( i=0, E3=0.001f; ibwidth == WB || st->bwidth == SWB) ) + { + polezero_filter( ptr, ptr_tmp, L_FRAME, shape1_num_coef, shape1_den_coef, 10, st->shape1_filt_mem_dec ); + mvr2r( ptr_tmp, ptr, L_FRAME ); + + switch(fid) + { + case 1: + /* Update other filter memory */ + polezero_filter( ptr, filtRes, L_FRAME, shape3_num_coef, shape3_den_coef, 10, st->shape3_filt_mem_dec ); + + /* filter the residual to desired shape */ + polezero_filter( ptr, ptr_tmp, L_FRAME, shape2_num_coef, shape2_den_coef, 10, st->shape2_filt_mem_dec ); + mvr2r( ptr_tmp, ptr, L_FRAME ); + + break; + case 2: + /* Update other filter memory */ + polezero_filter( ptr, filtRes, L_FRAME, shape2_num_coef, shape2_den_coef, 10, st->shape2_filt_mem_dec ); + + /* filter the residual to desired shape */ + polezero_filter( ptr, ptr_tmp, L_FRAME, shape3_num_coef, shape3_den_coef, 10, st->shape3_filt_mem_dec ); + + mvr2r( ptr_tmp, ptr, L_FRAME ); + + break; + default: + /* Update other filter memory */ + polezero_filter( ptr, filtRes, L_FRAME, shape2_num_coef, shape2_den_coef, 10, st->shape2_filt_mem_dec ); + + polezero_filter( ptr, filtRes, L_FRAME, shape3_num_coef, shape3_den_coef, 10, st->shape3_filt_mem_dec ); + + break; + } + + for (i=0, E2=0.001f; i -#include "options.h" /* Compilation switches */ -#include "prot_fx.h" /* Function prototypes */ - -#include "rom_com_fx.h" -#include "stl.h" - -/*===================================================================*/ -/* FUNCTION : normalize_arr() */ -/*-------------------------------------------------------------------*/ -/* PURPOSE : Normalize array */ -/* */ -/*-------------------------------------------------------------------*/ -/* GLOBAL INPUT ARGUMENTS : */ -/* _ (Word16*) qf */ -/* _ (Word16*) size */ -/* _ (Word16*) hdr */ -/*-------------------------------------------------------------------*/ -/* OUTPUT ARGUMENTS : */ -/* _ (Word16*) arr : Normalized array */ -/*-------------------------------------------------------------------*/ - -/* _ None */ -/*-------------------------------------------------------------------*/ -/* RETURN ARGUMENTS : */ -/* _ None */ -/*===================================================================*/ -static void normalize_arr(Word16 *arr, Word16 *qf, Word16 size, Word16 hdr) -{ - Word16 i; - Word16 max_s = 0; - - FOR(i = 0; i < size; i++) - { - max_s=s_max(max_s, abs_s(arr[i])); - } - - *qf=norm_s((Word16)max_s); - test(); - IF((*qf == 0)&&(((Word16)max_s)==0)) - { - *qf = 15; - move16(); - } - - *qf = *qf-hdr; - - FOR (i = 0; i < size; i++) - { - arr[i] = shl(arr[i], *qf); - move16(); /* saturation can occur here */ - } - - return; -} - -/*===================================================================*/ -/* FUNCTION : nelp_decoder_fx() */ -/*-------------------------------------------------------------------*/ -/* PURPOSE : NELP decoding for the current frame */ -/* */ -/*-------------------------------------------------------------------*/ -/* GLOBAL INPUT ARGUMENTS : */ -/* _ (Struct) st */ -/* _ (Word16[]) exc_nelp : adapt. excitation/total exc (Q0) */ -/* _ (Word16[]) exc : adapt. excitation exc (Q0) */ -/* _ (Word16) bfi : frame error rate */ -/* _ (Word16) coder_type : coding type */ -/*-------------------------------------------------------------------*/ -/* OUTPUT ARGUMENTS : */ -/* _ (Word16[]) exc_nelp : adapt. excitation/total exc (Q0) */ -/*-------------------------------------------------------------------*/ - -/* _ (Word16[]) shape1_filt_mem_dec : filter memory (Q0) */ -/* _ (Word16[]) shape2_filt_mem_dec : filter memory (Q0) */ -/* _ (Word16[]) shape3_filt_mem_dec : filter memory (Q0) */ -/* _ (Word16[]) bp1_filt_mem_wb_dec : filter memory (Q0) */ -/* _ (Word16[]) bp1_filt_mem_nb_dec : filter memory (Q0) */ -/*-------------------------------------------------------------------*/ -/* RETURN ARGUMENTS : */ -/* _ None */ -/*===================================================================*/ - -void nelp_decoder_fx( Decoder_State_fx *st_fx, Word16 *exc_nelp, Word16 *exc, Word16 *Q_exc, Word16 bfi, const Word16 coder_type - , Word16 *gain_buf - ) -{ - Word16 i, fid = 0; - Word16 ptr[L_FRAME], filtRes[L_FRAME], gain_fac; /*ptr, filtRes - Q0, gain_fac - Q14 */ - Word16 Gains[10]; /* Q0 */ - Word32 Gain, E3, E2; - Word16 BP1_ORDER = 4; - Word16 ptr_tmp[L_FRAME]; /* Q0 */ - Word16 iG1, iG2[2]; - Word16 exp_E2, exp_E3, frac_E2, frac_E3; - Word16 tmp, scale, exp, frac; - Word32 L_tmp, L_tmp1; - Word32 exc_sqr[L_SUBFR]; - Word32 max_exc_sqr; - Word16 n; - Word16 max_val = 0, norm_val = 0; - Word16 qGain=0; - - if (sub(st_fx->last_nelp_mode_dec_fx,1) == 0 && sub(st_fx->bwidth_fx, st_fx->last_bwidth_fx) != 0) - { - st_fx->last_nelp_mode_dec_fx = 0; - } - - test(); - test(); - test(); - IF ( sub(coder_type,UNVOICED) == 0 && sub(st_fx->bwidth_fx,NB) == 0 ) - { - IF (sub(st_fx->last_nelp_mode_dec_fx,1) != 0) - { - BP1_ORDER = 7; - move16(); - - set32_fx(st_fx->bp1_filt_mem_nb_dec_fx, 0, BP1_ORDER*2); - } - } - ELSE IF ( sub(coder_type,UNVOICED) == 0 && (sub(st_fx->bwidth_fx,WB) == 0|| sub(st_fx->bwidth_fx, SWB) == 0)) - { - BP1_ORDER =4; - move16(); - IF (sub(st_fx->last_nelp_mode_dec_fx,1) != 0) - { - set16_fx(st_fx->bp1_filt_mem_wb_dec_fx, 0 , BP1_ORDER*2); - } - } - - IF (sub(st_fx->last_nelp_mode_dec_fx,1) != 0) - { - set16_fx(st_fx->shape1_filt_mem_dec_fx, 0, 10); - set16_fx(st_fx->shape2_filt_mem_dec_fx, 0, 10); - set16_fx(st_fx->shape3_filt_mem_dec_fx, 0, 10); - } - - IF (bfi == 0) - { - test(); - IF(sub(st_fx->rf_frame_type,RF_NELP) == 0 && sub(st_fx->use_partial_copy,1)==0) - { - iG1 = st_fx->rf_indx_nelp_iG1; - iG2[0] = st_fx->rf_indx_nelp_iG2[0]; - iG2[1] = st_fx->rf_indx_nelp_iG2[1]; - } - ELSE - { - /* Do Unvoiced/NELP Decoding */ - iG1 =(Word16) get_next_indice_fx( st_fx, 5 ); - move16(); - iG2[0] =(Word16) get_next_indice_fx( st_fx, 6 ); - move16(); - iG2[1] =(Word16) get_next_indice_fx( st_fx, 6 ); - move16(); - } - - test(); - test(); - IF ( sub(coder_type,UNVOICED) == 0 && (sub(st_fx->bwidth_fx,WB) == 0|| sub(st_fx->bwidth_fx, SWB) == 0)) - { - test(); - IF(sub(st_fx->rf_frame_type,RF_NELP) == 0 && sub(st_fx->use_partial_copy,1)==0) - { - fid = st_fx->rf_indx_nelp_fid; - } - ELSE - { - fid = (Word16)get_next_indice_fx( st_fx, 2 ); - move16(); - } - } - - *Q_exc = dequantize_uvg_fx(iG1, iG2, Gains, st_fx->bwidth_fx ,1 ); - move16();/* Gains - Q0/Q3 */ - } - ELSE - { - FOR (i=1; i<=L_SUBFR; i++) - { - exc_sqr[i-1] = L_mult0(exc[-i],exc[-i]); - move32();/*2*Q_exc */ - } - max_exc_sqr = L_deposit_l(0); - FOR (i=0; ibwidth_fx,WB) == 0|| sub(st_fx->bwidth_fx, SWB) == 0)) - { - gain_fac = 19005; - move16(); /* 1.16f - Q14 */ - } - - IF (sub(st_fx->bwidth_fx,WB) == 0|| sub(st_fx->bwidth_fx, SWB) == 0) - { - /* Normalize Gains[10] with headroom 4, qGain is the new Q value os Gains, not Q0*/ - /* This is done to avoid internal overflow observed in the wb bp filter below, similar to encoder */ - normalize_arr(Gains, &qGain, 10, 4); - } - - generate_nelp_excitation_fx(&(st_fx->nelp_dec_seed_fx), Gains, ptr, gain_fac); - /* o: ptr = nelp_exc in Q=qGain, qGain = 0 always for NB */ - - test(); - test(); - IF ( sub(coder_type,UNVOICED ) == 0&& (sub(st_fx->bwidth_fx,WB) == 0|| sub(st_fx->bwidth_fx, SWB) == 0) ) - { - BP1_ORDER =4; - move16(); - Scale_sig(st_fx->bp1_filt_mem_wb_dec_fx, 2*BP1_ORDER, qGain); /* bring filter prev memory from Q0 to qGain */ - pz_filter_sp_fx(bp1_num_coef_wb_fx, bp1_den_coef_wb_fx, ptr, ptr_tmp, st_fx->bp1_filt_mem_wb_dec_fx, - BP1_ORDER, BP1_ORDER, L_FRAME, (sub(16,BP1_COEF_WB_QF))); - - Scale_sig(st_fx->bp1_filt_mem_wb_dec_fx, 2*BP1_ORDER, -qGain); /* bring filter prev memory from qGain to Q0 */ - Scale_sig(ptr_tmp, L_FRAME, -qGain); /* bring nelp_exc to Q0 */ - Copy(ptr_tmp,ptr,L_FRAME); - } - - test(); - IF ( sub(coder_type,UNVOICED ) == 0&& (sub(st_fx->bwidth_fx,NB) == 0) ) - { - BP1_ORDER = 7; - move16(); - - FOR (i=0; i < L_FRAME; i++ ) - { - max_val = s_max( ptr[i], max_val ); - } - tmp = shl(BP1_ORDER,1); - FOR (i=0; i < tmp; i++ ) - { - max_val = s_max( round_fx( L_shr( st_fx->bp1_filt_mem_nb_dec_fx[i], 16)), max_val ); - } - norm_val = norm_s(max_val); - - norm_val = s_max (0, sub(norm_val, 4)); /* 4 bit head room */ - - norm_val = s_min ( norm_val,8); /* scale only for very low level signals */ - - IF ( norm_val > 0 ) - { - Scale_sig32(st_fx->bp1_filt_mem_nb_dec_fx, shl(BP1_ORDER,1), norm_val) ; - Scale_sig(ptr, L_FRAME, norm_val); - *Q_exc = add( norm_val, *Q_exc ); - } - - BP1_ORDER = 7; - move16(); - pz_filter_dp_fx(bp1_num_coef_nb_fx_order7, bp1_den_coef_nb_fx_order7, ptr, ptr_tmp, st_fx->bp1_filt_mem_nb_dec_fx, - BP1_ORDER, BP1_ORDER, L_FRAME, (sub(16,BP1_COEF_NB_QF_ORDER7))); - - - IF ( norm_val > 0 ) - { - Scale_sig32(st_fx->bp1_filt_mem_nb_dec_fx, shl(BP1_ORDER,1), -norm_val) ; - - } - - Copy(ptr_tmp,ptr,L_FRAME); /*Q_exc */ - } - - E3 = L_deposit_l(1); - FOR (i=0 ; ibwidth_fx,WB) == 0|| sub(st_fx->bwidth_fx, SWB) == 0) ) - { - pz_filter_sp_fx(shape1_num_coef_fx, shape1_den_coef_fx, ptr, ptr_tmp, st_fx->shape1_filt_mem_dec_fx, - 10, 10, L_FRAME, (sub(16,SHAPE1_COEF_QF))); - Copy(ptr_tmp,ptr,L_FRAME); /*Q_exc */ - - SWITCH(fid) - { - case 1: - /* Update other filter memory */ - pz_filter_sp_fx(shape3_num_coef_fx, shape3_den_coef_fx, ptr, filtRes, st_fx->shape3_filt_mem_dec_fx, - 10, 10, L_FRAME, (sub(16,SHAPE3_COEF_QF))); - - /* filter the residual to desired shape */ - pz_filter_sp_fx(shape2_num_coef_fx, shape2_den_coef_fx, ptr, ptr_tmp, st_fx->shape2_filt_mem_dec_fx, - 10, 10, L_FRAME, (sub(16,SHAPE2_COEF_QF))); - - Copy(ptr_tmp,ptr,L_FRAME); /*Q_exc */ - - BREAK; - case 2: - /* Update other filter memory */ - pz_filter_sp_fx(shape2_num_coef_fx, shape2_den_coef_fx, ptr, filtRes, st_fx->shape2_filt_mem_dec_fx, - 10, 10, L_FRAME, (sub(16,SHAPE2_COEF_QF))); - - /* filter the residual to desired shape */ - pz_filter_sp_fx(shape3_num_coef_fx, shape3_den_coef_fx, ptr, ptr_tmp, st_fx->shape3_filt_mem_dec_fx, - 10, 10, L_FRAME, (sub(16,SHAPE3_COEF_QF))); - - Copy(ptr_tmp,ptr,L_FRAME); /*Q_exc */ - - BREAK; - default: - /* Update other filter memory */ - pz_filter_sp_fx(shape2_num_coef_fx, shape2_den_coef_fx, ptr, filtRes, st_fx->shape2_filt_mem_dec_fx, - 10, 10, L_FRAME, (sub(16,SHAPE2_COEF_QF))); - pz_filter_sp_fx(shape3_num_coef_fx, shape3_den_coef_fx, ptr, filtRes, st_fx->shape3_filt_mem_dec_fx, - 10, 10, L_FRAME, (sub(16,SHAPE3_COEF_QF))); - - BREAK; - } - - E2 = L_deposit_l(1); - FOR (i=0 ; i +#include "options.h" +#include "cnst.h" +#include "prot.h" +#include "rom_com.h" + +/*------------------------------------------------------------------------* + * Local functions + *------------------------------------------------------------------------*/ + +static void dequant_peaks( Decoder_State *st, float *vect_out, const float *peak_gain ); + +static short hvq_dec_pos( Decoder_State *st, short *pos_vec, const short length, const short num_peaks ); +static short sparse_dec_pos(Decoder_State *st, short *out, const short length ); + +/*-------------------------------------------------------------------------- + * hvq_dec() + * + * HVQ decoder + *--------------------------------------------------------------------------*/ + +void hvq_dec( + Decoder_State *st, /* i/o: decoder state structure */ + const short num_bits, /* i : Number of available bits */ + const long core_brate, /* i : Core bit-rate */ + const short *ynrm, /* i : Envelope coefficients */ + short *R, /* i/o: Bit allocation/updated bit allocation */ + float *noise_level, /* o : Noise level */ + short *peak_idx, /* o : Peak position vector */ + short *Npeaks, /* o : Total number of peaks */ + float *coefsq_norm, /* o : Output vector */ + const short core +) +{ + short i; + short bits; + short noise_level_idx; + + bits = num_bits; + + for( i = 0; i < HVQ_BWE_NOISE_BANDS; i++ ) + { + noise_level_idx = (short) get_next_indice( st, 2 ); + noise_level[i] = usdequant( noise_level_idx, 0.0f, 0.1f ); + + bits -= 2; + } + + peak_vq_dec( st, coefsq_norm, (short)core_brate, bits, ynrm, R, peak_idx, + Npeaks, core ); +} + +/*-------------------------------------------------------------------------- + * peak_vq_dec() + * + * Vector de-quantization of MDCT peaks + *--------------------------------------------------------------------------*/ + +void peak_vq_dec( + Decoder_State *st, /* i/o: decoder state structure */ + float *coefs_out, /* o : Output coefficient vector */ + const short brate, /* i : Core bitrate */ + const short num_bits, /* i : Number of bits for HVQ */ + const short *ynrm, /* i : Envelope coefficients */ + short *R, /* i/o: Bit allocation/updated bit allocation */ + short *vq_peak_idx, /* o : Peak position vector */ + short *Npeaks, /* o : Number of peaks */ + const short core /* i : Core type */ +) +{ + short vq_peaks, i, j, k, FlagN, hcode_l, diff; + short bin_th, max_peaks, pvq_bands; + short nf_seed = RANDOM_INITSEED; + short nf_gains_idx[HVQ_NF_GROUPS], pgain_difidx[HVQ_MAX_PEAKS_32k], pvq_norm[MAX_PVQ_BANDS]; + short gain_bits_array[MAX_PVQ_BANDS]; + short pos_bits; + float nf_gains[HVQ_NF_GROUPS], peak_gains[HVQ_MAX_PEAKS_32k]; + int manE_peak, manPkEnrg; /* (man, exp) representation ported from BASOP for interoperability */ + short expE_peak, expPkEnrg; + float pvq_vector[HVQ_PVQ_BUF_LEN]; + short res_vec[HVQ_THRES_BIN_32k]; + short k_sort[HVQ_MAX_PVQ_WORDS]; + short pvq_inp_vector[HVQ_PVQ_BUF_LEN]; + short npulses[MAX_PVQ_BANDS]; + short pvq_bits, Rk[MAX_PVQ_BANDS]; + float fg_pred[NB_SFM_MAX]; + short Rk_f[MAX_PVQ_BANDS]; /* Q3 */ + short sel_bnds[HVQ_NUM_SFM_24k]; + short n_sel_bnds; + short hvq_band_end[MAX_PVQ_BANDS]; + short hvq_band_start[MAX_PVQ_BANDS]; + short hvq_band_width[MAX_PVQ_BANDS]; + short n; + short s; + float normq; + + set_s( gain_bits_array, 0, MAX_PVQ_BANDS ); + set_f( pvq_vector, 0.0f, HVQ_PVQ_BUF_LEN ); + set_s( npulses, 0, MAX_PVQ_BANDS ); + set_s( pvq_inp_vector, 0, HVQ_PVQ_BUF_LEN ); + + /* Set bitrate dependent variables */ + if (brate == HQ_24k40) + { + max_peaks = HVQ_MAX_PEAKS_24k; + bin_th = HVQ_THRES_BIN_24k; + } + else + { + max_peaks = HVQ_MAX_PEAKS_32k; + bin_th = HVQ_THRES_BIN_32k; + } + + /* Get number of peaks */ + vq_peaks = (short) get_next_indice( st, 5 ); + vq_peaks = max_peaks - vq_peaks; + *Npeaks = vq_peaks; + diff = 5; + + /* safety check in case of bit errors */ + if( *Npeaks < HVQ_MIN_PEAKS ) + { + st->BER_detect = 1; + vq_peaks = HVQ_MIN_PEAKS; + *Npeaks = HVQ_MIN_PEAKS; + } + + /* De-quantize peak positions */ + for (i = 0; i < bin_th; i++) + { + res_vec[i] = 0; + } + + /* Unpack HVQ codewords */ + pos_bits = hvq_dec_pos(st, res_vec, bin_th, vq_peaks); + diff += pos_bits; + + for (i = 0, j = 0; i < bin_th && j < vq_peaks; i++) /* safety check in case of bit errors */ + { + if (res_vec[i]) + { + vq_peak_idx[j++] = i; + } + } + + /* safety check in case of bit errors */ + if( j < vq_peaks ) + { + st->BER_detect = 1; + vq_peaks = j - 1; + *Npeaks = j - 1; + } + + /* Huffman or differential coding */ + FlagN = (short) get_next_indice( st, 1 ); + + /* De-quantize peak gains */ + pgain_difidx[0] = (short) get_next_indice( st, GAIN0_BITS ); + + /* safety check in case of bit errors */ + if( pgain_difidx[0] > 44 ) + { + st->BER_detect = 1; + pgain_difidx[0] = 44; + } + peak_gains[0] = dicn_pg[pgain_difidx[0]]*sign((float) res_vec[vq_peak_idx[0]]); + + hcode_l = 0; + if(FlagN) + { + huff_dec( st, vq_peaks-1, MAX_PG_HUFFLEN, NUM_PG_HUFFLEN, hvq_pg_huff_thres, hvq_pg_huff_offset, hvq_pg_huff_tab, &pgain_difidx[1] ); + for (i = 1; i < vq_peaks; i++) + { + hcode_l += pgain_huffsizn[pgain_difidx[i]]; + } + } + else + { + for (i = 1; i < vq_peaks; i++) + { + pgain_difidx[i] = (short) get_next_indice( st, GAINI_BITS ); + hcode_l += GAINI_BITS; + } + } + + for (i = 1; i < vq_peaks; i++) + { + pgain_difidx[i] += pgain_difidx[i - 1] - 15; + + /* safety check in case of bit errors */ + if( pgain_difidx[i] > 44 || pgain_difidx[i] < 0) + { + st->BER_detect = 1; + pgain_difidx[i] = 44; + } + + peak_gains[i] = dicn_pg[pgain_difidx[i]]*sign((float) res_vec[vq_peak_idx[i]]); + } + + /* Scale up peak gains and accumulate peak energy */ + /* Simulating BASOP code for interoperability */ + manE_peak = 0; + expE_peak = 32; + for (i = 0; i < vq_peaks; i++) + { + peak_gains[i] *= 4.0f; + manPkEnrg = manPkEnrg_tbl[pgain_difidx[i]]; + expPkEnrg = expPkEnrg_tbl[pgain_difidx[i]]; + floating_point_add(&manE_peak, &expE_peak, manPkEnrg, expPkEnrg); + } + + /* Number of bits used for peak gain quantization */ + diff += FLAGN_BITS + GAIN0_BITS + hcode_l; + + /* De-quantize peaks */ + for (i = 0; i < vq_peaks; i++) + { + dequant_peaks( st, &coefs_out[vq_peak_idx[i]-2], &peak_gains[i] ); + + diff += 9; + } + + for (i = 0; i < HVQ_NF_GROUPS; i++) + { + nf_gains_idx[i] = (short) get_next_indice( st, 5 ); + nf_gains[i] = 0.5f*dicn[nf_gains_idx[i]]; + diff += 5; + } + + pvq_bits = num_bits - diff; + + /* Calculate number of PVQ bands to code and assign bits */ + pvq_bands = hvq_pvq_bitalloc(pvq_bits, brate, st->bwidth, ynrm, manE_peak, expE_peak, Rk, R, sel_bnds, &n_sel_bnds ); + + /* safety check in case of bit errors */ + if (pvq_bands == 0) + { + st->BER_detect = 1; + } + + pvq_bits -= HVQ_PVQ_GAIN_BITS*pvq_bands; + + /* Get band limits for concatenated PVQ target */ + hvq_concat_bands( pvq_bands, sel_bnds, n_sel_bnds, hvq_band_start, hvq_band_width, hvq_band_end ); + + s = 0; + for (k = 0; k < pvq_bands; k++) + { + k_sort[k] = k; + Rk_f[k] = Rk[k] * 8; + } + + pvq_decode_frame( st, pvq_vector, npulses, pvq_inp_vector, hvq_band_start, + hvq_band_end, hvq_band_width, pvq_bands, Rk_f, pvq_bits, core ); + + fine_gain_pred( hvq_band_start, hvq_band_end, hvq_band_width, k_sort, npulses, NULL, NULL, + pvq_bands, pvq_vector, pvq_inp_vector, fg_pred, core ); + + fine_gain_dec( st, k_sort, pvq_bands, gain_bits_array, fg_pred ); + + apply_gain(k_sort, hvq_band_start, hvq_band_end, pvq_bands, fg_pred, pvq_vector ); + + i = 0; + n = 0; + s = 0; + for (k = 0; k < pvq_bands; k++) + { + pvq_norm[k] = (short) get_next_indice( st, HVQ_PVQ_GAIN_BITS ); + pvq_norm[k] += 8; + + diff += HVQ_PVQ_GAIN_BITS; + + j = 0; + if( k >= pvq_bands - n_sel_bnds) + { + i = band_start_harm[sel_bnds[s++]]; + } + while (j < hvq_band_width[k]) + { + normq = dicn[pvq_norm[k]]; + if (coefs_out[i] == 0) + { + coefs_out[i] = pvq_vector[n] * normq; + j++; + n++; + } + i++; + } + } + /* Noise fill unqantized coeffs with one gain per group */ + for (i = 0; i < HVQ_NF_GROUPS; i++) + { + for (j = i*(bin_th/HVQ_NF_GROUPS); j < (i+1)*(bin_th/HVQ_NF_GROUPS); j++) + { + if (coefs_out[j] == 0) + { + coefs_out[j] = ((float)own_random(&nf_seed)/MAX16B)*nf_gains[i]; + } + } + } + + return; +} + +/*-------------------------------------------------------------------------- + * dequant_peaks() + * + * Reads codebook vector and scales peak + *--------------------------------------------------------------------------*/ + +static void dequant_peaks( + Decoder_State *st, /* i/o: decoder state structure */ + float *vect_out, /* o : Quantized vector */ + const float *peak_gain /* i : Peak gain */ +) +{ + float xq[4]; + const float *tmp; + short i, hvq_cb_rev; + short cb_idx; + + hvq_cb_rev = (short) get_next_indice( st, 1 ); + cb_idx = (short) get_next_indice( st, 8 ); + + if( hvq_cb_rev ) + { + tmp = &hvq_peak_cb[cb_idx*4+3]; + for (i = 0; i < 4; i++) + { + xq[i] = tmp[-i]; + } + } + else + { + mvr2r(&hvq_peak_cb[cb_idx*4], xq, 4); + } + if(vect_out[0] == 0) + { + vect_out[0] = xq[0] **peak_gain; + vect_out[1] = xq[1] **peak_gain; + } + else + { + if( fabs(peak_gain[-1]) <= fabs(*peak_gain) ) + { + vect_out[0] = xq[0] **peak_gain; + vect_out[1] = xq[1] **peak_gain; + } + else + { + if(vect_out[1] == 0 || fabs(peak_gain[-1]) <= fabs(*peak_gain)) + { + vect_out[1] = xq[1] **peak_gain; + } + } + } + vect_out[2] = *peak_gain; + vect_out[3] = xq[2] **peak_gain; + vect_out[4] = xq[3] **peak_gain; + + return; +} + +/*-------------------------------------------------------------------------- + * hvq_dec_pos() + * + * HVQ decode peak positions + *--------------------------------------------------------------------------*/ + +static short hvq_dec_pos( + Decoder_State *st, /* i/o: decoder state structure */ + short *pos_vec, + const short length, + const short num_peaks +) +{ + short peak_idx[HVQ_MAX_PEAKS_32k]; + short delta[HVQ_MAX_PEAKS_32k]; + short sign_vec[HVQ_MAX_PEAKS_32k]; + + short mode; + short num_bits; + short i, j; + + num_bits = 0; + set_s(pos_vec, 0, length); + + mode = (short)get_next_indice(st, 1); + num_bits += 1; + + if (mode == HVQ_CP_DELTA) + { + huff_dec(st, num_peaks, HVQ_CP_HUFF_MAX_CODE, HVQ_CP_HUFF_NUM_LEN, hvq_cp_huff_thres, hvq_cp_huff_offset, hvq_cp_huff_tab, delta); + + for (i = 0; i < num_peaks; i++) + { + num_bits += hvq_cp_huff_len[delta[i]]; + } + + peak_idx[0] = delta[0] - HVQ_CP_HUFF_OFFSET; + /* safety check in case of bit errors */ + if (peak_idx[0] < 2) + { + peak_idx[0] = 2; + st->BER_detect = 1; + } + for (i = 1; i < num_peaks; i++) + { + peak_idx[i] = delta[i] + peak_idx[i-1] + HVQ_CP_HUFF_OFFSET; + /* safety check in case of bit errors */ + if (peak_idx[i] >= HVQ_THRES_BIN_32k) + { + peak_idx[i] = HVQ_THRES_BIN_32k - 1; + st->BER_detect = 1; + } + } + + for (i = 0; i < num_peaks; i++) + { + pos_vec[peak_idx[i]] = 1; + } + } + else + { + num_bits += sparse_dec_pos(st, pos_vec, length); + } + + for (i = 0; i < num_peaks; i++) + { + sign_vec[i] = (get_next_indice_1(st) == 0) ? -1 : 1; + } + num_bits += num_peaks; + + for (i = 0, j = 0; i < length && j < num_peaks; i++) /* safety check in case of bit errors */ + { + if (pos_vec[i]) + { + pos_vec[i] *= sign_vec[j++]; + } + } + + return num_bits; +} + +/*-------------------------------------------------------------------------- + * sparse_dec_pos() + * + * Sparse decode positions + *--------------------------------------------------------------------------*/ + +static short sparse_dec_pos( + Decoder_State *st, /* i/o: decoder state structure */ + short *out, + const short length +) +{ + short layer2[HVQ_CP_L2_MAX]; + short layer_length; + short i, j; + short bits; + short idx, val; + + set_s(layer2, 0, HVQ_CP_L2_MAX); + set_s(out, 0, length); + bits = 0; + + layer_length = (short)((float)length/HVQ_CP_L1_LEN + 0.5); + + for (i = 0; i < layer_length; i++) + { + layer2[i] = (short)get_next_indice_1(st); + } + bits += layer_length; + + for (j = 0; j < layer_length; j++) + { + if (layer2[j]) + { + idx = (short)get_next_indice(st, HVQ_CP_MAP_IDX_LEN); + bits += HVQ_CP_MAP_IDX_LEN; + + val = hvq_cp_layer1_map5[idx]; + + /* safety check in case of bit errors */ + if ( j == 0 && val > 4 ) /* out[0] and out[1] are invalid positions */ + { + st->BER_detect = 1; + val = 4; + } + for (i = min((j+1)*HVQ_CP_L1_LEN, length)-1; i >= j*HVQ_CP_L1_LEN; i--) + { + out[i] = val&1; + val >>= 1; + } + } + } + + return bits; +} diff --git a/src/libs/libevs/lib_dec/peak_vq_dec_fx.cpp b/src/libs/libevs/lib_dec/peak_vq_dec_fx.cpp deleted file mode 100755 index 8a4cf735..00000000 --- a/src/libs/libevs/lib_dec/peak_vq_dec_fx.cpp +++ /dev/null @@ -1,609 +0,0 @@ -/*==================================================================================== - EVS Codec 3GPP TS26.442 Apr 03, 2018. Version 12.11.0 / 13.6.0 / 14.2.0 - ====================================================================================*/ - -#include "options.h" /* Compilation switches */ -#include "prot_fx.h" -#include "rom_com_fx.h" -#include "stl.h" /* required for wmc_tool */ - - -#define PK_VQ_NOISE_DELTA ((Word16)3277) /* 0.1 in Q15 */ - -/* Local functions */ -static void dequant_peaks_fx( Decoder_State_fx *st_fx, Word32 *vect_out, const Word32 *peak_gain); -static Word16 hvq_dec_pos_fx(Decoder_State_fx *st_fx, Word16 *pos_vec, const Word16 length, const Word16 num_peaks ); -static Word16 sparse_dec_pos_fx(Decoder_State_fx *st_fx, Word16 *out, const Word16 length ); - -/*-------------------------------------------------------------------------- - * hvq_dec_fx() - * - * HVQ decoder - *--------------------------------------------------------------------------*/ - -void hvq_dec_fx( - Decoder_State_fx *st_fx, /* i/o: decoder state structure */ - const Word16 num_bits, /* i : Number of available bits */ - const Word32 core_brate, /* i : Core bit-rate */ - const Word16 *ynrm, /* i : Envelope coefficients */ - Word16 *R, /* i/o: Bit allocation/updated bit allocation */ - Word16 *noise_level, /* o : Noise level in Q15 */ - Word16 *peak_idx, /* o : Peak position vector */ - Word16 *Npeaks, /* o : Total number of peaks */ - Word32 *coefsq_norm, /* o : Output vector in Q12 */ - const Word16 core -) -{ - Word16 i; - Word16 bits; - Word16 noise_level_idx; - - bits = num_bits; - - FOR( i = 0; i < HVQ_BWE_NOISE_BANDS; i++ ) - { - noise_level_idx = get_next_indice_fx( st_fx, 2 ); /* 2-bits => max noise_level-idx = 3 */ - noise_level[i] = i_mult(noise_level_idx, PK_VQ_NOISE_DELTA); - move16();/* max noise_level=3*0.1 => Q15 is good enough */ - - bits = sub(bits, 2); - } - - peak_vq_dec_fx( st_fx, coefsq_norm, (Word16)core_brate, bits, ynrm, R, peak_idx, - Npeaks, core ); -} - -/*-------------------------------------------------------------------------- - * peak_vq_dec() - * - * Vector de-quantization of MDCT peaks - *--------------------------------------------------------------------------*/ - -void peak_vq_dec_fx( - Decoder_State_fx *st_fx, /* i/o: decoder state structure */ - Word32 *coefs_out, /* o : Output coefficient vector Q12 */ - const Word16 brate, /* i : Core bitrate */ - const Word16 num_bits, /* i : Number of bits for HVQ */ - const Word16 *ynrm, /* i : Envelope coefficients */ - Word16 *R, /* i/o: Bit allocation/updated bit allocation */ - Word16 *vq_peak_idx, /* o : Peak position vector */ - Word16 *Npeaks, /* o : Number of peaks */ - const Word16 core -) -{ - Word16 vq_peaks, i, j, k, FlagN, hcode_l, diff; - Word16 bin_th, bin_th2, max_peaks, pvq_bands; - Word16 nf_gains_idx[HVQ_NF_GROUPS], pgain_difidx[HVQ_MAX_PEAKS_32k], pvq_norm[MAX_PVQ_BANDS]; - Word16 gain_bits_array[MAX_PVQ_BANDS]; - Word16 pos_bits; - Word32 nf_gains_fx[HVQ_NF_GROUPS], peak_gains_fx[HVQ_MAX_PEAKS_32k]; - Word16 pvq_vector[HVQ_PVQ_BUF_LEN]; - Word16 res_vec[HVQ_THRES_BIN_32k]; - Word16 k_sort[HVQ_MAX_PVQ_WORDS]; - Word16 pvq_inp_vector[HVQ_PVQ_BUF_LEN], pvq_maxpulse[HVQ_MAX_PVQ_WORDS]; - Word16 npulses[MAX_PVQ_BANDS]; - Word16 pvq_bits, Rk[MAX_PVQ_BANDS]; - Word16 fg_pred[NB_SFM_MAX]; - - Word32 *pCoefsOut; - Word16 whiteNoise; - UWord16 dontCare; - Word32 acc; - Word16 *pPvqVector; - Word32 manE_peak, manPeakGains, manPkEnrg; /* Due to very wide dynamic range, use floating point format, i.e., (man, exp) */ - Word16 expE_peak, expPeakGains, expPkEnrg; - Word16 *pSelBnds; - Word16 sel_bnds[HVQ_NUM_SFM_24k]; - Word16 hvq_band_end[MAX_PVQ_BANDS]; - Word16 hvq_band_start[MAX_PVQ_BANDS]; - Word16 hvq_band_width[MAX_PVQ_BANDS]; - Word16 n_sel_bnds; - Word32 normq; - UWord32 lsb; - Word32 tmp; - Word16 nf_seed = RANDOM_INITSEED; - move16(); - - set16_fx( gain_bits_array, 0, MAX_PVQ_BANDS ); - set16_fx( pvq_vector, 0, HVQ_PVQ_BUF_LEN ); - set16_fx( npulses, 0, MAX_PVQ_BANDS ); - set16_fx( pvq_inp_vector, 0, HVQ_PVQ_BUF_LEN ); - - /* Set bitrate dependent variables */ - IF (sub(brate, HQ_24k40) == 0) - { - max_peaks = HVQ_MAX_PEAKS_24k; - move16(); - bin_th = HVQ_THRES_BIN_24k; - move16(); - bin_th2 = HVQ_THRES_BIN_24k/HVQ_NF_GROUPS; - move16(); - } - ELSE - { - max_peaks = HVQ_MAX_PEAKS_32k; - move16(); - bin_th = HVQ_THRES_BIN_32k; - move16(); - bin_th2 = HVQ_THRES_BIN_32k/HVQ_NF_GROUPS; - move16(); - } - - /* Get number of peaks */ - vq_peaks = get_next_indice_fx( st_fx, 5 ); - vq_peaks = sub(max_peaks, vq_peaks); - *Npeaks = vq_peaks; - move16(); - diff = 5; - move16(); - - /* safety check in case of bit errors */ - IF( sub(*Npeaks, HVQ_MIN_PEAKS) < 0 ) - { - st_fx->BER_detect = 1; - move16(); - vq_peaks = HVQ_MIN_PEAKS; - move16(); - *Npeaks = HVQ_MIN_PEAKS; - move16(); - } - - /* De-quantize peak positions */ - FOR (i = 0; i < bin_th; i++) - { - res_vec[i] = 0; - move16(); - } - - /* Unpack PVQ codewords */ - pos_bits = hvq_dec_pos_fx(st_fx, res_vec, bin_th, vq_peaks); - diff = add(diff, pos_bits); - - j = 0; - move16(); - test(); - FOR (i = 0; i < bin_th && j < vq_peaks; i++) /* safety check in case of bit errors */ - { - IF ( res_vec[i] != 0) - { - vq_peak_idx[j++] = i; - move16(); - } - } - - /* safety check in case of bit errors */ - IF( sub(j, vq_peaks) < 0 ) - { - st_fx->BER_detect = 1; - move16(); - vq_peaks = sub(j, 1); - *Npeaks = sub(j, 1); - } - - /* Huffman or differential coding */ - FlagN = (Word16) get_next_indice_fx( st_fx, 1 ); - - /* De-quantize peak gains */ - pgain_difidx[0] = get_next_indice_fx( st_fx, GAIN0_BITS ); - - /* safety check in case of bit errors */ - IF( sub(pgain_difidx[0], 44) > 0 ) - { - st_fx->BER_detect = 1; - move16(); - pgain_difidx[0] = 44; - move16(); - } - peak_gains_fx[0] = dicn_pg_fx[pgain_difidx[0]]; /* Q12 */ move32(); - if (res_vec[vq_peak_idx[0]] < 0) - { - peak_gains_fx[0] = L_negate(peak_gains_fx[0]); - move16(); - } - - hcode_l = 0; - move16(); - IF (FlagN) - { - huff_dec_fx( st_fx, vq_peaks-1, MAX_PG_HUFFLEN, NUM_PG_HUFFLEN, hvq_pg_huff_thres, hvq_pg_huff_offset, hvq_pg_huff_tab, &pgain_difidx[1] ); - - FOR (i = 1; i < vq_peaks; i++) - { - hcode_l = add(hcode_l, pgain_huffsizn[pgain_difidx[i]]); - move16();/* indirect addressing*/ - } - } - ELSE - { - FOR (i = 1; i < vq_peaks; i++) - { - pgain_difidx[i] = get_next_indice_fx(st_fx, GAINI_BITS ); - move16(); - hcode_l = add(hcode_l, GAINI_BITS); - } - } - - FOR (i = 1; i < vq_peaks; i++) - { - pgain_difidx[i] = add(pgain_difidx[i], sub(pgain_difidx[i - 1],15)); - move16(); - - /* safety check in case of bit errors */ - test(); - IF( sub(pgain_difidx[i], 44) > 0 || pgain_difidx[i] < 0) - { - st_fx->BER_detect = 1; - move16(); - pgain_difidx[i] = 44; - move16(); - } - - peak_gains_fx[i] = dicn_pg_fx[pgain_difidx[i]]; - move32();/* Q12 move16(); */ - if (res_vec[vq_peak_idx[i]] < 0) - { - peak_gains_fx[i] = L_negate(peak_gains_fx[i]); - move32(); - } - } - - /* Scale up peak gains and accumulate peak energy */ - manE_peak = L_deposit_l(0); - expE_peak = 32; - move16(); - FOR (i = 0; i < vq_peaks; i++) - { - peak_gains_fx[i] = L_shl(peak_gains_fx[i], 2); - move32(); /* Q12 */ - /* Use floating point operation to deal with wide dynamic range. - * 32-bit mantissa is used here. It should be even more accurate than - * the floating-point reference code with 24-bit mantissa! */ - tmp = L_shl(dicn_pg_fx[pgain_difidx[i]], 2); - expPeakGains = norm_l(tmp); - manPeakGains = L_shl(tmp, expPeakGains); - Mpy_32_32_ss(manPeakGains, manPeakGains, &manPkEnrg, &lsb); /* peak_gains square */ - expPkEnrg = shl(expPeakGains, 1); /* Multiply by 2 due to squaring. */ - - floating_point_add(&manE_peak, &expE_peak, manPkEnrg, expPkEnrg); - } - /* Number of bits used for peak gain quantization */ - diff = add(diff, add(FLAGN_BITS + GAIN0_BITS, hcode_l)); - - /* De-quantize peaks */ - FOR (i = 0; i < vq_peaks; i++) - { - dequant_peaks_fx( st_fx, &coefs_out[vq_peak_idx[i]-2], &peak_gains_fx[i]); /* coefs_out in Q12, peak_gains_fx in Q14 */ - diff = add(diff, 9); - } - - FOR (i = 0; i < HVQ_NF_GROUPS; i++) - { - nf_gains_idx[i] = get_next_indice_fx( st_fx, 5 ); - move16(); - nf_gains_fx[i] = L_shr(dicn_fx[nf_gains_idx[i]],1); - move32(); /* nf_gains in Q14 */ - diff = add(diff, 5); - } - pvq_bits = sub(num_bits, diff); - - /* Calculate number of PVQ bands to code and assign bits */ - pvq_bands = hvq_pvq_bitalloc_fx(pvq_bits, brate, st_fx->bwidth_fx, ynrm, manE_peak, expE_peak, Rk, R, sel_bnds, - &n_sel_bnds); - - /* safety check in case of bit errors */ - if (pvq_bands == 0) - { - st_fx->BER_detect = 1; - move16(); - } - - pvq_bits = sub(pvq_bits, i_mult2(HVQ_PVQ_GAIN_BITS, pvq_bands)); - /* Get band limits for concatenated PVQ target */ - hvq_concat_bands_fx(pvq_bands, sel_bnds, n_sel_bnds, hvq_band_start, - hvq_band_width, hvq_band_end); - - FOR (k = 0; k < pvq_bands; k++) - { - k_sort[k] = k; - move16(); - } - - pvq_decode_frame_fx(st_fx, pvq_vector, npulses, pvq_inp_vector, hvq_band_start, hvq_band_end, hvq_band_width, pvq_bands, Rk, pvq_bits, core ); - - - fine_gain_pred_fx( hvq_band_start, hvq_band_end, hvq_band_width, k_sort, npulses, pvq_maxpulse, NULL, - pvq_bands, pvq_vector, pvq_inp_vector, fg_pred, core ); - - fine_gain_dec_fx( st_fx, k_sort, pvq_bands, gain_bits_array, fg_pred); - - apply_gain_fx(k_sort, hvq_band_start, hvq_band_end, pvq_bands, fg_pred, pvq_vector); - - pPvqVector = pvq_vector; - pCoefsOut = coefs_out; - pSelBnds = sel_bnds; - move16(); - FOR (k = 0; k < pvq_bands; k++) - { - pvq_norm[k] = get_next_indice_fx( st_fx, HVQ_PVQ_GAIN_BITS ); - pvq_norm[k] = add(pvq_norm[k], 8); - move16(); - - diff = add(diff, HVQ_PVQ_GAIN_BITS); - - j = 0; - move16(); - IF (sub(k, sub(pvq_bands, n_sel_bnds)) >= 0) - { - i = band_start_harm[*pSelBnds++]; - move16(); - move16(); - pCoefsOut = coefs_out + i; - } - normq = L_add(dicn_fx[pvq_norm[k]], 0); - WHILE (sub(j, hvq_band_width[k]) < 0) - { - IF (L_sub(*pCoefsOut, 0) == 0) - { - Mpy_32_16_ss(normq, *pPvqVector++, &acc, &dontCare); /* acc(Q11), normq(Q14), pvq_vector(Q12) */ - *pCoefsOut = L_shl(acc, 12 - 11); /* Q12 */ move32(); - j = add(j, 1); - } - pCoefsOut++; - } - } - - /* Noise fill unqantized coeffs with one gain per group */ - pCoefsOut = &coefs_out[-1]; - FOR (i = 0; i < HVQ_NF_GROUPS; i++) - { - FOR (j = 0; j < bin_th2; j++) - { - IF (*(++pCoefsOut) == 0) - { - whiteNoise = Random(&nf_seed); /* Q15 */ - Mpy_32_16_ss(nf_gains_fx[i], whiteNoise, &acc, &dontCare); /* nf_gains_fx[] in Q14 */ - *pCoefsOut = L_shr(acc, 14-12); /* Q12 */ move32(); - } - } - } - - return; -} - -/*-------------------------------------------------------------------------- - * dequant_peaks() - * - * Reads codebook vector and scales peak - *--------------------------------------------------------------------------*/ - -static void dequant_peaks_fx( - Decoder_State_fx *st_fx, /* i/o: decoder state structure */ - Word32 *vect_out, /* o : Quantized vector in Q12 */ - const Word32 *peak_gain /* i : Peak gain in Q12 */ -) -{ - Word16 xq[4]; - const Word16 *tmp; - Word16 i, hvq_cb_rev; - Word16 cb_idx, indx; - Word32 absPeakGain1, absPeakGain; - UWord16 dontCare; - - hvq_cb_rev = get_next_indice_fx( st_fx, 1 ); - cb_idx = get_next_indice_fx( st_fx, 8 ); - - indx = shl(cb_idx,2); - IF ( hvq_cb_rev ) - { - indx = add(indx,3); - tmp = &hvq_peak_cb_fx[indx]; - FOR (i = 0; i < 4; i++) - { - xq[i] = *tmp--; /* Q15 */ move16(); - } - } - ELSE - { - tmp = &hvq_peak_cb_fx[indx]; - FOR (i = 0; i < 4; i++) - { - xq[i] = *tmp++; /* Q15 */ move16(); - } - } - - absPeakGain = L_abs(peak_gain[0]); - - IF(vect_out[0] == 0) - { - Mpy_32_16_ss(*peak_gain, xq[0], &vect_out[0], &dontCare); /* vect_out in Q12 */ - Mpy_32_16_ss(*peak_gain, xq[1], &vect_out[1], &dontCare); /* Q12 */ - } - ELSE - { - absPeakGain1 = L_abs(peak_gain[-1]); - IF(L_sub(absPeakGain1, absPeakGain) <= 0) - { - Mpy_32_16_ss(*peak_gain, xq[0], &vect_out[0], &dontCare); /* vect_out in Q12 */ - Mpy_32_16_ss(*peak_gain, xq[1], &vect_out[1], &dontCare); /* Q12 */ - } - ELSE - { - IF(vect_out[1] == 0 || (L_sub(absPeakGain1, absPeakGain) <= 0)) - { - Mpy_32_16_ss(*peak_gain, xq[1], &vect_out[1], &dontCare); - } - } - } - vect_out[2] = *peak_gain; /* vect_out in Q12 */ - Mpy_32_16_ss(*peak_gain, xq[2], &vect_out[3], &dontCare); - Mpy_32_16_ss(*peak_gain, xq[3], &vect_out[4], &dontCare); - - return; -} - - -/*-------------------------------------------------------------------------- - * hvq_dec_pos() - * - * HVQ decode peak positions - *--------------------------------------------------------------------------*/ - -static Word16 hvq_dec_pos_fx( - Decoder_State_fx *st_fx, /* i/o: decoder state structure */ - Word16 *pos_vec, - const Word16 length, - const Word16 num_peaks -) -{ - Word16 peak_idx[HVQ_MAX_PEAKS_32k]; - Word16 delta[HVQ_MAX_PEAKS_32k]; - Word16 sign_vec[HVQ_MAX_PEAKS_32k]; - - Word16 mode; - Word16 num_bits, tmp; - Word16 i, j; - - num_bits = 0; - move16(); - set16_fx(pos_vec, 0, length); - - mode = get_next_indice_fx(st_fx, 1); - num_bits = add(num_bits, 1); - - IF (mode == HVQ_CP_DELTA) - { - huff_dec_fx(st_fx, num_peaks, HVQ_CP_HUFF_MAX_CODE, HVQ_CP_HUFF_NUM_LEN, hvq_cp_huff_thres, hvq_cp_huff_offset, hvq_cp_huff_tab, delta); - - FOR (i = 0; i < num_peaks; i++) - { - num_bits = add(num_bits, hvq_cp_huff_len[delta[i]]); - } - - peak_idx[0] = sub(delta[0], HVQ_CP_HUFF_OFFSET); - /* safety check in case of bit errors */ - IF (peak_idx[0] < 2) - { - peak_idx[0] = 2; - move16(); - st_fx->BER_detect = 1; - move16(); - } - FOR (i = 1; i < num_peaks; i++) - { - peak_idx[i] = add(add(delta[i], peak_idx[i-1]), HVQ_CP_HUFF_OFFSET); - move16(); - /* safety check in case of bit errors */ - IF (sub(peak_idx[i], HVQ_THRES_BIN_32k) >= 0) - { - peak_idx[i] = HVQ_THRES_BIN_32k - 1; - move16(); - st_fx->BER_detect = 1; - move16(); - } - } - - FOR (i = 0; i < num_peaks; i++) - { - pos_vec[peak_idx[i]] = 1; - move16(); - } - } - ELSE - { - tmp = sparse_dec_pos_fx(st_fx, pos_vec, length); - num_bits = add(num_bits, tmp); - } - - FOR (i = 0; i < num_peaks; i++) - { - IF (get_next_indice_1_fx(st_fx) == 0) - { - sign_vec[i] = -1; - move16(); - } - ELSE - { - sign_vec[i] = 1; - move16(); - } - } - num_bits = add(num_bits, num_peaks); - - j = 0; - move16(); - /* safety check in case of bit errors */ - test(); - FOR (i = 0; i < length && j < num_peaks; i++) - { - if (sub(pos_vec[i], 1) == 0) - { - pos_vec[i] = i_mult2(pos_vec[i], sign_vec[j++]); - move16(); - } - } - - return num_bits; -} - -/*-------------------------------------------------------------------------- - * sparse_dec_pos() - * - * Sparse decode positions - *--------------------------------------------------------------------------*/ - -static Word16 sparse_dec_pos_fx( - Decoder_State_fx *st_fx, /* i/o: decoder state structure */ - Word16 *out, - const Word16 length -) -{ - Word16 layer2[HVQ_CP_L2_MAX]; - Word16 layer_length; - Word16 i, j, tmp; - Word16 bits; - Word16 idx, val; - - set16_fx(layer2, 0, HVQ_CP_L2_MAX); - set16_fx(out, 0, length); - bits = 0; - move16(); - - /*layer_length = (short)((float)length/HVQ_CP_L1_LEN + 0.5); */ - layer_length = round_fx(L_mult0(length, 13107)); /* 0+16-16, 13107 is 1/5 in Q16 */ - - FOR (i = 0; i < layer_length; i++) - { - layer2[i] = get_next_indice_1_fx(st_fx); - move16(); - } - bits = add(bits, layer_length); - - FOR (j = 0; j < layer_length; j++) - { - IF (sub(layer2[j], 1) == 0) - { - idx = get_next_indice_fx(st_fx, HVQ_CP_MAP_IDX_LEN); - bits = add(bits, HVQ_CP_MAP_IDX_LEN); - - val = hvq_cp_layer1_map5[idx]; - move16(); - test(); /* safety check in case of bit errors */ - IF ( j == 0 && sub(val, 4) > 0 ) /* out[0] and out[1] are invalid positions */ - { - st_fx->BER_detect = 1; - move16(); - val = 4; - move16(); - } - tmp = i_mult2(j, HVQ_CP_L1_LEN); - FOR (i = sub(s_min(i_mult2(add(j,1), HVQ_CP_L1_LEN), length), 1); i >= tmp; i--) - { - out[i] = s_and(val, 1); - move16(); - val = lshr(val, 1); - } - } - } - - return bits; -} diff --git a/src/libs/libevs/lib_dec/pit_dec.cpp b/src/libs/libevs/lib_dec/pit_dec.cpp old mode 100755 new mode 100644 index 487dc3a2..5a2dcd3f --- a/src/libs/libevs/lib_dec/pit_dec.cpp +++ b/src/libs/libevs/lib_dec/pit_dec.cpp @@ -1,241 +1,757 @@ /*==================================================================================== - EVS Codec 3GPP TS26.442 Apr 03, 2018. Version 12.11.0 / 13.6.0 / 14.2.0 + EVS Codec 3GPP TS26.443 Nov 13, 2018. Version 12.11.0 / 13.7.0 / 14.3.0 / 15.1.0 ====================================================================================*/ #include #include +#include #include -#include "cnst_fx.h" -#include "prot_fx.h" -#include "stl.h" +#include "cnst.h" +#include "prot.h" +#include "rom_com.h" #include "options.h" -#include "rom_basop_util.h" -#define inv_T0_res InvIntTable /*----------------------------------------------------------* - * Mode2_pit_decode() + * pit_decode() * - * Decode pitch lag + * Decode OL pitch lag *----------------------------------------------------------*/ -Word32 Mode2_pit_decode( /* o: floating pitch value */ - const Word16 coder_type, /* i: coding model */ - Word16 i_subfr, /* i: subframe index */ - Word16 L_subfr, - Word16 **pt_indice, /* i/o: quantization indices pointer */ - Word16 *T0, /* i/o: close loop integer pitch */ - Word16 *T0_frac, /* o: close loop fractional part of the pitch */ - Word16 *T0_res, /* i/o: pitch resolution */ - Word16 *T0_min, /* i/o: lower limit for close-loop search */ - Word16 *T0_min_frac, /* i/o: lower limit for close-loop search */ - Word16 *T0_max, /* i/o: higher limit for close-loop search */ - Word16 *T0_max_frac, /* i/o: higher limit for close-loop search */ - Word16 pit_min, - Word16 pit_fr1, - Word16 pit_fr1b, - Word16 pit_fr2, - Word16 pit_max, - Word16 pit_res_max +float pit_decode( /* o : floating pitch value */ + Decoder_State *st, /* i/o: decoder state structure */ + const long core_brate, /* i : core bitrate */ + const short Opt_AMR_WB, /* i : flag indicating AMR-WB IO mode */ + const short L_frame, /* i : length of the frame */ + short i_subfr, /* i : subframe index */ + const short coder_type, /* i : coding type */ + short *limit_flag, /* i/o: restrained(0) or extended(1) Q limits */ + short *T0, /* o : close loop integer pitch */ + short *T0_frac, /* o : close loop fractional part of the pitch */ + short *T0_min, /* i/o: delta search min */ + short *T0_max, /* i/o: delta search max */ + const short L_subfr /* i : subframe length */ ) { - Word32 pitch; + float pitch; + short pitch_index, nBits, pit_flag; - IF(coder_type == 0) + pitch_index = 0; + + /*----------------------------------------------------------------* + * Set pit_flag = 0 for every subframe with absolute pitch search + *----------------------------------------------------------------*/ + + pit_flag = i_subfr; + if( i_subfr == 2*L_SUBFR ) { - *T0 = L_subfr; - move16(); - *T0_frac = 0; - move16(); - *T0_res = 1; - move16(); + pit_flag = 0; } - ELSE IF(sub(coder_type,1) == 0) /* 8/4/4/4 (EVS) */ + + /*-------------------------------------------------------* + * Retrieve the pitch index + *-------------------------------------------------------*/ + + if( !Opt_AMR_WB ) { - IF (i_subfr == 0) + /*----------------------------------------------------------------* + * pitch Q: Set limit_flag to 0 for restrained limits, and 1 for extended limits + *----------------------------------------------------------------*/ + + if( i_subfr == 0 ) { - Mode2_abs_pit_dec( T0, T0_frac, T0_res, pt_indice, pit_min, pit_fr1b, pit_min, pit_res_max); + *limit_flag = 1; + + if( coder_type == VOICED ) + { + *limit_flag = 2; /* double-extended limits */ + } + + if( coder_type == GENERIC && core_brate == ACELP_7k20 ) + { + *limit_flag = 0; + } } - ELSE + else if( i_subfr == 2*L_SUBFR && coder_type == GENERIC && core_brate <= ACELP_13k20 ) { - limit_T0_voiced( 4, shr(pit_res_max,1), *T0, *T0_frac, *T0_res, T0_min, T0_min_frac, T0_max, T0_max_frac, pit_min, pit_max ); - *T0_res = shr(pit_res_max,1); - move16(); - Mode2_delta_pit_dec( T0, T0_frac, *T0_res, T0_min, T0_min_frac, pt_indice); - } - } - ELSE IF(sub(coder_type,2) == 0) /* 8/5/8/5 (EVS) */ - { - test(); - IF ( ( i_subfr == 0 ) || ( sub(i_subfr,shl(L_subfr,1)) == 0) ) - { - Mode2_abs_pit_dec( T0, T0_frac, T0_res, pt_indice, pit_min, pit_fr1b, pit_min, pit_res_max); - } - ELSE - { - limit_T0_voiced( 5, shr(pit_res_max,1), *T0, *T0_frac, *T0_res, T0_min, T0_min_frac, T0_max, T0_max_frac, pit_min, pit_max ); - *T0_res = shr(pit_res_max,1); - move16(); - Mode2_delta_pit_dec( T0, T0_frac, *T0_res, T0_min, T0_min_frac, pt_indice); - } - } - ELSE IF(sub(coder_type,3) == 0) /* 9/6/6/6 (HRs- VC) */ - { - Word16 pit_res_max2 = pit_res_max; - if ( sub(pit_min,PIT_MIN_16k)==0 ) - { - pit_res_max2 = shr(pit_res_max,1); + if( *T0 > (PIT_FR1_EXTEND_8b + PIT_MIN)>>1 ) + { + *limit_flag = 0; + } } - IF ( ( i_subfr == 0 ) ) + /*-------------------------------------------------------* + * Retrieve the number of Q bits + *-------------------------------------------------------*/ + + nBits = 0; + if( coder_type != AUDIO ) { - Mode2_abs_pit_dec( T0, T0_frac, T0_res, pt_indice, pit_min, pit_fr1, pit_fr2, pit_res_max); + /* find the number of bits */ + if( L_frame == L_FRAME ) + { + nBits = ACB_bits_tbl[BIT_ALLOC_IDX(core_brate, coder_type, i_subfr, 0)]; + } + else /* L_frame == L_FRAME16k */ + { + nBits = ACB_bits_16kHz_tbl[BIT_ALLOC_IDX_16KHZ(core_brate, coder_type, i_subfr, 0)]; + } + + pitch_index = (short)get_next_indice( st, nBits ); } - ELSE + + /*-------------------------------------------------------* + * Pitch decoding in AUDIO mode + * (both ACELP@12k8 and ACELP@16k cores) + *-------------------------------------------------------*/ + + if( coder_type == AUDIO ) { - limit_T0_voiced( 6, pit_res_max2, *T0, 0, 1, T0_min, T0_min_frac, T0_max, T0_max_frac, pit_min, pit_max ); - *T0_res = pit_res_max2; - move16(); - Mode2_delta_pit_dec( T0, T0_frac, *T0_res, T0_min, T0_min_frac, pt_indice); + if( L_subfr == L_FRAME/2 && i_subfr != 0 ) + { + pit_flag = L_SUBFR; + } + + if( pit_flag == 0 ) + { + nBits = 10; + } + else + { + nBits = 6; + } + + pitch_index = (short)get_next_indice( st, nBits ); + + if( L_subfr == L_FRAME/2 && i_subfr != 0 && pitch_index >= 32 ) /* safety check in case of bit errors */ + { + pitch_index = pitch_index>>1; + st->BER_detect = 1; + } + + pit_Q_dec( 0, pitch_index, nBits, 4, pit_flag, *limit_flag, T0, T0_frac, T0_min, T0_max, &st->BER_detect ); + } + else if( coder_type == VOICED ) + { + /*-------------------------------------------------------* + * Pitch decoding in VOICED mode + * (ACELP@12k8 core only) + *-------------------------------------------------------*/ + + if( i_subfr == 2*L_SUBFR ) + { + pit_flag = i_subfr; + } + + pit_Q_dec( 0, pitch_index, nBits, 4, pit_flag, *limit_flag, T0, T0_frac, T0_min, T0_max, &st->BER_detect ); + } + else + { + /*-------------------------------------------------------* + * Pitch decoding in GENERIC mode + * (both ACELP@12k8 and ACELP@16k cores) + *-------------------------------------------------------*/ + + if( L_frame == L_FRAME ) + { + pit_Q_dec( 0, pitch_index, nBits, 8, pit_flag, *limit_flag, T0, T0_frac, T0_min, T0_max, &st->BER_detect ); + } + else + { + pit16k_Q_dec( pitch_index, nBits, *limit_flag, T0, T0_frac, T0_min, T0_max, &st->BER_detect ); + } } } - ELSE IF(sub(coder_type,4) == 0) /* 9/6/9/6 (AMRWB) */ + + /*-------------------------------------------------------* + * Pitch decoding in AMR-WB IO mode + *-------------------------------------------------------*/ + + else { - Word16 pit_res_max2 = pit_res_max; - if ( sub(pit_min,PIT_MIN_16k)==0 ) + *limit_flag = 0; + + if( i_subfr == 0 || ( i_subfr == 2*L_SUBFR && core_brate == ACELP_8k85 ) ) { - pit_res_max2 = shr(pit_res_max,1); + nBits = 8; } - test(); - IF ( ( i_subfr == 0 ) || ( sub(i_subfr,shl(L_subfr,1)) == 0 ) ) + else { - Mode2_abs_pit_dec( T0, T0_frac, T0_res, pt_indice, pit_min, pit_fr1, pit_fr2, pit_res_max); + nBits = 5; } - ELSE + + if( core_brate > ACELP_8k85 ) { - limit_T0_voiced( 6, pit_res_max2, *T0, 0, 1, T0_min, T0_min_frac, T0_max, T0_max_frac, pit_min, pit_max ); - *T0_res = pit_res_max2; - move16(); - Mode2_delta_pit_dec( T0, T0_frac, *T0_res, T0_min, T0_min_frac, pt_indice); + nBits = 6; + + if( i_subfr == 0 || i_subfr == 2*L_SUBFR ) + { + nBits = 9; + } } - } - ELSE IF(sub(coder_type,8) == 0) /* 8/5/5/5 (RF all pred mode) */ - { - IF (i_subfr == 0) - { - Mode2_abs_pit_dec( T0, T0_frac, T0_res, pt_indice, pit_min, pit_fr1b, pit_min, pit_res_max); - } - ELSE - { - limit_T0_voiced( 5, shr(pit_res_max,1), *T0, *T0_frac, *T0_res, T0_min, T0_min_frac, T0_max, T0_max_frac, pit_min, pit_max ); - *T0_res = shr(pit_res_max,1); - Mode2_delta_pit_dec( T0, T0_frac, *T0_res, T0_min, T0_min_frac, pt_indice); - } - } - ELSE IF(sub(coder_type,9) == 0) /* 8/0/8/0 (RF gen pred mode) */ - { - IF (i_subfr == 0) - { - Mode2_abs_pit_dec( T0, T0_frac, T0_res, pt_indice, pit_min, pit_fr1b, pit_min, pit_res_max); - } - ELSE - { - limit_T0_voiced( 4, shr(pit_res_max,1), *T0, *T0_frac, *T0_res, T0_min, T0_min_frac, T0_max, T0_max_frac, pit_min, pit_max ); - *T0_res = shr(pit_res_max,1); - Mode2_delta_pit_dec( T0, T0_frac, *T0_res, T0_min, T0_min_frac, pt_indice); - } - } - ELSE - { - assert(0 && "LTP mode not supported"); + + pitch_index = (short)get_next_indice( st, nBits ); + + pit_Q_dec( 1, pitch_index, nBits, 8, pit_flag, *limit_flag, T0, T0_frac, T0_min, T0_max, &st->BER_detect ); } /*-------------------------------------------------------* * Compute floating pitch output *-------------------------------------------------------*/ - assert(*T0_res > 0 || *T0_res <= 6); - - /*pitch = (float)(*T0) + (float)(*T0_frac)/(float)(*T0_res);*/ /* save subframe pitch values */ - pitch = L_mac(L_deposit_h(*T0), *T0_frac,inv_T0_res[*T0_res]); + pitch = (float)(*T0) + (float)(*T0_frac)/4.0f; return pitch; } - /*---------------------------------------------------------------------* - * Mode2_abs_pit_dec() + * abs_pit_dec() * * Decode the absolute pitch *---------------------------------------------------------------------*/ -void Mode2_abs_pit_dec( - Word16 *T0, /* o: integer pitch lag */ - Word16 *T0_frac, /* o: pitch fraction */ - Word16 *T0_res, /* o: pitch resolution */ - Word16 **pt_indice, /* i/o: pointer to Vector of Q indexes */ - Word16 pit_min, - Word16 pit_fr1, - Word16 pit_fr2, - Word16 pit_res_max +void abs_pit_dec( + const short fr_steps, /* i: fractional resolution steps (0, 2, 4) */ + short pitch_index, /* i: pitch index */ + const short limit_flag, /* i : restrained(0) or extended(1) limits */ + short *T0, /* o: integer pitch lag */ + short *T0_frac /* o: pitch fraction */ ) { - Word16 index; - Word16 pit_res_max_half, tmp1, tmp2, res; + if( limit_flag == 0 ) + { + if( fr_steps == 2 ) + { + if( pitch_index < (PIT_FR1_8b-PIT_MIN)*2 ) + { + *T0 = PIT_MIN + (pitch_index/2); + *T0_frac = pitch_index - ((*T0 - PIT_MIN)*2); + *T0_frac *= 2; + } + else + { + *T0 = pitch_index + PIT_FR1_8b - ((PIT_FR1_8b-PIT_MIN)*2); + *T0_frac = 0; + } + } + else if( fr_steps == 4 ) + { + if( pitch_index < (PIT_FR2_9b-PIT_MIN)*4 ) + { + *T0 = PIT_MIN + (pitch_index/4); + *T0_frac = pitch_index - (*T0 - PIT_MIN)*4; + } + else if( pitch_index < ( (PIT_FR2_9b-PIT_MIN)*4 + (PIT_FR1_9b-PIT_FR2_9b)*2) ) + { + pitch_index -= (PIT_FR2_9b-PIT_MIN)*4; + *T0 = PIT_FR2_9b + (pitch_index/2); + *T0_frac = pitch_index - (*T0 - PIT_FR2_9b)*2; + (*T0_frac) *= 2; + } + else + { + *T0 = pitch_index + PIT_FR1_9b - ((PIT_FR2_9b-PIT_MIN)*4) - ((PIT_FR1_9b-PIT_FR2_9b)*2); + *T0_frac = 0; + } + } + else /* fr_steps == 0 */ + { + /* not used in the codec */ + } + } + else if( limit_flag == 1 ) /* extended Q range */ + { + if( fr_steps == 2 ) + { + if( pitch_index < (PIT_FR1_EXTEND_8b-PIT_MIN_EXTEND)*2 ) + { + *T0 = PIT_MIN_EXTEND + (pitch_index/2); + *T0_frac = pitch_index - ((*T0 - PIT_MIN_EXTEND)*2); + *T0_frac *= 2; + } + else + { + *T0 = pitch_index + PIT_FR1_EXTEND_8b - ((PIT_FR1_EXTEND_8b-PIT_MIN_EXTEND)*2); + *T0_frac = 0; + } + } + else if( fr_steps == 4 ) + { + if( pitch_index < (PIT_FR2_EXTEND_9b-PIT_MIN_EXTEND)*4 ) + { + *T0 = PIT_MIN_EXTEND + (pitch_index/4); + *T0_frac = pitch_index - (*T0 - PIT_MIN_EXTEND)*4; + } + else if( pitch_index < ( (PIT_FR2_EXTEND_9b-PIT_MIN_EXTEND)*4 + (PIT_FR1_EXTEND_9b-PIT_FR2_EXTEND_9b)*2) ) + { + pitch_index -= (PIT_FR2_EXTEND_9b-PIT_MIN_EXTEND)*4; + *T0 = PIT_FR2_EXTEND_9b + (pitch_index/2); + *T0_frac = pitch_index - (*T0 - PIT_FR2_EXTEND_9b)*2; + (*T0_frac) *= 2; + } + else + { + *T0 = pitch_index + PIT_FR1_EXTEND_9b - ((PIT_FR2_EXTEND_9b-PIT_MIN_EXTEND)*4) - ((PIT_FR1_EXTEND_9b-PIT_FR2_EXTEND_9b)*2); + *T0_frac = 0; + } + } + else /* fr_steps == 0 */ + { + /* not used in the codec */ + } + } + else /* limit_flag == 2 */ + { + if( fr_steps == 2 ) + { + if( pitch_index < (PIT_FR1_DOUBLEEXTEND_8b-PIT_MIN_DOUBLEEXTEND)*2 ) + { + *T0 = PIT_MIN_DOUBLEEXTEND + (pitch_index/2); + *T0_frac = pitch_index - ((*T0 - PIT_MIN_DOUBLEEXTEND)*2); + *T0_frac *= 2; + } + else + { + *T0 = pitch_index + PIT_FR1_DOUBLEEXTEND_8b - ((PIT_FR1_DOUBLEEXTEND_8b-PIT_MIN_DOUBLEEXTEND)*2); + *T0_frac = 0; + } + } + else if( fr_steps == 4 ) + { + if( pitch_index < (PIT_FR2_DOUBLEEXTEND_9b-PIT_MIN_DOUBLEEXTEND)*4 ) + { + *T0 = PIT_MIN_DOUBLEEXTEND + (pitch_index/4); + *T0_frac = pitch_index - (*T0 - PIT_MIN_DOUBLEEXTEND)*4; + } + else if( pitch_index < ( (PIT_FR2_DOUBLEEXTEND_9b-PIT_MIN_DOUBLEEXTEND)*4 + (PIT_FR1_DOUBLEEXTEND_9b-PIT_FR2_DOUBLEEXTEND_9b)*2) ) + { + pitch_index -= (PIT_FR2_DOUBLEEXTEND_9b-PIT_MIN_DOUBLEEXTEND)*4; + *T0 = PIT_FR2_DOUBLEEXTEND_9b + (pitch_index/2); + *T0_frac = pitch_index - (*T0 - PIT_FR2_DOUBLEEXTEND_9b)*2; + (*T0_frac) *= 2; + } + else + { + *T0 = pitch_index + PIT_FR1_DOUBLEEXTEND_9b - ((PIT_FR2_DOUBLEEXTEND_9b-PIT_MIN_DOUBLEEXTEND)*4) - ((PIT_FR1_DOUBLEEXTEND_9b-PIT_FR2_DOUBLEEXTEND_9b)*2); + *T0_frac = 0; + } + } + else /* fr_steps == 0 */ + { + /* not used in the codec */ + } + } + + return; +} + + +/*---------------------------------------------------------------------* + * delta_pit_dec() + * + * Decode delta pitch + *---------------------------------------------------------------------*/ + +void delta_pit_dec( + const short fr_steps, /* i : fractional resolution steps (0, 2, 4) */ + const short pitch_index, /* i : pitch index */ + short *T0, /* o : integer pitch lag */ + short *T0_frac, /* o : pitch fraction */ + const short T0_min /* i : delta search min */ +) +{ + if( fr_steps == 0 ) + { + *T0 = T0_min + pitch_index; + *T0_frac = 0; + } + else if( fr_steps == 2 ) + { + *T0 = T0_min + pitch_index/2; + *T0_frac = pitch_index - (*T0 - T0_min)*2; + *T0_frac *= 2; + } + else if( fr_steps == 4 ) + { + *T0 = T0_min + pitch_index/4; + *T0_frac = pitch_index - (*T0 - T0_min)*4; + } + + return; +} + + +/*-------------------------------------------------* + * pit_Q_dec() + * + * pitch decoding + *-------------------------------------------------*/ + +void pit_Q_dec( + const short Opt_AMR_WB, /* i : flag indicating AMR-WB IO mode */ + const short pitch_index, /* i : pitch index */ + const short nBits, /* i : # of Q bits */ + const short delta, /* i : Half the CL searched interval */ + const short pit_flag, /* i : absolute(0) or delta(1) pitch Q */ + const short limit_flag, /* i : restrained(0) or extended(1) Q limits */ + short *T0, /* o : integer pitch lag */ + short *T0_frac, /* o : pitch fraction */ + short *T0_min, /* i/o: delta search min */ + short *T0_max /* i/o: delta search max */ + ,short *BER_detect /* o : BER detect flag */ +) +{ + if( nBits == 10 ) /* absolute decoding with 10 bits */ + { + if( limit_flag == 0 ) + { + *T0 = PIT_MIN + (pitch_index/4); + *T0_frac = pitch_index - (*T0 - PIT_MIN)*4; + } + else if( limit_flag == 1 ) + { + *T0 = PIT_MIN_EXTEND + (pitch_index/4); + *T0_frac = pitch_index - (*T0 - PIT_MIN_EXTEND)*4; + } + else /* limit_flag == 2 */ + { + *T0 = PIT_MIN_DOUBLEEXTEND + (pitch_index/4); + *T0_frac = pitch_index - (*T0 - PIT_MIN_DOUBLEEXTEND)*4; + } + } + else if( nBits == 9 ) /* absolute decoding with 9 bits */ + { + abs_pit_dec( 4, pitch_index, limit_flag, T0, T0_frac ); + + /* find T0_min and T0_max for delta search */ + if( Opt_AMR_WB ) + { + limit_T0( L_FRAME, delta, pit_flag, 0, *T0, 0, T0_min, T0_max ); /* T0_frac==0 to keep IO with AMR-WB */ + } + } + else if( nBits == 8 ) /* absolute decoding with 8 bits */ + { + abs_pit_dec( 2, pitch_index, limit_flag, T0, T0_frac ); + + /* find T0_min and T0_max for delta search */ + if( Opt_AMR_WB ) + { + limit_T0( L_FRAME, delta, pit_flag, 0, *T0, 0, T0_min, T0_max ); /* T0_frac==0 to keep IO with AMR-WB */ + } + } + else if( nBits == 6 ) /* relative decoding with 6 bits */ + { + delta_pit_dec( 4, pitch_index, T0, T0_frac, *T0_min ); + } + else if( nBits == 5 ) /* relative decoding with 5 bits */ + { + if( delta == 8 ) + { + delta_pit_dec( 2, pitch_index, T0, T0_frac, *T0_min ); + } + else /* delta == 4 */ + { + delta_pit_dec( 4, pitch_index, T0, T0_frac, *T0_min ); + } + } + else /* nBits == 4 */ /* relative decoding with 4 bits */ + { + if( delta == 8 ) + { + delta_pit_dec( 0, pitch_index, T0, T0_frac, *T0_min ); + } + else /* delta == 4 */ + { + delta_pit_dec( 2, pitch_index, T0, T0_frac, *T0_min ); + } + } + + /* biterror detection mechanism */ + if( ((*T0<<2) + *T0_frac) > (PIT_MAX<<2)+2 && pit_flag == 0 && !Opt_AMR_WB ) + { + *T0 = L_SUBFR; + *T0_frac = 0; + *BER_detect = 1; + } + + if( !Opt_AMR_WB ) + { + /* find T0_min and T0_max for delta search */ + limit_T0( L_FRAME, delta, L_SUBFR, limit_flag, *T0, *T0_frac, T0_min, T0_max ); + } + + return; +} + +/*-------------------------------------------------* + * pit16k_Q_dec() + * + * pitch decoding @16kHz core + *-------------------------------------------------*/ + +void pit16k_Q_dec( + const short pitch_index, /* i : pitch index */ + const short nBits, /* i : # of Q bits */ + const short limit_flag, /* i : restrained(0) or extended(1) limits */ + short *T0, /* o : integer pitch lag */ + short *T0_frac, /* o : pitch fraction */ + short *T0_min, /* i/o: delta search min */ + short *T0_max /* i/o: delta search max */ + ,short *BER_detect /* o : BER detect flag */ +) +{ + short index; + + if( nBits == 10 ) /* absolute decoding with 10 bits */ + { + { + if( pitch_index < (PIT16k_FR2_EXTEND_10b-PIT16k_MIN_EXTEND)*4 ) + { + *T0 = PIT16k_MIN_EXTEND + (pitch_index/4); + *T0_frac = pitch_index - ((*T0 - PIT16k_MIN_EXTEND)*4); + } + else + { + index = pitch_index - (PIT16k_FR2_EXTEND_10b-PIT16k_MIN_EXTEND)*4; + *T0 = PIT16k_FR2_EXTEND_10b + (index/2); + *T0_frac = index - (*T0 - PIT16k_FR2_EXTEND_10b)*2; + (*T0_frac) *= 2; + } + } + + } + else if( nBits == 9 ) /* absolute decoding with 9 bits */ + { + { + if (pitch_index < (PIT16k_FR2_EXTEND_9b-PIT16k_MIN_EXTEND)*4) + { + *T0 = PIT16k_MIN_EXTEND + (pitch_index/4); + *T0_frac = pitch_index - (*T0 - PIT16k_MIN_EXTEND)*4; + } + else if (pitch_index < ( (PIT16k_FR2_EXTEND_9b-PIT16k_MIN_EXTEND)*4 + (PIT16k_FR1_EXTEND_9b-PIT16k_FR2_EXTEND_9b)*2) ) + { + index = pitch_index - (PIT16k_FR2_EXTEND_9b-PIT16k_MIN_EXTEND)*4; + *T0 = PIT16k_FR2_EXTEND_9b + (index/2); + *T0_frac = index - (*T0 - PIT16k_FR2_EXTEND_9b)*2; + (*T0_frac) *= 2; + } + else + { + *T0 = pitch_index + PIT16k_FR1_EXTEND_9b - ((PIT16k_FR2_EXTEND_9b-PIT16k_MIN_EXTEND)*4) - ((PIT16k_FR1_EXTEND_9b-PIT16k_FR2_EXTEND_9b)*2); + *T0_frac = 0; + } + } + } + else /* nBits == 6 */ /* relative decoding with 6 bits */ + { + delta_pit_dec( 4, pitch_index, T0, T0_frac, *T0_min ); + } + + /* biterror detection mechanism */ + if( ((*T0<<2) + *T0_frac) > (PIT16k_MAX<<2) && nBits >= 9 ) + { + *T0 = L_SUBFR; + *T0_frac = 0; + *BER_detect = 1; + } + + /* find T0_min and T0_max for delta search */ + limit_T0( L_FRAME16k, 8, L_SUBFR, limit_flag, *T0, *T0_frac, T0_min, T0_max ); + + return; +} + + +/*----------------------------------------------------------* + * Mode2_pit_decode + * + * Decode pitch lag + *----------------------------------------------------------*/ + +float Mode2_pit_decode( /* o: floating pitch value */ + const short coder_type, /* i: coding model */ + short i_subfr, /* i: subframe index */ + int L_subfr, + int **pt_indice, /* i/o: quantization indices pointer */ + int *T0, /* i/o: close loop integer pitch */ + int *T0_frac, /* o: close loop fractional part of the pitch */ + int *T0_res, /* i/o: pitch resolution */ + int *T0_min, /* i/o: lower limit for close-loop search */ + int *T0_min_frac, /* i/o: lower limit for close-loop search */ + int *T0_max, /* i/o: higher limit for close-loop search */ + int *T0_max_frac, /* i/o: higher limit for close-loop search */ + int pit_min, + int pit_fr1, + int pit_fr1b, + int pit_fr2, + int pit_max, + int pit_res_max +) +{ + float pitch; + + if( coder_type == 0 ) /*Unvoiced Coding do nothing*/ + { + + *T0 = L_subfr; + *T0_frac = 0; + *T0_res = 1; + } + else if(coder_type == 1) /* 8/4/4/4 (EVS) */ + { + + if (i_subfr == 0) + { + Mode2_abs_pit_dec( T0, T0_frac, T0_res, pt_indice, pit_min, pit_fr1b, pit_min, pit_res_max); + } + else + { + limit_T0_voiced( 4, pit_res_max>>1, *T0, *T0_frac, *T0_res, T0_min, T0_min_frac, T0_max, T0_max_frac, pit_min, pit_max ); + *T0_res = (pit_res_max>>1); + Mode2_delta_pit_dec( T0, T0_frac, *T0_res, T0_min, T0_min_frac, pt_indice); + } + } + else if(coder_type == 2) /* 8/5/8/5 (EVS) */ + { + + if ( ( i_subfr == 0 ) || ( i_subfr == 2*L_subfr ) ) + { + Mode2_abs_pit_dec( T0, T0_frac, T0_res, pt_indice, pit_min, pit_fr1b, pit_min, pit_res_max); + } + else + { + limit_T0_voiced( 5, pit_res_max>>1, *T0, *T0_frac, *T0_res, T0_min, T0_min_frac, T0_max, T0_max_frac, pit_min, pit_max ); + *T0_res = (pit_res_max>>1); + Mode2_delta_pit_dec( T0, T0_frac, *T0_res, T0_min, T0_min_frac, pt_indice); + } + } + else if(coder_type == 3) /* 9/6/6/6 (HRs- VC) */ + { + int pit_res_max2 = pit_res_max; + if ( pit_min==PIT_MIN_16k ) + { + pit_res_max2 = pit_res_max >> 1; + } + + if (i_subfr == 0) + { + Mode2_abs_pit_dec( T0, T0_frac, T0_res, pt_indice, pit_min, pit_fr1, pit_fr2, pit_res_max); + } + else + { + limit_T0_voiced( 6, pit_res_max2, *T0, 0, 1, T0_min, T0_min_frac, T0_max, T0_max_frac, pit_min, pit_max ); + *T0_res = pit_res_max2; + Mode2_delta_pit_dec( T0, T0_frac, *T0_res, T0_min, T0_min_frac, pt_indice); + } + } + else if(coder_type == 4) /* 9/6/9/6 (AMRWB) */ + { + int pit_res_max2 = pit_res_max; + if ( pit_min==PIT_MIN_16k ) + { + pit_res_max2 = pit_res_max >> 1; + } + + if ( ( i_subfr == 0 ) || ( i_subfr == 2*L_subfr ) ) + { + Mode2_abs_pit_dec( T0, T0_frac, T0_res, pt_indice, pit_min, pit_fr1, pit_fr2, pit_res_max); + } + else + { + limit_T0_voiced( 6, pit_res_max2, *T0, 0, 1, T0_min, T0_min_frac, T0_max, T0_max_frac, pit_min, pit_max ); + *T0_res = pit_res_max2; + Mode2_delta_pit_dec( T0, T0_frac, *T0_res, T0_min, T0_min_frac, pt_indice); + } + } + else if(coder_type == 8) /* 8/5/5/5 (RF all pred mode) */ + { + + if (i_subfr == 0) + { + Mode2_abs_pit_dec( T0, T0_frac, T0_res, pt_indice, pit_min, pit_fr1b, pit_min, pit_res_max); + } + else + { + limit_T0_voiced( 5, pit_res_max>>1, *T0, *T0_frac, *T0_res, T0_min, T0_min_frac, T0_max, T0_max_frac, pit_min, pit_max ); + *T0_res = (pit_res_max>>1); + Mode2_delta_pit_dec( T0, T0_frac, *T0_res, T0_min, T0_min_frac, pt_indice); + } + } + else if(coder_type == 9) /* 8/0/8/0 (RF gen pred mode) */ + { + + if (i_subfr == 0) + { + Mode2_abs_pit_dec( T0, T0_frac, T0_res, pt_indice, pit_min, pit_fr1b, pit_min, pit_res_max); + } + else + { + limit_T0_voiced( 4, pit_res_max>>1, *T0, *T0_frac, *T0_res, T0_min, T0_min_frac, T0_max, T0_max_frac, pit_min, pit_max ); + *T0_res = (pit_res_max>>1); + Mode2_delta_pit_dec( T0, T0_frac, *T0_res, T0_min, T0_min_frac, pt_indice); + } + } + else /*RCELP 8 bits pitch delay*/ + { + assert(0); + } + + /*-------------------------------------------------------* + * Compute floating pitch output + *-------------------------------------------------------*/ + + pitch = (float)(*T0) + (float)(*T0_frac)/(float)(*T0_res); /* save subframe pitch values */ + + return pitch; +} + + +/*---------------------------------------------------------------------* + * Mode2_abs_pit_dec + * + * Decode the absolute pitch + *---------------------------------------------------------------------*/ +void Mode2_abs_pit_dec( + int *T0, /* o: integer pitch lag */ + int *T0_frac, /* o: pitch fraction */ + int *T0_res, /* o: pitch resolution */ + int **pt_indice, /* i/o: pointer to Vector of Q indexes */ + int pit_min, + int pit_fr1, + int pit_fr2, + int pit_res_max +) +{ + int index; + int pit_res_max_half; index = **pt_indice; - move16(); (*pt_indice)++; - pit_res_max_half = shr(pit_res_max,1); + pit_res_max_half = pit_res_max>>1; - tmp1 = i_mult(sub(pit_fr2,pit_min),pit_res_max); - tmp2 = i_mult(sub(pit_fr1,pit_fr2),pit_res_max_half); - IF (sub(index,tmp1) < 0) + if (index < (pit_fr2-pit_min)*pit_res_max) { - assert(pit_res_max > 1 && pit_res_max<=6); - res = pit_res_max; - move16(); - if(sub(pit_res_max,6) == 0) - { - res =shr(res,1); - } + *T0 = pit_min + (index/pit_res_max); - *T0 = mult(index,inv_T0_res[res]); - if(sub(pit_res_max,6) == 0) - { - *T0 =shr(*T0,1); - } - - *T0 = add(pit_min,*T0); - move16(); - - *T0_frac = sub(index,i_mult(sub(*T0,pit_min),pit_res_max)); - move16(); + *T0_frac = index - (*T0 - pit_min)*pit_res_max; *T0_res = pit_res_max; - move16(); } - ELSE IF (index < add(tmp1,tmp2) ) + else if (index < ( (pit_fr2-pit_min)*pit_res_max + (pit_fr1-pit_fr2)*pit_res_max_half) ) { - assert(pit_res_max > 1); + index -= (pit_fr2-pit_min)*pit_res_max; - index = sub(index,tmp1); - *T0 = add(pit_fr2,mult(index,inv_T0_res[pit_res_max_half])); - move16(); - *T0_frac = sub(index, i_mult(sub(*T0,pit_fr2),pit_res_max_half)); - move16(); + *T0 = pit_fr2 + (index/pit_res_max_half); + + *T0_frac = index - (*T0 - pit_fr2)*pit_res_max_half; *T0_res = pit_res_max_half; - move16(); } - ELSE + else { - *T0 = add(index,sub(pit_fr1,add(tmp1,tmp2))); - move16(); + *T0 = index + pit_fr1 - ((pit_fr2-pit_min)*pit_res_max) - ((pit_fr1-pit_fr2)*pit_res_max_half); *T0_frac = 0; - move16(); *T0_res = 1; - move16(); } return; @@ -248,701 +764,22 @@ void Mode2_abs_pit_dec( * Decode delta pitch *---------------------------------------------------------------------*/ void Mode2_delta_pit_dec( - Word16 *T0, /* o: integer pitch lag */ - Word16 *T0_frac, /* o: pitch fraction */ - Word16 T0_res, /* i: pitch resolution */ - Word16 *T0_min, /* i/o: delta search min */ - Word16 *T0_min_frac, /* i: delta search min */ - Word16 **pt_indice /* i/o: pointer to Vector of Q indexes */ + int *T0, /* o: integer pitch lag */ + int *T0_frac, /* o: pitch fraction */ + int T0_res, /* i: pitch resolution */ + int *T0_min, /* i/o: delta search min */ + int *T0_min_frac, /* i: delta search min */ + int **pt_indice /* i/o: pointer to Vector of Q indexes */ ) { - Word16 index, res; - - assert(T0_res > 1 && T0_res<=6); - - res = T0_res; - move16(); - if(sub(T0_res,6) == 0) - { - res =shr(res,1); - } + int index; index = **pt_indice; - move16(); (*pt_indice)++; + *T0 = *T0_min + (index+*T0_min_frac)/T0_res; - *T0 = mult(add(index,*T0_min_frac),inv_T0_res[res]); - if(sub(T0_res,6) == 0) - { - *T0 =shr(*T0,1); - } - - *T0 = add(*T0_min,*T0); - move16(); - - *T0_frac = add(index, sub(*T0_min_frac, i_mult(sub(*T0,*T0_min),T0_res))); - - return; -} - - -/*======================================================================*/ -/* FUNCTION : pit_decode_fx() */ -/*-----------------------------------------------------------------------*/ -/* PURPOSE : calculate pitch value */ -/* */ -/*-----------------------------------------------------------------------*/ -/* INPUT ARGUMENTS : */ -/* _ (Word32) core_brate : Core bitrate Q0 */ -/* _ (Word16) Opt_AMR_WB : flag indicating AMR-WB IO mode Q0 */ -/* _ (Word16) L_frame : length of the frame Q0 */ -/* _ (Word16) i_subfr : length of the frame Q0 */ -/* _ (Word16) coder_type : coding type Q0 */ -/* _ (Word16) L_subfr : subframe length */ -/*-----------------------------------------------------------------------*/ -/* OUTPUT ARGUMENTS : */ -/* _ (Word16 *) T0 : close loop integer pitch */ -/* _ (Word16 *) T0_frac : close loop fractional part of the pitch */ -/* _ (Word16 ) pitch : pitch value Q6 */ -/*-----------------------------------------------------------------------*/ -/* INPUT OUTPUT ARGUMENTS */ -/* _ (Word16 *) T0_min : delta search min for sf 2 & 4 */ -/* _ (Word16 *) T0_max : delta search max for sf 2 & 4 */ -/*-----------------------------------------------------------------------*/ -/* RETURN ARGUMENTS : */ -/* _ (Word16 ) pitch : close loop integer pitch Q6 */ -/*=======================================================================*/ - - -Word16 pit_decode_fx( /* o : floating pitch value */ - Decoder_State_fx *st_fx, /* i/o: decoder state structure */ - const Word32 core_brate, /* i : core bitrate */ - const Word16 Opt_AMR_WB, /* i : flag indicating AMR-WB IO mode */ - const Word16 L_frame, /* i : length of the frame */ - Word16 i_subfr, /* i : subframe index */ - const Word16 coder_type, /* i : coding type */ - Word16 *limit_flag, /* i/o: restrained(0) or extended(1) Q limits */ - Word16 *T0, /* o : close loop integer pitch */ - Word16 *T0_frac, /* o : close loop fractional part of the pitch */ - Word16 *T0_min, /* i/o: delta search min for sf 2 & 4 */ - Word16 *T0_max, /* i/o: delta search max for sf 2 & 4 */ - const Word16 L_subfr /* i : subframe length */ -) -{ - Word16 pitch; /*Q2*/ - Word16 pitch_index, nBits, pit_flag; - - pitch_index = 0; - - /*----------------------------------------------------------------* - * Set pit_flag = 0 for every subframe with absolute pitch search - *----------------------------------------------------------------*/ - pit_flag = i_subfr; - move16(); - - if (sub(i_subfr,PIT_DECODE_2XL_SUBFR) == 0) - { - pit_flag = 0; - move16(); - } - - /*-------------------------------------------------------* - * Retrieve the pitch index - *-------------------------------------------------------*/ - IF( !Opt_AMR_WB ) - { - /*----------------------------------------------------------------* - * pitch Q: Set limit_flag to 0 for restrained limits, and 1 for extended limits - *----------------------------------------------------------------*/ - test(); - test(); - IF( i_subfr == 0 ) - { - *limit_flag = 1; - move16(); - - if( sub(coder_type,VOICED) == 0) - { - *limit_flag = 2; - move16(); /* double-extended limits */ - } - test(); - if( sub(coder_type,GENERIC ) == 0 && L_sub(core_brate,ACELP_7k20) == 0) - { - *limit_flag = 0; - move16(); - } - } - ELSE IF( sub(i_subfr,2*L_SUBFR) == 0 && L_sub(coder_type,GENERIC) == 0 && L_sub(core_brate,ACELP_13k20) <= 0 ) - { - if( sub(*T0,shr(add(PIT_FR1_EXTEND_8b, PIT_MIN),1) ) > 0) - { - *limit_flag = 0; - move16(); - } - } - - /*-------------------------------------------------------* - * Retrieve the number of Q bits - *-------------------------------------------------------*/ - - nBits = 0; - move16(); - IF( sub(coder_type, AUDIO) != 0) - { - /* find the number of bits */ - IF( sub(L_frame,L_FRAME) == 0) - { - nBits = ACB_bits_tbl[BIT_ALLOC_IDX_fx(core_brate, coder_type, i_subfr, 0)]; - move16(); - } - ELSE /* L_frame == L_FRAME16k */ - { - nBits = ACB_bits_16kHz_tbl[BIT_ALLOC_IDX_16KHZ_fx(core_brate, coder_type, i_subfr, 0)]; - move16(); - } - - pitch_index = (Word16)get_next_indice_fx( st_fx, nBits ); - move16(); - } - - /*-------------------------------------------------------* - * Pitch decoding in AUDIO mode - * (both ACELP@12k8 and ACELP@16k cores) - *-------------------------------------------------------*/ - IF( sub(coder_type, AUDIO) == 0) - { - test(); - if( sub(L_subfr,L_FRAME/2) == 0 && i_subfr != 0 ) - { - pit_flag = L_SUBFR; - move16(); - } - if( pit_flag == 0 ) - { - nBits = 10; - move16(); - } - if( pit_flag != 0 ) - { - nBits = 6; - move16(); - } - - pitch_index = (Word16)get_next_indice_fx( st_fx, nBits ); - move16(); - - test(); - test(); - IF( sub(L_subfr,L_FRAME/2) == 0 && i_subfr != 0 && sub(pitch_index,32) >= 0 ) /* safety check in case of bit errors */ - { - pitch_index = shr(pitch_index,1); - move16(); - st_fx->BER_detect = 1; - move16(); - } - - pit_Q_dec_fx( 0, pitch_index, nBits, 4, pit_flag, *limit_flag, T0, T0_frac, T0_min, T0_max, &st_fx->BER_detect ); - } - ELSE IF( sub(coder_type,VOICED) == 0) - { - /*-------------------------------------------------------* - * Pitch decoding in VOICED mode - * (ACELP@12k8 core only) - *-------------------------------------------------------*/ - if( sub(i_subfr,2*L_SUBFR) == 0) - { - pit_flag = i_subfr; - move16(); - } - - pit_Q_dec_fx( 0, pitch_index, nBits, 4, pit_flag, *limit_flag, T0, T0_frac, T0_min, T0_max, &st_fx->BER_detect ); - } - ELSE - { - /*-------------------------------------------------------* - * Pitch decoding in GENERIC mode - * (both ACELP@12k8 and ACELP@16k cores) - *-------------------------------------------------------*/ - IF( sub(L_frame,L_FRAME) == 0) - { - pit_Q_dec_fx( 0, pitch_index, nBits, 8, pit_flag, *limit_flag, T0, T0_frac, T0_min, T0_max, &st_fx->BER_detect ); - } - ELSE - { - pit16k_Q_dec_fx( pitch_index, nBits, *limit_flag, T0, T0_frac, T0_min, T0_max, &st_fx->BER_detect ); - } - } - } - - /*-------------------------------------------------------* - * Pitch decoding in AMR-WB IO mode - *-------------------------------------------------------*/ - - ELSE - { - *limit_flag = 0; - move16(); - test(); - test(); - IF( i_subfr == 0 || ( sub(i_subfr, 2*L_SUBFR) == 0 && L_sub(core_brate,ACELP_8k85) == 0 ) ) - { - nBits = 8; - move16(); - } - ELSE - { - nBits = 5; - move16(); - } - IF( L_sub(core_brate, ACELP_8k85) > 0) - { - nBits = 6; - move16(); - test(); - if( i_subfr == 0 || sub(i_subfr, 2*L_SUBFR) == 0) - { - nBits = 9; - move16(); - } - } - - pitch_index = (Word16)get_next_indice_fx( st_fx, nBits ); - - pit_Q_dec_fx( 1, pitch_index, nBits, 8, pit_flag, *limit_flag, T0, T0_frac, T0_min, T0_max, &st_fx->BER_detect ); - } - - /*-------------------------------------------------------* - * Compute floating pitch output - *-------------------------------------------------------*/ - - pitch = shl(add(shl(*T0,2),*T0_frac),4); /* save subframe pitch values Q6 */ - - return pitch; -} - - -/*----------------------------------------------------------* - * pit_Q_dec_fx() - * - * Decode pitch lag - *----------------------------------------------------------*/ - -void pit_Q_dec_fx( - const Word16 Opt_AMR_WB, /* i : flag indicating AMR-WB IO mode */ - const Word16 pitch_index, /* i : pitch index */ - const Word16 nBits, /* i : # of Q bits */ - const Word16 delta, /* i : Half the CL searched interval */ - const Word16 pit_flag, /* i : absolute(0) or delta(1) pitch Q */ - const Word16 limit_flag, /* i : restrained(0) or extended(1) Q limits */ - Word16 *T0, /* o : integer pitch lag */ - Word16 *T0_frac, /* o : pitch fraction */ - Word16 *T0_min, /* i/o: delta search min */ - Word16 *T0_max /* i/o: delta search max */ - ,Word16 *BER_detect /* o : BER detect flag */ -) -{ - IF( sub(nBits, 10) == 0) /* absolute decoding with 10 bits */ - { - IF( limit_flag == 0 ) - { - *T0 = add(PIT_MIN,shr(pitch_index,2)); - *T0_frac = sub(pitch_index,shl(sub(*T0,PIT_MIN),2)); - } - ELSE IF( sub(limit_flag,1) == 0 ) - { - *T0 = add(PIT_MIN_EXTEND,shr(pitch_index,2)); - *T0_frac = sub(pitch_index ,shl(sub(*T0,PIT_MIN_EXTEND),2)); - } - ELSE /* limit_flag == 2 */ - { - *T0 = add(PIT_MIN_DOUBLEEXTEND,shr(pitch_index,2)); - *T0_frac = sub(pitch_index ,shl(sub(*T0,PIT_MIN_DOUBLEEXTEND),2)); - } - } - ELSE IF( sub(nBits, 9) == 0) /* absolute decoding with 9 bits */ - { - abs_pit_dec_fx( 4, pitch_index, limit_flag, T0, T0_frac ); - - /* find T0_min and T0_max for delta search */ - IF( Opt_AMR_WB ) - { - limit_T0_fx( L_FRAME, delta, pit_flag, 0, *T0, 0, T0_min, T0_max ); /* T0_frac==0 to keep IO with AMR-WB */ - } - } - ELSE IF( sub(nBits, 8) == 0 ) /* absolute decoding with 8 bits */ - { - abs_pit_dec_fx( 2, pitch_index, limit_flag, T0, T0_frac ); - - /* find T0_min and T0_max for delta search */ - IF( Opt_AMR_WB ) - { - limit_T0_fx( L_FRAME, delta, pit_flag, 0, *T0, 0, T0_min, T0_max ); /* T0_frac==0 to keep IO with AMR-WB */ - } - } - ELSE IF( sub(nBits, 6) == 0) /* relative decoding with 6 bits */ - { - delta_pit_dec_fx( 4, pitch_index, T0, T0_frac, *T0_min ); - } - ELSE IF( sub(nBits, 5) == 0 ) /* relative decoding with 5 bits */ - { - IF( sub(delta,8) == 0 ) - { - delta_pit_dec_fx( 2, pitch_index, T0, T0_frac, *T0_min ); - } - ELSE /* delta == 4 */ - { - delta_pit_dec_fx( 4, pitch_index, T0, T0_frac, *T0_min ); - } - } - ELSE /* nBits == 4 */ /* relative decoding with 4 bits */ - { - IF( sub(delta,8) == 0 ) - { - delta_pit_dec_fx( 0, pitch_index, T0, T0_frac, *T0_min ); - } - ELSE /* delta == 4 */ - { - delta_pit_dec_fx( 2, pitch_index, T0, T0_frac, *T0_min ); - } - } - - /* biterror detection mechanism */ - test(); - test(); - IF( sub(add((*T0<<2),*T0_frac),add((PIT_MAX<<2),2)) > 0 && pit_flag == 0 && !Opt_AMR_WB ) - { - *T0 = L_SUBFR; - move16(); - *T0_frac = 0; - move16(); - *BER_detect = 1; - move16(); - } - - IF( !Opt_AMR_WB ) - { - /* find T0_min and T0_max for delta search */ - limit_T0_fx( L_FRAME, delta, L_SUBFR, limit_flag, *T0, *T0_frac, T0_min, T0_max ); - } - - return; -} - -/*-------------------------------------------------* - * pit16k_Q_dec() - * - * pitch decoding @16kHz core - *-------------------------------------------------*/ - -void pit16k_Q_dec_fx( - const Word16 pitch_index, /* i : pitch index */ - const Word16 nBits, /* i : # of Q bits */ - const Word16 limit_flag, /* i : restrained(0) or extended(1) limits */ - Word16 *T0, /* o : integer pitch lag */ - Word16 *T0_frac, /* o : pitch fraction */ - Word16 *T0_min, /* i/o: delta search min */ - Word16 *T0_max /* i/o: delta search max */ - ,Word16 *BER_detect /* o : BER detect flag */ -) -{ - Word16 index; - - IF( sub(nBits,10) == 0) /* absolute decoding with 10 bits */ - { - { - IF( sub(pitch_index,shl((PIT16k_FR2_EXTEND_10b-PIT16k_MIN_EXTEND),2)) < 0 ) - { - *T0 = add(PIT16k_MIN_EXTEND, shr(pitch_index,2)); - move16(); - *T0_frac = sub(pitch_index, shl(sub(*T0, PIT16k_MIN_EXTEND),2)); - move16(); - } - ELSE - { - index = sub(pitch_index, shl((PIT16k_FR2_EXTEND_10b-PIT16k_MIN_EXTEND),2)); - *T0 = add(PIT16k_FR2_EXTEND_10b, shr(index,1)); - *T0_frac = sub(index, shl(sub(*T0, PIT16k_FR2_EXTEND_10b),1)); - /*(*T0_frac) *= 2;*/ - (*T0_frac) = shl(*T0_frac,1); - - } - } - - } - ELSE IF ( sub(nBits,9) == 0 ) /* absolute decoding with 9 bits */ - { - { - IF (sub(pitch_index,(PIT16k_FR2_EXTEND_9b-PIT16k_MIN_EXTEND)*4) < 0) - { - *T0 = add(PIT16k_MIN_EXTEND, shr(pitch_index,2)); - move16(); - *T0_frac = sub(pitch_index, shl(sub(*T0, PIT16k_MIN_EXTEND),2)); - move16(); - } - ELSE IF (sub(pitch_index,( (PIT16k_FR2_EXTEND_9b-PIT16k_MIN_EXTEND)*4 + (PIT16k_FR1_EXTEND_9b-PIT16k_FR2_EXTEND_9b)*2)) < 0 ) - { - index = sub(pitch_index, (PIT16k_FR2_EXTEND_9b-PIT16k_MIN_EXTEND)*4); - *T0 = add(PIT16k_FR2_EXTEND_9b, shr(index,1)); - move16(); - *T0_frac = sub(index, shl(sub(*T0, PIT16k_FR2_EXTEND_9b),1)); - move16(); - (*T0_frac) *= shl((*T0_frac),1); - } - ELSE - { - *T0 = add(pitch_index, PIT16k_FR1_EXTEND_9b - ((PIT16k_FR2_EXTEND_9b-PIT16k_MIN_EXTEND)*4) - ((PIT16k_FR1_EXTEND_9b-PIT16k_FR2_EXTEND_9b)*2)); - move16(); - *T0_frac = 0; - move16(); - } - } - } - ELSE /* nBits == 6 */ /* relative decoding with 6 bits */ - { - delta_pit_dec_fx( 4, pitch_index, T0, T0_frac, *T0_min ); - } - - /* biterror detection mechanism */ - test(); - IF( sub(add((*T0<<2),*T0_frac),(PIT16k_MAX<<2)) > 0 && sub(nBits,9) >= 0 ) - { - *T0 = L_SUBFR; - move16(); - *T0_frac = 0; - move16(); - *BER_detect = 1; - move16(); - } - - /* find T0_min and T0_max for delta search */ - limit_T0_fx( L_FRAME16k, 8, L_SUBFR, limit_flag, *T0, *T0_frac, T0_min, T0_max ); - - return; -} - -/*----------------------------------------------------------* - * abs_pit_dec_fx() - * - * Absolute pitch decoding - *----------------------------------------------------------*/ - -void abs_pit_dec_fx( - const Word16 fr_steps, /* i: fractional resolution steps (0, 2, 4) */ - Word16 pitch_index, /* i: pitch index */ - const Word16 limit_flag, /* i : restrained(0) or extended(1) limits */ - Word16 *T0, /* o: integer pitch lag */ - Word16 *T0_frac /* o: pitch fraction */ -) -{ - Word16 temp; - - IF( limit_flag == 0 ) - { - IF(sub(fr_steps,2) == 0) - { - IF(sub(pitch_index,PIT_FR1_8b_MINUS_PIT_MIN_X2) < 0) - { - *T0= add(PIT_MIN,shr(pitch_index,1)); - move16(); - temp = shl(sub(*T0,PIT_MIN),1); - *T0_frac = shl(sub(pitch_index,temp),1); - move16(); - } - ELSE - { - *T0 = add(pitch_index,PIT_FR1_8b_MINUS_PIT_FR1_8b_MINUS_PIT_MIN_X2); - move16(); - *T0_frac = 0; - move16(); - } - } - ELSE IF( sub(fr_steps,4) == 0 ) - { - IF(sub(pitch_index,PIT_FR2_9b_MINUS_PIT_MIN_X4) < 0) - { - *T0= add(PIT_MIN,shr(pitch_index,2)); - move16(); - temp = shl(sub(*T0,PIT_MIN),2); - *T0_frac = sub(pitch_index,temp); - move16(); - } - ELSE IF (sub(pitch_index,PIT_DECODE_1) < 0) /*( (PIT_FR2_9b-PIT_MIN)*4 + (PIT_FR1_9b-PIT_FR2_9b)*2) = 440*/ - { - pitch_index = sub(pitch_index,PIT_DECODE_2); /*pitch_index -= (PIT_FR2_9b-PIT_MIN)*4(=376);*/ - *T0 = add(PIT_FR2_9b,shr(pitch_index,1)); - move16(); - temp = shl(sub(*T0,PIT_FR2_9b),1); - *T0_frac = shl(sub(pitch_index,temp),1); - move16(); - } - ELSE - { - *T0 = add(pitch_index,PIT_DECODE_3); - move16(); - *T0_frac = 0; - move16(); - } - } - ELSE /* fr_steps == 0 */ - { - /* not used in the codec */ - } - } - ELSE IF( sub(limit_flag, 1) == 0 ) /* extended Q range */ - { - IF( sub(fr_steps,2) == 0 ) - { - IF( sub(pitch_index, PIT_FR1_EXT8b_MINUS_PIT_MIN_EXT_X2) < 0 ) - { - *T0 = add(PIT_MIN_EXTEND, shr(pitch_index,1)); - move16(); - *T0_frac = sub(pitch_index, shl(sub(*T0, PIT_MIN_EXTEND),1)); - *T0_frac = shl(*T0_frac, 1); - move16(); - } - ELSE - { - *T0 = add(pitch_index, sub(PIT_FR1_EXTEND_8b, PIT_FR1_EXT8b_MINUS_PIT_MIN_EXT_X2)); - move16(); - *T0_frac = 0; - move16(); - } - } - ELSE IF( sub(fr_steps,4) == 0 ) - { - IF( sub(pitch_index, PIT_FR2_EXT9b_MINUS_PIT_MIN_EXT_X4) < 0 ) - { - /**T0 = PIT_MIN_EXTEND + (pitch_index/4);*/ - *T0 = add(PIT_MIN_EXTEND, shr(pitch_index,2)); - move16(); - /**T0_frac = pitch_index - (*T0 - PIT_MIN_EXTEND)*4;*/ - *T0_frac = sub(pitch_index, shl(sub(*T0, PIT_MIN_EXTEND),2)); - move16(); - } - ELSE IF( sub(pitch_index,add(PIT_FR2_EXT9b_MINUS_PIT_MIN_EXT_X4, PIT_FR1_EXT9b_MINUS_PIT_FR2_EXT9b_X2)) < 0 ) - { - /*pitch_index -= (PIT_FR2_EXTEND_9b-PIT_MIN_EXTEND)*4;*/ - pitch_index = sub(pitch_index, PIT_FR2_EXT9b_MINUS_PIT_MIN_EXT_X4); - *T0 = add(PIT_FR2_EXTEND_9b, shr(pitch_index,1)); - *T0_frac = sub(pitch_index, shl(sub(*T0, PIT_FR2_EXTEND_9b),1)); - (*T0_frac) = shl(*T0_frac,1); - move16(); - } - ELSE - { - /**T0 = pitch_index + PIT_FR1_EXTEND_9b - ((PIT_FR2_EXTEND_9b-PIT_MIN_EXTEND)*4) - ((PIT_FR1_EXTEND_9b-PIT_FR2_EXTEND_9b)*2);move16();*/ - *T0 = add(pitch_index, PIT_DECODE_7); - move16(); - *T0_frac = 0; - move16(); - } - } - ELSE /* fr_steps == 0 */ - { - /* not used in the codec */ - } - } - ELSE /* limit_flag == 2 */ - { - IF( sub(fr_steps,2) == 0 ) - { - IF( sub(pitch_index,PIT_FR1_DEXT8b_MINUS_PIT_MIN_DEXT_X2) < 0) - { - *T0 = add(PIT_MIN_DOUBLEEXTEND, shr(pitch_index,1)); - move16(); - *T0_frac = sub(pitch_index, shl(sub(*T0, PIT_MIN_DOUBLEEXTEND),1)); - move16(); - *T0_frac = shl(*T0_frac,1); - move16(); - } - ELSE - { - /**T0 = pitch_index + PIT_FR1_DOUBLEEXTEND_8b - ((PIT_FR1_DOUBLEEXTEND_8b-PIT_MIN_DOUBLEEXTEND)*2);move16();*/ - *T0 = add(pitch_index, PIT_DECODE_8); - move16(); - *T0_frac = 0; - move16(); - } - } - ELSE IF( sub(fr_steps,4) == 0 ) - { - IF( sub(pitch_index, PIT_FR2_DEXT9b_MINUS_PIT_MIN_DEXT_X4) < 0) - { - *T0 = add(PIT_MIN_DOUBLEEXTEND, shr(pitch_index,2)); - move16(); - *T0_frac = sub(pitch_index, shl(sub(*T0, PIT_MIN_DOUBLEEXTEND),2)); - move16(); - } - ELSE IF( sub(pitch_index,PIT_DECODE_9) < 0) - { - /*pitch_index -= (PIT_FR2_DOUBLEEXTEND_9b-PIT_MIN_DOUBLEEXTEND)*4;move16();*/ - pitch_index = sub(pitch_index , PIT_FR2_DEXT9b_MINUS_PIT_MIN_DEXT_X4); - move16(); - *T0 = add(PIT_FR2_DOUBLEEXTEND_9b, shr(pitch_index,1)); - move16(); - *T0_frac = sub(pitch_index, shl(sub(*T0, PIT_FR2_DOUBLEEXTEND_9b),1)); - move16(); - (*T0_frac) = shl(*T0_frac,1); - move16(); - } - ELSE - { - *T0 = add(pitch_index, PIT_DECODE_10); - move16(); - *T0_frac = 0; - move16(); - } - } - ELSE /* fr_steps == 0 */ - { - /* not used in the codec */ - } - } - - return; -} - -/*----------------------------------------------------------* - * delta_pit_dec_fx() - * - * Delta pitch decoding - *----------------------------------------------------------*/ - -void delta_pit_dec_fx( - const Word16 fr_steps, /* i : fractional resolution steps (0, 2, 4) */ - const Word16 pitch_index, /* i : pitch index */ - Word16 *T0, /* o : integer pitch lag */ - Word16 *T0_frac, /* o : pitch fraction */ - const Word16 T0_min /* i : delta search min */ -) -{ - - Word16 temp; - IF( fr_steps == 0 ) - { - *T0 = add(T0_min,pitch_index); - move16(); - *T0_frac = 0; - move16(); - } - ELSE IF( sub(fr_steps,2) == 0 ) - { - *T0 = add(T0_min,shr(pitch_index,1)); - move16(); - temp = shl(sub(*T0,T0_min),1); - *T0_frac = shl(sub(pitch_index,temp),1); - move16(); - } - ELSE IF ( sub(fr_steps,4) == 0 ) - { - *T0 = add(T0_min,shr(pitch_index,2)); - move16(); - temp = shl(sub(*T0,T0_min),2); - *T0_frac = sub(pitch_index,temp); - move16(); - } + *T0_frac = index+*T0_min_frac - (*T0 - *T0_min)*T0_res; return; } diff --git a/src/libs/libevs/lib_dec/pitch_extr.cpp b/src/libs/libevs/lib_dec/pitch_extr.cpp old mode 100755 new mode 100644 index e11a55cc..b165a679 --- a/src/libs/libevs/lib_dec/pitch_extr.cpp +++ b/src/libs/libevs/lib_dec/pitch_extr.cpp @@ -1,176 +1,147 @@ /*==================================================================================== - EVS Codec 3GPP TS26.442 Apr 03, 2018. Version 12.11.0 / 13.6.0 / 14.2.0 + EVS Codec 3GPP TS26.443 Nov 13, 2018. Version 12.11.0 / 13.7.0 / 14.3.0 / 15.1.0 ====================================================================================*/ - -/*This file is up to date with trunk rev. 36531*/ - #include #include +#include #include -#include "cnst_fx.h" -#include "prot_fx.h" -#include "basop_util.h" -#include "stl.h" +#include "cnst.h" +#include "prot.h" #include "options.h" +#include "basop_util.h" -/*-------------------------------------------------------------------* - * - num x 32768 - * ------------------- Q15 - * PIT_MAX x Fact - *-------------------------------------------------------------------*/ - -#define PIT_MAX_DIV_8k(num, fact) ( -(num * 32768) / (PIT_MAX_12k8 * fact) ) -#define PIT_MAX_DIV_12k8(num, fact) ( -(num * 32768) / (PIT_MAX_12k8 * fact) ) -#define PIT_MAX_DIV_16k(num, fact) ( -(num * 32768) / (PIT_MAX_16k * fact) ) - /*-----------------------------------------------------------------* * Pitch prediction for frame erasure using linear fitting * *-----------------------------------------------------------------*/ -/*port is up to date with trunk 38840*/ void pitch_pred_linear_fit( - const Word16 /*short*/ bfi_cnt, /* i: bfi counter */ /*Q0 */ - const Word16 /*short*/ last_good, /* i: last classification type */ /*Q0 */ - Word32 /*float*/ *old_pitch_buf, /* i: pitch lag buffer */ /*Q16*/ - Word32 /*float*/ *old_fpitch, /* i: */ /*Q16*/ - Word32 /*float*/ *T0_out, /* o: estimated close loop pitch */ /*Q16*/ - Word16 /* int*/ pit_min, /* i: Minimum pitch lag */ /*Q0 */ - Word16 /* int*/ pit_max, /* i: Maximum pitch lag */ /*Q0 */ - Word16 /*float*/ *mem_pitch_gain, /* i: pitch gain [0] is the most recent subfr gain */ /*Q14*/ - Word16 /* int*/ limitation, - Word8 /*short*/ plc_use_future_lag, /* i: */ /*Q0 */ - Word16 /*short*/ *extrapolationFailed,/* o: flag if extrap decides not to change the pitch */ /*Q0 */ - Word16 nb_subfr /* i: number of ACELP subframes*/ + const short nbLostCmpt, /* i: bfi counter */ + const short last_good, /* i: last classification type */ + float *old_pitch_buf, /* i: pitch lag buffer */ + float *old_fpitch, /* i: */ + float *T0_out, /* o: estimated close loop pitch */ + int pit_min, /* i: Minimum pitch lag */ + int pit_max, /* i: Maximum pitch lag */ + float *mem_pitch_gain, /* i: pitch gain [0] is the most recent subfr gain */ + int limitation, + short plc_use_future_lag, /* i: */ + short *extrapolationFailed,/* o: flag if extrap decides not to change the pitch */ + int nb_subfr /* i: number of ACELP subframes */ ) { - Word32 pit, a, b, pita, pitb; - Word16 sum0; - Word32 T0; - Word32 mdy, dy[5]; - Word16 lcor; - Word16 imax, i; - Word16 pg[8]; /* local buffer for pitch gain*/ - Word32 ml[8]; /* local buffer for mem_lag*/ - Word16 const timeWeight[5] = {20480/*1.25f Q14*/, 18432/*1.125f Q14*/, 16384/*1.f Q14*/, 14336/*0.875f Q14*/, 12288/*.75f Q14*/}; /*Q14*/ - Word16 no_subfr_pred; - Word16 a1, a2, a3, a4, a5, tmpa, tmpb, b1, b2, b3, b4, b5; - Word16 a_e, b_e, sum0_q; - Word32 mem_lag[2*NB_SUBFR16k+2]; + float T0 = 0; + float mdy, dy[5], ftmp; + short lcor = 5; + short imax, i; + float pg[8], ml[8]; /* local buffer for pitch gain and mem_lag*/ + short no_subfr_pred; + float mem_lag[2*NB_SUBFR16k+2]; - /* Inverse the order the pitch lag memory */ - IF ( sub(nb_subfr, 4) == 0 ) + if( nb_subfr == 4 ) { - FOR (i = 0; i < 2*NB_SUBFR+2; i++) + for (i=0; i<2*NB_SUBFR+2; i++) { mem_lag[i] = old_pitch_buf[2*NB_SUBFR+1 - i]; - move32(); } } - ELSE /* L_frame == L_FRAME16k */ + else /* L_frame == L_FRAME16k */ { - FOR (i = 0; i < 2*NB_SUBFR16k+2; i++) + for (i=0; i<2*NB_SUBFR16k+2; i++) { mem_lag[i] = old_pitch_buf[2*NB_SUBFR16k+1 - i]; - move32(); } } - move16(); - move16(); - move16(); - move16(); - move16(); /*timeweight*/ - IF ( 0 > sub(pit_max,extract_h(*old_fpitch)) ) + if( (int) *old_fpitch > pit_max ) { *extrapolationFailed = 1; *T0_out = pit_max; + printf("\n WARNING: (int)*old_fpitch > pit_max : old_fpitch = %f, pit_max = %i \n\n",*old_fpitch, pit_max ); return; } - move16(); - lcor = 5; - T0 = L_deposit_l(0); - - test(); - test(); - IF (sub(bfi_cnt , 1) == 0 && sub(last_good , UNVOICED_TRANSITION) >= 0 && sub(last_good , ONSET) < 0) + if (nbLostCmpt == 1 && last_good >= UNVOICED_TRANSITION && last_good < ONSET) { - move16(); - no_subfr_pred = 4; - if (plc_use_future_lag!=0) + if (plc_use_future_lag) { - move16(); no_subfr_pred = 2; } + else + { + no_subfr_pred = 4; + } /* copy to local buffers, depending on availability of info about future subframes */ - Copy(mem_pitch_gain+no_subfr_pred-2,pg,8); - Copy32(mem_lag+no_subfr_pred-2,ml,8); + mvr2r(mem_pitch_gain+no_subfr_pred-2,pg,8); + mvr2r(mem_lag+no_subfr_pred-2,ml,8); - mdy = L_deposit_l(0); - - FOR (i = (sub(lcor,1)); i >= 0; i--) + mdy = 0.0f; + for (i = (lcor-1); i >= 0; i--) { - move32(); - dy[i] = L_sub(ml[i] , ml[i+1]); - mdy = L_add(mdy , dy[i]); + dy[i] = (ml[i] - ml[i+1]); + mdy += dy[i]; } /*---------------------------------------------------* * remove maximum variation *---------------------------------------------------*/ - move16(); + ftmp = (float)fabs(dy[0]); imax = 0; - pita = L_abs(dy[0]); - FOR (i = 1; i Q9*/),mult_r(pg[3],16384/*Q12->Q11*/))/*Q5*/; - a4 = mac_r(L_mac(L_mult( mult_r(-12*2048,pg[0])/*Q8*/,pg[3] /*Q12*/)/*Q5+16*/,mult_r(-6*2048,pg[1])/*Q8*/,pg[3]/*Q12*/)/*Q5+16*/,mult_r(-2*2048,pg[2])/*Q8*/,pg[3]/*Q12*/)/*Q5*/; - a3 = mac_r(L_mac(L_mult( mult_r(-8*2048,pg[0]) /*Q8*/,pg[2]),mult_r(-3*2048,pg[1])/*Q8*/,pg[2]),mult_r(pg[2],4096/*Q12->Q9*/),mult_r(pg[3],16384/*12->Q11*/));/*Q5*/ - a2 = mac_r(L_mac(L_mult( mult_r(2*2048,pg[1]) /*Q8*/,pg[2])/*Q5+16*/,mult_r(2*2048,pg[1])/*Q8*/,pg[3])/*Q5+16*/,mult_r(-4*2048,pg[0])/*Q8*/,pg[1]/*Q12*/)/*Q5*/; - a1 = mac_r(L_mac(L_mult( mult_r(3*2048,pg[0]) /*Q8*/,pg[1])/*Q5+16*/,mult_r(4*2048,pg[0])/*Q8*/,pg[2]/*Q12*/)/*Q5+16*/,mult_r(3*2048,pg[0])/*Q8*/,pg[3]/*Q12*/)/*Q5*/; + a5 = mac_r(L_mac(L_mac(L_mult(mult_r(-32768,pg_fx[0]) /*Q8*/,pg_fx[4])/*Q5+16*/, mult_r(-9*2048,pg_fx[1])/*Q8*/ , pg_fx[4]/*Q12*/ )/*Q5+16*/ ,mult_r(-4*2048,pg_fx[2])/*Q8*/, pg_fx[4]/*Q12*/)/*Q5+16*/,mult_r(pg_fx[4],-4096/*Q12->Q9*/),mult_r(pg_fx[3],16384/*Q12->Q11*/))/*Q5*/; + a4 = mac_r(L_mac(L_mult( mult_r(-12*2048,pg_fx[0])/*Q8*/,pg_fx[3] /*Q12*/)/*Q5+16*/,mult_r(-6*2048,pg_fx[1])/*Q8*/,pg_fx[3]/*Q12*/)/*Q5+16*/,mult_r(-2*2048,pg_fx[2])/*Q8*/,pg_fx[3]/*Q12*/)/*Q5*/; + a3 = mac_r(L_mac(L_mult( mult_r(-8*2048,pg_fx[0]) /*Q8*/,pg_fx[2]),mult_r(-3*2048,pg_fx[1])/*Q8*/,pg_fx[2]),mult_r(pg_fx[2],4096/*Q12->Q9*/),mult_r(pg_fx[3],16384/*12->Q11*/));/*Q5*/ + a2 = mac_r(L_mac(L_mult( mult_r(2*2048,pg_fx[1]) /*Q8*/,pg_fx[2])/*Q5+16*/,mult_r(2*2048,pg_fx[1])/*Q8*/,pg_fx[3])/*Q5+16*/,mult_r(-4*2048,pg_fx[0])/*Q8*/,pg_fx[1]/*Q12*/)/*Q5*/; + a1 = mac_r(L_mac(L_mult( mult_r(3*2048,pg_fx[0]) /*Q8*/,pg_fx[1])/*Q5+16*/,mult_r(4*2048,pg_fx[0])/*Q8*/,pg_fx[2]/*Q12*/)/*Q5+16*/,mult_r(3*2048,pg_fx[0])/*Q8*/,pg_fx[3]/*Q12*/)/*Q5*/; a = L_mac(L_mac(L_mac(L_mac(L_mult(a1 - , round_fx(L_shl(ml[0],4)))/*Q4*/ - , round_fx(L_shl(ml[1],4)) /*Q4*/, a2) - , round_fx(L_shl(ml[2],4)) /*Q4*/, a3) - , round_fx(L_shl(ml[3],4)) /*Q4*/, a4) - , round_fx(L_shl(ml[4],4)) /*Q4*/, a5); /*Q-6+16 = Q10*/ + , round_fx(L_shl(ml_fx[0],4)))/*Q4*/ + , round_fx(L_shl(ml_fx[1],4)) /*Q4*/, a2) + , round_fx(L_shl(ml_fx[2],4)) /*Q4*/, a3) + , round_fx(L_shl(ml_fx[3],4)) /*Q4*/, a4) + , round_fx(L_shl(ml_fx[4],4)) /*Q4*/, a5); /*Q-6+16 = Q10*/ a_e = norm_l(a); a = L_shl(a, a_e); - a1 = BASOP_Util_Divide3216_Scale(L_negate(a), /* Numerator */ /*scalefactor 21*/ - sum0, /* Denominator*/ /*scalefactor 10*/ - &tmpa); /* scalefactor for result */ + a1 = BASOP_Util_Divide3216_Scale( L_negate(a), /* Numerator */ /*scalefactor 21*/ + sum0, /* Denominator*/ /*scalefactor 10*/ + &tmpa); /* scalefactor for result */ /* Float: - b=(( pg[1]+2*pg[2]+3*pg[3]+4*pg[4])*pg[0] *//*b1*//* - *ml[0] + - (( pg[2]+2*pg[3]+3*pg[4])*pg[1]-pg[1]*pg[0]) *//*b2*//* - *ml[1] + - ( -2*pg[2]*pg[0]-pg[2]*pg[1]+(pg[3]+2*pg[4])*pg[2]) *//*b3*//* - *ml[2] + - ( -3*pg[3]*pg[0]-2*pg[3]*pg[1]-pg[3]*pg[2]+pg[4]*pg[3]) *//*b4*//* - *ml[3] + - ( -4*pg[4]*pg[0]-3*pg[4]*pg[1]-2*pg[4]*pg[2]-pg[4]*pg[3]) *//*b5*//* - *ml[4] )/sum0; MAC(22);MULT(9);DIV(1);*/ + b=(( pg[1]+2*pg[2]+3*pg[3]+4*pg[4])*pg[0] *//*b1*//* +*ml[0] + +(( pg[2]+2*pg[3]+3*pg[4])*pg[1]-pg[1]*pg[0]) *//*b2*//* +*ml[1] + +( -2*pg[2]*pg[0]-pg[2]*pg[1]+(pg[3]+2*pg[4])*pg[2]) *//*b3*//* +*ml[2] + +( -3*pg[3]*pg[0]-2*pg[3]*pg[1]-pg[3]*pg[2]+pg[4]*pg[3]) *//*b4*//* +*ml[3] + +( -4*pg[4]*pg[0]-3*pg[4]*pg[1]-2*pg[4]*pg[2]-pg[4]*pg[3]) *//*b5*//* +*ml[4] )/sum0; */ /*magic numbers in Q13 if not DIRECTLY marked otherwise*/ - b1 = mac_r(L_mac(L_mac(L_mult(mult_r(pg[1],pg[0]),32768/4)/*Q7+16*/,mult_r(2*8192,pg[0])/*Q10*/,pg[2]/*Q12*/)/*Q7+16*/,mult_r(3*8192,pg[0])/*Q10*/,pg[3]/*Q12*/)/*Q7+16*/, /*mult_r(4*8192,pg[0])*/ pg[0]/*Q10*/,pg[4]/*Q12*/)/*Q7*/; - b2 = mac_r(L_mac(L_mac(L_mult(mult_r(pg[2],pg[1]),32768/4)/*Q7+16*/,mult_r(2*8192,pg[1]),pg[3]),mult_r(3*8192,pg[1]),pg[4])/*Q7+16*/,mult_r(pg[1],-32768/2/*Q12->Q12*/),mult_r(pg[0],32768/2/*Q12->Q10*/))/*Q7*/; - b3 = mac_r(L_mac(L_mac(L_mult(mult_r(-2*8192,pg[0]),pg[2])/*Q7+16*/,mult_r(pg[2],-32768/2),mult_r(pg[1],32768/2)),mult_r(pg[3],32768/2),mult_r(pg[2],32768/2))/*Q5+16*/,mult_r(2*8192,pg[2]),pg[4])/*Q7*/; - b4 = mac_r(L_mac(L_mac(L_mult(mult_r(-3*8192,pg[0]),pg[3]),mult_r(-2*8192,pg[1]),pg[3]),mult_r(-32768/2,pg[3]),mult_r(32768/2,pg[2])),mult_r(32768/2,pg[4]),mult_r(32768/2,pg[3]));/*Q7*/ - b5 = mac_r(L_mac(L_mac(L_mult(mult_r(-32768/*(-4*8192)*/,pg[0]),pg[4]),mult_r(-3*8192,pg[1]),pg[4]),mult_r(-2*8192,pg[2]),pg[4]),mult_r(-32768/2,pg[4]),mult_r(32768/2,pg[3]))/*Q7*/; + b1 = mac_r(L_mac(L_mac(L_mult(mult_r(pg_fx[1],pg_fx[0]),32768/4)/*Q7+16*/,mult_r(2*8192,pg_fx[0])/*Q10*/,pg_fx[2]/*Q12*/)/*Q7+16*/,mult_r(3*8192,pg_fx[0])/*Q10*/,pg_fx[3]/*Q12*/)/*Q7+16*/, /*mult_r(4*8192,pg_fx[0])*/ pg_fx[0]/*Q10*/,pg_fx[4]/*Q12*/)/*Q7*/; + b2 = mac_r(L_mac(L_mac(L_mult(mult_r(pg_fx[2],pg_fx[1]),32768/4)/*Q7+16*/,mult_r(2*8192,pg_fx[1]),pg_fx[3]),mult_r(3*8192,pg_fx[1]),pg_fx[4])/*Q7+16*/,mult_r(pg_fx[1],-32768/2/*Q12->Q12*/),mult_r(pg_fx[0],32768/2/*Q12->Q10*/))/*Q7*/; + b3 = mac_r(L_mac(L_mac(L_mult(mult_r(-2*8192,pg_fx[0]),pg_fx[2])/*Q7+16*/,mult_r(pg_fx[2],-32768/2),mult_r(pg_fx[1],32768/2)),mult_r(pg_fx[3],32768/2),mult_r(pg_fx[2],32768/2))/*Q5+16*/,mult_r(2*8192,pg_fx[2]),pg_fx[4])/*Q7*/; + b4 = mac_r(L_mac(L_mac(L_mult(mult_r(-3*8192,pg_fx[0]),pg_fx[3]),mult_r(-2*8192,pg_fx[1]),pg_fx[3]),mult_r(-32768/2,pg_fx[3]),mult_r(32768/2,pg_fx[2])),mult_r(32768/2,pg_fx[4]),mult_r(32768/2,pg_fx[3]));/*Q7*/ + b5 = mac_r(L_mac(L_mac(L_mult(mult_r(-32768/*(-4*8192)*/,pg_fx[0]),pg_fx[4]),mult_r(-3*8192,pg_fx[1]),pg_fx[4]),mult_r(-2*8192,pg_fx[2]),pg_fx[4]),mult_r(-32768/2,pg_fx[4]),mult_r(32768/2,pg_fx[3]))/*Q7*/; b = L_mac(L_mac(L_mac(L_mac(L_mult(b1 - , round_fx(L_shl(ml[0],4)))/*Q4*/ - , round_fx(L_shl(ml[1],4)) /*Q4*/, b2) - , round_fx(L_shl(ml[2],4)) /*Q4*/, b3) - , round_fx(L_shl(ml[3],4)) /*Q4*/, b4) - , round_fx(L_shl(ml[4],4)) /*Q4*/, b5); /*Q-4+16 = Q12*/ + , round_fx(L_shl(ml_fx[0],4)))/*Q4*/ + , round_fx(L_shl(ml_fx[1],4)) /*Q4*/, b2) + , round_fx(L_shl(ml_fx[2],4)) /*Q4*/, b3) + , round_fx(L_shl(ml_fx[3],4)) /*Q4*/, b4) + , round_fx(L_shl(ml_fx[4],4)) /*Q4*/, b5); /*Q-4+16 = Q12*/ /*predict pitch for 4th future subframe*/ b_e = norm_l(b); b = L_shl(b, b_e); b1 = BASOP_Util_Divide3216_Scale(b, /* Numerator */ /*scalefactor 19*/ - sum0, /* Denominator*/ /*scalefactor 10*/ - &tmpb); /* scalefactor for result*/ + sum0, /* Denominator*/ /*scalefactor 10*/ + &tmpb); /* scalefactor for result*/ /*pit = a + b * ((float)no_subfr_pred + (float)nb_subfr);*/ pita = L_shl( L_deposit_l(a1),add(add(sum0_q, 16-10+1),sub(tmpa, a_e)))/*Q16*/; pitb = L_shl_r(L_mult(b1/*Q15*/,add(no_subfr_pred,nb_subfr)/*Q0*/ ),add(add(sum0_q, 16-12),sub(tmpb, b_e))); pit = L_add( pita , pitb ); /*Q16*/ - T0 = L_add(pit, 0); + /* convert pitch back to float precision */ + T0 = (float)pit*pow(2.f, -31+15); /*limit pitch to allowed range*/ + if( T0 > pit_max ) + { + T0 = (float)pit_max; + } - T0 = L_min(L_deposit_h(pit_max),T0); - T0 = L_max(L_deposit_h(pit_min),T0); + if( T0 < pit_min ) + { + T0 = (float)pit_min; + } - move16(); *extrapolationFailed = 0; } - ELSE + else { - T0 = L_deposit_l(0); + T0 = 0; *extrapolationFailed = 1; - move16(); } } - ELSE + else { - - T0 = L_deposit_l(0); - move16(); + T0 = 0; *extrapolationFailed = 1; } } - ELSE + else { - T0 = L_add(*old_fpitch, 0); - move16(); + T0 = *old_fpitch; *extrapolationFailed = 1; } - move32(); + *T0_out = T0; return; } -/* up to date with rev 8158*/ void get_subframe_pitch( - Word16 nSubframes, /* i: number of subframes */ /* Q0 */ - Word32 pitchStart, /* i: starting pitch lag (in subframe -1) */ /*15Q16*/ - Word32 pitchEnd, /* i: ending pitch lag (in subframe nSubframes-1) */ /*15Q16*/ - Word32 *pitchBuf /* o: interpolated pitch lag per subframe */ /*15Q16*/ + int nSubframes, /* i: number of subframes */ + float pitchStart, /* i: starting pitch lag (in subframe -1) */ + float pitchEnd, /* i: ending pitch lag (in subframe nSubframes-1) */ + float *pitchBuf /* o: interpolated pitch lag per subframe */ ) { - Word16 i,s; - Word32 pitchDelta; + int i; + float pitchDelta; assert((nSubframes > 0) && (pitchBuf != NULL) && (pitchStart >= 0) && (pitchEnd > 0)); - /*pitchDelta = (pitchEnd - pitchStart)/nSubframes;*/ - pitchDelta = L_deposit_l(BASOP_Util_Divide3216_Scale(L_sub(pitchEnd,pitchStart),nSubframes, &s));/*Q15*/ - pitchDelta = L_shl(pitchDelta,add(s,1));/*Q16*/ - pitchBuf[0] = L_add(pitchStart,pitchDelta); - FOR (i = 1; i < nSubframes; i++) + pitchDelta = (pitchEnd - pitchStart)/nSubframes; + pitchBuf[0] = pitchStart+pitchDelta; + for (i = 1; i < nSubframes; i++) { - pitchBuf[i] = L_add(pitchBuf[i-1] , pitchDelta); - move32(); + pitchBuf[i] = pitchBuf[i-1] + pitchDelta; } -} + return; +} diff --git a/src/libs/libevs/lib_dec/post_dec.cpp b/src/libs/libevs/lib_dec/post_dec.cpp old mode 100755 new mode 100644 index 89f2edac..d92c760a --- a/src/libs/libevs/lib_dec/post_dec.cpp +++ b/src/libs/libevs/lib_dec/post_dec.cpp @@ -1,25 +1,24 @@ /*==================================================================================== - EVS Codec 3GPP TS26.442 Apr 03, 2018. Version 12.11.0 / 13.6.0 / 14.2.0 + EVS Codec 3GPP TS26.443 Nov 13, 2018. Version 12.11.0 / 13.7.0 / 14.3.0 / 15.1.0 ====================================================================================*/ - - #include #include #include +#include #include "options.h" -#include "prot_fx.h" -#include "basop_util.h" -#include "stl.h" +#include "prot.h" +#include "rom_com.h" /*---------------------------------------------------------------------* * Function prototypes *---------------------------------------------------------------------*/ -static void bass_pf_1sf_delay( Word16 *syn, Word16 *T_sf, Word16 *gainT_sf, Word16 l_frame, - Word16 l_subfr, Word16 *bpf_noise_buf, Word16 *gain_factor_param, - Word8 disable_bpf, Word32 *lp_error_ener, Word32 *mem_error ); +static void bass_pf_1sf_delay( float *syn, const int *T_sf, const float *gainT_sf, const short l_frame, + const short l_subfr, float *bpf_noise_buf, int *gain_factor_param, + const short disable_bpf, float *mem_deemph_err, float *lp_ener ); + /*---------------------------------------------------------------------* * post_decoder() @@ -28,150 +27,124 @@ static void bass_pf_1sf_delay( Word16 *syn, Word16 *T_sf, Word16 *gainT_sf, Word *---------------------------------------------------------------------*/ void post_decoder( - Decoder_State_fx *st, - Word16 coder_type, - Word16 synth_buf[], - Word16 pit_gain[], - Word16 pitch[], - Word16 signal_out[], - Word16 *bpf_noise_buf + Decoder_State *st, /* i/o: decoder memory state pointer */ + const short coder_type, /* i : coder type */ + float synth_buf[], + const float pit_gain[], + const int pitch[], + float signal_out[], + float *bpf_noise_buf ) { - Word16 L_frame, nb_subfr; - Word16 *synth, *synth2; - Word16 pfstat_on_previous; - Word16 pitch_gain_adjust[NB_SUBFR16k]; - Word16 tmp, tmp_noise; - Word16 synth2_pe[L_FRAME_MAX]; - Word16 synth_buf2[PIT_MAX_16k+1+L_FRAME_MAX+M]; - Word32 bitrate; - Word8 tmp8; + short L_frame, nb_subfr, i; + float *synth2; + float *synth; + short pfstat_on_previous; + int pitch_gain_adjust[NB_SUBFR16k]; + float synth_buf2[NBPSF_PIT_MAX+L_FRAME_MAX+M]; + long bitrate; + float A[M+1]; + float pitch_buf[NB_SUBFR16k]; + float tmp; + short L_subfr; - - L_frame = st->L_frame_fx; - move16(); + L_frame = st->L_frame; nb_subfr = st->nb_subfr; - move16(); + bitrate = (st->core_brate > SID_2k40 )?st->total_brate:st->last_active_brate; pfstat_on_previous = st->pfstat.on; - move16(); st->pfstat.on = 0; - move16(); - - bitrate = L_add(st->total_brate_fx, 0); - if(st->core_brate_fx <= SID_2k40) - { - bitrate = L_add(st->last_active_brate_fx, 0); - } - - - /*Adapt Bpf: copy old and current adapt bpf parameters*/ - set16_fx(pitch_gain_adjust, st->bpf_gain_param, nb_subfr); - + set_i( pitch_gain_adjust, st->bpf_gain_param, nb_subfr ); synth = synth_buf + st->old_synth_len; synth2 = synth_buf2 + NBPSF_PIT_MAX; - Copy( st->pst_old_syn_fx, synth_buf2, NBPSF_PIT_MAX ); + mvr2r( st->pst_old_syn, synth_buf2, NBPSF_PIT_MAX ); - IF ( st->tcxonly != 0 ) + if( st->tcxonly ) { - Copy( synth, synth2, L_frame ); - IF ( pfstat_on_previous ) + /* High bitrates (48kbps and above), high sampling rates (25.6kHz and above) */ + + mvr2r( synth, synth2, L_frame ); + + if( pfstat_on_previous ) { - Copy( st->pfstat.mem_pf_in+L_SYN_MEM-M, synth-M, M ); - Residu3_fx ( st->old_Aq_12_8_fx, synth, synth_buf, L_SUBFR, 1 ); - E_UTIL_synthesis ( 1, st->old_Aq_12_8_fx, synth_buf, synth2, L_SUBFR, st->pfstat.mem_stp+L_SYN_MEM-M, 0, M ); - scale_st ( synth, synth2, &st->pfstat.gain_prec, L_SUBFR ); - blend_subfr2(synth2+L_SUBFR/2, synth+L_SUBFR/2, synth2+L_SUBFR/2); + /* Past frame was low-bitrate with formant post-filter */ + lsp2a_stab( st->lsp_old, A, M ); + mvr2r( st->pfstat.mem_pf_in+L_SYN_MEM-M, synth-M, M ); + L_subfr = st->L_frame/st->nb_subfr; + residu( A, M, synth, synth_buf, L_subfr ); + syn_filt ( A, M, synth_buf, synth2, L_subfr, st->pfstat.mem_stp+L_SYN_MEM-M, 0 ); + scale_st ( synth, synth2, &st->pfstat.gain_prec, L_subfr, -1 ); + blend_subfr2(synth2+L_subfr/2, synth+L_subfr/2, synth2+L_subfr/2); } } - ELSE + else { - /*Formant enhancement*/ - IF ( sub(st->last_bwidth_fx,NB)==0 ) + /* Low bitrates (32kbps and below), low sampling rates (12.8kHz and 16kHz) */ + if( st->last_bwidth == NB ) { - Copy( synth, synth2_pe, L_frame ); + /* NB Post-filter (pitch+formant post-filter) */ + mvr2r( synth, synth_buf, L_frame ); tmp = synth[-1]; - move16(); + preemph( synth_buf, st->preemph_fac, L_frame, &tmp ); - preemph_copy_fx( synth2_pe, synth2_pe, st->preemph_fac, L_frame, &tmp); - - tmp = 0; - move16(); - test(); - test(); - if ((L_sub(st->lp_noise, LP_NOISE_THRESH) > 0) || - (st->core_fx != ACELP_CORE) || - (sub(coder_type, UNVOICED) == 0)) + tmp = 0.0f; + for( i=0; i< nb_subfr; i ++ ) { - tmp = 1; - move16(); + pitch_buf[i] = pitch[i]; } - if(pfstat_on_previous==0) + if( pfstat_on_previous == 0 ) { st->pfstat.reset = 1; - move16(); } - IF ( sub(st->bwidth_fx,NB) == 0) + + if( st->bwidth == NB ) { st->pfstat.on = 1; - move16(); - tmp_noise = 0; - nb_post_filt( L_frame, &(st->pfstat), &tmp_noise, 0, synth2_pe, st->mem_Aq, pitch, GENERIC, st->BER_detect, tmp ); + nb_post_filt( L_frame, L_SUBFR, &(st->pfstat), &tmp, 0, synth_buf, st->mem_Aq, pitch_buf, GENERIC, st->BER_detect, + st->lp_noise>LP_NOISE_THRESH?1:((st->core != ACELP_CORE)||(coder_type==UNVOICED)) ); } - ELSE + else { st->pfstat.on = 0; - move16(); - tmp_noise = 0; - nb_post_filt( L_frame, &(st->pfstat), &tmp_noise, 0, synth2_pe, st->mem_Aq, pitch, AUDIO, st->BER_detect, tmp ); + nb_post_filt( L_frame, L_SUBFR, &(st->pfstat), &tmp, 0, synth_buf, st->mem_Aq, pitch_buf, AUDIO, st->BER_detect, + st->lp_noise>LP_NOISE_THRESH?1:((st->core != ACELP_CORE)||(coder_type==UNVOICED)) ); } - Copy(synth2_pe, synth2, L_frame); + mvr2r( synth_buf, synth2, L_frame ); tmp = synth2[-1]; - move16(); - deemph_fx( synth2, st->preemph_fac, L_frame, &tmp ); + deemph( synth2, st->preemph_fac, L_frame, &tmp ); } - ELSE + else { - if(pfstat_on_previous==0) + /* Formant Post-filter */ + if( pfstat_on_previous == 0 ) { st->pfstat.reset = 1; - move16(); } - IF ( sub(st->last_bwidth_fx,WB)>=0 ) + + if( st->bwidth >= WB ) { st->pfstat.on = 1; - move16(); - formant_post_filt( &(st->pfstat), synth, st->mem_Aq, synth2, L_frame, st->lp_noise, bitrate, 0 ); + formant_post_filt( &(st->pfstat), synth, st->mem_Aq, synth2, L_frame, L_SUBFR, st->lp_noise, bitrate, 0 ); } - ELSE + else { st->pfstat.on = 0; - move16(); - formant_post_filt( &(st->pfstat), synth, st->mem_Aq, synth2, L_frame, st->lp_noise, bitrate, 1 ); + formant_post_filt( &(st->pfstat), synth, st->mem_Aq, synth2, L_frame, L_SUBFR, st->lp_noise, bitrate, 1 ); } } /*Bass Post-filter */ - tmp8 = 0; - move16(); - test(); - if( L_sub(st->lp_noise,LP_NOISE_THRESH) > 0 && st->narrowBand ) - { - tmp8 = 1; - move16(); - } bass_pf_1sf_delay( synth2, pitch, pit_gain, L_frame, L_SUBFR, bpf_noise_buf, pitch_gain_adjust, - tmp8, &(st->lp_error_ener), &(st->mem_error) ); + (st->lp_noise>LP_NOISE_THRESH && st->narrowBand)?1:0, &(st->pst_mem_deemp_err), &(st->pst_lp_ener) ); } /* Output */ - Copy( synth2, signal_out, L_frame ); + mvr2r( synth2, signal_out, L_frame ); /* Update synth2 memory */ - Copy( synth_buf2 + L_frame, st->pst_old_syn_fx, NBPSF_PIT_MAX ); - + mvr2r( synth_buf2 + L_frame, st->pst_old_syn, NBPSF_PIT_MAX ); return; } @@ -184,225 +157,145 @@ void post_decoder( *---------------------------------------------------------------------*/ static void bass_pf_1sf_delay( - Word16 *syn, /* (i) : 12.8kHz synthesis to postfilter Q0 */ - Word16 *T_sf, /* (i) : Pitch period for all subframes (T_sf[16]) Q0 */ - Word16 *gainT_sf, /* (i) : Pitch gain for all subframes (gainT_sf[16]) Q14 */ - Word16 l_frame, /* (i) : frame length (should be multiple of l_subfr) Q0 */ - Word16 l_subfr, /* (i) : sub-frame length (60/64) Q0 */ - Word16 *bpf_noise_buf, /* (i) : harmoninc filtered signal Q0 */ - Word16 *gain_factor_param, /* (i) : gain factor param 0-> no BPF, 3-> full BPF */ - Word8 disable_bpf, - Word32 *lp_error_ener, - Word32 *mem_error + float *syn, /* i : synthesis to postfilter */ + const int *T_sf, /* i : Pitch period for all subframes (T_sf[4]) */ + const float *gainT_sf, /* i : Pitch gain for all subframes (gainT_sf[4]) */ + const short L_frame, /* i : frame length (multiple of l_subfr) */ + const short L_subfr_in, /* i : sub-frame length (80/64) */ + float *bpf_noise_buf, /* i : harmoninc filtered signal */ + int *gain_factor_param, /* i : gain factor param 0-> minimum BPF, 3-> full BPF */ + const short disable_bpf, /* i : flag to disable BPF */ + float *mem_deemph_err, /* i/o: Error deemphasis memory */ + float *lp_ener /* i/o: long_term error signal energy */ ) { - Word16 i, sf, i_subfr, T, lg, s1, st, tmp16; - Word16 gain; - Word32 tmp, nrg, lp_error, tmp32; - Word32 ener2; + short i, sf, i_subfr, T, lg, L_subfr; + float tmp, corr, ener, gain; + float noise_buf[(2*L_SUBFR)], *noise_in; + float error[L_SUBFR]; + float ener2; - - assert(bpf_noise_buf != NULL); + noise_in = noise_buf; sf = 0; - move16(); - lp_error = L_shl(*mem_error, 0); + L_subfr = L_subfr_in; - FOR (i_subfr = 0; i_subfr < l_frame; i_subfr += l_subfr) + for( i_subfr = 0; i_subfr < L_frame; i_subfr += L_subfr, sf++ ) { + if( i_subfr == 0 ) + { + L_subfr = L_subfr_in; + } + else if( i_subfr == L_frame ) + { + L_subfr = 0; + } + else + { + L_subfr = L_subfr_in; + } + T = T_sf[sf]; - move16(); + gain = gainT_sf[sf]; - lg = sub(sub(l_frame, T), i_subfr); - if (lg < 0) + if (gain > 1.0f) gain = 1.0f; + if (gain < 0.0f) gain = 0.0f; + + lg = L_frame - T - i_subfr; + if (lg < 0) lg = 0; + if (lg > L_subfr) lg = L_subfr; + + if( !disable_bpf && gain > 0 ) { - lg = 0; - move16(); - } - if (lg > l_subfr) - { - lg = l_subfr; - move16(); - } + corr = 0.01f; + ener = 0.01f; - test(); - IF (disable_bpf == 0 && gainT_sf[sf] > 0) - { - /* get headroom for used part of syn */ - tmp16 = add(l_subfr, T); - if (lg>0) + for( i=0; i 0) - { - FOR (i = 0; i < lg; i++) - { - tmp32 = L_mult(syn[i+i_subfr-T], 0x4000); - tmp32 = L_mac(tmp32, syn[i+i_subfr+T], 0x4000); - tmp16 = round_fx(L_shl(tmp32, s1)); /* Q0+s1 */ - - tmp = L_mac0(tmp, shl(syn[i+i_subfr], s1), tmp16); /* Q0+2*s1 */ - nrg = L_mac0(nrg, tmp16, tmp16); /* Q0+2*s1 */ - } + corr += syn[i+i_subfr] * (0.5f*syn[i+i_subfr-T] + 0.5f*syn[i+i_subfr+T]); + ener += (0.5f*syn[i+i_subfr-T] + 0.5f*syn[i+i_subfr+T])*(0.5f*syn[i+i_subfr-T] + 0.5f*syn[i+i_subfr+T]); } - IF (sub(lg, l_subfr) < 0) + for( i=lg; i 1.f ) + { + gain = 1.0f; + } + else if( gain<0.f ) + { + gain = 0.f; } - /* gain = tmp/nrg; */ - gain = BASOP_Util_Divide3232_Scale(tmp, nrg, &tmp16); - BASOP_SATURATE_WARNING_OFF; - gain = shl(gain, tmp16); /* Q15 */ - BASOP_SATURATE_WARNING_ON; - - if (gain < 0) + ener2 = 0.01f; + for( i=0; i 0) + if( tmp > 0.5f ) { - FOR (i = 0; i < lg; i++) - { - tmp32 = L_msu0(0, gain, syn[i+i_subfr-T]); - tmp32 = L_msu0(tmp32, gain, syn[i+i_subfr+T]); - tmp16 = mac_r(tmp32, gain, syn[i+i_subfr]); /* Q0 */ - - lp_error = Mpy_32_16_1(lp_error, 29491/*0.9f Q15*/); - lp_error = L_mac(lp_error, tmp16, 0x1000); /* Q13 */ - - tmp16 = round_fx(L_shl(lp_error, s1)); /* Q0+s1-3 */ - ener2 = L_mac0(ener2, tmp16, tmp16); /* Q0+(s1-3)*2 */ - } + tmp = 0.5f; } - - IF (sub(lg, l_subfr) < 0) + else if( tmp < 0.f ) { - FOR (i = lg; i < l_subfr; i++) - { - tmp32 = L_mult0(gain, syn[i+i_subfr]); - tmp32 = L_msu0(tmp32, gain, syn[i+i_subfr-T]); /* Q0 */ - tmp16 = round_fx(tmp32); - - lp_error = Mpy_32_16_1(lp_error, 29491/*0.9f Q15*/); - lp_error = L_mac(lp_error, tmp16, 0x1000); /* Q13 */ - - tmp16 = round_fx(L_shl(lp_error, s1)); /* Q0+s1-3 */ - ener2 = L_mac0(ener2, tmp16, tmp16); /* Q0+(s1-3)*2 */ - } + tmp = 0.0f; } - st = shl(sub(s1, 3), 1); - - IF (ener2 > 0) - { - ener2 = L_shr(BASOP_Util_Log2(ener2), 9); /* 15Q16 */ - ener2 = L_add(ener2, L_deposit_h(sub(31, st))); - } - ELSE - { - ener2 = L_add(0xFFF95B2C, 0); /* log2(0.01) (15Q16) */ - } - - *lp_error_ener = L_add(Mpy_32_16_1(L_sub(*lp_error_ener, ener2), 32440/*0.99f Q15*/), ener2); /* 15Q16 */ - - st = add(st, 6); - ener2 = L_sub(*lp_error_ener, L_deposit_h(sub(31, st))); - IF (ener2 >= 0) - { - tmp16 = add(extract_h(ener2), 1); - ener2 = L_sub(ener2, L_deposit_h(tmp16)); - tmp = L_shr(tmp, tmp16); - nrg = L_shr(nrg, tmp16); - } - ener2 = BASOP_Util_InvLog2(L_shl(ener2, 9)); /* Q0+2*s1 */ - - tmp32 = L_add(L_shr(nrg, 1), L_shr(ener2, 1)); - if (tmp32 == 0) tmp32 = L_deposit_l(1); - tmp16 = BASOP_Util_Divide3232_Scale(tmp, tmp32, &st); - BASOP_SATURATE_WARNING_OFF; - tmp16 = shl(tmp16, sub(st, 2)); /* Q15 */ - - if (sub(tmp16, 16384/*0.5f Q15*/) > 0) - { - tmp16 = 16384/*0.5f Q15*/; - move16(); - } - if (tmp16 < 0) - { - tmp16 = 0; - move16(); - } - BASOP_SATURATE_WARNING_ON; - /*Adjust gain*/ /* full gain = gainLTP*0.5*/ - /* adaptive gain = gainLTP*0.5*max(0.5f*gain_factor_param[sf],0.125f)*/ - tmp16 = round_fx(L_shl(L_mult0(tmp16, s_max(shl(gain_factor_param[sf],2),1)),13)); - + /* adaptive gain = gainLTP*0.5*gain_factor*0.5*/ + tmp *= max(0.5f*gain_factor_param[sf],0.125f); /* calculate noise based on voiced pitch */ - IF (lg > 0) + for( i=0; i reduce nrg of noise_in and avoid too much post-filtering*/ + /*noise_in[i] = tmp * (syn[i+i_subfr] - 0.5f*syn[i+i_subfr-T] - 0.5f*syn[i+i_subfr]);*/ + /*->noise_in[i] = tmp * 0.5f * (syn[i+i_subfr] - syn[i+i_subfr-T]);*/ + noise_in[i] *= 0.5f; } } - ELSE + else { - set16_fx(bpf_noise_buf+i_subfr, 0, l_subfr); + set_zero( noise_in, L_subfr ); } - sf = add(sf, 1); + /* copy bpf noise signal to buffer */ + mvr2r( noise_in, bpf_noise_buf + i_subfr, L_subfr ); + } - *mem_error = lp_error; - move32(); - - return; } - /*---------------------------------------------------------------------* * cldfb_synth_set_bandsToZero() * @@ -410,182 +303,131 @@ static void bass_pf_1sf_delay( *---------------------------------------------------------------------*/ void cldfb_synth_set_bandsToZero( - Decoder_State_fx *st, - Word32 **rAnalysis, - Word32 **iAnalysis, - const Word16 nTimeSlots, - const CLDFB_SCALE_FACTOR scaleFactor + Decoder_State *st, + float **rAnalysis, + float **iAnalysis, + const short nTimeSlots ) { - Word32 nrgQ31; - Word32 nrg_band[CLDFB_NO_CHANNELS_MAX], tempQ31, max_nrg; - Word16 realQ1, imagQ1, flag, offset, WBcnt; - Word16 perc_detect, perc_miss; - Word16 i, k, tmp1, tmp2, tmp3, tmp, update_perc; + float nrg_bwddec, nrg_band[CLDFB_NO_CHANNELS_MAX], thr_bwddwc, max_nrg, realQ1, imagQ1; + short flag, offset, WBcnt, i, k, update_perc; + float perc_detect, perc_miss; - realQ1 = 0; - move16(); - imagQ1 = 0; - move16(); + realQ1 = 0.0f; + imagQ1 = 0.0f; - set32_fx( nrg_band, 0, CLDFB_NO_CHANNELS_MAX ); - max_nrg = 0; + set_f( nrg_band, 0.0f, CLDFB_NO_CHANNELS_MAX ); + max_nrg = 0.0f; offset = 250; WBcnt = 20; - perc_miss = 13107; /*0.80 in Q14*/ - perc_detect = 14746; /*0.90 in Q14*/ + perc_miss = 0.83f; + perc_detect = 0.93f; - IF(sub(st->VAD,1) == 0) + if(st->VAD==1) { - st->active_frame_cnt_bwddec = add(st->active_frame_cnt_bwddec,1); - st->total_frame_cnt_bwddec = add(st->total_frame_cnt_bwddec,1); - if(sub(st->active_frame_cnt_bwddec, 99) > 0) + st->active_frame_cnt_bwddec++; + st->total_frame_cnt_bwddec++; + if(st->active_frame_cnt_bwddec > 99) { st->active_frame_cnt_bwddec = 100; - move16(); } - if(sub(st->total_frame_cnt_bwddec, 500) > 0) + if(st->total_frame_cnt_bwddec > 500) { st->total_frame_cnt_bwddec = 500; - move16(); } - FOR (i = 0; i < (st->cldfbSyn_fx->no_channels - st->cldfbSyn_fx->bandsToZero); i++) + for (i = 0; i < (st->cldfbSyn->no_channels - st->cldfbSyn->bandsToZero); i++) { - nrgQ31 = 0; - move32(); - FOR (k = 0; k < nTimeSlots; k++) + nrg_bwddec = 0.0f; + for (k = 0; k < nTimeSlots; k++) { - /* use 16-bit precision of real and imag buffers */ - realQ1 = extract_l(L_shr(rAnalysis[k][i], 31-(15+scaleFactor.lb_scale)+3)); - imagQ1 = extract_l(L_shr(iAnalysis[k][i], 31-(15+scaleFactor.lb_scale)+3)); /* Q(-3), headroom */ - nrgQ31 = L_mac0(nrgQ31, realQ1, realQ1); - nrgQ31 = L_mac0(nrgQ31, imagQ1, imagQ1); /* keep in Q(-6) */ + realQ1 = rAnalysis[k][i]; + imagQ1 = iAnalysis[k][i]; + nrg_bwddec += (realQ1*realQ1); + nrg_bwddec += (imagQ1*imagQ1); } - nrg_band[i] = (nrgQ31); - move16(); - test(); - if(L_sub(nrg_band[i], max_nrg) > 0 && sub(i,11) >= 0) + nrg_band[i] = (nrg_bwddec); + if( (nrg_band[i] > max_nrg) && (i > 11) ) { max_nrg = nrg_band[i]; - move16(); } } - FOR(; i < st->cldfbSyn_fx->no_channels; i++) + for(; i < st->cldfbSyn->no_channels; i++) { nrg_band[i] = 0; - move16(); } - nrgQ31 = 0; - move16(); - FOR(i = 2; i < 9; i++) + nrg_bwddec = 0; + for(i = 2; i < 9; i++) { - nrgQ31 = L_add(nrgQ31, Mult_32_16(nrg_band[i], 4681)); + nrg_bwddec += (nrg_band[i]/7.0f); } - tempQ31 = L_shr(nrgQ31,9); + thr_bwddwc = (nrg_bwddec/512.0f); - st->avg_nrg_LT = L_add(Mult_32_16(st->avg_nrg_LT, 32440), Mult_32_16(tempQ31, 327)); /*0.99*avg_nrg_LT + 0.01*tempQ31*/ + st->avg_nrg_LT = 0.98999f*st->avg_nrg_LT + 0.009979f*thr_bwddwc; update_perc = 1; - move16(); - if(st->ini_frame_fx >= 25 && tempQ31 < Mult_32_16(st->avg_nrg_LT, 164)) + if(st->ini_frame >= 25 && thr_bwddwc < st->avg_nrg_LT*0.005f) { update_perc = 0; - move16(); } flag = 1; - move16(); - if(max_nrg >= tempQ31) + if(max_nrg >= thr_bwddwc) { flag = 0; - move16(); } - FOR(i = 0; i < WBcnt-1; i++) + for(i = 0; i < WBcnt-1; i++) { st->flag_buffer[i] = st->flag_buffer[i+1]; - move16(); } st->flag_buffer[WBcnt-1] = flag; - move16(); /*long term percentage*/ - IF(sub(update_perc, 1) == 0) + if(update_perc == 1) { - IF(flag != 0) - { - tmp1 = sub(16384, st->perc_bwddec); /*Q14*/ - - tmp = norm_s(st->active_frame_cnt_bwddec); - tmp3 = shl(st->active_frame_cnt_bwddec, tmp); /*Qtmp*/ - - tmp2 = div_s(16384,tmp3); /* 1/active_frames in Q15 + Q14 - Qtmp = Q29 - Qtmp */ - tmp2 = mult_r(tmp2, tmp1); /*(1-perc)*(1/active_frames) in Q14 + Q29 - Qtmp - Q15 = Q28 - Qtmp*/ - st->perc_bwddec = add(st->perc_bwddec, shl(tmp2, sub(tmp, 14))); /* Q14 */ - } - ELSE - { - tmp1 = (st->perc_bwddec); /*Q14*/ - - tmp = norm_s(st->active_frame_cnt_bwddec); - tmp3 = shl(st->active_frame_cnt_bwddec, tmp); /*Qtmp*/ - - tmp2 = div_s(16384,tmp3); /* 1/active_frames in Q15 + Q14 - Qtmp = Q29 - Qtmp */ - tmp2 = mult_r(tmp2, tmp1); /*(perc)*(1/active_frames) in Q14 + Q29 - Qtmp - Q15 = Q28 - Qtmp*/ - st->perc_bwddec = sub(st->perc_bwddec, shl(tmp2, sub(tmp, 14))); /* Q14 */ - } + st->perc_bwddec += (flag - st->perc_bwddec)/st->active_frame_cnt_bwddec; } - test(); - IF(sub(st->total_frame_cnt_bwddec, offset) > 0 && sub(st->active_frame_cnt_bwddec, 50) > 0) + if((st->total_frame_cnt_bwddec > offset) && (st->active_frame_cnt_bwddec > 50) ) { - IF( (st->perc_bwddec >= perc_detect || (st->perc_bwddec >= perc_miss && st->last_flag_filter_NB)) && (sum16_fx(st->flag_buffer, WBcnt) != 0)) /*decision hysterysis*/ + if( (st->perc_bwddec >= perc_detect || (st->perc_bwddec >= perc_miss && st->last_flag_filter_NB)) && (sum_s(st->flag_buffer, WBcnt) != 0)) /*decision hysterysis*/ { - st->cldfbSyn_fx->bandsToZero = sub( st->cldfbSyn_fx->no_channels, 10 ); - move16(); - st->last_flag_filter_NB = 1; - move16(); /*VAD processing must be dependent on hysterysis, as if hysterysis fails, but threshold passes, we dont want next vad frames to have NB only*/ + st->cldfbSyn->bandsToZero = ( st->cldfbSyn->no_channels - 10 ); + st->last_flag_filter_NB = 1; /*VAD processing must be dependent on hysterysis, as if hysterysis fails, but threshold passes, we dont want next vad frames to have NB only*/ } - ELSE + else { st->last_flag_filter_NB = 0; - move16(); } } - ELSE + else { st->last_flag_filter_NB = 0; - move16(); } - IF(sum16_fx(st->flag_buffer, WBcnt) == 0) + if(sum_s(st->flag_buffer, WBcnt) == 0) { - st->perc_bwddec = 0; + st->perc_bwddec = 0.0f; st->active_frame_cnt_bwddec = 0; - move16(); st->total_frame_cnt_bwddec = 0; - move16(); st->last_flag_filter_NB = 0; - move16(); } } - ELSE + else { - IF(st->last_flag_filter_NB == 1) + if(st->last_flag_filter_NB == 1) { - st->cldfbSyn_fx->bandsToZero = st->last_active_bandsToZero_bwdec; - move16(); + st->cldfbSyn->bandsToZero = st->last_active_bandsToZero_bwdec; } - st->total_frame_cnt_bwddec = add(st->total_frame_cnt_bwddec, 1); - if(sub(st->total_frame_cnt_bwddec, 500) > 0) + st->total_frame_cnt_bwddec++; + if(st->total_frame_cnt_bwddec > 500) { st->total_frame_cnt_bwddec = 500; - move16(); } } - st->last_active_bandsToZero_bwdec = st->cldfbSyn_fx->bandsToZero; + st->last_active_bandsToZero_bwdec = st->cldfbSyn->bandsToZero; return; } diff --git a/src/libs/libevs/lib_dec/ppp_dec.cpp b/src/libs/libevs/lib_dec/ppp_dec.cpp new file mode 100644 index 00000000..321fbf54 --- /dev/null +++ b/src/libs/libevs/lib_dec/ppp_dec.cpp @@ -0,0 +1,76 @@ +/*==================================================================================== + EVS Codec 3GPP TS26.443 Nov 13, 2018. Version 12.11.0 / 13.7.0 / 14.3.0 / 15.1.0 + ====================================================================================*/ + +#include +#include +#include "cnst.h" +#include "prot.h" +#include "rom_com.h" + +/*------------------------------------------------------------------- + * ppp_quarter_decoder() + * + * PPP quarter decoder + *-------------------------------------------------------------------*/ + +void ppp_quarter_decoder( + Decoder_State *st, /* i/o: decoder state structure */ + DTFS_STRUCTURE *CURRCW_Q_DTFS, /* i/o: Current CW DTFS */ + int prevCW_lag, /* i : Previous lag */ + float *lastLgainD, /* i/o: Last gain lowband */ + float *lastHgainD, /* i/o: Last gain highwband */ + float *lasterbD, /* i/o: Last ERB vector */ + short bfi, /* i : FER flag */ + DTFS_STRUCTURE PREV_CW_D /* i : Previous DTFS */ +) +{ + DTFS_STRUCTURE *PREVDTFS = DTFS_new(); + + float tmp, temp_pl = (float) prevCW_lag, temp_l = (float) CURRCW_Q_DTFS->lag; + int l = CURRCW_Q_DTFS->lag; + int POWER_IDX,AMP_IDX[2]; + float Erot = 0.0, z = 0.0; + short num_erb = 24; + + if ( CURRCW_Q_DTFS->upper_cut_off_freq == 4000.0 ) + { + num_erb = 22; + } + else if ( CURRCW_Q_DTFS->upper_cut_off_freq == 6400.0 ) + { + num_erb = 24; + } + + DTFS_copy(PREVDTFS, PREV_CW_D); + if( bfi == 0 ) + { + POWER_IDX = get_next_indice( st, 6 ); + AMP_IDX[0] = get_next_indice( st, 6 ); + AMP_IDX[1] = get_next_indice( st, 6 ); + + /* Amplitude Dequantization */ + DTFS_dequant_cw(prevCW_lag,POWER_IDX,AMP_IDX, lastLgainD, lastHgainD, lasterbD,CURRCW_Q_DTFS,num_erb); + } + + /* Copying phase spectrum over */ + DTFS_adjustLag(PREVDTFS,l); + + z=((L_FRAME-temp_l)*(temp_l+temp_pl))/(2*temp_l*temp_pl); + + Erot=(float) (temp_l - rint_new(temp_l*(z - floor(z)))); + + DTFS_phaseShift(PREVDTFS,(float)(PI2*Erot/CURRCW_Q_DTFS->lag)) ; + DTFS_car2pol(PREVDTFS); + + mvr2r(PREVDTFS->b, CURRCW_Q_DTFS->b, (short)(CURRCW_Q_DTFS->lag>>1)+1); + + DTFS_pol2car(CURRCW_Q_DTFS); + + tmp = (float) get_next_indice( st, 3 ); + DTFS_phaseShift(CURRCW_Q_DTFS,(float)(PI2*(tmp-3)/CURRCW_Q_DTFS->lag)) ; + + free( PREVDTFS ); + + return; +} diff --git a/src/libs/libevs/lib_dec/ppp_dec_fx.cpp b/src/libs/libevs/lib_dec/ppp_dec_fx.cpp deleted file mode 100755 index ff53b9c9..00000000 --- a/src/libs/libevs/lib_dec/ppp_dec_fx.cpp +++ /dev/null @@ -1,162 +0,0 @@ -/*==================================================================================== - EVS Codec 3GPP TS26.442 Apr 03, 2018. Version 12.11.0 / 13.6.0 / 14.2.0 - ====================================================================================*/ - -#include -#include -#include "prot_fx.h" -#include "rom_com_fx.h" -#include "stl.h" - - -/*===================================================================*/ -/* FUNCTION : void ppp_quarter_decoder_fx () */ -/*-------------------------------------------------------------------*/ -/* PURPOSE : */ -/*-------------------------------------------------------------------*/ -/* INPUT ARGUMENTS : */ -/* _ Word16 bfi_fx - Q0 bad frame indicator */ -/* _ const Word16 *curr_lpc_fx - Q12 current frame LPC */ -/* _ Word16 *exc_fx - Q0 previous frame excitation */ -/* _ Word16 prevCW_lag_fx - Q0 Previous lag */ -/* _ (struct DTFS_fx) PREV_CW_D_FX : prototype in polar domain */ -/* (Word16) lag: length of prototype in time domain */ -/* (Word16 []) a: amplitude of harmonics, normalized */ -/* (Word16) Q: norm factor of a */ -/*-------------------------------------------------------------------*/ -/* OUTPUT ARGUMENTS : */ -/* _ Decoder_State_fx *st_fx: */ -/* _ Word16 *pitch - Q6 floating pitch values for each subframe */ -/* _ Word16 *out_fx - Q0 residual signal */ -/*-------------------------------------------------------------------*/ -/* INPUT/OUTPUT ARGUMENTS : */ -/* _ Decoder_State_fx *st_fx: */ -/* _ lsp_old_fx - Q15 */ -/* _ st_fx->dtfs_dec_xxxx */ -/* _ gainp_ppp Q14 */ -/* _ lastLgainD_fx - Q11 */ -/* _ lastHgainD_fx - Q11 */ -/* _ lasterbD_fx - Q13 */ -/* _ (struct DTFS_fx) CURRCW_Q_DTFS_FX : prototype in polar domain*/ -/* (Word16) lag: length of prototype in time domain */ -/* (Word16 []) a: amplitude of harmonics, normalized */ -/* (Word16) Q: norm factor of a */ -/* _ Word16 *pitch_buf_fx - Q6 fixed pitch values for each subframe */ -/* _ Word16 *exc_fx - Q0 previous frame excitation */ -/*-------------------------------------------------------------------*/ -/* RETURN ARGUMENTS : */ -/* _ None */ -/*-------------------------------------------------------------------*/ -/* CALLED FROM : RX */ -/*===================================================================*/ - -void ppp_quarter_decoder_fx( - DTFS_STRUCTURE_FX *CURRCW_Q_DTFS_FX, /* i/o: Current CW DTFS */ - Word16 prevCW_lag_fx, /* i : Previous lag */ - Word16 *lastLgainD_fx, /* i/o: Last gain lowband Q11 */ - Word16 *lastHgainD_fx, /* i/o: Last gain highwband Q11 */ - Word16 *lasterbD_fx, /* i/o: Last ERB vector Q13 */ - Word16 bfi, /* i : FER flag */ - Word16 *S_fx, /* i : sine table, Q15 */ - Word16 *C_fx, /* i : cosine table, Q15 */ - DTFS_STRUCTURE_FX PREV_CW_D_FX, /* i : Previous DTFS */ - Decoder_State_fx *st_fx -) -{ - DTFS_STRUCTURE_FX *PREVDTFS_FX = DTFS_new_fx(); - Word16 AMP_IDX_fx[2]; - Word16 temp_pl_fx = prevCW_lag_fx, temp_l_fx = CURRCW_Q_DTFS_FX->lag_fx; - Word16 temp_fx; - Word16 l_fx = CURRCW_Q_DTFS_FX->lag_fx; - Word16 POWER_IDX_fx; - Word16 Erot_fx = 0; - Word16 num_erb_fx = 24; - Word32 temp32d_fx,temp32n_fx; - Word32 L_tmp, L_tmp1; - Word16 tmp, exp; - - - IF ( sub(CURRCW_Q_DTFS_FX->upper_cut_off_freq_fx,4000 ) == 0) - { - num_erb_fx = 22; - move16(); - } - ELSE IF ( sub(CURRCW_Q_DTFS_FX->upper_cut_off_freq_fx,6400) == 0 ) - { - num_erb_fx = 24; - move16(); - } - - DTFS_copy_fx(PREVDTFS_FX, PREV_CW_D_FX); - IF (bfi == 0) - { - POWER_IDX_fx =(Word16) get_next_indice_fx( st_fx, 6); - move16(); - AMP_IDX_fx[0] =(Word16) get_next_indice_fx( st_fx, 6); - move16(); - AMP_IDX_fx[1] =(Word16) get_next_indice_fx( st_fx, 6); - move16(); - - /* Amplitude Dequantization */ - /*This normalization and de-normalization is done to avoid division by 12800. And this logic is used only in - dequant_cw. So upper cut-off frequencies need to be multiplied by a factor2.56. - This logic of normalisation is not employed in adjustlag, hence denormalisation is necessury.*/ - /*As the upper cut of freqencies are normalized to 12800, we have to multiply upper cut off freq by - 2.56(1/12800 in Q15) */ - temp32n_fx = L_mult(CURRCW_Q_DTFS_FX->upper_cut_off_freq_fx,10486);/* Q0+Q27 = Q28 */ - CURRCW_Q_DTFS_FX->upper_cut_off_freq_fx = (Word16)L_shr(temp32n_fx,13);/*Q15 */ - temp32n_fx = L_mult(CURRCW_Q_DTFS_FX->upper_cut_off_freq_of_interest_fx,10486);/* Q0+Q27 = Q28 */ - CURRCW_Q_DTFS_FX->upper_cut_off_freq_of_interest_fx = (Word16)L_shr(temp32n_fx,13);/*Q15 */ - - DTFS_dequant_cw_fx(prevCW_lag_fx,POWER_IDX_fx,AMP_IDX_fx,lastLgainD_fx,lastHgainD_fx,lasterbD_fx,CURRCW_Q_DTFS_FX,num_erb_fx); - /*De-normalize cut off frequencies */ - - temp32n_fx = L_shl((Word32)CURRCW_Q_DTFS_FX->upper_cut_off_freq_fx,13);/*Q28 */ - CURRCW_Q_DTFS_FX->upper_cut_off_freq_fx = (Word16)find_remd(temp32n_fx, 20971,&temp32d_fx); - temp32n_fx = L_shl((Word32)CURRCW_Q_DTFS_FX->upper_cut_off_freq_of_interest_fx,13);/*Q28 */ - CURRCW_Q_DTFS_FX->upper_cut_off_freq_of_interest_fx = (Word16)find_remd(temp32n_fx, 20971,&temp32d_fx); - } - - /* Copying phase spectrum over */ - DTFS_adjustLag_fx(PREVDTFS_FX,l_fx); - - temp_fx = sub(L_FRAME,temp_l_fx); /*Q0 */ - - exp = norm_s(temp_pl_fx); - tmp = div_s(shl(1,sub(14,exp)),temp_pl_fx); /*Q(29-exp) */ - L_tmp = L_mult(temp_fx,tmp); /*Q(31-exp); +1 due to /2 */ - L_tmp = L_shl(L_tmp,sub(exp,15)); /*Q16 */ - - exp = norm_s(temp_l_fx); - tmp = div_s(shl(1,sub(14,exp)),temp_l_fx); /*Q(29-exp) */ - L_tmp1 = L_mult(temp_fx,tmp); /*Q(31-exp); +1 due to /2 */ - L_tmp1 = L_shl(L_tmp1,sub(exp,15)); /*Q16 */ - - L_tmp = L_add(L_tmp,L_tmp1); /*Q16 */ - - tmp = lshr(extract_l(L_tmp),1); /*Q15 */ - L_tmp = L_mult(temp_l_fx,tmp); /*Q16 */ - temp_fx = rint_new_fx(L_tmp); - Erot_fx = sub(temp_l_fx,temp_fx); /*Q0 */ - - Q2phaseShift_fx(PREVDTFS_FX,shl(Erot_fx,2),CURRCW_Q_DTFS_FX->lag_fx,S_fx,C_fx); - IF ( sub(bfi,1) == 0 ) - { - DTFS_car2pol_fx(CURRCW_Q_DTFS_FX); - } - /*Phase copying is done through copy_phase instead of car2pol and pol2car */ - copy_phase_fx(PREVDTFS_FX,*CURRCW_Q_DTFS_FX,CURRCW_Q_DTFS_FX); - - { - temp_fx = (Word16) get_next_indice_fx( st_fx, 3 ); - - temp_fx = sub(temp_fx,3); - temp_fx = shl(temp_fx,2);/*Q2 */ - Q2phaseShift_fx(CURRCW_Q_DTFS_FX,temp_fx,CURRCW_Q_DTFS_FX->lag_fx,S_fx,C_fx); - } - - free(PREVDTFS_FX); - - return; -} - diff --git a/src/libs/libevs/lib_dec/pvq_core_dec.cpp b/src/libs/libevs/lib_dec/pvq_core_dec.cpp new file mode 100644 index 00000000..bb84433c --- /dev/null +++ b/src/libs/libevs/lib_dec/pvq_core_dec.cpp @@ -0,0 +1,428 @@ + +/*==================================================================================== + EVS Codec 3GPP TS26.443 Nov 13, 2018. Version 12.11.0 / 13.7.0 / 14.3.0 / 15.1.0 + ====================================================================================*/ + +#include +#include +#include "options.h" +#include "cnst.h" +#include "rom_com.h" +#include "prot.h" +#include "stl.h" + +static short get_pvq_splits( Decoder_State *st, const short band_bits, const short sfmsize, short *bits ); + +static void densitySymbolIndexDecode(Decoder_State *st, short density, short opp_sz, short near_sz,short *index_phi); + +static void pvq_decode_band( + Decoder_State *st, + short *pulse_vector, + short *npulses, + float *coefs_quant, + const short sfmsize, + const short band_bits, + short *bits_left, + const short strict_bits +) +{ + short K_val; + short j, Np; + short part_start[MAX_SPLITS+1], dim_part[MAX_SPLITS+1], bits_part[MAX_SPLITS+1]; + short pool_tot, pool_part, dim_parts; + float g_part[MAX_SPLITS]; + short g_part_s[MAX_SPLITS]; + short sg_part[MAX_SPLITS+1]; + short idx_sort[MAX_SPLITS+1]; + short js, band_bits_tot, split_bit; + + Np = get_pvq_splits(st, band_bits, sfmsize, &split_bit); + band_bits_tot = band_bits - split_bit; + + dim_parts = intLimCDivPos( (int)sfmsize,Np) ; + set_s(dim_part,dim_parts,Np-1); + dim_part[Np-1] = sfmsize-dim_parts*(Np-1); + + part_start[0] = 0; + for(j = 1; j 1 ) + { + decode_energies( st, Np, dim_part, bits_part, g_part_s, band_bits_tot, bits_left, sfmsize, strict_bits ); + } + else + { + bits_part[0] = band_bits_tot; + } + + pool_tot = 0; + pool_part = 0; + + for (j = 0; j < Np; j++) + { + g_part[j] = -((float)g_part_s[j])/32768; + g_part_s[j] = -g_part_s[j]; + } + + srt_vec_ind(g_part_s,sg_part,idx_sort,Np); + for(j = 0; j= 1 ) + { + pvq_decode(st, coefs_quant + part_start[js], pulse_vector + part_start[js], K_val, dim_part[js], g_part[js]); + } + else + { + set_f(coefs_quant + part_start[js],0.0f,dim_part[js]); + set_s(pulse_vector + part_start[js],0,dim_part[js]); + } + } + + return; +} + +void pvq_decode_frame( + Decoder_State *st, + float *coefs_quant, /* o : quantized coefficients */ + short *npulses, /* o : number of pulses per band */ + short *pulse_vector, /* o : non-normalized pulse shapes */ + const short *sfm_start, /* i : indices of first coefficients in the bands */ + const short *sfm_end, /* i : indices of last coefficients in the bands */ + const short *sfmsize, /* i : band sizes */ + const short nb_sfm, /* i : total number of bands */ + const short *R, /* i : bitallocation per band (Q3) */ + const short pvq_bits, /* i : number of bits avaiable */ + const short core /* i : core */ +) +{ + short i, j; + short band_bits, bits_left; + short bit_pool = 0; + short coded_bands, bands_to_code; + short curr_bits; + short R_sort[NB_SFM]; /*Q3*/ + short is, i_sort[NB_SFM]; + short strict_bits; + + rc_dec_init(st, pvq_bits); + curr_bits = (pvq_bits - RC_BITS_RESERVED)<<3; + bands_to_code = 0; + for (i = 0; i < nb_sfm; i++) + { + if (R[i] > 0) + { + bands_to_code++; + } + } + + if (core == ACELP_CORE) + { + strict_bits = 1; + srt_vec_ind (R, R_sort, i_sort, nb_sfm); + } + else + { + strict_bits = 0; + for(i=0; i 0) + { + bandBitsAdjustment(st->rc_num_bits, st->rc_range, curr_bits, bands_to_code, bands_to_code-coded_bands, sfmsize[is] ,R[is], bit_pool, /* inputs */ + &band_bits, &bits_left, &bit_pool); /* outputs */ + + pvq_decode_band( st, &pulse_vector[sfm_start[is]], &npulses[is], + &coefs_quant[sfm_start[is]], sfmsize[is], band_bits, + &bits_left, strict_bits); + + /* Updates */ + coded_bands++; + } + else + { + for (j = sfm_start[is]; j < sfm_end[is]; j++) + { + coefs_quant[j] = 0.0f; + pulse_vector[j] = 0; + } + } + } + + rc_dec_finish(st); +} + +/*-------------------------------------------------------------------* + * pvq_core_dec() + * + *-------------------------------------------------------------------*/ + +short pvq_core_dec ( + Decoder_State *st, + const short *sfm_start, + const short *sfm_end, + const short *sfmsize, + float coefs_quant[], /* o : output MDCT */ + short bits_tot, + short nb_sfm, + short *R, + short *Rs, + short *npulses, + short *maxpulse, + const short core +) +{ + short i; + short R_upd; + short ord[NB_SFM_MAX]; + short pulse_vector[L_FRAME48k]; + short pvq_bits; + short gain_bits_array[NB_SFM]; + float fg_pred[NB_SFM_MAX]; + + st->ber_occured_in_pvq = 0; + + R_upd = bits_tot * 8; + assign_gain_bits( core, nb_sfm, sfmsize, R, gain_bits_array, &R_upd ); + + pvq_bits = R_upd >> 3; + + pvq_decode_frame(st, coefs_quant, npulses, pulse_vector, sfm_start, + sfm_end, sfmsize, nb_sfm, R, pvq_bits, core ); + + if( Rs != NULL ) + { + for(i=0; i 0); /* Update Rs in case no pulses were assigned */ + } + } + + for(i=0; i 0); /* Update in case no pulses were assigned */ + } + + get_max_pulses( sfm_start, sfm_end, ord, npulses, nb_sfm, pulse_vector, maxpulse ); + + fine_gain_pred( sfm_start, sfm_end, sfmsize, ord, npulses, maxpulse, R, + nb_sfm, coefs_quant, pulse_vector, fg_pred, core ); + + fine_gain_dec(st, ord, nb_sfm, gain_bits_array, fg_pred); + + if( st->ber_occured_in_pvq != 0 ) + { + set_f( fg_pred, (1.0f/8192.0f), nb_sfm ); /* low complex ECU action in case of detetected BER in PVQ decoding */ + } + + apply_gain(ord, sfm_start, sfm_end, nb_sfm, fg_pred, coefs_quant); + + return (short)bits_tot; +} + +void decode_energies( + Decoder_State *st, + short Np, + short *dim_part, + short *bits_part, + short *g_part, + short qband, + short *bits_left, + short dim, + const short strict_bits +) +{ + short res; + short i, l_Np, r_Np; + short l_bits, r_bits, l_dim, r_dim; + short il, ir; + short oppRQ3, qzero; + short index_phi=-1; + l_Np = Np>>1; + r_Np = Np-l_Np; + + l_bits = 0; + l_dim = 0; + for(i=0; irc_num_bits, st->rc_range, &qzero); + densitySymbolIndexDecode( st, res, r_dim, l_dim, &index_phi); + densityAngle2RmsProjDec(res, index_phi, &ir,&il, &oppRQ3); + for(i = 0; i> 15; + } + + for(i = l_Np; i> 15; + } + + + NearOppSplitAdjustment( qband, qzero, st->rc_num_bits, st->rc_range, *bits_left, + strict_bits, Np, dim_part[0], dim_part[Np-1], + l_dim, r_dim, oppRQ3, + &l_bits, &r_bits, bits_left); + if(l_Np > 1) + { + decode_energies( st, l_Np, dim_part, bits_part, g_part, l_bits, bits_left, l_dim, strict_bits ); + } + else + { + bits_part[0] = l_bits; + } + + if(r_Np > 1) + { + decode_energies( st, r_Np, &dim_part[l_Np], &bits_part[l_Np], &g_part[l_Np], r_bits, bits_left, r_dim, strict_bits ); + } + else + { + bits_part[1] = r_bits; + } + return; +} + + +static void densitySymbolIndexDecode(Decoder_State *st, + short density, + short opp_sz, + short near_sz, + short *index_phi + ) +{ + + long tmp1; + short tmp2 ; + int sym_freq = 1, cum_freq = 0, tot, dec_freq; + short angle , c ; + short res1, res2, res_c, res_alpha; + short res=density; + short r_dim =opp_sz; + short l_dim =near_sz; + short alpha ; + + if( (0xFFFE&density) == 0 ) + { + /* odd density exit */ + *index_phi = -1; + return; + } + angle = atan2_fx(SQRT_DIM_fx[r_dim], SQRT_DIM_fx[l_dim]); + angle = shl(angle, 1); + angle = mult_r(angle, 20861); + c = mult_r(res, angle); + + res_c = res-c; + if(c == 0) + { + tot = res*(res+1) + 1; + dec_freq = rc_decode(st, tot); + alpha = (short) floor_sqrt_exact((unsigned int)(res+1)*(res+1)-dec_freq) + res+1; + sym_freq = 2*(res-alpha) + 1; + cum_freq = alpha*(2*(res+1)-alpha); + } + else if(c == res) + { + tot = res*(res+1) + 1; + dec_freq = rc_decode(st, tot); + alpha = (short) floor_sqrt_exact((unsigned int)dec_freq); + sym_freq = 2*alpha + 1; + cum_freq = alpha*alpha; + } + else + { + tot = res*c*(res-c) + res+1; + dec_freq = rc_decode(st, tot); + if(dec_freq < tot -(res+1) - (res-(c+1))*(res-c)*c + c+1 ) + { + alpha = (res_c-1+(short)floor_sqrt_exact((unsigned int)res_c*(res_c+4*dec_freq - 2) + 1))/(2*res_c); + sym_freq = 2*alpha*res_c + 1; + cum_freq = alpha*((alpha-1)*res_c + 1); + } + else + { + res1 = res+1; + res2 = 2*res+1; + tmp1 = (c*res2+1)*(c*res2+1) + 4*c*((tot-dec_freq-res1) -c*(res*res1)); + tmp2 = (short)floor_sqrt_exact((unsigned int) tmp1 ); + if(tmp2*tmp2 != tmp1) + { + tmp2++; /* convert to ceil */ + } + + alpha = (c*(2*res+1)+1-tmp2)/(2*c); + + res_alpha = res-alpha; + sym_freq = 2*res_alpha*c + 1; + cum_freq = tot -(res+1) - res_alpha*(res_alpha+1)*c + alpha; + } + } + rc_dec_update(st, cum_freq, sym_freq); + + *index_phi = alpha; + return; +} + + +/*--------------------------------------------------------------------------* + * get_pvq_splits() + * + * Retrieve the number of segments + *--------------------------------------------------------------------------*/ + +static short get_pvq_splits( /* o : Number of segments */ + Decoder_State *st, /* i/o: Decoder state */ + const short band_bits, /* i : Band bit rate */ + const short sfmsize, /* i : Band width */ + short *bits /* o : Used bits */ +) +{ + short Np; + unsigned int flag; + + Np = (short)(intLimCDivPos( (int)band_bits, 67)>>2); + if (band_bits - 268*Np != 0 || Np == 0 ) /* L_msu */ + { + Np++; /* ceil */ + } + *bits = 0; + if ( Np < MAX_SPLITS && (band_bits - (8*sfmsize * THR_ADD_SPLIT ) > 0)) + { + flag = rc_dec_bits(st, 1); + *bits = 8; + if( flag ) + { + Np += 1; + } + } + + Np = max(Np, (short)(ceil((float)sfmsize/PVQ_MAX_BAND_SIZE))); + Np = min(MAX_SPLITS, Np); + Np = min((short)floor((float)sfmsize/MIN_BAND_SIZE), Np); + return Np; +} + + diff --git a/src/libs/libevs/lib_dec/pvq_core_dec_fx.cpp b/src/libs/libevs/lib_dec/pvq_core_dec_fx.cpp deleted file mode 100755 index effd9eeb..00000000 --- a/src/libs/libevs/lib_dec/pvq_core_dec_fx.cpp +++ /dev/null @@ -1,556 +0,0 @@ -/*==================================================================================== - EVS Codec 3GPP TS26.442 Apr 03, 2018. Version 12.11.0 / 13.6.0 / 14.2.0 - ====================================================================================*/ - -#include -#include "options.h" /* Compilation switches */ -#include "cnst_fx.h" /* Common constants */ -#include "prot_fx.h" /* Function prototypes */ -#include "rom_com_fx.h" /* Static table prototypes */ -#include "stl.h" -#include "basop_util.h" - -static Word16 get_pvq_splits_fx(Decoder_State_fx *st_fx, const Word16 band_bits, const Word16 sfmsize, Word16 *bits); - -static void densitySymbolIndexDecode_fx(Decoder_State_fx *st_fx, const Word16 density, const Word16 opp_sz, const Word16 near_sz, Word16 *index_phi); - -/* Decode band with PVQ */ -static void pvq_decode_band_fx( - Decoder_State_fx *st_fx, - Word16 *pulse_vector, - Word16 *npulses, - Word16 *coefs_quant, - const Word16 sfmsize, - const Word16 band_bits, - Word16 *bits_left, - const Word16 strict_bits -) -{ - - Word16 K_val; - - Word16 j, Np; - Word16 part_start[MAX_SPLITS+1], dim_part[MAX_SPLITS+1], bits_part[MAX_SPLITS+1]; - Word16 pool_tot, pool_part, dim_parts; - Word16 g_part[MAX_SPLITS]; - Word16 g_part_neg[MAX_SPLITS]; - Word16 sg_part[MAX_SPLITS+1]; - Word16 idx_sort[MAX_SPLITS+1]; - Word16 js, band_bits_tot, split_bit; - Np = get_pvq_splits_fx(st_fx, band_bits, sfmsize, &split_bit); - band_bits_tot = sub(band_bits, split_bit); - - dim_parts = extract_h(L_mult(negate(sfmsize),lim_neg_inv_tbl_fx[Np])); - set16_fx(dim_part, dim_parts, sub(Np, 1)); - dim_part[Np-1] = sub(sfmsize, i_mult2(dim_parts, sub(Np, 1))); - move16(); - - part_start[0] = 0; - move16(); - FOR (j = 1; j < Np; j++) - { - part_start[j] = add(part_start[j-1], dim_part[j-1]); - move16(); - } - - /* Encode energies */ - set16_fx( g_part_neg, -32768, Np ); - IF( sub(Np, 1) > 0 ) - { - decode_energies_fx( st_fx, Np, dim_part, bits_part, g_part_neg, band_bits_tot, bits_left, sfmsize, strict_bits ); - } - ELSE - { - bits_part[0] = band_bits_tot; - move16(); - } - - pool_tot = 0; - move16(); - pool_part = 0; - move16(); - BASOP_SATURATE_WARNING_OFF - FOR (j = 0; j < Np; j++) - { - g_part[j] = negate(g_part_neg[j]); - } - BASOP_SATURATE_WARNING_ON - srt_vec_ind16_fx(g_part, sg_part, idx_sort, Np); - FOR(j = 0; j < Np; j++) - { - js = idx_sort[Np-1-j]; - pool_part = shrtCDivSignedApprox(pool_tot, sub(Np, j) ); - bits_part[js] = s_max(0, s_min(add(bits_part[js], pool_part), 256)); - move16(); - - conservativeL1Norm_fx(dim_part[js],bits_part[js], strict_bits, *bits_left, pool_tot , *npulses, /* inputs */ - &K_val, bits_left, &pool_tot, npulses); /* outputs */ - - IF( K_val > 0 ) - { - - pvq_decode_fx(st_fx, coefs_quant + part_start[js], pulse_vector + part_start[js], - K_val, dim_part[js], g_part_neg[js]); - } - ELSE - { - set16_fx(coefs_quant + part_start[js], 0, dim_part[js]); - set16_fx(pulse_vector + part_start[js], 0, dim_part[js]); - } - } - - return; -} - -void pvq_decode_frame_fx( - Decoder_State_fx *st_fx, - Word16 *coefs_quant, /* o : quantized coefficients */ - Word16 *npulses, /* o : number of pulses per band */ - Word16 *pulse_vector, /* o : non-normalized pulse shapes */ - const Word16 *sfm_start, /* i : indices of first coefficients in the bands */ - const Word16 *sfm_end, /* i : indices of last coefficients in the bands */ - const Word16 *sfmsize, /* i : band sizes */ - const Word16 nb_sfm, /* i : total number of bands */ - const Word16 *R, /* i : bitallocation per band */ - const Word16 pvq_bits, /* i : number of bits avaiable */ - const Word16 core /* i : core */ -) -{ - Word16 i, j; - Word16 band_bits, bits_left; - Word16 bit_pool = 0; - Word16 coded_bands, bands_to_code; - Word16 bits; - Word16 R_sort[NB_SFM]; - Word16 is, i_sort[NB_SFM]; - Word16 strict_bits; - - rc_dec_init_fx(st_fx, pvq_bits); - - bits = shl(sub(pvq_bits, RC_BITS_RESERVED), 3); - - bands_to_code = 0; - move16(); - FOR (i = 0; i < nb_sfm; i++) - { - if (R[i] > 0) - { - bands_to_code = add(bands_to_code, 1); - } - } - - IF (core == ACELP_CORE) - { - strict_bits = 1; - move16(); - srt_vec_ind16_fx (R, R_sort, i_sort, nb_sfm); - } - ELSE - { - strict_bits = 0; - move16(); - FOR (i = 0; i < nb_sfm; i++) - { - i_sort[i] = i; - move16(); - } - } - - coded_bands = 0; - move16(); - FOR (i = 0; i < nb_sfm; i++) - { - is = i_sort[i]; - move16(); - IF(R[is] > 0) - { - bandBitsAdjustment_fx(st_fx->rc_num_bits_fx, st_fx->rc_range_fx, bits, bands_to_code, bands_to_code-coded_bands, sfmsize[is] ,R[is], bit_pool, /* inputs */ - &band_bits, &bits_left, &bit_pool); /* outputs */ - - pvq_decode_band_fx( st_fx, &pulse_vector[sfm_start[is]], &npulses[is], - &coefs_quant[sfm_start[is]], sfmsize[is], band_bits, - &bits_left, strict_bits); - - /* Updates */ - coded_bands = add(coded_bands, 1); - } - ELSE - { - FOR (j = sfm_start[is]; j < sfm_end[is]; j++) - { - coefs_quant[j] = 0; - move16(); - pulse_vector[j] = 0; - move16(); - } - } - } - - rc_dec_finish_fx(st_fx); -} - -/*-------------------------------------------------------------------* - * pvq_core_dec() - * - *-------------------------------------------------------------------*/ - -Word16 pvq_core_dec_fx( - Decoder_State_fx *st_fx, - const Word16 *sfm_start, - const Word16 *sfm_end, - const Word16 *sfmsize, - Word16 coefs_quant[], /* o : output MDCT */ - Word16 *Q_coefs, - Word16 bits_tot, - Word16 nb_sfm, - Word16 *R, /* Q3 */ - Word16 *Rs, - Word16 *npulses, - Word16 *maxpulse, - const Word16 core -) -{ - Word16 i; - Word16 R_upd; - Word16 ord[NB_SFM_MAX]; - Word16 pulse_vector[L_FRAME48k]; - Word16 pvq_bits; - Word16 gain_bits_array[NB_SFM]; - Word16 fg_pred[NB_SFM_MAX]; - - st_fx->ber_occured_in_pvq = 0; - move16(); - - R_upd = shl(bits_tot, 3); - assign_gain_bits_fx( core, nb_sfm, sfmsize, R, gain_bits_array, &R_upd ); - - pvq_bits = shr(R_upd, 3); - - pvq_decode_frame_fx(st_fx, coefs_quant, npulses, pulse_vector, sfm_start, - sfm_end, sfmsize, nb_sfm, R, pvq_bits, core ); - - IF( Rs != NULL ) - { - FOR(i = 0; i < nb_sfm; i++) - { - if (npulses[i] <= 0) - { - Rs[i] = 0; - move16(); /* Update Rs in case no pulses were assigned */ - } - } - } - - FOR (i=0; i < nb_sfm; i++) - { - ord[i] = i; - move16(); - if (npulses[i] <= 0) - { - R[i] = 0; - move16(); /* Update in case no pulses were assigned */ - } - } - - get_max_pulses_fx( sfm_start, sfm_end, ord, npulses, nb_sfm, pulse_vector, maxpulse ); - - fine_gain_pred_fx( sfm_start, sfm_end, sfmsize, ord, npulses, maxpulse, R, - nb_sfm, coefs_quant, pulse_vector, fg_pred, core ); - - fine_gain_dec_fx( st_fx, ord, nb_sfm, gain_bits_array, fg_pred); - - IF( st_fx->ber_occured_in_pvq != 0 ) - { - set16_fx( fg_pred, 1, nb_sfm ); /* low complex ECU action in case of detetected BER in PVQ decoding */ - } - apply_gain_fx(ord, sfm_start, sfm_end, nb_sfm, fg_pred, coefs_quant); - *Q_coefs = 12; - - return bits_tot; -} - -void decode_energies_fx( - Decoder_State_fx *st_fx, - Word16 Np, - Word16 *dim_part, - Word16 *bits_part, - Word16 *g_part, /* Q15 */ - short qband, - Word16 *bits_left, - Word16 dim, - const Word16 strict_bits -) -{ - Word16 density; - Word16 i, l_Np, r_Np; - Word16 l_bits, r_bits, l_dim, r_dim; - Word16 il, ir; - Word16 oppRQ3, qzero; - Word16 l_gain, r_gain; - Word16 index_phi=-1; - - l_Np = shr(Np, 1); - r_Np = sub(Np, l_Np); - - l_bits = 0; - move16(); - l_dim = 0; - move16(); - FOR (i = 0; i < l_Np; i++) - { - l_dim = add(l_dim, dim_part[i]); - } - r_dim = sub(dim, l_dim); - - obtainEnergyQuantizerDensity_fx(dim, qband, &density); - rangeCoderFinalizationFBits_fx(st_fx->rc_num_bits_fx, st_fx->rc_range_fx, &qzero); - - densitySymbolIndexDecode_fx( st_fx, density, r_dim, l_dim, &index_phi); - densityAngle2RmsProjDec_fx(density, index_phi, &ir, &il, &oppRQ3); - - - - - l_gain = il; /* Q15 */ move16(); - r_gain = ir; /* Q15 */ move16(); - - FOR (i = 0; i < l_Np; i++) - { - g_part[i] = mult_r(l_gain, g_part[i]); - move16(); - } - - FOR (i = l_Np; i < Np; i++) - { - g_part[i] = mult_r(r_gain, g_part[i]); - move16(); - } - - NearOppSplitAdjustment_fx( qband, qzero, st_fx->rc_num_bits_fx, st_fx->rc_range_fx, *bits_left, - strict_bits, Np, dim_part[0], dim_part[Np-1], - l_dim, r_dim, oppRQ3, - &l_bits, &r_bits, bits_left); - - - IF (sub(l_Np, 1) > 0) - { - decode_energies_fx( st_fx, l_Np, dim_part, bits_part, g_part, l_bits, bits_left, l_dim, strict_bits ); - } - ELSE - { - bits_part[0] = l_bits; - move16(); - } - - IF (sub(r_Np, 1) > 0) - { - decode_energies_fx( st_fx, r_Np, &dim_part[l_Np], &bits_part[l_Np], &g_part[l_Np], r_bits, bits_left, r_dim, strict_bits ); - } - ELSE - { - bits_part[1] = r_bits; - move16(); - } - - return; -} - -static void densitySymbolIndexDecode_fx(Decoder_State_fx *st_fx, - const Word16 density, - const Word16 opp_sz, - const Word16 near_sz, - Word16 *index_phi - ) -{ - Word16 density1, density2; - Word32 tmp1; - Word16 tmp2; - Word16 c, density_alpha, density_c; - Word32 sym_freq, cum_freq, tot, dec_freq; - Word16 angle, expo, r; - UWord16 lsb; - Word32 acc; - Word16 alpha=0; - - IF( s_and((Word16)0xFFFE, density) == 0 ) - { - /* odd density exit */ - *index_phi = -1; - return; - } - - sym_freq = L_deposit_l(1); - - angle = atan2_fx(SQRT_DIM_fx[opp_sz], SQRT_DIM_fx[near_sz]); - angle = shl(angle, 1); - angle = mult_r(angle, 20861); - c = mult_r(density, angle); - density_c = sub(density, c); - - tot = L_mac0(1L, density, add(density, 1)); - IF (c == 0) - { - dec_freq = rc_decode_fx(st_fx, tot); - - density1 = add(density, 1); - acc = L_mult0(density1, density1); - acc = L_sub(acc, dec_freq); - alpha = add(getSqrtWord32(acc), density1); - sym_freq = L_mac(1L, sub(density, alpha), 1); - cum_freq = L_mac0(L_mult(alpha, density), alpha, 1); - } - ELSE IF (sub(c, density) == 0) - { - dec_freq = rc_decode_fx(st_fx, tot); - - alpha = getSqrtWord32(dec_freq); - sym_freq = L_add(L_shl(alpha, 1), 1); - cum_freq = L_mult0(alpha, alpha); - } - ELSE - { - acc = L_mult0(density, c); - Mpy_32_16_ss(acc, density_c, &acc, &lsb); - acc = L_or(L_shl(acc, 16), L_and(lsb, 0xffffL)); /* Concatenate acc and lsb forming 48 bits; upshift 16 bits; keep 32 MSB. */ - acc = L_shr(acc, 1); /* Compensate fractional mode multiply (Mpy_32_16_ss) */ - tot = L_add(L_add(acc, (Word32)density), 1L); - - dec_freq = rc_decode_fx(st_fx, tot); - - acc = L_mult0(sub(density_c, 1), density_c); - Mpy_32_16_ss(acc, c, &acc, &lsb); - acc = L_or(L_shl(acc, 16), L_and(lsb, 0xffffL)); /* Concatenate acc and lsb forming 48 bits; upshift 16 bits; keep 32 MSB. */ - acc = L_shr(acc, 1); /* Compensate fractional mode multiply (Mpy_32_16_ss) */ - acc = L_add(acc, L_add(density, 1)); - acc = L_sub(acc, L_add(c, 1)); - acc = L_sub(tot, acc); - IF (L_sub(dec_freq, acc ) < 0) - { - acc = L_add((Word32)density_c, L_shl(dec_freq, 2)); - acc = L_sub(acc, 2); - Mpy_32_16_ss(acc, density_c, &acc, &lsb); - acc = L_or(L_shl(acc, 16), L_and(lsb, 0xffffL)); /* Concatenate acc and lsb forming 48 bits; upshift 16 bits; keep 32 MSB. */ - acc = L_shr(acc, 1); /* Compensate fractional mode multiply (Mpy_32_16_ss) */ - acc = L_add(acc, 1); - tmp2 = getSqrtWord32(acc); - acc = L_add(density_c, tmp2); - acc = L_sub(acc, 1); - r = ratio(acc, L_shl(density_c,1), &expo); - alpha = shr(r, add(14, expo)); - - acc = L_mult(alpha, density_c); - sym_freq = L_add(acc, 1); - acc = L_mult0(sub(alpha, 1), density_c); - acc = L_add(acc, 1); - cum_freq = L_mult0(alpha, extract_l(acc)); - } - ELSE - { - density1 = add(density, 1); - density2 = add(shl(density, 1), 1); - - acc = L_mult0(density, density1); - Mpy_32_16_ss(acc, c, &acc, &lsb); - acc = L_or(L_shl(acc, 16), L_and(lsb, 0xffffL)); /* Concatenate acc and lsb forming 48-bit; upshift 16 bits; keep 32 MSB. */ - acc = L_shr(acc, 1); /* Compensate fractional mode multiply (Mpy_32_16_ss) */ - acc = L_add(density1, acc); - acc = L_add(dec_freq, acc); - acc = L_sub(tot, acc); - Mpy_32_16_ss(acc, c, &acc, &lsb); - acc = L_or(L_shl(acc, 16), L_and(lsb, 0xffffL)); - acc = L_shr(acc, 1 - 2); - - tmp2 = extract_l(L_mac0(1L, c, density2)); - tmp1 = L_mult0(tmp2, tmp2); - tmp1 = L_add(tmp1, acc); - tmp2 = getSqrtWord32(tmp1); /* floor */ - if (L_msu0(tmp1, tmp2, tmp2) != 0) - { - tmp2 = add(tmp2, 1); /* convert to ceil */ - } - - acc = L_mult0(c, density2); - acc = L_add(acc, 1); - acc = L_sub(acc, tmp2); - r = ratio(acc, L_shl(c, 1), &expo); - alpha = shr(r, add(14, expo)); - - density_alpha = sub(density, alpha); - sym_freq = L_mac(1L, density_alpha, c); - acc = L_mult0(density_alpha, add(density_alpha, 1)); - Mpy_32_16_ss(acc, c, &acc, &lsb); - acc = L_or(L_shl(acc, 16), L_and(lsb, 0xffffL)); /* Concatenate acc and lsb forming 48-bit; upshift 16 bits; keep 32 MSB. */ - acc = L_shr(acc, 1); /* Compensate fractional mode multiply (Mpy_32_16_ss) */ - acc = L_sub(acc, alpha); - acc = L_add(acc, density1); - cum_freq = L_sub(tot, acc); - } - } - - rc_dec_update_fx(st_fx, cum_freq, sym_freq); - *index_phi = alpha; - return; -} - - -/*--------------------------------------------------------------------------* - * get_pvq_splits() - * - * Retrieve the number of segments - *--------------------------------------------------------------------------*/ - -static Word16 get_pvq_splits_fx( /* o : Number of segments */ - Decoder_State_fx *st_fx, /* i/o: Decoder state */ - const Word16 band_bits, /* i : Band bit rate */ - const Word16 sfmsize, /* i : Band width */ - Word16 *bits /* o : Used bits */ -) -{ - Word16 Np, i; - Word32 acc, flag; - - IF (band_bits == 0) - { - Np = 1; - move16(); - } - ELSE - { - acc = L_mult0(band_bits, 0x7a44); - Np = extract_l(L_shr(acc, 23)); /* Get integer part. */ - if (L_and(acc, 0x7fffffL) != 0) /* If fractional part != 0, add 1. */ - { - Np = add(Np, 1); /* ceiling operation */ - } - } - *bits = 0; - move16(); - IF (sub(Np, MAX_SPLITS) < 0) - { - acc = L_mult0(8*THR_ADD_SPLIT, sfmsize); - IF (L_sub(band_bits, acc) > 0) - { - flag = rc_dec_bits_fx(st_fx, 1); - *bits = 8; - move16(); - if (flag != 0) - { - Np = add(Np, 1); - } - } - } - /* Check constraints for number of splits */ - /* The following code assumes that PVQ_MAX_BAND_SIZE is 64 */ - i = shr(sfmsize, 6); /* 6 = log2(64) = log2(PVQ_MAX_BAND_SIZE) */ - if (s_and(sfmsize, 0x3f) != 0) - { - i = add(i, 1); /* ceiling operation */ - } - - Np = s_max(i, Np); - Np = s_min(MAX_SPLITS, Np); - Np = s_min(sfmsize, Np); /* The code line assumes that MIN_BAND_SIZE is 1 */ - return Np; -} - - diff --git a/src/libs/libevs/lib_dec/pvq_decode.cpp b/src/libs/libevs/lib_dec/pvq_decode.cpp new file mode 100644 index 00000000..d7b59b59 --- /dev/null +++ b/src/libs/libevs/lib_dec/pvq_decode.cpp @@ -0,0 +1,74 @@ +/*==================================================================================== + EVS Codec 3GPP TS26.443 Nov 13, 2018. Version 12.11.0 / 13.7.0 / 14.3.0 / 15.1.0 + ====================================================================================*/ + +#include "options.h" +#include "prot.h" +#include "rom_com.h" +#include "math.h" + + +/*-------------------------------------------------------------------* + * Function pvq_decode() * + * * + * PVQ subvector decoding algorithm * + *-------------------------------------------------------------------*/ + +void pvq_decode( + Decoder_State *st, + float *xq, /* o: decoded vector (scaled float) */ + short *y, /* o: decoded vector (non-scaled short)*/ + const short k_val, /* i: number of allocated pulses */ + const short dim, /* i: Length of vector */ + const float gain /* i: Gain */ +) +{ + short i; + float gain_fac; + float yy; + short output[PVQ_MAX_BAND_SIZE]; /* short interface as in STL-FIP */ + unsigned int h_mem[1+KMAX_NON_DIRECT+1]; /* allocate max offset memory for dim 6 */ + PvqEntry entry; + + entry = get_size_mpvq_calc_offset(dim, k_val, h_mem); /* get size & prepare H(adaptive table for entry.size=N_MPVQ(dim,k_val) */ + + if( dim != 1) + { + entry.lead_sign_ind = (short)rc_dec_bits(st, 1); + entry.index = rc_dec_uniform(st, entry.size); /* NB so far no PVQ-size wc is exactly 2^32-1 */ + /* safety check in case of bit errors */ + if( entry.index >= entry.size || st->ber_occured_in_pvq != 0 ) + { + st->ber_occured_in_pvq = 1; + st->BER_detect = 1; + entry.index = 0; /* a zero index will essentially disable PVQ index decompostion complexity */ + } + + } + else + { + entry.lead_sign_ind = (short)rc_dec_bits(st, 1); /* always a single sign bit */ + entry.index = 0; + } + mpvq_decode_vec(&entry, h_mem, output); + + for(i=0; i -#include "options.h" /* Compilation switches */ -#include "stl.h" -#include "prot_fx.h" -#include "rom_com_fx.h" - -/*-------------------------------------------------------------------* -* Function pvq_decode_fx() * -* * -* PVQ subvector decoding algorithm * -*-------------------------------------------------------------------*/ - -void pvq_decode_fx( - Decoder_State_fx *st_fx, - Word16 *xq, /* o: decoded vector (Q15) */ - Word16 *y, /* o: decoded vector (non-scaled int) */ - const Word16 k_val, /* i: number of allocated pulses */ - const Word16 dim, /* i: Length of vector */ - const Word16 neg_gain /* i: Gain (negated to fit 1.0 in Q15 as -1.0) */ -) -{ - Word16 i; - - UWord32 h_mem[1+KMAX_NON_DIRECT_FX+1]; /* allocate max offset memory for dim 6 */ - - PvqEntry_fx entry; - - Word16 neg_gain_norm, shift_num,shift_den,shift_tot; - Word32 L_yy,L_isqrt,L_tmp; - UWord16 u16_tmp; - - entry = get_size_mpvq_calc_offset_fx(dim, k_val, h_mem); /* get size & prepare H(adaptive table for entry.size=N_MPVQ(dim,k_val) */ - - IF( sub(dim, 1) != 0) - { - entry.lead_sign_ind = (short)rc_dec_bits_fx(st_fx, 1); - entry.index = rc_dec_uniform_fx(st_fx, entry.size); - - - /* safety check in case of bit errors */ - test(); - IF( L_sub(entry.index, entry.size) >= 0 || st_fx->ber_occured_in_pvq != 0 ) - { - st_fx->ber_occured_in_pvq = 1; - move16(); - st_fx->BER_detect = 1; - move16(); - entry.index = 0; - move16(); /* a zero index will essentially disable PVQ index decompostion complexity */ - } - - } - ELSE - { - entry.lead_sign_ind = (short)rc_dec_bits_fx(st_fx, 1); /* always a single sign bit */ - entry.index = L_deposit_l(0); - } - - mpvq_decode_vec_fx(&entry, h_mem, y); - - IF( neg_gain == 0 ) - { - FOR(i=0; i +#include +#include "options.h" +#include "cnst.h" +#include "rom_com.h" +#include "prot.h" + + +static short rc_dec_read( Decoder_State *st ); + +/*-------------------------------------------------------------------* + * rc_dec_init() + * + * Initialize range coder + *-------------------------------------------------------------------*/ + +void rc_dec_init( + Decoder_State *st, /* i/o: Decoder State */ + short tot_bits /* i : Total bit budget */ +) +{ + short i; + + st->rc_low = 0; + st->rc_range = 0xffffffff; + st->rc_num_bits = 0; + st->rc_offset = tot_bits + st->next_bit_pos; + st->rc_end = st->rc_offset; + + for (i = 0; i < 4; i++) + { + st->rc_low = (st->rc_low << 8) + rc_dec_read(st); + } + + return; +} + +/*-------------------------------------------------------------------* + * rc_decode() + * + * Decode symbol + *-------------------------------------------------------------------*/ + +unsigned int rc_decode( /* o : Decoded cumulative frequency */ + Decoder_State *st, /* i/o: Decoder State */ + unsigned int tot /* i : Total cumulative frequency */ +) +{ + unsigned int inv, val; + short exp; + + inv = UL_inverse(tot, &exp); + st->rc_help = UMult_32_32(st->rc_range, inv); + st->rc_help = st->rc_help >> (exp - 32); + + /* safety check in case of bit errors */ + val = st->rc_low/st->rc_help; + if (val > tot) + { + st->BER_detect = 1; + return 0; + } + return val; +} + +/*-------------------------------------------------------------------* + * rc_dec_update() + * + * Update range coder + *-------------------------------------------------------------------*/ + +void rc_dec_update( + Decoder_State *st, /* i/o: Decoder State */ + unsigned int cum_freq, /* i : Cumulative frequency */ + unsigned int sym_freq /* i : Symbol frequency */ +) +{ + st->rc_low = st->rc_low - cum_freq*st->rc_help; + st->rc_range = st->rc_help*sym_freq; + + while (st->rc_range < (1<<24)) + { + st->rc_num_bits += 8; + st->rc_low = (st->rc_low << 8) + rc_dec_read(st); + st->rc_range <<= 8; + } + + return; +} + +/*-------------------------------------------------------------------* + * rc_dec_bits() + * + * Encode bits + *-------------------------------------------------------------------*/ + +unsigned int rc_dec_bits( /* i : Decoded value */ + Decoder_State *st, /* i/o: Decoder State */ + short bits /* i : Number of bits */ +) +{ + unsigned int value; + + st->rc_num_bits += bits; + + if (bits > 16) + { + st->rc_offset -= bits - 16; + value = get_indice(st, st->rc_offset, bits - 16) << 16; + st->rc_offset -= 16; + value |= get_indice(st, st->rc_offset, 16); + } + else + { + st->rc_offset -= bits; + value = get_indice(st, st->rc_offset, bits); + + } + + return value; +} + +/*-------------------------------------------------------------------* + * rc_dec_uniform() + * + * Encode with uniform distribution + *-------------------------------------------------------------------*/ + +unsigned int rc_dec_uniform( /* i : Decoded value */ + Decoder_State *st, /* i/o: Decoder State */ + unsigned int tot /* i : Maximum value */ +) +{ + unsigned int value; + short n; + n = 32 - norm_ul(tot - 1); /* aligned to BASOP */ + if (n <= 8) + { + value = rc_decode(st, tot); + rc_dec_update(st, value, 1); + } + else + { + n -= 8; + value = rc_decode(st, (tot >> n) + 1); + rc_dec_update(st, value, 1); + value <<= n; + value |= rc_dec_bits(st, n); + } + + return value; +} + +/*-------------------------------------------------------------------* + * rc_dec_finish() + * + * Finalize range decoder + *-------------------------------------------------------------------*/ + +void rc_dec_finish(Decoder_State *st) +{ + st->next_bit_pos = st->rc_end; +} + + +/*-------------------------------------------------------------------* + * rc_dec_read() + * + * Read a byte from bit stream + *-------------------------------------------------------------------*/ + +static short rc_dec_read(Decoder_State *st) +{ + short bits; + + bits = st->rc_end - st->next_bit_pos; + + /* If the end of the buffer has been reached, pad the last byte with zeros */ + if (bits < 8) + { + return (short)(get_next_indice(st, bits) << (8-bits)); + } + else + { + return (short)get_next_indice(st, 8); + } +} + diff --git a/src/libs/libevs/lib_dec/range_dec_fx.cpp b/src/libs/libevs/lib_dec/range_dec_fx.cpp deleted file mode 100755 index c7a92987..00000000 --- a/src/libs/libevs/lib_dec/range_dec_fx.cpp +++ /dev/null @@ -1,204 +0,0 @@ -/*==================================================================================== - EVS Codec 3GPP TS26.442 Apr 03, 2018. Version 12.11.0 / 13.6.0 / 14.2.0 - ====================================================================================*/ - -#include -#include "options.h" /* Compilation switches */ -#include "cnst_fx.h" /* Common constants */ -#include "rom_com_fx.h" /* Static table prototypes */ -#include "prot_fx.h" /* Function prototypes */ - - -#include "stl.h" - - -static Word16 rc_dec_read_fx(Decoder_State_fx *st_fx); - -/*-------------------------------------------------------------------* - * rc_dec_init() - * - * Initialize range coder - *-------------------------------------------------------------------*/ - -void rc_dec_init_fx( - Decoder_State_fx *st_fx, /* i/o: Decoder State */ - Word16 tot_bits /* i : Total bit budget */ -) -{ - Word16 i; - - st_fx->rc_low_fx = L_deposit_l(0); - st_fx->rc_range_fx = 0xffffffff; - move32(); - st_fx->rc_num_bits_fx = 0; - move16(); - st_fx->rc_offset_fx = add(tot_bits, st_fx->next_bit_pos_fx); - st_fx->rc_end_fx = st_fx->rc_offset_fx; - move16(); - - FOR (i = 0; i < 4; i++) - { - st_fx->rc_low_fx = UL_addNsD(UL_lshl(st_fx->rc_low_fx, 8), UL_deposit_l(rc_dec_read_fx(st_fx))); - } -} - -/*-------------------------------------------------------------------* - * rc_decode() - * - * Decode symbol - *-------------------------------------------------------------------*/ - -UWord32 rc_decode_fx( /* o : Decoded cumulative frequency */ - Decoder_State_fx *st_fx, /* i/o: Decoder State */ - UWord32 tot /* i : Total cumulative frequency */ -) -{ - UWord32 inv, lsb, val, UL_tmp1, UL_tmp2; - Word16 exp_num, exp_den, exp; - UWord16 sgn; - - inv = UL_inverse(tot, &exp); - Mpy_32_32_uu(st_fx->rc_range_fx, inv, &(st_fx->rc_help_fx), &lsb);/*0+exp-32*/ - st_fx->rc_help_fx = UL_lshr(st_fx->rc_help_fx, sub(exp, 32)); - - exp_den = norm_ul(st_fx->rc_help_fx); - UL_tmp2 = UL_lshl(st_fx->rc_help_fx, exp_den); - exp_num = sub(norm_ul(st_fx->rc_low_fx), 1); - UL_tmp1 = UL_lshl(st_fx->rc_low_fx, exp_num); - exp = add(32, sub(exp_num, exp_den)); - - val = UL_div(UL_tmp1, UL_tmp2); - val = UL_lshr(val, exp); - - UL_tmp1 = UL_Mpy_32_32(val, st_fx->rc_help_fx); - UL_tmp2 = UL_Mpy_32_32(UL_addNsD(val, 1), st_fx->rc_help_fx); - UL_tmp1 = UL_subNsD(st_fx->rc_low_fx, UL_tmp1); - UL_tmp2 = UL_subNsD(st_fx->rc_low_fx, UL_tmp2); - if (UL_tmp2 < UL_tmp1) - { - val = UL_addNsD(val, 1); - } - - /* safety check in case of bit errors */ - UL_tmp1 = UL_subNs(tot,val,&sgn); - IF ( sgn != 0) - { - st_fx->BER_detect = 1; - move16(); - return 0; - } - - return val; -} - -/*-------------------------------------------------------------------* - * rc_dec_update() - * - * Update range coder - *-------------------------------------------------------------------*/ - -void rc_dec_update_fx( - Decoder_State_fx *st_fx, /* i/o: Decoder State */ - UWord32 cum_freq, /* i : Cumulative frequency */ - UWord32 sym_freq /* i : Symbol frequency */ -) -{ - st_fx->rc_low_fx = UL_subNsD(st_fx->rc_low_fx, UL_Mpy_32_32(cum_freq, st_fx->rc_help_fx)); /*0+0*/ - st_fx->rc_range_fx = UL_Mpy_32_32(st_fx->rc_help_fx, sym_freq); - - WHILE (st_fx->rc_range_fx < 1<<24) - { - L_sub(0, 0); /* For comparision in while*/ - st_fx->rc_num_bits_fx = add(st_fx->rc_num_bits_fx, 8); - st_fx->rc_low_fx = UL_addNsD(UL_lshl(st_fx->rc_low_fx, 8), UL_deposit_l(rc_dec_read_fx(st_fx))); - st_fx->rc_range_fx = UL_lshl(st_fx->rc_range_fx, 8); - } -} - -/*-------------------------------------------------------------------* - * rc_dec_bits() - * - * Encode bits - *-------------------------------------------------------------------*/ - -Word32 rc_dec_bits_fx( /* i : Decoded value */ - Decoder_State_fx *st_fx, /* i/o: Decoder State */ - Word16 bits /* i : Number of bits */ -) -{ - Word32 value; - - st_fx->rc_num_bits_fx = add(st_fx->rc_num_bits_fx, bits); - - IF (sub(bits, 16) > 0) - { - st_fx->rc_offset_fx = sub(st_fx->rc_offset_fx, sub(bits, 16)); - value = UL_lshl(UL_deposit_l(get_indice_fx(st_fx, st_fx->rc_offset_fx, sub(bits, 16))), 16); - st_fx->rc_offset_fx = sub(st_fx->rc_offset_fx, 16); - value = UL_or(value, UL_deposit_l(get_indice_fx(st_fx, st_fx->rc_offset_fx, 16))); - } - ELSE - { - st_fx->rc_offset_fx = sub(st_fx->rc_offset_fx, bits); - value = UL_deposit_l(get_indice_fx(st_fx, st_fx->rc_offset_fx, bits)); - } - - return value; -} - -/*-------------------------------------------------------------------* - * rc_dec_uniform() - * - * Encode with uniform distribution - *-------------------------------------------------------------------*/ - -UWord32 rc_dec_uniform_fx( /* i : Decoded value */ - Decoder_State_fx *st_fx, /* i/o: Decoder State */ - UWord32 tot /* i : Maximum value */ -) -{ - UWord32 value; - Word16 n; - n = sub(32, norm_ul(tot - 1)); - - IF (sub(n, 8) <= 0) - { - value = rc_decode_fx(st_fx, tot); - rc_dec_update_fx(st_fx, value, 1); - } - ELSE - { - n = sub(n, 8); - value = rc_decode_fx(st_fx, UL_addNsD(UL_lshr(tot, n), 1)); - rc_dec_update_fx(st_fx, value, 1); - value = UL_lshl(value, n); - value = UL_or(value, rc_dec_bits_fx(st_fx, n)); - } - - return value; -} - -/*-------------------------------------------------------------------* - * rc_dec_finish() - * - * Finalize range decoder - *-------------------------------------------------------------------*/ - -void rc_dec_finish_fx(Decoder_State_fx *st_fx) -{ - st_fx->next_bit_pos_fx = st_fx->rc_end_fx; -} - -/*-------------------------------------------------------------------* - * rc_dec_read() - * - * Read a byte from bit stream - *-------------------------------------------------------------------*/ - - -static Word16 rc_dec_read_fx(Decoder_State_fx *st_fx) -{ - return get_next_indice_fx(st_fx, 8); -} - - diff --git a/src/libs/libevs/lib_dec/re8_dec_fx.cpp b/src/libs/libevs/lib_dec/re8_dec.cpp old mode 100755 new mode 100644 similarity index 55% rename from src/libs/libevs/lib_dec/re8_dec_fx.cpp rename to src/libs/libevs/lib_dec/re8_dec.cpp index 7c41e379..48c9d13a --- a/src/libs/libevs/lib_dec/re8_dec_fx.cpp +++ b/src/libs/libevs/lib_dec/re8_dec.cpp @@ -1,48 +1,50 @@ /*==================================================================================== - EVS Codec 3GPP TS26.442 Apr 03, 2018. Version 12.11.0 / 13.6.0 / 14.2.0 + EVS Codec 3GPP TS26.443 Nov 13, 2018. Version 12.11.0 / 13.7.0 / 14.3.0 / 15.1.0 ====================================================================================*/ -#include "options.h" /* Compilation switches */ -#include "prot_fx.h" /* Function prototypes */ -#include "stl.h" +#include "options.h" +#include "prot.h" + +/*-------------------------------------------------------------------* + * Function prototypes + *-------------------------------------------------------------------*/ +void re8_decode_base_index(int n, long I, int *x); /*-------------------------------------------------------------------------- -* re8_dec_fx() -* -* MULTI-RATE INDEXING OF A POINT y in THE LATTICE RE8 (INDEX DECODING) -* note: the index I is defined as a 32-bit word, but only -* 16 bits are required (long can be replaced by unsigned integer) -*--------------------------------------------------------------------------*/ - -void re8_dec_fx( - Word16 n, /* i : codebook number (*n is an integer defined in {0,2,3,4,..,n_max}) */ - const UWord16 I, /* i : index of c (pointer to unsigned 16-bit word) */ - const Word16 k[], /* i : index of v (8-dimensional vector of binary indices) = Voronoi index */ - Word16 y[] /* o : point in RE8 (8-dimensional integer vector) */ -) + re8_dec(n, I, k, y) + MULTI-RATE INDEXING OF A POINT y in THE LATTICE RE8 (INDEX DECODING) + (i) n: codebook number (*n is an integer defined in {0,2,3,4,..,n_max}) + (i) I: index of c (pointer to unsigned 16-bit word) + (i) k: index of v (8-dimensional vector of binary indices) = Voronoi index + (o) y: point in RE8 (8-dimensional integer vector) + note: the index I is defined as a 32-bit word, but only + 16 bits are required (long can be replaced by unsigned integer) + -------------------------------------------------------------------------- + */ +void re8_dec(int n, long I, int k[], int y[]) { - Word16 i, m, v[8]; + int i, m, v[8]; + /*------------------------------------------------------------------------* * decode the sub-indices I and kv[] according to the codebook number n: * if n=0,2,3,4, decode I (no Voronoi extension) * if n>4, Voronoi extension is used, decode I and kv[] *------------------------------------------------------------------------*/ - IF( sub(n, 4) <= 0 ) + if (n <= 4) { - re8_decode_base_index_fx( n, I, y ); + re8_decode_base_index(n, I, y); } - ELSE + else { /*--------------------------------------------------------------------* * compute the Voronoi modulo m = 2^r where r is extension order *--------------------------------------------------------------------*/ - m = 0; - move16(); - - FOR (; n > 4; n -= 2) + m = 1; + while (n > 4) { - m = add(m, 1); + m *= 2; + n -= 2; } /*--------------------------------------------------------------------* @@ -50,21 +52,19 @@ void re8_dec_fx( * [here c is stored in y to save memory] *--------------------------------------------------------------------*/ - re8_decode_base_index_fx( n, I, y ); + re8_decode_base_index(n, I, y); /*--------------------------------------------------------------------* * decode Voronoi index k[] into v *--------------------------------------------------------------------*/ - re8_k2y_fx( k, m, v ); + re8_k2y(k, m, v); /*--------------------------------------------------------------------* * reconstruct y as y = m c + v (with m=2^r, r integer >=1) *--------------------------------------------------------------------*/ - FOR( i=0; i<8; i++ ) + for (i=0; i<8; i++) { - /* y[i] = m*y[i] + v[i] */ - y[i] = add(shl(y[i], m), v[i]); - move16(); + y[i] = m*y[i] + v[i]; } } diff --git a/src/libs/libevs/lib_dec/rom_dec.cpp b/src/libs/libevs/lib_dec/rom_dec.cpp new file mode 100644 index 00000000..86f35d0d --- /dev/null +++ b/src/libs/libevs/lib_dec/rom_dec.cpp @@ -0,0 +1,214 @@ +/*==================================================================================== + EVS Codec 3GPP TS26.443 Nov 13, 2018. Version 12.11.0 / 13.7.0 / 14.3.0 / 15.1.0 + ====================================================================================*/ + +#include "options.h" +#include "cnst.h" + +/*----------------------------------------------------------------------------------* + * LP filter for filtering periodic part of excitation in artificial onset + * construction after frame error concealment + *----------------------------------------------------------------------------------*/ + +const float h_low[5] = { -0.0125f, 0.1090f, 0.7813f, 0.1090f, -0.0125f }; + +/* RE8 related tables */ +const int mult_avq_tab[7] = {1,1,1,342,1,1,171}; +const int shift_avq_tab[7] = {0,0,1, 10,2,0, 10}; + +const short hntable[55]= +{ + 0X13, -0X10, -0X0F, -0X11, 0X51, 0X61, -0X0E, -0X12, 0X51, 0X61, + -0X13, -0X0D, 0X51, 0X62, -0X14, 0X81, -0X0C, 0X81, -0X15, -0X17, + 0X71, 0X81, -0X18, -0X16, 0X71, -0X0B, 0X71, -0X1A, 0X71, -0X09, + -0X1B, -0X0A, -0X19, 0X41, -0X1C, -0X08, 0X31, 0X41, -0X1D, -0X06, + 0X31, 0X41, -0X07, 0X41, -0X05, -0X1E, -0X04, -0X1F, 0X11, -0X03, + 0X11, -0X02, 0X11, -0X01, 0X00 +}; + +const short hetable[57]= +{ + 0X12, 0X41, -0X0F, 0X41, -0X10, -0X0E, 0X31, -0X11, 0X31, 0X41, + -0X0D, 0X41, -0X12, 0X42, -0x0C, 0X61, -0X13, 0X61, 0X71, -0X0A, + 0X71, -0X0B, -0X14, -0X15, 0X51, 0X61, -0X16, -0X09, 0X51, 0X61, + -0X17, 0X62, -0X08, 0X81, -0X07, 0X81, -0X18, -0X05, -0X04, -0X03, + 0X51, -0X06, 0X51, -0X19, 0X51, -0X01, -0X1C, -0X02, -0X1B, -0X1A, + 0X11, 0X00, 0X11, -0X1D, 0X11, -0X1E, -0X1F +}; + +const short hestable[15]= +{ + 0X11, 0X21, -0X04, 0X21, -0X03, 0X21, -0X02, -0X05, 0X11, 0X21, -0X01, -0X06, + 0X11, -0X07, -0X00 +}; + +const float lsf_tab[LPC_SHB_ORDER] = +{ + 0.070633653f, 0.11962059f, 0.16925794f, 0.20627696f, 0.24345790f, + 0.31293656f, 0.34594478f, 0.38072862f, 0.410051247f, 0.44525622f +}; + +/* frequency group start bins for transient analysis */ +/* 125 375 750 1250 2000 4000 8000 16000 24000 */ +const short gw[LGW_MAX] = { 1, 3, 6, 10, 16, 32, 64, 128, 192 }; + +/* 31.25 343.75 718.75 1218.75 1968.75 4000 8000 16000 24000 */ +const short gwlpr[LGW_MAX] = { 1, 3*QUOT_LPR_LTR-1, 6*QUOT_LPR_LTR-1, 10*QUOT_LPR_LTR-1, 16*QUOT_LPR_LTR-1, 32*QUOT_LPR_LTR, 64*QUOT_LPR_LTR, 128*QUOT_LPR_LTR, 192*QUOT_LPR_LTR }; + +const float w_hamm48k_2[L_TRANA48k/2] = +{ + 0.080000000000000f, 0.080061898522781f, 0.080247577432747f, 0.080556986759243f, 0.080990043232791f, 0.081546630307495f, 0.082226598192408f, 0.083029763891845f, + 0.083955911254630f, 0.085004791032270f, 0.086176120946031f, 0.087469585762906f, 0.088884837380455f, 0.090421494920485f, 0.092079144831552f, 0.093857341000262f, + 0.095755604871328f, 0.097773425576361f, 0.099910260071357f, 0.102165533282844f, 0.104538638262646f, 0.107028936351231f, 0.109635757349585f, 0.112358399699582f, + 0.115196130672791f, 0.118148186567665f, 0.121213772915079f, 0.124392064692135f, 0.127682206544200f, 0.131083313015096f, 0.134594468785406f, 0.138214728918801f, + 0.141943119116349f, 0.145778635978722f, 0.149720247276233f, 0.153766892226636f, 0.157917481780606f, 0.162170898914830f, 0.166525998932624f, 0.170981609771997f, + 0.175536532321084f, 0.180189540740855f, 0.184939382795015f, 0.189784780187013f, 0.194724428904063f, 0.199756999568084f, 0.204881137793469f, 0.210095464551578f, + 0.215398576541875f, 0.220789046569584f, 0.226265423929784f, 0.231826234797829f, 0.237469982625987f, 0.243195148546199f, 0.249000191778843f, 0.254883550047394f, + 0.260843639998870f, 0.266878857629950f, 0.272987578718653f, 0.279168159261450f, 0.285418935915708f, 0.291738226447335f, 0.298124330183510f, 0.304575528470374f, + 0.311090085135560f, 0.317666246955443f, 0.324302244126969f, 0.330996290743956f, 0.337746585277719f, 0.344551311061912f, 0.351408636781431f, 0.358316716965264f, + 0.365273692483159f, 0.372277691045950f, 0.379326827709445f, 0.386419205381703f, 0.393552915333588f, 0.400726037712459f, 0.407936642058840f, 0.415182787825961f, + 0.422462524902000f, 0.429773894134909f, 0.437114927859666f, 0.444483650427822f, 0.451878078739195f, 0.459296222775571f, 0.466736086136265f, 0.474195666575400f, + 0.481672956540759f, 0.489165943714067f, 0.496672611552554f, 0.504190939831653f, 0.511718905188695f, 0.519254481667438f, 0.526795641263308f, 0.534340354469178f, + 0.541886590821560f, 0.549432319447051f, 0.556975509608890f, 0.564514131253475f, 0.572046155556704f, 0.579569555469978f, 0.587082306265726f, 0.594582386082315f, + 0.602067776468170f, 0.609536462925001f, 0.616986435449943f, 0.624415689076500f, 0.631822224414129f, 0.639204048186324f, 0.646559173767056f, 0.653885621715418f, + 0.661181420308344f, 0.668444606071246f, 0.675673224306430f, 0.682865329619155f, 0.690018986441185f, 0.697132269551692f, 0.704203264595389f, 0.711230068597719f, + 0.718210790476997f, 0.725143551553344f, 0.732026486054283f, 0.738857741616868f, 0.745635479786192f, 0.752357876510168f, 0.759023122630418f, 0.765629424369165f, + 0.772175003811978f, 0.778658099386259f, 0.785076966335314f, 0.791429877187917f, 0.797715122223211f, 0.803931009930835f, 0.810075867466152f, 0.816148041100446f, + 0.822145896665987f, 0.828067819995822f, 0.833912217358185f, 0.839677515885409f, 0.845362163997224f, 0.850964631818323f, 0.856483411590088f, 0.861917018076364f, + 0.867263988963175f, 0.872522885252262f, 0.877692291648358f, 0.882770816940072f, 0.887757094374303f, 0.892649782024062f, 0.897447563149619f, 0.902149146552868f, + 0.906753266924821f, 0.911258685186131f, 0.915664188820559f, 0.919968592201292f, 0.924170736910022f, 0.928269492048706f, 0.932263754543917f, 0.936152449443706f, + 0.939934530206900f, 0.943608978984751f, 0.947174806894860f, 0.950631054287315f, 0.953976791002949f, 0.957211116623676f, 0.960333160714807f, 0.963342083059310f, + 0.966237073883933f, 0.969017354077129f, 0.971682175398738f, 0.974230820681355f, 0.976662604023336f, 0.978976870973391f, 0.981172998706713f, 0.983250396192597f, + 0.985208504353495f, 0.987046796215483f, 0.988764777050081f, 0.990361984507393f, 0.991837988740540f, 0.993192392521341f, 0.994424831347216f, 0.995534973539285f, + 0.996522520331626f, 0.997387205951684f, 0.998128797691797f, 0.998747095971820f, 0.999241934392838f, 0.999613179781951f, 0.999860732228111f, 0.999984525109009f +}; + +const float w_hamm32k_2[L_TRANA32k/2] = +{ + 0.080000000000000f, 0.080139632090179f, 0.080558443590627f, 0.081256180242538f, 0.082232418452750f, 0.083486565550910f, 0.085017860149273f, 0.086825372604947f, + 0.088908005584270f, 0.091264494728999f, 0.093893409423896f, 0.096793153665248f, 0.099961967029797f, 0.103397925743485f, 0.107098943849369f, 0.111062774473996f, + 0.115287011191475f, 0.119769089484404f, 0.124506288300781f, 0.129495731705944f, 0.134734390628539f, 0.140219084699457f, 0.145946484182623f, 0.151913111996467f, + 0.158115345824847f, 0.164549420316138f, 0.171211429369169f, 0.178097328504598f, 0.185202937320297f, 0.192523942029263f, 0.200055898078497f, 0.207794232847276f, + 0.215734248423172f, 0.223871124454139f, 0.232199921074925f, 0.240715581906049f, 0.249412937123505f, 0.258286706597345f, 0.267331503097225f, 0.276541835562968f, + 0.285912112438167f, 0.295436645064799f, 0.305109651136783f, 0.314925258210395f, 0.324877507269410f, 0.334960356342792f, 0.345167684172755f, 0.355493293930949f, + 0.365930916980537f, 0.376474216681854f, 0.387116792239357f, 0.397852182587524f, 0.408673870313343f, 0.419575285613002f, 0.430549810280395f, 0.441590781725011f, + 0.452691497016760f, 0.463845216955300f, 0.475045170161378f, 0.486284557187706f, 0.497556554646881f, 0.508854319353835f, 0.520170992480304f, 0.531499703718800f, + 0.542833575453544f, 0.554165726935838f, 0.565489278461346f, 0.576797355546729f, 0.588083093103121f, 0.599339639603893f, 0.610560161244195f, 0.621737846089724f, + 0.632865908212225f, 0.643937591809204f, 0.654946175305346f, 0.665884975433158f, 0.676747351290353f, 0.687526708371517f, 0.698216502571607f, 0.708810244158849f, + 0.719301501714632f, 0.729683906037996f, 0.739951154012344f, 0.750097012432047f, 0.760115321786592f, 0.770000000000000f, 0.779745046123229f, 0.789344543977327f, + 0.798792665745119f, 0.808083675509254f, 0.817211932734458f, 0.826171895691878f, 0.834958124823446f, 0.843565286044212f, 0.851988153980648f, 0.860221615142946f, + 0.868260671029406f, 0.876100441160999f, 0.883736166044290f, 0.891163210060907f, 0.898377064281809f, 0.905373349204632f, 0.912147817412476f, 0.918696356152490f, + 0.925014989832710f, 0.931099882435622f, 0.936947339846999f, 0.942553812098577f, 0.947915895523229f, 0.953030334821319f, 0.957894025036981f, 0.962504013443125f, + 0.966857501334024f, 0.970951845724403f, 0.974784560953977f, 0.978353320196492f, 0.981655956872329f, 0.984690465963826f, 0.987455005232518f, 0.989947896337551f, + 0.992167625854595f, 0.994112846194642f, 0.995782376422118f, 0.997175202971826f, 0.998290480264278f, 0.999127531219040f, 0.999685847665791f, 0.999965090652822f +}; + +const float w_hamm16k_2[L_TRANA16k/2] = +{ + 0.080000000000000f, 0.080562848541440f, 0.082250016781061f, 0.085057375935460f, 0.088978055926352f, 0.094002462192807f, 0.100118299170741f, 0.107310600382232f, + 0.115561765060989f, 0.124851601224384f, 0.135157375086613f, 0.146453866692083f, 0.158713431632863f, 0.171906068699192f, 0.185999493297458f, 0.200959216456013f, + 0.216748629225465f, 0.233329092266912f, 0.250660030408878f, 0.268699031941561f, 0.287401952405387f, 0.306723022619904f, 0.326614960688639f, 0.347029087705815f, + 0.367915446881795f, 0.389222925795719f, 0.410899381476157f, 0.432891768003705f, 0.455146266323232f, 0.477608415948132f, 0.500223248234257f, 0.522935420897402f, + 0.545689353445147f, 0.568429363191639f, 0.591099801522450f, 0.613645190076067f, 0.636010356508734f, 0.658140569510427f, 0.679981672741539f, 0.701480217362516f, + 0.722583592832128f, 0.743240155654278f, 0.763399355758289f, 0.783011860203399f, 0.802029673904734f, 0.820406257085326f, 0.838096639166738f, 0.855057528819616f, + 0.871247419904816f, 0.886626693045890f, 0.901157712584333f, 0.914804918680351f, 0.927534914333744f, 0.939316547111965f, 0.950120985385339f, 0.959921788882895f, + 0.968694973396140f, 0.976419069472435f, 0.983075174954342f, 0.988647001236375f, 0.993120913125941f, 0.996485962210947f, 0.998733913652397f, 0.999859266336418f +}; + +const float w_hamm8k_2[L_TRANA8k/2] = +{ + 0.080000000000000f, 0.082285843331915f, 0.089120655589670f, 0.100436509338375f, 0.116120942539613f, 0.136018076249695f, 0.159930163814642f, 0.187619556165270f, + 0.218811063680407f, 0.253194691144983f, 0.290428718621751f, 0.330143097617545f, 0.371943128791458f, 0.415413384654218f, 0.460121838273212f, 0.505624156950245f, + 0.551468118199513f, 0.597198104137843f, 0.642359629619905f, 0.686503859115775f, 0.729192067440081f, 0.770000000000000f, 0.808522089228003f, 0.844375485294555f, + 0.877203861041720f, 0.906680953322544f, 0.932513805550792f, 0.954445679235113f, 0.972258605561518f, 0.985775551665376f, 0.994862180063559f, 0.999428183760704f, +}; + +const float w_hamm_sana48k_2[L_PROT_HAMM_LEN2_48k] = +{ + 0.080000000000000f, 0.080027462973758f, 0.080109848615839f, 0.080247147089046f, 0.080439341999361f, 0.080686410397899f, 0.080988322783646f, 0.081345043106986f, + 0.081756528774001f, 0.082222730651560f, 0.082743593073186f, 0.083319053845701f, 0.083949044256652f, 0.084633489082516f, 0.085372306597683f, 0.086165408584215f, + 0.087012700342376f, 0.087914080701944f, 0.088869442034286f, 0.089878670265216f, 0.090941644888610f, 0.092058238980796f, 0.093228319215714f, 0.094451745880830f, + 0.095728372893819f, 0.097058047820012f, 0.098440611890594f, 0.099875900021559f, 0.101363740833430f, 0.102903956671715f, 0.104496363628120f, 0.106140771562514f, + 0.107836984125627f, 0.109584798782499f, 0.111384006836658f, 0.113234393455047f, 0.115135737693669f, 0.117087812523972f, 0.119090384859956f, 0.121143215586007f, + 0.123246059585445f, 0.125398665769793f, 0.127600777108759f, 0.129852130660926f, 0.132152457605149f, 0.134501483272651f, 0.136898927179823f, 0.139344503061711f, + 0.141837918906203f, 0.144378876988888f, 0.146967073908615f, 0.149602200623714f, 0.152283942488898f, 0.155011979292835f, 0.157785985296381f, 0.160605629271474f, + 0.163470574540687f, 0.166380479017425f, 0.169334995246772f, 0.172333770446984f, 0.175376446551605f, 0.178462660252227f, 0.181592043041866f, 0.184764221258970f, + 0.187978816132029f, 0.191235443824805f, 0.194533715482165f, 0.197873237276507f, 0.201253610454792f, 0.204674431386151f, 0.208135291610080f, 0.211635777885218f, + 0.215175472238683f, 0.218753952015982f, 0.222370789931481f, 0.226025554119419f, 0.229717808185479f, 0.233447111258894f, 0.237213018045087f, 0.241015078878844f, + 0.244852839778006f, 0.248725842497672f, 0.252633624584921f, 0.256575719434027f, 0.260551656342175f, 0.264560960565666f, 0.268603153376600f, 0.272677752120042f, + 0.276784270271653f, 0.280922217495778f, 0.285091099704000f, 0.289290419114133f, 0.293519674309662f, 0.297778360299609f, 0.302065968578839f, 0.306381987188769f, + 0.310725900778505f, 0.315097190666374f, 0.319495334901855f, 0.323919808327907f, 0.328370082643670f, 0.332845626467550f, 0.337345905400666f, 0.341870382090660f, + 0.346418516295861f, 0.350989764949788f, 0.355583582225999f, 0.360199419603261f, 0.364836725931051f, 0.369494947495359f, 0.374173528084809f, 0.378871909057071f, + 0.383589529405564f, 0.388325825826447f, 0.393080232785873f, 0.397852182587524f, 0.402641105440390f, 0.407446429526807f, 0.412267581070735f, 0.417103984406268f, + 0.421955062046372f, 0.426820234751838f, 0.431698921600448f, 0.436590540056336f, 0.441494506039550f, 0.446410233995788f, 0.451337136966322f, 0.456274626658076f, + 0.461222113513879f, 0.466179006782852f, 0.471144714590954f, 0.476118644011648f, 0.481100201136704f, 0.486088791147110f, 0.491083818384099f, 0.496084686420271f, + 0.501090798130810f, 0.506101555764784f, 0.511116361016516f, 0.516134615097028f, 0.521155718805537f, 0.526179072601003f, 0.531204076673714f, 0.536230131016910f, + 0.541256635498423f, 0.546282989932337f, 0.551308594150653f, 0.556332848074950f, 0.561355151788038f, 0.566374905605590f, 0.571391510147749f, 0.576404366410692f, + 0.581412875838160f, 0.586416440392922f, 0.591414462628186f, 0.596406345758937f, 0.601391493733196f, 0.606369311303187f, 0.611339204096419f, 0.616300578686650f, + 0.621252842664750f, 0.626195404709433f, 0.631127674657866f, 0.636049063576134f, 0.640958983829565f, 0.645856849152894f, 0.650742074720264f, 0.655614077215060f, + 0.660472274899558f, 0.665316087684385f, 0.670144937197788f, 0.674958246854690f, 0.679755441925542f, 0.684535949604939f, 0.689299199080028f, 0.694044621598654f, + 0.698771650537277f, 0.703479721468629f, 0.708168272229108f, 0.712836742985904f, 0.717484576303842f, 0.722111217211948f, 0.726716113269708f, 0.731298714633038f, + 0.735858474119933f, 0.740394847275806f, 0.744907292438496f, 0.749395270802946f, 0.753858246485539f, 0.758295686588082f, 0.762707061261442f, 0.767091843768804f, + 0.771449510548575f, 0.775779541276891f, 0.780081418929751f, 0.784354629844749f, 0.788598663782413f, 0.792813013987120f, 0.796997177247615f, 0.801150653957089f, + 0.805272948172839f, 0.809363567675482f, 0.813422024027731f, 0.817447832632716f, 0.821440512791844f, 0.825399587762201f, 0.829324584813474f, 0.833215035284397f, + 0.837070474638713f, 0.840890442520641f, 0.844674482809841f, 0.848422143675885f, 0.852132977632196f, 0.855806541589490f, 0.859442396908678f, 0.863040109453242f, + 0.866599249641071f, 0.870119392495760f, 0.873600117697347f, 0.877041009632507f, 0.880441657444176f, 0.883801655080607f, 0.887120601343857f, 0.890398099937691f, + 0.893633759514900f, 0.896827193724033f, 0.899978021255524f, 0.903085865887227f, 0.906150356529334f, 0.909171127268689f, 0.912147817412476f, 0.915080071531290f, + 0.917967539501574f, 0.920809876547428f, 0.923606743281775f, 0.926357805746886f, 0.929062735454256f, 0.931721209423824f, 0.934332910222545f, 0.936897526002284f, + 0.939414750537061f, 0.941884283259609f, 0.944305829297265f, 0.946679099507180f, 0.949003810510844f, 0.951279684727920f, 0.953506450409391f, 0.955683841670007f, + 0.957811598520034f, 0.959889466896295f, 0.961917198692508f, 0.963894551788914f, 0.965821290081179f, 0.967697183508596f, 0.969522008081546f, 0.971295545908249f, + 0.973017585220782f, 0.974687920400358f, 0.976306352001886f, 0.977872686777781f, 0.979386737701038f, 0.980848323987568f, 0.982257271117780f, 0.983613410857422f, + 0.984916581277667f, 0.986166626774449f, 0.987363398087044f, 0.988506752315891f, 0.989596552939653f, 0.990632669831523f, 0.991614979274757f, 0.992543363977448f, + 0.993417713086533f, 0.994237922201026f, 0.995003893384487f, 0.995715535176712f, 0.996372762604660f, 0.996975497192592f, 0.997523666971448f, 0.998017206487434f, + 0.998456056809844f, 0.998840165538090f, 0.999169486807964f, 0.999443981297112f, 0.999663616229731f, 0.999828365380479f, 0.999938209077610f, 0.999993134205322f +}; + +const float w_hamm_sana32k_2[L_PROT_HAMM_LEN2_32k] = +{ + 0.080000000000000f, 0.080061898522781f, 0.080247577432747f, 0.080556986759243f, 0.080990043232791f, 0.081546630307495f, 0.082226598192408f, 0.083029763891845f, + 0.083955911254630f, 0.085004791032270f, 0.086176120946031f, 0.087469585762906f, 0.088884837380455f, 0.090421494920485f, 0.092079144831552f, 0.093857341000262f, + 0.095755604871328f, 0.097773425576361f, 0.099910260071357f, 0.102165533282844f, 0.104538638262646f, 0.107028936351231f, 0.109635757349585f, 0.112358399699582f, + 0.115196130672791f, 0.118148186567665f, 0.121213772915079f, 0.124392064692135f, 0.127682206544200f, 0.131083313015096f, 0.134594468785406f, 0.138214728918801f, + 0.141943119116349f, 0.145778635978722f, 0.149720247276233f, 0.153766892226636f, 0.157917481780606f, 0.162170898914830f, 0.166525998932624f, 0.170981609771997f, + 0.175536532321084f, 0.180189540740855f, 0.184939382795015f, 0.189784780187013f, 0.194724428904063f, 0.199756999568084f, 0.204881137793469f, 0.210095464551578f, + 0.215398576541875f, 0.220789046569584f, 0.226265423929784f, 0.231826234797829f, 0.237469982625987f, 0.243195148546199f, 0.249000191778843f, 0.254883550047394f, + 0.260843639998870f, 0.266878857629950f, 0.272987578718653f, 0.279168159261450f, 0.285418935915708f, 0.291738226447335f, 0.298124330183510f, 0.304575528470374f, + 0.311090085135560f, 0.317666246955443f, 0.324302244126969f, 0.330996290743956f, 0.337746585277719f, 0.344551311061912f, 0.351408636781431f, 0.358316716965264f, + 0.365273692483159f, 0.372277691045950f, 0.379326827709445f, 0.386419205381703f, 0.393552915333588f, 0.400726037712459f, 0.407936642058840f, 0.415182787825961f, + 0.422462524902000f, 0.429773894134909f, 0.437114927859666f, 0.444483650427822f, 0.451878078739195f, 0.459296222775571f, 0.466736086136265f, 0.474195666575400f, + 0.481672956540759f, 0.489165943714067f, 0.496672611552554f, 0.504190939831653f, 0.511718905188695f, 0.519254481667438f, 0.526795641263308f, 0.534340354469178f, + 0.541886590821560f, 0.549432319447051f, 0.556975509608890f, 0.564514131253475f, 0.572046155556704f, 0.579569555469978f, 0.587082306265726f, 0.594582386082315f, + 0.602067776468170f, 0.609536462925001f, 0.616986435449943f, 0.624415689076500f, 0.631822224414129f, 0.639204048186324f, 0.646559173767056f, 0.653885621715418f, + 0.661181420308344f, 0.668444606071246f, 0.675673224306430f, 0.682865329619155f, 0.690018986441185f, 0.697132269551692f, 0.704203264595389f, 0.711230068597719f, + 0.718210790476997f, 0.725143551553344f, 0.732026486054283f, 0.738857741616868f, 0.745635479786192f, 0.752357876510168f, 0.759023122630418f, 0.765629424369165f, + 0.772175003811978f, 0.778658099386259f, 0.785076966335314f, 0.791429877187917f, 0.797715122223211f, 0.803931009930835f, 0.810075867466152f, 0.816148041100446f, + 0.822145896665987f, 0.828067819995822f, 0.833912217358185f, 0.839677515885409f, 0.845362163997224f, 0.850964631818323f, 0.856483411590088f, 0.861917018076364f, + 0.867263988963175f, 0.872522885252262f, 0.877692291648358f, 0.882770816940072f, 0.887757094374303f, 0.892649782024062f, 0.897447563149619f, 0.902149146552868f, + 0.906753266924821f, 0.911258685186131f, 0.915664188820559f, 0.919968592201292f, 0.924170736910022f, 0.928269492048706f, 0.932263754543917f, 0.936152449443706f, + 0.939934530206900f, 0.943608978984751f, 0.947174806894860f, 0.950631054287315f, 0.953976791002949f, 0.957211116623676f, 0.960333160714807f, 0.963342083059310f, + 0.966237073883933f, 0.969017354077129f, 0.971682175398738f, 0.974230820681355f, 0.976662604023336f, 0.978976870973391f, 0.981172998706713f, 0.983250396192597f, + 0.985208504353495f, 0.987046796215483f, 0.988764777050081f, 0.990361984507393f, 0.991837988740540f, 0.993192392521341f, 0.994424831347216f, 0.995534973539285f, + 0.996522520331626f, 0.997387205951684f, 0.998128797691797f, 0.998747095971820f, 0.999241934392838f, 0.999613179781951f, 0.999860732228111f, 0.999984525109009f +}; + +const float w_hamm_sana16k_2[L_PROT_HAMM_LEN2_16k] = +{ + 0.080000000000000f, 0.080248875229243f, 0.080995231617495f, 0.082238261557724f, 0.083976620009229f, 0.086208425953062f, 0.088931264427414f, 0.092142189140766f, + 0.095837725659970f, 0.100013875169814f, 0.104666118800010f, 0.109789422514906f, 0.115378242560646f, 0.121426531463883f, 0.127927744575542f, 0.134874847152564f, + 0.142260321969963f, 0.150076177454966f, 0.158313956334418f, 0.166964744786114f, 0.176019182084144f, 0.185467470727822f, 0.195299387043225f, 0.205504292245887f, + 0.216071143952672f, 0.226988508130357f, 0.238244571468020f, 0.249827154159818f, 0.261723723084350f, 0.273921405366317f, 0.286407002305832f, 0.299167003660284f, + 0.312187602263317f, 0.325454708965093f, 0.338953967877692f, 0.352670771909129f, 0.366590278569198f, 0.380697426030022f, 0.394976949423959f, 0.409413397361190f, + 0.423991148649151f, 0.438694429195694f, 0.453507329077705f, 0.468413819756689f, 0.483397771422710f, 0.498442970447917f, 0.513533136930761f, 0.528651942311926f, + 0.543783027042910f, 0.558910018288144f, 0.574016547641481f, 0.589086268837895f, 0.604102875441222f, 0.619050118488809f, 0.633911824073957f, 0.648671910847171f, + 0.663314407417236f, 0.677823469633322f, 0.692183397729409f, 0.706378653312465f, 0.720393876176025f, 0.734213900920944f, 0.747823773365368f, 0.761208766726146f, + 0.774354397554188f, 0.787246441406510f, 0.799870948238030f, 0.812214257496436f, 0.824263012903808f, 0.836004176908999f, 0.847425044795124f, 0.858513258426909f, + 0.869256819623006f, 0.879644103138828f, 0.889663869245825f, 0.899305275893620f, 0.908557890441822f, 0.917411700948838f, 0.925857127005450f, 0.933885030101461f, + 0.941486723514159f, 0.948653981707932f, 0.955379049234843f, 0.961654649126531f, 0.967473990768381f, 0.972830777247415f, 0.977719212165966f, 0.982134005913770f, + 0.986070381391670f, 0.989524079180756f, 0.992491362151336f, 0.994969019506760f, 0.996954370257714f, 0.998445266123226f, 0.999440093855253f, 0.999937776984316f +}; + + +/* er_dec_tcx.c */ +const float h_high3_32[L_FIR_FER2] = {-0.0517f, -0.0587f, -0.0820f, -0.1024f, -0.1164f, 0.8786f, -0.1164f, -0.1024f, -0.0820f, -0.0587f, -0.0517f}; +const float h_high3_16[L_FIR_FER2] = { 0.f, -0.0205f, -0.0651f, -0.1256f, -0.1792f, 0.8028f, -0.1792f, -0.1256f, -0.0651f, -0.0205f, 0.f }; + diff --git a/src/libs/libevs/lib_dec/rom_dec.h b/src/libs/libevs/lib_dec/rom_dec.h new file mode 100644 index 00000000..0a895a9b --- /dev/null +++ b/src/libs/libevs/lib_dec/rom_dec.h @@ -0,0 +1,38 @@ +/*==================================================================================== + EVS Codec 3GPP TS26.443 Nov 13, 2018. Version 12.11.0 / 13.7.0 / 14.3.0 / 15.1.0 + ====================================================================================*/ + +#ifndef ROM_DEC_H +#define ROM_DEC_H + +#include +#include "options.h" +#include "cnst.h" + +extern const float h_low[]; /* LP filter for filtering periodic part of excitation in artificial onset construction after FEC */ + +extern const int mult_avq_tab[]; +extern const int shift_avq_tab[]; + +extern const short hntable[55]; +extern const short hetable[57]; +extern const short hestable[15]; + +extern const float lsf_tab[LPC_SHB_ORDER]; + +extern const short gw[LGW_MAX]; +extern const short gwlpr[LGW_MAX]; +extern const float w_hamm32k_2[L_TRANA32k/2]; +extern const float w_hamm16k_2[L_TRANA16k/2]; +extern const float w_hamm8k_2[L_TRANA8k/2]; +extern const float w_hamm_sana32k_2[L_PROT_HAMM_LEN2_32k]; +extern const float w_hamm_sana16k_2[L_PROT_HAMM_LEN2_16k]; +extern const float w_hamm48k_2[L_TRANA48k/2]; +extern const float w_hamm_sana48k_2[L_PROT_HAMM_LEN2_48k]; + +extern const float h_high3_32[L_FIR_FER2]; +extern const float h_high3_16[L_FIR_FER2]; + + +#endif + diff --git a/src/libs/libevs/lib_dec/rom_dec_fx.cpp b/src/libs/libevs/lib_dec/rom_dec_fx.cpp deleted file mode 100755 index ec50f103..00000000 --- a/src/libs/libevs/lib_dec/rom_dec_fx.cpp +++ /dev/null @@ -1,456 +0,0 @@ -/*==================================================================================== - EVS Codec 3GPP TS26.442 Apr 03, 2018. Version 12.11.0 / 13.6.0 / 14.2.0 - ====================================================================================*/ - -#include "stl.h" -#include "cnst_fx.h" /* Common constants */ -#include "basop_util.h" - -/* 125 375 750 1250 2000 4000 8000 16000 24000 */ -const Word16 gw_fx[Lgw_max] = { 1, 3, 6, 10, 16, 32, 64, 128, 192 }; /* frequency group start bins for transient analysis */ - -const Word16 gw_len_inv_fx[Lgw_max-1] = /* Q15 */ -{ - 16384, 10923, 8192, 5461, - 2048, 1024, 512, 512, -}; - -/* 31.25 343.75 718.75 1218.75 1968.75 4000 8000 16000 24000 */ -const Word16 gwlpr_fx[Lgw_max] = { 1, 3*Quot_Lpr_Ltr-1, 6*Quot_Lpr_Ltr-1, 10*Quot_Lpr_Ltr-1, 16*Quot_Lpr_Ltr-1, 32*Quot_Lpr_Ltr, 64*Quot_Lpr_Ltr, 128*Quot_Lpr_Ltr, 192*Quot_Lpr_Ltr }; /* frequency group start bins for transient analysis */ - - -const Word16 hestable_fx[15]= -{ - 0X11, 0X21, -0X04, 0X21, -0X03, 0X21, -0X02, -0X05, 0X11, 0X21, -0X01, -0X06, - 0X11, -0X07, -0X00 -}; -/*-------------------------------------------------------------------* - * num x 32768 + 0.5 - * ------------------- - * PIT_MAX x Fact - * Tables fill at compiled time - *-------------------------------------------------------------------*/ - -#define PIT_MAX_DIV(num, fact) ((num*32768L+(fact)*PIT_MAX/2) / ((fact)*PIT_MAX)) -#define PIT_MAX_DIV16k(num, fact) ((num*32768L+(fact)*PIT16k_MAX/2) / ((fact)*PIT16k_MAX)) - -/*----------------------------------------------------------------------------------* - * hp filter for filtering random part of excitation in frame error concealment - * Used in lib_dec\syn_bfi.c - *----------------------------------------------------------------------------------*/ - -const Word16 h_high_fx[5] = { -410, -3572, 25602, -3572, -410 }; -const Word16 inv_sqi[15] = -{ - 8192, /* 1/4 */ - 3641, /* 1/9 */ - 2048, /* 1/16 */ - 1311, /* 1/25 */ - 910, /* 1/36 */ - 669, /* 1/49 */ - 512, /* 1/64 */ - 405, /* 1/81 */ - 328, /* 1/100 */ - 271, /* 1/121 */ - 228, /* 1/144 */ - 194, /* 1/169 */ - 167, /* 1/196 */ - 146, /* 1/225 */ - 128 /* 1/256 */ -}; -/*-------------------------------------------------------------------* - * index square used in fec_adapt_codebook - *-------------------------------------------------------------------*/ -const Word16 sqi[15] = -{ - 4, /* 2 */ - 9, /* 3 */ - 16, /* 4 */ - 25, /* 5 */ - 36, /* 6 */ - 49, /* 7 */ - 64, /* 8 */ - 81, /* 9 */ - 100, /* 10 */ - 121, /* 11 */ - 144, /* 12 */ - 169, /* 13 */ - 196, /* 14 */ - 225, /* 15 */ - 256 /* 16 */ -}; -/*------------------------------------------------------------------------------* - * RE8 related tables rom - *------------------------------------------------------------------------------*/ - -/* NOTE: Many values here could fit in shorts instead of ints */ - -const Word16 mult_avq_tab_fx[7] = {1,1,1,342,1,1,171}; -const Word16 shift_avq_tab_fx[7] = {0,0,1, 10,2,0, 10}; - -/*----------------------------------------------------------------------------------* - * HR SWB BWE parameters - *----------------------------------------------------------------------------------*/ -const Word16 swb_hr_inv_frm_len[4] = /* in Q19 */ -{ - 26214, /* 1/(160/8) */ - 13107, /* 1/(320/8) */ - 6554, /* 1/(640/8) */ - 4369 /* 1/(960/8) */ -}; -const Word16 inv_tbl_2n_minus1[] = { -1, -1, /* Bits = 0 and 1 are not used */ - 21845/*Q16*/, - 18725/*Q17*/, - 17476/*Q18*/, - 16913/*Q19*/, - 16644/*Q20*/, - 16513/*Q21*/ - }; /* in Qx */ - - -const Word16 hntable_fx[55]= -{ - 0X13, -0X10, -0X0F, -0X11, 0X51, 0X61, -0X0E, -0X12, 0X51, 0X61, - -0X13, -0X0D, 0X51, 0X62, -0X14, 0X81, -0X0C, 0X81, -0X15, -0X17, - 0X71, 0X81, -0X18, -0X16, 0X71, -0X0B, 0X71, -0X1A, 0X71, -0X09, - -0X1B, -0X0A, -0X19, 0X41, -0X1C, -0X08, 0X31, 0X41, -0X1D, -0X06, - 0X31, 0X41, -0X07, 0X41, -0X05, -0X1E, -0X04, -0X1F, 0X11, -0X03, - 0X11, -0X02, 0X11, -0X01, 0X00 -}; - -const Word16 hetable_fx[57]= -{ - 0X12, 0X41, -0X0F, 0X41, -0X10, -0X0E, 0X31, -0X11, 0X31, 0X41, - -0X0D, 0X41, -0X12, 0X42, -0x0C, 0X61, -0X13, 0X61, 0X71, -0X0A, - 0X71, -0X0B, -0X14, -0X15, 0X51, 0X61, -0X16, -0X09, 0X51, 0X61, - -0X17, 0X62, -0X08, 0X81, -0X07, 0X81, -0X18, -0X05, -0X04, -0X03, - 0X51, -0X06, 0X51, -0X19, 0X51, -0X01, -0X1C, -0X02, -0X1B, -0X1A, - 0X11, 0X00, 0X11, -0X1D, 0X11, -0X1E, -0X1F -}; - -const Word16 lsf_tab_fx[LPC_SHB_ORDER] = -{ - 2315, 3920, 5546, 6759, 7978, - 10254, 11336, 12476, 13437, 14590 -}; - - -/*-----------------------------------------------------------------------------* - * lp filter for filtering periodic part of excitation in artificial onset - * construction after frame error concealment - * Used in lib_dec\onset_fx.c - *-----------------------------------------------------------------------------*/ - -const Word16 H_low[5] = -{ - -410, 3572, 25602, 3572, -410 -}; - -const Word16 w_hamm48k_2_fx[Ltrana48k/2] = -{ - 2621, 2623, 2630, 2640, 2654, 2672, 2694, 2721, - 2751, 2785, 2824, 2866, 2913, 2963, 3017, 3076, - 3138, 3204, 3274, 3348, 3426, 3507, 3593, 3682, - 3775, 3871, 3972, 4076, 4184, 4295, 4410, 4529, - 4651, 4777, 4906, 5039, 5175, 5314, 5457, 5603, - 5752, 5904, 6060, 6219, 6381, 6546, 6714, 6884, - 7058, 7235, 7414, 7596, 7781, 7969, 8159, 8352, - 8547, 8745, 8945, 9148, 9353, 9560, 9769, 9980, - 10194, 10409, 10627, 10846, 11067, 11290, 11515, 11741, - 11969, 12199, 12430, 12662, 12896, 13131, 13367, 13605, - 13843, 14083, 14323, 14565, 14807, 15050, 15294, 15538, - 15783, 16029, 16275, 16521, 16768, 17015, 17262, 17509, - 17757, 18004, 18251, 18498, 18745, 18991, 19238, 19483, - 19729, 19973, 20217, 20461, 20704, 20945, 21186, 21427, - 21666, 21904, 22140, 22376, 22611, 22844, 23075, 23306, - 23534, 23762, 23987, 24211, 24433, 24653, 24872, 25088, - 25303, 25515, 25725, 25934, 26140, 26343, 26545, 26744, - 26940, 27134, 27326, 27515, 27701, 27884, 28065, 28243, - 28419, 28591, 28760, 28927, 29090, 29250, 29408, 29562, - 29712, 29860, 30004, 30146, 30283, 30418, 30548, 30676, - 30800, 30920, 31037, 31150, 31260, 31366, 31468, 31567, - 31662, 31753, 31840, 31924, 32003, 32079, 32151, 32219, - 32283, 32344, 32400, 32452, 32501, 32545, 32585, 32622, - 32654, 32682, 32707, 32727, 32743, 32755, 32763, 32767 -}; - -const Word16 w_hamm32k_2_fx[Ltrana32k/2]= -{ - 2621, 2626, 2640, 2663, 2695, 2736, 2786, 2845, - 2913, 2991, 3077, 3172, 3276, 3388, 3509, 3639, - 3778, 3925, 4080, 4243, 4415, 4595, 4782, 4978, - 5181, 5392, 5610, 5836, 6069, 6309, 6555, 6809, - 7069, 7336, 7609, 7888, 8173, 8464, 8760, 9062, - 9369, 9681, 9998, 10319, 10646, 10976, 11310, 11649, - 11991, 12336, 12685, 13037, 13391, 13749, 14108, 14470, - 14834, 15199, 15566, 15935, 16304, 16674, 17045, 17416, - 17788, 18159, 18530, 18900, 19270, 19639, 20007, 20373, - 20738, 21101, 21461, 21820, 22176, 22529, 22879, 23226, - 23570, 23910, 24247, 24579, 24907, 25231, 25551, 25865, - 26175, 26479, 26778, 27072, 27360, 27642, 27918, 28188, - 28451, 28708, 28958, 29202, 29438, 29667, 29889, 30104, - 30311, 30510, 30702, 30886, 31061, 31229, 31388, 31539, - 31682, 31816, 31942, 32059, 32167, 32266, 32357, 32439, - 32511, 32575, 32630, 32675, 32712, 32739, 32758, 32767 -}; - -const Word16 w_hamm16k_2_fx[Ltrana16k/2] = -{ - 2621, 2640, 2695, 2787, 2916, 3080, 3281, 3516, - 3787, 4091, 4429, 4799, 5201, 5633, 6095, 6585, - 7102, 7646, 8214, 8805, 9418, 10051, 10703, 11371, - 12056, 12754, 13464, 14185, 14914, 15650, 16391, 17136, - 17881, 18626, 19369, 20108, 20841, 21566, 22282, 22986, - 23678, 24354, 25015, 25658, 26281, 26883, 27463, 28019, - 28549, 29053, 29529, 29976, 30393, 30780, 31134, 31455, - 31742, 31995, 32213, 32396, 32543, 32653, 32727, 32763 -}; - - -const Word16 w_hamm_sana48k_2_fx[288] = -{ - 2621, 2622, 2625, 2630, 2636, 2644, 2654, 2666, - 2679, 2694, 2711, 2730, 2751, 2773, 2797, 2823, - 2851, 2881, 2912, 2945, 2980, 3017, 3055, 3095, - 3137, 3180, 3226, 3273, 3321, 3372, 3424, 3478, - 3534, 3591, 3650, 3710, 3773, 3837, 3902, 3970, - 4039, 4109, 4181, 4255, 4330, 4407, 4486, 4566, - 4648, 4731, 4816, 4902, 4990, 5079, 5170, 5263, - 5357, 5452, 5549, 5647, 5747, 5848, 5950, 6054, - 6160, 6266, 6374, 6484, 6595, 6707, 6820, 6935, - 7051, 7168, 7287, 7406, 7527, 7650, 7773, 7898, - 8023, 8150, 8278, 8407, 8538, 8669, 8802, 8935, - 9070, 9205, 9342, 9479, 9618, 9758, 9898, 10040, - 10182, 10325, 10469, 10614, 10760, 10907, 11054, 11202, - 11351, 11501, 11652, 11803, 11955, 12108, 12261, 12415, - 12569, 12725, 12880, 13037, 13194, 13351, 13509, 13668, - 13827, 13986, 14146, 14306, 14467, 14628, 14789, 14951, - 15113, 15276, 15438, 15601, 15765, 15928, 16092, 16256, - 16420, 16584, 16748, 16913, 17077, 17242, 17406, 17571, - 17736, 17901, 18065, 18230, 18394, 18559, 18723, 18888, - 19052, 19216, 19379, 19543, 19706, 19870, 20032, 20195, - 20357, 20519, 20681, 20842, 21003, 21163, 21324, 21483, - 21642, 21801, 21959, 22117, 22274, 22431, 22587, 22742, - 22897, 23052, 23205, 23358, 23511, 23662, 23813, 23963, - 24113, 24261, 24409, 24556, 24702, 24848, 24992, 25136, - 25279, 25421, 25562, 25702, 25841, 25979, 26116, 26252, - 26387, 26521, 26654, 26786, 26917, 27047, 27175, 27303, - 27429, 27554, 27678, 27801, 27923, 28043, 28162, 28280, - 28397, 28512, 28626, 28739, 28850, 28960, 29069, 29177, - 29283, 29387, 29490, 29592, 29693, 29792, 29889, 29985, - 30080, 30173, 30265, 30355, 30444, 30531, 30616, 30700, - 30783, 30864, 30943, 31021, 31097, 31172, 31244, 31316, - 31386, 31454, 31520, 31585, 31648, 31710, 31769, 31827, - 31884, 31939, 31992, 32043, 32093, 32140, 32187, 32231, - 32274, 32315, 32354, 32391, 32427, 32461, 32493, 32524, - 32552, 32579, 32604, 32628, 32649, 32669, 32687, 32703, - 32717, 32730, 32741, 32750, 32757, 32762, 32766, 32767 -}; - -const Word16 POW_ATT_TABLE0[OFF_FRAMES_LIMIT+1] = -{ - 32767, 31293, 29885, 28540, 27255, 26029, 24857, 23738, 22670, 21650, - 20675, 19745, 18856, 18007, 17197, 16423, 8211, 4106, 2053, 1026, - 513, 257, 128, 64, 32, 16, 8, 4, 2, 1, 0 -}; -const Word16 POW_ATT_TABLE1[OFF_FRAMES_LIMIT+1] = -{ - 32767, 31656, 30581, 29543, 28540, 27571, 26635, 25731, 24857, 24013, - 23198, 22410, 21650, 20915, 20205, 19519, 9759, 4880, 2440, 1220, - 610, 305, 152, 76, 38, 19, 10, 5, 2, 1, 0 -}; -const Word16 GR_POW_HEADROOM[Lgw_max] = /* in Q0-- Number of bits down-shifting to prevent from saturation in group power accumulation.*/ -{ - 0, 0, 1, 2, 2, 3, 4, 4, 4 -}; - -/*---------------------------------------------------------------------* - * NB post-filter tables - *---------------------------------------------------------------------*/ - -const Word16 Tab_hup_s[SIZ_TAB_HUP_S] = -{ - -188, 2873, 31650, -1597, -484, 7041, 28469, -2147, -933, 12266, - 23705, -1992, -1492, 18050, 18050, -1492, -1992, 23705, 12266, -933, - -2147, 28469, 7041, -484, -1597, 31650, 2873, -188 -}; - -const Word16 Tab_hup_l[SIZ_TAB_HUP_L] = -{ - -40, 72, -156, 315, -579, 1023, -1874, 4439, - 31915, -3390, 1595, -887, 501, -266, 130, -59, - -77, 147, -317, 631, -1150, 2030, -3773, 9639, - 29436, -5579, 2727, -1527, 859, -453, 218, -101, - -106, 212, -455, 892, -1614, 2850, -5392, 15206, - 25569, -6549, 3303, -1860, 1041, -543, 258, -122, - -123, 253, -538, 1044, -1876, 3319, -6414, 20676, - 20676, -6414, 3319, -1876, 1044, -538, 253, -123, - -122, 258, -543, 1041, -1860, 3303, -6549, 25569, - 15206, -5392, 2850, -1614, 892, -455, 212, -106, - -101, 218, -453, 859, -1527, 2727, -5579, 29436, - 9639, -3773, 2030, -1150, 631, -317, 147, -77, - -59, 130, -266, 501, -887, 1595, -3390, 31915, - 4439, -1874, 1023, -579, 315, -156, 72, -40 -}; - - -/*Table 256 / (L_frame*2) , needed in sig_classifier.c and er_dec_acelp.c*/ -const Word16 T_256DIV_L_Frame[]= -{ - 6554 /*L_Frame 640*/ - ,8192 /*L_Frame 512*/ - ,8738 /*L_Frame 480*/ - ,13107/*L_Frame 320*/ - ,16384 /*L_Frame 256*/ - ,26214 /*L_Frame 160*/ -}; - -const Word16 T_DIV_L_Frame[] = /*0Q15 * 2^-7 */ -{ - 26214 /*160*/ - ,16384 /*256*/ - ,13107 /*320*/ - ,8738 /*480*/ - ,8192 /*512*/ - ,6553 /*640*/ -}; - - -/*er_dec_tcx.c*/ -const Word16 h_high3_32[L_FIR_FER2] = { -1694/*-0.0517f Q15*/, -1923/*-0.0587f Q15*/, -2687/*-0.0820f Q15*/, -3355/*-0.1024f Q15*/, -3814/*-0.1164f Q15*/, 28790/*0.8786f Q15*/, -3814/*-0.1164f Q15*/, -3355/*-0.1024f Q15*/, -2687/*-0.0820f Q15*/, -1923/*-0.0587f Q15*/, -1694/*-0.0517f Q15*/}; -const Word16 h_high3_16[L_FIR_FER2] = { 0/* 0.f Q15*/, -672/*-0.0205f Q15*/, -2133/*-0.0651f Q15*/, -4116/*-0.1256f Q15*/, -5872/*-0.1792f Q15*/, 26306/*0.8028f Q15*/, -5872/*-0.1792f Q15*/, -4116/*-0.1256f Q15*/, -2133/*-0.0651f Q15*/, -672/*-0.0205f Q15*/, 0/* 0.f Q15*/}; - -const Word16 pow2tab[15] = { 0x0001, 0x0002, 0x0004, 0x0008, 0x0010, 0x0020, 0x0040, 0x0080, 0x0100, 0x0200, 0x0400, 0x0800, 0x1000, 0x2000, 0x4000 }; - -/* CLDFB-BPF */ -/** - \brief Bass Post Filter weights - First bpf_weights coefficient is scaled by 0.5 -*/ -const Word16 bpf_weights_16_Fx[16] = -{ - 16385/*0.500020f Q15*/, 23022/*0.702561f Q15*/, 6843/*0.208838f Q15*/, 51/*0.001553f Q15*/, - 58/*0.001777f Q15*/, 45/*0.001370f Q15*/, 30/*0.000926f Q15*/, 18/*0.000554f Q15*/, - 9/*0.000270f Q15*/, 3/*0.000080f Q15*/, 1/*0.000030f Q15*/, 3/*0.000082f Q15*/, - 3/*0.000081f Q15*/, 2/*0.000052f Q15*/, 1/*0.000017f Q15*/, 1/*0.000016f Q15*/ -}; - - -/* Word16 (Q15) Hann window ranging from 0 to 32767/32768 (~0.999969) */ -const Word16 pcmdsp_window_hann_960[960] = -{ - 0, 0, 1, 3, 6, 9, 13, 17, 22, 28, 35, 42, 51, 59, 69, - 79, 90, 101, 114, 127, 140, 155, 170, 185, 202, 219, 237, 255, 274, 294, - 315, 336, 358, 381, 404, 428, 453, 478, 504, 531, 558, 586, 615, 645, 675, - 705, 737, 769, 802, 835, 869, 904, 940, 976, 1013, 1050, 1088, 1127, 1166, 1206, - 1247, 1289, 1331, 1373, 1416, 1460, 1505, 1550, 1596, 1643, 1690, 1737, 1786, 1835, 1884, - 1935, 1985, 2037, 2089, 2142, 2195, 2249, 2303, 2359, 2414, 2471, 2528, 2585, 2643, 2702, - 2761, 2821, 2882, 2943, 3004, 3066, 3129, 3192, 3256, 3321, 3386, 3451, 3517, 3584, 3651, - 3719, 3787, 3856, 3926, 3995, 4066, 4137, 4208, 4280, 4353, 4426, 4499, 4574, 4648, 4723, - 4799, 4875, 4951, 5028, 5106, 5184, 5263, 5342, 5421, 5501, 5581, 5662, 5743, 5825, 5907, - 5990, 6073, 6157, 6241, 6325, 6410, 6495, 6581, 6667, 6754, 6841, 6928, 7016, 7104, 7193, - 7282, 7371, 7461, 7551, 7641, 7732, 7823, 7915, 8007, 8099, 8192, 8285, 8378, 8472, 8566, - 8661, 8755, 8850, 8946, 9042, 9138, 9234, 9331, 9427, 9525, 9622, 9720, 9818, 9917,10015, - 10114,10213,10313,10413,10512,10613,10713,10814,10915,11016,11118,11219,11321,11423,11525, - 11628,11731,11834,11937,12040,12144,12247,12351,12455,12559,12664,12768,12873,12978,13083, - 13188,13293,13398,13504,13609,13715,13821,13927,14033,14139,14245,14352,14458,14565,14671, - 14778,14885,14992,15099,15205,15312,15419,15527,15634,15741,15848,15955,16062,16170,16277, - 16384,16491,16598,16706,16813,16920,17027,17134,17241,17349,17456,17563,17669,17776,17883, - 17990,18097,18203,18310,18416,18523,18629,18735,18841,18947,19053,19159,19264,19370,19475, - 19580,19685,19790,19895,20000,20104,20209,20313,20417,20521,20624,20728,20831,20934,21037, - 21140,21243,21345,21447,21549,21650,21752,21853,21954,22055,22155,22256,22355,22455,22555, - 22654,22753,22851,22950,23048,23146,23243,23341,23437,23534,23630,23726,23822,23918,24013, - 24107,24202,24296,24390,24483,24576,24669,24761,24853,24945,25036,25127,25217,25307,25397, - 25486,25575,25664,25752,25840,25927,26014,26101,26187,26273,26358,26443,26527,26611,26695, - 26778,26861,26943,27025,27106,27187,27267,27347,27426,27505,27584,27662,27740,27817,27893, - 27969,28045,28120,28194,28269,28342,28415,28488,28560,28631,28702,28773,28842,28912,28981, - 29049,29117,29184,29251,29317,29382,29447,29512,29576,29639,29702,29764,29825,29886,29947, - 30007,30066,30125,30183,30240,30297,30354,30409,30465,30519,30573,30626,30679,30731,30783, - 30833,30884,30933,30982,31031,31078,31125,31172,31218,31263,31308,31352,31395,31437,31479, - 31521,31562,31602,31641,31680,31718,31755,31792,31828,31864,31899,31933,31966,31999,32031, - 32063,32093,32123,32153,32182,32210,32237,32264,32290,32315,32340,32364,32387,32410,32432, - 32453,32474,32494,32513,32531,32549,32566,32583,32598,32613,32628,32641,32654,32667,32678, - 32689,32699,32709,32717,32726,32733,32740,32746,32751,32755,32759,32762,32765,32767,32767, - 32767,32767,32766,32764,32761,32758,32754,32750,32745,32739,32732,32725,32716,32708,32698, - 32688,32677,32666,32653,32640,32627,32612,32597,32582,32565,32548,32530,32512,32493,32473, - 32452,32431,32409,32386,32363,32339,32314,32289,32263,32236,32209,32181,32152,32122,32092, - 32062,32030,31998,31965,31932,31898,31863,31827,31791,31754,31717,31679,31640,31601,31561, - 31520,31478,31436,31394,31351,31307,31262,31217,31171,31124,31077,31030,30981,30932,30883, - 30832,30782,30730,30678,30625,30572,30518,30464,30408,30353,30296,30239,30182,30124,30065, - 30006,29946,29885,29824,29763,29701,29638,29575,29511,29446,29381,29316,29250,29183,29116, - 29048,28980,28911,28841,28772,28701,28630,28559,28487,28414,28341,28268,28193,28119,28044, - 27968,27892,27816,27739,27661,27583,27504,27425,27346,27266,27186,27105,27024,26942,26860, - 26777,26694,26610,26526,26442,26357,26272,26186,26100,26013,25926,25839,25751,25663,25574, - 25485,25396,25306,25216,25126,25035,24944,24852,24760,24668,24575,24482,24389,24295,24201, - 24106,24012,23917,23821,23725,23629,23533,23436,23340,23242,23145,23047,22949,22850,22752, - 22653,22554,22454,22354,22255,22154,22054,21953,21852,21751,21649,21548,21446,21344,21242, - 21139,21036,20933,20830,20727,20623,20520,20416,20312,20208,20103,19999,19894,19789,19684, - 19579,19474,19369,19263,19158,19052,18946,18840,18734,18628,18522,18415,18309,18202,18096, - 17989,17882,17775,17668,17562,17455,17348,17240,17133,17026,16919,16812,16705,16597,16490, - 16383,16276,16169,16061,15954,15847,15740,15633,15526,15418,15311,15204,15098,14991,14884, - 14777,14670,14564,14457,14351,14244,14138,14032,13926,13820,13714,13608,13503,13397,13292, - 13187,13082,12977,12872,12767,12663,12558,12454,12350,12246,12143,12039,11936,11833,11730, - 11627,11524,11422,11320,11218,11117,11015,10914,10813,10712,10612,10511,10412,10312,10212, - 10113,10014,9916, 9817, 9719, 9621, 9524, 9426, 9330, 9233, 9137, 9041, 8945, 8849, 8754, - 8660, 8565, 8471, 8377, 8284, 8191, 8098, 8006, 7914, 7822, 7731, 7640, 7550, 7460, 7370, - 7281, 7192, 7103, 7015, 6927, 6840, 6753, 6666, 6580, 6494, 6409, 6324, 6240, 6156, 6072, - 5989, 5906, 5824, 5742, 5661, 5580, 5500, 5420, 5341, 5262, 5183, 5105, 5027, 4950, 4874, - 4798, 4722, 4647, 4573, 4498, 4425, 4352, 4279, 4207, 4136, 4065, 3994, 3925, 3855, 3786, - 3718, 3650, 3583, 3516, 3450, 3385, 3320, 3255, 3191, 3128, 3065, 3003, 2942, 2881, 2820, - 2760, 2701, 2642, 2584, 2527, 2470, 2413, 2358, 2302, 2248, 2194, 2141, 2088, 2036, 1984, - 1934, 1883, 1834, 1785, 1736, 1689, 1642, 1595, 1549, 1504, 1459, 1415, 1372, 1330, 1288, - 1246, 1205, 1165, 1126, 1087, 1049, 1012, 975, 939, 903, 868, 834, 801, 768, 736, - 704, 674, 644, 614, 585, 557, 530, 503, 477, 452, 427, 403, 380, 357, 335, - 314, 293, 273, 254, 236, 218, 201, 184, 169, 154, 139, 126, 113, 100, 89, - 78, 68, 58, 50, 41, 34, 27, 21, 16, 12, 8, 5, 2, 0, 0 -}; - -/* Word16 (Q15) Hann window ranging from 0 to 32767/32768 (~0.999969) */ -const Word16 pcmdsp_window_hann_640[640] = -{ - 0, 1, 3, 7, 13, 20, 28, 39, 51, 64, 79, 95, 114, 133, 155, - 177, 202, 228, 255, 284, 315, 347, 381, 416, 453, 491, 531, 572, 615, 660, - 705, 753, 802, 852, 904, 958, 1013, 1069, 1127, 1186, 1247, 1309, 1373, 1438, 1505, - 1573, 1643, 1713, 1786, 1859, 1935, 2011, 2089, 2168, 2249, 2331, 2414, 2499, 2585, 2672, - 2761, 2851, 2943, 3035, 3129, 3224, 3321, 3418, 3517, 3618, 3719, 3822, 3926, 4031, 4137, - 4244, 4353, 4463, 4574, 4686, 4799, 4913, 5028, 5145, 5263, 5381, 5501, 5622, 5743, 5866, - 5990, 6115, 6241, 6368, 6495, 6624, 6754, 6884, 7016, 7148, 7282, 7416, 7551, 7687, 7823, - 7961, 8099, 8238, 8378, 8519, 8661, 8803, 8946, 9089, 9234, 9379, 9525, 9671, 9818, 9966, - 10114,10263,10413,10563,10713,10864,11016,11168,11321,11474,11628,11782,11937,12092,12247, - 12403,12559,12716,12873,13030,13188,13346,13504,13662,13821,13980,14139,14299,14458,14618, - 14778,14938,15099,15259,15419,15580,15741,15902,16062,16223,16384,16545,16706,16866,17027, - 17188,17349,17509,17669,17830,17990,18150,18310,18469,18629,18788,18947,19106,19264,19422, - 19580,19738,19895,20052,20209,20365,20521,20676,20831,20986,21140,21294,21447,21600,21752, - 21904,22055,22205,22355,22505,22654,22802,22950,23097,23243,23389,23534,23679,23822,23965, - 24107,24249,24390,24530,24669,24807,24945,25081,25217,25352,25486,25620,25752,25884,26014, - 26144,26273,26400,26527,26653,26778,26902,27025,27146,27267,27387,27505,27623,27740,27855, - 27969,28082,28194,28305,28415,28524,28631,28737,28842,28946,29049,29150,29251,29350,29447, - 29544,29639,29733,29825,29917,30007,30096,30183,30269,30354,30437,30519,30600,30679,30757, - 30833,30909,30982,31055,31125,31195,31263,31330,31395,31459,31521,31582,31641,31699,31755, - 31810,31864,31916,31966,32015,32063,32108,32153,32196,32237,32277,32315,32352,32387,32421, - 32453,32484,32513,32540,32566,32591,32613,32635,32654,32673,32689,32704,32717,32729,32740, - 32748,32755,32761,32765,32767,32767,32766,32764,32760,32754,32747,32739,32728,32716,32703, - 32688,32672,32653,32634,32612,32590,32565,32539,32512,32483,32452,32420,32386,32351,32314, - 32276,32236,32195,32152,32107,32062,32014,31965,31915,31863,31809,31754,31698,31640,31581, - 31520,31458,31394,31329,31262,31194,31124,31054,30981,30908,30832,30756,30678,30599,30518, - 30436,30353,30268,30182,30095,30006,29916,29824,29732,29638,29543,29446,29349,29250,29149, - 29048,28945,28841,28736,28630,28523,28414,28304,28193,28081,27968,27854,27739,27622,27504, - 27386,27266,27145,27024,26901,26777,26652,26526,26399,26272,26143,26013,25883,25751,25619, - 25485,25351,25216,25080,24944,24806,24668,24529,24389,24248,24106,23964,23821,23678,23533, - 23388,23242,23096,22949,22801,22653,22504,22354,22204,22054,21903,21751,21599,21446,21293, - 21139,20985,20830,20675,20520,20364,20208,20051,19894,19737,19579,19421,19263,19105,18946, - 18787,18628,18468,18309,18149,17989,17829,17668,17508,17348,17187,17026,16865,16705,16544, - 16383,16222,16061,15901,15740,15579,15418,15258,15098,14937,14777,14617,14457,14298,14138, - 13979,13820,13661,13503,13345,13187,13029,12872,12715,12558,12402,12246,12091,11936,11781, - 11627,11473,11320,11167,11015,10863,10712,10562,10412,10262,10113, 9965, 9817, 9670, 9524, - 9378, 9233, 9088, 8945, 8802, 8660, 8518, 8377, 8237, 8098, 7960, 7822, 7686, 7550, 7415, - 7281, 7147, 7015, 6883, 6753, 6623, 6494, 6367, 6240, 6114, 5989, 5865, 5742, 5621, 5500, - 5380, 5262, 5144, 5027, 4912, 4798, 4685, 4573, 4462, 4352, 4243, 4136, 4030, 3925, 3821, - 3718, 3617, 3516, 3417, 3320, 3223, 3128, 3034, 2942, 2850, 2760, 2671, 2584, 2498, 2413, - 2330, 2248, 2167, 2088, 2010, 1934, 1858, 1785, 1712, 1642, 1572, 1504, 1437, 1372, 1308, - 1246, 1185, 1126, 1068, 1012, 957, 903, 851, 801, 752, 704, 659, 614, 571, 530, - 490, 452, 415, 380, 346, 314, 283, 254, 227, 201, 176, 154, 132, 113, 94, - 78, 63, 50, 38, 27, 19, 12, 6, 2, 0 -}; - - diff --git a/src/libs/libevs/lib_dec/rom_dec_fx.h b/src/libs/libevs/lib_dec/rom_dec_fx.h deleted file mode 100755 index f7686c41..00000000 --- a/src/libs/libevs/lib_dec/rom_dec_fx.h +++ /dev/null @@ -1,86 +0,0 @@ -/*==================================================================================== - EVS Codec 3GPP TS26.442 Apr 03, 2018. Version 12.11.0 / 13.6.0 / 14.2.0 - ====================================================================================*/ - - -#ifndef ROM_DEC_FX_H -#define ROM_DEC_FX_H - -#include -#include "options.h" /* Compilation switches */ -#include "cnst_fx.h" - -/*----------------------------------------------------------------------------------* - * General tables - *----------------------------------------------------------------------------------*/ -extern const Word16 gw_fx[Lgw_max]; -extern const Word16 gw_len_inv_fx[Lgw_max-1]; -extern const Word16 gwlpr_fx[Lgw_max]; - -extern const Word16 hestable_fx[15]; - -extern const Word16 h_high_fx[5]; -extern const Word16 inv_sqi[15]; -extern const Word16 sqi[15]; - - -/*------------------------------------------------------------------------------* - * AVQ - RE8 tables - *------------------------------------------------------------------------------*/ - -extern const Word16 mult_avq_tab_fx[]; -extern const Word16 shift_avq_tab_fx[]; - -/*----------------------------------------------------------------------------------* - * HR SWB BWE parameters - *----------------------------------------------------------------------------------*/ - -extern const Word16 swb_hr_inv_frm_len[4]; /* in Q19 */ -extern const Word16 inv_tbl_2n_minus1[]; - -/*---------------------------------------------------------------------* - * TABLE ROM, defined in lib_dec_fx\rom_dec_fx.c - *---------------------------------------------------------------------*/ - -extern const Word16 hntable_fx[55]; -extern const Word16 hetable_fx[57]; - -extern const Word16 H_low[5]; - -extern const Word16 lsf_tab_fx[LPC_SHB_ORDER]; - -/*---------------------------------------------------------------------* - * NB post-filter tables - *---------------------------------------------------------------------*/ - -extern const Word16 Tab_hup_s[]; -extern const Word16 Tab_hup_l[]; - - -/*----------------------------- - * FEC_HQ_phase_ecu - *------------------------------*/ -extern const Word16 FFT_W256[]; -extern const Word16 w_hamm_sana48k_2_fx[]; -extern const Word16 w_hamm48k_2_fx[]; -extern const Word16 w_hamm32k_2_fx[]; -extern const Word16 w_hamm16k_2_fx[]; -extern const Word16 POW_ATT_TABLE0[]; -extern const Word16 POW_ATT_TABLE1[]; -extern const Word16 GR_POW_HEADROOM[]; - - -/*Table 256 / (L_frame*2) , needed in sig_classifier.c and er_dec_acelp.c*/ -extern const Word16 T_256DIV_L_Frame[]; -extern const Word16 T_DIV_L_Frame[]; /*0Q15 * 2^-7 */ - -/* er_dec_tcx.c */ -extern const Word16 h_high3_32[L_FIR_FER2]; -extern const Word16 h_high3_16[L_FIR_FER2]; - -extern const Word16 pow2tab[15]; - -/* CLDFB BPF */ -extern const Word16 bpf_weights_16_Fx[16]; - -#endif /* ROM_DEC_FX.H */ diff --git a/src/libs/libevs/lib_dec/rst_dec.cpp b/src/libs/libevs/lib_dec/rst_dec.cpp new file mode 100644 index 00000000..5f23bd0b --- /dev/null +++ b/src/libs/libevs/lib_dec/rst_dec.cpp @@ -0,0 +1,58 @@ +/*==================================================================================== + EVS Codec 3GPP TS26.443 Nov 13, 2018. Version 12.11.0 / 13.7.0 / 14.3.0 / 15.1.0 + ====================================================================================*/ + +#include +#include "options.h" +#include "cnst.h" +#include "rom_com.h" +#include "prot.h" + +/*----------------------------------------------------------------------------------* + * CNG_reset_dec() + * + * Reset decoder static variables in case of CNG frame + *----------------------------------------------------------------------------------*/ + +void CNG_reset_dec( + Decoder_State *st, /* i/o: decoder state structure */ + float *pitch_buf, /* o : floating pitch for each subframe */ + float *voice_factors /* o : voicing factors */ +) +{ + mvr2r( UVWB_Ave, st->mem_AR, M ); + set_f(st->mem_MA, 0, M ); + set_f( st->dispMem, 0, 8 ); + st->tilt_code = 0.0f; + st->gc_threshold = 0.0f; + + /* last good received frame for FEC in ACELP */ + st->clas_dec = UNVOICED_CLAS; + st->last_good = UNVOICED_CLAS; + + /* LP-filtered pitch gain set to 0 */ + st->lp_gainp = 0.0f; + + /* convert CNG energy into CNG gain for ACELP FEC */ + st->lp_gainc = (float)sqrt( st->lp_ener ); + + /* reset the pitch buffer in case of FRAME__NO_DATA or SID frames */ + if(st->L_frame == L_FRAME ) + { + set_f( pitch_buf, (float)L_SUBFR, NB_SUBFR ); + } + else /* st->L_frame == L_FRAME16k */ + { + set_f( pitch_buf, (float)L_SUBFR16k, NB_SUBFR16k ); + } + + set_f( voice_factors, 1.0, NB_SUBFR16k ); + + /* deactivate bass post-filter */ + st->bpf_off = 1; + + /* Reset active frame counter */ + st->act_cnt2 = 0; + + return; +} diff --git a/src/libs/libevs/lib_dec/rst_dec_fx.cpp b/src/libs/libevs/lib_dec/rst_dec_fx.cpp deleted file mode 100755 index 3b7f8593..00000000 --- a/src/libs/libevs/lib_dec/rst_dec_fx.cpp +++ /dev/null @@ -1,85 +0,0 @@ -/*==================================================================================== - EVS Codec 3GPP TS26.442 Apr 03, 2018. Version 12.11.0 / 13.6.0 / 14.2.0 - ====================================================================================*/ - -#include "options.h" /* Compilation switches */ -#include "stl.h" -#include "cnst_fx.h" /* Common constants */ -#include "rom_com_fx.h" /* Static table prototypes */ -#include "prot_fx.h" /* Function prototypes */ - -/*----------------------------------------------------------------------------------* - * CNG_reset_dec() - * - * Reset decoder static variables in case of CNG frame - *----------------------------------------------------------------------------------*/ - -void CNG_reset_dec_fx( - Decoder_State_fx *st_fx, /* i/o: decoder state structure */ - Word16 *pitch_buf, /* o : floating pitch for each subframe */ - Word16 *voice_factors /* o : voicing factors */ -) -{ - Word16 tmp, exp; - Word32 L_tmp; - Copy( UVWB_Ave_fx, st_fx->mem_AR_fx, M ); - set16_fx( st_fx->mem_MA_fx, 0, M ); - /*set16_fx( st_fx->dispMem_fx, 0, 8 );*/ - set16_fx( st_fx->dm_fx.prev_gain_pit , 0, 6 ); - st_fx->dm_fx.prev_gain_code = L_deposit_l(0); - st_fx->dm_fx.prev_state = 0; - move16(); - - st_fx->tilt_code_fx = 0; - move16(); - st_fx->gc_threshold_fx = 0; - move16(); - - /* last good received frame for FEC in ACELP */ - st_fx->clas_dec = UNVOICED_CLAS; - move16(); - st_fx->last_good_fx = UNVOICED_CLAS; - move16(); - - /* LP-filtered pitch gain set to 0 */ - st_fx->lp_gainp_fx = 0; - move16(); - - /* convert CNG energy into CNG gain for ACELP FEC */ - /* st->lp_gainc = sqrt( st->lp_ener ); */ - st_fx->lp_gainc_fx = 0; - move16(); - - IF (st_fx->lp_ener_fx != 0) - { - exp = norm_l(st_fx->lp_ener_fx); /* In Q6 */ - tmp = extract_h(L_shl(st_fx->lp_ener_fx, exp)); - exp = sub(exp, 30-6); - - tmp = div_s(16384, tmp); - L_tmp = L_deposit_h(tmp); - L_tmp = Isqrt_lc(L_tmp, &exp); - - st_fx->lp_gainc_fx = round_fx(L_shl(L_tmp, sub(exp, 12))); /* In Q3 */ - } - /* reset the pitch buffer in case of FRAME_NO_DATA or SID frames */ - IF( sub(st_fx->L_frame_fx,L_FRAME) == 0 ) - { - set16_fx( pitch_buf, L_SUBFR<<6, NB_SUBFR ); - } - ELSE /* st->L_frame == L_FRAME16k */ - { - set16_fx( pitch_buf, L_SUBFR16k<<6, NB_SUBFR16k ); - } - - set16_fx( voice_factors, 32767, NB_SUBFR16k ); - - /* deactivate bass post-filter */ - st_fx->bpf_off_fx = 1; - move16(); - /* Reset active frame counter */ - st_fx->act_cnt2_fx = 0; - move16(); - - return; -} diff --git a/src/libs/libevs/lib_dec/stat_dec.h b/src/libs/libevs/lib_dec/stat_dec.h new file mode 100644 index 00000000..cce08a45 --- /dev/null +++ b/src/libs/libevs/lib_dec/stat_dec.h @@ -0,0 +1,1014 @@ +/*==================================================================================== + EVS Codec 3GPP TS26.443 Nov 13, 2018. Version 12.11.0 / 13.7.0 / 14.3.0 / 15.1.0 + ====================================================================================*/ + +#ifndef STAT_DEC_H +#define STAT_DEC_H + +#include "options.h" +#include "stat_com.h" /* Common structures */ +#include "cnst.h" + +typedef enum _DEC_MODE +{ + DEC_NO_FRAM_LOSS = 0x0, + DEC_CONCEALMENT_EXT = 0x1 +} DEC_MODE; + +typedef enum framemode_t +{ + FRAMEMODE_NORMAL = 0x0, /**< frame available */ + FRAMEMODE_MISSING = 0x1, /**< frame missing => conceal */ + FRAMEMODE_FUTURE = 0x2 +} frameMode; + + +/* Arrays and variables specific to decoder */ +typedef struct +{ + HANDLE_FD_CNG_COM hFdCngCom; + + float msPeriodog[NPART_SHAPING]; /* Periodogram */ + float msBminWin[NPART_SHAPING]; + float msBminSubWin[NPART_SHAPING]; + float msPsd[NPART_SHAPING]; /* Power Spectral Density estimate (i.e., smoothed periodogram) */ + float msAlpha[NPART_SHAPING]; /* Optimal smoothing parameter */ + float msMinBuf[MSNUMSUBFR*NPART_SHAPING]; /* Buffer of minima */ + float msCurrentMinOut[NPART_SHAPING]; + float msCurrentMin[NPART_SHAPING]; + float msCurrentMinSubWindow[NPART_SHAPING]; + int msLocalMinFlag[NPART_SHAPING]; + int msNewMinFlag[NPART_SHAPING]; + float msPsdFirstMoment[NPART_SHAPING]; + float msPsdSecondMoment[NPART_SHAPING]; + float msNoiseFloor[NPART_SHAPING]; /* Estimated noise floor */ + float msNoiseEst[NPART_SHAPING]; /* Estimated noise level */ + float msLogPeriodog[NPART_SHAPING]; /* Periodogram */ + float msLogNoiseEst[NPART_SHAPING]; /* Estimated noise level */ + int npart_shaping; /* Number of partitions */ + int nFFTpart_shaping; /* Number of hybrid spectral partitions */ + int part_shaping[NPART_SHAPING]; /* Partition upper boundaries (band indices starting from 0) */ + int midband_shaping[NPART_SHAPING]; /* Central band of each partition */ + float psize_shaping[NPART_SHAPING]; /* Partition sizes */ + float psize_inv_shaping[NPART_SHAPING]; /* Inverse of partition sizes */ + float bandNoiseShape[FFTLEN2];/* CNG spectral shape computed at the decoder */ + float partNoiseShape[NPART];/* CNG spectral shape computed at the decoder */ + + short flag_dtx_mode; + float lp_speech; + float lp_noise; + + float msPeriodogBuf[MSBUFLEN*NPART_SHAPING]; + int msPeriodogBufPtr; + +} +FD_CNG_DEC; +typedef FD_CNG_DEC *HANDLE_FD_CNG_DEC; + +typedef struct +{ + int FrameSize; + + int Pitch; + int T_bfi; + + int Transient[MAX_POST_LEN]; + int TCX_Tonality[DEC_STATE_LEN]; + + float outx_new_n1; + float nsapp_gain; + float nsapp_gain_n; + float data_reci2[L_FRAME_MAX]; + float data_noise[L_FRAME_MAX]; + float ener_mean; + float ener; + int zp; + float recovery_gain; + float step_concealgain; + + int concealment_method; + int subframe; + int nbLostCmpt; + + short seed; + +} T_PLCInfo; + + +/*---------------------------------------------------------------* + * Structures for Tonal MDCT PLC * + *---------------------------------------------------------------*/ + +typedef enum +{ + TONALMDCTCONCEAL_OK = 0, + + __error_codes_start = -100, + + TONALMDCTCONCEAL_NSAMPLES_LARGER_THAN_MAXBLOCKSIZE, + TONALMDCTCONCEAL_INVALIDPOINTER, + TONALMDCTCONCEAL_UNEXPECTED_ERROR, + + __error_codes_end +} TONALMDCTCONCEAL_ERROR; + +typedef struct +{ + unsigned int nSamples; + unsigned int nSamplesCore; + Float32 * spectralData; + float * scaleFactors; + int blockIsValid; + int blockIsConcealed; + int tonalConcealmentActive; +} blockData; + +typedef struct +{ + unsigned int numIndexes; + unsigned short int indexOfTonalPeak[MAX_NUMBER_OF_IDX]; + unsigned short int lowerIndex[MAX_NUMBER_OF_IDX]; + unsigned short int upperIndex[MAX_NUMBER_OF_IDX]; + Float32 phaseDiff[MAX_NUMBER_OF_IDX]; /* This one can be stored with 16 bits in range 0..2*PI */ + Float32 phase_currentFramePredicted[MAX_NUMBER_OF_IDX*GROUP_LENGTH]; /* This one can be stored with 16 bits in range 0..2*PI, but the code has to be adapted to use moduo(2*PI) after adding */ +} TonalComponentsInfo; + +typedef void (*ApplyScaleFactorsPointer)(float x[], int lg, float const scaleFactors[]); + +struct tonalmdctconceal +{ + TCX_config * tcx_cfg; + void * pMDSTData; + unsigned int nSamples; + unsigned int nSamplesCore; + unsigned int nNonZeroSamples; + unsigned int nScaleFactors; + + float lastPitchLag; + + blockData lastBlockData; + blockData secondLastBlockData; + + Float32 scaleFactorsBuffers[2][FDNS_NPTS]; /* Contains also global gain. If it can not be stored in 16 bits with global gain included, then store global gain separately. */ + Float32 spectralDataBuffers[2][L_FRAME_MAX]; /* 16 bits is enough, because it is stored before applying scale factors. Take care that power spectrum is also stored here. */ + Float32 timeDataBuffer[(3*L_FRAME_MAX)/2]; + Float32 * lastPcmOut; + Float32 * secondLastPcmOut; + float * secondLastPowerSpectrum; + + float nFramesLost; + + TonalComponentsInfo * pTCI; +}; + +typedef struct tonalmdctconceal* TonalMDCTConcealPtr; + +typedef enum SIGNAL_CLASSIFER_MODE +{ + CLASSIFIER_ACELP, + CLASSIFIER_TCX +} SIGNAL_CLASSIFIER_MODE; + +/*---------------------------------------------------------------* + * Structures for IGF decoder * + *---------------------------------------------------------------*/ + +/* IGFSCFDecoder.h */ +typedef struct +{ + int bitsRead; /* after a call bitsRead contains the number of bits consumed by the decoder */ + int prev[64]; /* no more than 64 SCFs for the IGF energy envelope of one block */ + int scfCountLongBlock; + int t; + int bitrate; + const unsigned short *cf_se00; + const unsigned short *cf_se01; + short cf_off_se01; + const unsigned short *cf_se02; + const short *cf_off_se02; + const unsigned short *cf_se10; + short cf_off_se10; + const unsigned short *cf_se11; + const short *cf_off_se11; + Tastat acState; +} IGFSCFDEC_INSTANCE, *IGFSCFDEC_INSTANCE_HANDLE; + +/* IGFDec.h */ +typedef struct igfdec_private_data_struct +{ + + IGF_INFO igfInfo; + /* envelope reconstruction: */ + float igf_sN[IGF_MAX_SFB]; /* only with short blocks as static needed */ + float igf_pN[IGF_MAX_SFB]; /* only with short blocks as static needed */ + int igf_curr[IGF_MAX_SFB]; /* current igf energies */ + int igf_prev[IGF_MAX_SFB]; /* needed for concealment or indepflag==0 */ + int igf_curr_subframe[IGF_MAX_SUBFRAMES][IGF_TRANS_FAK][IGF_MAX_SFB]; /* current igf energies per subframe*/ + int igf_prev_subframe[IGF_MAX_SUBFRAMES][IGF_MAX_SFB]; /* needed for concealment or indepflag==0 */ + int igf_flatteningTrigger_subframe[IGF_MAX_SUBFRAMES]; + + /* spectral whitening: */ + float pSpecFlat[IGF_START_MX]; + int currWhiteningLevel[IGF_MAX_TILES]; + int prevWhiteningLevel[IGF_MAX_TILES]; /* needed for concealment */ + int currWhiteningLevel_subframe[IGF_MAX_SUBFRAMES][IGF_MAX_TILES]; + int prevWhiteningLevel_subframe[IGF_MAX_SUBFRAMES][IGF_MAX_TILES]; /* needed for concealment */ + + float totalNoiseNrg; + int n_noise_bands; + + float totalNoiseNrg_off; + int n_noise_bands_off; + + /* IGF SCF decoding: */ + IGFSCFDEC_INSTANCE hArithSCFdec; + + /* concealment: */ + int frameLossCounter; + +} IGFDEC_PRIVATE_DATA,*IGF_DEC_PRIVATE_DATA_HANDLE; + +typedef struct igfdec_instance_struct +{ + int isIGFActive; + int infoIGFAllZero; + int infoIGFStopLine; + int infoIGFStartLine; + int infoIGFStopFreq; + int infoIGFStartFreq; + unsigned char infoTCXNoise[IGF_START_MX]; + int flag_sparse[N_MAX_TCX-IGF_START_MN]; + float virtualSpec[N_MAX_TCX-IGF_START_MN]; + int flatteningTrigger; + IGFDEC_PRIVATE_DATA igfData; +} IGFDEC_INSTANCE, *IGF_DEC_INSTANCE_HANDLE; + +/*----------------------------------------------------------------------------------* + * + * Main decoder structure + * + *----------------------------------------------------------------------------------*/ + +typedef struct Decoder_State +{ + + /*----------------------------------------------------------------------------------* + * Common parameters + *----------------------------------------------------------------------------------*/ + + short codec_mode; /* Mode 1 or 2 */ + short mdct_sw_enable; /* MDCT switching enable flag */ + short mdct_sw; /* MDCT switching indicator */ + short last_codec_mode; /* last used codec mode */ + + unsigned short bit_stream[MAX_BITS_PER_FRAME+16]; + short next_bit_pos; /* position of the next bit to be read from the bitstream */ + short bitstreamformat; /* Bitstream format flag (G.192/MIME) */ + short amrwb_rfc4867_flag; /* MIME from rfc4867 is used */ + short BER_detect; /* flag to signal detected bit error in the bitstream */ + int output_Fs; /* output sampling rate */ + long total_brate; /* total bitrate in kbps of the codec */ + long last_total_brate; /* last total bitrate in kbps of the codec */ + long last_total_brate_ber; /* last total bitrate in kbps of the codec - used only when first frame is lost and BER is detected afterwards */ + short core; /* core (ACELP_CORE, TCX_20_CORE, TCX_10_CORE, HQ_CORE, AMR_WB_CORE) */ + long core_brate; /* core bitrate */ + long last_core_brate; /* previous frame core bitrate */ + short extl; /* extension layer */ + short last_extl; /* previous extension layer */ + long extl_brate; /* extension layer bitrate */ + short L_frame; /* ACELP core internal frame length */ + short bwidth; /* encoded signal bandwidth */ + short Opt_AMR_WB; /* flag indicating AMR-WB IO mode */ + short Opt_VOIP; /* flag indicating VOIP mode with JBM */ + short ini_frame; /* initialization frames counter */ + Word16 CNG; /* RXDTX handler: CNG=1, nonCNG=0 */ + Word16 prev_ft_speech; /* RXDTX handler: previous frametype flag for G.192 format AMRWB SID_FIRST detection */ + + /*----------------------------------------------------------------------------------* + * ACELP core parameters + *----------------------------------------------------------------------------------*/ + + float old_exc[L_EXC_MEM_DEC]; /* old excitation */ + float old_excFB[L_FRAME48k]; /* old excitation FB */ + float lsp_old[M]; /* old LSP vector at the end of the frame */ + float lsf_old[M]; /* old LSF vector at the end of the frame */ + unsigned int offset_scale1[MAX_NO_MODES+1][MAX_NO_SCALES+1]; /* offsets for LSF LVQ structure 1st 8-dim subvector*/ + unsigned int offset_scale2[MAX_NO_MODES+1][MAX_NO_SCALES+1]; /* offsets for LSF LVQ structure 2nd 8-dim subvector*/ + unsigned int offset_scale1_p[MAX_NO_MODES_p+1][MAX_NO_SCALES+1]; /* offsets for LSF LVQ structure, pred. case, 1st 8-dim subvector*/ + unsigned int offset_scale2_p[MAX_NO_MODES_p+1][MAX_NO_SCALES+1]; /* offsets for LSF LVQ structure, pred. case, 2nd 8-dim subvector*/ + short no_scales[MAX_NO_MODES][2]; /* LSF LVQ structure */ + short no_scales_p[MAX_NO_MODES_p][2]; /* LSF LVQ structure */ + float tilt_code; /* tilt of code */ + float mem_syn1[M]; /* synthesis filter memory (for core switching and FD BWE) */ + float mem_syn2[M]; /* synthesis filter memory */ + float mem_syn3[M]; + float mem_deemph; /* deemphasis filter memory */ + float mem_hp20_out[4]; /* HP filter memory for synthesis */ + float mem_AR[M]; /* AR memory of LSF quantizer (past quantized LSFs without mean) */ + float mem_MA[M]; /* MA memory of LSF quantizer (past quantized residual) */ + float stab_fac; /* LSF stability factor */ + float stab_fac_smooth; /* low-pass filtered stability factor */ + short last_coder_type; /* previous coder type */ + float agc_mem2[2]; /* memory of AGC for saturation control */ + float past_qua_en[GAIN_PRED_ORDER]; /* gain quantization memory (used also in AMR-WB IO mode) */ + short mid_lsf_int; + short safety_net; + + short seed_tcx ; /* AC mode (GSC) - seed for noise fill*/ + short GSC_noisy_speech; /* AC mode (GSC) - flag to indicate GSC osn SWB noisy speech */ + short Last_GSC_noisy_speech_flag; /* AC mode (GSC) - mem of the past flag to indicate GSC osn SWB noisy speech */ + short cor_strong_limit; /* AC mode (GSC) - Indicator about high spectral correlation per band */ + float old_y_gain[MBANDS_GN]; /* AC mode (GSC) - AR mem for low rate gain quantization */ + short noise_lev; /* AC mode (GSC) - noise level */ + float lt_ener_per_band[MBANDS_GN]; + float Last_frame_ener; /* AC mode (GSC) - last frame energy */ + float Last_GSC_spectrum[L_FRAME]; /* AC mode (GSC) - Last good GSC spectrum */ + short Last_GSC_pit_band_idx; /* AC mode (GSC) - Last pitch band index */ + float last_exc_dct_in[L_FRAME]; /* AC mode (GSC) - previous excitation */ + float last_ener; /* AC mode (GSC) - previous energy */ + short last_bitallocation_band[6]; /* AC mode (GSC) - previous bit allocation of each band */ + + float gc_threshold; /* Noise enhancer - threshold for gain_code */ + float dispMem[8]; /* Noise enhancer - phase dispersion algorithm memory */ + + float prev_r; /* HF BWE - previous sub-frame gain */ + float fmerit_w_sm; /* HF BWE - fmerit parameter memory */ + short frame_count; /* HF BWE - frame count */ + float ne_min; /* HF BWE - minimum Noise gate - short-term energy */ + float fmerit_m_sm; /* HF BWE - memory of fmerit_m param */ + float voice_fac_amr_wb_hf; /* HF BWE - voice factor */ + float unvoicing; /* HF BWE - unvoiced parameter */ + float unvoicing_sm; /* HF BWE - smoothed unvoiced parameter */ + short unvoicing_flag; /* HF BWE - unvoiced flag */ + short voicing_flag; /* HF BWE - voiced flag */ + short start_band_old; /* HF BWE - previous start point for copying frequency band */ + float OptCrit_old; /* HF BWE - previous criterion value for deciding the start point */ + + short seed2; /* HF (6-7kHz) BWE - seed for random signal generator */ + float mem_hp400[4]; /* HF (6-7kHz) BWE - hp400 filter memory */ + float mem_hf[(L_FIR-1)]; /* HF (6-7kHz) BWE - band-pass filter memory */ + float mem_syn_hf[M]; /* HF (6-7kHz) BWE - synthesis filter memory */ + float delay_syn_hf[NS2SA(16000,DELAY_CLDFB_NS)]; /* HF (6-7kHz) BWE - To synchronise BWE content with postfiltered synthesis */ + float mem_hp_interp[INTERP_3_1_MEM_LEN]; /* HF (6-7 kHz) BWE - interp. memory */ + + short unv_cnt; /* Stationary noise UV modification - unvoiced frame counter */ + short uv_count; /* Stationary noise UV modification - unvoiced counter */ + short act_count; /* Stationary noise UV modification - activation counter */ + float ge_sm; /* Stationary noise UV modification - smoothed excitation gain */ + float lspold_s[M]; /* Stationary noise UV modification - old LSP vector */ + short noimix_seed; /* Stationary noise UV modification - mixture seed */ + float min_alpha; /* Stationary noise UV modification - minimum alpha */ + float exc_pe; /* Stationary noise UV modification - memory of the preemphasis filter */ + + short bfi; /* FEC - bad frame indicator */ + short prev_bfi; /* FEC - previous bad frame indicator */ + short prev_old_bfi; /* FEC - previous old bad frame indicator */ + short seed; /* FEC - seed for random generator for excitation */ + float lp_ener_bfi; /* FEC - long-term active-signal average energy */ + short last_good; /* FEC - clas of last good received */ + float lp_gainp; /* FEC - low-pass filtered pitch gain */ + float lp_gainc; /* FEC - low-pass filtered code gain */ + float lp_ener; /* FEC - low-pass filtered energy */ + float enr_old; /* FEC - energy of the concealed frame */ + float bfi_pitch; /* FEC - pitch for FEC */ + short bfi_pitch_frame; /* FEC - frame length when pitch for FEC is saved */ + float old_pitch_buf[2*NB_SUBFR16k+2]; /* FEC - buffer of old subframe pitch values */ + short upd_cnt; /* FEC - counter of frames since last update */ + short scaling_flag; /* FEC - flag to indicate energy control of syn */ + float lp_ener_FEC_av; /* FEC - averaged voiced signal energy */ + float lp_ener_FEC_max; /* FEC - averaged voiced signal energy */ + float old_enr_LP; /* FEC - LP filter gain */ + short prev_nbLostCmpt; /* FEC - compt for number of consecutive lost frame at the previous frame*/ + short mode_lvq; /* FEC - index for LSF mean vector */ + float lsfoldbfi0[M]; /* FEC - LSF vector of the previous frame */ + float lsfoldbfi1[M]; /* FEC - LSF vector of the past previous frame */ + float lsf_adaptive_mean[M]; /* FEC - adaptive mean LSF vector for FEC */ + short decision_hyst; /* FEC - hysteresis of the music/speech decision */ + float old_exc2[L_EXC_MEM]; /* FEC - old excitation2 used in fast recovery */ + float old_syn2[L_EXC_MEM]; /* FEC - old syn speech used in fast recovery */ + short relax_prev_lsf_interp; + float mem_syn_clas_estim[L_SYN_MEM_CLAS_ESTIM]; /* FEC - memory of the synthesis signal for frame class estimation */ + float tilt_swb_fec; /* FEC - SWB TBE TILT */ + + short cng_seed; /* DTX/CNG - seed for white noise random generator */ + float lspCNG[M]; /* DTX/CNG - LP filtered ISPs */ + short first_CNG; /* DTX/CNG - first CNG frame flag */ + float Enew; /* DTX/CNG - decoded residual energy */ + short old_enr_index; /* DTX/CNG - index of last encoded CNG energy */ + short cng_ener_seed; /* DTX/CNG - seed for random generator for variation of excitation energy */ + short cng_ener_seed1; + short last_allow_cn_step; + short ho_hist_size; /* DTX/CNG - size of DTX hangover history buffer for averaging, <0,HO_HIST_SIZE> */ + short ho_hist_ptr; /* DTX/CNG - pointer for averaging buffers */ + long ho_sid_bw; /* DTX/CNG - SID bandwidth flags */ + float ho_lsp_hist[HO_HIST_SIZE*M]; /* DTX/CNG - old LSP buffer for averaging */ + float ho_ener_hist[HO_HIST_SIZE]; /* DTX/CNG - energy buffer for averaging */ + float ho_env_hist[HO_HIST_SIZE*NUM_ENV_CNG]; + short act_cnt; /* DTX/CNG - counter of active frames */ + short ho_circ_size; /* DTX/CNG - size of DTX hangover history buffer for averaging, <0,HO_HIST_SIZE> */ + short ho_circ_ptr; /* DTX/CNG - pointer for averaging buffers */ + float ho_lsp_circ[HO_HIST_SIZE*M]; /* DTX/CNG - old LSP buffer for averaging */ + float ho_ener_circ[HO_HIST_SIZE]; /* DTX/CNG - energy buffer for averaging */ + float ho_env_circ[HO_HIST_SIZE*NUM_ENV_CNG]; + short num_ho; /* DTX/CNG - number of selected hangover frames */ + short ho_16k_lsp[HO_HIST_SIZE]; /* DTX/CNG - 16k LSPs flags */ + short CNG_mode; /* DTX/CNG - mode for DTX configuration */ + long last_active_brate; /* DTX/CNG - last active frame bitrate used for CNG_mode control */ + short last_CNG_L_frame; /* DTX/CNG - last CNG frame length */ + short act_cnt2; /* DTX/CNG - counter of active frames for CNG_mode switching */ + short cng_type; /* DTX/CNG - flag indicating LP or CLDFB based SID/CNG */ + short last_cng_type; /* DTX/CNG - flag indicating last frame LP or CLDFB based SID/CNG */ + float old_env[20]; + float lp_env[20]; + float exc_mem[24]; + float exc_mem1[30]; + + short bpf_off; /* Bass post-filter - do not use BPF when this flag is set to 1 */ + float pst_old_syn[NBPSF_PIT_MAX]; /* Bass post-filter - old synthesis buffer 1 */ + float pst_mem_deemp_err; /* Bass post-filter - filter memory of noise LP filter */ + float pst_lp_ener; /* Bass post-filter - long-term energy */ + short Track_on_hist[L_TRACK_HIST]; /* Bass post-filter - History of half frame usage */ + short vibrato_hist[L_TRACK_HIST]; /* Bass post-filter - History of frames declared as vibrato */ + float psf_att; /* Bass post-filter - post filter attenuation factor */ + float mem_mean_pit[L_TRACK_HIST]; /* Bass post-filter - average pitch memory */ + + HANDLE_CLDFB_FILTER_BANK cldfbAna; /* main analysis filter bank handle */ + HANDLE_CLDFB_FILTER_BANK cldfbBPF; /* BPF analysis filter bank handle */ + HANDLE_CLDFB_FILTER_BANK cldfbSyn; /* main synthesis filter bank handle */ + + short last_active_bandsToZero_bwdec; + short flag_NB_bwddec; + short last_flag_filter_NB; + float perc_bwddec; + int active_frame_cnt_bwddec; + short flag_buffer[20]; + int total_frame_cnt_bwddec; + float avg_nrg_LT; + float ng_ener_ST; /* Noise gate - short-term energy */ + + short last_L_frame; /* ACELP@16kHz - last value of st->L_frame */ + float mem_preemp_preQ; /* ACELP@16kHz - prequantizer preemhasis memory */ + short last_nq_preQ; /* ACELP@16kHz - AVQ subquantizer number of the last sub-band of the last subframe */ + short use_acelp_preq; /* ACELP@16kHz - flag of prequantizer usage */ + + /* Improvement of unvoiced and audio signals in AMR-WB IO mode */ + short UV_cnt; /* number of consecutives frames classified as UV */ + float LT_UV_cnt; /* long-term consecutives frames classified as UV */ + float Last_ener; /* last_energy frame */ + float lt_diff_etot[MAX_LT]; /* stability estimation - long-term total energy variation */ + float old_Aq[NB_SUBFR*(M+1)]; /* old LPC filter coefficient */ + float lt_voice_fac; /* average voice factor over 4 sub-frames */ + + /* NB and formant post-filter */ + PFSTAT pfstat; /* NB and formant post-filter states */ + float psf_lp_noise; /* NB post-filter - long-term noise */ + + /*----------------------------------------------------------------------------------* + * SC-VBR + *----------------------------------------------------------------------------------*/ + + /* PPP decoder variables */ + short last_ppp_mode_dec; + short ppp_mode_dec; + short last_nelp_mode_dec; + short nelp_mode_dec; + int firstTime_voiceddec; + + /* DTFS variables */ + float dtfs_dec_a[MAXLAG_WI]; + float dtfs_dec_b[MAXLAG_WI]; + int dtfs_dec_lag; + int dtfs_dec_nH; + int dtfs_dec_nH_4kHz; + float dtfs_dec_upper_cut_off_freq_of_interest; + float dtfs_dec_upper_cut_off_freq; + float ph_offset_D; + float lastLgainD; /* previous gain value for the low band */ + float lastHgainD; /* previous gain value for the high band */ + float lasterbD[NUM_ERB_WB]; /* previous amplitude spectrum (ERB) */ + + /* NELP decoder variables */ + float bp1_filt_mem_nb_dec[14]; + float bp1_filt_mem_wb_dec[8]; + float shape1_filt_mem_dec[20]; + float shape2_filt_mem_dec[20]; + float shape3_filt_mem_dec[20]; + + short nelp_dec_seed; + float FadeScale; + float prev_gain_pit_dec; + float prev_tilt_code_dec; + short vbr_hw_BWE_disable_dec; + short last_vbr_hw_BWE_disable_dec; + + /*----------------------------------------------------------------------------------* + * channel-aware mode + *----------------------------------------------------------------------------------*/ + + float tilt_code_dec[NB_SUBFR16k]; + + short rf_frame_type; + short use_partial_copy; + short prev_use_partial_copy; + short rf_flag; + short rf_flag_last; + + short rf_fec_offset; + short next_coder_type; + short prev_rf_frame_type; + short rf_target_bits; + + short rf_indx_nelp_fid; + short rf_indx_nelp_iG1; + short rf_indx_nelp_iG2[2]; + short rf_indx_tbeGainFr; + + /*----------------------------------------------------------------------------------* + * HR SWB BWE parameters + *----------------------------------------------------------------------------------*/ + + short bwe_highrate_seed; + float t_audio_prev[2*END_FREQ_BWE_FULL_FB/50 - NUM_NONTRANS_START_FREQ_COEF]; + short old_is_transient_hr_bwe; + float mem_EnergyLT; + + + /*----------------------------------------------------------------------------------* + * HQ core parameters + *----------------------------------------------------------------------------------*/ + + float synth_history[L_FRAME48k+OLD_SYNTH_SIZE_DEC+NS2SA(48000, PH_ECU_LOOKAHEAD_NS)]; /* unified synthesis memory */ + float *old_synthFB; + float old_out[L_FRAME48k]; /* HQ core - previous synthesis for OLA */ + + float old_outLB[L_FRAME32k]; + float old_coeffs[L_FRAME8k]; /* HQ core - old coefficients (for FEC) */ + float oldIMDCTout[L_FRAME8k/2]; + float prev_oldauOut[L_FRAME8k]; + float diff_energy; + short stat_mode_out; + short stat_mode_old; + short phase_mat_flag; + short phase_mat_next; + short old_Min_ind; + float old_auOut_2fr[L_FRAME8k*2]; + short old_is_transient[3]; /* HQ core - previous transient flag (for FEC) */ + float old_out_pha[2][N_LEAD_NB]; /* FEC for HQ Core, 0-phase matching old_out, 1-overlapping original old_out and phase matching old_out*/ + short old_bfi_cnt; /* HQ core - # of bfi until previous frame(for FEC) */ + float ynrm_values[MAX_SB_NB][MAX_PGF]; + float r_p_values[MAX_SB_NB][MAX_ROW]; + float Norm_gain[SFM_N_NB]; + short HQ_FEC_seed; + float energy_MA_Curr[2]; + + short last_core; + short prev_last_core; + short last_hq_core_type; + short last_L_frame_ori; + float previoussynth[L_FRAME48k]; + float old_synth_sw[NS2SA(48000,FRAME_SIZE_NS-ACELP_LOOK_NS-DELAY_BWE_TOTAL_NS)]; + float delay_buf_out[HQ_DELTA_MAX*HQ_DELAY_COMP]; + short mem_norm[SFM_N_ENV_STAB]; + float mem_env_delta; + short no_att_hangover; + float energy_lt; + short hq_generic_seed; + float prev_noise_level[2]; + short prev_hqswb_clas; + short prev_R; /* the table of bit allocation of last frame */ + float prev_coeff_out[L_HQ_WB_BWE]; /* the highest coefficients of last frame */ + short prev_SWB_peak_pos[SPT_SHORTEN_SBNUM]; + float old_Aq_12_8[M+1]; /* old Aq[] for core switching */ + float old_Es_pred; /* old Es_pred for core switching */ + + short HqVoicing; + float fer_samples[L_FRAME48k]; + float prev_normq[SFM_N_WB]; /* previous norms */ + float prev_env[SFM_N_WB]; /* previous noise envelopes */ + + float last_ni_gain[BANDS_MAX]; + float last_env[BANDS_MAX]; + short last_max_pos_pulse; + + /* pre-echo reduction */ + float memfilt_lb; + float mean_prev_hb; + float smoothmem; + float mean_prev; + float mean_prev_nc; + float wmold_hb; + short prevflag; + short pastpre; + short prev_frm_hfe2; + short prev_stab_hfe2; + float prev_ni_ratio; + float prev_En_sb[NB_SWB_SUBBANDS]; + + /* PVQ range coder state */ + unsigned int rc_low; + unsigned int rc_range; + unsigned int rc_help; + short rc_num_bits; + short rc_offset; + short rc_end; + + /*----------------------------------------------------------------------------------* + * TBE parameters + *----------------------------------------------------------------------------------*/ + + /* states for the filters used in generating SHB excitation from WB excitation */ + float state_lpc_syn[LPC_SHB_ORDER]; + float mem_csfilt [2]; + + /* states for the filters used in generating SHB signal from SHB excitation*/ + float state_syn_shbexc[L_SHB_LAHEAD]; + float syn_overlap[L_SHB_LAHEAD]; /* overlap buffer used to Adjust SHB Frame Gain*/ + + /* previous frame parameters for frame error concealment */ + float lsp_prevfrm[ LPC_SHB_ORDER]; + float GainFrame_prevfrm; + float GainShape_Delay[NUM_SHB_SUBFR/2]; + float GainAttn; + + float old_bwe_exc[PIT16k_MAX * 2]; /* old excitation */ + short bwe_seed[2]; + float bwe_non_lin_prev_scale; + float old_bwe_exc_extended[NL_BUFF_OFFSET]; + float last_voice_factor; + + float genSHBsynth_Hilbert_Mem[HILBERT_MEM_SIZE]; + + float mem_genSHBexc_filt_down_shb[(2*ALLPASSSECTIONS_STEEP+1)]; + float mem_genSHBexc_filt_down_wb2[(2*ALLPASSSECTIONS_STEEP+1)]; + float mem_genSHBexc_filt_down_wb3[(2*ALLPASSSECTIONS_STEEP+1)]; + float genSHBsynth_state_lsyn_filt_shb_local[ 2 * ALLPASSSECTIONS_STEEP ]; + float state_lsyn_filt_shb[ 2 * ALLPASSSECTIONS_STEEP]; + float state_lsyn_filt_dwn_shb[ 2 * ALLPASSSECTIONS_STEEP]; + float mem_resamp_HB[INTERP_3_1_MEM_LEN]; + float mem_resamp_HB_32k[2*ALLPASSSECTIONS_STEEP+1]; + float prev_synth_buffer[NS2SA(48000,DELAY_BWE_TOTAL_NS - DELAY_CLDFB_NS)]; + float hb_prev_synth_buffer[NS2SA(48000, DELAY_BWE_TOTAL_NS)]; + short old_bwe_delay; + + short syn_dm_phase; + float fbbwe_hpf_mem[4][4]; + float prev_wb_bwe_frame_pow; + float prev_swb_bwe_frame_pow; + float prev_ener; + float prev_GainShape; + float fb_state_lpc_syn[LPC_SHB_ORDER]; + float fb_tbe_demph; + float prev_fbbwe_ratio; + + /* WB/SWB bandwidth switching */ + float tilt_wb; + float tilt_swb; + float prev_ener_shb; + float enerLH; + float prev_enerLH; + float enerLL; + float prev_enerLL; + short prev_fractive; + short prev_bws_cnt; + short bws_cnt; + short bws_cnt1; + float attenu1; + short last_inner_frame; + short last_bwidth; + float prev_weight1; + float t_audio_q[L_FRAME]; + float tbe_demph; + float tbe_premph; + float mem_stp_swb[LPC_SHB_ORDER]; + float *ptr_mem_stp_swb; + float gain_prec_swb; + float mem_zero_swb[LPC_SHB_ORDER]; + + float swb_lsp_prev_interp[LPC_SHB_ORDER]; + float prev1_shb_ener_sf, prev2_shb_ener_sf, prev3_shb_ener_sf, prev_res_shb_gshape, prev_mixFactors; + float tilt_mem; /* Formant factor adaptation tilt smoothing memory */ + float prev_lsf_diff[LPC_SHB_ORDER-2]; + float prev_tilt_para; + float cur_sub_Aq[M+1]; + + /* quantized data */ + short lsf_idx[NUM_Q_LSF]; + short m_idx; + short grid_idx; + short idxSubGains; + short idxFrameGain; + short idx_shb_fr_gain; + short idx_res_gs[NB_SUBFR16k]; + short idx_mixFac; + + short lsf_WB; + short gFrame_WB; + + short idxGain; + + float old_core_synth[L_FRAME16k]; + float old_tbe_synth[L_SHB_TRANSITION_LENGTH]; + + float int_3_over_2_tbemem_dec[INTERP_3_2_MEM_LEN]; + float interpol_3_2_cng_dec[INTERP_3_2_MEM_LEN]; + + /*----------------------------------------------------------------------------------* + * SWB BWE parameters + *----------------------------------------------------------------------------------*/ + + float old_wtda_swb[L_FRAME48k]; + float old_syn_12k8_16k[NS2SA(16000, DELAY_FD_BWE_ENC_NS)]; + float mem_deemph_old_syn; + short prev_mode; + float prev_SWB_fenv[SWB_FENV]; + float prev_Energy; + float prev_Energy_wb; + short prev_L_swb_norm; + short Seed; + short prev_frica_flag; + float mem_imdct[L_FRAME48k]; + float prev_td_energy; + float prev_weight; + short prev_coder_type; + short prev_flag; + float last_wb_bwe_ener; + float prev_fb_ener_adjust; + + /*----------------------------------------------------------------------------------* + * SWB DTX/CNG parameters + *----------------------------------------------------------------------------------*/ + + float shb_cng_ener; + float wb_cng_ener; + float last_wb_cng_ener; + float last_shb_cng_ener; + short swb_cng_seed; + float lsp_shb_prev_prev[LPC_SHB_ORDER]; + float lsp_shb_prev[LPC_SHB_ORDER]; + short shb_dtx_count; + short last_vad; + short trans_cnt; + short burst_cnt; + float last_shb_ener; + + /*----------------------------------------------------------------------------------* + * HQ FEC + *----------------------------------------------------------------------------------*/ + float *prev_good_synth; + short prev_sign_switch[HQ_FEC_SIGN_SFM]; + short prev_sign_switch_2[HQ_FEC_SIGN_SFM]; + + /* HQ PHASE ECU internal state */ + short time_offs; + float X_sav[PH_ECU_SPEC_SIZE]; + short num_p; + short plocs[MAX_PLOCS]; + float plocsi[MAX_PLOCS]; + float env_stab; + short mem_norm_hqfec[SFM_N_ENV_STAB]; + float mem_env_delta_hqfec; + float env_stab_plc; + float env_stab_state_p[NUM_ENV_STAB_PLC_STATES]; + short envstabplc_hocnt; + + float mag_chg_1st[LGW_MAX]; /* i/o: per band magnitude modifier for transients*/ + float Xavg[LGW_MAX]; /* Frequency group average gain to fade to */ + float beta_mute; /* Factor for long-term mute */ + + short last_fec; + short ph_ecu_HqVoicing; + short oldHqVoicing; + float oldgapsynth[L_FRAME48k]; + short ph_ecu_active; /* Set to 1 if Phase ECU was used in last bad frame; Set to 2 if TCX TD PLC was used */ + short ni_seed_forfec; + short ber_occured_in_pvq; /* flag for BER detection from PVQ routines */ + + /*----------------------------------------------------------------------------------* + * LD music post-filter + *----------------------------------------------------------------------------------*/ + + float LDm_mem_etot; /* LD music post-filter - total energy memory */ + short LDm_last_music_flag; /* LD music post-filter - last music flag */ + short LDm_nb_thr_1; /* LD music post-filter - number of consecutive frames of level 1 */ + short LDm_nb_thr_3; + float dct_post_old_exc[DCT_L_POST-OFFSET2]; + float LDm_thres[4]; /* LD music post-filter - Classification threshold */ + float LDm_lt_diff_etot[MAX_LT]; /* LD music post-filter - long-term total energy variation */ + float LDm_enh_lp_gbin[VOIC_BINS_HR]; /* LD music post-filter - smoothed suppression gain, per bin FFT */ + float LDm_enh_lf_EO[VOIC_BINS_HR]; /* LD music post-filter - old per bin E for previous half frame */ + float LDm_enh_min_ns_gain; /* LD music post-filter - minimum suppression gain */ + float LDm_bckr_noise[MBANDS_GN_LD]; /* LD music post-filter - background noise estimation per critical band */ + float filt_lfE[DCT_L_POST]; + short last_nonfull_music; + + + /*ACELP config*/ + short force_lpd_reset; + ACELP_config acelp_cfg; /*configuration set for each frame*/ + + ACELP_config acelp_cfg_rf; /* configuration for RF frame */ + + /*TCX config*/ + TCX_config tcx_cfg; + int L_frameTCX; + + /*dec_prm.c*/ + int bits_frame; /*bit per frame overall */ + int bits_frame_core; /*bit per frame for the core*/ + int narrowBand; + + int last_is_cng; + + float old_syn_Overl[L_FRAME32k/2]; + + float syn_Overl_TDAC[L_FRAME32k/2]; + float syn_Overl_TDACFB[L_FRAME_MAX/2]; + + float syn_Overl[L_FRAME32k/2]; + float syn_OverlFB[L_FRAME_MAX/2]; + + float *acelp_zir; + float old_synth[OLD_SYNTH_INTERNAL_DEC];/* synthesis memory */ + int old_synth_len; + int old_synth_lenFB; + float syn[M+1]; + + /* bass_pf.c */ + int bpf_gain_param; /* bass post-filter gain factor parameter (0->noBpf)*/ + + int L_frame_past; + int L_frameTCX_past; + + float lsfold_uw[M]; /* old lsf (unweighted) */ + float lspold_uw[M]; /* old lsp (unweighted) */ + short seed_tcx_plc; /* seed memory (for random function in TCX PLC) */ + float past_gpit; /* past gain of pitch (for frame recovery) */ + float past_gcode; /* past energy (!) of code (for frame recovery) */ + float lsf_cng[M]; /* lsf coefficients used for CNG generation (long term) */ + float lspold_cng[M]; /* lsp coefficients used for CNG generation (long term) */ + float lsp_q_cng[M]; /* lsp coefficients used for CNG generation (short term interpolated) */ + float old_lsp_q_cng[M]; /* lsp coefficients used for CNG generation (short term interpolated) */ + float lsf_q_cng[M]; /* lsf coefficients used for CNG generation (short term interpolated) */ + float old_lsf_q_cng[M]; /* lsf: old quantized lsfs for background noise */ + float Aq_cng[(NB_SUBFR16k+1)*(M+1)]; /* LPC coefficients derived from CNG estimate */ + float mem_syn_unv_back[M]; /* filter memory for unvoiced synth */ + int plcBackgroundNoiseUpdated; /* flag: Is background noise estimate updated? */ + float last_gain_syn_deemph; + float last_concealed_gain_syn_deemph; + + int enableTcxLpc; /* global toggle for the TCX LPC quantizer */ + int envWeighted; /* are is{p,f}_old[] weighted or not? */ + + /* variables for framing */ + int nb_subfr; + + int fscale; + int fscale_old; + int sr_core; + + int pit_min; + int pit_fr1; + int pit_fr1b; + int pit_fr2; + int pit_max; + int pit_res_max; + int pit_res_max_past; + + int pit_min_TCX; + int pit_max_TCX; + + /*Preemphasis factor*/ + float preemph_fac; + float gamma; + + /*for AMR-WB like 6.4 to 7 kHz upsampling and noise filling*/ + float mem_Aq[NB_SUBFR16k*(M+1)]; + + /* Error concealment */ + int last_core_bfi; /* PLC - mode in previous frame */ + int nbLostCmpt; /* PLC - compt for number of consecutive lost frame */ + int noise_filling_index; /* PLC - last decoded noise filling index */ + float old_fpitch; /* PLC - last pitch of previous frame (as transmitted) */ + float old_fpitchFB; /* PLC - last pitch of previous FB frame (depends on output sr) */ + short clas_dec; /* PLC - frame class at the decoder */ + float mem_pitch_gain[2*NB_SUBFR16k+2]; /* PLC - Pitch gain memory */ + short plc_use_future_lag; /* PLC - flag indicating if info (pitch lag / pitch gain) about + future frame is usable */ + int prev_widow_left_rect; + float CngLevelBackgroundTrace_bfi; /* PLC - long term gain estimate for background level, used for PLC fade out */ + /* state variables for the minimum statistics used for PLC */ + float NoiseLevelMemory_bfi[PLC_MIN_STAT_BUFF_SIZE]; + int NoiseLevelIndex_bfi; + int CurrLevelIndex_bfi; + float LastFrameLevel_bfi; + float old_gaintcx_bfi; + float cummulative_damping; + float cngTDLevel; + float conceal_eof_gain; + float damping; + float gainHelper; + float stepCompensate; + int reset_mem_AR; + short tcxConceal_recalc_exc; + + short rate_switching_init; + + /* LPC quantization */ + int lpcQuantization; + int numlpc; + + /* Bandwidth */ + float TcxBandwidth; + + float voice_fac; + + int tcxonly; + + /*TCX resisual Q*/ + int resQBits[NB_DIV]; /* number of bits read for the residual Quantization in TCX*/ + + int last_ctx_hm_enabled; + + /* TCX-LTP */ + int tcxltp; /* TCX LTP enabled for operation mode */ + float tcxltp_gain; + int tcxltp_pitch_int; + int tcxltp_pitch_fr; + + float tcxltp_mem_in[TCXLTP_MAX_DELAY]; + float tcxltp_mem_out[L_FRAME48k]; + int tcxltp_pitch_int_post_prev; + int tcxltp_pitch_fr_post_prev; + float tcxltp_gain_post_prev; + int tcxltp_filt_idx_prev; + + struct tonalmdctconceal tonalMDCTconceal; + int tonal_mdct_plc_active; + int last_tns_active; + int second_last_tns_active; + float cummulative_damping_tcx; + int second_last_core; + float tcxltp_second_last_pitch; + float tcxltp_third_last_pitch; + float tcxltp_last_gain_unmodified; + + float FBTCXdelayBuf[111]; /* 2.3125ms at 48kHz -> 111 samples */ + + /* parameters for switching */ + float mem_syn_r[L_SYN_MEM]; /*LPC synthesis memory needed for rate switching*/ + short rate_switching_reset; + + float bpf_noise_buf[L_FRAME16k]; + float *p_bpf_noise_buf; + + int enableGplc; + int flagGuidedAcelp; + int T0_4th; + int guidedT0; + + short enablePlcWaveadjust; + short tonality_flag; + T_PLCInfo plcInfo; + + short VAD; + short flag_cna; + short last_flag_cna; + + float lp_noise; + + short seed_acelp; + int core_ext_mode; /*GC,VC,UC,TC: core extended mode used for PLC or Acelp-external modules.*/ + + short dec_glr; + short dec_glr_idx; + + short tcx_hm_LtpPitchLag; + short tcx_lpc_shaped_ari; + + DEC_MODE m_decodeMode; + unsigned char m_frame_type; /*ZERO_FRAME/SID_FRAME/ACTIVE_FRAME*/ + unsigned char m_old_frame_type; /*ZERO_FRAME/SID_FRAME/ACTIVE_FRAME*/ + + /*Frequency-domain-based CNG*/ + HANDLE_FD_CNG_DEC hFdCngDec; + + IGFDEC_INSTANCE hIGFDec; + short igf; + + short tec_tfa; + short tec_flag; + short tfa_flag; + TEMPORAL_ENVELOPE_CODING_DECODER tecDec; + + short old_ppp_mode; + float old_hb_synth[L_FRAME48k]; + short con_tcx; + short last_con_tcx; + + short writeFECoffset; + + +} Decoder_State; + +#endif + diff --git a/src/libs/libevs/lib_dec/stat_dec_fx.h b/src/libs/libevs/lib_dec/stat_dec_fx.h deleted file mode 100755 index 6b20fe9d..00000000 --- a/src/libs/libevs/lib_dec/stat_dec_fx.h +++ /dev/null @@ -1,1112 +0,0 @@ -/*==================================================================================== - EVS Codec 3GPP TS26.442 Apr 03, 2018. Version 12.11.0 / 13.6.0 / 14.2.0 - ====================================================================================*/ - -#ifndef STAT_DEC_FX_H -#define STAT_DEC_FX_H - - -#include "options.h" /* Compilation switches */ -#include "cnst_fx.h" -#include "stat_com.h" - - -/*------------------------------------------------------------------------------------------* - * Indice - *------------------------------------------------------------------------------------------*/ - - -/* decoder mode enums */ -typedef enum _DEC_MODE -{ - DEC_NO_FRAM_LOSS = 0x0, - DEC_CONCEALMENT_EXT = 0x1 -} DEC_MODE; - -typedef enum -{ - FRAMEMODE_NORMAL = 0x0, /**< frame available */ - FRAMEMODE_MISSING = 0x1, /**< frame missing => conceal */ - FRAMEMODE_FUTURE = 0x2 -} frameMode_fx; - - -struct dispMem_fx -{ - Word16 prev_state; /*Q0 */ - Word32 prev_gain_code; /*Q16 */ - Word16 prev_gain_pit[6]; /*Q14 */ -}; - - -/*ari.h*/ -typedef struct -{ - Word32 low,high,vobf; -} TastatDec; - -/*---------------------------------------------------------------* - * IGF * - *---------------------------------------------------------------*/ -/* IGFSCFDecoder.h */ -typedef struct -{ - Word16 bitsRead; /* after a call bitsRead contains the number of bits consumed by the decoder */ - Word16 prev[64]; /* no more than 64 SCFs for the IGF energy envelope of one block, short or long */ - Word16 scfCountLongBlock; - Word16 t; - const Word16 *cf_se00; - const Word16 *cf_se01; - Word16 cf_off_se01; - const Word16 *cf_se02; - const Word16 *cf_off_se02; - const Word16 *cf_se10; - Word16 cf_off_se10; - const Word16 *cf_se11; - const Word16 *cf_off_se11; - TastatDec acState; -} IGFSCFDEC_INSTANCE, *IGFSCFDEC_INSTANCE_HANDLE; - -/* IGFDec.h */ -typedef struct igfdec_private_data_struct -{ - - IGF_INFO igfInfo; - /* envelope reconstruction: */ - Word32 igf_sN[IGF_MAX_SFB]; /* Q31 | only with short blocks as static needed */ - Word16 igf_sN_e[IGF_MAX_SFB]; /* | exponent for igf_sN */ - Word32 igf_pN[IGF_MAX_SFB]; /* Q31 | only with short blocks as static needed */ - Word16 igf_pN_e[IGF_MAX_SFB]; /* | exponent for igf_sN */ - Word16 igf_curr[IGF_MAX_SFB]; /* Q0 | igf_curr = [0, 91], current igf energies from bitstream */ - Word16 igf_prev[IGF_MAX_SFB]; /* Q0 | igf_prev = [0, 91], needed for concealment or indepflag==0 */ - Word16 igf_curr_subframe[IGF_MAX_SUBFRAMES][IGF_TRANS_FAK][IGF_MAX_SFB]; /* | current igf energies per subframe */ - Word16 igf_prev_subframe[IGF_MAX_SUBFRAMES][IGF_MAX_SFB]; /* | needed for concealment or indepflag==0 */ - Word16 igf_flatteningTrigger_subframe[IGF_MAX_SUBFRAMES]; - - /* spectral whitening: */ - Word32 pSpecFlat[IGF_START_MX]; /* Q31 | MDCT spectrum before LPC shaping */ - Word16 pSpecFlat_exp; /* | exponent of pSpecFlat */ - Word16 currWhiteningLevel[IGF_MAX_TILES]; /* Q0 | currWhiteningLevel = [0, 2], whitening lvl from bitstream */ - Word16 prevWhiteningLevel[IGF_MAX_TILES]; /* Q0 | prevWhiteningLevel = [0, 2], needed for concealment */ - Word16 currWhiteningLevel_subframe[IGF_MAX_SUBFRAMES][IGF_MAX_TILES]; - Word16 prevWhiteningLevel_subframe[IGF_MAX_SUBFRAMES][IGF_MAX_TILES]; /* | needed for concealment */ - - Word32 totalNoiseNrg; - Word16 n_noise_bands; - Word16 headroom_TCX_noise_white; - Word16 headroom_TCX_noise; - - Word32 totalNoiseNrg_off; - Word16 n_noise_bands_off; - - /* IGF SCF decoding: */ - IGFSCFDEC_INSTANCE hArithSCFdec; - - /* concealment: */ - Word16 frameLossCounter; - -} IGFDEC_PRIVATE_DATA,*IGF_DEC_PRIVATE_DATA_HANDLE; - -typedef struct igfdec_instance_struct -{ - Word16 isIGFActive; - Word16 infoIGFAllZero; - Word16 infoIGFStopLine; - Word16 infoIGFStartLine; - Word16 infoIGFStopFreq; - Word16 infoIGFStartFreq; - Word16 infoTCXNoise[IGF_START_MX]; - Word16 flag_sparse[N_MAX_TCX-IGF_START_MN]; - Word32 virtualSpec[N_MAX_TCX-IGF_START_MN]; /* Q31 | buffer for temp flattening */ - Word16 virtualSpec_e; /* | exponent of virtualSpec */ - Word16 flatteningTrigger; - IGFDEC_PRIVATE_DATA igfData; -} IGFDEC_INSTANCE, *IGF_DEC_INSTANCE_HANDLE; - -typedef struct -{ - Word16 FrameSize; - Word16 Pitch_fx; - Word8 T_bfi_fx; - Word16 Transient[MAX_POST_LEN]; - Word16 TCX_Tonality[DEC_STATE_LEN]; - Word16 outx_new_n1_fx; - Word16 nsapp_gain_fx; - Word16 nsapp_gain_n_fx; - Word32 data_reci2_fx[L_FRAME_MAX]; - Word16 data_reci2_scale; - Word16 data_noise[L_FRAME_MAX]; - Word32 ener_mean_fx; - Word32 ener_fx; - Word16 zp_fx; - Word16 recovery_gain; /*outside waveformadjustment: Q14 - insinde waveformadjustment: Q15*/ - Word16 step_concealgain_fx; - Word16 concealment_method; - Word16 subframe_fx; - Word32 nbLostCmpt; - Word16 seed; -} T_PLCInfo; - -/*---------------------------------------------------------------* - * Structures for Tonal MDCT PLC * - *---------------------------------------------------------------*/ -typedef enum -{ - TONALMDCTCONCEAL_OK = 0, - - __error_codes_start = -100, - - TONALMDCTCONCEAL_NSAMPLES_LARGER_THAN_MAXBLOCKSIZE, - TONALMDCTCONCEAL_INVALIDPOINTER, - TONALMDCTCONCEAL_UNEXPECTED_ERROR, - - __error_codes_end -} TONALMDCTCONCEAL_ERROR; - -typedef struct -{ - Word16 nSamples; - Word16 nSamplesCore; - Word16 * spectralData; - Word16 spectralData_exp; - Word16 * scaleFactors; - Word16 * scaleFactors_exp; - Word16 scaleFactors_max_e; - Word16 gain_tcx_exp; - Word8 blockIsValid; - Word16 blockIsConcealed; - Word8 tonalConcealmentActive; -} blockData; - -typedef struct -{ - Word16 numIndexes; - Word16 indexOfTonalPeak[MAX_NUMBER_OF_IDX]; - Word16 lowerIndex[MAX_NUMBER_OF_IDX]; - Word16 upperIndex[MAX_NUMBER_OF_IDX]; - Word16 phaseDiff[MAX_NUMBER_OF_IDX]; /* This one can be stored with 16 bits in range 0..2*PI */ - Word16 phase_currentFramePredicted[MAX_NUMBER_OF_IDX*GROUP_LENGTH]; /* This one can be stored with 16 bits in range [-pi;pi] 2Q13, but the code has to be adapted to use moduo(2*PI) after adding */ -} TonalComponentsInfo; - -typedef void (*ApplyScaleFactorsPointer)(Word16 const x[], Word16 lg, Word16 lg_total, Word16 const scaleFactors[], Word16 const scaleFactors_exp[], Word16 gains_max_exp, Word32 y[]); - -struct tonalmdctconceal -{ - TCX_config * tcx_cfg; - Word16 * pMDSTData; - Word16 nSamples; - Word16 nSamplesCore; - Word16 nNonZeroSamples; - Word16 nScaleFactors; - - Word32 lastPitchLag; - - blockData lastBlockData; - blockData secondLastBlockData; - - Word16 scaleFactorsBuffers[2][FDNS_NPTS]; /* Contains also global gain. */ - Word16 scaleFactorsBuffers_exp[2][FDNS_NPTS]; - Word16 spectralDataBuffers[2][L_FRAME_MAX]; /* 16 bits is enough, because it is stored before applying scale factors. Take care that power spectrum is also stored here. */ - Word16 timeDataBuffer[(3*L_FRAME_MAX)/2]; /* 16 bits are enough for the TD signal */ - - Word16 * lastPcmOut; - Word16 * secondLastPcmOut; - Word16 * secondLastPowerSpectrum; - Word16 secondLastPowerSpectrum_exp; - - Word16 nFramesLost; - - TonalComponentsInfo * pTCI; -}; - -typedef struct tonalmdctconceal* TonalMDCTConcealPtr; - -/*****************************************/ -/* STAT DEC */ -/*****************************************/ - -/*fd_cng_dec.h*/ -/* Arrays and variables specific to decoder */ -typedef struct -{ - HANDLE_FD_CNG_COM hFdCngCom; - - Word16 olapBufferAna[320]; - Word16 olapBufferSynth2[FFTLEN]; - - Word32 msPeriodog[NPART_SHAPING]; /* Periodogram */ - Word16 msPeriodog_exp; /* Common exponent for fft and cldfb energies */ - Word16 msPeriodog_exp_fft; - Word16 msPeriodog_exp_cldfb; - Word32 msBminWin[NPART_SHAPING]; - Word32 msBminSubWin[NPART_SHAPING]; - Word16 msPsd[NPART_SHAPING]; /* Power Spectral Density estimate (i.e., smoothed periodogram) */ - Word16 msPsd_exp_fft; - Word32 msAlpha[NPART_SHAPING]; /* Optimal smoothing parameter */ - - - Word32 msMinBuf[MSNUMSUBFR*NPART_SHAPING]; /* Buffer of minima */ - Word32 msCurrentMinOut[NPART_SHAPING]; - Word32 msCurrentMin[NPART_SHAPING]; - Word32 msCurrentMinSubWindow[NPART_SHAPING]; - - Word16 msLocalMinFlag[NPART_SHAPING]; - Word16 msNewMinFlag[NPART_SHAPING]; - - Word16 msPsdFirstMoment[NPART_SHAPING]; - Word32 msPsdSecondMoment[NPART_SHAPING]; - Word16 msNoiseFloor[NPART_SHAPING]; /* Estimated noise floor */ - Word32 msNoiseEst[NPART_SHAPING]; /* Estimated noise level */ - Word16 msNoiseEst_exp; - - Word16 npart_shaping; /* Number of partitions */ - Word16 nFFTpart_shaping; /* Number of hybrid spectral partitions */ - Word16 part_shaping[NPART_SHAPING]; /* Partition upper boundaries (band indices starting from 0) */ - Word16 midband_shaping[NPART_SHAPING]; /* Central band of each partition */ - Word16 psize_shaping[NPART_SHAPING]; /* Partition sizes */ - Word16 psize_shaping_norm[NPART_SHAPING]; /* Partition sizes, fractional variable */ - Word16 psize_shaping_norm_exp; /* Partition sizes exponent for fractional variable */ - Word16 psize_inv_shaping[NPART_SHAPING]; /* Inverse of partition sizes */ - Word32 bandNoiseShape[FFTLEN2]; /* CNG spectral shape computed at the decoder */ - Word16 bandNoiseShape_exp; /* exponent of bandNoiseShape */ - Word32 partNoiseShape[NPART]; /* CNG spectral shape computed at the decoder */ - Word16 partNoiseShape_exp; /* exponent of partNoiseShape */ - - Word16 flag_dtx_mode; - - Word32 lp_speech; /* format: Q9.23 */ - Word32 lp_noise; /* format: Q9.23 */ - - Word16 msPeriodogBuf[MSBUFLEN*NPART_SHAPING]; - Word16 msPeriodogBufPtr; - - Word16 msLogPeriodog[NPART_SHAPING]; - Word16 msLogNoiseEst[NPART_SHAPING]; -} -FD_CNG_DEC; -typedef FD_CNG_DEC *HANDLE_FD_CNG_DEC; - - -typedef struct Decoder_State_fx -{ - - /*----------------------------------------------------------------------------------* - * Common parameters - *----------------------------------------------------------------------------------*/ - Word16 codec_mode; /* MODE1 or MODE2 */ - Word16 mdct_sw_enable; /* MDCT switching enable flag */ - Word16 mdct_sw; /* MDCT switching indicator */ - Word16 last_codec_mode; /* last used codec mode*/ - UWord16 *bit_stream_fx; - Word16 next_bit_pos_fx; /* position of the next bit to be read from the bitstream */ - Word16 bitstreamformat; /* Bitstream format flag (G.192/MIME) */ - Word16 amrwb_rfc4867_flag; /* MIME from rfc4867 is used */ - Word16 total_num_bits; /* == st->total_brate / 50 */ - Word16 BER_detect; /* flag to signal detected bit error in the bitstream */ - - Word32 output_Fs_fx; /* output sampling rate Q0*/ - Word16 output_frame_fx; /* Output frame length Q0*/ - Word32 total_brate_fx; /* total bitrate in kbps of the codec Q0*/ - Word32 last_total_brate_fx; /* last total bitrate in kbps of the codec Q0*/ - Word32 last_total_brate_ber_fx; /* last total bitrate in kbps of the codec - used only when first frame is lost and BER is detected afterwards */ - Word16 core_fx; /* core (ACELP_CORE, TCX_20_CORE, TCX_10_CORE, HQ_CORE, AMR_WB_CORE) */ - Word32 core_brate_fx; /* core bitrate */ - Word32 last_core_brate_fx; /* previous frame core bitrate Q0*/ - Word16 extl_fx; /* extension layer Q0*/ - Word16 last_extl_fx; /* previous extension layer Q0*/ - Word32 extl_brate_fx; /* extension layer bitrate */ - Word16 L_frame_fx; /* ACELP core internal frame length */ - Word16 bwidth_fx; /* encoded signal bandwidth */ - Word16 Opt_AMR_WB_fx; /* flag indicating AMR-WB IO mode Q0*/ - Word16 Opt_VOIP_fx; /* flag indicating VOIP mode with JBM */ - Word16 ini_frame_fx; /* initialization frames counter */ - Word16 CNG_fx; /* RXDTX handler: CNG=1, nonCNG=0 */ - Word16 prev_ft_speech_fx; /* RXDTX handler: previous frametype flag for G.192 format AMRWB SID_FIRST detection */ - - /*----------------------------------------------------------------------------------* - * ACELP core parameters - *----------------------------------------------------------------------------------*/ - - Word16 old_exc_fx[L_EXC_MEM_DEC]; /* old excitation Q_exc*/ - Word16 old_excFB_fx[L_FRAME48k]; /* old excitation FB */ - Word16 lsp_old_fx[M]; /* old LSP vector at the end of the frame Q15*/ - Word16 lsf_old_fx[M]; /* old LSF vector at the end of the frame Q2.56*/ - Word32 offset_scale1_fx[MAX_NO_MODES+1][MAX_NO_SCALES+1]; /* offsets for LSF LVQ structure 1st 8-dim subvector*/ - Word32 offset_scale2_fx[MAX_NO_MODES+1][MAX_NO_SCALES+1]; /* offsets for LSF LVQ structure 2nd 8-dim subvector*/ - Word32 offset_scale1_p_fx[MAX_NO_MODES_p+1][MAX_NO_SCALES+1]; /* offsets for LSF LVQ structure, pred. case, 1st 8-dim subvector*/ - Word32 offset_scale2_p_fx[MAX_NO_MODES_p+1][MAX_NO_SCALES+1]; /* offsets for LSF LVQ structure, pred. case, 2nd 8-dim subvector*/ - Word16 no_scales_fx[MAX_NO_MODES][2]; /* LSF LVQ structure Q0*/ - Word16 no_scales_p_fx[MAX_NO_MODES_p][2]; /* LSF LVQ structure Q0*/ - Word16 tilt_code_fx; /* tilt of code Q15*/ - Word16 mem_syn2_fx[M]; /* synthesis filter memory Q_syn*/ - Word16 mem_syn1_fx[M]; /* synthesis filter memory (for core switching and FD BWE) */ - Word16 mem_syn3_fx[M]; - Word16 mem_deemph_fx; /* deemphasis filter memory Q_syn*/ - Word32 L_mem_hp_out_fx[5]; /* hp filter memory for synthesis */ - Word16 mem_MA_fx[M]; /* MA memory of LSF quantizer (past quantized residual)(Qx2.56)*/ - Word16 mem_AR_fx[M]; /* AR memory of LSF quantizer (past quantized LSFs without mean)(Qx2.56) */ - Word16 stab_fac_fx; /* LSF stability factor Q15*/ - Word16 stab_fac_smooth_fx; /* low-pass filtered stability factor Q15*/ - Word16 last_coder_type_fx; /* previous coder type Q0*/ - Word16 agc_mem_fx[2]; /* memory of AGC for saturation control Q0*/ - Word16 past_qua_en_fx[GAIN_PRED_ORDER]; /* gain quantization memory (used also in AMR-WB IO mode) */ - Word16 mid_lsf_int_fx; - Word16 safety_net_fx; - - Word16 seed_tcx_fx; /* AC mode (GSC) - seed for noise fill Q0*/ - Word16 GSC_noisy_speech_fx; /* AC mode (GSC) - flag to indicate GSC osn SWB noisy speech */ - Word16 Last_GSC_noisy_speech_flag_fx; /* AC mode (GSC) - mem of the past flag to indicate GSC osn SWB noisy speech */ - Word16 cor_strong_limit_fx; /* AC mode (GSC) - Indicator about high spectral correlation per band */ - Word16 old_y_gain_fx[MBANDS_GN]; /* AC mode (GSC) - AR mem for low rate gain quantization */ - Word16 noise_lev_fx; /* AC mode (GSC) - noise level Q0*/ - Word16 lt_ener_per_band_fx[MBANDS_GN]; /* Q12 */ - Word32 Last_frame_ener_fx; /* AC mode (GSC) - last frame energy */ - Word16 Last_GSC_spectrum_fx[L_FRAME]; /* AC mode (GSC) - Last good GSC spectrum */ - Word16 Last_GSC_pit_band_idx_fx; /* AC mode (GSC) - Last pitch band index Q0*/ - Word16 last_exc_dct_in_fx[L_FRAME]; /* AC mode (GSC) - previous excitation */ - Word16 last_ener_fx; /* AC mode (GSC) - previous energy */ - Word16 last_bitallocation_band_fx[6]; /* AC mode (GSC) - previous bit allocation of each band */ - - Word32 gc_threshold_fx; /* Noise enhancer - threshold for gain_code Q16*/ - struct dispMem_fx dm_fx; /* Noise enhancer - phase dispersion algorithm memory */ - - Word16 prev_r_fx; /* HF BWE - previous sub-frame gain */ - Word16 fmerit_w_sm_fx; /* HF BWE - fmerit parameter memory */ - Word16 frame_count_fx; /* HF BWE - frame count */ - Word16 ne_min_fx; /* HF BWE - minimum Noise gate - short-term energy */ - Word16 fmerit_m_sm_fx; /* HF BWE - memory of fmerit_m param */ - Word16 voice_fac_amr_wb_hf; /* HF BWE - voice factor */ - Word16 unvoicing_fx; /* HF BWE - unvoiced parameter */ - Word16 unvoicing_sm_fx; /* HF BWE - smoothed unvoiced parameter */ - Word16 unvoicing_flag_fx; /* HF BWE - unvoiced flag */ - Word16 voicing_flag_fx; /* HF BWE - voiced flag */ - Word16 start_band_old_fx; /* HF BWE - previous start point for copying frequency band */ - Word32 OptCrit_old_fx; /* HF BWE - previous criterion value for deciding the start point */ - - Word16 seed2_fx; /* HF (6-7kHz) BWE - seed for random signal generator Q0*/ - Word16 mem_hp400_fx[6]; /* HF (6-7kHz) BWE - hp400 filter memory */ - Word16 mem_hf_fx[2*L_FILT16k]; /* HF (6-7kHz) BWE - band-pass filter memory Q(-2-memExp1)*/ - Word16 mem_syn_hf_fx[M]; /* HF (6-7kHz) BWE - synthesis filter memory Q0*/ - Word16 delay_syn_hf_fx[NS2SA(16000,DELAY_CLDFB_NS)]; /* HF (6-7kHz) BWE - To synchronise BWE content with postfiltered synthesis Q0*/ - Word16 mem_hp_interp_fx[INTERP_3_1_MEM_LEN]; /* HF (6-7 kHz) BWE - interp. memory */ - - Word16 unv_cnt_fx; /* Stationary noise UV modification - unvoiced frame counter Q0*/ - Word16 uv_count_fx; /* Stationary noise UV modification - unvoiced counter Q0*/ - Word16 act_count_fx; /* Stationary noise UV modification - activation counter Q0*/ - Word32 ge_sm_fx; /* Stationary noise UV modification - smoothed excitation gain Q(GE_SHIFT)*/ - Word16 lspold_s_fx[M]; /* Stationary noise UV modification - old LSP vector Q15*/ - Word16 noimix_seed_fx; /* Stationary noise UV modification - mixture seed Q0*/ - Word16 min_alpha_fx; /* Stationary noise UV modification - minimum alpha Q15*/ - Word16 Q_stat_noise; /* Q of Exc_pe */ - Word16 exc_pe_fx; /* Stationary noise UV modification - scale (Q_stat_noise) */ - Word16 Q_stat_noise_ge; /* Q of ge_sm_fx */ - - Word16 bfi_fx; /* FEC - bad frame indicator */ - Word16 prev_bfi_fx; /* FEC - previous bad frame indicator Q0*/ - Word16 seed_fx; /* FEC - seed for random generator for excitation Q0*/ - Word16 lp_ener_FER_fx; /* FEC - long-term active-signal average energy Q8*/ - Word16 last_good_fx; /* FEC - clas of last good received Q0*/ - Word16 lp_gainc_fx; /* FEC - low-pass filtered code gain Q3*/ - Word16 lp_gainp_fx; /* FEC - low-pass filtered pitch gain Q14 */ - Word32 lp_ener_fx; /* FEC - low-pass filtered energy Q6*/ - Word32 enr_old_fx; /* FEC - energy of the concealed frame Q0*/ - Word16 bfi_pitch_fx; /* FEC - pitch for FEC */ - Word16 bfi_pitch_frame_fx; /*FEC - frame length when pitch for FEC is saved Q0*/ - Word32 old_pitch_buf_fx[2*NB_SUBFR16k+2]; /* FEC - buffer of old subframe pitch values 15Q16 */ - Word16 upd_cnt_fx; /* FEC - counter of frames since last update Q0*/ - Word16 scaling_flag; /* FEC - flag to indicate energy control of syn */ - Word32 lp_ener_FEC_av; /* FEC - averaged voiced signal energy Q0 */ - Word32 lp_ener_FEC_max; /* FEC - averaged voiced signal energy Q0 */ - Word16 old_enr_LP; /* FEC - LP filter gain Q5*/ - Word16 lsfoldbfi0_fx[M]; /* FEC - LSF vector of the previous frame (Qx2.56)*/ - Word16 lsfoldbfi1_fx[M]; /* FEC - LSF vector of the past previous frame (Qx2.56) */ - Word16 lsf_adaptive_mean_fx[M]; /* FEC - adaptive mean LSF vector for FEC (Qx2.56)*/ - Word16 decision_hyst_fx; /* FEC - hysteresis of the music/speech decision Q0*/ - Word16 old_exc2_fx[L_EXC_MEM]; /* FEC - old excitation2 used in fast recovery */ - Word16 old_syn2_fx[L_EXC_MEM]; /* FEC - old syn speech used in fast recovery */ - Word16 relax_prev_lsf_interp_fx; - Word16 mem_syn_clas_estim_fx[L_SYN_MEM_CLAS_ESTIM]; /* FEC - memory of the synthesis signal for frame class estimation */ - Word16 tilt_swb_fec_fx; /* FEC - SWB TBE TILT */ - - Word16 cng_seed_fx; /*CNG and DTX - seed for white noise random generator*/ - Word16 lspCNG_fx[M]; /* CNG and DTX - LP filtered ISPs Q15*/ - Word16 first_CNG_fx; /* CNG and DTX - first CNG frame flag Q0*/ - Word32 Enew_fx; /* CNG and DTX - decoded residual energy Q6*/ - Word16 old_enr_index_fx; /* CNG and DTX - index of last encoded CNG energy Q0*/ - Word16 cng_ener_seed_fx; /*CNG and DTX - seed for random generator for variation of excitation energyQ0*/ - Word16 cng_ener_seed1_fx; - Word16 last_allow_cn_step_fx; /*Q0*/ - Word16 ho_hist_size_fx; /* CNG and DTX - size of DTX hangover history buffer for averaging, <0,HO_HIST_SIZE> */ - Word16 ho_hist_ptr_fx; /* CNG and DTX - pointer for averaging buffers */ - Word32 ho_sid_bw_fx; /* CNG and DTX - SID bandwidth flags */ - Word16 ho_lsp_hist_fx[HO_HIST_SIZE*M]; /* CNG and DTX - old LSP buffer for averaging */ - Word32 ho_ener_hist_fx[HO_HIST_SIZE]; /* CNG and DTX - energy buffer for averaging */ /*Q6 */ - Word32 ho_env_hist_fx[HO_HIST_SIZE*NUM_ENV_CNG]; - Word16 act_cnt_fx; /* CNG and DTX - counter of active frames */ - Word16 ho_circ_size_fx; /* CNG and DTX - size of DTX hangover history buffer for averaging, <0,HO_HIST_SIZE> */ - Word16 ho_circ_ptr_fx; /* CNG and DTX - pointer for averaging buffers */ - Word16 ho_lsp_circ_fx[HO_HIST_SIZE*M]; /* CNG and DTX - old LSP buffer for averaging */ - Word32 ho_ener_circ_fx[HO_HIST_SIZE]; /* CNG and DTX - energy buffer for averaging */ /* Q6 */ - Word32 ho_env_circ_fx[HO_HIST_SIZE*NUM_ENV_CNG]; - Word16 num_ho_fx; /* DTX/CNG - number of selected hangover frames */ - Word16 ho_16k_lsp_fx[HO_HIST_SIZE]; /* DTX/CNG - 16k LSPs flags */ - Word16 CNG_mode_fx; /* DTX/CNG - mode for DTX configuration */ - Word32 last_active_brate_fx; /* DTX/CNG - last active frame bitrate used for CNG_mode control */ - Word16 last_CNG_L_frame_fx; /* DTX/CNG - last CNG frame length */ - Word16 act_cnt2_fx; /* DTX/CNG - counter of active frames for CNG_mode switching */ - Word16 cng_type_fx; /* DTX/CNG - flag indicating LP or CLDFB based SID/CNG */ - Word16 last_cng_type_fx; /* DTX/CNG - flag indicating last frame LP or CLDFB based SID/CNG */ - Word32 old_env_fx[20]; - Word32 lp_env_fx[20]; - Word16 exc_mem_fx[24]; - Word16 exc_mem1_fx[30]; - - Word16 bpf_off_fx; /* Bass post-filter - do not use BPF when this flag is set to 1 Q0*/ - Word16 pst_old_syn_fx[NBPSF_PIT_MAX]; /* Bass post-filter - old synthesis buffer 1 Q_syn2-1*/ - Word16 pst_mem_deemp_err_fx; /* Bass post-filter - filter memory of noise LP filter Q_syn2-1*/ - Word16 pst_lp_ener_fx; /* Bass post-filter - long-term energy Q8*/ - Word16 Track_on_hist_fx[L_TRACK_HIST]; /* Bass post-filter - History of half frame usage */ - Word16 vibrato_hist_fx[L_TRACK_HIST]; /* Bass post-filter - History of frames declared as vibrato */ - Word16 psf_att_fx; /* Bass post-filter - post filter attenuation factor */ - Word16 mem_mean_pit_fx[L_TRACK_HIST]; /* Bass post-filter - average pitch memory */ - - Word16 Ng_ener_ST_fx; /* Noise gate - short-term energy Q8*/ - - Word16 last_L_frame_fx; /* ACELP@16kHz - last value of st->L_frame */ - Word16 mem_preemp_preQ_fx; /* ACELP@16kHz - prequantizer preemhasis memory */ - Word16 last_nq_preQ_fx; /* ACELP@16kHz - AVQ subquantizer number of the last sub-band of the last subframe */ - Word16 use_acelp_preq; /* ACELP@16kHz - flag of prequantizer usage */ - - /* Improvement of unvoiced and audio signals in AMR-WB IO mode */ - Word16 UV_cnt_fx; /* number of consecutives frames classified as UV */ - Word16 LT_UV_cnt_fx; /* long-term consecutives frames classified as UV */ - Word16 Last_ener_fx; /* last_energy frame */ - Word16 lt_diff_etot_fx[MAX_LT]; /* stability estimation - long-term total energy variation */ - Word16 old_Aq_fx[68]; /* old LPC filter coefficient */ - Word16 lt_voice_fac_fx; /* average voice factor over 4 sub-frames */ - - /*----------------------------------------------------------------------------------* - * SC-VBR - *----------------------------------------------------------------------------------*/ - - Word16 last_ppp_mode_dec_fx; /*Q0*/ - Word16 ppp_mode_dec_fx; /*Q0*/ - Word16 last_nelp_mode_dec_fx; - Word16 nelp_mode_dec_fx; /* Q0 */ - Word16 firstTime_voiceddec_fx; /*Q0*/ - - /* DTFS variables */ - Word16 dtfs_dec_a_fx[MAXLAG_WI]; /*Variable Q format in dtfs_dec_Q*/ - Word16 dtfs_dec_b_fx[MAXLAG_WI]; /*Variable Q format in dtfs_dec_Q*/ - Word16 dtfs_dec_lag_fx; - Word16 dtfs_dec_nH_fx; - Word16 dtfs_dec_nH_4kHz_fx; /*Q0*/ - Word16 dtfs_dec_upper_cut_off_freq_of_interest_fx; /*Q0*/ - Word16 dtfs_dec_upper_cut_off_freq_fx; /*Q0*/ - Word16 ph_offset_D_fx; /* normalized by 2Pi Q15*/ - Word16 lastLgainD_fx; /* previous gain value for the low band Q11*/ - Word16 lastHgainD_fx; /* previous gain value for the high band Q11 */ - Word16 lasterbD_fx[NUM_ERB_WB]; /* previous amplitude spectrum (ERB) Q13*/ - Word16 dtfs_dec_Q; /*Q0*/ - - /* NELP decoder variables */ - Word32 bp1_filt_mem_nb_dec_fx[14]; /* qfm currently Q0*/ - Word16 bp1_filt_mem_wb_dec_fx[8]; /* qfm currently Q0*/ - Word16 shape1_filt_mem_dec_fx[10]; /* qfm currently Q0*/ - Word16 shape2_filt_mem_dec_fx[10]; /* qfm currently Q0*/ - Word16 shape3_filt_mem_dec_fx[10]; /* qfm currently Q0*/ - Word16 nelp_dec_seed_fx; /* Q0*/ - Word16 FadeScale_fx; /*Q15*/ - Word16 prev_gain_pit_dec_fx; /*Q14*/ - Word16 prev_tilt_code_dec_fx; /*Q15*/ - - /*----------------------------------------------------------------------------------* - * channel-aware mode - *----------------------------------------------------------------------------------*/ - - Word16 tilt_code_dec_fx[NB_SUBFR16k]; - Word16 rf_frame_type; - Word16 use_partial_copy; - Word16 prev_use_partial_copy; - Word16 rf_flag; - Word16 rf_flag_last; - - Word16 rf_fec_offset; - Word16 next_coder_type; - Word16 prev_rf_frame_type; - Word16 rf_target_bits; - - Word16 rf_indx_nelp_fid; - Word16 rf_indx_nelp_iG1; - Word16 rf_indx_nelp_iG2[2]; - Word16 rf_indx_tbeGainFr; - - /*----------------------------------------------------------------------------------* - * HR SWB BWE parameters - *----------------------------------------------------------------------------------*/ - - Word16 bwe_highrate_seed_fx; - Word16 t_audio_prev_fx[2*END_FREQ_BWE_FULL_FB/50 - NUM_NONTRANS_START_FREQ_COEF]; - Word16 t_audio_prev_fx_exp[NUM_TIME_SWITCHING_BLOCKS]; - Word16 old_is_transient_hr_bwe_fx; - Word32 L_mem_EnergyLT_fx; - Word16 mem_EnergyLT_fx_exp; - - /*----------------------------------------------------------------------------------* - * HQ core parameters - *----------------------------------------------------------------------------------*/ - - Word16 synth_history_fx[Lprot48k + L_FRAME_MAX]; /* unified synthesis memory */ - Word16 *old_synthFB_fx; - Word16 old_out_fx[L_FRAME48k]; /* HQ core - previous synthesis for OLA */ - - Word16 old_out_LB_fx[L_FRAME32k]; /* HQ core - previous synthesis for OLA for Low Band */ - Word16 Q_old_wtda_LB; - Word16 Q_old_wtda; - Word16 Q_old_postdec; /*scaling of the output of core_switching_post_dec_fx() */ - Word16 Qprev_synth_buffer_fx; - Word32 oldIMDCTout_fx[L_FRAME8k/2]; - Word16 prev_oldauOut_fx[L_FRAME8k]; - Word16 old_auOut_2fr_fx[L_FRAME8k*2]; - Word16 old_out_pha_fx[2][N_LEAD_NB]; /* FEC for HQ Core, 0-phase matching old_out, 1-overlapping original old_out and phase matching old_out*/ - Word16 diff_energy_fx; - Word32 old_coeffs_fx[L_FRAME8k]; /* HQ core - old coefficients (for FEC) */ - Word16 stat_mode_out_fx; - Word16 stat_mode_old_fx; - Word16 phase_mat_flag_fx; - Word16 phase_mat_next_fx; - Word16 old_Min_ind_fx; - Word16 old_is_transient_fx[3]; /* HQ core - previous transient flag (for FEC) */ - Word16 old_bfi_cnt_fx; /* HQ core - # of bfi until previous frame(for FEC) */ - Word16 prev_old_bfi_fx; - Word32 ynrm_values_fx[MAX_SB_NB][MAX_PGF]; - Word32 r_p_values_fx[MAX_SB_NB][MAX_ROW]; - /*Word16 old_hqswb_clas;*/ /* only used in inactive code, where it might probably be replaced by old_hqswb_clas_fx */ - Word16 Norm_gain_fx[SFM_N_NB]; - Word16 HQ_FEC_seed_fx; - Word16 energy_MA_Curr_fx[2]; - Word16 last_core_fx; /*Q0*/ - Word16 prev_last_core_fx; - - Word16 last_hq_core_type_fx; /*Q0*/ - Word16 last_L_frame_ori_fx; - Word16 previoussynth_fx[L_FRAME48k]; - Word16 old_synth_sw_fx[NS2SA(48000,FRAME_SIZE_NS-ACELP_LOOK_NS-DELAY_BWE_TOTAL_NS)]; - Word16 delay_buf_out_fx[HQ_DELTA_MAX*HQ_DELAY_COMP]; /*Q0*/ - Word16 mem_norm_fx[SFM_N_ENV_STAB]; /* Q0 */ - Word16 mem_env_delta_fx; /* Q11 */ - Word16 no_att_hangover_fx; /* Q0 */ - Word32 energy_lt_fx; /* Q13 */ - Word16 hq_generic_seed_fx; - Word16 prev_noise_level_fx[2]; /* Q15 */ - Word16 prev_hqswb_clas_fx; - Word16 prev_R_fx; /* the table of bit allocation of last frame */ - Word32 prev_coeff_out_fx[L_HQ_WB_BWE]; /* Q12 */ /* the coefficients of last frame */ - Word16 prev_SWB_peak_pos_fx[SPT_SHORTEN_SBNUM]; - Word16 old_Aq_12_8_fx[M+1]; /* Q12 old Aq[] for core switching */ - Word16 old_Es_pred_fx; /* old Es_pred for core switching */ - - - Word16 HqVoicing_fx; - Word16 fer_samples_fx[L_FRAME48k]; - Word32 prev_normq_fx[SFM_N_WB]; /* Q14 */ /* previous norms */ - Word32 prev_env_fx[SFM_N_WB]; /* previous noise envelopes */ - - Word32 last_ni_gain_fx[BANDS_MAX]; - Word16 last_env_fx[BANDS_MAX]; - Word16 last_max_pos_pulse_fx; - - /* pre-echo reduction */ - Word16 memfilt_lb_fx; /* Q0 */ - Word32 mean_prev_hb_fx; /* Q0 */ - Word16 smoothmem_fx; /* Q15 */ - Word32 mean_prev_fx; /* Q0 */ - Word32 mean_prev_nc_fx; /* Q0 */ - Word16 wmold_hb_fx; /* Q15 */ - Word16 prevflag_fx; /* Q0 */ - Word16 pastpre_fx; /* Q0 */ - - Word16 prev_frm_hfe2_fx; - Word16 prev_stab_hfe2_fx; - Word16 prev_ni_ratio_fx; /* 15 */ - Word16 prev_En_sb_fx[NB_SWB_SUBBANDS]; /* QsEn(4) */ - - /* PVQ range coder state */ - UWord32 rc_low_fx; - UWord32 rc_range_fx; - UWord32 rc_help_fx; - Word16 rc_num_bits_fx; - Word16 rc_offset_fx; - Word16 rc_end_fx; - - Word16 prev_env_Q[SFM_N_WB]; - - /*----------------------------------------------------------------------------------* - * TBE parameters - *----------------------------------------------------------------------------------*/ - - /* states for the filters used in generating SHB excitation from WB excitation */ - Word16 state_lpc_syn_fx[LPC_SHB_ORDER]; - Word32 mem_csfilt_fx [2]; - - /* states for the filters used in generating SHB signal from SHB excitation*/ - Word16 state_syn_shbexc_fx[L_SHB_LAHEAD]; - Word16 syn_overlap_fx[L_SHB_LAHEAD]; /* overlap buffer used to Adjust SHB Frame Gain*/ - - /* previous frame parameters for frame error concealment */ - Word16 lsp_prevfrm_fx[ LPC_SHB_ORDER]; - Word32 GainFrame_prevfrm_fx; - Word16 GainAttn_fx; - - Word16 old_bwe_exc_fx[PIT16k_MAX * 2]; /*Q_exc*/ - Word16 bwe_seed_fx[2]; /*Q0*/ - Word32 bwe_non_lin_prev_scale_fx; - Word16 old_bwe_exc_extended_fx[NL_BUFF_OFFSET]; - Word16 last_voice_factor_fx; /* Q6*/ - - Word32 genSHBsynth_Hilbert_Mem_fx[HILBERT_MEM_SIZE]; - Word16 mem_genSHBexc_filt_down_shb_fx[2*ALLPASSSECTIONS_STEEP+1]; - Word16 mem_genSHBexc_filt_down_wb2_fx[2*ALLPASSSECTIONS_STEEP+1]; - Word16 mem_genSHBexc_filt_down_wb3_fx[2*ALLPASSSECTIONS_STEEP+1]; - Word16 genSHBsynth_state_lsyn_filt_shb_local_fx[ 2 * ALLPASSSECTIONS_STEEP ]; - Word16 state_lsyn_filt_shb_fx[ 2 * ALLPASSSECTIONS_STEEP ]; - Word16 state_lsyn_filt_dwn_shb_fx[ 2 * ALLPASSSECTIONS_STEEP ]; - Word16 state_32and48k_WB_upsample_fx[2 * ALLPASSSECTIONS_STEEP]; /* !!! this memory in FLP is called mem_resamp_HB */ - Word16 hb_prev_synth_buffer_fx[NS2SA(48000, DELAY_BWE_TOTAL_NS)]; - Word16 old_bwe_delay_fx; /*Q0*/ - - Word16 syn_dm_phase_fx; - Word32 fbbwe_hpf_mem_fx[4][4]; - Word16 fbbwe_hpf_mem_fx_Q[4]; - Word32 prev_wb_bwe_frame_pow_fx; - Word32 prev_swb_bwe_frame_pow_fx; - Word32 prev_ener_fx; - Word16 prev_ener_fx_Q; - Word16 prev_GainShape_fx; - Word16 fb_state_lpc_syn_fx[LPC_SHB_ORDER]; - Word16 prev_Q_bwe_exc_fb; - Word16 fb_tbe_demph_fx; - Word16 prev_fbbwe_ratio_fx; - - /* WB/SWB bandwidth switching */ - Word16 tilt_wb_fx; - Word16 tilt_swb_fx; - Word16 prev_ener_shb_fx; - Word32 enerLH_fx; - Word32 prev_enerLH_fx; - Word32 enerLL_fx; - Word32 prev_enerLL_fx; - - Word16 prev_fractive_fx; - Word16 prev_bws_cnt_fx; - Word16 bws_cnt_fx; - Word16 bws_cnt1_fx; - Word16 attenu_fx; - Word16 last_inner_frame_fx; /* (HQ_CORE) DCT length */ - Word16 last_bwidth_fx; - Word16 prev_weight1_fx; - Word16 t_audio_q_fx[L_FRAME]; - Word16 tbe_demph_fx; - Word16 tbe_premph_fx; - Word16 mem_stp_swb_fx[LPC_SHB_ORDER]; - Word16 *ptr_mem_stp_swb_fx; - Word16 gain_prec_swb_fx; - Word16 mem_zero_swb_fx[LPC_SHB_ORDER]; - - Word16 swb_lsp_prev_interp_fx[LPC_SHB_ORDER]; - Word32 prev1_shb_ener_sf_fx, prev2_shb_ener_sf_fx, prev3_shb_ener_sf_fx; - Word16 prev_res_shb_gshape_fx, prev_mixFactors_fx; - Word16 tilt_mem_fx; /* Formant factor adaptation tilt smoothing memory */ - Word16 prev_lsf_diff_fx[LPC_SHB_ORDER-2]; - Word16 prev_tilt_para_fx; - Word16 cur_sub_Aq_fx[M+1]; - - Word16 lsf_idx_fx[NUM_Q_LSF]; - Word16 m_idx_fx; - Word16 grid_idx_fx; - Word16 idxSubGains_fx; - Word16 idxFrameGain_fx; - Word16 idx_shb_fr_gain_fx; - Word16 idx_res_gs_fx[NB_SUBFR16k]; - Word16 idx_mixFac_fx; - - Word16 lsf_WB_fx; - Word16 gFrame_WB_fx; - - Word16 idxGain_fx; - - Word16 old_core_synth_fx[L_FRAME16k]; - Word16 old_tbe_synth_fx[L_SHB_TRANSITION_LENGTH]; - Word16 int_3_over_2_tbemem_dec_fx[INTERP_3_2_MEM_LEN]; - Word16 interpol_3_2_cng_dec_fx[INTERP_3_2_MEM_LEN]; - Word16 mem_resamp_HB_fx[INTERP_3_1_MEM_LEN]; - Word16 mem_resamp_HB_32k_fx[2*ALLPASSSECTIONS_STEEP+1]; - - /*----------------------------------------------------------------------------------* - * SWB BWE parameters - *----------------------------------------------------------------------------------*/ - Word16 old_wtda_wb_fx_exp; - Word16 L_old_wtda_swb_fx[L_FRAME48k]; - Word16 old_wtda_swb_fx_exp; - Word16 mem_imdct_exp_fx; - Word16 old_syn_12k8_16k_fx[NS2SA(16000, DELAY_FD_BWE_ENC_NS)]; /*Q_syn2-1*/ - - Word16 mem_deemph_old_syn_fx; - Word16 prev_mode_fx; - Word16 prev_SWB_fenv_fx[SWB_FENV]; - Word16 prev_Energy_fx; - Word32 prev_Energy_wb_fx; - Word16 prev_L_swb_norm_fx; - Word16 Seed_fx; - Word16 memExp1; - Word16 prev_frica_flag_fx; - Word16 mem_imdct_fx[L_FRAME48k]; - Word16 prev_td_energy_fx; - Word16 prev_weight_fx; - Word16 prev_coder_type_fx; - Word16 prev_flag_fx; - Word16 last_wb_bwe_ener_fx; - Word16 prev_frame_pow_exp; - Word16 prev_Qx; - Word16 prev_Q_bwe_exc; - Word16 prev_Q_synth; - Word16 prev_fb_ener_adjust_fx; - - /*----------------------------------------------------------------------------------* - * SWB DTX/CNG parameters - *----------------------------------------------------------------------------------*/ - - Word16 shb_cng_ener_fx; - Word16 wb_cng_ener_fx; - Word16 last_wb_cng_ener_fx; - Word16 last_shb_cng_ener_fx; - Word16 swb_cng_seed_fx; - Word16 lsp_shb_prev_prev_fx[LPC_SHB_ORDER]; - Word16 lsp_shb_prev_fx[LPC_SHB_ORDER]; - Word16 shb_dtx_count_fx; - Word16 last_vad_fx; - Word16 trans_cnt_fx; - Word16 burst_cnt_fx; - Word16 last_shb_ener_fx; - - /*----------------------------------------------------------------------------------* - * HQ FEC - *----------------------------------------------------------------------------------*/ - - Word16 *prev_good_synth_fx; - Word16 prev_sign_switch_fx[HQ_FEC_SIGN_SFM]; - Word16 prev_sign_switch_2_fx[HQ_FEC_SIGN_SFM]; - - /* HQ PHASE ECU internal state */ - Word16 time_offs_fx; - Word16 X_sav_fx[PH_ECU_SPEC_SIZE]; - Word16 Q_X_sav; - Word16 num_p_fx; - Word16 plocs_fx[MAX_PLOCS]; - Word32 plocsi_fx[MAX_PLOCS]; - Word16 env_stab_fx; - Word16 mem_norm_hqfec_fx[SFM_N_ENV_STAB]; - Word16 mem_env_delta_hqfec_fx; - Word16 env_stab_plc_fx; - Word16 env_stab_state_p_fx[NUM_ENV_STAB_PLC_STATES]; - Word16 envstabplc_hocnt_fx; - Word16 mag_chg_1st_fx[Lgw_max]; /* i/o: per band magnitude modifier for transients*/ - Word16 Xavg_fx[Lgw_max]; /* Frequency group average gain to fade to */ - Word16 beta_mute_fx; /* Factor for long-term mute */ - Word16 last_fec_fx; - Word16 ph_ecu_HqVoicing_fx; - Word16 oldHqVoicing_fx; - Word16 oldgapsynth_fx[L_FRAME48k]; - Word16 ph_ecu_active_fx; /* Set if Phase ECU was used in last bad frame */ - Word16 ni_seed_forfec; - Word16 ber_occured_in_pvq; /* flag for BER detection from PVQ routines */ - - /*----------------------------------------------------------------------------------* - * LD music post-filter - *----------------------------------------------------------------------------------*/ - Word16 LDm_mem_etot_fx; /* LD music post-filter - total energy memory */ - Word16 LDm_last_music_flag_fx; /* LD music post-filter - last music flag */ - Word16 LDm_nb_thr_1_fx; /* LD music post-filter - number of consecutives frames of level 1 */ - Word16 LDm_nb_thr_3_fx; - Word16 dct_post_old_exc_fx[DCT_L_POST-OFFSET2]; - Word16 LDm_thres_fx[4]; /* LD music post-filter - Classification threshold */ - Word16 LDm_lt_diff_etot_fx[MAX_LT]; /* LD music post-filter - long-term total energy variation */ - Word16 LDm_enh_lp_gbin_fx[VOIC_BINS_HR]; /* LD music post-filter - smoothed suppression gain, per bin FFT */ - Word32 LDm_enh_lf_EO_fx[VOIC_BINS_HR]; /* LD music post-filter - old per bin E for previous half frame */ - Word16 LDm_enh_min_ns_gain_fx; /* LD music post-filter - minimum suppression gain */ - Word32 LDm_bckr_noise_fx[MBANDS_GN_LD]; /* LD music post-filter - background noise estimation per critical band */ - Word16 filt_lfE_fx[DCT_L_POST]; - Word16 last_nonfull_music_fx; - Word16 Old_ener_Q; /* Old energy scaling factor */ - - /*----------------------------------------------------------------------------------* - * Fixed point only - *----------------------------------------------------------------------------------*/ - Word16 Q_exc; - Word16 prev_Q_exc; - Word16 Q_subfr[L_Q_MEM]; - - Word16 prev_Q_bwe_syn; - Word16 prev_Q_bwe_syn2; - - Word16 Q_syn2; - Word16 Q_syn; - Word16 prev_Q_syn; - Word16 prev_hb_synth_fx_exp; - - Word16 prev_synth_buffer_fx[NS2SA(48000,DELAY_BWE_TOTAL_NS - DELAY_CLDFB_NS)]; - Word16 prev_lpc_wb_fx[LPC_SHB_ORDER_WB]; - Word16 GainShape_Delay[NUM_SHB_SUBFR/2]; - Word16 vbr_hw_BWE_disable_dec_fx; - Word16 last_vbr_hw_BWE_disable_dec_fx; - - HANDLE_CLDFB_FILTER_BANK cldfbAna_fx; /* main analysis filter bank handle */ - HANDLE_CLDFB_FILTER_BANK cldfbBPF_fx; /* BPF analysis filter bank handle */ - HANDLE_CLDFB_FILTER_BANK cldfbSyn_fx; /* main synthesis filter bank handle */ - - Word16 last_active_bandsToZero_bwdec; - Word16 flag_NB_bwddec; - Word16 last_flag_filter_NB; - Word16 perc_bwddec; /*Q14*/ - Word16 active_frame_cnt_bwddec; - Word16 flag_buffer[20]; - Word16 total_frame_cnt_bwddec; - Word32 avg_nrg_LT; - /*Frequency-domain-based CNG*/ - HANDLE_FD_CNG_DEC hFdCngDec_fx; - - /*ACELP config*/ - Word16 force_lpd_reset; - ACELP_config acelp_cfg; /*configuration set for each frame*/ - - ACELP_config acelp_cfg_rf; /* configuration for RF frame */ - - /*TCX config*/ - TCX_config tcx_cfg; - Word16 L_frameTCX; - - /* evs decoder */ - Word16 m_decodeMode; - Word16 m_frame_type; /*ZERO_FRAME/SID_FRAME/ACTIVE_FRAME*/ - Word16 m_old_frame_type; /*ZERO_FRAME/SID_FRAME/ACTIVE_FRAME*/ - - - /*dec_prm.c*/ - Word16 bits_frame; /* bit per frame overall included */ - Word16 bits_frame_core; /* bit per frame for the core */ - Word8 narrowBand; - Word16 bits_common; /* read bits from header and LPC*/ - - Word8 last_is_cng; - - Word16 old_syn_Overl[L_FRAME32k/2]; - - Word16 syn_Overl_TDAC[L_FRAME32k/2]; - Word16 syn_Overl_TDACFB[L_FRAME_MAX/2]; - - Word16 syn_Overl[L_FRAME32k/2]; - Word16 syn_OverlFB[L_FRAME_MAX/2]; - Word16 old_synth[OLD_SYNTH_INTERNAL_DEC]; /* synthesis memory */ - Word16 old_synth_len; - Word16 old_synth_lenFB; - Word16 syn[M+1]; - - /* bass_pf.c */ - Word16 bpf_gain_param; /*int*/ /* bass post-filter gain factor parameter (0->noBpf)*/ - - Word16 L_frame_past; - Word16 L_frameTCX_past; - - Word16 lsfold_uw[M]; /* old lsf (unweighted) */ - Word16 lspold_uw[M]; /* old lsp (unweighted) */ - Word16 seed_tcx_plc; /* seed memory (for random function in TCX PLC) */ - Word16 past_gpit; /* past gain of pitch (for frame recovery) */ - Word32 past_gcode; /* past energy (!) of code (for frame recovery) */ /*15Q16*/ - Word16 lsf_cng[M]; /* xSF coefficients used for CNG generation (long term) */ - Word16 lspold_cng[M]; /* xSP coefficients used for CNG generation (long term) */ - Word8 plcBackgroundNoiseUpdated; /* flag: Is background noise estimate updated? */ - Word16 lsp_q_cng[M]; /* xSP coefficients used for CNG generation (short term interpolated) */ - Word16 old_lsp_q_cng[M]; /* xSP coefficients used for CNG generation (short term interpolated) */ - Word16 lsf_q_cng[M]; /* xSF coefficients used for CNG generation (short term interpolated) */ - Word16 old_lsf_q_cng[M]; /* xSF: old quantized lsfs for background noise */ - Word16 Aq_cng[(NB_SUBFR16k+1)*(M+1)]; /* LPC coefficients derived from CNG estimate */ - Word16 mem_syn_unv_back[M]; /* filter memory for unvoiced synth */ - Word16 last_gain_syn_deemph; /*Q15*/ - Word16 last_gain_syn_deemph_e; - Word16 last_concealed_gain_syn_deemph; /*Q15*/ - Word16 last_concealed_gain_syn_deemph_e; - - Word8 enableTcxLpc; /* global toggle for the TCX LPC quantizer */ - Word8 envWeighted; /* are is{p,f}_old[] weighted or not? */ - - /* variables for framing */ - Word16 nb_subfr; - - Word16 fscale; - Word16 fscale_old; - Word32 sr_core; /*Q0*/ - - Word16 pit_min; /*int*/ - Word16 pit_fr1; - Word16 pit_fr1b; - Word16 pit_fr2; - Word16 pit_max; /*int Q0*/ - Word16 pit_res_max; - Word16 pit_res_max_past; - - Word16 pit_max_TCX; /*int Q0*/ - Word16 pit_min_TCX; /*int*/ - - /*Preemphasis factor*/ - Word16 preemph_fac; /*0Q15*/ - Word16 gamma; - Word16 inv_gamma; - - /*for AMR-WB like 6.4 to 7 kHz upsampling and noise filling*/ - Word16 mem_Aq[(NB_SUBFR16k)*(M+1)]; /* Q12 */ - - /* Error concealment */ - Word16 last_core_bfi; - Word16 nbLostCmpt; /* compt for number of consecutive lost frame*/ - Word16 prev_nbLostCmpt; /* compt for number of consecutive lost frame at the previous frame*/ - Word16 mode_lvq; /* index for LSF mean vector */ - Word32 old_fpitch; /* last pitch of previous frame */ /*15Q16*/ - Word32 old_fpitchFB; /* PLC - last pitch of previous FB frame (depends on output sr) */ /*15Q16*/ - Word16 clas_dec; - Word16 mem_pitch_gain[2*NB_SUBFR16k+2]; /* Pitch gain memory Q14 */ - Word8 plc_use_future_lag; - Word16 prev_widow_left_rect; - Word32 Mode2_lp_gainc; /* 15Q16 low passed code gain used for concealment*/ - Word32 Mode2_lp_gainp; /* 15Q16 low passed pitch gain used for concealment*/ - Word16 conCngLevelBackgroundTrace; /* Q15 long term gain estimate for background level, used for PLC fade out */ - Word16 conCngLevelBackgroundTrace_e; - /* state variables for the minimum statistics used for PLC */ - Word16 conNoiseLevelMemory[PLC_MIN_STAT_BUFF_SIZE];/*Q15*/ - Word16 conNoiseLevelMemory_e[PLC_MIN_STAT_BUFF_SIZE]; - Word16 conNoiseLevelIndex; /*Q0*/ - Word16 conCurrLevelIndex; /*Q0*/ - Word16 conLastFrameLevel;/*Q15*/ - Word16 conLastFrameLevel_e; - - Word16 old_gaintcx_bfi, old_gaintcx_bfi_e; - Word16 cummulative_damping_tcx; - Word16 cummulative_damping; /*Q15*/ - Word16 cngTDLevel; - Word16 cngTDLevel_e; - - Word16 conceal_eof_gain; /*Q14*/ - Word16 damping; /* 1Q14 */ - Word16 gainHelper; /*can be >1*/ - Word16 gainHelper_e; - Word16 stepCompensate; - Word16 stepCompensate_e; - Word16 reset_mem_AR; - Word16 tcxConceal_recalc_exc; - - - Word16 classifier_Q_mem_syn; /*scalingfactor of mem_syn_clas_estim_fx in MODE2 */ - - Word16 rate_switching_init; - - /* LPC quantization */ - Word16 lpcQuantization; - Word16 numlpc; - - /* Bandwidth */ - Word16 TcxBandwidth; - - /* For NB and formant post-filter */ - PFSTAT pfstat; - Word16 psf_lp_noise_fx; - - /* For adaptive tilt_code */ - Word16 voice_fac; - - Word8 tcxonly; - - /*TCX resisual Q*/ - Word16 resQBits[NB_DIV]; /* number of bits read for the residual Quantization in TCX*/ - - Word16 last_ctx_hm_enabled; - - /* TCX-LTP */ - Word8 tcxltp; - Word16 tcxltp_gain; - Word16 tcxltp_pitch_int; - Word16 tcxltp_pitch_fr; - - Word16 tcxltp_mem_in[TCXLTP_MAX_DELAY]; - Word16 tcxltp_mem_out[L_FRAME48k]; - Word16 tcxltp_pitch_int_post_prev; - Word16 tcxltp_pitch_fr_post_prev; - Word16 tcxltp_gain_post_prev; - Word16 tcxltp_filt_idx_prev; - - struct tonalmdctconceal tonalMDCTconceal; - Word8 tonal_mdct_plc_active; - Word8 last_tns_active; - Word8 second_last_tns_active; - Word16 second_last_core; - Word32 tcxltp_second_last_pitch; - Word32 tcxltp_third_last_pitch; - Word16 tcxltp_last_gain_unmodified; - - Word16 FBTCXdelayBuf[111]; /* 2.3125ms at 48kHz -> 111 samples */ - - /* parameters for switching */ - Word16 mem_syn_r[L_SYN_MEM]; /*LPC synthesis memory needed for rate switching*/ - Word16 rate_switching_reset; - - Word32 lp_error_ener; - Word32 mem_error; - Word16 bpf_noise_buf[L_FRAME_16k]; - Word16 *p_bpf_noise_buf; - - Word8 enableGplc; - Word16 flagGuidedAcelp; /*int*/ - Word16 T0_4th;/*int*/ - Word16 guidedT0; /*int*/ - - Word16 enablePlcWaveadjust; - Word16 tonality_flag; - T_PLCInfo plcInfo; - - Word8 VAD; - Word8 flag_cna; - Word8 last_flag_cna; - - Word32 lp_noise; - - Word16 seed_acelp; - - Word16 core_ext_mode; /*GC,VC,UC,TC: core extended mode used for PLC or Acelp-external modules.*/ - - Word8 dec_glr; - Word16 dec_glr_idx; - - Word16 tcx_hm_LtpPitchLag; - Word16 tcx_lpc_shaped_ari; - - Word16 igf; - IGFDEC_INSTANCE hIGFDec; - - CLDFB_SCALE_FACTOR scaleFactor; - - Word16 tec_tfa; - Word16 tec_flag; - Word16 tfa_flag; - TEMPORAL_ENVELOPE_CODING_DECODER_FX tecDec_fx; - - Word16 con_tcx; - Word16 last_con_tcx; - Word16 old_ppp_mode_fx; - Word16 old_hb_synth_fx[L_FRAME48k]; - - Word16 prev_Q_exc_fr; - Word16 prev_Q_syn_fr; - - Word16 writeFECoffset; - - -} Decoder_State_fx; -#endif diff --git a/src/libs/libevs/lib_dec/stat_noise_uv_dec.cpp b/src/libs/libevs/lib_dec/stat_noise_uv_dec.cpp new file mode 100644 index 00000000..b2727493 --- /dev/null +++ b/src/libs/libevs/lib_dec/stat_noise_uv_dec.cpp @@ -0,0 +1,75 @@ +/*==================================================================================== + EVS Codec 3GPP TS26.443 Nov 13, 2018. Version 12.11.0 / 13.7.0 / 14.3.0 / 15.1.0 + ====================================================================================*/ + +#include "options.h" +#include "prot.h" + + +/*---------------------------------------------------------* + * stat_noise_uv_dec() + * + * Modifies excitation signal in UC mode when the noise is stationary + *---------------------------------------------------------*/ + +void stat_noise_uv_dec( + Decoder_State *st, /* i/o: decoder static memory */ + const short coder_type, /* i : coding type */ + float *lsp_new, /* i : end-frame LSP vector */ + float *lsp_mid, /* i : mid-frame LSP vector */ + float *Aq, /* o : A(z) quantized for the 4 subframes */ + float *exc2 /* i/o: excitation buffer */ +) +{ + short i; + float ftmp, noisiness = 0; + + /*-----------------------------------------------------------------* + * Decode the VAD flag + *-----------------------------------------------------------------*/ + + if( coder_type == UNVOICED || ( coder_type == INACTIVE && st->core_brate <= ACELP_9k60 ) ) + { + /* read the noisiness parameter */ + noisiness = (float)get_next_indice( st, 5 ); + } + + /*-----------------------------------------------------------------* + * Update long-term energies for FEC + * Update LSP vector for CNG + *-----------------------------------------------------------------*/ + + if( coder_type == INACTIVE ) + { + if( st->unv_cnt > 20 ) + { + ftmp = st->lp_gainc * st->lp_gainc; + st->lp_ener = 0.7f * st->lp_ener + 0.3f * ftmp; + for( i=0; ilspCNG[i] = (float)(0.9f * st->lspCNG[i] + 0.1f * lsp_new[i]); + } + } + else + { + st->unv_cnt++; + } + } + else + { + st->unv_cnt = 0; + } + + /*-----------------------------------------------------------------* + * Modify the excitation signal + *-----------------------------------------------------------------*/ + + if ( !st->Opt_AMR_WB ) + { + stat_noise_uv_mod( coder_type, noisiness, st->lsp_old, lsp_new, lsp_mid, Aq, exc2, 0, &st->ge_sm, + &st->uv_count, &st->act_count, st->lspold_s, &st->noimix_seed, &st->min_alpha, + &st->exc_pe, st->core_brate, st->bwidth ); + } + + return; +} diff --git a/src/libs/libevs/lib_dec/stat_noise_uv_dec_fx.cpp b/src/libs/libevs/lib_dec/stat_noise_uv_dec_fx.cpp deleted file mode 100755 index 234a9d1f..00000000 --- a/src/libs/libevs/lib_dec/stat_noise_uv_dec_fx.cpp +++ /dev/null @@ -1,84 +0,0 @@ -/*==================================================================================== - EVS Codec 3GPP TS26.442 Apr 03, 2018. Version 12.11.0 / 13.6.0 / 14.2.0 - ====================================================================================*/ - -#include "options.h" /* Compilation switches */ -#include "stl.h" -#include "prot_fx.h" /* Function prototypes */ - - -/*---------------------------------------------------------* - * stat_noise_uv_dec() - * - * Modifies excitation signal in UC mode when the noise is stationary - *---------------------------------------------------------*/ -void stat_noise_uv_dec_fx( - Decoder_State_fx *st_fx, /* i/o: Decoder static memory */ - const Word16 coder_type, /* i : coding type */ - Word16 *lsp_new, /* i : end-frame LSP vector */ - Word16 *lsp_mid, /* i : mid-frame LSP vector */ - Word16 *Aq, /* o : A(z) quantized for the 4 subframes */ - Word16 *exc2 /* i/o: excitation buffer */ -) -{ - Word16 noisiness = 0, i; - Word32 L_tmp; - - /*-----------------------------------------------------------------* - * Decode the VAD flag - *-----------------------------------------------------------------*/ - test(); - test(); - IF( sub(coder_type,UNVOICED ) == 0|| ( sub(coder_type,INACTIVE) == 0 && L_sub(st_fx->core_brate_fx,ACELP_9k60) <= 0 ) ) - { - /* read the noisiness parameter */ - noisiness = (Word16)get_next_indice_fx( st_fx, 5 ); - move16(); - } - - /*-----------------------------------------------------------------* - * Update long-term energies for FEC - * Update LSP vector for CNG - *-----------------------------------------------------------------*/ - IF (sub(coder_type,INACTIVE) == 00) - { - IF (sub(st_fx->unv_cnt_fx,20) > 0) - { - /*ftmp = st->lp_gainc * st->lp_gainc;*/ - L_tmp = L_mult0(st_fx->lp_gainc_fx, st_fx->lp_gainc_fx); /*Q3 * Q3 ->Q6*/ - /*st->lp_ener = 0.7f * st->lp_ener + 0.3f * ftmp;*/ - L_tmp = Mult_32_16(L_tmp, 9830); - st_fx->lp_ener_fx = L_add(Mult_32_16(st_fx->lp_ener_fx, 22938), L_tmp); - move16(); /*Q6 + Q6*/ - - FOR( i=0 ; ilspCNG[i] = (float)(0.9f * st->lspCNG[i] + 0.1f * lspnew[i]);*/ - L_tmp = L_mult(lsp_new[i], 3277); - st_fx->lspCNG_fx[i] = mac_r(L_tmp, st_fx->lspCNG_fx[i], 29491); - move16();/*Q15*/ - } - } - ELSE - { - st_fx->unv_cnt_fx = add(st_fx->unv_cnt_fx,1); - } - } - ELSE - { - st_fx->unv_cnt_fx = 0; - move16(); - } - - IF (!st_fx->Opt_AMR_WB_fx) - { - stat_noise_uv_mod_fx( coder_type, noisiness, st_fx->lsp_old_fx, lsp_new, lsp_mid, Aq - ,exc2, st_fx->Q_exc, 0, &st_fx->ge_sm_fx, &st_fx->uv_count_fx, &st_fx->act_count_fx, - st_fx->lspold_s_fx, &st_fx->noimix_seed_fx, &st_fx->min_alpha_fx, - &st_fx->exc_pe_fx, st_fx->core_brate_fx, st_fx->bwidth_fx, - &st_fx->Q_stat_noise, &st_fx->Q_stat_noise_ge ); - } - - - return ; -} diff --git a/src/libs/libevs/lib_dec/swb_bwe_dec.cpp b/src/libs/libevs/lib_dec/swb_bwe_dec.cpp new file mode 100644 index 00000000..6faeb2d1 --- /dev/null +++ b/src/libs/libevs/lib_dec/swb_bwe_dec.cpp @@ -0,0 +1,664 @@ +/*==================================================================================== + EVS Codec 3GPP TS26.443 Nov 13, 2018. Version 12.11.0 / 13.7.0 / 14.3.0 / 15.1.0 + ====================================================================================*/ + +#include +#include +#include "options.h" +#include "cnst.h" +#include "prot.h" +#include "rom_com.h" +#include "basop_util.h" +#include "basop_proto_func.h" + + +/*-------------------------------------------------------------------* + * para_pred_bws() + * + * predict SWB parameters for bandwidth switching + *-------------------------------------------------------------------*/ +static short para_pred_bws( + Decoder_State *st, /* i/o: decoder state structure */ + float *signal_wb, /* i : wideband frequency signal */ + float *SWB_fenv, /* o : frequency-domain BWE envelope */ + short coder_type /* i : coding type */ +) +{ + short i, j, k; + short mode; + float *input_hi; + float peak, mean[7], mag, min; + float avrg1, avrg2; + float att; + + mode = NORMAL; + + k = 0; + input_hi = &signal_wb[SHARP_WIDTH]; + for(i = 0; i < 7; i ++) + { + peak = 0.0f; + mean[i] = 0; + for(j = 0; j < SHARP_WIDTH; j ++) + { + mag = (float) fabs(*input_hi); + if (mag > peak) + { + peak = mag; + } + mean[i] += mag; + input_hi ++; + } + + if (peak*(SHARP_WIDTH+3.5f) > 4.5f*mean[i] && peak > 8.0f) + { + k += 1; + } + } + + avrg1 = 0.0f; + avrg2 = 0.0f; + for(i=1; i<4; i++) + { + avrg1 += mean[i]; + avrg2 += mean[i+3]; + } + avrg1 /= 3; + avrg2 /= 3; + + min = FLT_MAX; + peak = 0.0f; + for(i = 4; i < 7; i ++) + { + if(mean[i] > 2.0f*avrg2) + { + mean[i] *= 2*avrg2/mean[i]; + } + if(mean[i] < min) + { + min = mean[i]; + } + if(mean[i] > peak) + { + peak = mean[i]; + } + } + + if(st->tilt_wb > 8) + { + min = min(st->tilt_wb/15.0f, 1.0f)*peak; + } + + if( peak == 0 || min == 0 ) + { + set_f( SWB_fenv, 0, SWB_FENV ); + } + else + { + for(i = 0; i < SWB_FENV; i ++) + { + SWB_fenv[i] = min*mean[i/5+4]/(64*peak); + } + } + + for(j = 0, i = SWB_FENV/2; i < SWB_FENV; i ++) + { + SWB_fenv[i] *= (1.0f - (float)j++/SWB_FENV); + } + + if(avrg1 > 8.0f*avrg2) + { + for(i = 0; i < SWB_FENV; i ++) + { + SWB_fenv[i] *= 0.5f; + } + } + if( st->last_core != HQ_CORE && st->last_codec_mode == MODE1 && + (st->enerLH > 0.5f*st->prev_enerLH && st->enerLH < 2.0f*st->prev_enerLH) && + (st->enerLL > 0.5f*st->prev_enerLL && st->enerLL < 2.0f*st->prev_enerLL) ) + { + for(i=0; iprev_coder_type != coder_type && SWB_fenv[i] > 2.0f*st->prev_SWB_fenv[i] ) + { + SWB_fenv[i] = 0.1f * SWB_fenv[i] + 0.9f * st->prev_SWB_fenv[i]; + } + else + { + SWB_fenv[i] = st->attenu1 * SWB_fenv[i] + (1.0f - st->attenu1) * st->prev_SWB_fenv[i]; + } + } + + if( st->attenu1 < 0.9f ) + { + st->attenu1 += 0.05f; + } + } + else + { + if( st->core_brate != st->last_core_brate || (st->enerLH > 0.5f*st->prev_enerLH && st->enerLH < 2.0f*st->prev_enerLH) || + (st->enerLL > 0.5f*st->prev_enerLL && st->enerLL < 2.0f*st->prev_enerLL) ) + { + for(i=0; i 2.0f*st->prev_SWB_fenv[i]) + { + SWB_fenv[i] = st->prev_SWB_fenv[i]; + } + } + } + + for(i=0; iprev_SWB_fenv[i]; + } + + st->attenu1 = 0.1f; + } + + if( k > 3 ) + { + mode = HARMONIC; + } + + att = ((float)N_WS2N_FRAMES - (float)st->bws_cnt) / (float)N_WS2N_FRAMES; + if(st->L_frame == L_FRAME16k ) + { + for( i = 0; i < 4; i++ ) + { + SWB_fenv[i] *= att; + } + } + + for( i=4; iold_wtda_swb, ALDO_WINDOW,ALDO_WINDOW, output_frame ); + direct_transform( wtda_synth, ysynth, 0, output_frame ); + + if( !st->bfi ) + { + if( st->total_brate == ACELP_13k20 ) + { + /* de-quantization */ + mode = WB_BWE_gain_deq( st, WB_fenv ); + st->last_wb_bwe_ener = 0.5f*(WB_fenv[0] + WB_fenv[1]); + } + else + { + if( st->last_extl != WB_BWE ) + { + st->prev_SWB_fenv[0] = 0.0f; + } + + mode = WB_BWE_gain_pred( WB_fenv, ysynth, coder_type, st->prev_coder_type, st->prev_SWB_fenv[0], voice_factors, pitch_buf, + st->last_core_brate, st->last_wb_bwe_ener, st->last_extl + ,st->tilt_wb + ); + } + } + else + { + /* FEC */ + mode = NORMAL; + for( i=0; i<2; i++ ) + { + WB_fenv[i] = 0.75f*st->prev_SWB_fenv[i]; + } + } + + if( st->last_extl != WB_BWE || st->bfi ) + { + mvr2r( WB_fenv, st->prev_SWB_fenv, 2 ); + } + + /* reconstruction of MDCT spectrum of the error signal */ + WB_BWE_decoding( ysynth, WB_fenv, yerror, L_FRAME16k, mode, st->last_extl, + &st->prev_Energy_wb, st->prev_SWB_fenv, &st->prev_L_swb_norm, st->extl, + coder_type, st->total_brate, &st->Seed, &st->prev_flag, st->prev_coder_type ); + + if ( st->output_Fs == 32000) + { + set_f( &yerror[L_FRAME16k], 0, L_FRAME16k ); + } + else if ( st->output_Fs == 48000 ) + { + set_f( &yerror[L_FRAME16k], 0, L_FRAME32k ); + } + + inverse_transform( yerror, wtda_synth, 0, output_frame, -1 ); + + window_ola( wtda_synth, hb_synth, st->mem_imdct, output_frame,ALDO_WINDOW,ALDO_WINDOW, 0,0,0 ); + + st->prev_mode = mode; + + return; +} + +/*-------------------------------------------------------------------* + * swb_bwe_gain_deq() + * + * Decoding of SWB parameters + *-------------------------------------------------------------------*/ + +short swb_bwe_gain_deq( /* o : BWE class */ + Decoder_State *st, /* i/o: decoder state structure */ + const short core, /* i : core */ + float *SWB_tenv, /* o : time-domain BWE envelope */ + float *SWB_fenv, /* o : frequency-domain BWE envelope */ + const short hr_flag, /* i : high rate flag */ + const short hqswb_clas /* i : HQ BWE class */ +) +{ + short index, mode, n_band; + short indice[6]; + float quant_tmp[SWB_FENV/2], quant_tmp2[SWB_FENV/2]; + short nb_bits[6]; + short nenv; + + if ( hqswb_clas > 0) + { + mode = (short)get_next_indice( st, 1 ); + if (mode == 0) + { + mode = (short)get_next_indice( st, 1 ); + } + else + { + mode = HQ_GENERIC_SP_EXC; + } + } + else + { + mode = (short)get_next_indice( st, 2 ); + } + + if( mode == 1 && core == ACELP_CORE ) + { + for( n_band = 0; n_band < SWB_TENV; n_band++ ) + { + index = (short)get_next_indice( st, 4 ); + SWB_tenv[n_band] = (float)(1 << index); + } + + indice[0] = (short)get_next_indice( st, 7 ); + indice[1] = (short)get_next_indice( st, 6 ); + + for(n_band = 0; n_band < DIM_TR1; n_band++) + { + quant_tmp[2*n_band]= Env_TR_Cdbk1[indice[0]*DIM_TR1+n_band]; + } + + quant_tmp[1] = (quant_tmp[0]+quant_tmp[2])*0.5f+Env_TR_Cdbk2[indice[1]*DIM_TR2]; + quant_tmp[3] = quant_tmp[2]+Env_TR_Cdbk2[indice[1]*DIM_TR2+1]; + + for(n_band = 0; n_band < SWB_FENV_TRANS; n_band++) + { + SWB_fenv[n_band] = (float)pow(10, 0.025f*(quant_tmp[n_band]+Mean_env_tr[n_band])); + } + + /* in case of band-width switching, attenuate frame gain */ + if( st->bws_cnt1 > 0 ) + { + for(n_band = 0; n_band < SWB_TENV; n_band++) + { + SWB_tenv[n_band] *= (float)st->bws_cnt1 / (float)N_NS2W_FRAMES; + } + + for (n_band = 0; n_band < SWB_FENV_TRANS; n_band++) + { + SWB_fenv[n_band] *= (float)st->bws_cnt1 / (float)N_NS2W_FRAMES; + } + } + } + else + { + nb_bits[0] = 5; + nb_bits[1] = 7; + nb_bits[2] = 6; + nb_bits[3] = 5; + + if ( hr_flag == 1 ) + { + nb_bits[4] = 5; + nenv = SWB_FENV - 2; + } + else + { + nb_bits[4] = 6; + nenv = SWB_FENV; + } + + for (n_band = 0; n_band < 5; n_band++) + { + indice[n_band] = (short) get_next_indice( st, nb_bits[n_band] ); + } + + if ( hqswb_clas == HQ_GEN_FB ) + { + indice[n_band] = (short) get_next_indice( st, 5 ); + } + + mvr2r( &EnvCdbk11[indice[0] * DIM11], quant_tmp, DIM11 ); + mvr2r( &EnvCdbk1st[indice[1] * DIM1ST], quant_tmp2, DIM1ST ); + mvr2r( &EnvCdbk2nd[indice[2] * DIM2ND], quant_tmp2+DIM1ST, DIM2ND ); + + for( n_band = 0; n_band < DIM11-1; n_band++ ) + { + quant_tmp[n_band] += quant_tmp2[n_band]; + SWB_fenv[n_band*2] = quant_tmp[n_band]; + } + + if ( hr_flag == 1 ) + { + quant_tmp[6] += quant_tmp2[6]; + SWB_fenv[11] = quant_tmp[6]; + + + mvr2r( &EnvCdbk3rd[indice[3] * DIM3RD], quant_tmp2, DIM3RD ); + mvr2r( &EnvCdbk3rd[indice[4] * DIM3RD], quant_tmp2+DIM3RD, DIM3RD ); + + for(n_band = 0; n_band < 5; n_band++) + { + SWB_fenv[n_band*2+1] = ((quant_tmp[n_band]+quant_tmp[n_band+1])/2.f)+quant_tmp2[n_band+1]; + } + + SWB_fenv[0] += quant_tmp2[0]; + } + else + { + quant_tmp[DIM11-1]+=quant_tmp2[DIM11-1]; + SWB_fenv[(DIM11-1)*2] = quant_tmp[DIM11-1]; + + mvr2r( &EnvCdbk3rd[indice[3] * DIM3RD], quant_tmp2, DIM3RD ); + mvr2r( &EnvCdbk4th[indice[4] * DIM4TH], quant_tmp2+DIM3RD, DIM4TH ); + + for( n_band = 0; n_band < DIM12-1; n_band++ ) + { + SWB_fenv[n_band*2+1] = ((quant_tmp[n_band]+quant_tmp[n_band+1])/2.f)+quant_tmp2[n_band]; + } + + SWB_fenv[n_band*2+1] = quant_tmp[n_band]+quant_tmp2[n_band]; + } + + for( n_band = 0; n_band < nenv; n_band++ ) + { + Word16 tmp,frac,exp; + Word32 L_tmp; + tmp = add((short)(SWB_fenv[n_band]*256),(short)(Mean_env[n_band]*256)); /*Q8 */ + + L_tmp = L_mult(tmp, 21771); /* 0.166096 in Q17 -> Q26 */ + L_tmp = L_shr(L_tmp, 10); /* From Q26 to Q16 */ + frac = L_Extract_lc(L_tmp, &exp); /* Extract exponent of L_tmp */ + + tmp = extract_l(Pow2(13, frac));/* Put 13 as exponent so that */ + /* output of Pow2() will be: */ + /* 16384 < Pow2() <= 32767 */ + exp = sub(exp, 13); + tmp = shl(tmp, add(exp,1)); /*Q1 */ + SWB_fenv[n_band] = (float)tmp*0.5f;; /*Q1 */ + } + + if ( hqswb_clas == HQ_GEN_FB ) + { + mvr2r( &EnvCdbkFB[indice[5] * DIM_FB], &SWB_fenv[nenv], DIM_FB ); + for( n_band = 0; n_band < DIM_FB; n_band++ ) + { + Word16 tmp,frac,exp; + Word32 L_tmp; + + tmp = add((short)(SWB_fenv[n_band + nenv]*128),(short)(Mean_env_fb[n_band]*128)); /*Q7 */ + L_tmp = L_mult(tmp, 21771); /* 0.166096 in Q17 -> Q25 */ + L_tmp = L_shr(L_tmp, 9); /* From Q25 to Q16 */ + frac = L_Extract_lc(L_tmp, &exp); /* Extract exponent of L_tmp */ + + tmp = extract_l(Pow2(13, frac));/* Put 13 as exponent so that */ + /* output of Pow2() will be: */ + /* 16384 < Pow2() <= 32767 */ + exp = sub(exp, 13); + tmp = shl(tmp, add(exp,1)); + move16(); + SWB_fenv[add(n_band,nenv)] = (float)tmp*0.5f; + } + } + + } + + return mode; +} + +/*-------------------------------------------------------------------* + * swb_bwe_dec() + * + * SWB BWE decoder (only for 32kHz signals) + *-------------------------------------------------------------------*/ + +void swb_bwe_dec( + Decoder_State *st, /* i/o: decoder state structure */ + const float *synth, /* i : ACELP core synthesis/final synthesis */ + float *hb_synth, /* o : SHB synthesis/final synthesis */ + const short output_frame /* i : frame length */ + ,short coder_type /* i : coding type */ +) +{ + short i, l_subfr; + float ysynth[L_FRAME48k]; + float yerror[L_FRAME48k]; + float wtda_synth[2*L_FRAME48k]; + float SWB_tenv[SWB_TENV]; + float SWB_fenv[SWB_FENV]; + short L; + short mode; + short frica_flag = 0; + float fb_ener_adjust = 0.0f; + short j = 0; + float ener_adjust_quan; + short idxGain; + + /*---------------------------------------------------------------------* + * SWB BWE decoding + *---------------------------------------------------------------------*/ + + /* windowing of the ACELP core synthesis */ + wtda( synth, wtda_synth, st->old_wtda_swb, ALDO_WINDOW, ALDO_WINDOW, output_frame ); + + /* DCT of the ACELP core synthesis */ + direct_transform( wtda_synth, ysynth, 0, output_frame ); + + if( !st->bfi ) + { + if( st->bws_cnt > 0 ) + { + /* estimate parameters */ + mode = para_pred_bws( st, ysynth, SWB_fenv, coder_type ); + } + else + { + /* de-quantization */ + mode = swb_bwe_gain_deq( st, ACELP_CORE, SWB_tenv, SWB_fenv, 0, -1 ); + } + + L = mode == TRANSIENT ? SWB_FENV_TRANS : SWB_FENV; + st->prev_ener_shb = 0.0f; + for(i=0; iprev_ener_shb += SWB_fenv[i]; + } + st->prev_ener_shb /= L; + } + else + { + /* SHB FEC */ + if( st->prev_mode != TRANSIENT ) + { + mode = st->prev_mode; + } + else + { + mode = NORMAL; + } + + mvr2r( st->prev_SWB_fenv, SWB_fenv, SWB_FENV ); + } + + /* reconstruction of MDCT spectrum of the error signal */ + set_f( yerror, 0, output_frame ); + + if (st->L_frame == L_FRAME16k ) + { + SWB_BWE_decoding( ysynth, SWB_fenv, yerror, L_FRAME32k-80, mode, &frica_flag, &st->prev_Energy, st->prev_SWB_fenv, + &st->prev_L_swb_norm, st->tilt_wb, &st->Seed, 80, &st->prev_weight, st->extl + ,st->last_extl + ); + } + else + { + SWB_BWE_decoding( ysynth, SWB_fenv, yerror, L_FRAME32k-80, mode, &frica_flag, &st->prev_Energy, st->prev_SWB_fenv, + &st->prev_L_swb_norm, st->tilt_wb, &st->Seed, 6, &st->prev_weight, st->extl + ,st->last_extl + ); + } + + if ( st->prev_frica_flag == 1 && frica_flag == 0 ) + { + for( i = 0; i < L_SUBFR; i++ ) + { + st->mem_imdct[i] *= 1.0f - i*0.015625f; + } + + for( ; i < output_frame; i++ ) + { + st->mem_imdct[i] = 0.0f; + } + } + + /* decode information */ + if ( st->extl == FB_BWE ) + { + if( !st->bfi ) + { + idxGain = (short)get_next_indice( st,NUM_BITS_FB_FRAMEGAIN); + fb_ener_adjust = usdequant(idxGain, FB_GAIN_QLOW, FB_GAIN_QDELTA); + } + else if( st->bfi ) + { + fb_ener_adjust = st->prev_fb_ener_adjust; + } + + st->prev_fb_ener_adjust = fb_ener_adjust; + if(mode == TRANSIENT) + { + ener_adjust_quan = fb_ener_adjust; + } + else + { + if(SWB_fenv[7] < 0.01f) + { + ener_adjust_quan = 0.0f; + } + else + { + ener_adjust_quan = min(SWB_fenv[13]/SWB_fenv[7], 4.0f); + } + } + for( i = FB_BAND_BEGIN; i < FB_BAND_BEGIN+DE_OFFSET1; i++ ) + { + yerror[i] = yerror[i-FB_BAND_WIDTH] * ((1.0f-j*FB_GAIN_QDELTA)*ener_adjust_quan + j*FB_GAIN_QDELTA*fb_ener_adjust); + j++; + } + for(; i < FB_BAND_END; i++ ) + { + yerror[i] = yerror[i-FB_BAND_WIDTH] * fb_ener_adjust; + } + } + + /* iDCT of the error signal */ + inverse_transform( yerror, wtda_synth, 0, output_frame, -1 ); + + /* inverse windowing of the error signal */ + window_ola( wtda_synth, hb_synth, st->mem_imdct, output_frame,ALDO_WINDOW,ALDO_WINDOW, 0,0,0 ); + l_subfr = output_frame/4; + + if( mode == TRANSIENT ) + { + for(i = 0; i < SWB_TENV; i++) + { + SWB_tenv[i] *= 0.8f; + } + + /* time envelope shaping when the current frame is TRANSIENT frame */ + time_envelop_shaping( hb_synth, SWB_tenv, output_frame ); + + st->prev_td_energy = SWB_tenv[3]; + } + else if( frica_flag == 1 && st->prev_frica_flag == 0 ) + { + time_reduce_pre_echo( synth, hb_synth, st->prev_td_energy, l_subfr ); + } + else + { + st->prev_td_energy = 0.0f; + for( i=0; iprev_td_energy += hb_synth[3*l_subfr+i]*hb_synth[3*l_subfr+i]; + } + st->prev_td_energy = (float)sqrt(st->prev_td_energy/l_subfr); + } + + st->prev_frica_flag = frica_flag; + st->prev_mode = mode; + + return; +} diff --git a/src/libs/libevs/lib_dec/swb_bwe_dec_fx.cpp b/src/libs/libevs/lib_dec/swb_bwe_dec_fx.cpp deleted file mode 100755 index ff05e916..00000000 --- a/src/libs/libevs/lib_dec/swb_bwe_dec_fx.cpp +++ /dev/null @@ -1,968 +0,0 @@ -/*==================================================================================== - EVS Codec 3GPP TS26.442 Apr 03, 2018. Version 12.11.0 / 13.6.0 / 14.2.0 - ====================================================================================*/ - -#include -#include "options.h" -#include "cnst_fx.h" -#include "prot_fx.h" -#include "rom_com_fx.h" -#include "rom_enc_fx.h" - - -#include "stl.h" -#define MAX_Q_NEW_INPUT 8 -#define Q_WTDA_FX 13 -#define Q_32_BITS 15 - -/*-------------------------------------------------------------------* - * para_pred_bws() - * - * predict SWB parameters for bandwidth switching - *-------------------------------------------------------------------*/ -static -Word16 para_pred_bws_fx( - Decoder_State_fx *st_fx, /* i/o: decoder state structure */ - Word16 *signal_wb_fx, /* i : wideband frequency signal */ - Word16 *SWB_fenv_fx, /* o : frequency-domain BWE envelope */ - Word16 Q_syn - ,Word16 coder_type /* i : coding type */ -) -{ - Word16 i, j, k; - Word16 mode; - Word16 tmp, tmp_den, tmp_num; - Word32 L_tmp, L_tmp_max; - Word16 exp; - Word16 *input_hi_fx; - Word32 *mea; - Word16 peak_fx, mag_fx; - Word32 mean_fx[7], peak_32_fx; - Word32 avrg1_fx, avrg2_fx, min_fx; - Word16 att_fx; - - mode = NORMAL; - move16(); - - k = 0; - move16(); - input_hi_fx = &signal_wb_fx[SHARP_WIDTH]; - move16(); - FOR(i = 0; i < 7; i ++) - { - peak_fx = 0; - move16(); - mean_fx[i] = 0; - move16(); - FOR(j = 0; j < SHARP_WIDTH; j ++) - { - mag_fx = abs_s(*input_hi_fx); - peak_fx = s_max(peak_fx ,mag_fx); - /*IF (sub(mag_fx, peak_fx) > 0) */ - /*{ */ - /* peak_fx = mag_fx; */ - /*} */ - mean_fx[i] = L_add(mean_fx[i], L_deposit_l(mag_fx)); - move32(); - input_hi_fx ++; - } - - IF(Q_syn < 11) - { - tmp = 1; - move16(); - } - ELSE - { - tmp = 0; - move16(); - if(sub(shr(peak_fx, 3), shl(1, Q_syn)) > 0) - { - tmp = 1; - move16(); - } - } - IF( tmp > 0) - { - L_tmp = L_msu0(Mult_32_16(L_shl(mean_fx[i], 10), 18432), peak_fx, 4544); - if (L_tmp < 0) - { - k = add(k, 1); - } - } - } - - avrg1_fx = L_deposit_l(0); - avrg2_fx = L_deposit_l(0); - FOR(i=1; i<4; i++) - { - avrg1_fx = L_add(avrg1_fx, mean_fx[i]); - avrg2_fx = L_add(avrg2_fx, mean_fx[i+3]); - } - avrg1_fx = Mult_32_16(avrg1_fx, 10923); - avrg2_fx = Mult_32_16(avrg2_fx, 10923); /* 1/3 -> Q15 -> 10923 */ - - min_fx = L_add(2147483647, 0); /*2^31 */ - peak_32_fx = L_deposit_l(0); - FOR(i = 4; i < 7; i ++) - { - IF(L_sub(mean_fx[i], L_shl(avrg2_fx, 1)) > 0) - { - exp = norm_l(mean_fx[i]); - IF(sub(exp, 16) < 0) - { - tmp_den = extract_l(L_shr(mean_fx[i], sub(16, exp))); /*Qsyn - 16 + exp */ - tmp_num = extract_l(L_shr(avrg2_fx, sub(15, exp))); /*//Qsyn - 16 + exp */ - } - ELSE - { - tmp_den = extract_l(mean_fx[i]); - tmp_num = extract_l(L_shl(avrg2_fx, 1)); - } - - tmp_den = div_s(1, tmp_den); - - tmp = i_mult(tmp_num, tmp_den); /*Q15 */ - - mean_fx[i] = Mult_32_16(mean_fx[i], tmp); - move32(); - } - min_fx = L_min(min_fx, mean_fx[i]); - peak_32_fx = L_max(peak_32_fx, mean_fx[i]); - /*IF(L_sub(mean_fx[i], min_fx) < 0) */ - /*{ */ - /* min_fx = mean_fx[i]; */ - /*} */ - /*IF(L_sub(mean_fx[i], peak_32_fx) > 0) */ - /*{ */ - /* peak_32_fx = mean_fx[i]; */ - /*} */ - } - - IF(sub(st_fx->tilt_wb_fx, 16384) > 0) - { - IF(sub(st_fx->tilt_wb_fx, 30720) > 0) - { - min_fx = peak_32_fx; - } - ELSE - { - tmp = extract_l(L_shr(L_mult0(st_fx->tilt_wb_fx, 17476), 14)); /*Q15 */ - min_fx = Mult_32_16(peak_32_fx, tmp); - } - } - - test(); - IF(peak_32_fx == 0 || min_fx == 0) - { - set16_fx(SWB_fenv_fx, 0, SWB_FENV); - } - ELSE - { - exp = norm_l(peak_32_fx); - IF(sub(exp, 16) < 0) - { - tmp_den = extract_l(L_shr(peak_32_fx, sub(16, exp))); /*Qsyn - 16 + exp */ - tmp = div_s(16384, tmp_den); /*Q15+14 - (Qsyn - 16 + exp) */ - tmp_num = extract_l(L_shr(min_fx, sub(16, exp))); /*Qsyn - 16 + exp */ - - tmp = extract_l(L_shr(L_mult0(tmp_num, tmp), 14)); /*Q15 */ - } - ELSE - { - tmp_den = extract_l(peak_32_fx); /*Qsyn */ - exp = norm_s(tmp_den); - tmp = div_s(shl(1, sub(14,exp)), tmp_den); /*Q 29-exp - Qsyn */ - tmp_num = extract_l(min_fx); /*Qsyn */ - - tmp = extract_l(L_shr(L_mult0(tmp_num, tmp), sub(14, exp))); /*Q15 */ - } - - j = 0; - move16(); - mea = &mean_fx[4]; - move16(); - L_tmp_max = L_shl(32767, add(Q_syn, 5)); - FOR(i = 0; i < SWB_FENV; i++) - { - IF(j == 5) - { - mea++; - move16(); - j = 0; - move16(); - } - j++; - move16(); - L_tmp = L_min(Mult_32_16(*mea, tmp), L_tmp_max); - SWB_fenv_fx[i] = extract_l(L_shr(L_tmp, add(Q_syn, 5))); - } - } - - j = 0; - move16(); - FOR(i = shr(SWB_FENV, 1); i < SWB_FENV; i++) - { - tmp = sub(32767, i_mult(j, 2341)); - move16(); - SWB_fenv_fx[i] = mult_r(SWB_fenv_fx[i], tmp); - move16(); - j++; - move16(); - } - - IF(L_sub(avrg1_fx, L_shl(avrg2_fx, 3)) > 0) - { - FOR(i = 0; i < SWB_FENV; i ++) - { - SWB_fenv_fx[i] = shr(SWB_fenv_fx[i], 1); - move16(); - } - } - - test(); - test(); - test(); - test(); - test(); - IF( sub(st_fx->last_core_fx, HQ_CORE) != 0 && sub(st_fx->last_codec_mode, MODE1) == 0 && - (L_sub(st_fx->enerLH_fx, L_shr(st_fx->prev_enerLH_fx, 1)) > 0 && L_sub(L_shr(st_fx->enerLH_fx, 1), st_fx->prev_enerLH_fx) < 0) && - (L_sub(st_fx->enerLL_fx, L_shr(st_fx->prev_enerLL_fx, 1)) > 0 && L_sub(L_shr(st_fx->enerLL_fx, 1), st_fx->prev_enerLL_fx) < 0) ) - { - FOR(i=0; iprev_coder_type_fx, coder_type) != 0 && sub(mult_r(SWB_fenv_fx[i], 16384), st_fx->prev_SWB_fenv_fx[i]) > 0) - { - /*SWB_fenv_fx[i] = add(mult_r(SWB_fenv_fx[i], 3277), mult_r(st_fx->prev_SWB_fenv_fx[i], 29491)); */ - SWB_fenv_fx[i] = round_fx(L_mac(L_mult(SWB_fenv_fx[i], 3277), st_fx->prev_SWB_fenv_fx[i], 29491)); - } - ELSE - { - /*SWB_fenv_fx[i] = add(mult_r(SWB_fenv_fx[i], st_fx->attenu_fx), mult_r(st_fx->prev_SWB_fenv_fx[i], sub(32767, st_fx->attenu_fx))); */ - SWB_fenv_fx[i] = round_fx(L_mac(L_mult(SWB_fenv_fx[i], st_fx->attenu_fx), st_fx->prev_SWB_fenv_fx[i], sub(32767, st_fx->attenu_fx))); - } - } - - IF(sub(st_fx->attenu_fx, 29491) < 0) - { - st_fx->attenu_fx = add(st_fx->attenu_fx, 1638); - move16(); - } - } - ELSE - { - test(); - test(); - test(); - test(); - IF( L_sub(st_fx->core_brate_fx, st_fx->last_core_brate_fx) != 0 || (L_sub(st_fx->enerLH_fx, L_shr(st_fx->prev_enerLH_fx, 1)) > 0 && L_sub(L_shr(st_fx->enerLH_fx, 1), st_fx->prev_enerLH_fx) < 0) || - (L_sub(st_fx->enerLL_fx, L_shr(st_fx->prev_enerLL_fx, 1)) > 0 && L_sub(L_shr(st_fx->enerLL_fx, 1), st_fx->prev_enerLL_fx) < 0) ) - { - FOR(i=0; iprev_SWB_fenv_fx[i]) > 0) - { - SWB_fenv_fx[i] = st_fx->prev_SWB_fenv_fx[i]; - move16(); - } - } - } - - FOR(i=0; iprev_SWB_fenv_fx[i], 3277)); */ - SWB_fenv_fx[i] = round_fx(L_mac(L_mult(SWB_fenv_fx[i], 29491), st_fx->prev_SWB_fenv_fx[i], 3277)); - } - st_fx->attenu_fx = 3277; - move16(); - } - - if(sub(k, 3) > 0) - { - mode = HARMONIC; - move16(); - } - - - att_fx = i_mult(sub(N_WS2N_FRAMES, st_fx->bws_cnt_fx), 819); - move16();/*15 */ - IF( sub(st_fx->L_frame_fx, L_FRAME16k) == 0 ) - { - FOR( i = 0; i < 4; i++ ) - { - SWB_fenv_fx[i] = mult_r(SWB_fenv_fx[i], att_fx); - move16(); /*Q1 */ - } - } - - FOR( i=4; iL_old_wtda_swb_fx, - &st_fx->old_wtda_swb_fx_exp, ALDO_WINDOW, ALDO_WINDOW, /* window overlap of current frame (0: full, 2: none, or 3: half) */ - output_frame ); - *Qpost = sub(new_input_fx_exp,15); - /* DCT of the ACELP core synthesis */ - direct_transform_fx(L_wtda_synth_fx, ysynth_32, 0, output_frame, &new_input_fx_exp); - - /* Convert to 16 Bits (Calc Shift Required to Stay within MAX_Q_NEW_INPUT) */ - scl = sub(16+MAX_Q_NEW_INPUT, new_input_fx_exp); - /* Possible to Upscale? */ - IF (scl > 0) - { - /* Yes */ - /* Calc Room to Upscale */ - Q_syn = Find_Max_Norm32(ysynth_32, output_frame); - /* Stay within MAX_Q_NEW_INPUT */ - scl = s_min(Q_syn, scl); - } - Copy_Scale_sig32_16(ysynth_32, ysynth_fx, output_frame, scl); - Q_syn = add(sub(new_input_fx_exp, 16), scl); - IF( !st_fx->bfi_fx ) - { - IF( L_sub(st_fx->total_brate_fx, ACELP_13k20) == 0 ) - { - /* de-quantization */ - mode = WB_BWE_gain_deq_fx(st_fx, WB_fenv_fx ); - st_fx->last_wb_bwe_ener_fx = mult_r(add(WB_fenv_fx[0], WB_fenv_fx[1]), 16384); - } - ELSE - { - if( sub(st_fx->last_extl_fx, WB_BWE) != 0 ) - { - st_fx->prev_SWB_fenv_fx[0] = 0; - move16(); - } - - mode = WB_BWE_gain_pred_fx( WB_fenv_fx, ysynth_fx, coder_type, st_fx->prev_coder_type_fx, st_fx->prev_SWB_fenv_fx[0], - voice_factors_fx, pitch_buf_fx, st_fx->last_core_brate_fx, st_fx->last_wb_bwe_ener_fx, Q_syn - ,st_fx->last_extl_fx, st_fx->tilt_wb_fx - ); - move16(); - } - } - ELSE - { - /* FEC */ - mode = NORMAL; - move16(); - FOR(i=0; i<2; i++) - { - WB_fenv_fx[i] = mult_r(st_fx->prev_SWB_fenv_fx[i], 24576); - } - } - test(); - IF( sub(st_fx->last_extl_fx, WB_BWE) != 0 || st_fx->bfi_fx ) - { - Copy( WB_fenv_fx, st_fx->prev_SWB_fenv_fx, 2 ); - } - - exp = norm_l(st_fx->prev_Energy_wb_fx); - IF(sub(add(st_fx->prev_Q_synth, exp),Q_syn) > 0) - { - st_fx->prev_Energy_wb_fx = L_shr(st_fx->prev_Energy_wb_fx, sub(st_fx->prev_Q_synth, Q_syn)); - } - ELSE - { - Q_syn = add(st_fx->prev_Q_synth, exp); - st_fx->prev_Energy_wb_fx = L_shl(st_fx->prev_Energy_wb_fx, exp); - } - WB_BWE_decoding_fx( ysynth_fx, WB_fenv_fx, ysynth_32, L_FRAME16k, mode, - st_fx->last_extl_fx, &st_fx->prev_Energy_wb_fx, st_fx->prev_SWB_fenv_fx, &st_fx->prev_L_swb_norm_fx, - st_fx->extl_fx, coder_type, st_fx->total_brate_fx, &st_fx->Seed_fx, &st_fx->prev_flag_fx, - st_fx->prev_coder_type_fx, Q_syn, &Q_syn_hb ); - IF ( L_sub(st_fx->output_Fs_fx, 32000) == 0) - { - set32_fx( &ysynth_32[L_FRAME16k], 0, L_FRAME16k ); - } - ELSE IF ( L_sub(st_fx->output_Fs_fx, 48000) == 0 ) - { - set32_fx( &ysynth_32[L_FRAME16k], 0, L_FRAME32k ); - } - Inverse_Transform( ysynth_32, &Q_syn_hb, t_audio32_tmp, 0, output_frame, output_frame ); - window_ola_fx( t_audio32_tmp, hb_synth_fx, &Q_syn_hb, st_fx->mem_imdct_fx, &st_fx->mem_imdct_exp_fx, output_frame, - ALDO_WINDOW,ALDO_WINDOW, 0,0,0); - st_fx->prev_mode_fx = mode; - st_fx->prev_Q_synth = Q_syn; - return Q_syn_hb; -} -/*-------------------------------------------------------------------* - * swb_bwe_gain_deq() - * - * Decoding of SWB parameters - *-------------------------------------------------------------------*/ -Word16 swb_bwe_gain_deq_fx( /* o : BWE class */ - Decoder_State_fx *st_fx, /* i/o: decoder state structure */ - const Word16 core, /* i : core */ - Word16 *SWB_tenv, /* o : Q0, time-domain BWE envelope */ - Word16 *SWB_fenv, /* o : Q1, frequency-domain BWE envelope */ - const Word16 hr_flag, /* i : high rate flag */ - const Word16 hqswb_clas /* i : HQ BWE class */ -) -{ - Word16 index, mode, n_band; - Word16 indice[6]; - Word16 quant_tmp[SWB_FENV/2], quant_tmp2[SWB_FENV/2]; - Word16 nb_bits[6]; - Word16 nenv; - Word16 tmp,exp,frac; - Word32 L_tmp; - - IF ( hqswb_clas > 0) - { - mode = (Word16)get_next_indice_fx( st_fx, 1 ); - IF (mode == 0) - { - mode = (Word16)get_next_indice_fx( st_fx, 1 ); - } - ELSE - { - mode = HQ_GENERIC_SP_EXC; - move16(); - } - } - ELSE - { - mode = (Word16)get_next_indice_fx( st_fx, 2 ); - } - - test(); - IF( sub(mode,1) == 0 && sub(core,ACELP_CORE) == 0 ) - { - FOR( n_band = 0; n_band < SWB_TENV; n_band++ ) - { - index = (Word16)get_next_indice_fx(st_fx, 4 ); - SWB_tenv[n_band] = shl(1, index); - move16(); - } - - indice[0] = (Word16)get_next_indice_fx(st_fx, 7 ); - move16(); - indice[1] = (Word16)get_next_indice_fx(st_fx, 6 ); - move16(); - - tmp = shl(indice[0],1); - FOR(n_band = 0; n_band < DIM_TR1; n_band++) - { - /*Env_TR_Cdbk1_fx[ indice[0]*DIM_TR1+n_band]*/ - quant_tmp[2*n_band] = Env_TR_Cdbk1_fx[add(tmp,n_band)];/*Q8 */ move16(); - } - - /*tmp = indice[1]*DIM_TR2*/ - tmp = shl(indice[1],1); - quant_tmp[1] = add(shr(add(quant_tmp[0], quant_tmp[2]),1), Env_TR_Cdbk2_fx[tmp]); - move16();/*Q8 */ - quant_tmp[3] = add(quant_tmp[2],Env_TR_Cdbk2_fx[add(tmp,1)]); - move16();/*Q8 */ - - FOR(n_band = 0; n_band < SWB_FENV_TRANS; n_band++) - { - tmp = add(quant_tmp[n_band], Mean_env_tr_fx[n_band]); /*Q8 */ - - /*-----------------------------------------------------------------* - * SWB_fenv[n_band] = pow(10.0, tmp/40) - * = pow(2, 3.321928*tmp/40) - * = pow(2, 0.0830482*tmp) - *-----------------------------------------------------------------*/ - L_tmp = L_mult(tmp, 21771); /* 0.0830482 in Q18 -> Q27 */ - L_tmp = L_shr(L_tmp, 11); /* From Q27 to Q16 */ - frac = L_Extract_lc(L_tmp, &exp); /* Extract exponent of L_tmp */ - tmp = extract_l(Pow2(13, frac)); - exp = sub(exp, 13); - SWB_fenv[n_band] = shl(tmp, add(exp, 1)); - move16();/*Q1 */ - } - /* in case of band-width switching, attenuate frame gain */ - IF( st_fx->bws_cnt1_fx > 0 ) - { - tmp = i_mult(st_fx->bws_cnt1_fx, 1638); - FOR(n_band = 0; n_band < SWB_TENV; n_band++) - { - SWB_tenv[n_band] = mult_r(SWB_tenv[n_band], tmp); - move16(); - } - - FOR (n_band = 0; n_band < SWB_FENV_TRANS; n_band++) - { - SWB_fenv[n_band] = mult_r(SWB_fenv[n_band], tmp); - move16(); - } - } - } - ELSE - { - nb_bits[0] = 5; - move16(); - nb_bits[1] = 7; - move16(); - nb_bits[2] = 6; - move16(); - nb_bits[3] = 5; - move16(); - - IF ( sub(hr_flag,1) == 0 ) - { - nb_bits[4] = 5; - move16(); - nenv = SWB_FENV - 2; - move16(); - } - ELSE - { - nb_bits[4] = 6; - move16(); - nenv = SWB_FENV; - move16(); - } - - FOR (n_band = 0; n_band < 5; n_band++) - { - indice[n_band] = (Word16) get_next_indice_fx(st_fx, nb_bits[n_band] ); - move16(); - } - - IF ( sub(hqswb_clas,HQ_GEN_FB) == 0 ) - { - indice[n_band] = (Word16) get_next_indice_fx(st_fx, 5 ); - move16(); - } - - Copy( &EnvCdbk11_fx[i_mult2(indice[0], DIM11)], quant_tmp, DIM11 ); - Copy( &EnvCdbk1st_fx[i_mult2(indice[1], DIM1ST)], quant_tmp2, DIM1ST ); - Copy( &EnvCdbk2nd_fx[i_mult2(indice[2], DIM2ND)], quant_tmp2+DIM1ST, DIM2ND ); - - FOR( n_band = 0; n_band < DIM11-1; n_band++ ) - { - quant_tmp[n_band] = add(quant_tmp[n_band], quant_tmp2[n_band]); - move16();/*Q8 */ - SWB_fenv[n_band*2] = quant_tmp[n_band]; - move16(); /*Q8 */ - } - - IF ( sub(hr_flag,1) == 0 ) - { - quant_tmp[6] = add(quant_tmp[6],quant_tmp2[6]); - move16();/*Q8 */ - SWB_fenv[11] = quant_tmp[6]; - move16(); - - Copy( &EnvCdbk3rd_fx[indice[3] * DIM3RD], quant_tmp2, DIM3RD ); - Copy( &EnvCdbk3rd_fx[indice[4] * DIM3RD], quant_tmp2+DIM3RD, DIM3RD ); - - FOR(n_band = 0; n_band < 5; n_band++) - { - SWB_fenv[add(shl(n_band,1),1)] = add(shr(add(quant_tmp[n_band], quant_tmp[n_band+1]),1), quant_tmp2[n_band+1]); - move16();/*Q8 */ - } - - SWB_fenv[0] = add(SWB_fenv[0], quant_tmp2[0]); - move16();/*Q8 */ - } - ELSE - { - quant_tmp[DIM11-1]=add(quant_tmp[DIM11-1],quant_tmp2[DIM11-1]); - move16();/*Q8 */ - SWB_fenv[(DIM11-1)*2] = quant_tmp[DIM11-1]; - move16(); - - Copy( &EnvCdbk3rd_fx[i_mult2(indice[3], DIM3RD)], quant_tmp2, DIM3RD ); - Copy( &EnvCdbk4th_fx[i_mult2(indice[4], DIM4TH)], quant_tmp2+DIM3RD, DIM4TH ); - - FOR( n_band = 0; n_band < DIM12-1; n_band++ ) - { - SWB_fenv[add(shl(n_band,1),1)] = add(shr(add(quant_tmp[n_band],quant_tmp[n_band+1]),1),quant_tmp2[n_band]); - move16();/*Q8 */ - } - - SWB_fenv[n_band*2+1] = add(quant_tmp[n_band],quant_tmp2[n_band]); - move16();/*Q8 */ - } - - FOR( n_band = 0; n_band < nenv; n_band++ ) - { - tmp = add(SWB_fenv[n_band],Mean_env_fx[n_band]); /*Q8 */ - - L_tmp = L_mult(tmp, 21771); /* 0.166096 in Q17 -> Q26 */ - L_tmp = L_shr(L_tmp, 10); /* From Q26 to Q16 */ - frac = L_Extract_lc(L_tmp, &exp); /* Extract exponent of L_tmp */ - - tmp = extract_l(Pow2(13, frac));/* Put 13 as exponent so that */ - /* output of Pow2() will be: */ - /* 16384 < Pow2() <= 32767 */ - exp = sub(exp, 13); - SWB_fenv[n_band] = shl(tmp, add(exp,1)); - move16();/*Q1 */ - } - - IF ( sub(hqswb_clas,HQ_GEN_FB) == 0 ) - { - Copy( &EnvCdbkFB_fx[i_mult2(indice[5], DIM_FB)], &SWB_fenv[nenv], DIM_FB ); /*Q7 */ - - FOR( n_band = 0; n_band < DIM_FB; n_band++ ) - { - tmp = add(SWB_fenv[add(n_band,nenv)], Mean_env_fb_fx[n_band]); - L_tmp = L_mult(tmp, 21771); /* 0.166096 in Q17 -> Q25 */ - L_tmp = L_shr(L_tmp, 9); /* From Q25 to Q16 */ - frac = L_Extract_lc(L_tmp, &exp); /* Extract exponent of L_tmp */ - - tmp = extract_l(Pow2(13, frac));/* Put 13 as exponent so that */ - /* output of Pow2() will be: */ - /* 16384 < Pow2() <= 32767 */ - exp = sub(exp, 13); - SWB_fenv[add(n_band,nenv)] = shl(tmp, add(exp,1)); - move16(); - } - } - - /* in case of band-width switching, attenuate frame gain */ - } - - return mode; -} - -/*-------------------------------------------------------------------* - * swb_bwe_dec() - * - * SWB BWE decoder (only for 32kHz signals) - *-------------------------------------------------------------------*/ -Word16 swb_bwe_dec_fx( - Decoder_State_fx *st_fx, /* i/o: decoder state structure */ - Word16 *synth_fx, /* i/o: ACELP core synthesis/final synthesis (might be rescaled inside wtda() ) */ - Word16 *hb_synth_fx, /* o : SHB synthesis/final synthesis */ - const Word16 output_frame /* i : frame length */ - ,Word16 * Qpost - ,Word16 coder_type /* i : coding type */ -) -{ - Word16 i, l_subfr; - Word16 mode; - Word16 frica_flag = 0; - Word16 idxGain; - Word16 Q_syn, Q_syn_hb; - Word16 ysynth_fx[L_FRAME48k]; - Word16 tmp; - Word16 SWB_tenv_fx[SWB_TENV]; - Word32 L_wtda_synth_fx[2*L_FRAME48k], ysynth_32[L_FRAME48k]; - Word16 scl, new_input_fx_exp; - Word32 t_audio32_tmp[L_FRAME48k]; - Word32 SWB_tenv_tmp_fx[SWB_TENV]; - Word32 L_tmp; - Word16 exp, frac; - Word16 fb_ener_adjust_fx = 0; - Word16 SWB_fenv_fx[SWB_FENV]; - Word16 L; - Word16 j = 0; - Word16 ener_adjust_quan_fx; - Word16 tmp2; - /*---------------------------------------------------------------------* - * SWB BWE decoding - *---------------------------------------------------------------------*/ - /* windowing of the ACELP core synthesis */ - new_input_fx_exp = *Qpost; - wtda_fx(synth_fx, &new_input_fx_exp, L_wtda_synth_fx, st_fx->L_old_wtda_swb_fx, - &st_fx->old_wtda_swb_fx_exp, - ALDO_WINDOW, - ALDO_WINDOW, /* window overlap of current frame (0: full, 2: none, or 3: half) */ - output_frame ); - *Qpost = sub(new_input_fx_exp,15); - /* DCT of the ACELP core synthesis */ - direct_transform_fx(L_wtda_synth_fx, ysynth_32, 0, output_frame, &new_input_fx_exp); - - /* Convert to 16 Bits (Calc Shift Required to Stay within MAX_Q_NEW_INPUT) */ - scl = sub(16+MAX_Q_NEW_INPUT, new_input_fx_exp); - /* Possible to Upscale? */ - IF (scl > 0) - { - /* Yes */ - /* Calc Room to Upscale */ - Q_syn = Find_Max_Norm32(ysynth_32, output_frame); - /* Stay within MAX_Q_NEW_INPUT */ - scl = s_min(Q_syn, scl); - } - Copy_Scale_sig32_16(ysynth_32, ysynth_fx, output_frame, scl); - Q_syn = add(sub(new_input_fx_exp, 16), scl); - - IF( !st_fx->bfi_fx ) - { - IF( st_fx->bws_cnt_fx > 0 ) - { - /* estimate parameters */ - mode = para_pred_bws_fx( st_fx, ysynth_fx, SWB_fenv_fx, Q_syn, coder_type ); - move16(); - } - ELSE - { - /* de-quantization */ - mode = swb_bwe_gain_deq_fx(st_fx, ACELP_CORE, SWB_tenv_fx, SWB_fenv_fx, 0, -1 ); - move16(); - } - - L = SWB_FENV; - move16(); - if(sub(mode, TRANSIENT) == 0) - { - L = SWB_FENV_TRANS; - move16(); - } - L_tmp = 0; - move16(); - FOR(i=0; iQ(15-exp) */ - st_fx->prev_ener_shb_fx = round_fx(L_shl(L_tmp, add(exp,2))); /*Q1 */ - } - ELSE - { - /* SHB FEC */ - IF( sub(st_fx->prev_mode_fx, TRANSIENT) != 0 ) - { - mode = st_fx->prev_mode_fx; - move16(); - } - ELSE - { - mode = NORMAL; - move16(); - } - - Copy( st_fx->prev_SWB_fenv_fx, SWB_fenv_fx, SWB_FENV ); - } - - /* reconstruction of MDCT spectrum of the error signal */ - set32_fx( ysynth_32, 0, output_frame ); - IF ( sub(st_fx->L_frame_fx, L_FRAME16k) == 0 ) - { - SWB_BWE_decoding_fx( ysynth_fx, SWB_fenv_fx, ysynth_32, L_FRAME32k-80, mode, &frica_flag, &st_fx->prev_Energy_fx, st_fx->prev_SWB_fenv_fx, - &st_fx->prev_L_swb_norm_fx, st_fx->tilt_wb_fx, &st_fx->Seed_fx, 80, &st_fx->prev_weight_fx, st_fx->extl_fx, Q_syn - ,st_fx->last_extl_fx - ); - } - ELSE - { - SWB_BWE_decoding_fx( ysynth_fx, SWB_fenv_fx, ysynth_32, L_FRAME32k-80, mode, &frica_flag, &st_fx->prev_Energy_fx, st_fx->prev_SWB_fenv_fx, - &st_fx->prev_L_swb_norm_fx, st_fx->tilt_wb_fx, &st_fx->Seed_fx, 6, &st_fx->prev_weight_fx, st_fx->extl_fx, Q_syn - ,st_fx->last_extl_fx - ); - } - - test(); - IF ( sub(st_fx->prev_frica_flag_fx, 1) == 0 && frica_flag == 0 ) - { - FOR( i = 0; i < L_SUBFR; i++ ) - { - tmp = sub(32767, extract_l(L_mult0(i, 512))); /*Q15 */ - st_fx->mem_imdct_fx[i] = mult_r(st_fx->mem_imdct_fx[i], tmp); - move16(); /*Q_synth */ - } - - FOR( ; i < output_frame; i++ ) - { - st_fx->mem_imdct_fx[i] = 0; - move16(); - } - } - - /* decode information */ - IF ( sub(st_fx->extl_fx, FB_BWE) == 0 ) - { - IF( !st_fx->bfi_fx ) - { - idxGain = (Word16)get_next_indice_fx(st_fx, NUM_BITS_FB_FRAMEGAIN ); - fb_ener_adjust_fx = usdequant_fx(idxGain, FB_GAIN_QLOW_FX, FB_GAIN_QDELTA_FX); /*Q15 */ - } - ELSE if( st_fx->bfi_fx ) - { - fb_ener_adjust_fx = st_fx->prev_fb_ener_adjust_fx; - move16(); - } - - st_fx->prev_fb_ener_adjust_fx = fb_ener_adjust_fx; - move16(); - IF(sub(mode, TRANSIENT) == 0) - { - ener_adjust_quan_fx = shr(fb_ener_adjust_fx, 2); - move16(); /*Q13*/ - } - ELSE - { - IF(SWB_fenv_fx[7] != 0) - { - tmp = div_s(1, SWB_fenv_fx[7]); - move16(); /*Q14*/ - ener_adjust_quan_fx = s_min(shr(i_mult(SWB_fenv_fx[13], tmp), 2), 32767); - move16(); /*Q13*/ - } - ELSE - { - ener_adjust_quan_fx = 0; - move16(); /*Q13*/ - } - } - - FOR( i = FB_BAND_BEGIN; i < FB_BAND_BEGIN+DE_OFFSET1; i++ ) - { - tmp = sub(32767, i_mult(j, 1024)); - tmp = mult_r(tmp, ener_adjust_quan_fx); /*Q13*/ - - tmp2 = i_mult(j, 256); /*Q13*/ - tmp2 = mult_r(tmp2, fb_ener_adjust_fx); /*Q13*/ - - tmp = add(tmp, tmp2); /*Q13*/ - ysynth_32[i] = ysynth_32[i-FB_BAND_WIDTH]; - move16(); - ysynth_32[i] = L_shl(Mult_32_16(ysynth_32[i], tmp), 2); - move32();/*15+Q_syn */ - j = add(j, 1); - } - - FOR( ; imem_imdct_fx, &st_fx->mem_imdct_exp_fx, output_frame, - ALDO_WINDOW, ALDO_WINDOW, 0,0,0); - l_subfr = mult(output_frame, 8192); - - test(); - IF( sub(mode,TRANSIENT) == 0 ) - { - FOR(i = 0; i < SWB_TENV; i++) - { - SWB_tenv_tmp_fx[i] = L_mult0(SWB_tenv_fx[i], 26214); - move32();/*Q15 */ - } - - /* time envelope shaping when the current frame is TRANSIENT frame */ - time_envelop_shaping_fx( hb_synth_fx, SWB_tenv_tmp_fx, output_frame, &Q_syn_hb ); - Q_syn_hb = sub(Q_syn_hb, 3); - - st_fx->prev_td_energy_fx = SWB_tenv_fx[3]; - move16(); - } - ELSE IF( sub(frica_flag, 1) == 0 && st_fx->prev_frica_flag_fx == 0 ) - { - time_reduce_pre_echo_fx( synth_fx, hb_synth_fx, st_fx->prev_td_energy_fx, l_subfr, *Qpost, Q_syn_hb ); - } - ELSE - { - tmp = i_mult2(3, l_subfr); - L_tmp = L_deposit_l(0); - FOR(i=0; iprev_td_energy_fx = 0; - move16(); - IF(L_tmp != 0) - { - exp = norm_l(L_tmp); - frac = extract_h(L_shl(L_tmp, exp)); - exp = sub(exp, sub(30,shl(Q_syn_hb,1))); - - tmp = div_s(16384, frac); - L_tmp = L_deposit_h(tmp); - L_tmp = Isqrt_lc(L_tmp, &exp); /*Q(31-exp) */ - st_fx->prev_td_energy_fx = round_fx(L_shl(L_tmp, sub(exp,15))); /*Q0 */ - } - } - - st_fx->prev_frica_flag_fx = frica_flag; - move16(); - st_fx->prev_mode_fx = mode; - move16(); - - return Q_syn_hb; -} diff --git a/src/libs/libevs/lib_dec/swb_bwe_dec_hr.cpp b/src/libs/libevs/lib_dec/swb_bwe_dec_hr.cpp new file mode 100644 index 00000000..92eb8df5 --- /dev/null +++ b/src/libs/libevs/lib_dec/swb_bwe_dec_hr.cpp @@ -0,0 +1,756 @@ +/*==================================================================================== + EVS Codec 3GPP TS26.443 Nov 13, 2018. Version 12.11.0 / 13.7.0 / 14.3.0 / 15.1.0 + ====================================================================================*/ + +#include +#include "options.h" +#include "prot.h" +#include "rom_com.h" + +/*-------------------------------------------------------------------* + * swb_bwe_dec_hr() + * + * HR SWB BWE decoder + *-------------------------------------------------------------------*/ + +void swb_bwe_dec_hr( + Decoder_State *st, /* i/o: decoder state structure */ + const float *syn_12k8_16k, /* i : ACELP core synthesis @16kHz */ + float *hb_synth, /* o : SHB synthesis */ + const short output_frame, /* i : frame length */ + const short unbits, /* i : number of core unused bits */ + const float pitch_buf[] /* i : pitch buffer */ +) +{ + short i, j, k, nBits, nBits_total, nBits_block, Nsv, Nsv2, width_noncoded; + short is_transient, tmpS, incr, IsTransient, pos; + int x_norm[NSV_MAX*(WIDTH_BAND+1)], x_norm1[NSV_MAX*(WIDTH_BAND+1)]; + float t_audio[L_FRAME48k], t_audio_tmp[L_FRAME48k]; + float gain = 0.0f, gain2, en_band[N_BANDS_BWE_HR]; + short ind1, ind2; + float EnergyLT, Energy; + short nq[NSV_MAX], nq2[NSV_MAX], nq_tmp[NSV_MAX]; + float tilt_wb, min_env, max_env; + float tmpF, tmp2, pitch, alpha; + float en_noncoded; + float env = 0.0f; + + /*---------------------------------------------------------------------* + * initializations + *---------------------------------------------------------------------*/ + + set_f( t_audio, 0.0f, output_frame ); + + st->bwe_highrate_seed = (short)((short)(pitch_buf[0]*64.0f)*(short)(pitch_buf[3]*64.0f)); + + ind2 = 0; /* only to suppress warnings */ + Nsv2 = 0; /* only to suppress warnings */ + gain2 = 0 ; /* only to suppress warnings */ + + /* reset memories in case that last frame was a different technology */ + if( st->last_core == HQ_CORE || st->last_extl != st->extl ) + { + set_f( st->old_wtda_swb, 0, L_FRAME48k ); + } + + /* calculate SWB BWE bit-budget */ + nBits = (short)(st->extl_brate) / 50 + unbits; + nBits_total = nBits; + + /*---------------------------------------------------------------------* + * calculate tilt of the core synthesis + *---------------------------------------------------------------------*/ + calc_tilt_bwe( syn_12k8_16k, &tilt_wb, L_FRAME16k ); + pitch = sum_f( pitch_buf, NB_SUBFR16k ) + EPSILON; + + + /*---------------------------------------------------------------------* + * FEC, or good frame decoding + *---------------------------------------------------------------------*/ + + if( st->bfi ) + { + is_transient = st->old_is_transient_hr_bwe; + + /* Replication of the last spectrum, with an attenuation */ + if( (st->clas_dec == VOICED_CLAS || st->clas_dec == INACTIVE_CLAS) && st->nbLostCmpt <= 3 ) + { + alpha = 0.8f; + } + else if( is_transient ) + { + alpha = 0.15f; + } + else + { + alpha = 0.3f; + } + + if( is_transient ) + { + /* set BWE spectrum length */ + if( output_frame == L_FRAME32k ) + { + tmpS = L_FRAME32k/NUM_TIME_SWITCHING_BLOCKS - NUM_TRANS_START_FREQ_COEF; + } + else /* output_frame == L_FRAME48k */ + { + tmpS = (2*END_FREQ_BWE_FULL_FB/50)/NUM_TIME_SWITCHING_BLOCKS - NUM_TRANS_START_FREQ_COEF; + } + + /* reconstruct */ + for( k=0; kt_audio_prev[i + k*tmpS]; + } + /* save transform coefficients for the next frame (needed in case of frame erasures) */ + mvr2r( t_audio + NUM_TRANS_START_FREQ_COEF + k*output_frame/NUM_TIME_SWITCHING_BLOCKS, st->t_audio_prev + k*tmpS, tmpS ); + } + } + else + { + /* set BWE spectrum length */ + if( output_frame == L_FRAME32k ) + { + tmpS = L_FRAME32k - NUM_NONTRANS_START_FREQ_COEF; + } + else /* output_frame == L_FRAME48k */ + { + tmpS = 2*END_FREQ_BWE_FULL_FB/50 - NUM_NONTRANS_START_FREQ_COEF; + } + + /* reconstruct */ + for( i=0; it_audio_prev[i]; + } + /* Save transform coefficients for the next frame (needed in case of frame erasures) */ + mvr2r( t_audio + NUM_NONTRANS_START_FREQ_COEF, st->t_audio_prev, tmpS ); + } + st->mem_EnergyLT *= alpha; + gain = (float)(2.0f*sqrt(st->mem_EnergyLT/output_frame)); + env = 1.0f; + } + else + { + /*---------------------------------------------------------------------* + * get transient frame flag + *---------------------------------------------------------------------*/ + + is_transient = (short) get_next_indice( st, 1 ); + + if( is_transient ) + { + nBits = -1; /* is_transient flag */ + nBits_block = nBits_total / NUM_TIME_SWITCHING_BLOCKS; + nBits += nBits_total % NUM_TIME_SWITCHING_BLOCKS; + + /* set width of noncoded (blind estimated) spectrum */ + if( st->extl == SWB_BWE_HIGHRATE || output_frame == L_FRAME32k ) + { + width_noncoded = L_FRAME32k/NUM_TIME_SWITCHING_BLOCKS - NUM_TRANS_END_FREQ_COEF; + tmpS = L_FRAME32k/NUM_TIME_SWITCHING_BLOCKS - NUM_TRANS_END_FREQ_COEF_EFF; + } + else /* st->extl == FB_BWE_HIGHRATE */ + { + width_noncoded = (2*END_FREQ_BWE_FULL_FB/50)/NUM_TIME_SWITCHING_BLOCKS - NUM_TRANS_END_FREQ_COEF; + tmpS = (2*END_FREQ_BWE_FULL_FB/50)/NUM_TIME_SWITCHING_BLOCKS - NUM_TRANS_END_FREQ_COEF_EFF; + } + + /*---------------------------------------------------------------------* + * transient frames: processing in blocks (subframes) + *---------------------------------------------------------------------*/ + + for( k = 0; k < NUM_TIME_SWITCHING_BLOCKS; k++ ) + { + nBits += nBits_block; + + /*---------------------------------------------------------------------* + * global gain and envelope decoding + *---------------------------------------------------------------------*/ + + /* get global gain */ + ind1 = (short) get_next_indice( st, NBITS_GLOB_GAIN_BWE_HR ); + gain = gain_dequant( ind1, MIN_GLOB_GAIN_BWE_HR, MAX_GLOB_GAIN_BWE_HR, NBITS_GLOB_GAIN_BWE_HR ); + nBits -= NBITS_GLOB_GAIN_BWE_HR; + + /* get energy per band */ + if( k == 0 ) + { + ind1 = (short) get_next_indice( st, NBITS_ENVELOPE_BWE_HR_TR ); + ind2 = ind1; + nBits -= NBITS_ENVELOPE_BWE_HR_TR; + } + else + { + if( ind2 < 8 ) + { + ind1 = (short) get_next_indice( st, NBITS_ENVELOPE_BWE_HR_TR - 1 ); + } + else + { + ind1 = (short) get_next_indice( st, NBITS_ENVELOPE_BWE_HR_TR - 1 ) + NUM_ENVLOPE_CODE_HR_TR2; + } + nBits -= (NBITS_ENVELOPE_BWE_HR_TR - 1); + } + + en_band[0] = swb_hr_env_code3[2 * ind1]; + en_band[1] = swb_hr_env_code3[2 * ind1 + 1]; + env = 0.5f*(en_band[0] + en_band[1]); + + /*---------------------------------------------------------------------* + * estimate energy of noncoded spectrum (14.4-20kHz) + *---------------------------------------------------------------------*/ + + en_noncoded = en_band[N_BANDS_TRANS_BWE_HR-1]; + + if( st->extl == FB_BWE_HIGHRATE ) + { + ind1 = (short) get_next_indice( st, NBITS_HF_GAIN_BWE_HR ); + nBits -= NBITS_HF_GAIN_BWE_HR; + + if( ind1 == 1 ) + { + en_noncoded *= BWE_HR_TRANS_EN_LIMIT1; + } + else if( ind1 == 2 ) + { + en_noncoded *= BWE_HR_TRANS_EN_LIMIT2; + } + else if( ind1 == 3 ) + { + en_noncoded *= BWE_HR_TRANS_EN_LIMIT3; + } + } + + /*---------------------------------------------------------------------* + * AVQ decoding (dequantize normalized spectrum) + *---------------------------------------------------------------------*/ + + Nsv = (NUM_TRANS_END_FREQ_COEF - NUM_TRANS_START_FREQ_COEF) / WIDTH_BAND; + AVQ_demuxdec( st, x_norm, &nBits, Nsv, nq ); + + for( i=0; i < Nsv*WIDTH_BAND; i++ ) + { + t_audio[k*output_frame/NUM_TIME_SWITCHING_BLOCKS + NUM_TRANS_START_FREQ_COEF + i] = (float) (x_norm[i]); + } + + /* apply noise-fill */ + swb_hr_noise_fill( is_transient, NUM_TRANS_START_FREQ_COEF, NUM_TRANS_END_FREQ_COEF, tilt_wb, pitch, nq, Nsv, &st->bwe_highrate_seed, + t_audio + NUM_TRANS_START_FREQ_COEF + k*output_frame/NUM_TIME_SWITCHING_BLOCKS ); + + /*---------------------------------------------------------------------* + * reconstruction + *---------------------------------------------------------------------*/ + + /* reconstruct 14-16(20) kHz spectrum */ + for( j = 0; j < tmpS; j++ ) + { + t_audio[k*output_frame/NUM_TIME_SWITCHING_BLOCKS + NUM_TRANS_END_FREQ_COEF_EFF + j] = 0.5f*t_audio[k*output_frame/NUM_TIME_SWITCHING_BLOCKS + NUM_TRANS_END_FREQ_COEF_EFF - tmpS + j]; + } + + /* envelope denormalization */ + for( i=0; it_audio_prev + k*(L_FRAME32k/NUM_TIME_SWITCHING_BLOCKS - NUM_TRANS_START_FREQ_COEF), L_FRAME32k/NUM_TIME_SWITCHING_BLOCKS - NUM_TRANS_START_FREQ_COEF ); + } + else /* output_frame == L_FRAME48k */ + { + mvr2r( t_audio + NUM_TRANS_START_FREQ_COEF + k*output_frame/NUM_TIME_SWITCHING_BLOCKS, st->t_audio_prev + k*((2*END_FREQ_BWE_FULL_FB/50)/NUM_TIME_SWITCHING_BLOCKS - NUM_TRANS_START_FREQ_COEF), (2*END_FREQ_BWE_FULL_FB/50)/NUM_TIME_SWITCHING_BLOCKS - NUM_TRANS_START_FREQ_COEF ); + } + + /* attenuate HFs in case of band-width switching */ + if( st->bws_cnt1 > 0 ) + { + if( output_frame == L_FRAME32k ) + { + j = L_FRAME32k/NUM_TIME_SWITCHING_BLOCKS - NUM_TRANS_START_FREQ_COEF; + } + else /* output_frame == L_FRAME48k */ + { + j = (2*END_FREQ_BWE_FULL_FB/50)/NUM_TIME_SWITCHING_BLOCKS - NUM_TRANS_START_FREQ_COEF; + } + + for( i=0; ibws_cnt1 / (float)N_NS2W_FRAMES; + } + } + } + } + else /* !is_transient */ + { + /* subtract one bit for is_transient flag */ + nBits--; + + /*---------------------------------------------------------------------* + * global gain and envelope decoding + *---------------------------------------------------------------------*/ + + /* get global gain */ + ind1 = (short) get_next_indice( st, NBITS_GLOB_GAIN_BWE_HR ); + gain = gain_dequant( ind1, MIN_GLOB_GAIN_BWE_HR, MAX_GLOB_GAIN_BWE_HR, NBITS_GLOB_GAIN_BWE_HR ); + + /* get energy per band */ + ind1 = (short) get_next_indice( st, NBITS_ENVELOPE_BWE_HR1 ); + ind2 = (short) get_next_indice( st, NBITS_ENVELOPE_BWE_HR2 ); + + en_band[0] = swb_hr_env_code1[2 * ind1]; + en_band[1] = swb_hr_env_code1[2 * ind1 + 1]; + en_band[2] = swb_hr_env_code2[2 * ind2]; + en_band[3] = swb_hr_env_code2[2 * ind2 + 1]; + env = 0.25f*(en_band[0] + en_band[1] + en_band[2] + en_band[3]); + + /*---------------------------------------------------------------------* + * choose sub-bands to be dequantized + *---------------------------------------------------------------------*/ + + /* find the subband with the min envelope */ + pos = 0; + min_env = en_band[0]; + max_env = en_band[0]; + for (j = 1; j < N_BANDS_BWE_HR; j++) + { + if(en_band[j] < min_env) + { + pos = j; + min_env = en_band[j]; + } + if(en_band[j] > max_env) + { + max_env = en_band[j]; + } + } + + /* decide the spectrum to be dequantized */ + if( nBits_total > NBITS_THRESH_BWE_HR ) + { + i = NUM_NONTRANS_END_FREQ_COEF - NUM_NONTRANS_START_FREQ_COEF; + } + else + { + i = NUM_NONTRANS_END_FREQ_COEF - NUM_NONTRANS_START_FREQ_COEF - 64 - 8*(pos%2); + } + + nBits -= NBITS_GLOB_GAIN_BWE_HR + NBITS_ENVELOPE_BWE_HR1 + NBITS_ENVELOPE_BWE_HR2; + + /*---------------------------------------------------------------------* + * estimate energy of noncoded spectrum (14.4-20kHz) + *---------------------------------------------------------------------*/ + + en_noncoded = 0.5f * min_env; + + if( st->extl == FB_BWE_HIGHRATE ) + { + ind1 = (short) get_next_indice( st, NBITS_HF_GAIN_BWE_HR ); + nBits -= NBITS_HF_GAIN_BWE_HR; + + if( ind1 == 1 ) + { + en_noncoded *= BWE_HR_NONTRANS_EN_LIMIT1; + } + else if( ind1 == 2 ) + { + en_noncoded *= 2.0f * BWE_HR_NONTRANS_EN_LIMIT2; + } + else if( ind1 == 3 ) + { + en_noncoded *= 2.0f * BWE_HR_NONTRANS_EN_LIMIT3; + } + } + + /*---------------------------------------------------------------------* + * AVQ decoding (dequantize normalized spectrum) + *---------------------------------------------------------------------*/ + + Nsv = i / WIDTH_BAND; + AVQ_demuxdec( st, x_norm, &nBits, Nsv, nq ); + + /*---------------------------------------------------------------------* + * second stage decoding + *---------------------------------------------------------------------*/ + + if( nBits >= 9 + NBITS_GLOB_GAIN_BWE_HR && sum_s( nq, Nsv) > 0 ) + { + ind1 = (short) get_next_indice( st, NBITS_GLOB_GAIN_BWE_HR ); + gain2 = gain_dequant( ind1, MIN_GLOB_GAIN_BWE_HR, MAX_GLOB_GAIN_BWE_HR, NBITS_GLOB_GAIN_BWE_HR ); + gain2 *= 0.0625f; + + /* calculate the number of subbands according to the rest bits */ + if( nBits > 396 ) + { + Nsv2 = 33; + } + else + { + Nsv2 = nBits/12; + } + + nBits -= NBITS_GLOB_GAIN_BWE_HR; + AVQ_demuxdec( st, x_norm1, &nBits, Nsv2, nq2 ); + } + + /*---------------------------------------------------------------------* + * dequantization + *---------------------------------------------------------------------*/ + + for( i=0; i Nsv ) + { + /* Safety check, happens rarely */ + set_s( nq_tmp + Nsv, 0, Nsv2 - Nsv ); + } + + k = 0; + incr = 0; + for( i=0; i= Nsv2 ) + { + break; + } + + if( nq_tmp[i] != 0 ) + { + for( j=0; j NBITS_THRESH_BWE_HR ) + { + mvr2r( t_audio_tmp, t_audio + NUM_NONTRANS_START_FREQ_COEF, NUM_NONTRANS_END_FREQ_COEF - NUM_NONTRANS_START_FREQ_COEF ); + } + else + { + ind1 = (pos*64 + pos/2 * WIDTH_BAND); + mvr2r( t_audio_tmp, t_audio + NUM_NONTRANS_START_FREQ_COEF, ind1 ); + + ind2 = ((pos+1)*64 + (pos+1)/2 * WIDTH_BAND); + mvr2r( t_audio_tmp + ind1, t_audio + NUM_NONTRANS_START_FREQ_COEF + ind2, NUM_NONTRANS_END_FREQ_COEF - NUM_NONTRANS_START_FREQ_COEF - ind2 ); + + /* reconstruct non-encoded subband */ + if( pos == 3 ) + { + mvr2r( t_audio + NUM_NONTRANS_START_FREQ_COEF + 128, t_audio + NUM_NONTRANS_START_FREQ_COEF + 200, 72 ); + + mvs2s( nq + 16, nq + 25, 9 ); + } + else + { + pos %= 2; + mvr2r( t_audio + NUM_NONTRANS_START_FREQ_COEF + ind2, t_audio + NUM_NONTRANS_START_FREQ_COEF + ind1, 64 + pos*WIDTH_BAND ); + ind1 /= WIDTH_BAND; + ind2 /= WIDTH_BAND; + + j = 0; + for( i=Nsv-1; i>=ind1; i-- ) + { + nq[33 - j++] = nq[i]; + } + + mvs2s( nq + ind2, nq + ind1, WIDTH_BAND+pos ); + } + } + + /* apply noise-fill */ + if( nBits < 200 ) + { + swb_hr_noise_fill( is_transient, NUM_NONTRANS_START_FREQ_COEF, NUM_NONTRANS_END_FREQ_COEF, tilt_wb, + pitch, nq, Nsv, &st->bwe_highrate_seed, t_audio + NUM_NONTRANS_START_FREQ_COEF ); + } + + /*---------------------------------------------------------------------* + * reconstruction + *---------------------------------------------------------------------*/ + + /* smoothing 12.6-12.8kHz */ + if( pos == 3 && nBits_total <= 400 ) + { + tmpF = sum2_f( t_audio + NUM_NONTRANS_START_FREQ_COEF + 200 - WIDTH_BAND, WIDTH_BAND ) + EPSILON; + tmp2 = sum2_f( t_audio + NUM_NONTRANS_START_FREQ_COEF + 200, WIDTH_BAND ) + EPSILON; + tmpF = (float)sqrt( tmpF/tmp2 ); + for( i=0; iextl == SWB_BWE_HIGHRATE || output_frame == L_FRAME32k ) + { + width_noncoded = L_FRAME32k - NUM_NONTRANS_END_FREQ_COEF; + } + else /* st->extl == FB_BWE_HIGHRATE */ + { + width_noncoded = 2*END_FREQ_BWE_FULL_FB/50 - NUM_NONTRANS_END_FREQ_COEF; + } + mvr2r( t_audio + NUM_NONTRANS_END_FREQ_COEF - width_noncoded, t_audio + NUM_NONTRANS_END_FREQ_COEF, width_noncoded ); + + /* smoothing 14.4-14.8kHz */ + tmpF = sum2_f( t_audio + NUM_NONTRANS_END_FREQ_COEF - WIDTH_BAND, WIDTH_BAND ) + EPSILON; + tmp2 = sum2_f( t_audio + NUM_NONTRANS_END_FREQ_COEF, WIDTH_BAND ) + EPSILON; + tmpF = (float)sqrt( tmpF/tmp2 ); + for( i=0; iextl == SWB_BWE_HIGHRATE || tmpF < 2.2f ) + { + for( j=0; jt_audio_prev, L_FRAME32k - NUM_NONTRANS_START_FREQ_COEF ); + } + else /* output_frame == L_FRAME48k */ + { + mvr2r( t_audio + NUM_NONTRANS_START_FREQ_COEF, st->t_audio_prev, 2*END_FREQ_BWE_FULL_FB/50 - NUM_NONTRANS_START_FREQ_COEF ); + } + + /* attenuate HFs in case of band-width switching */ + if( st->bws_cnt1 > 0 ) + { + if( output_frame == L_FRAME32k ) + { + j = L_FRAME32k - NUM_NONTRANS_START_FREQ_COEF; + } + else /* output_frame == L_FRAME48k */ + { + j = 2*END_FREQ_BWE_FULL_FB/50 - NUM_NONTRANS_START_FREQ_COEF; + } + + for( i=0; ibws_cnt1 / (float)N_NS2W_FRAMES; + } + } + } + } + + st->prev_ener_shb = gain*env; + for(i=0; iprev_SWB_fenv[i] = gain*env; + } + + /*---------------------------------------------------------------------* + * iOLA and iMDCT + *---------------------------------------------------------------------*/ + + inverse_transform( t_audio, t_audio_tmp, is_transient, output_frame, output_frame ); + window_ola( t_audio_tmp, hb_synth, st->old_wtda_swb, output_frame, ALDO_WINDOW, ALDO_WINDOW, 0,0,0 ); + + /*---------------------------------------------------------------------* + * final adjustments + *---------------------------------------------------------------------*/ + + if( !st->bfi ) + { + IsTransient = 0; + EnergyLT = st->mem_EnergyLT; + pos = 0; + for( j=0; j<4; j++ ) + { + Energy = sum2_f( hb_synth + j*(output_frame/4), output_frame/4 ) + EPSILON; + if( Energy > 12.5f * EnergyLT ) + { + IsTransient = 1; + pos = j; + } + + EnergyLT = 0.75f*EnergyLT + 0.25f*Energy; + } + + if( IsTransient == 1 && pos > 0 && tilt_wb < 3.0f && pitch > 500 ) + { + Nsv = pos*(output_frame/4); + Energy = sum2_f( hb_synth, Nsv ) + EPSILON; + if( st->last_extl != st->extl ) + { + st->mem_EnergyLT = Energy; + } + gain = (float)sqrt( pos*st->mem_EnergyLT/Energy ); + + gain *= 0.2f; + for( i=0; imem_EnergyLT = EnergyLT; + st->old_is_transient_hr_bwe = is_transient; + } + + /* post-processing in case of TD/FD switching */ + if( st->last_core == HQ_CORE || st->last_extl != st->extl ) + { + if( tilt_wb < 3.0f ) + { + gain = td_postprocess( hb_synth, output_frame, st->last_extl ); + + for( i=0; iold_wtda_swb[i] *= gain; + } + + tmpS = L_FRAME32k - NUM_NONTRANS_START_FREQ_COEF; + if( output_frame == L_FRAME48k ) + { + tmpS = 2*END_FREQ_BWE_FULL_FB/50 - NUM_NONTRANS_START_FREQ_COEF; + } + + for( i=0; it_audio_prev[i] *= gain; + } + } + } + + return; +} diff --git a/src/libs/libevs/lib_dec/swb_bwe_dec_hr_fx.cpp b/src/libs/libevs/lib_dec/swb_bwe_dec_hr_fx.cpp deleted file mode 100755 index 29e9ee57..00000000 --- a/src/libs/libevs/lib_dec/swb_bwe_dec_hr_fx.cpp +++ /dev/null @@ -1,1488 +0,0 @@ -/*==================================================================================== - EVS Codec 3GPP TS26.442 Apr 03, 2018. Version 12.11.0 / 13.6.0 / 14.2.0 - ====================================================================================*/ - -#include "options.h" /* Compilation switches */ -#include "prot_fx.h" /* Function prototypes */ -#include "rom_com_fx.h" /* Static table prototypes */ -#include "rom_dec_fx.h" /* Static table prototypes */ -#include "cnst_fx.h" /* Static table prototypes */ -#include "stl.h" - -#define Q_GUARD 1 -#define Q_32_BITS 14 /* scaling of 't_audio32' */ -#define MAKE_PSEUDO_FLT(v,e) ((((Word32)(v))<<16) + (e)) - -/*-----------------------------------------------------------* - * Gain_Dequant_HR() - * - * Returns decoded gain quantized between the specified - * range using the specified number of levels. - *-----------------------------------------------------------*/ -/* It would be more efficient (PROM wise) to combine - with gain_dequant_fx(). But for now the 'max' param has - a larger allowed range here (Q13) than in gain_dequant_fx() - where is is in Q15. This applies for the 'min' param too. - Here it is Q6 in gain_dequant_fx() it is Q0. But merging the - two functions would be less efficient (Performance Wise) - since the function here doesn't use 'Log2_norm_lc' at all - versus gain_dequant_fx() which does. */ -static Word16 Gain_Dequant_HR( /* o: decoded gain (Q13) */ - Word16 index, /* i: quantization index */ - const Word16 min, /* i: value of lower limit (Q13) */ - const Word16 bits, /* i: number of bits to dequantize */ - Word16 *exp /* o: exponent of Decoded Gain */ -) -{ - Word32 L_mini, L_fact; - Word16 gain; - Word32 L_temp; - Word16 exp1,exp2, p2_frac,p2_int; - - L_mini=0; /* no complexity counted, just to remove warning */ - L_fact=0; /* no complexity counted, just to remove warning */ - - move32(); - move32(); - IF (sub(min, G_AVQ_MIN_FX) == 0) - { - L_mini = MAKE_PSEUDO_FLT(26214, 15); /* 0.8 in Q15 */ - L_fact = MAKE_PSEUDO_FLT(14145, 11); /* Log2(96) - Log2(0.8) in Q11 */ - } - ELSE IF (sub(min, G_AVQ_MIN_DIV10_FX) == 0) - { - L_mini = MAKE_PSEUDO_FLT(20972, 18); /* 0.8*0.1 in Q18 */ - L_fact = MAKE_PSEUDO_FLT(20949, 11); /* Log2(96) - Log2(0.8*0.1) in Q11 */ - } - ELSE IF (sub(min, G_CODE_MIN_FX) == 0) - { - L_mini = MAKE_PSEUDO_FLT(20972, 20); /* 0.02 in Q20 */ - L_fact = MAKE_PSEUDO_FLT(32628, 12); /* Log2(5) - Log2(0.02) in Q12 */ - } - ELSE IF (sub(min, G_CODE_MIN_TC192_FX) == 0) - { - L_mini = MAKE_PSEUDO_FLT(19661, 15); /* 0.6 in Q15 */ - L_fact = MAKE_PSEUDO_FLT(24963, 12); /* Log2(41) - Log2(0.6) in Q12 */ - } - ELSE IF (sub(min, MIN_GLOB_GAIN_BWE_HR_FX) == 0) - { - L_mini = MAKE_PSEUDO_FLT(24576, 13); /* 3.0 in Q13 */ - L_fact = MAKE_PSEUDO_FLT(30232, 12); /* Log2(500) - Log2(3) in Q12 */ - } - /* levels = 1< 0 ) - { - pos = i; - move16(); - } - max_samp = s_max(temp, max_samp); - } - - IF( sub(pos, 160) < 0 ) - { - L_Energy = Calc_Energy_Autoscaled(hb_synth_fx + sub(input_frame, 80), hb_synth_fx_exp, 80, &temp1 ); - } - ELSE - { - L_Energy = Calc_Energy_Autoscaled(hb_synth_fx, hb_synth_fx_exp, 80, &temp1); - } - - ind1 = s_max(0, sub(pos, 40)); - ind2 = s_min( input_frame, add(pos, 40) ); - temp3 = sub(ind2, ind1); - - L_Energy2 = Calc_Energy_Autoscaled(hb_synth_fx + ind1, hb_synth_fx_exp, temp3, &temp2); - - /* Float Code: "gain_flt = min( 1.0f, 1.0f/sqrt( 80*tmpF/(gain_flt*temp) ) )" - * Multiply by 80 (eq to Mult by 1.25 and 64) - * So Div by 2 to avoid overflow - * Add 1/8 - * Adjust Exponent (-1 for Dib by2, -6 for Missing Mult by 64 - */ - L_Energy2 = L_add(L_shr(L_Energy2, 1), L_shr(L_Energy2, 3)); - temp2 = sub(temp2, 1+6); - - /* Normalize 'temp3' */ - temp = norm_s(temp3); - temp3 = shl(temp3, temp); - /* Adjust Exponent of Energy #1 */ - temp1 = add(temp1, temp); - /* Mult by 'temp3' */ - L_Energy = Mult_32_16(L_Energy, temp3); - L_Energy = L_max(L_Energy, 1); - - temp1 = sub(temp1, 15); /* because of Mpy_32_16_1 */ - - L_Energy = Sqrt_Ratio32(L_Energy, temp1, L_Energy2, temp2, &temp); - - /* Put Back to Q31 (Let it saturate to 0.99999 in fx because we wanted to limit the gain to 1.0 anyways) */ - L_Energy = L_shl(L_Energy, temp); - temp = round_fx(L_Energy); - - test(); - IF( sub(last_extl, SWB_BWE) == 0 || sub(last_extl, FB_BWE) == 0 ) - { - FOR( i = ind1; i < input_frame; i++ ) - { - hb_synth_fx[i] = mult_r(temp, hb_synth_fx[i]); - move16(); - } - } - ELSE - { - FOR( i = ind1; i < ind2; i++ ) - { - hb_synth_fx[i] = mult_r(temp, hb_synth_fx[i]); - move16(); - } - - IF ( sub(ind2, input_frame) != 0 ) - { - /* alpha_flt = (gain_flt > 0.5f) ? 1.0f : 0.5f;*/ - /* beta_flt = (alpha_flt - gain_flt)/sub(input_frame, ind2);*/ - temp2 = sub(16384, temp); - if (temp2 < 0) - temp2 = add(temp2, 16384); - temp3 = sub(input_frame, ind2); - /* Inverse 'temp3' */ - temp1 = norm_s(temp3); - temp3 = shl(temp3, temp1); - temp3 = div_s(16384, temp3); - L_Energy2 = L_mult0(temp2, temp3); - temp1 = add(temp1, 1); /* because we used 0.5 (16384) to inverse and not 1.0 (32768) */ - /* Back to Q31 */ - L_Energy2 = L_shr(L_Energy2, temp1); - - FOR( i = ind2; i < input_frame; i++ ) - { - hb_synth_fx[i] = mult_r(round_fx(L_Energy), hb_synth_fx[i]); - move16(); - L_Energy = L_add(L_Energy, L_Energy2); - } - } - } - - return temp; /* in Q15 */ -} - -/*-------------------------------------------------------------------* - * swb_bwe_dec_hr_fx() - * - * HR SWB BWE decoder - *-------------------------------------------------------------------*/ - -Word16 swb_bwe_dec_hr_fx( /* o : Exponent of SHB synthesis */ - Decoder_State_fx *st_fx, /* i/o: decoder state structure */ - const Word16 *syn_12k8_16k_fx,/* i : ACELP core synthesis @16kHz */ - const Word16 exp, /* i : Exponent of core synthesis */ - Word16 *hb_synth_fx, /* o : SHB synthesis */ - const Word16 output_frame, /* i : frame length */ - const Word16 unbits, /* i : number of core unused bits */ - const Word16 pitch_buf[] /* i : pitch buffer */ -) -{ - Word16 i, j, k, nBits, nBits_total, nBits_block, Nsv, Nsv2, width_noncoded; - Word16 is_transient, tmpS, incr, IsTransient, pos; - Word16 x_norm[NSV_MAX*(WIDTH_BAND+1)], x_norm1[NSV_MAX*(WIDTH_BAND+1)]; - Word32 t_audio32_tmp[L_FRAME48k]; - Word32 t_audio32[L_FRAME48k]; - Word16 t_audio_exp; - Word16 en_band[N_BANDS_BWE_HR]; - Word16 ind1, ind2; - Word32 L_EnergyLT, L_Energy; - Word16 nq[NSV_MAX], nq2[NSV_MAX], nq_tmp[NSV_MAX]; - Word16 alpha; - Word16 temp, temp2, temp3, temp4; - Word16 en_noncoded, min_env, max_env; - Word16 gain_fx = 0, gain2_fx, exp1, exp2; - Word16 len; - Word16 pitch; - Word32 L_temp, L_temp2; - Word32 L_tilt_wb; - Word16 hb_synth_fx_exp; - Word16 *ptr16; - Word32 *ptr32; - Word32 L_ener_all, L_ener_saved; - Word16 ener_all_exp, ener_saved_exp; - Word16 *t_audio, *t_audio_tmp; - Word16 env = 0; - Word16 exp_L, inv_L, frac; - - /* Use 't_audio32_tmp' Word32 Buffer as two Word16 Buffers to save local Stack. */ - /* There is no possible overlap so it is ok */ - t_audio = (Word16 *)&t_audio32_tmp[0]; - t_audio_tmp = (Word16 *)&t_audio32_tmp[L_FRAME48k/2]; - - st_fx->bwe_highrate_seed_fx = extract_l(L_mult0(pitch_buf[0],pitch_buf[3])); - - /*---------------------------------------------------------------------* - * initializations - *---------------------------------------------------------------------*/ - - set16_fx(t_audio, 0, output_frame); - set32_fx(t_audio32, 0, output_frame); - exp2 = 0; - move16(); - Nsv2 = 0; - move16(); - /* only to suppress warnings (no complexity counted) */ - gain2_fx = 0; - move16(); - ind2 = 0; - move16(); - L_ener_saved = 0; - move16(); - ener_saved_exp = 0; - move16(); - - /* reset memories in case that last frame was a different technology */ - test(); - IF( sub(st_fx->last_core_fx, HQ_CORE) == 0 || sub(st_fx->last_extl_fx, st_fx->extl_fx) != 0 ) - { - set16_fx( st_fx->L_old_wtda_swb_fx, 0, L_FRAME48k ); - st_fx->Q_old_wtda = 14; - move16(); - } - - /* calculate SWB BWE bit-budget */ - /* nBits = st->extl_brate/50 + unbits */ - nBits = add(320,unbits); /* st->extl_brate_fx is always 16kbps */ - nBits_total = nBits; - move16(); - - /*---------------------------------------------------------------------* - * calculate tilt of the core synthesis - *---------------------------------------------------------------------*/ - L_tilt_wb = calc_tilt_bwe_fx( syn_12k8_16k_fx, exp, L_FRAME16k ); - L_temp = L_mac(1L, 8192, pitch_buf[0]); - FOR (i = 1; i < NB_SUBFR16k-1; i++) - { - L_temp = L_mac(L_temp, 8192, pitch_buf[i]); - } - pitch = mac_r(L_temp, 8192, pitch_buf[i]); - /* pitch now in Q4 (Q6 div by 4) */ - - /*---------------------------------------------------------------------* - * FEC, or good frame decoding - *---------------------------------------------------------------------*/ - - IF( st_fx->bfi_fx ) - { - is_transient = st_fx->old_is_transient_hr_bwe_fx; - move16(); - - /* Replication of the last spectrum, with an attenuation */ - test(); - test(); - IF( (sub(st_fx->clas_dec, VOICED_CLAS) == 0 || sub(st_fx->clas_dec, INACTIVE_CLAS) == 0) && sub(st_fx->nbLostCmpt, 3) <= 0 ) - { - alpha = 26214; /* 0.80 */ move16(); - t_audio_exp = 0; - move16(); - } - ELSE IF ( is_transient ) - { - alpha = 19661 /* 0.15 */; - move16(); - t_audio_exp = 2; - move16(); - } - ELSE - { - alpha = 19661 /* 0.30 */; - move16(); - t_audio_exp = 1; - move16(); - } - - IF( is_transient ) - { - /* output_frame == L_FRAME48k */ - tmpS = (2*END_FREQ_BWE_FULL_FB/50)/NUM_TIME_SWITCHING_BLOCKS - NUM_TRANS_START_FREQ_COEF; - move16(); - /* set BWE spectrum length */ - if( sub(output_frame, L_FRAME32k) == 0 ) - { - tmpS = L_FRAME32k/NUM_TIME_SWITCHING_BLOCKS - NUM_TRANS_START_FREQ_COEF; - move16(); - } - - temp = shr(output_frame, 2); - pos = NUM_TRANS_START_FREQ_COEF; - move16(); - ind1 = 0; - move16(); - /* reconstruct */ - len = 0; - move16(); - /* Here t_audio was initialy filled with zeros */ - /* So, after the loop, the Q will be 'Q_32_Bits' */ - FOR( k=0; kt_audio_prev_fx_exp[k], Q_32_BITS); - temp4 = add(temp4, t_audio_exp); - FOR( i=0; it_audio_prev_fx[i + ind1]); - L_temp = L_shr(L_temp, temp4); - t_audio32[pos + i] = L_temp; - move32(); - } - ind1 = add(ind1, tmpS); - pos = add(pos, temp); - } - /* Save transform coefficients for the next frame (needed in case of frame erasures) */ - FOR( k=0; kt_audio_prev_fx + i_mult2(k, tmpS), tmpS, temp4); - st_fx->t_audio_prev_fx_exp[k] = add(Q_32_BITS, temp4); - move16(); - len = add(len, shr(output_frame, 2)); - } - } - ELSE - { - /* output_frame == L_FRAME48k */ - tmpS = 2*END_FREQ_BWE_FULL_FB/50 - NUM_NONTRANS_START_FREQ_COEF; - move16(); - /* set BWE spectrum length */ - if( sub(output_frame, L_FRAME32k) == 0 ) - { - tmpS = L_FRAME32k - NUM_NONTRANS_START_FREQ_COEF; - move16(); - } - - /* reconstruct */ - /* Here t_audio was initialy filled with zeros */ - /* So, after the loop, the Q will be 'Q_32_Bits' */ - temp4 = sub(st_fx->t_audio_prev_fx_exp[0], Q_32_BITS); - temp4 = add(temp4, t_audio_exp); - ptr32 = &t_audio32[NUM_NONTRANS_START_FREQ_COEF]; - FOR( i=0; it_audio_prev_fx[i]); - L_temp = L_shr(L_temp, temp4); - *ptr32++ = L_temp; - move32(); - } - /* Save transform coefficients for the next frame (needed in case of frame erasures) */ - temp = NUM_NONTRANS_START_FREQ_COEF; - move16(); /* not necessary but improves readability and allows a larger common code path */ - temp4 = Find_Max_Norm32(t_audio32 + temp, tmpS); - Copy_Scale_sig32_16(t_audio32 + temp, st_fx->t_audio_prev_fx, tmpS, temp4); - st_fx->t_audio_prev_fx_exp[0] = add(Q_32_BITS, temp4); - move16(); - } - - st_fx->L_mem_EnergyLT_fx = Mul_flt32_Q15(st_fx->L_mem_EnergyLT_fx, &st_fx->mem_EnergyLT_fx_exp, alpha); - move32(); - st_fx->mem_EnergyLT_fx_exp = add(st_fx->mem_EnergyLT_fx_exp, t_audio_exp); - - /* Set Exponent */ - t_audio_exp = Q_32_BITS; - move16(); - exp_L = norm_s(output_frame); - inv_L = div_s(shl(1,sub(14,exp_L)), output_frame); /*Q(29-exp_L)*/ - - /*Q(st_fx->mem_EnergyLT_fx_exp+29-exp_L-15) -> Q(st_fx->mem_EnergyLT_fx_exp-exp_L+14)*/ - st_fx->L_mem_EnergyLT_fx = Mul_flt32_Q15(st_fx->L_mem_EnergyLT_fx, &st_fx->mem_EnergyLT_fx_exp, inv_L); - move32(); - IF(st_fx->L_mem_EnergyLT_fx != 0) - { - exp1 = norm_l(st_fx->L_mem_EnergyLT_fx); - frac = extract_h(L_shl(st_fx->L_mem_EnergyLT_fx, exp1)); - exp1 = sub(exp1,sub(16,sub(st_fx->mem_EnergyLT_fx_exp,exp_L))); - - temp = div_s(16384, frac); - L_temp = L_deposit_h(temp); - L_temp = Isqrt_lc(L_temp, &exp1); - gain_fx = extract_l(L_shl(L_temp, sub(exp1, 2))); /*Q(31-exp + (exp-3)) -> Q13*/ - } - - env = 512; - move16(); - } - ELSE - { - /*---------------------------------------------------------------------* - * get transient frame flag - *---------------------------------------------------------------------*/ - - is_transient = (Word16) get_next_indice_fx( st_fx, 1 ); - - IF( is_transient ) - { - nBits = -1; - move16(); /* is_transient flag */ - nBits_block = shr(nBits_total, 2); - nBits = add(nBits, s_and(nBits_total, 3)); - - /* set width of noncoded (blind estimated) spectrum */ - test(); - IF( sub(st_fx->extl_fx, SWB_BWE_HIGHRATE) == 0 || sub(output_frame, L_FRAME32k) == 0 ) - { - width_noncoded = L_FRAME32k/NUM_TIME_SWITCHING_BLOCKS - NUM_TRANS_END_FREQ_COEF; - move16(); - tmpS = L_FRAME32k/NUM_TIME_SWITCHING_BLOCKS - NUM_TRANS_END_FREQ_COEF_EFF; - move16(); - } - ELSE /* st->extl == FB_BWE_HIGHRATE */ - { - width_noncoded = (2*END_FREQ_BWE_FULL_FB/50)/NUM_TIME_SWITCHING_BLOCKS - NUM_TRANS_END_FREQ_COEF; - move16(); - tmpS = (2*END_FREQ_BWE_FULL_FB/50)/NUM_TIME_SWITCHING_BLOCKS - NUM_TRANS_END_FREQ_COEF_EFF; - move16(); - } - - /*---------------------------------------------------------------------* - * transient frames: processing in blocks (subframes) - *---------------------------------------------------------------------*/ - len = 0; - move16(); - FOR( k = 0; k < NUM_TIME_SWITCHING_BLOCKS; k++ ) - { - nBits = add(nBits, nBits_block); - - /*---------------------------------------------------------------------* - * global gain and envelope decoding - *---------------------------------------------------------------------*/ - - /* get global gain */ - ind1 = (Word16) get_next_indice_fx( st_fx, NBITS_GLOB_GAIN_BWE_HR ); - gain_fx = Gain_Dequant_HR( ind1, MIN_GLOB_GAIN_BWE_HR_FX, NBITS_GLOB_GAIN_BWE_HR, &exp1 ); - nBits = sub(nBits, NBITS_GLOB_GAIN_BWE_HR); - - /* get energy per band */ - IF( k == 0 ) - { - ind1 = (Word16)get_next_indice_fx( st_fx, NBITS_ENVELOPE_BWE_HR_TR ); - ind2 = ind1; - move16(); - nBits = sub(nBits, NBITS_ENVELOPE_BWE_HR_TR); - } - ELSE - { - ind1 = (Word16)get_next_indice_fx( st_fx, NBITS_ENVELOPE_BWE_HR_TR - 1 ); - if( sub(ind2, 8) >= 0 ) - { - ind1 = add(ind1, NUM_ENVLOPE_CODE_HR_TR2); - } - nBits = sub(nBits, NBITS_ENVELOPE_BWE_HR_TR - 1); - } - - temp = shl(ind1, 1); - en_band[0] = swb_hr_env_code3_fx[temp]; - move16(); - en_band[1] = swb_hr_env_code3_fx[add(temp, 1)]; - move16(); - - /*env = add(shr(en_band[0], 1), shr(en_band[1], 1));*/ - env = mac_r(L_mult(en_band[0], 16384), en_band[1], 16384); - - /*---------------------------------------------------------------------* - * estimate energy of noncoded spectrum (14.4-20kHz) - *---------------------------------------------------------------------*/ - - en_noncoded = en_band[N_BANDS_TRANS_BWE_HR-1]; - move16(); - - IF( sub(st_fx->extl_fx, FB_BWE_HIGHRATE) == 0) - { - ind1 = (Word16)get_next_indice_fx( st_fx, NBITS_HF_GAIN_BWE_HR ); - nBits = sub(nBits, NBITS_HF_GAIN_BWE_HR); - - IF (sub(ind1, 1) == 0) - { - en_noncoded = round_fx(L_mult0(en_noncoded, BWE_HR_TRANS_EN_LIMIT1_FX_Q16)); - } - - IF( sub(ind1, 2) == 0 ) - { - en_noncoded = round_fx(L_mult0(en_noncoded, BWE_HR_TRANS_EN_LIMIT2_FX_Q16)); - } - - IF( sub(ind1, 3) == 0 ) - { - en_noncoded = round_fx(L_mult0(en_noncoded, BWE_HR_TRANS_EN_LIMIT3_FX_Q16)); - } - } - - /*---------------------------------------------------------------------* - * AVQ decoding (dequantize normalized spectrum) - *---------------------------------------------------------------------*/ - - Nsv = (NUM_TRANS_END_FREQ_COEF - NUM_TRANS_START_FREQ_COEF) / WIDTH_BAND; - move16(); - AVQ_demuxdec_fx( st_fx, x_norm, &nBits, Nsv, nq ); - - temp = add(len, NUM_TRANS_START_FREQ_COEF); - /* 't_audio' in Q8 */ - t_audio_exp = 8; - move16(); - FOR( i=0; i < Nsv*WIDTH_BAND; i++ ) - { - t_audio[temp + i] = shl(x_norm[i], t_audio_exp); - move16(); - } - - /* apply noise-fill */ - swb_hr_noise_fill_fx( is_transient, NUM_TRANS_START_FREQ_COEF, NUM_TRANS_END_FREQ_COEF, - round_fx(L_shl(L_tilt_wb, 3)), /* Q(24+3-16) -> Q11 */ - pitch, nq, Nsv, &st_fx->bwe_highrate_seed_fx, t_audio+temp, t_audio_exp ); - - /* Go from Q't_audio_exp' on 16 Bits to 'Q_32_BITS' on 32 bits */ - temp2 = i_mult2(WIDTH_BAND, Nsv); - ptr16 = &t_audio[temp]; - move16(); - ptr32 = &t_audio32[temp]; - j = shl(1, sub(Q_32_BITS, t_audio_exp)); - FOR (i = 0; i< temp2; i++) - { - /* put in 'Q_32_BITS' in a 32 Bits */ - L_temp = L_mult0(*ptr16++, j); - *ptr32++ = L_temp; - move32(); - } - - /*---------------------------------------------------------------------* - * reconstruction - *---------------------------------------------------------------------*/ - - temp = add(temp, NUM_TRANS_END_FREQ_COEF_EFF-NUM_TRANS_START_FREQ_COEF); - pos = sub(temp, tmpS); - ptr32 = &t_audio32[temp]; - /* reconstruct 14-16(20) kHz spectrum */ - FOR( j = 0; j < tmpS; j++ ) - { - *ptr32++ = L_shr(t_audio32[pos + j], 1); - move32(); - } - - temp = i_mult2(shr(output_frame, 2), k); - - temp2 = add(NUM_TRANS_START_FREQ_COEF, temp); - ptr32 = &t_audio32[temp2]; - /* envelope denormalization */ - FOR( i=0; it_audio_prev_fx + i_mult2(k, pos), pos, temp4); - st_fx->t_audio_prev_fx_exp[k] = add(Q_32_BITS, temp4); - move16(); - len = add(len, shr(output_frame, 2)); - - /* attenuate HFs in case of band-width switching */ - IF( st_fx->bws_cnt1_fx > 0 ) - { - temp = shr(output_frame, 2); - temp = i_mult(k, temp); - temp = add(NUM_TRANS_START_FREQ_COEF, temp); - temp2 = i_mult(st_fx->bws_cnt1_fx, 1638); /*Q15*/ - - j = (2*END_FREQ_BWE_FULL_FB/50)/NUM_TIME_SWITCHING_BLOCKS - NUM_TRANS_START_FREQ_COEF; - move16(); - if( output_frame == L_FRAME32k ) - { - j = L_FRAME32k/NUM_TIME_SWITCHING_BLOCKS - NUM_TRANS_START_FREQ_COEF; - move16(); - } - - FOR( i=0; iextl_fx, FB_BWE_HIGHRATE) == 0 ) - { - ind1 = (Word16) get_next_indice_fx( st_fx, NBITS_HF_GAIN_BWE_HR ); - nBits = sub(nBits, NBITS_HF_GAIN_BWE_HR); - - if (sub(ind1, 1) == 0) - { - /* en_noncoded = BWE_HR_NONTRANS_EN_LIMIT1*(0.5*min_env) ==> 0.25*min_env */ - en_noncoded = mult_r(min_env, BWE_HR_NONTRANS_EN_LIMIT2_FX_Q15/2); - } - - IF (sub(ind1, 2) == 0) - { - /* en_noncoded = 2.0*BWE_HR_NONTRANS_EN_LIMIT2*(0.5*min_env) ==> 1.2*min_env */ - en_noncoded = round_fx(L_shl(L_mult(BWE_HR_NONTRANS_EN_LIMIT2_FX_Q14, min_env), 1)); - } - - if (sub(ind1, 3) == 0) - { - /* en_noncoded = 2.0*BWE_HR_NONTRANS_EN_LIMIT3*(0.5*min_env) ==> 0.8*min_env */ - en_noncoded = mult_r(BWE_HR_NONTRANS_EN_LIMIT3_FX_Q15, min_env); - } - } - - /*---------------------------------------------------------------------* - * AVQ decoding (dequantize normalized spectrum) - *---------------------------------------------------------------------*/ - - /* Nsv = i / WIDTH_BAND */ - Nsv = shr(i, 3); - AVQ_demuxdec_fx( st_fx, x_norm, &nBits, Nsv, nq ); - - /*---------------------------------------------------------------------* - * second stage decoding - *---------------------------------------------------------------------*/ - - test(); - IF( sub(nBits, 9 + NBITS_GLOB_GAIN_BWE_HR) >= 0 && sum16_fx( nq, Nsv) > 0 ) - { - ind1 = (Word16) get_next_indice_fx( st_fx, NBITS_GLOB_GAIN_BWE_HR ); - gain2_fx = Gain_Dequant_HR( ind1, MIN_GLOB_GAIN_BWE_HR_FX, NBITS_GLOB_GAIN_BWE_HR, &exp2 ); - /* gain2_flt *= 0.0625f */ - exp2 = add(exp2, 4); - - /* calculate the number of subbands according to the rest bits */ - IF( sub(nBits, 396) > 0 ) - { - Nsv2 = 33; - move16(); - } - ELSE - { - /* Here what is acheived is an integer divide by 12 with truncation. */ - /* nBits/12 */ - Nsv2 = mult(nBits, 2731); - /* But, we have imprecision of the fraction so correction is necessary. */ - /* We crosscheck if 'Nsv2' is either too high or too low. */ - /* Finally, the result must satisfy: */ - /* Nsv2 * 12 <= nBits (Nsv2 is not too high) AND */ - /* nBits - Nsv2 * 12 < 12 (Nsv2 is the highest divisor) */ - L_temp = L_msu0(L_deposit_l(nBits), 12, Nsv2); - if (L_sub(L_temp, 12L) >= 0) - Nsv2 = add(Nsv2, 1); - if (L_temp < 0) - Nsv2 = sub(Nsv2, 1); - } - - nBits = sub(nBits, NBITS_GLOB_GAIN_BWE_HR); - AVQ_demuxdec_fx( st_fx, x_norm1, &nBits, Nsv2, nq2 ); - } - - /*---------------------------------------------------------------------* - * dequantization - *---------------------------------------------------------------------*/ - - /* set 't_audio' exp */ - t_audio_exp = 10; - move16(); - FOR( i = 0; i < Nsv*WIDTH_BAND; i++ ) - { - t_audio_tmp[i] = shl(x_norm[i], t_audio_exp); - move16(); - } - - Copy( nq, nq_tmp, Nsv ); - IF( sub(Nsv2, Nsv) > 0 ) - { - /* Safety check, happens rarely */ - set16_fx( nq_tmp + Nsv, 0, sub(Nsv2, Nsv) ); - } - - incr = 0; - move16(); - ptr16 = x_norm1; - temp2 = sub(sub(exp2, 15), t_audio_exp); /* go to Q't_audio' */ - FOR( i=0; i= 0 ) - { - BREAK; - } - - IF( nq_tmp[i] != 0 ) - { - temp = shl(i, 3); - FOR( j=0; j 0 ) - { - Copy( t_audio_tmp, ptr16, NUM_NONTRANS_END_FREQ_COEF - NUM_NONTRANS_START_FREQ_COEF ); - /* Update Maximum Written Location (from t_audio + NUM_NONTRANS_START_FREQ_COEF) */ - temp4 = NUM_NONTRANS_END_FREQ_COEF - NUM_NONTRANS_START_FREQ_COEF; - } - ELSE - { - ind1 = add(shl(pos, 6), i_mult2(shr(pos, 1), WIDTH_BAND)); - Copy( t_audio_tmp, ptr16, ind1 ); - - /* Update Maximum Written Location (from t_audio + NUM_NONTRANS_START_FREQ_COEF) */ - temp4 = ind1; - - temp = add(pos, 1); - ind2 = add(shl(temp, 6), i_mult2(shr(temp, 1), WIDTH_BAND)); - Copy( t_audio_tmp + ind1, ptr16 + ind2, NUM_NONTRANS_END_FREQ_COEF - NUM_NONTRANS_START_FREQ_COEF - ind2 ); - /* Update Maximum Written Location (from t_audio + NUM_NONTRANS_START_FREQ_COEF) */ - temp4 = s_max(temp4, NUM_NONTRANS_END_FREQ_COEF - NUM_NONTRANS_START_FREQ_COEF); - - /* reconstruct non-encoded subband */ - IF( sub(pos, 3) == 0 ) - { - Copy( t_audio + NUM_NONTRANS_START_FREQ_COEF + 128, ptr16 + 200, 72 ); - /* Update Maximum Written Location (from t_audio + NUM_NONTRANS_START_FREQ_COEF) */ - temp4 = s_max(temp4, 200+72); - - Copy( nq + 16, nq + 25, 9 ); - } - ELSE - { - pos = s_and(pos, 1); - temp3 = add(64, shl(pos, 3)); - Copy( ptr16 + ind2, ptr16 + ind1, temp3 ); - /* Update Maximum Written Location (from t_audio + NUM_NONTRANS_START_FREQ_COEF) */ - temp4 = s_max(temp4, add(ind1, temp3)); - - ind1 = shr(ind1, 3); - ind2 = shr(ind2, 3); - - j = 33; - move16(); - FOR( i=sub(Nsv, 1); i>=ind1; i-- ) - { - nq[j] = nq[i]; - move16(); - j = sub(j, 1); - } - - Copy( nq + ind2, nq + ind1, add(WIDTH_BAND, pos) ); - } - } - - /* apply noise-fill */ - IF( sub(nBits, 200) < 0 ) - { - swb_hr_noise_fill_fx( is_transient, NUM_NONTRANS_START_FREQ_COEF, NUM_NONTRANS_END_FREQ_COEF, - round_fx(L_shl(L_tilt_wb, 3)), /* Q(24+3-16) -> Q11 */ - pitch, nq, Nsv, &st_fx->bwe_highrate_seed_fx, t_audio + NUM_NONTRANS_START_FREQ_COEF, t_audio_exp ); - } - - /* Go from Q't_audio_exp' on 16 Bits to Q16 on 32 bits */ - ptr32 = &t_audio32[NUM_NONTRANS_START_FREQ_COEF]; - j = shl(1, sub(Q_32_BITS, t_audio_exp)); - FOR (i = 0; i < temp4; i++) - { - /* put in 'Q_32_BITS' in a 32 Bits */ - L_temp = L_mult0(*ptr16++, j); - *ptr32++ = L_temp; - move32(); - } - - /*---------------------------------------------------------------------* - * reconstruction - *---------------------------------------------------------------------*/ - - /* smoothing 12.6-12.8kHz */ - test(); - IF( sub(pos, 3) == 0 && sub(nBits_total, 400) <= 0 ) - { - ptr16 = &t_audio[NUM_NONTRANS_START_FREQ_COEF + 200 - WIDTH_BAND]; - L_temp = L_mac0(1L/* EPSILON */, *ptr16, *ptr16); - FOR (i = 1; i < WIDTH_BAND; i++) - { - ptr16++; - L_temp = L_mac0(L_temp, *ptr16, *ptr16); - } - ptr16++; - L_temp2 = L_mac0(1L/* EPSILON */, *ptr16, *ptr16); - FOR (i = 1; i < WIDTH_BAND; i++) - { - ptr16++; - L_temp2 = L_mac0(L_temp2, *ptr16, *ptr16); - } - L_temp = Sqrt_Ratio32(L_temp, 0, L_temp2, 0, &temp); - - /* if 'temp' is < 0 then it is req to shift right before substracting 1.0 */ - temp2 = s_min(0, temp); - L_temp = L_shl(L_temp, temp2); - /* Energy_flt - i*(Energy_flt-1.0)/8.0 */ - L_temp2 = L_add(L_temp, L_shr(-2147483647L-1L, s_max(0, temp))); /* 1.0 in same Q as Sqrt minus the Guard */ - /* / 8.0 */ - L_temp2 = L_shr(L_temp2, 3+Q_GUARD); - /* Add Guard */ - L_temp = L_shr(L_temp, Q_GUARD); - /* Set Index */ - ptr16 = &t_audio[NUM_NONTRANS_START_FREQ_COEF + 200]; - ptr32 = &t_audio32[NUM_NONTRANS_START_FREQ_COEF + 200]; - /* Set Exponent (relative to t_audio_exp (from 16 bits vector) */ - temp2 = add(sub(temp, temp2), sub(Q_GUARD-(16-Q_32_BITS), t_audio_exp)); - - FOR( i=0; iextl == FB_BWE_HIGHRATE */ - test(); - if( sub(st_fx->extl_fx, SWB_BWE_HIGHRATE) == 0 || sub(output_frame, L_FRAME32k) == 0 ) - { - width_noncoded = L_FRAME32k - NUM_NONTRANS_END_FREQ_COEF; - move16(); - } - - ptr16 = &t_audio[NUM_NONTRANS_END_FREQ_COEF - WIDTH_BAND]; - L_temp = L_mac0(1L/* EPSILON */, *ptr16, *ptr16); - FOR (i = 1; i < WIDTH_BAND; i++) - { - ptr16++; - L_temp = L_mac0(L_temp, *ptr16, *ptr16); - } - - ptr16 = &t_audio[sub(NUM_NONTRANS_END_FREQ_COEF, width_noncoded)]; - L_temp2 = L_mac0(1L/* EPSILON */, *ptr16, *ptr16); - FOR (i = 1; i < WIDTH_BAND; i++) - { - ptr16++; - L_temp2 = L_mac0(L_temp2, *ptr16, *ptr16); - } - L_temp = Sqrt_Ratio32(L_temp, 0, L_temp2, 0, &temp); - - /* So part of the copy can be skipped because the loop that follows */ - /* will take the values from t_audio (16 bits) */ - /* Since 'width_noncoded' is always > WIDTH_BAND, we can substract it from the length */ - /* and adjust the offset accordingly */ - Copy32( t_audio32 + sub(NUM_NONTRANS_END_FREQ_COEF+WIDTH_BAND, width_noncoded), - t_audio32 + NUM_NONTRANS_END_FREQ_COEF+WIDTH_BAND, sub(width_noncoded, WIDTH_BAND) ); - - /* smoothing 14.4-14.8kHz */ - ptr16 = &t_audio[sub(NUM_NONTRANS_END_FREQ_COEF, width_noncoded)]; - ptr32 = &t_audio32[NUM_NONTRANS_END_FREQ_COEF]; - temp = sub(temp, add(t_audio_exp, 16-Q_32_BITS)); - FOR( i=0; iextl_fx,SWB_BWE_HIGHRATE) == 0 || sub(temp,shl(18022,sub(15-13,temp2))) < 0 ) /* 2.2 in Q13 == 18022 */ - { - - /* (en_band_flt[3] - j*(en_band_flt[3]/WIDTH_BAND - en_noncoded_flt/WIDTH_BAND)) */ - L_temp = L_deposit_h(en_band[3]); - L_temp2 = L_mult(sub(en_band[3], en_noncoded), 32768/WIDTH_BAND); - ptr32 = &t_audio32[NUM_NONTRANS_END_FREQ_COEF]; - /* in L_temp/L_temp2, value in Q16+9 */ - FOR( j=0; j Q23 */ - L_temp2 = Mult_32_16(L_temp,32768/160); /* step */ - FOR( j=0; j Q25 */ - L_temp2 = Mult_32_16(L_temp,32768/320); /* step */ - FOR( ; jt_audio_prev_fx, pos, temp4); - st_fx->t_audio_prev_fx_exp[0] = add(Q_32_BITS, temp4); - move16(); - - /* attenuate HFs in case of band-width switching */ - IF( st_fx->bws_cnt1_fx > 0 ) - { - temp = i_mult(st_fx->bws_cnt1_fx, 1638); /*Q15*/ - - j = 2*END_FREQ_BWE_FULL_FB/50 - NUM_NONTRANS_START_FREQ_COEF; - move16(); - if( output_frame == L_FRAME32k ) - { - j = L_FRAME32k - NUM_NONTRANS_START_FREQ_COEF; - move16(); - } - - FOR( i=0; iprev_ener_shb_fx = extract_h(L_shr(L_mult0(32767, env), 7)); - } - ELSE - { - st_fx->prev_ener_shb_fx = extract_h(L_shr(L_mult0(gain_fx, env), 7)); - } - FOR(i=0; iprev_SWB_fenv_fx[i] = st_fx->prev_ener_shb_fx; - move16(); - } - - /*---------------------------------------------------------------------* - * iOLA and iMDCT - *---------------------------------------------------------------------*/ - - t_audio_exp = Q_32_BITS; - - Inverse_Transform( t_audio32, &t_audio_exp, t_audio32_tmp, is_transient, output_frame, output_frame ); - - window_ola_fx( t_audio32_tmp, hb_synth_fx, &t_audio_exp, st_fx->L_old_wtda_swb_fx, &st_fx->Q_old_wtda, output_frame, - ALDO_WINDOW, ALDO_WINDOW, 0,0,0); - - hb_synth_fx_exp = t_audio_exp; - move16(); - - /*---------------------------------------------------------------------* - * final adjustments - *---------------------------------------------------------------------*/ - - IF( !st_fx->bfi_fx ) - { - IsTransient = 0; - move16(); - L_EnergyLT = L_add(st_fx->L_mem_EnergyLT_fx, 0); - temp4 = st_fx->mem_EnergyLT_fx_exp; - move16(); - pos = 0; - move16(); - - ptr16 = hb_synth_fx; - move16(); - - len = shr(output_frame, 2); /* Divide Frame Len by 4, all (160, 320, 640, 960) are divisible by 4 */ - L_ener_all = L_deposit_l(0); - ener_all_exp = 40; - move16(); /* set to a high exponent */ - - FOR( j=0; j<4; j++ ) - { - L_Energy = Calc_Energy_Autoscaled(ptr16, hb_synth_fx_exp, len, &temp2); - ptr16 += len; - move16(); - /* Normalize Energy */ - temp = norm_l(L_Energy); - L_Energy = L_shl(L_Energy, temp); - /* Update Exponent of 'L_Energy' */ - temp2 = add(temp2, temp); - - /* Normalize Long Term Energy */ - temp = norm_l(L_EnergyLT); - L_EnergyLT = L_shl(L_EnergyLT, temp); - /* Calculate Exponent of Long Term Energy */ - temp = add(temp, temp4); - - /* Divide by 12.5 */ - L_temp = Mult_32_16(L_Energy, 20972); /* 20972 = 1/12.5*32768*8 (*8 to boost precision) */ - temp3 = norm_l(L_temp); - L_temp = L_shl(L_temp, temp3); - temp3 = add(add(temp2, temp3), 3); - /* Energies are Strictly Positive Values and Normalized - (compare exponent and value only if exponent is same) */ - /* Replaces: 'if (Energy_flt > 12.5f * EnergyLT_flt )' */ - temp3 = sub(temp3, temp); - test(); - test(); - IF (temp3 < 0 || (L_sub(L_temp, L_EnergyLT) > 0 && temp3 == 0)) - { - IsTransient = 1; - move16(); - pos = j; - move16(); - L_ener_saved = L_add(L_ener_all, 0); - ener_saved_exp = ener_all_exp; - move16(); - } - - L_ener_all = Add_flt32_flt32(L_Energy, temp2, L_ener_all, ener_all_exp, &ener_all_exp); - /* 0.25f*Energy_flt */ - temp2 = add(temp2, 2); - /* 0.75f*EnergyLT_flt */ - L_EnergyLT = L_sub(L_EnergyLT, L_shr(L_EnergyLT, 2)); - /* Exponent of 'L_EnergyLT' is 'temp' */ - /* Exponent of 'L_Energy' is 'temp2' */ - /* EnergyLT = 0.75f*EnergyLT + 0.25f*Energy */ - L_EnergyLT = Add_flt32_flt32(L_Energy, temp2, L_EnergyLT, temp, &temp4); - } - - test(); - test(); - test(); - IF( IsTransient != 0 && pos > 0 && L_sub(L_tilt_wb, 16777216L*3/*tilt_wb in Q24*/) < 0 && sub(pitch, 500*16/*Q4*/) > 0 ) - { - Nsv = i_mult2(pos, shr(output_frame, 2)); - - gain_fx = 16384; /* sqrt(1.0) in Q14 */ - /* pos is 1,2 or 3 */ - temp3 = sub(pos, 2); - if (temp3 == 0) - { - gain_fx = 23170; - move16(); /* sqrt(2.0) in Q14 */ - } - - if (temp3 > 0) - { - gain_fx = 28378; - move16(); /* sqrt(3.0) in Q14 */ - } - exp1 = 14; - move16(); - - IF( sub(st_fx->last_extl_fx, st_fx->extl_fx) == 0 ) - { - L_temp = Div_flt32_flt32( L_ener_saved, ener_saved_exp, st_fx->L_mem_EnergyLT_fx, st_fx->mem_EnergyLT_fx_exp, &temp2 ); - temp3 = sub(temp2, 1); - L_temp2 = Isqrt_lc(L_temp, &temp3); - temp3 = sub(sub(30+31-15+1, temp2), temp3); - - L_temp = Mult_32_16(L_temp2, gain_fx); - temp = norm_l(L_temp); - L_temp2 = L_shl(L_temp, temp); - gain_fx = round_fx(L_temp2); - exp1 = sub(add(temp3, temp), sub(31, exp1)); /* gain_fx is in Q14 */ - } - - L_temp = L_mult0(26214, gain_fx); - /* +16: Because 26214 is 0.2 in Q16 - * -16: Because of round_fx - * -15: To get exponent with ref to Q15 - * +1: Because of L_mult'0' - * and the normalization - */ - exp2 = add(exp1, +16-16-15+1); - temp = norm_l(L_temp); - L_temp = L_shl(L_temp, temp); - exp2 = add(exp2, temp); - temp = round_fx(L_temp); /* Gain is in Q15+x */ - FOR( i=0; i>(19-15+1)); /* 19-15+1 to Bring to Q30 */ - FOR ( i = 0; i < len; i++ ) - { - /* hb_synth[i+Nsv] *= (gain_flt - i*8.0f*(1.0f/output_frame*gain_flt - 1.0f/output_frame)) */ - *ptr16 = round_fx(L_shl(Mult_32_16(L_temp, *ptr16), 1)); - ptr16++; - L_temp = L_sub(L_temp, L_temp2); - } - } - - st_fx->L_mem_EnergyLT_fx = L_EnergyLT; - move32(); - st_fx->mem_EnergyLT_fx_exp = temp4; - move16(); - st_fx->old_is_transient_hr_bwe_fx = is_transient; - move16(); - } - - /* post-processing in case of TD/FD switching */ - test(); - IF( sub(st_fx->last_core_fx, HQ_CORE) == 0 || sub(st_fx->last_extl_fx, st_fx->extl_fx) != 0 ) - { - IF( L_sub(L_tilt_wb, 16777216L*3/*tilt_wb in Q24*/) < 0 ) - { - temp = TD_Postprocess( hb_synth_fx, hb_synth_fx_exp, output_frame, st_fx->last_extl_fx ); - - FOR( i=0; iL_old_wtda_swb_fx[i] = mult_r(st_fx->L_old_wtda_swb_fx[i], temp); - move16(); - } - - tmpS = L_FRAME32k - NUM_NONTRANS_START_FREQ_COEF; - move16(); - if( sub(output_frame,L_FRAME48k) == 0 ) - { - tmpS = 2*END_FREQ_BWE_FULL_FB/50 - NUM_NONTRANS_START_FREQ_COEF; - move16(); - } - - FOR( i=0; it_audio_prev_fx[i] = mult_r(st_fx->t_audio_prev_fx[i], temp); - move16(); - } - } - } - - return hb_synth_fx_exp; -} diff --git a/src/libs/libevs/lib_dec/swb_bwe_dec_lr.cpp b/src/libs/libevs/lib_dec/swb_bwe_dec_lr.cpp new file mode 100644 index 00000000..83948752 --- /dev/null +++ b/src/libs/libevs/lib_dec/swb_bwe_dec_lr.cpp @@ -0,0 +1,279 @@ +/*==================================================================================== + EVS Codec 3GPP TS26.443 Nov 13, 2018. Version 12.11.0 / 13.7.0 / 14.3.0 / 15.1.0 + ====================================================================================*/ + +#include +#include "options.h" +#include "cnst.h" +#include "prot.h" +#include "rom_com.h" +#include "stat_com.h" + + + +/*-------------------------------------------------------------------* + * DecodeSWBGenericParameters() + * + * Decoding of generic subband coding parameters + *-------------------------------------------------------------------*/ + +static void DecodeSWBGenericParameters( + Decoder_State *st, /* i/o: decoder state structure */ + short *lagIndices, /* o : lowband index for each subband */ + const short nBands_search, /* i : number of subbnads for SSearch */ + const short BANDS, /* i : total number of subbands per frame */ + const short *p2a_flags, /* i : HF tonal flag */ + const short hq_swb_clas /* i : mode of operation HQ_NORMAL or HQ_HARMONIC */ +) +{ + short sb; + + /* lag index for each subband (except last two) */ + for (sb = 0; sb < nBands_search; sb++) + { + if( hq_swb_clas == HQ_HARMONIC ) + { + lagIndices[sb] = (short)get_next_indice( st, bits_lagIndices_mode0_Har[sb]); + } + else + { + if( p2a_flags[BANDS-NB_SWB_SUBBANDS+sb] == 0 ) + { + lagIndices[sb] = (short)get_next_indice( st, bits_lagIndices_modeNormal[sb] ); + } + else + { + lagIndices[sb] = 0; + } + } + } + + return; +} + + +/*-------------------------------------------------------------------* + * DecodeSWBSubbands() + * + * Main routine for generic SWB coding + * + * High-frequency subbands are replicated based on the lowband signal using a lowband index denoting + * the selected lowband subband as well as linear and logarithmic domain gains + *-------------------------------------------------------------------*/ + +static void DecodeSWBSubbands( + Decoder_State *st, /* i/o: decoder state structure */ + float *spectra, /* i/o: MDCT domain spectrum */ + const short fLenLow, /* i : lowband length */ + const short fLenHigh, /* i : highband length */ + const short nBands, /* i : number of subbands */ + const short *sbWidth, /* i : subband lengths */ + short *lagIndices, + float *lagGains, /* i : first gain for each subband */ + short BANDS, /* i : number subbands per frame */ + short *band_start, /* i : band start of each SB */ + short *band_end, /* i : band end of each SB */ + float *band_energy, /* i : band energy of each SB */ + short *p2a_flags, /* i : HF tonal indicator */ + const short hqswb_clas, /* i : class information */ + const short har_bands, /* i : number of LF harmonic bands */ + const short *subband_search_offset, + short *prev_frm_hfe2, + short *prev_stab_hfe2, + short band_width[], /* i : subband band widths */ + const short *subband_offsets, /* i : subband offsets for sparse filling */ + const float spectra_ni[], /* i : core coder with sparseness filled */ + short *ni_seed /* i/o: random seed for search buffer NI */ +) +{ + short i; + short k; + float sspectra[L_FRAME32k]; + float sspectra_ni[L_FRAME32k],sspectra_diff[L_FRAME32k], th_g[NB_SWB_SUBBANDS]; + float ss_min=1.0f,g ,be_tonal[SWB_HAR_RAN1], xSynth_har[L_FRAME32k]; + GainItem pk_sf[(NB_SWB_SUBBANDS)*8]; + short lagIndices_real[NB_SWB_SUBBANDS]; + short pul_res[NB_SWB_SUBBANDS],cnt,imin; + short har_freq_est1 = 0; + short har_freq_est2 = 0; + short flag_dis = 1; + short pos_max_hfe2=0; + + set_s(pul_res,0,NB_SWB_SUBBANDS); + set_f( xSynth_har, 0.0f, fLenHigh ); + + + if( hqswb_clas == HQ_HARMONIC ) + { + /* Harmonic Structure analysis */ + pos_max_hfe2 = har_est( spectra, fLenLow, &har_freq_est1, &har_freq_est2, &flag_dis, prev_frm_hfe2, subband_search_offset, sbWidth, prev_stab_hfe2 ); + /* Spectrum normalization for the corecoder */ + noise_extr_corcod( spectra, spectra_ni, sspectra, sspectra_diff, sspectra_ni, fLenLow, st->prev_hqswb_clas, &st->prev_ni_ratio ); + /* Harmonic Structure analysis */ + + if(flag_dis == 0) + { + if(har_freq_est2 != SWB_HAR_RAN1 || har_freq_est2 != *prev_frm_hfe2) + { + har_freq_est2 +=lagIndices[0]; + } + } + /*Generate HF noise*/ + genhf_noise( sspectra_diff, xSynth_har, sspectra, BANDS, har_bands, har_freq_est2, pos_max_hfe2,pul_res,pk_sf,fLenLow, + fLenHigh, sbWidth, lagIndices, subband_offsets, subband_search_offset ); + + imin =(short) get_next_indice( st, 2); + g = (float)pow( 10.0f, gain_table_SWB_BWE[imin] ); + /* tonal energy estimation*/ + ton_ene_est( xSynth_har, be_tonal, band_energy, band_start, band_end, band_width, fLenLow, fLenHigh, BANDS, har_bands, g, pk_sf, pul_res ); + + /*HF Spectrum Generation*/ + Gettonl_scalfact( xSynth_har, spectra_ni, fLenLow, fLenHigh, har_bands, BANDS, band_energy, band_start, band_end, p2a_flags, be_tonal, pk_sf, pul_res); + if(flag_dis == 0) + { + *prev_frm_hfe2 = 0; + } + else + { + *prev_frm_hfe2 = har_freq_est2; + } + + for( k = har_bands; kprev_En_sb, p2a_flags, BANDS, band_start, band_end, fLenLow ); + /* xSynth is the reconstructed high-band */ + for( k = BANDS-NB_SWB_SUBBANDS; kprev_hqswb_clas_fx, &(st_fx->prev_ni_ratio_fx), &Qss); - IF( flag_dis == 0 ) - { - test(); - if( sub(har_freq_est2, SWB_HAR_RAN1) != 0 || sub(har_freq_est2, *prev_frm_hfe2_fx) != 0 ) - { - har_freq_est2 = add(har_freq_est2, lagIndices_fx[0]); - } - } - - /* Generate HF noise */ - genhf_noise_fx(sspectra_diff_fx, Qss, L_xSynth_har, QsL, sspectra_fx, BANDS_fx, har_bands_fx, har_freq_est2, pos_max_hfe2, pul_res_fx, pk_sf_fx, fLenLow_fx, fLenHigh_fx, sbWidth_fx, lagIndices_fx, subband_offsets_fx, subband_search_offset_fx); - - imin_fx = get_next_indice_fx(st_fx, 2); - move16(); - /* g= pow(10.0f, gain_table_SWB_BWE[imin]) */ - L_temp = L_mult(gain_table_SWB_BWE_fx[imin_fx], 27213); /* Q14+Q13+1=Q28 log(10)/log(2)=3.3219 27213.23(Q13) */ - L_temp = L_shr(L_temp, 12); /* Q28-Q12 -> Q16 */ - temp_lo_fx = L_Extract_lc(L_temp, &temp_hi_fx); - Qg = sub(14, temp_hi_fx); - g_fx = extract_l(Pow2(14, temp_lo_fx)); - g_fx = shl(g_fx, sub(11, Qg)); - - /* tonal energy estimation */ - ton_ene_est_fx( - L_xSynth_har, QsL, L_be_tonal, &QbeL, L_band_energy, Qbe, - band_start_fx, band_end_fx, band_width_fx, fLenLow_fx, fLenHigh_fx, - BANDS_fx, har_bands_fx, g_fx, pk_sf_fx, Qss, pul_res_fx - ); - - /*HF Spectrum Generation*/ - Gettonl_scalfact_fx( - L_xSynth_har, QsL, L_spectra_ni, fLenLow_fx, fLenHigh_fx, har_bands_fx, BANDS_fx, L_band_energy, Qbe, band_start_fx, band_end_fx, - p2a_flags_fx, L_be_tonal, QbeL, pk_sf_fx ,Qss, pul_res_fx); - - IF( flag_dis == 0 ) - { - *prev_frm_hfe2_fx = 0; - move16(); - } - ELSE - { - *prev_frm_hfe2_fx = har_freq_est2; - move16(); - } - - FOR( k = har_bands_fx; k < BANDS_fx; k++ ) - { - FOR( i = band_start_fx[k]; i <= band_end_fx[k]; i++ ) - { - L_spectra[i] = L_xSynth_har[i-fLenLow_fx]; - move32(); /* QsL */ - } - } - } - ELSE IF ( sub(hqswb_clas_fx, HQ_NORMAL) == 0 ) - { - ss_min_fx = spectrumsmooth_noiseton_fx( - L_spectra, /*QsL,*/ L_spectra_ni, sspectra_fx, sspectra_diff_fx, sspectra_ni_fx, &Qss, fLenLow_fx, ni_seed_fx); - - convert_lagIndices_pls2smp_fx( lagIndices_fx, nBands_fx, lagIndices_real_fx, sspectra_fx, sbWidth_fx, fLenLow_fx ); - FOR (k = 0; k < nBands_fx; k++) - { - if ( sub(p2a_flags_fx[BANDS_fx-NB_SWB_SUBBANDS+k], 1) == 0 ) - { - lagIndices_real_fx[k] = 0; - move16(); - } - } - - GetlagGains_fx( sspectra_ni_fx, Qss, - &L_band_energy[BANDS_fx-NB_SWB_SUBBANDS], Qbe, - nBands_fx, sbWidth_fx, lagIndices_real_fx, fLenLow_fx, lagGains_fx, QlagGains ); - - FOR(k=0; k Qs */ - } - } - - /* Construct spectrum */ - GetSynthesizedSpecThinOut_fx( - sspectra_ni_fx, Qss, L_xSynth_har, QsL, nBands_fx, sbWidth_fx, - lagIndices_real_fx, lagGains_fx, QlagGains, fLenLow_fx - ); - - /* Level adjustment for the missing bands */ - noiseinj_hf_fx( - L_xSynth_har, QsL, L_th_g, L_band_energy, Qbe, st_fx->prev_En_sb_fx, - p2a_flags_fx, BANDS_fx, band_start_fx, band_end_fx, fLenLow_fx, fLenHigh_fx - ); - - FOR( k = sub(BANDS_fx, NB_SWB_SUBBANDS); k < BANDS_fx; k++ ) - { - IF( p2a_flags_fx[k] == 0 ) - { - FOR( i = band_start_fx[k]; i <= band_end_fx[k]; i++ ) - { - L_spectra[i] = L_xSynth_har[i-fLenLow_fx]; - move32(); /* QsL */ - } - } - ELSE - { - FOR( i = band_start_fx[k]; i <= band_end_fx[k]; i++ ) - { - L_spectra[i] = L_spectra_ni[i]; - move32(); - } - } - } - } - - return; -} - -/*-------------------------------------------------------------------* - * swb_bwe_dec_lr() - * - * Main decoding routine of SWB BWE for the LR MDCT core - *-------------------------------------------------------------------*/ -void swb_bwe_dec_lr_fx( - Decoder_State_fx *st_fx, /* i/o: decoder state structure */ - const Word32 L_m_core[], /* i : lowband synthesis */ - const Word16 QsL, /* i : Q value of m_core */ - Word32 L_m[], /* o : highband synthesis with lowband zeroed */ - const Word32 L_total_brate, /* i : total bitrate for selecting subband pattern */ - Word16 BANDS_fx, /* i : Number subbands/Frame */ - Word16 *band_start_fx, /* i : Band Start of each SB */ - Word16 *band_end_fx, /* i : Band end of each SB */ - Word32 *L_band_energy, /* i : Band energy of each SB : Qbe */ - Word16 Qbe, /* i : Q value of band energy */ - Word16 *p2a_flags_fx, /* i : HF tonal Indicator */ - const Word16 hqswb_clas_fx, /* i : class information */ - Word16 lowlength_fx, /* i : Lowband Length */ - Word16 highlength_fx, /* i : Highband Length */ - const Word16 har_bands_fx, /* i : Number of LF harmonic bands */ - Word16 *prev_frm_hfe2_fx, /* i/o: */ - Word16 *prev_stab_hfe2_fx, /* i/o: */ - Word16 band_width_fx[], /* i : subband bandwidth */ - const Word32 L_y2_ni[], /* i/o: Sparse filled corecoder */ - Word16 *ni_seed_fx /* i/o: random seed */ -) -{ - Word16 k; - Word16 nBands_fx; - Word16 nBands_search_fx; - Word16 wBands_fx[NB_SWB_SUBBANDS]; - Word16 lagIndices_fx[NB_SWB_SUBBANDS]; - Word16 lagGains_fx[NB_SWB_SUBBANDS]; - Word16 QlagGains[NB_SWB_SUBBANDS]; - Word16 swb_lowband_fx, swb_highband_fx, allband_fx; - - const Word16 *subband_offsets_fx; - const Word16 *subband_search_offset_fx; - - Word32 *p_L_m; - - subband_search_offset_fx = subband_search_offsets_13p2kbps_Har_fx; - subband_offsets_fx = subband_offsets_sub5_13p2kbps_Har_fx; - - hf_parinitiz_fx(L_total_brate,hqswb_clas_fx,lowlength_fx,highlength_fx,wBands_fx,&subband_search_offset_fx,&subband_offsets_fx,&nBands_fx,&nBands_search_fx,&swb_lowband_fx,&swb_highband_fx); - allband_fx = add(swb_lowband_fx, swb_highband_fx); - move16(); - - /* Decoding of the SWB parameters */ - DecodeSWBGenericParameters_fx( st_fx, lagIndices_fx, nBands_search_fx, BANDS_fx, p2a_flags_fx, hqswb_clas_fx ); - - /* Copy WB synthesis for SWB decoding */ - Copy32( L_m_core, L_m, swb_lowband_fx + swb_highband_fx ); - - /* Generic subband processing */ - DecodeSWBSubbands_fx( - st_fx, - L_m, QsL, - swb_lowband_fx, swb_highband_fx, nBands_fx, wBands_fx, subband_offsets_fx, - lagIndices_fx, lagGains_fx, QlagGains, - BANDS_fx, band_start_fx, band_end_fx, - L_band_energy, Qbe, - p2a_flags_fx, hqswb_clas_fx, har_bands_fx, subband_search_offset_fx, - prev_frm_hfe2_fx, prev_stab_hfe2_fx, band_width_fx, L_y2_ni, ni_seed_fx - ); - - p_L_m = &L_m[sub(allband_fx, 1)]; - *p_L_m = Mult_32_16(*p_L_m, 2028); - move32(); - p_L_m--; /* 0.0625 = 2028 (Q15) */ - *p_L_m = Mult_32_16(*p_L_m, 4096); - move32(); - p_L_m--; /* 0.125 = 4096 (Q15) */ - *p_L_m = Mult_32_16(*p_L_m, 8192); - move32(); - p_L_m--; /* 0.25 = 8192 (Q15) */ - *p_L_m = Mult_32_16(*p_L_m, 16384); - move32(); - p_L_m--; /* 0.5 = 16384 (Q15) */ - - /* set low frequencies to zero */ - FOR ( k = 0; k < swb_lowband_fx; k++ ) - { - L_m[k] = L_deposit_l(0); - } - - return; -} diff --git a/src/libs/libevs/lib_dec/swb_tbe_dec.cpp b/src/libs/libevs/lib_dec/swb_tbe_dec.cpp new file mode 100644 index 00000000..f90b010d --- /dev/null +++ b/src/libs/libevs/lib_dec/swb_tbe_dec.cpp @@ -0,0 +1,1963 @@ +/*==================================================================================== + EVS Codec 3GPP TS26.443 Nov 13, 2018. Version 12.11.0 / 13.7.0 / 14.3.0 / 15.1.0 + ====================================================================================*/ + +#include +#include +#include "options.h" +#include "cnst.h" +#include "prot.h" +#include "rom_com.h" +#include "rom_dec.h" + +/*-----------------------------------------------------------------* + * Local functions + *-----------------------------------------------------------------*/ + +static void dequantizeSHBparams( Decoder_State *st, const short extl, long extl_brate, float *Q_lsf, float *Q_subgain, + float *Q_framegrain, short *uv_flag, float *Q_shb_ener_sf, float *Q_shb_res_gshape, float *Q_mixFactors ); +static void Dequant_lower_LSF( const short lsf_idx[], float lsf_q[] ); +static void Map_higher_LSF(float lsf_q[], const float m, const float grid_in[]); +static void Dequant_mirror_point(const float lsf_q[], const short m_idx, float *m); + +void InitSWBdecBuffer( + Decoder_State *st /* i/o: SHB decoder structure */ +) +{ + set_f(st->old_bwe_exc, 0.0f, (PIT16k_MAX * 2)); + st->bwe_seed[0] = 23; /* 1; */ + st->bwe_seed[1] = 59; /* 10000; */ + set_f( st->old_bwe_exc_extended, 0.0f, NL_BUFF_OFFSET ); + st->bwe_non_lin_prev_scale = 0; + st->last_voice_factor = 0.0f; + + set_f(st->genSHBsynth_Hilbert_Mem, 0.0f,HILBERT_MEM_SIZE); + set_f(st->genSHBsynth_state_lsyn_filt_shb_local, 0.0f,2 * ALLPASSSECTIONS_STEEP); + + st->syn_dm_phase = 0; + st->prev_fbbwe_ratio = 1.0f; + st->prev_wb_bwe_frame_pow = 0.001f; + st->prev_swb_bwe_frame_pow = 0.001f; + st->prev_fb_ener_adjust = 0.0f; + + return; +} + +void ResetSHBbuffer_Dec( + Decoder_State *st /* i/o: SHB encoder structure */ +) +{ + short i; + float f; + float inc; + + if ( st->extl != WB_TBE ) + { + f = 1.0f/22.0f; + inc = 1.0f/22.0f; + } + else + { + f = 1.0f/6.0f; + inc = 1.0f/6.0f; + } + + /* states for the filters used in generating SHB excitation from WB excitation*/ + set_f(st->mem_csfilt,0,2); + + /* states for the filters used in generating SHB signal from SHB excitation*/ + set_f(st->state_syn_shbexc,0,L_SHB_LAHEAD); + set_f( st->state_lpc_syn, 0, LPC_SHB_ORDER); + if( sub(st->extl, FB_TBE) == 0 ) + { + set_f( st->fb_state_lpc_syn, 0, LPC_SHB_ORDER ); + st->fb_tbe_demph = 0; + fb_tbe_reset_synth( st->fbbwe_hpf_mem,&st->prev_fbbwe_ratio); + } + /* states for the filters used in generating SHB signal from SHB excitation in wideband*/ + set_f( st->mem_genSHBexc_filt_down_shb, 0.0f, (2*ALLPASSSECTIONS_STEEP+1) ); + set_f( st->mem_genSHBexc_filt_down_wb2, 0.0f, (2*ALLPASSSECTIONS_STEEP+1) ); + set_f( st->mem_genSHBexc_filt_down_wb3, 0.0f, (2*ALLPASSSECTIONS_STEEP+1) ); + + set_f( st->state_lsyn_filt_shb,0, 2 * ALLPASSSECTIONS_STEEP ); + set_f( st->state_lsyn_filt_dwn_shb,0, 2 * ALLPASSSECTIONS_STEEP ); + set_f( st->mem_resamp_HB, 0, INTERP_3_1_MEM_LEN ); + + /* States for the local synthesis filters */ + set_f(st->syn_overlap,0,L_SHB_LAHEAD); + + /* States for FEC */ + if ( st->extl != WB_TBE ) + { + for (i=0; ilsp_prevfrm[i] = f; + f += inc; + } + } + else + { + for (i=0; ilsp_prevfrm[i] = f; + f += inc; + } + } + + st->GainFrame_prevfrm = 0.0f; + st->GainAttn = 1.0; + st->tbe_demph = 0.0f; + st->tbe_premph = 0.0f; + set_f(st->mem_stp_swb, 0, LPC_SHB_ORDER); + st->gain_prec_swb = 1.0f; + set_f( &st->GainShape_Delay[0], 0, NUM_SHB_SUBFR/2 ); + + set_f(st->old_core_synth, 0, L_FRAME16k); + set_f(st->old_tbe_synth, 0, L_SHB_TRANSITION_LENGTH); + st->tilt_swb_fec = 0.0f; + + return; +} + +/*-------------------------------------------------------------------* + * wb_tbe_dec() + * + * WB TBE decoder, 6 - 8 kHz band decoding module + *-------------------------------------------------------------------*/ + +void wb_tbe_dec( + Decoder_State *st, /* i/o: decoder state structure */ + const short coder_type, /* i : coding type */ + const float *bwe_exc_extended,/* i : bandwidth extended excitation */ + const float voice_factors[], /* i : voicing factors */ + float *synth /* o : WB synthesis/final synthesis */ +) +{ + short i; + float shaped_wb_excitation [ (L_FRAME16k + L_SHB_LAHEAD)/4 ]; + float exc4kWhtnd [L_FRAME16k / 4]; + float lsf_wb[LPC_SHB_ORDER_WB], lpc_wb[LPC_SHB_ORDER_WB + 1], GainShape[NUM_SHB_SUBFR], GainFrame ; + float error[L_FRAME16k]; + float upsampled_synth[L_FRAME48k]; + float prev_pow, curr_pow, scale; + float temp, curr_frame_pow; + short j; + float vf_modified[NB_SUBFR16k]; + short uv_flag = 0; + + if( st->bws_cnt == 0 ) + { + + if( !st->bfi ) + { + if( st->use_partial_copy ) + { + if(st->last_extl != WB_TBE) + { + st->GainFrame_prevfrm = 0; + st->lsp_prevfrm[0] = 0.1f; + for (i=1; ilsp_prevfrm[i] = st->lsp_prevfrm[i-i] + 0.1f; + } + } + + mvr2r( st->lsp_prevfrm, lsf_wb, LPC_SHB_ORDER_LBR_WB ); + set_f( GainShape, RECIP_ROOT_EIGHT, NUM_SHB_SUBFR/2 ); + + if( st->rf_frame_type == RF_NELP ) + { + /* Frame gain */ + /* only four LSBs are valid */ + st->rf_indx_tbeGainFr &= 0xF; + mvr2r( SHBCB_FrameGain16 + st->rf_indx_tbeGainFr, &GainFrame, 1 ); + if( st->core == ACELP_CORE && st->last_core == ACELP_CORE && !st->prev_use_partial_copy && st->prev_coder_type == UNVOICED && GainFrame != st->GainFrame_prevfrm && st->last_extl == WB_TBE) + { + GainFrame = 0.2f*GainFrame + 0.8f*st->GainFrame_prevfrm; + } + } + else + { + /* Frame gain */ + temp = 0.0f; + switch (st->rf_indx_tbeGainFr) + { + case 0: + GainFrame = 0.5f; + if(st->GainFrame_prevfrm <= 1.25) temp = 0.8f; + break; + case 1: + GainFrame = 2.0f; + if(st->GainFrame_prevfrm > 1.25 && st->GainFrame_prevfrm <= 3) temp = 0.8f; + break; + case 2: + GainFrame = 4.0f; + if(st->GainFrame_prevfrm > 3 && st->GainFrame_prevfrm <= 6) temp = 0.8f; + break; + case 3: + GainFrame = 8.0f; + if(st->GainFrame_prevfrm > 6 && st->GainFrame_prevfrm <= 16) temp = 0.8f; + break; + default: + GainFrame = 1.0f; + fprintf(stderr, "RF WB-TBE gain bits not supported."); + break; + } + + if(st->last_extl == WB_TBE) + { + GainFrame = (1 - temp)*GainFrame + temp*(st->GainFrame_prevfrm); + } + + if (st->core == ACELP_CORE && st->last_core == ACELP_CORE) + { + if (!st->prev_use_partial_copy && st->last_coder_type == VOICED && st->rf_frame_type == RF_GENPRED + && st->prev_tilt_code_dec < 0.046f && st->prev_tilt_code_dec > 0.006f ) + { + GainFrame *= 0.3f; + } + } + } + } + else + { + /* de-quantization */ + dequantizeSHBparams( st, st->extl, st->extl_brate, lsf_wb, GainShape, &GainFrame, &uv_flag, 0, 0, 0 ); + } + } + else + { + if ( st->extl_brate == WB_TBE_0k35 ) + { + mvr2r( st->lsp_prevfrm, lsf_wb, LPC_SHB_ORDER_LBR_WB ); + } + else + { + mvr2r( st->lsp_prevfrm, lsf_wb, LPC_SHB_ORDER_WB ); + } + set_f( GainShape, RECIP_ROOT_EIGHT, NUM_SHB_SUBFR/2 ); + st->GainAttn *= 0.85f; + if( st->codec_mode == MODE1 ) + { + GainFrame = st->GainAttn * st->GainFrame_prevfrm; + } + else + { + GainFrame = st->GainFrame_prevfrm; + } + } + + if ( st->extl_brate == WB_TBE_0k35 ) + { + /* convert LSPs back into LP coeffs */ + lsp2a( lpc_wb, lsf_wb, LPC_SHB_ORDER_LBR_WB ); + set_f( lpc_wb + LPC_SHB_ORDER_LBR_WB+1, 0.0f, (LPC_SHB_ORDER_WB - LPC_SHB_ORDER_LBR_WB) ); + } + else + { + /* convert LSPs back into LP coeffs */ + lsp2a( lpc_wb, lsf_wb, LPC_SHB_ORDER_WB ); + } + lpc_wb[0] = 1.0f; + mvr2r( voice_factors, vf_modified, NB_SUBFR16k ); + if( coder_type == VOICED ) + { + for (i = 1; i < NB_SUBFR; i++) + { + vf_modified[i] = 0.8f * voice_factors[i] + 0.2f * voice_factors[i-1]; + } + + if(st->L_frame != L_FRAME ) + { + vf_modified[4] = 0.8f * voice_factors[4] + 0.2f * voice_factors[3]; + } + } + + if(st->use_partial_copy && st->nelp_mode_dec) + { + set_f( vf_modified, 0.0f, NB_SUBFR16k ); + } + + /* From low band excitation, generate highband excitation */ + mvr2r( st->state_syn_shbexc, shaped_wb_excitation, L_SHB_LAHEAD / 4); + + GenShapedWBExcitation( shaped_wb_excitation+ L_SHB_LAHEAD / 4, lpc_wb, exc4kWhtnd, st->mem_csfilt, st->mem_genSHBexc_filt_down_shb, + st->mem_genSHBexc_filt_down_wb2, st->mem_genSHBexc_filt_down_wb3, st->state_lpc_syn, coder_type, + bwe_exc_extended, st->bwe_seed, vf_modified, uv_flag, st->igf ); + + prev_pow = sum2_f( shaped_wb_excitation, L_SHB_LAHEAD/4 ); + curr_pow = sum2_f( shaped_wb_excitation + L_SHB_LAHEAD/4, L_SHB_LAHEAD/4 ); + + if( voice_factors[0] > 0.75f ) + { + curr_pow *= 0.25; + } + + if( prev_pow == 0 ) + { + scale = 0; + } + else + { + scale = sqrt(curr_pow / prev_pow); + } + for (i=0; istate_syn_shbexc, L_SHB_LAHEAD/4 ); + + /* Adjust the subframe and frame gain of the synthesized shb signal */ + /* Scale the shaped excitation */ + ScaleShapedSHB( SHB_OVERLAP_LEN/2, shaped_wb_excitation, st->syn_overlap, GainShape, GainFrame, window_wb, subwin_wb ); + + curr_frame_pow = sum2_f( shaped_wb_excitation, L_FRAME16k/4 ) + 0.001f; + + if( !st->bfi && (st->prev_bfi || st->prev_use_partial_copy) ) + { + if( curr_frame_pow > 2.0f * st->prev_wb_bwe_frame_pow ) + { + scale = root_a_over_b( st->prev_wb_bwe_frame_pow, curr_frame_pow ); + temp = (float) pow(scale, 0.125f); + } + else + { + scale = 1.0f; + temp = 1.0f; + } + + for( j=0; j<8; j++ ) + { + GainShape[2*j] *= scale; + GainShape[2*j+1] *= scale; + for( i=0; iprev_wb_bwe_frame_pow = curr_frame_pow; + + /* generate 16kHz SHB signal (6 - 8 kHz) from 2kHz signal */ + GenWBSynth( shaped_wb_excitation, error , st->state_lsyn_filt_shb, st->state_lsyn_filt_dwn_shb ); + + mvr2r( error + L_FRAME16k - L_SHB_TRANSITION_LENGTH, st->old_tbe_synth, L_SHB_TRANSITION_LENGTH ); + + for ( i=0; ilast_wb_bwe_ener = 0.0f; + for( i=0; ilast_wb_bwe_ener += synth[i]*synth[i]; + } + st->last_wb_bwe_ener = (float)sqrt(st->last_wb_bwe_ener/L_FRAME16k); + + if( st->output_Fs == 32000 ) /* 32kHz sampling rate, but only WB output - interpolate */ + { + Interpolate_allpass_steep( synth, st->mem_resamp_HB, L_FRAME16k, upsampled_synth ); + mvr2r( upsampled_synth, synth, L_FRAME32k ); + } + else if(st->output_Fs == 48000 ) + { + interpolate_3_over_1_allpass( synth, L_FRAME16k, upsampled_synth, st->mem_resamp_HB, allpass_poles_3_ov_2 ); + mvr2r( upsampled_synth, synth, L_FRAME48k ); + } + } + else + { + for ( i = 0; i < LPC_SHB_ORDER_WB; i++ ) + { + lsf_wb[i] = i/6; + } + GainFrame = 0; + + st->prev_wb_bwe_frame_pow = 0.001f; + } + + /* Update previous frame parameters for FEC */ + mvr2r( lsf_wb, st->lsp_prevfrm, LPC_SHB_ORDER_WB); + st->GainFrame_prevfrm = GainFrame; + + if( !st->bfi ) + { + st->GainAttn = 1.0f; + } + + return; +} + +/*-------------------------------------------------------------------* + * swb_tbe_dec() + * + * SWB TBE decoder, 6 - 14 kHz (or 7.5 - 15.5 kHz) band decoding module + *-------------------------------------------------------------------*/ + +void swb_tbe_dec( + Decoder_State *st, /* i/o: decoder state structure */ + const short coder_type, /* i : coding type */ + const float *bwe_exc_extended,/* i : bandwidth extended excitation */ + const float voice_factors[], /* i : voicing factors */ + const float old_syn_12k8_16k[],/*i : low band synthesis*/ + float *White_exc16k, /* o : shaped white excitation for the FB TBE */ + float *synth, /* o : SHB synthesis/final synthesis */ + float *pitch_buf +) +{ + short i, j; + short stemp; + float shaped_shb_excitation [ L_FRAME16k + L_SHB_LAHEAD ]; + float lsf_shb[LPC_SHB_ORDER], lpc_shb[LPC_SHB_ORDER + 1], GainShape[NUM_SHB_SUBFR], GainFrame; + float error[L_FRAME32k]; + float ener; + short is_fractive; + float prev_pow, curr_pow, scale; + float curr_frame_pow, temp; + float GainShapeTemp[NUM_SHB_SUBFR/4], GainGrad0[3], GainGrad1[3], GainGradFEC[4]; + float vf_modified[NB_SUBFR16k]; + float f, inc; + float GainFrame_prevfrm; + float tilt_swb_fec; + float prev_ener_ratio; + float lsp_shb_1[LPC_SHB_ORDER], lsp_shb_2[LPC_SHB_ORDER], lsp_temp[LPC_SHB_ORDER]; + float lpc_shb_sf[4*(LPC_SHB_ORDER+1)]; + const float *ptr_lsp_interp_coef; + float shb_ener_sf; + float shb_res_gshape[NB_SUBFR16k]; + float mixFactors; + short vind; + float shb_res_dummy[L_FRAME16k]; + float shaped_shb_excitationTemp[L_FRAME16k]; + float ener_tmp[NUM_SHB_SUBGAINS]; + float GainShape_tmp[NUM_SHB_SUBGAINS]; + float pitch; + short l_subframe; + float formant_fac; + float synth_scale; + float lsf_diff[LPC_SHB_ORDER], w[LPC_SHB_ORDER]; + float refl[M]; + float tilt_para; + + /* initializations */ + GainFrame = 0.0f; + mixFactors = 0.0f; + shb_ener_sf = 0.0f; + set_f( shaped_shb_excitationTemp, 0.0f, L_FRAME16k ); + st->shb_dtx_count = 0; + is_fractive = 0; + + /* find tilt */ + calc_tilt_bwe( old_syn_12k8_16k, &tilt_swb_fec, L_FRAME); + + if( st->bfi && st->clas_dec != UNVOICED_CLAS ) + { + tilt_swb_fec = st->tilt_swb_fec; + } + /* WB/SWB bandwidth switching */ + if( (st->tilt_wb > 5 && st->clas_dec == UNVOICED_CLAS) || st->tilt_wb > 10 ) + { + if( (st->prev_fractive == 0 + && st->prev_enerLH < 2.0f*st->enerLH && st->prev_enerLH > 0.5f*st->enerLH + && st->prev_enerLL < 2.0f*st->enerLL && st->prev_enerLL > 0.5f*st->enerLL ) + || (st->prev_fractive == 1 && st->prev_enerLH > 3.0f*st->enerLH) + || (st->enerLL > 1.5f*st->enerLH && st->tilt_wb < 10.0f) ) + { + is_fractive = 0; + } + else + { + is_fractive = 1; + } + } + + /* WB/SWB bandwidth switching */ + if( st->bws_cnt > 0 ) + { + f = 1.0f/22.0f; + inc = 1.0f/22.0f; + + if ( is_fractive == 1 ) + { + mvr2r(lsf_tab, st->lsp_prevfrm, LPC_SHB_ORDER); + } + else + { + for (i=0; ilsp_prevfrm[i] = f; + f += inc; + } + } + if( (st->last_extl != SWB_TBE && st->last_extl != FB_TBE && !(st->prev_enerLH < 2.0f*st->enerLH && st->prev_enerLH > 0.5f*st->enerLH)) + || st->last_core != ACELP_CORE || (st->last_core == ACELP_CORE && labs(st->last_core_brate - st->core_brate) > 3600) || (is_fractive ^ st->prev_fractive) == 1 ) + { + set_f( GainShape, 0.3536f, NUM_SHB_SUBFR ); + } + else + { + st->prev_GainShape = (st->prev_GainShape > 0.3536f) ? 0.353f : st->prev_GainShape; + set_f( GainShape, st->prev_GainShape, NUM_SHB_SUBFR ); + } + + /* this never happens */ + mvr2r( st->lsp_prevfrm, lsf_shb, LPC_SHB_ORDER ); + set_f( shb_res_gshape, 0.2f, NB_SUBFR16k ); + } + else + { + if ( st->last_extl != SWB_TBE && st->last_extl != FB_TBE ) + { + f = 1.0f/22.0f; + inc = 1.0f/22.0f; + for (i=0; ilsp_prevfrm[i] = f; + f += inc; + } + } + + if( !st->bfi ) + { + if( st->use_partial_copy ) + { + if(st->last_extl != SWB_TBE) + { + st->GainFrame_prevfrm = 0; + f = 1.0f/22.0f; + inc = 1.0f/22.0f; + for (i=0; ilsp_prevfrm[i] = f; + f += inc; + } + } + mvr2r( st->lsp_prevfrm, lsf_shb, LPC_SHB_ORDER ); + set_f( GainShape, RECIP_ROOT_EIGHT, NUM_SHB_SUBFR ); + + if( st->rf_frame_type == RF_NELP ) + { + /* Frame gain */ + GainFrame = usdequant(st->rf_indx_tbeGainFr, SHB_GAIN_QLOW, SHB_GAIN_QDELTA); + GainFrame = (float) pow(10.0, GainFrame); + if( st->core == ACELP_CORE && st->last_core == ACELP_CORE && !st->prev_use_partial_copy + && st->prev_coder_type == UNVOICED && GainFrame != st->GainFrame_prevfrm && st->next_coder_type != GENERIC && st->last_extl == SWB_TBE ) + { + GainFrame = 0.2f*GainFrame + 0.8f*st->GainFrame_prevfrm; + } + } + else + { + temp = 0.0f; + /* Frame gain */ + switch (st->rf_indx_tbeGainFr) + { + case 0: + GainFrame = 0.5f; + if(st->GainFrame_prevfrm <= 1.25) temp = 0.8f; + break; + case 1: + GainFrame = 2.0f; + if(st->GainFrame_prevfrm > 1.25 && st->GainFrame_prevfrm <= 3) temp = 0.8f; + break; + case 2: + GainFrame = 4.0f; + if(st->GainFrame_prevfrm > 3 && st->GainFrame_prevfrm <= 6) temp = 0.8f; + break; + case 3: + GainFrame = 8.0f; + if(st->GainFrame_prevfrm > 6 && st->GainFrame_prevfrm <= 16) temp = 0.8f; + break; + default: + fprintf(stderr, "RF SWB-TBE gain bits not supported."); + } + if(st->last_extl == SWB_TBE) + { + GainFrame = (1 - temp)*GainFrame + temp*(st->GainFrame_prevfrm); + } + + if( st->core == ACELP_CORE && st->last_core == ACELP_CORE ) + { + if( !st->prev_use_partial_copy && st->last_coder_type == VOICED && st->rf_frame_type == RF_GENPRED && GainFrame > 8.0f && GainFrame < 11.67f ) + { + GainFrame *= 0.3f; + } + } + } + } + else + { + /* de-quantization */ + dequantizeSHBparams( st, st->extl, st->extl_brate, lsf_shb, GainShape, &GainFrame, &stemp, &shb_ener_sf, shb_res_gshape, &mixFactors ); + } + } + else + { + mvr2r( st->lsp_prevfrm, lsf_shb, LPC_SHB_ORDER ); + + if( st->codec_mode == MODE1 ) + { + /* the previous frame gainshape gradient and the gainshape gradient pattern for the current frame */ + for(j=0; j<3; j++) + { + GainGrad0[j] = st->GainShape_Delay[j+1] - st->GainShape_Delay[j]; + GainGrad1[j] = st->GainShape_Delay[j+5] - st->GainShape_Delay[j+4]; + GainGradFEC[j+1] = GainGrad0[j]*0.4f + GainGrad1[j]*0.6f; + } + + /* gradient for the first gainshape */ + if( ( GainGrad1[2] > 2 * GainGrad1[1] && GainGrad1[1] > 2 * GainGrad1[0] ) || + ( GainGrad1[2] < 2 * GainGrad1[1] && GainGrad1[1] < 2 * GainGrad1[0] ) ) + { + GainGradFEC[0] = GainGrad1[1] * 0.1f + GainGrad1[2] * 0.9f; + } + else + { + GainGradFEC[0] = GainGrad1[0] * 0.2f + GainGrad1[1] * 0.3f + GainGrad1[2] * 0.5f; + } + + /* get the first gainshape template */ + if( (st->prev_coder_type == UNVOICED || st->last_good == UNVOICED_CLAS) && GainGradFEC[0] > 0 ) + { + GainShapeTemp[0] = st->GainShape_Delay[7] + GainGradFEC[0]; + } + else if( GainGradFEC[0] > 0 ) + { + GainShapeTemp[0] = st->GainShape_Delay[7] + GainGradFEC[0] * 0.5f; + } + else + { + GainShapeTemp[0] = st->GainShape_Delay[7]; + } + + /*Get the second the third and the fourth gainshape template*/ + if( ( GainGrad1[2] > 10.0f * GainGrad1[1] ) && GainGrad1[1] > 0 ) + { + for(i=1; i 10.0f * GainGrad1[1] ) && GainGrad1[1] < 0 ) + { + for( i=1; iprev_coder_type == UNVOICED || st->last_good == UNVOICED_CLAS) && st->nbLostCmpt == 1 ) + { + for( i=0; iGainAttn *= 0.95f; + } + else if( st->prev_coder_type == UNVOICED || st->last_good == UNVOICED_CLAS ) + { + for( i=0; iGainAttn *= 0.95f; + } + else if( st->nbLostCmpt > 1 ) + { + for( i=0; iGainAttn *= 0.5f; + } + else + { + for( i=0; iGainAttn *= 0.85f; + } + + GainFrame = st->GainAttn * st->GainFrame_prevfrm; + } + else + { + for( i=0; icummulative_damping * st->GainShape_Delay[4+i]; + } + } + + if( tilt_swb_fec > 8 ) + { + if( st->nbLostCmpt == 1 ) + { + GainFrame = 0.6* st->cummulative_damping * st->GainFrame_prevfrm; + } + else if( st->nbLostCmpt == 2 ) + { + GainFrame = 0.35* st->cummulative_damping * st->GainFrame_prevfrm; + } + else + { + GainFrame = 0.2* st->cummulative_damping * st->GainFrame_prevfrm; + } + } + else + { + GainFrame = st->GainFrame_prevfrm; /* gain locking */ + } + } + + if( st->total_brate == ACELP_24k40 || st->total_brate == ACELP_32k ) + { + if( st->codec_mode == MODE1 ) + { + scale = st->prev1_shb_ener_sf/sqrt((st->prev2_shb_ener_sf * st->prev3_shb_ener_sf) +0.0001); + scale = st->prev_res_shb_gshape * min(scale, 1.0f); + if(st->prev2_shb_ener_sf > 2.0f * st->prev1_shb_ener_sf || st->prev3_shb_ener_sf > 2.0f * st->prev2_shb_ener_sf) + { + shb_ener_sf = 0.5f * scale * st->prev1_shb_ener_sf; + if(st->nbLostCmpt > 1) + { + shb_ener_sf *= 0.5f; + } + } + else + { + shb_ener_sf = scale * scale * st->prev1_shb_ener_sf; + } + } + else + { + if( st->prev2_shb_ener_sf > 2.0f * st->prev1_shb_ener_sf || st->prev3_shb_ener_sf > 2.0f * st->prev2_shb_ener_sf ) + { + shb_ener_sf = 0.5f* st->cummulative_damping * st->prev1_shb_ener_sf; + } + else + { + shb_ener_sf = st->cummulative_damping * st->prev1_shb_ener_sf; + } + } + } + + shb_ener_sf = max(shb_ener_sf, 1.0f); + mixFactors = st->prev_mixFactors; + + if( st->codec_mode == MODE2 ) + { + set_f( shb_res_gshape, 1.0f, NB_SUBFR16k ); + } + else + { + set_f( shb_res_gshape, 0.2f, NB_SUBFR16k ); + } + } + } + + /* get the gainshape delay */ + mvr2r( &st->GainShape_Delay[4], &st->GainShape_Delay[0], NUM_SHB_SUBFR/4 ); + for( i = 0; iGainShape_Delay[i+4] = GainShape[i*4]; + } + + mvr2r( voice_factors, vf_modified, NB_SUBFR16k ); + if( coder_type == VOICED || mean(voice_factors, 4) > 0.4f ) + { + for( i = 1; i < NB_SUBFR; i++ ) + { + vf_modified[i] = 0.8f * voice_factors[i] + 0.2f * voice_factors[i-1]; + } + + if(st->L_frame != L_FRAME ) + { + vf_modified[4] = 0.8f * voice_factors[4] + 0.2f * voice_factors[3]; + } + + } + + if(st->use_partial_copy && st->nelp_mode_dec) + { + set_f( vf_modified, 0.0f, NB_SUBFR16k ); + } + + /* SHB LSF from current frame; and convert to LSP for interpolation */ + lsf2lsp( lsf_shb, lsp_shb_2, LPC_SHB_ORDER, 1.0f ); + + if( st->last_extl == SWB_TBE || st->last_extl == FB_TBE ) + { + /* SHB LSP values from prev. frame for interpolation */ + mvr2r( st->swb_lsp_prev_interp, lsp_shb_1, LPC_SHB_ORDER ); + } + else + { + /* Use current frame's LSPs; in effect no interpolation */ + mvr2r( lsp_shb_2, lsp_shb_1, LPC_SHB_ORDER ); + } + if( st->bws_cnt == 0 && st->bws_cnt1 == 0 && st->prev_use_partial_copy == 0 && st->use_partial_copy == 0) + { + lsf_diff[0] = lsf_diff[LPC_SHB_ORDER-1] = 0.5f; + for(i=1; i<(LPC_SHB_ORDER-1); i++) + { + lsf_diff[i] = lsf_shb[i] - lsf_shb[i-1]; + } + + a2rc (st->cur_sub_Aq+1, refl, (short) M); + tilt_para = 6.6956f * (1.0f + refl[0]) * (1.0f + refl[0]) - 3.8714f * (1.0f + refl[0]) + 1.3041f; + if( st->last_extl != SWB_TBE && st->last_extl != FB_TBE ) + { + for( i=1; iprev_lsf_diff[i-1] = 0.5f*lsf_diff[i]; + } + } + + if( st->total_brate <= ACELP_16k40 ) + { + if(!(st->prev_tilt_para > 5.0f && (coder_type == TRANSITION || tilt_para < 1.0f)) && !(((st->prev_tilt_para < 3.0f && st->prev_coder_type >= VOICED)) && tilt_para > 5.0f)) + { + for( i = 1; i < (LPC_SHB_ORDER-1); i++ ) + { + if( lsf_diff[i] < 0 || st->prev_lsf_diff[i-1] <= 0 ) /* safety check in case of bit errors */ + { + w[i] = 0; + st->BER_detect = 1; + } + else + { + w[i] = (lsf_diff[i] < st->prev_lsf_diff[i-1]) ? min(max(0.8f*lsf_diff[i]/st->prev_lsf_diff[i-1], 0.5f), 1.0f) : min(max(0.8f*st->prev_lsf_diff[i-1]/lsf_diff[i], 0.5f), 1.0f); + } + } + w[0] = w[1]; + w[LPC_SHB_ORDER-1] = w[LPC_SHB_ORDER-2]; + + for( i = 0; i < LPC_SHB_ORDER; i++ ) + { + lsp_temp[i] = lsp_shb_1[i]*(1.0f-w[i]) + lsp_shb_2[i]*w[i]; + } + } + else + { + mvr2r( lsp_shb_2, lsp_temp, LPC_SHB_ORDER ); + } + + /* convert from lsp to lsf */ + lsp2lsf( lsp_temp, lsf_shb, LPC_SHB_ORDER, 1.0f ); + } + mvr2r( lsf_diff+1, st->prev_lsf_diff, LPC_SHB_ORDER-2 ); + st->prev_tilt_para = tilt_para; + } + else + { + mvr2r(lsp_shb_2, lsp_temp, LPC_SHB_ORDER); + } + + if( st->total_brate == ACELP_24k40 || st->total_brate == ACELP_32k ) + { + /* SHB LSP interpolation */ + ptr_lsp_interp_coef = interpol_frac_shb; + for( j = 0; j < 4; j++ ) + { + for( i = 0; i < LPC_SHB_ORDER; i++ ) + { + lsp_temp[i] = lsp_shb_1[i]*(*ptr_lsp_interp_coef) + lsp_shb_2[i]*(*(ptr_lsp_interp_coef+1)); + } + ptr_lsp_interp_coef += 2; + + /* convert from lsp to lsf */ + lsp2lsf( lsp_temp, lsp_temp, LPC_SHB_ORDER, 1.0f ); + + /* convert lsf to lpc for SHB synthesis */ + lsp2a( lpc_shb_sf+j*(LPC_SHB_ORDER+1), lsp_temp, LPC_SHB_ORDER ); + lpc_shb_sf[j*(LPC_SHB_ORDER+1)] = 1.0f; + } + } + + /* Save the SWB LSP values from current frame for interpolation */ + mvr2r( lsp_shb_2, st->swb_lsp_prev_interp, LPC_SHB_ORDER ); + + /* save the shb_ener and mixFactor values */ + st->prev3_shb_ener_sf = st->prev2_shb_ener_sf; + st->prev2_shb_ener_sf = st->prev1_shb_ener_sf; + st->prev1_shb_ener_sf = shb_ener_sf; + st->prev_res_shb_gshape = shb_res_gshape[4]; + st->prev_mixFactors = mixFactors; + + /* SWB CNG/DTX - update memories */ + mvr2r( st->lsp_shb_prev, st->lsp_shb_prev_prev, LPC_SHB_ORDER ); + mvr2r( lsf_shb, st->lsp_shb_prev, LPC_SHB_ORDER ); + + /* convert LSPs back into LP coeffs */ + lsp2a( lpc_shb, lsf_shb, LPC_SHB_ORDER ); + lpc_shb[0] = 1.0; + vind = (short)(mixFactors*8.0f); + + /* Determine formant PF strength */ + formant_fac = swb_formant_fac( lpc_shb[1], &st->tilt_mem ); + if(st->total_brate > ACELP_32k) + { + for( j = 0; j < 4; j++ ) + { + mvr2r(lpc_shb, &lpc_shb_sf[j*(LPC_SHB_ORDER+1)], LPC_SHB_ORDER+1); + } + } + + /* From low band excitation, generate highband excitation */ + mvr2r( st->state_syn_shbexc, shaped_shb_excitation, L_SHB_LAHEAD); + GenShapedSHBExcitation( shaped_shb_excitation + L_SHB_LAHEAD, lpc_shb, White_exc16k, st->mem_csfilt, st->mem_genSHBexc_filt_down_shb, st->state_lpc_syn, + coder_type, bwe_exc_extended, st->bwe_seed, vf_modified, st->extl, &(st->tbe_demph), &(st->tbe_premph), lpc_shb_sf, + &shb_ener_sf, shb_res_gshape, shb_res_dummy, &vind, formant_fac, st->fb_state_lpc_syn, &(st->fb_tbe_demph), st->total_brate , st->prev_bfi); + + for( i=0; imem_stp_swb, + st->ptr_mem_stp_swb, &(st->gain_prec_swb), st->mem_zero_swb, formant_fac ); + } + + mvr2r( shaped_shb_excitationTemp, &shaped_shb_excitation[L_SHB_LAHEAD], L_FRAME16k ); + prev_pow = sum2_f( shaped_shb_excitation, L_SHB_LAHEAD + 10 ); + curr_pow = sum2_f( shaped_shb_excitation + L_SHB_LAHEAD + 10, L_SHB_LAHEAD + 10 ); + + if( voice_factors[0] > 0.75f ) + { + curr_pow *= 0.25; + } + + if( prev_pow == 0 ) + { + scale = 0; + } + else + { + scale = sqrt(curr_pow/prev_pow); + } + for( i=0; istate_syn_shbexc, L_SHB_LAHEAD ); + l_subframe = L_FRAME16k/NUM_SHB_SUBGAINS; + ener = EPSILON; + for(i=0; ibws_cnt > 0 ) + { + ener *= 0.35f; + + if( st->tilt_swb > 8 ) + { + st->prev_fractive = 1; + } + + if( is_fractive == 0 ) + { + if( st->tilt_wb > 1.0 ) + { + st->tilt_wb = 1.0f; + } + else if( st->tilt_wb < 0.5 ) + { + st->tilt_wb = 0.5f; + } + + if( st->prev_fractive == 1 && st->tilt_wb > 0.5 ) + { + st->tilt_wb = 0.5f; + } + } + else + { + if ( st->tilt_wb > 4) + { + if ( st->prev_fractive == 0) + { + st->tilt_wb = 4; + } + else + { + st->tilt_wb = 8; + } + } + else + { + st->tilt_wb *= 2; + } + } + + if( ener != 0 ) + { + if( ener*st->tilt_wb > st->enerLH ) + { + st->tilt_wb = 0.5f*st->enerLH/ener; + } + else if( ener*st->tilt_wb < 0.05f*st->enerLH && is_fractive == 1 ) + { + st->tilt_wb = 0.25f*st->enerLH/ener; + } + + GainFrame_prevfrm = st->prev_ener_shb/ener; + } + else + { + GainFrame_prevfrm = 0; + } + + if ( is_fractive == 1) + { + GainFrame = 8.0f*st->tilt_wb; + } + else + { + GainFrame = 2.0f*st->tilt_wb; + } + + if ( (is_fractive & st->prev_fractive) == 1 && GainFrame > GainFrame_prevfrm ) + { + GainFrame = 0.2f*GainFrame + 0.8f*GainFrame_prevfrm; + } + else + { + if ( (st->prev_enerLH < 2.0f*st->enerLH && st->prev_enerLH > 0.5f*st->enerLH ) + && (st->prev_enerLL < 2.0f*st->enerLL && st->prev_enerLL > 0.5f*st->enerLL) + && (is_fractive ^ st->prev_fractive) == 0) + { + GainFrame = 0.5f*GainFrame + 0.5f*GainFrame_prevfrm; + } + else + { + if ( is_fractive == 0 && st->prev_fractive == 1 ) + { + GainFrame = (1.0f-0.1f*GainFrame)*GainFrame + 0.1f*GainFrame*GainFrame_prevfrm; + } + else + { + GainFrame = 0.5f*GainFrame + 0.5f*GainFrame_prevfrm; + } + } + } + + GainFrame *= ((float)N_WS2N_FRAMES - (float)st->bws_cnt) / (float)N_WS2N_FRAMES; + } + else + { + if( st->bws_cnt1 > 0 ) + { + GainFrame *= (float)st->bws_cnt1 / (float)N_WS2N_FRAMES; + } + + if( st->nbLostCmpt == 1 ) + { + prev_ener_ratio = st->prev_ener_shb/ener; + + if( st->clas_dec != UNVOICED_CLAS && st->clas_dec != UNVOICED_TRANSITION &&st->tilt_swb_fec < 8.0 && + ((st->enerLL > 0.5f*st->prev_enerLL && st->enerLL < 2.0f*st->prev_enerLL)|| (st->enerLH > 0.5f*st->prev_enerLH && st->enerLH < 2.0f*st->prev_enerLH))) + { + if( prev_ener_ratio > 4.0f * GainFrame ) + { + GainFrame = 0.4f * prev_ener_ratio + 0.6f * GainFrame; + } + else if( prev_ener_ratio > 2.0f * GainFrame ) + { + GainFrame = 0.8f * prev_ener_ratio + 0.2f * GainFrame; + } + else + { + GainFrame = 0.2f * prev_ener_ratio + 0.8f * GainFrame; + } + + if( tilt_swb_fec > st->tilt_swb_fec ) + { + GainFrame *= st->tilt_swb_fec > 0 ? (min(5.0f,tilt_swb_fec/st->tilt_swb_fec)) : 1.0f; + } + + } + else if( (st->clas_dec != UNVOICED_CLAS || st->tilt_swb_fec > 8.0) && prev_ener_ratio > 4.0f * GainFrame && + (st->enerLL > 0.5f*st->prev_enerLL ||st->enerLH > 0.5f*st->prev_enerLH) ) + { + GainFrame = 0.2f * prev_ener_ratio + 0.8f * GainFrame; + } + } + else if( st->nbLostCmpt > 1 ) + { + prev_ener_ratio = st->prev_ener_shb/ener; + if((prev_ener_ratio > 4.0 * GainFrame) && ((st->codec_mode == MODE1 && st->enerLL > st->prev_enerLL && st->enerLH > st->prev_enerLH) || st->codec_mode == MODE2)) + { + if( tilt_swb_fec > 10.0f && st->tilt_swb_fec >10.0f ) + { + GainFrame = min((prev_ener_ratio *0.8f + GainFrame * 0.2f),4.0f * GainFrame); + } + else + { + GainFrame = min((prev_ener_ratio *0.5f + GainFrame * 0.5f),4.0f * GainFrame); + } + } + else if((prev_ener_ratio > GainFrame) &&((st->codec_mode == MODE1 && st->enerLL > st->prev_enerLL && st->enerLH > st->prev_enerLH) || st->codec_mode == MODE2)) + { + if( tilt_swb_fec > 10.0f && st->tilt_swb_fec >10.0f ) + { + GainFrame = 0.5f * prev_ener_ratio + 0.5f * GainFrame; + } + else + { + GainFrame = 0.2f * prev_ener_ratio + 0.8f * GainFrame; + } + } + } + } + + st->prev_fractive = is_fractive; + + /* Adjust the subframe and frame gain of the synthesized shb signal */ + /* Scale the shaped excitation */ + if( st->L_frame == L_FRAME ) + { + pitch = 0.25f*sum_f(pitch_buf, 4); + } + else + { + pitch = 0.2f*sum_f(pitch_buf, 5); + } + + if( ((st->total_brate >= ACELP_24k40 && st->prev_coder_type == coder_type && coder_type != UNVOICED) + || (st->total_brate <= ACELP_16k40 && (st->prev_coder_type == coder_type || (st->prev_coder_type == VOICED && coder_type == GENERIC) || (st->prev_coder_type == GENERIC && coder_type == VOICED)))) + && pitch > 70 && st->extl < FB_TBE) + { + for( i=0; i st->prev_ener*st->prev_GainShape ) + { + GainShape_tmp[i] = 0.5f*(st->prev_ener*st->prev_GainShape/ener_tmp[i] + GainShape_tmp[i]); + } + st->prev_ener = ener_tmp[i]; + st->prev_GainShape = GainShape_tmp[i]; + } + for( i=0; isyn_overlap,GainShape,GainFrame,window_shb,subwin_shb ); + + curr_frame_pow = sum2_f( shaped_shb_excitation, L_FRAME16k ) + 0.001f; + + if( !st->bfi && (st->prev_bfi || st->prev_use_partial_copy ) ) + { + + if( ( curr_frame_pow > 2.0f * st->prev_swb_bwe_frame_pow ) && + ( curr_frame_pow < 30.0f * st->prev_swb_bwe_frame_pow ) && + st->prev_coder_type == UNVOICED ) + { + scale = sqrt( st->prev_swb_bwe_frame_pow/curr_frame_pow ); + if ((curr_frame_pow)==0) scale = 0; + + temp = (float)pow( scale, 0.125f ); + } + else + { + scale = 1.0f; + temp = 1.0f; + } + + for( j=0; j<8; j++ ) + { + GainShape[2*j] *= scale; + GainShape[2*j+1] *= scale; + for( i=0; ibfi ) + { + scale = 1.0f; + temp = 1.0f; + if( st->nbLostCmpt == 1 ) + { + if( curr_frame_pow > st->prev_swb_bwe_frame_pow && + st->prev_coder_type != UNVOICED && + st->last_good != UNVOICED_CLAS ) + { + scale = sqrt( st->prev_swb_bwe_frame_pow/curr_frame_pow ); + if ((curr_frame_pow)==0) scale = 0; + temp = (float) pow( scale, 0.125f ); + } + else if( curr_frame_pow < 0.5f *st->prev_swb_bwe_frame_pow && st->nbLostCmpt == 1 && + (st->enerLL > 0.5 * st->prev_enerLL || st->enerLH > 0.5 *st->prev_enerLH) && + (st->prev_coder_type == UNVOICED || st->last_good == UNVOICED_CLAS || st->tilt_swb_fec > 5.0f) ) + { + scale = sqrt(st->prev_swb_bwe_frame_pow / curr_frame_pow); + if ((curr_frame_pow)==0) scale = 0; + temp = (float) pow(scale, 0.125f); + } + } + else if ( st->nbLostCmpt > 1 ) + { + if( curr_frame_pow > st->prev_swb_bwe_frame_pow ) + { + scale = sqrt( st->prev_swb_bwe_frame_pow / curr_frame_pow ); + if ((curr_frame_pow)==0) scale = 0; + temp = (float) pow( scale, 0.125f ); + } + else if( curr_frame_pow < 0.5f *st->prev_swb_bwe_frame_pow && + (st->enerLL > 0.5 * st->prev_enerLL || st->enerLH > 0.5 *st->prev_enerLH) && + (st->prev_coder_type == UNVOICED || st->last_good == UNVOICED_CLAS || st->tilt_swb_fec > 5.0f) ) + { + scale = min(2.0f,sqrt(st->prev_swb_bwe_frame_pow/curr_frame_pow)); + if ((curr_frame_pow)==0) scale = 0; + temp = (float) pow(scale, 0.125f); + } + } + + for( j=0; j<8; j++ ) + { + GainShape[2 * j] *= scale; + GainShape[2 * j + 1] *= scale; + for( i=0; iprev_swb_bwe_frame_pow = curr_frame_pow; + + st->prev_ener_shb = EPSILON; + for( i=0; iprev_ener_shb += shaped_shb_excitation[i] * shaped_shb_excitation[i]; + } + st->prev_ener_shb = (float)sqrt(st->prev_ener_shb/L_FRAME16k); + + for(i=0; iprev_SWB_fenv[i] = (float)sqrt(curr_frame_pow/L_FRAME16k); + } + + /* generate 32kHz SHB synthesis from 12.8(16)kHz signal */ + GenSHBSynth( shaped_shb_excitation, error, st->genSHBsynth_Hilbert_Mem, + st->genSHBsynth_state_lsyn_filt_shb_local, st->L_frame, &(st->syn_dm_phase) ); + + mvr2r( error + L_FRAME32k - L_SHB_TRANSITION_LENGTH, st->old_tbe_synth, L_SHB_TRANSITION_LENGTH ); + + /* resample SHB synthesis (if needed) and scale down */ + synth_scale = (st->codec_mode == MODE1) ? 0.9f : 1.f; + + if( st->output_Fs == 48000 ) + { + if ( st->extl == FB_TBE) + { + for( i=0; iint_3_over_2_tbemem_dec, allpass_poles_3_ov_2 ); + } + + else if( st->output_Fs == 32000 ) + { + for( i=0; ioutput_Fs == 16000 ) + { + for( i=0; imem_resamp_HB_32k, L_FRAME32k, synth ); + } + + /* Update previous frame parameters for FEC */ + mvr2r( lsf_shb, st->lsp_prevfrm, LPC_SHB_ORDER ); + if( st->codec_mode == MODE1 ) + { + st->GainFrame_prevfrm = GainFrame; + st->tilt_swb_fec = tilt_swb_fec; + + if( !st->bfi ) + { + st->GainAttn = 1.0f; + } + } + else + { + if( !st->bfi ) + { + st->tilt_swb_fec = tilt_swb_fec; + st->GainFrame_prevfrm = GainFrame; /* gain locking on lost frame */ + st->GainAttn = 1.0f; + } + } + st->prev_ener = ener_tmp[NUM_SHB_SUBGAINS-1]; + st->prev_GainShape = GainShape[NUM_SHB_SUBFR-1]; + + return; +} + +/*-------------------------------------------------------------------* + * Dequant_lower_LSF() + * + * Dequantized the lower LSFs + *-------------------------------------------------------------------*/ + +static void Dequant_lower_LSF( + const short lsf_idx[], /* i : LSF indices */ + float lsf_q[] /* o : Quantized LSFs */ +) +{ + short i; + + lsf_q[0] = lsf_q_cb[0][lsf_idx[0]]; + for (i = 1; i < NUM_Q_LSF; i++) + { + lsf_q[i] = lsf_q_cb[i][lsf_idx[i]] + lsf_q[i-1]; + } + + return; +} + +/*-------------------------------------------------------------------* + * Map_higher_LSF() + * + * Map the higher LSFs from the lower LSFs + *-------------------------------------------------------------------*/ + +static void Map_higher_LSF( + float lsf_q[], /* i/o : Quantized lower LSFs */ + const float m, /* i : Mirroring point */ + const float grid_in[] /* i : Input LSF smoohthing grid */ +) +{ + float lsf_map[NUM_MAP_LSF]; + float grid[NUM_MAP_LSF]; + float last_q_lsf; + float lsf_smooth[NUM_MAP_LSF]; + float offset; + short i; + float scale; + + for (i = 0; i < NUM_MAP_LSF; i++) + { + lsf_map[i] = 2*m - lsf_q[NUM_MAP_LSF - 1 - i]; + } + + if (m > MAX_LSF/2) + { + offset = lsf_map[0]; + scale = (MAX_LSF - m)/m; + for (i = 0; i < NUM_MAP_LSF; i++) + { + lsf_map[i] = (lsf_map[i] - offset)*scale + offset; + } + } + + last_q_lsf = lsf_q[NUM_Q_LSF - 1]; + scale = MAX_LSF - last_q_lsf; + + for (i = 0; i < NUM_MAP_LSF; i++) + { + grid[i] = grid_in[i]*scale + last_q_lsf; + } + + for (i = 0; i < NUM_MAP_LSF; i++) + { + lsf_smooth[i] = (1 - grid_smoothing[i])*lsf_map[i] + grid_smoothing[i]*grid[i]; + } + + for (i = 0; i < NUM_MAP_LSF; i++) + { + lsf_q[NUM_Q_LSF + i] = lsf_smooth[i]; + } + + return; +} + +/*-------------------------------------------------------------------* + * Map_higher_LSF() + * + * Map the higher LSFs from the lower LSFs + *-------------------------------------------------------------------*/ + +static void Dequant_mirror_point( + const float lsf_q[], /* i/o : Quantized lower LSFs */ + const short m_idx, /* i : Mirror point index */ + float *m /* i : Mirroring point */ +) +{ + *m = mirror_point_q_cb[m_idx] + lsf_q[NUM_Q_LSF - 1]; + + return; +} + +/*-------------------------------------------------------------------* + * dequantizeSHBparams() + * + * Dequantize super highband spectral envolope, temporal gains and frame gain + *-------------------------------------------------------------------*/ + +static void dequantizeSHBparams( + Decoder_State *st, /* i/o: decoder state structure */ + const short extl, /* i : extension layer */ + long extl_brate, /* i : extensiuon layer bitrate */ + float *Q_lsf, /* o : SHB LSF from de-quantization */ + float *Q_subgain, /* o : SHB subframe gains from de-quantization */ + float *Q_framegrain, /* o : SHB frame gain from de-quantization */ + short *uv_flag, /* o : unvoiced flag */ + float *Q_shb_ener_sf, + float *Q_shb_res_gshape, + float *Q_mixFactors +) +{ + short i, j, idxLSF, idxSubGain, idxFrameGain; + float Q_combined_gains[NUM_SHB_SUBFR/4]; + float lsf_q[LPC_SHB_ORDER]; + short lsf_idx[NUM_Q_LSF]; + short m_idx, grid_idx; + float m; + short idx_shb_fr_gain, idx_res_gs[5], idx_mixFac; + + /* LSFs */ + if( extl == WB_TBE ) + { + if ( extl_brate == WB_TBE_0k35 ) + { + idxFrameGain = st->gFrame_WB; + idxLSF = st->lsf_WB; + + mvr2r( lbr_wb_bwe_lsfvq_cbook_2bit + idxLSF*LPC_SHB_ORDER_LBR_WB, Q_lsf, LPC_SHB_ORDER_LBR_WB ); + set_f( Q_subgain, RECIP_ROOT_EIGHT, NUM_SHB_SUBFR/2 ); + mvr2r( SHBCB_FrameGain16 + idxFrameGain, Q_framegrain, 1 ); + } + else + { + /* read the information about UNVOICED frame */ + *uv_flag = (short)get_next_indice( st, 1 ); + + idxSubGain = (short)get_next_indice( st, NUM_BITS_SHB_SUBGAINS ); + idxFrameGain = (short)get_next_indice( st, NUM_BITS_SHB_FrameGain ); + idxLSF = (short)get_next_indice( st, NUM_BITS_WB_LSF ); + + mvr2r( wb_bwe_lsfvq_cbook_8bit + idxLSF*LPC_SHB_ORDER_WB, Q_lsf, LPC_SHB_ORDER_WB ); + mvr2r( HBCB_SubGain5bit + idxSubGain * NUM_SHB_SUBFR/4, Q_combined_gains, NUM_SHB_SUBFR/4 ); + + for( i=0; icodec_mode == MODE2 ) + { + idxSubGain = st->idxSubGains; + idxFrameGain = st->idxFrameGain; + } + else + { + idxSubGain = (short)get_next_indice( st, NUM_BITS_SHB_SUBGAINS ); + idxFrameGain = (short)get_next_indice( st, NUM_BITS_SHB_FRAMEGAIN ); + } + + if( st->total_brate == ACELP_24k40 || st->total_brate == ACELP_32k ) + { + if( st->codec_mode == MODE2 ) + { + idx_shb_fr_gain = st->idx_shb_fr_gain; + } + else + { + idx_shb_fr_gain = (short)get_next_indice( st, NUM_BITS_SHB_ENER_SF ); + } + *Q_shb_ener_sf = usdequant(idx_shb_fr_gain, 0, 0.042f); + *Q_shb_ener_sf = (float)pow(10.0, *Q_shb_ener_sf ); + + for( i=0; i<5; i++ ) + { + if( st->codec_mode == MODE2 ) + { + idx_res_gs[i] = st->idx_res_gs[i]; + } + else + { + idx_res_gs[i] = (short)get_next_indice( st, NUM_BITS_SHB_RES_GS ); + } + Q_shb_res_gshape[i] = usdequant(idx_res_gs[i], 0.125f, 0.125f); + } + + if( st->codec_mode == MODE2 ) + { + idx_mixFac = st->idx_mixFac; + } + else + { + idx_mixFac = (short)get_next_indice( st, NUM_BITS_SHB_VF ); + } + *Q_mixFactors = usdequant(idx_mixFac, 0.125f, 0.125f); + } + else + { + *Q_shb_ener_sf = 0; + *Q_mixFactors = 0; + set_f(Q_shb_res_gshape, 0, 5); + } + + + if( st->rf_flag == 0 && !((st->total_brate == ACELP_9k60) || ( (st->total_brate == 0) && ((st->last_total_brate == ACELP_9k60) || (st->last_total_brate == ACELP_13k20 && st->rf_flag_last)) )) ) + { + /* LSFs */ + if( extl_brate == SWB_TBE_1k6 || extl_brate == FB_TBE_1k8 || extl_brate == SWB_TBE_2k8 || extl_brate == FB_TBE_3k0 ) + { + for( i = 0; i < NUM_Q_LSF; i++ ) + { + if( st->codec_mode == MODE2 ) + { + lsf_idx[i] = st->lsf_idx[i]; + } + else + { + lsf_idx[i] = (short)get_next_indice(st, lsf_q_num_bits[i]); + } + } + } + Dequant_lower_LSF( lsf_idx, lsf_q ); + if( st->codec_mode == MODE2 ) + { + m_idx = st->m_idx; + grid_idx = st->grid_idx; + } + else + { + m_idx = (short)get_next_indice( st, MIRROR_POINT_BITS ); + grid_idx = (short)get_next_indice( st, NUM_LSF_GRID_BITS ); + } + + Dequant_mirror_point(lsf_q, m_idx, &m); + + /* safety check in case of bit errors */ + if( m > MAX_LSF ) + { + st->BER_detect = 1; + m = MAX_LSF; + } + + Map_higher_LSF(lsf_q, m, lsf_grid[grid_idx]); + + for( i = 0; i < LPC_SHB_ORDER; i++ ) + { + /* safety check in case of bit errors */ + if ( lsf_q[LPC_SHB_ORDER - 1 - i] > MAX_LSF ) + { + st->BER_detect = 1; + lsf_q[LPC_SHB_ORDER - 1 - i] = MAX_LSF; + } + Q_lsf[i] = 0.5f - lsf_q[LPC_SHB_ORDER - 1 - i]; + } + } + else + { + set_s(lsf_idx, 0, 5); + mvs2s(st->lsf_idx, lsf_idx, 5); + grid_idx = 0; + m_idx = 0; + mvr2r( swb_tbe_lsfvq_cbook_8b + lsf_idx[0]*LPC_SHB_ORDER, Q_lsf, LPC_SHB_ORDER ); + } + space_lsfs( Q_lsf, LPC_SHB_ORDER ); + + /* Dequantize subgain indices */ + j = idxSubGain*NUM_SHB_SUBGAINS; + for ( i = 0; i < NUM_SHB_SUBGAINS; i++) + { + Q_subgain[i] = (float) pow(10.0, SHBCB_SubGain5bit[j++]); + } + + for (i=NUM_SHB_SUBFR-1; i>=0; i--) + { + Q_subgain[i] = Q_subgain[i*NUM_SHB_SUBGAINS/NUM_SHB_SUBFR]; + } + + /* Frame gain */ + *Q_framegrain = usdequant(idxFrameGain, SHB_GAIN_QLOW, SHB_GAIN_QDELTA); + *Q_framegrain = (float) pow(10.0, *Q_framegrain); + } + + return; +} +/*-------------------------------------------------------------------* + * fb_tbe_dec() + * + * FB TBE decoder, 14(resp. 15.5) - 20 kHz band decoding module + *-------------------------------------------------------------------*/ +void fb_tbe_dec( + Decoder_State *st, /* i/o: encoder state structure */ + const float fb_exc[], /* i : FB excitation from the SWB part */ + float *hb_synth /* o : high-band synthesis */ +) + +{ + short i; + float ratio = 0, fb_exc_energy = 0; + float fb_synth[L_FRAME48k]; + + /* decode FB slope information */ + if ( st->extl == FB_TBE && !st->bfi ) + { + if( st->codec_mode == MODE2 ) + { + i = st->idxGain; + } + else + { + i = (short)get_next_indice( st, 4 ); + } + ratio = (float)(1 << i); + } + else if ( st->extl == FB_TBE && st->bfi ) + { + ratio = st->prev_fbbwe_ratio; + } + + fb_exc_energy = sum2_f(fb_exc,L_FRAME16k); + + /* FB TBE synthesis */ + synthesise_fb_high_band( fb_exc,fb_synth,fb_exc_energy,ratio, st->L_frame, st->bfi, &(st->prev_fbbwe_ratio), st->fbbwe_hpf_mem ); + + /* add the fb_synth component to the hb_synth component */ + v_add( hb_synth, fb_synth, hb_synth, L_FRAME48k ); + + return; +} + + +/*---------------------------------------------------------------------* + * tbe_read_bitstream() + * + * Read TBE bitstream and populate the parameters for TD-BWE decoder. + *---------------------------------------------------------------------*/ +void tbe_read_bitstream( + Decoder_State *st +) +{ + short i; + + if ( (st->rf_flag || st->total_brate == ACELP_9k60) && st->bwidth == WB) + { + /* WB LSF */ + st->lsf_WB = get_next_indice(st, NUM_BITS_LBR_WB_LSF); + + /* WB frame gain */ + st->gFrame_WB = get_next_indice(st, NUM_BITS_SHB_FrameGain_LBR_WB); + } + else if( st->total_brate >= ACELP_9k60 && st->total_brate <= ACELP_32k && (st->bwidth == SWB || st->bwidth == FB) ) + { + if(st->rf_flag == 0 && st->total_brate > ACELP_9k60) + { + for (i=0; ilsf_idx[i] = get_next_indice(st, lsf_q_num_bits[i]); + } + st->m_idx = get_next_indice(st, MIRROR_POINT_BITS); + st->grid_idx = get_next_indice(st, NUM_LSF_GRID_BITS); + } + else + { + st->lsf_idx[0] = get_next_indice(st, 8); + st->m_idx = 0; + st->grid_idx = 0; + } + /* shape gains */ + st->idxSubGains = get_next_indice(st, NUM_BITS_SHB_SUBGAINS); + + /* frame gain */ + st->idxFrameGain = get_next_indice(st, NUM_BITS_SHB_FRAMEGAIN); + + if( st->total_brate >= ACELP_24k40 ) + { + /* sub frame energy*/ + st->idx_shb_fr_gain = get_next_indice(st, NUM_BITS_SHB_ENER_SF); + + /* gain shapes residual */ + for (i = 0; i < NB_SUBFR16k; i++) + { + st->idx_res_gs[i] = get_next_indice(st, NUM_BITS_SHB_RES_GS); + } + + /* voicing factor */ + st->idx_mixFac = get_next_indice(st, NUM_BITS_SHB_VF); + } + + if( st->tec_tfa == 1 ) + { + st->tec_flag = get_next_indice(st, BITS_TEC); + st->tfa_flag = get_next_indice(st, BITS_TFA); + if( st->tfa_flag && st->tec_flag ) + { + st->tec_flag = 2; + st->tfa_flag = 0; + } + + + } + else + { + st->tec_flag = 0; + st->tfa_flag = 0; + } + } + + if( st->bwidth == FB ) + { + st->idxGain = get_next_indice(st, 4); + } + + return; +} + + +/*---------------------------------------------------------------------* + * GenTransition() + * + * Generate a highband transition signal from the gain shape overlap + * buffer to fill the gap caused by the delay alignment buffer when + * switching from TBE to IGF + *---------------------------------------------------------------------*/ +void GenTransition( + const float *input, /* i : gain shape overlap buffer */ + const float *old_hb_synth, /* i : synthesized HB from previous frame */ + short length, /* i : targeted length of transition signal */ + float *output, /* o : synthesized transitions signal */ + float Hilbert_Mem[], /* i/o: memory */ + float state_lsyn_filt_shb_local[], /* i/o: memory */ + short *syn_dm_phase, + int output_Fs, + float *up_mem, + int rf_flag + , int bitrate +) +{ + short i; + float syn_overlap_32k[L_FRAME32k]; + + /* upsample overlap snippet */ + Interpolate_allpass_steep( input, state_lsyn_filt_shb_local, SHB_OVERLAP_LEN, syn_overlap_32k ); + + /* perform spectral flip and downmix with overlap snippet to match HB synth */ + if (rf_flag || bitrate == ACELP_9k60) + { + flip_and_downmix_generic( syn_overlap_32k, syn_overlap_32k, 2*SHB_OVERLAP_LEN, Hilbert_Mem, + Hilbert_Mem + HILBERT_ORDER1, Hilbert_Mem + (HILBERT_ORDER1+2*HILBERT_ORDER2), syn_dm_phase ); + } + else + { + for(i = 0; i < 2*SHB_OVERLAP_LEN; i++) + { + syn_overlap_32k[i] = ((i%2)==0)?(-syn_overlap_32k[i]):(syn_overlap_32k[i]); + } + } + + /* cross fade of overlap snippet and mirrored HB synth from previous frame */ + for (i=0; i<2*L_SHB_LAHEAD; i++) + { + output[i] = window_shb_32k[i]*old_hb_synth[L_SHB_TRANSITION_LENGTH-1-i] + window_shb_32k[2*L_SHB_LAHEAD-1-i]*syn_overlap_32k[i]; + } + + /* fill transition signal with mirrored HB synth from previous frame to fully fill delay alignment buffer gap */ + for ( ; i < length; i++) + { + output[i] = old_hb_synth[L_SHB_TRANSITION_LENGTH-1-i]; + } + + if( output_Fs == 48000 ) + { + interpolate_3_over_2_allpass( output, length, output, up_mem, allpass_poles_3_ov_2 ); + } + + return; +} + + +void GenTransition_WB( + const float *input, /* i : gain shape overlap buffer */ + const float *old_hb_synth, /* i : synthesized HB from previous frame */ + short length, /* i : targeted length of transition signal */ + float *output, /* o : synthesized transitions signal */ + float state_lsyn_filt_shb1[], + float state_lsyn_filt_shb2[], + int output_Fs, + float *up_mem +) +{ + short i; + float speech_buf_16k1[L_FRAME16k], speech_buf_16k2[L_FRAME16k]; + float upsampled_synth[L_FRAME48k]; + + /* upsample overlap snippet */ + Interpolate_allpass_steep( input, state_lsyn_filt_shb1, SHB_OVERLAP_LEN/2, speech_buf_16k1); + Interpolate_allpass_steep( speech_buf_16k1, state_lsyn_filt_shb2, SHB_OVERLAP_LEN, speech_buf_16k2); + + + /* perform spectral flip and downmix with overlap snippet to match HB synth */ + for(i = 0; i < SHB_OVERLAP_LEN; i++) + { + speech_buf_16k2[i] = ((i%2)==0)?(-speech_buf_16k2[i]):(speech_buf_16k2[i]); + } + + /* cross fade of overlap snippet and mirrored HB synth from previous frame */ + for (i=0; ilast_core != ACELP_CORE ) + { + set_f( st->old_bwe_exc, 0.0f, PIT16k_MAX * 2 ); + st->bwe_non_lin_prev_scale = 0.f; + } + if( bandwidth == WB ) + { + wb_tbe_extras_reset( st->mem_genSHBexc_filt_down_wb2, st->mem_genSHBexc_filt_down_wb3 ); + wb_tbe_extras_reset_synth( st->state_lsyn_filt_shb, st->state_lsyn_filt_dwn_shb, st->mem_resamp_HB ); + set_f( st->mem_genSHBexc_filt_down_shb, 0, 7 ); + set_f( st->state_lpc_syn, 0, 10 ); + set_f( st->state_syn_shbexc, 0, L_SHB_LAHEAD/4 ); + set_f( st->syn_overlap, 0, L_SHB_LAHEAD ); + set_f( st->mem_csfilt, 0, 2 ); + } + else if( bandwidth == SWB || bandwidth == FB ) + { + swb_tbe_reset( st->mem_csfilt, st->mem_genSHBexc_filt_down_shb, st->state_lpc_syn, + st->syn_overlap, st->state_syn_shbexc, &(st->tbe_demph), &(st->tbe_premph), + st->mem_stp_swb, &(st->gain_prec_swb) ); + + set_f( st->GainShape_Delay, 0, NUM_SHB_SUBFR/2 ); + set_f( st->int_3_over_2_tbemem_dec, 0.f, INTERP_3_2_MEM_LEN ); + set_f( st->mem_resamp_HB_32k, 0, 2*ALLPASSSECTIONS_STEEP+1 ); + + swb_tbe_reset_synth( st->genSHBsynth_Hilbert_Mem, st->genSHBsynth_state_lsyn_filt_shb_local ); + + if ( bandwidth == FB ) + { + st->prev_fb_ener_adjust = 0.0f; + set_f(st->fb_state_lpc_syn, 0, LPC_SHB_ORDER); + st->fb_tbe_demph = 0; + fb_tbe_reset_synth( st->fbbwe_hpf_mem, &st->prev_fbbwe_ratio ); + } + } + + return; +} diff --git a/src/libs/libevs/lib_dec/swb_tbe_dec_fx.cpp b/src/libs/libevs/lib_dec/swb_tbe_dec_fx.cpp deleted file mode 100755 index 058b48b7..00000000 --- a/src/libs/libevs/lib_dec/swb_tbe_dec_fx.cpp +++ /dev/null @@ -1,3594 +0,0 @@ -/*==================================================================================== - EVS Codec 3GPP TS26.442 Apr 03, 2018. Version 12.11.0 / 13.6.0 / 14.2.0 - ====================================================================================*/ - - - -#include -#include "options.h" -#include "cnst_fx.h" -#include "prot_fx.h" -#include "rom_com_fx.h" -#include "rom_dec_fx.h" -#include "stl.h" - -/*-----------------------------------------------------------------* - * Local functions - *-----------------------------------------------------------------*/ - - -static void dequantizeSHBparams_fx_9_1( Decoder_State_fx* st_fx, const Word16 extl, Word32 extl_brate, - Word16* Q_lsf, Word16* Q_subgain, Word32* Q_framegrain, Word16* uv_flag, - Word32* Q_shb_ener_sf_32, Word16* Q_shb_res_gshape, Word16* Q_mixFactors); -static void find_max_mem_dec( Decoder_State_fx* st_fx, Word16* n_mem, Word16 *n_mem2, Word16 *n_mem3 ); -static void rescale_genSHB_mem_dec( Decoder_State_fx* st_fx, Word16 sf ); -static void find_max_mem_wb( Decoder_State_fx* st_fx, Word16* n_mem ); -static void rescale_genWB_mem( Decoder_State_fx* st_fx, Word16 sf ); -static void Dequant_lower_LSF_fx( const Word16 lsf_idx[], Word16 lsf_q[] ); -static void Map_higher_LSF_fx( Word16 lsf_q[], const Word16 m, const Word16 grid_in[] ); -static void Dequant_mirror_point_fx( const Word16 lsf_q[], const Word16 m_idx, Word16* m ); - -/* gain shape concealment code */ -static void gradientGainShape(Decoder_State_fx *st_fx, Word16 *GainShape, Word32 *GainFrame); - -/*-------------------------------------------------------------------* - * find_max_mem_dec() - * - * Find norm and max in TBE memories and past buffers - *-------------------------------------------------------------------*/ -void find_max_mem_dec( - Decoder_State_fx *st_fx, - Word16 *n_mem, - Word16 *n_mem2 - ,Word16 *n_mem3 -) -{ - Word16 i; - Word16 n_mem_32; - Word16 max = 0; - Word32 Lmax = 0; - Word16 tempQ15, max2 = 0; - Word16 max3; - Word32 tempQ32, Lmax3; - - /* old BWE exc max */ - FOR( i = 0; i < NL_BUFF_OFFSET; i++ ) - { - tempQ15 = abs_s( st_fx->old_bwe_exc_extended_fx[i] ); - max = s_max( max, tempQ15 ); - } - - /* decimate all-pass steep memory */ - FOR ( i = 0; i < 7; i++ ) - { - tempQ15 = abs_s( st_fx->mem_genSHBexc_filt_down_shb_fx[i] ); - max = s_max(max, tempQ15); - } - - /* -- keep norm of state_lpc_syn_fx, state_syn_shbexc_fx, - and mem_stp_swb_fx separately for 24.4 and 32kbps ----*/ - /* findMaxMem2() inside tbe com */ - FOR ( i = 0; i < LPC_SHB_ORDER; i++ ) - { - tempQ15 = abs_s( st_fx->state_lpc_syn_fx[i] ); - max2 = s_max(max2, tempQ15); - } - - /* findMaxMem2() inside tbe com */ - FOR ( i = 0; i < L_SHB_LAHEAD; i++ ) - { - tempQ15 = abs_s( st_fx->state_syn_shbexc_fx[i] ); - max2 = s_max(max2, tempQ15); - } - - /* findMaxMem2() inside tbe com */ - FOR ( i = 0; i < LPC_SHB_ORDER; i++ ) - { - tempQ15 = abs_s( st_fx->mem_stp_swb_fx[i] ); - max2 = s_max(max2, tempQ15); - } - - /* for total_brate > 16.4kbps, use n_mem2; else account for the max2 for n_mem calculation */ - *n_mem2 = norm_s(max2); - if(max2 == 0) *n_mem2 = 15; - - if(L_sub(st_fx->total_brate_fx, ACELP_24k40) < 0) - { - max = s_max(max, max2); - } - - /* de-emph and pre-emph memory */ - tempQ15 = abs_s( st_fx->tbe_demph_fx ); - max = s_max(max, tempQ15); - - tempQ15 = abs_s( st_fx->tbe_premph_fx ); - max = s_max(max, tempQ15); - - IF( sub(st_fx->extl_fx, FB_TBE) == 0 ) - { - FOR ( i = 0; i < LPC_SHB_ORDER; i++ ) - { - tempQ15 = abs_s( st_fx->fb_state_lpc_syn_fx[i] ); - max = s_max(max, tempQ15); - } - /* FB de-emph memory */ - tempQ15 = abs_s( st_fx->fb_tbe_demph_fx); - max = s_max(max, tempQ15); - } - /* estimate the norm for 16-bit memories */ - *n_mem = norm_s( max ); - if( max == 0 ) - { - *n_mem = 15; - } - - /* estimate the norm for 32-bit memories */ - Lmax = L_abs( st_fx->mem_csfilt_fx[0] ); /* only element [0] is used in env. shaping */ - - n_mem_32 = norm_l( Lmax ); - if( Lmax == 0 ) - { - n_mem_32 = 31; - } - - tempQ15 = sub( s_min( *n_mem, n_mem_32 ), 1 ); - *n_mem = s_max( tempQ15, 0 ); - - /* --------------------------------------------------------------*/ - /* Find headroom for synthesis stage associated with these memories: - 1. st_fx->syn_overlap_fx - 2. st_fx->genSHBsynth_state_lsyn_filt_shb_local - 3. st_fx->genSHBsynth_Hilbert_Mem_fx (32-bit) */ - max3 = 0; - /* find max in prev overlapSyn */ - FOR ( i = 0; i < L_SHB_LAHEAD; i++ ) - { - tempQ15 = abs_s( st_fx->syn_overlap_fx[i] ); - max3 = s_max(max3, tempQ15); - } - /* find max in prev genSHBsynth_state_lsyn_filt_shb_local_fx */ - FOR ( i = 0; i < 2*ALLPASSSECTIONS_STEEP; i++ ) - { - tempQ15 = abs_s( st_fx->genSHBsynth_state_lsyn_filt_shb_local_fx[i] ); - max3 = s_max(max3, tempQ15); - } - /* find max in prev int_3_over_2_tbemem_dec_fx */ - IF( L_sub(st_fx->output_Fs_fx, 48000) == 0 ) - { - FOR ( i = 0; i < INTERP_3_2_MEM_LEN; i++ ) - { - tempQ15 = abs_s( st_fx->int_3_over_2_tbemem_dec_fx[i] ); - max3 = s_max(max3, tempQ15); - } - } - IF( L_sub(st_fx->output_Fs_fx, 16000) == 0 ) - { - FOR ( i = 0; i < (2*ALLPASSSECTIONS_STEEP+1); i++ ) - { - tempQ15 = abs_s( st_fx->mem_resamp_HB_32k_fx[i] ); - max3 = s_max(max3, tempQ15); - } - } - /* estimate the norm for 16-bit memories */ - *n_mem3 = norm_s( max3 ); - if( max3 == 0 ) *n_mem3 = 15; - - Lmax3 = 0; - IF(sub(st_fx->L_frame_fx, L_FRAME) == 0) - { - /* find max in prev genSHBsynth_Hilbert_Mem_fx */ - FOR ( i = 0; i < HILBERT_MEM_SIZE; i++ ) - { - tempQ32 = L_abs( st_fx->genSHBsynth_Hilbert_Mem_fx[i] ); - Lmax3 = L_max(Lmax3, tempQ32); - } - } - - /* estimate the norm for 32-bit memories */ - n_mem_32 = norm_l( Lmax3 ); - if( Lmax3 == 0 ) n_mem_32 = 31; - - tempQ15 = sub( s_min( *n_mem3, n_mem_32 ), 2 ); /* very important leave at least 2 bit head room - because of the Hilber transform and Q14 coeffs */ - *n_mem3 = s_max( tempQ15, 0 ); - /* --------------------------------------------------------------*/ -} - -/*-------------------------------------------------------------------* - * rescale_genSHB_mem_dec() - * - * Rescale genSHB memories - *-------------------------------------------------------------------*/ -void rescale_genSHB_mem_dec( - Decoder_State_fx *st_fx, - Word16 sf ) -{ - Word16 i; - - FOR( i = 0; i < NL_BUFF_OFFSET; i++ ) - { - st_fx->old_bwe_exc_extended_fx[i] = shl( st_fx->old_bwe_exc_extended_fx[i], sf ); - move16(); - } - - FOR( i = 0; i < 7; i++ ) - { - st_fx->mem_genSHBexc_filt_down_shb_fx[i] = shl( st_fx->mem_genSHBexc_filt_down_shb_fx[i], sf ); - move16(); - } - - /* -- Apply memory scaling for 13.2 and 16.4k bps using sf ----*/ - IF(L_sub(st_fx->total_brate_fx, ACELP_24k40) < 0) - { - FOR ( i = 0; i < LPC_SHB_ORDER; i++ ) - { - st_fx->state_lpc_syn_fx[i] = shl( st_fx->state_lpc_syn_fx[i], sf ); - move16(); - } - - FOR ( i = 0; i < L_SHB_LAHEAD; i++ ) - { - st_fx->state_syn_shbexc_fx[i] = shl( st_fx->state_syn_shbexc_fx[i], sf ); - move16(); - } - } - - IF( sub(st_fx->extl_fx, FB_TBE) == 0 ) - { - } - st_fx->mem_csfilt_fx[0] = L_shl( st_fx->mem_csfilt_fx[0], sf ); - move32(); - - st_fx->tbe_demph_fx = shl_r( st_fx->tbe_demph_fx, sf ); - move16(); - st_fx->tbe_premph_fx = shl_r( st_fx->tbe_premph_fx, sf ); - move16(); - -} - -void find_max_mem_wb( Decoder_State_fx* st_fx, Word16* n_mem ) -{ - Word16 i; - Word16 max = 0; - Word32 Lmax = 0; - Word16 n_mem_32; - - FOR( i = 0; i < NL_BUFF_OFFSET; i++ ) - max = s_max( max, abs_s( st_fx->old_bwe_exc_extended_fx[i] ) ); - - FOR( i = 0; i < 7; i++ ) - { - - if( abs_s( st_fx->mem_genSHBexc_filt_down_shb_fx[i] ) > max ) - max = abs_s( st_fx->mem_genSHBexc_filt_down_shb_fx[i] ); - } - - FOR( i = 0; i < 7; i++ ) - { - if( abs_s( st_fx->mem_genSHBexc_filt_down_wb2_fx[i] ) > max ) - max = abs_s( st_fx->mem_genSHBexc_filt_down_wb2_fx[i] ); - } - - FOR( i = 0; i < 7; i++ ) - { - - if( abs_s( st_fx->mem_genSHBexc_filt_down_wb3_fx[i] ) > max ) - max = abs_s( st_fx->mem_genSHBexc_filt_down_wb3_fx[i] ); - } - - FOR( i = 0; i < 10; i++ ) - { - - if( abs_s( st_fx->state_lpc_syn_fx[i] ) > max ) - max = abs_s( st_fx->state_lpc_syn_fx[i] ); - } - - FOR( i = 0; i < 5; i++ ) - { - - if( abs_s( st_fx->state_syn_shbexc_fx[i] ) > max ) - max = abs_s( st_fx->state_syn_shbexc_fx[i] ); - } - - IF ( max == 0 ) - { - *n_mem = 15; - move16(); - } - ELSE - { - *n_mem = norm_s( max ); - move16(); - } - - - FOR( i = 0; i < 2; i++ ) - { - - if( L_abs( st_fx->mem_csfilt_fx[i] ) > Lmax ) - Lmax = L_abs( st_fx->mem_csfilt_fx[i] ); - } - - IF ( Lmax == 0 ) - { - n_mem_32 = 31; - move16(); - } - ELSE - { - n_mem_32 = norm_l( Lmax ); - } - - *n_mem = sub( s_min( *n_mem, n_mem_32 ), 1 ); - *n_mem = s_max( *n_mem, 0 ); -} - -void rescale_genWB_mem( Decoder_State_fx* st_fx, Word16 sf ) -{ - Word16 i; - FOR( i = 0; i < NL_BUFF_OFFSET; i++ ) - { - st_fx->old_bwe_exc_extended_fx[i] = shl( st_fx->old_bwe_exc_extended_fx[i], sf ); - move16(); - } - - FOR( i = 0; i < 10; i++ ) - { - st_fx->state_lpc_syn_fx[i] = shl( st_fx->state_lpc_syn_fx[i], sf ); - move16(); - } - - FOR( i = 0; i < 5; i++ ) - { - st_fx->state_syn_shbexc_fx[i] = shl( st_fx->state_syn_shbexc_fx[i], sf ); - move16(); - } - - FOR( i = 0; i < 7; i++ ) - { - st_fx->mem_genSHBexc_filt_down_shb_fx[i] = shl( st_fx->mem_genSHBexc_filt_down_shb_fx[i], sf ); - move16(); - } - - FOR( i = 0; i < 7; i++ ) - { - st_fx->mem_genSHBexc_filt_down_wb2_fx[i] = shl( st_fx->mem_genSHBexc_filt_down_wb2_fx[i], sf ); - move16(); - } - - FOR( i = 0; i < 7; i++ ) - { - st_fx->mem_genSHBexc_filt_down_wb3_fx[i] = shl( st_fx->mem_genSHBexc_filt_down_wb3_fx[i], sf ); - move16(); - } - - FOR( i = 0; i < 2; i++ ) - { - st_fx->mem_csfilt_fx[i] = L_shl( st_fx->mem_csfilt_fx[i], sf ); - move32(); - } -} - - - -void InitSWBdecBuffer_fx( - Decoder_State_fx* st_fx /* i/o: SHB decoder structure */ -) -{ - set16_fx( st_fx->old_bwe_exc_fx, 0, ( PIT16k_MAX * 2 ) ); - st_fx->bwe_seed_fx[0] = 23; - move16(); - st_fx->bwe_seed_fx[1] = 59; - move16(); - - set16_fx( st_fx->old_bwe_exc_extended_fx, 0, NL_BUFF_OFFSET ); - st_fx->bwe_non_lin_prev_scale_fx = 0; - move16(); - st_fx->last_voice_factor_fx = 0; - move16(); - - set32_fx( st_fx->genSHBsynth_Hilbert_Mem_fx, 0, HILBERT_MEM_SIZE ); - set16_fx(st_fx->genSHBsynth_state_lsyn_filt_shb_local_fx, 0, 2*ALLPASSSECTIONS_STEEP); /* Interp all pass memory */ - - st_fx->syn_dm_phase_fx = 0; - move16(); - st_fx->prev_fbbwe_ratio_fx = 32767/*1.0f Q15*/; - - /* these are fd-bwe constants */ - st_fx->prev_wb_bwe_frame_pow_fx = 4194l/*0.001f Q22*/; /* Q22 */ - st_fx->prev_swb_bwe_frame_pow_fx = 4194l/*0.001f Q22*/; /* Q22 */ - st_fx->prev_fb_ener_adjust_fx = 0; - - set16_fx( st_fx->prev_lpc_wb_fx, 0, LPC_SHB_ORDER_WB); - st_fx->prev_Q_bwe_exc = 31; - move16(); - st_fx->prev_ener_fx_Q = 31; - move16(); - st_fx->prev_Qx = 0; - move16(); - st_fx->prev_frame_pow_exp = 0; - move16(); - st_fx->prev_Q_bwe_syn = 0; - move16(); - st_fx->prev_Q_bwe_syn2 = 0; - move16(); - return; -} - - -void ResetSHBbuffer_Dec_fx( Decoder_State_fx* st_fx /* i/o: SHB encoder structure */ ) -{ - Word16 i; - Word16 f; - Word16 inc; - - IF( st_fx->extl_fx != WB_TBE ) - { - f = 1489; - move16(); /* Q15 */ - inc = 1489; - move16(); /* Q15 */ - } - ELSE - { - f = 5461; - move16();/* Q15 */ - inc = 5461; - move16(); /* Q15 */ - } - - /* states for the filters used in generating SHB excitation from WB excitation*/ - set32_fx( st_fx->mem_csfilt_fx, 0, 2 ); - - /* states for the filters used in generating SHB signal from SHB excitation*/ - set16_fx( st_fx->state_syn_shbexc_fx, 0, L_SHB_LAHEAD ); - set16_fx( st_fx->state_lpc_syn_fx, 0, LPC_SHB_ORDER ); - - IF( sub(st_fx->extl_fx, FB_TBE) == 0 ) - { - set16_fx( st_fx->fb_state_lpc_syn_fx, 0, LPC_SHB_ORDER ); - st_fx->fb_tbe_demph_fx = 0; - move16(); - fb_tbe_reset_synth_fx( st_fx->fbbwe_hpf_mem_fx, st_fx->fbbwe_hpf_mem_fx_Q,&st_fx->prev_fbbwe_ratio_fx ); - } - /* states for the filters used in generating SHB signal from SHB excitation in wideband*/ - set16_fx( st_fx->mem_genSHBexc_filt_down_shb_fx, 0, 2*ALLPASSSECTIONS_STEEP+1); - set16_fx( st_fx->mem_genSHBexc_filt_down_wb2_fx, 0, 2*ALLPASSSECTIONS_STEEP+1); - set16_fx( st_fx->mem_genSHBexc_filt_down_wb3_fx, 0, 2*ALLPASSSECTIONS_STEEP+1); - set16_fx( st_fx->state_lsyn_filt_shb_fx,0, 2 * ALLPASSSECTIONS_STEEP ); - set16_fx( st_fx->state_lsyn_filt_dwn_shb_fx,0, 2 * ALLPASSSECTIONS_STEEP ); - set16_fx( st_fx->state_32and48k_WB_upsample_fx, 0, 2 * ALLPASSSECTIONS_STEEP ); - - /* States for the local synthesis filters */ - set16_fx( st_fx->syn_overlap_fx, 0, L_SHB_LAHEAD ); - - /* States for FEC */ - - IF( st_fx->extl_fx != WB_TBE ) - { - FOR( i = 0; i < LPC_SHB_ORDER; i++ ) - { - st_fx->lsp_prevfrm_fx[i] = f; - move16(); /*Q15*/ - f = add( f, inc ); - move16(); - } - } - ELSE - { - FOR( i = 0; i < LPC_SHB_ORDER_WB; i++ ) - { - st_fx->lsp_prevfrm_fx[i] = f; - move16();/*Q15*/ - f = add( f, inc ); - move16(); - } - } - st_fx->GainFrame_prevfrm_fx = 0; - move16();/*Q18*/ - st_fx->GainAttn_fx = 32767; - move16();/*Q15*/ - st_fx->tbe_demph_fx = 0; - st_fx->tbe_premph_fx = 0; - set16_fx(st_fx->mem_stp_swb_fx, 0, LPC_SHB_ORDER); - st_fx->gain_prec_swb_fx = 16384;/*Q14 =1*/ - set16_fx( &st_fx->GainShape_Delay[0], 0, NUM_SHB_SUBFR / 2 ); - - set16_fx(st_fx->old_core_synth_fx, 0, L_FRAME16k); - set16_fx(st_fx->old_tbe_synth_fx, 0, L_SHB_TRANSITION_LENGTH); - st_fx->tilt_swb_fec_fx = 0; - move16(); - - return; -} - - - - -/*==========================================================================*/ -/* FUNCTION : void wb_tbe_dec_fx () */ -/*--------------------------------------------------------------------------*/ -/* PURPOSE : WB TBE decoder, 6 - 8 kHz band decoding module */ -/*--------------------------------------------------------------------------*/ -/* INPUT ARGUMENTS : */ -/* _Word16 coder_type i : coding type */ -/* _Word32 *bwe_exc_extended i : bandwidth extended exciatation 2*Q_exc*/ -/* _Word16 Q_exc i : Q format */ -/* _Word16 voice_factors[] i : voicing factors Q15 */ -/*--------------------------------------------------------------------------*/ -/* OUTPUT ARGUMENTS : */ -/* _Word16 *synth o : WB synthesis/final synthesis Q_synth */ -/*--------------------------------------------------------------------------*/ -/* INPUT/OUTPUT ARGUMENTS : */ -/* Decoder_State_fx *st_fx, i/o: decoder state structure */ -/*--------------------------------------------------------------------------*/ -/* RETURN ARGUMENTS : */ -/* _ None */ -/*--------------------------------------------------------------------------*/ -/* CALLED FROM : */ -/*==========================================================================*/ -void wb_tbe_dec_fx( - Decoder_State_fx* st_fx, /* i/o: decoder state structure */ - const Word16 coder_type, /* i : coding type */ - Word32* bwe_exc_extended, /* i : bandwidth extended exciatation 2*Q_exc*/ - const Word16 Q_exc, - const Word16 voice_factors[], /* i : voicing factors */ - Word16* synth, /* o : WB synthesis/final synthesis */ - Word16* Q_synth -) -{ - Word16 i; - Word16 shaped_wb_excitation [ ( L_FRAME16k + L_SHB_LAHEAD )/4 ]; - Word16 shaped_wb_excitation_frac[ L_FRAME16k/4 ]; - Word16 bwe_exc_extended_16[ L_FRAME32k+40 ]; - Word16 exc4kWhtnd [ L_FRAME16k / 4]; - Word16 lsf_wb[ LPC_SHB_ORDER_WB ], lpc_wb[ LPC_SHB_ORDER_WB + 1 ], GainShape[ NUM_SHB_SUBFR ]; - Word32 GainFrame; - Word16 error[ L_FRAME16k ]; - Word16 synth_frac[ L_FRAME16k ]; - Word16 upsampled_synth[ L_FRAME48k ]; - Word32 prev_pow, curr_pow, curr_frame_pow; - Word16 curr_frame_pow_exp; - Word16 temp, scale, n; - Word16 j; - - Word16 Q_bwe_exc, Q_bwe_exc_ext, Qx; - Word16 n_mem, cnt; - Word16 max = 0; - Word32 L_tmp, Lacc, Lscale, Lmax = 0; - Word16 tmp, exp, sc; - Word16 vf_modified[ NB_SUBFR16k ]; - Word16 uv_flag = 0; - Word16 dummy=0; - Word32 dummy2[HILBERT_MEM_SIZE]= {0}; - Word16 f, inc; - - IF( st_fx->bws_cnt_fx == 0 ) - { - /* Initialization */ - set16_fx(GainShape, 11469/*0.35f Q15*/, NUM_SHB_SUBFR); - GainFrame = 1; - - IF( !st_fx->bfi_fx ) - { - IF(sub(st_fx->use_partial_copy,1)==0) - { - IF(sub(st_fx->last_extl_fx, WB_TBE) != 0) - { - st_fx->GainFrame_prevfrm_fx = 0; - st_fx->lsp_prevfrm_fx[0] = 3277/*0.1f Q15*/; - move16(); - FOR (i=1; ilsp_prevfrm_fx[i] = add(st_fx->lsp_prevfrm_fx[i-i], 3277/*0.1f Q15*/); - } - } - Copy( st_fx->lsp_prevfrm_fx, lsf_wb, LPC_SHB_ORDER_LBR_WB ); - set16_fx( GainShape, RECIP_ROOT_EIGHT_FX, NUM_SHB_SUBFR/2 ); - - IF( sub(st_fx->rf_frame_type,RF_NELP) == 0 ) - { - /* Frame gain */ - st_fx->rf_indx_tbeGainFr = s_and(st_fx->rf_indx_tbeGainFr, 0xF); /* only four LSBs are valid */ - Copy32( SHBCB_FrameGain16_fx + st_fx->rf_indx_tbeGainFr, &GainFrame, 1 ); - IF( sub(st_fx->core_fx,ACELP_CORE) == 0 && sub(st_fx->last_core_fx,ACELP_CORE) == 0 - && !st_fx->prev_use_partial_copy && sub(st_fx->prev_coder_type_fx,UNVOICED) == 0 - && L_sub(GainFrame,st_fx->GainFrame_prevfrm_fx) != 0 && sub(st_fx->last_extl_fx, WB_TBE) == 0 ) - { - /*GainFrame = 0.2f*GainFrame + 0.8f*st_fx->GainFrame_prevfrm_fx;*/ - GainFrame = L_add(Mult_32_16(st_fx->GainFrame_prevfrm_fx, 26214), Mult_32_16(GainFrame, 6553)); - } - } - ELSE - { - temp = 0; - move16(); - /* Frame gain */ - SWITCH (st_fx->rf_indx_tbeGainFr) - { - case 0: - GainFrame = 131072; /* 0.5f in Q18 */ - IF(L_sub(st_fx->GainFrame_prevfrm_fx, 327680l/*1.25 Q18*/) <= 0) temp = 26214/*0.8 Q15*/; - move16(); - BREAK; - case 1: - GainFrame = 524288; /* 2.0f in Q18 */ - IF(L_sub(st_fx->GainFrame_prevfrm_fx, 327680l/*1.25 Q18*/) > 0 && L_sub(st_fx->GainFrame_prevfrm_fx, 786432l/*3 Q18*/) <= 0) temp = 26214/*0.8 Q15*/; - move16(); - test(); - BREAK; - case 2: - GainFrame = 1048576;/* 4.0f in Q18 */ - IF(L_sub(st_fx->GainFrame_prevfrm_fx, 786432l/*3 Q18*/) > 0 && L_sub(st_fx->GainFrame_prevfrm_fx, 1572864l/*6 Q18*/) <= 0) temp = 26214/*0.8 Q15*/; - move16(); - test(); - BREAK; - case 3: - GainFrame = 2097152;/* 8.0f in Q18 */ - IF(L_sub(st_fx->GainFrame_prevfrm_fx, 1572864l/*6 Q18*/) > 0 && L_sub(st_fx->GainFrame_prevfrm_fx, 4194304l/*16 Q18*/) <= 0) temp = 26214/*0.8 Q15*/; - move16(); - test(); - BREAK; - default: - fprintf(stderr, "RF SWB-TBE gain bits not supported."); - } - IF(sub(st_fx->last_extl_fx, WB_TBE) == 0) - { - - GainFrame = L_add(Mult_32_16(st_fx->GainFrame_prevfrm_fx, temp), Mult_32_16(GainFrame, sub(32767,temp))); - } - IF(sub(st_fx->core_fx,ACELP_CORE) == 0 && sub(st_fx->last_core_fx,ACELP_CORE) == 0) - { - IF(!st_fx->prev_use_partial_copy && sub(st_fx->last_coder_type_fx, VOICED) == 0 && sub(st_fx->rf_frame_type,RF_GENPRED) == 0 - && sub(st_fx->prev_tilt_code_dec_fx,1497) < 0 && sub(st_fx->prev_tilt_code_dec_fx,200) > 0 ) - { - GainFrame = Mult_32_16(GainFrame,9830); - } - } - } - } - ELSE - { - /* de-quantization */ - dequantizeSHBparams_fx_9_1( st_fx, st_fx->extl_fx, st_fx->extl_brate_fx, lsf_wb, GainShape, &GainFrame, &uv_flag, 0, 0, 0 ); - } - } - ELSE - { - IF( L_sub( st_fx->extl_brate_fx, WB_TBE_0k35) == 0 ) - { - Copy( st_fx->lsp_prevfrm_fx, lsf_wb, LPC_SHB_ORDER_LBR_WB ); - } - ELSE - { - Copy( st_fx->lsp_prevfrm_fx, lsf_wb, LPC_SHB_ORDER_WB ); - } - set16_fx( GainShape, RECIP_ROOT_EIGHT_FX, NUM_SHB_SUBFR / 2 ); - - st_fx->GainAttn_fx = mult_r( st_fx->GainAttn_fx, 27853 ); - move16(); - - IF(sub(st_fx->codec_mode, MODE1) == 0) - { - GainFrame = Mult_32_16( st_fx->GainFrame_prevfrm_fx, st_fx->GainAttn_fx ); /*Q18*/ - } - ELSE - { - GainFrame = st_fx->GainFrame_prevfrm_fx; /*Q18*/ - } - } - - IF( st_fx->extl_brate_fx == WB_TBE_0k35 ) - { - /* convert LSPs back into LP coeffs */ - lsp2lpc_fx( lpc_wb + 1, lsf_wb, st_fx->prev_lpc_wb_fx, LPC_SHB_ORDER_LBR_WB ); - set16_fx( lpc_wb + LPC_SHB_ORDER_LBR_WB + 1, 0, ( LPC_SHB_ORDER_WB - LPC_SHB_ORDER_LBR_WB ) ); - FOR( i = 0; i < LPC_SHB_ORDER_WB; i++ ) - { - st_fx->prev_lpc_wb_fx[i] = lpc_wb[i + 1]; - move16(); - } - FOR( i = 1; i < LPC_SHB_ORDER_LBR_WB + 1; i++ ) - { - lpc_wb[i] = negate( lpc_wb[i] ); - move16(); - } - lpc_wb[0] = 4096; - move16(); - } - ELSE - { - /* convert LSPs back into LP coeffs */ - lsp2lpc_fx( lpc_wb + 1, lsf_wb, st_fx->prev_lpc_wb_fx, LPC_SHB_ORDER_WB ); - FOR( i = 0; i < LPC_SHB_ORDER_WB; i++ ) - { - st_fx->prev_lpc_wb_fx[i] = lpc_wb[i + 1]; - move16(); - } - FOR( i = 1; i < LPC_SHB_ORDER_WB + 1; i++ ) - { - lpc_wb[i] = negate( lpc_wb[i] ); - move16(); - } - lpc_wb[0] = 4096; - move16(); - } - - Copy( voice_factors, vf_modified, NB_SUBFR16k ); - IF( coder_type == VOICED ) - { - FOR( i = 1; i < NB_SUBFR; i++ ) - { - vf_modified[i] = add( mult_r( 26214, voice_factors[i] ), mult_r( 6554, voice_factors[i - 1] ) ); /* Q15 */ move16(); - } - IF( st_fx->L_frame_fx != L_FRAME ) - { - vf_modified[4] = add( mult_r( 26214, voice_factors[4] ), mult_r( 6554, voice_factors[3] ) ); /* Q15 */ move16(); - } - } - - /* From low band excitation, generate highband excitation */ - Lmax = 0; - FOR( cnt = 0; cnt < L_FRAME32k; cnt++ ) - { - Lmax = L_max( Lmax, L_abs( bwe_exc_extended[cnt] ) ); - } - Q_bwe_exc = ( Lmax == 0 )?31:norm_l( Lmax ); - Q_bwe_exc = sub( Q_bwe_exc, 1 ); - Q_bwe_exc = add( Q_bwe_exc, add( Q_exc, Q_exc ) ); - - find_max_mem_wb( st_fx, &n_mem ); - - if( sub( Q_bwe_exc, st_fx->prev_Q_bwe_exc ) > n_mem ) - { - Q_bwe_exc = add( st_fx->prev_Q_bwe_exc, n_mem ); - } - - test(); - if( uv_flag && sub( Q_bwe_exc, 20 ) > 0) - { - Q_bwe_exc = 20; - move16(); /* restrict this to 21 due to the Q factor requireemnt of the random number generator (keep 1 bit headroom) */ - } - - prev_pow = 0; - FOR( i = 0; i < L_SHB_LAHEAD / 4; i++ ) - { - prev_pow = L_mac0( prev_pow, st_fx->state_syn_shbexc_fx[i], st_fx->state_syn_shbexc_fx[i] ); /*Q(2*(st_fx->prev_Q_bwe_exc-16))*/ - } - - rescale_genWB_mem( st_fx, sub( Q_bwe_exc, st_fx->prev_Q_bwe_exc ) ); - - Copy( st_fx->old_bwe_exc_extended_fx, bwe_exc_extended_16, NL_BUFF_OFFSET ); - sc = sub( Q_bwe_exc, add( Q_exc, Q_exc ) ); - FOR( cnt = 0; cnt < L_FRAME32k; cnt++ ) - { - bwe_exc_extended_16[cnt + NL_BUFF_OFFSET] = round_fx( L_shl( bwe_exc_extended[cnt], sc ) ); - } - Copy( bwe_exc_extended_16 + L_FRAME32k, st_fx->old_bwe_exc_extended_fx, NL_BUFF_OFFSET ); - - Copy( st_fx->state_syn_shbexc_fx, shaped_wb_excitation, L_SHB_LAHEAD / 4 ); - - Q_bwe_exc_ext = sub( Q_bwe_exc, 16 ); - - GenShapedWBExcitation_fx( shaped_wb_excitation + L_SHB_LAHEAD / 4, lpc_wb, exc4kWhtnd, st_fx->mem_csfilt_fx, - st_fx->mem_genSHBexc_filt_down_shb_fx, st_fx->mem_genSHBexc_filt_down_wb2_fx, - st_fx->mem_genSHBexc_filt_down_wb3_fx, st_fx->state_lpc_syn_fx, coder_type, - bwe_exc_extended_16, Q_bwe_exc_ext, st_fx->bwe_seed_fx, vf_modified, uv_flag - , st_fx->igf - ); - - curr_pow = 0; - FOR( i = 0; i < L_SHB_LAHEAD / 4; i++ ) - { - curr_pow = L_mac0( curr_pow, shaped_wb_excitation[i + L_SHB_LAHEAD / 4], shaped_wb_excitation[i + - L_SHB_LAHEAD / 4] ); /* Q(2*Q_bwe_exc_ext) */ - } - - if( sub( voice_factors[0], 24576 ) > 0 ) - { - curr_pow = L_shr( curr_pow, 2 ); /* Q(2*Q_bwe_exc_ext) */ - } - - Lscale = root_a_over_b_fx( curr_pow, shl_r( Q_bwe_exc_ext, 1 ), prev_pow, - shl_r( sub( st_fx->prev_Q_bwe_exc, 16 ), 1 ), &exp ); - - FOR( i = 0; i < L_SHB_LAHEAD / 4 - 1; i++ ) - { - L_tmp = Mult_32_16( Lscale, shaped_wb_excitation[i] ); /* Q(16-exp+Q_bwe_exc_ext) */ - shaped_wb_excitation[i] = round_fx( L_shl( L_tmp, exp ) ); /* Q_bwe_exc_ext */ - } - Lscale = root_a_fx( Lscale, 31 - exp, &exp ); - L_tmp = Mult_32_16( Lscale, shaped_wb_excitation[L_SHB_LAHEAD / 4 - 1] ); /* Q(16-exp+Q_bwe_exc_ext) */ - shaped_wb_excitation[L_SHB_LAHEAD / 4 - 1] = round_fx( L_shl( L_tmp, exp ) ); /* Q_bwe_exc_ext */ - - /* Update SHB excitation */ - Copy( shaped_wb_excitation + L_FRAME16k / 4, st_fx->state_syn_shbexc_fx, L_SHB_LAHEAD / 4 ); - - - /* Adjust the subframe and frame gain of the synthesized shb signal */ - /* Scale the shaped excitation */ - ScaleShapedWB_fx( SHB_OVERLAP_LEN / 2, shaped_wb_excitation, st_fx->syn_overlap_fx, GainShape, GainFrame, - window_wb_fx, subwin_wb_fx, - Q_bwe_exc_ext - , st_fx->L_frame_fx - , 0 - , &dummy - , dummy - , dummy2 - ); - - max = 0; - FOR( i = 0; i < L_FRAME16k / 4; i++ ) - { - max = s_max( max, shaped_wb_excitation[i] ); /*Q0*/ - } - - IF( max == 0 ) - { - curr_frame_pow = 1; - move16(); - n = 0; - move16(); - } - ELSE - { - n = norm_s( max ); - FOR( i = 0; i < L_FRAME16k / 4; i++ ) - { - shaped_wb_excitation_frac[i] = shl( shaped_wb_excitation[i], n ); /*Q14*/ move16(); - } - n = sub( 14, n ); - curr_frame_pow = 1; - FOR( i = 0; i < L_FRAME16k / 4; i++ ) - { - L_tmp = L_mult( shaped_wb_excitation_frac[i], shaped_wb_excitation_frac[i] ); /*Q29*/ - curr_frame_pow = L_add( curr_frame_pow, L_shr( L_tmp, 7 ) ); /*Q22*/ - } - } - curr_frame_pow_exp = add( n, n ); - - IF ( sub(st_fx->prev_frame_pow_exp, curr_frame_pow_exp) > 0 ) - { - curr_frame_pow = L_shr( curr_frame_pow, sub( st_fx->prev_frame_pow_exp, curr_frame_pow_exp ) ); - curr_frame_pow_exp = st_fx->prev_frame_pow_exp; - } - ELSE - { - st_fx->prev_wb_bwe_frame_pow_fx = L_shr( st_fx->prev_wb_bwe_frame_pow_fx, sub( curr_frame_pow_exp, st_fx->prev_frame_pow_exp ) ); - } - - test(); - IF( !st_fx->bfi_fx && st_fx->prev_bfi_fx ) - { - IF( L_sub( L_shr( curr_frame_pow, 1 ), st_fx->prev_wb_bwe_frame_pow_fx ) > 0 ) - { - L_tmp = root_a_over_b_fx( st_fx->prev_wb_bwe_frame_pow_fx, 22, curr_frame_pow, 22, &exp ); - scale = round_fx( L_shl( L_tmp, exp ) ); /*Q15*/ - - L_tmp = root_a_fx( L_tmp, 31 - exp, &exp ); - L_tmp = root_a_fx( L_tmp, 31 - exp, &exp ); - L_tmp = root_a_fx( L_tmp, 31 - exp, &exp ); - temp = round_fx( L_shl( L_tmp, exp ) ); /* Q15 */ - } - ELSE - { - scale = temp = 32767; - move16();/* Q15 */ - } - - FOR( j = 0; j < 8; j++ ) - { - GainShape[2 * j] = mult_r( GainShape[2 * j], scale ); - GainShape[2 * j + 1] = mult_r( GainShape[2 * j + 1], scale ); - FOR( i = 0; i < L_FRAME16k / ( 4 * 8 ); i++ ) - { - shaped_wb_excitation[i + j * L_FRAME16k / ( 4 * 8 )] = mult_r( shaped_wb_excitation[i + j * L_FRAME16k / ( 4 * 8 )], scale ); - } - IF( temp > 0 ) - { - IF( sub( scale, temp ) < 0 ) - { - scale = div_s( scale, temp ); - } - ELSE - { - scale = 32767; - move16(); - } - } - ELSE - { - scale = 0; - move16(); - } - } - } - - st_fx->prev_wb_bwe_frame_pow_fx = curr_frame_pow; - move32(); - st_fx->prev_frame_pow_exp = curr_frame_pow_exp; - move16(); - - /* generate 16kHz SHB signal (6 - 8 kHz) from 2kHz signal */ - max = 0; - move16(); - FOR( cnt = 0; cnt < ( L_FRAME16k + L_SHB_LAHEAD ) / 4; cnt++ ) - { - if( abs_s( shaped_wb_excitation[cnt] ) > max ) - { - max = abs_s( shaped_wb_excitation[cnt] ); - } - } - Qx = norm_s( max ); - if ( max == 0 ) - { - Qx = 15; - move16(); - } - - Qx = sub( Qx, 1 ); /* 1 bit space for saturation */ - - max = 0; - move16(); - FOR( i = 0; i < 2*ALLPASSSECTIONS_STEEP; i++ ) - { - if( abs_s( st_fx->state_lsyn_filt_shb_fx[i] ) > max ) - max = abs_s( st_fx->state_lsyn_filt_shb_fx[i] ); - } - - FOR( i = 0; i < 2*ALLPASSSECTIONS_STEEP; i++ ) - { - if( abs_s( st_fx->state_lsyn_filt_dwn_shb_fx[i] ) > max ) - max = abs_s( st_fx->state_lsyn_filt_dwn_shb_fx[i] ); - } - - IF( L_sub(st_fx->output_Fs_fx, 32000) == 0 ) - { - FOR ( i = 0; i < 2*ALLPASSSECTIONS_STEEP; i++ ) - { - max = s_max(max, abs_s( st_fx->state_32and48k_WB_upsample_fx[i] )); - } - } - IF( L_sub(st_fx->output_Fs_fx, 48000) == 0 ) - { - FOR ( i = 0; i < INTERP_3_1_MEM_LEN; i++ ) - { - max = s_max(max, abs_s( st_fx->mem_resamp_HB_fx[i] )); - } - } - n_mem = 15; - if( max != 0 ) - { - n_mem = norm_s( max ); - } - n_mem = s_max( n_mem, 0 ); - - if( sub( Qx, st_fx->prev_Qx ) > n_mem ) - Qx = add( st_fx->prev_Qx, n_mem ); - - FOR( i = 0; i < ( L_FRAME16k + L_SHB_LAHEAD ) / 4; i++ ) - { - shaped_wb_excitation[i] = shl( shaped_wb_excitation[i], Qx ); - move16(); - } - - FOR( i = 0; i < 2*ALLPASSSECTIONS_STEEP; i++ ) - { - st_fx->state_lsyn_filt_shb_fx[i] = shl( st_fx->state_lsyn_filt_shb_fx[i], sub( Qx, st_fx->prev_Qx ) ); - move16(); - } - - FOR( i = 0; i < 2*ALLPASSSECTIONS_STEEP; i++ ) - { - st_fx->state_lsyn_filt_dwn_shb_fx[i] = shl( st_fx->state_lsyn_filt_dwn_shb_fx[i], sub( Qx, st_fx->prev_Qx ) ); - move16(); - } - - GenWBSynth_fx( shaped_wb_excitation, error, st_fx->state_lsyn_filt_shb_fx, st_fx->state_lsyn_filt_dwn_shb_fx ); - - Copy( error + L_FRAME16k - L_SHB_TRANSITION_LENGTH, st_fx->old_tbe_synth_fx, L_SHB_TRANSITION_LENGTH ); - - FOR( i = 0; i < L_FRAME16k; i++ ) - { - synth[i] = mult_r( error[i], 21299 ); - move16(); - } - - max = 0; - move16(); - FOR( cnt = 0; cnt < L_FRAME16k; cnt++ ) - { - max = s_max( max, abs_s( synth[cnt] ) ); - } - - IF( max == 0 ) - { - st_fx->last_wb_bwe_ener_fx = 0; - move16(); - } - ELSE - { - n = norm_s( max ); - FOR( cnt = 0; cnt < L_FRAME16k; cnt++ ) - { - synth_frac[cnt] = shl( synth[cnt], n ); /*Q14*/ move16(); - } - n = sub( sub( 14, n ), Qx ); - - Lacc = 0; - FOR( i = 0; i < L_FRAME16k; i++ ) - { - L_tmp = L_mult( synth_frac[i], synth_frac[i] ); /* Q29 */ - Lacc = L_add( Lacc, L_shr( L_tmp, 7 ) ); /* Q22 */ - } - - L_tmp = Mult_32_16( Lacc, 102 ); /* Q22 */ - exp = norm_l( L_tmp ); - tmp = round_fx( L_shl( L_tmp, exp ) ); - exp = sub( add( exp, 22 ), 30 ); - tmp = div_s( 16384, tmp ); - L_tmp = Isqrt_lc( L_deposit_h( tmp ), &exp ); /* Q(31-exp) */ - st_fx->last_wb_bwe_ener_fx = round_fx( L_shl( L_tmp, add( exp, n - 12 ) ) ); /* Q3 */ - } - - - IF( L_sub(st_fx->output_Fs_fx, 32000) == 0 ) /* 32kHz sampling rate, but only WB output - interpolate */ - { - Scale_sig(st_fx->state_32and48k_WB_upsample_fx, 2*ALLPASSSECTIONS_STEEP, sub( Qx, st_fx->prev_Qx )); - Interpolate_allpass_steep_fx( synth, st_fx->state_32and48k_WB_upsample_fx, L_FRAME16k, upsampled_synth ); - Copy( upsampled_synth, synth, L_FRAME32k ); - } - ELSE IF( L_sub(st_fx->output_Fs_fx, 48000) == 0 ) - { - Scale_sig(st_fx->mem_resamp_HB_fx, INTERP_3_1_MEM_LEN, sub( Qx, st_fx->prev_Qx )); - interpolate_3_over_1_allpass_fx( synth, L_FRAME16k, upsampled_synth, st_fx->mem_resamp_HB_fx, allpass_poles_3_ov_2 ); - Copy( upsampled_synth, synth, L_FRAME48k ); - } - } - ELSE - { - f = 5461; - move16();/* Q15 */ - inc = 5461; - move16();/* Q15 */ - FOR( i = 0; i < LPC_SHB_ORDER_WB; i++ ) - { - lsf_wb[i] = f; - move16();/*Q15*/ - f = add( f, inc ); - move16(); - } - GainFrame = 0; /* Q18 */ - Qx = 0; - Q_bwe_exc = 31; - st_fx->prev_wb_bwe_frame_pow_fx = 4194l/*0.001f Q22*/; /* Q22 */ - st_fx->prev_frame_pow_exp = 0; - move16(); - } - - /* Update previous frame parameters for FEC */ - Copy( lsf_wb, st_fx->lsp_prevfrm_fx, LPC_SHB_ORDER_WB ); - st_fx->GainFrame_prevfrm_fx = GainFrame; /* Q18 */ - - if( !st_fx->bfi_fx ) - { - st_fx->GainAttn_fx = 32767; - move16(); - } - - *Q_synth = Qx; - move16(); - - st_fx->prev_Q_bwe_exc = Q_bwe_exc; - move16(); - st_fx->prev_Qx = Qx; - move16(); - - return; -} - - - -/*======================================================================================*/ -/* FUNCTION : void swb_tbe_dec_fx () */ -/*--------------------------------------------------------------------------------------*/ -/* PURPOSE : SWB TBE decoder, 6 - 14 kHz (or 7.5 - 15.5 kHz) band decoding module */ -/*--------------------------------------------------------------------------------------*/ -/* INPUT ARGUMENTS : */ -/* _(Word16) coder_type : coding type */ -/* _(Word16*) bwe_exc_extended :bandwidth extended exciatation Q0 */ -/* _(Word16[]) voice_factors :voicing factors Q15 */ -/* _(Word16*) Q_white_exc :Q Format of White Exc */ -/* _(Word16*) Q_synth :Q Format of Synthesis */ -/*--------------------------------------------------------------------------------------*/ -/* OUTPUT ARGUMENTS : */ -/* _(Word16*)synth : SHB synthesis/final synthesis Q_white_exc */ -/* _(Word16*)White_exc16k : shaped white excitation for the FB TBE Q_synth */ -/*--------------------------------------------------------------------------------------*/ -/* INPUT/OUTPUT ARGUMENTS : */ -/* _ Decoder_State_fx *st_fx: : Decoder state structure */ -/*--------------------------------------------------------------------------------------*/ -/* RETURN ARGUMENTS : */ -/* _ None */ -/*--------------------------------------------------------------------------------------*/ -/* CALLED FROM : RX */ -/*======================================================================================*/ -void swb_tbe_dec_fx( - Decoder_State_fx* st_fx, /* i/o: decoder state structure */ - const Word16 coder_type, /* i : coding type */ - Word32* bwe_exc_extended, /* i : bandwidth extended excitation 2*Q_exc */ - Word16 Q_exc, - const Word16 voice_factors[], /* i : voicing factors */ - const Word16 old_syn_12k8_16k[], /* i : low band synthesis */ - Word16* White_exc16k, /* o : shaped white excitation for the FB TBE */ - Word16* Q_white_exc, - Word16* synth, /* o : SHB synthesis/final synthesis */ - Word16* Q_synth, - Word16* pitch_buf /* i : pitch buffer Q6 */ -) -{ - Word16 i; - Word16 shaped_shb_excitation [ L_FRAME16k + L_SHB_LAHEAD ]; - Word16 bwe_exc_extended_16[L_FRAME32k+NL_BUFF_OFFSET]; - Word16 lsf_shb[LPC_SHB_ORDER], lpc_shb[LPC_SHB_ORDER + 1], GainShape[NUM_SHB_SUBFR]; - Word32 GainFrame; - Word16 error[L_FRAME32k]; - Word32 L_ener; - Word16 ener; - Word16 is_fractive; - Word32 prev_pow, curr_pow, Lscale; - Word16 scale; - Word16 exp, tmp; - Word16 j, cnt ; - Word16 n_mem, n_mem2, Qx, sc; - Word16 n_mem3; - Word32 Lmax, L_tmp; - Word16 frac; - - Word32 L_tmp1, L_tmp2; - Word16 expa, expb; - Word16 fraca, fracb; - Word16 GainShape_tmp[NUM_SHB_SUBGAINS]; - Word16 Q_bwe_exc; - Word16 Q_shb; - Word16 vf_modified[NB_SUBFR16k]; - Word16 stemp; - - Word16 tilt_swb_fec; - Word16 Q_bwe_exc_fb; - - Word16 lsp_shb_1[LPC_SHB_ORDER], lsp_shb_2[LPC_SHB_ORDER], lsp_temp[LPC_SHB_ORDER]; - Word16 lpc_shb_sf[4*(LPC_SHB_ORDER+1)]; - const Word16 *ptr_lsp_interp_coef; - Word32 shb_ener_sf_32; - Word16 shb_res_gshape[NB_SUBFR16k]; - Word16 mixFactors; - Word16 vind; - Word16 shb_res_dummy[L_FRAME16k]; - Word16 shaped_shb_excitationTemp[L_FRAME16k]; - Word32 ener_tmp[NUM_SHB_SUBGAINS]; - Word16 pitch_fx; - Word16 l_subframe_fx; - Word16 formant_fac; - Word16 lsf_diff[LPC_SHB_ORDER], w[LPC_SHB_ORDER]; - Word16 refl[M]; - Word16 tilt_para; - Word16 tmp1,tmp2; - Word16 f_fx, inc_fx; - Word32 GainFrame_prevfrm_fx; - - Word16 synth_scale_fx; - Word16 mean_vf; - Word16 exp_ener, inv_ener; - Word32 prev_ener_ratio_fx=0; /* initialize just to avoid compiler warning */ - Word16 max,n,temp,shaped_shb_excitation_frac [ L_FRAME16k + L_SHB_LAHEAD ]; - Word32 curr_frame_pow; - Word16 curr_frame_pow_exp; - Word32 L_prev_ener_shb; - /* initializations */ - GainFrame = L_deposit_l(0); - mixFactors = 0; - move16(); - shb_ener_sf_32 = L_deposit_l(0); - set16_fx( shaped_shb_excitationTemp, 0, L_FRAME16k ); - st_fx->shb_dtx_count_fx = 0; - move16(); - is_fractive = 0; - move16(); - set16_fx( shb_res_gshape, 1638/*0.1f Q14*/, NB_SUBFR16k ); /* Q14 */ - Q_shb = 0; /* high band target Q factor set to zero */ - - L_tmp = calc_tilt_bwe_fx(old_syn_12k8_16k, st_fx->Q_syn2, st_fx->L_frame_fx); - tilt_swb_fec = round_fx(L_shl(L_tmp, 3)); - /* i: old_syn_12k8_16k in st_fx->Q_syn2 */ - /* o: tilt_swb_fec in Q11 */ - test(); - IF( st_fx->bfi_fx && sub(st_fx->clas_dec,UNVOICED_CLAS) != 0 ) - { - tilt_swb_fec = st_fx->tilt_swb_fec_fx; - move16(); - } - - /* WB/SWB bandwidth switching */ - test(); - test(); - IF( ( sub(st_fx->tilt_wb_fx, 10240) > 0 && sub(st_fx->clas_dec, UNVOICED_CLAS) == 0 ) || sub(st_fx->tilt_wb_fx, 20480) > 0 ) - { - test(); - test(); - test(); - test(); - test(); - test(); - test(); - IF( (st_fx->prev_fractive_fx == 0 && - (L_sub( st_fx->prev_enerLH_fx, L_shl( st_fx->enerLH_fx, 1 ) ) < 0 && L_sub( st_fx->prev_enerLH_fx, L_shr( st_fx->enerLH_fx, 1 ) ) > 0 - && L_sub( st_fx->prev_enerLL_fx, L_shl( st_fx->enerLL_fx, 1 ) ) < 0 && L_sub( st_fx->prev_enerLL_fx, L_shr( st_fx->enerLL_fx, 1 ) ) > 0)) - || (sub(st_fx->prev_fractive_fx,1) == 0 && - L_sub(L_shr(st_fx->prev_enerLH_fx,2), Mult_32_16(st_fx->enerLH_fx,24576)) > 0 ) /* 24576 in Q13*/ - || (L_sub(L_shr(st_fx->enerLL_fx,1), Mult_32_16(st_fx->enerLH_fx, 24576)) > 0 && /*24576 = 1.5 in Q14*/ - sub(st_fx->tilt_wb_fx, 20480) < 0 )/* 20480 = 10 in Q11*/ - ) - { - is_fractive = 0; - move16(); - } - ELSE - { - is_fractive = 1; - move16(); - } - } - - /* WB/SWB bandwidth switching */ - IF( st_fx->bws_cnt_fx > 0 ) - { - f_fx = 1489; /*Q15*/ - inc_fx = 1489; /*Q15*/ - IF(sub(is_fractive, 1) == 0) - { - Copy(lsf_tab_fx, st_fx->lsp_prevfrm_fx, LPC_SHB_ORDER); - } - ELSE - { - FOR (i=0; ilsp_prevfrm_fx[i] = f_fx; - move16(); - f_fx = add(f_fx, inc_fx); - } - } - test(); - test(); - test(); - test(); - test(); - test(); - test(); - IF( (sub(st_fx->last_extl_fx, SWB_TBE) != 0 && sub(st_fx->last_extl_fx, FB_TBE) != 0 && - !(L_sub(L_shr(st_fx->prev_enerLH_fx, 1), st_fx->enerLH_fx) < 0 &&L_sub(st_fx->prev_enerLH_fx, L_shr(st_fx->enerLH_fx,1)>0))) - || sub(st_fx->last_core_fx, ACELP_CORE) != 0 - || (sub(st_fx->last_core_fx, ACELP_CORE) == 0 && L_sub(L_abs(L_sub(st_fx->last_core_brate_fx, st_fx->core_brate_fx)), 3600) > 0) - || sub((is_fractive ^ st_fx->prev_fractive_fx), 1) == 0 ) - { - set16_fx( GainShape, 11587, NUM_SHB_SUBFR ); - } - ELSE - { - if(sub(st_fx->prev_GainShape_fx, 11587) > 0) - { - st_fx->prev_GainShape_fx = 11587; - move16(); - } - set16_fx( GainShape, st_fx->prev_GainShape_fx, NUM_SHB_SUBFR ); - } - - Copy( st_fx->lsp_prevfrm_fx, lsf_shb, LPC_SHB_ORDER ); - set16_fx( shb_res_gshape, 3277/*0.2f Q14*/, NB_SUBFR16k ); /* Q14 */ - } - ELSE /* No bandwidth switching */ - { - test(); - IF( sub(st_fx->last_extl_fx, SWB_TBE) != 0 && sub(st_fx->last_extl_fx, FB_TBE) != 0 ) - { - f_fx = 1489; /*Q15*/ move16(); - inc_fx = 1489; /*Q15*/ move16(); - FOR (i=0; ilsp_prevfrm_fx[i] = f_fx; - move16(); - f_fx = add(f_fx, inc_fx); - } - } - - IF( !st_fx->bfi_fx ) - { - IF(st_fx->use_partial_copy) - { - IF(sub(st_fx->last_extl_fx, SWB_TBE) != 0) - { - st_fx->GainFrame_prevfrm_fx = 0; - move16(); - move16(); - move16(); - f_fx = 1489/*0.045454f Q15*/; /*Q15*/ - inc_fx = 1489/*0.045454f Q15*/;; /*Q15*/ - FOR (i=0; ilsp_prevfrm_fx[i] = f_fx; - move16(); - f_fx = add(f_fx, inc_fx); - } - } - Copy( st_fx->lsp_prevfrm_fx, lsf_shb, LPC_SHB_ORDER ); - set16_fx( GainShape, RECIP_ROOT_EIGHT_FX, NUM_SHB_SUBFR ); - - IF( sub(st_fx->rf_frame_type,RF_NELP) == 0 ) - { - /* Frame gain */ - GainFrame = L_mac( SHB_GAIN_QLOW_FX, st_fx->rf_indx_tbeGainFr, SHB_GAIN_QDELTA_FX ); - move32();/*Q18*/ - L_tmp = Mult_32_16( GainFrame, 27213 ); /*Q16*/ /* 3.321928 in Q13 */ - - frac = L_Extract_lc( L_tmp, &exp ); - L_tmp = Pow2( 30, frac ); - GainFrame = L_shl( L_tmp, sub( exp, 12 ) ); /*Q18*/ - IF( sub(st_fx->core_fx,ACELP_CORE) == 0 && sub(st_fx->last_core_fx,ACELP_CORE) == 0 - && !st_fx->prev_use_partial_copy && sub(st_fx->prev_coder_type_fx,UNVOICED) == 0 - && L_sub(GainFrame,st_fx->GainFrame_prevfrm_fx) != 0 && sub(st_fx->next_coder_type,GENERIC) != 0 && sub(st_fx->last_extl_fx, SWB_TBE) == 0) - { - /*GainFrame = 0.2f*GainFrame + 0.8f*st_fx->GainFrame_prevfrm_fx;*/ - GainFrame = L_add(Mult_32_16(st_fx->GainFrame_prevfrm_fx, 26214), Mult_32_16(GainFrame, 6553)); - } - } - ELSE - { - temp = 0; - move16(); - /* Frame gain */ - SWITCH (st_fx->rf_indx_tbeGainFr) - { - case 0: - GainFrame = 131072; /* 0.5f in Q18 */ - IF(L_sub(st_fx->GainFrame_prevfrm_fx, 327680l/*1.25 Q18*/) <= 0) temp = 26214/*0.8 Q15*/; - move16(); - BREAK; - case 1: - GainFrame = 524288; /* 2.0f in Q18 */ - IF(L_sub(st_fx->GainFrame_prevfrm_fx, 327680l/*1.25 Q18*/) > 0 && L_sub(st_fx->GainFrame_prevfrm_fx, 786432l/*3 Q18*/) <= 0) temp = 26214/*0.8 Q15*/; - move16(); - test(); - BREAK; - case 2: - GainFrame = 1048576;/* 4.0f in Q18 */ - IF(L_sub(st_fx->GainFrame_prevfrm_fx, 786432l/*3 Q18*/) > 0 && L_sub(st_fx->GainFrame_prevfrm_fx, 1572864l/*6 Q18*/) <= 0) temp = 26214/*0.8 Q15*/; - move16(); - test(); - BREAK; - case 3: - GainFrame = 2097152;/* 8.0f in Q18 */ - IF(L_sub(st_fx->GainFrame_prevfrm_fx, 1572864l/*6 Q18*/) > 0 && L_sub(st_fx->GainFrame_prevfrm_fx, 4194304l/*16 Q18*/) <= 0) temp = 26214/*0.8 Q15*/; - move16(); - test(); - BREAK; - default: - fprintf(stderr, "RF SWB-TBE gain bits not supported."); - } - IF(sub(st_fx->last_extl_fx, SWB_TBE) == 0) - { - GainFrame = L_add(Mult_32_16(st_fx->GainFrame_prevfrm_fx, temp), Mult_32_16(GainFrame, sub(32767,temp))); - } - IF(sub(st_fx->core_fx,ACELP_CORE) == 0 && sub(st_fx->last_core_fx,ACELP_CORE) == 0) - { - IF(!st_fx->prev_use_partial_copy && sub(st_fx->last_coder_type_fx, VOICED) == 0 && sub(st_fx->rf_frame_type,RF_GENPRED) == 0 && L_sub(GainFrame, 2097152) > 0 && L_sub(GainFrame, 3059606) < 0 ) - { - GainFrame = Mult_32_16(GainFrame,9830); - } - } - } - } - ELSE - { - - /* de-quantization */ - dequantizeSHBparams_fx_9_1( st_fx, st_fx->extl_fx, st_fx->extl_brate_fx, lsf_shb, GainShape, &GainFrame, &stemp, - &shb_ener_sf_32, shb_res_gshape, &mixFactors ); - Q_shb = 0; - move16(); - /* o: shb_ener_sf_32 in (2*Q_shb) */ - /* o: shb_res_gshape in Q14 */ - /* o: GainShape Q15 */ - /* o: GainFrame Q18 */ - } - } - ELSE /* FER concealment of TBE parameters */ - { - Copy( st_fx->lsp_prevfrm_fx, lsf_shb, LPC_SHB_ORDER ); - - /* Gain shape concealment */ - IF( sub(st_fx->codec_mode, MODE1) == 0 ) - { - /* Gradient based GS estimation */ - gradientGainShape(st_fx, GainShape, &GainFrame); - /* o: GainShape[16] in Q15 */ - /* o: GainFrame in Q18 */ - } - ELSE - { - FOR( i = 0; i < NUM_SHB_SUBFR / 4; i++ ) - { - FOR( j = 0; j < 4; j++ ) - { - GainShape[i * 4 + j] = mult_r( st_fx->cummulative_damping, st_fx->GainShape_Delay[4+i]); - move16(); - } - } - IF( sub( tilt_swb_fec, 8<<11 ) > 0 ) /* tilt_swb_fec in Q11 */ - { - IF ( sub(st_fx->nbLostCmpt, 1) == 0 ) - { - GainFrame = Mult_32_16(st_fx->GainFrame_prevfrm_fx, 19661/*0.6f Q15*/); - } - ELSE IF( sub(st_fx->nbLostCmpt, 2) == 0 ) - { - GainFrame = Mult_32_16(st_fx->GainFrame_prevfrm_fx, 11469/*0.35f Q15*/); - } - ELSE - { - GainFrame = Mult_32_16(st_fx->GainFrame_prevfrm_fx, 6554/*0.2f Q15*/); - } - GainFrame = Mult_32_16( GainFrame, st_fx->cummulative_damping); - } - ELSE - { - GainFrame = st_fx->GainFrame_prevfrm_fx; - move16(); /* gain locking */ - } - } - - /* FER concealment for 24.4kbps and 32kbps */ - test(); - IF(L_sub(st_fx->total_brate_fx,ACELP_24k40) == 0 || L_sub(st_fx->total_brate_fx, ACELP_32k) == 0) - { - IF(sub(st_fx->codec_mode, MODE1) == 0) - { - /*scale = st->prev1_shb_ener_sf/root_a(st->prev2_shb_ener_sf * st->prev3_shb_ener_sf); */ - L_tmp = L_mult(extract_l(st_fx->prev2_shb_ener_sf_fx), extract_l(st_fx->prev3_shb_ener_sf_fx)); /*Q1*/ - tmp = round_fx(root_a_fx(L_tmp, 1, &exp)); /* Q = 15-exp */ - tmp1 = extract_l(st_fx->prev1_shb_ener_sf_fx); /*Q0*/ - i = sub(norm_s(tmp1), 1); - tmp1 = shl(tmp1, i); /* Qi */ - if(tmp == 0) - { - tmp = 32767/*1.0f Q15*/; - move16(); /*Q15*/ - } - ELSE - { - scale = div_s(tmp1, tmp); /* Q15 - Q(15-exp) + Qi = Qexp+i */ - scale = s_max(scale, 0); - /*scale = st->prev_res_shb_gshape * min(scale, 1.0f); */ - tmp = shl(scale, 15 - exp - i); /*Q15*/ - } - scale = mult_r(st_fx->prev_res_shb_gshape_fx, tmp); /* Q14 */ - - test(); - IF( L_sub( L_shr(st_fx->prev2_shb_ener_sf_fx, 1), st_fx->prev1_shb_ener_sf_fx ) > 0 || - L_sub( L_shr(st_fx->prev3_shb_ener_sf_fx, 1), st_fx->prev2_shb_ener_sf_fx ) > 0 ) - { - /* shb_ener_sf_32 = 0.5f * scale * st_fx->prev1_shb_ener_sf_fx; */ - shb_ener_sf_32 = Mult_32_16( st_fx->prev1_shb_ener_sf_fx, scale ); - - if( sub(st_fx->nbLostCmpt, 1) > 0) - { - /* shb_ener_sf_32 *= 0.5f; */ - shb_ener_sf_32 = L_shr(shb_ener_sf_32, 1); - } - } - ELSE - { - /* shb_ener_sf = scale * scale * st_fx->prev1_shb_ener_sf_fx; */ - L_tmp = L_mult(scale, scale); /* Q29 */ - shb_ener_sf_32 = L_shl(Mult_32_16(st_fx->prev1_shb_ener_sf_fx, round_fx(L_tmp)), 2); - } - } - ELSE - { - test(); - IF( L_sub( L_shr(st_fx->prev2_shb_ener_sf_fx, 1), st_fx->prev1_shb_ener_sf_fx ) > 0 || - L_sub( L_shr(st_fx->prev3_shb_ener_sf_fx, 1), st_fx->prev2_shb_ener_sf_fx ) > 0 ) - { - /* shb_ener_sf_32 = 0.5f * st->cummulative_damping * st_fx->prev1_shb_ener_sf_fx; */ - shb_ener_sf_32 = L_shr( Mult_32_16( st_fx->prev1_shb_ener_sf_fx, st_fx->cummulative_damping ), 1 ); - } - ELSE - { - shb_ener_sf_32 = Mult_32_16( st_fx->prev1_shb_ener_sf_fx, st_fx->cummulative_damping ); - } - } - } - - shb_ener_sf_32 = L_max( shb_ener_sf_32, 1l/*1.0f Q0*/ ); - mixFactors = st_fx->prev_mixFactors_fx; - - IF(sub(st_fx->codec_mode, MODE1) == 0) - { - set16_fx( shb_res_gshape, 3277/*0.2f Q14*/, 5 ); /* Q14 */ - } - ELSE - { - set16_fx( shb_res_gshape, 16384/*1.0f Q14*/, 5 ); /* Q14 */ - } - } - } - - /* get the gainshape delay */ - Copy( &st_fx->GainShape_Delay[4], &st_fx->GainShape_Delay[0], NUM_SHB_SUBFR / 4 ); - IF ( (st_fx->rf_flag != 0) || L_sub(st_fx->total_brate_fx, ACELP_9k60) == 0 ) - { - FOR( i = 0; i < NUM_SHB_SUBFR / 4; i++ ) - { - st_fx->GainShape_Delay[i + 4] = s_min( s_max( GainShape[i * 4], 3277/*0.1f Q15*/ ), 16384/*0.5f Q15*/ ); - move16(); - } - } - ELSE - { - FOR( i = 0; i < NUM_SHB_SUBFR / 4; i++ ) - { - st_fx->GainShape_Delay[i + 4] = GainShape[i * 4]; - move16(); - } - } - - /* voice factor modification to limit any spurious jumps in the middle of voiced subframes*/ - /* mean(voice_factors[i], 4); */ - L_tmp = L_mult(voice_factors[0], 8192); - L_tmp = L_mac(L_tmp, voice_factors[1], 8192); - L_tmp = L_mac(L_tmp, voice_factors[2], 8192); - mean_vf = mac_r(L_tmp, voice_factors[3], 8192); - - Copy( voice_factors, vf_modified, NB_SUBFR16k ); - - test(); - IF( sub(coder_type, VOICED) == 0 || sub(mean_vf, 13107/*0.4f Q15*/ ) > 0 ) - { - FOR( i = 1; i < NB_SUBFR; i++ ) - { - L_tmp = L_mult(voice_factors[i], 26214/*0.8f Q15*/); - vf_modified[i] = mac_r(L_tmp, voice_factors[i-1], 6554/*0.2f Q15*/); - move16(); - } - IF( sub(st_fx->L_frame_fx, L_FRAME) != 0 ) - { - L_tmp = L_mult(voice_factors[4], 26214/*0.8f Q15*/); - vf_modified[4] = mac_r(L_tmp, voice_factors[3], 6554/*0.2f Q15*/); - move16(); - } - } - - /* convert quantized LSFs to LSPs for interpolation */ - E_LPC_lsf_lsp_conversion(lsf_shb, lsp_shb_2, LPC_SHB_ORDER); - - test(); - IF( sub(st_fx->last_extl_fx, SWB_TBE) == 0 || sub(st_fx->last_extl_fx, FB_TBE) == 0) - { - /* SHB LSP values from prev. frame for interpolation */ - Copy(st_fx->swb_lsp_prev_interp_fx, lsp_shb_1, LPC_SHB_ORDER); - } - ELSE - { - /* Use current frame's LSPs; in effect no interpolation */ - Copy(lsp_shb_2, lsp_shb_1, LPC_SHB_ORDER); - } - - test(); - test(); - test(); - IF( st_fx->bws_cnt_fx == 0 && st_fx->bws_cnt1_fx == 0 && st_fx->prev_use_partial_copy == 0 && st_fx->use_partial_copy == 0 ) - { - lsf_diff[0] = 16384; - move16(); /*Q15*/ - lsf_diff[sub(LPC_SHB_ORDER,1)] = 16384; - move16(); /*Q15*/ - FOR(i=1; i < LPC_SHB_ORDER-1; i++) - { - lsf_diff[i] = sub(lsf_shb[i],lsf_shb[sub(i,1)]); - move16(); - } - - a2rc_fx (st_fx->cur_sub_Aq_fx+1, refl, M); - tmp = add(16384, shr(refl[0],1)); /*Q14*/ - tmp1 = mult(27425,tmp); - tmp1 = mult(tmp1,tmp); /*Q10*/ - tmp2 = shr(mult(31715,tmp),2); /*Q10*/ - tilt_para = add(sub(tmp1,tmp2),1335); /*Q10*/ - - test(); - IF(sub(st_fx->last_extl_fx,SWB_TBE) != 0 && sub(st_fx->last_extl_fx,FB_TBE) != 0) - { - FOR( i=1; iprev_lsf_diff_fx[i-1] = shr(lsf_diff[i], 1); - move16(); - } - } - - IF( L_sub(st_fx->total_brate_fx,ACELP_16k40) <= 0 ) - { - test(); - test(); - test(); - test(); - test(); - IF(!(sub(st_fx->prev_tilt_para_fx,5120) > 0 && (sub(coder_type,TRANSITION) == 0 || sub(tilt_para,1024) < 0)) && - !(((sub(st_fx->prev_tilt_para_fx,3072) < 0 && sub(st_fx->prev_coder_type_fx,VOICED) >= 0)) && sub(tilt_para,5120) > 0)) - { - FOR( i = 1; i < LPC_SHB_ORDER-1; i++ ) - { - IF(sub(lsf_diff[i],st_fx->prev_lsf_diff_fx[i-1]) < 0) - { - tmp = mult(26214,lsf_diff[i]); - - test(); - IF( st_fx->prev_lsf_diff_fx[i-1] <= 0 || tmp < 0 ) /* safety check in case of bit errors */ - { - st_fx->BER_detect = 1; - move16(); - tmp = 0; - } - ELSE - { - tmp = div_s(tmp,st_fx->prev_lsf_diff_fx[i-1]); - } - - tmp = s_max(tmp,16384); - w[i] = s_min(tmp,32767); - move16(); - } - ELSE - { - tmp = mult(26214,st_fx->prev_lsf_diff_fx[i-1]); - - test(); - IF( lsf_diff[i] <= 0 || tmp < 0 ) /* safety check in case of bit errors */ - { - st_fx->BER_detect = 1; - move16(); - tmp = 0; - } - ELSE - { - tmp = div_s(tmp,lsf_diff[i]); - } - - tmp = s_max(tmp,16384); - w[i] = s_min(tmp,32767); - move16(); - } - } - w[0] = w[1]; - w[sub(LPC_SHB_ORDER,1)] = w[sub(LPC_SHB_ORDER,2)]; - - FOR( i = 0; i < LPC_SHB_ORDER; i++ ) - { - tmp1 = mult(lsp_shb_1[i],sub(32767,w[i])); - tmp2 = mult(lsp_shb_2[i],w[i]); - lsp_temp[i] =add(tmp1,tmp2); - move16(); - } - } - ELSE - { - Copy(lsp_shb_2, lsp_temp, LPC_SHB_ORDER); - } - } - - Copy( lsf_diff + 1, st_fx->prev_lsf_diff_fx, LPC_SHB_ORDER-2 ); - st_fx->prev_tilt_para_fx = tilt_para; - } - ELSE - { - Copy(lsp_shb_2, lsp_temp, LPC_SHB_ORDER); - } - - test(); - IF ( L_sub(st_fx->total_brate_fx, ACELP_24k40 ) == 0 || L_sub( st_fx->total_brate_fx, ACELP_32k) == 0 ) - { - /* ---------- SHB LSP interpolation ---------- */ - ptr_lsp_interp_coef = interpol_frac_shb; /*Q15*/ - FOR( j = 0; j < 4; j++ ) - { - FOR( i = 0; i < LPC_SHB_ORDER; i++ ) - { - /*lsp_temp_fx[i] = lsp_shb_1_fx[i]*(*ptr_lsp_interp_coef_fx) */ - /* + lsp_shb_2_fx[i]*(*(ptr_lsp_interp_coef_fx+1));*/ - L_tmp = L_mult(lsp_shb_1[i], (*ptr_lsp_interp_coef)); - lsp_temp[i] = mac_r(L_tmp, lsp_shb_2[i], (*(ptr_lsp_interp_coef+1))); - move16(); - } - ptr_lsp_interp_coef += 2; - - /* convert from lsp to lsf */ - /*old code: lsp2lsf_fx(lsp_temp, lsp_temp, LPC_SHB_ORDER, INT_FS_FX); */ /* input lsp_temp_fx in Q15*/ - - tmp = i_mult(j, (LPC_SHB_ORDER+1)); - /* convert LSPs to LP coefficients */ - E_LPC_f_lsp_a_conversion(lsp_temp, lpc_shb_sf+tmp, LPC_SHB_ORDER); - /* Bring the LPCs to Q12 */ - Copy_Scale_sig( lpc_shb_sf+tmp, lpc_shb_sf+tmp, LPC_SHB_ORDER+1, sub(norm_s(lpc_shb_sf[tmp]),2) ); - } - } - /*ELSE*/ - { - /* for 13.2 and 16.4kbps */ - E_LPC_f_lsp_a_conversion(lsp_temp, lpc_shb, LPC_SHB_ORDER); - Copy_Scale_sig( lpc_shb, lpc_shb, LPC_SHB_ORDER+1, sub(norm_s(lpc_shb[0]),2) ); /* Q12 */ - } - - /* Save the SWB LSP values from current frame for interpolation */ - Copy(lsp_shb_2, st_fx->swb_lsp_prev_interp_fx, LPC_SHB_ORDER); - /* lsp_shb_2_fx in Q15 */ - - /* save the shb_ener Q18, prev_resgainshape Q14, and mixFactor Q15 values */ - st_fx->prev3_shb_ener_sf_fx = st_fx->prev2_shb_ener_sf_fx; - st_fx->prev2_shb_ener_sf_fx = st_fx->prev1_shb_ener_sf_fx; - st_fx->prev1_shb_ener_sf_fx = shb_ener_sf_32; - st_fx->prev_res_shb_gshape_fx = shb_res_gshape[4]; - st_fx->prev_mixFactors_fx = mixFactors; - - /* SWB CNG/DTX - update memories */ - Copy( st_fx->lsp_shb_prev_fx, st_fx->lsp_shb_prev_prev_fx, LPC_SHB_ORDER ); /* Q15 */ - Copy( lsf_shb, st_fx->lsp_shb_prev_fx, LPC_SHB_ORDER ); /* Q15 */ - - /* vind = (short)(mixFactors*8.0f); */ - vind = shl(mixFactors,3-15); /* 3 for mpy by 8.0f, -15 to bring it to Q0 */ - /* i: mixFactors in Q15 */ - /* o: vind in Q0 */ - - /* Determine formant PF strength */ - formant_fac = swb_formant_fac_fx( lpc_shb[1], &st_fx->tilt_mem_fx ); - /* o: formant_fac in Q15 */ - - /* -------- start of memory rescaling -------- */ - /* ----- calculate optimum Q_bwe_exc and rescale memories accordingly ----- */ - Lmax = 0; - FOR( cnt = 0; cnt < L_FRAME32k; cnt++ ) - { - Lmax = L_max( Lmax, L_abs( bwe_exc_extended[cnt] ) ); - } - Q_bwe_exc = norm_l( Lmax ); - if(Lmax == 0) - { - Q_bwe_exc = 31; - } - Q_bwe_exc = add( Q_bwe_exc, add( Q_exc, Q_exc ) ); - - /* Account for any outliers in the memories from previous frame for rescaling to avoid saturation */ - find_max_mem_dec( st_fx, &n_mem, &n_mem2, &n_mem3 ); /* for >=24.4, use n_mem2 lpc_syn, shb_20sample, and mem_stp_swb_fx memory */ - - tmp = add( st_fx->prev_Q_bwe_exc, n_mem ); - if( sub( Q_bwe_exc, tmp) > 0 ) - { - Q_bwe_exc = tmp; - } - - /* rescale the memories if Q_bwe_exc is different from previous frame */ - sc = sub( Q_bwe_exc, st_fx->prev_Q_bwe_exc ); - IF( sc != 0 ) - { - rescale_genSHB_mem_dec( st_fx, sc ); - } - - /* rescale the bwe_exc_extended and bring it to 16-bit single precision with dynamic norm */ - Copy( st_fx->old_bwe_exc_extended_fx, bwe_exc_extended_16, NL_BUFF_OFFSET ); - sc = sub( Q_bwe_exc, add( Q_exc, Q_exc ) ); - - FOR( cnt = 0; cnt < L_FRAME32k; cnt++ ) - { - bwe_exc_extended_16[cnt + NL_BUFF_OFFSET] = round_fx( L_shl( bwe_exc_extended[cnt], sc ) ); - } - Copy( bwe_exc_extended_16 + L_FRAME32k, st_fx->old_bwe_exc_extended_fx, NL_BUFF_OFFSET ); - - /* state_syn_shbexc_fx is kept at (st_fx->prev_Q_bwe_syn) for 24.4/32kbps or is kept at Q_bwe_exc for 13.2/16.4kbps */ - Copy( st_fx->state_syn_shbexc_fx, shaped_shb_excitation, L_SHB_LAHEAD ); - - /* save the previous Q factor (32-bit) of the buffer */ - st_fx->prev_Q_bwe_exc = Q_bwe_exc; - move16(); - - Q_bwe_exc = sub( Q_bwe_exc, 16 ); /* Q_bwe_exc reflecting the single precision dynamic norm-ed buffers from here */ - - /* -------- end of rescaling memories -------- */ - Q_bwe_exc_fb = st_fx->prev_Q_bwe_exc_fb; - move16(); - - IF( L_sub(st_fx->total_brate_fx, ACELP_32k) > 0 ) - { - FOR( j = 0; j < 4; j++ ) - { - Copy(lpc_shb, &lpc_shb_sf[j*(LPC_SHB_ORDER+1)], LPC_SHB_ORDER+1); - } - } - - /* Calculate the 6 to 14 kHz (or 7.5 - 15.5 kHz) SHB excitation signal from the low band ACELP core excitation */ - GenShapedSHBExcitation_fx( shaped_shb_excitation + L_SHB_LAHEAD, lpc_shb, White_exc16k, - st_fx->mem_csfilt_fx, st_fx->mem_genSHBexc_filt_down_shb_fx, st_fx->state_lpc_syn_fx, - coder_type, bwe_exc_extended_16, st_fx->bwe_seed_fx, vf_modified, st_fx->extl_fx, - &( st_fx->tbe_demph_fx ), &( st_fx->tbe_premph_fx ), lpc_shb_sf, shb_ener_sf_32, - shb_res_gshape, shb_res_dummy, &vind, formant_fac, st_fx->fb_state_lpc_syn_fx, - &(st_fx->fb_tbe_demph_fx), &Q_bwe_exc, &Q_bwe_exc_fb,Q_shb, n_mem2, st_fx->prev_Q_bwe_syn, st_fx->total_brate_fx, st_fx->prev_bfi_fx ); - - *Q_white_exc = Q_bwe_exc_fb; - IF( sub(st_fx->extl_fx, FB_TBE) == 0 ) - { - st_fx->prev_Q_bwe_exc_fb = Q_bwe_exc_fb; - move16(); - } - ELSE - { - /*Indirectly a memory reset of FB memories for next frame such that rescaling of memories would lead to 0 due to such high prev. Q value. - 51 because of 31 + 20(shift of Q_bwe_exc_fb before de-emphasis)*/ - st_fx->prev_Q_bwe_exc_fb = 51; - move16(); - } - /* rescale the TBE post proc memory */ - FOR( i = 0; i < LPC_SHB_ORDER; i++ ) - { - st_fx->mem_stp_swb_fx[i] = shl(st_fx->mem_stp_swb_fx[i], Q_bwe_exc - st_fx->prev_Q_bwe_syn); - move16(); - } - - FOR( i = 0; i < L_FRAME16k; i+=L_SUBFR16k ) - { - /* TD BWE post-processing */ - PostShortTerm_fx( &shaped_shb_excitation[L_SHB_LAHEAD+i], lpc_shb, &shaped_shb_excitationTemp[i], st_fx->mem_stp_swb_fx, - st_fx->ptr_mem_stp_swb_fx, &(st_fx->gain_prec_swb_fx), st_fx->mem_zero_swb_fx, formant_fac ); - } - Copy( shaped_shb_excitationTemp, &shaped_shb_excitation[L_SHB_LAHEAD], L_FRAME16k ); /* Q_bwe_exc */ - - tmp = sub(shl(Q_bwe_exc, 1), 31+16); - prev_pow = L_shl(1407374848l/*0.00001f Q47*/, tmp); /* 2*(Q_bwe_exc) */ - curr_pow = L_shl(1407374848l/*0.00001f Q47*/, tmp); /* 2*(Q_bwe_exc) */ - FOR( i = 0; i < L_SHB_LAHEAD + 10; i++ ) - { - prev_pow = L_mac0( prev_pow, shaped_shb_excitation[i], shaped_shb_excitation[i] ); /*2*Q_bwe_exc*/ - curr_pow = L_mac0( curr_pow, shaped_shb_excitation[i + L_SHB_LAHEAD + 10], shaped_shb_excitation[i+L_SHB_LAHEAD + 10] ); /* 2*Q_bwe_exc */ - } - - if( sub( voice_factors[0], 24576/*0.75f Q15*/ ) > 0 ) - { - curr_pow = L_shr( curr_pow, 2 ); /* Q(2*Q_bwe_exc) */ - } - - Lscale = root_a_over_b_fx( curr_pow, - shl(Q_bwe_exc, 1), - prev_pow, - shl(Q_bwe_exc, 1), - &exp ); - - FOR( i = 0; i < L_SHB_LAHEAD; i++ ) - { - L_tmp = Mult_32_16( Lscale, shaped_shb_excitation[i] ); /* Q_bwe_exc + (31-exp) - 15 */ - shaped_shb_excitation[i] = round_fx( L_shl( L_tmp, exp ) ); /* Q_bwe_exc */ - } - IF( exp < 0 ) - { - Lscale = L_shl(Lscale, exp); - exp = 0; - } - FOR( ; i < L_SHB_LAHEAD + 10; i++ ) - { - temp = i_mult(sub(i,19), 3277/*0.1f Q15*/); /* Q15 */ - L_tmp1 = Mult_32_16(L_shl(1, sub(31,exp)), temp); /* Q31-exp */ - temp = sub(32767/*1.0f Q15*/, temp); - Lscale = L_add(Mult_32_16(Lscale, temp), L_tmp1); - L_tmp = Mult_32_16( Lscale, shaped_shb_excitation[i] ); /* Q_bwe_exc + (31-exp) - 15 */ - shaped_shb_excitation[i] = round_fx( L_shl( L_tmp, exp ) ); /* Q_bwe_exc */ - } - - /* Update SHB excitation */ - Copy( shaped_shb_excitation + L_FRAME16k, st_fx->state_syn_shbexc_fx, L_SHB_LAHEAD ); /* Q_bwe_exc */ - - l_subframe_fx = L_FRAME16k/NUM_SHB_SUBGAINS; - L_ener = 0; - FOR(i = 0; i < NUM_SHB_SUBGAINS; i++) - { - L_tmp = 0; - ener_tmp[i] = 0; - FOR(j = 0; j < l_subframe_fx; j++) - { - L_tmp = L_mac0( L_tmp, shaped_shb_excitation[i*l_subframe_fx+j], shaped_shb_excitation[i*l_subframe_fx+j] );/* 2*Q_bwe_exc */ - } - L_tmp = Mult_32_16(L_tmp, 410/*0.0125 Q15*/); /* 2*Q_bwe_exc: ener_tmp_fx in (2*Q_bwe_exc) */ - IF( L_tmp != 0 ) - { - exp = norm_l( L_tmp ); - tmp = extract_h( L_shl( L_tmp, exp ) ); - exp = sub( exp, 30 - (2 * Q_bwe_exc) ); - - tmp = div_s( 16384, tmp ); - L_tmp = L_deposit_h( tmp ); - L_tmp = Isqrt_lc( L_tmp, &exp ); - ener_tmp[i] = L_shl( L_tmp, sub(add( exp, shl(Q_bwe_exc,1)),31)); /*2 * Q_bwe_exc: Q31 -exp +exp +2 * Q_bwe_exc -31 */ move32(); - L_ener = L_add(L_ener, L_shr(ener_tmp[i], 2));/* 2*Q_bwe_exc */ - } - } - ener = s_max(1, round_fx( L_shl( L_ener, sub(19, shl(Q_bwe_exc, 1)) ) )); /* Q3: 2*Q_bwe_exc+19-2*Q_bwe_exc-16 */ - - /* WB/SWB bandwidth switching */ - IF( st_fx->bws_cnt_fx > 0 ) - { - ener = mult(ener, 11587); - /*bandwidth switching should be updated*/ - if( sub( st_fx->tilt_swb_fx, 16384 ) > 0 ) - { - st_fx->prev_fractive_fx = 1; - move16(); - } - - IF( is_fractive == 0 ) - { - IF( sub( st_fx->tilt_wb_fx, 2048 ) > 0 ) /*assuming st_fx->tilt_wb_fx in Q11*/ - { - st_fx->tilt_wb_fx = 2048; - move16(); - } - ELSE IF( sub( st_fx->tilt_wb_fx, 1024 ) < 0 ) - { - st_fx->tilt_wb_fx = 1024; - move16(); - } - test(); - if( st_fx->prev_fractive_fx == 1 && sub( st_fx->tilt_wb_fx, 1024 ) > 0 ) - { - st_fx->tilt_wb_fx = 1024; - move16(); - } - } - ELSE - { - IF(sub(st_fx->tilt_wb_fx, 8192) > 0) - { - IF(st_fx->prev_fractive_fx == 0) - { - st_fx->tilt_wb_fx = 8192; - } - ELSE - { - st_fx->tilt_wb_fx = 16384; - } - } - ELSE - { - st_fx->tilt_wb_fx = shl(st_fx->tilt_wb_fx, 2); - } - } - - IF(ener != 0) - { - L_tmp = L_shl(L_mult0(ener, st_fx->tilt_wb_fx), sub(st_fx->Q_syn2, 14)); /* 3+11 +st_fx->Q_syn2 -14 = st_fx->Q_syn2*/ - exp_ener = norm_s(ener); - tmp = shl(ener, exp_ener);/*Q(3+exp)*/ - inv_ener = div_s(16384, tmp);/*Q(15+14-3-exp) = 26- exp*/ - - test(); - IF( L_sub(L_tmp, st_fx->enerLH_fx) > 0) /*st_fx->Q_syn2*/ - { - st_fx->tilt_wb_fx = extract_h(L_shr(Mult_32_16(st_fx->enerLH_fx, inv_ener), sub(sub(st_fx->Q_syn2, exp_ener),16))); /*Q11*/ - /*st_fx->Q_syn2 -1 + 26- exp_ener -15 -(st_fx->Q_syn2 -exp_ener -16 ) -16 +1 -1 = (11) *0.5*/ - } - ELSE IF( L_sub(L_tmp, Mult_32_16(st_fx->enerLH_fx, 1638)) < 0 && sub(is_fractive, 1) == 0 ) - { - st_fx->tilt_wb_fx = extract_h(L_shr(Mult_32_16(st_fx->enerLH_fx, inv_ener), sub(sub(st_fx->Q_syn2, exp_ener), 15))); /*Q11*/ - /*st_fx->Q_syn2 -1 + 26- exp_ener -15 -(st_fx->Q_syn2 -exp_ener -15 ) -16 = (11) 0.25*/ - } - L_tmp = L_mult0(st_fx->prev_ener_shb_fx, inv_ener); /*Q(1+15+14-3-exp_ener) = 27 -exp_ener*/ - GainFrame_prevfrm_fx = L_shr(L_tmp, sub(9, exp_ener)); /*27 -exp_ener -(9-exp_ener )= Q18*/ - } - ELSE - { - GainFrame_prevfrm_fx = 0; - } - - IF( sub(is_fractive , 1) == 0 ) - { - GainFrame = L_shl((Word32)st_fx->tilt_wb_fx, 10); - } - ELSE - { - GainFrame = L_shl((Word32)st_fx->tilt_wb_fx, 8); - } - - test(); - IF( sub((is_fractive & st_fx->prev_fractive_fx), 1) == 0 && L_sub(GainFrame, GainFrame_prevfrm_fx) > 0) - { - GainFrame = L_add(Mult_32_16(GainFrame_prevfrm_fx, 26214), Mult_32_16(GainFrame, 6554));/* 18 +15 -15 = 18*/ - } - ELSE - { - test(); - test(); - test(); - test(); - IF((L_sub(L_shr(st_fx->prev_enerLH_fx, 1), st_fx->enerLH_fx) < 0 && L_sub(st_fx->prev_enerLH_fx, L_shr(st_fx->enerLH_fx, 1)) > 0) - && (L_sub(L_shr(st_fx->prev_enerLL_fx, 1), st_fx->enerLL_fx) < 0 && L_sub(st_fx->prev_enerLL_fx, L_shr(st_fx->enerLL_fx, 1)) > 0) && (is_fractive ^ st_fx->prev_fractive_fx) == 0) - { - GainFrame = L_add(L_shr(GainFrame, 1), L_shr(GainFrame_prevfrm_fx, 1)); - } - ELSE - { - test(); - IF(is_fractive == 0 && sub(st_fx->prev_fractive_fx, 1) == 0) - { - L_tmp1 = L_shl(Mult_32_16(GainFrame, 3277), 13); /* 31 */ - L_tmp = L_sub(2147483647, L_tmp1); /* 31 */ - GainFrame = L_add(Mult_32_32(GainFrame, L_tmp), Mult_32_32(GainFrame_prevfrm_fx, L_tmp1)); /* 18 */ - } - ELSE - { - GainFrame = L_add(L_shr(GainFrame, 1), L_shr(L_min(GainFrame_prevfrm_fx, GainFrame), 1)); /* 18 */ - } - } - } - - GainFrame = Mult_32_16(GainFrame, i_mult(sub(N_WS2N_FRAMES, st_fx->bws_cnt_fx), 819)); /*Q18*/ - } - ELSE - { - IF(st_fx->bws_cnt1_fx > 0) - { - GainFrame = Mult_32_16(GainFrame, i_mult(st_fx->bws_cnt1_fx, 819)); /*Q18*/ - } - IF(sub(st_fx->nbLostCmpt, 1) >= 0) - { - ener = s_max(1, ener); - exp_ener = norm_s(ener); - tmp = shl(ener, exp_ener);/*Q(3+exp)*/ - inv_ener = div_s(16384, tmp);/*Q(15+14-3-exp)*/ - prev_ener_ratio_fx = L_shr(L_mult0(st_fx->prev_ener_shb_fx, inv_ener), sub(9, exp_ener)); /*Q: 1+26-exp-9+exp = 18 */ - } - - IF(sub(st_fx->nbLostCmpt, 1) == 0) - { - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - IF( sub(st_fx->clas_dec, UNVOICED_CLAS) != 0 && sub(st_fx->clas_dec, UNVOICED_TRANSITION) != 0 && sub(st_fx->tilt_swb_fec_fx, 16384) < 0 && - ((L_sub(st_fx->enerLL_fx, L_shr(st_fx->prev_enerLL_fx, 1)) > 0 && L_sub(L_shr(st_fx->enerLL_fx, 1), st_fx->prev_enerLL_fx) < 0)|| (L_sub(st_fx->enerLH_fx, L_shr(st_fx->prev_enerLH_fx, 1)) > 0 && L_sub(L_shr(st_fx->enerLH_fx, 1), st_fx->prev_enerLH_fx) < 0))) - { - IF(L_sub(L_shr(prev_ener_ratio_fx, 2), GainFrame) > 0) /*18*/ - { - GainFrame = L_add(Mult_32_16(prev_ener_ratio_fx, 13107), Mult_32_16(GainFrame, 19661));/*18*/ - } - ELSE IF(L_sub(L_shr(prev_ener_ratio_fx, 1), GainFrame) > 0) - { - GainFrame = L_add(Mult_32_16(prev_ener_ratio_fx, 26214), Mult_32_16(GainFrame, 6554)); - } - ELSE - { - GainFrame = L_add(Mult_32_16(prev_ener_ratio_fx, 6554), Mult_32_16(GainFrame, 26214)); - } - - test(); - IF(sub(tilt_swb_fec, st_fx->tilt_swb_fec_fx) > 0 && st_fx->tilt_swb_fec_fx > 0) - { - exp = norm_s(st_fx->tilt_swb_fec_fx); - tmp = shl(st_fx->tilt_swb_fec_fx, exp);/*Q(11+exp)*/ - tmp = div_s(16384, tmp);/*Q(15+14-11-exp)*/ - tmp = extract_h(L_shl(L_mult0(tmp, st_fx->tilt_wb_fx),sub(exp,1)));/*18 -exp +11 + exp -1 -16 =12; */ - GainFrame = L_shl(Mult_32_16(GainFrame, s_min(tmp, 20480)), 3); /*Q18 = 18 +12 -15 +3 */ - } - - } - ELSE IF( (sub(st_fx->clas_dec, UNVOICED_CLAS) != 0 || sub(st_fx->tilt_swb_fec_fx, 16384) > 0) && L_sub(L_shr(prev_ener_ratio_fx, 2), GainFrame) > 0 && - (L_sub(st_fx->enerLL_fx, L_shr(st_fx->prev_enerLL_fx, 1)) > 0 || L_sub(st_fx->enerLH_fx, L_shr(st_fx->prev_enerLH_fx, 1)) > 0) ) - { - GainFrame = L_add(Mult_32_16(prev_ener_ratio_fx, 6554), Mult_32_16(GainFrame, 26214)); - } - } - ELSE IF( sub(st_fx->nbLostCmpt, 1) > 0 ) - { - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - IF(L_sub(L_shr(prev_ener_ratio_fx, 2), GainFrame) > 0 && ((sub(st_fx->codec_mode, MODE1) == 0 && L_sub(st_fx->enerLL_fx, st_fx->prev_enerLL_fx) > 0 && L_sub(st_fx->enerLH_fx, st_fx->prev_enerLH_fx) > 0) || sub(st_fx->codec_mode, MODE2) == 0)) - { - test(); - IF( sub(tilt_swb_fec, 20480) > 0 && sub(st_fx->tilt_swb_fec_fx, 20480) > 0 ) - { - GainFrame = L_min(L_add(Mult_32_16(prev_ener_ratio_fx, 26214), Mult_32_16(GainFrame, 6554)), L_shl(Mult_32_16(GainFrame, 16384), 3)); /*Q18*/ - } - ELSE - { - GainFrame = L_min(L_add(Mult_32_16(prev_ener_ratio_fx, 16384), Mult_32_16(GainFrame, 16384)), L_shl(Mult_32_16(GainFrame, 16384), 3)); /*Q18*/ - } - } - ELSE IF(L_sub(prev_ener_ratio_fx, GainFrame) > 0 &&((sub(st_fx->codec_mode, MODE1) == 0 && L_sub(st_fx->enerLL_fx, st_fx->prev_enerLL_fx) > 0 && L_sub(st_fx->enerLH_fx, st_fx->prev_enerLH_fx) > 0) || sub(st_fx->codec_mode, MODE2) == 0)) - { - test(); - IF( sub(tilt_swb_fec, 20480) > 0 && sub(st_fx->tilt_swb_fec_fx, 20480) > 0 ) - { - GainFrame = L_add(Mult_32_16(prev_ener_ratio_fx, 16384), Mult_32_16(GainFrame, 16384)); - } - ELSE - { - GainFrame = L_add(Mult_32_16(prev_ener_ratio_fx, 6554), Mult_32_16(GainFrame, 26214)); - } - } - } - } - st_fx->prev_fractive_fx = is_fractive; - move16(); - - /* Adjust the subframe and frame gain of the synthesized shb signal */ - IF( sub(st_fx->L_frame_fx, L_FRAME) == 0 ) - { - /* pitch = 0.25f*sum_s(pitch_buf, 4); */ - L_tmp = L_mult(pitch_buf[0], 8192); - FOR (i=1; itotal_brate_fx, ACELP_24k40) >= 0 && sub(st_fx->prev_coder_type_fx, coder_type) == 0 && sub(coder_type, UNVOICED) != 0) - || (L_sub(st_fx->total_brate_fx, ACELP_16k40) <= 0 && (sub(st_fx->prev_coder_type_fx, coder_type) == 0 || (sub(st_fx->prev_coder_type_fx, VOICED) == 0 && sub(coder_type, GENERIC) == 0) || (sub(st_fx->prev_coder_type_fx, GENERIC) == 0 && sub(coder_type, VOICED) == 0)))) - && sub(pitch_fx, 4480 /*70 in Q6*/) > 0 && sub(st_fx->extl_fx, FB_TBE) < 0) - { - FOR(i=0; i st_fx->prev_ener_fx*st_fx->prev_GainShape_fx ) */ - L_tmp1 = Mult_32_16(ener_tmp[i], GainShape_tmp[i]); /* (2*Q_bwe_exc) */ - L_tmp2 = Mult_32_16(st_fx->prev_ener_fx, st_fx->prev_GainShape_fx); /* (2*st_fx->prev_ener_fx_Q) */ - tmp = sub(shl(Q_bwe_exc, 1), shl(st_fx->prev_ener_fx_Q, 1)); - L_tmp2 = L_shl(L_tmp2, tmp); /* new Q = (2*Q_bwe_exc) */ - - IF (L_sub(L_tmp1,L_tmp2) > 0) - { - /*GainShape_tmp_fx[i] = 0.5f*(L_tmp2/ener_tmp_fx[i] + GainShape_tmp_fx[i]);*/ - /* tmp = L_tmp2/ener_tmp_fx[i]*/ - L_tmp = L_tmp2; - if(L_tmp2 < 0) - { - L_tmp = L_negate(L_tmp2); - } - - expb = norm_l(L_tmp); - fracb = round_fx(L_shl(L_tmp,expb)); - expb = 30-expb; /* - (2*Q_bwe_exc_ext); */ - - expa = norm_l(ener_tmp[i]); - fraca = extract_h(L_shl(ener_tmp[i],expa)); - expa = 30-expa ; - - scale = shr(sub(fraca,fracb),15); - fracb = shl(fracb,scale); - expb = sub(expb,scale); - - tmp = div_s(fracb,fraca); - exp = sub(sub(expb,expa),1); - tmp = shl(tmp,exp); - GainShape_tmp[i] = add(tmp,shr(GainShape_tmp[i],1));/* Q15 */ - } - - st_fx->prev_ener_fx = ener_tmp[i]; - st_fx->prev_GainShape_fx = GainShape_tmp[i]; - st_fx->prev_ener_fx_Q = Q_bwe_exc; - } - FOR(i=0; iprev_ener_fx_Q = Q_bwe_exc; - move16(); - } - - - /* Back up the Q_bwe_exc associated with shaped_shb_excitation for the next frame*/ - st_fx->prev_Q_bwe_syn = Q_bwe_exc; - move16(); - - /* Scale the shaped excitation */ - ScaleShapedSHB_fx( SHB_OVERLAP_LEN, - shaped_shb_excitation, /* i/o: Q_bwe_exc */ - st_fx->syn_overlap_fx, - GainShape, /* Q15 */ - GainFrame, /* Q18 */ - window_shb_fx, - subwin_shb_fx, - &Q_bwe_exc - , &Qx - , n_mem3 - , st_fx->prev_Q_bwe_syn2 - ); - /* i: GainShape Q15 */ - /* i: GainFrame Q18 */ - /* i: shaped_shb_excitation Q_bwe_exc */ - /* o: shaped_shb_excitation Q_bwe_exc */ - /* o: st_fx->syn_overlap_fx Q_bwe_exc */ - - - max = 0; - FOR( i = 0; i < L_FRAME16k; i++ ) - { - max = s_max( max, shaped_shb_excitation[i] ); /* Q0 */ - } - - IF( max == 0 ) - { - curr_frame_pow = 0; - move16(); - n = 0; - move16(); - } - ELSE - { - n = norm_s( max ); - max = 0; - FOR( i = 0; i < L_FRAME16k; i++ ) - { - shaped_shb_excitation_frac[i] = shl( shaped_shb_excitation[i], n ); /*Q_bwe_exc+n*/ move16(); - } - - curr_frame_pow = 0; - FOR( i = 0; i < L_FRAME16k; i++ ) - { - L_tmp = L_mult0( shaped_shb_excitation_frac[i], shaped_shb_excitation_frac[i] ); /*2*(Q_bwe_exc+n)*/ - curr_frame_pow = L_add( curr_frame_pow, L_shr( L_tmp, 9 ) ); /*2*(Q_bwe_exc+n)-9*/ - } - } - curr_frame_pow_exp = sub(shl(add( Q_bwe_exc, n ), 1), 9); - - - tmp=sub( st_fx->prev_frame_pow_exp, curr_frame_pow_exp ); - IF( tmp > 0 ) /* shifting prev */ - { - IF (sub(tmp,32)>0) - { - st_fx->prev_frame_pow_exp = add(curr_frame_pow_exp,32); - tmp = 32; - } - st_fx->prev_swb_bwe_frame_pow_fx = L_shr(st_fx->prev_swb_bwe_frame_pow_fx, tmp); - st_fx->prev_frame_pow_exp = curr_frame_pow_exp; - move16(); - } - ELSE /* shifting curr */ - { - IF (sub(tmp,-32)<0) - { - curr_frame_pow_exp = sub(st_fx->prev_frame_pow_exp,32); - tmp = -32; - } - curr_frame_pow = L_shr(curr_frame_pow, -tmp); - curr_frame_pow_exp = st_fx->prev_frame_pow_exp; - } - test(); - IF( !st_fx->bfi_fx && st_fx->prev_bfi_fx ) - { - L_tmp = L_shr( curr_frame_pow, 4 ); - L_tmp = Mult_32_16( L_tmp, 17476 ); - - test(); - test(); - IF( ( L_sub( L_shr( curr_frame_pow, 1 ), st_fx->prev_swb_bwe_frame_pow_fx ) > 0 ) && - ( L_sub( st_fx->prev_swb_bwe_frame_pow_fx, L_tmp ) > 0 ) && sub(st_fx->prev_coder_type_fx,UNVOICED) == 0) - { - L_tmp = root_a_over_b_fx( st_fx->prev_swb_bwe_frame_pow_fx, curr_frame_pow_exp, curr_frame_pow, curr_frame_pow_exp, &exp ); - scale = round_fx( L_shl( L_tmp, exp ) ); /*Q15*/ - - L_tmp = root_a_fx( L_tmp, 31 - exp, &exp ); - L_tmp = root_a_fx( L_tmp, 31 - exp, &exp ); - L_tmp = root_a_fx( L_tmp, 31 - exp, &exp ); - temp = round_fx( L_shl( L_tmp, exp ) ); /*Q15*/ - } - ELSE - { - scale = temp = 32767; - move16();/*Q15*/ - } - FOR( j = 0; j < 8; j++ ) - { - GainShape[2 * j] = mult_r( GainShape[2 * j], scale ); - move16(); - GainShape[2 * j + 1] = mult_r( GainShape[2 * j + 1], scale ); - move16(); - FOR( i = 0; i < L_FRAME16k / 8; i++ ) - { - shaped_shb_excitation[i + j*L_FRAME16k/8] = mult_r( shaped_shb_excitation[i + j*L_FRAME16k/8],scale ); - move16(); - } - - IF( temp > 0 ) - { - /* scale <= temp, due to scale = sqrt( st->prev_swb_bwe_frame_pow_fx/curr_frame_pow ), temp = sqrt( scale, 1.f/8.f ) - and curr_frame_pow > st->prev_swb_bwe_frame_pow_fx -> scale <= 1.0, sqrt(scale, 1.f/8.f) >= scale */ - IF( sub( scale, temp ) < 0 ) - { - scale = div_s( scale, temp ); - } - ELSE - { - scale = 32767; - move16(); - } - } - ELSE - { - scale = 0; - move16(); - } - } - } - - /* adjust the FEC frame energy */ - IF( st_fx->bfi_fx ) - { - scale = temp = 4096; - move16();/*Q12*/ - - IF (sub(st_fx->nbLostCmpt,1) == 0 ) - { - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - IF( L_sub(curr_frame_pow, st_fx->prev_swb_bwe_frame_pow_fx) >0 && - sub(st_fx->prev_coder_type_fx, UNVOICED)!= 0 && - sub(st_fx->last_good_fx,UNVOICED_CLAS) != 0 ) - { - L_tmp = root_a_over_b_fx( st_fx->prev_swb_bwe_frame_pow_fx, curr_frame_pow_exp, curr_frame_pow, curr_frame_pow_exp, &exp ); /*31 - exp*/ - scale = round_fx( L_shl( L_tmp, sub(exp,3))); /*Q12*/ - L_tmp = root_a_fx( L_tmp, 31 - exp, &exp ); - L_tmp = root_a_fx( L_tmp, 31 - exp, &exp ); - L_tmp = root_a_fx( L_tmp, 31 - exp, &exp ); - temp = round_fx( L_shl( L_tmp, sub(exp,3))); /*Q12*/ - } - ELSE IF( L_sub(curr_frame_pow, L_shr(st_fx->prev_swb_bwe_frame_pow_fx,1)) <0 && sub(st_fx->nbLostCmpt,1) == 0 && - (L_sub(st_fx->enerLL_fx, L_shr( st_fx->prev_enerLL_fx,1)) > 0 || L_sub(st_fx->enerLH_fx, L_shr(st_fx->prev_enerLH_fx,1)) >0 ) && - (sub(st_fx->prev_coder_type_fx ,UNVOICED) == 0 || sub(st_fx->last_good_fx, UNVOICED_CLAS) == 0 || sub(st_fx->tilt_swb_fec_fx , 10240) > 0)) - { - L_tmp = root_a_over_b_fx( st_fx->prev_swb_bwe_frame_pow_fx, curr_frame_pow_exp, curr_frame_pow, curr_frame_pow_exp, &exp ); - scale = round_fx( L_shl( L_tmp, sub(exp,3) ) ); /*Q12*/ - L_tmp = root_a_fx( L_tmp, 31 - exp, &exp ); - L_tmp = root_a_fx( L_tmp, 31 - exp, &exp ); - L_tmp = root_a_fx( L_tmp, 31 - exp, &exp ); - temp = round_fx( L_shl( L_tmp, sub(exp,3) ) ); /*Q12*/ - } - } - ELSE IF (sub(st_fx->nbLostCmpt,1) > 0 ) - { - test(); - test(); - test(); - test(); - test(); - IF( L_sub(curr_frame_pow , st_fx->prev_swb_bwe_frame_pow_fx) >0 ) - { - L_tmp = root_a_over_b_fx( st_fx->prev_swb_bwe_frame_pow_fx, curr_frame_pow_exp, curr_frame_pow, curr_frame_pow_exp, &exp ); - scale = round_fx( L_shl( L_tmp, sub(exp,3) ) ); /*Q12*/ - L_tmp = root_a_fx( L_tmp, 31 - exp, &exp ); - L_tmp = root_a_fx( L_tmp, 31 - exp, &exp ); - L_tmp = root_a_fx( L_tmp, 31 - exp, &exp ); - temp = round_fx( L_shl( L_tmp, sub(exp,3) ) ); /*Q12*/ - - } - ELSE IF( L_sub(curr_frame_pow, L_shr(st_fx->prev_swb_bwe_frame_pow_fx,1)) < 0 && - (L_sub(st_fx->enerLL_fx, L_shr( st_fx->prev_enerLL_fx,1)) > 0 || L_sub(st_fx->enerLH_fx, L_shr(st_fx->prev_enerLH_fx,1)) > 0) && - (st_fx->prev_coder_type_fx == UNVOICED || st_fx->last_good_fx == UNVOICED_CLAS || sub(st_fx->tilt_swb_fec_fx , 10240) > 0) ) - { - L_tmp = root_a_over_b_fx( st_fx->prev_swb_bwe_frame_pow_fx, curr_frame_pow_exp, curr_frame_pow, curr_frame_pow_exp, &exp ); - L_tmp =L_min(L_tmp,L_shl(2,(31 - exp)));/*31 - exp*/ - scale = round_fx( L_shl( L_tmp, sub(exp,3) )); /*Q12*/ - L_tmp = root_a_fx( L_tmp, 31 - exp, &exp ); - L_tmp = root_a_fx( L_tmp, 31 - exp, &exp ); - L_tmp = root_a_fx( L_tmp, 31 - exp, &exp ); - temp = round_fx( L_shl( L_tmp, sub(exp,3) ) ); /*Q12*/ - } - } - FOR( j = 0; j < 8; j++ ) - { - GainShape[2 * j] = shl(mult_r( GainShape[2 * j], scale ),3); - move16(); /* 15 +12 +3-15 =15*/ - GainShape[2 * j + 1] = shl(mult_r( GainShape[2 * j + 1], scale ),3); - move16(); - FOR( i = 0; i < 40; i++ ) - { - shaped_shb_excitation[add(i,i_mult(j,40))] = shl(mult_r( shaped_shb_excitation[add(i,i_mult(j,40))], scale) ,3); - move16(); /* Q_bwe_exc +12+3 -15 =Q_bwe_exc*/ - } - - IF( temp > 0 ) - { - IF( sub( scale, temp ) < 0 ) - { - scale = shr(div_s( scale, temp ),3); - } - ELSE - { - tmp1 = sub(norm_s(scale), 1); - tmp2 = norm_s(temp); - scale = div_s( shl(scale, tmp1), shl(temp, tmp2) ); - scale = shr(scale, add(sub(tmp1, tmp2), 3)); - } - } - ELSE - { - scale = 0; - move16(); - } - } - } - - st_fx->prev_swb_bwe_frame_pow_fx = curr_frame_pow; - move32(); - st_fx->prev_frame_pow_exp = curr_frame_pow_exp; - move16(); - - L_prev_ener_shb = L_deposit_l(0); - FOR( i = 0; i < L_FRAME16k; i++ ) - { - L_prev_ener_shb = L_mac0( L_prev_ener_shb, shaped_shb_excitation[i], shaped_shb_excitation[i] ); /* Q0 */ - } - - /* st->prev_ener_shb = sqrt(st->prev_ener_shb/L_FRAME16k) */ - L_prev_ener_shb = Mult_32_16( L_prev_ener_shb, 26214 ); /* 2*Q_bwe_exc_mod+8; 26214=(1/L_FRAME16k) in Q23 */ - st_fx->prev_ener_shb_fx = 0; - move16(); - - IF( L_prev_ener_shb != 0 ) - { - exp = norm_l( L_prev_ener_shb ); - tmp = extract_h( L_shl( L_prev_ener_shb, exp ) ); - exp = sub( exp, 30 - ( 2 * Q_bwe_exc + 8 ) ); - - tmp = div_s( 16384, tmp ); - L_tmp = L_deposit_h( tmp ); - L_tmp = Isqrt_lc( L_tmp, &exp ); - st_fx->prev_ener_shb_fx = round_fx( L_shl( L_tmp, sub( exp, 14 ) ) ); /* Q1 */ - } - /* st->prev_SWB_fenv[i] = sqrt(curr_frame_pow/L_FRAME16k); */ - L_tmp = Mult_32_16( curr_frame_pow, 26214 ); /* curr_frame_pow_exp+8; 26214=(1/L_FRAME16k) in Q23 */ - tmp =0; - IF( L_tmp != 0 ) - { - exp = norm_l( L_tmp ); - tmp = extract_h( L_shl( L_tmp, exp ) ); - exp = sub( exp, 30 - ( curr_frame_pow_exp + 8 ) ); - - tmp = div_s( 16384, tmp ); - L_tmp = L_deposit_h( tmp ); - L_tmp = Isqrt_lc( L_tmp, &exp ); - tmp = round_fx( L_shl( L_tmp, sub( exp, 14 ) ) ); /* Q1 */ - } - set16_fx(st_fx->prev_SWB_fenv_fx, tmp, SWB_FENV); /* Q1 */ - - - /* rescale the memories if Q_bwe_exc is different from previous frame */ - sc = sub( Q_bwe_exc, st_fx->prev_Q_bwe_syn2 ); - IF( sc != 0 ) - { - FOR( i = 0; i < 2*ALLPASSSECTIONS_STEEP; i++ ) - { - st_fx->genSHBsynth_state_lsyn_filt_shb_local_fx[i] = shl( st_fx->genSHBsynth_state_lsyn_filt_shb_local_fx[i], sc ); - move16(); - } - - IF(sub(st_fx->L_frame_fx, L_FRAME) == 0) - { - FOR( i = 0; i < HILBERT_MEM_SIZE; i++ ) - { - st_fx->genSHBsynth_Hilbert_Mem_fx[i] = L_shl( st_fx->genSHBsynth_Hilbert_Mem_fx[i], sc ); - move32(); - } - } - IF( st_fx->output_Fs_fx == 48000 ) - { - Scale_sig(st_fx->int_3_over_2_tbemem_dec_fx, INTERP_3_2_MEM_LEN, sc); - } - IF( st_fx->output_Fs_fx == 16000 ) - { - Scale_sig(st_fx->mem_resamp_HB_32k_fx, 2*ALLPASSSECTIONS_STEEP + 1, sc); - } - } - /* i: shaped_shb_excitation[320] in (Q_bwe_exc) */ - /* i/o: st_fx->genSHBsynth_Hilbert_Mem_fx in (Q_bwe_exc) */ - /* i/o: st_fx->genSHBsynth_state_lsyn_filt_shb_local_fx in (Q_bwe_exc) */ - /* o: error in (Qx) */ - GenSHBSynth_fx( shaped_shb_excitation, error, st_fx->genSHBsynth_Hilbert_Mem_fx, - st_fx->genSHBsynth_state_lsyn_filt_shb_local_fx, st_fx->L_frame_fx, &( st_fx->syn_dm_phase_fx ) ); - - Copy( error + L_FRAME32k - L_SHB_TRANSITION_LENGTH, st_fx->old_tbe_synth_fx, L_SHB_TRANSITION_LENGTH ); - - /* resample SHB synthesis (if needed) and scale down */ - synth_scale_fx = 32767; - move16(); /* 1.0 in Q15 */ - if(sub(st_fx->codec_mode,MODE1)==0) - { - synth_scale_fx = 29491; - move16(); /* 0.9 in Q15 */ - } - - IF( L_sub(st_fx->output_Fs_fx, 48000) == 0 ) - { - IF( L_sub(st_fx->extl_fx,FB_TBE) == 0 ) - { - tmp = norm_l( GainFrame ); - if(GainFrame == 0) - { - tmp = 31; - } - L_tmp = L_shl(GainFrame,tmp);/* 18 + tmp */ - - tmp1 =0; - FOR( i = 0; i < L_FRAME16k; i++ ) - { - L_tmp1 = Mult_32_16( L_tmp, GainShape[NUM_SHB_SUBFR * i / L_FRAME16k] ); /* Q : 18 + tmp +15 -15*/ - White_exc16k[i] = round_fx( Mult_32_16( L_tmp1, White_exc16k[i] ) );/* 18 + tmp +*Q_white_exc -15 -16 */ - tmp1 = s_max(tmp1,abs_s(White_exc16k[i])); - } - - *Q_white_exc = sub(add(*Q_white_exc, tmp),13); /* *Q_white_exc + 18 + tmp -15 -16 */ - tmp = norm_s( tmp1 ); - if(tmp1 == 0) - { - tmp = 15; - } - - FOR(i=0; iint_3_over_2_tbemem_dec_fx, allpass_poles_3_ov_2 ); - } - ELSE IF( L_sub(st_fx->output_Fs_fx, 32000) == 0 ) - { - IF( sub(synth_scale_fx,32767) != 0 ) /* 1.0 in Q15 */ - { - FOR( i = 0; i < L_FRAME32k; i++ ) - { - synth[i] = mult_r( synth_scale_fx, error[i] ); - move16();/*Qx*/ - } - } - ELSE - { - Copy(error, synth, L_FRAME32k); - } - } - ELSE IF( L_sub(st_fx->output_Fs_fx, 16000) == 0 ) - { - IF( sub(synth_scale_fx,32767) != 0 ) /* 1.0 in Q15 */ - { - FOR( i = 0; i < L_FRAME32k; i++ ) - { - error[i] = mult_r(error[i],synth_scale_fx); - move16(); - } - } - - Decimate_allpass_steep_fx( error, st_fx->mem_resamp_HB_32k_fx, L_FRAME32k, synth ); - } - - /* Update previous frame parameters for FEC */ - Copy( lsf_shb, st_fx->lsp_prevfrm_fx, LPC_SHB_ORDER ); - IF(sub(st_fx->codec_mode, MODE1) == 0) - { - st_fx->GainFrame_prevfrm_fx = GainFrame; - move16(); /*Q18*/ - st_fx->tilt_swb_fec_fx = tilt_swb_fec; - - if( !st_fx->bfi_fx ) - { - st_fx->GainAttn_fx = 32767; - move16(); - } - } - ELSE - { - IF( !st_fx->bfi_fx ) - { - st_fx->GainFrame_prevfrm_fx = GainFrame; - move16(); /*Q18*/ - st_fx->tilt_swb_fec_fx = tilt_swb_fec; - move16(); - st_fx->GainAttn_fx = 32767; - move16(); - } - } - - st_fx->prev_ener_fx = ener_tmp[NUM_SHB_SUBGAINS-1]; - st_fx->prev_GainShape_fx = GainShape[NUM_SHB_SUBFR-1]; - *Q_synth = Q_bwe_exc; - move16(); - st_fx->prev_Q_bwe_syn2 = Q_bwe_exc; - move16(); - st_fx->prev_Qx = Q_bwe_exc; - move16(); - return; -} - -static void gradientGainShape( - Decoder_State_fx *st_fx, - Word16 *GainShape, - Word32 *GainFrame) -{ - Word16 i,j,tmp; - Word16 GainShapeTemp[NUM_SHB_SUBFR/4]; - Word16 GainGrad0[3]; - Word16 GainGrad1[3]; - Word16 GainGradFEC[4]; - - /* the previous frame gainshape gradient and the gainshape gradient pattern for the current frame */ - FOR( j = 0; j < 3; j++ ) - { - GainGrad0[j] = sub( shr( st_fx->GainShape_Delay[j + 1], 1 ), shr( st_fx->GainShape_Delay[j], 1 ) ); - move16();/* Q14 */ - GainGrad1[j] = sub( shr( st_fx->GainShape_Delay[j + 5], 1 ), shr( st_fx->GainShape_Delay[j + 4], 1 ) ); - move16();/* Q14 */ - GainGradFEC[j + 1] = add( mult_r( GainGrad0[j], 13107 ), mult_r( GainGrad1[j], 19660 ) ); - move16(); /* Q14 */ - } - - /* gradient for the first gainshape */ - test(); - test(); - test(); - IF( ( ( sub( shr( GainGrad1[2], 1 ), GainGrad1[1] ) > 0 ) && ( sub( shr( GainGrad1[1], 1 ), GainGrad1[0] ) > 0 ) ) || - ( ( sub( shr( GainGrad1[2], 1 ), GainGrad1[1] ) < 0 ) && ( sub( shr( GainGrad1[1], 1 ), GainGrad1[0] ) < 0 ) ) ) - { - GainGradFEC[0] = add( mult_r( GainGrad1[1], 3277 ), mult_r( GainGrad1[2], 29490 ) ); - move16(); /* Q14 */ - } - ELSE - { - GainGradFEC[0] = add( mult_r( GainGrad1[0], 6553 ), mult_r( GainGrad1[1], 9830 ) ); - move16(); - GainGradFEC[0] = add( GainGradFEC[0], mult_r( GainGrad1[2], 16384 ) ); - move16(); /* Q14 */ - } - - /* get the first gainshape template */ - test(); - test(); - IF( ( st_fx->prev_coder_type_fx == UNVOICED || st_fx->last_good_fx == UNVOICED_CLAS ) && GainGradFEC[0] > 0 ) - { - GainShapeTemp[0] = add( shr( st_fx->GainShape_Delay[7], 1 ), GainGradFEC[0] ); - move16(); - } - ELSE IF( GainGradFEC[0] > 0 ) - { - GainShapeTemp[0] = add( shr( st_fx->GainShape_Delay[7], 1 ), mult_r( GainGradFEC[0], 16384 ) ); - move16(); /* Q14 */ - } - ELSE - { - GainShapeTemp[0] = shr( st_fx->GainShape_Delay[7], 1 ); - move16();/* Q14 */ - } - - /*Get the second the third and the fourth gainshape template*/ - - tmp = shr( GainGrad1[2], 3 ); /* GainGrad1[2]/8 */ - tmp = mult_r( tmp, 26214 ); /* 0.8 in Q15 tmp*(8/10) */ - - test(); - IF( ( sub( tmp, GainGrad1[1] ) > 0 ) && GainGrad1[1] > 0 ) - { - FOR( i = 1; i < NUM_SHB_SUBFR / 4; i++ ) - { - GainShapeTemp[i] = add( GainShapeTemp[i - 1], mult_r( GainGradFEC[i], 26214 ) ); - move16(); /* GainShapeTemp[i-1] + 0.8* GainShapeTemp[i] */ - GainShapeTemp[i] = s_max( GainShapeTemp[i], 328/*0.01f Q15*/ ); - move16(); - } - } - ELSE - { - test(); - IF( ( sub( tmp, GainGrad1[1] ) > 0 ) && GainGrad1[1] < 0 ) - { - FOR( i = 1; i < NUM_SHB_SUBFR / 4; i++ ) - { - GainShapeTemp[i] = add( GainShapeTemp[i - 1], mult_r( GainGradFEC[i], 6553 ) ); - move16(); /* GainShapeTemp[i-1] + 0.8* GainShapeTemp[i] */ - GainShapeTemp[i] = s_max( GainShapeTemp[i], 328/*0.01f Q15*/ ); - move16(); /* Q14 */ - } - } - ELSE - { - FOR( i = 1; i < NUM_SHB_SUBFR / 4; i++ ) - { - GainShapeTemp[i] = add( GainShapeTemp[i - 1], GainGradFEC[i] ); - move16(); - GainShapeTemp[i] = s_max( GainShapeTemp[i], 328/*0.01f Q15*/ ); - move16(); - } - } - } - - /* Get the gainshape and gain frame for the current frame*/ - test(); - test(); - test(); - IF( ( st_fx->prev_coder_type_fx == UNVOICED || st_fx->last_good_fx == UNVOICED_CLAS ) && st_fx->nbLostCmpt == 1 ) - { - FOR( i = 0; i < NUM_SHB_SUBFR / 4; i++ ) - { - FOR( j = 0; j < 4; j++ ) - { - tmp = mult_r( GainShapeTemp[i], 19660 ); /* GainShapeTemp[i]*0.6 */ - - IF( sub( 8192, tmp ) > 0 ) - { - GainShape[i * 4 + j ] = shl( tmp, 2 ); - move16(); /* (GainShapeTemp[i]*0.6)>>1 */ - } - ELSE - { - GainShape[i * 4 + j ] = 32767; - move16(); /* Clipping here to avoid the a huge change of the code due to gain shape change */ - } - } - } - st_fx->GainAttn_fx = mult_r( st_fx->GainAttn_fx, 31129 ); - } - ELSE IF( st_fx->prev_coder_type_fx == UNVOICED || st_fx->last_good_fx == UNVOICED_CLAS ) - { - FOR( i = 0; i < NUM_SHB_SUBFR / 4; i++ ) - { - FOR( j = 0; j < 4; j++ ) - { - IF( sub( GainShapeTemp[i], 16384 ) < 0 ) - { - GainShape[i * 4 + j ] = shl( GainShapeTemp[i], 1 ); - move16(); - } - ELSE - { - GainShape[i * 4 + j ] = 32767 ; - move16(); - } - } - } - st_fx->GainAttn_fx = mult_r( st_fx->GainAttn_fx, 31129 ); - } - ELSE IF( st_fx->nbLostCmpt > 1 ) - { - FOR( i = 0; i < NUM_SHB_SUBFR / 4; i++ ) - { - FOR( j = 0; j < 4; j++ ) - { - GainShape[i * 4 + j ] = GainShapeTemp[i]; - move16(); - } - } - st_fx->GainAttn_fx = mult_r( st_fx->GainAttn_fx, 16384 ); - } - ELSE - { - FOR( i = 0; i < NUM_SHB_SUBFR / 4; i++ ) - { - FOR( j = 0; j < 4; j++ ) - { - IF( sub( GainShapeTemp[i], 16384 ) < 0 ) - { - GainShape[i * 4 + j] = shl( GainShapeTemp[i], 1 ); - move16(); - } - ELSE - { - GainShape[i * 4 + j] = 32767; - move16(); - } - } - } - st_fx->GainAttn_fx = mult_r( st_fx->GainAttn_fx, 27852 ); - } - - *GainFrame = Mult_32_16( st_fx->GainFrame_prevfrm_fx, st_fx->GainAttn_fx ); /* Q18 */ -} - -/*-------------------------------------------------------------------* - * Dequant_lower_LSF() - * - * Dequantized the lower LSFs - *-------------------------------------------------------------------*/ - - -static void Dequant_lower_LSF_fx( - const Word16 lsf_idx[], /* i : LSF indices */ - Word16 lsf_q[] /* o : Quantized LSFs */ -) -{ - Word16 i; - - lsf_q[0] = lsf_q_cb_fx[0][lsf_idx[0]]; - move16(); - FOR( i = 1; i < NUM_Q_LSF; i++ ) - { - lsf_q[i] = add( lsf_q_cb_fx[i][lsf_idx[i]], lsf_q[i - 1] ); - move16(); - } - - return; -} - -/*-------------------------------------------------------------------* - * Map_higher_LSF() - * - * Map the higher LSFs from the lower LSFs - *-------------------------------------------------------------------*/ - -static void Map_higher_LSF_fx( - Word16 lsf_q[], /* i/o : Quantized lower LSFs */ - const Word16 m, /* i : Mirroring point */ - const Word16 grid_in[] /* i : Input LSF smoohthing grid */ ) -{ - Word16 lsf_map[NUM_MAP_LSF]; - Word16 grid[NUM_MAP_LSF]; - Word16 last_q_lsf; - Word16 lsf_smooth[NUM_MAP_LSF]; - Word16 offset; - Word16 i; - Word16 scale; - - FOR( i = 0; i < NUM_MAP_LSF; i++ ) - { - lsf_map[i] = sub( shl( m, 1 ), lsf_q[NUM_MAP_LSF - 1 - i] ); - move16(); - } - - IF( sub( m, MAX_LSF_FX_BY_2 ) > 0 ) - { - offset = lsf_map[0]; - move16(); - scale = div_s( sub( MAX_LSF_FX, m ), m ); - FOR( i = 0; i < NUM_MAP_LSF; i++ ) - { - lsf_map[i] = add( mult_r( sub( lsf_map[i], offset ), scale ), offset ); - move16(); - } - } - - last_q_lsf = lsf_q[NUM_Q_LSF - 1]; - move16(); - scale = sub( MAX_LSF_FX, last_q_lsf ); - - FOR( i = 0; i < NUM_MAP_LSF; i++ ) - { - grid[i] = add( mult_r( grid_in[i], scale ), last_q_lsf ); - move16(); - } - - FOR( i = 0; i < NUM_MAP_LSF; i++ ) - { - lsf_smooth[i] = sub( mult_r( grid_smoothing_fx[i], grid[i] ), - mult_r( lsf_map[i], add( grid_smoothing_fx[i], -32768/*-1.0f Q15*/ ) ) ); - move16(); - } - - FOR( i = 0; i < NUM_MAP_LSF; i++ ) - { - lsf_q[NUM_Q_LSF + i] = lsf_smooth[i]; - move16(); - } - - return; -} - - - - -static void Dequant_mirror_point_fx( - const Word16 lsf_q[], /* i/o : Quantized lower LSFs */ - const Word16 m_idx, /* i : Mirror point index */ Word16* m /* i : Mirroring point */ ) -{ - *m = add( mirror_point_q_cb_fx[m_idx], lsf_q[NUM_Q_LSF - 1] ); - move16(); - - return; -} - - -/*==========================================================================*/ -/* FUNCTION : static void dequantizeSHBparams_fx_9_1 () */ -/*--------------------------------------------------------------------------*/ -/* PURPOSE : Dequantize super highband spectral envolope */ -/* temporal gains and frame gain */ -/*--------------------------------------------------------------------------*/ -/* INPUT ARGUMENTS : */ -/* _Word16 extl i : extension layer */ -/* _Word32 extl_brate i : extensiuon layer bitrate */ -/*--------------------------------------------------------------------------*/ -/* OUTPUT ARGUMENTS : */ -/* _Word16 *Q_lsf, o : SHB LSF from de-quantization Q15 */ -/* _Word16 *Q_subgain, o : SHB subframe gains from de-quantization Q15*/ -/* _Word32 *Q_framegrain o : SHB frame gain from de-quantization Q18 */ -/*--------------------------------------------------------------------------*/ -/* INPUT/OUTPUT ARGUMENTS : */ -/*--------------------------------------------------------------------------*/ -/* RETURN ARGUMENTS : */ -/* _ None */ -/*--------------------------------------------------------------------------*/ -/* CALLED FROM : */ -/*==========================================================================*/ -static void dequantizeSHBparams_fx_9_1( - Decoder_State_fx* st_fx, - const Word16 extl, /* i : extension layer */ - Word32 extl_brate, /* i : extensiuon layer bitrate */ - Word16* Q_lsf, /* o : SHB LSF from de-quantization Q15*/ - Word16* Q_subgain, /* o : SHB subframe gains from de-quantization Q15*/ - Word32* Q_framegrain, /* o : SHB frame gain from de-quantization Q18*/ - Word16* uv_flag, /* o : unvoiced flag*/ - Word32* Q_shb_ener_sf, /* o : Q15 */ - Word16* Q_shb_res_gshape, /* o : Q14 */ - Word16* Q_mixFactors /* o : Q15 */ -) -{ - Word16 i, j, idxLSF, idxSubGain, idxFrameGain; - Word16 Q_combined_gains[NUM_SHB_SUBFR/4]; - Word16 lsf_q[LPC_SHB_ORDER]; - Word16 lsf_idx[NUM_Q_LSF]; - Word16 m_idx, grid_idx; - Word16 m; - Word32 L_tmp; - Word16 tmp, frac, exp; - Word16 idx_shb_fr_gain, idx_res_gs[5], idx_mixFac; - Word16 temp_shb_ener_sf_fx; - - /* LSFs */ - - IF( sub( extl, WB_TBE ) == 0 ) - { - IF( L_sub( extl_brate, WB_TBE_0k35 ) == 0 ) - { - idxFrameGain = st_fx->gFrame_WB_fx; - idxLSF = st_fx->lsf_WB_fx; - - Copy( lbr_wb_bwe_lsfvq_cbook_2bit_fx + idxLSF * LPC_SHB_ORDER_LBR_WB, Q_lsf, LPC_SHB_ORDER_LBR_WB ); - set16_fx( Q_subgain, RECIP_ROOT_EIGHT_FX, NUM_SHB_SUBFR / 2 ); - Copy32( SHBCB_FrameGain16_fx + idxFrameGain, Q_framegrain, 1 ); - } - ELSE - { - *uv_flag = ( Word16 )get_next_indice_fx( st_fx, 1 ); - idxSubGain = ( Word16 )get_next_indice_fx( st_fx, NUM_BITS_SHB_SUBGAINS ); - move16(); - idxFrameGain = ( Word16 )get_next_indice_fx( st_fx, NUM_BITS_SHB_FrameGain ); - move16(); - idxLSF = ( Word16 )get_next_indice_fx( st_fx, NUM_BITS_WB_LSF ); - move16(); - Copy( wb_bwe_lsfvq_cbook_8bit_fx + idxLSF * LPC_SHB_ORDER_WB, Q_lsf, LPC_SHB_ORDER_WB ); - Copy( HBCB_SubGain5bit_fx + idxSubGain * NUM_SHB_SUBFR / 4, Q_combined_gains, NUM_SHB_SUBFR / 4 ); - - FOR( i = 0; i < NUM_SHB_SUBFR / 4; i++ ) - { - - L_tmp = L_mult( Q_combined_gains[i], 21771 ); /*Q26 0.166096 in Q17 */ - L_tmp = L_shr( L_tmp, 10 ); - frac = L_Extract_lc( L_tmp, &exp ); - tmp = extract_l( Pow2( 14, frac ) ); /* Put 14 as exponent so that */ - /* output of Pow2() will be: */ - /* 16384 < Pow2() <= 32767 */ - Q_combined_gains[i] = shl( tmp, add( exp, 1 ) ); /* Q15 */ - } - - FOR( i=0; i < NUM_SHB_SUBFR / 2; i+= 2) - { - Q_subgain[i] = Q_combined_gains[i / 2]; - move16(); - Q_subgain[i + 1] = Q_combined_gains[i / 2]; - move16(); - } - - /* frame gain */ - Copy32( SHBCB_FrameGain64_fx + idxFrameGain, Q_framegrain, 1 ); - } - } - ELSE /* SWB TBE DEC */ - { - IF(sub(st_fx->codec_mode,MODE2) == 0) - { - idxSubGain = st_fx->idxSubGains_fx; - idxFrameGain = st_fx->idxFrameGain_fx; - } - ELSE - { - idxSubGain = ( Word16 )get_next_indice_fx( st_fx, NUM_BITS_SHB_SUBGAINS ); - idxFrameGain = ( Word16 )get_next_indice_fx( st_fx, NUM_BITS_SHB_FRAMEGAIN ); - } - - test(); - IF( L_sub(st_fx->total_brate_fx, ACELP_24k40) == 0 || L_sub(st_fx->total_brate_fx, ACELP_32k) == 0 ) - { - IF(sub(st_fx->codec_mode,MODE2) == 0) - { - idx_shb_fr_gain = st_fx->idx_shb_fr_gain_fx; - } - ELSE - { - idx_shb_fr_gain = get_next_indice_fx( st_fx, NUM_BITS_SHB_ENER_SF ); - } - temp_shb_ener_sf_fx = usdequant_fx(idx_shb_fr_gain, 0, 86); /* 86 = 0.042f in Q11 = Qin-1 */ - /* o: temp_shb_ener_sf_fx in Q12 */ - - /* *Q_shb_ener_sf = Pow(10.0, temp_shb_ener_sf_fx ); */ - /* = pow(2, 3.321928*temp_shb_ener_sf_fx) */ - L_tmp = L_mult(temp_shb_ener_sf_fx, 27213 ); /* 3.321928 in Q13 -> L_tmp in Q12+Q13+1 = Q26 */ - L_tmp = L_shl( L_tmp, -10 ); /* bring L_tmp from Q26 to Q16 */ - frac = L_Extract_lc( L_tmp, &exp ); /* Extract exponent */ - L_tmp = Pow2(14, frac ); - *Q_shb_ener_sf = L_shl(L_tmp, exp-14+0 ); /* In Q_ener: 2*Q_shb+1, Q_shb = 0; */ - - FOR(i=0; i<5; i++) - { - IF(sub(st_fx->codec_mode,MODE2) == 0) - { - idx_res_gs[i] = st_fx->idx_res_gs_fx[i]; - move16(); - } - ELSE - { - idx_res_gs[i] = get_next_indice_fx( st_fx, NUM_BITS_SHB_RES_GS ); - move16(); - } - Q_shb_res_gshape[i] = usdequant_fx(idx_res_gs[i], - 2048/*0.125f Q14*/, /*2048 = 0.125 in Q14 */ - 1024/*0.125f Q13*/ /*1024 = 0.125 in Q13 */ - ); - move16(); - /* o: Q_shb_res_gshape in Q14 */ - } - - IF(sub(st_fx->codec_mode,MODE2) == 0) - { - idx_mixFac = st_fx->idx_mixFac_fx; - move16(); - } - ELSE - { - idx_mixFac = (Word16)get_next_indice_fx( st_fx, NUM_BITS_SHB_VF ); - } - *Q_mixFactors = usdequant_fx(idx_mixFac, 4096 /* 0.125 in Q15 */, 2048 /* 0.125 in Q14 */); - move16(); - /* o: Q_mixFactors in Q15 */ - } - ELSE - { - *Q_shb_ener_sf = L_deposit_l(0); - *Q_mixFactors = 0; - move16(); - set16_fx(Q_shb_res_gshape, 0, 5); - } - - /* LSFs */ - - - test(); - test(); - test(); - test(); - test(); - IF( (st_fx->rf_flag == 0) && !((L_sub(st_fx->total_brate_fx, ACELP_9k60) == 0) || ((st_fx->total_brate_fx == 0) && ( (L_sub(st_fx->last_total_brate_fx, ACELP_9k60) == 0) || (L_sub(st_fx->last_total_brate_fx, ACELP_13k20) == 0 && sub(st_fx->rf_flag_last, 1) == 0) ))) ) - - { - /* LSFs */ - test(); - test(); - test(); - IF ( L_sub(extl_brate, SWB_TBE_1k6) == 0 || L_sub(extl_brate, FB_TBE_1k8) == 0 || L_sub(extl_brate, SWB_TBE_2k8) == 0 || L_sub(extl_brate, FB_TBE_3k0) == 0 ) - { - IF(sub(st_fx->codec_mode,MODE2) == 0) - { - FOR (i = 0; i < NUM_Q_LSF; i++) - { - lsf_idx[i] = st_fx->lsf_idx_fx[i]; - move16(); - - } - } - ELSE - { - FOR (i = 0; i < NUM_Q_LSF; i++) - { - lsf_idx[i] = (Word16)get_next_indice_fx(st_fx, lsf_q_num_bits[i]); - move16(); - } - } - } - Dequant_lower_LSF_fx( lsf_idx, lsf_q ); - - IF(sub(st_fx->codec_mode,MODE2) == 0) - { - m_idx = st_fx->m_idx_fx; - } - ELSE - { - m_idx = (Word16)get_next_indice_fx( st_fx, MIRROR_POINT_BITS ); - move16(); - } - - Dequant_mirror_point_fx( lsf_q, m_idx, &m ); - - /* safety check in case of bit errors */ - IF(sub(m, MAX_LSF_FX) > 0) - { - st_fx->BER_detect = 1; - m = MAX_LSF_FX-1; - } - - IF(sub(st_fx->codec_mode,MODE2) == 0) - { - grid_idx = st_fx->grid_idx_fx; - } - ELSE - { - grid_idx = (Word16)get_next_indice_fx( st_fx, NUM_LSF_GRID_BITS ); - move16(); - } - - Map_higher_LSF_fx( lsf_q, m, lsf_grid_fx[grid_idx] ); - - FOR (i = 0; i < LPC_SHB_ORDER; i++) - { - /* safety check in case of bit errors */ - IF(sub(lsf_q[LPC_SHB_ORDER - 1 - i], MAX_LSF_FX) > 0) - { - st_fx->BER_detect = 1; - lsf_q[LPC_SHB_ORDER - 1 - i] = MAX_LSF_FX - 1; - } - Q_lsf[i] = sub( 16384, lsf_q[LPC_SHB_ORDER - 1 - i] ); - move16(); - } - } - ELSE - { - set16_fx(lsf_idx, 0, 5); - Copy(st_fx->lsf_idx_fx, lsf_idx, 5); - grid_idx = 0; - m_idx = 0; - Copy(swb_tbe_lsfvq_cbook_8b + lsf_idx[0]*LPC_SHB_ORDER, Q_lsf, LPC_SHB_ORDER); - } - - space_lsfs_fx( Q_lsf, LPC_SHB_ORDER ); - - /* Dequantize subgain indices */ - j = idxSubGain * NUM_SHB_SUBGAINS; - move16(); - FOR( i = 0; i < NUM_SHB_SUBGAINS; i++ ) - { - /* Q_subgain[i] = (float) pow(10.0, SHBCB_SubGain5bit[j++]); */ - - L_tmp = L_mult( SHBCB_SubGain5bit_fx[j++], 27213 ); /*Q28 3.321928 in Q13 */ - L_tmp = L_shr( L_tmp, 12 ); - frac = L_Extract_lc( L_tmp, &exp ); - tmp = extract_l( Pow2( 14, frac ) ); /* Put 14 as exponent so that */ - /* output of Pow2() will be: */ - /* 16384 < Pow2() <= 32767 */ - Q_subgain[i] = shl( tmp, add( exp, 1 ) ); /*Q15*/ move16(); - } - - FOR( i = NUM_SHB_SUBFR - 1; i >= 0; i-- ) - { - Q_subgain[i] = Q_subgain[i * NUM_SHB_SUBGAINS / NUM_SHB_SUBFR]; - move16(); - } - - /* Frame gain */ - *Q_framegrain = L_mac( SHB_GAIN_QLOW_FX, idxFrameGain, SHB_GAIN_QDELTA_FX ); - move32();/*Q18*/ - L_tmp = Mult_32_16( *Q_framegrain, 27213 ); /*Q16*/ /* 3.321928 in Q13 */ - frac = L_Extract_lc( L_tmp, &exp ); - L_tmp = Pow2( 30, frac ); - *Q_framegrain = L_shl( L_tmp, sub( exp, 12 ) ); /*Q18*/ - } - - return; -} - -/*-------------------------------------------------------------------* - * fb_tbe_dec() - * - * FB TBE decoder, 14(resp. 15.5) - 20 kHz band decoding module - *-------------------------------------------------------------------*/ -void fb_tbe_dec_fx( - Decoder_State_fx *st, /* i/o: encoder state structure */ - const Word16 fb_exc[], /* i : FB excitation from the SWB part */ - Word16 Q_fb_exc, - Word16 *hb_synth, /* o : high-band synthesis */ - Word16 hb_synth_exp -) - -{ - Word16 i; - Word16 ratio = 0; - Word32 fb_exc_energy = 0; - Word16 fb_synth[L_FRAME48k]; - - /* decode FB slope information */ - test(); - test(); - IF ( sub(st->extl_fx,FB_TBE) == 0 && !st->bfi_fx ) - { - IF( sub(st->codec_mode,MODE2) == 0 ) - { - i = st->idxGain_fx; - move16(); - } - ELSE - { - i = (Word16)get_next_indice_fx( st, 4 ); - } - ratio = shl(1,i); - } - ELSE if ( sub(st->extl_fx,FB_TBE) == 0 && st->bfi_fx ) - { - ratio = st->prev_fbbwe_ratio_fx; - move16(); - } - fb_exc_energy = sum2_fx_mod(fb_exc,L_FRAME16k); - - /* FB TBE synthesis */ - synthesise_fb_high_band_fx( fb_exc,Q_fb_exc,fb_synth,fb_exc_energy,ratio, st->L_frame_fx, st->bfi_fx, &(st->prev_fbbwe_ratio_fx), st->fbbwe_hpf_mem_fx, st->fbbwe_hpf_mem_fx_Q,hb_synth_exp); - - /* add the fb_synth component to the hb_synth component */ - /* v_add_fx( hb_synth, fb_synth, hb_synth, L_FRAME48k );*/ - FOR (i=0; irf_flag,1)==0 || L_sub(st_fx->total_brate_fx,ACELP_9k60) == 0 ) && sub(st_fx->bwidth_fx,WB) == 0) - { - /* WB LSF */ - st_fx->lsf_WB_fx = get_next_indice_fx(st_fx, NUM_BITS_LBR_WB_LSF); - - /* WB frame gain */ - st_fx->gFrame_WB_fx = get_next_indice_fx(st_fx, NUM_BITS_SHB_FrameGain_LBR_WB); - } - ELSE IF ( ( L_sub( st_fx->total_brate_fx, ACELP_9k60 ) >= 0 ) && ( L_sub( st_fx->total_brate_fx, ACELP_32k ) <= 0 ) && - ( ( sub( st_fx->bwidth_fx, SWB ) == 0 ) || ( sub( st_fx->bwidth_fx, FB ) == 0 ) ) ) - { - test(); - IF( (st_fx->rf_flag == 0) && (L_sub(st_fx->total_brate_fx, ACELP_9k60) > 0) ) - { - FOR (i = 0; i < NUM_Q_LSF; i++) - { - st_fx->lsf_idx_fx[i] = get_next_indice_fx(st_fx, lsf_q_num_bits[i]); - move16(); - } - - st_fx->m_idx_fx = get_next_indice_fx(st_fx, MIRROR_POINT_BITS); - - st_fx->grid_idx_fx = get_next_indice_fx(st_fx, NUM_LSF_GRID_BITS); - - } - ELSE - { - st_fx->lsf_idx_fx[0] = get_next_indice_fx(st_fx, 8); - move16(); - st_fx->m_idx_fx = 0; - move16(); - st_fx->grid_idx_fx = 0; - move16(); - } - - /* shape gains */ - st_fx->idxSubGains_fx = get_next_indice_fx(st_fx, NUM_BITS_SHB_SUBGAINS); - - /* frame gain */ - st_fx->idxFrameGain_fx = get_next_indice_fx(st_fx, NUM_BITS_SHB_FRAMEGAIN); - - IF ( L_sub( st_fx->total_brate_fx, ACELP_24k40 ) >= 0 ) - { - /* sub frame energy*/ - st_fx->idx_shb_fr_gain_fx = get_next_indice_fx(st_fx, NUM_BITS_SHB_ENER_SF); - - /* gain shapes residual */ - FOR (i = 0; i < NB_SUBFR16k; i++) - { - st_fx->idx_res_gs_fx[i] = get_next_indice_fx(st_fx, NUM_BITS_SHB_RES_GS); - move16(); - } - - /* voicing factor */ - st_fx->idx_mixFac_fx = get_next_indice_fx(st_fx, NUM_BITS_SHB_VF); - } - - IF (sub(st_fx->tec_tfa, 1) == 0) - { - st_fx->tec_flag = get_next_indice_fx(st_fx, BITS_TEC); - st_fx->tfa_flag = get_next_indice_fx(st_fx, BITS_TFA); - test(); - IF (st_fx->tfa_flag && st_fx->tec_flag) - { - st_fx->tec_flag = 2; - move16(); - st_fx->tfa_flag = 0; - move16(); - } - } - ELSE - { - st_fx->tec_flag = 0; - move16(); - st_fx->tfa_flag = 0; - move16(); - } - } - - IF ( sub( st_fx->bwidth_fx, FB ) == 0 ) - { - st_fx->idxGain_fx = get_next_indice_fx(st_fx, 4); - } -} - - -/*---------------------------------------------------------------------* -* GenTransition() -* -* Generate a highband transition signal from the gain shape overlap -* buffer to fill the gap caused by the delay alignment buffer when -* switching from TBE to IGF -*---------------------------------------------------------------------*/ -void GenTransition_fx( - const Word16 *input, /* i : gain shape overlap buffer */ - const Word16 *old_hb_synth, /* i : synthesized HB from previous frame */ - Word16 length, /* i : targeted length of transition signal */ - Word16 *output, /* o : synthesized transitions signal */ - Word32 Hilbert_Mem[], /* i/o: memory */ - Word16 state_lsyn_filt_shb_local[],/* i/o: memory */ - Word16 *syn_dm_phase, - Word32 target_fs, - Word16 *up_mem, - Word16 rf_flag - , Word32 bitrate -) -{ - Word16 i; - Word16 syn_overlap_32k[L_FRAME32k]; - Word32 L_tmp; - Word16 ol_len = 2*SHB_OVERLAP_LEN; - - /* upsample overlap snippet */ - Interpolate_allpass_steep_fx( input, state_lsyn_filt_shb_local, SHB_OVERLAP_LEN, syn_overlap_32k ); - - /* perform spectral flip and downmix with overlap snippet to match HB synth */ - test(); - IF( (rf_flag != 0) || L_sub( bitrate, ACELP_9k60 ) == 0 ) - { - flip_and_downmix_generic_fx( syn_overlap_32k, syn_overlap_32k, 2*SHB_OVERLAP_LEN, Hilbert_Mem, - Hilbert_Mem + HILBERT_ORDER1, Hilbert_Mem + (HILBERT_ORDER1+2*HILBERT_ORDER2), - syn_dm_phase ); - } - ELSE - { - FOR(i = 0; i < ol_len; i=i+2) - { - syn_overlap_32k[i] = negate(syn_overlap_32k[i]); - move16(); - syn_overlap_32k[i+1] = syn_overlap_32k[i+1]; - move16(); - } - } - - /* cross fade of overlap snippet and mirrored HB synth from previous frame */ - FOR ( i = 0; i < ol_len; i++ ) - { - L_tmp = L_mult( window_shb_32k_fx[i], old_hb_synth[L_SHB_TRANSITION_LENGTH-1-i] ); - output[i] = mac_r( L_tmp, window_shb_32k_fx[2*L_SHB_LAHEAD-1-i], syn_overlap_32k[i] ); - } - - /* fill transition signal with mirrored HB synth from previous frame to fully fill delay alignment buffer gap */ - FOR ( ; i < length; i++) - { - output[i] = old_hb_synth[L_SHB_TRANSITION_LENGTH-1-i]; - } - - IF ( L_sub( target_fs, 48000 ) == 0 ) - { - interpolate_3_over_2_allpass_fx( output, length, output, up_mem, allpass_poles_3_ov_2 ); - } - - return; -} - - -/*---------------------------------------------------------------------* - * GenTransition_WB_fx() - * - *---------------------------------------------------------------------*/ - -void GenTransition_WB_fx( - const Word16 *input, /* i : gain shape overlap buffer */ - const Word16 *old_hb_synth, /* i : synthesized HB from previous frame */ - const Word16 prev_Qx, /* i : scaling of old_hb_synth */ - Word16 length, /* i : targeted length of transition signal */ - Word16 *output, /* o : synthesized transitions signal */ - Word16 state_lsyn_filt_shb1[], - Word16 state_lsyn_filt_shb2[], - Word32 output_Fs, - Word16 *up_mem -) -{ - Word16 i; - Word32 L_tmp; - Word16 speech_buf_16k1[L_FRAME16k], speech_buf_16k2[L_FRAME16k]; - Word16 upsampled_synth[L_FRAME48k]; - Word16 input_scaled[SHB_OVERLAP_LEN/2]; - - /* upsample overlap snippet */ - Copy_Scale_sig(input, input_scaled, SHB_OVERLAP_LEN/2, prev_Qx); - Interpolate_allpass_steep_fx( input_scaled, state_lsyn_filt_shb1, SHB_OVERLAP_LEN/2, speech_buf_16k1); - Interpolate_allpass_steep_fx( speech_buf_16k1, state_lsyn_filt_shb2, SHB_OVERLAP_LEN, speech_buf_16k2); - - - /* perform spectral flip and downmix with overlap snippet to match HB synth */ - FOR(i = 0; i < SHB_OVERLAP_LEN; i+=2) - { - speech_buf_16k2[i] = negate(speech_buf_16k2[i]); - speech_buf_16k2[i+1] = speech_buf_16k2[i+1]; - } - - /* cross fade of overlap snippet and mirrored HB synth from previous frame */ - FOR (i=0; ilast_core_fx,ACELP_CORE) != 0 ) - { - set16_fx( st_fx->old_bwe_exc_fx, 0, PIT16k_MAX * 2 ); - st_fx->bwe_non_lin_prev_scale_fx = L_deposit_l(0); - st_fx->prev_Q_bwe_exc = 31; - move16(); - } - - test(); - IF( sub(bandwidth, WB) == 0 ) - { - wb_tbe_extras_reset_fx( st_fx->mem_genSHBexc_filt_down_wb2_fx, st_fx->mem_genSHBexc_filt_down_wb3_fx ); - wb_tbe_extras_reset_synth_fx( st_fx->state_lsyn_filt_shb_fx, st_fx->state_lsyn_filt_dwn_shb_fx, st_fx->state_32and48k_WB_upsample_fx, st_fx->mem_resamp_HB_fx ); - - set16_fx( st_fx->mem_genSHBexc_filt_down_shb_fx, 0, 7 ); - set16_fx( st_fx->state_lpc_syn_fx, 0, 10 ); - set16_fx( st_fx->state_syn_shbexc_fx, 0, L_SHB_LAHEAD/4 ); - set16_fx( st_fx->syn_overlap_fx, 0, L_SHB_LAHEAD ); - set32_fx( st_fx->mem_csfilt_fx, 0, 2 ); - } - ELSE IF( sub(bandwidth, SWB) == 0 || sub(bandwidth, FB) == 0 ) - { - swb_tbe_reset_fx( st_fx->mem_csfilt_fx, st_fx->mem_genSHBexc_filt_down_shb_fx, st_fx->state_lpc_syn_fx, - st_fx->syn_overlap_fx, st_fx->state_syn_shbexc_fx, &(st_fx->tbe_demph_fx), - &(st_fx->tbe_premph_fx), st_fx->mem_stp_swb_fx, &(st_fx->gain_prec_swb_fx) ); - - swb_tbe_reset_synth_fx( st_fx->genSHBsynth_Hilbert_Mem_fx, st_fx->genSHBsynth_state_lsyn_filt_shb_local_fx ); - - set16_fx( st_fx->GainShape_Delay, 0, NUM_SHB_SUBFR/2 ); - set16_fx( st_fx->int_3_over_2_tbemem_dec_fx, 0, INTERP_3_2_MEM_LEN); - set16_fx( st_fx->mem_resamp_HB_32k_fx, 0, 2*ALLPASSSECTIONS_STEEP+1 ); - - IF( sub(bandwidth, FB) == 0 ) - { - st_fx->prev_fb_ener_adjust_fx = 0; - set16_fx( st_fx->fb_state_lpc_syn_fx, 0, LPC_SHB_ORDER ); - st_fx->fb_tbe_demph_fx = 0; - fb_tbe_reset_synth_fx( st_fx->fbbwe_hpf_mem_fx, st_fx->fbbwe_hpf_mem_fx_Q,&st_fx->prev_fbbwe_ratio_fx ); - } - } - - return; -} diff --git a/src/libs/libevs/lib_dec/syn_outp.cpp b/src/libs/libevs/lib_dec/syn_outp.cpp new file mode 100644 index 00000000..c544bcc9 --- /dev/null +++ b/src/libs/libevs/lib_dec/syn_outp.cpp @@ -0,0 +1,105 @@ +/*==================================================================================== + EVS Codec 3GPP TS26.443 Nov 13, 2018. Version 12.11.0 / 13.7.0 / 14.3.0 / 15.1.0 + ====================================================================================*/ + +#include +#include "options.h" +#include "cnst.h" +#include "prot.h" + +/*---------------------------------------------------------------------* + * Local functions + *---------------------------------------------------------------------*/ + +/*-------------------------------------------------------------------* + * syn_output() + * + * Output synthesis signal with compensation for saturation + * returns number of clipped samples + *-------------------------------------------------------------------*/ + +unsigned int syn_output( /* o : number of clipped samples */ + float *synth, /* i/o: float synthesis signal */ + const short output_frame, /* i : output frame length */ + short *synth_out /* o : integer 16 bits synthesis signal */ +) +{ + /*-----------------------------------------------------------------* + * float to integer conversion with saturation control + *-----------------------------------------------------------------*/ + + /* integer conversion */ + return mvr2s( synth, synth_out, output_frame ); +} + + +/*-------------------------------------------------------------------* + * AGC_dec() + * + * In-place saturation control (Automatic Gain Control) + *-------------------------------------------------------------------*/ + +void AGC_dec( + float x[], /* i/o: input/output vector */ + float mem[], /* i/o: mem[2] should be init to [0,0] */ + const short n /* i : vector size */ +) +{ + short i; + float fac, prev, tmp, frame_fac, max; + + /*-----------------------------------------------------------------* + * calculate AGC factor to avoid saturation + *-----------------------------------------------------------------*/ + + max = 0.0f; + + for (i=0; i max) + { + max = tmp; + } + } + + frame_fac = 0.0f; + if ( max > 30000.0f ) + { + frame_fac = 0.5f - (15000.0f/max); + } + + fac = mem[0]; + prev = mem[1]; + + /*-----------------------------------------------------------------* + * AGC + *-----------------------------------------------------------------*/ + + for (i=0; i 32767.0f) + { + tmp = 32767.0f; + } + else if (tmp < -32768.0f) + { + tmp = -32768.0f; + } + + x[i] = (short)floor(tmp + 0.5f); + + } + + mem[0] = fac; + mem[1] = prev; + + return ; +} diff --git a/src/libs/libevs/lib_dec/syn_outp_fx.cpp b/src/libs/libevs/lib_dec/syn_outp_fx.cpp deleted file mode 100755 index 219ff88f..00000000 --- a/src/libs/libevs/lib_dec/syn_outp_fx.cpp +++ /dev/null @@ -1,116 +0,0 @@ -/*==================================================================================== - EVS Codec 3GPP TS26.442 Apr 03, 2018. Version 12.11.0 / 13.6.0 / 14.2.0 - ====================================================================================*/ - -#include "options.h" /* Compilation switches */ -#include "cnst_fx.h" /* Common constants */ -#include "prot_fx.h" /* Debug prototypes */ -#include "stl.h" /* required for wmc_tool */ - -/*-------------------------------------------------------------------* - * syn_output() - * - * Output synthesis signal with compensation for saturation - *-------------------------------------------------------------------*/ - -void syn_output_fx( - const Word16 codec_mode, /* i : MODE1 or MODE2 */ - Word16 *synth, /* i/o: float synthesis signal */ - const Word16 output_frame, /* i : output frame length */ - Word16 *synth_out, /* o : integer 16 bits synthesis signal */ - const Word16 Q_syn2 /* i : Synthesis scaling factor */ -) -{ - Word16 i, tmp; - Word32 L_tmp; - - /*tmp = sub(Q_syn2, 1); */ - tmp = Q_syn2; - - /*-----------------------------------------------------------------* - * Output synthesis signal with compensation for saturation - *-----------------------------------------------------------------*/ - - test(); - IF( codec_mode == MODE2 || sub(output_frame,L_FRAME8k) == 0 ) - { - /* integer conversion */ - /*mvr2s( synth, synth_out, output_frame ); */ - FOR (i = 0; i < output_frame; i++) - { - L_tmp = L_deposit_h(synth[i]); - synth_out[i] = round_fx(L_shr(L_tmp, tmp)); - } - } - ELSE - { - Copy_Scale_sig( synth, synth_out, output_frame, negate(tmp) ); - } - - return; -} -/*-------------------------------------------------------------------* - * Local function - * unscale_AGC - * - * Output synthesis signal with compensation for saturation - *-------------------------------------------------------------------*/ -void unscale_AGC( - const Word16 x[], /* i: 16kHz synthesis Qx */ - const Word16 Qx, /* i: scale factor of x */ - Word16 y[], /* o: output vector Q0 */ - Word16 mem[], /* i/o: mem[2] should be init to [0,0] */ - const Word16 n /* i: vector size */ -) -{ - Word16 i, fac, tmp, frame_fac, max; - Word32 L_tmp; - - /*----------------------------------------------------------------* - * calculate AGC factor to avoid saturation - *----------------------------------------------------------------*/ - - max = abs_s(x[0]); - FOR (i = 1; i < n; i++) - { - max = s_max(max, abs_s(x[i])); - } - BASOP_SATURATE_WARNING_OFF - tmp = shl(30000, Qx); /* saturation can occurs here */ - BASOP_SATURATE_WARNING_ON - frame_fac = 0; - move16(); - IF (sub(max, tmp) > 0) - { - frame_fac = sub(16384, div_s(shr(tmp, 1), max)); /* frame fac in Q15 */ - } - - /*----------------------------------------------------------------* - * AGC - *----------------------------------------------------------------*/ - /* update AGC factor (slowly) */ - fac = mac_r(L_mult(32440, mem[0]), 328, frame_fac); - - L_tmp = L_mult(x[0], 16384); - L_tmp = L_msu0(L_tmp, fac, x[0]); - L_tmp = L_msu(L_tmp, fac, mem[1]); - L_tmp = L_shr(L_tmp, -1); /* saturation can occur here */ - - y[0] = round_fx(L_tmp); - - FOR (i = 1; i < n; i++) - { - /* update AGC factor (slowly) */ - fac = mac_r(L_mult(32440, fac), 328, frame_fac); - - L_tmp = L_deposit_h(x[i]); - L_tmp = L_msu(L_tmp, fac, x[i]); - L_tmp = L_msu(L_tmp, fac, x[i-1]); - y[i] = round_fx(L_tmp); - } - - mem[0] = fac; - move16(); - mem[1] = shr(x[sub(i, 1)], 1); - move16(); -} diff --git a/src/libs/libevs/lib_dec/tcq_core_dec.cpp b/src/libs/libevs/lib_dec/tcq_core_dec.cpp new file mode 100644 index 00000000..0abe8542 --- /dev/null +++ b/src/libs/libevs/lib_dec/tcq_core_dec.cpp @@ -0,0 +1,436 @@ +/*==================================================================================== + EVS Codec 3GPP TS26.443 Nov 13, 2018. Version 12.11.0 / 13.7.0 / 14.3.0 / 15.1.0 + ====================================================================================*/ + +#include +#include +#include "options.h" +#include "cnst.h" +#include "rom_com.h" +#include "prot.h" +#include "basop_util.h" +#include "basop_proto_func.h" + +/*---------------------------------------------------------------------* + * tcq_core_LR_enc() + * + * Main Generic Audio Decoder Routine for LR-MDCT + *---------------------------------------------------------------------*/ + +void tcq_core_LR_dec( + Decoder_State *st, + int *inp_vector, + const short bit_budget, + const short BANDS, + const short *band_start, + const short *band_width, + Word32 *Rk_fx, + int *npulses, + short *k_sort, + const short *p2a_flags, + const short p2a_bands, + const short *last_bitalloc, + const short input_frame, + const short adjustFlag, + const short *is_transient +) +{ + short i, j, k; + float Rk_sort[NB_SFM]; + short flag_wbnb = 0; + short USQ_TCQ[NB_SFM]; /* TCQ is selected by default*/ + short nb_bytes, pulsesnum, nz; + int positions[L_FRAME32k]; + short k_num[2]; + ARCODEC ardec, *pardec; + BITSTREAM bs, *pbs; + + int nzbands = 0; + int lsbtcq_bits = TCQ_AMP; + int tcq_arbits = 2; + + /* LSB TCQ variables*/ + short dpath[280]; + short bcount = 0; + float mbuffer[560]; + + Word32 leftbits = 0; + Word32 sepbits = 0; + Word32 divider = 0; + + /*Word32 Rk_fx[NB_SFM];*/ /* Q16 */ + Word32 Rk_sort_fx[NB_SFM]; /* Q16 */ + Word32 bsub_fx = 0; + + Word16 nzb = 0; + Word32 delta_fx; + Word32 surplus_fx; + Word32 bit_surplus_fx[2]; + + /* initialization */ + set_s(dpath, 0, 280); + set_f(mbuffer, 0.f, 560); + set_f( Rk_sort, 0.f, NB_SFM ); + set_s( USQ_TCQ, 0, NB_SFM ); + set_i( positions, 0, L_FRAME32k ); + + if( input_frame <= L_FRAME16k && adjustFlag == 0 && *is_transient == 0 ) + { + flag_wbnb = 1; + lsbtcq_bits = 0; + tcq_arbits = 0; + } + + pardec = &ardec; + pbs = &bs; + pbs->curPos = 7; + pbs->numbits = 0; + pbs->numByte = 0; + + /* Bits distribution analysis*/ + for( i = 0; i < BANDS; i++ ) + { + if( L_sub( ar_div(Rk_fx[i], band_width[i]), 49152) >= 0) + { + /* USQ used for high importance bands*/ + USQ_TCQ[i] = 1; + } + else + { + /* TCQ used for usual bands*/ + USQ_TCQ[i] = 0; + } + if( Rk_fx[i] > 0.0f ) + { + nzbands++; + } + } + + for( j = 0; j < BANDS; j++ ) + { + if( Rk_fx[j] > 0.0f ) + { + nzb++; + } + } + + bsub_fx = L_shl(L_add(tcq_arbits, lsbtcq_bits), 16); + IF( bsub_fx > 0) + { + bsub_fx = L_add( bsub_fx, 2048); + } + for( j = BANDS - 1; j >= 0; j-- ) + { + if( Rk_fx[j] > 0 ) + { + Rk_fx[j] = L_sub(Rk_fx[j], ar_div(bsub_fx, nzb)); + if( Rk_fx[j] < 0) + { + bsub_fx = L_sub(bsub_fx, L_add(ar_div(bsub_fx, nzb), Rk_fx[j])); + Rk_fx[j] = 0; + } + else + { + bsub_fx = L_sub(bsub_fx, ar_div(bsub_fx, nzb)); + } + nzb = sub(nzb, 1); + } + } + + srt_vec_ind_fx( Rk_fx, Rk_sort_fx, k_sort, BANDS); + + /*read the bits*/ + nb_bytes = bit_budget >> 3; + k = bit_budget - (nb_bytes << 3); + for( i = 0; i < nb_bytes; i++ ) + { + pbs->buf[i] = (unsigned char)get_next_indice(st, 8); + } + + if( k > 0 ) + { + pbs->buf[nb_bytes] = (unsigned char)get_next_indice(st, (short)k); + pbs->buf[nb_bytes] <<= (8 - k); + i++; + nb_bytes++; + } + /* set two more bytes, which are used to flush the arithmetic coder, to 0 + -> this avoids reading of uninitialized memory */ + nb_bytes = min(nb_bytes + 2, MAX_SIZEBUF_PBITSTREAM); + for( ; i < nb_bytes; i++ ) + { + pbs->buf[i] = 0; + } + + pbs->maxBytes = nb_bytes; + + ar_decoder_start( pardec, pbs ); + + delta_fx = 0; + surplus_fx = 0; + + if( input_frame <= L_FRAME16k && adjustFlag == 0 && *is_transient == 0 ) + { + surplus_fx = -131072; + + bit_allocation_second_fx( Rk_fx, Rk_sort_fx, BANDS, band_width, + k_sort, k_num, p2a_flags, p2a_bands, last_bitalloc, input_frame); + + nzbands = 0; + for ( j = 0; j < BANDS; j++ ) + { + if ( sub(j, k_num[0]) == 0 || sub(j, k_num[1]) == 0) + { + sepbits = L_add( sepbits, Rk_fx[k_sort[j]]); + } + else + { + leftbits = L_add( leftbits, Rk_fx[k_sort[j]]); + if( Rk_fx[k_sort[j]] > 0 ) + { + nzbands = add(nzbands, 1); + } + } + } + + for( k = 0; k < BANDS; k++ ) + { + if( k != k_num[0] && k != k_num[1]) + { + if (Rk_fx[k_sort[k]] > 0 && USQ_TCQ[k_sort[k]] == 0) + { + /* When number of bits per band is less than + arithmetic bits overhead, this band is not encoded. + It may happens when the actual number of bits per + band is near same to estimated number of bits, for + most bands (very unprobable but possible) */ + if( L_add( Rk_fx[k_sort[k]], delta_fx) < 0 ) + { + pulsesnum = 0; + for( i = 0; i < band_width[k_sort[k]]; i++ ) + { + inp_vector[band_start[k_sort[k]] + i] = 0; + } + if( surplus_fx != 0 ) + { + surplus_fx = L_add( Rk_fx[k_sort[k]], surplus_fx); + surplus_fx = L_add( delta_fx, surplus_fx); + } + } + else + { + /*get number of pulses */ + pulsesnum = GetScale_fx( band_width[k_sort[k]], + L_add( Rk_fx[k_sort[k]], delta_fx), + &surplus_fx ); + + leftbits = L_sub( leftbits, L_add( Rk_fx[k_sort[k]], delta_fx) ); + + decode_position_ari_fx( pardec, band_width[k_sort[k]], pulsesnum, &nz, &positions[band_start[k_sort[k]]] ); + decode_mangitude_tcq_fx( pardec, band_width[k_sort[k]], pulsesnum, nz, &positions[band_start[k_sort[k]]], &inp_vector[band_start[k_sort[k]]], &surplus_fx ); + decode_signs_fx( pardec, band_width[k_sort[k]], &inp_vector[band_start[k_sort[k]]] ); + + } + nzbands--; + } + else if (Rk_fx[k_sort[k]] > 0 && USQ_TCQ[k_sort[k]] == 1) + { + /* When number of bits per band is less than + arithmetic bits overhead, this band is not encoded. + It may happens when the actual number of bits per + band is near same to estimated number of bits, for + most bands (very unprobable but possible) */ + if( L_add( Rk_fx[k_sort[k]], delta_fx) < 0 ) + { + pulsesnum = 0; + for( i = 0; i < band_width[k_sort[k]]; i++ ) + { + inp_vector[band_start[k_sort[k]] + i] = 0; + } + if( surplus_fx != 0 ) + { + surplus_fx = L_add( Rk_fx[k_sort[k]], surplus_fx); + surplus_fx = L_add( delta_fx, surplus_fx); + } + } + else + { + + pulsesnum = GetScale_fx(band_width[k_sort[k]], + L_add( Rk_fx[k_sort[k]], delta_fx), + &surplus_fx); + + leftbits = L_sub( leftbits, L_add( Rk_fx[k_sort[k]], delta_fx) ); + + decode_position_ari_fx( pardec, band_width[k_sort[k]], pulsesnum, &nz, &positions[band_start[k_sort[k]]] ); + decode_magnitude_usq_fx( pardec, band_width[k_sort[k]], pulsesnum, nz, &positions[band_start[k_sort[k]]], &inp_vector[band_start[k_sort[k]]] ); + decode_signs_fx( pardec, band_width[k_sort[k]], &inp_vector[band_start[k_sort[k]]] ); + + } + nzbands--; + } + else + { + pulsesnum = 0; + for( i = 0; i < band_width[k_sort[k]]; i++ ) + { + inp_vector[band_start[k_sort[k]] + i] = 0; + } + } + + npulses[k_sort[k]] = pulsesnum; + + if( Rk_fx[k_sort[k]] > 0 && surplus_fx < 0 ) + { + IF( nzbands <= 1 ) + { + divider = 0; + } + ELSE + { + divider = 2; + } + + IF( L_add( L_add( surplus_fx, sepbits), ar_div( leftbits, divider ) ) < 0 ) + { + /* Overflow possible => start to distribute negative surplus */ + delta_fx = ar_div( surplus_fx + sepbits, nzbands); + } + else + { + delta_fx = 0; + } + surplus_fx = L_sub(surplus_fx, delta_fx); + } + else + { + delta_fx = 0; + } + } + } + + if (( L_sub(surplus_fx,524288) > 0 && sub(input_frame,L_FRAME8k) == 0 ) || ( L_sub(surplus_fx,786432) > 0 && sub(input_frame,L_FRAME16k) == 0 )) + { + bit_surplus_fx[0] = Mult_32_16(surplus_fx,24576);/* Q16 */ + bit_surplus_fx[1] = Mult_32_16(surplus_fx,8192);/* Q16 */ + } + else + { + bit_surplus_fx[0] = surplus_fx; + bit_surplus_fx[1] = 0; + } + + for( k = 0; k < BANDS; k++ ) + { + for( j = 0; j < 2; j++ ) + { + if( k == k_num[j] ) + { + Rk_fx[k_sort[k]] = L_add(Rk_fx[k_sort[k]],bit_surplus_fx[j]); + if( Rk_fx[k_sort[k]] > 0 && USQ_TCQ[k_sort[k]] == 0 ) + { + /* get number of pulses */ + pulsesnum = GetScale_fx( band_width[k_sort[k]], Rk_fx[k_sort[k]], &surplus_fx ); + + decode_position_ari_fx( pardec, band_width[k_sort[k]], pulsesnum, &nz, &positions[band_start[k_sort[k]]] ); + /* decode tcq magniitude and update the surplus bits. */ + decode_mangitude_tcq_fx( pardec, band_width[k_sort[k]], pulsesnum, nz, &positions[band_start[k_sort[k]]], &inp_vector[band_start[k_sort[k]]], &surplus_fx ); + decode_signs_fx( pardec, band_width[k_sort[k]], &inp_vector[band_start[k_sort[k]]] ); + } + else if( Rk_fx[k_sort[k]] > 0 && USQ_TCQ[k_sort[k]] == 1 ) + { + pulsesnum = GetScale_fx( band_width[k_sort[k]], Rk_fx[k_sort[k]], &surplus_fx ); + + decode_position_ari_fx( pardec, band_width[k_sort[k]], pulsesnum, &nz, &positions[band_start[k_sort[k]]] ); + /* decode usq magnitude and don't need to update surplus bits */ + decode_magnitude_usq_fx( pardec, band_width[k_sort[k]], pulsesnum, nz, &positions[band_start[k_sort[k]]], &inp_vector[band_start[k_sort[k]]] ); + decode_signs_fx( pardec, band_width[k_sort[k]], &inp_vector[band_start[k_sort[k]]] ); + } + else + { + pulsesnum = 0; + for ( i = 0; i < band_width[k_sort[k]]; i++ ) + { + inp_vector[band_start[k_sort[k]] + i] = 0; + } + } + npulses[k_sort[k]] = pulsesnum; + } + } + } + } + else + { + for( k = 0; k < BANDS; k++ ) + { + if( Rk_fx[k_sort[k]] > 0 ) + { + pulsesnum = GetScale_fx(band_width[k_sort[k]], Rk_fx[k_sort[k]] + delta_fx, &surplus_fx); + + decode_position_ari_fx( pardec, band_width[k_sort[k]], pulsesnum, &nz, &positions[band_start[k_sort[k]]] ); + + /*decode usq magnitude and don't need to update surplus bits*/ + decode_magnitude_usq_fx( pardec, band_width[k_sort[k]], pulsesnum, nz, &positions[band_start[k_sort[k]]], &inp_vector[band_start[k_sort[k]]] ); + decode_signs_fx( pardec, band_width[k_sort[k]], &inp_vector[band_start[k_sort[k]]] ); + + nzbands = sub(nzbands, 1); + } + else + { + pulsesnum = 0; + for( i = 0; i < band_width[k_sort[k]]; i++ ) + { + inp_vector[band_start[k_sort[k]] + i] = 0; + } + } + + npulses[k_sort[k]] = pulsesnum; + + /* surplus distribution */ + if ( surplus_fx > 0 && nzbands > 0 ) + { + delta_fx = ar_div(surplus_fx, nzbands); + surplus_fx = L_sub(surplus_fx, delta_fx); + } + } + } + /* Load TCQ path from bitstream */ + LoadTCQdata( pardec, dpath, lsbtcq_bits); + + TCQLSBdec( dpath, mbuffer, 2*lsbtcq_bits ); + + ar_decoder_done( pardec ); + + /* Restore TCQ */ + if( !flag_wbnb ) + { + for( k = 0; k < BANDS; k++) + { + if( Rk_fx[k_sort[k]] > 0 ) + { + RestoreTCQdec( &inp_vector[ band_start[ k_sort[ k]]], band_width[k_sort[k]], &bcount, mbuffer ); + } + } + } + else + { + for( k = 0; k < BANDS; k++) + { + if( Rk_fx[k_sort[k]] > 0 && k != k_num[0] && k != k_num[1] ) + { + RestoreTCQdec( &inp_vector[ band_start[ k_sort[ k]]], band_width[k_sort[k]], &bcount, mbuffer ); + } + } + for( k = 0; k < BANDS; k++) + { + if( Rk_fx[k_sort[k]] > 0 && (k == k_num[0] || k == k_num[1]) ) + { + RestoreTCQdec( &inp_vector[ band_start[ k_sort[ k]]], band_width[k_sort[k]], &bcount, mbuffer ); + } + } + } + + + + return; +} diff --git a/src/libs/libevs/lib_dec/tcq_core_dec_fx.cpp b/src/libs/libevs/lib_dec/tcq_core_dec_fx.cpp deleted file mode 100755 index dc184f86..00000000 --- a/src/libs/libevs/lib_dec/tcq_core_dec_fx.cpp +++ /dev/null @@ -1,475 +0,0 @@ -/*==================================================================================== - EVS Codec 3GPP TS26.442 Apr 03, 2018. Version 12.11.0 / 13.6.0 / 14.2.0 - ====================================================================================*/ - -#include -#include "options.h" /* Compilation switches */ -#include "cnst_fx.h" /* Common constants */ -#include "rom_com_fx.h" /* Static table prototypes */ - -#include "prot_fx.h" -#include "stl.h" /* required for wmc_tool */ - -void tcq_core_LR_dec_fx( - Decoder_State_fx *st_fx, - Word16 *inp_vector_fx, /* x5 */ - const Word16 bit_budget, - const Word16 BANDS, - const Word16 *band_start, - const Word16 *band_width, - Word32 *Rk_fx, /* Q16 */ - Word16 *npulses, - Word16 *k_sort, - const Word16 *p2a_flags, - const Word16 p2a_bands, - const Word16 *last_bitalloc, - const Word16 input_frame, - const Word16 adjustFlag, - const Word16 *is_transient -) -{ - Word16 i, j, k; - Word32 Rk_sort_fx[NB_SFM]; - Word16 flag_wbnb = 0; - Word16 USQ_TCQ[NB_SFM]; /* TCQ is selected by default*/ - Word16 nb_bytes, pulsesnum, nz; - - Word16 positions_fx[L_FRAME48k]; - Word32 surplus_fx, delta_fx; - Word16 k_num[2]; - Word32 bit_surplus_fx[2]; - ARCODEC_FX ardec_fx, *pardec_fx; - BITSTREAM_FX bs_fx, *pbs_fx; - - Word16 nzb = 0; - Word16 nzbands = 0; - Word16 lsbtcq_bits = TCQ_AMP; - Word16 tcq_arbits = 2; - - /* LSB TCQ variables*/ - Word16 dpath[280]; - Word16 bcount = 0; - Word32 bsub_fx = 0; - Word16 mbuffer_fx[560]; - - Word32 leftbits = 0; - Word32 sepbits = 0; - Word32 divider = 0; - - if (Overflow == 1) - { - Overflow = 0; /* set overflow flag to zero before entering TCQ finctions without any message */ - } - - /* initialization */ - set16_fx(dpath, 0, 280); - set16_fx( USQ_TCQ, 0, NB_SFM ); - set16_fx(positions_fx, 0, L_FRAME32k); - set16_fx(mbuffer_fx, 0, 560); - - test(); - test(); - IF ( sub(input_frame, L_FRAME16k) <= 0 && adjustFlag == 0 && *is_transient == 0 ) - { - flag_wbnb = 1; - move16(); - lsbtcq_bits = 0; - move16(); - tcq_arbits = 0; - move16(); - } - - pardec_fx = &ardec_fx; - pbs_fx = &bs_fx; - pbs_fx->curPos = 7; - move16(); - pbs_fx->numbits = L_deposit_l(0); - pbs_fx->numByte = L_deposit_l(0); - - /* Bits distribution analysis*/ - FOR ( i = 0; i < BANDS; i++ ) - { - IF (L_sub(ar_div(Rk_fx[i], band_width[i]), 49152) >= 0) - { - /* USQ used for high importance bands*/ - USQ_TCQ[i] = 1; - move16(); - } - ELSE - { - /* TCQ used for usual bands*/ - USQ_TCQ[i] = 0; - move16(); - } - if ( Rk_fx[i] > 0 ) - { - nzbands = add(nzbands, 1); - } - } - - FOR ( j = 0; j < BANDS; j++ ) - { - if ( Rk_fx[j] > 0 ) - { - nzb = add(nzb, 1); - } - } - - bsub_fx = L_shl(L_add(tcq_arbits, lsbtcq_bits), 16); - if( bsub_fx > 0) - { - bsub_fx = L_add( bsub_fx, 2048); - } - FOR ( j = BANDS - 1; j >= 0; j-- ) - { - IF ( Rk_fx[j] > 0 ) - { - Rk_fx[j] = L_sub(Rk_fx[j], ar_div(bsub_fx, nzb)); - IF ( Rk_fx[j] < 0) - { - bsub_fx = L_sub(bsub_fx, L_add(ar_div(bsub_fx, nzb), Rk_fx[j])); - Rk_fx[j] = L_deposit_l(0); - } - ELSE - { - bsub_fx = L_sub(bsub_fx, ar_div(bsub_fx, nzb)); - } - nzb = sub(nzb, 1); - } - } - - srt_vec_ind_fx(Rk_fx, Rk_sort_fx, k_sort, BANDS); - - /*read the bits*/ - nb_bytes = shr(bit_budget, 3); - k = sub(bit_budget, shl(nb_bytes, 3)); - FOR ( i = 0; i < nb_bytes; i++ ) - { - pbs_fx->buf[i] = (UWord8)get_next_indice_fx(st_fx, 8); - move16(); - } - - IF ( k > 0 ) - { - Word16 tmp; - tmp = (UWord8)get_next_indice_fx(st_fx, k); - pbs_fx->buf[nb_bytes] = (UWord8)shl(tmp,sub(8,k)); - /* i++; - nb_bytes++; */ - i = add(i, 1); - nb_bytes = add(nb_bytes, 1); - } - /* set two more bytes, which are used to flush the arithmetic coder, to 0 - -> this avoids reading of uninitialized memory */ - nb_bytes = s_min(add(nb_bytes, 2), MAX_SIZEBUF_PBITSTREAM); - FOR ( ; i < nb_bytes; i++ ) - { - pbs_fx->buf[i] = 0; - move16(); - } - - pbs_fx->maxBytes = nb_bytes; - move16(); - - ar_decoder_start_fx(pardec_fx, pbs_fx); - - delta_fx = L_deposit_l(0); - surplus_fx = L_deposit_l(0); - - test(); - test(); - IF( sub(input_frame, L_FRAME16k) <= 0 && adjustFlag == 0 && *is_transient == 0 ) - { - surplus_fx = -131072; - move32();/*16 */ - - bit_allocation_second_fx(Rk_fx, Rk_sort_fx, BANDS, band_width, k_sort, k_num, p2a_flags, p2a_bands, last_bitalloc, input_frame); - - nzbands = 0; - move16(); - FOR ( j = 0; j < BANDS; j++ ) - { - IF( sub(j, k_num[0]) == 0 || sub(j, k_num[1]) == 0) - { - sepbits = L_add( sepbits, Rk_fx[k_sort[j]]); - } - ELSE - { - leftbits = L_add( leftbits, Rk_fx[k_sort[j]]); - if( Rk_fx[k_sort[j]] > 0 ) - { - nzbands = add(nzbands, 1); - } - } - } - - FOR( k = 0; k < BANDS; k++ ) - { - test(); - IF( sub(k, k_num[0]) != 0 && sub(k, k_num[1]) != 0) - { - test(); - test(); - IF (Rk_fx[k_sort[k]] > 0 && USQ_TCQ[k_sort[k]] == 0) - { - /* When number of bits per band is less than - arithmetic bits overhead, this band is not encoded. - It may happens when the actual number of bits per - band is near same to estimated number of bits, for - most bands (very unprobable but possible) */ - IF( L_add( Rk_fx[k_sort[k]], delta_fx) < 0 ) - { - pulsesnum = 0; - move16(); - FOR( i = 0; i < band_width[k_sort[k]]; i++ ) - { - inp_vector_fx[band_start[k_sort[k]] + i] = 0; - move16(); - } - IF( surplus_fx != 0 ) - { - /* surplus_fx += (Rk[k_sort[k]] + delta);*/ - surplus_fx = L_add( Rk_fx[k_sort[k]], surplus_fx); - surplus_fx = L_add( delta_fx, surplus_fx); - } - } - ELSE - { - /*get number of pulses */ - pulsesnum = GetScale_fx( band_width[k_sort[k]], - L_add( Rk_fx[k_sort[k]], delta_fx), - &surplus_fx ); - leftbits = L_sub( leftbits, L_add( Rk_fx[k_sort[k]], delta_fx) ); - decode_position_ari_fx( pardec_fx, band_width[k_sort[k]], pulsesnum, &nz, &positions_fx[band_start[k_sort[k]]] ); - /*decode tcq magniitude and update the surplus bits.*/ - decode_mangitude_tcq_fx( pardec_fx, band_width[k_sort[k]], pulsesnum, nz, &positions_fx[band_start[k_sort[k]]], &inp_vector_fx[band_start[k_sort[k]]], &surplus_fx ); - decode_signs_fx( pardec_fx, band_width[k_sort[k]], &inp_vector_fx[band_start[k_sort[k]]] ); - } - nzbands--; - move16(); - } - ELSE IF (Rk_fx[k_sort[k]] > 0 && sub(USQ_TCQ[k_sort[k]], 1) == 0) - { - /* When number of bits per band is less than - arithmetic bits overhead, this band is not encoded. - It may happens when the actual number of bits per - band is near same to estimated number of bits, for - most bands (very unprobable but possible) */ - IF( L_add( Rk_fx[k_sort[k]], delta_fx) < 0 ) - { - pulsesnum = 0; - move16(); - FOR( i = 0; i < band_width[k_sort[k]]; i++ ) - { - inp_vector_fx[band_start[k_sort[k]] + i] = 0; - move16(); - } - IF( surplus_fx != 0 ) - { - surplus_fx = L_add( Rk_fx[k_sort[k]], surplus_fx); - surplus_fx = L_add( delta_fx, surplus_fx); - } - } - ELSE - { - pulsesnum = GetScale_fx(band_width[k_sort[k]], - L_add( Rk_fx[k_sort[k]], delta_fx), - &surplus_fx); - leftbits = L_sub( leftbits, L_add( Rk_fx[k_sort[k]], delta_fx) ); - decode_position_ari_fx( pardec_fx, band_width[k_sort[k]], pulsesnum, &nz, &positions_fx[band_start[k_sort[k]]] ); - /*decode usq magnitude and don't need to update surplus bits*/ - decode_magnitude_usq_fx( pardec_fx, band_width[k_sort[k]], pulsesnum, nz, &positions_fx[band_start[k_sort[k]]], &inp_vector_fx[band_start[k_sort[k]]] ); - decode_signs_fx( pardec_fx, band_width[k_sort[k]], &inp_vector_fx[band_start[k_sort[k]]] ); - } - nzbands--; - move16(); - } - ELSE - { - pulsesnum = 0; - move16(); - FOR ( i = 0; i < band_width[k_sort[k]]; i++ ) - { - inp_vector_fx[band_start[k_sort[k]] + i] = 0; - move16(); - } - } - - npulses[k_sort[k]] = pulsesnum; - move16(); - - delta_fx = L_deposit_l(0); - test(); - IF( Rk_fx[k_sort[k]] > 0 && surplus_fx < 0 ) - { - IF( nzbands <= 1 ) - { - divider = 0; - } - ELSE - { - divider = 2; - } - - IF( L_add( L_add( surplus_fx, sepbits), ar_div( leftbits, divider ) ) < 0 ) - { - /* Overflow possible => start to distribute negative surplus */ - delta_fx = ar_div( surplus_fx + sepbits, nzbands); - } - else - { - delta_fx = 0; - } - surplus_fx = L_sub(surplus_fx, delta_fx); - - } - } - } - - test(); - test(); - test(); - IF (( L_sub(surplus_fx,524288) > 0 && sub(input_frame,L_FRAME8k) == 0 ) || ( L_sub(surplus_fx,786432) > 0 && sub(input_frame,L_FRAME16k) == 0 )) - { - bit_surplus_fx[0] = Mult_32_16(surplus_fx,24576);/* Q16 */ - bit_surplus_fx[1] = Mult_32_16(surplus_fx,8192);/* Q16 */ - } - ELSE - { - bit_surplus_fx[0] = surplus_fx; - move32(); - bit_surplus_fx[1] = L_deposit_l(0); - } - - FOR ( k = 0; k < BANDS; k++ ) - { - FOR ( j = 0; j < 2; j++ ) - { - IF ( sub(k, k_num[j]) == 0 ) - { - Rk_fx[k_sort[k]] = L_add(Rk_fx[k_sort[k]],bit_surplus_fx[j]); - move32(); - - test(); - test(); - IF ( Rk_fx[k_sort[k]] > 0 && USQ_TCQ[k_sort[k]] == 0 ) - { - /* get number of pulses */ - pulsesnum = GetScale_fx( band_width[k_sort[k]], Rk_fx[k_sort[k]], &surplus_fx ); - - decode_position_ari_fx( pardec_fx, band_width[k_sort[k]], pulsesnum, &nz, &positions_fx[band_start[k_sort[k]]] ); - /* decode tcq magniitude and update the surplus bits. */ - decode_mangitude_tcq_fx( pardec_fx, band_width[k_sort[k]], pulsesnum, nz, &positions_fx[band_start[k_sort[k]]], &inp_vector_fx[band_start[k_sort[k]]], &surplus_fx ); - decode_signs_fx( pardec_fx, band_width[k_sort[k]], &inp_vector_fx[band_start[k_sort[k]]] ); - } - ELSE IF( Rk_fx[k_sort[k]] > 0 && USQ_TCQ[k_sort[k]] == 1 ) - { - pulsesnum = GetScale_fx( band_width[k_sort[k]], Rk_fx[k_sort[k]], &surplus_fx ); - - decode_position_ari_fx( pardec_fx, band_width[k_sort[k]], pulsesnum, &nz, &positions_fx[band_start[k_sort[k]]] ); - /* decode usq magnitude and don't need to update surplus bits */ - decode_magnitude_usq_fx( pardec_fx, band_width[k_sort[k]], pulsesnum, nz, &positions_fx[band_start[k_sort[k]]], &inp_vector_fx[band_start[k_sort[k]]] ); - decode_signs_fx( pardec_fx, band_width[k_sort[k]], &inp_vector_fx[band_start[k_sort[k]]] ); - } - ELSE - { - pulsesnum = 0; - move16(); - FOR ( i = 0; i < band_width[k_sort[k]]; i++ ) - { - inp_vector_fx[band_start[k_sort[k]] + i] = 0; - move16(); - } - } - - npulses[k_sort[k]] = pulsesnum; - move16(); - } - } - } - } - ELSE - { - FOR ( k = 0; k < BANDS; k++ ) - { - IF ( Rk_fx[k_sort[k]] > 0 ) - { - pulsesnum = GetScale_fx(band_width[k_sort[k]], Rk_fx[k_sort[k]] + delta_fx, &surplus_fx); - - decode_position_ari_fx( pardec_fx, band_width[k_sort[k]], pulsesnum, &nz, &positions_fx[band_start[k_sort[k]]] ); - - /*decode usq magnitude and don't need to update surplus bits*/ - decode_magnitude_usq_fx( pardec_fx, band_width[k_sort[k]], pulsesnum, nz, &positions_fx[band_start[k_sort[k]]], &inp_vector_fx[band_start[k_sort[k]]] ); - decode_signs_fx( pardec_fx, band_width[k_sort[k]], &inp_vector_fx[band_start[k_sort[k]]] ); - - nzbands = sub(nzbands, 1); - } - ELSE - { - pulsesnum = 0; - move16(); - FOR ( i = 0; i < band_width[k_sort[k]]; i++ ) - { - inp_vector_fx[band_start[k_sort[k]] + i] = 0; - move16(); - } - } - - npulses[k_sort[k]] = pulsesnum; - move16(); - - /* surplus distribution */ - test(); - IF ( surplus_fx > 0 && nzbands > 0 ) - { - delta_fx = ar_div(surplus_fx, nzbands); - surplus_fx = L_sub(surplus_fx, delta_fx); - } - } - } - - /* Load TCQ path from bitstream */ - LoadTCQdata_fx(pardec_fx, dpath, lsbtcq_bits); - - TCQLSBdec_fx(dpath, mbuffer_fx, 2*lsbtcq_bits); - - ar_decoder_done_fx(pardec_fx); - - /* Restore TCQ */ - IF ( !flag_wbnb ) - { - FOR ( k = 0; k < BANDS; k++) - { - IF ( Rk_fx[k_sort[k]] > 0 ) - { - RestoreTCQdec_fx( &inp_vector_fx[ band_start[ k_sort[ k]]], band_width[k_sort[k]], &bcount, mbuffer_fx ); - } - } - } - ELSE - { - FOR( k = 0; k < BANDS; k++) - { - test(); - test(); - IF( Rk_fx[k_sort[k]] > 0 && k != k_num[0] && k != k_num[1] ) - { - RestoreTCQdec_fx( &inp_vector_fx[ band_start[ k_sort[ k]]], band_width[k_sort[k]], &bcount, mbuffer_fx ); - } - } - - FOR ( k = 0; k < BANDS; k++) - { - test(); - test(); - IF ( Rk_fx[k_sort[k]] > 0 && (k == k_num[0] || k == k_num[1]) ) - { - RestoreTCQdec_fx( &inp_vector_fx[ band_start[ k_sort[ k]]], band_width[k_sort[k]], &bcount, mbuffer_fx ); - } - } - } - - - - return; -} diff --git a/src/libs/libevs/lib_dec/tcx_utils_dec.cpp b/src/libs/libevs/lib_dec/tcx_utils_dec.cpp old mode 100755 new mode 100644 index 96a1c3fa..08e632a4 --- a/src/libs/libevs/lib_dec/tcx_utils_dec.cpp +++ b/src/libs/libevs/lib_dec/tcx_utils_dec.cpp @@ -1,340 +1,247 @@ /*==================================================================================== - EVS Codec 3GPP TS26.442 Apr 03, 2018. Version 12.11.0 / 13.6.0 / 14.2.0 + EVS Codec 3GPP TS26.443 Nov 13, 2018. Version 12.11.0 / 13.7.0 / 14.3.0 / 15.1.0 ====================================================================================*/ - +#include "cnst.h" #include #include +#include #include -#include "stl.h" #include "options.h" -#include "prot_fx.h" -#include "rom_basop_util.h" -#include "basop_util.h" -#include "rom_com_fx.h" +#include "prot.h" +#include "rom_com.h" + + void tcx_decoder_memory_update( - Word16 *xn_buf, /* i/o: mdct output buffer used also as temporary buffer */ - Word16 *synthout, /* o: synth */ - Word16 L_frame_glob, /* i: global frame length */ - Word16 *A, /* i: Quantized LPC coefficients */ - Decoder_State_fx *st, - Word16 *syn, /* o: st->syn */ - Word8 fb /* i: fullband flag */ + float *xn_buf, /* i/o: mdct output buffer used also as temporary buffer */ + float *synthout, /* o: synth */ + int L_frame_glob, /* i: global frame length */ + float *A, /* i: Quantized LPC coefficients */ + Decoder_State *st, /* i/o : decoder memory state */ + float *syn /* o: st->syn */ ) { - Word16 tmp; - Word16 *synth; - Word16 buf[1+M+LFAC+L_FRAME_PLUS]; - Word16 preemph; + float tmp; + float *synth; + float buf[1+M+L_FRAME_PLUS]; + float preemph_f = st->preemph_fac; - - preemph = st->preemph_fac; - move16(); + /*TCX must be aligned with ACELP*/ + assert(st->tcx_cfg.lfacNext<=0); /* Output synth */ - Copy(xn_buf, synthout, L_frame_glob); + mvr2r(xn_buf, synthout, L_frame_glob); /* Update synth */ + synth = buf + 1 + M; + mvr2r(syn, buf, 1+M); + mvr2r(xn_buf, synth, L_frame_glob); + mvr2r(synth+L_frame_glob-M-1, syn, 1+M); - synth = buf + M+1; - Copy(syn, buf, M+1); - Copy(xn_buf, synth, L_frame_glob); - Copy(synth + sub(L_frame_glob, M+1), syn, M+1); + /* Emphasis of synth -> synth_pe */ + tmp = synth[-M-1]; + preemph(synth-M, preemph_f, M+L_frame_glob, &tmp); + mvr2r(synth+L_frame_glob-M, st->mem_syn2, M); + mvr2r( synth+L_frame_glob-L_SYN_MEM, st->mem_syn_r, L_SYN_MEM); - IF (!fb) + if ( !st->tcxonly || L_frame_glob == L_FRAME16k) { - - /* Emphasis of synth -> synth_pe */ - tmp = synth[-M-1]; - move16(); - st->Q_syn = E_UTIL_f_preemph3(synth - M, preemph, add(M, L_frame_glob), &tmp, 1); - st->prev_Q_syn = st->Q_syn = st->Q_syn - 1; - Copy(synth + sub(L_frame_glob, M), st->mem_syn2_fx, M); - Copy(synth + sub(L_frame_glob, L_SYN_MEM), st->mem_syn_r, L_SYN_MEM); - - test(); - IF ( st->tcxonly == 0 || sub(L_frame_glob,L_FRAME16k)<=0) - { - /* Update excitation */ - IF(sub(st->Q_syn+1,st->Q_exc) != 0) - { - Scale_sig(st->old_exc_fx, L_EXC_MEM_DEC, sub(st->Q_syn+1,st->Q_exc)); - } - st->Q_exc = st->Q_syn + 1; - st->Q_subfr[0] = st->Q_subfr[1] = st->Q_subfr[2] = st->Q_subfr[3] = st->Q_subfr[4] = st->Q_exc; - - assert(L_frame_glob< L_EXC_MEM_DEC); - Copy( st->old_exc_fx + L_frame_glob, st->old_exc_fx, sub(L_EXC_MEM_DEC, L_frame_glob) ); - Residu3_fx(A, synth, st->old_exc_fx + sub(L_EXC_MEM_DEC, L_frame_glob), L_frame_glob, 1); - } - - /* Update old_Aq */ - Copy(A, st->old_Aq_12_8_fx, M+1); + /* Update excitation */ + assert(L_frame_glob < L_EXC_MEM_DEC); + mvr2r(st->old_exc+(L_frame_glob), st->old_exc, L_EXC_MEM_DEC-(L_frame_glob) ); + residu(A, M, synth, st->old_exc+L_EXC_MEM_DEC-(L_frame_glob), (L_frame_glob)); } + /* Update old_Aq */ + mvr2r(A, st->old_Aq_12_8, M+1); } +/*--------------------------------------------------------------- + * Residual Quantization + *--------------------------------------------------------------*/ + /* Returns: number of bits used (including "bits") */ -Word16 tcx_ari_res_invQ_spec( - Word32 x_Q[], /* i/o: quantized spectrum Q31-e */ - Word16 x_Q_e, /* i: quantized spectrum exponent Q0 */ - Word16 L_frame, /* i: number of lines Q0 */ - const Word16 prm[], /* i: bit-stream Q0 */ - Word16 target_bits, /* i: number of bits available Q0 */ - Word16 bits, /* i: number of bits used so far Q0 */ - Word16 deadzone, /* i: quantizer deadzone Q15 */ - const Word16 x_fac[] /* i: spectrum post-quantization factors Q14 */ +int tcx_ari_res_invQ_spec( + float x_Q[], /* i/o: quantized spectrum */ + int L_frame, /* i: number of lines */ + const int prm[], /* i: bit-stream */ + int target_bits, /* i: number of bits available */ + int bits, /* i: number of bits used so far */ + float deadzone, /* i: quantizer deadzone */ + const float x_fac[] /* i: spectrum post-quantization factors */ ) { - Word16 i, j, num_zeros; - Word16 zeros[L_FRAME_PLUS]; - Word16 fac_p, sign; - Word32 L_tmp; - Word16 s; + int i, j, num_zeros; + int zeros[L_FRAME_PLUS]; + float fac_m, fac_p, sign; /* Limit the number of residual bits */ - target_bits = s_min(target_bits, NPRM_RESQ); + target_bits = min(target_bits, NPRM_RESQ); /* Requantize the spectrum line-by-line */ - /* fac_m = deadzone * 0.5f; */ + fac_m = deadzone * 0.5f; num_zeros = 0; - move16(); - - FOR (i=0; i < L_frame; i++) + for (i=0; i= 0) /* no bits left */ + if (bits >= target_bits) { - BREAK; + /* no bits left */ + break; } - - IF (x_Q[i] != 0) + if (x_Q[i] != 0) { - sign = x_fac[i]; - move16(); - if (x_Q[i] < 0) sign = negate(sign); + if (x_Q[i] > 0) + { + sign = x_fac[i]; + } + else + { + sign = -x_fac[i]; + } - /* x_Q[i] += sign*(prm[bits++] * 0.5f - fac_m); */ - x_Q[i] = L_sub(x_Q[i], L_shr(L_mult(sign, add(deadzone, lshl(prm[bits], 15))), x_Q_e)); - move32(); - bits = add(bits, 1); + x_Q[i] += sign*(prm[bits++] * 0.5f - fac_m); } - ELSE + else { - zeros[num_zeros] = i; - move16(); - num_zeros = add(num_zeros, 1); + zeros[num_zeros++] = i; } } /* Requantize zeroed-lines of the spectrum */ - fac_p = msu_r(1417339264l/*0.33f*2.0f Q31*/, deadzone, 21627/*0.33f*2.0f Q15*/); /* Q15 */ - target_bits = sub(target_bits, 1); /* reserve 1 bit for the check below */ - - s = sub(x_Q_e, 1); - FOR (j = 0; j < num_zeros; j++) + fac_p = (1.0f - deadzone)*0.33f*2.0f; + --target_bits; /* reserve 1 bit for the check below */ + for (j=0; j= 0) /* 1 or 0 bits left */ + if (bits >= target_bits) { - BREAK; + /* 1 or 0 bits left */ + break; } i = zeros[j]; - move16(); - IF (prm[bits] != 0) + if (prm[bits++] != 0) { - bits = add(bits, 1); - L_tmp = L_mult(fac_p, x_fac[i]); /* Q30 */ - if (prm[bits] == 0) L_tmp = L_negate(L_tmp); - x_Q[i] = L_shr(L_tmp, s); - move32(); + x_Q[i] = (2*prm[bits++]-1) * fac_p * x_fac[i]; } - bits = add(bits, 1); } return bits; } -Word16 tcx_res_invQ_gain( - Word16 *gain_tcx, - Word16 *gain_tcx_e, - Word16 *prm, - Word16 resQBits +int tcx_res_invQ_gain( + float *gain_tcx, + const int *prm, + int resQBits ) { - Word16 bits; - Word16 gain, tmp1, tmp2; + int bits; - gain = *gain_tcx; - move16(); - - /* make sure we have a bit of headroom */ - IF (sub(gain, 0x7000) > 0) - { - gain = shr(gain, 1); - *gain_tcx_e = add(*gain_tcx_e, 1); - move16(); - } - /*Refine the gain quantization*/ - tmp1 = s_min(resQBits, TCX_RES_Q_BITS_GAIN); - FOR (bits=0; bits < tmp1; bits++) + for(bits=0; bits= 0) + for (i = 0; (i < L_frame) && (bits < resQBits); i++) { - BREAK; + /* bits < resQBits */ + if (x[i] != 0.0f) + { + if (prm[bits++] == 0) + { + x[i] -= (x[i] > 0.0f) ? fac_m : fac_p; + } + else + { + x[i] += (x[i] > 0.0f) ? fac_p : fac_m; + } + } + } + resQBits--; /* Quantize zeroed lines of the spectrum */ + for (i = 0; (i < L_frame) && (bits < resQBits); i++) + { + if (x[i] == 0.0f) + { + if (prm[bits++] != 0) + { + x[i] = (prm[bits++] * 2.64f - 1.32f) * fac_p; + } + } } - test(); - test(); - IF ((x[i] != 0) && ((lf_deemph_factors == NULL) || (sub(lf_deemph_factors[i], 0x2000) > 0))) + return bits; + } + for(i=0; i=resQBits) { - if (lf_deemph_factors != NULL) + break; + } + if(x[i]!=0.f && lf_deemph_factors[i] > 0.5f) + { + if(prm[bits++]==0) { - lf_deemph_factor = lf_deemph_factors[i]; - move16(); + x[i]-=(x[i]>0)?fac_m*lf_deemph_factors[i]:fac_p*lf_deemph_factors[i]; } - - IF (prm[bits] == 0) + else { - - /* Debug initialization to catch illegal cases of x[i] */ - tmp = 0; - - if (x[i] > 0) tmp = L_mult(fac_m, lf_deemph_factor); - if (x[i] < 0) tmp = L_mult(fac_p, lf_deemph_factor); - - assert(tmp != 0); - - x[i] = L_sub(x[i], L_shr(tmp, s)); - move32(); + x[i]+=(x[i]>0)?fac_p*lf_deemph_factors[i]:fac_m*lf_deemph_factors[i]; } - ELSE - { - - /* Debug initialization to catch illegal cases of x[i] */ - tmp = 0; - - if (x[i] > 0) tmp = L_mult(fac_p, lf_deemph_factor); - if (x[i] < 0) tmp = L_mult(fac_m, lf_deemph_factor); - - assert(tmp != 0); - - x[i] = L_add(x[i], L_shr(tmp, s)); - move32(); - } - bits = add(bits, 1); } } /*Quantize zeroed-line of the spectrum*/ - resQBits = sub(resQBits, 1); - - IF (lf_deemph_factors == NULL) + for(i=0; i=(resQBits-1)) /*need at least two bits*/ { - IF (sub(bits, resQBits) >= 0) - { - BREAK; - } - - IF (x[i] == 0) - { - IF (prm[bits] != 0) - { - bits = add(bits, 1); - - tmp = L_mult(21627/*1.32f Q14*/, fac_p); - if (prm[bits] == 0) tmp = L_negate(tmp); - - x[i] = L_shr(tmp, s); - move32(); - } - bits = add(bits, 1); - } + break; } - } - ELSE - { - c = sub(21627/*0.66f Q15*/, mult_r(sq_round, 21627/*0.66f Q15*/)); - - FOR (i = 0; i < L_frame; i++) + if(x[i]==0.f && lf_deemph_factors[i] > 0.5f) { - IF (sub(bits, resQBits) >= 0) + if(prm[bits++]==1) { - BREAK; - } - - test(); - IF ((x[i] == 0) && (sub(lf_deemph_factors[i], 0x2000) > 0)) - { - IF (prm[bits] != 0) - { - bits = add(bits, 1); - - tmp = L_mult(c, lf_deemph_factors[i]); - if (prm[bits] == 0) tmp = L_negate(tmp); - - x[i] = L_shr(tmp, s); - move32(); - } - bits = add(bits, 1); + thres=(1-sq_round)*0.66f*lf_deemph_factors[i]; + x[i]=(prm[bits++]*2.f-1.f)*thres; } } } diff --git a/src/libs/libevs/lib_dec/tns_base_dec.cpp b/src/libs/libevs/lib_dec/tns_base_dec.cpp old mode 100755 new mode 100644 index 04c5e1d2..01d4a75b --- a/src/libs/libevs/lib_dec/tns_base_dec.cpp +++ b/src/libs/libevs/lib_dec/tns_base_dec.cpp @@ -1,14 +1,15 @@ /*==================================================================================== - EVS Codec 3GPP TS26.442 Apr 03, 2018. Version 12.11.0 / 13.6.0 / 14.2.0 + EVS Codec 3GPP TS26.443 Nov 13, 2018. Version 12.11.0 / 13.7.0 / 14.3.0 / 15.1.0 ====================================================================================*/ - -#include "stl.h" -#include "prot_fx.h" -#include "stl.h" +#include "cnst.h" +#include "rom_com.h" +#include "prot.h" #include +#include #include -#include "rom_com_fx.h" + + /** Linear prediction analysis/synthesis filter definition. * @param order filter order. @@ -17,78 +18,54 @@ * @param x the current input value. * @return the output of the filter. */ -typedef Word32 (* TLinearPredictionFilter)(Word16 order, Word16 const parCoeff[], Word32 * state, Word32 x); +typedef float (* TLinearPredictionFilter)(int order, float const parCoeff[], float * state, float x); /********************************/ /* Interface functions */ /********************************/ -Word16 ReadTnsData(STnsConfig const * pTnsConfig, Decoder_State_fx *st, Word16 * pnBits, Word16 * stream, Word16 * pnSize) +TNS_ERROR ReadTnsData(STnsConfig const * pTnsConfig, Decoder_State * st, int * pnBits, int * stream, int * pnSize) { - Word16 start_bit_pos; - - - move16(); - start_bit_pos = st->next_bit_pos_fx; - - IF ( sub(pTnsConfig->nMaxFilters, 1) > 0 ) + int start_bit_pos; + start_bit_pos = st->next_bit_pos; + if (pTnsConfig->nMaxFilters > 1) { - - IF ( sub(pTnsConfig->iFilterBorders[0],512) < 0) + if (pTnsConfig->iFilterBorders[0] < 512) { - ReadFromBitstream(tnsEnabledSWBTCX10BitMap, 1, st, &stream, pnSize); + ReadFromBitstream(&tnsEnabledSWBTCX10BitMap, 1, st, &stream, pnSize); } - ELSE + else { - ReadFromBitstream(tnsEnabledSWBTCX20BitMap, 1, st, &stream, pnSize); + ReadFromBitstream(&tnsEnabledSWBTCX20BitMap, 1, st, &stream, pnSize); } } - ELSE + else { - ReadFromBitstream(tnsEnabledWBTCX20BitMap, 1, st, &stream, pnSize); + ReadFromBitstream(&tnsEnabledWBTCX20BitMap, 1, st, &stream, pnSize); } - move16(); - *pnBits = sub(st->next_bit_pos_fx, start_bit_pos); - - + *pnBits = st->next_bit_pos - start_bit_pos; return TNS_NO_ERROR; } -Word16 DecodeTnsData(STnsConfig const * pTnsConfig, Word16 const * stream, Word16 * pnSize, STnsData * pTnsData) +int DecodeTnsData(STnsConfig const * pTnsConfig, int const * stream, int * pnSize, STnsData * pTnsData) { - Word16 result; - - - ResetTnsData(pTnsData); - - IF ( sub(pTnsConfig->nMaxFilters, 1) > 0 ) + if (pTnsConfig->nMaxFilters > 1) { - - IF ( sub(pTnsConfig->iFilterBorders[0],512) < 0 ) + if (pTnsConfig->iFilterBorders[0] < 512) { - SetParameters(tnsEnabledSWBTCX10BitMap, 1, pTnsData, &stream, pnSize); + SetParameters(&tnsEnabledSWBTCX10BitMap, 1, pTnsData, &stream, pnSize); } - ELSE + else { - SetParameters(tnsEnabledSWBTCX20BitMap, 1, pTnsData, &stream, pnSize); + SetParameters(&tnsEnabledSWBTCX20BitMap, 1, pTnsData, &stream, pnSize); } } - ELSE + else { - SetParameters(tnsEnabledWBTCX20BitMap, 1, pTnsData, &stream, pnSize); + SetParameters(&tnsEnabledWBTCX20BitMap, 1, pTnsData, &stream, pnSize); } - - move16(); - result = FALSE; - if (pTnsData->nFilters > 0) - { - move16(); - result = TRUE; - } - - - return result; + return (pTnsData->nFilters > 0) ? TRUE : FALSE; } diff --git a/src/libs/libevs/lib_dec/tonalMDCTconcealment.cpp b/src/libs/libevs/lib_dec/tonalMDCTconcealment.cpp old mode 100755 new mode 100644 index e33d4b19..b2c773e9 --- a/src/libs/libevs/lib_dec/tonalMDCTconcealment.cpp +++ b/src/libs/libevs/lib_dec/tonalMDCTconcealment.cpp @@ -1,17 +1,16 @@ /*==================================================================================== - EVS Codec 3GPP TS26.442 Apr 03, 2018. Version 12.11.0 / 13.6.0 / 14.2.0 + EVS Codec 3GPP TS26.443 Nov 13, 2018. Version 12.11.0 / 13.7.0 / 14.3.0 / 15.1.0 ====================================================================================*/ #define _USE_MATH_DEFINES #include -#include "stl.h" -#include "basop_util.h" +#include +#include #include "options.h" -#include "typedef.h" -#include "cnst_fx.h" -#include "prot_fx.h" -#include "stat_com.h" +#include "prot.h" + + /************************************************************************************/ @@ -19,50 +18,40 @@ /************************************************************************************/ static void CalcMDXT(TonalMDCTConcealPtr const self, - Word16 const type, - Word16 const * const timeSignal, - Word32 * const mdxtOutput, - Word16 * const mdxtOutput_e); + char const type, + float const * const timeSignal, + float * const mdxtOutput); -static void CalcPowerSpec(Word32 * mdctSpec, /* i: MDCT spectrum */ - Word16 mdctSpec_exp, /* i: exponent of MDCT spectrum */ - Word32 * mdstSpec, /* i: MDST spectrum */ - Word16 mdstSpec_exp, /* i: exponent of MDST spectrum */ - Word16 nSamples, /* i: frame size */ - Word16 floorPowerSpectrum, /* i: lower limit for power spectrum bins */ - Word32 * powerSpec, /* o: power spectrum */ - Word16 * powerSpec_exp); +static void CalcPowerSpec(float const * mdctSpec, + float const * mdstSpec, + unsigned int nSamples, + float floorPowerSpectrum, + float * powerSpec); static void CalcPowerSpecAndDetectTonalComponents(TonalMDCTConcealPtr const self, - Word32 secondLastMDST[], - Word16 secondLastMDST_exp, - Word32 secondLastMDCT[], - Word16 secondLastMDCT_exp, - Word32 const pitchLag); -static void FindPhases( /* o: current phase [-pi;pi] 2Q13 */ - TonalMDCTConcealPtr const self, /* i: pointer to internal structure */ - Word32 secondLastMDCT[], /* i: MDST spectrum data */ - Word32 secondLastMDST[], /* i: MDCT spectrum data */ - Word16 diff_exp); /* i: exp_MDST - exp_MDCT */ + float secondLastMDST[], + float secondLastMDCT[], + float const pitchLag); -static void FindPhaseDifferences( /* o: Phase difference [-pi;pi] 2Q13*/ - TonalMDCTConcealPtr const self, /* i: Pointer to internal structure */ - Word32 powerSpectrum[]); /* i: Power spectrum data */ +static void FindPhases(TonalMDCTConcealPtr const self, + float const secondLastMDCT[], + float const secondLastMDST[]); +static void FindPhaseDifferences(TonalMDCTConcealPtr const self, + float powerSpectrum[]); /*******************************************************/ /*-------------- public functions -------------------- */ /*******************************************************/ TONALMDCTCONCEAL_ERROR TonalMDCTConceal_Init( TonalMDCTConcealPtr self, - Word16 nSamples, - Word16 nSamplesCore, - Word16 nScaleFactors, + unsigned int nSamples, + unsigned int nSamplesCore, + unsigned int nScaleFactors, TCX_config * tcx_cfg ) { - test(); - IF (sub(nSamples,L_FRAME_MAX) > 0 || sub(nScaleFactors,FDNS_NPTS) > 0) + if (nSamples > L_FRAME_MAX || nScaleFactors > FDNS_NPTS) { assert(nSamples <= L_FRAME_MAX); assert(nScaleFactors <= FDNS_NPTS); @@ -71,423 +60,228 @@ TONALMDCTCONCEAL_ERROR TonalMDCTConceal_Init( TonalMDCTConcealPtr self, assert((self->nScaleFactors == nScaleFactors) || (self->nSamples != nSamples)); /* If nSamples doesn't change then also nScaleFactors must stay the same */ self->tcx_cfg = tcx_cfg; - self->lastBlockData.spectralData = self->spectralDataBuffers[0]; - move16(); self->secondLastBlockData.spectralData = self->spectralDataBuffers[1]; - move16(); self->secondLastPowerSpectrum = self->secondLastBlockData.spectralData; - move16(); - self->lastBlockData.scaleFactors = self->scaleFactorsBuffers[0]; - move16(); self->secondLastBlockData.scaleFactors = self->scaleFactorsBuffers[1]; - move16(); - self->lastBlockData.scaleFactors_exp = self->scaleFactorsBuffers_exp[0]; - move16(); - self->secondLastBlockData.scaleFactors_exp = self->scaleFactorsBuffers_exp[1]; - move16(); - self->lastBlockData.blockIsValid = 0; - move16(); self->secondLastBlockData.blockIsValid = 0; - move16(); self->nSamples = 0; - move16(); self->nScaleFactors = 0; - move16(); self->lastBlockData.blockIsConcealed = 0; - move16(); self->secondLastBlockData.blockIsConcealed = 0; - move16(); - self->pTCI = (TonalComponentsInfo *)self->timeDataBuffer; - move16(); + self->lastPitchLag = 0; - self->lastPitchLag = L_deposit_l(0); - - IF (sub(self->nSamples,nSamples) != 0) + if (self->nSamples != nSamples) { self->secondLastBlockData.blockIsValid = 0; - move16(); self->lastBlockData.blockIsValid = 0; - move16(); } - self->nSamples = nSamples; - move16(); self->nSamplesCore = nSamplesCore; - move16(); - self->nScaleFactors = nScaleFactors; - move16(); /* Offset the pointer to the end of buffer, so that pTCI is not destroyed when - new time samples are stored in lastPcmOut */ move16(); - move16(); + new time samples are stored in lastPcmOut */ /* just the second half of the second last pcm output is needed */ - self->secondLastPcmOut = &self->timeDataBuffer[sub((3*L_FRAME_MAX)/2,3*(s_min(L_FRAME_MAX, nSamples))/2)]; - self->lastPcmOut = &self->timeDataBuffer[sub((3*L_FRAME_MAX)/2, s_min(L_FRAME_MAX, nSamples)) ]; + self->secondLastPcmOut = &self->timeDataBuffer[(3*L_FRAME_MAX)/2-(3*min(L_FRAME_MAX, nSamples))/2]; + self->lastPcmOut = &self->timeDataBuffer[(3*L_FRAME_MAX)/2-min(L_FRAME_MAX, nSamples)]; - /* If the second last frame was lost, we reuse saved TonalComponentsInfo and don't update pcm buffers */ + /* If the second last frame was lost and concealed with tonal PLC, we + reuse saved TonalComponentsInfo and don't update pcm buffers */ assert(sizeof(*self->pTCI) <= (self->lastPcmOut-self->timeDataBuffer)*sizeof(self->timeDataBuffer[0])); return TONALMDCTCONCEAL_OK; } + TONALMDCTCONCEAL_ERROR TonalMDCTConceal_SaveFreqSignal( TonalMDCTConcealPtr self, - Word32 const *mdctSpectrum, - Word16 const mdctSpectrum_exp, - Word16 nNewSamples, - Word16 nNewSamplesCore, - Word16 const *scaleFactors, - Word16 const *scaleFactors_exp, - Word16 const gain_tcx_exp + float const *mdctSpectrum, + unsigned int nNewSamples, + unsigned int nNewSamplesCore, + float const *scaleFactors ) { - Word16 * temp; - Word16 nOldSamples, tmp_exp, s, i, max_exp; - + float * temp; + int nOldSamples; assert(nNewSamples > 0 && nNewSamples <= 2*L_FRAME_MAX); /* Avoid overwriting self->secondLastPowerSpectrum stored in spectralData, because it is needed if the second last and the current frame are lost - and concealed using the Tonal MDCT PLC */ test(); - IF (!self->lastBlockData.tonalConcealmentActive || sub(self->lastBlockData.nSamples,nNewSamples) != 0) + and concealed using the Tonal MDCT PLC */ + if (!self->lastBlockData.tonalConcealmentActive || (self->lastBlockData.nSamples != nNewSamples)) { - IF (sub(nNewSamples,L_FRAME_MAX) <= 0) + if (nNewSamples <= L_FRAME_MAX) { /* Shift the buffers */ - temp = self->secondLastBlockData.spectralData; /* Save the pointer */ move16(); + temp = self->secondLastBlockData.spectralData; /* Save the pointer */ self->secondLastBlockData.spectralData = self->lastBlockData.spectralData; - move16(); self->lastBlockData.spectralData = temp; - move16(); - - tmp_exp = self->secondLastBlockData.spectralData_exp; /* Save the pointer */ move16(); - self->secondLastBlockData.spectralData_exp = self->lastBlockData.spectralData_exp; - move16(); - self->lastBlockData.spectralData_exp = tmp_exp; - move16(); - - tmp_exp = self->secondLastBlockData.gain_tcx_exp; /* Save the pointer */ move16(); - self->secondLastBlockData.gain_tcx_exp = self->lastBlockData.gain_tcx_exp; - move16(); - self->lastBlockData.gain_tcx_exp = tmp_exp; - move16(); - - tmp_exp = self->secondLastBlockData.scaleFactors_max_e; /* Save the pointer */ move16(); - self->secondLastBlockData.scaleFactors_max_e = self->lastBlockData.scaleFactors_max_e; - move16(); - self->lastBlockData.scaleFactors_max_e = tmp_exp; - move16(); - temp = self->secondLastBlockData.scaleFactors; - move16(); self->secondLastBlockData.scaleFactors = self->lastBlockData.scaleFactors; - move16(); self->lastBlockData.scaleFactors = temp; - move16(); - - temp = self->secondLastBlockData.scaleFactors_exp; - move16(); - self->secondLastBlockData.scaleFactors_exp = self->lastBlockData.scaleFactors_exp; - move16(); - self->lastBlockData.scaleFactors_exp = temp; - move16(); } - ELSE + else { - self->lastBlockData.spectralData = self->spectralDataBuffers[0]; - move16(); - self->secondLastBlockData.spectralData = self->spectralDataBuffers[1]; - move16(); - self->lastBlockData.scaleFactors = self->scaleFactorsBuffers[0]; - move16(); - self->secondLastBlockData.scaleFactors = self->scaleFactorsBuffers[1]; - move16(); - self->lastBlockData.scaleFactors_exp = self->scaleFactorsBuffers_exp[0]; - move16(); - self->secondLastBlockData.scaleFactors_exp = self->scaleFactorsBuffers_exp[1]; - move16(); + /* Order the buffers so that even transition frame can fit in if written into the first buffer */ + self->lastBlockData.spectralData = self->spectralDataBuffers[0]; + self->secondLastBlockData.spectralData = self->spectralDataBuffers[1]; + self->lastBlockData.scaleFactors = self->scaleFactorsBuffers[0]; + self->secondLastBlockData.scaleFactors = self->scaleFactorsBuffers[1]; } - nOldSamples = self->lastBlockData.nSamples; - move16(); self->lastBlockData.nSamples = nNewSamples; - move16(); self->secondLastBlockData.nSamples = nOldSamples; - move16(); - nOldSamples = self->lastBlockData.nSamplesCore; - move16(); self->lastBlockData.nSamplesCore = nNewSamplesCore; - move16(); self->secondLastBlockData.nSamplesCore = nOldSamples; - move16(); } - - test(); - IF ((nNewSamples > 0) && (sub(nNewSamples,2*L_FRAME_MAX) <= 0)) + if ((nNewSamples > 0) && (nNewSamples <= 2*L_FRAME_MAX)) { /* Store new data */ - s = getScaleFactor32(mdctSpectrum, nNewSamples); - - /*Copy(scaleFactors_exp, self->lastBlockData.scaleFactors_exp, self->nScaleFactors);*/ - max_exp = 0; - FOR (i = 0; i < self->nScaleFactors; i++) - { - self->lastBlockData.scaleFactors_exp[i] = scaleFactors_exp[i]; - move16(); - max_exp = s_max(max_exp, scaleFactors_exp[i]); - } - - /*s = sub(s, max_exp);*/ - self->lastBlockData.scaleFactors_max_e = max_exp; - - FOR (i = 0; i < nNewSamples; i++) - { - self->lastBlockData.spectralData[i] = extract_h(L_shl(mdctSpectrum[i], s)); - move16(); - } - self->lastBlockData.spectralData_exp = sub(mdctSpectrum_exp,s); - move16(); - self->lastBlockData.gain_tcx_exp = gain_tcx_exp; - - Copy(scaleFactors, self->lastBlockData.scaleFactors, self->nScaleFactors); + mvr2r(mdctSpectrum, self->lastBlockData.spectralData, nNewSamples); + mvr2r(scaleFactors, self->lastBlockData.scaleFactors, self->nScaleFactors); } return TONALMDCTCONCEAL_OK; } + TONALMDCTCONCEAL_ERROR TonalMDCTConceal_UpdateState(TonalMDCTConcealPtr self, - Word16 nNewSamples, - Word32 pitchLag, - Word16 badBlock, - Word8 tonalConcealmentActive + int nNewSamples, + float pitchLag, + int badBlock, + int tonalConcealmentActive ) { - Word8 newBlockIsValid; + int newBlockIsValid; + assert(!(!badBlock && tonalConcealmentActive)); - IF (badBlock) + if (badBlock) { newBlockIsValid = self->lastBlockData.blockIsValid; - move16(); } - ELSE + else { - newBlockIsValid = 0; - move16(); - test(); - if((sub(nNewSamples,2*L_FRAME_MAX) <= 0) && (nNewSamples > 0)) - { - newBlockIsValid = 1; - move16(); - } + newBlockIsValid = (nNewSamples <= 2*L_FRAME_MAX) && (nNewSamples > 0); } - /* Shift old state */ move16(); - move16(); - move16(); + /* Shift old state */ self->secondLastBlockData.blockIsConcealed = self->lastBlockData.blockIsConcealed; self->secondLastBlockData.blockIsValid = self->lastBlockData.blockIsValid; self->secondLastBlockData.tonalConcealmentActive = self->lastBlockData.tonalConcealmentActive; - /* Store new state */ move16(); - move16(); - move16(); + /* Store new state */ self->lastBlockData.blockIsConcealed = badBlock; self->lastBlockData.blockIsValid = newBlockIsValid; self->lastBlockData.tonalConcealmentActive = tonalConcealmentActive; - self->lastPitchLag = pitchLag; - move32(); return TONALMDCTCONCEAL_OK; } -static void FindPhases( /* o: currenc phase [-pi;pi] 2Q13 */ - TonalMDCTConcealPtr const self, /* i: pointer to internal structure */ - Word32 secondLastMDCT[], /* i: MDST spectrum data */ - Word32 secondLastMDST[], /* i: MDCT spectrum data */ - Word16 diff_exp) /* i: exp_MDST - exp_MDCT */ -{ - Word16 i; - Word16 l; - Word16 *pCurrentPhase; +static void FindPhases(TonalMDCTConcealPtr const self, float const secondLastMDCT[], float const secondLastMDST[]) +{ + unsigned int i; + int l; + float * pCurrentPhase; + pCurrentPhase = self->pTCI->phase_currentFramePredicted; /* for each index/index group */ - FOR( i = 0; i < self->pTCI->numIndexes; i++) + for( i = 0; i < self->pTCI->numIndexes; i++) { - FOR (l = self->pTCI->lowerIndex[i]; l <= self->pTCI->upperIndex[i]; l++) + for (l = self->pTCI->lowerIndex[i]; l <= self->pTCI->upperIndex[i]; l++) { - /* in contrast to the float code, the parameter secondLastMDST[l] - needs not to be negated - due to a different implementation of - the MDST */ - *pCurrentPhase++ = BASOP_util_atan2(secondLastMDST[l], secondLastMDCT[l], diff_exp); - move16(); + *pCurrentPhase++ = (float)atan2(secondLastMDST[l], secondLastMDCT[l]); } } + return; } -#define BANDWIDTH 7.0f -#define G 789516047l/*1.0/(2*1.36) Q31*/ -#define MAXRATIO 22938/*44.8f Q9*/ /* Maximum ratio |ODFT[k-1]|/|ODFT[k+1]| is 16.5 dB, that is maximum ratio (for fractional = 0) is (cos(PI/bandwidth)/cos(3PI/bandwidth))^1.36 */ -#define MM 1934815907 /* FL2WORD32(cos(EVS_PI/BANDWIDTH)); */ -#define SS 29166 /* FL2WORD16(cos((3*EVS_PI)/BANDWIDTH)*4); Q17*/ -#define N 931758243 /* FL2WORD32(sin(EVS_PI/BANDWIDTH)); */ -#define J 31946 /* FL2WORD16(sin((3*EVS_PI)/BANDWIDTH)); */ -static void FindPhaseDifferences( /* o: Phase difference [-pi;pi] 2Q13*/ - TonalMDCTConcealPtr const self, /* i: Pointer to internal structure */ - Word32 powerSpectrum[]) /* i: Power spectrum data */ +static void FindPhaseDifferences(TonalMDCTConcealPtr const self, float powerSpectrum[]) { - Word16 i, k; - Word16 * phaseDiff; - Word16 fractional, sf, sfn, sfd; - Word16 divi, s, j; - Word32 a, Q, L_tmp, m, n; + static float const bandwidth = 7.0f; + float const m = (float)cos(EVS_PI/bandwidth); + float const s = (float)cos((3*EVS_PI)/bandwidth); + float const n = (float)sin(EVS_PI/bandwidth); + float const j = (float)sin((3*EVS_PI)/bandwidth); + static float const G = (float)(1.0/(2*1.36)); + static float const maxRatio = 44.8f; /* Maximum ratio |ODFT[k-1]|/|ODFT[k+1]| is 16.5 dB, that is maximum ratio (for fractional = 0) is (cos(EVS_PI/bandwidth)/cos(3PI/bandwidth))^1.36 */ - s = SS; - move16(); - j = J; - move16(); + unsigned int i, k; + float odft_left, odft_right; + float * phaseDiff; + float fractional; + float Q, a; phaseDiff = self->pTCI->phaseDiff; - - FOR (i = 0; i < self->pTCI->numIndexes; i++) + for (i = 0; i < self->pTCI->numIndexes; i++) { - m = MM; - move16(); - n = N; - move16(); - k = self->pTCI->indexOfTonalPeak[i]; - move16(); - - IF (L_sub(Mpy_32_16_1(powerSpectrum[k-1],512/*1.0f Q9*/),Mpy_32_16_1(powerSpectrum[k+1], MAXRATIO)) >= 0) + odft_left = powerSpectrum[k-1]; + odft_right = powerSpectrum[k+1]; + if (odft_left >= maxRatio*odft_right) { - phaseDiff[i] = 0; /*(float)tan(0.0f*EVS_PI/bandwidth);*/ move16(); - if(s_and(k,1) != 0) - phaseDiff[i] = -12868/*-EVS_PI 3Q12*/; + a = (float)tan(0.0f*EVS_PI/bandwidth); } - ELSE + else { - IF (L_sub(Mpy_32_16_1(powerSpectrum[k+1],512/*1.0f Q9*/),Mpy_32_16_1(powerSpectrum[k-1], MAXRATIO)) >= 0) + if (odft_right >= maxRatio*odft_left) { - phaseDiff[i] = 12868/*EVS_PI 3Q12*/; /*(float)tan(2.0f*PI/bandwidth);*/ move16(); - if(s_and(k,1) != 0) - phaseDiff[i] = 0/*0 Q13*/; /*2Q13*/ + a = (float)tan(2.0f*EVS_PI/bandwidth); } - ELSE { - /*Q = (float)pow(odft_left/odft_right, G); - a = (m - Q * s) / (n + Q * j); - phaseDiff[i] = (float)atan(a) * (bandwidth/2.0f);*/ - /*max divi=44.8 & sf=6*/ - divi = BASOP_Util_Divide3232_uu_1616_Scale(powerSpectrum[k-1],powerSpectrum[k+1], &sf); - Q = BASOP_Util_fPow(L_deposit_h(divi), sf, G, 0, &sf); - L_tmp = Mpy_32_16_1(Q,s); - sfn = sub(sf, 2); - - if(sfn > 0) - m = L_shr(m, sfn); - - IF(sfn < 0) - { - L_tmp = L_shl(L_tmp, sfn); - sfn = 0; - } - - a = L_sub(m, L_tmp); /*sf*/ - - L_tmp = Mpy_32_16_1(Q,j); - IF(sf >= 0) - { - L_tmp = L_shr(L_tmp, 1); - sfd = add(sf,1); - n = L_shr(n,sfd); - } - ELSE{ - sfd = 0; - L_tmp = L_shl(L_tmp, sf); - } - - L_tmp = L_add(n,L_tmp); - fractional = BASOP_util_atan2(a, L_tmp, sub(sfn,sfd)); /*2Q13*/ - L_tmp = L_mult(fractional, 28672/*BANDWIDTH/2.0f Q13*/); /*2Q13*2Q13=4Q27*/ move16(); - - /* fractional is in the range 0..+pi */ - /* we need to stay in the range -2pi..+2pi */ - if(sub(s_and(k,3),1) == 0) - { - L_tmp = L_add(L_tmp, 421657440l/*+1*EVS_PI Q27*/); - } - if(sub(s_and(k,3),2) == 0) - { - L_tmp = L_sub(L_tmp, 843314880l/*+2*EVS_PI=-2*EVS_PI Q27*/); - } - if(sub(s_and(k,3),3) == 0) - { - L_tmp = L_sub(L_tmp, 421657440l/*+3*EVS_PI=-1*EVS_PI Q27*/); - } - phaseDiff[i] = round_fx(L_shl(L_tmp,1)); /*3Q12*/ + else + { + Q = (float)pow(odft_left/odft_right, G); + a = (m - Q * s) / (n + Q * j); } } + fractional = (float)atan(a) * (bandwidth/2.0f); + assert((fractional >= 0) && (fractional <= EVS_PI + 1.192092896e-07F)); + phaseDiff[i] = fractional + EVS_PI*(k%4); } + + return; } + static void CalcPowerSpecAndDetectTonalComponents(TonalMDCTConcealPtr const self, - Word32 secondLastMDST[], - Word16 secondLastMDST_exp, - Word32 secondLastMDCT[], - Word16 secondLastMDCT_exp, - Word32 const pitchLag) + float secondLastMDST[], + float secondLastMDCT[], + float const pitchLag) { - Word16 nSamples; - Word16 i; - Word16 floorPowerSpectrum; /* Minimum significant value of a spectral line in the power spectrum */ - Word32 powerSpectrum[L_FRAME_MAX]; - Word16 invScaleFactors[FDNS_NPTS]; - Word16 invScaleFactors_exp[FDNS_NPTS]; - Word16 powerSpectrum_exp, tmp_exp, old_exp; - - + unsigned int nSamples; + unsigned int i; + float floorPowerSpectrum; /* Minimum significant value of a spectral line in the power spectrum */ + float powerSpectrum[L_FRAME_MAX]; /* 32 bits are required */ + float invScaleFactors[FDNS_NPTS]; nSamples = self->nNonZeroSamples; - move16(); /* It is taken into account that the MDCT is not normalized. */ - floorPowerSpectrum/*Q0*/ = extract_l(Mpy_32_16_1(L_mult0(self->nSamples,self->nSamples),82)); /*1/400 = 82 Q15*/ - powerSpectrum_exp = 0; - move16(); - - CalcPowerSpec(secondLastMDCT, - secondLastMDCT_exp, - secondLastMDST, - secondLastMDST_exp, - nSamples, - floorPowerSpectrum, - powerSpectrum, - &powerSpectrum_exp); + floorPowerSpectrum = self->nSamples*self->nSamples/400.0f; + CalcPowerSpec(secondLastMDCT, secondLastMDST, nSamples, floorPowerSpectrum, powerSpectrum ); /* This setting to minimal level is required because the power spectrum is used in the threshold adaptation using the pitch up to self->nSamples. */ - set32_fx(powerSpectrum+nSamples, floorPowerSpectrum, sub(self->nSamples, nSamples)); + set_f(powerSpectrum+nSamples, floorPowerSpectrum, self->nSamples-nSamples); /* this setting to zero is needed since the FDNS needs to be called with self->nSamplesCore; it relevant only for nb; it has no effect to the output, but memory checker may complain otherwise due to the usage of uninitialized values */ - IF ( sub(self->nSamplesCore, self->nSamples) > 0 ) + if (self->nSamplesCore > self->nSamples) { - set32_fx(powerSpectrum+self->nSamples, 0, sub(self->nSamplesCore, self->nSamples)); + set_zero(powerSpectrum+self->nSamples, self->nSamplesCore-self->nSamples); } - DetectTonalComponents(self->pTCI->indexOfTonalPeak, self->pTCI->lowerIndex, self->pTCI->upperIndex, @@ -495,752 +289,417 @@ static void CalcPowerSpecAndDetectTonalComponents(TonalMDCTConcealPtr const self self->lastPitchLag, pitchLag, self->lastBlockData.spectralData, - add(self->lastBlockData.spectralData_exp,self->lastBlockData.gain_tcx_exp), self->lastBlockData.scaleFactors, - self->lastBlockData.scaleFactors_exp, - self->lastBlockData.scaleFactors_max_e, powerSpectrum, nSamples, self->nSamplesCore, - floorPowerSpectrum); - - FindPhases(self, secondLastMDCT, secondLastMDST, sub(secondLastMDST_exp,secondLastMDCT_exp)); - + floorPowerSpectrum ); + FindPhases(self, secondLastMDCT, secondLastMDST); FindPhaseDifferences(self, powerSpectrum); - - IF (self->pTCI->numIndexes > 0) + if (self->pTCI->numIndexes > 0) { - self->secondLastPowerSpectrum = self->secondLastBlockData.spectralData; - - /*sqrtFLOAT(powerSpectrum, powerSpectrum, nSamples);*/ - old_exp = powerSpectrum_exp; - powerSpectrum_exp = mult_r(sub(powerSpectrum_exp,2), 1 << 14); /*remove 2 bits of headroom from CalcPowerSpec*/ - FOR (i = 0; i < nSamples; i++) + for ( i=0; inScaleFactors; i++) + for (i = 0; i < self->nScaleFactors; i++) { - move16(); - move16(); - invScaleFactors_exp[i] = self->secondLastBlockData.scaleFactors_exp[i]; - invScaleFactors[i] = Inv16(self->secondLastBlockData.scaleFactors[i], &invScaleFactors_exp[i]); + invScaleFactors[i] = 1.0f/self->secondLastBlockData.scaleFactors[i]; } - - - /* here mdct_shaping() is intentionally used rather then mdct_shaping_16() */ - mdct_shaping(powerSpectrum, self->nSamplesCore, invScaleFactors, invScaleFactors_exp); - FOR (i = self->nSamplesCore; i < nSamples; i++) - { - powerSpectrum[i] = L_shl(Mpy_32_16_1(powerSpectrum[i], invScaleFactors[FDNS_NPTS-1]), invScaleFactors_exp[FDNS_NPTS-1]); - move32(); - } - - /* 16 bits are now enough for storing the power spectrum */ - FOR (i = 0; i < nSamples; i++) - { - self->secondLastPowerSpectrum[i] = round_fx(powerSpectrum[i]); - } - - powerSpectrum_exp = sub(powerSpectrum_exp, self->secondLastBlockData.gain_tcx_exp); - self->secondLastPowerSpectrum_exp = powerSpectrum_exp; - move16(); + mdct_noiseShaping(powerSpectrum, self->nSamplesCore, invScaleFactors); + v_multc( powerSpectrum + self->nSamplesCore, invScaleFactors[FDNS_NPTS-1], powerSpectrum + self->nSamplesCore, self->nSamples - self->nSamplesCore); + mvr2r( powerSpectrum, self->secondLastPowerSpectrum, self->nSamples); /* 16 bits are now enough for storing the power spectrum */ } + + return; } static void CalcMDXT(TonalMDCTConcealPtr const self, - Word16 const type, - Word16 const * const timeSignal, - Word32 * const mdxtOutput, - Word16 * const mdxtOutput_e) + char const type, + float const * const timeSignal, + float * const mdxtOutput) { - Word16 windowedTimeSignal[L_FRAME_PLUS+2*L_MDCT_OVLP_MAX]; - Word16 left_overlap, right_overlap, L_frame; + float windowedTimeSignal[L_FRAME_PLUS+2*L_MDCT_OVLP_MAX]; + int left_overlap, right_overlap, L_frame; L_frame = self->nSamples; - move16(); - - WindowSignal(self->tcx_cfg, - self->tcx_cfg->tcx_offsetFB, - FULL_OVERLAP, - FULL_OVERLAP, - &left_overlap, - &right_overlap, - timeSignal, - &L_frame, - windowedTimeSignal, - 1); - - IF (type == 0) + WindowSignal( self->tcx_cfg, self->tcx_cfg->tcx_offsetFB, FULL_OVERLAP, FULL_OVERLAP, + &left_overlap, &right_overlap, timeSignal, &L_frame, windowedTimeSignal, 1 ); + if (type == 'S') { - TCX_MDST(windowedTimeSignal, - mdxtOutput, - mdxtOutput_e, - left_overlap, - sub(L_frame, shr(add(left_overlap, right_overlap), 1)), - right_overlap); + TCX_MDST( windowedTimeSignal, mdxtOutput, left_overlap, L_frame - (left_overlap+right_overlap)/2, right_overlap ); } - ELSE + else { - TCX_MDCT(windowedTimeSignal, - mdxtOutput, - mdxtOutput_e, - left_overlap, - sub(L_frame, shr(add(left_overlap, right_overlap), 1)), - right_overlap); + TCX_MDCT( windowedTimeSignal, mdxtOutput, left_overlap, L_frame - (left_overlap+right_overlap)/2, right_overlap ); } + + return; } -TONALMDCTCONCEAL_ERROR TonalMDCTConceal_Detect( TonalMDCTConcealPtr const self, - Word32 const pitchLag, - Word16 * const numIndices) -{ - Word32 secondLastMDST[L_FRAME_MAX]; - Word32 secondLastMDCT[L_FRAME_MAX]; - Word16 secondLastMDCT_exp; - Word32 * powerSpectrum = secondLastMDST; - Word16 i, powerSpectrum_exp, secondLastMDST_exp, s; - Word16 nSamples; +TONALMDCTCONCEAL_ERROR TonalMDCTConceal_Detect( TonalMDCTConcealPtr const self, + float const pitchLag, + int * const numIndices) +{ + float secondLastMDST[L_FRAME_MAX]; /* 32 bits are required */ + float secondLastMDCT[L_FRAME_MAX]; /* 32 bits are required */ + float * powerSpectrum = secondLastMDST; + unsigned int nSamples; + unsigned int i; nSamples = self->nSamples; - move16(); - secondLastMDST_exp = 16; /*time signal Q-1*/ - secondLastMDCT_exp = 16; /*time signal Q-1*/ - test(); - test(); - test(); - test(); - test(); - IF (self->lastBlockData.blockIsValid && self->secondLastBlockData.blockIsValid - && (sub(self->lastBlockData.nSamples,nSamples) == 0) && (sub(self->secondLastBlockData.nSamples,nSamples) == 0) - && (!self->secondLastBlockData.blockIsConcealed || self->secondLastBlockData.tonalConcealmentActive || (pitchLag != 0)) /* Safety if the second last frame was concealed and tonal concealment was inactive */ + if (self->lastBlockData.blockIsValid + && self->secondLastBlockData.blockIsValid + && (self->lastBlockData.nSamples == nSamples) + && (self->secondLastBlockData.nSamples == nSamples) + && (!self->secondLastBlockData.blockIsConcealed + || self->secondLastBlockData.tonalConcealmentActive + || (pitchLag != 0)) + /* Safety if the second last frame was concealed and tonal concealment was inactive */ ) { - - IF (self->lastBlockData.blockIsConcealed == 0) + if (!self->lastBlockData.blockIsConcealed) { - IF (self->secondLastBlockData.tonalConcealmentActive == 0) + if (!self->secondLastBlockData.tonalConcealmentActive) { - CalcMDXT(self, 0, self->secondLastPcmOut, secondLastMDST, &secondLastMDST_exp); - CalcMDXT(self, 1, self->secondLastPcmOut, secondLastMDCT, &secondLastMDCT_exp); + CalcMDXT(self, 'S', self->secondLastPcmOut, secondLastMDST); + CalcMDXT(self, 'C', self->secondLastPcmOut, secondLastMDCT); self->nNonZeroSamples = 0; - FOR (i = 0; i < self->nSamples; i++) + for (i = 0; i < self->nSamples; i++) { if (self->secondLastBlockData.spectralData[i] != 0) { self->nNonZeroSamples = i; - move16(); } } - /* 23 is the maximum length of the MA filter in getEnvelope */ - self->nNonZeroSamples = s_min(self->nSamples, add(self->nNonZeroSamples, 23)); - move16(); - nSamples = self->nNonZeroSamples; - move16(); - - s = getScaleFactor32(secondLastMDST, nSamples); - - FOR (i = 0; i < nSamples; i++) - { - secondLastMDST[i] = L_shl(secondLastMDST[i], s); - move32(); - } - secondLastMDST_exp = sub(secondLastMDST_exp, s); - move16(); - s = getScaleFactor32(secondLastMDCT, nSamples); - - FOR (i = 0; i < nSamples; i++) - { - secondLastMDCT[i] = L_shl(secondLastMDCT[i], s); - move32(); - } - secondLastMDCT_exp = sub(secondLastMDCT_exp, s); - move16(); - CalcPowerSpecAndDetectTonalComponents(self, secondLastMDST, secondLastMDST_exp, secondLastMDCT, secondLastMDCT_exp, pitchLag); + self->nNonZeroSamples = min(self->nSamples, self->nNonZeroSamples+23); ; + CalcPowerSpecAndDetectTonalComponents(self, secondLastMDST, secondLastMDCT, pitchLag); } - ELSE + else { /* If the second last frame was also lost, it is expected that pastTimeSignal could hold a bit different signal (e.g. including fade-out) from the one stored in TonalMDCTConceal_SaveTimeSignal. */ /* That is why we reuse the already stored information about the concealed spectrum in the second last frame */ nSamples = self->nNonZeroSamples; - move16(); - mdct_shaping_16(self->secondLastPowerSpectrum, self->nSamplesCore, nSamples, - self->secondLastBlockData.scaleFactors, self->secondLastBlockData.scaleFactors_exp, - self->secondLastBlockData.scaleFactors_max_e, powerSpectrum); - - powerSpectrum_exp = getScaleFactor32(powerSpectrum, nSamples); - powerSpectrum_exp = sub(powerSpectrum_exp, 3); /*extra 3 bits of headroom for MA filter in getEnvelope*/ - - /* multFLOAT(powerSpectrum, powerSpectrum, powerSpectrum, nSamples); */ - FOR(i = 0; i < nSamples; i++) - { - Word32 const t = L_shl(powerSpectrum[i], powerSpectrum_exp); - powerSpectrum[i] = Mpy_32_32(t, t); - move32(); - } - + mvr2r(self->secondLastPowerSpectrum, powerSpectrum, nSamples); /* Convert from 16 bits to 32 bits */ + mdct_noiseShaping(powerSpectrum, self->nSamplesCore, self->secondLastBlockData.scaleFactors); + v_multc(powerSpectrum + self->nSamplesCore, + self->secondLastBlockData.scaleFactors[FDNS_NPTS-1], + powerSpectrum + self->nSamplesCore, + nSamples - self->nSamplesCore); + v_mult(powerSpectrum, powerSpectrum, powerSpectrum, nSamples); RefineTonalComponents(self->pTCI->indexOfTonalPeak, - self->pTCI->lowerIndex, - self->pTCI->upperIndex, - self->pTCI->phaseDiff, - self->pTCI->phase_currentFramePredicted, - &self->pTCI->numIndexes, - self->lastPitchLag, - pitchLag, - self->lastBlockData.spectralData, - add(self->lastBlockData.spectralData_exp,self->lastBlockData.gain_tcx_exp), - self->lastBlockData.scaleFactors, - self->lastBlockData.scaleFactors_exp, - self->lastBlockData.scaleFactors_max_e, - powerSpectrum, - nSamples, - self->nSamplesCore, - extract_l(Mpy_32_16_1(L_mult0(self->nSamples,self->nSamples),82))); /* floorPowerSpectrum */ - + self->pTCI->lowerIndex, + self->pTCI->upperIndex, + self->pTCI->phaseDiff, + self->pTCI->phase_currentFramePredicted, + &self->pTCI->numIndexes, + self->lastPitchLag, + pitchLag, + self->lastBlockData.spectralData, + self->lastBlockData.scaleFactors, + powerSpectrum, + nSamples, + self->nSamplesCore, + self->nSamples*self->nSamples/400.0f /* floorPowerSpectrum */ ); } } } - ELSE + else { self->pTCI->numIndexes = 0; - move16(); } - *numIndices = self->pTCI->numIndexes; - move16(); return TONALMDCTCONCEAL_OK; } + TONALMDCTCONCEAL_ERROR TonalMDCTConceal_InsertNoise( TonalMDCTConcealPtr self, /*IN */ - Word32* mdctSpectrum, /*OUT*/ - Word16* mdctSpectrum_exp, /*OUT*/ - Word8 tonalConcealmentActive, - Word16* pSeed, /*IN/OUT*/ - Word16 tiltCompFactor, - Word16 crossfadeGain, - Word16 crossOverFreq) + float* mdctSpectrum, /*OUT*/ + int tonalConcealmentActive, + short* pSeed, + float tiltCompFactor, + float crossfadeGain, + int crossOverFreq) { - Word16 i, ld, fac; - Word16 rnd, exp, exp_last, exp_noise, inv_samples, inv_exp; - Word16 g, tiltFactor, tilt, tmp; - Word32 nrgNoiseInLastFrame, nrgWhiteNoise, L_tmp, L_tmp2; + unsigned int i; + Word16 rnd; + float g, nrgNoiseInLastFrame, nrgWhiteNoise, tiltFactor, tilt; - - g = sub(32767/*1.0f Q15*/,crossfadeGain); - - rnd = 1977; - move16(); - if (self->lastBlockData.blockIsConcealed) + g = 1.0f-crossfadeGain; + if (!self->lastBlockData.blockIsConcealed) + { + rnd = 1977; + } + else { rnd = *pSeed; - move16(); } - - IF (self->lastBlockData.blockIsValid == 0) + if (!self->lastBlockData.blockIsValid) { /* may just become active if the very first frame is lost */ - set32_fx(mdctSpectrum, 0, self->nSamples); - *mdctSpectrum_exp = SPEC_EXP_DEC; + set_f( mdctSpectrum, 0.0f, self->nSamples); } - ELSE + else { - L_tmp = 805306368l/*0.375f Q31*/; - inv_exp = 15; - move16(); - inv_samples = Inv16(self->lastBlockData.nSamples, &inv_exp); - tiltFactor = round_fx(BASOP_Util_fPow(L_max(L_tmp, L_deposit_h(tiltCompFactor)), 0, L_deposit_h(inv_samples),inv_exp, &exp)); - BASOP_SATURATE_WARNING_OFF /*next op may result in 32768*/ - tiltFactor = shl(tiltFactor, exp); - BASOP_SATURATE_WARNING_ON - - tilt = 32767/*1.0f Q15*/; - move16(); - - nrgNoiseInLastFrame = L_deposit_h(0); - nrgWhiteNoise = L_deposit_h(0); - exp_last = exp_noise = 0; - move16(); - move16(); - IF (!tonalConcealmentActive) + /* based on what is done in tcx_noise_filling() */ + tiltFactor = (float)pow(max(0.375f, tiltCompFactor), 1.0f/self->lastBlockData.nSamples); + tilt = 1.0f; + nrgNoiseInLastFrame = nrgWhiteNoise = 0.0f; + if (!tonalConcealmentActive) { - ld = sub(14,norm_s(self->lastBlockData.nSamples)); - fac = shr(-32768,ld); - - FOR (i = 0; i < crossOverFreq; i++) + for (i = 0; i < (unsigned int)crossOverFreq; i++) { - Word16 x = self->lastBlockData.spectralData[i]; - Word32 y; - rnd = extract_l(L_mac0(13849, rnd, 31821)); - y = L_mult(tilt,rnd); - - nrgNoiseInLastFrame = L_add(nrgNoiseInLastFrame, Mpy_32_16_1(L_msu(0, x,fac),x)); - x = round_fx(y); - nrgWhiteNoise = L_add(nrgWhiteNoise, Mpy_32_16_1(L_msu(0, x,fac),x)); - - mdctSpectrum[i] = y; /* 15Q16 */ move32(); - - tilt = mult_r(tilt,tiltFactor); + float const x = self->lastBlockData.spectralData[i]; + float y; + rnd = (Word16) (rnd * 31821L + 13849L); + y = tilt*rnd; + nrgNoiseInLastFrame += x*x; + nrgWhiteNoise += y*y; + mdctSpectrum[i] = y; + tilt *= tiltFactor; } - - IF (nrgNoiseInLastFrame == 0) + if (nrgWhiteNoise > 0) { - set32_fx(mdctSpectrum, 0, crossOverFreq); - *mdctSpectrum_exp = SPEC_EXP_DEC; + g *= (float)sqrt(nrgNoiseInLastFrame/nrgWhiteNoise); } - ELSE + for (i = 0; i < (unsigned int)crossOverFreq; i++) { - exp_last = add(ld,shl(self->lastBlockData.spectralData_exp,1)); - exp_noise = add(ld,30); + float const x = self->lastBlockData.spectralData[i]; + float const y = mdctSpectrum[i]; - IF (nrgWhiteNoise > 0) + if (y > 0) { - ld = norm_l(nrgNoiseInLastFrame); - nrgNoiseInLastFrame = L_shl(nrgNoiseInLastFrame,ld); - exp_last = sub(exp_last,ld); - ld = norm_l(nrgWhiteNoise); - nrgWhiteNoise = L_shl(nrgWhiteNoise,ld); - exp_noise = sub(exp_noise,ld); - - exp = sub(exp_last, exp_noise); - - IF(nrgNoiseInLastFrame > nrgWhiteNoise) - { - nrgNoiseInLastFrame = L_shr(nrgNoiseInLastFrame,1); - exp = add(exp,1); - } - tmp = div_l(nrgNoiseInLastFrame,round_fx(nrgWhiteNoise)); - tmp = Sqrt16(tmp, &exp); - g = mult_r(g,tmp); - - L_tmp = L_deposit_h(0); - ld = sub(self->lastBlockData.spectralData_exp, 15); - exp = sub(ld, exp); - - IF(exp > 0) - { - g = shr(g,exp); - *mdctSpectrum_exp = self->lastBlockData.spectralData_exp; - } - ELSE - { - crossfadeGain = shl(crossfadeGain,exp); - *mdctSpectrum_exp = sub(self->lastBlockData.spectralData_exp,exp); - } - /*make a headroom for mdct_shaping*/ - exp = sub(*mdctSpectrum_exp, SPEC_EXP_DEC); - /* assert(exp < 0);*/ - IF(exp < 0) - { - *mdctSpectrum_exp = SPEC_EXP_DEC; - } - ELSE - { - exp = 0; - } + mdctSpectrum[i] = g*y + crossfadeGain*x; } - - FOR (i = 0; i < crossOverFreq; i++) + else { - Word16 const x = self->lastBlockData.spectralData[i]; - Word32 const y = mdctSpectrum[i]; - - if(g > 0) - { - L_tmp = Mpy_32_16_1(y,g); - } - - L_tmp2 = L_msu(L_tmp,crossfadeGain,x); - if(y > 0) - { - L_tmp2 = L_mac(L_tmp,crossfadeGain,x); - } - mdctSpectrum[i] = L_shl(L_tmp2, exp); - move32(); + mdctSpectrum[i] = g*y - crossfadeGain*x; } } - exp = sub(self->lastBlockData.spectralData_exp, sub(*mdctSpectrum_exp,16)); - FOR (i = crossOverFreq; i < self->lastBlockData.nSamples; i++) + + for (i = (unsigned int)crossOverFreq; i < self->lastBlockData.nSamples; i++) { - mdctSpectrum[i] = L_shl(L_deposit_l(self->lastBlockData.spectralData[i]), exp); - move32(); + mdctSpectrum[i] = self->lastBlockData.spectralData[i]; } } - ELSE + else { - Word16 l; + unsigned int l; assert(self->pTCI->numIndexes > 0); - - FOR (l = self->pTCI->lowerIndex[0]; l <= self->pTCI->upperIndex[0]; l++) + for (l = 0; l < self->pTCI->lowerIndex[0]; l++) { - mdctSpectrum[l] = L_deposit_l(0); + float const x = self->lastBlockData.spectralData[l]; + float y; + rnd = (Word16) (rnd * 31821L + 13849L); + y = tilt*rnd; + nrgNoiseInLastFrame += x*x; + nrgWhiteNoise += y*y; + mdctSpectrum[l] = y; + tilt *= tiltFactor; } - - ld = sub(14,norm_s(self->lastBlockData.nSamples)); - fac = shr(-32768,ld); - FOR (l = 0; l < self->pTCI->lowerIndex[0]; l++) + for (i = 1; i < self->pTCI->numIndexes; i++) { - Word16 x = self->lastBlockData.spectralData[l]; - Word32 y; - rnd = extract_l(L_mac0(13849, rnd, 31821)); - y = L_mult(tilt,rnd); - - nrgNoiseInLastFrame = L_add(nrgNoiseInLastFrame, Mpy_32_16_1(L_msu(0, x,fac),x)); - x = round_fx(y); - nrgWhiteNoise = L_add(nrgWhiteNoise, Mpy_32_16_1(L_msu(0, x,fac),x)); - - mdctSpectrum[l] = y; /* 15Q16 L_deposit_l(y);*/ move32(); - - tilt = mult_r(tilt,tiltFactor); - } - - FOR (i = 1; i < self->pTCI->numIndexes; i++) - { - /*tilt *= (float)pow(tiltFactor, self->pTCI->upperIndex[i-1]-self->pTCI->lowerIndex[i-1]+1);*/ - tmp= round_fx(BASOP_Util_fPow(L_deposit_h(tiltFactor), 0, L_deposit_h(self->pTCI->upperIndex[i-1]-self->pTCI->lowerIndex[i-1]+1),15, &exp)); - tmp = shl(tmp, exp); - tilt = mult_r(tilt,tmp); - - FOR (l = self->pTCI->lowerIndex[i]; l <= self->pTCI->upperIndex[i]; l++) + tilt *= (float)pow(tiltFactor, self->pTCI->upperIndex[i-1]-self->pTCI->lowerIndex[i-1]+1); + for (l = self->pTCI->upperIndex[i-1]+1; l < self->pTCI->lowerIndex[i]; l++) { - mdctSpectrum[l] = L_deposit_l(0); - } - - FOR (l = self->pTCI->upperIndex[i-1]+1; l < self->pTCI->lowerIndex[i]; l++) - { - Word16 x = self->lastBlockData.spectralData[l]; - Word32 y; - rnd = extract_l(L_mac0(13849, rnd, 31821)); - y = L_mult(tilt,rnd); - - nrgNoiseInLastFrame = L_add(nrgNoiseInLastFrame, Mpy_32_16_1(L_msu(0, x,fac),x)); - x = round_fx(y); - nrgWhiteNoise = L_add(nrgWhiteNoise, Mpy_32_16_1(L_msu(0, x,fac),x)); - - mdctSpectrum[l] = y; /* 15Q16 L_deposit_l(y);*/ move32(); - - tilt = mult_r(tilt,tiltFactor); + float const x = self->lastBlockData.spectralData[l]; + float y; + rnd = (Word16) (rnd * 31821L + 13849L); + y = tilt*rnd; + nrgNoiseInLastFrame += x*x; + nrgWhiteNoise += y*y; + mdctSpectrum[l] = y; + tilt *= tiltFactor; } } + tilt *= (float)pow(tiltFactor, self->pTCI->upperIndex[self->pTCI->numIndexes-1]-self->pTCI->lowerIndex[self->pTCI->numIndexes-1]+1); - tmp = round_fx(BASOP_Util_fPow(L_deposit_h(tiltFactor), 0, L_deposit_h(self->pTCI->upperIndex[self->pTCI->numIndexes-1]-self->pTCI->lowerIndex[self->pTCI->numIndexes-1]+1),15, &exp)); - BASOP_SATURATE_WARNING_OFF /*next op may result in 32768*/ - tmp = shl(tmp, exp); - BASOP_SATURATE_WARNING_ON - tilt = mult_r(tilt,tmp); - - FOR (l = add(self->pTCI->upperIndex[self->pTCI->numIndexes-1], 1); l < crossOverFreq; l++) + for (l = self->pTCI->upperIndex[self->pTCI->numIndexes-1]+1; l < (unsigned int)crossOverFreq; l++) { - Word16 x = self->lastBlockData.spectralData[l]; - Word32 y; - rnd = extract_l(L_mac0(13849, rnd, 31821)); - y = L_mult(tilt,rnd); - - nrgNoiseInLastFrame = L_add(nrgNoiseInLastFrame, Mpy_32_16_1(L_msu(0, x,fac),x)); - x = round_fx(y); - nrgWhiteNoise = L_add(nrgWhiteNoise, Mpy_32_16_1(L_msu(0, x,fac),x)); - - mdctSpectrum[l] = y; /* 15Q16 L_deposit_l(y);*/ move32(); - - tilt = mult_r(tilt,tiltFactor); + float const x = self->lastBlockData.spectralData[l]; + float y; + rnd = (Word16) (rnd * 31821L + 13849L); + y = tilt*rnd; + nrgNoiseInLastFrame += x*x; + nrgWhiteNoise += y*y; + mdctSpectrum[l] = y; + tilt *= tiltFactor; } - - IF (nrgNoiseInLastFrame == 0) + if (nrgWhiteNoise > 0) { - set32_fx(mdctSpectrum, 0, crossOverFreq); - *mdctSpectrum_exp = SPEC_EXP_DEC; + g *= (float)sqrt(nrgNoiseInLastFrame/nrgWhiteNoise); } - ELSE + for (l = 0; l < self->pTCI->lowerIndex[0]; l++) { - exp_last = add(ld,shl(self->lastBlockData.spectralData_exp,1)); - exp_noise = add(ld,shl(15,1)); + float const x = self->lastBlockData.spectralData[l]; + float const y = mdctSpectrum[l]; - ld = norm_l(nrgNoiseInLastFrame); - nrgNoiseInLastFrame = L_shl(nrgNoiseInLastFrame,ld); - exp_last = sub(exp_last,ld); - ld = norm_l(nrgWhiteNoise); - nrgWhiteNoise = L_shl(nrgWhiteNoise,ld); - exp_noise = sub(exp_noise,ld); - - exp = sub(exp_last, exp_noise); - - IF(nrgNoiseInLastFrame > nrgWhiteNoise) + if (y > 0) { - nrgNoiseInLastFrame = L_shr(nrgNoiseInLastFrame,1); - exp = add(exp,1); + mdctSpectrum[l] = g*y + crossfadeGain*x; } - tmp = div_l(nrgNoiseInLastFrame,round_fx(nrgWhiteNoise)); - tmp = Sqrt16(tmp, &exp); - g = mult_r(g,tmp); - - L_tmp = L_deposit_h(0); - ld = sub(self->lastBlockData.spectralData_exp, 15); - exp = sub(ld, exp); - IF(exp > 0) + else { - g = shr(g,exp); - *mdctSpectrum_exp = self->lastBlockData.spectralData_exp; - } - ELSE { - crossfadeGain = shl(crossfadeGain,exp); - *mdctSpectrum_exp = sub(self->lastBlockData.spectralData_exp,exp); - } - /*make a headroom for mdct_shaping*/ - exp = sub(*mdctSpectrum_exp, SPEC_EXP_DEC); - - - IF(exp < 0) - { - *mdctSpectrum_exp = SPEC_EXP_DEC; - } - ELSE - { - exp = 0; - } - - FOR (l = 0; l < self->pTCI->lowerIndex[0]; l++) - { - Word16 const x = self->lastBlockData.spectralData[l]; - Word32 const y = mdctSpectrum[l]; - - if(g > 0) - { - L_tmp = Mpy_32_16_1(y,g); - } - - L_tmp2 = L_msu(L_tmp,crossfadeGain,x); - if(y > 0) - { - L_tmp2 = L_mac(L_tmp,crossfadeGain,x); - } - mdctSpectrum[l] = L_shl(L_tmp2, exp); - move32(); - } - - FOR (i = 1; i < self->pTCI->numIndexes; i++) - { - FOR (l = self->pTCI->upperIndex[i-1]+1; l < self->pTCI->lowerIndex[i]; l++) - { - Word16 const x = self->lastBlockData.spectralData[l]; - Word32 const y = mdctSpectrum[l]; - - if(g > 0) - { - L_tmp = Mpy_32_16_1(y,g); - } - - L_tmp2 = L_msu(L_tmp,crossfadeGain,x); - if(y > 0) - { - L_tmp2 = L_mac(L_tmp,crossfadeGain,x); - } - mdctSpectrum[l] = L_shl(L_tmp2, exp); - move32(); - } - } - - /* initialize bins of tonal components with zero: basically not - necessary, but currently the whole spectrum is rescaled in - mdct_noiseShaping() and then there would be a processing of - uninitialized values */ - FOR (i = 0; i < self->pTCI->numIndexes; i++) - { - FOR (l = self->pTCI->lowerIndex[i]; l <= self->pTCI->upperIndex[i]; l++) - { - mdctSpectrum[l] = L_deposit_l(0); - } - } - - FOR (l = add(self->pTCI->upperIndex[self->pTCI->numIndexes-1], 1); l < crossOverFreq; l++) - { - Word16 const x = self->lastBlockData.spectralData[l]; - Word32 const y = mdctSpectrum[l]; - - if(g > 0) - { - L_tmp = Mpy_32_16_1(y,g); - } - - L_tmp2 = L_msu(L_tmp,crossfadeGain,x); - if(y > 0) - { - L_tmp2 = L_mac(L_tmp,crossfadeGain,x); - } - mdctSpectrum[l] = L_shl(L_tmp2, exp); - move32(); + mdctSpectrum[l] = g*y - crossfadeGain*x; } } - exp = sub(self->lastBlockData.spectralData_exp, sub(*mdctSpectrum_exp,16)); - FOR (l = crossOverFreq; l < self->lastBlockData.nSamples; l++) + for (i = 1; i < self->pTCI->numIndexes; i++) { - mdctSpectrum[l] = L_shl(L_deposit_l(self->lastBlockData.spectralData[l]), exp); - move32(); + for (l = self->pTCI->upperIndex[i-1]+1; l < self->pTCI->lowerIndex[i]; l++) + { + float const x = self->lastBlockData.spectralData[l]; + float const y = mdctSpectrum[l]; + + if (y > 0) + { + mdctSpectrum[l] = g*y + crossfadeGain*x; + } + else + { + mdctSpectrum[l] = g*y - crossfadeGain*x; + } + } + } + /* initialize bins of tonal components with zero: basically not + necessary, but currently the whole spectrum is rescaled in + mdct_noiseShaping() and then there would be a processing of + uninitialized values */ + for (i = 0; i < self->pTCI->numIndexes; i++) + { + for (l = self->pTCI->lowerIndex[i]; l <= self->pTCI->upperIndex[i]; l++) + { + mdctSpectrum[l] = 0; + + } + } + for (l = self->pTCI->upperIndex[self->pTCI->numIndexes-1]+1; l < (unsigned int)crossOverFreq; l++) + { + float const x = self->lastBlockData.spectralData[l]; + float const y = mdctSpectrum[l]; + + if (y > 0) + { + mdctSpectrum[l] = g*y + crossfadeGain*x; + } + else + { + mdctSpectrum[l] = g*y - crossfadeGain*x; + } + } + for (l = (unsigned int)crossOverFreq; l < self->lastBlockData.nSamples; l++) + { + mdctSpectrum[l] = self->lastBlockData.spectralData[l]; } } } *pSeed = rnd; - move16(); return TONALMDCTCONCEAL_OK; } + TONALMDCTCONCEAL_ERROR TonalMDCTConceal_Apply(TonalMDCTConcealPtr self, /*IN */ - Word32 *mdctSpectrum, /*IN/OUT*/ - Word16 *mdctSpectrum_exp /*IN */ + float *mdctSpectrum /*OUT */ ) { - Word16 i, l, exp; - Word16 * phaseDiff, * pCurrentPhase; - Word32 phaseToAdd, currentPhase; - Word32 powerSpectrum[L_FRAME_MAX]; - Word16 nSamples; + unsigned int i, l; + float * phaseDiff, * pCurrentPhase; + float phaseToAdd; + float powerSpectrum[L_FRAME_MAX]; + unsigned int nSamples; - - IF (self->lastBlockData.blockIsValid & self->secondLastBlockData.blockIsValid) + if (self->lastBlockData.blockIsValid & self->secondLastBlockData.blockIsValid) { assert(self->pTCI->numIndexes > 0); nSamples = self->nNonZeroSamples; - move16(); assert(self->pTCI->upperIndex[self->pTCI->numIndexes-1] < nSamples); - - - mdct_shaping_16(self->secondLastPowerSpectrum, self->nSamplesCore, nSamples, - self->secondLastBlockData.scaleFactors, self->secondLastBlockData.scaleFactors_exp, - self->secondLastBlockData.scaleFactors_max_e, powerSpectrum); - + mvr2r(self->secondLastPowerSpectrum, powerSpectrum, nSamples); /* Convert from 16 bits to 32 bits */ + mdct_noiseShaping(powerSpectrum, self->nSamplesCore, self->secondLastBlockData.scaleFactors); + v_multc( powerSpectrum + self->nSamplesCore, self->secondLastBlockData.scaleFactors[FDNS_NPTS-1], powerSpectrum + self->nSamplesCore, nSamples - self->nSamplesCore ); phaseDiff = self->pTCI->phaseDiff; /* if multiple frame loss occurs use the phase from the last frame and continue rotating */ pCurrentPhase = self->pTCI->phase_currentFramePredicted; - - exp = sub(*mdctSpectrum_exp, add(add(self->secondLastPowerSpectrum_exp, add(self->secondLastBlockData.gain_tcx_exp,1)),self->secondLastBlockData.scaleFactors_max_e)); - - IF (!self->lastBlockData.blockIsConcealed) + if (!self->lastBlockData.blockIsConcealed) { - if (self->secondLastBlockData.tonalConcealmentActive != 0) + if (self->secondLastBlockData.tonalConcealmentActive) { - self->nFramesLost = add(self->nFramesLost,2); /*Q1*/ move16(); + self->nFramesLost += 1; } - if (self->secondLastBlockData.tonalConcealmentActive == 0) + else { - self->nFramesLost = 3; /*Q1*/ move16(); + self->nFramesLost = 1.5; } } /* for each index group */ - FOR (i = 0; i < self->pTCI->numIndexes; i++) + for (i = 0; i < self->pTCI->numIndexes; i++) { - /*phaseToAdd = self->nFramesLost*phaseDiff[i]; */ - phaseToAdd = L_mult0(self->nFramesLost,phaseDiff[i]); /*Q1*3Q12=2Q13*/ - /* Move phaseToAdd to range -PI..PI */ - - WHILE (L_sub(phaseToAdd, 25736l/*EVS_PI Q13*/) > 0) + phaseToAdd = self->nFramesLost*phaseDiff[i]; + /* Move phaseToAdd to range -EVS_PI..EVS_PI */ + while (phaseToAdd > EVS_PI) { - phaseToAdd = L_sub(phaseToAdd, 51472l/*2*EVS_PI Q13*/); + phaseToAdd -= 2*EVS_PI; } - WHILE (L_sub(phaseToAdd, -25736l/*-EVS_PI Q13*/) < 0) + while (phaseToAdd < -EVS_PI) { - phaseToAdd = L_add(phaseToAdd, 51472l/*2*EVS_PI Q13*/); + /* should never occur in flt - kept for safety reasons */ + phaseToAdd += 2*EVS_PI; } - - FOR (l = self->pTCI->lowerIndex[i]; l <= self->pTCI->upperIndex[i]; l++) + for (l = self->pTCI->lowerIndex[i]; l <= self->pTCI->upperIndex[i]; l++) { - /* *pCurrentPhase and phaseToAdd are in range -PI..PI */ - currentPhase = L_mac0(phaseToAdd, (*pCurrentPhase++), 1); /*2Q13+2Q13=3Q13*/ - - if (L_sub(currentPhase, 25736l/*EVS_PI Q13*/) > 0) - { - currentPhase = L_sub(currentPhase, 51472l/*2*EVS_PI Q13*/); - } - if (L_sub(currentPhase, -25736l/*-EVS_PI Q13*/) < 0) - { - currentPhase = L_add(currentPhase, 51472l/*2*EVS_PI Q13*/); - } - /* getCosWord16 returns 1Q14*/ - mdctSpectrum[l] = Mpy_32_16_1(powerSpectrum[l],getCosWord16(extract_l(currentPhase))); - move32(); - mdctSpectrum[l] = L_shr(mdctSpectrum[l], exp); + float const currentPhase = (*pCurrentPhase++) + phaseToAdd; /* *pCurrentPhase and phaseToAdd are in range -EVS_PI..EVS_PI */ + mdctSpectrum[l] = (float)cos(currentPhase) * powerSpectrum[l]; } } } - - self->nFramesLost = add(self->nFramesLost,2); /*Q1*/ move16(); + self->nFramesLost++; return TONALMDCTCONCEAL_OK; } + TONALMDCTCONCEAL_ERROR TonalMDCTConceal_SaveTimeSignal( TonalMDCTConcealPtr self, - Word16* timeSignal, - Word16 nNewSamples + float* timeSignal, + unsigned int nNewSamples ) { - IF (sub(nNewSamples,self->nSamples) == 0) + if (nNewSamples == self->nSamples) { assert(nNewSamples <= L_FRAME_MAX); - IF (!self->secondLastBlockData.tonalConcealmentActive) + if (!self->secondLastBlockData.tonalConcealmentActive) { - Copy(self->lastPcmOut + self->nSamples/2, self->secondLastPcmOut, self->nSamples/2); + mvr2r(self->lastPcmOut + self->nSamples/2, self->secondLastPcmOut, self->nSamples/2); } - Copy(timeSignal, self->lastPcmOut, self->nSamples); + mvr2r(timeSignal, self->lastPcmOut, self->nSamples); } - return TONALMDCTCONCEAL_OK; } -static void CalcPowerSpec(Word32 * mdctSpec, /* i: MDCT spectrum Q31,mdctSpec_exp */ - Word16 mdctSpec_exp, /* i: exponent of MDCT spectrum */ - Word32 * mdstSpec, /* i: MDST spectrum Q31,mdstSpec_exp */ - Word16 mdstSpec_exp, /* i: exponent of MDST spectrum */ - Word16 nSamples, /* i: frame size */ - Word16 floorPowerSpectrum, /* i: lower limit for power spectrum bins Q0 */ - Word32 * powerSpec, /* o: power spectrum */ - Word16 * powerSpec_exp) /* o: exponent of power spectrum */ + + +static void CalcPowerSpec(float const * mdctSpec, float const * mdstSpec, + unsigned int nSamples, float floorPowerSpectrum, + float * powerSpec) { - Word16 k, s1, s2, tmp; - Word32 x, L_tmp, L_tmp_floor; + unsigned int k; + float x; - - k = s_max(mdctSpec_exp, mdstSpec_exp); - *powerSpec_exp = add(add(k, k), 3); /*extra 3 bits of headroom for MA filter in getEnvelope*/ move16(); - s1 = sub(*powerSpec_exp, add(mdctSpec_exp, mdctSpec_exp)); - s2 = sub(*powerSpec_exp, add(mdstSpec_exp, mdstSpec_exp)); - - k = sub(31, *powerSpec_exp); - /* If the signal is bellow floor, special care is needed for *powerSpec_exp */ - IF (sub(add(16-3, norm_s(floorPowerSpectrum)), k) < 0) /*extra 3 bits of headroom for MA filter in getEnvelope*/ + for (k = 1; k <= nSamples-2; k++) { - k = sub(k, add(16-3, norm_s(floorPowerSpectrum))); /*extra 3 bits of headroom for MA filter in getEnvelope*/ - *powerSpec_exp = add(*powerSpec_exp, k); - s1 = add(s1, k); - s2 = add(s2, k); - k = add(16-3, norm_s(floorPowerSpectrum)); + x = mdctSpec[k] * mdctSpec[k] + mdstSpec[k] * mdstSpec[k]; + powerSpec[k] = max(floorPowerSpectrum, x); } - L_tmp_floor = L_shl(L_deposit_l(floorPowerSpectrum), k); + powerSpec[0] = 0.5f*powerSpec[1]; + powerSpec[nSamples-1] = 0.5f*powerSpec[nSamples-2]; - tmp = sub(nSamples, 2); - FOR (k = 1; k <= tmp; k++) - { - x = Mpy_32_32(mdctSpec[k], mdctSpec[k]); /*Q31,2*mdctSpec_exp*/ - - L_tmp = Mpy_32_32(mdstSpec[k], mdstSpec[k]); /*Q31,2*mdstSpec_exp*/ - x = L_add(L_shr(x,s1), L_shr(L_tmp,s2)); /*Q31,*powerSpec_exp*/ - - powerSpec[k] = L_max(L_tmp_floor, x); - move32(); - } - - powerSpec[0] = L_shr(powerSpec[1], 1); - move32(); - powerSpec[nSamples-1] = L_shr(powerSpec[nSamples-2], 1); - move32(); + return; } + diff --git a/src/libs/libevs/lib_dec/transition_dec.cpp b/src/libs/libevs/lib_dec/transition_dec.cpp new file mode 100644 index 00000000..871d91a1 --- /dev/null +++ b/src/libs/libevs/lib_dec/transition_dec.cpp @@ -0,0 +1,743 @@ +/*==================================================================================== + EVS Codec 3GPP TS26.443 Nov 13, 2018. Version 12.11.0 / 13.7.0 / 14.3.0 / 15.1.0 + ====================================================================================*/ + +#include +#include "options.h" +#include "cnst.h" +#include "rom_com.h" +#include "prot.h" + +/*----------------------------------------------------------------------* + * Local functions + *----------------------------------------------------------------------*/ + +static void tc_dec( Decoder_State *st, const short L_frame, float exc[], short *T0, short *T0_frac, const short i_subfr, + const short tc_subfr, short *position, const long core_brate, float bwe_exc[] ); + +/*-------------------------------------------------------------------* + * transition_dec() + * + * Principal function for TC decoding + *-------------------------------------------------------------------*/ + +void transition_dec( + Decoder_State *st, /* i/o: decoder state structure */ + const long core_brate, /* i : core bitrate */ + const short Opt_AMR_WB, /* i : flag indicating AMR-WB IO mode */ + const short L_frame, /* i : length of the frame */ + const short i_subfr, /* i : subframe index */ + const short coder_type, /* i : coder type */ + const short tc_subfr, /* i : TC subframe index */ + short *Jopt_flag, /* i : joint optimization flag */ + float *exc, /* o : excitation signal */ + short *T0, /* o : close loop integer pitch */ + short *T0_frac, /* o : close loop fractional part of the pitch */ + short *T0_min, /* i/o: delta search min for sf 2 & 4 */ + short *T0_max, /* i/o: delta search max for sf 2 & 4 */ + float **pt_pitch, /* o : floating pitch values */ + short *position, /* i/o: first glottal impulse position in frame */ + float *bwe_exc /* o : excitation for SWB TBE */ +) +{ + short i, pit_flag, pit_start, pit_limit, index, nBits; + short limit_flag; + short offset; + + /* Set limit_flag to 0 for restrained limits, and 1 for extended limits */ + limit_flag = 0; + + /*---------------------------------------------------------------------* + * zero adaptive contribution (glottal shape codebook search not + * in first subframe(s) ) + *---------------------------------------------------------------------*/ + + if( tc_subfr > i_subfr+TC_0_192 ) + { + set_f(&exc[i_subfr], 0, L_SUBFR); + + if( L_frame == L_FRAME ) + { + set_f(&bwe_exc[i_subfr*HIBND_ACB_L_FAC], 0, (short) (L_SUBFR*HIBND_ACB_L_FAC)); /* set past excitation buffer to 0 */ + } + else + { + set_f(&bwe_exc[i_subfr*2], 0, (short) (L_SUBFR*2)); /* set past excitation buffer to 0 */ + } + + *T0 = L_SUBFR; + *T0_frac = 0; + **pt_pitch = (float)L_SUBFR; + } + + /*---------------------------------------------------------------------* + * glottal shape codebook search + *---------------------------------------------------------------------*/ + + else if( (tc_subfr-i_subfr >= 0) && (tc_subfr-i_subfr <= TC_0_192) ) + { + set_f( exc-L_EXC_MEM, 0, L_EXC_MEM ); /* set past excitation buffer to 0 */ + + if( L_frame == L_FRAME ) + { + set_f( bwe_exc-PIT_MAX*HIBND_ACB_L_FAC, 0, PIT_MAX*HIBND_ACB_L_FAC); /* set past excitation buffer to 0 */ + } + else + { + set_f( bwe_exc-PIT16k_MAX*2, 0, PIT16k_MAX*2); /* set past excitation buffer to 0 */ + } + + /* glottal shape codebook contribution construction */ + tc_dec( st, L_frame, exc, T0, T0_frac, i_subfr, tc_subfr, position, core_brate, bwe_exc ); + + **pt_pitch = (float)(*T0) + (float)(*T0_frac)/4.0f; /* save subframe pitch values */ + *Jopt_flag = 1; + } + + /*---------------------------------------------------------------------* + * Regular ACELP Decoding using GENERIC type decoder + * (all subframes following subframe with glottal shape codebook seach) + * - search the position of the 2nd glottal impulse in case that the first + * one is in the 1st subframe (different adaptive contribution + * construction and the pitch period coding is used) + *---------------------------------------------------------------------*/ + + else if (tc_subfr < i_subfr) + { + if( L_frame == L_FRAME ) + { + *Jopt_flag = 1; + + if( (i_subfr - tc_subfr >= L_SUBFR) && (i_subfr - tc_subfr <= L_SUBFR + TC_0_192) ) + { + pit_flag = 0; + } + else + { + pit_flag = L_SUBFR; + } + + if( tc_subfr == TC_0_0 ) + { + if( i_subfr == L_SUBFR ) + { + limit_T0( L_FRAME, 8, pit_flag, limit_flag, *T0, 0, T0_min, T0_max ); + } + + pit_flag = 1; + } + + /*-----------------------------------------------------------------* + * get number of bits for pitch decoding + *-----------------------------------------------------------------*/ + + nBits = ACB_bits_tbl[BIT_ALLOC_IDX(core_brate, TRANSITION, i_subfr, TC_SUBFR2IDX(tc_subfr))]; + + /*------------------------------------------------------------* + * first glottal impulse is in the 1st subframe + *------------------------------------------------------------*/ + + if( (i_subfr == L_SUBFR) && (tc_subfr >= TC_0_128) ) + { + /*--------------------------------------------------------* + * second glottal impulse is in the 3rd or 4th subframe + * - build exc[] in 2nd subframe + *--------------------------------------------------------*/ + + *T0 = 2*L_SUBFR; + *T0_frac = 0; + *Jopt_flag = 0; + + /* set adaptive part of exciation for curent subframe to 0 */ + set_f( &exc[i_subfr], 0, (short)(L_SUBFR+1) ); + + set_f( &bwe_exc[i_subfr*HIBND_ACB_L_FAC], 0, (short)(L_SUBFR*HIBND_ACB_L_FAC) ); + } + else if( (i_subfr == L_SUBFR) && (tc_subfr == TC_0_64) ) + { + /*--------------------------------------------------------* + * second glottal impulse is in the 2nd subframe, + * - build exc[] in 2nd subframe + *--------------------------------------------------------*/ + + if( PIT_MIN > (*position) ) + { + pit_start = L_SUBFR - (*position); + } + else + { + pit_start = PIT_MIN; + } + + if( pit_start < PIT_MIN ) + { + pit_start = PIT_MIN; + } + + pit_limit = 2*pit_start + (*position); + + /* 7 bit pitch DECODER */ + index = (short)get_next_indice( st, nBits ); + + *T0 = (short) (floor( pit_start + index/2 )); + *T0_frac = (index - (*T0 - pit_start)*2 ) * 2; + limit_T0( L_FRAME, 8, pit_flag, limit_flag, *T0, 0, T0_min, T0_max ); /* find T0_min and T0_max */ + + /* Find the adaptive codebook vector - ACELP long-term prediction */ + pred_lt4( &exc[i_subfr], &exc[i_subfr], *T0, *T0_frac, L_SUBFR+1, inter4_2, L_INTERPOL2, PIT_UP_SAMP ); + + offset = tbe_celp_exc_offset(*T0, *T0_frac); + for (i=0; i (PIT_MAX<<2)+2 ) + { + *T0 = L_SUBFR; + *T0_frac = 0; + st->BER_detect = 1; + } + + /* Find the adaptive codebook vector. ACELP long-term prediction */ + pred_lt4( &exc[i_subfr], &exc[i_subfr], *T0, *T0_frac, L_SUBFR+1, inter4_2, L_INTERPOL2, PIT_UP_SAMP ); + + offset = tbe_celp_exc_offset(*T0, *T0_frac); + for (i=0; iBER_detect ); + + /* Find the adaptive codebook vector */ + pred_lt4( &exc[i_subfr], &exc[i_subfr], *T0, *T0_frac, L_SUBFR+1, inter4_2, L_INTERPOL2, PIT_UP_SAMP ); + + offset = tbe_celp_exc_offset(*T0, *T0_frac); + for (i=0; i= 2*L_SUBFR) && (i_subfr == 3*L_SUBFR) ) + { + (*pt_pitch) -= 3; + **pt_pitch = (float)(*T0) + (float)(*T0_frac)/4.0f; + (*pt_pitch)++; + **pt_pitch = (float)(*T0) + (float)(*T0_frac)/4.0f; + (*pt_pitch)++; + **pt_pitch = (float)(*T0) + (float)(*T0_frac)/4.0f; + (*pt_pitch)++; + } + else if( (tc_subfr == L_SUBFR) && (i_subfr == 2*L_SUBFR) ) + { + (*pt_pitch) -= 2; + **pt_pitch = (float)(*T0) + (float)(*T0_frac)/4.0f; + (*pt_pitch)++; + **pt_pitch = (float)(*T0) + (float)(*T0_frac)/4.0f; + (*pt_pitch)++; + } + else if( (tc_subfr == TC_0_64) && (i_subfr == L_SUBFR) ) + { + (*pt_pitch) -= 1; + **pt_pitch = (float)(*T0) + (float)(*T0_frac)/4.0f; + (*pt_pitch)++; + } + else if( (tc_subfr == TC_0_128) && (i_subfr == 2*L_SUBFR) ) + { + (*pt_pitch) -= 2; + **pt_pitch = (float)(*T0) + (float)(*T0_frac)/4.0f; + (*pt_pitch)++; + **pt_pitch = (float)(*T0) + (float)(*T0_frac)/4.0f; + (*pt_pitch)++; + } + else if( (tc_subfr == TC_0_192) && (i_subfr == 3*L_SUBFR) ) + { + (*pt_pitch) -= 3; + **pt_pitch = (float)(*T0) + (float)(*T0_frac)/4.0f; + (*pt_pitch)++; + **pt_pitch = (float)(*T0) + (float)(*T0_frac)/4.0f; + (*pt_pitch)++; + **pt_pitch = (float)(*T0) + (float)(*T0_frac)/4.0f; + (*pt_pitch)++; + } + + } + else /* L_frame == L_FRAME16k */ + { + if( i_subfr >= 2*L_SUBFR ) + { + limit_flag = 1; + } + + if( i_subfr - tc_subfr == L_SUBFR ) + { + limit_T0( L_FRAME16k, 8, 0, limit_flag, *T0, *T0_frac, T0_min, T0_max ); /* find T0_min and T0_max */ + } + + /*-----------------------------------------------------------------* + * get number of bits and index for pitch decoding + *-----------------------------------------------------------------*/ + + nBits = ACB_bits_16kHz_tbl[BIT_ALLOC_IDX_16KHZ(core_brate, coder_type, i_subfr, TC_SUBFR2IDX_16KHZ(tc_subfr))]; + + index = (short)get_next_indice( st, nBits ); + + /*-----------------------------------------------------------------* + * Find adaptive part of excitation, encode pitch period + *-----------------------------------------------------------------*/ + + if( nBits == 10 ) + { + pit16k_Q_dec( index, nBits, limit_flag, T0, T0_frac, T0_min, T0_max, &st->BER_detect ); + } + else if( nBits == 8 ) /* tc_subfr==0 && i_subfr==L_SUBFR */ + { + /*-----------------------------------------------------------------------------* + * The pitch range is encoded absolutely with 8 bits and is divided as follows: + * PIT16k_MIN to PIT16k_FR2_TC0_2SUBFR-1 resolution 1/4 (frac = 0,1,2 or 3) + * PIT16k_FR2_TC0_2SUBFR to 2*L_SUBFR resolution 1/2 (frac = 0 or 2) + *-----------------------------------------------------------------------------*/ + + if( index < (PIT16k_FR2_TC0_2SUBFR-PIT16k_MIN)*4 ) + { + *T0 = PIT16k_MIN + (index/4); + *T0_frac = index - (*T0 - PIT16k_MIN)*4; + } + else + { + index -= (PIT16k_FR2_TC0_2SUBFR-PIT16k_MIN)*4; + *T0 = PIT16k_FR2_TC0_2SUBFR + (index/2); + *T0_frac = index - (*T0 - PIT16k_FR2_TC0_2SUBFR)*2; + (*T0_frac) *= 2; + } + + /* biterror detection mechanism */ + if( ((*T0<<2) + *T0_frac) > ((2*L_SUBFR)<<2) ) + { + *T0 = L_SUBFR; + *T0_frac = 0; + st->BER_detect = 1; + } + } + else if( nBits == 6 ) + { + delta_pit_dec( 4, index, T0, T0_frac, *T0_min ); + } + if( nBits == 6 ) + { + limit_T0( L_FRAME16k, 8, L_SUBFR, limit_flag, *T0, *T0_frac, T0_min, T0_max ); /* find T0_min and T0_max */ + } + + /*-----------------------------------------------------------------* + * - find the adaptive codebook vector + * - LP filtering of the adaptive excitation (if non-zero) + *-----------------------------------------------------------------*/ + + if( (i_subfr == L_SUBFR) && (*T0 == 2*L_SUBFR) ) + { + /* no adaptive excitation in the second subframe */ + set_f( &exc[i_subfr], 0, L_SUBFR+1 ); + + get_next_indice( st, 1 ); /* this bit is actually not needed */ + + set_f( &bwe_exc[i_subfr * 2], 0, L_SUBFR * 2 ); + } + else + { + /* Find the adaptive codebook vector - ACELP long-term prediction */ + pred_lt4( &exc[i_subfr], &exc[i_subfr], *T0, *T0_frac, L_SUBFR+1, inter4_2, L_INTERPOL2, PIT_UP_SAMP); + + for (i=0; i= 0) && (i < L_SUBFR) ) + { + exc[i+i_subfr] = glottal_cdbk[(imp_shape)*L_IMPULSE+i-imp_pos+L_IMPULSE2]*gain_trans; + } + } + + /*--------------------------------------------------------------* + * adapt. search of the second impulse in the same subframe + * (when appears) + *--------------------------------------------------------------*/ + + pred_lt4_tc( exc, *T0, *T0_frac, inter4_2, imp_pos, i_subfr ); + + if( L_frame == L_FRAME ) + { + interp_code_5over2(&exc[i_subfr], &bwe_exc[i_subfr * HIBND_ACB_L_FAC], L_SUBFR); + } + else + { + interp_code_4over2(&exc[i_subfr], &bwe_exc[i_subfr * 2], L_SUBFR); + } + + *position = imp_pos + i_subfr; + + return; +} +/*-------------------------------------------------------------------* + * tc_classif() + * + * TC subframe classification decoding + *-------------------------------------------------------------------*/ + +short tc_classif( + Decoder_State *st, /* i/o: decoder state structure */ + const short L_frame /* i : length of the frame */ +) +{ + short tc_subfr, indice; + + if( L_frame == L_FRAME ) + { + if ( get_next_indice( st, 1 ) ) + { + tc_subfr = TC_0_0; + } + else + { + if ( get_next_indice( st, 1 ) ) + { + tc_subfr = 0; + + if ( get_next_indice( st, 1 ) ) + { + tc_subfr = TC_0_192; + } + else + { + if ( get_next_indice( st, 1 ) ) + { + tc_subfr = TC_0_64; + } + else + { + tc_subfr = TC_0_128; + } + } + } + else + { + if ( get_next_indice( st, 1 ) ) + { + tc_subfr = L_SUBFR; + } + else + { + if ( get_next_indice( st, 1 ) ) + { + tc_subfr = 2*L_SUBFR; + } + else + { + tc_subfr = 3*L_SUBFR; + } + } + } + } + } + else /* L_frame == L_FRAME16k */ + { + indice = (short) get_next_indice( st, 2 ); + + if( indice < 3 ) + { + tc_subfr = indice * L_SUBFR; + } + else + { + if( get_next_indice( st, 1 ) == 0 ) + { + tc_subfr = 3*L_SUBFR; + } + else + { + tc_subfr = 4*L_SUBFR; + } + } + } + + return( tc_subfr ); +} diff --git a/src/libs/libevs/lib_dec/transition_dec_fx.cpp b/src/libs/libevs/lib_dec/transition_dec_fx.cpp deleted file mode 100755 index 3f5792ab..00000000 --- a/src/libs/libevs/lib_dec/transition_dec_fx.cpp +++ /dev/null @@ -1,925 +0,0 @@ -/*==================================================================================== - EVS Codec 3GPP TS26.442 Apr 03, 2018. Version 12.11.0 / 13.6.0 / 14.2.0 - ====================================================================================*/ - -#include "options.h" /* Compilation switches */ -#include "cnst_fx.h" /* Common constants */ -#include "rom_com_fx.h" /* Static table prototypes */ -#include "prot_fx.h" /* Function prototypes */ -#include "stl.h" - -/*----------------------------------------------------------------------* - * Local functions - *----------------------------------------------------------------------*/ - -static void tc_dec_fx( Decoder_State_fx *st_fx, const Word16 L_frame,Word16 exc[], Word16 *T0,Word16 *T0_frac, const Word16 i_subfr, - const Word16 tc_subfr, Word16 *position, const Word32 core_brate, Word16 bwe_exc[], Word16 *Q_exc ); - -/*======================================================================*/ -/* FUNCTION : transition_dec_fx() */ -/*----------------------------------------------------------------------*/ -/* PURPOSE : Principal function for TC decoding */ -/* */ -/*----------------------------------------------------------------------*/ -/* GLOBAL INPUT ARGUMENTS : */ -/* const Word32 core_brate, : core bitrate Q0 */ -/* _ (Word16) L_frame_fx : length of the frame Q0 */ -/* _ (Word16[]) pitch_buf_fx : floating pitch values for each subframe Q6*/ -/* _ (Word16[]) voice_factors_fx: frame error rate Q15 */ -/*-----------------------------------------------------------------------*/ -/* OUTPUT ARGUMENTS : */ -/* _ (Word16[]) exc_fx : adapt. excitation exc (Q0) */ -/* _ (Word16[]) exc2_fx : adapt. excitation/total exc (Q0) */ -/*-----------------------------------------------------------------------*/ - - -/*-----------------------------------------------------------------------*/ -/* RETURN ARGUMENTS : */ -/* _ None */ -/*=======================================================================*/ - -void transition_dec_fx( - Decoder_State_fx *st_fx, /* i/o: decoder state structure */ - const Word32 core_brate, /* i : core bitrate */ - const Word16 Opt_AMR_WB, /* i : flag indicating AMR-WB IO mode */ - const Word16 L_frame, /* i : length of the frame */ - const Word16 i_subfr, /* i : subframe index */ - const Word16 coder_type, /* i : coder type */ - const Word16 tc_subfr, /* i : TC subframe index */ - Word16 *Jopt_flag, /* i : joint optimization flag */ - Word16 *exc, /* o : excitation signal */ - Word16 *T0, /* o : close loop integer pitch */ - Word16 *T0_frac, /* o : close loop fractional part of the pitch */ - Word16 *T0_min, /* i/o: delta search min for sf 2 & 4 */ - Word16 *T0_max, /* i/o: delta search max for sf 2 & 4 */ - Word16 **pt_pitch, /* o : floating pitch values */ - Word16 *position, /* i/o: first glottal impulse position in frame */ - Word16 *bwe_exc, /* o : excitation for SWB TBE */ - Word16 *Q_exc /*i/o : scaling of excitation */ -) -{ - Word16 pit_flag, pit_start, pit_limit, index, nBits; - Word16 i, offset,temp,tmp; - Word16 limit_flag; - - /* Set limit_flag to 0 for restrained limits, and 1 for extended limits */ - limit_flag = 0; - - /*---------------------------------------------------------------------* - * zero adaptive contribution (glottal shape codebook search not - * in first subframe(s) ) - *---------------------------------------------------------------------*/ - IF(sub(tc_subfr, add(i_subfr,TC_0_192)) > 0) - { - set16_fx(&exc[i_subfr], 0, L_SUBFR); - - IF( sub(L_frame,L_FRAME) == 0 ) - { - set16_fx(&bwe_exc[i_subfr*HIBND_ACB_L_FAC], 0, (Word16) (L_SUBFR*HIBND_ACB_L_FAC)); /* set past excitation buffer to 0 */ - } - ELSE - { - set16_fx(&bwe_exc[i_subfr*2], 0, (Word16) (L_SUBFR*2)); /* set past excitation buffer to 0 */ - } - - *T0 = L_SUBFR; - move16(); - *T0_frac = 0; - move16(); - **pt_pitch = L_SUBFR_Q6; - move16(); - } - - /*---------------------------------------------------------------------* - * glottal shape codebook search - *---------------------------------------------------------------------*/ - - ELSE IF(((sub(tc_subfr,i_subfr) >= 0) && (sub(tc_subfr,i_subfr) <= TC_0_192) )) - { - set16_fx( exc-L_EXC_MEM, 0, L_EXC_MEM ); /* set past excitation buffer to 0 */ - - IF( sub(L_frame,L_FRAME) == 0 ) - { - set16_fx( bwe_exc-PIT_MAX*HIBND_ACB_L_FAC, 0, PIT_MAX*HIBND_ACB_L_FAC); /* set past excitation buffer to 0 */ - } - ELSE - { - set16_fx( bwe_exc-PIT16k_MAX*2, 0, PIT16k_MAX*2); /* set past excitation buffer to 0 */ - } - - /* glottal shape codebook contribution construction */ - tc_dec_fx( st_fx, L_frame, exc, T0, T0_frac, i_subfr, tc_subfr, position, core_brate, bwe_exc, Q_exc ); - - **pt_pitch = shl(add(shl(*T0,2),*T0_frac),4); - move16(); /* save subframe pitch values Q6 */ - - *Jopt_flag = 1; - move16(); - } - - /*---------------------------------------------------------------------* - * Regular ACELP Decoding using GENERIC type decoder - * (all subframes following subframe with glottal shape codebook seach) - * - search the position of the 2nd glottal impulse in case that the first - * one is in the 1st subframe (different adaptive contribution - * construction and the pitch period coding is used) - *---------------------------------------------------------------------*/ - - ELSE IF ( sub(tc_subfr,i_subfr) < 0) - { - IF( sub(L_frame,L_FRAME) == 0) - { - *Jopt_flag = 1; - move16(); - test(); - IF( (sub(sub(i_subfr,tc_subfr),L_SUBFR) >= 0) && (sub(sub(i_subfr,tc_subfr),L_SUBFR + TC_0_192) <= 0) ) - { - pit_flag = 0; - move16(); - } - ELSE - { - pit_flag = L_SUBFR; - move16(); - } - IF( sub(tc_subfr,TC_0_0) == 0) - { - IF( sub(i_subfr,L_SUBFR) == 0 ) - { - limit_T0_fx( L_FRAME, 8, pit_flag, limit_flag, *T0, 0, T0_min, T0_max ); - } - pit_flag = 1; - move16(); - } - - /*-----------------------------------------------------------------* - * get number of bits for pitch decoding - *-----------------------------------------------------------------*/ - - nBits = ACB_bits_tbl[BIT_ALLOC_IDX_fx(core_brate, TRANSITION, i_subfr, TC_SUBFR2IDX_fx(tc_subfr))]; - move16(); - - /*------------------------------------------------------------* - * first glottal impulse is in the 1st subframe - *------------------------------------------------------------*/ - test(); - test(); - test(); - test(); - test(); - test(); - IF( (sub(i_subfr,L_SUBFR) == 0) && (sub(tc_subfr,TC_0_128) >= 0) ) - { - /*--------------------------------------------------------* - * second glottal impulse is in the 3rd or 4th subframe - * - build exc[] in 2nd subframe - *--------------------------------------------------------*/ - - *T0 = 2*L_SUBFR; - move16(); - *T0_frac = 0; - move16(); - *Jopt_flag = 0; - move16(); - - /* set adaptive part of exciation for curent subframe to 0 */ - set16_fx( &exc[i_subfr], 0, (Word16)(L_SUBFR+1) ); - set16_fx( &bwe_exc[i_subfr*HIBND_ACB_L_FAC], 0, (Word16)(L_SUBFR*HIBND_ACB_L_FAC) ); - - } - ELSE IF( (sub(i_subfr,L_SUBFR) == 0) && (sub(tc_subfr,TC_0_64) == 0) ) - { - /*--------------------------------------------------------* - * second glottal impulse is in the 2nd subframe, - * - build exc[] in 2nd subframe - *--------------------------------------------------------*/ - pit_start = PIT_MIN; - move16(); - if (sub(PIT_MIN,(*position)) > 0) - { - pit_start = sub(L_SUBFR, *position); - } - - pit_start = s_max(pit_start, PIT_MIN ); - pit_limit = add(shl(pit_start,1), *position); - - /* 7 bit pitch DECODER */ - index = (Word16)get_next_indice_fx( st_fx, nBits ); - - *T0 = add(pit_start, shr((index),1)); - move16(); - *T0_frac = shl(sub((index),shl(sub(*T0, pit_start),1)),1); - move16(); - - limit_T0_fx( L_FRAME, 8, pit_flag, limit_flag, *T0, 0, T0_min, T0_max ); /* find T0_min and T0_max */ - - /* Find the adaptive codebook vector - ACELP long-term prediction */ - pred_lt4(&exc[i_subfr], &exc[i_subfr], *T0, *T0_frac, L_SUBFR+1, pitch_inter4_2, L_INTERPOL2, PIT_UP_SAMP); - offset = tbe_celp_exc_offset(*T0, *T0_frac, L_frame); - - move16(); - move16(); /* penality for 2 ptrs initialization */ - - FOR (i=0; i 0 ) - { - *T0 = L_SUBFR; - move16(); - *T0_frac = 0; - move16(); - st_fx->BER_detect = 1; - move16(); - } - - /* Find the adaptive codebook vector. ACELP long-term prediction */ - pred_lt4(&exc[i_subfr], &exc[i_subfr], *T0, *T0_frac, L_SUBFR+1, pitch_inter4_2, L_INTERPOL2, PIT_UP_SAMP); - offset = tbe_celp_exc_offset(*T0, *T0_frac, L_frame); - move16(); - move16(); /* penality for 2 ptrs initialization */ - FOR (i=0; iBER_detect ); - - /* Find the adaptive codebook vector */ - pred_lt4(&exc[i_subfr], &exc[i_subfr], *T0, *T0_frac, L_SUBFR+1, pitch_inter4_2, L_INTERPOL2, PIT_UP_SAMP); - offset = tbe_celp_exc_offset(*T0, *T0_frac, L_frame); - move16(); - move16(); /* penality for 2 ptrs initialization */ - FOR (i=0; i= 0) && (sub(i_subfr,3*L_SUBFR) == 0) ) - { - tmp = shl(add(shl(*T0,2),*T0_frac),4); - (*pt_pitch) -= 3; - move16(); - **pt_pitch = tmp; - move16(); /*Q6*/ - (*pt_pitch)++; - **pt_pitch = tmp; - move16(); /*Q6*/ - (*pt_pitch) ++; - move16(); - **pt_pitch = tmp; - move16(); /*Q6*/ - (*pt_pitch) ++; - move16(); - } - ELSE IF( (sub(tc_subfr,L_SUBFR) == 0) && (sub(i_subfr,2*L_SUBFR) == 0) ) - { - tmp = shl(add(shl(*T0,2),*T0_frac),4); - (*pt_pitch) -= 2; - move16(); - **pt_pitch = tmp; - move16(); /*Q6*/ - (*pt_pitch)++; - **pt_pitch = tmp; - move16(); /*Q6*/ - (*pt_pitch) ++; - move16(); - - } - ELSE IF( (sub(tc_subfr,TC_0_64) == 0) && (sub(i_subfr,L_SUBFR) == 0) ) - { - tmp = shl(add(shl(*T0,2),*T0_frac),4); - (*pt_pitch) -= 1; - move16(); - **pt_pitch = tmp; - move16(); /*Q6*/ - (*pt_pitch)++; - } - ELSE IF( (sub(tc_subfr,TC_0_128) == 0) && (sub(i_subfr,2*L_SUBFR) == 0) ) - { - tmp = shl(add(shl(*T0,2),*T0_frac),4); - (*pt_pitch) -= 2; - move16(); - **pt_pitch = tmp; - move16(); /*Q6*/ - (*pt_pitch)++; - **pt_pitch = tmp; - move16(); /*Q6*/ - (*pt_pitch) ++; - move16(); - } - ELSE IF( (sub(tc_subfr,TC_0_192) == 0) && (sub(i_subfr,3*L_SUBFR) == 0) ) - { - tmp = shl(add(shl(*T0,2),*T0_frac),4); - (*pt_pitch) -= 3; - move16(); - **pt_pitch = tmp; - move16(); /*Q6*/ - (*pt_pitch)++; - **pt_pitch = tmp; - move16(); /*Q6*/ - (*pt_pitch) ++; - move16(); - **pt_pitch = tmp; - move16(); /*Q6*/ - (*pt_pitch) ++; - move16(); - } - } - ELSE /* L_frame == L_FRAME16k */ - { - test(); - if( sub(i_subfr,2*L_SUBFR) >= 0) - { - limit_flag = 1; - move16(); - } - - IF( sub(sub(i_subfr, tc_subfr), L_SUBFR) == 0 ) - { - limit_T0_fx( L_FRAME16k, 8, 0, limit_flag, *T0, *T0_frac, T0_min, T0_max ); - } - - /*-----------------------------------------------------------------* - * get number of bits and index for pitch decoding - *-----------------------------------------------------------------*/ - - nBits = ACB_bits_16kHz_tbl[BIT_ALLOC_IDX_16KHZ_fx(core_brate, coder_type, i_subfr, TC_SUBFR2IDX_16KHZ_fx(tc_subfr))]; - move16(); - - index = (Word16)get_next_indice_fx( st_fx, nBits ); - - /*-----------------------------------------------------------------* - * Find adaptive part of excitation, encode pitch period - *-----------------------------------------------------------------*/ - - IF( sub(nBits,10) == 0 ) - { - pit16k_Q_dec_fx( index, nBits, limit_flag, T0, T0_frac, T0_min, T0_max, &st_fx->BER_detect ); - } - ELSE IF( sub(nBits,8) == 0 ) /* tc_subfr==0 && i_subfr==L_SUBFR */ - { - /*-----------------------------------------------------------------------------* - * The pitch range is encoded absolutely with 8 bits and is divided as follows: - * PIT16k_MIN to PIT16k_FR2_TC0_2SUBFR-1 resolution 1/4 (frac = 0,1,2 or 3) - * PIT16k_FR2_TC0_2SUBFR to 2*L_SUBFR resolution 1/2 (frac = 0 or 2) - *-----------------------------------------------------------------------------*/ - - IF( sub(index,(PIT16k_FR2_TC0_2SUBFR-PIT16k_MIN)*4) < 0 )/*(PIT16k_FR2_TC0_2SUBFR-PIT16k_MIN)*4*/ - { - *T0 = add(PIT16k_MIN,shr(index,2)); - move16(); - temp = shl(sub(*T0,PIT16k_MIN),2); - move16(); - *T0_frac = sub(index,temp); - move16(); - } - ELSE - { - index = sub(index,(PIT16k_FR2_TC0_2SUBFR-PIT16k_MIN)*4); /* (PIT16k_FR2_TC0_2SUBFR-PIT16k_MIN)*4 */ - *T0 = add(PIT16k_FR2_TC0_2SUBFR,shr(index,1)); - move16(); - temp = shl(sub(*T0,PIT16k_FR2_TC0_2SUBFR),1); - move16(); - *T0_frac = shl(sub(index,temp),1); - move16(); - } - - /* biterror detection mechanism */ - IF( sub(add((*T0<<2),*T0_frac),((2*L_SUBFR)<<2)) > 0 ) - { - *T0 = L_SUBFR; - move16(); - *T0_frac = 0; - move16(); - st_fx->BER_detect = 1; - move16(); - } - } - ELSE IF( sub(nBits,6) == 0 ) - { - delta_pit_dec_fx( 4, index, T0, T0_frac, *T0_min ); - } - IF( sub(nBits,6) == 0 ) - { - limit_T0_fx( L_FRAME16k, 8, L_SUBFR, limit_flag, *T0, *T0_frac, T0_min, T0_max ); /* find T0_min and T0_max */ - } - - /*-----------------------------------------------------------------* - * - find the adaptive codebook vector - * - LP filtering of the adaptive excitation (if non-zero) - *-----------------------------------------------------------------*/ - test(); - IF( (sub(i_subfr,L_SUBFR) == 0) && (sub(*T0,2*L_SUBFR) == 0) ) - { - /* no adaptive excitation in the second subframe */ - set16_fx( &exc[i_subfr], 0, L_SUBFR+1 ); - get_next_indice_fx( st_fx, 1 ); /* this bit is actually not needed */ - set16_fx( &bwe_exc[i_subfr * 2], 0, L_SUBFR * 2 ); - } - ELSE - { - /* Find the adaptive codebook vector - ACELP long-term prediction */ - pred_lt4(&exc[i_subfr], &exc[i_subfr], *T0, *T0_frac, L_SUBFR+1, pitch_inter4_2, L_INTERPOL2, PIT_UP_SAMP); - offset = tbe_celp_exc_offset(*T0, *T0_frac, L_frame); - move16(); - move16(); /* penalty for 2 ptrs initialization */ - FOR (i=0; i +#include "options.h" +#include "prot.h" +#include "rom_com.h" +#include "cnst.h" + +/*-------------------------------------------------------------------* + * updt_dec() + * + * Common updates (all frame types) + *-------------------------------------------------------------------*/ + +void updt_dec( + Decoder_State *st, /* i/o: state structure */ + const short L_frame, /* i : length of the frame */ + const short coder_type, /* i : coding type */ + const float *old_exc, /* i : buffer of excitation */ + const float *pitch_buf, /* i : floating pitch values for each subframe */ + const float Es_pred, /* i : predicited scaled innovation energy */ + const float *Aq, /* i : A(z) quantized for all subframes */ + const float *lsf_new, /* i : current frame LSF vector */ + const float *lsp_new, /* i : current frame LSP vector */ + const float voice_factors[], /* i : voicing factors */ + const float *old_bwe_exc, /* i : buffer of excitation */ + const float *gain_buf +) +{ + short i; + short tmp_seed; + + /* update old excitation buffer */ + mvr2r( &old_exc[L_frame], st->old_exc, L_EXC_MEM_DEC); + if( !st->Opt_AMR_WB ) + { + mvr2r( &old_bwe_exc[L_FRAME32k], st->old_bwe_exc, PIT16k_MAX * 2 ); + } + + /* update old LSP and LSF vector */ + mvr2r( lsf_new, st->lsf_old, M ); + mvr2r( lsp_new, st->lsp_old, M ); + + /* update last coding type */ + st->last_coder_type = coder_type; + if ( coder_type == INACTIVE || (st->bpf_off == 1 && coder_type != AUDIO && coder_type != TRANSITION) ) + { + /* overwrite previous coding type to help FEC */ + st->last_coder_type = UNVOICED; + } + + if( (coder_type != AUDIO || st->Last_GSC_noisy_speech_flag != 0) && st->Last_GSC_pit_band_idx > 0 ) + { + st->Last_GSC_pit_band_idx = 0; /*The temporal contribution of the GSC is meaningless after 1 frame lost for inactive & unvoiced content */ + } + /* this ensures that st->last_coder_type is never set to INACTIVE in case of AVQ inactive because the FEC does not distinguish between GSC inactive and AVQ inactive */ + + if ( coder_type == INACTIVE && st->total_brate > ACELP_24k40 ) + { + st->last_coder_type = GENERIC; + } + + if( st->Opt_AMR_WB && coder_type == INACTIVE && st->core_brate != SID_1k75 && st->core_brate != FRAME__NO_DATA ) + { + /* overwrite previous coding type to help FEC */ + st->last_coder_type = UNVOICED; + st->last_voice_factor = voice_factors[NB_SUBFR-1]; + } + + if( !st->Opt_AMR_WB ) + { + /* update voicing factor of TBE to help FEC */ + if(st->L_frame == L_FRAME ) + { + st->last_voice_factor = voice_factors[NB_SUBFR-1]; + } + else /* L_frame == L_FRAME16k */ + { + st->last_voice_factor = voice_factors[NB_SUBFR16k-1]; + } + } + + if ( coder_type != AUDIO && coder_type != INACTIVE ) + { + st->noise_lev = NOISE_LEVEL_SP3; + set_f( st->old_y_gain, 0.0f, MBANDS_GN ); + + for( i = 0; i < L_FRAME; i++ ) + { + tmp_seed = st->seed_tcx; + st->Last_GSC_spectrum[i] = own_random( &tmp_seed ) / 32768.0f; + } + } + + /* update last GSC SWB speech flag for FEC */ + st->Last_GSC_noisy_speech_flag = st->GSC_noisy_speech; + + /* update counter for FEC pitch estimate */ + st->upd_cnt++; + if( st->upd_cnt > MAX_UPD_CNT ) + { + st->upd_cnt = MAX_UPD_CNT; + } + + mvr2r( &st->old_pitch_buf[L_frame/L_SUBFR], st->old_pitch_buf, L_frame/L_SUBFR ); + mvr2r( pitch_buf, &st->old_pitch_buf[L_frame/L_SUBFR], L_frame/L_SUBFR ); + mvr2r( &st->mem_pitch_gain[2], &st->mem_pitch_gain[L_frame/L_SUBFR+2], L_frame/L_SUBFR ); + + if( L_frame == L_FRAME ) + { + st->mem_pitch_gain[2] = gain_buf[3]; + st->mem_pitch_gain[3] = gain_buf[2]; + st->mem_pitch_gain[4] = gain_buf[1]; + st->mem_pitch_gain[5] = gain_buf[0]; + } + else + { + st->mem_pitch_gain[2] = gain_buf[4]; + st->mem_pitch_gain[3] = gain_buf[3]; + st->mem_pitch_gain[4] = gain_buf[2]; + st->mem_pitch_gain[5] = gain_buf[1]; + st->mem_pitch_gain[6] = gain_buf[0]; + } + + + /* FEC - update adaptive LSF mean vector */ + mvr2r( st->lsfoldbfi0, st->lsfoldbfi1, M ); + mvr2r( lsf_new, st->lsfoldbfi0, M ); + + /* update of pitch and voicing information for HQ FEC */ + if ( st->last_core != HQ_CORE ) + { + if( !st->Opt_AMR_WB && coder_type == UNVOICED ) + { + st->HqVoicing = 0; + } + else + { + st->HqVoicing = 1; + } + } + + /* SC-VBR */ + st->old_ppp_mode = st->last_ppp_mode_dec; + st->last_ppp_mode_dec = st->ppp_mode_dec; + st->last_nelp_mode_dec = st->nelp_mode_dec; + st->last_vbr_hw_BWE_disable_dec = st->vbr_hw_BWE_disable_dec; + + /* core switching updates */ + mvr2r( &Aq[(st->L_frame/L_SUBFR-1)*(M+1)], st->old_Aq_12_8, M+1 ); + st->old_Es_pred = Es_pred; + + return; +} + +/*-------------------------------------------------------------------* + * updt_IO_switch() + * + * Common updates for AMR-WB IO mode and EVS primary mode switching + *-------------------------------------------------------------------*/ + +void updt_IO_switch_dec( + const short output_frame, /* i : output frame length */ + Decoder_State *st /* i/o: state structure */ +) +{ + float xsp_tmp[M]; + + if( st->last_core == AMR_WB_CORE ) /* switching to EVS primary mode */ + { + /* AMR-WB IO mode uses ISF(ISP), but EVS primary mode LSF(LSP) */ + mvr2r( stable_LSP, xsp_tmp, M ); + isf2lsf( st->lsf_old, st->lsf_old, xsp_tmp, M, INT_FS_12k8 ); + mvr2r( stable_LSP, xsp_tmp, M ); + isp2lsp( st->lsp_old, st->lsp_old, xsp_tmp, M ); + + /* AMR-WB IO mode uses ISF(ISP), but EVS primary mode uses LSF(LSP) */ + mvr2r( stable_LSP, xsp_tmp, M ); + isp2lsp( st->lspCNG, st->lspCNG, xsp_tmp, M ); + st->old_enr_index = min( (short)((float)st->old_enr_index / STEP_AMR_WB_SID * STEP_SID), 127 ); + + /* reset TD BWE buffers */ + set_f( st->old_bwe_exc, 0.0f, PIT16k_MAX * 2 ); + set_f( st->old_bwe_exc_extended, 0.0f, NL_BUFF_OFFSET ); + st->bwe_non_lin_prev_scale = 0.0; + st->last_voice_factor = 0.0f; + + wb_tbe_extras_reset( st->mem_genSHBexc_filt_down_wb2, st->mem_genSHBexc_filt_down_wb3 ); + wb_tbe_extras_reset_synth( st->state_lsyn_filt_shb, st->state_lsyn_filt_dwn_shb, st->mem_resamp_HB ); + + if( output_frame >= L_FRAME32k ) + { + swb_tbe_reset( st->mem_csfilt, st->mem_genSHBexc_filt_down_shb, st->state_lpc_syn, + st->syn_overlap, st->state_syn_shbexc, &st->tbe_demph, &st->tbe_premph, st->mem_stp_swb,&(st->gain_prec_swb) ); + + /* reset GainShape delay for SWB TBE FEC */ + set_f( st->GainShape_Delay, 0, NUM_SHB_SUBFR/2 ); + + swb_tbe_reset_synth( st->genSHBsynth_Hilbert_Mem, st->genSHBsynth_state_lsyn_filt_shb_local ); + } + + if( output_frame == L_FRAME48k ) + { + st->prev_fb_ener_adjust = 0.0f; + set_f(st->fb_state_lpc_syn, 0, LPC_SHB_ORDER); + st->fb_tbe_demph = 0; + fb_tbe_reset_synth( st->fbbwe_hpf_mem, &st->prev_fbbwe_ratio ); + } + + /* reset FD BWE buffers */ + st->prev_mode = NORMAL; + st->prev_Energy = 0.0f; + st->prev_Energy_wb = 0.0f; + st->prev_L_swb_norm = 8; + st->prev_frica_flag = 0; + set_f( st->mem_imdct, 0, L_FRAME48k ); + st->prev_td_energy = 0.0f; + st->prev_weight = 0.2f; + set_f( st->old_wtda_swb, 0, L_FRAME48k ); + + /* HQ core buffers */ + set_f( st->delay_buf_out, 0, HQ_DELTA_MAX*HQ_DELAY_COMP ); + + /* reset the unvoiced/audio signal improvement memories */ + st->seed_tcx = 15687; + st->UV_cnt = 30; + st->LT_UV_cnt = 60.0f; + + st->use_acelp_preq = 0; + if(st->last_flag_filter_NB == 1) + st->cldfbSyn->bandsToZero = 0; + st->last_active_bandsToZero_bwdec = 0; + st->flag_NB_bwddec = 0; + st->perc_bwddec = 0.0f; + st->last_flag_filter_NB = 0; + st->active_frame_cnt_bwddec = 0; + set_s(st->flag_buffer, 0, 20); + } + else /* switching to AMR-WB IO mode */ + { + /* ISF Q memories */ + set_f(st->mem_MA, 0, M ); + + /* AMR-WB IO mode uses ISF(ISP), but EVS primary mode LSF(LSP) */ + mvr2r( stable_ISP, xsp_tmp, M ); + lsf2isf( st->lsf_old, st->lsf_old, xsp_tmp, M, INT_FS_12k8 ); + mvr2r( stable_ISP, xsp_tmp, M ); + lsp2isp( st->lsp_old, st->lsp_old, xsp_tmp, M ); + + /* AMR-WB IO mode uses ISF(ISP), but EVS primary mode LSF(LSP) */ + mvr2r( stable_ISP, xsp_tmp, M ); + lsp2isp( st->lspCNG, st->lspCNG, xsp_tmp, M ); + st->old_enr_index = min( (short)((float)st->old_enr_index / STEP_SID * STEP_AMR_WB_SID), 63 ); + + /* gain quantization memory */ + set_f(st->past_qua_en, -14.0f, GAIN_PRED_ORDER ); + + /* HF synthesis memories */ + st->ng_ener_ST = -51.0f; + + hf_synth_amr_wb_reset( &st->seed2, st->mem_syn_hf, st->mem_hp_interp, &st->prev_r, &st->fmerit_w_sm, st->delay_syn_hf, + &st->frame_count, &st->ne_min, &st->fmerit_m_sm, &st->voice_fac_amr_wb_hf, &st->unvoicing, + &st->unvoicing_sm, &st->unvoicing_flag, &st->voicing_flag, &st->start_band_old, &st->OptCrit_old ); + + /* reset the unvoiced/audio signal improvement memories */ + st->seed_tcx = 15687; + st->UV_cnt = 30; + st->LT_UV_cnt = 60.0f; + st->Last_ener = 0.0f; + st->lt_voice_fac = 0.0f; + + st->psf_lp_noise = st->lp_noise; + + /* reset VBR signalling */ + st->last_ppp_mode_dec = 0; + st->last_nelp_mode_dec = 0; + st->ppp_mode_dec = 0; + st->nelp_mode_dec = 0; + } + + /* CNG - reset */ + st->ho_hist_size = 0; + + /* ISF Q memories */ + mvr2r( UVWB_Ave, st->mem_AR, M ); + + /* FEC - update adaptive LSF mean vector */ + mvr2r( st->lsf_old, st->lsfoldbfi0, M ); + mvr2r( st->lsf_old, st->lsfoldbfi1, M ); + mvr2r( st->lsf_old, st->lsf_adaptive_mean, M ); + + return; +} + +/*-------------------------------------------------------------------* + * updt_bw_switching() + * + * Updates for BW switching + *-------------------------------------------------------------------*/ + +void updt_bw_switching( + Decoder_State *st, /* i/o: decoder state structure */ + const float *synth /* i : float synthesis signal */ +) +{ + if( st->output_Fs == 32000 && st->bwidth == SWB ) + { + calc_tilt_bwe( synth, &(st->tilt_swb), L_FRAME32k ); + } + + st->prev_enerLH = st->enerLH; + st->prev_enerLL = st->enerLL; + st->last_bwidth = st->bwidth; + + if( st->core == ACELP_CORE ) + { + if( st->bwidth == WB && st->bws_cnt == 0 ) + { + st->last_inner_frame = L_FRAME16k; + } + else + { + st->last_inner_frame = L_FRAME32k; + } + + if(st->prev_mode == HARMONIC) + { + st->prev_weight1 = 0.2f; + } + else + { + st->prev_weight1 = 0.5f; + } + } + else + { + if( st->last_inner_frame >= L_FRAME16k && inner_frame_tbl[st->bwidth] <= L_FRAME16k && st->bws_cnt > 0 && st->bws_cnt < N_WS2N_FRAMES ) + { + st->last_inner_frame = st->last_inner_frame; + } + else + { + st->last_inner_frame = inner_frame_tbl[st->bwidth]; + } + + if(inner_frame_tbl[st->bwidth] >= L_FRAME32k || st->core_brate <= HQ_16k40) + { + if(st->prev_hqswb_clas == HQ_HARMONIC || st->prev_hqswb_clas == HQ_HVQ) + { + st->prev_weight1 = 0.2f; + } + else + { + st->prev_weight1 = 0.5f; + } + } + } + + return; +} + + +/*-------------------------------------------------------------------* + * updt_dec_common() + * + * Common updates for MODE1 and MODE2 + *-------------------------------------------------------------------*/ + +void updt_dec_common( + Decoder_State *st, /* i/o: decoder state structure */ + const short hq_core_type, /* i : HQ core type */ + const float *synth /* i : decoded synthesis */ +) +{ + + st->last_codec_mode = st->codec_mode; + st->last_extl = st->extl; + st->last_L_frame = st->L_frame; + + st->prev_old_bfi = st->prev_bfi; + st->prev_bfi = st->bfi; + st->old_bfi_cnt = st->nbLostCmpt; + st->last_con_tcx = st->con_tcx; + st->con_tcx = 0; + + st->prev_last_core = st->last_core; + + if( st->use_partial_copy ) + { + st->prev_rf_frame_type = st->rf_frame_type; + } + else + { + st->prev_rf_frame_type = INACTIVE; + } + + st->tcxConceal_recalc_exc = 0; + if( (st->rf_frame_type >= RF_TCXFD && st->rf_frame_type <= RF_TCXTD2 && st->use_partial_copy && st->bfi) || !st->bfi ) + { + if( st->bfi && st->last_good <= UNVOICED_TRANSITION && st->clas_dec > UNVOICED_TRANSITION && st->last_con_tcx ) + { + st->tcxConceal_recalc_exc = 1; + } + st->last_good = st->clas_dec; + } + + if ( st->m_frame_type == ACTIVE_FRAME && ( !st->bfi || st->use_partial_copy ) ) + { + st->rf_flag_last = st->rf_flag; + } + + if( st->codec_mode == MODE1 ) + { + if( !st->bfi && st->core_brate > SID_2k40 ) + { + st->last_active_brate = st->total_brate; + } + + st->last_core = st->core; + st->last_hq_core_type = hq_core_type; + } + else if( st->codec_mode == MODE2 ) + { + if( !st->bfi && st->last_is_cng == 0 ) + { + st->last_active_brate = st->total_brate; + } + + if( st->m_frame_type != ACTIVE_FRAME ) + { + st->last_is_cng = 1; + } + + if( !st->bfi ) + { + st->last_core = st->core; + } + st->last_core_bfi = st->core; /* also required for clean channel decoding */ + } + + st->last_core_brate = st->core_brate; + + /* save synthesis for core switching */ + mvr2r( synth + NS2SA(st->output_Fs, ACELP_LOOK_NS+DELAY_BWE_TOTAL_NS), st->old_synth_sw, NS2SA(st->output_Fs, FRAME_SIZE_NS-ACELP_LOOK_NS-DELAY_BWE_TOTAL_NS) ); + + if( (st->core_brate <= SID_2k40 && st->cng_type == FD_CNG) || (st->tcxonly && st->codec_mode == MODE2) ) + { + /* reset LP memories */ + set_zero( st->mem_MA, M ); + if(st->sr_core == 16000) + { + mvr2r( GEWB2_Ave, st->mem_AR, M ); + } + else + { + mvr2r( GEWB_Ave, st->mem_AR, M ); + } + } + + return; +} + +/*-------------------------------------------------------------------* +* update_decoder_LPD_cng() +* +* +*--------------------------------------------------------------------*/ + +void update_decoder_LPD_cng( + Decoder_State *st, + const short coder_type, + float *timeDomainBuffer, + float *A, + float *bpf_noise_buf +) +{ + short i; + float lsp[M], lsf[M], pitch[NB_SUBFR16k]; + float *synth, synth_buf[M+1+L_FRAME_MAX+L_FRAME_MAX/2]; + float tmp; + float buf_synth[OLD_SYNTH_SIZE_DEC+L_FRAME_MAX+M]; + int pf_pitch[NB_SUBFR16k]; + float pf_gain[NB_SUBFR16k]; + + /* LPC -> LSP/lsp */ + a2lsp_stab( A, lsp, st->lsp_old ); + + /* LSP/lsp -> LSF/lsf */ + if( st->L_frame == L_FRAME16k ) + { + lsp2lsf( lsp, lsf, M, INT_FS_16k ); + } + else + { + lsp2lsf( lsp, lsf, M, INT_FS_12k8 ); + } + + mvr2r( st->old_synth, buf_synth, st->old_synth_len ); + mvr2r( timeDomainBuffer, buf_synth+st->old_synth_len, st->L_frame ); + + /* Update synth memory */ + synth = synth_buf + (1+M); + mvr2r( st->syn, synth_buf, 1+M ); + mvr2r( timeDomainBuffer, synth, st->L_frame ); + mvr2r( synth+st->L_frame-(1+M), st->syn, 1+M ); + mvr2r( st->old_synth+st->L_frame, st->old_synth, st->old_synth_len-st->L_frame ); + mvr2r( synth, st->old_synth+st->old_synth_len-st->L_frame, st->L_frame ); + + mvr2r( synth+st->L_frame-(st->L_frame/2), st->old_syn_Overl, st->L_frame/2 ); + + st->tcxltp_last_gain_unmodified = 0.0f; + + /* Update pre-synth memory */ + tmp = synth[-(1+M)]; + preemph( synth-M, st->preemph_fac, M+st->L_frame, &tmp ); + mvr2r( synth+st->L_frame-M, st->mem_syn2, M ); + mvr2r( synth+st->L_frame-L_SYN_MEM, st->mem_syn_r, L_SYN_MEM ); + + /* Update excitation memory */ + assert(st->L_frame < L_EXC_MEM_DEC); + mvr2r( st->old_exc+st->L_frame, st->old_exc, L_EXC_MEM_DEC-st->L_frame ); + residu( A, M,synth, st->old_exc+L_EXC_MEM_DEC-st->L_frame, st->L_frame ); + + /* Update LPC-related memories */ + mvr2r( lsp, st->lsp_old, M ); + mvr2r( lsf, st->lsf_old, M ); + mvr2r( lsp, st->lspold_uw, M ); + mvr2r( lsf, st->lsfold_uw, M ); + + st->envWeighted = 0; + mvr2r( A, st->old_Aq_12_8, M+1 ); + st->old_Es_pred = 0; + + /* Reset acelp memories */ + set_zero( st->dispMem, 8 ); + st->tilt_code = TILT_CODE; + st->gc_threshold = 0.0f; + + /* Update ace/tcx mode */ + st->core = ACELP_CORE; + st->last_is_cng = 1; + + /* Reset TCX overlap */ + st->tcx_cfg.tcx_curr_overlap_mode = st->tcx_cfg.tcx_last_overlap_mode = ALDO_WINDOW; + + /* For BBWE and Postfilter */ + mvr2r( A, &(st->mem_Aq[0]), M+1 ); + mvr2r( A, &(st->mem_Aq[(M+1)]), M+1 ); + mvr2r( A, &(st->mem_Aq[2*(M+1)]), M+1 ); + mvr2r( A, &(st->mem_Aq[3*(M+1)]), M+1 ); + if( st->L_frame == L_FRAME16k ) + { + mvr2r( A, &(st->mem_Aq[4*(M+1)]), M+1 ); + } + + /* Update for concealment */ + st->nbLostCmpt = 0; + st->prev_old_bfi = 0; + + for (i=0; ilsf_adaptive_mean[i] = ( st->lsfoldbfi1[i]+ st->lsfoldbfi0[i] + lsf[i] )/3; + st->lsfoldbfi1[i] = st->lsfoldbfi0[i]; + st->lsfoldbfi0[i] = lsf[i]; + } + + set_f( pitch, (float)L_SUBFR, NB_SUBFR16k ); + + FEC_clas_estim( synth, pitch, st->L_frame, UNVOICED, st->codec_mode, st->mem_syn_clas_estim, &(st->clas_dec), + &st->lp_ener_bfi, st->core_brate, 0, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, -1.0f, st->narrowBand, (SIGNAL_CLASSIFIER_MODE)0, + 0, st->preemph_fac, st->tcxonly, st->last_core_brate ); + + /* Postfiltering */ + pf_pitch[0] = pf_pitch[1] = pf_pitch[2] = pf_pitch[3] = pf_pitch[4] = L_SUBFR; + pf_gain[0] = pf_gain[1] = pf_gain[2] = pf_gain[3] = pf_gain[4] = 0.f; + st->bpf_gain_param = 0; + + post_decoder( st, coder_type, buf_synth, pf_gain, pf_pitch, timeDomainBuffer, bpf_noise_buf ); + + return; +} diff --git a/src/libs/libevs/lib_dec/updt_dec_fx.cpp b/src/libs/libevs/lib_dec/updt_dec_fx.cpp deleted file mode 100755 index b9553227..00000000 --- a/src/libs/libevs/lib_dec/updt_dec_fx.cpp +++ /dev/null @@ -1,736 +0,0 @@ -/*==================================================================================== - EVS Codec 3GPP TS26.442 Apr 03, 2018. Version 12.11.0 / 13.6.0 / 14.2.0 - ====================================================================================*/ - -#include "options.h" /* Compilation switches */ -#include "cnst_fx.h" /* Common constants */ -#include "rom_com_fx.h" /* Static table prototypes */ -#include "prot_fx.h" /* Function prototypes */ -#include /* Debug prototypes */ -#include "stl.h" - -/*-------------------------------------------------------------------* - * updt_dec() - * - * Common updates (all frame types) - *-------------------------------------------------------------------*/ -void updt_dec_fx( - Decoder_State_fx *st_fx, /* i/o: state structure */ - const Word16 L_frame, /* i : length of the frame */ - const Word16 coder_type, /* i : coding type */ - const Word16 *old_exc_fx, /* i : buffer of excitation */ - const Word16 *pitch_buf_fx, /* i : floating pitch values for each subframe */ - const Word16 Es_pred, /* i : predicited scaled innovation energy */ - const Word16 *Aq, /* i : A(z) quantized for all subframes */ - const Word16 *lsf_new_fx, /* i : current frame LSF vector */ - const Word16 *lsp_new_fx, /* i : current frame LSP vector */ - const Word16 voice_factors[], /* i : voicing factors */ - const Word16 *old_bwe_exc_fx, /* i : buffer of excitation */ - const Word16 *gain_buf /* i : Q14*/ -) -{ - Word16 i, len; - - /* update old excitation buffer */ - Copy( &old_exc_fx[L_frame], st_fx->old_exc_fx, L_EXC_MEM_DEC ); - IF( !st_fx->Opt_AMR_WB_fx ) - { - Copy( &old_bwe_exc_fx[L_FRAME32k], st_fx->old_bwe_exc_fx, PIT16k_MAX * 2 ); - } - - /* update old LSP and LSF vector */ - Copy( lsf_new_fx, st_fx->lsf_old_fx, M ); - Copy( lsp_new_fx, st_fx->lsp_old_fx, M ); - - /* update last coding type */ - st_fx->last_coder_type_fx = coder_type; - test(); - test(); - test(); - if( sub(coder_type,INACTIVE) == 0 || (sub(st_fx->bpf_off_fx,1) == 0 && sub(coder_type,AUDIO) != 0 && sub(coder_type,TRANSITION) != 0) ) - { - st_fx->last_coder_type_fx = UNVOICED; - move16(); - } - test(); - test(); - if( (sub(coder_type,AUDIO) != 0 || st_fx->Last_GSC_noisy_speech_flag_fx != 0) && st_fx->Last_GSC_pit_band_idx_fx > 0 ) - { - st_fx->Last_GSC_pit_band_idx_fx = 0; - move16(); /*The temporal contribution of the GSC is meaningless after 1 frame lost for inactive & unvoiced content */ - } - /* this ensures that st_fx->last_coder_type_fx is never set to INACTIVE in case of AVQ inactive because the FEC does not distinguish between GSC inactive and AVQ inactive */ - - test(); - if( L_sub(st_fx->total_brate_fx,ACELP_24k40) > 0 && sub(coder_type,INACTIVE) == 0 ) - { - st_fx->last_coder_type_fx = GENERIC; - move16(); - } - test(); - test(); - test(); - IF( sub(st_fx->Opt_AMR_WB_fx,1) == 0 && sub(coder_type,INACTIVE) == 0 && L_sub(st_fx->core_brate_fx,SID_1k75) != 0 && L_sub(st_fx->core_brate_fx,FRAME_NO_DATA) != 0 ) - { - /* overwrite previous coding type to help FEC */ - st_fx->last_coder_type_fx = UNVOICED; - move16(); - st_fx->last_voice_factor_fx = voice_factors[NB_SUBFR-1]; - move16(); - } - - IF( !st_fx->Opt_AMR_WB_fx ) - { - /* update voicing factor of TBE to help FEC */ - - st_fx->last_voice_factor_fx = voice_factors[NB_SUBFR16k-1]; - move16(); - if( sub(st_fx->L_frame_fx,L_FRAME) == 0 ) - { - st_fx->last_voice_factor_fx = voice_factors[NB_SUBFR-1]; - move16(); - } - } - - test(); - IF ( coder_type != AUDIO && coder_type != INACTIVE ) - { - st_fx->noise_lev_fx = NOISE_LEVEL_SP3; - move16(); - set16_fx( st_fx->old_y_gain_fx, 0, MBANDS_GN ); - - FOR( i = 0; i < L_FRAME; i++ ) - { - Word16 tmp_seed = st_fx->seed_tcx_fx; - move16(); - st_fx->Last_GSC_spectrum_fx[i] = shr_r(Random( &tmp_seed ),5); - move16(); /*Q10*/ - } - } - - /* update last GSC SWB speech flag for FEC */ - st_fx->Last_GSC_noisy_speech_flag_fx = st_fx->GSC_noisy_speech_fx; - move16(); - - /* update counter for FEC pitch estimate */ - st_fx->upd_cnt_fx = add(st_fx->upd_cnt_fx,1); - - st_fx->upd_cnt_fx = s_min(st_fx->upd_cnt_fx, MAX_UPD_CNT); - - len = shr(L_frame,6); - Copy32( &st_fx->old_pitch_buf_fx[len], st_fx->old_pitch_buf_fx, len ); - FOR ( i = 0; i < len; i++ ) - { - st_fx->old_pitch_buf_fx[len+i] = L_mult0(pitch_buf_fx[i], 1<<10); - move32(); - } - Copy( &st_fx->mem_pitch_gain[2], &st_fx->mem_pitch_gain[L_frame/L_SUBFR+2], L_frame/L_SUBFR ); - IF (sub(L_frame , L_FRAME) == 0) - { - st_fx->mem_pitch_gain[2] = gain_buf[3]; - move16(); - st_fx->mem_pitch_gain[3] = gain_buf[2]; - move16(); - st_fx->mem_pitch_gain[4] = gain_buf[1]; - move16(); - st_fx->mem_pitch_gain[5] = gain_buf[0]; - move16(); - } - ELSE - { - st_fx->mem_pitch_gain[2] = gain_buf[4]; - move16(); - st_fx->mem_pitch_gain[3] = gain_buf[3]; - move16(); - st_fx->mem_pitch_gain[4] = gain_buf[2]; - move16(); - st_fx->mem_pitch_gain[5] = gain_buf[1]; - move16(); - st_fx->mem_pitch_gain[6] = gain_buf[0]; - move16(); - } - - - /* FEC - update adaptive LSF mean vector */ - Copy( st_fx->lsfoldbfi0_fx, st_fx->lsfoldbfi1_fx, M ); - Copy( lsf_new_fx, st_fx->lsfoldbfi0_fx, M ); - - /* update of pitch and voicing information for HQ FEC */ - IF ( sub(st_fx->last_core_fx,HQ_CORE) != 0 ) - { - st_fx->HqVoicing_fx = 1; - move16(); - test(); - if( !st_fx->Opt_AMR_WB_fx && sub(coder_type,UNVOICED) == 0 ) - { - st_fx->HqVoicing_fx = 0; - move16(); - } - } - - /* SC-VBR */ - st_fx->old_ppp_mode_fx = st_fx->last_ppp_mode_dec_fx; - move16(); - st_fx->last_ppp_mode_dec_fx = st_fx->ppp_mode_dec_fx; - move16(); - st_fx->last_nelp_mode_dec_fx = st_fx->nelp_mode_dec_fx; - move16(); - st_fx->last_vbr_hw_BWE_disable_dec_fx = st_fx->vbr_hw_BWE_disable_dec_fx; - move16(); - - /*core switching updates*/ - Copy( &Aq[(st_fx->L_frame_fx/L_SUBFR-1)*(M+1)], st_fx->old_Aq_12_8_fx, M+1 ); - st_fx->old_Es_pred_fx = Es_pred; - move16(); - - return; -} - -/*-------------------------------------------------------------------* - * updt_IO_switch() - * - * Common updates for AMR-WB IO mode and EVS primary switching - *-------------------------------------------------------------------*/ -void updt_IO_switch_dec_fx( - const Word16 output_frame, /* i : output frame length */ - Decoder_State_fx *st_fx /* o : Decoder static variables structure */ -) -{ - Word16 xsp_tmp[M]; - IF( sub(st_fx->last_core_fx,AMR_WB_CORE) == 0 ) /* switching to EVS primary mode */ - { - /* AMR-WB IO mode uses ISF(ISP), but EVS primary mode mode LSF(LSP) */ - Copy( stable_LSP_fx, xsp_tmp, M ); - isf2lsf_fx( st_fx->lsf_old_fx, st_fx->lsf_old_fx, xsp_tmp); - Copy( stable_LSP_fx, xsp_tmp, M ); - /*isp2lsp( st->lsp_old, st->lsp_old, xsp_tmp, M, grid100 );*/ - isp2lsp_fx( st_fx->lsp_old_fx, st_fx->lsp_old_fx, xsp_tmp, M); - - /* AMR-WB IO mode uses ISF(ISP), but EVS primary mode uses LSF(LSP) */ - Copy( stable_LSP_fx, xsp_tmp, M ); - /*isp2lsp( st->lspCNG, st->lspCNG, xsp_tmp, M, grid100 );*/ - isp2lsp_fx( st_fx->lspCNG_fx, st_fx->lspCNG_fx, xsp_tmp, M); - - st_fx->old_enr_index_fx = s_min(shl(st_fx->old_enr_index_fx,1), 127 ); - - /* reset TD BWE buffers */ - set16_fx( st_fx->old_bwe_exc_fx, 0, PIT16k_MAX * 2 ); - set16_fx( st_fx->old_bwe_exc_extended_fx, 0, NL_BUFF_OFFSET ); - st_fx->bwe_non_lin_prev_scale_fx = 0; - move16(); - st_fx->last_voice_factor_fx = 0; - move16(); - - wb_tbe_extras_reset_fx( st_fx->mem_genSHBexc_filt_down_wb2_fx, st_fx->mem_genSHBexc_filt_down_wb3_fx ); - wb_tbe_extras_reset_synth_fx( st_fx->state_lsyn_filt_shb_fx, st_fx->state_lsyn_filt_dwn_shb_fx, st_fx->state_32and48k_WB_upsample_fx, st_fx->mem_resamp_HB_fx ); - - IF( sub(output_frame,L_FRAME32k) >= 0 ) - { - swb_tbe_reset_fx( st_fx->mem_csfilt_fx, st_fx->mem_genSHBexc_filt_down_shb_fx, st_fx->state_lpc_syn_fx, - st_fx->syn_overlap_fx, st_fx->state_syn_shbexc_fx, &st_fx->tbe_demph_fx, &st_fx->tbe_premph_fx - ,st_fx->mem_stp_swb_fx,&(st_fx->gain_prec_swb_fx) ); - set16_fx( st_fx->GainShape_Delay, 0, NUM_SHB_SUBFR/2 ); - swb_tbe_reset_synth_fx( st_fx->genSHBsynth_Hilbert_Mem_fx, st_fx->genSHBsynth_state_lsyn_filt_shb_local_fx ); - } - - IF( sub(output_frame,L_FRAME48k) == 0 ) - { - st_fx->prev_fb_ener_adjust_fx = 0; - move16(); - set16_fx( st_fx->fb_state_lpc_syn_fx, 0, LPC_SHB_ORDER ); - st_fx->fb_tbe_demph_fx = 0; - fb_tbe_reset_synth_fx( st_fx->fbbwe_hpf_mem_fx, st_fx->fbbwe_hpf_mem_fx_Q,&st_fx->prev_fbbwe_ratio_fx ); - } - st_fx->prev_Energy_wb_fx = L_deposit_l(0); - st_fx->prev_weight_fx = 6554; - move16(); - - /* reset FD BWE buffers */ - st_fx->prev_mode_fx = NORMAL; - move16(); - st_fx->prev_Energy_fx = 0; - move16(); - st_fx->prev_L_swb_norm_fx = 8; - move16(); - st_fx->prev_frica_flag_fx = 0; - move16(); - set16_fx( st_fx->mem_imdct_fx, 0, L_FRAME48k ); - st_fx->prev_td_energy_fx = 0; - move16(); - set16_fx(st_fx->L_old_wtda_swb_fx, 0, L_FRAME48k ); - /* HQ core buffers */ - set16_fx( st_fx->delay_buf_out_fx, 0, HQ_DELTA_MAX*HQ_DELAY_COMP ); - - /* reset the unvoiced/audio signal improvement memories */ - st_fx->seed_tcx_fx = 15687; - move16(); - st_fx->UV_cnt_fx = 30; - move16(); - st_fx->LT_UV_cnt_fx = (60<<6); - move16(); - - st_fx->use_acelp_preq = 0; - move16(); - move16(); - move16(); - move16(); - move16(); - move16(); - move16(); - if(sub(st_fx->last_flag_filter_NB, 1) == 0) - st_fx->cldfbSyn_fx->bandsToZero = 0; - st_fx->last_active_bandsToZero_bwdec = 0; - st_fx->flag_NB_bwddec = 0; - st_fx->perc_bwddec = 0; - st_fx->last_flag_filter_NB = 0; - st_fx->active_frame_cnt_bwddec = 0; - set16_fx(st_fx->flag_buffer, 0, 20); - } - ELSE /* switching to AMR-WB IO mode */ - { - /* ISF Q memories */ - set16_fx( st_fx->mem_MA_fx, 0, M ); - - /* AMR-WB IO mode uses ISF(ISP), but EVS primary mode LSF(LSP) */ - Copy( stable_ISP_fx, xsp_tmp, M ); - lsf2isf_fx( st_fx->lsf_old_fx, st_fx->lsf_old_fx, xsp_tmp, M); - Copy( stable_ISP_fx, xsp_tmp, M ); - lsp2isp_fx( st_fx->lsp_old_fx, st_fx->lsp_old_fx, xsp_tmp, M); - - /* AMR-WB IO mode uses ISF(ISP), but EVS primary mode LSF(LSP) */ - Copy( stable_ISP_fx, xsp_tmp, M ); - lsp2isp_fx( st_fx->lspCNG_fx, st_fx->lspCNG_fx, xsp_tmp, M); - - st_fx->old_enr_index_fx = s_max(s_min(shr(st_fx->old_enr_index_fx, 1), 63 ),0); - - - /* gain quantization memory */ - set16_fx( st_fx->past_qua_en_fx, -14*1024, GAIN_PRED_ORDER ); - - /* HF synthesis memories */ - st_fx->Ng_ener_ST_fx = -51*256; /*Q8*/ move16(); - - hf_synth_amr_wb_reset_fx( &st_fx->seed2_fx, st_fx->mem_syn_hf_fx, st_fx->mem_hp_interp_fx, - &st_fx->prev_r_fx, &st_fx->fmerit_w_sm_fx, st_fx->delay_syn_hf_fx, &st_fx->frame_count_fx, - &st_fx->ne_min_fx, &st_fx->fmerit_m_sm_fx, &st_fx->voice_fac_amr_wb_hf, - &st_fx->unvoicing_fx, &st_fx->unvoicing_sm_fx, &st_fx->unvoicing_flag_fx, - &st_fx->voicing_flag_fx, &st_fx->start_band_old_fx, &st_fx->OptCrit_old_fx ); - - /* reset the unvoiced/audio signal improvement memories */ - st_fx->seed_tcx_fx = 15687; - move16(); - st_fx->UV_cnt_fx = 30; - move16(); - st_fx->LT_UV_cnt_fx = 60<<6; - move16(); - st_fx->Last_ener_fx = 0; - move16(); - st_fx->lt_voice_fac_fx = 0; - move16(); - - st_fx->psf_lp_noise_fx = round_fx(L_shl(st_fx->lp_noise,1)); - - /* reset VBR signalling */ - st_fx->last_ppp_mode_dec_fx = 0; - move16(); - st_fx->last_nelp_mode_dec_fx = 0; - move16(); - st_fx->ppp_mode_dec_fx = 0; - move16(); - st_fx->nelp_mode_dec_fx = 0; - move16(); - } - - /* CNG - reset */ - st_fx->ho_hist_size_fx = 0; - move16(); - - /* LSF Q memories */ - Copy( UVWB_Ave_fx, st_fx->mem_AR_fx, M ); - - /* FEC - update adaptive LSF mean vector */ - Copy( st_fx->lsf_old_fx, st_fx->lsfoldbfi0_fx, M ); - Copy( st_fx->lsf_old_fx, st_fx->lsfoldbfi1_fx, M ); - Copy( st_fx->lsf_old_fx, st_fx->lsf_adaptive_mean_fx, M ); - - return; -} - -/*-------------------------------------------------------------------* - * updt_bw_switching() - * - * Updates for BW switching - *-------------------------------------------------------------------*/ - -void updt_bw_switching_fx( - Decoder_State_fx *st_fx, /* i/o: decoder state structure */ - const Word16 *synth, /* i : float synthesis signal */ - const Word16 Qpost -) -{ - test(); - IF(st_fx->output_Fs_fx == 32000 && st_fx->bwidth_fx == SWB) - { - st_fx->tilt_swb_fx = round_fx(L_shl(calc_tilt_bwe_fx(synth, Qpost, L_FRAME32k), 3)); - } - - st_fx->prev_enerLH_fx = st_fx->enerLH_fx; - move32(); - st_fx->prev_enerLL_fx = st_fx->enerLL_fx; - move32(); - st_fx->last_bwidth_fx = st_fx->bwidth_fx; - move32(); - - IF( sub(st_fx->core_fx, ACELP_CORE) == 0 ) - { - st_fx->last_inner_frame_fx = L_FRAME32k; - move16(); - test(); - if( sub(st_fx->bwidth_fx, WB) == 0 && st_fx->bws_cnt_fx == 0 ) - { - st_fx->last_inner_frame_fx = L_FRAME16k; - move16(); - } - - st_fx->prev_weight1_fx = 16384; - move16(); - if(sub(st_fx->prev_mode_fx, HARMONIC) == 0) - { - st_fx->prev_weight1_fx = 6554; - move16(); - } - } - ELSE - { - test(); - test(); - test(); - IF( !(sub(st_fx->last_inner_frame_fx, L_FRAME16k) >= 0 && sub(inner_frame_tbl[st_fx->bwidth_fx], L_FRAME16k) <= 0 && st_fx->bws_cnt_fx > 0 && sub(st_fx->bws_cnt_fx, N_WS2N_FRAMES) < 0) ) - { - st_fx->last_inner_frame_fx = inner_frame_tbl[st_fx->bwidth_fx]; - move16(); - } - - test(); - IF(sub(inner_frame_tbl[st_fx->bwidth_fx], L_FRAME32k) >= 0 || L_sub(st_fx->core_brate_fx, HQ_16k40) <= 0) - { - st_fx->prev_weight1_fx = 16384; - move16(); - test(); - if(sub(st_fx->prev_hqswb_clas_fx, HQ_HARMONIC) == 0 || sub(st_fx->prev_hqswb_clas_fx, HQ_HVQ) == 0) - { - st_fx->prev_weight1_fx = 6554; - move16(); - } - } - } - - return; -} - -/*-------------------------------------------------------------------* - * updt_dec_common() - * - * Common updates for MODE1 and MODE2 - *-------------------------------------------------------------------*/ - -void updt_dec_common_fx( - Decoder_State_fx *st_fx, /* i/o: decoder state structure */ - Word16 hq_core_type_fx, /* i : HQ core type */ - const Word16 *synth /* i : decoded synthesis */ -) -{ - - st_fx->last_codec_mode = st_fx->codec_mode; - move16(); - st_fx->last_extl_fx = st_fx->extl_fx; - move16(); - st_fx->last_L_frame_fx = st_fx->L_frame_fx; - move16(); - - st_fx->prev_old_bfi_fx = st_fx->prev_bfi_fx; - move16(); - st_fx->prev_bfi_fx = st_fx->bfi_fx; - move16(); - st_fx->old_bfi_cnt_fx = st_fx->nbLostCmpt; - move16(); - st_fx->last_con_tcx = st_fx->con_tcx; - move16(); - st_fx->con_tcx = 0; - - st_fx->tcxConceal_recalc_exc = 0; - move16(); - test(); - test(); - IF( (sub(st_fx->rf_frame_type,RF_TCXFD) >= 0 && sub(st_fx->rf_frame_type,RF_TCXTD2) <= 0 && st_fx->use_partial_copy && st_fx->bfi_fx) || !st_fx->bfi_fx ) - { - test(); - test(); - test(); - if( st_fx->bfi_fx && (sub(st_fx->last_good_fx, UNVOICED_TRANSITION) <= 0) && (sub(st_fx->clas_dec, UNVOICED_TRANSITION) > 0) && st_fx->last_con_tcx ) - { - st_fx->tcxConceal_recalc_exc = 1; - move16(); - } - st_fx->last_good_fx = st_fx->clas_dec; - move16(); - } - IF (st_fx->use_partial_copy) - { - st_fx->prev_rf_frame_type = st_fx->rf_frame_type; - } - ELSE - { - st_fx->prev_rf_frame_type = INACTIVE; - } - - if (sub(st_fx->m_frame_type, ACTIVE_FRAME) == 0 && (st_fx->bfi_fx != 1 || st_fx->use_partial_copy != 0)) - { - st_fx->rf_flag_last = st_fx->rf_flag; - } - - IF( sub(st_fx->codec_mode,MODE1)==0 ) - { - test(); - if( !st_fx->bfi_fx && st_fx->core_brate_fx > SID_2k40 ) - { - move16(); - st_fx->last_active_brate_fx = st_fx->total_brate_fx; - } - - move16(); - move16(); - st_fx->last_core_fx = st_fx->core_fx; - st_fx->last_hq_core_type_fx = hq_core_type_fx; - } - ELSE IF( sub(st_fx->codec_mode,MODE2)==0 ) - { - test(); - if ((!st_fx->bfi_fx) && (st_fx->last_is_cng==0)) - { - move16(); - st_fx->last_active_brate_fx = st_fx->total_brate_fx; - } - /* INFO: moved from update_decoder_LPD_cng() */ - if (sub(st_fx->m_frame_type,ACTIVE_FRAME)!=0) - { - move16(); - st_fx->last_is_cng = 1; - } - - - if (!st_fx->bfi_fx) - { - st_fx->last_core_fx = st_fx->core_fx; - } - move16(); - move16(); - st_fx->last_core_bfi = st_fx->core_fx; /* also required for clean channel decoding */ - } - move16(); - st_fx->last_core_brate_fx = st_fx->core_brate_fx; - - /* save synthesis for core switching */ - Copy_Scale_sig( synth + NS2SA_fx2(st_fx->output_Fs_fx,ACELP_LOOK_NS+DELAY_BWE_TOTAL_NS), st_fx->old_synth_sw_fx, NS2SA_fx2(st_fx->output_Fs_fx,FRAME_SIZE_NS-ACELP_LOOK_NS-DELAY_BWE_TOTAL_NS), st_fx->Q_old_postdec ); - - test(); - test(); - test(); - IF( ((L_sub(st_fx->core_brate_fx,SID_2k40) <= 0) && sub(st_fx->cng_type_fx, FD_CNG) == 0) - || (st_fx->tcxonly && sub(st_fx->codec_mode,MODE2)==0) - ) - - { - /* reset LP memories */ - set16_fx( st_fx->mem_MA_fx,0, M ); - IF( L_sub(st_fx->sr_core,16000) == 0 ) - { - Copy( GEWB2_Ave_fx, st_fx->mem_AR_fx, M ); - } - ELSE - { - Copy( GEWB_Ave_fx, st_fx->mem_AR_fx, M ); - } - } - return; -} - - -void update_decoder_LPD_cng( Decoder_State_fx *st, Word16 coder_type, Word16 *timeDomainBuffer, Word16 *A, Word16 *bpf_noise_buf) -{ - Word16 i; - Word16 lsp[M], lsf[M]; - Word16 *synth, synth_buf[M+1+L_FRAME_MAX+L_FRAME_MAX/2], tmp; - Word16 buf_synth[OLD_SYNTH_SIZE_DEC+L_FRAME_MAX+M]; - Word16 pf_pitch[NB_SUBFR16k]; - Word16 pf_gain[NB_SUBFR16k]; - Word16 pitch[NB_SUBFR16k]; - - - /* LPC order */ - move16(); - - /* LPC -> LSP */ - E_LPC_a_lsp_conversion( A, lsp, st->lsp_old_fx, M ); - - /* LSP -> LSF */ - IF(sub(st->L_frame_fx, L_FRAME16k)== 0) - { - lsp2lsf_fx( lsp, lsf, M, INT_FS_16k_FX ); - } - ELSE - { - E_LPC_lsp_lsf_conversion( lsp, lsf, M ); - } - - - Copy( st->old_synth, buf_synth, st->old_synth_len ); - Copy( timeDomainBuffer, buf_synth+st->old_synth_len, st->L_frame_fx ); - - /* Update synth memory */ - - move16(); - synth = synth_buf + (1+M) ; - - Copy( st->syn, synth_buf, 1+M ); - Copy( timeDomainBuffer, synth, st->L_frame_fx ); - Copy( synth+st->L_frame_fx-(1+M), st->syn, 1+M ); - Copy( st->old_synth+st->L_frame_fx, st->old_synth, st->old_synth_len-st->L_frame_fx ); - Copy( synth, st->old_synth+st->old_synth_len-st->L_frame_fx, st->L_frame_fx ); - bufferCopyFx( synth+st->L_frame_fx-(st->L_frame_fx/2), st->old_syn_Overl, st->L_frame_fx/2,0 /*Qf_syn*/, -1 /*Qf_old_xnq*/, 0 , 0 /*Q_old_xnq*/); - - st->tcxltp_last_gain_unmodified = 0; - - /* Update pe-synth memory */ - move16(); - tmp = synth[-(1+M)]; - - st->Q_syn = E_UTIL_f_preemph3( synth-M, st->preemph_fac, M+st->L_frame_fx, &tmp, 1 ); - st->prev_Q_syn = st->Q_syn = st->Q_syn - 1; - Copy( synth+st->L_frame_fx-M, st->mem_syn2_fx, M ); - Copy( synth+st->L_frame_fx-L_SYN_MEM, st->mem_syn_r, L_SYN_MEM ); - - /* Update excitation memory */ - assert(st->L_frame_fx < L_EXC_MEM_DEC); - IF(sub(add(st->Q_syn,1),st->Q_exc) != 0) - { - Scale_sig(st->old_exc_fx, L_EXC_MEM_DEC, sub(add(st->Q_syn,1),st->Q_exc)); - } - st->Q_exc = st->Q_syn + 1; - Copy( st->old_exc_fx+st->L_frame_fx, st->old_exc_fx, sub(L_EXC_MEM_DEC,st->L_frame_fx) ); - Residu3_fx( A, synth, st->old_exc_fx+L_EXC_MEM_DEC-st->L_frame_fx, st->L_frame_fx, 1 ); - - /* Update LPC-related memories */ - - Copy( lsp, st->lsp_old_fx, M ); - Copy( lsf, st->lsf_old_fx, M ); - Copy( lsp, st->lspold_uw, M ); - Copy( lsf, st->lsfold_uw, M ); - move16(); - move16(); - st->envWeighted = 0; - Copy( A, st->old_Aq_12_8_fx, M+1 ); - st->old_Es_pred_fx=0; - - /* Reset acelp memories */ - - move16(); - st->dm_fx.prev_gain_code = L_deposit_l(0); - set16_fx(st->dm_fx.prev_gain_pit, 0, 6); - st->dm_fx.prev_state = 0; - - move16(); - move16(); - st->tilt_code_fx = TILT_CODE; - st->gc_threshold_fx = 0; - - /* Update ace/tcx mode */ - st->core_fx = ACELP_CORE; - move16(); - move16(); - move16(); - st->last_is_cng = 1; - move16(); - - /* Reset TCX overlap */ - move16(); - move16(); - st->tcx_cfg.tcx_curr_overlap_mode = st->tcx_cfg.tcx_last_overlap_mode = ALDO_WINDOW; - - /* For BBWE and Postfilter */ - - Copy( A, &(st->mem_Aq[0]), M+1 ); - Copy( A, &(st->mem_Aq[(M+1)]), M+1 ); - Copy( A, &(st->mem_Aq[2*(M+1)]), M+1 ); - Copy( A, &(st->mem_Aq[3*(M+1)]), M+1 ); - IF( sub(st->L_frame_fx, L_FRAME16k) == 0 ) - { - Copy( A, &(st->mem_Aq[4*(M+1)]), M+1 ); - } - - /* Update for concealment */ - move16(); - move16(); - st->nbLostCmpt = 0; - st->prev_old_bfi_fx = 0; - - FOR (i=0; ilsf_adaptive_mean_fx[i] = add( mult_r(st->lsfoldbfi1_fx[i], 10923/*1.0f/3.0f Q15*/), add( mult_r(st->lsfoldbfi0_fx[i], 10923/*1.0f/3.0f Q15*/), mult_r(lsf[i], 10923/*1.0f/3.0f Q15*/) ) ); - st->lsfoldbfi1_fx[i] = st->lsfoldbfi0_fx[i]; - st->lsfoldbfi0_fx[i] = lsf[i]; - } - - set16_fx(pitch, shl(L_SUBFR, 6), NB_SUBFR16k); - - FEC_clas_estim_fx( - st, - /*Opt_AMR_WB*/0, /*A*/ - st->L_frame_fx, - &(st->clas_dec), - coder_type, - pitch, - synth, - &st->lp_ener_FER_fx, - /**decision_hyst*/NULL, /* i/o: hysteresis of the music/speech decision */ - /**UV_cnt*/ NULL, /* i/o: number of consecutives frames classified as UV */ - /**LT_UV_cnt*/ NULL, /* i/o: long term consecutives frames classified as UV */ - /**Last_ener*/ NULL, /* i/o: last_energy frame */ - /**locattack*/ NULL, /* i/o: detection of attack (mainly to localized speech burst) */ - /**lt_diff_etot*/NULL, /* i/o: long-term total energy variation */ - /**amr_io_class*/ NULL, /* i/o: classification for AMR-WB IO mode */ - /*bitrate*/ 0 , /* i : Decoded bitrate */ - st->Q_syn, /* i : Synthesis scaling */ - /**class_para*/ NULL, /* o : classification para. fmerit1 */ - st->mem_syn_clas_estim_fx, /* i/o: memory of the synthesis signal for frame class estimation */ - &st->classifier_Q_mem_syn, /*i/o : exponent for memory of synthesis signal for frame class estimation */ - -32768/*-1.f Q15*/, /* i : LTP Gain */ - 0/*CLASSIFIER_ACELP*/, /* i : signal classifier mode */ - 0/*bfi*/, /* i : bad frame indicator */ - st->last_core_brate_fx /* i : bitrate of previous frame */ - ); - - /* Postfiltering */ - move16(); - move16(); - move16(); - move16(); - move16(); - move16(); - move16(); - move16(); - move16(); - move16(); - pf_pitch[0] = pf_pitch[1] = pf_pitch[2] = pf_pitch[3] = pf_pitch[4] = L_SUBFR; - pf_gain[0] = pf_gain[1] = pf_gain[2] = pf_gain[3] = pf_gain[4] = 0; - st->bpf_gain_param=0; - move16(); - - post_decoder( st, coder_type, buf_synth, pf_gain, pf_pitch, timeDomainBuffer, bpf_noise_buf ); - - return; -} - diff --git a/src/libs/libevs/lib_dec/vlpc_1st_dec.cpp b/src/libs/libevs/lib_dec/vlpc_1st_dec.cpp old mode 100755 new mode 100644 index d4064248..32a6d890 --- a/src/libs/libevs/lib_dec/vlpc_1st_dec.cpp +++ b/src/libs/libevs/lib_dec/vlpc_1st_dec.cpp @@ -1,30 +1,37 @@ /*==================================================================================== - EVS Codec 3GPP TS26.442 Apr 03, 2018. Version 12.11.0 / 13.6.0 / 14.2.0 + EVS Codec 3GPP TS26.443 Nov 13, 2018. Version 12.11.0 / 13.7.0 / 14.3.0 / 15.1.0 ====================================================================================*/ +#include #include -#include "prot_fx.h" -#include "stl.h" +#include "prot.h" -extern Word16 const dico_lsf_abs_8b[]; +extern float const dico_lsf_abs_8b[]; + +/*------------------------------------------------------------------* +* vlpc_1st_dec() +* +* +*------------------------------------------------------------------*/ void vlpc_1st_dec( - Word16 index, /* input: codebook index */ - Word16 *lsfq) /* i/o: i:prediction o:quantized lsf */ + int index, /* input: codebook index */ + float *lsfq, /* i/o: i:prediction o:quantized lsf */ + float sr_core +) { - Word16 i; - const Word16 *p_dico; - - + short i; + const float *p_dico; + float scale = sr_core/INT_FS_12k8; assert(index < 256); + p_dico = &dico_lsf_abs_8b[index * M]; - FOR (i = 0; i < M; i++) + for (i = 0; i < M; i++) { - lsfq[i] = add(lsfq[i], *p_dico); - move16(); - p_dico++; + lsfq[i] += scale **p_dico++; } + return; } diff --git a/src/libs/libevs/lib_dec/vlpc_2st_dec.cpp b/src/libs/libevs/lib_dec/vlpc_2st_dec.cpp old mode 100755 new mode 100644 index 67919c5b..51fc3508 --- a/src/libs/libevs/lib_dec/vlpc_2st_dec.cpp +++ b/src/libs/libevs/lib_dec/vlpc_2st_dec.cpp @@ -1,59 +1,42 @@ /*==================================================================================== - EVS Codec 3GPP TS26.442 Apr 03, 2018. Version 12.11.0 / 13.6.0 / 14.2.0 + EVS Codec 3GPP TS26.443 Nov 13, 2018. Version 12.11.0 / 13.7.0 / 14.3.0 / 15.1.0 ====================================================================================*/ #include #include -#include "prot_fx.h" -#include "stl.h" +#include +#include "prot.h" + +/*------------------------------------------------------------------* +* vlpc_2st_dec() +* +* +*------------------------------------------------------------------*/ void vlpc_2st_dec( - Word16 *lsfq, /* i/o: i:1st stage o:1st+2nd stage */ - Word16 *indx, /* input: index[] (4 bits per words) */ - Word16 mode, /* input: 0=abs, >0=rel */ - Word32 sr_core) + float *lsfq, /* i/o: i:1st stage o:1st+2nd stage */ + int *indx, /* input: index[] (4 bits per words) */ + int mode, /* input: 0=abs, >0=rel */ + float sr_core +) { - Word16 i; - Word16 w[M]; - Word16 xq[M]; - Word16 gap; - - + short i; + float w[M]; + int xq[M]; + float scale = sr_core/INT_FS_12k8; /* weighting from the 1st stage */ - lsf_weight_2st(lsfq, w, mode); + lsf_weight_2st( lsfq, w, mode, sr_core ); /* quantize */ - AVQ_dec_lpc(indx, xq, 2); + AVQ_dec_lpc( indx, xq, 2 ); /* quantized lsf */ - - FOR (i=0; i +#include +#include "prot.h" +#include "cnst.h" +#include "rom_com.h" + +/*-------------------------------------------------------------------* + * ppp_voiced_decoder() + * + * Voiced decoder for SC-VBR + *-------------------------------------------------------------------*/ + +void ppp_voiced_decoder( + Decoder_State *st, /* i/o: state structure */ + float *out, /* o : residual signal */ + const float *lpc2, /* i : current frame LPC */ + float *exc, /* i : previous frame excitation */ + float *pitch /* o : floating pitch values for each subframe */ + ,short bfi +) +{ + short k, delta_lag_D = 0; + float upper_cut_off_freq_of_interest = 0, upper_cut_off_freq = 0; + int pl, l; + float interp_delay[3], temp_l, temp_pl, diff; + + DTFS_STRUCTURE *TMPDTFS = DTFS_new(); + DTFS_STRUCTURE *CURRP_Q_D = DTFS_new(); + + DTFS_STRUCTURE *dtfs_temp = DTFS_new(); + + if ( st->bwidth == NB ) + { + upper_cut_off_freq_of_interest = 3300.0; + upper_cut_off_freq = 4000.0; + } + else if ( st->bwidth == WB ) + { + upper_cut_off_freq_of_interest = 4000.0; + upper_cut_off_freq = 6400.0; + } + + /* Initialization */ + if (st->firstTime_voiceddec) + { + st->firstTime_voiceddec=0; + + /* (st->PREV_CW_D) = DTFS_new();*/ + st->dtfs_dec_lag = 0; + st->dtfs_dec_nH = 0; + st->dtfs_dec_nH_4kHz = 0; + st->dtfs_dec_upper_cut_off_freq_of_interest = 3300.0; + st->dtfs_dec_upper_cut_off_freq = 4000.0; + + for(k = 0; k < MAXLAG_WI; k++) + { + st->dtfs_dec_a[k] = 0.0; + st->dtfs_dec_b[k] = 0.0; + } + } + pl = (int)min(rint_new(st->old_pitch_buf[(2*NB_SUBFR)-1]),MAX_LAG_PIT); + delta_lag_D = (short) get_next_indice( st, 5 ); + + l = min(MAX_LAG_PIT,pl+delta_lag_D-11); + + temp_pl = (float) pl; + temp_l = (float) l; + + if (temp_pl != temp_l) + { + for(k=0; klast_coder_type == UNVOICED) + { + pl = l; /* if prev frame was sil/uv*/ + } + + if (pl > (int)anint(1.85*l)) + { + pl /= 2; + } + + if (pl*2 <= PIT_MAX && pl <= (int)anint(0.54*l)) + { + pl *= 2; + } + + /* Restoring PPP memories when the last frame is non-PPP or full-rate PPP */ + if (st->last_ppp_mode_dec != 1) + { + DTFS_to_fs(exc-pl, pl, dtfs_temp, st->bwidth == WB ? (short)16000 : (short)8000 ,0); + + st->ph_offset_D = 0.0 ; + + /* Copy over PREV_CW_D into TMPDTFS */ + DTFS_copy(TMPDTFS, *dtfs_temp); + + DTFS_car2pol(TMPDTFS); + + st->lastLgainD = (float) log10(TMPDTFS->lag*DTFS_setEngyHarm(92.0,1104.5,0.0,1104.5,1.0,TMPDTFS)); + st->lastHgainD = (float) log10(TMPDTFS->lag*DTFS_setEngyHarm(1104.5,upper_cut_off_freq_of_interest,1104.5,upper_cut_off_freq,1.0,TMPDTFS)); + + DTFS_to_erb(*TMPDTFS,st->lasterbD); + } + else + { + /* Copy DTFS related parameters from 'st' to 'dtfs_temp' structure */ + dtfs_temp->lag = st->dtfs_dec_lag; + dtfs_temp->nH = st->dtfs_dec_nH; + dtfs_temp->nH_4kHz = st->dtfs_dec_nH_4kHz; + dtfs_temp->upper_cut_off_freq_of_interest = st->dtfs_dec_upper_cut_off_freq_of_interest; + dtfs_temp->upper_cut_off_freq = st->dtfs_dec_upper_cut_off_freq; + + mvr2r(st->dtfs_dec_a, dtfs_temp->a, MAXLAG_WI); + mvr2r(st->dtfs_dec_b, dtfs_temp->b, MAXLAG_WI); + } + + CURRP_Q_D->lag = l; + + /* safety check in case of bit errors */ + if( CURRP_Q_D->lag <= 0 ) + { + CURRP_Q_D->lag = 1; + st->BER_detect = 1; + } + + /* compute nH for lag */ + CURRP_Q_D->nH = (int)floor(upper_cut_off_freq/(((float)INT_FS_12k8)/CURRP_Q_D->lag)); + diff = ((float)INT_FS_12k8) / CURRP_Q_D->lag ; + + if (upper_cut_off_freq-(diff*CURRP_Q_D->nH)>=diff) + { + CURRP_Q_D->nH++; + } + + CURRP_Q_D->nH_4kHz = (int)floor(4000.0/(INT_FS_12k8/CURRP_Q_D->lag)); + + if (4000.0 - (diff*CURRP_Q_D->nH_4kHz) >= diff) + { + CURRP_Q_D->nH_4kHz++; + } + + CURRP_Q_D->upper_cut_off_freq = dtfs_temp->upper_cut_off_freq; + CURRP_Q_D->upper_cut_off_freq_of_interest = dtfs_temp->upper_cut_off_freq_of_interest; + + if ( bfi == 0 ) + { + ppp_quarter_decoder( st, CURRP_Q_D, dtfs_temp->lag, &(st->lastLgainD), &(st->lastHgainD), + &(st->lasterbD[0]), + bfi, + *dtfs_temp ); + } + + WIsyn(*dtfs_temp, CURRP_Q_D, lpc2, &(st->ph_offset_D), out, (short) L_FRAME ,0 ); + + DTFS_copy(dtfs_temp, *CURRP_Q_D); + + /* Copy DTFS related parameters from 'dtfs_temp' to 'st' structure */ + st->dtfs_dec_lag = dtfs_temp->lag; + st->dtfs_dec_nH = dtfs_temp->nH; + st->dtfs_dec_nH_4kHz = dtfs_temp->nH_4kHz; + st->dtfs_dec_upper_cut_off_freq_of_interest = dtfs_temp->upper_cut_off_freq_of_interest; + st->dtfs_dec_upper_cut_off_freq = dtfs_temp->upper_cut_off_freq; + + mvr2r(dtfs_temp->a, st->dtfs_dec_a, MAXLAG_WI); + mvr2r(dtfs_temp->b, st->dtfs_dec_b, MAXLAG_WI); + + free(TMPDTFS); + free(CURRP_Q_D); + free(dtfs_temp); + + return; +} diff --git a/src/libs/libevs/lib_dec/voiced_dec_fx.cpp b/src/libs/libevs/lib_dec/voiced_dec_fx.cpp deleted file mode 100755 index b59ee540..00000000 --- a/src/libs/libevs/lib_dec/voiced_dec_fx.cpp +++ /dev/null @@ -1,363 +0,0 @@ -/*==================================================================================== - EVS Codec 3GPP TS26.442 Apr 03, 2018. Version 12.11.0 / 13.6.0 / 14.2.0 - ====================================================================================*/ - -#include -#include "prot_fx.h" -#include "rom_com_fx.h" -#include "log2.h" -#include "stl.h" - -/*===================================================================*/ -/* FUNCTION : void ppp_voiced_decoder_fx () */ -/*-------------------------------------------------------------------*/ -/* PURPOSE : */ -/*-------------------------------------------------------------------*/ -/* INPUT ARGUMENTS : */ -/* _ Word16 bfi_fx - Q0 bad frame indicator */ -/* _ const Word16 *lpc2_fx - Q12 current frame LPC */ -/* _ Word16 *exc_fx - Q0 previous frame excitation */ -/*-------------------------------------------------------------------*/ -/* OUTPUT ARGUMENTS : */ -/* _ Decoder_State_fx *st_fx: */ -/* _ lastLgainD_fx - Q11 */ -/* _ lastHgainD_fx - Q11 */ -/* _ lasterbD_fx - Q13 */ -/* _ Word16 *pitch - Q6 floating pitch values for each subframe */ -/* _ Word16 *out_fx - Q0 residual signal */ -/*-------------------------------------------------------------------*/ -/* INPUT/OUTPUT ARGUMENTS : */ -/* _ Decoder_State_fx *st_fx: */ -/* _ lsp_old_fx - Q15 */ -/* _ st_fx->dtfs_dec_xxxx */ -/* _ a nd b in st_fx->dtfs_dec_Q */ -/* rest all in Q0 */ -/* _ gainp_ppp Q14 */ -/* _ Word16 *pitch_buf_fx - Q6 fixed pitch values for each subframe */ -/*-------------------------------------------------------------------*/ -/* RETURN ARGUMENTS : */ -/* _ None */ -/*-------------------------------------------------------------------*/ -/* CALLED FROM : RX */ -/*===================================================================*/ -void ppp_voiced_decoder_fx( - Decoder_State_fx *st_fx, /* i/o: state structure */ - Word16 *out_fx, /* o : residual signal */ - const Word16 *lpc2_fx, /* i : current frame LPC */ - Word16 *exc_fx, /* i : previous frame excitation */ - Word16 *pitch, /* o : floating pitch values for each subframe */ - Word16 bfi /* i : Frame error rate */ -) -{ - Word16 k, delta_lag_D = 0,temp,Ql,Qh,diff; - Word16 upper_cut_off_freq_of_interest = 0, upper_cut_off_freq = 0; - Word16 pl, l,n,rem_fx; - Word16 temp_l_fx, temp_pl_fx,interp_delay_fx[3]; - Word32 logLag,Ltemp_q,Ltemp,rem32,temp32_fx,tempnH_fx; - Word16 exp,tmp; - Word32 L_tmp; - - DTFS_STRUCTURE_FX *TMPDTFS_FX = DTFS_new_fx(); - DTFS_STRUCTURE_FX *CURRP_Q_D_FX = DTFS_new_fx(); - - DTFS_STRUCTURE_FX *dtfs_temp_fx = DTFS_new_fx(); - - Word16 pf_temp1[MAXLAG_WI]; /*maynot need more than MAXLAG_WI/2+1 */ - Word16 pf_temp2[MAXLAG_WI]; - Word16 pf_temp[MAXLAG_WI]; - Word16 pf_n2[MAXLAG_WI]; - Word16 S_fx[4*PIT_MAX+1], C_fx[4*PIT_MAX+1]; - Word16 temp_Fs; - - test(); - IF (sub(st_fx->bwidth_fx,WB) == 0 || sub(st_fx->bwidth_fx,SWB) == 0) - { - upper_cut_off_freq_of_interest = 0x2800; - move16();/*4000 normalized to 12800 in Q15 */ - upper_cut_off_freq = 0x4000; - move16();/*6400 normalized to 12800 in Q15 */ - } - ELSE IF (sub(st_fx->bwidth_fx,NB) == 0 ) - { - upper_cut_off_freq_of_interest = 0x2100; - move16();/*3300 normalized to 12800 in Q15 */ - upper_cut_off_freq = 0x2800; - move16(); - } - - temp_Fs = 8000; - - if ( sub( st_fx->bwidth_fx, WB) == 0 ) - { - temp_Fs = 16000; - move16(); - } - - - - /* Initialization */ - IF (st_fx->firstTime_voiceddec_fx) - { - st_fx->firstTime_voiceddec_fx=0; - move16(); - - /* (st_fx->PREV_CW_D) = DTFS_new();*/ - st_fx->dtfs_dec_lag_fx = 0; - move16(); - st_fx->dtfs_dec_nH_fx = 0; - move16(); - st_fx->dtfs_dec_nH_4kHz_fx = 0; - move16(); - st_fx->dtfs_dec_upper_cut_off_freq_of_interest_fx = 3300; - move16(); - st_fx->dtfs_dec_upper_cut_off_freq_fx = 4000; - move16(); - - FOR(k = 0; k < MAXLAG_WI; k++) - { - st_fx->dtfs_dec_a_fx[k] = 0; - move16(); - st_fx->dtfs_dec_b_fx[k] = 0; - move16(); - } - st_fx->dtfs_dec_Q = 0; - move16(); - } - - pl = s_min(rint_new_fx(st_fx->old_pitch_buf_fx[(2*NB_SUBFR)-1]),MAX_LAG_PIT); - delta_lag_D = (Word16) get_next_indice_fx( st_fx, 5 ); - - - l = s_min(MAX_LAG_PIT,add(pl,sub(delta_lag_D,11))); - - - temp_pl_fx = pl; - move16(); - temp_l_fx = l; - move16(); - - IF (sub(temp_pl_fx,temp_l_fx) != 0) - { - FOR(k=0; klast_coder_type_fx,UNVOICED) == 0) - { - pl = l; - move16(); /* if prev frame was sil/uv*/ - } - - temp = mult(shl(l,3),30310);/*Q3+14+1-16 = Q2 30310 is 1.85 in Q14 */ - - IF( temp >= 0 ) - { - temp = add(temp,2); - } - ELSE - { - temp = sub(temp,2); - } - temp = shr(temp,2);/*Q0 */ - - if (sub(pl,temp) > 0) - { - pl = shr(pl,1); - } - - temp = mult(shl(l,3),8857);/*Q3+14+1-16 = Q2 8847 is 0.54 in Q14 */ - IF( temp >= 0 ) - { - temp = add(temp,2); - } - ELSE - { - temp = sub(temp,2); - } - temp = shr(temp,2);/*Q0 */ - - test(); - if (sub(shl(pl,1),PIT_MAX) <= 0 && sub(pl,temp) <= 0) - { - pl = shl(pl,1); - } - - /* Restoring PPP memories when the last frame is non-PPP or full-rate PPP */ - IF (sub(st_fx->last_ppp_mode_dec_fx,1) != 0) - { - - GetSinCosTab_fx(pl, S_fx, C_fx); - DTFS_to_fs_fx(exc_fx-pl, pl, dtfs_temp_fx, temp_Fs, 0, S_fx, C_fx); - - st_fx->ph_offset_D_fx = 0 ; - move16(); - - /* Copy over PREV_CW_D into TMPDTFS */ - DTFS_copy_fx(TMPDTFS_FX, *dtfs_temp_fx); - - DTFS_car2pol_fx(TMPDTFS_FX); - - /*st_fx->lastLgainD = (float) log10(TMPDTFS->lag*DTFS_setEngyHarm(92.0,1104.5,0.0,1104.5,1.0,TMPDTFS)); */ - - L_tmp = L_deposit_h(TMPDTFS_FX->lag_fx);/*Q16 */ - exp = norm_l(L_tmp); - tmp = Log2_norm_lc(L_shl(L_tmp,exp)); - exp = (30-exp-16); - L_tmp = Mpy_32_16(exp,tmp,12330);/* Q13 */ /* 10*log10(2) in Q12*/ - logLag = L_shl(L_tmp, 10);/*Q23 */ - - Ltemp_q=L_shl(L_mult(shl(TMPDTFS_FX->Q,1),24660),9); /* Ltemp_q=2Q*10log10(2), Q23 */ - /* Process low band */ - Ltemp=DTFS_setEngyHarm_fx(236,2828,0,2828,1,0,&Ql,TMPDTFS_FX);/* Ltemp in 2*TMP.Q */ - /* Compensate for Q factor of energy to get log10(lag*eng) */ - - - Ltemp=log10_fx(Ltemp); /* Ltemp=10log10(eng), Q23 */ - Ltemp=L_add(L_sub(Ltemp,Ltemp_q),logLag); /* Ltemp=10*log10(lag*eng), Q23 */ - st_fx->lastLgainD_fx=round_fx(L_shl((Word32)Mpy_32_16(extract_h(Ltemp),extract_l(Ltemp),0x6666),1)); /* Q11 */ - - - - /* Process high band */ - Ltemp=DTFS_setEngyHarm_fx(2828,upper_cut_off_freq_of_interest,2828,upper_cut_off_freq,1,0,&Qh,TMPDTFS_FX); - - - Ltemp=log10_fx(Ltemp); - Ltemp=L_add(L_sub(Ltemp,Ltemp_q),logLag); /* Ltemp=10*log10(lag*eng), Q23 */ - st_fx->lastHgainD_fx=round_fx(L_shl((Word32)Mpy_32_16(extract_h(Ltemp),extract_l(Ltemp),0x6666),1)); /* Q11 */ - - - /* Need to unify the Q factors of both bands */ - TMPDTFS_FX->Q=s_min(Ql,Qh); /* set Q factor to be the smaller one */ - n=sub(Ql,Qh); /* compare band Q factors */ - - /*This logic adjusts difference between Q formats of both bands */ - IF (n<0) - { - rshiftHarmBand_fx(TMPDTFS_FX,2828, upper_cut_off_freq,n); - } - ELSE IF (n>0) - { - rshiftHarmBand_fx(TMPDTFS_FX,0, 2828, sub(Qh,Ql)); - } - - DTFS_to_erb_fx(*TMPDTFS_FX,st_fx->lasterbD_fx); - - } - ELSE - { - /* Copy DTFS related parameters from 'st' to 'dtfs_temp' structure */ - dtfs_temp_fx->lag_fx = st_fx->dtfs_dec_lag_fx; - move16(); - dtfs_temp_fx->nH_fx = st_fx->dtfs_dec_nH_fx; - move16(); - dtfs_temp_fx->nH_4kHz_fx = st_fx->dtfs_dec_nH_4kHz_fx; - move16(); - dtfs_temp_fx->upper_cut_off_freq_of_interest_fx = st_fx->dtfs_dec_upper_cut_off_freq_of_interest_fx; - move16(); - dtfs_temp_fx->upper_cut_off_freq_fx = st_fx->dtfs_dec_upper_cut_off_freq_fx; - move16(); - - Copy(st_fx->dtfs_dec_a_fx, dtfs_temp_fx->a_fx, MAXLAG_WI); - Copy(st_fx->dtfs_dec_b_fx, dtfs_temp_fx->b_fx, MAXLAG_WI); - dtfs_temp_fx->Q = st_fx->dtfs_dec_Q; - move16(); - } - - CURRP_Q_D_FX->lag_fx = l; - move16(); - - /* safety check in case of bit errors */ - IF( CURRP_Q_D_FX->lag_fx <= 0 ) - { - CURRP_Q_D_FX->lag_fx = 1; - move16(); - st_fx->BER_detect = 1; - move16(); - } - - /* compute nH for lag */ - Ltemp = L_shl((Word32)upper_cut_off_freq,13);/*Q28 */ - upper_cut_off_freq = (Word16)find_remd(Ltemp, 20971,&rem32);/*denormalize upper_cut_off_freq */ - - - - /* temp32_fx = (Word32)divide_dp((Word40)819200,(Word40)L_shl((Word32)CURRP_Q_D_FX->lag_fx,6),-23,1);//Q6 */ - exp = norm_s(CURRP_Q_D_FX->lag_fx); - tmp = div_s(shl(1,sub(14,exp)),CURRP_Q_D_FX->lag_fx);/*29-exp */ - L_tmp =L_shl(L_mult0(tmp,12800),exp - 7); - temp32_fx = round_fx(L_tmp); - diff = round_fx(L_shl(temp32_fx,16-6));/*Q0 */ - - CURRP_Q_D_FX->nH_fx = find_rem(upper_cut_off_freq,diff,&rem_fx);/*Q0 */ - - exp = norm_s(diff); - tmp = div_s(shl(1,sub(14,exp)),diff);/*29-exp */ - L_tmp = L_shl(L_mult0(4000,tmp),exp - 7); - tempnH_fx = extract_h(L_tmp); - CURRP_Q_D_FX->nH_4kHz_fx = round_fx(L_shl(tempnH_fx,16-6));/*Q0 */ - - - IF(sub(sub(upper_cut_off_freq,shr((Word16)L_mult(diff,CURRP_Q_D_FX->nH_fx),1)),diff)>=0) - { - CURRP_Q_D_FX->nH_fx = add(CURRP_Q_D_FX->nH_fx,1); - } - tempnH_fx = L_mult0(extract_l(temp32_fx),CURRP_Q_D_FX->nH_4kHz_fx);/* */ - tempnH_fx = L_sub((Word32)256000,tempnH_fx);/*Q6 */ - - if(L_sub(tempnH_fx,temp32_fx)>=0) - { - CURRP_Q_D_FX->nH_4kHz_fx = add(CURRP_Q_D_FX->nH_4kHz_fx,1); - } - - CURRP_Q_D_FX->upper_cut_off_freq_fx = dtfs_temp_fx->upper_cut_off_freq_fx; - move16(); - CURRP_Q_D_FX->upper_cut_off_freq_of_interest_fx = dtfs_temp_fx->upper_cut_off_freq_of_interest_fx; - move16(); - GetSinCosTab_fx(CURRP_Q_D_FX->lag_fx,S_fx,C_fx); - - IF ( bfi == 0 ) - { - ppp_quarter_decoder_fx(CURRP_Q_D_FX,dtfs_temp_fx->lag_fx,&(st_fx->lastLgainD_fx), - &(st_fx->lastHgainD_fx),st_fx->lasterbD_fx,bfi,S_fx,C_fx,*dtfs_temp_fx, st_fx); - } - - WIsyn_fx(*dtfs_temp_fx, CURRP_Q_D_FX, lpc2_fx, &(st_fx->ph_offset_D_fx), out_fx, (Word16)L_FRAME, 0, - S_fx, C_fx, pf_temp1, pf_temp2, pf_temp, pf_n2); - - DTFS_copy_fx(dtfs_temp_fx, *CURRP_Q_D_FX); - - /* Copy DTFS related parameters from 'dtfs_temp' to 'st' structure */ - st_fx->dtfs_dec_lag_fx = dtfs_temp_fx->lag_fx; - move16(); - st_fx->dtfs_dec_nH_fx = dtfs_temp_fx->nH_fx; - move16(); - st_fx->dtfs_dec_nH_4kHz_fx = dtfs_temp_fx->nH_4kHz_fx; - move16(); - st_fx->dtfs_dec_upper_cut_off_freq_of_interest_fx = dtfs_temp_fx->upper_cut_off_freq_of_interest_fx; - move16(); - st_fx->dtfs_dec_upper_cut_off_freq_fx = dtfs_temp_fx->upper_cut_off_freq_fx; - move16(); - - Copy(dtfs_temp_fx->a_fx, st_fx->dtfs_dec_a_fx, MAXLAG_WI); - Copy(dtfs_temp_fx->b_fx, st_fx->dtfs_dec_b_fx, MAXLAG_WI); - - st_fx->dtfs_dec_Q = dtfs_temp_fx->Q; - move16(); - - free(TMPDTFS_FX); - free(CURRP_Q_D_FX); - free(dtfs_temp_fx); - - return; -} diff --git a/src/libs/libevs/lib_dec/voip_client.cpp b/src/libs/libevs/lib_dec/voip_client.cpp old mode 100755 new mode 100644 index a53ad9e5..2ac31128 --- a/src/libs/libevs/lib_dec/voip_client.cpp +++ b/src/libs/libevs/lib_dec/voip_client.cpp @@ -1,5 +1,5 @@ /*==================================================================================== - EVS Codec 3GPP TS26.442 Apr 03, 2018. Version 12.11.0 / 13.6.0 / 14.2.0 + EVS Codec 3GPP TS26.443 Nov 13, 2018. Version 12.11.0 / 13.7.0 / 14.3.0 / 15.1.0 ====================================================================================*/ #include @@ -8,10 +8,9 @@ #include #include #include "options.h" -#include "stl.h" -#include "prot_fx.h" -#include "cnst_fx.h" -#include "basop_util.h" +#include "prot.h" +#include "cnst.h" +#include "rom_com.h" #include "EvsRXlib.h" #include "g192.h" @@ -25,6 +24,7 @@ extern long frame; /* Counter of frames */ * Local constants *------------------------------------------------------------------------------------------*/ +#define PCMBUFSIZE 1920 /*------------------------------------------------------------------------------------------* * decodeVoip() @@ -32,41 +32,40 @@ extern long frame; /* Counter of frames */ * Main function for EVS decoder with VOIP mode *------------------------------------------------------------------------------------------*/ -Word16 decodeVoip( - Decoder_State_fx *st_fx, +int decodeVoip( + Decoder_State *st, FILE *f_stream, FILE *f_synth, #ifdef SUPPORT_JBM_TRACEFILE const char *jbmTraceFileName, #endif const char *jbmFECoffsetFileName, /* : Output file for Optimum FEC offset */ - const Word16 quietMode + const short quietMode ) { /* input/output */ G192_HANDLE g192 = NULL; G192_ERROR g192err; - Word16 optimum_offset, FEC_hi; - FILE *f_offset = 0; + short optimum_offset,FEC_hi; + FILE *f_offset = NULL; /* main loop */ - Word32 nextPacketRcvTime_ms = 0; - Word32 systemTime_ms = 0; + unsigned int nextPacketRcvTime_ms = 0; + unsigned int systemTime_ms = 0; EVS_RX_HANDLE hRX = NULL; EVS_RX_ERROR rxerr = EVS_RX_NO_ERROR; Word16 jbmSafetyMargin = 60; /* allowed delay reserve in addition to network jitter to reduce late-loss [milliseconds] */ - Word16 dec_delay, zero_pad; + short dec_delay, zero_pad; unsigned char au[2560]; - Word16 auSize; - Word16 rtpSequenceNumber; - Word32 rtpTimeStamp; - - Word16 pcmBuf[3 * L_FRAME48k] = {0}; - Word16 pcmBufSize = 3 * L_FRAME48k; + short auSize; + unsigned short rtpSequenceNumber; + unsigned int rtpTimeStamp; + Word16 pcmBuf[3 * L_FRAME48k] = {0}; + unsigned int pcmBufSize = 3 * L_FRAME48k; /* open input file */ g192err = G192_Reader_Open(&g192, f_stream); @@ -76,6 +75,7 @@ Word16 decodeVoip( return -1; } + if(jbmFECoffsetFileName) { f_offset = fopen( jbmFECoffsetFileName, "w+" ); @@ -87,35 +87,33 @@ Word16 decodeVoip( } } - /* initialize receiver */ - rxerr = EVS_RX_Open(&hRX, st_fx, jbmSafetyMargin); + /* initialize receiver (wraps decoder) */ + rxerr = EVS_RX_Open(&hRX, st, jbmSafetyMargin); if(rxerr) { fprintf(stderr,"unable to open receiver\n"); G192_Reader_Close(&g192); - if( f_offset ) fclose(f_offset); + if( f_offset ) fclose (f_offset); return -1; } #ifdef SUPPORT_JBM_TRACEFILE rxerr = EVS_RX_SetJbmTraceFileName(hRX, jbmTraceFileName); if(rxerr) { - fprintf(stderr,"unable to set JBM trace file: %s\n", jbmTraceFileName); + fprintf(stderr,"unable to set JBM trace file name: %s\n", jbmTraceFileName); G192_Reader_Close(&g192); - if( f_offset ) fclose(f_offset); + if( f_offset ) fclose (f_offset); EVS_RX_Close(&hRX); return -1; } #endif + /* calculate the delay compensation to have the decoded signal aligned with the original input signal */ /* the number of first output samples will be reduced by this amount */ - dec_delay = NS2SA_fx2(st_fx->output_Fs_fx, get_delay_fx(DEC, st_fx->output_Fs_fx)); + dec_delay = NS2SA(st->output_Fs, get_delay(DEC, st->output_Fs) + 0.5f); zero_pad = dec_delay; - /* start WMOPS counting for decoding process only */ - BASOP_end_noprint - BASOP_init /* read first packet */ g192err = G192_ReadVoipFrame_compact(g192, au, &auSize, @@ -124,7 +122,7 @@ Word16 decodeVoip( { fprintf(stderr,"failed to read first RTP packet\n"); G192_Reader_Close(&g192); - if( f_offset ) fclose(f_offset); + if( f_offset ) fclose (f_offset); EVS_RX_Close(&hRX); return -1; } @@ -142,14 +140,9 @@ Word16 decodeVoip( /* main receiving/decoding loop */ for( ; ; ) { - Word16 nSamples = 0; -#if (WMOPS) - fwc(); - Reset_WMOPS_counter(); -#endif - + unsigned int nSamples = 0; /* read all packets with a receive time smaller than the system time */ - while( nextPacketRcvTime_ms != -1 && nextPacketRcvTime_ms <= systemTime_ms ) + while( nextPacketRcvTime_ms <= systemTime_ms ) { /* feed the previous read packet into the receiver now */ rxerr = EVS_RX_FeedFrame(hRX, au, auSize, rtpSequenceNumber, rtpTimeStamp, @@ -158,7 +151,7 @@ Word16 decodeVoip( { printf("\nerror in feeding access unit: %8x", rxerr); G192_Reader_Close(&g192); - if( f_offset ) fclose(f_offset); + if( f_offset ) fclose (f_offset); EVS_RX_Close(&hRX); return -1; } @@ -168,28 +161,30 @@ Word16 decodeVoip( if(g192err == G192_EOF) { /* finished reading */ - nextPacketRcvTime_ms = -1; + nextPacketRcvTime_ms = (unsigned int) -1; } else if(g192err != G192_NO_ERROR) { fprintf(stderr,"failed to read RTP packet\n"); G192_Reader_Close(&g192); - if( f_offset ) fclose(f_offset); + if( f_offset ) fclose (f_offset); EVS_RX_Close(&hRX); return -1; } } /* we are finished when all packets have been received and jitter buffer is empty */ - if( nextPacketRcvTime_ms == -1 && EVS_RX_IsEmpty(hRX) ) + if( nextPacketRcvTime_ms == (unsigned int)(-1) && EVS_RX_IsEmpty(hRX) ) break; /* decode and get samples */ - rxerr = EVS_RX_GetSamples(hRX, &nSamples, pcmBuf, pcmBufSize, systemTime_ms); + rxerr = EVS_RX_GetSamples(hRX, &nSamples, pcmBuf, pcmBufSize, systemTime_ms + ); + EVS_RX_Get_FEC_offset(hRX, &optimum_offset, &FEC_hi); - if ( st_fx->writeFECoffset == 1 && f_offset ) + if ( st->writeFECoffset == 1 && f_offset ) { if ( FEC_hi == 1) { @@ -220,7 +215,6 @@ Word16 decodeVoip( fprintf( f_offset, "%d\n", optimum_offset ); } - if(rxerr != EVS_RX_NO_ERROR) { printf("\nerror in getting samples: %8x", rxerr); @@ -230,25 +224,23 @@ Word16 decodeVoip( return -1; } - /* write the synthesized signal into output file */ - /* do final delay compensation */ - IF ( dec_delay == 0 ) + if ( dec_delay == 0 ) { fwrite( pcmBuf, sizeof(Word16), nSamples, f_synth ); } - ELSE + else { - IF ( sub(dec_delay, nSamples) <= 0 ) + if ( dec_delay <= (short)nSamples ) { - fwrite( pcmBuf + dec_delay, sizeof(Word16), sub(nSamples, dec_delay), f_synth ); + fwrite( pcmBuf + dec_delay, sizeof(Word16), nSamples - dec_delay, f_synth ); dec_delay = 0; - move16(); } - ELSE + else { - dec_delay = sub(dec_delay, nSamples); + dec_delay -= nSamples; } } + frame++; if( quietMode == 0 ) { @@ -258,10 +250,10 @@ Word16 decodeVoip( } /* add zeros at the end to have equal length of synthesized signals */ - set16_fx( pcmBuf, 0, zero_pad ); + set_s( pcmBuf, 0, zero_pad ); fwrite( pcmBuf, sizeof(Word16), zero_pad, f_synth ); - if( quietMode == 0 ) + if (quietMode == 0) { fprintf( stdout, "\n\n" ); fprintf( stdout, "Decoding finished\n\n" ); @@ -270,15 +262,12 @@ Word16 decodeVoip( { fprintf( stdout, "Decoding of %ld frames finished\n\n", frame ); } - - /* end of WMOPS counting */ - BASOP_end + fprintf( stdout, "\n\n" ); /* free memory etc. */ - BASOP_init G192_Reader_Close(&g192); EVS_RX_Close(&hRX); - BASOP_end_noprint return 0; } + diff --git a/src/libs/libevs/lib_dec/waveadjust_fec_dec.cpp b/src/libs/libevs/lib_dec/waveadjust_fec_dec.cpp old mode 100755 new mode 100644 index 9a01083b..292c82a4 --- a/src/libs/libevs/lib_dec/waveadjust_fec_dec.cpp +++ b/src/libs/libevs/lib_dec/waveadjust_fec_dec.cpp @@ -1,1601 +1,782 @@ /*==================================================================================== - EVS Codec 3GPP TS26.442 Apr 03, 2018. Version 12.11.0 / 13.6.0 / 14.2.0 + EVS Codec 3GPP TS26.443 Nov 13, 2018. Version 12.11.0 / 13.7.0 / 14.3.0 / 15.1.0 ====================================================================================*/ -#include -#include -#include +#include "options.h" +#include #include -#include "prot_fx.h" -#include "basop_util.h" -#include "stat_com.h" -#include "stl.h" /* FOR wmc_tool */ - -void get_maxConv_and_pitch_x(Word16 *s_LP, Word16 s, Word16 e, Word16 N, - Word32 *maxConv, Word16 *maxConv_bits, Word16 *pitch); -Word16 get_voicing_x(Word16 *s_LP, Word16 pitch, Word32 covMax,Word16 maxConv_bits, Word16 Framesize); -Word32 con_Log10(Word32 i_s32Val, Word16 i_s16Q); +#include +#include +#include +#include "prot.h" -Word16 vadmin(Word16 a, Word16 b) + +static void LpFilter2(float *x, float *y, int N, float *mem); +static float harmo(float *X, int n, float f); +static int Is_Periodic(float cov_max, int zp, float ener, float ener_mean,int pitch, int Framesize, float *mdctdata); +static float sig_tilt(float *s, int FrameSize); +static int zero_pass(float *s, int N); +static float dot(float *a, float *b, int N); +static int array_max_indx(float *s, int N); + +/* Decoder side */ +static void LpFilter2(float *x, float *y, int N, float *mem) { - return s_min(a, b); -} - -void set_state(Word16 *state, Word16 num, Word16 N) -{ - Word16 i, tmp; - - tmp = sub(N, 1); - FOR (i = 0; i < tmp; i++) + int i; + y[0] = 0.18f * mem[0] + 0.64f * mem[1] + 0.18f * x[0]; + y[1] = 0.18f * mem[1] + 0.64f * y[0] + 0.18f * x[1]; + for (i = 2; i < N; i++) { - state[i] = state[i+1]; - move16(); + y[i] = 0.18f * y[i-2] + 0.64f * y[i-1] + 0.18f * x[i]; } - state[tmp] = num; - move16(); } -void concealment_update_x(Word16 bfi, Word16 curr_mode, Word16 tonality, Word32 *invkoef, Word16 *invkoef_scale, void *_plcInfo) +static float harmo(float *X, int n, float f) { - T_PLCInfo *plcInfo = (T_PLCInfo*)_plcInfo; - Word32 *data_reci2 = plcInfo->data_reci2_fx; - Word16 *tcx_tonality = plcInfo->TCX_Tonality; - Word16 FrameSize = plcInfo->FrameSize; - Word16 subframe = plcInfo->subframe_fx; - Word16 i; - move16(); - move16(); - IF (sub(curr_mode ,1)==0) + int h, k, m = 8; + float ener = 0, ener_harmo = 0; + for (k = 1; k < m+1; k++) { - set_state(plcInfo->Transient, curr_mode, MAX_POST_LEN); - - FOR (i = 0; i < FrameSize; i++) + h = (int)(k*f - 0.5f); + if (k*f - h > 0.5f) { - data_reci2[i] = invkoef[i]; - move32(); - + ener_harmo += X[h]*X[h] + X[h+1]*X[h+1]; } - plcInfo->data_reci2_scale = *invkoef_scale; - move16(); - IF (!bfi) + else { - set_state(tcx_tonality, tonality, DEC_STATE_LEN); + ener_harmo += X[h]*X[h]; } } - ELSE + for (k = 0; k < n; k++) { - - IF (subframe == 0) - { - set_state(plcInfo->Transient, curr_mode, MAX_POST_LEN); - - IF (!bfi) - { - set_state(tcx_tonality, tonality, DEC_STATE_LEN); - } - } - /* don't store the second subframe during frameloss; in - pitch_search_fx(), low_freq_rate is derived on the last good - TCX-10 spectrum */ - test(); - IF (!bfi || subframe == 0) - { - - Word32 *ptr = data_reci2+subframe; - Word16 FrameSize2 = shr(FrameSize,1); - - FOR (i = 0; i < FrameSize2; i++) - { - ptr[i] = invkoef[i]; - move32(); - } - - plcInfo->data_reci2_scale = *invkoef_scale; - move16(); - } + ener += X[k]*X[k]; } - return; + return ener_harmo/(ener+EPSILON); } -static Word16 zero_pass_w32_x(Word16 *s, Word16 N) +static int Is_Periodic(float cov_max, int zp, float ener, float ener_mean,int pitch, int Framesize, float *mdctdata) { - Word16 i; - Word32 temp, zp = L_deposit_l(0); - - FOR (i = 1; i < N; i++) - { - temp = L_mac0(-1L, s[i],s[i-1]); - zp = L_sub(zp, L_shr(temp,31)); - } - return extract_l(zp); -} - -Word16 Sqrt_x_fast(Word32 value) -{ - Word16 norm; - Word16 result, index; - - norm = sub(23, norm_l(value)); - index = extract_l( L_shr_r(value, add(norm, s_and(norm, 1)))); - result = shr(sqrt_table_pitch_search[index], sub(11, shr(add(norm,1),1))); - return result; -} - -Word32 dot_w32_accuracy_x(Word16 *s1, Word16 *s2, Word16 nbits, Word16 N) -{ - Word16 i; - Word32 eng = L_deposit_l(0), temp; - - FOR (i = 0; i < N; i++) - { - temp = L_mult0(s1[i], s2[i]); - eng = L_add(eng, L_shr(temp,nbits)); - } - - return eng; -} - - -Word16 int_div_s_x(Word16 a, Word16 b) -{ - Word16 result = 0; - Word16 norm, left=0, i; - move16(); - move16(); - test(); - IF (sub(a,b) < 0 || b == 0) - { - return 0; - } - ELSE - { - a = add(a, shr(b,1)); - norm = sub(norm_s(b),norm_s(a)); - - FOR (i = norm; i>= 0; i--) - { - left = shr(a, i); - result = shl(result,1); - IF (sub(left,b) >= 0) - { - result = add(result,1); - left= sub(left, b); - a = add(shl(left,i), s_and(a, sub(shl(1,i),1))); - } - } - } - - return result; -} - -Word16 GetW32Norm_x(Word32 *s, Word16 N) -{ - Word32 smax = L_deposit_l(0); - Word16 smax_norm, i; - - FOR (i = 0; i < N; i++) - { - smax = L_or(smax, L_abs(s[i])); - } - - smax_norm = norm_l(smax); - - return smax_norm; -} - -Word16 harmo_x(Word32 *X, Word16 Framesize, Word16 pitch) -{ - Word16 h, k, result = 0; - Word32 ener = L_deposit_l(0), ener_harmo = L_deposit_l(0); - Word16 norm1, d1, d2; - Word16 ener_w, ener_harmo_w; - Word16 nbits = sub(15, norm_s(Framesize)); - move16(); - norm1 = GetW32Norm_x(X, Framesize); - - FOR (k = 1; k < 9; k++) - { - h = sub(int_div_s_x(extract_l(L_mult(k, Framesize)), pitch),1); - - d1 = extract_h(L_shl(X[h], norm1)); - d2 = extract_h(L_shl(X[h+1],norm1)); - - ener_harmo = L_add(ener_harmo, - L_shr(L_mac0(L_mult0(d1, d1), d2, d2),nbits)); - } - - FOR (k = 0; k < Framesize; k++) - { - d1 = extract_h(L_shl(X[k],norm1)); - ener = L_add(ener, L_shr(L_mult0(d1, d1),nbits)); - } - - norm1 = norm_l(ener); - ener_w = extract_h(L_shl(ener,norm1)); - ener_harmo_w = extract_h(L_shl(ener_harmo,norm1)); - - IF (L_sub(ener_harmo ,ener)>= 0) - { - return 32767; - } - test(); - IF ((ener_harmo_w <= 0)||(ener_w <= 0)) - { - return 0; - } - result = div_s(ener_harmo_w, ener_w); - return result; -} - -static -Word16 get_low_freq_eng_rate_x(Word32 *mdct_data, - Word16 curr_mode, - Word16 N) -{ - Word16 N1, N2, i; - Word32 low_eng = L_deposit_l(0), eng = L_deposit_l(0), smax = L_deposit_l(0); - Word16 nbits, temp, norm = 0; - move16(); - N1 = 30; - N2 = N; - move16(); - move16(); - IF (sub(2 ,curr_mode)==0) - { - N1 = shr(30,1); - N2 = shr(N,1); - } - - nbits = sub(15, norm_s(N2)); - - FOR (i = 0; i < N2; i++) - { - smax = L_or(smax, L_abs(mdct_data[i])); - } - - norm = norm_l(smax); - - FOR (i = 0; i < N1; i++) - { - temp = extract_h(L_shl(mdct_data[i], norm)); - low_eng = L_add(low_eng, L_shr(L_mult0(temp, temp),nbits)); - } - - FOR (i = N1; i < N2; i++) - { - temp = extract_h(L_shl(mdct_data[i], norm)); - eng = L_add(eng, L_shr(L_mult0(temp, temp),nbits)); - } - eng = L_add(low_eng, eng); - - /* IF (low_eng<(eng+EPSILON)*0.02) return 1;ELSE return 0; */ - /* smax=eng*0.02 */ - smax = L_shr(Mpy_32_16_1(eng, 5243), 3); - - return (L_sub(low_eng,smax) <= 0); -} - -void LpFilter2_x(Word16 *x, Word16 *y, Word16 N) -{ - Word16 i; - Word16 smax, norm; - Word16 a1 = 5898; /* W16(0.18f); */ - Word16 a2 = 20971; /* W16(0.64f); */ - move16(); - move16(); - smax=0; - move16(); - FOR (i = 0; i < N; i++) - { - smax = s_or(smax, abs_s(x[i])); - } - norm = norm_s(smax); - - y[0] = mult(shl(x[0],norm), a1); - move16(); - y[1] = add(mult(y[0], a2),mult(shl(x[1],norm), a1)); - move16(); - - FOR (i = 2; i < N; i++) - { - /* 5898*2+20971=32767 -->no overflow */ - y[i] = add(mult(y[i-2],a1), add(mult(y[i-1],a2), mult(shl(x[i],norm),a1))); - move16(); - } -} - -void sig_tilt_x(Word16 *s, Word16 FrameSize, Word32 *enr1, Word32 *enr2) -{ - Word16 subFrameSize, shIFt; - Word16 *p1, *p2; - Word16 nbits; - - subFrameSize = shr(FrameSize, 2); - p1 = s+subFrameSize; - p2 = s+sub(subFrameSize, 2); - - shIFt = sub(FrameSize, subFrameSize); - nbits = sub(15, norm_s(shIFt)); - *enr1 = dot_w32_accuracy_x(p1, p2, nbits, shIFt); - move32(); - *enr2 = dot_w32_accuracy_x(p1, p1, nbits, shIFt); - move32(); -} - -void get_maxConv_and_pitch_x(Word16 *s_LP, Word16 s, Word16 e, Word16 N, - Word32 *maxConv, Word16 *maxConv_bits, Word16 *pitch) -{ - Word16 t, cov_size, size = N; - Word32 tmp_sigma = L_deposit_l(0), cov_max_sigma = L_deposit_l(0); - Word16 nbits,tmp_pitch=0; - Word32 r1_high, r2_high; - UWord16 r1_low, r2_low; - Word32 tmp_sigma_last = L_deposit_l(0); /* not needed, just to avoid compiler warning */ - Word16 cov_size_last = N; /* not needed, just to avoid compiler warning */ - Word32 cov_max_sigma_tmp = L_deposit_l(0); - Word16 size_tmp = N; - move16(); - move16(); - nbits = sub(15, norm_s(sub(N, s))); - - FOR (t = s; t < e; t++) - { - cov_size = sub(N,t); - tmp_sigma = dot_w32_accuracy_x(s_LP, s_LP+t, nbits, cov_size); - - IF (sub(t,s) > 0) /* don't use the first value */ - { - Mpy_32_16_ss(tmp_sigma , cov_size_last, &r1_high, &r1_low); - Mpy_32_16_ss(tmp_sigma_last, cov_size , &r2_high, &r2_low); - /* tmp_sigma > tmp_sigma_last */ - test(); - test(); - move16(); - move16(); /* moves are for the (Word32) casts */ - IF((L_sub(r1_high, r2_high) > 0) || - (L_sub(r1_high, r2_high) == 0 && L_sub((Word32)r1_low, (Word32)r2_low) > 0)) - { - /* store the current cov, if it is larger than the last one */ - cov_max_sigma_tmp = tmp_sigma; - move32(); - size_tmp = cov_size; - move16(); - } - ELSE - { - Mpy_32_16_ss(cov_max_sigma , size_tmp, &r1_high, &r1_low); - Mpy_32_16_ss(cov_max_sigma_tmp, size , &r2_high, &r2_low); - /* cov_max_sigma < cov_max_sigma_tmp */ - test(); - test(); - move16(); - move16(); /* moves are for the (Word32) casts */ - IF((L_sub(r1_high, r2_high) < 0) || - (L_sub(r1_high, r2_high) == 0 && L_sub((Word32)r1_low, (Word32)r2_low) < 0)) - { - /* otherwise */ - /* use the last value of cov, being a max */ - cov_max_sigma = cov_max_sigma_tmp; - move32(); - size = cov_size; - move16(); - /* and use the last index as pitch */ - tmp_pitch = sub(t,1); - } - } - } - tmp_sigma_last = tmp_sigma; - move32(); - cov_size_last = cov_size; - move16(); - } - *pitch = tmp_pitch; - move16(); - *maxConv = cov_max_sigma; - move32(); - *maxConv_bits = nbits; - move16(); -} - -Word16 get_voicing_x(Word16 *s_LP, Word16 pitch, Word32 covMax,Word16 maxConv_bits, Word16 Framesize) -{ - Word32 eng1 = L_deposit_l(0), eng2 = L_deposit_l(0); - Word16 voicing, norm; - Word16 tmpLen, nbits; - Word16 eng1_w, eng2_w; - - IF (covMax <= 0) - { - return 0; - } - ELSE - { - tmpLen = sub(Framesize, pitch); - nbits = maxConv_bits; - move16(); - - eng1 = dot_w32_accuracy_x(s_LP, s_LP, nbits, tmpLen); - eng2 = dot_w32_accuracy_x(s_LP+pitch, s_LP+pitch, nbits, tmpLen); - - norm = sub(norm_l(L_or(eng1, L_or(eng2, covMax))),1); - eng1 = L_shl(eng1, norm); - eng2 = L_shl(eng2, norm); - covMax = L_shl(covMax, norm); - - eng1_w = Sqrt_x_fast(eng1); - eng2_w = Sqrt_x_fast(eng2); - - eng1 = L_mult0(eng1_w, eng2_w); - norm = norm_l(eng1); - eng1_w = extract_h(L_shl(eng1, norm)); - eng2_w = extract_h(L_shl(covMax, norm)); - - IF (L_sub(covMax , eng1)>=0) - { - return 32767; - } - test(); - IF ((eng2_w <= 0)||(eng1_w <= 0)) - { - return 0; - } - voicing = div_s(eng2_w, eng1_w); - - return voicing; - } -} - -void pitch_modify_x(Word16 *s_LP, Word16 *voicing, Word16 *pitch, Word16 FrameSize) -{ - Word32 eng1, eng2, eng3; - Word16 shIFt = shr(*pitch ,1); - Word16 tmpLen, nbits, norm, voicing2; - Word16 eng1_w, eng2_w; - - tmpLen = sub(FrameSize, shIFt); - nbits = sub(15, norm_s(tmpLen)); - - eng1 = dot_w32_accuracy_x(s_LP+shIFt, s_LP+shIFt, nbits, tmpLen); - eng2 = dot_w32_accuracy_x(s_LP, s_LP, nbits, tmpLen); - eng3 = dot_w32_accuracy_x(s_LP+shIFt, s_LP, nbits, tmpLen); - - IF (eng3 <= 0) - { - return ; - } - - norm = sub(norm_l(L_or(eng1, L_or(eng2, eng3))),1); - eng1 = L_shl(eng1, norm); - eng2 = L_shl(eng2, norm); - eng3 = L_shl(eng3, norm); - - eng1_w = Sqrt_x_fast(eng1); - eng2_w = Sqrt_x_fast(eng2); - - eng1 = L_mult0(eng1_w, eng2_w); - - norm = norm_l(eng1); - eng1_w = extract_h(L_shl(eng1, norm)); - eng2_w = extract_h(L_shl(eng3, norm)); - - IF (L_sub(eng3,eng1) >= 0) - { - voicing2 = 32767; - move16(); - } - ELSE { test(); - IF ((eng2_w <= 0)||(eng1_w <= 0)) - { - voicing2 = 0; - move16(); - } - ELSE { - voicing2 = div_s(eng2_w, eng1_w); - } - } - - IF (sub(voicing2, *voicing) > 0) - { - *pitch = shIFt; - move16(); - *voicing = voicing2; - move16(); - } -} - -Word16 Is_Periodic_x(Word32 *mdct_data, Word16 cov_max, Word16 zp, Word32 ener, - Word32 ener_mean, Word16 pitch, Word16 Framesize) -{ - Word16 flag =0; - Word16 harm; - move16(); - test(); - test(); - test(); - IF (L_sub(ener, L_shl(50,8)) < 0 || (L_sub(ener, L_sub(ener_mean, L_shl(8,8))) < 0 - && sub(cov_max, 29491) < 0 )) + int flag =0; + float f = 2.0f*Framesize/pitch; + float harm; + harm = harmo(mdctdata /*X*/, Framesize, f); + if (ener < 50 || (ener < ener_mean - 8.0f && cov_max < 0.9f)) { flag = 0; - move16(); } - ELSE IF (sub(cov_max, 26214) > 0) + else if (cov_max > 0.8f) { flag = 1; - move16(); } - ELSE IF (sub(zp, 100) > 0) + else if (zp > 100) { flag = 0; - move16(); } - ELSE IF (L_sub(ener, L_sub(ener_mean,L_shl(6,8))) < 0) + else if (ener < ener_mean - 6) { flag = 0; - move16(); } - ELSE IF (L_sub(ener, L_add(ener_mean, L_shl(1,8))) > 0 && sub(cov_max, 19661) > 0) + else if (ener > ener_mean + 1 && cov_max > 0.6f) { flag = 1; - move16(); } - ELSE + else if (harm < 0.7f) { - harm = harmo_x(mdct_data, Framesize, pitch); - flag = 1; - move16(); - if (sub(harm, 22938) < 0) - { - flag = 0; - move16(); - } + flag = 0; + } + else + { + flag = 1; } - return flag; } -Word16 get_conv_relation_x(Word16 *s_LP, Word16 shIFt, Word16 N) +static int zero_pass(float *s, int N) { - Word32 eng1,eng2, eng3; - Word16 eng1_w, eng2_w; - Word16 tmp, norm, nbits; - - nbits = sub(15, norm_s(N)); - eng3 = dot_w32_accuracy_x(s_LP, s_LP+shIFt, nbits, N); - - IF (eng3 <= 0) + int zp = 0, i; + for (i = 1; i < N; i++) { - return 0; - } - - eng1 = dot_w32_accuracy_x(s_LP+shIFt, s_LP+shIFt, nbits, N); - eng2 = dot_w32_accuracy_x(s_LP, s_LP, nbits, N); - - norm = sub(norm_l(L_or(eng1, L_or(eng2, eng3))),1); - eng1 = L_shl(eng1, norm); - eng2 = L_shl(eng2, norm); - eng3 = L_shl(eng3, norm); - - eng1_w = Sqrt_x_fast(eng1); - eng2_w = Sqrt_x_fast(eng2); - - eng1 = L_mult0(eng1_w, eng2_w); - - norm = norm_l(eng1); - eng1_w = extract_h(L_shl(eng1, norm)); - eng2_w = extract_h(L_shl(eng3, norm)); - - IF (L_sub(eng3, eng1) >= 0) - { - return 32767; - } - test(); - IF ((eng2_w <= 0)||(eng1_w <= 0)) - { - return 0; - } - - tmp = div_s(eng2_w, eng1_w); - - return tmp; -} - -static -Word16 pitch_search_fx(Word16 *s, /* lastPcmOut */ - Word16 *outx_new, - Word16 Framesize, - Word16 *voicing, - Word16 zp, - Word32 ener, - Word32 ener_mean, - Word32 *mdct_data, - Word16 curr_mode - ) -{ - Word16 pitch = 0; - Word32 cov_max = L_deposit_l(0), tilt_enr1, tilt_enr2; - Word16 s_LP[L_FRAME_MAX]; - Word16 start_pos, end_pos; - Word16 low_freq_rate_result; - Word16 flag = 0, zp_current; - Word32 *mdctPtr; - Word16 curr_frmsize; - Word16 cov_max_bits=0; - Word16 i; - move16(); - move16(); - move16(); - *voicing = 0; - move16(); - curr_frmsize = Framesize; - move16(); - if (sub(2, curr_mode) == 0) - { - curr_frmsize = shr(Framesize, 1); - } - - zp_current = zero_pass_w32_x(outx_new, curr_frmsize); - - if (sub(2, curr_mode) == 0) - { - zp_current = shl(zp_current,1); - } - IF (sub(Framesize, 256) <= 0) - { - IF (sub(zp_current, 70) > 0) + if (s[i-1] * s[i] <= 0) { - return 0; + zp++; } } - ELSE - { - IF (sub(zp_current, 105) > 0) - { - return 0; - } - } - - mdctPtr = mdct_data; - if (sub(2, curr_mode) == 0) - { - mdctPtr = mdct_data + shr(Framesize,1); - } - - low_freq_rate_result = get_low_freq_eng_rate_x(mdctPtr, - curr_mode, - Framesize); - - IF(low_freq_rate_result) - { - return 0; - } - - LpFilter2_x(s, s_LP, Framesize); - sig_tilt_x(s_LP, Framesize, &tilt_enr1, &tilt_enr2); - IF (sub(Framesize, 320) <= 0) - { - test(); - IF ((0==tilt_enr2) || - (L_sub(tilt_enr1, L_shr(tilt_enr2, 1)) < 0)) - { - return 0; - } - } - ELSE - { - test(); - IF ((0==tilt_enr2) || - (L_sub(tilt_enr1, Mpy_32_16_1(tilt_enr2, 22938)) < 0)) - { - return 0; - } - } - - IF (sub(Framesize, 320) <= 0) - { - start_pos = extract_l(L_shr(L_mac0(0x80, 34, Framesize), 8)); - end_pos = extract_l(L_shr(L_mac0(0x2 , 3, Framesize), 2)); - get_maxConv_and_pitch_x(s_LP, start_pos, end_pos, Framesize, &cov_max, &cov_max_bits, &pitch); - *voicing = get_voicing_x(s_LP, pitch, cov_max, cov_max_bits, Framesize); - move16(); - pitch_modify_x(s_LP, voicing, &pitch, Framesize); - } - ELSE - { - Word16 s_tmp[L_FRAME_MAX]; - Word16 Framesize_tmp; - Word16 pitch_tmp[3]; - Word16 cov_size; - - Framesize_tmp = shr(Framesize, 1); - FOR (i = 0; i < Framesize_tmp; i++) - { - s_tmp[i] = s_LP[2*i]; - move16(); - } - - start_pos = extract_l( L_shr(L_mac0(0x80, 34, Framesize_tmp), 8)); - end_pos = extract_l( L_shr(L_mac0(0x2, 3, Framesize_tmp), 2)); - - cov_max = L_deposit_l(0); - pitch = 0; - move16(); - get_maxConv_and_pitch_x(s_tmp, start_pos, end_pos, Framesize_tmp, &cov_max, &cov_max_bits, &pitch); - - IF (pitch > 0) - { - pitch_tmp[0] = 0; - move16(); - if (sub(shl(pitch, 1), 1) > 0) - { - pitch_tmp[0] = sub(shl(pitch, 1), 1); - move16(); - } - pitch_tmp[1] = shl(pitch, 1); - move16(); - pitch_tmp[2] = add(shl(pitch, 1), 1); - move16(); - start_pos = 0; - move16(); - pitch = 0; - move16(); - FOR (i = 0; i < 3; i++) - { - cov_size = sub(Framesize, pitch_tmp[i]); - end_pos = get_conv_relation_x(s_LP, pitch_tmp[i], cov_size); - IF (sub(end_pos, start_pos) > 0) - { - start_pos = end_pos; - move16(); - pitch = pitch_tmp[i]; - move16(); - } - } - *voicing = start_pos; - move16(); - } - } - - IF (pitch > 0) - { - flag = Is_Periodic_x(mdct_data, *voicing, zp, ener, ener_mean, pitch, Framesize); - } - if (flag == 0 ) - { - pitch = 0; - move16(); - } - return pitch; + return zp; } -void concealment_init_x(Word16 N, void *_plcInfo) +static float dot(float *a, float *b, int N) { - T_PLCInfo *plcInfo = (T_PLCInfo*)_plcInfo; - Word16 i; - - plcInfo->FrameSize = N; - move16(); - plcInfo->Pitch_fx = 0; - move16(); - plcInfo->T_bfi_fx = 0; - move16(); - plcInfo->outx_new_n1_fx = 0; - move16(); - plcInfo->nsapp_gain_fx = 0; - move16(); - plcInfo->nsapp_gain_n_fx = 0; - move16(); - plcInfo->ener_mean_fx = L_deposit_l(15213); /*Q8 59.4260f*256*/ - plcInfo->ener_fx = L_deposit_l(0); - plcInfo->zp_fx = N; - move16(); - plcInfo->recovery_gain = 0; - move16(); - plcInfo->step_concealgain_fx = 0; - move16(); - plcInfo->concealment_method = TCX_NONTONAL; - move16(); - plcInfo->subframe_fx = 0; - move16(); - plcInfo->nbLostCmpt = L_deposit_l(0); - plcInfo->seed = 21845; - move16(); - - FOR (i = 0; i < TCX_TONALITY_INIT_CNT; i++) + float sum = 0; + int i; + for (i = 0; i < N; i++) { - plcInfo->TCX_Tonality[i] = 1; - move16(); + sum += (float)(a[i] * b[i]); } - FOR (i = TCX_TONALITY_INIT_CNT; i < DEC_STATE_LEN; i++) - { - plcInfo->TCX_Tonality[i] = 0; - move16(); - } - - FOR (i = 0; i < MAX_POST_LEN; i++) - { - plcInfo->Transient[i] = 1; - move16(); - } - - FOR (i = 0; i < L_FRAME_MAX; i++) - { - plcInfo->data_reci2_fx[i] = L_deposit_l(0); - } - return; + return sum; } -static Word16 own_random_fix( /* o : output random value */ - Word16 *seed /* i/o: random seed */ -) +static int array_max_indx(float *s, int N) { - *seed = extract_l(L_mac0(13849L, *seed , 31821)); - return(*seed); -} - -void concealment_decode_fix(Word16 curr_mode, Word32 *invkoef, Word16 *invkoef_scale,void *_plcInfo) -{ - T_PLCInfo *plcInfo = (T_PLCInfo*)_plcInfo; - Word16 i; - Word16 N = plcInfo->FrameSize; - Word16 *seed = &(plcInfo->seed); - Word16 sign; - move16(); - IF (plcInfo->concealment_method == TCX_NONTONAL) /* #define TCX_NONTONAL 0 */ + int i, indx = 0; + for (i = 0; i < N; i++) { - IF (sub(curr_mode, 1) == 0) - { - /* copy the data of the last frame */ - mvr2r_Word32(plcInfo->data_reci2_fx, invkoef, N); - *invkoef_scale = plcInfo->data_reci2_scale; - move16(); - /* sign randomization */ - FOR (i = 0; i < N; i++) - { - sign = add(shl(shr(own_random_fix(seed),15),1),1); - if(sub(sign,-1)==0) - { - invkoef[i] = L_negate(invkoef[i]); - move32(); - } - } - } - } - return; -} - - -Word16 Spl_GetScalingSquare_x(Word16 *in_vector, Word16 in_vector_length, Word16 times) -{ - Word16 nbits = sub(15, norm_s(times))/*Spl_GetSizeInBits_x(times)*/; - Word16 i; - Word16 smax = -1; - Word16 sabs; - Word16 *sptr = in_vector; - Word16 t; - move16(); - FOR (i = in_vector_length; i > 0; i--) - { - - sabs = abs_s(*sptr); - sptr++; - smax = s_max(sabs, smax); - - } - - t = norm_l(L_mult0(smax, smax)); - - IF (smax == 0) - { - return 0; /* Since norm(0) returns 0 */ - } - ELSE - { - nbits = sub(nbits, t); - nbits = s_max(0,nbits); - - return nbits; - } -} - - -Word32 Spl_Energy_x(Word16* vector, Word16 vector_length, Word16* scale_factor) -{ - Word32 en = L_deposit_l(0); - Word32 i; - Word16 scaling = Spl_GetScalingSquare_x(vector, vector_length, vector_length); - - FOR (i = 0; i < vector_length; i++) - { - en = L_add(en,L_shr(L_mult0(vector[i], vector[i]), scaling)); - } - - move32(); - *scale_factor = scaling; - - return en; -} - -void Log10OfEnergy_x(Word16 *s, Word32 *enerlogval, Word16 len) -{ - Word32 energy = L_deposit_l(0), tmp2 = L_deposit_l(0); - Word16 shfts = 0; - Word32 Log10_energy = L_deposit_l(0), Log10_len = L_deposit_l(0); - move16(); - energy = Spl_Energy_x(s, len, &shfts);/* Q:-shfts */ - IF (energy > 0) - { - Log10_energy = con_Log10(energy, negate(shfts)); /* Q25 */ - Log10_len = con_Log10(L_deposit_l(len), 0); /* Q25 */ - tmp2 = L_sub(Log10_energy,Log10_len); /* Q25 */ - tmp2 = Mpy_32_16_1(tmp2,20480); /* Q11->10 Q=25+11-15=21 */ - *enerlogval = L_shr(tmp2,13); /* Q8 */ move32(); - } - ELSE - { - *enerlogval = -25600; - move32(); - } - -} - -static Word32 fnLog2(Word32 L_Input) -{ - - Word16 swC0 = -0x2b2a, swC1 = 0x7fc5, swC2 = -0x54d0; - Word16 siShIFtCnt, swInSqrd, swIn; - Word32 LwIn; - move16(); - move16(); - move16(); - /*_________________________________________________________________________ - | | - | Executable Code | - |_________________________________________________________________________| - */ - - /* normalize input and store shIFts required */ - /* ----------------------------------------- */ - - siShIFtCnt = norm_l(L_Input); - LwIn = L_shl(L_Input, siShIFtCnt); - siShIFtCnt = add(siShIFtCnt, 1); - siShIFtCnt = negate(siShIFtCnt); - - /* calculate x*x*c0 */ - /* ---------------- */ - - swIn = extract_h(LwIn); - swInSqrd = mult_r(swIn, swIn); - LwIn = L_mult(swInSqrd, swC0); - - /* add x*c1 */ - /* --------- */ - - LwIn = L_mac(LwIn, swIn, swC1); - - /* add c2 */ - /* ------ */ - - LwIn = L_add(LwIn, L_deposit_h(swC2)); - - /* apply *(4/32) */ - /* ------------- */ - - LwIn = L_shr(LwIn, 3); - LwIn = L_and(LwIn, 0x03ffffff); - siShIFtCnt = shl(siShIFtCnt, 10); - LwIn = L_add(LwIn, L_deposit_h(siShIFtCnt)); - - /* return log2 */ - /* ----------- */ - - return (LwIn); -} - -static Word32 fnLog10(Word32 L_Input) -{ - - Word16 Scale = 9864; /* 0.30103 = log10(2) */ - Word32 LwIn; - move16(); - /*_________________________________________________________________________ - | | - | Executable Code | - |_________________________________________________________________________| - */ - - /* 0.30103*log2(x) */ - /* ------------------- */ - - LwIn = fnLog2(L_Input); - LwIn = Mpy_32_16_1(LwIn, Scale); - - return (LwIn); -} - -Word32 con_Log10(Word32 i_s32Val, Word16 i_s16Q) -{ - Word32 s32Out; - Word32 s32Correct; /* corrected (31-q)*log10(2) */ - const Word16 s16Log10_2 = 19728; /* log10(2)~Q16 */ move16(); - - IF(0 == i_s32Val) - { - return EVS_LW_MIN; - } - - s32Out = fnLog10(i_s32Val); /* (2^26)*log10(a) */ - - s32Correct = L_mult(sub(31,i_s16Q), s16Log10_2); /* q = 17 */ - s32Correct = L_shl(s32Correct, 8); /* q = 25 */ - s32Out = L_shr(s32Out, 1); /* q = 25 */ - - s32Out = L_add(s32Out, s32Correct); - - return s32Out; -} - -void concealment_update2_x(Word16 *outx_new, void *_plcInfo, Word16 FrameSize) -{ - T_PLCInfo *plcInfo = (T_PLCInfo*)_plcInfo; - - plcInfo->zp_fx = zero_pass_w32_x(outx_new, FrameSize); - move16(); - - Log10OfEnergy_x(outx_new, &plcInfo->ener_fx, FrameSize); /* Q8 */ - test(); - IF (sub(plcInfo->zp_fx, 100) < 0 && L_sub(plcInfo->ener_fx, L_shl(50,8)) > 0) - { - plcInfo->ener_mean_fx = L_add(Mpy_32_16_1(plcInfo->ener_mean_fx ,32112/* 0.98 Q15 */), - Mpy_32_16_1(plcInfo->ener_fx , 655/* 0.02 Q15 */)); - move32(); - } - return; -} - -static Word16 array_max_indx_fx(Word16 *s, Word16 N) -{ - Word16 i, indx = 0; - move16(); - FOR (i = 0; i < N; i++) - { - if (sub(s[i], s[indx]) > 0) + if (s[i] > s[indx]) { indx = i; - move16(); } } return indx; } -Word16 ffr_getSfWord16( /* o: measured headroom in range [0..15], 0 IF all x[i] == 0 */ - Word16 *x, /* i: array containing 16-bit data */ - Word16 len_x) /* i: length of the array to scan */ +static float sig_tilt(float *s, int FrameSize) { - Word16 i, i_min, i_max; - Word16 x_min, x_max; - - - x_max = 0; - move16(); - x_min = 0; - move16(); - FOR (i = 0; i < len_x; i++) - { - if (x[i] >= 0) - x_max = s_max(x_max,x[i]); - if (x[i] < 0) - x_min = s_min(x_min,x[i]); - } - - i_max = 0x10; - move16(); - i_min = 0x10; - move16(); - - if (x_max != 0) - i_max = norm_s(x_max); - - if (x_min != 0) - i_min = norm_s(x_min); - - i = s_and(s_min(i_max, i_min),0xF); - - - return i; + float tilt, enr1, enr2; + int subFrameSize, shift = 2; + float *p1, *p2; + subFrameSize = FrameSize>>2; + p1 = s+subFrameSize; + p2 = s+subFrameSize-shift; + enr1 = dot(p1, p2, FrameSize-subFrameSize); + enr2 = dot(p1, p1, FrameSize-subFrameSize); + tilt = enr1 / (enr2+EPSILON); + return tilt; } -static Word16 OverlapAdd_fx(Word16 *pitch125_data, Word16 *sbuf, - Word16 n, Word16 pitch, Word16 Framesize) +static int pitch_search(float *s, /* lastPcmOut */ + float *outx_new, + int Framesize, + float *voicing, + int *zp, + float *ener, + float ener_mean, + float *mdct_data, + int curr_mode + ) { - Word16 n1,n2,s,s16MaxCoefNorm,s16MaxCoefNorm2,tmp16; - Word16 i; - Word16 pitch125 =extract_l(L_shr(L_add(L_add(L_deposit_h(pitch), L_mult(pitch, 8192)), 32768) ,16)); - Word16 Loverlap = sub(pitch125,pitch); - Word16 Framesize_sub_n = sub(Framesize, n); + int pitch = 0, t, i; + float cov_max = 0, temp = 0, tmp, tilt, mdct_ener = 0, low_freq_rate; + float s_LP[L_FRAME_MAX] = {0}; + float mem[2]= {0}; + short start_pos, end_pos; + int cov_size; + int flag = 0, zp_current; + int curr_frmsize = Framesize/curr_mode; + float tmp_last = 0; /* not needed, just to avoid compiler warning */ + float cov_max_tmp = 0; + zp_current = zero_pass(outx_new, curr_frmsize); - n1 = Framesize_sub_n; - move16(); - n2 = Framesize_sub_n; - move16(); - if( sub(Loverlap, Framesize_sub_n) < 0 ) + if (curr_mode==2) { - n1 = Loverlap; - move16(); + zp_current = zp_current << 1; } - if( sub(pitch125, Framesize_sub_n) < 0 ) + if (Framesize <= 256) { - n2 = pitch125; - move16(); + if (zp_current > 70) + { + return 0; + } } - s16MaxCoefNorm = sub(ffr_getSfWord16(sbuf+n, n1),1); - s16MaxCoefNorm2 = ffr_getSfWord16(pitch125_data, n1); - Loverlap = s_max(1, Loverlap); - tmp16 =BASOP_Util_Divide1616_Scale(1, Loverlap,&s); - FOR (i = 0; i < n1; i++) + else { - Word16 tmp; - Word16 dat; - dat= shl(sbuf[n+i],s16MaxCoefNorm); - tmp = extract_l(L_shl(L_mult0(i, tmp16), s)); /* q15 */ - sbuf[n+i] = round_fx(L_add(L_shr(L_mult(dat, sub(32767,tmp)),s16MaxCoefNorm), - L_shr(L_mult(shl(pitch125_data[i],s16MaxCoefNorm2),tmp),s16MaxCoefNorm2))); + if (zp_current > 105) + { + return 0; + } + } + if (curr_mode == 2) + { + mdct_data = mdct_data + (Framesize>>1); } - FOR (i = n1; i < n2; i++) + for (i = 0; i < 30/curr_mode; i++) { - sbuf[n+i] = pitch125_data[i]; - move16(); + mdct_ener += mdct_data[i]*mdct_data[i]; + } + low_freq_rate = mdct_ener; + for (i = 30/curr_mode; i < Framesize/curr_mode; i++) + { + mdct_ener += mdct_data[i]*mdct_data[i]; + } + low_freq_rate /= (mdct_ener+EPSILON); + if (curr_mode == 2) + { + mdct_data = mdct_data - (Framesize>>1); + } + if(low_freq_rate < 0.02f) + { + return 0; } - pitch = add(n, pitch); + LpFilter2(s, s_LP, Framesize, mem); + tilt = sig_tilt(s_LP, Framesize); + if (Framesize <= 320) + { + if (tilt < 0.5f) + { + return 0; + } + } + else + { + if (tilt < 0.7f) + { + return 0; + } + } + if (Framesize <= 320) + { + start_pos = (int)(Framesize * 34/256.0 + 0.5f); + end_pos = (int)(Framesize * 3/4.0 + 0.5f); + for (t = start_pos; t < end_pos; t++) + { + cov_size = Framesize-t; + tmp = dot(s_LP, s_LP+t, cov_size)/cov_size; + if (t > start_pos) /* don't use the first value */ + { + if ( tmp > tmp_last) /* store the current cov, if it is larger than the last one */ + { + cov_max_tmp = tmp; + } + else if (cov_max < cov_max_tmp) /* otherwise */ + { + cov_max = cov_max_tmp; /* use the last value cov, being a max */ + pitch = t-1; /* and the last index as pitch */ + } + } + tmp_last = tmp; + } + temp = (float)(sqrt(dot(s_LP+pitch, s_LP+pitch, Framesize-pitch)) * + sqrt(dot(s_LP,s_LP,Framesize-pitch))); + *voicing = cov_max * (Framesize - pitch) / (temp + EPSILON); + { + float temp2, voicing2; + temp2 = (float)(sqrt(dot(s_LP+(pitch>>1), s_LP+(pitch>>1), Framesize-(pitch>>1))) * + sqrt(dot(s_LP,s_LP,Framesize-(pitch>>1)))); + voicing2 = dot(s_LP+(pitch>>1),s_LP,Framesize-(pitch>>1))/temp2; + if (voicing2 > *voicing) + { + pitch = pitch>>1; + *voicing = voicing2; + } + } + } + else + { + float s_tmp[L_FRAME_MAX]; + int Framesize_tmp = Framesize>>1; + int pitch_tmp[3]; + for (i = 0; i < Framesize_tmp; i++) + { + s_tmp[i] = s_LP[2*i]; + } + start_pos = (int)((34.0f*Framesize_tmp)/256 + 0.5f); + end_pos = (int)((Framesize_tmp>>1)*1.5f + 0.5f); + cov_max = 0; + pitch = 0; + for (t = start_pos; t < end_pos; t++) + { + cov_size = Framesize_tmp-t; + tmp = dot(s_tmp, s_tmp+t, cov_size)/cov_size; + if (t > start_pos) /* don't use the first value */ + { + if ( tmp > tmp_last) /* store the current cov, if it is larger than the last one */ + { + cov_max_tmp = tmp; + } + else if (cov_max < cov_max_tmp) /* otherwise */ + { + cov_max = cov_max_tmp; /* use the last value cov, being a max */ + pitch = t-1; /* and the last index as pitch */ + } + } + tmp_last = tmp; + } + if (pitch > 0) + { + pitch_tmp[0] = max(2*pitch - 1,0); + pitch_tmp[1] = 2*pitch; + pitch_tmp[2] = 2*pitch + 1; + cov_max = 0; + pitch = 0; + for (i = 0; i < 3; i++) + { + cov_size = Framesize - pitch_tmp[i]; + temp = (float)(sqrt(dot(s_LP+pitch_tmp[i], s_LP+pitch_tmp[i], cov_size)) * + sqrt(dot(s_LP,s_LP,cov_size))); + tmp = dot(s_LP, s_LP + pitch_tmp[i], cov_size)/(temp+EPSILON); + if (tmp > cov_max) + { + cov_max = tmp; + pitch = pitch_tmp[i]; + } + } + *voicing = cov_max; + } + } + if (pitch > 0) + { + flag = Is_Periodic(*voicing, *zp, *ener, ener_mean, pitch, Framesize, mdct_data); + } + if (flag == 0 ) + { + pitch = 0; + } return pitch; } -static void add_noise (Word16 * const sbuf, - Word16 * const outx_new_n1, - Word16 const* const noise_seg, - Word16 const Len, - Word16 * const gain, - Word16 const* const gain_n, - Word8 const firstFrame) +static int OverlapAdd(float *pitch125_data, float *sbuf, int n, int pitch, int Bufsize) { - Word16 i; - Word16 temp_OUT; - - IF( !firstFrame ) + int pitch125 = (int)floor(0.5f+(1.25f*(float)pitch)); + int Loverlap = pitch125 - pitch; + int n1 = min(Loverlap, Bufsize-n); + int n2 = min(pitch125, Bufsize-n); + int i; + float tmp, dat; + for (i = 0; i < n1; i++) { - temp_OUT = sub(noise_seg[0], mult((*outx_new_n1),22282/* 0.68 Q15 */)); - sbuf[0] = add(sbuf[0], mult((temp_OUT), *gain)); - move16(); - *gain = mac_r(L_mult(32439/* 0.99 Q15 */,*gain),328/* 0.01 Q15 */,*gain_n); + tmp = (float)i/(float)Loverlap; + dat = sbuf[n+i]; + sbuf[n+i] = (float)((1.0 - tmp)*dat + tmp*pitch125_data[i]); } - - FOR( i = 1; i < Len; i++ ) + for (i = n1; i < n2; i++) { - temp_OUT = sub(noise_seg[i], mult((noise_seg[i-1]),22282/* 0.68 Q15 */)); - sbuf[i] = add(sbuf[i], mult((temp_OUT), *gain)); - move16(); - *gain = mac_r(L_mult(32439/* 0.99 Q15 */,*gain),328/* 0.01 Q15 */,*gain_n); + sbuf[n+i] = pitch125_data[i]; } + return (n+pitch); +} - *outx_new_n1 = noise_seg[i-1]; /*q0*/ +static void add_noise (float * const sbuf, + float * const outx_new_n1, + float const* const noise_seg, + int const Len, + float * const gain, + float const* const gain_n, + int const firstFrame) +{ + int i; + + if (!firstFrame) + { + sbuf[0] += *gain * (noise_seg[0] - 0.68f*(*outx_new_n1)); + *gain = 0.99f*(*gain) + 0.01f*(*gain_n); + } + for (i = 1; i < Len; i++) + { + sbuf[i] += *gain * (noise_seg[i] - 0.68f*noise_seg[i-1]); + *gain = 0.99f*(*gain) + 0.01f*(*gain_n); + } + *outx_new_n1 = noise_seg[i-1]; - return; } static -Word16 waveform_adj_fix(Word16 *overlapbuf, - Word16 *outdata2, - Word16 *outx_new, - Word16 *data_noise, - Word16 *outx_new_n1, - Word16 *nsapp_gain, - Word16 *nsapp_gain_n, - Word16 Framesize, - Word8 T_bfi, - Word16 voicing, - Word16 curr_mode, - Word16 pitch) +int waveform_adj( + float *overlapbuf, + float *outdata2, + float *outx_new, + float *data_noise, + float *outx_new_n1, + float *nsapp_gain, + float *nsapp_gain_n, + int Framesize, + int T_bfi, + float voicing, + int curr_mode, + int pitch) { - Word16 i, zp1, zp2,Framesizediv2,s16MaxCoefNorm; - Word16 sbuf[L_FRAME_MAX]; - Word16 tmp; + int i, zp1, zp2; + float sbuf[L_FRAME_MAX] = {0}; - Framesizediv2=shr(Framesize,1); - zp1 = zero_pass_w32_x(outdata2, Framesizediv2); - zp2 = zero_pass_w32_x(outdata2+Framesizediv2, Framesizediv2); + zp1 = zero_pass(outdata2, Framesize>>1); + zp2 = zero_pass(outdata2+(Framesize>>1), Framesize>>1); /* judge if the pitch is usable */ - tmp = 1; - move16(); - if (sub(zp1, 1) > 0) + if( 4*max(zp1,1) < zp2 ) { - tmp = zp1; - move16(); - } - IF (sub(shl(tmp,2), zp2) < 0) - { - move16(); return 0; } /* adjust the pitch value */ - test(); - test(); - test(); - IF (T_bfi && (sub(pitch , Framesizediv2)<=0) - && (sub(Framesize ,256)>0) && (sub(curr_mode , 1)==0)) + if (T_bfi && pitch <= Framesize>>1 && Framesize > 256 && curr_mode == 1) { - Word16 i1 = 0, i2 = 0; - Word16 pos1, pos2, pos3; - move16(); - move16(); - i1 = add(1 , array_max_indx_fx(outx_new, pitch)); - i2 = add(1 , array_max_indx_fx(outx_new+pitch, pitch)); - - pos1 = add(i2,sub(pitch,i1)); - pos3 = add(pos1, mult(pos1, 8192/* 0.25 Q15 */)); - pos2 = add(pitch,mult(pitch, 8192/* 0.25 Q15 */)); - - test(); - test(); - IF ((sub(pos1,pos2)<0) && (sub(pos3,pitch)>0) && (sub(pos1,Framesizediv2)<0)) + int i1 = 0, i2 = 0; + i1 = 1 + array_max_indx(outx_new, pitch); + i2 = 1 + array_max_indx(outx_new+pitch, pitch); + if ((float)(i2+pitch-i1)<(1.25f*pitch) && (1.25f*(i2+pitch-i1))>(float)pitch && (float)(i2+pitch-i1)<(float)(Framesize>>1)) { - pitch = add(i2,sub(pitch,i1)); + pitch = i2+pitch-i1; } } { - Word16 pitch125 = 0, Loverlap = 0, n = 0; - Word16 pitch125_data[L_FRAME_MAX]; - move16(); - move16(); - pitch125 = extract_l((L_shr(L_add(L_add(L_deposit_h(pitch), L_mult(pitch, 8192)), 32768) ,16))); - Loverlap = sub(pitch125,pitch); - FOR (i = 0; i < pitch; i++) - { - pitch125_data[i] = outdata2[Framesize-pitch+i]; - move16(); - } - FOR (i = 0; i < Loverlap; i++) - { - pitch125_data[pitch+i] = outx_new[i]; - move16(); - } - FOR (i = 0; i < Framesize; i++) - { - sbuf[i] = outx_new[i]; - move16(); - } + int pitch125 = 0, Loverlap = 0, n = 0; + float pitch125_data[L_FRAME_MAX] = {0}; + pitch125 = (int)floor(0.5f+(1.25f*(float)pitch)); + Loverlap = pitch125 - pitch; + memcpy(pitch125_data, outdata2+Framesize-pitch, sizeof(float)*pitch); + memcpy(pitch125_data+pitch, outx_new, sizeof(float)*Loverlap); + memcpy(sbuf, outx_new, sizeof(float)*Framesize); { - Word16 pitch125a1; - Word16 tmp_buf[2*L_FRAME_MAX], *p_tmp = tmp_buf+1; - - FOR (i = 0; i < pitch125; i++) - { - p_tmp[i] = pitch125_data[i]; - move16(); - } - + float tmp_buf[L_FRAME_MAX]= {0}, *p_tmp = tmp_buf+1; + memcpy(p_tmp, pitch125_data, sizeof(float)*pitch125); p_tmp[-1] = outdata2[Framesize-pitch-1]; - move16(); p_tmp[pitch125] = outx_new[Loverlap]; - move16(); - pitch125a1 = add(pitch125,1); - s16MaxCoefNorm = sub(ffr_getSfWord16(p_tmp-1, pitch125a1),1); - FOR (i = 0; i < pitch125a1; i++) + for (i = 0; i < pitch125; i++) { - p_tmp[i-1] = shl(p_tmp[i-1],s16MaxCoefNorm); - move16(); - } - FOR (i = 0; i < pitch125; i++) - { - pitch125_data[i] = round_fx(L_shr(L_add((L_mult(p_tmp[i], 20972)),L_mac(L_mult(p_tmp[i-1], 5898),p_tmp[i+1],5898)),s16MaxCoefNorm)); + pitch125_data[i] = 0.18f*p_tmp[i-1]+0.64f*p_tmp[i]+0.18f*p_tmp[i+1]; } } - - WHILE (sub(n, Framesize) < 0) /* periodical extension */ + while (n < Framesize) /* periodical extension */ { - n = OverlapAdd_fx(pitch125_data,sbuf,n,pitch,Framesize); + n = OverlapAdd(pitch125_data,sbuf,n,pitch,Framesize); } - /* maximum pitch lag is 3/4 Framesize; pitch125_data is reused for temporary storage, since outdata2 (holding the pcm data of the last good frame) is still needed and overlapbuf overlaps outdata2 */ - Copy(&sbuf[Framesize/4], pitch125_data, (3*Framesize)/4); + mvr2r(&sbuf[Framesize/4], pitch125_data, (3*Framesize)/4); - *nsapp_gain = 0; - move16(); - *nsapp_gain_n = sub(32767 ,shr(voicing,1)); /* q15 */ - tmp = Framesize; - move16(); - /* use last good signal for noise generation */ - add_noise(sbuf, outx_new_n1, outdata2, tmp, nsapp_gain, nsapp_gain_n, 1); - /* save current (noisy) output from IMDCT */ - mvr2r_Word16(outx_new, data_noise, tmp); + *nsapp_gain = 0.0; + *nsapp_gain_n = 1.0f - voicing/2; + { + int size = Framesize; + /* use last good signal for noise generation */ + add_noise(sbuf, outx_new_n1, outdata2, size, nsapp_gain, nsapp_gain_n, 1); + /* save current (noisy) output from IMDCT */ + mvr2r(outx_new, data_noise, size); + } /* overlapbuf can now be filled with sbuf, needed for subsequently lost frames */ - Copy(pitch125_data, &overlapbuf[Framesize/4], (3*Framesize)/4); + mvr2r(pitch125_data, &overlapbuf[Framesize/4], (3*Framesize)/4); } - FOR (i = 0; i < Framesize; i++) + for (i = 0; i < Framesize; i++) { outx_new[i] = sbuf[i]; - move16(); } + return pitch; } -void waveform_adj2_fix( Word16 *overlapbuf, - Word16 *outx_new, - Word16 *data_noise, - Word16 *outx_new_n1, - Word16 *nsapp_gain, - Word16 *nsapp_gain_n, - Word16 *recovery_gain, - Word16 step_concealgain, - Word16 pitch, - Word16 Framesize, - Word16 delay, - Word16 bfi_cnt, - Word16 bfi - ) +void waveform_adj2(float *overlapbuf, + float *outx_new, + float *data_noise, + float *outx_new_n1, + float *nsapp_gain, + float *nsapp_gain_n, + float *recovery_gain, + float step_concealgain, + int pitch, + int Framesize, + int delay, + int bfi_cnt, + int bfi) { - Word16 i, n,tablescale,ratio, - dat,Framesizesubn,Framesizesubp,tmp16,s,ptable,temp_OUT,s16MaxCoefNorm,s16MaxCoefNorm2; - Word16 sbuf[L_FRAME_MAX]; - - n=0; - move16(); - Framesizesubn = sub(Framesize,n); - Framesizesubp = sub(Framesize,pitch); - IF (pitch > 0) + int i, n=0; + float ratio; + float sbuf[L_FRAME_MAX]; + if (pitch > 0) { - WHILE (Framesizesubn>0) + while (n < Framesize) { /* periodical extension */ - Word16 tmp = vadmin(pitch, Framesizesubn); - FOR (i = 0; i < tmp; i++) + for (i = 0; i < min(pitch, Framesize-n); i++) { - sbuf[n+i] = overlapbuf[Framesizesubp+i]; - move16(); + sbuf[n+i] = overlapbuf[Framesize-pitch+i]; } - n = add(n, pitch); - Framesizesubn = sub(Framesize,n); + n += pitch; } - - FOR (i = 0; i < Framesize; i++) + for (i = 0; i < Framesize; i++) { overlapbuf[i] = sbuf[i]; - move16(); } - { - Word16 size = Framesize; - Word16* noise_ptr = data_noise; - + int size = Framesize; + float* noise_ptr = data_noise; /* use last (noisy) output from IMDCT for noise generation */ add_noise(sbuf, outx_new_n1, noise_ptr, size, nsapp_gain, nsapp_gain_n, 0); - - /* save current (noisy) output from IMDCT */ - IF( bfi ) + if (bfi) { - mvr2r_Word16(outx_new, noise_ptr, size); + /* save current (noisy) output from IMDCT */ + mvr2r(outx_new, noise_ptr, size); } } - test(); - IF (sub(bfi_cnt ,4)==0 || bfi == 0) + if (bfi_cnt == 4 || bfi == 0) { - SWITCH ( Framesize) + if (bfi == 0) { - case 160: + int gain_zero_start = 10000; + /* overlap-and-add */ + if (step_concealgain > EPSILON) { - tablescale =8; - move16(); - ptable = 26214; /* (Word16)(32767*256/160.0+0.5); q7+15 */ move16(); - BREAK; + gain_zero_start = (int)min((float)L_FRAME48k, (*recovery_gain/step_concealgain)) + 1; } - case 320: + + if (delay > 0) { - tablescale =9; - move16(); - ptable = 26214; /* (Word16)(32767*256/320.0+0.5); q8+15 */ move16(); - BREAK; + Framesize -= delay; } - case 512: + for (i = 0; i < min(gain_zero_start, Framesize); i++) { - tablescale =10; - move16(); - ptable = 32767; /* q9+15 */ move16(); - BREAK; + ratio = (float)i/(float)Framesize; + outx_new[i] = (1-ratio)*sbuf[i]**recovery_gain+ratio*outx_new[i]; + *recovery_gain -= step_concealgain; } - case 640: + for (i = gain_zero_start; i < Framesize; i++) { - tablescale =10; - move16(); - ptable = 26214; /* (Word16)(32767*512/640.0+0.5); q9+15 */ move16(); - BREAK; + ratio = (float)i/(float)Framesize; + outx_new[i] = ratio*outx_new[i]; } - default: /* 960 */ + if (*recovery_gain < 0.0f) { - tablescale =10; - move16(); - ptable = 17456; /* (Word16)(32767*512/960.0); q9+15 */ move16(); - BREAK; + *recovery_gain = 0.0f; } } - IF (bfi == 0) /* overlap-and-add */ - { - Word16 gain_zero_start = 10000; - move16(); - - IF (step_concealgain > 0) - { - gain_zero_start = BASOP_Util_Divide1616_Scale(*recovery_gain, step_concealgain,&s); - gain_zero_start= shl(gain_zero_start, sub(s,14)); /* q0 */ - gain_zero_start= add(gain_zero_start,1); - } - - IF (delay > 0) - { - Framesize = sub(Framesize,delay); - } - - s16MaxCoefNorm = sub(ffr_getSfWord16(sbuf, Framesize),1); - s16MaxCoefNorm2 = ffr_getSfWord16(outx_new, Framesize); - tmp16 = vadmin(gain_zero_start, Framesize); - FOR (i = 0; i < tmp16; i++) - { - ratio = extract_l(L_shr(L_mult(i, ptable), tablescale)); - dat= shl(sbuf[i],s16MaxCoefNorm); - temp_OUT= mult(*recovery_gain, sub(32767,ratio)); - outx_new[i]= round_fx(L_add(L_shr(L_mult(temp_OUT,dat ),s16MaxCoefNorm-1), L_shr(L_mult(shl(outx_new[i],s16MaxCoefNorm2),ratio),s16MaxCoefNorm2))); - move16(); - *recovery_gain =sub(*recovery_gain,shr_r(step_concealgain,1)); /* q14 */ - } - FOR (i = gain_zero_start; i < Framesize; i++) - { - ratio = extract_l(L_shr(L_mult(i, ptable), tablescale)); - outx_new[i] = round_fx(L_shr(L_mult(shl(outx_new[i],s16MaxCoefNorm2),ratio),s16MaxCoefNorm2)); - - } - - if (*recovery_gain < 0) - { - *recovery_gain = 0; - move16(); - } - } - ELSE + else { /* overlap-and-add */ - Word16 tmp; - s16MaxCoefNorm = sub(ffr_getSfWord16(sbuf, Framesize),1); - s16MaxCoefNorm2 = ffr_getSfWord16(outx_new, Framesize); - FOR (i = 0; i < Framesize; i++) + for (i = 0; i < Framesize; i++) { - dat = shl(sbuf[i], s16MaxCoefNorm); - tmp = extract_l(L_shr(L_mult(i, ptable), tablescale)); - outx_new[i] = round_fx(L_add(L_shr(L_mult(dat, sub(32767,tmp)),s16MaxCoefNorm), L_shr(L_mult(shl(outx_new[i],s16MaxCoefNorm2),tmp),s16MaxCoefNorm2))); + ratio = (float)i/(float)Framesize; + outx_new[i] = (1-ratio)*sbuf[i]+ratio*outx_new[i]; } } } - ELSE + else { - FOR (i = 0; i < Framesize; i++) + for (i = 0; i < Framesize; i++) { outx_new[i] = sbuf[i]; - move16(); } } } return; } -void concealment_signal_tuning_fx(Word16 bfi, Word16 curr_mode, Word16 *outx_new_fx, void *_plcInfo, Word16 nbLostCmpt, Word16 pre_bfi, Word16 *OverlapBuf_fx, Word16 past_core_mode, Word16 *outdata2_fx, Decoder_State_fx *st) +void set_state(int *state, int num, int N) +{ + int i; + for (i = 0; i < N-1; i++) + { + state[i] = state[i+1]; + } + state[N-1] = num; + return; +} + +void concealment_init(int N, void *_plcInfo) { T_PLCInfo *plcInfo = (T_PLCInfo*)_plcInfo; - Word16 FrameSize = plcInfo->FrameSize; - Word16 Pitch = plcInfo->Pitch_fx; - Word16 voicing_fx = 0; - move16(); - move16(); - move16(); - move16(); - IF (bfi) + int i; + + plcInfo->FrameSize = N; + plcInfo->Pitch = 0; + plcInfo->T_bfi = 0; + plcInfo->outx_new_n1 = 0.0f; + plcInfo->nsapp_gain = 0.0f; + plcInfo->nsapp_gain_n = 0.0f; + plcInfo->ener_mean = 59.4260f; + plcInfo->ener = 0.0f; + plcInfo->zp = N; + plcInfo->recovery_gain = 0.0f; + plcInfo->step_concealgain = 0.0f; + plcInfo->concealment_method = TCX_NONTONAL; + plcInfo->subframe = 0; + plcInfo->nbLostCmpt = 0; + plcInfo->seed = 21845; + + for (i = 0; i < TCX_TONALITY_INIT_CNT; i++) + { + plcInfo->TCX_Tonality[i] = 1; + } + for (i = TCX_TONALITY_INIT_CNT; i < DEC_STATE_LEN; i++) + { + plcInfo->TCX_Tonality[i] = 0; + } + for (i = 0; i < MAX_POST_LEN; i++) + { + plcInfo->Transient[i] = 1; + } + + for (i = 0; i < L_FRAME_MAX; i++) + { + plcInfo->data_reci2[i] = 0; + } + return; +} + +void concealment_decode(int curr_mode, float *invkoef, void *_plcInfo) +{ + T_PLCInfo *plcInfo = (T_PLCInfo*)_plcInfo; + int i; + int N = plcInfo->FrameSize; + short *seed = &(plcInfo->seed); + short sign; + if (plcInfo->concealment_method == TCX_NONTONAL) + { + if (curr_mode == 1) + { + /* copy the data of the last frame */ + mvr2r(plcInfo->data_reci2, invkoef, N); + /* sign randomization */ + for (i = 0; i < N; i++) + { + sign = ((own_random(seed)>>15)<<1)+1; + invkoef[i] *= sign; + } + } + } + return; +} + +void concealment_update(int bfi, int curr_mode, int tonality, float *invkoef, void *_plcInfo) +{ + T_PLCInfo *plcInfo = (T_PLCInfo*)_plcInfo; + float *data_reci2 = plcInfo->data_reci2; + int *tcx_tonality = plcInfo->TCX_Tonality; + int FrameSize = plcInfo->FrameSize; + int subframe = plcInfo->subframe; + int i; + if (curr_mode == 1) + { + set_state(plcInfo->Transient, curr_mode, MAX_POST_LEN); + for (i = 0; i < FrameSize; i++) + { + data_reci2[i] = invkoef[i]; + } + if (!bfi) + { + set_state(tcx_tonality, tonality, DEC_STATE_LEN); + } + } + else + { + if (subframe == 0) + { + set_state(plcInfo->Transient, curr_mode, MAX_POST_LEN); + if (!bfi) + { + set_state(tcx_tonality, tonality, DEC_STATE_LEN); + } + } + /* don't store the second subframe during frameloss; in + pitch_search(), low_freq_rate is derived on the last good + TCX-10 spectrum */ + if (!bfi || subframe == 0) + { + float *ptr = data_reci2+subframe; + for (i = 0; i < FrameSize>>1; i++) + { + ptr[i] = invkoef[i]; + } + } + } + return; +} + +void concealment_update2(float *outx_new, void *_plcInfo, int FrameSize) +{ + T_PLCInfo *plcInfo = (T_PLCInfo*)_plcInfo; + plcInfo->zp = zero_pass(outx_new, FrameSize); + plcInfo->ener = dot(outx_new, outx_new, FrameSize)/FrameSize; + plcInfo->ener = 10 * (float)log10(plcInfo->ener+EPSILON); + if (plcInfo->zp < 100 && plcInfo->ener > 50) + { + plcInfo->ener_mean = 0.98f*plcInfo->ener_mean + 0.02f*plcInfo->ener; + } + return; +} + +void concealment_signal_tuning(int bfi, int curr_mode, float *outx_new, void *_plcInfo, int nbLostCmpt, int pre_bfi, + float *OverlapBuf, int past_core_mode, float *outdata2, Decoder_State *st) +{ + T_PLCInfo *plcInfo = (T_PLCInfo*)_plcInfo; + int FrameSize = plcInfo->FrameSize; + float *data_reci2 = plcInfo->data_reci2; + int Pitch = plcInfo->Pitch; + float voicing = 0; + if (bfi) { - test(); - IF (st->enablePlcWaveadjust && plcInfo->concealment_method == TCX_NONTONAL) /* #define TCX_NONTONAL 0 */ + if (st->enablePlcWaveadjust && plcInfo->concealment_method == TCX_NONTONAL) { - - IF (sub(nbLostCmpt, 1) == 0) + if (nbLostCmpt == 1) { - plcInfo->Pitch_fx = pitch_search_fx(outdata2_fx, - outx_new_fx, - FrameSize, - &voicing_fx, - plcInfo->zp_fx, - (plcInfo->ener_fx), - (plcInfo->ener_mean_fx), - plcInfo->data_reci2_fx, - curr_mode - ); - move16(); - - IF (plcInfo->Pitch_fx) /* waveform adjustment for the first lost frame */ + plcInfo->Pitch = pitch_search(outdata2, + outx_new, + FrameSize, + &voicing, + &plcInfo->zp, + &plcInfo->ener, + plcInfo->ener_mean, + data_reci2, + curr_mode + ); + if (plcInfo->Pitch) /* waveform adjustment for the first lost frame */ { - plcInfo->Pitch_fx = waveform_adj_fix(OverlapBuf_fx, - outdata2_fx, - outx_new_fx, - plcInfo->data_noise, - &plcInfo->outx_new_n1_fx, - &plcInfo->nsapp_gain_fx, - &plcInfo->nsapp_gain_n_fx, - FrameSize, - plcInfo->T_bfi_fx, - voicing_fx, - curr_mode, - plcInfo->Pitch_fx); - move16(); + plcInfo->Pitch = waveform_adj(OverlapBuf, + outdata2, + outx_new, + plcInfo->data_noise, + &plcInfo->outx_new_n1, + &plcInfo->nsapp_gain, + &plcInfo->nsapp_gain_n, + FrameSize, + plcInfo->T_bfi, + voicing, + curr_mode, + plcInfo->Pitch); } } - ELSE IF (sub(nbLostCmpt, 5) < 0) /* waveform adjustment for the 2nd~4th lost frame */ + else if (nbLostCmpt < 5) /* waveform adjustment for the 2nd~4th lost frame */ { - waveform_adj2_fix(OverlapBuf_fx, - outx_new_fx, + waveform_adj2(OverlapBuf, + outx_new, + plcInfo->data_noise, + &plcInfo->outx_new_n1, + &plcInfo->nsapp_gain, + &plcInfo->nsapp_gain_n, + &plcInfo->recovery_gain, + plcInfo->step_concealgain, + Pitch, + FrameSize, + 0, + nbLostCmpt, + bfi); + } + } + plcInfo->T_bfi = 1; + } + else + { + if (pre_bfi && + past_core_mode != 0 && + st->last_total_brate >= HQ_48k && + st->last_codec_mode == MODE2) + { + if (plcInfo->concealment_method == TCX_NONTONAL) + { + if (plcInfo->nbLostCmpt < 4) /* smoothing of the concealed signal with the good signal */ + { + waveform_adj2(OverlapBuf, + outx_new, plcInfo->data_noise, - &plcInfo->outx_new_n1_fx, - &plcInfo->nsapp_gain_fx, - &plcInfo->nsapp_gain_n_fx, + &plcInfo->outx_new_n1, + &plcInfo->nsapp_gain, + &plcInfo->nsapp_gain_n, &plcInfo->recovery_gain, - plcInfo->step_concealgain_fx, + plcInfo->step_concealgain, Pitch, FrameSize, 0, - nbLostCmpt, + plcInfo->nbLostCmpt + 1, bfi); - } - } - plcInfo->T_bfi_fx = 1; - move16(); - } - ELSE - { - test(); - test(); - test(); - IF (pre_bfi && - past_core_mode != 0 && - L_sub(st->last_total_brate_fx, 48000) >= 0 && - sub(st->last_codec_mode, MODE2) == 0) - { - IF (plcInfo->concealment_method == TCX_NONTONAL) /* #define TCX_NONTONAL 0 */ - { - IF (L_sub(plcInfo->nbLostCmpt, 4) < 0) /* smoothing of the concealed signal with the good signal */ - { - waveform_adj2_fix(OverlapBuf_fx, - outx_new_fx, - plcInfo->data_noise, - &plcInfo->outx_new_n1_fx, - &plcInfo->nsapp_gain_fx, - &plcInfo->nsapp_gain_n_fx, - &plcInfo->recovery_gain, - plcInfo->step_concealgain_fx, - Pitch, - FrameSize, - 0, - add(extract_l(plcInfo->nbLostCmpt), 1), - bfi); } } } - ELSE + else { - plcInfo->T_bfi_fx = 0; - move16(); + plcInfo->T_bfi = 0; } } return; diff --git a/src/libs/libevs/lib_enc/ACcontextMapping_enc.cpp b/src/libs/libevs/lib_enc/ACcontextMapping_enc.cpp old mode 100755 new mode 100644 index 1d9aa416..dc75aedc --- a/src/libs/libevs/lib_enc/ACcontextMapping_enc.cpp +++ b/src/libs/libevs/lib_enc/ACcontextMapping_enc.cpp @@ -1,713 +1,636 @@ /*==================================================================================== - EVS Codec 3GPP TS26.442 Apr 03, 2018. Version 12.11.0 / 13.6.0 / 14.2.0 + EVS Codec 3GPP TS26.443 Nov 13, 2018. Version 12.11.0 / 13.7.0 / 14.3.0 / 15.1.0 ====================================================================================*/ -#include -#include -#include -#include #include "options.h" -#include "stl.h" -#include "basop_util.h" -#include "stl.h" -#include "cnst_fx.h" -#include "prot_fx.h" -#include "rom_com_fx.h" +#include +#include "cnst.h" +#include "rom_com.h" +#include "prot.h" -/** - * \brief Arithmetic encoder - * \param[i] x - * \param[o] ntuples amount of encoded tuple (2 lines per tuple) - * \param[i] nt - * \param[i] nbbits - * \param[i] resQMaxBits - * \return none - */ -Word16 ACcontextMapping_encode2_no_mem_s17_LC( - Encoder_State_fx *st, - Word16 *x, - Word16 nt, - Word16 lastnz, - Word16 nbbits, - Word16 resQMaxBits, + +/*-------------------------------------------------------------------* +* ACcontextMapping_encode2_no_mem_s17_LC() +* +* Arithmetic encoder +*-------------------------------------------------------------------*/ + +void ACcontextMapping_encode2_no_mem_s17_LC( + Encoder_State *st, + int *x, + int nt, + int lastnz, + int nbbits, + int resQMaxBits, CONTEXT_HM_CONFIG *hm_cfg) { - Word16 ptr[BITBUFSIZE]; - TastatEnc as, as_overflow; - Word16 bp, bp_overflow; - Word16 a1, b1, a1_i, b1_i, k; - Word16 t, pki, lev1; - Word16 rateFlag; - Word16 value; - Word16 nbbits_ntuples, nbbits_lsbs, nbbits_signs, nbbits_signs_overflow, nbbits_lsbs_overflow, flag_overflow; - Word16 *lsbs_bits2; - Word16 tmp; - Word16 nt_half; - Word16 c[2], *ctx; - Word16 p1, p2; - Word16 ii[2], idx1, idx2, idx; - Word16 numPeakIndicesOrig, numHoleIndices; - get_next_coeff_function get_next_coeff; - Word16 signs[N_MAX]; - Word16 nbbits_m2; + int ptr[BITBUFSIZE]; + Tastat as, as_overflow; + int bp, bp_overflow; + int a1, b1, a1_i, b1_i, k; + int t, pki, lev1; + int rateFlag; + int value; + int nbbits_ntuples, nbbits_lsbs, nbbits_signs,nbbits_signs_overflow, nbbits_lsbs_overflow, flag_overflow; + int *lsbs_bits; + int nt_half; + int c[2], *ctx; + int p1, p2; + int ii[2], idx1, idx2, idx; + int numPeakIndicesOrig, numHoleIndices; + int signs[N_MAX]; + int nbbits_m2; a1 = 0; /* to avoid compilation warnings */ b1 = 0; /* to avoid compilation warnings */ - /* Rate flag */ - rateFlag = 0; - move16(); - if (sub(nbbits, 400) > 0) + if (nbbits > 400) { rateFlag = 2 << NBITS_CONTEXT; - move16(); + } + else + { + rateFlag = 0; } /* Init */ - nt_half = shr(nt, 1); + nt_half = nt >> 1; c[0] = c[1] = 0; - move16(); - move16(); /* Bits for encoding the number of encoded tuples */ - nbbits_ntuples = sub(14, norm_s(negate(nt))); + nbbits_ntuples = 0; + k = 1; + + while (knumPeakIndices; - move16(); - hm_cfg->numPeakIndices = s_min(hm_cfg->numPeakIndices, lastnz); - move16(); - numHoleIndices = sub(lastnz, hm_cfg->numPeakIndices); + hm_cfg->numPeakIndices = min(hm_cfg->numPeakIndices, lastnz); + numHoleIndices = lastnz - hm_cfg->numPeakIndices; /* Mark hole indices beyond lastnz as pruned */ - FOR (k=numHoleIndices; knumHoleIndices; ++k) + for (k=numHoleIndices; knumHoleIndices; ++k) { - hm_cfg->holeIndices[k] = add(hm_cfg->holeIndices[k], nt); - move16(); + hm_cfg->holeIndices[k] = hm_cfg->holeIndices[k] + nt; } ii[0] = numPeakIndicesOrig; - move16(); ii[1] = 0; - move16(); - get_next_coeff = get_next_coeff_mapped; - move16(); + p1 = p2 = 0; /* to avoid compilation warnings */ } - ELSE /* unmapped domain */ + else { + /* unmapped domain */ ii[0] = 0; - move16(); p1 = p2 = 0; - move16(); - move16(); - - get_next_coeff = get_next_coeff_unmapped; - move16(); /* Find last non-zero tuple */ /* ensure termination of while loop by dummy value */ a1 = x[0]; - move16(); x[0] = 1; - move16(); - WHILE (s_or(x[lastnz-1], x[lastnz-2]) == 0) + while (x[lastnz-1] == 0 && x[lastnz-2] == 0) { - lastnz = sub(lastnz, 2); + lastnz -= 2; } x[0] = a1; - move16(); } - lsbs_bits2 = ptr+nbbits-1; + lsbs_bits=ptr+nbbits-1; /*Start Encoding*/ ari_start_encoding_14bits(&as); /*Main Loop through the 2-tuples*/ b1_i = -1; - move16(); - FOR (k = 0; k < lastnz; k += 2) + + for (k=0; k 0) + if (hm_cfg) { - t = add(t, 1 << NBITS_CONTEXT); + a1_i = get_next_coeff_mapped(ii, &p1, &idx1, hm_cfg); + b1_i = get_next_coeff_mapped(ii, &p2, &idx2, hm_cfg); + } + else + { + a1_i = get_next_coeff_unmapped(ii, &idx1); + b1_i = get_next_coeff_unmapped(ii, &idx2); } + idx = min(idx1, idx2); + + /* Get context */ + ctx = &c[p1 | p2]; + + t = *ctx + rateFlag; + t += (nt_half >= idx) ? 0 : (1 << NBITS_CONTEXT); + /* Init current 2-tuple encoding */ + if (flag_overflow != 0) { x[a1_i] = 0; - move16(); - } - if (flag_overflow != 0) - { x[b1_i] = 0; - move16(); } - a1 = abs_s(x[a1_i]); - b1 = abs_s(x[b1_i]); + a1 = abs(x[a1_i]); + b1 = abs(x[b1_i]); lev1 = -1; - move16(); /*Copy states*/ ari_copy_states(&as, &as_overflow); bp_overflow = bp; - move16(); nbbits_signs_overflow = nbbits_signs; - move16(); nbbits_lsbs_overflow = nbbits_lsbs; - move16(); /*Signs encoding*/ - signs[nbbits_signs] = lshr(x[a1_i], 15); - move16(); + if (a1 > 0) { - nbbits_signs = add(nbbits_signs, 1); + signs[nbbits_signs++] = ((unsigned int)x[a1_i] >> (sizeof(unsigned int)*8-1)); } - signs[nbbits_signs] = lshr(x[b1_i], 15); - move16(); + if (b1 > 0) { - nbbits_signs = add(nbbits_signs, 1); + signs[nbbits_signs++] = ((unsigned int)x[b1_i] >> (sizeof(unsigned int)*8-1)); } /* MSBs coding */ - WHILE (sub(s_max(a1, b1), A_THRES) >= 0) + while (max(a1, b1) >= A_THRES) { - tmp = add(t, Tab_esc_nb[lev1+1]); - assert(tmp >= 0 && tmp < 4096); - pki = ari_lookup_s17_LC[tmp]; - move16(); - bp = ari_encode_14bits_ext(ptr, bp, &as, VAL_ESC, ari_pk_s17_LC_ext[pki]); + pki = ari_lookup_s17_LC[t + ((lev1+1) << (NBITS_CONTEXT + NBITS_RATEQ))]; + bp = ari_encode_14bits_ext(ptr,bp,&as,VAL_ESC,ari_pk_s17_LC_ext[pki]); - *lsbs_bits2-- = s_and(a1, 1); - move16(); - *lsbs_bits2-- = s_and(b1, 1); - move16(); + *lsbs_bits-- = a1 & 1; + *lsbs_bits-- = b1 & 1; /* LSBs bit counting */ - nbbits_lsbs = add(nbbits_lsbs, 2); + nbbits_lsbs += 2; - a1 = shr(a1, 1); - b1 = shr(b1, 1); + a1 >>= 1; + b1 >>= 1; - lev1 = s_min(add(lev1, 1), 2); + lev1 = min(lev1+1, 2); } - tmp = add(t, Tab_esc_nb[lev1+1]); - assert(tmp >= 0 && tmp < 4096); - pki = ari_lookup_s17_LC[tmp]; - move16(); - bp = ari_encode_14bits_ext(ptr, bp, &as, add(a1, shl(b1, A_THRES_SHIFT)), ari_pk_s17_LC_ext[pki]); + pki = ari_lookup_s17_LC[t + ((lev1+1) << (NBITS_CONTEXT + NBITS_RATEQ))]; + bp = ari_encode_14bits_ext(ptr,bp,&as,a1+A_THRES*b1,ari_pk_s17_LC_ext[pki]); + /* Check bit budget */ - IF (sub(add(add(add(bp, extract_l(as.vobf)), nbbits_signs), nbbits_lsbs), nbbits_m2) > 0) + if (bp+as.vobf+nbbits_signs+nbbits_lsbs > nbbits_m2) { ari_copy_states(&as_overflow, &as); bp = bp_overflow; - move16(); - IF (flag_overflow == 0) + if (!flag_overflow) { nbbits_signs = nbbits_signs_overflow; - move16(); nbbits_lsbs = nbbits_lsbs_overflow; - move16(); - IF (hm_cfg) + + if (hm_cfg) { flag_overflow = 1; - move16(); /* Code from now only zeros */ x[a1_i] = 0; - move16(); x[b1_i] = 0; - move16(); lev1 = -1; - move16(); - assert(t >= 0 && t < 4096); pki = ari_lookup_s17_LC[t]; - move16(); - bp = ari_encode_14bits_ext(ptr, bp, &as, 0, ari_pk_s17_LC_ext[pki]); + bp = ari_encode_14bits_ext(ptr,bp,&as,0,ari_pk_s17_LC_ext[pki]); - IF (sub(add(add(add(bp, extract_l(as.vobf)), nbbits_signs), nbbits_lsbs), nbbits_m2) > 0) + if (bp+as.vobf+nbbits_signs+nbbits_lsbs>nbbits_m2) { ari_copy_states(&as_overflow, &as); bp = bp_overflow; - move16(); - BREAK; + break; } } - ELSE + else { - BREAK; + break; } } - ELSE + else { - BREAK; + break; } } /* Update context for next 2-tuple */ - IF (sub(p1, p2) == 0) /* peak-peak or hole-hole context */ + if (p1 == p2) { - if (lev1 > 0) t = add(12, lev1); - if (lev1 <= 0) t = add(a1, b1); - if (lev1 == 0) t = add(t, t); + /* peak-peak or hole-hole context */ - *ctx = add(shl(s_and(*ctx, 0xf), 4), add(t, 1)); - move16(); - } - ELSE /* mixed context */ - { - IF (s_and(idx1, 1)) /* update first context */ + if (lev1 <= 0) { - c[p1] = update_mixed_context(c[p1], abs_s(x[a1_i])); - move16(); + t = 1 + (a1 + b1)*(lev1+2); + } + else + { + t = 13 + lev1; } - IF (s_and(idx2, 1)) /* update second context */ + *ctx = (*ctx & 0xf) * 16 + t; + } + else + { + /* mixed context */ + + if (idx1 & 1) { - c[p2] = update_mixed_context(c[p2], abs_s(x[b1_i])); - move16(); + /* update first context */ + c[p1] = update_mixed_context(c[p1], abs(x[a1_i])); + } + + if (idx2 & 1) + { + /* update second context */ + c[p2] = update_mixed_context(c[p2], abs(x[b1_i])); } } } /*end of the 2-tuples loop*/ - /* End arithmetic coder, overflow management */ - bp = ari_done_encoding_14bits(ptr, bp, &as); - /* Overflow is detected */ - IF (sub(k, lastnz) != 0) + /* End arithmetic coder, overflow management */ + bp = ari_done_encoding_14bits(ptr,bp,&as); + + /*Overflow is detected*/ + + if (k!=lastnz) { - IF (hm_cfg) + + if (hm_cfg) { - /* Fill with zero to be sure that the decoder finishes the MSB decoding at the same position */ - tmp = sub(nbbits, add(nbbits_signs, nbbits_lsbs)); - set16_fx(&ptr[bp], 0, sub(tmp, bp)); - bp = tmp; - move16(); + /*Fill with zero to be sure that decoder finish at the same position the MSB decoding*/ + + for(; bp>1)-1; + push_next_indice(st, value, nbbits_ntuples); /* Push arithmetic coded bits */ - push_next_bits_fx(st, &ptr[nbbits_ntuples], sub(bp, nbbits_ntuples)); + push_next_bits(st, &ptr[nbbits_ntuples], bp - nbbits_ntuples); /* Push sign bits */ - push_next_bits_fx(st, signs, nbbits_signs); - bp = add(bp, nbbits_signs); + push_next_bits(st, signs, nbbits_signs); + bp += nbbits_signs; /*write residual Quantization bits*/ - tmp = s_min(sub(sub(nbbits, bp), nbbits_lsbs), resQMaxBits); - FOR (k = 0; k < tmp; k++) + + for(k=0; kindexBuffer; - move16(); + + for (i=length; i >= 4; i-=2) + { + + if (x[tmp[i-2]] != 0 || x[tmp[i-1]] != 0) + { + last_nz = i; + break; + } + } } - - lobs[0] = 4; - move16(); - lobs[1] = shr(length, 1); /* length/2 */ move16(); - lobs[2] = add(lobs[1], shr(length, 2)); - move16(); - lobs[3] = add(lobs[2], shr(length, 3)); - move16(); - - last_nz = 0; - move16(); - i = length; - move16(); - FOR (stage=3; stage>=0; --stage) + else { - IF (hm_cfg) /* mapped kernel */ + /* unmapped kernel */ + + for (i=length; i >= 4; i-=2) { - FOR (; i >= lobs[stage]; i-=2) + + if (x[i-2] != 0 || x[i-1] != 0) { - if (x[tmp[i-2]] != 0) - { - last_nz = s_max(last_nz, i); - } - if (x[tmp[i-1]] != 0) - { - last_nz = s_max(last_nz, i); - } + last_nz = i; + break; } } - ELSE /* unmapped kernel */ - { - FOR (; i >= lobs[stage]; i-=2) - { - if (x[i-2] != 0) - { - last_nz = s_max(last_nz, i); - } - if (x[i-1] != 0) - { - last_nz = s_max(last_nz, i); - } - } - } - IF (last_nz > 0) - { - BREAK; - } } - return s_max(last_nz, 2); + return last_nz; } -Word16 ACcontextMapping_encode2_estimate_no_mem_s17_LC( - const Word16 *x, - Word16 nt, - Word16 *lastnz_out, - Word16 *nEncoded, - Word16 target, - Word16 *stop, + + +/*-------------------------------------------------------------------* +* ACcontextMapping_encode2_estimate_no_mem_s17_LC() +* +* +*-------------------------------------------------------------------*/ + +int ACcontextMapping_encode2_estimate_no_mem_s17_LC( + const int *x, + int nt, + int *lastnz_out, + int *nEncoded, + int target, + int *stop, CONTEXT_HM_CONFIG *hm_cfg ) { - Word16 a1, b1, a1_i, b1_i; - Word16 k, t, pki, lev1; - Word16 lastnz, lastnz2; - Word16 rateFlag; - Word16 nbits_old, nbits; - Word16 stop2; - Word16 cum_freq_norm, cum_freq_norm_e; - Word32 proba; - Word16 nlz; - const UWord16 *cum_freq; - Word16 symbol; - const Word8 *lookup; - Word16 nt_half; - Word16 c[2], *ctx; - Word16 p1, p2; - Word16 ii[2], idx1, idx2, idx; - Word16 numPeakIndicesOrig=0, numHoleIndices=0; /* initialize just to avoid compiler warning */ - get_next_coeff_function get_next_coeff; - + int a1, b1, a1_i, b1_i; + int k, t, pki, lev1; + int lastnz, lastnz2; + int rateFlag; + int nbits_old, nbits; + int stop2; + int proba; + short nlz; + const unsigned short *cum_freq; + long symbol; + const unsigned char *lookup; + int nt_half; + int c[2], *ctx; + int p1, p2; + int ii[2], idx1, idx2, idx; + int numPeakIndicesOrig = 0, numHoleIndices = 0; /* only to avoid compiler warning */ /* Rate flag */ - rateFlag = 0; - move16(); - if (sub(target, 400) > 0) + if (target > 400) { rateFlag = 2 << NBITS_CONTEXT; - move16(); + } + else + { + rateFlag = 0; } - /* proba coded on 14bits -> proba=1 */ - proba = L_deposit_l(16384); + /* 2 bits = arithmetic coder initialization interval = 1 bits for rounding last proba + 1 bit?*/ + nbits = 2; + /*proba coded on 14bits -> proba=1*/ + proba = 16384; /* Init */ - nt_half = shr(nt, 1); + nt_half = nt >> 1; stop2 = 0; - move16(); c[0] = c[1] = 0; - move16(); - move16(); - /* bits to encode lastnz + 2 bits headroom */ - nbits = sub(2+14, norm_s(sub(nt, 1))); + /* bits to encode lastnz */ + k = 1; + + while (knumPeakIndices; - move16(); - hm_cfg->numPeakIndices = s_min(hm_cfg->numPeakIndices, lastnz); - move16(); - numHoleIndices = sub(lastnz, hm_cfg->numPeakIndices); + hm_cfg->numPeakIndices = min(hm_cfg->numPeakIndices, lastnz); + numHoleIndices = lastnz - hm_cfg->numPeakIndices; /* Mark hole indices beyond lastnz as pruned */ - FOR (k=numHoleIndices; knumHoleIndices; ++k) + for (k=numHoleIndices; knumHoleIndices; ++k) { - hm_cfg->holeIndices[k] = add(hm_cfg->holeIndices[k], nt); - move16(); + hm_cfg->holeIndices[k] = hm_cfg->holeIndices[k] + nt; } ii[0] = numPeakIndicesOrig; - move16(); ii[1] = 0; - move16(); - get_next_coeff = get_next_coeff_mapped; - move16(); + p1 = p2 = 0; /* to avoid compilation warnings */ } - ELSE /* unmapped domain */ + else { + /* unmapped domain */ ii[0] = 0; - move16(); p1 = p2 = 0; - move16(); - move16(); - - get_next_coeff = get_next_coeff_unmapped; - move16(); } /* Main Loop through the 2-tuples */ - FOR (k=0; k 0) - { - t = add(t, 1 << NBITS_CONTEXT); - } + t = *ctx + rateFlag; + t += (nt_half >= idx) ? 0 : (1 << NBITS_CONTEXT); /* Init current 2-tuple encoding */ - a1 = abs_s(x[a1_i]); - b1 = abs_s(x[b1_i]); + a1 = abs(x[a1_i]); + b1 = abs(x[b1_i]); + lev1 = -(1 << (NBITS_CONTEXT+NBITS_RATEQ)); - lev1 = -(1<< (NBITS_CONTEXT+NBITS_RATEQ)); - move16(); /* Signs Bits */ - if (a1 > 0) - { - nbits = add(nbits, 1); - } - - if (b1 > 0) - { - nbits = add(nbits, 1); - } + nbits += min(a1, 1); + nbits += min(b1, 1); /* pre-compute address of ari_pk_s17_LC_ext[0][Val_esc] to avoid doing it multiple times inside the loop */ + lookup = &ari_lookup_s17_LC[t] + (1 << (NBITS_CONTEXT+NBITS_RATEQ)); /* check while condition */ - /* MSBs coding */ - lookup = &ari_lookup_s17_LC[t] + (1 << (NBITS_CONTEXT+NBITS_RATEQ)); /* address calculation not counted */ - WHILE (sub(s_max(a1, b1), A_THRES) >= 0) + while (max(a1, b1) >= A_THRES) { pki = lookup[lev1]; - move16(); - cum_freq = ari_pk_s17_LC_ext[pki] + VAL_ESC; /* address calculation not counted */ + cum_freq = ari_pk_s17_LC_ext[pki] + VAL_ESC; /*p1*p2=proba on 28 bits: p=0.5->power(2,27)*/ - - cum_freq_norm_e = norm_s(cum_freq[0]); - cum_freq_norm = shl(cum_freq[0], cum_freq_norm_e); - proba = Mpy_32_16_1(proba, cum_freq_norm); - proba = L_shl(proba, sub(14, cum_freq_norm_e)); - + proba *= *(cum_freq); /*Number of leading zero computed in one cycle=norm_l() in BASOP*/ - nlz = sub(norm_l(proba), 2); - proba = L_shl(proba, sub(nlz, 15)); - - nbits = add(nbits, nlz); + nlz=2; + while(proba<134217728) /*power(2,27)*/ + { + nlz++; + proba=proba<<1; + } + nbits+=nlz; /*addition added as shift not done in norm_l(): real shift = 14-nlz*/ - /*proba is rounded down on 14 bits ->automatic over-estimation of bit consumption*/ + proba>>=14; /*proba is rounded down on 14 bits ->automatic over-estimation of bit consumption*/ - a1 = shr(a1, 1); - b1 = shr(b1, 1); - lev1 = s_min(add(lev1, 1 << (NBITS_CONTEXT+NBITS_RATEQ)), 2 << (NBITS_CONTEXT+NBITS_RATEQ)); + (a1) >>= 1; + (b1) >>= 1; + + lev1 = min(lev1 + (1 << (NBITS_CONTEXT+NBITS_RATEQ)), 2 << (NBITS_CONTEXT+NBITS_RATEQ)); + /* check while condition */ + } + pki = lookup[lev1]; + symbol = a1 + A_THRES*b1; + cum_freq = ari_pk_s17_LC_ext[pki] + symbol; + /*p1*p2=proba on 28 bits: p=0.5->power(2,27)*/ + proba *= (cum_freq[0] - cum_freq[1]); + /*Number of leading zero computed in one cycle=norm_l() in BASOP*/ + nlz=0; + while(proba<134217728) /*power(2,27)*/ + { + nlz++; + proba=proba<<1; } - pki = lookup[lev1]; - move16(); - symbol = add(a1, shl(b1, A_THRES_SHIFT)); - cum_freq = ari_pk_s17_LC_ext[pki] + symbol; /* address calculation not counted */ - /*p1*p2=proba on 28 bits: p=0.5->power(2,27)*/ - - cum_freq_norm = sub(cum_freq[0], cum_freq[1]); - cum_freq_norm_e = norm_s(cum_freq_norm); - cum_freq_norm = shl(cum_freq_norm, cum_freq_norm_e); - proba = Mpy_32_16_1(proba, cum_freq_norm); - proba = L_shl(proba, sub(15, cum_freq_norm_e)); - - /*Number of leading zero computed in one cycle=norm_l() in BASOP*/ - nlz = sub(norm_l(proba), 3); - proba = L_shl(proba, sub(nlz, 14)); - - nbits = add(nbits, nlz); - /*addition added as shift not done in norm_l(): real shift = 14-nlz*/ - /*proba is rounded down on 14 bits ->automatic over-estimation of bit consumption*/ + nbits+=nlz; + proba>>=14; /*proba is rounded down on 14 bits ->automatic over-estimation of bit consumption*/ /* Should we truncate? */ - - IF (nbits > 0) + if ( nbits>0 ) { stop2 = 1; - move16(); - IF (*stop) + if (*stop) { - BREAK; + break; } } - ELSE + else { - test(); - test(); - IF (hm_cfg || k==0 || s_or(x[a1_i], x[b1_i])) + if (hm_cfg || k==0 || x[a1_i] || x[b1_i]) { - nbits_old = add(nbits, target); - lastnz2 = add(b1_i, 1); + nbits_old = nbits+target; + lastnz2 = b1_i+1; } } /* Update context for next 2-tuple */ - IF (sub(p1, p2) == 0) /* peak-peak or hole-hole context */ + if (p1 == p2) /* peak-peak or hole-hole context */ { - lev1 = shr(lev1, NBITS_CONTEXT+NBITS_RATEQ); - if (lev1 > 0) t = add(12, lev1); - if (lev1 <= 0) t = add(a1, b1); - if (lev1 == 0) t = add(t, t); + lev1 >>= NBITS_CONTEXT+NBITS_RATEQ; - *ctx = add(shl(s_and(*ctx, 0xf), 4), add(t, 1)); - move16(); - } - ELSE /* mixed context */ - { - IF (s_and(idx1, 1)) /* update first context */ + if (lev1 <= 0) { - c[p1] = update_mixed_context(c[p1], abs_s(x[a1_i])); - move16(); + t = 1 + (a1 + b1)*(lev1+2); + } + else + { + t = 13 + lev1; } - IF (s_and(idx2, 1)) /* update second context */ + *ctx = (*ctx & 0xf) * 16 + t; + } + else + { + /* mixed context */ + + if (idx1 & 1) { - c[p2] = update_mixed_context(c[p2], abs_s(x[b1_i])); - move16(); + /* update first context */ + c[p1] = update_mixed_context(c[p1], abs(x[a1_i])); + } + + if (idx2 & 1) + { + /* update second context */ + c[p2] = update_mixed_context(c[p2], abs(x[b1_i])); } } - } /* end of the 2-tuples loop */ + } /*end of the 2-tuples loop*/ - nbits = add(nbits, target); + nbits += target; /* Output */ + if (*stop) { nbits = nbits_old; - move16(); } if (stop2) { stop2 = nbits; - move16(); } *nEncoded = lastnz2; - move16(); *stop = stop2; - move16(); - if (lastnz_out) - { - *lastnz_out = lastnz; - move16(); - } + *lastnz_out = lastnz; - IF (hm_cfg) + if (hm_cfg) { /* Restore hole indices beyond lastnz */ - FOR (k=numHoleIndices; knumHoleIndices; ++k) + for (k=numHoleIndices; knumHoleIndices; ++k) { - hm_cfg->holeIndices[k] = sub(hm_cfg->holeIndices[k], nt); - move16(); + hm_cfg->holeIndices[k] = hm_cfg->holeIndices[k] - nt; } hm_cfg->numPeakIndices = numPeakIndicesOrig; - move16(); } - return nbits_old; } - - diff --git a/src/libs/libevs/lib_enc/FEC_enc.cpp b/src/libs/libevs/lib_enc/FEC_enc.cpp new file mode 100644 index 00000000..56223cd6 --- /dev/null +++ b/src/libs/libevs/lib_enc/FEC_enc.cpp @@ -0,0 +1,239 @@ +/*==================================================================================== + EVS Codec 3GPP TS26.443 Nov 13, 2018. Version 12.11.0 / 13.7.0 / 14.3.0 / 15.1.0 + ====================================================================================*/ + +#include +#include "options.h" +#include "cnst.h" +#include "prot.h" +#include "rom_com.h" + +/*-------------------------------------------------------------------* + * FEC_encode() + * + * Encoder supplementary information for FEC + *-------------------------------------------------------------------*/ + +void FEC_encode( + Encoder_State *st, /* i/o: encoder state structure */ + const float *synth, /* i : pointer to synthesized speech for E computation */ + const short coder_type, /* i : type of coder */ + short clas, /* i : signal clas for current frame */ + const float *fpit, /* i : close loop fractional pitch buffer */ + const float *res, /* i : LP residual signal frame */ + short *last_pulse_pos, /* i/o: Position of the last pulse */ + const short L_frame, /* i : Frame length */ + const long total_brate, /* i : total codec bitrate */ + const long core_brate /* i : total codec bitrate */ +) +{ + short tmpS, index; + short maxi, sign = 0, tmp_FER_pitch; + float enr_q; + + tmpS = 0; + enr_q = 1.0f; + + if( coder_type > UNVOICED && coder_type < AUDIO && core_brate >= ACELP_11k60 ) + { + /*-----------------------------------------------------------------* + * encode signal class (not needed for VC mode since it is clearly voiced) (2 bits) + *-----------------------------------------------------------------*/ + + if ( coder_type != VOICED ) + { + /* encode signal clas with 2 bits */ + if( clas == UNVOICED_CLAS ) + { + index = 0; + } + else if( clas == VOICED_TRANSITION || clas == UNVOICED_TRANSITION ) + { + index = 1; + } + else if( clas == VOICED_CLAS ) + { + index = 2; + } + else + { + index = 3; + } + + push_indice( st, IND_FEC_CLAS, index, FEC_BITS_CLS); + } + + /*-----------------------------------------------------------------* + * Encode frame energy (5 bits) + *-----------------------------------------------------------------*/ + + if( total_brate >= ACELP_16k40 && coder_type != TRANSITION ) /* GENERIC and VOICED frames */ + { + /* frame energy (maximum energy per pitch period for voiced frames or mean energy per sample over 2nd halframe for unvoiced frames) */ + fer_energy( L_frame, clas, synth, fpit[(L_frame>>6)-1], &enr_q, L_frame ); + + /* linearly quantize the energy in the range 0 : FEC_ENR_STEP : 96 dB */ + tmpS = (short)( 10.0 * log10( enr_q + 0.001f ) / FEC_ENR_STEP ); + + if( tmpS > FEC_ENR_QLIMIT ) + { + tmpS = FEC_ENR_QLIMIT; + } + + if( tmpS < 0 ) + { + tmpS = 0; + } + + push_indice( st, IND_FEC_ENR, tmpS, FEC_BITS_ENR ); + } + + /*-----------------------------------------------------------------* + * Encode last glottal pulse position (8 bits) + *-----------------------------------------------------------------*/ + + if( total_brate >= ACELP_32k && coder_type != TRANSITION ) /* GENERIC frames */ + { + /* retrieve the last glottal pulse position of the previous frame */ + /* use the current pitch information to scale or not the quantization */ + tmp_FER_pitch = (short)(fpit[0]); /* take the 1st subframe pitch, since it is easier to retieve it on decoder side */ + + + sign = 0; + maxi = *last_pulse_pos; + if ( maxi < 0 ) + { + sign = 1; + maxi = -maxi; + } + + if ( tmp_FER_pitch >= 128 ) + { + maxi /= 2; + } + + if ( maxi > 127 ) + { + /* better not use the glottal pulse position at all instead of using a wrong pulse */ + /* can happen only with pitch > 254 and max pit = 289 and should happen very rarely */ + maxi = 0; + } + + if( sign == 1 ) + { + maxi += 128; /* use 8 bits (MSB represents the sign of the pulse) */ + } + + push_indice( st, IND_FEC_POS, maxi, FEC_BITS_POS ); + } + + /* find the glottal pulse position of the current frame (could be sent as extra FEC info in the next frame) */ + maxi = 0; + if( clas >= VOICED_CLAS && total_brate >= ACELP_24k40 ) + { + maxi = findpulse( L_frame, res, (short)(fpit[(L_frame>>6)-1]), 0, &sign ); + if ( sign == 1 ) + { + maxi = -maxi; + } + } + + *last_pulse_pos = maxi; + } + else + { + *last_pulse_pos = 0; + } + + return; +} + + +/*-------------------------------------------------------------------* + * FEC_lsf_estim_enc() + * + * Simulates LSF estimation in case of FEC in the encoder ( only one frame erasure is considered ) + * The estimated LSF vector is then used to check LSF stability and may invoke safety-net usage in the next frame + *-------------------------------------------------------------------*/ + +void FEC_lsf_estim_enc( + Encoder_State *st, /* i : Encoder static memory */ + const short L_frame, /* i : length of the frame */ + float *lsf /* o : estimated LSF vector */ +) +{ + short i; + float alpha, lsf_mean[M]; + + if( L_frame == L_FRAME ) + { + mvr2r( UVWB_Ave, lsf_mean, M ); + } + else + { + mvr2r( GEWB2_Ave, lsf_mean, M ); + } + + /*----------------------------------------------------------------------* + * Initialize the alpha factor + *----------------------------------------------------------------------*/ + + if( st->last_coder_type == UNVOICED ) + { + /* clearly unvoiced */ + alpha = ALPHA_UU; + } + else if( st->last_coder_type == AUDIO || st->clas == INACTIVE_CLAS ) + { + alpha = 0.995f; + } + else if( st->clas == UNVOICED_CLAS ) + { + /* if stable, do not flatten the spectrum in the first erased frame */ + alpha = st->stab_fac * (1.0f - 2.0f*ALPHA_U) + 2.0f*ALPHA_U; + } + else if( st->clas == UNVOICED_TRANSITION ) + { + alpha = ALPHA_UT; + } + else if( st->clas == VOICED_CLAS || st->clas == ONSET ) + { + /* clearly voiced - mild convergence to the CNG spectrum for the first three erased frames */ + alpha = ALPHA_V; + } + else if( st->clas == SIN_ONSET ) + { + alpha = ALPHA_S; + } + else + { + /* long erasures and onsets - rapid convergence to the CNG spectrum */ + alpha = ALPHA_VT; + } + + /*----------------------------------------------------------------------* + * Extrapolate LSF vector + *----------------------------------------------------------------------*/ + + /* extrapolate the old LSF vector */ + for (i=0; ilsf_adaptive_mean[i]; + + /* move old LSF vector towards the mean LSF vector */ + lsf[i] = alpha * st->lsf_old[i] + (1.0f - alpha) * lsf_mean[i]; + } + + /* check LSF stability through LSF ordering */ + if( L_frame == L_FRAME ) + { + reorder_lsf( lsf, MODE1_LSF_GAP, M, INT_FS_12k8 ); + } + else /* L_frame == L_FRAME16k */ + { + reorder_lsf( lsf, MODE1_LSF_GAP, M, INT_FS_16k ); + } + + return; +} diff --git a/src/libs/libevs/lib_enc/FEC_enc_fx.cpp b/src/libs/libevs/lib_enc/FEC_enc_fx.cpp deleted file mode 100755 index aa8c44c6..00000000 --- a/src/libs/libevs/lib_enc/FEC_enc_fx.cpp +++ /dev/null @@ -1,294 +0,0 @@ -/*==================================================================================== - EVS Codec 3GPP TS26.442 Apr 03, 2018. Version 12.11.0 / 13.6.0 / 14.2.0 - ====================================================================================*/ - -#include "options.h" /* Compilation switches */ -#include "cnst_fx.h" /* Common constants */ -#include "prot_fx.h" /* Function prototypes */ -#include "rom_com_fx.h" /* Static table prototypes */ -#include "stl.h" - - - -/*============================================================================*/ -/* FUNCTION : void FEC_encode_fx() */ -/*----------------------------------------------------------------------------*/ -/* PURPOSE : Encoder supplementary information for FEC */ -/*----------------------------------------------------------------------------*/ -/* INPUT ARGUMENTS : */ -/* Word16 *synth i : pointer to synthesized speech for E computation */ -/* Word16 coder_type i : type of coder */ -/* Word16 clas i : signal clas for current frame */ -/* Word16 *fpit i : close loop fractional pitch buffer */ -/* Word16 *res i : LP residual signal frame */ -/* Word16 L_frame i : Frame length */ -/* Word32 total_brate i : total codec bitrate */ -/*----------------------------------------------------------------------------*/ -/* OUTPUT ARGUMENTS : */ -/*----------------------------------------------------------------------------*/ -/* INPUT/OUTPUT ARGUMENTS : */ -/* Word16 *last_pulse_pos i/o: Position of the last pulse */ -/* Encoder_State_fx *st_fx i/o: state structure */ -/*----------------------------------------------------------------------------*/ -/* RETURN ARGUMENTS : */ -/* _ None */ -/*----------------------------------------------------------------------------*/ -/* */ -/*============================================================================*/ -void FEC_encode_fx( - Encoder_State_fx *st_fx, /* i/o: encoder state structure */ - const Word16 *synth, /* i : pointer to synthesized speech for E computation */ - const Word16 coder_type, /* i : type of coder */ - Word16 clas, /* i : signal clas for current frame */ - const Word16 *fpit, /* i : close loop fractional pitch buffer */ - const Word16 *res, /* i : LP residual signal frame */ - Word16 *last_pulse_pos, /* i/o: Position of the last pulse */ - const Word16 L_frame, /* i : Frame length */ - const Word32 total_brate, /* i : total codec bitrate */ - const Word32 core_brate, /* i : total codec bitrate */ - const Word16 Q_new, /* i : input scaling */ - const Word16 shift /* i : scaling to get 12bits */ -) -{ - Word16 tmpS, index; - Word16 maxi, sign, tmp_FER_pitch; - Word32 enr_q, Ltmp; - Word16 enr_lg_ent, enr_lg_frac, exp_enrq; - - - tmpS = 0; - move16(); - enr_q = 1; - move16(); - sign = 0; - move16(); - test(); - test(); - IF( sub(coder_type,UNVOICED) > 0 && sub(coder_type,AUDIO) < 0 && L_sub(core_brate,ACELP_11k60) >= 0 ) - { - /*-----------------------------------------------------------------* - * encode signal class (not needed for VC mode since it is clearly voiced) (2 bits) - *-----------------------------------------------------------------*/ - IF ( sub(coder_type,VOICED) != 0 ) - { - /* encode signal clas with 2 bits */ - test(); - IF(sub(clas,UNVOICED_CLAS) == 0 ) - { - index = 0; - move16(); - } - ELSE IF( sub(clas,VOICED_TRANSITION) == 0 || sub(clas,UNVOICED_TRANSITION) == 0 ) - { - index = 1; - move16(); - } - ELSE IF( sub(clas,VOICED_CLAS) == 0 ) - { - index = 2; - move16(); - } - ELSE - { - index = 3; - move16(); - } - push_indice_fx( st_fx, IND_FEC_CLAS, index, FEC_BITS_CLS); - } - - /*-----------------------------------------------------------------* - * encode frame energy (5 bits) - *-----------------------------------------------------------------*/ - test(); - IF( L_sub(total_brate,ACELP_16k40) >= 0 && sub(coder_type,TRANSITION) != 0) /* GENERIC and VOICED frames */ - { - /* frame energy (maximum energy per pitch period for voiced frames or mean energy per sample over 2nd halframe for unvoiced frames) */ - /*frame_ener( L_frame, clas, synth, fpit[(L_frame>>6)-1], &enr_q, 0 );*/ - exp_enrq = frame_ener_fx( L_frame, clas, synth, shr_r(fpit[sub(shr(L_frame , 6),1)],6), &enr_q, L_frame, Q_new, shift, 1); - - /* linearly quantize the energy in the range 0 : FEC_ENR_STEP : 96 dB */ - /*tmpS = (short)( 10.0 * log10( enr_q + 0.001f ) / FEC_ENR_STEP )*/ /*To be converted fl_2_fx*/ - - enr_lg_frac = Log2_norm_lc(enr_q); - enr_lg_ent = sub(30, exp_enrq); - Ltmp = Mpy_32_16(enr_lg_ent,enr_lg_frac, LG10_s3_0); - tmpS = extract_h(L_shl(Ltmp, 1)); - - tmpS = s_min(tmpS, 31); - tmpS = s_max(tmpS, 0); - - push_indice_fx( st_fx, IND_FEC_ENR, tmpS, FEC_BITS_ENR ); - } - /*-----------------------------------------------------------------* - * Encode last glottal pulse position (8 bits) - *-----------------------------------------------------------------*/ - test(); - IF( L_sub(total_brate,ACELP_32k) >= 0 && sub(coder_type,TRANSITION) != 0) /* GENERIC frames */ - { - /* retrieve the last glottal pulse position of the previous frame */ - /* use the current pitch information to scale or not the quantization */ - tmp_FER_pitch = shr(fpit[0],6); /* take the 1st subframe pit, since it is easier to get on decoder side */ - sign = 0; - move16(); - maxi = *last_pulse_pos; - move16(); - IF ( maxi < 0 ) - { - sign = 1; - move16(); - /*maxi = -maxi; */ - maxi = negate(maxi); - } - - if ( sub(tmp_FER_pitch,128) >= 0) - { - maxi = shr(maxi , 1); - } - - if ( sub(maxi,127) > 0) - { - /* better not use the glottal pulse position at all instead of using a wrong pulse */ - /* can happen only with pitch > 254 and max pit = 289 and should happen very rarely */ - maxi = 0; - move16(); - } - - if( sign == 1 ) - { - maxi = add(maxi,128);/* use 8 bits (MSB represent the sign of the pulse) */ - } - - push_indice_fx( st_fx, IND_FEC_POS, maxi, FEC_BITS_POS ); - } - maxi = 0; - move16(); - - /* If bitrate < 24k4, then the pitch - is not represented in the same domain (12.k instead of 16k) */ - test(); - IF( sub(clas,VOICED_CLAS) >= 0 && L_sub(total_brate,ACELP_24k40) >= 0 ) - { - /*maxi = findpulse( L_frame, res, (short)(fpit[(L_frame>>6)-1]), 0, &sign ); */ - maxi = findpulse_fx( L_frame, res, shr_r(fpit[sub(shr(L_frame , 6) , 1)], 6), 0, &sign ); - if ( sign == 1 ) - { - /*maxi = -maxi;*/ - maxi = negate(maxi); - } - } - - *last_pulse_pos = maxi; - move16(); - } - ELSE - { - *last_pulse_pos = 0; - move16(); - } - - return; -} - - -/*-------------------------------------------------------------------* -* FEC_lsf_estim_enc_fx() -* -* Simulates LSF estimation in case of FEC in the encoder ( only one frame erasure is considered ) -* The estimated LSF vector is then used to check LSF stability and may invoke safety-net usage in the next frame -*-------------------------------------------------------------------*/ - -void FEC_lsf_estim_enc_fx( - Encoder_State_fx *st_fx, /* i : Encoder static memory */ - const Word16 L_frame, /* i : length of the frame */ - Word16 *lsf /* o : estimated LSF vector */ -) -{ - Word16 i; - Word16 alpha, lsf_mean[M]; - Word16 tmp; - - IF( sub(L_frame, L_FRAME) == 0 ) - { - Copy( UVWB_Ave_fx, lsf_mean, M ); - } - ELSE - { - Copy( GEWB2_Ave_fx, lsf_mean, M ); - } - - /*----------------------------------------------------------------------* - * Initialize the alpha factor - *----------------------------------------------------------------------*/ - - IF( sub(st_fx->last_coder_type_fx, UNVOICED) == 0 ) - { - /* clearly unvoiced */ - alpha = _ALPHA_UU_FX; - move16(); - } - ELSE - { - test(); - test(); - IF( sub(st_fx->last_coder_type_fx, AUDIO) == 0 || sub(st_fx->clas_fx, INACTIVE_CLAS) == 0 ) - { - alpha = 32604; - move16(); - } - ELSE IF( sub(st_fx->clas_fx, UNVOICED_CLAS) == 0 ) - { - /* if stable, do not flatten the spectrum in the first erased frame */ - /* alpha = st->stab_fac * (1.0f - 2.0f*ALPHA_U) + 2.0f*ALPHA_U; */ - alpha = add(mult(st_fx->stab_fac_fx, 32768 - _ALPHA_U_FX_X_2), _ALPHA_U_FX_X_2); - } - ELSE IF( sub(st_fx->clas_fx, UNVOICED_TRANSITION) == 0 ) - { - alpha = _ALPHA_UT_FX; - move16(); - } - ELSE IF( sub(st_fx->clas_fx, VOICED_CLAS) == 0 || sub(st_fx->clas_fx, ONSET) == 0 ) - { - /* clearly voiced - mild convergence to the CNG spectrum for the first three erased frames */ - alpha = _ALPHA_V_FX; - move16(); - } - ELSE IF( sub(st_fx->clas_fx, SIN_ONSET) == 0 ) - { - alpha = _ALPHA_S_FX; - move16(); - } - ELSE - { - /* long erasures and onsets - rapid convergence to the CNG spectrum */ - alpha = _ALPHA_VT_FX; - move16(); - } - } - /*----------------------------------------------------------------------* - * Extrapolate LSF vector - *----------------------------------------------------------------------*/ - tmp = sub(32767, alpha); - /* extrapolate the old LSF vector */ - FOR (i=0; ilsf_adaptive_mean[i]; */ - lsf_mean[i] = mac_r(L_mult(BETA_FEC_FX, lsf_mean[i]), 32768-BETA_FEC_FX, st_fx->lsf_adaptive_mean_fx[i]); - - /* move old LSF vector towards the mean LSF vector */ - /* lsf[i] = alpha * st->lsf_old[i] + (1.0f - alpha) * lsf_mean[i]; */ - lsf[i] = mac_r(L_mult(alpha, st_fx->lsf_old_fx[i]), tmp, lsf_mean[i]); - } - - /* check LSF stability through LSF ordering */ - IF( sub(L_frame, L_FRAME) == 0 ) - { - reorder_lsf_fx( lsf, MODE1_LSF_GAP_FX, M , INT_FS_FX); - } - ELSE /* L_frame == L_FRAME16k */ - { - reorder_lsf_fx( lsf, MODE1_LSF_GAP_FX, M, INT_FS_16k_FX); - } - - return; -} diff --git a/src/libs/libevs/lib_enc/SNR_calc.cpp b/src/libs/libevs/lib_enc/SNR_calc.cpp old mode 100755 new mode 100644 index b7d82c23..b5a19e8a --- a/src/libs/libevs/lib_enc/SNR_calc.cpp +++ b/src/libs/libevs/lib_enc/SNR_calc.cpp @@ -1,510 +1,184 @@ /*==================================================================================== - EVS Codec 3GPP TS26.442 Apr 03, 2018. Version 12.11.0 / 13.6.0 / 14.2.0 + EVS Codec 3GPP TS26.443 Nov 13, 2018. Version 12.11.0 / 13.7.0 / 14.3.0 / 15.1.0 ====================================================================================*/ +#include #include -#include - -#include "basop_util.h" -#include "options.h" -#include "stl.h" -#include "vad_basop.h" -#include "rom_enc_fx.h" -#include "prot_fx.h" -#include "rom_enc_fx.h" +#include "prot.h" +#include "rom_enc.h" -void calc_lf_snr( - Word32 *lf_snr_smooth, /*(o) smoothed lf_snr*/ - Word32 *lf_snr, /*(o) long time frequency domain - SNR calculated by l_speech_snr and l_silence_snr*/ - Word32 l_speech_snr, /*(i) sum of active frames snr */ - Word32 l_speech_snr_count, /*(i) amount of the active frame */ - Word32 l_silence_snr, /*(i) sum of the nonactive frames snr*/ - Word32 l_silence_snr_count, /*(i) amount of the nonactive frame */ - Word16 fg_energy_count, /*(i) amount of the foreground energy frame */ - Word16 bg_energy_count, /*(i) amount of the background energy frame */ - Word16 bw_index /*(i) band width index*/ -) -{ - - Word32 l_snr,div1,div2,tmp; - Word16 q_divout,q_divout1; - - - div1 = VAD_L_div(l_speech_snr,l_speech_snr_count,16,0,&q_divout); - div2 = VAD_L_div(l_silence_snr,l_silence_snr_count,16,0,&q_divout1); - l_snr = VAD_L_ADD(div1,q_divout,L_negate(div2),q_divout1,&q_divout); - - *lf_snr_smooth = MUL_F(*lf_snr_smooth, 29490/* 0.9 Q15 */); - move32(); - tmp = MUL_F(l_snr, 26214); - *lf_snr_smooth = VAD_L_ADD( *lf_snr_smooth, 25, tmp, add(3,q_divout), &q_divout1); - move32(); - *lf_snr_smooth = L_shr(*lf_snr_smooth, sub(q_divout1, 25)); - move32(); - l_snr = L_shr(l_snr, sub(q_divout, 25)); - - test(); - if(( sub(bg_energy_count, 56) < 0) || (sub(fg_energy_count, 56) < 0 )) - { - l_snr = L_add(0, 161061275/* 4.8 Q25 */); - } - - l_snr = MUL_F(l_snr, 3932/* 0.12 Q15 */); - l_snr = L_sub(l_snr, 12079595/* 0.36 Q25 */); - - l_snr = L_max(0, l_snr); - l_snr = L_min(l_snr, MAX_LF_SNR_TAB[bw_index]); - - *lf_snr = l_snr; - move32(); - -} - -void calc_lt_snr(T_CldfbVadState *st, /*(io) vad state*/ - Word32 *lt_snr_org_fp, /*(o) original long time SNR*/ - Word32 *lt_snr_fp, /*(o) long time SNR calculated by fg_energy and bg_energy*/ - Word32 fg_energy, /*(i) foreground energy sum */ - Word16 fg_energy_count, /*(i) amount of the foreground energy frame */ - Word32 bg_energy, /*(i) background energy sum */ - Word16 bg_energy_count, /*(i) amount of the background energy frame */ - Word16 bw_index, /*(i) band width index*/ - Word16 lt_noise_sp_center0 /*(i) long time noise spectral center by 0*/ - ) -{ - Word16 tmp_lt_noise_sp_center; - Word16 q_div1,q_div2,q_divout,q_divout1; - Word32 lt_snr_org; - Word32 lt_snr,div1,div2,tmp; - - - tmp_lt_noise_sp_center = sub(lt_noise_sp_center0,1432/* 1.4 Q10 */); - if(sub(tmp_lt_noise_sp_center, 818/* 0.8 Q10 */) > 0) - { - tmp_lt_noise_sp_center = 818/* 0.8 Q10 */; - move16(); - } - - if(tmp_lt_noise_sp_center<0) - { - tmp_lt_noise_sp_center = 0; - move16(); - } - - div1 = MUL_F(fg_energy,bg_energy_count); - div1 = VAD_L_ADD(div1,st->fg_energy_scale, 1, 126 ,&q_div1); - div2 = MUL_F(bg_energy,fg_energy_count); - div2 = VAD_L_ADD(div2,st->bg_energy_scale, 1, 126 ,&q_div2); - if( div2 == 0 ) - { - div2 = 1; - move32(); /* div2==0 , may occur for >30000 frames all zero input */ - if(div1 != 0) - { - st->bg_energy_scale = add(st->fg_energy_scale, 50); - } - } - div2 = VAD_L_div(div1,div2,q_div1,q_div2,&q_divout); - lt_snr_org = VAD_Log2(div2,q_divout); - lt_snr_org = MUL_F(lt_snr_org, 9864); - lt_snr = L_add(0, lt_snr_org); - *lt_snr_org_fp = lt_snr; - move32(); - - test(); - IF(sub(bg_energy_count, 56)<0||sub(fg_energy_count,56)<0) - { - lt_snr = L_add(0, 70464302/* 2.1 Q25 */); - } - - IF(sub(bw_index, CLDFBVAD_NB_ID)== 0) - { - lt_snr = L_sub(L_shr(lt_snr,1), 25165823/* 0.75 Q25 */); - } - ELSE IF(sub(bw_index, CLDFBVAD_WB_ID)== 0) - { - lt_snr = L_sub(L_shr(lt_snr,1), 25165823/* 0.75 Q25 */); - } - ELSE - { - lt_snr = MUL_F(lt_snr, 15073/* 0.46 Q15 */); - lt_snr = L_sub(lt_snr, 23152557/* 0.69 Q25 */); - } - - tmp = MUL_F(lt_snr,13107/* 0.4 Q15 */); - - tmp = L_add(L_shr(tmp,1), -26214); - - tmp = MUL_F(tmp, 13107/* 0.4 Q15 */); - tmp = MUL_F(tmp,tmp_lt_noise_sp_center); - lt_snr = VAD_L_ADD(lt_snr, 25, tmp,19, &q_divout1); - lt_snr = L_shr(lt_snr, sub(q_divout1,25)); - - lt_snr = L_max(0, lt_snr); - - if(L_sub(lt_snr,67108862/* 2.0 Q25 */)>0) - { - lt_snr = L_add(0, 67108862/* 2.0 Q25 */); - } - - *lt_snr_fp = lt_snr; - move32(); - -} - - -void calc_snr_flux( - Word32 tsnr, /*(i) time-domain SNR*/ - Word32 *pre_snr, /*(io) time-domain SNR storage*/ - Word32 *snr_flux_fp /*(o) average tsnr*/ -) -{ - Word32 i; - Word32 tmp, snr_flux; - Word16 s16MaxCoefNorm; - /*save a new time-domain SNR to pre_snr[0]*/ - - - test(); - IF( (L_sub(L_shr(tsnr,1) , 43620759/* 2.6f/2.0f Q25 */)<0 )&&tsnr>0) - { - pre_snr[0] = tsnr; - move32(); - } - ELSE IF(tsnr <= 0) - { - pre_snr[0] = 0; - move32(); - } - ELSE - { - pre_snr[0] = 87241517/* 2.6 Q25 */; - move32(); - } - - /*calculate snr_flux*/ - snr_flux = L_add(0, 0); - s16MaxCoefNorm = sub(ffr_getSfWord32(pre_snr, 32), 5); - FOR(i=0; i<32; i++) - { - tmp = L_shl(pre_snr[i],s16MaxCoefNorm); - snr_flux = L_add(snr_flux, tmp); - } - snr_flux = L_shr(snr_flux,add(s16MaxCoefNorm,5)); - *snr_flux_fp = snr_flux; - move32(); - - /*update the tsnr storage pre_snr*/ - FOR(i=PRE_SNR_NUM-1; i>0; i--) - { - pre_snr[i] = pre_snr[i-1]; - move32(); - } - -} -void snr_calc(T_CldfbVadState *st, /*(io) vad state*/ - Word16 sacle_sbpower, /*(i) the Scaling of sbpower*/ - Word32 *snr, /*(o) frequency domain SNR */ - Word32 *tsnr, /*(o) time domain SNR */ - Word32 frame_energy, /*(i) current frame energy */ - Word32 bandwith /*(i) band width*/ +void SNR_calc(float frame_sb_energy[], /*(i) energy of sub-band divided non-uniformly*/ + float sb_bg_energy[], /*(i) sub-band background energy*/ + float t_bg_energy, /*(i) time background energy of several frames*/ + float *snr, /*(o) frequency domain SNR */ + float *tsnr, /*(o) time domain SNR */ + float frame_energy, /*(i) current frame energy */ + int bandwidth /*(i) band width*/ ) { - Word32 i; - Word32 tmpframe_eg,tmpsb_eg,constff,div1,div2; - Word32 snr_tmp, tmp; + int i; + float snr_tmp,tmp; + int SNR_sb_num; + SNR_sb_num = ENERGY_BAND_NUM[bandwidth-CLDFBVAD_NB_ID]; - Word32 SNR_sb_num; - Word32 *sb_bg_energy ; - Word32 *frame_sb_energy ; - Word32 t_bg_energy; - Word16 tmp_addQ1,tmp_addQ2,minscale,minscale1,minscale2,s16MaxCoefNorm,q_divout; - Word32 tmpspec_amp; - Word32 const CONSTfix= 1759218560; - Word32 snr_tmpidx[12] = {0}; - - - SNR_sb_num = add(0, SNR_SUB_BAND_NUM[bandwith-CLDFBVAD_NB_ID]); - sb_bg_energy = st->sb_bg_energy; - frame_sb_energy = st->frame_sb_energy; - t_bg_energy = L_add(0, st->t_bg_energy); - - snr_tmp = L_add(0, 0); - FOR(i=0; iframe_sb_energy_scale, CONSTfix, 44, &tmp_addQ1); - div2 = VAD_L_ADD(sb_bg_energy[i], st->sb_bg_energy_scale, CONSTfix, 44, &tmp_addQ2); - tmp = VAD_L_div(div1, div2, tmp_addQ1, tmp_addQ2, &q_divout); - tmp = VAD_Log2(tmp, q_divout); - - if(L_sub(tmp, -11146447/* -0.33219 Q25 */)>0) + tmp = (frame_sb_energy[i]+0.0001f)/(sb_bg_energy[i]+0.0001f); + tmp = (float)log10(tmp); + if(tmp>-0.1) { - snr_tmpidx[i] = tmp; - move32(); + tmp = tmp*3.3219f; + snr_tmp += tmp; } } - - s16MaxCoefNorm = sub(ffr_getSfWord32(snr_tmpidx, (Word16)SNR_sb_num), 4); - FOR(i=0; i< SNR_sb_num; i++) + if (snr_tmp<0) { - tmpspec_amp = L_shl(snr_tmpidx[i], s16MaxCoefNorm); - snr_tmp = L_add(snr_tmp, tmpspec_amp); + snr_tmp = 0; } - snr_tmp = L_max(0, snr_tmp); - snr_tmp = MUL_F(snr_tmp,BAND_MUL[bandwith-CLDFBVAD_NB_ID]); - *snr = L_shr(snr_tmp,s16MaxCoefNorm); - move32(); - - IF(bandwith == CLDFBVAD_SWB_ID) + *snr = snr_tmp/SNR_sb_num; + tmp = (frame_energy+0.0001f)/(t_bg_energy+0.0001f); + tmp = (float)log10(tmp); + *tsnr = tmp*3.3219f; + if(bandwidth == CLDFBVAD_SWB_ID) { - IF(t_bg_energy) - { - minscale = norm_l(t_bg_energy); - minscale2 = sub(s_min(add(minscale,st->scale_t_bg_energy),31),1); - tmpsb_eg = L_shr(t_bg_energy,sub(st->scale_t_bg_energy,minscale2)); - constff = L_shr(1,sub(31,minscale2)); - } - ELSE - { - tmpsb_eg = L_add(0, 0); - constff = L_add(0, 1); - minscale2 = 31; - move16(); - } - div2 = L_add(tmpsb_eg,constff); - tmp = VAD_L_div(frame_energy, div2, sacle_sbpower, minscale2, &q_divout); - IF(tmp) - { - minscale = norm_l(tmp); - minscale2 = sub(s_min(add(minscale,q_divout), 31), 1); - tmpsb_eg = L_shr(tmp, limitScale32(sub(q_divout, minscale2))); - constff = L_shr(1, sub(31, minscale2)); - tmp = L_add(tmpsb_eg, constff); - } - ELSE - { - tmp = L_add(0, 1); - minscale2 = 31; - move16(); - } - *tsnr = VAD_Log2(tmp, minscale2); - move32(); - } - ELSE - { - IF(frame_energy) - { - minscale = norm_l(frame_energy); - minscale1 = sub(s_min(add(minscale,sacle_sbpower),44),1); - tmpframe_eg = L_shr(frame_energy,sub(sacle_sbpower,minscale1)); - constff = L_shr(CONSTfix,sub(44,minscale1)); - } - ELSE - { - tmpframe_eg = L_add(0, 0); - constff = L_add(0, CONSTfix); - minscale1 = 44; - move16(); - } - div1 = L_add(tmpframe_eg, constff); - IF(t_bg_energy) - { - minscale = norm_l(t_bg_energy); - minscale2 = sub(s_min(add(minscale,st->scale_t_bg_energy),44),1); - tmpsb_eg = L_shr(t_bg_energy,sub(st->scale_t_bg_energy,minscale2)); - constff = L_shr(CONSTfix,sub(44,minscale2)); - } - ELSE - { - tmpsb_eg = L_add(0, 0); - constff = L_add(0, CONSTfix); - minscale2 = 44; - move16(); - } - div2 = L_add(tmpsb_eg, constff); - tmp = VAD_L_div(div1, div2, minscale1, minscale2, &q_divout); - *tsnr = VAD_Log2(tmp,q_divout); - move32(); + tmp = (frame_energy)/(t_bg_energy+FLT_MIN); + tmp = (float)log10(tmp+FLT_MIN); + *tsnr = tmp*3.3219f; } } -Word32 construct_snr_thresh( Word16 sp_center[], /*(i) spectral center*/ - Word32 snr_flux, /*(i) snr flux*/ - Word32 lt_snr, /*(i) long time time domain snr*/ - Word32 l_snr, /*(i) long time frequency domain snr*/ - Word32 continuous_speech_num, /*(i) amount of continuous speech frames*/ - Word16 continuous_noise_num, /*(i) amount of continuous noise frames*/ - Word32 fg_energy_est_start, /*(i) whether if estimated energy*/ - Word16 bw_index /*(i) band width index*/ - ) +void calc_snr_flux(float tsnr, /*(i) time-domain SNR*/ + float pre_snr[], /*(io)time-domain SNR storage*/ + float *snr_flux /*(o) average tsnr*/ + ) { - - Word32 bw_snr,tmp_snr,snr_delta,test_l_snr,tmp,div1,div2; + int i; + float snr_sum = 0.0f; + if (tsnr < 2.6f&&tsnr>0) + pre_snr[0] = tsnr; + else if(tsnr<=0) + pre_snr[0] = 0; + else + pre_snr[0] = 2.6f; - - snr_delta = L_add(COMVAD_INIT_SNR_DELTA[bw_index],0); - bw_snr = L_add(lt_snr,0); - - - - test_l_snr = L_add(lt_snr,0); - IF(sub(bw_index, CLDFBVAD_SWB_ID)== 0) + snr_sum =0; + for(i=0; i0) - { - snr_delta = L_add(snr_delta,0); - } - ELSE IF(sub(sp_center[2], 2660/* 2.6 Q10 */)>0) - { - snr_delta = L_add(snr_delta, 1006633/* 0.03 Q25 */); - } - ELSE IF(sub(sp_center[2], 1637/* 1.6 Q10 */)>0) - { - snr_delta = L_add(snr_delta ,1677722/* 0.05 Q25 */); - } - ELSE IF(sub(sp_center[3], 1432/* 1.4 Q10 */)>0) - { - snr_delta = L_add(snr_delta , 3355443/* 0.10 Q25 */); - } - ELSE - { - snr_delta = L_add(snr_delta , 13421773/* 0.40 Q25 */); - } - - tmp = MUL_F(l_snr, 3277/* 0.1 Q15 */); - tmp = L_add(tmp,20132659/* 0.6 Q25 */); - - test(); - test(); - IF(L_sub(continuous_speech_num, 8) > 0&& L_sub(fg_energy_est_start, 1) ==0) - { - snr_delta = L_sub(snr_delta, 6710886/* 0.2 Q25 */); - } - ELSE IF(sub(continuous_noise_num,12) > 0&&(L_sub(snr_flux, tmp)>0)) - { - snr_delta = L_add(snr_delta, 3355443/* 0.10 Q25 */); - } - ELSE IF(sub(continuous_noise_num, 24) > 0) - { - snr_delta = L_add(snr_delta, 6710886/* 0.2 Q25 */); - } - ELSE IF((sub(continuous_noise_num, 4) > 0)) - { - snr_delta = L_add(snr_delta, 3355443/* 0.10 Q25 */); - } + snr_sum += pre_snr[i]; } - ELSE IF(sub(bw_index, CLDFBVAD_WB_ID) == 0) + *snr_flux = snr_sum/PRE_SNR_NUM; + for(i=PRE_SNR_NUM-1; i>0; i--) { - - IF(sub(sp_center[3], 2864/* 2.80 Q10 */)>0) - { - snr_delta = L_add(snr_delta,0); - } - ELSE IF(sub(sp_center[2], 2660/* 2.6 Q10 */)>0) - { - snr_delta = L_add(snr_delta, 1006633/* 0.03 Q25 */); - } - ELSE IF(sub(sp_center[2], 1637/* 1.6 Q10 */)>0) - { - snr_delta = L_add(snr_delta, 1677722/* 0.05 Q25 */); - } - ELSE IF(sub(sp_center[3], 1432/* 1.4 Q10 */)>0) - { - snr_delta = L_add(snr_delta, 3355443/* 0.10 Q25 */); - } - ELSE - { - snr_delta = L_add(snr_delta, 10066330/* 0.30 Q25 */); - } - - tmp = MUL_F(bw_snr, 3277/* 0.1 Q15 */); - tmp = L_add(tmp,20132659/* 0.6 Q25 */); - - test(); - test(); - IF(L_sub(continuous_speech_num, 8) > 0 && L_sub(fg_energy_est_start, 1) == 0) - { - snr_delta = L_sub(snr_delta, 3355443/* 0.10 Q25 */); - } - ELSE IF(sub(continuous_noise_num,12)>0 && (L_sub(snr_flux,tmp) > 0)) - { - snr_delta = L_add(snr_delta, 3355443/* 0.10 Q25 */); - } - ELSE IF(sub(continuous_noise_num,24) > 0) - { - snr_delta = L_add(snr_delta, 6710886/* 0.20 Q25 */); - } - ELSE IF((sub(continuous_noise_num,4) > 0)) - { - snr_delta = L_add(snr_delta, 3355443/* 0.10 Q25 */); - } + pre_snr[i] = pre_snr[i-1]; } - ELSE IF(sub(bw_index, CLDFBVAD_NB_ID)== 0) - { - IF(sub(sp_center[3], 3069/* 3.0 Q10 */)>0) - { - snr_delta = L_add(snr_delta,0); - } - ELSE IF(sub(sp_center[2], 2660/* 2.6 Q10 */)>0) - { - snr_delta = L_add(snr_delta , 671089/* 0.02 Q25 */); - } - ELSE IF(sub(sp_center[2],1637/* 1.6 Q10 */)>0) - { - snr_delta = L_add(snr_delta , 1342177/* 0.04 Q25 */); - } - ELSE IF(sub(sp_center[2], 1494/* 1.46 Q10 */)>0) - { - snr_delta = L_add(snr_delta , 3355443/* 0.10 Q25 */); - } - ELSE - { - snr_delta = L_add(snr_delta , 6039798/* 0.18 Q25 */); - } - - tmp = MUL_F(l_snr, 3277/* 0.1 Q15 */); - div1 = L_add(tmp,6710886/* 0.2 Q25 */); - div2 = L_add(tmp,20132659/* 0.6 Q25 */); - - test(); - test(); - test(); - test(); - test(); - IF(L_sub(continuous_speech_num, 80) > 0 && L_sub(fg_energy_est_start, 1) == 0 && (sub(sp_center[0],1432/* 1.4 Q10 */)>0)) - { - snr_delta = L_sub(snr_delta, 10737418/* 0.32 Q25 */); - } - ELSE IF(L_sub(continuous_speech_num,8) > 0 && L_sub(fg_energy_est_start, 1)==0 && (L_sub(snr_flux,div1)>0)) - { - snr_delta = L_sub(snr_delta, 3355443/* 0.10 Q25 */); - } - ELSE IF(sub(continuous_noise_num,12) > 0 && (L_sub(snr_flux,div2) >0)) - { - snr_delta = L_add(snr_delta, 3355443/* 0.10 Q25 */); - } - ELSE IF(sub(continuous_noise_num, 24) > 0) - { - snr_delta = L_add(snr_delta, 6710886/* 0.2 Q25 */); - } - } - ELSE - { - snr_delta = L_add(33554431/* 1.0 Q25 */,0); - } - tmp_snr = L_add(snr_delta, test_l_snr); - - - return tmp_snr; +} + +void calc_lt_snr(float *lt_snr_org, /*(o) original long time SNR*/ + float *lt_snr, /*(o) long time SNR calculated by fg_energy and bg_energy*/ + float fg_energy, /*(i) foreground energy sum */ + int fg_energy_count, /*(i) number of the foreground energy frame */ + float bg_energy, /*(i) background energy sum */ + int bg_energy_count, /*(i) number of the background energy frame */ + int bw_index, /*(i) band width index*/ + float lt_noise_sp_center0 /*(i) long time noise spectral center by 0*/ + ) +{ + float tmp_lt_noise_sp_center; + float rtn_lt_snr; + + const float offset = -0.00156247615814208984375f; + + + tmp_lt_noise_sp_center = lt_noise_sp_center0-1.4f; + if(tmp_lt_noise_sp_center>0.8) + { + tmp_lt_noise_sp_center = 0.8f; + } + if(tmp_lt_noise_sp_center<0) + { + tmp_lt_noise_sp_center = 0.0f; + } + rtn_lt_snr = (float)log10((fg_energy*bg_energy_count+FLT_MIN)/(bg_energy*fg_energy_count+FLT_MIN)); + *lt_snr_org = rtn_lt_snr; + + if(bg_energy_count<56||fg_energy_count<56) + { + rtn_lt_snr = 2.1f; + } + + if(bw_index == CLDFBVAD_NB_ID) + { + rtn_lt_snr = (rtn_lt_snr-1.5f)*0.5f; + } + else if(bw_index == CLDFBVAD_WB_ID) + { + rtn_lt_snr = (rtn_lt_snr-1.5f)*0.50f; + } + else + { + rtn_lt_snr = (rtn_lt_snr-1.5f)*0.46f; + + } + rtn_lt_snr = rtn_lt_snr + (rtn_lt_snr*0.4f+offset)*tmp_lt_noise_sp_center*0.4f; + if(rtn_lt_snr<0) + { + rtn_lt_snr = 0.0f; + } + + if(rtn_lt_snr>2.0) + { + rtn_lt_snr = 2.0f; + } + + *lt_snr = rtn_lt_snr; + + +} + +void calc_lf_snr(float *lf_snr_smooth, /*(o) smoothed lf_snr*/ + float *lf_snr, /*(o) long time frequency domain + SNR calculated by l_speech_snr and l_silence_snr*/ + float l_speech_snr, /*(i) sum of active frames snr */ + int l_speech_snr_count, /*(i) number of the active frame */ + float l_silence_snr, /*(i) sum of the nonactive frames snr*/ + int l_silence_snr_count, /*(i) number of the nonactive frame */ + int fg_energy_count, /*(i) number of the foreground energy frame */ + int bg_energy_count, /*(i) number of the background energy frame */ + int bw_index /*(i) band width index*/ + ) +{ + float l_snr; + l_snr = l_speech_snr/l_speech_snr_count - l_silence_snr/l_silence_snr_count; + *lf_snr_smooth = *lf_snr_smooth*0.9f + 0.1f*l_snr; + + if(bg_energy_count<56||fg_energy_count<56) + { + l_snr = 4.8f; + } + + + l_snr = (l_snr - 3.0f)*0.12f; + + if(l_snr<0) + { + l_snr = 0; + } + + if(l_snr>MAX_LF_SNR_TAB[bw_index]) + { + l_snr = MAX_LF_SNR_TAB[bw_index]; + } + + *lf_snr = l_snr; } diff --git a/src/libs/libevs/lib_enc/acelp_core_enc.cpp b/src/libs/libevs/lib_enc/acelp_core_enc.cpp new file mode 100644 index 00000000..381626c7 --- /dev/null +++ b/src/libs/libevs/lib_enc/acelp_core_enc.cpp @@ -0,0 +1,585 @@ +/*==================================================================================== + EVS Codec 3GPP TS26.443 Nov 13, 2018. Version 12.11.0 / 13.7.0 / 14.3.0 / 15.1.0 + ====================================================================================*/ + +#include +#include +#include "options.h" +#include "cnst.h" +#include "rom_enc.h" +#include "rom_com.h" +#include "prot.h" + +/*-------------------------------------------------------------------* + * acelp_core_enc() + * + * ACELP core encoder + *--------------------------------------------------------------------*/ + +void acelp_core_enc( + Encoder_State *st, /* i/o: encoder state structure */ + LPD_state *mem, /* i/o: acelp memories */ + const float inp[], /* i : input signal of the current frame */ + const short vad_flag, + const float ener, /* i : residual energy from Levinson-Durbin*/ + const short pitch[3], /* i : open-loop pitch values for quantiz. */ + const float voicing[3], /* i : Open-loop pitch gains */ + float A[NB_SUBFR16k*(M+1)], /* i : A(z) unquantized for the 4 subframes*/ + float Aw[NB_SUBFR16k*(M+1)], /* i : weighted A(z) unquant. for subframes*/ + const float epsP[M+1], /* i : LP prediction errors */ + float lsp_new[M], /* i : LSPs at the end of the frame */ + float lsp_mid[M], /* i : LSPs in the middle of the frame */ + short coder_type, /* i : coding type */ + const short sharpFlag, /* i : formant sharpening flag */ + short vad_hover_flag, + const short attack_flag, /* i : flag signalling attack encoded by AC mode (GSC) */ + float bwe_exc_extended[], /* i/o: bandwidth extended excitation */ + float *voice_factors, /* o : voicing factors */ + float old_syn_12k8_16k[], /* o : intermediate ACELP synthesis at 12.8kHz or 16kHz to be used by SWB BWE */ + float pitch_buf[NB_SUBFR16k], /* o : floating pitch for each subframe */ + short *unbits /* o : number of unused bits */ +) +{ + short nBits; /* reserved bits */ + short i; + float old_exc[L_EXC], *exc; /* excitation signal buffer */ + float lsf_new[M]; /* ISFs at the end of the frame */ + float Aq[NB_SUBFR16k*(M+1)]; /* A(z) quantized for the 4 subframes */ + float syn[L_FRAME16k]; /* synthesis signal buffer */ + float res[L_FRAME16k]; /* Residual signal for FER protection */ + float exc2[L_FRAME16k]; /* enhanced excitation */ + float Es_pred; /* predicited scaled innovation energy */ + float tmp_noise; /* NB post-filter long-term noise energy*/ + short tc_subfr; /* TC sub-frame indication */ + float old_bwe_exc[(PIT16k_MAX + (L_FRAME16k + 1) + L_SUBFR16k) * 2]; /* excitation buffer */ + float *bwe_exc; /* excitation for SWB TBE */ + short allow_cn_step; + float int_fs; + float att; + float lim; + short T_op[3]; + short nb_bits; /* parameters handling */ + int indice; + + /* SC-VBR - back-up memories for LSF quantizer and synthesis filter */ + short mCb1, pstreaklen; + float mem_MA[M], mem_AR[M], Bin_E[L_FFT], Bin_E_old[L_FFT/2], lsp_new_bck[M], lsp_mid_bck[M], mem_syn_bck[M]; + float clip_var, mem_w0_bck, streaklimit; + + float q_env[NUM_ENV_CNG]; + short sid_bw = -1; + float exc3[L_FRAME16k]; + float syn1[L_FRAME16k]; + float enr; + float enr_index; + + float tilt_code_bck; + float gc_threshold_bck; + float clip_var_bck[6]; + short next_force_sf_bck; + + + + /*------------------------------------------------------------------* + * Initialization + *------------------------------------------------------------------*/ + + Es_pred = 0; + + mvs2s( pitch, T_op, 3 ); + + /* convert pitch values to 16kHz domain */ + if ( st->L_frame == L_FRAME16k ) + { + T_op[0] = (short)(T_op[0] * 1.25f + 0.5f); + T_op[1] = (short)(T_op[1] * 1.25f + 0.5f); + T_op[2] = T_op[1]; + } + + exc = old_exc + L_EXC_MEM; /* pointer to excitation signal in the current frame */ + mvr2r( mem->old_exc, old_exc, L_EXC_MEM ); + + bwe_exc = old_bwe_exc + PIT16k_MAX * 2; /* pointer to BWE excitation signal in the current frame */ + mvr2r( st->old_bwe_exc, old_bwe_exc, PIT16k_MAX * 2 ); + + st->bpf_off = 0; + if( st->last_core == HQ_CORE || st->last_codec_mode == MODE2 ) + { + /* in case of HQ->ACELP switching, do not apply BPF */ + st->bpf_off = 1; + /* reset the GSC pre echo energy threshold in case of switching */ + st->Last_frame_ener = (float)MAX_32; + } + + /* force safety-net LSFQ in the first frames after CNG segment */ + if( st->last_core_brate <= SID_2k40 ) + { + st->Nb_ACELP_frames = 0; + } + st->Nb_ACELP_frames++; + + if( st->L_frame == L_FRAME ) + { + int_fs = INT_FS_12k8; + } + else + { + int_fs = INT_FS_16k; + } + + tmp_noise = 0; + tc_subfr = 0; + + /* SC-VBR temporary variables */ + mCb1 = 0; + pstreaklen = 0; + clip_var = 0; + mem_w0_bck = 0; + streaklimit = 0; + + /* channel-aware mode */ + reset_rf_indices(st); + + /*-----------------------------------------------------------------* + * ACELP@12k8 / ACELP@16k switching + *-----------------------------------------------------------------*/ + + if( st->last_L_frame != st->L_frame && st->last_core != HQ_CORE ) + { + /* in case of switching, do not apply BPF (flag employed also in updt_enc()) */ + st->bpf_off = 1; + + /* force safety-net LSFQ in the first frames after ACELP@12k8/ACELP@16k switching */ + st->Nb_ACELP_frames = 1; + + /* convert old quantized LSP vector */ + if( st->L_frame == L_FRAME ) + { + st->rate_switching_reset = lsp_convert_poly( st->lsp_old, st->L_frame, 0 ); + } + else + { + st->rate_switching_reset = st->rate_switching_reset_16kHz; + mvr2r( st->lsp_old16k, st->lsp_old, M ); + } + + /* convert old quantized LSF vector */ + lsp2lsf( st->lsp_old, st->lsf_old, M, int_fs ); + + /* interpolation of unquantized ISPs */ + if( st->rate_switching_reset ) + { + /*extrapolation in case of unstable LSP*/ + int_lsp4( st->L_frame, lsp_mid, lsp_mid, lsp_new, A, M, 0 ); + } + else + { + int_lsp4( st->L_frame, st->lsp_old, lsp_mid, lsp_new, A, M, 0 ); + } + + /* Reset LPC mem */ + mvr2r( GEWB_Ave, st->mem_AR, M ); + set_zero( st->mem_MA, M ); + + /* update synthesis filter memories */ + synth_mem_updt2( st->L_frame, st->last_L_frame, mem->old_exc, mem->mem_syn_r, mem->mem_syn2, mem->mem_syn, ENC ); + mvr2r( mem->old_exc, old_exc, L_EXC_MEM ); + mvr2r( mem->mem_syn2, st->mem_syn1, M ); + mvr2r( mem->mem_syn2, mem->mem_syn3, M ); + + /* update Aw[] coefficients */ + weight_a_subfr( st->L_frame/L_SUBFR, A, Aw, st->gamma, M ); + } + + if( st->last_bwidth == NB && st->bwidth != NB && st->ini_frame != 0 ) + { + st->rate_switching_reset = 1; + } + + /*----------------------------------------------------------------* + * Encoding of CNG frames + *----------------------------------------------------------------*/ + + if( st->core_brate == SID_2k40 || st->core_brate == FRAME__NO_DATA ) + { + if( st->cng_type == LP_CNG ) + { + /* Run CNG post parameter update */ + cng_params_postupd( st->ho_circ_ptr, &st->cng_buf_cnt, st->cng_exc2_buf, + st->cng_brate_buf, st->ho_env_circ); + /* encode CNG parameters */ + CNG_enc( st, st->L_frame, Aq, inp, ener, lsp_new, lsf_new , &allow_cn_step, st->burst_ho_cnt, q_env, &sid_bw, st->exc_mem2 ); + /* comfort noise generation */ + CNG_exc( st->core_brate, st->L_frame, &st->Enew, &st->cng_seed, exc, exc2, &st->lp_ener, + st->last_core_brate, &st->first_CNG, &st->cng_ener_seed, bwe_exc, allow_cn_step, &st->last_allow_cn_step, st->num_ho, + q_env, st->lp_env, st->old_env, st->exc_mem, st->exc_mem1, &sid_bw, &st->cng_ener_seed1, exc3, st->Opt_AMR_WB ); + } + else + { + if( st->core_brate == SID_2k40 ) + { + FdCng_encodeSID( st->hFdCngEnc, st, st->preemph_fac ); + st->last_CNG_L_frame = st->L_frame; + } + + generate_comfort_noise_enc( st ); + + FdCng_exc( st->hFdCngEnc->hFdCngCom, &st->CNG_mode, st->L_frame, st->lsp_old, st->first_CNG, st->lspCNG, Aq, lsp_new,lsf_new, exc, exc2, bwe_exc); + mvr2r( exc2, exc3, st->L_frame ); + if( st->core_brate == SID_2k40 ) + { + enr = dotp( exc, exc, st->L_frame ) / st->L_frame; + enr = (float)log10( enr + 0.1f ) / (float)log10( 2.0f ); + + /* decrease the energy in case of WB input */ + if( st->bwidth != NB ) + { + if( st->bwidth == WB ) + { + if( st->CNG_mode >= 0 ) + { + /* Bitrate adapted attenuation */ + att = ENR_ATT[st->CNG_mode]; + } + else + { + /* Use least attenuation for higher bitrates */ + att = ENR_ATT[4]; + } + } + else + { + att = 1.5f; + } + + enr -= att; + } + + enr_index = (short)( (enr + 2.0f) * STEP_SID ); + if( enr_index > 127 ) + { + enr_index = 127; + } + + if( enr_index < 0 ) + { + enr_index = 0; + } + st->old_enr_index = enr_index; + } + } + + + /* synthesis at 12.8kHz sampling rate */ + syn_12k8( st->L_frame, Aq, exc3, syn1, mem->mem_syn3, 1 ); + + /* reset the encoder */ + CNG_reset_enc( st, mem, pitch_buf, voice_factors, 0 ); + + /* update st->mem_syn1 for ACELP core switching */ + mvr2r( mem->mem_syn3, st->mem_syn1, M ); + + /* update ACELP core synthesis filter memory */ + mvr2r( mem->mem_syn3, mem->mem_syn, M ); + + /* update old synthesis buffer - needed for ACELP internal sampling rate switching */ + mvr2r( syn1 + st->L_frame - L_SYN_MEM, mem->mem_syn_r, L_SYN_MEM ); + + + /* save and delay synthesis to be used by SWB BWE */ + save_old_syn( st->L_frame, syn1, old_syn_12k8_16k, st->old_syn_12k8_16k, st->preemph_fac, &st->mem_deemph_old_syn ); + + /*Update MODE2 core switching memory*/ + deemph( syn1, st->preemph_fac, st->L_frame, &(st->LPDmem.syn[M]) ); + mvr2r( syn1+st->L_frame-M-1, st->LPDmem.syn, M+1 ); + } + + /*----------------------------------------------------------------* + * Encoding of all other frames + *----------------------------------------------------------------*/ + + else + { + /*-----------------------------------------------------------------* + * After inactive period, use the most up-to-date ISPs + *-----------------------------------------------------------------*/ + + if ( st->last_core_brate == FRAME__NO_DATA || st->last_core_brate == SID_2k40 ) + { + mvr2r( st->lspCNG, st->lsp_old, M ); + + lsp2lsf( st->lspCNG, st->lsf_old, M, int_fs ); + } + + /*-----------------------------------------------------------------* + * Reset higher ACELP pre-quantizer in case of switching + *-----------------------------------------------------------------*/ + + if( !st->use_acelp_preq ) + { + st->mem_deemp_preQ = 0.0f; + st->mem_preemp_preQ = 0.0f; + st->last_nq_preQ = 0; + } + st->use_acelp_preq = 0; + + /*-----------------------------------------------------------------* + * LSF Quantization + * A[z] calculation + *-----------------------------------------------------------------*/ + + /* SC-VBR & channel-aware mode - back-up memories for LSF quantizer and synthesis filter */ + lsf_syn_mem_backup( st, mem, &tilt_code_bck, &gc_threshold_bck, clip_var_bck, &next_force_sf_bck, lsp_new, lsp_mid, &clip_var, + mem_AR, mem_MA, lsp_new_bck, lsp_mid_bck, &mCb1, Bin_E, Bin_E_old, mem_syn_bck, &mem_w0_bck, &streaklimit, &pstreaklen ); + + lsf_enc( st, st->L_frame, coder_type, lsf_new, lsp_new, lsp_mid, Aq, &st->stab_fac, st->Nb_ACELP_frames ); + + /*---------------------------------------------------------------* + * Calculation of LP residual (filtering through A[z] filter) + *---------------------------------------------------------------*/ + + calc_residu( inp, res, Aq, st->L_frame ); + + /* smoothing in case of CNG */ + if( st->Opt_DTX_ON && vad_hover_flag ) + { + st->burst_ho_cnt++; + if(st->burst_ho_cnt > HO_HIST_SIZE) + { + st->burst_ho_cnt = HO_HIST_SIZE; + } + if( st->bwidth != NB ) + { + if( st->bwidth == WB && st->CNG_mode >= 0 ) + { + lim = HO_ATT[st->CNG_mode]; + } + else + { + lim = 0.6f; + } + + att = lim/6.0f; + att = 1.0f/(1 + att * st->burst_ho_cnt); + + if ( att < lim ) + { + att = lim; + } + + for( i = 0; i < st->L_frame; i++ ) + { + res[i] *= att; + } + } + } + else + { + st->burst_ho_cnt = 0; + } + + /*---------------------------------------------------------------* + * Calculation of prediction for scaled innovation energy + * (for memory-less gain quantizer) + *---------------------------------------------------------------*/ + + if( ( coder_type != UNVOICED && coder_type != AUDIO && coder_type != INACTIVE && !(st->core_brate <= ACELP_8k00 && coder_type != TRANSITION) ) + || (coder_type == INACTIVE && st->total_brate >= ACELP_32k) ) + { + nb_bits = Es_pred_bits_tbl[BIT_ALLOC_IDX(st->core_brate, coder_type, -1, -1)]; + Es_pred_enc( &Es_pred, &indice, st->L_frame, L_SUBFR, res, voicing, nb_bits, 0 ); + + push_indice( st, IND_ES_PRED, indice, nb_bits ); + } + + /*------------------------------------------------------------* + * Encode excitation according to coding type + *------------------------------------------------------------*/ + + if( st->nelp_mode ) + { + /* SC-VBR - NELP frames */ + encod_nelp( st, mem, inp, Aw, Aq, res, syn, &tmp_noise, exc, exc2, pitch_buf, voice_factors, bwe_exc ); + } + else if( coder_type == UNVOICED ) + { + /* UNVOICED frames (Gauss. excitation) */ + encod_unvoiced( st, mem, inp, Aw, Aq, vad_flag, res, syn, &tmp_noise, exc, pitch_buf, voice_factors, bwe_exc ); + } + else if( coder_type == TRANSITION ) + { + tc_subfr = encod_tran( st, mem, st->L_frame, inp, Aw, Aq, coder_type, Es_pred, T_op, voicing, res, syn, + exc, exc2, pitch_buf, voice_factors, bwe_exc, attack_flag, unbits, sharpFlag ); + } + else if( st->ppp_mode ) + { + /* SC-VBR - PPP frames */ + encod_ppp( st, mem, inp, Aw, Aq, &coder_type, sharpFlag, T_op, voicing, res, syn, exc, exc2, pitch_buf, voice_factors, bwe_exc ); + + if( st->bump_up ) /* PPP failed, bump up */ + { + /* restore memories of LSF quantizer and synthesis filter */ + lsf_syn_mem_restore( st, mem, tilt_code_bck, + gc_threshold_bck, + clip_var_bck, next_force_sf_bck, + lsp_new, lsp_mid, clip_var, mem_AR, mem_MA, lsp_new_bck, lsp_mid_bck, mCb1, Bin_E,Bin_E_old,mem_syn_bck, mem_w0_bck, streaklimit, pstreaklen ); + + /* redo LSF quantization */ + lsf_enc( st, st->L_frame, coder_type, lsf_new, lsp_new, lsp_mid, Aq, &st->stab_fac, st->Nb_ACELP_frames ); + + /* recalculation of LP residual (filtering through A[z] filter) */ + calc_residu( inp, res, Aq, st->L_frame ); + st->burst_ho_cnt = 0; + + /* VOICED frames in SC-VBR */ + encod_gen_voic( st, mem, st->L_frame, sharpFlag, inp, Aw, Aq, coder_type, Es_pred, T_op, voicing, res, syn, + exc, exc2, pitch_buf, voice_factors, bwe_exc, unbits ); + } + } + else if( coder_type == AUDIO || ( coder_type == INACTIVE && st->core_brate <= ACELP_24k40 ) ) + { + /* AUDIO and INACTIVE frames (coded by GSC technology) */ + encod_audio( st, mem, inp, Aw, Aq, T_op, voicing, res, syn, exc, pitch_buf, voice_factors, bwe_exc, attack_flag, coder_type, lsf_new, &tmp_noise ); + } + else + { + /* GENERIC, VOICED and INACTIVE frames (coded by AVQ technology) */ + encod_gen_voic( st, mem, st->L_frame, sharpFlag, inp, Aw, Aq, coder_type, Es_pred, T_op, voicing, res, syn, + exc, exc2, pitch_buf, voice_factors, bwe_exc, unbits ); + } + + + /* update st->mem_syn1 for ACELP core switching */ + mvr2r( mem->mem_syn, st->mem_syn1, M ); + + /* update old synthesis buffer - needed for ACELP internal sampling rate switching */ + mvr2r( syn + st->L_frame - L_SYN_MEM, mem->mem_syn_r, L_SYN_MEM ); + + /* save and delay synthesis to be used by SWB BWE */ + save_old_syn( st->L_frame, syn, old_syn_12k8_16k, st->old_syn_12k8_16k, st->preemph_fac, &st->mem_deemph_old_syn ); + + /*Update MODE2 core switching memory*/ + mvr2r( syn, syn1, st->L_frame ); + deemph( syn1, st->preemph_fac, st->L_frame, &(st->LPDmem.syn[M]) ); + mvr2r( syn1+st->L_frame-M-1, st->LPDmem.syn, M+1 ); + + + /*--------------------------------------------------------------------------------------* + * Modify the excitation signal when the noise is stationary + *--------------------------------------------------------------------------------------*/ + + if ( st->nelp_mode != 1 ) + { + /* exc2 buffer is needed only for updating of Aq[] which is needed for core switching */ + mvr2r( exc, exc2, st->L_frame); + stat_noise_uv_enc( st, coder_type, epsP, lsp_new, lsp_mid, Aq, exc2 ); + } + + /*-----------------------------------------------------------------* + * Encode supplementary information for Frame Error Concealment + *-----------------------------------------------------------------*/ + + FEC_encode( st, syn, coder_type, st->clas, pitch_buf, res, &st->Last_pulse_pos, st->L_frame, st->total_brate, st->core_brate ); + + if( st->L_frame == L_FRAME ) + { + mvr2r( Aq+2*(M+1), st->cur_sub_Aq, (M+1) ); + } + else + { + mvr2r( Aq+3*(M+1), st->cur_sub_Aq, (M+1) ); + } + + + } /* end of active inp coding */ + + + /*-----------------------------------------------------------------* + * Write ACELP unused bits + *-----------------------------------------------------------------*/ + + if ( st->core_brate != SID_2k40 && st->core_brate != FRAME__NO_DATA && st->core_brate != PPP_NELP_2k80 ) + { + /* unused bits */ + if ( coder_type == AUDIO || ( coder_type == INACTIVE && st->core_brate <= ACELP_24k40 ) ) + { + nBits = 0; + } + else if(st->L_frame == L_FRAME ) + { + nBits = reserved_bits_tbl[BIT_ALLOC_IDX(st->core_brate, coder_type, -1, TC_SUBFR2IDX(tc_subfr))]; + } + else + { + nBits = 0; + } + + while( nBits > 0 ) + { + i = min(nBits, 16); + push_indice( st, IND_UNUSED, 0, i ); + nBits -= i; + } + } + + /*-----------------------------------------------------------------* + * Apply non linearity in case of SWB TBE + *-----------------------------------------------------------------*/ + + if( (st->last_Opt_SC_VBR == 1 && st->Opt_SC_VBR == 0) || ((st->extl == SWB_TBE || st->extl == WB_TBE || st->extl == FB_TBE) && st->last_extl != SWB_TBE && st->last_extl != WB_TBE && st->last_extl != FB_TBE) ) + { + st->bwe_non_lin_prev_scale = 0.0f; + set_f( st->old_bwe_exc_extended, 0.0f, NL_BUFF_OFFSET ); + } + + if( !st->Opt_SC_VBR ) + { + /* Apply a non linearity to the SHB excitation */ + non_linearity( bwe_exc, bwe_exc_extended, st->old_bwe_exc_extended, L_FRAME32k, &st->bwe_non_lin_prev_scale, coder_type, voice_factors, st->L_frame ); + } + + if ( st->core_brate == SID_2k40 || st->core_brate == FRAME__NO_DATA ) + { + st->bwe_non_lin_prev_scale = 0.0f; + } + + /*-----------------------------------------------------------------* + * Updates + *-----------------------------------------------------------------*/ + + updt_enc( st, st->L_frame, coder_type, old_exc, pitch_buf, Es_pred, Aq, lsf_new, lsp_new, old_bwe_exc ); + + if( st->Opt_DTX_ON && st->core_brate > SID_2k40 ) + { + /* update CNG parameters in active frames */ + cng_params_upd( lsp_new, exc, st->L_frame, &st->ho_circ_ptr, st->ho_ener_circ, + &st->ho_circ_size, st->ho_lsp_circ, ENC, st->ho_env_circ, + &st->cng_buf_cnt, st->cng_exc2_buf, st->cng_brate_buf, st->last_active_brate ); + + if( st->L_frame == L_FRAME ) + { + /* store LSPs@16k, potentially to be used in CNG@16k */ + mvr2r( st->lsp_old16k, &(st->ho_lsp_circ2[(st->ho_circ_ptr)*M]), M ); + } + + /* set LSP@16k flag for the first buffer */ + st->ho_16k_lsp[st->ho_circ_ptr] = (st->L_frame == L_FRAME ? 0 : 1 ); + + /* efficient DTX hangover control */ + if ( st->burst_ho_cnt > 1 ) + { + dtx_hangover_control( st, lsp_new ); + } + } + + /* SC-VBR update of average data rate */ + if ( vad_flag == 1 ) + { + update_average_rate( st ); + + } + + + + return; +} diff --git a/src/libs/libevs/lib_enc/acelp_core_enc_fx.cpp b/src/libs/libevs/lib_enc/acelp_core_enc_fx.cpp deleted file mode 100755 index b1c2fd97..00000000 --- a/src/libs/libevs/lib_enc/acelp_core_enc_fx.cpp +++ /dev/null @@ -1,651 +0,0 @@ -/*==================================================================================== - EVS Codec 3GPP TS26.442 Apr 03, 2018. Version 12.11.0 / 13.6.0 / 14.2.0 - ====================================================================================*/ - -#include -#include -#include "options.h" /* Compilation switches */ -#include "cnst_fx.h" /* Common constants */ -#include "rom_enc_fx.h" /* Encoder static table prototypes */ -#include "rom_com_fx.h" /* Static table prototypes */ -#include "prot_fx.h" /* Function prototypes */ -#include "stl.h" - -/*-------------------------------------------------------------------* - * acelp_core_enc() - * - * ACELP core encoder - *--------------------------------------------------------------------*/ -void acelp_core_enc_fx( - Encoder_State_fx *st_fx, /* i/o: encoder state structure */ - LPD_state *mem, /* i/o: acelp memories */ - const Word16 inp_fx[], /* i : input signal of the current frame */ - const Word16 vad_flag_fx, - const Word32 ener_fx, /* i : residual energy from Levinson-Durbin*/ - const Word16 pitch[3], /* i : open-loop pitch values for quantiz. */ - const Word16 voicing_fx[3], /* i : Open-loop pitch gains */ - Word16 A_fx[NB_SUBFR16k*(M+1)], /* i : A(z) unquantized for the 4 subframes*/ - Word16 Aw_fx[NB_SUBFR16k*(M+1)], /* i : weighted A(z) unquant. for subframes*/ - const Word16 epsP_h_fx[M+1], /* i : LP prediction errors */ - const Word16 epsP_l_fx[M+1], /* i : LP prediction errors */ - Word16 lsp_new_fx[M], /* i : LSPs at the end of the frame */ - Word16 lsp_mid_fx[M], /* i : LSPs in the middle of the frame */ - Word16 coder_type_fx, /* i : coding type */ - const Word16 sharpFlag_fx, /* i : formant sharpening flag */ - Word16 vad_hover_flag_fx, - const Word16 gsc_attack_flag_fx, /* i : flag signalling attack encoded by AC mode (GSC) */ - Word32 bwe_exc_extended_fx[], /* i/o: bandwidth extended excitation */ - Word16 *voice_factors_fx, /* o : voicing factors */ - Word16 old_syn_12k8_16k_fx[], /* o : intermediate ACELP synthesis at 12.8kHz or 16kHz to be used by SWB BWE */ - Word16 pitch_buf_fx[NB_SUBFR16k], /* o : floating pitch for each subframe */ - Word16 *unbits_fx, /* o : number of unused bits */ - const Word16 Q_new, - const Word16 shift -) -{ - Word16 nBits; /* reserved bits */ - Word16 i; - Word16 old_exc_fx[L_EXC], *exc_fx; /* excitation signal buffer */ - Word16 lsf_new_fx[M]; /* ISFs at the end of the frame */ - Word16 Aq_fx[NB_SUBFR16k*(M+1)]; /* A(z) quantized for the 4 subframes */ - Word16 syn_fx[L_FRAME16k]; /* synthesis vector */ - Word16 res_fx[L_FRAME16k]; /* Residual signal for FER protection */ - Word16 exc2_fx[L_FRAME16k]; /* enhanced excitation */ - Word16 Es_pred_fx; /* predicited scaled innovation energy */ - Word16 tmp_noise_fx; /* NB post-filter long-term noise energy*/ - Word16 tc_subfr_fx; /* TC sub-frame indication */ - Word16 old_bwe_exc_fx[(PIT16k_MAX + (L_FRAME16k + 1) + L_SUBFR16k) * 2]; /* excitation buffer */ - Word16 *bwe_exc_fx; /* excitation for SWB TBE */ - Word16 allow_cn_step_fx; - Word16 int_fs_fx; - Word32 L_epsP[2]; - /* SC-VBR - back-up memories for LSF quantizer and synthesis filter */ - Word16 mCb1_fx, pstreaklen_fx; - Word16 mem_MA_fx[M], mem_AR_fx[M], lsp_new_bck_fx[M], lsf_new_bck_fx[M], lsp_mid_bck_fx[M], mem_syn_bck_fx[M]; - Word32 Bin_E_fx[L_FFT], Bin_E_old_fx[L_FFT/2]; - Word16 clip_var_fx, mem_w0_bck_fx, streaklimit_fx; - Word16 T_op_fx[3]; - Word16 nb_bits; - Word16 indice; - Word16 tmp16; - Word16 enr_index; - Word16 enr, maxv, scale, att; - Word16 hi, lo; - Word16 *pt_res; - Word32 L_tmp, L_ener; - - Word16 tilt_code_bck_fx; - Word32 gc_threshold_bck_fx; - Word16 clip_var_bck_fx[6]; - Word16 next_force_sf_bck_fx; - Word32 q_env[NUM_ENV_CNG]; - Word16 sid_bw=-1; - Word16 exc3_fx[L_FRAME16k]; - Word16 syn1_fx[L_FRAME16k]; - - - - /*------------------------------------------------------------------* - * Initialization - *------------------------------------------------------------------*/ - - Es_pred_fx = 0; - move16(); - - Copy( pitch, T_op_fx, 3 ); - - /* convert pitch values to 16kHz domain */ - IF ( sub(st_fx->L_frame_fx,L_FRAME16k) == 0 ) - { - /*T_op[0] = (short)(T_op[0] * 1.25f + 0.5f);*/ - T_op_fx[0] = round_fx(L_mac(L_shl(T_op_fx[0],16), T_op_fx[0], 8192)); - /*T_op[1] = (short)(T_op[1] * 1.25f + 0.5f);*/ - T_op_fx[1] = round_fx(L_mac(L_shl(T_op_fx[1],16), T_op_fx[1], 8192)); - T_op_fx[2] = T_op_fx[1]; - move16(); - } - exc_fx = old_exc_fx + L_EXC_MEM; /* pointer to excitation signal in the current frame */ - Copy( mem->old_exc, old_exc_fx, L_EXC_MEM ); - - bwe_exc_fx = old_bwe_exc_fx + PIT16k_MAX * 2; /* pointer to BWE excitation signal in the current frame */ - Copy( st_fx->old_bwe_exc_fx, old_bwe_exc_fx, PIT16k_MAX * 2); - - st_fx->bpf_off_fx = 0; - move16(); - test(); - IF( sub(st_fx->last_core_fx,HQ_CORE) == 0 || sub(st_fx->last_codec_mode,MODE2)==0) - { - /* in case of HQ->ACELP switching, do not apply BPF */ - st_fx->bpf_off_fx = 1; - move16(); - st_fx->Last_frame_ener_fx = MAX_32; - move32(); - } - - /* force safety-net LSFQ in the first frames after CNG segment */ - if( L_sub(st_fx->last_core_brate_fx,SID_2k40) <= 0 ) - { - st_fx->Nb_ACELP_frames_fx = 0; - move16(); - } - st_fx->Nb_ACELP_frames_fx = add(st_fx->Nb_ACELP_frames_fx,1); - - int_fs_fx = INT_FS_16k_FX; - move16(); - if( sub(st_fx->L_frame_fx, L_FRAME) == 0) - { - int_fs_fx = INT_FS_FX; - move16(); - } - - tmp_noise_fx = 0; - move16(); - tc_subfr_fx = 0; - move16(); - - /* SC-VBR temporary variables */ - mCb1_fx = 0; - move16(); - pstreaklen_fx = 0; - move16(); - clip_var_fx = 0; - move16(); - mem_w0_bck_fx = 0; - move16(); - streaklimit_fx = 0; - move16(); - - /* channel-aware mode */ - reset_rf_indices(st_fx); - - /*-----------------------------------------------------------------* - * ACELP@12k8 / ACELP@16k switching - *-----------------------------------------------------------------*/ - test(); - IF( sub(st_fx->last_L_frame_fx,st_fx->L_frame_fx) != 0 && sub(st_fx->last_core_fx,HQ_CORE) != 0 ) - { - /* in case of switching, do not apply BPF */ - st_fx->bpf_off_fx = 1; - move16(); - - /* force safety-net LSFQ in the first frames after ACELP@12k8/ACELP@16k switching */ - st_fx->Nb_ACELP_frames_fx = 1; - move16(); - - /* convert old quantized LSP vector */ - IF( sub(st_fx->L_frame_fx,L_FRAME) == 0 ) - { - st_fx->rate_switching_reset = lsp_convert_poly_fx( st_fx->lsp_old_fx, st_fx->L_frame_fx, 0 ); - } - ELSE - { - st_fx->rate_switching_reset=st_fx->rate_switching_reset_16kHz; - move16(); - Copy( st_fx->lsp_old16k_fx, st_fx->lsp_old_fx, M ); - } - - /* convert old quantized LSF vector */ - lsp2lsf_fx( st_fx->lsp_old_fx, st_fx->lsf_old_fx, M, int_fs_fx ); - - /* interpolation of unquantized ISPs */ - IF( st_fx->rate_switching_reset ) - { - /*extrapolation in case of unstable LSP*/ - int_lsp4_fx( st_fx->L_frame_fx, lsp_mid_fx, lsp_mid_fx, lsp_new_fx, A_fx, M, 0 ); - } - ELSE - { - int_lsp4_fx( st_fx->L_frame_fx, st_fx->lsp_old_fx, lsp_mid_fx, lsp_new_fx, A_fx, M, 0 ); - } - - /* Reset LPC mem */ - Copy( GEWB_Ave_fx, st_fx->mem_AR_fx, M ); - set16_fx( st_fx->mem_MA_fx,0, M ); - - /* update synthesis filter memories */ - synth_mem_updt2( st_fx->L_frame_fx, st_fx->last_L_frame_fx, mem->old_exc, mem->mem_syn_r,mem->mem_syn2, mem->mem_syn, ENC ); - Copy( mem->old_exc, old_exc_fx, L_EXC_MEM ); - Copy( mem->mem_syn2,st_fx->mem_syn1_fx, M ); - Copy( mem->mem_syn2, mem->mem_syn3, M ); - - /* update Aw[] coefficients */ - weight_a_subfr_fx( shr(st_fx->L_frame_fx,6), A_fx, Aw_fx, st_fx->gamma, M ); - - } - - test(); - test(); - if(sub(st_fx->last_bwidth_fx,NB)==0 && sub(st_fx->bwidth_fx,NB)!=0 && st_fx->ini_frame_fx!=0) - { - st_fx->rate_switching_reset=1; - move16(); - } - /*----------------------------------------------------------------* - * Encoding of CNG frames - *----------------------------------------------------------------*/ - test(); - IF ( L_sub(st_fx->core_brate_fx,SID_2k40) == 0 || L_sub(st_fx->core_brate_fx,FRAME_NO_DATA) == 0 ) - { - IF( sub(st_fx->cng_type_fx,LP_CNG) == 0 ) - { - /* Run CNG post parameter update */ - cng_params_postupd_fx( st_fx->ho_circ_ptr_fx, &st_fx->cng_buf_cnt, st_fx->cng_exc2_buf, st_fx->cng_Qexc_buf, - st_fx->cng_brate_buf, st_fx->ho_env_circ_fx); - /* encode CNG parameters */ - CNG_enc_fx( st_fx, st_fx->L_frame_fx, Aq_fx, inp_fx, ener_fx, lsp_new_fx, lsf_new_fx, &allow_cn_step_fx, st_fx->burst_ho_cnt_fx, sub(Q_new,1), q_env, &sid_bw, st_fx->exc_mem2_fx ); - - /* comfort noise generation */ - CNG_exc_fx( st_fx->core_brate_fx, st_fx->L_frame_fx, &st_fx->Enew_fx, &st_fx->cng_seed_fx, exc_fx, exc2_fx, &st_fx->lp_ener_fx, st_fx->last_core_brate_fx, - &st_fx->first_CNG_fx, &st_fx->cng_ener_seed_fx, bwe_exc_fx, allow_cn_step_fx, &st_fx->last_allow_cn_step_fx, sub(st_fx->prev_Q_new,1), sub(Q_new,1), st_fx->num_ho_fx, - q_env, st_fx->lp_env_fx, st_fx->old_env_fx, st_fx->exc_mem_fx, st_fx->exc_mem1_fx, &sid_bw, &st_fx->cng_ener_seed1_fx, exc3_fx, st_fx->Opt_AMR_WB_fx ); - } - ELSE - { - IF( L_sub(st_fx->core_brate_fx, SID_2k40) == 0 ) - { - FdCng_encodeSID( st_fx->hFdCngEnc_fx, st_fx, st_fx->preemph_fac ); - st_fx->last_CNG_L_frame_fx = st_fx->L_frame_fx; - move16(); - } - - generate_comfort_noise_enc( st_fx, Q_new, 1 ); - - FdCng_exc( st_fx->hFdCngEnc_fx->hFdCngCom, &st_fx->CNG_mode_fx, st_fx->L_frame_fx, st_fx->lsp_old_fx, - st_fx->first_CNG_fx, st_fx->lspCNG_fx, Aq_fx, lsp_new_fx, lsf_new_fx, exc_fx, exc2_fx, bwe_exc_fx ); - - Copy( exc2_fx, exc3_fx, st_fx->L_frame_fx ); - - IF( L_sub(st_fx->core_brate_fx, SID_2k40) == 0 ) - { - maxv = 0; - move16(); - FOR(i = 0; i < st_fx->L_frame_fx; i++) - { - maxv = s_max(maxv, abs_s(exc_fx[i])); - } - scale = norm_s(maxv); - pt_res = exc_fx; - L_ener = L_deposit_l(1); - IF( sub(st_fx->L_frame_fx, L_FRAME) == 0) - { - FOR (i=0; i<128; i++) - { - tmp16 = shl(*pt_res,scale); - L_tmp = L_mult0(tmp16, tmp16); - pt_res++; - tmp16 = shl(*pt_res,scale); - L_tmp = L_mac0(L_tmp, tmp16, tmp16); /* 2*(Q_new+scale) */ - pt_res++; - L_ener = L_add(L_ener, L_shr(L_tmp, 7)); /* 2*(Q_new+scale)+1, divide by L_frame done here */ - } - } - ELSE /* L_FRAME16k */ - { - FOR (i=0; i<160; i++) - { - tmp16 = shl(*pt_res,scale); - L_tmp = L_mult0(tmp16, tmp16); - pt_res++; - tmp16 = shl(*pt_res,scale); - L_tmp = L_mac0(L_tmp, tmp16, tmp16); /* 2*(Q_new+scale) */ - pt_res++; - L_ener = L_add(L_ener, L_shr(Mult_32_16(L_tmp,26214 /* 256/320, Q15 */), 7)); /* 2*(Q_new+scale)+15+1-16+1, divide by L_frame done here */ - } - } - - hi = norm_l(L_ener); - lo = Log2_norm_lc(L_shl(L_ener, hi)); - hi = sub(30, add(hi, shl(add(Q_new, scale), 1))); /* log2 exp in Q2*(Q_new+scale) */ - L_tmp = L_Comp(hi, lo); /* Q16 */ - enr = round_fx(L_shl(L_tmp, 8)); /* Q8 (16+8-16) */ - - /* decrease the energy in case of WB input */ - IF( sub(st_fx->bwidth_fx, NB) != 0 ) - { - IF( sub(st_fx->bwidth_fx,WB) == 0 ) - { - IF( st_fx->CNG_mode_fx >= 0 ) - { - /* Bitrate adapted attenuation */ - att = ENR_ATT_fx[st_fx->CNG_mode_fx]; - } - ELSE - { - /* Use least attenuation for higher bitrates */ - att = ENR_ATT_fx[4]; - } - } - ELSE - { - att = 384; - move16();/*Q8*/ - } - enr = sub(enr, att ); - } - - /* calculate the energy quantization index */ - enr_index = add(enr, 512 /* Q8(2.0) */); /* enr + 2.0 */ - enr_index = extract_l(L_shr(L_mult0(enr_index, STEP_SID_FX), 12+8)); /* Q0 (8+12-(8+12)) */ - - /* limit the energy quantization index */ - enr_index = s_min(enr_index, 127); - enr_index = s_max(enr_index, 0); - - st_fx->old_enr_index_fx = enr_index; - move16(); - } - } - - /* synthesis at 12.8kHz sampling rate */ - syn_12k8_fx( st_fx->L_frame_fx, Aq_fx, exc3_fx, syn1_fx, mem->mem_syn3, 1, Q_new, st_fx->Q_syn ); - - /* reset the encoder */ - CNG_reset_enc_fx( st_fx, mem, pitch_buf_fx, voice_factors_fx, 0 ); - - /* update st->mem_syn1 for ACELP core switching */ - Copy( mem->mem_syn3, st_fx->mem_syn1_fx, M ); - - /* update ACELP core synthesis filter memory */ - Copy( mem->mem_syn3, mem->mem_syn, M ); - - /* update old synthesis buffer - needed for ACELP internal sampling rate switching */ - Copy( syn1_fx + st_fx->L_frame_fx - L_SYN_MEM, mem->mem_syn_r, L_SYN_MEM ); - - /* save and delay synthesis to be used by SWB BWE */ - save_old_syn_fx( st_fx->L_frame_fx, syn1_fx, old_syn_12k8_16k_fx, st_fx->old_syn_12k8_16k_fx, st_fx->preemph_fac, &st_fx->mem_deemph_old_syn_fx ); - /* Update MODE2 core switching memory */ - tmp16 = mem->syn[M]; - move16(); - E_UTIL_deemph2( sub(Q_new,1), syn1_fx, st_fx->preemph_fac, st_fx->L_frame_fx, &tmp16 ); - Copy( syn1_fx+st_fx->L_frame_fx-M-1, mem->syn, M+1 ); - - } - - /*----------------------------------------------------------------* - * Encoding of all other frames - *----------------------------------------------------------------*/ - - ELSE - { - /*-----------------------------------------------------------------* - * After inactive period, use the most up-to-date ISPs - *-----------------------------------------------------------------*/ - - test(); - IF ( L_sub(st_fx->last_core_brate_fx,FRAME_NO_DATA) == 0 || L_sub(st_fx->last_core_brate_fx,SID_2k40) == 0 ) - { - Copy( st_fx->lspCNG_fx, st_fx->lsp_old_fx, M ); - - lsp2lsf_fx( st_fx->lspCNG_fx, st_fx->lsf_old_fx, M, int_fs_fx ); - } - - /*-----------------------------------------------------------------* - * Reset higher ACELP pre-quantizer in case of switching - *-----------------------------------------------------------------*/ - IF( !st_fx->use_acelp_preq ) - { - st_fx->mem_deemp_preQ_fx = 0; - move16(); - st_fx->mem_preemp_preQ_fx = 0; - move16(); - st_fx->last_nq_preQ_fx = 0; - move16(); - } - - st_fx->use_acelp_preq = 0; - move16(); - - /*-----------------------------------------------------------------* - * LSF Quantization - * A[z] calculation - *-----------------------------------------------------------------*/ - - /* SC-VBR - back-up memories for LSF quantizer and synthesis filter */ - lsf_syn_mem_backup_fx( st_fx, &(st_fx->LPDmem), &tilt_code_bck_fx, &gc_threshold_bck_fx, clip_var_bck_fx, &next_force_sf_bck_fx, - lsp_new_fx, lsf_new_fx, lsp_mid_fx, &clip_var_fx, mem_AR_fx, mem_MA_fx, lsp_new_bck_fx, lsf_new_bck_fx, - lsp_mid_bck_fx, &mCb1_fx, Bin_E_fx, Bin_E_old_fx, mem_syn_bck_fx, &mem_w0_bck_fx, &streaklimit_fx, &pstreaklen_fx); - - lsf_enc_fx( st_fx, st_fx->L_frame_fx, coder_type_fx, lsf_new_fx, lsp_new_fx, lsp_mid_fx, Aq_fx, &st_fx->stab_fac_fx, - st_fx->Nb_ACELP_frames_fx, Q_new ); - - /*---------------------------------------------------------------* - * Calculation of LP residual (filtering through A[z] filter) - *---------------------------------------------------------------*/ - - calc_residu_fx( st_fx, inp_fx, res_fx, Aq_fx, vad_hover_flag_fx ); - - /*---------------------------------------------------------------* - * Calculation of prediction for scaled innovation energy - * (for memory-less gain quantizer) - *---------------------------------------------------------------*/ - test(); - test(); - test(); - test(); - test(); - test(); - IF( ( sub(coder_type_fx,UNVOICED) != 0 && sub(coder_type_fx,AUDIO) != 0 && sub(coder_type_fx,INACTIVE) != 0 - && !(L_sub(st_fx->core_brate_fx,ACELP_8k00) <= 0 && sub(coder_type_fx,TRANSITION) != 0) ) - || (sub(coder_type_fx,INACTIVE) == 0 && L_sub(st_fx->total_brate_fx,ACELP_32k) >= 0) ) - { - nb_bits = Es_pred_bits_tbl[BIT_ALLOC_IDX_fx(st_fx->core_brate_fx, coder_type_fx, -1, -1)]; - move16(); - Es_pred_enc_fx( &Es_pred_fx, &indice, st_fx->L_frame_fx, res_fx, voicing_fx, nb_bits, 0, Q_new ); - push_indice_fx( st_fx, IND_ES_PRED, indice, nb_bits ); - } - - - /*------------------------------------------------------------* - * Encode excitation according to coding type - *------------------------------------------------------------*/ - test(); - test(); - IF( st_fx->nelp_mode_fx ) - { - /* SC-VBR - NELP frames */ - encod_nelp_fx( st_fx, mem, inp_fx, Aw_fx, Aq_fx, res_fx, syn_fx, &tmp_noise_fx, exc_fx, exc2_fx, pitch_buf_fx, - voice_factors_fx, bwe_exc_fx, Q_new, shift); - } - ELSE IF( sub(coder_type_fx,UNVOICED) == 0 ) - { - /* UNVOICED frames (Gauss. excitation) */ - encod_unvoiced_fx( st_fx, mem, inp_fx, Aw_fx, Aq_fx, vad_flag_fx, res_fx, syn_fx, - &tmp_noise_fx, exc_fx, pitch_buf_fx, voice_factors_fx, bwe_exc_fx,Q_new,shift ); - } - ELSE IF( sub(coder_type_fx,TRANSITION) == 0) - { - tc_subfr_fx = encod_tran_fx( st_fx, mem, st_fx->L_frame_fx, inp_fx, Aw_fx, Aq_fx, coder_type_fx, Es_pred_fx, T_op_fx, voicing_fx, res_fx, syn_fx, - exc_fx, exc2_fx, pitch_buf_fx, voice_factors_fx, bwe_exc_fx, gsc_attack_flag_fx, unbits_fx, sharpFlag_fx, shift, Q_new ); - move16(); - } - ELSE IF( st_fx->ppp_mode_fx ) - { - encod_ppp_fx( st_fx, mem, inp_fx, Aw_fx, Aq_fx, &coder_type_fx, sharpFlag_fx, T_op_fx, voicing_fx, - res_fx, syn_fx, exc_fx, exc2_fx, pitch_buf_fx, voice_factors_fx, bwe_exc_fx, Q_new, shift); - - IF( st_fx->bump_up_fx ) /* PPP failed, bump up */ - { - /* restore memories of LSF quantizer and synthesis filter */ - lsf_syn_mem_restore_fx( st_fx, &(st_fx->LPDmem), tilt_code_bck_fx, gc_threshold_bck_fx, clip_var_bck_fx, next_force_sf_bck_fx, - lsp_new_fx, lsf_new_fx, lsp_mid_fx, clip_var_fx, mem_AR_fx, mem_MA_fx, lsp_new_bck_fx, lsf_new_bck_fx, - lsp_mid_bck_fx, mCb1_fx, Bin_E_fx,Bin_E_old_fx,mem_syn_bck_fx, mem_w0_bck_fx, streaklimit_fx, pstreaklen_fx ); - - /* redo LSF quantization */ - lsf_enc_fx( st_fx, st_fx->L_frame_fx, coder_type_fx, lsf_new_fx, lsp_new_fx, lsp_mid_fx, Aq_fx, &st_fx->stab_fac_fx, st_fx->Nb_ACELP_frames_fx, Q_new ); - - /* recalculation of LP residual (filtering through A[z] filter) */ - calc_residu_fx( st_fx, inp_fx, res_fx, Aq_fx, 0 ); - - /* VOICED frames in SC-VBR when bumped up*/ - encod_gen_voic_fx( st_fx, mem, st_fx->L_frame_fx, sharpFlag_fx, inp_fx, Aw_fx, Aq_fx, coder_type_fx, Es_pred_fx, T_op_fx, voicing_fx, res_fx, syn_fx, - exc_fx, exc2_fx, pitch_buf_fx, voice_factors_fx, bwe_exc_fx, unbits_fx, shift, Q_new ); - } - } - ELSE IF( sub(coder_type_fx,AUDIO) == 0 || ( sub(coder_type_fx,INACTIVE) == 0 && L_sub(st_fx->core_brate_fx,ACELP_24k40) <= 0 ) ) - { - /* AUDIO and INACTIVE frames (coded by GSC technology) */ - encod_audio_fx( st_fx, mem, inp_fx, Aw_fx, Aq_fx, T_op_fx, voicing_fx, res_fx, syn_fx, exc_fx, pitch_buf_fx, voice_factors_fx, bwe_exc_fx, - gsc_attack_flag_fx, coder_type_fx, lsf_new_fx, &tmp_noise_fx, Q_new , shift); - } - ELSE - { - /* GENERIC, VOICED and INACTIVE frames (coded by AVQ technology) */ - encod_gen_voic_fx( st_fx, mem, st_fx->L_frame_fx, sharpFlag_fx, inp_fx, Aw_fx, Aq_fx, coder_type_fx, Es_pred_fx, T_op_fx, voicing_fx, res_fx, syn_fx, - exc_fx, exc2_fx, pitch_buf_fx, voice_factors_fx, bwe_exc_fx, unbits_fx, shift, Q_new ); - } - - /* update st->mem_syn1 for ACELP core switching */ - Copy( mem->mem_syn, st_fx->mem_syn1_fx, M ); - - /* update old synthesis buffer - needed for ACELP internal sampling rate switching */ - Copy( syn_fx + st_fx->L_frame_fx - L_SYN_MEM, mem->mem_syn_r, L_SYN_MEM ); - - /* save and delay synthesis to be used by SWB BWE */ - save_old_syn_fx( st_fx->L_frame_fx, syn_fx, old_syn_12k8_16k_fx, st_fx->old_syn_12k8_16k_fx, st_fx->preemph_fac, &st_fx->mem_deemph_old_syn_fx ); - - /*Update MODE2 core switching memory*/ - Copy( syn_fx, syn1_fx, st_fx->L_frame_fx ); - E_UTIL_deemph2( sub(Q_new,1), syn1_fx, st_fx->preemph_fac, st_fx->L_frame_fx, &mem->syn[M] ); - Copy( syn1_fx+st_fx->L_frame_fx-M-1, mem->syn, M+1 ); - - - /*--------------------------------------------------------------------------------------* - * Modify the excitation signal when the noise is stationary - *--------------------------------------------------------------------------------------*/ - - IF ( sub(st_fx->nelp_mode_fx,1) != 0 ) - { - L_epsP[0] = L_Comp(epsP_h_fx[2],epsP_l_fx[2]); - move32(); - L_epsP[1] = L_Comp(epsP_h_fx[M],epsP_l_fx[M]); - move32(); - Copy(exc_fx, exc2_fx, st_fx->L_frame_fx); - stat_noise_uv_enc_fx( st_fx, coder_type_fx, L_epsP, lsp_new_fx, lsp_mid_fx, Aq_fx, exc2_fx, Q_new ); - } - - /*-----------------------------------------------------------------* - * Encode supplementary information for Frame Error Concealment - *-----------------------------------------------------------------*/ - - FEC_encode_fx( st_fx, syn_fx, coder_type_fx, st_fx->clas_fx, pitch_buf_fx, res_fx, &st_fx->Last_pulse_pos_fx, - st_fx->L_frame_fx, st_fx->total_brate_fx, st_fx->core_brate_fx, Q_new, shift ); - - IF( sub(st_fx->L_frame_fx,L_FRAME) == 0 ) - { - Copy( Aq_fx+2*(M+1), st_fx->cur_sub_Aq_fx, (M+1) ); - } - ELSE - { - Copy( Aq_fx+3*(M+1), st_fx->cur_sub_Aq_fx, (M+1) ); - } - - } /* end of active inp coding */ - - /*-----------------------------------------------------------------* - * Write ACELP unused bits - *-----------------------------------------------------------------*/ - - test(); - test(); - IF ( L_sub(st_fx->core_brate_fx,SID_2k40) != 0 && L_sub(st_fx->core_brate_fx,FRAME_NO_DATA) != 0 && L_sub(st_fx->core_brate_fx,PPP_NELP_2k80) != 0 ) - { - /* reserved bits */ - test(); - test(); - IF ( sub(coder_type_fx,AUDIO) == 0 || ( sub(coder_type_fx,INACTIVE) == 0 && L_sub(st_fx->core_brate_fx,ACELP_24k40) <= 0 ) ) - { - nBits = 0; - move16(); - } - ELSE IF( sub(st_fx->L_frame_fx,L_FRAME) == 0 ) - { - nBits = reserved_bits_tbl[BIT_ALLOC_IDX_fx(st_fx->core_brate_fx, coder_type_fx, -1, TC_SUBFR2IDX_fx(tc_subfr_fx))]; - move16(); - } - ELSE - { - nBits = 0; - move16(); - } - WHILE( nBits > 0 ) - { - i = s_min(nBits, 16); - push_indice_fx( st_fx, IND_UNUSED, 0, i ); - nBits = sub(nBits,i); - } - } - - - /*-----------------------------------------------------------------* - * Apply non linearity in case of SWB TBE - *-----------------------------------------------------------------*/ - - test(); - test(); - test(); - test(); - test(); - test(); - test(); - IF ( (sub(st_fx->last_Opt_SC_VBR_fx,1)==0 && st_fx->Opt_SC_VBR_fx==0) || ((sub(st_fx->extl_fx,SWB_TBE)==0 || sub(st_fx->extl_fx,WB_TBE)==0 || sub(st_fx->extl_fx,FB_TBE)==0) && sub(st_fx->last_extl_fx,SWB_TBE)!=0 && sub(st_fx->last_extl_fx,WB_TBE)!=0 && sub(st_fx->last_extl_fx,FB_TBE)!=0) ) - { - st_fx->bwe_non_lin_prev_scale_fx = L_deposit_l(0); - set16_fx( st_fx->old_bwe_exc_extended_fx, 0, NL_BUFF_OFFSET ); - } - - IF( !st_fx->Opt_SC_VBR_fx ) - { - /* Apply a non linearity to the SHB excitation */ - non_linearity_fx( bwe_exc_fx, bwe_exc_extended_fx, L_FRAME32k, &st_fx->bwe_non_lin_prev_scale_fx, Q_new, coder_type_fx, voice_factors_fx, st_fx->L_frame_fx); - } - test(); - if ( L_sub(st_fx->core_brate_fx,SID_2k40) == 0 || L_sub(st_fx->core_brate_fx,FRAME_NO_DATA) == 0 ) - { - st_fx->bwe_non_lin_prev_scale_fx = L_deposit_l(0); - } - - /*-----------------------------------------------------------------* - * Updates - *-----------------------------------------------------------------*/ - updt_enc_fx( st_fx, st_fx->L_frame_fx, coder_type_fx, old_exc_fx, pitch_buf_fx, - Es_pred_fx,Aq_fx, lsf_new_fx, lsp_new_fx, old_bwe_exc_fx ); - - test(); - IF( (st_fx->Opt_DTX_ON_fx != 0 ) && (L_sub(st_fx->core_brate_fx,SID_2k40) > 0) ) - { - /* update CNG parameters in active frames */ - cng_params_upd_fx( lsp_new_fx, exc_fx, st_fx->L_frame_fx, &st_fx->ho_circ_ptr_fx, st_fx->ho_ener_circ_fx, - &st_fx->ho_circ_size_fx, st_fx->ho_lsp_circ_fx, Q_new, ENC, NULL, &st_fx->cng_buf_cnt, - st_fx->cng_exc2_buf, st_fx->cng_Qexc_buf, st_fx->cng_brate_buf, st_fx->last_active_brate_fx ); - - IF( sub(st_fx->L_frame_fx,L_FRAME) == 0 ) - { - /* store LSPs@16k, potentially to be used in CNG@16k */ - Copy( st_fx->lsp_old16k_fx, &(st_fx->ho_lsp_circ2_fx[(st_fx->ho_circ_ptr_fx)*M]), M ); - } - - /* Set 16k LSP flag for CNG buffer */ - st_fx->ho_16k_lsp_fx[st_fx->ho_circ_ptr_fx] = 0; - move16(); - if(sub(st_fx->L_frame_fx, L_FRAME) != 0) - { - st_fx->ho_16k_lsp_fx[st_fx->ho_circ_ptr_fx] = 1; - move16(); - } - - /* efficient DTX hangover control */ - IF ( sub(st_fx->burst_ho_cnt_fx,1) > 0 ) - { - dtx_hangover_control_fx( st_fx, lsp_new_fx ); - } - } - - /* SC-VBR update of average data rate */ - IF ( sub(vad_flag_fx,1) == 0 ) - { - update_average_rate_fx( st_fx ); - - } - - return; -} diff --git a/src/libs/libevs/lib_enc/acelp_core_switch_enc.cpp b/src/libs/libevs/lib_enc/acelp_core_switch_enc.cpp new file mode 100644 index 00000000..061779cb --- /dev/null +++ b/src/libs/libevs/lib_enc/acelp_core_switch_enc.cpp @@ -0,0 +1,438 @@ +/*==================================================================================== + EVS Codec 3GPP TS26.443 Nov 13, 2018. Version 12.11.0 / 13.7.0 / 14.3.0 / 15.1.0 + ====================================================================================*/ + +#include +#include +#include "options.h" +#include "cnst.h" +#include "rom_enc.h" +#include "rom_com.h" +#include "prot.h" +#include "prot.h" + +/*---------------------------------------------------------------------* + * Local functions + *---------------------------------------------------------------------*/ + +static void encod_gen_voic_core_switch( Encoder_State *st, LPD_state *mem,const short L_frame, const float inp[], + const float Aq[], const float A[], const short coder_type, const short T_op[], + const float voicing[], float *exc, const long core_bitrate ); + +static void bwe_switch_enc( Encoder_State *st, const float *old_input ); + +/*-------------------------------------------------------------------* + * acelp_core_switch_enc() + * + * ACELP core encoder in the ACELP->HQ switching frame + *--------------------------------------------------------------------*/ + +void acelp_core_switch_enc( + Encoder_State *st, /* i/o: encoder state structure */ + LPD_state *mem, /* i/o: encoder memories */ + const float inp12k8[], /* i : input signal @12.8 kHz */ + const float inp16k[], /* i : input signal @16 kHz */ + const short T_op_orig[2], /* i : open-loop pitch values for quantiz. */ + const float voicing[3], /* i : Open-loop pitch gains */ + const float A[NB_SUBFR16k*(M+1)] /* i : A(z) unquantized for the 4 subframes*/ +) +{ + short i, T_op[2]; + float old_exc[L_EXC], *exc; /* excitation signal buffer */ + const float *inp; + long cbrate; + float Aq[2*(M+1)]; + + /* initializations */ + exc = old_exc + L_EXC_MEM; /* pointer to excitation signal in the current frame */ + mvr2r( mem->old_exc, old_exc, L_EXC_MEM ); + + mvr2r( st->old_Aq_12_8, Aq, M+1 ); + mvr2r( st->old_Aq_12_8, Aq + (M+1), M+1 ); + + T_op[0] = T_op_orig[0]; + T_op[1] = T_op_orig[1]; + + /*----------------------------------------------------------------* + * set switching frame bit-rate + *----------------------------------------------------------------*/ + + if( st->last_L_frame == L_FRAME ) /* ACELP@12k8 core */ + { + inp = inp12k8; + + if( st->core_brate > ACELP_24k40 ) + { + cbrate = ACELP_24k40; + } + else + { + cbrate = st->core_brate; + } + } + else /* ACELP@16k core */ + { + inp = inp16k; + + if( st->core_brate <= ACELP_8k00 ) + { + cbrate = ACELP_8k00; + } + else if( st->core_brate <= ACELP_14k80 ) + { + cbrate = ACELP_14k80; + } + else + { + cbrate = min( st->core_brate, ACELP_22k60 ); + } + } + + if( st->last_L_frame != st->L_frame ) + { + if( st->last_L_frame == L_FRAME ) + { + T_op[0] = (short)(0.8f * T_op[0] + 0.5f); + T_op[1] = (short)(0.8f * T_op[1] + 0.5f); + } + else + { + T_op[0] = (short)(1.25f * T_op[0] + 0.5f); + T_op[1] = (short)(1.25f * T_op[1] + 0.5f); + } + } + + /*----------------------------------------------------------------* + * Excitation encoding + *----------------------------------------------------------------*/ + + encod_gen_voic_core_switch( st, mem, st->last_L_frame, inp, Aq, A, GENERIC, T_op, voicing, exc, cbrate ); + + + /*----------------------------------------------------------------* + * Manipulate ACELP subframe indices (move them to their proper place) + *----------------------------------------------------------------*/ + + for( i=0; i<20; i++ ) + { + st->ind_list[IND_CORE_SWITCHING_CELP_SUBFRAME+i].value = st->ind_list[TAG_ACELP_SUBFR_LOOP_START+i].value; + st->ind_list[IND_CORE_SWITCHING_CELP_SUBFRAME+i].nb_bits = st->ind_list[TAG_ACELP_SUBFR_LOOP_START+i].nb_bits; + st->ind_list[TAG_ACELP_SUBFR_LOOP_START+i].nb_bits = -1; + } + + /*----------------------------------------------------------------* + * BWE encoding + *----------------------------------------------------------------*/ + + if( !( (st->last_L_frame == L_FRAME16k && inner_frame_tbl[st->bwidth]==L_FRAME16k ) || inner_frame_tbl[st->bwidth] == L_FRAME8k ) ) + { + bwe_switch_enc( st, (const float *)st->old_input_signal ); + } + + return; +} + + +/*-------------------------------------------------------------------* + * encod_gen_voic_core_switch() + * + * Encode excitation signal in ACELP->HQ switching frame + *-------------------------------------------------------------------*/ + +static void encod_gen_voic_core_switch( + Encoder_State *st, /* i/o: state structure */ + LPD_state *mem, /* i/o: encoder memories */ + const short L_frame, /* i : length of the frame */ + const float inp[], /* i : input signal */ + const float Aq[], /* i : LP coefficients */ + const float A[], /* i : unquantized A(z) filter */ + const short coder_type, /* i : coding type */ + const short T_op[], /* i : open loop pitch */ + const float voicing[], /* i : voicing */ + float *exc, /* i/o: current non-enhanced excitation */ + const long core_bitrate /* i : switching frame bit-rate */ +) +{ + float res[L_SUBFR]; /* residual signal */ + float Ap[M+1]; /* A(z) with spectral expansion */ + float xn[L_SUBFR]; /* Target vector for pitch search */ + float xn2[L_SUBFR]; /* Target vector for codebook search */ + float cn[L_SUBFR]; /* Target vector in residual domain */ + float h1[L_SUBFR+(M+1)]; /* Impulse response vector */ + float code[L_SUBFR]; /* Fixed codebook excitation */ + float y1[L_SUBFR]; /* Filtered adaptive excitation */ + float y2[L_SUBFR]; /* Filtered algebraic excitation */ + float gain_pit ; /* Pitch gain */ + float voice_fac; /* Voicing factor */ + float gain_code; /* Gain of code */ + float gain_inov; /* inovation gain */ + short i; /* tmp variables */ + short T0, T0_frac; /* close loop integer pitch and fractional part */ + short T0_min, T0_max; /* pitch variables */ + float pitch; /* floating pitch value */ + float g_corr[6]; /* ACELP correl, values + gain pitch */ + short clip_gain; /* ISF clip gain */ + short unbits; /* number of unused bits for EVS_PI */ + float norm_gain_code; + short pitch_limit_flag; + float tmpF; + short lp_select, lp_flag; + + /*------------------------------------------------------------------* + * Initializations + *------------------------------------------------------------------*/ + + unbits = 0; + + if( L_frame == L_FRAME ) + { + T0_max = PIT_MAX; + T0_min = PIT_MIN; + } + else /* L_frame == L_FRAME16k */ + { + T0_max = PIT16k_MAX; + T0_min = PIT16k_MIN; + } + + /*------------------------------------------------------------------* + * Calculation of LP residual (filtering through A[z] filter) + *------------------------------------------------------------------*/ + + residu( Aq, M, inp, res, L_SUBFR ); + + /*------------------------------------------------------------------* + * ACELP subframe loop + *------------------------------------------------------------------*/ + + mvr2r( res, exc, L_SUBFR ); + + if( L_frame == L_FRAME16k ) + { + weight_a( A, Ap, GAMMA16k, M ); /* Bandwidth expansion of A(z) filter coefficients */ + find_targets( inp, mem->mem_syn, 0, &mem->mem_w0, Aq, res, L_SUBFR, Ap, PREEMPH_FAC_16k, xn, cn, h1 ); + } + else + { + weight_a( A, Ap, GAMMA1, M ); /* Bandwidth expansion of A(z) filter coefficients */ + find_targets( inp, mem->mem_syn, 0, &mem->mem_w0, Aq, res, L_SUBFR, Ap, PREEMPH_FAC, xn, cn, h1 ); + } + + + /*----------------------------------------------------------------* + * Close-loop pitch search and quantization + * Adaptive exc. construction + *----------------------------------------------------------------*/ + + pitch = pit_encode( st, core_bitrate, 0, L_frame, coder_type, &pitch_limit_flag, + 0, exc, L_SUBFR, T_op, &T0_min, &T0_max, &T0, &T0_frac, h1, xn ); + + /*-----------------------------------------------------------------* + * Find adaptive exitation + *-----------------------------------------------------------------*/ + + pred_lt4( exc, exc, T0, T0_frac, L_SUBFR+1, inter4_2, L_INTERPOL2, PIT_UP_SAMP ); + + /*-----------------------------------------------------------------* + * Gain clipping test to avoid unstable synthesis on frame erasure + * or in case of floating point encoder & fixed p. decoder + *-----------------------------------------------------------------*/ + + clip_gain = gp_clip( core_bitrate, voicing, 0, coder_type, xn, st->clip_var ); + + /*-----------------------------------------------------------------* + * LP filtering of the adaptive excitation, codebook target computation + *-----------------------------------------------------------------*/ + + lp_select = lp_filt_exc_enc( MODE1, core_bitrate, 0, coder_type, 0, exc, h1,xn, y1, xn2, L_SUBFR, + L_frame, g_corr, clip_gain, &gain_pit, &lp_flag ); + + if( lp_flag == NORMAL_OPERATION ) + { + push_indice( st, IND_LP_FILT_SELECT, lp_select, 1 ); + } + + /*-----------------------------------------------------------------* + * Innovation encoding + *-----------------------------------------------------------------*/ + + inov_encode( st, core_bitrate, 0, L_frame, L_frame, coder_type, st->bwidth, 0, 0, -1, Aq, gain_pit, cn, exc, + h1, mem->tilt_code, pitch, xn2, code, y2, &unbits ); + + /*-----------------------------------------------------------------* + * Gain encoding + *-----------------------------------------------------------------*/ + + if (L_frame == L_FRAME) + { + gain_enc_mless( st, core_bitrate, L_frame, TRANSITION, 0, -1, xn, y1, y2, code, st->old_Es_pred, + &gain_pit, &gain_code, &gain_inov, &norm_gain_code, g_corr, clip_gain ); + } + else + { + gain_enc_mless( st, core_bitrate, L_frame, coder_type, 0, -1, xn, y1, y2, code, st->old_Es_pred, + &gain_pit, &gain_code, &gain_inov, &norm_gain_code, g_corr, clip_gain ); + } + + gp_clip_test_gain_pit( core_bitrate, gain_pit, st->clip_var); + mem->tilt_code = est_tilt( exc, gain_pit, code, gain_code, &voice_fac, L_SUBFR, 0 ); + + /*-----------------------------------------------------------------* + * Construct adaptive part of the excitation + *-----------------------------------------------------------------*/ + + for( i = 0; i < L_SUBFR; i++ ) + { + tmpF = gain_pit * exc[i]; + exc[i] = tmpF + gain_code * code[i]; + } + + /* write reserved bits */ + if( unbits ) + { + push_indice( st, IND_UNUSED, 0, unbits ); + } + + /*-----------------------------------------------------------------* + * long term prediction on the 2nd sub frame + *-----------------------------------------------------------------*/ + + pred_lt4( &exc[L_SUBFR], &exc[L_SUBFR], T0, T0_frac, L_SUBFR+1, inter4_2, L_INTERPOL2,PIT_UP_SAMP ); + + for( i = 0; i < L_SUBFR; i++ ) + { + exc[i+L_SUBFR] *= gain_pit; + } + + return; +} + + +/*-------------------------------------------------------------------* + * bwe_switch_enc() + * + * Encode BWE in ACELP->HQ switching frame + *-------------------------------------------------------------------*/ + +static void bwe_switch_enc( + Encoder_State *st, /* i/o: encoder state structure */ + const float *new_speech /* i : original input signal */ +) +{ + short i, k, delta, Loverlapp, d1, d1m, maxd1, ind1, fdelay, gapsize; + float accA, accB, min_sq_cross, min_corr, E1, E2, gain; + float tmp_mem[2*L_FILT48k], tmp_mem2[2*L_FILT48k], hb_synth_tmp[NS2SA(48000, 10000000L)]; + const float *hp_filter; + float synth_subfr_bwe[SWITCH_MAX_GAP]; /* synthesized bwe for core switching */ + short n, L, input_frame; + + input_frame = st->input_Fs/50; + + L = NS2SA(st->input_Fs,FRAME_SIZE_NS); + n = ((float)L * N_ZERO_MDCT_NS/FRAME_SIZE_NS); + + /* set multiplication factor according to the sampling rate */ + hp_filter = hp16000_48000; + fdelay = 48; + if( st->input_Fs == 16000 ) + { + delta = 1; + if( st->last_L_frame == L_FRAME ) + { + hp_filter = hp12800_16000; + fdelay = 20; + } + } + else if( st->input_Fs == 32000 ) + { + delta = 2; + if( st->last_L_frame == L_FRAME ) + { + hp_filter = hp12800_32000; + fdelay = 40; + } + else + { + hp_filter = hp16000_32000; + fdelay = 32; + } + } + else + { + delta = 3; + if( st->last_L_frame == L_FRAME ) + { + hp_filter = hp12800_48000; + fdelay = 60; + } + } + + set_f( tmp_mem, 0, 2*L_FILT48k ); + set_f( tmp_mem2, 0, 2*L_FILT48k ); + + Loverlapp = delta*SWITCH_OVERLAP_8k*2; + gapsize = delta * (NS2SA(16000,SWITCH_GAP_LENGTH_NS)); + set_f( synth_subfr_bwe, 0, SWITCH_MAX_GAP ); + + for( i=0; i>1, fdelay, 1 ); + + + min_sq_cross = -1; + min_corr = 0; + d1m = 0; + + maxd1 = (short)(((input_frame>>1) - gapsize-fdelay)/delta); + + /* find delay */ + for( k = 0, d1 = 0; k < maxd1; d1 += delta, k++ ) + { + accA = accB = 0; + for( i = 0; i < gapsize; i += delta ) + { + accA += hb_synth_tmp[d1+i+fdelay] * hb_synth_tmp[d1+i+fdelay]; + accB += hb_synth_tmp[d1+i+fdelay] * synth_subfr_bwe[i]; + } + if( accB * accB * min_corr >= min_sq_cross *accA ) + { + d1m = k; + min_corr = accA; + min_sq_cross = accB * accB; + } + } + + push_indice( st, IND_CORE_SWITCHING_AUDIO_DELAY, d1m, AUDIODELAYBITS ); + + /* find gain */ + E1 = 0.0f; + E2 = 1.0f; /* to avoid /0 */ + + for( i=0; i -#include "options.h" -#include "rom_com_fx.h" -#include "prot_fx.h" -#include "stl.h" /* required for wmc_tool */ - -/*---------------------------------------------------------------------* - * Local functions - *---------------------------------------------------------------------*/ - -static void encod_gen_voic_core_switch_fx( Encoder_State_fx *st_fx, - LPD_state *mem, - const Word16 L_frame_fx, const Word16 inp_fx[], - const Word16 Aq_fx[], const Word16 A_fx[], const Word16 coder_type_fx, const Word16 T_op_fx[], - const Word16 voicing_fx[], Word16 *exc_fx, const Word32 core_bitrate_fx, Word16 shift, Word16 Q_new ); - -static void bwe_switch_enc_fx( Encoder_State_fx *st_fx, const Word16 *new_speech ); - -static Word16 dotprod_satcont(const Word16 *x, const Word16 *y, Word16 qx, Word16 qy, Word16 *qo, Word16 len, Word16 delta); - -/*-------------------------------------------------------------------* - * acelp_core_switch_enc_fx() - * - * ACELP core encoder in the ACELP->HQ switching frame - *--------------------------------------------------------------------*/ - -void acelp_core_switch_enc_fx( - Encoder_State_fx *st_fx, /* i/o: encoder state structure */ - LPD_state *mem, - const Word16 inp12k8[], /* i : input signal @12.8 kHz Q0 */ - const Word16 inp16k[], /* i : input signal @16 kHz Q0 */ - const Word16 T_op_orig[2], /* i : open-loop pitch values for quantiz. Q0 */ - const Word16 voicing[3], /* i : Open-loop pitch gains Q15 */ - const Word16 A[NB_SUBFR16k*(M+1)], /* i : A(z) unquantized for the 4 subframes Q12*/ - Word16 shift, - Word16 Q_new -) -{ - Word16 i, T_op[2]; - Word16 old_exc[L_EXC], *exc; /* excitation signal buffer Qexc */ - const Word16 *inp; - Word32 cbrate; - Word16 Aq[2*(M+1)]; - - /* initializations */ - exc = &old_exc[L_EXC_MEM]; - move16(); /* pointer to excitation signal in the current frame */ - Copy( mem->old_exc, old_exc, L_EXC_MEM ); /*now old_exc has the same scaling as st_fx->old_exc; need to change later? */ - - Copy( st_fx->old_Aq_12_8_fx, Aq, M+1 ); - Copy( st_fx->old_Aq_12_8_fx, Aq + (M+1), M+1 ); - - T_op[0] = T_op_orig[0]; - move16(); - T_op[1] = T_op_orig[1]; - move16(); - - /*----------------------------------------------------------------* - * set switching frame bit-rate - *----------------------------------------------------------------*/ - - IF( sub(st_fx->last_L_frame_fx, L_FRAME) == 0 ) /* ACELP@12k8 core */ - { - inp = inp12k8; - - IF( L_sub(st_fx->core_brate_fx, ACELP_24k40 ) > 0 ) - { - cbrate = L_add(ACELP_24k40, 0); - } - ELSE - { - cbrate = L_add(st_fx->core_brate_fx, 0); - } - } - ELSE /* ACELP@16k core */ - { - inp = inp16k; - - IF( L_sub(st_fx->core_brate_fx, ACELP_8k00) <= 0 ) - { - cbrate = L_add(ACELP_8k00, 0); - } - ELSE IF (L_sub(st_fx->core_brate_fx, ACELP_14k80) <= 0 ) - { - cbrate = L_add(ACELP_14k80, 0); - } - ELSE - { - cbrate = L_min( st_fx->core_brate_fx, ACELP_22k60 ); - } - } - - IF( sub(st_fx->last_L_frame_fx, st_fx->L_frame_fx) != 0 ) - { - IF( sub(st_fx->last_L_frame_fx, L_FRAME) == 0 ) - { - T_op[0] = shr(add(round_fx(L_shl(L_mult(26214, T_op[0]), 1)), 1), 1); - move16(); - T_op[1] = shr(add(round_fx(L_shl(L_mult(26214, T_op[1]), 1)), 1), 1); - move16(); - } - ELSE - { - T_op[0] = shr(add(round_fx(L_shl(L_mult(20480, T_op[0]), 2)), 1), 1); - move16(); - T_op[1] = shr(add(round_fx(L_shl(L_mult(20480, T_op[1]), 2)), 1), 1); - move16(); - } - - } - - /*----------------------------------------------------------------* - * Excitation encoding - *----------------------------------------------------------------*/ - - encod_gen_voic_core_switch_fx( st_fx, mem, st_fx->last_L_frame_fx, inp, Aq, A, GENERIC, T_op, voicing, exc, cbrate, shift, Q_new ); - - /*----------------------------------------------------------------* - * bit-stream: modify the layer of sub frame CELP - *----------------------------------------------------------------*/ - - FOR( i=0; i<20; i++ ) - { - st_fx->ind_list_fx[IND_CORE_SWITCHING_CELP_SUBFRAME+i].value=st_fx->ind_list_fx[TAG_ACELP_SUBFR_LOOP_START+i].value; - move16(); - st_fx->ind_list_fx[IND_CORE_SWITCHING_CELP_SUBFRAME+i].nb_bits=st_fx->ind_list_fx[TAG_ACELP_SUBFR_LOOP_START+i].nb_bits; - move16(); - st_fx->ind_list_fx[TAG_ACELP_SUBFR_LOOP_START+i].nb_bits=-1; - move16(); - } - - /*----------------------------------------------------------------* - * BWE encoding - *----------------------------------------------------------------*/ - - test(); - test(); - IF( !( ( sub(st_fx->last_L_frame_fx, L_FRAME16k) == 0 && sub(inner_frame_tbl[st_fx->bwidth_fx], L_FRAME16k) == 0 ) || sub(inner_frame_tbl[st_fx->bwidth_fx], L_FRAME8k) == 0 ) ) - { - bwe_switch_enc_fx( st_fx, (const Word16 *)st_fx->old_input_signal_fx ); - } - - return; -} - -/*-------------------------------------------------------------------* - * encod_gen_voic_core_switch() - * - * Encode excitation signal in ACELP->HQ switching frame - *-------------------------------------------------------------------*/ - -static void encod_gen_voic_core_switch_fx( - Encoder_State_fx *st_fx, /* i/o: state structure */ - LPD_state *mem, - const Word16 L_frame, /* i : length of the frame */ - const Word16 inp[], /* i : input signal */ - const Word16 Aq[], /* i : LP coefficients */ - const Word16 A[], /* i : unquantized A(z) filter */ - const Word16 coder_type, /* i : coding type */ - const Word16 T_op[], /* i : open loop pitch */ - const Word16 voicing[], /* i : voicing */ - Word16 *exc, /* i/o: current non-enhanced excitation */ - const Word32 core_bitrate, /* i : switching frame bit-rate */ - Word16 shift, - Word16 Q_new -) -{ - Word16 res[L_SUBFR]; /* residual signal Qexc */ - Word16 Ap[M+1]; /* A(z) with spectral expansion Q12 */ - Word16 xn[L_SUBFR]; /* Target vector for pitch search */ - Word16 xn2[L_SUBFR]; /* Target vector for codebook search */ - Word16 cn[L_SUBFR]; /* Target vector in residual domain */ - Word16 h1[L_SUBFR+(M+1)]; /* Impulse response vector */ - - Word16 code[L_SUBFR]; /* Fixed codebook excitation Q9 */ - Word16 y1[L_SUBFR]; /* Filtered adaptive excitation */ - Word16 y2[L_SUBFR]; /* Filtered algebraic excitation */ - Word16 gain_pit ; /* Pitch gain Q15 */ - Word16 voice_fac; /* Voicing factor Q15 */ - Word32 gain_code; /* Gain of code Q16 */ - Word16 gain_inov; /* inovation gain */ - Word16 i,gcode16; /* tmp variables */ - Word16 T0, T0_frac; /* close loop integer pitch and fractional part */ - Word16 T0_min, T0_max; /* pitch variables */ - - Word16 pitch,tmp16; /* floating pitch value */ - Word16 g_corr[6]; /* ACELP correl, values + gain pitch */ - Word16 clip_gain; /* ISF clip gain */ - - Word16 unbits; /* number of unused bits for PI */ - Word32 norm_gain_code; - Word16 pitch_limit_flag; - Word32 L_tmp, Lgcode; - Word16 shift_wsp; - Word16 h2[L_SUBFR+(M+1)]; - Word16 lp_select, lp_flag; - - /*------------------------------------------------------------------* - * Initializations - *------------------------------------------------------------------*/ - - shift_wsp = add(Q_new,shift); - - unbits = 0; - move16(); - - IF( sub(L_frame, L_FRAME) == 0 ) - { - T0_max = PIT_MAX; - move16(); - T0_min = PIT_MIN; - move16(); - } - ELSE /* L_frame == L_FRAME16k */ - { - T0_max = PIT16k_MAX; - move16(); - T0_min = PIT16k_MIN; - move16(); - } - - /*------------------------------------------------------------------* - * Calculation of LP residual (filtering through A[z] filter) - *------------------------------------------------------------------*/ - - tmp16=st_fx->L_frame_fx; - move16(); - st_fx->L_frame_fx=L_SUBFR; - move16(); - calc_residu_fx(st_fx,inp,res,Aq,0); - st_fx->L_frame_fx=tmp16; - move16(); - - /*------------------------------------------------------------------* - * ACELP subframe loop - *------------------------------------------------------------------*/ - - - Copy( res, exc, L_SUBFR ); - - IF( sub(L_frame,L_FRAME16k)==0 ) - { - weight_a_fx( A, Ap, GAMMA16k, M ); /* Bandwidth expansion of A(z) filter coefficients */ - find_targets_fx(inp, mem->mem_syn, 0, &mem->mem_w0, Aq, res, L_SUBFR, Ap, PREEMPH_FAC_16k, xn, cn, h1); - } - ELSE - { - weight_a_fx( A, Ap, GAMMA1, M ); /* Bandwidth expansion of A(z) filter coefficients */ - find_targets_fx(inp, mem->mem_syn,0,&mem->mem_w0, Aq, res, L_SUBFR, Ap, TILT_FAC_FX, xn, cn ,h1); - } - - /*Scale_sig(h1, L_SUBFR, shift); *//*Q14-shift */ - Copy_Scale_sig(h1, h2, L_SUBFR, -2); - Scale_sig(h1, L_SUBFR, add(1, shift)); /* set h1[] in Q14 with scaling for convolution */ - - /* scaling of xn[] to limit dynamic at 12 bits */ - Scale_sig(xn, L_SUBFR, shift); - - /*----------------------------------------------------------------* - * Close-loop pitch search and quantization - * Adaptive exc. construction - *----------------------------------------------------------------*/ - - pitch = pit_encode_fx( st_fx, core_bitrate, 0, L_frame, coder_type, &pitch_limit_flag, - 0, exc, L_SUBFR, T_op, &T0_min, &T0_max, &T0, &T0_frac, h1, xn ); - - /*-----------------------------------------------------------------* - * Find adaptive exitation - *-----------------------------------------------------------------*/ - - pred_lt4( &exc[0], &exc[0], T0, T0_frac, L_SUBFR+1, pitch_inter4_2, L_INTERPOL2, PIT_UP_SAMP ); - - /*-----------------------------------------------------------------* - * Gain clipping test to avoid unstable synthesis on frame erasure - * or in case of floating point encoder & fixed p. decoder - *-----------------------------------------------------------------*/ - - clip_gain = gp_clip_fx( core_bitrate, voicing, 0, coder_type, xn, st_fx->clip_var_fx, sub(shift_wsp, 1) ); - - /*-----------------------------------------------------------------* - * LP filtering of the adaptive excitation, codebook target computation - *-----------------------------------------------------------------*/ - - lp_select = lp_filt_exc_enc_fx( MODE1, core_bitrate, 0, coder_type, 0, exc, h1, xn, y1, xn2, L_SUBFR, L_frame, g_corr, clip_gain, &gain_pit, &lp_flag ); - - IF( sub(lp_flag,NORMAL_OPERATION) == 0 ) - { - push_indice_fx( st_fx, IND_LP_FILT_SELECT, lp_select, 1 ); - } - - /*-----------------------------------------------------------------* - * Innovation encoding - *-----------------------------------------------------------------*/ - - inov_encode_fx( st_fx, core_bitrate, 0, L_frame,st_fx->last_L_frame_fx, coder_type, st_fx->bwidth_fx, 0, 0, -1, Aq, gain_pit, cn, exc, - h2, mem->tilt_code, pitch, xn2, code, y2, &unbits,shift); - - /*-----------------------------------------------------------------* - * Gain encoding - *-----------------------------------------------------------------*/ - IF( sub(L_frame,L_FRAME) == 0 ) - { - gain_enc_mless_fx( st_fx,core_bitrate, L_frame, TRANSITION, 0, -1, xn, y1, shift_wsp, y2, code, st_fx->old_Es_pred_fx, - &gain_pit, &gain_code, &gain_inov, &norm_gain_code, g_corr, clip_gain ); - } - ELSE - { - gain_enc_mless_fx( st_fx,core_bitrate, L_frame, coder_type, 0, -1, xn, y1, shift_wsp, y2, code, st_fx->old_Es_pred_fx, - &gain_pit, &gain_code, &gain_inov, &norm_gain_code, g_corr, clip_gain ); - } - - gp_clip_test_gain_pit_fx( core_bitrate, gain_pit, st_fx->clip_var_fx ); - - Lgcode = L_shl(gain_code, Q_new); /* scaled gain_code with Qnew -> Q16*/ - gcode16 = round_fx(Lgcode); - - mem->tilt_code = Est_tilt2( exc+0, gain_pit, code, gain_code, &voice_fac,shift ); - - /*-----------------------------------------------------------------* - * Construct adaptive part of the excitation - *-----------------------------------------------------------------*/ - - FOR( i = 0; i < L_SUBFR; i++ ) - { - /* code in Q9, gain_pit in Q14 */ - L_tmp = L_mult(gcode16, code[i]); - L_tmp = L_shl(L_tmp, 5); - L_tmp = L_mac(L_tmp, exc[i ], gain_pit); - L_tmp = L_shl(L_tmp, 1); /* saturation can occur here */ - exc[i ] = round_fx(L_tmp); - } - - /* write reserved bits */ - IF( unbits ) - { - push_indice_fx(st_fx, IND_UNUSED, 0, unbits ); - } - - /*-----------------------------------------------------------------* - * long term prediction on the 2nd sub frame - *-----------------------------------------------------------------*/ - - pred_lt4(&exc[L_SUBFR], &exc[L_SUBFR], T0, T0_frac, L_SUBFR+1, pitch_inter4_2, L_INTERPOL2, PIT_UP_SAMP); - - FOR( i = L_SUBFR; i < 2*L_SUBFR; i++ ) - { - exc[i] = round_fx(L_shl(L_mult(exc[i], gain_pit), 1)); - } - - return; -} - - -/*-------------------------------------------------------------------* - * bwe_switch_enc() - * - * Encode BWE in ACELP->HQ switching frame - *-------------------------------------------------------------------*/ - -static void bwe_switch_enc_fx( - Encoder_State_fx *st_fx, /* i/o: encoder state structure */ - const Word16 *new_speech_fx /* i : original input signal Q0 */ -) -{ - - Word16 k, Loverlapp_fx, d1m_fx, maxd1_fx, ind1_fx, gapsize_fx; - Word16 delta_fx, fdelay_fx; - const Word16 *hp_filter_fx; - const Word16 *fpointers_tab[6] = {hp12800_16000_fx, hp12800_32000_fx, hp12800_48000_fx, hp16000_48000_fx, hp16000_32000_fx, hp16000_48000_fx}; - Word16 tmp, shift; - const Word16 *ptmp; - Word16 tmp_mem_fx[2*L_FILT48k], tmp_mem2_fx[2*L_FILT48k], hb_synth_tmp_fx[480]; - Word16 Fs_kHz; - Word16 q_tmp1, q_tmp2, Qmc, Qsq; - Word32 L_tmp1, L_tmp2, L_tmp3, min_sq_cross_fx; - Word16 accA_fx, accB_fx, min_corr_fx, E1_fx, E2_fx, gain_fx; - Word16 synth_subfr_bwe_fx[SWITCH_MAX_GAP]; /* synthesized bwe for core switching */ - - Word16 n, L; - L = NS2SA_fx2(st_fx->input_Fs_fx,FRAME_SIZE_NS); - - /* set multiplication factor according to the sampling rate */ - tmp = extract_l(L_shr(st_fx->input_Fs_fx,14)); - delta_fx = add(tmp,1); - Fs_kHz = shl(delta_fx,4); - tmp = add(tmp,i_mult2(3,(sub(st_fx->last_L_frame_fx,L_FRAME)!=0))); - ptmp = fpointers_tab[tmp]; - move16(); - - hp_filter_fx = ptmp; - fdelay_fx=i_mult2(16,delta_fx); - IF(sub(st_fx->last_L_frame_fx,L_FRAME)==0) - { - fdelay_fx=i_mult2(20,delta_fx); - } - - n = i_mult2(N16_CORE_SW,delta_fx); - - set16_fx( tmp_mem_fx, 0, 2*L_FILT48k); - set16_fx( tmp_mem2_fx, 0, 2*L_FILT48k); - - Loverlapp_fx = i_mult2(delta_fx,SWITCH_OVERLAP_8k*2); - gapsize_fx = i_mult2(delta_fx,NS2SA(16000,SWITCH_GAP_LENGTH_NS)); - - shift = sub(add(add(shr(L,1),n),Loverlapp_fx),gapsize_fx) ; - Copy( new_speech_fx+shift,synth_subfr_bwe_fx,add(gapsize_fx,fdelay_fx) ); - Copy( new_speech_fx+sub(shift,fdelay_fx),tmp_mem_fx,fdelay_fx ); - - tmp = add(gapsize_fx, fdelay_fx); - fir_fx( synth_subfr_bwe_fx, hp_filter_fx, synth_subfr_bwe_fx, tmp_mem_fx, tmp, fdelay_fx, 1, 0 ); - Copy(synth_subfr_bwe_fx+shr(fdelay_fx,1),synth_subfr_bwe_fx,sub(gapsize_fx,shr(fdelay_fx,1)) ); - - tmp = i_mult2(Fs_kHz,10); - fir_fx( new_speech_fx, hp_filter_fx, hb_synth_tmp_fx, tmp_mem2_fx, tmp, fdelay_fx, 1, 0 ); - - min_sq_cross_fx = L_negate(1); - Qsq = 0; - move16(); - min_corr_fx = 0; - move16(); - Qmc = 0; - move16(); - d1m_fx = 0; - move16(); - - maxd1_fx = sub(tmp,add(gapsize_fx,fdelay_fx)); - - IF (sub(delta_fx, 2) == 0) - { - maxd1_fx = shr(maxd1_fx,1); - } - ELSE IF (sub(delta_fx, 3) == 0 ) - { - maxd1_fx = extract_h(L_mult(maxd1_fx, 10923)); - } - - /* find delay */ - ptmp = &hb_synth_tmp_fx[fdelay_fx]; - move16(); - FOR( k = 0; k < maxd1_fx; k++ ) - { - accA_fx = dotprod_satcont(ptmp, ptmp, 0, 0, &q_tmp1, gapsize_fx, delta_fx); - accB_fx = dotprod_satcont(ptmp, synth_subfr_bwe_fx, 0, 0, &q_tmp2, gapsize_fx, delta_fx); - ptmp += delta_fx; - L_tmp1 = L_mult0(accB_fx, accB_fx); /*2*q_tmp2; */ - L_tmp2 = Mult_32_16(L_tmp1, min_corr_fx); /*2*q_tmp2+Qmc-15 */ - L_tmp3 = Mult_32_16(min_sq_cross_fx, accA_fx); /*Qsq+q_tmp1-15 */ - shift = s_min(add(shl(q_tmp2,1),Qmc),add(q_tmp1,Qsq)); - L_tmp2 = L_shr(L_tmp2, sub(add(shl(q_tmp2,1),Qmc),shift)); - L_tmp3 = L_shr(L_tmp3, sub(add(q_tmp1,Qsq),shift)); - - IF (L_sub(L_tmp2,L_tmp3)>=0) - { - d1m_fx = k; - move16(); - min_corr_fx = accA_fx; - move16(); - Qmc = q_tmp1; - move16(); - min_sq_cross_fx = L_add(L_tmp1, 0); - Qsq = shl(q_tmp2,1); - move16(); - } - } - - push_indice_fx(st_fx, IND_CORE_SWITCHING_AUDIO_DELAY, d1m_fx, AUDIODELAYBITS ); - - tmp = add(i_mult2(d1m_fx,delta_fx),fdelay_fx); - ptmp = &hb_synth_tmp_fx[tmp]; - move16(); - E1_fx = dotprod_satcont(synth_subfr_bwe_fx, synth_subfr_bwe_fx, 0, 0, &q_tmp1, gapsize_fx, 1); - E2_fx = dotprod_satcont(ptmp, ptmp, 0, 0, &q_tmp2, gapsize_fx, 1); - - IF (!E1_fx) - { - E1_fx = shl(1,14); - q_tmp1 = 14; - move16(); - } - IF (!E2_fx) - { - E2_fx = shl(1,14); - q_tmp2 = 14; - move16(); - } - - tmp = div_s(shl(1, 14), E1_fx); /*Q(29-q_tmp1) */ - L_tmp1 = L_mult(tmp, E2_fx); /*30-q_tmp1+q_tmp2 */ - q_tmp2 = sub(q_tmp1, q_tmp2); /*30-q_tmp2 */ - L_tmp1 = L_shl(L_tmp1, sub(q_tmp2, 24)); - gain_fx = round_fx(Isqrt(L_tmp1)); /*Q12 */ - - ind1_fx = usquant_fx( gain_fx, &gain_fx, shr(MINVALUEOFFIRSTGAIN_FX,1), shr(DELTAOFFIRSTGAIN_FX,4), (1 << NOOFGAINBITS1) ); - push_indice_fx( st_fx,IND_CORE_SWITCHING_AUDIO_GAIN, ind1_fx, NOOFGAINBITS1 ); - - return; -} - -static Word16 dotprod_satcont(const Word16 *x, const Word16 *y, Word16 qx, Word16 qy, Word16 *qo, Word16 len, Word16 delta) -{ - Word16 tmp_tabx[L_FRAME48k], tmp_taby[L_FRAME48k]; - Word16 shift, q, ener, i; - Word32 L_tmp; - - Copy( x, tmp_tabx, len ); - Copy( y, tmp_taby, len ); - shift = 0; - move16(); - DO - { - L_tmp = L_deposit_l(0); - Overflow = 0; - move16(); - FOR ( i = 0; i < len; i += delta ) - { - L_tmp = L_mac0(L_tmp, tmp_tabx[i], tmp_taby[i]); /*Q(qx+qy-shift) */ - } - - IF(Overflow != 0) - { - FOR( i = 0; i < len; i += delta ) - { - tmp_tabx[i] = shr(tmp_tabx[i], 2); - move16(); - tmp_taby[i] = shr(tmp_taby[i], 2); - move16(); - } - shift = add(shift, 4); - } - } - WHILE(Overflow != 0); - - q = norm_l(L_tmp); - L_tmp = L_shl(L_tmp, q); /*Q(qx+qy-shift+q) */ - ener = extract_h(L_tmp); /*Q(qx+qy-shift+q-16) */ - q = add(q, add(qx, qy)); - *qo = sub(q, add(shift, 16)); - - return ener; -} diff --git a/src/libs/libevs/lib_enc/acelp_enc_util.cpp b/src/libs/libevs/lib_enc/acelp_enc_util.cpp old mode 100755 new mode 100644 index 20b20274..809d6b16 --- a/src/libs/libevs/lib_enc/acelp_enc_util.cpp +++ b/src/libs/libevs/lib_enc/acelp_enc_util.cpp @@ -1,278 +1,47 @@ /*==================================================================================== - EVS Codec 3GPP TS26.442 Apr 03, 2018. Version 12.11.0 / 13.6.0 / 14.2.0 + EVS Codec 3GPP TS26.443 Nov 13, 2018. Version 12.11.0 / 13.7.0 / 14.3.0 / 15.1.0 ====================================================================================*/ - +#include #include #include -#include "stl.h" -#include "prot_fx.h" -#include "basop_util.h" #include "options.h" -#include "cnst_fx.h" -#include "stl.h" -#include "rom_com_fx.h" -#include "rom_enc_fx.h" +#include "typedef.h" +#include "prot.h" +#include "cnst.h" +#include "rom_com.h" -#define _1_Q9 0x200 +/*-------------------------------------------------------------------* +* E_ACELP_toeplitz_mul() +* +* Multiplication of Toeplitz matrix with vector c, such that d = toeplitz(R)*c +*-------------------------------------------------------------------*/ - -/* - * E_ACELP_toeplitz_mul - * - * Parameters: - * R I: coefficients of Toeplitz matrix (Q9) - * c I: input vector Q_xn - * d O: output vector, exponent = j - * - * Function: - * Multiplication of Toeplitz matrix with vector c, such that - * d = toeplitz(R)*c - * Vector length is L_SUBFR -*/ -Word16 E_ACELP_toeplitz_mul(const Word16 R[], const Word16 c[], Word16 d[], const Word16 L_subfr, const Word16 highrate) -{ - static const Word16 step = 4; - Word16 k, j, i; - Word32 s; - Word32 y32[L_SUBFR16k], L_maxloc, L_tot; - - - assert(L_subfr <= L_SUBFR16k); - - - /* first keep the result on 32 bits and find absolute maximum */ - L_tot = L_deposit_l(1); - - FOR (k = 0; k < step; k++) - { - L_maxloc = L_deposit_l(0); - FOR (i = k; i < L_subfr; i += step) - { - s = L_mult(R[i], c[0]); - FOR (j = 1; j < i; j++) - { - s = L_mac(s, R[i-j], c[j]); - } - FOR (; j 16 x tot */ - - Copy_Scale_sig_32_16(y32, d, L_subfr, j); - - return j; -} - -void E_ACELP_weighted_code( - const Word16 code[], /* i: code */ - const Word16 H[], /* i: impulse response */ - Word16 Q, /* i: Q format of H */ - Word16 y[] /* o: weighted code */ +void E_ACELP_toeplitz_mul( + float R[], + float c[], + float d[] ) { - Word16 i, j, k, one, n, nz[L_SUBFR]; - Word32 L_tmp; + short k, j; + float s; - /* Collect nonzeros */ - n = 0; - move16(); - FOR (i=0; i 0); - one = shl(1, Q); - Q = sub(15, Q); - - /* Generate weighted code */ - j = nz[0]; - move16(); - set16_fx(y, 0, j); - FOR (k=0; knb_pulse+(k*4) <= 40); - - copyWord8((const Word8*)E_ROM_tipos+(k * 4), (Word8*)ipos, config->nb_pulse); - - /* if all tracks do not have equal number of pulses */ - restpulses = s_and(config->nb_pulse, 3); - - IF (restpulses) - { - SWITCH (config->codetrackpos) - { - case TRACKPOS_FIXED_FIRST: /* fixed track positions, starting from left */ - /* add tracks from left */ - FOR (iPulse=0; iPulsenb_pulse-restpulses+iPulse] = (UWord8)iPulse; - move16(); - } - /* Put the same track on the next position, because the 1-pulse search - * will access it to determine if this could be in any track. */ - ipos[config->nb_pulse] = ipos[config->nb_pulse-1]; - move16(); - BREAK; - case TRACKPOS_FIXED_EVEN: /* fixed track positions, odd tracks */ - /* odd tracks, switch order for every iteration */ - ipos[config->nb_pulse-restpulses] = (UWord8)s_and(lshl(k,1),2); - move16();/* 0 for even k, 2 for odd */ - ipos[config->nb_pulse-restpulses+1] = (UWord8)s_xor(ipos[config->nb_pulse-restpulses], 2); - move16();/* 2 for even k, 0 for odd */ - BREAK; - case TRACKPOS_FIXED_TWO: /* two tracks instead of four */ - /* Put the next track on the next position, because the 1-pulse search - * will access it to determine if this could be in any track. */ - ipos[config->nb_pulse] = (UWord8)s_and(add(ipos[config->nb_pulse-1],1),3); - move16(); - BREAK; - default: /* one or three free track positions */ - /* copy an extra position from table - 1pulse search will access this */ - ipos[config->nb_pulse] = E_ROM_tipos[add(shl(k,2),config->nb_pulse)]; - move16(); - BREAK; - } - } -} - diff --git a/src/libs/libevs/lib_enc/amr_wb_enc.cpp b/src/libs/libevs/lib_enc/amr_wb_enc.cpp new file mode 100644 index 00000000..06354c90 --- /dev/null +++ b/src/libs/libevs/lib_enc/amr_wb_enc.cpp @@ -0,0 +1,539 @@ +/*==================================================================================== + EVS Codec 3GPP TS26.443 Nov 13, 2018. Version 12.11.0 / 13.7.0 / 14.3.0 / 15.1.0 + ====================================================================================*/ + +#include +#include +#include "options.h" +#include "cnst.h" +#include "rom_enc.h" +#include "rom_com.h" +#include "prot.h" + +/*-------------------------------------------------------------------* + * amr_wb_enc() + * + * AMR-WB encoder + *-------------------------------------------------------------------*/ + +void amr_wb_enc( + Encoder_State *st, /* i/o: encoder state structure */ + const short *input_sp, /* i : input signal */ + const short n_samples /* i : number of input samples */ +) +{ + short i, delay, harm_flag; + float old_inp[L_INP_12k8], *new_inp, *inp; /* buffer of old input signal */ + float old_inp_16k[L_INP_12k8+L_SUBFR], *inp_16k, *new_inp_16k;/* buffer of old input signal @16kHz*/ + float old_exc[L_EXC], *exc; /* excitation signal buffer */ + float old_wsp[L_WSP], *wsp; /* weighted input signal buffer */ + short input_frame; /* frame length at input sampling freq. */ + float fr_bands[2*NB_BANDS]; /* energy in frequency bands */ + float lf_E[2*VOIC_BINS]; /* per bin spectrum energy in lf */ + float tmpN[NB_BANDS]; /* temporary noise update */ + float tmpE[NB_BANDS], PS[L_FFT/2]; /* temporary averaged energy of 2 sf. */ + float corr_shift; /* correlation shift */ + float relE; /* frame relative energy */ + float non_staX, cor_map_sum, sp_div; + short vad_flag; + short localVAD; + float Etot; /* total energy */ + float ener; /* residual energy from Levinson-Durbin */ + short pitch[3]; /* open-loop pitch values */ + float voicing[3]; /* open-loop pitch gains */ + float A[NB_SUBFR*(M+1)]; /* A(z) unquantized for the 4 subframes */ + float Aw[NB_SUBFR*(M+1)]; /* weigted A(z) unquant. for 4 subframes*/ + float epsP[M+1]; /* LP prediction errors */ + float isp_new[M]; /* ISPs at the end of the frame */ + float isf_new[M]; /* ISFs at the end of the frame */ + float isp_tmp[M]; + float Aq[NB_SUBFR*(M+1)]; /* A(z) quantized for the 4 subframes */ + float syn[L_FRAME]; /* synthesis vector */ + float res[L_FRAME]; /* residual signal for FER protection */ + float exc2[L_FRAME]; /* enhanced excitation */ + float pitch_buf[NB_SUBFR]; /* floating pitch for each subframe */ + float dummy_buf[L_FRAME32k]; /* dummy buffer - no usage */ + float snr_sum_he; + short allow_cn_step; + short localVAD_HE_SAD; + short tmps; + short vad_flag_dtx; + short vad_hover_flag; + short coder_type; + short hf_gain[NB_SUBFR]; + short high_lpn_flag; + float lp_bckr, hp_bckr; + float q_env[NUM_ENV_CNG]; + short sid_bw = 0; + float exc3[L_FRAME]; + float fft_buff[2*L_FFT]; + float sp_floor; + float tmp; + + + /*------------------------------------------------------------------* + * Initialization + *------------------------------------------------------------------*/ + + st->L_frame = L_FRAME; + st->gamma = GAMMA1; + st->core = AMR_WB_CORE; + st->core_brate = st->total_brate; + st->input_bwidth = st->last_input_bwidth; + st->bwidth = st->last_bwidth; + st->extl = -1; + coder_type = GENERIC; + input_frame = (short)(st->input_Fs / 50); /* frame length of the input signal */ + st->encoderPastSamples_enc = (L_FRAME*9)/16; + st->encoderLookahead_enc = L_LOOK_12k8; + + st->bpf_off = 0; + if( st->last_core == HQ_CORE || st->last_codec_mode == MODE2 ) + { + st->bpf_off = 1; + } + + st->igf = 0; + + /* Updates in case of EVS primary mode -> AMR-WB IO mode switching */ + if( st->last_core != AMR_WB_CORE ) + { + updt_IO_switch_enc( st, input_frame ); + } + + /* Updates in case of HQ -> AMR-WB IO switching */ + core_switching_pre_enc( st, &(st->LPDmem), NULL, NULL ); + + set_s( hf_gain, 0, NB_SUBFR ); + + set_f( old_inp, 0.0f, L_INP_12k8 ); + exc = old_exc + L_EXC_MEM; /* pointer to excitation signal in the current frame */ + mvr2r( st->LPDmem.old_exc, old_exc, L_EXC_MEM ); + + + new_inp = old_inp + L_INP_MEM; /* pointer to new samples of the input signal */ + inp = new_inp - L_LOOK_12k8; /* pointer to current frame of input signal */ + wsp = old_wsp + L_WSP_MEM; /* pointer to current frame of weighted signal */ + + mvr2r( st->old_inp_12k8, old_inp, L_INP_MEM ); + mvr2r( st->old_wsp, old_wsp, L_WSP_MEM ); + + new_inp_16k = old_inp_16k + L_INP_MEM; /* pointer to new samples of the input signal in 16kHz core */ + inp_16k = new_inp_16k - L_LOOK_16k; /* pointer to the current frame of input signal in 16kHz core */ + mvr2r( st->old_inp_16k, old_inp_16k, L_INP_MEM ); + + /* in case of switching, reset AMR-WB BWE memories */ + if( st->total_brate == ACELP_23k85 && st->last_core_brate != ACELP_23k85 ) + { + hf_cod_init( st->mem_hp400_enc, st->mem_hf_enc, st->mem_syn_hf_enc, st->mem_hf2_enc, &st->gain_alpha ); + } + + /*----------------------------------------------------------------* + * set input samples buffer + *----------------------------------------------------------------*/ + + /* get delay to synchronize ACELP and MDCT frame */ + delay = NS2SA(st->input_Fs, DELAY_FIR_RESAMPL_NS); + + mvr2r( st->input - delay, st->old_input_signal, input_frame+delay ); + + /*----------------------------------------------------------------* + * Buffering of input signal + * (convert 'short' input data to 'float') + * HP filtering + *----------------------------------------------------------------*/ + + mvs2r( input_sp, st->input, n_samples ); + + for( i = n_samples; i < input_frame; i++ ) + { + st->input[i] = 0; + } + + hp20( st->input, input_frame, st->mem_hp20_in, st->input_Fs ); + + /*-----------------------------------------------------------------* + * switching from ACELP@16k core to AMR-WB IO mode + *-----------------------------------------------------------------*/ + + st->rate_switching_reset = 0; + + if( st->last_core != AMR_WB_CORE && st->last_L_frame == L_FRAME16k && st->last_core != HQ_CORE) + { + /* in case of switching, do not apply BPF */ + st->bpf_off = 1; + /* convert old quantized LSP vector */ + st->rate_switching_reset = lsp_convert_poly( st->lsp_old, L_FRAME, 1 ); + + /* convert old quantized LSF vector */ + lsp2lsf( st->lsp_old, st->lsf_old, M, INT_FS_12k8 ); + + /* Reset LPC mem */ + mvr2r( GEWB_Ave, st->mem_AR, M ); + set_zero( st->mem_MA, M ); + + /* update synthesis filter memories */ + synth_mem_updt2( L_FRAME, st->last_L_frame, st->LPDmem.old_exc, st->LPDmem.mem_syn_r, st->mem_syn1, st->LPDmem.mem_syn, ENC ); + mvr2r( st->LPDmem.old_exc, old_exc, L_EXC_MEM ); + mvr2r( st->mem_syn1, st->LPDmem.mem_syn2, M ); + mvr2r( st->LPDmem.mem_syn2, st->LPDmem.mem_syn3, M ); + + /* lsp -> isp */ + mvr2r( stable_ISP, isp_tmp, M ); + lsp2isp( st->lsp_old, st->lsp_old, isp_tmp, M ); + + } + + /* update buffer of old subframe pitch values */ + if( st->last_L_frame != L_FRAME ) + { + if( st->last_L_frame == L_FRAME32k ) + { + tmp = (float)12800/(float)32000; + } + else if( st->last_L_frame == 512 ) + { + tmp = (float)12800/(float)25600; + } + else /* st->last_L_frame == L_FRAME16k */ + { + tmp = (float)12800/(float)16000; + } + + for( i=NB_SUBFR16k-NB_SUBFR; iold_pitch_buf[i-1] = tmp * st->old_pitch_buf[i]; + } + + for( i=2*NB_SUBFR16k-NB_SUBFR; i<2*NB_SUBFR16k; i++ ) + { + st->old_pitch_buf[i-2] = tmp * st->old_pitch_buf[i]; + } + } + if( st->last_bwidth == NB && st->ini_frame != 0 ) + { + st->rate_switching_reset = 1; + } + + /*----------------------------------------------------------------* + * Change the sampling frequency to 12.8 kHz + *----------------------------------------------------------------*/ + + modify_Fs( st->input, input_frame, st->input_Fs, new_inp, 12800, st->mem_decim, 0 ); + + /* update signal buffer */ + mvr2r( new_inp, st->buf_speech_enc+L_FRAME, L_FRAME ); + + /*------------------------------------------------------------------* + * Perform fixed preemphasis through 1 - g*z^-1 + *-----------------------------------------------------------------*/ + + preemph( new_inp, PREEMPH_FAC, L_FRAME, &st->mem_preemph); + + /*----------------------------------------------------------------* + * Compute spectrum, find energy per critical frequency band + * Track energy and signal dynamics + * Detect NB spectrum in a 16kHz-sampled input + *----------------------------------------------------------------*/ + + analy_sp( inp, st->Bin_E, st->Bin_E_old, fr_bands, lf_E, &Etot, st->min_band, st->max_band, dummy_buf, PS, fft_buff ); + + noise_est_pre( Etot, st->ini_frame, &st->Etot_l, &st->Etot_h, &st->Etot_l_lp, &st->Etot_last, &st->Etot_v_h2, &st->sign_dyn_lp, st->harm_cor_cnt, &st->Etot_lp ); + + /*----------------------------------------------------------------* + * VAD + *----------------------------------------------------------------*/ + + vad_flag = wb_vad( st, fr_bands, &localVAD, &tmps, &tmps, &tmps, &snr_sum_he, &localVAD_HE_SAD, &st->flag_noisy_speech_snr ); + + if( vad_flag == 0 ) + { + coder_type = INACTIVE; + } + + /* apply DTX hangover for CNG analysis */ + vad_flag_dtx = dtx_hangover_addition( st, localVAD, vad_flag, st->lp_speech-st->lp_noise, 0, &vad_hover_flag ); + + + /*-----------------------------------------------------------------* + * Select SID or FRAME__NO_DATA frame if DTX enabled + *-----------------------------------------------------------------*/ + + if ( st->last_core != AMR_WB_CORE ) + { + st->fd_cng_reset_flag = 1; + } + else if ( st->fd_cng_reset_flag > 0 && st->fd_cng_reset_flag < 10 ) + { + st->fd_cng_reset_flag++; + } + else + { + st->fd_cng_reset_flag = 0; + } + + dtx( st, vad_flag_dtx, inp ); + + /*----------------------------------------------------------------* + * Noise energy down-ward update and total noise energy estimation + * Long-term energies and relative frame energy updates + * Correlation correction as a function of total noise level + *----------------------------------------------------------------*/ + + noise_est_down( fr_bands, st->bckr, tmpN, tmpE, st->min_band, st->max_band, &st->totalNoise, Etot, &st->Etot_last, &st->Etot_v_h2 ); + + high_lpn_flag = 0; + long_enr( st, Etot, localVAD_HE_SAD, high_lpn_flag ); + relE = Etot - st->lp_speech; + + if( st->bwidth != NB ) + { + lp_bckr = mean( st->bckr, 10 ); + } + else + { + lp_bckr = mean( st->bckr+1, 9 ); + } + hp_bckr = 0.5f * (st->bckr[st->max_band-1] + st->bckr[st->max_band]); + st->bckr_tilt_lt = 0.9f * st->bckr_tilt_lt + 0.1f * lp_bckr / hp_bckr; + + corr_shift = correlation_shift(st->totalNoise); + + /*----------------------------------------------------------------* + * WB, SWB and FB bandwidth detector + *----------------------------------------------------------------*/ + + bw_detect( st, st->input, localVAD, NULL ); + + /* in AMR_WB IO, limit the maximum band-width to WB */ + if( st->bwidth > WB ) + { + st->bwidth = WB; + } + + /*----------------------------------------------------------------* + * Perform LP analysis + * Compute weighted inp + * Perform open-loop pitch analysis + * Perform 1/4 pitch precision improvement + *----------------------------------------------------------------*/ + + if ( vad_flag == 0 ) + { + /* reset the OL pitch tracker memories during inactive frames */ + pitch_ol_init( &st->old_thres, &st->old_pitch, &st->delta_pit, &st->old_corr ) ; + } + + /* LP analysis */ + analy_lp_AMR_WB( inp, &ener, A, epsP, isp_new, st->lsp_old1, isf_new, st->old_pitch_la, st->old_voicing_la ); + + /* compute weighted input */ + find_wsp( L_FRAME, L_SUBFR, NB_SUBFR, A, Aw, inp, TILT_FAC, wsp, &st->mem_wsp, GAMMA1, L_LOOK_12k8 ); + + /* open-loop pitch analysis */ + pitch_ol( pitch,voicing, &st->old_pitch, &st->old_corr, corr_shift, &st->old_thres, + &st->delta_pit, st->old_wsp2, wsp, st->mem_decim2, relE, L_LOOK_12k8, 0, st->bwidth, 0 ); + + st->old_pitch_la = pitch[2]; + st->old_voicing_la = voicing[2]; + + + vad_param_updt( st, pitch, voicing, corr_shift, A ); + + /*------------------------------------------------------------------* + * Update estimated noise energy and voicing cut-off frequency + *-----------------------------------------------------------------*/ + + noise_est( st, tmpN, pitch, voicing, epsP, Etot, relE, corr_shift, tmpE, fr_bands, &cor_map_sum, + &sp_div, &non_staX, &harm_flag, lf_E, &st->harm_cor_cnt, st->Etot_l_lp, &sp_floor ); + + /*----------------------------------------------------------------* + * Change the sampling frequency to 16 kHz, + * input@16kHz needed for AMR-WB IO BWE @23.85kbps + *----------------------------------------------------------------*/ + + if ( st->input_Fs == 16000 ) + { + /* no resampling needed, only delay adjustement to account for the FIR resampling delay */ + tmps = NS2SA(16000, DELAY_FIR_RESAMPL_NS); + mvr2r( st->mem_decim16k + tmps, new_inp_16k, tmps ); + mvr2r( st->input, new_inp_16k + tmps, input_frame - tmps ); + mvr2r( st->input + input_frame - 2*tmps, st->mem_decim16k, 2*tmps ); + } + else if( st->input_Fs == 32000 || st->input_Fs == 48000 ) + { + modify_Fs( st->input, input_frame, st->input_Fs, new_inp_16k, 16000, st->mem_decim16k, 0 ); + } + + /*----------------------------------------------------------------* + * Encoding of SID frames + *----------------------------------------------------------------*/ + + if ( st->core_brate == SID_1k75 || st->core_brate == FRAME__NO_DATA ) + { + /* encode CNG parameters */ + CNG_enc( st, L_FRAME, Aq, inp, ener, isp_new, isf_new , &allow_cn_step, st->burst_ho_cnt, q_env, &sid_bw, st->exc_mem2 ); + + /* comfort noise generation */ + CNG_exc( st->core_brate, L_FRAME, &st->Enew, &st->cng_seed, exc, exc2, &st->lp_ener, + st->last_core_brate, &st->first_CNG, &st->cng_ener_seed, dummy_buf, allow_cn_step, &st->last_allow_cn_step, st->num_ho, + q_env, st->lp_env, st->old_env, st->exc_mem, st->exc_mem1, &sid_bw, &st->cng_ener_seed1, exc3, st->Opt_AMR_WB ); + + if ( st->first_CNG == 0 ) + { + st->first_CNG = 1; + } + /* synthesis */ + syn_12k8( L_FRAME, Aq, exc2, dummy_buf, st->LPDmem.mem_syn3, 1 ); /* dummy_buf = temporary buffer to handle syn1[] */ + + /* reset the encoder */ + CNG_reset_enc( st, &(st->LPDmem), pitch_buf, dummy_buf+L_FRAME, 0 ); + + /* update st->mem_syn1 for ACELP core switching */ + mvr2r( st->LPDmem.mem_syn3, st->mem_syn1, M ); + + /* update ACELP core synthesis filter memory */ + mvr2r( st->LPDmem.mem_syn3, st->LPDmem.mem_syn, M ); + + /* update old synthesis buffer - needed for ACELP internal sampling rate switching */ + mvr2r( dummy_buf + L_FRAME - L_SYN_MEM, st->LPDmem.mem_syn_r, L_SYN_MEM ); + + /* Update MODE2 core switching memory */ + deemph( dummy_buf, PREEMPH_FAC, L_FRAME, &(st->LPDmem.syn[M]) ); + mvr2r( dummy_buf+L_FRAME-M-1, st->LPDmem.syn, M+1 ); + } + + /*----------------------------------------------------------------* + * Encoding of all other frames + *----------------------------------------------------------------*/ + + else + { + /*-----------------------------------------------------------------* + * After inactive period, use the most up-to-date ISPs + *-----------------------------------------------------------------*/ + + if( st->last_core_brate == FRAME__NO_DATA || st->last_core_brate == SID_1k75 ) + { + mvr2r( st->lspCNG, st->lsp_old, M ); + isp2isf( st->lspCNG, st->lsf_old, M, INT_FS_12k8 ); + set_f( old_exc, 0, L_EXC_MEM ); + } + + /*-----------------------------------------------------------------* + * ISF Quantization and interpolation + *-----------------------------------------------------------------*/ + + isf_enc_amr_wb( st, isf_new, isp_new, Aq, &st->stab_fac ); + + /*---------------------------------------------------------------* + * Calculation of LP residual (filtering through A[z] filter) + *---------------------------------------------------------------*/ + + calc_residu( inp, res, Aq, L_FRAME ); + st->burst_ho_cnt = 0; + + /*------------------------------------------------------------* + * Encode excitation + *------------------------------------------------------------*/ + + encod_amr_wb( st, &(st->LPDmem), inp, Aw, Aq, pitch, voicing, res, syn, exc, exc2, pitch_buf, hf_gain, inp_16k ); + + + /* update st->mem_syn1 for ACELP core switching */ + mvr2r( st->LPDmem.mem_syn, st->mem_syn1, M ); + + /* update old synthesis buffer - needed for ACELP internal sampling rate switching */ + mvr2r( syn + L_FRAME - L_SYN_MEM, st->LPDmem.mem_syn_r, L_SYN_MEM ); + + /* Update MODE2 core switching memory */ + mvr2r( syn, dummy_buf, L_FRAME ); + deemph( dummy_buf, PREEMPH_FAC, L_FRAME, &(st->LPDmem.syn[M]) ); + mvr2r( dummy_buf+L_FRAME-M-1, st->LPDmem.syn, M+1 ); + + /*--------------------------------------------------------------------------------------* + * Write VAD information into the bitstream in AMR-WB IO mode + *--------------------------------------------------------------------------------------*/ + + push_indice( st, IND_VAD_FLAG, vad_flag, 1 ); + + } + + + /*-----------------------------------------------------------------* + * Updates + *-----------------------------------------------------------------*/ + + /* update old weighted speech buffer - for OL pitch analysis */ + mvr2r( &old_wsp[L_FRAME], st->old_wsp, L_WSP_MEM ); + + /* update old input signal buffer */ + mvr2r( &old_inp[L_FRAME], st->old_inp_12k8, L_INP_MEM ); + + /* update old input signal @16kHz buffer */ + if( st->input_Fs > 8000 ) + { + mvr2r( &old_inp_16k[L_FRAME16k], st->old_inp_16k, L_INP_MEM ); + } + + /* update of old per-band energy spectrum */ + mvr2r( fr_bands + NB_BANDS, st->enrO, NB_BANDS ); + + /* update the last bandwidth */ + st->last_input_bwidth = st->input_bwidth; + st->last_bwidth = st->bwidth; + + /* update signal buffers */ + mvr2r( new_inp, st->buf_speech_enc_pe+L_FRAME, L_FRAME ); + mvr2r( wsp, st->buf_wspeech_enc+L_FRAME+L_SUBFR, L_FRAME + L_LOOK_12k8 ); + + updt_enc( st, L_FRAME, coder_type, old_exc, pitch_buf, 0, Aq, isf_new, isp_new, dummy_buf ); + + core_encode_update( st ); + + /* update main codec parameters */ + st->last_extl = -1; + st->last_core = st->core; + st->last_L_frame = L_FRAME; + st->last_core_brate = st->core_brate; + st->last_total_brate = st->total_brate; + st->Etot_last = Etot; + st->last_coder_type_raw = st->coder_type_raw; + st->last_codec_mode = st->codec_mode; + + /* Increase the counter of initialization frames */ + if( st->ini_frame < MAX_FRAME_COUNTER ) + { + (st->ini_frame)++; + } + + if( st->core_brate > SID_1k75 ) + { + st->last_active_brate = st->total_brate; + } + + if ( st->core_brate > SID_1k75 && st->first_CNG ) + { + if( st->act_cnt >= BUF_DEC_RATE ) + { + st->act_cnt = 0; + } + + st->act_cnt++; + + if( st->act_cnt == BUF_DEC_RATE && st->ho_hist_size > 0 ) + { + st->ho_hist_size--; + } + + if( ++(st->act_cnt2) >= MIN_ACT_CNG_UPD ) + { + st->act_cnt2 = MIN_ACT_CNG_UPD; + } + } + + + + + return; +} diff --git a/src/libs/libevs/lib_enc/amr_wb_enc_fx.cpp b/src/libs/libevs/lib_enc/amr_wb_enc_fx.cpp deleted file mode 100755 index ff4f8d72..00000000 --- a/src/libs/libevs/lib_enc/amr_wb_enc_fx.cpp +++ /dev/null @@ -1,625 +0,0 @@ -/*==================================================================================== - EVS Codec 3GPP TS26.442 Apr 03, 2018. Version 12.11.0 / 13.6.0 / 14.2.0 - ====================================================================================*/ - -#include - -#include "options.h" /* Compilation switches */ -#include "cnst_fx.h" /* Common constants */ -#include "rom_enc_fx.h" /* Encoder static table prototypes */ -#include "rom_com_fx.h" /* Static table prototypes */ -#include "prot_fx.h" /* Function prototypes */ -#include "stl.h" /* required by wmc_tool */ -#include "basop_util.h" - -/*-------------------------------------------------------------------* - * amr_wb_enc() - * - * AMR-WB encoder - *--------------------------------------------------------------------*/ - -void amr_wb_enc_fx( - Encoder_State_fx *st, /* i/o: encoder state structure */ - const Word16 input_sp[], /* i : input signal */ - const Word16 n_samples /* i : number of input samples */ -) -{ - Word16 i, delay; - Word16 old_inp[L_INP_12k8], *new_inp, *inp; /* buffer of old input signal */ - Word16 old_inp_16k[L_INP_12k8+L_SUBFR], *inp_16k, *new_inp_16k;/* buffer of old input signal @16kHz*/ - Word16 old_exc[L_EXC], *exc; /* excitation signal buffer */ - Word16 old_wsp[L_WSP], *wsp; /* weighted input signal buffer */ - Word16 input_frame; /* frame length at input sampling freq. */ - Word32 fr_bands[2*NB_BANDS]; /* energy in frequency bands */ - Word32 lf_E[2*VOIC_BINS]; /* per bin spectrum energy in lf */ - Word32 tmpN[NB_BANDS]; /* temporary noise update */ - Word32 tmpE[NB_BANDS], PS[L_FFT/2]; /* temporary averaged energy of 2 sf. */ - Word16 corr_shift; /* correlation shift */ - Word16 relE; /* frame relative energy */ - Word16 cor_map_sum, sp_div; - Word16 vad_flag; - Word16 localVAD; - Word16 Etot; /* total energy */ - Word32 ener = 0; /* residual energy from Levinson-Durbin */ - Word16 pitch[3]; /* open-loop pitch values */ - Word16 voicing[3]; /* open-loop pitch gains */ - Word16 A[NB_SUBFR*(M+1)]; /* A(z) unquantized for the 4 subframes */ - Word16 Aw[NB_SUBFR*(M+1)]; /* A(z) unquantized for the 4 subframes */ - Word16 vad_hover_flag, noisy_speech_HO, clean_speech_HO, NB_speech_HO; - Word16 epsP_h[M+1]; /* LP prediction errors */ - Word16 epsP_l[M+1]; /* LP prediction errors */ - Word16 isp_new[M]; /* ISPs at the end of the frame */ - Word16 isf_new[M]; /* ISFs at the end of the frame */ - Word16 isp_tmp[M]; - Word16 Aq[NB_SUBFR*(M+1)]; /* A(z) quantized for the 4 subframes */ - Word16 syn[L_FRAME]; /* synthesis vector */ - Word16 res[L_FRAME]; /* residual signal for FER protection */ - Word16 exc2[L_FRAME]; /* enhanced excitation */ - Word16 pitch_buf[NB_SUBFR]; /* floating pitch for each subframe */ - Word16 dummy_buf[L_FRAME32k]; /* dummy buffer - no usage */ - Word16 snr_sum_he; - Word16 allow_cn_step; - Word16 tmps; - Word16 harm_flag; /* Q0 */ - Word16 high_lpn_flag; - Word16 localVAD_HE_SAD; - Word16 vad_flag_dtx; - Word16 coder_type; - Word16 hf_gain_fx[NB_SUBFR]; - Word16 Q_new, Q_exp,Q_r[2]; - Word16 excitation_max_test, shift; - Word32 Le_min_scaled; - Word16 Q_sp_div; - Word16 non_staX, Scale_fac[2]; - Word16 sp_floor; - Word16 fft_buff[2*L_FFT]; - Word32 q_env[NUM_ENV_CNG]; - Word16 sid_bw = 0; - Word16 exc3[L_FRAME]; - Word32 lp_bckr, hp_bckr, Ltmp; - Word16 tmp, e_tmp; - - /*------------------------------------------------------------------* - * Initialization - *------------------------------------------------------------------*/ - - st->L_frame_fx = L_FRAME; - move16(); - st->gamma = GAMMA1; - move16(); - st->core_fx = AMR_WB_CORE; - move16(); - st->core_brate_fx = st->total_brate_fx; - move16(); - st->input_bwidth_fx = st->last_input_bwidth_fx; - move16(); - st->bwidth_fx = st->last_bwidth_fx; - move16(); - coder_type = GENERIC; - move16(); - input_frame = st->input_frame_fx; - move16(); /* frame length of the input signal */ - st->extl_fx = -1; - st->encoderPastSamples_enc = (L_FRAME*9)/16; - st->encoderLookahead_enc = L_LOOK_12k8; - st->bpf_off_fx = 0; - move16(); - test(); - if( sub(st->last_core_fx,HQ_CORE) == 0 || sub(st->last_codec_mode,MODE2) == 0 ) - { - st->bpf_off_fx = 1; - move16(); - } - st->igf = 0; - move16(); - - /* Updates in case of EVS primary mode -> AMR-WB IO mode switching */ - IF( sub(st->last_core_fx,AMR_WB_CORE) != 0 ) - { - updt_IO_switch_enc_fx( st, input_frame); - } - - /* Updates in case of HQ -> AMR-WB IO mode switching */ - Q_new = 0; - move16(); /* prevent compiler warning only*/ - core_switching_pre_enc_fx( st,&(st->LPDmem), NULL, NULL ); - - set16_fx( hf_gain_fx, 0, NB_SUBFR ); - set16_fx( old_inp, 0, L_INP_12k8 ); - exc = old_exc + L_EXC_MEM; /* pointer to excitation signal in the current frame */ - - Copy( st->LPDmem.old_exc, old_exc, L_EXC_MEM ); - - new_inp = old_inp + L_INP_MEM; /* pointer to new samples of the input signal */ - inp = new_inp - L_LOOK_12k8; /* pointer to current frame of input signal */ - wsp = old_wsp + L_WSP_MEM; /* pointer to current frame of weighted signal */ - - Copy( st->old_inp_12k8_fx, old_inp, L_INP_MEM ); - Copy( st->old_wsp_fx, old_wsp, L_WSP_MEM ); - - new_inp_16k = old_inp_16k + L_INP_MEM; /* pointer to new samples of the input signal in 16kHz core */ - inp_16k = new_inp_16k - L_LOOK_16k; /* pointer to the current frame of input signal in 16kHz core */ - Copy( st->old_inp_16k_fx, old_inp_16k, L_INP_MEM ); - - /* in case of switching, reset AMR-WB BWE memories */ - test(); - IF( L_sub(st->total_brate_fx,ACELP_23k85) == 0 && L_sub(st->last_core_brate_fx,ACELP_23k85) != 0 ) - { - hf_cod_init_fx( st->mem_hp400_enc_fx, st->mem_hf_enc_fx, st->mem_syn_hf_enc_fx, st->mem_hf2_enc_fx, &st->gain_alpha_fx ); - } - - /*----------------------------------------------------------------* - * set input samples buffer - *----------------------------------------------------------------*/ - - /* get delay to synchronize ACELP and MDCT frame */ - delay = NS2SA_fx2(st->input_Fs_fx, DELAY_FIR_RESAMPL_NS); - - Copy( st->input - delay, st->old_input_signal_fx, input_frame+delay ); - - /*----------------------------------------------------------------* - * Buffering of input signal - * HP filtering - *----------------------------------------------------------------*/ - - Copy( input_sp, st->input, n_samples ); - FOR( i = n_samples; i < input_frame; i++ ) - { - st->input[i] = 0; - move16(); - } - hp20( st->input, 1, input_frame, st->mem_hp20_in_fx, st->input_Fs_fx ); - - /*-----------------------------------------------------------------* - * switching from ACELP@16k core to AMR-WB IO mode - *-----------------------------------------------------------------*/ - - st->rate_switching_reset=0; - move16(); - test(); - test(); - IF( sub(st->last_core_fx,AMR_WB_CORE) != 0 && sub(st->last_L_frame_fx,L_FRAME16k) == 0 && sub(st->last_core_fx,HQ_CORE) != 0) - { - /* in case of switching, do not apply BPF */ - st->bpf_off_fx = 1; - move16(); - st->rate_switching_reset=lsp_convert_poly_fx(st->lsp_old_fx, L_FRAME, 1); - - /* convert old quantized LSF vector */ - lsp2lsf_fx( st->lsp_old_fx, st->lsf_old_fx, M, INT_FS_FX ); - - /* Reset LPC mem */ - Copy( GEWB_Ave_fx, st->mem_AR_fx, M ); - set16_fx( st->mem_MA_fx,0, M ); - - /* update synthesis filter memories */ - synth_mem_updt2( L_FRAME, st->last_L_frame_fx, st->LPDmem.old_exc, st->LPDmem.mem_syn_r, st->mem_syn1_fx, st->LPDmem.mem_syn, ENC ); - Copy( st->LPDmem.old_exc, old_exc, L_EXC_MEM ); - Copy( st->mem_syn1_fx, st->LPDmem.mem_syn2, M ); - Copy( st->LPDmem.mem_syn2, st->LPDmem.mem_syn3, M ); - - /* lsp -> isp */ - Copy( stable_ISP_fx, isp_tmp, M ); - lsp2isp_fx( st->lsp_old_fx, st->lsp_old_fx, isp_tmp, M ); - - } - - /* update buffer of old subframe pitch values */ - IF( sub(st->last_L_frame_fx,L_FRAME) != 0 ) - { - move16(); - IF( sub(st->last_L_frame_fx,L_FRAME32k) == 0 ) - { - /* (float)12800/(float)32000; */ - tmp = 13107; - } - ELSE IF( sub(st->last_L_frame_fx,512) == 0 ) - { - /* (float)12800/(float)25600; */ - tmp = 16384; - } - ELSE /* st->last_L_frame == L_FRAME16k */ - { - /* (float)12800/(float)16000; */ - tmp = 26214; - } - - FOR( i=NB_SUBFR16k-NB_SUBFR; iold_pitch_buf_fx[i-1] = mult_r(tmp, st->old_pitch_buf_fx[i]); - move16(); - } - - FOR( i=2*NB_SUBFR16k-NB_SUBFR; i<2*NB_SUBFR16k; i++ ) - { - st->old_pitch_buf_fx[i-2] = mult_r(tmp, st->old_pitch_buf_fx[i]); - move16(); - } - } - - test(); - if( sub(st->last_bwidth_fx,NB)==0 && st->ini_frame_fx!=0 ) - { - st->rate_switching_reset=1; - move16(); - } - - /*----------------------------------------------------------------* - * Change the sampling frequency to 12.8 kHz - *----------------------------------------------------------------*/ - - modify_Fs_fx( st->input, input_frame, st->input_Fs_fx, new_inp, 12800, st->mem_decim_fx, 0 ); - - /* update signal buffer */ - Copy( new_inp, st->buf_speech_enc+L_FRAME, L_FRAME ); - Scale_sig( st->buf_speech_enc+L_FRAME, L_FRAME, 1 ); - - /*------------------------------------------------------------------* - * Perform fixed preemphasis through 1 - g*z^-1 - *-----------------------------------------------------------------*/ - - Preemph_scaled( new_inp, &Q_new, &st->mem_preemph_fx, st->Q_max, PREEMPH_FAC, 0, 1, L_Q_MEM, L_FRAME, st->last_coder_type_fx, 1 ); - - Q_exp = sub(Q_new, st->Q_old); - move16(); - st->Q_old = Q_new; - move16(); - - Le_min_scaled = Scale_mem_pre_proc( st->ini_frame_fx, Q_exp, &Q_new, old_inp, &(st->mem_wsp_fx), st->enrO_fx, st->bckr_fx, st->ave_enr_fx, - st->ave_enr2_fx, st->fr_bands1_fx, st->fr_bands2_fx, st->Bin_E_old_fx ); - - Q_exp = sub(Q_new, st->prev_Q_new); - move16(); - Scale_mem_enc( Q_exp, old_inp_16k, old_exc, st->old_bwe_exc_fx, &(st->LPDmem.mem_w0), st->LPDmem.mem_syn, st->LPDmem.mem_syn2, - &st->mem_deemp_preQ_fx, st->last_exc_dct_in_fx, st->old_input_lp_fx ); - - /*----------------------------------------------------------------* - * Compute spectrum, find energy per critical frequency band - * Track energy and signal dynamics - * Detect NB spectrum in a 16kHz-sampled input - *----------------------------------------------------------------*/ - - analy_sp( inp, Q_new, fr_bands, lf_E, &Etot, st->min_band_fx, st->max_band_fx, Le_min_scaled, Scale_fac, st->Bin_E_fx, - st->Bin_E_old_fx, PS, st->lgBin_E_fx, st->band_energies, fft_buff ); - - noise_est_pre_fx( Etot, st->ini_frame_fx, &st->Etot_l_fx, &st->Etot_h_fx, &st->Etot_l_lp_fx, &st->Etot_last_fx, - &st->Etot_v_h2_fx, &st->sign_dyn_lp_fx, st->harm_cor_cnt_fx, &st->Etot_lp_fx ); - - /*----------------------------------------------------------------* - * VAD - *----------------------------------------------------------------*/ - - vad_flag = wb_vad_fx( st, fr_bands, &localVAD, &noisy_speech_HO, &clean_speech_HO, &NB_speech_HO, - &snr_sum_he, &localVAD_HE_SAD, &(st->flag_noisy_speech_snr), Q_new ) ; - - if ( vad_flag == 0 ) - { - coder_type = INACTIVE; - move16(); - } - - /* apply DTX hangover for CNG analysis */ - vad_flag_dtx = dtx_hangover_addition_fx( st, localVAD, vad_flag, sub(st->lp_speech_fx, st->lp_noise_fx), 0, &vad_hover_flag ); - - /*-----------------------------------------------------------------* - * Select SID or FRAME_NO_DATA frame if DTX enabled - *-----------------------------------------------------------------*/ - - IF ( sub(st->last_core_fx,AMR_WB_CORE) != 0 ) - { - st->fd_cng_reset_flag = 1; - move16(); - } - ELSE IF ( s_and((st->fd_cng_reset_flag > 0),(sub(st->fd_cng_reset_flag,10) < 0)) ) - { - st->fd_cng_reset_flag = add(st->fd_cng_reset_flag,1); - } - ELSE - { - st->fd_cng_reset_flag = 0; - move16(); - } - - dtx_fx( st, vad_flag_dtx, inp, Q_new ); - - /*----------------------------------------------------------------* - * Noise energy down-ward update and total noise energy estimation - * Long-term energies and relative frame energy updates - * Correlation correction as a function of total noise level - *----------------------------------------------------------------*/ - - noise_est_down_fx( fr_bands, st->bckr_fx, tmpN, tmpE, st->min_band_fx, st->max_band_fx, &st->totalNoise_fx, - Etot, &st->Etot_last_fx, &st->Etot_v_h2_fx, Q_new, Le_min_scaled ); - - high_lpn_flag = 0; - move16(); /* Q0 flag */ - long_enr_fx( st, Etot, localVAD_HE_SAD, high_lpn_flag ); - relE = sub(Etot, st->lp_speech_fx); /* Q8 */ - - IF( sub(st->bwidth_fx, NB) != 0 ) - { - lp_bckr = Mean32( st->bckr_fx, 10 ); - } - ELSE - { - lp_bckr = Mean32( st->bckr_fx+1, 9 ); - } - hp_bckr = L_shr(L_add(st->bckr_fx[st->max_band_fx-1] , st->bckr_fx[st->max_band_fx]),1); - if( hp_bckr == 0 ) /* Avoid division by zero. */ - { - hp_bckr = L_deposit_l(1); - } - tmp = BASOP_Util_Divide3232_Scale( lp_bckr, hp_bckr, &e_tmp ); - Ltmp = L_shr_r( L_deposit_h( tmp ), sub( 15, e_tmp ) ); - st->bckr_tilt_lt = L_add( Mpy_32_16_r( st->bckr_tilt_lt, 29491 ), Mpy_32_16_r( Ltmp, 3277 ) ); - - corr_shift = correlation_shift_fx( st->totalNoise_fx ); - - /*----------------------------------------------------------------* - * WB, SWB and FB bandwidth detector - *----------------------------------------------------------------*/ - - bw_detect_fx( st, st->input, localVAD, NULL, NULL ); - - /* in AMR_WB IO, limit the maximum band-width to WB */ - if( sub(st->bwidth_fx,WB) > 0 ) - { - st->bwidth_fx = WB; - move16(); - } - - /*----------------------------------------------------------------* - * Perform LP analysis - * Compute weighted inp - * Perform open-loop pitch analysis - * Perform 1/4 pitch precision improvement - *----------------------------------------------------------------*/ - - IF ( vad_flag == 0 ) - { - /* reset the OL pitch tracker memories during inactive frames */ - pitch_ol_init_fx( &st->old_thres_fx, &st->old_pitch, &st->delta_pit_fx, &st->old_corr_fx) ; - } - - analy_lp_AMR_WB_fx( inp, &ener, A, epsP_h, epsP_l, isp_new, st->lsp_old1_fx, - isf_new, st->old_pitch_la, st->old_voicing_la, Q_new, Q_r ); - - find_wsp( A, inp, wsp, &st->mem_wsp_fx, TILT_FAC_FX, L_FRAME, L_LOOK_12k8, L_SUBFR, Aw, GAMMA1, NB_SUBFR ); - Scale_wsp( wsp, &(st->old_wsp_max), &shift, &Q_exp, &(st->old_wsp_shift), - st->old_wsp2_fx, st->mem_decim2_fx, st->old_wsp_fx, add(L_FRAME, L_LOOK_12k8)); - - excitation_max_test = -32768; - move16(); - FOR (i = 0; i < L_EXC_MEM; i++) - { - excitation_max_test = s_max(abs_s(old_exc[i]),excitation_max_test); - } - - test(); - if( sub(excitation_max_test,8192)>0 && shift==0 ) - { - shift = -1; - move16(); - } - pitch_ol_fx( pitch, voicing, &st->old_pitch, &st->old_corr_fx, corr_shift, &st->old_thres_fx, &st->delta_pit_fx, st->old_wsp2_fx, wsp, st->mem_decim2_fx, relE, 0, st->bwidth_fx, st->Opt_SC_VBR_fx ); - st->old_pitch_la = pitch[2]; - move16(); - st->old_voicing_la = voicing[2]; - move16(); - - /* VAD parameters update */ - vad_param_updt_fx( st, pitch, voicing, corr_shift, vad_flag, A ); - - /*------------------------------------------------------------------* - * Update estimated noise energy and voicing cut-off frequency - *-----------------------------------------------------------------*/ - - noise_est_fx( st, tmpN, pitch, voicing, epsP_h, epsP_l, Etot, relE, corr_shift, tmpE, fr_bands, &cor_map_sum, &sp_div, &Q_sp_div, &non_staX, &harm_flag, - lf_E, &st->harm_cor_cnt_fx, st->Etot_l_lp_fx, st->Etot_v_h2_fx, &st->bg_cnt_fx, st->lgBin_E_fx, Q_new, Le_min_scaled, &sp_floor ); - - /*----------------------------------------------------------------* - * Change the sampling frequency to 16 kHz, - * input@16kHz needed for AMR-WB IO BWE @23.85kbps - *----------------------------------------------------------------*/ - - test(); - IF( L_sub(st->input_Fs_fx, 16000) == 0 ) - { - /* no resampling needed, only delay adjustement to account for the FIR resampling delay */ - tmps = NS2SA_fx2(16000, DELAY_FIR_RESAMPL_NS); - Copy_Scale_sig( &st->mem_decim16k_fx[tmps], new_inp_16k, tmps, -1 ); /* Input in Q0 -> Output in Q-1 to mimic the resampling filter */ - Copy_Scale_sig( st->input, new_inp_16k + tmps, sub(input_frame, tmps), -1 ); /* Input in Q0 -> Output in Q-1 to mimic the resampling filter */ - Copy( st->input + input_frame - shl(tmps,1), st->mem_decim16k_fx, shl(tmps,1) ); /* memory still in Q0 */ - } - ELSE IF( L_sub(st->input_Fs_fx, 32000) == 0 || L_sub(st->input_Fs_fx, 48000) == 0 ) - { - modify_Fs_fx( st->input, input_frame, st->input_Fs_fx, new_inp_16k, 16000, st->mem_decim16k_fx, 0 ); - } - - /*----------------------------------------------------------------* - * Encoding of SID frames - *----------------------------------------------------------------*/ - - test(); - IF ( L_sub(st->core_brate_fx,SID_1k75) == 0 || L_sub(st->core_brate_fx,FRAME_NO_DATA) == 0 ) - { - /* encode CNG parameters */ - CNG_enc_fx( st, L_FRAME, Aq, inp, ener, isp_new, isf_new , &allow_cn_step, st->burst_ho_cnt_fx, sub(Q_new,1), - q_env, &sid_bw, st->exc_mem2_fx ); - - /* comfort noise generation */ - CNG_exc_fx( st->core_brate_fx, L_FRAME, &st->Enew_fx, &st->cng_seed_fx, exc, exc2, &st->lp_ener_fx, - st->last_core_brate_fx, &st->first_CNG_fx, &st->cng_ener_seed_fx, dummy_buf, allow_cn_step, - &st->last_allow_cn_step_fx, sub(st->prev_Q_new,1), sub(Q_new,1), st->num_ho_fx, q_env, st->lp_env_fx, - st->old_env_fx, st->exc_mem_fx, st->exc_mem1_fx, &sid_bw, &st->cng_ener_seed1_fx, exc3, st->Opt_AMR_WB_fx ); - - if ( st->first_CNG_fx == 0 ) - { - st->first_CNG_fx = 1; - move16(); - } - - /* synthesis */ - syn_12k8_fx( L_FRAME, Aq, exc2, dummy_buf, st->LPDmem.mem_syn3, 1, Q_new, st->Q_syn ); - - /* reset the encoder */ - CNG_reset_enc_fx( st, &(st->LPDmem), pitch_buf, dummy_buf+L_FRAME, 0 ); - - /* update st->mem_syn1 for ACELP core switching */ - Copy( st->LPDmem.mem_syn3, st->mem_syn1_fx, M ); - - /* update ACELP core synthesis filter memory */ - Copy( st->LPDmem.mem_syn3, st->LPDmem.mem_syn, M ); - - /* update old synthesis buffer - needed for ACELP internal sampling rate switching */ - Copy( dummy_buf + L_FRAME - L_SYN_MEM, st->LPDmem.mem_syn_r, L_SYN_MEM ); - /* Update MODE2 core switching memory */ - E_UTIL_deemph2( sub(Q_new,1), dummy_buf, PREEMPH_FAC, L_FRAME, &(st->LPDmem.syn[M]) ); - Copy( dummy_buf+L_FRAME-M-1, st->LPDmem.syn, M+1 ); - - } - - /*----------------------------------------------------------------* - * Encoding of all other frames - *----------------------------------------------------------------*/ - - ELSE - { - /*-----------------------------------------------------------------* - * After inactive period, use the most up-to-date ISPs - *-----------------------------------------------------------------*/ - test(); - IF( L_sub(st->last_core_brate_fx,FRAME_NO_DATA) == 0 || L_sub(st->last_core_brate_fx,SID_1k75) == 0 ) - { - Copy( st->lspCNG_fx, st->lsp_old_fx, M ); - E_LPC_isp_isf_conversion( st->lspCNG_fx, st->lsf_old_fx, M); - set16_fx( old_exc, 0, L_EXC_MEM ); - } - - /*-----------------------------------------------------------------* - * ISF Quantization and interpolation - *-----------------------------------------------------------------*/ - - isf_enc_amr_wb_fx( st, isf_new, isp_new, Aq, &st->stab_fac_fx); - - /*---------------------------------------------------------------* - * Calculation of LP residual (filtering through A[z] filter) - *---------------------------------------------------------------*/ - - calc_residu_fx( st, inp, res, Aq, 0 ); - st->burst_ho_cnt_fx = 0; - move16(); - - /*------------------------------------------------------------* - * Encode excitation - *------------------------------------------------------------*/ - - encod_amr_wb_fx( st, &(st->LPDmem), inp, Aw, Aq, pitch, voicing, res, syn, exc, exc2, pitch_buf, hf_gain_fx, inp_16k, shift, Q_new ); - - /* update st->mem_syn1 for ACELP core switching */ - Copy( st->LPDmem.mem_syn, st->mem_syn1_fx, M ); - - /* update old synthesis buffer - needed for ACELP internal sampling rate switching */ - Copy( syn + L_FRAME - L_SYN_MEM, st->LPDmem.mem_syn_r, L_SYN_MEM ); - - /* Update MODE2 core switching memory */ - E_UTIL_deemph2( sub(Q_new,1), syn, PREEMPH_FAC, L_FRAME, &(st->LPDmem.syn[M]) ); - Copy( syn+L_FRAME-M-1, st->LPDmem.syn, M+1 ); - - /*--------------------------------------------------------------------------------------* - * Write VAD information into the bitstream in AMR-WB IO mode - *--------------------------------------------------------------------------------------*/ - - push_indice_fx( st, IND_VAD_FLAG, vad_flag, 1 ); - } - - /*-----------------------------------------------------------------* - * Updates - *-----------------------------------------------------------------*/ - - /* update old weighted speech buffer - for OL pitch analysis */ - Copy( &old_wsp[L_FRAME], st->old_wsp_fx, L_WSP_MEM ); - - /* update old input signal buffer */ - Copy( &old_inp[L_FRAME], st->old_inp_12k8_fx, L_INP_MEM ); - - /* update old input signal @16kHz buffer */ - IF( L_sub(st->input_Fs_fx,8000) > 0 ) - { - Copy( &old_inp_16k[L_FRAME16k], st->old_inp_16k_fx, L_INP_MEM ); - } - - /* update of old per-band energy spectrum */ - Copy32( fr_bands + NB_BANDS, st->enrO_fx, NB_BANDS ); - - /* update the last bandwidth */ - st->last_input_bwidth_fx = st->input_bwidth_fx; - st->last_bwidth_fx = st->bwidth_fx; - - /* update signal buffers */ - Copy( new_inp, st->buf_speech_enc_pe+L_FRAME, L_FRAME ); - Copy( wsp, st->buf_wspeech_enc+L_FRAME+L_SUBFR, L_FRAME + L_LOOK_12k8 ); - updt_enc_fx( st, L_FRAME, coder_type, old_exc, pitch_buf, 0, Aq, isf_new, isp_new, dummy_buf ); - - core_encode_update( st ); - - /* update main codec parameters */ - st->last_extl_fx = -1; - move16(); - st->last_core_fx = st->core_fx; - move16(); - st->last_L_frame_fx = L_FRAME; - move16(); - st->last_core_brate_fx = st->core_brate_fx; - move16(); - st->last_total_brate_fx = st->total_brate_fx; - move16(); - st->Etot_last_fx = Etot; - move16(); - st->last_coder_type_raw_fx = st->coder_type_raw_fx; - move16(); - st->last_codec_mode = st->codec_mode; - move16(); - - st->prev_Q_new = Q_new; - - /* Increase the counter of initialization frames */ - if( sub(st->ini_frame_fx,MAX_FRAME_COUNTER) < 0 ) - { - st->ini_frame_fx = add(st->ini_frame_fx,1); - } - - if( L_sub(st->core_brate_fx,SID_1k75) > 0 ) - { - st->last_active_brate_fx = st->total_brate_fx; - move32(); - } - - test(); - IF ( L_sub(st->core_brate_fx,SID_1k75) > 0 && st->first_CNG_fx ) - { - if( sub(st->act_cnt_fx,BUF_DEC_RATE) >= 0 ) - { - st->act_cnt_fx = 0; - move16(); - } - - st->act_cnt_fx = add(st->act_cnt_fx,1); - - test(); - if( sub(st->act_cnt_fx,BUF_DEC_RATE) == 0 && st->ho_hist_size_fx > 0 ) - { - st->ho_hist_size_fx = sub(st->ho_hist_size_fx,1); - } - - st->act_cnt2_fx = add(st->act_cnt2_fx,1); - if( sub(st->act_cnt2_fx, MIN_ACT_CNG_UPD) >= 0 ) - { - st->act_cnt2_fx = MIN_ACT_CNG_UPD; - move16(); - } - } - - - return; -} diff --git a/src/libs/libevs/lib_enc/analy_lp.cpp b/src/libs/libevs/lib_enc/analy_lp.cpp new file mode 100644 index 00000000..b0944eb0 --- /dev/null +++ b/src/libs/libevs/lib_enc/analy_lp.cpp @@ -0,0 +1,143 @@ +/*==================================================================================== + EVS Codec 3GPP TS26.443 Nov 13, 2018. Version 12.11.0 / 13.7.0 / 14.3.0 / 15.1.0 + ====================================================================================*/ + +#include "options.h" +#include "cnst.h" +#include "rom_com.h" +#include "prot.h" + +/*-------------------------------------------------------------------* + * analy_lp() + * + * Perform LP analysis + * + * - autocorrelations + lag windowing + * - Levinson-Durbin algorithm to find A(z) + * - convert A(z) to LSPs + * - find interpolated LSPs and convert back to A(z) for all subframes + * - update LSPs for the next frame + *-------------------------------------------------------------------*/ + +void analy_lp( + const float speech[], /* i : pointer to the speech frame */ + const short L_frame, /* i : length of the frame */ + const short L_look, /* i : look-ahead */ + float *ener, /* o : residual energy from Levinson-Durbin */ + float A[], /* o : A(z) filter coefficients */ + float epsP[], /* o : LP analysis residual energies for each iteration */ + float lsp_new[], /* o : current frame LSPs */ + float lsp_mid[], /* o : current mid-frame LSPs */ + float lsp_old[], /* i/o: previous frame unquantized LSPs */ + const short Top[2], /* i : open loop pitch lag */ + const float Tnc[2], /* i : open loop pitch gain */ + const float sr_core /* i : internal sampling rate */ +) +{ + short i_subfr, wind_length, half_frame; + float r[M+1], *lsp; + const float *wind, *pt; + short half_frame_idx; + + if( L_frame == L_FRAME ) + { + wind_length = L_LP; + wind = LP_assym_window; + } + else /* L_frame == L_FRAME16k */ + { + wind_length = L_LP_16k; + wind = LP_assym_window_16k; + } + lsp = lsp_mid; + half_frame = L_frame>>1; + + half_frame_idx = 0; + + for( i_subfr = half_frame; i_subfr <= L_frame; i_subfr = i_subfr + half_frame ) + { + pt = speech + i_subfr + L_look - wind_length; + + /* Autocorrelations */ + autocorr( pt, r, M, wind_length, wind, 0, 0, 0 ); + + /* Lag windowing */ + adapt_lag_wind( r, M, Top[half_frame_idx], Tnc[half_frame_idx], sr_core ); + ++half_frame_idx; + + /* Levinson-Durbin */ + lev_dur( A, r, M, epsP ); + + /* Conversion of A(z) to LSPs */ + a2lsp_stab( A, lsp, lsp_old ); + + lsp = lsp_new; + } + + /* LSP interpolation */ + int_lsp4( L_frame, lsp_old, lsp_mid, lsp_new, A, M, 0 ); + + /* updates */ + mvr2r( lsp_new, lsp_old, M ); + + *ener = epsP[M]; + + return; +} + + +/*-------------------------------------------------------------------* + * analy_lp_AMR_WB() + * + * Perform LP analysis for AMR-WB IO mode + * + * - autocorrelations + lag windowing + * - Levinson-Durbin algorithm to find A(z) + * - convert A(z) to ISPs + * - find interpolated ISPs and convert back to A(z) for all subframes + * - update ISPs for the next frame + *-------------------------------------------------------------------*/ + +void analy_lp_AMR_WB( + const float speech[], /* i : pointer to the speech frame */ + float *ener, /* o : residual energy from Levinson-Durbin */ + float A[], /* o : A(z) filter coefficients */ + float epsP[], /* o : LP analysis residual energies for each iteration */ + float isp_new[], /* o : current frame ISPs */ + float isp_old[], /* i/o: previous frame unquantized ISPs */ + float isf_new[], /* o : current frame ISFs */ + const int Top, /* i : open loop pitch lag */ + const float Tnc /* i : open loop pitch gain */ +) +{ + short wind_length; + float r[M+1]; + const float *wind; + + /* Initialization */ + wind_length = L_LP_AMR_WB; + wind = hamcos_window; + + /* Autocorrelations */ + autocorr( speech - L_SUBFR, r, M, wind_length, wind, 0, 0, 0 ); + + /* Lag windowing */ + adapt_lag_wind( r, M, Top, Tnc, 12800 ); + + /* Levinson-Durbin */ + lev_dur( A, r, M, epsP ); + + a2isf( A, isf_new, stable_ISF, M); + isf2isp( isf_new, isp_new, M, INT_FS_12k8 ); + + /* ISP interpolation */ + int_lsp( L_FRAME, isp_old, isp_new, A, M, interpol_isp_amr_wb, 1 ); + + *ener = epsP[M]; + + /* updates */ + mvr2r( isp_new, isp_old, M ); + + return; +} + diff --git a/src/libs/libevs/lib_enc/analy_lp_fx.cpp b/src/libs/libevs/lib_enc/analy_lp_fx.cpp deleted file mode 100755 index 7c1e4880..00000000 --- a/src/libs/libevs/lib_enc/analy_lp_fx.cpp +++ /dev/null @@ -1,173 +0,0 @@ -/*==================================================================================== - EVS Codec 3GPP TS26.442 Apr 03, 2018. Version 12.11.0 / 13.6.0 / 14.2.0 - ====================================================================================*/ - -#include "options.h" /* Compilation switches */ -#include "cnst_fx.h" /* Common constants */ -#include "rom_com_fx.h" /* Static table prototypes */ -#include "rom_enc_fx.h" /* Static table prototypes */ -#include "prot_fx.h" /* Function prototypes */ -#include "stl.h" - -/*-------------------------------------------------------------------* - * analy_lp() - * - * Perform LP analysis - * - * - autocorrelations + lag windowing - * - Levinson-Durbin algorithm to find A(z) - * - convert A(z) to LSPs - * - find interpolated LSPs and convert back to A(z) for all subframes - * - update LSPs for the next frame - *-------------------------------------------------------------------*/ - -void analy_lp_fx( - const Word16 speech[], /* i : pointer to the speech frame */ - const Word16 L_frame, /* i : length of the frame */ - const Word16 L_look, /* i : look-ahead */ - Word32 *ener, /* o : residual energy from Levinson-Durbin */ - Word16 A[], /* o : A(z) filter coefficients */ - Word16 epsP_h[], /* o : LP analysis residual energies for each iteration */ - Word16 epsP_l[], /* o : LP analysis residual energies for each iteration */ - Word16 lsp_new[], /* o : current frame LSPs */ - Word16 lsp_mid[], /* o : current mid-frame LSPs */ - Word16 lsp_old[], /* i/o: previous frame unquantized LSPs */ - const Word16 Top[2], /* i : open loop pitch lag */ - const Word16 Tnc[2], /* i : open loop pitch gain */ - const Word32 Core_sr, /* i : Internal core sampling rate */ - Word16 Q_new, - Word16 *Q_r -) -{ - Word16 r_h[M+1]; /* Autocorrelations of windowed speech MSB */ - Word16 r_l[M+1]; /* Autocorrelations of windowed speech LSB */ - Word32 LepsP[M+1]; - Word16 i, i_subfr, wind_length = 0; - Word16 *lsp; - const Word16 *wind = NULL; - const Word16 *pt; - Word16 half_frame; - - IF( sub(L_frame,L_FRAME) == 0 ) - { - wind_length = L_LP; - move16(); - wind = Assym_window_W16fx; - } - ELSE /* L_frame == L_FRAME16k */ - { - wind_length = L_LP_16k; - move16(); - wind = assym_window_16k_fx; - } - lsp = lsp_mid; - half_frame = shr(L_frame,1); - - FOR( i_subfr = 0; i_subfr <= 1; i_subfr++ ) - { - pt = speech + sub(add(half_frame, L_look), wind_length); - half_frame = shl(half_frame,1); - - /* Autocorrelations */ - autocorr_fx(pt, M, r_h, r_l, &Q_r[1-i_subfr], wind_length, wind, 0, 0 ); - - /* Lag windowing */ - adapt_lag_wind( r_h, r_l, M, Top[i_subfr], Tnc[i_subfr], Core_sr ); - - /* Levinson-Durbin */ - E_LPC_lev_dur(r_h, r_l, A, LepsP, M, NULL); - FOR (i = 0; i <= M; i++) - { - L_Extract(LepsP[i], &epsP_h[i], &epsP_l[i]); - } - /*Q_r[... might not be needed from external...*/ - Q_r[1-i_subfr] = add(Q_r[1-i_subfr], shl(Q_new, 1)); - move16(); - - /* Conversion of A(z) to LSPs */ - E_LPC_a_lsp_conversion( A, lsp, lsp_old, M ); - - lsp = lsp_new; - } - - /* LSP interpolation */ - int_lsp4_fx( L_frame, lsp_old, lsp_mid, lsp_new, A , M, 0 ); - Copy (lsp_new, lsp_old, M); - *ener = L_Comp(epsP_h[M],epsP_l[M]); - move32(); - - return; - -} - - -/*-------------------------------------------------------------------* - * analy_lp_AMR_WB() - * - * Perform LP analysis for AMR-WB IO mode - * - * - autocorrelations + lag windowing - * - Levinson-Durbin algorithm to find A(z) - * - convert A(z) to ISPs - * - find interpolated ISPs and convert back to A(z) for all subframes - * - update ISPs for the next frame - *-------------------------------------------------------------------*/ - -void analy_lp_AMR_WB_fx( - const Word16 speech[], /* i : pointer to the speech frame */ - Word32 *ener, /* o : residual energy from Levinson-Durbin */ - Word16 A[], /* o : A(z) filter coefficients */ - Word16 epsP_h[], /* o : LP analysis residual energies for each iteration */ - Word16 epsP_l[], /* o : LP analysis residual energies for each iteration */ - Word16 isp_new[], /* o : current frame ISPs */ - Word16 isp_old[], /* i/o: previous frame unquantized ISPs */ - Word16 isf_new[], /* o : current frame ISPs */ - Word16 Top, /* i : open loop pitch lag */ - Word16 Tnc, /* i : open loop pitch gain */ - Word16 Q_new, - Word16 *Q_r -) -{ - Word16 r_h[M+1]; /* Autocorrelations of windowed speech MSB */ - Word16 r_l[M+1]; /* Autocorrelations of windowed speech LSB */ - Word32 LepsP[M+1]; - Word16 i, wind_length = 0; - const Word16 *wind; - - /* Initialization */ - wind_length = L_LP_AMR_WB; - move16(); - wind = Hamcos_Window; - - /* Autocorrelations */ - autocorr_fx( speech - L_SUBFR, M, r_h, r_l, &Q_r[0], wind_length, wind, 0, 0 ); - - /* Lag windowing */ - adapt_lag_wind( r_h, r_l, M, Top, Tnc, INT_FS_FX ); - - /* Levinson-Durbin */ - /*lev_dur( A, r, M, epsP );*/ - E_LPC_lev_dur(r_h, r_l, A, LepsP, M, NULL); - FOR (i = 0; i <= M; i++) - { - L_Extract(LepsP[i], &epsP_h[i], &epsP_l[i]); - } - /*Q_r[... might not be needed from external...*/ - Q_r[0] = add(Q_r[0], shl(Q_new, 1)); - move16(); - - E_LPC_a_lsf_isf_conversion( A, isf_new, stable_ISF_fx, M, 0 ); - E_LPC_isf_isp_conversion( isf_new, isp_new, M ); - - /* ISP interpolation */ - int_lsp_fx( L_FRAME, isp_old, isp_new, A, M, interpol_isp_amr_wb_fx, 1 ); - - /**ener = epsP[M];*/ - *ener = L_Comp(epsP_h[M],epsP_l[M]); - move32(); - - /* updates */ - Copy( isp_new, isp_old, M ); - - return; -} diff --git a/src/libs/libevs/lib_enc/analy_sp.cpp b/src/libs/libevs/lib_enc/analy_sp.cpp old mode 100755 new mode 100644 index 16950f68..7d014d45 --- a/src/libs/libevs/lib_enc/analy_sp.cpp +++ b/src/libs/libevs/lib_enc/analy_sp.cpp @@ -1,170 +1,105 @@ /*==================================================================================== - EVS Codec 3GPP TS26.442 Apr 03, 2018. Version 12.11.0 / 13.6.0 / 14.2.0 + EVS Codec 3GPP TS26.443 Nov 13, 2018. Version 12.11.0 / 13.7.0 / 14.3.0 / 15.1.0 ====================================================================================*/ +#include #include "options.h" -#include "cnst_fx.h" -#include "stl.h" -#include "basop_util.h" -#include "prot_fx.h" -#include "rom_enc_fx.h" -#include +#include "cnst.h" +#include "rom_enc.h" +#include "rom_com.h" +#include "prot.h" -static void find_enr( Word16 data[], Word32 band[], Word32 *ptE, Word32 *LEtot, const Word16 min_band, const Word16 max_band, - const Word16 Q_new2, const Word32 e_min, Word32 *Bin_E, Word16 BIN_FREQ_FX, Word32 *band_energies ); +static void find_enr( const float data[], float band[], float *ptE, float *Etot, const short min_band, + const short max_band, float *Bin_E, const short bin_freq, float *band_ener ); /*-------------------------------------------------------------------* * analy_sp() * - * Spectral analysis of 12.8kHz input + * Spectral analysis *-------------------------------------------------------------------*/ void analy_sp( - Word16 *speech, /* i : speech buffer Q_new - preemph_bits */ - const Word16 Q_new, /* i : current scaling exp Q0 */ - Word32 *fr_bands, /* o : energy in critical frequency bands Q_new + QSCALE */ - Word32 *lf_E, /* o : per bin E for first... Q_new + QSCALE - 2*/ - Word16 *Etot, /* o : total input energy Q8 */ - const Word16 min_band, /* i : minimum critical band Q0 */ - const Word16 max_band, /* i : maximum critical band Q0 */ - const Word32 e_min_scaled, /* i : minimum energy scaled Q_new + QSCALE */ - Word16 Scale_fac[2], /* o : FFT scales factors (2 values by frame) Q0 */ - Word32 *Bin_E, /* o : per-bin energy spectrum */ - Word32 *Bin_E_old, /* o : per-bin energy spectrum of the previous frame */ - Word32 *PS, /* o : per-bin energy spectrum */ - Word16 *EspecdB, /* o : per-bin log energy spectrum (with f=0) Q7 */ - Word32 *band_energies,/* o : energy in critical frequency bands without minimum noise floor MODE2_E_MIN */ - Word16 *fft_buff /* o : FFT coefficients */ + float *speech, /* i : speech buffer */ + float *Bin_E, /* o : per bin log energy spectrum */ + float *Bin_E_old, /* o : per bin log energy spectrum for mid-frame */ + float *fr_bands, /* o : per band energy spectrum (2 analyses) */ + float lf_E[], /* o : per bin E for first VOIC_BINS bins (without DC) */ + float *Etot, /* o : total input energy */ + const short min_band, /* i : minimum critical band */ + const short max_band, /* i : maximum critical band */ + float *band_ener, /* o: energy in critical frequency bands without minimum noise floor E_MIN */ + float *PS /* o : Per bin energy spectrum */ + ,float *fft_buff /* o : FFT coefficients */ ) { - Word16 *pt; - Word16 i_subfr, i, exp_etot, frac_etot, exp, exp_frac, exp2; - Word32 *pt_bands; - Word32 Ltmp, LEtot, L_tmp2; - Word16 *pt_fft; - Word16 Min_val, Max_val; - Word16 Scale_fac2; - Word16 fft_temp[L_FFT]; - - + short i_subfr, i; + float *pt_bands, *pt_fft, *pt; + const float *pt1; /*-----------------------------------------------------------------* - * Compute spectrum - * find energy per critical frequency band and total energy in dB + * Perform two spectral analyses + * Find energy per critical frequency band and total energy in dB *-----------------------------------------------------------------*/ pt_bands = fr_bands; pt_fft = fft_buff; - LEtot = L_deposit_l(0); + *Etot = 0.0f; - FOR (i_subfr=0; i_subfr <= 1; i_subfr++) + for( i_subfr = 0; i_subfr <= 1; i_subfr++ ) { - pt = speech + 3*(L_SUBFR/2) - L_FFT/2; - if(i_subfr != 0) + /* set pointer to the beginning of the signal for spectral analysis */ + if (i_subfr == 0) { + /* set the pointer for first analysis window */ + pt = speech + 3*(L_SUBFR/2) - L_FFT/2; + } + else + { + /* set the pointer for second analysis window */ pt = speech + 7*(L_SUBFR/2) - L_FFT/2; } - /* Clear 1st value of 1st part, copy 1st value of 2nd part */ - fft_temp[0] = 0; - move16(); - fft_temp[L_FFT/2] = pt[L_FFT/2]; - move16(); - Max_val = s_max(fft_temp[0],fft_temp[L_FFT/2]); - Min_val = s_min(fft_temp[0],fft_temp[L_FFT/2]); - - FOR (i=1; i 0) - Max_val = s_max(Max_val, fft_temp[i]); - if (fft_temp[i] < 0) - Min_val = s_min(Min_val, fft_temp[i]); - - /* 2nd windowed part */ - fft_temp[L_FFT-i] = mult_r(pt[L_FFT-i], sqrt_han_window[i]); - move16(); - if (fft_temp[L_FFT-i] > 0) - Max_val = s_max(Max_val, fft_temp[L_FFT-i]); - if (fft_temp[L_FFT-i] < 0) - Min_val = s_min(Min_val, fft_temp[L_FFT-i]); + pt_fft[i] = *pt++ **pt1++; + } + /* 2nd half of the window */ + for( i=L_FFT/2; i= 0 && sub(i,max_band) <= 0) + if ( band[i] < E_MIN ) { - IF (L_sub(band[i],e_min) < 0) - { - Ltmp1 = L_shl(e_min, 0); - exp_band = 0; - move16(); - } - - wtmp = sub(exp_band, exp_etot); - if (wtmp > 0) - { - etot = L_shr(etot, wtmp); - } - exp_etot = s_max(exp_etot, exp_band); - etot = L_add(etot, L_shl(Ltmp1, sub(exp_band, exp_etot))); + band[i] = E_MIN; } - - band_energies[i] = band[i]; - move32(); - - band[i] = L_max(band[i], e_min); - move32(); } - IF (sub(BIN_FREQ_FX, 50) == 0) + /* continue computing the energy per critical band for higher frequencies */ + if ( bin_freq == 50 ) { - /*-----------------------------------------------------------------* - * Continue compute the E per critical band for high frequencies - *-----------------------------------------------------------------*/ - - FOR (i = voic_band; i < NB_BANDS; i++) + for( i = voic_band; i < NB_BANDS; i++ ) { - tmpptr = Bin_E; - move16(); - Ltmp1 = L_deposit_l(0); - - FOR (; freq <= crit_bands[i]; freq += BIN_FREQ_FX) + band[i] = 0.0f; + cnt = 0; + while( freq <= crit_bands[i] ) { - /* *ptE = *ptR * *ptR + *ptI * *ptI */ - Ltmp = L_mult(*ptI, *ptI); - Ltmp = L_mac(Ltmp, *ptR, *ptR); - - /* *ptE *= 4.0 / (L_FFT*L_FFT) */ - /* normalization - corresponds to FFT normalization by 2/L_FFT */ - BASOP_SATURATE_WARNING_OFF; /* saturation seems to have no effect (tested by simulation) */ - *Bin_E = L_shl(Ltmp, diff_scaleM2); - move32(); /* scaled by Q_new + QSCALE - 2 */ - BASOP_SATURATE_WARNING_ON; + *Bin_E = *ptR **ptR + *ptI **ptI; + *Bin_E *= norm_val; + band[i] += *Bin_E; Bin_E++; - Ltmp1 = L_add(Ltmp1, Ltmp); - ptR++; ptI--; + + freq += bin_freq; + cnt++; } - exp_band = sub(norm_l(Ltmp1), 1); /* divide by 2 to ensure band < cnt */ - wtmp = round_fx(L_shl(Ltmp1, exp_band)); + band[i] *= inv_tbl[cnt]; /* normalization per frequency bin */ - /* band[i] /= cnt */ /* normalization per frequency bin */ - cnt = (Word16)(Bin_E - tmpptr); - shift_to_norm = norm_s(cnt); - wtmp = div_s(wtmp, shl(cnt, shift_to_norm)); - Ltmp1 = L_deposit_l(wtmp); + band_ener[i] = band[i]; /* per band energy without E_MIN */ - exp_band = sub(exp_band, shift_to_norm); - exp_band = sub(diff_scaleP1, exp_band); - BASOP_SATURATE_WARNING_OFF; /* saturation seems to have no effect (tested by simulation) */ - band[i] = L_shl(Ltmp1, exp_band); - move32();/* band scaled by Q_new + QSCALE */ - BASOP_SATURATE_WARNING_ON; - - test(); - IF (sub(i,min_band) >= 0 && sub(i,max_band) <= 0) + if( band[i] < E_MIN ) { - IF (L_sub(band[i],e_min) < 0) - { - Ltmp1 = L_shl(e_min, 0); - exp_band = 0; - move16(); - } - - wtmp = sub(exp_band, exp_etot); - if (wtmp > 0) - { - etot = L_shr(etot, wtmp); - } - exp_etot = s_max(exp_etot, exp_band); - - etot = L_add(etot, L_shl(Ltmp1, sub(exp_band, exp_etot))); + band[i] = E_MIN; } - - band_energies[i] = band[i]; - move32(); - - band[i] = L_max(band[i], e_min); - move32(); } } - /*-----------------------------------------------------------------* - * Find the total energy over the input bandwidth - *-----------------------------------------------------------------*/ - - etot = L_add(*LEtot, L_shl(etot, sub(exp_etot, 4))); - - *LEtot = etot; - move32(); + /* find the total log energy */ + tmp = *Etot; + for( i = min_band; i <= max_band; i++ ) + { + tmp += band[i]; + } + *Etot = tmp; return; } diff --git a/src/libs/libevs/lib_enc/ari_enc.cpp b/src/libs/libevs/lib_enc/ari_enc.cpp old mode 100755 new mode 100644 index bf1ff4ef..169cb9f7 --- a/src/libs/libevs/lib_enc/ari_enc.cpp +++ b/src/libs/libevs/lib_enc/ari_enc.cpp @@ -1,14 +1,17 @@ /*==================================================================================== - EVS Codec 3GPP TS26.442 Apr 03, 2018. Version 12.11.0 / 13.6.0 / 14.2.0 + EVS Codec 3GPP TS26.443 Nov 13, 2018. Version 12.11.0 / 13.7.0 / 14.3.0 / 15.1.0 ====================================================================================*/ +#include #include +#include "cnst.h" +#include "prot.h" +#include "stat_com.h" #include "assert.h" -#include "stl.h" -#include "basop_mpy.h" -#include "cnst_fx.h" -#include "rom_com_fx.h" -#include "prot_fx.h" +#include "basop_util.h" + + + /** * \brief Copy state @@ -18,21 +21,17 @@ * * \return none */ -void ari_copy_states(TastatEnc *source, TastatEnc *dest) +void ari_copy_states(Tastat *source, Tastat *dest) { dest->low = source->low; - move32(); dest->high = source->high; - move32(); dest->vobf = source->vobf; - move16(); } /*--------------------------------------------------------------- Ari encoder 14 bits routines -------------------------------------------------------------*/ - /** * \brief Start ArCo encoding * @@ -40,32 +39,12 @@ void ari_copy_states(TastatEnc *source, TastatEnc *dest) * * \return none */ -void ari_start_encoding_14bits(TastatEnc *s) +void ari_start_encoding_14bits(Tastat *s) { - s->low = L_deposit_l(0); - s->high = ari_q4new + 1; - move32(); + /* : addressing is made with walking pointer s */ + s->low = 0; + s->high = ari_q4new; s->vobf = 0; - move16(); -} - - -/* Returns: new bit-stream position */ -static Word16 ari_put_bit_plus_follow( - Word16 ptr[], /* o: bit-stream */ - Word16 bp, /* i: bit-stream position */ - Word16 bits_to_follow, /* i: number of opposite bits to follow 'bit' */ - Word16 bit /* i: bit to send */ -) -{ - assert(bit == 0 || bit == 1); - ptr[bp++] = bit; /* send initially a zero or one */ move16(); - bit = s_xor(bit, 1); /* invert bit to send */ - FOR ( ; bits_to_follow > 0; bits_to_follow--) - { - ptr[bp++] = bit; /* send inverted bit */ move16(); - } - return bp; } /** @@ -77,19 +56,42 @@ static Word16 ari_put_bit_plus_follow( * * \return bit consumption */ -Word16 ari_done_encoding_14bits(Word16 *ptr, Word16 bp, TastatEnc *s) +long ari_done_encoding_14bits(int *ptr,long bp,Tastat *s) { - Word16 bit; + long low; + long bits_to_follow; - bit = 0; - move16(); - if ( L_sub(s->low,ari_q1new) >= 0 ) + + + + /* not needed, s points to s->low */ + low = s->low; + bits_to_follow = s->vobf+1; + + if ( low < ari_q1new ) { - bit = s_xor(bit,1); + ptr[bp++] = 0; /*send a zero*/ + for(; bits_to_follow>0; bits_to_follow--) + { + ptr[bp++] = 1; /*send a one*/ + } + } + else + { + ptr[bp++] = 1; /*send a one*/ + for(; bits_to_follow>0; bits_to_follow--) + { + ptr[bp++] = 0; /*send a zero*/ + } } - return ari_put_bit_plus_follow(ptr, bp, add(s->vobf, 1), bit); -} + /*It is done so no need to save values-> no counting*/ + /*s->low = low; + s->vobf = bits_to_follow;*/ + + + return bp; +} /** @@ -103,141 +105,70 @@ Word16 ari_done_encoding_14bits(Word16 *ptr, Word16 bp, TastatEnc *s) * * \return bit consumption */ -Word16 ari_encode_14bits_ext( - Word16 *ptr, - Word16 bp, - TastatEnc *s, - Word32 symbol, - UWord16 const *cum_freq -) +long ari_encode_14bits_ext(int *ptr,long bp,Tastat *s,long symbol,const unsigned short *cum_freq) { - Word32 low; - Word32 high; - Word32 range; - Word16 bits_to_follow; - Word16 i; - UWord16 temp; - Word32 L_temp1, L_temp2; + long low, high, range; + long bits_to_follow; - high = L_add(s->high, 0); - low = L_add(s->low, 0); - range = L_sub(high, low); - L_temp1 = L_shl(range,15-stat_bitsnew/*both are constants*/); - Mpy_32_16_ss(L_temp1, cum_freq[symbol+1], &L_temp2, &temp); - if (symbol != 0) /* when symbol is 0, range remains unchanged */ - { - Mpy_32_16_ss(L_temp1, cum_freq[symbol], &range, &temp); - } - high = L_add(low, range); - low = L_add(low, L_temp2); + + /*for all operation using bit_ptr=&ptr[bp] */ + /* for reading s->high,low,vobf sequentially */ + high=s->high; + low =s->low; + range = high-low+1; + + high = low + mul_sbc_14bits(range,cum_freq[symbol]) - 1; + low += mul_sbc_14bits(range,cum_freq[symbol+1]); bits_to_follow = s->vobf; - move16(); - FOR (i = 0; i < 0x7FFF; i++) + for (;;) { - IF (L_sub(high, ari_q2new) <= 0) + if ( high0; bits_to_follow--) + { + ptr[bp++] = 1; /*send a one*/ + } } - ELSE IF (L_sub(low, ari_q2new) >= 0) + else { - bp = ari_put_bit_plus_follow(ptr, bp, bits_to_follow, 1); - bits_to_follow = 0; - move16(); - low = L_sub(low, ari_q2new); - high = L_sub(high, ari_q2new); /* Subtract offset to top. */ - } - ELSE - { - test(); - IF (L_sub(low, ari_q1new) >= 0 && L_sub(high, ari_q3new) <= 0) + if ( low>=ari_q2new ) + { + ptr[bp++] = 1; /*send a one*/ + for(; bits_to_follow>0; bits_to_follow--) + { + ptr[bp++] = 0; /*send a zero*/ + } + low -= ari_q2new; + high -= ari_q2new; /* Subtract offset to top. */ + } + else { /* Output an opposite bit */ - /* later if in middle half. */ - bits_to_follow = add(bits_to_follow, 1); - low = L_sub(low, ari_q1new); /* Subtract offset to middle*/ - high = L_sub(high, ari_q1new); - } - ELSE { - BREAK; /* Otherwise exit loop. */ + if ( low>=ari_q1new && highlow = low; - move32(); s->high = high; - move32(); s->vobf = bits_to_follow; - move16(); - return bp; -} - -Word16 ari_encode_overflow(TastatEnc *s) -{ - return L_sub(L_sub(s->high, 1), s->low) <= 0; -} - - -static Word16 ari_encode_14bits_high_low(Word16 *ptr, Word16 bp, Word16 bits, TastatEnc *s, Word32 high, Word32 low) -{ - Word16 bits_to_follow, tmp; - - bits_to_follow = s->vobf; - move16(); - - /* while there are more than 16 bits left */ - tmp = sub(16, bits); - WHILE (add(add(bp, bits_to_follow), tmp) < 0) - { - IF (L_sub(high, ari_q2new) <= 0) - { - bp = ari_put_bit_plus_follow(ptr, bp, bits_to_follow, 0); - bits_to_follow = 0; - move16(); - } - ELSE IF (L_sub(low, ari_q2new) >= 0) - { - bp = ari_put_bit_plus_follow(ptr, bp, bits_to_follow, 1); - bits_to_follow = 0; - move16(); - low = L_sub(low, ari_q2new); - high = L_sub(high, ari_q2new); /* Subtract offset to top. */ - } - ELSE - { - test(); - IF (L_sub(low, ari_q1new) >= 0 && L_sub(high, ari_q3new) <= 0) - { - /* Output an opposite bit */ - /* later if in middle half. */ - bits_to_follow = add(bits_to_follow, 1); - low = L_sub(low, ari_q1new); /* Subtract offset to middle*/ - high = L_sub(high, ari_q1new); - } - ELSE { - BREAK; /* Otherwise exit loop. */ - } - } - - low = L_add(low, low); - high = L_add(high, high); /* Scale up code range. */ - } - - s->low = low; - move32(); - s->high = high; - move32(); - s->vobf = bits_to_follow; - move16(); return bp; } @@ -248,44 +179,153 @@ static Word16 ari_encode_14bits_high_low(Word16 *ptr, Word16 bp, Word16 bits, Ta * Encode an cumulative frequency interval. *-------------------------------------------------------------------------*/ -Word16 ari_encode_14bits_range(Word16 *ptr, Word16 bp, Word16 bits, TastatEnc *s, Word16 cum_freq_low, Word16 cum_freq_high) +long ari_encode_14bits_range(int *ptr, long bp, long bits, Tastat *s, unsigned short cum_freq_low, unsigned short cum_freq_high) { - Word32 low, high, range; + long low, high, range; + long bits_to_follow; - range = L_sub(s->high, s->low); - high = L_add(s->low, mul_sbc_14bits(range, cum_freq_high)); - low = L_add(s->low, mul_sbc_14bits(range, cum_freq_low)); - return ari_encode_14bits_high_low(ptr, bp, bits, s, high, low); + /* not needed, s points to s->low */ + high = s->high; + high++; + low = s->low; + range = high - low; + + high = low + mul_sbc_14bits(range, cum_freq_high); + low += mul_sbc_14bits(range, cum_freq_low); + + bits_to_follow = s->vobf; + + /* while there are more than 16 bits left */ + for (; bp + 16 + bits_to_follow - bits < 0;) + { + if (high <= ari_q2new) + { + ptr[bp++] = 0; /*send a zero*/ + for (; bits_to_follow > 0; bits_to_follow--) + { + ptr[bp++] = 1; /*send a one*/ + } + } + else if (low >= ari_q2new) + { + /* to reach this branch */ + ptr[bp++] = 1; /*send a one*/ + for (; bits_to_follow > 0; bits_to_follow--) + { + ptr[bp++] = 0; /*send a zero*/ + } + low -= ari_q2new; + high -= ari_q2new; /* Subtract offset to top. */ + } + else if (low >= ari_q1new && high <= ari_q3new) + { + /* to reach this branch */ + /* Output an opposite bit */ + /* later if in middle half. */ + bits_to_follow += 1; + low -= ari_q1new; /* Subtract offset to middle*/ + high -= ari_q1new; + } + else + { + /* to reach this branch */ + break; /* Otherwise exit loop. */ + } + + low += low; + high += high; /* Scale up code range. */ + } + /* if there are <= 16 bits left */ + if (bp + 16 + bits_to_follow - bits >= 0) + { + /* No need to do anyhing, but let's keep a place for a breakpoint */ + s->vobf = -1; + } + + s->low = low; + s->high = high - 1; + s->vobf = bits_to_follow; + + return bp; } - /*------------------------------------------------------------------------ * Function: ari_encode_14bits_sign * * Encode a sign with equal probabilities. *-------------------------------------------------------------------------*/ -Word16 ari_encode_14bits_sign(Word16 *ptr, Word16 bp, Word16 bits, TastatEnc *s, Word16 sign) +long ari_encode_14bits_sign(int *ptr, long bp, long bits, Tastat *s, long sign) { - Word32 low, high, range; - Word32 L_tmp; + long low, high, range; + long bits_to_follow; - high = L_add(s->high, 0); - low = L_add(s->low, 0); - range = L_sub(high, low); - L_tmp = L_shr(range, 1); - if (sign != 0) + + /* not needed, s points to s->low */ + high = s->high; + high++; + low = s->low; + range = high - low; + + if (sign) { - high = L_add(low, L_tmp); + high = low + (range >> 1); } - if (sign == 0) + else { - low = L_add(low, L_tmp); + low += range >> 1; } - return ari_encode_14bits_high_low(ptr, bp, bits, s, high, low); + bits_to_follow = s->vobf; + + /* while there are more than 16 bits left */ + for (; bp + 16 + bits_to_follow - bits < 0;) + { + if (high <= ari_q2new) + { + ptr[bp++] = 0; /*send a zero*/ + for (; bits_to_follow > 0; bits_to_follow--) + { + ptr[bp++] = 1; /*send a one*/ + } + } + else if (low >= ari_q2new) + { + /* to reach this branch */ + ptr[bp++] = 1; /*send a one*/ + for (; bits_to_follow > 0; bits_to_follow--) + { + ptr[bp++] = 0; /*send a zero*/ + } + low -= ari_q2new; + high -= ari_q2new; /* Subtract offset to top. */ + } + else if (low >= ari_q1new && high <= ari_q3new) + { + /* to reach this branch */ + /* Output an opposite bit */ + /* later if in middle half. */ + bits_to_follow += 1; + low -= ari_q1new; /* Subtract offset to middle*/ + high -= ari_q1new; + } + else + { + /* to reach this branch */ + break; /* Otherwise exit loop. */ + } + + low += low; + high += high; /* Scale up code range. */ + } + + s->low = low; + s->high = high - 1; + s->vobf = bits_to_follow; + + return bp; } /*------------------------------------------------------------------------ @@ -293,28 +333,77 @@ Word16 ari_encode_14bits_sign(Word16 *ptr, Word16 bp, Word16 bits, TastatEnc *s, * * Finish up encoding in CBR mode. *-------------------------------------------------------------------------*/ -Word16 ari_done_cbr_encoding_14bits(Word16 *ptr, Word16 bp, Word16 bits, TastatEnc *s) +long ari_done_cbr_encoding_14bits(int *ptr, long bp, long bits, Tastat *s) { - Word16 high, tmp, k; - tmp = sub(bits, 16); - WHILE (sub(sub(tmp, bp), s->vobf) > 0) + long high; + long bits_to_follow; + int k; + + + while (bits - bp - 16 - s->vobf > 0) { bp = ari_encode_14bits_sign(ptr, bp, bits, s, 0); } - high = extract_l(L_sub(s->high, 1)); + /* not needed, s points to s->low */ + high = s->high; + bits_to_follow = s->vobf; - bp = ari_put_bit_plus_follow(ptr, bp, s->vobf, lshr(high, 15)); - high = lshl(high, 1); - - tmp = s_min(15, sub(bits, bp)); - FOR (k=0; k 0; bits_to_follow--) + { + ptr[bp++] = 1; /*send a one*/ + } + } + else + { + ptr[bp++] = 1; /*send a one*/ + for (; bits_to_follow > 0; bits_to_follow--) + { + ptr[bp++] = 0; /*send a zero*/ + } + } + /* write remaining bits */ + for (k = 0x4000; k > 0; k >>= 1) + { + if (k & high) + { + ptr[bp++] = 1; /*send a one*/ + } + else + { + ptr[bp++] = 0; /*send a zero*/ + } + if (bp >= bits) + break; + } + } + else + { + /* no carry-bits, just write all bits */ + for (k = 0x8000; k > 0; k >>= 1) + { + if (k & high) + { + ptr[bp++] = 1; /*send a one*/ + } + else + { + ptr[bp++] = 0; /*send a zero*/ + } + if (bp >= bits) + break; + } + + } + return bp; } diff --git a/src/libs/libevs/lib_enc/ari_hm_enc.cpp b/src/libs/libevs/lib_enc/ari_hm_enc.cpp old mode 100755 new mode 100644 index 84fe11e0..6d58d2ca --- a/src/libs/libevs/lib_enc/ari_hm_enc.cpp +++ b/src/libs/libevs/lib_enc/ari_hm_enc.cpp @@ -1,799 +1,589 @@ /*==================================================================================== - EVS Codec 3GPP TS26.442 Apr 03, 2018. Version 12.11.0 / 13.6.0 / 14.2.0 + EVS Codec 3GPP TS26.443 Nov 13, 2018. Version 12.11.0 / 13.7.0 / 14.3.0 / 15.1.0 ====================================================================================*/ - -#include -#include -#include -#include +#include "cnst.h" +#include "rom_enc.h" #include "stl.h" -#include "cnst_fx.h" #include "basop_util.h" -#include "rom_com_fx.h" -#include "rom_enc_fx.h" -#include "prot_fx.h" +#include +#include +#include "prot.h" +#include "rom_com.h" -Word16 EncodeIndex( - Word16 Bandwidth, - Word16 PeriodicityIndex, - Encoder_State_fx *st + +/*-------------------------------------------------------------------* + * EncodeIndex() + * + * + *-------------------------------------------------------------------*/ + +int EncodeIndex( + int Bandwidth, + int PeriodicityIndex, + Encoder_State *st ) { - Word16 NumRatioBitsBwLtpIndx; - IF ( s_and(PeriodicityIndex, kLtpHmFlag) != 0 ) + if (PeriodicityIndex & kLtpHmFlag) { - Word16 LtpPitchIndex = shr(PeriodicityIndex, 9); + int LtpPitchIndex = PeriodicityIndex >> 9; assert(0 <= LtpPitchIndex && LtpPitchIndex <= 16); - - PeriodicityIndex = sub(PeriodicityIndex, 1); + --PeriodicityIndex; assert((PeriodicityIndex & 0xff) < (1 << NumRatioBits[Bandwidth][LtpPitchIndex])); - NumRatioBitsBwLtpIndx = NumRatioBits[Bandwidth][LtpPitchIndex]; - move16(); - - push_next_indice_fx(st, s_and(PeriodicityIndex, 0xff), NumRatioBitsBwLtpIndx); - return NumRatioBitsBwLtpIndx; + push_next_indice(st, PeriodicityIndex & 0xff, NumRatioBits[Bandwidth][LtpPitchIndex]); + return NumRatioBits[Bandwidth][LtpPitchIndex]; } - ELSE + else { - push_next_indice_fx(st, PeriodicityIndex, 8); + push_next_indice(st, PeriodicityIndex, 8); return 8; } } -static Word16 SearchPeriodicityIndex_Single( - const Word16 AbsMdct3[], - Word16 NumToConsider, - Word32 Lag, - Word16 FractionalResolution + +/*-------------------------------------------------------------------* + * GetWeight() + * + * + *-------------------------------------------------------------------*/ + +static float GetWeight(int i) +{ + i = 3 * i - 2; + + return (float)(pow(i, 0.3) / pow(256 - 1, 0.3)); +} + + +/*-------------------------------------------------------------------* + * SearchPeriodicityIndex_Single() + * + * + *-------------------------------------------------------------------*/ + +static float SearchPeriodicityIndex_Single( + const float AbsMdct3[], + int NumToConsider, + int Lag, + int FractionalResolution ) { - Word16 HighestMultiplier; - Word32 AbsMeanCurrent3; /* Mean for BucketWidth == 3 */ - Word32 Limit, OldIndex, i; - Word16 Result, tmp1, tmp2; + int HighestMultiplier; + float AbsMeanCurrent3; /* Mean for BucketWidth == 3 */ + int Limit; + int OldIndex, i; + Limit = (NumToConsider - 1) << FractionalResolution; + AbsMeanCurrent3 = 0; + HighestMultiplier = 1; - Limit = L_deposit_l(sub(NumToConsider, 1)); - Limit = L_shl(Limit, FractionalResolution); - AbsMeanCurrent3 = L_deposit_l(0); - HighestMultiplier = 0; - move16(); - - FOR (i=Lag; i> FractionalResolution; + AbsMeanCurrent3 += AbsMdct3[OldIndex] * GetWeight(HighestMultiplier); + ++HighestMultiplier; } - tmp1 = sub(norm_l(AbsMeanCurrent3), 1); - tmp2 = norm_s(HighestMultiplier); - Result = div_s( round_fx(L_shl(AbsMeanCurrent3, tmp1)), s_max(shl(HighestMultiplier, tmp2), 0x4000) ); - if (HighestMultiplier == 0) - { - tmp2 = 14 + 16; - move16(); - } - Result = shr(Result, s_min(15, sub(sub(tmp1, tmp2), 7-15))); - - return Result; + return AbsMeanCurrent3 / (HighestMultiplier - 1 + 0.00001f); } + +/*-------------------------------------------------------------------* + * SearchPeriodicityIndex_Range() + * + * + *-------------------------------------------------------------------*/ + static void SearchPeriodicityIndex_Range( - const Word16 AbsMdct3[], - Word16 NumToConsider, - Word16 Lo, - Word16 Hi, - Word16 FractionalResolution, - Word16 Adj, - Word16 Spacing, - Word16 *PeriodicityIndex, - Word16 *Score + const float AbsMdct3[], + int NumToConsider, + int Lo, + int Hi, + int FractionalResolution, + int Adj, + int Spacing, + int *PeriodicityIndex, + float *Score ) { - Word16 Index, BestIndex; - Word16 CurrentScore, BestScore; - Word16 B; + int Index, BestIndex; + float CurrentScore, BestScore; + int B; - BestScore = -1; - move16(); + BestScore = -1e30f; BestIndex = 0; - move16(); - FOR (Index = Lo; Index < Hi; Index += Spacing) + for (Index = Lo; Index < Hi; Index += Spacing) { - CurrentScore = SearchPeriodicityIndex_Single( - AbsMdct3, - NumToConsider, - add(Index, Adj), - FractionalResolution - ); + CurrentScore = SearchPeriodicityIndex_Single( AbsMdct3, NumToConsider, Index + Adj, FractionalResolution ); - if (sub(CurrentScore, BestScore) > 0) + if (CurrentScore > BestScore) { + BestScore = CurrentScore; BestIndex = Index; - move16(); } - BestScore = s_max(BestScore, CurrentScore); } - if (sub(BestScore, *Score) > 0) + if (BestScore > *Score) { + *Score = BestScore; *PeriodicityIndex = BestIndex; - move16(); } - BestScore = s_max(BestScore, *Score); - B = sub(BestIndex, shr(Spacing, 1)); - B = s_max(Lo, B); - FOR (Index = B; Index < BestIndex; ++Index) + B = BestIndex - (Spacing >> 1); + B = max(Lo, B); + + for (Index = B; Index < BestIndex; ++Index) { - CurrentScore = SearchPeriodicityIndex_Single( - AbsMdct3, - NumToConsider, - add(Index, Adj), - FractionalResolution - ); + CurrentScore = SearchPeriodicityIndex_Single( AbsMdct3, NumToConsider, Index + Adj, FractionalResolution ); - if (sub(CurrentScore, BestScore) > 0) + if (CurrentScore > *Score) { + *Score = CurrentScore; *PeriodicityIndex = Index; - move16(); } - BestScore = s_max(BestScore, CurrentScore); } - B = add(BestIndex, shr(Spacing, 1)); + B = BestIndex + (Spacing >> 1); - FOR (Index = add(BestIndex, 1); Index <= B; ++Index) + for (Index = BestIndex + 1; Index <= B; ++Index) { - CurrentScore = SearchPeriodicityIndex_Single( - AbsMdct3, - NumToConsider, - add(Index, Adj), - FractionalResolution - ); + CurrentScore = SearchPeriodicityIndex_Single( AbsMdct3, NumToConsider, Index + Adj, FractionalResolution ); - if (sub(CurrentScore, BestScore) > 0) + if (CurrentScore > *Score) { + *Score = CurrentScore; *PeriodicityIndex = Index; - move16(); } - BestScore = s_max(BestScore, CurrentScore); } - *Score = BestScore; - move16(); + return; } + +/*-------------------------------------------------------------------* + * UnmapIndex() + * + * + *-------------------------------------------------------------------*/ + /* Returns: PeriodicityIndex */ -Word16 SearchPeriodicityIndex( - const Word32 Mdct[], /* (I) Coefficients, Mdct[0..NumCoeffs-1] */ - const Word32 UnfilteredMdct[], /* (I) Unfiltered coefficients, UnfilteredMdct[0..NumCoeffs-1] */ - Word16 NumToConsider, /* (I) Number of coefficients */ - Word16 TargetBits, /* (I) Target bit budget (excl. Done flag) */ - Word16 LtpPitchLag, - Word16 LtpGain, /* (I) LTP gain */ - Word16 *RelativeScore /* (O) Energy concentration factor (2Q13) */ +int SearchPeriodicityIndex( + const float Mdct[], /* (I) Coefficients, Mdct[0..NumCoeffs-1] */ + const float UnfilteredMdct[], /* (I) Unfiltered coefficients, UnfilteredMdct[0..NumCoeffs-1] */ + int NumCoeffs, /* (I) Number of coefficients */ + int TargetBits, /* (I) Target bit budget (excl. Done flag) */ + short LtpPitchLag, + float LtpGain, /* (I) LTP gain */ + float *RelativeScore /* (O) Energy concentration factor */ ) { - Word16 AbsMdct3[MAX_LENGTH]; - Word32 A, B, C; - Word16 i; - Word16 MaxAt; - Word16 Score, CurrentScore; - Word16 PeriodicityIndex; - Word32 AbsTotal; /* 16Q15 */ - Word16 Multiplier; - Word16 LtpPitchIndex; - Word8 Bandwidth; - Word32 Lag; - Word16 s, tmp, tmp2, tmp3; - Word32 tmp32; + float AbsMdct3[MAX_LENGTH], A, B, C=0.f; + int i; + int MaxAt; + float Score; + int PeriodicityIndex = 0; + int NumToConsider = NumCoeffs; + float AbsTotal; - /* Debug init (not instrumented) */ - C = -3000; - PeriodicityIndex = 0; - move16(); - Score = -1; - move16(); + Score = -1e30f; - s = sub(Find_Max_Norm32(Mdct, NumToConsider), 2); + A = (float)fabs(Mdct[0]); + B = (float)fabs(Mdct[1]); - A = L_shl(L_abs(Mdct[0]), s); - B = L_shl(L_abs(Mdct[1]), s); - - tmp = sub(NumToConsider, 3); - FOR (i = 1; i < tmp; i += 3) + for (i = 1; i < NumToConsider - 3; i += 3) { - C = L_shl(L_abs(Mdct[i + 1]), s); - AbsMdct3[i] = round_fx(L_add(L_add(A, B), C)); + C = (float)fabs(Mdct[i + 1]); + AbsMdct3[i] = A + B + C; - A = L_shl(L_abs(Mdct[i + 2]), s); - AbsMdct3[i + 1] = round_fx(L_add(L_add(A, B), C)); + A = (float)fabs(Mdct[i + 2]); + AbsMdct3[i + 1] = A + B + C; - B = L_shl(L_abs(Mdct[i + 3]), s); - AbsMdct3[i + 2] = round_fx(L_add(L_add(A, B), C)); + B = (float)fabs(Mdct[i + 3]); + AbsMdct3[i + 2] = A + B + C; } - IF (sub(i, sub(NumToConsider, 1)) < 0) + if (i < NumToConsider - 1) { - C = L_shl(L_abs(Mdct[i + 1]), s); - AbsMdct3[i] = round_fx(L_add(L_add(A, B), C)); + C = (float)fabs(Mdct[i + 1]); + AbsMdct3[i] = A + B + C; } - IF (sub(i, sub(NumToConsider, 2)) < 0) + + if (i + 1 < NumToConsider - 1) { - A = L_shl(L_abs(Mdct[i + 2]), s); - assert(C != -3000); - AbsMdct3[i + 1] = round_fx(L_add(L_add(A, B), C)); + A = (float)fabs(Mdct[i + 2]); + AbsMdct3[i + 1] = A + B + C; } - AbsTotal = L_deposit_l(0); - IF (UnfilteredMdct != NULL) + AbsTotal = 0.0f; + + if (UnfilteredMdct != NULL) { - FOR (i = 0; i < NumToConsider; ++i) + for (i = 0; i < NumToConsider; ++i) { - AbsTotal = L_add(AbsTotal, L_shr(L_abs(UnfilteredMdct[i]), 16)); + AbsTotal += (float)fabs(UnfilteredMdct[i]); } - /* balance difference between filtered and unfiltered mdct samples */ - AbsTotal = L_shr(AbsTotal, sub(4, s)); } - ELSE + else { - tmp = sub(NumToConsider, 1); - FOR (i = 1; i < tmp; i += 3) + for (i = 1; i < NumToConsider - 1; i += 3) { - AbsTotal = L_mac0(AbsTotal, AbsMdct3[i], 1); + AbsTotal += AbsMdct3[i]; } } - test(); - IF ((LtpPitchLag > 0) && (sub(LtpGain, kLtpHmGainThr) > 0)) - { - Bandwidth = 0; - move16(); - if (sub(NumToConsider, 256) >= 0) - { - Bandwidth = 1; - move16(); - } - LtpPitchIndex = sub(mult_r(LtpPitchLag, 1 << (15-kLtpHmFractionalResolution)), 2); + if ((LtpPitchLag > 0) && (LtpGain > kLtpHmGainThr)) + { + int FractionalResolution = kLtpHmFractionalResolution; + int Multiplier; + int LtpPitchIndex; + int Bandwidth; + + Bandwidth = NumCoeffs >= 256; + LtpPitchIndex = ((LtpPitchLag + (1 << (kLtpHmFractionalResolution - 1))) >> kLtpHmFractionalResolution) - 2; assert(0 <= LtpPitchIndex && LtpPitchIndex <= 16); - tmp32 = L_shl(L_deposit_l(sub(NumToConsider, 2)), kLtpHmFractionalResolution); - tmp = shl(1, NumRatioBits[Bandwidth][LtpPitchIndex]); - FOR (Multiplier = 1; Multiplier <= tmp; ++Multiplier) + for (Multiplier = 1; Multiplier <= (1 << NumRatioBits[Bandwidth][LtpPitchIndex]); ++Multiplier) { - Lag = L_shr(L_mult0(LtpPitchLag, Ratios[Bandwidth][LtpPitchIndex][Multiplier-1]), 8); + float CurrentScore; + int Lag; - test(); - IF ((L_sub(Lag, 4<= 0) && (L_sub(Lag, tmp32) <= 0)) + Lag = (LtpPitchLag * (int)(4 * Ratios[Bandwidth][LtpPitchIndex][Multiplier-1])) >> 2; + + if (Lag >= (4 << FractionalResolution) && (Lag <= ((NumToConsider-2) << FractionalResolution))) { - CurrentScore = SearchPeriodicityIndex_Single( - AbsMdct3, - NumToConsider, - Lag, - kLtpHmFractionalResolution - ); + CurrentScore = SearchPeriodicityIndex_Single( AbsMdct3, NumToConsider, Lag, FractionalResolution ); - if (sub(CurrentScore, Score) > 0) + if (CurrentScore > Score) { - PeriodicityIndex = s_or(Multiplier, kLtpHmFlag); + Score = CurrentScore; + PeriodicityIndex = Multiplier | kLtpHmFlag; } - Score = s_max(Score, CurrentScore); } } - PeriodicityIndex = s_or(PeriodicityIndex, shl(LtpPitchIndex, 9)); + PeriodicityIndex |= LtpPitchIndex << 9; } - ELSE + else { - IF (UnfilteredMdct != NULL) + if (UnfilteredMdct != NULL) { MaxAt = 1; - move16(); - A = L_shr(AbsMdct3[1], 6); + A = AbsMdct3[1]; - FOR (i = 4; i < NumToConsider - 1; i += 3) + for (i = 4; i < NumToConsider - 1; i += 3) { - if (L_sub(AbsMdct3[i], AbsMdct3[MaxAt]) > 0) + + if (AbsMdct3[i] > AbsMdct3[MaxAt]) { MaxAt = i; - move16(); } - A = L_add(A, L_shr(AbsMdct3[i], 6)); + A += AbsMdct3[i]; } - if (L_sub(L_shr(AbsMdct3[MaxAt], 6), Mpy_32_16_1(A, 22938/*0.7 Q15*/)) > 0) + if (AbsMdct3[MaxAt] > A * 0.7f) { - NumToConsider = s_min( NumToConsider, add(MaxAt, 4) ); + NumToConsider = min(NumToConsider, MaxAt + 4); } } - SearchPeriodicityIndex_Range( - AbsMdct3, - NumToConsider, - 0, 16, - 3, - GET_ADJ2(0, 6, 3), - 4, - &PeriodicityIndex, - &Score - ); + SearchPeriodicityIndex_Range( AbsMdct3, NumToConsider, 0, 16, 3, GET_ADJ2(0, 6, 3), 4, &PeriodicityIndex, &Score ); - SearchPeriodicityIndex_Range( - AbsMdct3, - NumToConsider, - 16, 80, - 4, - GET_ADJ2(16, 8, 4), - 4, - &PeriodicityIndex, - &Score - ); + SearchPeriodicityIndex_Range( AbsMdct3, NumToConsider, 16, 80, 4, GET_ADJ2(16, 8, 4), 4, &PeriodicityIndex, &Score ); - SearchPeriodicityIndex_Range( - AbsMdct3, - NumToConsider, - 80, 208, - 3, - GET_ADJ2(80, 12, 3), - 4, - &PeriodicityIndex, - &Score - ); + SearchPeriodicityIndex_Range( AbsMdct3, NumToConsider, 80, 208, 3, GET_ADJ2(80, 12, 3), 4, &PeriodicityIndex, &Score ); - IF (sub(NumToConsider, 128) <= 0) /* no long lags for band-limited MDCTs */ + if (NumToConsider <= 128) { - SearchPeriodicityIndex_Range( - AbsMdct3, - NumToConsider, - 208, add(88, NumToConsider), - 0, - GET_ADJ2(224, 188, 0), - 1, - &PeriodicityIndex, - &Score - ); + /* no long lags for band-limited MDCTs */ + + SearchPeriodicityIndex_Range( AbsMdct3, NumToConsider, 208, 88 + NumToConsider, 0, GET_ADJ2(224, 188, 0), 1, &PeriodicityIndex, &Score ); } - ELSE { - test(); - IF (sub(TargetBits, kSmallerLagsTargetBitsThreshold) > 0 && sub(NumToConsider, 256) >= 0) + else + { + + if (TargetBits > kSmallerLagsTargetBitsThreshold && NumCoeffs >= 256) { - SearchPeriodicityIndex_Range( - AbsMdct3, - NumToConsider, - 208, 224, - 1, - GET_ADJ2(208, 28, 1), - 1, - &PeriodicityIndex, - &Score - ); - SearchPeriodicityIndex_Range( - AbsMdct3, - NumToConsider, - 224, 256, - 0, - GET_ADJ2(224, 188, 0), - 1, - &PeriodicityIndex, - &Score - ); + SearchPeriodicityIndex_Range( AbsMdct3, NumToConsider, 208, 224, 1, GET_ADJ2(208, 28, 1), 1, &PeriodicityIndex, &Score ); + + SearchPeriodicityIndex_Range( AbsMdct3, NumToConsider, 224, 256, 0, GET_ADJ2(224, 188, 0 ), 1, &PeriodicityIndex, &Score ); } - ELSE { - SearchPeriodicityIndex_Range( - AbsMdct3, - NumToConsider, - 208, 256, - 1, - GET_ADJ2(208, 28, 1), - 1, - &PeriodicityIndex, - &Score - ); + else + { + SearchPeriodicityIndex_Range( AbsMdct3, NumToConsider, 208, 256, 1, GET_ADJ2(208, 28, 1), 1, &PeriodicityIndex, &Score ); } } } - IF (AbsTotal > 0) + if (AbsTotal > 0) { - tmp32 = L_mult0(Score, NumToConsider); /* -> 16Q15 */ - tmp = sub(norm_l(tmp32), 1); - tmp2 = norm_l(AbsTotal); - tmp3 = div_s( round_fx(L_shl(tmp32, tmp)), round_fx(L_shl(AbsTotal, tmp2)) ); - BASOP_SATURATE_WARNING_OFF - *RelativeScore = shr(tmp3, add(sub(tmp, tmp2), 2)); /* -> 2Q13 */ move16(); - BASOP_SATURATE_WARNING_ON + *RelativeScore = Score/AbsTotal*(float)NumCoeffs; } - ELSE + else { *RelativeScore = 0; - move16(); } + return PeriodicityIndex; } + +/*-------------------------------------------------------------------* + * PeakFilter() + * + * + *-------------------------------------------------------------------*/ + +#define kPeakElevationThreshold 1.0f + static void PeakFilter( - const Word32 x[], /* (I) absolute spectrum */ - Word32 y[], /* (O) filtered absolute spectrum, must not alias x[] */ - Word16 L_frame /* (I) number of spectral lines */ + const float x[], /* (I) absolute spectrum */ + float y[], /* (O) filtered absolute spectrum, must not alias x[] */ + int L_frame /* (I) number of spectral lines */ ) { - Word16 flen, i; -#define kPeakElevationThreshold 1.0f - Word16 m; - Word32 a; + int flen, i; + float a, m; - flen = shr(L_frame, 4); - /* m = kPeakElevationThreshold / (float)(2*flen + 1); */ - m = shr(div_s(8/*kPeakElevationThreshold Q3*/, add(shl(flen,1), 1)), 3); + flen = (L_frame >> 4); + m = kPeakElevationThreshold / (float)(2*flen + 1); - a = L_deposit_l(0); - FOR (i=0; i= 0) - { - bw_flag = 1; - move16(); - } - - /* Bit consumption for the HM off case: 1 bit flag */ - hm_bits = 1; - move16(); - move16(); - prm_hm[1] = tcx_hm_search( - abs_spectrum, - L_frame, - sub(targetBits, hm_bits), - LtpPitchLag, - LtpGain, - &RelativeScore - ); + prm_hm[1] = SearchPeriodicityIndex( fspec, abs_spectrum, L_frame, targetBits - *hm_bits, LtpPitchLag, LtpGain, &RelativeScore ); /* Convert the index to lag */ - UnmapIndex( - prm_hm[1], - bw_flag, - LtpPitchLag, - (( sub(sub(targetBits, hm_bits),kSmallerLagsTargetBitsThreshold) <= 0 ) || !bw_flag), - &fract_res, - &lag - ); - test(); + UnmapIndex( prm_hm[1], L_frame >= 256, LtpPitchLag, (targetBits - *hm_bits <= kSmallerLagsTargetBitsThreshold) || (L_frame < 256), &fract_res, &lag ); /* Render harmonic model */ - tcx_hm_render( - lag, - fract_res, - p - ); + tcx_hm_render( lag, fract_res, LtpGain, p ); /* Calculate and quantize gain */ gain = 0; - move16(); - tcx_hm_quantize_gain( - abs_spectrum, - spectrum_e, - env, - lag, - fract_res, - p, - L_frame, - coder_type, - RelativeScore, - &prm_hm[2], - &gain - ); + tcx_hm_quantize_gain( abs_spectrum, env, lag, fract_res, p, L_frame, coder_type, RelativeScore, &prm_hm[2], &gain ); /* Decision */ - IF ( gain > 0 ) + if (gain > 0) { - prm_hm[0] = 1; /* flag: on */ move16(); + prm_hm[0] = 1; /* flag: on */ - hm_bits = add(hm_bits, CountIndexBits(bw_flag, prm_hm[1])); + *hm_bits += CountIndexBits( L_frame >= 256, prm_hm[1] ); - if (sub(coder_type, VOICED) == 0) + if (coder_type == VOICED) { - hm_bits = add(hm_bits, kTcxHmNumGainBits); + *hm_bits += kTcxHmNumGainBits; } - tcx_hm_modify_envelope( - gain, - lag, - fract_res, - p, - env, - L_frame - ); + tcx_hm_modify_envelope( gain, lag, fract_res, p, env, L_frame ); } - ELSE + else { - prm_hm[0] = 0; /* flag: off */ move16(); - prm_hm[1] = -1; /* pitch index */ move16(); - prm_hm[2] = 0; /* gain index */ move16(); + prm_hm[0] = 0; /* flag: off */ + prm_hm[1] = -1; /* pitch index */ + prm_hm[2] = 0; /* gain index */ } - *hm_bits_out = hm_bits; - move16(); + return; } - diff --git a/src/libs/libevs/lib_enc/arith_coder_enc.cpp b/src/libs/libevs/lib_enc/arith_coder_enc.cpp old mode 100755 new mode 100644 index a6e55476..b09c81d9 --- a/src/libs/libevs/lib_enc/arith_coder_enc.cpp +++ b/src/libs/libevs/lib_enc/arith_coder_enc.cpp @@ -1,814 +1,625 @@ /*==================================================================================== - EVS Codec 3GPP TS26.442 Apr 03, 2018. Version 12.11.0 / 13.6.0 / 14.2.0 + EVS Codec 3GPP TS26.443 Nov 13, 2018. Version 12.11.0 / 13.7.0 / 14.3.0 / 15.1.0 ====================================================================================*/ +#include #include #include #include #include - #include "options.h" -#include "cnst_fx.h" -#include "prot_fx.h" +#include "cnst.h" +#include "prot.h" +#include "rom_com.h" #include "basop_util.h" -#include "rom_com_fx.h" -#include "stl.h" - -/* Returns: estimated SQ scale Q15-e */ -static Word16 tcx_arith_estimate_scale( - const Word32 abs_spectrum[], /* i: absolute MDCT coefficients Q31-e */ - Word16 abs_spectrum_e, /* i: MDCT exponent Q0 */ - Word16 L_frame, /* i: number of spectral lines Q0 */ - const Word16 envelope[], /* i: scaled envelope Q15-e */ - Word16 envelope_e, /* i: scaled envelope exponent Q0 */ - Word16 *scale_e /* o: scale exponent Q0 */ -) -{ - Word16 scale, tmp, k, s, s1; - Word32 L_tmp, accu; +#include "basop_proto_func.h" +/*-------------------------------------------------------------------* + * Local constants + *-------------------------------------------------------------------*/ - /* compute normalised standard deviation and determine approximate scale */ - accu = L_deposit_l(0); - s = 30; - move16(); - - FOR (k = 0; k < L_frame; k++) - { - /* tmp = abs_spectrum[k] * envelope[k]; - scale += tmp * tmp; */ - - /* normalize, multiply, square */ - s1 = 30; - move16(); - if (abs_spectrum[k] != 0) - { - s1 = norm_l(abs_spectrum[k]); - } - - tmp = mult_r(round_fx(L_shl(abs_spectrum[k], s1)), envelope[k]); - L_tmp = L_mult0(tmp, tmp); - tmp = sub(shl(s1, 1), 1); - - /* adjust accu scaling */ - s1 = s; - move16(); - if (L_and(accu, 0x40000000) != 0) s = sub(s, 1); - s = s_min(s, tmp); - - s1 = sub(s1, s); - if (s1 != 0) accu = L_shr(accu, s1); - - /* scale and accumulate */ - BASOP_SATURATE_WARNING_OFF; - accu = L_add(accu, L_shr(L_tmp, sub(tmp, s))); - BASOP_SATURATE_WARNING_ON; - } - s = sub(shl(add(abs_spectrum_e, envelope_e), 1), s); - if (accu == 0) accu = L_deposit_l(1); - - /* scale = (float)sqrt((L_frame * 65536.0f*65536.0f*4.0f) / scale); */ - scale = BASOP_Util_Divide3216_Scale(accu, shl(L_frame, 2), &tmp); - s = sub(add(s, tmp), 15); - scale = ISqrt16(scale, &s); - *scale_e = s; - - - return scale; -} +#define LOG2_E 1.44269504089f #define kMaxNumHeapElems 10 typedef struct HeapElem { - Word32 mScore; /* Sort key */ - Word16 mIndex; /* Original index */ + float mScore; /* Sort key */ + int mIndex; /* Original index */ } HeapElem; typedef struct Heap { HeapElem mElem[2*kMaxNumHeapElems+1]; - Word16 mSize; + int mSize; } Heap; -static void MinHeapify_i(Heap *H, Word16 i) -{ - Word16 left, right, largest; - HeapElem T; +/*-------------------------------------------------------------------* + * tcx_arith_estimate_scale() + * + * + *-------------------------------------------------------------------*/ - - left = add(shl(i, 1), 1); - right = add(left, 1); - largest = i; - move16(); - - if (L_sub(H->mElem[left].mScore, H->mElem[largest].mScore) < 0) - { - largest = left; - move16(); - } - - if (L_sub(H->mElem[right].mScore, H->mElem[largest].mScore) < 0) - { - largest = right; - move16(); - } - - WHILE (sub(largest, i) != 0) - { - T.mIndex = H->mElem[i].mIndex; - move16(); - T.mScore = L_add(H->mElem[i].mScore, 0); - - H->mElem[i].mIndex = H->mElem[largest].mIndex; - move16(); - H->mElem[i].mScore = H->mElem[largest].mScore; - move32(); - - H->mElem[largest].mIndex = T.mIndex; - move16(); - H->mElem[largest].mScore = T.mScore; - move32(); - - i = largest; - move16(); - - left = add(shl(i, 1), 1); - right = add(left, 1); - - if (L_sub(H->mElem[left].mScore, H->mElem[largest].mScore) < 0) - { - largest = left; - move16(); - } - - if (L_sub(H->mElem[right].mScore, H->mElem[largest].mScore) < 0) - { - largest = right; - move16(); - } - } - -} - -static Word16 tcx_arith_find_max_scale( /* Q15-e */ - const Word32 abs_spectrum[], /* i: absolute MDCT coefficients Q31-e */ - Word16 abs_spectrum_e, /* i: MDCT exponent Q0 */ - Word16 L_frame, /* i: number of spectral lines Q0 */ - const Word16 envelope[], /* i: scaled envelope Q15-e */ - Word16 envelope_e, /* i: scaled envelope exponent Q0 */ - const Word16 exps[], /* i: expfp(-(int)envelope[]/2) Q15 */ - Word16 deadzone, /* i: deadzone (0.5f = no deadzone) Q15 */ - Word16 *scale_e /* o: scale exponent Q0 */ +static float tcx_arith_estimate_scale( /* o: estimated SQ scale */ + const float abs_spectrum[], /* i: absolute MDCT coefficients */ + int L_frame, /* i: number of spectral lines */ + const Word16 envelope[], /* i: scaled envelope (Q15-e) */ + Word16 envelope_e /* i: scaled envelope exponent (Q0) */ ) { - Word16 i, k, q, scale, tmp, s; - Word32 p, L_tmp; - Heap heap = {{{0,0}},0}; /* silence a compiler warning */ + float scale, tmp; + int k; + + /* compute normalised standard deviation and determine approximate scale */ + scale = 0.01f; + for (k = 0; k < L_frame; k++) + { + tmp = abs_spectrum[k] * envelope[k]; + scale += tmp * tmp; + } + tmp = (float)(1 << (15-envelope_e)); + scale = (float)sqrt((L_frame * tmp*tmp*4.0f) / scale); + + + return scale; +} + + +/*-------------------------------------------------------------------* + * MinHeapify_i() + * + * + *-------------------------------------------------------------------*/ + +static void MinHeapify_i(Heap *H, int i) +{ + int left, right, largest; + HeapElem T; + + left = 2*i + 1; + right = left + 1; + largest = i; + + if (H->mElem[left].mScore < H->mElem[largest].mScore) + { + largest = left; + } + if (H->mElem[right].mScore < H->mElem[largest].mScore) + { + largest = right; + } + while (largest != i) + { + T.mIndex = H->mElem[i].mIndex; + T.mScore = H->mElem[i].mScore; + + H->mElem[i].mIndex = H->mElem[largest].mIndex; + H->mElem[i].mScore = H->mElem[largest].mScore; + + H->mElem[largest].mIndex = T.mIndex; + H->mElem[largest].mScore = T.mScore; + + i = largest; + + left = 2*i + 1; + right = left + 1; + + if (H->mElem[left].mScore < H->mElem[largest].mScore) + { + largest = left; + } + if (H->mElem[right].mScore < H->mElem[largest].mScore) + { + largest = right; + } + } + + return; +} + + +/*-------------------------------------------------------------------* + * tcx_arith_find_max_scale() + * + * + *-------------------------------------------------------------------*/ + +static float tcx_arith_find_max_scale( + const float abs_spectrum[], /* i: absolute MDCT coefficients */ + int L_frame, /* i: number of spectral lines */ + const Word16 envelope[], /* i: scaled envelope (Q15-e) */ + Word16 envelope_e, /* i: scaled envelope exponent (Q0) */ + const Word16 exps[], /* i: expfp(-(int)envelope[]/2) */ + float deadzone /* i: deadzone (0.5f = no deadzone) */ +) +{ + int i, k, q; + float p, scale; + Heap heap; Word16 tmpi1, tmpi2; - const Word32 limit = -325614240l/*-9.70406052784f Q25*/; /* = ln(1/16384): log of smallest allowed probability */ - - + float envelope_scale; + const float limit = -9.70406052784f; /* = ln(1/16384): log of smallest allowed probability */ /* Find the top most offending lines according to probability estimates */ heap.mSize = kMaxNumHeapElems; - move16(); + heap.mElem[0].mScore = 0; /* mal: just to silnce the compiler */ - FOR (i = 0; i < heap.mSize; i++) + for (i=0; i 0) + p = envelope[k] * abs_spectrum[k]; + if (p > heap.mElem[0].mScore) { heap.mElem[0].mScore = p; - move32(); heap.mElem[0].mIndex = k; - move16(); MinHeapify_i(&heap, 0); } } /* Make sure the scale is limited so that the offending lines don't cause probability underflow. */ /* Also limit scale to avoiding saturation of the gain quantizer */ - /* scale = 1.0f/(float)sqrt(L_frame*0.5f); */ - tmp = 15-1; - move16(); - scale = ISqrt16(L_frame, &tmp); - *scale_e = tmp; - move16(); - - FOR (i = 0; i < heap.mSize; i++) + scale = 1.0f/(float)sqrt(L_frame*0.5f); + envelope_scale = -(float)pow(2, envelope_e-16); + for (i=0; i 1/log2(e) */ - L_tmp = L_sub(limit, L_tmp); - tmp = negate(BASOP_Util_Divide3216_Scale(L_tmp, envelope[k], &s)); - s = sub(add(s, 6), sub(envelope_e, 1)); - L_tmp = L_shl(L_deposit_h(tmp), sub(s, 15+1)); /* Q16 */ - L_tmp = L_sub(L_tmp, 0x8000); - q = extract_h(L_add(L_tmp, 0xFFFF)); /* ceil */ + q = (int)ceil(((limit - log(1.0f - (exps[k]/32768.0) * (exps[k]/32768.0))) / (envelope[k]*envelope_scale) - 1) / 2.0f); /* Refinement: get the exact q */ powfp_odd2(exps[k], q, &tmpi1, &tmpi2); - - IF (sub(sub(tmpi1, tmpi2), 2) >= 0) /* q may be too low */ + if (tmpi1 - tmpi2 >= 2) { - powfp_odd2(exps[k], add(q, 1), &tmpi1, &tmpi2); - - WHILE (sub(sub(tmpi1, tmpi2), 2) >= 0) + /* q may be too low */ + powfp_odd2(exps[k], q+1, &tmpi1, &tmpi2); + while (tmpi1 - tmpi2 >= 2) { - q = add(q, 1); - powfp_odd2(exps[k], add(q, 1), &tmpi1, &tmpi2); + ++q; + powfp_odd2(exps[k], q+1, &tmpi1, &tmpi2); } } - ELSE /* q is too high */ + else { - q = sub(q, 1); + /* q is too high */ + --q; powfp_odd2(exps[k], q, &tmpi1, &tmpi2); - - WHILE (sub(sub(tmpi1, tmpi2), 2) < 0) + while (tmpi1 - tmpi2 < 2) { - q = sub(q, 1); + --q; powfp_odd2(exps[k], q, &tmpi1, &tmpi2); } } /* Find the largest scale so that the quantized magnitude is at most q */ - /* p = (q+0.99f-deadzone)/(abs_spectrum[k] + 0.000001f); */ - L_tmp = L_add(L_deposit_h(q), L_mult(sub(32440/*0.99f Q15*/, deadzone), 1)); /* Q16 */ - tmp = BASOP_Util_Divide3232_Scale(L_tmp, L_add(abs_spectrum[k], 1), &s); - s = sub(add(s, 15), abs_spectrum_e); - - k = norm_s(tmp); - tmp = shl(tmp, k); - s = sub(s, k); - - /* assert((int)(abs_spectrum[k] * p + deadzone) <= q); */ - - /* scale = min(scale, p); */ - IF (compMantExp16Unorm(tmp, s, scale, *scale_e) < 0) - { - scale = tmp; - move16(); - *scale_e = s; - move16(); - } + p = (q+0.99f-deadzone)/(abs_spectrum[k] + 0.000001f); + assert((int)(abs_spectrum[k] * p + deadzone) <= q); + scale = min(scale, p); } return scale; } -/* Returns: index of highest freq. nonzero line (-1 if all zeros) */ -static Word16 tcx_arith_find_kMax( - const Word32 abs_spectrum[], /* i: absolute MDCT coefficients Q31-e */ - Word16 abs_spectrum_e, /* i: MDCT exponent Q0 */ - Word16 L_frame, /* i: number of spectral lines Q0 */ - Word16 scale, /* i: scalar quantizer scale Q15-e */ - Word16 scale_e, /* i: scale exponent Q0 */ - Word16 deadzone, /* i: deadzone (0.5f = no deadzone) Q15 */ - const Word8 deadzone_flags[] /* i: line-wise deadzone control */ + +/*-------------------------------------------------------------------* + * tcx_arith_find_kMax() + * + * + *-------------------------------------------------------------------*/ + +static int tcx_arith_find_kMax( /* o: index of highest freq. nonzero line (-1 if all zeros) */ + const float abs_spectrum[], /* i: absolute MDCT coefficients */ + int L_frame, /* i: number of spectral lines */ + float scale, /* i: scalar quantizer scale */ + float deadzone, /* i: deadzone (0.5f = no deadzone) */ + const int deadzone_flags[] /* i: line-wise deadzone control */ ) { - Word16 kMax; - Word32 tmp[2]; + int kMax; - move32(); - move32(); - tmp[0] = L_shr(L_mac(0x7FFFFFFF, deadzone, (Word16)0x8000), abs_spectrum_e); /* 1.0f - deadzone scaled to MDCT exponent */ - tmp[1] = L_shr(0x7FFFFFFF, abs_spectrum_e); /* 1.0f scaled to MDCT exponent */ - - FOR (kMax = sub(L_frame, 1); kMax >= 0; kMax--) + kMax = L_frame - 1; + while ((kMax >= 0) && (abs_spectrum[kMax] * scale < (1.0f - deadzone) + deadzone * deadzone_flags[kMax])) { - IF (L_sub(L_shl(Mpy_32_16_1(abs_spectrum[kMax], scale), scale_e), tmp[deadzone_flags[kMax]]) >= 0) - { - BREAK; - } + kMax--; } - return kMax; } -#define LOG2_E 23637/*1.44269504089f Q14*/ -/* Returns: best scale Q15-e */ -static Word16 tcx_arith_rateloop( - const Word32 abs_spectrum[], /* i: absolute MDCT coefficients Q31-e */ - Word16 abs_spectrum_e, /* i: MDCT exponent Q0 */ - Word16 L_frame, /* i: number of spectral lines Q0 */ - const Word16 envelope[], /* i: scaled envelope Q15-e */ - Word16 envelope_e, /* i: scaled envelope exponent Q0 */ - const Word16 exps[], /* i: expfp(-(int)envelope[]/2) Q15 */ - Word16 target_bits, /* i: target bit budget Q0 */ - Word16 deadzone, /* i: deadzone (0.5f = no deadzone) Q15 */ - const Word8 deadzone_flags[], /* i: line-wise deadzone control Q0 */ - Word16 *target_bits_fac, /* i/o: scale estimator compensation Q14 */ - Word16 *scale_e /* o: scale exponent Q0 */ +/*-------------------------------------------------------------------* + * tcx_arith_rateloop() + * + * + *-------------------------------------------------------------------*/ + +static float tcx_arith_rateloop( /* o: best scale */ + const float abs_spectrum[], /* i: absolute MDCT coefficients */ + int L_frame, /* i: number of spectral lines */ + const Word16 envelope[], /* i: scaled envelope (Q15-e) */ + Word16 envelope_e, /* i: scaled envelope exponent (Q0) */ + const Word16 exps[], /* i: expfp(-(int)envelope[]/2) */ + int target_bits, /* i: target bit budget */ + float deadzone, /* i: deadzone (0.5f = no deadzone) */ + const int deadzone_flags[], /* i: line-wise deadzone control */ + float *target_bits_fac /* i/o: scale estimator compensation */ ) { - Word16 k, kMax, q; - Word16 s, adjust; - Word16 fixed_bits[2][N_MAX_ARI]; - Word32 max_complexity; - Word16 iter; /* rate loop iteration counter */ - Word16 scale; /* SQ scale factor to try next */ - Word16 scale_best; /* best SQ scale factor */ - Word16 scale_max; /* maximum allowable scale factor */ - Word16 lob; /* lower bound of SQ scale factor */ - Word16 hib; /* upper bound of SQ scale factor */ - Word16 flag; /* 1:bit surplus, -1:bit deficit, 0:unknown */ - Word32 complexity; /* cumulative rate loop complexity */ - Word32 bits; /* number of bits (approximate) Q9 */ - Word32 L_tmp; - Word16 tmp, tmp3; - Word32 tmp2; + int k, kMax, q; + float s, adjust; + float fixed_bits[2][N_MAX_ARI]; + float estimator_undershoot; + float max_complexity; + int iter; /* rate loop iteration counter */ + float scale; /* SQ scale factor to try next */ + float scale_best; /* best SQ scale factor */ + float scale_max; /* maximum allowable scale factor */ + float lob; /* lower bound of SQ scale factor */ + float hib; /* upper bound of SQ scale factor */ + int flag; /* 1:bit surplus, -1:bit deficit, 0:unknown */ + float complexity; /* cumulative rate loop complexity */ + float bits; /* number of bits (approximate) */ + float envelope_scale; + scale = tcx_arith_estimate_scale(abs_spectrum, L_frame, envelope, envelope_e); + scale *= *target_bits_fac; - scale = tcx_arith_estimate_scale(abs_spectrum, abs_spectrum_e, L_frame, envelope, envelope_e, &tmp); - scale = mult_r(scale, *target_bits_fac); - tmp = add(tmp, 1); - - scale_max = tcx_arith_find_max_scale(abs_spectrum, abs_spectrum_e, L_frame, envelope, envelope_e, exps, deadzone, scale_e); - - BASOP_SATURATE_WARNING_OFF; - scale = shl(scale, sub(tmp, *scale_e)); - BASOP_SATURATE_WARNING_ON; - scale = s_min(scale, scale_max); + scale_max = tcx_arith_find_max_scale(abs_spectrum, L_frame, envelope, envelope_e, exps, deadzone); + if (scale > scale_max) scale = scale_max; scale_best = scale; - move16(); - lob = 0; - move16(); - hib = 0; - move16(); + lob = 0.0f; + hib = 0.0f; flag = 0; - move16(); - complexity = L_deposit_l(0); - bits = L_deposit_l(0); + complexity = 0; + bits = 0; + max_complexity = 96.0f * L_frame; iter = 0; - move16(); - - max_complexity = L_mult0(96, L_frame); + envelope_scale = (float)pow(2, envelope_e-15); + estimator_undershoot = 0; /* Precalculate fixed bit costs */ - FOR (k = 0; k < L_frame; k++) + for (k=0; k 1.25f) *target_bits_fac = 1.25f; + if (*target_bits_fac < 0.75f) *target_bits_fac = 0.75f; } } - - IF (L_sub(bits, L_mult0(target_bits, 1<<9)) <= 0) /* Bits leftover => scale is too small */ + if (bits <= target_bits) { - test(); - IF (flag <= 0 || sub(scale, scale_best) >= 0) + /* Bits leftover => scale is too small */ + if (flag <= 0 || scale >= scale_best) { scale_best = scale; - move16(); flag = 1; - move16(); } lob = scale; - move16(); - - IF (hib > 0) /* Bisection search */ + if (hib > 0) { - scale = add(shr(lob, 1), shr(hib, 1)); + /* Bisection search */ + scale = (lob + hib)*0.5f; } - ELSE /* Initial scale adaptation */ + else { - /* adjust = 1.25f * target_bits / (float)bits; */ - tmp = BASOP_Util_Divide3232_Scale(L_mult0(target_bits, 0x280), bits, &s); - BASOP_SATURATE_WARNING_OFF; /* adjust limited to <= 2.0, scale to <= scale_max */ - adjust = shl(tmp, sub(s, 1)); /* Q14 */ - scale = shl(mult_r(scale, adjust), 1); - BASOP_SATURATE_WARNING_ON; - scale = s_min(scale, scale_max); + /* Initial scale adaptation */ + adjust = 1.25f * target_bits / (float)bits; + if (adjust > 2.0f) adjust = 2.0f; + scale *= adjust; + if (scale > scale_max) scale = scale_max; } } - ELSE /* Ran out of bits => scale is too large */ + else { + /* Ran out of bits => scale is too large */ hib = scale; - move16(); - - IF (lob > 0) /* Bisection search */ + if (lob > 0) { - scale = add(shr(lob, 1), shr(hib, 1)); + /* Bisection search */ + scale = (lob + hib)*0.5f; } - ELSE { /* Initial scale adaptation */ - /* adjust = 0.8f * target_bits / (float)bits; */ - tmp = BASOP_Util_Divide3232_Scale(L_mult0(target_bits, 0x19A), bits, &s); - adjust = shl(tmp, s); /* Q15 */ - adjust = s_max(adjust, 16384/*0.5f Q15*/); - scale = mult_r(scale, adjust); + else + { + /* Initial scale adaptation */ + adjust = 0.8f * target_bits / (float)bits; + if (adjust < 0.5f) adjust = 0.5f; + scale *= adjust; } - - IF (flag <= 0) + if (flag <= 0) { scale_best = scale; - move16(); flag = 0; - move16(); } } - iter = add(iter, 1); + ++iter; } return scale_best; } -/* Returns: number of bits consumed */ -static Word16 tcx_arith_encode( - Word16 q_abs_spectrum[], /* i/o: scalar quantized absolute spectrum Q0 */ - const Word16 signs[], /* i: signs */ - Word16 kMax, /* i: number of nonzero spectral lines to code Q0 */ - Word16 L_frame, /* i: nominal number of spectral lines Q0 */ - const Word16 exps[], /* i: expfp(-(int)envelope[]/2) Q15 */ - Word16 target_bits, /* i: target bit budget Q0 */ - Word16 prm[] /* o: bit-stream Q0 */ + +/*-------------------------------------------------------------------* + * tcx_arith_encode() + * + * + *-------------------------------------------------------------------*/ + +static int tcx_arith_encode( /* o: number of bits consumed */ + int q_abs_spectrum[], /* i/o: scalar quantized absolute spectrum */ + const int signs[], /* i: signs */ + int kMax, /* i: number of nonzero spectral lines to code */ + int L_frame, /* i: nominal number of spectral lines */ + const Word16 exps[], /* i: expfp(-(int)envelope[]/2) */ + int target_bits, /* i: target bit budget */ + int prm[] /* o: bit-stream */ ) { - TastatEnc as, as_lastgood; - Word16 bp, bp_lastgood; - Word16 k; - Word16 kEncoded; + Tastat as, as_lastgood; + int bp, bp_lastgood; + int k; + int kEncoded; Word16 tmpi1, tmpi2; - - /* Final coding */ ari_start_encoding_14bits(&as); ari_copy_states(&as, &as_lastgood); - bp = 0; - move16(); - bp_lastgood = 0; - move16(); + bp = bp_lastgood = 0; kEncoded = kMax; - move16(); - - FOR (k = 0; k <= kMax; k++) + for (k=0; k<=kMax; ++k) { - IF (q_abs_spectrum[k] == 0) + if (q_abs_spectrum[k] == 0) { assert(exps[k] >= 2); - bp = ari_encode_14bits_range(prm, bp, target_bits, &as, shr(exps[k], 1), 16384); + bp = ari_encode_14bits_range(prm, bp, target_bits, &as, exps[k]>>1, 16384); } - ELSE /* q_abs_spectrum[k] != 0 */ + else { + /* q_abs_spectrum[k] != 0 */ powfp_odd2(exps[k], q_abs_spectrum[k], &tmpi1, &tmpi2); - - WHILE (sub(tmpi1, add(tmpi2, 2)) < 0) + while (tmpi1 < tmpi2 + 2) { - q_abs_spectrum[k] = sub(q_abs_spectrum[k], 1); - move16(); + --q_abs_spectrum[k]; powfp_odd2(exps[k], q_abs_spectrum[k], &tmpi1, &tmpi2); } - - bp = ari_encode_14bits_range(prm, bp, target_bits, &as, shr(tmpi2, 1), shr(tmpi1, 1)); + bp = ari_encode_14bits_range(prm, bp, target_bits, &as, tmpi2>>1, tmpi1>>1); bp = ari_encode_14bits_sign(prm, bp, target_bits, &as, signs[k]); } /* Check bit budget status */ - IF (ari_encode_overflow(&as)) /* no bits left */ + if (as.high <= as.low) { + /* no bits left */ /* printf("\noverflow at %d\n\n", k); */ - - IF (sub(q_abs_spectrum[k], 1) > 0) /* Lower magnitude is still > 0 */ + if (q_abs_spectrum[k] > 1) /* Lower magnitude is still > 0 */ { /* Restore state */ ari_copy_states(&as_lastgood, &as); bp = bp_lastgood; - move16(); /* Quantize to lower magnitude */ - q_abs_spectrum[k] = sub(q_abs_spectrum[k], 1); - move16(); + --q_abs_spectrum[k]; /* Retry encoding */ powfp_odd2(exps[k], q_abs_spectrum[k], &tmpi1, &tmpi2); - - bp = ari_encode_14bits_range(prm, bp, target_bits, &as, shr(tmpi2, 1), shr(tmpi1, 1)); + bp = ari_encode_14bits_range(prm, bp, target_bits, &as, tmpi2>>1, tmpi1>>1); bp = ari_encode_14bits_sign(prm, bp, target_bits, &as, signs[k]); - - IF (!ari_encode_overflow(&as)) /* Success */ + if (as.high > as.low) /* Success */ { ari_copy_states(&as, &as_lastgood); bp_lastgood = bp; - move16(); kEncoded = k; - move16(); - - set16_fx(q_abs_spectrum+k+1, 0, sub(kMax, k)); - BREAK; + for (++k; k <= kMax; k++) + { + q_abs_spectrum[k] = 0; + } + break; } } ari_copy_states(&as_lastgood, &as); bp = bp_lastgood; - move16(); - kEncoded = sub(k, 1); - - set16_fx(q_abs_spectrum+k, 0, sub(kMax, kEncoded)); - BREAK; + kEncoded = k-1; + for (; k <= kMax; k++) + { + q_abs_spectrum[k] = 0; + } + break; } - ELSE + else { ari_copy_states(&as, &as_lastgood); bp_lastgood = bp; - move16(); } } /* Send zeros until L_frame */ - tmpi1 = add(kEncoded, 1); - kEncoded = sub(L_frame, 1); - FOR (k = tmpi1; k < L_frame; k++) + for (k=kEncoded+1, kEncoded=L_frame-1; k= 1); - - bp = ari_encode_14bits_range(prm, bp, target_bits, &as, shr(exps[k],1), 16384); + assert(exps[k] >= 2); + bp = ari_encode_14bits_range(prm, bp, target_bits, &as, exps[k]>>1, 16384); /* Check bit budget status */ - IF (ari_encode_overflow(&as)) /* no bits left */ + if (as.high <= as.low) { + /* no bits left */ ari_copy_states(&as_lastgood, &as); bp = bp_lastgood; - move16(); - kEncoded = sub(k, 1); - BREAK; + kEncoded = k-1; + break; } - ELSE + else { ari_copy_states(&as, &as_lastgood); bp_lastgood = bp; - move16(); } } - IF (sub(kEncoded, sub(L_frame, 1)) == 0) /* RESQ bits possibly available */ + if (kEncoded == L_frame-1) { + /* RESQ bits possibly available */ /* Limit target bits to actually needed bits */ - target_bits = add(add(bp, 16), extract_l(as.vobf)); + bp = ari_done_cbr_encoding_14bits(prm, bp, bp + 16 + as.vobf, &as); } - return ari_done_cbr_encoding_14bits(prm, bp, target_bits, &as); + else + { + bp = ari_done_cbr_encoding_14bits(prm, bp, target_bits, &as); + } + + return bp; } + +/*-------------------------------------------------------------------* + * tcx_arith_encode_envelope() + * + * + *-------------------------------------------------------------------*/ + void tcx_arith_encode_envelope( - Word32 spectrum[], /* i/o: MDCT coefficients Q31-e */ - Word16 *spectrum_e, /* i/o: MDCT exponent Q0 */ - Word16 signs[], /* o: signs (spectrum[.]<0) Q0 */ - Word16 L_frame, /* i: frame or MDCT length Q0 */ - Word16 L_spec, /* i: frame or MDCT length Q0 */ - Encoder_State_fx *st, /* i/o: coder state */ - const Word16 A_ind[], /* i: quantised LPC coefficients Q12 */ - Word16 target_bits, /* i: number of available bits Q0 */ - Word16 prm[], /* o: bitstream parameters Q0 */ - Word8 use_hm, /* i: use HM in current frame? */ - Word16 prm_hm[], /* o: HM parameter area Q0 */ - Word16 tcxltp_pitch, /* i: TCX LTP pitch in FD, -1 if n/a Q0*/ - Word16 *arith_bits, /* o: bits used for ari. coding Q0 */ - Word16 *signaling_bits, /* o: bits used for signaling Q0 */ - Word16 *nf_seed /* o: noise filling seed Q0 */ - ,Word16 low_complexity /* i: low-complexity flag Q0 */ + float spectrum[], /* i/o: MDCT coefficients */ + int signs[], /* o: signs (spectrum[.]<0) */ + int L_frame, /* i: frame or MDCT length */ + int L_spec, /* i: length w/o BW limitation */ + Encoder_State *st, /* i/o: coder state */ + const Word16 A_ind[], /* i: quantised LPC coefficients */ + int target_bits, /* i: number of available bits */ + int prm[], /* o: bitstream parameters */ + int use_hm, /* i: use HM in current frame? */ + int prm_hm[], /* o: HM parameter area */ + short tcxltp_pitch, /* i: TCX LTP pitch in FD, -1 if n/a*/ + int *arith_bits, /* o: bits used for ari. coding */ + int *signaling_bits, /* o: bits used for signaling */ + int low_complexity /* i: low-complexity flag */ ) { + Word16 tmp; Word32 env[N_MAX_ARI]; /* unscaled envelope (Q16) */ Word16 *envelope; /* scaled envelope (Q15-e) */ Word16 envelope_e; Word16 exponents[N_MAX_ARI]; /* Q15 */ - Word16 L_spec_core; - Word16 *q_spectrum; + int L_spec_core; + int *q_spectrum; TCX_config *tcx_cfg; - Word16 scale, scale_e; - Word16 k, kMax; - Word16 deadzone; - const Word8 *deadzone_flags; - Word16 gamma_w, gamma_uw; - Word16 hm_bits; - Word32 L_tmp, L_tmp2; - Word16 tmp; - - - assert(L_spec <= N_MAX_ARI); + float scale; + int k, kMax; + float deadzone; + const int *deadzone_flags; + float gamma_w, gamma_uw; + int hm_bits; + assert(L_spec<=N_MAX_ARI); tcx_cfg = &st->tcx_cfg; deadzone = tcx_cfg->sq_rounding; - move16(); deadzone_flags = st->memQuantZeros; *signaling_bits = 0; - move16(); - assert(st->enableTcxLpc); - gamma_w = 32767/*1.0f Q15*/; - move16(); - gamma_uw = st->inv_gamma; - move16(); + gamma_w = 1.0f; + gamma_uw = 1.0f/st->gamma; + tcx_arith_render_envelope( A_ind, L_frame, L_spec, FL2WORD16(tcx_cfg->preemph_fac), FL2WORD16(gamma_w), FL2WORD16(0.5f*gamma_uw), env ); - tcx_arith_render_envelope( - A_ind, - L_frame, - L_spec, - tcx_cfg->preemph_fac, - gamma_w, - gamma_uw, - env - ); - - FOR (k = 0; k < L_spec; k++) + for (k=0; kcoder_type, - prm_hm, - tcxltp_pitch, - st->tcxltp_gain, - &hm_bits - ); + tcx_hm_analyse( spectrum, L_spec, env, target_bits, tcx_cfg->coder_type, prm_hm, tcxltp_pitch, st->tcxltp_gain, &hm_bits ); - target_bits = sub(target_bits, hm_bits); - *signaling_bits = add(*signaling_bits, hm_bits); - move16(); + target_bits -= hm_bits; + *signaling_bits += hm_bits; } - ELSE + else { - prm_hm[0] = 0; /* just to be sure */ move16(); + prm_hm[0] = 0; /* just to be sure */ hm_bits = 0; - move16(); } L_spec_core = L_spec; - move16(); if (st->igf) { - L_spec_core = s_min(L_spec_core, st->hIGFEnc.infoStartLine); + L_spec_core = min(L_spec_core, st->hIGFEnc.infoStartLine); } envelope = (Word16*)env; + tcx_arith_scale_envelope( L_spec, L_spec_core, env, target_bits, low_complexity, envelope, &envelope_e ); - tcx_arith_scale_envelope( - L_spec, - L_spec_core, - env, - target_bits, - low_complexity, - envelope, - &envelope_e - ); - - tmp = sub(envelope_e, 1+15); + tmp = sub(envelope_e, 1); FOR (k = 0; k < L_spec; k++) { - exponents[k] = round_fx(expfp(envelope[k], tmp)); + exponents[k] = expfp(negate(envelope[k]), tmp); } - - scale = tcx_arith_rateloop( - spectrum, - *spectrum_e, - L_spec, - envelope, - envelope_e, - exponents, - target_bits, - deadzone, - deadzone_flags, - &st->LPDmem.tcx_target_bits_fac, - &scale_e - ); + scale = tcx_arith_rateloop( spectrum, L_spec, envelope, envelope_e, exponents, target_bits, deadzone, deadzone_flags, &st->LPDmem.tcx_target_bits_fac ); /* Final quantization */ - kMax = tcx_arith_find_kMax( - spectrum, - *spectrum_e, - L_spec, - scale, scale_e, - deadzone, - deadzone_flags - ); + kMax = tcx_arith_find_kMax( spectrum, L_spec, scale, deadzone, deadzone_flags ); - q_spectrum = (Word16*)env; /* Reuse buffer */ - - L_tmp = L_mult(deadzone, 1); /* Q16 */ - tmp = add(sub(*spectrum_e, 15), scale_e); - FOR (k = 0; k <= kMax; k++) + q_spectrum = (int*)env; /* Reuse buffer */ + for (k=0; k<=kMax; ++k) { /* quantise using dead-zone */ - q_spectrum[k] = extract_h(L_add(L_shl(Mpy_32_16_1(spectrum[k], scale), tmp), L_tmp)); + q_spectrum[k] = (int)(spectrum[k] * scale + deadzone); } /* Final encoding */ - *arith_bits = tcx_arith_encode( - q_spectrum, - signs, - kMax, - L_spec, - exponents, - target_bits, - prm - ); + *arith_bits = tcx_arith_encode( q_spectrum, signs, kMax, L_spec, exponents, target_bits, prm ); /* Multiply back the signs */ - L_tmp2 = L_deposit_l(0); - FOR (k = 0; k <= kMax; k++) + for (k=0; k<=kMax; ++k) { - L_tmp2 = L_macNs(L_tmp2, q_spectrum[k], k); - - if (signs[k] != 0) L_tmp = L_mult(q_spectrum[k], -(1<< (30 - SPEC_EXP_DEC))); - if (signs[k] == 0) L_tmp = L_mult(q_spectrum[k], 1 << (30 - SPEC_EXP_DEC)); - spectrum[k] = L_tmp; - move32(); + spectrum[k] = (float)(q_spectrum[k] * (1-2*signs[k])); + } + for (; k +#include "options.h" +#include "prot.h" +#include "rom_com.h" + +/*-------------------------------------------------------------------* + * Function AVQ_cod() * + * * + * Split algebraic vector quantizer (AVQ) based on RE8 latice * + *-------------------------------------------------------------------*/ + +float AVQ_cod( /* o: comfort noise gain factor */ + const float xri[], /* i: vector to quantize */ + int xriq[], /* o: quantized normalized vector (assuming the bit budget is enough) */ + const short nb_bits, /* i: number of allocated bits */ + const short Nsv /* i: number of subvectors (lg=Nsv*8) */ +) +{ + short i, j, iter; + int c[8]; + float gain_inv, x1[8], ener, tmp, nbits, nbits_max, fac, offset; + float ebits[NSV_MAX]; + + /* find energy of each subvector in log domain (scaled for bits estimation) */ + for( i=0; i= 0 */ + for( j=0; j<8; j++ ) + { + x1[j] = xri[i*8+j]; + ener += x1[j]*x1[j]; + } + + /* estimated bit consumption when gain=1 */ + ebits[i] = 5.0f * FAC_LOG2 * (float)log10( ener*0.5f ); + } + + /* estimate gain according to number of bits allowed */ + fac = 128.0f; /* start at the middle (offset range = 0 to 255.75) */ + offset = 0.0f; + nbits_max = 0.95f * ((float)(nb_bits - Nsv)); + + /* tree search with 10 iterations : offset with step of 0.25 bits (0.3 dB) */ + for( iter=0; iter<10; iter++ ) + { + offset += fac; + /* calculate the required number of bits */ + nbits = 0.0; + for( i=0; i bits ) + { + bits = (short)t[j]; + pos = j; + } + } + sort_idx[i] = pos; + t[pos] = -1; + } + + /* compute multi-rate indices and avoid bit budget overflow */ + pos_max = 0; + bits = 0; + for( i=0; i 0 ) + { + j = pos_max; + if( pos > j ) + { + j = pos; + } + + /* compute (number of bits -1) to describe Q #nq */ + if( nq[pos] >= 2 ) + { + overflow = (short)(nq[pos]*5-1); + } + else + { + overflow = 0; + } + + /* check for overflow and compute number of bits-1 (n) */ + if( (bits+overflow+j) > *nb_bits ) + { + /* if budget overflow */ + for( j=pos*8; j<(pos*8)+8; j++ ) + { + xriq[j] = 0; + } + nq[pos] = 0; /* force Q0 */ + } + else + { + bits += overflow; + pos_max = j; /* update index of the last described subvector */ + } + } + } + + /* write indexes to the bitstream */ + /* ============================== */ + + bits = *nb_bits; + overflow = 0; + + for( i=0; i 8 ) + { + /* write the unary code for nq[i] */ + j = (short)(nq[i] - 1); + if ( nq[i] > 0 ) + { + /* write the unary code */ + while ( j > 16 ) + { + push_indice( st, nq_ind, 65535, 16 ); + bits -= 16; + j -= 16; + } + + if ( j > 0 ) + { + push_indice( st, nq_ind, (1< 4 ) + { + nk = (nq-3)>>1; + n = nq - nk*2; + } + + /* write n groups of 4-bit for base codebook index (I) */ + while( n-- > 0 ) + { + indx[pos++] = (I & 0x0F); + I >>= 4; + } + + /* write n groups of 4-bit for Voronoi index (k[]) */ + while( nk-- > 0 ) + { + ival = 0; + + for( i=0; i<8; i++ ) + { + ival <<= 1; + ival += (kv[i] & 0x01); + kv[i] >>= 1; + } + indx[pos++] = (ival & 0x0F); + ival >>= 4; + indx[pos++] = (ival & 0x0F); + } + } + + return; +} diff --git a/src/libs/libevs/lib_enc/avq_cod_fx.cpp b/src/libs/libevs/lib_enc/avq_cod_fx.cpp deleted file mode 100755 index 228b154c..00000000 --- a/src/libs/libevs/lib_enc/avq_cod_fx.cpp +++ /dev/null @@ -1,460 +0,0 @@ -/*==================================================================================== - EVS Codec 3GPP TS26.442 Apr 03, 2018. Version 12.11.0 / 13.6.0 / 14.2.0 - ====================================================================================*/ - -#include "options.h" /* Compilation switches */ -#include "prot_fx.h" /* Function prototypes */ -#include "rom_com_fx.h" /* Static table prototypes */ -#include "stl.h" - -/*-------------------------------------------------------------------* -* Function AVQ_cod() * -* * -* Split algevraic vector quantizer (AVQ) base on RE8 latice * -*-------------------------------------------------------------------*/ - -void AVQ_cod_fx( /* o: comfort noise gain factor */ - const Word16 xri[], /* i: vector to quantize */ - Word16 xriq[], /* o: quantized normalized vector (assuming the bit budget is enough) */ - const Word16 NB_BITS, /* i: number of allocated bits */ - const Word16 Nsv /* i: number of subvectors (lg=Nsv*8) */ - ,const Word16 Q_in_ref /* i: Scaling input */ -) -{ - Word16 i, l, iter, c[8]; - Word16 gain_inv, tmp, nbits, nbits_max, fac, offset; - Word16 ebits[NSV_MAX], e_ebits, f_ebits, e_tmp,f_tmp, tmp16, l_8; - Word32 Lener, Ltmp, Lgain, x1[8]; - Word16 tot_est_bits, Q_in; - - Q_in = sub(Q_in_ref,1); - move16(); - - /* find energy of each subvector in log domain (scaled for bits estimation) */ - /* if the number of allocated bits is high, recompute the energy of sub vectors with a different scaling factor (applicable only in BASOP code) */ - DO - { - Q_in = add(Q_in,1); - tot_est_bits = 0; - move16(); - FOR (l=0; l= 0 */ - FOR (i=0; i<8; i++) - { - Lener = L_mac(Lener, xri[l*8+i], xri[l*8+i]); - } - /* estimated bit consumption when gain=1 */ - /* ebits[l] = 5.0 * FAC_LOG2 * (Word16)log10(ener * 0.5) */ - e_ebits = norm_l(Lener); - f_ebits = Log2_norm_lc(L_shl(Lener, e_ebits)); - e_ebits = sub(30-2, e_ebits); /* -2 = *0.25 */ - e_ebits = sub(e_ebits, shl(Q_in,1)); - - Ltmp = L_deposit_h(e_ebits); - Ltmp = L_mac(Ltmp, f_ebits, 1); - Ltmp = L_add(L_shl(Ltmp,6), L_shl(Ltmp,4)); /* Mult by 5.0 and then by 16 (To go to Q4). Do it using Mult by 80 (which is 64+16) */ - ebits[l] = round_fx(Ltmp); /*Q4*/ - tot_est_bits = add(tot_est_bits, shr(ebits[l],4)); - } - test(); - test(); - } - WHILE( (sub(Q_in, Q_in_ref) <= 0) && sub( tot_est_bits, mult( 26214, NB_BITS )) <= 0 && sub( tot_est_bits, 600) > 0 ) ; /* limited to 1 possible iteration */ - - /*----------------------------------------------------------------* - * subvector energy worst case: - * - typically, it's a tone with maximum of amplitude (RMS=23170). - * - fft length max = 1024 (N/2 is 512) - * log10(energy) = log10(23710*23710*1024*(N/2)) = 14.45 - * ebits --> 5.0*FAC_LOG2*14.45 = 240 bits - *----------------------------------------------------------------*/ - - /* estimate gain according to number of bits allowed */ - /* start at the middle (offset range = 0 to 255.75) Q6 */ - fac = 2048; - move16(); - offset = 0; - move16(); - - Ltmp = L_mult(31130, sub(NB_BITS, Nsv)); /* (1810 - 8 - 1152/8)*.95*/ - nbits_max = round_fx(L_shl(Ltmp, 4)); - - /* tree search with 10 iterations : offset with step of 0.25 bits (0.3 dB) */ - FOR (iter=0; iter<10; iter++) - { - offset = add(fac, offset); - /* calculate the required number of bits */ - nbits = 0; - move16(); - FOR (l=0; l 0 ) - { - pos = j; - move16(); - } - bits = s_max(t[j],bits); - - } - sort_idx[i] = pos; - move16(); - t[pos] = -1; - move16(); - } - - /* compute multi-rate indices and avoid bit budget overflow */ - pos_max = 0; - move16(); - bits = 0; - move16(); - FOR( i=0; i 0 ) - { - j = pos_max; - move16(); - j = s_max(pos,j); - - /* compute (number of bits -1) to describe Q #nq */ - IF(sub(nq[pos],2) >= 0 ) - { - overflow = sub(i_mult2(nq[pos],5),1); - } - ELSE - { - overflow = 0; - move16(); - } - - /* check for overflow and compute number of bits-1 (n) */ - IF( sub(add(bits,add(overflow,j)),*nb_bits) > 0 ) - { - /* if budget overflow */ - pos_tmp = add(shl(pos,3),8); /*(pos*8)+8*/ - FOR( j=pos*8; j 0 ) - { - /* write the unary code for nq[i] */ - j = sub(nq[i], 1); - IF ( nq[i] > 0 ) - { - /* write the unary code */ - FOR( ; j > 16; j -= 16 ) - { - push_indice_fx( st_fx, nq_ind, 65535, 16 ); - bits = sub(bits,16); - } - - IF ( j > 0 ) - { - push_indice_fx( st_fx, nq_ind, extract_l(L_sub(L_shl(1L,j),1L)), j ); - bits = sub(bits,j); - } - } - IF ( !overflow ) - { - /* write the stop bit */ - push_indice_fx( st_fx, nq_ind, 0, 1 ); - bits = sub(bits,1); - } - - /* write codebook indices (rank I and event. Voronoi index kv) */ - IF( nq[i] == 0 ) /* Q0 */ - { - /* nothing to write */ - } - ELSE IF( sub(nq[i],5) < 0 ) /* Q2, Q3, Q4 */ - { - push_indice_fx( st_fx, i_ind, I[i], shl(nq[i],2) ); - bits = sub(bits, shl(nq[i],2)); - } - ELSE IF( s_and(nq[i],1) == 0 ) /* Q4 + Voronoi extensions r=1,2,3,... */ - { - push_indice_fx( st_fx, i_ind, I[i], 4*4 ); - bits = sub(bits,4*4); - pos = sub(shr(nq[i],1), 2); /* Voronoi order determination */ - move16(); /*ptr init*/ - FOR( j=0; j<8; j++ ) - { - push_indice_fx( st_fx, kv_ind, kv[i*8+j], pos ); - } - - bits = sub(bits,shl(pos,3)); - } - ELSE /* Q3 + Voronoi extensions r=1,2,3,... */ - { - push_indice_fx( st_fx, i_ind, I[i], 4*3 ); - bits = sub(bits, 4*3); - - pos = sub(shr(nq[i],1), 1); /* Voronoi order determination */ - move16(); /* ptr init */ - FOR( j=0; j<8; j++ ) - { - push_indice_fx( st_fx, kv_ind, kv[i*8+j], pos ); - } - - bits = sub(bits,shl(pos,3)); - } - } - } /* for */ - - *nb_bits = bits; - move16(); - - FOR( i=0; i 16Q15*/ move32(); - } - re8_PPV_fx(x1, c); /*x1:8Q15, c:15Q0*/ - re8_cod_fx(c, &nq, &I16, kv); - I = UL_deposit_l(I16); - - FOR (i=0; i<8; i++) - { - nvecq[l*8+i] = shl(c[i],10); /*15Q0->5Q10*/ move16(); - } - - indx[l] = nq; /* index[0..Nsv-1] = quantizer number (0,2,3,4...) */ move16(); - nk = 0; - move16(); - n = nq; - move16(); - - IF (sub(nq,4) > 0) - { - nk = shr(sub(nq,3),1); /*nk = (nq-3)>>1;*/ - n = sub(nq,shl(nk,1)); /*n = nq - nk*2; */ - } - - /* write n groups of 4-bit for base codebook index (I) */ - FOR ( ; n > 0; n-- ) - { - indx[pos++] = s_and(extract_l(I),0x000F); - move16(); - I = L_shr(I,4); - } - - /* write n groups of 4-bit for Voronoi index (k[]) */ - FOR ( ; nk > 0; nk--) - { - ival = 0; - move16(); - FOR (i=0; i<8; i++) - { - ival = shl(ival,1); /*ival <<= 1;*/ - ival = add(ival,s_and(kv[i],0x0001)); /*ival += (kv[i] & 0x01);*/ - kv[i] = shr(kv[i],1); /*kv[i] >>= 1;*/ move16(); - } - indx[pos++] = s_and(ival,0x000F); - move16(); - ival = shr(ival,4); - indx[pos++] = s_and(ival,0x000F); - move16(); - } - } - - - return; -} diff --git a/src/libs/libevs/lib_enc/bass_psfilter_enc.cpp b/src/libs/libevs/lib_enc/bass_psfilter_enc.cpp old mode 100755 new mode 100644 index acbcee6e..e9bc2daf --- a/src/libs/libevs/lib_enc/bass_psfilter_enc.cpp +++ b/src/libs/libevs/lib_enc/bass_psfilter_enc.cpp @@ -1,389 +1,212 @@ /*==================================================================================== - EVS Codec 3GPP TS26.442 Apr 03, 2018. Version 12.11.0 / 13.6.0 / 14.2.0 + EVS Codec 3GPP TS26.443 Nov 13, 2018. Version 12.11.0 / 13.7.0 / 14.3.0 / 15.1.0 ====================================================================================*/ - - #include #include #include +#include #include "options.h" -#include "prot_fx.h" -#include "basop_util.h" -#include "stl.h" -#include "stat_enc_fx.h" + +#include "prot.h" +#include "rom_com.h" -Word16 bass_pf_enc( - Word16 *orig, /* (i) : 12.8kHz original signal Q0 */ - Word16 *syn, /* (i) : 12.8kHz synthesis to postfilter Q0 */ - Word16 *T_sf, /* (i) : Pitch period for all subframes (T_sf[16]) Q0 */ - Word16 *gainT_sf, /* (i) : Pitch gain for all subframes (gainT_sf[16]) Q14 */ - Word16 l_frame, /* (i) : frame length (should be multiple of l_subfr) Q0 */ - Word16 l_subfr, /* (i) : sub-frame length (60/64) Q0 */ - Word16 *gain_factor_param, /* (o) : quantized gain factor Q0 */ - Word16 mode, /* (i) : coding mode of adapt bpf */ - struct MEM_BPF *mem_bpf /* i/o : memory state */ + +/*---------------------------------------------------------------------* + * bass_pf_enc() + * + * Low-frequency postfiltering, decoder parammeter estimation + *---------------------------------------------------------------------*/ + +float bass_pf_enc( + const float *orig, /* (i) : 12.8kHz original signal */ + const float *syn, /* (i) : 12.8kHz synthesis to postfilter */ + const float pitch_buf[], /* (i) : Pitch gain for all subframes (gainT_sf[16]) */ + const float gainT_sf[], /* (i) : Pitch gain for all subframes (gainT_sf[16]) */ + const short l_frame, /* (i) : frame length (should be multiple of l_subfr)*/ + const short l_subfr_in, /* (i) : sub-frame length (80/64) */ + float mem_bpf[], /* i/o : memory state [2*L_FILT16k] */ + float mem_error_bpf[], /* i/o : memory state [2*L_FILT16k] */ + int *gain_factor_param, /* (o) : quantized gain factor */ + const short mode, /* (i) : coding mode of adapt bpf */ + float *mem_deemph_err, /* o : Error deemphasis memory */ + float *lp_ener /* o : long_term error signal energy */ ) { - Word16 i, j, sf, i_subfr, T, lg, l_filt; - Word16 gain, d, tmp16, hr, s1, s2, s2_old, s3, s4, st, st2, st3; - Word32 nrg, tmp, nrg1, nrg2, n, snr, lp_error, tmp32; - Word16 noise_buf[L_FILT16k+2*L_SUBFR], *noise, *noise_in; - Word16 error_buf[L_FILT16k+2*L_SUBFR], *error, *error_in; - Word32 cross_n_d, nrg_n; - const Word16 *pFilt; - Word32 ener2; + int i, j, sf, i_subfr, T, lg, l_subfr, l_filt; + float d,n, snr, nrg1,nrg2, gain,nrg,tmp; + float noise_buf[L_FILT16k+(2*L_SUBFR)], *noise, *noise_in; + float error_buf[L_FILT16k+(2*L_SUBFR)], *error, *error_in; + float cross_n_d, nrg_n; + const float *pFilt; + float ener2; - IF (sub(l_frame, L_FRAME16k) != 0) + if ( l_frame!=L_FRAME16k ) { pFilt = filt_lp; l_filt = L_FILT; - move16(); } - ELSE + else { pFilt = filt_lp_16kHz; l_filt = L_FILT16k; - move16(); } noise = noise_buf + l_filt; - noise_in = noise_buf + shl(l_filt, 1); - error = error_buf; - error_in = error_buf + l_filt; + noise_in = noise_buf + 2*l_filt; + error = error_buf + l_filt; + error_in = error_buf + 2*l_filt; sf = 0; - move16(); - snr = L_deposit_l(0); - nrg_n = L_deposit_l(0); - cross_n_d = L_deposit_l(0); - lp_error = L_shl(mem_bpf->lp_error, 0); - s2_old = mem_bpf->noise_shift_old; - move16(); - s3 = s4 = 0; /* initialization of s3 and s4 to suppress compiler warnings; - s3 and s4 get initialized for i_subfr == 0 */ - - nrg1 = nrg2 = 0; /* initialization fo nrg1 and nrg2 to suppress compiler warnings; - nrg1 and nrg1 get initialized for i_subfr == 0 */ - - FOR (i_subfr = 0; i_subfr < l_frame; i_subfr += l_subfr) + snr=0.f; + nrg_n=1e-6f; + cross_n_d = 0.f; + l_subfr = l_subfr_in; + for (i_subfr=0; i_subfr 1.0f) gain = 1.0f; + if (gain < 0.0f) gain = 0.0f; + + lg = l_frame - T - i_subfr; + if (lg < 0) lg = 0; + if (lg > l_subfr) lg = l_subfr; + + + if (gain > 0) { - lg = 0; - move16(); - } - if (sub(lg, l_subfr) > 0) - { - lg = l_subfr; - move16(); - } - - IF (gainT_sf[sf] > 0) - { - /* get headroom for used part of syn */ - tmp16 = s_max(add(lg, shl(T, 1)), add(l_subfr, T)); - hr = getScaleFactor16(syn + sub(i_subfr, T), tmp16); - s1 = sub(hr, 3); - - tmp = L_deposit_l(1); - nrg = L_deposit_l(1); - - IF (lg > 0) + tmp = 0.01f; + nrg=0.01f; + for (i=0; i1.0f) + { + gain=1.0f; + } + else if(gain<0.f) + { + gain=0.f; } - IF (sub(lg, l_subfr) < 0) + ener2=0.01f; + for (i=0; i0.5f) { - gain = 0; - move16(); + tmp=0.5f; + } + else if(tmp<0.f) + { + tmp=0.0f; } - st = sub(norm_l(lp_error), 3); - test(); - if ((sub(st, s1) < 0) && (lp_error != 0)) + for (i=0; i 0) + for (i=lg; i 0) - { - ener2 = L_shr(BASOP_Util_Log2(ener2), 9); /* 15Q16 */ - ener2 = L_add(ener2, L_deposit_h(sub(31, st))); - } - ELSE - { - ener2 = 0xFFF95B2C; /* log2(0.01) (15Q16) */ move32(); - } - - mem_bpf->lp_error_ener = L_add(Mpy_32_16_1(L_sub(mem_bpf->lp_error_ener, ener2), 32440/*0.99f Q15*/), ener2); /* 15Q16 */ - - st = add(st, 6); - ener2 = L_sub(mem_bpf->lp_error_ener, L_deposit_h(sub(31, st))); - IF (ener2 >= 0) - { - tmp16 = add(extract_h(ener2), 1); - ener2 = L_sub(ener2, L_deposit_h(tmp16)); - tmp = L_shr(tmp, tmp16); - nrg = L_shr(nrg, tmp16); - } - ener2 = BASOP_Util_InvLog2(L_shl(ener2, 9)); /* Q0+2*s1 */ - - tmp32 = L_add(L_shr(nrg, 1), L_shr(ener2, 1)); - if (tmp32 == 0) tmp32 = L_deposit_l(1); - tmp16 = BASOP_Util_Divide3232_Scale(tmp, tmp32, &st); - BASOP_SATURATE_WARNING_OFF; - tmp16 = shl(tmp16, sub(st, 2)); /* Q15 */ - - if (sub(tmp16, 16384/*0.5f Q15*/) > 0) - { - tmp16 = 16384/*0.5f Q15*/; - move16(); - } - if (tmp16 < 0) - { - tmp16 = 0; - move16(); - } - BASOP_SATURATE_WARNING_ON; - - s2 = hr; - move16(); - - IF (lg > 0) - { - FOR (i = 0; i < lg; i++) - { - tmp32 = L_msu0(0, tmp16, syn[i+i_subfr-T]); - tmp32 = L_msu0(tmp32, tmp16, syn[i+i_subfr+T]); - tmp32 = L_mac(tmp32, tmp16, syn[i+i_subfr]); - noise_in[i] = round_fx(L_shl(tmp32, s2)); /* Q0+s2 */ - - error_in[i] = sub(orig[i+i_subfr], syn[i+i_subfr]); /*Q0*/ move16(); - } - } - - IF (sub(lg, l_subfr) < 0) - { - FOR (i = lg; i < l_subfr; i++) - { - tmp32 = L_mult0(tmp16, syn[i+i_subfr]); - tmp32 = L_msu0(tmp32, tmp16, syn[i+i_subfr-T]); - noise_in[i] = round_fx(L_shl(tmp32, s2)); /* Q0+s2 */ - - error_in[i] = sub(orig[i+i_subfr], syn[i+i_subfr]); /*Q0*/ move16(); - } + noise_in[i] = tmp * (syn[i+i_subfr] - syn[i+i_subfr-T]); + noise_in[i] *= 0.5f; + error_in[i] =(orig[i+i_subfr]-syn[i+i_subfr]); } } - ELSE + else { - set16_fx(noise_in, 0, l_subfr); - set16_fx(error_in, 0, l_subfr); - s2 = s2_old; + set_zero(noise_in, l_subfr); + set_zero(error_in, l_subfr); } - tmp16 = shl(l_filt, 1); + mvr2r(mem_bpf, noise_buf, 2*l_filt); + mvr2r(noise_buf+l_subfr, mem_bpf, 2*l_filt); - /* copy history buffers (rescale noise history to new exponent) */ - st = sub(s2, s2_old); - FOR (i = 0; i < tmp16; i++) - { - noise_buf[i] = shl(mem_bpf->noise_buf[i], st); - move16(); - } - Copy(noise_buf+l_subfr, mem_bpf->noise_buf, tmp16); - s2_old = s2; - move16(); + mvr2r(mem_error_bpf, error_buf, 2*l_filt); + mvr2r(error_buf+l_subfr, mem_error_bpf, 2*l_filt); - Copy(mem_bpf->error_buf, error_buf, l_filt); - Copy(error_buf+l_subfr, mem_bpf->error_buf, l_filt); - - /* get noise shift */ - st = getScaleFactor16(noise-l_filt, add(l_subfr, shl(l_filt, 1))); - st = add(sub(st, 3), s2); - if (i_subfr == 0) - { - s3 = st; - move16(); - } - tmp16 = sub(st, s3); - IF (tmp16 < 0) - { - nrg_n = L_shl(nrg_n, s_max(-15, shl(tmp16, 1))); - cross_n_d = L_shl(cross_n_d, tmp16); - s3 = st; - move16(); - } - - /* get error shift */ - st = getScaleFactor16(error, l_subfr); - st = sub(st, 3); - if (i_subfr == 0) - { - s4 = st; - move16(); - } - tmp16 = sub(st, s4); - IF (tmp16 < 0) - { - cross_n_d = L_shl(cross_n_d, tmp16); - nrg1 = L_shl(nrg1, shl(tmp16, 1)); - nrg2 = L_shl(nrg2, shl(tmp16, 1)); - s4 = st; - move16(); - } - - nrg1 = L_deposit_l(1); - nrg2 = L_deposit_l(1); + nrg1=1e-6f; + nrg2=1e-6f; /* substract from voiced speech low-pass filtered noise */ - st = sub(s_min(s3, s4), 1); - st2 = sub(s3, s2); - st3 = sub(st,s2); - FOR (i = 0; i < l_subfr; i++) + for (i=0; i/ */ - *gain_factor_param = 2; - move16(); - IF (sub(mode, 2) == 0) + if(mode==2) { - /* *gain_factor_param = (int)(-2.f*(cross_n_d/nrg_n)+0.5f); */ - tmp16 = BASOP_Util_Divide3232_Scale(cross_n_d, nrg_n, &st); /* Q15-st-s3+s4 */ - BASOP_SATURATE_WARNING_OFF; - tmp16 = shl(negate(tmp16), add(sub(add(st, s3), s4), 1-14)); /* Q1 */ - tmp16 = shr(add(tmp16, 1), 1); /* Q0 */ - BASOP_SATURATE_WARNING_ON; - - *gain_factor_param = tmp16; - move16(); - if (sub(tmp16, 3) > 0) + *gain_factor_param = (int)(-2.f*(cross_n_d/nrg_n)+0.5f); + if(*gain_factor_param>3) { - *gain_factor_param = 3; - move16(); + *gain_factor_param=3; } - if (tmp16 < 0) + else if(*gain_factor_param<0) { - *gain_factor_param = 0; - move16(); + *gain_factor_param=0; } - /*If optimal gain negatif or zero but snr still positif->gain=0.5f*/ - test(); - if (snr > 0 && *gain_factor_param == 0) + if(snr>0.f && *gain_factor_param==0) { - *gain_factor_param = 1; - move16(); + *gain_factor_param=1; } } - - mem_bpf->lp_error = lp_error; - move32(); - mem_bpf->noise_shift_old = s2_old; - move16(); + else + { + *gain_factor_param=2; + } - return 0; + return(snr); + } - diff --git a/src/libs/libevs/lib_enc/bw_detect.cpp b/src/libs/libevs/lib_enc/bw_detect.cpp new file mode 100644 index 00000000..04639b0b --- /dev/null +++ b/src/libs/libevs/lib_enc/bw_detect.cpp @@ -0,0 +1,505 @@ +/*==================================================================================== + EVS Codec 3GPP TS26.443 Nov 13, 2018. Version 12.11.0 / 13.7.0 / 14.3.0 / 15.1.0 + ====================================================================================*/ + +#include +#include +#include "options.h" +#include "cnst.h" +#include "rom_enc.h" +#include "rom_com.h" +#include "prot.h" + +/*-------------------------------------------------------------------* + * Local constants + *-------------------------------------------------------------------*/ + +#define ALPHA_BWD 0.75f +#define BWD_LT_THRESH 0.6f + +#define BWD_COUNT_MAX 100 +#define BWD_COUNT_WIDER_BW 10 + +#define CLDFB_ENER_OFFSET 1.6f + +/*-------------------------------------------------------------------* + * bw_detect() + * + * bandwidth detector + *-------------------------------------------------------------------*/ + +void bw_detect( + Encoder_State *st, /* i/o: Encoder State */ + const float signal_in[], /* i : input signal */ + const short localVAD, + float *enerBuffer +) +{ + short i, j, k, bw_max, bin_width, n_bins; + float spect[BWD_TOTAL_WIDTH], in_win[BWD_TOTAL_WIDTH]; + float spect_bin[BWD_N_BINS_MAX]; + float cldfb_bin[9]; + const float *pt, *pt1; + float max_NB, max_WB, max_SWB, max_FB, mean_NB, mean_WB, mean_SWB, mean_FB; + short cldfb_bin_width = 4; + + if( st->input_Fs > 8000 ) + { + if( enerBuffer != NULL ) + { + float ScalFac = 1.0f; + + ScalFac = 1/ ( st->cldfbAnaEnc->scale * st->cldfbAnaEnc->scale * 8.f); + set_f( cldfb_bin, 0.001f, 9 ); + + /* NB: 1.2 - 2.8 kHz, 4 cldfb-bands*/ + cldfb_bin[0] += sum_f( &(enerBuffer[3]), cldfb_bin_width ); + + /* WB: 4.4 - 7.2 kHz, 8 cldfb-bands, mid band(14) counted twice */ + if( st->input_Fs >= 16000 ) + { + cldfb_bin[1] += sum_f( &(enerBuffer[11]), cldfb_bin_width ); + cldfb_bin[2] += sum_f( &(enerBuffer[14]), cldfb_bin_width ); + } + + /* SWB: 9.2 - 15.6 kHz, 16 cldfb-bands */ + if( st->input_Fs >= 32000 ) + { + cldfb_bin[3] += sum_f( &(enerBuffer[23]), cldfb_bin_width ); + cldfb_bin[4] += sum_f( &(enerBuffer[27]), cldfb_bin_width ); + cldfb_bin[5] += sum_f( &(enerBuffer[31]), cldfb_bin_width ); + cldfb_bin[6] += sum_f( &(enerBuffer[35]), cldfb_bin_width ); + } + + /* FB: 16.8 - 20.0 kHz, 8 cldfb-bands */ + if( st->input_Fs >= 48000 ) + { + cldfb_bin[7] += sum_f( &(enerBuffer[42]), cldfb_bin_width ); + cldfb_bin[8] += sum_f( &(enerBuffer[46]), cldfb_bin_width ); + } + + for (i=0; i<9; i++) + { + cldfb_bin[i] = (float)log10( cldfb_bin[i]* ScalFac ); /* see formula used in perform_noise_estimation_enc() for CNG */ + } + + } + else + { + + /* set width of a speactral bin (corresponds to 1.5kHz) */ + if( st->input_Fs == 16000 ) + { + bw_max = WB; + bin_width = 60; + n_bins = 5; /* spectrum to 7.5 kHz */ + } + else if( st->input_Fs == 32000 ) + { + bw_max = SWB; + bin_width = 30; + n_bins = 10; /* spectrum to 15 kHz */ + } + else /* st->input_Fs == 48000 */ + { + bw_max = FB; + bin_width = 20; + n_bins = BWD_N_BINS_MAX; /* spectrum to 19.5 kHz */ + } + + /*---------------------------------------------------------------------* + * windowing of the input signal + *---------------------------------------------------------------------*/ + + pt = signal_in; + pt1 = hann_window_320; + + /* 1st half of the window */ + for( i=0; iinput_Fs == 16000 ) + { + /* for 16kHz sampled inputs, do not check SWB & FB */ + mean_SWB = 0.0f; + max_SWB = 0.0f; + mean_FB = 0.0f; + max_FB = 0.0f; + } + else if( st->input_Fs == 32000 ) + { + /* for 32kHz sampled inputs, do not check FB */ + mean_FB = 0.0f; + max_FB = 0.0f; + mean_SWB = mean( cldfb_bin + 3, 4 ); /* SWB: 9.2 - 15.6 kHz, 16 cldfb-bands (4 bins) */ + maximum ( cldfb_bin + 3, 4 , &max_SWB ); + mean_SWB += CLDFB_ENER_OFFSET; + max_SWB += CLDFB_ENER_OFFSET; + } + else + { + mean_SWB = mean( cldfb_bin + 3, 4 ) ; /* SWB: 9.2 - 15.6 kHz, 16 cldfb-bands (4 bins) */ + maximum ( cldfb_bin + 3, 4 , &max_SWB ); + mean_FB = mean ( cldfb_bin + 7, 2 ); /* FB: 16.8 - 20.0 kHz, 8 cldfb-bands (2 bins) */ + maximum ( cldfb_bin + 7, 2 , &max_FB ); + + mean_SWB += CLDFB_ENER_OFFSET; + max_SWB += CLDFB_ENER_OFFSET; + mean_FB += CLDFB_ENER_OFFSET; + max_FB += CLDFB_ENER_OFFSET; + } + + } + else + { + mean_NB = mean( spect_bin + bwd_start_bin[0], bwd_end_bin[0]-bwd_start_bin[0]+1 ); /* NB: 1.5-3.0kHz (1 bin) */ + maximum ( spect_bin + bwd_start_bin[0], bwd_end_bin[0]-bwd_start_bin[0]+1, &max_NB ); + mean_WB = mean( spect_bin + bwd_start_bin[1], bwd_end_bin[1]-bwd_start_bin[1]+1 ); /* WB: 4.5-7.5kHz (2 bins) */ + maximum( spect_bin + bwd_start_bin[1], bwd_end_bin[1]-bwd_start_bin[1]+1, &max_WB ); + + if( st->input_Fs == 16000 ) + { + /* for 16kHz sampled inputs, do not check SWB & FB */ + mean_SWB = 0.0f; + max_SWB = 0.0f; + mean_FB = 0.0f; + max_FB = 0.0f; + } + else if( st->input_Fs == 32000 ) + { + mean_SWB = mean( spect_bin + bwd_start_bin[2], bwd_end_bin[2]-bwd_start_bin[2]+1 ); /* SWB: 9.0-15.0kHz (4 bins) */ + maximum( spect_bin + bwd_start_bin[2], bwd_end_bin[2]-bwd_start_bin[2]+1, &max_SWB ); + + /* for 32kHz sampled inputs, do not check FB */ + mean_FB = 0.0f; + max_FB = 0.0f; + } + else + { + mean_SWB = mean( spect_bin + bwd_start_bin[2], bwd_end_bin[2]-bwd_start_bin[2]+1 ); /* SWB: 9.0-15.0kHz (4 bins) */ + maximum( spect_bin + bwd_start_bin[2], bwd_end_bin[2]-bwd_start_bin[2]+1, &max_SWB ); + mean_FB = mean( spect_bin + bwd_start_bin[3], bwd_end_bin[3]-bwd_start_bin[3]+1 ); /* FB: 16.5-19.5kHz (2 bins) */ + maximum( spect_bin + bwd_start_bin[3], bwd_end_bin[3]-bwd_start_bin[3]+1, &max_FB ); + } + } + + /*---------------------------------------------------------------------* + * update LT counters and energies + *---------------------------------------------------------------------*/ + + if( localVAD || st->lp_noise > 30 ) + { + st->lt_mean_NB = ALPHA_BWD * st->lt_mean_NB + (1-ALPHA_BWD) * mean_NB; + st->lt_mean_WB = ALPHA_BWD * st->lt_mean_WB + (1-ALPHA_BWD) * mean_WB; + st->lt_mean_SWB = ALPHA_BWD * st->lt_mean_SWB + (1-ALPHA_BWD) * mean_SWB; + + if( enerBuffer != NULL ) + { + if( 0.9f * max_WB > BWD_LT_THRESH * st->lt_mean_NB ) + { + if( 2.5f * max_WB > max_NB ) + { + st->count_WB++; + } + } + else + { + if( 3.5f * mean_WB < mean_NB ) + { + st->count_WB--; + } + } + + if( 0.83f * max_SWB > BWD_LT_THRESH * st->lt_mean_WB && max_WB > BWD_LT_THRESH * st->lt_mean_NB ) + { + if( 2 * max_SWB > max_WB ) + { + st->count_SWB++; + } + } + else + { + if( 3 * mean_SWB < mean_WB ) + { + st->count_SWB--; + } + } + + if( max_FB > BWD_LT_THRESH * st->lt_mean_SWB && 0.83f * max_SWB > BWD_LT_THRESH * st->lt_mean_WB && max_WB > BWD_LT_THRESH * st->lt_mean_NB ) + { + if( 3 * max_FB > max_SWB ) + { + st->count_FB++; + } + } + else + { + if( 4.1f * mean_FB < mean_SWB ) + { + st->count_FB--; + } + } + + } + else + { + if( max_WB > BWD_LT_THRESH * st->lt_mean_NB ) + { + if( 2 * max_WB > max_NB ) + { + st->count_WB++; + } + } + else + { + if( 2.6f * mean_WB < mean_NB ) + { + st->count_WB--; + } + } + + if( max_SWB > BWD_LT_THRESH * st->lt_mean_WB && max_WB > BWD_LT_THRESH * st->lt_mean_NB ) + { + if( 2 * max_SWB > max_WB ) + { + st->count_SWB++; + } + } + else + { + if( 3 * mean_SWB < mean_WB ) + { + st->count_SWB--; + } + } + + if( max_FB > BWD_LT_THRESH * st->lt_mean_SWB && max_SWB > BWD_LT_THRESH * st->lt_mean_WB && max_WB > BWD_LT_THRESH * st->lt_mean_NB ) + { + if( 2 * max_FB > max_SWB ) + { + st->count_FB++; + } + } + else + { + if( 3 * mean_FB < mean_SWB ) + { + st->count_FB--; + } + } + } + + st->count_WB = min(st->count_WB,BWD_COUNT_MAX); + st->count_SWB = min(st->count_SWB,BWD_COUNT_MAX); + st->count_FB = min(st->count_FB,BWD_COUNT_MAX); + st->count_WB = max(st->count_WB,0); + st->count_SWB = max(st->count_SWB,0); + st->count_FB = max(st->count_FB,0); + + /*---------------------------------------------------------------------* + * check against thresholds + * detect a band-width change + *---------------------------------------------------------------------*/ + + /* switching to a higher BW */ + if( st->last_input_bwidth == NB ) + { + if( st->count_WB > BWD_COUNT_WIDER_BW ) + { + st->input_bwidth = WB; + st->count_WB = BWD_COUNT_MAX; + + if( st->count_SWB > BWD_COUNT_WIDER_BW ) + { + st->input_bwidth = SWB; + st->count_SWB = BWD_COUNT_MAX; + + if( st->count_FB > BWD_COUNT_WIDER_BW ) + { + st->input_bwidth = FB; + st->count_FB = BWD_COUNT_MAX; + } + } + } + } + + if( st->last_input_bwidth == WB && st->input_Fs > 16000 ) + { + if( st->count_SWB > BWD_COUNT_WIDER_BW ) + { + st->input_bwidth = SWB; + st->count_SWB = BWD_COUNT_MAX; + + if( st->count_FB > BWD_COUNT_WIDER_BW ) + { + st->input_bwidth = FB; + st->count_FB = BWD_COUNT_MAX; + } + } + } + + if( st->last_input_bwidth == SWB && st->input_Fs > 32000 ) + { + if( st->count_FB > BWD_COUNT_WIDER_BW ) + { + st->input_bwidth = FB; + st->count_FB = BWD_COUNT_MAX; + } + } + + /* switching to a lower BW */ + if( st->last_input_bwidth == FB ) + { + if( st->count_FB < 10 ) + { + st->input_bwidth = SWB; + st->count_FB = 0; + } + if( st->count_SWB < 10 ) + { + st->input_bwidth = WB; + st->count_SWB = 0; + st->count_FB = 0; + } + if( st->count_WB < 10 ) + { + st->input_bwidth = NB; + st->count_WB = 0; + st->count_SWB = 0; + st->count_FB = 0; + } + } + + if( st->last_input_bwidth == SWB ) + { + if( st->count_SWB < 10 ) + { + st->input_bwidth = WB; + st->count_SWB = 0; + st->count_FB = 0; + } + if( st->count_WB < 10 ) + { + st->input_bwidth = NB; + st->count_WB = 0; + st->count_SWB = 0; + st->count_FB = 0; + } + } + + if( st->last_input_bwidth == WB ) + { + if( st->count_WB < 10 ) + { + st->input_bwidth = NB; + st->count_WB = 0; + st->count_SWB = 0; + st->count_FB = 0; + } + } + } + } + + /* verify that maximum encoded bandwidth (specified on the command line) is not exceeded */ + if( st->input_bwidth > st->max_bwidth ) + { + st->input_bwidth = st->max_bwidth; + } + + + /* Set and limit the encoded bandwidth */ + if ( st->codec_mode == MODE1 ) + { + long total_brate; + + st->bwidth = st->input_bwidth; + total_brate = st->total_brate; + if ( total_brate <= ACELP_9k60 && st->bwidth != NB && st->bwidth != WB ) + { + st->bwidth = WB; + } + else if ( total_brate >= ACELP_13k20 && total_brate <= ACELP_16k40 && st->bwidth > SWB ) + { + st->bwidth = SWB; + } + else if ( total_brate >= ACELP_32k && st->bwidth < WB ) + { + st->bwidth = WB; + } + } + else + { + short n, bits_frame_nominal, tmpBandwidthMin; + + bits_frame_nominal = st->total_brate / 50; + for( n=0; nrf_mode ) + { + tmpBandwidthMin = WB; + } + + st->bwidth = max(min(st->input_bwidth, FrameSizeConfig[n].bandwidth_max), tmpBandwidthMin); + } + + return; +} diff --git a/src/libs/libevs/lib_enc/bw_detect_fx.cpp b/src/libs/libevs/lib_enc/bw_detect_fx.cpp deleted file mode 100755 index a507b333..00000000 --- a/src/libs/libevs/lib_enc/bw_detect_fx.cpp +++ /dev/null @@ -1,915 +0,0 @@ -/*==================================================================================== - EVS Codec 3GPP TS26.442 Apr 03, 2018. Version 12.11.0 / 13.6.0 / 14.2.0 - ====================================================================================*/ - -#include -#include "options.h" /* Compilation switches */ -#include "cnst_fx.h" /* Common constants */ -#include "rom_enc_fx.h" /* Encoder static table prototypes */ -#include "prot_fx.h" /* Function prototypes */ -#include "stl.h" - -#include "rom_com_fx.h" -#include "basop_util.h" - -/*-------------------------------------------------------------------* - * Local constants - *-------------------------------------------------------------------*/ - -#define ALPHA_BWD_FX 24576 /* 0.75 in Q15*/ -#define BWD_LT_THRESH_FX 19661 /* 0.6 in Q15*/ - -#define BWD_COUNT_MAX 100 -#define BWD_COUNT_WIDER_BW 10 - -#define BWD_N_BINS_MAX 13 - -#define CLDFB_ENER_OFFSET_FX 26214 /* 1.6 in Q14 */ - -/*-------------------------------------------------------------------* - * bw_detect() - * - * WB, SWB and FB bandwidth detector - *--------------------------------------------------------------------*/ - -void bw_detect_fx( - Encoder_State_fx *st, /* i/o: Encoder State */ - const Word16 signal_in[], /* i : input signal */ - const Word16 localVAD, - Word32 *enerBuffer, /* i : CLDFB Energy Q31 */ - Word16 *cldfbBuf_Ener_Exp /* i : CLDFB Energy Exponent */ -) -{ - Word16 Q_dct; - Word16 i, j, k, bw_max, bin_width, n_bins; - Word16 max_NB, max_WB, max_SWB, max_FB, mean_NB, mean_WB, mean_SWB, mean_FB; /* Q11*/ - const Word16 *pt, *pt1; - Word16 spect[BWD_TOTAL_WIDTH], spect_bin[BWD_N_BINS_MAX]; - Word32 spect32[BWD_TOTAL_WIDTH],in_win32[BWD_TOTAL_WIDTH]; - Word16 e_tmp, f_tmp; - Word32 L_tmp, sum32; - - Word32 L_tmp1, L_tmp2, L_tmp3; - Word16 scale; - Word16 ScalFac, ScalFacInv; - Word32 cldfb_bin[9]; - Word16 cldfb_bin_Exp[9]; - Word16 cldfb_bin_width = 4; - const Word32 *pt32; - Word32 max_NB32, max_WB32, max_SWB32, max_FB32, mean_NB32, mean_WB32, mean_SWB32, mean_FB32; /* Q11*/ /* we need Word32 for the new cldfb energy vectors */ - - /* only for debugging */ - /* float cldfbBuf_Ener_float[CLDFB_NO_CHANNELS_MAX]; - for(i=0; i< CLDFB_NO_CHANNELS_MAX; i++){ - cldfbBuf_Ener_float[i] = (enerBuffer[i] * pow (2, -(31 - cldfbBuf_Ener_Exp[i]))); - } - */ - - IF( L_sub(st->input_Fs_fx,8000) > 0 ) - { - - IF ( enerBuffer != NULL) - { - n_bins = 9; - move16(); - scale = st->cldfbAna_Fx->scale; - move16();/* 7Q8 */ - - /*ScalFac = 1/ ( st->cldfbAnaEnc->scale * st->cldfbAnaEnc->scale * 8.f);*/ - /*hs->CLDFBscalingFactor = div_s(1, shl(i_mult2(CLDFBscale, CLDFBscale), 3));*/ - - assert(2048/*1.0/(1<<4) Q15*/ < mult(scale, scale)); - /* Exponent ScalFacInv: -16 = -(2*7 (CLDFBscale) + 2 (8.0) */ - ScalFacInv = shl(mult(scale,scale),1); /* Q8*Q8 = Q16 + shl -> Q17 -16 -> Q1; shl -> Q2 */ - /* Exponent ScalFac: -15 = -(2*7 (CLDFBscale) + 2 (8.0) - 1 (1.0)) */ - ScalFac = div_s(0x4000,ScalFacInv); /* bin(17214) *2^-15 * 2^-15 = 0.0000160 , use CLDFBscalingFactor_EXP for this*/ /*Q15*/ - - - /*set_f( cldfb_bin, 0.001f, 9 );*/ - set32_fx( cldfb_bin, 1, n_bins ); /* Q31*/ - set16_fx( cldfb_bin_Exp, -15, n_bins ); - - /* NB: 1.2 - 2.8 kHz, 4 cldfb-bands */ - FOR(i=0; i< cldfb_bin_width; i++ ) - { - cldfb_bin[0] = BASOP_Util_Add_Mant32Exp( cldfb_bin[0],cldfb_bin_Exp[0], enerBuffer[3+i], cldfbBuf_Ener_Exp[3+i], &(cldfb_bin_Exp[0]) ); - move32();/* result: Q31 */ - } - - cldfb_bin[0] = Mpy_32_16_1(cldfb_bin[0], ScalFac ); - move32(); /* Q31 */ - cldfb_bin_Exp[0] = add( cldfb_bin_Exp[0], CLDFBscalingFactor_EXP); - move16(); - - if(cldfb_bin[i] == 0) - { - cldfb_bin[i] = L_deposit_l(1); - } - L_tmp = BASOP_Util_Log2(cldfb_bin[0]); /*(log2(660423549*2^(-31))/64)*2^31*/ - L_tmp = L_add(L_tmp,L_shl(L_deposit_l(cldfb_bin_Exp[0]),31-LD_DATA_SCALE)); /* Q25 */ - cldfb_bin[0] = Mpy_32_16_1(L_tmp, 9864/*1.0f/3.3219280948873623478703194294894f Q15*/); - move32();/* 1/log2(10) */ /* Q25 */ - - /* WB: 4.4 - 7.2 kHz, 8 cldfb-bands, mid band(14) counted twice */ - IF( L_sub(st->input_Fs_fx,16000) >= 0 ) - { - /* - cldfb_bin[1] += Sum( &(enerBuffer[11]), cldfb_bin_width ); - cldfb_bin[2] += Sum( &(enerBuffer[14]), cldfb_bin_width );*/ - FOR(i=0; i< cldfb_bin_width; i++ ) - { - cldfb_bin[1] = BASOP_Util_Add_Mant32Exp( cldfb_bin[1],cldfb_bin_Exp[1], enerBuffer[11+i], cldfbBuf_Ener_Exp[11+i], &(cldfb_bin_Exp[1]) ); - move32(); - cldfb_bin[2] = BASOP_Util_Add_Mant32Exp( cldfb_bin[2],cldfb_bin_Exp[2], enerBuffer[14+i], cldfbBuf_Ener_Exp[14+i], &(cldfb_bin_Exp[2]) ); - move32(); - } - FOR(i=1; i<= 2; i++ ) - { - cldfb_bin[i] = Mpy_32_16_1(cldfb_bin[i], ScalFac ); - move32(); - cldfb_bin_Exp[i] = add( cldfb_bin_Exp[i], CLDFBscalingFactor_EXP); - move16(); - - if(cldfb_bin[i] == 0) - { - cldfb_bin[i] = L_deposit_l(1); - } - L_tmp = BASOP_Util_Log2(cldfb_bin[i]); /*(log2(660423549*2^(-31))/64)*2^31*/ - L_tmp = L_add(L_tmp,L_shl(L_deposit_l(cldfb_bin_Exp[i]),31-LD_DATA_SCALE)); /* Q25 */ - cldfb_bin[i] = Mpy_32_16_1(L_tmp, 9864/*1.0f/3.3219280948873623478703194294894f Q15*/); - move32();/* 1/log2(10) */ /* Q25 */ - } - } - - /* SWB: 9.2 - 15.6 kHz, 16 cldfb-bands */ - IF( L_sub(st->input_Fs_fx,32000) >= 0 ) - { - /* - cldfb_bin[3] += Sum( &(enerBuffer[23]), cldfb_bin_width ); - cldfb_bin[4] += Sum( &(enerBuffer[27]), cldfb_bin_width ); - cldfb_bin[5] += Sum( &(enerBuffer[31]), cldfb_bin_width ); - cldfb_bin[6] += Sum( &(enerBuffer[35]), cldfb_bin_width ); - */ - FOR(i=0; i< cldfb_bin_width; i++ ) - { - cldfb_bin[3] = BASOP_Util_Add_Mant32Exp( cldfb_bin[3],cldfb_bin_Exp[3], enerBuffer[23+i], cldfbBuf_Ener_Exp[23+i], &(cldfb_bin_Exp[3]) ); - move32(); - cldfb_bin[4] = BASOP_Util_Add_Mant32Exp( cldfb_bin[4],cldfb_bin_Exp[4], enerBuffer[27+i], cldfbBuf_Ener_Exp[27+i], &(cldfb_bin_Exp[4]) ); - move32(); - cldfb_bin[5] = BASOP_Util_Add_Mant32Exp( cldfb_bin[5],cldfb_bin_Exp[5], enerBuffer[31+i], cldfbBuf_Ener_Exp[31+i], &(cldfb_bin_Exp[5]) ); - move32(); - cldfb_bin[6] = BASOP_Util_Add_Mant32Exp( cldfb_bin[6],cldfb_bin_Exp[6], enerBuffer[35+i], cldfbBuf_Ener_Exp[35+i], &(cldfb_bin_Exp[6]) ); - move32(); - } - FOR(i=3; i<= 6; i++ ) - { - cldfb_bin[i] = Mpy_32_16_1(cldfb_bin[i], ScalFac ); - move32(); - cldfb_bin_Exp[i] = add( cldfb_bin_Exp[i], CLDFBscalingFactor_EXP); - move16(); - - if(cldfb_bin[i] == 0) - { - cldfb_bin[i] = L_deposit_l(1); - } - L_tmp = BASOP_Util_Log2(cldfb_bin[i]); /*(log2(660423549*2^(-31))/64)*2^31*/ - L_tmp = L_add(L_tmp,L_shl(L_deposit_l(cldfb_bin_Exp[i]),31-LD_DATA_SCALE)); /* Q25 */ - cldfb_bin[i] = Mpy_32_16_1(L_tmp, 9864/*1.0f/3.3219280948873623478703194294894f Q15*/); - move32();/* 1/log2(10) */ /* Q25 */ - } - } - - /* FB: 16.8 - 20.0 kHz, 8 cldfb-bands */ - IF( L_sub(st->input_Fs_fx,48000) >= 0 ) - { - /* - cldfb_bin[7] += Sum( &(enerBuffer[42]), cldfb_bin_width ); - cldfb_bin[8] += Sum( &(enerBuffer[46]), cldfb_bin_width ); - */ - FOR(i=0; i< cldfb_bin_width; i++ ) - { - cldfb_bin[7] = BASOP_Util_Add_Mant32Exp( cldfb_bin[7],cldfb_bin_Exp[7], enerBuffer[42+i], cldfbBuf_Ener_Exp[42+i], &(cldfb_bin_Exp[7]) ); - move32(); - cldfb_bin[8] = BASOP_Util_Add_Mant32Exp( cldfb_bin[8],cldfb_bin_Exp[8], enerBuffer[46+i], cldfbBuf_Ener_Exp[46+i], &(cldfb_bin_Exp[8]) ); - move32(); - } - FOR(i=7; i<= 8; i++ ) - { - cldfb_bin[i] = Mpy_32_16_1(cldfb_bin[i], ScalFac ); - move32(); - cldfb_bin_Exp[i] = add( cldfb_bin_Exp[i], CLDFBscalingFactor_EXP); - move16(); - - if(cldfb_bin[i] == 0) - { - cldfb_bin[i] = L_deposit_l(1); - } - L_tmp = BASOP_Util_Log2(cldfb_bin[i]); /*(log2(660423549*2^(-31))/64)*2^31*/ - L_tmp = L_add(L_tmp,L_shl(L_deposit_l(cldfb_bin_Exp[i]),31-LD_DATA_SCALE)); /* Q25 */ - cldfb_bin[i] = Mpy_32_16_1(L_tmp, 9864/*1.0f/3.3219280948873623478703194294894f Q15*/); - move32();/* 1/log2(10) */ /* Q25 */ - } - } - /* cldfb_bin_Exp[] are applied now in cldfb_bin[i] -> don't use again */ - set16_fx( cldfb_bin_Exp, 0, n_bins ); - - } - ELSE - { - - /* set width of a speactral bin (corresponds to 1.5kHz) */ - IF( L_sub(st->input_Fs_fx,16000) == 0 ) - { - bw_max = WB; - move16(); - bin_width = 60; - move16(); - n_bins = 5; - move16(); /* spectrum to 7.5 kHz */ - } - ELSE IF( L_sub(st->input_Fs_fx,32000) == 0 ) - { - bw_max = SWB; - move16(); - bin_width = 30; - move16(); - n_bins = 10; - move16(); /* spectrum to 15.0 kHz */ - } - ELSE /* st->input_Fs == 48000 */ - { - bw_max = FB; - move16(); - bin_width = 20; - move16(); - n_bins = BWD_N_BINS_MAX; - move16(); /* spectrum to 19.5 kHz */ - } - - /*---------------------------------------------------------------------* - * windowing of the input signal - *---------------------------------------------------------------------*/ - Q_dct = 0; - move16(); - pt = signal_in; - pt1 = hann_window_320_fx; - /* 1st half of the window */ - FOR( i=0; i Q16*/ - } - pt1--; - /* 2nd half of the window */ - FOR(; i Q25 */ - - mean_NB = extract_l(L_shr( L_add(mean_NB32 ,cldfb_ener_offset_32), 25-11)); /* (Q25 + Q25) -> Q11 */ - max_NB = extract_l(L_shr( L_add(max_NB32 ,cldfb_ener_offset_32), 25-11)); /* (Q25 + Q25) -> Q11 */ - mean_WB = extract_l(L_shr( L_add(mean_WB32 ,cldfb_ener_offset_32), 25-11)); /* (Q25 + Q25) -> Q11 */ - max_WB = extract_l(L_shr( L_add(max_WB32 ,cldfb_ener_offset_32), 25-11)); /* (Q25 + Q25) -> Q11 */ - - - /*if WB */ - IF( L_sub(st->input_Fs_fx,16000) == 0 ) - { - /* for 16kHz sampled inputs, do not check SWB & FB */ - mean_SWB = 0; - move16(); - max_SWB = 0; - move16(); - mean_FB = 0; - move16(); - max_FB = 0; - move16(); - } - ELSE - { - /* else if SWB */ - IF( L_sub(st->input_Fs_fx,32000) == 0 ) - { - - /* for 32kHz sampled inputs, do not check FB */ - mean_FB = 0; - move16(); - max_FB = 0; - move16(); - - /* SWB: 8,8 - 15,2 kHz, 16 cldfb-bands (4 bins) */ - - maximum_32_fx( pt32, 4, &max_SWB32 ); - - L_tmp = L_shr(*pt32++, 2); /* /4 */ - L_tmp = L_add(L_tmp,L_shr(*pt32++, 2)); - L_tmp = L_add(L_tmp,L_shr(*pt32++, 2)); - mean_SWB32 = L_add(L_tmp,L_shr(*pt32++, 2)); - - mean_SWB = extract_l(L_shr(L_add(mean_SWB32, cldfb_ener_offset_32), 25-11)); /* (Q25 + Q25) -> Q11 */ - max_SWB = extract_l(L_shr(L_add(max_SWB32 , cldfb_ener_offset_32), 25-11)); /* (Q25 + Q25) -> Q11 */ - - } - ELSE - { /* FB */ - /* SWB: 8,8 - 15,2 kHz, 16 cldfb-bands (4 bins) */ - - maximum_32_fx( pt32, 4, &max_SWB32 ); - - L_tmp = L_shr(*pt32++, 2); /* /4 */ - L_tmp = L_add(L_tmp,L_shr(*pt32++, 2)); - L_tmp = L_add(L_tmp,L_shr(*pt32++, 2)); - mean_SWB32 = L_add(L_tmp,L_shr(*pt32++, 2)); - - mean_SWB = extract_l(L_shr(L_add(mean_SWB32, cldfb_ener_offset_32), 25-11)); /* (Q25 + Q25) -> Q11 */ - max_SWB = extract_l(L_shr(L_add(max_SWB32 , cldfb_ener_offset_32), 25-11)); /* (Q25 + Q25) -> Q11 */ - - - /* FB: 16,4 - 19,6 kHz, 8 cldfb-bands (2 bins) */ - - maximum_32_fx( pt32, 2, &max_FB32 ); - - L_tmp = L_shr(*pt32++, 1); - mean_FB32 = L_add(L_tmp,L_shr(*pt32++, 1)); - - mean_FB = extract_l(L_shr(L_add(mean_FB32, cldfb_ener_offset_32), 25-11)); /* (Q25 + Q25) -> Q11 */ - max_FB = extract_l(L_shr(L_add(max_FB32 , cldfb_ener_offset_32), 25-11)); /* (Q25 + Q25) -> Q11 */ - - } - } - } - ELSE - { - pt = (const Word16 *)spect_bin; - /* NB: 1.5-3.0kHz (1 bin) */ - pt++; - mean_NB = *pt++; - move16(); - max_NB = mean_NB; - move16(); - - /* WB: 4.5-7.5kHz (2 bins) */ - pt++; - maximum_fx( pt, 2, &max_WB ); - L_tmp = L_mult(*pt++,16384); - L_tmp = L_mac(L_tmp,*pt++,16384); - mean_WB = round_fx(L_tmp); - - IF( L_sub(st->input_Fs_fx,16000) == 0 ) - { - /* for 16kHz sampled inputs, do not check SWB & FB */ - mean_SWB = 0; - move16(); - max_SWB = 0; - move16(); - mean_FB = 0; - move16(); - max_FB = 0; - move16(); - } - ELSE - { - /* SWB: 9.0-15.0kHz (4 bins) */ - pt++; - maximum_fx( pt, 4, &max_SWB ); - L_tmp = L_mult(*pt++,8192); - L_tmp = L_mac(L_tmp,*pt++,8192); - L_tmp = L_mac(L_tmp,*pt++,8192); - L_tmp = L_mac(L_tmp,*pt++,8192); - mean_SWB = round_fx(L_tmp); - - IF( L_sub(st->input_Fs_fx,48000) == 0 ) - { - /* FB: 16.5-19.5kHz (2 bins) */ - pt++; - maximum_fx( pt, 2, &max_FB ); - L_tmp = L_mult(*pt++,16384); - L_tmp = L_mac(L_tmp,*pt++,16384); - mean_FB = round_fx(L_tmp); - } - ELSE - { - /* for 32kHz sampled inputs, do not check FB */ - mean_FB = 0; - move16(); - max_FB = 0; - move16(); - } - } - } - /*---------------------------------------------------------------------* - * update LT counters and energies - *---------------------------------------------------------------------*/ - - /*if( localVAD || st->lp_noise > 30 )*/ - test(); - IF( localVAD || sub(st->lp_noise_fx,7680) > 0 ) - { - /*st->lt_mean_NB_fx = ALPHA_BWD * st->lt_mean_NB_fx + (1-ALPHA_BWD) * mean_NB;*/ - L_tmp = L_mult(ALPHA_BWD_FX, st->lt_mean_NB_fx); /* Q15 * Q11 -> Q27 */ - L_tmp = L_mac(L_tmp, 32768-ALPHA_BWD_FX, mean_NB); /* Q15 * Q11) -> L_mac(Q27, Q27) -> Q27*/ - st->lt_mean_NB_fx = round_fx(L_tmp); /* Q11 (27-16) */ - - /*st->lt_mean_WB_fx = ALPHA_BWD * st->lt_mean_WB_fx + (1-ALPHA_BWD) * mean_WB;*/ - L_tmp = L_mult(ALPHA_BWD_FX, st->lt_mean_WB_fx); - L_tmp = L_mac(L_tmp, 32768-ALPHA_BWD_FX, mean_WB); - st->lt_mean_WB_fx = round_fx(L_tmp); - - /*st->lt_mean_SWB_fx = ALPHA_BWD * st->lt_mean_SWB_fx + (1-ALPHA_BWD) * mean_SWB;*/ - L_tmp = L_mult(ALPHA_BWD_FX, st->lt_mean_SWB_fx); - L_tmp = L_mac(L_tmp, 32768-ALPHA_BWD_FX, mean_SWB); - st->lt_mean_SWB_fx = round_fx(L_tmp); - - - - IF ( enerBuffer != NULL ) - { - /*if( 0.9f * max_WB > BWD_LT_THRESH_FX * st->lt_mean_NB_fx )*/ - - /* optim: if( max_WB > (BWD_LT_THRESH_FX / 0.9) * st->lt_mean_NB_fx )*/ - - L_tmp = L_mult(3686,max_WB); /* (0.9 in Q12) x Q11 -> Q24*/ - - L_tmp1 = L_mult(BWD_LT_THRESH_FX,st->lt_mean_NB_fx); /* Q15 x Q11 -> Q27 */ - L_tmp1 = L_shl(L_tmp1, 24-27); /* Q27 -> Q24) */ - L_tmp1 = L_sub(L_tmp, L_tmp1 ); - - IF( L_tmp1 > 0 ) - { - /*if( 2.5f * max_WB > max_NB )*/ - L_tmp = L_mult(10240,max_WB); /* 2.5 in Q12 x Q11 -> Q24 */ - L_tmp1 = L_mult(max_NB, 4096); /* Q11 x (1 in Q12) -> Q24 */ - IF( L_sub(L_tmp,L_tmp1) > 0 ) /* Q24 */ - { - st->count_WB_fx = add(st->count_WB_fx,1); - } - } - ELSE - { - /*if( 3.5f * mean_WB < mean_NB )*/ - L_tmp = L_mult(14336,mean_WB); /* 3.5 in Q12 x Q11 -> Q24*/ - L_tmp1 = L_mult(mean_NB,4096); - L_tmp = L_sub(L_tmp, L_tmp1); - IF( L_tmp < 0 ) - { - st->count_WB_fx = sub(st->count_WB_fx, 1); - } - } - - /*if( 0.83f * max_SWB > BWD_LT_THRESH_FX * st->lt_mean_WB_fx && max_WB > BWD_LT_THRESH_FX * st->lt_mean_NB_fx )*/ - /* IF( L_msu( L_tmp,BWD_LT_THRESH_FX,st->lt_mean_WB_fx) > 0 && L_msu( L_deposit_h(max_WB),BWD_LT_THRESH_FX,st->lt_mean_NB_fx) > 0 ) - {*/ - - L_tmp = L_mult(3400,max_SWB); /* (0.83 in Q12) x Q11 -> Q24*/ - L_tmp1 = L_mult(BWD_LT_THRESH_FX,st->lt_mean_WB_fx); /* Q15 x Q11 -> Q27 */ - L_tmp1 = L_shl(L_tmp1, 24-27); /* Q27 -> Q24) */ - L_tmp1 = L_sub(L_tmp, L_tmp1 ); - - L_tmp = L_mult( max_WB,4096); - L_tmp2 = L_mult(BWD_LT_THRESH_FX,st->lt_mean_NB_fx); /* Q15 x Q11 -> Q27 */ - L_tmp2 = L_shl(L_tmp2, 24-27); /* Q27 -> Q24) */ - L_tmp2 = L_sub(L_tmp, L_tmp2 ); - - test(); - IF(L_tmp1 > 0 && L_tmp2 > 0 ) - { - /*if( 2 * max_SWB > max_WB )*/ - L_tmp = L_mult(max_WB,4096); - L_tmp1 = L_mult(8192,max_SWB); /* 2.0 in Q12 x Q11 -> Q24*/ - L_tmp1 = L_sub(L_tmp1, L_tmp); /* Q24 - (Q11 x (1 in Q12) ) = Q24 */ - IF(L_tmp1 > 0 ) - { - st->count_SWB_fx = add(st->count_SWB_fx, 1); - } - } - ELSE - { - /*if( 3 * mean_SWB < mean_WB )*/ - L_tmp = L_mult(mean_WB,4096); - L_tmp1 = L_mult(12288,mean_SWB); /* 3.0 in Q12 x Q11 -> Q24*/ - L_tmp1 = L_sub(L_tmp1,L_tmp); /* Q24 - (Q11 x (1 in Q12) ) = Q24 */ - IF(L_tmp1 < 0 ) - { - st->count_SWB_fx = sub(st->count_SWB_fx,1); - } - } - /*if( max_FB > BWD_LT_THRESH_FX * st->lt_mean_SWB_fx && 0.83f * max_SWB > BWD_LT_THRESH_FX * st->lt_mean_WB_fx && max_WB > BWD_LT_THRESH_FX * st->lt_mean_NB_fx )*/ - - L_tmp = L_mult(max_FB, 4096); /* Q11 x (1 in Q12) = Q24 */ - L_tmp1 = L_mult(BWD_LT_THRESH_FX, st->lt_mean_SWB_fx); /* Q15 x Q11 -> Q27 */ - L_tmp1 = L_shl(L_tmp1, 24-27); /* Q27 -> Q24) */ - L_tmp1 = L_sub( L_tmp, L_tmp1); /* Q24 */ - - L_tmp = L_mult(max_SWB, 3400 ); /* (0.83 in Q12) x Q11) = Q24 */ - L_tmp2 = L_mult(BWD_LT_THRESH_FX,st->lt_mean_WB_fx); /* Q15 x Q11 -> Q27 */ - L_tmp2 = L_shl(L_tmp2, 24-27); /* Q27 -> Q24) */ - L_tmp2 = L_sub(L_tmp, L_tmp2 ); /* Q24 */ - - L_tmp = L_mult(max_WB,4096); /* Q11 x (1 in Q12) = Q24*/ - - L_tmp3 = L_mult(BWD_LT_THRESH_FX,st->lt_mean_NB_fx); /* Q15 x Q11 -> Q27 */ - L_tmp3 = L_shl(L_tmp3, 24-27); /* Q27 -> Q24) */ - L_tmp3 = L_sub(L_tmp, L_tmp3 ); - - test(); - test(); - IF(L_tmp1 > 0 && L_tmp2 > 0 && L_tmp3 > 0 ) - { - /*if( 3 * max_FB > max_SWB )*/ - L_tmp = L_mult( max_SWB,4096 ); /* Q11 x (1 in Q12) = Q24*/ - L_tmp1 = L_mult(12288,max_FB); /* 3.0 in Q12 x Q11 -> Q24*/ - L_tmp1 = L_sub(L_tmp1, L_tmp); /* Q24 */ - IF(L_tmp1 > 0 ) - { - st->count_FB_fx = add(st->count_FB_fx,1); - } - } - ELSE - { - /* if( 4.1f * mean_FB < mean_SWB )*/ - L_tmp = L_mult(mean_SWB,4096); /* Q11 x (1 in Q12) = Q24 */ - L_tmp1 = L_mult(16794,mean_FB); /* 4.1 in Q12 x Q11 -> Q24*/ - L_tmp1 = L_sub(L_tmp1,L_tmp); /* Q24 */ - IF(L_tmp1 < 0 ) - { - st->count_FB_fx = sub(st->count_FB_fx,1); - } - } - - } - ELSE /* DCT based detection */ - { - /*if( max_WB > BWD_LT_THRESH * st->lt_mean_NB_fx )*/ - IF( L_msu( L_deposit_h(max_WB),BWD_LT_THRESH_FX,st->lt_mean_NB_fx) > 0 ) - { - /*if( 2 * max_WB > max_NB )*/ - L_tmp = L_mult(8192,max_WB); /* 2.0 in Q12 x Q11 -> Q24*/ - if( L_msu(L_tmp,max_NB,4096) > 0 ) - { - st->count_WB_fx = add(st->count_WB_fx,1); - } - } - ELSE - { - /*if( 2.6f * mean_WB < mean_NB )*/ - L_tmp = L_mult(10650,mean_WB); /* 2.6 in Q12 x Q11 -> Q24*/ - L_tmp = L_msu(L_tmp,mean_NB,4096); - test(); - test(); - if( L_tmp < 0 && !(sub(mean_WB,-1) == 0 && sub(mean_NB,-1) == 0) ) - { - st->count_WB_fx = sub(st->count_WB_fx, 1); - } - } - - test(); - /*if( max_SWB > BWD_LT_THRESH * st->lt_mean_WB_fx && max_WB > BWD_LT_THRESH * st->lt_mean_NB_fx )*/ - test(); - IF( L_msu( L_deposit_h(max_SWB),BWD_LT_THRESH_FX,st->lt_mean_WB_fx) > 0 && L_msu( L_deposit_h(max_WB),BWD_LT_THRESH_FX,st->lt_mean_NB_fx) > 0 ) - { - /*if( 2 * max_SWB > max_WB )*/ - L_tmp = L_mult(8192,max_SWB); /* 2.0 in Q12 x Q11 -> Q24*/ - if( L_msu(L_tmp,max_WB,4096) > 0 ) - { - st->count_SWB_fx = add(st->count_SWB_fx,1); - } - } - ELSE - { - /*if( 3 * mean_SWB < mean_WB )*/ - L_tmp = L_mult(12288,mean_SWB); /* 3.0 in Q12 x Q11 -> Q24*/ - L_tmp = L_msu(L_tmp,mean_WB,4096); - test(); - test(); - if( L_tmp < 0 && !(sub(mean_SWB,-1) == 0 && sub(mean_WB,-1) == 0) ) - { - st->count_SWB_fx = sub(st->count_SWB_fx,1); - } - } - - test(); - test(); - /*if( max_FB > BWD_LT_THRESH * st->lt_mean_SWB_fx && max_SWB > BWD_LT_THRESH * st->lt_mean_WB_fx && max_WB > BWD_LT_THRESH * st->lt_mean_NB_fx )*/ - IF( L_msu( L_deposit_h(max_FB),BWD_LT_THRESH_FX,st->lt_mean_SWB_fx) > 0 && L_msu( L_deposit_h(max_SWB),BWD_LT_THRESH_FX,st->lt_mean_WB_fx) > 0 && L_msu( L_deposit_h(max_WB),BWD_LT_THRESH_FX,st->lt_mean_NB_fx) > 0 ) - { - /*if( 2 * max_FB > max_SWB )*/ - L_tmp = L_mult(8192,max_FB); /* 2.0 in Q12 x Q11 -> Q24*/ - if( L_msu(L_tmp,max_SWB,4096) > 0 ) - { - st->count_FB_fx = add(st->count_FB_fx,1); - } - } - ELSE - { - /*if( 3 * mean_FB < mean_SWB )*/ - L_tmp = L_mult(12288,mean_FB); /* 3.0 in Q12 x Q11 -> Q24*/ - test(); - test(); - if( L_msu(L_tmp,mean_SWB,4096) < 0 && !(sub(mean_FB,-1) == 0 && sub(mean_SWB,-1) == 0) ) - { - st->count_FB_fx = sub(st->count_FB_fx,1); - } - } - } - - st->count_WB_fx = s_min(st->count_WB_fx,BWD_COUNT_MAX); - move16(); - st->count_SWB_fx = s_min(st->count_SWB_fx,BWD_COUNT_MAX); - move16(); - st->count_FB_fx = s_min(st->count_FB_fx,BWD_COUNT_MAX); - move16(); - st->count_WB_fx = s_max(st->count_WB_fx,0); - move16(); - st->count_SWB_fx = s_max(st->count_SWB_fx,0); - move16(); - st->count_FB_fx = s_max(st->count_FB_fx,0); - move16(); - - /*---------------------------------------------------------------------* - * check against thresholds - * detect a band-width change - *---------------------------------------------------------------------*/ - - /* switching to a higher BW */ - IF( sub(st->last_input_bwidth_fx,NB) == 0 ) - { - IF( sub(st->count_WB_fx,BWD_COUNT_WIDER_BW) > 0 ) - { - st->input_bwidth_fx = WB; - move16(); - st->count_WB_fx = BWD_COUNT_MAX; - move16(); - - IF( sub(st->count_SWB_fx,BWD_COUNT_WIDER_BW) > 0 ) - { - st->input_bwidth_fx = SWB; - move16(); - st->count_SWB_fx = BWD_COUNT_MAX; - move16(); - - IF( sub(st->count_FB_fx,BWD_COUNT_WIDER_BW) > 0 ) - { - st->input_bwidth_fx = FB; - move16(); - st->count_FB_fx = BWD_COUNT_MAX; - move16(); - } - } - } - } - - test(); - IF( sub(st->last_input_bwidth_fx,WB) == 0 && L_sub(st->input_Fs_fx,16000) > 0 ) - { - IF( sub(st->count_SWB_fx,BWD_COUNT_WIDER_BW) > 0 ) - { - st->input_bwidth_fx = SWB; - move16(); - st->count_SWB_fx = BWD_COUNT_MAX; - move16(); - - IF( sub(st->count_FB_fx,BWD_COUNT_WIDER_BW) > 0 ) - { - st->input_bwidth_fx = FB; - move16(); - st->count_FB_fx = BWD_COUNT_MAX; - move16(); - } - } - } - - test(); - IF( sub(st->last_input_bwidth_fx,SWB) == 0 && L_sub(st->input_Fs_fx,32000) > 0 ) - { - IF( sub(st->count_FB_fx,BWD_COUNT_WIDER_BW) > 0 ) - { - st->input_bwidth_fx = FB; - move16(); - st->count_FB_fx = BWD_COUNT_MAX; - move16(); - } - } - - /* switching to a lower BW */ - IF( sub(st->last_input_bwidth_fx,FB) == 0 ) - { - IF( sub(st->count_FB_fx,10) < 0 ) - { - st->input_bwidth_fx = SWB; - move16(); - st->count_FB_fx = 0; - move16(); - } - IF( sub(st->count_SWB_fx,10) < 0 ) - { - st->input_bwidth_fx = WB; - move16(); - st->count_SWB_fx = 0; - move16(); - st->count_FB_fx = 0; - move16(); - } - IF( sub(st->count_WB_fx,10) < 0 ) - { - st->input_bwidth_fx = NB; - move16(); - st->count_WB_fx = 0; - move16(); - st->count_SWB_fx = 0; - move16(); - st->count_FB_fx = 0; - move16(); - } - } - - IF( sub(st->last_input_bwidth_fx,SWB) == 0 ) - { - IF( sub(st->count_SWB_fx,10) < 0 ) - { - st->input_bwidth_fx = WB; - move16(); - st->count_SWB_fx = 0; - move16(); - st->count_FB_fx = 0; - move16(); - } - IF( sub(st->count_WB_fx,10) < 0 ) - { - st->input_bwidth_fx = NB; - move16(); - st->count_WB_fx = 0; - move16(); - st->count_SWB_fx = 0; - move16(); - st->count_FB_fx = 0; - move16(); - } - - } - - IF( sub(st->last_input_bwidth_fx,WB) == 0 ) - { - IF( sub(st->count_WB_fx,10) < 0 ) - { - st->input_bwidth_fx = NB; - move16(); - st->count_WB_fx = 0; - move16(); - st->count_SWB_fx = 0; - move16(); - st->count_FB_fx = 0; - move16(); - } - } - } - } - - - /* verify that maximum encoded bandwidth (specified on the command line) is not exceeded */ - IF( sub(st->input_bwidth_fx,st->max_bwidth_fx) > 0 ) - { - st->input_bwidth_fx = st->max_bwidth_fx; - move16(); - } - - /* Set and limit the encoded bandwidth */ - IF ( sub(st->codec_mode,MODE1) == 0 ) - { - Word32 total_brate_fx; - - st->bwidth_fx = st->input_bwidth_fx; - move16(); - - total_brate_fx = L_add(st->total_brate_fx, 0); - - /* change the encoded bandwidth, if not supported at particular bitrate */ - test(); - test(); - test(); - test(); - test(); - IF ( L_sub(total_brate_fx, ACELP_9k60) <= 0 && sub(st->bwidth_fx,NB) != 0 && sub(st->bwidth_fx,WB) != 0 ) - { - st->bwidth_fx = WB; - move16(); - } - ELSE IF ( L_sub(st->total_brate_fx,ACELP_13k20) >= 0 && L_sub(st->total_brate_fx,ACELP_16k40) <= 0 && sub(st->bwidth_fx,SWB) > 0 ) - { - st->bwidth_fx = SWB; - move16(); - } - ELSE IF ( L_sub(st->total_brate_fx,ACELP_32k) >= 0 && sub(st->bwidth_fx,WB) < 0 ) - { - st->bwidth_fx = WB; - move16(); - } - } - ELSE - { - Word16 n, bits_frame_nominal; - - UWord16 lsb; - Word16 tmpbandwidthMin; - - Mpy_32_16_ss(st->total_brate_fx, 5243, &L_tmp, &lsb); /* 5243 is 1/50 in Q18. (0+18-15=3) */ - bits_frame_nominal = extract_l(L_shr(L_tmp, 3)); /* Q0 */ - - FOR (n=0; nrf_mode,1) == 0 ) - { - tmpbandwidthMin = WB; - } - st->bwidth_fx = s_max(s_min(st->input_bwidth_fx, FrameSizeConfig[n].bandwidth_max), tmpbandwidthMin); - } - - return; -} - diff --git a/src/libs/libevs/lib_enc/cng_enc.cpp b/src/libs/libevs/lib_enc/cng_enc.cpp new file mode 100644 index 00000000..21c51ce8 --- /dev/null +++ b/src/libs/libevs/lib_enc/cng_enc.cpp @@ -0,0 +1,1001 @@ +/*==================================================================================== + EVS Codec 3GPP TS26.443 Nov 13, 2018. Version 12.11.0 / 13.7.0 / 14.3.0 / 15.1.0 + ====================================================================================*/ + +#include +#include "options.h" +#include "cnst.h" +#include "rom_enc.h" +#include "rom_com.h" +#include "prot.h" + +/*---------------------------------------------------------------------* + * Local constants + *---------------------------------------------------------------------*/ + +#define MAX_DELTA_CNG 1 + +/*---------------------------------------------------------------------* + * Local functions + *---------------------------------------------------------------------*/ + +static short shb_DTX( Encoder_State *st, const float *shb_speech, const float *syn_12k8_16k ); + +static void shb_CNG_encod( Encoder_State *st, const short update + ); + +/*---------------------------------------------------------------------* + * CNG_enc() + * + * Confort noise generation for the coder + *---------------------------------------------------------------------*/ + +void CNG_enc( + Encoder_State *st, /* i/o: State structure */ + const short L_frame, /* i : length of the frame */ + float Aq[], /* o : LP coefficients */ + const float *speech, /* i : pointer to current frame input speech buffer */ + float enr, /* i : residual energy from Levinson-Durbin */ + float *lsp_new, /* i/o: current frame ISPs */ + float *lsf_new, /* i/o: current frame ISFs */ + short *allow_cn_step, /* o : allow CN step */ + short burst_ho_cnt, /* i : hangover frames at end of speech burst */ + float *q_env, + short *sid_bw, + float *exc_mem2 +) +{ + short enr_index, i; + float step, res[L_FRAME16k]; + short maxl, num_bits; + short j, k, ptr; + short m1; + float weights; + float sp_enr; + short m = 0; + float tmp[HO_HIST_SIZE*M]; + short ll, s_ptr; + float att=1.0f; + float lsf_tmp[M]; + float C[M]; + float max[2]; + short max_idx[2]; + float ftmp; + float lsp_tmp[M]; + float dev; + float max_dev; + float dist; + short max_idx1[2]= {0,0}; + float fft_io[L_FRAME16k]; + float *ptR,*ptI; + float enr1=0; + float env[NUM_ENV_CNG]; + float min1; + short min1_idx; + float d; + float res1[L_FRAME16k]; + float tmp_env[HO_HIST_SIZE*NUM_ENV_CNG]; + short force_cn_step=0; + + /* calculate input energy */ + sp_enr = (float) log10( sum2_f( speech, L_frame )/L_frame + 0.1f )/ (float)log10(2.0f); + + if (sp_enr < 0.0f) + { + sp_enr = 0.0f; + } + + if ( st->first_CNG == 0 || st->old_enr_index < 0 ) + { + st->lp_sp_enr = sp_enr; + } + else + { + if ( st->last_core_brate > SID_2k40 && burst_ho_cnt > 0 && st->lp_sp_enr < 6.0f && (sp_enr - st->lp_sp_enr) > 4.0f && sp_enr > 6.0f ) + { + st->lp_sp_enr = sp_enr; + force_cn_step = 1; + } + else + { + st->lp_sp_enr = 0.1f * sp_enr + 0.9f * st->lp_sp_enr; + } + } + + /* update the pointer to circular buffer of old LSP vectors */ + if( ++(st->cng_hist_ptr) == DTX_HIST_SIZE ) + { + st->cng_hist_ptr = 0; + } + + /* update the circular buffer of old LSP vectors with the new LSP vector */ + mvr2r( lsp_new, &(st->cng_lsp_hist[(st->cng_hist_ptr)*M]), M ); + + /*-----------------------------------------------------------------* + * Find CNG spectral envelope + * Find LSP median + *-----------------------------------------------------------------*/ + + if( (st->core_brate == SID_2k40 || st->core_brate == SID_1k75) && st->cng_cnt >= (st->cng_hist_size-1) ) + { + set_f( max, 0.0f, 2 ); + set_s( max_idx, 0, 2 ); + + for( i=0; icng_hist_size; i++ ) + { + if (st->L_frame == L_FRAME ) + { + lsp2lsf( &st->cng_lsp_hist[i*M], lsf_tmp, M, INT_FS_12k8 ); + ftmp = 6400.0f / (M+1); + C[i] = (6400.0f - lsf_tmp[M-1] - ftmp) * (6400.0f - lsf_tmp[M-1] - ftmp); + } + else + { + lsp2lsf( &st->cng_lsp_hist[i*M], lsf_tmp, M, INT_FS_16k ); + ftmp = 8000.0f / (M+1); + C[i] = (8000.0f - lsf_tmp[M-1] - ftmp) * (8000.0f - lsf_tmp[M-1] - ftmp); + } + + C[i] += (lsf_tmp[0] - ftmp) * (lsf_tmp[0] - ftmp); + + for ( j=0; j max[0] ) + { + max[1] = max[0]; + max_idx[1] = max_idx[0]; + max[0] = C[i]; + max_idx[0] = i; + } + else if ( C[i] > max[1] ) + { + max[1] = C[i]; + max_idx[1] = i; + } + } + + for ( i=0; icng_hist_size; j++ ) + { + lsp_new[i] += st->cng_lsp_hist[j*M+i]; + } + + lsp_new[i] -= (st->cng_lsp_hist[max_idx[0]*M+i] + st->cng_lsp_hist[max_idx[1]*M+i]); + lsp_new[i] /= (float)(st->cng_hist_size - 2); + } + max_idx1[0] = max_idx[0]; + max_idx1[1] = max_idx[1]; + } + + /*-----------------------------------------------------------------* + * Quantize CNG spectral envelope (only in SID frame) + * Quantize the LSF vector + *-----------------------------------------------------------------*/ + + *allow_cn_step = ((st->cng_cnt == 0) && + (st->lp_sp_enr > 6.0f) && + ((st->lp_sp_enr + 4.0f) < sp_enr) && + (st->first_CNG != 0 ) && + (st->old_enr_index >= 0) && + (st->last_core_brate > SID_2k40)) || + force_cn_step; + + if( st->core_brate == SID_2k40 || st->core_brate == SID_1k75 ) + { + /* LSF quantization */ + if ( st->Opt_AMR_WB ) + { + isf_enc_amr_wb( st, lsf_new, lsp_new, 0, 0 ); + } + else + { + lsf_enc( st, L_frame, INACTIVE, lsf_new, lsp_new, 0, 0, 0, 100 ); + } + + /* Reset CNG history if CNG frame length is changed */ + if ( st->bwidth == WB && st->first_CNG && st->L_frame != st->last_CNG_L_frame ) + { + st->ho_hist_size = 0; + } + } + else + { + /* Use old LSP vector */ + mvr2r( st->lsp_old, lsp_new, M ); + mvr2r( st->lsf_old, lsf_new, M ); + } + + /* Initialize the CNG spectral envelope in case of the very first CNG frame */ + if( st->first_CNG == 0 ) + { + mvr2r( st->lsp_old, st->lspCNG, M ); + } + + /*---------------------------------------------------------------------* + * CNG spectral envelope update + * Find A(z) coefficients + *---------------------------------------------------------------------*/ + + if( st->last_core_brate == FRAME__NO_DATA || st->last_core_brate == SID_1k75 || st->last_core_brate == SID_2k40 ) + { + /* Reset hangover counter if not first SID period */ + if( st->core_brate > FRAME__NO_DATA ) + { + st->num_ho = 0; + } + /* Update LSPs if last SID energy not outlier or insufficient number of hangover frames */ + if( st->num_ho < 3 || st->Enew < 1.5f * st->lp_ener ) + { + for( i=0; ilspCNG[i] = CNG_ISF_FACT * st->lspCNG[i] + (1-CNG_ISF_FACT) * lsp_new[i]; + } + } + } + else + { + /* Update CNG_mode if allowed */ + if( ( st->Opt_AMR_WB || st->bwidth == WB ) && ( !st->first_CNG || st->act_cnt2 >= MIN_ACT_CNG_UPD ) ) + { + if( st->last_active_brate > ACELP_16k40 ) + { + st->CNG_mode = -1; + } + else if( st->last_active_brate > ACELP_13k20 ) + { + st->CNG_mode = 4; + } + else if( st->last_active_brate > ACELP_9k60 ) + { + st->CNG_mode = 3; + } + else if( st->last_active_brate > ACELP_8k00 ) + { + st->CNG_mode = 2; + } + else if( st->last_active_brate > ACELP_7k20 ) + { + st->CNG_mode = 1; + } + else + { + st->CNG_mode = 0; + } + } + + /* If first SID after active burst update LSF history from circ buffer */ + st->act_cnt = 0; + s_ptr = st->ho_circ_ptr-burst_ho_cnt+1; + if( s_ptr < 0 ) + { + s_ptr += st->ho_circ_size; + } + + for( ll = burst_ho_cnt; ll > 0; ll-- ) + { + if( ++(st->ho_hist_ptr) == HO_HIST_SIZE ) + { + st->ho_hist_ptr = 0; + } + /* Conversion between 12.8k and 16k LSPs */ + if( L_frame == L_FRAME && st->ho_16k_lsp[s_ptr] == 1 ) + { + /* Conversion from 16k LPSs to 12k8 */ + lsp_convert_poly( &(st->ho_lsp_circ[s_ptr*M]), L_frame, 0 ); + } + else if ( L_frame == L_FRAME16k && st->ho_16k_lsp[s_ptr] == 0 ) + { + /* 16k LSPs already converted and stored, just copy to the other buffer */ + mvr2r(&(st->ho_lsp_circ2[s_ptr*M]), &(st->ho_lsp_circ[s_ptr*M]), M ); + } + + /* update circular buffers */ + mvr2r(&(st->ho_lsp_circ[s_ptr*M]), &(st->ho_lsp_hist[st->ho_hist_ptr*M]), M ); + mvr2r(&(st->ho_ener_circ[s_ptr]), &(st->ho_ener_hist[st->ho_hist_ptr]), 1 ); + st->ho_sid_bw = ( st->ho_sid_bw & 0x3fffffffL ) << 1; + mvr2r(&(st->ho_env_circ[s_ptr*NUM_ENV_CNG]), &(st->ho_env_hist[st->ho_hist_ptr*NUM_ENV_CNG]), NUM_ENV_CNG ); + + st->ho_hist_size++; + if (st->ho_hist_size > HO_HIST_SIZE) + { + st->ho_hist_size = HO_HIST_SIZE; + } + + s_ptr++; + + if( s_ptr == st->ho_circ_size ) + { + s_ptr = 0; + } + } + if ( burst_ho_cnt > 0) + { + *allow_cn_step |= ( st->ho_ener_hist[st->ho_hist_ptr] > 4.0f * st->lp_ener ); + } + + if ( !*allow_cn_step && st->ho_hist_size > 0 ) + { + ptr = st->ho_hist_ptr; + mvr2r( &(st->ho_lsp_hist[ptr*M]), tmp, M ); + m1 = 0; + if( (st->ho_sid_bw & 0x1L) == 0 ) + { + mvr2r( &st->ho_env_hist[ptr*NUM_ENV_CNG], tmp_env, NUM_ENV_CNG ); + m1 = 1; + } + enr = W_DTX_HO[0] * st->ho_ener_hist[ptr]; + weights = W_DTX_HO[0]; + m = 1; + for( k=1; kho_hist_size; k++ ) + { + ptr--; + if( ptr < 0 ) + { + ptr = HO_HIST_SIZE - 1; + } + + if ( st->ho_ener_hist[ptr] < st->ho_ener_hist[st->ho_hist_ptr] * BUF_H_NRG && + st->ho_ener_hist[ptr] > st->ho_ener_hist[st->ho_hist_ptr] * BUF_L_NRG ) + { + enr += W_DTX_HO[k] * st->ho_ener_hist[ptr]; + weights += W_DTX_HO[k]; + mvr2r( &st->ho_lsp_hist[ptr*M], &tmp[m*M], M ); + if( (st->ho_sid_bw & (0x1L << k)) == 0 ) + { + mvr2r( &st->ho_env_hist[ptr*NUM_ENV_CNG], &tmp_env[m1*NUM_ENV_CNG], NUM_ENV_CNG ); + m1++; + } + m++; + } + } + + enr /= weights; + st->lp_ener = enr; + + set_f( max, 0.0f, 2 ); + set_s( max_idx, 0, 2 ); + + for( i=0; iL_frame == L_FRAME ) + { + lsp2lsf( &tmp[i*M], lsf_tmp, M, INT_FS_12k8 ); + ftmp = 6400.0f / (M+1); + C[i] = (6400.0f - lsf_tmp[M-1] - ftmp) * (6400.0f - lsf_tmp[M-1] - ftmp); + } + else + { + lsp2lsf( &tmp[i*M], lsf_tmp, M, INT_FS_16k ); + ftmp = 8000.0f / (M+1); + C[i] = (8000.0f - lsf_tmp[M-1] - ftmp) * (8000.0f - lsf_tmp[M-1] - ftmp); + } + + C[i] += (lsf_tmp[0] - ftmp) * (lsf_tmp[0] - ftmp); + + for ( j=0; j max[0] ) + { + max[1] = max[0]; + max_idx[1] = max_idx[0]; + max[0] = C[i]; + max_idx[0] = i; + } + else if ( C[i] > max[1] ) + { + max[1] = C[i]; + max_idx[1] = i; + } + } + + if ( m == 1 ) + { + mvr2r(tmp, lsp_tmp, M); + } + else if ( m < 4 ) + { + for ( i=0; i max_dev ) + { + max_dev = dev; + } + } + + if ( dist > 0.4f || max_dev > 0.1f ) + { + for( i=0; ilspCNG[i] = lsp_tmp[i]; + } + } + else + { + for( i=0; ilspCNG[i] = 0.8f * lsp_tmp[i] + (1-0.8f) * lsp_new[i]; + } + } + if( m1 > 0 ) + { + for ( i=0; ilp_ener; + } + mvr2r(env, st->lp_env, NUM_ENV_CNG); + } + } + else + { + mvr2r( lsp_new, st->lspCNG, M ); /* use newly analyzed parameters */ + } + } + + if ( st->Opt_AMR_WB ) + { + isp2a( st->lspCNG, Aq, M ); + } + else + { + lsp2a_stab( st->lspCNG, Aq, M ); + } + + for( i=1; ibwidth != NB ) + { + if( st->bwidth == WB && st->CNG_mode >= 0 ) + { + ftmp = HO_ATT[st->CNG_mode]; + } + else + { + ftmp = 0.6f; + } + + att = ftmp/6.0f; + att = 1.0f/(1 + att * 8); + + if ( att < ftmp ) + { + att = ftmp; + } + + for( i = 0; i < st->L_frame; i++ ) + { + res1[i] *= att; + } + } + + /* calculate the spectrum of residual signal */ + mvr2r(res1, fft_io, st->L_frame); + + if ( st->L_frame == L_FRAME16k ) + { + modify_Fs( fft_io, L_FRAME16k, 16000, fft_io, 12800, exc_mem2, 0 ); + } + + fft_rel(fft_io, L_FFT, LOG2_L_FFT); + ptR = &fft_io[1]; + ptI = &fft_io[L_FFT-1]; + for ( i=0; icng_res_env[(st->cng_hist_ptr)*NUM_ENV_CNG]), NUM_ENV_CNG ); + /* calculate the residual signal energy */ + enr = dotp( res, res, L_frame ) / L_frame; + + /* convert log2 of residual signal energy */ + enr = (float)log10( enr + 0.1f ) / (float)log10( 2.0f ); + + /* update the circular buffer of old energies */ + st->cng_ener_hist[st->cng_hist_ptr] = enr; + + /*-----------------------------------------------------------------* + * Quantize residual signal energy (only in SID frame) + *-----------------------------------------------------------------*/ + + if( st->core_brate == SID_2k40 || st->core_brate == SID_1k75 ) + { + if( st->cng_cnt >= st->cng_hist_size - 1 ) + { + /* average the envelope except outliers */ + for ( i=0; icng_hist_size; j++ ) + { + env[i] += st->cng_res_env[j*NUM_ENV_CNG+i]; + } + + env[i] -= (st->cng_res_env[max_idx1[0]*NUM_ENV_CNG+i] + st->cng_res_env[max_idx1[1]*NUM_ENV_CNG+i]); + env[i] /= (float)(st->cng_hist_size - 2); + } + /* compute average excitation energy */ + enr = 0; + weights = 0; + ptr = st->cng_hist_ptr; + + for( k=0; kcng_hist_size; k++ ) + { + enr += W_HIST[k] * st->cng_ener_hist[ptr--]; + if( ptr < 0 ) + { + ptr = DTX_HIST_SIZE - 1; + } + + weights += W_HIST[k]; + } + + /* normalize the average value */ + enr /= weights; + } + + /* decrease the energy in case of WB input */ + if( st->bwidth != NB ) + { + if( st->bwidth == WB ) + { + if( st->CNG_mode >= 0 ) + { + /* Bitrate adapted attenuation */ + att = ENR_ATT[st->CNG_mode]; + } + else + { + /* Use least attenuation for higher bitrates */ + att = ENR_ATT[4]; + } + } + else + { + att = 1.5f; + } + + enr -= att; + } + + /* intialize the energy quantization parameters */ + if( !st->Opt_AMR_WB ) + { + step = STEP_SID; + maxl = 127; + num_bits = 7; + } + else + { + step = STEP_AMR_WB_SID; + maxl = 63; + num_bits = 6; + } + + /* calculate the energy quantization index */ + enr_index = (short)( (enr + 2.0f) * step ); + + /* limit the energy quantization index */ + if( enr_index > maxl ) + { + enr_index = maxl; + } + + if( enr_index < 0 ) + { + enr_index = 0; + } + + /* allow only slow energy increase */ + if( st->first_CNG && enr_index > st->old_enr_index + MAX_DELTA_CNG ) + { + if( *allow_cn_step == 1 ) + { + enr_index = st->old_enr_index + (short) (0.85f*(enr_index - st->old_enr_index)) ; + } + else + { + enr_index = st->old_enr_index + MAX_DELTA_CNG; + } + } + st->old_enr_index = enr_index; + + push_indice( st, IND_ENERGY, enr_index, num_bits ); + if ( enr_index == 0 ) + { + enr_index = -5; + } + /* find the quatized energy */ + st->Enew = (float)enr_index / step - 2.0f; + st->Enew = (float)( pow( 2.0f, st->Enew ) ); + if ( st->core_brate == SID_2k40 ) + { + enr1 = (float)log10( st->Enew*L_frame + 0.1f ) / (float)log10( 2.0f ); + for ( i=0; iEnew; + + if ( env[i] < 0.0f ) + { + env[i] = 0.1f; + } + + env[i] = (float)log10( env[i] + 0.1f ) / (float)log10( 2.0f ); + env[i] -= att; + + if ( env[i] < 0 ) + { + env[i] = 0; + } + + env[i] = enr1 - env[i]; + } + + /* codebook search */ + min1 = 9999.0f;; + min1_idx = 0; + + for ( i=0; i<64; i++ ) + { + d = 0.0f; + for ( j=0; jEnew < 1.5f * st->lp_ener) ) + { + /* update the pointer to circular buffer of old LSP vectors */ + if( ++(st->ho_hist_ptr) == HO_HIST_SIZE ) + { + st->ho_hist_ptr = 0; + } + + /* update the circular buffer of old LSP vectors with the new LSP vector */ + mvr2r( lsp_new, &(st->ho_lsp_hist[(st->ho_hist_ptr)*M]), M ); + + /* update the hangover energy buffer */ + st->ho_ener_hist[st->ho_hist_ptr] = st->Enew; + if ( st->core_brate == SID_2k40 ) + { + for ( i=0; iEnew; + } + mvr2r( env, &(st->ho_env_hist[(st->ho_hist_ptr)*NUM_ENV_CNG]), NUM_ENV_CNG ); + } + if(++(st->ho_hist_size) > HO_HIST_SIZE) + { + st->ho_hist_size = HO_HIST_SIZE; + } + } + } + + /* dithering bit for AMR-WB IO mode is always set to 0 */ + if( st->core_brate == SID_1k75 ) + { + push_indice( st, IND_DITHERING, 0, 1 ); + } + + if ( st->core_brate == SID_2k40 ) + { + push_indice( st, IND_ACELP_16KHZ, st->L_frame == L_FRAME16k ? 1 : 0, 1 ); + } + + if ( st->core_brate == SID_2k40 ) + { + /* transmit ho_cnt for use at decoder side as CNG synthesis assistance */ + if( st->burst_ho_cnt > (HO_HIST_SIZE-1) ) + { + push_indice( st, IND_CNG_HO, (HO_HIST_SIZE-1), 3 ); /* send max allowed value , limited to 7 */ + } + else + { + push_indice( st, IND_CNG_HO, st->burst_ho_cnt, 3 ); /* send actual value */ + } + st->num_ho = m; + push_indice( st, IND_SID_TYPE, 0, 1 ); + + if ( st->input_Fs < 32000 ) + { + push_indice( st, IND_SID_BW, 0, 1 ); + *sid_bw = 0; + } + } + + /*-----------------------------------------------------------------* + * Updates + *-----------------------------------------------------------------*/ + + /* update the SID frames counter */ + if( st->core_brate == SID_2k40 || st->core_brate == SID_1k75 ) + { + st->cng_cnt = 0; + st->cng_hist_ptr = -1; + + /* update frame length memory */ + st->last_CNG_L_frame = st->L_frame; + } + else + { + st->cng_cnt++; + } + + + + return; +} + +/*---------------------------------------------------------------------* + * swb_CNG_enc() + * + * SWB DTX/CNG encoding + *---------------------------------------------------------------------*/ + +void swb_CNG_enc( + Encoder_State *st, /* i/o: State structure */ + const float *shb_speech, /* i : SHB target signal (6-14kHz) at 16kHz */ + const float *syn_12k8_16k /* i : ACELP core synthesis at 12.8kHz or 16kHz */ +) +{ + short shb_SID_updt; + + if( st->core_brate == SID_2k40 || st->core_brate == FRAME__NO_DATA ) + { + if ( st->cng_type == LP_CNG ) + { + /* decide if SHB SID encoding or not */ + shb_SID_updt = shb_DTX( st, shb_speech, syn_12k8_16k ); + + /* SHB CNG encoding */ + shb_CNG_encod( st, shb_SID_updt ); + } + st->last_vad = 0; + } + else + { + st->last_vad = 1; + } + + return; +} + +/*---------------------------------------------------------------------* + * shb_CNG_encod() + * + * SID parameters encoding for SHB signal + *---------------------------------------------------------------------*/ + +static void shb_CNG_encod( + Encoder_State *st, /* i/o: State structure */ + const short update /* i : SID update flag */ +) +{ + short idx_ener = 0; + + if ( update == 1 ) + { + /* SHB energy quantization */ + idx_ener = (short)(0.9f * (0.1f*st->mov_shb_cng_ener/(float)log10(2.0f) + 6.0f) + 0.5f ); + if ( st->bwidth < SWB ) + { + idx_ener = 0; + } + + if ( idx_ener > 15 ) + { + idx_ener = 15; + } + else if ( idx_ener < 0 ) + { + idx_ener = 0; + } + + push_indice( st, IND_SHB_CNG_GAIN, idx_ener, 4 ); + push_indice( st, IND_SID_BW, 1, 1 ); + st->nb_bits_tot = st->nb_bits_tot - st->ind_list[IND_CNG_ENV1].nb_bits; + st->ind_list[IND_CNG_ENV1].nb_bits = -1; + push_indice( st, IND_UNUSED, 0, 2 ); + st->ho_sid_bw = ( st->ho_sid_bw & 0x3fffffffL ) << 1; + st->ho_sid_bw |= 0x1L; + } + else if ( st->core_brate == SID_2k40 ) + { + st->ho_sid_bw = ( st->ho_sid_bw & 0x3fffffffL ) << 1; + push_indice( st, IND_SID_BW, 0, 1 ); + } + + + return; +} + +/*---------------------------------------------------------------------* + * shb_DTX() + * + * Decide if encoding SHB SID or not + *---------------------------------------------------------------------*/ + +static short shb_DTX( + Encoder_State *st, /* i/o: State structure */ + const float *shb_speech, /* i : SHB target signal (6-14kHz) at 16kHz */ + const float *syn_12k8_16k /* i : ACELP core synthesis at 12.8kHz or 16kHz */ +) +{ + short i; + short update; + float shb_old_speech[(L_LOOK_12k8 + L_SUBFR + L_FRAME) * 5/4]; + float *shb_new_speech; + float wb_ener; + float shb_ener; + float log_wb_ener; + float log_shb_ener; + float ftmp; + short allow_cn_step=0; + + shb_new_speech = shb_old_speech + (L_LOOK_12k8 + L_SUBFR) * 5/4; + mvr2r( st->old_speech_shb, shb_old_speech, (L_LOOK_12k8 + L_SUBFR) * 5/4 ); + mvr2r( shb_speech, shb_new_speech, L_FRAME16k ); + mvr2r( shb_old_speech + L_FRAME16k, st->old_speech_shb, (L_LOOK_12k8 + L_SUBFR) * 5/4 ); + + shb_ener = 0; + for ( i=0; iL_frame) + 0.001f; + wb_ener = wb_ener/st->L_frame; + + log_wb_ener = 10 * (float)log10(wb_ener); + log_shb_ener = 10 * (float)log10(shb_ener) - 6.5f; + + if ( st->first_CNG == 0 ) + { + st->mov_wb_cng_ener = log_wb_ener; + st->mov_shb_cng_ener = log_shb_ener; + st->last_wb_cng_ener = log_wb_ener; + st->last_shb_cng_ener = log_shb_ener; + } + if ( fabs(log_wb_ener - st->mov_wb_cng_ener) > 12.0f ) + { + allow_cn_step = 1; + } + + if ( allow_cn_step == 1 ) + { + st->mov_wb_cng_ener = log_wb_ener; + st->mov_shb_cng_ener = log_shb_ener; + } + else + { + ftmp = log_wb_ener - st->mov_wb_cng_ener; + + st->mov_wb_cng_ener += 0.9f * ftmp; + + ftmp = log_shb_ener - st->mov_shb_cng_ener; + + st->mov_shb_cng_ener += 0.25f * ftmp; + } + st->shb__NO_DATA_cnt++; + + update = 0; + if ( st->core_brate == SID_2k40 ) + { + if ( st->first_CNG == 0 ) + { + update = 1; + } + else if ( st->shb_cng_ini_cnt > 0 ) + { + st->shb_cng_ini_cnt--; + update = 1; + } + else if ( st->last_vad == 1 ) + { + update = 1; + } + else if ( st->shb__NO_DATA_cnt >= 100 ) + { + update = 1; + } + else if ( fabs((st->mov_wb_cng_ener - st->mov_shb_cng_ener) - (st->last_wb_cng_ener - st->last_shb_cng_ener)) > 3.0f ) + { + update = 1; + } + else if ( (st->bwidth >=SWB && st->last_SID_bwidth < SWB) || (st->bwidth last_SID_bwidth >= SWB) ) + { + update = 1; + } + + st->last_SID_bwidth = st->bwidth; + } + + if ( update == 1 ) + { + st->last_wb_cng_ener = st->mov_wb_cng_ener; + st->last_shb_cng_ener = st->mov_shb_cng_ener; + st->shb__NO_DATA_cnt = 0; + } + + return (update); +} diff --git a/src/libs/libevs/lib_enc/cng_enc_fx.cpp b/src/libs/libevs/lib_enc/cng_enc_fx.cpp deleted file mode 100755 index 38e38f6b..00000000 --- a/src/libs/libevs/lib_enc/cng_enc_fx.cpp +++ /dev/null @@ -1,1375 +0,0 @@ -/*==================================================================================== - EVS Codec 3GPP TS26.442 Apr 03, 2018. Version 12.11.0 / 13.6.0 / 14.2.0 - ====================================================================================*/ - -#include "options.h" /* Compilation switches */ -#include "cnst_fx.h" /* Common constants */ -#include "rom_enc_fx.h" /* Encoder static table prototypes */ -#include "rom_com_fx.h" /* Static table prototypes */ -#include "prot_fx.h" /* Function prototypes */ -#include "stl.h" -#include "basop_mpy.h" - -/*---------------------------------------------------------------------* -* Local constants -*---------------------------------------------------------------------*/ - -#define MAX_DELTA 1 -#define MIN_CNT 50 /* Minimum frame number before SID interval adaptation */ -#define INT_H 50 -#define INT_L 8 - -/*---------------------------------------------------------------------* - * Local functions - *---------------------------------------------------------------------*/ -static void shb_CNG_encod_fx( - Encoder_State_fx *st_fx, /* i/o: State structure */ - const Word16 update_fx /* i : SID update flag */ -); -static Word16 shb_DTX_fx( - Encoder_State_fx *st_fx, /* i/o: State structure */ - const Word16 *shb_speech_fx, /* i : SHB target signal (6-14kHz) at 16kHz */ - const Word16 *syn_12k8_16k /* i : ACELP core synthesis at 12.8kHz or 16kHz */ -); - -void CNG_enc_fx( - Encoder_State_fx *st_fx,/* i/o: State structure */ - const Word16 L_frame, /* i : length of the frame Q0 */ - Word16 Aq[], /* o : LP coefficients Q12 */ - const Word16 *speech, /* i : pointer to current frame input speech buffer Q_new */ - Word32 L_enr, /* i : residual energy from Levinson-Durbin Q6 */ - Word16 *lsp_new, /* i/o: current frame ISPs Q15 */ - Word16 *lsf_new, /* i/o: current frame ISFs Qlog2(2.56) */ - Word16 *allow_cn_step, /* o : allow CN step Q0 */ - Word16 burst_ho_cnt, /* i : hangover frames at end of speech burst Q0 */ - Word16 Q_new /* i : Q value of speech */ - ,Word32 *q_env - ,Word16 *sid_bw - ,Word16 *exc_mem2 -) -{ - Word16 enr_index; - Word16 i, j, ptr; - Word16 m1; - Word16 res[L_FRAME16k]; - Word16 step_inv=0; - Word16 hi, lo; - Word16 maxl=0; - Word16 num_bits=0; - Word16 step=0; - Word16 *pt_res; - const Word16 *pt_sp; - Word16 enr; - Word32 L_tmp, L_ener; - Word16 k, tmp1; - Word16 weights; - Word16 sp_enr; - Word32 L_tmp1; - Word16 exp; - Word16 m = 0; - Word16 tmp[HO_HIST_SIZE*M]; - Word16 ll, s_ptr; - Word16 tmpv, maxv, scale, att = 1; - Word16 lsf_tmp[M]; - Word32 C[M]; - Word32 max[2]; - Word16 max_idx[2]; - Word16 ftmp_fx; - Word16 lsp_tmp[M]; - Word16 dev; - Word16 max_dev; - Word16 dist; - Word16 max_idx1[2]= {0,0}; - Word16 fft_io[L_FRAME16k]; - Word16 *ptR,*ptI; - Word32 enr1=0; - Word32 env[NUM_ENV_CNG]; - Word32 min1; - Word16 min1_idx; - Word32 d; - Word16 res1[L_FRAME16k]; - Word32 tmp_env[HO_HIST_SIZE*NUM_ENV_CNG]; - Word16 fra; - Word16 temp_lo_fx, temp_hi_fx; - Word16 exp_pow; - Word16 force_cn_step=0; - Word16 tmp_loop; - - /* Temp variables for floating point functions */ - - /*sp_enr = (float) log10( sum2_f( speech, L_frame )/L_frame + 0.1f )/ (float)log10(2.0f);*//*9.1 */ - pt_sp = speech; - L_ener = L_deposit_l(1); - /* L_ener = L_add(L_shr(sum2_f_fx( speech, L_frame ), 8) , L_ener);*/ - IF( sub(L_frame, L_FRAME) == 0) - { - FOR (j=0; j<128; j++) - { - L_tmp = L_mult0(*pt_sp, *pt_sp); - pt_sp++; - L_tmp = L_mac0(L_tmp, *pt_sp, *pt_sp); - pt_sp++; - L_ener = L_add(L_ener, L_shr(L_tmp, 7)); /* 2*Q_new + 1, divide by L_frame done here */ - } - } - ELSE /* L_FRAME16k */ - { - FOR (i=0; i<2; i++) - { - FOR (j=0; j<80; j++) - { - L_tmp = L_mult0(*pt_sp, *pt_sp); - pt_sp++; - L_tmp = L_mac0(L_tmp, *pt_sp, *pt_sp); - pt_sp++; - L_ener = L_add(L_ener, L_shr(Mult_32_16(L_tmp,26214 /* 256/320, Q15 */), 7)); /* 2*Q_new + 1, divide by L_frame done here */ - } - } - } - - hi = norm_l(L_ener); - lo = Log2_norm_lc(L_shl(L_ener, hi)); - hi = sub(29, hi); /* log2 exp in Q2*Q_new */ - hi = sub(hi, shl(Q_new, 1)); /* Q0 */ - L_tmp = L_Comp(hi, lo); /* Q16 */ - sp_enr = round_fx(L_shl(L_tmp, 8)); /* Q8 (16+8-16) */ - - if (sp_enr < 0) - { - sp_enr = 0; - move16(); - } - test(); - IF ( st_fx->first_CNG_fx == 0 || st_fx->old_enr_index_fx < 0 ) - { - st_fx->lp_sp_enr_fx = sp_enr; - move16(); /* Q8 */ - } - ELSE - { - test(); - test(); - test(); - test(); - IF ( L_sub(st_fx->last_core_brate_fx, SID_2k40) > 0 && burst_ho_cnt > 0 && sub(st_fx->lp_sp_enr_fx, 1536) < 0 && - sub(sub(sp_enr, st_fx->lp_sp_enr_fx), 1024) > 0 && sub(sp_enr, 1536) > 0 ) - { - st_fx->lp_sp_enr_fx = sp_enr; - move16(); - force_cn_step = 1; - move16(); - } - ELSE - { - st_fx->lp_sp_enr_fx = round_fx(L_mac(L_mult(29491 /* 0.9, Q15 */,st_fx->lp_sp_enr_fx), 3277 /* 0.1, Q15 */,sp_enr)); /* Q8 (8+15+1-16) */ - } - } - /* update the pointer to circular buffer of old LSP vectors */ - st_fx->cng_hist_ptr_fx = add(st_fx->cng_hist_ptr_fx,1); - if(sub(st_fx->cng_hist_ptr_fx, DTX_HIST_SIZE) == 0) - { - st_fx->cng_hist_ptr_fx = 0; - move16(); - } - - /* update the circular buffer of old LSP vectors with the new LSP vector */ - Copy( lsp_new, &(st_fx->cng_lsp_hist_fx[(st_fx->cng_hist_ptr_fx)*M]), M ); - - /*-----------------------------------------------------------------* - * Find CNG spectral envelope - * Find LSP median - *-----------------------------------------------------------------*/ - test(); - test(); - IF( (L_sub(st_fx->core_brate_fx, SID_2k40) == 0 || L_sub(st_fx->core_brate_fx, SID_1k75) == 0) && sub(st_fx->cng_cnt_fx, sub(st_fx->cng_hist_size_fx,1)) >= 0 ) - { - set32_fx( max, 0, 2 ); - set16_fx( max_idx, 0, 2 ); - - FOR( i=0; icng_hist_size_fx; i++ ) - { - IF ( sub(st_fx->L_frame_fx,L_FRAME) == 0 ) - { - lsp2lsf_fx( &st_fx->cng_lsp_hist_fx[i*M], lsf_tmp, M, INT_FS_FX ); - ftmp_fx = 964; - move16();/*QX2.56 */ - tmpv = sub(16384,add(lsf_tmp[M-1],ftmp_fx)); /*QX2.56 */ - L_tmp = L_mult0(tmpv,tmpv); /*QX6.5536 */ - } - ELSE - { - lsp2lsf_fx( &st_fx->cng_lsp_hist_fx[i*M], lsf_tmp, M, INT_FS_16k ); - ftmp_fx = 1205; - move16();/*QX2.56 */ - tmpv = sub(20480,add(lsf_tmp[M-1],ftmp_fx)); /*QX2.56 */ - L_tmp = L_mult0(tmpv,tmpv); /*QX6.5536 */ - } - - tmpv = sub(lsf_tmp[0],ftmp_fx); /*QX2.56 */ - L_tmp = L_mac0(L_tmp,tmpv,tmpv); /*QX6.5536 */ - FOR ( j=0; j 0 ) - { - max[1] = max[0]; - move32(); - max_idx[1] = max_idx[0]; - move16(); - max[0] = C[i]; - move32(); - max_idx[0] = i; - move16(); - } - ELSE IF ( L_sub(C[i],max[1]) > 0 ) - { - max[1] = C[i]; - move32(); - max_idx[1] = i; - move16(); - } - } - - FOR ( i=0; icng_hist_size_fx; j++ ) - { - L_tmp = L_add(L_tmp,L_deposit_l(st_fx->cng_lsp_hist_fx[j*M+i])); /*Q15 */ - } - - L_tmp = L_sub(L_tmp,L_add(L_deposit_l(st_fx->cng_lsp_hist_fx[max_idx[0]*M+i]),L_deposit_l(st_fx->cng_lsp_hist_fx[max_idx[1]*M+i]))); /*Q15 */ - tmpv= div_s(1,sub(st_fx->cng_hist_size_fx,2)); /*Q15 */ - L_tmp = Mpy_32_16_1(L_tmp,tmpv); /*Q15 */ - lsp_new[i] = extract_l(L_tmp); /*Q15 */ - } - max_idx1[0] = max_idx[0]; - move16(); - max_idx1[1] = max_idx[1]; - move16(); - } - - /*-----------------------------------------------------------------* - * Quantize CNG spectral envelope (only in SID frame) - * Quantize the LSF vector - *-----------------------------------------------------------------*/ - *allow_cn_step = 0; - move16(); - test(); - test(); - test(); - test(); - test(); - test(); - IF( ((st_fx->cng_cnt_fx == 0) && - sub(st_fx->lp_sp_enr_fx, 1536) > 0 && - (sub(add(st_fx->lp_sp_enr_fx,1024 /* 4.0, Q8 */), sp_enr) < 0) && - (st_fx->first_CNG_fx !=0 ) && - (st_fx->old_enr_index_fx>=0) && - (L_sub(st_fx->last_core_brate_fx, SID_2k40) > 0)) || - sub(force_cn_step, 1) == 0 ) - { - *allow_cn_step = 1; - move16(); - } - test(); - IF( L_sub(st_fx->core_brate_fx, SID_2k40) == 0 || L_sub(st_fx->core_brate_fx, SID_1k75) == 0 ) - { - /* LSF quantization */ - IF ( st_fx->Opt_AMR_WB_fx != 0 ) - { - isf_enc_amr_wb_fx( st_fx, lsf_new, lsp_new, 0, 0 ); - } - ELSE - { - lsf_enc_fx( st_fx, L_frame, INACTIVE, lsf_new, lsp_new, 0, 0, 0, 100, Q_new ); - } - /* Reset CNG history if CNG frame length is changed */ - test(); - test(); - if ( sub(st_fx->bwidth_fx,WB) == 0 && st_fx->first_CNG_fx != 0 && sub(st_fx->L_frame_fx,st_fx->last_CNG_L_frame_fx) != 0 ) - { - st_fx->ho_hist_size_fx = 0; - move16(); - } - } - ELSE - { - /* Use old LSP vector */ - Copy( st_fx->lsp_old_fx, lsp_new, M ); - Copy( st_fx->lsf_old_fx, lsf_new, M ); - } - - /* Initialize the CNG spectral envelope in case of the very first CNG frame */ - IF( st_fx->first_CNG_fx == 0 ) - { - Copy( st_fx->lsp_old_fx, st_fx->lspCNG_fx, M ); - } - - /*---------------------------------------------------------------------* - * CNG spectral envelope update - * Find A(z) coefficients - *---------------------------------------------------------------------*/ - - IF( L_sub(st_fx->last_core_brate_fx, SID_2k40) <= 0 ) - { - /* Reset hangover counter if not first SID period */ - if( L_sub(st_fx->core_brate_fx,FRAME_NO_DATA) > 0 ) - { - st_fx->num_ho_fx = 0; - move16(); - } - /* Update LSPs if last SID energy not outlier or insufficient number of hangover frames */ - test(); - IF( sub(st_fx->num_ho_fx,3) < 0 || L_sub(Mult_32_16(st_fx->Enew_fx,21845 /*1/1.5f, Q15*/), st_fx->lp_ener_fx) < 0 ) - { - FOR( i=0; ilspCNG_fx[i] = mac_r(L_mult(CNG_ISF_FACT_FX,st_fx->lspCNG_fx[i]),32768-CNG_ISF_FACT_FX,lsp_new[i]); - move16(); /* Q15 (15+15+1-16) */ - } - } - } - ELSE - { - /* Update CNG_mode if allowed */ - test(); - test(); - test(); - IF( ( st_fx->Opt_AMR_WB_fx || sub(st_fx->bwidth_fx,WB) == 0 ) - && ( !st_fx->first_CNG_fx || sub(st_fx->act_cnt2_fx,MIN_ACT_CNG_UPD) >= 0 ) ) - { - IF( L_sub(st_fx->last_active_brate_fx,ACELP_16k40) > 0) - { - st_fx->CNG_mode_fx = -1; - move16(); - } - ELSE IF( L_sub(st_fx->last_active_brate_fx,ACELP_13k20) > 0 ) - { - st_fx->CNG_mode_fx = 4; - move16(); - } - ELSE IF( L_sub(st_fx->last_active_brate_fx,ACELP_9k60) > 0 ) - { - st_fx->CNG_mode_fx = 3; - move16(); - } - ELSE IF( L_sub(st_fx->last_active_brate_fx,ACELP_8k00) > 0 ) - { - st_fx->CNG_mode_fx = 2; - move16(); - } - ELSE IF( L_sub(st_fx->last_active_brate_fx,ACELP_7k20) > 0 ) - { - st_fx->CNG_mode_fx = 1; - move16(); - } - ELSE - { - st_fx->CNG_mode_fx = 0; - move16(); - } - } - - /* If first sid after active burst update LSF history from circ buffer */ - st_fx->act_cnt_fx = 0; - move16(); - s_ptr = add(sub(st_fx->ho_circ_ptr_fx,burst_ho_cnt),1); - - if( s_ptr < 0 ) - { - s_ptr = add(s_ptr, st_fx->ho_circ_size_fx); - } - - FOR( ll = burst_ho_cnt; ll > 0; ll-- ) - { - st_fx->ho_hist_ptr_fx = add(st_fx->ho_hist_ptr_fx,1); - if( sub(st_fx->ho_hist_ptr_fx, HO_HIST_SIZE) == 0 ) - { - st_fx->ho_hist_ptr_fx = 0; - move16(); - } - - /* Conversion between 12.8k and 16k LSPs */ - test(); - test(); - IF( sub(L_frame,L_FRAME ) == 0 && sub(st_fx->ho_16k_lsp_fx[s_ptr],1) == 0 ) - { - /* Conversion from 16k LPSs to 12k8 */ - lsp_convert_poly_fx( &(st_fx->ho_lsp_circ_fx[s_ptr*M]), L_frame, 0 ); - } - ELSE IF ( sub(L_frame,L_FRAME16k) == 0 && st_fx->ho_16k_lsp_fx[s_ptr] == 0 ) - { - /* 16k LSPs already converted and stored, just copy to the other buffer */ - Copy(&(st_fx->ho_lsp_circ2_fx[s_ptr*M]), &(st_fx->ho_lsp_circ_fx[s_ptr*M]), M ); - } - /* update the circular buffers */ - Copy(&(st_fx->ho_lsp_circ_fx[s_ptr*M]), &(st_fx->ho_lsp_hist_fx[st_fx->ho_hist_ptr_fx*M]), M ); - Copy32(&(st_fx->ho_ener_circ_fx[s_ptr]), &(st_fx->ho_ener_hist_fx[st_fx->ho_hist_ptr_fx]), 1 ); - st_fx->ho_sid_bw_fx = L_shl(L_and(st_fx->ho_sid_bw_fx, (Word32) 0x3fffffffL ), 1); - Copy32(&(st_fx->ho_env_circ_fx[s_ptr*NUM_ENV_CNG]), &(st_fx->ho_env_hist_fx[st_fx->ho_hist_ptr_fx*NUM_ENV_CNG]), NUM_ENV_CNG ); - - st_fx->ho_hist_size_fx = add(st_fx->ho_hist_size_fx,1); - if (sub(st_fx->ho_hist_size_fx, HO_HIST_SIZE) > 0) - { - st_fx->ho_hist_size_fx = HO_HIST_SIZE; - move16(); - } - - s_ptr = add(s_ptr,1); - - if( sub(s_ptr, st_fx->ho_circ_size_fx) == 0 ) - { - s_ptr = 0; - move16(); - } - } - - IF ( burst_ho_cnt > 0) - { - /**allow_cn_step |= ( st_fx->ho_ener_hist_fx[st_fx->ho_hist_ptr_fx] > 4 * st_fx->lp_ener_fx ); */ - L_tmp1 = L_shr(st_fx->ho_ener_hist_fx[st_fx->ho_hist_ptr_fx],2); - L_tmp1 = L_sub(L_tmp1,st_fx->lp_ener_fx); - - if(L_tmp1>0) - { - *allow_cn_step = s_or(*allow_cn_step,1); - } - } - test(); - IF ( *allow_cn_step == 0 && st_fx->ho_hist_size_fx > 0 ) - { - /* Use average of energies below last energy */ - ptr = st_fx->ho_hist_ptr_fx; - move16(); - Copy( &(st_fx->ho_lsp_hist_fx[ptr*M]), tmp, M ); - m1 = 0; - move16(); - IF( L_and(st_fx->ho_sid_bw_fx, (Word32) 0x1) == 0 ) - { - Copy32( &st_fx->ho_env_hist_fx[ptr*NUM_ENV_CNG], tmp_env, NUM_ENV_CNG ); - m1 = 1; - move16(); - } - L_enr = Mult_32_16(st_fx->ho_ener_hist_fx[ptr],W_DTX_HO_FX[0]) ;/* Q6+15-15->Q6 */ - - weights = W_DTX_HO_FX[0]; /* Q15 */ - - m = 1; - move16(); - FOR( k=1; kho_hist_size_fx; k++ ) - { - ptr = sub(ptr,1); - if( ptr < 0 ) - { - ptr = HO_HIST_SIZE - 1; - move16(); - } - - test(); - IF ( L_sub(Mult_32_16(st_fx->ho_ener_hist_fx[ptr],ONE_OVER_BUF_H_NRG_FX),st_fx->ho_ener_hist_fx[st_fx->ho_hist_ptr_fx]) < 0 && - L_sub(st_fx->ho_ener_hist_fx[ptr],Mult_32_16(st_fx->ho_ener_hist_fx[st_fx->ho_hist_ptr_fx], BUF_L_NRG_FX)) > 0 ) - { - /*enr += W_DTX_HO[k] * st_fx->ho_ener_hist[ptr]; */ - L_tmp1 = Mult_32_16(st_fx->ho_ener_hist_fx[ptr],W_DTX_HO_FX[k]) ; /* Q6+15-15->Q6 */ - L_enr = L_add(L_enr,L_tmp1); /* Q6 */ - - /*weights += W_DTX_HO[k]; */ - weights = add( weights, W_DTX_HO_FX[k]); /* Q15 */ - - Copy( &st_fx->ho_lsp_hist_fx[ptr*M], &tmp[m*M], M ); - IF( L_and(st_fx->ho_sid_bw_fx, L_shl((Word32)0x1,k)) == 0 ) - { - Copy32( &st_fx->ho_env_hist_fx[ptr*NUM_ENV_CNG], &tmp_env[m1*NUM_ENV_CNG], NUM_ENV_CNG ); - m1 = add(m1,1); - } - m = add(m,1); - } - } - - /*enr /= weights; */ - exp = norm_s(weights); - tmp1 = div_s(shl(1,sub(14,exp)),weights); /* Q(15+14-exp-15) */ - L_tmp1 = Mult_32_16(L_enr,tmp1); /* Q(14-exp+6-15)->Q(5-exp) */ - L_enr = L_shl(L_tmp1,add(exp,1)); /* Q6 */ - - st_fx->lp_ener_fx = L_enr; - move32();/* Q6 */ - - set32_fx( max, 0, 2 ); - set16_fx( max_idx, 0, 2 ); - - FOR( i=0; iL_frame_fx,L_FRAME) == 0 ) - { - lsp2lsf_fx( &tmp[i*M], lsf_tmp, M, INT_FS_FX ); - ftmp_fx = 964; - move16();/*QX2.56 */ - tmpv = sub(16384,add(lsf_tmp[M-1],ftmp_fx)); /*QX2.56 */ - L_tmp = L_mult0(tmpv,tmpv); /*QX6.5536 */ - } - ELSE - { - lsp2lsf_fx( &tmp[i*M], lsf_tmp, M, INT_FS_16k ); - ftmp_fx = 1205; - move16();/*QX2.56 */ - tmpv = sub(20480,add(lsf_tmp[M-1],ftmp_fx)); /*QX2.56 */ - L_tmp = L_mult0(tmpv,tmpv); /*QX6.5536 */ - } - - tmpv = sub(lsf_tmp[0],ftmp_fx); /*QX2.56 */ - L_tmp = L_mac0(L_tmp,tmpv,tmpv); /*QX6.5536 */ - FOR ( j=0; j 0 ) - { - max[1] = max[0]; - move32(); - max_idx[1] = max_idx[0]; - move16(); - max[0] = C[i]; - move32(); - max_idx[0] = i; - move16(); - } - ELSE IF ( L_sub(C[i],max[1]) > 0 ) - { - max[1] = C[i]; - move32(); - max_idx[1] = i; - move16(); - } - } - - IF ( sub(m,1) == 0 ) - { - Copy(tmp, lsp_tmp, M); - } - ELSE IF ( sub(m,4) < 0 ) - { - FOR ( i=0; i 0 ) - { - max_dev = dev; - move16(); - } - } - - test(); - IF ( sub(dist,13107) > 0 || sub(max_dev,3277) > 0 ) - { - FOR( i=0; ilspCNG_fx[i] = lsp_tmp[i]; - move16(); /*Q15 */ - } - } - ELSE - { - FOR( i=0; ilspCNG_fx[i] = add(mult_r(26214,lsp_tmp[i]),mult_r(6554,lsp_new[i])); - move16(); - } - } - IF( m1 > 0 ) - { - FOR ( i=0; ilp_ener_fx; */ - IF(sub(m1,1) == 0) - { - L_tmp = L_sub(L_tmp,L_add(st_fx->lp_ener_fx,st_fx->lp_ener_fx)); - } - ELSE - { - tmp1 = div_s(1,m1); - L_tmp = Mult_32_16(L_tmp,tmp1); - L_tmp = L_sub(L_tmp,L_add(st_fx->lp_ener_fx,st_fx->lp_ener_fx)); - } - - env[i] = L_tmp; - move32(); - } - Copy32(env, st_fx->lp_env_fx, NUM_ENV_CNG); - } - } - ELSE - { - Copy( lsp_new, st_fx->lspCNG_fx, M ); /* use newly analyzed ISFs */ - } - } - IF ( st_fx->Opt_AMR_WB_fx != 0 ) - { - E_LPC_f_isp_a_conversion( st_fx->lspCNG_fx, Aq, M ); - } - ELSE - { - E_LPC_f_lsp_a_conversion( st_fx->lspCNG_fx, Aq, M ); /* Find A(z) (not interpolated) */ - } - - tmp_loop = shr(L_frame,6); - FOR( i=1; ibwidth_fx,NB) != 0 ) - { - test(); - IF( sub(st_fx->bwidth_fx,WB) == 0 && st_fx->CNG_mode_fx >= 0 ) - { - ftmp_fx = HO_ATT_FX[st_fx->CNG_mode_fx]; - } - ELSE - { - ftmp_fx = 19661; - move16(); - } - - att = mult(ftmp_fx,5461);/* Q15 */ - L_tmp = L_mult(att,8);/* Q16 */ - tmp1 = extract_l(L_shr(L_tmp,2));/* Q14 */ - tmp1 = add(16384,tmp1); - att = div_s(16374,tmp1); /* Q15 */ - - IF ( sub(att,ftmp_fx) < 0 ) - { - att = ftmp_fx; - move16(); - } - - FOR( i = 0; i < st_fx->L_frame_fx; i++ ) - { - /*res1[i] *= att;*/ - res1[i] = mult(res1[i],att); - move16();/* Q_new */ - } - att = shr(att,7);/* Q8 */ - } - - /* calculate the spectrum of residual signal */ - Copy(res1, fft_io, st_fx->L_frame_fx); - - IF ( sub(st_fx->L_frame_fx,L_FRAME16k) == 0 ) - { - modify_Fs_fx( fft_io, L_FRAME16k, 16000, fft_io, 12800, exc_mem2,0); - } - - fft_rel_fx(fft_io, L_FFT, LOG2_L_FFT); - ptR = &fft_io[1]; - ptI = &fft_io[L_FFT-1]; - FOR ( i=0; icng_res_env_fx[(st_fx->cng_hist_ptr_fx)*NUM_ENV_CNG]), NUM_ENV_CNG ); - - /* calculate the residual signal energy */ - /*enr = dotp( res, res, L_frame ) / L_frame; */ - maxv = 0; - move16(); - FOR(i = 0; i < st_fx->L_frame_fx; i++) - { - maxv = s_max(maxv, abs_s(res[i])); - } - scale = norm_s(maxv); - pt_res = res; - L_ener = L_deposit_l(1); - IF( sub(L_frame, L_FRAME) == 0) - { - FOR (j=0; j<128; j++) - { - tmpv = shl(*pt_res,scale); - L_tmp = L_mult0(tmpv, tmpv); - pt_res++; - tmpv = shl(*pt_res,scale); - L_tmp = L_mac0(L_tmp, tmpv, tmpv); /* 2*(Q_new+scale) */ - pt_res++; - L_ener = L_add(L_ener, L_shr(L_tmp, 7)); /* 2*(Q_new+scale)+1, divide by L_frame done here */ - } - } - ELSE /* L_FRAME16k */ - { - FOR (j=0; j<160; j++) - { - tmpv = shl(*pt_res,scale); - L_tmp = L_mult0(tmpv, tmpv); - pt_res++; - tmpv = shl(*pt_res,scale); - L_tmp = L_mac0(L_tmp, tmpv, tmpv); /* 2*(Q_new+scale) */ - pt_res++; - L_ener = L_add(L_ener, L_shr(Mult_32_16(L_tmp,26214 /* 256/320, Q15 */), 7)); /* 2*(Q_new+scale)+15+1-16+1, divide by L_frame done here */ - } - } - /* convert log2 of residual signal energy */ - /*enr = (float)log10( enr + 0.1f ) / (float)log10( 2.0f ); */ - hi = norm_l(L_ener); - lo = Log2_norm_lc(L_shl(L_ener, hi)); - hi = sub(29, hi); /* log2 exp in Q2*(Q_new+scale) */ - hi = sub(hi, shl(add(Q_new,scale), 1)); /* Q0 */ - L_tmp = L_Comp(hi, lo); /* Q16 */ - enr = round_fx(L_shl(L_tmp, 8)); /* Q8 (16+8-16) */ - - /* update the circular buffer of old energies */ - st_fx->cng_ener_hist_fx[st_fx->cng_hist_ptr_fx] = enr; - move16(); /* Q8 */ - - /*-----------------------------------------------------------------* - * Quantize residual signal energy (only in SID frame) - *-----------------------------------------------------------------*/ - test(); - IF( L_sub(st_fx->core_brate_fx, SID_2k40) == 0 || L_sub(st_fx->core_brate_fx, SID_1k75) == 0 ) - { - IF( sub(st_fx->cng_cnt_fx,sub(st_fx->cng_hist_size_fx,1)) >= 0 ) - { - /* average the envelope except outliers */ - FOR ( i=0; icng_hist_size_fx; j++ ) - { - L_tmp1 = L_add(L_tmp1,st_fx->cng_res_env_fx[j*NUM_ENV_CNG+i]); - } - L_tmp = L_add(st_fx->cng_res_env_fx[max_idx1[0]*NUM_ENV_CNG+i],st_fx->cng_res_env_fx[max_idx1[1]*NUM_ENV_CNG+i]); - L_tmp1 = L_sub(L_tmp1,L_tmp); - - /* env[i] /= (float)(st_fx->cng_hist_size_fx - 2); */ - tmp1 = sub(st_fx->cng_hist_size_fx,2); - IF(sub(tmp1,1) > 0) - { - tmp1 = div_s(1,tmp1); - L_tmp1 = Mult_32_16(L_tmp1,tmp1); - } - - env[i] = L_tmp1; - move32(); - } - /* compute average excitation energy */ - L_tmp = L_deposit_l(0); - ptr = st_fx->cng_hist_ptr_fx; - move16(); - - FOR (k=0; kcng_hist_size_fx; k++) - { - /* enr += W_HIST[k]*cng_ener_hist[ptr] */ - L_tmp = L_mac0(L_tmp, W_HIST_FX[k], st_fx->cng_ener_hist_fx[ptr]); /* Q24 (8+16) */ - ptr = sub(ptr, 1); - if (ptr < 0) /* check for circular pointer */ - { - ptr = DTX_HIST_SIZE - 1; - move16(); - } - } - /*----------------------------------------------------------- - * here we want to divide L_tmp by the sum - * of all the coefs used W_HIST[0..cng_hist_size-1] - * The table W_HIST_S already contains the inverted sum. - * That is - * W_HIST_S[k] 1 - * ------------- = --------------------------- - * 4096 W_HIST[0] + ... + W_HIST[k] - * - * 1 / Sum(W_HIST[0..k]) is always > 1 since the sum - * of the coefs 0..k is always < 1 but > 0 - * enr is in Q8 since the history buffer constains Q8 energies - *-----------------------------------------------------------*/ - /*L_tmp = Mpy_32_16_1(L_tmp, W_HIST_S_FX[k-1]); */ /* normalize average value */ - L_tmp = Mult_32_16(L_tmp, W_HIST_S_FX[k-1]); /* Q21 (24+12+1-16) */ - L_tmp = L_shl(L_tmp, 3); /* Q24 */ - enr = round_fx(L_tmp); /* Q8 */ - } - /* decrease the energy in case of WB input */ - IF( sub(st_fx->bwidth_fx, NB) != 0 ) - { - IF( sub(st_fx->bwidth_fx,WB) == 0 ) - { - IF( st_fx->CNG_mode_fx >= 0 ) - { - /* Bitrate adapted attenuation */ - att = ENR_ATT_fx[st_fx->CNG_mode_fx]; - move16(); - } - ELSE - { - /* Use least attenuation for higher bitrates */ - att = ENR_ATT_fx[4]; - move16(); - } - } - ELSE - { - att = 384; - move16();/*Q8*/ - } - enr = sub(enr, att ); - } - /* intialize the energy quantization parameters */ - IF( st_fx->Opt_AMR_WB_fx == 0 ) - { - step = STEP_SID_FX; - move16(); - step_inv = ISTEP_SID_FX; - move16(); - maxl = 127; - move16(); - num_bits = 7; - move16(); - } - ELSE - { - step = STEP_AMR_WB_SID_FX; - move16(); - step_inv = ISTEP_AMR_WB_SID_FX; - move16(); - maxl = 63; - move16(); - num_bits = 6; - move16(); - } - - /* calculate the energy quantization index */ - enr_index = add(enr, 512 /* Q8(2.0) */); /* enr + 2.0 */ - enr_index = extract_l(L_shr(L_mult0(enr_index, step), 12+8)); /* Q0 (8+12-(8+12)) */ - - /* limit the energy quantization index */ - enr_index = s_min(enr_index, maxl); - enr_index = s_max(enr_index, 0); - - /* allow only slow energy increase */ - test(); - IF( st_fx->old_enr_index_fx >= 0 && sub(enr_index, add(st_fx->old_enr_index_fx, MAX_DELTA)) > 0 ) - { - IF( *allow_cn_step != 0 ) - { - tmp1 = mult(27853 /* Q15(0.85) */,sub(enr_index,st_fx->old_enr_index_fx)); - enr_index = add(st_fx->old_enr_index_fx,tmp1); - } - ELSE - { - enr_index = add(st_fx->old_enr_index_fx, MAX_DELTA); - } - } - st_fx->old_enr_index_fx = enr_index; - move16(); - - push_indice_fx( st_fx, IND_ENERGY, enr_index, num_bits ); - if ( enr_index == 0 ) - { - enr_index = -5; - move16(); - } - /* Find quantized energy */ - /* *Enew = (float)enr_index / step - 2.0 */ - /* *Enew = (float)pow(2.0, *Enew) */ - L_tmp = L_mult(enr_index, step_inv); /* Q16(0+15+1) */ - /* substract by 2 not done to leave Energy in Q2 */ - lo = L_Extract_lc(L_tmp, &hi); - st_fx->Enew_fx = Pow2(add(hi, 4), lo); /* Q6 */ - IF ( L_sub(st_fx->core_brate_fx, SID_2k40) == 0 ) - { - /* enr1 = (float)log10( st->Enew*L_frame + 0.1f ) / (float)log10( 2.0f );*/ - exp = norm_l(st_fx->Enew_fx); - L_tmp = L_shl(st_fx->Enew_fx,exp); /*Q(exp+6) */ - L_tmp = Mult_32_16(L_tmp,shl(L_frame,5));/* Q(exp+6+5-15=exp-4) */ - L_tmp = L_shr(L_tmp,sub(exp,10)); /* Q6 */ - - exp = norm_l(L_tmp); - fra = Log2_norm_lc(L_shl(L_tmp,exp)); - exp = sub(sub(30,exp),6); - L_tmp = L_Comp(exp,fra); - enr1 = L_shr(L_tmp,10);/* Q6 */ - - FOR ( i=0; iEnew;*/ - L_tmp1 = L_add(env[i], 0); - L_tmp = L_add(st_fx->Enew_fx,st_fx->Enew_fx); - L_tmp1 = L_sub(L_tmp1,L_tmp); /*Q6*/ - - IF ( L_tmp1 < 0 ) - { - L_tmp1 = L_deposit_l(6); /* (0.1)Q6 */ - } - /* env[i] = (float)log10( env[i] + 0.1f ) / (float)log10( 2.0f ); */ - exp = norm_l(L_tmp1); - fra = Log2_norm_lc(L_shl(L_tmp1,exp)); - exp = sub(sub(30,exp),6); - L_tmp = L_Comp(exp,fra); - L_tmp1 = L_shr(L_tmp,10); /* Q6 */ - - L_tmp = L_shr(L_deposit_l(att),2);/* Q6 */ - L_tmp1 = L_sub(L_tmp1,L_tmp); - - IF ( L_tmp1 < 0 ) - { - L_tmp1 = L_deposit_l(0); - } - - L_tmp1 = L_sub(enr1,L_tmp1); - - env[i] = L_tmp1; - move32(); - } - - /* codebook search */ - min1 = L_add(1310588928, 0); /* Q17 */ - min1_idx = 0; - move16(); - - FOR ( i=0; i<64; i++ ) - { - d = L_deposit_l(0); - FOR ( j=0; jEnew_fx,21845 /*1/1.5f, Q15*/), st_fx->lp_ener_fx) < 0 ) - { - /* update the pointer to circular buffer of old LSP vectors */ - st_fx->ho_hist_ptr_fx = add(st_fx->ho_hist_ptr_fx, 1); - if( sub(st_fx->ho_hist_ptr_fx,HO_HIST_SIZE) == 0 ) - { - st_fx->ho_hist_ptr_fx = 0; - move16(); - } - - /* update the circular buffer of old LSP vectors with the new LSP vector */ - Copy( lsp_new, &(st_fx->ho_lsp_hist_fx[(st_fx->ho_hist_ptr_fx)*M]), M ); - - /* update the hangover energy buffer */ - st_fx->ho_ener_hist_fx[st_fx->ho_hist_ptr_fx] = st_fx->Enew_fx; - move32(); - IF ( L_sub(st_fx->core_brate_fx, SID_2k40) == 0 ) - { - FOR ( i=0; iEnew;*/ - L_tmp = L_sub(enr1,q_env[i]);/* Q6 */ - L_tmp = L_shl(L_tmp, 10);/* 16 */ - temp_lo_fx = L_Extract_lc(L_tmp, &temp_hi_fx); - - exp_pow = sub(14, temp_hi_fx); - L_tmp = Pow2(14, temp_lo_fx); /* Qexp_pow */ - env[i] = L_shl(L_tmp, sub(6, exp_pow)); - move32(); /* Q6 */ - L_tmp = L_add(st_fx->Enew_fx,st_fx->Enew_fx); - env[i] = L_add(env[i],L_tmp); - move32();/* Q6 */ - } - Copy32( env, &(st_fx->ho_env_hist_fx[(st_fx->ho_hist_ptr_fx)*NUM_ENV_CNG]), NUM_ENV_CNG ); - } - st_fx->ho_hist_size_fx = add(st_fx->ho_hist_size_fx,1); - if( sub(st_fx->ho_hist_size_fx,HO_HIST_SIZE) > 0 ) - { - st_fx->ho_hist_size_fx = HO_HIST_SIZE; - move16(); - } - } - } - /* dithering bit for AMR-WB IO mode is always set to 0 */ - IF( L_sub(st_fx->core_brate_fx, SID_1k75) == 0 ) - { - push_indice_fx( st_fx, IND_DITHERING, 0, 1 ); - } - IF ( L_sub(st_fx->core_brate_fx, SID_2k40) == 0 ) - { - IF(sub(st_fx->L_frame_fx, L_FRAME16k) == 0) - { - push_indice_fx( st_fx, IND_ACELP_16KHZ, 1, 1 ); - } - ELSE - { - push_indice_fx( st_fx, IND_ACELP_16KHZ, 0, 1 ); - } - } - - IF ( L_sub(st_fx->core_brate_fx, SID_2k40) == 0 ) - { - push_indice_fx( st_fx, IND_CNG_HO, s_min(st_fx->burst_ho_cnt_fx, 7 ), 3 ); - st_fx->num_ho_fx = m; - move16(); - push_indice_fx( st_fx, IND_SID_TYPE, 0, 1 ); - - IF ( L_sub(st_fx->input_Fs_fx, 32000) < 0 ) - { - push_indice_fx( st_fx, IND_SID_BW, 0, 1 ); - *sid_bw = 0; - move16(); - } - } - - /*-----------------------------------------------------------------* - * Updates - *-----------------------------------------------------------------*/ - /* update the SID frames counter */ - test(); - IF( L_sub(st_fx->core_brate_fx, SID_2k40) == 0 || L_sub(st_fx->core_brate_fx, SID_1k75) == 0 ) - { - st_fx->cng_cnt_fx = 0; - move16(); - st_fx->cng_hist_ptr_fx = -1; - move16(); - /* update frame length memory */ - st_fx->last_CNG_L_frame_fx = st_fx->L_frame_fx; - move16(); - } - ELSE - { - st_fx->cng_cnt_fx = add(st_fx->cng_cnt_fx,1); - } - - return; -} -/*---------------------------------------------------------------------* - * swb_CNG_enc() - * - * SWB DTX/CNG encoding - *---------------------------------------------------------------------*/ -void swb_CNG_enc_fx( - Encoder_State_fx *st_fx, /* i/o: State structure */ - const Word16 *shb_speech_fx, /* i : SHB target signal (6-14kHz) at 16kHz (Q0) */ - const Word16 *syn_12k8_16k_fx /* i : ACELP core synthesis at 12.8kHz or 16kHz (st_fx->Q_syn = 0) */ -) -{ - Word16 shb_SID_updt_fx=0; - - test(); - IF ( L_sub(st_fx->core_brate_fx, SID_2k40) == 0 || st_fx->core_brate_fx == FRAME_NO_DATA ) - { - IF (sub(st_fx->cng_type_fx,LP_CNG) == 0) - { - /* decide if SHB SID encoding or not */ - shb_SID_updt_fx = shb_DTX_fx( st_fx, shb_speech_fx, syn_12k8_16k_fx ); - - /* SHB CNG encoding */ - shb_CNG_encod_fx( st_fx, shb_SID_updt_fx ); - } - st_fx->last_vad_fx = 0; - move16(); - } - ELSE - { - st_fx->last_vad_fx = 1; - move16(); - } - - return; -} - -/*---------------------------------------------------------------------* - * shb_CNG_encod() - * - * SID parameters encoding for SHB signal - *---------------------------------------------------------------------*/ -static void shb_CNG_encod_fx( - Encoder_State_fx *st_fx, /* i/o: State structure */ - const Word16 update_fx /* i : SID update flag */ -) -{ - Word16 idx_ener_fx; - - idx_ener_fx = 0; - move16(); - IF ( sub(update_fx, 1) == 0 ) - { - /* SHB energy quantization */ - idx_ener_fx = shr(add(mult(st_fx->mov_shb_cng_ener_fx, 9797), 1510), 8); /* Q0 */ - - if ( sub(st_fx->bwidth_fx, SWB) < 0 ) - { - idx_ener_fx = 0; - move16(); - } - - IF ( sub(idx_ener_fx, 15) > 0 ) - { - idx_ener_fx = 15; - move16(); - } - ELSE - { - idx_ener_fx = s_max(idx_ener_fx,0); - } - - push_indice_fx( st_fx, IND_SHB_CNG_GAIN, idx_ener_fx, 4); - push_indice_fx( st_fx, IND_SID_BW, 1, 1 ); - st_fx->nb_bits_tot_fx = sub(st_fx->nb_bits_tot_fx,st_fx->ind_list_fx[IND_CNG_ENV1].nb_bits); - st_fx->ind_list_fx[IND_CNG_ENV1].nb_bits = -1; - move16(); - push_indice_fx( st_fx, IND_UNUSED, 0, 2); - st_fx->ho_sid_bw_fx = L_shl(L_and(st_fx->ho_sid_bw_fx, (Word32) 0x3fffffffL ), 1); - st_fx->ho_sid_bw_fx = L_or(st_fx->ho_sid_bw_fx, 0x1L); - } - ELSE - { - IF ( L_sub(st_fx->core_brate_fx, SID_2k40) == 0 ) - { - st_fx->ho_sid_bw_fx = L_shl(L_and(st_fx->ho_sid_bw_fx, (Word32) 0x3fffffffL ), 1); - push_indice_fx( st_fx, IND_SID_BW, 0, 1 ); - } - } - - return; -} - -/*---------------------------------------------------------------------* -* shb_DTX() -* -* Decide if encoding SHB SID or not -*---------------------------------------------------------------------*/ -static Word16 shb_DTX_fx( - Encoder_State_fx *st_fx, /* i/o: State structure */ - const Word16 *shb_speech_fx, /* i : SHB target signal (6-14kHz) at 16kHz (Q0) */ - const Word16 *syn_12k8_16k /* i : ACELP core synthesis at 12.8kHz or 16kHz (st_fx->Q_syn = 0) */ -) -{ - Word16 i; - Word16 update_fx; - Word16 shb_old_speech_fx[(ACELP_LOOK_12k8 + L_SUBFR + L_FRAME) * 5/4]; - Word16 *shb_new_speech_fx; - Word32 wb_ener_fx; - Word32 shb_ener_fx; - Word16 log_wb_ener_fx; - Word16 log_shb_ener_fx; - Word16 tmp; - Word16 exp; - Word16 fra; - Word16 allow_cn_step_fx=0; - - shb_new_speech_fx = shb_old_speech_fx + (ACELP_LOOK_12k8 + L_SUBFR) * 5/4; - Copy( st_fx->old_speech_shb_fx, shb_old_speech_fx, (ACELP_LOOK_12k8 + L_SUBFR) * 5/4 ); - Copy( shb_speech_fx, shb_new_speech_fx, L_FRAME16k ); - Copy( shb_old_speech_fx + L_FRAME16k, st_fx->old_speech_shb_fx, (ACELP_LOOK_12k8 + L_SUBFR) * 5/4 ); - - shb_ener_fx = L_deposit_l(0); - FOR ( i=0; iL_frame_fx; i++ ) - { - wb_ener_fx = L_mac(wb_ener_fx, syn_12k8_16k[i], syn_12k8_16k[i]); - } - - wb_ener_fx = L_add(Mpy_32_16_1(wb_ener_fx, 128), 1); /* 128 in Q15, wb_ener_fx in Q1 */ - - exp = norm_l(wb_ener_fx); - fra = Log2_norm_lc(L_shl(wb_ener_fx, exp)); - exp = sub(30-1, exp); - wb_ener_fx = Mpy_32_16(exp, fra, LG10); - log_wb_ener_fx = round_fx(L_shl(wb_ener_fx, 10)); /* log_wb_ener_fx in Q8 */ - - exp = norm_l(shb_ener_fx); - fra = Log2_norm_lc(L_shl(shb_ener_fx, exp)); - exp = sub(30-1, exp); - shb_ener_fx = Mpy_32_16(exp, fra, LG10); - log_shb_ener_fx = sub(round_fx(L_shl(shb_ener_fx, 10)), 1664); /* log_shb_ener_fx in Q8 */ - - IF ( st_fx->first_CNG_fx == 0 ) - { - st_fx->mov_wb_cng_ener_fx = log_wb_ener_fx; - move16(); - st_fx->mov_shb_cng_ener_fx = log_shb_ener_fx; - move16(); - st_fx->last_wb_cng_ener_fx = log_wb_ener_fx; - move16(); - st_fx->last_shb_cng_ener_fx = log_shb_ener_fx; - move16(); - } - - if ( sub(abs_s(sub(log_wb_ener_fx, st_fx->mov_wb_cng_ener_fx)), 3072) > 0 ) - { - allow_cn_step_fx = 1; - move16(); - } - - IF ( sub(allow_cn_step_fx, 1) == 0 ) - { - st_fx->mov_wb_cng_ener_fx = log_wb_ener_fx; - move16(); - st_fx->mov_shb_cng_ener_fx = log_shb_ener_fx; - move16(); - } - ELSE - { - tmp = sub(log_wb_ener_fx, st_fx->mov_wb_cng_ener_fx); /* Q8 */ - tmp = mult(tmp, 29491); /* Q8 */ - st_fx->mov_wb_cng_ener_fx = add(st_fx->mov_wb_cng_ener_fx, tmp); /* Q8 */ - - tmp = sub(log_shb_ener_fx, st_fx->mov_shb_cng_ener_fx); - tmp = mult(tmp, 8192); /* Q8 */ - st_fx->mov_shb_cng_ener_fx = add(st_fx->mov_shb_cng_ener_fx, tmp); /* Q8 */ - } - st_fx->shb_NO_DATA_cnt_fx = add(st_fx->shb_NO_DATA_cnt_fx, 1); - - update_fx = 0; - move16(); - IF ( L_sub(st_fx->core_brate_fx, SID_2k40) == 0 ) - { - test(); - test(); - IF ( st_fx->first_CNG_fx == 0 || sub(st_fx->last_vad_fx, 1) == 0 || sub(st_fx->shb_NO_DATA_cnt_fx, 100) >= 0 ) - { - update_fx = 1; - move16(); - } - ELSE - { - IF ( st_fx->shb_cng_ini_cnt_fx > 0 ) - { - update_fx = 1; - move16(); - st_fx->shb_cng_ini_cnt_fx = sub(st_fx->shb_cng_ini_cnt_fx, 1); - } - ELSE - { - IF ( sub(abs_s(sub(sub(st_fx->mov_wb_cng_ener_fx, st_fx->mov_shb_cng_ener_fx), sub(st_fx->last_wb_cng_ener_fx, st_fx->last_shb_cng_ener_fx))), 768) > 0 ) - { - update_fx = 1; - move16(); - } - ELSE - { - test(); - IF ( sub(st_fx->bwidth_fx, SWB) >= 0 && sub(st_fx->last_SID_bwidth_fx, SWB) < 0 ) - { - update_fx = 1; - move16(); - } - ELSE - { - test(); - IF ( sub(st_fx->bwidth_fx, SWB) < 0 && sub(st_fx->last_SID_bwidth_fx, SWB) >= 0 ) - { - update_fx = 1; - move16(); - } - } - } - } - } - - st_fx->last_SID_bwidth_fx = st_fx->bwidth_fx; - move16(); - } - - IF ( sub(update_fx, 1) == 0 ) - { - st_fx->last_wb_cng_ener_fx = st_fx->mov_wb_cng_ener_fx; - move16(); - st_fx->last_shb_cng_ener_fx = st_fx->mov_shb_cng_ener_fx; - move16(); - st_fx->shb_NO_DATA_cnt_fx = 0; - move16(); - } - - - return (update_fx); -} diff --git a/src/libs/libevs/lib_enc/cod2t32.cpp b/src/libs/libevs/lib_enc/cod2t32.cpp new file mode 100644 index 00000000..d6137a32 --- /dev/null +++ b/src/libs/libevs/lib_enc/cod2t32.cpp @@ -0,0 +1,304 @@ +/*==================================================================================== + EVS Codec 3GPP TS26.443 Nov 13, 2018. Version 12.11.0 / 13.7.0 / 14.3.0 / 15.1.0 + ====================================================================================*/ + +#include "options.h" +#include "cnst.h" +#include "prot.h" + + +/*---------------------------------------------------------------------* + * Local constants + *---------------------------------------------------------------------*/ + +#define STEP 2 +#define MSIZE 1024 + + +/*---------------------------------------------------------------------------------- + * Function acelp_2t32() + * + * 12 bits algebraic codebook. + * 2 tracks x 32 positions per track = 64 samples. + * + * 12 bits --> 2 pulses in a frame of 64 samples. + * + * All pulses can have two (2) possible amplitudes: +1 or -1. + * Each pulse can have 32 possible positions. + *----------------------------------------------------------------------------------*/ + +void acelp_2t32( + Encoder_State *st, /* i/o: encoder state structure */ + const float dn[], /* i : corr. between target and h[]. */ + const float h[], /* i : impulse response of weighted synthesis filter */ + float code[], /* o : algebraic (fixed) codebook excitation */ + float y[] /* o : filtered fixed codebook excitation */ +) +{ + short i, j, k, i0, i1, ix, iy, pos, pos2, index; + float psk, ps1, ps2, alpk, alp1, alp2, sq; + float pol[L_SUBFR], dn_p[L_SUBFR], r0; + short ii,jj; + float s, cor, sign0, sign1; + float *p0, *p1, *p2; + const float *ptr_h1, *ptr_h2, *ptr_hf; + float rrixix[NB_TRACK_FCB_2T][NB_POS_FCB_2T]; + float rrixiy[MSIZE]; + + + /*----------------------------------------------------------------* + * Compute rrixix[][] needed for the codebook search. + *----------------------------------------------------------------*/ + + /* Init pointers to last position of rrixix[] */ + p0 = &rrixix[0][NB_POS_FCB_2T - 1]; + p1 = &rrixix[1][NB_POS_FCB_2T - 1]; + + ptr_h1 = h; + cor = 0.0f; + for (i = 0; i < NB_POS_FCB_2T; i++) + { + cor += *ptr_h1 **ptr_h1; + ptr_h1++; + *p1-- = cor; + cor += *ptr_h1 **ptr_h1; + ptr_h1++; + *p0-- = cor; + } + + p0 = rrixix[0]; + p1 = rrixix[1]; + + for (i = 0; i < NB_POS_FCB_2T; i++) + { + *p0 = 0.5f * (*p0); + p0++; + *p1 = 0.5f * (*p1); + p1++; + } + + /*------------------------------------------------------------* + * Compute rrixiy[][] needed for the codebook search. + *------------------------------------------------------------*/ + + pos = MSIZE - 1; + pos2 = MSIZE - 2; + ptr_hf = h + 1; + + for (k = 0; k < NB_POS_FCB_2T; k++) + { + /* Init pointers to last position of diagonals */ + p1 = &rrixiy[pos]; + p0 = &rrixiy[pos2]; + + cor = 0.0f; + ptr_h1 = h; + ptr_h2 = ptr_hf; + + for (i = k+1; i < NB_POS_FCB_2T; i++) + { + cor += *ptr_h1++ **ptr_h2++; + *p1 = cor; + + cor += *ptr_h1++ **ptr_h2++; + *p0 = cor; + + p1 -= (NB_POS_FCB_2T + 1); + p0 -= (NB_POS_FCB_2T + 1); + } + + cor += *ptr_h1++ **ptr_h2; + *p1 = cor; + + pos -= NB_POS_FCB_2T; + pos2--; + ptr_hf += STEP; + } + + /*----------------------------------------------------------------* + * computing reference vector and pre-selection of polarities + *----------------------------------------------------------------*/ + + for(i=0; i=0.0f) + { + pol[i]= 1.0f; + } + else + { + pol[i]=-1.0f; + } + + /* including polarities into dn[] */ + dn_p[i]=dn[i]*pol[i]; + } + + /*----------------------------------------------------------------* + * compute denominator ( multiplied by polarity ) + *----------------------------------------------------------------*/ + + k=0; + ii=0; + for(i=0; i 0) + { + psk = sq; + alpk = alp2; + pos = i1; + } + } + p1 -= NB_POS_FCB_2T; + if (pos >= 0) + { + ix = i0; + iy = pos; + } + } + + i0 = ix/STEP; + i1 = iy/STEP; + sign0 = pol[ix]; + sign1 = pol[iy]; + + + /*-------------------------------------------------------------------* + * Build the codeword, the filtered codeword and index of codevector. + *-------------------------------------------------------------------*/ + + set_f( code, 0.0f, L_SUBFR ); + + code[ix] = sign0; + code[iy] = sign1; + index = (i0<<6) + i1; + + if(sign0 < 0.0f) + { + index += 0x800; + } + + if(sign1 < 0.0f) + { + index += 0x20; + } + + set_f( y, 0.0f, L_SUBFR ); + for(i=ix; i 0 ) + { + index += L_SUBFR; + } + + push_indice( st, IND_ALG_CDBK_1T64, index, 7 ); + + return; +} diff --git a/src/libs/libevs/lib_enc/cod2t32_fx.cpp b/src/libs/libevs/lib_enc/cod2t32_fx.cpp deleted file mode 100755 index ac9a7f09..00000000 --- a/src/libs/libevs/lib_enc/cod2t32_fx.cpp +++ /dev/null @@ -1,383 +0,0 @@ -/*==================================================================================== - EVS Codec 3GPP TS26.442 Apr 03, 2018. Version 12.11.0 / 13.6.0 / 14.2.0 - ====================================================================================*/ - -#include "options.h" /* Compilation switches */ -#include "cnst_fx.h" /* Common constants */ -#include "prot_fx.h" /* Function prototypes */ -#include "stl.h" - - -/*-------------------------------------------------------------------* -* Local Constants -*-------------------------------------------------------------------*/ - -#define STEP 2 -#define MSIZE 1024 - -/*---------------------------------------------------------------------------------- -* Function acelp_2t32() -* -* 12 bits algebraic codebook. -* 2 tracks x 32 positions per track = 64 samples. -* -* 12 bits --> 2 pulses in a frame of 64 samples. -* -* All pulses can have two (2) possible amplitudes: +1 or -1. -* Each pulse can have 32 possible positions. -*----------------------------------------------------------------------------------*/ - -void acelp_2t32_fx( - Encoder_State_fx *st_fx, /* i/o: encoder state structure */ - const Word16 dn[], /* i : corr. between target and h[]. */ - const Word16 h[], /* i : impulse response of weighted synthesis filter */ - Word16 code[], /* o : algebraic (fixed) codebook excitation */ - Word16 y[] /* o : filtered fixed codebook excitation */ -) -{ - Word16 i, j, k, i0, i1, ix, iy, pos, pos2, sign0, sign1,index; - Word16 ps1, ps2, alpk, alp1, alp2; - Word16 sq,psk; - Word16 pol[L_SUBFR], dn_p[L_SUBFR]; - Word16 ii,jj; - Word16 *p0, *p1, *p2; - const Word16 *ptr_h1, *ptr_h2, *ptr_hf; - - Word32 s, L_cor; - Word32 L_tmp; - Word16 rrixix[NB_TRACK_FCB_2T][NB_POS_FCB_2T]; - Word16 rrixiy[MSIZE]; - - /*----------------------------------------------------------------* - * Compute rrixix[][] needed for the codebook search. - *----------------------------------------------------------------*/ - - /* Init pointers to last position of rrixix[] */ - p0 = &rrixix[0][NB_POS_FCB_2T - 1]; - move16(); - p1 = &rrixix[1][NB_POS_FCB_2T - 1]; - move16(); - - ptr_h1 = h; - move16(); - L_cor = L_deposit_h(1); - FOR (i = 0; i < NB_POS_FCB_2T; i++) - { - L_cor = L_mac(L_cor, *ptr_h1, *ptr_h1); - ptr_h1++; - *p1-- = extract_h(L_cor); - move16(); /*Q9 Q7*/ - L_cor = L_mac(L_cor, *ptr_h1, *ptr_h1); - ptr_h1++; - *p0-- = extract_h(L_cor); - move16(); /*Q9 Q7*/ - } - - p0 = rrixix[0]; - move16(); - p1 = rrixix[1]; - move16(); - - FOR (i = 0; i < NB_POS_FCB_2T; i++) - { - *p0 = shr(*p0, 1); - move16(); - p0++; - *p1 = shr(*p1, 1); - move16(); - p1++; - } - - /*------------------------------------------------------------* - * Compute rrixiy[][] needed for the codebook search. - *------------------------------------------------------------*/ - - pos = MSIZE - 1; - move16(); - pos2 = MSIZE - 2; - move16(); - ptr_hf = h + 1; - move16(); - - FOR (k = 0; k < NB_POS_FCB_2T; k++) - { - /* Init pointers to last position of diagonals */ - p1 = &rrixiy[pos]; - move16(); - p0 = &rrixiy[pos2]; - move16(); - - ptr_h1 = h; - move16(); - ptr_h2 = ptr_hf; - move16(); - - L_cor = L_mult(*ptr_h1++, *ptr_h2++); - FOR (i = k; i < NB_POS_FCB_2T-1; i++) - { - *p1 = round_fx(L_cor); - L_cor = L_mac(L_cor, *ptr_h1++, *ptr_h2++); - *p0 = round_fx(L_cor); - L_cor = L_mac(L_cor, *ptr_h1++, *ptr_h2++); - - p1 -= (NB_POS_FCB_2T + 1); - move16(); - p0 -= (NB_POS_FCB_2T + 1); - move16(); - } - - *p1 = round_fx(L_cor); - - pos -= NB_POS_FCB_2T; - move16(); - pos2--; - ptr_hf += STEP; - move16(); - } - - /*----------------------------------------------------------------* - * computing reference vector and pre-selection of polarities - *----------------------------------------------------------------*/ - - L_tmp = L_deposit_h(dn[0]); - FOR(i=0; i=0) - { - pol[i] = 1; - move16(); - dn_p[i] = dn[i]; - move16(); - } - ELSE - { - pol[i] = -1; - move16(); - dn_p[i] = negate(dn[i]); - move16(); - } - } - - /*----------------------------------------------------------------* - * compute denominator ( multiplied by polarity ) - *----------------------------------------------------------------*/ - - k=0; - ii=0; - move16(); - move16(); - FOR(i=0; i 0) - { - psk = sq; - move16(); - alpk = alp2; - move16(); - pos = i1; - move16(); - } - } - p1 -= NB_POS_FCB_2T; - move16(); - - IF (pos >= 0) - { - ix = i0; - move16(); - iy = pos; - move16(); - } - } - - i0 = shr(ix,1); - i1 = shr(iy,1); - - sign0 = shl(pol[ix],9); - sign1 = shl(pol[iy],9); - - /*-------------------------------------------------------------------* - * Build the codeword, the filtered codeword and index of codevector. - *-------------------------------------------------------------------*/ - - set16_fx( code, 0, L_SUBFR ); - - code[ix] = sign0; - move16(); - code[iy] = sign1; - move16(); - - index = add(shl(i0, 6), i1); - - - if (sign0 < 0) - { - index = add(index, 0x800); - } - if (sign1 < 0) - { - index = add(index, 0x20); /* move16();*/ - } - - set16_fx( y, 0, L_SUBFR ); - /* y_Q9 = sign_Q9<<3 * h_Q12 */ - - sign0 = shl(sign0, 3); - sign1 = shl(sign1, 3); - - FOR(i=ix; i0) - { - y[i] = shr_r(h[i-pos],3); - move16(); - } - ELSE - { - y[i] = negate(shr_r(h[i-pos],3)); - move16(); - } - } - - index = pos; - move16(); - if( sgn > 0 ) - { - index = add(index,L_SUBFR); - } - { - push_indice_fx( st_fx, IND_ALG_CDBK_1T64, index, 7 ); - } - - return; -} diff --git a/src/libs/libevs/lib_enc/cod4t64.cpp b/src/libs/libevs/lib_enc/cod4t64.cpp new file mode 100644 index 00000000..8e435642 --- /dev/null +++ b/src/libs/libevs/lib_enc/cod4t64.cpp @@ -0,0 +1,957 @@ +/*==================================================================================== + EVS Codec 3GPP TS26.443 Nov 13, 2018. Version 12.11.0 / 13.7.0 / 14.3.0 / 15.1.0 + ====================================================================================*/ + +#include +#include "options.h" +#include "cnst.h" +#include "rom_enc.h" +#include "prot.h" +#include "rom_com.h" + + +/*---------------------------------------------------------------------* + * Local functions + *---------------------------------------------------------------------*/ + +static short quant_1p_N1( const short pos, const short N ); +static short quant_2p_2N1( const short pos1, const short pos2, const short N ); +static short quant_3p_3N1( const short pos1, const short pos2, const short pos3, const short N ); +static long quant_4p_4N( const short pos[], const short N ); +static long quant_5p_5N( const short pos[], const short N ); +static long quant_6p_6N_2( const short pos[], const short N ); +static int pre_process( const float v[], short pos_vector[], int pos_vector_num[], int *pulse_pos_num); +static int fcb_encode_position( short pos_vector[], int n, int pos_num, int flag ); +static int fcb_encode_class( int *buffer, int pulse_num, int pos_num ); +static int fcb_encode_PI( const float v[], int pulse_num ); + +/*---------------------------------------------------------------------* + * ACELP_4t64() + * + * 20, 36, 44, 52, 64, 72, 88 bits algebraic codebook. + * 4 tracks x 16 positions per track = 64 samples. + * + * 20 bits --> 4 pulses in a frame of 64 samples. + * 36 bits --> 8 pulses in a frame of 64 samples. + * 44 bits 13 + 9 + 13 + 9 --> 10 pulses in a frame of 64 samples. + * 52 bits 13 + 13 + 13 + 13 --> 12 pulses in a frame of 64 samples. + * 64 bits 2 + 2 + 2 + 2 + 14 + 14 + 14 + 14 --> + * 16 pulses in a frame of 64 samples. + * 72 bits 10 + 2 + 10 + 2 + 10 + 14 + 10 + 14 --> + * 18 pulses in a frame of 64 samples. + * 88 bits 11 + 11 + 11 + 11 + 11 + 11 + 11 + 11 --> + * 24 pulses in a frame of 64 samples. + * All pulses can have two (2) possible amplitudes: +1 or -1. + * Each pulse can have sixteen (16) possible positions. + *---------------------------------------------------------------------*/ + +short acelp_4t64( + Encoder_State *st, /* i/o: encoder state structure */ + float dn[], /* i : corr. between target and h[]. */ + const float cn[], /* i : residual after long term prediction */ + const float H[], /* i : impulse response of weighted synthesis filter */ + float R[], /* i : autocorrelation values */ + const short acelpautoc, /* i : autocorrealtion flag */ + float code[], /* o : algebraic (fixed) codebook excitation */ + float y[], /* o : filtered fixed codebook excitation */ + short nbbits, /* i : number of bits per codebook */ + const short cmpl_flag, /* i : coomplexity reduction flag */ + const short Opt_AMR_WB /* i : flag indicating AMR-WB IO mode */ +) +{ + short i, k, index, track; + long L_index; + + short ind[NPMAXPT*NB_TRACK_FCB_4T+32]; + short saved_bits = 0; + PulseConfig config; + int indexing_indices[6], wordcnt, bitcnt; + + + /*-----------------------------------------------------------------* + * Configuration + *-----------------------------------------------------------------*/ + + + switch (nbbits) + { + case 20: /* EVS/AMR-WB pulse indexing: 20 bits, 4 pulses, 4 tracks */ + config.nbiter = 4; /* 4x12x16=768 loop */ + config.alp = 2.0f; + config.nb_pulse = 4; + config.fixedpulses = 0; + config.nbpos[0] = 4; + config.nbpos[1] = 8; + break; + + case 28: /* EVS pulse indexing: 28 bits, 6 pulses, 4 tracks */ + config.nbiter = 4; /* 4x20x16=1280 loops */ + config.alp = 1.0f; /* coeff for sign setting */ + config.nb_pulse = 6; + config.fixedpulses = 0; + config.nbpos[0] = 6; + config.nbpos[1] = 6; + config.nbpos[2] = 8; + break; + + case 36: /* EVS/AMR-WB pulse indexing: 36 bits, 8 pulses, 4 tracks */ + config.nbiter = 4; /* 4x20x16=1280 loops */ + config.alp = 1.0f; /* coeff for sign setting */ + config.nb_pulse = 8; + config.fixedpulses = 2; + config.nbpos[0] = 4; + config.nbpos[1] = 8; + config.nbpos[2] = 8; + break; + + case 43: /* EVS pulse indexing: 43 bits, 10 pulses, 4 tracks */ + case 44: /* AMR-WB pulse indexing: 44 bits, 10 pulses, 4 tracks */ + config.nbiter = 4; /* 4x26x16=1664 loops */ + config.alp = 1.0f; + config.nb_pulse = 10; + config.fixedpulses = 2; + config.nbpos[0] = 4; + config.nbpos[1] = 6; + config.nbpos[2] = 8; + config.nbpos[3] = 8; + break; + + case 50: /* EVS pulse indexing: 50 bits, 12 pulses, 4 tracks */ + case 52: /* AMR-WB pulse indexing: 52 bits, 12 pulses, 4 tracks */ + config.nbiter = 4; /* 4x26x16=1664 loops */ + config.alp = 1.0f; + config.nb_pulse = 12; + config.fixedpulses = 4; + config.nbpos[0] = 4; + config.nbpos[1] = 6; + config.nbpos[2] = 8; + config.nbpos[3] = 8; + break; + + case 62: /* EVS pulse indexing: 62 bits, 16 pulses, 4 tracks */ + case 64: /* AMR-WB pulse indexing: 64 bits, 16 pulses, 4 tracks */ + config.nbiter = 3; /* 3x36x16=1728 loops */ + config.alp = 0.8F; + config.nb_pulse = 16; + config.fixedpulses = 4; + config.nbpos[0] = 4; + config.nbpos[1] = 4; + config.nbpos[2] = 6; + config.nbpos[3] = 6; + config.nbpos[4] = 8; + config.nbpos[5] = 8; + break; + + case 72: /* AMR-WB pulse indexing: 72 bits, 18 pulses, 4 tracks */ + config.nbiter = 3; /* 3x35x16=1680 loops */ + config.alp = 0.75F; + config.nb_pulse = 18; + config.fixedpulses = 4; + config.nbpos[0] = 2; + config.nbpos[1] = 3; + config.nbpos[2] = 4; + config.nbpos[3] = 5; + config.nbpos[4] = 6; + config.nbpos[5] = 7; + config.nbpos[6] = 8; + break; + + case 88: /* AMR-WB pulse indexing: 88 bits, 24 pulses, 4 tracks */ + config.nbiter = 2; /* 2x53x16=1696 loop */ + config.alp = 0.5f; + config.nb_pulse = 24; + config.fixedpulses = 4; + config.nbpos[0] = 2; + config.nbpos[1] = 2; + config.nbpos[2] = 3; + config.nbpos[3] = 4; + config.nbpos[4] = 5; + config.nbpos[5] = 6; + config.nbpos[6] = 7; + config.nbpos[7] = 8; + config.nbpos[8] = 8; + config.nbpos[9] = 8; + break; + + case 87: /* EVS pulse indexing: 87 bits, 26 pulses, 4 tracks */ + config.nbiter = 1; + config.alp = 0.5F; + config.nb_pulse = 26; + config.fixedpulses = 4; + config.nbpos[0] = 4; + config.nbpos[1] = 6; + config.nbpos[2] = 6; + config.nbpos[3] = 8; + config.nbpos[4] = 8; + config.nbpos[5] = 8; + config.nbpos[6] = 8; + config.nbpos[7] = 8; + config.nbpos[8] = 8; + config.nbpos[9] = 8; + config.nbpos[10] = 8; + break; + } + + /* reduce the number of iterations as a compromise between the performance and complexity */ + if( cmpl_flag > 0 ) + { + config.nbiter = cmpl_flag; + } + + config.codetrackpos = TRACKPOS_FIXED_FIRST; + config.bits = nbbits; + + /*-----------------------------------------------------------------* + * Search + *-----------------------------------------------------------------*/ + + if( acelpautoc ) + { + E_ACELP_4tsearchx( dn, cn, R, code, &config, ind ); + + /* Generate weighted code */ + set_f( y, 0.0f, L_SUBFR ); + for( i=0; i> 4; + bitcnt = nbbits & 15; + for ( i = 0; i < wordcnt; i++ ) + { + push_indice( st, IND_ALG_CDBK_4T64, indexing_indices[i], 16 ); + } + if ( bitcnt ) + { + push_indice( st, IND_ALG_CDBK_4T64, indexing_indices[i], bitcnt ); + } + + } + else + { + /* AMR-WB pulse indexing */ + + if (nbbits == 20) + { + for (track = 0; track < NB_TRACK_FCB_4T; track++) + { + k = track * NPMAXPT; + index = quant_1p_N1(ind[k], 4); + push_indice( st, IND_ALG_CDBK_4T64, index, 5 ); + } + } + else if (nbbits == 36) + { + for (track = 0; track < NB_TRACK_FCB_4T; track++) + { + k = track * NPMAXPT; + index = quant_2p_2N1(ind[k], ind[k+1], 4); + push_indice( st, IND_ALG_CDBK_4T64, index, 9 ); + } + } + else if (nbbits == 44) + { + for (track = 0; track < (NB_TRACK_FCB_4T - 2); track++) + { + k = track * NPMAXPT; + index = quant_3p_3N1(ind[k], ind[k+1], ind[k+2], 4); + push_indice( st, IND_ALG_CDBK_4T64, index, 13 ); + } + + for (track = 2; track < NB_TRACK_FCB_4T; track++) + { + k = track * NPMAXPT; + index = quant_2p_2N1(ind[k], ind[k+1], 4); + push_indice( st, IND_ALG_CDBK_4T64, index, 9 ); + } + } + else if (nbbits == 52) + { + for (track = 0; track < NB_TRACK_FCB_4T; track++) + { + k = track*NPMAXPT; + index = quant_3p_3N1(ind[k], ind[k+1], ind[k+2], 4); + push_indice( st, IND_ALG_CDBK_4T64, index, 13 ); + } + } + else if (nbbits == 64) + { + for (track = 0; track < NB_TRACK_FCB_4T; track++) + { + k = track * NPMAXPT; + L_index = quant_4p_4N(&ind[k], 4); + index = ((L_index >> 14) & 3); + push_indice( st, IND_ALG_CDBK_4T64_1, index, 2 ); + } + + for (track = 0; track < NB_TRACK_FCB_4T; track++) + { + k = track * NPMAXPT; + L_index = quant_4p_4N(&ind[k], 4); + index = (L_index & 0x3FFF); + push_indice( st, IND_ALG_CDBK_4T64_2, index, 14 ); + } + } + else if (nbbits == 72) + { + for (track=0; track< (NB_TRACK_FCB_4T - 2); track++) + { + k = track * NPMAXPT; + L_index = quant_5p_5N(&ind[k], 4); + index = ((L_index >> 10) & 0x03FF); + push_indice( st, IND_ALG_CDBK_4T64_1, index, 10 ); + } + + for (track = 2; track < NB_TRACK_FCB_4T; track++) + { + k = track * NPMAXPT; + L_index = quant_4p_4N(&ind[k], 4); + index = ((L_index >> 14) & 3); + push_indice( st, IND_ALG_CDBK_4T64_1, index, 2 ); + } + + for (track=0; track< (NB_TRACK_FCB_4T - 2); track++) + { + k = track * NPMAXPT; + L_index = quant_5p_5N(&ind[k], 4); + index = (L_index & 0x03FF); + push_indice( st, IND_ALG_CDBK_4T64_2, index, 10 ); + } + + for (track = 2; track < NB_TRACK_FCB_4T; track++) + { + k = track * NPMAXPT; + L_index = quant_4p_4N(&ind[k], 4); + index = (L_index & 0x3FFF); + push_indice( st, IND_ALG_CDBK_4T64_2, index, 14 ); + } + } + else if (nbbits == 88) + { + for (track = 0; track < NB_TRACK_FCB_4T; track++) + { + k = track * NPMAXPT; + L_index = quant_6p_6N_2(&ind[k], 4); + index = ((L_index >> 11) & 0x07FF); + push_indice( st, IND_ALG_CDBK_4T64_1, index, 11 ); + } + + for (track = 0; track < NB_TRACK_FCB_4T; track++) + { + k = track * NPMAXPT; + L_index = quant_6p_6N_2(&ind[k], 4); + index = (L_index & 0x07FF); + push_indice( st, IND_ALG_CDBK_4T64_2, index, 11 ); + } + } + } + + return saved_bits; +} + + +/*---------------------------------------------------------------------* + * Quantization of 1 pulse with N+1 bits: * + *---------------------------------------------------------------------*/ +static short quant_1p_N1( /* o: return N+1 bits */ + const short pos, /* i: position of the pulse */ + const short N /* i: number of bits for position */ +) +{ + short mask, index; + + mask = ((1<>2; + pos_vector_num[j] = fabs(v[k]); + if (v[k]>0) + sign = sign << 1; + else + sign = ( sign << 1 ) + 1; + j++; + } + } + *pulse_pos_num = j; + + return sign; +} + +/*---------------------------------------------------------------------* + *encode the position * + *---------------------------------------------------------------------*/ + +static int fcb_encode_position( /* o: return index of the positions which have pulse*/ + short pos_vector[], /* i: position of the pulse on a track */ + int n, + int pos_num, /* i: the number of position which have pulse */ + int flag +) +{ + int i; + int mmm1; + int temp2; + mmm1 = PI_select_table[n][pos_num] - 1; + temp2 = pos_num; + + if (flag) /* no decrease */ + { + for (i=0; i>2; + if (code[k]<0) + { + tmp += 16; + } + if (fabs(code[k])>1) + { + ind[j] = tmp; + ind[j+1] = tmp; + break; + } + else + { + ind[j] = tmp; + j++; + } + } + } + k = track * NPMAXPT; + ps[track] = quant_2p_2N1(ind[k], ind[k+1], 4); + p[track] = 2; + } + joint_index = ps[0]*5472 + ps[1]; + if (joint_index >= joint_offset) + { + joint_index += joint_offset; + } + else + { + saved_bits += 1; + } + + idxs[0] = ( ( ps[2] << 9 ) + ps[3] ) & 0xffff; + idxs[1] = ( ( joint_index << 2 ) + ( ps[2] >> 7 ) ) & 0xffff; + idxs[2] = joint_index >> 14; + + return saved_bits; +} + diff --git a/src/libs/libevs/lib_enc/cod4t64_fx.cpp b/src/libs/libevs/lib_enc/cod4t64_fx.cpp deleted file mode 100755 index 38f1dfab..00000000 --- a/src/libs/libevs/lib_enc/cod4t64_fx.cpp +++ /dev/null @@ -1,1167 +0,0 @@ -/*==================================================================================== - EVS Codec 3GPP TS26.442 Apr 03, 2018. Version 12.11.0 / 13.6.0 / 14.2.0 - ====================================================================================*/ - -#include "options.h" /* VMR-WB compilation switches */ -#include "cnst_fx.h" /* Common constants */ -#include "rom_enc_fx.h" /* Encoder static table prototypes */ -#include "prot_fx.h" /* Function prototypes */ -#include "rom_com_fx.h" /* Static table prototypes */ -#include "stl.h" - - -/*-------------------------------------------------------------------* - * Local constants - *-------------------------------------------------------------------*/ - -#define STEP 4 -#define MSIZE 256 -#define NB_MAX 8 - -/*-------------------------------------------------------------------* - * Local function prototypes - *-------------------------------------------------------------------*/ -static Word16 quant_1p_N1_fx(const Word16 pos,const Word16 N); -static Word16 quant_2p_2N1_fx(const Word16 pos1, const Word16 pos2, const Word16 N); -static Word16 quant_3p_3N1_fx( const Word16 pos1, const Word16 pos2, const Word16 pos3, const Word16 N ); -static Word32 quant_4p_4N_fx( const Word16 pos[], const Word16 N ); -static Word32 quant_5p_5N_fx( const Word16 pos[], const Word16 N ); -static Word32 quant_6p_6N_2_fx( const Word16 pos[], const Word16 N ); - - - -static Word32 fcb_encode_position_fx(Word16 pos_vector[],Word32 n,Word32 pos_num,Word32 flag); -static Word32 fcb_encode_class_fx(Word32 sector_6p_num[],Word32 pulse_num,Word32 pulse_pos_num); -static Word32 fcb_encode_PI_fx(const Word16 v[], Word32 pulse_num); -static Word32 pre_process_fx( const Word16 v[], Word16 sector_6p[], Word32 sector_6p_num[], Word32 *pulse_pos_num ); - -/*---------------------------------------------------------------------* - * ACELP_4t64() - * - * 20, 36, 44, 52, 64, 72, 88 bits algebraic codebook. - * 4 tracks x 16 positions per track = 64 samples. - * - * 20 bits --> 4 pulses in a frame of 64 samples. - * 36 bits --> 8 pulses in a frame of 64 samples. - * 44 bits 13 + 9 + 13 + 9 --> 10 pulses in a frame of 64 samples. - * 52 bits 13 + 13 + 13 + 13 --> 12 pulses in a frame of 64 samples. - * 64 bits 2 + 2 + 2 + 2 + 14 + 14 + 14 + 14 --> - * 16 pulses in a frame of 64 samples. - * 72 bits 10 + 2 + 10 + 2 + 10 + 14 + 10 + 14 --> - * 18 pulses in a frame of 64 samples. - * 88 bits 11 + 11 + 11 + 11 + 11 + 11 + 11 + 11 --> - * 24 pulses in a frame of 64 samples. - * All pulses can have two (2) possible amplitudes: +1 or -1. - * Each pulse can have sixteen (16) possible positions. - *---------------------------------------------------------------------*/ - -Word16 acelp_4t64_fx( - Encoder_State_fx *st_fx, /* i/o: encoder state structure */ - Word16 dn[], /* i : corr. between target and h[]. */ - const Word16 cn[], /* i : residual after long term prediction Q_new*/ - const Word16 H[], /* i : impulse response of weighted synthesis filter Q12*/ - Word16 R[], /* i : autocorrelation values */ - const Word16 acelpautoc, /* i : autocorrealtion flag */ - Word16 code[], /* o : algebraic (fixed) codebook excitation Q9*/ - Word16 y[], /* o : filtered fixed codebook excitation Q9*/ - Word16 nbbits, /* i : number of bits per codebook */ - const Word16 cmpl_flag, /* i : complexity reduction flag */ - const Word16 Opt_AMR_WB /* i : flag indicating AMR-WB IO mode */ -) -{ - - Word16 i, k, index, track; - Word32 L_index; - Word16 ind[NPMAXPT*NB_TRACK_FCB_4T+32]; /* VE3: why +32 ???*/ - Word16 codvec[NB_PULSE_MAX+4]= {0}; - Word16 saved_bits = 0; - - PulseConfig config; - Word16 indexing_indices[6], wordcnt, bitcnt; - - set16_fx(codvec, 0, NB_PULSE_MAX+4); - SWITCH (nbbits) - { - - case 20: /* EVS/AMR-WB pulse indexing: 20 bits, 4 pulses, 4 tracks */ - config.nbiter = 4; - move16(); /* 4x12x16=768 loop */ - config.alp = 16384; - move16(); /* 2 in Q13*/ - config.nb_pulse = 4; - move16(); - config.fixedpulses = 0; - move16(); - config.nbpos[0] = 4; - move16(); - config.nbpos[1] = 8; - move16(); - BREAK; - - case 28: /* EVS pulse indexing: 28 bits, 6 pulses, 4 tracks */ - config.nbiter = 4; - move16(); /* 4x20x16=1280 loops */ - config.alp = 8192; - move16(); /* coeff FOR sign setting */ - config.nb_pulse = 6; - move16(); - config.fixedpulses = 0; - move16(); - config.nbpos[0] = 6; - move16(); - config.nbpos[1] = 6; - move16(); - config.nbpos[2] = 8; - move16(); - BREAK; - - case 36: /* EVS/AMR-WB pulse indexing: 36 bits, 8 pulses, 4 tracks */ - config.nbiter = 4; - move16(); /* 4x20x16=1280 loops */ - config.alp = 8192; - move16(); /* coeff FOR sign setting */ - config.nb_pulse = 8; - move16(); - config.fixedpulses = 2; - move16(); - config.nbpos[0] = 4; - move16(); - config.nbpos[1] = 8; - move16(); - config.nbpos[2] = 8; - move16(); - BREAK; - - case 43: /* EVS pulse indexing: 43 bits, 10 pulses, 4 tracks */ - case 44: /* AMR-WB pulse indexing: 44 bits, 10 pulses, 4 tracks */ - config.nbiter = 4; - move16(); /* 4x26x16=1664 loops */ - config.alp = 8192; - move16(); - config.nb_pulse = 10; - move16(); - config.fixedpulses = 2; - move16(); - config.nbpos[0] = 4; - move16(); - config.nbpos[1] = 6; - move16(); - config.nbpos[2] = 8; - move16(); - config.nbpos[3] = 8; - move16(); - BREAK; - - case 50: /* EVS pulse indexing: 50 bits, 12 pulses, 4 tracks */ - case 52: /* AMR-WB pulse indexing: 52 bits, 12 pulses, 4 tracks */ - config.nbiter = 4; - move16(); /* 4x26x16=1664 loops */ - config.alp = 8192; - move16(); - config.nb_pulse = 12; - move16(); - config.fixedpulses = 4; - move16(); - config.nbpos[0] = 4; - move16(); - config.nbpos[1] = 6; - move16(); - config.nbpos[2] = 8; - move16(); - config.nbpos[3] = 8; - move16(); - BREAK; - - case 62: /* EVS pulse indexing: 62 bits, 16 pulses, 4 tracks */ - case 64: /* AMR-WB pulse indexing: 64 bits, 16 pulses, 4 tracks */ - config.nbiter = 3; - move16(); /* 3x36x16=1728 loops */ - config.alp = 6554; - move16(); - config.nb_pulse = 16; - move16(); - config.fixedpulses = 4; - move16(); - config.nbpos[0] = 4; - move16(); - config.nbpos[1] = 4; - move16(); - config.nbpos[2] = 6; - move16(); - config.nbpos[3] = 6; - move16(); - config.nbpos[4] = 8; - move16(); - config.nbpos[5] = 8; - move16(); - BREAK; - - case 72: /* AMR-WB pulse indexing: 72 bits, 18 pulses, 4 tracks */ - config.nbiter = 3; - move16(); /* 3x35x16=1680 loops */ - config.alp = 6144; - move16(); - config.nb_pulse = 18; - move16(); - config.fixedpulses = 4; - move16(); - config.nbpos[0] = 2; - move16(); - config.nbpos[1] = 3; - move16(); - config.nbpos[2] = 4; - move16(); - config.nbpos[3] = 5; - move16(); - config.nbpos[4] = 6; - move16(); - config.nbpos[5] = 7; - move16(); - config.nbpos[6] = 8; - move16(); - BREAK; - - case 88: /* AMR-WB pulse indexing: 88 bits, 24 pulses, 4 tracks */ - config.nbiter = 2; - move16(); /* 2x53x16=1696 loop */ - config.alp = 4096; - move16(); - config.nb_pulse = 24; - move16(); - config.fixedpulses = 4; - move16(); - config.nbpos[0] = 2; - move16(); - config.nbpos[1] = 2; - move16(); - config.nbpos[2] = 3; - move16(); - config.nbpos[3] = 4; - move16(); - config.nbpos[4] = 5; - move16(); - config.nbpos[5] = 6; - move16(); - config.nbpos[6] = 7; - move16(); - config.nbpos[7] = 8; - move16(); - config.nbpos[8] = 8; - move16(); - config.nbpos[9] = 8; - move16(); - BREAK; - - case 87: /* EVS pulse indexing: 87 bits, 26 pulses, 4 tracks */ - config.nbiter = 1; - move16(); - config.alp = 4096; - move16(); - config.nb_pulse = 26; - move16(); - config.fixedpulses = 4; - move16(); - config.nbpos[0] = 4; - move16(); - config.nbpos[1] = 6; - move16(); - config.nbpos[2] = 6; - move16(); - config.nbpos[3] = 8; - move16(); - config.nbpos[4] = 8; - move16(); - config.nbpos[5] = 8; - move16(); - config.nbpos[6] = 8; - move16(); - config.nbpos[7] = 8; - move16(); - config.nbpos[8] = 8; - move16(); - config.nbpos[9] = 8; - move16(); - config.nbpos[10] = 8; - move16(); - BREAK; - } - - /* reduce the number of iterations as a compromise between the performance and complexity */ - if( cmpl_flag > 0 ) - { - config.nbiter = cmpl_flag; - move16(); - } - - config.codetrackpos = TRACKPOS_FIXED_FIRST; - move16(); - config.bits = nbbits; - move16(); - - IF (acelpautoc) - { - E_ACELP_4tsearchx( dn, cn, R, code, &config, ind ); - - /* Generate weighted code */ - E_ACELP_weighted_code(code, H, 12, y); - } - ELSE - { - E_ACELP_4tsearch(dn, cn, H, code, &config, ind, y); - - FOR(i=0; i it doesn't need to be operated by Basic Operators */ - - n_1 = (Word16) (N - 1); - move16(); - nb_pos = shl(1, n_1); /* nb_pos = (1< 1, Q0 */ - IF (v[k]>0) - { - sign = L_shl(sign, 1); - } - ELSE - { - sign = L_add(L_shl( sign, 1), 1); - } - j =add(j, 1); - } - } - *pulse_pos_num = L_deposit_l(j); - - return sign; -} - - -/*--------------------------------------------------------------------------* -* E_ACELP_code43bit -* -* Fixed bit-length arithmetic coding of pulses -* v - (input) pulse vector -* s - (output) encoded state -* n - (output) range of possible states (0...n-1) -* p - (output) number of pulses found -* len - (input) length of pulse vector -* trackstep - (input) step between tracks -*--------------------------------------------------------------------------*/ - -Word16 E_ACELP_code43bit(const Word16 code[], UWord32 *ps, Word16 *p, UWord16 idxs[]) -{ - Word16 i,j,k,track; - Word16 ind[32]; - - Word16 tmp; - Word32 L_tmp; - Word32 joint_index; - static const Word32 joint_offset = 3611648; /*offset for 3 pulses per track*/ - Word16 saved_bits = 0; - - FOR (track = 0; track < 2; track++) - { - ps[track] = fcb_encode_PI_fx(code+track, 3); - move32(); - p[track] = 3; - move16(); - } - - FOR (track = 2; track < NB_TRACK_FCB_4T; track++) - { - i = j = i_mult2(track, NPMAXPT); - move16(); - FOR (k = track; k < 64; k += 4) - { - IF (code[k]) - { - tmp = shr(k, 2); - if (code[k] < 0) - { - tmp = add(tmp, 16); - } - ind[j] = tmp; - move16(); - IF (sub(abs_s(code[k]), 512) > 0) - { - ind[j + 1] = tmp; - move16(); - BREAK; - } - j = add(j, 1); - } - } - ps[track] = quant_2p_2N1_fx(ind[i], ind[i+1], 4); - move32(); - p[track] = 2; - move16(); - } - /* joint_index = ps[0]*5472 + ps[1]; */ - L_tmp = L_shl(ps[0], 12); - L_tmp = L_add(L_tmp, L_shl(ps[0], 10)); - L_tmp = L_add(L_tmp, L_shl(ps[0], 8)); - L_tmp = L_add(L_tmp, L_shl(ps[0], 6)); - L_tmp = L_add(L_tmp, L_shl(ps[0], 5)); - joint_index = L_add(L_tmp, ps[1]); - L_tmp = L_sub(joint_index, joint_offset); - if (L_tmp >= 0) - { - joint_index = L_add(joint_index, joint_offset); - } - if (L_tmp < 0) - { - saved_bits = add(saved_bits, 1); - } - idxs[0] = extract_l(L_add(L_shl(ps[2], 9), ps[3])); - idxs[1] = extract_l(L_add(L_shl(joint_index, 2), L_shr(ps[2], 7))); - idxs[2] = extract_l(L_shr(joint_index, 14)); - - return saved_bits; -} diff --git a/src/libs/libevs/lib_enc/cod_ace.cpp b/src/libs/libevs/lib_enc/cod_ace.cpp old mode 100755 new mode 100644 index b8ec4c94..a1e7f13b --- a/src/libs/libevs/lib_enc/cod_ace.cpp +++ b/src/libs/libevs/lib_enc/cod_ace.cpp @@ -1,16 +1,14 @@ /*==================================================================================== - EVS Codec 3GPP TS26.442 Apr 03, 2018. Version 12.11.0 / 13.6.0 / 14.2.0 + EVS Codec 3GPP TS26.443 Nov 13, 2018. Version 12.11.0 / 13.7.0 / 14.3.0 / 15.1.0 ====================================================================================*/ #include #include +#include #include -#include "prot_fx.h" -#include "basop_util.h" +#include "prot.h" #include "options.h" -#include "stl.h" - -#include "rom_basop_util.h" +#include "rom_com.h" /*-------------------------------------------------------------------* * coder_acelp() @@ -18,162 +16,128 @@ * Encode ACELP frame *-------------------------------------------------------------------*/ -Word16 coder_acelp( /* output SEGSNR for CL decision */ - ACELP_config *acelp_cfg, /*input/output: configuration of the ACELP coding*/ - const Word16 coder_type, /* input: coding type */ - const Word16 A[], /* input: coefficients 4xAz[M+1] */ - const Word16 Aq[], /* input: coefficients 4xAz_q[M+1] */ - Word16 speech[], /* input: speech[-M..lg] */ - Word16 synth[], - LPD_state *LPDmem, - const Word16 voicing[], /* input: open-loop LTP gain */ - const Word16 T_op[], /* input: open-loop LTP lag */ - Word16 *prm, /* output: acelp parameters */ - Word16 stab_fac, - Encoder_State_fx *st, +void coder_acelp( + ACELP_config *acelp_cfg, /* i/o: configuration of the ACELP */ + const short coder_type, /* i : coding type */ + const float A[], /* i : coefficients 4xAz[M+1] */ + const float Aq[], /* i : coefficients 4xAz_q[M+1] */ + const float speech[], /* i : speech[-M..lg] */ + float synth[], /* o : synthesis */ + LPD_state *LPDmem, /* i/o: ACELP memories */ + const float voicing[], /* input: open-loop LTP gain */ + const short T_op[], /* input: open-loop LTP lag */ + int *prm, /* output: acelp parameters */ + const float stab_fac, + Encoder_State *st, /* i/o : coder memory state */ HANDLE_PLC_ENC_EVS hPlc_Ext, - Word16 target_bits, /* i/o : coder memory state */ - Word16 Q_new, - Word16 shift - ,Word16 *pitch_buf /* output : pitch values for each subfr.*/ - ,Word16 *voice_factors /* output : voicing factors */ - ,Word16 *bwe_exc /* output : excitation for SWB TBE */ + const short target_bits, + float *gain_pitch_buf,/* o : gain pitch values */ + float *gain_code_buf, /* o : gain code values */ + float *pitch_buf, /* o : pitch values for each subfr.*/ + float *voice_factors, /* o : voicing factors */ + float *bwe_exc /* o : excitation for SWB TBE */ ) { - Word16 i, j, i_subfr, j_subfr; - Word16 T0, T0_min, T0_min_frac, T0_max, T0_max_frac, T0_res; - Word16 T0_frac; - Word16 tmp, tmp2, Es_pred; - Word16 gain_pit, voice_fac; - Word32 gain_code, Ltmp, Ltmp2; + short i, i_subfr; + int T0, T0_min, T0_min_frac, T0_max, T0_max_frac, T0_res, T0_frac; + float tmp, Es_pred; + float gain_pit, gain_code, voice_fac; ACELP_CbkCorr g_corr; - const Word16 *p_A, *p_Aq; - Word16 h1[L_SUBFR]; /* weighted impulse response of LP */ - Word16 code[L_SUBFR]; - Word16 xn_exp; - Word16 Q_xn; - Word16 Q_new_p5; - Word16 cn[L_SUBFR]; - Word16 xn[L_SUBFR]; - Word16 y1[L_SUBFR]; /* Filtered adaptive excitation */ - Word16 y2[L_SUBFR]; /* Filtered adaptive excitation */ - Word16 res_save; - Word16 exc_buf[L_EXC_MEM+L_DIV_MAX+1], *exc; - Word16 exc2[L_SUBFR]; - Word16 *syn,syn_buf[M+L_DIV_MAX+L_DIV_MAX/2]; /*128 for the memory, L_DIV for the current synth and 128 for the ZIR for next TCX*/ - Word16 syn2[L_DIV_MAX]; - Word16 gain_inov; - Word32 past_gcode; - Word16 L_frame; - Word16 clip_gain; - Word32 gain_code2; - Word16 code2[L_SUBFR]; - Word16 y22[L_SUBFR]; /* Filtered adaptive excitation */ - Word32 gain_code_vect[2]; - Word16 error = 0; - Word16 gain_preQ = 0; /* Gain of prequantizer excitation */ - Word16 code_preQ[L_SUBFR]; /* Prequantizer excitation */ - - Word16 dummy = 0; - set16_fx(code_preQ, 0, L_SUBFR); - - - T0 = 0; /* to avoid compilation warnings */ - T0_frac = 0; /* to avoid compilation warnings */ - T0_res = 0; /* to avoid compilation warnings */ - gain_pit = 0; /* to avoid compilation warnings */ - + float g_corr2[6]; + const float *p_A, *p_Aq; + float h1[L_SUBFR]; /* weighted impulse response of LP */ + float code[L_SUBFR]; + float cn[L_SUBFR]; + float xn[L_SUBFR]; + float xn2[L_SUBFR]; + float y1[L_SUBFR]; /* Filtered adaptive excitation */ + float y2[L_SUBFR]; /* Filtered adaptive excitation */ + float res_save; + float exc_buf[L_EXC_MEM+L_FRAME16k+1], *exc; + float exc2[L_SUBFR]; + float *syn,syn_buf[M+L_FRAME16k+L_FRAME16k/2]; /*128 for the memory, L_FRAME for the current synth and 128 for the ZIR for next TCX*/ + float syn2[L_FRAME16k]; + float norm_gain_code, gain_inov; + short clip_gain; + float gain_code2; + float code2[L_SUBFR]; + float y22[L_SUBFR]; /* Filtered adaptive excitation */ + float lp_select; + float *pt_pitch, *pt_gain_pitch, *pt_gain_code; + int offset; + float error; + float gain_preQ; /* Gain of prequantizer excitation */ + float code_preQ[L_SUBFR]; /* Prequantizer excitation */ /* Configure ACELP */ - LPDmem->nbits = BITS_ALLOC_config_acelp( target_bits, coder_type, &(st->acelp_cfg), st->narrowBand, st->nb_subfr ); - - /* Init Framing parameters */ - move16(); - move16(); - move16(); - L_frame = st->L_frame_fx; - - - /*------------------------------------------------------------------------* - * Previous frame is TCX (for non-EVS modes)(deactivated permanently) * - *------------------------------------------------------------------------*/ + BITS_ALLOC_config_acelp( target_bits, coder_type, &(st->acelp_cfg), st->narrowBand, st->nb_subfr ); /*------------------------------------------------------------------------* * Initialize buffers * *------------------------------------------------------------------------*/ - /* Rescale ACELP memories, which were not scaled yet*/ - xn_exp = sub(sub(15+1, Q_new),shift); - Q_xn = add(sub(Q_new,1),shift); - Q_new_p5 = add(Q_new, 5); + set_f( code_preQ, 0.f, L_SUBFR ); + gain_preQ = 0.0f; /* Reset phase dispersion */ - IF (st->last_core_fx > ACELP_CORE) + if( st->last_core > ACELP_CORE ) { - move16(); - move16(); - move16(); - st->dm_fx.prev_gain_code = 0; - set16_fx(st->dm_fx.prev_gain_pit, 0, 6); - st->dm_fx.prev_state = 0; + set_zero( st->dispMem, 8 ); } /* set excitation memory*/ - move16(); - move16(); - exc = exc_buf+L_EXC_MEM; - Copy(LPDmem->old_exc, exc_buf, L_EXC_MEM); - *(exc+st->L_frame_fx) = 0; + exc = exc_buf + L_EXC_MEM; + mvr2r( LPDmem->old_exc, exc_buf, L_EXC_MEM ); + *(exc+st->L_frame) = 0.f; /*to solve a warning*/ /* Init syn buffer */ - move16(); syn = syn_buf + M; - Copy(LPDmem->mem_syn, syn_buf, M); + mvr2r( LPDmem->mem_syn, syn_buf, M ); + pt_pitch = pitch_buf; + pt_gain_pitch = gain_pitch_buf; + pt_gain_code = gain_code_buf; - /* calculate residual */ - move16(); - p_Aq = Aq; - FOR (i_subfr=0; i_subfrL_frame ); - } /*------------------------------------------------------------------------* * Find and quantize mean_ener_code for gain quantizer * *------------------------------------------------------------------------*/ - IF (acelp_cfg->nrg_mode>0) + if( acelp_cfg->nrg_mode > 0 ) { - - Es_pred_enc_fx(&Es_pred, prm, L_frame, exc, voicing, acelp_cfg->nrg_bits, acelp_cfg->nrg_mode>1, Q_new - ); + Es_pred_enc( &Es_pred, prm, st->L_frame, L_SUBFR, exc, voicing, acelp_cfg->nrg_bits, acelp_cfg->nrg_mode>1 ); prm++; } - ELSE + else { - - Es_pred=0; + Es_pred = 0.f; } - IF (sub(st->L_frame_fx,L_FRAME) == 0) + if( st->L_frame == L_FRAME ) { - Copy(Aq+2*(M+1), st->cur_sub_Aq_fx, (M+1)); + mvr2r( Aq+2*(M+1), st->cur_sub_Aq, (M+1) ); } - ELSE + else { - Copy(Aq+3*(M+1), st->cur_sub_Aq_fx, (M+1)); + mvr2r( Aq+3*(M+1), st->cur_sub_Aq, (M+1) ); } - /*------------------------------------------------------------------------* * Loop for every subframe in the analysis frame * *------------------------------------------------------------------------* * To find the pitch and innovation parameters. The subframe size is * - * L_SUBFR and the loop is repeated L_FRAME_PLUS/L_SUBFR * - * times. * + * L_SUBFR and the loop is repeated L_FRAME_PLUS/L_SUBFR times. * * - compute impulse response of weighted synthesis filter (h1[]) * * - compute the target signal for pitch search * * - find the closed-loop pitch parameters * @@ -187,22 +151,15 @@ Word16 coder_acelp( /* output SEGSNR for CL decision */ * - find synthesis speech * * - update states of weighting filter * *------------------------------------------------------------------------*/ - move16(); - move16(); + p_A = A; p_Aq = Aq; - move16(); res_save = exc[0]; - j_subfr = 0; - move16(); - FOR (i_subfr=0; i_subfrL_frame; i_subfr += L_SUBFR ) { - /* Restore exc[i_subfr] and save next exc[L_SUBFR+i_subfr] */ - move16(); - move16(); exc[i_subfr] = res_save; res_save = exc[L_SUBFR+i_subfr]; @@ -210,35 +167,15 @@ Word16 coder_acelp( /* output SEGSNR for CL decision */ * Find target for pitch search (xn[]), target for innovation search (cn[]) * * and impulse response of the weighted synthesis filter (h1[]). * *--------------------------------------------------------------------------*/ - find_targets_fx( - speech, - &syn[i_subfr-M], - i_subfr, - &LPDmem->mem_w0, - p_Aq, - exc, - L_SUBFR, - p_A, - st->preemph_fac, - xn, - cn - ,h1 - ); - /*---------------------------------------------------------------* - * Compute impulse response, h1[], of weighted synthesis filter * - *---------------------------------------------------------------*/ - Scale_sig(h1, L_SUBFR, add(1,shift)); /* Q13+1-shift */ - - /* scaling of xn[] to limit dynamic at 12 bits */ - Scale_sig(xn, L_SUBFR, shift); + find_targets( speech, &syn[i_subfr-M], i_subfr, &LPDmem->mem_w0, p_Aq,exc, L_SUBFR, p_A, st->preemph_fac, xn, cn, h1 ); /*-----------------------------------------------------------------* * Gain clipping test to avoid unstable synthesis on frame erasure * or in case of floating point encoder & fixed p. decoder *-----------------------------------------------------------------*/ - clip_gain = Mode2_gp_clip( voicing, i_subfr, coder_type, xn, st->clip_var_fx, L_SUBFR, Q_xn ); + clip_gain = gp_clip( st->core_brate, voicing, i_subfr, coder_type, xn, st->clip_var ); /*-----------------------------------------------------------------* * - find unity gain pitch excitation (adaptive codebook entry) * @@ -247,146 +184,129 @@ Word16 coder_acelp( /* output SEGSNR for CL decision */ * - compute pitch gain1 * *-----------------------------------------------------------------*/ - IF ( acelp_cfg->ltp_bits!=0 ) + if ( acelp_cfg->ltp_bits != 0 ) { - /* Adaptive Codebook (GC and VC) */ + /* pitch lag coding */ + Mode2_pit_encode( acelp_cfg->ltp_mode, i_subfr, &prm, &exc[i_subfr], + T_op, &T0_min, &T0_min_frac, &T0_max, &T0_max_frac, &T0, &T0_frac, &T0_res, + h1, xn, st->pit_min, st->pit_fr1, st->pit_fr1b, st->pit_fr2, st->pit_max, st->pit_res_max ); - Mode2_pit_encode( acelp_cfg->ltp_mode, - i_subfr, - &prm, - &exc[i_subfr], - T_op, - &T0_min, - &T0_min_frac, - &T0_max, - &T0_max_frac, - &T0, - &T0_frac, - &T0_res, - h1, - xn, - st->pit_min, - st->pit_fr1, - st->pit_fr1b, - st->pit_fr2, - st->pit_max, - st->pit_res_max); - - E_ACELP_adaptive_codebook( exc, - T0, - T0_frac, - T0_res, - st->pit_res_max, - acelp_cfg->ltf_mode, - i_subfr, - L_SUBFR, - L_frame, - h1, - clip_gain, - xn, - y1, - &g_corr, - &prm, - &gain_pit, - xn_exp - ,0 - ,0 - ,&dummy - ); + /* find pitch excitation */ + if( st->pit_res_max == 6 ) + { + if ( T0_res == (st->pit_res_max>>1) ) + { + pred_lt4( &exc[i_subfr], &exc[i_subfr], T0, T0_frac<<1, L_SUBFR+1, inter6_2, PIT_L_INTERPOL6_2, PIT_UP_SAMP6); + } + else + { + pred_lt4( &exc[i_subfr], &exc[i_subfr], T0, T0_frac, L_SUBFR+1, inter6_2, PIT_L_INTERPOL6_2, PIT_UP_SAMP6); + } + } + else + { + if( T0_res == (st->pit_res_max>>1) ) + { + pred_lt4( &exc[i_subfr], &exc[i_subfr], T0, T0_frac<<1, L_SUBFR+1, inter4_2, L_INTERPOL2, PIT_UP_SAMP); + } + else + { + pred_lt4( &exc[i_subfr], &exc[i_subfr], T0, T0_frac, L_SUBFR+1, inter4_2, L_INTERPOL2, PIT_UP_SAMP); + } + } + /* filter adaptive codebook */ + lp_select = lp_filt_exc_enc( MODE2, st->core_brate, 0, coder_type, i_subfr, exc, h1, xn, y1, xn2, L_SUBFR, + st->L_frame, g_corr2, clip_gain, &(gain_pit), &(acelp_cfg->ltf_mode) ); + if( acelp_cfg->ltf_mode == NORMAL_OPERATION ) + { + *prm = lp_select; + prm++; + } + g_corr.y1y1 = g_corr2[0]; + g_corr.xy1 = -0.5f*(g_corr2[1]-0.01f)+0.01f; } - ELSE IF ( acelp_cfg->ltp_bits==0 ) + else { /* No adaptive codebook (UC) */ - gain_pit=0; - g_corr.xy1=0; - g_corr.xy1_e=0; - g_corr.y1y1=0; - g_corr.y1y1_e=0; - set16_fx(y1,0,L_SUBFR); - set16_fx(exc+i_subfr,0,L_SUBFR); + gain_pit=0.f; + g_corr.xy1=0.f; + g_corr.y1y1=0.f; + set_zero( y1, L_SUBFR ); + set_zero( exc+i_subfr, L_SUBFR ); T0 = L_SUBFR; T0_frac = 0; T0_res = 1; } - IF( st->igf != 0 ) + if( st->igf ) { - tbe_celp_exc(L_frame, i_subfr, T0, T0_frac, &error, bwe_exc); + if( st->sr_core == 12800 ) + { + offset = T0 * HIBND_ACB_L_FAC + (int) ((float) T0_frac * 0.25f * HIBND_ACB_L_FAC + 2 * HIBND_ACB_L_FAC + 0.5f) - 2 * HIBND_ACB_L_FAC; + for (i = 0; i < L_SUBFR * HIBND_ACB_L_FAC; i++) + { + bwe_exc[i + i_subfr * HIBND_ACB_L_FAC] = bwe_exc[i + i_subfr * HIBND_ACB_L_FAC - offset + (int) error]; + } + error += (float) offset - (float) T0 * HIBND_ACB_L_FAC - 0.25f * HIBND_ACB_L_FAC * (float) T0_frac; + } + else + { + offset = T0 * 2 + (int) ((float) T0_frac * 0.5f + 4 + 0.5f) - 4; + for (i=0; itilt_code, - acelp_cfg->fixed_cdk_index[j_subfr], + E_ACELP_innovative_codebook( exc, T0, T0_frac, T0_res, gain_pit, LPDmem->tilt_code, + acelp_cfg->fixed_cdk_index[i_subfr/L_SUBFR], + acelp_cfg->pre_emphasis, + acelp_cfg->pitch_sharpening, + acelp_cfg->phase_scrambling, acelp_cfg->formant_enh, acelp_cfg->formant_tilt, acelp_cfg->formant_enh_num, acelp_cfg->formant_enh_den, - acelp_cfg->pitch_sharpening, - acelp_cfg->pre_emphasis, - acelp_cfg->phase_scrambling, - i_subfr, - p_Aq, - h1, - xn, - cn, - y1, - y2, - st->acelp_autocorr, - &prm, - code, - shift - ,st->L_frame_fx, - st->last_L_frame_fx, - st->total_brate_fx + i_subfr, p_Aq, h1, xn, cn, y1, y2, + st->acelp_autocorr, &prm, code + ,st->L_frame, st->last_L_frame, st->total_brate ); - E_ACELP_xy2_corr(xn, y1, y2, &g_corr, L_SUBFR, Q_xn); - - g_corr.y2y2_e = sub(g_corr.y2y2_e, 18); /* -18 (y2*y2: Q9*Q9) */ - g_corr.xy2_e = sub(g_corr.xy2_e, add(Q_xn,9)); /* -(Q_xn+9) (xn: Q_xn y2: Q9) */ - g_corr.y1y2_e = sub(g_corr.y1y2_e, add(Q_xn,9)); /* -(Q_xn+9) (y1: Q_xn y2: Q9) */ - g_corr.xx_e = sub(g_corr.xx_e, add(Q_xn,Q_xn)); /* -(Q_xn+Q_xn) (xn: Q_xn) */ + E_corr_xy2( xn, y1, y2, g_corr2, L_SUBFR ); + g_corr.y2y2 = 0.01F + g_corr2[2]; + g_corr.xy2 = 0.01F + -0.5f*g_corr2[3]; + g_corr.y1y2 = 0.01F + 0.5f*g_corr2[4]; + g_corr.xx = 0.01F + dotp( xn, xn, L_SUBFR ); /*----------------------------------------------------------------------* * Add Gaussian excitation * *----------------------------------------------------------------------*/ - IF (sub(acelp_cfg->gains_mode[j_subfr], 7) == 0) + if(acelp_cfg->gains_mode[i_subfr/L_SUBFR]==7) { + gauss_L2( h1, code2, y2, y22, &gain_code2, g_corr2, gain_pit, + LPDmem->tilt_code, p_Aq, acelp_cfg->formant_enh_num, &(st->seed_acelp) ); - gauss_L2(h1, - code2, - y2, - y22, - &gain_code2, - &g_corr, - gain_pit, - LPDmem->tilt_code, - p_Aq, - acelp_cfg->formant_enh_num, - &(st->seed_acelp), - shift - ); + g_corr.y1y1 = g_corr2[0]; + g_corr.y1y2 = g_corr2[4]; } - ELSE + else { - gain_code2 = L_deposit_l(0); - set16_fx(code2, 0, L_SUBFR); - set16_fx(y22, 0, L_SUBFR); + gain_code2 = 0.f; + set_zero( code2, L_SUBFR ); + set_zero( y22, L_SUBFR ); } /*----------------------------------------------------------* @@ -394,213 +314,116 @@ Word16 coder_acelp( /* output SEGSNR for CL decision */ * - quantize fixed codebook gain * *----------------------------------------------------------*/ - encode_acelp_gains( code, - acelp_cfg->gains_mode[j_subfr], - Es_pred, - clip_gain, - &g_corr, - &gain_pit, - &gain_code, - &prm, - &past_gcode, - &gain_inov, - L_SUBFR, - code2, - &gain_code2, - st->flag_noisy_speech_snr - ); + encode_acelp_gains( code, acelp_cfg->gains_mode[i_subfr/L_SUBFR], Es_pred, clip_gain, &g_corr, &gain_pit, &gain_code, + &prm, &norm_gain_code, &gain_inov, L_SUBFR, code2, &gain_code2, st->flag_noisy_speech_snr ); - gp_clip_test_gain_pit_fx( st->core_brate_fx, gain_pit, st->clip_var_fx ); - - gain_code_vect[0] = gain_code; - move32(); - gain_code_vect[1] = gain_code; - move32(); + gp_clip_test_gain_pit( st->core_brate, gain_pit, st->clip_var); /*----------------------------------------------------------* - * - voice factor (for pitch enhancement) * + * - voice factor (for codebook tilt sharpening) * *----------------------------------------------------------*/ - E_UTIL_voice_factor( exc, - i_subfr, - code, - gain_pit, - gain_code, - &voice_fac, - &(LPDmem->tilt_code), - L_SUBFR, - acelp_cfg->voice_tilt, - Q_new, - shift - ); + + LPDmem->tilt_code = est_tilt( exc+i_subfr, gain_pit, code, gain_code, &voice_fac, L_SUBFR, acelp_cfg->voice_tilt ); st->rf_tilt_buf[i_subfr/L_SUBFR] = LPDmem->tilt_code; + /*-----------------------------------------------------------------* * Update memory of the weighting filter *-----------------------------------------------------------------*/ - /* st_fx->mem_w0 = xn[L_SUBFR-1] - (gain_pit*y1[L_SUBFR-1]) - (gain_code*y2[L_SUBFR-1]); */ - Ltmp = Mpy_32_16_1(gain_code, y2[L_SUBFR-1]); - Ltmp = L_shl(Ltmp, add(5,Q_xn)); - Ltmp = L_mac(Ltmp, y1[L_SUBFR-1], gain_pit); - /* Add Gaussian contribution*/ - Ltmp2 = Mpy_32_16_1(gain_code2, y22[L_SUBFR-1]); - Ltmp2 = L_shl(Ltmp2, add(5,Q_xn)); - Ltmp = L_add(Ltmp, Ltmp2); - LPDmem->mem_w0 =sub(xn[L_SUBFR-1], round_fx(L_shl(Ltmp, 1))); - move16(); - BASOP_SATURATE_WARNING_OFF; - LPDmem->mem_w0 =shr(LPDmem->mem_w0, shift); /*Qnew-1*/ - BASOP_SATURATE_WARNING_ON; - + LPDmem->mem_w0 = xn[L_SUBFR-1] - gain_pit * y1[L_SUBFR-1] - gain_code * y2[L_SUBFR-1] - gain_code2*y22[L_SUBFR-1]; /*-------------------------------------------------------* * - Find the total excitation. * *-------------------------------------------------------*/ - tmp2 = shr(L_SUBFR, 1); - FOR (j = 0; j < 2; j++) + for( i = 0; i < L_SUBFR; i++ ) { - FOR (i = sub(tmp2, shr(L_SUBFR, 1)); i < tmp2; i++) - { - /* code in Q9, gain_pit in Q14; exc Q_new */ - Ltmp = Mpy_32_16_1(gain_code2, code2[i]); - Ltmp = L_shl(Ltmp, Q_new_p5); - Ltmp = L_mac(Ltmp, gain_pit, exc[i+i_subfr]); - BASOP_SATURATE_WARNING_OFF - exc2[i] = round_fx(L_shl(Ltmp, 1)); - BASOP_SATURATE_WARNING_ON - - Ltmp2 = Mpy_32_16_1(gain_code_vect[j], code[i]); - Ltmp2 = L_shl(Ltmp2, Q_new_p5); - Ltmp = L_add(Ltmp, Ltmp2); - BASOP_SATURATE_WARNING_OFF - Ltmp = L_shl(Ltmp, 1); /* saturation can occur here */ - BASOP_SATURATE_WARNING_ON - exc[i + i_subfr] = round_fx(Ltmp); - } - tmp2 = L_SUBFR; - move16(); + exc2[i] = gain_pit*exc[i+i_subfr]; + exc2[i] += gain_code2*code2[i]; + exc[i+i_subfr] = exc2[i] + gain_code*code[i]; } /*-----------------------------------------------------------------* * Prepare TBE excitation *-----------------------------------------------------------------*/ - IF( st->igf != 0 ) - { - prep_tbe_exc_fx( L_frame, - i_subfr, - gain_pit, - gain_code, - code, - voice_fac, - &voice_factors[i_subfr/L_SUBFR], - bwe_exc, - gain_preQ, - code_preQ, - Q_new, - T0, - T0_frac, - coder_type, - st->core_brate_fx ); - } + prep_tbe_exc( st->L_frame, i_subfr, gain_pit, gain_code, code, voice_fac, &voice_factors[i_subfr/L_SUBFR], + bwe_exc, gain_preQ, code_preQ, T0, coder_type, st->core_brate ); /*---------------------------------------------------------* * Enhance the excitation * *---------------------------------------------------------*/ - E_UTIL_enhancer( voice_fac, - stab_fac, - past_gcode, - gain_inov, - &LPDmem->gc_threshold, - code, - exc2, - gain_pit, - &st->dm_fx.prev_gain_code, - st->dm_fx.prev_gain_pit, - &st->dm_fx.prev_state, - coder_type, - acelp_cfg->fixed_cdk_index[j_subfr], - L_SUBFR, - L_frame, - Q_new - ); + enhancer( MODE2, -1, acelp_cfg->fixed_cdk_index[i_subfr/L_SUBFR], 0, coder_type, st->L_frame, voice_fac, stab_fac, + norm_gain_code, gain_inov, &(LPDmem->gc_threshold), code, exc2, gain_pit, st->dispMem ); /*----------------------------------------------------------* * - compute the synthesis speech * *----------------------------------------------------------*/ - E_UTIL_synthesis(1, p_Aq, exc2, &syn2[i_subfr], L_SUBFR, LPDmem->mem_syn2, 1, M); + syn_filt( p_Aq, M, exc2, &syn2[i_subfr], L_SUBFR, LPDmem->mem_syn2, 1 ); - /*Save data for BPF*/ + syn_filt( p_Aq, M, &exc[i_subfr], &syn[i_subfr], L_SUBFR, &syn[i_subfr-M], 0 ); - move16(); - move16(); - /* st->bpf_T[j_subfr] = (int)((float)T0+(float)T0_frac/(float)T0_res+0.5f); */ - st->bpf_T[j_subfr] = add(T0, shr(div_s(T0_frac, T0_res), 14)); - st->bpf_gainT[j_subfr] = gain_pit; + /*----------------------------------------------------------* + * Save buffers for BPF * + *----------------------------------------------------------*/ - E_UTIL_synthesis(1, p_Aq, &exc[i_subfr], &syn[i_subfr], L_SUBFR, &syn[i_subfr-M], 0, M); + *pt_pitch = ((float)T0+(float)T0_frac/(float)T0_res+0.5f); + *pt_gain_pitch = gain_pit; + *pt_gain_code = gain_code; /*----------------------------------------------------------* * Update * *----------------------------------------------------------*/ - move16(); - move16(); + p_A += (M+1); p_Aq += (M+1); + pt_pitch++; + pt_gain_pitch++; + pt_gain_code++; - IF( hPlc_Ext != NULL ) + if( hPlc_Ext != NULL ) { hPlc_Ext->T0_4th = T0; - move16(); } - move32(); - st->gain_code[j_subfr] = gain_code; - - j_subfr = add(j_subfr, 1); } /* end of subframe loop */ - p_A -= (M+1); + p_A -= (M+1); p_Aq -= (M+1); /*----------------------------------------------------------* * Update LPD memory * *----------------------------------------------------------*/ - Copy (exc+L_frame-L_EXC_MEM, LPDmem->old_exc, L_EXC_MEM); - Copy(syn+L_frame-M, LPDmem->mem_syn, M); - Copy(syn+L_frame-L_SYN_MEM, LPDmem->mem_syn_r, L_SYN_MEM); - IF( hPlc_Ext != NULL ) + mvr2r( exc + st->L_frame - L_EXC_MEM, LPDmem->old_exc, L_EXC_MEM ); + mvr2r( syn + st->L_frame - M, LPDmem->mem_syn, M ); + mvr2r( syn + st->L_frame - L_SYN_MEM, LPDmem->mem_syn_r, L_SYN_MEM ); + + if( hPlc_Ext != NULL ) { - hPlc_Ext->Q_exp = sub( Q_new, hPlc_Ext->Q_new ); - move16(); - hPlc_Ext->Q_new = Q_new; - move16(); - Copy( exc+L_frame-L_EXC_MEM-8, hPlc_Ext->old_exc_Qold, 8); + mvr2r( exc + st->L_frame - L_EXC_MEM - 8, hPlc_Ext->old_exc, 8 ); } /*----------------------------------------------------------* * ZIR at the end of the ACELP frame (for TCX) * *----------------------------------------------------------*/ - Copy(syn2, syn, L_frame); - move16(); + + mvr2r( syn2, syn, st->L_frame ); tmp = LPDmem->syn[M]; - E_UTIL_deemph2(sub(Q_new,1), syn, st->preemph_fac, L_frame, &tmp); + deemph( syn, st->preemph_fac, st->L_frame, &tmp ); + mvr2r( syn + st->L_frame/2, LPDmem->Txnq, st->L_frame/2 ); + mvr2r( syn + st->L_frame - (M+1), LPDmem->syn, M+1 ); + mvr2r( syn, synth, st->L_frame ); - bufferCopyFx(syn+L_frame-(L_frame/2), LPDmem->Txnq, shr(L_frame,1),0 /*Qf_syn*/, -1 /*Qf_Txnq*/, 0 /*Q_syn*/ , 0 /*Q_Txnq*/); - Copy(syn+L_frame-M-1, LPDmem->syn, 1+M); /*Q0*/ - Copy(syn, synth, L_frame); - - assert(T0_res <= 6); /*Update MODE1*/ - Copy(p_Aq, st->old_Aq_12_8_fx, M+1 ); - st->old_Es_pred_fx = Es_pred; + mvr2r( p_Aq, st->old_Aq_12_8, M+1 ); + st->old_Es_pred = Es_pred; - return 0; + return; } diff --git a/src/libs/libevs/lib_enc/cod_tcx.cpp b/src/libs/libevs/lib_enc/cod_tcx.cpp old mode 100755 new mode 100644 index fd4c333e..d257bddd --- a/src/libs/libevs/lib_enc/cod_tcx.cpp +++ b/src/libs/libevs/lib_enc/cod_tcx.cpp @@ -1,236 +1,171 @@ /*==================================================================================== - EVS Codec 3GPP TS26.442 Apr 03, 2018. Version 12.11.0 / 13.6.0 / 14.2.0 + EVS Codec 3GPP TS26.443 Nov 13, 2018. Version 12.11.0 / 13.7.0 / 14.3.0 / 15.1.0 ====================================================================================*/ - +#include "cnst.h" #include #include +#include #include -#include "stat_com.h" -#include "prot_fx.h" -#include "basop_util.h" -#include "stl.h" -#include "basop_mpy.h" +#include "prot.h" +/*-------------------------------------------------------------------* +* HBAutocorrelation() +* +* +*-------------------------------------------------------------------*/ -/* Up to the Autocorrelation it is the same code as in GetMDCT, with the difference in the parameters in the call to tcx_windowing_analysis */ void HBAutocorrelation( - TCX_config *tcx_cfg, /* input: configuration of TCX */ - Word16 left_overlap_mode, /* input: overlap mode of left window half */ - Word16 right_overlap_mode, /* input: overlap mode of right window half */ - Word16 speech[], /* input: speech[-LFAC..L_frame+LFAC] */ - Word16 L_frame, /* input: frame length */ - Word32 *r, /* output: autocorrelations vector */ - Word16 m /* input : order of LP filter */ + TCX_config *tcx_cfg, /* input: configuration of TCX */ + int left_overlap_mode, /* input: overlap mode of left window half */ + int right_overlap_mode, /* input: overlap mode of right window half */ + float speech[], /* input: synthesis */ + int L_frame, /* input: frame length */ + float *r, /* output: autocorrelations vector */ + int m /* input : order of LP filter */ ) { - Word16 i, j, left_overlap, right_overlap; - Word16 len, norm, shift, fact; - Word32 L_tmp, L_sum; - Word16 y[L_MDCT_OVLP_MAX+L_FRAME_PLUS+L_MDCT_OVLP_MAX]; - + int i, j, left_overlap, right_overlap; + float s; + float xn_buf[L_MDCT_OVLP_MAX+L_FRAME_PLUS+L_MDCT_OVLP_MAX]; /*-----------------------------------------------------------* * Windowing * *-----------------------------------------------------------*/ - WindowSignal(tcx_cfg, tcx_cfg->tcx_offset, left_overlap_mode, right_overlap_mode, &left_overlap, &right_overlap, speech, &L_frame, y, 0); + WindowSignal( tcx_cfg, tcx_cfg->tcx_offset, left_overlap_mode, right_overlap_mode, + &left_overlap, &right_overlap, speech, &L_frame, xn_buf, 0 ); /*-----------------------------------------------------------* * Autocorrelation * *-----------------------------------------------------------*/ - len = add(L_frame, shr(add(left_overlap, right_overlap), 1)); - - /* calculate shift */ - shift = 0; - move16(); - L_sum = L_deposit_l(0); - Overflow = 0; - move16(); - FOR (i = 0; i < len; i+=1) + for (i = 0; i <= m; i++) { - /* Test Addition */ - L_mac0(L_sum, y[i], y[i]); - IF (Overflow) + s = 0.0; + + for (j = 0; j < L_frame+(left_overlap+right_overlap)/2-i; j++) { - Overflow = 0; - move16(); - shift = 1; - move16(); - L_tmp = L_msu0( 0, y[i], y[i] ); - L_tmp = L_shr( L_tmp, 1 ); - L_sum = L_add( L_shr( L_sub( L_sum, 1 ), 1 ), 1 ); - - L_sum = L_sub( L_sum, L_tmp ); - - FOR (j = add(i,1); j 0) + if (r[0] < 100.0) { - fact = lshr(-32768, shift); - FOR (i = 0; i < len; i++) - { - y[i] = mult_r(y[i], fact); - move16(); - } + r[0] = 100.0; } - /* Compute and normalize r[0] */ - L_sum = L_mac0(1, y[0], y[0]); - FOR (i = 1; i < len; i++) - { - L_sum = L_mac0(L_sum, y[i], y[i]); - } - - norm = norm_l(L_sum); - L_sum = L_shl(L_sum, norm); - r[0] = L_sum; - move32(); - - /* Compute r[1] to r[m] */ - FOR (i = 1; i <= m; i++) - { - L_sum = L_mult0(y[0],y[i]); - FOR (j = 1; j < len - i; j++) - { - L_sum = L_mac0(L_sum, y[j], y[j + i]); - } - - L_sum = L_shl(L_sum, norm); - r[i] = L_sum; - move32(); - } + return; } +/*-------------------------------------------------------------------* +* TNSAnalysis() +* +* +*-------------------------------------------------------------------*/ + void TNSAnalysis( - TCX_config *tcx_cfg, /* input: configuration of TCX */ - Word16 L_frame, /* input: frame length */ - Word16 L_spec, - Word16 tcxMode, /* input: TCX mode for the frame/subframe - TCX20 | TCX10 | TCX 5 (meaning 2 x TCX 5) */ - Word8 isAfterACELP, /* input: Flag indicating if the last frame was ACELP. For the second TCX subframe it should be 0 */ - Word32 spectrum[], /* input: MDCT spectrum */ - STnsData * pTnsData, /* output: Tns data */ - Word8 * pfUseTns, /* output: Flag indicating if TNS is used */ - Word16 *predictionGain + TCX_config *tcx_cfg, /* input: configuration of TCX */ + int L_frame, /* input: frame length */ + int L_spec, + const short tcxMode, /* input: TCX mode for the frame/subframe - TCX20 | TCX10 | TCX 5 (meaning 2 x TCX 5) */ + int isAfterACELP, /* input: Flag indicating if the last frame was ACELP. For the second TCX subframe it should be 0 */ + float spectrum[], /* input: MDCT spectrum of the subframe */ + STnsData * pTnsData, /* output: Tns data */ + int * pfUseTns, /* output: Flag indicating if TNS is used */ + float* predictionGain ) { - Word32 buff[8]; - Word16 tmp = 0; /* initialization only to avoid compiler warning, not counted */ - Word16 tmp2 = 0; /* initialization only to avoid compiler warning, not counted */ - + float buff[8]; /* Buffer for the rearrangement of LF TCX5 */ /* Init TNS */ *pfUseTns = 0; - move16(); - IF (tcx_cfg->fIsTNSAllowed != 0) + if (tcx_cfg->fIsTNSAllowed) { - tcx_cfg->pCurrentTnsConfig = &tcx_cfg->tnsConfig[sub(tcxMode, TCX_20) == 0][isAfterACELP]; - test(); + + tcx_cfg->pCurrentTnsConfig = &tcx_cfg->tnsConfig[tcxMode == TCX_20][isAfterACELP]; L_spec = tcx_cfg->pCurrentTnsConfig->iFilterBorders[0]; - move16(); /*-----------------------------------------------------------* * Temporal Noise Shaping analysis * *-----------------------------------------------------------*/ - IF (sub(tcxMode, TCX_5) == 0) + if (tcxMode == TCX_5) { - tmp = shr(L_frame,2); - /* rearrange LF sub-window lines prior to TNS analysis & filtering */ - tmp2 = shr(L_spec,1); - - IF (sub(tmp2, tmp) < 0) + if (L_spec < L_frame/2) { - Copy32(spectrum+8, spectrum+16, sub(tmp2, 8)); - Copy32(spectrum+tmp, spectrum+8, 8); - Copy32(spectrum+tmp+8, spectrum+tmp2+8, sub(tmp2, 8)); + mvr2r(spectrum+8, spectrum+16, L_spec/2-8); + mvr2r(spectrum+L_frame/4, spectrum+8, 8); + mvr2r(spectrum+L_frame/4+8, spectrum+L_spec/2+8, L_spec/2-8); } - ELSE + else { - Copy32(spectrum+tmp, buff, 8); - Copy32(spectrum+8, spectrum+16, sub(tmp, 8)); - Copy32(buff, spectrum+8, 8); + mvr2r(spectrum+L_frame/4, buff, 8); + mvr2r(spectrum+8, spectrum+16, L_frame/4-8); + mvr2r(buff, spectrum+8, 8); } } - move16(); - *pfUseTns = (Word8)DetectTnsFilt(tcx_cfg->pCurrentTnsConfig, spectrum, pTnsData, predictionGain); + *pfUseTns = DetectTnsFilt(tcx_cfg->pCurrentTnsConfig, spectrum, pTnsData, predictionGain); - /* If TNS should be used then get the residual after applying it inplace in spectrum */ - IF (*pfUseTns != 0) + /* If TNS should be used then get the residual after applying it inplace in the spectrum */ + if (*pfUseTns) { ApplyTnsFilter(tcx_cfg->pCurrentTnsConfig, pTnsData, spectrum, 1); + } - IF (sub(tcxMode, TCX_5) == 0) + if (tcxMode == TCX_5) { /* undo rearrangement of LF sub-window lines prior to TNS analysis */ - IF (sub(tmp2, tmp) < 0) + if (L_spec < L_frame/2) { - Copy32(spectrum+tmp2+8, spectrum+tmp+8, sub(tmp2, 8)); - Copy32(spectrum+8, spectrum+tmp, 8); - Copy32(spectrum+16, spectrum+8, sub(tmp2, 8)); - set32_fx(spectrum+tmp2, 0, sub(tmp,tmp2)); - set32_fx(spectrum+tmp+tmp2, 0, sub(tmp,tmp2)); + mvr2r(spectrum+L_spec/2+8, spectrum+L_frame/4+8, L_spec/2-8); + mvr2r(spectrum+8, spectrum+L_frame/4, 8); + mvr2r(spectrum+16, spectrum+8, L_spec/2-8); + set_zero(spectrum+L_spec/2, L_frame/4-L_spec/2); + set_zero(spectrum+L_frame/4+L_spec/2, L_frame/4-L_spec/2); } - ELSE + else { - Copy32(spectrum+8, buff, 8); - Copy32(spectrum+16, spectrum+8, sub(tmp, 8)); - Copy32(buff, spectrum+tmp, 8); + mvr2r(spectrum+8, buff, 8); + mvr2r(spectrum+16, spectrum+8, L_frame/4-8); + mvr2r(buff, spectrum+L_frame/4, 8); } } } + return; } + +/*-------------------------------------------------------------------* +* ShapeSpectrum() +* +* +*-------------------------------------------------------------------*/ + void ShapeSpectrum( - TCX_config *tcx_cfg,/*input: configuration of TCX*/ - Word16 A[], /* input: quantized coefficients NxAz_q[M+1] */ - Word16 gainlpc[], /* output: MDCT gains for the previous frame */ - Word16 gainlpc_e[], /* output: MDCT gains exponents */ - Word16 L_frame_glob,/* input: frame length */ - Word16 L_spec, - Word32 spectrum[], /* i/o: MDCT spectrum */ - Word8 pfUseTns, /* output: Flag indicating if TNS is used */ - Encoder_State_fx *st + TCX_config *tcx_cfg,/*input: configuration of TCX */ + float A[], /* input: quantized coefficients NxAz_q[M+1] */ + float gainlpc[], /* output: MDCT gains for the previous frame */ + int L_frame_glob, /* input: frame length */ + int L_spec, + float spectrum[], /* i/o: MDCT spectrum */ + int fUseTns, /* output: Flag indicating if TNS is used */ + Encoder_State *st ) { - Word16 L_frame; - Word16 Ap[M+2]; - Word16 gamma1; - Word16 gainlpc_noinv[FDNS_NPTS]; - Word16 gainlpc_noinv_e[FDNS_NPTS]; - Word16 i; - Word32 max_low_pre = 0, max_high_pre = 0; - + int L_frame; + int tcx_offset; + float Ap[M+2]; + float gamma1; + float max_low_pre = 0.f, max_high_pre = 0.f; /*-----------------------------------------------------------* * Init * @@ -238,66 +173,56 @@ void ShapeSpectrum( /* Init lengths */ L_frame = L_frame_glob; - move16(); + tcx_offset = tcx_cfg->tcx_offset; gamma1 = st->gamma; - move16(); - if (st->enableTcxLpc != 0) + + if (st->enableTcxLpc) { - gamma1 = 0x7FFF; - move16(); + gamma1 = 1.0f; } /* if past frame is ACELP */ - IF (st->last_core_fx == ACELP_CORE) + if (st->last_core == 0) { - L_frame = add(L_frame, tcx_cfg->tcx_offset); - L_spec = add(L_spec, shr(tcx_cfg->tcx_coded_lines, 2)); + L_frame += tcx_offset; + L_spec += tcx_cfg->tcx_coded_lines >> 2; if(tcx_cfg->lfacNext<0) { - L_frame = sub(L_frame,tcx_cfg->lfacNext); - move16(); + L_frame -= tcx_cfg->lfacNext; } } - test(); - tcxGetNoiseFillingTilt(A, - M, - L_frame, - (L_sub(st->total_brate_fx, ACELP_13k20) >= 0 && st->rf_mode == 0 ), - &st->noiseTiltFactor); + tcxGetNoiseFillingTilt( A, L_frame, (st->total_brate >= ACELP_13k20 && !st->rf_mode), &st->noiseTiltFactor ); /* Calculate Spectrum Flatness Measure for the TCX Concealment */ - IF (st->enablePlcWaveadjust) + if( st->enablePlcWaveadjust ) { - tcx_cfg->SFM2 = SFM_Cal(spectrum, s_min(200, L_frame)); + tcx_cfg->SFM2 = SFM_Cal(spectrum, min(200, L_frame)); } - test(); - test(); - test(); - IF( (L_sub(st->total_brate_fx, ACELP_9k60) == 0 && sub(st->bwidth_fx, SWB) == 0) || - (L_sub(st->total_brate_fx, ACELP_13k20) == 0 && sub(st->bwidth_fx, SWB) == 0) ) + if( (st->total_brate == ACELP_9k60 && st->bwidth == SWB) || + (st->total_brate == ACELP_13k20 && st->bwidth == SWB) ) { - max_low_pre = 0; - move32(); - FOR (i = 0; i < L_frame; i++) + int i; + + max_low_pre = 0.f; + for (i = 0; i < L_frame; i++) { - Word32 tmp = L_abs(spectrum[i]); - if( L_sub(tmp, max_low_pre) > 0 ) + float tmp = fabs(spectrum[i]); + if( tmp > max_low_pre ) { - max_low_pre = L_add(0, tmp); + max_low_pre = tmp; } } - max_high_pre = 0; - move32(); + max_high_pre = 0.f; for (i = 0; i < L_spec - L_frame; i++) { - Word32 tmp = L_abs(spectrum[L_frame + i]); - if( L_sub( tmp, max_high_pre) > 0 ) + float tmp = fabs(spectrum[L_frame + i]); + if( tmp > max_high_pre ) { - max_high_pre = L_add(0, tmp); + max_high_pre = tmp; } } } @@ -305,1899 +230,1032 @@ void ShapeSpectrum( /*-----------------------------------------------------------* * Pre-shaping in frequency domain using weighted LPC (Wz) * *-----------------------------------------------------------*/ + weight_a(A, Ap, gamma1, M); - weight_a_fx( A, Ap, gamma1, M ); + lpc2mdct(Ap, M, gainlpc); - lpc2mdct( Ap, M, gainlpc_noinv, gainlpc_noinv_e, gainlpc, gainlpc_e ); + mdct_preShaping(spectrum, L_frame, gainlpc); - mdct_shaping( spectrum, L_frame, gainlpc_noinv, gainlpc_noinv_e ); - FOR (i = L_frame; i < L_spec; i++) - { - spectrum[i] = L_shl(Mpy_32_16_1(spectrum[i], gainlpc_noinv[FDNS_NPTS-1]), gainlpc_noinv_e[FDNS_NPTS-1]); - move32(); - } + v_multc(spectrum+L_frame, 1.f/gainlpc[FDNS_NPTS-1], spectrum+L_frame, L_spec-L_frame); /* reduce the peaks in the IGF region, to make life of the core-coder easier... */ - test(); - IF( ( L_sub(st->total_brate_fx, ACELP_9k60) == 0 && sub(st->bwidth_fx, SWB) == 0 ) || - ( L_sub(st->total_brate_fx, ACELP_13k20) == 0 && sub(st->bwidth_fx, SWB) == 0 ) ) + if( (st->total_brate == ACELP_9k60 && st->bwidth == SWB) || + (st->total_brate == ACELP_13k20 && st->bwidth == SWB) ) { - Word16 sf_width; - Word16 dist_low, dist_high; - Word16 max_fac_s, max_fac_m; - Word32 max_low, max_low1, max_low2, max_high; - Word16 headroom, shift, tmp16; + int i, sf_width; + int dist_low, dist_high; + float max_fac; + float max_low, max_low1, max_low2, max_high; - - max_fac_m = 24576; - move16(); - /* max_fac = 3 */ - max_fac_s = 2; - move16(); if( st->tcx_lpc_shaped_ari ) { - /* max_fac = 1.5 */ - max_fac_s = 1; - move16(); + max_fac = 1.5f; + } + else + { + max_fac = 3.f; } - sf_width = shr(L_frame, 1); + sf_width = L_frame / 2; - max_low2 = 0; - move32(); + max_low2 = 0.f; dist_low = 0; - move16(); - FOR (i = 0; i < sf_width; i++) + for (i = 0; i < sf_width; i++) { - Word32 tmp = L_abs(spectrum[L_frame - 1 - i]); - IF( L_sub(tmp, max_low2) > 0 ) + float tmp = fabs(spectrum[L_frame - 1 - i]); + if( tmp > max_low2 ) { - max_low2 = L_add(0, tmp); + max_low2 = tmp; dist_low = i; - move16(); } } - max_low1 = 0; - move32(); - FOR (i = 0; i < sub(L_frame, sf_width); i++) + max_low1 = 0.f; + for (i = 0; i < L_frame - sf_width; i++) { - Word32 tmp = L_abs(spectrum[L_frame - sf_width - 1 - i]); - if( L_sub(tmp, max_low1) > 0 ) + float tmp = fabs(spectrum[L_frame - sf_width - 1 - i]); + if( tmp > max_low1 ) { - max_low1 = L_add(0, tmp); + max_low1 = tmp; } if( tmp > max_low2 ) { - dist_low = add(sf_width, i); + dist_low = sf_width + i; } } - max_low = L_max(max_low1, max_low2); + max_low = max(max_low1, max_low2); - max_high = 0; - move32(); + max_high = 0.f; dist_high = 0; - move16(); - FOR (i = 0; i < sub(L_spec, L_frame); i++) + for (i = 0; i < L_spec - L_frame; i++) { - Word32 tmp = L_abs(spectrum[L_frame + i]); - if( L_sub(tmp, max_high) > 0 ) + float tmp = fabs(spectrum[L_frame + i]); + if( tmp > max_high) { - max_high = L_add(0, tmp); + max_high = tmp; dist_high = i; - move16(); } } - /* at least 9 bits headroom are needed for below multiplicitions */ - shift = 0; - move16(); - headroom = 31; - move16(); - - tmp16 = norm_l(max_low); - if(max_low != 0) headroom = s_min(headroom, tmp16); - - tmp16 = norm_l(max_low2); - if(max_low2 != 0) headroom = s_min(headroom, tmp16); - - tmp16 = norm_l(max_high); - if(max_high != 0) headroom = s_min(headroom, tmp16); - - if( sub(headroom, 9) < 0) + if( (4.f * dist_high * max_high > dist_low * max_low) && (16.f * max_low_pre > max_high_pre) && (max_high > max_fac * max_low2) ) { - shift = sub(9, headroom); + float fac = max_fac * max_low2 / max_high; + v_multc(spectrum + L_frame, fac, spectrum + L_frame, L_spec - L_frame); } - max_low = L_shr(max_low, shift); - max_low2 = L_shr(max_low2, shift); - max_high = L_shr(max_high, shift); - test(); - test(); - IF( L_sub(imult3216(max_high, dist_high), imult3216(L_shr(max_low, 2), dist_low)) > 0 && (L_sub(max_low_pre, L_shr(max_high_pre, 4)) > 0) && (L_sub(max_high, L_shl(Mpy_32_16_r(max_low2, max_fac_m), max_fac_s)) > 0) ) - { - Word16 fac; - fac = divide3232(max_low2, max_high); - fac = shl(mult_r( fac, max_fac_m ), max_fac_s); - - FOR (i = 0; i < sub(L_spec, L_frame); i++) - { - spectrum[L_frame + i] = Mpy_32_16_1(spectrum[L_frame + i], fac); - } - } } - - test(); - test(); - test(); - IF( st->tcxonly && st->tcxltp && (st->tcxltp_gain > 0) && !pfUseTns ) + if (st->tcxonly && st->tcxltp && (st->tcxltp_gain > 0.0f) && !fUseTns ) { - PsychAdaptLowFreqEmph(spectrum, gainlpc, gainlpc_e); + PsychAdaptLowFreqEmph(spectrum, gainlpc); } + return; } +/*-------------------------------------------------------------------* +* QuantizeSpectrum() +* +* +*-------------------------------------------------------------------*/ + void QuantizeSpectrum( - TCX_config *tcx_cfg, /*input: configuration of TCX*/ - Word16 A[], /* input: quantized coefficients NxAz_q[M+1] */ - Word16 Aqind[], /* input: frame-independent quantized coefficients (M+1) */ - Word16 gainlpc[], /* input: MDCT gains of the previous frame */ - Word16 gainlpc_e[], /* input: MDCT gains exponents */ - Word16 synth[], - Word16 L_frame_glob, /* input: frame length */ - Word16 L_frameTCX_glob, - Word16 L_spec, - Word16 nb_bits, /*input: bit budget*/ - Word8 tcxonly, /*input: only TCX flag*/ - Word32 spectrum[], /* i/o: MDCT spectrum, input is shaped MDCT spectrum */ - Word16 *spectrum_e, /* i/o: MDCT spectrum exponent */ - STnsData * pTnsData, /* input: Tns data */ - Word8 fUseTns, /* input: Flag indicating if TNS is used */ - Word16 tnsSize, /* input: number of tns parameters put into prm */ - LPD_state *LPDmem, /*i/o: memories*/ - Word16 prm[], /* output: tcx parameters */ - Word16 frame_cnt, /* input: frame counter in the super_frame */ - Encoder_State_fx *st, + TCX_config *tcx_cfg,/*input: configuration of TCX*/ + float A[], /* input: quantized coefficients NxAz_q[M+1] */ + Word16 Aqind[], /* input: frame-independent quantized coefficients (M+1) */ + float gainlpc[], /* input: MDCT gains of the previous frame */ + float synth[], + int L_frame_glob, /* input: frame length */ + int L_frameTCX_glob, + int L_spec, + int nb_bits, /*input: bit budget*/ + int tcxonly, /*input: only TCX flag*/ + float spectrum[], /* i/o: MDCT spectrum, input is shaped MDCT spectrum */ + STnsData * pTnsData,/* input: Tns data */ + int fUseTns, /* input: Flag indicating if TNS is used */ + int tnsSize, /* input: number of tns parameters put into prm */ + LPD_state *LPDmem, /*i/o: memories*/ + int prm[], /* output: tcx parameters */ + int frame_cnt, /* input: frame counter in the super_frame */ + Encoder_State *st, CONTEXT_HM_CONFIG *hm_cfg ) { - Word16 i, L_frame, tcx_offset; - Word16 stop; - Word16 tmp1, tmp2, tmp3, tmp4, s; - Word32 tmp32; - Word8 tmp8; - Word16 *tmpP16; - Word16 L_frameTCX; - Word16 fac_ns; - Word16 nf_seed; - Word32 ener; - Word16 ener_e; - Word16 gain_tcx, gain_tcx_e; - Word16 sqBits; - Word16 overlap; - Word16 noiseFillingSize; - Word16 noiseTransWidth; - Word32 *OriginalSpectrum; - Word16 OriginalSpectrum_e; - Word16 ctxHmBits; - Word16 resQBits; - Word16 *signs; - Word16 signaling_bits; - Word16 *prm_ltp, *prm_tns, *prm_hm, *prm_lastnz, *prm_target; - Word16 Aq_old[M+1]; - Word32 SFM; - Word32 K, K2; - Word16 aldo; /* ALDO flag in current frame*/ - Word16 nz; /* non-zero length in ALDO window*/ - CONTEXT_HM_CONFIG * phm_cfg; + int i, sqTargetBits, L_frame, tcx_offset, stop; + int L_frameTCX; + float fac_ns, ener, gain_tcx, gain_tcx_opt; + float xn_buf[L_MDCT_OVLP_MAX+L_FRAME_PLUS+L_MDCT_OVLP_MAX]; + float x_orig[N_MAX]; + float sqGain = 1.0f; + int sqBits; + int sqBits_noStop; + int overlap; + int noiseFillingSize; + int noiseTransWidth = MIN_NOISE_FILLING_HOLE; + int nEncoded; + int *sqQ; + short LtpPitchLag; + int ctxHmBits; + int resQBits; + int resQTargetBits = 0; + short nf_seed = 0; + int PeriodicityIndex, NumIndexBits; + float *OriginalSpectrum; + int nEncodedCtxHm, stopCtxHm, sqBitsCtxHm, Selector; + int lastnz, lastnzCtxHm; + float RelativeScore; + int *signs; + int signaling_bits; + int *prm_ltp, *prm_tns, *prm_hm, *prm_lastnz, *prm_target; + float SFM; + float K, K2; + float Aq_old[M+1]; + short aldo; /* ALDO flag in current frame*/ + short nz; /* non-zero length in ALDO window*/ + int maxNfCalcBw; + /*-----------------------------------------------------------* + * Init * + *-----------------------------------------------------------*/ - /* Stack memory is split between encoder and internal decoder to reduce max - stack memory usage. */ + /* Init lengths */ + L_frame = L_frame_glob; + L_frameTCX = L_frameTCX_glob; + overlap = tcx_cfg->tcx_mdct_window_length; + aldo=0; + nz=NS2SA(st->sr_core, N_ZERO_MDCT_NS); + + tcx_offset = tcx_cfg->tcx_offset; + + OriginalSpectrum = NULL; + signs = NULL; /* silence warning */ + NumIndexBits = 0; + sqBits = 0; + ctxHmBits = 0; + resQBits=0; + prm_ltp = &prm[1+NOISE_FILL_RANGES]; + prm_tns = prm_ltp + LTPSIZE; + prm_hm = prm_tns + tnsSize; + prm_lastnz = prm_hm + 2; + sqQ = prm_hm + NPRM_CTX_HM; + + /* if past frame is ACELP */ + + if (st->last_core == 0) { - Word16 sqTargetBits; - Word16 gain_tcx_opt, gain_tcx_opt_e; - Word16 sqGain, sqGain_e; - Word16 sqBits_noStop; - Word16 nEncoded; - Word16 maxNfCalcBw; - Word16 PeriodicityIndex; - Word16 NumIndexBits; - Word16 nEncodedCtxHm, stopCtxHm, sqBitsCtxHm, Selector; - Word16 lastnz, lastnzCtxHm; - Word16 RelativeScore; - Word32 x_orig[N_MAX]; - Word16 x_orig_e; - Word16 resQTargetBits; - Word16 xn_buf16[L_FRAME_PLUS]; - Word16 *sqQ; - Word16 LtpPitchLag; + tcx_cfg->last_aldo=0; - - sqGain = 0x4000; - move16(); - sqGain_e = 1; - move16(); - noiseTransWidth = MIN_NOISE_FILLING_HOLE; - move16(); - resQTargetBits = 0; - move16(); - - /*-----------------------------------------------------------* - * Init * - *-----------------------------------------------------------*/ - - /* Init lengths */ - L_frame = L_frame_glob; - move16(); - L_frameTCX = L_frameTCX_glob; - move16(); - overlap = tcx_cfg->tcx_mdct_window_length; - move16(); - aldo = 0; - move16(); - nz = NS2SA_fx2(st->sr_core, N_ZERO_MDCT_NS); - move16(); - /* Modified the overlap to the delay in case of short blocks*/ - tcx_offset = tcx_cfg->tcx_offset; - move16(); - - OriginalSpectrum = NULL; - signs = NULL; /* silence warning */ - NumIndexBits = 0; - move16(); - sqBits = 0; - move16(); - ctxHmBits = 0; - move16(); - resQBits = 0; - move16(); - prm_ltp = &prm[1+NOISE_FILL_RANGES]; - move16(); - prm_tns = prm_ltp + LTPSIZE; - move16(); - prm_hm = prm_tns + tnsSize; - move16(); - prm_lastnz = prm_hm + 2; - move16(); - sqQ = prm_hm + NPRM_CTX_HM; - move16(); - - /* if past frame is ACELP */ - - IF (st->last_core_fx == ACELP_CORE) + L_frame += tcx_offset; + L_frameTCX += tcx_cfg->tcx_offsetFB; + L_spec += tcx_cfg->tcx_coded_lines >> 2; + if(tcx_cfg->lfacNext<0) + { + L_frame -= tcx_cfg->lfacNext; + L_frameTCX -= tcx_cfg->lfacNextFB; + tcx_offset = tcx_cfg->lfacNext; + } + else { - tcx_cfg->last_aldo = 0; - move16(); - - L_frame = add(L_frame, tcx_offset); - L_frameTCX = add(L_frameTCX, tcx_cfg->tcx_offsetFB); - L_spec = add(L_spec, shr(tcx_cfg->tcx_coded_lines, 2)); tcx_offset = 0; - move16(); - IF(tcx_cfg->lfacNext<0) - { - L_frame = sub(L_frame,tcx_cfg->lfacNext); - L_frameTCX = sub(L_frameTCX, tcx_cfg->lfacNextFB); - tcx_offset = tcx_cfg->lfacNext; - move16(); - } - st->noiseLevelMemory = 0; - move16(); + } + st->noiseLevelMemory = 0; + } + + + lsp2a_stab( st->lsp_old, Aq_old, M ); + + /* target bitrate for SQ */ + sqTargetBits = nb_bits-7-NBITS_NOISE_FILL_LEVEL; + + /*Unquantized spectrum here*/ + if(st->enablePlcWaveadjust) + { + + SFM = SFM_Cal(spectrum, min(200, L_frame_glob)); + + if (L_frame_glob <= 256) + { + K = 0.4f; + K2 = 0.1f; + } + else if (L_frame_glob == 320 || L_frame_glob == 512) + { + K = 0.4f; + K2 = 0.1f; + } + else /*FrameSize_Core == 640*/ + { + K = 0.35f; + K2 = 0.04f; } - E_LPC_f_lsp_a_conversion(st->lsp_old_fx, Aq_old, M); - - /* target bitrate for SQ */ - sqTargetBits = sub(nb_bits, 7 + NBITS_NOISE_FILL_LEVEL); - - /*Unquantized spectrum here*/ - IF (st->enablePlcWaveadjust) + if (SFM < K) { - - - SFM = SFM_Cal(spectrum, s_min(200, L_frame_glob)); - test(); - IF (sub(L_frame_glob, 256) <= 0) - { - K = 0x33333333; - move32(); - K2 = 0xCCCCCCD; - move32(); - } - ELSE IF (sub(L_frame_glob,320) == 0 || sub(L_frame_glob, 512)== 0 ) - { - K = 0x33333333; - move32(); - K2 = 0xCCCCCCD; - move32(); - } - ELSE /*FrameSize_Core == 640*/ - { - K = 0x2CCCCCCD; - move32(); - K2 = 0x51EB852; - move32(); - } - - - IF ( L_sub(SFM, K)<0 ) - { - st->Tonal_SideInfo = 1; - move16(); - } - ELSE - { - st->Tonal_SideInfo = 0; - move16(); - } - - if ( L_sub(tcx_cfg->SFM2, K2)< 0) - { - st->Tonal_SideInfo = 1; - move16(); - } + st->Tonal_SideInfo = 1; + } + else + { + st->Tonal_SideInfo = 0; } - /* Save pre-shaped spectrum*/ - Copy32(spectrum, x_orig, L_spec); - x_orig_e = *spectrum_e; - move16(); - - /*-----------------------------------------------------------* - * Bandwidth Limitation * - *-----------------------------------------------------------*/ - - noiseFillingSize = L_spec; - move16(); - IF (st->igf != 0) + if (tcx_cfg->SFM2 < K2) { - noiseFillingSize = st->hIGFEnc.infoStartLine; - move16(); - } - ELSE - { - st->hIGFEnc.infoStopLine = noiseFillingSize; - move16(); + st->Tonal_SideInfo = 1; } + } - FOR (i=st->hIGFEnc.infoStopLine; itcx_lpc_shaped_ari == 0) /* old arithmetic coder */ + noiseFillingSize = L_spec; + if (st->igf) + { + noiseFillingSize = (&st->hIGFEnc)->infoStartLine; + } + else + { + (&st->hIGFEnc)->infoStopLine = noiseFillingSize; + } + + for (i=(&st->hIGFEnc)->infoStopLine; i < max(L_frame, L_frameTCX); i++) + { + spectrum[i] = 0.0f; + } + + /*-----------------------------------------------------------* + * Quantization * + *-----------------------------------------------------------*/ + + if (!st->tcx_lpc_shaped_ari) + { + /* context based arithmetic coder */ + + /* Fast estimation of the scalar quantizer step size */ + if (tcx_cfg->ctx_hm && (st->last_core != 0) ) { - /* Fast estimation of the scalar quantizer step size */ - test(); - IF ((tcx_cfg->ctx_hm != 0) && (st->last_core_fx != ACELP_CORE)) + LtpPitchLag = ((!tcxonly) && (st->tcxltp_pitch_int < st->L_frame) + ? ((2 * st->L_frame * st->pit_res_max) << kLtpHmFractionalResolution) / (st->tcxltp_pitch_int * st->pit_res_max + st->tcxltp_pitch_fr): -1); + + ++ctxHmBits; /* ContextHM flag */ + --sqTargetBits; /* ContextHM flag */ + + OriginalSpectrum = spectrum; + + PeriodicityIndex = SearchPeriodicityIndex( OriginalSpectrum, NULL, L_spec, sqTargetBits, LtpPitchLag, + st->tcxltp ? st->tcxltp_gain : -1.0f, &RelativeScore ); + + ConfigureContextHm( L_spec, sqTargetBits, PeriodicityIndex, LtpPitchLag, hm_cfg ); + + NumIndexBits = CountIndexBits( L_spec >= 256, PeriodicityIndex ); + + /* Quantize original spectrum */ + sqGain = SQ_gain( OriginalSpectrum, (int)(LPDmem->tcx_target_bits_fac * (float)sqTargetBits), L_spec ); + + tcx_scalar_quantization( OriginalSpectrum, sqQ, L_spec, sqGain, tcx_cfg->sq_rounding, st->memQuantZeros, tcxonly ); + + /* Estimate original bitrate */ + stop = 0; + sqBits = ACcontextMapping_encode2_estimate_no_mem_s17_LC( sqQ, L_spec, &lastnz, &nEncoded, sqTargetBits, &stop, NULL ); + + /* Estimate context mapped bitrate */ + stopCtxHm = 0; + + /* Context Mapping */ + sqBitsCtxHm = ACcontextMapping_encode2_estimate_no_mem_s17_LC( sqQ, L_spec, &lastnzCtxHm, &nEncodedCtxHm, + sqTargetBits - NumIndexBits, &stopCtxHm, hm_cfg ); + + /* Decide whether or not to use context mapping */ + + Selector = max(stop, sqBits) - (max(stopCtxHm, sqBitsCtxHm) + NumIndexBits); + + if (Selector > 2 || (abs(Selector) <= 2 && kCtxHmOlRSThr < RelativeScore)) { - LtpPitchLag = -1; - move16(); - - test(); - IF ((tcxonly == 0) && (sub(st->tcxltp_pitch_int, st->L_frame_fx) < 0)) - { - tmp32 = L_shl(L_mult0(st->L_frame_fx, st->pit_res_max), 1+kLtpHmFractionalResolution+1); - tmp1 = add(imult1616(st->tcxltp_pitch_int, st->pit_res_max), st->tcxltp_pitch_fr); - LtpPitchLag = div_l(tmp32, tmp1); - } - - ctxHmBits = add(ctxHmBits, 1); /* ContextHM flag */ - sqTargetBits = sub(sqTargetBits, 1); /* ContextHM flag */ - - OriginalSpectrum = spectrum; - OriginalSpectrum_e = *spectrum_e; - move16(); - - tmp1 = -1; - move16(); - if (st->tcxltp != 0) - { - tmp1 = st->tcxltp_gain; - move16(); - } - PeriodicityIndex = SearchPeriodicityIndex( - OriginalSpectrum, - NULL, - L_spec, - sqTargetBits, - LtpPitchLag, - tmp1, - &RelativeScore - ); - - ConfigureContextHm( - L_spec, - sqTargetBits, - PeriodicityIndex, - LtpPitchLag, - hm_cfg - ); - - tmp1 = 1; - move16(); - if (sub(L_spec, 256) < 0) - { - tmp1 = 0; - move16(); - } - NumIndexBits = CountIndexBits( tmp1, PeriodicityIndex); - - - - /* Quantize original spectrum */ - - sqGain = SQ_gain(OriginalSpectrum, OriginalSpectrum_e, - shl(mult(LPDmem->tcx_target_bits_fac, sqTargetBits), 1), - L_spec, - &sqGain_e); - - tcx_scalar_quantization(OriginalSpectrum, OriginalSpectrum_e, - sqQ, - L_spec, - sqGain, sqGain_e, - tcx_cfg->sq_rounding, - st->memQuantZeros, - tcxonly); - - /* Estimate original bitrate */ - stop = 0; - move16(); - - sqBits = ACcontextMapping_encode2_estimate_no_mem_s17_LC(sqQ, - L_spec, - &lastnz, - &nEncoded, - sqTargetBits, - &stop, - NULL); - - /* Estimate context mapped bitrate */ - - stopCtxHm = 0; - move16(); - - /* Context Mapping */ - sqBitsCtxHm = ACcontextMapping_encode2_estimate_no_mem_s17_LC(sqQ, - L_spec, - &lastnzCtxHm, - &nEncodedCtxHm, - sub(sqTargetBits, NumIndexBits), - &stopCtxHm, - hm_cfg - ); - - /* Decide whether or not to use context mapping */ - Selector = sub(s_max(stop, sqBits), add(s_max(stopCtxHm, sqBitsCtxHm), NumIndexBits)); - - test(); - test(); - IF ((sub(Selector, 2) > 0) || ((sub(abs_s(Selector), 2) <= 0) && - (sub(kCtxHmOlRSThr, RelativeScore) < 0))) - { - /* CtxHm is likely better */ - sqTargetBits = sub(sqTargetBits, NumIndexBits); - ctxHmBits = add(ctxHmBits, NumIndexBits); - prm_hm[0] = 1; - move16(); - prm_hm[1] = PeriodicityIndex; - move16(); - *prm_lastnz = lastnzCtxHm; - move16(); - sqBits_noStop = sqBits = sqBitsCtxHm; - move16(); - move16(); - nEncoded = nEncodedCtxHm; - move16(); - stop = stopCtxHm; - move16(); - } - ELSE /* Original is better or not much difference */ - { - prm_hm[0] = 0; - move16(); - prm_hm[1] = PeriodicityIndex; - move16(); - *prm_lastnz = lastnz; - move16(); - PeriodicityIndex = -1; - move16(); - - sqBits_noStop = sqBits; - move16(); - } - - - if (stop != 0) - { - - sqBits = stop; - move16(); - } + /* CtxHm is likely better */ + sqTargetBits -= NumIndexBits; + ctxHmBits += NumIndexBits; + prm_hm[0] = 1; + prm_hm[1] = PeriodicityIndex; + *prm_lastnz = lastnzCtxHm; + sqBits_noStop = sqBits = sqBitsCtxHm; + nEncoded = nEncodedCtxHm; + stop = stopCtxHm; } - ELSE /* no context hm*/ + else { + /* Original is better or not much difference */ + prm_hm[0] = 0; + prm_hm[1] = PeriodicityIndex; + *prm_lastnz = lastnz; PeriodicityIndex = -1; - move16(); - - sqGain = SQ_gain(spectrum, *spectrum_e, - shl(mult(LPDmem->tcx_target_bits_fac, sqTargetBits), 1), - L_spec, - &sqGain_e); - - /* Quantize spectrum */ - - tcx_scalar_quantization(spectrum, *spectrum_e, - sqQ, - L_spec, - sqGain, sqGain_e, - tcx_cfg->sq_rounding, - st->memQuantZeros, - tcxonly - ); - - /* Estimate bitrate */ - stop = 0; - move16(); - sqBits = ACcontextMapping_encode2_estimate_no_mem_s17_LC(sqQ, - L_spec, - prm_lastnz, /* lastnz */ - &nEncoded, - sqTargetBits, - &stop, - NULL); sqBits_noStop = sqBits; - move16(); - - if (stop != 0) - { - sqBits = stop; - move16(); - } - } /* end of if (ctx_hm) */ - - /* Adjust correction factor */ - tmp1 = sqBits; - move16(); - - if (s_and(L_spec, sub(L_spec, 1)) == 0) /* power-of-2 */ - { - tmp1 = add(tmp1, 1); } - tmp1 = BASOP_Util_Divide1616_Scale(sqTargetBits, tmp1, &tmp2); - BASOP_SATURATE_WARNING_OFF - LPDmem->tcx_target_bits_fac = shl(mult(LPDmem->tcx_target_bits_fac, tmp1), tmp2); - BASOP_SATURATE_WARNING_ON - - if (sub(LPDmem->tcx_target_bits_fac, 0x5000) > 0) + if (stop != 0) { - LPDmem->tcx_target_bits_fac = 0x5000; - move16(); + sqBits = stop; } - if (sub(LPDmem->tcx_target_bits_fac, 0x3000) < 0) + } + else + { + /* no context hm*/ + PeriodicityIndex = -1; + + sqGain = SQ_gain(spectrum, (int)(LPDmem->tcx_target_bits_fac * (float)sqTargetBits), L_spec); + + /* Quantize spectrum */ + tcx_scalar_quantization( spectrum, sqQ, L_spec, sqGain, tcx_cfg->sq_rounding, st->memQuantZeros, tcxonly ); + + /* Estimate bitrate */ + stop = 0; + sqBits_noStop = sqBits = ACcontextMapping_encode2_estimate_no_mem_s17_LC( sqQ, L_spec, prm_lastnz, &nEncoded, sqTargetBits, &stop, NULL); + + if(stop!=0) { - LPDmem->tcx_target_bits_fac = 0x3000; - move16(); + sqBits=stop; + } + } /* end of if (ctx_hm) */ + + /* Adjust correction factor */ + if ((L_spec & (L_spec - 1)) == 0) + { + /* power-of-2 */ + LPDmem->tcx_target_bits_fac *= (float)sqTargetBits / (float)(sqBits + 1); + } + else + { + LPDmem->tcx_target_bits_fac *= (float)sqTargetBits / (float)sqBits; + } + + if (LPDmem->tcx_target_bits_fac>1.25) + { + LPDmem->tcx_target_bits_fac = 1.25; + } + if (LPDmem->tcx_target_bits_fac<0.75) + { + LPDmem->tcx_target_bits_fac = 0.75; + } + + /* Refine quantizer step size with a rate-control-loop (optional) */ + sqBits = tcx_scalar_quantization_rateloop( spectrum, sqQ, L_spec, &sqGain, tcx_cfg->sq_rounding, st->memQuantZeros, + prm_lastnz, /* lastnz */ sqTargetBits, &nEncoded, &stop, sqBits_noStop, sqBits, tcx_cfg->tcxRateLoopOpt, + tcxonly, PeriodicityIndex >= 0 ? hm_cfg : NULL ); + + if (ctxHmBits > 0) + { + /* Mapping tool is enabled */ + /* Truncate spectrum */ + for (i=nEncoded; i= 0) { - phm_cfg = hm_cfg; - move16(); - } - sqBits = tcx_scalar_quantization_rateloop(spectrum, *spectrum_e, - sqQ, - L_spec, - &sqGain, &sqGain_e, - tcx_cfg->sq_rounding, - st->memQuantZeros, - prm_lastnz, /* lastnz */ - sqTargetBits, - &nEncoded, - &stop, - sqBits_noStop, - sqBits, - tcx_cfg->tcxRateLoopOpt, - tcxonly, - phm_cfg - ); + /* Mapping is used */ + /* Estimate non-mapped bitrate */ + stopCtxHm = 1; - IF (ctxHmBits > 0) /* Mapping tool is enabled */ - { - /* Truncate spectrum */ - set16_fx(sqQ+nEncoded, 0, sub(L_spec, nEncoded)); + sqBitsCtxHm = ACcontextMapping_encode2_estimate_no_mem_s17_LC(sqQ, L_spec, &lastnz, &nEncodedCtxHm, sqTargetBits, &stopCtxHm, NULL); - IF (PeriodicityIndex >= 0) /* Mapping is used */ + /* Decide whether or not to revert mapping */ + Selector = sqBits - (sqBitsCtxHm + NumIndexBits); + + if (stopCtxHm == 0 && Selector > 0) { - /* Estimate non-mapped bitrate */ - stopCtxHm = 1; - move16(); - - sqBitsCtxHm = ACcontextMapping_encode2_estimate_no_mem_s17_LC(sqQ, - L_spec, - &lastnz, - &nEncodedCtxHm, - sqTargetBits, - &stopCtxHm, - NULL); - - /* Decide whether or not to revert mapping */ - Selector = sub(sqBits, add(sqBitsCtxHm, NumIndexBits)); - - test(); - IF (stopCtxHm == 0 && Selector > 0) /* Non-mapped is better */ - { - sqTargetBits = add(sqTargetBits, NumIndexBits); - ctxHmBits = sub(ctxHmBits, NumIndexBits); - prm_hm[0] = 0; - move16(); - *prm_lastnz = lastnz; - move16(); - PeriodicityIndex = -1; - move16(); - sqBits_noStop = sqBits = sqBitsCtxHm; - move16(); - move16(); - nEncoded = nEncodedCtxHm; - move16(); - stop = stopCtxHm; - move16(); - } + /* Non-mapped is better */ + sqTargetBits += NumIndexBits; + ctxHmBits -= NumIndexBits; + prm_hm[0] = 0; + *prm_lastnz = lastnz; + PeriodicityIndex = -1; + sqBits_noStop = sqBits = sqBitsCtxHm; + nEncoded = nEncodedCtxHm; + stop = stopCtxHm; } - ELSE /* Mapping is not used */ + } + else + { + /* Mapping is not used */ + /* Estimate mapped bitrate */ + stopCtxHm = 1; + + sqBitsCtxHm = ACcontextMapping_encode2_estimate_no_mem_s17_LC( sqQ, L_spec, &lastnzCtxHm, &nEncodedCtxHm, + sqTargetBits - NumIndexBits, &stopCtxHm, hm_cfg ); + + /* Decide whether or not to use mapping */ + Selector = sqBits - (sqBitsCtxHm + NumIndexBits); + + if (stopCtxHm == 0 && Selector > 0) { - /* Estimate mapped bitrate */ - stopCtxHm = 1; - move16(); - sqBitsCtxHm = ACcontextMapping_encode2_estimate_no_mem_s17_LC(sqQ, - L_spec, - &lastnzCtxHm, - &nEncodedCtxHm, - sub(sqTargetBits, NumIndexBits), - &stopCtxHm, - hm_cfg - ); - - /* Decide whether or not to use mapping */ - Selector = sub(sqBits, add(sqBitsCtxHm, NumIndexBits)); - - test(); - IF (stopCtxHm == 0 && Selector > 0) /* Mapped is better */ - { - sqTargetBits = sub(sqTargetBits, NumIndexBits); - ctxHmBits = add(ctxHmBits, NumIndexBits); - prm_hm[0] = 1; - move16(); - *prm_lastnz = lastnzCtxHm; - move16(); - PeriodicityIndex = prm_hm[1]; - move16(); - sqBits_noStop = sqBits = sqBitsCtxHm; - move16(); - move16(); - nEncoded = nEncodedCtxHm; - move16(); - stop = stopCtxHm; - move16(); - } + /* Mapped is better */ + sqTargetBits -= NumIndexBits; + ctxHmBits += NumIndexBits; + prm_hm[0] = 1; + *prm_lastnz = lastnzCtxHm; + PeriodicityIndex = prm_hm[1]; + sqBits_noStop = sqBits = sqBitsCtxHm; + nEncoded = nEncodedCtxHm; + stop = stopCtxHm; } } - - /* Limit low sqGain for avoiding saturation of the gain quantizer*/ - tmp1 = mult_r(shl(L_spec, 5), 26214/*128.f/NORM_MDCT_FACTOR Q15*/); - s = 15-5-7; - IF( L_spec >= 1024 ) - { - /*reduce precision for avoiding overflow*/ - tmp1 = mult_r(shl(L_spec, 4), 26214/*128.f/NORM_MDCT_FACTOR Q15*/); - s = 15-4-7; - } - tmp1 = ISqrt16(tmp1, &s); - - tmp2 = sub(sqGain_e, s); - IF (tmp2 >= 0) - { - BASOP_SATURATE_WARNING_OFF; - tmp2 = sub(sqGain, shr(tmp1, tmp2)); - BASOP_SATURATE_WARNING_ON; - } - ELSE - { - tmp2 = sub(shl(sqGain, s_max(-15, tmp2)), tmp1); - } - - IF (tmp2 < 0) - { - sqGain = tmp1; - sqGain_e = s; - - tcx_scalar_quantization( spectrum, *spectrum_e, - sqQ, - L_spec, - sqGain, sqGain_e, - tcx_cfg->sq_rounding, - st->memQuantZeros, - tcxonly - ); - - move16(); - stop=1; - - phm_cfg = NULL; - move16(); - if (PeriodicityIndex >= 0) - { - phm_cfg = hm_cfg; - move16(); - } - sqBits = ACcontextMapping_encode2_estimate_no_mem_s17_LC(sqQ, - L_spec, - prm_lastnz, - &nEncoded, - sqTargetBits, - &stop, - phm_cfg - ); - } - - /* Truncate spectrum (for CBR) */ - IF (stop != 0) - { - set16_fx(sqQ+nEncoded, 0, sub(L_spec, nEncoded)); - } - - /* Save quantized Values */ - tmp32 = L_deposit_l(0); - FOR(i=0; itcx_lpc_shaped_ari, - gainlpc, gainlpc_e, - L_frame - ); + sqGain = (float)sqrt((float)NORM_MDCT_FACTOR / (float)L_spec); - prm_target = sqQ; - move16(); - sqQ = prm_target + 1; - move16(); - signs = hm_cfg->indexBuffer; - move16(); + tcx_scalar_quantization( spectrum, sqQ, L_spec, sqGain, tcx_cfg->sq_rounding, st->memQuantZeros, tcxonly ); - LtpPitchLag = -1; - move16(); + stop=1; - IF (sub(st->tcxltp_pitch_int, st->L_frame_fx) < 0) - { - tmp32 = L_shl(L_mult0(st->L_frame_fx, st->pit_res_max), 1+kLtpHmFractionalResolution+1); - tmp1 = add(imult1616(st->tcxltp_pitch_int, st->pit_res_max), st->tcxltp_pitch_fr); - LtpPitchLag = div_l(tmp32, tmp1); - } - - tmp8 = 1; - move16(); - if (sub(st->last_core_fx, ACELP_CORE) == 0) - { - tmp8 = 0; - move16(); - } - - tcx_arith_encode_envelope( - spectrum, - spectrum_e, - signs, - L_frame, - L_spec, - st, - Aqind, - sqTargetBits, - sqQ, - tmp8, - prm_hm, /* HM parameter area */ - LtpPitchLag, - &sqBits, - &signaling_bits, - &nf_seed - , shr(st->bwidth_fx, 1) /* equivalent to: (st->bwidth_fx > WB)?1:0 */ - ); - - sqTargetBits = sub(sqTargetBits, signaling_bits); - *prm_target = sqTargetBits; - move16(); + sqBits = ACcontextMapping_encode2_estimate_no_mem_s17_LC( sqQ, L_spec, prm_lastnz, &nEncoded, sqTargetBits, &stop, PeriodicityIndex >= 0 ? hm_cfg : NULL); } - /*-----------------------------------------------------------* - * Compute optimal TCX gain. * - *-----------------------------------------------------------*/ - /* initialize LF deemphasis factors in xn_buf */ - set16_fx(xn_buf16, 0x4000, L_spec); - - IF (tcxonly == 0) + /* Truncate spectrum (for CBR) */ + if ( stop ) { - - AdaptLowFreqDeemph(spectrum, *spectrum_e, - st->tcx_lpc_shaped_ari, - gainlpc, gainlpc_e, - L_frame, - xn_buf16 /* LF deemphasis factors */ - ); - } - - tcx_get_gain(x_orig, x_orig_e, - spectrum, *spectrum_e, - L_spec, - &gain_tcx_opt, &gain_tcx_opt_e, - &ener, &ener_e); - - IF (gain_tcx_opt <= 0) - { - gain_tcx_opt = sqGain; - move16(); - gain_tcx_opt_e = sqGain_e; - move16(); - } - gain_tcx = gain_tcx_opt; - move16(); - gain_tcx_e = gain_tcx_opt_e; - move16(); - - /* Save gains for FAC and Residual Q*/ - - /*-----------------------------------------------------------* - * Quantize TCX gain * - *-----------------------------------------------------------*/ - - IF (L_sub(st->total_brate_fx, ACELP_13k20) >= 0 && st->rf_mode == 0 ) - { - QuantizeGain(L_spec, &gain_tcx, &gain_tcx_e, &prm[0]); - } - - - /*-----------------------------------------------------------* - * Residual Quantization * - *-----------------------------------------------------------*/ - - IF (tcx_cfg->resq) - { - - resQTargetBits = sub(sqTargetBits, sqBits); - - IF (st->tcx_lpc_shaped_ari) /* new arithmetic coder */ + for (i=nEncoded; isq_rounding, - xn_buf16 /* LF deemphasis factors */ ); - - /* Transmit zeros when there bits remain after RESQ */ - set16_fx(prm_resq+resQBits, 0, sub(resQTargetBits, resQBits)); - } - ELSE /* old arithmetic coder */ - { - move16(); - tmpP16 = NULL; - if (tcxonly == 0) - { - move16(); - tmpP16 = xn_buf16; - } - - resQBits = tcx_res_Q_gain(gain_tcx_opt, gain_tcx_opt_e, - &gain_tcx, &gain_tcx_e, - &sqQ[L_spec], - resQTargetBits); - - resQBits = tcx_res_Q_spec(x_orig, x_orig_e, - spectrum, *spectrum_e, - L_spec, - gain_tcx, gain_tcx_e, - &sqQ[L_spec], - resQTargetBits, - resQBits, - tcx_cfg->sq_rounding, - tmpP16 /* LF deemphasis factors */ ); - } - - - } - - - /*-----------------------------------------------------------* - * ALFE tcx only bitrates * - *-----------------------------------------------------------*/ - - IF (st->tcxonly != 0) - { - test(); - test(); - IF (st->tcxltp != 0 && (st->tcxltp_gain > 0) && fUseTns == 0) - { - - PsychAdaptLowFreqDeemph(spectrum, gainlpc, gainlpc_e, NULL); + sqQ[i] = 0; } } + /* Save quantized Values */ - /*-----------------------------------------------------------* - * TCX SNR for Analysis purposes * - *-----------------------------------------------------------*/ - + for(i=0; imeasuredBwRatio, L_frame), 1))); - - /*-----------------------------------------------------------* - * Estimate and quantize noise factor * - *-----------------------------------------------------------*/ - - IF (L_sub(st->total_brate_fx, HQ_96k) >= 0) - { - fac_ns = 0; - move16(); - prm[1] = 0; - move16(); - } - ELSE - { - /* noise filling start bin */ - i = shr(L_frame, 3); - IF (L_sub(st->total_brate_fx, ACELP_13k20) >= 0 && st->rf_mode == 0 ) - { - i = idiv1616U(L_frame, 6); - } - - IF (tcxonly) - { - tmp1 = 0; - move16(); - test(); - test(); - if ((tcx_cfg->ctx_hm != 0) && (st->last_core_fx != ACELP_CORE) && (prm_hm[0] != 0)) - { - tmp1 = 10240/*0.3125f Q15*/; - move16(); - } - noiseTransWidth = HOLE_SIZE_FROM_LTP(s_max(st->tcxltp_gain, tmp1)); - - if (sub(L_frame, shr(st->L_frame_fx, 1)) == 0) - { - /* minimum transition for noise filling in TCX-10 */ - noiseTransWidth = 3; - move16(); - } - } - - tcx_noise_factor( x_orig, x_orig_e, - spectrum, - i, - maxNfCalcBw, - noiseTransWidth, - L_frame, - gain_tcx, gain_tcx_e, - st->noiseTiltFactor, - &fac_ns, &prm[NOISE_FILL_RANGES] ); - - /* hysteresis for very tonal passages (more stationary noise filling level) */ - - IF (sub(prm[NOISE_FILL_RANGES], 1) == 0) - { - st->noiseLevelMemory = add(1, abs_s(st->noiseLevelMemory)); /* update counter */ - } - ELSE { - test(); - IF ((sub(prm[NOISE_FILL_RANGES], 2) == 0) && - (sub(abs_s(st->noiseLevelMemory), 5) > 0)) - { - /* reduce noise filling level by one step */ - prm[NOISE_FILL_RANGES] = 1; - move16(); - fac_ns = shr(0x6000, NBITS_NOISE_FILL_LEVEL); - - /* signal that noise level is changed by inverting sign of level memory */ - tmp1 = 5; - move16(); - if (st->noiseLevelMemory >= 0) - { - tmp1 = sub(-1, st->noiseLevelMemory); - } - st->noiseLevelMemory = tmp1; - } - ELSE { - /* reset memory since level is too different */ - st->noiseLevelMemory = 0; - move16(); - } - } - - } /* bitrate */ + spectrum[i] = (float)sqQ[i]; + /* noise filling seed */ + nf_seed += (short)(abs(sqQ[i]) * i * 2); } - /* Free encoder specific stack to use it below for the internal TCX decoder. */ } + else + { + /* low rates: envelope based arithmetic coder */ + + AdaptLowFreqEmph( spectrum, NULL, 0.f, 1, gainlpc, L_frame ); + + prm_target = sqQ; + sqQ = prm_target + 1; + signs = hm_cfg->indexBuffer; + + LtpPitchLag = ((st->tcxltp_pitch_int < st->L_frame) + ? ((2 * st->L_frame * st->pit_res_max) << kLtpHmFractionalResolution) / (st->tcxltp_pitch_int * st->pit_res_max + st->tcxltp_pitch_fr): -1); + + tcx_arith_encode_envelope( spectrum, signs, L_frame, L_spec, st, Aqind, sqTargetBits, sqQ, st->last_core != ACELP_CORE, + prm_hm, /* HM parameter area */ LtpPitchLag, &sqBits, &signaling_bits ,(st->bwidth > WB)?1:0 ); + + sqTargetBits -= signaling_bits; + *prm_target = sqTargetBits; + + /* Noise filling seed */ + for (i=0; itcx_lpc_shaped_ari, gainlpc, L_frame, xn_buf /* LF deemphasis factors */ ); + } + + gain_tcx_opt = get_gain(x_orig, spectrum, L_spec, &ener); + + if (gain_tcx_opt <= 0.0f) + { + gain_tcx_opt = sqGain; + } + gain_tcx = gain_tcx_opt; + + /*-----------------------------------------------------------* + * Quantize TCX gain * + *-----------------------------------------------------------*/ + + /* gain quantization here in case of VBR unvoiced coding; fixes problems of uninitialized global gain values */ + if (st->total_brate >= ACELP_13k20 && !st->rf_mode) + { + QuantizeGain(L_spec, &gain_tcx, &prm[0]); + } + + /*-----------------------------------------------------------* + * Residual Quantization * + *-----------------------------------------------------------*/ + + if (tcx_cfg->resq) + { + resQTargetBits = sqTargetBits-sqBits; + + if (st->tcx_lpc_shaped_ari) + { + /* envelope based arithmetic coder */ + int *prm_resq; + + prm_resq = sqQ + sqTargetBits - resQTargetBits; + + resQBits = tcx_ari_res_Q_spec( x_orig, signs, spectrum, L_spec, gain_tcx, prm_resq, resQTargetBits, + resQBits, tcx_cfg->sq_rounding, xn_buf /* LF deemphasis factors */ ); + + /* Transmit zeros when there bits remain after RESQ */ + for (i=resQBits; isq_rounding, tcxonly ? NULL : xn_buf /* LF deemphasis factors */ ); + } + + } + + /*-----------------------------------------------------------* + * ALFE tcx only bitrates * + *-----------------------------------------------------------*/ + + if (st->tcxonly) + { + if (st->tcxltp && (st->tcxltp_gain > 0.0f) && !fUseTns) + { + PsychAdaptLowFreqDeemph( spectrum, gainlpc, NULL ); + } + } + + /*-----------------------------------------------------------* + * TCX SNR for Analysis purposes * + *-----------------------------------------------------------*/ + + + + + maxNfCalcBw = min(noiseFillingSize, (int)(st->measuredBwRatio * (float)L_frame + 0.5f)); + + /*-----------------------------------------------------------* + * Estimate and quantize noise factor * + *-----------------------------------------------------------*/ + + if (st->total_brate >= HQ_96k) + { + fac_ns = 0.0f; + prm[1] = 0; + } + else + { + i = L_frame / ((st->total_brate >= ACELP_13k20 && !st->rf_mode) ? 6 : 8); /* noise filling start bin*/ + + if (tcxonly) + { + noiseTransWidth = HOLE_SIZE_FROM_LTP(max(st->tcxltp_gain,(tcx_cfg->ctx_hm && st->last_core != 0) ? 0.3125f*prm_hm[0] : 0)); + + if (L_frame == st->L_frame >> 1) + { + noiseTransWidth = 3; /* minimum transition for noise filling in TCX-10 */ + } + } + + tcx_noise_factor( x_orig, spectrum, i, maxNfCalcBw, noiseTransWidth, L_frame, + gain_tcx, st->noiseTiltFactor, &fac_ns, &prm[NOISE_FILL_RANGES] ); + + /* hysteresis for very tonal passages (more stationary noise filling level) */ + + if (prm[1] == 1) + { + st->noiseLevelMemory = 1 + abs(st->noiseLevelMemory); /* update counter */ + } + else + { + if ((prm[1] == 2) && (abs(st->noiseLevelMemory) > 5)) + { + prm[1] = 1; /* reduce noise filling level by one step */ + fac_ns = 0.75f / (1<noiseLevelMemory = (st->noiseLevelMemory < 0) ? 5 : -1 - st->noiseLevelMemory; + } + else + { + st->noiseLevelMemory = 0; /* reset memory since level is too different */ + } + } + } /* bitrate */ + /*-----------------------------------------------------------* * Internal TCX decoder * *-----------------------------------------------------------*/ + + /*-----------------------------------------------------------* + * Noise Filling. * + *-----------------------------------------------------------*/ + + /* Replication of ACELP formant enhancement for low rates */ + if ( st->total_brate < ACELP_13k20 || st->rf_mode ) { - /* Overlay of a 16-bit buffer xn_buf16 with a 32-bit buffer xn_buf32 */ - /* The size is determined by the requirements of the 16-bit buffer. */ - Word32 xn_buf32[(L_MDCT_OVLP_MAX+L_FRAME_PLUS+L_MDCT_OVLP_MAX)/2]; - Word16 *xn_buf16 = (Word16*)xn_buf32; + tcxFormantEnhancement(xn_buf, gainlpc, spectrum, L_frame); + } - /*Enable internal TCX decoder to run always to update LPD memory for rate switching */ + if (fac_ns > 0.0f) + { + i = tcxGetNoiseFillingTilt( A, L_frame, (st->total_brate >= ACELP_13k20 && !st->rf_mode), &st->noiseTiltFactor); - IF (tcxonly == 0) + tcx_noise_filling( spectrum, nf_seed, i, noiseFillingSize, noiseTransWidth, L_frame, st->noiseTiltFactor, fac_ns, NULL ); + } + + if (st->total_brate < ACELP_13k20 || st->rf_mode) + { + /* partially recompute global gain (energy part), taking noise filling and formant enhancement into account */ + gain_tcx_opt = 1e-6f; + for (i = 0; i < L_spec; i++) { + gain_tcx_opt += spectrum[i] * spectrum[i]; } + gain_tcx *= (float)sqrt(ener / gain_tcx_opt); + QuantizeGain(L_spec, &gain_tcx, &prm[0]); + } - /*-----------------------------------------------------------* - * Noise Filling. * - *-----------------------------------------------------------*/ + /*end of noise filling*/ - /* Replication of ACELP formant enhancement for low rates */ - IF ( L_sub(st->total_brate_fx, ACELP_13k20) < 0 || st->rf_mode != 0) + /*-----------------------------------------------------------* + * Noise shaping in frequency domain (1/Wz) * + *-----------------------------------------------------------*/ + + /* LPC gains already available */ + mdct_noiseShaping( spectrum, L_frame, gainlpc ); + + /*-----------------------------------------------------------* + * Apply gain * + *-----------------------------------------------------------*/ + + if( st->tcx_cfg.coder_type == INACTIVE ) + { + + gain_tcx *= tcx_cfg->na_scale; + } + + v_multc( spectrum, gain_tcx, spectrum, L_spec); + + stop = tcx_cfg->tcx_last_overlap_mode; /* backup last TCX overlap mode */ + + + if ((L_frame == st->L_frame >> 1) && tcxonly) + { + int L = L_frame; + + if ((tcx_cfg->fIsTNSAllowed && fUseTns != 0) || (L_spec > L_frame)) L = L_spec; + + tcxInvertWindowGrouping( tcx_cfg, xn_buf, spectrum, L, fUseTns, st->last_core, stop, frame_cnt, 0); + } + + /*-----------------------------------------------------------* + * Temporal Noise Shaping Synthesis * + *-----------------------------------------------------------*/ + + if (tcx_cfg->fIsTNSAllowed) + { + SetTnsConfig(tcx_cfg, L_frame_glob == st->L_frame, (st->last_core == 0) && (frame_cnt == 0)); + + /* Apply TNS to get the reconstructed signal */ + if (fUseTns != 0) { - tcxFormantEnhancement(xn_buf16, gainlpc, gainlpc_e, spectrum, spectrum_e, L_frame, L_spec); - } + ApplyTnsFilter(tcx_cfg->pCurrentTnsConfig, pTnsData, spectrum, 0); - IF (fac_ns > 0) - { - tmp1 = 0; - move16(); - if ( L_sub(st->total_brate_fx, ACELP_13k20) >= 0 && st->rf_mode == 0) + if ((L_frame == st->L_frame >> 1) && (tcxonly)) { - tmp1 = 1; - move16(); - } - - i = tcxGetNoiseFillingTilt(A, - M, - L_frame, - tmp1, - &st->noiseTiltFactor); - - tcx_noise_filling(spectrum, *spectrum_e, - nf_seed /* seed */, - i, - noiseFillingSize, - noiseTransWidth, - L_frame, - st->noiseTiltFactor, - fac_ns, - NULL - ); - } - - IF (L_sub(st->total_brate_fx, ACELP_13k20) < 0 || st->rf_mode != 0) - { - /* partially recompute global gain (energy part), taking noise filling and formant enhancement into account */ - s = sub(getScaleFactor32(spectrum, L_spec), 4); - tmp32 = L_deposit_l(1); - - FOR (i = 0; i < L_spec; i++) - { - tmp1 = round_fx(L_shl(spectrum[i], s)); - tmp32 = L_mac0(tmp32, tmp1, tmp1); - } - - tmp1 = BASOP_Util_Divide3232_Scale(ener, tmp32, &tmp2); - tmp2 = add(tmp2, sub(ener_e, add(shl(sub(*spectrum_e, s), 1), 1))); - tmp1 = Sqrt16(tmp1, &tmp2); - - gain_tcx = mult(gain_tcx, tmp1); - gain_tcx_e = add(gain_tcx_e, tmp2); - - QuantizeGain(L_spec, &gain_tcx, &gain_tcx_e, &prm[0]); - } - - /*end of noise filling*/ - - /*-----------------------------------------------------------* - * Noise shaping in frequency domain (1/Wz) * - *-----------------------------------------------------------*/ - - /* LPC gains already available */ - mdct_shaping(spectrum, L_frame, gainlpc, gainlpc_e); - - /*-----------------------------------------------------------* - * Apply gain * - *-----------------------------------------------------------*/ - IF (sub(st->tcx_cfg.coder_type, INACTIVE) == 0 ) - { - gain_tcx = mult_r(gain_tcx, tcx_cfg->na_scale); - } - - FOR (i = 0; i < L_spec; i++) - { - spectrum[i] = Mpy_32_16_1(spectrum[i], gain_tcx); - move32(); - } - *spectrum_e = add(*spectrum_e, gain_tcx_e); - move16(); - - stop = tcx_cfg->tcx_last_overlap_mode; /* backup last TCX overlap mode */ move16(); - - test(); - IF ((sub(L_frame, shr(st->L_frame_fx, 1)) == 0) && (tcxonly != 0)) - { - Word16 L = L_frame; - move16(); - - test(); - test(); - if (((tcx_cfg->fIsTNSAllowed != 0) && (fUseTns != 0)) || (sub(L_spec, L_frame) > 0)) - { - L = L_spec; - move16(); - } - - tcxInvertWindowGrouping(tcx_cfg, - xn_buf32, - spectrum, - L, - fUseTns, - st->last_core_fx, - stop, - frame_cnt, - 0); - } - - /*-----------------------------------------------------------* - * Temporal Noise Shaping Synthesis * - *-----------------------------------------------------------*/ - - IF (tcx_cfg->fIsTNSAllowed != 0) - { - test(); - test(); - test(); - SetTnsConfig(tcx_cfg, sub(L_frame_glob, st->L_frame_fx) == 0, (st->last_core_fx == ACELP_CORE) && (frame_cnt == 0)); - - /* Apply TNS to get the reconstructed signal */ - IF (fUseTns != 0) - { - ApplyTnsFilter(tcx_cfg->pCurrentTnsConfig, pTnsData, spectrum, 0); - - test(); - IF ((sub(L_frame, shr(st->L_frame_fx, 1)) == 0) && (tcxonly != 0)) + if ((tcx_cfg->tcx_last_overlap_mode != FULL_OVERLAP) || + ((tcx_cfg->tcx_curr_overlap_mode == FULL_OVERLAP) && (frame_cnt == 0) && (stop == 0)) + ) { - test(); - test(); - test(); - IF ( (tcx_cfg->tcx_last_overlap_mode != FULL_OVERLAP) || - ((tcx_cfg->tcx_curr_overlap_mode == FULL_OVERLAP) && (frame_cnt == 0) && (stop == 0)) ) + const int L_win = L_spec >> 1; + + /* undo rearrangement of LF sub-window lines for TNS synthesis filter */ + if (L_frame > L_spec) { - tmp1 = shr(L_spec, 1); - /* undo rearrangement of LF sub-window lines for TNS synthesis filter */ - assert(L_frame <= L_spec); - Copy32(spectrum+8, xn_buf32, 8); - Copy32(spectrum+16, spectrum+8, sub(tmp1,8)); - Copy32(xn_buf32, spectrum+tmp1, 8); + assert(0); + } + else + { + mvr2r(spectrum+8, xn_buf, L_win); + mvr2r(xn_buf, spectrum+L_win, 8); + mvr2r(xn_buf+8, spectrum+8, L_win-8); } } } } + } + /*-----------------------------------------------------------* + * Compute inverse MDCT of spectrum[]. * + *-----------------------------------------------------------*/ + + if ((L_frame == st->L_frame >> 1) && (tcxonly)) + { + if (tcx_cfg->tcx_last_overlap_mode != FULL_OVERLAP) { - /* normalize spectrum to minimize IMDCT noise */ - s = getScaleFactor32(spectrum, L_frame); - FOR (i = 0; i < L_frame; i++) + /* minimum or half overlap, two transforms, grouping into one window */ + float win[(L_FRAME_PLUS+L_MDCT_OVLP_MAX)/2]; + const int L_win = L_frame >> 1; + const int L_spec_TCX5 = max(L_frame, L_spec) >> 1; + const int L_ola = (tcx_cfg->tcx_last_overlap_mode == MIN_OVERLAP) ? tcx_cfg->tcx_mdct_window_min_length : tcx_cfg->tcx_mdct_window_half_length; + int w; + + set_f( win, 0, (L_FRAME_PLUS+L_MDCT_OVLP_MAX)/2 ); + set_zero(xn_buf, tcx_offset+(L_ola>>1)); /* zero left end of buffer */ + + for (w = 0; w < 2; w++) { - spectrum[i] = L_shl(spectrum[i], s); - move32(); + if (tcx_cfg->tcx_last_overlap_mode == MIN_OVERLAP) + { + TCX_MDCT_Inverse(spectrum+w*L_spec_TCX5, win, L_ola, L_win-L_ola, L_ola); + } + else + { + TCX_MDCT_Inverse(spectrum+w*L_spec_TCX5, win, L_ola, L_win-L_ola, L_ola); + } + + tcx_windowing_synthesis_current_frame( win, tcx_cfg->tcx_aldo_window_2, tcx_cfg->tcx_mdct_window_half, tcx_cfg->tcx_mdct_window_minimum, + L_ola, tcx_cfg->tcx_mdct_window_half_length, tcx_cfg->tcx_mdct_window_min_length, w==0 && st->last_core==0, + (w > 0) || (w == 0 && stop == 2) ? MIN_OVERLAP : tcx_cfg->tcx_last_overlap_mode, LPDmem->acelp_zir, + st->LPDmem.Txnq, NULL, Aq_old, tcx_cfg->tcx_mdct_window_trans, L_win, + tcx_offset<0?-tcx_offset:0, + (w > 0) ? 1 : st->last_core, 0, 0 ); + + if (w > 0) + { + tcx_windowing_synthesis_past_frame( xn_buf+tcx_offset-(L_ola>>1)+w*L_win, tcx_cfg->tcx_aldo_window_1_trunc, tcx_cfg->tcx_mdct_window_half, + tcx_cfg->tcx_mdct_window_minimum, L_ola, tcx_cfg->tcx_mdct_window_half_length, tcx_cfg->tcx_mdct_window_min_length, 2 ); + } + + /* add part of current sub-window overlapping with previous window */ + v_add(win, xn_buf+tcx_offset-(L_ola>>1)+w*L_win, xn_buf+tcx_offset-(L_ola>>1)+w*L_win, L_ola); + + /* copy new sub-window region not overlapping with previous window */ + mvr2r(win+L_ola, xn_buf+tcx_offset+(L_ola>>1)+w*L_win, L_win); } - *spectrum_e = sub(*spectrum_e, s); + + /* To assure that no garbage values are copied to LPDmem->Txnq */ + set_zero(xn_buf+L_frame+tcx_offset+(L_ola>>1), overlap-tcx_offset-(L_ola>>1)); + } + else if ((frame_cnt == 0) && (tcx_cfg->tcx_curr_overlap_mode == FULL_OVERLAP)) + { + /* special overlap attempt, two transforms, grouping into one window */ + float win[(L_FRAME_PLUS+L_MDCT_OVLP_MAX)/2]; + const int L_win = L_frame >> 1; + const int L_spec_TCX5 = max(L_frame, L_spec) >> 1; + const int L_ola = tcx_cfg->tcx_mdct_window_min_length; + int w; + + set_f( win, 0, (L_FRAME_PLUS+L_MDCT_OVLP_MAX)/2 ); + + /* Resize overlap (affect only asymmetric window)*/ + overlap = st->tcx_cfg.tcx_mdct_window_delay; + + /* 1st TCX-5 window, special MDCT with minimum overlap on right side */ + TCX_MDCT_Inverse(spectrum, win+L_win, 0, L_win-(L_ola>>1), L_ola); + + /* copy new sub-window region not overlapping with previous window */ + mvr2r(win+L_win, xn_buf+(overlap>>1), L_win+(L_ola>>1)); + + /* 2nd TCX-5 window, regular MDCT with minimum overlap on both sides */ + TCX_MDCT_Inverse(spectrum+L_spec_TCX5, win, L_ola, L_win-L_ola, L_ola); + + tcx_windowing_synthesis_current_frame( win, tcx_cfg->tcx_aldo_window_2, tcx_cfg->tcx_mdct_window_half, tcx_cfg->tcx_mdct_window_minimum, + L_ola, tcx_cfg->tcx_mdct_window_half_length, tcx_cfg->tcx_mdct_window_min_length, 0, /* left_rect */ + 2, /* left_mode */ LPDmem->acelp_zir, st->LPDmem.Txnq, NULL, Aq_old, + tcx_cfg->tcx_mdct_window_trans, L_win, tcx_offset<0?-tcx_offset:0, + 1, /* not st->last_core */ 0 ,0 ); + + tcx_windowing_synthesis_past_frame( xn_buf+(overlap>>1)+L_win-(L_ola>>1), tcx_cfg->tcx_aldo_window_1_trunc, tcx_cfg->tcx_mdct_window_half, + tcx_cfg->tcx_mdct_window_minimum, L_ola, tcx_cfg->tcx_mdct_window_half_length, tcx_cfg->tcx_mdct_window_min_length, 2 ); + + /* add part of current sub-window overlapping with previous window */ + v_add(win, xn_buf+(overlap>>1)+L_win-(L_ola>>1), xn_buf+(overlap>>1)+L_win-(L_ola>>1), L_ola); + + /* copy new sub-window region not overlapping with previous window */ + mvr2r(win+L_ola, xn_buf+(overlap>>1)+L_win+(L_ola>>1), L_win); + + /* extra folding-out on left side of win, for perfect reconstruction */ + for (w = (overlap>>1); w < overlap; w++) + { + xn_buf[overlap-1-w] = -1.0f * xn_buf[w]; + } + + tcx_windowing_synthesis_current_frame( xn_buf, tcx_cfg->tcx_aldo_window_2, tcx_cfg->tcx_mdct_window_half, tcx_cfg->tcx_mdct_window_minimum, + overlap, /*tcx_cfg->tcx_mdct_window_length*/ tcx_cfg->tcx_mdct_window_half_length, tcx_cfg->tcx_mdct_window_min_length, + st->last_core == ACELP_CORE, 0, /* left_mode */ LPDmem->acelp_zir, st->LPDmem.Txnq, NULL, + Aq_old, tcx_cfg->tcx_mdct_window_trans, L_win, tcx_offset<0?-tcx_offset:0, + st->last_core, 0, 0 ); + } + else + { + /* default, i.e. maximum overlap, single transform, no grouping */ + TCX_MDCT_Inverse(spectrum, xn_buf, overlap, L_frame-overlap, overlap); + + tcx_windowing_synthesis_current_frame( xn_buf, tcx_cfg->tcx_aldo_window_2, tcx_cfg->tcx_mdct_window_half, tcx_cfg->tcx_mdct_window_minimum, + overlap, /*tcx_cfg->tcx_mdct_window_length*/ tcx_cfg->tcx_mdct_window_half_length, tcx_cfg->tcx_mdct_window_min_length, + st->last_core == ACELP_CORE, (frame_cnt > 0) && (stop == 0) && (st->last_core!=0) ? 2 : stop, LPDmem->acelp_zir, + st->LPDmem.Txnq, NULL, Aq_old, tcx_cfg->tcx_mdct_window_trans, L_frame_glob >> 1, + tcx_offset<0?-tcx_offset:0, + st->last_core, 0, 0 ); + + } /* tcx_last_overlap_mode != FULL_OVERLAP */ + } + else + { + /* frame is TCX-20 or not TCX-only */ + + if (st->tcx_cfg.tcx_last_overlap_mode != TRANSITION_OVERLAP) + { + float tmp[L_FRAME_PLUS]; + + edct(spectrum, xn_buf+overlap/2+nz, L_frame); + v_multc( xn_buf+overlap/2+nz, (float)sqrt((float)L_frame / NORM_MDCT_FACTOR), tmp, L_frame); + + window_ola( tmp, xn_buf, st->old_out, L_frame, tcx_cfg->tcx_last_overlap_mode, tcx_cfg->tcx_curr_overlap_mode, 0, 0, NULL ); + aldo = 1; + } + else + { + TCX_MDCT_Inverse(spectrum, xn_buf, overlap, L_frame-overlap, overlap); /*-----------------------------------------------------------* - * Compute inverse MDCT of spectrum[]. * - *-----------------------------------------------------------*/ - test(); - IF ((sub(L_frame, shr(st->L_frame_fx, 1)) == 0) && (tcxonly != 0)) - { - IF (tcx_cfg->tcx_last_overlap_mode != FULL_OVERLAP) - { - Word16 win[(L_FRAME_PLUS+L_MDCT_OVLP_MAX)/2]; - Word16 L_win, L_spec_TCX5, L_ola, w; - - /* minimum or half overlap, two transforms, grouping into one window */ - L_win = shr(L_frame, 1); - L_spec_TCX5 = shr(s_max(L_frame, L_spec), 1); - L_ola = tcx_cfg->tcx_mdct_window_half_length; - move16(); - if ( sub(tcx_cfg->tcx_last_overlap_mode, MIN_OVERLAP) == 0 ) - { - L_ola = tcx_cfg->tcx_mdct_window_min_length; - move16(); - } - - set16_fx(win, 0, (L_FRAME_PLUS+L_MDCT_OVLP_MAX)/2); - set16_fx(xn_buf16, 0, add(tcx_offset, shr(L_ola, 1))); /* zero left end of buffer */ - - FOR (w = 0; w < 2; w++) - { - - IF (sub(tcx_cfg->tcx_last_overlap_mode, MIN_OVERLAP) == 0) - { - TCX_MDCT_Inverse(spectrum + L_mult0(w, L_spec_TCX5), sub(*spectrum_e, TCX_IMDCT_SCALE+TCX_IMDCT_HEADROOM), - win, - L_ola, sub(L_win, L_ola), L_ola); - } - ELSE - { - TCX_MDCT_Inverse(spectrum + L_mult0(w, L_spec_TCX5), sub(*spectrum_e, TCX_IMDCT_SCALE+TCX_IMDCT_HEADROOM), - win, - L_ola, sub(L_win, L_ola), L_ola); - } - - tmp1 = tcx_cfg->tcx_last_overlap_mode; - move16(); - test(); - test(); - if ((w > 0) || ((w == 0) && (sub(stop, 2) == 0))) - { - tmp1 = MIN_OVERLAP; - move16(); - } - - tmp2 = 0; - move16(); - test(); - if ((w == 0) && (st->last_core_fx == ACELP_CORE)) - { - tmp2 = 1; - move16(); - } - - tmp3 = st->last_core_fx; - move16(); - if (w > 0) - { - tmp3 = 1; - move16(); - } - - tmp4 = 0; - move16(); - if (tcx_offset < 0) - { - tmp4 = negate(tcx_offset); - } - - tcx_windowing_synthesis_current_frame(win, - tcx_cfg->tcx_aldo_window_2, - tcx_cfg->tcx_mdct_window_half, - tcx_cfg->tcx_mdct_window_minimum, - L_ola, - tcx_cfg->tcx_mdct_window_half_length, - tcx_cfg->tcx_mdct_window_min_length, - tmp2, - tmp1, - LPDmem->acelp_zir, - st->LPDmem.Txnq, - NULL, - Aq_old, - tcx_cfg->tcx_mdct_window_trans, - L_win, - tmp4, - tmp3, - 0, - 0 - ); - - tmp1 = add(tcx_offset, imult1616(w, L_win)); - move16(); - tmpP16 = xn_buf16 + sub(tmp1, shr(L_ola, 1)); - - IF (w > 0) - { - tcx_windowing_synthesis_past_frame(tmpP16, - tcx_cfg->tcx_aldo_window_1_trunc, - tcx_cfg->tcx_mdct_window_half, - tcx_cfg->tcx_mdct_window_minimum, - L_ola, - tcx_cfg->tcx_mdct_window_half_length, - tcx_cfg->tcx_mdct_window_min_length, - 2 - ); - } - /* add part of current sub-window overlapping with previous window */ - FOR (i = 0; i < L_ola; i++) - { - tmpP16[i] = add(tmpP16[i], win[i]); - move16(); - } - /* copy new sub-window region not overlapping with previous window */ - Copy(win + L_ola, xn_buf16 + add(tmp1, shr(L_ola, 1)), L_win); - } - /* To assure that no garbage values are copied to LPDmem->Txnq */ - set16_fx(xn_buf16 + add(add(L_frame, tcx_offset), shr(L_ola, 1)), - 0, sub(sub(overlap, tcx_offset), shr(L_ola, 1))); - - - } - ELSE IF ( s_and(frame_cnt == 0, (tcx_cfg->tcx_curr_overlap_mode == FULL_OVERLAP)) ) - { - /* special overlap attempt, two transforms, grouping into one window */ - Word16 win[(L_FRAME_PLUS+L_MDCT_OVLP_MAX)/2]; - Word16 L_win, L_spec_TCX5, L_ola, w; - - L_win = shr(L_frame, 1); - L_spec_TCX5 = shr(s_max(L_frame, L_spec), 1); - L_ola = tcx_cfg->tcx_mdct_window_min_length; - move16(); - - set16_fx(win, 0, (L_FRAME_PLUS+L_MDCT_OVLP_MAX)/2); - - /* Resize overlap (affect only asymmetric window)*/ - overlap = st->tcx_cfg.tcx_mdct_window_delay; - /* 1st TCX-5 window, special MDCT with minimum overlap on right side */ - TCX_MDCT_Inverse(spectrum, sub(*spectrum_e, TCX_IMDCT_SCALE+TCX_IMDCT_HEADROOM), - win + L_win, - 0, sub(L_win, shr(L_ola, 1)), L_ola); - - /* copy new sub-window region not overlapping with previous window */ - Copy(win+L_win, xn_buf16+shr(overlap, 1), add(L_win, shr(L_ola, 1))); - - /* 2nd TCX-5 window, regular MDCT with minimum overlap on both sides */ - - TCX_MDCT_Inverse(spectrum + L_spec_TCX5, sub(*spectrum_e, TCX_IMDCT_SCALE+TCX_IMDCT_HEADROOM), - win, - L_ola, sub(L_win, L_ola), L_ola); - - tmp4 = 0; - move16(); - if (tcx_offset <0) - { - tmp4 = negate(tcx_offset); - } - tcx_windowing_synthesis_current_frame(win, - tcx_cfg->tcx_aldo_window_2, - tcx_cfg->tcx_mdct_window_half, - tcx_cfg->tcx_mdct_window_minimum, - L_ola, - tcx_cfg->tcx_mdct_window_half_length, - tcx_cfg->tcx_mdct_window_min_length, - 0, /* left_rect */ - 2, /* left_mode */ - LPDmem->acelp_zir, - st->LPDmem.Txnq, - NULL, - Aq_old, - tcx_cfg->tcx_mdct_window_trans, - L_win, - tmp4, - 1, /* not LPDmem->mode */ - 0, - 0 - ); - - - move16(); - tmpP16 = xn_buf16 + add(sub(L_win, shr(L_ola, 1)), shr(overlap,1)); - - tcx_windowing_synthesis_past_frame(tmpP16, - tcx_cfg->tcx_aldo_window_1_trunc, - tcx_cfg->tcx_mdct_window_half, - tcx_cfg->tcx_mdct_window_minimum, - L_ola, - tcx_cfg->tcx_mdct_window_half_length, - tcx_cfg->tcx_mdct_window_min_length, - 2 - ); - - /* add part of current sub-window overlapping with previous window */ - FOR (i = 0; i < L_ola; i++) - { - tmpP16[i] = add(tmpP16[i], win[i]); - move16(); - } - - /* copy new sub-window region not overlapping with previous window */ - Copy(win + L_ola, - xn_buf16 + add(add(shr(overlap,1), shr(L_ola, 1)), L_win), - L_win); - - /* extra folding-out on left side of win, for perfect reconstruction */ - FOR (w = shr(overlap,1); w < overlap; w++) - { - xn_buf16[overlap-1-w] = negate(xn_buf16[w]); - move16(); - } - - tmp4 = 0; - move16(); - if (tcx_offset < 0) - { - tmp4 = negate(tcx_offset); - } - tcx_windowing_synthesis_current_frame(xn_buf16, - tcx_cfg->tcx_aldo_window_2, - tcx_cfg->tcx_mdct_window_half, - tcx_cfg->tcx_mdct_window_minimum, - overlap, - tcx_cfg->tcx_mdct_window_half_length, - tcx_cfg->tcx_mdct_window_min_length, - st->last_core_fx==ACELP_CORE, - 0, - LPDmem->acelp_zir, - st->LPDmem.Txnq, - NULL, - Aq_old, - tcx_cfg->tcx_mdct_window_trans, - L_win, - tmp4, - st->last_core_fx, - 0, - 0 - ); - } - ELSE /* default, i.e. maximum overlap, single transform, no grouping */ - { - - TCX_MDCT_Inverse(spectrum, sub(*spectrum_e, TCX_IMDCT_SCALE+TCX_IMDCT_HEADROOM), - xn_buf16, - overlap, sub(L_frame, overlap), overlap); - - tmp1 = stop; - move16(); - test(); - test(); - if ((frame_cnt > 0) && (stop == 0) && (st->last_core_fx != ACELP_CORE)) - { - tmp1 = 2; - move16(); - } - - tmp4 = 0; - move16(); - if (tcx_offset <0) - { - tmp4 = negate(tcx_offset); - } - tcx_windowing_synthesis_current_frame(xn_buf16, - tcx_cfg->tcx_aldo_window_2, - tcx_cfg->tcx_mdct_window_half, - tcx_cfg->tcx_mdct_window_minimum, - overlap, /*tcx_cfg->tcx_mdct_window_length*/ - tcx_cfg->tcx_mdct_window_half_length, - tcx_cfg->tcx_mdct_window_min_length, - st->last_core_fx==ACELP_CORE, - tmp1, - LPDmem->acelp_zir, - st->LPDmem.Txnq, - NULL, - Aq_old, - tcx_cfg->tcx_mdct_window_trans, - shr(L_frame_glob, 1), - tmp4, - st->last_core_fx, - 0, - 0 - ); - - } /* tcx_last_overlap_mode > 0 */ - - } - ELSE /* frame is TCX-20 or not TCX-only */ - { - IF (sub(st->tcx_cfg.tcx_last_overlap_mode, TRANSITION_OVERLAP) != 0) - { - Word32 tmp_buf[L_FRAME_PLUS]; - Word16 Q; - - /* DCT */ - Q = sub(31, *spectrum_e); - edct_fx(spectrum, tmp_buf, L_frame, &Q); - - /* scale by sqrt(L / NORM_MDCT_FACTOR) */ - tmp1 = mult_r(shl(L_frame, 4), 26214/*128.f / NORM_MDCT_FACTOR Q15*/); /* 4Q11 */ - tmp2 = 4; - move16(); - tmp1 = Sqrt16(tmp1, &tmp2); - - FOR (i = 0; i < L_frame; i++) - { - tmp_buf[i] = Mpy_32_16_1(tmp_buf[i], tmp1); - move32(); - } - Q = sub(Q, tmp2); - - - window_ola_fx(tmp_buf, - xn_buf16, - &Q, - st->old_out_fx, - &st->Q_old_out, - L_frame, - tcx_cfg->tcx_last_overlap_mode, - tcx_cfg->tcx_curr_overlap_mode, - 0, - 0, - NULL); - - /* scale output */ - FOR (i = 0; i < L_frame; i++) - { - xn_buf16[i] = shr(xn_buf16[i], Q); - move16(); - } - - aldo = 1; - move16(); - } - ELSE - { - - TCX_MDCT_Inverse(spectrum, sub(*spectrum_e, TCX_IMDCT_SCALE+TCX_IMDCT_HEADROOM), - xn_buf16, - overlap, sub(L_frame, overlap), overlap); - - /*-----------------------------------------------------------* - * Windowing, overlap and add * - *-----------------------------------------------------------*/ - - /* Window current frame */ - tmp4 = 0; - move16(); - if (tcx_offset<0) - { - tmp4 = negate(tcx_offset); - } - tcx_windowing_synthesis_current_frame(xn_buf16, - tcx_cfg->tcx_aldo_window_2, - tcx_cfg->tcx_mdct_window_half, - tcx_cfg->tcx_mdct_window_minimum, - overlap, /*tcx_cfg->tcx_mdct_window_length*/ - tcx_cfg->tcx_mdct_window_half_length, - tcx_cfg->tcx_mdct_window_min_length, - st->last_core_fx==ACELP_CORE, - tcx_cfg->tcx_last_overlap_mode, /*left mode*/ - LPDmem->acelp_zir, - st->LPDmem.Txnq, - NULL, - Aq_old, - tcx_cfg->tcx_mdct_window_trans, - shr(L_frame_glob, 1), - tmp4, - st->last_core_fx, - 0, - 0 - ); - } - } /* TCX-10 and TCX-only */ - - /* Window and overlap-add past frame if past frame is TCX */ - test(); - test(); - test(); - IF ((st->last_core_fx > ACELP_CORE) && (((sub(L_frameTCX, shr(st->L_frameTCX, 1)) == 0) && (st->tcxonly != 0)) || (sub(st->tcx_cfg.tcx_last_overlap_mode, TRANSITION_OVERLAP) == 0))) - { - - IF (tcx_cfg->last_aldo != 0) - { - tmp2 = add(st->Q_old_out, TCX_IMDCT_HEADROOM); - - tmp1 = sub(overlap, tcx_cfg->tcx_mdct_window_min_length); - FOR (i=0; i < tmp1; i++) - { - xn_buf16[i] = shl(add(xn_buf16[i], shr(st->old_out_fx[i+nz], tmp2)), TCX_IMDCT_HEADROOM); - move16(); - } - - /* fade truncated ALDO window */ - tmp1 = sub(overlap, shr(tcx_cfg->tcx_mdct_window_min_length, 1)); - FOR ( ; i < tmp1; i++) - { - tmp3 = mult_r(shr(st->old_out_fx[i+nz], tmp2), tcx_cfg->tcx_mdct_window_minimum[i-overlap+tcx_cfg->tcx_mdct_window_min_length].v.re); - xn_buf16[i] = shl(add(xn_buf16[i], tmp3), TCX_IMDCT_HEADROOM); - move16(); - } - FOR ( ; i < overlap; i++) - { - tmp3 = mult_r(shr(st->old_out_fx[i+nz], tmp2), tcx_cfg->tcx_mdct_window_minimum[overlap-1-i].v.im); - xn_buf16[i] = shl(add(xn_buf16[i], tmp3), TCX_IMDCT_HEADROOM); - move16(); - } - - FOR ( ; i < L_frame; i++) - { - xn_buf16[i] = shl(xn_buf16[i], TCX_IMDCT_HEADROOM); - move16(); - } - } - ELSE - { - test(); - test(); - test(); - if ((frame_cnt > 0) && (stop == 0) && (tcx_cfg->tcx_curr_overlap_mode == 0) && (st->last_core_fx != ACELP_CORE)) - { - stop = 2; /* use minimum overlap between the two TCX-10 windows */ move16(); - } - - tmp1 = stop; - move16(); - test(); - if ((stop == 0) || (sub(tcx_cfg->tcx_last_overlap_mode, MIN_OVERLAP) == 0)) - { - tmp1 = tcx_cfg->tcx_last_overlap_mode; - move16(); - } - - tcx_windowing_synthesis_past_frame( LPDmem->Txnq - , - tcx_cfg->tcx_aldo_window_1_trunc, - tcx_cfg->tcx_mdct_window_half, - tcx_cfg->tcx_mdct_window_minimum, - overlap, - tcx_cfg->tcx_mdct_window_half_length, - tcx_cfg->tcx_mdct_window_min_length, - tmp1 - ); - - BASOP_SATURATE_WARNING_OFF; - FOR (i=0; iTxnq[i]), TCX_IMDCT_HEADROOM); - move16(); - } - - IF (sub(i, L_frame) < 0) - { - FOR ( ; i < L_frame; i++) - { - xn_buf16[i] = shl(xn_buf16[i], TCX_IMDCT_HEADROOM); - move16(); - } - } - BASOP_SATURATE_WARNING_ON; - } - } - ELSE - { - IF (aldo == 0) - { - BASOP_SATURATE_WARNING_OFF; - FOR (i = 0; i < L_frame; i++) - { - xn_buf16[i] = shl(xn_buf16[i], TCX_IMDCT_HEADROOM); - move16(); - } - BASOP_SATURATE_WARNING_ON; - } - } - - test(); - test(); - test(); - IF ( (aldo == 0) && - ((sub(L_frameTCX, shr(st->L_frameTCX, 1)) == 0 && frame_cnt > 0) || - sub(L_frameTCX, shr(st->L_frameTCX, 1)) != 0) ) - { - /*Compute windowed synthesis in case of switching to ALDO windows in next frame*/ - FOR (i = 0; i < nz; i++) - { - st->old_out_fx[i] = shr(xn_buf16[L_frame-nz+i], TCX_IMDCT_HEADROOM); - move16(); - } - Copy(xn_buf16+L_frame, st->old_out_fx+nz, overlap); - set16_fx(st->old_out_fx+nz+overlap, 0, nz); - - tcx_windowing_synthesis_past_frame( st->old_out_fx+nz, - tcx_cfg->tcx_aldo_window_1_trunc, - tcx_cfg->tcx_mdct_window_half, - tcx_cfg->tcx_mdct_window_minimum, - overlap, - tcx_cfg->tcx_mdct_window_half_length, - tcx_cfg->tcx_mdct_window_min_length, - tcx_cfg->tcx_curr_overlap_mode - ); - - /* If current overlap mode = FULL_OVERLAP -> ALDO_WINDOW */ - IF (sub(tcx_cfg->tcx_curr_overlap_mode, FULL_OVERLAP) == 0) - { - FOR (i=0; iold_out_fx[nz+overlap+i] = shr(mult_r(xn_buf16[L_frame-1-i], tcx_cfg->tcx_aldo_window_1[nz-1-i]), TCX_IMDCT_HEADROOM); - move16(); - } - tcx_cfg->tcx_curr_overlap_mode = ALDO_WINDOW; - move16(); - } - - st->Q_old_out = -TCX_IMDCT_HEADROOM; - move16(); - } - tcx_cfg->last_aldo = aldo; - move16(); - - /* Update Txnq */ - IF (tcx_cfg->last_aldo == 0) - { - Copy(xn_buf16 + L_frame, LPDmem->Txnq, overlap); - } - - - /* Output */ - Copy(xn_buf16+shr(overlap,1)-tcx_offset, synth, L_frame_glob); + * Windowing, overlap and add * + *-----------------------------------------------------------*/ + /* Window current frame */ + tcx_windowing_synthesis_current_frame( xn_buf, tcx_cfg->tcx_aldo_window_2, tcx_cfg->tcx_mdct_window_half, tcx_cfg->tcx_mdct_window_minimum, + overlap, /*tcx_cfg->tcx_mdct_window_length*/ tcx_cfg->tcx_mdct_window_half_length, tcx_cfg->tcx_mdct_window_min_length, + st->last_core == ACELP_CORE, tcx_cfg->tcx_last_overlap_mode, /*left mode*/ LPDmem->acelp_zir, st->LPDmem.Txnq, + NULL, Aq_old, tcx_cfg->tcx_mdct_window_trans, L_frame_glob >> 1, tcx_offset<0?-tcx_offset:0, + st->last_core, 0, 0 ); } + } /* TCX-20/TCX-10 and TCX-only */ - /* Free internal TCX decoder stack memory */ + /* Window and overlap-add past frame if past frame is TCX */ + if ((st->last_core > 0) && (((L_frameTCX == st->L_frameTCX >> 1) && (st->tcxonly)) || (st->tcx_cfg.tcx_last_overlap_mode == TRANSITION_OVERLAP)) ) + { + if (tcx_cfg->last_aldo) + { + for (i=0; i < overlap - tcx_cfg->tcx_mdct_window_min_length; i++) + { + xn_buf[i] += st->old_out[i+nz]; + } + /* fade truncated ALDO window */ + for ( ; i < overlap; i++) + { + xn_buf[i] += st->old_out[i+nz] * tcx_cfg->tcx_mdct_window_minimum[overlap-1-i]; + } + } + else + { + if ((frame_cnt > 0) && (stop == 0) && (tcx_cfg->tcx_curr_overlap_mode == FULL_OVERLAP)&& (st->last_core!=0)) + { + stop = 2; /* use minimum overlap between the two TCX-10 windows */ + } + + tcx_windowing_synthesis_past_frame( LPDmem->Txnq, tcx_cfg->tcx_aldo_window_1_trunc, tcx_cfg->tcx_mdct_window_half, + tcx_cfg->tcx_mdct_window_minimum, overlap, tcx_cfg->tcx_mdct_window_half_length, tcx_cfg->tcx_mdct_window_min_length, + (stop == 0 || tcx_cfg->tcx_last_overlap_mode == MIN_OVERLAP) ? tcx_cfg->tcx_last_overlap_mode : stop ); + + for (i=0; iTxnq[i]; + } + } } + if(!aldo && (((L_frameTCX == st->L_frameTCX >> 1)&&frame_cnt > 0) || L_frameTCX != (st->L_frameTCX >> 1))) + { + /*Compute windowed synthesis in case of switching to ALDO windows in next frame*/ + mvr2r(xn_buf+L_frame-nz, st->old_out, nz+overlap); + set_zero(st->old_out+nz+overlap, nz); + tcx_windowing_synthesis_past_frame( st->old_out+nz, tcx_cfg->tcx_aldo_window_1_trunc, tcx_cfg->tcx_mdct_window_half, tcx_cfg->tcx_mdct_window_minimum, + overlap, tcx_cfg->tcx_mdct_window_half_length, tcx_cfg->tcx_mdct_window_min_length, tcx_cfg->tcx_curr_overlap_mode ); + + if(tcx_cfg->tcx_curr_overlap_mode==FULL_OVERLAP) + { + for (i=0; iold_out[nz+overlap+i]=xn_buf[L_frame-1-i]*tcx_cfg->tcx_aldo_window_1_trunc[-1-i]; + } + tcx_cfg->tcx_curr_overlap_mode=ALDO_WINDOW; + } + } + tcx_cfg->last_aldo=aldo; + + /* Update Txnq */ + if (!tcx_cfg->last_aldo) + { + mvr2r(xn_buf+L_frame, LPDmem->Txnq, overlap); + } + + /* Output */ + mvr2r( xn_buf+(overlap>>1)-tcx_offset, synth, L_frame_glob ); + /* Update L_frame_past */ st->L_frame_past = L_frame; - move16(); + return; } +/*-------------------------------------------------------------------* +* coder_tcx() +* +* +*-------------------------------------------------------------------*/ + void coder_tcx( - Word16 n, - TCX_config *tcx_cfg, /*input: configuration of TCX*/ - Word16 A[], /* input: quantized coefficients NxAz_q[M+1] */ - Word16 Aqind[], /* input: frame-independent quantized coefficients (M+1) */ - Word16 synth[], - Word16 L_frame_glob, /* input: frame length */ - Word16 L_frameTCX_glob, - Word16 L_spec, - Word16 nb_bits, /*input: bit budget*/ - Word8 tcxonly, /*input: only TCX flag*/ - Word32 spectrum[], /* i/o: MDCT spectrum */ - Word16 *spectrum_e, /* i/o: MDCT spectrum exponent */ - LPD_state *LPDmem, /*i/o: memories*/ - Word16 prm[], /* output: tcx parameters */ - Encoder_State_fx *st, + int n, + TCX_config *tcx_cfg, /*input: configuration of TCX*/ + float A[], /* input: quantized coefficients NxAz_q[M+1] */ + Word16 Aqind[], /* input: frame-independent quantized coefficients (M+1) */ + float synth[], + int L_frame_glob, /* input: frame length */ + int L_frameTCX_glob, + int L_spec, + int nb_bits, /*input: bit budget*/ + int tcxonly, /*input: only TCX flag*/ + float spectrum[], /* i/o: MDCT spectrum */ + LPD_state *LPDmem, /*i/o: memories*/ + int prm[], /* output: tcx parameters */ + Encoder_State *st, CONTEXT_HM_CONFIG *hm_cfg ) { - Word16 L_frame; - Word16 left_overlap, right_overlap; - Word16 tnsSize; /* number of tns parameters put into prm */ - Word16 tnsBits; /* number of tns bits in the frame */ - Word16 ltpBits; - Word16 gainlpc[FDNS_NPTS], gainlpc_e[FDNS_NPTS]; - Word16 win[N_MAX+L_MDCT_OVLP_MAX]; - Word32 powerSpec[N_MAX]; - Word16 powerSpec_e; - Word16 winMDST[N_MAX+L_MDCT_OVLP_MAX]; - Word16 *pWinMDST; - Word16 left_overlap_mode, right_overlap_mode; + int L_frame; + int left_overlap=-1, right_overlap=-1; + int tnsSize = 0; /* number of tns parameters put into prm */ + int tnsBits = 0; /* number of tns bits in the frame */ + int ltpBits = 0; + float gainlpc[FDNS_NPTS]; + float buf[N_MAX+L_MDCT_OVLP_MAX]; + float winMDST[N_MAX+L_MDCT_OVLP_MAX]; + float * win; + float * powerSpec; - - left_overlap = right_overlap = -1; - move16(); - move16(); - tnsSize = 0; - move16(); - tnsBits = 0; - move16(); - ltpBits = 0; - move16(); + powerSpec = win = buf; /* Share memory for windowed TD signal and for the power spectrum */ L_frame = L_frameTCX_glob; - move16(); /*-----------------------------------------------------------* * Windowing * *-----------------------------------------------------------*/ - IF (sub(st->tcx_cfg.tcx_last_overlap_mode, TRANSITION_OVERLAP) == 0) + if (st->tcx_cfg.tcx_last_overlap_mode == TRANSITION_OVERLAP) { - - WindowSignal(tcx_cfg, - tcx_cfg->tcx_offsetFB, - tcx_cfg->tcx_last_overlap_mode, - tcx_cfg->tcx_curr_overlap_mode, - &left_overlap, &right_overlap, - st->speech_TCX, - &L_frame, - win - ,1 - ); + WindowSignal( tcx_cfg, tcx_cfg->tcx_offsetFB, tcx_cfg->tcx_last_overlap_mode, tcx_cfg->tcx_curr_overlap_mode, + &left_overlap, &right_overlap, st->speech_TCX, &L_frame, win, 1 ); /*-----------------------------------------------------------* - * Compute MDCT * + * Compute MDCT for xn_buf[]. * *-----------------------------------------------------------*/ - *spectrum_e = 16; - move16(); - TCX_MDCT(win, spectrum, spectrum_e, left_overlap, sub(L_frame, shr(add(left_overlap, right_overlap), 1)), right_overlap); + TCX_MDCT( win, spectrum, left_overlap, L_frame-(left_overlap+right_overlap)/2, right_overlap ); + } - ELSE + else { - Word32 tmp_buf[L_FRAME_PLUS]; - Word16 Q, tmp1, tmp2, i; + wtda( st->new_speech_TCX, win, NULL, tcx_cfg->tcx_last_overlap_mode, tcx_cfg->tcx_curr_overlap_mode, L_frame); - Q = 0; - move16(); + WindowSignal( tcx_cfg, tcx_cfg->tcx_offsetFB, tcx_cfg->tcx_last_overlap_mode == ALDO_WINDOW ? FULL_OVERLAP : tcx_cfg->tcx_last_overlap_mode, + tcx_cfg->tcx_curr_overlap_mode == ALDO_WINDOW ? FULL_OVERLAP : tcx_cfg->tcx_curr_overlap_mode, + &left_overlap, &right_overlap, st->speech_TCX, &L_frame, winMDST, 1 ); - wtda_fx(st->new_speech_TCX, - &Q, - tmp_buf, - NULL, - NULL, - tcx_cfg->tcx_last_overlap_mode, - tcx_cfg->tcx_curr_overlap_mode, - L_frame); - left_overlap_mode = tcx_cfg->tcx_last_overlap_mode; - move16(); - if (sub(left_overlap_mode, ALDO_WINDOW) == 0) - { - left_overlap_mode = FULL_OVERLAP; - move16(); - } - right_overlap_mode = tcx_cfg->tcx_curr_overlap_mode; - move16(); - if (sub(right_overlap_mode, ALDO_WINDOW) == 0) - { - right_overlap_mode = FULL_OVERLAP; - move16(); - } + edct( win, spectrum, L_frame ); - WindowSignal( tcx_cfg, tcx_cfg->tcx_offsetFB, - left_overlap_mode, right_overlap_mode, - &left_overlap, &right_overlap, st->speech_TCX, &L_frame, winMDST, 1 ); - - /* scale by NORM_MDCT_FACTOR / L */ - tmp1 = mult_r(shl(L_frame, 4), 26214/*128.f / NORM_MDCT_FACTOR Q15*/); /* 4Q11 */ - tmp2 = 4; - move16(); - tmp1 = ISqrt16(tmp1, &tmp2); - - FOR (i = 0; i < L_frame; i++) - { - tmp_buf[i] = Mpy_32_16_1(tmp_buf[i], tmp1); - move32(); - } - Q = sub(Q, tmp2); - - /* DCT */ - edct_fx(tmp_buf, spectrum, L_frame, &Q); - *spectrum_e = sub(31, Q); + v_multc(spectrum, (float)sqrt((float)NORM_MDCT_FACTOR / L_frame), spectrum, L_frame); } - /*-----------------------------------------------------------* * Attenuate upper end of NB spectrum, * * to simulate ACELP behavior * *-----------------------------------------------------------*/ - IF (st->narrowBand != 0) + if( st->narrowBand ) { attenuateNbSpectrum(L_frame, spectrum); } @@ -2208,108 +1266,63 @@ void coder_tcx( * Detect low pass if present. * *-----------------------------------------------------------*/ - pWinMDST = winMDST; - move16(); - if (sub(st->tcx_cfg.tcx_last_overlap_mode, TRANSITION_OVERLAP) == 0) - { - pWinMDST = win; - move16(); - } + AnalyzePowerSpectrum( st, L_frame*st->L_frame/st->L_frameTCX, L_frame, left_overlap, right_overlap, spectrum, + (st->tcx_cfg.tcx_last_overlap_mode == TRANSITION_OVERLAP) ? win : winMDST, powerSpec ); - AnalyzePowerSpectrum(st, - round_fx(L_shl(Mpy_32_16_1(L_mult0(L_frame,st->L_frame_fx)/*Q0*/, - getInvFrameLen(st->L_frameTCX)/*Q21*/)/*Q6*/,16-6)), - L_frame, - left_overlap, right_overlap, - spectrum, *spectrum_e, - pWinMDST, - powerSpec, &powerSpec_e); - IF (tcx_cfg->fIsTNSAllowed != 0) + if (tcx_cfg->fIsTNSAllowed) { - test(); - test(); - SetTnsConfig(tcx_cfg, sub(L_frame_glob, st->L_frame_fx) == 0, st->last_core_fx == 0); - - TNSAnalysis(tcx_cfg, L_frame, L_spec, TCX_20, st->last_core_fx == 0, spectrum, st->tnsData, st->fUseTns - , &st->hIGFEnc.tns_predictionGain - ); + SetTnsConfig(tcx_cfg, L_frame_glob == st->L_frame, st->last_core == 0); + TNSAnalysis(tcx_cfg, L_frame, L_spec, TCX_20, st->last_core == 0, spectrum, st->tnsData, st->fUseTns, &(&st->hIGFEnc)->tns_predictionGain ); } - ELSE + else { st->fUseTns[0] = st->fUseTns[1] = 0; - move16(); - move16(); } - IF(st->igf) - { - ProcessIGF(&st->hIGFEnc, st, spectrum, spectrum_e, powerSpec, &powerSpec_e, 1, st->fUseTns[0], (st->last_core_fx == ACELP_CORE), 0); - } - - ShapeSpectrum(tcx_cfg, A, gainlpc, gainlpc_e, - L_frame_glob, - L_spec, - spectrum, - st->fUseTns[0], - st - ); if(st->igf) { - nb_bits = sub(nb_bits, st->hIGFEnc.infoTotalBitsPerFrameWritten); + ProcessIGF(&st->hIGFEnc, st, spectrum, powerSpec, 1, st->fUseTns[0], (st->last_core == ACELP_CORE), 0); } - IF (tcx_cfg->fIsTNSAllowed != 0) + + ShapeSpectrum( tcx_cfg, A, gainlpc, L_frame_glob, L_spec, spectrum, st->fUseTns[0], st ); + + if(st->igf) + { + nb_bits -= st->hIGFEnc.infoTotalBitsPerFrameWritten; + } + + if (tcx_cfg->fIsTNSAllowed) { EncodeTnsData(tcx_cfg->pCurrentTnsConfig, st->tnsData, prm+1+NOISE_FILL_RANGES+LTPSIZE, &tnsSize, &tnsBits); } - QuantizeSpectrum(tcx_cfg, - A, - Aqind, - gainlpc, gainlpc_e, - synth, - L_frame_glob, - L_frameTCX_glob, - L_spec, - sub(sub(nb_bits, tnsBits), ltpBits), - tcxonly, - spectrum, spectrum_e, - st->tnsData, - st->fUseTns[0], - tnsSize, - LPDmem, - prm, - n, - st, - hm_cfg - ); - - LPDmem->nbits = add(LPDmem->nbits, add(tnsBits, ltpBits)); + QuantizeSpectrum( tcx_cfg, A, Aqind, gainlpc, synth, L_frame_glob, L_frameTCX_glob, L_spec, + nb_bits-tnsBits-ltpBits, tcxonly, spectrum,st->tnsData, st->fUseTns[0], + tnsSize, LPDmem, prm, n, st, hm_cfg ); + return; } - /*-------------------------------------------------------------------* * coder_tcx_post() * * *-------------------------------------------------------------------*/ -void coder_tcx_post(Encoder_State_fx *st, - LPD_state *LPDmem, - TCX_config *tcx_cfg, - Word16 *synth, - const Word16 *A, - const Word16 *Ai, - Word16 *wsig, - Word16 Q_new, - Word16 shift - ) +void coder_tcx_post( + Encoder_State *st, + LPD_state *LPDmem, + TCX_config *tcx_cfg, + float *synth, + float *A, + const float *Ai, + float *wsig ) { - Word16 xn_buf[L_FRAME_MAX]; + float xn_buf[L_FRAME_MAX]; /* TCX output */ - Copy( synth, xn_buf, st->L_frame_fx ); + mvr2r( synth, xn_buf, st->L_frame ); /*-----------------------------------------------------------* @@ -2317,7 +1330,7 @@ void coder_tcx_post(Encoder_State_fx *st, *-----------------------------------------------------------*/ /* Update LPDmem (Txnq,syn,syn_pe,old_exc,wsyn,Ai,Aq) */ - tcx_encoder_memory_update( wsig, xn_buf, st->L_frame_fx, Ai, A, tcx_cfg->preemph_fac, LPDmem, st, synth, Q_new, shift ); + tcx_encoder_memory_update( wsig, xn_buf, st->L_frame, Ai, A, tcx_cfg->preemph_fac, LPDmem, st, M, synth ); return; } diff --git a/src/libs/libevs/lib_enc/cod_uv.cpp b/src/libs/libevs/lib_enc/cod_uv.cpp old mode 100755 new mode 100644 index bf386481..a7de3cc9 --- a/src/libs/libevs/lib_enc/cod_uv.cpp +++ b/src/libs/libevs/lib_enc/cod_uv.cpp @@ -1,13 +1,13 @@ /*==================================================================================== - EVS Codec 3GPP TS26.442 Apr 03, 2018. Version 12.11.0 / 13.6.0 / 14.2.0 + EVS Codec 3GPP TS26.443 Nov 13, 2018. Version 12.11.0 / 13.7.0 / 14.3.0 / 15.1.0 ====================================================================================*/ - #include #include +#include #include -#include "prot_fx.h" -#include "stl.h" +#include "prot.h" + /*-------------------------------------------------------------------* * gauss_L2: @@ -17,72 +17,47 @@ * * Gaussian excitation is generated by a white noise and shapes it with LPC-derived filter *-------------------------------------------------------------------*/ + void gauss_L2( - const Word16 h[], /* i : weighted LP filter impulse response Q14+s */ - Word16 code[], /* o : gaussian excitation Q9 */ - const Word16 y2[], /* i : zero-memory filtered code. excitation Q9 */ - Word16 y11[], /* o : zero-memory filtered gauss. excitation Q9 */ - Word32 *gain, /* o : excitation gain Q16 */ - ACELP_CbkCorr *g_corr, /*i/o : correlation structure for gain coding */ - const Word16 gain_pit, /* i : unquantized gain of code Q14 */ - const Word16 tilt_code, /* i : tilt of code Q15 */ - const Word16 *Aq, /* i : quantized LPCs Q12 */ - const Word16 formant_enh_num, /* i : formant enhancement numerator factor Q15 */ - Word16 *seed_acelp, /*i/o : random seed Q0 */ - const Word16 shift + const float h[], /* i : weighted LP filter impulse response */ + float code[], /* o : gaussian excitation */ + float y2[], /* i : zero-memory filtered code. excitation */ + float y11[], /* o : zero-memory filtered gauss. excitation */ + float *gain, /* o : excitation gain */ + float g_corr[], /* i/o : correlation structure for gain coding */ + float gain_pit, /* i : unquantized gain of code */ + float tilt_code, /* i : tilt of code */ + const float *Aq, /* i : quantized LPCs */ + float formant_enh_num, /* i : formant enhancement factor */ + short *seed_acelp /*i/o : random seed */ ) { - Word16 i, tmp16; - Word32 tmp32, tmp32_2; - - - assert(gain_pit==0); + short i; + assert(gain_pit==0.f); + (void)gain_pit; /*-----------------------------------------------------------------* * Find new target for the Gaussian codebook *-----------------------------------------------------------------*/ /*Generate white gaussian noise using central limit theorem method (N only 4 as E_util_random is not purely uniform)*/ - FOR (i = 0; i < L_SUBFR; i++) + for( i=0; iy1y1 = round_fx(L_shl(tmp32, tmp16)); - g_corr->y1y1_e = sub(31-18, tmp16); - move16(); - - tmp16 = norm_l(tmp32_2); - g_corr->y1y2 = round_fx(L_shl(tmp32_2, tmp16)); - g_corr->y1y2_e = sub(31-18, tmp16); - move16(); + g_corr[0] = 0.01F + dotp( y11, y11, L_SUBFR ); + g_corr[4] = 0.01F + dotp( y11, y2, L_SUBFR ); + return; } - diff --git a/src/libs/libevs/lib_enc/comvad_decision.cpp b/src/libs/libevs/lib_enc/comvad_decision.cpp old mode 100755 new mode 100644 index 87669a83..489cf579 --- a/src/libs/libevs/lib_enc/comvad_decision.cpp +++ b/src/libs/libevs/lib_enc/comvad_decision.cpp @@ -1,884 +1,819 @@ /*==================================================================================== - EVS Codec 3GPP TS26.442 Apr 03, 2018. Version 12.11.0 / 13.6.0 / 14.2.0 + EVS Codec 3GPP TS26.443 Nov 13, 2018. Version 12.11.0 / 13.7.0 / 14.3.0 / 15.1.0 ====================================================================================*/ - +#include #include #include - - -#include "basop_util.h" -#include "stl.h" -#include "vad_basop.h" -#include "prot_fx.h" -#include "rom_enc_fx.h" +#include "prot.h" +#include "rom_enc.h" +static int comvad_hangover( + float lt_snr_org, /*(i)original long time SNR*/ + float snr, /*(i) frequency domain SNR */ + float lf_snr, /*(i) long time frequency domain SNR calculated by l_speech_snr and l_silence_snr*/ + float snr_flux, /*(i) average tsnr*/ + int bw_index, /*(i) band width index*/ + int vad_flag, + int pre_res_hang_num, /*(i) residual number of previous hangover */ + int continuous_speech_num2, /*(i) number of continuous speech frames*/ + int noisy_type /*(i) noisy type*/ +); -/* only one is activated in below preprocessing*/ -/*#define CLDFB_VAD*/ /* test on the CLDFB-VAD */ -static -Word16 comvad_hangover( Word32 lt_snr_org, /*(i)original long time SNR*/ - Word32 snr, /*(i) frequency domain SNR */ - Word32 l_snr, /*(i) long time frequency domain - SNR calculated by l_speech_snr and l_silence_snr*/ - Word32 snr_flux, /*(i) average tsnr*/ - Word16 bw_index, /*(i) band width index*/ - Word16 vad_flag, - Word16 pre_res_hang_num, /*(i) residual amount of previous hangover */ - Word16 continuous_speech_num2, /*(i) amount of continuous speech frames*/ - Word16 noisy_type /*(i) noisy type*/ - ) + +int comvad_decision(T_CldfbVadState *st, + float snr, /*(i) frequency domain SNR */ + float tsnr, /*(i) time domain SNR */ + float snr_flux, /*(i) average tsnr of several frames*/ + float lt_snr, /*(i)long time SNR calculated by fg_energy and bg_energy*/ + float lt_snr_org, /*(i)original long time SNR*/ + float lf_snr, /*(i) long time frequency domain + SNR calculated by l_speech_snr and l_silence_snr*/ + float frame_energy, /*(i) current frame energy */ + int music_backgound_f, /*(i) background music flag*/ + short *cldfb_addition, + short vada_flag + ) { - Word32 l_snr_add; - Word16 speech_flag; + int speech_flag = st->speech_flag; + int fg_energy_count = st->fg_energy_count; + int bg_energy_count = st->bg_energy_count; + float fg_energy = st->fg_energy; + float bg_energy = st->bg_energy; + int l_speech_snr_count=st->l_speech_snr_count; + int vad_flag; + float snr_thresh = 0.2f; + float *ltd_stable_rate = st->ltd_stable_rate; + float *sp_center = st->sp_center; + int frameloop = st->frameloop; + int bw_index = st->bw_index; + int noisy_type = UNKNOWN_NOISE; + short vadb_flag = 0; + /* + * ls_snr_org + * -------NB---------------WB----------------SWB--------- + * l16 [13.5 17] [13.5 16] [13.1 15.2] + * 126 [12 14] [10.7 12.7] [10.3 12.1] + * l36 [9.5 12] [8.5 10.5] [7.8 9.2] + * 15dB [3.5 4.5] + * 20dB [4.5 5.5] + */ - speech_flag = pre_res_hang_num; - move16(); + /* + * lt_snr_org + * -------NB---------------WB----------------SWB--------- + * l16 [-- --] [-- --] [-- --] + * 126 [-- --] [-- -] [-- --] + * l36 [-- --] [-- --] [- --] + * 15dB [1.2 1.9] + * 20dB [2.1 2.7] [1.8 2.3] + */ + + if(st->lf_snr_smooth > LS_MIN_SELENCE_SNR[bw_index - CLDFBVAD_NB_ID] && lt_snr_org > LT_MIN_SILENCE_SNR[bw_index - CLDFBVAD_NB_ID]) - IF(sub(bw_index, CLDFBVAD_SWB_ID) == 0) { - IF(vad_flag) + noisy_type = SILENCE; + } + snr_thresh = construct_snr_thresh( sp_center, snr_flux, lt_snr, lf_snr, + st->continuous_speech_num, st->continuous_noise_num, st->fg_energy_est_start, bw_index); + + if(snr>(snr_thresh)) + { + vad_flag =1; + } + else + { + vad_flag =0; + } + if(tsnr> 4.0) + { + vad_flag =1; + } + + + if(frameloop>25) + { + if(vad_flag == 1&&st->fg_energy_est_start==1) { - speech_flag = 4; - move16(); - if(L_sub(lt_snr_org, 117440509/* 3.5 Q25 */) > 0) + if(fg_energy_count==512) { - speech_flag = 3; - move16(); + fg_energy = fg_energy*0.75f; + fg_energy_count = 384; + } + if((frame_energy*bg_energy_count)>6*bg_energy) + { + fg_energy = fg_energy + frame_energy; + fg_energy_count = fg_energy_count + 1; + } + } + } + if(music_backgound_f) + { + vad_flag =1; + } + if(vad_flag==1) + { + + if(snr > st->l_silence_snr/st->l_silence_snr_count + 1.5) + { + if(l_speech_snr_count==512) + { + st->l_speech_snr = st->l_speech_snr*0.75f; + l_speech_snr_count = 384; + + st->l_speech_snr += snr; + l_speech_snr_count++; + } + else + { + st->l_speech_snr += snr; + l_speech_snr_count++; + } + } + } + if(bw_index == CLDFBVAD_NB_ID) + { + if(snr_flux > 1.9+ lt_snr*0.28 ) + { + vad_flag = 1; + } + if((snr_flux > 1.5)&&sp_center[3]>1.6&& lt_snr_org<3.5) + { + vad_flag = 1; + } + if((snr_flux > 1.2)&&sp_center[3]>1.9&& lt_snr_org<3.5) + { + vad_flag = 1; + } + if((snr_flux > 1.00f)&&sp_center[3]>3.2&& lt_snr_org<3.5) + { + vad_flag = 1; + } + } + if(bw_index == CLDFBVAD_WB_ID) + { + if((snr_flux > 2.1+lt_snr*0.24) ) + { + vad_flag = 1; + } + if((snr_flux > 1.6)&&sp_center[3]>2.5&& lt_snr_org<3.5) + { + vad_flag = 1; + } + if((snr_flux > 1.2)&&sp_center[3]>2.8&& lt_snr_org<3.5) + { + vad_flag = 1; + } + if((snr_flux > 1.0)&&sp_center[3]>4.5&& lt_snr_org<3.5) + { + vad_flag = 1; + } + } + if(bw_index == CLDFBVAD_SWB_ID) + { + + if((snr_flux > 2.1+ lt_snr*0.32) ) + { + vad_flag = 1; + } + if((snr_flux > 1.68)&&sp_center[3]>2.76&& lt_snr_org<3.5) + { + vad_flag = 1; + } + if((snr_flux > 1.24)&&sp_center[3]>2.92&& lt_snr_org<3.5) + { + vad_flag = 1; + } + if((snr_flux > 1.10f)&&sp_center[3]>4.6&& lt_snr_org<3.5) + { + vad_flag = 1; + } + } + if(st->fg_energy_est_start==0) + { + if(ltd_stable_rate[0]>0.08 && vad_flag == 1 && frame_energy>50) + { + st->fg_energy_est_start=1; + } + } + + /************************************************************************/ + /* hangover */ + /************************************************************************/ + speech_flag = comvad_hangover(lt_snr_org, snr, lf_snr, snr_flux, bw_index, vad_flag, speech_flag, + st->continuous_speech_num2, noisy_type); + + if(vad_flag==0&&speech_flag>0) + { + speech_flag--; + vad_flag = 1; + } + + vadb_flag = vad_flag; + + if(bw_index == CLDFBVAD_SWB_ID) + { + + if(SILENCE == noisy_type && snr > 0.2 && vad_flag==0) + { + vad_flag = vada_flag; + } + else if(st->lf_snr_smooth < 10.5 || SILENCE!=noisy_type) + { + if((snr_flux > 2.0) + || (st->continuous_speech_num2 > 40 && (snr_flux > 1.8)) + || music_backgound_f == 1) + { + vad_flag = vada_flag | vadb_flag; + } + /*only use for silence*/ + else if(noisy_type == SILENCE) + { + vad_flag = vada_flag; + } + } + } + else if(bw_index == CLDFBVAD_WB_ID) + { + + if(SILENCE == noisy_type && snr > 0.2 && vad_flag==0) + { + vad_flag = vada_flag; + } + else + { + if(st->lf_snr_smooth < 10.5 || SILENCE!=noisy_type) + { + if(snr_flux > 2.2 + || (st->continuous_speech_num2 > 40 && (snr_flux > 1.5)) + || music_backgound_f == 1) + { + vad_flag = vada_flag|vadb_flag; + } + else if(SILENCE == noisy_type) + { + vad_flag = vada_flag; + } + } - test(); - test(); - IF((sub(continuous_speech_num2, 8) < 0)&& (L_sub(lt_snr_org, 134217724/* 4.0 Q25 */) < 0)) + } + + } + else + { + if(noisy_type == SILENCE ) + { + if(st->lf_snr_smooth > 12.5 && music_backgound_f == 0) { - speech_flag = sub(8, continuous_speech_num2); + vad_flag = vada_flag; } - ELSE IF((L_sub(snr_flux, 26843545/* 0.8 Q25 */) > 0 )&&(sub(continuous_speech_num2, 24) > 0)) + } + else + { + if((snr_flux > 2.0) + || (st->continuous_speech_num2 > 30 && (snr_flux > 1.5)) + || music_backgound_f == 1) { - IF(L_sub(lt_snr_org, 120795952/* 3.6 Q25 */) > 0) + vad_flag = vada_flag | vadb_flag; + } + } + } + if(vad_flag==0 ) + { + if(st->l_silence_snr_count==512) + { + st->l_silence_snr = st->l_silence_snr*0.75f; + st->l_silence_snr_count = 384; + + st->l_silence_snr += snr; + st->l_silence_snr_count++; + } + else if(snr<0.8) + { + st->l_silence_snr += snr; + st->l_silence_snr_count++; + } + } + if((vad_flag + vada_flag) == 0) + + { + if(bg_energy_count==512) + { + bg_energy = bg_energy*0.75f; + bg_energy_count = 384; + } + + if(tsnr<1.0) + { + bg_energy = bg_energy + frame_energy; + bg_energy_count = bg_energy_count +1; + } + } + + st->lt_snr_org = lt_snr_org; + st->speech_flag = speech_flag; + + st->fg_energy_count = fg_energy_count; + st->bg_energy_count = bg_energy_count; + st->fg_energy = fg_energy; + st->bg_energy = bg_energy; + st->l_speech_snr_count = l_speech_snr_count; + + + st->vad_flag_for_bk_update = vad_flag; + if(st->update_count < 12 && vadb_flag==1) + { + st->warm_hang_num = max(20, speech_flag); + } + + + if(vad_flag==0&&st->warm_hang_num>0) + { + st->warm_hang_num--; + vad_flag = 1; + } + + if(noisy_type == SILENCE + && bw_index != CLDFBVAD_NB_ID) + + { + *cldfb_addition = 2; + } + else + { + *cldfb_addition = 0; + + if(bw_index == CLDFBVAD_WB_ID) + { + *cldfb_addition = 3; + } + if(bw_index == CLDFBVAD_SWB_ID) + { + *cldfb_addition = 1; + } + if(st->bw_index == CLDFBVAD_NB_ID) + { + *cldfb_addition = 1; + } + } + + return vad_flag; +} + +float construct_snr_thresh(float sp_center[], /*(i) spectral center*/ + float snr_flux, /*(i) snr flux*/ + float lt_snr, /*(i) long time time domain snr*/ + float lf_snr, /*(i) long time frequency domain snr*/ + int continuous_speech_num, /*(i) number of continuous speech frames*/ + int continuous_noise_num, /*(i) number of continuous noise frames*/ + int fg_energy_est_start, /*(i) whether if estimated energy*/ + int bw_index /*(i) band width index*/ + ) +{ + float test_l_snr=0.f; + float snr_delta; + float snr_thresh; + float bw_snr; + + + snr_delta = COMVAD_INIT_SNR_DELTA[bw_index]; + bw_snr = lt_snr; + + if(bw_index == CLDFBVAD_SWB_ID) + { + + test_l_snr = lt_snr; + test_l_snr = test_l_snr*1.0f; + + if(sp_center[3]>2.80f) + { + snr_delta = snr_delta + 0.00f; + } + else if(sp_center[2]>2.6) + { + snr_delta = snr_delta + 0.03f; + } + else if(sp_center[2]>1.6) + { + snr_delta = snr_delta + 0.05f; + } + else if(sp_center[3]>1.4) + { + snr_delta = snr_delta + 0.10f; + } + else + { + snr_delta = snr_delta + 0.40f; + } + + if(continuous_speech_num > 8&&fg_energy_est_start==1) + { + snr_delta = snr_delta - 0.2f; + } + else if(continuous_noise_num > 12&&(snr_flux>0.6+lf_snr*0.1)) + { + snr_delta = snr_delta + 0.1f; + } + else if(continuous_noise_num > 24) + { + snr_delta = snr_delta + 0.2f; + } + else if((continuous_noise_num > 4)) + { + snr_delta = snr_delta + 0.1f; + } + + } + else if(bw_index == CLDFBVAD_WB_ID) + { + + test_l_snr = lt_snr; + if(sp_center[3]>2.80f) + { + snr_delta = snr_delta + 0.00f; + } + else if(sp_center[2]>2.6) + { + snr_delta = snr_delta + 0.03f; + } + else if(sp_center[2]>1.6) + { + snr_delta = snr_delta + 0.05f; + } + else if(sp_center[3]>1.4) + { + snr_delta = snr_delta + 0.10f; + } + else + { + snr_delta = snr_delta + 0.30f; + } + + if(continuous_speech_num > 8&&fg_energy_est_start==1) + { + snr_delta = snr_delta - 0.1f; + } + else if(continuous_noise_num > 12&&(snr_flux>0.6+bw_snr*0.1)) + { + snr_delta = snr_delta + 0.1f; + } + else if(continuous_noise_num > 24) + { + snr_delta = snr_delta + 0.2f; + } + else if((continuous_noise_num > 4)) + { + snr_delta = snr_delta + 0.1f; + } + } + else if(bw_index == CLDFBVAD_NB_ID) + { + + test_l_snr = lt_snr; + + if(sp_center[3]>3.0) + { + snr_delta = snr_delta + 0.00f; + } + else if(sp_center[2]>2.6) + { + snr_delta = snr_delta + 0.02f; + } + else if(sp_center[2]>1.6) + { + snr_delta = snr_delta + 0.04f; + } + else if(sp_center[2]>1.46) + { + snr_delta = snr_delta + 0.10f; + } + else + { + snr_delta = snr_delta + 0.18f; + } + + if(continuous_speech_num > 80&&fg_energy_est_start==1&&(sp_center[0]>1.4)) + { + snr_delta = snr_delta - 0.32f; + } + else if(continuous_speech_num > 8&&fg_energy_est_start==1&&(snr_flux>0.2+lf_snr*0.1)) + { + snr_delta = snr_delta - 0.1f; + } + else if(continuous_noise_num > 12&&(snr_flux>0.6+lf_snr*0.1)) + { + snr_delta = snr_delta + 0.1f; + } + else if(continuous_noise_num > 24) + { + + snr_delta = snr_delta + 0.2f; + } + } + else + { + snr_delta = 1.0f; + } + + snr_thresh = snr_delta + test_l_snr ; + + + return snr_thresh; +} + +static int comvad_hangover(float lt_snr_org, /*(i)original long time SNR*/ + float snr, /*(i) frequency domain SNR */ + float lf_snr, /*(i) long time frequency domain + SNR calculated by l_speech_snr and l_silence_snr*/ + float snr_flux, /*(i) average tsnr*/ + int bw_index, /*(i) band width index*/ + int vad_flag, + int pre_res_hang_num, /*(i) residual number of previous hangover */ + int continuous_speech_num2, /*(i) number of continuous speech frames*/ + int noisy_type /*(i) noisy type*/ + ) + +{ + int speech_flag = pre_res_hang_num; + + + if(bw_index == CLDFBVAD_SWB_ID) + { + if(vad_flag) + { + if(lt_snr_org > 3.5f) + speech_flag = 3; + else + speech_flag = 4; + if((continuous_speech_num2 < 8)&& (lt_snr_org < 4.0f)) + { + speech_flag = 8 - continuous_speech_num2; + } + else if((snr_flux > 0.8 )&&(continuous_speech_num2 > 24)) + { + if(lt_snr_org > 3.6f) { speech_flag = 3; - move16(); } - ELSE IF(L_sub(lt_snr_org, 87241521/* 2.6 Q25 */) > 0 ) + else if(lt_snr_org > 2.6f) { speech_flag = 3; - move16(); } - ELSE IF(L_sub(lt_snr_org, 53687090/* 1.6 Q25 */) > 0 ) + else if(lt_snr_org > 1.6f) { speech_flag = 4; - move16(); } - ELSE + else { speech_flag = 5; - move16(); } - speech_flag = sub(speech_flag,1); + speech_flag = speech_flag - 1; } - - IF(sub(continuous_speech_num2, 120) < 0) + if(continuous_speech_num2 < 120) { - test(); - IF(L_sub(snr, 50331647/* 1.5 Q25 */)>0) + if(snr>1.5) { speech_flag = 9; - move16(); } - ELSE IF(L_sub(snr, 33554431/* 1.0 Q25 */)>0 && sub(speech_flag, 7)<0) + else if(snr>1.0&&speech_flag<7) { speech_flag = 7; - move16(); } - ELSE IF(sub(speech_flag,3) <0) + else if(speech_flag<3) { speech_flag = 3; - move16(); } - if(sub(speech_flag,3)>0) + if(speech_flag > 3) { - speech_flag =sub(speech_flag,2); + speech_flag -= 2; } } - ELSE + else { - IF(L_sub(lt_snr_org, 120795952/* 3.6 Q25 */) > 0) + if(lt_snr_org > 3.6f) { speech_flag = 1; - move16(); } - ELSE IF(L_sub(lt_snr_org, 100663293/* 3.0 Q25 */) > 0) + else if(lt_snr_org > 3.0f) { speech_flag = 2; - move16(); } - ELSE IF(L_sub(lt_snr_org, 83886078/* 2.5 Q25 */) > 0) + else if(lt_snr_org > 2.5f) { speech_flag = 3; - move16(); } - ELSE IF(L_sub(lt_snr_org, 67108862/* 2.0 Q25 */) > 0) + else if(lt_snr_org > 2.0f) { speech_flag = 3; - move16(); } - ELSE IF(L_sub(lt_snr_org, 50331647/* 1.5 Q25 */)> 0) + else if(lt_snr_org > 1.5f) { speech_flag = 4; - move16(); } - ELSE + else { speech_flag = 5; - move16(); } } - - if(sub(noisy_type, SILENCE)==0) + if(noisy_type==SILENCE) { speech_flag = 6; - move16(); } } } - ELSE IF(sub(bw_index, CLDFBVAD_WB_ID) == 0) + else if(bw_index == CLDFBVAD_WB_ID) { - IF(vad_flag) + if(vad_flag) { - IF(L_sub(lt_snr_org, 117440509/* 3.5 Q25 */) > 0) - { + if(lt_snr_org > 3.5f) speech_flag = 1; - move16(); - } - ELSE - { + else speech_flag = 2; - move16(); - } - - test(); - test(); - IF((sub(continuous_speech_num2, 8) < 0) && (L_sub(lt_snr_org, 134217724/* 4.0 Q25 */) <0 )) + if((continuous_speech_num2 < 8)&& (lt_snr_org < 4.0f)) { - speech_flag = sub(8, continuous_speech_num2); + speech_flag = 8 - continuous_speech_num2; } - ELSE IF((L_sub(snr_flux, 30198988/* 0.9 Q25 */) > 0) && (sub(continuous_speech_num2, 50) > 0)) + else if((snr_flux > 0.9 )&&(continuous_speech_num2 > 50)) { - IF(L_sub(lt_snr_org, 120795952/* 3.6 Q25 */) > 0) + if(lt_snr_org > 3.6f) { speech_flag = 1; - move16(); } - ELSE IF(L_sub(lt_snr_org, 87241521/* 2.6 Q25 */) > 0) + else if(lt_snr_org > 2.6f) { speech_flag = 5; - move16(); } - ELSE IF(L_sub(lt_snr_org, 53687090/* 1.6 Q25 */) > 0) + else if(lt_snr_org > 1.6f) { speech_flag = 6; - move16(); } - ELSE + else { speech_flag = 7; - move16(); } - IF(sub(speech_flag , 1)>0) + if(speech_flag > 1) { - speech_flag = sub(speech_flag , 1); + speech_flag = speech_flag - 1; } - } - IF(sub(continuous_speech_num2, 120)< 0) + } + if(continuous_speech_num2 < 120) { - test(); - test(); - test(); - IF(L_sub(snr, 50331647/* 1.5 Q25 */)>0) + if(snr>1.5) { speech_flag = 6; - move16(); } - ELSE IF(L_sub(snr, 33554431/* 1.0 Q25 */)>0 && sub(speech_flag, 5) < 0) + else if(snr>1.0&&speech_flag<5) { speech_flag = 5; - move16(); } - ELSE IF(L_sub(snr, 26843545/* 0.8 Q25 */)>0 && L_sub(lt_snr_org,67108862/* 2.0 Q25 */) < 0 && sub(speech_flag, 4) < 0) + else if(snr>0.8&<_snr_org < 2 &&speech_flag<4) { speech_flag = 4; - move16(); } - ELSE IF(sub(speech_flag, 3) < 0) + else if(speech_flag<3) { speech_flag = 3; - move16(); } } - ELSE + else { - IF(L_sub(lt_snr_org,120795952/* 3.6 Q25 */) > 0) + if(lt_snr_org > 3.6f) { speech_flag = 1; - move16(); } - ELSE IF(L_sub(lt_snr_org, 100663293/* 3.0 Q25 */) > 0) + else if(lt_snr_org > 3.0f) { speech_flag = 2; - move16(); } - ELSE IF(L_sub(lt_snr_org, 83886078/* 2.5 Q25 */) > 0) + else if(lt_snr_org > 2.5f) { speech_flag = 2; - move16(); } - ELSE IF(L_sub(lt_snr_org, 67108862/* 2.0 Q25 */) > 0) + else if(lt_snr_org > 2.0f) { speech_flag = 3; - move16(); } - ELSE { + else + { speech_flag = 3; - move16(); } } - if(sub(noisy_type, SILENCE)==0) + if(noisy_type==SILENCE) { speech_flag = 6; - move16(); } } } - ELSE /* NB */ + else { - IF(vad_flag) + if(vad_flag) { - l_snr_add = L_add(0x0199999a,MUL_F(l_snr,0x0ccd)); - - IF(L_sub(lt_snr_org, 117440509/* 3.5 Q25 */) > 0) - { + if(lt_snr_org > 3.5f) speech_flag = 3; - move16(); - } - ELSE - { + else speech_flag = 4; - move16(); - } - - test(); - test(); - IF((sub(continuous_speech_num2,8) < 0)&& (L_sub(lt_snr_org, 134217724/* 4.0 Q25 */) < 0)) + if((continuous_speech_num2 < 8)&& (lt_snr_org < 4.0f)) { - speech_flag = sub(8, continuous_speech_num2); + speech_flag = 8 - continuous_speech_num2; } - ELSE IF((L_sub(snr_flux, l_snr_add) > 0)&&(sub(continuous_speech_num2, 24) > 0)) + else if((snr_flux > 0.8 + lf_snr*0.1)&&(continuous_speech_num2 > 24)) { - IF(L_sub(lt_snr_org, 120795952/* 3.6 Q25 */) > 0) + if(lt_snr_org > 3.6f) { speech_flag = 3; - move16(); } - ELSE IF(L_sub(lt_snr_org, 87241521/* 2.6 Q25 */) > 0) + else if(lt_snr_org > 2.6f) { speech_flag = 8; - move16(); } - ELSE IF(L_sub(lt_snr_org, 40265317/* 1.2 Q25 */) > 0) + else if(lt_snr_org > 1.2f) { speech_flag = 10; - move16(); } - ELSE + else { speech_flag = 12; - move16(); } - - IF(sub(speech_flag ,2)>0) + if(speech_flag > 2) { - speech_flag = sub(speech_flag,2); + speech_flag = speech_flag - 2; } - } - IF(sub(continuous_speech_num2, 120) < 0) + } + if(continuous_speech_num2 < 120) { - test(); - test(); - IF(L_sub(snr, 50331647/* 1.5 Q25 */)>0) + if(snr>1.5) { speech_flag = 10; - move16(); } - ELSE IF(L_sub(snr, 33554431/* 1.0 Q25 */)>0 && sub(speech_flag,7) < 0) + else if(snr>1.0&&speech_flag<7) { speech_flag = 7; - move16(); } - ELSE IF(sub(speech_flag, 3)<0 && sub(continuous_speech_num2, 12) > 0) + else if(speech_flag<3&&continuous_speech_num2>12) { speech_flag = 3; - move16(); } } - ELSE + else { - IF(L_sub(lt_snr_org, 120795952/* 3.6 Q25 */) > 0) + if(lt_snr_org > 3.6f) { speech_flag = 2; - move16(); } - ELSE IF(L_sub(lt_snr_org, 100663293/* 3.0 Q25 */) > 0) + else if(lt_snr_org > 3.0f) { speech_flag = 2; - move16(); } - ELSE IF(L_sub(lt_snr_org, 83886078/* 2.5 Q25 */) > 0) + else if(lt_snr_org > 2.5f) { speech_flag = 3; - move16(); } - ELSE IF(L_sub(lt_snr_org, 67108862/* 2.0 Q25 */) > 0) + else if(lt_snr_org > 2.0f) { speech_flag = 3; - move16(); } - ELSE IF(L_sub(lt_snr_org, 50331647/* 1.5 Q25 */)> 0) + else if(lt_snr_org > 1.5f) { speech_flag = 4; - move16(); } - ELSE + else { speech_flag = 4; - move16(); } } - - if(sub(noisy_type, SILENCE) == 0) + if(noisy_type==SILENCE) { speech_flag = 2; - move16(); } } } - - IF((sub(vad_flag,1)==0)) + if(vad_flag == 1) { - IF((sub(noisy_type, SILENCE) != 0)) + if(noisy_type != SILENCE) { speech_flag--; } - ELSE + else { - speech_flag = sub(speech_flag, 3); + speech_flag = speech_flag - 3; } - speech_flag = s_max(speech_flag, 0); - } + if(speech_flag < 0) + { + speech_flag = 0; + } + } return speech_flag; } - -Word16 comvad_decision( T_CldfbVadState *st, - Word32 l_snr, /*(i) long time frequency domain*/ - Word32 lt_snr_org, /*(i) original long time SNR*/ - Word32 lt_snr, /*(i) long time SNR calculated by fg_energy and bg_energy*/ - Word32 snr_flux, /*(i) average tsnr of several frames*/ - Word32 snr, /*(i) frequency domain SNR */ - Word32 tsnr, /*(i) time domain SNR */ - Word32 frame_energy, /*(i) current frame energy */ - Word16 music_backgound_f, /*(i) background music flag*/ - Word16 frame_energy_Q, /*(i) the Scaling of current frame energy*/ - Word16 *cldfb_addition, /*o: adjust the harmonized hangover */ - Word16 vada_flag - ) -{ - Word16 speech_flag; - Word32 fg_energy; - Word32 bg_energy; - Word32 tmp_snr; - Word16 vad_flag; - Word16 vadb_flag; - Word32 l_silence_snr_count; - Word32 snr_sub; - Word32 snr_div_fix32; - Word32 l_silence_snr; - - Word16 snr_div_fix; - Word16 Qnorm_silence,Qnorm_silence_count; - Word16 tmpout; - Word16 noisy_type; - Word32 lt_snr_org_cmp; - - - - /* avoid overflows in the following if conditions */ - tsnr = L_shr(tsnr,1); - - noisy_type = UNKNOWN_NOISE; - move16(); - speech_flag = st->speech_flag; - move16(); - fg_energy = L_add(st->fg_energy,0); - bg_energy = L_add(st->bg_energy,0); - - Qnorm_silence = 0; - move16(); - Qnorm_silence_count = 0; - move16(); - - test(); - IF(L_sub(st->lf_snr_smooth, LS_MIN_SILENCE_SNR[st->bw_index - CLDFBVAD_NB_ID] ) > 0 && L_sub(lt_snr_org, LT_MIN_SILENCE_SNR[st->bw_index - CLDFBVAD_NB_ID] )> 0) - { - noisy_type = SILENCE; - move16(); - } - - tmp_snr = construct_snr_thresh( st->sp_center, - snr_flux, - lt_snr, - l_snr, - st->continuous_speech_num, - st->continuous_noise_num, - st->fg_energy_est_start, - st->bw_index); - - { - vad_flag = 0; - move16(); - if(L_sub(snr, tmp_snr) > 0) - { - vad_flag = 1; - move16(); - } - - if(L_sub(tsnr, 67108862/* 4.0/2.0 Q25 */) > 0 ) - { - vad_flag = 1; - move16(); - } - } - - IF(sub(st->frameloop, 25) > 0) - { - test(); - IF(sub(vad_flag, 1) == 0 && L_sub(st->fg_energy_est_start, 1) == 0) - { - Word32 frame_energy_mult_fix32,bg_energy_mult_fix32; - Word16 frame_energy_mult_Q,bg_energy_mult_Q; - - IF(sub(st->fg_energy_count, 512) == 0) - { - fg_energy = MUL_F(fg_energy, 0x6000); - st->fg_energy_count = 384; - move16(); - } - - frame_energy_mult_fix32 = MUL_F(frame_energy, st->bg_energy_count); - frame_energy_mult_Q = sub(frame_energy_Q, 15); - - bg_energy_mult_fix32 = MUL_F(bg_energy, 6); - bg_energy_mult_Q = sub(st->bg_energy_scale, 15); - - IF(sub(frame_energy_mult_Q, bg_energy_mult_Q) > 0) - { - frame_energy_mult_fix32 = L_shr(frame_energy_mult_fix32,sub(frame_energy_mult_Q, bg_energy_mult_Q)); - } - IF(sub(frame_energy_mult_Q, bg_energy_mult_Q) < 0) - { - bg_energy_mult_fix32 = L_shr(bg_energy_mult_fix32,limitScale32(sub(bg_energy_mult_Q, frame_energy_mult_Q))); - } - - IF(L_sub(frame_energy_mult_fix32, bg_energy_mult_fix32) > 0) - { - fg_energy = VAD_L_ADD(fg_energy, st->fg_energy_scale, frame_energy, frame_energy_Q, &st->fg_energy_scale); - st->fg_energy_count = add(st->fg_energy_count, 1); - move16(); - } - } - } - - if(music_backgound_f) - { - vad_flag = 1; - move16(); - } - - IF(sub(vad_flag, 1) == 0) - { - IF (st->l_silence_snr == 0) - { - snr_div_fix = 0; - move16(); - } - ELSE - { - Qnorm_silence=sub(norm_l(st->l_silence_snr), 1); - Qnorm_silence_count=norm_l(st->l_silence_snr_count); - l_silence_snr = L_shl(st->l_silence_snr,Qnorm_silence); - l_silence_snr_count = L_shl(st->l_silence_snr_count,Qnorm_silence_count); - snr_div_fix = div_l(l_silence_snr,extract_h(l_silence_snr_count)); - } - snr_sub = L_sub(snr, 0x3000000); - snr_div_fix32 = L_deposit_l(snr_div_fix); - snr_div_fix32 = L_shr(snr_div_fix32, add(6, sub(Qnorm_silence, Qnorm_silence_count))); - - - IF(L_sub(snr_sub, snr_div_fix32) > 0) - { - IF(L_sub(st->l_speech_snr_count, 512) == 0) - { - st->l_speech_snr = L_add(MUL_F(st->l_speech_snr, 0x6000), L_shr(snr, 9)); - move32(); - st->l_speech_snr_count = L_deposit_l(384+1); - move32(); - } - ELSE - { - st->l_speech_snr = L_add(st->l_speech_snr, L_shr(snr, 9)); - move32(); - st->l_speech_snr_count = L_add(st->l_speech_snr_count, 1); - move32(); - } - } - } - - lt_snr_org_cmp = L_sub(lt_snr_org, 117440509/* 3.5 Q25 */); - - IF(sub(st->bw_index, CLDFBVAD_NB_ID) == 0) - { - Word32 lt_snr_add; - - lt_snr_add = L_add(0x03cccccd, MUL_F(lt_snr, 0x23d7)); - - if(L_sub(snr_flux, lt_snr_add) > 0) - { - vad_flag = 1; - move16(); - } - - test(); - test(); - if( (L_sub(snr_flux, 50331647/* 1.5 Q25 */) > 0) && (sub(st->sp_center[3], 1637/* 1.6 Q10 */) > 0) && (lt_snr_org_cmp < 0) ) - { - vad_flag = 1; - move16(); - } - - test(); - test(); - if( (L_sub(snr_flux, 40265317/* 1.2 Q25 */) > 0) && (sub(st->sp_center[3], 1944/* 1.9 Q10 */) > 0) && (lt_snr_org_cmp < 0) ) - { - vad_flag = 1; - move16(); - } - - test(); - test(); - if((L_sub(snr_flux, 33554431/* 1.0 Q25 */) > 0) && (sub(st->sp_center[3], 3274/* 3.2 Q10 */) > 0) && (lt_snr_org_cmp < 0)) - { - vad_flag = 1; - move16(); - } - } - ELSE IF(sub(st->bw_index, CLDFBVAD_WB_ID) == 0) - { - Word32 lt_snr_add; - - lt_snr_add = L_add(0x04333333, MUL_F(lt_snr, 0x1eb8)); - - if(L_sub(snr_flux, lt_snr_add) > 0) - { - vad_flag = 1; - move16(); - } - - test(); - test(); - if((L_sub(snr_flux, 53687090/* 1.6 Q25 */) > 0 ) && (sub(st->sp_center[3], 2558/* 2.5 Q10 */) > 0) && (lt_snr_org_cmp < 0)) - { - vad_flag = 1; - move16(); - } - - test(); - test(); - if((L_sub(snr_flux, 40265317/* 1.2 Q25 */) > 0) && (sub(st->sp_center[3], 2864/* 2.8 Q10 */) > 0) && (lt_snr_org_cmp < 0)) - { - vad_flag = 1; - move16(); - } - - test(); - test(); - if((L_sub(snr_flux, 33554431/* 1.0 Q25 */) > 0) && (sub(st->sp_center[3], 4604/* 4.5 Q10 */) > 0) && (lt_snr_org_cmp < 0)) - { - vad_flag = 1; - move16(); - } - } - ELSE - { - Word32 lt_snr_add; - - lt_snr_add = L_add(0x04333333, MUL_F(lt_snr, 0x28f5)); - - if((L_sub(snr_flux, lt_snr_add) > 0)) - { - vad_flag = 1; - move16(); - } - - test(); - test(); - if((L_sub(snr_flux, 56371444/* 1.68 Q25 */) > 0) && (sub(st->sp_center[3], 2823/* 2.76 Q10 */) > 0) && (lt_snr_org_cmp < 0)) - { - vad_flag = 1; - move16(); - } - - test(); - test(); - if((L_sub(snr_flux, 41607494/* 1.24 Q25 */) > 0) && (sub(st->sp_center[3], 2987/* 2.92 Q10 */) > 0) && (lt_snr_org_cmp < 0)) - { - vad_flag = 1; - move16(); - } - - test(); - test(); - if((L_sub(snr_flux, 36909874/* 1.10 Q25 */) > 0) && (sub(st->sp_center[3], 4706/* 4.6 Q10 */) > 0) && (lt_snr_org_cmp < 0)) - { - vad_flag = 1; - move16(); - } - } - - - IF(st->fg_energy_est_start==0) - { - tmpout = VAD_L_CMP(frame_energy, frame_energy_Q, 50, 0); - - test(); - test(); - if(sub(st->ltd_stable_rate[0], 2621/* 0.08 Q15 */) > 0 && sub(vad_flag,1) == 0 && (tmpout> 0)) - { - st->fg_energy_est_start = L_deposit_l(1); - } - } - - speech_flag = comvad_hangover( lt_snr_org, - snr, - l_snr, - snr_flux, - st->bw_index, - vad_flag, - speech_flag, - st->continuous_speech_num2, - noisy_type); - - - - test(); - IF(vad_flag == 0 && speech_flag > 0) - { - speech_flag = sub(speech_flag, 1); - vad_flag = 1; - move16(); - } - vadb_flag = vad_flag; - - IF(sub(st->bw_index, CLDFBVAD_SWB_ID) == 0) - { - test(); - test(); - test(); - IF(sub(SILENCE, noisy_type) == 0 - && L_sub(snr, 6710886/* 0.2 Q25 */) > 0 - && vad_flag == 0) - { - vad_flag = vada_flag; - move16(); - } - ELSE IF(L_sub(st->lf_snr_smooth,352321526/* 10.5 Q25 */)<0 || sub(SILENCE, noisy_type) != 0) - { - test(); - test(); - test(); - IF(L_sub(snr_flux, 67108862/* 2.0 Q25 */) > 0 - || (st->continuous_speech_num2 > 40 && L_sub(snr_flux, 60397976/* 1.8 Q25 */) > 0) - || music_backgound_f == 1) - { - vad_flag = s_or(vad_flag, vada_flag); - } - ELSE IF(sub(SILENCE, noisy_type) == 0) - { - vad_flag = vada_flag; - } - } - - } - ELSE IF(sub(st->bw_index, CLDFBVAD_WB_ID) == 0) - { - test(); - test(); - test(); - IF(sub(SILENCE, noisy_type) == 0 - && L_sub(snr, 6710886/* 0.2 Q25 */) > 0 - && vad_flag == 0) - { - vad_flag = vada_flag; - move16(); - } - ELSE IF(L_sub(st->lf_snr_smooth,352321526/* 10.5 Q25 */)<0 || sub(SILENCE, noisy_type) != 0) - { - test(); - test(); - test(); - IF(L_sub(snr_flux, 73819748/* 2.2 Q25 */) > 0 - || (st->continuous_speech_num2 > 40 && L_sub(snr_flux, 50331647/* 1.5 Q25 */) > 0) - || music_backgound_f == 1) - { - vad_flag = s_or(vad_flag, vada_flag); - } - ELSE IF(sub(SILENCE, noisy_type) == 0) - { - vad_flag = vada_flag; - } - - } - - } - ELSE - { - IF(sub(SILENCE, noisy_type) == 0) - { - test(); - IF(L_sub(st->lf_snr_smooth , 419430388/* 12.5 Q25 */) > 0 - && music_backgound_f == 0) - { - vad_flag = vada_flag; - } - } - ELSE - { - test(); - test(); - test(); - IF(L_sub(snr_flux, 67108862/* 2.0 Q25 */) > 0 - || (st->continuous_speech_num2 > 30 && L_sub(snr_flux, 50331647/* 1.5 Q25 */) > 0) - || music_backgound_f == 1) - { - vad_flag = s_or(vad_flag, vada_flag); - } - } - } - - IF(vad_flag == 0) - { - IF(L_sub(st->l_silence_snr_count, 512) == 0) - { - st->l_silence_snr = L_add(MUL_F(st->l_silence_snr, 0x6000),L_shr(snr, 9)); - move32(); - st->l_silence_snr_count = L_deposit_l(384+1); - move32(); - } - ELSE IF(L_sub(snr, 26843545/* 0.8 Q25 */) < 0) - { - st->l_silence_snr = L_add(st->l_silence_snr, L_shr(snr,9)); - move32(); - st->l_silence_snr_count = L_add(st->l_silence_snr_count, 1); - move32(); - } - } - - IF(add(vad_flag, vada_flag) == 0) - { - IF(sub(st->bg_energy_count, 512) == 0) - { - bg_energy = MUL_F(bg_energy, 0x6000); - st->bg_energy_count = 384; - move16(); - } - - IF(L_sub(tsnr, 16777216/* 1.0/2.0 Q25 */) < 0) - { - bg_energy = VAD_L_ADD(bg_energy, st->bg_energy_scale, frame_energy, frame_energy_Q, &st->bg_energy_scale); - st->bg_energy_count = add(st->bg_energy_count, 1); - move16(); - } - } - - test(); - st->vad_flag_for_bk_update = vad_flag; - IF(sub(st->update_count, 12) < 0 && sub(vadb_flag, 1)==0) - { - st->warm_hang_num = s_max(20, speech_flag); - } - test(); - IF(vad_flag == 0 && st->warm_hang_num > 0) - { - st->warm_hang_num = sub(st->warm_hang_num, 1); - vad_flag = 1; - move16(); - } - - - - - st->lt_snr_org = lt_snr_org; - move32(); - st->fg_energy = fg_energy; - move32(); - st->bg_energy = bg_energy; - move32(); - - st->speech_flag = speech_flag; - move16(); - - move16(); - test(); - IF(sub(noisy_type, SILENCE) == 0 - && sub(st->bw_index, CLDFBVAD_NB_ID) != 0) - { - *cldfb_addition = 2; - } - ELSE - { - *cldfb_addition = 0; - - if(sub(st->bw_index, CLDFBVAD_WB_ID)==0) - { - *cldfb_addition = 3; - move16(); - } - if(sub(st->bw_index, CLDFBVAD_SWB_ID)==0) - { - *cldfb_addition = 1; - move16(); - } - if(sub(st->bw_index, CLDFBVAD_NB_ID)==0) - { - *cldfb_addition = 1; - move16(); - } - - } - - - - - return vad_flag; -} - diff --git a/src/libs/libevs/lib_enc/cor_shif.cpp b/src/libs/libevs/lib_enc/cor_shif.cpp new file mode 100644 index 00000000..b607d518 --- /dev/null +++ b/src/libs/libevs/lib_enc/cor_shif.cpp @@ -0,0 +1,36 @@ +/*==================================================================================== + EVS Codec 3GPP TS26.443 Nov 13, 2018. Version 12.11.0 / 13.7.0 / 14.3.0 / 15.1.0 + ====================================================================================*/ + +#include +#include "prot.h" + +/*-------------------------------------------------------------------* + * Correlation_shift + * + * Find normalized correlation correction dependent on estimated noise + * Note: this variable is basically active only if noise suppression + * is desactivated. * Otherwise, (for default NS = 14 dB and up to 10dB SNR) + * it can be assumed about 0 + *-------------------------------------------------------------------*/ + +#define MAX_CORR_SHIFT 0.5f + +float correlation_shift( /* o : noise dependent voicing correction */ + const float totalNoise /* i : noise estimate over all critical bands */ +) +{ + float corr_shift; + + corr_shift = 0.0f; + if( totalNoise > 28.18225893613955f ) /* to make corr_shift > 0.0 */ + { + /* useful values range from 0 to 1 (can saturate at 1.0) */ + corr_shift = 2.4492e-4f * (float)exp( 0.1596f * totalNoise ) - 0.022f; + } + if( corr_shift > MAX_CORR_SHIFT ) + { + corr_shift = MAX_CORR_SHIFT; + } + return corr_shift; +} diff --git a/src/libs/libevs/lib_enc/cor_shif_fx.cpp b/src/libs/libevs/lib_enc/cor_shif_fx.cpp deleted file mode 100755 index c9c31400..00000000 --- a/src/libs/libevs/lib_enc/cor_shif_fx.cpp +++ /dev/null @@ -1,50 +0,0 @@ -/*==================================================================================== - EVS Codec 3GPP TS26.442 Apr 03, 2018. Version 12.11.0 / 13.6.0 / 14.2.0 - ====================================================================================*/ - -#include "options.h" /* Compilation switches */ -#include "cnst_fx.h" /* Common constants */ -#include "prot_fx.h" /* Function prototypes */ -#include "stl.h" - - -/*-------------------------------------------------------------------* - * correlation_shift_fx - * - * Find normalized correlation correction dependent on estimated noise - * Note: this variable is basically active only if noise suppression - * is desactivated. Otherwise, for default NS = 14 dB and up to 10dB SNR - * it can be assumed about 0 - *-------------------------------------------------------------------*/ - -Word16 correlation_shift_fx( /* o : noise dependent voicing correction Q15 */ - Word16 totalNoise_fx /* i/o: noise estimate over all critical bands Q8 */ -) -{ - Word16 corr_shift_fx, e_Noise, f_Noise, wtmp; - Word32 Ltmp; - - corr_shift_fx = 0; - move16(); - - IF (sub(totalNoise_fx, 7215) > 0) /* to make corr_shift > 0.0 */ - { - /*------------------------------------------------------------* - * useful values range from 0 to 1 (can saturate at 1.0) Q31 value - * corr_shift = 2.4492E-4 * exp(0.1596 * totalNoise) - 0.022 - * Result in Q14 - *------------------------------------------------------------*/ - Ltmp = L_mult(totalNoise_fx, 7545); /* Q24 */ - Ltmp = L_shr(Ltmp, 8); /* Q24 -> Q16 */ - f_Noise = L_Extract_lc(Ltmp, &e_Noise); - wtmp = extract_l(Pow2(14, f_Noise)); /* Put 14 as exponent */ - - e_Noise = sub(e_Noise, 14); /* Retreive exponent of wtmp */ - Ltmp = Mpy_32_16(8, 837, wtmp); /* 2.4492e-4(Q31) * exp(0.1596*totalNoise) */ - Ltmp = L_shl(Ltmp,add(e_Noise, 15)); /* Result in Q31 */ - corr_shift_fx = round_fx(L_sub(Ltmp, 47244640)); /* Represents corr_shift in Q15 */ - } - corr_shift_fx = s_min(corr_shift_fx,16384); /* limit to 0.5 */ - - return corr_shift_fx; -} diff --git a/src/libs/libevs/lib_enc/core_enc_2div.cpp b/src/libs/libevs/lib_enc/core_enc_2div.cpp old mode 100755 new mode 100644 index 8c9e666c..8212d218 --- a/src/libs/libevs/lib_enc/core_enc_2div.cpp +++ b/src/libs/libevs/lib_enc/core_enc_2div.cpp @@ -1,143 +1,115 @@ /*==================================================================================== - EVS Codec 3GPP TS26.442 Apr 03, 2018. Version 12.11.0 / 13.6.0 / 14.2.0 + EVS Codec 3GPP TS26.443 Nov 13, 2018. Version 12.11.0 / 13.7.0 / 14.3.0 / 15.1.0 ====================================================================================*/ - #include #include +#include #include -#include "prot_fx.h" -#include "basop_util.h" #include "options.h" -#include "cnst_fx.h" -#include "stl.h" +#include "cnst.h" +#include "prot.h" +#include "rom_com.h" + + +/*-------------------------------------------------------------------* + * core_encode_twodiv() + * + * Two-div core encoder + *-------------------------------------------------------------------*/ void core_encode_twodiv( - const Word16 new_samples[], - Encoder_State_fx *st, /* i/o : coder memory state */ - const Word16 coder_type, /* i : coding type */ - const Word16 pitch[3], /* i : open-loop pitch values for quantiz. */ - const Word16 voicing[3], /* i : open-loop pitch gains */ - Word16 Aw[NB_SUBFR16k*(M+1)], /* i : weighted A(z) unquant. for subframes*/ - Word16 *Q_new, - Word16 *shift + const float new_samples[], /* i : new samples */ + Encoder_State *st, /* i/o : coder memory state */ + const short coder_type, /* i : coding type */ + const short pitch[3], /* i : open-loop pitch values for quantiz. */ + const float voicing[3], /* i : open-loop pitch gains */ + float Aw[NB_SUBFR16k*(M+1)] /* i : weighted A(z) unquant. for subframes*/ ) { - Word16 n; - Word16 lsp_new[M], lsp_mid[M]; - Word16 lsf_q[M], lsp_q[M], lspmid_q[M]; - Word16 A_q[M+1]; - Word16 param_lpc[NPRM_LPC_NEW]; - Word16 nbits_lpc[2]; - Word16 param_core[2*NPRM_DIV]; - Word16 target_bits; - Word16 gainlpc[2][FDNS_NPTS]; - Word16 gainlpc_e[2][FDNS_NPTS]; - Word16 tnsSize[2]; /* number of tns parameters put into prm */ - Word16 tnsBits[2]; /* number of tns bits in the frame */ - Word16 ltpBits; - Word16 bitsAvailable; - Word32 spectrum_buf[N_MAX]; - Word32 *spectrum[2]; /* MDCT spectrum */ - Word16 spectrum_e[2]; - Word16 indexBuffer[2*((N_MAX/2)+1)]; + short n; + float lsp_new[M], lsp_mid[M]; + float lsf_q[M], lsp_q[M]; + float lspmid_q[M]; + float A_q[M+1]; + int param_lpc[NPRM_LPC_NEW]; + int nbits_lpc[2]; + int param_core[2*NPRM_DIV]; + int target_bits; + float gainlpc[2][FDNS_NPTS]; + int tnsSize[2]; /* number of tns parameters put into prm */ + int tnsBits[2]; /* number of tns bits in the frame */ + int ltpBits; + int bitsAvailable; + int indexBuffer[2*((N_MAX/2)+1)]; CONTEXT_HM_CONFIG hm_cfg[2]; - Word16 i, T_op[3]; - Word16 bits_param_lpc[10], no_param_lpc; + short bits_param_lpc[10], no_param_lpc; + short i, T_op[3]; - spectrum[0] = spectrum_buf; - spectrum[1] = spectrum_buf + N_TCX10_MAX; - hm_cfg[0].indexBuffer = &indexBuffer[0]; - move16(); hm_cfg[1].indexBuffer = &indexBuffer[N_MAX/2+1]; - move16(); - move16(); - move16(); - move16(); - move16(); - move16(); - tnsSize[0] = 0; - tnsSize[1] = 0; - tnsBits[0] = 0; - tnsBits[1] = 0; + set_i( tnsSize, 0, 2 ); + set_i( tnsBits, 0, 2 ); ltpBits = 0; - FOR( i = 0; i < 3; i++ ) + for( i = 0; i < 3; i++ ) { - move16(); T_op[i] = pitch[i]; /* check minimum pitch for quantization */ - IF ( sub(T_op[i], PIT_MIN_SHORTER) < 0 ) + if( T_op[i] < PIT_MIN_SHORTER ) { - move16(); - T_op[i] = shl(T_op[i], 1); + T_op[i] *= 2; } /* convert pitch values to core sampling-rate */ - IF ( sub(st->L_frame_fx, L_FRAME) != 0 ) + if ( st->L_frame != L_FRAME ) { - move16(); - /* T_op[i] = (short)(T_op[i] * (float)st->L_frame_fx/(float)L_FRAME + 0.5f); */ - T_op[i] = round_fx(L_shr(L_mult0(T_op[i], st->L_frame_fx), 8 - 16)); + T_op[i] = (short)(T_op[i] * (float)st->L_frame/(float)L_FRAME + 0.5f); } } + /*--------------------------------------------------------------* * TCX20/TCX10 switching decision *---------------------------------------------------------------*/ - move16(); - st->core_fx = TCX_10_CORE; - if ( sub(st->tcxMode,TCX_20) == 0 ) + if ( st->tcxMode == TCX_10 ) { - move16(); - st->core_fx = TCX_20_CORE; + st->core = TCX_10_CORE; } - assert(st->tcxMode == TCX_20 || st->tcxMode == TCX_10); + else if ( st->tcxMode == TCX_20 ) + { + st->core = TCX_20_CORE; + } + /*--------------------------------------------------------------* * Core Signal Analysis: MDCT, TNS, LPC analysis *---------------------------------------------------------------*/ - core_signal_analysis_high_bitrate( new_samples, - T_op, - voicing, - pitch, - Aw, - lsp_new, - lsp_mid, - st, - tnsSize, - tnsBits, - param_core, - <pBits, - st->L_frame_fx, - st->L_frameTCX, - spectrum, - spectrum_e, - Q_new, - shift - ); + core_signal_analysis_high_bitrate( new_samples, T_op, voicing, pitch, lsp_new, lsp_mid, st, + tnsSize, tnsBits, param_core, <pBits, st->L_frame,st->L_frameTCX ); /*--------------------------------------------------------------* * LPC Quantization *---------------------------------------------------------------*/ - lpc_quantization( st, st->core_fx, st->lpcQuantization, st->lsf_old_fx , lsp_new, lsp_mid, lsp_q, lsf_q, - lspmid_q, NULL, st->clip_var_fx, st->mem_MA_fx, st->mem_AR_fx, - st->narrowBand, coder_type, 0, param_lpc, nbits_lpc, bits_param_lpc, &no_param_lpc, &(st->seed_acelp), - st->Bin_E_fx, st->Bin_E_old_fx, add(*Q_new, Q_SCALE - 2) ); + lpc_quantization( st, st->core, st->lpcQuantization, st->lsf_old, lsp_new, lsp_mid, lsp_q, lsf_q, + lspmid_q, st->mem_MA, st->mem_AR, st->narrowBand, coder_type, + 0, /*No acelp->no need to compute any mid-LPC*/ + param_lpc, nbits_lpc, &(st->seed_acelp), st->sr_core, st->Bin_E, st->Bin_E_old, + bits_param_lpc, &no_param_lpc ); /*--------------------------------------------------------------* - * Rate switching - *---------------------------------------------------------------*/ - IF( st->rate_switching_reset!=0 ) + * Rate switching + *--------------------------------------------------------------*/ + + if( st->rate_switching_reset ) { - Copy( lsp_q, st->lsp_old_fx, M ); - Copy( lsf_q, st->lsf_old_fx, M ); + mvr2r( lsp_q, st->lsp_old, M ); + mvr2r( lsf_q, st->lsf_old, M ); } @@ -146,189 +118,102 @@ void core_encode_twodiv( * Run Two TCX10 *---------------------------------------------------------------*/ - IF ( sub(st->core_fx,TCX_10_CORE) == 0 ) + if( st->core == TCX_10_CORE ) { - Word16 last_ace_mode; + const int last_ace_mode = st->last_core; - - move16(); - last_ace_mode = st->last_core_fx; - - - FOR (n = 0; n < 2; n++) + for (n = 0; n < 2; n++) { - IF(n == 0) + if ( n == 0 ) { - E_LPC_f_lsp_a_conversion(lspmid_q, A_q, M); + lsp2a_stab( lspmid_q, A_q, M ); } - ELSE + else { - E_LPC_f_lsp_a_conversion(lsp_q, A_q, M); + lsp2a_stab(lsp_q, A_q, M); } /* Shape spectrum */ - ShapeSpectrum(&(st->tcx_cfg), - A_q, - gainlpc[n], - gainlpc_e[n], - shr(st->L_frame_fx, 1), - shr(st->tcx_cfg.tcx_coded_lines, 1), - spectrum[n], - st->fUseTns[n], - st - ); + ShapeSpectrum( &(st->tcx_cfg), A_q, gainlpc[n], st->L_frame/2, st->tcx_cfg.tcx_coded_lines/2, st->spectrum[n], st->fUseTns[n], st ); - st->last_core_fx = st->core_fx; - move16(); + st->last_core = st->core; } - st->last_core_fx = last_ace_mode; - move16(); - + st->last_core = last_ace_mode; /* Calculate target bits */ - bitsAvailable = sub(sub(sub(st->bits_frame_core, nbits_lpc[0]), nbits_lpc[1]), st->nb_bits_header_tcx); + bitsAvailable = st->bits_frame_core - nbits_lpc[0] - nbits_lpc[1] - st->nb_bits_header_tcx; /* subtract bits for TCX overlap mode (1 bit: full, 2 bits: half or no overlap) */ - bitsAvailable = sub(bitsAvailable,1); - test(); - if (sub(st->tcx_cfg.tcx_curr_overlap_mode, HALF_OVERLAP) == 0 || sub(st->tcx_cfg.tcx_curr_overlap_mode, MIN_OVERLAP) == 0) + bitsAvailable -= (st->tcx_cfg.tcx_curr_overlap_mode == HALF_OVERLAP || st->tcx_cfg.tcx_curr_overlap_mode == MIN_OVERLAP) ? 2 : 1; + bitsAvailable -= (&st->hIGFEnc)->infoTotalBitsWritten; + + st->measuredBwRatio = 1.f; + + for( n = 0; n < 2; n++ ) { - bitsAvailable = sub(bitsAvailable,1); - } + target_bits = ((bitsAvailable + 1 - n)>>1) - tnsBits[n]; - bitsAvailable = sub(bitsAvailable, st->hIGFEnc.infoTotalBitsWritten); - - /* calculate noise-filling over whole spectrum for TCX10 frames */ - move16(); - st->measuredBwRatio = 0x4000; - - FOR (n = 0; n < 2; n++) - { - target_bits = sub(shr(sub(add(bitsAvailable, 1), n),1), tnsBits[n]); - - if (n == 0) + if( n == 0 ) { - target_bits = sub(target_bits, ltpBits); + target_bits -= ltpBits; } - test(); if(st->enablePlcWaveadjust && n) { - target_bits = sub(target_bits, 1); + target_bits -= 1; } - /* Run TCX10 encoder */ - - QuantizeSpectrum( - &(st->tcx_cfg), - A_q, - NULL, - gainlpc[n], - gainlpc_e[n], - st->synth+n*st->L_frame_fx/2, - shr(st->L_frame_fx, 1), - shr(st->L_frameTCX, 1), - shr(st->tcx_cfg.tcx_coded_lines, 1), - target_bits, - st->tcxonly, - spectrum[n], - &spectrum_e[n], - st->tnsData+n, - st->fUseTns[n], - tnsSize[n], - &(st->LPDmem), - param_core+n*NPRM_DIV, - n, - st, - &hm_cfg[n] - ); + QuantizeSpectrum( &(st->tcx_cfg), A_q, NULL, gainlpc[n], st->synth+n*st->L_frame/2, st->L_frame/2, st->L_frameTCX/2, st->tcx_cfg.tcx_coded_lines/2, + target_bits, st->tcxonly, st->spectrum[n], st->tnsData+n, st->fUseTns[n], tnsSize[n], &(st->LPDmem), param_core+n*NPRM_DIV, n, st, &hm_cfg[n] ); /* Update tcx overlap mode */ - test(); - if ((n > 0) || (st->tcxonly==0)) + if( (n > 0) || !st->tcxonly ) { - move16(); st->tcx_cfg.tcx_last_overlap_mode = st->tcx_cfg.tcx_curr_overlap_mode; } + } - coder_tcx_post( st, &(st->LPDmem), &(st->tcx_cfg), st->synth, A_q, Aw, st->wspeech_enc, *Q_new, *shift ); + coder_tcx_post( st, &(st->LPDmem), &(st->tcx_cfg), st->synth, A_q, Aw, st->wspeech_enc ); } /*--------------------------------------------------------------* * Run One TCX20 *---------------------------------------------------------------*/ - IF ( sub(st->core_fx,TCX_20_CORE) == 0 ) + if( st->core == TCX_20_CORE ) { + lsp2a_stab( lsp_q, A_q, M ); - E_LPC_f_lsp_a_conversion(lsp_q, A_q, M); + ShapeSpectrum( &(st->tcx_cfg), A_q, gainlpc[0], st->L_frame, st->tcx_cfg.tcx_coded_lines, st->spectrum_long, st->fUseTns[0], st ); - - ShapeSpectrum(&(st->tcx_cfg), - A_q, - gainlpc[0], - gainlpc_e[0], - st->L_frame_fx, - st->tcx_cfg.tcx_coded_lines, - spectrum[0], - st->fUseTns[0], - st - ); + st->measuredBwRatio = 1.f; /* Calculate target bits */ + target_bits = st->bits_frame_core - tnsBits[0] - nbits_lpc[0] - st->nb_bits_header_tcx - ltpBits; - target_bits = sub(sub(sub(sub(st->bits_frame_core, tnsBits[0]), nbits_lpc[0]), st->nb_bits_header_tcx), ltpBits); /* subtract bits for TCX overlap mode (1 bit: full, 2 bits: half or no overlap) */ - target_bits = sub(target_bits,1); - test(); - if (sub(st->tcx_cfg.tcx_curr_overlap_mode, HALF_OVERLAP) == 0 || sub(st->tcx_cfg.tcx_curr_overlap_mode, MIN_OVERLAP) == 0) + target_bits -= (st->tcx_cfg.tcx_curr_overlap_mode == HALF_OVERLAP || st->tcx_cfg.tcx_curr_overlap_mode == MIN_OVERLAP) ? 2 : 1; + + target_bits -= st->hIGFEnc.infoTotalBitsPerFrameWritten; + + if( st->enablePlcWaveadjust ) { - target_bits = sub(target_bits,1); + target_bits -= 1; } - target_bits = sub(target_bits, st->hIGFEnc.infoTotalBitsPerFrameWritten); + QuantizeSpectrum( &(st->tcx_cfg), A_q, NULL, gainlpc[0],st->synth, st->L_frame, st->L_frameTCX,st->tcx_cfg.tcx_coded_lines, target_bits, + st->tcxonly, st->spectrum_long, st->tnsData, st->fUseTns[0], tnsSize[0], &(st->LPDmem), param_core, 0, st, &hm_cfg[0]); - - if(st->enablePlcWaveadjust) - { - target_bits = sub(target_bits, 1); - } - - - QuantizeSpectrum( - &(st->tcx_cfg), - A_q, - NULL, - gainlpc[0], - gainlpc_e[0], - st->synth, - st->L_frame_fx, - st->L_frameTCX, - st->tcx_cfg.tcx_coded_lines, - target_bits, - st->tcxonly, - spectrum[0], - &spectrum_e[0], - &st->tnsData[0], - st->fUseTns[0], - tnsSize[0], - &(st->LPDmem), - param_core, - 0, - st, - &hm_cfg[0] - ); - - coder_tcx_post( st, &(st->LPDmem), &(st->tcx_cfg), st->synth, A_q, Aw, st->wspeech_enc, *Q_new, *shift ); + coder_tcx_post( st, &(st->LPDmem), &(st->tcx_cfg), st->synth, A_q, Aw, st->wspeech_enc ); } /* Update lsp/lsf memory */ - Copy(lsf_q, st->lsf_old_fx, M); - Copy(lsp_q, st->lsp_old_fx, M); + mvr2r( lsf_q, st->lsf_old, M ); + mvr2r( lsp_q, st->lsp_old, M ); @@ -336,7 +221,8 @@ void core_encode_twodiv( * Generate Bitstream *---------------------------------------------------------------*/ - enc_prm( coder_type, param_core, param_lpc, st, st->L_frame_fx, hm_cfg, bits_param_lpc, no_param_lpc ); + enc_prm( coder_type, param_core, param_lpc, st, st->L_frame, hm_cfg, bits_param_lpc, no_param_lpc ); + + return; } - diff --git a/src/libs/libevs/lib_enc/core_enc_init.cpp b/src/libs/libevs/lib_enc/core_enc_init.cpp old mode 100755 new mode 100644 index 401745c4..cd013c11 --- a/src/libs/libevs/lib_enc/core_enc_init.cpp +++ b/src/libs/libevs/lib_enc/core_enc_init.cpp @@ -1,27 +1,25 @@ /*==================================================================================== - EVS Codec 3GPP TS26.442 Apr 03, 2018. Version 12.11.0 / 13.6.0 / 14.2.0 + EVS Codec 3GPP TS26.443 Nov 13, 2018. Version 12.11.0 / 13.7.0 / 14.3.0 / 15.1.0 ====================================================================================*/ #include -#include "prot_fx.h" -#include "basop_mpy.h" -#include "options.h" -#include "cnst_fx.h" -#include "stl.h" -#include "count.h" -#include "basop_util.h" -#include "rom_com_fx.h" #include +#include "options.h" +#include "cnst.h" +#include "prot.h" +#include "rom_com.h" /*-----------------------------------------------------------------------* * Local functions *-----------------------------------------------------------------------*/ -static void init_tcx( Encoder_State_fx *st, Word16 L_frame_old ); -static void init_core_sig_ana( Encoder_State_fx *st ); -static void init_acelp( Encoder_State_fx *st, Word16 L_frame_old, const Word16 shift); -static void init_modes( Encoder_State_fx *st ); +static void init_tcx( Encoder_State *st, int L_frame_old ); +static void init_sig_buffers( Encoder_State *st, const int L_frame_old, const short L_subfr ); +static void init_core_sig_ana( Encoder_State *st ); +static void init_acelp( Encoder_State *st, int L_frame_old ); +static void init_modes( Encoder_State *st ); + /*-----------------------------------------------------------------------* * init_coder_ace_plus() @@ -29,106 +27,79 @@ static void init_modes( Encoder_State_fx *st ); * Initialization of state variables *-----------------------------------------------------------------------*/ -void init_coder_ace_plus(Encoder_State_fx *st, const Word16 shift) +void init_coder_ace_plus( Encoder_State *st ) { - Word16 L_frame_old; /*keep old frame size for switching */ - Word16 L_subfr; - + int L_frame_old; /*keep old frame size for switching */ + short L_subfr; /* Bitrate */ - st->tcxonly = getTcxonly(st->total_brate_fx); - move16(); + st->tcxonly = getTcxonly(st->total_brate); /* Core Sampling Rate */ - st->sr_core = getCoreSamplerateMode2(st->total_brate_fx, st->bwidth_fx, st->rf_mode ); + st->sr_core = getCoreSamplerateMode2(st->total_brate, st->bwidth, st->rf_mode ); st->fscale = sr2fscale(st->sr_core); - move16(); /* Narrowband? */ - st->narrowBand = 0; - move16(); - if( sub(st->bwidth_fx, NB) == 0 ) - { - st->narrowBand = 1; - move16(); - } + st->narrowBand = (st->bwidth == NB)?1:0; /* Core Framing */ - L_frame_old = st->last_L_frame_fx; - move16(); - st->L_frame_fx = extract_l(Mult_32_16(st->sr_core , 0x0290)); + L_frame_old = st->last_L_frame; + st->L_frame = st->sr_core / 50; st->L_frame_past = -1; - move16(); - st->L_frameTCX = extract_l(Mult_32_16(st->input_Fs_fx , 0x0290)); + st->L_frameTCX = st->input_Fs / 50; - st->nb_subfr = NB_SUBFR; - move16(); - L_subfr = shr(st->L_frame_fx, 2); - test(); - IF ( sub(st->L_frame_fx, L_FRAME16k) == 0 && L_sub(st->total_brate_fx, 32000) <= 0 ) + if( st->L_frame == L_FRAME16k && st->total_brate <= ACELP_32k ) { st->nb_subfr = NB_SUBFR16k; - move16(); - L_subfr = mult(st->L_frame_fx, 0x199A); /*1/5 = 0x199A Q15*/ move16(); } + else + { + st->nb_subfr = NB_SUBFR; + } + L_subfr = st->L_frame/st->nb_subfr; /* Core Lookahead */ - st->encoderLookahead_enc = NS2SA_fx2(st->sr_core, ACELP_LOOK_NS); - move16(); - st->encoderLookahead_FB = NS2SA_fx2(st->input_Fs_fx, ACELP_LOOK_NS); - move16(); + st->encoderLookahead_enc = NS2SA(st->sr_core, ACELP_LOOK_NS); + st->encoderLookahead_FB = NS2SA(st->input_Fs, ACELP_LOOK_NS); - IF ( st->ini_frame_fx == 0 ) + if( st->ini_frame == 0 ) { st->acelpFramesCount = 0; - move16(); - st->prevTempFlatness_fx = 128/*1.0f Q7*/; - move16(); + st->prevTempFlatness = 1.0f; } /* Initialize TBE */ - st->prev_coder_type_fx = GENERIC; - move16(); - set16_fx( st->prev_lsf_diff_fx, 16384, LPC_SHB_ORDER-2 ); - st->prev_tilt_para_fx = 0; - move16(); - set16_fx( st->cur_sub_Aq_fx, 0, M+1 ); + st->prev_coder_type = GENERIC; + set_f( st->prev_lsf_diff, 0.5f, LPC_SHB_ORDER-2 ); + st->prev_tilt_para = 0.0f; + set_zero( st->cur_sub_Aq, M+1 ); - st->currEnergyHF_fx = 0; - move16(); - st->currEnergyHF_e_fx = 0; - move16(); - st->energyCoreLookahead_Fx = 0; - move16(); + st->currEnergyHF = 0; /* Initialize LPC analysis/quantization */ - st->lpcQuantization = 0; - move16(); - test(); - if( L_sub(st->sr_core,16000) <= 0 && st->tcxonly == 0 ) + if( st->sr_core <= 16000 && st->tcxonly == 0 ) { st->lpcQuantization = 1; - move16(); + } + else + { + st->lpcQuantization = 0; } - - st->next_force_safety_net_fx = 0; - move16(); - test(); - test(); - IF ( sub(st->last_L_frame_fx,st->L_frame_fx) != 0 || sub(st->last_core_fx,AMR_WB_CORE) == 0 || sub(st->last_core_fx,HQ_CORE) == 0 ) + st->next_force_safety_net = 0; + if( (st->last_L_frame != st->L_frame) || (st->last_core == AMR_WB_CORE) || (st->last_core == HQ_CORE) ) { - set16_fx( st->mem_MA_fx, 0, M ); - Copy(GEWB_Ave_fx, st->mem_AR_fx, M); + set_f( st->mem_MA, 0.0f, M ); + mvr2r( GEWB_Ave, st->mem_AR, M ); } /* Initialize IGF */ + memset( &st->hIGFEnc, 0, sizeof(st->hIGFEnc) ); st->hIGFEnc.infoStopFrequency = -1; - move16(); - IF( st->igf ) + if( st->igf ) { - IGFEncSetMode(&st->hIGFEnc, st->total_brate_fx, st->bwidth_fx, st->rf_mode); + IGFEncSetMode( &st->hIGFEnc, st->total_brate, st->bwidth, st->rf_mode ); } /* Initialize TCX */ @@ -139,59 +110,50 @@ void init_coder_ace_plus(Encoder_State_fx *st, const Word16 shift) /* Initialize Signal Buffers */ init_sig_buffers( st, L_frame_old, L_subfr ); - /* Initialize ACELP */ - init_acelp( st, L_frame_old , shift); - - if(st->ini_frame_fx == 0) + init_acelp( st, L_frame_old ); + if( st->ini_frame == 0 ) { st->tec_tfa = 0; - move16(); } - IF(st->tec_tfa == 0) + if( st->tec_tfa == 0 ) { - resetTecEnc_Fx(&st->tecEnc, 0); + resetTecEnc( &(st->tecEnc), 0); } - ELSE + else { - resetTecEnc_Fx(&st->tecEnc, 1); + resetTecEnc( &(st->tecEnc), 1); } - st->tec_tfa = 0; - move16(); - test(); - test(); - if( sub(st->bwidth_fx, SWB) == 0 && (L_sub(st->total_brate_fx, ACELP_16k40) == 0 || L_sub(st->total_brate_fx, ACELP_24k40) == 0) ) + + if( st->bwidth == SWB && (st->total_brate == ACELP_16k40 || st->total_brate == ACELP_24k40) ) { st->tec_tfa = 1; - move16(); + } + else + { + st->tec_tfa = 0; } st->tec_flag = 0; - move16(); st->tfa_flag = 0; - move16(); + /* Initialize DTX */ - IF( st->ini_frame_fx == 0 ) + if( st->ini_frame == 0 ) { vad_init(&st->vad_st); } - st->glr = 0; - move16(); - - test(); - test(); - test(); - if( (L_sub(st->total_brate_fx, ACELP_9k60)==0)||( L_sub(st->total_brate_fx, ACELP_16k40)==0)|| - (L_sub(st->total_brate_fx, ACELP_24k40)==0)||(L_sub(st->total_brate_fx, ACELP_32k)==0)) + if( st->total_brate == ACELP_9k60 || st->total_brate == ACELP_16k40 || st->total_brate == ACELP_24k40 ) { st->glr = 1; - move16(); + } + else + { + st->glr = 0; } st->glr_reset = 0; - move16(); /* Initialize ACELP/TCX Modes */ init_modes( st ); @@ -200,572 +162,502 @@ void init_coder_ace_plus(Encoder_State_fx *st, const Word16 shift) /* Adaptive BPF */ - set16_fx(st->mem_bpf.noise_buf, 0, 2*L_FILT16k); - set16_fx(st->mem_bpf.error_buf, 0, L_FILT16k); - set16_fx(st->bpf_gainT, 0, NB_SUBFR16k); + set_zero( st->mem_bpf, 2*L_FILT16k ); + set_zero( st->mem_error_bpf, 2*L_FILT16k ); - set16_fx(st->bpf_T, PIT_MIN_12k8, NB_SUBFR16k); - - st->mem_bpf.noise_shift_old = 0; - move16(); - - IF ( st->ini_frame_fx == 0 ) - { - st->Q_max_enc[0] = 15; - move16(); - st->Q_max_enc[1] = 15; - move16(); - } - - st->enablePlcWaveadjust = 0; - move16(); - if (L_sub(st->total_brate_fx, 48000) >= 0) + if( st->total_brate >= HQ_48k ) { st->enablePlcWaveadjust = 1; - move16(); + } + else + { + st->enablePlcWaveadjust = 0; } open_PLC_ENC_EVS( &st->plcExt, st->sr_core ); st->glr_idx[0] = 0; - move16(); st->glr_idx[1] = 0; - move16(); - move16(); - move16(); /* casts */ - st->mean_gc[0] = L_deposit_h(0); - st->mean_gc[1] = L_deposit_h(0); - st->prev_lsf4_mean = 0; - move16(); - - st->last_stab_fac = 0; - move16(); - + st->mean_gc[0] = 0.0f; + st->mean_gc[1] = 0.0f; + st->prev_lsf4_mean = 0.0f; + st->last_stab_fac = 0.0f; return; } -static void init_tcx( Encoder_State_fx *st, Word16 L_frame_old ) + +/*-----------------------------------------------------------------------* + * init_tcx() + * + * Initialization of TCX + *-----------------------------------------------------------------------*/ + +static void init_tcx( + Encoder_State *st, + int L_frame_old +) { - Word16 i; - Word16 fscaleFB; + short mdctWindowLength; + short mdctWindowLengthFB; + /* Share the memories for 2xTCX10/4xTCX5 and for TCX20 */ + st->spectrum[0] = st->spectrum_long; + st->spectrum[1] = st->spectrum_long + N_TCX10_MAX; - fscaleFB = div_l(L_shl(st->input_Fs_fx, LD_FSCALE_DENOM+1), 12800); - - init_TCX_config(&st->tcx_cfg, st->L_frame_fx, st->fscale, st->L_frameTCX, fscaleFB ); + st->tcx_cfg.tcx5Size = NS2SA(st->sr_core, FRAME_SIZE_NS/4); /* Always 5 ms */ + st->tcx_cfg.tcx5SizeFB = NS2SA(st->input_Fs, FRAME_SIZE_NS/4); /* Always 5 ms */ st->tcx_cfg.tcx_mdct_window_length_old = st->tcx_cfg.tcx_mdct_window_length; - move16(); + mdctWindowLength = getMdctWindowLength(st->fscale); + mdctWindowLengthFB = mdctWindowLength * st->input_Fs / st->sr_core; + + /* Initialize the TCX MDCT window */ + /*Symmetric window = sinus LD window*/ + st->tcx_cfg.tcx_mdct_window_delay = mdctWindowLength; + st->tcx_cfg.tcx_mdct_window_delayFB = mdctWindowLengthFB; + st->tcx_cfg.tcx_mdct_window_length = mdctWindowLength; + st->tcx_cfg.tcx_mdct_window_lengthFB = mdctWindowLengthFB; + + mdct_window_sine( st->tcx_cfg.tcx_mdct_window, st->tcx_cfg.tcx_mdct_window_length ); + mdct_window_sine( st->tcx_cfg.tcx_mdct_windowFB, st->tcx_cfg.tcx_mdct_window_lengthFB ); + + mdct_window_sine( st->tcx_cfg.tcx_mdct_window_half, st->tcx_cfg.tcx_mdct_window_length/2 ); + mdct_window_sine( st->tcx_cfg.tcx_mdct_window_halfFB, st->tcx_cfg.tcx_mdct_window_lengthFB/2 ); + + /*ALDO windows for MODE2*/ + mdct_window_aldo(st->tcx_cfg.tcx_aldo_window_1, st->tcx_cfg.tcx_aldo_window_2, st->L_frame); + mdct_window_aldo(st->tcx_cfg.tcx_aldo_window_1_FB, st->tcx_cfg.tcx_aldo_window_2_FB, NS2SA(st->input_Fs, FRAME_SIZE_NS)); + st->tcx_cfg.tcx_aldo_window_1_trunc = st->tcx_cfg.tcx_aldo_window_1 + NS2SA(st->sr_core, N_ZERO_MDCT_NS); + st->tcx_cfg.tcx_aldo_window_1_FB_trunc = st->tcx_cfg.tcx_aldo_window_1_FB + NS2SA(st->input_Fs, N_ZERO_MDCT_NS); + + /*1.25ms transition window for ACELP->TCX*/ + st->tcx_cfg.tcx_mdct_window_trans_length = NS2SA(st->sr_core, ACELP_TCX_TRANS_NS); + mdct_window_sine( st->tcx_cfg.tcx_mdct_window_trans, st->tcx_cfg.tcx_mdct_window_trans_length ); + st->tcx_cfg.tcx_mdct_window_trans_lengthFB = NS2SA(st->input_Fs, ACELP_TCX_TRANS_NS); + mdct_window_sine( st->tcx_cfg.tcx_mdct_window_transFB, st->tcx_cfg.tcx_mdct_window_trans_lengthFB ); + + /*Mid-OLA*/ + /*compute minimum length for "half" window: lookahead - 5ms. It must be also multiple of 2*/ + st->tcx_cfg.tcx_mdct_window_half_length=2*((st->encoderLookahead_enc-(int)(0.005f*st->sr_core+0.5f))>>1); + st->tcx_cfg.tcx_mdct_window_half_lengthFB=2*((st->encoderLookahead_FB-(int)(0.005f*st->input_Fs+0.5f))>>1); + assert( (st->tcx_cfg.tcx_mdct_window_half_length>16) && "Half window can not be large enough!"); + + mdct_window_sine( st->tcx_cfg.tcx_mdct_window_half, st->tcx_cfg.tcx_mdct_window_half_length ); + mdct_window_sine( st->tcx_cfg.tcx_mdct_window_halfFB, st->tcx_cfg.tcx_mdct_window_half_lengthFB ); + + /* minimum overlap 1.25 ms */ + st->tcx_cfg.tcx_mdct_window_min_length = st->sr_core / 800; + st->tcx_cfg.tcx_mdct_window_min_lengthFB = st->input_Fs / 800; + mdct_window_sine(st->tcx_cfg.tcx_mdct_window_minimum, st->tcx_cfg.tcx_mdct_window_min_length); + mdct_window_sine(st->tcx_cfg.tcx_mdct_window_minimumFB, st->tcx_cfg.tcx_mdct_window_min_lengthFB); /* TCX Offset */ - st->tcx_cfg.tcx_offset = shr(st->tcx_cfg.tcx_mdct_window_delay, 1); - move16(); - st->tcx_cfg.tcx_offsetFB = shr(st->tcx_cfg.tcx_mdct_window_delayFB, 1); - move16(); - + st->tcx_cfg.tcx_offset = (st->tcx_cfg.tcx_mdct_window_delay>>1); + st->tcx_cfg.tcx_offsetFB = (st->tcx_cfg.tcx_mdct_window_delayFB>>1); /*<0 rectangular transition with optimized window size = L_frame+L_frame/4*/ - st->tcx_cfg.lfacNext = sub(st->tcx_cfg.tcx_offset, shr(st->L_frame_fx, 2)); - move16(); - st->tcx_cfg.lfacNextFB = sub(st->tcx_cfg.tcx_offsetFB, shr(st->L_frameTCX, 2)); + st->tcx_cfg.lfacNext = st->tcx_cfg.tcx_offset - st->L_frame/4; + st->tcx_cfg.lfacNextFB = st->tcx_cfg.tcx_offsetFB - st->L_frameTCX/4; - IF ( st->ini_frame_fx == 0 ) + if( st->ini_frame == 0 ) { st->tcx_cfg.tcx_curr_overlap_mode = st->tcx_cfg.tcx_last_overlap_mode = ALDO_WINDOW; - move16(); - move16(); } - /* Init TCX target bits correction factor */ - st->LPDmem.tcx_target_bits_fac = 0x4000; /*1.0f in 1Q14*/ move16(); - st->measuredBwRatio = 0x4000; /*1.0f in 1Q14*/ move16(); - st->noiseTiltFactor = 9216; /*0.5625f in 1Q14*/ move16(); + st->LPDmem.tcx_target_bits_fac = 1.0f; + + st->measuredBwRatio = 1.0f; + st->noiseTiltFactor = 0.5625f; st->noiseLevelMemory = 0; - move16(); + /*SQ deadzone & memory quantization*/ - - /*0.375f: deadzone of 1.25->rounding=1-1.25/2 (No deadzone=0.5)*/ - st->tcx_cfg.sq_rounding = 12288/*0.375f Q15*/; - move16(); - - FOR (i = 0; i < L_FRAME_PLUS; i++) - { - st->memQuantZeros[i] = 0; - move16(); - } + st->tcx_cfg.sq_rounding = 0.375f; /*deadzone of 1.25->rounding=1-1.25/2 (No deadzone=0.5)*/ + set_i( st->memQuantZeros, 0, L_FRAME_PLUS ); /* TCX rate loop */ - st->tcx_cfg.tcxRateLoopOpt = 0; - move16(); - - if ( st->tcxonly != 0 ) - { - st->tcx_cfg.tcxRateLoopOpt = 2; - move16(); - } + st->tcx_cfg.tcxRateLoopOpt = (st->tcxonly) ? 2 : 0; /* TCX bandwidth */ - move16(); - st->tcx_cfg.bandwidth = getTcxBandwidth(st->bwidth_fx); - + st->tcx_cfg.bandwidth = getTcxBandwidth(st->bwidth); /* set number of coded lines */ - st->tcx_cfg.tcx_coded_lines = getNumTcxCodedLines(st->bwidth_fx); + st->tcx_cfg.tcx_coded_lines = getNumTcxCodedLines(st->bwidth); /* TNS in TCX */ - move16(); - move16(); - st->tcx_cfg.fIsTNSAllowed = getTnsAllowed(st->total_brate_fx - ,st->igf - ); st->tcx_cfg.pCurrentTnsConfig = NULL; + st->tcx_cfg.fIsTNSAllowed = getTnsAllowed( st->total_brate, st->igf ); - IF ( st->tcx_cfg.fIsTNSAllowed != 0 ) + if( st->tcx_cfg.fIsTNSAllowed ) { - InitTnsConfigs(bwMode2fs[st->bwidth_fx], st->tcx_cfg.tcx_coded_lines, st->tcx_cfg.tnsConfig, st->hIGFEnc.infoStopFrequency, st->total_brate_fx); + InitTnsConfigs( bwMode2fs[st->bwidth], st->tcx_cfg.tcx_coded_lines, st->tcx_cfg.tnsConfig, (&st->hIGFEnc)->infoStopFrequency, st->total_brate); } /* TCX-LTP */ st->tcxltp = getTcxLtp(st->sr_core); - test(); - test(); - test(); - test(); - IF( st->ini_frame_fx == 0 ) + if( st->ini_frame == 0 ) { - - st->tcxltp_pitch_int_past = st->L_frame_fx; - move16(); + st->tcxltp_pitch_int_past = st->L_frame; st->tcxltp_pitch_fr_past = 0; - move16(); - st->tcxltp_gain_past = 0; - move16(); - st->tcxltp_norm_corr_past = 0; - move16(); + st->tcxltp_gain_past = 0.f; + st->tcxltp_norm_corr_past = 0.f; } - ELSE IF ( sub(st->L_frame_fx,L_frame_old) != 0 && !((st->total_brate_fx==16400||st->total_brate_fx==24400)&&(st->total_brate_fx==st->last_total_brate_fx)&&(st->last_bwidth_fx==st->bwidth_fx)) ) + else if( st->L_frame!=L_frame_old && !((st->total_brate==ACELP_16k40||st->total_brate==ACELP_24k40)&&(st->total_brate==st->last_total_brate)&&(st->last_bwidth==st->bwidth)) ) { - Word16 pitres, pitres_old; - Word16 pit, pit_old; + int pitres, pitres_old; + float pit, pit_old; - pitres_old = 4; - move16(); - if (sub(160,shr(L_frame_old,sub(7,norm_s(L_frame_old)))) == 0) /*if ( L_frame_old%160==0 )*/ + if ( L_frame_old%160==0 ) { pitres_old = 6; - move16(); } - - /*pit_old = (float)st->tcxltp_pitch_int_past + (float)st->tcxltp_pitch_fr_past/(float)pitres_old;*/ - pit_old = add(st->tcxltp_pitch_int_past, mult_r(st->tcxltp_pitch_fr_past, div_s(1,pitres_old))); - - pitres = 4; - move16(); - if (sub(160,shr(st->L_frame_fx,sub(7,norm_s(st->L_frame_fx)))) == 0) /*if ( st->L_frame_fx%160==0 )*/ + else + { + pitres_old = 4; + } + pit_old = (float)st->tcxltp_pitch_int_past + (float)st->tcxltp_pitch_fr_past/(float)pitres_old; + if (st->L_frame%160==0 ) { pitres = 6; - move16(); } - - /*pit = pit_old * (float)st->L_frame_fx/(float)L_frame_old;*/ - pit = shl(mult_r(pit_old, div_s(st->L_frame_fx, shl(L_frame_old, 2))), 2); - /* assert(pit <= st->L_frame_fx);*/ - - st->tcxltp_pitch_int_past = pit; - move16(); - move16(); - st->tcxltp_pitch_fr_past = i_mult2(sub(pit,st->tcxltp_pitch_int_past),pitres); - move16(); + else + { + pitres = 4; + } + pit = pit_old * (float)st->L_frame/(float)L_frame_old; + st->tcxltp_pitch_int_past = (int)pit; + st->tcxltp_pitch_fr_past = (int)( (pit-(float)st->tcxltp_pitch_int_past)*(float)pitres ); } + /* Context HM*/ + st->tcx_cfg.ctx_hm = getCtxHm( st->total_brate, st->rf_mode ); + /* Residual Coding*/ - st->tcx_cfg.resq = getResq(st->total_brate_fx); - move16(); + st->tcx_cfg.resq = getResq(st->total_brate); + st->tcx_cfg.tcxRateLoopOpt = (st->tcx_cfg.resq && !st->tcxonly) ? 1 : st->tcx_cfg.tcxRateLoopOpt; - test(); - if ( st->tcx_cfg.resq != 0 && st->tcxonly == 0) - { - st->tcx_cfg.tcxRateLoopOpt = 1; - move16(); - } + st->tcx_lpc_shaped_ari = getTcxLpcShapedAri( st->total_brate, st->bwidth, st->rf_mode ); - st->tcx_cfg.ctx_hm = getCtxHm( st->total_brate_fx, st->rf_mode ); - - st->tcx_lpc_shaped_ari = getTcxLpcShapedAri( - st->total_brate_fx, - st->bwidth_fx - ,st->rf_mode - ); + return; } -void init_sig_buffers( Encoder_State_fx *st, const Word16 L_frame_old, const Word16 L_subfr ) -{ +/*-----------------------------------------------------------------------* + * init_sig_buffers() + * + * Initialization of signal buffers + *-----------------------------------------------------------------------*/ +static void init_sig_buffers( + Encoder_State *st, + const int L_frame_old, + const short L_subfr +) +{ /* Encoder Past Samples at encoder-sampling-rate */ - st->encoderPastSamples_enc = shr(imult1616(st->L_frame_fx, 9), 4); + st->encoderPastSamples_enc = (st->L_frame*9)/16; /* Initialize Signal Buffers and Pointers at encoder-sampling-rate */ - IF ( st->ini_frame_fx == 0 ) + if ( st->ini_frame == 0 ) { - set16_fx(st->buf_speech_enc, 0, L_PAST_MAX_32k+L_FRAME32k+L_NEXT_MAX_32k); - set16_fx(st->buf_speech_enc_pe, 0, L_PAST_MAX_32k+L_FRAME32k+L_NEXT_MAX_32k); - set16_fx(st->buf_speech_ltp, 0, L_PAST_MAX_32k+L_FRAME32k+L_NEXT_MAX_32k); - set16_fx(st->buf_wspeech_enc, 0, L_FRAME16k+L_SUBFR+L_FRAME16k+L_NEXT_MAX_16k); + set_zero(st->buf_speech_enc, L_PAST_MAX_32k+L_FRAME32k+L_NEXT_MAX_32k); + set_zero(st->buf_speech_enc_pe, L_PAST_MAX_32k+L_FRAME32k+L_NEXT_MAX_32k); + set_zero(st->buf_speech_ltp, L_PAST_MAX_32k+L_FRAME32k+L_NEXT_MAX_32k); + set_zero(st->buf_wspeech_enc, L_FRAME16k+L_SUBFR+L_FRAME16k+L_NEXT_MAX_16k); } - ELSE + else if ( st->L_frame!=L_frame_old && !((st->total_brate==16400||st->total_brate==24400)&&(st->total_brate==st->last_total_brate)&&(st->last_bwidth==st->bwidth)) ) { - test(); - test(); - test(); - test(); - test(); - IF ( sub(st->L_frame_fx,L_frame_old) != 0 && !((L_sub(st->total_brate_fx,ACELP_16k40)==0||L_sub(st->total_brate_fx,ACELP_24k40)==0)&&(L_sub(st->total_brate_fx,st->last_total_brate_fx)==0)&&(sub(st->last_bwidth_fx,st->bwidth_fx)==0)) ) + lerp( st->buf_speech_enc, st->buf_speech_enc, st->L_frame, L_frame_old ); + + if( (st->last_core != TCX_20_CORE) && (st->last_core != TCX_10_CORE) ) { - lerp( st->buf_speech_enc, st->buf_speech_enc, st->L_frame_fx, L_frame_old ); - test(); - IF( sub(st->last_core_fx,TCX_20_CORE) != 0 && sub(st->last_core_fx,TCX_10_CORE) != 0 ) /* condition should be checked again */ - { - Copy( st->buf_speech_enc, st->buf_speech_ltp, st->L_frame_fx ); - } - - Copy_Scale_sig( st->old_wsp_fx, st->buf_wspeech_enc+st->L_frame_fx + L_SUBFR-L_WSP_MEM,L_WSP_MEM, sub(st->prev_Q_new, st->prev_Q_old)); - - /*Resamp buffers needed only for ACELP*/ - test(); - test(); - IF( sub(st->L_frame_fx,L_FRAME) == 0 && !st->tcxonly ) - { - Copy_Scale_sig( st->old_inp_12k8_fx, st->buf_speech_enc_pe+st->L_frame_fx-L_INP_MEM,L_INP_MEM, sub(st->prev_Q_new, st->prev_Q_old)); - - } - ELSE IF( sub(st->L_frame_fx,L_FRAME16k) == 0 && !st->tcxonly ) - { - lerp( st->buf_wspeech_enc+st->L_frame_fx + L_SUBFR-L_WSP_MEM, st->buf_wspeech_enc+st->L_frame_fx + L_SUBFR-310, 310, L_WSP_MEM ); - Copy( st->old_inp_16k_fx, st->buf_speech_enc_pe+st->L_frame_fx-L_INP_MEM,L_INP_MEM); - - } - - st->mem_preemph_enc = st->buf_speech_enc[st->encoderPastSamples_enc+st->encoderLookahead_enc-1]; - move16(); - st->mem_wsp_enc = st->buf_wspeech_enc[st->L_frame_fx+L_SUBFR-1]; - move16(); + mvr2r( st->buf_speech_enc, st->buf_speech_ltp, st->L_frame ); } - /*coming from TCXonly modes*/ - ELSE IF( !st->tcxonly && L_sub(st->last_total_brate_fx,ACELP_32k)>=0) + + mvr2r( st->old_wsp, st->buf_wspeech_enc+st->L_frame + L_SUBFR-L_WSP_MEM,L_WSP_MEM); + + /*Resamp buffers needed only for ACELP*/ + if( st->L_frame == L_FRAME && !st->tcxonly ) { - - Copy_Scale_sig( st->old_wsp_fx, st->buf_wspeech_enc+st->L_frame_fx + L_SUBFR-L_WSP_MEM,L_WSP_MEM, sub(st->prev_Q_new, st->prev_Q_old)); - - /*Resamp buffers needed only for ACELP*/ - IF( sub(st->L_frame_fx,L_FRAME16k) == 0) - { - lerp( st->buf_wspeech_enc+st->L_frame_fx + L_SUBFR-L_WSP_MEM, st->buf_wspeech_enc+st->L_frame_fx + L_SUBFR-310, 310, L_WSP_MEM ); - } - st->LPDmem.mem_w0 = 0; - move16(); - st->mem_wsp_enc = st->buf_wspeech_enc[st->L_frame_fx+L_SUBFR-1]; - move16(); + mvr2r( st->old_inp_12k8, st->buf_speech_enc_pe+st->L_frame-L_INP_MEM,L_INP_MEM); } + else if( st->L_frame == L_FRAME16k && !st->tcxonly ) + { + lerp( st->buf_wspeech_enc+st->L_frame + L_SUBFR-L_WSP_MEM, st->buf_wspeech_enc+st->L_frame + L_SUBFR-310, 310, L_WSP_MEM ); + mvr2r( st->old_inp_16k, st->buf_speech_enc_pe+st->L_frame-L_INP_MEM,L_INP_MEM); + } + + st->mem_preemph_enc = st->buf_speech_enc[st->L_frame-1]; + st->mem_wsp_enc = st->buf_wspeech_enc[st->L_frame+L_SUBFR-1]; + + } + /*coming from TCXonly modes*/ + else if( !st->tcxonly && st->last_total_brate>ACELP_32k ) + { + mvr2r( st->old_wsp, st->buf_wspeech_enc+st->L_frame + L_SUBFR-L_WSP_MEM,L_WSP_MEM); + + /*Resamp buffers needed only for ACELP*/ + if( st->L_frame == L_FRAME16k) + { + lerp( st->buf_wspeech_enc+st->L_frame + L_SUBFR-L_WSP_MEM, st->buf_wspeech_enc+st->L_frame + L_SUBFR-310, 310, L_WSP_MEM ); + } + st->LPDmem.mem_w0 = 0; + st->mem_wsp_enc = st->buf_wspeech_enc[st->L_frame+L_SUBFR-1]; } st->new_speech_enc = st->buf_speech_enc + st->encoderPastSamples_enc + st->encoderLookahead_enc; st->new_speech_enc_pe = st->buf_speech_enc_pe + st->encoderPastSamples_enc + st->encoderLookahead_enc; st->new_speech_ltp = st->buf_speech_ltp + st->encoderPastSamples_enc + st->encoderLookahead_enc; - st->new_speech_TCX = st->input_buff + L_FRAME48k + NS2SA(48000, DELAY_FIR_RESAMPL_NS) - NS2SA(st->input_Fs_fx, DELAY_FIR_RESAMPL_NS); + st->new_speech_TCX = st->input_buff + L_FRAME48k + NS2SA(48000, DELAY_FIR_RESAMPL_NS) - NS2SA(st->input_Fs, DELAY_FIR_RESAMPL_NS); st->speech_enc = st->buf_speech_enc + st->encoderPastSamples_enc; st->speech_enc_pe = st->buf_speech_enc_pe + st->encoderPastSamples_enc; st->speech_ltp = st->buf_speech_ltp + st->encoderPastSamples_enc; st->speech_TCX = st->new_speech_TCX - st->encoderLookahead_FB; - st->wspeech_enc = st->buf_wspeech_enc + st->L_frame_fx + L_subfr; + st->wspeech_enc = st->buf_wspeech_enc + st->L_frame + L_subfr; - test(); - test(); - IF( st->ini_frame_fx == 0 || sub(st->L_frame_fx,L_frame_old) != 0 || sub(st->last_codec_mode,MODE1) == 0 ) + if( st->ini_frame == 0 || st->L_frame != L_frame_old || st->last_codec_mode == MODE1 ) { - set16_fx(st->buf_synth, 0, OLD_SYNTH_SIZE_ENC+L_FRAME32k); + set_zero( st->buf_synth, OLD_SYNTH_SIZE_ENC+L_FRAME32k ); } - - st->synth = st->buf_synth + st->L_frame_fx + L_subfr; - + st->synth = st->buf_synth + st->L_frame + L_subfr; return; + } -static void init_core_sig_ana( Encoder_State_fx *st ) + +/*-----------------------------------------------------------------------* + * init_core_sig_ana() + * + * + *-----------------------------------------------------------------------*/ + +static void init_core_sig_ana( + Encoder_State *st +) { - - /* Pre-emphasis factor and memory */ - - st->preemph_fac = PREEMPH_FAC_SWB; /*SWB*/ move16(); - IF ( sub(st->fscale, (16000*FSCALE_DENOM)/12800) < 0 ) + if (st->fscale < (16000*FSCALE_DENOM)/12800) { - st->preemph_fac = PREEMPH_FAC; /*WB*/ move16(); + st->preemph_fac = PREEMPH_FAC; /*WB*/ } - ELSE IF ( sub(st->fscale, (24000*FSCALE_DENOM)/12800) < 0 ) + else if (st->fscale < (24000*FSCALE_DENOM)/12800) { - st->preemph_fac = PREEMPH_FAC_16k; /*WB*/ move16(); + st->preemph_fac = PREEMPH_FAC_16k; /*WB*/ + } + else + { + st->preemph_fac = PREEMPH_FAC_SWB; /*SWB*/ } - st->tcx_cfg.preemph_fac=st->preemph_fac; - move16(); + st->tcx_cfg.preemph_fac = st->preemph_fac; - st->gamma = GAMMA1; - move16(); - st->inv_gamma = GAMMA1_INV; - move16(); - IF ( L_sub(st->sr_core, 16000) == 0 ) + if ( st->sr_core==16000 ) { st->gamma = GAMMA16k; - move16(); - st->inv_gamma = GAMMA16k_INV; - move16(); } - - - st->min_band_fx = 1; - move16(); - st->max_band_fx = 16; - move16(); - - IF ( st->narrowBand == 0) + else { - st->min_band_fx = 0; - move16(); - st->max_band_fx = 19; - move16(); + st->gamma = GAMMA1; } + if( st->narrowBand ) + { + st->min_band = 1; + st->max_band = 16; + } + else + { + st->min_band = 0; + st->max_band = 19; + } + return; } -static void init_acelp( Encoder_State_fx *st, Word16 L_frame_old , const Word16 shift) -{ - Word16 mem_syn_r_size_old; - Word16 mem_syn_r_size_new; +/*-----------------------------------------------------------------------* + * init_acelp() + * + * + *-----------------------------------------------------------------------*/ + +static void init_acelp( + Encoder_State *st, + int L_frame_old +) +{ + short mem_syn_r_size_old; + short mem_syn_r_size_new; /* Init pitch lag */ st->pit_res_max = initPitchLagParameters(st->sr_core, &st->pit_min, &st->pit_fr1, &st->pit_fr1b, &st->pit_fr2, &st->pit_max); - /* Init LPDmem */ - IF( st->ini_frame_fx == 0 ) + if (st->ini_frame == 0) { - set16_fx( st->LPDmem.syn, 0, 1+M ); + set_zero( st->LPDmem.syn, 1+M ); - set16_fx( st->LPDmem.Txnq, 0, L_FRAME32k/2+64); - st->LPDmem.acelp_zir = st->LPDmem.Txnq + shr(st->L_frame_fx,1); - set16_fx( st->LPDmem.mem_syn_r, 0, L_SYN_MEM ); + set_zero( st->LPDmem.Txnq, L_FRAME32k/2+64 ); + st->LPDmem.acelp_zir = st->LPDmem.Txnq + (st->L_frame/2); + set_zero( st->LPDmem.mem_syn_r, L_SYN_MEM ); } - ELSE /*Rate switching*/ + else /*Rate switching*/ { - IF( sub(st->last_core_fx,ACELP_CORE) == 0 ) + if( st->last_core == ACELP_CORE ) { - lerp( st->LPDmem.Txnq,st->LPDmem.Txnq, shr(st->L_frame_fx,1), shr(L_frame_old,1) ); + lerp( st->LPDmem.Txnq,st->LPDmem.Txnq, st->L_frame/2, L_frame_old/2 ); } - ELSE + else { - lerp( st->LPDmem.Txnq,st->LPDmem.Txnq, st->tcx_cfg.tcx_mdct_window_length, st->tcx_cfg.tcx_mdct_window_length_old ); + lerp( st->LPDmem.Txnq, st->LPDmem.Txnq, st->tcx_cfg.tcx_mdct_window_length, st->tcx_cfg.tcx_mdct_window_length_old ); } - st->LPDmem.acelp_zir = st->LPDmem.Txnq + shr(st->L_frame_fx,1); + st->LPDmem.acelp_zir = st->LPDmem.Txnq + (st->L_frame/2); /* Rate switching */ - IF( sub(st->last_codec_mode,MODE1) == 0 ) + if( st->last_codec_mode == MODE1 ) { - Copy( st->mem_syn1_fx, st->LPDmem.mem_syn2, M ); - set16_fx( st->LPDmem.Txnq, 0, L_FRAME32k/2+64); - set16_fx( st->LPDmem.syn, 0, M ); + mvr2r( st->mem_syn1, st->LPDmem.mem_syn2, M ); + set_zero( st->LPDmem.Txnq, L_FRAME32k/2+64 ); + set_zero( st->LPDmem.syn, M ); } - /*AMR-WBIO->MODE2*/ - IF( sub(st->last_core_fx,AMR_WB_CORE) == 0 ) + if( st->last_core == AMR_WB_CORE ) { - st->next_force_safety_net_fx=1; - move16(); - st->last_core_fx = ACELP_CORE; - move16(); + st->next_force_safety_net = 1; + st->last_core = ACELP_CORE; } - /*HQ-CORE->MODE2*/ - test(); - IF( sub(st->last_codec_mode,MODE1)==0 && sub(st->last_core_fx,HQ_CORE) == 0 ) + + if( st->last_codec_mode == MODE1 && st->last_core == HQ_CORE ) { /*Reset of ACELP memories*/ - st->next_force_safety_net_fx=1; - move16(); + st->next_force_safety_net = 1; st->rate_switching_reset = 1; - move16(); st->LPDmem.tilt_code = TILT_CODE; - move16(); - set16_fx( st->LPDmem.old_exc, 0, L_EXC_MEM ); - set16_fx( st->LPDmem.syn, 0, 1+M ); - st->LPDmem.mem_w0 = 0; - move16(); - set16_fx( st->LPDmem.mem_syn, 0, M ); - set16_fx( st->LPDmem.mem_syn2, 0, M ); + set_zero( st->LPDmem.old_exc, L_EXC_MEM ); + set_zero( st->LPDmem.syn, 1+M ); + st->LPDmem.mem_w0 = 0.0f; + set_zero( st->LPDmem.mem_syn, M ); + set_zero( st->LPDmem.mem_syn2, M ); /* unquantized LPC*/ - test(); - IF ( !((L_sub(st->total_brate_fx,ACELP_16k40)==0||L_sub(st->total_brate_fx,ACELP_24k40)==0)&&(L_sub(st->total_brate_fx,st->last_total_brate_fx)==0)&&(sub(st->last_bwidth_fx,st->bwidth_fx)==0)) ) + if ( !((st->total_brate == ACELP_16k40 || st->total_brate == ACELP_24k40) && st->total_brate == st->last_total_brate && st->last_bwidth == st->bwidth) ) { - Copy( st->lsp_old1_fx, st->lspold_enc_fx, M ); /*lsp old @12.8kHz*/ - IF( sub(st->L_frame_fx,L_FRAME16k) == 0 ) + mvr2r( st->lsp_old1, st->lspold_enc, M ); /*lsp old @12.8kHz*/ + if( st->L_frame == L_FRAME16k ) { - lsp_convert_poly_fx( st->lspold_enc_fx, st->L_frame_fx, 0 ); + lsp_convert_poly( st->lspold_enc, st->L_frame, 0 ); } } - Copy( st->lspold_enc_fx, st->lsp_old_fx, M ); /*used unquantized values for mid-LSF Q*/ - IF( st->tcxonly == 0 ) - { - lsp2lsf_fx( st->lsp_old_fx, st->lsf_old_fx, M, st->sr_core ); - } - ELSE - { - E_LPC_lsp_lsf_conversion( st->lsp_old_fx, st->lsf_old_fx, M ); - } - st->last_core_fx = TCX_20_CORE; - move16(); + mvr2r( st->lspold_enc, st->lsp_old, M ); /*used unquantized values for mid-LSF Q*/ + lsp2lsf( st->lsp_old, st->lsf_old, M, st->sr_core ); + + st->last_core = TCX_20_CORE; st->tcx_cfg.last_aldo=1; /*It was previously ALDO*/ st->tcx_cfg.tcx_curr_overlap_mode = ALDO_WINDOW; + /*ALDO overlap windowed past: also used in MODE1 but for other MDCT-FB*/ - set16_fx( st->old_out_fx, 0, st->L_frame_fx ); + set_f( st->old_out, 0, st->L_frame ); + } - ELSE + else { - test(); - test(); - IF( (sub(st->L_frame_fx,L_frame_old) != 0) && (sub(st->L_frame_fx,L_FRAME16k) <= 0) && (sub(L_frame_old,L_FRAME16k) <= 0) ) + if( st->L_frame != L_frame_old && st->L_frame <= L_FRAME16k && L_frame_old <= L_FRAME16k ) /* Rate switching between 12.8 and 16 kHz*/ { + float tmp, A[M+1], Ap[M+1],tmp_buf[M+1]; + /* convert quantized LSP vector */ - st->rate_switching_reset=lsp_convert_poly_fx( st->lsp_old_fx, st->L_frame_fx, 0 ); - IF( st->tcxonly == 0 ) + st->rate_switching_reset = lsp_convert_poly( st->lsp_old, st->L_frame, 0 ); + lsp2lsf( st->lsp_old, st->lsf_old, M, st->sr_core ); + + if( st->L_frame == L_FRAME16k ) { - lsp2lsf_fx( st->lsp_old_fx, st->lsf_old_fx, M, st->sr_core ); + mvr2r( st->lsp_old, st->lspold_enc, M ); } - ELSE + else { - E_LPC_lsp_lsf_conversion( st->lsp_old_fx, st->lsf_old_fx, M ); - } - IF( sub(st->L_frame_fx,L_FRAME16k)==0 ) - { - Copy( st->lsp_old_fx, st->lspold_enc_fx, M ); - } - ELSE - { - Copy( st->lsp_old1_fx, st->lspold_enc_fx, M ); + mvr2r( st->lsp_old1, st->lspold_enc, M ); } - synth_mem_updt2( st->L_frame_fx, st->last_L_frame_fx, st->LPDmem.old_exc, st->LPDmem.mem_syn_r, st->LPDmem.mem_syn2, st->LPDmem.mem_syn, ENC ); + synth_mem_updt2( st->L_frame, st->last_L_frame, st->LPDmem.old_exc, st->LPDmem.mem_syn_r, st->LPDmem.mem_syn2, st->LPDmem.mem_syn, ENC ); - /*Mem of deemphasis stay unchanged : st->LPDmem.syn*/ - { - Word16 tmp, A[M+1], Ap[M+1],tmp_buf[M+1]; - /* Update wsyn */ - /* lsp2a_stab( st->lsp_old, A, M ); */ - E_LPC_f_lsp_a_conversion(st->lsp_old_fx, A, M); - weight_a_fx( A, Ap, GAMMA1, M ); - tmp=0; - move16(); - tmp_buf[0]=0; - move16(); - Copy( st->LPDmem.mem_syn2, tmp_buf+1, M ); - deemph_fx( tmp_buf+1, st->preemph_fac, M, &tmp ); - Residu3_fx( Ap, tmp_buf+M, &tmp, 1, 1 ); - st->LPDmem.mem_w0 = sub(shr(st->wspeech_enc[-1],shift), tmp); - } + /* Update wsyn */ + lsp2a_stab( st->lsp_old, A, M ); + weight_a( A, Ap, GAMMA1, M ); + tmp = 0.f; + tmp_buf[0] = 0.f; + mvr2r( st->LPDmem.mem_syn2, tmp_buf+1, M ); + deemph( tmp_buf+1, st->preemph_fac, M, &tmp ); + residu( Ap, M, tmp_buf+M, &tmp, 1 ); + st->LPDmem.mem_w0 = st->wspeech_enc[-1] - tmp; } - ELSE IF((sub(st->L_frame_fx,L_frame_old) != 0)) + else if( st->L_frame != L_frame_old ) /* Rate switching involving TCX only modes */ { /*Partial reset of ACELP memories*/ - st->next_force_safety_net_fx=1; - move16(); + st->next_force_safety_net = 1; st->rate_switching_reset = 1; - move16(); /*reset partly some memories*/ st->LPDmem.tilt_code = TILT_CODE; - move16(); - set16_fx( st->LPDmem.old_exc, 0, L_EXC_MEM ); - move16(); + set_zero( st->LPDmem.old_exc, L_EXC_MEM ); /*Resamp others memories*/ /*Size of LPC syn memory*/ - /* 1.25/20.0 = 1.0/16.0 -> shift 4 to the right. */ - mem_syn_r_size_old = shr(L_frame_old, 4); - mem_syn_r_size_new = shr(st->L_frame_fx, 4); - + mem_syn_r_size_old = (int)(1.25*L_frame_old/20.f); + mem_syn_r_size_new = (int)(1.25*st->L_frame/20.f); lerp( st->LPDmem.mem_syn_r+L_SYN_MEM-mem_syn_r_size_old, st->LPDmem.mem_syn_r+L_SYN_MEM-mem_syn_r_size_new, mem_syn_r_size_new, mem_syn_r_size_old ); - Copy( st->LPDmem.mem_syn_r+L_SYN_MEM-M, st->LPDmem.mem_syn, M); - Copy( st->LPDmem.mem_syn, st->LPDmem.mem_syn2, M ); + mvr2r( st->LPDmem.mem_syn_r+L_SYN_MEM-M, st->LPDmem.mem_syn, M ); + mvr2r( st->LPDmem.mem_syn, st->LPDmem.mem_syn2, M ); /*Untouched memories : st->LPDmem.syn & st->LPDmem.mem_w0*/ st->LPDmem.mem_w0 = 0; - move16(); /* unquantized LPC*/ - Copy( st->lsp_old1_fx, st->lspold_enc_fx, M ); /*lsp old @12.8kHz*/ - IF( sub(st->L_frame_fx,L_FRAME16k)==0 ) + mvr2r( st->lsp_old1, st->lspold_enc, M ); /*lsp old @12.8kHz*/ + if( st->L_frame == L_FRAME16k ) { - lsp_convert_poly_fx( st->lspold_enc_fx, st->L_frame_fx, 0 ); - } - Copy( st->lspold_enc_fx, st->lsp_old_fx, M ); /*used unquantized values for mid-LSF Q*/ - IF( st->tcxonly == 0 ) - { - lsp2lsf_fx( st->lsp_old_fx, st->lsf_old_fx, M, st->sr_core ); - } - ELSE - { - E_LPC_lsp_lsf_conversion( st->lsp_old_fx, st->lsf_old_fx, M ); + lsp_convert_poly( st->lspold_enc, st->L_frame, 0 ); } + mvr2r( st->lspold_enc, st->lsp_old, M ); /*used unquantized values for mid-LSF Q*/ + lsp2lsf( st->lsp_old, st->lsf_old, M, st->sr_core ); } - ELSE IF( !st->tcxonly && sub(st->L_frame_fx,L_FRAME16k) == 0 && L_sub(st->last_total_brate_fx,ACELP_32k) > 0 ) - { - lsp2lsf_fx( st->lsp_old_fx, st->lsf_old_fx, M, st->sr_core ); - } + /* necessary in BASOP only, due to different representations of st->lsf_old */ + /* else if ( !st->tcxonly && (st->L_frame == L_FRAME16k) && (st->last_total_brate > ACELP_32k) ) */ + /* { */ + /* lsp2lsf( st->lsp_old, st->lsf_old, M, st->sr_core ); */ + /* } */ } } - test(); - test(); - if(sub(st->last_bwidth_fx,NB)==0 && sub(st->bwidth_fx,NB)!=0 && st->ini_frame_fx!=0) + if( st->last_bwidth == NB && st->bwidth != NB && st->ini_frame != 0 ) { - st->rate_switching_reset=1; - move16(); + st->rate_switching_reset = 1; } /* Post-processing */ - st->dm_fx.prev_gain_code = L_deposit_l(0); - set16_fx(st->dm_fx.prev_gain_pit, 0, 6); - st->dm_fx.prev_state = 0; - move16(); - st->LPDmem.gc_threshold = 0; - move16(); + set_zero( st->dispMem, 8 ); + st->LPDmem.gc_threshold = 0.0f; /* Pulse Search configuration */ st->acelp_autocorr = 1; - move16(); /*Use for 12.8 kHz sampling rate and low bitrates, the conventional pulse search->better SNR*/ - if ((L_sub(st->total_brate_fx, ACELP_9k60) <= 0 || st->rf_mode != 0) && (L_sub(st->sr_core,12800) == 0)) + if( ((st->total_brate <= ACELP_9k60 || st->rf_mode == 1) && (st->sr_core == 12800)) ) { st->acelp_autocorr = 0; - move16(); } - /*BPF parameters for adjusting gain in function of background noise*/ - IF( sub(st->codec_mode,MODE2) == 0 ) + if( st->codec_mode == MODE2 ) { - st->mem_bpf.lp_error_ener = L_deposit_l(0); + st->pst_lp_ener = 0.0f; if( st->last_codec_mode == MODE1 ) { - st->mem_bpf.lp_error = L_deposit_l(0); + st->pst_mem_deemp_err = 0.0f; } } @@ -773,78 +665,46 @@ static void init_acelp( Encoder_State_fx *st, Word16 L_frame_old , const Word16 return; } -static void init_modes( Encoder_State_fx *st ) +/*-----------------------------------------------------------------------* + * init_modes() + * + * + *-----------------------------------------------------------------------*/ + +static void init_modes( + Encoder_State *st +) { - Word8 n; - Word32 tmp32; - - - + short n; /* Restrict ACE/TCX20/TCX10 mode */ - move16(); - st->restrictedMode = getRestrictedMode(st->total_brate_fx, st->Opt_AMR_WB_fx); - move16(); - st->acelpEnabled = 0; - move16(); - st->tcx20Enabled = 0; - move16(); - st->tcx10Enabled = 0; - - if (sub(s_and(st->restrictedMode,1),1) == 0) - { - st->acelpEnabled = 1; - move16(); - } - if (sub(s_and(st->restrictedMode,2),2) == 0) - { - st->tcx20Enabled = 1; - move16(); - } - if (sub(s_and(st->restrictedMode,4),4) == 0) - { - st->tcx10Enabled = 1; - move16(); - } - + st->restrictedMode = getRestrictedMode(st->total_brate, st->Opt_AMR_WB); + st->acelpEnabled = (st->restrictedMode & 1) == 1; + st->tcx20Enabled = (st->restrictedMode & 2) == 2; + st->tcx10Enabled = (st->restrictedMode & 4) == 4; /* TCX mode (TCX20 TCX10_10 or NO_TCX) */ st->tcxMode = NO_TCX; - move16(); - /* Bits Budget */ - /*st->bits_frame_nominal = (int)( (float)st->L_frame_fx * (float)FSCALE_DENOM * (float)st->bitrate / ( (float)st->fscale * 12800.0f ) );*/ - /*st->bits_frame_nominal = (int)( (float)st->L_frame_fx/(float)st->fscale * (float)FSCALE_DENOM/128.0f * (float)st->bitrate/100.0f + 0.49f );*/ - /*328 = 0.010009765625 in 0Q15*/ - /* st->bits_frame_nominal = extract_h(L_add(L_mult(div_l(L_mult(shl(st->L_frame_fx,2),st->bitrate),st->fscale),328),16056)); */ + /*st->bits_frame_nominal = (int)( (float)st->L_frame * (float)FSCALE_DENOM * (float)st->total_brate / ( (float)st->fscale * 12800.0f ) );*/ + st->bits_frame_nominal = (int)( (float)st->L_frame/(float)st->fscale * (float)FSCALE_DENOM/128.0f * (float)st->total_brate/100.0f + 0.49f ); - /* st->bits_frame_nominal = (int)( (float)st->L_frame_fx/(float)st->fscale * (float)FSCALE_DENOM/128.0f * (float)st->bitrate/100.0f + 0.49f ); */ - assert(FSCALE_DENOM == 512); - assert(st->fscale == 2 * st->L_frame_fx); /* this assumption is true if operated in 20ms frames with FSCALE_DENOM == 512, which is the current default */ - tmp32 = L_shl(st->total_brate_fx, 1); /* (float)st->L_frame_fx/(float)st->fscale * (float)FSCALE_DENOM/128.0f * (float)st->bitrate */ - st->bits_frame_nominal = extract_l(L_shr(Mpy_32_16_1(tmp32, 20972), 6)); /* 20972 = 0.01 * 64 * 32768 */ - assert(st->bits_frame_nominal == (int)( (float)st->L_frame_fx/(float)st->fscale * (float)FSCALE_DENOM/128.0f * (float)st->total_brate_fx/100.0f + 0.49f )); - - IF (st->Opt_AMR_WB_fx) + if( st->Opt_AMR_WB ) { st->bits_frame = st->bits_frame_nominal; st->bits_frame_core = st->bits_frame_nominal; st->frame_size_index = 0; - move16(); } - ELSE + else { - FOR (n=0; nbits_frame_nominal) == 0) + if (FrameSizeConfig[n].frame_bits==st->bits_frame_nominal) { - move16(); - move16(); - move16(); st->frame_size_index = n; - st->bits_frame = FrameSizeConfig[n].frame_bits; - st->bits_frame_core = FrameSizeConfig[n].frame_net_bits; - BREAK; + st->bits_frame = FrameSizeConfig[n].frame_bits; + st->bits_frame_core = FrameSizeConfig[n].frame_net_bits; + break; } } if (n==FRAME_SIZE_NB) @@ -856,6 +716,5 @@ static void init_modes( Encoder_State_fx *st ) /* Reconfigure core */ core_coder_reconfig( st ); - return; } diff --git a/src/libs/libevs/lib_enc/core_enc_ol.cpp b/src/libs/libevs/lib_enc/core_enc_ol.cpp old mode 100755 new mode 100644 index 99fb41b9..11b36b4c --- a/src/libs/libevs/lib_enc/core_enc_ol.cpp +++ b/src/libs/libevs/lib_enc/core_enc_ol.cpp @@ -1,27 +1,28 @@ /*==================================================================================== - EVS Codec 3GPP TS26.442 Apr 03, 2018. Version 12.11.0 / 13.6.0 / 14.2.0 + EVS Codec 3GPP TS26.443 Nov 13, 2018. Version 12.11.0 / 13.7.0 / 14.3.0 / 15.1.0 ====================================================================================*/ #include #include +#include #include -#include "prot_fx.h" -#include "basop_util.h" #include "options.h" -#include "cnst_fx.h" -#include "stl.h" -#include "stl.h" -#include "rom_com_fx.h" +#include "prot.h" +#include "rom_com.h" +#include "basop_proto_func.h" +/*-------------------------------------------------------------------* + * Local functions + *-------------------------------------------------------------------*/ +static void BITS_ALLOC_ACELP_config_rf( const short coder_type, float *tilt_code, short *rf_frame_type, + short *rf_target_bits, short nb_subfr, short rf_fec_indicator, float *pitch_buf ); -void closest_centroid_rf(const Word16 *data, /* i : input data */ - const Word16 *weights, /* i : weights */ - const Word16 *quantizer, /* i : quantizer table */ - const Word16 centroids, /* i : number of centroids */ - const Word16 length, /* i : dimension of quantiser */ - Word16 *ind_vec); /* o : list of best match indice vectors */ +static void BITS_ALLOC_TCX_config_rf( short *rf_frame_type, short *rf_target_bits, short PLC_Mode, + short coder_type, short last_core, int TD_Mode ); +static void closest_centroid_rf( const float *data, const float *weights, const float *quantizer, + const short centroids, const short length, short *ind_vec ); /*-------------------------------------------------------------------* * core_encode_openloop() @@ -30,177 +31,160 @@ void closest_centroid_rf(const Word16 *data, /* i : input data */ *-------------------------------------------------------------------*/ void core_encode_openloop( - Encoder_State_fx *st, /* i/o: encoder state structure */ - const Word16 coder_type, /* i : coding type */ - const Word16 pitch[3], /* i : open-loop pitch values for quantiz. */ - const Word16 voicing[3], /* i : open-loop pitch gains */ - const Word16 Aw[NB_SUBFR16k*(M+1)], /* i : weighted A(z) unquant. for subframes*/ - const Word16 *lsp_new, /* i : LSPs at the end of the frame */ - const Word16 *lsp_mid, /* i : LSPs at the middle of the frame */ - Word16 *pitch_buf, /* i/o: floating pitch values for each subfr*/ - Word16 *voice_factors, /* o : voicing factors */ - Word16 *ptr_bwe_exc, /* o : excitation for SWB TBE */ - const Word16 vad_hover_flag, - Word16 Q_new, - Word16 shift + Encoder_State *st, /* i/o: encoder state structure */ + const short coder_type, /* i : coding type */ + const short pitch[3], /* i : open-loop pitch values for quantiz. */ + const float voicing[3], /* i : open-loop pitch gains */ + const float Aw[NB_SUBFR16k*(M+1)], /* i : weighted A(z) unquant. for subframes*/ + const float *lsp_new, /* i : LSPs at the end of the frame */ + const float *lsp_mid, /* i : LSPs at the middle of the frame */ + float *pitch_buf, /* i/o: floating pitch values for each subfr*/ + float *voice_factors, /* o : voicing factors */ + float *ptr_bwe_exc, /* o : excitation for SWB TBE */ + const short vad_hover_flag ) { - Word16 lsf_q[M], lsp_q[M], lspmid_q[M], lsf_tcx_q[M], lsp_tcx_q[M]; + float lsf_q[M], lsp_q[M], lspmid_q[M]; Word16 lspq_ind[M]; Word16 A_q_ind[M+1]; - Word16 tcx_lpc_cdk; - Word16 A_w[M+1]; - Word16 A_q[NB_SUBFR16k*(M+1)]; - Word16 param_lpc[NPRM_LPC_NEW]; - Word16 nbits_lpc; - Word16 param_core[2*NPRM_DIV]; - Word16 target_bits; - Word16 stab_fac; - Word32 spectrum_long[N_MAX]; /* MDCT output for a long block */ - Word16 spectrum_long_e; - Word16 indexBuffer[N_MAX+1]; + float A_q_ace[NB_SUBFR16k*(M+1)]; + float A_q_tcx[NB_SUBFR16k*(M+1)]; + int param_lpc[NPRM_LPC_NEW]; + int nbits_lpc; + int param_core[2*NPRM_DIV]; + int target_bits; + float stab_fac; + int indexBuffer[N_MAX+1]; CONTEXT_HM_CONFIG hm_cfg; - Word16 bits_param_lpc[10], no_param_lpc; + float lsp_tcx_q[M], lsf_tcx_q[M]; + int tcx_lpc_cdk; + float A_w[M+1]; + float gain_pitch_buf[NB_SUBFR16k]; + float gain_code_buf[NB_SUBFR16k]; + short bits_param_lpc[10], no_param_lpc; - Word16 i; /* lsf quant parameters */ - Word16 lsp_q_rf[M]; - Word16 Aq_rf[NB_SUBFR*(M+1)]; - Word16 stab_fac_rf; - Word16 *exc_rf; - Word16 *syn_rf; - Word16 tmp; - Word16 rf_PLC_Mode; - Word16 TD_mode; - Word16 xsp[M], xsf[M]; - Word16 rf_mem_MA[M]; + float lsp_q_rf[M]; + float Aq_rf[NB_SUBFR*(M+1)]; + float stab_fac_rf; + float *exc_rf; + float *syn_rf; + short rf_PLC_Mode; + short TD_Mode; + short rf_tcx_lpc_cdk; + float lsp[M], lsf[M]; + float rf_mem_MA[M]; + float exc_buf_rf[L_EXC_MEM + L_FRAME + 1]; + float syn_buf_rf[M+L_FRAME16k+L_FRAME16k/2]; - Word16 exc_buf_rf[L_EXC_MEM + L_FRAME + 1]; - Word16 syn_buf_rf[M+L_FRAME16k+L_FRAME16k/2]; + float w_rf[M], lsf_uq_rf[M]; + float lsf_q_1st_rf[M], lsf_q_d_rf[M], lsf_q_rf[M]; + float lsp_old_q_rf[M], lsf_old_q_rf[M]; - Word16 w_rf[M+1], lsf_uq_rf[M+1]; - Word16 lsf_q_1st_rf[M+1], lsf_q_d_rf[M+1], lsf_q_rf[M+1]; - Word16 lsp_old_q_rf[M+1], lsf_old_q_rf[M+1]; - - - /* copy primary memories to use later during partial copy assembly */ - - /* These primary memories are already scaled by (Q_new-st->prev_Q_new) inside pre_proc_fx() - and copied to the partial frame at start of each frame to be used in computing partial copy params. - But then they are discarded, not need for continuation - The idea is to not maintain these memories seperately, and have the ability to generate the - primary copy memories using the partial copy parameters at decode, so same in enc - */ + /*--------------------------------------------------------------* + * back up parameters for RF + *---------------------------------------------------------------*/ /* back up the old LSPs and LSFs */ - Copy(st->lsp_old_fx, lsp_old_q_rf, M); - Copy(st->lsf_old_fx, lsf_old_q_rf, M); + mvr2r( st->lsp_old, lsp_old_q_rf, M ); + mvr2r( st->lsf_old, lsf_old_q_rf, M ); /* back up old exc before primary encoding */ - set16_fx( exc_buf_rf, 0, (L_EXC_MEM+L_FRAME+1) ); + set_f( exc_buf_rf, 0, (L_EXC_MEM+L_FRAME+1) ); exc_rf = exc_buf_rf + L_EXC_MEM; - Copy(st->LPDmem.old_exc, exc_buf_rf, L_EXC_MEM); + mvr2r(st->LPDmem.old_exc, exc_buf_rf, L_EXC_MEM); /* back up old synthesis before primary encoding */ - set16_fx( syn_buf_rf, 0, (M+L_FRAME16k+L_FRAME16k/2) ); + set_f( syn_buf_rf, 0, (M+L_FRAME16k+L_FRAME16k/2) ); syn_rf = syn_buf_rf + M; - Copy(st->LPDmem.mem_syn, syn_buf_rf, M); + mvr2r(st->LPDmem.mem_syn, syn_buf_rf, M); /* back up syn2 mem */ - Copy(st->LPDmem.mem_syn2, st->rf_mem_syn2, M); + mvr2r(st->LPDmem.mem_syn2, st->rf_mem_syn2, M); /* back up LPD mem_w0 target generation memory */ st->rf_mem_w0 = st->LPDmem.mem_w0; /* back up clip gain memory */ - Copy( st->clip_var_fx, st->rf_clip_var, 6 ); + mvr2r( st->clip_var, st->rf_clip_var, 6 ); /* back up tilt code */ st->rf_tilt_code = st->LPDmem.tilt_code; /* back up dispMem */ - st->rf_dm_fx.prev_state = st->dm_fx.prev_state; - st->rf_dm_fx.prev_gain_code = st->dm_fx.prev_gain_code; - FOR(i=0; i<6; i++) - { - st->rf_dm_fx.prev_gain_pit[i] = st->dm_fx.prev_gain_pit[i]; - } + mvr2r( st->dispMem, st->rf_dispMem, 8 ); /* back up gc_threshold for noise addition */ st->rf_gc_threshold = st->LPDmem.gc_threshold; - /* initialization */ - tcx_lpc_cdk = 0; - move16(); - set16_fx( param_lpc, 0, NPRM_LPC_NEW ); - set16_fx( param_core, 0, 2*NPRM_DIV ); - Copy( st->tcxltp_param, ¶m_core[1+NOISE_FILL_RANGES], LTPSIZE ); - - no_param_lpc = 0; - move16(); /* avoid MSVC warnings */ - nbits_lpc = 0; - move16(); /* avoid MSVC warnings */ - stab_fac = 0; - move16(); /* avoid MSVC warnings */ - - set32_fx(spectrum_long, 0, N_MAX); - - hm_cfg.indexBuffer = indexBuffer; - move16(); /*--------------------------------------------------------------* - * LPC Quantization - *---------------------------------------------------------------*/ + * Initializations + *---------------------------------------------------------------*/ - st->acelp_cfg.midLpc = st->acelp_cfg.midLpc_enable; - move16(); - test(); - if ( (sub(st->lpcQuantization, 1) == 0) && (sub(coder_type, VOICED) == 0)) + tcx_lpc_cdk = 0; + set_i( param_lpc, 0, NPRM_LPC_NEW ); + set_i( param_core, 0, 2*NPRM_DIV ); + mvi2i( st->tcxltp_param, ¶m_core[1+NOISE_FILL_RANGES], LTPSIZE ); + + no_param_lpc = 0; /* avoid MSVC warnings */ + nbits_lpc = 0; /* avoid MSVC warnings */ + stab_fac = 0.0f; /* avoid MSVC warnings */ + + hm_cfg.indexBuffer = indexBuffer; + + /*--------------------------------------------------------------* + * LPC Quantization + *---------------------------------------------------------------*/ + + if( st->lpcQuantization == 1 && coder_type == VOICED ) { - st->acelp_cfg.midLpc = 0; - move16(); + (&(st->acelp_cfg))->midLpc = 0; + } + else + { + (&(st->acelp_cfg))->midLpc=st->acelp_cfg.midLpc_enable; } - test(); - IF ( st->core_fx==ACELP_CORE || !st->enableTcxLpc ) + if( st->core == ACELP_CORE || !st->enableTcxLpc ) { - IF (st->envWeighted) + if( st->envWeighted ) { /* Unweight the envelope */ - E_LPC_lsp_unweight( st->lsp_old_fx, st->lsp_old_fx, st->lsf_old_fx, st->inv_gamma, M ); + E_LPC_lsp_unweight( st->lsp_old, st->lsp_old, st->lsf_old, 1.0f/st->gamma ); st->envWeighted = 0; - move16(); } - IF(sub(st->core_fx,TCX_20_CORE)==0) + if( st->core == TCX_20_CORE ) { - lpc_quantization( st, st->core_fx, st->lpcQuantization, st->lsf_old_fx, lsp_new, lsp_mid, - lsp_q, lsf_q, lspmid_q, lspq_ind, st->clip_var_fx, st-> mem_MA_fx, st->mem_AR_fx, - st->narrowBand, AUDIO, st->acelp_cfg.midLpc, param_lpc, &nbits_lpc, bits_param_lpc, &no_param_lpc, - &(st->seed_acelp), st->Bin_E_fx, st->Bin_E_old_fx, add(Q_new, Q_SCALE - 2) ); - + lpc_quantization( st, st->core, st->lpcQuantization, st->lsf_old, lsp_new, lsp_mid, lsp_q, lsf_q, + lspmid_q, st->mem_MA, st->mem_AR, st->narrowBand, AUDIO, st->acelp_cfg.midLpc, param_lpc, &nbits_lpc, + &(st->seed_acelp), st->sr_core, st->Bin_E, st->Bin_E_old, bits_param_lpc, &no_param_lpc ); } - ELSE + else { - - lpc_quantization( st, st->core_fx, st->lpcQuantization, st->lsf_old_fx, lsp_new, lsp_mid, - lsp_q, lsf_q, lspmid_q, lspq_ind, st->clip_var_fx, st-> mem_MA_fx, st->mem_AR_fx, - st->narrowBand, coder_type, st->acelp_cfg.midLpc, param_lpc, &nbits_lpc, bits_param_lpc, &no_param_lpc, - &(st->seed_acelp), st->Bin_E_fx, st->Bin_E_old_fx, add(Q_new, Q_SCALE - 2) ); + lpc_quantization( st, st->core, st->lpcQuantization, st->lsf_old, lsp_new, lsp_mid, lsp_q, lsf_q, + lspmid_q, st->mem_MA, st->mem_AR, st->narrowBand, coder_type, st->acelp_cfg.midLpc, param_lpc, &nbits_lpc, + &(st->seed_acelp), st->sr_core, st->Bin_E, st->Bin_E_old, bits_param_lpc, &no_param_lpc ); } /*-------------------------------------------------------------* * Rate switching: reset - *---------------------------------------------------------------*/ - IF( st->rate_switching_reset!=0 ) + *-------------------------------------------------------------*/ + + if( st->rate_switching_reset ) { - Copy( lsp_q, st->lsp_old_fx, M ); - Copy( lsf_q, st->lsf_old_fx, M ); - Copy( lsp_q, lspmid_q, M ); + mvr2r( lsp_q, st->lsp_old, M ); + mvr2r( lsf_q, st->lsf_old, M ); + mvr2r( lsp_q, lspmid_q, M ); } - stab_fac = lsf_stab_fx(lsf_q, st->lsf_old_fx, 0, st->L_frame_fx); + /*--------------------------------------------------------------* + * LPC Interpolation + *---------------------------------------------------------------*/ + + stab_fac = lsf_stab( lsf_q, st->lsf_old, 0, st->L_frame ); } @@ -209,96 +193,75 @@ void core_encode_openloop( /*--------------------------------------------------------------* * Run ACELP *---------------------------------------------------------------*/ - IF ( st->core_fx==ACELP_CORE ) + + if( st->core == ACELP_CORE ) { - IF ( st->acelp_cfg.midLpc != 0 ) + if( st->acelp_cfg.midLpc ) { - int_lsp4_fx( st->L_frame_fx, st->lsp_old_fx, lspmid_q, lsp_q, A_q, M, 0 ); + int_lsp4( st->L_frame, st->lsp_old, lspmid_q, lsp_q, A_q_ace, M, 0 ); } - ELSE + else { - int_lsp_fx( st->L_frame_fx, st->lsp_old_fx, lsp_q, A_q, M, interpol_frac_fx, 0 ); + int_lsp( st->L_frame, st->lsp_old, lsp_q, A_q_ace, M, interpol_frac_12k8, 0 ); } /* Calculate target bits */ - target_bits = sub(sub(st->bits_frame_core, nbits_lpc), st->nb_bits_header_ace); + target_bits = st->bits_frame_core - nbits_lpc - st->nb_bits_header_ace; - if(sub(st->rf_mode,1) == 0) + if( st->rf_mode ) { /* joint bit allocation for redundant frame and TBE */ /* calculate target bits for core coding */ - target_bits = sub(target_bits, st->rf_target_bits_write); - } - IF( st->igf != 0 ) - { - target_bits = sub( target_bits, get_tbe_bits_fx( st->total_brate_fx, st->bwidth_fx, st->rf_mode ) ); - + target_bits -= st->rf_target_bits_write; } - if ( st->acelp_cfg.midLpc != 0) + if( st->igf ) { - target_bits = sub(target_bits, MIDLSF_NBITS ); + target_bits -= get_tbe_bits( st->total_brate, st->bwidth, st->rf_mode ); + } + + if( st->acelp_cfg.midLpc ) + { + target_bits -= MIDLSF_NBITS; } if( st->plcExt.enableGplc ) { - target_bits = sub(target_bits, st->plcExt.nBits); + target_bits -= st->plcExt.nBits; } /* reset TBE buffers previous frame frame wasn't ACELP*/ - IF( sub( st->last_core_fx, ACELP_CORE ) != 0 ) + if( st->last_core != ACELP_CORE ) { - TBEreset_enc_fx( st, st->bwidth_fx ); + TBEreset_enc( st, st->bwidth ); } - /* Run ACELP encoder */ - coder_acelp( - &(st->acelp_cfg), - coder_type, - Aw, - A_q, - st->speech_enc_pe, - st->synth, - &(st->LPDmem), - voicing, - pitch, - param_core, - stab_fac, - st, - &st->plcExt, - target_bits, - Q_new, - shift, - pitch_buf, - voice_factors, - ptr_bwe_exc - ); + coder_acelp( &(st->acelp_cfg), coder_type, Aw, A_q_ace, st->speech_enc_pe, + st->synth, &(st->LPDmem), voicing, pitch, param_core, stab_fac, st, &st->plcExt, target_bits, + gain_pitch_buf, gain_code_buf, pitch_buf, voice_factors, ptr_bwe_exc + ); + st->glr_idx[0] = encSideSpecPowDiffuseDetector( st->plcExt.last_lsf_ref, st->plcExt.last_lsf_con, + st->last_sr_core, &(st->prev_lsf4_mean), st->glr, coder_type ); - st->glr_idx[0] = encSideSpecPowDiffuseDetector( st->plcExt.last_lsf_ref, st->plcExt.last_lsf_con, st->last_sr_core, &(st->prev_lsf4_mean), st->glr, coder_type ); - Copy(lsf_q, st->plcExt.last_lsf_ref, M); - Copy(st->plcExt.lsf_con, st->plcExt.last_lsf_con, M); + mvr2r( lsf_q, st->plcExt.last_lsf_ref, M ); + mvr2r( st->plcExt.lsf_con, st->plcExt.last_lsf_con, M ); - updateSpecPowDiffuseIdx(st); + updateSpecPowDiffuseIdx( st, gain_pitch_buf, gain_code_buf ); - if(sub(st->last_stab_fac, 655/*0.02f Q15*/) > 0) + if( st->last_stab_fac > 0.02 ) { - move16(); st->glr_idx[0] = 0; } - move16(); st->last_stab_fac = stab_fac; - move16(); - st->plcExt.LPDmem = &st->LPDmem; - encoderSideLossSimulation( st, &st->plcExt, lsf_q, stab_fac, st->plcExt.calcOnlylsf, st->L_frame_fx); + st->plcExt.LPDmem = &(st->LPDmem); + + encoderSideLossSimulation( st, &st->plcExt, lsf_q, stab_fac, st->plcExt.calcOnlylsf, st->L_frame ); st->tcxltp_norm_corr_past = voicing[1]; - move16(); - st->tcx_cfg.tcx_curr_overlap_mode = st->tcx_cfg.tcx_last_overlap_mode = ALDO_WINDOW; - move16(); } @@ -308,226 +271,189 @@ void core_encode_openloop( * Run TCX20 *---------------------------------------------------------------*/ - IF ( sub(st->core_fx, TCX_20_CORE) == 0 ) + if( st->core == TCX_20_CORE ) { - IF (st->enableTcxLpc) + if( st->enableTcxLpc ) { - IF( sub(st->rf_mode,1)==0) + if( st->rf_mode ) { - Copy(st->mem_MA_fx, rf_mem_MA, M); + mvr2r( st->mem_MA, rf_mem_MA, M ); } - tcx_lpc_cdk = tcxlpc_get_cdk(st->tcx_cfg.coder_type); + tcx_lpc_cdk = tcxlpc_get_cdk( st->tcx_cfg.coder_type ); /* Get the envelope corresponding to the current frame */ - E_LPC_int_lpc_tcx( st->lspold_enc_fx, lsp_new, A_q ); + E_LPC_int_lpc_tcx( st->lspold_enc, lsp_new, A_q_tcx ); /* Weight the envelope */ - weight_a_fx(A_q, A_q, st->gamma, M); + weight_a( A_q_tcx, A_q_tcx, st->gamma, M ); /* Save the weighted envelope */ - Copy(A_q, A_w, M+1); + mvr2r( A_q_tcx, A_w, M+1 ); - /* Convert to xSP and xSF */ - E_LPC_a_lsp_conversion(A_q, xsp, lsp_new, M ); - E_LPC_lsp_lsf_conversion(xsp, xsf, M); + /* Convert to lsp and lsf */ + a2lsp_stab( A_q_tcx, lsp, lsp_new ); + lsp2lsf( lsp, lsf, M, INT_FS_12k8 ); /* Quantize */ - Q_lsf_tcxlpc( xsf, lsf_tcx_q, lspq_ind, param_lpc, M, st->narrowBand, tcx_lpc_cdk, st-> mem_MA_fx, - st->tcx_cfg.coder_type, st->Bin_E_fx, add(Q_new, Q_SCALE-2) ); + Q_lsf_tcxlpc( lsf, lsf_tcx_q, lspq_ind, param_lpc, st->narrowBand, tcx_lpc_cdk, st->mem_MA, st->tcx_cfg.coder_type, st->Bin_E ); /* Account for consumed bits */ nbits_lpc = TCXLPC_NUMBITS; - move16(); - if (param_lpc[0]) + if( param_lpc[0] ) { - nbits_lpc = add(nbits_lpc, TCXLPC_IND_NUMBITS); + nbits_lpc += TCXLPC_IND_NUMBITS; } - /* Convert quantized xSF to xSP and A */ - E_LPC_lsf_lsp_conversion(lsf_tcx_q, lsp_tcx_q, M); - E_LPC_f_lsp_a_conversion(lsp_tcx_q, A_q, M); + /* Convert quantized lsf to lsp and A */ + lsf2lsp( lsf_tcx_q, lsp_tcx_q, M, INT_FS_12k8 ); + lsp2a_stab( lsp_tcx_q, A_q_tcx, M ); } - ELSE + else { - E_LPC_int_lpc_tcx( st->lsp_old_fx, lsp_q, A_q ); + E_LPC_int_lpc_tcx( st->lsp_old, lsp_q, A_q_tcx ); } - IF (st->tcx_lpc_shaped_ari != 0) + if( st->tcx_lpc_shaped_ari ) { - E_LPC_f_lsp_a_conversion(lspq_ind, A_q_ind, M); + basop_E_LPC_f_lsp_a_conversion(lspq_ind, A_q_ind, M); } /* Calculate target bits */ - target_bits = sub(sub(st->bits_frame_core, nbits_lpc), st->nb_bits_header_tcx); - if(sub(st->rf_mode,1) == 0) + target_bits = st->bits_frame_core - nbits_lpc - st->nb_bits_header_tcx; + if( st->rf_mode ) { /* joint bit allocation for redundant frame and TBE */ /* calculate target bits for core coding */ - target_bits = sub(target_bits, st->rf_target_bits_write); + target_bits -= st->rf_target_bits_write; } - IF (sub(st->mdct_sw, MODE1) == 0) + if( st->mdct_sw == MODE1 ) { - /* Account for core mode signaling bits difference: bandwidth and ACELP/TCX signaling bit are replaced */ - target_bits = add(target_bits, sub(add(FrameSizeConfig[st->frame_size_index].bandwidth_bits, 1), signalling_mode1_tcx20_enc(st, 0))); + /* Account for core mode signalling bits difference: bandwidth and ACELP/TCX signaling bit are replaced */ + target_bits += (FrameSizeConfig[st->frame_size_index].bandwidth_bits + 1) - signalling_mode1_tcx20_enc(st, 0); } - ELSE if ( sub(st->mdct_sw_enable, MODE2) == 0 ) + else if( st->mdct_sw_enable == MODE2 ) { - target_bits = sub(target_bits, 1); + --target_bits; } if( st->plcExt.enableGplc ) { - target_bits = sub(target_bits, st->plcExt.nBits); + target_bits -= st->plcExt.nBits; } /* subtract bits for TCX overlap mode (1 bit: full, 2 bits: half or no overlap) */ - target_bits = sub(target_bits,1); - test(); - if (sub(st->tcx_cfg.tcx_curr_overlap_mode, HALF_OVERLAP) == 0 || sub(st->tcx_cfg.tcx_curr_overlap_mode, MIN_OVERLAP) == 0) - { - target_bits = sub(target_bits,1); - } + target_bits -= (st->tcx_cfg.tcx_curr_overlap_mode == HALF_OVERLAP || st->tcx_cfg.tcx_curr_overlap_mode == MIN_OVERLAP) ? 2 : 1; - target_bits = sub(target_bits, st->tcxltp_bits); + target_bits -= st->tcxltp_bits; + + /* Run TCX20 encoder */ + + coder_tcx( 0, &(st->tcx_cfg), + A_q_tcx, A_q_ind, + st->synth, st->L_frame, st->L_frameTCX, st->tcx_cfg.tcx_coded_lines, target_bits, + st->tcxonly, st->spectrum_long, &(st->LPDmem), param_core, st, &hm_cfg); + + coder_tcx_post( st, &(st->LPDmem), &(st->tcx_cfg), st->synth, A_q_tcx, Aw, st->wspeech_enc ); - coder_tcx( - 0, - &(st->tcx_cfg), - A_q, - A_q_ind, - st->synth, - st->L_frame_fx, - st->L_frameTCX, - st->tcx_cfg.tcx_coded_lines, - target_bits, - st->tcxonly, - spectrum_long, - &spectrum_long_e, - &(st->LPDmem), - param_core, - st, - &hm_cfg - ); - - coder_tcx_post( st, &(st->LPDmem), &(st->tcx_cfg), st->synth, A_q, Aw, st->wspeech_enc, Q_new, shift ); - - - move16(); st->plcExt.LPDmem = &(st->LPDmem); - GplcTcxEncSetup(st, &st->plcExt, Q_new); + GplcTcxEncSetup( st, &st->plcExt ); - IF (st->enableTcxLpc) + if( st->enableTcxLpc ) { - E_LPC_lsp_unweight( lsp_tcx_q, lsp_q, lsf_q, st->inv_gamma, M ); + E_LPC_lsp_unweight(lsp_tcx_q, lsp_q, lsf_q, 1.0f/st->gamma ); /* Update lsf_q for encoderSideLossSimulation() */ } - - encoderSideLossSimulation( st, &st->plcExt, lsf_q, stab_fac, 1, st->L_frame_fx ); + encoderSideLossSimulation( st, &st->plcExt, lsf_q, stab_fac, 1, st->L_frame ); } /* Update lsp/lsf memory */ - Copy( lsp_new, st->lspold_enc_fx, M ); + mvr2r( lsp_new, st->lspold_enc, M ); - test(); - IF ( st->enableTcxLpc && st->core_fx != ACELP_CORE ) + if( st->enableTcxLpc && st->core != ACELP_CORE ) { - /* Update lsf/lsp memory */ - Copy(lsf_tcx_q, st->lsf_old_fx, M); - Copy(lsp_tcx_q, st->lsp_old_fx, M); + /* Update lsf / lsp memory */ + mvr2r(lsf_tcx_q, st->lsf_old, M); + mvr2r(lsp_tcx_q, st->lsp_old, M); st->envWeighted = 1; - move16(); /* Update ACELP quantizer state */ - lsf_update_memory( st->narrowBand, st->lsf_old_fx, st-> mem_MA_fx, st-> mem_MA_fx, M ); - - st->pstreaklen_fx = 0; - st->streaklimit_fx = 32767; + lsf_update_memory( st->narrowBand, st->lsf_old, st->mem_MA, st->mem_MA ); + st->pstreaklen = 0; + st->streaklimit = 1.0f; /* check resonance for pitch clipping algorithm */ - gp_clip_test_lsf_fx( st->lsf_old_fx, st->clip_var_fx, 0 ); - Copy(st->lsf_old_fx, st->mem_AR_fx, M); + gp_clip_test_lsf( st->core_brate, st->lsf_old, st->clip_var, 0 ); + mvr2r( st->lsf_old, st->mem_AR, M ); } - ELSE + else { - /* Update ISP/ISF memory */ - Copy(lsf_q, st->lsf_old_fx, M); - Copy(lsp_q, st->lsp_old_fx, M); + mvr2r( lsf_q, st->lsf_old, M ); + mvr2r( lsp_q, st->lsp_old, M ); } - /*--------------------------------------------------------------* - * Update LP_CNG parameters - *--------------------------------------------------------------*/ - - test(); - IF( st->Opt_DTX_ON_fx != 0 && vad_hover_flag != 0 ) + /* Update MODE1 CNG parameters */ + if( st->Opt_DTX_ON && vad_hover_flag ) { - st->burst_ho_cnt_fx = add(st->burst_ho_cnt_fx,1); - if( sub(st->burst_ho_cnt_fx,HO_HIST_SIZE) > 0 ) + st->burst_ho_cnt++; + if( st->burst_ho_cnt > HO_HIST_SIZE ) { - st->burst_ho_cnt_fx = HO_HIST_SIZE; - move16(); + st->burst_ho_cnt = HO_HIST_SIZE; } } - ELSE + else { - st->burst_ho_cnt_fx = 0; - move16(); + st->burst_ho_cnt = 0; } - IF( st->Opt_DTX_ON_fx != 0 ) + if( st->Opt_DTX_ON ) { /* update CNG parameters in active frames */ - IF ( sub(st->bwidth_fx,NB) == 0 && st->enableTcxLpc && st->core_fx != ACELP_CORE ) + if( st->bwidth == NB && st->enableTcxLpc && st->core != ACELP_CORE ) { - Word16 buf[L_LP], res[L_FRAME], A[M+1], r_l[M+1], r_h[M+1], lsptmp[M], Q_r; - assert(st->L_frame_fx==L_FRAME); - Copy(st->synth+L_FRAME-L_LP, buf, L_LP); + float buf[L_LP], res[L_FRAME], A[M+1], r[M+1], tmp, lsptmp[M]; + + assert( st->L_frame==L_FRAME ); + + mvr2r( st->synth+L_FRAME-L_LP, buf, L_LP ); tmp = st->synth[L_FRAME-L_LP-1]; - E_UTIL_f_preemph2(Q_new-1, buf, st->preemph_fac, L_LP, &tmp); - autocorr_fx( buf, M, r_h, r_l, &Q_r, L_LP, Assym_window_W16fx, 0, 0 ); - lag_wind(r_h, r_l, M, INT_FS_FX, LAGW_WEAK); - E_LPC_lev_dur(r_h, r_l, A, NULL, M, NULL); - E_LPC_a_lsp_conversion(A, lsptmp, lsp_new, M); - Residu3_fx(A, buf+L_LP-L_FRAME, res, L_FRAME, 1); - cng_params_upd_fx( lsptmp, res, st->L_frame_fx, &st->ho_circ_ptr_fx, - st->ho_ener_circ_fx, &st->ho_circ_size_fx, st->ho_lsp_circ_fx, - Q_new, ENC, NULL, &st->cng_buf_cnt, st->cng_exc2_buf, - st->cng_Qexc_buf, st->cng_brate_buf, st->last_active_brate_fx ); + preemph( buf, st->preemph_fac, L_LP, &tmp ); + autocorr( buf, r, M, L_LP, LP_assym_window, 0, 0, 0 ); + lag_wind( r, M, INT_FS_12k8, LAGW_WEAK ); + lev_dur( A, r, M, NULL ); + a2lsp_stab( A, lsptmp, lsp_new ); + + residu( A, M, buf+L_LP-L_FRAME, res, L_FRAME ); + + cng_params_upd( lsptmp, res, st->L_frame, &st->ho_circ_ptr, st->ho_ener_circ, + &st->ho_circ_size, st->ho_lsp_circ, ENC, st->ho_env_circ, + &st->cng_buf_cnt, st->cng_exc2_buf, st->cng_brate_buf, st->last_active_brate ); } - ELSE + else { - cng_params_upd_fx( lsp_new, st->LPDmem.old_exc+L_EXC_MEM-st->L_frame_fx, - st->L_frame_fx, &st->ho_circ_ptr_fx, st->ho_ener_circ_fx, - &st->ho_circ_size_fx, st->ho_lsp_circ_fx, Q_new, ENC, NULL, - &st->cng_buf_cnt, st->cng_exc2_buf, - st->cng_Qexc_buf, st->cng_brate_buf, - st->last_active_brate_fx ); + cng_params_upd( lsp_new, st->LPDmem.old_exc+L_EXC_MEM-st->L_frame, st->L_frame, + &st->ho_circ_ptr, st->ho_ener_circ, &st->ho_circ_size, + st->ho_lsp_circ, ENC, st->ho_env_circ, &st->cng_buf_cnt, + st->cng_exc2_buf, st->cng_brate_buf, st->last_active_brate ); } - IF( sub(st->L_frame_fx,L_FRAME) == 0 ) + if( st->L_frame == L_FRAME ) { /* store LSPs@16k, potentially to be used in CNG@16k */ - Copy( st->lsp_old16k_fx, &(st->ho_lsp_circ2_fx[(st->ho_circ_ptr_fx)*M]), M ); + mvr2r( st->lsp_old16k, &(st->ho_lsp_circ2[(st->ho_circ_ptr)*M]), M ); } /* Set 16k LSP flag for CNG buffer */ - st->ho_16k_lsp_fx[st->ho_circ_ptr_fx] = 1; - move16(); - if ( sub(st->L_frame_fx,L_FRAME) == 0 ) - { - st->ho_16k_lsp_fx[st->ho_circ_ptr_fx] = 0; - move16(); - } + st->ho_16k_lsp[st->ho_circ_ptr] = (st->L_frame == L_FRAME ? 0 : 1 ); /* efficient DTX hangover control */ - IF ( sub(st->burst_ho_cnt_fx, 1) > 0 ) + if ( st->burst_ho_cnt > 1 ) { - dtx_hangover_control_fx( st, lsp_new ); + dtx_hangover_control( st, lsp_new ); } } @@ -535,83 +461,66 @@ void core_encode_openloop( * Adaptive Bass Post-filter *---------------------------------------------------------------*/ - test(); - IF (sub(st->core_fx, ACELP_CORE)>0 || (st->rate_switching_reset!=0)) + + if( st->core > ACELP_CORE || st->rate_switching_reset ) { /*TCX mode: copy values*/ - set16_fx(st->mem_bpf.noise_buf, 0, 2*L_FILT16k); /*TCX->no gain*/ - set16_fx(st->mem_bpf.error_buf, 0, L_FILT16k); /*TCX->no gain*/ - st->bpf_gain_param=0; + set_zero( st->mem_bpf, 2*L_FILT16k ); /*TCX->no gain*/ + set_zero( st->mem_error_bpf, 2*L_FILT16k ); /*TCX->no gain*/ + st->bpf_gain_param = 0; } - ELSE IF (st->acelp_cfg.bpf_mode > 0) + else if( st->acelp_cfg.bpf_mode >= 1 ) { /*ACELP: estimate bpf parameter with delay=0*/ /*Estimate bpf parameter*/ - bass_pf_enc( st->speech_enc, st->synth, st->bpf_T, st->bpf_gainT, st->L_frame_fx, L_SUBFR, &(st->bpf_gain_param), st->acelp_cfg.bpf_mode, &(st->mem_bpf) ); + bass_pf_enc( st->speech_enc, st->synth, pitch_buf, gain_pitch_buf, st->L_frame, L_SUBFR, st->mem_bpf, st->mem_error_bpf, + &(st->bpf_gain_param), st->acelp_cfg.bpf_mode ,&(st->pst_lp_ener), &(st->pst_mem_deemp_err) ); + } - - /*--------------------------------------------------------------* * Analysis Print Out *---------------------------------------------------------------*/ + /*--------------------------------------------------------------* * Generate Bitstream *---------------------------------------------------------------*/ - enc_prm( coder_type, param_core, param_lpc, st, st->L_frame_fx, &hm_cfg, bits_param_lpc, no_param_lpc ); + enc_prm( coder_type, param_core, param_lpc, st, st->L_frame, &hm_cfg, bits_param_lpc, no_param_lpc ); /* Channel-aware mode - encode partial copy */ - IF( sub(st->rf_mode,1)==0) + if( st->rf_mode ) { - set16_fx(lsf_q_1st_rf, 0, M); - IF (sub(st->core_fx, ACELP_CORE) == 0) + set_f( lsf_q_1st_rf, 0.0f, M); + + if( st->core == ACELP_CORE ) { - /* convert LSPs to LP coefficients */ - lsp2lsf_fx( lsp_new, lsf_uq_rf, M, st->sr_core ); - /*i: lsp_new Q15 */ - /*o: lsf_uq_rf Qx2.56*/ + /* convert lsp to lsf */ + lsp2lsf( lsp_new, lsf_uq_rf, M, st->sr_core ); /* first stage VQ, 8 bits; reuse TCX high rate codebook */ - st->rf_indx_lsf[0][0] = vlpc_1st_cod(lsf_uq_rf, lsf_q_1st_rf, w_rf, st->rf_mode); - /*v_sub(lsf_uq_rf, lsf_q_1st_rf, lsf_q_d_rf, M);*/ - FOR (i=0; irf_indx_lsf[0][0] = vlpc_1st_cod( lsf_uq_rf, lsf_q_1st_rf, st->sr_core, w_rf ); + v_sub( lsf_uq_rf, lsf_q_1st_rf, lsf_q_d_rf, M ); - /* second stage vq */ - closest_centroid_rf(lsf_q_d_rf, w_rf, lsf_q_diff_cb_8b_rf, (1<<8), M, &st->rf_indx_lsf[0][1]); - /*i: lsf_q_d_rf in Q6 */ - /*o: quantization index Q0 */ + /* second stage vq */ + closest_centroid_rf( lsf_q_d_rf, w_rf, lsf_q_diff_cb_8b_rf, (1<<8), M, &st->rf_indx_lsf[0][1] ); - /* quantized lsf from two stages */ - /*v_add(lsf_q_1st_rf, lsf_q_diff_cb_8b_rf + M * st->rf_indx_lsf[0][1], lsf_q_rf, M);*/ - FOR (i=0; irf_indx_lsf[0][1]]; /*tmp = quantized lsf_q_d_rf in Q6*/ - tmp = shr(mult_r(tmp,20972),4); /* bring lsf_q_d_rf to Qx2.56 for addition */ - lsf_q_rf[i] = add(lsf_q_1st_rf[i], tmp); - } + /* quantized lsf from two stages */ + v_add( lsf_q_1st_rf, lsf_q_diff_cb_8b_rf + M * st->rf_indx_lsf[0][1], lsf_q_rf, M ); v_sort( lsf_q_rf, 0, M-1 ); - reorder_lsf_fx( lsf_q_rf, LSF_GAP_FX, M, st->sr_core ); + reorder_lsf( lsf_q_rf, LSF_GAP, M, st->sr_core ); } - ELSE + else { - Word16 rf_tcx_lpc_cdk; - rf_tcx_lpc_cdk = tcxlpc_get_cdk( GENERIC ); + /* Quantize */ - Q_lsf_tcxlpc( xsf, lsf_tcx_q, lspq_ind, param_lpc, M, st->narrowBand, rf_tcx_lpc_cdk, rf_mem_MA, GENERIC, st->Bin_E_fx, add(Q_new, Q_SCALE-2) ); + Q_lsf_tcxlpc( lsf, lsf_tcx_q, lspq_ind, param_lpc, st->narrowBand, rf_tcx_lpc_cdk, rf_mem_MA, GENERIC, st->Bin_E ); /* VQ, 5+4+4 bits; reuse TCX low rate codebook */ st->rf_indx_lsf[0][0] = param_lpc[1]; @@ -619,22 +528,18 @@ void core_encode_openloop( st->rf_indx_lsf[0][2] = param_lpc[3]; } - IF (sub(st->core_fx, ACELP_CORE) == 0) + if (st->core == ACELP_CORE) { /* current n-th ACELP frame and its corresponding partial copy */ - - /*lsf2lsp( lsf_q_rf, lsp_q_rf, M, st->sr_core );*/ - E_LPC_lsf_lsp_conversion( lsf_q_rf, lsp_q_rf, M ); - /*i: lsf_q_rf in Qx2.56*/ - /*o: lsp_q_rf in Q15*/ + lsf2lsp( lsf_q_rf, lsp_q_rf, M, st->sr_core ); /* Interpolate LSPs and convert to LPC */ - int_lsp_fx( st->L_frame_fx, lsp_old_q_rf, lsp_q_rf, Aq_rf, M, interpol_frac_fx, 0 ); + int_lsp( st->L_frame, lsp_old_q_rf, lsp_q_rf, Aq_rf, M, interpol_frac_12k8, 0 ); - /* stability estimation */ - stab_fac_rf = lsf_stab_fx( lsf_q_rf, lsf_old_q_rf, 0, st->L_frame_fx ); /*Q15*/ + /* stability estimation */ + stab_fac_rf = lsf_stab( lsf_q_rf, lsf_old_q_rf, 0, st->L_frame ); - /* Configure partial copy estimation of the current n-th frame to be packed in future with n+fec_offset frame */ + /* Configure partial copy estimation of the current n-th frame to be packed in future with n+fec_offset frame */ /* o: rf_frame_type, o: rf_target_bits */ BITS_ALLOC_ACELP_config_rf( coder_type, st->rf_tilt_buf, &st->rf_frame_type, &st->rf_target_bits, st->nb_subfr, st->rf_fec_indicator, pitch_buf ); @@ -642,823 +547,532 @@ void core_encode_openloop( st->rf_indx_frametype[0] = st->rf_frame_type; st->rf_targetbits_buff[0] = st->rf_target_bits; - IF( sub(st->rf_frame_type,RF_NO_DATA) != 0 ) + if( st->rf_frame_type != RF__NO_DATA ) { /* coder_acelp_rf does the partial copy encoding based on the rf frame type chosen for the RF encoding */ - coder_acelp_rf(&(st->acelp_cfg_rf), coder_type, Aw, Aq_rf, st->speech_enc_pe, voicing, pitch, - stab_fac_rf, st, st->rf_target_bits, st->rf_frame_type, exc_rf, syn_rf, Q_new, shift); + coder_acelp_rf( st->rf_target_bits, st->speech_enc_pe, coder_type, st->rf_frame_type, Aw, Aq_rf, + voicing, pitch, stab_fac_rf, st, &(st->acelp_cfg_rf), exc_rf, syn_rf ); } } - ELSE + else { - st->rf_clas[0] = st->clas_fx; - move16(); + + TD_Mode = 1; + st->rf_clas[0] = st->clas; st->rf_gain_tcx[0] = param_core[0]; - move16(); /* attenuate somewhat the gain for onset when the correlation with previous frame is too low: avoid preecho */ - tmp = mult_r(shl(st->rf_gain_tcx[1], 1), 26214/*0.8f Q15*/); - - test(); - test(); - IF( (st->rf_gain_tcx[1] != 0) && (sub(st->rf_gain_tcx[0], tmp) > 0) && (sub(st->tcxltp_gain, 6554/*0.2 Q15*/) <= 0) ) + if( st->rf_gain_tcx[1]!= 0 && st->rf_gain_tcx[0] > 1.6*st->rf_gain_tcx[1] && st->tcxltp_gain <= 0.2 ) { - st->rf_gain_tcx[0] = tmp; - move16(); + st->rf_gain_tcx[0] = 1.6*st->rf_gain_tcx[1]; - if( sub(tmp, 127) > 0) + if( st->rf_gain_tcx[0] > 127 ) { st->rf_gain_tcx[0] = 127; - move16(); } } /* get concealment decision*/ rf_PLC_Mode = 0; - move16(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - IF( - (sub(st->core_fx, TCX_20_CORE) == 0)/*(st->core == TCX_20_CORE)*/ - && (sub(st->last_core_fx,TCX_20_CORE) == 0)/*&&(st->last_core == TCX_20_CORE)*/ - && (sub(st->rf_second_last_core, TCX_20_CORE) == 0)/*&& (st->rf_second_last_core == TCX_20_CORE)*/ - && ( (sub(st->tcxltp_pitch_int, shr(st->L_frame_fx, 1)) <= 0) || ( sub(st->tcxltp_gain, 13107/*0.4f Q15*/) <= 0) )/*&& ((st->tcxltp_pitch_int <= 0.5f*st->L_frame) || ( st->tcxltp_gain <= 0.4f))*/ - && (sub(st->tcxltp_pitch_int, st->rf_tcxltp_pitch_int_past) == 0)/*&& (st->tcxltp_pitch_int == st->rf_tcxltp_pitch_int_past)*/ - && (st->rf_last_tns_active == 0)/*!st->rf_last_tns_active*/ - && (st->rf_second_last_tns_active == 0)/*!st->rf_second_last_tns_active*/ - && ( (st->tcx_cfg.fIsTNSAllowed & st->fUseTns[0]) == 0)/*!(st->tcx_cfg.fIsTNSAllowed & st->fUseTns[0])*/ - ) + if ((st->core == TCX_20_CORE) + &&(st->last_core == TCX_20_CORE) + && (st->rf_second_last_core == TCX_20_CORE) + && ((st->tcxltp_pitch_int <= 0.5f*st->L_frame) || (st->tcxltp_gain <= 0.4f)) + && (st->tcxltp_pitch_int == st->rf_tcxltp_pitch_int_past) + && !st->rf_last_tns_active + && !st->rf_second_last_tns_active + && !(st->tcx_cfg.fIsTNSAllowed & st->fUseTns[0]) + ) { rf_PLC_Mode = 1; - move16(); } - ELSE IF (st->last_core_fx != 0) + else if (st->last_core != 0) { - test(); - test(); - test(); - IF ( ((sub(st->clas_fx, UNVOICED_TRANSITION) <= 0) || (sub(st->last_clas_fx, UNVOICED_TRANSITION) <= 0) || (sub(st->tcxltp_gain, 13107/*0.4f Q15*/) <= 0)) - && sub(st->last_core_fx, -1) != 0 ) + if( (st->clas <= UNVOICED_TRANSITION || st->last_clas <= UNVOICED_TRANSITION || st->tcxltp_gain <= 0.4f) && st->last_core!=-1 ) { - rf_PLC_Mode = st->last_core_fx; - move16(); + rf_PLC_Mode = st->last_core; } } /* call TD1 when the gain drop compare to previous frame*/ - test(); - test(); - test(); - test(); - IF( rf_PLC_Mode == 0 && st->rf_gain_tcx[1] != 0 && - ( (st->transientDetection.transientDetector.bIsAttackPresent != 0 && sub(st->rf_gain_tcx[0], mult_r(st->rf_gain_tcx[1], 31785/*0.97f Q15*/)) < 0) || - sub(st->rf_gain_tcx[0], mult_r(st->rf_gain_tcx[1], 29491/*0.90f Q15*/)) < 0 ) - ) + if (rf_PLC_Mode == 0 && st->rf_gain_tcx[1]!= 0 && + ((st->transientDetection.transientDetector.bIsAttackPresent && st->rf_gain_tcx[0] < 0.97*st->rf_gain_tcx[1]) || + st->rf_gain_tcx[0] < 0.90*st->rf_gain_tcx[1])) { - TD_mode = 0; + TD_Mode = 0; } - ELSE + else { - TD_mode = 1; + TD_Mode = 1; } /* updates */ st->rf_tcxltp_pitch_int_past = st->tcxltp_pitch_int; - move16(); st->rf_second_last_tns_active = st->rf_last_tns_active; - move16(); - st->rf_last_tns_active = (st->tcx_cfg.fIsTNSAllowed & st->fUseTns[0]); - move16(); - st->rf_second_last_core = st->last_core_fx; - move16(); + st->rf_last_tns_active = st->tcx_cfg.fIsTNSAllowed & st->fUseTns[0]; + st->rf_second_last_core = st->last_core; st->rf_tcxltp_param[0] = st->tcxltp_param[1]; - move16(); /* Configure partial copy estimation of the current n-th frame to be packed in future with n+fec_offset frame */ /* o: rf_frame_type, o: rf_target_bits */ - BITS_ALLOC_TCX_config_rf( &st->rf_frame_type, &st->rf_target_bits, rf_PLC_Mode, coder_type, st->last_core_fx, TD_mode); + BITS_ALLOC_TCX_config_rf( &st->rf_frame_type, &st->rf_target_bits, rf_PLC_Mode, coder_type, st->last_core, TD_Mode ); /* RF frame type in the buffer */ st->rf_indx_frametype[0] = st->rf_frame_type; - move16(); st->rf_targetbits_buff[0] = st->rf_target_bits; - move16(); - } } - return; } - /*-------------------------------------------------------------------* * closest_centroid_rf() * * Determine a set of closest VQ centroids for a given input *-------------------------------------------------------------------*/ -void closest_centroid_rf( - const Word16 *data, /* i : input data Qx */ - const Word16 *weights, /* i : weights */ - const Word16 *quantizer, /* i : quantizer table Qx */ - const Word16 centroids, /* i : number of centroids */ - const Word16 length, /* i : dimension of quantiser */ - Word16 *ind_vec /* o : list of best match indice vectors */ + +static void closest_centroid_rf( + const float *data, /* i : input data */ + const float *weights, /* i : weights */ + const float *quantizer, /* i : quantizer table */ + const short centroids, /* i : number of centroids */ + const short length, /* i : dimension of quantiser */ + short *ind_vec /* o : list of best match indice vectors */ ) { - Word16 i,j; - Word16 tmp, tmpL; - Word32 werr, best_werr; - Word32 L_tmp; - + short i,j; + float tmp, werr, best_werr; ind_vec[0] = 0; - move16(); - best_werr = MAX_32; - move32(); + best_werr = 1.0E20f; - FOR( i = 0; i < centroids; i++ ) + for( i=0; iL_frame; + int overlap; + int tcx_offset = st->tcx_cfg.tcx_offset; + float *x = st->spectrum_long; + float target; + int T0; + float gain, noise, scale; + float *pt_ener_sfr, ener_sfr[NB_SUBFR16k]; /* Check minimum pitch for quantization */ - FOR( i = 0; i < 3; i++ ) + for( i = 0; i < 3; i++ ) { - tmp16 = pitch[i]; - move16(); /* check minimum pitch for quantization */ - if (sub(tmp16, PIT_MIN_SHORTER) < 0) + if( pitch[i] < PIT_MIN_SHORTER ) { - tmp16 = shl(tmp16, 1); + pitch[i] *= 2; } /* convert pitch values to 16kHz domain */ - s = mult_r(tmp16, 8192/*0.25f Q15*/); - if (sub(st->L_frame_fx, L_FRAME16k) == 0) + if ( st->L_frame == L_FRAME16k ) { - /*pitch[i] = (short)(pitch[i] * 1.25f + 0.5f);*/ - tmp16 = add(tmp16, s); + pitch[i] = (short)(pitch[i] * 1.25f + 0.5f); } - pitch[i] = tmp16; - move16(); } - IF (st->narrowBand != 0) + if( st->narrowBand == 1 ) { pitchDoubling_det( st->wspeech_enc, pitch, pitch_fr, voicing_fr ); } - E_LPC_f_lsp_a_conversion(lsp_mid, A_q_tcx, M); + lsp2a_stab(lsp_mid, A_q_tcx, M); - - /* LTP */ - - tcx_ltp_encode( st->tcxltp, - st->tcxonly, - TCX_20, - st->L_frame_fx, - L_SUBFR, - st->speech_enc + st->encoderLookahead_enc, - st->speech_ltp + st->encoderLookahead_enc, - st->wspeech_enc + st->encoderLookahead_enc, - pitch[1], - st->tcxltp_param, - &st->tcxltp_bits, - &st->tcxltp_pitch_int, - &st->tcxltp_pitch_fr, - &st->tcxltp_gain, - &st->tcxltp_pitch_int_past, - &st->tcxltp_pitch_fr_past, - &st->tcxltp_gain_past, - &st->tcxltp_norm_corr_past, - st->last_core_fx, - st->pit_min, - st->pit_fr1, - st->pit_fr2, - st->pit_max, - st->pit_res_max, - &st->transientDetection, - 0, - A_q_tcx, - M - ); + tcx_ltp_encode( st->tcxltp, st->tcxonly, TCX_20, st->L_frame, L_SUBFR, st->speech_enc+st->encoderLookahead_enc, st->speech_ltp+st->encoderLookahead_enc, + st->wspeech_enc+st->encoderLookahead_enc, pitch[1], st->tcxltp_param, &st->tcxltp_bits, &st->tcxltp_pitch_int, &st->tcxltp_pitch_fr, + &st->tcxltp_gain, &st->tcxltp_pitch_int_past, &st->tcxltp_pitch_fr_past, &st->tcxltp_gain_past, &st->tcxltp_norm_corr_past, st->last_core, + st->pit_min, st->pit_fr1, st->pit_fr2, st->pit_max, st->pit_res_max, &st->transientDetection, 0, A_q_tcx, M ); /* Force TCX when TCX20 in MODE1 is selected */ - IF ( sub(st->mdct_sw, MODE1) == 0 ) + if( st->mdct_sw == MODE1 ) { - st->core_fx = TCX_20_CORE; - move16(); + st->core = TCX_20_CORE; } - ELSE + else { /*--------------------------------------------------------------* - * Estimate TCX SNR - *---------------------------------------------------------------*/ + * Estimate TCX SNR + *---------------------------------------------------------------*/ - L_frame = st->L_frame_fx; - move16(); - tcx_offset = st->tcx_cfg.tcx_offset; - move16(); + target = 1000.f; + if ( st->sr_core == 16000.f ) target = 850.f; + if ( st->sr_core == 12800.f ) target = 850.f; + if ( st->narrowBand == 1 ) target = 500.f; - target = L_add(0x14C315C, 0); /* 1000.f * log2(10)/10 (15Q16) */ - test(); - if (L_sub(st->sr_core, 16000) == 0 || L_sub(st->sr_core, 12800) == 0) + if( st->last_core == ACELP_CORE ) { - target = L_add(0x11A5D28, 0); /* 850.f * log2(10)/10 (15Q16) */ - } - if ( st->narrowBand != 0 ) - { - target = L_add(0xA618AE, 0); /* 500f * log2(10)/10 (15Q16) */ + L_frame += tcx_offset; + + if( st->tcx_cfg.lfacNext < 0 ) + { + L_frame -= st->tcx_cfg.lfacNext; + tcx_offset = st->tcx_cfg.lfacNext; + } + else + { + tcx_offset = 0; + } } - IF (st->last_core_fx == ACELP_CORE) - { - L_frame = add(L_frame, tcx_offset); - tcx_offset = s_min(st->tcx_cfg.lfacNext, 0); - L_frame = sub(L_frame, tcx_offset); - } - L_frame_4 = shr(L_frame, 2); overlap = st->tcx_cfg.tcx_mdct_window_delay; - move16(); - Copy(st->speech_ltp + sub(tcx_offset, shr(overlap, 1)), xn_buf, add(L_frame, overlap)); - tmp16 = shr(overlap, 1); - IF (sub(st->last_core_fx,ACELP_CORE)==0) + mvr2r(st->speech_ltp-(overlap>>1)+tcx_offset, xn_buf, L_frame+overlap); + + if( st->last_core == ACELP_CORE ) { - IF (tcx_offset < 0) + if( tcx_offset < 0 ) { - set16_fx(xn_buf, 0, tmp16); + set_f( xn_buf, 0.0f, overlap>>1 ); } } - ELSE + else { - FOR (i = 0; i < tmp16; i++) + for (i = 0; i < overlap; i++) { - xn_buf[i] = mult_r(xn_buf[i], st->tcx_cfg.tcx_mdct_window[i].v.im); - move16(); - } - FOR ( ; i < overlap; i++) - { - xn_buf[i] = mult_r(xn_buf[i], st->tcx_cfg.tcx_mdct_window[overlap-1-i].v.re); - move16(); + xn_buf[i] *= st->tcx_cfg.tcx_mdct_window[i]; } } - FOR (i = 0; i < tmp16; i++) + for (i = 0; i < overlap; i++) { - xn_buf[L_frame+i] = mult_r(xn_buf[L_frame+i], st->tcx_cfg.tcx_mdct_window[i].v.re); - move16(); - } - FOR ( ; i < overlap; i++) - { - xn_buf[L_frame+i] = mult_r(xn_buf[L_frame+i], st->tcx_cfg.tcx_mdct_window[overlap-1-i].v.im); - move16(); + xn_buf[L_frame+i] *= st->tcx_cfg.tcx_mdct_window[overlap-1-i]; } - x_e = 16; - move16(); - TCX_MDCT(xn_buf, x, &x_e, overlap, sub(L_frame, overlap), overlap); - tmp16 = mult_r(shl(L_frame, 5), 29309/*16*0.0559017 Q15*/); /* L_frame / sqrt(2*NORM_MDCT_FACTOR); Q9 */ - FOR (i = 0; i < L_frame; i++) + TCX_MDCT( xn_buf, x, overlap, L_frame-overlap, overlap ); + + for( i = 0; i < L_frame; i++ ) { - x[i] = Mpy_32_16_1(x[i], tmp16); - move32(); - } - x_e = add(x_e, 6); - - weight_a_fx(A_q_tcx, Ap, st->gamma, M); - - lpc2mdct(Ap, M, gainlpc, gainlpc_e, NULL, NULL); - - mdct_shaping(x, L_frame, gainlpc, gainlpc_e); - - IF ( st->narrowBand ) - { - j = mult( L_frame, 20480 ); - set32_fx(&x[j], 0, sub(L_frame, j)); + x[i] *= (float)L_frame / sqrt(2*NORM_MDCT_FACTOR); } - FOR (i = 0; i < L_frame_4; i++) + weight_a( A_q_tcx, Ap, st->gamma, M ); + + lpc2mdct( Ap, M, gainlpc ); + + mdct_preShaping( x, L_frame, gainlpc ); + + if( st->narrowBand == 1 ) { - /* normalization */ - s = 31; - move16(); + j = (int)( (float)L_frame*0.625f ); - tmp16 = norm_l(x[0]); - if (x[0] != 0) s = s_min(s, tmp16); - - tmp16 = norm_l(x[1]); - if (x[1] != 0) s = s_min(s, tmp16); - - tmp16 = norm_l(x[2]); - if (x[2] != 0) s = s_min(s, tmp16); - - tmp16 = norm_l(x[3]); - if (x[3] != 0) s = s_min(s, tmp16); - - s = sub(s, 2); /* 2 bits headroom */ - - /* calc quadruple energy */ - ener = L_deposit_l(1); - - tmp16 = extract_h(L_shl(x[0], s)); - ener = L_mac(ener, tmp16, tmp16); - - tmp16 = extract_h(L_shl(x[1], s)); - ener = L_mac(ener, tmp16, tmp16); - - tmp16 = extract_h(L_shl(x[2], s)); - ener = L_mac(ener, tmp16, tmp16); - - tmp16 = extract_h(L_shl(x[3], s)); - ener = L_mac(ener, tmp16, tmp16); - - s = shl(sub(x_e, s), 1); - - tmp32 = L_add(BASOP_Util_Log2(ener), L_shl(L_deposit_l(s), 25)); /* log2, 6Q25 */ - tmp32 = L_shr(tmp32, 9); /* 15Q16 */ - en[i] = L_add(tmp32, 0x2FD5F); /* 0x2FD5F -> 9.f * log2(10)/10 (15Q16) */ move32(); - - x += 4; + set_f( x + j, 0.0f, L_frame - j ); } - fac = L_add(0x2A854B, 0); /* 0x2A854B -> 128.f * log2(10)/10 (15Q16) */ - offset = L_add(fac, 0); - - FOR (iter = 0; iter < 10; iter++) + for( i = 0; i < L_frame; i+=4 ) { - fac = L_shr(fac, 1); - offset = L_sub(offset, fac); - ener = L_deposit_l(0); + ener = 0.01f + x[i]*x[i] + x[i+1]*x[i+1] + x[i+2]*x[i+2] + x[i+3]*x[i+3]; + en[i/4] = 9.0f + 10.0f*(float)log10(ener); + } - assert(L_frame_4 % 4 == 0); - FOR (i=0; i < L_frame_4; i+=4) + fac = 128.0f; + offset = fac; + + for( iter = 0; iter < 10; iter++ ) + { + fac *= 0.5f; + offset -= fac; + ener = 0.0f; + + for( i=0; i 0) /* 0xFF20 -> 3.f * log2(10)/10 */ + if( tmp > 3.0f ) { - ener = L_add(ener, tmp32); + ener += tmp; } - tmp32 = L_sub(en[i+1], offset); - - if (L_sub(tmp32, 0xFF20) > 0) /* 0xFF20 -> 3.f * log2(10)/10 */ + if( ener > target ) { - ener = L_add(ener, tmp32); - } - - tmp32 = L_sub(en[i+2], offset); - - if (L_sub(tmp32, 0xFF20) > 0) /* 0xFF20 -> 3.f * log2(10)/10 */ - { - ener = L_add(ener, tmp32); - } - - tmp32 = L_sub(en[i+3], offset); - - if (L_sub(tmp32, 0xFF20) > 0) /* 0xFF20 -> 3.f * log2(10)/10 */ - { - ener = L_add(ener, tmp32); - } - - IF (L_sub(ener, target) > 0) - { - offset = L_add(offset, fac); - BREAK; + offset += fac; + break; } } } - if (L_sub(offset, 0xAA153) <= 0) /* 0xAA153 -> 32.f * log2(10)/10 */ + if( offset <= 32.f ) { - offset = L_add(0xFFD57AB5, 0); /* 0xFFD57AB5 -> -128.f * log2(10)/10; */ + offset = -128.f; } - offset_tcx = offset; - move32(); - s = add(extract_h(offset), 1); - offset = L_sub(L_and(offset, 0xFFFF), 0x10000); - ener = BASOP_Util_InvLog2(L_shl(offset, 9)); + sqGain = (float)pow(10.0f, offset/20.0f); + ener = sqGain*sqGain/12.f*(float)sqrt(2.f)/(float)L_frame; - ener = Mpy_32_16_1(Mpy_32_16_1(ener, 0x78AE), getInvFrameLen(L_frame)); /* 0x78AE -> sqrt(2)/12 (Q18) */ - ener_e = sub(s, 9); + snr_tcx = 0.0f; + pt_ener_sfr = ener_sfr; - tcx_snr = L_deposit_l(0); - - FOR (i = 0; i < st->L_frame_fx; i += L_SUBFR) + for( i = 0; i < st->L_frame; i += L_SUBFR ) { - tmp32 = L_deposit_l(0); + *pt_ener_sfr = sum2_f( st->wspeech_enc + i, L_SUBFR ) + 1e-6f; - FOR (j = 0; j < L_SUBFR; j++) - { - tmp32 = L_mac0(tmp32, st->wspeech_enc[i+j], st->wspeech_enc[i+j]); - } - tmp32 = L_shr(BASOP_Util_Log2(tmp32), 9); /* 15Q16 */ - tmp32 = L_add(tmp32, L_sub( 0x1F0000, L_shl( L_deposit_h( add( Q_new, sub( shift, 1 ) ) ), 1 ) ) ); /* wspeech_enc scaling */ - if (L_sub(tmp32, 0xFFEC1185) < 0) - { - tmp32 = L_add(0, 0xFFEC1185); /* 0xFFEC1185 -> log2(1e-6) in 15Q16 */ - } - - tcx_snr = L_add(tcx_snr, tmp32); + snr_tcx += (float)log10( *pt_ener_sfr/(ener*L_SUBFR) ); + pt_ener_sfr++; } - tcx_snr = Mpy_32_16_1(tcx_snr, div_s(L_SUBFR, st->L_frame_fx)); - tcx_snr = L_sub(tcx_snr, L_shr(BASOP_Util_Log2(Mpy_32_16_1(ener, L_SUBFR)), 9)); - tcx_snr = L_sub(tcx_snr, L_deposit_h(add(ener_e, 15))); - tcx_snr = L_shl(Mpy_32_16_1(tcx_snr, 0x6054), 2); /* 0x6054 -> 10/log2(10) (2Q13) */ + snr_tcx *= ((float)(10*L_SUBFR))/(float)st->L_frame; - BASOP_SATURATE_WARNING_OFF - snr_tcx = round_fx(L_shl(tcx_snr, 8)); /* 7Q8 */ - BASOP_SATURATE_WARNING_ON /*--------------------------------------------------------------* * Estimate ACELP SNR *---------------------------------------------------------------*/ - tmp32 = L_deposit_l(0); + scale = 0.055f; + if ( st->sr_core == 16000 ) scale = 0.092f; + if ( st->sr_core == 12800 ) scale = 0.059f; + if ( st->narrowBand ) scale = 0.15f; - /* - snr_acelp = 1/nSubFrames + sum( 10*log10( signal / (noise*0.055) ) - snr_acelp = sum( (log2(signal) - log2(noise)) * 10/log2(10) )/nSubFrames - 10*log10(0.055) - */ + snr_acelp = 0.0f; + fac = (float)st->sr_core/12800.f; + pt_ener_sfr = ener_sfr; - i2 = 0; - move16(); - FOR (i = 0; i < st->L_frame_fx; i += L_SUBFR) + for( i = 0; i < st->L_frame; i += L_SUBFR ) { - IF ( L_sub( st->sr_core, 16000 ) == 0 ) + T0 = (int)( (fac*pitch_fr[(int)((float)(i/L_SUBFR)/fac+0.5f)]) + 0.5f ); + gain = get_gain( st->wspeech_enc+i, st->wspeech_enc+i-T0, L_SUBFR, NULL ); + + noise = 1e-6f; + for( j = 0; j < L_SUBFR; j++ ) { - T0 = shr(add( add(pitch_fr[mult_r(i2,26214/*(float)L_FRAME/(float)L_FRAME16k Q15*/)], shr(pitch_fr[mult_r(i2,26214/*(float)L_FRAME/(float)L_FRAME16k Q15*/)], 2)) , (1 << 5) ), 6); - } - ELSE - { - T0 = shr(add( pitch_fr[i2] , (1 << 5) ), 6); + tmp = st->wspeech_enc[i+j] - gain * st->wspeech_enc[i+j-T0]; + noise += tmp * tmp; } - gain = get_gain( st->wspeech_enc + i, st->wspeech_enc + sub(i, T0), L_SUBFR ); - - signal = L_deposit_l(1); - noise = L_deposit_l(1); - - FOR (j = 0; j < L_SUBFR; j++) - { - signal = L_mac0(signal, st->wspeech_enc[i+j], st->wspeech_enc[i+j]); - - tmp16 = round_fx(L_shl(Mpy_32_16_r(gain, st->wspeech_enc[i+j-T0]), 15)); - tmp16 = sub(st->wspeech_enc[i+j], tmp16); - noise = L_mac0(noise, tmp16, tmp16); - } - /* Assume always 4 sub frames. */ - /*assert( (st->L_frame_fx / L_SUBFR) == 4);*/ - tmp32 = L_add(tmp32, Mpy_32_16_1(L_sub(BASOP_Util_Log2(signal), BASOP_Util_Log2(noise)), 12330/*3.0102999566398119521373889472449 Q12*/)); - i2 = add(i2, 1); + noise *= scale; + snr_acelp += (float)log10( *pt_ener_sfr/noise ); + pt_ener_sfr++; } - if(sub(st->L_frame_fx,L_FRAME16k) == 0) - { - tmp32 = Mpy_32_16_1(tmp32,26214/*(float)L_FRAME/(float)L_FRAME16k Q15*/); - } + snr_acelp *= ((float)(10*L_SUBFR))/(float)st->L_frame; - offset = L_add(0, -211332072l/*-12.5963731051575616 Q24*/); /* 10*log10(0.055f) */ - if (L_sub(st->sr_core, 16000) == 0) - { - offset = L_add(0, -173847554l/*-10.362121726544446 Q24*/); /* 10*log10(0.092f) */ - } - if (L_sub(st->sr_core, 12800) == 0) - { - offset = L_add(0, -206216813l/*-12.291479883578557 Q24*/); /* 10*log10(0.059f) */ - } - if (st->narrowBand != 0) - { - offset = L_add(0, -138228949l/*-8.2390874094431865 Q24*/); /* 10*log10(0.15f) */ - } - tmp32 = L_sub(tmp32, offset); - - snr_acelp = round_fx(tmp32); /* 7Q8 */ /*--------------------------------------------------------------* * Switching Decision *---------------------------------------------------------------*/ - dsnr = 0; - move16(); + dsnr = 0.0f; /* hysteresis for very small SNR differences between ACELP and TCX */ /* try to use TCX instead of ACELP on temporally stationary frames */ - test(); - test(); - test(); - test(); - test(); - test(); - test(); - if ((sub(snr_acelp, snr_tcx) > 0) && - (sub(snr_acelp, add(snr_tcx, 512/*2.0f Q8*/)) < 0) && - (sub(add(st->prevTempFlatness_fx, currFlatness), 416/*3.25f Q7*/) < 0 || sub(stab_fac, 0x7fff) == 0 || (L_sub(st->sr_core, 12800) == 0 && sub(sp_aud_decision0,1)==0 && sub(add(st->prevTempFlatness_fx, currFlatness), 2560/*20.f Q7*/) < 0)) && - (sub(st->acelpFramesCount, 6) <= 0)) + if( (snr_acelp > snr_tcx) && + (snr_acelp < snr_tcx + 2.0f) && + (st->prevTempFlatness + currFlatness < 3.25f || stab_fac == 1.0f || (st->sr_core == 12800 && sp_aud_decision0 == 1 && st->prevTempFlatness + currFlatness < 20.f)) && + (st->acelpFramesCount <= 6)) { - dsnr = -512/*-2.0f Q8*/; - move16(); + dsnr = -2.0f; } /* try to use ACELP instead of TCX on transient and "buzzy" frames */ - test(); - test(); - test(); - if ((sub(snr_acelp, snr_tcx) < 0) && - (sub(snr_acelp, sub(snr_tcx, 512/*2.0f Q8*/)) > 0) && - (sub(add(st->prevTempFlatness_fx, currFlatness), 416/*3.25f Q7*/) > 0) && - (sub(st->acelpFramesCount, 6) >= 0)) + if( (snr_acelp < snr_tcx) && + (snr_acelp > snr_tcx - 2.0f) && + (st->prevTempFlatness + currFlatness > 3.25f) && + (st->acelpFramesCount >= 6)) { - dsnr = 512/*2.0f Q8*/; - move16(); + dsnr = 2.0f; } - tmp16 = 0; - move16(); - FOR(i = 0; i < 4; i++) - { - tmp16 = add(tmp16, shr(voicing_fr[i],2)); /*mean of voicing_fr in Q15*/ - } - - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - if( L_sub(st->sr_core, 12800) == 0 && (offset_tcx < 0x18950F) && sub(non_staX, 1280 /*5.0f Q8*/ ) > 0 && (snr_acelp >= snr_tcx - 1024 /*4.0f in Q8*/) && sub(st->acelpFramesCount,1) >= 0 && ( (sub(st->lps_fx, st->lpm_fx) > 0 && sub(tmp16, 9830) >= 0) || (sub(st->acelpFramesCount,6) >= 0 && (st->lps_fx > st->lpm_fx - 768))) && (sp_aud_decision0 == 0) && vad_flag != 0 ) + if( (st->sr_core == 12800) && (offset < 74.0f) && (non_staX > 5.0f) && (snr_acelp >= snr_tcx - 4) && st->acelpFramesCount >= 1 && (((st->lps > st->lpm) && mean(voicing_fr, 4) >= 0.3f) || (st->acelpFramesCount >= 6 && (st->lps > st->lpm - 1.5f))) && (sp_aud_decision0 == 0) && vad_flag ) { /* Fine tuned across various databases based on various metrics to detect TCX frames in speech.*/ - dsnr = 1024; - move16(); + dsnr = 4.0f; } - IF ( st->flag_noisy_speech_snr ) + if( st->flag_noisy_speech_snr ) { - test(); - IF ( vad_flag || st->Opt_DTX_ON_fx ) + if( vad_flag || st->Opt_DTX_ON ) { - dsnr = add(dsnr, 512/*2.0f Q8*/); + dsnr += 2.f; } - ELSE + else { - dsnr = sub(dsnr, 512/*2.0f Q8*/); + dsnr -= 2.f; } } - test(); - test(); - test(); - test(); - test(); - test(); - if (L_sub(st->sr_core, 12800) == 0 && (sub(non_staX,512/*2.0f Q8*/) < 0 || (st->flag_noisy_speech_snr==0&&sub(vad_flag, 1) == 0&&(offset_tcx==L_add(0xFFD57AB5, 0))&&sub(st->acelpFramesCount,6) >= 0)) && (st->last_core_fx==ACELP_CORE||st->last_core_fx==TCX_20_CORE)) + if (st->sr_core == 12800 && (non_staX < 2.f || (st->flag_noisy_speech_snr==0&&vad_flag==1&&offset==-128.f&&st->acelpFramesCount>=6)) && (st->last_core==ACELP_CORE||st->last_core==TCX_20_CORE)) { - st->core_fx = st->last_core_fx; + st->core = st->last_core; } - ELSE IF ( sub(add(snr_acelp, dsnr), snr_tcx) > 0 ) + else if( snr_acelp + dsnr > snr_tcx ) { - st->core_fx = ACELP_CORE; - move16(); - st->acelpFramesCount = s_min(32767-1, add(st->acelpFramesCount, 1)); + st->core = ACELP_CORE; + st->acelpFramesCount = min(32767-1, st->acelpFramesCount + 1); } - ELSE + else { - st->core_fx = TCX_20_CORE; - move16(); + st->core = TCX_20_CORE; st->acelpFramesCount = 0; - move16(); } - } /* Fixed Decision (using -C) */ - test(); - if ( st->acelpEnabled != 0 && st->tcx20Enabled == 0 ) + if( st->acelpEnabled == 1 && st->tcx20Enabled == 0 ) { - st->core_fx = ACELP_CORE; - move16(); + st->core = ACELP_CORE; } - test(); - if ( st->acelpEnabled == 0 && st->tcx20Enabled != 0 ) + if( st->acelpEnabled == 0 && st->tcx20Enabled == 1 ) { - st->core_fx = TCX_20_CORE; - move16(); + st->core = TCX_20_CORE; } - st->prevTempFlatness_fx = currFlatness; - move16(); + + st->prevTempFlatness = currFlatness; + + return; } - - - /*-------------------------------------------------------------------* * BITS_ALLOC_ACELP_config_rf() * * configure channel aware mode *-------------------------------------------------------------------*/ -void BITS_ALLOC_ACELP_config_rf(const Word16 coder_type, - Word16 *tilt_code, - Word16 *rf_frame_type, - Word16 *rf_target_bits, - Word16 nb_subfr - , Word16 rf_fec_indicator - , Word16 *pitch_buf - ) +static void BITS_ALLOC_ACELP_config_rf( + const short coder_type, + float *tilt_code, + short *rf_frame_type, + short *rf_target_bits, + short nb_subfr, + short rf_fec_indicator, + float *pitch_buf +) { - Word16 mean_tc, min_tilt_code, max_tilt_code; - Word16 nrgMode, ltfMode, ltpMode, gainsMode; - Word32 L_tmp; + float mean_tc, min_tilt_code, max_tilt_code; + short nrgMode, ltfMode, ltpMode, gainsMode; - Word16 en_partial_red = 1; - Word16 dpit1, dpit2, dpit3; + short en_partial_red = 1; + float dpit1, dpit2, dpit3; /* Init */ *rf_target_bits = 0; - move16(); /* ----------------------------------------* * RF frame type selection * *-----------------------------------------*/ + /* Mean tilt code estimation */ mean_tc = 0; - move16(); - /*mean_tc = mean_fx(tilt_code, nb_subfr);*/ - IF( sub(nb_subfr, 4) == 0 ) - { - /* subframe 4 case */ - L_tmp = L_mult(tilt_code[0], 8192); - L_tmp = L_mac(L_tmp, tilt_code[1], 8192 ); - L_tmp = L_mac(L_tmp, tilt_code[2], 8192 ); - mean_tc = mac_r(L_tmp, tilt_code[3], 8192 ); /* mean_tc in Q15 */ - } - ELSE - { - /* subframe 5 case */ - L_tmp = L_mult(tilt_code[0], 6554); - L_tmp = L_mac(L_tmp, tilt_code[1], 6554 ); - L_tmp = L_mac(L_tmp, tilt_code[2], 6554 ); - L_tmp = L_mac(L_tmp, tilt_code[3], 6554 ); - mean_tc = mac_r(L_tmp, tilt_code[4], 6554 ); /* mean_tc in Q15 */ - } + mean_tc = mean(tilt_code, nb_subfr); /* Maximum tilt code estimation */ max_tilt_code = tilt_code[0]; - move16(); - maximum_fx(tilt_code, nb_subfr, &max_tilt_code); + maximum(tilt_code, nb_subfr, &max_tilt_code); /* Minimum tilt code estimation */ min_tilt_code=tilt_code[0]; - move16(); - minimum_fx(tilt_code, nb_subfr, &min_tilt_code); + minimum(tilt_code, nb_subfr, &min_tilt_code); - /* Estimate the frame's criticality and decide - whether to transmit partial redundancy information */ - dpit1 = abs_s( sub(pitch_buf[1], pitch_buf[0])); - dpit2 = abs_s( sub(pitch_buf[2], pitch_buf[1])); - dpit3 = abs_s( sub(pitch_buf[3], pitch_buf[2])); + /* ----------------------------------------*/ + /* Decide Criticality */ + /*-----------------------------------------*/ + dpit1 = (float)fabs( pitch_buf[0] - pitch_buf[1] ); + dpit2 = (float)fabs( pitch_buf[1] - pitch_buf[2] ); + dpit3 = (float)fabs( pitch_buf[2] - pitch_buf[3] ); - IF ( sub( rf_fec_indicator, 1 ) == 0 ) + if ( rf_fec_indicator == 1) { - test(); - test(); - test(); - test(); - IF ( sub( max_tilt_code, 15729/*0.48f Q15*/ ) > 0 && sub( dpit1, 0 ) <= 0 && sub( dpit2, 0 ) <= 0 && sub( dpit3, 0 ) <= 0 && sub(coder_type, VOICED ) == 0 ) + if ( max_tilt_code > 0.48f && dpit1 <= 0.0f && dpit2 <= 0.0f && dpit3 <= 0.0f && coder_type == VOICED ) { en_partial_red = 0; - move16(); } - ELSE IF ( sub( max_tilt_code, 15401/*0.47f Q15*/ ) > 0 && sub( dpit1, 64 ) <= 0 && sub( dpit2, 64 ) <= 0 && sub( dpit3, 64 ) <= 0 && sub(coder_type, GENERIC ) == 0 ) + if ( max_tilt_code > 0.47f && dpit1 <= 1.0f && dpit2 <= 1.0f && dpit3 <= 1.0f && coder_type == GENERIC) { en_partial_red = 0; - move16(); } } - ELSE + else { - test(); - test(); - test(); - test(); - IF ( sub( max_tilt_code, 15401/*0.47f Q15*/ )> 0 && sub( dpit1, 16 ) <= 0 && sub( dpit2, 16 ) <= 0 && sub( dpit3, 16 ) <= 0 && sub(coder_type, VOICED ) == 0 ) + if ( max_tilt_code > 0.47 && dpit1 <= 0.25f && dpit2 <= 0.25f && dpit3 <= 0.25f && coder_type == VOICED ) { en_partial_red = 0; - move16(); } - ELSE IF ( sub( max_tilt_code, 14746/*0.45f Q15*/ ) > 0 && sub( dpit1, 80 ) <= 0 && sub( dpit2, 80 ) <= 0 && sub( dpit3, 80 ) <= 0 && sub(coder_type, GENERIC ) == 0 ) + if ( max_tilt_code > 0.45 && dpit1 <= 1.25f && dpit2 <= 1.25f && dpit3 <= 1.25f && coder_type == GENERIC) { en_partial_red = 0; - move16(); } } + /* ---------------------------------------------------------* * Identify number of bits required as per rf frame type * * ---------------------------------------------------------*/ /* rf_mode, 1 bit */ - *rf_target_bits = add(*rf_target_bits,1); + *rf_target_bits += 1; /* rf_fec_offset 2 bits */ - *rf_target_bits = add(*rf_target_bits,2); + *rf_target_bits += 2; /* rf_frame_type, 3 bits */ - *rf_target_bits = add(*rf_target_bits,3); + *rf_target_bits += 3; /* LSF bits 8 + 8 bits */ - *rf_target_bits = add(*rf_target_bits,16); + *rf_target_bits += 16; /* Intialize the RF mode frame type to all-pred */ *rf_frame_type = RF_ALLPRED; - test(); - IF( sub(coder_type,INACTIVE) == 0 || en_partial_red == 0) + if ( coder_type == INACTIVE || en_partial_red == 0 ) { - *rf_frame_type = RF_NO_DATA; + *rf_frame_type = RF__NO_DATA; } - ELSE IF ( sub(coder_type,UNVOICED) == 0 || sub(coder_type,INACTIVE) == 0) + else if ( coder_type == UNVOICED || coder_type == INACTIVE ) { *rf_frame_type = RF_NELP; } - ELSE IF( sub(coder_type,GENERIC) == 0 && sub(max_tilt_code, 1638/*0.05f Q15*/) <0 ) + else if( ( coder_type == GENERIC ) && max_tilt_code < 0.05f) { *rf_frame_type = RF_NOPRED; } - ELSE IF( sub(coder_type,GENERIC) == 0 && sub(mean_tc,9830/*0.3f Q15*/) < 0) + else if( ( coder_type == GENERIC ) && mean_tc < 0.3f) { *rf_frame_type = RF_GENPRED; } @@ -1469,7 +1083,7 @@ void BITS_ALLOC_ACELP_config_rf(const Word16 coder_type, gainsMode = ACELP_GAINS_MODE[1][1][*rf_frame_type]; /* Number of RF bits for different RF coder types */ - SWITCH (*rf_frame_type) + switch (*rf_frame_type) { case RF_ALLPRED: /* Es_pred bits 3 bits, LTF: 1, pitch: 8,5,5,5, FCB: 0, gain: 7,0,7,0, Diff GFr: 4*/ @@ -1477,20 +1091,18 @@ void BITS_ALLOC_ACELP_config_rf(const Word16 coder_type, + ACELP_LTF_BITS[ltfMode] + ACELP_LTP_BITS_SFR[ltpMode][0] + ACELP_LTP_BITS_SFR[ltpMode][1] + ACELP_LTP_BITS_SFR[ltpMode][2] + ACELP_LTP_BITS_SFR[ltpMode][3] + ACELP_GAINS_BITS[gainsMode] + ACELP_GAINS_BITS[gainsMode] - + 2 /*2 bits for PartialCopy GainFrame*/ - ); - BREAK; + + 2 /*2 bits for PartialCopy GainFrame*/ ); + break; case RF_NOPRED: /* Es_pred bits 3 bits, LTF: 0, pitch: 0, FCB: 7,7,7,7, gain: 6,0,6,0, Diff GFr: 2*/ - /*bits += (3 + 0 + 0 + 28 + 12 + 2); *//* 64 rf bits */ + /*bits += (3 + 0 + 0 + 28 + 12 + 2); */ /* 64 rf bits */ *rf_target_bits += ( ACELP_NRG_BITS[nrgMode] + ACELP_LTF_BITS[ltfMode] + 28 + ACELP_GAINS_BITS[gainsMode] + ACELP_GAINS_BITS[gainsMode] - + 2 /*2 bits for PartialCopy GainFrame*/ - ); - BREAK; + + 2 /*2 bits for PartialCopy GainFrame*/ ); + break; case RF_GENPRED: /* Es_pred bits 3 bits, LTF: 0, pitch: 8,0,8,0, FCB: 6,7,5,5, gain: 5,0,5,0, Diff GFr: 0*/ @@ -1500,20 +1112,18 @@ void BITS_ALLOC_ACELP_config_rf(const Word16 coder_type, + ACELP_LTP_BITS_SFR[ltpMode][0] + ACELP_LTP_BITS_SFR[ltpMode][1] + ACELP_LTP_BITS_SFR[ltpMode][2] + ACELP_LTP_BITS_SFR[ltpMode][3] + 14 + ACELP_GAINS_BITS[gainsMode] + ACELP_GAINS_BITS[gainsMode] - + 2 /*2 bits for PartialCopy GainFrame*/ - ); - BREAK; + + 2 /*2 bits for PartialCopy GainFrame*/ ); + break; case RF_NELP: /* gain: 19, Diff GFr: 5 */ /*bits += (19 + 5); */ *rf_target_bits += (19 + NUM_BITS_SHB_FRAMEGAIN); - BREAK; + break; - case RF_NO_DATA: + case RF__NO_DATA: *rf_target_bits = 6; - BREAK; - + break; default: assert(!"RF_Frame_type does not belong to ACELP Partial copy frame types possible!"); break; @@ -1528,73 +1138,55 @@ void BITS_ALLOC_ACELP_config_rf(const Word16 coder_type, * * configure channel aware mode *-------------------------------------------------------------------*/ -void BITS_ALLOC_TCX_config_rf( - Word16 *rf_frame_type, - Word16 *rf_target_bits, - Word16 PLC_Mode, - Word16 coder_type, - Word16 last_core, - Word16 TD_mode +static void BITS_ALLOC_TCX_config_rf( + short *rf_frame_type, + short *rf_target_bits, + short PLC_Mode, + short coder_type, + short last_core, + int TD_Mode ) { - Word16 bits; - /* Init: rf_mode + rf_fec_offset + rf_frame_type */ - bits = 1 + 2 + 3; - move16(); + *rf_target_bits = 1 + 2 + 3; - test(); - IF( sub(coder_type, INACTIVE) == 0 || sub(last_core, ACELP_CORE) == 0 ) + if( coder_type == INACTIVE || last_core == ACELP_CORE ) { - *rf_frame_type = RF_NO_DATA; - move16(); + *rf_frame_type = RF__NO_DATA; } - ELSE + else { /* classification */ - bits = add(bits, 2); + *rf_target_bits += 2; - IF( PLC_Mode != 0 ) + if( PLC_Mode ) { /* TCX global gain = 7 bits */ - bits = add(bits, 7); + *rf_target_bits += 7; *rf_frame_type = RF_TCXFD; - move16(); } - ELSE + else { /* pitch and gain */ /* LTP data */ - IF( TD_mode != 0) + if( TD_Mode ) { - bits = add(bits, 9); + *rf_target_bits += 9; *rf_frame_type = RF_TCXTD2; - move16(); } - ELSE + else { - bits = add(bits, 9); + *rf_target_bits += 9; *rf_frame_type = RF_TCXTD1; - move16(); } } - if( sub(*rf_frame_type, RF_TCXFD) == 0 ) + if( *rf_frame_type == RF_TCXFD ) { /* TCXFD: LSF bits 5 + 4 + 4 bits */ /* only embed LSF for FD concealment */ - bits = add(bits, TCXLPC_NUMBITS); + *rf_target_bits += TCXLPC_NUMBITS; } } - - *rf_target_bits = bits; - move16(); - return; } - - - - - - diff --git a/src/libs/libevs/lib_enc/core_enc_reconf.cpp b/src/libs/libevs/lib_enc/core_enc_reconf.cpp old mode 100755 new mode 100644 index e1faab54..f708ec0a --- a/src/libs/libevs/lib_enc/core_enc_reconf.cpp +++ b/src/libs/libevs/lib_enc/core_enc_reconf.cpp @@ -1,30 +1,31 @@ /*==================================================================================== - EVS Codec 3GPP TS26.442 Apr 03, 2018. Version 12.11.0 / 13.6.0 / 14.2.0 + EVS Codec 3GPP TS26.443 Nov 13, 2018. Version 12.11.0 / 13.7.0 / 14.3.0 / 15.1.0 ====================================================================================*/ #include #include +#include #include -#include "prot_fx.h" #include "options.h" -#include "cnst_fx.h" -#include "stl.h" -#include "rom_com_fx.h" -#include "rom_enc_fx.h" +#include "prot.h" +#include "rom_com.h" +#include "rom_enc.h" + /*-----------------------------------------------------------------* * Funtion core_coder_reconfig * * ~~~~~~~~~~~~~~~~~~~ * * - reconfig core coder when switching to another frame type * *-----------------------------------------------------------------*/ -void core_coder_reconfig(Encoder_State_fx *st) + +void core_coder_reconfig( + Encoder_State *st +) { - Word16 i; - - + short bandwidth, i; /*Configuration of ACELP*/ - BITS_ALLOC_init_config_acelp(st->total_brate_fx, st->narrowBand, st->nb_subfr, &(st->acelp_cfg)); + BITS_ALLOC_init_config_acelp( st->total_brate, st->narrowBand, st->nb_subfr, &(st->acelp_cfg) ); /*Configuration of partial copy*/ st->acelp_cfg_rf.mode_index = 1; @@ -37,241 +38,137 @@ void core_coder_reconfig(Encoder_State_fx *st) st->acelp_cfg_rf.formant_enh_num = FORMANT_SHARPENING_G1; st->acelp_cfg_rf.formant_enh_den = FORMANT_SHARPENING_G2; - st->nb_bits_header_tcx = 2; /*Mode(1) + Last_mode(1)*/ move16(); - IF (st->tcxonly == 0) + if( st->tcxonly ) { - move16(); - st->nb_bits_header_ace = 4; - st->nb_bits_header_tcx = st->nb_bits_header_ace; - move16(); - if ( st->tcx_cfg.lfacNext<=0 ) - { - /*st->nb_bits_header_ace--;*/ /*No Last_mode*/ - st->nb_bits_header_ace = sub(st->nb_bits_header_ace,1); - } - } - - if ( st->tcxonly) - { - st->nb_bits_header_tcx = add(st->nb_bits_header_tcx,2); - } - - - /*Switch off TCX or ACELP?*/ - IF( L_sub(st->sr_core,12800) == 0 ) - { - st->acelpEnabled = 0; - move16(); - - if( s_and(st->restrictedMode,1) != 0) - { - st->acelpEnabled = 1; - move16(); - } - - st->tcx20Enabled = 0; - move16(); - if( s_and(st->restrictedMode,2) != 0) - { - - st->tcx20Enabled = 1; - move16(); - } - } - move32(); - move32(); - move16(); - st->prevEnergyHF_fx = st->currEnergyHF_fx = 1073725440l/*65535.0f Q14*/; /* prevent block switch */ - st->currEnergyHF_e_fx = 17; - - /*Sanity check : don't need to be instrumented*/ - if(st->tcxonly==0) - { - assert(st->acelpEnabled || st->tcx20Enabled || st->frame_size_index==0); + st->nb_bits_header_tcx = 1+1; /*TCX20/TCX10 + last_core*/ + st->nb_bits_header_tcx += 2; /* Siganl class*/ } else { - assert(st->tcx10Enabled || st->tcx20Enabled || st->frame_size_index==0); + st->nb_bits_header_ace = 1+2+1; /*TCX/ACELP+coder_type + last_core*/ + st->nb_bits_header_tcx = st->nb_bits_header_ace; + + if ( st->tcx_cfg.lfacNext<=0 ) + { + st->nb_bits_header_ace--; /*No last_core*/ + } } + /*Switch off TCX or ACELP?*/ + if( st->sr_core==12800 ) + { + st->acelpEnabled = (st->restrictedMode & 1) == 1; + st->tcx20Enabled = (st->restrictedMode & 2) == 2; + } + st->prevEnergyHF = st->currEnergyHF = 65535.0f; /* prevent block switch */ + + /* TCX-LTP */ st->tcxltp = getTcxLtp(st->sr_core); /*Use for 12.8 kHz sampling rate and low bitrates, the conventional pulse search->better SNR*/ - st->acelp_autocorr = 1; - move16(); - - test(); - if( (L_sub(st->total_brate_fx, 9600) <= 0) && (L_sub(st->sr_core,12800) == 0) ) + if( ((st->total_brate <= ACELP_9k60) && (st->sr_core == 12800)) ) { st->acelp_autocorr = 0; - move16(); } + /*Get bandwidth mode*/ + if( st->narrowBand ) { - Word16 bandwidth_mode; + bandwidth = NB; + } + else if(st->sr_core<=16000) + { + bandwidth = WB; + } + else + { + bandwidth = SWB; + } - /*Get bandwidth mode*/ - IF(st->narrowBand) + /*Scale TCX for non-active frames to adjust loudness with ACELP*/ + st->tcx_cfg.na_scale = 1.f; + if( bandwidth < SWB && !(st->tcxonly) ) + { + int scaleTableSize = sizeof (scaleTcxTable) / sizeof (scaleTcxTable[0]); + for (i = 0 ; i < scaleTableSize ; i++) { - bandwidth_mode=0; - } - ELSE IF( L_sub(st->sr_core, 16000)<=0 ) - { - move16(); - bandwidth_mode=1; - } - ELSE - { - move16(); - bandwidth_mode=2; - } - /*Scale TCX for non-active frames to adjust loudness with ACELP*/ - st->tcx_cfg.na_scale=32767/*1.0f Q15*/; - - test(); - IF( sub(bandwidth_mode,2)<0 && (st->tcxonly==0)) - { - const Word16 scaleTableSize = sizeof (scaleTcxTable) / sizeof (scaleTcxTable[0]); - - FOR (i = 0 ; i < scaleTableSize ; i++) + if ( (bandwidth == scaleTcxTable[i].bwmode) && + (st->total_brate >= scaleTcxTable[i].bitrateFrom) && + (st->total_brate < scaleTcxTable[i].bitrateTo) ) { - - test(); - test(); - IF ( sub(bandwidth_mode, scaleTcxTable[i].bwmode) == 0 && - L_sub(st->total_brate_fx, scaleTcxTable[i].bitrateFrom) >= 0 && - L_sub(st->total_brate_fx, scaleTcxTable[i].bitrateTo) < 0 ) + if( st->rf_mode ) { - if( st->rf_mode ) - { - i--; - } - move16(); - st->tcx_cfg.na_scale = scaleTcxTable[i].scale; - BREAK; + i--; } + st->tcx_cfg.na_scale=scaleTcxTable[i].scale; + break; } } } - st->enableTcxLpc = 0; - move16(); + st->enableTcxLpc = (st->lpcQuantization == 1) && (st->total_brate <= LOWRATE_TCXLPC_MAX_BR || st->rf_mode); - test(); - if ( sub(st->lpcQuantization, 1) == 0 && ( L_sub(st->total_brate_fx, LOWRATE_TCXLPC_MAX_BR) <= 0 || st->rf_mode != 0 ) ) - { - st->enableTcxLpc = 1; - move16(); - } - - IF ( st->ini_frame_fx == 0 || sub(st->last_codec_mode, MODE1) == 0 ) + if( st->ini_frame == 0 || st->last_codec_mode == MODE1 ) { st->envWeighted = 0; - move16(); } - test(); - test(); - IF( sub(st->bwidth_fx, SWB) ==0 && - (L_sub(st->total_brate_fx, ACELP_16k40) == 0 || L_sub(st->total_brate_fx, ACELP_24k40) == 0) ) + if( st->bwidth == SWB && (st->total_brate == ACELP_16k40 || st->total_brate == ACELP_24k40) ) { - IF(st->tec_tfa == 0) + if(st->tec_tfa == 0) { - FOR (i = 0; i < MAX_TEC_SMOOTHING_DEG; i++) - { - st->tecEnc.loBuffer[i] = 0; - move16(); - } + set_zero(st->tecEnc.loBuffer, MAX_TEC_SMOOTHING_DEG); } st->tec_tfa = 1; - move16(); } - ELSE + else { st->tec_tfa = 0; - move16(); } st->enablePlcWaveadjust = 0; - move16(); - IF (L_sub(st->total_brate_fx, 48000) >= 0) + if( st->total_brate >= HQ_48k ) { st->enablePlcWaveadjust = 1; - move16(); } - - move16(); st->glr = 0; - test(); - test(); - test(); - if( (L_sub(st->total_brate_fx, 9600)==0)||( L_sub(st->total_brate_fx, 16400)==0)|| - (L_sub(st->total_brate_fx, 24400)==0)) + if( st->total_brate == ACELP_9k60 || st->total_brate == ACELP_16k40 || st->total_brate == ACELP_24k40 ) { - move16(); st->glr = 1; } - if(st->glr) + if( st->glr ) { - - st->nb_bits_header_ace = add(st->nb_bits_header_ace, G_LPC_RECOVERY_BITS); + st->nb_bits_header_ace += G_LPC_RECOVERY_BITS; } - test(); - IF (sub(st->bwidth_fx, NB) == 0 || sub(st->bwidth_fx, WB) == 0) + if( st->bwidth == NB || st->bwidth == WB ) { - test(); - IF (st->rf_mode==0) - { - st->nmStartLine = startLineWB[s_min((sizeof(startLineWB)/sizeof(startLineWB[0])-1), s_max(3, st->frame_size_index))]; - move16(); - } - ELSE - { - st->nmStartLine = startLineWB[s_min((sizeof(startLineWB)/sizeof(startLineWB[0])-1), s_max(3, st->frame_size_index-1))]; - move16(); - } + st->nmStartLine = startLineWB[min((sizeof(startLineWB)/sizeof(startLineWB[0])-1), (unsigned)max(0, (st->rf_mode==0) ? st->frame_size_index:st->frame_size_index-1))]; } - ELSE /* (st->bwidth_fx == SWB || st->bwidth_fx == FB) */ + else /* (st->bwidth == SWB || st->bwidth == FB) */ { - IF (st->rf_mode==0) - { - st->nmStartLine = startLineSWB[s_min((sizeof(startLineSWB)/sizeof(startLineSWB[0])-1), sub(s_max(3, st->frame_size_index), 3))]; - move16(); - } - ELSE { - st->nmStartLine = startLineSWB[s_min((sizeof(startLineSWB)/sizeof(startLineSWB[0])-1), sub(s_max(3, st->frame_size_index-1), 3))]; - move16(); - } + st->nmStartLine = startLineSWB[min((sizeof(startLineSWB)/sizeof(startLineSWB[0])-1), (unsigned)max(3, (st->rf_mode==0) ? st->frame_size_index:st->frame_size_index-1) - 3)]; } - test(); - test(); - test(); - test(); - test(); - IF ( (L_sub(st->total_brate_fx, ACELP_24k40) < 0) && (( L_sub(st->total_brate_fx, st->last_total_brate_fx) > 0) || (sub(st->last_codec_mode, MODE1) == 0) )) + if( (st->total_brate < ACELP_24k40) && ( (st->total_brate > st->last_total_brate) || (st->last_codec_mode == MODE1) ) ) { /* low-freq memQuantZeros must be reset partially if bitrate increased */ - FOR (i = 0; i < st->nmStartLine; i++) - { - st->memQuantZeros[i] = 0; - move16(); - } + set_i( st->memQuantZeros, 0, st->nmStartLine ); } - ELSE IF ( (L_sub(st->total_brate_fx, ACELP_24k40) >= 0) && (L_sub(st->total_brate_fx, ACELP_32k) <= 0) && (L_sub(st->last_total_brate_fx, ACELP_13k20) >= 0) && (L_sub(st->last_total_brate_fx, ACELP_24k40) < 0) ) + else { - FOR (i = 0; i < st->L_frame_fx; i++) /* memQuantZeros won't be updated */ + if( (st->total_brate >= ACELP_24k40) && (st->total_brate <= ACELP_32k) && (st->last_total_brate >= ACELP_13k20) && (st->last_total_brate < ACELP_24k40) ) { - st->memQuantZeros[i] = 0; - move16(); + set_i(st->memQuantZeros, 0, st->L_frame); } } + + return; } diff --git a/src/libs/libevs/lib_enc/core_enc_switch.cpp b/src/libs/libevs/lib_enc/core_enc_switch.cpp old mode 100755 new mode 100644 index e472e993..65754c39 --- a/src/libs/libevs/lib_enc/core_enc_switch.cpp +++ b/src/libs/libevs/lib_enc/core_enc_switch.cpp @@ -1,230 +1,165 @@ /*==================================================================================== - EVS Codec 3GPP TS26.442 Apr 03, 2018. Version 12.11.0 / 13.6.0 / 14.2.0 + EVS Codec 3GPP TS26.443 Nov 13, 2018. Version 12.11.0 / 13.7.0 / 14.3.0 / 15.1.0 ====================================================================================*/ #include #include +#include #include -#include "prot_fx.h" -#include "basop_mpy.h" #include "options.h" -#include "cnst_fx.h" -#include "rom_com_fx.h" +#include "prot.h" +#include "rom_com.h" -#include "stl.h" +/*-------------------------------------------------------------------* + * core_coder_mode_switch() + * + * + *-------------------------------------------------------------------*/ -void core_coder_mode_switch( Encoder_State_fx *st, const Word16 bandwidth_in, - const Word32 bitrate, - const Word16 shift) +void core_coder_mode_switch( + Encoder_State *st, + int bandwidth_in, + int bitrate +) { - Word16 i, fscale, switchWB; - Word16 bSwitchFromAmrwbIO; - Word16 bandwidth; - Word32 tmp32; - Word32 sr_core; - - - move16(); - move16(); - move16(); - move16(); + int i, fscale, switchWB, sr_core; + int bSwitchFromAmrwbIO; + int bandwidth; bandwidth = bandwidth_in; switchWB = 0; bSwitchFromAmrwbIO = 0; - if ( sub(st->last_core_fx, AMR_WB_CORE) == 0 ) + if( st->last_core == AMR_WB_CORE ) { - move16(); bSwitchFromAmrwbIO = 1; } + /* force active frame for the first frame when switching from high bitrates when dtx is enabled*/ sr_core = getCoreSamplerateMode2(bitrate, bandwidth, st->rf_mode); - move16(); - fscale = sr2fscale(sr_core); - move16(); + fscale = sr2fscale(sr_core); - IF ( s_and(s_and(sub(bandwidth,WB)>=0, sub(fscale, (FSCALE_DENOM*16000)/12800)==0), sub(fscale, st->fscale)==0)) + if ( (bandwidth >= WB) && (fscale==(FSCALE_DENOM*16000)/12800) && (fscale == st->fscale) ) { - IF ( s_or(s_and(L_sub(bitrate, 32000)>0, (st->tcxonly==0)), s_and(L_sub(bitrate, 32000)<=0, st->tcxonly!=0)) ) + if ( ((bitrate>32000) && (st->tcxonly==0)) || ((bitrate<=32000) && (st->tcxonly==1)) ) { - move16(); switchWB = 1; } } - if( sub(st->last_codec_mode,MODE1)==0 ) + if( st->last_codec_mode == MODE1 ) { - move16(); - switchWB = 1; /*force init when coming from MODE1*/ - } - test(); - if( L_sub(st->last_total_brate_fx,ACELP_32k)>0 && L_sub(st->total_brate_fx,ACELP_32k) <= 0) - { - move16(); switchWB = 1; /*force init when coming from MODE1*/ } - test(); - test(); - IF ( (sub(fscale, st->fscale)==0) && (bSwitchFromAmrwbIO==0) && (switchWB==0) ) + if( st->last_total_brate > ACELP_32k && st->total_brate <= ACELP_32k ) { - st->total_brate_fx = bitrate; - move32(); + switchWB = 1; /*force init when coming from MODE1*/ + } + + if( fscale == st->fscale && !bSwitchFromAmrwbIO && !switchWB ) + { + + st->total_brate = bitrate; st->sr_core = sr_core; - move32(); - st->L_frame_fx = extract_l(Mult_32_16(st->sr_core , 0x0290)); - assert(st->L_frame_fx == st->sr_core / 50); - st->tcxonly = getTcxonly(st->total_brate_fx); - - /* st->bits_frame_nominal = (int)( (float)st->L_frame_fx/(float)st->fscale ) * (float)FSCALE_DENOM/128.0f * (float)st->bitrate/100.0f + 0.49f ; */ - /* st->bits_frame_nominal = extract_l(L_shr(Mpy_32_16_1( L_shl(st->bitrate,8), mult_r(div_s(st->fscale, shl(st->L_frame_fx,4)), FL2WORD16(FSCALE_DENOM/12800.f))), 6)); */ - tmp32 = L_shl(st->total_brate_fx, 1); /* (float)st->L_frame_fx/(float)st->fscale * (float)FSCALE_DENOM/128.0f * (float)st->bitrate */ - st->bits_frame_nominal = extract_l(L_shr(Mpy_32_16_1(tmp32, 20972), 6)); /* 20972 = 0.01 * 64 * 32768 */ - assert(st->bits_frame_nominal == (int)( (float)st->L_frame_fx/(float)st->fscale * (float)FSCALE_DENOM/128.0f * (float)st->total_brate_fx/100.0f + 0.49f )); - - st->igf = getIgfPresent(bitrate, bandwidth, st->rf_mode); + st->L_frame = sr_core / 50; + st->tcxonly = getTcxonly(st->total_brate); + st->bits_frame_nominal = (int)( (float)st->L_frame/(float)st->fscale * (float)FSCALE_DENOM/128.0f * (float)st->total_brate/100.0f + 0.49f ); + st->igf = getIgfPresent(bitrate, bandwidth, st->rf_mode ); /* switch IGF configuration */ - IF (st->igf) + if (st->igf) { - IGFEncSetMode( &st->hIGFEnc, st->total_brate_fx, bandwidth, st->rf_mode ); + IGFEncSetMode( &st->hIGFEnc, st->total_brate, bandwidth, st->rf_mode ); } st->tcx_cfg.tcx_coded_lines = getNumTcxCodedLines(bandwidth); - move16(); - st->tcx_cfg.bandwidth = getTcxBandwidth(st->bwidth_fx); - move16(); - move16(); - st->tcx_cfg.tcxRateLoopOpt = 0; - if (st->tcxonly) + st->tcx_cfg.bandwidth = getTcxBandwidth(bandwidth); + st->tcx_cfg.tcxRateLoopOpt = (st->tcxonly) ? 2 : 0; + st->tcx_cfg.ctx_hm = getCtxHm(st->total_brate, st->rf_mode ); + st->tcx_cfg.resq = getResq(st->total_brate); + st->tcx_lpc_shaped_ari = getTcxLpcShapedAri( st->total_brate, st->bwidth, st->rf_mode ); + + st->tcx_cfg.tcxRateLoopOpt = (st->tcx_cfg.resq && !st->tcxonly) ? 1 : st->tcx_cfg.tcxRateLoopOpt; + st->tcx_cfg.fIsTNSAllowed = getTnsAllowed(st->total_brate, st->igf); + + if (st->tcx_cfg.fIsTNSAllowed) { - move16(); - st->tcx_cfg.tcxRateLoopOpt = 2; + InitTnsConfigs( bwMode2fs[bandwidth], st->tcx_cfg.tcx_coded_lines, st->tcx_cfg.tnsConfig, (&st->hIGFEnc)->infoStopFrequency, st->total_brate); } - st->tcx_cfg.ctx_hm = getCtxHm(st->total_brate_fx, st->rf_mode ); - move16(); - st->tcx_cfg.resq = getResq(st->total_brate_fx); - move16(); - st->tcx_lpc_shaped_ari = getTcxLpcShapedAri( - st->total_brate_fx, - bandwidth - ,st->rf_mode - ); - - test(); - if (st->tcx_cfg.resq != 0 && st->tcxonly == 0) - { - st->tcx_cfg.tcxRateLoopOpt = 1; - move16(); - } - st->tcx_cfg.fIsTNSAllowed = getTnsAllowed(st->total_brate_fx, st->igf); - IF (st->tcx_cfg.fIsTNSAllowed != 0) - { - InitTnsConfigs(bwMode2fs[bandwidth], st->tcx_cfg.tcx_coded_lines, st->tcx_cfg.tnsConfig, st->hIGFEnc.infoStopFrequency, st->total_brate_fx); - } - move16(); - - st->narrowBand = 0; - move16(); - if(sub(st->bwidth_fx, NB) == 0) + if( bandwidth == NB ) { st->narrowBand = 1; - move16(); + st->min_band = 1; + st->max_band = 16; } - IF ( st->narrowBand ) + else { - st->min_band_fx = 1; - move16(); - st->max_band_fx = 16; - move16(); - } - ELSE - { - st->min_band_fx = 0; - move16(); - st->max_band_fx = 19; - move16(); + st->narrowBand = 0; + st->min_band = 0; + st->max_band = 19; } - FOR (i=0; ibits_frame_nominal) == 0 ) + if (FrameSizeConfig[i].frame_bits==st->bits_frame_nominal) { - move16(); - move16(); - move16(); st->frame_size_index = i; st->bits_frame = FrameSizeConfig[i].frame_bits; st->bits_frame_core = FrameSizeConfig[i].frame_net_bits; - BREAK; + break; } } - st->restrictedMode = getRestrictedMode(st->total_brate_fx, 0); + st->restrictedMode = getRestrictedMode( st->total_brate, 0 ); core_coder_reconfig( st ); } - ELSE + else { - st->igf = getIgfPresent(bitrate, bandwidth, st->rf_mode); - init_coder_ace_plus(st, shift); + st->igf = getIgfPresent(bitrate, bandwidth, st->rf_mode ); + init_coder_ace_plus( st ); } - IF( st->igf != 0 ) + if( st->igf ) { - test(); - test(); - test(); - test(); - test(); - IF( (sub(st->bwidth_fx, WB) == 0 && sub(st->last_extl_fx, WB_TBE) != 0) || - (sub(st->bwidth_fx, SWB) == 0 && sub(st->last_extl_fx, SWB_TBE) != 0) || - (sub(st->bwidth_fx, FB) == 0 && sub(st->last_extl_fx, FB_TBE) != 0) ) + /* reset TBE */ + if( ( st->bwidth == WB && st->last_extl != WB_TBE ) || + ( st->bwidth == SWB && st->last_extl != SWB_TBE ) || + ( st->bwidth == FB && st->last_extl != FB_TBE ) ) { - /* reset TBE buffers as previous frame wasn't using TBE */ - TBEreset_enc_fx( st, st->bwidth_fx ); + TBEreset_enc( st, st->bwidth ); } - ELSE + else { - set16_fx( st->state_lpc_syn_fx, 0, LPC_SHB_ORDER ); - set16_fx( st->state_syn_shbexc_fx, 0, L_SHB_LAHEAD ); - set16_fx( st->mem_stp_swb_fx, 0, LPC_SHB_ORDER ); - set16_fx( st->mem_zero_swb_fx, 0, LPC_SHB_ORDER ); - st->gain_prec_swb_fx = 16384; - move16(); /*Q14 = 1 */ + set_f( st->state_lpc_syn, 0.0f, LPC_SHB_ORDER ); + set_f( st->state_syn_shbexc, 0.0f, L_SHB_LAHEAD ); + set_f( st->mem_stp_swb, 0.0f, LPC_SHB_ORDER ); + set_f( st->mem_zero_swb, 0, LPC_SHB_ORDER ); + st->gain_prec_swb = 1.0f; } } - IF ( s_and(st->envWeighted!=0, st->enableTcxLpc==0) ) + if (st->envWeighted && !st->enableTcxLpc) { /* Unweight the envelope */ - E_LPC_lsp_unweight( - st->lsp_old_fx, - st->lsp_old_fx, - st->lsf_old_fx, - st->inv_gamma, - M - ); - move16(); + E_LPC_lsp_unweight( st->lsp_old, st->lsp_old, st->lsf_old, 1.0f/st->gamma ); st->envWeighted = 0; } - st->enablePlcWaveadjust = 0; - move16(); - if (L_sub(bitrate, 48000) >= 0) + if( bitrate >= HQ_48k ) { st->enablePlcWaveadjust = 1; - move16(); + } + else + { + st->enablePlcWaveadjust = 0; } - test(); - IF(L_sub(st->last_total_brate_fx, 32000) > 0 - || L_sub(st->last_codec_mode,MODE1)==0 ) + if( (st->last_total_brate > HQ_32k) || (st->last_codec_mode == MODE1) ) { - move16(); st->glr_reset = 1; } -} + return; +} diff --git a/src/libs/libevs/lib_enc/core_enc_updt.cpp b/src/libs/libevs/lib_enc/core_enc_updt.cpp old mode 100755 new mode 100644 index 0434ad5d..7a1d7d22 --- a/src/libs/libevs/lib_enc/core_enc_updt.cpp +++ b/src/libs/libevs/lib_enc/core_enc_updt.cpp @@ -1,257 +1,185 @@ /*==================================================================================== - EVS Codec 3GPP TS26.442 Apr 03, 2018. Version 12.11.0 / 13.6.0 / 14.2.0 + EVS Codec 3GPP TS26.443 Nov 13, 2018. Version 12.11.0 / 13.7.0 / 14.3.0 / 15.1.0 ====================================================================================*/ #include #include +#include #include -#include "prot_fx.h" -#include "basop_util.h" #include "options.h" -#include "cnst_fx.h" -#include "stl.h" +#include "prot.h" +#include "rom_com.h" +#include "cnst.h" -void core_encode_update(Encoder_State_fx *st - ) + +/*-------------------------------------------------------------------* +* core_encode_update() +* +* Common updates of buffers +*-------------------------------------------------------------------*/ + +void core_encode_update( + Encoder_State *st /* i/o: Encoder state structure */ +) { - Word16 n; - - - - /*--------------------------------------------------------------* - * Update Buffers - *---------------------------------------------------------------*/ + short n; /* Update Input Signal Buffers */ + n = st->encoderPastSamples_enc + st->encoderLookahead_enc; - n = add(st->encoderPastSamples_enc, st->encoderLookahead_enc); + mvr2r( st->buf_speech_enc_pe + st->L_frame, st->buf_speech_enc_pe, n ); + mvr2r( st->buf_speech_enc + st->L_frame, st->buf_speech_enc, n ); - Copy(st->buf_speech_enc +st->L_frame_fx, st->buf_speech_enc, n); - Copy(st->buf_speech_enc_pe+st->L_frame_fx, st->buf_speech_enc_pe, n); - - - IF(!st->tcxonly) + if( !st->tcxonly ) { - n = add(st->L_frame_fx, shr(st->L_frame_fx,2)); - Copy(st->buf_wspeech_enc+st->L_frame_fx, st->buf_wspeech_enc, n); + n = st->L_frame + st->L_frame/4; + mvr2r( st->buf_wspeech_enc + st->L_frame, st->buf_wspeech_enc, n ); } - - IF ( s_or( s_or(st->core_fx == ACELP_CORE, s_or( L_sub(st->core_brate_fx, SID_2k40) == 0, L_sub(st->core_brate_fx, FRAME_NO_DATA) == 0) ), L_sub(st->core_fx, AMR_WB_CORE) == 0 ) ) + if( st->core == ACELP_CORE || st->core == AMR_WB_CORE || st->core_brate == SID_2k40 || st->core_brate == FRAME__NO_DATA ) { - Copy(st->buf_speech_enc + st->L_frame_fx, st->buf_speech_ltp + st->L_frame_fx, st->L_frame_fx); + mvr2r( st->buf_speech_enc + st->L_frame, st->buf_speech_ltp + st->L_frame, st->L_frame ); } - n = add(st->encoderPastSamples_enc, st->encoderLookahead_enc); - Copy(st->buf_speech_ltp+st->L_frame_fx, st->buf_speech_ltp, n); - Copy(st->buf_synth+st->L_frame_fx, st->buf_synth, add(st->L_frame_fx,L_SUBFR)); + n = st->encoderPastSamples_enc + st->encoderLookahead_enc; + mvr2r( st->buf_speech_ltp + st->L_frame, st->buf_speech_ltp, n ); + mvr2r( st->buf_synth + st->L_frame, st->buf_synth, st->L_frame+L_SUBFR ); - /* Update previous mode */ - - move16(); - st->last_core_fx = st->core_fx; /* not in float -> remove? */ - - - test(); - test(); - test(); - IF( ((L_sub(st->core_brate_fx,SID_2k40) <= 0) && sub(st->cng_type_fx, FD_CNG) == 0) - || (st->tcxonly && sub(st->codec_mode,MODE2)==0) - ) + if( (st->core_brate <= SID_2k40 && st->cng_type == FD_CNG) || (st->tcxonly && st->codec_mode == MODE2) ) { /* reset LP memories */ - set16_fx( st->mem_MA_fx,0, M ); - Copy( GEWB_Ave_fx, st->mem_AR_fx, M ); + set_zero( st->mem_MA, M ); + mvr2r( GEWB_Ave, st->mem_AR, M ); } -} - - -void core_encode_update_cng( Encoder_State_fx *st, - Word16 *timeDomainBuffer, - Word16 *A, - Word16 *Aw, - Word16 Q_new, - Word16 shift - ) -{ - Word16 i; - Word16 lsp[M]; - Word16 lsf[M]; /* 14Q1 * 1.28 */ - Word16 *synth, synth_buf[M+1+L_FRAME_PLUS+L_FRAME_PLUS/2], wsyn[L_FRAME_PLUS]; - Word16 *p_A, tmp; - Word16 enr_index; - Word16 enr, tmpv, maxv, scale, att; - Word16 hi, lo; - Word16 *pt_res; - Word32 L_tmp, L_ener; - - - /* LPC -> LSP/lsp */ - /* LSP/lsp -> LSF/lsf */ - E_LPC_a_lsp_conversion( A, lsp, st->lsp_old_fx, M ); - IF(sub(st->L_frame_fx, L_FRAME16k)== 0) - { - lsp2lsf_fx( lsp, lsf, M, INT_FS_16k_FX ); - } - ELSE - { - E_LPC_lsp_lsf_conversion( lsp, lsf, M ); - } - - /* Update synth memory */ - move16(); - synth = synth_buf + (1+M); - Copy( st->LPDmem.syn, synth_buf, 1+M ); - Copy( timeDomainBuffer, synth, st->L_frame_fx ); - Copy( synth+st->L_frame_fx-(1+M), st->LPDmem.syn, 1+M ); - Copy( synth, st->synth, st->L_frame_fx ); - - /* Update ZIR */ - set16_fx( synth+st->L_frame_fx, 0, shr(st->L_frame_fx,1) ); - E_UTIL_synthesis(1, A, synth+st->L_frame_fx, synth+st->L_frame_fx, shr(st->L_frame_fx,1), &synth[st->L_frame_fx-M], 0, M ); - Copy( synth+st->L_frame_fx-(st->L_frame_fx/2), st->LPDmem.Txnq, shr(st->L_frame_fx,1) ); - - /* Update pe-synth memory */ - move16(); - tmp = synth[-(1+M)]; - E_UTIL_f_preemph2( Q_new-1, synth-M, st->preemph_fac, M+st->L_frame_fx, &tmp ); - Copy( synth+st->L_frame_fx-M, st->LPDmem.mem_syn, M ); - Copy( synth+st->L_frame_fx-M, st->LPDmem.mem_syn2, M ); - - /* Update excitation memory */ - Copy( st->LPDmem.old_exc+st->L_frame_fx, st->LPDmem.old_exc, s_max(L_EXC_MEM-st->L_frame_fx, 0 )); - Residu3_fx( A, synth, st->LPDmem.old_exc+s_max(L_EXC_MEM-st->L_frame_fx, 0), st->L_frame_fx, 1 ); - - /* Update LP_CNG memory */ - IF( L_sub(st->core_brate_fx, SID_2k40) == 0 ) - { - pt_res = st->LPDmem.old_exc + L_EXC_MEM - st->L_frame_fx; - maxv = 0; - move16(); - FOR(i = 0; i < st->L_frame_fx; i++) - { - maxv = s_max(maxv, abs_s(pt_res[i])); - } - scale = norm_s(maxv); - L_ener = L_deposit_l(1); - IF( sub(st->L_frame_fx, L_FRAME) == 0) - { - FOR (i=0; i<128; i++) - { - tmpv = shl(*pt_res,scale); - L_tmp = L_mult0(tmpv, tmpv); - pt_res++; - tmpv = shl(*pt_res,scale); - L_tmp = L_mac0(L_tmp, tmpv, tmpv); /* 2*(Q_new+scale) */ - pt_res++; - L_ener = L_add(L_ener, L_shr(L_tmp, 7)); /* 2*(Q_new+scale)+1, divide by L_frame done here */ - } - } - ELSE /* L_FRAME16k */ - { - FOR (i=0; i<160; i++) - { - tmpv = shl(*pt_res,scale); - L_tmp = L_mult0(tmpv, tmpv); - pt_res++; - tmpv = shl(*pt_res,scale); - L_tmp = L_mac0(L_tmp, tmpv, tmpv); /* 2*(Q_new+scale) */ - pt_res++; - L_ener = L_add(L_ener, L_shr(Mult_32_16(L_tmp,26214 /* 256/320, Q15 */), 7)); /* 2*(Q_new+scale)+15+1-16+1, divide by L_frame done here */ - } - } - - hi = norm_l(L_ener); - lo = Log2_norm_lc(L_shl(L_ener, hi)); - hi = sub(30, add(hi, shl(add(Q_new, scale), 1))); /* log2 exp in Q2*(Q_new+scale) */ - L_tmp = L_Comp(hi, lo); /* Q16 */ - enr = round_fx(L_shl(L_tmp, 8)); /* Q8 (16+8-16) */ - - /* decrease the energy in case of WB input */ - IF( sub(st->bwidth_fx, NB) != 0 ) - { - IF( sub(st->bwidth_fx,WB) == 0 ) - { - IF( st->CNG_mode_fx >= 0 ) - { - /* Bitrate adapted attenuation */ - att = ENR_ATT_fx[st->CNG_mode_fx]; - } - ELSE - { - /* Use least attenuation for higher bitrates */ - att = ENR_ATT_fx[4]; - } - } - ELSE - { - att = 384; - move16();/*Q8*/ - } - enr = sub(enr, att ); - } - - /* calculate the energy quantization index */ - enr_index = add(enr, 512 /* Q8(2.0) */); /* enr + 2.0 */ - enr_index = extract_l(L_shr(L_mult0(enr_index, STEP_SID_FX), 12+8)); /* Q0 (8+12-(8+12)) */ - - /* limit the energy quantization index */ - enr_index = s_min(enr_index, 127); - enr_index = s_max(enr_index, 0); - - st->old_enr_index_fx = enr_index; - } - - /* Update weighted synthesis memory */ - move16(); - p_A = Aw; - FOR ( i = 0; i < st->L_frame_fx; i += L_SUBFR ) - { - Residu3_fx( p_A, &synth[i], &wsyn[i], L_SUBFR, 0); - p_A += (M+1); - } - move16(); - - - - tmp = sub(st->wspeech_enc[-1],shl(st->LPDmem.mem_w0,shift)); - E_UTIL_deemph2( -shift, wsyn, st->preemph_fac, st->L_frame_fx, &tmp ); - st->LPDmem.mem_w0 = sub(st->wspeech_enc[st->L_frame_fx-1], tmp); - st->LPDmem.mem_w0 =shr(st->LPDmem.mem_w0, shift); - - /* Update LPC-related memories */ - - Copy( lsp, st->lsp_old_fx, M ); - Copy( lsf, st->lsf_old_fx, M ); - move16(); - st->envWeighted = 0; - Copy( A, st->old_Aq_12_8_fx, M+1 ); - st->old_Es_pred_fx=0; - - - /* Reset acelp memories */ - move16(); - move16(); - st->dm_fx.prev_gain_code = L_deposit_l(0); - set16_fx(st->dm_fx.prev_gain_pit,0,6); - st->dm_fx.prev_state = 0; - st->LPDmem.tilt_code = TILT_CODE; - st->LPDmem.gc_threshold = L_deposit_l(0); - - /* Update ace/tcx mode */ - move16(); - st->core_fx = ACELP_CORE; - - /* Reset TCX overlap */ - st->tcx_cfg.tcx_curr_overlap_mode = st->tcx_cfg.tcx_last_overlap_mode = ALDO_WINDOW; - move16(); - - IF( st->first_CNG_fx == 0 ) - { - Copy( st->lsp_old_fx, st->lspCNG_fx, M ); - } return; } +/*-------------------------------------------------------------------* +* core_encode_update_cng() +* +* Common updates in case of CNG +*-------------------------------------------------------------------*/ + +void core_encode_update_cng( + Encoder_State *st, + float *timeDomainBuffer, + float *A, + const float Aw[] /* i : weighted A(z) unquant. for subframes*/ +) +{ + float lsp[M], lsf[M]; + float *synth, synth_buf[M+1+L_FRAME_PLUS+L_FRAME_PLUS/2], wsyn[L_FRAME_PLUS]; + float tmp; + float enr; + float att; + float enr_index; + + /* LPC -> LSP/lsp */ + a2lsp_stab( A, lsp, st->lsp_old ); + + /* LSP/lsp -> LSF/lsf */ + if( st->L_frame == L_FRAME16k ) + { + lsp2lsf( lsp, lsf, M, INT_FS_16k ); + } + else + { + lsp2lsf( lsp, lsf, M, INT_FS_12k8 ); + } + + /* Update synth memory */ + synth = synth_buf + (1+M); + mvr2r( st->LPDmem.syn, synth_buf, 1+M ); + mvr2r( timeDomainBuffer, synth, st->L_frame); + mvr2r( synth+st->L_frame-(1+M), st->LPDmem.syn, 1+M ); + mvr2r( synth, st->synth, st->L_frame); + + /* Update ZIR */ + set_zero( synth+st->L_frame, st->L_frame/2 ); + syn_filt( A, M,synth+st->L_frame, synth+st->L_frame, st->L_frame/2, &synth[st->L_frame-M], 0 ); + mvr2r( synth+st->L_frame-(st->L_frame/2), st->LPDmem.Txnq, st->L_frame/2 ); + + /* Update pe-synth memory */ + tmp = synth[-(1+M)]; + preemph( synth-M, st->preemph_fac, M+st->L_frame, &tmp ); + mvr2r( synth+st->L_frame-M, st->LPDmem.mem_syn, M ); + mvr2r( synth+st->L_frame-M, st->LPDmem.mem_syn2, M ); + + /* Update excitation memory */ + mvr2r( st->LPDmem.old_exc+st->L_frame, st->LPDmem.old_exc, max(L_EXC_MEM-st->L_frame,0)); + residu( A, M,synth, st->LPDmem.old_exc+max(L_EXC_MEM-st->L_frame,0), st->L_frame ); + if ( st->core_brate == SID_2k40 ) + { + enr = dotp( st->LPDmem.old_exc+max(L_EXC_MEM-st->L_frame,0), st->LPDmem.old_exc+max(L_EXC_MEM-st->L_frame,0), st->L_frame ) / st->L_frame; + enr = (float)log10( enr + 0.1f ) / (float)log10( 2.0f ); + + /* decrease the energy in case of WB input */ + if( st->bwidth != NB ) + { + if( st->bwidth == WB ) + { + if( st->CNG_mode >= 0 ) + { + /* Bitrate adapted attenuation */ + att = ENR_ATT[st->CNG_mode]; + } + else + { + /* Use least attenuation for higher bitrates */ + att = ENR_ATT[4]; + } + } + else + { + att = 1.5f; + } + + enr -= att; + } + + enr_index = (short)( (enr + 2.0f) * STEP_SID ); + if( enr_index > 127 ) + { + enr_index = 127; + } + + if( enr_index < 0 ) + { + enr_index = 0; + } + st->old_enr_index = enr_index; + } + + /* Update weighted synthesis memory */ + calc_residu( synth, wsyn, Aw, st->L_frame ); + tmp = st->wspeech_enc[-1]-st->LPDmem.mem_w0; + deemph( wsyn, st->preemph_fac, st->L_frame, &tmp ); + st->LPDmem.mem_w0 = st->wspeech_enc[st->L_frame-1]-wsyn[st->L_frame-1]; + + /* Update LPC-related memories */ + mvr2r( lsp, st->lsp_old, M ); + mvr2r( lsf, st->lsf_old, M ); + st->envWeighted = 0; + mvr2r( A, st->old_Aq_12_8, M+1 ); + st->old_Es_pred = 0; + + /* Reset acelp memories */ + set_zero( st->dispMem, 8 ); + st->LPDmem.tilt_code = TILT_CODE; + st->LPDmem.gc_threshold = 0.0f; + + /* Update ace/tcx mode */ + st->core = ACELP_CORE; + + /* Reset TCX overlap */ + st->tcx_cfg.tcx_curr_overlap_mode = st->tcx_cfg.tcx_last_overlap_mode = ALDO_WINDOW; + + if( st->first_CNG == 0 ) + { + mvr2r( st->lsp_old, st->lspCNG, M ); + } + + return; +} diff --git a/src/libs/libevs/lib_enc/core_switching_enc.cpp b/src/libs/libevs/lib_enc/core_switching_enc.cpp new file mode 100644 index 00000000..b5716a9b --- /dev/null +++ b/src/libs/libevs/lib_enc/core_switching_enc.cpp @@ -0,0 +1,418 @@ +/*==================================================================================== + EVS Codec 3GPP TS26.443 Nov 13, 2018. Version 12.11.0 / 13.7.0 / 14.3.0 / 15.1.0 + ====================================================================================*/ + +#include "options.h" +#include "cnst.h" +#include "rom_enc.h" +#include "rom_com.h" +#include "prot.h" +#include "math.h" +#include "assert.h" + +/*---------------------------------------------------------------------* + * core_switching_pre_enc() + * + * Preprocessing (preparing) for ACELP/HQ core switching + *---------------------------------------------------------------------*/ + +void core_switching_pre_enc( + Encoder_State *st, /* i/o: encoder state structure */ + LPD_state *mem, /* i/o: encoder state structure */ + const float *old_inp_12k8, /* i : old input signal @12.8kHz */ + const float *old_inp_16k /* i : old input signal @16kHz */ +) +{ + short Sample_Delay_HP, Sample_Delay_LP; + + + /* Codec mode switching */ + if( st->last_codec_mode == MODE2 ) + { + st->mem_deemph = st->LPDmem.syn[M]; + + mvr2r( mem->mem_syn2, st->mem_syn1, M ); + + st->igf = 0; + + if( st->last_core != ACELP_CORE ) + { + /* reset BWE memories */ + set_f( st->old_bwe_exc, 0, PIT16k_MAX*2 ); + st->bwe_non_lin_prev_scale = 0.0f; + } + set_f( st->old_syn_12k8_16k, 0, NS2SA(16000, DELAY_FD_BWE_ENC_NS) ); + + if( st->last_core == TCX_20_CORE || st->last_core == TCX_10_CORE ) + { + st->last_core = HQ_CORE; + + + set_f( st->last_ni_gain, 0, BANDS_MAX ); + set_f( st->last_env, 0, BANDS_MAX ); + st->last_max_pos_pulse = 0; + + st->mode_count = 0; + st->mode_count1 = 0; + + set_s( st->prev_SWB_peak_pos, 0, SPT_SHORTEN_SBNUM ); + st->prev_frm_hfe2 = 0; + st->prev_stab_hfe2 = 0; + + /*ALDO overlap windowed past: also used in MODE2 but for other MDCT-LB*/ + set_f( st->old_out, 0, L_FRAME32k ); + + } + if( st->L_frame == L_FRAME16k && st->last_L_frame==L_FRAME ) + { + mvr2r( st->lsp_old, st->lsp_old16k, M ); + st->rate_switching_reset_16kHz = lsp_convert_poly( st->lsp_old16k, L_FRAME16k, 0 ); + } + + st->use_acelp_preq = 0; + } + + if( st->last_core == -1 && st->core == HQ_CORE ) + { + /* very first frame is HQ_CORE */ + st->last_core = HQ_CORE; + } + + if( st->core == HQ_CORE && (st->last_core == ACELP_CORE || st->last_core == AMR_WB_CORE) ) /* HQ init */ + { + + set_f( st->last_ni_gain, 0, BANDS_MAX ); + set_f( st->last_env, 0, BANDS_MAX ); + st->last_max_pos_pulse = 0; + + st->mode_count = 0; + st->mode_count1 = 0; + + set_s( st->prev_SWB_peak_pos, 0, SPT_SHORTEN_SBNUM ); + st->prev_frm_hfe2 = 0; + st->prev_stab_hfe2 = 0; + + set_f( st->old_out, 0, L_FRAME32k ); + } + + /* Here we only handle cases where last_ppp and last_nelp not updated when coming from CodecB or other cores + within ACELP_CORE if switching from another bitarate to vbr, last_ppp and last_nelp is always updated in the previous frame */ + if( sub(st->core, ACELP_CORE) == 0 && ( st->last_core != ACELP_CORE || st->last_codec_mode == MODE2)) + { + st->last_last_ppp_mode = 0; + st->last_ppp_mode = 0; + st->last_nelp_mode =0; + } + + /* Handle state reset of stat_noise_uv_mod memory */ + if( st->core == ACELP_CORE && (st->last_core != ACELP_CORE || st->last_codec_mode == MODE2 || st->last_total_brate <= PPP_NELP_2k80 ) ) + { + st->act_count = 3; + st->uv_count = 0; + } + + if( (st->core == ACELP_CORE || st->core == AMR_WB_CORE) && st->last_core == HQ_CORE ) + { + /* Reset the ACELP core in case of HQ->ACELP core switching */ + + if(st->L_frame == L_FRAME16k ) + { + mvr2r( TRWB2_Ave, st->lsf_old, M ); /* init of LSP */ + lsf2lsp( st->lsf_old, st->lsp_old, M, INT_FS_16k ); + } + else + { + mvr2r( TRWB_Ave, st->lsf_old, M ); /* init of LSP */ + lsf2lsp( st->lsf_old, st->lsp_old, M, INT_FS_12k8 ); + } + + st->mem_deemph = 0; + st->LPDmem.syn[M] = 0; + set_f( mem->mem_syn2, 0.0f, M ); + set_f( mem->mem_syn, 0.0f, M ); + set_f( st->mem_syn1, 0.0f, M ); + st->Nb_ACELP_frames = 0; + + /* Reset ACELP parameters */ + set_zero( st->mem_MA, M ); + mvr2r( GEWB_Ave, st->mem_AR, M ); + mem->mem_w0 = 0.0f; + mem->tilt_code = 0.0f; + init_gp_clip(st->clip_var); + mem->gc_threshold = 0.0f; + set_f( st->dispMem, 0, 8 ); + + st->last_coder_type = GENERIC; + + mvr2r( st->old_pitch_buf + st->L_frame/L_SUBFR, st->old_pitch_buf, st->L_frame/L_SUBFR ); + set_f( st->old_pitch_buf + st->L_frame/L_SUBFR, L_SUBFR, st->L_frame/L_SUBFR ); + /* Reset old ACELP buffers */ + set_f( mem->old_exc, 0, L_EXC_MEM ); + set_f( st->old_bwe_exc, 0, PIT16k_MAX*2 ); + + + /* reset BWE memories */ + st->bwe_non_lin_prev_scale = 0.0; + set_f( st->old_syn_12k8_16k, 0, NS2SA(16000, DELAY_FD_BWE_ENC_NS) ); + } + + if( st->input_Fs >= 16000 && st->last_extl != WB_BWE && st->extl == WB_BWE ) + { + if( st->last_extl != SWB_BWE && st->last_extl != FB_BWE ) + { + st->prev_mode = NORMAL; + st->modeCount = 0; + } + + st->prev_L_swb_norm1 = 8; + } + + if( ( st->input_Fs >= 32000 && st->last_extl != SWB_BWE && st->extl == SWB_BWE ) || + ( st->input_Fs >= 48000 && st->last_extl != FB_BWE && st->extl == FB_BWE ) ) + { + /* we are switching to SWB BWE - reset SWB BWE buffers */ + if( st->L_frame == L_FRAME ) + { + Sample_Delay_HP = NS2SA( 16000, ACELP_LOOK_NS + DELAY_FD_BWE_ENC_12k8_NS + DELAY_FIR_RESAMPL_NS - DELAY_CLDFB_NS ); + Sample_Delay_LP = NS2SA( 12800, ACELP_LOOK_NS + DELAY_FD_BWE_ENC_12k8_NS ); + + mvr2r( old_inp_12k8 + L_INP_MEM + L_FRAME - Sample_Delay_LP, st->old_input_lp, Sample_Delay_LP ); + } + else + { + Sample_Delay_HP = NS2SA( 16000, ACELP_LOOK_NS + DELAY_FD_BWE_ENC_16k_NS + DELAY_FIR_RESAMPL_NS - DELAY_CLDFB_NS ); + Sample_Delay_LP = NS2SA( 16000, ACELP_LOOK_NS + DELAY_FD_BWE_ENC_16k_NS ); + + mvr2r( old_inp_16k + L_INP_MEM + L_FRAME - Sample_Delay_LP, st->old_input_lp, Sample_Delay_LP ); + } + mvr2r( st->old_speech_shb + L_LOOK_16k + L_SUBFR16k - Sample_Delay_HP, st->new_input_hp, Sample_Delay_HP ); + + if (st->last_extl != WB_BWE) + { + st->prev_mode = NORMAL; + st->modeCount = 0; + } + st->EnergyLF = 0.0f; + st->prev_L_swb_norm1 = 8; + } + + + + return; +} + + +/*---------------------------------------------------------------------* + * core_switching_post_enc() + * + * Postprocessing for ACELP/HQ core switching + *---------------------------------------------------------------------*/ + +void core_switching_post_enc( + Encoder_State *st, /* i/o: encoder state structure */ + const float *old_inp_12k8, /* i : old input signal @12.8kHz */ + const float *old_inp_16k, /* i : old input signal @16kHz */ + const short pitch[3], /* i : open-loop pitch values for quantiz. */ + const float voicing[3], /* i : Open-loop pitch gains */ + const float A[] /* i : unquant. LP filter coefs. */ +) +{ + short T_op[3]; + + + + mvs2s( pitch, T_op, 3 ); + + + if( st->core == HQ_CORE ) + { + st->use_acelp_preq = 0; + + if( (st->last_core == ACELP_CORE || st->last_core == AMR_WB_CORE) ) /* core switching ==> CELP subframe encoding */ + { + acelp_core_switch_enc( st, &(st->LPDmem), old_inp_12k8 + L_INP_MEM - NS2SA(INT_FS_12k8, ACELP_LOOK_NS), + old_inp_16k + L_INP_MEM - NS2SA(INT_FS_16k, ACELP_LOOK_NS), T_op, voicing, A ); + } + + st->bwe_non_lin_prev_scale = 0.0; + st->mem_deemph_old_syn = 0.0f; + } + else + { + + /* reset SWB TBE buffers */ + if( st->extl == WB_TBE && st->last_extl != WB_TBE ) + { + wb_tbe_extras_reset( st->mem_genSHBexc_filt_down_wb2, st->mem_genSHBexc_filt_down_wb3 ); + + if( st->last_extl != WB_BWE ) + { + set_f( st->decim_state1, 0.0f, (2*ALLPASSSECTIONS_STEEP+1) ); + set_f( st->decim_state2, 0.0f, (2*ALLPASSSECTIONS_STEEP+1) ); + } + + set_f( st->state_syn_shbexc, 0, L_SHB_LAHEAD/4 ); + set_f( st->syn_overlap, 0, L_SHB_LAHEAD ); + set_f( st->mem_csfilt, 0, 2 ); + } + + if( (st->extl == SWB_TBE || st->extl == FB_TBE) && + ( st->last_core == HQ_CORE || st->L_frame != st->last_L_frame || (st->last_extl != SWB_TBE && st->last_extl != FB_TBE) ) + ) + { + set_f( st->state_ana_filt_shb, 0.0f, (2*ALLPASSSECTIONS_STEEP+1) ); + set_f( st->old_speech_shb, 0.0f, L_LOOK_16k + L_SUBFR16k ); + + swb_tbe_reset( st->mem_csfilt, st->mem_genSHBexc_filt_down_shb, st->state_lpc_syn, st->syn_overlap, + st->state_syn_shbexc, &(st->tbe_demph), &(st->tbe_premph), st->mem_stp_swb, &(st->gain_prec_swb) ); + + set_f( st->dec_2_over_3_mem,0.0f, 12 ); + set_f( st->dec_2_over_3_mem_lp,0.0f, 6 ); + + } + else if( (st->extl == SWB_TBE || st->extl == FB_TBE) && + ( (st->last_total_brate != st->total_brate) || (st->last_bwidth != st->bwidth) || + (st->last_codec_mode != MODE1) || (st->rf_mode_last != st->rf_mode) ) ) + { + set_f( st->state_lpc_syn, 0.0f, LPC_SHB_ORDER ); + set_f( st->state_syn_shbexc, 0.0f, L_SHB_LAHEAD ); + set_f( st->mem_stp_swb, 0.0f, LPC_SHB_ORDER ); + set_f( st->mem_zero_swb, 0, LPC_SHB_ORDER ); + st->gain_prec_swb = 1.0f; + } + + /* Interp_3_2 CNG buffers reset */ + + if( st->extl == FB_TBE && ( st->last_extl != FB_TBE || st->L_frame != st->last_L_frame ) ) + { + set_f(st->fb_state_lpc_syn, 0, LPC_SHB_ORDER); + st->fb_tbe_demph = 0; + fb_tbe_reset_enc( st->elliptic_bpf_2_48k_mem, &st->prev_fb_energy ); + } + } + + + + return; +} + + +/*---------------------------------------------------------------------* + * core_switching_hq_prepare_enc() + * + * Preprocessing in the first HQ frame after ACELP frame + * - modify bit allocation for HQ core removing CELP subframe budget + * - update st->old_wtda to modify windows at the encoder + *---------------------------------------------------------------------*/ + +void core_switching_hq_prepare_enc( + Encoder_State *st, /* i/o: encoder state structure */ + short *num_bits, /* i/o: bit budget update */ + const short input_frame, /* i : frame length */ + float *wtda_audio, + const float *audio +) +{ + short delta, Loverlapp, i; + short n; + long cbrate; + + /* set multiplication factor according to the sampling rate */ + delta = 1; + if( input_frame == L_FRAME16k ) + { + delta = 2; + } + else if( input_frame == L_FRAME32k ) + { + delta = 4; + } + else if( input_frame == L_FRAME48k ) + { + delta = 6; + } + + /* set switching frame bit-rate */ + if( st->last_L_frame == L_FRAME) + { + if( st->core_brate > ACELP_24k40 ) + { + cbrate = ACELP_24k40; + } + else + { + cbrate = st->core_brate; + } + /* subtract ACELP switching frame bits */ + if( st->core_brate >= ACELP_11k60 ) + { + /* subtract one bit for LP filtering flag */ + (*num_bits)--; + } + + *num_bits -= ACB_bits_tbl[BIT_ALLOC_IDX(cbrate, GENERIC, 0, 0)]; /* pitch bits */ + *num_bits -= gain_bits_tbl[BIT_ALLOC_IDX(cbrate, TRANSITION, 0, 0)]; /* gain bits */ + *num_bits -= FCB_bits_tbl[BIT_ALLOC_IDX(cbrate, GENERIC, 0, 0)]; /* FCB bits */ + } + else /* L_frame == L_FRAME16k */ + { + if( st->core_brate <= ACELP_8k00 ) + { + cbrate = ACELP_8k00; + } + else if( st->core_brate <= ACELP_14k80 ) + { + cbrate = ACELP_14k80; + } + else + { + cbrate = min(st->core_brate,ACELP_22k60); + } + + /* subtract ACELP switching frame bits */ + if( st->core_brate >= ACELP_11k60 ) + { + /* subtract one bit for LP filtering flag */ + (*num_bits)--; + } + + + *num_bits -= ACB_bits_16kHz_tbl[BIT_ALLOC_IDX_16KHZ(cbrate, GENERIC, 0, 0)]; /* pitch bits */ + *num_bits -= gain_bits_16kHz_tbl[BIT_ALLOC_IDX_16KHZ(cbrate, GENERIC, 0, 0)]; /* gain bits */ + *num_bits -= FCB_bits_16kHz_tbl[BIT_ALLOC_IDX_16KHZ(cbrate, GENERIC, 0, 0)]; /* FCB bits */ + } + + /* subtract BWE bits */ + if ( !((inner_frame_tbl[st->bwidth]==L_FRAME16k && st->last_L_frame==L_FRAME16k)|| inner_frame_tbl[st->bwidth] == L_FRAME8k) ) + { + *num_bits -= (NOOFGAINBITS1 + AUDIODELAYBITS); + } + + + n = ((float)input_frame * N_ZERO_MDCT_NS/FRAME_SIZE_NS); + + /* Transition window at the encoder */ + Loverlapp = delta*SWITCH_OVERLAP_8k; + for( i = 0; i old_out, 0.0f, L_FRAME32k ); + + return; +} + diff --git a/src/libs/libevs/lib_enc/core_switching_enc_fx.cpp b/src/libs/libevs/lib_enc/core_switching_enc_fx.cpp deleted file mode 100755 index 06c1f13b..00000000 --- a/src/libs/libevs/lib_enc/core_switching_enc_fx.cpp +++ /dev/null @@ -1,512 +0,0 @@ -/*==================================================================================== - EVS Codec 3GPP TS26.442 Apr 03, 2018. Version 12.11.0 / 13.6.0 / 14.2.0 - ====================================================================================*/ - -#include "options.h" /* Compilation switches */ -#include "cnst_fx.h" /* Common constants */ -#include "rom_enc_fx.h" /* Encoder static table prototypes */ -#include "rom_com_fx.h" /* Static table prototypes */ -#include "prot_fx.h" /* Function prototypes */ -#include "stl.h" /* required for wmc_tool */ - - -/*---------------------------------------------------------------------* -* core_switching_pre_enc() -* -* Preprocessing (preparing) for ACELP/HQ core switching -*---------------------------------------------------------------------*/ - -void core_switching_pre_enc_fx( - Encoder_State_fx *st_fx, /* i/o: encoder state structure */ - LPD_state *mem, /* i/o: encoder state structure */ - const Word16 *old_inp_12k8, /* i : old input signal @12.8kHz */ - const Word16 *old_inp_16k /* i : old input signal @16kHz */ -) -{ - Word16 Sample_Delay_HP, Sample_Delay_LP; - Word16 tmp16; - Word16 tmp; - - /* Mode switching */ - IF( sub(st_fx->last_codec_mode,MODE2) == 0 ) - { - st_fx->mem_deemph_fx = st_fx->LPDmem.syn[M]; - move16(); - - Copy( mem->mem_syn2, st_fx->mem_syn1_fx, M ); - - st_fx->igf = 0; - move16(); - - IF( sub(st_fx->last_core_fx,ACELP_CORE) != 0 ) - { - /* reset BWE memories */ - set16_fx( st_fx->old_bwe_exc_fx, 0, PIT16k_MAX*2 ); - st_fx->bwe_non_lin_prev_scale_fx = L_deposit_l(0); - } - - set16_fx( st_fx->old_syn_12k8_16k_fx, 0, NS2SA(16000, DELAY_FD_BWE_ENC_NS) ); - - test(); - IF( sub(st_fx->last_core_fx,TCX_20_CORE)==0 || sub(st_fx->last_core_fx,TCX_10_CORE)==0 ) - { - st_fx->last_core_fx = HQ_CORE; - move16(); - - set32_fx( st_fx->last_ni_gain_fx, 0, BANDS_MAX ); - set16_fx( st_fx->last_env_fx, 0, BANDS_MAX ); - st_fx->last_max_pos_pulse_fx = 0; - move16(); - - st_fx->mode_count_fx = 0; - move16(); - st_fx->mode_count1_fx = 0; - move16(); - - set16_fx( st_fx->prev_SWB_peak_pos_fx, 0, SPT_SHORTEN_SBNUM ); - st_fx->prev_frm_hfe2_fx = 0; - move16(); - st_fx->prev_stab_hfe2_fx = 0; - move16(); - - /*ALDO overlap windowed past: also used in MODE2 but for other MDCT-LB*/ - set16_fx( st_fx->old_out_fx, 0, L_FRAME32k ); - } - - test(); - IF( (sub(st_fx->L_frame_fx,L_FRAME16k) == 0) && (sub(st_fx->last_L_frame_fx,L_FRAME) == 0)) - { - Copy( st_fx->lsp_old_fx, st_fx->lsp_old16k_fx, M ); - - st_fx->rate_switching_reset_16kHz = lsp_convert_poly_fx( st_fx->lsp_old16k_fx, st_fx->L_frame_fx, 0 ); - } - - st_fx->use_acelp_preq = 0; - move16(); - - } - - test(); - IF( add(st_fx->last_core_fx, 1) == 0 && sub(st_fx->core_fx, HQ_CORE) == 0 ) - { - /* very first frame is HQ_CORE */ - st_fx->last_core_fx = HQ_CORE; - move16(); - } - - test(); - test(); - IF( sub(st_fx->core_fx, HQ_CORE) == 0 && ( sub(st_fx->last_core_fx, ACELP_CORE) == 0 || sub(st_fx->last_core_fx, AMR_WB_CORE) == 0 ) ) /* HQ init */ - { - set32_fx( st_fx->last_ni_gain_fx, 0, BANDS_MAX ); - set16_fx( st_fx->last_env_fx, 0, BANDS_MAX ); - st_fx->last_max_pos_pulse_fx = 0; - move16(); - - st_fx->mode_count_fx = 0; - move16(); - st_fx->mode_count1_fx = 0; - move16(); - - set16_fx( st_fx->prev_SWB_peak_pos_fx, 0, SPT_SHORTEN_SBNUM ); - st_fx->prev_frm_hfe2_fx = 0; - move16(); - st_fx->prev_stab_hfe2_fx = 0; - move16(); - - set16_fx( st_fx->old_out_fx, 0, L_FRAME32k ); - } - - /* Here we only handle cases where last_ppp and last_nelp not updated when coming from CodecB or other cores - within ACELP_CORE if switching from another bitarate to vbr, last_ppp and last_nelp is always updated in the previous frame */ - test(); - test(); - IF( sub(st_fx->core_fx, ACELP_CORE) == 0 && (sub(st_fx->last_core_fx, ACELP_CORE) != 0 || sub(st_fx->last_codec_mode,MODE2) == 0 )) - { - st_fx->last_last_ppp_mode_fx = 0; - move16(); - st_fx->last_ppp_mode_fx = 0; - move16(); - st_fx->last_nelp_mode_fx =0; - move16(); - } - - test(); - test(); - test(); - IF( sub(st_fx->core_fx, ACELP_CORE) == 0 && ( sub(st_fx->last_core_fx, ACELP_CORE) != 0 || sub(st_fx->last_codec_mode,MODE2) == 0 || L_sub(st_fx->last_total_brate_fx, PPP_NELP_2k80) <= 0 )) - { - st_fx->act_count_fx = 3; - move16(); - st_fx->uv_count_fx = 0; - move16(); - } - - test(); - test(); - IF( ( sub(st_fx->core_fx, ACELP_CORE) == 0 || sub(st_fx->core_fx, AMR_WB_CORE) == 0 ) && sub(st_fx->last_core_fx, HQ_CORE) == 0 ) - { - IF(sub(st_fx->L_frame_fx, L_FRAME16k)==0 ) - { - Copy( TRWB2_Ave_fx, st_fx->lsf_old_fx, M ); /* init of LSP */ - lsf2lsp_fx( st_fx->lsf_old_fx, st_fx->lsp_old_fx, M, INT_FS_16k ); - } - ELSE - { - Copy( TRWB_Ave_fx, st_fx->lsf_old_fx, M ); /* init of LSP */ - lsf2lsp_fx( st_fx->lsf_old_fx, st_fx->lsp_old_fx, M, INT_FS_FX ); - } - - st_fx->mem_deemph_fx = 0; - move16(); - st_fx->LPDmem.syn[M] = 0; - move16(); - set16_fx(mem->mem_syn2, 0, M ); - set16_fx( mem->mem_syn, 0, M ); - set16_fx( st_fx->mem_syn1_fx, 0, M ); - st_fx->Nb_ACELP_frames_fx = 0; - move16(); - - /* Reset ACELP parameters */ - set16_fx( st_fx->mem_MA_fx,0, M ); - Copy( GEWB_Ave_fx, st_fx->mem_AR_fx, M ); - mem->mem_w0 = 0; - move16(); - mem->tilt_code = 0; - move16(); - init_gp_clip_fx( st_fx->clip_var_fx ); - mem->gc_threshold = 0; - move16(); - - /* set16_fx( st_fx->dispMem, 0, 8 ); */ - set16_fx( st_fx->dm_fx.prev_gain_pit, 0, 6 ); - st_fx->dm_fx.prev_state = 0; - move16(); - st_fx->dm_fx.prev_gain_code = L_deposit_l(0); - - st_fx->last_coder_type_fx = GENERIC; - move16(); - - tmp16 = add(NB_SUBFR,1); - move16(); - - if( sub(st_fx->L_frame_fx,L_FRAME) == 0 ) - { - tmp16=NB_SUBFR; - move16(); - } - - Copy( st_fx->old_pitch_buf_fx + tmp16, st_fx->old_pitch_buf_fx, tmp16 ); - set16_fx( st_fx->old_pitch_buf_fx + tmp16, L_SUBFR,tmp16); - - /* Reset old ACELP buffers */ - set16_fx( mem->old_exc, 0, L_EXC_MEM ); - set16_fx( st_fx->old_bwe_exc_fx, 0, PIT16k_MAX*2 ); - - /* reset BWE memories */ - st_fx->bwe_non_lin_prev_scale_fx = 0; - set16_fx( st_fx->old_syn_12k8_16k_fx, 0, NS2SA(16000, DELAY_FD_BWE_ENC_NS) ); - } - - test(); - test(); - IF( L_sub(st_fx->input_Fs_fx, 16000) >= 0 && sub(st_fx->last_extl_fx, WB_BWE) != 0 && sub(st_fx->extl_fx, WB_BWE) == 0 ) - { - test(); - IF( sub(st_fx->last_extl_fx, SWB_BWE) != 0 && sub(st_fx->last_extl_fx, FB_BWE) != 0 ) - { - st_fx->prev_mode_fx = NORMAL; - move16(); - st_fx->modeCount_fx = 0; - move16(); - } - - st_fx->prev_L_swb_norm1_fx = 8; - move16(); - } - - test(); - test(); - test(); - test(); - test(); - IF( ( L_sub(st_fx->input_Fs_fx, 32000) >= 0 && sub(st_fx->last_extl_fx, SWB_BWE) != 0 && sub(st_fx->extl_fx, SWB_BWE) == 0 ) || - ( L_sub(st_fx->input_Fs_fx, 48000) >= 0 && sub(st_fx->last_extl_fx, FB_BWE) != 0 && sub(st_fx->extl_fx, FB_BWE) == 0 ) ) - { - /* we are switching to SWB BWE - reset SWB BWE buffers */ - - IF( sub(st_fx->L_frame_fx, L_FRAME) == 0 ) - { - Sample_Delay_HP = NS2SA( 16000, ACELP_LOOK_NS + DELAY_FD_BWE_ENC_12k8_NS + DELAY_FIR_RESAMPL_NS - DELAY_CLDFB_NS ); - Sample_Delay_LP = NS2SA( 12800, ACELP_LOOK_NS + DELAY_FD_BWE_ENC_12k8_NS ); - - Copy( old_inp_12k8 + sub(L_INP_MEM + L_FRAME, Sample_Delay_LP), st_fx->old_input_lp_fx, Sample_Delay_LP ); - } - ELSE - { - Sample_Delay_HP = NS2SA( 16000, ACELP_LOOK_NS + DELAY_FD_BWE_ENC_16k_NS + DELAY_FIR_RESAMPL_NS - DELAY_CLDFB_NS ); - Sample_Delay_LP = NS2SA( 16000, ACELP_LOOK_NS + DELAY_FD_BWE_ENC_16k_NS ); - Copy( old_inp_16k + sub(L_INP_MEM + L_FRAME, Sample_Delay_LP), st_fx->old_input_lp_fx, Sample_Delay_LP ); - } - - tmp = sub(L_LOOK_16k + L_SUBFR16k, Sample_Delay_HP); - Copy( &st_fx->old_speech_shb_fx[tmp], st_fx->new_input_hp_fx, Sample_Delay_HP ); - add(0,0); - - IF (sub(st_fx->last_extl_fx,WB_BWE) != 0) - { - st_fx->prev_mode_fx = NORMAL; - move16(); - st_fx->modeCount_fx = 0; - move16(); - } - st_fx->EnergyLF_fx = L_deposit_l(0); - st_fx->prev_L_swb_norm1_fx = 8; - move16();/*8.0 in Q0 */ - st_fx->EnergyLT_fx_exp = 30; - move16(); /* Set to a High Exponent so it is 1^-30 */ - } - - return; -} - - - -/*---------------------------------------------------------------------* -* core_switching_post_enc() -* -* Postprocessing for ACELP/HQ core switching -*---------------------------------------------------------------------*/ -void core_switching_post_enc_fx( - Encoder_State_fx *st_fx, /* i/o: encoder state structure */ - const Word16 old_inp_12k8[], /* i : input signal @12.8 kHz Qinp */ - const Word16 old_inp_16k[], /* i : input signal @16 kHz Qinp */ - const Word16 pitch[3], /* i : open-loop pitch values for quantiz. */ - const Word16 voicing[3], /* i : Open-loop pitch gains */ - const Word16 A[], /* i : unquant. LP filter coefs. (Q12) */ - Word16 Qshift, - Word16 Q_new, - const Word16 Qsp, /* i/o : Q from acelp synthsis */ - Word16 *Qmus /* i/o : Q from mdct synthsis / Q of output synthesis */ -) -{ - Word16 T_op[3]; - - Copy( pitch, T_op, 3 ); - - IF( sub(st_fx->core_fx, HQ_CORE) == 0 ) - { - st_fx->use_acelp_preq = 0; - move16(); - - test(); - IF( ( sub(st_fx->last_core_fx, ACELP_CORE) == 0 || sub(st_fx->last_core_fx, AMR_WB_CORE) == 0) ) /* core switching ==> CELP subframe encoding */ - { - acelp_core_switch_enc_fx( st_fx, &(st_fx->LPDmem),old_inp_12k8 + L_INP_MEM - NS2SA_fx2(INT_FS_FX, ACELP_LOOK_NS), - old_inp_16k + L_INP_MEM - NS2SA_fx2(INT_FS_16k, ACELP_LOOK_NS), T_op, voicing, A, Qshift, Q_new ); - } - - st_fx->bwe_non_lin_prev_scale_fx = L_deposit_l(0); - st_fx->mem_deemph_old_syn_fx = 0; - move16(); - - } - ELSE - { - *Qmus=Qsp; /* Write Qout */ - - /* reset SWB TBE buffers */ - test(); - IF( sub(st_fx->extl_fx, WB_TBE) == 0 && sub(st_fx->last_extl_fx, WB_TBE) != 0 ) - { - wb_tbe_extras_reset_fx( st_fx->mem_genSHBexc_filt_down_wb2_fx, st_fx->mem_genSHBexc_filt_down_wb3_fx ); - - IF ( sub(st_fx->last_extl_fx, WB_BWE) != 0 ) - { - set16_fx( st_fx->decim_state1_fx, 0, 2*ALLPASSSECTIONS_STEEP+1 ); - set16_fx( st_fx->decim_state2_fx, 0, 2*ALLPASSSECTIONS_STEEP+1 ); - } - - set16_fx( st_fx->state_syn_shbexc_fx, 0, L_SHB_LAHEAD/4 ); - set16_fx( st_fx->syn_overlap_fx, 0, L_SHB_LAHEAD ); - set32_fx( st_fx->mem_csfilt_fx, 0, 2 ); - } - - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - IF( (sub(st_fx->extl_fx, SWB_TBE) == 0 || sub(st_fx->extl_fx, FB_TBE) == 0) && - ( sub(st_fx->last_core_fx,HQ_CORE) == 0 || sub(st_fx->L_frame_fx, st_fx->last_L_frame_fx) != 0 || - ( sub(st_fx->last_extl_fx, SWB_TBE) != 0 && sub(st_fx->last_extl_fx, FB_TBE) != 0 ) ) - ) - { - set16_fx( st_fx->state_ana_filt_shb_fx, 0, (2*ALLPASSSECTIONS_STEEP+1) ); - set16_fx( st_fx->old_speech_shb_fx, 0, L_LOOK_16k + L_SUBFR16k ); - - swb_tbe_reset_fx( st_fx->mem_csfilt_fx, st_fx->mem_genSHBexc_filt_down_shb_fx, st_fx->state_lpc_syn_fx, - st_fx->syn_overlap_fx, st_fx->state_syn_shbexc_fx, &(st_fx->tbe_demph_fx), &(st_fx->tbe_premph_fx), - st_fx->mem_stp_swb_fx, &(st_fx->gain_prec_swb_fx)); - - set16_fx( st_fx->dec_2_over_3_mem_fx,0, 12 ); - set16_fx( st_fx->dec_2_over_3_mem_lp_fx,0, 6 ); - } - ELSE IF( ( sub(st_fx->extl_fx, SWB_TBE) == 0 || sub(st_fx->extl_fx, FB_TBE) == 0 ) && - ( L_sub(st_fx->last_total_brate_fx, st_fx->total_brate_fx) != 0 || sub(st_fx->last_bwidth_fx, st_fx->bwidth_fx) != 0 || - sub(st_fx->last_codec_mode, MODE1) != 0 || sub(st_fx->rf_mode, st_fx->rf_mode_last) != 0 ) ) - { - set16_fx( st_fx->state_lpc_syn_fx, 0, LPC_SHB_ORDER ); - set16_fx( st_fx->state_syn_shbexc_fx, 0, L_SHB_LAHEAD ); - set16_fx( st_fx->mem_stp_swb_fx, 0, LPC_SHB_ORDER ); - set16_fx( st_fx->mem_zero_swb_fx, 0, LPC_SHB_ORDER ); - st_fx->gain_prec_swb_fx = 16384; - move16(); /*Q14 = 1 */ - } - - test(); - test(); - IF( sub(st_fx->extl_fx, FB_TBE) == 0 && ( sub(st_fx->last_extl_fx, FB_TBE) != 0 || sub(st_fx->L_frame_fx, st_fx->last_L_frame_fx) != 0 ) ) - { - set16_fx( st_fx->fb_state_lpc_syn_fx, 0, LPC_SHB_ORDER ); - st_fx->fb_tbe_demph_fx = 0; - fb_tbe_reset_enc_fx( st_fx->elliptic_bpf_2_48k_mem_fx, &st_fx->prev_fb_energy_fx,st_fx->elliptic_bpf_2_48k_mem_fx_Q,&st_fx->prev_fb_energy_fx_Q); - } - } - - return; -} - -/*---------------------------------------------------------------------* -* core_switching_hq_prepare_enc() -* -* Preprocessing in the first HQ frame after ACELP frame -* - modify bit allocation for HQcore removing CELP subframe budget -* - update st->old_wtda to modify windows at the encoder -*---------------------------------------------------------------------*/ - -void core_switching_hq_prepare_enc_fx( - Encoder_State_fx *st_fx, /* i/o: encoder state structure */ - Word16 *num_bits, /* i/o: bit budget update */ - const Word16 input_frame, /* i : frame length */ - Word32 *wtda_audio, /* shall be q_audio + 15, audio allready scalled in wtda function */ - const Word16 *audio -) -{ - Word16 delta, Loverlapp, i; - Word16 tmp16; - Word32 cbrate, *pt_32; - const Word16 *pt_cos, *pt_16; - Word16 n; - - SWITCH (input_frame) - { - case L_FRAME8k: - delta = 1; - move16(); - pt_cos= sin_switch_8; - BREAK; - case L_FRAME16k: - delta = 2; - move16(); - pt_cos= sin_switch_16; - BREAK; - case L_FRAME32k: - delta = 4; - move16(); - pt_cos= sin_switch_32; - BREAK; - default : - delta = 6; - move16(); - pt_cos= sin_switch_48; - BREAK; - } - - /* set switching frame bit-rate */ - IF( sub(st_fx->last_L_frame_fx, L_FRAME) == 0 ) - { - IF( L_sub(st_fx->core_brate_fx, ACELP_24k40) > 0 ) - { - cbrate = L_add(ACELP_24k40, 0); - } - ELSE - { - cbrate = L_add(st_fx->core_brate_fx, 0); - } - - /* subtract ACELP switching frame bits */ - IF( L_sub(st_fx->core_brate_fx, ACELP_11k60) >= 0 ) - { - (*num_bits) = sub((*num_bits), 1); /* LP_FLAG bit */ - } - *num_bits = sub( (*num_bits), ACB_bits_tbl[BIT_ALLOC_IDX_fx(cbrate, GENERIC, 0, 0)] ); /* pitch bits*/ - *num_bits = sub( (*num_bits), gain_bits_tbl[BIT_ALLOC_IDX_fx(cbrate, TRANSITION, 0, 0)] ); /* gain bits */ - *num_bits = sub( (*num_bits), FCB_bits_tbl[BIT_ALLOC_IDX_fx(cbrate, GENERIC, 0, 0)] ); /* FCB bits */ - } - ELSE /* L_frame == L_FRAME16k */ - { - IF( L_sub(st_fx->core_brate_fx, ACELP_8k00) <= 0 ) - { - cbrate = L_add(ACELP_8k00, 0); - } - ELSE IF( L_sub(st_fx->core_brate_fx, ACELP_14k80) <= 0 ) - { - cbrate = L_add(ACELP_14k80, 0); - } - ELSE - { - cbrate = L_min(st_fx->core_brate_fx, ACELP_22k60); - } - - /* subtract ACELP switching frame bits */ - IF( L_sub(st_fx->core_brate_fx, ACELP_11k60) >= 0 ) - { - (*num_bits) = sub((*num_bits), 1); /* LP_FLAG bit */ - } - *num_bits = sub((*num_bits), ACB_bits_16kHz_tbl[BIT_ALLOC_IDX_16KHZ_fx(cbrate, GENERIC, 0, 0)]); /* pitch bits*/ - *num_bits = sub((*num_bits), gain_bits_16kHz_tbl[BIT_ALLOC_IDX_16KHZ_fx(cbrate, GENERIC, 0, 0)]); /* gain bits */ - *num_bits = sub((*num_bits), FCB_bits_16kHz_tbl[BIT_ALLOC_IDX_16KHZ_fx(cbrate, GENERIC, 0, 0)]); /* FCB bits */ - } - - /* subtract BWE bits */ - test(); - test(); - IF( !( ( sub(inner_frame_tbl[st_fx->bwidth_fx], L_FRAME16k) == 0 && sub(st_fx->last_L_frame_fx, L_FRAME16k) == 0 ) || sub(inner_frame_tbl[st_fx->bwidth_fx], L_FRAME8k) == 0 ) ) - { - *num_bits = sub((*num_bits), (NOOFGAINBITS1 + AUDIODELAYBITS)); - } - - /* Transition window at the encoder */ - n=i_mult2(N_ZERO_8,delta); - Loverlapp=i_mult2(SWITCH_OVERLAP_8k,delta); - /*Overflow=0; */ - - pt_32 = wtda_audio+shr(input_frame,1); - pt_16 = audio+sub(n,1); - tmp16 = sub(shr(input_frame,1),Loverlapp); - - FOR( i = 0; i < tmp16; i++ ) - { - /* wtda_audio[i+input_frame/2] = - audio[n-i-1]; */ - *pt_32++=L_negate(L_shr(L_deposit_h(*pt_16--),1)); /* Q +16 -1 */ - } - - pt_cos = pt_cos + Loverlapp - 1; - FOR( i = tmp16; i < shr(input_frame,1); i++ ) - { - /* *pt_32++ = - audio[n-i-1] *(float)cos((i+1-input_frame/2+Loverlapp)*EVS_PI/(2*(Loverlapp+1))); win=cos() */ - *pt_32++=L_negate(L_mult0(*pt_16--,*pt_cos--)); - } - - /* reset state of old_out if switching */ - set16_fx( st_fx->old_out_fx, 0, L_FRAME32k ); - - return; -} diff --git a/src/libs/libevs/lib_enc/corr_xh.cpp b/src/libs/libevs/lib_enc/corr_xh.cpp new file mode 100644 index 00000000..43803406 --- /dev/null +++ b/src/libs/libevs/lib_enc/corr_xh.cpp @@ -0,0 +1,41 @@ +/*==================================================================================== + EVS Codec 3GPP TS26.443 Nov 13, 2018. Version 12.11.0 / 13.7.0 / 14.3.0 / 15.1.0 + ====================================================================================*/ + +#include +#include "options.h" +#include "prot.h" +#include "cnst.h" + +/*-------------------------------------------------------------------* + * corr_xh() + * + * Compute the correlation between the target signal and the impulse + * response of the weighted synthesis filter. + * + * y[i] = sum(j=i,l-1) x[j]*h[j-i], i=0,l-1 + *-------------------------------------------------------------------*/ + +void corr_xh( + const float *x, /* i : target signal */ + float *y, /* o : correlation between x[] and h[] */ + const float *h, /* i : impulse response (of weighted synthesis filter) */ + const int L_subfr /* i : length of the subframe */ +) +{ + short i, j; + float s; + + for (i = 0; i < L_subfr; i++) + { + s = 0.0f; + for (j = i; j < L_subfr; j++) + { + s += x[j]*h[j-i]; + } + + y[i] = s; + } + + return; +} diff --git a/src/libs/libevs/lib_enc/corr_xh_fx.cpp b/src/libs/libevs/lib_enc/corr_xh_fx.cpp deleted file mode 100755 index a6019032..00000000 --- a/src/libs/libevs/lib_enc/corr_xh_fx.cpp +++ /dev/null @@ -1,65 +0,0 @@ -/*==================================================================================== - EVS Codec 3GPP TS26.442 Apr 03, 2018. Version 12.11.0 / 13.6.0 / 14.2.0 - ====================================================================================*/ - -#include "options.h" -#include "prot_fx.h" -#include "cnst_fx.h" -#include "stl.h" - - -#define NB_TRACK 4 -#define STEP NB_TRACK - -/*-------------------------------------------------------------------* - * corr_xh_fx: - * - * Compute the correlation between the target signal and the impulse - * response of the weighted synthesis filter. - * - * y[i]=sum(j=i,l-1) x[j]*h[j-i], i=0,l-1 - *-------------------------------------------------------------------*/ -void corr_xh_fx( - const Word16 x[], /* i : target signal */ - Word16 dn[], /* o : correlation between x[] and h[] */ - const Word16 h[] /* i : impulse response (of weighted synthesis filter) */ -) -{ - Word16 i, j, k; - Word32 L_tmp, y32[L_SUBFR], L_maxloc, L_tot; - - /* first keep the result on 32 bits and find absolute maximum */ - L_tot = L_deposit_l(1); - - FOR (k = 0; k < NB_TRACK; k++) - { - L_maxloc = L_deposit_l(0); - FOR (i = k; i < L_SUBFR; i += STEP) - { - L_tmp = L_mac(1L, x[i], h[0]); /* 1 -> to avoid null dn[] */ - FOR (j = i; j < L_SUBFR-1; j++) - { - L_tmp = L_mac(L_tmp, x[j+1], h[j+1 - i]); - } - - y32[i] = L_tmp; - move32(); - L_tmp = L_abs(L_tmp); - L_maxloc = L_max(L_tmp, L_maxloc); - } - /* tot += 3*max / 8 */ - L_maxloc = L_shr(L_maxloc, 2); - L_tot = L_add(L_tot, L_maxloc); /* +max/4 */ - L_tot = L_add(L_tot, L_shr(L_maxloc, 1)); /* +max/8 */ - } - - /* Find the number of right shifts to do on y32[] so that */ - /* 6.0 x sumation of max of dn[] in each track not saturate. */ - - j = sub(norm_l(L_tot), 4); /* 4 -> 16 x tot */ - - FOR (i = 0; i < L_SUBFR; i++) - { - dn[i] = round_fx(L_shl(y32[i], j)); - } -} diff --git a/src/libs/libevs/lib_enc/decision_matrix_enc.cpp b/src/libs/libevs/lib_enc/decision_matrix_enc.cpp new file mode 100644 index 00000000..ebddae1a --- /dev/null +++ b/src/libs/libevs/lib_enc/decision_matrix_enc.cpp @@ -0,0 +1,636 @@ +/*==================================================================================== + EVS Codec 3GPP TS26.443 Nov 13, 2018. Version 12.11.0 / 13.7.0 / 14.3.0 / 15.1.0 + ====================================================================================*/ + +#include +#include +#include "options.h" +#include "prot.h" +#include "stat_enc.h" +#include "stat_dec.h" +#include "rom_com.h" + + +/*-----------------------------------------------------------------* + * decision_matrix_enc() + * + * Select operating point (combination of technologies) based on input signal properties and command-line parameters: + * + * 7.20 8.00 9.60 13.20 16.40 24.40 32 48 64 96 128 + * Mode 1 1 2 1 2 2 1 2 1 2 2 + * ---------------------------------------------------------------------------------------------------------------------------------------------------------------- + * NB + * speech ACELP@12k8 ACELP@12k8 ACELP@12k8 ACELP@12k8 + * audio LR MDCT LR MDCT TCX LR MDCT + * inactive GSC@12k8 GSC@12k8 TCX GSC@12k8 + * ---------------------------------------------------------------------------------------------------------------------------------------------------------------- + * WB + * speech ACELP@12k8 ACELP@12k8 ACELP@12k8 ACELP@12k8 ACELP@16k ACELP@16k ACELP@16k TCX ACELP@16k TCX TCX + * +0b WB BWE +0b WB BWE +TD WB BWE +TD WB BWE + * audio GSC@12k8 GSC@12k8 TCX LR MDCT TCX TCX HQ TCX HQ TCX TCX + * +0b WB BWE +0b WB BWE +IGF + * inactive GSC@12k8 GSC@12k8 TCX GSC@12k8 TCX TCX AVQ@16k TCX AVQ@16k TCX TCX + * +0b WB BWE +0b WB BWE +IGF +FD WB BWE + * ---------------------------------------------------------------------------------------------------------------------------------------------------------------- + * SWB + * speech ACELP@12k8 ACELP@16k ACELP@16k ACELP@16k TCX ACELP@16k TCX TCX + * +TD SWB BWE +TD SWB BWE +TD SWB BWE +TD SWB BWE +IGF +HR SWB BWE + * audio LR MDCT/GSC TCX TCX HQ TCX HQ TCX TCX + * +FD SWB BWE +IGF +IGF +FD SWB BWE +IGF + * inactive GSC@12k8 TCX TCX AVQ@16k TCX AVQ@16k TCX TCX + * +FD SWB BWE +IGF +IGF +FD SWB BWE +IGF +HR SWB BWE + * ---------------------------------------------------------------------------------------------------------------------------------------------------------------- + * FB + * speech ACELP@16k ACELP@16k ACELP@16k TCX ACELP@16k TCX TCX + * +TD FB BWE +TD FB BWE +TD FB BWE +IGF +HR FB BWE + * audio TCX TCX HQ TCX HQ TCX TCX + * +IGF +IGF +FD FB BWE +IGF + * inactive TCX TCX AVQ@16k TCX AVQ@16k TCX TCX + * +IGF +IGF +FD FB BWE +IGF +HR FB BWE + * ----------------------------------------------------------------------------------------------------------------------------------------------------------------- + * + * Note: the GSC technology is part of the ACELP core as AUDIO coder_type (it is used also at 13.2 for SWB unvoiced noisy speech) + * Note2: FB processing is optional and is activated via "-band FB" option on the encoder command line + * Note3: NB (0-4kHz), WB (0-8kHz), SWB (0-16kHz), FB (0-20kHz) + * + * Signalling of modes (x marks a mode that must be signalled in the bitstream) + * + * 7.20 8.00 9.6 13.2 16.4 24.4 32 48 64 + * NB WB SWB FB NB WB SWB FB NB WB SWB FB NB WB SWB FB NB WB SWB FB NB WB SWB FB NB WB SWB FB NB WB SWB FB NB WB SWB FB + * GC, 12k8 x x x x x x x x x x x x x + * UC, 12k8 x x x x x x + * VC, 12k8 x x x x x x x x x x x x x + * TC, 12k8 x x x x x x x x x x x x x + * GC, 16k x x x x x x x x x x x x + * TC, 16k x x x x x x x x x x x x + * AC(GSC) x x x x x x x x x x x x x + * IC x x x x x x x x x x x x x x x x x x x x x x x x x + * + * GC, 12k8, FS x x x x x x x x x x x x x + * GC, 16k, FS x x x x x x x x x x x + * VC, 12k8, FS x x x x x x x + * TC, 12k8, FS x + * TC, 16k, FS x x x x x x x x x x x + * + * LR MDCT x x x x x x x x x x x + * + *-----------------------------------------------------------------*/ + +void decision_matrix_enc( + Encoder_State *st, /* i : encoder state structure */ + const short sp_aud_decision1, /* i : 1st stage speech/music classification */ + const short sp_aud_decision2, /* i : 2nd stage speech/music classification */ + const short coder_type, /* i : coder type */ + const short vad_flag, + short *hq_core_type /* o : HQ core type */ +) +{ + /* initialization */ + st->core = -1; + st->extl = -1; + st->extl_brate = 0; + *hq_core_type = -1; + st->igf = 0; + + /* SID and FRAME__NO_DATA frames */ + if( st->Opt_DTX_ON && (st->core_brate == SID_2k40 || st->core_brate == FRAME__NO_DATA ) ) + { + st->core = ACELP_CORE; + + if( st->input_Fs >= 32000 && st->bwidth >= SWB ) + { + st->extl = SWB_CNG; + } + + st->rf_mode = 0; + + return; + } + + st->core_brate = 0; + + /* SC-VBR */ + if ( st->Opt_SC_VBR ) + { + /* SC-VBR */ + st->core = ACELP_CORE; + st->core_brate = ACELP_7k20; + st->total_brate = ACELP_7k20; + + if ( st->ppp_mode == 1 ) + { + /* PPP mode */ + st->core_brate = PPP_NELP_2k80; + } + else if( ((coder_type == UNVOICED || coder_type == TRANSITION) && !sp_aud_decision1) || st->bwidth != NB ) + { + + if( coder_type == UNVOICED && vad_flag == 1 && ( ( st->last_bwidth >= SWB && st->last_Opt_SC_VBR ) || st->last_bwidth < SWB ) + && (st->last_core!=HQ_CORE || st->bwidth != NB) ) + { + /* NELP mode */ + st->nelp_mode = 1; + st->core_brate = PPP_NELP_2k80; + } + else if ( coder_type == TRANSITION || ( coder_type == UNVOICED && st->nelp_mode != 1 ) || + ( ( coder_type == AUDIO || coder_type == INACTIVE ) && st->bwidth != NB ) ) + { + /* silence portions */ + st->core_brate = ACELP_8k00; + st->total_brate = ACELP_8k00; + } + } + + return; + } + + /*---------------------------------------------------------------------* + * NB + *---------------------------------------------------------------------*/ + + else if ( st->bwidth == NB ) + { + st->core = ACELP_CORE; + + if( st->total_brate >= HQCORE_NB_MIN_RATE && sp_aud_decision1 == 1 ) + { + st->core = HQ_CORE; + } + } + + /*---------------------------------------------------------------------* + * WB + *---------------------------------------------------------------------*/ + + else if ( st->bwidth == WB ) + { + st->core = ACELP_CORE; + + if( ( st->total_brate >= HQCORE_WB_MIN_RATE && sp_aud_decision1 == 1 ) || st->total_brate >= HQ_96k ) + { + st->core = HQ_CORE; + } + else + { + if ( st->bwidth == WB && st->total_brate < ACELP_9k60 ) + { + st->extl = WB_BWE; + } + else if ( st->bwidth == WB && st->total_brate >= ACELP_9k60 && st->total_brate <= ACELP_16k40 ) + { + /* Note: WB BWE is used exceptionally at 13.2 kbps if GSC is selected instead of LR-MDCT */ + if ( sp_aud_decision1 == 1 || coder_type == INACTIVE || ( sp_aud_decision1 == 0 && sp_aud_decision2 == 1 ) ) + { + st->extl = WB_BWE; + st->extl_brate = WB_BWE_0k35; + } + else + { + st->extl = WB_TBE; + st->extl_brate = WB_TBE_1k05; + } + } + } + } + + /*---------------------------------------------------------------------* + * SWB and FB + *---------------------------------------------------------------------*/ + + else if ( st->bwidth == SWB || st->bwidth == FB ) + { + if( ( st->total_brate >= HQCORE_SWB_MIN_RATE && sp_aud_decision1 == 1 ) || st->total_brate >= HQ_96k ) + { + st->core = HQ_CORE; + } + else + { + st->core = ACELP_CORE; + + if ( st->total_brate >= ACELP_13k20 && st->total_brate < ACELP_48k ) + { + /* Note: SWB BWE is not used in case of GSC noisy speech */ + /* Note: SWB BWE is used exceptionally at 13.2 kbps if GSC is selected instead of LR-MDCT */ + if ( ( sp_aud_decision1 == 1 || coder_type == INACTIVE || ( sp_aud_decision1 == 0 && sp_aud_decision2 == 1 ) ) && !st->GSC_noisy_speech ) + { + st->extl = SWB_BWE; + st->extl_brate = SWB_BWE_1k6; + + if ( st->bwidth == FB && st->total_brate >= ACELP_24k40 ) + { + st->extl = FB_BWE; + st->extl_brate = FB_BWE_1k8; + } + } + else + { + st->extl = SWB_TBE; + st->extl_brate = SWB_TBE_1k6; + + if( st->total_brate >= ACELP_24k40 ) + { + st->extl_brate = SWB_TBE_2k8; + } + + if ( st->bwidth == FB && st->total_brate >= ACELP_24k40 ) + { + st->extl = FB_TBE; + st->extl_brate = FB_TBE_3k0; + } + } + } + else if ( st->total_brate >= ACELP_48k ) + { + st->extl = SWB_BWE_HIGHRATE; + st->extl_brate = SWB_BWE_16k; + + if( st->bwidth == FB ) + { + st->extl = FB_BWE_HIGHRATE; + } + } + } + } + + /*-----------------------------------------------------------------* + * Set HQ core type + *-----------------------------------------------------------------*/ + + if( st->core == HQ_CORE ) + { + *hq_core_type = NORMAL_HQ_CORE; + + if( (st->bwidth == SWB || st->bwidth == WB) && st->total_brate <= LRMDCT_CROSSOVER_POINT ) + { + /* note that FB (bit-rate >= 24400bps) is always coded with NORMAL_HQ_CORE */ + *hq_core_type = LOW_RATE_HQ_CORE; + } + else if( st->bwidth == NB ) + { + *hq_core_type = LOW_RATE_HQ_CORE; + } + } + + /* set core bitrate */ + st->core_brate = st->total_brate - st->extl_brate; + + if ( st->ini_frame == 0 ) + { + /* avoid switching in the very first frame */ + st->last_core = st->core; + st->last_core_brate = st->core_brate; + st->last_extl = st->extl; + } + + return; +} + +/*---------------------------------------------------------------------* + * signalling_mode1_tcx20_enc() + * + * write MODE1 TCX20 signalling information into the bit-stream + *---------------------------------------------------------------------*/ + +short signalling_mode1_tcx20_enc( + Encoder_State *st, /* i/o: encoder state structure */ + const short push /* i : flag to push indice */ +) +{ + short num_bits; + short nBits, idx, start_idx; + + assert(st->core == TCX_20_CORE); + + num_bits = 0; + + /* Use ACELP signaling for LR MDCT */ + if ( st->total_brate <= ACELP_16k40 ) + { + /* find the section in the ACELP signalling table corresponding to bitrate */ + idx = 0; + while ( acelp_sig_tbl[idx] != st->total_brate ) + { + idx++; + } + + /* retrieve the number of bits for signalling */ + nBits = (short) acelp_sig_tbl[++idx]; + + /* retrieve the signalling index */ + start_idx = ++idx; + while( acelp_sig_tbl[idx] != SIG2IND(LR_MDCT, st->bwidth, 0, 0) ) + { + idx++; + } + + num_bits += nBits; + if( push ) + { + push_indice( st, IND_ACELP_SIGNALLING, idx - start_idx, nBits ); + } + + /* HQ/TCX core switching flag */ + ++num_bits; + if( push ) + { + push_indice( st, IND_MDCT_CORE, 1, 1 ); + } + } + else + { + if( st->core_brate <= ACELP_64k ) + { + /* write ACELP/HQ core indication flag */ + ++num_bits; + if( push ) + { + push_indice( st, IND_CORE, 1, 1 ); + } + } + + /* HQ/TCX core switching flag */ + ++num_bits; + if( push ) + { + push_indice( st, IND_MDCT_CORE, 1, 1 ); + } + + num_bits += 2; + if( push ) + { + /* write band-width (needed for different I/O sampling rate support) */ + if( st->bwidth == NB ) + { + push_indice( st, IND_HQ_BWIDTH, 0, 2 ); + } + else if( st->bwidth == WB ) + { + push_indice( st, IND_HQ_BWIDTH, 1, 2 ); + } + else if( st->bwidth == SWB ) + { + push_indice( st, IND_HQ_BWIDTH, 2, 2 ); + } + else /* st->bwidth == FB */ + { + push_indice( st, IND_HQ_BWIDTH, 3, 2 ); + } + } + } + + return num_bits; +} + + +/*---------------------------------------------------------------------* + * signalling_enc() + * + * write signalling information into the bit-stream + *---------------------------------------------------------------------*/ + +void signalling_enc( + Encoder_State *st, /* i : encoder state structure */ + const short coder_type, /* i : coder type */ + const short sharpFlag /* i : formant sharpening flag */ +) +{ + short nBits, idx, start_idx; + + if( st->mdct_sw == MODE2 ) + { + + assert(!st->tcxonly); + assert(st->core == HQ_CORE); + + push_next_indice(st, 1, 1); /* TCX */ + push_next_indice(st, 1, 1); /* HQ_CORE */ + + /* write ACELP->HQ core switching flag */ + if( st->last_core == ACELP_CORE || st->last_core == AMR_WB_CORE ) + { + push_indice( st, IND_HQ_SWITCHING_FLG, 1, 1 ); + + /* write ACELP L_frame info */ + if( st->last_L_frame == L_FRAME ) + { + push_indice( st, IND_LAST_L_FRAME, 0, 1 ); + } + else + { + push_indice( st, IND_LAST_L_FRAME, 1, 1 ); + } + } + else + { + push_indice( st, IND_HQ_SWITCHING_FLG, 0, 1 ); + } + + return; + } + + if( st->core == ACELP_CORE ) + { + if( st->ppp_mode == 1 || st->nelp_mode == 1 ) + { + /* 1 bit to distinguish between 2.8kbps PPP/NELP frame and SID frame */ + push_indice( st, IND_CORE, 0, 1 ); + + /* SC-VBR: 0 - PPP_NB, 1 - PPP_WB, 2 - NELP_NB, 3 - NELP_WB */ + if ( coder_type == VOICED && st->bwidth == NB && st->ppp_mode == 1 ) + { + push_indice( st, IND_PPP_NELP_MODE, 0, 2 ); + } + else if ( coder_type == VOICED && st->bwidth != NB && st->ppp_mode == 1 ) + { + push_indice( st, IND_PPP_NELP_MODE, 1, 2 ); + } + else if ( coder_type == UNVOICED && st->bwidth == NB && st->nelp_mode == 1 ) + { + push_indice( st, IND_PPP_NELP_MODE, 2, 2); + } + else if ( coder_type == UNVOICED && st->bwidth != NB && st->nelp_mode == 1 ) + { + push_indice( st, IND_PPP_NELP_MODE, 3, 2 ); + } + } + else if( st->core_brate != SID_2k40 && st->core_brate != FRAME__NO_DATA ) + { + /* write the ACELP/HQ core selection bit */ + if (st->total_brate >= ACELP_24k40 ) + { + push_indice( st, IND_CORE, 0, 1 ); + } + + /* find the section in the ACELP signalling table corresponding to bitrate */ + idx = 0; + while ( acelp_sig_tbl[idx] != st->total_brate ) + { + idx++; + } + + /* retrieve the number of bits for signalling */ + nBits = (short) acelp_sig_tbl[++idx]; + + /* retrieve the signalling index */ + start_idx = ++idx; + while( acelp_sig_tbl[idx] != SIG2IND(coder_type, st->bwidth, sharpFlag, st->rf_mode) ) + { + idx++; + } + + push_indice( st, IND_ACELP_SIGNALLING, idx - start_idx, nBits ); + } + + /* write extension layer flag to distinguish between TBE (0) and BWE (1) */ + if( st->extl_brate > 0 ) + { + if( st->extl == WB_TBE || st->extl == SWB_TBE || st->extl == FB_TBE ) + { + push_indice( st, IND_BWE_FLAG, 0, 1 ); + } + else if( st->extl == WB_BWE || st->extl == SWB_BWE || st->extl == FB_BWE ) + { + push_indice( st, IND_BWE_FLAG, 1, 1 ); + } + } + } + else /* HQ core */ + { + /* write ACELP->HQ core switching flag */ + if( st->last_core == ACELP_CORE || st->last_core == AMR_WB_CORE ) + { + push_indice( st, IND_HQ_SWITCHING_FLG, 1, 1 ); + + /* write ACELP L_frame info */ + if( st->last_L_frame == L_FRAME ) + { + push_indice( st, IND_LAST_L_FRAME, 0, 1 ); + } + else + { + push_indice( st, IND_LAST_L_FRAME, 1, 1 ); + } + } + else + { + push_indice( st, IND_HQ_SWITCHING_FLG, 0, 1 ); + } + + /* HQ/TCX core switching flag */ + push_indice( st, IND_MDCT_CORE, 0, 1 ); + + /* Use ACELP signaling for LR MDCT */ + if ( st->total_brate <= ACELP_16k40 ) + { + /* find the section in the ACELP signalling table corresponding to bitrate */ + idx = 0; + while ( acelp_sig_tbl[idx] != st->total_brate ) + { + idx++; + } + + /* retrieve the number of bits for signalling */ + nBits = (short) acelp_sig_tbl[++idx]; + + /* retrieve the signalling index */ + start_idx = ++idx; + while( acelp_sig_tbl[idx] != SIG2IND(LR_MDCT, st->bwidth, 0, 0) ) + { + idx++; + } + + push_indice( st, IND_ACELP_SIGNALLING, idx - start_idx, nBits ); + } + else + { + if( st->core_brate <= ACELP_64k ) + { + /* write ACELP/HQ core indication flag */ + push_indice( st, IND_CORE, 1, 1 ); + } + + /* write band-width (needed for different I/O sampling rate support) */ + if( st->bwidth == NB ) + { + push_indice( st, IND_HQ_BWIDTH, 0, 2 ); + } + else if( st->bwidth == WB ) + { + push_indice( st, IND_HQ_BWIDTH, 1, 2 ); + } + else if( st->bwidth == SWB ) + { + push_indice( st, IND_HQ_BWIDTH, 2, 2 ); + } + else /* st->bwidth == FB */ + { + push_indice( st, IND_HQ_BWIDTH, 3, 2 ); + } + } + } + + return; +} + +/*---------------------------------------------------------------------* + * signalling_enc_rf() + * + * write channel-aware signalling information into the bit-stream + *---------------------------------------------------------------------*/ + +void signalling_enc_rf( + Encoder_State *st /* i/o: encoder state structure */ +) +{ + short i, tmp_rf, sfr; + + /* write partial copy into bitstream */ + if( st->rf_mode == 1 ) + { + enc_prm_rf( st, st->rf_indx_frametype[st->rf_fec_offset], st->rf_fec_offset ); + st->rf_indx_tbeGainFr[0] = st->RF_bwe_gainFr_ind; + } + + /* Shift the RF indices such that the partial copy associated with + (n-fec_offset)th frame is included in the bitstream in nth frame. */ + tmp_rf = st->rf_fec_offset; + for(i = tmp_rf; i >= 0 ; i--) + { + /* rf frame type */ + st->rf_indx_frametype[i+1] = st->rf_indx_frametype[i]; + + /* rf target bits buffer */ + st->rf_targetbits_buff[i+1] = st->rf_targetbits_buff[i]; + + /* lsf indx */ + st->rf_indx_lsf[i+1][0] = st->rf_indx_lsf[i][0]; + st->rf_indx_lsf[i+1][1] = st->rf_indx_lsf[i][1]; + st->rf_indx_lsf[i+1][2] = st->rf_indx_lsf[i][2]; + + /* ES pred energy */ + st->rf_indx_EsPred[i+1] = st->rf_indx_EsPred[i]; + + /* LTF mode, sfr params: pitch, fcb and gain */ + for(sfr = 0; sfr < st->nb_subfr; sfr++) + { + st->rf_indx_ltfMode[i+1][sfr] = st->rf_indx_ltfMode[i][sfr]; + st->rf_indx_pitch[i+1][sfr] = st->rf_indx_pitch[i][sfr]; + st->rf_indx_fcb[i+1][sfr] = st->rf_indx_fcb[i][sfr]; + st->rf_indx_gain[i+1][sfr] = st->rf_indx_gain[i][sfr]; + } + + /* shift the nelp indices */ + st->rf_indx_nelp_iG1[i+1] = st->rf_indx_nelp_iG1[i]; + st->rf_indx_nelp_iG2[i+1][0] = st->rf_indx_nelp_iG2[i][0]; + st->rf_indx_nelp_iG2[i+1][1] = st->rf_indx_nelp_iG2[i][1]; + st->rf_indx_nelp_fid[i+1] = st->rf_indx_nelp_fid[i]; + + /* tbe gain Fr shift */ + st->rf_indx_tbeGainFr[i+1] = st->rf_indx_tbeGainFr[i]; + st->rf_clas[i+1] = st->rf_clas[i]; + st->rf_gain_tcx[i+1] = st->rf_gain_tcx[i]; + st->rf_tcxltp_param[i+1] = st->rf_tcxltp_param[i]; + } + + return; +} diff --git a/src/libs/libevs/lib_enc/decision_matrix_enc_fx.cpp b/src/libs/libevs/lib_enc/decision_matrix_enc_fx.cpp deleted file mode 100755 index 780c8286..00000000 --- a/src/libs/libevs/lib_enc/decision_matrix_enc_fx.cpp +++ /dev/null @@ -1,751 +0,0 @@ -/*==================================================================================== - EVS Codec 3GPP TS26.442 Apr 03, 2018. Version 12.11.0 / 13.6.0 / 14.2.0 - ====================================================================================*/ - -#include -#include -#include "options.h" -#include "prot_fx.h" -#include "stat_enc_fx.h" -#include "rom_com_fx.h" -#include "stl.h" - - -/*-----------------------------------------------------------------* - * decision_matrix_enc() - * - * Select operating point (combination of technologies) based on input signal properties and command-line parameters: - * - * 7.20 8.00 9.60 13.20 16.40 24.40 32 48 64 96 128 - * Mode 1 1 2 1 2 2 2 2 1 2 2 - * ---------------------------------------------------------------------------------------------------------------------------------------------------------------- - * NB - * speech ACELP@12k8 ACELP@12k8 ACELP@12k8 ACELP@12k8 - * audio LR MDCT LR MDCT TCX LR MDCT - * inactive GSC@12k8 GSC@12k8 TCX GSC@12k8 - * ---------------------------------------------------------------------------------------------------------------------------------------------------------------- - * WB - * speech ACELP@12k8 ACELP@12k8 ACELP@12k8 ACELP@12k8 ACELP@16k ACELP@16k ACELP@16k TCX ACELP@16k TCX TCX - * +0b WB BWE +0b WB BWE +TD WB BWE +TD WB BWE - * audio GSC@12k8 GSC@12k8 TCX LR MDCT TCX TCX HQ TCX HQ TCX TCX - * +0b WB BWE +0b WB BWE +IGF - * inactive GSC@12k8 GSC@12k8 TCX GSC@12k8 TCX TCX AVQ@16k TCX AVQ@16k TCX TCX - * +0b WB BWE +0b WB BWE +IGF +FD WB BWE - * ---------------------------------------------------------------------------------------------------------------------------------------------------------------- - * SWB - * speech ACELP@12k8 ACELP@16k ACELP@16k ACELP@16k TCX ACELP@16k TCX TCX - * +TD SWB BWE +TD SWB BWE +TD SWB BWE +TD SWB BWE +IGF +HR SWB BWE - * audio LR MDCT/GSC TCX TCX HQ TCX HQ TCX TCX - * +FD SWB BWE +IGF +IGF +FD SWB BWE +IGF - * inactive GSC@12k8 TCX TCX AVQ@16k TCX AVQ@16k TCX TCX - * +FD SWB BWE +IGF +IGF +FD SWB BWE +IGF +HR SWB BWE - * ---------------------------------------------------------------------------------------------------------------------------------------------------------------- - * FB - * speech ACELP@16k ACELP@16k ACELP@16k TCX ACELP@16k TCX TCX - * +TD FB BWE +TD FB BWE +TD FB BWE +IGF +HR FB BWE - * audio TCX TCX HQ TCX HQ TCX TCX - * +IGF +IGF +FD FB BWE +IGF - * inactive TCX TCX AVQ@16k TCX AVQ@16k TCX TCX - * +IGF +IGF +FD FB BWE +IGF +HR FB BWE - * --------------------------------------------------------------------------------------------------------------------------------------------------------------- - * - * Note: the GSC technology is part of the ACELP core as AUDIO coder_type (it is used also at 13.2 and 16.4 kbps for SWB unvoiced noisy speech) - * Note2: FB processing is optional and is activated via "-band FB" option on the encoder command line - * Note3: NB (0-4kHz), WB (0-8kHz), SWB (0-16kHz), FB (0-20kHz) - * - * Signalling of modes (x marks a mode that must be signalled in the bitstream) - * - * 7.20 8.00 9.6 13.2 16.4 24.4 32 48 64 - * NB WB SWB FB NB WB SWB FB NB WB SWB FB NB WB SWB FB NB WB SWB FB NB WB SWB FB NB WB SWB FB NB WB SWB FB NB WB SWB FB - * GC, 12k8 x x x x x x x x x x x x x - * UC, 12k8 x x x x x x - * VC, 12k8 x x x x x x x x x x x x x - * TC, 12k8 x x x x x x x x x x x x x - * GC, 16k x x x x x x x x x x x x - * TC, 16k x x x x x x x x x x x x - * AC(GSC) x x x x x x x x x x x x x - * IC x x x x x x x x x x x x x x x x x x x x x x x x x - * - * GC, 12k8, FS x x x x x x x x x x x x x - * GC, 16k, FS x x x x x x x x x x x - * VC, 12k8, FS x x x x x x x - * TC, 12k8, FS x - * TC, 16k, FS x x x x x x x x x x x - * - * LR MDCT x x x x x x x x x x x - * - *-----------------------------------------------------------------*/ - -void decision_matrix_enc_fx( - Encoder_State_fx *st_fx, /* i : encoder state structure */ - const Word16 sp_aud_decision1, /* i : 1st stage speech/music classification */ - const Word16 sp_aud_decision2, /* i : 2nd stage speech/music classification */ - const Word16 coder_type, /* i : coder type */ - const Word16 vad_flag, - Word16 *hq_core_type /* o : HQ core type */ -) -{ - /* initialization */ - st_fx->core_fx = -1; - move16(); - st_fx->extl_fx = -1; - move16(); - st_fx->extl_brate_fx = 0; - move16(); - *hq_core_type = -1; - move16(); - st_fx->igf = 0; - move16(); - /* SID and FRAME_NO_DATA frames */ - test(); - test(); - IF( st_fx->Opt_DTX_ON_fx && (L_sub(st_fx->core_brate_fx,SID_2k40) == 0 || L_sub(st_fx->core_brate_fx,FRAME_NO_DATA) == 0 ) ) - { - st_fx->core_fx = ACELP_CORE; - move16(); - - test(); - if( L_sub(st_fx->input_Fs_fx,32000) >= 0 && sub(st_fx->bwidth_fx,SWB) >= 0 ) - { - st_fx->extl_fx = SWB_CNG; - move16(); - } - - st_fx->rf_mode = 0; - move16(); - - return; - } - - st_fx->core_brate_fx = L_deposit_l(0); - - /* SC-VBR */ - IF ( st_fx->Opt_SC_VBR_fx ) - { - /* SC-VBR */ - st_fx->core_fx = ACELP_CORE; - move16(); - st_fx->core_brate_fx = ACELP_7k20; - move32(); - st_fx->total_brate_fx = ACELP_7k20; - move32(); - - test(); - test(); - test(); - IF ( sub(st_fx->ppp_mode_fx,1) == 0 ) - { - /* PPP mode */ - st_fx->core_brate_fx = PPP_NELP_2k80; - move16(); - } - ELSE IF ( ( ( sub(coder_type,UNVOICED) == 0 || sub(coder_type,TRANSITION) == 0 ) && sp_aud_decision1 == 0 ) || sub(st_fx->bwidth_fx, NB) != 0 ) - { - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - IF ( sub(coder_type,UNVOICED) == 0 && sub(vad_flag,1) == 0 && - ( ( sub(st_fx->last_bwidth_fx,SWB) >= 0 && st_fx->last_Opt_SC_VBR_fx == 1 ) || sub(st_fx->last_bwidth_fx, SWB) < 0 ) && - ( sub(st_fx->last_core_fx,HQ_CORE) != 0 || sub(st_fx->bwidth_fx, NB) != 0) ) - { - /* NELP mode */ - st_fx->nelp_mode_fx = 1; - move16(); - st_fx->core_brate_fx = PPP_NELP_2k80; - move32(); - } - ELSE IF ( sub(coder_type,TRANSITION) == 0 || ( sub(coder_type,UNVOICED) == 0 && sub(st_fx->nelp_mode_fx, 1) != 0 ) || - ( ( sub(coder_type,AUDIO) == 0 || sub(coder_type,INACTIVE) == 0 ) && sub(st_fx->bwidth_fx, NB) != 0 ) ) - - { - /* silence portions */ - st_fx->core_brate_fx = ACELP_8k00; - move32(); - st_fx->total_brate_fx = ACELP_8k00; - move32(); - } - } - - return; - } - - /*---------------------------------------------------------------------* - * NB - *---------------------------------------------------------------------*/ - - ELSE IF ( sub(st_fx->bwidth_fx,NB) == 0 ) - { - st_fx->core_fx = ACELP_CORE; - move16(); - - test(); - if ( L_sub(st_fx->total_brate_fx,HQCORE_NB_MIN_RATE) >= 0 && sub(sp_aud_decision1,1) == 0 ) - { - st_fx->core_fx = HQ_CORE; - move16(); - } - } - - /*---------------------------------------------------------------------* - * WB - *---------------------------------------------------------------------*/ - - ELSE IF ( sub(st_fx->bwidth_fx,WB) == 0 ) - { - st_fx->core_fx = ACELP_CORE; - move16(); - - test(); - test(); - IF ( ( L_sub(st_fx->total_brate_fx,HQCORE_WB_MIN_RATE) >= 0 && sub(sp_aud_decision1,1) == 0 ) || - L_sub(st_fx->total_brate_fx,HQ_96k) >= 0 ) - { - st_fx->core_fx = HQ_CORE; - move16(); - } - ELSE - { - test(); - test(); - test(); - test(); - IF ( sub(st_fx->bwidth_fx,WB) == 0 && L_sub(st_fx->total_brate_fx,ACELP_9k60) < 0 ) - { - st_fx->extl_fx = WB_BWE; - move16(); - } - ELSE IF ( sub(st_fx->bwidth_fx,WB) == 0 && L_sub(st_fx->total_brate_fx,ACELP_9k60) >= 0 && L_sub(st_fx->total_brate_fx,ACELP_16k40) <= 0 ) - { - /* Note: WB BWE is used exceptionally at 13.2 kbps if GSC is selected instead of LR-MDCT */ - test(); - test(); - test(); - IF ( sub(sp_aud_decision1,1) == 0 || sub(coder_type,INACTIVE) == 0 || ( sp_aud_decision1 == 0 && sub(sp_aud_decision2,1) == 0) ) - { - st_fx->extl_fx = WB_BWE; - move16(); - st_fx->extl_brate_fx = WB_BWE_0k35; - move32(); - } - ELSE - { - st_fx->extl_fx = WB_TBE; - move16(); - st_fx->extl_brate_fx = WB_TBE_1k05; - move32(); - } - } - } - } - - /*---------------------------------------------------------------------* - * SWB and FB - *---------------------------------------------------------------------*/ - - ELSE IF ( sub(st_fx->bwidth_fx,SWB) == 0 || sub(st_fx->bwidth_fx,FB) == 0 ) - { - test(); - test(); - IF ( ( L_sub(st_fx->total_brate_fx,HQCORE_SWB_MIN_RATE) >= 0 && sub(sp_aud_decision1,1) == 0) || - L_sub(st_fx->total_brate_fx,HQ_96k) >= 0 ) - { - st_fx->core_fx = HQ_CORE; - move16(); - } - ELSE - { - st_fx->core_fx = ACELP_CORE; - move16(); - - test(); - test(); - IF ( L_sub(st_fx->total_brate_fx,ACELP_13k20) >= 0 && L_sub(st_fx->total_brate_fx,ACELP_48k) < 0 ) - { - /* Note: SWB BWE is not used in case of GSC noisy speech */ - /* Note: SWB BWE is used exceptionally at 13.2 kbps if GSC is selected instead of LR-MDCT */ - test(); - test(); - test(); - test(); - IF ( (sub(sp_aud_decision1,1) == 0 || sub(coder_type,INACTIVE) == 0 || ( sp_aud_decision1 == 0 && sub(sp_aud_decision2,1) == 0 )) && st_fx->GSC_noisy_speech_fx == 0 ) - { - st_fx->extl_fx = SWB_BWE; - move16(); - st_fx->extl_brate_fx = SWB_BWE_1k6; - move32(); - - test(); - IF ( sub(st_fx->bwidth_fx,FB) == 0 && L_sub(st_fx->total_brate_fx,ACELP_24k40) >= 0 ) - { - st_fx->extl_fx = FB_BWE; - move16(); - st_fx->extl_brate_fx = FB_BWE_1k8; - move32(); - } - } - ELSE - { - st_fx->extl_fx = SWB_TBE; - move16(); - st_fx->extl_brate_fx = SWB_TBE_1k6; - move32(); - if( L_sub(st_fx->total_brate_fx,ACELP_24k40) >= 0 ) - { - st_fx->extl_brate_fx = SWB_TBE_2k8; - move32(); - } - - test(); - IF ( sub(st_fx->bwidth_fx,FB) == 0 && L_sub(st_fx->total_brate_fx,ACELP_24k40) >= 0 ) - { - st_fx->extl_fx = FB_TBE; - move16(); - { - st_fx->extl_brate_fx = FB_TBE_3k0; - move32(); - } - } - } - } - ELSE IF ( L_sub(st_fx->total_brate_fx,ACELP_48k) >= 0 ) - { - st_fx->extl_fx = SWB_BWE_HIGHRATE; - move16(); - st_fx->extl_brate_fx = SWB_BWE_16k; - move32(); - - if( sub(st_fx->bwidth_fx,FB) == 0 ) - { - st_fx->extl_fx = FB_BWE_HIGHRATE; - move32(); - } - } - } - } - - /*-----------------------------------------------------------------* - * Set HQ core type - *-----------------------------------------------------------------*/ - - IF( sub(st_fx->core_fx,HQ_CORE) == 0 ) - { - *hq_core_type = NORMAL_HQ_CORE; - move16(); - - test(); - test(); - IF( (sub(st_fx->bwidth_fx,SWB) == 0 || sub(st_fx->bwidth_fx,WB) == 0) && L_sub(st_fx->total_brate_fx,LRMDCT_CROSSOVER_POINT) <= 0 ) - { - /* note that FB is always coded with NORMAL_HQ_CORE */ - *hq_core_type = LOW_RATE_HQ_CORE; - move16(); - } - ELSE IF( sub(st_fx->bwidth_fx,NB) == 0 ) - { - *hq_core_type = LOW_RATE_HQ_CORE; - move16(); - } - } - - /* set core bitrate */ - st_fx->core_brate_fx = L_sub(st_fx->total_brate_fx, st_fx->extl_brate_fx); - - IF ( st_fx->ini_frame_fx == 0 ) - { - /* avoid switching in the very first frame */ - st_fx->last_core_fx = st_fx->core_fx; - move16(); - st_fx->last_core_brate_fx = st_fx->core_brate_fx; - move32(); - st_fx->last_extl_fx = st_fx->extl_fx; - move16(); - } - - return; -} - -/*---------------------------------------------------------------------* - * signalling_mode1_tcx20_enc() - * - * write MODE1 TCX20 signalling information into the bit-stream - *---------------------------------------------------------------------*/ - -Word16 signalling_mode1_tcx20_enc( - Encoder_State_fx *st, /* i : encoder state structure */ - Word16 push -) -{ - Word16 num_bits; - Word16 nBits, idx, start_idx; - - assert(st->core_fx == TCX_20_CORE); - - num_bits = 0; - move16(); - - /* Use ACELP signaling for LR MDCT */ - IF ( L_sub(st->total_brate_fx, ACELP_16k40) <= 0 ) - { - /* find the section in the ACELP signalling table corresponding to bitrate */ - idx = 0; - move16(); - WHILE ( L_sub(acelp_sig_tbl[idx], st->total_brate_fx) != 0 ) - { - idx = add(idx, 1); - } - - /* retrieve the number of bits for signalling */ - idx = add(idx, 1); - nBits = extract_l(acelp_sig_tbl[idx]); - - /* retrieve the signalling index */ - idx = add(idx, 1); - start_idx = idx; - move16(); - WHILE ( L_sub(acelp_sig_tbl[idx], SIG2IND_fx(LR_MDCT, st->bwidth_fx, 0, 0)) != 0 ) - { - idx = add(idx, 1); - } - - num_bits = add(num_bits, nBits); - IF (push != 0) - { - push_indice_fx( st, IND_ACELP_SIGNALLING, sub(idx, start_idx), nBits ); - } - - /* HQ/TCX core switching flag */ - num_bits = add(num_bits, 1); - IF (push != 0) - { - push_indice_fx( st, IND_MDCT_CORE, 1, 1 ); - } - } - ELSE - { - IF ( L_sub(st->core_brate_fx, ACELP_64k) <= 0 ) - { - /* write ACELP/HQ core indication flag */ - num_bits = add(num_bits, 1); - IF (push != 0) - { - push_indice_fx( st, IND_CORE, 1, 1 ); - } - } - - /* HQ/TCX core switching flag */ - num_bits = add(num_bits, 1); - IF (push != 0) - { - push_indice_fx( st, IND_MDCT_CORE, 1, 1 ); - } - - num_bits = add(num_bits, 2); - IF (push != 0) - { - /* write band-width (needed for different I/O sampling rate support) */ - IF ( sub(st->bwidth_fx, NB) == 0 ) - { - push_indice_fx( st, IND_HQ_BWIDTH, 0, 2 ); - } - ELSE IF ( sub(st->bwidth_fx, WB) == 0 ) - { - push_indice_fx( st, IND_HQ_BWIDTH, 1, 2 ); - } - ELSE IF ( sub(st->bwidth_fx, SWB) == 0 ) - { - push_indice_fx( st, IND_HQ_BWIDTH, 2, 2 ); - } - ELSE /* st->bwidth == FB */ - { - push_indice_fx( st, IND_HQ_BWIDTH, 3, 2 ); - } - } - } - - return num_bits; -} - -/*---------------------------------------------------------------------* - * signalling_enc() - * - * write signalling information into the bit-stream - *---------------------------------------------------------------------*/ - -void signalling_enc_fx( - Encoder_State_fx *st_fx, /* i : encoder state structure */ - const Word16 coder_type, /* i : coder type */ - const Word16 sharpFlag /* i : formant sharpening flag */ -) -{ - Word16 nBits, idx, start_idx; - Word32 k; - - IF (sub(st_fx->mdct_sw, MODE2) == 0) - { - - assert(!st_fx->tcxonly); - assert(st_fx->core_fx == HQ_CORE); - - push_next_indice_fx(st_fx, 1, 1); /* TCX */ - push_next_indice_fx(st_fx, 1, 1); /* HQ_CORE */ - - /* write ACELP->HQ core switching flag */ - test(); - IF ( sub(st_fx->last_core_fx, ACELP_CORE) == 0 || sub(st_fx->last_core_fx, AMR_WB_CORE) == 0 ) - { - push_indice_fx( st_fx, IND_HQ_SWITCHING_FLG, 1, 1 ); - - /* write ACELP L_frame info */ - IF( sub(st_fx->last_L_frame_fx, L_FRAME) == 0 ) - { - push_indice_fx( st_fx, IND_LAST_L_FRAME, 0, 1 ); - } - ELSE - { - push_indice_fx( st_fx, IND_LAST_L_FRAME, 1, 1 ); - } - } - ELSE - { - push_indice_fx( st_fx, IND_HQ_SWITCHING_FLG, 0, 1 ); - } - - return; - } - IF( sub(st_fx->core_fx,ACELP_CORE ) == 0) - { - - test(); - test(); - IF( sub(st_fx->ppp_mode_fx,1) == 0 || sub(st_fx->nelp_mode_fx,1) == 0 ) - { - - /* 1 bit to distinguish between 2.8kbps PPP/NELP frame and SID frame */ - push_indice_fx( st_fx, IND_CORE, 0, 1 ); - /* SC-VBR: 0 - PPP_NB, 1 - PPP_WB, 2 - NELP_NB, 3 - NELP_WB */ - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - IF ( sub(coder_type,VOICED) == 0 && sub(st_fx->bwidth_fx,NB) == 0 && sub(st_fx->ppp_mode_fx,1) == 0 ) - { - push_indice_fx( st_fx, IND_PPP_NELP_MODE, 0, 2 ); - } - ELSE IF ( sub(coder_type,VOICED) == 0 && sub(st_fx->bwidth_fx,NB) != 0 && sub(st_fx->ppp_mode_fx,1) == 0 ) - { - push_indice_fx( st_fx, IND_PPP_NELP_MODE, 1, 2 ); - } - ELSE IF ( sub(coder_type,UNVOICED) == 0 && sub(st_fx->bwidth_fx,NB) == 0 && sub(st_fx->nelp_mode_fx,1) == 0 ) - { - push_indice_fx( st_fx, IND_PPP_NELP_MODE, 2, 2); - } - ELSE IF ( sub(coder_type,UNVOICED) == 0 && sub(st_fx->bwidth_fx,NB) != 0 && sub(st_fx->nelp_mode_fx,1) == 0 ) - { - push_indice_fx( st_fx, IND_PPP_NELP_MODE, 3, 2 ); - } - } - ELSE IF( L_sub(st_fx->core_brate_fx,SID_2k40) != 0 && L_sub(st_fx->core_brate_fx,FRAME_NO_DATA) != 0 ) - { - /* write the ACELP/HQ core selection bit */ - IF (L_sub(st_fx->total_brate_fx,ACELP_24k40) >= 0 ) - { - push_indice_fx( st_fx, IND_CORE, 0, 1 ); - } - - /* find the section in the ACELP signalling table corresponding to bitrate */ - idx = 0; - WHILE ( L_sub(acelp_sig_tbl[idx],st_fx->total_brate_fx) != 0 ) - { - idx++; - } - - /* retrieve the number of bits for signalling */ - nBits = (short) acelp_sig_tbl[++idx]; - - /* retrieve the signalling index */ - start_idx = ++idx; - k = SIG2IND_fx(coder_type, st_fx->bwidth_fx, sharpFlag, st_fx->rf_mode); - WHILE( L_sub(acelp_sig_tbl[idx], k) != 0 ) - { - idx++; - } - - push_indice_fx( st_fx, IND_ACELP_SIGNALLING, idx - start_idx, nBits ); - } - - /* write extension layer flag to distinguish between TBE (0) and BWE (1) */ - IF( st_fx->extl_brate_fx > 0 ) - { - test(); - test(); - test(); - test(); - IF( sub(st_fx->extl_fx,WB_TBE) == 0 || sub(st_fx->extl_fx,SWB_TBE) == 0 || sub(st_fx->extl_fx,FB_TBE) == 0 ) - { - push_indice_fx( st_fx, IND_BWE_FLAG, 0, 1 ); - } - ELSE IF( sub(st_fx->extl_fx,WB_BWE) == 0 || sub(st_fx->extl_fx,SWB_BWE) == 0 || sub(st_fx->extl_fx,FB_BWE) == 0 ) - { - push_indice_fx( st_fx, IND_BWE_FLAG, 1, 1 ); - } - } - } - ELSE /* HQ core */ - { - /* write ACELP->HQ switching frame flag */ - test(); - IF( sub(st_fx->last_core_fx,ACELP_CORE) == 0 || sub(st_fx->last_core_fx,AMR_WB_CORE) == 0 ) - { - push_indice_fx( st_fx, IND_HQ_SWITCHING_FLG, 1, 1 ); - /* write ACELP L_frame info */ - IF( sub(st_fx->last_L_frame_fx, L_FRAME)==0 ) - { - push_indice_fx( st_fx, IND_LAST_L_FRAME, 0, 1 ); - } - ELSE - { - push_indice_fx( st_fx, IND_LAST_L_FRAME, 1, 1 ); - } - } - ELSE - { - push_indice_fx( st_fx, IND_HQ_SWITCHING_FLG, 0, 1 ); - } - - /* HQ/TCX core switching flag */ - push_indice_fx( st_fx, IND_MDCT_CORE, 0, 1 ); - - /* Use ACELP signaling for LR MDCT */ - IF ( L_sub(st_fx->total_brate_fx,ACELP_16k40) <= 0 ) - { - /* find the section in the ACELP signalling table corresponding to bitrate */ - idx = 0; - WHILE ( L_sub(acelp_sig_tbl[idx],st_fx->total_brate_fx) != 0 ) - { - idx++; - } - - /* retrieve the number of bits for signalling */ - nBits = extract_l(acelp_sig_tbl[++idx]); - - /* retrieve the signalling index */ - start_idx = ++idx; - move16(); - k = SIG2IND_fx(LR_MDCT, st_fx->bwidth_fx, 0, 0); - WHILE( L_sub(acelp_sig_tbl[idx], k) != 0 ) - { - idx++; - } - - push_indice_fx( st_fx, IND_ACELP_SIGNALLING, idx - start_idx, nBits ); - } - ELSE - { - - IF( L_sub(st_fx->core_brate_fx,ACELP_64k) <= 0 ) - { - /* write ACELP/HQ core indication flag */ - push_indice_fx( st_fx, IND_CORE, 1, 1 ); - } - - /* write band-width (needed for different I/O sampling rate support) */ - IF( sub(st_fx->bwidth_fx,NB) == 0 ) - { - push_indice_fx( st_fx, IND_HQ_BWIDTH, 0, 2 ); - } - ELSE IF( sub(st_fx->bwidth_fx,WB) == 0 ) - { - push_indice_fx( st_fx, IND_HQ_BWIDTH, 1, 2 ); - } - ELSE IF( sub(st_fx->bwidth_fx,SWB) == 0 ) - { - push_indice_fx( st_fx, IND_HQ_BWIDTH, 2, 2 ); - } - ELSE /* st_fx->bwidth_fx == FB */ - { - push_indice_fx( st_fx, IND_HQ_BWIDTH, 3, 2 ); - } - } - } - - return; -} - -/*---------------------------------------------------------------------* - * signalling_enc_rf() - * - * write channel-aware signalling information into the bit-stream - *---------------------------------------------------------------------*/ - -void signalling_enc_rf( - Encoder_State_fx *st /* i : encoder state structure */ -) -{ - Word16 i, tmp_rf; - Word16 sfr; - - - /* write partial copy into bitstream */ - IF(sub(st->rf_mode,1) == 0) - { - enc_prm_rf(st, st->rf_indx_frametype[st->rf_fec_offset], st->rf_fec_offset); - st->rf_indx_tbeGainFr[0] = st->rf_bwe_gainFr_ind; - } - - /* Shift the RF indices such that the partial copy associated with - (n-fec_offset)th frame is included in the bitstream in nth frame. */ - tmp_rf = st->rf_fec_offset; - - FOR(i = tmp_rf; i >= 0 ; i--) - { - /* rf frame type */ - st->rf_indx_frametype[i+1] = st->rf_indx_frametype[i]; - /* rf target bits buffer */ - st->rf_targetbits_buff[i+1] = st->rf_targetbits_buff[i]; - - /* lsf indx */ - st->rf_indx_lsf[i+1][0] = st->rf_indx_lsf[i][0]; - st->rf_indx_lsf[i+1][1] = st->rf_indx_lsf[i][1]; - st->rf_indx_lsf[i+1][2] = st->rf_indx_lsf[i][2]; - - /* ES pred energy */ - st->rf_indx_EsPred[i+1] = st->rf_indx_EsPred[i]; - - /* LTF mode, sfr params: pitch, fcb and gain */ - FOR(sfr = 0; sfr < st->nb_subfr; sfr++) - { - st->rf_indx_ltfMode[i+1][sfr] = st->rf_indx_ltfMode[i][sfr]; - st->rf_indx_pitch[i+1][sfr] = st->rf_indx_pitch[i][sfr]; - st->rf_indx_fcb[i+1][sfr] = st->rf_indx_fcb[i][sfr]; - st->rf_indx_gain[i+1][sfr] = st->rf_indx_gain[i][sfr]; - } - - /* shift the nelp indices */ - st->rf_indx_nelp_iG1[i+1] = st->rf_indx_nelp_iG1[i]; - st->rf_indx_nelp_iG2[i+1][0] = st->rf_indx_nelp_iG2[i][0]; - st->rf_indx_nelp_iG2[i+1][1] = st->rf_indx_nelp_iG2[i][1]; - st->rf_indx_nelp_fid[i+1] = st->rf_indx_nelp_fid[i]; - - /* tbe gain Fr shift */ - st->rf_indx_tbeGainFr[i+1] = st->rf_indx_tbeGainFr[i]; - st->rf_clas[i+1] = st->rf_clas[i]; - st->rf_gain_tcx[i+1] = st->rf_gain_tcx[i]; - st->rf_tcxltp_param[i+1] = st->rf_tcxltp_param[i]; - } - - return; -} - - diff --git a/src/libs/libevs/lib_enc/detect_transient.cpp b/src/libs/libevs/lib_enc/detect_transient.cpp new file mode 100644 index 00000000..e15d89a6 --- /dev/null +++ b/src/libs/libevs/lib_enc/detect_transient.cpp @@ -0,0 +1,228 @@ +/*==================================================================================== + EVS Codec 3GPP TS26.443 Nov 13, 2018. Version 12.11.0 / 13.7.0 / 14.3.0 / 15.1.0 + ====================================================================================*/ + +#include "options.h" +#include "prot.h" +#include "cnst.h" +#include "rom_com.h" + + +/*-------------------------------------------------------------------------- + * hp_filter() + * + * High pass filter + *--------------------------------------------------------------------------*/ + +static void hp_filter( + const float *x, /* i : input signal */ + float *y, /* o : output signal */ + float *oldx, /* i/o: previous filter input */ + float *oldy, /* i/o: previous filter output */ + const short L /* i : length (32 or 48Hz) */ +) +{ + short i; + + y[0] = 0.4931f * *oldy + 0.7466f*(x[0] - *oldx); + + for(i = 1; i < L; i++) + { + y[i] = 0.4931f*y[i-1] + 0.7466f*(x[i] - x[i-1]); + } + + *oldx = x[L - 1]; + *oldy = y[L - 1]; + + return; +} + +/*-------------------------------------------------------------------------- + * detect_transient() + * + * Detect if the signal is a transient + *--------------------------------------------------------------------------*/ + +short detect_transient( /* o : transient flag */ + const float *in, /* i : input signal */ + Encoder_State *st, /* i/o: Encoder state structure */ + const short L, /* i : length (32 or 48kHz) */ + const short coder_type /* i : coder type */ +) +{ + float Energy; + float EnergyLT; + short i, blk; + short IsTransient; + float out_filt[L_FRAME48k]; + short position = 0; + float thr; + float Thres = 0.f; + float Energy_in[5]; + float E_low, E_high; + float E_in = 0.0f, E_out = 0.0f; + + IsTransient = 0; + + if( st->last_extl != st->extl ) + { + st->TransientHangOver = 0; + st->old_hpfilt_in = 0; + st->old_hpfilt_out = 0; + st->Energy_Old = 0; + } + + /* High-pass filter */ + hp_filter( in, out_filt, &(st->old_hpfilt_in), &(st->old_hpfilt_out), L ); + + /* Long-term energy */ + if( st->last_extl != st->extl || (st->last_extl == st->extl && st->last_core != st->core) || st->last_codec_mode == MODE2 ) + { + EnergyLT = EPSILON; + for ( i = 0; i < L/4; i++ ) + { + EnergyLT += out_filt[i] * out_filt[i]; + } + } + else + { + EnergyLT = st->EnergyLT; + } + + if(L == L_FRAME8k) + { + Energy_in[0] = st->Energy_Old; + E_in = 0; + E_out = 0; + + /* Compute block energy */ + for ( blk = 0; blk < 4; blk++ ) + { + Energy = EPSILON; + Energy_in[blk+1] = EPSILON; + + for ( i = 0; i < L/4; i++ ) + { + Energy += out_filt[i + blk*(L/4)] * out_filt[i + blk*(L/4)]; + Energy_in[blk+1] += in[i + blk*(L/4)] * in[i + blk*(L/4)]; + } + + E_in += Energy_in[blk+1]; + E_out += Energy; + + Thres = 15.f; + + if(Energy > 6.0f * EnergyLT) + { + IsTransient = 1; + position = blk; + } + + EnergyLT = 0.75f*EnergyLT + 0.25f*Energy; + } + } + else + { + /* Compute block energy */ + for ( blk = 0; blk < 4; blk++ ) + { + Energy = EPSILON; + for ( i = 0; i < L/4; i++ ) + { + Energy += out_filt[i + blk*(L/4)] * out_filt[i + blk*(L/4)]; + } + + if( st->extl == SWB_BWE || st->extl == FB_BWE ) + { + if( ( Energy > 13.5f * EnergyLT ) || ( Energy > 10.0f * EnergyLT && coder_type == INACTIVE ) ) + { + IsTransient = 1; + position = blk; + } + } + else + { + if( st->total_brate <= HQ_16k40 && st->bwidth == SWB ) + { + thr = 13.5f; + } + else + { + thr = 6.0f; + } + + if( Energy > thr * EnergyLT ) + { + IsTransient = 1; + position = blk; + } + } + + EnergyLT = 0.75f*EnergyLT + 0.25f*Energy; + } + } + + st->EnergyLT = EnergyLT; + + if( ( st->last_extl != SWB_BWE && st->last_extl != SWB_TBE && st->extl == SWB_BWE ) || + ( st->last_extl != FB_BWE && st->last_extl != FB_TBE && st->extl == FB_BWE ) ) + { + IsTransient = 0; + } + + if( IsTransient && L == L_FRAME8k ) + { + E_low = 0.f; + blk = 0; + for(i=0; i0.7f)) && ((E_in/E_out)>Thres) ) + { + IsTransient = 0; + } + } + + if ( IsTransient ) + { + if(L == L_FRAME8k) + { + if( position == 3 ) + { + st->TransientHangOver = 1; + } + } + else + { + st->TransientHangOver = 1; + } + } + else + { + if( st->TransientHangOver ) + { + st->TransientHangOver = 0; + IsTransient = 1; + } + } + + if( L == L_FRAME8k ) + { + st->Energy_Old = Energy_in[4]; + } + + return IsTransient; +} diff --git a/src/libs/libevs/lib_enc/detect_transient_fx.cpp b/src/libs/libevs/lib_enc/detect_transient_fx.cpp deleted file mode 100755 index 794162d1..00000000 --- a/src/libs/libevs/lib_enc/detect_transient_fx.cpp +++ /dev/null @@ -1,352 +0,0 @@ -/*==================================================================================== - EVS Codec 3GPP TS26.442 Apr 03, 2018. Version 12.11.0 / 13.6.0 / 14.2.0 - ====================================================================================*/ - -#include "options.h" /* Compilation switches */ -#include "cnst_fx.h" /* Common constants */ -#include "rom_com_fx.h" /* Static table prototypes */ -#include "prot_fx.h" /* Function prototypes */ -#include "stl.h" /* required for wmc_tool */ - -/*--------------------------------------------------------------------------*/ -/* Function hp_filter */ -/* ~~~~~~~~~~~~~~~~~~~~ */ -/* */ -/* High pass filter */ -/*--------------------------------------------------------------------------*/ -/* float x (i) in Q_new input to filter */ -/* float y (o) in Q_new +2 output of filter */ -/* float *oldy (i/o) previous output of filter */ -/* float *oldx (i/o) in Q_memx previous input of filter */ -/* short L (i) in Q_memx +2 length (32 or 48 kHz) */ -/*--------------------------------------------------------------------------*/ - -static void hp_filter_fx( - const Word16 *x, /*Q_new */ - Word16 *y, /*Q_new */ - Word16 *oldy, /*Q_new */ - Word16 *oldx, /*Q_new */ - const Word16 L -) -{ - Word16 i; - Word32 L_tmp; - - - /*y[0] = 0.4931f * *oldy + 0.7466f*(x[0] - *oldx); */ - L_tmp = L_mult(sub(x[0],*oldx),24465);/*Q_new+16 */ - L_tmp = L_mac(L_tmp,*oldy,16158);/*Q_new+16 */ - y[0] = round_fx(L_tmp);/*Q_new */ - - FOR (i = 1; i < L; i++) - { - /*y[i] = 0.4931f*y[i-1] + 0.7466f*(x[i] - x[i-1]); */ - L_tmp = L_mult(sub(x[i],x[i-1]),24465);/*Q_new+16 */ - L_tmp = L_mac(L_tmp,y[i-1],16158);/*Q_new+16 */ - y[i] = round_fx(L_tmp); /*Q_new */ - } - - *oldx = x[L - 1]; - move16();/*Q_new */ - *oldy = y[L - 1]; - move16();/*Q_new */ - -} -/*--------------------------------------------------------------------------*/ -/* Function detect_transient */ -/* ~~~~~~~~~~~~~~~~~~~~~~~~~~ */ -/* */ -/* Detect if the signal is a transient */ -/*--------------------------------------------------------------------------*/ -/* float in[] (i) input signal Q_new */ -/* Encoder_State *st (i/o) state of coder */ -/* short L (i) length (32 or 48 kHz) */ -/*--------------------------------------------------------------------------*/ -/* short return (o) result of transient check */ -/*--------------------------------------------------------------------------*/ - -Word16 detect_transient_fx( - const Word16 *in_fx, /*Q_new */ - /*Encoder_State *st, */ - const Word16 L, - const Word16 coder_type , /* i : coder type */ - Word16 Q_new, - Encoder_State_fx *st_fx -) -{ - Word32 Energy,L_tmp; - Word32 EnergyLT; - Word16 i, blk; - Word16 IsTransient; - Word16 out_filt_fx[L_FRAME48k]; - Word16 position = 0; - Word16 thr; - Word32 L_tmp2; - Word16 shift; - Word32 Energy_fx, E_in_fx = 0, E_out_fx = 0, Energy_in_fx[5] = {0,0,0,0,0}; /* Energy_fx can be replaced by Energy */ - Word32 E_low_fx, E_high_fx; - Word16 temp16, Thres_fx = 0; - Word16 exp; - - shift = 0; - move16(); - - IsTransient = 0; - move16(); - IF (sub(st_fx->last_extl_fx, st_fx->extl_fx) != 0) - { - st_fx->TransientHangOver_fx = 0; - move16(); - st_fx->old_hpfilt_in_fx = 0; - move16(); - st_fx->old_hpfilt_out_fx = 0; - move16(); - } - - /* High pass filter */ - hp_filter_fx(in_fx, out_filt_fx, &(st_fx->old_hpfilt_in_fx), &(st_fx->old_hpfilt_out_fx), L); - - /* Long term energy */ - test(); - test(); - test(); - IF (sub(st_fx->last_extl_fx, st_fx->extl_fx) != 0 || (sub(st_fx->last_extl_fx, st_fx->extl_fx) == 0 && sub(st_fx->last_core_fx, st_fx->core_fx) != 0) || sub(st_fx->last_codec_mode, MODE2) == 0) - { - /*EnergyLT = EPSILON_FX; */ - EnergyLT = L_deposit_l(0); - FOR (i = 0; i < L/4; i++) - { - /*EnergyLT += out_filt[i] * out_filt[i]; */ - EnergyLT = L_mac0(EnergyLT, out_filt_fx[i], out_filt_fx[i]); /*2Q_new */ - } - } - ELSE - { - EnergyLT = L_add(st_fx->EnergyLT_fx, 0); /*2Q_new */ - } - IF (sub(L, L_FRAME8k) == 0) - { - Energy_in_fx[0] = st_fx->Energy_Old_fx; - move32(); - /* Compute block energy */ - FOR ( blk = 0; blk < 4; blk++ ) - { - Energy_fx = L_deposit_l(0); - Energy_in_fx[blk + 1] = L_deposit_l(0); - FOR ( i = 0; i < L/4; i++ ) - { - temp16 = extract_l(L_shr(out_filt_fx[i + blk*(L/4)], 12)); - Energy_fx = L_add(Energy_fx, L_mult0(temp16, temp16)); - temp16 = shr(in_fx[i + blk*(L/4)], Q_new); - Energy_in_fx[blk+1] = L_add(Energy_in_fx[blk+1], L_mult0(temp16, temp16)); - move32(); - } - - E_in_fx = L_add(E_in_fx, Energy_in_fx[blk + 1]); - E_out_fx = L_add(E_out_fx, Energy_fx); - - Thres_fx = 2185;/*1 /15 */ - move16(); - IF (L_sub(Mult_32_16(Energy_fx, 5461), EnergyLT) > 0) - { - IsTransient = 1; - move16(); - position = blk; - move16(); - } - - EnergyLT = L_add(Mult_32_16(EnergyLT, 24576), Mult_32_16(Energy_fx, 8192)); - } - } - ELSE - { - /* Compute block energy */ - FOR ( blk = 0; blk < 4; blk++ ) - { - L_tmp = L_deposit_l(0); - FOR ( i = 0; i < L/8; i++ ) - { - /*Energy += out_filt_fx[i + blk*(L/4)] * out_filt_fx[i + blk*(L/4)]; */ - L_tmp = L_mac0(L_tmp, out_filt_fx[i + blk*(L/4)], out_filt_fx[i + blk*(L/4)]); /*2Q_new */ - } - L_tmp2 = L_deposit_l(0); - FOR (; i < L/4; i++ ) - { - /*Energy += out_filt_fx[i + blk*(L/4)] * out_filt_fx[i + blk*(L/4)]; */ - L_tmp2 = L_mac0(L_tmp2, out_filt_fx[i + blk*(L/4)], out_filt_fx[i + blk*(L/4)]); /*2Q_new */ - } - Overflow = 0; - move16(); - Energy = L_add(L_tmp, L_tmp2); - shift = 0; - if (Overflow != 0) - { - shift = 1; - move16(); - } - Overflow = 0; - move16(); - - Energy = L_add(L_shr(L_tmp, shift), L_shr(L_tmp2, shift)); - - test(); - IF( sub(st_fx->extl_fx,SWB_BWE) == 0 || sub(st_fx->extl_fx,FB_BWE) == 0 ) - { - /*Calculate shift to get to Q0*/ - test(); - test(); - IF((L_sub(Mult_32_16(Energy, shl(2427, shift)), EnergyLT) > 0) || (L_sub(Mult_32_16(Energy, shl(3277, shift)), EnergyLT) > 0 && sub(coder_type,INACTIVE) == 0)) - { - IsTransient = 1; - move16(); - position = blk; - move16(); - } - } - ELSE - { - test(); - IF( L_sub(st_fx->total_brate_fx,HQ_16k40) <= 0&& sub(st_fx->bwidth_fx,SWB) == 0 ) - { - thr = 2427; - move16(); - } - ELSE - { - thr = 5461; - move16(); - } - thr = shl(thr, shift); - /*if(Energy > L_shr(Mult_32_16(EnergyLT,22624),shift_cnt)) //getting in Q0 32*16 = Q_inp1+Q_inp2+1-16 */ - IF(L_sub(Mult_32_16(Energy, thr),EnergyLT) > 0) - /*if(Energy > 6.0f * EnergyLT) */ - { - IsTransient = 1; - move16(); - position = blk; - move16(); - } - } - /*EnergyLT = 0.75f*EnergyLT + 0.25f*Energy; */ - /*0.75f*EnergyLT in Q0 //0.25f*Energy in Q0 */ - EnergyLT = L_add(Mult_32_16(EnergyLT,24576),Mult_32_16(Energy, shl(8192, shift))); /*2Q_new */ - } - } - st_fx->EnergyLT_fx = EnergyLT; - move32(); - - test(); - test(); - test(); - test(); - test(); - if( ( sub(st_fx->last_extl_fx,SWB_BWE) != 0 && sub(st_fx->last_extl_fx,SWB_TBE) != 0 && sub(st_fx->extl_fx,SWB_BWE) == 0 ) || - ( sub(st_fx->last_extl_fx,FB_BWE) != 0 && sub(st_fx->last_extl_fx,FB_TBE) != 0 && sub(st_fx->extl_fx,FB_BWE) == 0 ) ) - { - IsTransient = 0; - move16(); - } - - test(); - IF ( IsTransient && L == L_FRAME8k ) - { - blk = 0; - move16(); - E_low_fx = L_deposit_l(0); - FOR (i=0; i 0 && L_sub(Mult_32_16(E_in_fx, Thres_fx), E_out_fx) > 0) - { - IsTransient = 0; - move16(); - } - } - IF ( L_sub(st_fx->core_brate_fx,ACELP_24k40) == 0 ) - { - test(); - IF ( sub(st_fx->last_core_fx,HQ_CORE) != 0 || L_sub(st_fx->last_core_brate_fx,ACELP_24k40) != 0 ) - { - st_fx->TransientHangOver_fx = 0; - move16(); - IsTransient = 0; - move16(); - } - ELSE - { - IF ( IsTransient ) - { - IF ( sub(position,3) == 0 ) - { - /* Set Hangover */ - st_fx->TransientHangOver_fx = 1; - move16(); - } - } - ELSE - { - IF ( st_fx->TransientHangOver_fx ) - { - st_fx->TransientHangOver_fx = 0; - move16(); - IsTransient = 1; - move16(); - } - } - } - } - ELSE - { - IF ( IsTransient ) - { - st_fx->TransientHangOver_fx = 1; - move16(); - } - ELSE - { - IF( st_fx->TransientHangOver_fx ) - { - st_fx->TransientHangOver_fx = 0; - move16(); - IsTransient = 1; - move16(); - } - } - } - - IF (sub(L, L_FRAME8k) == 0) - { - st_fx->Energy_Old_fx = Energy_in_fx[4]; - move32(); - } - - return IsTransient; -} diff --git a/src/libs/libevs/lib_enc/diffcod.cpp b/src/libs/libevs/lib_enc/diffcod.cpp new file mode 100644 index 00000000..c3caf4d0 --- /dev/null +++ b/src/libs/libevs/lib_enc/diffcod.cpp @@ -0,0 +1,125 @@ +/*==================================================================================== + EVS Codec 3GPP TS26.443 Nov 13, 2018. Version 12.11.0 / 13.7.0 / 14.3.0 / 15.1.0 + ====================================================================================*/ + +#include "options.h" +#include "prot.h" +#include "rom_com.h" + + +/*--------------------------------------------------------------------------*/ +/* Function diffcod */ +/* ~~~~~~~~~~~~~~~~~ */ +/* */ +/* Differential coding for indices of quantized norms */ +/*--------------------------------------------------------------------------*/ +/* short *normqlg2 (o) quantized norms in log2 */ +/* short N (i) number of sub-vectors */ +/* short *y (i/o) indices of quantized norms */ +/* short *difidx (o) differential code */ +/*--------------------------------------------------------------------------*/ + +void diffcod( + const short N, + short *y, + short *difidx +) +{ + short i, k, r; + + for (i=N-1; i>0; i--) + { + r = i - 1; + k = y[i] - y[r]; + if (k<(-15)) + { + y[r] = y[i] + 15; + } + } + + for (i=1; i16) + { + k = 16; + y[i] = y[r] + 16; + } + difidx[r] = k + 15; + } + + return; +} + + + + +/*-------------------------------------------------------------------------- + * diffcod_lrmdct() + * + * Differential coding for indices of quantized norms + *--------------------------------------------------------------------------*/ + +void diffcod_lrmdct( + const short N, /* i : number of sub-vectors */ + const int be_ref, /* o : band energy reference */ + int *y, /* i/o: indices of quantized norms */ + int *difidx, /* o : differential code */ + const short is_transient /* i : transient flag */ +) +{ + short i, m, r; + int k; + int thr_l,thr_h; + + if(is_transient) + { + thr_l=-15; + thr_h=16; + } + else + { + thr_l=-32; + thr_h=31; + } + + difidx[0] = y[0] - be_ref; + if(difidx[0]>thr_h) + { + difidx[0] = thr_h; + y[0] = be_ref + thr_h; + } + + if(difidx[0]0; i--) + { + r = i - 1; + k = y[i] - y[r]; + if (kthr_h) + { + k = thr_h; + y[i] = y[r] + thr_h; + } + difidx[i] = k; + } + + return; +} + diff --git a/src/libs/libevs/lib_enc/diffcod_fx.cpp b/src/libs/libevs/lib_enc/diffcod_fx.cpp deleted file mode 100755 index d5409431..00000000 --- a/src/libs/libevs/lib_enc/diffcod_fx.cpp +++ /dev/null @@ -1,142 +0,0 @@ -/*==================================================================================== - EVS Codec 3GPP TS26.442 Apr 03, 2018. Version 12.11.0 / 13.6.0 / 14.2.0 - ====================================================================================*/ - -#include "options.h" /* Compilation switches */ -#include "rom_com_fx.h" /* Static table prototypes */ -#include "prot_fx.h" /* Function Prototypes */ -#include "stl.h" - -/*--------------------------------------------------------------------------*/ -/* Function diffcod */ -/* ~~~~~~~~~~~~~~~~~ */ -/* */ -/* Differential coding for indices of quantized norms */ -/*--------------------------------------------------------------------------*/ -/* Word16 N (i) number of sub-vectors */ -/* Word16 *y (i/o) indices of quantized norms */ -/* Word16 *difidx (o) differential code */ -/*--------------------------------------------------------------------------*/ - -void diffcod_fx( - const Word16 N, /* (i) number of sub-vectors */ - Word16 *y, /* (i/o) indices of quantized norms */ - Word16 *difidx /* (o) differential code */ -) -{ - Word16 i, k, r; - - FOR (i=N-1; i>0; i--) - { - r = sub(i, 1); - k = sub(y[i], y[r]); - if ( sub(k, -15) < 0 ) - { - y[r] = add(y[i], 15); - move16(); - } - } - - FOR (i=1; i 0 ) - { - k = 16; - move16(); - y[i] = add(y[r], 16); - move16(); - } - difidx[r] = add(k, 15); - move16(); - } - - return; -} - - - - -/*-------------------------------------------------------------------------- - * diffcod_lrmdct() - * - * Differential coding for indices of quantized norms - *--------------------------------------------------------------------------*/ - -void diffcod_lrmdct_fx( - const Word16 N, /* i : number of sub-vectors */ - const Word16 be_ref, /* i : band energy reference */ - Word16 *y, /* i/o: indices of quantized norms */ - Word16 *difidx, /* o : differential code */ - const Word16 is_transient /* i : transient flag */ -) -{ - Word16 i, m, r; - Word16 k; - Word16 thr_l,thr_h; - - IF(is_transient) - { - thr_l = -15; - move16(); - thr_h = 16; - move16(); - } - ELSE - { - thr_l = -32; - move16(); - thr_h = 31; - move16(); - } - - difidx[0] = sub(y[0], be_ref); - move16(); - IF( sub(difidx[0], thr_h) > 0) - { - difidx[0] = thr_h; - move16(); - y[0] = add(be_ref, thr_h); - move16(); - } - - IF( sub(difidx[0],thr_l) < 0 ) - { - difidx[0] = thr_l; - move16(); - y[0] = add(be_ref, thr_l); - move16(); - } - - m = sub(N, 1); - FOR (i=m; i>0; i--) - { - r = sub(i, 1); - k = sub(y[i], y[r]); - move16(); - if ( sub(k, thr_l) < 0 ) - { - y[r] = sub(y[i], thr_l); - move16(); - } - } - - FOR (i=1; i 0 ) - { - k = thr_h; - move16(); - y[i] = add(y[r], thr_h); - move16(); - } - difidx[i] = k; - move16(); - } - - return; -} - diff --git a/src/libs/libevs/lib_enc/dtx.cpp b/src/libs/libevs/lib_enc/dtx.cpp new file mode 100644 index 00000000..43026b52 --- /dev/null +++ b/src/libs/libevs/lib_enc/dtx.cpp @@ -0,0 +1,657 @@ +/*==================================================================================== + EVS Codec 3GPP TS26.443 Nov 13, 2018. Version 12.11.0 / 13.7.0 / 14.3.0 / 15.1.0 + ====================================================================================*/ + +#include +#include +#include "options.h" +#include "cnst.h" +#include "prot.h" +#include "rom_com.h" + +/*-------------------------------------------------------------------* + * Local constants + *-------------------------------------------------------------------*/ + +#define ALPHA_ENER_SLOW 0.99f /* Slow adaptation (noise up, speech down) */ +#define ALPHA_ENER_FAST 0.90f /* Fast adaptation (noise down, speech up) */ +#define MIN_CNT 50 /* Minimum frame number before SID interval adaptation */ + +#define SNR_H 51.0f /* Estimated SNR and corresponding SID interval */ +/* 51dB corresponds to 25dB SNR before noise supressor */ +#define SNR_L 36.0f +#define INT_H 50 +#define INT_L 8 + +#define LTE_VAR -4.0f + +#define CNG_TYPE_HO 20 /* hangover for switching between CNG types */ + + +/*-------------------------------------------------------------------* + * Local functions + *-------------------------------------------------------------------*/ + +static void update_SID_cnt( Encoder_State *st ); + + +/*-------------------------------------------------------------------* + * dtx() + * + * Discontinuous transmission operation + *-------------------------------------------------------------------*/ + +void dtx( + Encoder_State *st, /* i/o: encoder state structure */ + const short vad, /* i : vad flag */ + const float speech[] /* i : Pointer to the speech frame */ +) +{ + float alpha; + + /* Initialization */ + if( st->ini_frame == 0 ) + { + st->active_cnt = CNG_TYPE_HO; + if( st->codec_mode == MODE1 || st->Opt_AMR_WB ) + { + st->cng_type = LP_CNG; + } + else + { + st->cng_type = FD_CNG; + } + } + + if( st->Opt_DTX_ON && vad == 0 && + st->ini_frame > 2 && /* CNG coding starts after 3 frames */ + st->fd_cng_reset_flag == 0 && + st->last_core != AMR_WB_CORE && + st->Opt_AMR_WB == 0 ) + { + if ( st->last_core_brate > SID_2k40 && + st->last_total_brate_cng != -1 && + st->last_total_brate_cng != st->total_brate && + (st->last_total_brate_cng <= ACELP_24k40 || st->lp_noise < 15) + ) + { + st->total_brate = st->last_total_brate_cng; + if( !(st->total_brate == ACELP_7k20 && st->Opt_SC_VBR) ) + { + st->Opt_SC_VBR = 0; + } + + st->rf_mode = st->last_rf_mode_cng; + st->bwidth = st->last_bwidth_cng; + st->codec_mode = st->last_codec_mode_cng; + } + if ( st->last_core_brate <= SID_2k40 && + st->last_total_brate != st->total_brate && + ( st->last_total_brate <= ACELP_24k40 || st->lp_noise < 15 ) ) + { + st->total_brate = st->last_total_brate; + if( !(st->total_brate == ACELP_7k20 && st->Opt_SC_VBR) ) + { + st->Opt_SC_VBR = 0; + } + + st->Opt_RF_ON = 0; + if( st->rf_mode && st->rf_fec_offset > 0 && st->total_brate == ACELP_13k20 && st->bwidth != NB ) + { + st->Opt_RF_ON = 1; + } + st->rf_mode = st->Opt_RF_ON; + st->bwidth = st->last_bwidth; + switch ( st->total_brate ) + { + case 5900: + st->codec_mode = MODE1; + break; + case 7200: + st->codec_mode = MODE1; + break; + case 8000: + st->codec_mode = MODE1; + break; + case 9600: + st->codec_mode = MODE2; + break; + case 13200: + st->codec_mode = MODE1; + break; + case 16400: + st->codec_mode = MODE2; + break; + case 24400: + st->codec_mode = MODE2; + break; + case 32000: + st->codec_mode = MODE1; + break; + case 48000: + st->codec_mode = MODE2; + break; + case 64000: + st->codec_mode = MODE1; + break; + case 96000: + st->codec_mode = MODE2; + break; + case 128000: + st->codec_mode = MODE2; + break; + } + } + } + + /*------------------------------------------------------------------------* + * Select SID or FRAME__NO_DATA frame if DTX is enabled + *------------------------------------------------------------------------*/ + + if( st->Opt_DTX_ON && vad == 0 && + st->ini_frame > 2 && /* CNG coding starts after 3 frames */ + ( st->total_brate <= ACELP_24k40 || st->lp_noise < 15 ) && /* at higher bitrates, DTX kicks in only when the level of background noise is low */ + st->fd_cng_reset_flag == 0 ) + { + /* reset counter */ + st->active_cnt = 0; + + if ( st->Opt_AMR_WB ) + { + st->last_total_brate_cng = -1; + } + else + { + st->last_total_brate_cng = st->total_brate; + st->last_bwidth_cng = st->bwidth; + st->last_codec_mode_cng = st->codec_mode; + st->last_rf_mode_cng = st->rf_mode; + } + + if( st->cnt_SID == 0 ) + { + /* this will be a SID frame */ + if ( st->Opt_AMR_WB ) + { + st->core_brate = SID_1k75; + } + else + { + st->core_brate = SID_2k40; + } + } + else + { + /* this will be a no data frame */ + st->core_brate = FRAME__NO_DATA; + } + + if( st->core_brate == FRAME__NO_DATA && st->last_core != ACELP_CORE && !st->Opt_AMR_WB ) + { + /* force SID frame when switching from HQ core or AMR-WB IO mode into inactive frame in ACELP core when DTX is on */ + st->core_brate = SID_2k40; + } + + if( st->cng_type == FD_CNG && st->total_brate <= ACELP_24k40 ) /* at highest bit-rates, use exclusively LP_CNG */ + { + if ( st->total_brate == ACELP_9k60 || st->total_brate == ACELP_16k40 || st->total_brate == ACELP_24k40 ) + { + st->codec_mode = MODE2; + } + } + else + { + st->cng_type = LP_CNG; + if ( st->codec_mode == MODE2 ) + { + st->lp_cng_mode2 = 1; + } + st->codec_mode = MODE1; + } + } + + /*------------------------------------------------------------------------* + * Reset counters when in active frame (neither SID nor FRAME__NO_DATA frame) + *------------------------------------------------------------------------*/ + + if( st->core_brate != SID_2k40 && st->core_brate != SID_1k75 && st->core_brate != 0 ) + { + st->cnt_SID = 0; + + /* change SID update rate */ + /* first SID update is only 8 (3 in AMR-WB IO mode) frames after the active speech end */ + if( !st->Opt_AMR_WB ) + { + st->max_SID = FIXED_SID_RATE; + } + else + { + st->max_SID = 3; + } + + if ( st->max_SID > st->interval_SID ) + { + st->max_SID = st->interval_SID; + } + + /* reset the counter of CNG frames for averaging */ + st->cng_cnt = 0; + + if( st->active_cnt >= CNG_TYPE_HO && !st->Opt_AMR_WB ) + { + if ( st->cng_type == LP_CNG && ( (st->input_bwidth == NB && st->bckr_tilt_lt > 9.f) || (st->input_bwidth > NB && st->bckr_tilt_lt > 45.f) ) ) + { + st->cng_type = FD_CNG; + } + else if ( st->cng_type == FD_CNG && ( (st->input_bwidth == NB && st->bckr_tilt_lt < 2.f) || (st->input_bwidth > NB && st->bckr_tilt_lt < 10.f) ) ) + { + st->cng_type = LP_CNG; + } + st->last_total_brate_cng = -1; + } + else if( st->Opt_AMR_WB ) + { + st->cng_type = LP_CNG; + } + + st->active_cnt++; + st->active_cnt = min(st->active_cnt,200); + } + + /*------------------------------------------------------------------------* + * Update speech and background noise long-term energy + *------------------------------------------------------------------------*/ + + st->frame_ener = 0.0f; + + if ( st->Opt_DTX_ON ) + { + st->frame_ener = sum2_f( speech, L_FRAME ); + + /* Active speech (voiced) */ + if ( st->clas == VOICED_CLAS ) + { + alpha = ALPHA_ENER_SLOW; + if ( st->frame_ener > st->lt_ener_voiced ) + { + alpha = ALPHA_ENER_FAST; + } + + st->lt_ener_voiced = alpha * st->lt_ener_voiced + (1.0f-alpha) * st->frame_ener; + + (st->VarDTX_cnt_voiced)++; + + if (st->VarDTX_cnt_voiced > MIN_CNT) + { + st->VarDTX_cnt_voiced = MIN_CNT; + } + } + + /* Background noise */ + else if( !st->Opt_AMR_WB ) + { + alpha = ALPHA_ENER_SLOW; + if (st->frame_ener < st->lt_ener_noise) + { + alpha = ALPHA_ENER_FAST; + } + + st->lt_ener_noise = alpha * st->lt_ener_noise + (1.0f-alpha) * st->frame_ener; + + (st->VarDTX_cnt_noise)++; + + if ( st->VarDTX_cnt_noise > MIN_CNT) + { + st->VarDTX_cnt_noise = MIN_CNT; + } + } + } + + /* Update of the SID counter */ + update_SID_cnt( st ); + + /* Update encoded bandwidth */ + if( st->Opt_DTX_ON && (st->core_brate == SID_2k40 || st->core_brate == FRAME__NO_DATA ) ) + { + st->bwidth = st->last_bwidth; + if( st->last_core_brate > SID_2k40 && st->last_total_brate_cng != -1 ) + { + st->bwidth = st->last_bwidth_cng; + } + + if( st->Opt_RF_ON && st->total_brate == ACELP_13k20 && st->bwidth == NB ) + { + st->codec_mode = MODE1; + reset_rf_indices(st); + st->Opt_RF_ON = 0; + st->rf_mode = 0; + } + + if ( st->codec_mode == MODE2 ) + { + short n, bits_frame_nominal, tmpBandwidthMin; + + bits_frame_nominal = st->total_brate / 50; + for( n=0; nrf_mode ) + { + tmpBandwidthMin = WB; + } + + st->bwidth = max(min(st->bwidth, FrameSizeConfig[n].bandwidth_max), tmpBandwidthMin); + } + + } + + return; +} + + +/*---------------------------------------------------------------------* + * update_SID_cnt() + * + * Update of the SID counter + *---------------------------------------------------------------------*/ + +static void update_SID_cnt( + Encoder_State *st /* i/o: State structure */ +) +{ + float EstimatedSNR, delta; + + if( st->core_brate == SID_2k40 || st->core_brate == SID_1k75 || st->core_brate == FRAME__NO_DATA ) + { + /* Adapt the SID interval */ + if ( st->var_SID_rate_flag && st->VarDTX_cnt_voiced == MIN_CNT && st->VarDTX_cnt_noise == MIN_CNT ) + { + EstimatedSNR = 10.0f * (float)log10( (0.01f + st->lt_ener_voiced) / (0.01f + st->lt_ener_noise) ); + if ( EstimatedSNR > SNR_H ) + { + st->interval_SID = INT_H; + } + else if ( EstimatedSNR < SNR_L ) + { + st->interval_SID = INT_L; + } + else + { + st->interval_SID = INT_L + (short)((INT_H - INT_L) * (EstimatedSNR - SNR_L)/(SNR_H - SNR_L)); + } + st->interval_SID = min(max(st->interval_SID, INT_L), INT_H); + + if( !st->Opt_AMR_WB || st->max_SID != 3 ) + { + st->max_SID = st->interval_SID; /* change SID update rate */ + } + } + + if( st->Opt_DTX_ON == 1 && st->cnt_SID != 0 ) + { + /* Send SID frame only if long-term energy variation is above threshold */ + delta = 10.0f * (float)log10((0.01f + st->lt_ener_noise)/(0.01f + st->lt_ener_last_SID)); + if ( delta < LTE_VAR && st->VarDTX_cnt_voiced == MIN_CNT && st->VarDTX_cnt_noise == MIN_CNT ) + { + /* Send SID frame, and reset lt_ener_noise */ + st->lt_ener_noise = st->frame_ener; + } + } + else + { + /* If SID frame was sent, update long-term energy */ + st->lt_ener_last_SID = st->lt_ener_noise; + } + + (st->cnt_SID)++; + + if( st->var_SID_rate_flag ) + { + if( st->Opt_AMR_WB && st->max_SID == 3 && st->cnt_SID == 3 ) + { + /* set the size of CNG history buffer for averaging to 3 frames */ + st->cng_hist_size = 3; + } + else if ( st->max_SID != 3 && st->cnt_SID == DTX_HIST_SIZE ) + { + /* set the size of CNG history buffer for averaging to DTX_HIST_SIZE frames */ + /* be sure that DTX_HIST_SIZE >= INT_L */ + st->cng_hist_size = DTX_HIST_SIZE; + } + } + + if( !st->var_SID_rate_flag && st->interval_SID > 1 ) + { + /* set the size of CNG history buffer for averaging to interval_SID frames */ + st->cng_hist_size = st->interval_SID; + if (st->cng_hist_size > DTX_HIST_SIZE) + { + st->cng_hist_size = DTX_HIST_SIZE; + } + } + + if( st->cnt_SID >= st->max_SID ) + { + /* adaptive SID update interval */ + st->max_SID = st->interval_SID; + st->cnt_SID = 0; + } + } + + return; +} + + +/*-------------------------------------------------------------------* + * dtx_hangover_control() + * + * + *-------------------------------------------------------------------*/ + +void dtx_hangover_control( + Encoder_State *st, /* i/o: encoder state structure */ + const float lsp_new[M] /* i : current frame LSPs */ +) +{ + short ptr; + short i, j, m; + float tmp_lsp[max(DTX_HIST_SIZE,HO_HIST_SIZE)*M]; + float tmp_enr[max(DTX_HIST_SIZE,HO_HIST_SIZE)]; + float tmp[max(DTX_HIST_SIZE,HO_HIST_SIZE)*M]; + float enr_new; + float weights; + float enr_est, lsp_est[M]; + float Dlsp, Denr; + float lsf_tmp[M]; + float C[M]; + float max[2]; + short max_idx[2]; + float ftmp; + float Dlsp_n2e, Denr_n2e; + + /* get current frame exc energy in log2 */ + enr_new = (float)(log10(st->ho_ener_circ[st->ho_circ_ptr]) / log10(2.0f)); + + if( enr_new < 0.0f ) + { + enr_new = 0.0f; + } + + /* get energies and lsps of hangover frames */ + ptr = st->ho_circ_ptr - (st->burst_ho_cnt-1); + if( ptr < 0 ) + { + ptr += st->ho_circ_size; + } + + for( i=0; iburst_ho_cnt-1; i++ ) + { + mvr2r( &(st->ho_lsp_circ[ptr*M]), &(tmp_lsp[i*M]), M ); + tmp_enr[i] = st->ho_ener_circ[ptr]; + + ptr++; + if( ptr == st->ho_circ_size ) + { + ptr = 0; + } + } + + /* get estimated CNG energy and lsps assuming terminate hangover at current frame */ + ptr = st->burst_ho_cnt - 2; + enr_est = W_DTX_HO[0] * tmp_enr[ptr]; + weights = W_DTX_HO[0]; + mvr2r( &(tmp_lsp[ptr*M]), tmp, M ); + m = 1; + + for( i = 1; i < st->burst_ho_cnt-2; i++ ) + { + if ( tmp_enr[ptr-i] < tmp_enr[ptr] * BUF_H_NRG && tmp_enr[ptr-i] > tmp_enr[ptr] * BUF_L_NRG ) + { + enr_est += W_DTX_HO[i] * tmp_enr[ptr-i]; + weights += W_DTX_HO[i]; + mvr2r( &tmp_lsp[(ptr-i)*M], &tmp[m*M], M ); + m++; + } + } + + enr_est /= weights; + + if( enr_est < 1.0f ) + { + enr_est = 1.0f; + } + + Denr_n2e = (float)fabs(enr_new - log10(enr_est) / log10(2.0f)); + + if( m < 3 ) + { + enr_est = 0.8f*enr_est + (1-0.8f)*st->ho_ener_circ[st->ho_circ_ptr]; + } + else + { + enr_est = 0.95f*enr_est + (1-0.95f)*st->ho_ener_circ[st->ho_circ_ptr]; + } + + enr_est = (float)(log10(enr_est) / log10(2.0f)); + + if( enr_est < 0.0f ) + { + enr_est = 0.0f; + } + + set_f( max, 0.0f, 2 ); + set_s( max_idx, 0, 2 ); + + for( i=0; iL_frame == L_FRAME ) + { + lsp2lsf( &tmp[i*M], lsf_tmp, M, INT_FS_12k8 ); + ftmp = 6400.0f / (M+1); + C[i] = (6400.0f - lsf_tmp[M-1] - ftmp) * (6400.0f - lsf_tmp[M-1] - ftmp); + } + else + { + lsp2lsf( &tmp[i*M], lsf_tmp, M, INT_FS_16k ); + ftmp = 8000.0f / (M+1); + C[i] = (8000.0f - lsf_tmp[M-1] - ftmp) * (8000.0f - lsf_tmp[M-1] - ftmp); + } + + C[i] += (lsf_tmp[0] - ftmp) * (lsf_tmp[0] - ftmp); + for ( j=0; j max[0] ) + { + max[1] = max[0]; + max_idx[1] = max_idx[0]; + max[0] = C[i]; + max_idx[0] = i; + } + else if ( C[i] > max[1] ) + { + max[1] = C[i]; + max_idx[1] = i; + } + } + + if( m == 1 ) + { + mvr2r( tmp, lsp_est, M ); + } + else if( m < 4 ) + { + for( i=0; ilspCNG[i] - lsp_est[i]); + if ( fabs(st->lspCNG[i] - lsp_est[i]) > max[0] ) + { + max[0] = (float)fabs(st->lspCNG[i] - lsp_est[i]); + } + } + Denr = (float)fabs((log10(st->lp_ener+0.1f)/log10(2.0f)) - enr_est); + + /* make decision if DTX hangover can be terminated */ + st->hangover_terminate_flag = 0; + + if (( Dlsp < 0.4f && Denr < 1.4f && max[0] < 0.1f && Dlsp_n2e < 0.4f && Denr_n2e < 1.2f && st->Opt_SC_VBR)|| + ( Dlsp < 0.4f && Denr < 0.8f && max[0] < 0.1f && Dlsp_n2e < 0.4f && Denr_n2e < 0.8f && !st->Opt_SC_VBR)) + { + st->hangover_terminate_flag = 1; + } + + return; +} diff --git a/src/libs/libevs/lib_enc/dtx_fx.cpp b/src/libs/libevs/lib_enc/dtx_fx.cpp deleted file mode 100755 index 661af103..00000000 --- a/src/libs/libevs/lib_enc/dtx_fx.cpp +++ /dev/null @@ -1,919 +0,0 @@ -/*==================================================================================== - EVS Codec 3GPP TS26.442 Apr 03, 2018. Version 12.11.0 / 13.6.0 / 14.2.0 - ====================================================================================*/ - -#include "options.h" /* Compilation switches */ -#include "cnst_fx.h" /* Common constants */ -#include "prot_fx.h" /* Function prototypes */ -#include "rom_com_fx.h" -#include "stl.h" -#include "basop_mpy.h" -#include "assert.h" - -/*-------------------------------------------------------------------* - * Local constants - *-------------------------------------------------------------------*/ -#define ALPHA_ENER_FAST_FX 29491 /* Fast adaptation (noise down, speech up) */ -#define ALPHA_ENER_SLOW_FX 32440 /* Fast adaptation (noise down, speech up) */ - -#define MIN_CNT 50 /* Minimum frame number before SID interval adaptation */ - -#define SNR_H_FX 13056 /* Estimated SNR and corresponding SID interval */ -#define SNR_L_FX 9216 /* 51dB corresponds to 25dB SNR before noise supressor */ -#define INT_H 50 -#define INT_L 8 -#define RATIO (INT_H - INT_L)/((SNR_H_FX - SNR_L_FX)/256) - -#define LTE_VAR_FX -1024 /* Q8, -4.0f */ - -#define CNG_TYPE_HO 20 /* hangover for switching between CNG types */ - -/*-------------------------------------------------------------------* - * Local functions - *-------------------------------------------------------------------*/ - -static void update_SID_cnt( Encoder_State_fx *st_fx ); - - -/*==================================================================================*/ -/* FUNCTION : dtx_fx() */ -/*----------------------------------------------------------------------------------*/ -/* PURPOSE : Discontinuous transmission operation */ -/*----------------------------------------------------------------------------------*/ -/* INPUT ARGUMENTS : */ -/* _ (Encoder_State_Fx) st_fx : encoder state structure */ -/* _ (Word16) vad : vad flag Q0 */ -/* _ (Word16[]) speech_fx : Pointer to the speech frame qSpeech */ -/* _ (Word16) qSpeech : speech buffer qformat value */ -/* _ (Word16*) qener : frame_ener/lt_ener_voiced/lt_ener_noise buf qformat */ -/*----------------------------------------------------------------------------------*/ -/* OUTPUT ARGUMENTS : */ -/* _ (Word16*) qener : frame_ener/lt_ener_voiced/lt_ener_noise buf qformat */ -/* _ (Encoder_State_Fx) st_fx : encoder state structure */ -/*----------------------------------------------------------------------------------*/ - -/*----------------------------------------------------------------------------------*/ -/* RETURN ARGUMENTS : */ -/* _ None */ -/*==================================================================================*/ -void dtx_fx( - Encoder_State_fx *st_fx, /* i/o: encoder state structure */ - const Word16 vad, /* i : vad flag */ - const Word16 speech[], /* i : Pointer to the speech frame */ - Word16 Q_speech /* i : Q factor for speech */ - -) -{ - Word16 alpha,j,i,Q_speech2; - Word32 L_tmp; - - /* Initialization */ - IF( st_fx->ini_frame_fx == 0 ) - { - st_fx->active_fr_cnt_fx = CNG_TYPE_HO; - move16(); - - st_fx->cng_type_fx = FD_CNG; - move16(); - test(); - if( sub( st_fx->codec_mode, MODE1 ) == 0 || st_fx->Opt_AMR_WB_fx ) - { - st_fx->cng_type_fx = LP_CNG; - move16(); - } - } - test(); - test(); - IF( st_fx->Opt_DTX_ON_fx && vad == 0 && - sub(st_fx->ini_frame_fx,2) > 0 && /* CNG coding starts after 2 frames */ - st_fx->fd_cng_reset_flag == 0 && - sub(st_fx->last_core_fx, AMR_WB_CORE) != 0 && - st_fx->Opt_AMR_WB_fx == 0 ) - { - test(); - test(); - test(); - test(); - test(); - IF ( L_sub(st_fx->last_core_brate_fx,SID_2k40) > 0 && - L_sub(st_fx->last_total_brate_cng_fx,-1) != 0 && - L_sub(st_fx->last_total_brate_cng_fx,st_fx->total_brate_fx) != 0 && - ( (L_sub(st_fx->last_total_brate_cng_fx, ACELP_24k40) <= 0) || (sub(st_fx->lp_noise_fx, 1280) < 0) ) ) - { - st_fx->total_brate_fx = st_fx->last_total_brate_cng_fx; - move32(); - test(); - if( !(L_sub(st_fx->total_brate_fx,ACELP_7k20) == 0 && st_fx->Opt_SC_VBR_fx) ) - { - st_fx->Opt_SC_VBR_fx = 0; - move16(); - } - - st_fx->Opt_RF_ON = 0; - move16(); - test(); - test(); - test(); - if( st_fx->rf_mode && st_fx->rf_fec_offset > 0 && L_sub(st_fx->total_brate_fx,ACELP_13k20) == 0 && sub(st_fx->bwidth_fx,NB) != 0 ) - { - st_fx->Opt_RF_ON = 1; - move16(); - } - st_fx->rf_mode = st_fx->Opt_RF_ON; - move16(); - st_fx->bwidth_fx = st_fx->last_bwidth_cng_fx; - move16(); - st_fx->codec_mode = st_fx->last_codec_mode_cng; - move16(); - } - test(); - test(); - test(); - test(); - test(); - IF ( L_sub(st_fx->last_core_brate_fx,SID_2k40) <= 0 && - L_sub(st_fx->last_total_brate_fx,st_fx->total_brate_fx) != 0 && - ( L_sub(st_fx->last_total_brate_fx,ACELP_24k40) <= 0 || sub(st_fx->lp_noise_fx, 1280) < 0) ) - - { - st_fx->total_brate_fx = st_fx->last_total_brate_fx; - move32(); - test(); - if( !(L_sub(st_fx->total_brate_fx,ACELP_7k20) == 0 && st_fx->Opt_SC_VBR_fx) ) - { - st_fx->Opt_SC_VBR_fx = 0; - move16(); - } - - st_fx->Opt_RF_ON = 0; - move16(); - test(); - test(); - test(); - if( st_fx->rf_mode && st_fx->rf_fec_offset > 0 && L_sub(st_fx->total_brate_fx,ACELP_13k20) == 0 && sub(st_fx->bwidth_fx,NB) != 0 ) - { - st_fx->Opt_RF_ON = 1; - move16(); - } - st_fx->rf_mode = st_fx->Opt_RF_ON; - move16(); - st_fx->bwidth_fx = st_fx->last_bwidth_fx; - move32(); - SWITCH ( st_fx->total_brate_fx ) - { - case 5900: - st_fx->codec_mode = MODE1; - move16(); - BREAK; - case 7200: - st_fx->codec_mode = MODE1; - move16(); - BREAK; - case 8000: - st_fx->codec_mode = MODE1; - move16(); - BREAK; - case 9600: - st_fx->codec_mode = MODE2; - move16(); - BREAK; - case 13200: - st_fx->codec_mode = MODE1; - move16(); - BREAK; - case 16400: - st_fx->codec_mode = MODE2; - move16(); - BREAK; - case 24400: - st_fx->codec_mode = MODE2; - move16(); - BREAK; - case 32000: - st_fx->codec_mode = MODE1; - move16(); - BREAK; - case 48000: - st_fx->codec_mode = MODE2; - move16(); - BREAK; - case 64000: - st_fx->codec_mode = MODE1; - move16(); - BREAK; - case 96000: - st_fx->codec_mode = MODE2; - move16(); - BREAK; - case 128000: - st_fx->codec_mode = MODE2; - move16(); - BREAK; - } - } - } - - /*------------------------------------------------------------------------* - * Select SID or FRAME_NO_DATA frame if DTX is enabled - *------------------------------------------------------------------------*/ - - test(); - test(); - test(); - test(); - test(); - IF( st_fx->Opt_DTX_ON_fx && vad == 0 && - sub(st_fx->ini_frame_fx,2) > 0 && /* CNG coding starts after 2 frames */ - ( L_sub(st_fx->total_brate_fx,ACELP_24k40) <= 0 || sub(st_fx->lp_noise_fx, 1280) < 0) && - st_fx->fd_cng_reset_flag == 0 ) - { - /* reset counter */ - st_fx->active_fr_cnt_fx = 0; - move16(); - - IF( st_fx->Opt_AMR_WB_fx ) - { - st_fx->last_total_brate_cng_fx = -1; - } - ELSE - { - st_fx->last_total_brate_cng_fx = st_fx->total_brate_fx; - st_fx->last_bwidth_cng_fx = st_fx->bwidth_fx; - st_fx->last_codec_mode_cng = st_fx->codec_mode; - } - - IF( st_fx->cnt_SID_fx == 0 ) - { - /* this will be a SID frame */ - IF ( st_fx->Opt_AMR_WB_fx ) - { - st_fx->core_brate_fx = SID_1k75; - move32(); - } - ELSE - { - st_fx->core_brate_fx = SID_2k40; - move32(); - } - } - ELSE - { - /* this will be a no data frame */ - st_fx->core_brate_fx = FRAME_NO_DATA; - move32(); - } - - test(); - test(); - IF( L_sub(st_fx->core_brate_fx,FRAME_NO_DATA) == 0 && sub(st_fx->last_core_fx,ACELP_CORE) != 0 && !st_fx->Opt_AMR_WB_fx ) - { - /* force SID frame when switching from HQ core or AMR-WB IO mode into inactive frame in ACELP core when DTX is on */ - st_fx->core_brate_fx = SID_2k40; - move32(); - } - - test(); - IF( sub(st_fx->cng_type_fx,FD_CNG) == 0 && L_sub(st_fx->total_brate_fx,ACELP_24k40) <= 0 ) /* at highest bit-rates, use exclusively LP_CNG */ - { - test(); - test(); - IF ( L_sub(st_fx->total_brate_fx,ACELP_9k60) == 0 || L_sub(st_fx->total_brate_fx,ACELP_16k40) == 0 || L_sub(st_fx->total_brate_fx,ACELP_24k40) == 0 ) - { - st_fx->codec_mode = MODE2; - move16(); - } - } - ELSE - { - st_fx->cng_type_fx = LP_CNG; - move16(); - IF ( st_fx->codec_mode == MODE2 ) - { - st_fx->lp_cng_mode2 = 1; - move16(); - } - st_fx->codec_mode = MODE1; - move16(); - } - - - } - - /*------------------------------------------------------------------------* - * Reset counters when in active frame (not in SID or FRAME_NO_DATA frame) - *------------------------------------------------------------------------*/ - /* NB core bit rate can be "-1" at startup , so one can not use core_brate_fx <=2400 */ - test(); - test(); - IF ( (L_sub(st_fx->core_brate_fx ,SID_2k40) != 0 ) && (L_sub(st_fx->core_brate_fx, SID_1k75) != 0 ) && (st_fx->core_brate_fx != 0)) - { - st_fx->cnt_SID_fx = 0; - move16(); - - /* change SID update rate */ - /* first SID update is only 8 (3) frames after the active speech end */ - IF( !st_fx->Opt_AMR_WB_fx ) - { - st_fx->max_SID_fx = FIXED_SID_RATE; - move16(); - } - ELSE - { - st_fx->max_SID_fx = 3; - move16(); /* first SID update is only 3 frames after the active speech end */ - } - - IF ( sub(st_fx->interval_SID_fx,st_fx->max_SID_fx) < 0 ) - { - st_fx->max_SID_fx = st_fx->interval_SID_fx; - move16();/* change SID update rate */ - } - - st_fx->cng_cnt_fx = 0; - move16(); /* reset the counter of CNG frames for averaging */ - - test(); - IF( sub(st_fx->active_fr_cnt_fx,CNG_TYPE_HO) >= 0 && st_fx->Opt_AMR_WB_fx == 0 ) - { - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - IF( sub(st_fx->cng_type_fx,LP_CNG) == 0 && ( (sub(st_fx->input_bwidth_fx,NB) == 0 && L_sub(st_fx->bckr_tilt_lt,589824l/*9.f Q16*/) > 0) || (sub(st_fx->input_bwidth_fx,NB) > 0 && L_sub(st_fx->bckr_tilt_lt,2949120l/*45.f Q16*/) > 0) ) ) - { - st_fx->cng_type_fx = FD_CNG; - move16(); - } - ELSE IF( sub(st_fx->cng_type_fx,FD_CNG) == 0 && ( (sub(st_fx->input_bwidth_fx,NB) == 0 && L_sub(st_fx->bckr_tilt_lt,131072l/*2.f Q16*/) < 0) || (sub(st_fx->input_bwidth_fx,NB) > 0 && L_sub(st_fx->bckr_tilt_lt,655360l/*10.f Q16*/) < 0) ) ) - { - st_fx->cng_type_fx = LP_CNG; - move16(); - } - st_fx->last_total_brate_cng_fx = -1; - } - ELSE IF( st_fx->Opt_AMR_WB_fx ) - { - st_fx->cng_type_fx = LP_CNG; - move16(); - } - st_fx->active_fr_cnt_fx = add( st_fx->active_fr_cnt_fx, 1 ); - st_fx->active_fr_cnt_fx = s_min(st_fx->active_fr_cnt_fx, 200); - } - - /*------------------------------------------------------------------------* - * Update speech and background noise long-term energy - *------------------------------------------------------------------------*/ - - st_fx->frame_ener_fx = L_deposit_l(0); - - IF ( st_fx->Opt_DTX_ON_fx ) - { - Q_speech2 = add(shl(Q_speech, 1), 7); - FOR (j=0; j<16; j++) - { - L_tmp = L_mult0(*speech, *speech); - speech++; - FOR (i = 1; i< L_FRAME/16; i++) - { - L_tmp = L_mac0(L_tmp, *speech, *speech); - speech++; - } - st_fx->frame_ener_fx = L_add(st_fx->frame_ener_fx, L_shr(L_tmp, Q_speech2));/*Q(-7) */ - } - - /* Active speech (voiced) */ - - IF ( sub(st_fx->clas_fx,VOICED_CLAS) == 0 ) - { - alpha = ALPHA_ENER_SLOW_FX; - move16(); - if ( L_sub(st_fx->frame_ener_fx,st_fx->lt_ener_voiced_fx) > 0 ) - { - alpha = ALPHA_ENER_FAST_FX; - move16();/*Q15 */ - } - - /*st_fx->lt_ener_voiced_fx = alpha * st_fx->lt_ener_voiced_fx + (1.0f-alpha) * st_fx->frame_ener_fx;*/ - L_tmp = L_sub(st_fx->lt_ener_voiced_fx, st_fx->frame_ener_fx); - L_tmp = Mult_32_16(L_tmp, alpha); - st_fx->lt_ener_voiced_fx = L_add(L_tmp, st_fx->frame_ener_fx); /*Q(-7) */ - - st_fx->VarDTX_cnt_voiced_fx = add(st_fx->VarDTX_cnt_voiced_fx,1); - - st_fx->VarDTX_cnt_voiced_fx = s_min(st_fx->VarDTX_cnt_voiced_fx, MIN_CNT); - } - /* Background noise */ - ELSE IF( !st_fx->Opt_AMR_WB_fx ) - { - alpha = ALPHA_ENER_SLOW_FX; - move16(); - if (L_sub(st_fx->frame_ener_fx,st_fx->lt_ener_noise_fx) < 0) - { - alpha = ALPHA_ENER_FAST_FX; - move16(); - } - - /*st_fx->lt_ener_noise_fx = alpha * st_fx->lt_ener_noise_fx + (1.0f-alpha) * st_fx->frame_ener_fx;*/ - L_tmp = L_sub(st_fx->lt_ener_noise_fx, st_fx->frame_ener_fx); - L_tmp = Mult_32_16(L_tmp, alpha); - st_fx->lt_ener_noise_fx = L_add(L_tmp, st_fx->frame_ener_fx); - move32();/*Q(-7) */ - - st_fx->VarDTX_cnt_noise_fx = add(st_fx->VarDTX_cnt_noise_fx,1); - - st_fx->VarDTX_cnt_noise_fx = s_min(st_fx->VarDTX_cnt_noise_fx, MIN_CNT); - } - } - - /* Update of the SID counter */ - update_SID_cnt( st_fx ); - - /* Update encoded bandwidth */ - test(); - test(); - IF( st_fx->Opt_DTX_ON_fx && (st_fx->core_brate_fx == SID_2k40 || st_fx->core_brate_fx == FRAME_NO_DATA ) ) - { - - st_fx->bwidth_fx = st_fx->last_bwidth_fx; - move16(); - test(); - if( L_sub(st_fx->last_core_brate_fx, SID_2k40) > 0 && L_sub(st_fx->last_total_brate_cng_fx, -1) != 0 ) - { - st_fx->bwidth_fx = st_fx->last_bwidth_cng_fx; - move16(); - } - - test(); - test(); - IF( st_fx->Opt_RF_ON && (L_sub(st_fx->total_brate_fx, ACELP_13k20) == 0) && (sub(st_fx->bwidth_fx, NB) == 0)) - { - st_fx->codec_mode = MODE1; - move16(); - reset_rf_indices(st_fx); - st_fx->Opt_RF_ON = 0; - move16(); - st_fx->rf_mode = 0; - move16(); - } - - /* Set and limit the encoded bandwidth */ - IF ( sub(st_fx->codec_mode, MODE2) == 0 ) - { - Word16 n, bits_frame_nominal; - - UWord16 lsb; - Word16 tmpbandwidthMin; - - Mpy_32_16_ss(st_fx->total_brate_fx, 5243, &L_tmp, &lsb); /* 5243 is 1/50 in Q18. (0+18-15=3) */ - bits_frame_nominal = extract_l(L_shr(L_tmp, 3)); /* Q0 */ - - FOR (n=0; nrf_mode,1) == 0 ) - { - tmpbandwidthMin = WB; - } - st_fx->bwidth_fx = s_max(s_min(st_fx->bwidth_fx, FrameSizeConfig[n].bandwidth_max), tmpbandwidthMin); - } - - } - - return; -} - -/*---------------------------------------------------------------------* - * update_SID_cnt() - * - * Update of the SID counter - *---------------------------------------------------------------------*/ - -static void update_SID_cnt( - Encoder_State_fx *st_fx /* i/o: State structure */ -) -{ - Word16 EstimatedSNR, delta, frac, exp; - Word32 L_tmp1, L_tmp2; - - test(); - test(); - IF( L_sub(st_fx->core_brate_fx, SID_2k40) == 0 || L_sub(st_fx->core_brate_fx, SID_1k75) == 0 || st_fx->core_brate_fx == FRAME_NO_DATA ) - { - /* Adapt the SID interval */ - test(); - test(); - IF ( st_fx->var_SID_rate_flag_fx != 0 && sub(st_fx->VarDTX_cnt_voiced_fx, MIN_CNT) == 0 && sub(st_fx->VarDTX_cnt_noise_fx, MIN_CNT) == 0 ) - { - /* EstimatedSNR = 10.0f * (float)log10( (0.01f + st_fx->lt_ener_voiced) / (0.01f + st_fx->lt_ener_noise) ); */ - - L_tmp1 = L_max(st_fx->lt_ener_voiced_fx, 1); - exp = norm_l(L_tmp1); - frac = Log2_norm_lc(L_shl(L_tmp1, exp)); - exp = sub(30, exp); - L_tmp1 = L_Comp(exp, frac); - L_tmp2 = L_max(st_fx->lt_ener_noise_fx, 1); - exp = norm_l(L_tmp2); - frac = Log2_norm_lc(L_shl(L_tmp2, exp)); - exp = sub(30, exp); - L_tmp1 = L_sub(L_tmp1, L_Comp(exp, frac)); - /* 10 x Log10(a/b) = 10 x Log10(2) x [Log2(a) - Log2(b)] */ - /* 10 x Log10(2) = ~3.0103 */ - L_tmp1 = Mpy_32_16_1(L_tmp1, 24660); /* mult by 3.0103 / 4 in Q15 */ - L_tmp1 = L_shl(L_tmp1, 2+8); /* mult by 4 and shift left 8 to go in Q24 */ - EstimatedSNR = round_fx(L_tmp1); /* now in Q8 */ - IF ( sub(EstimatedSNR,SNR_H_FX) > 0 ) - { - st_fx->interval_SID_fx = INT_H; - move16(); - } - ELSE IF ( sub(EstimatedSNR,SNR_L_FX) < 0 ) - { - st_fx->interval_SID_fx = INT_L; - move16(); - } - ELSE - { - st_fx->interval_SID_fx = extract_h(L_mac(INT_L*65536L-SNR_L_FX/256*65536L*RATIO,(32768/256)*RATIO, EstimatedSNR)); - } - test(); - - if( st_fx->Opt_AMR_WB_fx == 0 || sub(st_fx->max_SID_fx,3) != 0 ) - { - st_fx->max_SID_fx = st_fx->interval_SID_fx; - move16(); /* change SID update rate */ - } - } - test(); - IF( st_fx->Opt_DTX_ON_fx != 0 && st_fx->cnt_SID_fx != 0 ) - { - L_tmp1 = L_max(st_fx->lt_ener_noise_fx, 1); - exp = norm_l(L_tmp1); - frac = Log2_norm_lc(L_shl(L_tmp1, exp)); - exp = sub(30, exp); - L_tmp1 = L_Comp(exp, frac); - L_tmp2 = L_max(st_fx->lt_ener_last_SID_fx, 1); - exp = norm_l(L_tmp2); - frac = Log2_norm_lc(L_shl(L_tmp2, exp)); - exp = sub(30, exp); - L_tmp1 = L_sub(L_tmp1, L_Comp(exp, frac)); - /* 10 x Log10(a/b) = 10 x Log10(2) x [Log2(a) - Log2(b)] */ - /* 10 x Log10(2) = ~3.0103 */ - L_tmp1 = Mpy_32_16_1(L_tmp1, 24660); /* mult by 3.0103 / 4 in Q15 */ - L_tmp1 = L_shl(L_tmp1, 2+8); /* mult by 4 and shift left 8 to go in Q24 */ - delta = round_fx(L_tmp1); /* now in Q8 */ - test(); - test(); - if ( sub(delta,LTE_VAR_FX) < 0 && sub(st_fx->VarDTX_cnt_voiced_fx,MIN_CNT) == 0 && sub(st_fx->VarDTX_cnt_noise_fx, MIN_CNT) == 0 ) - { - /* Send SID frame, and reset lt_ener_noise */ - st_fx->lt_ener_noise_fx = st_fx->frame_ener_fx; - move32(); - } - } - ELSE - { - /* If SID frame was sent, update long-term energy */ - st_fx->lt_ener_last_SID_fx = st_fx->lt_ener_noise_fx; - move32(); - } - st_fx->cnt_SID_fx = add(st_fx->cnt_SID_fx,1); - - IF( st_fx->var_SID_rate_flag_fx ) - { - test(); - test(); - test(); - - if( st_fx->Opt_AMR_WB_fx != 0 && sub(st_fx->max_SID_fx,3) == 0 && sub(st_fx->cnt_SID_fx,3) == 0 ) - { - /* set the size of CNG history buffer for averaging to DTX_HIST_SIZE frames */ - /* be sure that DTX_HIST_SIZE >= INT_L */ - st_fx->cng_hist_size_fx = 3; - move16(); - } - test(); - /*else if ( st_fx->max_SID_fx != 3 && st_fx->cnt_SID_fx == DTX_HIST_SIZE )//compile error */ - if( sub(st_fx->max_SID_fx,3) != 0 && sub(st_fx->cnt_SID_fx,DTX_HIST_SIZE) == 0 ) - { - /* set the size of CNG history buffer for averaging to 3 frames */ - st_fx->cng_hist_size_fx = DTX_HIST_SIZE; - move16(); - } - } - test(); - IF( st_fx->var_SID_rate_flag_fx == 0 && sub(st_fx->interval_SID_fx,1) > 0 ) - { - /* set the size of CNG history buffer for averaging to interval_SID frames */ - st_fx->cng_hist_size_fx = st_fx->interval_SID_fx; - move16(); - if ( sub(st_fx->cng_hist_size_fx, DTX_HIST_SIZE) > 0 ) - { - st_fx->cng_hist_size_fx = DTX_HIST_SIZE; - move16(); - } - } - IF( sub(st_fx->cnt_SID_fx,st_fx->max_SID_fx) >= 0 ) - { - /* adaptive SID update interval */ - st_fx->max_SID_fx = st_fx->interval_SID_fx; - move16(); - st_fx->cnt_SID_fx = 0; - move16(); - } - } - - return; -} - - -void dtx_hangover_control_fx( - Encoder_State_fx *st_fx, /* i/o: encoder state structure */ - const Word16 lsp_new_fx[M] /* i : current frame LSPs */ -) -{ - Word16 ptr; - Word16 i,j,m; - Word16 tmp_lsp[/*max(DTX_HIST_SIZE,*/HO_HIST_SIZE/*)*/*M]; - Word32 tmp_enr[/*max(DTX_HIST_SIZE,*/HO_HIST_SIZE/*)*/]; - Word16 tmp[/*max(DTX_HIST_SIZE,*/HO_HIST_SIZE/*)*/*M]; - Word16 enr_new; - Word16 weights; - Word32 enr_est; - Word16 enr_est_log; - Word16 lsp_est[M]; - Word16 Dlsp,Denr; - Word16 lsf_tmp[M]; - Word32 C[M]; - Word32 max[2]; - Word16 max_idx[2]; - Word16 ftmp_fx; - Word16 Dlsp_n2e,Denr_n2e; - Word16 exp,fra,exp2,fra2; - Word16 S_max; - Word16 S_tmp; - Word32 L_tmp; - - - /* get current frame exc energy in log2 */ - exp = norm_l(st_fx->ho_ener_circ_fx[st_fx->ho_circ_ptr_fx]); - fra = Log2_norm_lc(L_shl(st_fx->ho_ener_circ_fx[st_fx->ho_circ_ptr_fx],exp)); - exp = sub(sub(30,exp),6); - L_tmp = L_Comp(exp,fra); - enr_new = round_fx(L_shl(L_tmp,8)); /*Q8 */ - - if ( enr_new < 0 ) - { - enr_new = 0; - move16(); /*Q8 */ - } - - /* get energies and lsps of hangover frames */ - ptr = sub(st_fx->ho_circ_ptr_fx,sub(st_fx->burst_ho_cnt_fx,1)); - IF ( ptr < 0 ) - { - ptr = add(st_fx->ho_circ_size_fx,ptr); - } - - FOR ( i=0; iburst_ho_cnt_fx-1; i++ ) - { - Copy( &(st_fx->ho_lsp_circ_fx[ptr*M]), &(tmp_lsp[i*M]), M ); - tmp_enr[i] = st_fx->ho_ener_circ_fx[ptr]; - move32();/*Q6 */ - - ptr = add(ptr,1); - if ( sub(ptr,st_fx->ho_circ_size_fx) == 0 ) - { - ptr = 0; - move16(); - } - } - - /* get estimated CNG energy and lsps assuming terminate hangover at current frame */ - ptr = sub(st_fx->burst_ho_cnt_fx,2); - enr_est = Mpy_32_16_1(tmp_enr[ptr],W_DTX_HO_FX[0]); /*Q6 */ - weights = W_DTX_HO_FX[0]; - move16();/*Q15 */ - Copy( &(tmp_lsp[ptr*M]), tmp, M ); - m = 1; - move16(); - - FOR ( i=1; iburst_ho_cnt_fx-2; i++ ) - { - test(); - IF ( L_sub(Mpy_32_16_1(tmp_enr[ptr-i],ONE_OVER_BUF_H_NRG_FX),tmp_enr[ptr]) < 0 && - L_sub(tmp_enr[ptr-i],Mpy_32_16_1(tmp_enr[ptr], BUF_L_NRG_FX)) > 0 ) - { - enr_est = L_add(enr_est,Mpy_32_16_1(tmp_enr[ptr-i],W_DTX_HO_FX[i])); /*Q6 */ - weights = add(weights,W_DTX_HO_FX[i]); /*Q15 */ - Copy( &tmp_lsp[(ptr-i)*M], &tmp[m*M], M ); - m = add(m,1); - } - } - - exp = norm_l(enr_est); - fra = round_fx(L_shl(enr_est,exp)); - exp2 = norm_s(weights); - fra2 = shl(weights,exp2); - exp = sub(sub(exp,16),exp2); - IF ( sub(fra,fra2) > 0 ) - { - fra = shr(fra,1); - exp = sub(exp,1); - } - L_tmp = L_deposit_l(div_s(fra,fra2)); - enr_est = L_shr(L_tmp,exp); /*Q6 */ - - if ( L_sub(enr_est,64) < 0 ) - { - enr_est = 64; - move16();/*Q6 */ - } - - exp = norm_l(enr_est); - fra = Log2_norm_lc(L_shl(enr_est,exp)); - exp = sub(sub(30,exp),6); - L_tmp = L_Comp(exp,fra); - enr_est_log = round_fx(L_shl(L_tmp,8)); /*Q8 */ - Denr_n2e = abs_s(sub(enr_new,enr_est_log)); /*Q8 */ - - IF ( sub(m,3) < 0 ) - { - enr_est = L_add(Mpy_32_16_1(enr_est,26214),Mpy_32_16_1(st_fx->ho_ener_circ_fx[st_fx->ho_circ_ptr_fx],6554)); /*Q6 */ - } - ELSE - { - enr_est = L_add(Mpy_32_16_1(enr_est,31130),Mpy_32_16_1(st_fx->ho_ener_circ_fx[st_fx->ho_circ_ptr_fx],1638)); /*Q6 */ - } - - exp = norm_l(enr_est); - fra = Log2_norm_lc(L_shl(enr_est,exp)); - exp = sub(sub(30,exp),6); - L_tmp = L_Comp(exp,fra); - enr_est_log = round_fx(L_shl(L_tmp,8)); /*Q8 */ - - if ( enr_est_log < 0 ) - { - enr_est_log = 0; - move16(); - } - - set32_fx( max, 0, 2 ); - set16_fx( max_idx, 0, 2 ); - - FOR( i=0; iL_frame_fx,L_FRAME) == 0 ) - { - lsp2lsf_fx( &tmp[i*M], lsf_tmp, M, INT_FS_FX ); - ftmp_fx = 964; - move16();/*QX2.56 */ - S_tmp = sub(16384,add(lsf_tmp[M-1],ftmp_fx)); /*QX2.56 */ - C[i] = L_mult0(S_tmp,S_tmp); /*QX6.5536 */ - } - ELSE - { - lsp2lsf_fx( &tmp[i*M], lsf_tmp, M, INT_FS_16k ); - ftmp_fx = 1205; - move16();/*QX2.56 */ - S_tmp = sub(20480,add(lsf_tmp[M-1],ftmp_fx)); /*QX2.56 */ - C[i] = L_mult0(S_tmp,S_tmp); /*QX6.5536 */ - } - - S_tmp = sub(lsf_tmp[0],ftmp_fx); /*QX2.56 */ - C[i] = L_mac0(C[i],S_tmp,S_tmp); /*QX6.5536 */ - FOR ( j=0; j 0 ) - { - max[1] = max[0]; - move16(); - max_idx[1] = max_idx[0]; - move16(); - max[0] = C[i]; - move16(); - max_idx[0] = i; - move16(); - } - ELSE IF ( L_sub(C[i],max[1]) > 0 ) - { - max[1] = C[i]; - move16(); - max_idx[1] = i; - move16(); - } - } - - IF ( sub(m,1) == 0 ) - { - Copy( tmp, lsp_est, M ); - } - ELSE IF ( sub(m,4) < 0 ) - { - FOR ( i=0; ilspCNG_fx[i],lsp_est[i])); /*Q15 */ - Dlsp = add(Dlsp,S_tmp); /*Q15 */ - IF ( sub(S_tmp,S_max) > 0 ) - { - S_max = S_tmp; /*Q15 */ - } - } - - exp = norm_l(st_fx->lp_ener_fx); - fra = Log2_norm_lc(L_shl(st_fx->lp_ener_fx,exp)); - exp = sub(sub(30,exp),6); - L_tmp = L_Comp(exp,fra); - S_tmp = round_fx(L_shl(L_tmp,8)); /*Q8 */ - Denr = abs_s(sub(S_tmp,enr_est_log)); /*Q8 */ - - /* make decision if DTX hangover can be terminated */ - st_fx->hangover_terminate_flag_fx = 0; - move16(); /*Q0 */ - - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - IF ( ( sub(Dlsp,13107) < 0 && sub(Denr,359) < 0 && sub(S_max,3277) < 0 - && sub(Dlsp_n2e,13107) < 0 && sub(Denr_n2e,308) < 0 && st_fx->Opt_SC_VBR_fx == 1 ) || - ( sub(Dlsp,13107) < 0 && sub(Denr,205) < 0 && sub(S_max,3277) < 0 - && sub(Dlsp_n2e,13107) < 0 && sub(Denr_n2e,205) < 0 && st_fx->Opt_SC_VBR_fx == 0 ) ) - - { - st_fx->hangover_terminate_flag_fx = 1; - move16(); /*Q0 */ - } - - return; -} diff --git a/src/libs/libevs/lib_enc/enc_acelp.cpp b/src/libs/libevs/lib_enc/enc_acelp.cpp old mode 100755 new mode 100644 index fdcfc08e..bdbf03e1 --- a/src/libs/libevs/lib_enc/enc_acelp.cpp +++ b/src/libs/libevs/lib_enc/enc_acelp.cpp @@ -1,20 +1,30 @@ /*==================================================================================== - EVS Codec 3GPP TS26.442 Apr 03, 2018. Version 12.11.0 / 13.6.0 / 14.2.0 + EVS Codec 3GPP TS26.443 Nov 13, 2018. Version 12.11.0 / 13.7.0 / 14.3.0 / 15.1.0 ====================================================================================*/ +#include #include #include -#include "stl.h" -#include "prot_fx.h" +#include "typedef.h" #include "options.h" -#include "basop_util.h" -#include "rom_com_fx.h" -#include "rom_enc_fx.h" +#include "prot.h" +#include "rom_com.h" +#include "rom_enc.h" -#define _2_ 0x4000 /*Q12*/ -#define _1_ 0x2000 /*Q12*/ -#define _1_Q9 0x200 + +/*---------------------------------------------------------------------* +* Local functions +*---------------------------------------------------------------------*/ + +static void E_ACELP_codearithp(const float v[], long unsigned *n, long unsigned *ps, int *p, int trackstep, int tracklen); + +/*---------------------------------------------------------------------* +* Local constants +*---------------------------------------------------------------------*/ + +#define NB_MAX 8 + /* * E_ACELP_h_vec_corrx * @@ -32,90 +42,75 @@ * Returns: * void */ -void E_ACELP_h_vec_corr1(Word16 h[], Word16 vec[], UWord8 track, - Word16 sign[], Word16 (*rrixix)[16], - Word16 cor[], Word16 dn2_pos[], - Word16 nb_pulse) +static void acelp_h_vec_corr1( + Float32 h[], + Float32 vec[], + UWord8 track, + Float32 sign[], + Float32 (*rrixix)[16], + Float32 cor[], + Word16 dn2_pos[], + Word32 nb_pulse +) { Word16 i, j; - Word16 dn, corr; + Word32 dn; Word16 *dn2; - Word16 *p0, *p1, *p2; - Word32 L_sum; + Float32 *p0; + Float32 s; - dn2 = &dn2_pos[shl(track,3)]; + dn2 = &dn2_pos[track * 8]; p0 = rrixix[track]; - - FOR (i = 0; i < nb_pulse; i++) + for (i = 0; i < nb_pulse; i++) { dn = dn2[i]; - move16(); - L_sum = L_deposit_l(0); - p1 = h; - p2 = &vec[dn]; - FOR (j = dn; j < L_SUBFR-1; j++) - L_sum = L_mac(L_sum, *p1++, *p2++); - - corr = mac_r(L_sum, *p1++, *p2++); /*Q9*/ - - /*cor[dn >> 2] = sign[dn] * s + p0[dn >> 2];*/ - j = shr(dn,2); - if(sign[dn] > 0) + s = 0.0F; + /* L_SUBFR-dn */ + /* vec[dn] */ + for (j = 0; j < (L_SUBFR - dn); j++) { - corr = add(p0[j], corr); - } - if(sign[dn] < 0) - { - corr = sub(p0[j], corr); + s += h[j] * vec[dn + j]; } - cor[j] = corr; - move16(); + cor[dn >> 2] = sign[dn] * s + p0[dn >> 2]; } + return; } -void E_ACELP_h_vec_corr2(Word16 h[], Word16 vec[], UWord8 track, - Word16 sign[], Word16 (*rrixix)[16], - Word16 cor[]) +static void acelp_h_vec_corr2( + Float32 h[], + Float32 vec[], + UWord8 track, + Float32 sign[], + Float32 (*rrixix)[16], + Float32 cor[]) { - Word16 i, j, pos, corr; - Word16 *p0, *p1, *p2; - Word32 L_sum; + Word32 i, j; + Float32 *p0; + Float32 s; + p0 = rrixix[track]; - - pos = track; - move16(); - FOR (i = 0; i < 16; i++) + /* sign[track] */ + for (i = 0; i < 16; i++) { - L_sum = L_deposit_l(0); - p1 = h; - p2 = &vec[pos]; - FOR (j = pos; j < L_SUBFR-1; j++) - L_sum = L_mac(L_sum, *p1++, *p2++); - - corr = mac_r(L_sum, *p1++, *p2++); /*Q9*/ - - /*cor[i] = s * sign[track] + p0[i];*/ - - if(sign[pos] > 0) + s = 0.0F; + /* h[0], vec[track] */ + /* L_SUBFR-track */ + for (j = 0; j < L_SUBFR - track; j++) { - corr = add(*p0++, corr); + s += h[j] * vec[track + j]; } - if(sign[pos] < 0) - { - corr = sub(*p0++, corr); - } - cor[i] = corr; - move16(); - pos = add(pos,4); + cor[i] = s * sign[track] + p0[i]; + track += 4; } + return; } /* - * E_ACELP_2pulse_search + * acelp_2pulse_search * * Parameters: * nb_pos_ix I: nb of pos for pulse 1 (1..8) @@ -137,110 +132,71 @@ void E_ACELP_h_vec_corr2(Word16 h[], Word16 vec[], UWord8 track, * Returns: * void */ -static void E_ACELP_2pulse_search(Word16 nb_pos_ix, UWord8 track_x, - UWord8 track_y, Word16 *ps, Word16 *alp, - Word16 *ix, Word16 *iy, Word16 dn[], - Word16 *dn2, Word16 cor_x[], - Word16 cor_y[], Word16 (*rrixiy)[256]) +static void acelp_2pulse_search( Word32 nb_pos_ix, UWord8 track_x, + UWord8 track_y, Float32 *ps, Float32 *alp, + Word16 *ix, Word16 *iy, Float32 dn[], + Word16 *dn2, Float32 cor_x[], + Float32 cor_y[], Float32 (*rrixiy)[256]) { - Word16 x, x2, y, i, *pos_x; - Word16 ps0, ps1, alp2_16, ps2, sq; - Word32 alp0, alp1, alp2, s; - Word16 *p1, *p2; - Word16 sqk[2], alpk[2], ik; - Word32 xy_save; - Word16 check = 0; /* debug code not instrumented */ - + Word16 x, x2, y, x_save = 0, y_save = 0, i, *pos_x; + Float32 ps0, alp0; + Float32 ps1, ps2, sq, sqk; + Float32 alp1, alp2, alpk; + Float32 *p1, *p2; + Float32 s; + /* x_save=y_save=0 */ /* eight dn2 max positions per track */ - /*pos_x = &dn2[track_x << 3]; SHIFT(1); PTR_INIT(1);*/ - pos_x = &dn2[shl(track_x, 3)]; - move16(); - + pos_x = &dn2[track_x << 3]; /* save these to limit memory searches */ - alp0 = L_deposit_h(*alp); ps0 = *ps; - move16(); + alp0 = *alp; - alpk[0] = 1; - move16(); - sqk[0] = -1; - move16(); - x2 = shr(pos_x[0], 2); - if (mac_r(L_mac(L_mac(alp0, cor_x[x2], _1_), cor_y[0], _1_), rrixiy[track_x][shl(x2,4)], _1_) < 0) + alpk = 1.0F; + sqk = -1.0F; + x2 = pos_x[0] >> 2; + if( (alp0 + cor_x[x2] + cor_y[0] + rrixiy[track_x][x2 << 4]) < 0 ) { - sqk[0] = 1; - move16(); + sqk = 1.0F; } - ik = 0; - move16(); - xy_save = L_mac0(L_deposit_l(track_y), track_x, L_SUBFR); /* loop track 1 */ - FOR (i = 0; i < nb_pos_ix; i++) + for (i = 0; i < nb_pos_ix; i++) { x = pos_x[i]; - move16(); - x2 = shr(x, 2); + x2 = x >> 2; /* dn[x] has only nb_pos_ix positions saved */ - /*ps1 = ps0 + dn[x];*/ - ps1 = add(ps0, dn[x]); - - /*alp1 = alp0 + cor_x[x2];*/ - alp1 = L_mac(alp0, cor_x[x2], _1_); /*Q22*/ - + ps1 = ps0 + dn[x]; + alp1 = alp0 + cor_x[x2]; p1 = cor_y; - p2 = &rrixiy[track_x][shl(x2,4)]; - - FOR (y = track_y; y < L_SUBFR; y += 4) + p2 = &rrixiy[track_x][x2 << 4]; + for (y = track_y; y < L_SUBFR; y += 4) { - /*ps2 = ps1 + dn[y];*/ - ps2 = add(ps1, dn[y]); + ps2 = ps1 + dn[y]; + alp2 = alp1 + (*p1++) + (*p2++); - /*alp2 = alp1 + (*p1++) + (*p2++);*/ - alp2 = L_mac(alp1, *p1++, _1_); - alp2_16 = mac_r(alp2, *p2++, _1_); /*Q6*/ - alpk[1-ik] = alp2_16; - move16(); + sq = ps2 * ps2; - /*sq = ps2 * ps2;*/ - sq = mult(ps2, ps2); - sqk[1-ik] = sq; - move16(); + s = (alpk * sq) - (sqk * alp2); - /*s = (alpk[ik] * sq) - (sqk[0] * alp2);*/ - s = L_msu(L_mult(alpk[ik], sq), sqk[ik], alp2_16); /*Q16*/ - - if (s > 0) + if (s > 0.0F) { - ik = sub(1, ik); - check = 1; /* debug code not instrumented */ - } - if (s > 0) - { - xy_save = L_mac0(y, x, L_SUBFR); + sqk = sq; + alpk = alp2; + y_save = y; + x_save = x; } } } - assert(check); /* debug code not instrumented */ - - ps2 = extract_l(xy_save); - *iy = s_and(ps2, L_SUBFR-1); - move16(); - *ix = lshr(ps2, 6); - move16(); - - /**ps = ps0 + dn[*ix] + dn[*iy];*/ - *ps = add(ps0, add(dn[*ix], dn[*iy])); - move16(); - - *alp = alpk[ik]; - move16(); + *ps = ps0 + dn[x_save] + dn[y_save]; + *alp = alpk; + *ix = x_save; + *iy = y_save; + return; } - /* * E_ACELP_1pulse_search * @@ -260,426 +216,79 @@ static void E_ACELP_2pulse_search(Word16 nb_pos_ix, UWord8 track_x, * Returns: * void */ -static void E_ACELP_1pulse_search(UWord8 tracks[2], - Word16 *ps, - Word16 *alp, +static void E_ACELP_1pulse_search(UWord8 track_x, + UWord8 track_y, + Float32 *ps, + Float32 *alp, Word16 *ix, - Word16 dn[], - Word16 cor_x[], - Word16 cor_y[]) + Float32 dn[], + Float32 cor_x[], + Float32 cor_y[]) { Word16 x, x_save = 0; - Word16 ps0; - Word16 ps1, sq; - Word16 alp1; - Word32 s, alp0; - Word16 sqk[2], alpk[2], ik; - Word16 ntracks, t; - Word16 check = 0; /* debug code not instrumented */ + Float32 ps0, alp0; + Float32 ps1, sq, sqk; + Float32 alp1, alpk; + Float32 s; /* save these to limit memory searches */ - alp0 = L_deposit_h(*alp); ps0 = *ps; - move16(); + alp0 = *alp; + alpk = 1.0F; + sqk = -1.0F; - alpk[0] = 1; - move16(); - sqk[0] = -1; - move16(); - if (mac_r(alp0, cor_x[shr(tracks[0],2)], _1_) < 0) + if ( (alp0 + cor_x[(track_x >> 2)]) < 0) { - sqk[0] = 1; - move16(); + sqk = 1.0F; } - ik = 0; - move16(); + for (x = track_x; x < L_SUBFR; x += 4) + { + ps1 = ps0 + dn[x]; + alp1 = alp0 + cor_x[x>>2]; + sq = ps1 * ps1; + s = (alpk * sq) - (sqk * alp1); - ntracks = 1; - if (sub(tracks[1], tracks[0]) != 0) - { - ntracks = 2; - move16(); - } - FOR (t=0; t 0.0F) { - cor_x = cor_y; - move16(); + sqk = sq; + alpk = alp1; + x_save = x; } - FOR (x = tracks[t]; x < L_SUBFR; x += 4) + } + if(track_y!=track_x) + { + for (x = track_y; x < L_SUBFR; x += 4) { - /*ps1 = ps0 + dn[x]; ADD(1);*/ - ps1 = add(ps0, dn[x]); + ps1 = ps0 + dn[x]; + alp1 = alp0 + cor_y[x>>2]; + sq = ps1 * ps1; + s = (alpk * sq) - (sqk * alp1); - /*alp1 = alp0 + cor_x[x>>2]; SHIFT(1);ADD(1);*/ - alp1 = mac_r(alp0, cor_x[shr(x,2)], _1_); /*Q6*/ - alpk[1-ik] = alp1; - move16(); - - /*sq = ps1 * ps1; MULT(1);*/ - sq = mult(ps1, ps1); - sqk[1-ik] = sq; - move16(); - - /*s = (alpk * sq) - (sqk * alp1); MULT(1);MAC(1); */ - s = L_msu(L_mult(alpk[ik], sq), sqk[ik], alp1);/*Q16*/ - - if (s > 0) - { - ik = sub(1, ik); - check = 1; /* debug code not instrumented */ - } - if (s > 0) + if (s > 0.0F) { + sqk = sq; + alpk = alp1; x_save = x; - move16(); } } - - assert( check ); /* debug code not instrumented */ } - *ps = add(ps0, dn[x_save]); - move16(); - *alp = alpk[ik]; - move16(); + + *ps = ps0 + dn[x_save]; + *alp = alpk; *ix = x_save; - move16(); -} - -/* - * E_ACELP_xh_corr - * - * Parameters: - * h I: impulse response (of weighted synthesis filter) (Q12) - * x I: target signal (Q0) - * y O: correlation between x[] and h[] <12b - * - * Function: - * Compute the correlation between the target signal and the impulse - * response of the weighted synthesis filter. - * - * y[i]=sum(j=i,l-1) x[j]*h[j-i], i=0,l-1 - * - * Vector size is L_SUBFR - * - * Returns: - * void - */ -static void E_ACELP_xh_corr(Word16 *x, Word16 *y, Word16 *h, Word16 L_subfr) -{ - Word16 i, j,k; - Word32 L_tmp, y32[L_SUBFR16k], L_maxloc, L_tot; - - assert(L_subfr <= L_SUBFR16k); - - /* first keep the result on 32 bits and find absolute maximum */ - L_tot = L_deposit_l(1); - - FOR (k = 0; k < 4; k++) - { - L_maxloc = L_deposit_l(0); - FOR (i = k; i < L_subfr; i += 4) - { - L_tmp = L_mac0(1L, x[i], h[0]); /* 1 -> to avoid null dn[] */ - FOR (j = i; j < L_subfr-1; j++) - { - L_tmp = L_mac0(L_tmp, x[j+1], h[j+1 - i]); - } - - y32[i] = L_tmp; - move32(); - L_tmp = L_abs(L_tmp); - L_maxloc = L_max(L_tmp, L_maxloc); - } - /* tot += 3*max / 8 */ - L_maxloc = L_shr(L_maxloc, 2); - /* Do not warn saturation of L_tot, since its for headroom estimation. */ - BASOP_SATURATE_WARNING_OFF - L_tot = L_add(L_tot, L_maxloc); /* +max/4 */ - L_tot = L_add(L_tot, L_shr(L_maxloc, 1)); /* +max/8 */ - BASOP_SATURATE_WARNING_ON - } - - /* Find the number of right shifts to do on y32[] so that */ - /* 6.0 x sumation of max of dn[] in each track not saturate. */ - - j = sub(norm_l(L_tot), 4+16); /* 4 -> 16 x tot */ - - Copy_Scale_sig_32_16(y32, y, L_subfr, j); -} - -/** - * \brief calculate autocorrelation of vector x - * \param x input vector 4Q11 - * \param y output (autocorrelation coefficients) - * \param L_subfr length of x (and y) - * \param bits amount of target headroom bits for y - * \return exponent of y - */ -Word16 E_ACELP_hh_corr(Word16 *x, Word16 *y, Word16 L_subfr, Word16 bits) -{ - Word16 i, j, k = 0; /* initialize just to avoid compiler warning */ - Word32 L_tmp, L_sum; - - FOR (i = 0; i < L_subfr-1; i++) - { - L_tmp = L_mult0( x[i], x[0] ); - FOR (j = i+2; j < L_subfr; j+=2) - { - L_tmp = L_mac0( L_tmp, x[j], x[j-i] ); - } - L_sum = L_shr( L_tmp, 1 ); - - L_tmp = L_mult0( x[i+1], x[1] ); - FOR (j = i+3; j < L_subfr; j+=2) - { - L_tmp = L_mac0( L_tmp, x[j], x[j-i] ); - } - L_sum = L_add( L_sum, L_shr( L_tmp, 1 ) ); - - if (i == 0) - { - k = norm_l(L_sum); - } - if (i == 0) - { - k = sub(k, bits); - } - - y[i] = round_fx( L_shl( L_sum, k ) ); - } - - L_tmp = L_mult0( x[i], x[0] ); - L_sum = L_shr( L_tmp, 1 ); - y[i] = round_fx( L_shl( L_sum, k ) ); - - k = add(1, k); - - return k; -} - -/* - * E_ACELP_xy1_corr - * - * Parameters: - * xn I: target signal - * y1 I: filtered adaptive codebook excitation - * g_coeff O: correlations and -2 - * norm_flag I: flag to trigger normalization of the result - * L_subfr I: length of data - * exp_xn I: common exponent of xn[] and y1[] - * - * Function: - * Find the correlations between the target xn[] and the filtered adaptive - * codebook excitation y1[]. ( and -2 ) - * Subframe size = L_SUBFR - * - * Returns: - * pitch gain (0 ... 1.2F) (Q14) - */ -Word16 E_ACELP_xy1_corr(Word16 xn[], Word16 y1[], ACELP_CbkCorr *g_corr, Word16 norm_flag, Word16 L_subfr, Word16 exp_xn) -{ - Word16 i, Q_xn; - Word16 xy, yy, exp_xy, exp_yy, gain; - Word32 L_off; - - L_off = L_shr(10737418l/*0.01f/2.0f Q31*/, s_min(add(exp_xn,exp_xn), 31)); - L_off = L_max(1,L_off); /* ensure at least a '1' */ - - /* Compute scalar product t1: */ - yy = round_fx(Dot_product15_offs(y1, y1, L_subfr, &exp_yy, L_off)); - - /* Compute scalar product t0: */ - xy = round_fx(Dot_product12_offs(xn, y1, L_subfr, &exp_xy, L_off)); - - /* Compute doubled format out of the exponent */ - Q_xn = shl(sub(15,exp_xn),1); - g_corr->y1y1 = yy; - move16(); - g_corr->y1y1_e = sub(exp_yy, Q_xn); - move16(); - g_corr->xy1 = xy; - move16(); - g_corr->xy1_e = sub(exp_xy, Q_xn); - move16(); - - /* If (xy < 0) gain = 0 */ - IF (xy < 0) - { - move16(); - gain = 0; - GOTO bail; - } - - /* compute gain = xy/yy */ - - xy = mult_r(xy,0x4000); /* Be sure xy < yy */ - gain = div_s(xy, yy); - - i = add(exp_xy, 1 - 1); /* -1 -> gain in Q14 */ - i = sub(i, exp_yy); - BASOP_SATURATE_WARNING_OFF - gain = shl(gain, i); /* saturation can occur here */ - BASOP_SATURATE_WARNING_ON - /* gain = s_max(0, gain); */ /* see above xy < 0. */ - - /* if (gain > 1.2) gain = 1.2 in Q14 */ - - gain = s_min(19661/*1.2f Q14*/ /* 19661 */, gain); - - /*Limit the energy of pitch contribution*/ - IF (norm_flag) - { - Word16 tmp, exp_tmp, exp_div; - - /* Compute scalar product */ - tmp = round_fx(Dot_product12_offs(xn, xn, L_subfr, &exp_tmp, 1)); - /* gain_p_snr = sqrt(/) */ - tmp = BASOP_Util_Divide1616_Scale(tmp, yy, &exp_div); - exp_tmp = add(sub(exp_tmp, exp_yy), exp_div); - - tmp = Sqrt16(tmp, &exp_tmp); - - /* Note: shl works as shl or shr. */ - exp_tmp = sub(exp_tmp,1); - BASOP_SATURATE_WARNING_OFF - tmp = round_fx(L_shl(Mpy_32_16_1( 1717986944l/*ACELP_GAINS_CONST Q31*/, tmp), exp_tmp)); - BASOP_SATURATE_WARNING_ON - - gain = s_min(gain, tmp); - } - -bail: - - - return (gain); -} - -/* - * E_ACELP_xy2_corr - * - * Parameters: - * xn I: target signal in Q_xn - * y1 I: filtered adaptive codebook excitation in Q_xn - * y2 I: filtered fixed codebook excitation in Q9 - * g_corr O: correlations , -2, 2 - * L_subfr I: subframe size - * - * Function: - * Find the correlations between the target xn[], the filtered adaptive - * codebook exc. y1[], and the filtered fixed codebook innovation y2[]. - * ( , -2 and 2 ) - * Subrame size = L_SUBFR - * - * Returns: - * pitch gain (0 ... 1.2F) - */ -void E_ACELP_xy2_corr(Word16 xn[], Word16 y1[], Word16 y2[], - ACELP_CbkCorr *g_corr, Word16 L_subfr, Word16 exp_xn) -{ - Word16 xny2, y2y2, y1y2, xx, exp_xny2, exp_y2y2, exp_y1y2, exp_xx; - Word32 L_off; - - BASOP_SATURATE_ERROR_ON; - - /* Compute scalar product */ - y2y2 = extract_h(Dot_product15_offs(y2, y2, L_subfr, &exp_y2y2, 5243l/*0.01f Q19*/)); - - /* L_off = 1L; */ - L_off = L_shr(10737418l/*0.01f/2.0f Q31*/, sub(30-9, exp_xn)); - - /* Compute scalar product */ - xny2 = extract_h(Dot_product12_offs(xn, y2, L_subfr, &exp_xny2, L_off)); - - /* Compute scalar product */ - y1y2 = extract_h(Dot_product12_offs(y1, y2, L_subfr, &exp_y1y2, L_off)); - - /* Compute scalar product */ - L_off = L_shr(21474836l/*0.01f Q31*/, s_min(31, sub(30, shl(exp_xn, 1)))); - xx = extract_h(Dot_product12_offs(xn, xn, L_subfr, &exp_xx, L_off)); - - - g_corr->y2y2 = y2y2; - move16(); - g_corr->y2y2_e = exp_y2y2; - move16(); - g_corr->xy2 = xny2; - move16(); - g_corr->xy2_e = exp_xny2; - move16(); - g_corr->y1y2 = y1y2; - move16(); - g_corr->y1y2_e = exp_y1y2; - move16(); - g_corr->xx = xx; - move16(); - g_corr->xx_e = exp_xx; - move16(); - - - BASOP_SATURATE_ERROR_OFF; -} - - - -/* - * E_ACELP_codebook_target_update - * - * Parameters: - * x I: old target (for pitch search) (Q_xn) - * x2 O: new target (for codebook search) (Q_xn) - * y I: filtered adaptive codebook vector (Q_xn) - * gain I: adaptive codebook gain (Q14) - * - * Function: - * Update the target vector for codebook search. - * Subframe size = L_SUBFR - * Returns: - * void - */ -void E_ACELP_codebook_target_update(Word16 *x, Word16 *x2, Word16 *y, - Word16 gain, Word16 L_subfr) -{ - Word16 i, Q15_flag; - Word32 L_tmp; - - assert(gain >= 0); - - Q15_flag = 0; - move16(); - if (sub(gain, 1<<14) < 0) - { - Q15_flag = 1; - move16(); - } - gain = shl(gain, Q15_flag); - - FOR (i = 0; i < L_subfr; i++) - { - L_tmp = L_deposit_h(x[i]); - if (Q15_flag == 0) - { - L_tmp = L_msu(L_tmp, y[i], gain); - } - x2[i] = msu_r(L_tmp, y[i], gain); - move16(); - } + return; } /* - * E_ACELP_pulsesign + * acelp_pulsesign * * Parameters: - * cn I: residual after long term prediction <12b - * dn I: corr. between target and h[]. <12b - * dn2 I/O: dn2[] = mix of dn[] and cn[] - * sign O: sign of pulse 0 or -1 + * cn I: residual after Word32 term prediction + * dn I: corr. between target and h[]. + * dn2 O: dn2[] = mix of dn[] and cn[] + * sign O: sign of pulse * vec O: negative sign of pulse - * alp I: energy of all fixed pulses Q13 - * sign_val I: value for signs - * L_subfr I: subframe length * * Function: * Determine sign of each pulse position, store them in "sign" @@ -688,166 +297,94 @@ void E_ACELP_codebook_target_update(Word16 *x, Word16 *x2, Word16 *y, * Returns: * void */ -void E_ACELP_pulsesign(const Word16 cn[], Word16 dn[], Word16 dn2[], Word16 sign[], Word16 vec[], const Word16 alp, const Word16 sign_val, const Word16 L_subfr) +void acelp_pulsesign( + const float cn[], + float dn[], + float dn2[], + float sign[], + float vec[], + float alp +) { - Word16 i; - Word32 Lval, Lcor; - Word16 k_cn, k_dn, sign_neg, e_dn, e_cn; - Word16 signs[3]; - Word16 *ptr16; - Word16 val, index; - + int i; + float val; + float s, cor; /* calculate energy for normalization of cn[] and dn[] */ - Lval = L_mac0(1, cn[0], cn[0]); - Lcor = L_mac0(1, dn[0], dn[0]); - - FOR (i = 1; i < L_subfr; i++) + val = (cn[0] * cn[0]) + 1.0F; + cor = (dn[0] * dn[0]) + 1.0F; + for (i = 1; i < L_SUBFR; i ++) { - Lval = L_mac0(Lval, cn[i], cn[i]); - Lcor = L_mac0(Lcor, dn[i], dn[i]); + val += (cn[i] * cn[i]); + cor += (dn[i] * dn[i]); } - e_dn = 31; - move16(); - e_cn = 31; - move16(); - - Lval = Sqrt32(Lval, &e_dn); - Lcor = Sqrt32(Lcor, &e_cn); - i = sub(e_dn,e_cn); - if(i < 0) - Lval = L_shl(Lval, i); - if(i > 0) - Lcor = L_shr(Lcor, i); - - k_dn = round_fx(Lval); - k_cn = round_fx(Lcor); - - k_cn = mult_r(0x2000, k_cn); /* 1 in Q13 */ - k_dn = mult_r(alp, k_dn); /* alp in Q13 */ - - sign_neg = negate(sign_val); - - signs[0] = sign_neg; - move16(); - signs[1] = sign_val; - move16(); - signs[2] = sign_neg; - move16(); - ptr16 = &signs[1]; - - FOR (i = 0; i < L_subfr; i++) + s = (float)sqrt(cor / val); + for (i = 0; i < L_SUBFR; i++) { - /*cor = (s * cn[i]) + (alp * dn[i]); MULT(1);MAC(1);*/ - Lcor = L_mult(cn[i], k_cn); - Lcor = L_mac(Lcor, dn[i], k_dn); - val = round_fx(L_shl(Lcor,4)); /*shifting by 4 may overflow but improves accuracy*/ - - index = shr(val, 15); - sign[i] = ptr16[index]; - move16(); /* yields -1 (when ps < 0) or 0 (when ps >= 0) */ - vec[i] = ptr16[index+1]; - move16(); - - if (val < 0) + cor = (s * cn[i]) + (alp * dn[i]); + if (cor >= 0.0F) { - dn[i] = negate(dn[i]); - move16(); + sign[i] = 1.0F; + vec[i] = -1.0F; + dn2[i] = cor; /* dn2[] = mix of dn[] and cn[] */ + } + else + { + sign[i] = -1.0F; + vec[i] = 1.0F; + dn[i] = -dn[i]; /* modify dn[] according to the fixed sign */ + dn2[i] = -cor; /* dn2[] = mix of dn[] and cn[] */ } - dn2[i] = abs_s(val); - move16(); /* dn2[] = mix of dn[] and cn[] */ } + return; } - -void E_ACELP_findcandidates(Word16 dn2[], Word16 dn2_pos[], Word16 pos_max[]) +void acelp_findcandidates(float dn2[], short dn2_pos[], short pos_max[], int L_subfr, int tracks) { - Word16 i, k, j, i8; - Word16 *ps_ptr; - - FOR (i = 0; i < 4; i++) + int i,k,j; + float *ps_ptr; + /* &pos_max[0], &dn2_pos[0] */ + for (i = 0; i < tracks; i++) { - i8 = shl(i, 3); - FOR (k = i8; k < i8+8; k++) + for (k = 0; k < NB_MAX; k++) { ps_ptr = &dn2[i]; - - FOR (j = i+4; j < L_SUBFR; j += 4) + for (j = i+tracks; j < L_subfr; j += tracks) { - if (sub(dn2[j], *ps_ptr) > 0) + if (dn2[j] > *ps_ptr) { ps_ptr = &dn2[j]; - move16(); } } - - *ps_ptr = -1; /* dn2 < 0 when position is selected */ move16(); - dn2_pos[k] = (Word16)(ps_ptr - dn2); - move16(); + *ps_ptr = (float)k - NB_MAX; /* dn2 < 0 when position is selected */ + dn2_pos[i * 8 + k] = ps_ptr - dn2; } - pos_max[i] = dn2_pos[i8]; - move16(); + pos_max[i] = dn2_pos[i * 8]; } } - -static void E_ACELP_apply_sign(Word16 *p0, Word16 *psign0) +static void acelp_hbuf(float *h_buf, float **h, float **h_inv, const float *H) { - p0[0] = mult_r( p0[0] , psign0[ 0]); - move16(); - p0[1] = mult_r( p0[1] , psign0[ 4]); - move16(); - p0[2] = mult_r( p0[2] , psign0[ 8]); - move16(); - p0[3] = mult_r( p0[3] , psign0[12]); - move16(); - p0[4] = mult_r( p0[4] , psign0[16]); - move16(); - p0[5] = mult_r( p0[5] , psign0[20]); - move16(); - p0[6] = mult_r( p0[6] , psign0[24]); - move16(); - p0[7] = mult_r( p0[7] , psign0[28]); - move16(); - p0[8] = mult_r( p0[8] , psign0[32]); - move16(); - p0[9] = mult_r( p0[9] , psign0[36]); - move16(); - p0[10] = mult_r( p0[10] , psign0[40]); - move16(); - p0[11] = mult_r( p0[11] , psign0[44]); - move16(); - p0[12] = mult_r( p0[12] , psign0[48]); - move16(); - p0[13] = mult_r( p0[13] , psign0[52]); - move16(); - p0[14] = mult_r( p0[14] , psign0[56]); - move16(); - p0[15] = mult_r( p0[15] , psign0[60]); - move16(); -} - -void E_ACELP_vec_neg(Word16 h[], Word16 h_inv[], Word16 L_subfr) -{ - Word16 i; - - FOR(i = 0; i < L_subfr; i ++) + int i; + *h = h_buf + L_SUBFR; + *h_inv = h_buf + (3*L_SUBFR); + for (i=0; i i3i3, i2i2, i1i1, i0i0 */ /* Init pointers to last position of rrixix[] */ - p0 = &rrixix[0][16 - 1]; /* Q9 */ + p0 = &rrixix[0][16 - 1]; p1 = &rrixix[1][16 - 1]; p2 = &rrixix[2][16 - 1]; p3 = &rrixix[3][16 - 1]; ptr_h1 = h; - cor = L_deposit_l(0); - FOR (i = 0; i < 16; i++) + cor = 0.0F; + for(i = 0; i < 16; i++) { - cor = L_mac(cor, *ptr_h1, *ptr_h1); + cor += (*ptr_h1) * (*ptr_h1); ptr_h1++; - *p3-- = round_fx(L_shr(cor, 1)); - cor = L_mac(cor, *ptr_h1, *ptr_h1); + *p3-- = cor * 0.5F; + cor += (*ptr_h1) * (*ptr_h1); ptr_h1++; - *p2-- = round_fx(L_shr(cor, 1)); - cor = L_mac(cor, *ptr_h1, *ptr_h1); + *p2-- = cor * 0.5F; + cor += (*ptr_h1) * (*ptr_h1); ptr_h1++; - *p1-- = round_fx(L_shr(cor, 1)); - cor = L_mac(cor, *ptr_h1, *ptr_h1); + *p1-- = cor * 0.5F; + cor += (*ptr_h1) * (*ptr_h1); ptr_h1++; - *p0-- = round_fx(L_shr(cor, 1)); /* Q9 */ + *p0-- = cor * 0.5F; } @@ -887,39 +424,54 @@ void E_ACELP_corrmatrix(Word16 h[], Word16 sign[], Word16 vec[], Word16 rrixix[4 pos = 256 - 1; ptr_hf = h + 1; - FOR (k = 0; k < 16; k++) + for(k = 0; k < 16; k++) { + p3 = &rrixiy[2][pos]; p2 = &rrixiy[1][pos]; p1 = &rrixiy[0][pos]; p0 = &rrixiy[3][pos - 16]; - cor = L_deposit_h(0); + cor = 0.0F; ptr_h1 = h; ptr_h2 = ptr_hf; - - FOR (i = k; i < 16-1; i++) + for(i = k; i < 15; i++) { - cor = L_mac(cor, *ptr_h1++, *ptr_h2++); - *p3 = round_fx(cor); - cor = L_mac(cor, *ptr_h1++, *ptr_h2++); - *p2 = round_fx(cor); - cor = L_mac(cor, *ptr_h1++, *ptr_h2++); - *p1 = round_fx(cor); - cor = L_mac(cor, *ptr_h1++, *ptr_h2++); - *p0 = round_fx(cor); + cor += (*ptr_h1) * (*ptr_h2); + ptr_h1++; + ptr_h2++; + *p3 = cor; + cor += (*ptr_h1) * (*ptr_h2); + ptr_h1++; + ptr_h2++; + *p2 = cor; + cor += (*ptr_h1) * (*ptr_h2); + ptr_h1++; + ptr_h2++; + *p1 = cor; + cor += (*ptr_h1) * (*ptr_h2); + ptr_h1++; + ptr_h2++; + *p0 = cor; p3 -= (16 + 1); p2 -= (16 + 1); p1 -= (16 + 1); p0 -= (16 + 1); } - cor = L_mac(cor, *ptr_h1++, *ptr_h2++); - *p3 = round_fx(cor); - cor = L_mac(cor, *ptr_h1++, *ptr_h2++); - *p2 = round_fx(cor); - cor = L_mac(cor, *ptr_h1++, *ptr_h2++); - *p1 = round_fx(cor); + + cor += (*ptr_h1) * (*ptr_h2); + ptr_h1++; + ptr_h2++; + *p3 = cor; + cor += (*ptr_h1) * (*ptr_h2); + ptr_h1++; + ptr_h2++; + *p2 = cor; + cor += (*ptr_h1) * (*ptr_h2); + ptr_h1++; + ptr_h2++; + *p1 = cor; pos -= 16; ptr_hf += 4; @@ -929,34 +481,44 @@ void E_ACELP_corrmatrix(Word16 h[], Word16 sign[], Word16 vec[], Word16 rrixix[4 pos = 256 - 1; ptr_hf = h + 3; - FOR (k = 0; k < 16; k++) + for(k = 0; k < 16; k++) { + p3 = &rrixiy[3][pos]; p2 = &rrixiy[2][pos - 1]; p1 = &rrixiy[1][pos - 1]; p0 = &rrixiy[0][pos - 1]; - cor = L_deposit_h(0); + cor = 0.0F; ptr_h1 = h; ptr_h2 = ptr_hf; - FOR (i = k; i < 16-1; i++) + for(i= k + 1; i < 16; i++ ) { - cor = L_mac(cor, *ptr_h1++, *ptr_h2++); - *p3 = round_fx(cor); - cor = L_mac(cor, *ptr_h1++, *ptr_h2++); - *p2 = round_fx(cor); - cor = L_mac(cor, *ptr_h1++, *ptr_h2++); - *p1 = round_fx(cor); - cor = L_mac(cor, *ptr_h1++, *ptr_h2++); - *p0 = round_fx(cor); + cor += (*ptr_h1) * (*ptr_h2); + ptr_h1++; + ptr_h2++; + *p3 = cor; + cor += (*ptr_h1) * (*ptr_h2); + ptr_h1++; + ptr_h2++; + *p2 = cor; + cor += (*ptr_h1) * (*ptr_h2); + ptr_h1++; + ptr_h2++; + *p1 = cor; + cor += (*ptr_h1) * (*ptr_h2); + ptr_h1++; + ptr_h2++; + *p0 = cor; p3 -= (16 + 1); p2 -= (16 + 1); p1 -= (16 + 1); p0 -= (16 + 1); } - cor = L_mac(cor, *ptr_h1++, *ptr_h2++); - *p3 = round_fx(cor); + + cor += (*ptr_h1) * (*ptr_h2); + *p3 = cor; pos--; ptr_hf += 4; @@ -967,122 +529,143 @@ void E_ACELP_corrmatrix(Word16 h[], Word16 sign[], Word16 vec[], Word16 rrixix[4 */ p0 = &rrixiy[0][0]; - /* speed-up: 11% */ p1 = &rrixiy[1][0]; p2 = &rrixiy[2][0]; p3 = &rrixiy[3][0]; - - FOR(i = 0; i < L_SUBFR; i += 4) + for(i = 0; i < L_SUBFR; i += 4) { - - psign0 = &vec[1]; - if (sign[i+0] > 0 ) psign0 = &sign[1]; - - psign1 = &vec[2]; - if (sign[i+1] > 0 ) psign1 = &sign[2]; - - psign2 = &vec[3]; - if (sign[i+2] > 0 ) psign2 = &sign[3]; - - psign3 = &vec[0]; - if (sign[i+3] > 0 ) psign3 = &sign[0]; - - E_ACELP_apply_sign(p0, psign0); + if (sign[i+0] < 0.0F) psign0 = &vec[1]; + else psign0 = &sign[1]; + if (sign[i+1] < 0.0F) psign1 = &vec[2]; + else psign1 = &sign[2]; + if (sign[i+2] < 0.0F) psign2 = &vec[3]; + else psign2 = &sign[3]; + if (sign[i+3] < 0.0F) psign3 = &vec[0]; + else psign3 = &sign[0]; + p0[0] = p0[0] * psign0[ 0]; + p0[1] = p0[1] * psign0[ 4]; + p0[2] = p0[2] * psign0[ 8]; + p0[3] = p0[3] * psign0[12]; + p0[4] = p0[4] * psign0[16]; + p0[5] = p0[5] * psign0[20]; + p0[6] = p0[6] * psign0[24]; + p0[7] = p0[7] * psign0[28]; + p0[8] = p0[8] * psign0[32]; + p0[9] = p0[9] * psign0[36]; + p0[10] = p0[10] * psign0[40]; + p0[11] = p0[11] * psign0[44]; + p0[12] = p0[12] * psign0[48]; + p0[13] = p0[13] * psign0[52]; + p0[14] = p0[14] * psign0[56]; + p0[15] = p0[15] * psign0[60]; p0 += 16; - E_ACELP_apply_sign(p1, psign1); + p1[0] = p1[0] * psign1[ 0]; + p1[1] = p1[1] * psign1[ 4]; + p1[2] = p1[2] * psign1[ 8]; + p1[3] = p1[3] * psign1[12]; + p1[4] = p1[4] * psign1[16]; + p1[5] = p1[5] * psign1[20]; + p1[6] = p1[6] * psign1[24]; + p1[7] = p1[7] * psign1[28]; + p1[8] = p1[8] * psign1[32]; + p1[9] = p1[9] * psign1[36]; + p1[10] = p1[10] * psign1[40]; + p1[11] = p1[11] * psign1[44]; + p1[12] = p1[12] * psign1[48]; + p1[13] = p1[13] * psign1[52]; + p1[14] = p1[14] * psign1[56]; + p1[15] = p1[15] * psign1[60]; p1 += 16; - E_ACELP_apply_sign(p2, psign2); + p2[0] = p2[0] * psign2[ 0]; + p2[1] = p2[1] * psign2[ 4]; + p2[2] = p2[2] * psign2[ 8]; + p2[3] = p2[3] * psign2[12]; + p2[4] = p2[4] * psign2[16]; + p2[5] = p2[5] * psign2[20]; + p2[6] = p2[6] * psign2[24]; + p2[7] = p2[7] * psign2[28]; + p2[8] = p2[8] * psign2[32]; + p2[9] = p2[9] * psign2[36]; + p2[10] = p2[10] * psign2[40]; + p2[11] = p2[11] * psign2[44]; + p2[12] = p2[12] * psign2[48]; + p2[13] = p2[13] * psign2[52]; + p2[14] = p2[14] * psign2[56]; + p2[15] = p2[15] * psign2[60]; p2 += 16; - E_ACELP_apply_sign(p3, psign3); + p3[0] = p3[0] * psign3[ 0]; + p3[1] = p3[1] * psign3[ 4]; + p3[2] = p3[2] * psign3[ 8]; + p3[3] = p3[3] * psign3[12]; + p3[4] = p3[4] * psign3[16]; + p3[5] = p3[5] * psign3[20]; + p3[6] = p3[6] * psign3[24]; + p3[7] = p3[7] * psign3[28]; + p3[8] = p3[8] * psign3[32]; + p3[9] = p3[9] * psign3[36]; + p3[10] = p3[10] * psign3[40]; + p3[11] = p3[11] * psign3[44]; + p3[12] = p3[12] * psign3[48]; + p3[13] = p3[13] * psign3[52]; + p3[14] = p3[14] * psign3[56]; + p3[15] = p3[15] * psign3[60]; p3 += 16; } } -void E_ACELP_4tsearch(Word16 dn[], const Word16 cn[], const Word16 H[], Word16 code[], - const PulseConfig *config, Word16 ind[], Word16 y[]) +void E_ACELP_4tsearch(Float32 dn[], const Float32 cn[], const Float32 H[], float code[], + PulseConfig *config, Word16 ind[], Float32 y[]) { - Word16 sign[L_SUBFR], vec[L_SUBFR]; - Word16 cor_x[16], cor_y[16], h_buf[4 * L_SUBFR]; - Word16 rrixix[4][16]; - Word16 rrixiy[4][256]; - Word16 dn2[L_SUBFR]; - Word16 psk, ps, alpk, alp = 0; + Float32 sign[L_SUBFR], vec[L_SUBFR]; + Float32 cor_x[16], cor_y[16], h_buf[4 * L_SUBFR]; + Float32 rrixix[4][16]; + Float32 rrixiy[4][256]; + Float32 dn2[L_SUBFR]; + Float32 psk, ps, alpk, alp = 0.0F; Word16 codvec[NB_PULSE_MAX]; Word16 pos_max[4]; Word16 dn2_pos[8 * 4]; UWord8 ipos[NB_PULSE_MAX]; - Word16 *p0, *p1, *p2, *p3; - Word16 *h, *h_inv; - Word16 i, j, k, l, st, pos; - Word16 val, tmp, scale; - Word32 s, L_tmp; - Word16 nb_pulse, nb_pulse_m2; - Word16 check = 0; /* debug code not instrumented */ + Float32 *p0, *p1, *p2, *p3; + Float32 *h, *h_inv; + Word32 i, j, k, l, st, pos = 0, index, track; + UWord8 iPulse; + Float32 val; + Float32 s; + UWord8 restpulses; - alp = config->alp; /* Q13 */ /* initial value for energy of all fixed pulses */ move16(); - nb_pulse = config->nb_pulse; - move16(); - nb_pulse_m2 = sub(nb_pulse, 2); + alp = config->alp; /* initial value for energy of all fixed pulses */ + /* set_i( (int *)codvec, 0, config->nb_pulse); */ - set16_fx(codvec, 0, nb_pulse); + for (k=0; knb_pulse; k++) codvec[k] = 0; /* * Find sign for each pulse position. */ - E_ACELP_pulsesign(cn, dn, dn2, sign, vec, alp, 0x7fff, L_SUBFR); + acelp_pulsesign(cn, dn, dn2, sign, vec, alp); /* * Select the most important 8 position per track according to dn2[]. */ - E_ACELP_findcandidates(dn2, dn2_pos, pos_max); + + acelp_findcandidates(dn2, dn2_pos, pos_max, L_SUBFR, NB_TRACK_FCB_4T); /* * Compute h_inv[i]. */ - set16_fx(h_buf, 0, L_SUBFR); - - set16_fx(h_buf + (2 * L_SUBFR),0,L_SUBFR); - - h = h_buf + L_SUBFR; - h_inv = h_buf + (3 * L_SUBFR); - - /*Check the energy if it is too high then scale to prevent an overflow*/ - scale = 0; - move16(); - L_tmp = L_deposit_l(0); - BASOP_SATURATE_WARNING_OFF - FOR (i = 0; i < L_SUBFR; i++) - { - L_tmp = L_mac(L_tmp, H[i], H[i]); - } - val = extract_h(L_tmp); - BASOP_SATURATE_WARNING_ON - - if (sub(val, 0x2000) > 0) - { - scale = -1; - move16(); - } - if (sub(val, 0x7000) > 0) - { - scale = -2; - move16(); - } - - Copy_Scale_sig(H, h, L_SUBFR, scale); - - E_ACELP_vec_neg(h, h_inv, L_SUBFR); + acelp_hbuf( h_buf, &h, &h_inv, H ); /* * Compute correlation matrices needed for the codebook search. */ + E_ACELP_corrmatrix(h, sign, vec, rrixix, rrixiy); @@ -1096,230 +679,281 @@ void E_ACELP_4tsearch(Word16 dn[], const Word16 cn[], const Word16 H[], Word16 c * 64 bits (16p): 2 iter x ((1x1)+(1x1)+(4x16)+(6x16) * +(6x16)+(8x16)+(8x16)+(8x16)) = 1280 tests */ - psk = -1; - move16(); - alpk = 1; - move16(); - + psk = -1.0; + alpk = 1.0; /*Number of iterations*/ - FOR (k = 0; k < config->nbiter; k++) + for (k = 0; k < config->nbiter; k++) { - E_ACELP_setup_pulse_search_pos(config, k, ipos); - - /* format of alp changes to Q(15-ALP2_E) */ - - pos = config->fixedpulses; - move16(); - - IF (config->fixedpulses == 0) /* 1100, 11, 1110, 1111, 2211 */ + /* copy search order from hash-table */ + for ( l=0; lnb_pulse; l++ ) { - ps = 0; - move16(); - alp = 0; - move16(); - set16_fx(vec, 0, L_SUBFR); + ipos[l] = tipos[(k * 4) + l]; } - ELSE IF (sub(config->fixedpulses, 2) == 0) /* 2222 and 3322 */ + + /* if all tracks do not have equal number of pulses */ + restpulses = config->nb_pulse & 3; + if (restpulses) + { + switch (config->codetrackpos) + { + case TRACKPOS_FIXED_FIRST: /* fixed track positions, starting from left */ + /* add tracks from left */ + for (iPulse=0; iPulse < restpulses; iPulse++) + { + ipos[config->nb_pulse-restpulses+iPulse] = iPulse; + } + /* Put the same track on the next position, because the 1-pulse search + * will access it to determine if this could be in any track. */ + ipos[config->nb_pulse] = ipos[config->nb_pulse-1]; + break; + case TRACKPOS_FIXED_EVEN: /* fixed track positions, odd tracks */ + /* odd tracks, switch order for every iteration */ + ipos[config->nb_pulse-restpulses] = (k<<1) & 2; /* 0 for even k, 2 for odd*/ + ipos[config->nb_pulse-restpulses+1] = ipos[config->nb_pulse-restpulses] ^ 2; /* 2 for even k, 0 for odd*/ + break; + case TRACKPOS_FIXED_TWO: /* two tracks instead of four */ + /* Put the next track on the next position, because the 1-pulse search + * will access it to determine if this could be in any track. */ + ipos[config->nb_pulse] = (ipos[config->nb_pulse-1]+1) & 3; + break; + default: /* one or three free track positions */ + /* copy an extra position from table - 1pulse search will access this */ + ipos[config->nb_pulse] = tipos[(k*4)+config->nb_pulse]; + break; + } + } + if (config->fixedpulses == 0)/* 1100, 11, 1110, 1111, 2211 */ + { + pos = 0; + ps = 0.0F; + alp = 0.0F; + memset(vec, 0, L_SUBFR * sizeof(Float32)); + } + else if (config->fixedpulses == 2) /* 2222 and 3322 */ { /* first stage: fix 2 pulses */ + pos = 2; + ind[0] = pos_max[ipos[0]]; - move16(); ind[1] = pos_max[ipos[1]]; - move16(); - ps = add(dn[ind[0]], dn[ind[1]]); + ps = dn[ind[0]] + dn[ind[1]]; - /*alp = rrixix[ipos[0]][ind[0] >> 2] + rrixix[ipos[1]][ind[1] >> 2] + - rrixiy[ipos[0]][((ind[0] >> 2) << 4) + (ind[1] >> 2)];*/ - i = shr(ind[0], 2); - j = shr(ind[1], 2); - l = add(shl(i, 4), j); - s = L_mult(rrixix[ipos[0]][i], _1_); /* Q9+Q12+1 */ - s = L_mac(s, rrixix[ipos[1]][j], _1_); - alp = mac_r(s, rrixiy[ipos[0]][l], _1_); + /*ind[1]>>2 and ind[0]>>2 and save*/ + /* ipos[1] and ipos[0] and save*/ + alp = rrixix[ipos[0]][ind[0] >> 2] + rrixix[ipos[1]][ind[1] >> 2] + + rrixiy[ipos[0]][((ind[0] >> 2) << 4) + (ind[1] >> 2)]; - p0 = h - ind[0]; - if (sign[ind[0]] < 0) + if (sign[ind[0]] < 0.0) { p0 = h_inv - ind[0]; } - - p1 = h - ind[1]; - if (sign[ind[1]] < 0) + else + { + p0 = h - ind[0]; + } + if (sign[ind[1]] < 0.0) { p1 = h_inv - ind[1]; } - - FOR (i = 0; i < L_SUBFR; i++) + else { - vec[i] = add(*p0++, *p1++); - move16(); + p1 = h - ind[1]; + } + /*ptx = &vec p1 and p0 already initialize*/ + vec[0] = p0[0] + p1[0]; + vec[1] = p0[1] + p1[1]; + vec[2] = p0[2] + p1[2]; + vec[3] = p0[3] + p1[3]; + for (i = 4; i < L_SUBFR; i += 6) + { + vec[i] = p0[i] + p1[i]; + vec[i + 1] = p0[i + 1] + p1[i + 1]; + vec[i + 2] = p0[i + 2] + p1[i + 2]; + vec[i + 3] = p0[i + 3] + p1[i + 3]; + vec[i + 4] = p0[i + 4] + p1[i + 4]; + vec[i + 5] = p0[i + 5] + p1[i + 5]; } } - ELSE /* 3333 and above */ + else /* 3333 and above */ { /* first stage: fix 4 pulses */ + pos = 4; ind[0] = pos_max[ipos[0]]; - move16(); ind[1] = pos_max[ipos[1]]; - move16(); ind[2] = pos_max[ipos[2]]; - move16(); ind[3] = pos_max[ipos[3]]; - move16(); - - /*ps = dn[ind[0]] + dn[ind[1]] + dn[ind[2]] + dn[ind[3]];*/ - ps = add(add(add(dn[ind[0]], dn[ind[1]]), dn[ind[2]]), dn[ind[3]]); + ps = dn[ind[0]] + dn[ind[1]] + dn[ind[2]] + dn[ind[3]]; p0 = h - ind[0]; - if (sign[ind[0]] < 0) + if (sign[ind[0]] < 0.0) { p0 = h_inv - ind[0]; } p1 = h - ind[1]; - if (sign[ind[1]] < 0) + if (sign[ind[1]] < 0.0) { p1 = h_inv - ind[1]; } p2 = h - ind[2]; - if (sign[ind[2]] < 0) + if (sign[ind[2]] < 0.0) { p2 = h_inv - ind[2]; } p3 = h - ind[3]; - if (sign[ind[3]] < 0) + if (sign[ind[3]] < 0.0) { p3 = h_inv - ind[3]; } - - FOR (i = 0; i < L_SUBFR; i++) + /* pt =&vec; others already defined*/ + vec[0] = p0[0] + p1[0] + p2[0] + p3[0]; + for (i = 1; i < L_SUBFR; i += 3) { - vec[i] = add(add(add(*p0++, *p1++), *p2++), *p3++); - move16(); + vec[i] = p0[i] + p1[i] + p2[i] + p3[i]; + vec[i + 1] = p0[i + 1] + p1[i + 1] + p2[i + 1] + p3[i + 1]; + vec[i + 2] = p0[i + 2] + p1[i + 2] + p2[i + 2] + p3[i + 2]; } - L_tmp = L_mult(vec[0], vec[0]); - FOR (i = 1; i < L_SUBFR; i++) - L_tmp = L_mac(L_tmp, vec[i], vec[i]); + alp = 0.0F; + alp += vec[0] * vec[0] + vec[1] * vec[1]; + alp += vec[2] * vec[2] + vec[3] * vec[3]; - alp = round_fx(L_shr(L_tmp, 3)); + for (i = 4; i < L_SUBFR; i += 6) + { + alp += vec[i] * vec[i]; + alp += vec[i + 1] * vec[i + 1]; + alp += vec[i + 2] * vec[i + 2]; + alp += vec[i + 3] * vec[i + 3]; + alp += vec[i + 4] * vec[i + 4]; + alp += vec[i + 5] * vec[i + 5]; + } - /*alp *= 0.5F; */ + alp *= 0.5F; } /* other stages of 2 pulses */ - st = 0; - move16(); - FOR (j = pos; j < nb_pulse; j += 2) + for (j = pos, st = 0; j < config->nb_pulse; j += 2, st++) { - IF (sub(nb_pulse_m2, j) >= 0) /* pair-wise search */ + if ((config->nb_pulse-j) >= 2) /*pair-wise search*/ { + /* * Calculate correlation of all possible positions * of the next 2 pulses with previous fixed pulses. * Each pulse can have 16 possible positions. */ - E_ACELP_h_vec_corr1(h, vec, ipos[j], sign, rrixix, cor_x, dn2_pos, config->nbpos[st]); - - E_ACELP_h_vec_corr2(h, vec, ipos[j + 1], sign, rrixix, cor_y); + acelp_h_vec_corr1(h, vec, ipos[j], sign, rrixix, cor_x, dn2_pos, + config->nbpos[st]); + acelp_h_vec_corr2(h, vec, ipos[j + 1], sign, rrixix, cor_y); /* * Find best positions of 2 pulses. */ - E_ACELP_2pulse_search(config->nbpos[st], ipos[j], ipos[j + 1], &ps, &alp, - &ind[j], &ind[j+1], dn, dn2_pos, cor_x, cor_y, rrixiy); + acelp_2pulse_search(config->nbpos[st], ipos[j], ipos[j + 1], &ps, &alp, + &ind[j], &ind[j+1], dn, dn2_pos, cor_x, cor_y, rrixiy); } - ELSE /* single pulse search */ + else /*single pulse search*/ { - E_ACELP_h_vec_corr2(h, vec, ipos[j], sign, rrixix, cor_x); - - E_ACELP_h_vec_corr2(h, vec, ipos[j + 1], sign, rrixix, cor_y); - - E_ACELP_1pulse_search(&ipos[j], &ps, &alp, - &ind[j], dn, cor_x, cor_y); + acelp_h_vec_corr2(h, vec, ipos[j], sign, rrixix, cor_x); + acelp_h_vec_corr2(h, vec, ipos[j + 1], sign, rrixix, cor_y); + E_ACELP_1pulse_search(ipos[j], ipos[j+1], &ps, &alp, + &ind[j], dn, cor_x, cor_y); } - - IF (0 < sub(nb_pulse_m2, j)) + if( j < (config->nb_pulse - 2) ) { p0 = h - ind[j]; - if (sign[ind[j]] < 0) + if (sign[ind[j]] < 0.0) { p0 = h_inv - ind[j]; } p1 = h - ind[j + 1]; - if (sign[ind[j + 1]] < 0) + if (sign[ind[j + 1]] < 0.0) { p1 = h_inv - ind[j + 1]; } - - FOR (i = 0; i < L_SUBFR; i++) + vec[0] += p0[0] + p1[0]; + vec[1] += p0[1] + p1[1]; + vec[2] += p0[2] + p1[2]; + vec[3] += p0[3] + p1[3]; + for (i = 4; i < L_SUBFR; i += 6) { - tmp = add(*p0++, *p1++); - vec[i] = add(vec[i], tmp); /* can saturate here. */ move16(); - } + vec[i] += p0[i] + p1[i]; + vec[i + 1] += p0[i + 1] + p1[i + 1]; + vec[i + 2] += p0[i + 2] + p1[i + 2]; + vec[i + 3] += p0[i + 3] + p1[i + 3]; + vec[i + 4] += p0[i + 4] + p1[i + 4]; + vec[i + 5] += p0[i + 5] + p1[i + 5]; + } } - st = add(st, 1); } /* memorise the best codevector */ - /*ps = ps * ps; MULT(1);*/ - ps = mult(ps, ps); - /*s = (alpk * ps) - (psk * alp); MULT(2);ADD(1);*/ - s = L_msu(L_mult(alpk, ps), psk, alp); /*Q9+Q6+1=Q16*/ + ps = ps * ps; + s = (alpk * ps) - (psk * alp); if (psk < 0) { - s = 1; + s = 1.0F; } - IF (s > 0) + if (s > 0.0F) { psk = ps; - move16(); alpk = alp; - move16(); - Copy(ind,codvec, nb_pulse); - check = 1; /* debug code not instrumented */ + memcpy(codvec, ind, config->nb_pulse * sizeof(Word16)); } } - assert( check ); /* debug code not instrumented */ - /* * Build the codeword, the filtered codeword and index of codevector, as well as store weighted correlations. */ - E_ACELP_build_code(nb_pulse, codvec, sign, code, ind); - - set16_fx(y, 0, L_SUBFR); - FOR (k = 0; knb_pulse; k++) { - i = codvec[k]; - move16(); - p0 = h_inv - i; - if (sign[i] > 0) + i = codvec[k]; /* read pulse position */ + val = sign[i]; /* read sign */ + + index = i / 4; /* pos of pulse (0..15) */ + track = i % 4; + if (val > 0) { - p0 -= 2*L_SUBFR; + code[i] += 1.0f; + codvec[k] += (2 * L_SUBFR); } - FOR (i=0; i= 0) + { + i++; + } + + ind[i] = index; + + p0 = h_inv - codvec[k]; + for(i=0; i0; --i) - { - dst[i] = s_or(lshl(src[i], shift_bits), lshr(src[i-1], right_shift)); - move16(); - } - dst[i] = s_or(lshl(src[i], shift_bits), lsb_bits); - move16(); -} - -#define MAX_IDX_LEN 9 - -Word16 E_ACELP_indexing( - const Word16 code[], - const PulseConfig *config, - Word16 num_tracks, - Word16 prm[] -) -{ - Word16 track, shift_bits; - Word16 p[NB_TRACK_FCB_4T], wordcnt; - UWord32 s[NB_TRACK_FCB_4T], n[NB_TRACK_FCB_4T]; - UWord16 idx[MAX_IDX_LEN]; - Word16 saved_bits; + unsigned short track; + int p[NB_TRACK_FCB_4T], wordcnt; + int k; + unsigned short idxs[MAX_IDX_LEN], maxppos; + unsigned long s[NB_TRACK_FCB_4T], n[NB_TRACK_FCB_4T]; + int maxp; + short saved_bits; assert(num_tracks == NB_TRACK_FCB_4T); saved_bits = 0; - move16(); /* * Code state of pulses of all tracks * */ - wordcnt = shr(add(config->bits, 15), 4); /* ceil(bits/16) */ - - set16_fx((Word16*)idx, 0, wordcnt); - - IF (sub(config->bits, 43) == 0) /* EVS pulse indexing */ + wordcnt = (config.bits + 15) >> 4; /* ceil(bits/16) */ + for (k=0; kcodetrackpos) + switch(config.codetrackpos) { case TRACKPOS_FIXED_TWO: /* Code position of consecutive tracks with single extra pulses */ + /* Find track with one pulse less. */ - if (sub(p[0], p[1]) != 0) + if (p[0] == p[1]) + { + /* Either 1100 or 0011 */ + if (p[1]>p[2]) + { + track = 0; /* 1100 */ + } + else + { + track = 2; /* 0011 */ + } + } + else { /* Either 0110 or 1001 */ - track = 1; - move16(); + if (p[0] < p[1]) + { + track = 1; /* 0110 */ + } + else + { + track = 3; /* 1001 */ + } } - if (sub(p[3], p[1]) > 0) - { - track = add(track, 2); - } - shift_bits = 2; - move16(); - BREAK; - + /* Multiply by number of possible states (=shift by two) and + * add actual state. */ + longshiftleft(idxs,2,idxs,wordcnt); + longadd(idxs, &track, wordcnt, 1); + break; case TRACKPOS_FREE_THREE: /* Code position of track with one pulse less than others */ - /* Find track with one pulse less. */ - if (sub(p[1], p[0]) < 0) - { - track = 1; - move16(); - } - if (sub(p[2], p[0]) < 0) - { - track = 2; - move16(); - } - if (sub(p[3], p[0]) < 0) - { - track = 3; - move16(); - } - shift_bits = 2; - move16(); - BREAK; + /* Find track with one pulse less. */ + maxp = p[0]; + maxppos = 0; + for (track=1; track < 4; track++) + { + if (p[track] < maxp) + { + maxppos = track; + break; + } + } + /* Multiply by number of possible states (=shift by two) and + * add actual state. */ + longshiftleft(idxs,2,idxs,wordcnt); + longadd(idxs, &maxppos, wordcnt, 1); + break; case TRACKPOS_FREE_ONE: - /* Code position of track with one pulse less than others */ - /* Find track with one pulse less. */ - if (sub(p[1], p[0]) > 0) - { - track = 1; - move16(); - } - if (sub(p[2], p[0]) > 0) - { - track = 2; - move16(); - } - if (sub(p[3], p[0]) > 0) - { - track = 3; - move16(); - } - shift_bits = 2; - move16(); - BREAK; + /* Code position of track with one pulse more than others */ + /* Find track with one pulse more. */ + maxp = p[0]; + maxppos = 0; + for (track=1; track < 4; track++) + { + if (p[track] > maxp) + { + maxppos = track; + break; + } + } + /* Multiply by number of possible states (=shift by two) and + * add actual state. */ + longshiftleft(idxs, 2, idxs, wordcnt); + longadd(idxs, &maxppos, wordcnt, 1); + break; case TRACKPOS_FIXED_EVEN: case TRACKPOS_FIXED_FIRST: - BREAK; - + break; default: - printf("Codebook mode not implemented.\n"); + printf("Codebook mode not implemented."); assert(0); /* mode not yet implemented*/ - BREAK; + break; } - E_ACELP_indexing_shift(wordcnt, shift_bits, track, idx, (UWord16*)prm); - - return saved_bits; -} - -/*--------------------------------------------------------------------------* - * E_ACELP_adaptive_codebook - * - * Find adaptive codebook. - *--------------------------------------------------------------------------*/ -void E_ACELP_adaptive_codebook( - Word16 *exc, /* i/o: pointer to the excitation frame Q_new */ - Word16 T0, /* i : integer pitch lag Q0 */ - Word16 T0_frac, /* i : fraction of lag */ - Word16 T0_res, /* i : pitch resolution */ - Word16 T0_res_max, /* i : maximum pitch resolution */ - Word16 mode, /* i : filtering mode (0: no, 1: yes, 2: adaptive) */ - Word16 i_subfr, /* i : subframe index */ - Word16 L_subfr, /* i : subframe length */ - Word16 L_frame, /* i : subframe length */ - Word16 *h1, /* i : impulse response of weighted synthesis filter 1Q14+shift */ - Word16 clip_gain, /* i : flag to indicate ??? */ - Word16 *xn, /* i : Close-loop Pitch search target vector Q_xn */ - Word16 *y1, /* o : zero-memory filtered adaptive excitation Q_xn */ - ACELP_CbkCorr *g_corr,/* o : ACELP correlation values */ - Word16 **pt_indice, /* i/o: quantization indices pointer */ - Word16 *pitch_gain, /* o : adaptive codebook gain 1Q14 */ - Word16 exp_xn /* i : exponent of xn (Q_xn-15) */ - ,Word16 rf_mode - ,Word16 rf_coder_type - ,Word16* lp_select - -) -{ - Word16 y2[L_SUBFR], xn2[L_SUBFR], code[L_SUBFR]; - ACELP_CbkCorr g_corr2; - Word16 gain1 = 0, gain2 = 0, fac_m, fac_n; - Word16 i, select, exp_ener; - Word32 L_tmp, L_ener; - const Word16 *pitch_inter; - Word16 pit_L_interpol, pit_up_samp; - Word16 use_prev_sf_pit_gain = 0; - - if( rf_mode == 1 && rf_coder_type == 100) + /* cast to output buffer */ + for (k=0; k 0) - { - gain1 = 15565/*0.95f Q14*/; - move16(); - } - *pitch_gain = gain1; - move16(); - } - - /* find energy of new target xn2[] */ - E_ACELP_codebook_target_update(xn, xn2, y1, gain1, L_subfr); - L_ener = Dot_product12_offs(xn2, xn2, L_subfr, &exp_ener, 0); - L_ener = L_shr(L_ener,sub(31,exp_ener)); - } - - /*-----------------------------------------------------------------* - * - find pitch excitation filtered by 1st order LP filter. * - * - find filtered pitch exc. y2[]=exc[] convolved with h1[]) * - * - compute pitch gain2 * - *-----------------------------------------------------------------*/ test(); - IF(sub(mode,NORMAL_OPERATION)==0 || sub(mode,LOW_PASS)==0) - { - /* find pitch excitation with lp filter */ - fac_m = 20972/*0.64f Q15*/; - move16(); - if ( sub(L_frame,L_FRAME16k)==0 ) - { - fac_m = 19005/*0.58f Q15*/; - move16(); - } - /* fac_n = 0.5*(1.0-fac_m); */ - fac_n = mult_r(sub(0x7FFF,fac_m),0x4000); - FOR (i=0; i 0) - { - gain2 = 15565/*0.95f Q14*/; - move16(); - } - - /* find energy of new target xn2[] */ - E_ACELP_codebook_target_update(xn, xn2, y2, gain2, L_subfr); - L_tmp = Dot_product12_offs(xn2, xn2, L_subfr, &exp_ener,0); - L_tmp = L_shr(L_tmp,sub(31,exp_ener)); - - /*-----------------------------------------------------------------* - * use the best prediction (minimise quadratic error). * - *-----------------------------------------------------------------*/ test(); - IF (sub(mode,LOW_PASS)==0 || L_sub(L_tmp,L_ener) < 0) - { - /* use the lp filter for pitch excitation prediction */ - select = LOW_PASS; - move16(); - Copy(code, &exc[i_subfr], L_subfr); - Copy(y2, y1, L_subfr); - *pitch_gain = gain2; - move16(); - g_corr->y1y1 = g_corr2.y1y1; - move16(); - g_corr->xy1 = g_corr2.xy1; - move16(); - g_corr->y1y1_e = g_corr2.y1y1_e; - move16(); - g_corr->xy1_e = g_corr2.xy1_e; - move16(); - } - ELSE - { - /* no filter used for pitch excitation prediction */ - select = FULL_BAND; - move16(); - *pitch_gain = gain1; - move16(); - } - - IF(sub(mode,NORMAL_OPERATION)==0) - { - **pt_indice = select; - (*pt_indice)++; - move16(); - } - } - ELSE - { - /* no filter used for pitch excitation prediction */ - select = FULL_BAND; - move16(); - } - *lp_select=select; - - BASOP_SATURATE_ERROR_OFF; + return (saved_bits); } @@ -1746,98 +1172,105 @@ void E_ACELP_adaptive_codebook( * Find innovative codebook. *--------------------------------------------------------------------------*/ void E_ACELP_innovative_codebook( - Word16 *exc, /* i : pointer to the excitation frame Q_new */ - Word16 T0, /* i : integer pitch lag Q0 */ - Word16 T0_frac, /* i : fraction of lag Q0 */ - Word16 T0_res, /* i : pitch resolution Q0 */ - Word16 gain_pit, /* i : adaptive codebook gain 1Q14 */ - Word16 tilt_code, /* i : tilt factor Q15 */ - Word16 mode, /* i : innovative codebook mode Q0 */ - Word16 formant_enh, /* i : use formant enhancement Q0 */ - Word16 formant_tilt, /* i : use tilt of formant enhancement Q0 */ - const Word16 formant_enh_num, /* i : formant sharpening numerator weighting */ - const Word16 formant_enh_den, /* i : formant sharpening denominator weighting */ - Word16 pitch_sharpening, /* i : use pitch sharpening Q0 */ - Word16 pre_emphasis, - Word16 phase_scrambling, - Word16 i_subfr, /* i : subframe index */ - const Word16 *Aq, /* i : quantized LPC coefficients 3Q12 */ - Word16 *h1, /* i : impulse response of weighted synthesis filter 1Q14+shift */ - Word16 *xn, /* i : Close-loop Pitch search target vector Q_xn */ - Word16 *cn, /* i : Innovative codebook search target vector Q_new */ - Word16 *y1, /* i : zero-memory filtered adaptive excitation Q_xn */ - Word16 *y2, /* o : zero-memory filtered algebraic excitation Q9 */ - Word8 acelpautoc, /* i : autocorrelation mode enabled */ - Word16 **pt_indice, /* i/o: quantization indices pointer */ - Word16 *code, /* o : innovative codebook Q9 Q9 */ - Word16 shift /* i : Scaling to get 12 bits */ - ,const Word16 L_frame, /* i : length of the frame */ - const Word16 last_L_frame,/* i : length of the last frame */ - const Word32 total_brate /* i : ttoal bit-rate */ + float *exc, /* i : pointer to the excitation frame */ + int T0, /* i : integer pitch lag */ + int T0_frac, /* i : fraction of lag */ + int T0_res, /* i : pitch resolution */ + float gain_pit, /* i : adaptive codebook gain */ + float tilt_code, /* i : tilt factor */ + int mode, /* i : innovative codebook mode */ + int pre_emphasis,/* i : use pre_emphasis */ + int pitch_sharpening, /* i : use pitch sharpening */ + int phase_scrambling, /* i : use phase scrambling */ + int formant_enh, /* i : use formant enhancement */ + int formant_tilt,/* i : use tilt of formant enhancement */ + float formant_enh_num, /* i : formant enhancement numerator weighting factor*/ + float formant_enh_den, /* i : formant enhancement denominator weighting factor*/ + const short i_subfr, /* i : subframe index */ + const float *Aq, /* i : quantized LPC coefficients */ + float *h1, /* i : impulse response of weighted synthesis filter */ + float *xn, /* i : Close-loop Pitch search target vector */ + float *cn, /* i : Innovative codebook search target vector */ + float *y1, /* i : zero-memory filtered adaptive excitation */ + float *y2, /* o : zero-memory filtered algebraic excitation */ + int acelpautoc, /* i : autocorrelation mode enabled */ + int **pt_indice, /* i/o: quantization indices pointer */ + float *code /* o : innovative codebook */ + ,const short L_frame, /* i : length of the frame */ + const short last_L_frame,/* i : length of the last frame */ + const long total_brate /* i : total bit-rate */ ) { - Word16 xn2[L_SUBFR] /* Q_xn */, cn2[L_SUBFR] /* Q_xn */, dn[L_SUBFR] /* Rw2*cn2 */, h2[L_SUBFR] /* 4Q11 */; - Word16 Rw2[L_SUBFR]; - Word16 pitch; + float xn2[L_SUBFR], cn2[L_SUBFR], dn[L_SUBFR], h2[L_SUBFR]; + float Rw2[L_SUBFR]; + int i,k; + float pitch; - - pitch = T0; - move16(); - if (sub(T0_frac, shr(T0_res, 1)) > 0) - { - pitch = add(pitch,1); - } - - BASOP_SATURATE_ERROR_ON; + pitch = (float)T0+(float)T0_frac/(float)T0_res; /* Update target vector for ACELP codebook search */ - E_ACELP_codebook_target_update(xn, xn2, y1, gain_pit, L_SUBFR); + updt_tar(xn, xn2, y1, gain_pit, L_SUBFR); /* Include fixed-gain pitch contribution into impulse resp. h1[] */ - Copy_Scale_sig(h1, h2, L_SUBFR, sub(-3, shift)); /*h2 1Q14+shift -> 4Q11, 1bit of headroom for Residu and xh_corr*/ - - cb_shape_fx(pre_emphasis, pitch_sharpening, phase_scrambling, formant_enh, formant_tilt, - formant_enh_num, formant_enh_den, Aq, h2, tilt_code, pitch, 1); + mvr2r( h1, h2, L_SUBFR); + cb_shape( pre_emphasis, pitch_sharpening, phase_scrambling, formant_enh, formant_tilt, + formant_enh_num, formant_enh_den, Aq, h2, tilt_code, pitch ); /* Correlation between target xn2[] and impulse response h1[] */ - IF (acelpautoc) + if (acelpautoc & 0x01) { - /* h2: 4Q11, Rw2: (Rw2_e)Q */ - /* Rw2_e = */ E_ACELP_hh_corr(h2, Rw2, L_SUBFR, 3); - - E_ACELP_conv(xn2, h2, cn2); - - /* dn_e -> Rw2_e*Q_xn */ - /*dn_e = */ E_ACELP_toeplitz_mul(Rw2,cn2,dn,L_SUBFR,sub((Word16)PulseConfTable[mode].nb_pulse, 24) > 0); + corr_xh(h2, Rw2, h2, L_SUBFR); + for (k=0; k0?1:-1); /* sign */ + for (h=0; h < v[k]*tmp; h++) { - pos[posno++] = t; - move16(); + pos[posno] = t; + sig[posno] = tmp; + posno++; + if (posno > 9) + { + assert(0); + } } - t = add(t, 1); } + *p = posno; - /* Iterate over the different pulse positions */ - s = L_deposit_l(0); - t = 0; - move16(); - nb_pulse = 0; - move16(); - FOR (k=0; k save sign */ + s <<= 1; + if (sig[k] < 0) + { + s++; + } } - - /* Code sign */ - /* We use L_add_c since we want to work with unsigned UWord32 */ - /* Therefore, we have to clear carry */ - Carry = 0; - s = L_lshl(s, 1); - if (sign < 0) - { - s = L_add_c(s, 1); - } - - /* Code last pulse */ - Carry = 0; - s = L_add_c(s, pulsestostates[pos[k]][t]); - t = add(t, 1); + s += pulsestostates[pos[k]][k]; } - *ps = s; - move32(); - *n = L_deposit_l(0); - if (nb_pulse) + if (posno) { - *n = pulsestostates[NB_POS_FCB_4T][nb_pulse-1]; - move32(); + *n = pulsestostates[tracklen][posno-1]; + } + else + { + *n = 0; } - *p = nb_pulse; - move16(); } -void fcb_pulse_track_joint(UWord16 *idxs, Word16 wordcnt, UWord32 *index_n, Word16 *pulse_num, Word16 track_num) +void fcb_pulse_track_joint( unsigned short *idxs, int wordcnt, long unsigned *index_n, int *pulse_num, int track_num ) { - Word16 hi_to_low[10]; - UWord32 index, index_mask; - Word32 indx_tmp; - Word16 indx_flag, indx_flag_1; - Word16 track, track_num1, pulse_num0, pulse_num1; - Word16 indx_flag_2; + int hi_to_low[10] = { 0, 0, 0, 3, 9, 5, 3, 1, 8, 8}; - Copy(hi_to_low_tmpl, hi_to_low, 10); + unsigned long long index; + unsigned int index_mask; + int indx_tmp,indx_flag,indx_flag_1; + int track,track_num1,pulse_num0,pulse_num1; + int indx_flag_2; - indx_flag = 0; - move16(); - indx_flag_1 = 0; - move16(); + indx_flag=0; + indx_flag_1=0; indx_flag_2 = 0; - move16(); - - FOR (track = 0; track < track_num; track++) + for (track=0; track < track_num; track++) { - indx_flag = add(indx_flag, shr(pulse_num[track], 2)); - indx_flag_1 = add(indx_flag_1, shr(pulse_num[track], 1)); - indx_flag_2 = add(indx_flag_2, shr(pulse_num[track], 3)); + indx_flag += (pulse_num[track]>>2); + indx_flag_1 += (pulse_num[track]>>1); + indx_flag_2 += (pulse_num[track]>>3); } - IF (sub(indx_flag_2, 1) >= 0) + if (indx_flag_2 >= 1) { hi_to_low[7] = 9; - move16(); - index_mask = 0xFFFFFF; - move32(); + index_mask = 0xffffff; } - ELSE + else { - if (sub(indx_flag, track_num) < 0) + hi_to_low[7] = 1; + if (indx_flag>=track_num) { - hi_to_low[4] = 1; - move16(); + hi_to_low[4]=9; + index_mask = 0xffff; + } + else + { + hi_to_low[4]=1; + index_mask = 0xff; } - index_mask = L_shr(0xFFFF, sub(9, hi_to_low[4])); } - IF (sub(indx_flag_1, track_num) >= 0) + if (indx_flag_1>=track_num) { - indx_tmp = L_deposit_l(0); - index = L_shr(index_n[0], low_len[pulse_num[0]]); - FOR (track = 1; track < track_num; track++) + indx_tmp = 0; + index = index_n[0] >> low_len[pulse_num[0]]; + for (track=1; track < track_num; track++) { - pulse_num0 = pulse_num[track - 1]; - move16(); + pulse_num0 = pulse_num[track-1]; pulse_num1 = pulse_num[track]; - move16(); - indx_tmp = L_lshr(index_n[track], low_len[pulse_num1]); - /* index = index * indx_fact[pulse_num1] + indx_tmp; */ - index = UL_Mpy_32_32(index, UL_deposit_l(indx_fact[pulse_num1])); - index = UL_addNsD(index, indx_tmp); - index_n[track - 1] = L_add(L_and(index_n[track - 1], low_mask[pulse_num0]), - L_and(L_lshl(index, low_len[pulse_num0]), index_mask)); + indx_tmp = index_n[track] >> low_len[pulse_num1]; + index = index * indx_fact[pulse_num1] + indx_tmp; - index = L_lshr(index, hi_to_low[pulse_num0]); + index_n[track-1] = ( index_n[track-1] & low_mask[pulse_num0] ) + ( ( index << low_len[pulse_num0] )& index_mask ) ; + index = index >> hi_to_low[pulse_num0]; } - track_num1 = sub(track_num, 1); + track_num1 = track_num - 1; pulse_num1 = pulse_num[track_num1]; - move16(); - index_n[track_num1] = L_and(L_add(L_and(index_n[track_num1], low_mask[pulse_num1]), - L_lshl(index, low_len[pulse_num1])), index_mask); - index = L_lshr(index, hi_to_low[pulse_num1]); - IF (sub(indx_flag, track_num) >= 0) + index_n[track_num1] = ( ( index_n[track_num1] & low_mask[pulse_num1] ) + ( index << low_len[pulse_num1] ) ) & index_mask; + index = index >> hi_to_low[pulse_num1]; + if (indx_flag>=track_num) { - IF (sub(indx_flag_2, 1) >= 0) + if (indx_flag_2 >= 1) { - idxs[0] = extract_l(index_n[0]); - idxs[1] = extract_l(L_add(L_lshl(index_n[1], 8), L_lshr(index_n[0], 16))); - idxs[2] = extract_l(L_lshr(index_n[1], 8)); - idxs[3] = extract_l(index_n[2]); - idxs[4] = extract_l(L_add(L_lshl(index_n[3], 8), L_lshr(index_n[2], 16))); - idxs[5] = extract_l(L_lshr(index_n[3], 8)); - track = 6; - move16(); - } - ELSE - { - FOR (track = 0; track < track_num; track++) + idxs[0] = index_n[0] & 0xffff; + idxs[1] = ( ( index_n[1] << 8 ) + ( index_n[0] >> 16) ) & 0xffff; + idxs[2] = index_n[1] >> 8; + idxs[3] = index_n[2] & 0xffff; + idxs[4] = ( ( index_n[3] << 8 ) + ( index_n[2] >> 16) ) & 0xffff; + idxs[5] = index_n[3] >> 8; + for (track=6; track < wordcnt; track++) { - idxs[track] = extract_l(index_n[track]); + idxs[track] = index&0xffff; + index = index >> 16; + } + } + else + { + for (track=0; track < track_num; track++) + { + idxs[track] = index_n[track]; + } + for (track=track_num; track < wordcnt; track++) + { + idxs[track] = index&0xffff; + index = index >> 16; } } } - ELSE + else { - idxs[0] = extract_l(L_add(L_lshl(index_n[0], 8), index_n[1])); - idxs[1] = extract_l(L_add(L_lshl(index_n[2], 8), index_n[3])); - track = 2; - move16(); + idxs[0] = ( index_n[0] << 8 ) + index_n[1]; + idxs[1] = ( index_n[2] << 8 ) + index_n[3]; + for (track=2; track < wordcnt; track++) + { + idxs[track] = index&0xffff; + index = index >> 16; + } } } - ELSE + else { index = index_n[0]; - move32(); - FOR (track = 1; track < 4; track++) + for (track=1; track < 4; track++) { pulse_num1 = pulse_num[track]; - index = L_add(L_lshl(index, index_len[pulse_num1]), index_n[track]); + index = ( index << index_len[pulse_num1] ) + index_n[track]; + } + for (track=0; track < wordcnt; track++) + { + idxs[track] = index&0xffff; + index = index >> 16; } - track = 0; - move16(); - } - FOR (; track < wordcnt; track++) - { - idxs[track] = extract_l(index); - index = L_lshr(index, 16); } + + return; } diff --git a/src/libs/libevs/lib_enc/enc_acelp_tcx_main.cpp b/src/libs/libevs/lib_enc/enc_acelp_tcx_main.cpp old mode 100755 new mode 100644 index 28a040ab..9cd59071 --- a/src/libs/libevs/lib_enc/enc_acelp_tcx_main.cpp +++ b/src/libs/libevs/lib_enc/enc_acelp_tcx_main.cpp @@ -1,112 +1,102 @@ /*==================================================================================== - EVS Codec 3GPP TS26.442 Apr 03, 2018. Version 12.11.0 / 13.6.0 / 14.2.0 + EVS Codec 3GPP TS26.443 Nov 13, 2018. Version 12.11.0 / 13.7.0 / 14.3.0 / 15.1.0 ====================================================================================*/ #include #include +#include #include -#include "prot_fx.h" #include "options.h" -#include "cnst_fx.h" -#include "stl.h" +#include "prot.h" +#include "rom_com.h" +/*-------------------------------------------------------------------* + * enc_acelp_tcx_main() + * + * encoder function for coding ACELP/TCX + *--------------------------------------------------------------------*/ + void enc_acelp_tcx_main( - const Word16 new_samples[], /* i : new samples */ - Encoder_State_fx *st, /* i/o: encoder state structure */ - const Word16 coder_type, /* i : coding type */ - const Word16 pitch[3], /* i : open-loop pitch values for quantiz. */ - const Word16 voicing[3], /* i : open-loop pitch gains */ - Word16 Aw[NB_SUBFR16k*(M+1)], /* i : weighted A(z) unquant. for subframes*/ - const Word16 lsp_new[M], /* i : LSPs at the end of the frame */ - const Word16 lsp_mid[M], /* i : LSPs at the middle of the frame */ - HANDLE_FD_CNG_ENC hFdCngEnc, /* i/o: FD CNG handle */ - Word32 bwe_exc_extended[], /* i/o: bandwidth extended excitation */ - Word16 *voice_factors, /* o : voicing factors */ - Word16 pitch_buf[], /* o : floating pitch for each subframe */ - Word16 vad_hover_flag, - Word16 *Q_new, - Word16 *shift + const float new_samples[], /* i : new samples */ + Encoder_State *st, /* i/o: encoder state structure */ + const short coder_type, /* i : coding type */ + const short pitch[3], /* i : open-loop pitch values for quantiz. */ + const float voicing[3], /* i : open-loop pitch gains */ + float Aw[NB_SUBFR16k*(M+1)], /* i : weighted A(z) unquant. for subframes*/ + const float lsp_new[M], /* i : LSPs at the end of the frame */ + const float lsp_mid[M], /* i : LSPs at the middle of the frame */ + HANDLE_FD_CNG_ENC hFdCngEnc, /* i/o: FD CNG handle */ + float bwe_exc_extended[], /* i/o: bandwidth extended excitation */ + float *voice_factors, /* o : voicing factors */ + float pitch_buf[], /* o : floating pitch for each subframe */ + short vad_hover_flag ) { - Word16 old_bwe_exc[(PIT16k_MAX + (L_FRAME16k + 1) + L_SUBFR16k) * 2]; /* excitation buffer */ - Word16 *ptr_bwe_exc; + + float old_bwe_exc[(PIT16k_MAX + (L_FRAME16k + 1) + L_SUBFR16k) * 2]; /* excitation buffer */ + float *ptr_bwe_exc; /* pointer to BWE excitation signal in the current frame */ + ptr_bwe_exc = old_bwe_exc + PIT16k_MAX * 2; - IF( sub( st->last_core_fx, ACELP_CORE) == 0 ) + if (st->last_core == ACELP_CORE) { - set16_fx( old_bwe_exc + PIT16k_MAX * 2, 0, ((L_FRAME16k + 1) + L_SUBFR16k) * 2 ); - Copy( st->old_bwe_exc_fx, old_bwe_exc, PIT16k_MAX * 2 ); + set_f( old_bwe_exc + PIT16k_MAX * 2, 0.f, ((L_FRAME16k + 1) + L_SUBFR16k) * 2 ); + mvr2r( st->old_bwe_exc, old_bwe_exc, PIT16k_MAX * 2 ); } - ELSE + else { - set16_fx( old_bwe_exc, 0, ((L_FRAME16k + 1) + L_SUBFR16k + PIT16k_MAX) * 2 ); + set_f( old_bwe_exc, 0.f, ((L_FRAME16k + 1) + L_SUBFR16k + PIT16k_MAX) * 2 ); } - /* PLC: [Guided ACELP PLC] */ - gPLC_encInfo(&st->plcExt, - st->total_brate_fx, - st->bwidth_fx, - st->clas_fx, - coder_type - ); - IF ( s_and(st->core_brate_fx!=FRAME_NO_DATA, st->core_brate_fx!=SID_2k40) ) + /* Guided ACELP PLC */ + gPLC_encInfo( &st->plcExt, st->total_brate, st->bwidth, st->clas, coder_type ); + + if( st->core_brate != FRAME__NO_DATA && st->core_brate != SID_2k40 ) { - /* Run Core Coder */ - IF (st->tcxonly == 0) + if( st->tcxonly == 0 ) { - core_encode_openloop( st, coder_type, - pitch, - voicing, Aw, lsp_new, lsp_mid, - pitch_buf, voice_factors, ptr_bwe_exc - , vad_hover_flag, *Q_new, *shift ); + core_encode_openloop( st, coder_type, pitch, voicing, Aw, lsp_new, lsp_mid, pitch_buf, voice_factors, ptr_bwe_exc, vad_hover_flag ); } - ELSE + else { - core_encode_twodiv( new_samples, - st, coder_type, pitch, voicing, Aw, Q_new, shift ); + core_encode_twodiv( new_samples, st, coder_type, pitch, voicing, Aw ); } - /*-----------------------------------------------------------------* - * Apply non linearity to the SHB excitation - *-----------------------------------------------------------------*/ - - test(); - IF( sub( st->core_fx, ACELP_CORE ) == 0 && st->igf != 0 ) + /* Apply non linearity to the SHB excitation */ + if( st->core == ACELP_CORE && st->igf ) { - non_linearity_fx( ptr_bwe_exc, bwe_exc_extended, L_FRAME32k, &st->bwe_non_lin_prev_scale_fx, *Q_new - , coder_type, voice_factors, st->L_frame_fx - ); + non_linearity( ptr_bwe_exc, bwe_exc_extended, st->old_bwe_exc_extended, L_FRAME32k, &st->bwe_non_lin_prev_scale, coder_type, voice_factors, st->L_frame ); - /* update the old BWE exe memory */ - Copy( &old_bwe_exc[L_FRAME32k], st->old_bwe_exc_fx, PIT16k_MAX * 2 ); + /* update the old_BWE_exc memory */ + mvr2r( &old_bwe_exc[L_FRAME32k], st->old_bwe_exc, PIT16k_MAX * 2 ); } - ELSE + else { - set16_fx( st->old_bwe_exc_extended_fx, 0, NL_BUFF_OFFSET ); - set16_fx( st->old_bwe_exc_fx, 0, PIT16k_MAX * 2 ); - st->bwe_non_lin_prev_scale_fx = 0; + set_f( st->old_bwe_exc_extended, 0, NL_BUFF_OFFSET ); + set_f( st->old_bwe_exc, 0, PIT16k_MAX * 2 ); /* reset old non_linear exc during igf frames */ + st->bwe_non_lin_prev_scale = 0.0f; } } - ELSE + else { /* Run SID Coder */ - IF ( st->core_brate_fx == SID_2k40 ) + if( st->core_brate == SID_2k40 ) { FdCng_encodeSID( hFdCngEnc, st, st->preemph_fac ); } /* Generate Comfort Noise */ - generate_comfort_noise_enc( st, *Q_new, 1 ); + generate_comfort_noise_enc( st ); /* Update Core Encoder */ - core_encode_update_cng( st, hFdCngEnc->hFdCngCom->timeDomainBuffer, hFdCngEnc->hFdCngCom->A_cng, Aw, *Q_new, *shift ); + core_encode_update_cng( st, hFdCngEnc->hFdCngCom->timeDomainBuffer, hFdCngEnc->hFdCngCom->A_cng, Aw ); } - /* coreSwitching update of MODE1 parameters in the last frame */ - st->last_coder_type_fx = coder_type; + /* coreSwitching update of Mode 1 parameters in the last frame */ + st->last_coder_type = coder_type; return; diff --git a/src/libs/libevs/lib_enc/enc_acelpx.cpp b/src/libs/libevs/lib_enc/enc_acelpx.cpp old mode 100755 new mode 100644 index 616b2a7e..e99a55a8 --- a/src/libs/libevs/lib_enc/enc_acelpx.cpp +++ b/src/libs/libevs/lib_enc/enc_acelpx.cpp @@ -1,541 +1,473 @@ /*==================================================================================== - EVS Codec 3GPP TS26.442 Apr 03, 2018. Version 12.11.0 / 13.6.0 / 14.2.0 + EVS Codec 3GPP TS26.443 Nov 13, 2018. Version 12.11.0 / 13.7.0 / 14.3.0 / 15.1.0 ====================================================================================*/ - +#include #include #include -#include "stl.h" -#include "prot_fx.h" -#include "basop_util.h" +#include "typedef.h" #include "options.h" -#include "rom_enc_fx.h" +#include "prot.h" +#include "rom_enc.h" -#define _1_Q11 (2048/*1.0f Q11*/) /* 1.0f in 4Q11 */ - -static void E_ACELP_update_cor( - const Word16 pos[], /* i */ - Word16 nb_pulse, /* i */ - const Word16 sign[], /* i */ - const Word16 R[], /* i */ - const Word16 cor_in[], /* i */ - Word16 cor_out[] /* o */ -) -{ - Word16 sign_x, sign_y; - const Word16 *pRx, *pRy; - Word16 i, tmp; - - IF (sub(nb_pulse, 2) == 0) - { - /* Update product of autocorrelation and already fixed pulses. with the - * two newly found ones */ - sign_x = sign[pos[0]]; - move16(); - sign_y = sign[pos[1]]; - move16(); - - IF (s_xor(sign_x, sign_y) < 0) - { - i = 1; - move16(); - if (sign_x > 0) - { - i = 0; - move16(); - } - pRx = R-pos[i]; - pRy = R-pos[1-i]; - /* different sign x and y */ - FOR (i=0; i 0) - { - /* sign x and y is positive */ - FOR (i=0; i 0 in the first iteration, the actual values do not matter. */ - sqk[0] = -1; - move16(); - alpk[0] = 1; - move16(); x = pos_x[0]; - move16(); sgnx = sign[track_y]; - move16(); if (sign[x] < 0) { - sgnx = negate(sgnx); + sgnx = -sgnx; } - if (mac_r(L_mac(L_mac(alp0, cor[x], sign[x]), cor[track_y], sign[track_y]), R[track_y-x], sgnx) < 0) + if ( (alp0 + (cor[x] * sign[x]) + (cor[track_y] * sign[track_y]) + (R[track_y-x] * sgnx)) < 0.0F ) { - sqk[0] = 1; - move16(); + sqk = 1.0F; } - ik = 0; - move16(); - xy_save = L_mac0(L_deposit_l(track_y), track_x, L_SUBFR); /* loop track 1 */ - FOR (i=0; i 0) + s = (alpk * sq) - (sqk * alp2); + if (s > 0.0F) { - alp2_16 = mac_r(alp2, pR[y], sign[y]); /* Qalp = (Q_R=Q_cor)*Q_signval */ + sqk = sq; + alpk = alp2; + y_save = y; + x_save = x; } - if (sgnx < 0) - { - alp2_16 = msu_r(alp2, pR[y], sign[y]); /* Qalp = (Q_R=Q_cor)*Q_signval */ - } - alpk[1-ik] = alp2_16; - move16(); - - /*sq = ps2 * ps2; MULT(1);*/ - sq = mult_r(ps2, ps2); /* (3+3)Q -> 6Q9 */ - sqk[1-ik] = sq; - move16(); - - - /*s = (alpk * sq) - (sqk * alp2); MULT(1);MAC(1);*/ - s = L_msu(L_mult(alpk[ik], sq), sqk[ik], alp2_16); /* Q_sq = Q_sqk, Q_alpk = Q_alp */ - if (s > 0) - { - ik = sub(1, ik); - } - if (s > 0) - { - xy_save = L_mac0(y, x, L_SUBFR); - } - assert( ((s >= 0 && i==0 && y == track_y)) || (y > track_y) || (i > 0)); } } - ps1 = extract_l(xy_save); - pos[1] = s_and(ps1, L_SUBFR-1); - move16(); - pos[0] = lshr(ps1, 6); - move16(); /* Update numerator */ - *ps = add(add(ps0,dn[pos[0]]),dn[pos[1]]); - move16(); - + *ps = ps0 + dn[x_save] + dn[y_save]; /* Update denominator */ - *alp = alpk[ik]; - move16(); + *alp = alpk; - E_ACELP_update_cor(pos, 2, sign, R, cor, cor); + /* Update product of autocorrelation and already fixed pulses. with the + * two newly found ones */ + pRx = R-x_save; + pRy = R-y_save; + sign_x = sign[x_save]; + sign_y = sign[y_save]; + for (i=0; i 0 in the first iteration, the actual values do not matter. */ - move16(); - move16(); - alpk[0] = 1; - sqk[0] = -1; - ik = 0; - move16(); - if (mac_r(alp0, cor[tracks[0]], sign[tracks[0]]) < 0) + if ( (alp0 + (cor[track_x] * sign[track_x])) < 0 ) { - sqk[0] = 1; - move16(); + sqk = 1.0F; } - x_save = tracks[0]; - move16(); - - ntracks = 1; - if (sub(tracks[1], tracks[0]) != 0) + x_save = track_x; + for (x = track_x; x < L_SUBFR; x += 4) { - ntracks = 2; - move16(); - } - FOR (t=0; t 0.0F) { - /* ps1 = ps0 + dn[x]; ADD(1);*/ - ps1 = add(ps0, dn[x]); - /* alp1 = alp0 + 2*sign[x]*cor[x]; MAC(1); MULT(1);*/ - assert(sign[x] == sign_val_1<<1 || sign[x] == -(sign_val_1<<1)); - alp1 = mac_r(alp0, cor[x], sign[x]); /* Qalp = (Q_R=Q_cor)*Q_signval */ - alpk[1-ik] = alp1; - move16(); - - - /*sq = ps1 * ps1; MULT(1);*/ - sq = mult_r(ps1, ps1); /* 6Q9 */ - sqk[1-ik] = sq; - move16(); - - /*s = (alpk[ik] * sq) - (sqk[ik] * alp1); MULT(1);MAC(1);*/ - s = L_msu(L_mult(alpk[ik], sq), sqk[ik], alp1); - - if (s > 0) - { - ik = sub(1, ik); - } - if (s > 0) + sqk = sq; + alpk = alp1; + x_save = x; + } + } + if(track_y!=track_x) + { + for (x = track_y; x < L_SUBFR; x += 4) + { + ps1 = ps0 + dn[x]; + alp1 = alp0 + 2*sign[x]*cor[x]; + sq = ps1 * ps1; + s = (alpk * sq) - (sqk * alp1); + if (s > 0.0F) { + sqk = sq; + alpk = alp1; x_save = x; - move16(); } - assert( t>0 || ((s >= 0) && (x == tracks[t])) || x > tracks[t]); } } - *ps = add(ps0, dn[x_save]); - move16(); - *alp = alpk[ik]; - move16(); + *ps = ps0 + dn[x_save]; + *alp = alpk; *ix = x_save; - move16(); + return; } /* Autocorrelation method for searching pulse positions effectively * Algorithm is identical to traditional covariance method. */ -void E_ACELP_4tsearchx(Word16 dn[], const Word16 cn[], Word16 Rw[], Word16 code[], const PulseConfig *config, Word16 ind[]) +void E_ACELP_4tsearchx( + Float32 dn[], + const Float32 cn[], + Float32 Rw[], + float code[], + PulseConfig *config + , Word16 ind[] +) { - Word16 sign[L_SUBFR], vec[L_SUBFR]; - Word16 cor[L_SUBFR]; - Word16 R_buf[2*L_SUBFR-1], *R; - Word16 dn2[L_SUBFR]; - Word16 ps2k, ps /* same format as dn[] */, ps2, alpk, alp = 0 /* Q13 and later Q_Rw*Q_signval=Q_cor*Q_signval */; - Word32 s; + Float32 sign[L_SUBFR], vec[L_SUBFR]; + Float32 cor[L_SUBFR]; + Float32 R_buf[2*L_SUBFR-1], *R; + Float32 dn2[L_SUBFR]; + Float32 psk = 0.0F, ps2k, ps, ps2, alpk, alp = 0.0F; Word16 codvec[NB_PULSE_MAX]; Word16 pos_max[4]; Word16 dn2_pos[8 * 4]; UWord8 ipos[NB_PULSE_MAX]; - Word16 i, j, k, st, pos = 0; - Word16 scale; - Word16 sign_val_1, sign_val_2; - Word16 nb_pulse, nb_pulse_m2; - - ps = 0; /* to avoid compilation warnings */ + Float32 *p0; + Word32 i, j, k, l, st, pos = 0, index, track; + UWord8 iPulse; + Float32 val; + Float32 s; + UWord8 restpulses; - - alp = config->alp; /* Q13 */ move16(); - nb_pulse = config->nb_pulse; - move16(); - nb_pulse_m2 = sub(nb_pulse, 2); - - /* Init to avoid crash when the search does not find a solution */ - FOR (k=0; kalp; + for (k=0; knb_pulse; k++) { - codvec[k] = k; - move16(); + codvec[k] = (k & 3); } - scale = 0; - move16(); - s = L_mult0(Rw[0], Rw[0]); - FOR (i = 1; i < L_SUBFR; i++) - { - s = L_mac0(s, Rw[i], Rw[i]); - } - if (s_and(sub(nb_pulse, 9) >= 0, L_sub(s, 0x800000) > 0)) - { - scale = -1; - move16(); - } - if (s_and(sub(nb_pulse, 13) >= 0, L_sub(s, 0x4000000) > 0)) - { - scale = -2; - move16(); - } - IF (sub(nb_pulse, 18) >= 0) - { - if (L_sub(s, 0x200000) > 0) - { - scale = -1; - move16(); - } - if (L_sub( s, 0x400000 ) > 0) - { - scale = -2; - move16(); - } - if (L_sub( s, 0x4000000 ) > 0) - { - scale = -3; - move16(); - } - } - if (s_and(sub(nb_pulse, 28) >= 0, L_sub(s, 0x800000) > 0)) - { - scale = -3; - move16(); - } - if (s_and(sub(nb_pulse, 36) >= 0, L_sub(s, 0x4000000) > 0)) - { - scale = -4; - move16(); - } + set_f( cor, 0.0f, L_SUBFR); /* Set up autocorrelation vector */ R = R_buf+L_SUBFR-1; - Copy_Scale_sig(Rw, R, L_SUBFR, scale); - FOR (k=1; k= 0) - { - sign_val_2 = shr(sign_val_2, 1); - } - sign_val_1 = shr(sign_val_2, 1); + /* * Find sign for each pulse position. */ - E_ACELP_pulsesign(cn, dn, dn2, sign, vec, alp, sign_val_2, L_SUBFR); + + acelp_pulsesign(cn, dn, dn2, sign, vec, alp); /* * Select the most important 8 position per track according to dn2[]. */ - E_ACELP_findcandidates(dn2, dn2_pos, pos_max); + acelp_findcandidates(dn2, dn2_pos, pos_max, L_SUBFR, NB_TRACK_FCB_4T); + + /* * Deep first search: + * ------------------ + * 20 bits (4p): 4 iter x ((4x16)+(8x16)) = 768 tests + * 36 bits (8p): 4 iter x ((1x1)+(4x16)+(8x16)+(8x16)) = 1280 tests + * 52 bits (12p): 3 iter x ((1x1)+(1x1)+(4x16)+(6x16) + * +(8x16)+(8x16)) = 1248 tests + * 64 bits (16p): 2 iter x ((1x1)+(1x1)+(4x16)+(6x16) + * +(6x16)+(8x16)+(8x16)+(8x16)) = 1280 tests */ - - /* Ensure that in the loop below s > 0 in the first iteration, the actual values do not matter. */ - ps2k = -1; - move16(); - alpk = 1; - move16(); - - /* Number of iterations */ - FOR (k = 0; k < config->nbiter; k++) + ps2k = -1.0; + alpk = 1000.0; + /*Number of iterations*/ + for (k = 0; k < config->nbiter; k++) { - E_ACELP_setup_pulse_search_pos(config, k, ipos); - - /* index to first non-fixed position */ - pos = config->fixedpulses; - move16(); - - IF (config->fixedpulses == 0)/* 1100, 11, 1110, 1111, 2211 */ + /* copy search order from hash-table */ + assert(config->nb_pulse+(k*4) <= 40); + for ( l=0; lnb_pulse; l++ ) { - ps = 0; - move16(); - alp = 0; - move16(); - set16_fx(cor, 0, L_SUBFR); + ipos[l] = tipos[(k * 4) + l]; } - ELSE + + /* if all tracks do not have equal number of pulses */ + restpulses = config->nb_pulse & 3; + if (restpulses) { - assert(config->fixedpulses == 2 || config->fixedpulses == 4); + switch (config->codetrackpos) + { + case TRACKPOS_FIXED_FIRST: /* fixed track positions, starting from left */ + /* add tracks from left */ + for (iPulse=0; iPulse < restpulses; iPulse++) + { + ipos[config->nb_pulse-restpulses+iPulse] = iPulse; + } + /* Put the same track on the next position, because the 1-pulse search + * will access it to determine if this could be in any track. */ + ipos[config->nb_pulse] = ipos[config->nb_pulse-1]; + break; + case TRACKPOS_FIXED_EVEN: /* fixed track positions, odd tracks */ + /* odd tracks, switch order for every iteration */ + ipos[config->nb_pulse-restpulses] = (k<<1) & 2; /* 0 for even k, 2 for odd*/ + ipos[config->nb_pulse-restpulses+1] = ipos[config->nb_pulse-restpulses] ^ 2; /* 2 for even k, 0 for odd*/ + break; + case TRACKPOS_FIXED_TWO: /* two tracks instead of four */ + /* Put the next track on the next position, because the 1-pulse search + * will access it to determine if this could be in any track. */ + ipos[config->nb_pulse] = (ipos[config->nb_pulse-1]+1) & 3; + break; + default: /* one or three free track positions */ + /* copy an extra position from table - 1pulse search will access this */ + ipos[config->nb_pulse] = tipos[(k*4)+config->nb_pulse]; + break; + } + } + if (config->fixedpulses == 0)/* 1100, 11, 1110, 1111, 2211 */ + { + pos = 0; + ps = 0.0F; + alp = 0.0F; + memset(cor, 0, L_SUBFR * sizeof(Float32)); + } + else if (config->fixedpulses == 2) /* 2222 and 3322 */ + { + /* --- first stage: fix 2 pulses --- */ + /* index to first non-fixed position */ + pos = 2; /* set fixed positions */ - FOR (i=0; ifixedpulses, sign, R, NULL, cor); + /* first pulse */ + p0 = R-ind[0]; + if (sign[ind[0]]>0) + { + for (i=0; i0) + { + for (i=0; ifixedpulses == 4) */ /* 3333 and above */ + { + /* first stage: fix 4 pulses */ + pos = 4; + + ind[0] = pos_max[ipos[0]]; + ind[1] = pos_max[ipos[1]]; + ind[2] = pos_max[ipos[2]]; + ind[3] = pos_max[ipos[3]]; + + /* correlation of fixed part with residual */ + ps = dn[ind[0]] + dn[ind[1]] + dn[ind[2]] + dn[ind[3]]; + + /* multiplication of autocorrelation with signed fixed pulses */ + /* first pulse */ + p0 = R-ind[0]; + if (sign[ind[0]]>0) { - s = L_mac0(s, cor[ind[i]], sign[ind[i]]); /*Q12+Q9+1=Q6 */ - ps = add(ps, dn[ind[i]]); + for (i=0; i>1 sign = 2*/ + else + { + for (i=0; i0) + { + for (i=0; inb_pulse; j += 2, st++) { - IF (sub(nb_pulse_m2, j) >= 0) /* pair-wise search */ + if ((config->nb_pulse-j) >= 2) { + /*pair-wise search*/ + /* * Calculate correlation of all possible positions * of the next 2 pulses with previous fixed pulses. * Each pulse can have 16 possible positions. */ - E_ACELP_2pulse_searchx(config->nbpos[st], ipos[j], ipos[j + 1], R, &ps, &alp, - &ind[j], &ind[j+1], dn, dn2_pos, cor, sign, sign_val_2); + E_ACELP_2pulse_searchx(config->nbpos[st], ipos[j], ipos[j + 1], R, &ps, &alp,&ind[j], &ind[j+1], dn, dn2_pos, cor, sign); } - ELSE /* single pulse search */ + else { - E_ACELP_1pulse_searchx(&ipos[j], R, &ps, &alp, - &ind[j], dn, cor, sign, sign_val_1); + /*single pulse search*/ + E_ACELP_1pulse_searchx(ipos[j], ipos[j + 1], R, &ps, &alp,&ind[j], dn, cor, sign); } - - - st = add(st, 1); } /* memorise the best codevector */ - /*ps2 = ps * ps; MULT(1);*/ - ps2 = mult(ps, ps); - - /*s = (alpk * ps2) - (ps2k * alp); MULT(2);ADD(1);*/ - s = L_msu(L_mult(alpk, ps2), ps2k, alp); - - IF (s > 0) + ps2 = ps * ps; + s = (alpk * ps2) - (ps2k * alp); + if (s > 0.0F) { ps2k = ps2; - move16(); + psk = ps; alpk = alp; - move16(); - Copy(ind, codvec, nb_pulse); + memcpy(codvec, ind, config->nb_pulse * sizeof(Word16)); } - } + } /* * Store weighted energy of code, build the codeword and index of codevector. */ - E_ACELP_build_code(nb_pulse, codvec, sign, code, ind); + + memset(code, 0, L_SUBFR * sizeof(float)); + memset(ind, 0xffffffff, NPMAXPT * 4 * sizeof(Word16)); + for (k = 0; k < config->nb_pulse; k++) + { + i = codvec[k]; /* read pulse position */ + val = sign[i]; /* read sign */ + + index = i / 4; /* pos of pulse (0..15) */ + track = i % 4; + if (val*psk > 0) + { + code[i] += 1.0f; + codvec[k] += (2 * L_SUBFR); + } + else + { + code[i] -= 1.0f; + index += 16; + } + + i = track * NPMAXPT; + while (ind[i] >= 0) + { + i++; + } + + ind[i] = index; + + } + + return; + } diff --git a/src/libs/libevs/lib_enc/enc_amr_wb.cpp b/src/libs/libevs/lib_enc/enc_amr_wb.cpp new file mode 100644 index 00000000..0fd1c735 --- /dev/null +++ b/src/libs/libevs/lib_enc/enc_amr_wb.cpp @@ -0,0 +1,198 @@ +/*==================================================================================== + EVS Codec 3GPP TS26.443 Nov 13, 2018. Version 12.11.0 / 13.7.0 / 14.3.0 / 15.1.0 + ====================================================================================*/ + +#include "options.h" +#include "cnst.h" +#include "prot.h" +#include "rom_com.h" + + +/*-------------------------------------------------------------------* + * encod_amr_wb() + * + * Encode excitation signal in AMR-WB IO mode + *-------------------------------------------------------------------*/ + +void encod_amr_wb( + Encoder_State *st, /* i/o: state structure */ + LPD_state *mem, /* i/o: encoder state structure */ + const float speech[], /* i : input speech */ + const float Aw[], /* i : weighted A(z) unquantized for subframes */ + const float Aq[], /* i : 12k8 Lp coefficient */ + const short pitch[3], /* i : open-loop pitch values for quantiz. */ + const float voicing[], /* i : voicing */ + const float *res, /* i : residual signal */ + float *syn, /* i/o: core synthesis */ + float *exc, /* i/o: current non-enhanced excitation */ + float *exc2, /* i/o: current enhanced excitation */ + float *pitch_buf, /* i/o: floating pitch values for each subframe */ + short hf_gain[NB_SUBFR], /* o : decoded HF gain */ + const float *speech16k /* i : input speech @16kHz */ +) +{ + float xn[L_SUBFR]; /* Target vector for pitch search */ + float xn2[L_SUBFR]; /* Target vector for codebook search */ + float cn[L_SUBFR]; /* Target vector in residual domain */ + float h1[L_SUBFR+(M+1)]; /* Impulse response vector */ + float code[L_SUBFR]; /* Fixed codebook excitation */ + float y1[L_SUBFR]; /* Filtered adaptive excitation */ + float y2[L_SUBFR]; /* Filtered algebraic excitation */ + float gain_pit ; /* Pitch gain */ + float voice_fac; /* Voicing factor */ + float gain_code; /* Gain of code */ + float gain_inov; /* inovation gain */ + short i, i_subfr; /* tmp variables */ + short T_op[3]; /* pitch period for quantization */ + short T0, T0_frac; /* close loop integer pitch and fractional part */ + short T0_min, T0_max; /* pitch variables */ + float *pt_pitch; /* pointer to floating pitch buffer */ + float g_corr[6]; /* ACELP correl, values + gain pitch */ + short clip_gain; /* LSF clip gain */ + const float *p_Aw, *p_Aq; /* pointer to LP filter coeff. vector*/ + short unbits = 0; + float norm_gain_code; + short pitch_limit_flag; + short lp_select, lp_flag; + + + /*------------------------------------------------------------------* + * Initializations + *------------------------------------------------------------------*/ + + pitch_limit_flag = 0; /* always restrained pitch Q range in IO mode */ + T0_max = PIT_MAX; + T0_min = PIT_MIN; + + p_Aw = Aw; + p_Aq = Aq; + pt_pitch = pitch_buf; + + mvs2s( pitch, T_op, 2 ); + if( T_op[0] <= PIT_MIN ) + { + T_op[0] *= 2; + } + + if( T_op[1] <= PIT_MIN ) + { + T_op[1] *= 2; + } + + /*------------------------------------------------------------------* + * ACELP subframe loop + *------------------------------------------------------------------*/ + + for ( i_subfr = 0; i_subfr < L_FRAME; i_subfr += L_SUBFR ) + { + /*----------------------------------------------------------------* + * Bandwidth expansion of A(z) filter coefficients + * Find the the excitation search target "xn" and innovation + * target in residual domain "cn" + * Compute impulse response, h1[], of weighted synthesis filter + *----------------------------------------------------------------*/ + + mvr2r( &res[i_subfr], &exc[i_subfr], L_SUBFR ); + + find_targets( speech, mem->mem_syn, i_subfr, &mem->mem_w0, p_Aq, res, L_SUBFR, p_Aw, TILT_FAC, xn, cn, h1 ); + + /*----------------------------------------------------------------* + * Close-loop pitch search and quantization + * Adaptive exc. construction + *----------------------------------------------------------------*/ + + *pt_pitch = pit_encode( st, st->core_brate, 1, L_FRAME, -1, &pitch_limit_flag, i_subfr, exc, + L_SUBFR, T_op, &T0_min, &T0_max, &T0, &T0_frac, h1, xn ); + + /*-----------------------------------------------------------------* + * Find adaptive exitation + *-----------------------------------------------------------------*/ + + pred_lt4( &exc[i_subfr], &exc[i_subfr], T0, T0_frac, L_SUBFR+1, inter4_2, L_INTERPOL2, PIT_UP_SAMP); + + /*-----------------------------------------------------------------* + * Gain clipping test to avoid unstable synthesis on frame erasure + * or in case of floating point encoder & fixed p. decoder + *-----------------------------------------------------------------*/ + + clip_gain = gp_clip( st->core_brate, voicing, i_subfr, 0, xn, st->clip_var ); + + /*-----------------------------------------------------------------* + * LP filtering of the adaptive excitation, codebook target computation + *-----------------------------------------------------------------*/ + + lp_select = lp_filt_exc_enc( MODE1, st->core_brate, 1, -1, i_subfr, exc, h1, xn, y1, xn2, + L_SUBFR, L_FRAME, g_corr, clip_gain, &gain_pit, &lp_flag ); + + if( lp_flag == NORMAL_OPERATION ) + { + push_indice( st, IND_LP_FILT_SELECT, lp_select, 1 ); + } + + /*-----------------------------------------------------------------* + * Innovation encoding + *-----------------------------------------------------------------*/ + + inov_encode( st, st->core_brate, 1, L_FRAME, st->last_L_frame, -1, -1, 0, i_subfr, -1, p_Aq, + gain_pit, cn, exc, h1, mem->tilt_code, *pt_pitch, xn2, code, y2, &unbits); + + /*-----------------------------------------------------------------* + * Gain encoding + * Pitch gain clipping test + * Estimate spectrum tilt and voicing + *-----------------------------------------------------------------*/ + + gain_enc_amr_wb( st, xn, y1, y2, code, st->core_brate, &gain_pit, &gain_code, + &gain_inov, &norm_gain_code, g_corr, clip_gain, st->past_qua_en ); + + gp_clip_test_gain_pit( st->core_brate, gain_pit, st->clip_var); + + mem->tilt_code = est_tilt( exc+i_subfr, gain_pit, code, gain_code, &voice_fac, L_SUBFR, 0 ); + + /*-----------------------------------------------------------------* + * Update memory of the weighting filter + *-----------------------------------------------------------------*/ + + mem->mem_w0 = xn[L_SUBFR-1] - gain_pit * y1[L_SUBFR-1] - gain_code * y2[L_SUBFR-1]; + + /*-----------------------------------------------------------------* + * Find the total excitation + *-----------------------------------------------------------------*/ + + for ( i = 0; i < L_SUBFR; i++ ) + { + exc2[i+i_subfr] = gain_pit * exc[i+i_subfr]; + exc[i+i_subfr] = exc2[i+i_subfr] + gain_code * code[i]; + } + + + /*-----------------------------------------------------------------* + * Synthesize speech to update mem_syn[] + * Update A(z) filters + *-----------------------------------------------------------------*/ + + syn_filt( p_Aq, M, &exc[i_subfr], &syn[i_subfr], L_SUBFR, mem->mem_syn, 1 ); + + /*-----------------------------------------------------------------* + * HF gain modification factors at 23.85 kbps + *-----------------------------------------------------------------*/ + + if ( st->core_brate == ACELP_23k85 ) + { + if( st->input_Fs >= 16000 ) + { + hf_cod( st->core_brate, &speech16k[i_subfr * L_SUBFR16k/L_SUBFR], p_Aq, &exc[i_subfr], &syn[i_subfr], + &st->seed2_enc, st->mem_hp400_enc, st->mem_syn_hf_enc, st->mem_hf_enc, st->mem_hf2_enc, &st->hangover_cnt, + &st->gain_alpha, &hf_gain[i_subfr/L_SUBFR] ); + } + + push_indice( st, IND_HF_GAIN_MODIFICATION, hf_gain[i_subfr/L_SUBFR], 4 ); + } + + p_Aw += (M+1); + p_Aq += (M+1); + pt_pitch++; + } + + return; +} diff --git a/src/libs/libevs/lib_enc/enc_amr_wb_fx.cpp b/src/libs/libevs/lib_enc/enc_amr_wb_fx.cpp deleted file mode 100755 index aa935447..00000000 --- a/src/libs/libevs/lib_enc/enc_amr_wb_fx.cpp +++ /dev/null @@ -1,232 +0,0 @@ -/*==================================================================================== - EVS Codec 3GPP TS26.442 Apr 03, 2018. Version 12.11.0 / 13.6.0 / 14.2.0 - ====================================================================================*/ - -#include "options.h" /* Compilation switches */ -#include "cnst_fx.h" /* Common constants */ -#include "prot_fx.h" /* Function prototypes */ -#include "rom_com_fx.h" /* Static table prototypes */ -#include "stl.h" /* required by wmc_tool */ - -/*-------------------------------------------------------------------* - * encod_amr_wb() - * - * Encode excitation signal in AMR-WB IO mode - *-------------------------------------------------------------------*/ -void encod_amr_wb_fx( - Encoder_State_fx *st, /* i/o: state structure */ - LPD_state *mem, /* i/o: acelp memories */ - const Word16 speech[], /* i : input speech */ - const Word16 Aw[], /* i : weighted A(z) unquantized for subframes */ - const Word16 Aq[], /* i : 12k8 Lp coefficient */ - const Word16 pitch[3], /* i : open-loop pitch values for quantiz. */ - const Word16 voicing[], /* i : voicing */ - const Word16 *res, /* i : residual signal */ - Word16 *syn, /* i/o: core synthesis */ - Word16 *exc, /* i/o: current non-enhanced excitation */ - Word16 *exc2, /* i/o: current enhanced excitation */ - Word16 *pitch_buf, /* i/o: floating pitch values for each subframe */ - Word16 hf_gain_fx[NB_SUBFR], /* o : decoded HF gain */ - const Word16 *speech16k_fx, - Word16 shift, - Word16 Q_new -) -{ - Word16 xn[L_SUBFR]; /* Target vector for pitch search */ - Word16 xn2[L_SUBFR]; /* Target vector for codebook search */ - Word16 cn[L_SUBFR]; /* Target vector in residual domain */ - Word16 h1[L_SUBFR+(M+1)]; /* Impulse response vector */ - Word16 h2[L_SUBFR+(M+1)]; /* Impulse response vector */ - Word16 code[L_SUBFR]; /* Fixed codebook excitation */ - Word16 y1[L_SUBFR]; /* Filtered adaptive excitation */ - Word16 y2[L_SUBFR]; /* Filtered algebraic excitation */ - Word16 gain_pit ; /* Pitch gain */ - Word16 voice_fac; /* Voicing factor */ - Word32 gain_code; /* Gain of code */ - Word16 gain_inov; /* inovation gain */ - Word16 i, i_subfr; /* tmp variables */ - Word16 T0, T0_frac; /* close loop integer pitch and fractional part */ - Word16 T0_min, T0_max; /* pitch variables */ - Word16 *pt_pitch; /* pointer to floating pitch buffer */ - Word16 g_corr[10]; /* ACELP correl, values + gain pitch */ - Word16 clip_gain; /* LSF clip gain */ - const Word16 *p_Aw, *p_Aq; /* pointer to LP filter coeff. vector*/ - Word16 unbits; - Word32 norm_gain_code; - Word16 pitch_limit_flag; - Word16 shift_wsp; - Word32 L_tmp; - Word16 gcode16; - Word32 Ltmp; - Word32 Lgcode; - Word16 T_op[3]; /* pitch period for quantization */ - Word16 lp_select, lp_flag; - - /*------------------------------------------------------------------* - * Initializations - *------------------------------------------------------------------*/ - - set16_fx( y2, 0, L_SUBFR ); - set16_fx( code, 0, L_SUBFR ); - - pitch_limit_flag = 0; - move16(); /* always restrained pitch Q range in IO mode */ - T0_max = PIT_MAX; - move16(); - T0_min = PIT_MIN; - move16(); - unbits = 0; - move16(); - - p_Aw = Aw; - p_Aq = Aq; - pt_pitch = pitch_buf; - shift_wsp = add(Q_new,shift); - - Copy( pitch, T_op, 2 ); - if (sub(T_op[0],PIT_MIN) <= 0) - { - T_op[0] = shl(T_op[0],1); - move16(); - } - - if (sub(T_op[1],PIT_MIN) <= 0) - { - /*T_op[1] *= 2;*/ - T_op[1] = shl(T_op[1],1); - move16(); - } - - /*------------------------------------------------------------------* - * ACELP subframe loop - *------------------------------------------------------------------*/ - FOR ( i_subfr = 0; i_subfr < L_FRAME; i_subfr += L_SUBFR ) - { - /*----------------------------------------------------------------* - * Bandwidth expansion of A(z) filter coefficients - * Find the the excitation search target "xn" and innovation - * target in residual domain "cn" - * Compute impulse response, h1[], of weighted synthesis filter - *----------------------------------------------------------------*/ - Copy( &res[i_subfr], &exc[i_subfr], L_SUBFR ); - - find_targets_fx( speech, mem->mem_syn, i_subfr, &mem->mem_w0, p_Aq, - res, L_SUBFR, p_Aw, TILT_FAC_FX, xn, cn, h1 ); - - Copy_Scale_sig(h1, h2, L_SUBFR, -2); - Scale_sig(h1, L_SUBFR, add(1, shift)); /* set h1[] in Q14 with scaling for convolution */ - - /* scaling of xn[] to limit dynamic at 12 bits */ - Scale_sig(xn, L_SUBFR, shift); - - /*----------------------------------------------------------------* - * Close-loop pitch search and quantization - * Adaptive exc. construction - *----------------------------------------------------------------*/ - - *pt_pitch = pit_encode_fx(st, st->core_brate_fx, 1, L_FRAME, -1, &pitch_limit_flag, i_subfr, exc, - L_SUBFR, T_op, &T0_min, &T0_max, &T0, &T0_frac, h1, xn ); - - /*-----------------------------------------------------------------* - * Find adaptive exitation - *-----------------------------------------------------------------*/ - - pred_lt4(&exc[i_subfr], &exc[i_subfr], T0, T0_frac, L_SUBFR+1, pitch_inter4_2, L_INTERPOL2, PIT_UP_SAMP); - - /*-----------------------------------------------------------------* - * Gain clipping test to avoid unstable synthesis on frame erasure - * or in case of floating point encoder & fixed p. decoder - *-----------------------------------------------------------------*/ - - clip_gain = gp_clip_fx( st->core_brate_fx, voicing, i_subfr, 0, xn, st->clip_var_fx, sub(shift_wsp,1)); - - /*-----------------------------------------------------------------* - * LP filtering of the adaptive excitation, codebook target computation - *-----------------------------------------------------------------*/ - - lp_select = lp_filt_exc_enc_fx( MODE1, st->core_brate_fx, 1, -1, i_subfr, exc, h1, - xn, y1, xn2, L_SUBFR, L_FRAME, g_corr, clip_gain, &gain_pit, &lp_flag ); - - IF( sub(lp_flag,NORMAL_OPERATION) == 0 ) - { - push_indice_fx( st, IND_LP_FILT_SELECT, lp_select, 1 ); - } - - /*-----------------------------------------------------------------* - * Innovation encoding - *-----------------------------------------------------------------*/ - inov_encode_fx( st, st->core_brate_fx, 1, L_FRAME, st->last_L_frame_fx, -1, -1, 0, i_subfr, -1, p_Aq, gain_pit, cn, - exc, h2, mem->tilt_code, *pt_pitch, xn2, code, y2, &unbits, shift ); - /*-----------------------------------------------------------------* - * Gain encoding - * Pitch gain clipping test - * Estimate spectrum tilt and voicing - *-----------------------------------------------------------------*/ - gain_enc_amr_wb_fx( st, xn, shift_wsp, y1, y2, code, st->core_brate_fx, &gain_pit, &gain_code, - &gain_inov, &norm_gain_code, g_corr, clip_gain, st->past_qua_en_fx ); - - gp_clip_test_gain_pit_fx( st->core_brate_fx, gain_pit, st->clip_var_fx ); - Lgcode = L_shl(gain_code, Q_new); /* scaled gain_code with Qnew -> Q16*/ - gcode16 = round_fx(Lgcode); - - mem->tilt_code = Est_tilt2( exc+i_subfr, gain_pit, code, Lgcode, &voice_fac, shift ); - - FOR (i = 0; i < L_SUBFR; i++) - { - exc2[i+i_subfr] = round_fx(L_shl(L_mult(gain_pit,exc[i+i_subfr]),1)); - } - - /*-----------------------------------------------------------------* - * Update memory of the weighting filter - *-----------------------------------------------------------------*/ - - /*st->mem_w0 = xn[L_SUBFR-1] - gain_pit * y1[L_SUBFR-1] - gain_code * y2[L_SUBFR-1];*/ - Ltmp = L_mult(gcode16, y2[L_SUBFR - 1]); - Ltmp = L_shl(Ltmp, add(5, shift)); - Ltmp = L_negate(Ltmp); - Ltmp = L_mac(Ltmp, xn[L_SUBFR - 1], 16384); - Ltmp = L_msu(Ltmp, y1[L_SUBFR - 1], gain_pit); - Ltmp = L_shl(Ltmp, sub(1, shift)); - mem->mem_w0 = round_fx(Ltmp); /*Q_new-1 */ - - /*-----------------------------------------------------------------* - * Find the total excitation - *-----------------------------------------------------------------*/ - FOR (i = 0; i < L_SUBFR; i++) - { - L_tmp = L_mult(gcode16, code[i]); - L_tmp = L_shl(L_tmp, 5); - L_tmp = L_mac(L_tmp, exc[i + i_subfr], gain_pit); - L_tmp = L_shl(L_tmp, 1); /* saturation can occur here */ - exc[i + i_subfr] = round_fx(L_tmp); - } - - /*-----------------------------------------------------------------* - * Synthesize speech to update mem_syn[] - * Update A(z) filters - *-----------------------------------------------------------------*/ - Syn_filt_s(1, p_Aq, M, &exc[i_subfr], &syn[i_subfr], L_SUBFR, mem->mem_syn, 1 ); - - /*-----------------------------------------------------------------* - * HF gain modification factors at 23.85 kbps - *-----------------------------------------------------------------*/ - - IF ( L_sub(st->core_brate_fx,ACELP_23k85) == 0 ) - { - IF( L_sub(st->input_Fs_fx,16000) >= 0 ) - { - hf_cod_fx( st->core_brate_fx, &speech16k_fx[i_subfr * L_SUBFR16k/L_SUBFR], Aq, &exc[i_subfr], &syn[i_subfr], - &st->seed2_enc_fx, st->mem_hp400_enc_fx, st->mem_syn_hf_enc_fx, st->mem_hf_enc_fx, st->mem_hf2_enc_fx, - st->hangover_cnt_fx, &st->gain_alpha_fx, &hf_gain_fx[i_subfr/L_SUBFR], add(Q_new,1), st->Q_syn); - } - - push_indice_fx(st, IND_HF_GAIN_MODIFICATION, hf_gain_fx[i_subfr/L_SUBFR], 4 ); - } - - p_Aw += (M+1); - p_Aq += (M+1); - pt_pitch++; - } - - return; -} diff --git a/src/libs/libevs/lib_enc/enc_gain.cpp b/src/libs/libevs/lib_enc/enc_gain.cpp old mode 100755 new mode 100644 index e1a24a7f..c5456ea9 --- a/src/libs/libevs/lib_enc/enc_gain.cpp +++ b/src/libs/libevs/lib_enc/enc_gain.cpp @@ -1,129 +1,18 @@ /*==================================================================================== - EVS Codec 3GPP TS26.442 Apr 03, 2018. Version 12.11.0 / 13.6.0 / 14.2.0 + EVS Codec 3GPP TS26.443 Nov 13, 2018. Version 12.11.0 / 13.7.0 / 14.3.0 / 15.1.0 ====================================================================================*/ +#include #include #include #include #include -#include "stl.h" -#include "prot_fx.h" -#include "rom_com_fx.h" -#include "basop_util.h" +#include "typedef.h" +#include "prot.h" +#include "rom_enc.h" +#include "rom_com.h" -/* - * E_GAIN_norm_corr - * - * Parameters: - * exc I: excitation buffer (Q_new) - * xn I: target signal (Q_new+shift-1) - * h I: weighted synthesis filter impulse response (Q14+shift) - * t0_min I: minimum value in the searched range - * t0_max I: maximum value in the searched range - * corr_norm O: normalized correlation (Q15+(Q_new+shift-1)+scale) - * - * Function: - * Find the normalized correlation between the target vector and the - * filtered past excitation (correlation between target and filtered - * excitation divided by the square root of energy of filtered excitation) - * Size of subframe = L_SUBFR. - * - * Returns: - * void - */ -void E_GAIN_norm_corr(Word16 exc[], Word16 xn[], Word16 h[], - Word16 t_min, Word16 t_max, Word16 corr_norm[], Word16 L_subfr) -{ - Word16 excf[L_SUBFR]; /* filtered past excitation (Q_new+shift-1) */ - Word16 ps, norm, exp_alp, exp_ps, scale, L_subfr2; - Word16 t, j, k; - Word32 L_tmp, L_tmp2; - - - k = negate(t_min); - L_subfr2 = shr(L_subfr, 1); - - /* compute the filtered excitation for the first delay t_min */ - E_UTIL_f_convolve(&exc[k], h, excf,L_subfr); - - /* Compute rounded down 1/sqrt(energy of xn[]) */ - Dot_product12_offs(xn, xn, L_subfr, &scale, 1); - - scale = add(scale, 2+1); /* energy of xn[] x 2 + rounded up */ - scale = negate(shr(scale, 1)); /* (1< 0; j--) - { - /*excf[j] = excf[j - 1] + exc[k] * h[j]; MAC(1); STORE(1);*/ - /* saturation can occur in add() */ - excf[j] = add(mult_r(exc[k], h[j]), excf[j - 1]); - move16(); - - } - excf[0] = mult_r(exc[k],h[0]); - move16(); - } - /* Last reduced iteration for t=t_max */ - L_tmp = Dot_product12_offs(xn, excf, L_subfr, &exp_ps, 1); - ps = extract_h(L_tmp); - - - /* Compute 1/sqrt(energy of excf[]) */ - L_tmp = Dot_product12_offs(excf, excf, L_subfr2, NULL, 1); - L_tmp2 = Dot_product12_offs(excf+L_subfr2, excf+L_subfr2, L_subfr2, NULL, 1); - exp_alp = sub(s_min(norm_l(L_tmp), norm_l(L_tmp2)), 1); - L_tmp = L_add(L_shl(L_tmp, exp_alp), L_shl(L_tmp2, exp_alp)); - exp_alp = sub(31+1, exp_alp); - - - /*norm = (Float32)(1.0F / sqrt(alp)); SQRT(1);*/ - L_tmp = ISqrt32(L_tmp, &exp_alp); - norm = extract_h(L_tmp); - - /* Normalize correlation = correlation * (1/sqrt(energy)) */ - /*corr_norm[t-t_min] = ps * norm; MULT(1); STORE(1);*/ - L_tmp = L_mult(ps, norm); - L_tmp = L_shl(L_tmp, add(add(exp_ps, exp_alp), scale)); - corr_norm[t-t_min] = round_fx(L_tmp); - - return; -} /* @@ -139,15 +28,14 @@ void E_GAIN_norm_corr(Word16 exc[], Word16 xn[], Word16 h[], * Returns: * interpolated value */ -static Word16 E_GAIN_norm_corr_interpolate(Word16 *x, Word16 frac) +static Float32 E_GAIN_norm_corr_interpolate(Float32 *x, Word32 frac) { - Word16 *x1, *x2, i; - const Word16 *c1, *c2; - Word32 s; + Float32 s, *x1, *x2; + const Float32 *c1, *c2; - IF (frac < 0) + if (frac < 0) { - frac = add(frac,4); + frac += 4; x--; } @@ -155,33 +43,21 @@ static Word16 E_GAIN_norm_corr_interpolate(Word16 *x, Word16 frac) x2 = &x[1]; c1 = &E_ROM_inter4_1[frac]; c2 = &E_ROM_inter4_1[4 - frac]; - - /*s = x1[0] * c1[0] + x2[0] * c2[0]; + s = x1[0] * c1[0] + x2[0] * c2[0]; s += x1[-1] * c1[4] + x2[1] * c2[4]; s += x1[-2] * c1[8] + x2[2] * c2[8]; - s += x1[-3] * c1[12] + x2[3] * c2[12];*/ - - s = L_deposit_l(0); - FOR (i = 0; i < 4; i++) - { - s = L_mac(s,*x1--,*c1); - s = L_mac(s,*x2++,*c2); - c1 += 4; - c2 += 4; - } - - return round_fx(L_shl(s, 1)); + s += x1[-3] * c1[12] + x2[3] * c2[12]; + return s; } -static Word16 E_GAIN_norm_corr_interpolate6(Word16 *x, Word16 frac) +static Float32 E_GAIN_norm_corr_interpolate6(Float32 *x, Word32 frac) { - Word16 *x1, *x2, i; - const Word16 *c1, *c2; - Word32 s; + Float32 s, *x1, *x2; + const Float32 *c1, *c2; - IF (frac < 0) + if (frac < 0) { - frac = add(frac,6); + frac += 6; x--; } @@ -189,21 +65,11 @@ static Word16 E_GAIN_norm_corr_interpolate6(Word16 *x, Word16 frac) x2 = &x[1]; c1 = &E_ROM_inter6_1[frac]; c2 = &E_ROM_inter6_1[6 - frac]; - - /*s = x1[0] * c1[0] + x2[0] * c2[0]; + s = x1[0] * c1[0] + x2[0] * c2[0]; s += x1[-1] * c1[6] + x2[1] * c2[6]; s += x1[-2] * c1[12] + x2[2] * c2[12]; - s += x1[-3] * c1[18] + x2[3] * c2[18];*/ - s = L_deposit_l(0); - FOR (i = 0; i < 4; i++) - { - s = L_mac(s,*x1--,*c1); - s = L_mac(s,*x2++,*c2); - c1 += 6; - c2 += 6; - } - - return round_fx(L_shl(s, 1)); + s += x1[-3] * c1[18] + x2[3] * c2[18]; + return s; } /* @@ -227,60 +93,53 @@ static Word16 E_GAIN_norm_corr_interpolate6(Word16 *x, Word16 frac) * Returns: * chosen integer pitch lag */ -Word16 E_GAIN_closed_loop_search(Word16 exc[], - Word16 xn[], Word16 h[], - Word16 t0_min, Word16 t0_min_frac, Word16 t0_max, Word16 t0_max_frac, Word16 t0_min_max_res, Word16 *pit_frac, Word16 *pit_res, Word16 pit_res_max, - Word16 i_subfr, Word16 pit_min, Word16 pit_fr2, Word16 pit_fr1, Word16 L_subfr) +Word32 E_GAIN_closed_loop_search(Float32 exc[], + Float32 xn[], Float32 h[], + Word32 t0_min, Word32 t0_min_frac, Word32 t0_max, Word32 t0_max_frac, Word32 t0_min_max_res, Word32 *pit_frac, Word32 *pit_res, Word32 pit_res_max, + Word32 i_subfr, Word32 pit_min, Word32 pit_fr2, Word32 pit_fr1, Word32 L_subfr) { - Word16 corr_v[32 + 2 * L_INTERPOL1 + 1]; - Word16 cor_max, max, temp; - Word16 *corr; - Word16 i, fraction, frac1, frac2, step; - Word16 t0, t_min, t_max; + Float32 corr_v[32 + 2 * L_INTERPOL1 + 1]; + Float32 cor_max, max, temp; + Float32 *corr; + Word32 i, fraction, frac1, frac2, step; + Word32 t0, t_min, t_max; + (void)t0_min_frac; + (void)t0_max_frac; + (void)t0_min_max_res; - set16_fx(corr_v, 0, 32 + 2 * L_INTERPOL1 + 1); /* Find interval to compute normalized correlation */ if (t0_min_frac>0) { - t0_min = add(t0_min,1); + t0_min++; } - t_min = sub(t0_min,L_INTERPOL1); - t_max = add(t0_max,L_INTERPOL1); + t_min = t0_min - L_INTERPOL1; + t_max = t0_max + L_INTERPOL1; /* allocate memory to normalized correlation vector */ - corr = &corr_v[negate(t_min)]; /* corr[t_min..t_max] */ + corr = &corr_v[-t_min]; /* corr[t_min..t_max] */ /* Compute normalized correlation between target and filtered excitation */ - E_GAIN_norm_corr(exc, xn, h, t_min, t_max, corr_v, L_subfr); + norm_corr(exc, xn, h, t_min, t_max, corr, L_subfr); /* find integer pitch */ max = corr[t0_min]; - move16(); t0 = t0_min; - move16(); - - FOR(i = t0_min + 1; i <= t0_max; i++) + for(i = t0_min + 1; i <= t0_max; i++) { - BASOP_SATURATE_WARNING_OFF; - if( sub(corr[i],max) >= 0) + if( corr[i] >= max) { + max = corr[i]; t0 = i; - move16(); } - max = s_max(max, corr[i]); - BASOP_SATURATE_WARNING_ON; } /* If first subframe and t0 >= pit_fr1, do not search fractionnal pitch */ - test(); - IF((i_subfr == 0) && sub(t0,pit_fr1) >= 0) + if((i_subfr == 0) & (t0 >= pit_fr1)) { *pit_frac = 0; - move16(); *pit_res = 1; - move16(); return(t0); } @@ -291,105 +150,86 @@ Word16 E_GAIN_closed_loop_search(Word16 exc[], * the interpolated normalized correlation. */ - IF ( sub(t0_min_max_res,shr(pit_res_max,1)) == 0) + if ( t0_min_max_res == (pit_res_max>>1) ) { - t0_min_frac = shl(t0_min_frac,1); - t0_max_frac = shl(t0_max_frac,1); + t0_min_frac = t0_min_frac << 1; + t0_max_frac = t0_max_frac << 1; } step = 1; - frac1 = sub(1,pit_res_max); - frac2 = sub(pit_res_max,1); - - test(); - test(); - IF (((i_subfr == 0) && sub(t0,pit_fr2) >= 0) || sub(pit_fr2,pit_min) <= 0) + frac1 = -(pit_res_max-1); + frac2 = pit_res_max-1; + if (((i_subfr == 0) & (t0 >= pit_fr2)) | (pit_fr2 <= pit_min)) { step = 2; - frac1 = sub(2,pit_res_max); - frac2 = sub(pit_res_max,2); + frac1 = -(pit_res_max-2); + frac2 = pit_res_max-2; } - test(); - IF ( (sub(t0,t0_min) == 0) && (t0_min_frac==0) ) + + if ( (t0 == t0_min) && (t0_min_frac==0) ) { frac1 = t0_min_frac; - move16(); } - ELSE + else if ( (t0 == t0_min) && (frac1+pit_res_max=0 && frac2>frac1); - - IF (sub(pit_res_max,6) == 0) + if (pit_res_max == 6) { cor_max = E_GAIN_norm_corr_interpolate6(&corr[t0], frac1); fraction = frac1; - - FOR (i = (frac1 + step); i <= frac2; i += step) + for (i = (frac1 + step); i <= frac2; i += step) { + ; temp = E_GAIN_norm_corr_interpolate6(&corr[t0], i); - IF (sub(temp,cor_max) > 0) + if (temp > cor_max) { cor_max = temp; - move16(); fraction = i; - move16(); } } } - ELSE + else { cor_max = E_GAIN_norm_corr_interpolate(&corr[t0], frac1); fraction = frac1; - - FOR (i = (frac1 + step); i <= frac2; i += step) + for (i = (frac1 + step); i <= frac2; i += step) { + ; temp = E_GAIN_norm_corr_interpolate(&corr[t0], i); - IF (sub(temp,cor_max) > 0) + if (temp > cor_max) { cor_max = temp; - move16(); fraction = i; - move16(); } } } /* limit the fraction value */ - IF (fraction < 0) + if (fraction < 0) { - fraction = add(fraction,pit_res_max); - t0 = sub(t0,1); + fraction += pit_res_max; + t0 -= 1; } - test(); - test(); - IF (((i_subfr == 0) && sub(t0,pit_fr2) >= 0) || sub(pit_fr2,pit_min) <= 0) + if (((i_subfr == 0) & (t0 >= pit_fr2)) | (pit_fr2 <= pit_min)) { - *pit_res = shr(pit_res_max,1); - move16(); - *pit_frac = shr(fraction,1); - move16(); + *pit_res = pit_res_max>>1; + *pit_frac = fraction>>1; } - ELSE + else { *pit_res = pit_res_max; - move16(); *pit_frac = fraction; - move16(); } return (t0); } + + diff --git a/src/libs/libevs/lib_enc/enc_gen_voic.cpp b/src/libs/libevs/lib_enc/enc_gen_voic.cpp new file mode 100644 index 00000000..186e9b1f --- /dev/null +++ b/src/libs/libevs/lib_enc/enc_gen_voic.cpp @@ -0,0 +1,308 @@ +/*==================================================================================== + EVS Codec 3GPP TS26.443 Nov 13, 2018. Version 12.11.0 / 13.7.0 / 14.3.0 / 15.1.0 + ====================================================================================*/ + +#include "options.h" +#include "cnst.h" +#include "prot.h" +#include "rom_com.h" + + +/*-------------------------------------------------------------------* + * encod_gen_voic() + * + * Encode excitation signal + *-------------------------------------------------------------------*/ + +void encod_gen_voic( + Encoder_State *st, /* i/o: state structure */ + LPD_state *mem, /* i/o: encoder memories */ + const short L_frame, /* i : length of the frame */ + const short sharpFlag, /* i : formant sharpening flag */ + const float speech[], /* i : input speech */ + const float Aw[], /* i : weighted A(z) unquantized for subframes */ + const float Aq[], /* i : LP coefficients */ + const short coder_type, /* i : coding type */ + const float Es_pred, /* i : predicted scaled innov. energy */ + const short T_op[], /* i : open loop pitch */ + const float voicing[], /* i : voicing */ + const float *res, /* i : residual signal */ + float *syn, /* i/o: core synthesis */ + float *exc, /* i/o: current non-enhanced excitation */ + float *exc2, /* i/o: current enhanced excitation */ + float *pitch_buf, /* i/o: floating pitch values for each subframe */ + float *voice_factors, /* o : voicing factors */ + float *bwe_exc, /* o : excitation for SWB TBE */ + short *unbits /* i/o: number of unused bits */ +) +{ + float xn[L_SUBFR]; /* Target vector for pitch search */ + float xn2[L_SUBFR]; /* Target vector for codebook search */ + float cn[L_SUBFR]; /* Target vector in residual domain */ + float h1[L_SUBFR+(M+1)]; /* Impulse response vector */ + float code[L_SUBFR]; /* Fixed codebook excitation */ + float y1[L_SUBFR]; /* Filtered adaptive excitation */ + float y2[L_SUBFR]; /* Filtered algebraic excitation */ + float gain_pit; /* Pitch gain */ + float voice_fac; /* Voicing factor */ + float gain_code; /* Gain of code */ + float gain_inov; /* inovation gain */ + short i, i_subfr; /* tmp variables */ + short T0, T0_frac; /* close loop integer pitch and fractional part */ + short T0_min, T0_max; /* pitch variables */ + float *pt_pitch; /* pointer to floating pitch buffer */ + float g_corr[6]; /* ACELP correl, values + gain pitch */ + float gains_mem[2*(NB_SUBFR-1)]; /* pitch gain and code gain from previous subframes */ + short clip_gain; /* LSF clip gain */ + const float *p_Aw, *p_Aq; /* pointer to LP filter coeff. vector*/ + float error; + int offset; + float gain_preQ; /* Gain of prequantizer excitation */ + float code_preQ[L_SUBFR]; /* Prequantizer excitation */ + short unbits_PI; /* number of unused bits for EVS_PI */ + float norm_gain_code; + short pitch_limit_flag; + short harm_flag_acelp; + short lp_select, lp_flag; + + /*------------------------------------------------------------------* + * Initializations + *------------------------------------------------------------------*/ + + gain_pit = 0; + gain_code = 0; + gain_preQ = 0; + unbits_PI = 0; + error = 0.0f; + + if( L_frame == L_FRAME ) + { + T0_max = PIT_MAX; + T0_min = PIT_MIN; + } + else /* L_frame == L_FRAME16k */ + { + T0_max = PIT16k_MAX; + T0_min = PIT16k_MIN; + } + + p_Aw = Aw; + p_Aq = Aq; + pt_pitch = pitch_buf; + gain_preQ = 0; + set_f( code_preQ, 0, L_SUBFR ); + + /* set and write harmonicity flag */ + harm_flag_acelp = 0; + + if( st->core_brate > ACELP_24k40 && st->core_brate <= ACELP_32k && coder_type == GENERIC ) + { + if( st->last_harm_flag_acelp > 2 ) + { + harm_flag_acelp = 1; + } + + push_indice( st, IND_HARM_FLAG_ACELP, harm_flag_acelp, 1 ); + } + + /*------------------------------------------------------------------* + * ACELP subframe loop + *------------------------------------------------------------------*/ + + for( i_subfr=0; i_subfrmem_syn, i_subfr, &mem->mem_w0, p_Aq, res, L_SUBFR, p_Aw, st->preemph_fac, xn, cn, h1 ); + + /*----------------------------------------------------------------* + * Close-loop pitch search and quantization + * Adaptive exc. construction + *----------------------------------------------------------------*/ + + *pt_pitch = pit_encode( st, st->core_brate, 0, L_frame, coder_type, &pitch_limit_flag, i_subfr, + exc, L_SUBFR, T_op, &T0_min, &T0_max, &T0, &T0_frac, h1, xn ); + + if( L_frame == L_FRAME ) + { + offset = tbe_celp_exc_offset( T0, T0_frac ); + for (i=0; icore_brate, voicing, i_subfr, coder_type, xn, st->clip_var ); + + if( coder_type == INACTIVE ) + { + /* in case of AVQ inactive, limit the gain to 0.65 */ + clip_gain = 2; + } + + /*-----------------------------------------------------------------* + * LP filtering of the adaptive excitation, codebook target computation + *-----------------------------------------------------------------*/ + + lp_select = lp_filt_exc_enc( MODE1, st->core_brate, 0, coder_type, i_subfr, exc, h1, xn, y1, xn2, L_SUBFR, + L_frame, g_corr, clip_gain, &gain_pit, &lp_flag ); + + if( lp_flag == NORMAL_OPERATION ) + { + push_indice( st, IND_LP_FILT_SELECT, lp_select, 1 ); + } + + /* update long-term pitch gain for speech/music classifier */ + st->lowrate_pitchGain = 0.9f * st->lowrate_pitchGain + 0.1f * gain_pit; + + /*-----------------------------------------------------------------* + * Transform-domain contribution (active frames) + *-----------------------------------------------------------------*/ + + if( st->core_brate > ACELP_24k40 && coder_type != INACTIVE ) + { + transf_cdbk_enc( st, st->core_brate, st->extl, coder_type, harm_flag_acelp, i_subfr, -1, cn, exc, + p_Aq, p_Aw, h1, xn, xn2, y1, y2, Es_pred, &gain_pit, gain_code, g_corr, clip_gain, + &(st->mem_deemp_preQ), &(st->mem_preemp_preQ), &gain_preQ, code_preQ, unbits ); + } + + /*-----------------------------------------------------------------* + * Innovation encoding + *-----------------------------------------------------------------*/ + + inov_encode( st, st->core_brate, 0, L_frame, st->last_L_frame, coder_type, st->bwidth, sharpFlag, i_subfr, -1, p_Aq, + gain_pit, cn, exc, h1, mem->tilt_code, *pt_pitch, xn2, code, y2, &unbits_PI ); + + /*-----------------------------------------------------------------* + * Gain encoding + *-----------------------------------------------------------------*/ + + if ( st->core_brate <= ACELP_8k00 ) + { + gain_enc_lbr( st, st->core_brate, coder_type, i_subfr, xn, y1, y2, code, + &gain_pit, &gain_code, &gain_inov, &norm_gain_code, g_corr, gains_mem, clip_gain ); + } + else if ( st->core_brate > ACELP_32k ) + { + gain_enc_SQ( st, st->core_brate, coder_type, i_subfr, -1, xn, y1, y2, code, Es_pred, + &gain_pit, &gain_code, &gain_inov, &norm_gain_code, g_corr, clip_gain ); + } + else + { + gain_enc_mless( st, st->core_brate, L_frame, coder_type, i_subfr, -1, xn, y1, y2, code, Es_pred, + &gain_pit, &gain_code, &gain_inov, &norm_gain_code, g_corr, clip_gain ); + } + + if ( st->last_ppp_mode == 1 ) + { + /* SC-VBR - all other st->clip_var values will be updated even in a PPP frame */ + st->clip_var[1] = gain_pit; + } + + /*-----------------------------------------------------------------* + * update LP-filtered gains for the case of frame erasures + *-----------------------------------------------------------------*/ + + gp_clip_test_gain_pit( st->core_brate, gain_pit, st->clip_var); + mem->tilt_code = est_tilt( exc+i_subfr, gain_pit, code, gain_code, &voice_fac, L_SUBFR, 0 ); + + /*-----------------------------------------------------------------* + * Transform-domain contribution (inactive frames) + *-----------------------------------------------------------------*/ + + if ( st->core_brate > ACELP_24k40 && coder_type == INACTIVE ) + { + transf_cdbk_enc( st, st->core_brate, st->extl, coder_type, 0, i_subfr, -1, cn, exc, + p_Aq, p_Aw, h1, xn, xn2, y1, y2, Es_pred, &gain_pit, gain_code, g_corr, clip_gain, + &(st->mem_deemp_preQ), &(st->mem_preemp_preQ), &gain_preQ, code_preQ, unbits ); + } + + /*-----------------------------------------------------------------* + * Update memory of the weighting filter + *-----------------------------------------------------------------*/ + + mem->mem_w0 = xn[L_SUBFR-1] - (gain_pit*y1[L_SUBFR-1]) - (gain_code*y2[L_SUBFR-1]); + + /*-----------------------------------------------------------------* + * Construct adaptive part of the excitation + * Save the non-enhanced excitation for FEC_exc + *-----------------------------------------------------------------*/ + + for ( i = 0; i < L_SUBFR; i++ ) + { + exc2[i+i_subfr] = gain_pit * exc[i+i_subfr]; + exc[i+i_subfr] = exc2[i+i_subfr] + gain_code * code[i]; + } + + /*-----------------------------------------------------------------* + * Add the ACELP pre-quantizer contribution + *-----------------------------------------------------------------*/ + if( st->core_brate > ACELP_24k40 ) + { + for ( i = 0; i < L_SUBFR; i++ ) + { + exc2[i+i_subfr] += gain_preQ * code_preQ[i]; + exc[i+i_subfr] += gain_preQ * code_preQ[i]; + } + } + + /*-----------------------------------------------------------------* + * Prepare TBE excitation + *-----------------------------------------------------------------*/ + + prep_tbe_exc( L_frame, i_subfr, gain_pit, gain_code, code, voice_fac, &voice_factors[i_subfr/L_SUBFR], + bwe_exc, gain_preQ, code_preQ, T0, coder_type, st->core_brate ); + + + /*-----------------------------------------------------------------* + * Synthesize speech to update mem_syn[]. + * Update A(z) filters + *-----------------------------------------------------------------*/ + + syn_filt( p_Aq, M, &exc[i_subfr], &syn[i_subfr], L_SUBFR, mem->mem_syn, 1 ); + + p_Aw += (M+1); + p_Aq += (M+1); + pt_pitch++; + } + + /* write reserved bits */ + while( unbits_PI > 0 ) + { + i = min(unbits_PI, 16); + push_indice( st, IND_UNUSED, 0, i ); + unbits_PI -= i; + } + + /* SC-VBR */ + st->prev_ppp_gain_pit = gain_pit; + st->prev_tilt_code = mem->tilt_code; + + return; +} diff --git a/src/libs/libevs/lib_enc/enc_gen_voic_fx.cpp b/src/libs/libevs/lib_enc/enc_gen_voic_fx.cpp deleted file mode 100755 index c09a8265..00000000 --- a/src/libs/libevs/lib_enc/enc_gen_voic_fx.cpp +++ /dev/null @@ -1,382 +0,0 @@ -/*==================================================================================== - EVS Codec 3GPP TS26.442 Apr 03, 2018. Version 12.11.0 / 13.6.0 / 14.2.0 - ====================================================================================*/ - -#include "options.h" /* Compilation switches */ -#include "cnst_fx.h" /* Common constants */ -#include "prot_fx.h" /* Function prototypes */ -#include "rom_com_fx.h" /* Static table prototypes */ - -#include "stl.h" - - -/*======================================================================*/ -/* FUNCTION : encod_gen_voic_fx() */ -/*----------------------------------------------------------------------*/ -/* PURPOSE : encode generic (GC), voiced (VC) and AMR-WB IO frames */ -/* */ -/*----------------------------------------------------------------------*/ -/* INPUT ARGUMENTS : */ -/* _ (Struct) st_fx : encoder static memory */ -/* _ (Word16) L_frame_fx : length of the frame Q0 */ - -/* _ (Word16[]) speech_fx : input speech Q0 */ -/* _ (Word16[]) Aq_fx : LP filter coefficient Q12 */ -/* _ (Word16[]) A_fx : unquantized A(z) filter */ -/* with bandwidth expansion Q12 */ -/* _ (Word16) coder_type_fx : coding type */ -/* _ (Word16) Es_pred_fx : predicted scaled innov. energy Q8 */ -/* _ (Word16[]) T_op_fx : open loop pitch Q0 */ -/* _ (Word16[]) voicing_fx : floating pitch values for each subframe Q15*/ -/* _ (Word16[]) res_fx : residual signal Q_new */ -/* _ (Word16[]) exc_fx : adapt. excitation exc (Q0) */ -/* _ (Word16[]) exc2_fx : adapt. excitation/total exc (Q0) */ -/* _ (Word16[]) pitch_buf_fx : floating pitch values for each subframe Q6*/ -/* _ (Word16) shift : shift */ -/* _ (Word16) Q_new : */ -/*-----------------------------------------------------------------------*/ -/* OUTPUT ARGUMENTS : */ -/* _ (Word16[]) exc_fx : adapt. excitation exc (Q0) */ -/* _ (Word16[]) exc2_fx : adapt. excitation/total exc (Q0) */ -/* _ (Word16[]) syn_fx :core synthesis Q_new */ -/* _ (Word16[]) voice_factors_fx: voicing factors Q15 */ -/* _ (Word16[]) bwe_exc_fx : excitation for SWB TBE Q0 */ -/*-----------------------------------------------------------------------*/ - - -/*-----------------------------------------------------------------------*/ -/* RETURN ARGUMENTS : */ -/* _ None */ -/*=======================================================================*/ - -void encod_gen_voic_fx( - Encoder_State_fx *st_fx, /* i/o: state structure */ - LPD_state *mem, /* i/o: acelp memories */ - const Word16 L_frame_fx, /* i : length of the frame */ - const Word16 sharpFlag_fx, /* o : formant sharpening flag */ - const Word16 speech_fx[], /* i : input speech */ - const Word16 Aw_fx[], /* i : weighted A(z) unquantized for subframes */ - const Word16 Aq_fx[], /* i : 12k8 Lp coefficient */ - const Word16 coder_type_fx, /* i : coding type */ - const Word16 Es_pred_fx, /* i : predicted scaled innov. energy */ - const Word16 T_op_fx[], /* i : open loop pitch */ - const Word16 voicing_fx[], /* i : voicing */ - const Word16 *res_fx, /* i : residual signal */ - Word16 *syn_fx, /* i/o: core synthesis */ - Word16 *exc_fx, /* i/o: current non-enhanced excitation */ - Word16 *exc2_fx, /* i/o: current enhanced excitation */ - Word16 *pitch_buf_fx, /* i/o: floating pitch values for each subframe */ - Word16 *voice_factors_fx, /* o : voicing factors */ - Word16 *bwe_exc_fx, /* o : excitation for SWB TBE */ - Word16 *unbits_fx, /* i/o: number of unused bits */ - Word16 shift, - Word16 Q_new -) -{ - Word16 xn_fx[L_SUBFR]; /* Target vector for pitch search */ - Word16 xn2_fx[L_SUBFR]; /* Target vector for codebook search */ - Word16 cn_fx[L_SUBFR]; /* Target vector in residual domain */ - Word16 h1_fx[L_SUBFR+(M+1)]; /* Impulse response vector */ - Word16 h2_fx[L_SUBFR+(M+1)]; /* Impulse response vector */ - Word16 code_fx[L_SUBFR]; /* Fixed codebook excitation */ - Word16 y1_fx[L_SUBFR]= {0}; /* Filtered adaptive excitation */ - Word16 y2_fx[L_SUBFR]; /* Filtered algebraic excitation */ - Word16 gain_pit_fx = 0; /* Pitch gain */ - Word16 voice_fac_fx; /* Voicing factor */ - Word32 gain_code_fx = 0; /* Gain of code */ - Word16 gain_inov_fx=0; /* inovation gain */ - Word32 gc_mem[NB_SUBFR-1]; /* gain_code from previous subframes */ - Word16 gp_mem[NB_SUBFR-1]; /* gain_pitch from previous subframes*/ - Word16 i, i_subfr_fx; /* tmp variables */ - Word16 T0_fx=0, T0_frac_fx=0; /* close loop integer pitch and fractional part */ - Word16 T0_min_fx, T0_max_fx; /* pitch variables */ - Word16 *pt_pitch_fx; /* pointer to floating pitch buffer */ - Word16 g_corr_fx[10]; /* ACELP correl, values + gain pitch */ - Word16 clip_gain_fx; /* LSF clip gain */ - const Word16 *p_Aw_fx, *p_Aq_fx; /* pointer to LP filter coeff. vector*/ - Word16 error_fx = 0; - Word16 gain_preQ_fx = 0; /* Gain of prequantizer excitation */ - Word16 code_preQ_fx[L_SUBFR]; /* Prequantizer excitation */ - Word16 unbits_PI_fx = 0; /* number of unused bits for PI */ - Word32 norm_gain_code_fx=0; - Word16 pitch_limit_flag; - Word16 gcode16; - Word32 Ltmp; - Word32 Ltmp1; - Word32 Lgcode; - Word16 tmp1_fx; - Word16 shift_wsp; - Word16 harm_flag_acelp; - Word16 lp_select, lp_flag; - - /*------------------------------------------------------------------* - * Initializations - *------------------------------------------------------------------*/ - - gain_pit_fx = 0; - move16(); - gain_code_fx = L_deposit_l(0); - gain_preQ_fx = 0; - move16(); - unbits_PI_fx = 0; - move16(); - error_fx = 0; - move16(); - - IF( sub(L_frame_fx,L_FRAME) == 0) - { - T0_max_fx = PIT_MAX; - move16(); - T0_min_fx = PIT_MIN; - move16(); - } - ELSE /* L_frame == L_FRAME16k */ - { - T0_max_fx = PIT16k_MAX; - move16(); - T0_min_fx = PIT16k_MIN; - move16(); - } - - p_Aw_fx = Aw_fx; - p_Aq_fx = Aq_fx; - pt_pitch_fx = pitch_buf_fx; - gain_preQ_fx = 0; - move16(); - set16_fx( code_preQ_fx, 0, L_SUBFR ); - - shift_wsp = add(Q_new,shift); - - /* set and write harmonicity flag */ - harm_flag_acelp = 0; - move16(); - test(); - test(); - IF( L_sub(st_fx->core_brate_fx,ACELP_24k40) > 0 && L_sub(st_fx->core_brate_fx,ACELP_32k) <= 0 && sub(coder_type_fx,GENERIC) == 0 ) - { - if( sub(st_fx->last_harm_flag_acelp_fx,2) > 0 ) - { - harm_flag_acelp = 1; - move16(); - } - - push_indice_fx( st_fx, IND_HARM_FLAG_ACELP, harm_flag_acelp, 1 ); - } - - /*------------------------------------------------------------------* - * ACELP subframe loop - *------------------------------------------------------------------*/ - - FOR( i_subfr_fx=0; i_subfr_fxmem_syn, i_subfr_fx, &mem->mem_w0, p_Aq_fx, - res_fx, L_SUBFR, p_Aw_fx, st_fx->preemph_fac, xn_fx, cn_fx, h1_fx ); - - Copy_Scale_sig( h1_fx, h2_fx, L_SUBFR, -2 ); - Scale_sig( h1_fx, L_SUBFR, add(1, shift) ); /* set h1[] in Q14 with scaling for convolution */ - - /* scaling of xn[] to limit dynamic at 12 bits */ - Scale_sig( xn_fx, L_SUBFR, shift ); - - *pt_pitch_fx = pit_encode_fx( st_fx, st_fx->core_brate_fx, 0, L_frame_fx, coder_type_fx, &pitch_limit_flag, i_subfr_fx, exc_fx, - L_SUBFR, T_op_fx, &T0_min_fx, &T0_max_fx, &T0_fx, &T0_frac_fx, h1_fx, xn_fx ); - - tbe_celp_exc(L_frame_fx,i_subfr_fx,T0_fx, T0_frac_fx, &error_fx, bwe_exc_fx); - - /*-----------------------------------------------------------------* - * Find adaptive exitation - *-----------------------------------------------------------------*/ - - pred_lt4(&exc_fx[i_subfr_fx], &exc_fx[i_subfr_fx], T0_fx, T0_frac_fx, L_SUBFR+1, pitch_inter4_2, L_INTERPOL2, PIT_UP_SAMP); - - /*-----------------------------------------------------------------* - * Gain clipping test to avoid unstable synthesis on frame erasure - *-----------------------------------------------------------------*/ - - clip_gain_fx = gp_clip_fx(st_fx->core_brate_fx,voicing_fx,i_subfr_fx,coder_type_fx,xn_fx,st_fx->clip_var_fx,sub(shift_wsp, 1)); - - if( sub(coder_type_fx,INACTIVE) == 0 ) - { - /* in case of AVQ inactive, limit the gain to 0.65 */ - clip_gain_fx = 2; - move16(); - } - - /*-----------------------------------------------------------------* - * LP filtering of the adaptive excitation, codebook target computation - *-----------------------------------------------------------------*/ - - lp_select = lp_filt_exc_enc_fx( MODE1, st_fx->core_brate_fx, 0, coder_type_fx, i_subfr_fx, exc_fx, h1_fx, - xn_fx, y1_fx, xn2_fx, L_SUBFR, L_frame_fx, g_corr_fx, clip_gain_fx, &gain_pit_fx, &lp_flag ); - - IF( sub(lp_flag,NORMAL_OPERATION) == 0 ) - { - push_indice_fx( st_fx, IND_LP_FILT_SELECT, lp_select, 1 ); - } - - /*st_fx->lowrate_pitchGain = 0.9f * st_fx->lowrate_pitchGain + 0.1f * gain_pit_fx;*/ - st_fx->lowrate_pitchGain = round_fx(L_mac(L_mult(29491, st_fx->lowrate_pitchGain), 6554, gain_pit_fx)); /*Q14*Q16(0.1) + Q15 -> Q15*/ - - /*-----------------------------------------------------------------* - * Transform domain contribution encoding - active frames - *-----------------------------------------------------------------*/ - - test(); - IF( L_sub(st_fx->core_brate_fx,ACELP_24k40) > 0 && sub(coder_type_fx,INACTIVE) != 0 ) - { - transf_cdbk_enc_fx( st_fx, st_fx->core_brate_fx, st_fx->extl_fx, coder_type_fx, harm_flag_acelp, i_subfr_fx, -1, cn_fx, exc_fx, - p_Aq_fx, p_Aw_fx, h1_fx, xn_fx, xn2_fx, y1_fx, y2_fx, Es_pred_fx, &gain_pit_fx, gain_code_fx, g_corr_fx, clip_gain_fx, - &(st_fx->mem_deemp_preQ_fx), &(st_fx->mem_preemp_preQ_fx), &gain_preQ_fx, code_preQ_fx, unbits_fx, Q_new, shift); - } - - /*-----------------------------------------------------------------* - * Innovation encoding - *-----------------------------------------------------------------*/ - - inov_encode_fx( st_fx, st_fx->core_brate_fx, 0, L_frame_fx, st_fx->last_L_frame_fx, - coder_type_fx, st_fx->bwidth_fx, sharpFlag_fx, i_subfr_fx, -1, p_Aq_fx, - gain_pit_fx, cn_fx, exc_fx, h2_fx, mem->tilt_code, *pt_pitch_fx, xn2_fx, code_fx, y2_fx, &unbits_PI_fx, shift ); - - /*-----------------------------------------------------------------* - * Gain encoding - *-----------------------------------------------------------------*/ - - IF ( L_sub(st_fx->core_brate_fx,ACELP_8k00) <= 0) - { - gain_enc_lbr_fx( st_fx, st_fx->core_brate_fx, coder_type_fx, i_subfr_fx, xn_fx, y1_fx, shift_wsp, y2_fx, code_fx, - &gain_pit_fx, &gain_code_fx, &gain_inov_fx, &norm_gain_code_fx, g_corr_fx, gc_mem, gp_mem, clip_gain_fx ); - } - ELSE IF ( L_sub(st_fx->core_brate_fx,ACELP_32k) > 0 ) - { - gain_enc_SQ_fx( st_fx, st_fx->core_brate_fx, coder_type_fx, i_subfr_fx, -1, xn_fx, y1_fx, y2_fx, code_fx, Es_pred_fx, - &gain_pit_fx, &gain_code_fx, &gain_inov_fx, &norm_gain_code_fx, g_corr_fx, clip_gain_fx, shift_wsp ); - } - ELSE - { - gain_enc_mless_fx( st_fx, st_fx->core_brate_fx, L_frame_fx, coder_type_fx, i_subfr_fx, -1, xn_fx, y1_fx, shift_wsp, y2_fx, code_fx, Es_pred_fx, - &gain_pit_fx, &gain_code_fx, &gain_inov_fx, &norm_gain_code_fx, g_corr_fx, clip_gain_fx ); - } - - if ( sub(st_fx->last_ppp_mode_fx,1) == 0 ) - { - /* SC-VBR - all other st->clip_var values will be updated even in a PPP frame */ - st_fx->clip_var_fx[1] = gain_pit_fx; - move16(); - } - gp_clip_test_gain_pit_fx( st_fx->core_brate_fx, gain_pit_fx, st_fx->clip_var_fx ); - - Lgcode = L_shl(gain_code_fx, Q_new); /* scaled gain_code with Qnew -> Q16*/ - gcode16 = round_fx(Lgcode); - - mem->tilt_code = Est_tilt2(&exc_fx[i_subfr_fx], gain_pit_fx, code_fx, Lgcode, &voice_fac_fx, shift); - - /*-----------------------------------------------------------------* - * Transform domain contribution encoding - inactive frames - *-----------------------------------------------------------------*/ - - test(); - IF ( L_sub(st_fx->core_brate_fx,ACELP_24k40) > 0 && sub(coder_type_fx,INACTIVE) == 0 ) - { - transf_cdbk_enc_fx( st_fx, st_fx->core_brate_fx, st_fx->extl_fx, coder_type_fx, 0, i_subfr_fx, -1, cn_fx, exc_fx, - p_Aq_fx, p_Aw_fx, h1_fx, xn_fx, xn2_fx, y1_fx, y2_fx, Es_pred_fx, &gain_pit_fx, gain_code_fx, g_corr_fx, clip_gain_fx, - &(st_fx->mem_deemp_preQ_fx), &(st_fx->mem_preemp_preQ_fx), &gain_preQ_fx, code_preQ_fx, unbits_fx, Q_new, shift); - } - - /*-----------------------------------------------------------------* - * Update memory of the weighting filter - *-----------------------------------------------------------------*/ - - /* st_fx->mem_w0 = xn[L_SUBFR-1] - (gain_pit*y1[L_SUBFR-1]) - (gain_code*y2[L_SUBFR-1]); */ - Ltmp = L_mult(gcode16, y2_fx[L_SUBFR - 1]); - Ltmp = L_shl(Ltmp, add(5, shift)); - Ltmp = L_negate(Ltmp); - Ltmp = L_mac(Ltmp, xn_fx[L_SUBFR - 1], 16384); - Ltmp = L_msu(Ltmp, y1_fx[L_SUBFR - 1], gain_pit_fx); - Ltmp = L_shl(Ltmp, sub(1, shift)); - mem->mem_w0 = round_fx(Ltmp); /*Q_new-1 */ - - IF( L_sub(st_fx->core_brate_fx,ACELP_24k40) > 0 ) - { - tmp1_fx = add(16-(2+Q_AVQ_OUT_DEC+1),Q_new); - - FOR( i = 0; i < L_SUBFR; i++ ) - { - /* Contribution from AVQ layer */ - Ltmp1 = L_mult(gain_preQ_fx, code_preQ_fx[i]); /* Q2 + Q6 -> Q9*/ - Ltmp1 = L_shl(Ltmp1,tmp1_fx); /* Q16 + Q_exc */ - - /* Compute exc2 */ - Ltmp = L_shl(L_mult(gain_pit_fx,exc_fx[i+i_subfr_fx]),1); - exc2_fx[i+i_subfr_fx] = round_fx(L_add(Ltmp, Ltmp1)); - - /* code in Q9, gain_pit in Q14 */ - Ltmp = L_mult(gcode16, code_fx[i]); - Ltmp = L_shl(Ltmp, 5); - Ltmp = L_mac(Ltmp, exc_fx[i + i_subfr_fx], gain_pit_fx); - Ltmp = L_shl(Ltmp, 1); /* saturation can occur here */ - - exc_fx[i+i_subfr_fx] = round_fx(L_add(Ltmp, Ltmp1)); - } - - } - ELSE - { - /*-----------------------------------------------------------------* - * Construct adaptive part of the excitation - * Save the non-enhanced excitation for FEC_exc - *-----------------------------------------------------------------*/ - FOR (i = 0; i < L_SUBFR; i++) - { - /* code in Q9, gain_pit in Q14 */ - Ltmp = L_mult(gcode16, code_fx[i]); - Ltmp = L_shl(Ltmp, 5); - Ltmp = L_mac(Ltmp, exc_fx[i + i_subfr_fx], gain_pit_fx); - Ltmp = L_shl(Ltmp, 1); /* saturation can occur here */ - exc_fx[i + i_subfr_fx] = round_fx(Ltmp); - } - } - /*-----------------------------------------------------------------* - * Prepare TBE excitation - *-----------------------------------------------------------------*/ - - prep_tbe_exc_fx( L_frame_fx, i_subfr_fx, gain_pit_fx, gain_code_fx, code_fx, voice_fac_fx, - &voice_factors_fx[i_subfr_fx/L_SUBFR], bwe_exc_fx, gain_preQ_fx, code_preQ_fx, Q_new, - T0_fx, T0_frac_fx, coder_type_fx, st_fx->core_brate_fx ); - - /*-----------------------------------------------------------------* - * Synthesize speech to update mem_syn[]. - * Update A(z) filters - *-----------------------------------------------------------------*/ - - Syn_filt_s( 1, p_Aq_fx, M, &exc_fx[i_subfr_fx], &syn_fx[i_subfr_fx], L_SUBFR, mem->mem_syn, 1 ); - - p_Aw_fx += (M+1); - p_Aq_fx += (M+1); - pt_pitch_fx++; - } - - /* write reserved bits */ - WHILE( unbits_PI_fx > 0 ) - { - i = s_min(unbits_PI_fx, 16); - push_indice_fx( st_fx, IND_UNUSED, 0, i ); - unbits_PI_fx -= i; - } - /* SC-VBR */ - st_fx->prev_ppp_gain_pit_fx = gain_pit_fx; - move16(); - st_fx->prev_tilt_code_fx = mem->tilt_code; - move16(); - - return; - -} diff --git a/src/libs/libevs/lib_enc/enc_gen_voic_rf.cpp b/src/libs/libevs/lib_enc/enc_gen_voic_rf.cpp new file mode 100644 index 00000000..19c04e6a --- /dev/null +++ b/src/libs/libevs/lib_enc/enc_gen_voic_rf.cpp @@ -0,0 +1,383 @@ +/*==================================================================================== + EVS Codec 3GPP TS26.443 Nov 13, 2018. Version 12.11.0 / 13.7.0 / 14.3.0 / 15.1.0 + ====================================================================================*/ + +#include +#include "options.h" +#include "cnst.h" +#include "prot.h" +#include "rom_com.h" + + +/*-------------------------------------------------------------------* + * reset_rf_indices() + * + * Initialization of oartial redundancy coding + *-------------------------------------------------------------------*/ + +void reset_rf_indices( + Encoder_State *st /* i: state structure - contains partial RF indices */ +) +{ + short i, j; + + st->rf_frame_type = 0; /* since this function is called every frame this will happen even for a SID frame, hence treating it as GSC frame, i.e no RF encoding */ + + st->rf_mem_w0 = 0; + set_f( st->rf_clip_var, 0, 6 ); + st->rf_tilt_code = 0; + set_f( st->rf_mem_syn2, 0, M ); + set_f( st->rf_dispMem, 0, 8 ); + st->rf_gc_threshold = 0; + set_f( st->rf_tilt_buf, 0, NB_SUBFR16k ); + + st->rf_target_bits = 0; + st->rf_target_bits_write = 0; + st->rf_tcxltp_pitch_int_past = st->L_frame; + st->rf_last_tns_active = 0; + st->rf_second_last_tns_active = 0; + st->rf_second_last_core= 0; + + for( i = 0; i < MAX_RF_FEC_OFFSET; i++ ) + { + st->rf_indx_frametype[i] = RF__NO_DATA; + st->rf_targetbits_buff[i] = 6; /* rf_mode: 1, rf_frame_type: 3, and fec_offset: 2 */ + st->rf_indx_lsf[i][0] = 0; + st->rf_indx_lsf[i][1] = 0; + st->rf_indx_lsf[i][2] = 0; + st->rf_indx_EsPred[i] = 0; + st->rf_indx_nelp_fid[i] = 0; + st->rf_indx_nelp_iG1[i] = 0; + st->rf_indx_nelp_iG2[i][0] = 0; + st->rf_indx_nelp_iG2[i][1] = 0; + + for( j = 0; j < NB_SUBFR16k; j++ ) + { + st->rf_indx_ltfMode[i][j] = 0; + st->rf_indx_pitch[i][j] = 0; + st->rf_indx_fcb[i][j] = 0; + st->rf_indx_gain[i][j] = 0; + } + + st->rf_clas[i] = UNVOICED_CLAS; + st->rf_gain_tcx[i] = 0; + st->rf_tcxltp_param[i] = 0; + + st->rf_indx_tbeGainFr[i] = 0; + } + + return; +} + + +/*-------------------------------------------------------------------* + * coder_acelp_rf() + * + * Encode excitation signal (partial redundancy) + *-------------------------------------------------------------------*/ + +void coder_acelp_rf( + const short target_bits, /* i: target bits */ + const float speech[], /* i : speech[-M..lg] */ + const short coder_type, /* i : coding type */ + const short rf_frame_type, /* i : rf_frame_type */ + const float A[], /* i : coefficients 4xAz[M+1] */ + const float Aq[], /* i : coefficients 4xAz_q[M+1] */ + const float voicing[], /* i : open-loop LTP gain */ + const short T_op[], /* i : open-loop LTP lag */ + const float stab_fac, /* i : LP stability factor */ + Encoder_State *st, /* i/o : coder memory state */ + ACELP_config *acelp_cfg, /* i/o: configuration of the ACELP */ + float *exc_rf, /* i/o: pointer to RF excitation */ + float *syn_rf /* i/o: pointer to RF synthesis */ +) +{ + short i, i_subfr, nSubfr; + int T0, T0_min, T0_min_frac, T0_max, T0_max_frac, T0_res; + int T0_frac; + float Es_pred_rf; + float gain_pit, gain_code, voice_fac; + float prev_gain_pit; + ACELP_CbkCorr g_corr; + float g_corr2[6]; + const float *p_A, *p_Aq; + float code[L_SUBFR]; + float xn[L_SUBFR], cn[L_SUBFR], h1[L_SUBFR]; + float xn2[L_SUBFR], y1[L_SUBFR], y2[L_SUBFR]; + float res_save; + float exc2[L_SUBFR]; + float exc_nelp[L_FRAME]; + float syn2[L_FRAME16k]; + float past_gcode, gain_inov; + short clip_gain; + float gain_code2; + float code2[L_SUBFR]; + float y22[L_SUBFR]; + float lp_select; + int *prm_rf; + + /*-----------------------------------------------------------------------* + * Initialization + *------------------------------------------------------------------------*/ + past_gcode = 0; + gain_inov = 0; + T0 = 0; + T0_res = 0; + T0_frac = 0; + gain_pit = 0; + gain_code = 0; + voice_fac = 0; + prev_gain_pit=0; + Es_pred_rf = 0; + set_f(code, 0.0f, L_SUBFR); + + /*-----------------------------------------------------------------------* + * Configure ACELP partial copy * + *-----------------------------------------------------------------------*/ + + BITS_ALLOC_config_acelp( target_bits, rf_frame_type, &(st->acelp_cfg_rf), 0, st->nb_subfr ); + + /* Reset phase dispersion */ + if( st->last_core > 0 ) + { + set_zero( st->rf_dispMem, 8 ); + } + + /*---------------------------------------------------------------* + * Calculation of LP residual (filtering through A[z] filter) + *---------------------------------------------------------------*/ + + calc_residu( speech, exc_rf, Aq, st->L_frame ); + + /*------------------------------------------------------------------------* + * Find and quantize mean_ener_code for gain quantizer * + *------------------------------------------------------------------------*/ + + Es_pred_rf = 0; + if( acelp_cfg->nrg_mode > 0 && rf_frame_type != RF_NELP ) + { + Es_pred_enc( &Es_pred_rf, &st->rf_indx_EsPred[0], st->L_frame, L_SUBFR, exc_rf, voicing, + acelp_cfg->nrg_bits, acelp_cfg->nrg_mode>1 ); + } + + /*------------------------------------------------------------------* + * ACELP subframe loop + *------------------------------------------------------------------*/ + + p_A = A; + p_Aq = Aq; + + res_save = exc_rf[0]; + nSubfr = 0; + + for( i_subfr = 0; i_subfr < st->L_frame; i_subfr += L_SUBFR ) + { + if( rf_frame_type != RF_NELP ) + { + /* Restore exc[i_subfr] and save next exc[L_SUBFR+i_subfr] */ + exc_rf[i_subfr] = res_save; + res_save = exc_rf[L_SUBFR + i_subfr]; + + /*--------------------------------------------------------------------------* + * Find target for pitch search (xn[]), target for innovation search (cn[]) * + * and impulse response of the weighted synthesis filter (h1[]). * + *--------------------------------------------------------------------------*/ + + find_targets( speech, &syn_rf[i_subfr-M], i_subfr, &(st->rf_mem_w0), + p_Aq, exc_rf, L_SUBFR, p_A, st->preemph_fac, xn, cn, h1 ); + } + + /* full frame nelp partial copy encoding */ + if( rf_frame_type == RF_NELP ) + { + if( i_subfr == 0 ) + { + nelp_encoder( st, exc_rf, exc_nelp + ,0 + ); + } + mvr2r( &exc_nelp[i_subfr], exc2, L_SUBFR ); + mvr2r( &exc_nelp[i_subfr], exc_rf, L_SUBFR ); + } + else + { + /*-----------------------------------------------------------------* + * Gain clipping test to avoid unstable synthesis on frame erasure + * or in case of floating point encoder & fixed p. decoder + *-----------------------------------------------------------------*/ + + clip_gain = gp_clip( st->core_brate, voicing, i_subfr, coder_type, xn, st->rf_clip_var ); + + /*-----------------------------------------------------------------* + * - find unity gain pitch excitation (adaptive codebook entry) * + * with fractional interpolation. * + * - find filtered pitch exc. y1[]=exc[] convolved with h1[]) * + * - compute pitch gain1 * + *-----------------------------------------------------------------*/ + + if( acelp_cfg->gains_mode[i_subfr/L_SUBFR] == 0 ) + { + gain_pit = prev_gain_pit; + } + + if ( acelp_cfg->ltp_bits != 0 ) + { + prm_rf = &st->rf_indx_pitch[0][nSubfr]; + + /* Adaptive Codebook (GC and VC) */ + Mode2_pit_encode( acelp_cfg->ltp_mode, i_subfr, &prm_rf, &exc_rf[i_subfr], + T_op, &T0_min, &T0_min_frac, &T0_max, &T0_max_frac, &T0, &T0_frac, &T0_res, h1, xn, + st->pit_min, st->pit_fr1, st->pit_fr1b, st->pit_fr2, st->pit_max, st->pit_res_max ); + + /* find ACB excitation */ + if( T0_res == (st->pit_res_max>>1) ) /* st->pit_res_max is 4 for 12.8kHz core */ + { + pred_lt4( &exc_rf[i_subfr], &exc_rf[i_subfr], T0, T0_frac<<1, L_SUBFR+1, inter4_2, L_INTERPOL2, PIT_UP_SAMP); + } + else + { + pred_lt4( &exc_rf[i_subfr], &exc_rf[i_subfr], T0, T0_frac, L_SUBFR+1, inter4_2, L_INTERPOL2, PIT_UP_SAMP); + } + + + /* filter adaptive codebook */ + lp_select = lp_filt_exc_enc( MODE2, st->core_brate, 0, (acelp_cfg->gains_mode[i_subfr/L_SUBFR]>0)?(acelp_cfg->gains_mode[i_subfr/L_SUBFR]):(100), + i_subfr, exc_rf, h1, xn, y1, xn2, L_SUBFR, st->L_frame, g_corr2, clip_gain, &(gain_pit), &(acelp_cfg->ltf_mode) ); + + if( acelp_cfg->ltf_mode == NORMAL_OPERATION ) + { + st->rf_indx_ltfMode[0][nSubfr] = lp_select; + } + + g_corr.y1y1 = g_corr2[0]; + g_corr.xy1 = -0.5f*(g_corr2[1]-0.01f)+0.01f; + } + else + { + gain_pit=0.f; + g_corr.xy1=0.f; + g_corr.y1y1=0.f; + set_zero( y1, L_SUBFR ); + set_zero( exc_rf+i_subfr, L_SUBFR ); + T0 = L_SUBFR; + T0_frac = 0; + T0_res = 1; + } + + /*----------------------------------------------------------------------* + * Encode the algebraic innovation * + *----------------------------------------------------------------------*/ + + if( acelp_cfg->fixed_cdk_index[i_subfr/L_SUBFR] >= 0 ) + { + prm_rf = &st->rf_indx_fcb[0][nSubfr]; + E_ACELP_innovative_codebook( exc_rf, T0, T0_frac, T0_res, gain_pit, st->rf_tilt_code, + acelp_cfg->fixed_cdk_index[i_subfr/L_SUBFR], + acelp_cfg->pre_emphasis, + acelp_cfg->pitch_sharpening, + acelp_cfg->phase_scrambling, + acelp_cfg->formant_enh, + acelp_cfg->formant_tilt, + acelp_cfg->formant_enh_num, + acelp_cfg->formant_enh_den, + i_subfr, p_Aq, h1, xn, cn, y1, y2, + st->acelp_autocorr, &prm_rf, code + ,st->L_frame, st->last_L_frame, st->total_brate + + ); + } + else + { + set_f( code, 0.0f, L_SUBFR ); + set_f( y2, 0.0f, L_SUBFR ); + } + + if( i_subfr < (st->L_frame - L_SUBFR) ) + { + E_corr_xy2( xn, y1, y2, g_corr2, L_SUBFR ); + g_corr.y2y2 = 0.01F + g_corr2[2]; + g_corr.xy2 = 0.01F + -0.5f*g_corr2[3]; + g_corr.y1y2 = 0.01F + 0.5f*g_corr2[4]; + + g_corr.xx = 0.01F + dotp( xn, xn, L_SUBFR ); + + /*----------------------------------------------------------------------* + * Add Gaussian excitation * + *----------------------------------------------------------------------*/ + + gain_code2 = 0.f; + set_zero( code2, L_SUBFR ); + set_zero( y22, L_SUBFR ); + + /*----------------------------------------------------------* + * - Compute the fixed codebook gain * + * - quantize fixed codebook gain * + *----------------------------------------------------------*/ + + if( acelp_cfg->gains_mode[i_subfr/L_SUBFR] != 0 ) + { + prm_rf = &st->rf_indx_gain[0][nSubfr]; + encode_acelp_gains( code, acelp_cfg->gains_mode[i_subfr/L_SUBFR], Es_pred_rf, clip_gain, &g_corr, &gain_pit, &gain_code, + &prm_rf, &past_gcode, &gain_inov, L_SUBFR, code2, &gain_code2, st->flag_noisy_speech_snr ); + } + + gp_clip_test_gain_pit( st->core_brate, gain_pit, st->rf_clip_var ); + + /*----------------------------------------------------------* + * - voice factor (for codebook tilt sharpening) * + *----------------------------------------------------------*/ + + st->rf_tilt_code = est_tilt( exc_rf+i_subfr, gain_pit, code, gain_code, &voice_fac, L_SUBFR, acelp_cfg->voice_tilt ); + + /*-----------------------------------------------------------------* + * Update memory of the weighting filter + *-----------------------------------------------------------------*/ + + st->rf_mem_w0 = xn[L_SUBFR-1] - gain_pit * y1[L_SUBFR-1] - gain_code * y2[L_SUBFR-1] - gain_code2*y22[L_SUBFR-1]; + + /*-------------------------------------------------------* + * - Find the total excitation. * + *-------------------------------------------------------*/ + + for( i = 0; i < L_SUBFR; i++ ) + { + exc2[i] = gain_pit * exc_rf[i+i_subfr]; + exc2[i] += gain_code2 * code2[i]; + exc_rf[i+i_subfr] = exc2[i] + gain_code * code[i]; + } + + /*---------------------------------------------------------* + * Enhance the excitation * + *---------------------------------------------------------*/ + + enhancer( MODE2, -1, acelp_cfg->fixed_cdk_index[i_subfr/L_SUBFR], 0, coder_type, st->L_frame, voice_fac, stab_fac, + past_gcode, gain_inov, &st->rf_gc_threshold, code, exc2, gain_pit, st->rf_dispMem ); + } + } + + if( (i_subfr < (st->L_frame - L_SUBFR)) || (rf_frame_type != RF_NELP) ) + { + /*----------------------------------------------------------* + * - compute the synthesis speech * + *----------------------------------------------------------*/ + + syn_filt( p_Aq, M, exc2, &syn2[i_subfr], L_SUBFR, st->rf_mem_syn2, 1 ); + + syn_filt( p_Aq, M, &exc_rf[i_subfr], &syn_rf[i_subfr], L_SUBFR, &syn_rf[i_subfr-M], 0 ); + + /*----------------------------------------------------------* + * Updates * + *----------------------------------------------------------*/ + + p_A += (M+1); + p_Aq += (M+1); + nSubfr++; + + /* copy current gain for next subframe use, in case there is no explicit encoding */ + prev_gain_pit = gain_pit; + } + + } /* end of subframe loop */ + + return; +} diff --git a/src/libs/libevs/lib_enc/enc_gen_voic_rf_fx.cpp b/src/libs/libevs/lib_enc/enc_gen_voic_rf_fx.cpp deleted file mode 100755 index 51ee9a97..00000000 --- a/src/libs/libevs/lib_enc/enc_gen_voic_rf_fx.cpp +++ /dev/null @@ -1,624 +0,0 @@ -/*==================================================================================== - EVS Codec 3GPP TS26.442 Apr 03, 2018. Version 12.11.0 / 13.6.0 / 14.2.0 - ====================================================================================*/ - -#include "options.h" -#include "cnst_fx.h" -#include "prot_fx.h" -#include "rom_com_fx.h" -#include "stl.h" -#include "rom_basop_util.h" -#include "basop_mpy.h" - - - -void reset_rf_indices( - Encoder_State_fx *st /* i: state structure - contains partial RF indices */ -) -{ - st->rf_frame_type = 0; /* since this function is called every frame this will happen even for a SID frame, hence treating it as GSC frame, i.e no RF encoding */ - - { - Word16 i, j; - - st->rf_mem_w0 = 0; - move16(); - set16_fx(st->rf_clip_var, 0 ,6); - st->rf_tilt_code = 0; - move16(); - set16_fx(st->rf_mem_syn2, 0, M); - st->rf_dm_fx.prev_state = 0; - move16(); - st->rf_dm_fx.prev_gain_code = 0; - move32(); - - FOR(i=0; i<6; i++) - { - st->rf_dm_fx.prev_gain_pit[i] = 0; - move16(); - } - - st->rf_gc_threshold = 0; - move32(); - set16_fx(st->rf_tilt_buf, 0, NB_SUBFR16k); - - st->rf_target_bits = 0; - move16(); - st->rf_target_bits_write = 0; - move16(); - st->rf_tcxltp_pitch_int_past = st->L_frame_fx; - move16(); - st->rf_last_tns_active = 0; - move16(); - st->rf_second_last_tns_active = 0; - move16(); - st->rf_second_last_core= 0; - move16(); - - FOR( i = 0; i < MAX_RF_FEC_OFFSET; i++) - { - st->rf_indx_frametype[i] = RF_NO_DATA; - move16(); /* rf_mode: 1, rf_frame_type: 3, and fec_offset: 2 */ - st->rf_targetbits_buff[i] = 6; - move16(); - st->rf_indx_lsf[i][0] = 0; - move16(); - st->rf_indx_lsf[i][1] = 0; - move16(); - st->rf_indx_lsf[i][2] = 0; - move16(); - st->rf_indx_EsPred[i] = 0; - move16(); - st->rf_indx_nelp_fid[i] = 0; - move16(); - st->rf_indx_nelp_iG1[i] = 0; - move16(); - st->rf_indx_nelp_iG2[i][0] = 0; - move16(); - st->rf_indx_nelp_iG2[i][1] = 0; - move16(); - - FOR( j = 0; j < NB_SUBFR16k; j++) - { - st->rf_indx_ltfMode[i][j] = 0; - move16(); - st->rf_indx_pitch[i][j] = 0; - move16(); - st->rf_indx_fcb[i][j] = 0; - move16(); - st->rf_indx_gain[i][j] = 0; - move16(); - } - - st->rf_clas[i] = UNVOICED_CLAS; - move16(); - st->rf_gain_tcx[i] = 0; - move16(); - st->rf_tcxltp_param[i] = 0; - move16(); - - st->rf_indx_tbeGainFr[i] = 0; - move16(); - } - } - - return; -} - - -/*-------------------------------------------------------------------* - * coder_acelp_rf() - * - * Encode excitation signal (partial redundancy) - *-------------------------------------------------------------------*/ -void coder_acelp_rf( - ACELP_config *acelp_cfg_rf, /*input/output: configuration of the ACELP coding*/ - const Word16 coder_type, /* input: coding type */ - const Word16 A[], /* input: coefficients 4xAz[M+1] */ - const Word16 Aq[], /* input: coefficients 4xAz_q[M+1] */ - Word16 speech[], /* input: speech[-M..lg] */ - const Word16 voicing[], /* input: open-loop LTP gain */ - const Word16 T_op[], /* input: open-loop LTP lag */ - Word16 stab_fac, - Encoder_State_fx *st, - Word16 target_bits, /* i/o : coder memory state */ - const Word16 rf_frame_type, /* i : rf_frame_type */ - Word16 *exc_rf, /* i/o: pointer to RF excitation */ - Word16 *syn_rf, /* i/o: pointer to RF synthesis */ - Word16 Q_new, - Word16 shift -) -{ - Word16 i, j, i_subfr, j_subfr; - Word16 T0, T0_min, T0_min_frac, T0_max, T0_max_frac, T0_res; - Word16 T0_frac; - Word16 tmp2; - Word16 gain_pit, voice_fac; - Word32 gain_code, Ltmp, Ltmp2; - ACELP_CbkCorr g_corr; - const Word16 *p_A, *p_Aq; - Word16 h1[L_SUBFR]; /* weighted impulse response of LP */ - Word16 code[L_SUBFR]; - Word16 xn_exp; - Word16 Q_xn; - Word16 Q_new_p5; - Word16 cn[L_SUBFR]; - Word16 xn[L_SUBFR]; - Word16 y1[L_SUBFR]; /* Filtered adaptive excitation */ - Word16 y2[L_SUBFR]; /* Filtered adaptive excitation */ - Word16 res_save; - Word16 exc_nelp[L_FRAME]; - Word16 exc2[L_SUBFR]; - Word16 syn2[L_DIV_MAX]; - Word16 gain_inov; - Word32 past_gcode; - Word16 L_frame; - Word16 clip_gain; - Word32 gain_code2; - Word16 code2[L_SUBFR]; - Word16 y22[L_SUBFR]; /* Filtered adaptive excitation */ - Word32 gain_code_vect[2]; - Word16 *prm_rf; - Word16 Es_pred_rf; - Word16 nSubfr; - Word16 prev_gain_pit; - Word16 rf_coder_type; - Word16 lp_select; - - /* to avoid compilation warnings */ - past_gcode = 0; - gain_inov = 0; - T0 = 0; - T0_frac = 0; - T0_res = 0; - gain_pit = 0; - gain_code = 0; - voice_fac = 0; - prev_gain_pit=0; - Es_pred_rf = 0; - set16_fx(code, 0, L_SUBFR); - - /*-----------------------------------------------------------------------* - * Configure ACELP partial copy * - *------------------------------------------------------------------------*/ - tmp2 = BITS_ALLOC_config_acelp( target_bits, rf_frame_type, acelp_cfg_rf, 0, st->nb_subfr ); - - /* Init Framing parameters */ - L_frame = st->L_frame_fx; - - /*------------------------------------------------------------------------* - * Initialize buffers * - *------------------------------------------------------------------------*/ - - /* Rescale ACELP memories, which were not scaled yet*/ - xn_exp = sub(sub(15+1, Q_new),shift); - Q_xn = add(sub(Q_new,1),shift); - Q_new_p5 = add(Q_new, 5); - - /* Reset phase dispersion */ - IF (st->last_core_fx > ACELP_CORE) - { - st->rf_dm_fx.prev_gain_code = 0; - set16_fx(st->rf_dm_fx.prev_gain_pit, 0, 6); - st->rf_dm_fx.prev_state = 0; - } - - /* calculate residual */ - p_Aq = Aq; - FOR (i_subfr=0; i_subfrnrg_mode > 0 && sub(rf_frame_type,RF_NELP) != 0 ) - { - Es_pred_enc_fx(&Es_pred_rf, &st->rf_indx_EsPred[0], L_frame, exc_rf, voicing, - acelp_cfg_rf->nrg_bits, acelp_cfg_rf->nrg_mode>1, Q_new); - } - - /*------------------------------------------------------------------------* - * Loop for every subframe in the analysis frame * - *------------------------------------------------------------------------* - * To find the pitch and innovation parameters. The subframe size is * - * L_SUBFR and the loop is repeated L_FRAME_PLUS/L_SUBFR * - * times. * - * - compute impulse response of weighted synthesis filter (h1[]) * - * - compute the target signal for pitch search * - * - find the closed-loop pitch parameters * - * - encode the pitch delay * - * - update the impulse response h1[] by including fixed-gain pitch * - * - find target vector for codebook search * - * - correlation between target vector and impulse response * - * - codebook search * - * - encode codebook address * - * - VQ of pitch and codebook gains * - * - find synthesis speech * - * - update states of weighting filter * - *------------------------------------------------------------------------*/ - p_A = A; - p_Aq = Aq; - - res_save = exc_rf[0]; - nSubfr = 0; - j_subfr = 0; - - FOR (i_subfr=0; i_subfrrf_mem_w0), - p_Aq, - exc_rf, - L_SUBFR, - p_A, - st->preemph_fac, - xn, - cn - ,h1 - ); - - /*---------------------------------------------------------------* - * Compute impulse response, h1[], of weighted synthesis filter * - *---------------------------------------------------------------*/ - Scale_sig(h1, L_SUBFR, add(1,shift)); /* Q13+1-shift */ - - /* scaling of xn[] to limit dynamic at 12 bits */ - Scale_sig(xn, L_SUBFR, shift); - - } - - - /*-----------------------------------------------------------------* - * Gain clipping test to avoid unstable synthesis on frame erasure - * or in case of floating point encoder & fixed p. decoder - *-----------------------------------------------------------------*/ - /* full frame nelp partial copy encoding */ - IF( sub(rf_frame_type,RF_NELP) == 0 ) - { - IF( i_subfr == 0 ) - { - nelp_encoder_fx( st, exc_rf, exc_nelp, &Q_new,0); - } - Copy( &exc_nelp[i_subfr], exc2, L_SUBFR ); - Copy( &exc_nelp[i_subfr], exc_rf, L_SUBFR ); - - } - ELSE - { - clip_gain = Mode2_gp_clip( voicing, i_subfr, coder_type, xn, st->rf_clip_var, L_SUBFR, Q_xn ); - - /*-----------------------------------------------------------------* - * - find unity gain pitch excitation (adaptive codebook entry) * - * with fractional interpolation. * - * - find filtered pitch exc. y1[]=exc[] convolved with h1[]) * - * - compute pitch gain1 * - *-----------------------------------------------------------------*/ - if( acelp_cfg_rf->gains_mode[i_subfr/L_SUBFR] == 0 ) - { - gain_pit = prev_gain_pit; - move16(); - } - - IF ( acelp_cfg_rf->ltp_bits!=0 ) - { - prm_rf = &st->rf_indx_pitch[0][nSubfr]; - - /* Adaptive Codebook (GC and VC) */ - Mode2_pit_encode( acelp_cfg_rf->ltp_mode, - i_subfr, - &prm_rf, - &exc_rf[i_subfr], - T_op, - &T0_min, - &T0_min_frac, - &T0_max, - &T0_max_frac, - &T0, - &T0_frac, - &T0_res, - h1, - xn, - st->pit_min, - st->pit_fr1, - st->pit_fr1b, - st->pit_fr2, - st->pit_max, - st->pit_res_max); - - /* find ACB excitation */ - rf_coder_type = 100; - move16(); - if( acelp_cfg_rf->gains_mode[i_subfr/L_SUBFR] > 0 ) - { - rf_coder_type = acelp_cfg_rf->gains_mode[i_subfr/L_SUBFR]; - move16(); - } - - E_ACELP_adaptive_codebook( exc_rf, - T0, - T0_frac, - T0_res, - st->pit_res_max, - acelp_cfg_rf->ltf_mode, - i_subfr, - L_SUBFR, - L_frame, - h1, - clip_gain, - xn, - y1, - &g_corr, - &prm_rf, - &gain_pit, - xn_exp - ,st->rf_mode - ,rf_coder_type - ,&lp_select - ); - - - - if( acelp_cfg_rf->ltf_mode == NORMAL_OPERATION ) - { - st->rf_indx_ltfMode[0][nSubfr] = lp_select; - } - } - ELSE IF ( acelp_cfg_rf->ltp_bits==0 ) - { - /* No adaptive codebook (UC) */ - gain_pit=0; - g_corr.xy1=0; - g_corr.xy1_e=0; - g_corr.y1y1=0x4000; /* set to 0x4000 instead of 0 to avoid assert failue in gain_enc : assert(coeff0 >= 0x4000) */ - g_corr.y1y1_e=0; - set16_fx(y1,0,L_SUBFR); - set16_fx(exc_rf+i_subfr,0,L_SUBFR); - T0 = L_SUBFR; - T0_frac = 0; - T0_res = 1; - } - - - /*----------------------------------------------------------------------* - * Encode the algebraic innovation * - *----------------------------------------------------------------------*/ - IF( acelp_cfg_rf->fixed_cdk_index[i_subfr/L_SUBFR] >= 0 ) - { - prm_rf = &st->rf_indx_fcb[0][nSubfr]; - - E_ACELP_innovative_codebook( exc_rf, - T0, - T0_frac, - T0_res, - gain_pit, - st->rf_tilt_code, - acelp_cfg_rf->fixed_cdk_index[j_subfr], - acelp_cfg_rf->formant_enh, - acelp_cfg_rf->formant_tilt, - acelp_cfg_rf->formant_enh_num, - acelp_cfg_rf->formant_enh_den, - acelp_cfg_rf->pitch_sharpening, - acelp_cfg_rf->pre_emphasis, - acelp_cfg_rf->phase_scrambling, - i_subfr, - p_Aq, - h1, - xn, - cn, - y1, - y2, - st->acelp_autocorr, - &prm_rf, - code, - shift - ,st->L_frame_fx, - st->last_L_frame_fx, - st->total_brate_fx - ); - } - ELSE - { - set16_fx(code, 0, L_SUBFR); - set16_fx(y2, 0, L_SUBFR); - } - - IF( i_subfr < sub(L_frame,L_SUBFR) ) - { - E_ACELP_xy2_corr(xn, y1, y2, &g_corr, L_SUBFR, Q_xn); - - g_corr.y2y2_e = sub(g_corr.y2y2_e, 18); /* -18 (y2*y2: Q9*Q9) */ - g_corr.xy2_e = sub(g_corr.xy2_e, add(Q_xn,9)); /* -(Q_xn+9) (xn: Q_xn y2: Q9) */ - g_corr.y1y2_e = sub(g_corr.y1y2_e, add(Q_xn,9)); /* -(Q_xn+9) (y1: Q_xn y2: Q9) */ - g_corr.xx_e = sub(g_corr.xx_e, add(Q_xn,Q_xn)); /* -(Q_xn+Q_xn) (xn: Q_xn) */ - - - /*----------------------------------------------------------------------* - * Add Gaussian excitation * - *----------------------------------------------------------------------*/ - gain_code2 = L_deposit_l(0); - set16_fx(code2, 0, L_SUBFR); - set16_fx(y22, 0, L_SUBFR); - - - - - /*----------------------------------------------------------* - * - Compute the fixed codebook gain * - * - quantize fixed codebook gain * - *----------------------------------------------------------*/ - IF( acelp_cfg_rf->gains_mode[i_subfr/L_SUBFR] != 0 ) - { - prm_rf = &st->rf_indx_gain[0][nSubfr]; - - encode_acelp_gains( code, - acelp_cfg_rf->gains_mode[j_subfr], - Es_pred_rf, - clip_gain, - &g_corr, - &gain_pit, - &gain_code, - &prm_rf, - &past_gcode, - &gain_inov, - L_SUBFR, - code2, - &gain_code2, - st->flag_noisy_speech_snr - ); - } - - - - gp_clip_test_gain_pit_fx( st->core_brate_fx, gain_pit, st->rf_clip_var ); - - gain_code_vect[0] = gain_code; - move32(); - gain_code_vect[1] = gain_code; - move32(); - - /*----------------------------------------------------------* - * - voice factor (for pitch enhancement) * - *----------------------------------------------------------*/ - E_UTIL_voice_factor( exc_rf, - i_subfr, - code, - gain_pit, - gain_code, - &voice_fac, - &(st->rf_tilt_code), - L_SUBFR, - acelp_cfg_rf->voice_tilt, - Q_new, - shift - ); - - - /*-----------------------------------------------------------------* - * Update memory of the weighting filter - *-----------------------------------------------------------------*/ - /* st_fx->_rf_mem_w0 = xn[L_SUBFR-1] - (gain_pit*y1[L_SUBFR-1]) - (gain_code*y2[L_SUBFR-1]); */ - Ltmp = Mpy_32_16_1(gain_code, y2[L_SUBFR-1]); - Ltmp = L_shl(Ltmp, add(5,Q_xn)); - Ltmp = L_mac(Ltmp, y1[L_SUBFR-1], gain_pit); - /* Add Gaussian contribution*/ - Ltmp2 = Mpy_32_16_1(gain_code2, y22[L_SUBFR-1]); - Ltmp2 = L_shl(Ltmp2, add(5,Q_xn)); - Ltmp = L_add(Ltmp, Ltmp2); - st->rf_mem_w0 =sub(xn[L_SUBFR-1], round_fx(L_shl(Ltmp, 1))); - move16(); - BASOP_SATURATE_WARNING_OFF; - st->rf_mem_w0 =shr(st->rf_mem_w0, shift); /*Qnew-1*/ - BASOP_SATURATE_WARNING_ON; - - - - /*-------------------------------------------------------* - * - Find the total excitation. * - *-------------------------------------------------------*/ - - tmp2 = shr(L_SUBFR, 1); - FOR (j = 0; j < 2; j++) - { - FOR (i = sub(tmp2, shr(L_SUBFR, 1)); i < tmp2; i++) - { - /* code in Q9, gain_pit in Q14; exc Q_new */ - Ltmp = Mpy_32_16_1(gain_code2, code2[i]); - Ltmp = L_shl(Ltmp, Q_new_p5); - Ltmp = L_mac(Ltmp, gain_pit, exc_rf[i+i_subfr]); - BASOP_SATURATE_WARNING_OFF - exc2[i] = round_fx(L_shl(Ltmp, 1)); - BASOP_SATURATE_WARNING_ON - - Ltmp2 = Mpy_32_16_1(gain_code_vect[j], code[i]); - Ltmp2 = L_shl(Ltmp2, Q_new_p5); - Ltmp = L_add(Ltmp, Ltmp2); - BASOP_SATURATE_WARNING_OFF - Ltmp = L_shl(Ltmp, 1); /* saturation can occur here */ - BASOP_SATURATE_WARNING_ON - exc_rf[i + i_subfr] = round_fx(Ltmp); - } - tmp2 = L_SUBFR; - } - - - - /*---------------------------------------------------------* - * Enhance the excitation * - *---------------------------------------------------------*/ - E_UTIL_enhancer( voice_fac, - stab_fac, - past_gcode, - gain_inov, - &st->rf_gc_threshold, - code, - exc2, - gain_pit, - &st->rf_dm_fx.prev_gain_code, - st->rf_dm_fx.prev_gain_pit, - &st->rf_dm_fx.prev_state, - coder_type, - acelp_cfg_rf->fixed_cdk_index[j_subfr], - L_SUBFR, - L_frame, - Q_new - ); - } - } - - IF( i_subfr < sub(L_frame,L_SUBFR) || sub(rf_frame_type,RF_NELP) != 0 ) - { - - /*----------------------------------------------------------* - * - compute the synthesis speech * - *----------------------------------------------------------*/ - - E_UTIL_synthesis(1, p_Aq, exc2, &syn2[i_subfr], L_SUBFR, st->rf_mem_syn2, 1, M); - - E_UTIL_synthesis(1, p_Aq, &exc_rf[i_subfr], &syn_rf[i_subfr], L_SUBFR, &syn_rf[i_subfr-M], 0, M); - - /*----------------------------------------------------------* - * Update * - *----------------------------------------------------------*/ - p_A += (M+1); - p_Aq += (M+1); - nSubfr++; - - st->gain_code[j_subfr] = gain_code; - j_subfr = add(j_subfr, 1); - - /* copy current gain for next subframe use, in case there is no explicit encoding */ - prev_gain_pit = gain_pit; - - } - - - - } /* end of subframe loop */ - - - return; -} - - diff --git a/src/libs/libevs/lib_enc/enc_higher_acelp.cpp b/src/libs/libevs/lib_enc/enc_higher_acelp.cpp new file mode 100644 index 00000000..341fe2ff --- /dev/null +++ b/src/libs/libevs/lib_enc/enc_higher_acelp.cpp @@ -0,0 +1,331 @@ +/*==================================================================================== + EVS Codec 3GPP TS26.443 Nov 13, 2018. Version 12.11.0 / 13.7.0 / 14.3.0 / 15.1.0 + ====================================================================================*/ + +#include +#include "options.h" +#include "cnst.h" +#include "prot.h" +#include "rom_com.h" + + +/*---------------------------------------------------------------------* + * Local functions + *---------------------------------------------------------------------*/ + +static void find_cn( const float xn[], const float Ap[], const float *p_Aq, float cn[] ); + +/*-----------------------------------------------------------------* + * Transform domain contribution encoding + *-----------------------------------------------------------------*/ + +void transf_cdbk_enc( + Encoder_State *st, /* i/o: encoder state structure */ + const long core_brate, /* i : core bitrate */ + const short extl, /* i : extension layer */ + const short coder_type, /* i : coding type */ + const short harm_flag_acelp,/* i : harmonic flag for higher rates ACELP */ + const short i_subfr, /* i : subframe index */ + const short tc_subfr, /* i : TC subframe index */ + float cn[], /* i/o: target vector in residual domain */ + float exc[], /* i/o: pointer to excitation signal frame */ + const float *p_Aq, /* i : 12k8 Lp coefficient */ + const float Ap[], /* i : weighted LP filter coefficients */ + const float h1[], /* i : weighted filter input response */ + float xn[], /* i/o: target vector */ + float xn2[], /* i/o: target vector for innovation search */ + float y1[], /* i/o: zero-memory filtered adaptive excitation */ + const float y2[], /* i : zero-memory filtered innovative excitation */ + const float Es_pred, /* i : predicited scaled innovation energy */ + float *gain_pit, /* i/o: adaptive excitation gain */ + const float gain_code, /* i : innovative excitation gain */ + float g_corr[], /* o : ACELP correlation values */ + const short clip_gain, /* i : adaptive gain clipping flag */ + float *mem_deemp, /* i/o: prequantizer deemhasis memory */ + float *mem_preemp, /* i/o: prequantizer preemhasis memory */ + float *gain_preQ, /* o : prequantizer excitation gain */ + float code_preQ[], /* o : prequantizer excitation */ + short *unbits /* o : number of AVQ unused bits */ +) +{ + short i, index, nBits, Nsv; + float x_in[L_SUBFR], x_tran[L_SUBFR], temp; + int x_norm[L_SUBFR+L_SUBFR/WIDTH_BAND]; + float corr, ener; + short nq[L_SUBFR/WIDTH_BAND]; + + /*--------------------------------------------------------------* + * Set bit-allocation + *--------------------------------------------------------------*/ + + Nsv = 8; + nBits = AVQ_bits_16kHz_tbl[BIT_ALLOC_IDX_16KHZ(core_brate, coder_type, i_subfr, TC_SUBFR2IDX_16KHZ(tc_subfr))]; + + /* increase # of AVQ allocated bits by unused bits from the previous subframe */ + nBits += (*unbits); + + /*--------------------------------------------------------------* + * Compute/Update target + * For inactive frame, find target in residual domain + * Deemphasis + *--------------------------------------------------------------*/ + + if ( coder_type == INACTIVE ) + { + for( i=0; i ACELP_24k40 && core_brate <= ACELP_32k && !harm_flag_acelp ) + { + mvr2r( x_in, x_tran, L_SUBFR ); + } + else + { + edct2( L_SUBFR, -1, x_in, x_tran, ip_edct2_64, w_edct2_64 ); + } + + /*--------------------------------------------------------------* + * Split algebraic vector quantizer based on RE8 lattice + *--------------------------------------------------------------*/ + + AVQ_cod( x_tran, x_norm, nBits, Nsv ); + + /*--------------------------------------------------------------* + * Find prequantizer excitation gain + * Quantize the gain + *--------------------------------------------------------------*/ + + corr = 0; + ener = 1e-6f; + + for (i = 0; i < Nsv*8; i++) + { + corr += x_tran[i]*(float)x_norm[i]; + ener += (float)x_norm[i]*(float)x_norm[i]; + } + + *gain_preQ = corr/ener; + + if ( coder_type == INACTIVE ) + { + *gain_preQ /= gain_code; + + if( core_brate == ACELP_64k ) + { + index = usquant( *gain_preQ, gain_preQ, G_AVQ_MIN_INACT_64k, G_AVQ_DELTA_INACT_64k, (1 << G_AVQ_BITS) ); + } + else if( core_brate == ACELP_48k ) + { + index = usquant( *gain_preQ, gain_preQ, G_AVQ_MIN_INACT_48k, G_AVQ_DELTA_INACT_48k, (1 << G_AVQ_BITS) ); + } + else + { + index = usquant( *gain_preQ, gain_preQ, G_AVQ_MIN_INACT, G_AVQ_DELTA_INACT, (1 << G_AVQ_BITS) ); + } + + *gain_preQ *= gain_code; + } + else + { + if( Es_pred < 0 ) + { + temp = 0.25f * fabs(Es_pred); + } + else + { + temp = Es_pred; + } + *gain_preQ /= temp; + + if( core_brate > ACELP_24k40 && core_brate <= ACELP_32k ) + { + index = gain_quant( gain_preQ, 0.1f*G_AVQ_MIN, G_AVQ_MAX, G_AVQ_BITS ); + } + else + { + index = gain_quant( gain_preQ, G_AVQ_MIN, G_AVQ_MAX, G_AVQ_BITS ); + } + *gain_preQ *= temp; + } + + push_indice( st, IND_AVQ_GAIN, index, G_AVQ_BITS ); + + /*--------------------------------------------------------------* + * Encode and multiplex subvectors into bit-stream + *--------------------------------------------------------------*/ + + AVQ_encmux( st, -1, x_norm, &nBits, Nsv, nq ); + + /* save # of AVQ unused bits for next subframe */ + *unbits = nBits; + + /* at the last subframe, write AVQ unused bits */ + if( i_subfr == 4*L_SUBFR && extl != SWB_BWE_HIGHRATE && extl != FB_BWE_HIGHRATE ) + { + while( *unbits > 0 ) + { + i = min(*unbits, 16); + push_indice( st, IND_UNUSED, 0, i ); + *unbits -= i; + } + } + + /*--------------------------------------------------------------* + * DCT transform + *--------------------------------------------------------------*/ + + for( i=0; i ACELP_24k40 && core_brate <= ACELP_32k && !harm_flag_acelp ) + { + mvr2r( x_tran, code_preQ, L_SUBFR ); + } + else + { + edct2( L_SUBFR, 1, x_tran, code_preQ, ip_edct2_64, w_edct2_64 ); + } + + /*--------------------------------------------------------------* + * Preemphasise + *--------------------------------------------------------------*/ + + /* in extreme cases at subframe boundaries, lower the preemphasis memory to avoid a saturation */ + if( (nq[7] != 0) && (st->last_nq_preQ - nq[0] > 7) ) + { + *mem_preemp /= 16; + } + + st->last_nq_preQ = nq[7]; + + preemph( code_preQ, FAC_PRE_AVQ, L_SUBFR, mem_preemp ); + + /*--------------------------------------------------------------* + * For inactive segments + * - Zero-memory filtered pre-filter excitation + * - Update of targets and gain_pit + * For active segments + * - Update xn[L_subfr-1] for updating the memory of the weighting filter + *--------------------------------------------------------------*/ + + if ( coder_type == INACTIVE ) + { + temp = code_preQ[0] * h1[L_SUBFR-1]; + + for( i=1; i 0.95f ) + { + *gain_pit = 0.95f; + } + + updt_tar( xn, xn2, y1, *gain_pit, L_SUBFR ); + } + + st->use_acelp_preq = 1; + + return; + +} + +/*-------------------------------------------------------------------* + * Find target in residual domain - cn[] + *-------------------------------------------------------------------*/ + +static void find_cn( + const float xn[], /* i : target signal */ + const float Ap[], /* i : weighted LP filter coefficients */ + const float *p_Aq, /* i : 12k8 LP coefficients */ + float cn[] /* o : target signal in residual domain */ +) +{ + float tmp, tmp_fl[L_SUBFR+M]; + + set_f( tmp_fl, 0, M ); + mvr2r( xn, tmp_fl+M, L_SUBFR ); + tmp = 0.0f; + + preemph( tmp_fl+M, PREEMPH_FAC_16k, L_SUBFR, &tmp ); + syn_filt( Ap, M, tmp_fl+M, tmp_fl+M, L_SUBFR, tmp_fl, 0 ); + residu( p_Aq, M, tmp_fl+M, cn, L_SUBFR ); + + return; +} + +/*---------------------------------------------------------------* + * gain_quant() + * + * Quantization of gains between the specified range + * using the specified number of levels. + *---------------------------------------------------------------*/ + +short gain_quant( /* o: quantization index */ + float *gain, /* i/o: quantized gain */ + const float min, /* i: value of lower limit */ + const float max, /* i: value of upper limit */ + const short bits /* i: number of bits to quantize */ +) +{ + short index, levels; + float tmp, c_min, c_mult; + + levels = 1< levels-1 ) + { + index = levels-1; + } + + *gain = (float)pow( 10.0, (((float)index)/c_mult) + c_min ); + + return(index); +} diff --git a/src/libs/libevs/lib_enc/enc_higher_acelp_fx.cpp b/src/libs/libevs/lib_enc/enc_higher_acelp_fx.cpp deleted file mode 100755 index cc92bf87..00000000 --- a/src/libs/libevs/lib_enc/enc_higher_acelp_fx.cpp +++ /dev/null @@ -1,456 +0,0 @@ -/*==================================================================================== - EVS Codec 3GPP TS26.442 Apr 03, 2018. Version 12.11.0 / 13.6.0 / 14.2.0 - ====================================================================================*/ - -#include "options.h" /* Compilation switches */ -#include "cnst_fx.h" /* Common constants */ -#include "prot_fx.h" /* Function prototypes */ -#include "rom_com_fx.h" /* Static table prototypes */ -#include "stl.h" - -/*---------------------------------------------------------------------* - * Local functions - *---------------------------------------------------------------------*/ -static void find_cn_fx( const Word16 xn[], const Word16 Ap[], const Word16 *p_Aq, Word16 cn[] ); - -/*-----------------------------------------------------------------* - * Transform domain contribution encoding - *-----------------------------------------------------------------*/ -#define Q_MINUS 4 -void transf_cdbk_enc_fx( - Encoder_State_fx *st_fx, /* i/o: encoder state structure */ - const Word32 core_brate, /* i : core bitrate */ - const Word16 extl, /* i : extension layer */ - const Word16 coder_type, /* i : coding type */ - const Word16 harm_flag_acelp,/* i : harmonic flag for higher rates ACELP */ - const Word16 i_subfr, /* i : subframe index */ - const Word16 tc_subfr, /* i : TC subframe index */ - Word16 cn[], /* i/o: target vector in residual domain */ - Word16 exc[], /* i/o: pointer to excitation signal frame */ - const Word16 *p_Aq, /* i : 12k8 Lp coefficient */ - const Word16 Ap[], /* i : weighted LP filter coefficients */ - const Word16 h1[], /* i : weighted filter input response */ - Word16 xn[], /* i/o: target vector */ - Word16 xn2[], /* i/o: target vector for innovation search */ - Word16 y1[], /* i/o: zero-memory filtered adaptive excitation */ - const Word16 y2[], /* i : zero-memory filtered innovative excitation */ - const Word16 Es_pred, /* i : predicited scaled innovation energy */ - Word16 *gain_pit, /* i/o: adaptive excitation gain */ - const Word32 gain_code, /* i : innovative excitation gain */ - Word16 g_corr[], /* o : ACELP correlation values */ - const Word16 clip_gain, /* i : adaptive gain clipping flag */ - Word16 *mem_deemp, /* i/o: prequantizer deemhasis memory */ - Word16 *mem_preemp, /* i/o: prequantizer preemhasis memory */ - Word16 *gain_preQ, /* o : prequantizer excitation gain */ - Word16 code_preQ[], /* o : prequantizer excitation */ - Word16 *unbits, /* o : number of AVQ unused bits */ - const Word16 Q_new, /* i : Current frame scaling */ - const Word16 shift /* i : shifting applied to y1, xn,... */ -) -{ - Word16 i, index, nBits, Nsv, Es_pred_loc; - Word16 x_in[L_SUBFR], x_tran[L_SUBFR], gcode16, stmp; - Word16 e_corr, m_corr, e_ener, m_ener, m_den, e_den; - Word16 x_norm[L_SUBFR+L_SUBFR/WIDTH_BAND]; - Word32 L_corr, L_ener, Ltmp, Ltmp1; - Word16 nq[L_SUBFR/WIDTH_BAND]; - Word32 out32[L_SUBFR]; - Word16 Qdct; - - /*--------------------------------------------------------------* - * Set bit-allocation - *--------------------------------------------------------------*/ - - Nsv = 8; - move16(); - nBits = AVQ_bits_16kHz_tbl[BIT_ALLOC_IDX_16KHZ_fx(core_brate, coder_type, i_subfr, TC_SUBFR2IDX_16KHZ_fx(tc_subfr))]; - move16(); - - /* increase # of AVQ allocated bits by unused bits from the previous subframe */ - nBits = add(nBits, *unbits); - - /*--------------------------------------------------------------* - * Compute/Update target - * For inactive frame, find target in residual domain - * Deemphasis - *--------------------------------------------------------------*/ - IF (sub(coder_type,INACTIVE) == 0) - { - gcode16 = round_fx(L_shl(gain_code, Q_new)); - FOR( i=0; i 0 && !harm_flag_acelp ) - { - Copy_Scale_sig( x_in, x_tran, L_SUBFR,-Q_MINUS+1 ); /*Q_new-1 -> Q_new-4*/ - /*Copy( x_in, x_tran, L_SUBFR );*/ - Qdct = sub(Q_new,Q_MINUS); - } - ELSE - { - Qdct = 0; - move16(); - edct2_fx( L_SUBFR, -1, x_in, out32, &Qdct, ip_edct2_64_fx, w_edct2_64_fx ); - Qdct = negate(Qdct); - Copy_Scale_sig_32_16(out32, x_tran, L_SUBFR, sub(Qdct,Q_MINUS-1)); /* Output in Q_new-4 */ - Qdct = sub(Q_new,Q_MINUS); - } - - /*--------------------------------------------------------------* - * Split algebraic vector quantizer based on RE8 lattice - *--------------------------------------------------------------*/ - AVQ_cod_fx( x_tran, x_norm, nBits, Nsv, 0 ); - - /*--------------------------------------------------------------* - * Find prequantizer excitation gain - * Quantize the gain - *--------------------------------------------------------------*/ - L_corr = L_deposit_l(0); - L_ener = L_deposit_l(0); - FOR (i = 0; i < Nsv*8; i++) - { - /*fcorr += fx_tran[i]*(float)ix_norm[i];*/ - /*fener += (float)ix_norm[i]*(float)ix_norm[i];*/ - stmp = shl(x_norm[i],Q_AVQ_OUT ); - L_corr = L_mac(L_corr, x_tran[i], stmp); - L_ener = L_mac(L_ener, stmp, stmp); - } - L_ener = L_max(L_ener,1); - - /* No negative gains allowed in the quantizer*/ - L_corr = L_max(L_corr,0); - - e_corr = norm_l(L_corr); - m_corr = extract_h(L_shl(L_corr, e_corr)); - e_corr = sub(30, add(e_corr,sub(Qdct,Q_AVQ_OUT))); - e_ener = norm_l(L_ener); - m_ener = extract_h(L_shl(L_ener, e_ener)); - e_ener = sub(30, e_ener); - - IF(sub(m_corr,m_ener)>0) - { - m_corr = shr(m_corr,1); - e_corr = add(e_corr,1); - } - m_corr = div_s(m_corr, m_ener); - e_corr = sub(e_corr, e_ener); - Ltmp = L_shl(m_corr, s_min(add(e_corr,1),31)); /* Lgain in Q16 */ - IF ( sub(coder_type,INACTIVE) == 0 ) - { - Ltmp1 = L_max(gain_code,1); - e_den = norm_l(Ltmp1); - m_den = extract_h(L_shl(Ltmp1, e_den)); - /* ensure m_corr < m_den */ - test(); - IF( m_corr>0 && m_den >0) - { - m_corr = div_s(16384, m_den); - e_corr = sub(14+4, e_den); - Ltmp = L_shr(Mult_32_16(Ltmp, m_corr), e_corr); /*Q12*/ - stmp = round_fx(L_shl(Ltmp,16)); - } - ELSE - { - stmp = 0; - move16(); - } - IF( L_sub(core_brate,ACELP_64k) == 0 ) - { - index = usquant_fx( stmp, &stmp, G_AVQ_MIN_INACT_64k_Q12, G_AVQ_DELTA_INACT_64k_Q12>>1, (1 << G_AVQ_BITS) ); - } - ELSE IF( L_sub(core_brate,ACELP_48k) == 0 ) - { - index = usquant_fx( stmp, &stmp, G_AVQ_MIN_INACT_48k_Q12, G_AVQ_DELTA_INACT_48k_Q12>>1, (1 << G_AVQ_BITS) ); - } - ELSE - { - index = usquant_fx( stmp, &stmp, G_AVQ_MIN_INACT_Q12, G_AVQ_DELTA_INACT_Q12>>1, (1 << G_AVQ_BITS) ); - } - Ltmp = Mult_32_16(gain_code,stmp); /* Q16 * Q12 - 15 -> Q13*/ - Ltmp = L_shl(Ltmp,5); /* Q13 -> Q18*/ - *gain_preQ = round_fx(Ltmp); /* Q2*/ - } - ELSE - { - IF( Es_pred < 0 ) - { - Es_pred_loc = shr(negate(Es_pred),2); - } - ELSE - { - Es_pred_loc = Es_pred; - move16(); - } - - e_den = norm_s(Es_pred_loc); - m_den = shl(Es_pred_loc, e_den); - /* ensure m_corr < m_den */ - test(); - IF( m_corr>0 && m_den >0) - { - m_corr = div_s(16384, m_den); - e_corr = sub(14-8, e_den); - Ltmp = L_shr(Mult_32_16(Ltmp, m_corr), e_corr); - } - ELSE - { - Ltmp = L_deposit_l(0); - } - test(); - IF( L_sub(core_brate,ACELP_32k) <= 0 && L_sub(core_brate,ACELP_24k40) > 0 ) - { - index = gain_quant_fx(&Ltmp, &stmp, LG10_G_AVQ_MIN_32kbps_Q14, LG10_G_AVQ_MAX_Q13, G_AVQ_BITS, &e_den ); - } - ELSE - { - index = gain_quant_fx(&Ltmp, &stmp, LG10_G_AVQ_MIN_Q14, LG10_G_AVQ_MAX_Q13, G_AVQ_BITS, &e_den ); - } - Ltmp = L_mult(stmp,Es_pred_loc); /* Q0*Q8 -> Q9*/ - Ltmp = L_shl(Ltmp,add(e_den,9)); /* Q18*/ - *gain_preQ = round_fx(Ltmp); /* Q2*/ - } - push_indice_fx( st_fx, IND_AVQ_GAIN, index, G_AVQ_BITS ); - - /*--------------------------------------------------------------* - * Encode and multiplex subvectors into bit-stream - *--------------------------------------------------------------*/ - - AVQ_encmux_fx( st_fx, -1, x_norm, &nBits, Nsv, nq ); - - /* save # of AVQ unused bits for next subframe */ - *unbits = nBits; - move16(); - - /* at the last subframe, write AVQ unused bits */ - test(); - test(); - IF( sub(i_subfr,4*L_SUBFR) == 0 && sub(extl,SWB_BWE_HIGHRATE) != 0 && sub(extl,FB_BWE_HIGHRATE) != 0 ) - { - WHILE( *unbits > 0 ) - { - i = s_min(*unbits, 16); - push_indice_fx( st_fx, IND_UNUSED, 0, i ); - *unbits -= i; - } - } - - /*--------------------------------------------------------------* - * DCT transform - *--------------------------------------------------------------*/ - - FOR( i=0; i 0 && !harm_flag_acelp ) - { - Copy( x_tran, code_preQ, L_SUBFR ); - } - ELSE - { - Qdct = 0; - move16(); - edct2_fx( L_SUBFR, 1, x_tran, out32, &Qdct, ip_edct2_64_fx, w_edct2_64_fx ); - /*qdct = sub(Q_AVQ_OUT_DEC,qdct+Q_AVQ_OUT_DEC);*/ - Qdct = negate(Qdct); - Copy_Scale_sig_32_16(out32, code_preQ, L_SUBFR, Qdct); /* Output in Q_AVQ_OUT_DEC */ - /*qdct = Q_AVQ_OUT_DEC;*/ - } - - /*--------------------------------------------------------------* - * Preemphasise - *--------------------------------------------------------------*/ - /* in extreme cases at subframe boundaries, lower the preemphasis memory to avoid a saturation */ - test(); - if( (nq[7] != 0) && (sub( sub(st_fx->last_nq_preQ_fx, nq[0]), 7) > 0) ) - { - /* *mem_preemp /= 16; */ - *mem_preemp = shr(*mem_preemp,4); - move16(); - } - st_fx->last_nq_preQ_fx = nq[7]; - move16(); - preemph_fx( code_preQ, FAC_PRE_AVQ_FX, L_SUBFR, mem_preemp ); - - /*--------------------------------------------------------------* - * For inactive segments - * - Zero-memory filtered pre-filter excitation - * - Update of targets and gain_pit - * For inactive segments - * - Update xn[L_subfr-1] for updating the memory of the weighting filter - *--------------------------------------------------------------*/ - - IF ( sub(coder_type,INACTIVE) == 0 ) - { - /*ftemp = fcode_preQ[0] *fh1[L_SUBFR-1];*/ - Ltmp = L_mult(code_preQ[0], h1[L_SUBFR-1]); /*1+14+shift + Q_AVQ_OUT */ - FOR( i=1; i Q_new + shift -1 */ - } - ELSE - { - conv_fx( code_preQ, h1, x_tran, L_SUBFR ); - updt_tar_HR_fx( cn, cn, code_preQ, *gain_preQ, sub(Q_new, add(-15+2,Q_AVQ_OUT_DEC)), L_SUBFR ); - - updt_tar_HR_fx( xn, xn, x_tran, *gain_preQ, sub(Q_new, add(-15+2,Q_AVQ_OUT_DEC)), L_SUBFR ); - *gain_pit = corr_xy1_fx( xn, y1, g_corr, L_SUBFR, 0 ); - - /* clip gain if necessary to avoid problems at decoder */ - test(); - if( sub(clip_gain,1) == 0 && sub(*gain_pit, 15565) > 0) - { - *gain_pit = 15565; - move16(); - } - updt_tar_fx( xn, xn2, y1, *gain_pit, L_SUBFR ); - } - - st_fx->use_acelp_preq = 1; - move16(); - - return; - -} -/*-------------------------------------------------------------------* - * Find target in residual domain - cn[] - *-------------------------------------------------------------------*/ - -static void find_cn_fx( - const Word16 xn[], /* i : target signal */ - const Word16 Ap[], /* i : weighted LP filter coefficients */ - const Word16 *p_Aq, /* i : 12k8 LP coefficients */ - Word16 cn[] /* o : target signal in residual domain */ -) -{ - Word16 tmp, tmp_fl[L_SUBFR+M]; - - set16_fx( tmp_fl, 0, M ); - Copy( xn, tmp_fl+M, L_SUBFR ); - tmp = 0; - move16(); - preemph_fx( tmp_fl+M, PREEMPH_FAC_16k, L_SUBFR, &tmp ); - syn_filt_s_lc_fx(0, Ap, tmp_fl+M, tmp_fl+M, L_SUBFR); - Residu3_lc_fx( p_Aq, M, tmp_fl+M, cn, L_SUBFR, 1 ); - - return; -} - - -/*-----------------------------------------------------------------* - * Transform domain contribution encoding - *-----------------------------------------------------------------*/ -Word16 gain_quant_fx( /* o: quantization index */ - Word32 *gain, /* i: quantized gain (Q16) */ - Word16 *gain16, /* o: quantized gain (expg) */ - const Word16 c_min, /* i: log10 of lower limit in Q14 */ - const Word16 c_max, /* i: log10 of upper limit in Q13 */ - const Word16 bits, /* i: number of bits to quantize */ - Word16 *expg /* o: output exponent of gain16 */ -) -{ - Word16 index, levels; - Word16 c_gain; - Word16 e_tmp, f_tmp, exp; - Word16 tmp, tmp1, tmp2, frac; - Word32 L_tmp; - - levels = shl(1, bits); - /* Prevent gain to be smaller than 0.0003. */ - /* This is to avoid an overflow when the gain is very small */ - /* the log10 give a high negative value in Q13 that overflow */ - /* on this code (the resulting value of 'index' is not affected. */ - /* tmp2 = msu_r(L_deposit_h(c_gain),c_min,16384) */ - L_tmp = L_max(*gain, 20); - - /*c_min = (float)log10(min);*/ - /*c_mult = (float) ((levels-1)/(log10(max)-c_min));*/ - - /*tmp = c_mult * ((float)log10(*gain) - c_min); - = ((levels-1)/(log10(max)-log10(min)))*((float)log10(*gain) - log10(min));*/ - - e_tmp = norm_l(L_tmp); - f_tmp = Log2_norm_lc(L_shl(L_tmp, e_tmp)); - e_tmp = sub(30-16,e_tmp);/*Q(min)=16*/ - L_tmp = Mpy_32_16(e_tmp, f_tmp, 9864); /* Q16 */ /*log10(2) in Q15*/ - c_gain = round_fx(L_shl(L_tmp, 13)); /* Q13 */ - - /*tmp1 = sub(c_max,c_min); Q14*/ - /*tmp2 = sub(c_gain,c_min); Q14*/ - - tmp1 = msu_r(L_deposit_h(c_max/*in Q13 already*/),c_min, 16384); /*Q13*/ - tmp2 = msu_r(L_deposit_h(c_gain/*in Q13 already*/),c_min,16384); /*Q13*/ - IF(tmp1 != 0) - { - exp = norm_s(tmp1); - frac = div_s(shl(1,sub(14,exp)),tmp1); /*Q(15-exp)*/ - L_tmp = L_mult(tmp2,frac); /*Q(30-exp)*/ - L_tmp = Mult_32_16(L_tmp,sub(levels,1)); /*Q(15-exp)*/ - index = extract_l(L_shr(L_add(L_tmp,shr(1<<14,exp)),sub(15,exp))); - } - ELSE - { - L_tmp = L_mult(tmp2,sub(levels,1)); /*Q15*/ - index = extract_l(L_shr(L_add(L_tmp,1<<14),15)); - } - - index = s_max(index ,0); - index = s_min(index ,sub(levels,1)); - - /**gain = (float)pow( 10.0, (((float)index)/c_mult) + c_min ); - y = index/c_mult + c_min; - = (index/(levels-1))*(log10(max) - log10(min)) + log10(min); - = z*log10(max) + (1-z)*log10(min) - z = (index/(levels-1))*/ - tmp = div_s(index,sub(levels,1)); /*Q15*/ - L_tmp = L_mult(tmp,c_max);/*Q29*/ - L_tmp = L_mac0(L_tmp,sub(32767,tmp),c_min); /*Q29*/ - - L_tmp = Mult_32_16(L_tmp,27213); /*Q27, 3.321928 in Q13*/ - L_tmp = L_shr(L_tmp,11); /*Q27->Q16*/ - - frac = L_Extract_lc(L_tmp, expg); /* Extract exponent of gcode0 */ - - *gain16 = extract_l(Pow2(14, frac));/* Put 14 as exponent so that */ - /* output of Pow2() will be: */ - /* 16384 < Pow2() <= 32767 */ - *expg = sub(*expg, 14); - move16(); - - return(index); -} diff --git a/src/libs/libevs/lib_enc/enc_nelp.cpp b/src/libs/libevs/lib_enc/enc_nelp.cpp new file mode 100644 index 00000000..b8e1ade8 --- /dev/null +++ b/src/libs/libevs/lib_enc/enc_nelp.cpp @@ -0,0 +1,113 @@ +/*==================================================================================== + EVS Codec 3GPP TS26.443 Nov 13, 2018. Version 12.11.0 / 13.7.0 / 14.3.0 / 15.1.0 + ====================================================================================*/ + +#include "options.h" +#include "cnst.h" +#include "rom_com.h" +#include "prot.h" + +/*-------------------------------------------------------------------* + * encod_nelp() + * + * Encode Unvoiced frames in SC-VBR + *-------------------------------------------------------------------*/ + +void encod_nelp( + Encoder_State *st, /* i/o: state structure */ + LPD_state *mem, /* i/o: encoder memories */ + const float *speech, /* i : input speech */ + const float Aw[], /* i : weighted A(z) unquantized for subframes */ + const float *Aq, /* i : 12k8 Lp coefficient */ + float *res, /* o : residual signal */ + float *synth, /* o : core synthesis */ + float *tmp_noise, /* o : long-term noise energy */ + float *exc, /* i/o: current non-enhanced excitation */ + float *exc2, /* i/o: current enhanced excitation */ + float *pitch_buf, /* o : floating pitch values for each subframe */ + float *voice_factors, /* o : voicing factors */ + float *bwe_exc /* o : excitation for SWB TBE */ +) +{ + float xn[L_SUBFR]; /* Target vector for pitch search */ + float h1[L_SUBFR]; /* Impulse response vector */ + float exc_nelp[L_FRAME]; + const float *p_Aw,*p_Aq;/* pointer to LP filter coeff. vector */ + short i_subfr, j; + + + short reduce_gains = 0; + + if ( st->bwidth == NB && st->input_Fs >= 16000) + { + if (st->last_nelp_mode == 0) + { + set_f( st->nelp_lp_fit_mem, 0, NELP_LP_ORDER*2 ); + } + polezero_filter( res, res, L_FRAME, num_nelp_lp, den_nelp_lp, NELP_LP_ORDER, st->nelp_lp_fit_mem ); /*16-Q of filter coeff*/ + } + + p_Aw = Aw; + p_Aq = Aq; + + for (i_subfr=0; i_subfrmem_syn, i_subfr, &mem->mem_w0, p_Aq,res, L_SUBFR, p_Aw, TILT_FAC, xn, NULL, h1 ); + + if (i_subfr == 0) + { + if ( (st->Local_VAD == 1 ) && ( st->bwidth == NB) ) + { + reduce_gains = 1; + } + + nelp_encoder(st, res, exc_nelp, reduce_gains); + } + *tmp_noise = 0; + + /*-----------------------------------------------------------------* + * Synthesize speech to update mem_syn[]. + * Update A(z) filters + *-----------------------------------------------------------------*/ + + syn_filt( p_Aq, M, &exc_nelp[i_subfr], &synth[i_subfr], L_SUBFR, mem->mem_syn, 1 ); + + p_Aw += (M+1); + p_Aq += (M+1); + *pitch_buf = L_SUBFR; + pitch_buf++; + } + + mvr2r( exc_nelp, exc, L_FRAME ); + + /*-----------------------------------------------------------------* + * Updates: last value of new target is stored in mem_w0 + *-----------------------------------------------------------------*/ + + mem->mem_w0 = xn[L_SUBFR-1] - (exc[L_FRAME-1]); + mem->tilt_code = 0.0f; /* purely unvoiced */ + st->prev_tilt_code = mem->tilt_code; + + mvr2r(exc, exc2, L_FRAME); + + st->prev_ppp_gain_pit = 0.0; + st->dispMem[0] = 0; + st->dispMem[2] = st->prev_ppp_gain_pit; + + for( j=3; j<7; j++ ) + { + st->dispMem[j] = st->dispMem[j-1]; + } + + interp_code_5over2( exc2, bwe_exc, L_FRAME ); + set_f( voice_factors, 0.0f, NB_SUBFR16k ); + + return; +} diff --git a/src/libs/libevs/lib_enc/enc_nelp_fx.cpp b/src/libs/libevs/lib_enc/enc_nelp_fx.cpp deleted file mode 100755 index e7082f4f..00000000 --- a/src/libs/libevs/lib_enc/enc_nelp_fx.cpp +++ /dev/null @@ -1,172 +0,0 @@ -/*==================================================================================== - EVS Codec 3GPP TS26.442 Apr 03, 2018. Version 12.11.0 / 13.6.0 / 14.2.0 - ====================================================================================*/ - -#include "options.h" /* Compilation switches */ -#include "cnst_fx.h" /* Common constants */ -#include "prot_fx.h" /* Function prototypes */ -#include "stl.h" - -/*==============================================================================*/ -/* FUNCTION : encod_nelp_fx() */ -/*------------------------------------------------------------------------------*/ -/* PURPOSE : Encode Unvoiced frames in SC-VBR */ -/*------------------------------------------------------------------------------*/ -/* INPUT ARGUMENTS : */ -/* _ (Encoder_State_fx) st_fx: state structure */ -/* _ (Word16[]) speech_fx : input speech Q_new-1 */ -/* _ (Word16[]) Aq_fx : 12k8 Lp coefficient Q12 */ -/* _ (Word16[]) A_fx : unquantized A(z) filter */ -/* with bandwidth expansion Q12 */ -/* _ (Word16) coder_type_fx : coding type */ -/* _ (Word16[]) res_fx : residual signal Q_new */ -/* _ (Word16*) Q_new : res qformat */ -/* _ (Word16) shift */ -/*------------------------------------------------------------------------------*/ -/* OUTPUT ARGUMENTS : */ -/* _ (Word16[]) synth_fx : core synthesis */ -/* _ (Word16[]) tmp_noise_fx: long-term noise energy Q0 */ -/* _ (Word16[]) exc_fx : current non-enhanced excitation Q_new */ -/* _ (Word16[]) exc2_fx : current enhanced excitation Q_new */ -/* _ (Word16[]) pitch_buf_fx: floating pitch values for each subframe Q6 */ -/* _ (Word16*) voice_factors : voicing factors */ -/* _ (Word16*) bwe_exc : excitation for SWB TBE */ -/*------------------------------------------------------------------------------*/ - -/*------------------------------------------------------------------------------*/ -/* RETURN ARGUMENTS : */ -/* _ None */ -/*==============================================================================*/ -void encod_nelp_fx( - Encoder_State_fx *st_fx, /* i/o: state structure */ - LPD_state *mem, /* i/o: acelp memories */ - const Word16 *speech_fx, /* i : input speech */ - const Word16 Aw_fx[], /* i : weighted A(z) unquantized for subframes */ - const Word16 Aq_fx[], /* i : 12k8 Lp coefficient */ - Word16 *res_fx, /* o : residual signal */ - Word16 *synth_fx, /* o : core synthesis */ - Word16 *tmp_noise_fx, /* o : long-term noise energy */ - Word16 *exc_fx, /* i/o: current non-enhanced excitation */ - Word16 *exc2_fx, /* i/o: current enhanced excitation */ - Word16 *pitch_buf_fx, /* o : floating pitch values for each subframe */ - Word16* voice_factors_fx, /* o : voicing factors */ - Word16* bwe_exc_fx, /* o : excitation for SWB TBE */ - Word16 Q_new, - Word16 shift - -) -{ - Word16 xn_fx[L_SUBFR]; /* Target vector for pitch search */ - Word16 h1_fx[L_SUBFR]; /* Impulse response vector */ - Word16 exc_nelp_fx[L_FRAME]; - - Word16 i_subfr, j; - - const Word16 *p_Aw_fx, *p_Aq_fx; /* pointer to LP filter coeff. vector */ - Word16 saved_Q_new = Q_new; - - Word16 reduce_gains = 0; - - IF ( sub(st_fx->bwidth_fx, NB) == 0 && L_sub(st_fx->input_Fs_fx, 16000) >= 0) - { - IF (st_fx->last_nelp_mode_fx == 0) - { - set16_fx( st_fx->nelp_lp_fit_mem, 0, NELP_LP_ORDER*2 ); - } - Scale_sig(st_fx->nelp_lp_fit_mem, NELP_LP_ORDER*2, sub(Q_new, st_fx->prev_Q_new)); - - pz_filter_sp_fx( num_nelp_lp_fx, den_nelp_lp_fx, res_fx, res_fx, st_fx->nelp_lp_fit_mem, NELP_LP_ORDER, NELP_LP_ORDER, L_FRAME, 3); /*16-Q of filter coeff*/ - - } - - p_Aw_fx = Aw_fx; - p_Aq_fx = Aq_fx; - - - FOR (i_subfr=0; i_subfrmem_syn, i_subfr, &mem->mem_w0, p_Aq_fx, - res_fx, L_SUBFR, p_Aw_fx, TILT_FAC_FX, xn_fx, NULL - ,h1_fx - ); - /* scale xn[] and h1[] to avoid overflow in dot_product12() */ - Scale_sig(xn_fx, L_SUBFR, shift); /* scaling of xn[] to limit dynamic at 12 bits */ - - IF (i_subfr == 0) - { - test(); - IF ( sub(st_fx->Local_VAD, 1 ) == 0 && sub( st_fx->bwidth_fx, NB) == 0 ) - { - reduce_gains = 1; - } - - nelp_encoder_fx( st_fx, res_fx, exc_nelp_fx, &Q_new - ,reduce_gains - ); - - Scale_sig(exc_nelp_fx, L_FRAME, (saved_Q_new - Q_new)); - } - - - *tmp_noise_fx = 0; - move16(); - - /*-----------------------------------------------------------------* - * Synthesize speech to update mem_syn[]. - * Update A(z) filters - *-----------------------------------------------------------------*/ - Syn_filt_s(1, p_Aq_fx, M, &exc_nelp_fx[i_subfr], &synth_fx[i_subfr], L_SUBFR, mem->mem_syn, 1); - - p_Aw_fx += (M+1); - move16(); - p_Aq_fx += (M+1); - move16(); - *pitch_buf_fx = L_SUBFR_Q6; - move16(); - - pitch_buf_fx++; - move16(); - } - - Copy(exc_nelp_fx, exc_fx, L_FRAME); - - /*-----------------------------------------------------------------* - * Updates: last value of new target is stored in mem_w0 - *-----------------------------------------------------------------*/ - - mem->mem_w0 = sub(shr(xn_fx[L_SUBFR-1],shift), shr(exc_fx[L_FRAME-1],1)); - move16();/*Q_new-1 */ - mem->tilt_code = 0; - move16();/* purely unvoiced */ - st_fx->prev_tilt_code_fx = mem->tilt_code; - move16(); - - Copy(exc_fx, exc2_fx, L_FRAME); - - st_fx->prev_ppp_gain_pit_fx = 0; - move16(); - - st_fx->dm_fx.prev_state = 0; - move16(); - st_fx->dm_fx.prev_gain_pit[0] = st_fx->prev_ppp_gain_pit_fx; - move16(); - - FOR(j=1; j<5; j++) - { - st_fx->dm_fx.prev_gain_pit[j] = st_fx->dm_fx.prev_gain_pit[j-1]; - move16(); - } - - interp_code_5over2_fx( exc2_fx, bwe_exc_fx, L_FRAME ); - set16_fx( voice_factors_fx, 0, NB_SUBFR16k ); - - return; -} diff --git a/src/libs/libevs/lib_enc/enc_pit_exc.cpp b/src/libs/libevs/lib_enc/enc_pit_exc.cpp new file mode 100644 index 00000000..8919c53c --- /dev/null +++ b/src/libs/libevs/lib_enc/enc_pit_exc.cpp @@ -0,0 +1,277 @@ +/*==================================================================================== + EVS Codec 3GPP TS26.443 Nov 13, 2018. Version 12.11.0 / 13.7.0 / 14.3.0 / 15.1.0 + ====================================================================================*/ + +#include +#include "options.h" +#include "cnst.h" +#include "rom_com.h" +#include "prot.h" + +/*-------------------------------------------------------------------* + * enc_pit_exc() + * + * Encode pitch only contribution + *-------------------------------------------------------------------*/ + +void enc_pit_exc( + Encoder_State *st, /* i/o: State structure */ + LPD_state *mem, /* i/o: encoder memories */ + const float *speech, /* i : Input speech */ + const float Aw[], /* i : weighted A(z) unquantized for subframes */ + const float *Aq, /* i : 12k8 Lp coefficient */ + const float Es_pred, /* i : predicted scaled innov. energy */ + const short *T_op, /* i : open loop pitch */ + const float *voicing, /* i : voicing */ + const float *res, /* i : residual signal */ + float *synth, /* i/o: core synthesis */ + float *exc, /* i/o: current non-enhanced excitation */ + short *T0, /* i/o: close loop integer pitch */ + short *T0_frac, /* i/o: close-loop pitch period - fractional part */ + float *pitch_buf, /* i/o: Fractionnal per subframe pitch */ + const short nb_subfr, /* i : Number of subframe considered */ + float *gpit /* o : pitch mean gpit */ +) +{ + float xn[PIT_EXC_L_SUBFR]; /* Target vector for pitch search */ + float xn2[PIT_EXC_L_SUBFR]; /* Target vector for codebook search */ + float cn[PIT_EXC_L_SUBFR]; /* Target vector in residual domain */ + float h1[PIT_EXC_L_SUBFR+(M+1)]; /* Impulse response vector */ + float y1[PIT_EXC_L_SUBFR]; /* Filtered adaptive excitation */ + float code[L_SUBFR]; /* Fixed codebook excitation */ + float y2[L_SUBFR]; /* Filtered algebraic excitation */ + float voice_fac; /* Voicing factor */ + float gain_code; /* Gain of code */ + float gain_inov; /* inovation gain */ + float gain_pit; /* Pitch gain */ + short pit_idx, i_subfr; /* tmp variables */ + short T0_min, T0_max; /* pitch variables */ + float g_corr[10]; /* ACELP correlation values + gain pitch */ + short clip_gain, i; /* LSF clip gain and LP flag */ + const float *p_Aw, *p_Aq; /* pointer to LP filter coefficient vector */ + float *pt_pitch; /* pointer to floating pitch */ + short L_subfr; + float cum_gpit, gpit_tmp; + short Local_BR, Pitch_BR, Pitch_CT; + short unbits_PI = 0; /* saved bits for EVS_PI */ + float norm_gain_code; + short pitch_limit_flag; + short lp_select, lp_flag; + + /*------------------------------------------------------------------* + * Initialization + *------------------------------------------------------------------*/ + + pitch_limit_flag = 1; /* always extended pitch Q range */ + + if( st->GSC_noisy_speech ) + { + Local_BR = ACELP_7k20; + Pitch_CT = GENERIC; + Pitch_BR = ACELP_7k20; + } + else + { + Local_BR = ACELP_7k20; + Pitch_CT = AUDIO; + Pitch_BR = st->core_brate; + } + + gain_code = 0; + + T0_max = PIT_MAX; + T0_min = PIT_MIN; + + cum_gpit = 0.0f; + L_subfr = L_FRAME/nb_subfr; + + + /*------------------------------------------------------------------* + * ACELP subframe loop + *------------------------------------------------------------------*/ + + p_Aw = Aw; + p_Aq = Aq; + pt_pitch = pitch_buf; /* pointer to the pitch buffer */ + for( i_subfr = 0; i_subfr < L_FRAME; i_subfr += L_subfr ) + { + + /*----------------------------------------------------------------* + * Find the the excitation search target "xn" and innovation + * target in residual domain "cn" + * Compute impulse response, h1[], of weighted synthesis filter + *----------------------------------------------------------------*/ + + mvr2r( &res[i_subfr], &exc[i_subfr], L_subfr ); + + if( L_subfr == L_SUBFR ) + { + find_targets( speech, st->mem_syn_tmp, i_subfr, &st->mem_w0_tmp, p_Aq, res, L_subfr, p_Aw, st->preemph_fac, xn, cn, h1 ); + } + else + { + find_targets( speech, st->mem_syn_tmp, i_subfr, &st->mem_w0_tmp, p_Aq, res, L_subfr, p_Aw, st->preemph_fac, xn, NULL, h1 ); + } + + /*----------------------------------------------------------------* + * Close-loop pitch search and quantization + * Adaptive exc. construction + *----------------------------------------------------------------*/ + + *pt_pitch = pit_encode( st, Pitch_BR, 0, L_FRAME, Pitch_CT, &pitch_limit_flag, i_subfr, exc, + L_subfr, T_op, &T0_min, &T0_max, T0, T0_frac, h1, xn ); + + /*-----------------------------------------------------------------* + * Find adaptive exitation + *-----------------------------------------------------------------*/ + + pred_lt4( &exc[i_subfr], &exc[i_subfr], *T0, *T0_frac, L_subfr+1, inter4_2, L_INTERPOL2, PIT_UP_SAMP); + + /*-----------------------------------------------------------------* + * Gain clipping test to avoid unstable synthesis on frame erasure + * or in case of floating point encoder & fixed p. decoder + *-----------------------------------------------------------------*/ + + clip_gain = gp_clip( st->core_brate, voicing, i_subfr, AUDIO, xn, st->clip_var ); + + /*-----------------------------------------------------------------* + * Codebook target computation + * (No LP filtering of the adaptive excitation) + *-----------------------------------------------------------------*/ + + lp_select = lp_filt_exc_enc( MODE1, st->core_brate, 0, AUDIO, i_subfr, exc, h1, xn, y1, xn2, L_subfr, + L_FRAME, g_corr, clip_gain, &gain_pit, &lp_flag ); + + if( lp_flag == NORMAL_OPERATION ) + { + push_indice( st, IND_LP_FILT_SELECT, lp_select, 1 ); + } + + /* update long-term pitc hgain for speech/music classifier */ + st->lowrate_pitchGain = 0.9f * st->lowrate_pitchGain + 0.1f * gain_pit; + + gpit_tmp = gain_pit; + + if( st->GSC_noisy_speech == 0 || L_subfr != L_SUBFR ) + { + pit_idx = (short) vquant(&gain_pit, mean_gp, &gain_pit, dic_gp, 1, 16); + push_indice( st, IND_PIT_IDX, pit_idx, 4 ); + } + + if( st->GSC_noisy_speech && L_subfr == L_SUBFR ) + { + /*-----------------------------------------------------------------* + * Innovation & gain encoding + *-----------------------------------------------------------------*/ + + inov_encode( st, Local_BR, 0, L_FRAME, st->last_L_frame, LOCAL_CT, WB, 1, i_subfr, -1, + p_Aq, gain_pit, cn, exc, h1, mem->tilt_code, *pt_pitch, xn2, code, y2, &unbits_PI ); + + gain_enc_mless( st, Local_BR, L_FRAME, LOCAL_CT, i_subfr, -1, xn, y1, y2, code, Es_pred, + &gain_pit, &gain_code, &gain_inov, &norm_gain_code, g_corr, clip_gain ); + } + + gp_clip_test_gain_pit( st->core_brate, gain_pit, st->clip_var ); + + if( st->GSC_noisy_speech ) + { + mem->tilt_code = est_tilt( exc+i_subfr, gain_pit, code, gain_code, &voice_fac, L_SUBFR, 0 ); + } + else + { + mem->tilt_code = 0.0f; + } + + /*-----------------------------------------------------------------* + * Update memory of the weighting filter + *-----------------------------------------------------------------*/ + + if( st->GSC_noisy_speech ) + { + st->mem_w0_tmp = xn[L_subfr-1] - (gain_pit*y1[L_subfr-1]) - (gain_code*y2[L_subfr-1]); + } + else + { + st->mem_w0_tmp = xn[L_subfr-1] - (gain_pit*y1[L_subfr-1]); + } + + /*-----------------------------------------------------------------* + * Construct adaptive part of the excitation + * Save the non-enhanced excitation for FEC_exc + *-----------------------------------------------------------------*/ + + if( st->GSC_noisy_speech ) + { + for ( i = 0; i < L_subfr; i++ ) + { + exc[i+i_subfr] = gain_pit * exc[i+i_subfr] + gain_code * code[i]; + } + } + else + { + for ( i = 0; i < L_subfr; i++ ) + { + exc[i+i_subfr] = gain_pit * exc[i+i_subfr]; + } + } + + /*-----------------------------------------------------------------* + * Synthesize speech to update mem_syn[]. + * Update A(z) filters + *-----------------------------------------------------------------*/ + + syn_filt( p_Aq, M, &exc[i_subfr], &synth[i_subfr], L_subfr, st->mem_syn_tmp, 1 ); + + if( L_subfr == 2*L_SUBFR ) + { + if( i_subfr == 0 ) + { + cum_gpit = gpit_tmp*.5f; + } + else + { + cum_gpit += gpit_tmp*.5f; + } + + p_Aw += 2*(M+1); + p_Aq += 2*(M+1); + pt_pitch++; + *pt_pitch = *(pt_pitch-1); + pt_pitch++; + } + else if( L_subfr == 4*L_SUBFR ) + { + cum_gpit = gpit_tmp; + + pt_pitch++; + *pt_pitch = *(pt_pitch-1); + pt_pitch++; + *pt_pitch = *(pt_pitch-1); + pt_pitch++; + *pt_pitch = *(pt_pitch-1); + pt_pitch++; + + p_Aw += 4*(M+1); + p_Aq += 4*(M+1); + } + else + { + if( i_subfr == 0 ) + { + cum_gpit = gpit_tmp*.25f; + } + else + { + cum_gpit += gpit_tmp*.25f; + } + + pt_pitch++; + p_Aw += (M+1); + p_Aq += (M+1); + } + } + + *gpit = 0.1f * *gpit + 0.9f * cum_gpit; + + return; +} diff --git a/src/libs/libevs/lib_enc/enc_pit_exc_fx.cpp b/src/libs/libevs/lib_enc/enc_pit_exc_fx.cpp deleted file mode 100755 index ea1095ae..00000000 --- a/src/libs/libevs/lib_enc/enc_pit_exc_fx.cpp +++ /dev/null @@ -1,361 +0,0 @@ -/*==================================================================================== - EVS Codec 3GPP TS26.442 Apr 03, 2018. Version 12.11.0 / 13.6.0 / 14.2.0 - ====================================================================================*/ - -#include "options.h" /* Compilation switches */ -#include "cnst_fx.h" /* Common constants */ -#include "rom_com_fx.h" /* Static table prototypes */ -#include "prot_fx.h" /* Function prototypes */ - - -#include "stl.h" - -/*======================================================================*/ -/* FUNCTION : enc_pit_exc_fx() */ -/*----------------------------------------------------------------------*/ -/* PURPOSE : Encode pitch only contribution */ -/* */ -/*----------------------------------------------------------------------*/ -/* INPUT ARGUMENTS : */ -/* _ (Struct) st_fx : encoder static memory */ -/* _ (Word16[]) speech_fx : input speech Qnew-1 */ -/* _ (Word16[]) Aq_fx : LP filter coefficient Q12 */ -/* _ (Word16[]) A_fx : unquantized A(z) filter */ -/* with bandwidth expansion Q12 */ -/* _ (Word16) coder_type_fx : coding type */ -/* _ (Word16) Es_pred_fx : predicted scaled innov. energy Q8 */ -/* _ (Word16[]) T_op_fx : open loop pitch Q0 */ -/* _ (Word16[]) voicing_fx : floating pitch values for each subframe Q15*/ -/* _ (Word16[]) res_fx : residual signal Q_new */ -/* _ (Word16[]) exc_fx : adapt. excitation exc (Qnew) */ -/* _ (Word16[]) exc2_fx : adapt. excitation/total exc (Qnew) */ -/* _ (Word16[]) pitch_buf_fx : floating pitch values for each subframe Q6*/ -/* _ (Word16[]) *wH1, : Weighted impulses response mask */ -/* _ (Word16) shift : shift */ -/* _ (Word16) Q_new : */ -/*-----------------------------------------------------------------------*/ -/* OUTPUT ARGUMENTS : */ -/* _ (Word16[]) exc_fx : adapt. excitation exc (Qnew) */ -/* _ (Word16[]) exc2_fx : adapt. excitation/total exc (Qnew) */ -/* _ (Word16[]) syn_fx :core synthesis */ -/* _ (Word16[]) voice_factors_fx: voicing factors Q15 */ -/* _ (Word16[]) bwe_exc_fx : excitation for SWB TBE Q0 */ -/*-----------------------------------------------------------------------*/ - -/*-----------------------------------------------------------------------*/ -/* RETURN ARGUMENTS : */ -/* _ None */ -/*=======================================================================*/ -void enc_pit_exc_fx( - Encoder_State_fx *st_fx, /* i/o: State structure */ - LPD_state *mem, /* i/o: acelp memories */ - const Word16 *speech, /* i : Input speech */ - const Word16 Aw[], /* i : weighted A(z) unquantized for subframes */ - const Word16 Aq[], /* i : 12k8 Lp coefficient */ - const Word16 Es_pred, /* i : predicted scaled innov. energy */ - const Word16 *T_op, /* i : open loop pitch */ - const Word16 *voicing, /* i : voicing */ - const Word16 *res, /* i : residual signal */ - Word16 *synth, /* i/o: core synthesis */ - Word16 *exc, /* i/o: current non-enhanced excitation */ - Word16 *T0, /* i/o: close loop integer pitch */ - Word16 *T0_frac, /* i/o: close-loop pitch period - fractional part */ - Word16 *pitch_buf, /* i/o: Fractionnal per subframe pitch */ - const Word16 nb_subfr, /* i : Number of subframe considered */ - Word16 *gpit, /* o : pitch mean gpit */ - Word16 *saved_bit_pos, /* o : saved position in the bitstream before pitch contribution */ - Word16 Q_new, - Word16 shift -) -{ - Word16 xn[PIT_EXC_L_SUBFR]; /* Target vector for pitch search */ - Word16 xn2[PIT_EXC_L_SUBFR]; /* Target vector for codebook search */ - Word16 h1[PIT_EXC_L_SUBFR+(M+1)]; /* Impulse response vector */ - Word16 y1[PIT_EXC_L_SUBFR]; /* Filtered adaptive excitation */ - Word16 code[L_SUBFR]; /* Fixed codebook excitation */ - Word16 y2[L_SUBFR]; /* Filtered algebraic excitation */ - Word16 voice_fac; /* Voicing factor */ - Word32 gain_code; /* Gain of code */ - Word16 gain_inov; /* inovation gain */ - Word16 gain_pit; /* Pitch gain */ - Word16 pit_idx, i_subfr; /* tmp variables */ - Word16 T0_min, T0_max; /* pitch variables */ - Word16 g_corr[10]; /* ACELP correlation values + gain pitch */ - Word16 clip_gain, i; /* LSF clip gain and LP flag */ - const Word16 *p_Aw, *p_Aq; /* pointer to LP filter coefficient vector */ - Word16 cn1[L_SUBFR], *cn; /* (Used only when L_subfr == L_SUBFR) Target vector in residual domain */ - Word16 *pt_pitch; /* pointer to floating pitch */ - Word16 L_subfr; - Word16 cum_gpit, gpit_tmp; - Word16 Local_BR, Pitch_BR, Pitch_CT; - Word16 unbits_PI = 0; /* saved bits for PI */ - Word32 norm_gain_code; - Word16 pitch_limit_flag; - Word16 h2[PIT_EXC_L_SUBFR+(M+1)]; /* Impulse response vector */ - Word32 Ltmp; - Word32 Lgcode; - Word16 gcode16; - Word16 shift_wsp; - Word16 lp_select, lp_flag; - /*------------------------------------------------------------------* - * Initialization - *------------------------------------------------------------------*/ - - pitch_limit_flag = 1; - move16(); /* always extended pitch Q range */ - - IF( st_fx->GSC_noisy_speech_fx ) - { - Local_BR = ACELP_7k20; - move16(); - Pitch_CT = GENERIC; - move16(); - Pitch_BR = ACELP_7k20; - move16(); - } - ELSE - { - - Local_BR = ACELP_7k20; - move16(); - Pitch_CT = AUDIO; - move16(); - Pitch_BR = extract_l(st_fx->core_brate_fx); - } - gain_code = 0; - move16(); - T0_max = PIT_MAX; - move16(); - T0_min = PIT_MIN; - move16(); - - cum_gpit = 0; - move16(); - - L_subfr = mult_r(L_FRAME,div_s(1,nb_subfr)); - - *saved_bit_pos = st_fx->next_bit_pos_fx; - move16(); - - /*------------------------------------------------------------------* - * ACELP subframe loop - *------------------------------------------------------------------*/ - cn = NULL; - if(sub(L_subfr, L_SUBFR)==0) - { - cn = cn1; - move16(); - } - p_Aw = Aw; - - p_Aq = Aq; - pt_pitch = pitch_buf; /* pointer to the pitch buffer */ - shift_wsp = add(Q_new,shift); - FOR ( i_subfr = 0; i_subfr < L_FRAME; i_subfr += L_subfr ) - { - - /*----------------------------------------------------------------* - * Bandwidth expansion of A(z) filter coefficients - * Find the the excitation search target "xn" and innovation - * target in residual domain "cn" - * Compute impulse response, h1[], of weighted synthesis filter - *----------------------------------------------------------------*/ - Copy( &res[i_subfr], &exc[i_subfr], L_subfr ); - /* condition on target (compared to float) has been put outside the loop */ - find_targets_fx( speech, mem->mem_syn, i_subfr, &mem->mem_w0, p_Aq, - res, L_subfr, p_Aw, st_fx->preemph_fac, xn, cn,h1); - Copy_Scale_sig(h1, h2, L_subfr, -2); - Scale_sig(h1, L_subfr, add(1, shift)); /* set h1[] in Q14 with scaling for convolution */ - - /* scaling of xn[] to limit dynamic at 12 bits */ - Scale_sig(xn, L_subfr, shift); - - /*----------------------------------------------------------------* - * Close-loop pitch search and quantization - * Adaptive exc. construction - *----------------------------------------------------------------*/ - *pt_pitch = pit_encode_fx( st_fx, Pitch_BR, 0, L_FRAME, Pitch_CT, &pitch_limit_flag, i_subfr, exc, - L_subfr, T_op, &T0_min, &T0_max, T0, T0_frac, h1, xn ); - /*-----------------------------------------------------------------* - * Find adaptive exitation - *-----------------------------------------------------------------*/ - - pred_lt4(&exc[i_subfr], &exc[i_subfr], *T0, *T0_frac, L_subfr+1, pitch_inter4_2, L_INTERPOL2, PIT_UP_SAMP); - /*-----------------------------------------------------------------* - * Gain clipping test to avoid unstable synthesis on frame erasure - * or in case of floating point encoder & fixed p. decoder - *-----------------------------------------------------------------*/ - - clip_gain = gp_clip_fx(st_fx->core_brate_fx, voicing, i_subfr, AUDIO, xn, st_fx->clip_var_fx,sub(shift_wsp, 1)); - - /*-----------------------------------------------------------------* - * Codebook target computation - * (No LP filtering of the adaptive excitation) - *-----------------------------------------------------------------*/ - - lp_select = lp_filt_exc_enc_fx( MODE1, st_fx->core_brate_fx, 0, AUDIO, i_subfr, exc, h1, - xn, y1, xn2, L_subfr, L_FRAME, g_corr, clip_gain, &gain_pit, &lp_flag ); - - IF( sub(lp_flag,NORMAL_OPERATION) == 0 ) - { - push_indice_fx( st_fx, IND_LP_FILT_SELECT, lp_select, 1 ); - } - - /*st_fx->lowrate_pitchGain = 0.9f * st_fx->lowrate_pitchGain + 0.1f * gain_pit;*/ - st_fx->lowrate_pitchGain = round_fx(L_mac(L_mult(29491, st_fx->lowrate_pitchGain), 6554, gain_pit)); /*Q14*Q16(0.1) + Q15 -> Q15*/ - - - gpit_tmp = gain_pit; - move16(); /*Q14*/ - test(); - IF( st_fx->GSC_noisy_speech_fx == 0 || sub(L_subfr,L_SUBFR ) != 0 ) - { - pit_idx = vquant_fx( &gain_pit, mean_gp_fx, &gain_pit, dic_gp_fx, 1, 16 ); - push_indice_fx( st_fx, IND_PIT_IDX, pit_idx, 4 ); - } - ELSE - { - /*-----------------------------------------------------------------* - * Innovation & gain encoding - *-----------------------------------------------------------------*/ - /* h2 in Q12 for codebook search */ - /* h1 has been scaled with 1 + shift so we need to remove 2 and (1+shift) = -3 - shift*/ - Copy_Scale_sig( h1, h2, L_subfr, sub(-2-1,shift) ); - - inov_encode_fx( st_fx, Local_BR, 0, L_FRAME, st_fx->last_L_frame_fx, LOCAL_CT, WB, 1, i_subfr, -1, p_Aq, - gain_pit, cn, exc, h2, mem->tilt_code, *pt_pitch, xn2, code, y2, &unbits_PI,shift - ); - /*-----------------------------------------------------------------* - * Gain encoding - *-----------------------------------------------------------------*/ - gain_enc_mless_fx( st_fx, Local_BR, L_FRAME, LOCAL_CT, i_subfr, -1, xn, y1, shift_wsp, y2, code, Es_pred, - &gain_pit, &gain_code, &gain_inov, &norm_gain_code, g_corr, clip_gain ); - } - - gp_clip_test_gain_pit_fx( st_fx->core_brate_fx, gain_pit, st_fx->clip_var_fx ); - - Lgcode = L_shl(gain_code, Q_new); /* scaled gain_code with Qnew -> Q16*/ - gcode16 = round_fx(Lgcode); - IF( st_fx->GSC_noisy_speech_fx) - { - mem->tilt_code = Est_tilt2(&exc[i_subfr], gain_pit, code, Lgcode, &voice_fac, shift); - move16(); - } - ELSE - { - mem->tilt_code = 0; - move16(); - } - /*-----------------------------------------------------------------* - * Update memory of the weighting filter - *-----------------------------------------------------------------*/ - IF( st_fx->GSC_noisy_speech_fx) - { - Ltmp = L_mult(gcode16, y2[L_subfr - 1]); - Ltmp = L_shl(Ltmp, add(5, shift)); - Ltmp = L_negate(Ltmp); - Ltmp = L_mac(Ltmp, xn[L_subfr - 1], 16384); - Ltmp = L_msu(Ltmp, y1[L_subfr - 1], gain_pit); - Ltmp = L_shl(Ltmp, sub(1, shift)); - mem->mem_w0 = round_fx(Ltmp); /*Q_new-1 */ - } - ELSE - { - Ltmp = L_mult(xn[L_subfr - 1], 16384); - Ltmp = L_msu(Ltmp, y1[L_subfr - 1], gain_pit); - Ltmp = L_shl(Ltmp, sub(1, shift)); - mem->mem_w0 = round_fx(Ltmp); /*Q_new-1 */ - } - - /*-----------------------------------------------------------------* - * Construct adaptive part of the excitation - * Save the non-enhanced excitation for FEC_exc - *-----------------------------------------------------------------*/ - IF( st_fx->GSC_noisy_speech_fx) - { - FOR ( i = 0; i < L_subfr; i++ ) - { - /* code in Q9, gain_pit in Q14 */ - Ltmp = L_mult(gcode16, code[i]); - Ltmp = L_shl(Ltmp, 5); - Ltmp = L_mac(Ltmp, exc[i + i_subfr], gain_pit); - Ltmp = L_shl(Ltmp, 1); /* saturation can occur here */ - exc[i + i_subfr] = round_fx(Ltmp); - } - } - ELSE - { - FOR ( i = 0; i < L_subfr; i++ ) - { - - Ltmp = L_mult(exc[i + i_subfr], gain_pit); - Ltmp = L_shl(Ltmp, 1); /* saturation can occur here */ - exc[i + i_subfr] = round_fx(Ltmp); - } - } - - /*-----------------------------------------------------------------* - * Synthesize speech to update mem_syn[]. - * Update A(z) filters - *-----------------------------------------------------------------*/ - - Syn_filt_s( 1, p_Aq, M, &exc[i_subfr], &synth[i_subfr], L_subfr, st_fx->mem_syn_tmp_fx, 1 ); - IF( sub(L_subfr,2*L_SUBFR) == 0 ) - { - IF( i_subfr == 0 ) - { - cum_gpit = mult_r(gpit_tmp,16384); - } - ELSE - { - cum_gpit = add(cum_gpit,mult_r(gpit_tmp,16384)); - } - p_Aw += 2*(M+1); - move16(); - p_Aq += 2*(M+1); - move16(); - pt_pitch++; - *pt_pitch = *(pt_pitch-1); - move16(); - pt_pitch++; - } - ELSE IF(sub(L_subfr,4*L_SUBFR) == 0 ) - { - cum_gpit = gpit_tmp; - move16(); - - pt_pitch++; - *pt_pitch = *(pt_pitch-1); - move16(); - pt_pitch++; - *pt_pitch = *(pt_pitch-1); - move16(); - pt_pitch++; - *pt_pitch = *(pt_pitch-1); - pt_pitch++; - p_Aw += 4*(M+1); - p_Aq += 4*(M+1); - } - ELSE - { - IF( i_subfr == 0 ) - { - - cum_gpit = mult_r(gpit_tmp,8192); - } - ELSE - { - cum_gpit = add(cum_gpit,mult_r(gpit_tmp,8192)); - } - - pt_pitch++; - p_Aw += (M+1); - p_Aq += (M+1); - } - } - - cum_gpit = shl(cum_gpit,1); /*Q15*/ - *gpit = round_fx(L_mac(L_mult(3277 , *gpit), 29491, cum_gpit)); /*Q15*/ - - -} diff --git a/src/libs/libevs/lib_enc/enc_ppp.cpp b/src/libs/libevs/lib_enc/enc_ppp.cpp new file mode 100644 index 00000000..884b7cdb --- /dev/null +++ b/src/libs/libevs/lib_enc/enc_ppp.cpp @@ -0,0 +1,165 @@ +/*==================================================================================== + EVS Codec 3GPP TS26.443 Nov 13, 2018. Version 12.11.0 / 13.7.0 / 14.3.0 / 15.1.0 + ====================================================================================*/ + +#include +#include +#include "options.h" +#include "cnst.h" +#include "prot.h" + +/*------------------------------------------------------------------- + * encod_ppp() + * + * Encode PPP frames in SC-VBR + *-------------------------------------------------------------------*/ + +void encod_ppp( + Encoder_State *st, /* i/o: state structure */ + LPD_state *mem, /* i/o: encoder memories */ + const float speech[], /* i : input speech */ + const float Aw[], /* i : weighted A(z) unquantized for subframes */ + const float Aq[], /* i : 12k8 Lp coefficient */ + short *coder_type, /* i/o: coding type */ + const short sharpFlag, /* i : formant sharpening flag */ + const short T_op[], /* i : open loop pitch */ + const float voicing[], /* i : voicing */ + float *res, /* i/o: residual signal */ + float *synth, /* i/o: core synthesis */ + float *exc, /* i/o: current non-enhanced excitation */ + float *exc2, /* i/o: current enhanced excitation */ + float *pitch_buf, /* i/o: floating pitch values for each subframe */ + float *voice_factors, /* o : voicing factors */ + float *bwe_exc /* o : excitation for SWB TBE */ +) +{ + float xn[L_SUBFR]; /* Target vector for pitch search */ + float h1[L_SUBFR+(M+1)];/* Impulse response vector */ + short i_subfr; /* tmp variables */ + const float *p_Aw,*p_Aq;/* pointer to LP filter coeff. vector */ + short k; + float p_Aq_old[M+1], excQ_ppp[L_FRAME], p_Aq_curr[M], pitch[NB_SUBFR]; + float LPC_de_old[M+1], LPC_de_curr[M+1]; + short rate_ctrl; + + rate_ctrl = st->rate_control; + + /*------------------------------------------------------------------* + * ACELP subframe loop + *------------------------------------------------------------------*/ + + p_Aw = Aw; + p_Aq = Aq; + + for( i_subfr=0; i_subfrmem_syn, i_subfr, &mem->mem_w0, p_Aq,res, L_SUBFR, p_Aw, TILT_FAC,xn, NULL, h1 ); + + /* call voiced encoder at this point */ + if( i_subfr == 0 ) /* generate the L_FRAME exc */ + { + for( k=0; klsp_old, p_Aq_old, M ); + + deemph_lpc( p_Aq_curr, p_Aq_old, LPC_de_curr, LPC_de_old, 1 ); + + /* last frame-end lpc and curr frame-end lpc */ + ppp_voiced_encoder( st, res, excQ_ppp, T_op[1], LPC_de_old, LPC_de_curr, exc, pitch, st->vadsnr ); + + if( st->bump_up ) + { + i_subfr = L_FRAME; + } + } + + if( st->bump_up != 1 ) + { + /*-----------------------------------------------------------------* + * Gain clipping test to avoid unstable synthesis on frame erasure + * or in case of floating point encoder & fixed p. decoder + *-----------------------------------------------------------------*/ + + gp_clip( st->core_brate, voicing, i_subfr, *coder_type, xn, st->clip_var ); + + /* run the above to maintain gain clipping memories */ + gp_clip_test_gain_pit( st->core_brate, st->prev_ppp_gain_pit, st->clip_var ); + + /*-----------------------------------------------------------------* + * Synthesize speech to update mem_syn[]. + * Update A(z) filters + *-----------------------------------------------------------------*/ + + syn_filt( p_Aq, M, &excQ_ppp[i_subfr], &synth[i_subfr], L_SUBFR, mem->mem_syn, 1 ); + + p_Aw += (M+1); + p_Aq += (M+1); + } + + } /* end of subframe loop */ + + + if( st->bump_up ) + { + /* PPP failed, bump up */ + st->ppp_mode = 0; + st->core_brate = ACELP_7k20; + st->pppcountE = 0; + + if ( st->set_ppp_generic ) + { + *coder_type = GENERIC; + } + else + { + *coder_type = VOICED; + } + + /* delete previous indices */ + reset_indices_enc( st ); + + /* signalling matrix (writing of signalling bits) */ + signalling_enc( st, *coder_type, sharpFlag ); + } + else + { + mvr2r( excQ_ppp, exc, L_FRAME ); + + /*-----------------------------------------------------------------* + * Updates: last value of new target is stored in mem_w0 + *-----------------------------------------------------------------*/ + + mem->mem_w0 = xn[L_SUBFR-1] - (exc[L_FRAME-1]); + + mvr2r( exc, exc2, L_FRAME ); + + st->dispMem[0] = 2; + st->dispMem[2] = st->prev_ppp_gain_pit; + + for( k=3; k<7; k++ ) + { + st->dispMem[k] = st->dispMem[k-1]; + } + mem->tilt_code = st->prev_tilt_code; + mvr2r( pitch, pitch_buf, NB_SUBFR ); + pitch_buf[NB_SUBFR16k-1] = pitch[NB_SUBFR-1]; + interp_code_5over2( exc2, bwe_exc, L_FRAME ); + set_f( voice_factors, 0.0f, NB_SUBFR16k ); + } + + st->rate_control = rate_ctrl; + + return; +} diff --git a/src/libs/libevs/lib_enc/enc_ppp_fx.cpp b/src/libs/libevs/lib_enc/enc_ppp_fx.cpp deleted file mode 100755 index 9f3a9165..00000000 --- a/src/libs/libevs/lib_enc/enc_ppp_fx.cpp +++ /dev/null @@ -1,227 +0,0 @@ -/*==================================================================================== - EVS Codec 3GPP TS26.442 Apr 03, 2018. Version 12.11.0 / 13.6.0 / 14.2.0 - ====================================================================================*/ - -#include "options.h" /* Compilation switches */ -#include "cnst_fx.h" /* Common constants */ -#include "prot_fx.h" /* Function prototypes */ -#include "stl.h" -/*Temporary location to be move in prot* when merge is done */ -void E_LPC_f_lsp_a_conversion(const Word16 *lsp, Word16 *a, const Word16 m); - -/*=======================================================================================*/ -/* FUNCTION : encod_ppp_fx() */ -/*---------------------------------------------------------------------------------------*/ -/* PURPOSE : */ -/*---------------------------------------------------------------------------------------*/ -/* INPUT ARGUMENTS : */ -/* _ (Word16) speech_fx[], i : input speech Q_new */ -/* _ (Word16) Aq_fx[], i : 12k8 Lp coefficient Q12 */ -/* _ (Word16) A_fx[], i : unquantized A(z) filter with bandwidth expansion Q12*/ -/* _ (Word16) coder_type_fx, i : coding type */ -/* _ (Word16) T_op_fx[], i : open loop pitch */ -/* _ (Word16) voicing_fx[], i : voicing Q15 */ -/* _ (Word16) *res_fx, i : residual signal Q_new */ -/* _ (Word16) Q_new i : Q factor for res */ -/* _ (Word16) vadsnr_fx i : SNR for current frame Q7 */ -/*---------------------------------------------------------------------------------------*/ -/* OUTPUT ARGUMENTS : */ -/* _ (Word16) *exc2_fx, o : current enhanced excitation Q0 */ -/* _ (Word16) *pitch_buf_fx, o : floating pitch values for each subframe Q6 */ -/* _ (Word16) *synth_fx, o : core synthesis Q-1 */ -/* _ Encoder_State_fx *st_fx: */ -/* _ lastLgainE_fx - Q11 */ -/* _ lastHgainE_fx - Q11 */ -/* _ lasterbE_fx - Q13 */ -/*---------------------------------------------------------------------------------------*/ -/* INPUT/OUTPUT ARGUMENTS : */ -/* _ Encoder_State_fx *st_fx: */ -/* _ st_fx->dtfs_enc_xxxx */ -/* _ a nd b in st_fx->dtfs_enc_Q */ -/* rest all in Q0 */ -/* - bump_up_fx - Q0 */ -/* _ (Word16) *exc_fx, o : current enhanced excitation Q0 */ -/*---------------------------------------------------------------------------------------*/ -/* RETURN ARGUMENTS : */ -/* _ None. */ -/*---------------------------------------------------------------------------------------*/ -/* CALLED FROM : TX */ -/*=======================================================================================*/ -void encod_ppp_fx( - Encoder_State_fx* st_fx, /* i/o: state structure */ - LPD_state *mem, /* i/o: acelp memories */ - const Word16 speech_fx[], /* i : input speech Q_new*/ - const Word16 Aw_fx[], /* i : weighted A(z) unquantized for subframes */ - const Word16 Aq_fx[], /* i : 12k8 Lp coefficient */ - Word16 *coder_type_fx, /* i : coding type */ - Word16 sharpFlag_fx, /* i : formant sharpening flag */ - const Word16 T_op_fx[], /* i : open loop pitch */ - const Word16 voicing_fx[], /* i : voicing Q15*/ - Word16 *res_fx, /* i : residual signal Q_new*/ - Word16 *synth_fx, /* o : core synthesis Q-1*/ - Word16 *exc_fx, /* i/o: current non-enhanced excitation Q_new*/ - Word16 *exc2_fx, /* o: current enhanced excitation Q0*/ - Word16 *pitch_buf_fx, /* o: floating pitch values for each subframe Q6*/ - Word16 *voice_factors, /* o : voicing factors */ - Word16 *bwe_exc, /* o : excitation for SWB TBE */ - Word16 Q_new, - Word16 shift -) -{ - Word16 xn_fx[L_SUBFR]; /* Target vector for pitch search */ - Word16 h1_fx[L_SUBFR+(M+1)]; /* Impulse response vector */ - Word16 i_subfr; /* tmp variables */ - const Word16 *p_Aw_fx, *p_Aq_fx; /* pointer to LP filter coeff. vector*/ - - Word16 k; - Word16 p_Aq_old_fx[M+1], excQ_ppp_fx[L_FRAME] ,p_Aq_curr_fx[M], pitch_fx[NB_SUBFR]; - Word16 LPC_de_old_fx[M+1], LPC_de_curr_fx[M+1]; - Word16 shift_wsp = add(Q_new,shift); - Word16 rate_ctrl_fx; - Word16 saved_Q_new = Q_new; - - rate_ctrl_fx = st_fx->rate_control_fx; - move16(); - - /*------------------------------------------------------------------* - * ACELP subframe loop - *------------------------------------------------------------------*/ - p_Aw_fx = Aw_fx; - p_Aq_fx = Aq_fx; - FOR (i_subfr=0; i_subfrmem_syn, i_subfr, &mem->mem_w0, p_Aq_fx, - res_fx, L_SUBFR, p_Aw_fx, TILT_FAC_FX, xn_fx, NULL - ,h1_fx - ); - - /* scale xn[] and h1[] to avoid overflow in dot_product12() */ - Scale_sig(xn_fx, L_SUBFR, shift); /* scaling of xn[] to limit dynamic at 12 bits */ - - /* call voiced encoder at this point */ - IF (i_subfr == 0) /* generate the L_FRAME exc */ - { - FOR(k=0; klsp_old_fx, p_Aq_old_fx, M ); - deemph_lpc_fx( p_Aq_curr_fx, p_Aq_old_fx, LPC_de_curr_fx, LPC_de_old_fx ,1); - /* both outputs LPC_de_curr_fx and LPC_de_old_fx are in Q12 */ - - - /* last frame-end lpc and curr frame-end lpc */ - ppp_voiced_encoder_fx( st_fx, res_fx, excQ_ppp_fx, T_op_fx[1], LPC_de_old_fx, - LPC_de_curr_fx, exc_fx, pitch_fx, st_fx->vadsnr_fx, Q_new ); - - Scale_sig(exc_fx, L_FRAME, (saved_Q_new - Q_new)); - if (sub(st_fx->bump_up_fx,1) == 0) - { - i_subfr = L_FRAME; - move16(); - } - } - - IF( sub(st_fx->bump_up_fx,1) != 0 ) - { - /*-----------------------------------------------------------------* - * Gain clipping test to avoid unstable synthesis on frame erasure - * or in case of floating point encoder & fixed p. decoder - *-----------------------------------------------------------------*/ - gp_clip_fx(st_fx->core_brate_fx, voicing_fx, i_subfr, *coder_type_fx, xn_fx, st_fx->clip_var_fx, sub(shift_wsp,1)); - - - /* run the above to maintain gain clipping memories */ - gp_clip_test_gain_pit_fx( st_fx->core_brate_fx, st_fx->prev_ppp_gain_pit_fx, st_fx->clip_var_fx ); - - - /*-----------------------------------------------------------------* - * Synthesize speech to update mem_syn[]. - * Update A(z) filters - *-----------------------------------------------------------------*/ - - Syn_filt_s( 1, p_Aq_fx, M, &excQ_ppp_fx[i_subfr], &synth_fx[i_subfr], L_SUBFR, mem->mem_syn, 1 ); - - - p_Aw_fx += (M+1); - p_Aq_fx += (M+1); - } - - } /* end of subframe loop */ - - IF( st_fx->bump_up_fx ) - { - /* PPP failed, bump up */ - st_fx->ppp_mode_fx = 0; - move16(); - st_fx->core_brate_fx = ACELP_7k20; - move16(); - st_fx->pppcountE_fx = 0; - move16(); - - IF ( st_fx->set_ppp_generic_fx ) - { - *coder_type_fx = GENERIC; - move16(); - } - ELSE - { - *coder_type_fx = VOICED; - move16(); - } - - /* We write signalling indices again only in case of bump_up */ - /* delete previous indices */ - reset_indices_enc_fx( st_fx ); - - /* signalling matrix (writing of signalling bits) */ - signalling_enc_fx( st_fx, *coder_type_fx, sharpFlag_fx ); - } - ELSE - { - Copy(excQ_ppp_fx, exc_fx, L_FRAME); - - /*-----------------------------------------------------------------* - * Updates: last value of new target is stored in mem_w0 - *-----------------------------------------------------------------*/ - - mem->mem_w0 = sub(shr(xn_fx[L_SUBFR-1],shift), shr(exc_fx[L_FRAME-1],1)); /*Q_new-1 */ - - Copy(exc_fx, exc2_fx, L_FRAME); - - st_fx->dm_fx.prev_state = 2; - move16();/*Q0 dispMem index 0 */ - st_fx->dm_fx.prev_gain_pit[0] = st_fx->prev_ppp_gain_pit_fx; - move16();/*Q14 dispMem index 2 */ - - FOR( k=1; k<5; k++ ) - { - st_fx->dm_fx.prev_gain_pit[k] = st_fx->dm_fx.prev_gain_pit[k-1]; - move16(); - } - - mem->tilt_code = st_fx->prev_tilt_code_fx; - move16(); - Copy(pitch_fx, pitch_buf_fx, NB_SUBFR); - pitch_buf_fx[ NB_SUBFR16k -1 ] = pitch_fx[ NB_SUBFR - 1 ]; - - interp_code_5over2_fx( exc2_fx, bwe_exc, L_FRAME ); - set16_fx( voice_factors, 0, NB_SUBFR16k ); - } - - st_fx->rate_control_fx = rate_ctrl_fx; - move16(); - - return; -} diff --git a/src/libs/libevs/lib_enc/enc_prm.cpp b/src/libs/libevs/lib_enc/enc_prm.cpp old mode 100755 new mode 100644 index 1a84eadd..0d389377 --- a/src/libs/libevs/lib_enc/enc_prm.cpp +++ b/src/libs/libevs/lib_enc/enc_prm.cpp @@ -1,53 +1,52 @@ /*==================================================================================== - EVS Codec 3GPP TS26.442 Apr 03, 2018. Version 12.11.0 / 13.6.0 / 14.2.0 + EVS Codec 3GPP TS26.443 Nov 13, 2018. Version 12.11.0 / 13.7.0 / 14.3.0 / 15.1.0 ====================================================================================*/ #include +#include #include #include #include #include "options.h" -#include "rom_com_fx.h" -#include "stl.h" -#include "prot_fx.h" +#include "cnst.h" +#include "rom_com.h" +#include "prot.h" +/*-------------------------------------------------------------------* + * enc_prm_hm() + * + * + *-------------------------------------------------------------------*/ + static void enc_prm_hm( - Word16 *prm_hm, - Encoder_State_fx *st, - Word16 L_frame + int *prm_hm, + Encoder_State *st, + int L_frame ) { - Word8 flag; - /* Disable HM for non-GC,VC modes */ - test(); - IF (sub(st->tcx_cfg.coder_type, VOICED) != 0 && sub(st->tcx_cfg.coder_type, GENERIC) != 0) + if( st->tcx_cfg.coder_type != VOICED && st->tcx_cfg.coder_type != GENERIC ) { return; } /* Flag */ - push_next_indice_fx(st, prm_hm[0], 1); + push_next_indice(st, prm_hm[0], 1); - IF (prm_hm[0]) + if( prm_hm[0] ) { /* Periodicy index */ - flag = 0; - move16(); - if ( sub(L_frame, 256) >= 0) - { - flag = 1; - move16(); - } - EncodeIndex(flag, prm_hm[1], st); + EncodeIndex( L_frame >= 256, prm_hm[1], st ); - IF (sub(st->tcx_cfg.coder_type, VOICED) == 0) + if( st->tcx_cfg.coder_type == VOICED ) { /* Gain index */ - push_next_indice_fx(st, prm_hm[2], kTcxHmNumGainBits); + push_next_indice(st, prm_hm[2], kTcxHmNumGainBits); } } + + return; } /*-----------------------------------------------------------------* @@ -57,145 +56,122 @@ static void enc_prm_hm( * encode RF parameters for ACELP and TCX partial copy * *-----------------------------------------------------------------*/ -void enc_prm_rf( Encoder_State_fx *st, - const Word16 rf_frame_type, - const Word16 fec_offset +void enc_prm_rf( Encoder_State *st, + const short rf_frame_type, + const short fec_offset ) { - Word16 sfr, nb_subfr, n, index; - Word16 ltp_mode, ltf_mode, gains_mode; + short sfr, nb_subfr, n, index; + short ltp_mode, ltf_mode, gains_mode; nb_subfr = st->nb_subfr; /* partial copy bitstream writing */ - test(); - IF ( sub(rf_frame_type,RF_TCXFD) >= 0 && sub(rf_frame_type,RF_TCXTD2) <= 0) + if ( rf_frame_type >= RF_TCXFD && rf_frame_type <= RF_TCXTD2) { /* TCX frames partial copy write */ - - /* LSF indices */ - IF( sub(rf_frame_type, RF_TCXFD) == 0 ) + if(rf_frame_type == RF_TCXFD) { - push_next_indice_fx(st, st->rf_indx_lsf[fec_offset][0], lsf_numbits[0]); /* VQ 1 */ - push_next_indice_fx(st, st->rf_indx_lsf[fec_offset][1], lsf_numbits[1]); /* VQ 2 */ - push_next_indice_fx(st, st->rf_indx_lsf[fec_offset][2], lsf_numbits[2]); /* VQ 3 */ + push_next_indice(st, st->rf_indx_lsf[fec_offset][0], lsf_numbits[0]); /* VQ 1 */ + push_next_indice(st, st->rf_indx_lsf[fec_offset][1], lsf_numbits[1]); /* VQ 2 */ + push_next_indice(st, st->rf_indx_lsf[fec_offset][2], lsf_numbits[2]); /* VQ 3 */ } /* classification */ - test(); - test(); - IF( sub(st->rf_clas[fec_offset], UNVOICED_CLAS) == 0 ) + if( st->rf_clas[fec_offset] == UNVOICED_CLAS ) { index = 0; - move16(); } - ELSE IF( (sub(st->rf_clas[fec_offset], VOICED_TRANSITION) == 0) || (sub(st->rf_clas[fec_offset], UNVOICED_TRANSITION) == 0) ) + else if( (st->rf_clas[fec_offset] == VOICED_TRANSITION) || (st->rf_clas[fec_offset] == UNVOICED_TRANSITION) ) { index = 1; - move16(); } - ELSE IF( sub(st->rf_clas[fec_offset], VOICED_CLAS) == 0 ) + else if( st->rf_clas[fec_offset] == VOICED_CLAS ) { index = 2; - move16(); } - ELSE + else { index = 3; - move16(); } - push_next_indice_fx(st, index, 2); + push_next_indice(st, index, 2); - IF( sub(rf_frame_type, RF_TCXFD) == 0 ) + if(rf_frame_type == RF_TCXFD) { /* TCX global gain = 7 bits */ - push_next_indice_fx(st, st->rf_gain_tcx[fec_offset], 7); - /*window info - 1 bit for long overlap - 2 if minimum or half overlap*/ + push_next_indice(st, st->rf_gain_tcx[fec_offset], 7); } - ELSE + else { - /*gains adapt - gains inov*/ - - /*LPC on full rate -> excitation */ - /* pitch and gain */ /* LTP data */ - test(); - IF ( (sub(rf_frame_type, RF_TCXTD1) == 0 || sub(rf_frame_type, RF_TCXTD2) == 0) && st->tcxltp != 0 ) + if ( (rf_frame_type == RF_TCXTD1 || rf_frame_type == RF_TCXTD2) && st->tcxltp ) { - push_next_indice_fx(st, st->rf_tcxltp_param[fec_offset], 9); + push_next_indice(st, st->rf_tcxltp_param[fec_offset], 9); } } } - ELSE IF( sub(rf_frame_type,7) == 0 ) /* NELP bitstream writing */ + else if( rf_frame_type == 7 ) /* NELP bitstream writing */ { /* LSF indices */ - push_next_indice_fx(st, st->rf_indx_lsf[fec_offset][0], 8); /* VQ 1 */ - push_next_indice_fx(st, st->rf_indx_lsf[fec_offset][1], 8); /* VQ 2 */ + push_next_indice(st, st->rf_indx_lsf[fec_offset][0], 8); /* VQ 1 */ + push_next_indice(st, st->rf_indx_lsf[fec_offset][1], 8); /* VQ 2 */ /* NELP gain indices */ - push_next_indice_fx( st, st->rf_indx_nelp_iG1[fec_offset], 5 ); - push_next_indice_fx( st, st->rf_indx_nelp_iG2[fec_offset][0], 6 ); - push_next_indice_fx( st, st->rf_indx_nelp_iG2[fec_offset][1], 6 ); + push_next_indice( st, st->rf_indx_nelp_iG1[fec_offset], 5 ); + push_next_indice( st, st->rf_indx_nelp_iG2[fec_offset][0], 6 ); + push_next_indice( st, st->rf_indx_nelp_iG2[fec_offset][1], 6 ); /* NELP filter selection index */ - push_next_indice_fx( st, st->rf_indx_nelp_fid[fec_offset], 2 ); + push_next_indice( st, st->rf_indx_nelp_fid[fec_offset], 2 ); /* tbe gainFr */ - push_next_indice_fx( st, st->rf_indx_tbeGainFr[fec_offset], 5 ); + push_next_indice( st, st->rf_indx_tbeGainFr[fec_offset], 5 ); } - ELSE IF ( sub(rf_frame_type,4) >= 0 ) /* rf_frame_type ALL_PRED: 4, NO_PRED: 5, GEN_PRED: 6 */ + else if ( rf_frame_type >= 4 ) /* rf_frame_type ALL_PRED: 4, NO_PRED: 5, GEN_PRED: 6 */ { /* LSF indices */ - push_next_indice_fx(st, st->rf_indx_lsf[fec_offset][0], 8); /* VQ 1 */ - push_next_indice_fx(st, st->rf_indx_lsf[fec_offset][1], 8); /* VQ 2 */ + push_next_indice(st, st->rf_indx_lsf[fec_offset][0], 8); /* VQ 1 */ + push_next_indice(st, st->rf_indx_lsf[fec_offset][1], 8); /* VQ 2 */ /* ES pred */ - push_next_indice_fx(st, st->rf_indx_EsPred[fec_offset], 3); + push_next_indice(st, st->rf_indx_EsPred[fec_offset], 3); ltp_mode = ACELP_LTP_MODE[1][1][rf_frame_type]; ltf_mode = ACELP_LTF_MODE[1][1][rf_frame_type]; gains_mode = ACELP_GAINS_MODE[1][1][rf_frame_type]; /* Subframe parameters */ - FOR( sfr = 0; sfr < nb_subfr; sfr++ ) + for( sfr = 0; sfr < nb_subfr; sfr++ ) { /* Pitch lag (5, or 8 bits) */ n = ACELP_LTP_BITS_SFR[ltp_mode][sfr]; - IF (n != 0) + if (n != 0) { - push_next_indice_fx(st, st->rf_indx_pitch[fec_offset][sfr], n); + push_next_indice(st, st->rf_indx_pitch[fec_offset][sfr], n); } /* Adaptive codebook filtering (1 bit) */ - IF( sub(ltf_mode,2) == 0 ) + if( ltf_mode == 2 ) { - push_next_indice_fx(st, st->rf_indx_ltfMode[fec_offset][sfr], 1); + push_next_indice(st, st->rf_indx_ltfMode[fec_offset][sfr], 1); } /*Innovative codebook*/ - test(); - test(); - test(); - IF( (sub(rf_frame_type,RF_NOPRED) == 0) || - (sub(rf_frame_type,RF_GENPRED) == 0 && - (sfr == 0 || sub(sfr,2) == 0)) ) + if( (rf_frame_type == RF_NOPRED) + || ( rf_frame_type == RF_GENPRED && (sfr == 0 || sfr == 2)) ) { - push_next_indice_fx(st, st->rf_indx_fcb[fec_offset][sfr], 7); + push_next_indice(st, st->rf_indx_fcb[fec_offset][sfr], 7); } /* Gains (5b, 6b or 7b / subfr) */ - test(); - IF( sfr == 0 || sub(sfr,2) == 0 ) + if( sfr == 0 || sfr == 2 ) { n = ACELP_GAINS_BITS[gains_mode]; - push_next_indice_fx(st, st->rf_indx_gain[fec_offset][sfr], n); + push_next_indice(st, st->rf_indx_gain[fec_offset][sfr], n); } } /* tbe gainFr */ - push_next_indice_fx( st, st->rf_indx_tbeGainFr[fec_offset], 2 ); + push_next_indice( st, st->rf_indx_tbeGainFr[fec_offset], 2 ); } /***************/ @@ -205,27 +181,22 @@ void enc_prm_rf( Encoder_State_fx *st, /***************/ /* write FEC offset just before the rf_frame_type */ - test(); - test(); - IF(sub(fec_offset,2) == 0 ) + if(fec_offset == 2 ) { - push_next_indice_fx(st, 0, 2); + push_next_indice(st, 0, 2); } - ELSE IF(sub(fec_offset,3) == 0 || sub(fec_offset,5) == 0 || sub(fec_offset,7) == 0) + else if(fec_offset == 3 || fec_offset == 5 || fec_offset == 7) { - push_next_indice_fx(st, (fec_offset - 1)/2, 2); + push_next_indice(st, (fec_offset - 1)/2, 2); } /* write RF frame type last in the bitstream */ - push_next_indice_fx(st, rf_frame_type, 3); + push_next_indice(st, rf_frame_type, 3); } - - - /*-----------------------------------------------------------------* - * Funtion enc_prm() * + * Function enc_prm() * * ~~~~~~~~~~~~~~~~~~~~~~ * * * * encode parameters according to selected mode including * @@ -233,202 +204,174 @@ void enc_prm_rf( Encoder_State_fx *st, *-----------------------------------------------------------------*/ void enc_prm( - const Word16 coder_type, /* (i) : coding type */ - Word16 param[], /* (i) : parameters */ - Word16 param_lpc[], /* (i) : LPC parameters */ - Encoder_State_fx *st, /* i/o : quantization Analysis values */ - Word16 L_frame, - CONTEXT_HM_CONFIG hm_cfg[] - ,Word16 * bits_param_lpc, - Word16 no_param_lpc + const short coder_type, /* i : coding type */ + int param[], /* i : parameters */ + int param_lpc[], /* i : LPC parameters */ + Encoder_State *st, /* i/o: quantization Analysis values */ + const short L_frame, /* i : frame length */ + CONTEXT_HM_CONFIG hm_cfg[], + short * bits_param_lpc, + short no_param_lpc ) { - Word16 j, k, n, sfr, core, last_core, *prm, tmp; - Word16 nbits_start, total_nbbits; - Word16 nbits_header; - Word16 nbits_lpc; - Word16 nbits_tcx; - Word16 lg,nb_subfr; - Word16 lgFB; - Word16 nTnsParams; - Word16 nTnsBits; - Word16 ix, j_old, wordcnt, bitcnt; - Word16 hm_size; - Word16 numlpc; - Word8 flag_ctx_hm; - Word16 index; - Word32 tmp32; - CONTEXT_HM_CONFIG * phm_cfg; - Word16 idx; - Word16 start_idx; - Word16 nBits; + short j, k, n, sfr, core, last_core; + int *prm; + short nbits_start, total_nbbits, nbits_header, nbits_lpc, nbits_tcx; + short lg, nb_subfr; + int lgFB; + int nTnsParams, nTnsBits; + int ix, j_old, wordcnt, bitcnt; + short hm_size; + short numlpc, index; + short flag_ctx_hm; + + int idx; + int start_idx; + short nBits; /*--------------------------------------------------------------------------------* - * INIT + * initialization *--------------------------------------------------------------------------------*/ - move16(); - move16(); - move16(); - move16(); - move16(); - move16(); - nbits_lpc=0; + nbits_lpc = 0; nbits_tcx = 0; flag_ctx_hm = 0; /* Useful parameters */ - move16(); - move16(); - move16(); nb_subfr = st->nb_subfr; - core = st->core_fx; - last_core = st->last_core_fx; + core = st->core; + last_core = st->last_core; /* Initialize pointers */ - move16(); prm = param; /* Init counters */ - move16(); - move16(); j = 0; - nbits_start = st->nb_bits_tot_fx; - + nbits_start = st->nb_bits_tot; /*--------------------------------------------------------------------------------* * HEADER *--------------------------------------------------------------------------------*/ - IF (sub(st->mdct_sw, MODE1) == 0) + if (st->mdct_sw == MODE1) { /* Adjust st->bits_frame_core not to subtract MODE2 bandwidth signaling */ - st->bits_frame_core = add(st->bits_frame_core, FrameSizeConfig[st->frame_size_index].bandwidth_bits); + st->bits_frame_core += FrameSizeConfig[st->frame_size_index].bandwidth_bits; /* Write MODE1 core mode signaling */ signalling_mode1_tcx20_enc(st, 1); } + /* EVS header */ /* Modes (ACE_GC, ACE_UC, TCX20, TCX10...) */ - - IF ( st->tcxonly ) + if ( st->tcxonly ) { - push_next_indice_fx(st, core==TCX_10_CORE, 1); + push_next_indice(st, core == TCX_10_CORE, 1); { - index = 3; - move16(); - test(); - IF( sub(st->clas_fx, UNVOICED_CLAS) == 0 ) + if( st->clas == UNVOICED_CLAS ) { index = 0; - move16(); } - ELSE IF( (sub(st->clas_fx, VOICED_TRANSITION) == 0) || (sub(st->clas_fx, UNVOICED_TRANSITION) == 0) ) + else if( (st->clas == VOICED_TRANSITION) || (st->clas == UNVOICED_TRANSITION) ) { index = 1; - move16(); } - ELSE IF( sub(st->clas_fx, VOICED_CLAS) == 0 ) + else if( st->clas == VOICED_CLAS ) { index = 2; - move16(); } - push_next_indice_fx(st, index, 2); + else + { + index = 3; + } + push_next_indice(st, index, 2); } } - ELSE + else { - IF ( core==ACELP_CORE ) + if ( core == ACELP_CORE ) { /* write the RF signalling information */ - IF( sub(st->rf_mode,1) == 0) + if( st->rf_mode ==1 ) { /* find the section in the ACELP signalling table corresponding to bitrate */ idx = 0; - WHILE ( L_sub(acelp_sig_tbl[idx],st->total_brate_fx) != 0 ) /* total bitrate is kept at 13.2kbps */ + while ( acelp_sig_tbl[idx] != st->total_brate ) /* total bitrate is kept at 13.2kbps */ { - idx = add(idx,1); + idx++; } /* retrieve the number of bits for signalling */ - nBits = (Word16) acelp_sig_tbl[++idx]; + nBits = (short) acelp_sig_tbl[++idx]; /* retrieve the signalling index */ - idx = add(idx,1); - start_idx = idx; - tmp32 = SIG2IND_fx(coder_type, st->bwidth_fx, st->sharpFlag, st->rf_mode); - WHILE( L_sub(acelp_sig_tbl[idx], tmp32) != 0 ) + start_idx = ++idx; + while( acelp_sig_tbl[idx] != SIG2IND(coder_type, st->bwidth, st->sharpFlag, st->rf_mode) ) { - idx = add(idx,1); + idx++; } - push_next_indice_fx( st, idx - start_idx, nBits); - push_next_indice_fx( st, 0, 1); /* Indicate to the decoder that the core is ACELP*/ + push_next_indice( st, idx - start_idx, nBits); + push_next_indice( st, 0, 1); /* Indicate to the decoder that the core is ACELP*/ nbits_start = 3; } - ELSE + else { - push_next_indice_fx(st, coder_type, 3); + push_next_indice( st, coder_type, 3 ); } } - ELSE + else { - IF (sub(st->mdct_sw, MODE1) == 0) + if (st->mdct_sw == MODE1) { /* 2 bits instead of 3 as TCX is already signaled */ - push_next_indice_fx(st, st->tcx_cfg.coder_type, 2 ); + push_next_indice(st, st->tcx_cfg.coder_type, 2 ); } - ELSE + else { - IF (sub(st->mdct_sw_enable, MODE2) == 0) + if (st->mdct_sw_enable == MODE2) { - push_next_indice_fx(st, 1, 1); /* TCX */ - push_next_indice_fx(st, 0, 1); /* not HQ_CORE */ - push_next_indice_fx(st, st->tcx_cfg.coder_type, 2); + push_next_indice(st, 1, 1); /* TCX */ + push_next_indice(st, 0, 1); /* not HQ_CORE */ + push_next_indice(st, st->tcx_cfg.coder_type, 2); } - ELSE + else { /*write the RF signalling information*/ - IF( sub(st->rf_mode,1) == 0) + if( st->rf_mode ==1 ) { /* find the section in the ACELP signalling table corresponding to bitrate */ idx = 0; - WHILE (L_sub(acelp_sig_tbl[idx],st->total_brate_fx) != 0) + while ( acelp_sig_tbl[idx] != st->total_brate ) { - idx = add(idx,1); + idx++; } /* retrieve the number of bits for signalling */ - nBits = (Word16) acelp_sig_tbl[++idx]; + nBits = (short) acelp_sig_tbl[++idx]; - test(); - test(); - IF(sub(st->tcx_cfg.coder_type,VOICED) == 0 || - sub(st->tcx_cfg.coder_type,GENERIC) == 0 || - sub(st->tcx_cfg.coder_type,TRANSITION) == 0) + if(st->tcx_cfg.coder_type == VOICED || st->tcx_cfg.coder_type == GENERIC || st->tcx_cfg.coder_type == TRANSITION) { st->sharpFlag=1; } - ELSE + else { st->sharpFlag=0; } /* retrieve the signalling index */ - idx = add(idx,1); - start_idx = idx; - tmp32 = SIG2IND_fx(st->tcx_cfg.coder_type, st->bwidth_fx, st->sharpFlag, st->rf_mode); - WHILE( L_sub(acelp_sig_tbl[idx], tmp32)!= 0 ) + start_idx = ++idx; + while( acelp_sig_tbl[idx] != SIG2IND(st->tcx_cfg.coder_type, st->bwidth, st->sharpFlag, st->rf_mode) ) { - idx = add(idx,1); + idx++; } - push_next_indice_fx( st, idx - start_idx, nBits); - push_next_indice_fx( st, 1, 1); /* Indicate to the decoder that the core is TCX*/ + push_next_indice( st, idx - start_idx, nBits); + push_next_indice( st, 1, 1); /* Indicate to the decoder that the core is TCX*/ nbits_start = 3; } - ELSE + else { - push_next_indice_fx(st, 4+st->tcx_cfg.coder_type, 3 ); + push_next_indice(st, ACELP_MODE_MAX + st->tcx_cfg.coder_type, 3 ); } } } @@ -436,120 +379,100 @@ void enc_prm( } /* Encode previous mode for error concealment */ - test(); - IF (!(core==ACELP_CORE&&st->tcx_cfg.lfacNext<=0)) + if( !( core == ACELP_CORE && st->tcx_cfg.lfacNext<=0 ) ) { - tmp = 0; - move16(); - test(); - IF( sub(last_core, ACELP_CORE) != 0 || sub(core, TCX_10_CORE) == 0 ) - - { - tmp = TCX_20_CORE; - move16(); - } - push_next_indice_fx(st, tmp, 1); + push_next_indice(st, ((last_core!=ACELP_CORE) || (core==TCX_10_CORE)), 1); } /* write TCX overlap mode (1 bit: full, 2 bits: half or no overlap) */ - IF ( core!=ACELP_CORE ) + if( core != ACELP_CORE ) { - Word16 overlap_code; + int overlap_code; assert(st->tcx_cfg.tcx_curr_overlap_mode != NOT_SUPPORTED && st->tcx_cfg.tcx_curr_overlap_mode <= ALDO_WINDOW && st->tcx_cfg.tcx_curr_overlap_mode >= FULL_OVERLAP); /*1 is not allowed!*/ - IF (sub(st->tcx_cfg.tcx_curr_overlap_mode, MIN_OVERLAP) == 0) + if (st->tcx_cfg.tcx_curr_overlap_mode == MIN_OVERLAP) { nbits_tcx = 2; - move16(); overlap_code = 2; - move16(); } - ELSE IF (sub(st->tcx_cfg.tcx_curr_overlap_mode, HALF_OVERLAP) == 0) + else if (st->tcx_cfg.tcx_curr_overlap_mode == HALF_OVERLAP) { nbits_tcx = 2; - move16(); overlap_code = 3; - move16(); } - ELSE + else { nbits_tcx = 1; - move16(); overlap_code = 0; - move16(); } - push_next_indice_fx(st, overlap_code, nbits_tcx); + push_next_indice(st, overlap_code, nbits_tcx); } - IF( st->plcExt.enableGplc ) + if( st->plcExt.enableGplc ) { /* encode side information. */ enc_prm_side_Info( &st->plcExt, st ); } - IF( st->glr != 0) + if( st->glr ) { - test(); - test(); - test(); - test(); - if (core != ACELP_CORE || sub(coder_type,INACTIVE) == 0 || (st->last_core_fx == ACELP_CORE && sub(st->last_coder_type_raw_fx, INACTIVE) == 0) || st->glr_reset != 0) + if( core != ACELP_CORE || coder_type == INACTIVE || + (st->last_core == ACELP_CORE && st->last_coder_type_raw == INACTIVE) || + st->glr_reset ) { st->glr_idx[0] = 0; - move16(); } - IF( sub(core,ACELP_CORE) == 0 ) + if( core == ACELP_CORE ) { - push_next_indice_fx(st, st->glr_idx[0], G_LPC_RECOVERY_BITS); + push_next_indice(st, st->glr_idx[0], G_LPC_RECOVERY_BITS); } } st->glr_reset = 0; - move16(); - - nbits_header = sub(st->nb_bits_tot_fx, nbits_start); + nbits_header = st->nb_bits_tot - nbits_start; /*--------------------------------------------------------------------------------* * LPC PARAMETERS *--------------------------------------------------------------------------------*/ - IF ( s_and(st->enableTcxLpc!=0, core != ACELP_CORE) ) + if( st->enableTcxLpc && core != ACELP_CORE ) { /* Encode the indices */ nbits_lpc = enc_lsf_tcxlpc(¶m_lpc, st); } - ELSE + else { - IF (st->lpcQuantization == 0) + if( st->lpcQuantization == 0 ) { /* LPC quantizer */ - numlpc = 2; - move16(); - if(sub(core, TCX_20_CORE) == 0) + if(core == TCX_20_CORE) { numlpc = 1; - move16(); + } + else + { + numlpc = 2; } nbits_lpc = encode_lpc_avq(st, numlpc, param_lpc, core); } - ELSE IF (sub(st->lpcQuantization, 1)==0) + else if( st->lpcQuantization == 1 ) { - test(); - test(); - IF(L_sub(st->sr_core, 16000)==0 && sub(coder_type, VOICED) == 0 && sub(core, ACELP_CORE) == 0) + if(st->sr_core == 16000 && coder_type == VOICED + && core==ACELP_CORE + ) { nbits_lpc = lsf_bctcvq_encprm(st, param_lpc, bits_param_lpc, no_param_lpc); } - ELSE + else { nbits_lpc = lsf_msvq_ma_encprm(st, param_lpc, core, coder_type, st->acelp_cfg.midLpc, bits_param_lpc, no_param_lpc ); } } - ELSE + else { - assert(0 && "LPC quant not supported!"); + assert(0); } } @@ -563,208 +486,175 @@ void enc_prm( /*--------------------------------------------------------------------------------* * ACELP *--------------------------------------------------------------------------------*/ - - IF (core == ACELP_CORE) + if( core == ACELP_CORE ) { /* Adaptive BPF (2 bits)*/ n = ACELP_BPF_BITS[st->acelp_cfg.bpf_mode]; - IF(n!=0) + if( n!=0 ) { - push_next_indice_fx(st, st->bpf_gain_param, n); + push_next_indice(st, st->bpf_gain_param, n); } /* Mean energy (2 or 3 bits) */ n = ACELP_NRG_BITS[st->acelp_cfg.nrg_mode]; - IF(n!=0) + if( n!=0 ) { - push_next_indice_fx(st, prm[j++], n); + push_next_indice(st, prm[j++], n); } /* Subframe parameters */ - - FOR (sfr=0; sfracelp_cfg.ltp_mode][sfr]; - IF (n!=0) + if (n!=0) { - push_next_indice_fx(st, prm[j++], n); + push_next_indice(st, prm[j++], n); } /* Adaptive codebook filtering (1 bit) */ - - IF(sub(st->acelp_cfg.ltf_mode,2)==0) + if( st->acelp_cfg.ltf_mode == 2 ) { - push_next_indice_fx(st, prm[j++], 1); + push_next_indice(st, prm[j++], 1); } /*Innovative codebook*/ + + j_old = j; + if ((st->acelp_cfg.fixed_cdk_index[sfr] >= ACELP_FIXED_CDK_NB) || (st->acelp_cfg.fixed_cdk_index[sfr] < 0)) { - move16(); - j_old = j; - - if ((st->acelp_cfg.fixed_cdk_index[sfr] >= ACELP_FIXED_CDK_NB) || (st->acelp_cfg.fixed_cdk_index[sfr] < 0)) - { - fprintf(stderr,"ACELP bits allocation: wrong fixed cdk bit allocation\n"); - assert(0); - } - - - wordcnt = shr(ACELP_FIXED_CDK_BITS(st->acelp_cfg.fixed_cdk_index[sfr]), 4); - - bitcnt = s_and(ACELP_FIXED_CDK_BITS(st->acelp_cfg.fixed_cdk_index[sfr]), 15); - - - FOR (ix = 0; ix < wordcnt; ix++) - { - push_next_indice_fx(st, prm[j++], 16); - } - - IF (bitcnt) - { - push_next_indice_fx(st, prm[j++], bitcnt); - } - - j = add(j_old, 8); + fprintf(stderr,"ACELP bits allocation: wrong fixed cdk bit allocation\n"); + assert(0); } + wordcnt = ACELP_FIXED_CDK_BITS(st->acelp_cfg.fixed_cdk_index[sfr]) >> 4; + bitcnt = ACELP_FIXED_CDK_BITS(st->acelp_cfg.fixed_cdk_index[sfr]) & 15; + + for (ix = 0; ix < wordcnt; ix++) + { + push_next_indice(st, prm[j++], 16); + } + + if (bitcnt) + { + push_next_indice(st, prm[j++], bitcnt); + } + + j = j_old+8; + /* Gains (5b, 6b or 7b / subfr) */ - n = ACELP_GAINS_BITS[st->acelp_cfg.gains_mode[sfr]]; - push_next_indice_fx(st, prm[j++], n); - }/*end of for(sfr)*/ - }/*end of mode[0]==0*/ + n=ACELP_GAINS_BITS[st->acelp_cfg.gains_mode[sfr]]; + push_next_indice(st, prm[j++], n); + } + + } /*--------------------------------------------------------------------------------* * TCX20 *--------------------------------------------------------------------------------*/ - IF ( s_or(sub(core,TCX_20_CORE) == 0, sub(core,HQ_CORE) == 0) ) + + if( core == TCX_20_CORE ) { - flag_ctx_hm = 0; - move16(); - IF(st->enablePlcWaveadjust) + if( st->enablePlcWaveadjust ) { - push_next_indice_fx(st, st->Tonal_SideInfo, 1); + push_next_indice(st, st->Tonal_SideInfo, 1); } /* TCX Gain = 7 bits */ - push_next_indice_fx(st, prm[j++], 7); + push_next_indice(st, prm[j++], 7); /* TCX Noise Filling = NBITS_NOISE_FILL_LEVEL bits */ - push_next_indice_fx(st, prm[j++], NBITS_NOISE_FILL_LEVEL); + push_next_indice(st, prm[j++], NBITS_NOISE_FILL_LEVEL); /* LTP data */ - test(); - IF ( st->tcxltp || L_sub(st->sr_core, 25600) > 0) + if ( st->tcxltp || (st->sr_core > 25600) ) /* PLC pitch info for HB */ { - IF ( prm[j] ) + if ( prm[j] ) { - push_next_indice_fx(st, 1 , 1); - push_next_indice_fx(st, prm[j+1], 9); - push_next_indice_fx(st, prm[j+2], 2); + push_next_indice(st, 1 , 1); + push_next_indice(st, prm[j+1], 9); + push_next_indice(st, prm[j+2], 2); } - ELSE + else { - push_next_indice_fx(st, 0 , 1); + push_next_indice(st, 0, 1); } } - j = add(j, 3); + + j += 3; /* TCX spectral data */ lg = L_frame; - move16(); lgFB = st->tcx_cfg.tcx_coded_lines; - move16(); - - IF ( last_core==ACELP_CORE ) + if ( last_core == ACELP_CORE ) { /* ACE->TCX transition */ - lg = add(lg, st->tcx_cfg.tcx_offset); - lgFB = add(lgFB, shr(lgFB, 2)); + lg += st->tcx_cfg.tcx_offset; + lgFB += lgFB >> 2; if(st->tcx_cfg.lfacNext<0) { - lg = sub(lg,st->tcx_cfg.lfacNext); + lg -= st->tcx_cfg.lfacNext; } } /* TNS data */ nTnsParams = 0; - move16(); nTnsBits = 0; - move16(); - IF (st->tcx_cfg.fIsTNSAllowed) + if (st->tcx_cfg.fIsTNSAllowed) { WriteTnsData(st->tcx_cfg.pCurrentTnsConfig, prm+j, &nTnsParams, st, &nTnsBits); - j = add(j, nTnsParams); + j += nTnsParams; } - hm_size = shl(mult(st->tcx_cfg.bandwidth, lg), 1); - test(); - IF ( st->tcx_lpc_shaped_ari && sub(last_core, ACELP_CORE) != 0 ) + hm_size = (int)(2.0f*st->tcx_cfg.bandwidth*(float)lg); + + if (st->tcx_lpc_shaped_ari && last_core != ACELP_CORE) { - enc_prm_hm(&prm[j], st, hm_size); + enc_prm_hm( &prm[j], st, hm_size ); } /*Context HM flag*/ - test(); - IF ( st->tcx_cfg.ctx_hm && sub(last_core, ACELP_CORE) != 0 ) + if ( st->tcx_cfg.ctx_hm && (last_core != ACELP_CORE) ) { - push_next_indice_fx(st, prm[j], 1); + push_next_indice(st, prm[j], 1); - IF (prm[j]) + if (prm[j]) { - EncodeIndex(sub(hm_size,256) >= 0, prm[j+1], st); - flag_ctx_hm = 1; - move16(); + EncodeIndex(hm_size >= 256, prm[j+1], st); + + flag_ctx_hm=1; } } - j = add(j, NPRM_CTX_HM); - - IF (st->igf) + j += NPRM_CTX_HM; + /* IGF data */ + if (st->igf) { st->hIGFEnc.infoTotalBitsPerFrameWritten = 0; - move16(); - IF (sub(st->last_core_fx, ACELP_CORE) == 0) - { - IGFEncWriteBitstream( &st->hIGFEnc, st, &st->hIGFEnc.infoTotalBitsPerFrameWritten, - IGF_GRID_LB_TRAN, 1 ); - } - ELSE - { - IGFEncWriteBitstream( &st->hIGFEnc, st, &st->hIGFEnc.infoTotalBitsPerFrameWritten, - IGF_GRID_LB_NORM, 1 ); - } + IGFEncWriteBitstream( &st->hIGFEnc, st, &st->hIGFEnc.infoTotalBitsPerFrameWritten, + (st->last_core == ACELP_CORE)?IGF_GRID_LB_TRAN:IGF_GRID_LB_NORM, 1 ); } - total_nbbits = sub(st->nb_bits_tot_fx, nbits_start); - if(sub(st->rf_mode,1)==0) - { - total_nbbits = add(total_nbbits,st->rf_target_bits_write); - } - nbits_tcx = sub(st->bits_frame_core, total_nbbits); - IF (st->tcx_lpc_shaped_ari != 0) + total_nbbits = st->nb_bits_tot - nbits_start; + if(st->rf_mode) { - push_next_bits_fx(st, &prm[++j], nbits_tcx); - j = add(j, nbits_tcx); + total_nbbits += st->rf_target_bits_write; } - ELSE + nbits_tcx = st->bits_frame_core - total_nbbits; + + if (st->tcx_lpc_shaped_ari) { - phm_cfg = NULL; - move16(); - if (flag_ctx_hm) - { - phm_cfg = hm_cfg; - move16(); - } - ACcontextMapping_encode2_no_mem_s17_LC(st, prm+j, - lgFB, - prm[j-1], /* lastnz */ - nbits_tcx, NPRM_RESQ * st->tcx_cfg.resq, phm_cfg); + push_next_bits(st, &prm[++j], nbits_tcx); + j += nbits_tcx; + } + else + { + ACcontextMapping_encode2_no_mem_s17_LC( st, prm+j, lgFB, prm[j-1], /* lastnz */ + nbits_tcx, NPRM_RESQ * st->tcx_cfg.resq, flag_ctx_hm?hm_cfg:NULL ); } } @@ -774,122 +664,95 @@ void enc_prm( * TCX10 *--------------------------------------------------------------------------------*/ - - IF (sub(core,TCX_10_CORE) == 0) + if( core == TCX_10_CORE ) { - Word16 nbits_igf = 0; - move16(); - IF (st->igf) + int nbits_igf = 0; + if (st->igf) { nbits_igf = IGFEncWriteConcatenatedBitstream( &st->hIGFEnc, st ); } - FOR (k = 0; k < 2; k++) + + for (k = 0; k < 2; k++) { flag_ctx_hm = 0; - move16(); - move16(); - move16(); prm = param + (k*NPRM_DIV); - j = 0; - move16(); - nbits_tcx = total_nbbits = sub(st->nb_bits_tot_fx, nbits_start); + nbits_tcx = total_nbbits = st->nb_bits_tot - nbits_start; - test(); - IF(st->enablePlcWaveadjust && k) + if(st->enablePlcWaveadjust && k) { - push_next_indice_fx(st, st->Tonal_SideInfo, 1); + push_next_indice(st, st->Tonal_SideInfo, 1); } - /* TCX Gain = 7 bits */ - push_next_indice_fx(st, prm[j++], 7); + push_next_indice(st, prm[j++], 7); /* TCX Noise Filling = NBITS_NOISE_FILL_LEVEL bits */ - push_next_indice_fx(st, prm[j++], NBITS_NOISE_FILL_LEVEL); + push_next_indice(st, prm[j++], NBITS_NOISE_FILL_LEVEL); /* LTP data */ - test(); - test(); - IF ( (k == 0) && (st->tcxltp!=0 || L_sub(st->sr_core, 25600) > 0 ) )/* PLC pitch info for HB */ + if ( (k == 0) && (st->tcxltp || (st->sr_core > 25600) ) ) /* PLC pitch info for HB */ { - IF ( prm[j] ) + if ( prm[j] ) { - push_next_indice_fx(st, 1 , 1); - push_next_indice_fx(st, prm[j+1], 9); - push_next_indice_fx(st, prm[j+2], 2); + push_next_indice(st, 1 , 1); + push_next_indice(st, prm[j+1], 9); + push_next_indice(st, prm[j+2], 2); } - ELSE + else { - push_next_indice_fx(st, 0 , 1); + push_next_indice(st, 0 , 1); } } - j = add(j, 3); + j += 3; /* TCX spectral data */ - lg = shr(L_frame, 1); - lgFB = shr(st->tcx_cfg.tcx_coded_lines, 1); + lg = L_frame >> 1; + lgFB = st->tcx_cfg.tcx_coded_lines >> 1; - IF ( s_and(k==0, last_core==ACELP_CORE) ) + if ( k==0 && last_core == ACELP_CORE ) { /* ACE->TCX transition */ - lg = add(lg, st->tcx_cfg.tcx_offset); - lgFB = add(lgFB, shr(lgFB, 1)); + lg += st->tcx_cfg.tcx_offset; + lgFB += lgFB >> 1; + if(st->tcx_cfg.lfacNext<0) { - lg = sub(lg,st->tcx_cfg.lfacNext); + lg -= st->tcx_cfg.lfacNext; } } /* TNS data */ - move16(); - move16(); nTnsParams = 0; nTnsBits = 0; - IF (st->tcx_cfg.fIsTNSAllowed) + if( st->tcx_cfg.fIsTNSAllowed ) { - SetTnsConfig(&st->tcx_cfg, 0, (last_core == ACELP_CORE) && (k == 0)); - WriteTnsData(st->tcx_cfg.pCurrentTnsConfig, prm+j, &nTnsParams, st, &nTnsBits); - j = add(j, nTnsParams); + j += nTnsParams; } - hm_size = shl(mult(st->tcx_cfg.bandwidth, lgFB), 1); + hm_size = (int)(2.0f*st->tcx_cfg.bandwidth*(float)lgFB); /*Context HM flag*/ - test(); - test(); - IF ( st->tcx_cfg.ctx_hm && !(last_core == ACELP_CORE && k == 0) ) + if ( st->tcx_cfg.ctx_hm && !(last_core == ACELP_CORE && k == 0) ) { - push_next_indice_fx(st, prm[j], 1); + push_next_indice(st, prm[j], 1); - IF (prm[j]) + if (prm[j]) { - EncodeIndex(sub(hm_size,256) >= 0, prm[j+1], st); - flag_ctx_hm = 1; - move16(); + EncodeIndex(hm_size >= 256, prm[j+1], st); + flag_ctx_hm=1; } } - j = add(j, NPRM_CTX_HM); + j += NPRM_CTX_HM; - total_nbbits = sub(st->nb_bits_tot_fx, nbits_start); - - nbits_tcx = sub(shr(sub(add(sub(sub(sub(st->bits_frame_core, nbits_header), nbits_lpc), nbits_igf), 1), k), 1), sub(total_nbbits, nbits_tcx)); - - phm_cfg = NULL; - move16(); - if (flag_ctx_hm) - { - phm_cfg = &hm_cfg[k]; - move16(); - } - ACcontextMapping_encode2_no_mem_s17_LC(st, prm+j, - lgFB, - prm[j-1], /* lastnz */ - nbits_tcx, NPRM_RESQ * st->tcx_cfg.resq, phm_cfg); + total_nbbits = st->nb_bits_tot - nbits_start; + nbits_tcx = (( st->bits_frame_core - nbits_header - nbits_lpc - nbits_igf + 1 - k) >> 1) - (total_nbbits - nbits_tcx); + ACcontextMapping_encode2_no_mem_s17_LC( st, prm+j, lgFB, prm[j-1], /* lastnz */nbits_tcx, + NPRM_RESQ * st->tcx_cfg.resq, flag_ctx_hm?&hm_cfg[k]:NULL ); } /* k, window index */ } @@ -899,16 +762,9 @@ void enc_prm( * END *--------------------------------------------------------------------------------*/ - - total_nbbits = sub(st->nb_bits_tot_fx, nbits_start); + total_nbbits = st->nb_bits_tot - nbits_start; - /* Check if total encoded bits does not exceed CBR target bits (->this must never happen) */ - if (st->bits_frame_core&&(total_nbbits>st->bits_frame_core)) - { - fprintf(stderr,"AllocatedBits: %d Used bits: %d \n", st->bits_frame_core,total_nbbits); - assert(!"Core totalbits > CBR target bitrate"); - } return; } diff --git a/src/libs/libevs/lib_enc/enc_tran.cpp b/src/libs/libevs/lib_enc/enc_tran.cpp new file mode 100644 index 00000000..f6d52424 --- /dev/null +++ b/src/libs/libevs/lib_enc/enc_tran.cpp @@ -0,0 +1,314 @@ +/*==================================================================================== + EVS Codec 3GPP TS26.443 Nov 13, 2018. Version 12.11.0 / 13.7.0 / 14.3.0 / 15.1.0 + ====================================================================================*/ + +#include "options.h" +#include "prot.h" +#include "rom_com.h" + +/*-------------------------------------------------------------------* + * encod_tran() + * + * Encode transition (TC) frames + *-------------------------------------------------------------------*/ + +short encod_tran( + Encoder_State *st, /* i/o: state structure */ + LPD_state *mem, /* i/o: encoder memories */ + const short L_frame, /* i : length of the frame */ + const float speech[], /* i : input speech */ + const float Aw[], /* i : weighted A(z) unquantized for subframes */ + const float Aq[], /* i : LP coefficients */ + const short coder_type, /* i : coding type */ + const float Es_pred, /* i : predicted scaled innov. energy */ + const short T_op[], /* i : open loop pitch */ + const float voicing[], /* i : voicing */ + const float *res, /* i : residual signal */ + float *syn, /* i/o: core synthesis */ + float *exc, /* i/o: current non-enhanced excitation */ + float *exc2, /* i/o: current enhanced excitation */ + float *pitch_buf, /* i/o: floating pitch values for each subframe */ + float *voice_factors, /* o : voicing factors */ + float *bwe_exc, /* i/o: excitation for SWB TBE */ + const short attack_flag, /* i : Flag to indicate when an audio attack is dealt with TM */ + short *unbits, /* i/o: number of unused bits */ + const short sharpFlag /* i : formant sharpening flag */ +) +{ + float xn[L_SUBFR]; /* Target vector for pitch search */ + float xn2[L_SUBFR]; /* Target vector for codebook search */ + float cn[L_SUBFR]; /* Target vector in residual domain */ + float h1[L_SUBFR+(M+1)]; /* Impulse response vector */ + float code[L_SUBFR]; /* Fixed codebook excitation */ + float y1[L_SUBFR]; /* Filtered adaptive excitation */ + float y2[L_SUBFR]; /* Filtered algebraic excitation */ + float gain_pit; /* Pitch gain */ + float voice_fac; /* Voicing factor */ + float gain_code; /* Gain of code */ + float gain_inov; /* inovation gain */ + short i, i_subfr, tc_subfr; /* tmp variables */ + short position, T0_min, T0_max; /* pitch and TC variables */ + short T0, T0_frac; /* close loop integer pitch and fractional part */ + float *pt_pitch; /* pointer to floating pitch buffer */ + float g_corr[6]; /* ACELP correlation values and gain pitch */ + short clip_gain; /* LSF clip gain */ + const float *p_Aw, *p_Aq; /* pointer to LP filter coefficient vector */ + float gain_preQ; /* Gain of prequantizer excitation */ + float code_preQ[L_SUBFR]; /* Prequantizer excitation */ + short Jopt_flag; /* joint optimization flag */ + short unbits_PI; /* saved bits for EVS_PI */ + float norm_gain_code; + + /*------------------------------------------------------------------* + * Initializations + *------------------------------------------------------------------*/ + + gain_pit = 0; + gain_code = 0; + gain_preQ = 0; + unbits_PI = 0; + + if( L_frame == L_FRAME ) + { + T0_max = PIT_MAX; + T0_min = PIT_MIN; + } + else /* L_frame == L_FRAME16k */ + { + T0_max = PIT16k_MAX; + T0_min = PIT16k_MIN; + } + + Jopt_flag = 0; + tc_subfr = -1; + if( attack_flag ) + { + tc_subfr = 3*L_SUBFR; + } + + p_Aw = Aw; + p_Aq = Aq; + pt_pitch = pitch_buf; + gain_preQ = 0; + set_f( code_preQ, 0, L_SUBFR ); + + /*----------------------------------------------------------------* + * ACELP subframe loop + *----------------------------------------------------------------*/ + + for ( i_subfr=0; i_subfrmem_syn, i_subfr, &mem->mem_w0, p_Aq, res, L_SUBFR, p_Aw, st->preemph_fac, xn, cn, h1 ); + + /*-----------------------------------------------------------------* + * TC: subframe determination & + * adaptive/glottal part of excitation construction + *-----------------------------------------------------------------*/ + + transition_enc( st, st->core_brate, L_frame, coder_type, i_subfr, &tc_subfr, &Jopt_flag, &position, voicing, T_op, &T0, + &T0_frac, &T0_min, &T0_max, exc, y1, res, h1, xn, xn2, st->clip_var, &gain_pit, g_corr, &clip_gain, &pt_pitch, bwe_exc ); + + /*-----------------------------------------------------------------* + * Transform domain contribution encoding - active frames + *-----------------------------------------------------------------*/ + + if( st->core_brate > ACELP_24k40 ) + { + transf_cdbk_enc( st, st->core_brate, st->extl, coder_type, 0, i_subfr, tc_subfr, cn, exc, + p_Aq, p_Aw, h1, xn, xn2, y1, y2, Es_pred, &gain_pit, gain_code, g_corr, clip_gain, + &(st->mem_deemp_preQ), &(st->mem_preemp_preQ), &gain_preQ, code_preQ, unbits ); + } + + /*-----------------------------------------------------------------* + * ACELP codebook search + pitch sharpening + *-----------------------------------------------------------------*/ + + inov_encode( st, st->core_brate, 0, L_frame, st->last_L_frame, coder_type, st->bwidth, sharpFlag, i_subfr, tc_subfr, p_Aq, + gain_pit, cn, exc, h1, mem->tilt_code, *pt_pitch, xn2, code, y2, &unbits_PI ); + + if( (st->L_frame == L_FRAME16k) && (tc_subfr == 0) && (i_subfr == L_SUBFR) && (T0 == 2*L_SUBFR) ) + { + Jopt_flag = 1; + } + + /*-----------------------------------------------------------------* + * Quantize the gains + * Test quantized gain of pitch for pitch clipping algorithm + * Update tilt of code: 0.0 (unvoiced) to 0.5 (voiced) + *-----------------------------------------------------------------*/ + + if( Jopt_flag == 0 ) + { + /* SQ gain_code */ + gain_enc_tc( st, st->core_brate, L_frame, i_subfr, tc_subfr, xn, y2, code, Es_pred, + &gain_pit, &gain_code, &gain_inov, &norm_gain_code ); + } + else + { + if( st->core_brate > ACELP_32k ) + { + /* SQ gain_pit and gain_code */ + gain_enc_SQ( st, st->core_brate, coder_type, i_subfr, tc_subfr, xn, y1, y2, code, Es_pred, + &gain_pit, &gain_code, &gain_inov, &norm_gain_code, g_corr, clip_gain ); + } + else + { + /* VQ gain_pit and gain_code */ + gain_enc_mless( st, st->core_brate, L_frame, coder_type, i_subfr, tc_subfr, xn, y1, y2, code, Es_pred, + &gain_pit, &gain_code, &gain_inov, &norm_gain_code, g_corr, clip_gain ); + } + } + + /*-----------------------------------------------------------------* + * update LP-filtered gains for the case of frame erasures + *-----------------------------------------------------------------*/ + + gp_clip_test_gain_pit( st->core_brate, gain_pit, st->clip_var); + mem->tilt_code = est_tilt( exc+i_subfr, gain_pit, code, gain_code, &voice_fac, L_SUBFR, 0 ); + + /*-----------------------------------------------------------------* + * Update memory of the weighting filter + *-----------------------------------------------------------------*/ + + mem->mem_w0 = xn[L_SUBFR-1] - (gain_pit*y1[L_SUBFR-1]) - (gain_code*y2[L_SUBFR-1]); + + /*-----------------------------------------------------------------* + * Construct adaptive part of the excitation + * Save the non-enhanced excitation for FEC_exc + *-----------------------------------------------------------------*/ + + for( i = 0; i < L_SUBFR; i++ ) + { + exc2[i+i_subfr] = gain_pit * exc[i+i_subfr]; + exc[i+i_subfr] = exc2[i+i_subfr] + gain_code * code[i]; + } + + /*-----------------------------------------------------------------* + * Add the ACELP pre-quantizer contribution + *-----------------------------------------------------------------*/ + + if( st->core_brate > ACELP_24k40 ) + { + for( i = 0; i < L_SUBFR; i++ ) + { + exc2[i+i_subfr] += gain_preQ * code_preQ[i]; + exc[i+i_subfr] += gain_preQ * code_preQ[i]; + } + } + + /*-----------------------------------------------------------------* + * Prepare TBE excitation + *-----------------------------------------------------------------*/ + + prep_tbe_exc( L_frame, i_subfr, gain_pit, gain_code, code, voice_fac, &voice_factors[i_subfr/L_SUBFR], + bwe_exc, gain_preQ, code_preQ, T0, coder_type, st->core_brate ); + + + /*-----------------------------------------------------------------* + * Synthesize speech to update mem_syn[]. + * Update A(z) filters + *-----------------------------------------------------------------*/ + + syn_filt( p_Aq, M, &exc[i_subfr], &syn[i_subfr], L_SUBFR, mem->mem_syn, 1 ); + + p_Aw += (M+1); + p_Aq += (M+1); + pt_pitch++; + } + + /* write reserved bits */ + while( unbits_PI > 0 ) + { + i = min( unbits_PI, 16 ); + push_indice( st, IND_UNUSED, 0, i ); + unbits_PI -= i; + } + + /* write TC configuration */ + if( L_frame == L_FRAME ) + { + if( tc_subfr == TC_0_0 ) + { + push_indice( st, IND_TC_SUBFR, 1, 1 ); + } + else if( tc_subfr == TC_0_64 ) + { + push_indice( st, IND_TC_SUBFR, 0, 1 ); + push_indice( st, IND_TC_SUBFR, 1, 1 ); + push_indice( st, IND_TC_SUBFR, 0, 1 ); + push_indice( st, IND_TC_SUBFR, 1, 1 ); + } + else if( tc_subfr == TC_0_128 ) + { + push_indice( st, IND_TC_SUBFR, 0, 1 ); + push_indice( st, IND_TC_SUBFR, 1, 1 ); + push_indice( st, IND_TC_SUBFR, 0, 1 ); + push_indice( st, IND_TC_SUBFR, 0, 1 ); + } + else if( tc_subfr == TC_0_192 ) + { + push_indice( st, IND_TC_SUBFR, 0, 1 ); + push_indice( st, IND_TC_SUBFR, 1, 1 ); + push_indice( st, IND_TC_SUBFR, 1, 1 ); + } + else if( tc_subfr == L_SUBFR ) + { + push_indice( st, IND_TC_SUBFR, 0, 1 ); + push_indice( st, IND_TC_SUBFR, 0, 1 ); + push_indice( st, IND_TC_SUBFR, 1, 1 ); + } + else if( tc_subfr == 2*L_SUBFR ) + { + push_indice( st, IND_TC_SUBFR, 0, 1 ); + push_indice( st, IND_TC_SUBFR, 0, 1 ); + push_indice( st, IND_TC_SUBFR, 0, 1 ); + push_indice( st, IND_TC_SUBFR, 1, 1 ); + } + else if( tc_subfr == 3*L_SUBFR ) + { + push_indice( st, IND_TC_SUBFR, 0, 1 ); + push_indice( st, IND_TC_SUBFR, 0, 1 ); + push_indice( st, IND_TC_SUBFR, 0, 1 ); + push_indice( st, IND_TC_SUBFR, 0, 1 ); + } + } + else /* L_frame == L_FRAME16k */ + { + if( tc_subfr == 0 ) + { + push_indice( st, IND_TC_SUBFR, 0, 2 ); + } + else if( tc_subfr == L_SUBFR ) + { + push_indice( st, IND_TC_SUBFR, 1, 2 ); + } + else if( tc_subfr == 2*L_SUBFR ) + { + push_indice( st, IND_TC_SUBFR, 2, 2 ); + } + else if( tc_subfr == 3*L_SUBFR ) + { + push_indice( st, IND_TC_SUBFR, 3, 2 ); + push_indice( st, IND_TC_SUBFR, 0, 1 ); + } + else if( tc_subfr == 4*L_SUBFR ) + { + push_indice( st, IND_TC_SUBFR, 3, 2 ); + push_indice( st, IND_TC_SUBFR, 1, 1 ); + } + } + + /* SC-VBR */ + st->prev_ppp_gain_pit = gain_pit; + st->prev_tilt_code = mem->tilt_code; + + return tc_subfr; +} diff --git a/src/libs/libevs/lib_enc/enc_tran_fx.cpp b/src/libs/libevs/lib_enc/enc_tran_fx.cpp deleted file mode 100755 index 2651660d..00000000 --- a/src/libs/libevs/lib_enc/enc_tran_fx.cpp +++ /dev/null @@ -1,416 +0,0 @@ -/*==================================================================================== - EVS Codec 3GPP TS26.442 Apr 03, 2018. Version 12.11.0 / 13.6.0 / 14.2.0 - ====================================================================================*/ - -#include "options.h" /* Compilation switches */ -#include "prot_fx.h" /* Function prototypes */ -#include "rom_com_fx.h" /* Static table prototypes */ - - -#include "stl.h" - -/*=================================================================================*/ -/* FUNCTION : void encod_tran_fx () */ -/*---------------------------------------------------------------------------------*/ -/* PURPOSE : */ -/*---------------------------------------------------------------------------------*/ -/* INPUT ARGUMENTS : */ -/* (Word16) L_frame_fx : length of the frame Q0 */ -/* (Word16[]) speech_fx : input speech Q0 */ -/* (Word16[]) Aq_fx : 12k8 Lp coefficient Q12 */ -/* (Word16[]) A_fx : unquantized A(z) filter with bandwidth expansion Q12 */ -/* (Word16) coder_type : coding type Q0 */ -/* (Word16) Es_pred_fx : predicted scaled innov. energy Q8 */ -/* (Word16[]) T_op_fx : open loop pitch Q0 */ -/* (Word16[]) voicing_fx : voicing Q15 */ -/* (Word16*) res_fx : residual signal Q_new*/ -/* (Word16) gsc_attack_flag : Flag to indicate when an audio attack is deal with TM*/ -/* (Word16) shift : shift factor */ -/* (Word16[]) Q_new : input scaling */ -/*---------------------------------------------------------------------------------*/ -/* OUTPUT ARGUMENTS : */ -/* (Word16*) voice_factors : voicing factors Q15 */ -/*---------------------------------------------------------------------------------*/ -/* INPUT/OUTPUT ARGUMENTS : */ -/* Encoder_State_fx *st_fx :Encoder state structure */ -/* (Word16*) syn_fx :core synthesis Qnew */ -/* (Word16*) exc_fx :current non-enhanced excitation Q0 */ -/* (Word16*) exc2_fx :current enhanced excitation Q0 */ -/* (Word16*) pitch_buf_fx :floating pitch values for each subframe Q6 */ -/* (Word16*) bwe_exc_fx :excitation for SWB TBE Q0 */ -/*---------------------------------------------------------------------------------*/ -/* RETURN ARGUMENTS : */ -/* _ None */ -/*---------------------------------------------------------------------------------*/ - -Word16 encod_tran_fx( - Encoder_State_fx *st_fx, /* i/o: state structure */ - LPD_state *mem, /* i/o: acelp memories */ - const Word16 L_frame_fx, /* i : length of the frame */ - const Word16 speech_fx[], /* i : input speech */ - const Word16 Aw_fx[], /* i : weighted A(z) unquantized for subframes */ - const Word16 Aq_fx[], /* i : 12k8 Lp coefficient */ - const Word16 coder_type, /* i : coding type */ - const Word16 Es_pred_fx, /* i : predicted scaled innov. energy */ - const Word16 T_op_fx[], /* i : open loop pitch */ - const Word16 voicing_fx[], /* i : voicing */ - const Word16 *res_fx, /* i : residual signal */ - Word16 *syn_fx, /* i/o: core synthesis */ - Word16 *exc_fx, /* i/o: current non-enhanced excitation */ - Word16 *exc2_fx, /* i/o: current enhanced excitation */ - Word16 *pitch_buf_fx, /* i/o: floating pitch values for each subframe */ - Word16 *voice_factors, /* o : voicing factors */ - Word16 *bwe_exc_fx, /* i/o: excitation for SWB TBE */ - const Word16 gsc_attack_flag, /* i : Flag to indicate when an audio attack is deal with TM */ - Word16 *unbits, /* i/o: number of unused bits */ - Word16 sharpFlag, /* o : formant sharpening flag */ - const Word16 shift, /* i : Scaling to get 12 bits */ - const Word16 Q_new /* i : Input scaling */ -) -{ - Word16 xn[L_SUBFR]; /* Target vector for pitch search */ - Word16 xn2[L_SUBFR]; /* Target vector for codebook search */ - Word16 cn[L_SUBFR]; /* Target vector in residual domain */ - Word16 h1[L_SUBFR+(M+1)]; /* Impulse response vector */ - Word16 h2_fx[L_SUBFR+(M+1)]; /* Impulse response vector */ - Word16 code[L_SUBFR]; /* Fixed codebook excitation */ - Word16 y1[L_SUBFR]; /* Filtered adaptive excitation */ - Word16 y2[L_SUBFR]; /* Filtered algebraic excitation */ - Word16 gain_pit = 0,Gain_pitX2,gcode16; /* Pitch gain */ - Word16 voice_fac; /* Voicing factor */ - Word32 gain_code = 0; /* Gain of code */ - Word32 Lgcode; - Word16 gain_inov=0; /* inovation gain */ - Word16 i, i_subfr, tc_subfr,tmp1_fx,tmp_fx; /* tmp variables */ - Word16 position, T0_min, T0_max; /* pitch and TC variables */ - Word16 T0, T0_frac; /* close loop integer pitch and fractional part */ - Word16 *pt_pitch; /* pointer to floating pitch buffer */ - Word16 g_corr[10]; /* ACELP correlation values and gain pitch */ - Word16 clip_gain; /* LSF clip gain */ - const Word16 *p_Aw, *p_Aq; /* pointer to LP filter coefficient vector */ - Word16 gain_preQ = 0; /* Gain of prequantizer excitation */ - Word16 code_preQ[L_SUBFR]; /* Prequantizer excitation */ - Word16 Jopt_flag; /* joint optimization flag */ - Word16 unbits_PI = 0; /* saved bits for PI */ - Word32 norm_gain_code=0; - - Word16 shift_wsp; - Word32 L_tmp; - - /*------------------------------------------------------------------* - * Initializations - *------------------------------------------------------------------*/ - gain_pit = 0; - move16(); - gain_code = L_deposit_l(0); - gain_preQ = 0; - move16(); - unbits_PI = 0; - move16(); - IF( sub(L_frame_fx,L_FRAME) == 0 ) - { - T0_max = PIT_MAX; - move16(); - T0_min = PIT_MIN; - move16(); - } - ELSE /* L_frame == L_FRAME16k */ - { - T0_max = PIT16k_MAX; - move16(); - T0_min = PIT16k_MIN; - move16(); - } - - /**unbits = 0;move16();*/ - Jopt_flag = 0; - move16(); - tc_subfr = -1; - move16(); - if( gsc_attack_flag ) - { - tc_subfr = 3*L_SUBFR; - move16(); - } - - p_Aw = Aw_fx; - p_Aq = Aq_fx; - pt_pitch = pitch_buf_fx; - gain_preQ = 0; - move16(); - set16_fx( code_preQ, 0, L_SUBFR ); - shift_wsp = add(Q_new,shift); - - /*----------------------------------------------------------------* - * ACELP subframe loop - *----------------------------------------------------------------*/ - - FOR ( i_subfr=0; i_subfrmem_syn, i_subfr, &mem->mem_w0, p_Aq, - res_fx, L_SUBFR, p_Aw, st_fx->preemph_fac, xn, cn, h1 ); - - Copy_Scale_sig(h1, h2_fx, L_SUBFR, -2); - Scale_sig(h1, L_SUBFR, add(1, shift)); /* set h1[] in Q14 with scaling for convolution */ - - /* scaling of xn[] to limit dynamic at 12 bits */ - Scale_sig(xn, L_SUBFR, shift); - - /*-----------------------------------------------------------------* - * TC: subframe determination & - * adaptive/glottal part of excitation construction - *-----------------------------------------------------------------*/ - - transition_enc_fx( st_fx, st_fx->core_brate_fx, L_frame_fx, coder_type, i_subfr, &tc_subfr, &Jopt_flag, &position, voicing_fx, T_op_fx, &T0, - &T0_frac, &T0_min, &T0_max, exc_fx, y1, res_fx, h1, xn, xn2, st_fx->clip_var_fx, &gain_pit, g_corr, &clip_gain, &pt_pitch, bwe_exc_fx ,Q_new,shift); - - /*-----------------------------------------------------------------* - * Transform domain contribution encoding - active frames - *-----------------------------------------------------------------*/ - - IF( L_sub(st_fx->core_brate_fx,ACELP_24k40) > 0 ) - { - transf_cdbk_enc_fx( st_fx, st_fx->core_brate_fx, st_fx->extl_fx, coder_type, 0, i_subfr, tc_subfr, cn, exc_fx, - p_Aq, Aw_fx, h1, xn, xn2, y1, y2, Es_pred_fx, &gain_pit, gain_code, g_corr, clip_gain, - &(st_fx->mem_deemp_preQ_fx), &(st_fx->mem_preemp_preQ_fx), &gain_preQ, code_preQ, unbits, Q_new, shift); - } - - /*-----------------------------------------------------------------* - * ACELP codebook search + pitch sharpening - *-----------------------------------------------------------------*/ - - inov_encode_fx( st_fx, st_fx->core_brate_fx, 0, L_frame_fx, st_fx->last_L_frame_fx, coder_type, st_fx->bwidth_fx, sharpFlag, - i_subfr, tc_subfr, p_Aq, gain_pit, cn, exc_fx, h2_fx, mem->tilt_code, *pt_pitch, xn2, code, y2, &unbits_PI, shift ); - - test(); - test(); - test(); - if( (sub(st_fx->L_frame_fx,L_FRAME16k) == 0) && (tc_subfr == 0) && (sub(i_subfr,L_SUBFR) == 0) && (sub(T0,2*L_SUBFR) == 0) ) - { - Jopt_flag = 1; - move16(); - } - /*-----------------------------------------------------------------* - * Quantize the gains - * Test quantized gain of pitch for pitch clipping algorithm - * Update tilt of code: 0.0 (unvoiced) to 0.5 (voiced) - *-----------------------------------------------------------------*/ - IF( Jopt_flag == 0 ) - { - /* SQ gain_code */ - gain_enc_tc_fx( st_fx, st_fx->core_brate_fx, L_frame_fx, i_subfr, tc_subfr, xn, y2, code, Es_pred_fx, - &gain_pit, &gain_code, &gain_inov, &norm_gain_code, shift_wsp ); - } - ELSE - { - IF ( L_sub(st_fx->core_brate_fx,ACELP_32k) > 0 ) - { - /* SQ gain_pit and gain_code */ - gain_enc_SQ_fx( st_fx, st_fx->core_brate_fx, coder_type, i_subfr, tc_subfr, xn, y1, y2, code, Es_pred_fx, - &gain_pit, &gain_code, &gain_inov, &norm_gain_code, g_corr, clip_gain, shift_wsp ); - } - ELSE - { - /* VQ gain_pit and gain_code */ - gain_enc_mless_fx( st_fx, st_fx->core_brate_fx, L_frame_fx, coder_type, i_subfr, tc_subfr, xn, y1, shift_wsp, y2, code, Es_pred_fx, - &gain_pit, &gain_code, &gain_inov, &norm_gain_code, g_corr, clip_gain ); - } - } - gp_clip_test_gain_pit_fx( st_fx->core_brate_fx, gain_pit, st_fx->clip_var_fx ); - - Lgcode = L_shl(gain_code, Q_new); /* scaled gain_code with Qnew -> Q16*/ - gcode16 = round_fx(Lgcode); - mem->tilt_code = Est_tilt2(&exc_fx[i_subfr], gain_pit, code, Lgcode, &voice_fac, shift); - /*-----------------------------------------------------------------* - * Update memory of the weighting filter - *-----------------------------------------------------------------*/ - - /*st->mem_w0 = xn[L_SUBFR-1] - (gain_pit*y1[L_SUBFR-1]) - (gain_code*y2[L_SUBFR-1]);*/ - L_tmp = L_mult(gcode16, y2[L_SUBFR - 1]); - L_tmp = L_shl(L_tmp, add(5, shift)); - L_tmp = L_negate(L_tmp); - L_tmp = L_mac(L_tmp, xn[L_SUBFR - 1], 16384); - L_tmp = L_msu(L_tmp, y1[L_SUBFR - 1], gain_pit); - L_tmp = L_shl(L_tmp, sub(1, shift)); - mem->mem_w0 = round_fx(L_tmp); /*Q_new-1*/ - - /*-----------------------------------------------------------------* - * Construct adaptive part of the excitation - * Save the non-enhanced excitation for FEC_exc - *-----------------------------------------------------------------*/ - - /* Here, all these conditions have one purpose: to use */ - /* the most efficient loop (the one with the least ops) */ - /* This is done by upscaling gain_pit_fx and/or gain_code16 */ - /* when they don't use all 16 bits of precision */ - - /* exc Q_exc, gpit Q14, code Q12, gcode Q0 */ - IF (norm_s(gain_pit) == 0) - { - FOR (i = 0; i < L_SUBFR; i++) - { - exc2_fx[i+i_subfr] = round_fx(L_shl(L_mult(gain_pit,exc_fx[i+i_subfr]),1)); - } - } - ELSE - { - Gain_pitX2 = shl(gain_pit, 1); - FOR (i = 0; i < L_SUBFR; i++) - { - exc2_fx[i+i_subfr] = mult_r(Gain_pitX2,exc_fx[i+i_subfr]); - } - } - - /*-----------------------------------------------------------------* - * Construct adaptive part of the excitation - * Save the non-enhanced excitation for FEC_exc - *-----------------------------------------------------------------*/ - FOR (i = 0; i < L_SUBFR; i++) - { - /* code in Q9, gain_pit in Q14 */ - L_tmp = L_mult(gcode16, code[i]); - L_tmp = L_shl(L_tmp, 5); - L_tmp = L_mac(L_tmp, exc_fx[i + i_subfr], gain_pit); - L_tmp = L_shl(L_tmp, 1); /* saturation can occur here */ - exc_fx[i + i_subfr] = round_fx(L_tmp); - } - - /*-----------------------------------------------------------------* - * Add the ACELP pre-quantizer contribution - *-----------------------------------------------------------------*/ - - IF( L_sub(st_fx->core_brate_fx,ACELP_24k40) > 0 ) - { - tmp1_fx = add(16-(2+Q_AVQ_OUT_DEC+1),Q_new); - FOR( i = 0; i < L_SUBFR; i++ ) - { - L_tmp = L_mult(gain_preQ, code_preQ[i]); /* Q2 + Q10 -> Q13*/ - L_tmp = L_shl(L_tmp,tmp1_fx); /* Q16 + Q_exc */ - tmp_fx = round_fx(L_tmp); - - exc2_fx[i+i_subfr] = add(exc2_fx[i+i_subfr],tmp_fx); - move16(); - exc_fx[i+i_subfr] = add(exc_fx[i+i_subfr],tmp_fx); - move16(); - } - } - - /*-----------------------------------------------------------------* - * Prepare TBE excitation - *-----------------------------------------------------------------*/ - - prep_tbe_exc_fx( L_frame_fx, i_subfr, gain_pit, gain_code, code, voice_fac, &voice_factors[i_subfr/L_SUBFR], - bwe_exc_fx, gain_preQ, code_preQ, Q_new, T0, T0_frac, coder_type, st_fx->core_brate_fx ); - - /*-----------------------------------------------------------------* - * Synthesize speech to update mem_syn[]. - * Update A(z) filters - *-----------------------------------------------------------------*/ - - Syn_filt_s( 1, p_Aq, M, &exc_fx[i_subfr], &syn_fx[i_subfr], L_SUBFR, mem->mem_syn, 1 ); - - p_Aw += (M+1); - p_Aq += (M+1); - pt_pitch++; - } - - /* write reserved bits */ - WHILE( unbits_PI > 0 ) - { - i = s_min(unbits_PI, 16); - push_indice_fx( st_fx, IND_UNUSED, 0, i ); - unbits_PI -= i; - } - - /* write TC configuration */ - IF( sub(L_frame_fx,L_FRAME) == 0 ) - { - IF( sub(tc_subfr,TC_0_0) == 0 ) - { - push_indice_fx( st_fx, IND_TC_SUBFR, 1, 1 ); - } - ELSE IF( sub(tc_subfr,TC_0_64) == 0 ) - { - push_indice_fx( st_fx, IND_TC_SUBFR, 0, 1 ); - push_indice_fx( st_fx, IND_TC_SUBFR, 1, 1 ); - push_indice_fx( st_fx, IND_TC_SUBFR, 0, 1 ); - push_indice_fx( st_fx, IND_TC_SUBFR, 1, 1 ); - } - ELSE IF( sub(tc_subfr,TC_0_128) == 0 ) - { - push_indice_fx( st_fx, IND_TC_SUBFR, 0, 1 ); - push_indice_fx( st_fx, IND_TC_SUBFR, 1, 1 ); - push_indice_fx( st_fx, IND_TC_SUBFR, 0, 1 ); - push_indice_fx( st_fx, IND_TC_SUBFR, 0, 1 ); - } - ELSE IF( sub(tc_subfr,TC_0_192) == 0 ) - { - push_indice_fx( st_fx, IND_TC_SUBFR, 0, 1 ); - push_indice_fx( st_fx, IND_TC_SUBFR, 1, 1 ); - push_indice_fx( st_fx, IND_TC_SUBFR, 1, 1 ); - } - ELSE IF( sub(tc_subfr,L_SUBFR) == 0 ) - { - push_indice_fx( st_fx, IND_TC_SUBFR, 0, 1 ); - push_indice_fx( st_fx, IND_TC_SUBFR, 0, 1 ); - push_indice_fx( st_fx, IND_TC_SUBFR, 1, 1 ); - } - ELSE IF( sub(tc_subfr,2*L_SUBFR) == 0 ) - { - push_indice_fx( st_fx, IND_TC_SUBFR, 0, 1 ); - push_indice_fx( st_fx, IND_TC_SUBFR, 0, 1 ); - push_indice_fx( st_fx, IND_TC_SUBFR, 0, 1 ); - push_indice_fx( st_fx, IND_TC_SUBFR, 1, 1 ); - } - ELSE IF( sub(tc_subfr,3*L_SUBFR) == 0 ) - { - push_indice_fx( st_fx, IND_TC_SUBFR, 0, 1 ); - push_indice_fx( st_fx, IND_TC_SUBFR, 0, 1 ); - push_indice_fx( st_fx, IND_TC_SUBFR, 0, 1 ); - push_indice_fx( st_fx, IND_TC_SUBFR, 0, 1 ); - } - - } - ELSE /* L_frame == L_FRAME16k */ - { - IF( tc_subfr == 0 ) - { - push_indice_fx( st_fx, IND_TC_SUBFR, 0, 2 ); - } - ELSE IF( sub(tc_subfr,L_SUBFR) == 0 ) - { - push_indice_fx( st_fx, IND_TC_SUBFR, 1, 2 ); - } - ELSE IF( sub(tc_subfr,2*L_SUBFR) == 0 ) - { - push_indice_fx( st_fx, IND_TC_SUBFR, 2, 2 ); - } - ELSE IF( sub(tc_subfr,3*L_SUBFR) == 0 ) - { - push_indice_fx( st_fx, IND_TC_SUBFR, 3, 2 ); - push_indice_fx( st_fx, IND_TC_SUBFR, 0, 1 ); - } - ELSE IF( sub(tc_subfr,4*L_SUBFR) == 0 ) - { - push_indice_fx( st_fx, IND_TC_SUBFR, 3, 2 ); - push_indice_fx( st_fx, IND_TC_SUBFR, 1, 1 ); - } - - } - - /* SC-VBR */ - st_fx->prev_ppp_gain_pit_fx = gain_pit; - move16(); - st_fx->prev_tilt_code_fx = mem->tilt_code; - move16(); - - return tc_subfr; -} diff --git a/src/libs/libevs/lib_enc/enc_uv.cpp b/src/libs/libevs/lib_enc/enc_uv.cpp new file mode 100644 index 00000000..17c83209 --- /dev/null +++ b/src/libs/libevs/lib_enc/enc_uv.cpp @@ -0,0 +1,108 @@ +/*==================================================================================== + EVS Codec 3GPP TS26.443 Nov 13, 2018. Version 12.11.0 / 13.7.0 / 14.3.0 / 15.1.0 + ====================================================================================*/ + +#include "options.h" +#include "cnst.h" +#include "prot.h" + +/*-------------------------------------------------------------------* + * encod_unvoiced() + * + * Encode unvoiced (UC) frames + *-------------------------------------------------------------------*/ + +void encod_unvoiced( + Encoder_State *st, /* i/o: state structure */ + LPD_state *mem, /* i/o: encoder memories */ + const float *speech, /* i : input speech */ + const float Aw[], /* i : weighted A(z) unquantized for subframes */ + const float *Aq, /* i : LP coefficients */ + const short vad_flag, + const float *res, /* i : residual signal */ + float *syn, /* o : core synthesis */ + float *tmp_noise, /* o : long-term noise energy */ + float *exc, /* i/o: current non-enhanced excitation */ + float *pitch_buf, /* o : floating pitch values for each subframe */ + float *voice_factors, /* o : voicing factors */ + float *bwe_exc /* i/o: excitation for SWB TBE */ +) +{ + float xn[L_SUBFR]; /* Target vector for pitch search */ + float h1[L_SUBFR]; /* Impulse response vector */ + float code[L_SUBFR]; /* Fixed codebook excitation */ + float y2[L_SUBFR]; /* Filtered algebraic excitation */ + float *pt_pitch; /* pointer to floating pitch buffer */ + float gain_pit; /* Pitch gain */ + float voice_fac; /* Voicing factor */ + float gain_code; /* gain of code */ + float gain_inov; /* inovative gain */ + const float *p_Aw, *p_Aq; /* pointer to LP filter coeff. vector */ + short i_subfr; + float norm_gain_code; + + /*------------------------------------------------------------------* + * Initializations + *------------------------------------------------------------------*/ + + gain_pit = 0; + + if( st->Opt_SC_VBR && vad_flag == 0 && (st->last_ppp_mode == 1 || st->last_nelp_mode == 1) ) + { + /* SC_VBR - reset the encoder, to avoid memory not updated issue for the + case when UNVOICED mode is used to code inactive speech */ + CNG_reset_enc( st, mem, pitch_buf, voice_factors, 1 ); + + } + + p_Aw = Aw; + p_Aq = Aq; + pt_pitch = pitch_buf; + + /*----------------------------------------------------------------* + * subframe loop + *----------------------------------------------------------------*/ + + for( i_subfr=0; i_subfrmem_syn, i_subfr, &mem->mem_w0, p_Aq,res, L_SUBFR, p_Aw, st->preemph_fac, xn, NULL, h1 ); + + /*----------------------------------------------------------------* + * Unvoiced subframe processing + *----------------------------------------------------------------*/ + + *pt_pitch = gaus_encode( st, i_subfr, h1, xn, exc, &mem->mem_w0, st->clip_var, &mem->tilt_code, code, &gain_code, + y2, &gain_inov, &voice_fac, &gain_pit, &norm_gain_code, st->core_brate ); + + *tmp_noise = norm_gain_code; + + voice_factors[i_subfr/L_SUBFR] = 0.0f; + + interp_code_5over2( &exc[i_subfr], &bwe_exc[i_subfr * HIBND_ACB_L_FAC], L_SUBFR ); + + /*-----------------------------------------------------------------* + * Synthesize speech to update mem_syn[]. + * Update A(z) filters + *-----------------------------------------------------------------*/ + + syn_filt( p_Aq, M, &exc[i_subfr], &syn[i_subfr], L_SUBFR, mem->mem_syn, 1 ); + + p_Aw += (M+1); + p_Aq += (M+1); + pt_pitch++; + } + + /* SC-VBR */ + st->prev_ppp_gain_pit = gain_pit; + st->prev_tilt_code = mem->tilt_code; + + return; +} diff --git a/src/libs/libevs/lib_enc/enc_uv_fx.cpp b/src/libs/libevs/lib_enc/enc_uv_fx.cpp deleted file mode 100755 index 0224b95b..00000000 --- a/src/libs/libevs/lib_enc/enc_uv_fx.cpp +++ /dev/null @@ -1,119 +0,0 @@ -/*==================================================================================== - EVS Codec 3GPP TS26.442 Apr 03, 2018. Version 12.11.0 / 13.6.0 / 14.2.0 - ====================================================================================*/ - -#include "options.h" /* Compilation switches */ -#include "cnst_fx.h" /* Common constants */ -#include "prot_fx.h" /* Function prototypes */ -#include "stl.h" - -/*-------------------------------------------------------------------* - * encod_unvoiced() - * - * Encode unvoiced (UC) frames - *-------------------------------------------------------------------*/ -/*fixed point implementation of unvoiced_encoder*/ -void encod_unvoiced_fx( - Encoder_State_fx *st_fx, /* i/o: state structure */ - LPD_state *mem, /* i/o: acelp memories */ - const Word16 *speech_fx, /* i : Input speech */ - const Word16 Aw_fx[], /* i : weighted A(z) unquantized for subframes */ - const Word16 *Aq_fx, /* i : 12k8 Lp coefficient */ - const Word16 vad_flag_fx, - const Word16 *res_fx, /* i : residual signal */ - Word16 *syn_fx, /* o : core synthesis */ - Word16 *tmp_noise_fx, /* o : long-term noise energy */ - Word16 *exc_fx, /* i/o: current non-enhanced excitation */ - Word16 *pitch_buf_fx, /* o : floating pitch values for each subframe */ - Word16 *voice_factors_fx, /* o : voicing factors */ - Word16 *bwe_exc_fx, /* i/o: excitation for SWB TBE */ - const Word16 Q_new, - const Word16 shift -) -{ - Word16 xn_fx[L_SUBFR]; /* Target vector for pitch search */ - Word16 h1_fx[L_SUBFR]; /* Impulse response vector */ - Word16 code_fx[L_SUBFR]; /* Fixed codebook excitation */ - Word16 y2_fx[L_SUBFR]; /* Filtered algebraic excitation */ - Word16 *pt_pitch_fx; /* pointer to floating pitch buffer */ - Word16 gain_pit_fx; /* Pitch gain */ - Word16 voice_fac_fx; /* Voicing factor */ - Word32 L_gain_code_fx; /* gain of code */ - Word16 gain_inov_fx; /* inovative gain */ - const Word16 *p_Aw_fx, *p_Aq_fx; /* pointer to LP filter coeff. vector */ - Word16 i_subfr; - Word32 norm_gain_code_fx; - - /*------------------------------------------------------------------* - * Initializations - *------------------------------------------------------------------*/ - gain_pit_fx = 0; - move16(); - - test(); - test(); - test(); - IF( st_fx->Opt_SC_VBR_fx && vad_flag_fx == 0 && (sub(st_fx->last_ppp_mode_fx,1) == 0 || sub(st_fx->last_nelp_mode_fx,1) == 0) ) - { - /* SC_VBR - reset the encoder, to avoid memory not updated issue for the - case when UNVOICED mode is used to code inactive speech */ - CNG_reset_enc_fx( st_fx, mem, pitch_buf_fx, voice_factors_fx, 1 ); - } - - p_Aw_fx = Aw_fx; - p_Aq_fx = Aq_fx; - pt_pitch_fx = pitch_buf_fx; - move16(); - - FOR (i_subfr=0; i_subfrmem_syn, i_subfr, &mem->mem_w0, p_Aq_fx, - res_fx, L_SUBFR, p_Aw_fx, st_fx->preemph_fac, xn_fx, NULL - ,h1_fx - ); - /*Copy_Scale_sig(h1_fx, h2_fx, L_SUBFR, -2);*/ - Scale_sig(h1_fx, L_SUBFR, add(1, shift)); /* set h1[] in Q14 with scaling for convolution */ - - /* scaling of xn[] to limit dynamic at 12 bits */ - Scale_sig(xn_fx, L_SUBFR, shift); - /*----------------------------------------------------------------* - * Unvoiced subframe processing - *----------------------------------------------------------------*/ - - *pt_pitch_fx = gaus_encode_fx( st_fx, i_subfr, h1_fx, xn_fx, exc_fx, &mem->mem_w0, st_fx->clip_var_fx, - &mem->tilt_code, code_fx, &L_gain_code_fx, y2_fx, &gain_inov_fx, - &voice_fac_fx, &gain_pit_fx, Q_new,shift,&norm_gain_code_fx, st_fx->core_brate_fx ); - - *tmp_noise_fx = extract_h(norm_gain_code_fx); - - voice_factors_fx[i_subfr/L_SUBFR] = 0; - move16(); - - interp_code_5over2_fx( &exc_fx[i_subfr], &bwe_exc_fx[i_subfr * HIBND_ACB_L_FAC], L_SUBFR ); - - /*-----------------------------------------------------------------* - * Synthesize speech to update mem_syn[]. - * Update A(z) filters - *-----------------------------------------------------------------*/ - Syn_filt_s(1, p_Aq_fx, M, &exc_fx[i_subfr], &syn_fx[i_subfr], L_SUBFR, mem->mem_syn, 1 ); - - p_Aw_fx += (M+1); - p_Aq_fx += (M+1); - pt_pitch_fx++; - } - - /* SC-VBR */ - st_fx->prev_ppp_gain_pit_fx = gain_pit_fx; - move16(); - st_fx->prev_tilt_code_fx = mem->tilt_code; - move16(); - - return; -} diff --git a/src/libs/libevs/lib_enc/encoder.cpp b/src/libs/libevs/lib_enc/encoder.cpp old mode 100755 new mode 100644 index 29f278c1..3c994d01 --- a/src/libs/libevs/lib_enc/encoder.cpp +++ b/src/libs/libevs/lib_enc/encoder.cpp @@ -1,64 +1,54 @@ /*==================================================================================== - EVS Codec 3GPP TS26.442 Apr 03, 2018. Version 12.11.0 / 13.6.0 / 14.2.0 + EVS Codec 3GPP TS26.443 Nov 13, 2018. Version 12.11.0 / 13.7.0 / 14.3.0 / 15.1.0 ====================================================================================*/ - #include #include #include #include #include -#include #include #include #include "options.h" -#include "stl.h" -#include "disclaimer.h" +#include "cnst.h" +#include "prot.h" +#include "rom_com.h" #include "g192.h" -#include "stat_enc_fx.h" -#include "prot_fx.h" /*------------------------------------------------------------------------------------------* * Global variables *------------------------------------------------------------------------------------------*/ long frame = 0; /* Counter of frames */ + + /*------------------------------------------------------------------------------------------* - * Local constants + * Main encoder function *------------------------------------------------------------------------------------------*/ - - - int main( int argc, char** argv ) { - FILE *f_stream = NULL; /* output bitstream file */ - Indice_fx ind_list[MAX_NUM_INDICES]; /* list of indices */ - Encoder_State_fx *st_fx; /*Encoder state struct*/ - Word16 enc_delay; - FILE *f_input; /* input signal file */ - FILE *f_rate; /* bitrate switching profile file */ - FILE *f_bwidth; /* bandwidth switching profile file */ + + FILE *f_input; /* MODE1 - input signal file */ + FILE *f_stream; /* MODE1 - output bitstream file */ + FILE *f_rate = NULL; /* MODE1 - bitrate switching profile file */ + FILE *f_bwidth = NULL; /* MODE1 - bandwidth switching profile file */ FILE *f_rf = NULL; /* Channel aware configuration file */ - Word16 input_frame; - Word16 tmps; - Word16 n_samples; - Word16 data[L_FRAME48k]; /* Input buffer */ - Word32 bwidth_profile_cnt = 0; /* counter of frames for bandwidth switching profile file */ - Word16 quietMode = 0; - Word16 noDelayCmp = 0; - Word16 Opt_RF_ON_loc, rf_fec_offset_loc; - - + long bwidth_profile_cnt = 0; /* MODE1 - counter of frames for bandwidth switching profile file */ + short tmps, input_frame, enc_delay, n_samples; + short quietMode = 0; + short noDelayCmp = 0; + short data[L_FRAME48k]; /* 'short' buffer for input signal */ + Indice ind_list[MAX_NUM_INDICES]; /* list of indices */ + Encoder_State *st; /* MODE1 - encoder state structure */ UWord8 pFrame[(MAX_BITS_PER_FRAME + 7) >> 3]; Word16 pFrame_size = 0; + short Opt_RF_ON_loc, rf_fec_offset_loc; + + - /* start WMOPS counting */ - BASOP_init - /*Inits*/ - f_bwidth = f_rate = NULL; /*------------------------------------------------------------------------------------------* * Allocate memory for static variables @@ -66,60 +56,49 @@ int main( int argc, char** argv ) * Encoder initialization *------------------------------------------------------------------------------------------*/ - if ( (st_fx = (Encoder_State_fx *) calloc( 1, sizeof(Encoder_State_fx) ) ) == NULL ) + if ( (st = (Encoder_State *) malloc( sizeof(Encoder_State) ) ) == NULL ) { fprintf(stderr, "Can not allocate memory for encoder state structure\n"); exit(-1); } - io_ini_enc_fx( argc, argv, &f_input, &f_stream, &f_rate, &f_bwidth, - &f_rf, - &quietMode, &noDelayCmp, st_fx); + io_ini_enc( argc, argv, &f_input, &f_stream, &f_rate, &f_bwidth, + &f_rf, &quietMode, &noDelayCmp, st ); - /*input_frame = (short)(st->input_Fs / 50);*/ - st_fx->input_frame_fx = extract_l(Mult_32_16(st_fx->input_Fs_fx , 0x0290)); - input_frame = st_fx->input_frame_fx; + Opt_RF_ON_loc = st->Opt_RF_ON; + rf_fec_offset_loc = st->rf_fec_offset; - Opt_RF_ON_loc = st_fx->Opt_RF_ON; - rf_fec_offset_loc = st_fx->rf_fec_offset; + st->ind_list = ind_list; + init_encoder( st ); - st_fx->ind_list_fx = ind_list; - init_encoder_fx( st_fx ); + input_frame = (short)(st->input_Fs / 50); /*------------------------------------------------------------------------------------------* * Compensate for encoder delay (bitstream aligned with input signal) * Compensate for the rest of codec delay (local synthesis aligned with decoded signal and original signal) *------------------------------------------------------------------------------------------*/ - - enc_delay = NS2SA(st_fx->input_Fs_fx, get_delay_fx(ENC, st_fx->input_Fs_fx)); - + enc_delay = NS2SA( st->input_Fs, get_delay(ENC, st->input_Fs) + 0.5f); if ( noDelayCmp == 0 ) { /* read samples and throw them away */ - if( (tmps = (Word16)fread(data, sizeof(short), enc_delay, f_input)) != enc_delay ) + if( (tmps = (short)fread(data, sizeof(short), enc_delay, f_input)) != enc_delay ) { + fprintf(stderr, "Can not read the data from input file\n"); + exit(-1); } - + /* the number of first output samples will be reduced by this amount */ } + /*------------------------------------------------------------------------------------------* * Loop for every frame of input data * - Read the input data - * - Select the best operating mode + * - Process switching files * - Run the encoder * - Write the parameters into output bitstream file *------------------------------------------------------------------------------------------*/ - BASOP_end_noprint; - BASOP_init; -#if (WMOPS) - Init_WMOPS_counter(); - Reset_WMOPS_counter(); - setFrameRate(48000, 960); -#endif - - - if (quietMode == 0) + if( quietMode == 0 ) { fprintf( stdout, "\n------ Running the encoder ------\n\n" ); fprintf( stdout, "Frames processed: " ); @@ -129,154 +108,114 @@ int main( int argc, char** argv ) fprintf( stdout, "\n-- Start the encoder (quiet mode) --\n\n" ); } - - /*Encode-a-frame loop start*/ while( (n_samples = (short)fread(data, sizeof(short), input_frame, f_input)) > 0 ) { -#if (WMOPS) - Reset_WMOPS_counter(); -#endif - SUB_WMOPS_INIT("enc"); - - IF(f_rf != NULL) + if(f_rf != NULL) { - read_next_rfparam_fx( - &st_fx->rf_fec_offset, &st_fx->rf_fec_indicator, f_rf); - rf_fec_offset_loc = st_fx->rf_fec_offset; + read_next_rfparam( &st->rf_fec_offset, &st->rf_fec_indicator, f_rf); + rf_fec_offset_loc = st->rf_fec_offset; } - IF(f_rate != NULL) + if (f_rate != NULL) { /* read next bitrate from profile file (only if invoked on the cmd line) */ - read_next_brate_fx( &st_fx->total_brate_fx, st_fx->last_total_brate_fx, - f_rate, st_fx->input_Fs_fx, &st_fx->Opt_AMR_WB_fx, &st_fx->Opt_SC_VBR_fx, &st_fx->codec_mode ); + read_next_brate( &st->total_brate, st->last_total_brate, + f_rate, st->input_Fs, &st->Opt_AMR_WB, &st->Opt_SC_VBR, &st->codec_mode); } - IF (f_bwidth != NULL) + if (f_bwidth != NULL) { /* read next bandwidth from profile file (only if invoked on the cmd line) */ - read_next_bwidth_fx( &st_fx->max_bwidth_fx, f_bwidth, &bwidth_profile_cnt, st_fx->input_Fs_fx ); + read_next_bwidth( &st->max_bwidth, f_bwidth, &bwidth_profile_cnt, st->input_Fs ); } - IF( ( st_fx->Opt_RF_ON && ( L_sub( st_fx->total_brate_fx, ACELP_13k20 ) != 0 || L_sub( st_fx->input_Fs_fx, 8000 ) == 0 || st_fx->max_bwidth_fx == NB ) ) - || st_fx->rf_fec_offset == 0 ) + if( ( st->Opt_RF_ON && ( st->total_brate != ACELP_13k20 || st->input_Fs == 8000 || st->max_bwidth == NB ) ) || st->rf_fec_offset == 0 ) { - IF( L_sub( st_fx->total_brate_fx, ACELP_13k20) == 0 ) + if( st->total_brate == ACELP_13k20 ) { - st_fx->codec_mode = MODE1; - reset_rf_indices(st_fx); + st->codec_mode = MODE1; + reset_rf_indices(st); } - st_fx->Opt_RF_ON = 0; - st_fx->rf_fec_offset = 0; - + st->Opt_RF_ON = 0; + st->rf_fec_offset = 0; } - IF( Opt_RF_ON_loc && rf_fec_offset_loc != 0 && L_sub( st_fx->total_brate_fx, ACELP_13k20 ) == 0 && L_sub( st_fx->input_Fs_fx, 8000 ) != 0 && st_fx->max_bwidth_fx != NB ) + if( Opt_RF_ON_loc && rf_fec_offset_loc != 0 && L_sub( st->total_brate, ACELP_13k20 ) == 0 && L_sub( st->input_Fs, 8000 ) != 0 && st->max_bwidth != NB ) { - st_fx->codec_mode = MODE2; - IF(st_fx->Opt_RF_ON == 0) + st->codec_mode = MODE2; + if(st->Opt_RF_ON == 0) { - reset_rf_indices(st_fx); + reset_rf_indices(st); } - st_fx->Opt_RF_ON = 1; - st_fx->rf_fec_offset = rf_fec_offset_loc; + st->Opt_RF_ON = 1; + st->rf_fec_offset = rf_fec_offset_loc; } /* in case of 8kHz sampling rate or when in "max_band NB" mode, limit the total bitrate to 24.40 kbps */ - IF ( (L_sub( st_fx->input_Fs_fx, 8000 ) == 0 || (st_fx->max_bwidth_fx == NB)) && L_sub( st_fx->total_brate_fx, ACELP_24k40 ) > 0 ) + if ( ((st->input_Fs == 8000)|| (st->max_bwidth == NB)) && (st->total_brate > ACELP_24k40) ) { - st_fx->total_brate_fx = ACELP_24k40; - st_fx->codec_mode = MODE2; + st->total_brate = ACELP_24k40; + st->codec_mode = MODE2; } /* run the main encoding routine */ + if ( st->Opt_AMR_WB ) + { + amr_wb_enc( st, data, n_samples ); + } + else + { + evs_enc( st, data, n_samples ); + } - IF ( st_fx->Opt_AMR_WB_fx ) - { - SUB_WMOPS_INIT("amr_wb_enc"); - amr_wb_enc_fx( st_fx, data, n_samples); - END_SUB_WMOPS; - } - ELSE - { - SUB_WMOPS_INIT("evs_enc"); - /* EVS encoder*/ - evs_enc_fx( st_fx, data, n_samples); - END_SUB_WMOPS; - } /* pack indices into serialized payload format */ - if( st_fx->bitstreamformat == MIME ) + if( st->bitstreamformat == MIME ) { - indices_to_serial(st_fx, pFrame, &pFrame_size); + indices_to_serial( st, pFrame, &pFrame_size ); } /* write indices into bitstream file */ - write_indices_fx( st_fx, f_stream, pFrame, pFrame_size ); + write_indices( st, f_stream + , pFrame, pFrame_size + ); - END_SUB_WMOPS; - /* update WMPOS counting (end of frame) */ - - - fflush(stderr); + fflush( stderr ); frame++; - if (quietMode == 0) + if( quietMode == 0 ) { fprintf( stdout, "%-8ld\b\b\b\b\b\b\b\b", frame ); } - -#if (WMOPS) - fwc(); -#endif } - /* ----- Encode-a-frame loop end ----- */ - - - if (quietMode == 0) + if( quietMode == 0 ) { fprintf( stdout, "\n\n" ); - fprintf(stderr, "Encoding finished\n\n"); + fprintf( stdout, "Encoding finished\n\n" ); } else { - fprintf(stderr, "Encoding of %ld frames finished\n\n", frame); + fprintf( stdout, "Encoding of %ld frames finished\n\n", frame ); } -#if (WMOPS) - fwc(); - printf("\nEncoder complexity\n"); - WMOPS_output(0); - printf("\n"); -#endif - /* Close Encoder, Close files and free ressources */ - BASOP_init + /*------------------------------------------------------------------------------------------* + * Close files and free ressources + *------------------------------------------------------------------------------------------*/ - - IF(st_fx != NULL) - { - /* common delete function */ - destroy_encoder_fx( st_fx ); - free(st_fx); - } - - BASOP_end_noprint - - - IF(f_input) - fclose(f_input); - IF(f_stream) - fclose(f_stream); - IF(f_rate) - fclose(f_rate); - IF(f_bwidth) - fclose(f_bwidth); + fclose( f_input ); + fclose( f_stream ); + if ( f_rate ) fclose ( f_rate ); + if ( f_bwidth ) fclose ( f_bwidth ); + destroy_encoder( st ); + free( st ); return 0; } + + diff --git a/src/libs/libevs/lib_enc/energy.cpp b/src/libs/libevs/lib_enc/energy.cpp old mode 100755 new mode 100644 index 9085a356..b05a9f71 --- a/src/libs/libevs/lib_enc/energy.cpp +++ b/src/libs/libevs/lib_enc/energy.cpp @@ -1,412 +1,209 @@ /*==================================================================================== - EVS Codec 3GPP TS26.442 Apr 03, 2018. Version 12.11.0 / 13.6.0 / 14.2.0 + EVS Codec 3GPP TS26.443 Nov 13, 2018. Version 12.11.0 / 13.7.0 / 14.3.0 / 15.1.0 ====================================================================================*/ - +#include #include #include -#include +#include "prot.h" +#include "cnst.h" +#include "rom_enc.h" -#include "basop_util.h" -#include "stl.h" -#include "rom_enc_fx.h" -#include "vad_basop.h" -#include "prot_fx.h" -void est_energy( - Word32 enerBuffer[CLDFB_NO_CHANNELS_MAX], /* i: energy vector per band */ - Word16 enerBuffer_exp, /* i: exponent of energy vector */ - Word32 *frame_sb_energy, /*(o) energy of sub-band divided non-uniformly*/ - Word32 *frame_energy2_p, /*(o) frame energy 2*/ - Word32 *HB_Power_p, /*(o) high frequency energy*/ - Word32 *frame_energy_p, /*(o) frame energy 1*/ - Word16 *sb_power_Q, /*(o) the scaling of sb_power*/ - Word16 *frame_energy2_Q, /*(o) the scaling of frame_energy*/ - Word16 *HB_Power_Q, /*(o) the scaling of HB_Power*/ - Word16 *frame_energy_Q, /*(o) the Scaling of frame_energy*/ - Word16 *frame_sb_energy_scale, /*(o) the Scaling of frame_sb_energy[]*/ - Word32 bandwidth /*(i) band width*/ -) -{ - Word32 i,j; - Word32 frame_energy2,HB_Power,tmpspec_amp; - Word32 sb_power_tmp; - Word32 frame_energy,s32CopyPower; - Word32 SNR_sb_num; - Word16 shr_tmp; - Word32 BandNum; - Word16 widthsb,s16MaxCoefNorm; - const Word16 *Nregion_index; - Word32 *sb_power = enerBuffer; - Word32 Ltmp32 = 0; - - SNR_sb_num = SNR_SUB_BAND_NUM[bandwidth-CLDFBVAD_NB_ID]; - move16(); - Nregion_index = REGION_INDEX[bandwidth-CLDFBVAD_NB_ID]; - move16(); - - shr_tmp = BAND_SCALE_AJ[bandwidth]; - move16(); - BandNum = BAND_NUM_TAB[bandwidth]; - move16(); - - frame_energy2 = L_shr(sb_power[1], shr_tmp); - HB_Power = L_shr(sb_power[6], shr_tmp); - FOR(i = 2; i < BandNum; i++) - { - Ltmp32 = L_shr(sb_power[i],shr_tmp); - frame_energy2 = L_add(frame_energy2, Ltmp32 ); - if(i > 6) HB_Power = L_add(HB_Power, Ltmp32 ); - } - frame_energy2 = L_sub(frame_energy2, Ltmp32 ); - - sb_power_tmp = L_shr(sb_power[0],shr_tmp); - - IF(L_sub(bandwidth,1)==0) - { - frame_energy = L_add(frame_energy2,MUL_F(sb_power_tmp,0x147a)); - } - ELSE IF(L_sub(bandwidth,2)==0) - { - frame_energy = L_add(frame_energy2,MUL_F(sb_power_tmp,0x1eb8)); - } - ELSE IF(L_sub(bandwidth,3)==0) - { - frame_energy = L_add(frame_energy2,MUL_F(sb_power_tmp,0x23d7)); - } - ELSE IF(L_sub(bandwidth,4)==0) - { - frame_energy = L_add(frame_energy2,MUL_F(sb_power_tmp,0x23d7)); - } - ELSE - { - frame_energy = L_add(frame_energy2,MUL_F(sb_power_tmp,0x23d7)); - } - - *frame_energy2_p = frame_energy2; - move32(); - *HB_Power_p = HB_Power; - move32(); - *frame_energy_p = frame_energy; - move32(); - /* enerBuffer(float) = enerBuffer(fixed) * 2^(-(31-enerBuffer_exp)) */ - /* +30 is to keep original precision */ - *sb_power_Q = sub(31+30,enerBuffer_exp); - move16(); - *frame_energy2_Q = sub(*sb_power_Q,shr_tmp); - move16(); - *HB_Power_Q = sub(*sb_power_Q,shr_tmp); - move16(); - *frame_energy_Q = sub(*sb_power_Q,shr_tmp); - move16(); - - FOR(i=0; i<6; i++) - { - frame_sb_energy[i] = sb_power[i]; - move32(); - } - - FOR(i=6; if_tonality_rate; - Word16 *ltd_stable_rate = st->ltd_stable_rate; - Word32 bandwith = st->bw_index; - Word16 cmp_tmp; + int i; + int SNR_sb_num; + float *sb_bg_energy = st->sb_bg_energy; + float *frame_sb_energy = st->frame_sb_energy; + float *f_tonality_rate = st->f_tonality_rate; + float *ltd_stable_rate = st->ltd_stable_rate; + int frameloop = st->frameloop; - move32(); - move16(); - move16(); + float t_bg_energy = st->t_bg_energy; - tmp = L_deposit_l(-1); + SNR_sb_num = ENERGY_BAND_NUM[st->bw_index - CLDFBVAD_NB_ID]; - CONST32fix.s16Exp = 44; - move16(); - CONST32fix.s32Mantissa = 1759218560; - move32(); - SNR_sb_num = SNR_SUB_BAND_NUM[bandwith - CLDFBVAD_NB_ID]; - move16(); - scale_sb_energy = st->sb_bg_energy_scale; - move16(); - sb_bg_energy = st->sb_bg_energy; - move32(); - frame_sb_energy = st->frame_sb_energy; - move32(); - t_bg_energy = L_add(st->t_bg_energy,0); - move32(); + frame_energy = frame_energy + 0.0001f; - t_bg_energy_sum = st->t_bg_energy_sum; - move32(); - normscal = norm_l(frame_energy); - exp_frame_energy.s16Exp = add(scale,normscal); - exp_frame_energy.s32Mantissa = L_shl(frame_energy,normscal); - exp_frame_energy = VAD_AddExp(exp_frame_energy,CONST32fix); - cmp_lt_frame = VAD_L_CMP(exp_frame_energy.s32Mantissa,exp_frame_energy.s16Exp,46,0); - FOR(i=0; i5)&&(f_tonality_rate[0]<0.56)&& + (f_tonality_rate[1]<0.5)&<d_stable_rate[1]<0.06&&snr<2.5f) { - p_scale_sb_energy[i] = scale_sb_energy; - move16(); - } - test(); - test(); - test(); - test(); - test(); - IF( (sub(st->frameloop, 60) < 0) && (sub(st->frameloop, 5) > 0) &&(sub(f_tonality_rate[0],9174/* 0.56 Q14 */)<0) - && (sub(f_tonality_rate[1],8192/* 0.5 Q14 */)<0) && (sub(ltd_stable_rate[1],1966/* 0.06 Q15 */)<0) - && L_sub(snr, 83886080) < 0) - { - t_bg_energy_sum = VAD_AddExp(t_bg_energy_sum,exp_frame_energy); + st->t_bg_energy_sum += frame_energy; + st->tbg_energy_count++; - update_sb_bg_energy(sb_bg_energy, &st->tbg_energy_count, p_scale_sb_energy, SNR_sb_num, frame_sb_energy, st->frame_sb_energy_scale, - 29490/* 0.90 Q15 */, 3, 26214); - } - - test(); - test(); - IF((L_sub(update_flag,1)==0) && (sub(st->frameloop, 2) > 0) && music_backgound_f==0) - { - IF(sub(st->bg_update_count, 16) < 0) + for(i=0; itbg_energy_count, p_scale_sb_energy, SNR_sb_num, frame_sb_energy, st->frame_sb_energy_scale, - 31456/* 0.96 Q15 */, 4, 20971/* 0.04 Q19 */); - - st->bg_update_count = add(st->bg_update_count, 1); + sb_bg_energy[i] = sb_bg_energy[i]*0.90f + frame_sb_energy[i]*0.1f; } - ELSE + } + if(update_flag==1&&frameloop>2&&music_backgound_f==0) + { + if(st->bg_update_count<16) { - - cmp_lt_frame = VAD_L_CMP(t_bg_energy, st->scale_t_bg_energy, exp_frame_energy.s32Mantissa, exp_frame_energy.s16Exp); - cmp_pre_frame = VAD_L_CMP(MUL_F(st->frame_energy_smooth, 24576), sub(st->frame_energy_smooth_scale, 5), exp_frame_energy.s32Mantissa, exp_frame_energy.s16Exp); - cmp_tmp = VAD_L_CMP(MUL_F(t_bg_energy, 24576), sub(st->scale_t_bg_energy, 4), exp_frame_energy.s32Mantissa, exp_frame_energy.s16Exp); - - test(); - IF( (cmp_lt_frame < 0) && (cmp_pre_frame < 0) ) + st->t_bg_energy_sum += frame_energy; + st->tbg_energy_count++; + for(i=0; iframe_sb_energy_scale); - FOR(i=0; ibg_update_count++; + } + else + { + float a = 0.94f; + if((t_bg_energyframe_energy_smoothtbg_energy_count, p_scale_sb_energy, SNR_sb_num, frame_sb_energy, st->frame_sb_energy_scale, - 31456/* 0.96 Q15 */, 4, 20971/* 0.04 Q19 */); - - } - ELSE - { - cmp_pre_frame = VAD_L_CMP(t_bg_energy, st->scale_t_bg_energy, exp_frame_energy.s32Mantissa, exp_frame_energy.s16Exp); - IF(cmp_pre_frame>0) + st->t_bg_energy_sum += frame_energy; + st->tbg_energy_count++; + for(i=0; itbg_energy_count, p_scale_sb_energy, SNR_sb_num, frame_sb_energy, st->frame_sb_energy_scale, - 31129/* 0.95 Q15 */, 4, 26214/* 0.05 Q19 */); - + sb_bg_energy[i] = sb_bg_energy[i]*0.96f + frame_sb_energy[i]*0.04f; } - ELSE + } + else + { + if(t_bg_energy>frame_energy) { - t_bg_energy_sum = VAD_AddExp(t_bg_energy_sum, exp_frame_energy); - update_sb_bg_energy(sb_bg_energy, &st->tbg_energy_count, p_scale_sb_energy, SNR_sb_num, frame_sb_energy, st->frame_sb_energy_scale, - 31456/* 0.96 Q15 */, 4, 20971/* 0.04 Q19 */); + a = 0.95f; + st->t_bg_energy_sum += frame_energy; + st->tbg_energy_count++; + for(i=0; it_bg_energy_sum += frame_energy; + st->tbg_energy_count++; + for(i=0; iscale_t_bg_energy, MUL_F(exp_frame_energy.s32Mantissa, 32000), sub(exp_frame_energy.s16Exp, 9)); - cmp_lt_frame = VAD_L_CMP(sb_bg_energy[0], scale_sb_energy, MUL_F(frame_sb_energy[0], 20480), sub(st->frame_sb_energy_scale, 4)); - - test(); - IF( (cmp_pre_frame > 0) && (cmp_lt_frame > 0) ) + if((t_bg_energy>500*frame_energy)&&(sb_bg_energy[0] >10*frame_sb_energy[0])) { - tmpQ = add(4, st->frame_sb_energy_scale); - FOR(i=0; i10*frame_energy) { - cmp_pre_frame = VAD_L_CMP(t_bg_energy, st->scale_t_bg_energy, MUL_F(exp_frame_energy.s32Mantissa, 20480), sub(exp_frame_energy.s16Exp, 4)); - IF( cmp_pre_frame > 0 ) + for(i=0; iframe_sb_energy_scale); - FOR(i=0; itbg_energy_count); - cmp_pre_frame = VAD_L_CMP(t_bg_energy_sum.s32Mantissa, t_bg_energy_sum.s16Exp, tmp, 0); - IF(cmp_pre_frame > 0) + if(st->t_bg_energy_sum>160*st->tbg_energy_count) { - i = norm_l(tmp); - t_bg_energy_sum.s32Mantissa = L_shl(tmp, i); - t_bg_energy_sum.s16Exp = i; - move16(); + st->t_bg_energy_sum = 160.0f*st->tbg_energy_count; } - NormEnergyWord32(sb_bg_energy, SNR_sb_num, p_scale_sb_energy, &scale_sb_energy); - cmp_pre_frame = VAD_L_CMP(t_bg_energy, st->scale_t_bg_energy, 1, 0); - test(); - test(); - test(); - IF( (sub(music_backgound_f, 1) == 0) && (L_sub(st->lt_snr_org, 107374179/* 3.2 Q25 */) < 0) - && (cmp_pre_frame > 0) && update_flag == 0) + if(music_backgound_f==1&&st->lt_snr_org<3.2&&t_bg_energy>1&&update_flag==0) { - tmp = L_shr(2147/* 0.000001 Q31 */, sub(31, scale_sb_energy)); - FOR(i=0; iscale_t_bg_energy, 15)); - IF(cmp_pre_frame < 0) - { - tmp = L_shr(2147/* 0.000001 Q31 */, sub(31, scale_sb_energy)); - FOR(i=0; itbg_energy_count, 64) == 0)) + if(st->tbg_energy_count==64) { st->tbg_energy_count = 48; - move16(); - t_bg_energy_sum.s32Mantissa = MUL_F(t_bg_energy_sum.s32Mantissa, 24575/* 0.75 Q15 */); + st->t_bg_energy_sum = st->t_bg_energy_sum*0.75f; } - t_bg_energy = VAD_L_div(t_bg_energy_sum.s32Mantissa, st->tbg_energy_count, t_bg_energy_sum.s16Exp, 0, &q_divout); - st->scale_t_bg_energy = q_divout; - move16(); - st->t_bg_energy = t_bg_energy; - move32(); - st->sb_bg_energy_scale = scale_sb_energy; - move16(); - st->t_bg_energy_sum = t_bg_energy_sum; - move16(); - move32(); + st->t_bg_energy = st->t_bg_energy_sum/st->tbg_energy_count; + + } +void est_energy(float sb_power[], /*(o) energy of sub-band divided uniformly*/ + float frame_sb_energy[], /*(o) energy of sub-band divided non-uniformly*/ + float *p_frame_energy, /*(o) frame energy 1*/ + float *p_frame_energy2, /*(o) frame energy 2*/ + float *p_high_energy, /*(o) high frequency energy*/ + int bw /*(i) band width*/ + ) +{ + int i, j; + float frame_energy2 = 0.0f; + float high_energy = 0.0f; + int band_num = BAND_NUM_TAB[bw]; + const float sb_power_scale[5] = {0.0f, 0.16f, 0.24f, 0.28f, 0.28f}; + + const int *Nregion_index; + int SNR_sb_num; + + + for(i=0; i0 && (i!=band_num-1)) + { + frame_energy2+=sb_power[i]; + } + if(i>5) + { + high_energy += sb_power[i]; + } + } + + high_energy /= (32768.f * 32768.f); + frame_energy2 /= (32768.f * 32768.f); + + Nregion_index = REGION_INDEX[bw-CLDFBVAD_NB_ID]; + SNR_sb_num = ENERGY_BAND_NUM[bw-CLDFBVAD_NB_ID]; + + for(i=0; i +#include "options.h" +#include "cnst.h" +#include "rom_com.h" +#include "prot.h" + + +/*-------------------------------------------------------------------* + * Local constantes + *-------------------------------------------------------------------*/ + +#define NB_VOIC 13 +#define DIV_NB_VOIC (1.0f/NB_VOIC) +#define ALPA 0.95f +#define ALPAM1 (1.0f-ALPA) +#define BETA (ALPAM1/2.0f) +#define AFREQ_THR 2 +#define GPIT_THR 0.4f +#define HANGOVER_DELAY 2 + +/*-------------------------------------------------------------------* + * Pit_exc_contribution_len() + * + * Determine up to which band the pit contribution is significant + *-------------------------------------------------------------------*/ + +short Pit_exc_contribution_len( /* o : bin where pitch contribution is significant */ + Encoder_State *st, /* i/o: state structure */ + const float *dct_res, /* i : DCT of residual */ + float *dct_pitex, /* i/o: DCT of pitch contribution */ + float *pitch_buf, /* i/o: Pitch per subframe */ + short *hangover, /* i : hangover for the time contribution switching */ + const short coder_type /* i : coding type */ +) +{ + float corr_dct_pit[MBANDS_LOC], corr_tmp; + float av_corr, min_corr, ftmp; + short freq, i, j; + short last_pit_band, pit_contr_idx, last_pit_bin; + float ener_res; + float ener_pit; + float low_pit, F1st_harm, F8th_harm; + float corr_dct_pit_tmp[MBANDS_LOC]; + short time_flg = 0; + short Len, max_len; + short tmp_dec; + short Mbands_loc = MBANDS_LOC-2; + + if(st->L_frame == L_FRAME16k ) + { + Mbands_loc = MBANDS_LOC; + } + + minimum( pitch_buf, st->L_frame >> 6, &low_pit ); + + F1st_harm = 12800.0f/low_pit; + F8th_harm = 8.0f*F1st_harm; + + freq = 0; + for (i = 0; i core_brate < ACELP_9k60 ) + { + /* Correlation really poor at low rate, time domain still valide */ + av_corr *= 2.0; + } + + min_corr =(float)fabs(mfreq_loc[0] - av_corr); + + for (i = 1; i mfreq_loc[last_pit_band] ) + { + do + { + last_pit_band++; + } + while( F8th_harm >= mfreq_loc[last_pit_band] ); + } + + if( last_pit_band > 7+BAND1k2 && (st->core_brate < CFREQ_BITRATE || st->bwidth == NB) ) + { + last_pit_band = 7+BAND1k2; + } + else if ( last_pit_band > 10+BAND1k2 && st->core_brate >= CFREQ_BITRATE ) + { + last_pit_band = 10+BAND1k2; + } + + time_flg = 0; + if( (st->mem_last_pit_band > 0 && st->old_corr > 0.5f && st->mold_corr > 0.5f && st->lt_gpitch >= 1.5f*GPIT_THR ) + || (last_pit_band > 6) + || (last_pit_band >= 4 && st->lt_gpitch >= 1.5f*GPIT_THR && st->old_corr > 0.7f) + || (last_pit_band > BAND1k2 && st->mold_corr > 0.80f && st->lt_gpitch >= GPIT_THR) ) + { + tmp_dec = 1; + } + else + { + tmp_dec = 0; + } + + /* Different past and current decision */ + if ( (st->mem_last_pit_band == 0 && tmp_dec == 1) || (st->mem_last_pit_band > 0 && tmp_dec == 0) ) + { + if( *hangover == 0 ) + { + time_flg = tmp_dec; + *hangover = HANGOVER_DELAY; + } + else + { + time_flg = 0; + if( st->mem_last_pit_band > 0 ) + { + time_flg = 1; + } + + (*hangover) -= 1; + if( *hangover < 0 ) + { + *hangover = 0; + } + } + } + else + { + time_flg = tmp_dec; + *hangover = HANGOVER_DELAY; + } + + /* Decicison on final lenght of time contribution */ + pit_contr_idx = 0; + if( time_flg == 1 || coder_type != INACTIVE || st->GSC_noisy_speech ) + { + if( st->core_brate bwidth == NB) + { + last_pit_band = 7+BAND1k2; + } + } + else if(st->core_brate < ACELP_9k60 && low_pit < 128) + { + last_pit_band = 5+BAND1k2; + } + else if(st->core_brate < ACELP_9k60 ) + { + last_pit_band = 3+BAND1k2; + } + else if( last_pit_band < BAND1k2+1 ) + { + last_pit_band = BAND1k2+1; + } + + last_pit_bin = (short)(mfreq_loc[last_pit_band]/BIN_SIZE); + + st->bpf_off = 0; + + max_len = st->L_frame-last_pit_bin; + if( st->bwidth == NB ) + { + max_len = 160-last_pit_bin; + } + + Len = 80; + if( max_len < 80 ) + { + Len = max_len; + } + + if(st->core_brate == ACELP_8k00 && st->bwidth != NB ) + { + for (i=0; i < max_len; i++) + { + dct_pitex[i+last_pit_bin] = 0.0f; + } + } + else + { + for (i = 0; i < Len; i++) + { + dct_pitex[i+last_pit_bin] *= sm_table[i]; + } + + for (; i < max_len; i++) + { + dct_pitex[i+last_pit_bin] = 0.0f; + } + } + + st->mem_last_pit_band = last_pit_band; + pit_contr_idx = last_pit_band-BAND1k2; + } + else + { + set_f(dct_pitex, 0.0f, st->L_frame); + st->bpf_off = 1; + last_pit_bin = 0; + last_pit_band = 0; + pit_contr_idx = 0; + st->mem_last_pit_band = 0; + set_f( pitch_buf, (float)L_SUBFR, NB_SUBFR ); + + /* pitch contribution useless - delete all previously written indices belonging to pitch contribution */ + for( i = TAG_ACELP_SUBFR_LOOP_START; i < TAG_ACELP_SUBFR_LOOP_END; i++ ) + { + if( st->ind_list[i].nb_bits != -1 ) + { + st->nb_bits_tot -= st->ind_list[i].nb_bits; + st->ind_list[i].nb_bits = -1; + } + } + + if( st->ind_list[IND_ES_PRED].nb_bits != -1 ) + { + st->nb_bits_tot -= st->ind_list[IND_ES_PRED].nb_bits; + st->ind_list[IND_ES_PRED].nb_bits = -1; + } + } + + if( st->core_brate < CFREQ_BITRATE ) + { + if( st->core_brate < ACELP_9k60 ) + { + if( pit_contr_idx > 0 ) + { + pit_contr_idx = 1; + } + + if( coder_type == INACTIVE ) + { + push_indice( st, IND_PIT_CONTR_IDX, pit_contr_idx, 1 ); + } + } + else + { + push_indice( st, IND_PIT_CONTR_IDX, pit_contr_idx, 3 ); + } + } + else + { + push_indice( st, IND_PIT_CONTR_IDX, pit_contr_idx, 4 ); + } + + return last_pit_bin; +} diff --git a/src/libs/libevs/lib_enc/eval_pit_contr_fx.cpp b/src/libs/libevs/lib_enc/eval_pit_contr_fx.cpp deleted file mode 100755 index 81cff4df..00000000 --- a/src/libs/libevs/lib_enc/eval_pit_contr_fx.cpp +++ /dev/null @@ -1,413 +0,0 @@ -/*==================================================================================== - EVS Codec 3GPP TS26.442 Apr 03, 2018. Version 12.11.0 / 13.6.0 / 14.2.0 - ====================================================================================*/ - -#include "options.h" /* Compilation switches */ -#include "cnst_fx.h" /* Common constants */ -#include "rom_com_fx.h" /* Static table prototypes */ -#include "prot_fx.h" /* Function prototypes */ -#include "stl.h" - -/*-------------------------------------------------------------------* - * Local constantes - *-------------------------------------------------------------------*/ -#define NB_VOIC_FX 13 -#define DIV_NB_VOIC_FX 2521 - -#define ALPA_FX 31130 -#define ALPAM1_FX (32768-ALPA_FX) - -#define BETA_FX 819 -#define AFREQ_THR 2 - -#define HANGOVER_DELAY 2 - -/*======================================================================*/ -/* FUNCTION : Pit_exc_contribution_len_fx() */ -/*----------------------------------------------------------------------*/ -/* PURPOSE : Determine up to which band the pit contribution is significant*/ -/*----------------------------------------------------------------------*/ -/* INPUT ARGUMENTS : */ -/* _ (Struct) st_fx : encoder static memory */ -/* _ (Word16[]) dct_res : DCT of residual Qnew */ -/* _ (Word16[]) dct_pitex : DCT of pitch contribution Qnew */ -/* _ (Word16[]) pitch_buf : Pitch per subframe Q6 */ -/* _ (Word16[]) nb_subfr : Number of subframe considered */ -/* _ (Word16) hangover : hangover for the time contribution switching*/ -/* _ (Word16) Qnew : */ -/*-----------------------------------------------------------------------*/ -/* OUTPUT ARGUMENTS : */ -/* _ (Word16[]) dct_res : DCT of residual Qnew */ -/* _ (Word16[]) dct_pitex : DCT of pitch contribution Qnew */ -/*-----------------------------------------------------------------------*/ - - -/*-----------------------------------------------------------------------*/ -/* RETURN ARGUMENTS : */ -/* _ None */ -/*=======================================================================*/ - -Word16 Pit_exc_contribution_len_fx( /* o : bin where pitch contribution is significant */ - Encoder_State_fx *st_fx, /* i/o: state structure */ - const Word16 *dct_res, /* i : DCT of residual */ - Word16 *dct_pitex, /* i/o: DCT of pitch contribution */ - Word16 *pitch_buf, /* i/o: Pitch per subframe */ - const Word16 nb_subfr, /* i : Number of subframe considered */ - Word16 *hangover, /* i : hangover for the time contribution switching */ - const Word16 coder_type, /* i : coding type */ - Word16 Qnew -) -{ - - Word16 corr_dct_pit[MBANDS_LOC]; - Word32 corr_tmp,L_tmp; - Word16 av_corr, min_corr, ftmp, tmp_ex, tmp_res; - Word16 freq, i, j; - Word16 last_pit_band, pit_contr_idx, last_pit_bin; - Word32 ener_res; - Word32 ener_pit; - Word16 low_pit, F1st_harm, F8th_harm; - Word16 corr_dct_pit_tmp[MBANDS_LOC]; - Word16 time_flg = 0; - Word16 Len, max_len; - Word16 tmp_dec; - Word16 Mbands_loc = MBANDS_LOC-2; - Word16 exp1,tmp,exp2; - Word32 L_tmp1, ener_init; - Word16 exp_norm; - Word16 norm; - Word16 val_thrs; - - if( sub(st_fx->L_frame_fx,L_FRAME16k) == 0) - { - Mbands_loc = MBANDS_LOC; - move16(); - } - - minimum_fx( pitch_buf, nb_subfr, &low_pit); - exp1 = norm_s(low_pit); - tmp = shl(low_pit,exp1); - { - /*F1st_harm = 12800.0f/low_pit;*/ - tmp = div_s(12800,tmp); /*15-6-exp1(->9-exp1)*/ - F1st_harm = shr_r(tmp,sub(5,exp1)); /*Q4*/ - } - - /*F8th_harm = 8.0f*F1st_harm;*/ - F8th_harm = extract_l(L_shr_r(L_mult0(F1st_harm,8),2)); /*Q2*/ - - freq = 0; - move16(); - ener_init = L_shl(3,2*Qnew-5); /*(0.1->3 in Q5) 2*Qnew*/ - FOR (i = 0; i core_brate_fx,ACELP_9k60) < 0 ) - { - av_corr = shl(av_corr,1); /*Q2 Correlation really poor at low rate, time domain still valide*/ - } - min_corr = abs_s(sub(mfreq_loc_Q2fx[0],av_corr)); /*Q2*/ - - FOR (i = 1; i 0 ) - { - DO - { - last_pit_band = add(last_pit_band,1); - } - WHILE( sub(F8th_harm,mfreq_loc_Q2fx[last_pit_band]) >= 0 ); - } - test(); - test(); - test(); - IF( sub(last_pit_band,7+BAND1k2) > 0 && (L_sub(st_fx->core_brate_fx,CFREQ_BITRATE) < 0 || sub(st_fx->bwidth_fx,NB) == 0) )/*Added for 9.1*/ - { - last_pit_band = 7+BAND1k2; - move16(); - } - ELSE IF ( sub(last_pit_band,10+BAND1k2) > 0 && L_sub(st_fx->core_brate_fx,CFREQ_BITRATE) >= 0 ) - { - last_pit_band = add(10,BAND1k2); - } - - time_flg = 0; - move16(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - IF( (st_fx->mem_last_pit_band_fx > 0 && sub(st_fx->old_corr_fx,16384) > 0 && sub(st_fx->mold_corr_fx,16384) > 0 && sub(st_fx->lt_gpitch_fx,19661) >= 0/*1.5f*GPIT_THR*/ ) - || (sub(last_pit_band,6) > 0) - || (sub(last_pit_band,4) >= 0 && sub(st_fx->lt_gpitch_fx,19661) >= 0/*1.5f*GPIT_THR*/ && sub(st_fx->old_corr_fx,22938) > 0) - || (sub(last_pit_band,BAND1k2) > 0 && sub(st_fx->mold_corr_fx,26214) > 0 && sub(st_fx->lt_gpitch_fx,13107) >= 0/*GPIT_THR*/) - ) - { - tmp_dec = 1; - move16(); - } - ELSE - { - tmp_dec = 0; - move16(); - } - - /* Different past and current decision */ - test(); - test(); - test(); - IF ( (st_fx->mem_last_pit_band_fx == 0 && sub(tmp_dec,1) == 0) || (st_fx->mem_last_pit_band_fx > 0 && tmp_dec == 0) ) - { - IF( *hangover == 0 ) - { - time_flg = tmp_dec; - move16(); - *hangover = HANGOVER_DELAY; - move16(); - } - ELSE - { - time_flg = 0; - move16(); - if( st_fx->mem_last_pit_band_fx > 0 ) - { - time_flg = 1; - move16(); - } - - (*hangover) = sub((*hangover),1); - if( *hangover < 0 ) - { - *hangover = 0; - move16(); - } - } - } - ELSE - { - time_flg = tmp_dec; - move16(); - *hangover = HANGOVER_DELAY; - move16(); - } - - /* Decicison on final lenght of time contribution */ - pit_contr_idx = 0; - move16(); - test(); - test(); - IF( sub(time_flg,1) == 0 || sub(coder_type,INACTIVE) != 0 || st_fx->GSC_noisy_speech_fx ) - { - test(); - test(); - /*if(st_fx->core_brate_fx core_brate_fx,ACELP_9k60) < 0 && sub(low_pit , 4096) < 0) - { - last_pit_band = add(9 , BAND1k2); - if(sub(st_fx->bwidth_fx,NB) == 0) - { - last_pit_band = add(7,BAND1k2); - } - } - ELSE IF(L_sub(st_fx->core_brate_fx,ACELP_9k60) < 0 && sub(low_pit , 8192) < 0) - { - last_pit_band = add(5 , BAND1k2); - } - ELSE IF(L_sub(st_fx->core_brate_fx,ACELP_9k60) < 0 ) - { - last_pit_band = add(3 , BAND1k2); - } - ELSE IF( sub(last_pit_band,add(BAND1k2,1)) < 0 ) - { - last_pit_band = add(BAND1k2,1); - } - last_pit_bin = mfreq_loc_div_25[last_pit_band]; - move16(); - - st_fx->bpf_off_fx = 0; - move16(); - - max_len = sub(st_fx->L_frame_fx,last_pit_bin); - - if( sub(st_fx->bwidth_fx,NB) == 0 ) - { - max_len = sub(160,last_pit_bin); - } - - Len = 80; - move16(); - if(sub(max_len,80) < 0) - { - Len = max_len; - move16(); - } - test(); - IF((L_sub(st_fx->core_brate_fx,ACELP_8k00) == 0) && (sub(st_fx->bwidth_fx,NB) != 0)) - { - move16(); /*ptr init*/ - FOR (i=0; i < max_len; i++) - { - dct_pitex[i+last_pit_bin] = 0; - move16(); - } - } - ELSE - { - - FOR (i = 0; i < Len; i++) - { - dct_pitex[i+last_pit_bin] = mult_r(dct_pitex[i+last_pit_bin],sm_table_fx[i]); - } - FOR (; i < max_len; i++) - { - dct_pitex[i+last_pit_bin] = 0; - move16(); - } - } - st_fx->mem_last_pit_band_fx = last_pit_band; - move16(); - pit_contr_idx = sub(last_pit_band,BAND1k2); - } - ELSE - { - set16_fx(dct_pitex, 0, st_fx->L_frame_fx); - st_fx->bpf_off_fx = 1; - move16(); - last_pit_bin = 0; - move16(); - last_pit_band = 0; - move16(); - pit_contr_idx = 0; - move16(); - st_fx->mem_last_pit_band_fx = 0; - move16(); - - { - set16_fx( pitch_buf, shl(L_SUBFR,6), NB_SUBFR ); - } - /* pitch contribution useless - delete all previously written indices belonging to pitch contribution */ - FOR ( i = TAG_ACELP_SUBFR_LOOP_START; i < TAG_ACELP_SUBFR_LOOP_END; i++ ) - { - IF ( st_fx->ind_list_fx[i].nb_bits != -1 ) - { - st_fx->nb_bits_tot_fx = sub(st_fx->nb_bits_tot_fx,st_fx->ind_list_fx[i].nb_bits); - st_fx->ind_list_fx[i].nb_bits = -1; - move16(); - } - } - - IF ( st_fx->ind_list_fx[IND_ES_PRED].nb_bits != -1 ) - { - st_fx->nb_bits_tot_fx = sub(st_fx->nb_bits_tot_fx,st_fx->ind_list_fx[IND_ES_PRED].nb_bits); - st_fx->ind_list_fx[IND_ES_PRED].nb_bits = -1; - move16(); - } - } - IF( L_sub(st_fx->core_brate_fx,CFREQ_BITRATE) < 0 ) - { - IF(L_sub(st_fx->core_brate_fx,ACELP_9k60) < 0) - { - if(pit_contr_idx>0) - { - pit_contr_idx=1; - move16(); - } - - IF( sub(coder_type,INACTIVE) == 0 ) - { - push_indice_fx( st_fx, IND_PIT_CONTR_IDX, pit_contr_idx, 1 ); - } - } - ELSE - { - push_indice_fx( st_fx, IND_PIT_CONTR_IDX, pit_contr_idx, 3 ); - } - } - ELSE - { - push_indice_fx( st_fx, IND_PIT_CONTR_IDX, pit_contr_idx, 4 ); - } - - return last_pit_bin; - -} diff --git a/src/libs/libevs/lib_enc/evs_enc.cpp b/src/libs/libevs/lib_enc/evs_enc.cpp new file mode 100644 index 00000000..2c955283 --- /dev/null +++ b/src/libs/libevs/lib_enc/evs_enc.cpp @@ -0,0 +1,701 @@ +/*==================================================================================== + EVS Codec 3GPP TS26.443 Nov 13, 2018. Version 12.11.0 / 13.7.0 / 14.3.0 / 15.1.0 + ====================================================================================*/ + +#include "options.h" +#include "cnst.h" +#include "rom_com.h" +#include "prot.h" + +/*-------------------------------------------------------------------* +* Local functions +*-------------------------------------------------------------------*/ + +static void configure_core_coder( Encoder_State *st, short *coder_type, const short localVAD ); + +static void writeFrameHeader( Encoder_State *st ); + +static void initFrameHeader( Encoder_State *st ); + +/*-------------------------------------------------------------------* + * evs_enc() + * + * Principal encoder routine + *-------------------------------------------------------------------*/ + +void evs_enc( + Encoder_State *st, /* i/o: encoder state structure */ + const short *data, /* i : input signal */ + const short n_samples /* i : number of input samples */ +) +{ + short i, input_frame, delay; + float old_inp_12k8[L_INP_12k8], *inp; /* buffer of input signal @ 12k8 */ + float old_inp_16k[L_INP]; /* buffer of input signal @ 16kHz */ + short sp_aud_decision1; /* 1st stage speech/music classification */ + short sp_aud_decision2; /* 2nd stage speech/music classification */ + float fr_bands[2*NB_BANDS]; /* energy in frequency bands */ + short vad_flag; + short localVAD; + float Etot; /* total energy; correlation shift */ + float ener; /* residual energy from Levinson-Durbin */ + short pitch[3]; /* open-loop pitch values for quantization */ + float voicing[3]; /* OL maximum normalized correlation */ + float A[NB_SUBFR16k*(M+1)]; /* A(z) unquantized for subframes */ + float Aw[NB_SUBFR16k*(M+1)]; /* weighted A(z) unquantized for subframes */ + float epsP[M+1]; /* LP prediction errors */ + float lsp_new[M]; /* LSPs at the end of the frame */ + float lsp_mid[M]; /* ISPs in the middle of the frame */ + short coder_type; /* coder type */ + short sharpFlag; /* formant sharpening flag */ + short vad_hover_flag; + short hq_core_type; /* HQ core type (HQ, or LR-MDCT) */ + short attack_flag; /* flag signalling attack encoded by the AC mode (GSC) */ + float new_inp_resamp16k[L_FRAME16k]; /* new input signal @16kHz, non pre-emphasised, used by the WB TBE/BWE */ + float old_syn_12k8_16k[L_FRAME16k]; /* ACELP core synthesis at 12.8kHz or 16kHz to be used by the SWB BWE */ + float shb_speech[L_FRAME16k]; + float hb_speech[L_FRAME16k/4]; + float new_swb_speech[L_FRAME48k]; + float bwe_exc_extended[L_FRAME32k+NL_BUFF_OFFSET]; + float voice_factors[NB_SUBFR16k]; + float fb_exc[L_FRAME16k]; + short Voicing_flag; + float pitch_buf[NB_SUBFR16k]; + short unbits; + short padBits; + float realBuffer[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX]; /* real buffer */ + float imagBuffer[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX]; /* imag buffer */ + + + /*------------------------------------------------------------------* + * Initializiation + *-----------------------------------------------------------------*/ + + input_frame = (short)(st->input_Fs / 50); + st->core = -1; + st->extl = -1; + st->core_brate = -1; + st->input_bwidth = st->last_input_bwidth; + st->bwidth = st->last_bwidth; + hq_core_type = -1; + unbits = 0; + + st->bits_frame_core = 0; /* For getting bit consumption in core coder */ + st->lp_cng_mode2 = 0; + st->mdct_sw_enable = 0; + st->mdct_sw = 0; + st->rate_switching_reset = 0; + + /*----------------------------------------------------------------* + * set input samples buffer + *----------------------------------------------------------------*/ + + /* get delay to synchronize ACELP and MDCT frame */ + delay = NS2SA(st->input_Fs, DELAY_FIR_RESAMPL_NS); + + mvr2r( st->input - delay, st->old_input_signal, input_frame+delay ); + + /*----------------------------------------------------------------* + * convert 'short' input data to 'float' + *----------------------------------------------------------------*/ + + for( i=0; iinput[i] = (float)data[i]; + } + + if( n_samples < input_frame ) + { + set_f( st->input + n_samples, 0.0f, input_frame - n_samples ); + } + + /*----------------------------------------------------------------* + * HP filtering + *----------------------------------------------------------------*/ + + hp20( st->input, input_frame, st->mem_hp20_in, st->input_Fs ); + + /*----------------------------------------------------------------* + * Updates in case of AMR-WB IO mode -> EVS primary mode switching + *----------------------------------------------------------------*/ + + if( st->last_core == AMR_WB_CORE ) + { + updt_IO_switch_enc( st, input_frame ); + set_f( st->old_speech_shb, 0, L_LOOK_16k + L_SUBFR16k ); + cldfb_reset_memory( st->cldfbAnaEnc ); + cldfb_reset_memory( st->cldfbSynTd ); + } + + /*---------------------------------------------------------------------* + * Pre-processing + *---------------------------------------------------------------------*/ + + pre_proc( st, input_frame, st->input, old_inp_12k8, old_inp_16k, &inp, &sp_aud_decision1, + &sp_aud_decision2, fr_bands, &vad_flag, &localVAD, &Etot, &ener, pitch, voicing, + A, Aw, epsP, lsp_new, lsp_mid, &coder_type, &sharpFlag, &vad_hover_flag, + &attack_flag, new_inp_resamp16k, &Voicing_flag, realBuffer, imagBuffer, &hq_core_type ); + + st->sharpFlag = sharpFlag; + + if( st->mdct_sw == MODE2 ) + { + + st->bits_frame_nominal = st->total_brate / 50; + initFrameHeader( st ); + + writeFrameHeader( st ); + + if( (st->total_brate > ACELP_24k40 && st->total_brate < HQ_96k) || (st->total_brate == ACELP_24k40 && st->bwidth >= WB) ) + { + st->L_frame = L_FRAME16k; + st->gamma = GAMMA16k; + st->preemph_fac = PREEMPH_FAC_16k; + + weight_a_subfr( NB_SUBFR16k, A, Aw, GAMMA16k, M ); + + if( st->last_L_frame == L_FRAME && st->ini_frame != 0 ) + { + /* this is just an approximation, but it is sufficient */ + mvr2r( st->lsp_old1, st->lspold_enc, M ); + } + } + else + { + st->L_frame = L_FRAME; + st->gamma = GAMMA1; + st->preemph_fac = PREEMPH_FAC; + } + + st->sr_core = 50*st->L_frame; + st->core_brate = st->total_brate; + + st->igf = 0; + hq_core_type = NORMAL_HQ_CORE; + + if( (st->bwidth == SWB || st->bwidth == WB) && st->total_brate <= LRMDCT_CROSSOVER_POINT ) + { + /* note that FB (bit-rate >= 24400bps) is always coded with NORMAL_HQ_CORE */ + hq_core_type = LOW_RATE_HQ_CORE; + } + else if( st->bwidth == NB ) + { + hq_core_type = LOW_RATE_HQ_CORE; + } + } + + /*---------------------------------------------------------------------* + * Encoding + *---------------------------------------------------------------------*/ + + if( st->codec_mode == MODE1 ) + { + /* write signalling info into the bitstream */ + signalling_enc( st, coder_type, sharpFlag ); + + /*---------------------------------------------------------------------* + * Preprocessing (preparing) for ACELP/HQ core switching + *---------------------------------------------------------------------*/ + + core_switching_pre_enc( st, &(st->LPDmem), old_inp_12k8, old_inp_16k ); + + /*---------------------------------------------------------------------* + * ACELP core encoding + *---------------------------------------------------------------------*/ + + if( st->core == ACELP_CORE ) + { + acelp_core_enc( st, &st->LPDmem, inp, vad_flag, ener, pitch, voicing, + A, Aw, epsP, lsp_new, lsp_mid, coder_type, sharpFlag, vad_hover_flag, attack_flag, + bwe_exc_extended, voice_factors, old_syn_12k8_16k, pitch_buf, &unbits ); + } + + /*---------------------------------------------------------------------* + * HQ core encoding + *---------------------------------------------------------------------*/ + + if( st->core == HQ_CORE ) + { + hq_core_enc( st, st->input - delay, input_frame, hq_core_type, Voicing_flag ); + } + + /*---------------------------------------------------------------------* + * Postprocessing for ACELP/HQ core switching + *---------------------------------------------------------------------*/ + + core_switching_post_enc( st, old_inp_12k8, old_inp_16k, pitch, voicing, A ); + } + + else /* MODE2 */ + { + + /*----------------------------------------------------------------* + * Configuration of core coder/SID + * Write Frame Header + *----------------------------------------------------------------*/ + + configure_core_coder( st, &coder_type, localVAD ); + + if( st->mdct_sw != MODE1 ) + { + writeFrameHeader( st ); + } + + /*----------------------------------------------------------------* + * Core-Coder + *----------------------------------------------------------------*/ + + /* Call main encoding function */ + enc_acelp_tcx_main( old_inp_16k + L_INP_MEM, st, coder_type, pitch, voicing, Aw, lsp_new, + lsp_mid, st->hFdCngEnc, bwe_exc_extended, voice_factors, pitch_buf, + vad_hover_flag ); + + /*---------------------------------------------------------------------* + * Postprocessing for Mode 1/2 switching + *---------------------------------------------------------------------*/ + /* TBE for Mode 2 interface */ + if( st->igf && st->core_brate > SID_2k40 ) + { + if( st->core == ACELP_CORE ) + { + switch (st->bwidth) + { + case WB: + st->extl = WB_TBE; + st->extl_brate = WB_TBE_0k35; + break; + + case SWB: + st->extl = SWB_TBE; + st->extl_brate = SWB_TBE_1k6; + break; + + case FB: + st->extl = FB_TBE; + st->extl_brate = FB_TBE_1k8; + break; + } + } + else + { + coder_type = -1; + st->extl = IGF_BWE; + st->extl_brate = 0; + } + + st->core_brate = st->total_brate - st->extl_brate; + + if( st->tec_tfa == 1 ) + { + st->core_brate -= BITS_TEC; + st->core_brate -= BITS_TFA; + } + } + + /*----------------------------------------------------------------* + * Complete Bitstream Writing + *----------------------------------------------------------------*/ + + /* Pad the bitstream with zeros and byte-alignment*/ + if( st->igf && st->core == ACELP_CORE && st->core_brate > SID_2k40 ) + { + padBits = ((st->bits_frame+7)/8)*8 - (st->nb_bits_tot + (st->rf_target_bits_write - ((st->rf_mode==1)?1:0) ) + get_tbe_bits(st->total_brate, st->bwidth, st->rf_mode )); + } + else + { + padBits = ((st->bits_frame+7)/8)*8 - (st->nb_bits_tot + (st->rf_target_bits_write - ((st->rf_mode==1)?1:0) )); + } + + for( i = 0; iinput_Fs >= 16000 && st->bwidth < SWB ) + { + /* Common pre-processing for WB TBE and WB BWE */ + wb_pre_proc( st, new_inp_resamp16k, hb_speech ); + } + + if ( st->extl == WB_TBE ) + { + /* WB TBE encoder */ + wb_tbe_enc( st, coder_type, hb_speech, bwe_exc_extended, voice_factors, pitch_buf, voicing ); + + if( st->codec_mode == MODE2 ) + { + tbe_write_bitstream( st ); + } + } + else if ( st->extl == WB_BWE ) + { + /* WB BWE encoder */ + wb_bwe_enc( st, new_inp_resamp16k, coder_type ); + } + + /*---------------------------------------------------------------------* + * SWB(FB) TBE encoding + * SWB(FB) BWE encoding + *---------------------------------------------------------------------*/ + + if( !st->Opt_SC_VBR && st->input_Fs >= 32000 ) + { + /* Common pre-processing for SWB(FB) TBE and SWB(FB) BWE */ + swb_pre_proc( st, st->input, new_swb_speech, shb_speech, realBuffer, imagBuffer ); + } + else if( st->input_Fs >= 32000 ) + { + set_f( st->old_speech_shb, 0.0f, L_LOOK_16k + L_SUBFR16k ); + set_f( shb_speech, 0.0f, L_FRAME16k ); + } + + /* SWB TBE encoder */ + if ( st->extl == SWB_TBE || st->extl == FB_TBE || (st->igf && st->core == ACELP_CORE && st->extl != WB_TBE) ) + { + if( st->core_brate != FRAME__NO_DATA && st->core_brate != SID_2k40 ) + { + swb_tbe_enc( st, coder_type, shb_speech, bwe_exc_extended, voice_factors, fb_exc, voicing, pitch_buf ); + + if ( st->extl == FB_TBE ) + { + /* FB TBE encoder */ + fb_tbe_enc( st, st->input, fb_exc ); + } + + if( st->codec_mode == MODE2 ) + { + if( st->tec_tfa == 1 ) + { + tecEnc_TBE( &(st->tecEnc.corrFlag), voicing, coder_type); + + if( coder_type == INACTIVE ) + { + st->tec_flag = 0; + st->tecEnc.corrFlag = 0; + } + st->tfa_flag = tfaEnc_TBE( st->tfa_enr, st->last_core, voicing, pitch_buf ); + set_TEC_TFA_code( st->tecEnc.corrFlag, &st->tec_flag, &st->tfa_flag ); + } + else + { + st->tec_flag = 0; + st->tecEnc.corrFlag = 0; + st->tfa_flag = 0; + } + + tbe_write_bitstream( st ); + } + } + } + else if( st->extl == SWB_BWE || st->extl == FB_BWE ) + { + /* SWB(FB) BWE encoder */ + swb_bwe_enc( st, old_inp_12k8, old_inp_16k, old_syn_12k8_16k, new_swb_speech, shb_speech, coder_type ); + } + else if( st->extl == SWB_BWE_HIGHRATE || st->extl == FB_BWE_HIGHRATE ) + { + swb_bwe_enc_hr( st, st->input - delay, input_frame, coder_type, unbits ); + } + + + /*---------------------------------------------------------------------* + * SWB DTX/CNG encoding + *---------------------------------------------------------------------*/ + + if ( st->Opt_DTX_ON && input_frame >= L_FRAME32k ) + { + /* SHB DTX/CNG encoder */ + swb_CNG_enc( st, shb_speech, old_syn_12k8_16k ); + } + + + /*---------------------------------------------------------------------* + * Channel-aware mode - write signaling information into the bit-stream + *---------------------------------------------------------------------*/ + + signalling_enc_rf( st ); + + + /*---------------------------------------------------------------------* + * Updates - MODE1 + *---------------------------------------------------------------------*/ + + + st->last_sr_core = st->sr_core; + st->last_codec_mode = st->codec_mode; + st->last_L_frame = st->L_frame; + st->last_core = st->core; + + st->last_total_brate = st->total_brate; + st->last_core_brate = st->core_brate; + st->last_extl = st->extl; + st->last_input_bwidth = st->input_bwidth; + st->last_bwidth = st->bwidth; + st->Etot_last = Etot; + st->last_coder_type_raw = st->coder_type_raw; + + if( st->core_brate > SID_2k40 ) + { + st->last_active_brate = st->total_brate; + } + + if ( st->core == HQ_CORE ) + { + /* in the HQ core, coder_type is not used so it could have been set to anything */ + st->prev_coder_type = GENERIC; + } + else + { + st->prev_coder_type = coder_type; + } + + if( st->core_brate > SID_2k40 && st->first_CNG == 1 ) + { + if( st->act_cnt >= BUF_DEC_RATE ) + { + st->act_cnt = 0; + } + + st->act_cnt++; + + if( st->act_cnt == BUF_DEC_RATE && st->ho_hist_size > 0 ) + { + st->ho_hist_size--; + } + + if( ++(st->act_cnt2) >= MIN_ACT_CNG_UPD ) + { + st->act_cnt2 = MIN_ACT_CNG_UPD; + } + } + + if ( st->core_brate <= SID_2k40 && st->first_CNG == 0 && st->cng_type == LP_CNG ) + { + st->first_CNG = 1; + } + + /*-----------------------------------------------------------------* + * Increase the counter of initialization frames + * Limit the max number of init. frames + *-----------------------------------------------------------------*/ + + if( st->ini_frame < MAX_FRAME_COUNTER ) + { + (st->ini_frame)++; + } + + /* synchronisation of CNG seeds */ + if( st->core_brate != FRAME__NO_DATA && st->core_brate != SID_2k40 ) + { + own_random( &(st->cng_seed) ); + own_random( &(st->cng_ener_seed) ); + } + + + /*---------------------------------------------------------------------* + * Updates - MODE2 + *---------------------------------------------------------------------*/ + + if( st->mdct_sw == MODE2 ) + { + st->codec_mode = MODE2; + st->sr_core = getCoreSamplerateMode2( st->total_brate, st->bwidth, st->rf_mode ); + st->L_frame = st->sr_core / 50; + if ( st->sr_core == 12800 ) + { + st->preemph_fac = PREEMPH_FAC; + st->gamma = GAMMA1; + } + else + { + st->preemph_fac = PREEMPH_FAC_16k; + st->gamma = GAMMA16k; + } + + st->igf = getIgfPresent( st->total_brate, st->bwidth, st->rf_mode ); + } + + /* update FER clas */ + st->last_clas = st->clas; + + /* Update Core */ + core_encode_update( st ); + + if( st->mdct_sw == MODE1 ) + { + st->codec_mode = MODE1; + } + + if( st->lp_cng_mode2 ) + { + st->codec_mode = MODE2; + } + + /* RF mode updates */ + if( st->rf_mode ) + { + if (st->rf_frame_type == RF_NELP ) + { + st->last_nelp_mode = 1; + } + else + { + st->last_nelp_mode = 0; + } + } + st->rf_mode_last = st->rf_mode; + if( st->Opt_RF_ON ) + { + st->L_frame = L_FRAME; + st->rf_mode = 1; + } + + + + + return; +} + + +/*-------------------------------------------------------------------* + * initFrameHeader() + * + * Init Mode 2 frame header + *-------------------------------------------------------------------*/ + +static void initFrameHeader( + Encoder_State *st /* i/o: encoder state structure */ +) +{ + + int n; + + if( st->core_brate == SID_2k40 ) + { + /*Get size of frame*/ + st->bits_frame = FRAME_2_4; + st->bits_frame_core += FRAME_2_4-4; /*1 bit for SID on/off + 2 bits for bandwith in case of SID + 1 bit CNG type */ + st->frame_size_index = 2; + } + else if( st->core_brate == FRAME__NO_DATA ) + { + st->bits_frame = FRAME_0; + st->bits_frame_core += st->bits_frame; + st->frame_size_index = 0; + } + else + { + for( n=0; nbits_frame_nominal ) + { + st->frame_size_index = n; + st->bits_frame = FrameSizeConfig[n].frame_bits; + st->bits_frame_core = FrameSizeConfig[n].frame_net_bits; + break; + } + } + } + + return; +} + +/*-------------------------------------------------------------------* + * writeFrameHeader() + * + * Write Mode 2 frame header + *-------------------------------------------------------------------*/ + +static void writeFrameHeader( + Encoder_State *st /* i/o: encoder state structure */ +) +{ + + if( st->core_brate != FRAME__NO_DATA ) + { + /* SID flag at 2.4kbps */ + if( st->core_brate == SID_2k40 ) + { + if ( st->cng_type == FD_CNG ) + { + /* write SID/CNG type flag */ + push_next_indice( st, 1, 1 ); + + /* write bandwidth mode */ + push_next_indice( st, st->bwidth, 2 ); + + /* write L_frame */ + if( st->L_frame == L_FRAME ) + { + push_next_indice( st, 0, 1 ); + } + else + { + push_next_indice( st, 1, 1 ); + } + } + } + else /* active frames */ + { + if( st->rf_mode == 0 ) + { + push_next_indice( st, st->bwidth-FrameSizeConfig[st->frame_size_index].bandwidth_min, FrameSizeConfig[st->frame_size_index].bandwidth_bits); + } + } + + /* Write reserved bit */ + if( FrameSizeConfig[st->frame_size_index].reserved_bits && st->rf_mode == 0) + { + push_next_indice( st, 0, FrameSizeConfig[st->frame_size_index].reserved_bits ); + } + } + + return; +} + + +/*------------------------------------------------------------------------* + * Configuration of core coder/SID + *------------------------------------------------------------------------*/ + +static void configure_core_coder( + Encoder_State *st, /* i/o: encoder state structure */ + short *coder_type, /* i : coder type */ + const short localVAD +) +{ + initFrameHeader( st ); + + if( st->core_brate != SID_2k40 && st->core_brate != FRAME__NO_DATA ) + { + if( st->tcxonly ) + { + *coder_type = GENERIC; + } + + st->tcx_cfg.coder_type = *coder_type; + + + if( !st->tcxonly && !localVAD && st->tcx_cfg.coder_type == GENERIC ) + { + st->tcx_cfg.coder_type = UNVOICED; + } + } + + st->igf = getIgfPresent( st->total_brate, st->bwidth, st->rf_mode ); + + if( st->core_brate != SID_2k40 && st->core_brate != FRAME__NO_DATA ) + { + st->core_brate = st->total_brate; + } + + return; +} diff --git a/src/libs/libevs/lib_enc/evs_enc_fx.cpp b/src/libs/libevs/lib_enc/evs_enc_fx.cpp deleted file mode 100755 index 1aa0919b..00000000 --- a/src/libs/libevs/lib_enc/evs_enc_fx.cpp +++ /dev/null @@ -1,804 +0,0 @@ -/*==================================================================================== - EVS Codec 3GPP TS26.442 Apr 03, 2018. Version 12.11.0 / 13.6.0 / 14.2.0 - ====================================================================================*/ - -#include -#include -#include "options.h" /* Compilation switches */ -#include "prot_fx.h" -#include "cnst_fx.h" /* Common constants */ -#include "stl.h" /* Debug prototypes */ -#include "rom_com_fx.h" /* Common constants */ - -static void initFrameHeader_loc( Encoder_State_fx *st ); -static void writeFrameHeader_loc( Encoder_State_fx *st ); -static void configure_core_coder_loc( Encoder_State_fx *st, Word16 *coder_type,const Word16 localVAD); - -/*-------------------------------------------------------------------* - * evs_enc() - * - * Principal encoder routine - *-------------------------------------------------------------------*/ - -void evs_enc_fx( - Encoder_State_fx *st, /* i/o: encoder state structure */ - const Word16 *data, /* i : input signal */ - const Word16 n_samples /* i : number of input samples */ -) -{ - Word16 i, input_frame, delay; - Word16 old_inp_12k8[L_INP_12k8], *inp = 0; /* buffer of input signal @ 12k8 */ - Word16 old_inp_16k[L_INP]; /* buffer of input signal @ 16kHz */ - Word16 sp_aud_decision1; /* 1st stage speech/music classification */ - Word16 sp_aud_decision2; /* 2nd stage speech/music classification */ - Word32 fr_bands[2*NB_BANDS]; /* energy in frequency bands */ - Word16 vad_flag; - Word16 localVAD; - Word16 Etot; /* total energy; correlation shift */ - Word32 ener; /* residual energy from Levinson-Durbin */ - Word16 pitch[3]; /* open-loop pitch values for quantization */ - Word16 voicing[3]; /* OL maximum normalized correlation */ - Word16 A[NB_SUBFR16k*(M+1)]; /* A(z) unquantized for subframes */ - Word16 Aw[NB_SUBFR16k*(M+1)]; /* weighted A(z) unquantized for subframes */ - Word16 epsP_h[M+1]; /* LP prediction errors */ - Word16 epsP_l[M+1]; /* LP prediction errors */ - Word32 epsP[M+1]; /* LP prediction errors */ - Word16 lsp_new[M]; /* LSPs at the end of the frame */ - Word16 lsp_mid[M]; /* ISPs in the middle of the frame */ - Word16 coder_type; /* coder type */ - Word16 sharpFlag; /* formant sharpening flag */ - Word16 vad_hover_flag; - Word16 hq_core_type; /* HQ core type (HQ, or LR-MDCT) */ - - Word16 attack_flag; /* flag signalling attack encoded by the AC mode (GSC) */ - Word16 new_inp_resamp16k[L_FRAME16k]; /* new input signal @16kHz, non pre-emphasised, used by the WB TBE/BWE */ - Word16 old_syn_12k8_16k[L_FRAME16k]; /* ACELP core synthesis at 12.8kHz or 16kHz to be used by the SWB BWE */ - Word16 shb_speech[L_FRAME16k]; - Word16 hb_speech[L_FRAME16k/4]; - Word16 new_swb_speech[L_FRAME48k]; - Word32 bwe_exc_extended[L_FRAME32k + NL_BUFF_OFFSET]; /* non-linear bandwidth extension buffer */ - Word16 voice_factors[NB_SUBFR16k]; - Word16 fb_exc[L_FRAME16k]; - Word16 Voicing_flag; - Word16 pitch_buf[NB_SUBFR16k]; - Word16 unbits; - - Word16 padBits; - Word32 realBuffer[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX]; /* real buffer */ - Word32 imagBuffer[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX]; /* imag buffer */ - CLDFB_SCALE_FACTOR cldfbScale; - Word16 Q_new, shift, Q_synth; - Word16 Q_r[2]; - Word16 Q_shb_spch, Q_fb_exc; - Word32 L_tmp; - UWord16 lsb; - Word16 tmp; - - Q_shb_spch = 0; - move16(); /* to avoid compiler warnings */ - - - - - /*------------------------------------------------------------------* - * Initializiation - *-----------------------------------------------------------------*/ - - input_frame = st->input_frame_fx; - move16(); - st->core_fx = -1; - move16(); - st->extl_fx = -1; - move16(); - st->core_brate_fx = -1; - move32(); - st->input_bwidth_fx = st->last_input_bwidth_fx; - move16(); - st->bwidth_fx = st->last_bwidth_fx; - move16(); - hq_core_type = -1; - move16(); - unbits = 0; - move16(); - - st->bits_frame_core = 0; - move16(); /* For getting bit consumption in core coder */ - st->lp_cng_mode2 = 0; - move16(); - st->mdct_sw_enable = 0; - move16(); - st->mdct_sw = 0; - move16(); - shift = st->old_wsp_shift; - move16(); - st->rate_switching_reset = 0; - move16(); - - /*----------------------------------------------------------------* - * set input samples buffer - *----------------------------------------------------------------*/ - - /* get delay to synchronize ACELP and MDCT frame */ - delay = NS2SA_fx2(st->input_Fs_fx, DELAY_FIR_RESAMPL_NS); - - Copy( st->input - delay, st->old_input_signal_fx, input_frame+delay ); - - /*----------------------------------------------------------------* - * convert 'short' input data to 'float' - *----------------------------------------------------------------*/ - - Copy(data, st->input, input_frame); - IF( sub(n_samples,input_frame) < 0) - { - set16_fx( st->input + n_samples, 0, sub(input_frame, n_samples) ); - } - - /*----------------------------------------------------------------* - * HP filtering - *----------------------------------------------------------------*/ - - hp20( st->input, 1, input_frame, st->mem_hp20_in_fx, st->input_Fs_fx ); - - /*----------------------------------------------------------------* - * Updates in case of AMR-WB IO mode -> EVS primary mode switching - *----------------------------------------------------------------*/ - - IF( sub(st->last_core_fx, AMR_WB_CORE) == 0 ) - { - updt_IO_switch_enc_fx( st, input_frame ); - set16_fx(st->old_speech_shb_fx, 0, L_LOOK_16k + L_SUBFR16k); - cldfb_reset_memory( st->cldfbAna_Fx ); - cldfb_reset_memory( st->cldfbSyn_Fx ); - } - - /*---------------------------------------------------------------------* - * Pre-processing - *---------------------------------------------------------------------*/ - - pre_proc_fx( st, input_frame, st->input, old_inp_12k8, old_inp_16k, &inp, &sp_aud_decision1, - &sp_aud_decision2, fr_bands, &vad_flag, &localVAD, &Etot, &ener, pitch, voicing, - A, Aw, epsP_h, epsP_l, epsP, lsp_new, lsp_mid, &coder_type, &sharpFlag, &vad_hover_flag, - &attack_flag, new_inp_resamp16k, &Voicing_flag, realBuffer, imagBuffer, &cldfbScale, st->LPDmem.old_exc, - &hq_core_type, - &Q_new, &shift, Q_r ); - - st->sharpFlag = sharpFlag; - - IF (sub(st->mdct_sw,MODE2) == 0) - { - - Mpy_32_16_ss(st->total_brate_fx, 5243, &L_tmp, &lsb); /* 5243 is 1/50 in Q18. (0+18-15=3) */ - st->bits_frame_nominal = extract_l(L_shr(L_tmp, 3)); /* Q0 */ - - initFrameHeader_loc( st ); - writeFrameHeader_loc( st ); - - test(); - test(); - test(); - IF ((L_sub(st->total_brate_fx,ACELP_24k40) > 0 && L_sub(st->total_brate_fx,HQ_96k) < 0) || (L_sub(st->total_brate_fx,ACELP_24k40) == 0 && sub(st->bwidth_fx,WB) >= 0)) - { - st->L_frame_fx = L_FRAME16k; - move16(); - st->gamma = GAMMA16k; - move16(); - st->preemph_fac = PREEMPH_FAC_16k; - move16(); - - weight_a_subfr_fx( NB_SUBFR16k, A, Aw, GAMMA16k, M ); - test(); - IF (sub(st->last_L_frame_fx,L_FRAME) == 0 && st->ini_frame_fx != 0) - { - /* this is just an approximation, but it is sufficient */ - Copy( st->lsp_old1_fx, st->lspold_enc_fx, M ); - } - } - ELSE - { - st->L_frame_fx = L_FRAME; - move16(); - st->gamma = GAMMA1; - move16(); - st->preemph_fac = PREEMPH_FAC; - move16(); - } - - st->sr_core = L_mult0(50,st->L_frame_fx); - st->core_brate_fx = st->total_brate_fx; - move32(); - - st->igf = 0; - move16(); - hq_core_type = NORMAL_HQ_CORE; - move16(); - test(); - test(); - IF( (sub(st->bwidth_fx,SWB) == 0 || sub(st->bwidth_fx,WB) == 0) && L_sub(st->total_brate_fx,LRMDCT_CROSSOVER_POINT) <= 0 ) - { - /* note that FB (bit-rate >= 24400bps) is always coded with NORMAL_HQ_CORE */ - hq_core_type = LOW_RATE_HQ_CORE; - move16(); - } - ELSE IF( sub(st->bwidth_fx,NB) == 0 ) - { - hq_core_type = LOW_RATE_HQ_CORE; - move16(); - } - } - - IF( sub(st->codec_mode,MODE1) == 0 ) - { - /*---------------------------------------------------------------------* - * Write signalling info into the bitstream - *---------------------------------------------------------------------*/ - - signalling_enc_fx( st, coder_type, sharpFlag ); - - /*---------------------------------------------------------------------* - * Preprocessing (preparing) for ACELP/HQ core switching - *---------------------------------------------------------------------*/ - - core_switching_pre_enc_fx( st,&(st->LPDmem), old_inp_12k8, old_inp_16k); - - /*---------------------------------------------------------------------* - * ACELP core encoding - *---------------------------------------------------------------------*/ - - IF( sub(st->core_fx,ACELP_CORE) == 0 ) - { - acelp_core_enc_fx( st, &(st->LPDmem), inp, vad_flag, ener, - pitch, voicing, A, Aw, epsP_h, epsP_l, lsp_new, lsp_mid, coder_type, sharpFlag, vad_hover_flag, - attack_flag, bwe_exc_extended, voice_factors, old_syn_12k8_16k, pitch_buf, &unbits, Q_new, shift ); - } - - /*---------------------------------------------------------------------* - * HQ core encoding - *---------------------------------------------------------------------*/ - - IF( sub(st->core_fx,HQ_CORE) == 0 ) - { - hq_core_enc_fx( st, st->input - delay, input_frame, hq_core_type, Voicing_flag); - } - - /*---------------------------------------------------------------------* - * Postprocessing for ACELP/HQ core switching - *---------------------------------------------------------------------*/ - core_switching_post_enc_fx( st, old_inp_12k8, old_inp_16k, pitch, voicing, - A, shift, Q_new, st->Q_syn2, &Q_synth ); - } - ELSE /* MODE2 */ - { - /*----------------------------------------------------------------* - * Configuration of core coder/SID - * Write Frame Header - *----------------------------------------------------------------*/ - - configure_core_coder_loc( st, &coder_type, localVAD ); - - IF (st->mdct_sw != MODE1) - { - writeFrameHeader_loc( st ); - } - - /*----------------------------------------------------------------* - * Core-Coder - *----------------------------------------------------------------*/ - - /* Call main encoding function */ - enc_acelp_tcx_main( old_inp_16k + L_INP_MEM, st, coder_type, pitch, voicing, Aw, lsp_new, lsp_mid, - st->hFdCngEnc_fx, bwe_exc_extended, voice_factors, pitch_buf - , vad_hover_flag, &Q_new, &shift ); - - /*---------------------------------------------------------------------* - * Postprocessing for codec switching - *---------------------------------------------------------------------*/ - /* TBE interface */ - test(); - IF ( st->igf != 0 && L_sub(st->core_brate_fx,SID_2k40) > 0 ) - { - IF( sub(st->core_fx,ACELP_CORE) == 0 ) - { - SWITCH (st->bwidth_fx) - { - case WB: - st->extl_fx = WB_TBE; - move16(); - st->extl_brate_fx = WB_TBE_0k35; - move32(); - BREAK; - - case SWB: - st->extl_fx = SWB_TBE; - move16(); - st->extl_brate_fx = SWB_TBE_1k6; - move32(); - BREAK; - - case FB: - st->extl_fx = FB_TBE; - move16(); - st->extl_brate_fx = FB_TBE_1k8; - move32(); - BREAK; - } - } - ELSE - { - coder_type = -1; - move16(); - st->extl_fx = IGF_BWE; - move16(); - st->extl_brate_fx = 0; - move32(); - } - - st->core_brate_fx = L_sub(st->total_brate_fx, st->extl_brate_fx); - - IF( sub(st->tec_tfa, 1) == 0 ) - { - st->core_brate_fx = L_sub(st->core_brate_fx, BITS_TEC); - st->core_brate_fx = L_sub(st->core_brate_fx, BITS_TFA); - } - } - - /*----------------------------------------------------------------* - * Complete Bitstream Writing - *----------------------------------------------------------------*/ - - padBits = 0; - - test(); - test(); - IF( st->igf != 0 && sub(st->core_fx,ACELP_CORE) == 0 && L_sub(st->core_brate_fx,SID_2k40) > 0 ) - { - /* padBits = ((st->bits_frame+7)/8)*8 - (st->nb_bits_tot + (st->rf_target_bits_write - ((st->Opt_RF_ON==1)?1:0) ) + get_tbe_bits(st->total_brate, st->bwidth, st->rf_mode )); */ - tmp = add(get_tbe_bits_fx(st->total_brate_fx, st->bwidth_fx, st->rf_mode), sub(st->rf_target_bits_write, st->rf_mode)); - padBits = sub(sub(shl(shr(add(st->bits_frame,7),3),3), st->nb_bits_tot_fx), tmp); - } - ELSE - { - /* padBits = ((st->bits_frame+7)/8)*8 - (st->nb_bits_tot + (st->rf_target_bits_write - ((st->Opt_RF_ON==1)?1:0) )); */ - tmp = sub(st->rf_target_bits_write, st->rf_mode); - padBits = sub(shl(shr(add(st->bits_frame,7),3),3), add(st->nb_bits_tot_fx, tmp)); - } - - FOR( i = 0; iinput_Fs_fx,16000 ) >= 0 && (sub(st->bwidth_fx, SWB) < 0) ) - { - /* Common pre-processing for WB TBE and WB BWE */ - wb_pre_proc_fx( st, new_inp_resamp16k, hb_speech ); - /* o: new_inp_resamp16k at Q = -1 */ - } - - IF ( sub(st->extl_fx,WB_TBE) == 0 ) - { - /* WB TBE encoder */ - wb_tbe_enc_fx( st, coder_type, hb_speech, bwe_exc_extended, Q_new, voice_factors, pitch_buf, voicing); - - IF( sub(st->codec_mode,MODE2) == 0 ) - { - tbe_write_bitstream_fx( st ); - } - } - ELSE IF ( sub(st->extl_fx, WB_BWE) == 0 ) - { - /* WB BWE encoder */ - wb_bwe_enc_fx( st, new_inp_resamp16k, coder_type ); - - } - - /*---------------------------------------------------------------------* - * SWB(FB) TBE encoding - * SWB BWE encoding - *---------------------------------------------------------------------*/ - test(); - IF (!st->Opt_SC_VBR_fx && L_sub(st->input_Fs_fx,32000) >= 0 ) - { - /* Common pre-processing for SWB(FB) TBE and SWB BWE */ - swb_pre_proc_fx(st, st->input, new_swb_speech, shb_speech, &Q_shb_spch, realBuffer, imagBuffer, &cldfbScale ); - } - ELSE IF( L_sub(st->input_Fs_fx,32000) >= 0 ) - { - set16_fx( st->old_speech_shb_fx, 0, L_LOOK_16k + L_SUBFR16k ); - set16_fx( shb_speech, 0, L_FRAME16k ); - } - - /* SWB TBE encoder */ - test(); - test(); - test(); - test(); - test(); - test(); - IF ( sub(st->extl_fx, SWB_TBE) == 0 || sub(st->extl_fx, FB_TBE) == 0 || ( st->igf != 0 && sub(st->core_fx, ACELP_CORE) == 0 && sub(st->extl_fx, WB_TBE) != 0 ) ) - { - test(); - IF( L_sub(st->core_brate_fx,FRAME_NO_DATA) != 0 && L_sub(st->core_brate_fx,SID_2k40) != 0 ) - { - swb_tbe_enc_fx( st, coder_type, shb_speech, bwe_exc_extended, voice_factors, fb_exc, &Q_fb_exc, Q_new, Q_shb_spch, voicing, pitch_buf ); - - IF ( sub(st->extl_fx,FB_TBE) == 0 ) - { - /* FB TBE encoder */ - fb_tbe_enc_fx( st, st->input, fb_exc, Q_fb_exc ); - } - - IF( sub(st->codec_mode,MODE2) == 0 ) - { - IF( sub(st->tec_tfa, 1) == 0 ) - { - tecEnc_TBE_fx(&st->tecEnc.corrFlag, voicing, coder_type); - - IF( sub(coder_type, INACTIVE) == 0 ) - { - st->tec_flag = 0; - move16(); - st->tecEnc.corrFlag = 0; - move16(); - } - st->tfa_flag = tfaEnc_TBE_fx( st->tfa_enr, st->last_core_fx, voicing, pitch_buf, shl(Q_shb_spch, 1)); - set_TEC_TFA_code_fx( st->tecEnc.corrFlag, &st->tec_flag, &st->tfa_flag ); - } - ELSE - { - st->tec_flag = 0; - move16(); - st->tecEnc.corrFlag = 0; - move16(); - st->tfa_flag = 0; - move16(); - } - - tbe_write_bitstream_fx( st ); - } - } - } - ELSE IF ( sub(st->extl_fx,SWB_BWE) == 0 || sub(st->extl_fx,FB_BWE) == 0 ) - { - /* SWB BWE encoder */ - swb_bwe_enc_fx( st, old_inp_12k8, old_inp_16k, old_syn_12k8_16k, new_swb_speech, shb_speech, coder_type, Q_shb_spch, sub(Q_new, 1) ); - } - ELSE IF( sub(st->extl_fx,SWB_BWE_HIGHRATE) == 0 || sub(st->extl_fx,FB_BWE_HIGHRATE) == 0 ) - { - /* SWB HR BWE encoder */ - swb_bwe_enc_hr_fx(st, st->input - delay, st->Q_syn2, input_frame, coder_type, unbits ); - } - - /*---------------------------------------------------------------------* - * SWB DTX/CNG encoding - *---------------------------------------------------------------------*/ - - test(); - IF ( st->Opt_DTX_ON_fx && sub(input_frame,L_FRAME32k) >= 0 ) - { - swb_CNG_enc_fx( st, shb_speech, old_syn_12k8_16k ); - } - - /*---------------------------------------------------------------------* - * Channel-aware mode - write signaling information into the bit-stream - *---------------------------------------------------------------------*/ - - signalling_enc_rf( st ); - - /*---------------------------------------------------------------------* - * Updates - MODE1 - *---------------------------------------------------------------------*/ - - st->last_sr_core = st->sr_core; - move16(); - st->last_codec_mode = st->codec_mode; - move16(); - st->last_L_frame_fx = st->L_frame_fx; - move16(); - st->last_core_fx = st->core_fx; - move16(); - - st->last_total_brate_fx = st->total_brate_fx; - move32(); - st->last_core_brate_fx = st->core_brate_fx; - move32(); - st->last_extl_fx = st->extl_fx; - move16(); - st->last_input_bwidth_fx = st->input_bwidth_fx; - move16(); - st->last_bwidth_fx = st->bwidth_fx; - move16(); - st->Etot_last_fx = Etot; - move16(); - st->last_coder_type_raw_fx = st->coder_type_raw_fx; - move16(); - - st->prev_Q_new = Q_new; - - if( L_sub(st->core_brate_fx,SID_2k40) > 0 ) - { - st->last_active_brate_fx = st->total_brate_fx; - move32(); - } - IF ( sub(st->core_fx,HQ_CORE) == 0 ) - { - /* in the HQ core, coder_type is not used so it could have been set to anything */ - st->prev_coder_type_fx = GENERIC; - } - ELSE - { - st->prev_coder_type_fx = coder_type; - } - - test(); - IF( L_sub(st->core_brate_fx,SID_2k40) > 0 && sub(st->first_CNG_fx,1) == 0 ) - { - if( sub(st->act_cnt_fx,BUF_DEC_RATE) >= 0 ) - { - st->act_cnt_fx = 0; - move16(); - } - - st->act_cnt_fx = add(st->act_cnt_fx,1); - - test(); - if( sub(st->act_cnt_fx,BUF_DEC_RATE) == 0 && st->ho_hist_size_fx > 0 ) - { - st->ho_hist_size_fx = sub(st->ho_hist_size_fx,1); - } - - st->act_cnt2_fx = add(st->act_cnt2_fx,1); - if( sub(st->act_cnt2_fx,MIN_ACT_CNG_UPD) >= 0 ) - { - st->act_cnt2_fx = MIN_ACT_CNG_UPD; - move16(); - } - } - - test(); - test(); - if ( L_sub(st->core_brate_fx,SID_2k40) <= 0 && st->first_CNG_fx == 0 && sub(st->cng_type_fx,LP_CNG) == 0 ) - { - st->first_CNG_fx = 1; - move16(); - } - - /*-----------------------------------------------------------------* - * Increase the counter of initialization frames - * Limit the max number of init. frames - *-----------------------------------------------------------------*/ - - if( sub(st->ini_frame_fx,MAX_FRAME_COUNTER) < 0 ) - { - st->ini_frame_fx = add(st->ini_frame_fx, 1); - } - - /* synchronisation of CNG seeds */ - test(); - IF( L_sub(st->core_brate_fx,FRAME_NO_DATA) != 0 && L_sub(st->core_brate_fx, SID_2k40) != 0 ) - { - Random( &(st->cng_seed_fx) ); - Random( &(st->cng_ener_seed_fx) ); - } - - - /*---------------------------------------------------------------------* - * Updates - MODE2 - *---------------------------------------------------------------------*/ - IF( sub(st->mdct_sw,MODE2) == 0 ) - { - st->codec_mode = MODE2; - move16(); - st->sr_core = getCoreSamplerateMode2( st->total_brate_fx, st->bwidth_fx, st->rf_mode); - Mpy_32_16_ss(st->sr_core, 5243, &L_tmp, &lsb); /* 5243 is 1/50 in Q18. (0+18-15=3) */ - st->L_frame_fx = extract_l(L_shr(L_tmp, 3)); /* Q0 */ - assert(st->L_frame_fx == st->sr_core / 50); - IF ( L_sub(st->sr_core,12800) == 0 ) - { - st->preemph_fac = PREEMPH_FAC; - move16(); - st->gamma = GAMMA1; - move16(); - } - ELSE - { - st->preemph_fac = PREEMPH_FAC_16k; - move16(); - st->gamma = GAMMA16k; - move16(); - } - st->igf = getIgfPresent(st->total_brate_fx, st->bwidth_fx, st->rf_mode); - } - - /* update FER clas */ - st->last_clas_fx = st->clas_fx; - - core_encode_update( st ); - if( sub(st->mdct_sw,MODE1) == 0 ) - { - st->codec_mode = MODE1; - move16(); - } - if( st->lp_cng_mode2 ) - { - st->codec_mode = MODE2; - move16(); - } - - IF (sub(st->rf_mode,1)==0 ) - { - IF (sub(st->rf_frame_type,RF_NELP) == 0) - { - st->last_nelp_mode_fx = 1; - } - ELSE - { - st->last_nelp_mode_fx = 0; - } - } - - /* RF mode updates */ - st->rf_mode_last = st->rf_mode; - IF(sub(st->Opt_RF_ON,1)==0) - { - st->L_frame_fx = L_FRAME; - st->rf_mode = 1; - } - - - - return; -} - - -/*-------------------------------------------------------------------* - * initFrameHeader() - * - * Initialize MODE2 frame header - *-------------------------------------------------------------------*/ -static void initFrameHeader_loc( Encoder_State_fx *st ) -{ - - Word16 n; - - IF( L_sub(st->core_brate_fx, SID_2k40) == 0 ) - { - /*Get size of frame*/ - st->bits_frame = FRAME_2_4; - move16(); - st->bits_frame_core = add(st->bits_frame_core, FRAME_2_4-4); /*1 bit for SID on/off + 3 bits for bandwith in case of SID.*/ - st->frame_size_index = 2; - move16(); - } - ELSE IF( L_sub(st->core_brate_fx,FRAME_NO_DATA) == 0 ) - { - st->bits_frame = FRAME_0; - move16(); - st->bits_frame_core = add(st->bits_frame_core,st->bits_frame); - st->frame_size_index = 0; - move16(); - } - ELSE - { - FOR( n=0; nbits_frame_nominal) == 0 ) - { - st->frame_size_index = n; - move16(); - st->bits_frame = FrameSizeConfig[n].frame_bits; - move16(); - st->bits_frame_core = FrameSizeConfig[n].frame_net_bits; - move16(); - BREAK; - } - } - } - - return; -} - -/*-------------------------------------------------------------------* - * writeFrameHeader() - * - * Write MODE2 frame header - *-------------------------------------------------------------------*/ -static void writeFrameHeader_loc( Encoder_State_fx *st ) -{ - - IF( L_sub(st->core_brate_fx,FRAME_NO_DATA) != 0 ) - { - /* SID flag at 2.4kbps */ - IF( L_sub(st->core_brate_fx,SID_2k40) == 0 ) - { - IF ( sub(st->cng_type_fx,FD_CNG) == 0 ) - { - /* write SID/CNG type flag */ - push_next_indice_fx( st, 1, 1 ); - - /* write bandwidth mode */ - push_next_indice_fx( st, st->bwidth_fx, 2 ); - - /* write L_frame */ - IF( sub(st->L_frame_fx,L_FRAME) == 0 ) - { - push_next_indice_fx( st, 0, 1 ); - } - ELSE - { - push_next_indice_fx( st, 1, 1 ); - } - } - } - ELSE /* active frames */ - { - IF(st->rf_mode == 0) - { - push_next_indice_fx( st, sub(st->bwidth_fx,FrameSizeConfig[st->frame_size_index].bandwidth_min), FrameSizeConfig[st->frame_size_index].bandwidth_bits); - } - } - - /* Write reserved bit */ - test(); - IF( FrameSizeConfig[st->frame_size_index].reserved_bits && st->rf_mode == 0) - { - push_next_indice_fx( st, 0, FrameSizeConfig[st->frame_size_index].reserved_bits ); - } - } - - return; -} - -/*------------------------------------------------------------------------* -* Configuration of core coder/SID -*------------------------------------------------------------------------*/ - -static void configure_core_coder_loc( - Encoder_State_fx *st, /* i/o: encoder state structure */ - Word16 *coder_type, /* i : coder type */ - const Word16 localVAD -) -{ - - initFrameHeader_loc( st ); - - test(); - IF( L_sub(st->core_brate_fx, SID_2k40) != 0 && L_sub(st->core_brate_fx, FRAME_NO_DATA) != 0 ) - { - if( st->tcxonly ) - { - *coder_type = GENERIC; - move16(); - } - - st->tcx_cfg.coder_type = *coder_type; - move16(); - - - test(); - test(); - if( !st->tcxonly && !localVAD && sub(st->tcx_cfg.coder_type,GENERIC) == 0 ) - { - st->tcx_cfg.coder_type = UNVOICED; - move16(); - } - } - - st->igf = getIgfPresent(st->total_brate_fx, st->bwidth_fx, st->rf_mode); - - test(); - if( L_sub(st->core_brate_fx,SID_2k40) != 0 && L_sub(st->core_brate_fx,FRAME_NO_DATA) != 0 ) - { - st->core_brate_fx = st->total_brate_fx; - move32(); - } - - return; -} diff --git a/src/libs/libevs/lib_enc/ext_sig_ana.cpp b/src/libs/libevs/lib_enc/ext_sig_ana.cpp old mode 100755 new mode 100644 index 077cf2c9..fc90a1c1 --- a/src/libs/libevs/lib_enc/ext_sig_ana.cpp +++ b/src/libs/libevs/lib_enc/ext_sig_ana.cpp @@ -1,163 +1,87 @@ /*==================================================================================== - EVS Codec 3GPP TS26.442 Apr 03, 2018. Version 12.11.0 / 13.6.0 / 14.2.0 + EVS Codec 3GPP TS26.443 Nov 13, 2018. Version 12.11.0 / 13.7.0 / 14.3.0 / 15.1.0 ====================================================================================*/ #include +#include #include -#include "prot_fx.h" -#include "stl.h" -#include "basop_util.h" +#include "options.h" +#include "prot.h" +#include "rom_com.h" +/*-------------------------------------------------------------------* +* core_signal_analysis_high_bitrate() +* +* +*-------------------------------------------------------------------*/ -/*-------------------------------------------------------------- - * Main Functions - *--------------------------------------------------------------*/ - -void core_signal_analysis_high_bitrate( const Word16 *new_samples, /*i: 0Q15*/ - const Word16 T_op[3], /* i : open-loop pitch values for quantiz. */ - const Word16 voicing[3], /* i : open-loop pitch gains */ - const Word16 pitch[2], - Word16 Aw[NB_SUBFR16k*(M+1)],/* i : weighted A(z) unquant. for subframes*/ - Word16 lsp_new[], - Word16 lsp_mid[], - Encoder_State_fx *st, - Word16 pTnsSize[], - Word16 pTnsBits[], - Word16 param_core[], - Word16 *ltpBits, - Word16 L_frame, - Word16 L_frameTCX, - Word32 **spectrum, - Word16 *spectrum_e, - Word16 *Q_new, - Word16 *shift - ) +void core_signal_analysis_high_bitrate( + const float *new_samples, + const short T_op[3], /* i : open-loop pitch values for quantiz. */ + const float voicing[3], /* i : open-loop pitch gains */ + const short pitch[2], /* i : open-loop pitch @12.8kHz for adapt. lag windowing */ + float lsp_new[], + float lsp_mid[], + Encoder_State *st, + int pTnsSize[], + int pTnsBits[], + int param_core[], + int *ltpBits, + int L_frame, + int L_frameTCX +) { - const Word16 last_overlap = st->tcx_cfg.tcx_last_overlap_mode; - const Word16 curr_overlap = st->tcx_cfg.tcx_curr_overlap_mode; - Word16 i, frameno; - Word16 L_subframe; - Word16 left_overlap, right_overlap, folding_offset; - Word32 buf[N_MAX]; /* Buffer for TCX20/TCX10 windowing, power spectrum */ - Word16 A[M+1]; - Word16 mdstWin[N_MAX+L_MDCT_OVLP_MAX]; /* Buffer for MDST windowing */ - Word16 * pMdstWin; - Word16 lpc_left_overlap_mode, lpc_right_overlap_mode; - Word16 * tcx20Win = (Word16*)buf; - Word32 powerSpec[N_MAX]; - Word16 powerSpec_e; - Word32 interleaveBuf[N_TCX10_MAX]; - Word16 *tcx5Win = (Word16*)interleaveBuf; /* Buffer for TCX5 windowing and interleaving. */ - Word16 r_h[NB_DIV][M+1], r_l[NB_DIV][M+1]; - Word32 r[M+1], epsP[M+1]; - Word16 *lsp[2]; - Word8 tmp8; - Word16 alw_pitch_lag_12k8[2], alw_pitch_lag_12k8_wc; - Word16 alw_voicing[2], alw_voicing_wc; - Word16 nSubframes; - Word16 overlap_mode[3]; - Word16 transform_type[2]; - Word16 tcx10SizeFB; - Word16 tcx5SizeFB; - Word16 tcx10Size; - Word16 tmp, *tmpP16; - Word32 *tmpP32; - Word16 Q_exp; + const int last_overlap = st->tcx_cfg.tcx_last_overlap_mode; + const int curr_overlap = st->tcx_cfg.tcx_curr_overlap_mode; + int i, frameno; + int L_subframe; + int left_overlap=-1, right_overlap=-1, folding_offset; + float buf[N_MAX+L_MDCT_OVLP_MAX]; /* Buffer for TCX20/TCX10 windowing */ + float mdstWin[N_MAX+L_MDCT_OVLP_MAX]; /* Buffer for MDST windowing */ + float * powerSpec; + float * tcx20Win; + float tcx5Win[N_TCX10_MAX/2+L_MDCT_OVLP_MAX]; /* Buffer for TCX5 windowing and interleaving. */ + float * interleaveBuf = tcx5Win; + int nSubframes; + short overlap_mode[3]; + short transform_type[2]; + float r[M+1]; + float A[M+1]; + float * lsp[2]; + const int tcx10SizeFB = 2*st->tcx_cfg.tcx5SizeFB; + const int tcx5SizeFB = st->tcx_cfg.tcx5SizeFB; + const int tcx10Size = 2*st->tcx_cfg.tcx5Size; + short alw_pitch_lag_12k8[2], alw_pitch_lag_12k8_wc; + float alw_voicing[2], alw_voicing_wc; - - (void)Aw; - (void)shift; - - left_overlap = -1; - move16(); - right_overlap = -1; - move16(); - - tcx10SizeFB = shl(st->tcx_cfg.tcx5SizeFB, 1); - tcx5SizeFB = st->tcx_cfg.tcx5SizeFB; - move16(); - tcx10Size = shl(st->tcx_cfg.tcx5Size, 1); + powerSpec = tcx20Win = buf; /* Share memory for windowed TD signal and for the power spectrum */ /*--------------------------------------------------------------* * Input Signal Processing: copy, HP filter, pre-emphasis *---------------------------------------------------------------*/ /* Copy Samples */ - Copy(new_samples, st->new_speech_enc, L_frame ); - Scale_sig( st->new_speech_enc, L_frame, 1 ); + mvr2r( new_samples, st->new_speech_enc, L_frame ); /*--------------------------------------------------------------* * TCX-LTP *---------------------------------------------------------------*/ - tmp8 = 0; - move16(); - if(L_sub(st->sr_core, 25600) > 0) + tcx_ltp_encode( st->tcxltp, st->tcxonly, st->tcxMode, L_frame, L_SUBFR, st->speech_enc+st->encoderLookahead_enc, + st->speech_ltp+st->encoderLookahead_enc, st->speech_enc+st->encoderLookahead_enc, + T_op[1], ¶m_core[1+NOISE_FILL_RANGES], ltpBits, &st->tcxltp_pitch_int, &st->tcxltp_pitch_fr, + &st->tcxltp_gain, &st->tcxltp_pitch_int_past, &st->tcxltp_pitch_fr_past, &st->tcxltp_gain_past, + &st->tcxltp_norm_corr_past, st->last_core, st->pit_min, st->pit_fr1, st->pit_fr2, st->pit_max, + st->pit_res_max, &st->transientDetection, (st->sr_core > 25600), NULL, M ); + + mvr2r( st->speech_enc+st->encoderLookahead_enc, st->new_speech_enc_pe, L_frame ); + + preemph( st->new_speech_enc_pe, st->preemph_fac, L_frame, &(st->mem_preemph_enc) ); + + if( st->tcxMode == TCX_10 ) { - tmp8 = 1; - move16(); - } - - tcx_ltp_encode( st->tcxltp, - st->tcxonly, - st->tcxMode, - L_frame, - L_SUBFR, - st->speech_enc+st->encoderLookahead_enc, - st->speech_ltp+st->encoderLookahead_enc, - st->speech_enc+st->encoderLookahead_enc, - T_op[1], - ¶m_core[1+NOISE_FILL_RANGES], - ltpBits, - &st->tcxltp_pitch_int, - &st->tcxltp_pitch_fr, - &st->tcxltp_gain, - &st->tcxltp_pitch_int_past, - &st->tcxltp_pitch_fr_past, - &st->tcxltp_gain_past, - &st->tcxltp_norm_corr_past, - st->last_core_fx, - st->pit_min, - st->pit_fr1, - st->pit_fr2, - st->pit_max, - st->pit_res_max, - &st->transientDetection, - tmp8, - NULL, - M - ); - - - Copy(st->speech_enc+st->encoderLookahead_enc, st->new_speech_enc_pe, L_frame); - - Preemph_scaled(st->new_speech_enc_pe, /* input: Q0, output: Q_new - 1 */ - Q_new, - &(st->mem_preemph_enc), - st->Q_max_enc, - st->preemph_fac, - 1, /* preemph_bits = output scaling */ - 0, - 2, - L_frame, - st->coder_type_raw_fx,1 - ); - - Q_exp = sub(*Q_new, st->prev_Q_new); - move16(); - - /* Rescale Memory */ - Scale_sig(st->old_inp_16k_fx, L_INP_MEM, sub(*Q_new,st->Q_old)); - IF (Q_exp != 0) - { - Scale_sig(st->buf_speech_enc_pe, st->encoderPastSamples_enc+st->encoderLookahead_enc, Q_exp); - Scale_sig(&(st->mem_wsp_enc), 1, Q_exp); - } - - IF (sub(st->tcxMode,TCX_10) == 0) - { - Copy( ¶m_core[1+NOISE_FILL_RANGES], ¶m_core[NPRM_DIV+1+NOISE_FILL_RANGES], LTPSIZE ); + mvi2i( ¶m_core[1+NOISE_FILL_RANGES], ¶m_core[NPRM_DIV+1+NOISE_FILL_RANGES], LTPSIZE ); } lsp[0] = lsp_new; @@ -168,318 +92,165 @@ void core_signal_analysis_high_bitrate( const Word16 *new_samples, /*i: 0Q15*/ *--------------------------------------------------------------------------*/ alw_pitch_lag_12k8[0] = pitch[0]; - move16(); alw_pitch_lag_12k8[1] = pitch[1]; - move16(); alw_voicing[0] = voicing[0]; - move16(); alw_voicing[1] = voicing[1]; - move16(); - alw_pitch_lag_12k8_wc = s_min(alw_pitch_lag_12k8[0], alw_pitch_lag_12k8[1]); - alw_voicing_wc = s_max(alw_voicing[0], alw_voicing[1]); - overlap_mode[0] = last_overlap; /* Overlap between the last and the current frame */ move16(); + alw_pitch_lag_12k8_wc = min(alw_pitch_lag_12k8[0], alw_pitch_lag_12k8[1]); + alw_voicing_wc = max(alw_voicing[0], alw_voicing[1]); + overlap_mode[0] = last_overlap; /* Overlap between the last and the current frame */ - IF (sub(st->tcxMode, TCX_20) == 0) + if (st->tcxMode == TCX_20) { nSubframes = 1; - move16(); transform_type[0] = TCX_20; - move16(); - overlap_mode[1] = curr_overlap; /* Overlap between the current and the next frame */ move16(); + overlap_mode[1] = curr_overlap; /* Overlap between the current and the next frame */ alw_pitch_lag_12k8[0] = alw_pitch_lag_12k8_wc; - move16(); alw_voicing[0] = alw_voicing_wc; - move16(); } - ELSE + else { nSubframes = 2; - move16(); - IF (sub(curr_overlap, FULL_OVERLAP) == 0) + if (curr_overlap == FULL_OVERLAP) { transform_type[0] = TCX_5; - move16(); transform_type[1] = TCX_10; - move16(); - - overlap_mode[1] = MIN_OVERLAP; /* Overlap between 2nd and 3rd sub-frame */ move16(); - if (sub(last_overlap, HALF_OVERLAP) == 0) - { - overlap_mode[1] = HALF_OVERLAP; - move16(); - } + overlap_mode[1] = (last_overlap == HALF_OVERLAP) ? HALF_OVERLAP : MIN_OVERLAP; /* Overlap between 2nd and 3rd sub-frame */ } - ELSE IF (sub(last_overlap, FULL_OVERLAP) == 0) + else if (last_overlap == FULL_OVERLAP) { transform_type[0] = TCX_10; - move16(); transform_type[1] = TCX_5; - move16(); - - overlap_mode[1] = MIN_OVERLAP; /* Overlap between 1st and 2nd sub-frame */ move16(); - if (sub(curr_overlap, HALF_OVERLAP) == 0) - { - overlap_mode[1] = HALF_OVERLAP; - move16(); - } + overlap_mode[1] = (curr_overlap == HALF_OVERLAP) ? HALF_OVERLAP : MIN_OVERLAP; /* Overlap between 1st and 2nd sub-frame */ } - ELSE + else { transform_type[0] = transform_type[1] = TCX_5; - move16(); - move16(); - - overlap_mode[1] = MIN_OVERLAP; /* Overlap between 2nd and 3rd sub-frame */ move16(); - test(); - if (sub(last_overlap, HALF_OVERLAP) == 0 && sub(curr_overlap, HALF_OVERLAP) == 0) - { - overlap_mode[1] = HALF_OVERLAP; - move16(); - } + overlap_mode[1] = (last_overlap == HALF_OVERLAP && curr_overlap == HALF_OVERLAP) ? HALF_OVERLAP : MIN_OVERLAP; /* Overlap between 2nd and 3rd sub-frame */ } - overlap_mode[2] = curr_overlap; /* Overlap between the current and the next frame */ move16(); + overlap_mode[2] = curr_overlap; /* Overlap between the current and the next frame */ } - IF (sub(transform_type[0], TCX_20) != 0) + + if (transform_type[0] != TCX_20) { IGFEncResetTCX10BitCounter(&st->hIGFEnc); } - /*-------------------------------------------------------------------------* - * Get MDCT output and TNS parameters. Apply TNS in the spectrum if needed - *--------------------------------------------------------------------------*/ - FOR (frameno = 0; frameno < nSubframes; frameno++) + for (frameno = 0; frameno < nSubframes; frameno++) { - L_subframe = L_frameTCX; - move16(); - if (sub(nSubframes, 1) != 0) L_subframe = shr(L_frameTCX, 1); + /*-------------------------------------------------------------------------* + * Get MDCT output and TNS parameters. Apply TNS in the spectrum if needed + *--------------------------------------------------------------------------*/ - lpc_left_overlap_mode = overlap_mode[frameno]; - move16(); - lpc_right_overlap_mode = overlap_mode[frameno+1]; - move16(); - if (sub(lpc_left_overlap_mode, ALDO_WINDOW) == 0) - { - lpc_left_overlap_mode = FULL_OVERLAP; - move16(); - } - if (sub(lpc_right_overlap_mode, ALDO_WINDOW) == 0) - { - lpc_right_overlap_mode = FULL_OVERLAP; - move16(); - } + L_subframe = L_frameTCX/nSubframes; - test(); - IF ((sub(transform_type[frameno], TCX_20) != 0) || (sub(st->tcx_cfg.tcx_last_overlap_mode, TRANSITION_OVERLAP) == 0)) + if( (transform_type[frameno] == TCX_20) && (st->tcx_cfg.tcx_last_overlap_mode != TRANSITION_OVERLAP) ) + { + wtda( st->new_speech_TCX, tcx20Win, NULL, overlap_mode[frameno], overlap_mode[frameno+1], L_frameTCX ); + + /* Windowing of the 2xTCX5 subframes or 1xTCX10 or 1xTCX20 */ + WindowSignal( &st->tcx_cfg, st->tcx_cfg.tcx_offsetFB, overlap_mode[frameno] == ALDO_WINDOW ? FULL_OVERLAP : overlap_mode[frameno], + overlap_mode[frameno+1] == ALDO_WINDOW ? FULL_OVERLAP : overlap_mode[frameno+1], &left_overlap, &right_overlap, + &st->speech_TCX[frameno*tcx10SizeFB], &L_subframe, mdstWin, 1 ); + } + else { /* Windowing of the 2xTCX5 subframes or 1xTCX10 or 1xTCX20 */ - WindowSignal(&st->tcx_cfg, - st->tcx_cfg.tcx_offsetFB, - overlap_mode[frameno], - overlap_mode[frameno+1], - &left_overlap, &right_overlap, - &st->speech_TCX[frameno*tcx10SizeFB], - &L_subframe, - tcx20Win - ,1 - ); + WindowSignal( &st->tcx_cfg, st->tcx_cfg.tcx_offsetFB, overlap_mode[frameno], overlap_mode[frameno+1], &left_overlap, &right_overlap, + &st->speech_TCX[frameno*tcx10SizeFB], &L_subframe, tcx20Win, 1 ); } - IF (sub(transform_type[frameno], TCX_5) == 0) + if( transform_type[frameno] == TCX_5 ) { - folding_offset = shr(left_overlap, 1); - /* Outter left folding */ - FOR (i = 0; i < folding_offset; i++) + for (i = 0; i < left_overlap/2; i++) { - tcx20Win[folding_offset+i] = sub(tcx20Win[folding_offset+i], tcx20Win[folding_offset-1-i]); - move16(); + tcx20Win[left_overlap/2+i] -= tcx20Win[left_overlap/2-1-i]; } + /* Outter right folding */ - tmp = shr(right_overlap, 1); - FOR (i = 0; i < tmp; i++) + for (i = 0; i < right_overlap/2; i++) { - tcx20Win[L_subframe+folding_offset-1-i] = add(tcx20Win[L_subframe+folding_offset-1-i], tcx20Win[L_subframe+folding_offset+i]); - move16(); + tcx20Win[L_subframe+left_overlap/2-1-i] += tcx20Win[L_subframe+left_overlap/2+i]; } + /* 2xTCX5 */ L_subframe = tcx5SizeFB; - move16(); + folding_offset = left_overlap/2; - tmpP16 = tcx20Win; - tmpP32 = spectrum[frameno]; - FOR (i = 0; i < 2; i++) + for (i = 0; i < 2; i++) { - test(); - test(); - WindowSignal(&st->tcx_cfg, - folding_offset, - mac_r(-(1<<16), 3<<8, shl(i,7)), /* equivalent to: i == 0 ? RECTANGULAR_OVERLAP : MIN_OVERLAP */ - mac_r(2<<16, -(3<<8), shl(i,7)), /* equivalent to: sub(i, 1) == 0 ? RECTANGULAR_OVERLAP : MIN_OVERLAP */ - &left_overlap, &right_overlap, - tmpP16, - &L_subframe, - tcx5Win - ,1 - ); - spectrum_e[frameno] = 16; - move16(); - TCX_MDCT(tcx5Win, - tmpP32, - &spectrum_e[frameno], - left_overlap, - sub(L_subframe, shr(add(left_overlap, right_overlap), 1)), - right_overlap); + WindowSignal( &st->tcx_cfg, folding_offset, i == 0 ? RECTANGULAR_OVERLAP : MIN_OVERLAP, i == 1 ? RECTANGULAR_OVERLAP : MIN_OVERLAP, + &left_overlap, &right_overlap, tcx20Win+i*tcx5SizeFB, &L_subframe, tcx5Win, 1 ); - tmpP16 += tcx5SizeFB; - tmpP32 += tcx5SizeFB; + TCX_MDCT( tcx5Win, st->spectrum[frameno]+i*tcx5SizeFB, left_overlap, L_subframe-(left_overlap+right_overlap)/2, right_overlap ); } } - ELSE /* transform_type[frameno] != TCX_5 */ + else /* transform_type[frameno] != TCX_5 */ { assert(transform_type[frameno] == TCX_10 || transform_type[frameno] == TCX_20); - /* TCX20/TCX10 */ - spectrum_e[frameno] = 16; - move16(); - test(); - IF ((sub(transform_type[frameno], TCX_20) == 0) && (sub(st->tcx_cfg.tcx_last_overlap_mode, TRANSITION_OVERLAP) != 0)) + if( transform_type[frameno] == TCX_20 && st->tcx_cfg.tcx_last_overlap_mode != TRANSITION_OVERLAP ) { - Word32 tmp_buf[L_FRAME_PLUS]; - Word16 Q, tmp1, tmp2; - - Q = 0; - move16(); - - wtda_fx(st->new_speech_TCX, - &Q, - tmp_buf, - NULL, - NULL, - overlap_mode[frameno], - overlap_mode[frameno+1], - L_frameTCX); - - WindowSignal(&st->tcx_cfg, - st->tcx_cfg.tcx_offsetFB, - lpc_left_overlap_mode, - lpc_right_overlap_mode, - &left_overlap, &right_overlap, - &st->speech_TCX[frameno*tcx10SizeFB], - &L_subframe, - mdstWin - ,1 - ); - - /* scale by NORM_MDCT_FACTOR / L */ - tmp1 = mult_r(shl(L_subframe, 4), 26214/*128.f / NORM_MDCT_FACTOR Q15*/); /* 4Q11 */ - tmp2 = 4; - move16(); - tmp1 = ISqrt16(tmp1, &tmp2); - - FOR (i = 0; i < L_subframe; i++) - { - tmp_buf[i] = Mpy_32_16_1(tmp_buf[i], tmp1); - move32(); - } - Q = sub(Q, tmp2); - - /* DCT */ - edct_fx(tmp_buf, spectrum[frameno], L_subframe, &Q); - *spectrum_e = sub(31, Q); + edct(tcx20Win, st->spectrum[frameno], L_subframe); + v_multc(st->spectrum[frameno], (float)sqrt((float)NORM_MDCT_FACTOR / L_subframe), st->spectrum[frameno], L_subframe); } - ELSE + else { - TCX_MDCT(tcx20Win, - spectrum[frameno], - &spectrum_e[frameno], - left_overlap, - sub(L_subframe, shr(add(left_overlap, right_overlap), 1)), - right_overlap); + /* TCX20/TCX10 */ + TCX_MDCT( tcx20Win, st->spectrum[frameno], left_overlap, L_subframe-(left_overlap+right_overlap)/2, right_overlap ); } /* For TCX20 at bitrates up to 64 kbps we need the power spectrum */ - test(); - test(); - IF (sub(st->tcxMode, TCX_20) == 0 && ((L_sub(st->total_brate_fx, HQ_96k) < 0) || st->igf)) + if ((st->tcxMode == TCX_20) && ((st->total_brate < HQ_96k) || st->igf)) { - - pMdstWin = tcx20Win; - test(); - if (((sub(st->tcxMode, TCX_20) == 0) && (sub(st->tcx_cfg.tcx_last_overlap_mode, TRANSITION_OVERLAP) != 0))) - { - pMdstWin = mdstWin; - } - /* Compute noise-measure flags for spectrum filling and quantization */ - AnalyzePowerSpectrum(st, - div_l(L_mult(L_subframe, st->L_frame_fx), st->L_frameTCX), - L_subframe, - left_overlap, right_overlap, - spectrum[frameno], spectrum_e[frameno], - pMdstWin, - powerSpec, &powerSpec_e); + AnalyzePowerSpectrum( st, L_subframe*st->L_frame/st->L_frameTCX, L_subframe, left_overlap, right_overlap, st->spectrum[frameno], + ((st->tcxMode == TCX_20) && (st->tcx_cfg.tcx_last_overlap_mode != TRANSITION_OVERLAP)) ? mdstWin : tcx20Win, powerSpec ); } } - test(); - test(); - TNSAnalysis(&st->tcx_cfg, L_frameTCX, - st->tcx_cfg.tcx_coded_lines, - transform_type[frameno], (frameno == 0) && (st->last_core_fx == ACELP_CORE), - spectrum[frameno], &st->tnsData[frameno], &st->fUseTns[frameno], NULL - ); + TNSAnalysis( &st->tcx_cfg, L_frameTCX, st->tcx_cfg.tcx_coded_lines, transform_type[frameno], (frameno == 0) && (st->last_core == 0), + st->spectrum[frameno], &st->tnsData[frameno], &st->fUseTns[frameno], NULL ); EncodeTnsData(st->tcx_cfg.pCurrentTnsConfig, &st->tnsData[frameno], param_core+frameno*NPRM_DIV+1+NOISE_FILL_RANGES+LTPSIZE, pTnsSize+frameno, pTnsBits+frameno); - IF (sub(transform_type[frameno], TCX_5) == 0) + if( transform_type[frameno] == TCX_5 ) { /* group sub-windows: interleave bins according to their frequencies */ - FOR (i = 0; i < tcx5SizeFB; i++) + for( i = 0; i < tcx5SizeFB; i++ ) { - interleaveBuf[2*i] = spectrum[frameno][i]; - move32(); - interleaveBuf[2*i+1] = spectrum[frameno][tcx5SizeFB+i]; - move32(); + interleaveBuf[2*i] = st->spectrum[frameno][i]; + interleaveBuf[2*i+1] = st->spectrum[frameno][tcx5SizeFB+i]; } - Copy32(interleaveBuf, spectrum[frameno], tcx10SizeFB); + + mvr2r( interleaveBuf, st->spectrum[frameno], tcx10SizeFB ); } /*--------------------------------------------------------------* * LPC analysis *---------------------------------------------------------------*/ + HBAutocorrelation( &st->tcx_cfg, overlap_mode[frameno]==ALDO_WINDOW?FULL_OVERLAP:overlap_mode[frameno], + overlap_mode[frameno+1]==ALDO_WINDOW?FULL_OVERLAP:overlap_mode[frameno+1], + &st->speech_enc_pe[frameno*tcx10Size], L_frame/nSubframes, r, M ); - HBAutocorrelation(&st->tcx_cfg, - lpc_left_overlap_mode, - lpc_right_overlap_mode, - &st->speech_enc_pe[frameno*tcx10Size], - shr(L_frame, sub(nSubframes, 1)), - r, - M); + adapt_lag_wind( r, M, alw_pitch_lag_12k8[frameno], alw_voicing[frameno], st->sr_core ); - FOR (i=0; i <= M; i++) + lev_dur( A, r, M, NULL ); + + a2lsp_stab( A, lsp[nSubframes-1-frameno], st->lspold_enc ); + + if( st->igf ) { - move16(); - move16(); - r_l[frameno][i] = L_Extract_lc(r[i], &r_h[frameno][i]); - } - - adapt_lag_wind( r_h[frameno], r_l[frameno], M, alw_pitch_lag_12k8[frameno], alw_voicing[frameno], st->sr_core ); - - E_LPC_lev_dur(r_h[frameno], r_l[frameno], A, epsP, M, NULL); - - E_LPC_a_lsp_conversion(A, lsp[nSubframes-1-frameno], st->lspold_enc_fx, M ); - - IF (st->igf) - { - ProcessIGF(&st->hIGFEnc, st, spectrum[frameno], &(spectrum_e[frameno]), powerSpec, &powerSpec_e, transform_type[frameno] == TCX_20, st->fUseTns[frameno], (st->last_core_fx == ACELP_CORE), frameno); + ProcessIGF(&st->hIGFEnc, st, st->spectrum[frameno], powerSpec, transform_type[frameno] == TCX_20, st->fUseTns[frameno], (st->last_core == ACELP_CORE), frameno ); } } /* Copy memory */ - mvr2r_Word16(lsp_new, st->lspold_enc_fx, M); - + mvr2r( lsp_new, st->lspold_enc, M ); + return; } + diff --git a/src/libs/libevs/lib_enc/fd_cng_enc.cpp b/src/libs/libevs/lib_enc/fd_cng_enc.cpp old mode 100755 new mode 100644 index 500f6b6f..c8d28bea --- a/src/libs/libevs/lib_enc/fd_cng_enc.cpp +++ b/src/libs/libevs/lib_enc/fd_cng_enc.cpp @@ -1,47 +1,48 @@ /*==================================================================================== - EVS Codec 3GPP TS26.442 Apr 03, 2018. Version 12.11.0 / 13.6.0 / 14.2.0 + EVS Codec 3GPP TS26.443 Nov 13, 2018. Version 12.11.0 / 13.7.0 / 14.3.0 / 15.1.0 ====================================================================================*/ - #include -#include "stl.h" +#include +#include "rom_enc.h" +#include "rom_com.h" +#include "prot.h" +#include "stat_enc.h" #include "options.h" -#include "stl.h" -#include "rom_com_fx.h" -#include "prot_fx.h" -#include "basop_util.h" -#include "rom_basop_util.h" +/*-------------------------------------------------------------------* +* createFdCngEnc() +* +* +*-------------------------------------------------------------------*/ -/******************************** -* External functions * -********************************/ - -#define swap(x,y,type) {type u__p; u__p=x; x=y; y=u__p;} - - -/************************************* -* Create an instance of type FD_CNG * -*************************************/ void createFdCngEnc(HANDLE_FD_CNG_ENC* hFdCngEnc) { HANDLE_FD_CNG_ENC hs; /* Allocate memory */ hs = (HANDLE_FD_CNG_ENC) calloc(1, sizeof (FD_CNG_ENC)); - move16(); - createFdCngCom(&(hs->hFdCngCom)); + *hFdCngEnc = hs; - move16(); return; } -void initFdCngEnc(HANDLE_FD_CNG_ENC hsEnc, Word32 input_Fs, Word16 scale) +/*-------------------------------------------------------------------* +* initFdCngEnc() +* +* Initialize FD_CNG +*-------------------------------------------------------------------*/ + +void initFdCngEnc( + HANDLE_FD_CNG_ENC hsEnc, /* i/o: Contains the variables related to the FD-based CNG process */ + int input_Fs, /* i: input signal sampling frequency in Hz */ + float scale /* i: scaling factor */ +) { - Word16 j; + int j; HANDLE_FD_CNG_COM hsCom = hsEnc->hFdCngCom; /* Initialize common */ @@ -51,1447 +52,697 @@ void initFdCngEnc(HANDLE_FD_CNG_ENC hsEnc, Word32 input_Fs, Word16 scale) /* Configure the Noise Estimator */ hsCom->numSlots = 16; - move16(); hsCom->numCoreBands = 16; - move16(); - hsCom->regularStopBand = idiv1616U( extract_l( L_shr( input_Fs, 5 ) ), 25 ); - if ( sub( hsCom->regularStopBand, 40 ) > 0 ) + hsCom->regularStopBand = input_Fs/800; + if ( hsCom->regularStopBand > 40 ) { hsCom->regularStopBand = 40; - move16(); } hsCom->startBand = 2; - move16(); - IF ( sub( hsCom->regularStopBand, 10 ) == 0 ) + if ( hsCom->regularStopBand == 10 ) { hsCom->stopFFTbin = 160; - move16(); hsCom->stopBand = 160; - move16(); hsCom->nFFTpart = 17; - move16(); } - ELSE + else { hsCom->stopFFTbin = 256; - move16(); - hsCom->stopBand = add( sub( hsCom->regularStopBand, hsCom->numCoreBands ), hsCom->stopFFTbin ); + hsCom->stopBand = hsCom->regularStopBand - hsCom->numCoreBands + hsCom->stopFFTbin; hsCom->nFFTpart = 20; - move16(); } - initPartitions( sidparts_encoder_noise_est, 24, hsCom->startBand, hsCom->stopBand, hsCom->part, &hsCom->npart, hsCom->midband, hsCom->psize, hsCom->psize_norm, &hsCom->psize_norm_exp, hsCom->psize_inv, 0); + initPartitions( sidparts_encoder_noise_est, sizeof(sidparts_encoder_noise_est)/sizeof(int), hsCom->startBand, hsCom->stopBand, hsCom->part, &hsCom->npart, hsCom->midband, hsCom->psize, hsCom->psize_inv, 0); - hsCom->nCLDFBpart = sub( hsCom->npart, hsCom->nFFTpart ); - FOR(j=0; jnCLDFBpart; j++) + hsCom->nCLDFBpart = hsCom->npart - hsCom->nFFTpart; + for(j=0; jnCLDFBpart; j++) { - hsCom->CLDFBpart[j] = sub( hsCom->part[j+hsCom->nFFTpart], sub( 256, hsCom->startBand ) ); + hsCom->CLDFBpart[j] = hsCom->part[j+hsCom->nFFTpart] - (256-hsCom->startBand); hsCom->CLDFBpsize_inv[j] = hsCom->psize_inv[j+hsCom->nFFTpart]; } - /* Initialize noise estimation algorithm */ - set32_fx( hsEnc->msPeriodog, 0, NPART ); - hsEnc->msPeriodog_exp_fft = 0; - move16(); - hsEnc->msPeriodog_exp_cldfb = 0; - move16(); - set32_fx( hsEnc->msAlpha, 0, NPART ); - set32_fx( hsEnc->msBminWin, 0, NPART ); - set32_fx( hsEnc->msBminSubWin, 0, NPART ); + /* Initialize the Noise Estimator */ - set32_fx( hsEnc->msNoiseEst, 0, NPART ); - hsEnc->msNoiseEst_exp = 0; - move16(); - set32_fx( hsEnc->energy_ho, 0, NPART ); - set32_fx( hsEnc->msNoiseEst_old, 0, NPART ); - - set16_fx( hsEnc->msLogPeriodog, 0, NPART ); - set16_fx( hsEnc->msLogNoiseEst, 0, NPART ); - set16_fx( hsEnc->msPsd, 0, NPART ); - set16_fx( hsEnc->msNoiseFloor, 0, NPART ); - set32_fx( hsEnc->msMinBuf, 2147483647l/*1.0 Q31*/, MSNUMSUBFR*NPART ); - set32_fx( hsEnc->msCurrentMin, 2147483647l/*1.0 Q31*/, NPART ); - set32_fx( hsEnc->msCurrentMinOut, 2147483647l/*1.0 Q31*/, NPART ); - set32_fx( hsEnc->msCurrentMinSubWindow, 2147483647l/*1.0 Q31*/, NPART ); - set16_fx( hsEnc->msPsdFirstMoment, 0, NPART ); - set16_fx( hsEnc->msPeriodogBuf, 0, MSBUFLEN*NPART ); - - set16_fx( hsEnc->msLocalMinFlag, 0, NPART ); - set16_fx( hsEnc->msNewMinFlag, 0, NPART ); + set_f( hsEnc->msPeriodog, 0.0f, NPART ); + set_f( hsEnc->msAlpha, 0.0f, NPART ); + set_f( hsEnc->msBminWin, 0.0f, NPART ); + set_f( hsEnc->msBminSubWin, 0.0f, NPART ); + set_f( hsEnc->msPsd, 0.0f, NPART ); + set_f( hsEnc->msNoiseFloor, 0.0f, NPART ); + set_f( hsEnc->msNoiseEst, 0.0f, NPART ); + set_f( hsEnc->energy_ho, 0.0f, NPART ); + set_f( hsEnc->msNoiseEst_old, 0.0f, NPART ); + set_f( hsEnc->msMinBuf, FLT_MAX, MSNUMSUBFR*NPART ); + set_f( hsEnc->msCurrentMin, FLT_MAX, NPART ); + set_f( hsEnc->msCurrentMinOut, FLT_MAX, NPART ); + set_f( hsEnc->msCurrentMinSubWindow, FLT_MAX, NPART ); + set_i( hsEnc->msLocalMinFlag, 0, NPART ); + set_i( hsEnc->msNewMinFlag, 0, NPART ); + set_f( hsEnc->msPsdFirstMoment, 0.0f, NPART ); + set_f( hsEnc->msPsdSecondMoment, 0.0f, NPART ); hsEnc->msPeriodogBufPtr = 0; - move16(); - set32_fx( hsEnc->msPsdSecondMoment, 0, NPART ); - + set_f( hsEnc->msPeriodogBuf, 0.0f, MSBUFLEN*NPART ); + set_f( hsEnc->msLogPeriodog, 0.0f, NPART ); + set_f( hsEnc->msLogNoiseEst, 0.0f, NPART ); return; } -/************************************ -* Configure FD_CNG * -************************************/ -void configureFdCngEnc(HANDLE_FD_CNG_ENC hsEnc, /* i/o: Contains the variables related to the FD-based CNG process */ - Word16 bandwidth, /* i: bandwidth */ - Word32 bitrate - ) +/*-------------------------------------------------------------------* +* configureFdCngEnc() +* +* Configure FD_CNG +*-------------------------------------------------------------------*/ + +void configureFdCngEnc( + HANDLE_FD_CNG_ENC hsEnc, /* i/o: Contains the variables related to the FD-based CNG process */ + short bandwidth, + int bitrate +) { HANDLE_FD_CNG_COM hsCom = hsEnc->hFdCngCom; - Word16 psizeDec[NPART]; - Word16 psizeDec_norm[NPART]; - Word16 psizeDec_norm_exp; - Word16 psize_invDec[NPART]; - - set16_fx(psizeDec, 0, NPART); + float psizeDec[NPART]; + float psize_invDec[NPART]; hsCom->CngBandwidth = bandwidth; - move16(); - IF ( sub( hsCom->CngBandwidth, FB ) == 0 ) + if ( hsCom->CngBandwidth == FB ) { hsCom->CngBandwidth = SWB; } hsCom->CngBitrate = bitrate; - move32(); /* NB configuration */ - IF ( sub(bandwidth,NB) == 0 ) + if ( bandwidth == NB ) { - hsCom->FdCngSetup = FdCngSetup_nb; /* PTR assignation -> no move needed*/ + hsCom->FdCngSetup = FdCngSetup_nb; } /* WB configuration */ - ELSE IF ( sub(bandwidth,WB) == 0 ) + else if ( bandwidth == WB ) { /* FFT 6.4kHz, no CLDFB */ - IF ( L_sub(bitrate,ACELP_8k00) <= 0 ) + if ( bitrate <= ACELP_8k00 ) { hsCom->FdCngSetup = FdCngSetup_wb1; } /* FFT 6.4kHz, CLDFB 8.0kHz */ - ELSE IF ( L_sub(bitrate,ACELP_13k20) <= 0 ) + else if ( bitrate <= ACELP_13k20 ) { hsCom->FdCngSetup = FdCngSetup_wb2; } /* FFT 8.0kHz, no CLDFB */ - ELSE + else { hsCom->FdCngSetup = FdCngSetup_wb3; } } /* SWB/FB configuration */ - ELSE + else { /* FFT 6.4kHz, CLDFB 14kHz */ - IF ( L_sub(bitrate,ACELP_13k20) <= 0 ) + if ( bitrate <= ACELP_13k20 ) { hsCom->FdCngSetup = FdCngSetup_swb1; } /* FFT 8.0kHz, CLDFB 16kHz */ - ELSE + else { hsCom->FdCngSetup = FdCngSetup_swb2; } } hsCom->fftlen = hsCom->FdCngSetup.fftlen; - move16(); hsEnc->stopFFTbinDec = hsCom->FdCngSetup.stopFFTbin; - move16(); /* Configure the SID quantizer and the Confort Noise Generator */ hsEnc->startBandDec = hsCom->startBand; - move16(); - hsEnc->stopBandDec = add( hsCom->FdCngSetup.sidPartitions[hsCom->FdCngSetup.numPartitions-1], 1 ); - move16(); - initPartitions( hsCom->FdCngSetup.sidPartitions, - hsCom->FdCngSetup.numPartitions, - hsEnc->startBandDec, - hsEnc->stopBandDec, - hsEnc->partDec, - &hsEnc->npartDec, - hsEnc->midbandDec, - psizeDec, - psizeDec_norm, - &psizeDec_norm_exp, - psize_invDec, - 0 - ); - IF ( sub(hsEnc->stopFFTbinDec,160) == 0 ) + hsEnc->stopBandDec = hsCom->FdCngSetup.sidPartitions[hsCom->FdCngSetup.numPartitions-1] + 1; + initPartitions( hsCom->FdCngSetup.sidPartitions, hsCom->FdCngSetup.numPartitions, hsEnc->startBandDec, hsEnc->stopBandDec, + hsEnc->partDec, &hsEnc->npartDec, hsEnc->midbandDec, psizeDec, psize_invDec, 0 ); + + if ( hsEnc->stopFFTbinDec == 160 ) { hsEnc->nFFTpartDec = 17; - move16(); } - ELSE IF ( sub(hsEnc->stopFFTbinDec,256) == 0 ) + else if ( hsEnc->stopFFTbinDec == 256 ) { hsEnc->nFFTpartDec = 20; - move16(); } - ELSE + else { hsEnc->nFFTpartDec = 21; - move16(); } - SWITCH (hsCom->fftlen) + switch (hsCom->fftlen) { case 512: - hsCom->fftlenShift = 8; - move16(); - hsCom->fftlenFac = 32767/*1.0 Q15*/; - move16(); - BREAK; + hsCom->fftSineTab = NULL; + hsCom->olapWinAna = olapWinAna512; + hsCom->olapWinSyn = olapWinSyn256; + break; case 640: - hsCom->fftlenShift = 9; - move16(); - hsCom->fftlenFac = 20480/*0.625 Q15*/; - move16(); - BREAK; + hsCom->fftSineTab = fftSineTab640; + hsCom->olapWinAna = olapWinAna640; + hsCom->olapWinSyn = olapWinSyn320; + break; default: assert(!"Unsupported FFT length for FD-based CNG"); - BREAK; + break; } - BASOP_getTables( &hsCom->olapWinAna, NULL, NULL, shr(hsCom->fftlen, 1)); - BASOP_getTables( &hsCom->olapWinSyn, NULL, NULL, shr(hsCom->fftlen, 2)); - hsCom->frameSize = shr( hsCom->fftlen, 1 ); + hsCom->frameSize = hsCom->fftlen >> 1; + return; } -/************************************** -* Delete the instance of type FD_CNG * -**************************************/ -void deleteFdCngEnc(HANDLE_FD_CNG_ENC * hFdCngEnc) + +/*-------------------------------------------------------------------* +* deleteFdCngEnc() +* +* Delete the instance of type FD_CNG +*-------------------------------------------------------------------*/ + +void deleteFdCngEnc( + HANDLE_FD_CNG_ENC *hFdCngEnc +) { - HANDLE_FD_CNG_ENC hsEnc; - hsEnc = *hFdCngEnc; - move16(); - IF (hsEnc != NULL) + HANDLE_FD_CNG_ENC hsEnc = *hFdCngEnc; + if (hsEnc != NULL) { deleteFdCngCom(&(hsEnc->hFdCngCom)); free(hsEnc); *hFdCngEnc = NULL; - move16(); } + + return; } +/*-------------------------------------------------------------------* +* resetFdCngEnc() +* +* Reset the instance of type FD_CNG +*-------------------------------------------------------------------*/ void resetFdCngEnc( - Encoder_State_fx * st + Encoder_State * st ) { - Word16 tmpTest; - Word16 n; - Word16 totalNoiseIncrease; - Word16 thresh = 5 * 256; /* 5.0 in Q8 */ - - /* st->totalNoise_fx; Q8 Noise estimator - total noise energy */ + int n; + float totalNoiseIncrease; /* Detect fast increase of totalNoise */ - totalNoiseIncrease = sub(st->totalNoise_fx, st->last_totalNoise_fx); - st->last_totalNoise_fx = st->totalNoise_fx; - move16(); - IF ( totalNoiseIncrease > 0 ) + totalNoiseIncrease = st->totalNoise - st->last_totalNoise; + st->last_totalNoise = st->totalNoise; + if ( totalNoiseIncrease > 0 ) { - IF ( sub(st->totalNoise_increase_len_fx,TOTALNOISE_HIST_SIZE) == 0 ) + if ( st->totalNoise_increase_len == TOTALNOISE_HIST_SIZE ) { - FOR ( n = 0; n < TOTALNOISE_HIST_SIZE-1; n++ ) + for ( n = 0; n < TOTALNOISE_HIST_SIZE - 1; n++ ) { - st->totalNoise_increase_hist_fx[n] = st->totalNoise_increase_hist_fx[n+1]; - move16(); + st->totalNoise_increase_hist[n] = st->totalNoise_increase_hist[n+1]; } - st->totalNoise_increase_hist_fx[TOTALNOISE_HIST_SIZE-1] = totalNoiseIncrease; - move16(); + st->totalNoise_increase_hist[TOTALNOISE_HIST_SIZE-1] = totalNoiseIncrease; } - ELSE + else { - st->totalNoise_increase_hist_fx[st->totalNoise_increase_len_fx] = totalNoiseIncrease; - move16(); - st->totalNoise_increase_len_fx = add(st->totalNoise_increase_len_fx, 1); + st->totalNoise_increase_hist[st->totalNoise_increase_len] = totalNoiseIncrease; + st->totalNoise_increase_len++; } } - ELSE + else { - st->totalNoise_increase_len_fx = 0; - move16(); + st->totalNoise_increase_len = 0; } - totalNoiseIncrease = 0; - move16(); - FOR ( n = 0; n < st->totalNoise_increase_len_fx; n++ ) + totalNoiseIncrease = 0.f; + for ( n = 0; n < st->totalNoise_increase_len; n++ ) { - totalNoiseIncrease = add(totalNoiseIncrease, st->totalNoise_increase_hist_fx[n]); + totalNoiseIncrease += st->totalNoise_increase_hist[n]; } - - test(); - test(); - tmpTest = ((sub (totalNoiseIncrease,thresh) > 0) && (sub(st->totalNoise_increase_len_fx,TOTALNOISE_HIST_SIZE)==0) && (sub(st->ini_frame_fx,150)>0) ); - - test(); - IF ( tmpTest || ( sub (st->input_bwidth_fx,st->last_input_bwidth_fx) > 0 ) || sub(st->last_core_fx,AMR_WB_CORE) == 0 ) + if ( + (totalNoiseIncrease > 5 && st->totalNoise_increase_len == TOTALNOISE_HIST_SIZE && st->ini_frame > 150 ) + || + ( st->input_bwidth > st->last_input_bwidth ) + || + ( st->last_core == AMR_WB_CORE ) + ) { st->fd_cng_reset_flag = 1; - move16(); - st->hFdCngEnc_fx->hFdCngCom->msFrCnt_init_counter = 0; - move16(); - st->hFdCngEnc_fx->hFdCngCom->init_old = 32767; - move16(); + st->hFdCngEnc->hFdCngCom->msFrCnt_init_counter = 0; + st->hFdCngEnc->hFdCngCom->init_old = FLT_MAX; } - ELSE IF ( s_and((st->fd_cng_reset_flag > 0),(sub(st->fd_cng_reset_flag,10) < 0)) ) + else if ( st->fd_cng_reset_flag > 0 && st->fd_cng_reset_flag < 10 ) { - st->fd_cng_reset_flag = add(st->fd_cng_reset_flag,1); + st->fd_cng_reset_flag++; } - ELSE + else { st->fd_cng_reset_flag = 0; - move16(); } + + return; } -/* - perform_noise_estimation_enc - Parameters: +/*-------------------------------------------------------------------* +* perform_noise_estimation_enc() +* +* Perform noise estimation +*-------------------------------------------------------------------*/ - band_energies i: energy in critical bands without minimum noise floor MODE2_E_MIN - band_energies_exp i: exponent for energy in critical bands without minimum noise floor MODE2_E_MIN - cldfbBufferReal, i: real part of the CLDFB buffer - cldfbBufferImag, i: imaginary part of the CLDFB buffer - cldfbBufferExp, i: exponent for CLDFB buffer - bitrate i: bitrate - st i/o: FD_CNG structure containing all buffers and variables - - Function: - Perform noise estimation - - Returns: - void -*/ -void perform_noise_estimation_enc (Word32 *band_energies, /* i: energy in critical bands without minimum noise floor MODE2_E_MIN */ - Word16 band_energies_exp, /* i: exponent for energy in critical bands without minimum noise floor MODE2_E_MIN */ - Word32 *enerBuffer, - Word16 enerBuffer_exp, - HANDLE_FD_CNG_ENC st /* i/o: FD_CNG structure containing all buffers and variables */ - ) +void perform_noise_estimation_enc( + float *band_energies, /* i: energy in critical bands without minimum noise floor E_MIN */ + float *enerBuffer, + HANDLE_FD_CNG_ENC st /* i/o: CNG structure containing all buffers and variables */ +) { - Word16 i, j, s, s1, s2; - Word16 nFFTpart; - Word16 nCLDFBpart; - Word16 numBands; - Word16 numCoreBands; - Word16 regularStopBand; - Word16 numSlots; - Word32 tmp; - Word32 *periodog; - Word32 *ptr_per; - Word32 *msPeriodog; + short i, j; + int numCoreBands = st->hFdCngCom->numCoreBands; + int regularStopBand = st->hFdCngCom->regularStopBand; + int numSlots = st->hFdCngCom->numSlots; + float numSlots_inv = 1.f/(float)numSlots; /*enough if done only once*/ + float * periodog = st->hFdCngCom->periodog; + float * ptr_per = periodog; + int npart = st->hFdCngCom->npart; + int nFFTpart = st->hFdCngCom->nFFTpart; + float * psize = st->hFdCngCom->psize; + float * msPeriodog = st->msPeriodog; + float * msNoiseEst = st->msNoiseEst; + float * msLogPeriodog = st->msLogPeriodog; + float * msLogNoiseEst = st->msLogNoiseEst; - nFFTpart = st->hFdCngCom->nFFTpart; - move16(); - nCLDFBpart = st->hFdCngCom->nCLDFBpart; - move16(); - numCoreBands = st->hFdCngCom->numCoreBands; - move16(); - regularStopBand = st->hFdCngCom->regularStopBand; - move16(); - numSlots = st->hFdCngCom->numSlots; - move16(); - periodog = st->hFdCngCom->periodog; - move16(); - ptr_per = periodog; - move16(); - msPeriodog = st->msPeriodog; - move16(); - - assert(numSlots == 16); - /* preemphasis compensation and grouping of per bin energies into msPeriodog */ - FOR (i=0; i < nFFTpart; i++) + for(i=0; imsPeriodog_exp_fft = add(band_energies_exp, PREEMPH_COMPENSATION_EXP); - move16(); - - numBands = sub(regularStopBand, numCoreBands); - - IF ( numBands > 0 ) + /* Adjust to the desired time resolution by averaging the periodograms over the time slots */ + for(j=numCoreBands ; jhFdCngCom->scalingFactor); - move32(); - - ptr_per++; - } - - /* exponent for cldfb part of msPeriodog */ - st->hFdCngCom->exp_cldfb_periodog = add( sub(enerBuffer_exp, 4), CLDFBscalingFactor_EXP ); - - /* Adjust CLDFB filterbank to the desired frequency resolution by averaging over spectral partitions for SID transmission */ - bandcombinepow ( - periodog, - st->hFdCngCom->exp_cldfb_periodog, - numBands, - st->hFdCngCom->CLDFBpart, - st->hFdCngCom->nCLDFBpart, - st->hFdCngCom->CLDFBpsize_inv, - &msPeriodog[nFFTpart], - &st->msPeriodog_exp_cldfb - ); - - /* find common exponent for fft part and cldfb part of msperiodog */ - s1 = getScaleFactor32 (msPeriodog,nFFTpart); - s2 = getScaleFactor32 (&msPeriodog[nFFTpart],nCLDFBpart); - - s = s_max(sub(st->msPeriodog_exp_fft,s1), sub(st->msPeriodog_exp_cldfb,s2)); - s1 = sub(s,st->msPeriodog_exp_fft); - s2 = sub(s,st->msPeriodog_exp_cldfb); - - st->msPeriodog_exp_fft = s; - move16(); - st->msPeriodog_exp_cldfb = s; - move16(); - - FOR (i=0; i < nFFTpart; i++) - { - msPeriodog[i] = L_shr(msPeriodog[i],s1); - move32(); - } - - FOR (i=0; i < nCLDFBpart; i++) - { - msPeriodog[nFFTpart+i] = L_shr(msPeriodog[nFFTpart+i],s_min(31,s2)); - move32(); - } + (*ptr_per) = (enerBuffer[j] * numSlots_inv * st->hFdCngCom->scalingFactor); + ptr_per++; } - /* exponent for entire msPeriodog vector */ - st->msPeriodog_exp = st->msPeriodog_exp_fft; - move16(); + /* Adjust filterbank to the desired frequency resolution by averaging over spectral partitions for SID transmission */ + if (numCoreBands < regularStopBand) + { + bandcombinepow(periodog, regularStopBand-numCoreBands, st->hFdCngCom->CLDFBpart, st->hFdCngCom->nCLDFBpart, st->hFdCngCom->CLDFBpsize_inv, &msPeriodog[nFFTpart]); + } /* Compress MS inputs */ - compress_range(st->msPeriodog, st->msPeriodog_exp, st->msLogPeriodog, st->hFdCngCom->npart); + compress_range(msPeriodog, msLogPeriodog, npart); /* Call the minimum statistics routine for noise estimation */ - minimum_statistics ( - st->hFdCngCom->npart, - st->hFdCngCom->nFFTpart, - st->hFdCngCom->psize_norm, - st->msLogPeriodog, - st->msNoiseFloor, - st->msLogNoiseEst, - st->msAlpha, - st->msPsd, - st->msPsdFirstMoment, - st->msPsdSecondMoment, - st->msMinBuf, - st->msBminWin, - st->msBminSubWin, - st->msCurrentMin, - st->msCurrentMinOut, - st->msCurrentMinSubWindow, - st->msLocalMinFlag, - st->msNewMinFlag, - st->msPeriodogBuf, - &(st->msPeriodogBufPtr), - st->hFdCngCom - ); + minimum_statistics( npart, nFFTpart, psize, msLogPeriodog, st->msNoiseFloor, msLogNoiseEst, + st->msAlpha, st->msPsd, st->msPsdFirstMoment, st->msPsdSecondMoment, + st->msMinBuf, st->msBminWin, st->msBminSubWin, + st->msCurrentMin, st->msCurrentMinOut, st->msCurrentMinSubWindow, + st->msLocalMinFlag, st->msNewMinFlag, st->msPeriodogBuf, &(st->msPeriodogBufPtr), st->hFdCngCom ); /* Expand MS outputs */ - expand_range(st->msLogNoiseEst, st->msNoiseEst, &st->msNoiseEst_exp, st->hFdCngCom->npart); + expand_range( msLogNoiseEst, msNoiseEst, npart ); + return; } -/* - AdjustFirstSID - Parameters: +/*-------------------------------------------------------------------* +* AdjustFirstSID() +* +* Adjust the noise estimator at the beginning of each CNG phase (encoder-side) +*-------------------------------------------------------------------*/ - npart i : number of parts - msPeriodog i : pointer to periodog vector - msPeriodog_exp i : exponent of periodog vector - energy_ho i/o : pointer to energy - energy_ho_exp i/o : pointer to exponent of energy - msNoiseEst i/o : pointer to estimated noise - msNoiseEst_exp i/o : pointer to exponent of estimated noise - msNoiseEst_old i/o : pointer to old estimated noise - msNoiseEst_old_exp i/o : pointer to exponent of old estimated noise - active_frame_counter i/o : pointer to active frame counter - stcod i : pointer to Coder_State structure - - Function: - Adjust the noise estimator at the beginning of each CNG phase (encoder-side) - - Returns: - void -*/ -Word16 -AdjustFirstSID (Word16 npart, /* i : number of parts */ - Word32 *msPeriodog, /* i : pointer to periodog vector */ - Word16 msPeriodog_exp, /* i : exponent of periodog vector */ - Word32 *energy_ho, /* i/o : pointer to energy */ - Word16 *energy_ho_exp, /* i/o : pointer to exponent of energy */ - Word32 *msNoiseEst, /* i/o : pointer to estimated noise */ - Word16 *msNoiseEst_exp, /* i/o : pointer to exponent of estimated noise */ - Word32 *msNoiseEst_old, /* i/o : pointer to old estimated noise */ - Word16 *msNoiseEst_old_exp, /* i/o : pointer to exponent of old estimated noise */ - Word16 *active_frame_counter, /* i/o : pointer to active frame counter */ - Encoder_State_fx *stcod /* i : pointer to Coder_State_Plus structure */ - ) +void AdjustFirstSID( + int npart, + float * msPeriodog, + float * energy_ho, + float * msNoiseEst, + float * msNoiseEst_old, + short * active_frame_counter, + Encoder_State *stcod +) { - Word16 i, sc, s1, s2, lambda, lambdaM1, invFac; - Word32 tmp32, energy_ho_local, msNoiseEst_local; + float lambda; + int i; - test(); - IF ( sub(stcod->cnt_SID_fx,1) == 0 && L_sub(stcod->last_core_brate_fx,SID_2k40) > 0 ) + if ( stcod->cnt_SID == 1 && stcod->last_core_brate > SID_2k40 ) { /* Detect the hangover period and the first SID frame at the beginning of each CNG phase */ - /* First hangover frame */ - Copy32 (msPeriodog, energy_ho, npart); - *energy_ho_exp = msPeriodog_exp; - move16(); - + /* Average input energy over hangover period */ + mvr2r(msPeriodog, energy_ho, npart); /*First hangover frame*/ /* Set first SID to current input level but add some smoothing */ - IF ( sub(*active_frame_counter,254) >= 0 ) + lambda = (float)pow( 0.96f, (float)(*active_frame_counter+1) ); + v_multc( msNoiseEst_old, lambda, msNoiseEst_old, npart ); + v_multc( energy_ho, 1-lambda, energy_ho, npart ); + + v_add( msNoiseEst_old, energy_ho, energy_ho, npart ); + for (i=0; i 0 ) + if (msNoiseEst[i]>energy_ho[i]) { - msNoiseEst[i] = energy_ho_local; - move32(); - } - ELSE - { - msNoiseEst[i] = msNoiseEst_local; - move32(); - } - if ( msNoiseEst[i] > 0 ) - { - tmp32 = L_add(0,1); + msNoiseEst[i] = energy_ho[i]; } } - /* Set exponent to zero if msNoiseEst is zero */ - if ( tmp32==0 ) - { - *msNoiseEst_exp = 0; - move16(); - } - *active_frame_counter = 0; - move16(); } - test(); - IF ( L_sub(stcod->core_brate_fx,SID_2k40) != 0 && L_sub(stcod->core_brate_fx,FRAME_NO_DATA) != 0 ) + + if ( stcod->core_brate != SID_2k40 && stcod->core_brate != FRAME__NO_DATA ) { - /* Count the number of active frames in a row */ - *active_frame_counter = add(*active_frame_counter, 1); - move16(); + (*active_frame_counter)++; /* Count the number of active frames in a row */ } - ELSE + else { - /* Store the noise estimate obtained in the CNG phases */ - Copy32 (msNoiseEst, msNoiseEst_old, npart); - *msNoiseEst_old_exp = *msNoiseEst_exp; - move16(); - + mvr2r( msNoiseEst, msNoiseEst_old, npart); /* Store the noise estimate obtained in the CNG phases */ } - - return 0; + return; } +/*-------------------------------------------------------------------* +* FdCng_encodeSID() +* +* Generate a bitstream out of the partition levels +*-------------------------------------------------------------------*/ -/* - msvq_encoder - - Parameters: - - cb i : Codebook (indexed cb[stages][levels][p]) format Q9.7 - u[] i : Vector to be encoded (prediction and mean removed) format Q9.7 - levels i : Number of levels in each stage - maxC i : Tree search size - stages i : Number of stages - N i : Vector dimension - maxN i : Codebook vector dimension - Idx o : Indices - - - Function: - multi stage vector quantisation - - Returns: - void -*/ -static void msvq_encoder (const Word16 * const cb[], /* i : Codebook (indexed cb[*stages][levels][p]) scaled with 8 bits */ - Word16 u[], /* i : Vector to be encoded (prediction and mean removed) */ - const Word16 levels[], /* i : Number of levels in each stage */ - Word16 maxC, /* i : Tree search size */ - Word16 stages, /* i : Number of stages */ - Word16 N, /* i : Vector dimension */ - Word16 maxN, /* i : Codebook vector dimension */ - Word16 Idx[] /* o : Indices */ - ) +void FdCng_encodeSID( + HANDLE_FD_CNG_ENC stenc, /* i/o: CNG structure containing all buffers and variables */ + Encoder_State *corest, + float preemph_fac +) { - Word32 *dist[2]; - Word32 t1, en, ss2, tmp; - const Word16 *cbp, *cb_stage, *p2; - Word16 *p1, *pTmp; - Word16 *indices[2], *resid[2], Tmp[M_MAX]; - Word16 i, j, m, s, c, c2, p_max; - Word16 parents[MBEST_MAX]; - Word32 dist_buf[2*MBEST_MAX]; - Word16 resid_buf[2*MBEST_MAX*M_MAX]; - Word16 idx_buf[2*MBEST_MAX*NSTAGES_MAX]; - - - - /*----------------------------------------------------------------* - * Allocate memory for previous (parent) and current nodes. - * Parent node is indexed [0], current node is indexed [1]. - *----------------------------------------------------------------*/ - - indices[0] = idx_buf; - indices[1] = idx_buf + maxC*stages; - set16_fx(idx_buf, 0, 2*stages*maxC); - - resid[0] = resid_buf; - resid[1] = resid_buf + maxC*N; - - dist[0] = dist_buf; - dist[1] = dist_buf + maxC; - - set16_fx(parents, 0, maxC); - - /*----------------------------------------------------------------* - * ISF weights are normalized, so it is always better to multiply it first - * Set up inital distance vector - *----------------------------------------------------------------*/ - - ss2 = L_mult(u[0], u[0]); - FOR (j=1; j < N; j++) - { - ss2 = L_mac(ss2, u[j], u[j]); - } - - FOR (j=0; j < maxC; j++) - { - dist[1][j] = ss2; - move32(); - } - - /* Set up inital error (residual) vectors */ - pTmp = resid[1]; - FOR (c=0; c 0) - { - p_max = add(i,0); - } - } - } - } - } /* FOR (j=0; jhFdCngCom; + float* E = stenc->msNoiseEst; + float gain; + int i, index; + float v[32], e; + int indices[32]; + float w[32]; + (void)preemph_fac; /* Init */ - st = stenc->hFdCngCom; - - E_Exp = stenc->msNoiseEst_exp; - move16(); - E_ExpLd64 = L_shl(E_Exp, WORD32_BITS-1-LD_DATA_SCALE); - E = stenc->msNoiseEst; - N = stenc->npartDec; - move16(); - - normFacN = getNormReciprocalWord16(N); - normShiftN = BASOP_util_norm_s_bands2shift(N); - - normFacGain = getNormReciprocalWord16(N_GAIN_MAX-N_GAIN_MIN); - normShiftGain = BASOP_util_norm_s_bands2shift(N_GAIN_MAX-N_GAIN_MIN); /* Convert to LOG */ - - /* e: Q14.23 format, v: Q9.23 format */ - e = L_deposit_l(0); - tmp = Mpy_32_32_r(L_shl(1, sub(31, E_Exp)), 214748); /* 1e-4f, Q31-E_Exp */ - FOR (i=0; iCngBandwidth, st->CngBitrate ); + /* Quantize gain */ + index = (short) floor( gain*1.5f + 60.f + 0.5f ); - /* Quantize gain, Q14.23 format */ - gain = L_add(gain, L_shr(gain,1)); - gain = L_add(gain, 507510784l/*60.5 Q23*/); - index = extract_l(L_shr(gain,WORD32_BITS-1-8)); - - - if ( index < 0 ) + if (index < 0) { index = 0; - move16(); } - if ( sub(index,127) > 0) + if (index > 127) { index = 127; - move16(); } - /* gain Q14.23 format */ - gain = L_shl(L_deposit_l(index), WORD32_BITS-1-8); - gain = L_sub(gain, 503316480l/*60.0 Q23*/); - gain = Mpy_32_16_1(gain, 21845/*2.0f/3.0f Q15*/); - + gain = ((float)index-60.f)/1.5f; /* Apply gain and undo log */ - - /* sidNoiseEst: format Q6.26, 0.66438561897 = log10(10)/log10(2.0) / 10.0 * 2.0 */ - - /* calculate worst case for scaling */ - maxVal = 0x80000000/*-1.0 Q31*/; - move32(); - FOR (i=0; i= 0) - { - maxVal = L_sub(maxVal, 33554432l/*0.015625 Q31*/); - sidNoiseEst_Exp = add(sidNoiseEst_Exp,1); - } - st->sidNoiseEstExp = sidNoiseEst_Exp; - move16(); - E_ExpLd64 = L_shl(sidNoiseEst_Exp, WORD32_BITS-1-LD_DATA_SCALE); - - FOR (i=0; isidNoiseEst[i] = BASOP_Util_InvLog2(tmp); - move32(); + st->sidNoiseEst[i] = (float)pow( 10.f, (v[i]+gain)/10.f ); } /* NB last band energy compensation */ - IF ( sub(st->CngBandwidth,NB) == 0 ) + if (st->CngBandwidth == NB) { - st->sidNoiseEst[N-1] = Mpy_32_16_1(st->sidNoiseEst[N-1], NB_LAST_BAND_SCALE); - move32(); + st->sidNoiseEst[N-1] *= NB_LAST_BAND_SCALE; } - test(); - if (sub( st->CngBandwidth,SWB) == 0 && L_sub(st->CngBitrate,ACELP_13k20) <= 0 ) + if ( st->CngBandwidth == SWB && st->CngBitrate <= ACELP_13k20 ) { - st->sidNoiseEst[N-1] = Mpy_32_16_1(st->sidNoiseEst[N-1], SWB_13k2_LAST_BAND_SCALE); - move32(); + st->sidNoiseEst[N-1] *= SWB_13k2_LAST_BAND_SCALE; } - /* Write bitstream */ - IF ( sub(corest->codec_mode, MODE2) == 0 ) + if ( corest->codec_mode == MODE2 ) { - FOR (i=0; ibwidth_fx, 2 ); - IF (sub(corest->L_frame_fx, L_FRAME16k) == 0) + push_indice( corest, IND_SID_TYPE, 1, 1 ); + push_indice( corest, IND_ACELP_16KHZ, corest->bwidth, 2 ); + push_indice( corest, IND_ACELP_16KHZ, corest->L_frame == L_FRAME16k ? 1 : 0, 1 ); + + for ( i=0; i cngNoiseLevel: Q6.26 format */ - scalebands(st->sidNoiseEst, stenc->partDec, stenc->npartDec, stenc->midbandDec, stenc->nFFTpartDec, sub(stenc->stopBandDec,stenc->startBandDec), st->cngNoiseLevel, 1); - st->cngNoiseLevelExp = st->sidNoiseEstExp; - move16(); - - - lpc_from_spectrum(st->cngNoiseLevel, st->cngNoiseLevelExp, stenc->startBandDec, stenc->stopFFTbinDec, st->fftlen, st->A_cng, M, preemph_fac ); + scalebands(st->sidNoiseEst, stenc->partDec, stenc->npartDec, stenc->midbandDec, stenc->nFFTpartDec, stenc->stopBandDec-stenc->startBandDec, st->cngNoiseLevel, 1); + lpc_from_spectrum(st->cngNoiseLevel, stenc->startBandDec, stenc->stopFFTbinDec, st->fftlen, st->fftSineTab, st->A_cng, preemph_fac ); + return; } -void generate_comfort_noise_enc (Encoder_State_fx *stcod, - Word16 Q_new, - Word16 gen_exc - ) +void generate_comfort_noise_enc( Encoder_State *stcod ) { - Word16 i, s, sn, cnt; - Word16 startBand2; - Word16 stopFFTbin2; - Word16 preemph_fac; - Word32 sqrtNoiseLevel; - Word16 randGaussExp; - Word16 fftBufferExp; - Word16 cngNoiseLevelExp; - Word16 *seed; - Word16 *timeDomainOutput; - Word32 *ptr_r, *ptr_i; - Word32 *cngNoiseLevel; - Word32 *ptr_level; - Word32 *fftBuffer; - Word16 old_syn_pe_tmp[16]; - Word16 tcx_transition = 0; - HANDLE_FD_CNG_ENC stenc = stcod->hFdCngEnc_fx; + short i; + float * ptr_r; + float * ptr_i; + HANDLE_FD_CNG_ENC stenc = stcod->hFdCngEnc; HANDLE_FD_CNG_COM st = stenc->hFdCngCom; - - - - /* Warning fix */ - s = 0; - - /* pointer initialization */ - - cngNoiseLevel = st->cngNoiseLevel; - cngNoiseLevelExp = st->cngNoiseLevelExp; - ptr_level = cngNoiseLevel; - seed = &(st->seed); - fftBuffer = st->fftBuffer; - timeDomainOutput = st->timeDomainBuffer; + float * cngNoiseLevel = st->cngNoiseLevel; + float * ptr_level = cngNoiseLevel; + short * seed = &(st->seed); + float scale = 1.f; + float * fftBuffer = st->fftBuffer; + float * timeDomainOutput = st->timeDomainBuffer; + float preemph_fac = stcod->preemph_fac; + int tcx_transition = 0; + float enr, att; + short bwidth = stcod->bwidth; + short CNG_mode = stcod->CNG_mode; /* Generate Gaussian random noise in real and imaginary parts of the FFT bins Amplitudes are adjusted to the estimated noise level cngNoiseLevel in each bin - scaling Gaussian random noise: format Q3.29 */ - sn = 0; - move16(); - IF ( s_and(cngNoiseLevelExp,1) != 0 ) + if (stenc->startBandDec==0) { - sn = add(sn,1); - cngNoiseLevelExp = add(cngNoiseLevelExp,sn); - move16(); - } - - randGaussExp = CNG_RAND_GAUSS_SHIFT; - move16(); - cnt = sub(stenc->stopFFTbinDec, stenc->startBandDec); - IF ( stenc->startBandDec == 0 ) - { - /* DC component in FFT */ - s = 0; - move16(); - sqrtNoiseLevel = Sqrt32(L_shr(*ptr_level,sn), &s); - - fftBuffer[0] = L_shl(Mpy_32_32(rand_gauss(seed),sqrtNoiseLevel),s); - move32(); - - /* Nyquist frequency is discarded */ - fftBuffer[1] = L_deposit_l(0); - - ptr_level = ptr_level + 1; + rand_gauss(&fftBuffer[0], seed); + fftBuffer[0] *= (float)sqrt(scale **ptr_level); /* DC component in FFT */ + ptr_level++; ptr_r = fftBuffer + 2; - cnt = sub(cnt, 1); } - ELSE + else { - startBand2 = shl(stenc->startBandDec,1); - set32_fx(fftBuffer, 0, startBand2); - ptr_r = fftBuffer + startBand2; + fftBuffer[0] = 0.f; + set_f( fftBuffer+2, 0.0f, 2*(stenc->startBandDec-1) ); + ptr_r = fftBuffer + 2*stenc->startBandDec; } - - sn = add(sn,1); ptr_i = ptr_r + 1; - FOR (i=0; i < cnt; i++) + for( ; ptr_level < cngNoiseLevel+stenc->stopFFTbinDec-stenc->startBandDec ; ptr_level++) { - s = 0; - move16(); - sqrtNoiseLevel = Sqrt32(L_shr(*ptr_level,sn), &s); - /* Real part in FFT bins */ - *ptr_r = L_shl(Mpy_32_32(rand_gauss(seed),sqrtNoiseLevel),s); - move32(); - + rand_gauss(ptr_r, seed); + (*ptr_r) *= (float)sqrt((scale **ptr_level)*0.5f); + ptr_r += 2; /* Imaginary part in FFT bins */ - *ptr_i = L_shl(Mpy_32_32(rand_gauss(seed),sqrtNoiseLevel),s); - move32(); - - ptr_r = ptr_r + 2; - ptr_i = ptr_i + 2; - ptr_level = ptr_level + 1; + rand_gauss(ptr_i, seed); + (*ptr_i) *= (float)sqrt((scale **ptr_level)*0.5f); + ptr_i += 2; } - /* Remaining FFT bins are set to zero */ - stopFFTbin2 = shl(stenc->stopFFTbinDec,1); - set32_fx(fftBuffer+stopFFTbin2, 0, sub(st->fftlen,stopFFTbin2)); - - fftBufferExp = add(shr(cngNoiseLevelExp,1),randGaussExp); + set_f( fftBuffer+2*stenc->stopFFTbinDec, 0.0f, st->fftlen-2*stenc->stopFFTbinDec); + /* Nyquist frequency is discarded */ + fftBuffer[1] = 0.f; /* If previous frame is active, reset the overlap-add buffer */ - IF ( L_sub(stcod->last_core_brate_fx,SID_2k40) > 0 ) + if( stcod->last_core_brate > SID_2k40 ) { - set16_fx(st->olapBufferSynth, 0, st->fftlen); - test(); - test(); - IF ( (L_sub(stcod->last_core_fx,ACELP_CORE) > 0 && sub(stcod->codec_mode,MODE2) == 0) || sub(stcod->codec_mode,MODE1) == 0 ) + set_f( st->olapBufferSynth, 0.0f, st->fftlen); + if( (stcod->last_core>0 && stcod->codec_mode == MODE2)||stcod->codec_mode == MODE1 ) { tcx_transition = 1; - move16(); } } /* Perform STFT synthesis */ - SynthesisSTFT (fftBuffer, fftBufferExp, timeDomainOutput, st->olapBufferSynth, st->olapWinSyn, - tcx_transition, - st, gen_exc, &Q_new); + SynthesisSTFT(fftBuffer, timeDomainOutput, st->olapBufferSynth, st->olapWinSyn, tcx_transition, st ); + /* update CNG excitation energy for LP_CNG */ + + /* calculate the residual signal energy */ + enr = dotp( st->exc_cng, st->exc_cng, st->frameSize ) / st->frameSize; + + /* convert log2 of residual signal energy */ + enr = (float)log10( enr + 0.1f ) / (float)log10( 2.0f ); + + /* decrease the energy in case of WB input */ + if( bwidth != NB ) { - Word32 Lener, att; - Word16 exp; - /* update CNG excitation energy for LP_CNG */ - - /* calculate the residual signal energy */ - /*enr = dotp( st->exc_cng, st->exc_cng, st->frameSize ) / st->frameSize;*/ - Lener = Dot_productSq16HQ(1,st->exc_cng,stcod->L_frame_fx,&exp); - exp = add(sub(shl(sub(15,Q_new),1),8),exp); /*8 = log2(256)*/ - - /* convert log2 of residual signal energy */ - /*(float)log10( enr + 0.1f ) / (float)log10( 2.0f );*/ - Lener = BASOP_Util_Log2(Lener); - Lener = L_add(Lener,L_shl(L_deposit_l(exp),WORD32_BITS-1-LD_DATA_SCALE)); /*Q25*/ - if(sub(stcod->L_frame_fx,L_FRAME16k) == 0) + if( bwidth == WB ) { - Lener = L_sub(Lener, 10802114l/*0.3219280949f Q25*/); /*log2(320) = 8.3219280949f*/ + if( CNG_mode >= 0 ) + { + /* Bitrate adapted attenuation */ + att = ENR_ATT[CNG_mode]; + } + else + { + /* Use least attenuation for higher bitrates */ + att = ENR_ATT[4]; + } } - /* decrease the energy in case of WB input */ - IF( sub(stcod->bwidth_fx, NB) != 0 ) + else { - IF( sub(stcod->bwidth_fx,WB) == 0 ) - { - IF( stcod->CNG_mode_fx >= 0 ) - { - /* Bitrate adapted attenuation */ - att = L_shl(L_deposit_l(ENR_ATT_fx[stcod->CNG_mode_fx]),17); - } - ELSE - { - /* Use least attenuation for higher bitrates */ - att = L_shl(L_deposit_l(ENR_ATT_fx[4]),17); - } - } - ELSE - { - att = 384<<17; - move32();/*1.5 Q8<<17=Q25*/ - } - Lener = L_sub(Lener, att ); + att = 1.5f; } - /*stdec->lp_ener = 0.8f * stcod->lp_ener + 0.2f * pow( 2.0f, enr );*/ - Lener = BASOP_util_Pow2(Lener, 6, &exp); - Lener = Mult_32_16(Lener, 6554/*0.2f Q15*/); - exp = sub(25,exp); - Lener = L_shr(Lener, exp); /*Q6*/ - stcod->lp_ener_fx = L_add(Mult_32_16(stcod->lp_ener_fx, 26214/*0.8f Q15*/), Lener); /*Q6*/ + + enr -= att; } + stcod->lp_ener = 0.8f * stcod->lp_ener + 0.2f * pow( 2.0f, enr ); + + /* Overlap-add when previous frame is active */ - test(); - IF ( ( L_sub(stcod->last_core_brate_fx,SID_2k40) > 0 ) && ( sub(stcod->codec_mode,MODE2) == 0 ) ) + if( stcod->last_core_brate > SID_2k40 && stcod->codec_mode == MODE2 ) { - Word32 old_exc_ener, gain, noise32; - Word16 seed_loc, lpcorder, old_syn, tmp, gain16, N, N2, N4, N8; - Word16 old_exc_ener_exp, gain_exp; - Word16 normFacE, normShiftE, normShiftEM1; - Word16 normFacG, normShiftG, normShiftGM1; - Word16 noiseExp, *old_exc, old_Aq[M+1], *old_syn_pe; - Word16 noise[640], normShiftP2; - Word16 Q_exc, Q_syn; + float noise[2048], old_exc_ener = 0.f, gain = 0.f, tmp; + int N = st->frameSize; + short seed_loc = st->seed; + float *old_exc, old_Aq[M+1], *old_syn_pe, old_syn; - - assert(st->frameSize <= 640); - - seed_loc = st->seed; - move16(); - N = st->frameSize; - move16(); - N2 = shr(st->frameSize,1); - - IF ( sub(stcod->last_core_fx,ACELP_CORE) > 0 ) + if( stcod->last_core > 0 ) { - Word16 left_overlap_mode; - left_overlap_mode = stcod->tcx_cfg.tcx_last_overlap_mode; - move16(); - if (sub(left_overlap_mode, ALDO_WINDOW) == 0) - { - left_overlap_mode = FULL_OVERLAP; - move16(); - } - tcx_windowing_synthesis_current_frame( timeDomainOutput, stcod->tcx_cfg.tcx_mdct_window, /*Keep sine windows for limiting Time modulation*/ stcod->tcx_cfg.tcx_mdct_window_half, stcod->tcx_cfg.tcx_mdct_window_minimum, stcod->tcx_cfg.tcx_mdct_window_length, stcod->tcx_cfg.tcx_mdct_window_half_length, - stcod->tcx_cfg.tcx_mdct_window_min_length, - 0, - left_overlap_mode, - NULL, - NULL, - NULL, - NULL, - NULL, - N/2, - shr(sub(abs_s(stcod->tcx_cfg.tcx_offset), stcod->tcx_cfg.tcx_offset), 1), /* equivalent to: stdec->tcx_cfg.tcx_offset<0?-stdec->tcx_cfg.tcx_offset:0 */ - 1, - 0, - 0 - ); + stcod->tcx_cfg.tcx_mdct_window_min_length, 0, + stcod->tcx_cfg.tcx_last_overlap_mode==ALDO_WINDOW?FULL_OVERLAP:stcod->tcx_cfg.tcx_last_overlap_mode, + NULL, NULL, NULL, NULL, NULL, N/2, stcod->tcx_cfg.tcx_offset<0?-stcod->tcx_cfg.tcx_offset:0, + 1, 0, 0 ); - IF (stcod->tcx_cfg.last_aldo != 0) + if(stcod->tcx_cfg.last_aldo) { - FOR (i=0; iframeSize; i++) + for (i=0; iframeSize; i++) { - timeDomainOutput[i] = add(timeDomainOutput[i], shr_r(stcod->old_out_fx[i+NS2SA(stcod->sr_core, N_ZERO_MDCT_NS)],stcod->Q_old_out)); - move16(); + timeDomainOutput[i] += stcod->old_out[i+NS2SA(stcod->sr_core, N_ZERO_MDCT_NS)]; } } - ELSE + else { tcx_windowing_synthesis_past_frame( stcod->LPDmem.Txnq, - stcod->tcx_cfg.tcx_aldo_window_1_trunc, - stcod->tcx_cfg.tcx_mdct_window_half, - stcod->tcx_cfg.tcx_mdct_window_minimum, - stcod->tcx_cfg.tcx_mdct_window_length, - stcod->tcx_cfg.tcx_mdct_window_half_length, - stcod->tcx_cfg.tcx_mdct_window_min_length, - stcod->tcx_cfg.tcx_last_overlap_mode - ); + stcod->tcx_cfg.tcx_aldo_window_1_trunc, + stcod->tcx_cfg.tcx_mdct_window_half, + stcod->tcx_cfg.tcx_mdct_window_minimum, + stcod->tcx_cfg.tcx_mdct_window_length, + stcod->tcx_cfg.tcx_mdct_window_half_length, + stcod->tcx_cfg.tcx_mdct_window_min_length, + stcod->tcx_cfg.tcx_last_overlap_mode ); - FOR (i=0; itcx_cfg.tcx_mdct_window_length; i++) { - timeDomainOutput[i] = add(timeDomainOutput[i],shl(stcod->LPDmem.Txnq[i],TCX_IMDCT_HEADROOM)); - move16(); + timeDomainOutput[i] += stcod->LPDmem.Txnq[i]; } } } - ELSE + else { - - /* - - the scaling of the LPCs (e.g. old_Aq) is always Q12 (encoder or decoder) - - - the scaling of the deemphasized signals (e.g. old_syn) is always Q0 (encoder or decoder) - - - the scaling of the excitation signals in the encoder (e.g. old_exc) is Q_new - - the scaling of the preemphasized signals in the encoder (e.g. old_syn_pe) is Q_new-1 - - - the scaling of the excitation signals in the decoder (e.g. old_exc) is Q_exc (or stdec->Q_exc) - - the scaling of the preemphasized signals in the decoder (e.g. old_syn_pe) is Q_syn (or stdec->Q_syn) - */ - - lpcorder = M; - move16(); - E_LPC_f_lsp_a_conversion(stcod->lsp_old_fx, old_Aq, M); - old_exc = stcod->LPDmem.old_exc+sub(L_EXC_MEM,N2); + lsp2a_stab( stcod->lsp_old, old_Aq, M ); + old_exc = stcod->LPDmem.old_exc+L_EXC_MEM-(N/2); old_syn_pe = stcod->LPDmem.mem_syn2; - old_syn = stcod->LPDmem.syn[lpcorder]; - move16(); - preemph_fac = stcod->preemph_fac; - move16(); - Q_exc = Q_new; - Q_syn = sub(Q_new,1); - - /* shift to be in the range of values supported by getNormReciprocalWord16() */ - N8 = shr(N2, CNG_NORM_RECIPROCAL_RANGE_SHIFT); - - assert( N2 == (N8<LPDmem.syn[M]; + for ( i=0; iolapWinSyn[i].v.re); - timeDomainOutput[i] = add(timeDomainOutput[i],tmp); - move16(); - tmp = mult(noise[i+N4],st->olapWinSyn[N4-1-i].v.im); - timeDomainOutput[i+N4] = add(timeDomainOutput[i+N4],tmp); - move16(); + timeDomainOutput[i] += noise[i] * st->olapWinSyn[N/2+i]; } } } + return; } - diff --git a/src/libs/libevs/lib_enc/find_tar.cpp b/src/libs/libevs/lib_enc/find_tar.cpp new file mode 100644 index 00000000..a666a673 --- /dev/null +++ b/src/libs/libevs/lib_enc/find_tar.cpp @@ -0,0 +1,86 @@ +/*==================================================================================== + EVS Codec 3GPP TS26.443 Nov 13, 2018. Version 12.11.0 / 13.7.0 / 14.3.0 / 15.1.0 + ====================================================================================*/ + +#include "options.h" +#include "cnst.h" +#include "prot.h" + +/*-------------------------------------------------------------------* + * find_targets() + * + * Find the target vectors for excitaiton search: + *-------------------------------------------------------------------*/ + +void find_targets( + const float *speech, /* i : pointer to the speech frame */ + const float *mem_syn, /* i : memory of the synthesis filter */ + const short i_subfr, /* i : subframe index */ + float *mem_w0, /* i/o: weighting filter denominator memory */ + const float *p_Aq, /* i : interpolated quantized A(z) filter */ + const float *res, /* i : residual signal */ + const short L_subfr, /* i : length of vectors for gain quantization */ + const float *Ap, /* i : unquantized A(z) filter with bandwidth expansion */ + const float tilt_fac, /* i : tilt factor */ + float *xn, /* o : Close-loop Pitch search target vector */ + float *cn, /* o : target vector in residual domain */ + float *h1 /* o : impulse response of weighted synthesis filter */ +) +{ + short i; + float error[M+5*L_SUBFR]; /* error of quantization */ + float tmp_fl[L_SUBFR+M], tmp; + + /*------------------------------------------------------------------------* + * Find the target vector for excitation search: + * + * |------| res[n] + * speech[n]---| A(z) |-------- + * |------| | |--------| error[n] |------| + * zero -- (-)--| 1/A(z) |-----------| W(z) |-- target + * exc |--------| |------| + * + * Instead of subtracting the zero-input response of filters from + * the weighted input speech, the above configuration is used to + * compute the target vector. + *-----------------------------------------------------------------------*/ + + for ( i=0; i cn[] */ + set_f( tmp_fl, 0, M ); + mvr2r( xn, tmp_fl+M, L_subfr/2 ); + tmp = 0.0f; + + preemph( tmp_fl+M, tilt_fac, L_subfr/2, &tmp ); + syn_filt( Ap, M, tmp_fl+M, tmp_fl+M, L_subfr/2, tmp_fl, 0 ); + residu( p_Aq, M, tmp_fl+M, cn, L_subfr/2 ); + + /* second half: res[] --> cn[] (approximated and faster) */ + mvr2r( &res[i_subfr+(L_subfr/2)], cn+(L_subfr/2), L_subfr/2 ); + } + + /*-----------------------------------------------------------------* + * Compute impulse response h1[] of the weighted synthesis filter + *-----------------------------------------------------------------*/ + + set_f( h1, 0, L_subfr ); + mvr2r( Ap, h1, M+1 ); + syn_filt( p_Aq, M, h1, h1, L_subfr, h1+(M+1), 0 ); + tmp = 0.0f; + deemph( h1, tilt_fac, L_subfr, &tmp ); + + return; +} diff --git a/src/libs/libevs/lib_enc/find_tar_fx.cpp b/src/libs/libevs/lib_enc/find_tar_fx.cpp deleted file mode 100755 index d0e5c170..00000000 --- a/src/libs/libevs/lib_enc/find_tar_fx.cpp +++ /dev/null @@ -1,155 +0,0 @@ -/*==================================================================================== - EVS Codec 3GPP TS26.442 Apr 03, 2018. Version 12.11.0 / 13.6.0 / 14.2.0 - ====================================================================================*/ - -#include "options.h" /* Compilation switches */ -#include "prot_fx.h" /* Function prototypes */ -#include "cnst_fx.h" /* Common constants */ -#include "basop_util.h" -#include "stl.h" - - - -void find_targets_fx( - const Word16 *speech, /* i : pointer to the speech frame Q_new-1*/ - const Word16 *mem_syn, /* i : memory of the synthesis filter Q_new-1*/ - const Word16 i_subfr, /* i : subframe index */ - Word16 *mem_w0, /* i/o: weighting filter denominator memory Q_new-1*/ - const Word16 *p_Aq, /* i : interpolated quantized A(z) filter Q12*/ - const Word16 *res, /* i : residual signal Q_new*/ - const Word16 L_subfr, /* i : length of vectors for gain quantization */ - const Word16 *Ap, /* i : unquantized A(z) filter with bandwidth expansion Q12*/ - Word16 tilt_fac, /* i : tilt factor Q15 */ - Word16 *xn, /* o : Close-loop Pitch search target vector Q_new-1*/ - Word16 *cn /* o : target vector in residual domain Q_new*/ - ,Word16 *h1 -) -{ - Word16 i; - Word16 temp[M+5*L_SUBFR]; /* error of quantization */ - Word16 scale,scaleq,j,d,s,s2,tmp; - Word16 Aqs[M+1]; - Word32 Ltmp; - /*------------------------------------------------------------------------* - * Find the target vector for excitation search: - * - * |------| res[n] - * speech[n]---| A(z) |-------- - * |------| | |--------| error[n] |------| - * zero -- (-)--| 1/A(z) |-----------| W(z) |-- target - * exc |--------| |------| - * - * Instead of subtracting the zero-input response of filters from - * the weighted input speech, the above configuration is used to - * compute the target vector. - *-----------------------------------------------------------------------*/ - FOR (i=0; i cn[] */ - temp[0] = 0; - move16(); - preemph_copy_fx(xn, cn, tilt_fac, L_SUBFR/2, temp); - syn_filt_s_lc_fx(1, Ap, cn, temp, L_SUBFR/2); /* Q-1 -> Q-2 */ - Residu3_lc_fx(p_Aq, M, temp, cn, L_SUBFR/2, 1); /* Q-2 -> Q-1 */ - Scale_sig(cn, L_SUBFR/2,1); - - /* second half: res[] --> cn[] (approximated and faster) */ - Copy(&res[i_subfr+(L_SUBFR/2)], cn+(L_SUBFR/2), L_SUBFR/2); - } - - /*---------------------------------------------------------------* - * Compute impulse response, h1[], of weighted synthesis filter * - *---------------------------------------------------------------*/ - - scale = norm_s( Ap[0] ); - scaleq = norm_s( p_Aq[0] ); - d = sub( scaleq, scale ); - IF ( d >= 0 ) - { - Copy( p_Aq, Aqs, M+1 ); - s = add( scaleq, 1 ); - s2 = shr( 16384, d ); - } - ELSE - { - Copy_Scale_sig( p_Aq, Aqs, M+1, d ); - s = add( scale, 1 ); - s2 = 16384; - } - Overflow = 0; - move16(); - FOR (i = 0; i < M; i++) - { - Ltmp = L_mult(Ap[i], s2); - FOR (j = 1; j <= i; j++) - { - Ltmp = L_msu(Ltmp, Aqs[j], h1[i-j]); - } - h1[i] = round_fx(L_shl(Ltmp, s)); - } - Ltmp = L_mult(Ap[i], s2); - FOR (j = 1; j <= M; j++) - { - Ltmp = L_msu(Ltmp, Aqs[j], h1[i-j]); - } - h1[M] = round_fx(L_shl(Ltmp, s)); - FOR (i=M+1; i < L_subfr; i++) - { - Ltmp = L_msu(0, Aqs[1], h1[i-1]); - FOR (j = 2; j <= M; j++) - { - Ltmp = L_msu(Ltmp, Aqs[j], h1[i-j]); - } - h1[i] = round_fx(L_shl(Ltmp, s)); - } - IF(Overflow) - { - s2 = shr(s2, 1); - FOR (i = 0; i < M; i++) - { - Ltmp = L_mult(Ap[i], s2); - FOR (j = 1; j <= i; j++) - { - Ltmp = L_msu(Ltmp, Aqs[j], h1[i-j]); - } - h1[i] = round_fx(L_shl(Ltmp, s)); - } - Ltmp = L_mult(Ap[i], s2); - FOR (j = 1; j <= M; j++) - { - Ltmp = L_msu(Ltmp, Aqs[j], h1[i-j]); - } - h1[M] = round_fx(L_shl(Ltmp, s)); - FOR (i=M+1; i < L_subfr; i++) - { - Ltmp = L_msu(0, Aqs[1], h1[i-1]); - FOR (j = 2; j <= M; j++) - { - Ltmp = L_msu(Ltmp, Aqs[j], h1[i-j]); - } - h1[i] = round_fx(L_shl(Ltmp, s)); - } - } - - tmp = 0; - Deemph2(h1, tilt_fac, L_subfr, &tmp); - - return; - -} diff --git a/src/libs/libevs/lib_enc/find_tilt.cpp b/src/libs/libevs/lib_enc/find_tilt.cpp new file mode 100644 index 00000000..087b2c05 --- /dev/null +++ b/src/libs/libevs/lib_enc/find_tilt.cpp @@ -0,0 +1,183 @@ +/*==================================================================================== + EVS Codec 3GPP TS26.443 Nov 13, 2018. Version 12.11.0 / 13.7.0 / 14.3.0 / 15.1.0 + ====================================================================================*/ + +#include +#include "options.h" +#include "cnst.h" +#include "prot.h" + +/*---------------------------------------------------------------------* + * Local constants + *---------------------------------------------------------------------*/ + +#define FACT 3.0f /* background noise energy estimation adjusting factor - to maintain the ADR about the same */ +#define TH_COR 0.6f /* Minimum correlation for per bin processing */ +#define TH_D 50.0f /* Difference limit between nearest harmonic and a frequency bin */ +#define TH_PIT (INT_FS_12k8 / (2.0f * TH_D)) /* Maximum pitch for per bin processing */ + +/*-------------------------------------------------------------------* + * find_tilt() + * + * Find LF/HF energy ratio + *-------------------------------------------------------------------*/ + +void find_tilt( + const float fr_bands[], /* i : energy in frequency bands */ + const float bckr[], /* i : per band background noise energy estimate */ + float ee[2], /* o : lf/hf E ration for present frame */ + const short pitch[3], /* i : open loop pitch values for 3 half-frames */ + const float voicing[3], /* i : normalized correlation for 3 half-frames */ + const float *lf_E, /* i : per bin energy for low frequencies */ + const float corr_shift, /* i : normalized correlation correction */ + const short bwidth, /* i : input signal bandwidth */ + const short max_band, /* i : maximum critical band */ + float hp_E[], /* o : energy in HF */ + const short codec_mode, /* i : Mode 1 or 2 */ + float *bckr_tilt_lt, /* i/o: lf/hf E ratio of background noise */ + short Opt_vbr_mode +) +{ + float lp_bckr, hp_bckr, lp_E, freq, f0, f1, f2, mean_voi, bin; + const float *pt_bands, *pt_bckr, *tmp_E, *hf_bands, *pt_E; + short cnt, i, nb_bands; + float th_pit; + + /*-----------------------------------------------------------------* + * Initializations + *-----------------------------------------------------------------*/ + + th_pit = TH_PIT; + + if( bwidth != NB ) + { + /* WB processing */ + bin = BIN; /* First useful frequency bin ~ 50 Hz */ + pt_bands = fr_bands; + tmp_E = lf_E; + pt_bckr = bckr; + nb_bands = 10; + } + else + { + /* NB processing */ + bin = 3.0f*BIN; /* first useful frequency bin ~ 150 Hz */ + pt_bands = fr_bands+1; /* exlcude 1st critical band */ + tmp_E = lf_E + 2; /* start at the 3rd bin (150 Hz) */ + pt_bckr = bckr+1; /* exclude 1st critical band */ + nb_bands = 9; /* nb. of "low" frequency bands taken into account in NB processing */ + } + + /*-----------------------------------------------------------------* + * Find spectrum tilt + *-----------------------------------------------------------------*/ + + pt_E = tmp_E; /* pointer at the 1st useful element of the per-bin energy vector */ + hf_bands = fr_bands; + + /* bckr + voicing */ + lp_bckr = mean( pt_bckr, nb_bands ); /* estimated noise E in first critical bands, up to 1270 Hz */ + hp_bckr = 0.5f * (bckr[max_band-1] + bckr[max_band]); /* estimated noise E in last 2 critical bands */ + *bckr_tilt_lt = 0.9f * *bckr_tilt_lt + 0.1f * lp_bckr / hp_bckr; + + if ( codec_mode == MODE2 + || Opt_vbr_mode + ) + { + lp_bckr *= FACT; + hp_bckr *= FACT; + } + + mean_voi = 0.5f * (voicing[1] + voicing[2]) + corr_shift; + f0 = ((float)INT_FS_12k8) / pitch[2]; + + for( i=0; i<2; i++ ) + { + hp_E[i] = 0.5f * (hf_bands[max_band-1] + hf_bands[max_band]) - hp_bckr; /* average E in last 2 critical bands */ + + if ( !Opt_vbr_mode) + { + if( hp_E[i] < E_MIN ) + { + /* to avoid division by 0 */ + hp_E[i] = E_MIN; + } + + } + else + { + if( hp_E[i] < 1.0f ) + { + /* to avoid division by 0 */ + hp_E[i] = 1.0f; + } + } + + + if( (mean_voi > TH_COR) && (pitch[2] < th_pit) ) + { + /* high-pitched voiced frames */ + freq = bin; /* 1st useful frequency bin */ + cnt = 0; + lp_E = 0.0f; + f1 = 1.5f * f0; /* middle between 2 harmonics */ + f2 = f0; + + while( freq <= 1270.0f ) /* end frequency of 10th critical band */ + { + /*pt_E*/ + while( freq <= f1 ) + { + if( fabs(freq-f2) < TH_D ) /* include only bins sufficiently close to harmonics */ + { + lp_E += *pt_E; + cnt++; + } + freq += BIN; + pt_E++; + } + f1 += f0; + f2 += f0; /* next harmonic */ + } + + lp_E = lp_E / (float)cnt - lp_bckr; + pt_E = tmp_E + VOIC_BINS; /* update for next half-frame */ + } + else + { + /* other than high-pitched voiced frames */ + lp_E = mean( pt_bands, nb_bands ) - lp_bckr; /* average E in first critical bands, up to 1270 Hz */ + } + + if ( !Opt_vbr_mode) + { + if( lp_E < E_MIN ) + { + /* avoid negative E due to noise subtraction */ + lp_E = E_MIN; + } + } + else + { + + if( lp_E < 0.0f ) + { + /* avoid negative E due to noise subtraction */ + lp_E = 0.0f; + } + } + + /* calculate the tilt (LF/HF ratio) */ + ee[i] = lp_E / hp_E[i]; + + if( bwidth == NB ) /* for NB input, compensate for the missing bands */ + { + ee[i] *= 6.0f; + } + + pt_bands += NB_BANDS; /* update pointers for the next half-frame */ + hf_bands += NB_BANDS; + } + + return; +} diff --git a/src/libs/libevs/lib_enc/find_tilt_fx.cpp b/src/libs/libevs/lib_enc/find_tilt_fx.cpp deleted file mode 100755 index ebf402c3..00000000 --- a/src/libs/libevs/lib_enc/find_tilt_fx.cpp +++ /dev/null @@ -1,229 +0,0 @@ -/*==================================================================================== - EVS Codec 3GPP TS26.442 Apr 03, 2018. Version 12.11.0 / 13.6.0 / 14.2.0 - ====================================================================================*/ - -#include "options.h" /* Compilation switches */ -#include "cnst_fx.h" /* Common constants */ -#include "prot_fx.h" /* Function prototypes */ -#include "stl.h" -#include "basop_util.h" - -/*-------------------------------------------------------------------* - * find_tilt() - * - * Find LF/HF energy ratio - *-------------------------------------------------------------------*/ - -void find_tilt_fx( - const Word32 fr_bands[], /* i : energy in frequency bands Q_new + Q_SCALE*/ - const Word32 bckr[], /* i : per band background noise energy estimate Q_new + Q_SCALE*/ - Word32 ee[2], /* o : lf/hf E ration for present frame Q6*/ - const Word16 pitch[3], /* i : open loop pitch values for 3 half-frames Q0*/ - const Word16 voicing[3], /* i : normalized correlation for 3 half-frames Q15*/ - const Word32 *lf_E, /* i : per bin energy for low frequencies Q_new + Q_SCALE - 2*/ - const Word16 corr_shift, /* i : normalized correlation correction Q15*/ - const Word16 bwidth, /* i : input signal bandwidth */ - const Word16 max_band, /* i : maximum critical band */ - Word32 hp_E[], /* o : energy in HF Q_new + Q_SCALE*/ - const Word16 codec_mode, /* i : MODE1 or MODE2 */ - const Word16 Q_new, /* i : scaling factor */ - Word32 *bckr_tilt_lt /* i/o: lf/hf E ratio of background noise Q16 */ - ,Word16 Opt_vbr_mode -) -{ - Word32 lp_bckr = 0, hp_bckr = 0, lp_E, Ltmp; - const Word32 *pt_E, *pt_bands, *pt_bckr, *hf_bands, *tmp_E; - Word16 tmp, freq, f0, f1, f2, mean_voi, bin; - Word16 i, nb_bands; - Word16 e_tmp, m_tmp; - Word16 m_Fs, e_Fs; - Word16 m_cnt, e_cnt; - Word16 m_hpE, e_hpE; - Word16 scaling; - /*-----------------------------------------------------------------* - * Initializations - *-----------------------------------------------------------------*/ - - scaling = add(Q_new, QSCALE); - IF( sub(bwidth,NB) != 0 ) - { - /* WB processing */ - bin = BIN4_FX; - move16(); /* First useful frequency bin ~ 50 Hz */ - pt_bands = fr_bands; - tmp_E = lf_E; - pt_bckr = bckr; - nb_bands = 10; - move16(); - } - ELSE - { - /* NB processing */ - bin = add(shl(BIN4_FX,1), BIN4_FX); /* First useful frequency bin ~ 150 Hz */ - pt_bands = fr_bands+1; /* Exlcude 1st critical band */ - tmp_E = lf_E + 2; /* Start at the 3rd bin (150 Hz) */ - pt_bckr = bckr+1; /* Exlcude 1st critical band */ - nb_bands = 9; - move16(); /* Nb. of "low" frequency bands taken into account in NB processing */ - } - - /*-----------------------------------------------------------------* - * Find spectrum tilt - *-----------------------------------------------------------------*/ - - pt_E = tmp_E; /* Point at the 1st useful element of the per-bin energy vector */ - hf_bands = fr_bands; - - /* bckr + voicing */ - /*lp_bckr = mean( pt_bckr, nb_bands );*/ /* estimated noise E in first critical bands, up to 1270 Hz */ - lp_bckr = Mean32(pt_bckr, nb_bands); - /*hp_bckr = 0.5f * (bckr[max_band-1] + bckr[max_band]);*/ /* estimated noise E in last 2 critical bands */ - hp_bckr = L_shr(L_add(bckr[max_band-1] , bckr[max_band]),1); - if (hp_bckr == 0) /* Avoid division by zero. */ - { - hp_bckr = L_deposit_l(1); - } - tmp = BASOP_Util_Divide3232_Scale( lp_bckr, hp_bckr, &e_tmp ); - Ltmp = L_shr_r( L_deposit_h( tmp ), sub( 15, e_tmp ) ); - *bckr_tilt_lt = L_add( Mpy_32_16_r( *bckr_tilt_lt, 29491 ), Mpy_32_16_r( Ltmp, 3277 ) ); - - test(); - IF ( sub(codec_mode,MODE2) == 0 || Opt_vbr_mode == 1) - { - /*lp_bckr *= FACT;*/ - /*hp_bckr *= FACT;*/ - lp_bckr = L_add(L_shl(lp_bckr,1),lp_bckr); - hp_bckr = L_add(L_shl(hp_bckr,1),hp_bckr); - } - /*mean_voi = 0.5f * (voicing[1] + voicing[2]) + corr_shift;*/ - Ltmp = L_mult(voicing[1], 16384); - Ltmp = L_mac(Ltmp, voicing[2], 16384); - Ltmp = L_mac(Ltmp,corr_shift, 32767); - mean_voi = round_fx(Ltmp); - - /*f0 = INT_FS_FX / pitch[2];*/ - e_tmp = norm_s(pitch[2]); - m_tmp = shl(pitch[2], e_tmp); - - m_Fs = div_s(INT_FS_FX, m_tmp); - e_Fs = sub(15, e_tmp); - f0 = shr(m_Fs, sub(e_Fs,4)); /* Q4 */ - - FOR( i=0; i<2; i++ ) - { - /*hp_E[i] = 0.5f * (hf_bands[max_band-1] + hf_bands[max_band]) - hp_bckr; *//* averaged E in last 2 critical bands */ - Ltmp = L_add(L_shr(hf_bands[max_band-1], 1), L_shr(hf_bands[max_band], 1)); - hp_E[i] = L_sub(Ltmp, hp_bckr); - IF ( Opt_vbr_mode == 0 ) - { - hp_E[i] = L_max(hp_E[i], L_shl(E_MIN_FX, Q_new)); - move32(); - } - ELSE - { - hp_E[i] = L_max(hp_E[i], L_shl(1, scaling)); - move32(); - } - - test(); - IF(sub(mean_voi,TH_COR_FX) > 0 && sub(pitch[2], TH_PIT_FX) < 0) /* High-pitched voiced frames */ - { - freq = bin; - move16(); /* 1st useful frequency bin */ - m_cnt = 0; - move16(); - lp_E = L_deposit_l(0); - - f1 = add(shr(f0,1),f0); /* Middle between 2 harmonics */ - f2 = f0; - move16(); - WHILE(sub(freq, 20320) <= 0) /* End frequency of 10th critical band */ - { - FOR (; freq <= f1; freq += BIN4_FX) - { - /* include only bins sufficiently close to harmonics */ - tmp = sub(freq, f2); - IF(L_mac0(-(Word32)TH_D_FX*TH_D_FX, tmp, tmp) < 0) - { - lp_E = L_add(*pt_E, lp_E); - m_cnt = add(m_cnt, 1); - } - pt_E++; - } - f1 = add(f1,f0); - f2 = add(f2,f0); - } - /*lp_E = lp_E / (float)cnt - lp_bckr;*/ - e_tmp = sub(norm_l(lp_E), 1); - m_tmp = extract_h(L_shl(lp_E, e_tmp)); - - e_tmp = sub(e_tmp,2); /* lf_e divided by 4 in anal_sp */ - - e_cnt = norm_s(m_cnt); - m_cnt = shl(m_cnt, e_cnt); - - m_tmp = div_s(m_tmp, m_cnt); - e_tmp = sub(e_tmp, e_cnt); - - lp_E = L_sub(L_shr(m_tmp, sub(e_tmp, 1)), lp_bckr); - - - pt_E = tmp_E + VOIC_BINS; /* Update for next half-frame */ - } - ELSE /* Other than high-pitched voiced frames */ - { - /*lp_E = mean( pt_bands, nb_bands ) - lp_bckr;*/ /* averaged E in first critical bands, up to 1270 Hz */ - lp_E = L_sub(Mean32( pt_bands, nb_bands ) , lp_bckr); - } - IF ( Opt_vbr_mode == 0 ) - { - lp_E = L_max(lp_E, L_shl(E_MIN_FX,Q_new)); - } - ELSE - { - lp_E = L_max(lp_E, 0); - } - /*ee[i] = lp_E / hp_E[i];*/ /* LF/HF ratio */ - test(); - IF (lp_E != 0 && hp_E[i] != 0) - { - e_tmp = sub(norm_l(lp_E), 1); - m_tmp = extract_h(L_shl(lp_E, e_tmp)); - e_hpE = norm_l(hp_E[i]); - m_hpE = extract_h(L_shl(hp_E[i], e_hpE)); - m_tmp = div_s(m_tmp, m_hpE); - e_tmp = sub(e_tmp, e_hpE); - - ee[i] = L_shr(m_tmp, add(e_tmp, 15-6)); /* ee in Q6 */ - } - ELSE IF (lp_E == 0) - { - ee[i] = L_deposit_l(0); - } - ELSE - { - ee[i] = MAX_32; - } - - IF( sub(bwidth,NB) == 0 ) /* For NB input, compensate for the missing bands */ - { - Ltmp = L_shl(ee[i], 3); - IF (L_sub(Ltmp, MAX_32) == 0) /* if Overflow: Compute with less precision */ - { - Ltmp = Mult_32_16(ee[i], 24576); /* 6/8 */ - ee[i] = L_shl(Ltmp, 3); - move32(); /* x8 */ - } - ELSE - { - ee[i] = Mult_32_16(Ltmp, 24576); - move32();/* 6/8 */ - } - } - - pt_bands += NB_BANDS; /* Update for next half-frame */ - hf_bands += NB_BANDS; - } - - return; -} diff --git a/src/libs/libevs/lib_enc/find_uv.cpp b/src/libs/libevs/lib_enc/find_uv.cpp old mode 100755 new mode 100644 index fa55b3e1..0fa00d36 --- a/src/libs/libevs/lib_enc/find_uv.cpp +++ b/src/libs/libevs/lib_enc/find_uv.cpp @@ -1,172 +1,138 @@ /*==================================================================================== - EVS Codec 3GPP TS26.442 Apr 03, 2018. Version 12.11.0 / 13.6.0 / 14.2.0 + EVS Codec 3GPP TS26.443 Nov 13, 2018. Version 12.11.0 / 13.7.0 / 14.3.0 / 15.1.0 ====================================================================================*/ -#include "options.h" /* Compilation switches */ -#include "cnst_fx.h" /* Common constants */ -#include "prot_fx.h" /* Function prototypes */ -#include "stl.h" +#include +#include "options.h" +#include "cnst.h" +#include "prot.h" /*-------------------------------------------------------------------* * Local constants *-------------------------------------------------------------------*/ #define L_ENR (NB_SSF+2) - - +#define VOI_THRLD 0.2f /*-------------------------------------------------------------------* - * find_ener_decrease_fx() + * Local functions + *-------------------------------------------------------------------*/ + +static float find_ener_decrease( const short ind_deltaMax, const float *pt_enr_ssf ); + +/*-------------------------------------------------------------------* + * find_ener_decrease() * - * Find maximum energy ration between short subblocks in case + * Find maximum energy ratio between short sub-subframes in case * energy is trailing off after a spike *-------------------------------------------------------------------*/ -static Word16 find_ener_decrease_fx( /* o : maximum energy ratio Q10 */ - const Word16 ind_deltaMax, /* i : index of the beginning of maximum energy search */ - const Word32 *pt_enr_ssf /* i : Pointer to the energy buffer */ +static float find_ener_decrease( /* o : maximum energy ratio */ + const short ind_deltaMax, /* i : index of the beginning of maximum energy search */ + const float *pt_enr_ssf /* i : Pointer to the energy buffer */ ) { - Word16 i, j, end, flag; - Word16 wtmp0, wtmp1; - Word32 maxEnr, minEnr; - Word16 dE2, exp0, exp1; - - dE2 = 0; - move16(); + short i, j, end, flag; + float maxEnr, minEnr, dE2; + dE2 = 0.0f; j = ind_deltaMax+2; - move16(); end = j+L_ENR; - move16(); - maxEnr = L_add(pt_enr_ssf[j], 0); - j = add(j, 1); + maxEnr = pt_enr_ssf[j]; + j++; flag = 0; - move16(); - FOR( i=j; i0) && (flag == 0) ) + if( pt_enr_ssf[i] > maxEnr && flag == 0 ) { - maxEnr = L_add(pt_enr_ssf[i], 0); /*Q0*/ - j = add(j, 1); + maxEnr = pt_enr_ssf[i]; + j++; } - ELSE + else { flag = 1; - move16(); } } - minEnr = L_add(maxEnr, 0); - FOR( i=j; i 0) + fac = *pt_enr_ssf1 / (*pt_enr_ssf + 1.0f); + if( fac > dE1 ) { + dE1 = fac; ind_deltaMax = i; - move16(); } - dE1 = L_max(dE1, fac_32); - pt_enr_ssf++; pt_enr_ssf1++; } @@ -176,84 +142,64 @@ Word16 find_uv_fx( /* o : coding type * Average voicing (normalized correlation) *-----------------------------------------------------------------*/ - /*mean_ee = 1.0f/3.0f * (st->ee_old + ee[0] + ee[1]); */ /* coefficients take into account the position of the window */ - mean_ee = L_add(L_add(st_fx->ee_old_fx, ee[0]), ee[1]); - mean_ee = Mult_32_16(mean_ee, 10923); /*Q6*/ - - /* mean_voi3 = 1.0f/3.0f * (voicing[0] + voicing[1] + voicing[2]);*/ - Ltmp0 = L_mult( voicing[0], 10923); - Ltmp0 = L_mac(Ltmp0, voicing[1], 10923); - mean_voi3 = mac_r(Ltmp0, voicing[2], 10923); /*Q15*/ + mean_ee = 1.0f/3.0f * (st->ee_old + ee[0] + ee[1]); + mean_voi3 = 1.0f/3.0f * (voicing[0] + voicing[1] + voicing[2]); /*-----------------------------------------------------------------* * Total frame energy difference (dE3) *-----------------------------------------------------------------*/ - dE3 = sub(Etot, st_fx->Etot_last_fx); /*Q8*/ + dE3 = Etot - st->Etot_last; /*-----------------------------------------------------------------* - * Energy decrease after spike (dE2) - *-----------------------------------------------------------------*/ + * Energy decrease after spike (dE2) + *-----------------------------------------------------------------*/ /* set different thresholds and conditions for NB and WB input */ - dE2_th = 30<<10; - move32(); - nb_cond = 1; - move16(); /* no additional condition for WB input */ - IF ( sub(st_fx->input_bwidth_fx,NB) == 0 ) + if ( st->input_bwidth == NB ) { - dE2_th = 21<<10; - move32(); - if(sub(add(mean_voi3, corr_shift), 22282) >= 0) /*( mean_voi3 + corr_shift ) >= 0.68f*/ - { - nb_cond = 0; - move16(); - } + dE2_th = 21.0f; + nb_cond = ( mean_voi3 + corr_shift ) < 0.68f; + } + else + { + dE2_th = 30.0f; + nb_cond = 1; /* no additional condition for WB input */ } /* calcualte maximum energy decrease */ - dE2 = 0; - move16(); /* Test on energy decrease after an energy spike */ + dE2 = 0.0f; pt_enr_ssf = enr_ssf + 2*NB_SSF; - test(); - IF( L_sub(dE1, 30<<13) > 0 && nb_cond) /*>30 Q13*/ + if( dE1 > 30.0f && nb_cond ) { - IF( sub(sub(shl(NB_SSF,1), ind_deltaMax),L_ENR) < 0 ) + if( 2 * NB_SSF - ind_deltaMax < L_ENR ) { - st_fx->old_ind_deltaMax_fx = ind_deltaMax; - move16(); - Copy32( pt_enr_ssf, st_fx->old_enr_ssf_fx, 2*NB_SSF ); + st->old_ind_deltaMax = ind_deltaMax; + mvr2r( pt_enr_ssf, st->old_enr_ssf, 2*NB_SSF ); } - ELSE + else { - st_fx->old_ind_deltaMax_fx = -1; - move16(); - dE2 = find_ener_decrease_fx( ind_deltaMax, pt_enr_ssf ); /*Q10*/ - - if( L_sub(dE2,dE2_th) > 0) + st->old_ind_deltaMax = -1; + dE2 = find_ener_decrease( ind_deltaMax, pt_enr_ssf ); + if( dE2 > dE2_th ) { - st_fx->spike_hyst_fx = 0; - move16(); + st->spike_hyst = 0; } } } - ELSE + else { - IF( st_fx->old_ind_deltaMax_fx >= 0 ) + if( st->old_ind_deltaMax >= 0 ) { - Copy32( st_fx->old_enr_ssf_fx, enr_ssf, 2*NB_SSF ); - dE2 = find_ener_decrease_fx( st_fx->old_ind_deltaMax_fx, enr_ssf ); - - if( L_sub(dE2,dE2_th) > 0) + mvr2r( st->old_enr_ssf, enr_ssf, 2*NB_SSF ); + dE2 = find_ener_decrease( st->old_ind_deltaMax, enr_ssf ); + if( dE2 > dE2_th ) { - st_fx->spike_hyst_fx = 1; - move16(); + st->spike_hyst = 1; } } - - st_fx->old_ind_deltaMax_fx = -1; - move16(); + st->old_ind_deltaMax = -1; } /*-----------------------------------------------------------------* @@ -261,28 +207,23 @@ Word16 find_uv_fx( /* o : coding type *-----------------------------------------------------------------*/ tmp_offset_flag = 1; - move16(); - IF ( sub(st_fx->input_bwidth_fx, NB) != 0 ) + if ( st->input_bwidth != NB ) { - ee0_th = 154; /*2.4 in Q6 */ move16(); - voi_th = 24248; /*0.74f Q15 */ move16(); + ee0_th = 2.4f; + voi_th = 0.74f; } - ELSE + else { - ee0_th = 627; /*9.8f Q6 */ move16(); - voi_th = 24904; /*0.76f Q15*/ move16(); + ee0_th = 9.8f; + voi_th = 0.76f; } - test(); - test(); - test(); - if( ( sub(st_fx->last_coder_type_raw_fx,UNVOICED) == 0 ) || /* previous frame was unvoiced */ - ( ( L_sub(ee[0],ee0_th) < 0 ) && ( L_sub(hp_E[0],L_shl(E_MIN_FX,Q_new)) > 0 ) && /* energy is concentrated in high frequencies provided that some energy is present in HF */ - ( sub(add(voicing[0],corr_shift),voi_th) < 0 ) ) ) /* normalized correlation is low */ + if( ( st->last_coder_type_raw == UNVOICED ) || /* previous frame was unvoiced */ + ( ( ee[0] < ee0_th ) && ( hp_E[0] > (float)E_MIN ) && /* energy is concentrated in high frequencies provided that some energy is present in HF. The cast to (float) is needed for Linux i686 (gcc version 4.7.2), otherwise the criterion hp_E[0] > E_MIN holds true if E_MIN was assigned to hp_E[0] before */ + ( voicing[0] + corr_shift < voi_th ) ) ) /* normalized correlation is low */ { tmp_offset_flag = 0; - move16(); } /*-----------------------------------------------------------------* @@ -290,113 +231,82 @@ Word16 find_uv_fx( /* o : coding type *-----------------------------------------------------------------*/ /* SC-VBR - set additional parameters and thresholds for SC-VBR */ - mean_voi3_offset = 0; - move16(); + mean_voi3_offset = 0.0f; flag_low_relE = 0; - move16(); - ee1_th = 608; /*9.5 Q6*/ move16(); - IF ( st_fx->Opt_SC_VBR_fx ) + ee1_th = 9.5f; + if ( st->Opt_SC_VBR ) { - ee1_th = 544; /*8.5f Q6*/ move16(); + ee1_th = 8.5f; /* SC-VBR - determine the threshold on relative energy as a function of lp_noise */ - IF ( sub(st_fx->input_bwidth_fx,NB) != 0 ) + if ( st->input_bwidth != NB ) { - /*relE_thres = 0.700f * st->lp_noise - 33.5f; (lp_noise in Q8, constant Q8<<16) */ - L_tmp = L_mac(-562036736, 22938, st_fx->lp_noise_fx); - if ( st_fx->Last_Resort_fx == 0 ) + if ( st->Last_Resort == 0 ) { - /*relE_thres = 0.650f * st->lp_noise - 33.5f; (lp_noise in Q8, constant Q8<<16)*/ - L_tmp = L_mac(-562036736, 21299, st_fx->lp_noise_fx); + relE_thres = 0.650f * st->lp_noise - 33.5f; + } + else + { + relE_thres = 0.700f * st->lp_noise - 33.5f; } - relE_thres = round_fx(L_tmp); } - ELSE + else { + relE_thres = 0.60f * st->lp_noise - 28.2f; - /*relE_thres = 0.60f * st->lp_noise - 28.2f; (lp_noise in Q8, constant Q8<<16)*/ - L_tmp = L_mac(-473117491, 19661, st_fx->lp_noise_fx); - relE_thres = round_fx(L_tmp); } - relE_thres = s_max(relE_thres , -6400); /* Q8 */ + + if( relE_thres < -25.0f ) + { + relE_thres = -25.0f; + } /* SC-VBR = set flag on low relative energy */ - if ( sub(relE,relE_thres) < 0 ) + if ( relE < relE_thres ) { flag_low_relE = 1; - move16(); } /* SC-VBR - correction of voicing threshold for NB inputs (important only in noisy conditions) */ - test(); - if ( sub(st_fx->input_bwidth_fx,NB) == 0 && sub(st_fx->vadnoise_fx,20<<8) < 0 ) /* vadnoise in Q8, constant Q0<<8 */ + if ( st->input_bwidth == NB && st->vadnoise < 20.0f ) { - mean_voi3_offset = 1638; /*0.05f Q15*/ move16(); + mean_voi3_offset = 0.05f; } } /* make decision whether frame is unvoiced */ - E_min_th = L_shl(E_MIN_FX,Q_new); coder_type = GENERIC; - move16(); - IF ( sub(st_fx->input_bwidth_fx,NB) == 0 ) + if ( st->input_bwidth == NB ) { - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - if( ( ( sub(add(mean_voi3, corr_shift),add(22282,mean_voi3_offset)) < 0) && /* normalized correlation low */ - ( ( sub(add(voicing[2], corr_shift),25887) ) < 0 ) && /* normalized correlation low on look-ahead - onset detection */ - ( L_sub(ee[0], 640) < 0 ) && ( L_sub(hp_E[0], E_min_th) > 0 ) && /* energy concentrated in high frequencies provided that some energy is present in HF... */ - ( L_sub(ee[1], ee1_th) < 0 ) && ( L_sub(hp_E[1], E_min_th) > 0 ) && /* ... biased towards look-ahead to detect onsets */ - ( tmp_offset_flag == 0 ) && /* Take care of voiced offsets */ - ( st_fx->music_hysteresis_fx == 0 ) && /* ... and in segment after AUDIO frames */ - ( L_sub(dE1, 237568) <= 0 ) && /* Avoid on sharp energy spikes */ - ( L_sub(st_fx->old_dE1_fx,237568) <= 0 ) && /* + one frame hysteresis */ - ( st_fx->spike_hyst_fx < 0 ) ) || /* Avoid after sharp energy spikes followed by decay (e.g. castanets) */ - flag_low_relE ) /* low relative frame energy (only for SC-VBR) */ + if( ( ( mean_voi3 + corr_shift < 0.68f + mean_voi3_offset ) && /* normalized correlation low */ + ( ( voicing[2] + corr_shift ) < 0.79f ) && /* normalized correlation low on look-ahead - onset detection */ + ( ee[0] < 10.0f ) && ( hp_E[0] > (float)E_MIN ) && /* energy concentrated in high frequencies provided that some energy is present in HF... */ + ( ee[1] < ee1_th ) && ( hp_E[1] > (float)E_MIN ) && /* ... biased towards look-ahead to detect onsets. The cast to (float) is needed for Linux i686 (gcc version 4.7.2), otherwise the criterion hp_E[0] > E_MIN holds true if E_MIN was assigned to hp_E[] before */ + ( tmp_offset_flag == 0 ) && /* take care of voiced offsets */ + ( st->music_hysteresis == 0 ) && /* ... and in segment after AUDIO frames */ + ( dE1 <= 29.0f ) && /* avoid on sharp energy spikes */ + ( st->old_dE1 <= 29.0f ) && /* + one frame hysteresis */ + ( st->spike_hyst < 0 ) ) || /* avoid after sharp energy spikes followed by decay (e.g. castanets) */ + flag_low_relE ) /* low relative frame energy (only for SC-VBR) */ { coder_type = UNVOICED; - move16(); } } - ELSE + else { - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - if( ( ( sub(add(mean_voi3, corr_shift),add(22774,mean_voi3_offset)) < 0) && /* normalized correlation low */ - ( ( sub(add(voicing[2], corr_shift),25887) ) < 0 ) && /* normalized correlation low on look-ahead - onset detection */ - ( L_sub(ee[0], 397) < 0 ) && ( L_sub(hp_E[0], E_min_th) > 0 ) && /* energy concentrated in high frequencies provided that some energy is present in HF... */ - ( L_sub(ee[1], 397) < 0 ) && ( L_sub(hp_E[1], E_min_th) > 0 ) && /* ... biased towards look-ahead to detect onsets */ - ( tmp_offset_flag == 0 ) && /* Take care of voiced offsets */ - ( st_fx->music_hysteresis_fx == 0 ) && /* ... and in segment after AUDIO frames */ - ( L_sub(dE1, 245760) <= 0 ) && /* Avoid on sharp energy spikes */ - ( L_sub(st_fx->old_dE1_fx,245760) <= 0 ) && /* + one frame hysteresis */ - ( st_fx->spike_hyst_fx < 0 ) ) /* Avoid after sharp energy spikes followed by decay (e.g. castanets) */ - || ( flag_low_relE - && ( L_sub(st_fx->old_dE1_fx,245760) <= 0 ) - ) - ) /* low relative frame energy (only for SC-VBR) */ + if( ( ( mean_voi3 + corr_shift < 0.695f + mean_voi3_offset ) && /* normalized correlation low */ + ( ee[0] < 6.2f ) && ( hp_E[0] > (float)E_MIN ) && /* energy concentrated in high frequencies provided that some energy is present in HF */ + ( ee[1] < 6.2f ) && ( hp_E[1] > (float)E_MIN ) && /* ... biased towards look-ahead to detect onsets. The cast to (float) is needed for Linux i686 (gcc version 4.7.2), otherwise the criterion hp_E[0] > E_MIN holds true if E_MIN was assigned to hp_E[] before */ + ( tmp_offset_flag == 0 ) && /* take care of voiced offsets */ + ( st->music_hysteresis == 0 ) && /* ... and in segment after AUDIO frames */ + ( dE1 <= 30.0f ) && /* avoid on sharp energy spikes */ + ( st->old_dE1 <= 30.0f ) && /* + one frame hysteresis */ + ( st->spike_hyst < 0 ) ) || /* avoid after sharp energy spikes followed by decay (e.g. castanets) */ + ( flag_low_relE + && st->old_dE1 <= 30.0f + )) /* low relative frame energy (only for SC-VBR) */ { coder_type = UNVOICED; - move16(); } } @@ -404,78 +314,49 @@ Word16 find_uv_fx( /* o : coding type * Decision about VC *-----------------------------------------------------------------*/ - st_fx->set_ppp_generic_fx = 0; - move16(); + st->set_ppp_generic = 0; - test(); - test(); - IF( sub(localVAD,1) == 0 && sub(coder_type,GENERIC) == 0 && sub(last_core_orig,AMR_WB_CORE) != 0 ) + if( localVAD == 1 && coder_type == GENERIC && last_core_orig != AMR_WB_CORE) { - dpit1 = abs_s( sub(T_op_fr[1], T_op_fr[0])); - dpit2 = abs_s( sub(T_op_fr[2], T_op_fr[1])); - dpit3 = abs_s( sub(T_op_fr[3], T_op_fr[2])); - - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - IF( ( sub(voicing_fr[0],19825)> 0 ) && /* normalized correlation high in 1st sf. */ - ( sub(voicing_fr[1],19825) > 0) && /* normalized correlation high in 2st sf. */ - ( sub(voicing_fr[2],19825) > 0) && /* normalized correlation high in 3st sf. */ - ( sub(voicing_fr[3],19825) > 0) && /* normalized correlation high in 4st sf. */ - ( L_sub(mean_ee,256) > 0 ) && /* energy concentrated in low frequencies */ - ( sub(dpit1,3<<6) < 0 ) && - ( sub(dpit2,3<<6) < 0 ) && - ( sub(dpit3,3<<6) < 0 ) ) + if( ( voicing_fr[0] > 0.605f ) && /* normalized correlation high in 1st sf. */ + ( voicing_fr[1] > 0.605f ) && /* normalized correlation high in 2st sf. */ + ( voicing_fr[2] > 0.605f ) && /* normalized correlation high in 3st sf. */ + ( voicing_fr[3] > 0.605f ) && /* normalized correlation high in 4st sf. */ + ( mean_ee > 4.0f ) && /* energy concentrated in low frequencies */ + ( fabs( pitch_fr[1] - pitch_fr[0] ) < 3.0f ) && /* small OL pitch difference in 1st sf. */ + ( fabs( pitch_fr[2] - pitch_fr[1] ) < 3.0f ) && /* small OL pitch difference in 2nd sf. */ + ( fabs( pitch_fr[3] - pitch_fr[2] ) < 3.0f ) ) /* small OL pitch difference in 3rd sf. */ { coder_type = VOICED; - move16(); } - ELSE IF ( st_fx->Opt_SC_VBR_fx && sub(st_fx->input_bwidth_fx,NB) == 0 && sub(st_fx->vadnoise_fx,20<<8) < 0 ) + else if ( st->Opt_SC_VBR && st->input_bwidth == NB && st->vadnoise < 20 ) { - test(); - test(); - test(); - test(); - test(); - test(); - test(); - IF( sub(voicing_fr[0],8192)> 0 && /* normalized correlation high in 1st sf. */ - ( sub(voicing_fr[1],8192) > 0) && /* normalized correlation high in 2st sf. */ - ( sub(voicing_fr[2],8192) > 0) && /* normalized correlation high in 3st sf. */ - ( sub(voicing_fr[3],8192) > 0) && /* normalized correlation high in 4st sf. */ - ( L_sub(mean_ee,64) > 0 ) && /* energy concentrated in low frequencies */ - ( sub(dpit1,5<<6) < 0 ) && - ( sub(dpit2,5<<6) < 0 ) && - ( sub(dpit3,5<<6) < 0 ) ) + if( ( voicing_fr[0] > 0.25f) && /* normalized correlation high in 1st sf. */ + ( voicing_fr[1] > 0.25f ) && /* normalized correlation high in 2st sf. */ + ( voicing_fr[2] > 0.25f ) && /* normalized correlation high in 3st sf. */ + ( voicing_fr[3] > 0.25f ) && /* normalized correlation high in 4st sf. */ + ( mean_ee > 1.0f ) && /* energy concentrated in low frequencies (used 1.0 for WB) */ + ( fabs( pitch_fr[1] - pitch_fr[0] ) < 5.0f ) && /* small OL pitch difference in 1st sf. */ + ( fabs( pitch_fr[2] - pitch_fr[1] ) < 5.0f ) && /* small OL pitch difference in 2nd sf. */ + ( fabs( pitch_fr[3] - pitch_fr[2] ) < 5.0f ) ) /* small OL pitch difference in 3rd sf. */ { - st_fx->set_ppp_generic_fx = 1; - move16(); + st->set_ppp_generic = 1; coder_type = VOICED; - move16(); } } - /* set VOICED mode for frames with very stable pitch and high correlation and avoid to switch to AUDIO/MUSIC later */ - voicing_m = mac_r(L_mac(L_mac(L_mult(voicing_fr[3], 8192), voicing_fr[2], 8192),voicing_fr[1], 8192),voicing_fr[0], 8192); - test(); - test(); - test(); - test(); - test(); - IF ( *flag_spitch || ( sub(dpit1,3<<6) <= 0 && sub(dpit2,3<<6) <= 0 && sub(dpit3,3<<6) <= 0 && - sub(voicing_m, 31130) > 0 && sub(voicing_sm, 31785) > 0 ) ) + voicing_m = mean( voicing_fr, NB_SUBFR ); + + dpit1 = (float)fabs( pitch_fr[0] - pitch_fr[1] ); + dpit2 = (float)fabs( pitch_fr[1] - pitch_fr[2] ); + dpit3 = (float)fabs( pitch_fr[2] - pitch_fr[3] ); + + if( *flag_spitch || ( dpit1 <= 3.0f && dpit2 <= 3.0f && dpit3 <= 3.0f && + voicing_m > 0.95f && voicing_sm > 0.97f ) ) { coder_type = VOICED; - move16(); - *flag_spitch = 1; - move16();/*to avoid switch to AUDIO/MUSIC later*/ + *flag_spitch = 1; /*to avoid switch to AUDIO/MUSIC later*/ } } @@ -483,69 +364,50 @@ Word16 find_uv_fx( /* o : coding type * Channel-aware mode - set RF mode and total bitrate *-----------------------------------------------------------------*/ - st_fx->rf_mode = st_fx->Opt_RF_ON; - move16(); + st->rf_mode = st->Opt_RF_ON; - IF ( sub ( coder_type, GENERIC ) == 0 ) + if ( coder_type == GENERIC ) { - test(); - test(); - test(); - test(); - IF( ( sub(voicing_fr[0],6554) < 0) && /* normalized correlation high in 2st sf. */ - ( sub(voicing_fr[1],6554) < 0) && /* normalized correlation high in 2st sf. */ - ( sub(voicing_fr[2],6554) < 0) && /* normalized correlation high in 3rd sf. */ - ( sub(voicing_fr[3],6554) < 0) && /* normalized correlation high in 4th sf. */ - ( sub(st_fx->vadnoise_fx, 25 << 8 ) > 0 )) /* when speech is clean */ - + if( ( voicing_fr[0] < VOI_THRLD ) && /* normalized correlation high in 1st sf. */ + ( voicing_fr[1] < VOI_THRLD ) && /* normalized correlation high in 2st sf. */ + ( voicing_fr[2] < VOI_THRLD ) && /* normalized correlation high in 3st sf. */ + ( voicing_fr[3] < VOI_THRLD ) && /* normalized correlation high in 4st sf. */ + ( st->vadnoise > 25.0f ) ) /* when speech is clean */ { - st_fx->rf_mode = 0; - move16(); + st->rf_mode = 0; /* Current frame cannot be compressed to pack the partial redundancy;*/ - if( st_fx->rf_mode != st_fx->Opt_RF_ON ) + if( st->rf_mode != st->Opt_RF_ON ) { - core_coder_mode_switch( st_fx, st_fx->bwidth_fx, st_fx->total_brate_fx, shift ); + core_coder_mode_switch( st, st->bwidth, st->total_brate ); } } } - - - - /*-----------------------------------------------------------------* * Updates *-----------------------------------------------------------------*/ /* update spike hysteresis parameters */ - test(); - if( st_fx->spike_hyst_fx >= 0 && sub(st_fx->spike_hyst_fx,2) < 0 ) + if( st->spike_hyst >= 0 && st->spike_hyst < 2 ) { - st_fx->spike_hyst_fx = add(st_fx->spike_hyst_fx,1); + st->spike_hyst++; } /* reset spike hysteresis */ - test(); - test(); - test(); - if( ( sub(st_fx->spike_hyst_fx,1) > 0 ) && - ( sub(dE3,5<<8) > 0 || /* energy increases */ - ( sub(relE, -3328) > 0 && ( sub(add(mean_voi3, corr_shift),22774) > 0) ) ) ) /* normalized correlation is high */ + if( ( st->spike_hyst > 1 ) && + ( dE3 > 5.0f || /* energy increases */ + ( relE > -13.0f && ( mean_voi3 + corr_shift > 0.695f) ) ) ) /* normalized correlation is high */ { - st_fx->spike_hyst_fx = -1; - move16(); + st->spike_hyst = -1; } /* update tilt parameters */ - st_fx->ee_old_fx = ee[1]; - move32(); /*Q6*/ - st_fx->old_dE1_fx = dE1; - move32(); /*Q13*/ + st->ee_old = ee[1]; + st->old_dE1 = dE1; - /* save the raw coder_type for various modules later in the codec (the reason is that e.g. UNVOICED is lost at higher rates) */ - st_fx->coder_type_raw_fx = coder_type; - move16(); + /* save the raw coder_type for various modules later in the codec (the reason is that e.g. UNVOICED is not used (rewritten) at higher rates) */ + st->coder_type_raw = coder_type; return coder_type; } diff --git a/src/libs/libevs/lib_enc/find_wsp.cpp b/src/libs/libevs/lib_enc/find_wsp.cpp new file mode 100644 index 00000000..4e491305 --- /dev/null +++ b/src/libs/libevs/lib_enc/find_wsp.cpp @@ -0,0 +1,61 @@ +/*==================================================================================== + EVS Codec 3GPP TS26.443 Nov 13, 2018. Version 12.11.0 / 13.7.0 / 14.3.0 / 15.1.0 + ====================================================================================*/ + +#include "options.h" +#include "cnst.h" +#include "prot.h" + +/*-------------------------------------------------------------------* + * find_wsp() + * + * Compute weighted speech used in open-loop pitch search + *-------------------------------------------------------------------*/ + +void find_wsp( + const short L_frame, /* i : length of the frame */ + const short L_subfr, /* i : length of subframe */ + const short nb_subfr, /* i : number of subframes */ + const float *A, /* i : A(z) filter coefficients */ + float *Aw, /* o : weighted A(z) filter coefficients */ + const float *speech, /* i : pointer to the denoised speech frame */ + const float tilt_fact, /* i : tilt factor */ + float *wsp, /* o : poitnter to the weighted speech frame */ + float *mem_wsp, /* i/o: W(Z) denominator memory */ + const float gamma, /* i : weighting factor */ + const short L_look /* i : look-ahead */ +) +{ + float *p_Aw, tmp; + short i_subfr; + + + /*-----------------------------------------------------------------* + * Compute weighted A(z) unquantized for subframes + *-----------------------------------------------------------------*/ + + weight_a_subfr( nb_subfr, A, Aw, gamma, M ); + + /*-----------------------------------------------------------------* + * Compute weighted speech for all subframes + *-----------------------------------------------------------------*/ + + p_Aw = Aw; + for (i_subfr=0; i_subfr -#include -#include "stl.h" -#include "prot_fx.h" -#include "options.h" -#include "cnst_fx.h" -#include "stl.h" - - - -/* - * find_wsp - * - * Parameters: - * Az I: A(z) filter coefficients Q12 - * speech I: pointer to the denoised speech frame Q_new - preemph_bits - * wsp O: pointer to the weighted speech frame Q_new - preemph_bits - * mem_wsp I/O: W(z) denominator memory - * preemph_fac I: pre-emphasis factor Q15 - * L_frame I: length of the frame - * lookahead I: length of a look-ahead - * L_subfr I: length of the sub-frame - * - * Function: - * Find weighted speech (formula from AMR-WB) - * - * Returns: - * void - */ -void find_wsp( - const Word16 Az[], - const Word16 speech[], - Word16 wsp[], - Word16 *mem_wsp, - const Word16 preemph_fac, - const Word16 L_frame, - const Word16 lookahead, - const Word16 L_subfr, - Word16 *Aw, /* o : weighted A(z) filter coefficients */ - const Word16 gamma, /* i : weighting factor */ - const Word16 nb_subfr /* i : number of subframes */ -) -{ - Word16 i_subfr, wtmp; - const Word16 *p_Az; - /*-----------------------------------------------------------------* - * Compute weighted A(z) unquantized for subframes - *-----------------------------------------------------------------*/ - - weight_a_subfr_fx( nb_subfr, Az, Aw, gamma, M ); - - - /*----------------------------------------------------------------* - * Compute weighted speech for all subframes - *----------------------------------------------------------------*/ - BASOP_SATURATE_WARNING_OFF - p_Az = Aw; /*move16();*/ - FOR (i_subfr = 0; i_subfr < L_frame; i_subfr += L_subfr) - { - Residu3_fx(p_Az, &speech[i_subfr], &wsp[i_subfr], L_subfr, 0); - p_Az += (M+1); - } - p_Az -= (M+1); - BASOP_SATURATE_WARNING_ON - /*----------------------------------------------------------------* - * Weighted speech computation is extended on look-ahead - *----------------------------------------------------------------*/ - deemph_fx(wsp, preemph_fac, L_frame, mem_wsp); /* use Deemph2 to prevent saturation */ - - IF ( lookahead != 0 ) - { - Residu3_fx(p_Az, &speech[L_frame], &wsp[L_frame], lookahead, 0); - wtmp = *mem_wsp; - move16(); - deemph_fx(&wsp[L_frame], preemph_fac, lookahead, &wtmp); - } - -} - - - diff --git a/src/libs/libevs/lib_enc/frame_spec_dif_cor_rate.cpp b/src/libs/libevs/lib_enc/frame_spec_dif_cor_rate.cpp old mode 100755 new mode 100644 index b6058cd39..2256549d --- a/src/libs/libevs/lib_enc/frame_spec_dif_cor_rate.cpp +++ b/src/libs/libevs/lib_enc/frame_spec_dif_cor_rate.cpp @@ -1,111 +1,62 @@ /*==================================================================================== - EVS Codec 3GPP TS26.442 Apr 03, 2018. Version 12.11.0 / 13.6.0 / 14.2.0 + EVS Codec 3GPP TS26.443 Nov 13, 2018. Version 12.11.0 / 13.7.0 / 14.3.0 / 15.1.0 ====================================================================================*/ +#include +#include "prot.h" -#include - -#include "basop_util.h" -#include "stl.h" -#include "vad_basop.h" -#include "prot_fx.h" - - - -void frame_spec_dif_cor_rate(T_CldfbVadState *st, /*(io) vad state*/ - Word32 *spec_amp, /*(i) spectral amplitude*/ - Word16 sacle, /*(i) the scaling of spec_amp*/ - Word16 f_tonality_rate[3] /*(o) tonality rate*/ - ) +/*-------------------------------------------------------------------* + * frame_spec_dif_cor_rate() + * + * + *-------------------------------------------------------------------*/ +void frame_spec_dif_cor_rate( + float spec_amp[], /*(i) spectral amplitude*/ + float pre_spec_low_dif[], /*(io) low spectrum different*/ + float f_tonality_rate[] /*(o) tonality rate*/ +) { - Word32 i,tmp; - Word16 spec_low_dif_tmp,tmpq,tmpq2,*p_dx_Q,dx_Q=0; - Word32 tmpspec_low_dif[PRE_SPEC_DIF_NUM]; - Word32 maxVal; - Word16 resu; - Word16 scalefactor,spec_dif_cor_rate; - Word32 m,dx,dy; - Word16 *pre_spec_low_dif = st->pre_spec_low_dif; - const Word32 FIX_cost1 = 2147484/* 0.001f Q31 */; + int i; + float spec_low_dif[59]; + float tmp,spec_low_dif_cor_rate,spec_dif_cor_rate; + float m,dx,dy; - - p_dx_Q = &dx_Q; - maxVal = L_add(0,0); - FOR(i=0; i< PRE_SPEC_DIF_NUM; i++) + for(i=0; iscale_spec_low_dif); - *p_dx_Q = shl(tmpq2,1); - move16(); - *p_dx_Q = sub(*p_dx_Q ,32); - move16(); - IF(sub(*p_dx_Q , 31)<0) - { - dx = L_add(dx,L_shr(FIX_cost1,limitScale32(sub(31,*p_dx_Q)))); - } - ELSE - { - dx = L_add(L_shr(dx,limitScale32(sub(*p_dx_Q,31))),FIX_cost1); - *p_dx_Q = 31; - move16(); - } - - dx = vad_Sqrt_l(dx,p_dx_Q); - - m = L_shr(m,limitScale32(add(sub(tmpq2,*p_dx_Q),1))); - spec_dif_cor_rate = 16384; - move16(); - - if(dx) - { - spec_dif_cor_rate = divide3232(m,dx); - } + /* 1073741.824 = 0.001 * 32768 * 32768 */ + spec_low_dif_cor_rate = (float)(m/sqrt((dx*dy+1073741.824f))); + spec_dif_cor_rate = spec_low_dif_cor_rate; f_tonality_rate[0] = spec_dif_cor_rate; - move16(); - tmp = L_mac0(L_mult0(f_tonality_rate[1],31456/* 0.96 Q15 */), spec_dif_cor_rate,1311/* 0.04 Q15 */); - f_tonality_rate[1] = shl(round_fx(tmp),1); - move16(); - tmp = L_mac0(L_mult0(f_tonality_rate[2],29490/* 0.90 Q15 */), spec_dif_cor_rate,3277/* 0.1 Q15 */); - f_tonality_rate[2] = shl(round_fx(tmp),1); - move16(); - st->scale_spec_low_dif = tmpq; - move16(); + f_tonality_rate[1] = f_tonality_rate[1]*0.96f + spec_dif_cor_rate*0.04f; + f_tonality_rate[2] = f_tonality_rate[2]*0.90f + spec_dif_cor_rate*0.1f; + for(i=0; i +#include "options.h" +#include "cnst.h" +#include "rom_com.h" +#include "prot.h" + +/*-------------------------------------------------------------------* + * Local constants + *-------------------------------------------------------------------*/ + +#define RANGE 64 + +/*---------------------------------------------------------------------* + * Es_pred_enc() + * + * Calculation and quantization of average predicted innovation energy to be + *---------------------------------------------------------------------*/ + +void Es_pred_enc( + float *Es_pred, /* o : predicited scaled innovation energy */ + int *Es_pred_indice, /* o : indice corresponding to above parameter */ + const short L_frame, /* i : length of the frame */ + const short L_subfr, /* i : length of the subframe */ + const float *res, /* i : residual signal */ + const float *voicing, /* i : normalized correlation in three 1/2frames */ + const short nb_bits, /* i : allocated number of bits */ + const short no_ltp /* i : no_ltp flag */ +) +{ + short i, i_subfr, size; + float tmp, dist, mean_ener_code, ener; + float weight; + const float *qua_table; + + /*----------------------------------------------------------* + * calculate the average residual signal energy + *----------------------------------------------------------*/ + if( L_frame == L_FRAME ) + { + weight = 0.25f; + } + else /* L_frame == L_FRAME16k */ + { + weight = 0.2f; + } + + mean_ener_code = 0.0f; + for (i_subfr = 0; i_subfr < L_frame; i_subfr += L_subfr) + { + /* calculate the energy of residual signal */ + ener = sum2_f(&res[i_subfr], L_subfr) + 0.01f; + ener = 10 * (float)log10( ener / ((float) L_subfr)); + if ((ener < 0) && !(no_ltp)) + { + ener = 0; + } + + /* update the average energy of residual signal */ + mean_ener_code += weight * ener; + } + + if( !no_ltp ) + { + /*----------------------------------------------------------* + * subtract an estimate of adaptive codebook contribution + *----------------------------------------------------------*/ + + mean_ener_code -= 10.0f * (0.5f * voicing[0] + 0.5f * voicing[1]); + + /*----------------------------------------------------------* + * quantize the average predicted innovation energy + *----------------------------------------------------------*/ + switch ( nb_bits ) + { + case 5: + { + qua_table = Es_pred_qua_5b; + break; + } + case 4: + { + qua_table = Es_pred_qua_4b; + break; + } + case 3: + { + qua_table = Es_pred_qua_3b; + break; + } + default: + { + qua_table = Es_pred_qua_5b; + break; + } + } + } + else + { + qua_table = Es_pred_qua_4b_no_ltp; + } + + /* select codebook, size and number of bits */ + size = (short)pow2[nb_bits]; + + /* find the nearest neighbour (codevector) */ + tmp = 1e30f; + *Es_pred_indice=0; + for (i=0; i, -2,, -2 and 2 */ + const short clip_gain, /* i : gain pitch clipping flag (1 = clipping) */ + float *past_qua_en /* i/o: gain quantization memory (4 words) */ +) +{ + short index, i, j, min_ind, size, nBits; + float dist, dist_min, g_pitch, g_code, qua_en, gcode0; + const float *p, *t_qua_gain; + + /*-----------------------------------------------------------------* + * gain computation correlations + * find raw innovation energy + *-----------------------------------------------------------------*/ + + E_corr_xy2( xn, y1, y2, g_corr,L_SUBFR); + g_corr[2] += 0.01F; + g_corr[3] -= 0.02F; + g_corr[4] += 0.02F; + *gain_inov = 1.0f / (float)sqrt( ( dotp( code, code, L_SUBFR ) + 0.01f ) / L_SUBFR ); + + /*-----------------------------------------------------------------* + * find the initial quantization pitch index + * set gains search range + *-----------------------------------------------------------------*/ + + if ( core_brate < ACELP_12k65 ) + { + t_qua_gain = t_qua_gain6b; + nBits = 6; + min_ind = 0; + size = RANGE; + if (clip_gain == 1) + { + size -= 16; /* limit pitch gain to 1.0 */ + } + } + else + { + t_qua_gain = t_qua_gain7b; + nBits = 7; + p = t_qua_gain7b + RANGE; /* pt at 1/4th of table */ + j = NB_QUA_GAIN7B - RANGE; + if (clip_gain == 1) + { + j -= 27; /* limit pitch gain to 1.0 */ + } + + min_ind = 0; + g_pitch = *gain_pit; + + + for (i=0; i *p) + { + min_ind++; + } + } + size = RANGE; + } + + /*-----------------------------------------------------------------* + * predicted code gain + *-----------------------------------------------------------------*/ + + /* start with predicting code energy in dB */ + gcode0 = MEAN_ENER; + for (i=0; i0; i--) + { + past_qua_en[i] = past_qua_en[i-1]; + } + past_qua_en[0] = (float)(20.0*log10(qua_en)); + + push_indice( st, IND_GAIN, index, nBits ); + + *norm_gain_code = *gain_code / *gain_inov; + + return; +} + +/*---------------------------------------------------------------------* + * gain_enc_mless() + * + * Quantization of pitch and codebook gains without prediction (memory-less) + * - an initial predicted gain, gcode0, is first determined based on + * the predicted average innovation energy + * - a correction factor gamma = g_code / gcode0 is then vector quantized along with gain_pit + * - the mean-squared weighted error criterion is used for codebook search + *---------------------------------------------------------------------*/ + +void gain_enc_mless( + Encoder_State *st, /* i/o: encoder state structure */ + const long core_brate, /* i : core bitrate */ + const short L_frame, /* i : length of the frame */ + const short coder_type, /* i : coding type */ + const short i_subfr, /* i : subframe index */ + const short tc_subfr, /* i : TC subframe index */ + const float *xn, /* i : target vector */ + const float *y1, /* i : zero-memory filtered adaptive excitation */ + const float *y2, /* i : zero-memory filtered algebraic codebook excitation */ + const float *code, /* i : algebraic excitation */ + const float Es_pred, /* i : predicted scaled innovation energy */ + float *gain_pit, /* o : quantized pitch gain */ + float *gain_code, /* o : quantized codebook gain */ + float *gain_inov, /* o : gain of the innovation (used for normalization) */ + float *norm_gain_code, /* o : norm. gain of the codebook excitation */ + float *g_corr, /* i/o: correlations , -2,, -2 and 2 */ + const short clip_gain /* i : gain pitch clipping flag (1 = clipping) */ +) +{ + short index, i, size, nBits; + float dist, dist_min, g_pitch, g_code, gcode0, Ei, Ecode; + short nBits2; + float tmp1, tmp2; + const float *p, *qua_table; + + /*-----------------------------------------------------------------* + * calculate the rest of the correlation coefficients + * c2 = , c3 = -2, c4 = 2 + *-----------------------------------------------------------------*/ + + E_corr_xy2( xn, y1, y2, g_corr,L_SUBFR); + g_corr[2] += 0.01F; + g_corr[3] -= 0.02F; + g_corr[4] += 0.02F; + + /*-----------------------------------------------------------------* + * calculate the unscaled innovation energy + * calculate the predicted gain code + *-----------------------------------------------------------------*/ + + Ecode = (dotp( code, code, L_SUBFR) + 0.01f) / L_SUBFR; + *gain_inov = 1.0f / (float)sqrt( Ecode ); + Ei = 10 * (float)log10( Ecode ); + gcode0 = (float) pow(10, 0.05 * (Es_pred - Ei)); + + /*-----------------------------------------------------------------* + * select the codebook, size and number of bits + * set the gains searching range + *-----------------------------------------------------------------*/ + + if( L_frame == L_FRAME ) + { + nBits = gain_bits_tbl[BIT_ALLOC_IDX(core_brate, coder_type, i_subfr, TC_SUBFR2IDX(tc_subfr))]; + } + else /* L_frame == L_FRAME16k */ + { + nBits = gain_bits_16kHz_tbl[ BIT_ALLOC_IDX_16KHZ(core_brate, coder_type, i_subfr, TC_SUBFR2IDX_16KHZ(tc_subfr)) ]; + } + + if( (tc_subfr == 3*L_SUBFR && i_subfr == 3*L_SUBFR && L_frame == L_FRAME) || + (tc_subfr == 4*L_SUBFR && i_subfr == 4*L_SUBFR && L_frame == L_FRAME16k) ) + { + /* in case of attack at the end of the frame, use scalar gain quantizers */ + tmp1 = (g_corr[0]*g_corr[2]) - (0.25f*g_corr[4]*g_corr[4]); + tmp2 = -0.5f*g_corr[1]/tmp1; + tmp1 = -0.5f*g_corr[3]/tmp1; + + *gain_pit = (g_corr[2]*tmp2) - (0.5f*g_corr[4]*tmp1); + *gain_code = (g_corr[0]*tmp1) - (0.5f*g_corr[4]*tmp2); + + *gain_pit = max(G_PITCH_MIN_TC192,min(*gain_pit,G_PITCH_MAX_TC192)); + + /* set number of bits for two SQs */ + nBits2 = (nBits+1)>>1; + nBits = nBits>>1; + + /* gain_pit Q */ + tmp1 = (G_PITCH_MAX_TC192 - G_PITCH_MIN_TC192) / ((1 << nBits) - 1); /* set quantization step */ + index = usquant( *gain_pit, gain_pit, G_PITCH_MIN_TC192, tmp1, (1 << nBits) ); + push_indice( st, IND_GAIN_PIT, index, nBits ); + + /* gain_code Q */ + *gain_code /= gcode0; + index = gain_quant( gain_code, G_CODE_MIN_TC192, G_CODE_MAX_TC192, nBits2 ); + push_indice( st, IND_GAIN_CODE, index, nBits2 ); + *gain_code *= gcode0; + } + else + { + size = (short)pow2[nBits]; + + switch ( nBits ) + { + case 7: + { + qua_table = gain_qua_mless_7b; + if ( clip_gain == 1 ) size -= 30; + break; + } + case 6: + { + qua_table = gain_qua_mless_6b; + if ( clip_gain == 1 ) size -= 14; + break; + } + case 5: + { + qua_table = gain_qua_mless_5b; + if ( clip_gain == 1 ) size -= 6; + break; + } + default: + { + qua_table = gain_qua_mless_6b; + if ( clip_gain == 1 ) size -= 14; + break; + } + } + + /* in case of AVQ inactive, limit the gain_pit to 0.65 */ + if( clip_gain == 2 && nBits == 6 ) + { + size -= 36; + nBits--; + } + + /*-----------------------------------------------------------------* + * search for the best quantizer + *-----------------------------------------------------------------*/ + + p = qua_table; + dist_min = 3.402823466e+38F; + index = 0; + for (i = 0; i, -2,, -2 and 2 */ + const short clip_gain /* i : gain pitch clipping flag (1 = clipping) */ +) +{ + short index, nBits_pitch, nBits_code; + float g_code, gcode0, Ei, Ecode, tmp1, tmp2; + short tmp16; + /*-----------------------------------------------------------------* + * calculate the rest of the correlation coefficients + * c2 = , c3 = -2, c4 = 2 + *-----------------------------------------------------------------*/ + + g_corr[1] *= -0.5; + g_corr[2] = dotp( y2, y2, L_SUBFR ) + 0.01f; + g_corr[3] = dotp( xn, y2, L_SUBFR ) - 0.02f; + g_corr[4] = dotp( yy1, y2, L_SUBFR ) + 0.02f; + + /*-----------------------------------------------------------------* + * calculate the unscaled innovation energy + * calculate the predicted gain code + * calculate optimal gains + *-----------------------------------------------------------------*/ + + Ecode = (dotp( code, code, L_SUBFR) + 0.01f) / L_SUBFR; + *gain_inov = 1.0f / (float)sqrt( Ecode ); + Ei = 10 * (float)log10( Ecode ); + gcode0 = (float) pow(10, 0.05 * (Es_pred - Ei)); + + tmp1 = (g_corr[0]*g_corr[2]) - (g_corr[4]*g_corr[4]); + tmp2 = g_corr[1]/tmp1; + tmp1 = g_corr[3]/tmp1; + + *gain_pit = (g_corr[2]*tmp2) - (g_corr[4]*tmp1); + *gain_code = (g_corr[0]*tmp1) - (g_corr[4]*tmp2); + + *gain_pit = max(G_PITCH_MIN,min(*gain_pit,G_PITCH_MAX)); + + /*-----------------------------------------------------------------* + * limit the pitch gain searching range (if indicated by clip_gain) + *-----------------------------------------------------------------*/ + + if( clip_gain == 1 && *gain_pit > 0.95f ) + { + *gain_pit = 0.95f; + } + else if( clip_gain == 2 && *gain_pit > 0.65f ) + { + *gain_pit = 0.65f; + } + + /*-----------------------------------------------------------------* + * search for the best quantized values + *-----------------------------------------------------------------*/ + + nBits_pitch = gain_bits_16kHz_tbl[ BIT_ALLOC_IDX_16KHZ(core_brate, coder_type, i_subfr, TC_SUBFR2IDX_16KHZ(tc_subfr)) ]; + nBits_code = (nBits_pitch+1)>>1; + nBits_pitch = nBits_pitch>>1; + + tmp16 = div_s(1,((1 << (nBits_pitch)) - 1) ); /* Q15*/ + tmp1 = (float)mult_r((short)(G_PITCH_MAX*8192.0f+0.5f),tmp16)/8192.0f; + index = usquant( *gain_pit, gain_pit, G_PITCH_MIN, tmp1, (1 << nBits_pitch) ); + push_indice( st, IND_GAIN_PIT, index, nBits_pitch ); + + g_code = *gain_code / gcode0; + index = gain_quant( &g_code, G_CODE_MIN, G_CODE_MAX, nBits_code ); + *gain_code = g_code * gcode0; + push_indice( st, IND_GAIN_CODE, index, nBits_code); + + *norm_gain_code = *gain_code / *gain_inov; + + return; +} + +/*-------------------------------------------------------------------* + * gain_enc_gaus() + * + * Quantization of gain for Gaussian codebook + *-------------------------------------------------------------------*/ + +short gain_enc_gaus( /* o : Return index of quantization */ + float *gain, /* i/o: Code gain to quantize */ + const short bits, /* i : number of bits to quantize */ + const float lowBound, /* i : lower bound of quantizer (dB) */ + const float topBound /* i : upper bound of quantizer (dB) */ +) +{ + short index; + float enr, stepSize; + + + enr = (float)( 20.0 * log10( *gain + 0.001f ) ); /* codebook gain in dB */ + + /*-----------------------------------------------------------------* + * quantize linearly the log E + *-----------------------------------------------------------------*/ + + stepSize = (topBound-lowBound)/((float)(1<= (1< 3 ) + { + g_code = *gain_code / gcode0; + index = gain_quant( &g_code, G_CODE_MIN, G_CODE_MAX, nBits ); + *gain_code = g_code * gcode0; + push_indice( st, IND_GAIN_CODE, index, nBits ); + } + else + { + index = N_GAIN_CODE_TC-1; + for( i=0; i < N_GAIN_CODE_TC-1; i++ ) + { + if( *gain_code < ((tbl_gain_code_tc[i]+(tbl_gain_code_tc[i+1]-tbl_gain_code_tc[i])/2) * gcode0) ) + { + index = i; + break; + } + } + + /*----------------------------------------------------------------* + * 3-bit -> 2-bit encoding + *----------------------------------------------------------------*/ + + if( nBits == 2 ) + { + index /= 2; + *gain_code = tbl_gain_code_tc[index*2] * gcode0; + push_indice( st, IND_GAIN_CODE, index, nBits ); + } + else + { + *gain_code = tbl_gain_code_tc[index] * gcode0; + push_indice( st, IND_GAIN_CODE, index, nBits ); + } + } + + *norm_gain_code = *gain_code / *gain_inov; + + return; +} + +/*---------------------------------------------------------------------* + * E_corr_xy2() + * + * Find the correlations between the target xn[], the filtered adaptive + * codebook exc. y1[], and the filtered fixed codebook innovation y2[]. + * ( , -2 and 2 ) (stored in g_corr[2..4]) + *---------------------------------------------------------------------*/ + +void E_corr_xy2( + const float xn[], /* i : target vector */ + const float y1[], /* i : filtered excitation components 1 */ + const float y2[], /* i : filtered excitation components 2 */ + float g_corr[],/* o : correlations between x, y1, y2, y3, y4 */ + const short L_subfr /* i : subframe size */ +) +{ + + + g_corr[2] = dotp(y2, y2, L_subfr); + g_corr[3] = -2.0f * dotp(xn, y2, L_subfr); + g_corr[4] = 2.0f * dotp(y1, y2, L_subfr); + + return; +} + + +/*---------------------------------------------------------------------* + * gain_enc_lbr() + * + * Quantization of pitch and codebook gains without prediction (memory-less) + * in ACELP at 7.2 and 8.0 kbps + * - the gain codebooks and gain estimation constants are different in each subframe + * - the estimated gain, gcode0, is first determined based on + * classification and/or previous quantized gains (from previous subframes in the current frame) + * - a correction factor gamma = g_code / gcode0 is then vector quantized + * along with gain_pit + * - the mean-squared error criterion is used for codebook search + *---------------------------------------------------------------------*/ + +void gain_enc_lbr( + Encoder_State *st, /* i/o: encoder state structure */ + const long core_brate, /* i : core bitrate */ + const short coder_type, /* i : coding type */ + const short i_subfr, /* i : subframe index */ + const float *xn, /* i : target vector */ + const float *y1, /* i : zero-memory filtered adaptive excitation */ + const float *y2, /* i : zero-memory filtered algebraic codebook excitation */ + const float *code, /* i : algebraic excitation */ + float *gain_pit, /* o : quantized pitch gain */ + float *gain_code, /* o : quantized codebook gain */ + float *gain_inov, /* o : gain of the innovation (used for normalization) */ + float *norm_gain_code, /* o : norm. gain of the codebook excitation */ + float *g_corr, /* i/o: correlations , -2,, -2 and 2 */ + float gains_mem[], /* i/o: pitch gain and code gain from previous subframes */ + const short clip_gain /* i : gain pitch clipping flag (1 = clipping) */ +) +{ + short index = 0, i, size, nBits, n_pred, ctype; + float dist, dist_min, g_pitch, g_code, gcode0, aux[10], Ecode; + short rf_flag = 0; + const float *p, *b, *cdbk = 0; + + /*-----------------------------------------------------------------* + * calculate the rest of the correlation coefficients + * c2 = , c3 = -2, c4 = 2, c5* = + * c5* - not necessary to calculate + *-----------------------------------------------------------------*/ + + E_corr_xy2( xn, y1, y2, g_corr,L_SUBFR); + g_corr[2] += 0.01F; + g_corr[3] -= 0.02F; + g_corr[4] += 0.02F; + Ecode = ( dotp( code, code, L_SUBFR ) + 0.01f ) / L_SUBFR; + *gain_inov = 1.0f / (float)sqrt(Ecode); + + /*-----------------------------------------------------------------* + * select the codebook, size and number of bits + * set the gains searching range + *-----------------------------------------------------------------*/ + + nBits = gain_bits_tbl[BIT_ALLOC_IDX(core_brate, coder_type, i_subfr, 0)]; + size = (short)pow2[nBits]; + + /*-----------------------------------------------------------------* + * calculate prediction of gcode + * search for the best codeword + *-----------------------------------------------------------------*/ + + ctype = 2*(coder_type - 1); + if (i_subfr == 0) + { + b = b_1sfr; + n_pred = 2; + + switch ( nBits ) + { + case 8: + { + cdbk = gp_gamma_1sfr_8b; + if ( clip_gain == 1 ) size -= 60; + break; + } + case 7: + { + cdbk = gp_gamma_1sfr_7b; + if ( clip_gain == 1 ) size -= 27; + break; + } + case 6: + { + cdbk = gp_gamma_1sfr_6b; + if ( clip_gain == 1 ) size -= 10; + break; + } + } + + /* calculate predicted gain */ + aux[0] = 1.0f; + aux[1] = ctype; + gcode0 = (float)pow(10, dotp(b, aux, n_pred) - 0.5f * (float)log10(Ecode)); + + /* searching of codebook */ + p = cdbk; + dist_min = 3.402823466e+38F; + index = 0; + for (i = 0; i, -2,, -2 and 2 */ - const Word16 clip_gain /* i : gain pitch clipping flag (1 = clipping) */ - -) -{ - - Word16 index, size, nBits, nBits2; - Word16 gcode0, Ei, gain_code16; - const Word16 *qua_table; - Word16 coeff[5], exp_coeff[5]; - Word16 exp, exp_code, exp_inov, exp_gcode0, frac, tmp; - Word32 L_tmp, L_tmp1, L_tmp2; - Word16 tmp1, expg; - Word16 exp1, exp2; - Word16 exp_num, exp_den, exp_div, frac_den; - Word32 L_frac_num, L_frac_den, L_div; - - /*-----------------------------------------------------------------* - * calculate the rest of the correlation coefficients - * c2 = , c3 = -2, c4 = 2 - *-----------------------------------------------------------------*/ - - coeff[0] = g_corr[0]; - move16(); - exp_coeff[0] = g_corr[1]; - move16(); - coeff[1] = negate(g_corr[2]); - move16(); /* coeff[1] = -2 xn yy1 */ - exp_coeff[1] = add(g_corr[3], 1); - move16(); - - /* Compute scalar product */ - coeff[2] = extract_h(Dot_product12(y2, y2, L_SUBFR, &exp)); - exp_coeff[2] = add(sub(exp, 18), shl(Q_xn, 1)); - move16(); /* -18 (y2 Q9) */ - - /* Compute scalar product -2* */ - coeff[3] = extract_h(L_negate(Dot_product12(xn, y2, L_SUBFR, &exp))); - exp_coeff[3] = add(sub(exp, 9 - 1), Q_xn); - move16(); /* -9 (y2 Q9), +1 (2 xn y2) */ - - /* Compute scalar product 2* */ - coeff[4] = extract_h(Dot_product12(y1, y2, L_SUBFR, &exp)); - exp_coeff[4] = add(sub(exp, 9 - 1), Q_xn); - move16(); /* -9 (y2 Q9), +1 (2 y1 y2) */ - - /*-----------------------------------------------------------------* - * calculate the unscaled innovation energy - * calculate the predicted gain code - *-----------------------------------------------------------------*/ - - /* gain_inov = 1.0f / sqrt((dot_product(code, code, L_SUBFR) + 0.01) / L_SUBFR) */ - L_tmp = Dot_product12(code, code, L_SUBFR, &exp_code); - exp_inov = sub(exp_code, 18+6); - exp_code = sub(exp_code, 30); - - /*Ei = 10 * log10((dot_product(code, code, L_SUBFR) + 0.01) / L_SUBFR) */ - - /*----------------------------------------------------------------* - * calculate the predicted gain code - *----------------------------------------------------------------*/ - tmp = norm_l(L_tmp); - frac = Log2_norm_lc(L_shl(L_tmp, tmp)); - tmp = add(30-18-6-1, sub(exp_code, tmp)); /* exp: -18 (code in Q9), -6 (/L_SUBFR) */ - L_tmp1 = Mpy_32_16(tmp, frac, 12330); /* Q13 */ - Ei = round_fx(L_shl(L_tmp1, 11)); /* Q8 */ - - /* predicted codebook gain */ - gcode0 = sub(Es_pred, Ei); /* Q8 */ - - /*---------------------------------------------------------------* - * Decode codebook gain and the adaptive excitation low-pass - * filtering factor (Finalize computation ) - *---------------------------------------------------------------*/ - /* gain_inov = 1.0f / sqrt((dot_product(code, code, L_SUBFR) + 0.01) / L_SUBFR) */ - L_tmp = Isqrt_lc(L_tmp, &exp_inov); - *gain_inov = extract_h(L_shl(L_tmp, sub(exp_inov, 3))); /* gain_inov in Q12 */ - - /* gcode0 = pow(10, 0.05 * (Es_pred - Ei)) */ - /*----------------------------------------------------------------* - * gcode0 = pow(10.0, gcode0/20) - * = pow(2, 3.321928*gcode0/20) - * = pow(2, 0.166096*gcode0) - *----------------------------------------------------------------*/ - - L_tmp = L_mult(gcode0, 21771); /* *0.166096 in Q17 -> Q26 */ - L_tmp = L_shr(L_tmp, 10); /* From Q26 to Q16 */ - frac = L_Extract_lc(L_tmp, &exp_gcode0); /* Extract exponent of gcode0 */ - - gcode0 = extract_l(Pow2(14, frac)); /* Put 14 as exponent so that */ - /* output of Pow2() will be: */ - /* 16384 < Pow2() <= 32767 */ - exp_gcode0 = sub(exp_gcode0, 14); - - /*-----------------------------------------------------------------* - * select the codebook, size and number of bits - * set the gains searching range - *-----------------------------------------------------------------*/ - IF( sub(L_frame,L_FRAME) == 0 ) - { - nBits = gain_bits_tbl[BIT_ALLOC_IDX_fx(core_brate, coder_type, i_subfr, TC_SUBFR2IDX_fx(tc_subfr))]; - move16(); - } - ELSE /* L_frame == L_FRAME16k */ - { - nBits = gain_bits_16kHz_tbl[BIT_ALLOC_IDX_16KHZ_fx(core_brate, coder_type, i_subfr, TC_SUBFR2IDX_16KHZ_fx(tc_subfr)) ]; - move16(); - } - test(); - test(); - test(); - test(); - test(); - IF( (sub(tc_subfr,3*L_SUBFR) == 0 && sub(i_subfr,3*L_SUBFR) == 0 && sub(L_frame,L_FRAME) == 0) || - (sub(tc_subfr,4*L_SUBFR) == 0 && sub(i_subfr,4*L_SUBFR) == 0 && sub(L_frame,L_FRAME16k) == 0) ) - { - /* *gain_pit = (g_corr[2]*tmp2) - (0.5f*g_corr[4]*tmp3); - = ((-0.5f*g_corr[1]*g_corr[2]) - (-0.25*g_corr[3]*g_corr[4]))/tmp1; - = ((0.25*g_corr[3]*g_corr[4]) - (0.5*g_corr[1]*g_corr[2]))/tmp1; */ - - /* *gain_code = (g_corr[0]*tmp3) - (0.5f*g_corr[4]*tmp2); - = ((-0.5*g_corr[3]*g_corr[0]) - (-0.25*g_corr[1]*g_corr[4]))/tmp1; - = ((0.25*g_corr[1]*g_corr[4]) - (0.5*g_corr[0]*g_corr[3]))/tmp1; */ - - L_tmp1 = L_mult(coeff[0],coeff[2]); /*Q31*/ - exp1 = add(exp_coeff[0], exp_coeff[2]); - - L_tmp2 = L_shr(L_mult(coeff[4],coeff[4]),2); /*Q31*/ - exp2 = add(exp_coeff[4], exp_coeff[4]); - - IF(sub(exp1,exp2)>0) - { - L_tmp2 = L_shr(L_tmp2,sub(exp1,exp2)); /*Q31*/ - exp_den = exp1; - move16(); - } - ELSE - { - L_tmp1 = L_shr(L_tmp1,sub(exp2,exp1)); /*Q31*/ - exp_den = exp2; - move16(); - } - L_frac_den = L_sub(L_tmp1,L_tmp2); /*Q31*/ - - frac_den = extract_h(L_frac_den); - frac_den = s_max(frac_den,1); - L_frac_den = L_max(L_frac_den,1); - exp = norm_l(L_frac_den); - tmp = div_s(shl(1,sub(14,exp)),frac_den); /*Q(14-exp)*/ - - L_tmp1 = L_shr(L_mult(coeff[3],coeff[4]),2); /*Q31*/ - exp1 = add(exp_coeff[3], exp_coeff[4]); - - L_tmp2 = L_shr(L_mult(coeff[1],coeff[2]),1); /*Q31*/ - exp2 = add(exp_coeff[1], exp_coeff[2]); - - IF(sub(exp1,exp2)>0) - { - L_tmp2 = L_shr(L_tmp2,sub(exp1,exp2)); /*Q31*/ - exp_num = exp1; - move16(); - } - ELSE - { - L_tmp1 = L_shr(L_tmp1,sub(exp2,exp1)); /*Q31*/ - exp_num = exp2; - move16(); - } - L_frac_num = L_sub(L_tmp1,L_tmp2); /*Q31*/ - - L_div = Mult_32_16(L_frac_num,tmp); /*Q(30-exp)*/ - exp_div = sub(exp_num,exp_den); - - *gain_pit = round_fx(L_shl(L_div,add(exp,exp_div))); /*Q14*/ - - L_tmp1 = L_shr(L_mult(coeff[1],coeff[4]),2); /*Q31*/ - exp1 = add(exp_coeff[1], exp_coeff[4]); - - L_tmp2 = L_shr(L_mult(coeff[0],coeff[3]),1); /*Q31*/ - exp2 = add(exp_coeff[0], exp_coeff[3]); - - IF(sub(exp1,exp2)>0) - { - L_tmp2 = L_shr(L_tmp2,sub(exp1,exp2)); /*Q31*/ - exp_num = exp1; - } - ELSE - { - L_tmp1 = L_shr(L_tmp1,sub(exp2,exp1)); /*Q31*/ - exp_num = exp2; - } - L_frac_num = L_sub(L_tmp1,L_tmp2); /*Q31*/ - - L_div = Mult_32_16(L_frac_num,tmp); /*Q(30-exp)*/ - exp_div = sub(exp_num,exp_den); - - *gain_code = L_shl(L_div,sub(add(exp,exp_div),14)); - move32();/*Q16*/ - - *gain_pit = s_max(G_PITCH_MIN_TC192_Q14,s_min(*gain_pit,G_PITCH_MAX_TC192_Q14)); - - /* set number of bits for two SQs */ - nBits2 = shr(add(nBits,1),1); - nBits = shr(nBits,1); - - /* gain_pit Q */ - - tmp1 = mult_r(G_PITCH_MAX_MINUS_MIN_TC192_Q13,div_s(1,sub(shl(1, nBits), 1))); /*Q13*/ /* set quantization step */ - index = usquant_fx( *gain_pit, gain_pit, G_PITCH_MIN_TC192_Q14, tmp1, shl(1, nBits) ); - move16(); - push_indice_fx( st_fx, IND_GAIN_PIT, index, nBits ); - - /* gain_code Q */ - /**gain_code /= gcode0;*/ - IF(gcode0 != 0) - { - tmp = div_s(16384,gcode0); /*Q15*/ - L_tmp = Mult_32_16(*gain_code,tmp); /*Q16*/ - *gain_code = L_shr(L_tmp,add(14,exp_gcode0)); /*Q16*/ - } - - index = gain_quant_fx( gain_code, &gain_code16, LG10_G_CODE_MIN_TC192_Q14, LG10_G_CODE_MAX_TC192_Q13, nBits2, &expg ); - push_indice_fx( st_fx, IND_GAIN_CODE, index, nBits2 ); - L_tmp = L_mult(gain_code16,gcode0); /*Q0*Q0 -> Q1*/ - *gain_code = L_shl(L_tmp,add(add(expg,exp_gcode0),15)); /*Q16*/ - } - ELSE - { - size = extract_l(pow2[nBits]); - - SWITCH ( nBits ) - { - case 7: - { - qua_table = gain_qua_mless_7b_fx; - move16(); - if ( sub(clip_gain,1) == 0 ) size = sub(size,30); - BREAK; - } - case 6: - { - qua_table = gain_qua_mless_6b_fx; - move16(); - if ( sub(clip_gain,1) == 0 ) size = sub(size,14); - BREAK; - } - case 5: - { - qua_table = gain_qua_mless_5b_fx; - move16(); - if ( sub(clip_gain,1) == 0 ) size = sub(size,6); - BREAK; - } - default: - { - qua_table = gain_qua_mless_6b_fx; - move16(); - if ( sub(clip_gain,1) == 0 ) size = sub(size,14); - BREAK; - } - } - - /* in case of AVQ inactive, limit the gain_pit to 0.65 */ - test(); - IF( sub(clip_gain,2) == 0 && sub(nBits,6) == 0 ) - { - size = sub(size,36); - nBits = sub(nBits,1); - } - - /*-----------------------------------------------------------------* - * search for the best quantizer - *-----------------------------------------------------------------*/ - index = Find_Opt_gainQ_fx(coeff, exp_coeff, gain_pit, gain_code, gcode0, exp_gcode0, qua_table, size); - push_indice_fx( st_fx, IND_GAIN, index, nBits ); - } - - /* *norm_gain_code = *gain_code / *gain_inov; */ - exp = sub(norm_s(*gain_inov),1); - exp = s_max(exp, 0); - - tmp = div_s(shr(8192,exp),*gain_inov); - *norm_gain_code = L_shr(Mult_32_16(*gain_code, tmp),sub(1,exp)); - move32(); - - return; -} - - -/*---------------------------------------------------------------------* -* gain_enc_SQ() -* -* Scalar Quantization of pitch and codebook gains without prediction -* - an initial predicted gain, gcode0, is first determined based on -* the predicted scaled innovation energy -* - a correction factor gamma = g_code / gcode0 is then vector quantized -* along with gain_pit -* - the mean-squared weighted error criterion is used for codebook search -*---------------------------------------------------------------------*/ - -void gain_enc_SQ_fx( - Encoder_State_fx *st_fx, /* i/o: encoder state structure */ - const Word32 core_brate, /* i : core bitrate */ - const Word16 coder_type, /* i : coding type */ - const Word16 i_subfr, /* i : subframe index */ - const Word16 tc_subfr, /* i : TC subframe index */ - const Word16 *xn, /* i : target vector Q_xn */ - const Word16 *yy1, /* i : zero-memory filtered adaptive excitation Q_xn */ - const Word16 *y2, /* i : zero-memory filtered algebraic codebook excitation Q9 */ - const Word16 *code, /* i : algebraic excitation Q9 */ - const Word16 Es_pred, /* i : predicted scaled innovation energy Q8 */ - Word16 *gain_pit, /* o : quantized pitch gain Q14 */ - Word32 *gain_code, /* o : quantized codebook gain Q16 */ - Word16 *gain_inov, /* o : gain of the innovation (used for normalization) Q12 */ - Word32 *norm_gain_code, /* o : norm. gain of the codebook excitation Q16 */ - Word16 *g_corr, /* i/o: correlations , ,, -2 and 2 */ - const Word16 clip_gain, /* i : gain pitch clipping flag (1 = clipping) */ - const Word16 Q_xn /* i : xn and y1 scaling */ -) -{ - Word16 index, nBits_pitch, nBits_code; - Word16 gcode0, Ei, gain_code16; - Word16 coeff[5], exp_coeff[5]; - Word16 exp, exp_code, exp_inov, exp_gcode0, frac, tmp; - - Word32 L_tmp, L_tmp1, L_tmp2; - Word16 tmp1, expg; - Word16 exp1, exp2; - Word16 exp_num, exp_den, exp_div, frac_den; - Word32 L_frac_num, L_frac_den, L_div; - - /*-----------------------------------------------------------------* - * calculate the rest of the correlation coefficients - * c2 = , c3 = -2, c4 = 2 - *-----------------------------------------------------------------*/ - /*g_corr[1] *= -0.5;*/ - /*g_corr[2] = dotp( y2, y2, L_SUBFR ) + 0.01f;*/ - /*g_corr[3] = dotp( xn, y2, L_SUBFR ) - 0.02f;*/ - /*g_corr[4] = dotp( yy1, y2, L_SUBFR ) + 0.02f;*/ - - coeff[0] = g_corr[0]; - move16(); - exp_coeff[0] = g_corr[1]; - move16(); - coeff[1] = g_corr[2]; - move16(); /* coeff[1] = xn yy1 */ - exp_coeff[1] = g_corr[3]; - move16(); - - /* Compute scalar product */ - coeff[2] = extract_h(Dot_product12(y2, y2, L_SUBFR, &exp)); - exp_coeff[2] = add(sub(exp, 18), shl(Q_xn, 1)); - move16(); /* -18 (y2 Q9) */ - - /* Compute scalar product */ - coeff[3] = extract_h(Dot_product12(xn, y2, L_SUBFR, &exp)); - exp_coeff[3] = add(sub(exp, 9 ), Q_xn); - move16(); /* -9 (y2 Q9), (xn y2) */ - - /* Compute scalar product */ - coeff[4] = extract_h(Dot_product12(yy1, y2, L_SUBFR, &exp)); - exp_coeff[4] = add(sub(exp, 9), Q_xn); - move16(); /* -9 (y2 Q9), (y1 y2) */ - - /*-----------------------------------------------------------------* - * calculate the unscaled innovation energy - * calculate the predicted gain code - * calculate optimal gains - *-----------------------------------------------------------------*/ - /*Ecode = (dotp( code, code, L_SUBFR) + 0.01f) / L_SUBFR;*/ - /**gain_inov = 1.0f / (float)sqrt( Ecode );*/ - - L_tmp = Dot_product12(code, code, L_SUBFR, &exp_code); - exp_inov = sub(exp_code, 18+6); - exp_code = sub(exp_code, 30); - - /*Ei = 10 * log10((dot_product(code, code, L_SUBFR) + 0.01) / L_SUBFR) */ - /*----------------------------------------------------------------* - * calculate the predicted gain code - *----------------------------------------------------------------*/ - tmp = norm_l(L_tmp); - frac = Log2_norm_lc(L_shl(L_tmp, tmp)); - tmp = add(30-18-6-1, sub(exp_code, tmp)); /* exp: -18 (code in Q9), -6 (/L_SUBFR) */ - L_tmp1 = Mpy_32_16(tmp, frac, 12330); /* Q13 */ - Ei = round_fx(L_shl(L_tmp1, 11)); /* Q8 */ - - /* predicted codebook gain */ - gcode0 = sub(Es_pred, Ei); /* Q8 */ - - /*---------------------------------------------------------------* - * Decode codebook gain and the adaptive excitation low-pass - * filtering factor (Finalize computation ) - *---------------------------------------------------------------*/ - /* gain_inov = 1.0f / sqrt((dot_product(code, code, L_SUBFR) + 0.01) / L_SUBFR) */ - L_tmp = Isqrt_lc(L_tmp, &exp_inov); - *gain_inov = extract_h(L_shl(L_tmp, sub(exp_inov, 3))); /* gain_inov in Q12 */ - - /* gcode0 = pow(10, 0.05 * (Es_pred - Ei)) */ - /*----------------------------------------------------------------* - * gcode0 = pow(10.0, gcode0/20) - * = pow(2, 3.321928*gcode0/20) - * = pow(2, 0.166096*gcode0) - *----------------------------------------------------------------*/ - - L_tmp = L_mult(gcode0, 21771); /* *0.166096 in Q17 -> Q26 */ - L_tmp = L_shr(L_tmp, 10); /* From Q26 to Q16 */ - frac = L_Extract_lc(L_tmp, &exp_gcode0); /* Extract exponent of gcode0 */ - - gcode0 = extract_l(Pow2(14, frac)); /* Put 14 as exponent so that */ - /* output of Pow2() will be: */ - /* 16384 < Pow2() <= 32767 */ - exp_gcode0 = sub(exp_gcode0, 14); - - - /*tmp1 = (g_corr[0]*g_corr[2]) - (g_corr[4]*g_corr[4]); - tmp2 = g_corr[1]/tmp1; - tmp1 = g_corr[3]/tmp1; - - *gain_pit = (g_corr[2]*tmp2) - (g_corr[4]*tmp1); - *gain_code = (g_corr[0]*tmp1) - (g_corr[4]*tmp2);*/ - - /* *gain_pit = (g_corr[2]*tmp2) - (g_corr[4]*tmp3); - = ((g_corr[1]*g_corr[2]) - (g_corr[3]*g_corr[4]))/tmp1;*/ - - /* *gain_code = (g_corr[0]*tmp3) - (g_corr[4]*tmp2); - = ((g_corr[3]*g_corr[0]) - (g_corr[1]*g_corr[4]))/tmp1;*/ - - L_tmp1 = L_mult(coeff[0],coeff[2]); /*Q31*/ - exp1 = add(exp_coeff[0], exp_coeff[2]); - - L_tmp2 = L_mult(coeff[4],coeff[4]); /*Q31*/ - exp2 = add(exp_coeff[4], exp_coeff[4]); - - IF(sub(exp1,exp2)>0) - { - L_tmp2 = L_shr(L_tmp2,sub(exp1,exp2)); /*Q31*/ - exp_den = exp1; - move16(); - } - ELSE - { - L_tmp1 = L_shr(L_tmp1,sub(exp2,exp1)); /*Q31*/ - exp_den = exp2; - move16(); - } - L_frac_den = L_sub(L_tmp1,L_tmp2); /*Q31*/ - - frac_den = extract_h(L_frac_den); - frac_den = s_max(frac_den,1); - L_frac_den = L_max(L_frac_den,1); - exp = norm_l(L_frac_den); - tmp = div_s(shl(1,sub(14,exp)),frac_den); /*Q(14-exp)*/ - - - - L_tmp1 = L_mult(coeff[3],coeff[4]); /*Q31*/ - exp1 = add(exp_coeff[3], exp_coeff[4]); - - L_tmp2 = L_mult(coeff[1],coeff[2]); /*Q31*/ - exp2 = add(exp_coeff[1], exp_coeff[2]); - - IF(sub(exp1,exp2)>0) - { - L_tmp2 = L_shr(L_tmp2,sub(exp1,exp2)); /*Q31*/ - exp_num = exp1; - move16(); - } - ELSE - { - L_tmp1 = L_shr(L_tmp1,sub(exp2,exp1)); /*Q31*/ - exp_num = exp2; - move16(); - } - L_frac_num = L_sub(L_tmp2, L_tmp1); /*Q31*/ - - L_div = Mult_32_16(L_frac_num,tmp); /*Q(30-exp)*/ - exp_div = sub(exp_num,exp_den); - - *gain_pit = round_fx(L_shl(L_div,add(exp,exp_div))); /*Q14*/ - - L_tmp1 = L_mult(coeff[1],coeff[4]); /*Q31*/ - exp1 = add(exp_coeff[1], exp_coeff[4]); - - L_tmp2 = L_mult(coeff[0],coeff[3]); /*Q31*/ - exp2 = add(exp_coeff[0], exp_coeff[3]); - - IF(sub(exp1,exp2)>0) - { - L_tmp2 = L_shr(L_tmp2,sub(exp1,exp2)); /*Q31*/ - exp_num = exp1; - } - ELSE - { - L_tmp1 = L_shr(L_tmp1,sub(exp2,exp1)); /*Q31*/ - exp_num = exp2; - } - L_frac_num = L_sub(L_tmp2, L_tmp1); /*Q31*/ - - L_div = Mult_32_16(L_frac_num,tmp); /*Q(30-exp)*/ - exp_div = sub(exp_num,exp_den); - - *gain_code = L_shl(L_div,s_max(-31,sub(add(exp,exp_div),14))); - move32();/*Q16*/ - - *gain_pit = s_max(G_PITCH_MIN_Q14,s_min(*gain_pit,G_PITCH_MAX_Q14)); - - /*-----------------------------------------------------------------* - * limit the pitch gain searching range (if indicated by clip_gain) - *-----------------------------------------------------------------*/ - - test(); - test(); - IF( sub(clip_gain,1) == 0 && sub(*gain_pit, 15565) > 0) - { - *gain_pit = 15565; - move16(); - } - ELSE IF( sub(clip_gain,2) == 0 && sub(*gain_pit,10650) > 0 ) - { - *gain_pit = 10650; - move16(); - } - - /*-----------------------------------------------------------------* - * search for the best quantized values - *-----------------------------------------------------------------*/ - - nBits_pitch = gain_bits_16kHz_tbl[BIT_ALLOC_IDX_16KHZ_fx(core_brate, coder_type, i_subfr, TC_SUBFR2IDX_16KHZ_fx(tc_subfr)) ]; - - /* set number of bits for two SQs */ - nBits_code = shr(add(nBits_pitch,1),1); - nBits_pitch = shr(nBits_pitch,1); - - /* gain_pit Q */ - /*tmp1 = (G_PITCH_MAX - G_PITCH_MIN) / ((1 << nBits_pitch) - 1);*/ /* set quantization step */ - tmp1 = mult_r(G_PITCH_MAX_Q13,div_s(1,sub(shl(1, nBits_pitch), 1))); /*Q13*/ /* set quantization step */ - - index = usquant_fx( *gain_pit, gain_pit, G_PITCH_MIN_Q14, tmp1, shl(1, nBits_pitch) ); - move16(); - push_indice_fx( st_fx, IND_GAIN_PIT, index, nBits_pitch ); - - /* gain_code Q */ - /* *gain_code /= gcode0; */ - IF(gcode0 != 0) - { - tmp = div_s(16384,gcode0); /*Q15*/ - L_tmp = Mult_32_16(*gain_code,tmp); /*Q16*/ - *gain_code = L_shr(L_tmp,add(14,exp_gcode0)); /*Q16*/ - } - - index = gain_quant_fx( gain_code, &gain_code16, LG10_G_CODE_MIN_Q14, LG10_G_CODE_MAX_Q13, nBits_code, &expg ); - push_indice_fx( st_fx, IND_GAIN_CODE, index, nBits_code ); - L_tmp = L_mult(gain_code16,gcode0); /*Q0*Q0 -> Q1*/ - *gain_code = L_shl(L_tmp,add(add(expg,exp_gcode0),15)); - move32(); /*Q16*/ - - /* *norm_gain_code = *gain_code / *gain_inov; */ - exp = sub(norm_s(*gain_inov),1); - exp = s_max(exp, 0); - - tmp = div_s(shr(8192,exp),*gain_inov); - *norm_gain_code = L_shr(Mult_32_16(*gain_code, tmp),sub(1,exp)); - move32(); - - return; -} - -/*-------------------------------------------------------------------* - * gain_enc_gaus() - * - * Quantization of gain for Gaussian codebook - *-------------------------------------------------------------------*/ -Word16 gain_enc_gaus_fx( /* o : Return index of quantization */ - Word32 *gain, /* i/o: Code gain to quantize */ - const Word16 bits, /* i : number of bits to quantize */ - const Word16 lowBound, /* i : lower bound of quantizer (dB) Q8 */ - const Word16 stepSize, /* i : Step size choice Q14 */ - const Word16 inv_stepSize /* i : Step size choice Q15 */ -) -{ - Word16 index, exp_gain, frac_gain, wtmp; - Word16 enr_q, wenr; - Word32 Ltmp, enr; - - /*enr = 20.0 * log10(*gain + 0.001) codebook gain in dB */ - exp_gain = norm_l(*gain); - frac_gain = Log2_norm_lc(L_shl(*gain, exp_gain)); - exp_gain = sub(30-16, exp_gain); - - enr = Mpy_32_16(exp_gain, frac_gain, LG10); /* Output in Q13 */ - wenr = extract_h(L_shl(enr, 8+3)); - - /*----------------------------------------------------------------* - * Quantize linearly the log E - *----------------------------------------------------------------*/ - - wtmp = sub(wenr, lowBound); /* Q8 */ - - index = extract_l(L_shr(L_mac(8388608, wtmp, inv_stepSize),16+8)); - - /* index [0 (1< Q26 */ - enr = L_shr(enr, 10); /*Q26->Q16*/ - frac_gain = L_Extract_lc(enr, &exp_gain); - - Ltmp = Pow2(14, frac_gain); /* Put 14 as exponent */ - exp_gain= sub(exp_gain, 14); /* Retreive exponent of wtmp */ - *gain = L_shl(Ltmp ,add(16,exp_gain)); - move32(); /*Q16*/ - - return index; -} -/*-----------------------------------------------------------------* - * gain_enc_tc() - * - * Search and quantization of gain_code for subframes (in the - * beginning of frame) without pulses in TC - 3b coding. - * In this case: - * - gain_pit = 0 - * - gain_code - scalar quantization (no prediciton history used) - *-----------------------------------------------------------------*/ -void gain_enc_tc_fx( - Encoder_State_fx *st_fx, /* i/o: encoder state structure */ - const Word32 core_brate, /* i : core bitrate */ - const Word16 L_frame, /* i : length of the frame */ - const Word16 i_subfr, /* i : subframe index */ - const Word16 tc_subfr, /* i : TC subframe index */ - const Word16 xn_fx[], /* i : target vector */ - const Word16 y2_fx[], /* i : zero-memory filtered algebraic codebook excitation */ - const Word16 code_fx[], /* i : algebraic excitation */ - const Word16 Es_pred_fx, /* i : predicted scaled innovation energy */ - Word16 *gain_pit_fx, /* o : Pitch gain / Quantized pitch gain */ - Word32 *gain_code_fx, /* o : quantized codebook gain */ - Word16 *gain_inov_fx, /* o : innovation gain */ - Word32 *norm_gain_code_fx, /* o : norm. gain of the codebook excitation */ - const Word16 Q_xn /* i : xn and y1 scaling Q0 */ -) -{ - Word16 i, index=0, nBits, num, den, exp_num, exp_den; - Word16 Ei_fx, g_code_fx, gcode0_fx; - Word16 expg, expg2, e_tmp, f_tmp, exp_gcode0, tmp_fx, frac,tmp16; - Word32 L_tmp, L_tmp1; - Word16 wgain_code=0, gain_code16; - *gain_pit_fx = 0; - move16(); - /*----------------------------------------------------------------* - * get number of bits for gain quantization - *----------------------------------------------------------------*/ - IF( sub(L_frame,L_FRAME) == 0 ) - { - nBits = gain_bits_tbl[BIT_ALLOC_IDX_fx(core_brate, TRANSITION, i_subfr, TC_SUBFR2IDX_fx(tc_subfr))]; - move16(); - } - ELSE /* L_frame == L_FRAME16k */ - { - nBits = gain_bits_16kHz_tbl[BIT_ALLOC_IDX_16KHZ_fx(core_brate, TRANSITION, i_subfr, TC_SUBFR2IDX_16KHZ_fx(tc_subfr))]; - move16(); - } - - /*----------------------------------------------------------------* - * find the code pitch (for current subframe) - *----------------------------------------------------------------*/ - - /**gain_code = dotp( xn, y2, L_SUBFR )/( dotp( y2, y2, L_SUBFR ) + 0.01f );*/ - /* Compute scalar product */ - L_tmp = Dot_product(y2_fx, y2_fx, L_SUBFR); /* -18 (y2 Q9) */ - exp_den = norm_l(L_tmp); - den = extract_h(L_shl(L_tmp, exp_den)); - exp_den = sub(add(exp_den, 18), shl(Q_xn, 1)); - - /* Compute scalar product */ - L_tmp1 = Dot_product(xn_fx, y2_fx, L_SUBFR); /* -9 (y2 Q9) */ - exp_num = sub(norm_l(L_tmp1),1); - num = extract_h(L_shl(L_tmp1, exp_num)); - exp_num = sub(add(exp_num, 8 ), Q_xn); - - tmp16 = s_or(shr(num, 16), 1); /* extract sign if num < 0 tmp16 = -1 else tmp16 = 1 */ - num = abs_s(num); - - /*----------------------------------------------------------------* - * compute gain = xy/yy - *----------------------------------------------------------------*/ - g_code_fx = div_s(num, den); - - i = sub(exp_num, exp_den); /* Gain_trans in Q7 */ - g_code_fx = i_mult2(g_code_fx, tmp16); /* apply sign */ - *gain_code_fx = L_shr(L_deposit_l(g_code_fx),i); - move32(); - - /*----------------------------------------------------------------* - * calculate the predicted gain code - * decode codebook gain - *----------------------------------------------------------------*/ - - *gain_pit_fx = 0; - move16(); - - /*Ecode = (dotp( code, code, L_SUBFR) + 0.01f) / L_SUBFR; - *gain_inov = 1.0f / (float)sqrt( Ecode );*/ - - L_tmp = Dot_product12(code_fx, code_fx, L_SUBFR, &expg); - expg = sub(expg, 18 + 6); /* exp: -18 (code in Q9), -6 (/L_SUBFR) */ - expg2 = expg; - move16(); - L_tmp1 = L_add(0,L_tmp); /* sets to 'L_tmp' in 1 clock */ - L_tmp = Isqrt_lc(L_tmp, &expg); - - *gain_inov_fx = extract_h(L_shl(L_tmp, sub(expg, 3))); - move16();/* gain_inov in Q12 */ - - /*Ei = 10 * (float)log10( Ecode );*/ - e_tmp = norm_l(L_tmp1); - f_tmp = Log2_norm_lc(L_shl(L_tmp1, e_tmp)); - e_tmp = sub(expg2,add(1,e_tmp)); - L_tmp1 = Mpy_32_16(e_tmp, f_tmp, 12330); /* Q13 */ /* 10*log10(2) in Q12*/ - Ei_fx = round_fx(L_shl(L_tmp1, 11)); /* Q8 */ - /*gcode0 = (float) pow(10, 0.05 * (Es_pred - Ei));*/ - gcode0_fx = sub(Es_pred_fx, Ei_fx); /* Q8 */ - /*-----------------------------------------------------------------* - * gcode0 = pow(10.0, gcode0/20) - * = pow(2, 3.321928*gcode0/20) - * = pow(2, 0.166096*gcode0) - *-----------------------------------------------------------------*/ - L_tmp = L_mult(gcode0_fx, 21771); /* *0.166096 in Q17 -> Q26 */ - L_tmp = L_shr(L_tmp, 10); /* From Q26 to Q16 */ - frac = L_Extract_lc(L_tmp, &exp_gcode0); /* Extract exponent of gcode0 */ - gcode0_fx = extract_l(Pow2(14, frac));/* Put 14 as exponent so that */ - exp_gcode0 = sub(exp_gcode0, 14); - IF( sub(nBits,3) > 0 ) - { - /*g_code = *gain_code / gcode0;*/ - IF(gcode0_fx != 0) - { - tmp16 = div_s(16384,gcode0_fx); /*Q15*/ - L_tmp = Mult_32_16(*gain_code_fx,tmp16); /*Q16*/ - *gain_code_fx = L_shr(L_tmp,add(14,exp_gcode0)); /*Q16*/ - } - ELSE - { - *gain_code_fx = MAX_32; - move32(); - } - - /*index = gain_quant( &g_code, G_CODE_MIN, G_CODE_MAX, nBits );*/ - index = gain_quant_fx( gain_code_fx, &gain_code16, LG10_G_CODE_MIN_TC_Q14, LG10_G_CODE_MAX_TC_Q13, nBits, &expg ); - - /**gain_code = g_code * gcode0;*/ - L_tmp = L_mult(gain_code16,gcode0_fx); /*Q0*Q0 -> Q1*/ - *gain_code_fx = L_shl(L_tmp,add(add(expg,exp_gcode0),15)); /*Q16*/ move32(); - - push_indice_fx( st_fx, IND_GAIN_CODE, index, nBits ); - } - ELSE - { - index = N_GAIN_CODE_TC-1; - move16(); - FOR( i=0; i < N_GAIN_CODE_TC-1; i++ ) - { - L_tmp = L_mult(tbl_gain_code_tc_quant_mean[i], gcode0_fx); /* Q13*Q0 -> Q14 */ - L_tmp = L_shl(L_tmp, add(exp_gcode0, 2)); /* Q14 -> Q16 */ - - IF( L_sub(*gain_code_fx, L_tmp) < 0 ) - { - index = i; - move16(); - BREAK; - } - } - /*----------------------------------------------------------------* - * 3-bit -> 2-bit encoding - *----------------------------------------------------------------*/ - IF( sub(nBits,2) == 0 ) - { - /* 2-bit -> 3-bit decoding */ - index = shr(index ,1); - wgain_code = tbl_gain_code_tc_fx[shl(index,1)]; - move16(); - /**gain_code *= gcode0;*/ - L_tmp = L_mult(wgain_code, gcode0_fx); /* Q13*Q0 -> Q14 */ - *gain_code_fx= L_shl(L_tmp, add(exp_gcode0, 2)); - move32(); /* Q14 -> Q16 */ - push_indice_fx( st_fx, IND_GAIN_CODE, index, nBits ); - } - ELSE /* nBits == 3 */ - { - wgain_code = tbl_gain_code_tc_fx[index]; - move16(); - /**gain_code *= gcode0;*/ - L_tmp = L_mult(wgain_code, gcode0_fx); /* Q13*Q0 -> Q14 */ - *gain_code_fx= L_shl(L_tmp, add(exp_gcode0, 2)); - move32(); /* Q14 -> Q16 */ - push_indice_fx( st_fx, IND_GAIN_CODE, index, nBits ); - } - } - - /*-----------------------------------------------------------------* - * decode normalized codebook gain - *-----------------------------------------------------------------*/ - /**norm_gain_code = *gain_code / *gain_inov;*/ - expg = sub(norm_s(*gain_inov_fx),1); - expg = s_max(expg, 0); - - tmp_fx = div_s(shr(8192,expg),*gain_inov_fx); - *norm_gain_code_fx = L_shr(Mult_32_16(*gain_code_fx, tmp_fx),sub(1,expg)); - move32(); - return; -} -/*-----------------------------------------------------------------* - * Find_Opt_gainQ_fx() - * - * Find the best quantizer - *-----------------------------------------------------------------*/ -static Word16 Find_Opt_gainQ_fx( - Word16 *coeff, - Word16 *exp_coeff, - Word16 *gain_pit, - Word32 *gain_code, - Word16 gcode0, - Word16 exp_gcode0, - const Word16 *cdbk, /* i : Codebook used */ - const Word16 size /* i : size of Codebook used */ -) -{ - Word16 index, i, j; - const Word16 *p; - Word16 g_pitch, g2_pitch, g_code, g_pit_cod, g2_code, g2_code_lo; - Word32 dist_min; - Word16 coeff_lo[5]; - Word16 exp_max[5]; - Word16 exp_code, e_max; - Word32 L_tmp, L_tmp1; - - - /*----------------------------------------------------------------* - * Find the best quantizer - * ~~~~~~~~~~~~~~~~~~~~~~~ - * Before doing the computation we need to align exponents of coeff[] - * to be sure to have the maximum precision. - * - * In the table the pitch gains are in Q14, the code gains are in Q9 and - * are multiply by gcode0 which have been multiply by 2^exp_gcode0. - * Also when we compute g_pitch*g_pitch, g_code*g_code and g_pitch*g_code - * we divide by 2^15. - * Considering all the scaling above we have: - * - * exp_code = exp_gcode0-9+15 = exp_gcode0+6 - * - * g_pitch*g_pitch = -14-14+15 - * g_pitch = -14 - * g_code*g_code = (2*exp_code)+15 - * g_code = exp_code - * g_pitch*g_code = -14 + exp_code +15 - * - * g_pitch*g_pitch * coeff[0] ;exp_max0 = exp_coeff[0] - 13 - * g_pitch * coeff[1] ;exp_max1 = exp_coeff[1] - 14 - * g_code*g_code * coeff[2] ;exp_max2 = exp_coeff[2] +15+(2*exp_code) - * g_code * coeff[3] ;exp_max3 = exp_coeff[3] + exp_code - * g_pitch*g_code * coeff[4] ;exp_max4 = exp_coeff[4] + 1 + exp_code - *----------------------------------------------------------------*/ - - exp_code = add(exp_gcode0, 6); - - exp_max[0] = sub(exp_coeff[0], 13); - move16(); - exp_max[1] = sub(exp_coeff[1], 14); - move16(); - exp_max[2] = add(exp_coeff[2], add(15, shl(exp_code, 1))); - move16(); - exp_max[3] = add(exp_coeff[3], exp_code); - move16(); - exp_max[4] = add(exp_coeff[4], add(1, exp_code)); - move16(); - - /* Find maximum exponant */ - e_max = exp_max[0]; - move16(); - FOR (i = 1; i < 5; i++) - { - e_max = s_max(exp_max[i], e_max); - } - - /* align coeff[] and save in special 32 bit double precision */ - FOR (i = 0; i < 5; i++) - { - j = add(sub(e_max, exp_max[i]), 2); /* /4 to avoid overflow */ - L_tmp = L_deposit_h(coeff[i]); - L_tmp = L_shr(L_tmp, j); - L_Extract(L_tmp, &coeff[i], &coeff_lo[i]); - coeff_lo[i] = shr(coeff_lo[i], 3);/* lo >> 3 */ move16(); - } - - /* searching of codebook */ - p = cdbk; - move16(); - dist_min = L_deposit_h(MAX_16); - index = 0; - move16(); - FOR (i = 0; i < size; i++) - { - g_pitch = *p++; - move16(); - g_code = *p++; - move16(); - - g_code = mult_r(g_code, gcode0); - g2_pitch = mult_r(g_pitch, g_pitch); - g_pit_cod = mult_r(g_code, g_pitch); - L_tmp = L_mult(g_code, g_code); - g2_code_lo = L_Extract_lc(L_tmp, &g2_code); - - L_tmp = L_mult(coeff[2], g2_code_lo); - L_tmp = L_shr(L_tmp, 3); - L_tmp = L_mac(L_tmp, coeff_lo[0], g2_pitch); - L_tmp = L_mac(L_tmp, coeff_lo[1], g_pitch); - L_tmp = L_mac(L_tmp, coeff_lo[2], g2_code); - L_tmp = L_mac(L_tmp, coeff_lo[3], g_code); - L_tmp = L_mac(L_tmp, coeff_lo[4], g_pit_cod); - L_tmp = L_shr(L_tmp, 12); - L_tmp = L_mac(L_tmp, coeff[0], g2_pitch); - L_tmp = L_mac(L_tmp, coeff[1], g_pitch); - L_tmp = L_mac(L_tmp, coeff[2], g2_code); - L_tmp = L_mac(L_tmp, coeff[3], g_code); - L_tmp = L_mac(L_tmp, coeff[4], g_pit_cod); - - L_tmp1 = L_sub(L_tmp, dist_min); - if (L_tmp1 < 0) - { - index = i; - move16(); - } - dist_min = L_min(L_tmp, dist_min); - } - - p = &cdbk[add(index, index)]; - move16(); - - *gain_pit = *p++; /* selected pitch gain in Q14 */ move16(); - g_code = *p++; /* selected code gain in Q9 */ move16(); - - L_tmp = L_mult(g_code, gcode0); /* Q9*Q0 -> Q10 */ - L_tmp = L_shl(L_tmp, add(exp_gcode0, 6)); /* Q10 -> Q16 */ - - *gain_code = L_tmp; /* gain of code in Q16 */ move16(); - return index; -} -/*---------------------------------------------------------------------* - * gain_enc_lbr() - * - * Quantization of pitch and codebook gains without prediction (memory-less) - * in ACELP at 6.6 and 7.5 kbps - * - the gain codebooks and gain estimation constants are different in each subframe - * - the estimated gain, gcode0, is first determined based on - * classification and/or previous quantized gains (from previous subframes in the current frame) - * - a correction factor gamma = g_code / gcode0 is then vector quantized - * along with gain_pit - * - the mean-squared error criterion is used for codebook search - *---------------------------------------------------------------------*/ - -void gain_enc_lbr_fx( - Encoder_State_fx *st_fx, /* i/o: encoder state structure */ - const Word32 core_brate, /* i : core bitrate */ - const Word16 coder_type, /* i : coding type */ - const Word16 i_subfr, /* i : subframe index */ - const Word16 *xn, /* i : target vector Q_xn*/ - const Word16 *y1, /* i : zero-memory filtered adaptive excitation Q_xn*/ - const Word16 Q_xn, /* i : xn and y1 format */ - const Word16 *y2, /* i : zero-memory filtered algebraic codebook excitation Q9*/ - const Word16 *code, /* i : algebraic excitation Q9*/ - Word16 *gain_pit, /* o : quantized pitch gain Q14*/ - Word32 *gain_code, /* o : quantized codebook gain Q16*/ - Word16 *gain_inov, /* o : gain of the innovation (used for normalization) Q12*/ - Word32 *norm_gain_code, /* o : norm. gain of the codebook excitation Q16*/ - Word16 *g_corr, /* i/o: correlations , -2,, -2 and 2 mant/exp*/ - Word32 gc_mem[], /* i/o: gain_code from previous subframes */ - Word16 gp_mem[], /* i/o: gain_pitch from previous subframes */ - const Word16 clip_gain /* i : gain pitch clipping flag (1 = clipping) */ -) -{ - - Word16 index = 0, size, nBits, n_pred, ctype; - const Word16 *b, *cdbk = 0; - Word16 gcode0, aux[10]; - Word16 coeff[5], exp_coeff[5]; - Word16 exp, exp_code, exp_inov, exp_gcode0, frac, tmp; - Word32 L_tmp, L_tmp1, L_inov; - - /*-----------------------------------------------------------------* - * calculate the rest of the correlation coefficients - * c2 = , c3 = -2, c4 = 2, c5* = - * c5* - not necessary to calculate - *-----------------------------------------------------------------*/ - - coeff[0] = g_corr[0]; - move16(); - exp_coeff[0] = g_corr[1]; - move16(); - coeff[1] = negate(g_corr[2]); - move16(); /* coeff[1] = -2 xn yy1 */ - exp_coeff[1] = add(g_corr[3], 1); - move16(); - - /* Compute scalar product */ - - coeff[2] = extract_h(Dot_product12(y2, y2, L_SUBFR, &exp)); - exp_coeff[2] = add(sub(exp, 18), shl(Q_xn, 1)); /* -18 (y2 Q9) */ move16(); - - /* Compute scalar product -2* */ - - coeff[3] = extract_h(L_negate(Dot_product12(xn, y2, L_SUBFR, &exp))); - exp_coeff[3] = add(sub(exp, 9 - 1), Q_xn); /* -9 (y2 Q9), +1 (2 xn y2) */ move16(); - - /* Compute scalar product 2* */ - - coeff[4] = extract_h(Dot_product12(y1, y2, L_SUBFR, &exp)); - exp_coeff[4] = add(sub(exp, 9 - 1), Q_xn); /* -9 (y2 Q9), +1 (2 yy1 y2) */ move16(); - - /*g_corr[2] += 0.01F; g_corr[3] -= 0.02F; g_corr[4] += 0.02F;*/ - - /*Ecode = ( dotp( code, code, L_SUBFR ) + 0.01f ) / L_SUBFR; - *gain_inov = 1.0f / (float)sqrt(Ecode);*/ - L_tmp = Dot_product12(code, code, L_SUBFR, &exp_code); - L_inov = L_add(0,L_tmp); /* sets to 'L_tmp' in 1 clock */ - /* exp_code: -18 (code in Q9), -6 (/L_SUBFR), -31 (L_tmp Q31->Q0) */ - /* output gain_inov*/ - exp_inov = sub(exp_code, 18 + 6); - L_inov = Isqrt_lc(L_inov, &exp_inov); - *gain_inov = extract_h(L_shl(L_inov, sub(exp_inov, 3))); /* gain_inov in Q12 */ - - - /*-----------------------------------------------------------------* - * select the codebook, size and number of bits - * set the gains searching range - *-----------------------------------------------------------------*/ - - nBits = gain_bits_tbl[BIT_ALLOC_IDX_fx(core_brate, coder_type, i_subfr, 0)]; - move16(); - size = extract_l(pow2[nBits]); - - ctype = shl(sub(coder_type, 1), 1); - - /*-----------------------------------------------------------------* - * calculate prediction of gcode - * search for the best codeword - *-----------------------------------------------------------------*/ - IF (i_subfr == 0) - { - b = b_1sfr_fx; - move16(); - n_pred = 2; - move16(); - - SWITCH ( nBits ) - { - case 8: - { - cdbk = gp_gamma_1sfr_8b_fx; - move16(); - if ( sub(clip_gain,1) == 0 ) size = sub(size,60); - move16(); - BREAK; - } - case 7: - { - cdbk = gp_gamma_1sfr_7b_fx; - move16(); - if ( sub(clip_gain,1) == 0 ) size = sub(size,27); - move16(); - BREAK; - } - case 6: - { - cdbk = gp_gamma_1sfr_6b_fx; - move16(); - if ( sub(clip_gain,1) == 0 ) size = sub(size,10); - move16(); - BREAK; - } - } - - /* calculate predicted gain */ - aux[0] = 4096; - move16(); - aux[1] = shl(ctype,12); - - /* gcode0 = (float)pow(10, dotp(b, aux, n_pred) - 0.5f * (float)log10(Ecode)); - gcode0 = (float)pow(10, dotp(b, aux, n_pred) - 0.05f * 10 * (float)log10(Ecode)); - gcode0 = (float)pow(10, 0.05(20 * dotp(b, aux, n_pred) - 10 * (float)log10(Ecode))); */ - - exp_code = sub(exp_code, 18 + 6 + 1); - exp = norm_l(L_tmp); - frac = Log2_norm_lc(L_shl(L_tmp, exp)); - exp = sub(exp_code,exp); - L_tmp1 = Mpy_32_16(exp, frac, 24660); /* Q14 */ /* 10*log10(2) in Q13*/ - - L_tmp = Dot_product(b, aux, n_pred); /*Q25*/ - L_tmp = Mult_32_16(L_tmp,320);/*Q14, 20 in Q4*/ - L_tmp = L_sub(L_tmp,L_tmp1);/*Q14*/ - - gcode0 = round_fx(L_shl(L_tmp, 10)); /* Q8 */ - - /*-----------------------------------------------------------------* - * gcode0 = pow(10.0, gcode0/20) - * = pow(2, 3.321928*gcode0/20) - * = pow(2, 0.166096*gcode0) - *-----------------------------------------------------------------*/ - - L_tmp = L_mult(gcode0, 21771); /* *0.166096 in Q17 -> Q26 */ - L_tmp = L_shr(L_tmp, 10); /* From Q26 to Q16 */ - frac = L_Extract_lc(L_tmp, &exp_gcode0); /* Extract exponent of gcode0 */ - - gcode0 = extract_l(Pow2(14, frac));/* Put 14 as exponent so that */ - /* output of Pow2() will be: */ - /* 16384 < Pow2() <= 32767 */ - exp_gcode0 = sub(exp_gcode0, 14); - index= Find_Opt_gainQ_fx(coeff, exp_coeff, gain_pit, gain_code, gcode0, exp_gcode0, cdbk, size); - - gc_mem[0] = *gain_code; - move16(); /*Q16*/ - gp_mem[0] = *gain_pit; - move16();/*Q14*/ - } - ELSE IF (sub(i_subfr,L_SUBFR) == 0) - { - b = b_2sfr_fx; - move16(); - n_pred = 4; - move16(); - - switch ( nBits ) - { - case 7: - { - cdbk = gp_gamma_2sfr_7b_fx; - move16(); - if ( sub(clip_gain,1) == 0 ) size = sub(size,30); - move16(); - BREAK; - } - case 6: - { - cdbk = gp_gamma_2sfr_6b_fx; - move16(); - if ( sub(clip_gain,1) == 0 ) size = sub(size,12); - move16(); - BREAK; - } - } - - /* calculate predicted gain */ - aux[0] = 4096; - move16(); - aux[1] = shl(ctype,12); - move16(); - - /*aux[2] = (float)log10(gc_mem[0]); - = log2(gc_mem[0])*log10(2);*/ - exp = norm_l(gc_mem[0]); - frac = Log2_norm_lc(L_shl(gc_mem[0], exp)); - exp = sub(sub(30,exp),16); /*Q_format(gc_1sfr_fx)=16*/ - L_tmp1 = Mpy_32_16(exp, frac, 9864); - move16(); /* Q16 */ - aux[2] = round_fx(L_shl(L_tmp1, 12)); /* Q12 */ - - aux[3] = shr(gp_mem[0],2); - move16();/*Q12*/ - - /*-----------------------------------------------------------------* - * gcode0 = pow(10.0, dotp(b, aux, n_pred) - * = pow(2, 3.321928*dotp(b, aux, n_pred) - *-----------------------------------------------------------------*/ - L_tmp = Dot_product(b, aux, n_pred); /*Q25*/ - L_tmp = Mult_32_16(L_tmp, 27213); /* *3.321928 in Q13 -> Q23 */ - L_tmp = L_shr(L_tmp, 7); /* From Q23 to Q16 */ - frac = L_Extract_lc(L_tmp, &exp_gcode0); /* Extract exponent of gcode0 */ - - gcode0 = extract_l(Pow2(14, frac));/* Put 14 as exponent so that */ - /* output of Pow2() will be: */ - /* 16384 < Pow2() <= 32767 */ - exp_gcode0 = sub(exp_gcode0, 14); - - index= Find_Opt_gainQ_fx(coeff, exp_coeff, gain_pit, gain_code, gcode0, exp_gcode0, cdbk, size); - gc_mem[1] = *gain_code; - move32(); - gp_mem[1] = *gain_pit; - move16(); - } - ELSE IF (sub(i_subfr,2*L_SUBFR) == 0) - { - b = b_3sfr_fx; - move16(); - n_pred = 6; - move16(); - cdbk = gp_gamma_3sfr_6b_fx; - move16(); - if ( sub(clip_gain,1) == 0 ) - { - size = sub(size,11); - } - - /* calculate predicted gain */ - aux[0] = 4096; - move16(); - aux[1] = shl(ctype,12); - move16(); - - /*aux[2] = (float)log10(gc_mem[0]); - = log2(gc_mem[0])*log10(2);*/ - exp = norm_l(gc_mem[0]); - frac = Log2_norm_lc(L_shl(gc_mem[0], exp)); - exp = sub(sub(30,exp),16); /*Q_format(gc_mem[0])=16*/ - L_tmp1 = Mpy_32_16(exp, frac, 9864); /* Q16 */ - aux[2] = round_fx(L_shl(L_tmp1, 12)); /* Q12 */ - - /*aux[3] = (float)log10(gc_mem[1]); - = log2(gc_mem[1])*log10(2);*/ - exp = norm_l(gc_mem[1]); - frac = Log2_norm_lc(L_shl(gc_mem[1], exp)); - exp = sub(sub(30,exp),16); /*Q_format(gc_mem[1])=16*/ - L_tmp1 = Mpy_32_16(exp, frac, 9864); /* Q16 */ - aux[3] = round_fx(L_shl(L_tmp1, 12)); /* Q12 */ - - aux[4] = shr(gp_mem[0],2); - move16();/*Q12*/ - aux[5] = shr(gp_mem[1],2); - move16();/*Q12*/ - - /*-----------------------------------------------------------------* - * gcode0 = pow(10.0, dotp(b, aux, n_pred) - * = pow(2, 3.321928*dotp(b, aux, n_pred) - *-----------------------------------------------------------------*/ - L_tmp = Dot_product(b, aux, n_pred); /*Q25*/ - L_tmp = Mult_32_16(L_tmp, 27213); /* *3.321928 in Q13 -> Q23 */ - L_tmp = L_shr(L_tmp, 7); /* From Q23 to Q16 */ - frac = L_Extract_lc(L_tmp, &exp_gcode0); /* Extract exponent of gcode0 */ - - gcode0 = extract_l(Pow2(14, frac));/* Put 14 as exponent so that */ - /* output of Pow2() will be: */ - /* 16384 < Pow2() <= 32767 */ - exp_gcode0 = sub(exp_gcode0, 14); - - /*----------------------------------------------------------------* - * Find the best quantizer - * ~~~~~~~~~~~~~~~~~~~~~~~ - * Before doing the computation we need to align exponents of coeff[] - * to be sure to have the maximum precision. - * - * In the table the pitch gains are in Q14, the code gains are in Q9 and - * are multiply by gcode0 which have been multiply by 2^exp_gcode0. - * Also when we compute g_pitch*g_pitch, g_code*g_code and g_pitch*g_code - * we divide by 2^15. - * Considering all the scaling above we have: - * - * exp_code = exp_gcode0-9+15 = exp_gcode0+6 - * - * g_pitch*g_pitch = -14-14+15 - * g_pitch = -14 - * g_code*g_code = (2*exp_code)+15 - * g_code = exp_code - * g_pitch*g_code = -14 + exp_code +15 - * - * g_pitch*g_pitch * coeff[0] ;exp_max0 = exp_coeff[0] - 13 - * g_pitch * coeff[1] ;exp_max1 = exp_coeff[1] - 14 - * g_code*g_code * coeff[2] ;exp_max2 = exp_coeff[2] +15+(2*exp_code) - * g_code * coeff[3] ;exp_max3 = exp_coeff[3] + exp_code - * g_pitch*g_code * coeff[4] ;exp_max4 = exp_coeff[4] + 1 + exp_code - *----------------------------------------------------------------*/ - - index= Find_Opt_gainQ_fx(coeff, exp_coeff, gain_pit, gain_code, gcode0, exp_gcode0, cdbk, size); - - gc_mem[2] = *gain_code; - move32(); - gp_mem[2] = *gain_pit; - move16(); - } - ELSE IF (sub(i_subfr,3*L_SUBFR) == 0) - { - b = b_4sfr_fx; - move16(); - n_pred = 8; - move16(); - - cdbk = gp_gamma_4sfr_6b_fx; - move16(); - if ( sub(clip_gain,1) == 0 ) - { - size = sub(size,11); - move16(); - } - - /* calculate predicted gain */ - aux[0] = 4096; - move16(); - aux[1] = shl(ctype,12); - move16(); - - /*aux[2] = (float)log10(gc_mem[0]); - = log2(gc_mem[0])*log10(2);*/ - exp = norm_l(gc_mem[0]); - frac = Log2_norm_lc(L_shl(gc_mem[0], exp)); - exp = sub(sub(30,exp),16); /*Q_format(gc_mem[0])=16*/ - L_tmp1 = Mpy_32_16(exp, frac, 9864); /* Q16 */ - aux[2] = round_fx(L_shl(L_tmp1, 12)); /* Q12 */ - - /*aux[3] = (float)log10(gc_mem[1]); - = log2(gc_mem[1])*log10(2);*/ - exp = norm_l(gc_mem[1]); - frac = Log2_norm_lc(L_shl(gc_mem[1], exp)); - exp = sub(sub(30,exp),16); /*Q_format(gc_mem[1])=16*/ - L_tmp1 = Mpy_32_16(exp, frac, 9864); /* Q16 */ - aux[3] = round_fx(L_shl(L_tmp1, 12)); /* Q12 */ - - - /*aux[4] = (float)log10(gc_mem[2]); - = log2(gc_mem[2])*log10(2);*/ - exp = norm_l(gc_mem[2]); - frac = Log2_norm_lc(L_shl(gc_mem[2], exp)); - exp = sub(sub(30,exp),16); /*Q_format(gc_mem[2])=16*/ - L_tmp1 = Mpy_32_16(exp, frac, 9864); /* Q16 */ - aux[4] = round_fx(L_shl(L_tmp1, 12)); /* Q12 */ - - aux[5] = shr(gp_mem[0],2); - move16();/*Q12*/ - aux[6] = shr(gp_mem[1],2); - move16();/*Q12*/ - aux[7] = shr(gp_mem[2],2); - move16();/*Q12*/ - /*-----------------------------------------------------------------* - * gcode0 = pow(10.0, dotp(b, aux, n_pred) - * = pow(2, 3.321928*dotp(b, aux, n_pred) - *-----------------------------------------------------------------*/ - L_tmp = Dot_product(b, aux, n_pred); /*Q25*/ - L_tmp = Mult_32_16(L_tmp, 27213); /* *3.321928 in Q13 -> Q23 */ - L_tmp = L_shr(L_tmp, 7); /* From Q23 to Q16 */ - frac = L_Extract_lc(L_tmp, &exp_gcode0); /* Extract exponent of gcode0 */ - - gcode0 = extract_l(Pow2(14, frac));/* Put 14 as exponent so that */ - /* output of Pow2() will be: */ - /* 16384 < Pow2() <= 32767 */ - exp_gcode0 = sub(exp_gcode0, 14); - - index = Find_Opt_gainQ_fx(coeff, exp_coeff, gain_pit, gain_code, gcode0, exp_gcode0, cdbk, size); - } - - /* *norm_gain_code = *gain_code / *gain_inov; */ - exp = sub(norm_s(*gain_inov),1); - exp = s_max(exp, 0); - - tmp = div_s(shr(8192,exp),*gain_inov); - *norm_gain_code = L_shr(Mult_32_16(*gain_code, tmp),sub(1,exp)); - move32(); - { - push_indice_fx( st_fx, IND_GAIN, index, nBits ); - } - return; -} - -/*-------------------------------------------------------------------* - * gain_enc_amr_wb() - * - * Quantization of pitch and codebook gains (used also in AMR-WB IO mode) - * MA prediction is performed on the innovation energy (in dB with mean removed). - * An initial predicted gain, gcode0, is first determined and the correction - * factor alpha = g_code / gcode0 is quantized. - * The pitch gain and the correction factor are vector quantized and the - * mean-squared weighted error criterion is used in the quantizer search. - *-------------------------------------------------------------------*/ - - -void gain_enc_amr_wb_fx( - Encoder_State_fx *st, /* i/o: encoder state structure */ - const Word16 *xn, /* i : target vector */ - const Word16 Q_xn, /* i : xn and yy1 format Q0 */ - const Word16 *yy1, /* i : zero-memory filtered adaptive excitation */ - const Word16 *y2, /* i : zero-memory filtered algebraic codebook excitation */ - const Word16 *code, /* i : algebraic excitation */ - const Word32 core_brate, /* i : core bitrate */ - Word16 *gain_pit, /* i/o: pitch gain / Quantized pitch gain */ - Word32 *gain_code, /* o : quantized codebook gain */ - Word16 *gain_inov, /* o : gain of the innovation (used for normalization) */ - Word32 *norm_gain_code, /* o : norm. gain of the codebook excitation */ - Word16 *g_coeff, /* i/o: correlations , -2,, -2 and 2 */ - const Word16 clip_gain, /* i : gain pitch clipping flag (1 = clipping) */ - Word16 *past_qua_en /* i/o: gain quantization memory (4 words) */ -) -{ - - Word16 i, j, index, min_ind, size; - Word16 exp, frac, gcode0, exp_gcode0, e_max, exp_code, exp_inov, qua_ener; - Word16 g_pitch, g2_pitch, g_code, g_pit_cod, g2_code, g2_code_lo; - Word16 coeff[5], coeff_lo[5], exp_coeff[5]; - Word16 exp_max[5], tmp, nBits; - Word32 L_tmp, dist_min, L_inov, L_tmp1; - const Word16 *t_qua_gain, *p; - - /*----------------------------------------------------------------* - * Find the initial quantization pitch index - * Set gains search range - *----------------------------------------------------------------*/ - IF (core_brate>= ACELP_12k65) - { - t_qua_gain = t_qua_gain7b_fx; - move16(); - /* pt at 1/4th of table */ - p = t_qua_gain7b_fx + RANGE; - move16(); - - j = NB_QUA_GAIN7B - RANGE; - move16(); - - IF (sub(clip_gain, 1) == 0) - { - j = sub(j, 27); /* limit gain pitch to 1.0 */ - } - min_ind = 0; - move16(); - g_pitch = *gain_pit; - move16(); - - FOR (i = 0; i < j; i++) - { - if (sub(g_pitch, *p) > 0) - { - min_ind = add(min_ind, 1); - } - p += 2; - } - size = RANGE; - move16(); - nBits = 7; - } - ELSE - { - t_qua_gain = t_qua_gain6b_fx; - min_ind = 0; - move16(); - size = RANGE; - move16(); - if (sub(clip_gain, 1) == 0) - { - size = sub(size, 16); /* limit gain pitch to 1.0 */ - } - nBits = 6; - } - /*----------------------------------------------------------------* - * Compute coefficients needed for the quantization. - * - * coeff[0] = yy1 yy1 - * coeff[1] = -2 xn yy1 - * coeff[2] = y2 y2 - * coeff[3] = -2 xn y2 - * coeff[4] = 2 yy1 y2 - * - * Product and have been computed in Adpt_enr() and - * are in vector g_coeff[]. - *----------------------------------------------------------------*/ - coeff[0] = g_coeff[0]; - move16(); - exp_coeff[0] = g_coeff[1]; - move16(); - coeff[1] = negate(g_coeff[2]); - move16(); /* coeff[1] = -2 xn yy1 */ - exp_coeff[1] = add(g_coeff[3], 1); - move16(); - - /* Compute scalar product */ - coeff[2] = extract_h(Dot_product12(y2, y2, L_SUBFR, &exp)); - exp_coeff[2] = add(sub(exp, 18), shl(Q_xn, 1)); /* -18 (y2 Q9) */ - - /* Compute scalar product -2* */ - coeff[3] = extract_h(L_negate(Dot_product12(xn, y2, L_SUBFR, &exp))); - exp_coeff[3] = add(sub(exp, 9 - 1), Q_xn); /* -9 (y2 Q9), +1 (2 xn y2) */ - - /* Compute scalar product 2* */ - coeff[4] = extract_h(Dot_product12(yy1, y2, L_SUBFR, &exp)); - exp_coeff[4] = add(sub(exp, 9 - 1), Q_xn); /* -9 (y2 Q9), +1 (2 yy1 y2) */ - - /*----------------------------------------------------------------* - * Find energy of code and compute: - * - * L_tmp = MEAN_ENER - 10log10(energy of code/ L_subfr) - * = MEAN_ENER - 3.0103*log2(energy of code/ L_subfr) - *----------------------------------------------------------------*/ - L_tmp = Dot_product12(code, code, L_SUBFR, &exp_code); - L_inov = L_add(L_tmp, 0); - /* exp_code: -18 (code in Q9), -6 (/L_subfr), -31 (L_tmp Q31->Q0) */ - /* output gain_inov*/ - exp_inov = sub(exp_code, 18 + 6); - L_inov = Isqrt_lc(L_inov, &exp_inov); - *gain_inov = extract_h(L_shl(L_inov, sub(exp_inov, 3))); /* gain_inov in Q12 */ - - exp_code = sub(exp_code, 18 + 6 + 31); - frac = Log2_lc(L_tmp, &exp); - exp = add(exp, exp_code); - L_tmp = Mpy_32_16(exp, frac, -24660); /* x -3.0103(Q13) -> Q14 */ - - L_tmp = L_mac(L_tmp, MEAN_ENER, 8192); /* + MEAN_ENER in Q14 */ - - /*----------------------------------------------------------------* - * predicted codebook gain - *----------------------------------------------------------------*/ - L_tmp = L_shl(L_tmp, 10); /* From Q14 to Q24 */ - L_tmp = L_mac0(L_tmp, pred_gain_fx[0], past_qua_en[0]); /* Q14*Q10 -> Q24 */ - L_tmp = L_mac0(L_tmp, pred_gain_fx[1], past_qua_en[1]); /* Q14*Q10 -> Q24 */ - L_tmp = L_mac0(L_tmp, pred_gain_fx[2], past_qua_en[2]); /* Q14*Q10 -> Q24 */ - L_tmp = L_mac0(L_tmp, pred_gain_fx[3], past_qua_en[3]); /* Q14*Q10 -> Q24 */ - - gcode0 = extract_h(L_tmp); /* From Q24 to Q8 */ - - /*----------------------------------------------------------------* - * gcode0 = pow(10.0, gcode0/20) - * = pow(2, 3.321928*gcode0/20) - * = pow(2, 0.166096*gcode0) - *----------------------------------------------------------------*/ - L_tmp = L_mult(gcode0, 5443); /* *0.166096 in Q15 -> Q24 */ - L_tmp = L_shr(L_tmp, 8); /* From Q24 to Q16 */ - L_Extract(L_tmp, &exp_gcode0, &frac); /* Extract exponent of gcode0 */ - - gcode0 = extract_l(Pow2(14, frac)); /* Put 14 as exponent so that */ - /* output of Pow2() will be: */ - /* 16384 < Pow2() <= 32767 */ - exp_gcode0 = sub(exp_gcode0, 14); - - /*----------------------------------------------------------------* - * Find the best quantizer - * ~~~~~~~~~~~~~~~~~~~~~~~ - * Before doing the computation we need to aling exponents of coeff[] - * to be sure to have the maximum precision. - * - * In the table the pitch gains are in Q14, the code gains are in Q11 and - * are multiply by gcode0 which have been multiply by 2^exp_gcode0. - * Also when we compute g_pitch*g_pitch, g_code*g_code and g_pitch*g_code - * we divide by 2^15. - * Considering all the scaling above we have: - * - * exp_code = exp_gcode0-11+15 = exp_gcode0+4 - * - * g_pitch*g_pitch = -14-14+15 - * g_pitch = -14 - * g_code*g_code = (2*exp_code)+15 - * g_code = exp_code - * g_pitch*g_code = -14 + exp_code +15 - * - * g_pitch*g_pitch * coeff[0] ;exp_max0 = exp_coeff[0] - 13 - * g_pitch * coeff[1] ;exp_max1 = exp_coeff[1] - 14 - * g_code*g_code * coeff[2] ;exp_max2 = exp_coeff[2] +15+(2*exp_code) - * g_code * coeff[3] ;exp_max3 = exp_coeff[3] + exp_code - * g_pitch*g_code * coeff[4] ;exp_max4 = exp_coeff[4] + 1 + exp_code - *----------------------------------------------------------------*/ - - exp_code = add(exp_gcode0, 4); - - exp_max[0] = sub(exp_coeff[0], 13); - move16(); - exp_max[1] = sub(exp_coeff[1], 14); - move16(); - exp_max[2] = add(exp_coeff[2], - add(15, shl(exp_code, 1))); - move16(); - exp_max[3] = add(exp_coeff[3], exp_code); - move16(); - exp_max[4] = add(exp_coeff[4], - add(1, exp_code)); - move16(); - - /* Find maximum exponant */ - e_max = exp_max[0]; - move16(); - FOR (i = 1; i < 5; i++) - { - e_max = s_max(exp_max[i], e_max); - } - - /* align coeff[] and save in special 32 bit double precision */ - FOR (i = 0; i < 5; i++) - { - j = add(sub(e_max, exp_max[i]), 2); /* /4 to avoid overflow */ - L_tmp = L_deposit_h(coeff[i]); - L_tmp = L_shr(L_tmp, j); - L_Extract(L_tmp, &coeff[i], &coeff_lo[i]); - coeff_lo[i] = shr(coeff_lo[i], 3);/* lo >> 3 */move16(); - } - - /* Codebook search */ - dist_min = L_add(MAX_32, 0); - p = &t_qua_gain[shl(min_ind, 1)]; - move16(); - - index = 0; - move16(); - FOR (i = 0; i < size; i++) - { - g_pitch = *p++; - move16(); - g_code = *p++; - move16(); - - g_code = mult_r(g_code, gcode0); - g2_pitch = mult_r(g_pitch, g_pitch); - g_pit_cod = mult_r(g_code, g_pitch); - L_tmp = L_mult(g_code, g_code); - L_Extract(L_tmp, &g2_code, &g2_code_lo); - - L_tmp = L_mult(coeff[2], g2_code_lo); - L_tmp = L_shr(L_tmp, 3); - L_tmp = L_mac(L_tmp, coeff_lo[0], g2_pitch); - L_tmp = L_mac(L_tmp, coeff_lo[1], g_pitch); - L_tmp = L_mac(L_tmp, coeff_lo[2], g2_code); - L_tmp = L_mac(L_tmp, coeff_lo[3], g_code); - L_tmp = L_mac(L_tmp, coeff_lo[4], g_pit_cod); - L_tmp = L_shr(L_tmp, 12); - L_tmp = L_mac(L_tmp, coeff[0], g2_pitch); - L_tmp = L_mac(L_tmp, coeff[1], g_pitch); - L_tmp = L_mac(L_tmp, coeff[2], g2_code); - L_tmp = L_mac(L_tmp, coeff[3], g_code); - L_tmp = L_mac(L_tmp, coeff[4], g_pit_cod); - - L_tmp1 = L_sub(L_tmp, dist_min); - /* splitting the if cost half the complexity of using IF macro */ - if (L_tmp1 < 0) - { - dist_min = L_add(L_tmp, 0); - } - if (L_tmp1 < 0) - { - index = i; - move16(); - } - - } - /* Read the quantized gains */ - index = add(index, min_ind); - - p = &t_qua_gain[add(index, index)]; - move16(); - *gain_pit = *p++; /* selected pitch gain in Q14 */ move16(); - g_code = *p++; /* selected code gain in Q11 */ move16(); - - L_tmp = L_mult(g_code, gcode0); /* Q11*Q0 -> Q12 */ - L_tmp = L_shl(L_tmp, add(exp_gcode0, 4)); /* Q12 -> Q16 */ - - *gain_code = L_tmp; /* gain of code in Q16 */ move16(); - - /*---------------------------------------------------* - * qua_ener = 20*log10(g_code) - * = 6.0206*log2(g_code) - * = 6.0206*(log2(g_codeQ11) - 11) - *---------------------------------------------------*/ - L_tmp = L_deposit_l(g_code); - frac = Log2_lc(L_tmp, &exp); - exp = sub(exp, 11); - L_tmp = Mpy_32_16(exp, frac, 24660); /* x 6.0206 in Q12 */ - - qua_ener = extract_l(L_shr(L_tmp, 3)); /* result in Q10 */ - - /*----------------------------------------------------------------* - * update table of past quantized energies - *----------------------------------------------------------------*/ - - past_qua_en[3] = past_qua_en[2]; - move16(); - past_qua_en[2] = past_qua_en[1]; - move16(); - past_qua_en[1] = past_qua_en[0]; - move16(); - past_qua_en[0] = qua_ener; - move16(); - - - exp = sub(norm_s(*gain_inov),1); - exp = s_max(exp, 0); - - tmp = div_s(shr(8192,exp),*gain_inov); - *norm_gain_code = L_shr(Mult_32_16(*gain_code, tmp),sub(1,exp)); - move32(); - - push_indice_fx( st, IND_GAIN, index, nBits ); - - return; -} diff --git a/src/libs/libevs/lib_enc/gaus_enc.cpp b/src/libs/libevs/lib_enc/gaus_enc.cpp new file mode 100644 index 00000000..528f113c --- /dev/null +++ b/src/libs/libevs/lib_enc/gaus_enc.cpp @@ -0,0 +1,429 @@ +/*==================================================================================== + EVS Codec 3GPP TS26.443 Nov 13, 2018. Version 12.11.0 / 13.7.0 / 14.3.0 / 15.1.0 + ====================================================================================*/ + +#include +#include "options.h" +#include "cnst.h" +#include "rom_com.h" +#include "prot.h" + +/*-------------------------------------------------------------------* + * Local constants + *-------------------------------------------------------------------*/ + +#define NMAX 8 /* Control of the routine's complexity */ +#define FAC_DELTA 16.0f + +/*---------------------------------------------------------------------* + * Prototypes + *---------------------------------------------------------------------*/ + +static short cod_2pos( const short ind1,const short ind2,const float sign1, + const float sign2,const short n ); + +static void gauss2v( Encoder_State *st, const float h[], const float xn[], const float dn[], float code[], + float y1[], float *gain, const short lg, const short nb_bits ); + +/*-------------------------------------------------------------------* + * Gaus_encode + * + * Encoder UnVoiced excitation coding using Gaussian codebooks + * - ACELP quantized Gaussian excitation + * - gain quantization + * - Total excitation for UnVoiced coders + * - Updates + *-------------------------------------------------------------------*/ + +float gaus_encode( + Encoder_State *st, /* i/o: encoder state structure */ + const short i_subfr, /* i : subframe index */ + const float *h1, /* i : weighted filter input response */ + const float *xn, /* i : target vector */ + float *exc, /* o : pointer to excitation signal frame */ + float *mem_w0, /* o : weighting filter denominator memory */ + float *gp_clip_mem, /* o : memory of gain of pitch clipping algorithm */ + float *tilt_code, /* o : synthesis excitation spectrum tilt */ + float *code, /* o : algebraic excitation */ + float *gain_code, /* o : Code gain. */ + float *y2, /* o : zero-memory filtered adaptive excitation */ + float *gain_inov, /* o : innovation gain */ + float *voice_fac, /* o : voicing factor */ + float *gain_pit, /* o : adaptive excitation gain */ + float *norm_gain_code, /* o : normalized innovative cb. gain */ + const long core_brate /* i : core bitrate */ +) +{ + short i = 0, nb_bits, idx; + float dn[L_SUBFR]; /* Correlation between xn and h1 */ + + /*----------------------------------------------------------------* + * Encode gaussian excitation + *----------------------------------------------------------------*/ + + corr_xh( xn, dn, h1, L_SUBFR ); /* Correlation between target xn[] and impulse response h1[] */ + + nb_bits = FCB_bits_tbl[BIT_ALLOC_IDX(core_brate, UNVOICED, i_subfr, TC_SUBFR2IDX(-1))]; + + gauss2v( st, h1, xn, dn, code, y2, gain_code, L_SUBFR, nb_bits>>1 ); + + /*----------------------------------------------------------------* + * Encode gaussian gain + *----------------------------------------------------------------*/ + + /* codeword energy computation */ + *gain_inov = 1.0f / (float)sqrt( ( dotp( code, code, L_SUBFR ) + 0.01f ) / L_SUBFR ); + + nb_bits = gain_bits_tbl[BIT_ALLOC_IDX(core_brate, UNVOICED, i_subfr, TC_SUBFR2IDX(-1))]; + + idx = gain_enc_gaus( gain_code, nb_bits, -30.0f, 190.0f ); + push_indice( st, IND_GAIN, idx, nb_bits ); + + /*-----------------------------------------------------------------* + * Total excitation for Unvoiced coders + *-----------------------------------------------------------------*/ + + for (i = 0; i < L_SUBFR; i++) + { + exc[i+i_subfr] = *gain_code * code[i]; + } + + /*-----------------------------------------------------------------* + * Updates: last value of new target is stored in mem_w0 + *-----------------------------------------------------------------*/ + + *mem_w0 = xn[L_SUBFR-1] - *gain_code * y2[L_SUBFR-1]; + + init_gp_clip(gp_clip_mem); /* reset pitch clipping parameters */ + *gain_pit = 0.0f; + *tilt_code = 0.0f; /* purely unvoiced */ + *voice_fac = -1.0f; /* purely unvoiced */ + + *norm_gain_code = *gain_code / *gain_inov; + + return L_SUBFR; +} + +/*-------------------------------------------------------------------* + * gauss2v() + * + * encoder of Gaussian Codebook for unvoiced + * consisting of addition of 2 Gaussian vectors + * + * One Gaussian vector of 192 values vectors delayed by 2 + *-------------------------------------------------------------------*/ + +static void gauss2v( + Encoder_State *st, /* i/o: encoder state structure */ + const float h[], /* i : weighted LP filter impulse response */ + const float xn[], /* i : target signal */ + const float dn[], /* i : backward filtered target */ + float code[], /* o : gaussian excitation */ + float y11[], /* o : zero-memory filtered gauss. excitation */ + float *gain, /* o : excitation gain */ + const short lg, /* i : subframe size */ + const short nb_bits /* i : nb ob bits per track (max 6) */ +) +{ + short i, j, ind1, ind2, idx; + short nvec, step; + float cor, cora, cor2, cor2w, eneri, enerw; + float *pt1, *pt2; + float max[NMAX+1], *pos[NMAX+1], sign[NMAX+1]; + float ener[NMAX+1], corr[NMAX+1], ener1; + float dico2[L_SUBFR*NMAX]; + float c1, c0; + float gxx, gcc; + float gaus_dico2[190]; + float hg[190]; + float delta; + short index_delta; + + + /*-----------------------------------------------------------------* + * Encode the tilt of gaussian excitation + *-----------------------------------------------------------------*/ + + c0=0.0f; /* Compute spectral tilt of target */ + c1=0.0f; + for (i=1; i 7) + { + index_delta = 7; + } + + delta = STEP_DELTA * (float)index_delta; + if( delta > 0.0f ) /* Adapt spectral tilt of initial codebook */ + { + gaus_dico2[0] = gaus_dico[0]; + for (i=1; i<190; i++) + { + gaus_dico2[i] = (gaus_dico[i] - delta*gaus_dico[i-1])/(1+delta*delta); + } + } + else + { + for (i=0; i<190; i++) + { + gaus_dico2[i] = gaus_dico[i]; + } + } + + /*-----------------------------------------------------------------* + * Codebook search initializations + *-----------------------------------------------------------------*/ + + ind1 = 0; + ind2 = 0; + + nvec = 1 << nb_bits; + step = 0x80 >> nb_bits; + + /*-----------------------------------------------------------------* + * dot product between dn and gaussian codevectors, + * keep NMAX best vectors + *-----------------------------------------------------------------*/ + + set_f(max, 0, NMAX+1); + set_f(sign, 0, NMAX+1); + + for (i = 0; i < NMAX+1; i++) + { + pos[i] = (float *)gaus_dico2; + } + + pt1 = (float *)gaus_dico2; + + for (i=0; i < nvec; i++, pt1+=step) + { + cor = dotp(pt1, dn, lg); + cora = (float)fabs(cor); + j = NMAX-1; + do + { + if(cora >= max[j]) + { + max[j+1] = max[j]; + pos[j+1] = pos[j]; + sign[j+1] = sign[j]; + max[j] = cora; + pos[j] = pt1; + sign[j] = cor; + } + + j--; + } + while (j >= 0); + } + + /*-----------------------------------------------------------------* + * filter selected vectors + * put sign + * compute energy + *-----------------------------------------------------------------*/ + + pt1 = dico2; + for (i=0; i cor2w * eneri) + { + cor2w = cor2; + enerw = eneri; + ind1 = i; + ind2 = j; + } + } + } + + /*-----------------------------------------------------------------* + * Compute zero-memory filtered gauss. excitation y + *-----------------------------------------------------------------*/ + + pt1 = dico2 + ind1*L_SUBFR; + pt2 = dico2 + ind2*L_SUBFR; + for(i=0; i= 0.0f) + { + sign[ind1] = 1.0f; + } + else + { + sign[ind1] = -1.0f; + } + + if(sign[ind2] >= 0.0f) + { + sign[ind2] = 1.0f; + } + else + { + sign[ind2] = -1.0f; + } + + /*-----------------------------------------------------------------* + * Compute code + *-----------------------------------------------------------------*/ + + pt1 = pos[ind1]; + pt2 = pos[ind2]; + for(i=0; i 0.0f) + { + s1=0; + } + + s2=1; + if(sign2 > 0.0f) + { + s2=0; + } + + if(s1 == s2) + { + if (ind1<=ind2) + { + i1 = ind1; + i2 = ind2; + } + else + { + i1 = ind2; + i2 = ind1; + } + } + else + { + if (ind1>ind2) + { + i1 = ind1; + i2 = ind2; + } + else + { + i1 = ind2; + i2 = ind1; + s1 = s2; + } + } + index = i1*n + i2; + index = (index<<1) + s1; + + return index; +} diff --git a/src/libs/libevs/lib_enc/gaus_enc_fx.cpp b/src/libs/libevs/lib_enc/gaus_enc_fx.cpp deleted file mode 100755 index d2e2e68e..00000000 --- a/src/libs/libevs/lib_enc/gaus_enc_fx.cpp +++ /dev/null @@ -1,666 +0,0 @@ -/*==================================================================================== - EVS Codec 3GPP TS26.442 Apr 03, 2018. Version 12.11.0 / 13.6.0 / 14.2.0 - ====================================================================================*/ - -#include "options.h" /* Compilation switches */ -#include "cnst_fx.h" /* Common constants */ -#include "rom_com_fx.h" /* Static table prototypes */ -#include "rom_enc_fx.h" /* Static table prototypes */ -#include "prot_fx.h" /* Function prototypes */ -#include "stl.h" -#include "basop_mpy.h" - -/*-------------------------------------------------------------------* - * Local constants - *-------------------------------------------------------------------*/ - -#define NMAX 8 /* Control of the routine's complexity */ -/* #define FAC_DELTA 16.0f */ -#define SFAC_DELTA 11 - -/*-------------------------------------------------------------------* - * Local functions - *-------------------------------------------------------------------*/ - -static Word16 cod_2pos_fx( const Word16 ind1, const Word16 ind2, const Word16 sign1, const Word16 sign2, const Word16 n ); - -static void gauss2v_fx( Encoder_State_fx *st_fx, const Word16 h[], const Word16 xn[], const Word16 dn[], Word16 code[], - Word16 y1[], Word32 *gain, const Word16 lg, const Word16 shift, const Word16 Q_new, const Word16 nb_bits ); - -/*-------------------------------------------------------------------* - * Gaus_encode - * - * Encoder UnVoiced excitation coding using Gaussian codebooks - * - ACELP quantized Gaussian excitation - * - gain quantization - * - Total excitation for UnVoiced coders - * - Updates - *-------------------------------------------------------------------*/ -Word16 gaus_encode_fx( - Encoder_State_fx *st_fx, /* i/o: encoder state structure */ - const Word16 i_subfr, /* i : subframe index */ - const Word16 *h1, /* i : weighted filter input response */ - const Word16 *xn, /* i : target vector */ - Word16 *exc, /* o : pointer to excitation signal frame */ - Word16 *mem_w0, /* o : weighting filter denominator memory */ - Word16 *clip_gain, /* o : memory of gain of pitch clipping algorithm */ - Word16 *tilt_code, /* o : synthesis excitation spectrum tilt */ - Word16 *code, /* o : algebraic excitation Q9 */ - Word32 *gain_code, /* o : Code gain. Q16 */ - Word16 *y2, /* o : zero-memory filtered adaptive excitation Q9 */ - Word16 *gain_inov, /* o : innovation gain Q12 */ - Word16 *voice_fac, /* o : voicing factor Q15 */ - Word16 *gain_pit, /* o : adaptive excitation gain Q14 */ - const Word16 Q_new, /* i : scaling factor */ - const Word16 shift, /* i : scaling factor */ - Word32 *norm_gain_code, /* o : normalized innovative cb. gain Q16 */ - const Word32 core_brate /* i : core bitrate */ -) -{ - Word16 nb_bits, idx; - Word16 i=0; - Word32 Ltmp; - Word16 dn[L_SUBFR], exp_code, gcode; /* Correlation between xn and h1 */ - Word16 exp,tmp; - - /*----------------------------------------------------------------* - * Encode gaussian excitation - *----------------------------------------------------------------*/ - - /* Correlation between target xn2[] and impulse response h1[] */ - corr_xh_fx(xn, dn, h1); - - nb_bits = FCB_bits_tbl[BIT_ALLOC_IDX_fx(core_brate, UNVOICED, i_subfr, TC_SUBFR2IDX_fx(-1))]; - - gauss2v_fx(st_fx, h1, xn, dn, code, y2, gain_code, L_SUBFR, shift, Q_new, shr(nb_bits,1)); - - /*----------------------------------------------------------------* - * Encode gaussian gain - *----------------------------------------------------------------*/ - - /* codeword energy computation */ - Ltmp = Dot_product12(code, code, L_SUBFR, &exp_code); - - exp_code = sub(exp_code, 18 + 6); /* exp: -18 (code in Q9), -6 (L_subfr = 64) */ - Ltmp = Isqrt_lc(Ltmp, &exp_code); - *gain_inov = extract_h(L_shl(Ltmp, sub(exp_code, 3))); /* g_code_inov in Q12 */ - - nb_bits = gain_bits_tbl[BIT_ALLOC_IDX_fx(core_brate, UNVOICED, i_subfr, TC_SUBFR2IDX_fx(-1))]; - /* low bound = -30; stepSize = 1.71875; inv_stepSize = 0.5818181 */ - idx = gain_enc_gaus_fx(gain_code, nb_bits, -7680, 28160, 19065); - push_indice_fx( st_fx, IND_GAIN, idx, nb_bits ); - - /*----------------------------------------------------------------* - * Total excitation for Unvoiced coders - *----------------------------------------------------------------*/ - gcode = round_fx(L_shl(*gain_code, Q_new)); /* scaled gain_code with Qnew */ - FOR (i = 0; i < L_SUBFR; i++) - { - exc[i+i_subfr] = round_fx(L_shl(L_mult(gcode, code[i]), 15-9)); - } - - /*----------------------------------------------------------------* - * Updates: last value of new target is stored in mem_w0 - *----------------------------------------------------------------*/ - - Ltmp = L_mult(gcode, y2[L_SUBFR - 1]); - Ltmp = L_shl(Ltmp, add(5, shift)); - Ltmp = L_negate(Ltmp); - Ltmp = L_mac(Ltmp, xn[L_SUBFR - 1], 16384); - Ltmp = L_shl(Ltmp, sub(1, shift)); - *mem_w0 = round_fx(Ltmp); - init_gp_clip_fx(clip_gain); /* reset pitch clipping parameters */ - - *gain_pit = 0; - *tilt_code = 0; - move16(); /* purely unvoiced */ - *voice_fac = -32768; - move16(); /* purely unvoiced */ - exp = sub(norm_s(*gain_inov),1); - exp = s_max(exp, 0); - - tmp = div_s(shr(8192,exp),*gain_inov); - *norm_gain_code = L_shr(Mult_32_16(*gain_code, tmp),sub(1,exp)); - move16(); - - return (L_SUBFR<<6); -} - -/*-------------------------------------------------------------------* - * gauss2v() - * - * encoder of Gaussian Codebook for unvoiced - * consisting of addition of 2 Gaussian vectors - * - * One Gaussian vector of 192 values vectors delayed by 2 - *-------------------------------------------------------------------*/ -void gauss2v_fx( - Encoder_State_fx *st_fx, /* i/o: encoder state structure */ - const Word16 h[], /* i : weighted LP filter impulse response Q15 */ - const Word16 xn[], /* i : target signal Q12 */ - const Word16 dn[], /* i : backward filtered target Q12 */ - Word16 code[], /* o : gaussian excitation Q9 */ - Word16 y1[], /* o : zero-memory filtered gauss. excitation Q8 */ - Word32 *gain, /* o : excitation gain. 32-bit number in Q16 */ - const Word16 lg, /* i : subframe size Q0 */ - const Word16 shift, /* i : Scaling factor Q0 */ - const Word16 Q_new, /* i : Scaling factor Q0 */ - const Word16 nb_bits /* i : nb ob bits per track (max 6) */ -) -{ - Word16 i, j, ind1, ind2; - Word16 nvec, step; - Word32 cor, cora, dotprod; - Word16 enerw; - Word32 eneri,cor2; - Word32 enerw32,cor2w32; - Word16 *cpt1; - Word16 *pt1, *pt2; - Word32 max[NMAX+1]; - Word16 *pos[NMAX+1]; - Word32 sign[NMAX+1]; - Word32 ener[NMAX+1], corr[NMAX+1], ener1; - Word16 dico2[L_SUBFR*NMAX]; - Word16 exp_num; - Word16 exp_den; - Word16 Num; - Word16 Den; - Word32 GainPortion1; - Word32 GainPortion2; - Word32 cor_abs; - Word16 cor_neg; - Word16 div_result; - Word32 ener_sqrt; - Word32 Portion; - Word16 sign1,sign2; - Word16 enerw_norm,enerw_mantissa; - Word16 cor2w_norm,cor2w_mantissa; - Word16 eneri_norm,eneri_mantissa; - Word16 cor2_norm ,cor2_mantissa; - Word16 difference_norm; - Word32 cor32; /* 32-bit intermediate value*/ - Word16 hi1, lo1; - Word16 update_best; - Word16 idx; - Word32 Lc0,Lc1, Lnum, Lden; - Word16 gxx, gcc,index_delta, delta, m_sign, inv_delta; - Word16 hg[190],Gaus_dico2[190]; - Word16 shiftP3; - - /*----------------------------------------------------------------* - * Encode the tilt of gaussian excitation - *----------------------------------------------------------------*/ - - /* Compute spectral tilt of target */ - Lc0 = L_mult(xn[1], xn[1]); - Lc1 = L_mult(xn[1], xn[0]); - FOR (i=2; i 0) /* Adapt spectral tilt of initial codebook */ - { - /* Computation of 1 / (1+fdelta*fdelta) */ - inv_delta = inv_delta_tab[sub(index_delta, 1)]; - move16(); /* Q15 */ - - /* fgaus_dico2[0] = gaus_dico[0] */ - Gaus_dico2[0] = gaus_dico_fx[0]; - FOR (i=1; i<190; i++) - { - /* fgaus_dico2[i] = (gaus_dico[i] - fdelta*gaus_dico[i-1]) / (1 + fdelta*fdelta) */ - Lnum = L_msu(L_deposit_h(gaus_dico_fx[i]), delta, gaus_dico_fx[i-1]); - Gaus_dico2[i] = round_fx(Mpy_32_16_1(Lnum, inv_delta)); - } - } - ELSE - { - FOR (i=0; i<190; i++) - { - /* fgaus_dico2[i] = gaus_dico[i] */ - Gaus_dico2[i] = gaus_dico_fx[i]; - move16(); - } - } - - /*----------------------------------------------------------------* - * Initializations - *----------------------------------------------------------------*/ - - ind1 = 0; - move16(); - ind2 = 0; - move16(); - - nvec = shl(1, nb_bits); - step = shr(0x80, nb_bits); - - /*----------------------------------------------------------------* - * dot product between dn and gaussian codevectors, - * keep NMAX best vectors - *----------------------------------------------------------------*/ - - set32_fx(max, 0, NMAX+1); - set32_fx(sign, 0, NMAX+1); - - FOR (i = 0; i < NMAX+1; i++) - { - pos[i] = (Word16 *)Gaus_dico2; - } - - cpt1 = Gaus_dico2; - move16(); - - FOR (i=0; i< nvec; i++) - { - /* Dot product without normalization, because values are compared with each other afterwards. */ - cor = Dot_product(cpt1, dn, lg); /* Q12 * Q12 * length of 64 + 1 left shift ==> Q31*/ - cora = L_abs(cor); - j = NMAX-1; - move16(); - - DO - { - IF (L_sub(cora, max[j]) >= 0) - { - max[j+1] = max[j]; - move32(); /*Q31*/ - pos[j+1] = pos[j]; - move16(); /*Pointer*/ - sign[j+1] = sign[j]; - move32(); /*Q31*/ - max[j] = cora; - move32(); /*Q31*/ - pos[j] = cpt1; - move16(); /*Pointer*/ - sign[j] = cor; - move32(); /*Q31*/ - } - j--; - } - WHILE (j >= 0); - cpt1 += step; - } - - /*----------------------------------------------------------------* - * filter selected vectors - * put sign - * compute energy - *----------------------------------------------------------------*/ - - pt1 = dico2; - move16(); - FOR (i=0; i Q31 */ - corr[i] = Dot_product(pt1,xn,lg); /* must be equal to sign[i] !! */ - move32(); /* pt1 points into dico2, in Q12. xn is in Q12 */ - /* Result is for Q12 * Q12 with length of 64 (6 bits) + 1 left shift => Q31 */ - pt1 += L_SUBFR; - } - - /*------------------------------------------------------------------------* - * try all combinations of NMAX best vectors - *------------------------------------------------------------------------*/ - - pt1 = dico2; - move16(); - - /* Initial values for search algorithm */ - enerw32 = L_deposit_h(0x80); - cor2w32 = L_deposit_l(-2); - enerw_norm = norm_l(enerw32); - cor2w_norm = norm_l(cor2w32); - cor2w_mantissa = round_fx(L_shl(cor2w32,cor2w_norm)); - enerw_mantissa = round_fx(L_shl(enerw32,enerw_norm)); - - FOR (i=0; i< NMAX; i++) - { - pt2 = pt1; - move16(); - FOR (j=i; j Q31 */ - - /* eneri = round_fx(ener[i]) + round_fx(ener[j]) + 2*round_fx(dotprod) */ - /* Use ScalingShift to stay aligned with ener[] */ - eneri=L_shl(dotprod, 1); /* One left shift added for factor of 2 */ - eneri=L_add(ener[i], eneri); - eneri=L_add(ener[j], eneri); /* Q31 */ - - lo1 = L_Extract_lc(cor32, &hi1); - cor2 = Sad_32(0, hi1, lo1); /* Square + Add */ - - cor2_norm = norm_l(cor2); - eneri_norm = norm_l(eneri); - cor2_mantissa = round_fx(L_shl(cor2, cor2_norm)); - eneri_mantissa = round_fx(L_shl(eneri, eneri_norm)); - - difference_norm = sub(add(cor2_norm, enerw_norm), add(cor2w_norm, eneri_norm)); - - update_best = 0; - move16(); - - IF (difference_norm > 0) - { - if (L_sub(L_shr(L_mult(cor2_mantissa, enerw_mantissa), difference_norm), - L_mult(cor2w_mantissa, eneri_mantissa)) > 0) - { - update_best = 1; - move16(); - } - } - ELSE - { - if (L_msu(L_shl(L_mult(cor2w_mantissa, eneri_mantissa), difference_norm), cor2_mantissa, enerw_mantissa) < 0) - { - update_best=1; - move16(); - } - } - IF (update_best != 0) - { - cor2w_mantissa = cor2_mantissa; - move16(); - cor2w_norm = cor2_norm; - move16(); - enerw_mantissa = eneri_mantissa; - move16(); - enerw_norm = eneri_norm; - move16(); - ind1 = i; - move16(); - ind2 = j; - move16(); - } - pt2 += L_SUBFR; - } - pt1 += L_SUBFR; - } - - enerw = round_fx(L_shr(L_deposit_h(enerw_mantissa), enerw_norm)); - - /*----------------------------------------------------------------* - * Compute zero-memory filtered gauss. excitation y - *----------------------------------------------------------------*/ - - pt1 = dico2 + ind1*L_SUBFR; - move16(); /*Pointer arithmetic*/ - pt2 = dico2 + ind2*L_SUBFR; - move16(); - - shiftP3 = add(shift, 3); - FOR (i=0; i= 0) - { - sign1 = 32767; - move16(); - } - - sign2 = (-32768); - move16(); - if (sign[ind2] >= 0) - { - sign2 = 32767; - move16(); - } - - /*----------------------------------------------------------------* - * Compute code - *----------------------------------------------------------------*/ - - pt1 = pos[ind1]; - move16(); /* Points to gaussian vector (gaus_dico_fx) in Q12 */ - pt2 = pos[ind2]; - move16(); /* Points to gaussian vector (gaus_dico_fx) in Q12 */ - - /* sign[ind1] and sign[ind2] */ - FOR (i=0; i Q31 */ - - exp_num = sub(norm_s(enerw), 1); - exp_den = norm_l(ener1); - Num = shl(enerw, exp_num); - Den = round_fx(L_shl(ener1, exp_den)); - - GainPortion2 = L_deposit_l(0); /* Unexpected division by zero. Eliminate this gain contribution */ - IF (Den != 0) /* Protection against division by zero */ - { - div_result = div_s(Num, Den); /* Q15 */ - - /* Re-scale to compensate for normalization*/ - GainPortion2 = L_shr(L_deposit_l(div_result), sub(exp_num, exp_den)); - } - - ener_sqrt = Isqrt(L_shl(GainPortion2, 1)); /* Make value a Q16 prior to division (align on power of 4) */ - ener_sqrt = L_shr(ener_sqrt, 8); /* Left-shift Q23 result to make a Q15 result */ - - Portion = Mult_32_16(GainPortion1, 19661); /* Performs GainPortion1*.6 */ - Portion = Madd_32_16(Portion, ener_sqrt, 13107); /* Performs ener_sqrt*.4 */ - - /* Gain must be output in a 32-bit variable as a Q16 */ - /* Compensate for Q_new */ - *gain = L_shl(Portion, sub(13, Q_new)); - move32(); - - return; -} - - -/*---------------------------------------------------------------------* - * Put selected codevector positions and signs into quantization index - *---------------------------------------------------------------------*/ -static Word16 cod_2pos_fx( /* o : codebook quantization index */ - const Word16 ind1, /* i : index of 1st gaussian vector */ - const Word16 ind2, /* i : index of 2nd gaussian vector */ - const Word16 sign1, /* i : sign of 1st gaussian vector */ - const Word16 sign2, /* i : sign of 2nd gaussian vector */ - const Word16 n /* i : nb. of codebook vectors */ -) -{ - Word16 i1, i2, index, s1, s2; - s1 = 1; - move16(); - - if (sign1 > 0) - { - s1 = 0; - move16(); - } - s2 = 1; - move16(); - if (sign2 > 0) - { - s2 = 0; - move16(); - } - - IF (sub(s1, s2)==0) - { - IF (sub(ind1, ind2) <= 0) - { - i1 = ind1; - move16(); - i2 = ind2; - move16(); - } - ELSE - { - i1 = ind2; - move16(); - i2 = ind1; - move16(); - } - } - ELSE - { - IF (sub(ind1, ind2)>0) - { - i1 = ind1; - move16(); - i2 = ind2; - move16(); - } - ELSE - { - i1 = ind2; - move16(); - i2 = ind1; - move16(); - s1 = s2; - move16(); - } - } - - index = extract_l(L_mult(i1, n)); - index = add(index, shl(i2, 1)); - index = add(index, s1); - - return index; -} diff --git a/src/libs/libevs/lib_enc/gp_clip.cpp b/src/libs/libevs/lib_enc/gp_clip.cpp new file mode 100644 index 00000000..126f909c --- /dev/null +++ b/src/libs/libevs/lib_enc/gp_clip.cpp @@ -0,0 +1,213 @@ +/*==================================================================================== + EVS Codec 3GPP TS26.443 Nov 13, 2018. Version 12.11.0 / 13.7.0 / 14.3.0 / 15.1.0 + ====================================================================================*/ + +#include +#include "prot.h" +#include "options.h" +#include "prot.h" +#include "cnst.h" + +/*-------------------------------------------------------------------* +* Local constants +*-------------------------------------------------------------------*/ + +#define DIST_ISF_MAX_IO 150.0f + +#define DIST_ISF_MAX 120.0f +#define DIST_ISF_THRES 60 +#define GAIN_PIT_THRES 0.9f +#define GAIN_PIT_MIN 0.6f + +#define ALPHA1 0.98f +#define ALPHA4 0.99f +#define WINDOW_SIZE 50 +#define THRESH_TYPE 0.85f +#define THRESH_VOICING 0.86f + +/*-------------------------------------------------------------------* +* init_gp_clip +* +* Pitch Gain clipping initializations +*-------------------------------------------------------------------*/ +void init_gp_clip( + float mem[] /* o: memory of gain of pitch clipping algorithm */ +) +{ + mem[0] = DIST_ISF_MAX; + mem[1] = GAIN_PIT_MIN; + mem[2] = 0.0f; /* old energy of target (dB) */ + mem[3] = 0.0f; + mem[4] = 0.0f; + mem[5] = 0.8f; + + return; +} + +/*-------------------------------------------------------------------* + * Function gp_clip + * + * The gain needs to be limited (gain pitch < 1.0) when one of the + * following cases occurs: + * - a resonance on LPC filter (lp_disp < 60 Hz) AND a good pitch + * prediction (lp_gp > 0.9) + * - target energy drops by 6 dB AND a good pitch prediction (lp_gp>1.0) + *-------------------------------------------------------------------*/ + +short gp_clip( + const long core_brate, /* i : core bitrate */ + const float *voicing, /* i : normalized correlations (from OL pitch) */ + const short i_subfr, /* i : subframe index */ + const short coder_type, /* i : type of coder */ + const float xn[], /* i : target vector */ + float mem[] /* i/o: memory of gain of pitch clipping algorithm */ +) +{ + short clip; + short i; + float wener, tmp; + + clip = 0; + if( (core_brate == ACELP_6k60) || (core_brate == ACELP_8k85) ) + { + tmp = 0.9f + (0.1f * mem[0]/DIST_ISF_MAX_IO); /* clipping is activated when filtered pitch gain > threshold (0.94 to 1) */ + if (mem[1] > tmp) + { + clip = 1; + } + } + else if( (mem[0] < DIST_ISF_THRES) && (mem[1] > GAIN_PIT_THRES) ) + { + clip = 1; + } + + wener = 0.01f; + for (i=0; i 1.0f)) + { + clip = 1; + } + + mem[2] = wener; + tmp = ALPHA1 * mem[4]; + + if( coder_type == GENERIC || coder_type == TRANSITION || coder_type == INACTIVE ) + { + tmp += (1-ALPHA1); + } + + mem[4] = tmp; + tmp = ALPHA4 * mem[5]; + if( i_subfr == 0 ) + { + mem[5] = (1-ALPHA4) * voicing[0] + tmp; + } + else if( i_subfr == 2*L_SUBFR ) + { + mem[5] = (1-ALPHA4) * voicing[1] + tmp; + } + if( mem[3] > WINDOW_SIZE ) + { + if( ( mem[4] > THRESH_TYPE ) && ( mem[5] > THRESH_VOICING ) ) + { + clip = 1; + } + } + else + { + mem[3]++; + } + + return (clip); +} + +/*-------------------------------------------------------------------* + * gp_clip_test_lsf() + * + * check the minimum distance of LSFs for pitch gain clipping flag + *-------------------------------------------------------------------*/ + +void gp_clip_test_lsf( + const long core_brate, /* i : core bitrate */ + const float lsf[], /* i : LSF vector */ + float mem[], /* i/o: memory of gain of pitch clipping algorithm */ + const short Opt_AMR_WB /* i : flag indicating AMR-WB IO mode */ +) +{ + short i; + short m; + float dist, dist_min; + + dist_min = lsf[1] - lsf[0]; + + if ( Opt_AMR_WB ) + { + m = M-1; + } + else + { + m = M; + } + + for (i=2; i DIST_ISF_MAX_IO) + { + dist = DIST_ISF_MAX_IO; + } + } + else if (dist > DIST_ISF_MAX) + { + dist = DIST_ISF_MAX; + } + + mem[0] = dist; + + return; +} + +/*-------------------------------------------------------------------* + * gp_clip_test_gain_pit() + * + * low-pass filtering of the pitch gain for pitch gain clipping flag + *-------------------------------------------------------------------*/ + +void gp_clip_test_gain_pit( + const long core_brate, /* i : core bitrate */ + const float gain_pit, /* i : gain of quantized pitch */ + float mem[] /* i/o: memory of gain of pitch clipping algorithm */ +) +{ + float gain; + + if( (core_brate == ACELP_6k60) || (core_brate == ACELP_8k85) ) + { + gain = 0.98f*mem[1] + 0.02f*gain_pit; /* long term LTP gain average (>250ms) */ + } + else + { + gain = 0.9f*mem[1] + 0.1f*gain_pit; + } + if (gain < GAIN_PIT_MIN) + { + gain = GAIN_PIT_MIN; + } + mem[1] = gain; + + return; +} diff --git a/src/libs/libevs/lib_enc/gp_clip_fx.cpp b/src/libs/libevs/lib_enc/gp_clip_fx.cpp deleted file mode 100755 index 1c94fc9b..00000000 --- a/src/libs/libevs/lib_enc/gp_clip_fx.cpp +++ /dev/null @@ -1,396 +0,0 @@ -/*==================================================================================== - EVS Codec 3GPP TS26.442 Apr 03, 2018. Version 12.11.0 / 13.6.0 / 14.2.0 - ====================================================================================*/ - -#include "options.h" /* Compilation switches */ -#include "cnst_fx.h" /* Common constants */ -#include "prot_fx.h" /* Function prototypes */ -#include "basop_util.h" -#include "stl.h" - -/*-------------------------------------------------------------------* - * Local constants - *-------------------------------------------------------------------*/ - -#define DIST_ISF_MAX_IO 384 /* 150 Hz (6400Hz=16384) */ -#define DIST_ISF_MAX 307 /* 120 Hz (6400Hz=16384) */ -#define DIST_ISF_THRES 154 /* 60 (6400Hz=16384) */ -#define GAIN_PIT_THRES 14746 /* 0.9 in Q14 */ -#define GAIN_PIT_MIN 9830 /* 0.6 in Q14 */ - -#define ALPHA1 32113 /* 0.98f */ -#define ALPHA4 32440 /* 0.99f */ -#define WINDOW_SIZE 50 -#define THRESH_TYPE 13926 /* 0.85f in Q14 */ -#define THRESH_VOICING 14090 /* 0.86f in Q14 */ - -#define GPCLIP_E (6+2) - -#define ALPHA1_M1 21474836l/*1.0f-0.98 Q30*/ -#define ALPHA4_M1 10737408l/*1.0f-0.99f Q30*/ - -/*-------------------------------------------------------------------* - * init_gp_clip - * - * Pitch Gain clipping initializations - *-------------------------------------------------------------------*/ -void init_gp_clip_fx( - Word16 mem[] /* o : memory of gain of pitch clipping algorithm */ -) -{ - mem[0] = DIST_ISF_MAX; - move16(); /* Q0 */ - mem[1] = GAIN_PIT_MIN; - move16(); /* 1Q14 */ - mem[2] = 0; - move16(); /* 8Q7 */ /* old energy of target (dB) */ - mem[3] = 0; - move16(); /* Q0 */ - mem[4] = 0; - move16(); /* Q14 */ - mem[5] = 13107;/*0.8*/ move16(); /* Q14 */ - - return; -} - -/*-------------------------------------------------------------------* - * Function gp_clip - * - * The gain needs to be limited (gain pitch < 1.0) when one of the - * following cases occurs: - * - a resonance on LPC filter (lp_disp < 60 Hz) AND a good pitch - * prediction (lp_gp > 0.9) - * - target energy drops by 6 dB AND a good pitch prediction (lp_gp>1.0) - *-------------------------------------------------------------------*/ - -Word16 gp_clip_fx( - const Word32 core_brate, /* i : core bitrate */ - const Word16 *voicing, /* i : normalized correlations (from OL pitch) */ - const Word16 i_subfr, /* i : subframe index */ - const Word16 coder_type, /* i : type of coder */ - const Word16 xn[], /* i : target vector */ - Word16 mem[], /* i/o: memory of gain of pitch clipping algorithm */ - const Word16 Q_new /* i : scaling factor */ -) -{ - Word16 clip; - Word16 i, wener; - Word16 e_ener, f_ener; - Word32 ener; - Word32 L_tmp; - Word16 thres; - - clip = 0; - move16(); - test(); - IF( (core_brate == ACELP_6k60) || (core_brate == ACELP_8k85) ) - { - thres = add(14746, mult(1638, extract_l(L_mult(mem[0], (Word16)(16384/DIST_ISF_MAX_IO))))); /* clipping is activated when filtered pitch gain > threshold (0.94 to 1 in Q14) */ - test(); - if (sub(mem[1], thres) > 0) - { - clip = 1; - move16(); - } - } - ELSE - { - test(); - if(sub(mem[0], DIST_ISF_THRES) < 0 && sub(mem[1], GAIN_PIT_THRES) > 0) - { - clip = 1; - move16(); - } - } - - ener = L_mac(1L, xn[0], xn[0]); - FOR (i=1; i 0) - { - clip = 1; - move16(); - } - - mem[2] = wener; - move16(); - - L_tmp = L_mult(ALPHA1, mem[4]); - - test(); - test(); - if (sub(coder_type,GENERIC) == 0 || sub(coder_type,TRANSITION) == 0 || sub(coder_type,INACTIVE) == 0 ) - { - /* mem[4] = (1-ALPHA1) + ALPHA1 * mem[4], if branch taken */ - /* mem[4] = ALPHA1 * mem[4], otherwise */ - L_tmp = L_add(L_tmp, 32768L*(32768-ALPHA1)); - } - mem[4] = round_fx(L_tmp); - - L_tmp = L_mult(ALPHA4, mem[5]); - if (i_subfr == 0) - { - /* mem[5] = (1-ALPHA4) * voicing[0] + ALPHA4 * mem[5] */ - mem[5] = mac_r(L_tmp, (32768-ALPHA4)/2, voicing[0]); - move16(); /* /2 to put voicing from Q15 to Q14 */ - } - - if (sub(i_subfr, 2*L_SUBFR) == 0) - { - /* mem[5] = (1-ALPHA4) * voicing[1] + ALPHA4 * mem[5] */ - mem[5] = mac_r(L_tmp, (32768-ALPHA4)/2, voicing[1]); - move16(); /* /2 to put voicing from Q15 to Q14 */ - } - - IF (sub(mem[3], WINDOW_SIZE) > 0) - { - test(); - if (sub(mem[4], THRESH_TYPE) > 0 && sub(mem[5], THRESH_VOICING) > 0) - { - clip = 1; - move16(); - } - } - ELSE - { - mem[3] = add(mem[3], 1); - move16(); - } - - return (clip); -} - -/*-------------------------------------------------------------------* - * gp_clip_test_lsf() - * - * check the minimum distance of LSFs for pitch gain clipping flag - *-------------------------------------------------------------------*/ - -void gp_clip_test_isf_fx( - const Word32 core_brate, /* i : core bitrate */ - const Word16 isf[], /* i : isf values (in frequency domain) */ - Word16 mem[], /* i/o: memory of gain of pitch clipping algorithm */ - const Word16 Opt_AMR_WB /* i : flag indicating AMR-WB IO mode */ -) -{ - Word16 i, dist, dist_min, m; - - dist_min = sub(isf[1], isf[0]); - - m = M; - move16(); - if ( sub(Opt_AMR_WB,1)==0 ) - { - m = M-1; - move16(); - } - - move16(); /* ptr init*/ - FOR (i = 2; i < m; i++) - { - dist = sub(isf[i], isf[i - 1]); - dist_min = s_min(dist, dist_min); - } - - dist = extract_h(L_mac(L_mult(26214, mem[0]), 6554, dist_min)); - - test(); - IF( (core_brate == ACELP_6k60) || (core_brate == ACELP_8k85) ) - { - dist = s_min(dist, DIST_ISF_MAX_IO); - } - ELSE - { - dist = s_min(dist, DIST_ISF_MAX); - } - mem[0] = dist; - move16(); - - return; -} - -/*-------------------------------------------------------------------* - * gp_clip_test_gain_pit() - * - * low-pass filtering of the pitch gain for pitch gain clipping flag - *-------------------------------------------------------------------*/ - -void gp_clip_test_gain_pit_fx( - const Word32 core_brate, /* i : core bitrate */ - const Word16 gain_pit, /* i : gain of quantized pitch Q14 */ - Word16 mem[] /* i/o: memory of gain of pitch clipping algorithm 1Q14 */ -) -{ - Word16 gain; - Word32 L_tmp; - - test(); - IF( (core_brate == ACELP_6k60) || (core_brate == ACELP_8k85) ) - { - L_tmp = L_mult(32113, mem[1]); /* long term LTP gain average (>250ms) */ - L_tmp = L_mac(L_tmp, 655, gain_pit); - } - ELSE - { - L_tmp = L_mult(29491, mem[1]); - L_tmp = L_mac(L_tmp, 3277, gain_pit); - } - gain = extract_h(L_tmp); - gain = s_max(gain, GAIN_PIT_MIN); - mem[1] = gain; - move16(); - - return; -} - - -/*-------------------------------------------------------------------* - * Function gp_clip - * - * The gain needs to be limited (gain pitch < 1.0) when one of the - * following cases occurs: - * - a resonance on LPC filter (lp_disp < 60 Hz) AND a good pitch - * prediction (lp_gp > 0.9) - * - target energy drops by 6 dB AND a good pitch prediction (lp_gp>1.0) - *-------------------------------------------------------------------*/ -Word16 Mode2_gp_clip( - const Word16 voicing[3], /* i : normalized correlations from OL pitch Q15 */ - const Word16 i_subfr, /* i : subframe index */ - const Word16 coder_type, /* i : type of coder */ - const Word16 xn[], /* i : target vector Q_xn */ - Word16 mem[], /* i/o: memory of gain of pitch clipping algorithm */ - /* mem[0]: Q0 */ - /* mem[1]: 1Q14 */ - /* mem[2]: 8Q7 */ - /* mem[3]: Q0 (integer) */ - /* mem[4]: Q14 */ - /* mem[5]: Q14 */ - const Word16 L_subfr, - const Word16 Q_xn /* i : scaling factor of vector xn[] */ -) -{ - Word16 clip, tmp, exp_xn; - Word16 i; - Word32 wener, Ltmp; - - move16(); - clip = 0; - - test(); - if ((sub(mem[0],DIST_ISF_THRES) < 0) && (sub(mem[1],GAIN_PIT_THRES) > 0)) - { - move16(); - clip = 1; - } - - /*ener_exp = exp_xn * 2 + 1*/ - exp_xn = add(shl(sub(15,Q_xn),1), 1); - wener = L_shr(21474836l/*0.01f Q31*/, s_min(31,exp_xn)); - wener = L_max(1,wener); - - FOR (i=0; i 0) - { - move16(); - clip = 1; - } - - move16(); - mem[2] = tmp; /* wener in 8Q7 format */ - Ltmp = Mpy_32_16_1(ALPHA1, mem[4]); /* mem[4] in Q14 format, Ltmp in Q14 */ - - if( s_or(sub(coder_type,GENERIC) == 0, sub(coder_type,TRANSITION) == 0) ) - { - Ltmp = L_add(Ltmp, ALPHA1_M1); - } - mem[4] = round_fx(Ltmp); - - Ltmp = Mpy_32_16_1(ALPHA4, mem[5]); /* mem[5] in Q14 format, Ltmp in Q14 */ - IF( i_subfr == 0 ) - { - move16(); /* voicing: Q15 */ - mem[5] = round_fx(L_add(Mpy_32_16_1(ALPHA4_M1, voicing[0]), Ltmp)); - } - ELSE IF( sub(i_subfr,shl(L_subfr,1)) == 0 ) - { - move16(); - mem[5] = round_fx(L_add(Mpy_32_16_1(ALPHA4_M1, voicing[1]), Ltmp)); - } - - IF( sub(mem[3],WINDOW_SIZE) > 0 ) - { - test(); - if( ( sub(mem[4],THRESH_TYPE) > 0 ) && ( sub(mem[5],THRESH_VOICING) > 0 )) - { - move16(); - clip = 1; - } - } - ELSE - { - move16(); - mem[3] = add(mem[3], 1); - } - - - return (clip); -} - -/*-------------------------------------------------------------------* -* gp_clip_test_lsf: -* -* check the minimum distance of LSFs for pitch gain clipping flag -*-------------------------------------------------------------------*/ -void gp_clip_test_lsf_fx( - const Word16 lsf[], /* i : lsf values (in frequency domain) 14Q1*1.28 */ - Word16 mem[], /* i/o: memory of gain of pitch clipping algorithm */ - const Word16 m /* i : dimension of lsf */ -) -{ - Word16 i; - Word16 dist, dist_min; - - dist_min = sub(lsf[1],lsf[0]); - - FOR (i=2; i +#include "options.h" +#include "cnst.h" +#include "rom_com.h" +#include "prot.h" + +/*-------------------------------------------------------------------* + * Local functions + *-------------------------------------------------------------------*/ + +static float edyn( const float *vec, const short lvec ); + +static void gsc_enc( Encoder_State *st, float res_dct_in[], float exc_dct_in[], const short Diff_len, + const short bits_used, const short nb_subfr, const short coder_type, + float *lsf_new, float* exc_wo_nf, float *tmp_noise ); + +/*-------------------------------------------------------------------* + * encod_audio() + * + * Encode audio (AC) frames + *-------------------------------------------------------------------*/ + +void encod_audio( + Encoder_State *st, /* i/o: State structure */ + LPD_state *mem, /* i/o: encoder memories */ + const float speech[], /* i : input speech */ + const float Aw[], /* i : weighted A(z) unquantized for subframes */ + const float Aq[], /* i : 12k8 Lp coefficient */ + const short T_op[], /* i : open loop pitch */ + const float voicing[], /* i : voicing */ + const float *res, /* i : residual signal */ + float *synth, /* i/o: core synthesis */ + float *exc, /* i/o: current non-enhanced excitation */ + float *pitch_buf, /* i/o: floating pitch values for each subframe */ + float *voice_factors, /* o : voicing factors */ + float *bwe_exc, /* o : excitation for SWB TBE */ + const short attack_flag, /* i : Flag that point to an attack coded with AC mode (GSC) */ + const short coder_type, /* i : coding type */ + float *lsf_new, /* i : current frame ISF vector */ + float *tmp_noise /* o : long-term noise energy */ +) +{ + const float *p_Aq; + short i, i_subfr, nb_subfr, last_pit_bin; + short T0_tmp, T0_frac_tmp, nb_subfr_flag; + short tmp_nb_bits_tot; + float Es_pred; + float dct_res[L_FRAME], dct_epit[L_FRAME]; + float m_mean; + float exc_wo_nf[L_FRAME]; + short nb_bits; /*number of bits*/ + int indice; /*parameter indices to write*/ + + m_mean = 0.0f; + tmp_nb_bits_tot = 0; + + T0_tmp = 64; + T0_frac_tmp = 0; + mvr2r( mem->mem_syn, st->mem_syn_tmp, M ); + st->mem_w0_tmp = mem->mem_w0; + Es_pred = 0; + + /*---------------------------------------------------------------* + * Encode GSC attack flag (used to reduce possible pre-echo) + * Encode GSC SWB speech flag + *---------------------------------------------------------------*/ + + push_indice( st, IND_GSC_ATTACK, attack_flag, 1 ); + + if( coder_type != INACTIVE && st->total_brate >= ACELP_13k20 ) + { + push_indice( st,IND_GSC_SWB_SPEECH, st->GSC_noisy_speech, 1); + } + + /*---------------------------------------------------------------* + * Find and encode the number of subframes + *---------------------------------------------------------------*/ + + if ( st->core_brate >= ACELP_9k60 && st->core_brate <= ACELP_13k20 ) + { + for( i = 0; i < 5; i++ ) + { + if( fabs(st->gsc_lt_diff_etot[MAX_LT-i-1]) > 6.0f && st->cor_strong_limit == 1 ) + { + st->cor_strong_limit = 0; + } + } + } + + if( st->GSC_noisy_speech ) + { + nb_subfr = NB_SUBFR; + st->cor_strong_limit = 0; + nb_subfr_flag = 1; + } + else + { + if( (st->cor_strong_limit == 0 || coder_type == INACTIVE) && st->core_brate >= ACELP_9k60 ) + { + nb_subfr = 2; + nb_subfr_flag = 0; + st->cor_strong_limit = 0; + } + else + { + nb_subfr = SWNB_SUBFR; + nb_subfr_flag = 1; + } + + if( st->core_brate >= ACELP_9k60 ) + { + /* nb_subfr_flag can only have the value 0 or 1 */ + push_indice( st, IND_HF_NOISE, nb_subfr_flag, 1); + } + } + + /*---------------------------------------------------------------* + * Compute adaptive (pitch) excitation contribution + *---------------------------------------------------------------*/ + + if( st->GSC_noisy_speech && nb_subfr == NB_SUBFR ) + { + nb_bits = Es_pred_bits_tbl[BIT_ALLOC_IDX(st->core_brate, GENERIC, -1, -1)]; + Es_pred_enc( &Es_pred, &indice, L_FRAME, L_SUBFR, res, voicing, nb_bits, 0 ); + push_indice( st, IND_ES_PRED, indice, nb_bits ); + } + + enc_pit_exc( st, mem, speech, Aw, Aq, Es_pred, T_op, voicing, res, synth, exc, &T0_tmp, &T0_frac_tmp, pitch_buf, nb_subfr, &st->lt_gpitch ); + + /*---------------------------------------------------------------* + * DCT transform + *---------------------------------------------------------------*/ + + edct( exc, dct_epit, L_FRAME ); + edct( res, dct_res, L_FRAME ); + + /*---------------------------------------------------------------* + * Calculate energy dynamics + *---------------------------------------------------------------*/ + + for( i = 7; i < 15; i++ ) + { + m_mean += edyn( dct_res+i*16, 16 ); + } + m_mean *= 0.125f; + + if( m_mean > st->mid_dyn ) + { + st->mid_dyn = 0.2f * st->mid_dyn + 0.8f * m_mean; + } + else + { + st->mid_dyn = 0.6f * st->mid_dyn + 0.4f * m_mean; + } + + if( coder_type != INACTIVE ) + { + st->noise_lev = (NOISE_LEVEL_SP3+1) - usquant(st->mid_dyn, &m_mean, MIN_DYNAMIC, DYNAMIC_RANGE/GSC_NF_STEPS, GSC_NF_STEPS); + if( st->noise_lev > NOISE_LEVEL_SP3) + { + st->noise_lev = NOISE_LEVEL_SP3; + } + } + + st->past_dyn_dec = st->noise_lev; + + if( st->core_brate <= ACELP_8k00 ) + { + if( st->noise_lev <= NOISE_LEVEL_SP2 ) + { + st->noise_lev = NOISE_LEVEL_SP2; + } + + push_indice( st, IND_NOISE_LEVEL, st->noise_lev - NOISE_LEVEL_SP2, 2 ); + } + else if( st->GSC_noisy_speech ) + { + st->noise_lev = NOISE_LEVEL_SP3; + } + else + { + push_indice( st, IND_NOISE_LEVEL, st->noise_lev - NOISE_LEVEL_SP0, 3 ); + } + + /*---------------------------------------------------------------* + * Find and encode the last band where the adaptive (pitch) contribution is significant + *---------------------------------------------------------------*/ + + last_pit_bin = Pit_exc_contribution_len( st, dct_res, dct_epit, pitch_buf, &st->pit_exc_hangover, coder_type ); + + if( last_pit_bin == 0 ) + { + mem->tilt_code = 0.0f; + } + else + { + last_pit_bin++; + } + + /*--------------------------------------------------------------------------------------* + * GSC encoder + *--------------------------------------------------------------------------------------*/ + + /* Find the current total number of bits used */ + tmp_nb_bits_tot = st->nb_bits_tot; + + if( st->extl_brate > 0 ) + { + /* subtract 1 bit for TBE/BWE BWE flag (bit counted in extl_brate) */ + tmp_nb_bits_tot--; + } + + if( coder_type == INACTIVE && st->core_brate <= ACELP_9k60 ) + { + /* add 5 bits for noisiness */ + tmp_nb_bits_tot += 5; + } + + gsc_enc( st, dct_res, dct_epit, last_pit_bin, tmp_nb_bits_tot, nb_subfr, coder_type, lsf_new, exc_wo_nf, tmp_noise ); + + /*--------------------------------------------------------------------------------------* + * iDCT transform + *--------------------------------------------------------------------------------------*/ + + edct( dct_epit, exc, L_FRAME ); + edct( exc_wo_nf, exc_wo_nf, L_FRAME ); + + + /*--------------------------------------------------------------------------------------* + * Remove potential pre-echo in case an onset has been detected + *--------------------------------------------------------------------------------------*/ + + pre_echo_att( &st->Last_frame_ener, exc, attack_flag, st->last_coder_type ); + + /*--------------------------------------------------------------------------------------* + * Update BWE excitation + *--------------------------------------------------------------------------------------*/ + + set_f( voice_factors, 0.0f, NB_SUBFR); + interp_code_5over2( exc, bwe_exc, L_FRAME ); + + /*--------------------------------------------------------------------------------------* + * Synthesis + *--------------------------------------------------------------------------------------*/ + + p_Aq = Aq; + for ( i_subfr=0; i_subfrmem_syn, 1 ); + p_Aq += (M+1); + } + + /*--------------------------------------------------------------------------------------* + * Updates + *--------------------------------------------------------------------------------------*/ + + mem->mem_w0 = st->mem_w0_tmp; + mvr2r( exc_wo_nf, exc, L_FRAME ); + + return; +} + +/*-------------------------------------------------------------------* + * gsc_enc() + * + * Generic audio signal encoder + *-------------------------------------------------------------------*/ + +static void gsc_enc( + Encoder_State *st, /* i/o: State structure */ + float res_dct_in[], /* i : dct of residual signal */ + float exc_dct_in[], /* i/o: dct of pitch-only excitation / total excitation */ + const short Diff_len, /* i : Lenght of the difference signal (before pure spectral)*/ + const short bits_used, /* i : Number of bit used before frequency Q */ + const short nb_subfr, /* i : Number of subframe considered */ + const short coder_type, /* i : coding type */ + float *lsf_new, /* i : ISFs at the end of the frame */ + float *exc_wo_nf, /* o : excitation (in f domain) without noisefill */ + float *tmp_noise /* o : long-term noise energy */ +) +{ + short i; + float exc_diffQ[L_FRAME]; + float exc_diff[L_FRAME]; + short bit; + short nb_subbands; + short pvq_len; + short bits_per_bands[MBANDS_GN]; /*Q3*/ + short tmp_band; + float concat_in[L_FRAME]; + float concat_out[L_FRAME]; + short max_ener_band[MBANDS_GN], j; + float Ener_per_bd_iQ[MBANDS_GN]; + short last_bin; + short bitallocation_band[MBANDS_GN]; + short bitallocation_exc[2]; + short npulses[NB_SFM]; + short maxpulse[NB_SFM]; + float mean_gain; + short seed_init; + + /*--------------------------------------------------------------------------------------* + * Initialization + *--------------------------------------------------------------------------------------*/ + + bit = bits_used; + set_f( exc_diffQ, 0.0f, L_FRAME ); + + /*--------------------------------------------------------------------------------------* + * Calculate the difference between the residual spectrum and the spectrum of adaptive excitation + * (non valuable temporal content present in exc_dct_in is already zeroed) + *--------------------------------------------------------------------------------------*/ + + v_sub( res_dct_in, exc_dct_in, exc_diff, L_FRAME ); + exc_diff[0] = 0; + + /*--------------------------------------------------------------------------------------* + * Multiply the difference spectrum with the normalized spectral shape of the residual signal + * This improves the stability of the differnece spectrum since the spectral shape of the + * residual signal is less suseptible to rapid changes than the difference spectrum + *--------------------------------------------------------------------------------------*/ + + if( Diff_len == 0 ) + { + tmp_band = 0; + } + else + { + tmp_band = st->mem_last_pit_band; + } + + Ener_per_band_comp( exc_diff, Ener_per_bd_iQ, MBANDS_GN, 1 ); + + /*--------------------------------------------------------------------------------------* + * Gain quantizaion + *--------------------------------------------------------------------------------------*/ + + mean_gain = gsc_gainQ( st, Ener_per_bd_iQ, Ener_per_bd_iQ, st->core_brate, coder_type, st->bwidth ); + *tmp_noise = 10.0f * mean_gain; + + /*--------------------------------------------------------------------------------------* + * PVQ encoder + *--------------------------------------------------------------------------------------*/ + + bands_and_bit_alloc( st->cor_strong_limit, st->noise_lev, st->core_brate, Diff_len, bit, &bit, Ener_per_bd_iQ, + max_ener_band, bits_per_bands, &nb_subbands, exc_diff, concat_in, &pvq_len, + coder_type, st->bwidth, st->GSC_noisy_speech ); + + set_s( npulses, 0, NB_SFM ); + bit -= pvq_core_enc(st, concat_in, concat_out, bit, nb_subbands, gsc_sfm_start, gsc_sfm_end, gsc_sfm_size, bits_per_bands, NULL, npulses, maxpulse, ACELP_CORE ); + + /* write unused bits */ + while( bit > 0 ) + { + i = min( bit, 16 ); + push_indice( st, IND_UNUSED, 0, i ); + bit -= i; + } + + /* Reorder Q bands */ + last_bin = 0; + set_s( bitallocation_band, 0, MBANDS_GN ); + seed_init = 0; + + for( j = 0; j < nb_subbands; j++ ) + { + mvr2r( concat_out+j*16, exc_diffQ + max_ener_band[j]*16, 16 ); + + if( max_ener_band[j] > last_bin ) + { + last_bin = max_ener_band[j]; + } + + bitallocation_band[max_ener_band[j]] = 1; + + seed_init += npulses[j]; + } + if( st->last_coder_type != AUDIO /* First audio frame */ + && st->last_coder_type != UNVOICED ) /* last_coder_type == INACTIVE is overwritten in update_enc to UNVOICED */ + { + for( j = 0; j < nb_subbands*16; j++ ) + { + if( concat_out[j] > 0 ) + { + seed_init = (short)((int)seed_init<<3); + } + if( concat_out[j] < 0 ) + { + seed_init += 3; + } + } + + st->seed_tcx = seed_init; + } + + if( st->core_brate == ACELP_8k00 && st->bwidth != NB ) + { + bitallocation_exc[0] = 0; + bitallocation_exc[1] = 0; + + if( exc_diffQ[L_FRAME8k - 2] != 0 ) + { + bitallocation_exc[0] = 1; + } + + if( exc_diffQ[L_FRAME8k - 1] != 0 ) + { + bitallocation_exc[1] = 1; + } + } + + /*--------------------------------------------------------------------------------------* + * Skip adaptive (pitch) contribution frequency band (no noise added over the adaptive (pitch) contribution) + * Find x pulses between 1.6-3.2kHz to code in the spectrum of the residual signal + * Gain is based on the inter-correlation gain between the pulses found and residual signal + *--------------------------------------------------------------------------------------*/ + + freq_dnw_scaling( st->cor_strong_limit, coder_type, st->noise_lev, st->core_brate, exc_diffQ ); + + /*--------------------------------------------------------------------------------------* + * Estimate noise level + *--------------------------------------------------------------------------------------*/ + + highband_exc_dct_in( st->core_brate, mfreq_bindiv_loc, last_bin, Diff_len, st->noise_lev, tmp_band, exc_diffQ, + &st->seed_tcx, Ener_per_bd_iQ, nb_subfr, exc_dct_in, st->last_coder_type, bitallocation_band, lsf_new, + st->last_exc_dct_in, &st->last_ener, st->last_bitallocation_band, bitallocation_exc, 0, coder_type, + st->bwidth, exc_wo_nf, st->GSC_noisy_speech, NULL ); + + exc_dct_in[0] = 0; + + return; +} + +/*---------------------------------------------------------------------* + * edyn() + * + * Calculate energy dynamics in a vector (ratio of energy maximum to energy mean) + *---------------------------------------------------------------------*/ + +static float edyn( /* o : ratio of max to mean */ + const float *vec, /* i : input vector */ + const short lvec /* i : length of input vector */ +) +{ + short j; + float temp, ener_max, ener_mean, dyn; + + ener_mean = 1.0f; + ener_max = 1.0f; + + for( j=0; j ener_max ) + { + ener_max = temp; + } + ener_mean += temp; + } + ener_mean /= lvec; + dyn = 10.0f * (ener_max / ener_mean); + + return dyn; +} diff --git a/src/libs/libevs/lib_enc/gs_enc_fx.cpp b/src/libs/libevs/lib_enc/gs_enc_fx.cpp deleted file mode 100755 index 2e76d740..00000000 --- a/src/libs/libevs/lib_enc/gs_enc_fx.cpp +++ /dev/null @@ -1,570 +0,0 @@ -/*==================================================================================== - EVS Codec 3GPP TS26.442 Apr 03, 2018. Version 12.11.0 / 13.6.0 / 14.2.0 - ====================================================================================*/ - -#include "options.h" -#include "cnst_fx.h" -#include "rom_com_fx.h" -#include "prot_fx.h" -#include "stl.h" - -/*-------------------------------------------------------------------* - * Local functions - *-------------------------------------------------------------------*/ - -static Word16 edyn_fx(const Word16 *vec, const Word16 lvec, Word16 Qnew); - -static void gsc_enc_fx( Encoder_State_fx *st_fx, Word16 res_dct_in[],Word16 exc_dct_in[], - const Word16 Diff_len,const Word16 bits_used, const Word16 nb_subfr,const Word16 coder_type, - Word16 *lsf_new,Word16 *exc_wo_nf, Word16 *tmp_noise, Word16 Q_exc ); - -/*-------------------------------------------------------------------* - * encod_audio() - * - * Encode audio (AC) frames - *-------------------------------------------------------------------*/ -void encod_audio_fx( - Encoder_State_fx *st_fx, /* i/o: State structure */ - LPD_state *mem, /* i/o: acelp memories */ - const Word16 speech[], /* i : input speech Q_new */ - const Word16 Aw[], /* i : weighted A(z) unquantized for subframes */ - const Word16 Aq[], /* i : 12k8 Lp coefficient */ - const Word16 T_op[], /* i : open loop pitch */ - const Word16 voicing[], /* i : voicing Q15 */ - const Word16 *res, /* i : residual signal Q_new */ - Word16 *synth, /* i/o: core synthesis Q-1 */ - Word16 *exc, /* i/o: current non-enhanced excitation Q_new */ - Word16 *pitch_buf, /* i/o: floating pitch values for each subframe Q6 */ - Word16 *voice_factors, /* o : voicing factors Q15 */ - Word16 *bwe_exc, /* o : excitation for SWB TBE Q0 */ - const Word16 attack_flag, /* i : Flag that point to an attack coded with AC mode (GSC) */ - const Word16 coder_type, /* i : coding type */ - Word16 *lsf_new, /* i : current frame ISF vector */ - Word16 *tmp_noise, /* o : noise energy */ - Word16 Q_new, - Word16 shift -) -{ - const Word16 *p_Aq; - Word16 i, i_subfr, nb_subfr, last_pit_bin; - Word16 T0_tmp, T0_frac_tmp, nb_subfr_flag; - Word16 tmp_nb_bits_tot = 0; - Word16 Es_pred; - Word16 dct_res[L_FRAME], dct_epit[L_FRAME]; - Word16 m_mean = 0; - Word16 saved_bit_pos; - Word16 exc_wo_nf[L_FRAME]; - Word32 Lm_mean; - Word16 nb_bits; - Word16 indice; - - m_mean = 0; - move16(); - tmp_nb_bits_tot = 0; - move16(); - - T0_tmp = 64; - move16(); - T0_frac_tmp = 0; - move16(); - Copy(mem->mem_syn, st_fx->mem_syn_tmp_fx, M); - st_fx->mem_w0_tmp_fx = mem->mem_w0; - move16(); - Es_pred = 0; - move16(); - - /*---------------------------------------------------------------* - * Encode GSC attack flag (used to reduce possible pre-echo) - * Encode GSC SWB speech flag - *---------------------------------------------------------------*/ - push_indice_fx( st_fx, IND_GSC_ATTACK, attack_flag, 1 ); - - test(); - IF( sub(coder_type,INACTIVE ) != 0&& L_sub(st_fx->total_brate_fx,ACELP_13k20) >= 0) - { - push_indice_fx( st_fx,IND_GSC_SWB_SPEECH, st_fx->GSC_noisy_speech_fx, 1); - } - /*---------------------------------------------------------------* - * Find and encode the number of subframes - *---------------------------------------------------------------*/ - test(); - IF ( L_sub(st_fx->core_brate_fx,ACELP_9k60) >= 0&& L_sub(st_fx->core_brate_fx,ACELP_13k20) <= 0 ) - { - FOR( i = 0; i < 5; i++) - { - test(); - if( sub(abs_s(st_fx->gsc_lt_diff_etot_fx[MAX_LT-i-1]),1536) > 0 && sub(st_fx->cor_strong_limit_fx,1) == 0 ) - { - st_fx->cor_strong_limit_fx = 0; - move16(); - } - } - } - IF( st_fx->GSC_noisy_speech_fx ) - { - nb_subfr = NB_SUBFR; - move16(); - st_fx->cor_strong_limit_fx = 0; - move16(); - nb_subfr_flag = 1; - move16(); - } - ELSE - { - test(); - test(); - IF( (st_fx->cor_strong_limit_fx == 0 || sub(coder_type,INACTIVE) == 0) && L_sub(st_fx->core_brate_fx,ACELP_9k60) >= 0 ) - { - nb_subfr = 2; - move16(); - nb_subfr_flag = 0; - move16(); - st_fx->cor_strong_limit_fx = 0; - move16(); - } - ELSE - { - nb_subfr = SWNB_SUBFR; - move16(); - nb_subfr_flag = 1; - move16(); - } - IF( L_sub(st_fx->core_brate_fx,ACELP_9k60) >= 0 ) - { - /* nb_subfr_flag can only have the value 0 or 1 */ - push_indice_fx( st_fx, IND_HF_NOISE, nb_subfr_flag, 1); - } - } - - /*---------------------------------------------------------------* - * Compute adaptive (pitch) excitation contribution - *---------------------------------------------------------------*/ - - test(); - IF( st_fx->GSC_noisy_speech_fx && sub(nb_subfr,NB_SUBFR ) == 0 ) - { - nb_bits = Es_pred_bits_tbl[BIT_ALLOC_IDX_fx(st_fx->core_brate_fx, GENERIC, -1, -1)]; - move16(); - Es_pred_enc_fx( &Es_pred, &indice, L_FRAME, res, voicing, nb_bits,0, Q_new - ); - push_indice_fx( st_fx, IND_ES_PRED, indice, nb_bits ); - } - - enc_pit_exc_fx( st_fx, mem, speech, Aw, Aq,Es_pred, T_op, voicing, res, synth, exc, &T0_tmp, - &T0_frac_tmp, pitch_buf, nb_subfr, &st_fx->lt_gpitch_fx, &saved_bit_pos, Q_new, shift ); - - /*---------------------------------------------------------------* - * DCT transform - *---------------------------------------------------------------*/ - edct_16fx( exc, dct_epit, L_FRAME, 7 ); - edct_16fx( res, dct_res, L_FRAME, 7 ); - /*---------------------------------------------------------------* - * Calculate energy dynamics - *---------------------------------------------------------------*/ - Lm_mean = L_deposit_l(0); - FOR( i = 7; i < 15; i++ ) - { - /*m_mean = add(m_mean,edyn_fx( dct_res+i*16, 16, Q_new )); */ - Lm_mean = L_mac(Lm_mean, edyn_fx( dct_res+i*16, 16, Q_new ), 4096);/*Q7*/ - } - m_mean = round_fx(Lm_mean);/*Q7*/ - - IF( sub(m_mean,st_fx->mid_dyn_fx) > 0 ) - { - /*st_fx->mid_dyn_fx = 0.2f * st_fx->mid_dyn_fx + 0.8f * m_mean;*/ - st_fx->mid_dyn_fx = round_fx(L_mac(L_mult(26214,m_mean),6554,st_fx->mid_dyn_fx));/*Q7*/ - } - ELSE - { - /*st_fx->mid_dyn_fx = 0.6f * st_fx->mid_dyn_fx + 0.4f * m_mean;*/ - st_fx->mid_dyn_fx = round_fx(L_mac(L_mult(13107,m_mean),19661,st_fx->mid_dyn_fx));/*Q7*/ - } - IF( sub(coder_type,INACTIVE) != 0 ) - { - st_fx->noise_lev_fx = sub((NOISE_LEVEL_SP3+1), usquant_fx(st_fx->mid_dyn_fx, &m_mean, MIN_DYNAMIC_FX, shr(GSF_NF_DELTA_FX,1), GSC_NF_STEPS)); - - st_fx->noise_lev_fx = s_min(st_fx->noise_lev_fx, NOISE_LEVEL_SP3); - } - - st_fx->past_dyn_dec_fx = st_fx->noise_lev_fx; - move16(); - IF( L_sub(st_fx->core_brate_fx,ACELP_8k00) <= 0) - { - st_fx->noise_lev_fx = s_max(st_fx->noise_lev_fx, NOISE_LEVEL_SP2); - push_indice_fx( st_fx, IND_NOISE_LEVEL, sub(st_fx->noise_lev_fx, NOISE_LEVEL_SP2), 2 ); - } - ELSE IF( st_fx->GSC_noisy_speech_fx ) - { - st_fx->noise_lev_fx = NOISE_LEVEL_SP3; - move16(); - } - ELSE - { - push_indice_fx( st_fx, IND_NOISE_LEVEL, sub(st_fx->noise_lev_fx, NOISE_LEVEL_SP0), 3 ); - } - - /*---------------------------------------------------------------* - * Find and encode the last band where the adaptive (pitch) contribution is significant - *---------------------------------------------------------------*/ - - last_pit_bin = Pit_exc_contribution_len_fx( st_fx, dct_res, dct_epit, pitch_buf, nb_subfr, &st_fx->pit_exc_hangover, coder_type, Q_new ); - - IF( last_pit_bin == 0 ) - { - mem->tilt_code = 0; - move16(); - } - ELSE - { - /*last_pit_bin++;*/ - last_pit_bin = add(last_pit_bin,1); - } - - /*--------------------------------------------------------------------------------------* - * GSC encoder - *--------------------------------------------------------------------------------------*/ - - /* Find the current total number of bits used */ - tmp_nb_bits_tot = st_fx->nb_bits_tot_fx; - move16(); - - - if( st_fx->extl_brate_fx > 0 ) - { - /* subtract 1 bit for TBE/BWE BWE flag (bit counted in extl_brate) */ - tmp_nb_bits_tot = sub(tmp_nb_bits_tot,1); - } - test(); - if( sub(coder_type,INACTIVE) == 0 && L_sub(st_fx->core_brate_fx,ACELP_9k60) <= 0 ) - { - /* add 5 bits for noisiness */ - tmp_nb_bits_tot = add(tmp_nb_bits_tot,5); - } - - gsc_enc_fx( st_fx, dct_res, dct_epit, last_pit_bin, tmp_nb_bits_tot, nb_subfr, coder_type, lsf_new, exc_wo_nf, tmp_noise, Q_new ); - - /*--------------------------------------------------------------------------------------* - * iDCT transform - *--------------------------------------------------------------------------------------*/ - - edct_16fx( dct_epit, exc, L_FRAME, 7 ); - edct_16fx( exc_wo_nf, exc_wo_nf, L_FRAME, 7 ); - /*--------------------------------------------------------------------------------------* - * Remove potential pre-echo in case an onset has been detected - *--------------------------------------------------------------------------------------*/ - - pre_echo_att_fx( &st_fx->Last_frame_ener_fx, exc, attack_flag, Q_new - ,st_fx->last_coder_type_fx - ); - - /*--------------------------------------------------------------------------------------* - * Update BWE excitation - *--------------------------------------------------------------------------------------*/ - - set16_fx( voice_factors, 0, NB_SUBFR ); - interp_code_5over2_fx( exc, bwe_exc, L_FRAME ); - - /*--------------------------------------------------------------------------------------* - * Synthesis - *--------------------------------------------------------------------------------------*/ - - p_Aq = Aq; - FOR (i_subfr=0; i_subfrmem_syn, 1 ); - p_Aq += (M+1); - } - - /*--------------------------------------------------------------------------------------* - * Updates - *--------------------------------------------------------------------------------------*/ - - mem->mem_w0 = st_fx->mem_w0_tmp_fx; - move16(); - Copy( exc_wo_nf, exc, L_FRAME ); - - return; -} - -/*================================================================================*/ -/* FUNCTION : void gsc_enc_fx () */ -/*--------------------------------------------------------------------------------*/ -/* PURPOSE : Generic audio signal encoder */ -/*--------------------------------------------------------------------------------*/ -/* INPUT ARGUMENTS : */ -/* _ (Word16) res_dct_in : dct of residual signal Q_exc */ -/* _ (Word16) Diff_len : Lenght of the difference signal Q0 */ -/* _ (Word16) coder_type : coding type Q0 */ -/* _ (Word16) bits_used : Number of bit used before frequency Q Q0 */ -/* _ (Word16) nb_subfr : Number of subframe considered Q0 */ -/* _ (Word16) Qexc : Q format of exc_dct_in */ -/*--------------------------------------------------------------------------------*/ -/* OUTPUT ARGUMENTS : */ -/* _ None */ -/*--------------------------------------------------------------------------------*/ -/* INPUT/OUTPUT ARGUMENTS : */ -/* Encoder_State_fx *st_fx:Encoder State Structure */ -/* _ (Word16[]) exc_dct_in : dctof pitch-only excitation / total excitation Q_exc */ -/*--------------------------------------------------------------------------------*/ -/* RETURN ARGUMENTS : */ -/* _None */ -/*================================================================================*/ - - -static void gsc_enc_fx( - Encoder_State_fx *st_fx, /* i/o: State structure */ - Word16 res_dct_in[], /* i : dct of residual signal */ - Word16 exc_dct_in[], /* i/o: dct of pitch-only excitation / total excitation */ - const Word16 Diff_len, - const Word16 bits_used, - const Word16 nb_subfr, - const Word16 coder_type, - Word16 *lsf_new, /* i : ISFs at the end of the frame */ - Word16 *exc_wo_nf, /* o : excitation (in f domain) without noisefill */ - Word16 *tmp_noise, /* o : noise energy */ - Word16 Q_exc -) -{ - Word16 y2_filt[L_FRAME]; - Word16 exc_diffQ[L_FRAME]; - Word16 exc_diff[L_FRAME]; - Word16 bit,tmp; - Word16 nb_subbands; - Word16 pvq_len, i; - Word16 bits_per_bands[MBANDS_GN]; - Word16 tmp_band; - Word16 concat_in[L_FRAME]; - Word16 concat_out[L_FRAME]; - Word16 max_ener_band[MBANDS_GN], j; - Word16 Ener_per_bd_iQ[MBANDS_GN]; - Word16 last_bin, mean_gain; - Word16 bitallocation_band[MBANDS_GN]; - Word16 bitallocation_exc[2]; - - Word16 inpulses_fx[NB_SFM]; - Word16 imaxpulse_fx[NB_SFM]; - Word16 Q_tmp; - Word16 seed_init; - - set16_fx( inpulses_fx, 0, NB_SFM ); - set16_fx( imaxpulse_fx, 0, NB_SFM ); - - /*--------------------------------------------------------------------------------------* - * Initialization - *--------------------------------------------------------------------------------------*/ - - bit = bits_used; - move16(); - set16_fx( exc_diffQ, 0, L_FRAME ); - set16_fx( y2_filt, 0, L_FRAME ); - - /*--------------------------------------------------------------------------------------* - * Calculate the difference between the residual spectrum and the spectrum of adaptive excitation - * (non valuable temporal content present in exc_dct_in is already zeroed) - *--------------------------------------------------------------------------------------*/ - - Vr_subt( res_dct_in, exc_dct_in, exc_diff, L_FRAME ); - exc_diff[0] = 0; - move16(); - - /*--------------------------------------------------------------------------------------* - * Multiply the difference spectrum with the normalized spectral shape of the residual signal - * This improves the stability of the differnece spectrum since the spectral shape of the - * residual signal is less suseptible to rapid changes than the difference spectrum - *--------------------------------------------------------------------------------------*/ - IF( Diff_len == 0 ) - { - tmp_band = 0; - move16(); - } - ELSE - { - tmp_band = st_fx->mem_last_pit_band_fx; - move16(); - } - - Ener_per_band_comp_fx( exc_diff, Ener_per_bd_iQ, Q_exc, MBANDS_GN, 1 ); - - /*--------------------------------------------------------------------------------------* - * Gain quantizaion - *--------------------------------------------------------------------------------------*/ - - mean_gain = gsc_gainQ_fx( st_fx, Ener_per_bd_iQ, Ener_per_bd_iQ, st_fx->core_brate_fx, coder_type, st_fx->bwidth_fx ); - *tmp_noise = mult_r(320,mean_gain); /*10 in Q5 lp_gainc in Q3 */ - - /*--------------------------------------------------------------------------------------* - * Frequency encoder - *--------------------------------------------------------------------------------------*/ - - bands_and_bit_alloc_fx( st_fx->cor_strong_limit_fx, st_fx->noise_lev_fx, st_fx->core_brate_fx, Diff_len, bit, &bit, Ener_per_bd_iQ, - max_ener_band, bits_per_bands, &nb_subbands, exc_diff, concat_in, &pvq_len, coder_type, st_fx->bwidth_fx, st_fx->GSC_noisy_speech_fx ); - - Q_tmp = Q_exc; - move16(); - - tmp = pvq_core_enc_fx( st_fx, concat_in, concat_out, &Q_tmp, bit, nb_subbands, gsc_sfm_start, gsc_sfm_end, - gsc_sfm_size, bits_per_bands, NULL, inpulses_fx, imaxpulse_fx, ACELP_CORE ); - Scale_sig( concat_out, gsc_sfm_end[nb_subbands-1], sub(Q_PVQ_OUT, Q_tmp) ); - - bit = sub(bit,tmp); - /* write unused bits */ - WHILE( bit > 0 ) - { - i = s_min( bit, 16 ); - push_indice_fx( st_fx, IND_UNUSED, 0, i ); - bit = sub(bit,i); - } - /* Reorder Q bands */ - seed_init = 0; - move16(); - last_bin = 0; - move16(); - set16_fx( bitallocation_band, 0, MBANDS_GN ); - - FOR(j = 0; j < nb_subbands; j++) - { - Copy( concat_out+j*16, exc_diffQ + max_ener_band[j]*16, 16 );/*Q12*/ - - last_bin = s_max(last_bin , max_ener_band[j]); - - bitallocation_band[ max_ener_band[j]] = 1; - move16(); - - seed_init = add(seed_init,inpulses_fx[j]); - move16(); - } - test(); - IF( sub(st_fx->last_coder_type_fx, AUDIO) != 0 /* First audio frame */ - && sub(st_fx->last_coder_type_fx, UNVOICED) != 0 )/* last_coder_type == INACTIVE is overwritten in update_enc to UNVOICED */ - { - FOR( j = 0; j < shl(nb_subbands,4); j++ ) - { - IF( concat_out[j] > 0 ) - { - seed_init = extract_l(L_shl(seed_init,3)); - } - IF( concat_out[j] < 0 ) - { - seed_init = add(seed_init,3); - move16(); - } - } - st_fx->seed_tcx_fx = seed_init; - move16(); - } - test(); - IF( L_sub(st_fx->core_brate_fx,ACELP_8k00) == 0 && sub(st_fx->bwidth_fx,NB) != 0 ) - { - bitallocation_exc[0] = 0; - move16(); - bitallocation_exc[1] = 0; - move16(); - if( exc_diffQ[L_FRAME8k - 2] != 0 ) - { - bitallocation_exc[0] = 1; - move16(); - } - if( exc_diffQ[L_FRAME8k - 1] != 0 ) - { - bitallocation_exc[1] = 1; - move16(); - } - } - - /*--------------------------------------------------------------------------------------* - * Skip adaptive (pitch) contribution frequency band (no noise added over the adaptive (pitch) contribution) - * Find x pulses between 1.6-3.2kHz to code in the spectrum of the residual signal - * Gain is based on the inter-correlation gain between the pulses found and residual signal - *--------------------------------------------------------------------------------------*/ - - freq_dnw_scaling_fx( st_fx->cor_strong_limit_fx, coder_type, st_fx->noise_lev_fx, st_fx->core_brate_fx, exc_diffQ, Q_PVQ_OUT ); - - /*--------------------------------------------------------------------------------------* - * Estimate noise level - *--------------------------------------------------------------------------------------*/ - - highband_exc_dct_in_fx( st_fx->core_brate_fx, mfreq_bindiv_loc_fx, last_bin, Diff_len, st_fx->noise_lev_fx, tmp_band, exc_diffQ, - &st_fx->seed_tcx_fx, Ener_per_bd_iQ, nb_subfr, exc_dct_in, st_fx->last_coder_type_fx, bitallocation_band, lsf_new, - st_fx->last_exc_dct_in_fx, &st_fx->last_ener_fx, st_fx->last_bitallocation_band_fx, bitallocation_exc, 0, coder_type, - st_fx->bwidth_fx, exc_wo_nf, Q_PVQ_OUT, Q_exc, st_fx->GSC_noisy_speech_fx, NULL ); - - exc_dct_in[0] = 0; - move16(); - - return; -} - -/*======================================================================*/ -/* FUNCTION : edyn_fx() */ -/*----------------------------------------------------------------------*/ -/* PURPOSE : Calculate energy dynamics in a vector */ -/* (ratio of energy maximum to energy mean) */ -/* */ -/*----------------------------------------------------------------------*/ -/* INPUT ARGUMENTS : */ -/* _ (Word16 *) vec : ratio of max to mean Qnew */ -/* _ (Word16) lvec : input vector */ -/* _ (Word16) Q_new : */ -/*-----------------------------------------------------------------------*/ -/* OUTPUT ARGUMENTS : */ -/* _ (Word16) dyn : ratio of energy maximum to energy mean (Q7) */ -/*-----------------------------------------------------------------------*/ - -/*-----------------------------------------------------------------------*/ -/* RETURN ARGUMENTS : */ -/* _ None */ -/*=======================================================================*/ - -static Word16 edyn_fx( /* o : ratio of max to mean */ - const Word16 *vec, /* i : input vector */ - const Word16 lvec, /* i : length of input vector */ - Word16 Qnew -) -{ - Word16 j=0; - Word16 dyn; - Word32 L_tmp, ener_max, ener_mean; - Word16 tmp,exp2,tmp2,tmp1,exp1,exp3; - Word16 scale; - - ener_mean = L_shl(1,shl(Qnew,1)); /*2*Qnew*/ - ener_max = L_shl(1,shl(Qnew,1)); - - FOR( j=0; j 0) - { - exp1 = norm_l(ener_mean); - tmp1 = round_fx(L_shl(ener_mean,exp1)); - exp1 = sub(30,exp1); - - exp2 = norm_l(ener_max); - tmp2 = extract_h(L_shl(ener_max,exp2)); - exp2 = sub(30,exp2); - - scale = shr(sub(tmp1, tmp2), 15); - tmp2 = shl(tmp2, scale); - exp2 = sub(exp2, scale); - - exp3 = sub(exp1,exp2); - - tmp = div_s(tmp2, tmp1); /*Q(15+exp3)*/ - - L_tmp = L_shr_r(L_mult(tmp,10),exp3); - dyn = round_fx(L_shl(L_tmp,7)); /*Q7*/ - } - ELSE - { - dyn = 1280; - move16(); - } - return dyn; - -} diff --git a/src/libs/libevs/lib_enc/guided_plc_enc.cpp b/src/libs/libevs/lib_enc/guided_plc_enc.cpp old mode 100755 new mode 100644 index 141f1e45..aa5aeb4c --- a/src/libs/libevs/lib_enc/guided_plc_enc.cpp +++ b/src/libs/libevs/lib_enc/guided_plc_enc.cpp @@ -1,241 +1,151 @@ /*==================================================================================== - EVS Codec 3GPP TS26.442 Apr 03, 2018. Version 12.11.0 / 13.6.0 / 14.2.0 + EVS Codec 3GPP TS26.443 Nov 13, 2018. Version 12.11.0 / 13.7.0 / 14.3.0 / 15.1.0 ====================================================================================*/ - -#include "stl.h" -#include "prot_fx.h" -#include "stat_dec_fx.h" -#include "basop_util.h" +#include "stat_enc.h" +#include "prot.h" -/************************************************************/ -/* Macro for the functions to be implemented. */ -/************************************************************/ +/*-------------------------------------------------------------------* +* coderLookAheadInnovation() +* +* +*-------------------------------------------------------------------*/ void coderLookAheadInnovation( - Word16 A_3Q12[], /* input: coefficients NxAz[M+1] */ - Word16 *pT, /* out: pitch */ - HANDLE_PLC_ENC_EVS st, /* i/o: coder memory state */ - Word16 *speechLookAhead_Qx, /* i: input speech in Q(st->Qold) */ - Word16 *old_exc, /* i: input excitation in Q(st->Qold) */ - Word16 L_frame + const float A[], /* input: coefficients NxAz[M+1] */ + int *pT, /* out: pitch */ + HANDLE_PLC_ENC_EVS st, /* i/o: coder memory state */ + float *speechLookAhead, + float *old_exc, + int L_subfr, + int L_frame ) { - Word16 i; - Word16 prev_pitch, T0_fx; - Word16 *exc_Qx, exc_buf_Qx[L_EXC_MEM+2*L_SUBFR+8]; - Word32 mantissa_max = -0x7fffffffL; - Word16 subfr_len = 0; - Word16 search_range = 9; - Word16 exc_max; - Word16 exc_sh; - Word32 ps,alp, alp_ini; - Word32 alp_s1, alp_s2; - Word16 k; - Word16 ps_e,alp_e; - Word32 max_ps, max_ps_tmp; - Word16 max_ps_e; - Word16 tmp_loop; + int i; + float *exc, exc_buf[L_EXC_MEM+2*L_SUBFR+8] = { 0.0f }; + int T0=0; + short prev_pitch; + float ps, alp, max_ps; + short subfr_len; + short search_range; - /* Debug init (not instrumented) */ - T0_fx = -3000; - subfr_len = shl(L_SUBFR,1); /* 2*L_SUBFR */ - if( sub( L_FRAME16k, L_frame ) > 0 ) + search_range = 9; + + /* Framing parameters */ + if( L_frame < L_FRAME16k ) { - subfr_len = add(L_SUBFR,48); /* 1.75*L_SUBFR */ + subfr_len = (short)(1.75*L_subfr); + } + else + { + subfr_len = (short)(2*L_subfr); } /*------------------------------------------------------------------------* - * - BASOP specific initialization. * + * Initialize buffers * *------------------------------------------------------------------------*/ - /* initialization */ - exc_Qx = exc_buf_Qx + L_EXC_MEM + 8; - FOR( i=0; iT0_4th; - move16(); + /* find target signals */ /* find best candidate of pitch lag */ - T0_fx = st->T0_4th; - move16(); - mantissa_max = -0x7fffffffL; - move32(); - max_ps = -0x7fffffffL; - move32(); - max_ps_e = 16; - move16(); - - /*find maximum*/ - exc_max = 0; - move16(); - tmp_loop = s_min(-prev_pitch+search_range+subfr_len,0); - FOR(i=-prev_pitch-search_range; i < tmp_loop; i++) { - exc_max = s_max(exc_Qx[i],exc_max); - } - FOR(i= 0; ipit_max)>0 || sub(add(prev_pitch,i),st->pit_min)<0 ) + max_ps = -1.0e10; + T0 = st->T0_4th; + for( i=-search_range; ist->pit_max || prev_pitch+ipit_min ) + { + continue; + } + ps = dotp( exc, &exc[-(prev_pitch+i)], subfr_len ); + alp = dotp( &exc[-(prev_pitch+i)], &exc[-(prev_pitch+i)], subfr_len ); + ps /= (float)sqrt( alp + 1.0e-10 ); + if( max_ps < ps ) + { + max_ps = ps; + T0 = prev_pitch + i; + } } - ps = L_deposit_l(0); - alp_s1 = L_deposit_l(0); - alp_s2 = L_deposit_l(0); - - FOR(k=0; kT0_4th; } - - /*calculate "small" dotproducts in order to subtract them from the "bigger" one*/ - FOR(k=negate(add(prev_pitch,search_range)); k<-prev_pitch-i; k++) - { - alp_s1 = L_mac(alp_s1,exc_Qx[k],exc_Qx[k]); - } - tmp_loop = sub(add(search_range,subfr_len) ,prev_pitch); - FOR(k = + subfr_len - i -prev_pitch ; k < tmp_loop; k++) - { - alp_s2 = L_mac(alp_s2,exc_Qx[k],exc_Qx[k]); - } - alp = L_sub(alp_ini,L_add(alp_s1,alp_s2)); - alp = L_max(alp, 1); /* alp must not be 0 */ - alp_e = shl(exc_sh,1); - ps_e = shl(exc_sh,1); - alp = ISqrt32(alp, &alp_e); - ps = Mpy_32_16_1(ps,round_fx(alp)); /*alp_e+ps_e*/ - - ps_e = add(alp_e,ps_e); - - BASOP_SATURATE_WARNING_OFF - max_ps_tmp = L_shl(max_ps,sub(max_ps_e,ps_e)); - BASOP_SATURATE_WARNING_ON - - - IF (L_sub(max_ps_tmp , ps) < 0) - { - max_ps = L_add(ps, 0); - max_ps_e = ps_e; - move16(); - T0_fx = add(prev_pitch,i); - } - - } - mantissa_max = max_ps; - move32(); - if( mantissa_max < 0 ) - { - T0_fx = st->T0_4th; - move16(); } - /* Update excitation */ - pT[0] = T0_fx; - move16(); + pT[0] = T0; return; } -/************************************************************/ -/* Static functions */ -/************************************************************/ -void enc_prm_side_Info( HANDLE_PLC_ENC_EVS hPlc_Ext, Encoder_State_fx *st ) -{ - Word16 diff_pitch; - Word16 bits_per_subfr, search_range; - bits_per_subfr = 4; - move16(); - search_range = 8; - move16(); +/*-------------------------------------------------------------------* +* enc_prm_side_Info() +* +* +*-------------------------------------------------------------------*/ - IF( sub(hPlc_Ext->nBits,1)>0 ) - { - - push_next_indice_fx(st, 1, 1); - - diff_pitch = sub(hPlc_Ext->T0, hPlc_Ext->T0_4th); - test(); - if( (sub(diff_pitch,sub(search_range,1)) > 0) || (sub(diff_pitch,add(-search_range,1)) < 0) ) - { - diff_pitch = -8; - move16(); - } - - push_next_indice_fx(st, add(diff_pitch, search_range), bits_per_subfr); - } - ELSE - { - push_next_indice_fx(st, 0, 1); - } - - return; -} - -/************************************************************/ -/* Functions for encoder side loss simulation */ -/************************************************************/ -void encoderSideLossSimulation( - Encoder_State_fx *st, +void enc_prm_side_Info( HANDLE_PLC_ENC_EVS hPlc_Ext, - Word16 *lsf_q, /* Q1*1.28 */ - Word16 stab_fac, /* Q15 */ - Word8 calcOnlyISF, - const Word16 L_frame + Encoder_State *st ) { - Word16 lspLocal_Q15[M]; - Word16 const* xsfBase; /* base for differential XSF coding */ + int diff_pitch; + short bits_per_subfr, search_range; + bits_per_subfr = 4; + search_range = 8; + + if( hPlc_Ext->nBits > 1 ) + { + push_next_indice(st, 1, 1); + + diff_pitch = hPlc_Ext->T0 - hPlc_Ext->T0_4th; + + if( ( diff_pitch > search_range-1 ) || ( diff_pitch < -search_range+1 ) ) + { + diff_pitch = -8; + } + + push_next_indice(st, (diff_pitch+search_range), bits_per_subfr); + } + else + { + push_next_indice(st, 0, 1); + } + + return; +} + +/*-------------------------------------------------------------------* +* encoderSideLossSimulation() +* +* Encoder side loss simulation +*-------------------------------------------------------------------*/ + +void encoderSideLossSimulation( + Encoder_State *st, + HANDLE_PLC_ENC_EVS hPlc_Ext, + float *lsf_q, + float stab_fac, + int calcOnlylsf, + int L_frame +) +{ + float lspLocal[M]; + float const* lsfBase; /* base for differential lsf coding */ /************************************************************* * Decoder state could be stored with memcpy, @@ -243,203 +153,215 @@ void encoderSideLossSimulation( *************************************************************/ /* Decoder State Update */ - IF( sub(L_frame,L_FRAME_16k)==0 ) + lsf2lsp( lsf_q, lspLocal, M, st->sr_core ); + + lsfBase = PlcGetlsfBase( st->lpcQuantization, st->narrowBand, st->sr_core ); + + mvr2r( st->mem_MA, hPlc_Ext->mem_MA, M ); + + /* lsf parameter processing for concealment */ + updatelsfForConcealment( hPlc_Ext, lsf_q); + hPlc_Ext->stab_fac = stab_fac; + + /* Update Decoder State for the loss simulation at the next frame */ + mvr2r( lsf_q, hPlc_Ext->lsfold, M ); + mvr2r( lspLocal, hPlc_Ext->lspold, M ); + + if (calcOnlylsf) { - lsf2lsp_fx( lsf_q, lspLocal_Q15, M, INT_FS_16k_FX ); - } - ELSE - { - lsf2lsp_fx( lsf_q, lspLocal_Q15, M, INT_FS_FX ); - } - - - xsfBase = PlcGetLsfBase (st->lpcQuantization, - st->narrowBand, - st->sr_core); - - Copy( st->mem_MA_fx, hPlc_Ext->mem_MA_14Q1, M ); - Copy( st->mem_AR_fx, hPlc_Ext->mem_AR, M ); - - - /* ISF parameter processing for concealment */ - updateLSFForConcealment( hPlc_Ext, lsf_q, M ); - hPlc_Ext->stab_fac_Q15 = stab_fac; - move16(); - - Copy( lsf_q, hPlc_Ext->lsfold_14Q1, M ); - Copy( lspLocal_Q15, hPlc_Ext->lspold_Q15, M ); - - - IF (calcOnlyISF != 0) - { - /* ISF concealment simulation */ - getConcealedLSF( hPlc_Ext, xsfBase, st->clas_fx, L_frame ); + /* lsf concealment simulation */ + getConcealedlsf( hPlc_Ext, lsfBase, L_frame, st->clas); hPlc_Ext->T0 = hPlc_Ext->T0_4th; - move16(); } - ELSE + else { - Word16 old_exc_Qx[L_EXC_MEM+8]; - Word16 A_3Q12[(NB_SUBFR16k+1)*(M+1)]; - Word16 *speechLookAhead_Qx; + float AqCon[(NB_SUBFR16k+1)*(M+1)]; + float *speechLookAhead; + float old_exc[L_EXC_MEM+8]; - /* calculate Q-value for input speech */ - speechLookAhead_Qx = &(st->speech_enc_pe[L_frame]); + /* Initialize pointers here */ + mvr2r( hPlc_Ext->old_exc, old_exc, 8 ); + mvr2r( hPlc_Ext->LPDmem->old_exc, &old_exc[8], L_EXC_MEM ); + speechLookAhead = &( st->speech_enc_pe[L_frame] ); - Copy( hPlc_Ext->old_exc_Qold, old_exc_Qx, 8 ); - Copy( hPlc_Ext->LPDmem->old_exc, &old_exc_Qx[8], L_EXC_MEM ); - Scale_sig( old_exc_Qx, 8, hPlc_Ext->Q_exp ); - - /* ISF concealment simulation */ - getConcealedLP( hPlc_Ext, A_3Q12, xsfBase, st->clas_fx, L_frame ); + /* lsf concealment simulation */ + getConcealedLP( hPlc_Ext, AqCon, lsfBase, st->sr_core, st->clas, L_frame); /* apply encoder side PLC simulation */ hPlc_Ext->pit_min = st->pit_min; - move16(); hPlc_Ext->pit_max = st->pit_max; - move16(); - coderLookAheadInnovation( A_3Q12, &(hPlc_Ext->T0), hPlc_Ext, speechLookAhead_Qx, old_exc_Qx, L_frame ); + coderLookAheadInnovation( AqCon, &(hPlc_Ext->T0), hPlc_Ext, speechLookAhead, old_exc, L_SUBFR, st->L_frame ); + } + return; } +/*-------------------------------------------------------------------* +* GplcTcxEncSetup() +* +* +*-------------------------------------------------------------------*/ -void GplcTcxEncSetup( Encoder_State_fx *st, HANDLE_PLC_ENC_EVS hPlc_Ext, Word16 Q_new ) +void GplcTcxEncSetup( + Encoder_State *st, + HANDLE_PLC_ENC_EVS hPlc_Ext) { hPlc_Ext->T0_4th = st->tcxltp_pitch_int; - move16(); - hPlc_Ext->Q_exp = sub( Q_new, hPlc_Ext->Q_new); - move16(); - hPlc_Ext->Q_new = Q_new; - move16(); - set16_fx( hPlc_Ext->old_exc_Qold, 0, 8); + + return; } -Word16 encSideSpecPowDiffuseDetector( - Word16 *lsf_ref, - Word16 *lsf_con, - Word32 sr_core, - Word16 *prev_lsf4_mean, - Word8 sw - , Word16 coder_type +/*-------------------------------------------------------------------* +* encSideSpecPowDiffuseDetector() +* +* +*-------------------------------------------------------------------*/ + +short encSideSpecPowDiffuseDetector( + float *lsf_ref, + float *lsf_con, + int sr_core, + float *prev_lsf4_mean, + short sw + ,short coder_type ) { - Word16 tmp; - Word16 lsf_mod[M]; - Word32 dist1, dist2, cum_dist1, cum_dist2; - Word16 lsf4_mean; - Word16 th; - Word16 idx; - Word16 cnt_imprv, i; - Word32 L_tmp; - Word16 th_dif; + float lsf_mod[M]; + float dist1, dist2, cum_dist1, cum_dist2; + float lsf4_mean; + float th; + float th_dif_lsf4_mean; + short idx; + int cnt_imprv, i; - /* calculate the mean of the lowest 4 LSFs */ + /* calculate the mean of the lowest 4 lsfs */ + lsf4_mean = 0; - L_tmp = L_mult(lsf_ref[0], 8192/*1.0/4.0 Q15*/); - L_tmp = L_mac(L_tmp, lsf_ref[1], 8192/*1.0/4.0 Q15*/); - L_tmp = L_mac(L_tmp, lsf_ref[2], 8192/*1.0/4.0 Q15*/); - lsf4_mean = mac_r(L_tmp, lsf_ref[3], 8192/*1.0/4.0 Q15*/); - - IF(sw) + for(i = 0; i < 4; i++) { - Copy(lsf_con, lsf_mod, M); + lsf4_mean += lsf_ref[i]; + } + lsf4_mean /= 4.0f; - modify_lsf(lsf_mod, M, sr_core, 1 ); + if(sw) + { + mvr2r( lsf_con, lsf_mod, M ); + + modify_lsf( lsf_mod, M, sr_core + , 1 + ); - move16(); - move16(); cum_dist1 = 0; cum_dist2 = 0; cnt_imprv = 0; - IF( L_sub( sr_core, 16000 ) == 0 ) - { - th = 2560; - move16(); /* LSF */ - th_dif = 288; - move16(); /* LSF */ - } - ELSE - { - th = 2048; - move16(); /* LSF */ - th_dif = 230; - move16(); /* LSF */ - } - FOR(i = 0; i < M; i++) + for(i = 0; i < M; i++) { - tmp = sub(lsf_con[i], lsf_ref[i]); - dist1 = L_mult(tmp, tmp); - tmp = sub(lsf_mod[i], lsf_ref[i]); - dist2 = L_mult(tmp, tmp); + dist1 = (lsf_con[i] - lsf_ref[i]) * (lsf_con[i] - lsf_ref[i]); + dist2 = (lsf_mod[i] - lsf_ref[i]) * (lsf_mod[i] - lsf_ref[i]); + cum_dist1 += dist1; + cum_dist2 += dist2; - if(L_sub(dist1, dist2) > 0) + if(dist1 > dist2) { - cnt_imprv = add(cnt_imprv, 1); + cnt_imprv++; } - cum_dist1 = L_add(cum_dist1, dist1); - cum_dist2 = L_add(cum_dist2, dist2); } - idx = 0; - move16(); + th = 800; + th_dif_lsf4_mean = 90; - test(); - test(); - test(); - if(L_sub(cum_dist1, L_add(cum_dist2, Mpy_32_16_1(cum_dist2, 4915))) > 0 - && sub(sub(lsf4_mean, *prev_lsf4_mean), th_dif) > 0 - && sub(*prev_lsf4_mean, th) < 0 - && sub(cnt_imprv, 2) > 0 - && sub(coder_type, GENERIC) == 0 ) + if(sr_core == 16000) + { + th *= 1.25; + th_dif_lsf4_mean *= 1.25; + } + + + if(cum_dist1 > cum_dist2 * 1.15 + && lsf4_mean - *prev_lsf4_mean > th_dif_lsf4_mean + && *prev_lsf4_mean < th + && cnt_imprv > 2 + && coder_type == GENERIC + ) { idx = 1; - move16(); } - + else + { + idx = 0; + } } - ELSE + else { - move16(); idx = 0; } + /* update parameters */ - move16(); *prev_lsf4_mean = lsf4_mean; return idx; } -void updateSpecPowDiffuseIdx( Encoder_State_fx *st) +/*-------------------------------------------------------------------* +* updateSpecPowDiffuseIdx() +* +* +*-------------------------------------------------------------------*/ + +void updateSpecPowDiffuseIdx( + Encoder_State *st, + const float gain_pitch_buf[], /* i : gain pitch values */ + const float gain_code_buf[] /* i : gain pitch values */ +) { - Word16 min_gp; - Word16 k; + float min_gp; + int k; + st->mean_gc[1] = gain_code_buf[0]; + min_gp = gain_pitch_buf[0]; - move32(); - move16(); - st->mean_gc[1] = st->gain_code[0]; - min_gp = st->bpf_gainT[0]; - - FOR(k = 1; k < 4; k++) + for(k = 1; k < 4; k++) { - st->mean_gc[1] = L_add(st->mean_gc[1], st->gain_code[k]); - min_gp = s_min(min_gp, st->bpf_gainT[k]); + st->mean_gc[1] += gain_code_buf[k]; + + if( gain_pitch_buf[k] < min_gp ) + { + min_gp = gain_pitch_buf[k]; + } } - /* Suppress saturation warning in threshold comparison. */ - test(); - if(L_sub(st->mean_gc[1], L_add(st->mean_gc[0], Mpy_32_16_r(st->mean_gc[0], 3211/*0.098 Q15*/))) < 0 || - sub(min_gp, 13435/*0.82 Q14*/) > 0) + if(st->mean_gc[1] / (st->mean_gc[0] + 1e-6) < 1.098 || min_gp > 0.82) { - move16(); st->glr_idx [0]= 0; } - move16(); st->mean_gc[0] = st->mean_gc[1]; + return; } + +/*-------------------------------------------------------------------* +* getConcealedlsf() +* +* +*-------------------------------------------------------------------*/ + +void getConcealedlsf( + HANDLE_PLC_ENC_EVS memDecState, + const float lsfBase[], + int L_frame, + int last_good +) +{ + float *lsf = memDecState->lsf_con; + + dlpc_bfi( L_frame, &lsf[0], memDecState->lsfold, last_good, + 1 /*assumes packet loss */, memDecState->mem_MA, memDecState->mem_AR, &(memDecState->stab_fac), memDecState->lsf_adaptive_mean, + 1, NULL, 0, NULL, NULL, lsfBase); + + return; +} diff --git a/src/libs/libevs/lib_enc/hf_cod_amrwb.cpp b/src/libs/libevs/lib_enc/hf_cod_amrwb.cpp new file mode 100644 index 00000000..f8918643 --- /dev/null +++ b/src/libs/libevs/lib_enc/hf_cod_amrwb.cpp @@ -0,0 +1,307 @@ +/*==================================================================================== + EVS Codec 3GPP TS26.443 Nov 13, 2018. Version 12.11.0 / 13.7.0 / 14.3.0 / 15.1.0 + ====================================================================================*/ + +#include +#include "options.h" +#include "cnst.h" +#include "prot.h" +#include "rom_com.h" + +/*---------------------------------------------------------------------* + * Local functions + *---------------------------------------------------------------------*/ + +static void hp400_12k8(float signal[], const short lg, float mem[]); +static void filt_6k_8k(float signal[], const short lg, float mem[]); + +/*---------------------------------------------------------------------* + * hf_cod_init() + * + * + *---------------------------------------------------------------------*/ + +void hf_cod_init( + float *mem_hp400_enc, /* o: memory of hp 400 Hz filter */ + float *mem_hf1_enc, /* o: HF band-pass filter memory */ + float *mem_syn_hf_enc, /* o: HF synthesis memory */ + float *mem_hf2_enc, /* o: HF band-pass filter memory */ + float *gain_alpha /* o: smoothing gain for transitions between active and inactive frames */ +) +{ + set_f( mem_hp400_enc, 0, 4 ); + set_f( mem_hf1_enc, 0, L_FIR-1 ); + set_f( mem_syn_hf_enc, 0, M ); + set_f( mem_hf2_enc, 0, L_FIR-1 ); + *gain_alpha = 1.0; + + return; +} + + +/*---------------------------------------------------------------------* + * hf_cod() + * + * + *---------------------------------------------------------------------*/ + +void hf_cod( + const long core_brate, /* i : core bitrate */ + const float *speech16k, /* i : original speech at 16 kHz */ + const float Aq[], /* i : quantized Aq */ + const float exc[], /* i : excitation at 12.8 kHz */ + float synth[], /* i : 12.8kHz synthesis signal */ + short *seed2_enc, /* i/o: random seed for HF noise gen */ + float *mem_hp400_enc, /* i/o: memory of hp 400 Hz filter */ + float *mem_syn_hf_enc, /* i/o: HF synthesis memory */ + float *mem_hf1_enc, /* i/o: HF band-pass filter memory */ + float *mem_hf2_enc, /* i/o: HF band-pass filter memory */ + const short *dtxHangoverCount, + float *gain_alpha, /* i/o: smoothing gain for transitions between active and inactive frames */ + short *hf_gain /* o : HF gain to be transmitted to decoder */ +) +{ + short i; + float ener_hf, ener_exc, ener_input, fac, HF_syn[L_SUBFR16k], tmp, ener, scale; + float Ap[M16k+1]; + float HF_SP[L_SUBFR16k]; + float HF_est_gain; + float HF_calc_gain; + float HF_corr_gain; + short HF_gain_ind; + float dist_min, dist; + float HF[L_SUBFR16k]; /* o : HF excitation */ + + /* Original speech signal as reference for high band gain quantisation */ + for (i = 0; i < L_SUBFR16k; i++) + { + HF_SP[i] = speech16k[i]; + } + + /*-----------------------------------------------------------------* + * generate white noise vector + *-----------------------------------------------------------------*/ + + for (i=0; i 1.0f) /* this condition is not in G.722.2, but in AMR-WB!*/ + { + HF_est_gain = 1.0f; + } + + /*-----------------------------------------------------------------* + * synthesis of noise: 4.8kHz..5.6kHz --> 6kHz..7kHz + *-----------------------------------------------------------------*/ + + weight_a( Aq, Ap, 0.6f, M ); + syn_filt( Ap, M, HF, HF_syn, L_SUBFR16k, mem_syn_hf_enc, 1 ); + + /*-----------------------------------------------------------------* + * high pass filtering (0.9375ms of delay = 15 samples@16k) + *-----------------------------------------------------------------*/ + + filt_6k_8k( HF_syn, L_SUBFR16k, mem_hf1_enc ); + + /* filtering of the original signal */ + filt_6k_8k( HF_SP, L_SUBFR16k, mem_hf2_enc ); + + /* check the gain difference */ + ener_input = 0.01f; + ener_hf = 0.01f; + for ( i=0; i 6) + { + *gain_alpha = 1.0f; + } + + HF_corr_gain = (*gain_alpha)*HF_calc_gain + (1.0f-(*gain_alpha))*HF_est_gain; + HF_corr_gain /= 2.0f; /* to stay in alignlent with AMR-WB legacy decoder where decoded gain is multiplied by 2 */ + + /* Quantize the correction gain */ + dist_min = 100000.0f; + HF_gain_ind = 0; + for ( i = 0; i < 16; i++ ) + { + dist = (HF_corr_gain-HP_gain[i])*(HF_corr_gain-HP_gain[i]); + if (dist_min > dist) + { + dist_min = dist; + HF_gain_ind = i; + } + } + + *hf_gain = HF_gain_ind; + + return; +} + +/*-----------------------------------------------------------------------* + * Function hp400_12k8() * + * * + * 2nd order Cheb2 high pass filter with cut off frequency at 400 Hz. * + * Optimized for fixed-point to get the following frequency response : * + * * + * frequency : 0Hz 100Hz 200Hz 300Hz 400Hz 630Hz 1.5kHz 3kHz * + * dB loss : -infdB -30dB -20dB -10dB -3dB +6dB +1dB 0dB * + * * + * Algorithm : * + * * + * y[i] = b[0]*x[i] + b[1]*x[i-1] + b[2]*x[i-2] * + * + a[1]*y[i-1] + a[2]*y[i-2]; * + * * + * short b[3] = {3660, -7320, 3660}; in Q12 * + * short a[3] = {4096, 7320, -3540}; in Q12 * + * * + * float --> b[3] = {0.893554687, -1.787109375, 0.893554687}; * + * a[3] = {1.000000000, 1.787109375, -0.864257812}; * + *-----------------------------------------------------------------------*/ + +static void hp400_12k8( + float signal[], /* i/o: signal */ + const short lg, /* i : lenght of signal */ + float mem[] /* i/o: filter memory [4] */ +) +{ + short i; + float x0, x1, x2; + float yy0, yy1, y2; + + yy1 = mem[0]; + y2 = mem[1]; + x0 = mem[2]; + x1 = mem[3]; + for(i=0; i=0 ) - { - tmp_fx = shr(tmp_fx, 1); - q2 = sub(q2, 1); - } - - sign = 0; - move16(); - IF ( tmp_fx < 0 ) - { - tmp_fx = abs_s(tmp_fx); - sign = 1; - move16(); - } - - fac_fx = div_s(tmp_fx, ener_fx); /*Q(15+q2-q1) */ - shift = sub(q1, add(q2, 5)); - fac_fx = shl(fac_fx, shift); /*Q10 */ - IF (sign) - { - fac_fx = s_xor(fac_fx, -1); - } - - HF_est_gain_fx = sub(1024, fac_fx); /*Q12 */ - - test(); - IF( L_sub(core_brate_fx, SID_1k75) == 0 || core_brate_fx == FRAME_NO_DATA ) - { - HF_est_gain_fx = round_fx(L_shl(L_mult(HF_est_gain_fx, 20480), 1)); /*Q10 */ - } - - HF_est_gain_fx = s_max(HF_est_gain_fx, 102); - HF_est_gain_fx = s_min(HF_est_gain_fx, 1024); - - /*-----------------------------------------------------------------* - * synthesis of noise: 4.8kHz..5.6kHz --> 6kHz..7kHz - *-----------------------------------------------------------------*/ - - weight_a_lc_fx( Aq_fx, Ap_fx, Gamma_19661_Tbl_fx, M ); - Syn_filt_s( 0, Ap_fx, M, HF_fx, HF_syn_fx, L_SUBFR16k, mem_syn_hf_enc_fx, 1 ); /*Q0 */ - - /*-----------------------------------------------------------------* - * high pass filtering (0.9375ms of delay = 15 samples@16k) - *-----------------------------------------------------------------*/ - - fir_fx(HF_syn_fx, fir_6k_8k_fx, HF_syn_fx, mem_hf1_enc_fx, L_SUBFR16k, L_FIR-1, 1, 0); - fir_fx(HF_SP_fx, fir_6k_8k_fx, HF_SP_fx, mem_hf2_enc_fx, L_SUBFR16k, L_FIR-1, 1, 0); - - /* check the gain difference */ - - ener_hf_fx = dot_prod_satcontr(HF_syn_fx, HF_syn_fx, 0, 0, &q2, L_SUBFR16k); - ener_input_fx = dot_prod_satcontr(HF_SP_fx, HF_SP_fx, 0, 0, &q1, L_SUBFR16k); - - HF_calc_gain_fx = div_s(shl(1, 14), ener_input_fx); /*Q(29-q1) */ - L_tmp = L_mult(ener_hf_fx, HF_calc_gain_fx); /*30-q1+q2 */ - q2 = sub(q1, q2); /*30-q2 */ - HF_calc_gain_fx = round_fx(Isqrt(L_shl(L_tmp, sub(q2, 20)))); /*Q10 */ - - - /* set energy of HF synthesis to energy of original HF: - cross-fade between HF levels in active and inactive frame in hangover period */ - - IF ( sub(4, dtxHangoverCount_fx) > 0 ) - { - *gain_alpha_fx = 16384; - move16(); - } - ELSE - { - L_tmp = L_shl(L_mult(sub(10, dtxHangoverCount_fx), 4681), 15);/*Q31 */ - L_tmp = Mult_32_16(L_tmp, *gain_alpha_fx); /*Q30 */ - *gain_alpha_fx = round_fx(L_tmp); /*Q14 */ - } - L_tmp = L_mult(sub(16384, *gain_alpha_fx), HF_est_gain_fx); /*Q25 */ - L_tmp = L_mac(L_tmp, *gain_alpha_fx, HF_calc_gain_fx); /*Q25 */ - IF (L_sub(L_tmp,67108863) >= 0 ) - { - L_tmp = 67108863; - move32(); - } - L_tmp = L_shl(L_tmp, 5); - HF_corr_gain_fx = extract_h(L_tmp); /*Q14; HF_corr_gain_fx/2 in Q15 */ - - /* Quantize the correction gain */ - dist_min_fx = 2147483647; - move32(); - HF_gain_ind_fx = 0; - move16(); - pt2 = HP_gain_fx; - FOR ( i = 0; i < 16; i++ ) - { - dist_fx = L_mult(sub(HF_corr_gain_fx, *pt2), sub(HF_corr_gain_fx, *pt2)); - pt2++; - IF ( L_sub(dist_min_fx, dist_fx) > 0 ) - { - dist_min_fx = L_add(dist_fx, 0); - HF_gain_ind_fx = i; - move16(); - } - } - *hf_gain_fx = HF_gain_ind_fx; - move16(); - - return; -} diff --git a/src/libs/libevs/lib_enc/hq_classifier_enc.cpp b/src/libs/libevs/lib_enc/hq_classifier_enc.cpp new file mode 100644 index 00000000..cbfc7db9 --- /dev/null +++ b/src/libs/libevs/lib_enc/hq_classifier_enc.cpp @@ -0,0 +1,502 @@ +/*==================================================================================== + EVS Codec 3GPP TS26.443 Nov 13, 2018. Version 12.11.0 / 13.7.0 / 14.3.0 / 15.1.0 + ====================================================================================*/ + +#include +#include "options.h" +#include "cnst.h" +#include "prot.h" +#include "rom_com.h" + +/*-----------------------------------------------------------------* + * Local constants + *-----------------------------------------------------------------*/ + +#define SHARP_DIST_THRES 22.2f + +/*-----------------------------------------------------------------* + * Local functions + *-----------------------------------------------------------------*/ + +static void hvq_classifier( const float *input, short *prev_Npeaks, short *prev_peaks, + short *hqswb_clas, short *Npeaks, short *peaks, const long core_brate, + const short last_core, float *nf_gains, short *hvq_hangover, float *pe_gains ); + +/*--------------------------------------------------------------------------* + * hq_classifier_enc() + * + * HQ mode selector (decision_matrix) + *--------------------------------------------------------------------------*/ + +short hq_classifier_enc( /* o : Consumed bits */ + Encoder_State *st, /* i/o: encoder state structure */ + const short length, /* i : Frame length */ + const float *coefs, /* i : Spectral coefficients */ + const short is_transient, /* i : Transient flag */ + short *Npeaks, /* o : Number of identified peaks */ + short *peaks, /* o : Peak indices */ + float *pe_gains, /* o : Peak gains */ + float *nf_gains, /* o : Noise-fill gains */ + short *hqswb_clas /* o : HQ class */ +) +{ + short bits; + + *hqswb_clas = HQ_NORMAL; + if( is_transient ) + { + *hqswb_clas = HQ_TRANSIENT; + } + else if( length == L_FRAME32k && st->core_brate <= HQ_32k && st->bwidth == st->last_bwidth ) + { + /* Detect HQ_HARMONIC mode */ + *hqswb_clas = peak_avrg_ratio( st->total_brate, coefs, NUMC_N+96, &st->mode_count, &st->mode_count1 ); + + /* Detect HQ_HVQ mode */ + hvq_classifier( coefs, &st->prev_Npeaks, st->prev_peaks, hqswb_clas, Npeaks, peaks, st->core_brate, st->last_core, + nf_gains, &st->hvq_hangover, pe_gains ); + } + else if ( length == L_FRAME48k && st->core_brate <= HQ_32k && st->bwidth == st->last_bwidth ) + { + /* Detect HQ_HARMONIC mode */ + *hqswb_clas = peak_avrg_ratio( st->total_brate, coefs, NUMC_N+96, &st->mode_count, &st->mode_count1 ); + /* Detect HQ_HVQ mode */ + hvq_classifier( coefs, &st->prev_Npeaks, st->prev_peaks, hqswb_clas, Npeaks, peaks, st->core_brate, st->last_core, + nf_gains, &st->hvq_hangover, pe_gains ); + } + if( length == L_FRAME48k && st->core_brate <= HQ_32k && *hqswb_clas == HQ_NORMAL) + { + *hqswb_clas = HQ_GEN_FB; + } + /* set the required number of bits for signalling */ + if( length >= L_FRAME32k && st->core_brate <= HQ_32k ) + { + bits = 2; + } + else + { + bits = 1; + } + + /* write signalling info to the bitstream */ + if ( length == L_FRAME48k && st->core_brate <= HQ_32k ) + { + if ( *hqswb_clas >= HQ_GEN_SWB) + { + push_indice( st, IND_HQ_SWB_CLAS, *hqswb_clas - 5, bits ); + } + else + { + push_indice( st, IND_HQ_SWB_CLAS, *hqswb_clas, bits ); + } + } + else + { + push_indice( st, IND_HQ_SWB_CLAS, *hqswb_clas, bits ); + } + + if ( *hqswb_clas == HQ_NORMAL && length == L_FRAME32k && st->core_brate <= HQ_32k ) + { + *hqswb_clas = HQ_GEN_SWB; + } + + return bits; +} + +/*--------------------------------------------------------------------------* + * peak_avrg_ratio() + * + * Classify the input signal and decide if it has a harmonic structure + *--------------------------------------------------------------------------*/ +short peak_avrg_ratio( + const long total_brate, + const float *input_hi, /* i : input signal */ + const short N, /* i : number of coefficients */ + short *mode_count, /* i/o: HQ_HARMONIC mode count */ + short *mode_count1 /* i/o: HQ_NORMAL mode count */ +) +{ + float mean, peak, sharp; + short i, j, q, k, k1, hqswb_clas; + float input_abs[L_FRAME32k]; + + for ( i = 96; i < N; i++) + { + input_abs[i] = (float) fabs(input_hi[i]); + } + + hqswb_clas = HQ_NORMAL; + + k = 0; + k1 = 0; + q = 96; + for( i = 3; i < 17; i++ ) + { + peak = 0.0f; + mean = EPSILON; + for(j = 0; j < 32; j++, q++) + { + mean += input_abs[q]; + + if ( input_abs[q] > peak ) + { + peak = input_abs[q]; + } + } + + sharp = 32 * peak / mean; + + if( i < 8 ) + { + if( sharp > 4.5 ) + { + k += 1; + } + } + else + { + if( sharp > 3.6 && peak > 10 ) + { + k1 += 1; + } + } + } + + if( k + k1 >= 10 && k1 > 5 ) + { + if( *mode_count < 8 ) + { + (*mode_count)++; + } + + if( *mode_count1 > 0 ) + { + (*mode_count1)--; + } + } + else + { + if( *mode_count > 0 ) + { + (*mode_count)--; + } + + if( *mode_count1 < 8 ) + { + (*mode_count1)++; + } + } + if( (k + k1 >= 5 && k1 > 2 && total_brate == HQ_24k40) || (((k + k1 >= 10 && k1 > 5) || *mode_count >= 5) && *mode_count1 < 5) ) + { + hqswb_clas = HQ_HARMONIC; + } + + return hqswb_clas; +} + + +/*--------------------------------------------------------------------------* + * hvq_classifier() + * + * Classification of spectral content for HQ_HVQ mode + *--------------------------------------------------------------------------*/ + +static void hvq_classifier( + const float *input, /* i : input signal */ + short *prev_Npeaks, /* i/o: Peak number memory */ + short *prev_peaks, /* i/o: Peak indices memory */ + short *hqswb_clas, /* i/o: HQ class */ + short *Npeaks, /* o : Number of peaks */ + short *peaks, /* o : Peak indices */ + const long core_brate, /* i : Core bit-rate */ + const short last_core, /* i : Last core used */ + float *nf_gains, /* o : Noisefloor gains */ + short *hvq_hangover, /* i/o: Mode-switch hangover */ + float *pe_gains /* o : peak gains */ +) +{ + const float *p_adj; + float sharp_dist; + float nf, pe, d, peak, thr_tmp, m; + float input_abs[L_FRAME32k], thr[L_FRAME16k]; + float pe_mean[HVQ_NSUB_32k], nf_mean[HVQ_NSUB_32k]; + float sharp[HVQ_NSUB_32k]; + + short num_sharp_bands, i, j, k, q, peak_th, nsub, pindx, N, offset; + short num_peak_cands, high, low; + short peak_cand_idx[HVQ_THRES_BIN_32k], avail_peaks[HVQ_NSUB_32k]; + + if( *hqswb_clas == HQ_HARMONIC && last_core != ACELP_CORE && last_core != AMR_WB_CORE ) + { + set_f(thr, 0.0f, L_FRAME16k); + if( core_brate == HQ_24k40 ) + { + nsub = HVQ_NSUB_24k; + } + else + { + nsub = HVQ_NSUB_32k; + } + + N = nsub * HVQ_BW; + + for( i = 0; i < N; i++ ) + { + input_abs[i] = (float) fabs(input[i]); + } + + *Npeaks = 0; + nf = 800; + pe = 800; + num_sharp_bands = 0; + k = 0; + q = 0; + sharp_dist = 0; + + /* Find peak threshold */ + for( i = 0; i < nsub; i++ ) + { + peak = 0.0f; + nf_mean[i] = EPSILON; + pe_mean[i] = EPSILON; + for( j = 0; j < HVQ_BW; j++, q++ ) + { + d = input_abs[q]; + + if( d > nf ) + { + nf = HVQ_NF_WEIGHT1 * nf + (1 - HVQ_NF_WEIGHT1) * d; + } + else + { + nf = HVQ_NF_WEIGHT2 * nf + (1 - HVQ_NF_WEIGHT2) * d; + } + + if( d > pe ) + { + pe = HVQ_PE_WEIGHT1 * pe + (1 - HVQ_PE_WEIGHT1) * d; + } + else + { + pe = HVQ_PE_WEIGHT2 * pe + (1 - HVQ_PE_WEIGHT2) * d; + } + + nf_mean[i] += nf; + pe_mean[i] += pe; + + if( d > peak ) + { + peak = d; + } + } + + nf_mean[i] /= HVQ_BW; + pe_mean[i] /= HVQ_BW; + + + thr_tmp = (float)pow( pe_mean[i]/nf_mean[i], HVQ_THR_POW ) * nf_mean[i]; + set_f( &thr[k], thr_tmp, HVQ_BW ); + k += HVQ_BW; + + sharp[i] = peak / nf_mean[i]; + sharp_dist += sharp[i] - HVQ_SHARP_THRES; + + if( sharp[i] > HVQ_SHARP_THRES ) + { + num_sharp_bands++; + } + } + + /* Estimate noise floor gains */ + offset = nsub % 2; + for( i = 0; i < 2*(nsub/2); i++ ) + { + nf_gains[(2*i+1)/nsub] += nf_mean[i+offset]; + pe_gains[(2*i+1)/nsub] += pe_mean[i+offset]; + } + + for( i = 0; i < HVQ_NF_GROUPS; i++ ) + { + nf_gains[i] /= nsub/HVQ_NF_GROUPS; + pe_gains[i] /= nsub/HVQ_NF_GROUPS; + } + + /* Allocate available peaks */ + for( i = 0; i < nsub; i++ ) + { + avail_peaks[i] = HVQ_PA_PEAKS_SHARP1; + if( nf_mean[i] < nf_gains[(2*i+1)/nsub] * HVQ_PA_FAC ) + { + if( sharp[i] < HVQ_PA_SHARP_THRES3 ) + { + avail_peaks[i] = HVQ_PA_PEAKS_SHARP3; + } + else if( sharp[i] < HVQ_PA_SHARP_THRES2 ) + { + avail_peaks[i] = HVQ_PA_PEAKS_SHARP2; + } + } + } + + /* Adjust threshold around previous peaks */ + for( i = 0; i < *prev_Npeaks; i++ ) + { + j = prev_peaks[i] - 2; + k = prev_peaks[i] + 2; + p_adj = hvq_thr_adj; + + for( q = j; q < k; q++ ) + { + thr[q] *= *p_adj++; + } + } + + num_peak_cands = 0; + + /* Remove everything below threshold for peak search */ + input_abs[0] = 0; + input_abs[1] = 0; + input_abs[N-2] = 0; + input_abs[N-1] = 0; + for( i = 0; i < N-2; i++ ) + { + if( input_abs[i] < thr[i] ) + { + input_abs[i] = 0; + } + else + { + input_abs[num_peak_cands] = input_abs[i]; + peak_cand_idx[num_peak_cands] = i; + num_peak_cands++; + } + } + + if( core_brate == HQ_24k40 ) + { + peak_th = HVQ_MAX_PEAKS_24k_CLAS; + } + else + { + peak_th = HVQ_MAX_PEAKS_32k; + } + + /* Find peaks */ + pindx = maximum( input_abs, num_peak_cands, &m ); + i = 0; + + while( m > 0 && i < peak_th+1) + { + if( avail_peaks[peak_cand_idx[pindx]/HVQ_BW] > 0 ) + { + peaks[i++] = peak_cand_idx[pindx]; + avail_peaks[peak_cand_idx[pindx]/HVQ_BW]--; + } + + j = pindx - 2; + k = pindx + 2; + + if( j < 0 ) + { + j = 0; + } + + if( k > num_peak_cands-1 ) + { + k = num_peak_cands-1; + } + + low = peak_cand_idx[pindx] - 2; + high = peak_cand_idx[pindx] + 2; + + if( low < 0 ) + { + low = 0; + } + + if( high > N-1 ) + { + high = N-1; + } + + for( q = j; q <= pindx; q++ ) + { + if( peak_cand_idx[q] >= low ) + { + peak_cand_idx[q] = 0; + input_abs[q] = 0; + } + } + + for( q = pindx + 1; q <= k; q++ ) + { + if( peak_cand_idx[q] <= high ) + { + peak_cand_idx[q] = 0; + input_abs[q] = 0; + } + } + + pindx = maximum(input_abs, num_peak_cands, &m); + } + + *Npeaks = i; + + /* decision about HQ_HVQ mode */ + if (*Npeaks > HVQ_MIN_PEAKS) + { + if( num_sharp_bands > nsub - 3 && *Npeaks <= peak_th ) + { + sharp_dist /= nsub; + if( sharp_dist <= SHARP_DIST_THRES && *hvq_hangover < 0 ) + { + (*hvq_hangover)++; + } + else + { + *hqswb_clas = HQ_HVQ; + *hvq_hangover = 2; + } + + /* update memory */ + *prev_Npeaks = *Npeaks; + mvs2s( peaks, prev_peaks, *Npeaks ); + } + else + { + if( *hvq_hangover > 0 ) + { + *hqswb_clas = HQ_HVQ; + (*hvq_hangover)--; + } + else + { + *hvq_hangover = -1; + } + } + } + else + { + *hvq_hangover = -1; + } + + + if( core_brate == HQ_24k40 ) + { + *Npeaks = min( HVQ_MAX_PEAKS_24k, *Npeaks ); + } + else + { + *Npeaks = min( HVQ_MAX_PEAKS_32k, *Npeaks ); + } + } + else + { + *prev_Npeaks = 0; + *hvq_hangover = 0; + } + + return; +} + + diff --git a/src/libs/libevs/lib_enc/hq_classifier_enc_fx.cpp b/src/libs/libevs/lib_enc/hq_classifier_enc_fx.cpp deleted file mode 100755 index 1aaf3409..00000000 --- a/src/libs/libevs/lib_enc/hq_classifier_enc_fx.cpp +++ /dev/null @@ -1,671 +0,0 @@ -/*==================================================================================== - EVS Codec 3GPP TS26.442 Apr 03, 2018. Version 12.11.0 / 13.6.0 / 14.2.0 - ====================================================================================*/ - -#include "options.h" /* Compilation switches */ -#include "cnst_fx.h" /* Common constants */ -#include "prot_fx.h" /* Function prototypes */ -#include "rom_com_fx.h" /* Static table prototypes */ -#include "stl.h" /* Debug prototypes */ - -/*-----------------------------------------------------------------* - * Local constants - *-----------------------------------------------------------------*/ - -#define SHARP_DIST_THRES 22.2f -#define SHARP_DIST_THRES_FX 1420 /* Q6, 22.2 */ - -/*-----------------------------------------------------------------* - * Local functions - *-----------------------------------------------------------------*/ - -void hvq_classifier_fx( const Word32 *input, Word16 *prev_Npeaks, Word16 *prev_peaks, - Word16 *hqswb_clas, Word16 *Npeaks, Word16 *peaks, const Word32 L_core_brate, - const Word16 last_core, Word32 *L_nf_gains, Word16 *hvq_hangover, Word32 *L_pe_gains ); - -/*--------------------------------------------------------------------------* - * hq_classifier_enc_fx() - * - * HQ mode selector (decision_matrix) - *--------------------------------------------------------------------------*/ - -Word16 hq_classifier_enc_fx( /* o : Consumed bits Q0 */ - Encoder_State_fx *st_fx, /* i/o: encoder state structure */ - const Word16 length, /* i : Frame length Q0 */ - const Word32 *coefs, /* i : Spectral coefficients Q12 */ - const Word16 is_transient, /* i : Transient flag Q0 */ - Word16 *Npeaks, /* o : Number of identified peaks Q0 */ - Word16 *peaks, /* o : Peak indices Q0 */ - Word32 *pe_gains, /* o : Peak gains Q12 */ - Word32 *nf_gains, /* o : Noise-fill gains Q12 */ - Word16 *hqswb_clas /* o : HQ class Q0 */ -) -{ - Word16 bits; - - *hqswb_clas = HQ_NORMAL; - IF( sub( is_transient, 1) == 0 ) - { - *hqswb_clas = HQ_TRANSIENT; - move16(); - } - - /* classification and limit bandwidth for bit allocation */ - test(); - test(); - test(); - IF( sub(length, L_FRAME32k) == 0 && sub(is_transient,1) != 0 && L_sub(st_fx->core_brate_fx, HQ_32k) <= 0 && sub(st_fx->bwidth_fx, st_fx->last_bwidth_fx) == 0 ) - { - /* Detect HQ_HARMONIC mode */ - *hqswb_clas = peak_avrg_ratio_fx( st_fx->total_brate_fx, coefs, NUMC_N+96, &st_fx->mode_count_fx, &st_fx->mode_count1_fx, 12 ); - - /* Detect harmonic VQ mode HQ_HVQ */ - hvq_classifier_fx( coefs, &st_fx->prev_Npeaks_fx, st_fx->prev_peaks_fx, hqswb_clas, Npeaks, peaks, st_fx->core_brate_fx, st_fx->last_core_fx, - nf_gains, &st_fx->hvq_hangover_fx, pe_gains ); - } - - test(); - test(); - test(); - IF ( sub(length, L_FRAME48k) == 0 && sub( is_transient, 1) != 0 && L_sub(st_fx->core_brate_fx, HQ_32k) <= 0 && sub( st_fx->bwidth_fx, st_fx->last_bwidth_fx) == 0 ) - { - /* Detect HQ_HARMONIC mode */ - *hqswb_clas = peak_avrg_ratio_fx( st_fx->total_brate_fx, coefs, NUMC_N+96, &st_fx->mode_count_fx, &st_fx->mode_count1_fx, 12); - /* Detect harmonic VQ mode HQ_HVQ */ - hvq_classifier_fx( coefs, &st_fx->prev_Npeaks_fx, st_fx->prev_peaks_fx, hqswb_clas, Npeaks, peaks, - st_fx->core_brate_fx, st_fx->last_core_fx, nf_gains, &st_fx->hvq_hangover_fx, pe_gains ); - } - - test(); - test(); - IF( sub(length, L_FRAME48k) == 0 && L_sub(st_fx->core_brate_fx, HQ_32k) <= 0 && sub(*hqswb_clas,HQ_NORMAL) == 0 ) - { - *hqswb_clas = HQ_GEN_FB; - move16(); - } - - test(); - IF( sub( length, L_FRAME32k) >= 0 && L_sub( st_fx->core_brate_fx, HQ_32k) <= 0 ) - { - bits = 2; - move16(); - } - ELSE - { - bits = 1; - move16(); - } - - test(); - IF ( sub( length, L_FRAME48k) == 0 && L_sub( st_fx->core_brate_fx, HQ_32k) <= 0 ) - { - IF ( sub( *hqswb_clas, HQ_GEN_SWB) >= 0) - { - push_indice_fx( st_fx, IND_HQ_SWB_CLAS, *hqswb_clas - 5, bits ); - } - ELSE - { - push_indice_fx( st_fx, IND_HQ_SWB_CLAS, *hqswb_clas, bits ); - } - } - ELSE - { - push_indice_fx( st_fx, IND_HQ_SWB_CLAS, *hqswb_clas, bits ); - } - - test(); - test(); - IF ( sub( *hqswb_clas, HQ_NORMAL) == 0 && sub( length, L_FRAME32k) == 0 && L_sub( st_fx->core_brate_fx, HQ_32k ) <= 0 ) - { - *hqswb_clas = HQ_GEN_SWB; - move16(); - } - - return bits; -} - -/*--------------------------------------------------------------------------* - * peak_avrg_ratio() - * - * Classify the input signal and decide if it has a harmonic structure - *--------------------------------------------------------------------------*/ -Word16 peak_avrg_ratio_fx( - const Word32 total_brate, - const Word32 *input_hi_fx, /* i : input signal */ - const Word16 length, /* i : number of coefficients */ - Word16 *mode_count, /* i/o: HQ_HARMONIC mode count */ - Word16 *mode_count1, /* i/o: HQ_NORMAL mode count */ - Word16 Q_coeff -) -{ - Word16 i, j, q, k, k1, hqswb_clas; - Word32 mean_fx, peak_fx; - Word32 input_abs_fx[L_FRAME32k]; - Word32 peak_th_fx; - - FOR ( i = 96; i < length; i++) - { - input_abs_fx[i] = L_abs(input_hi_fx[i]); - } - - hqswb_clas = HQ_NORMAL; - move16(); - peak_th_fx = L_shl(10L, sub(Q_coeff, 5)); /* 5 is safe shift */ - - k = 0; - move16(); - k1 = 0; - move16(); - q = 96; /* q used for indexing */ - - FOR( i = 3; i < 17; i ++ ) - { - peak_fx = L_deposit_l(0); - mean_fx = L_deposit_l(1); - - /*for(j = 0; j < 32; j ++, q ++) */ - FOR(j = 0; j < 32; j ++) - { - input_abs_fx[q] =L_shr(input_abs_fx[q],5); /*Q_coeff-5 */ - mean_fx =L_add(mean_fx,input_abs_fx[q]); /*Q_coeff-5 */ - IF (L_sub(input_abs_fx[q] , peak_fx)>0) - { - peak_fx =input_abs_fx[q] ; /*Q_coeff-5 */ - } - q ++; - } - - IF(sub(i,8) < 0) - { - if(L_sub(peak_fx, Mult_32_16(mean_fx, 4608))>0) /* Q15 0.140625 */ - { - k = add(k,1); - } - } - ELSE - { - test(); - if(L_sub(peak_fx, Mult_32_16(mean_fx, 3686))>0 /*Q15 0.1125 */ - && L_sub(peak_fx, peak_th_fx) >0) /*Q27 10 */ - { - k1 = add(k1,1); - } - } - } - - test(); - IF( sub(add(k,k1),10) >= 0 && sub(k1,5) > 0 ) - { - if( sub(*mode_count,8) < 0 ) - { - *mode_count = add(*mode_count,1); - } - - if( *mode_count1 > 0 ) - { - *mode_count1 = sub(*mode_count1,1); - } - } - ELSE - { - if( sub(*mode_count1,8) < 0 ) - { - *mode_count1 = add(*mode_count1,1); - } - - if( *mode_count > 0 ) - { - *mode_count = sub(*mode_count,1); - } - } - - test(); - test(); - test(); - test(); - test(); - test(); - if ((sub(add(k, k1), 5) >= 0 && sub(k1, 2) > 0 && L_sub(total_brate, HQ_24k40) == 0) - || (((sub(add(k, k1), 10) >= 0 && sub(k1, 5) > 0) || sub(*mode_count, 5) >= 0) && sub(*mode_count1, 5) < 0)) - { - hqswb_clas = HQ_HARMONIC; - move16(); - } - - return hqswb_clas; -} - -/*--------------------------------------------------------------------------* - * hvq_classifier() - * - * Classification of harmonic low band content for Harmonic VQ - *--------------------------------------------------------------------------*/ - -void hvq_classifier_fx( - const Word32 *input, /* i : input signal Q12 */ - Word16 *prev_Npeaks, /* i/o: Peak number memory Q0 */ - Word16 *prev_peaks, /* i/o: Peak indices memory Q0 */ - Word16 *hqswb_clas, /* i/o: HQ class Q0 */ - Word16 *Npeaks, /* o : Number of peaks Q0 */ - Word16 *peaks, /* o : Peak indices Q0 */ - const Word32 L_core_brate, /* i : Core bit-rate Q0 */ - const Word16 last_core, /* i : Last core used Q0 */ - Word32 *L_nf_gains, /* o : Noisefloor gains Q12 */ - Word16 *hvq_hangover, /* i/o: Mode-switch hangover Q0 */ - Word32 *L_pe_gains /* o : peak gains Q12 */ -) -{ - const Word16 *p_adj; - UWord16 lsb; - - Word32 L_input_abs[L_FRAME32k]; - Word32 L_input_max; - Word32 L_thr[L_FRAME16k]; - Word32 L_thr_tmp; - Word32 L_m; - Word32 L_tmp; - Word32 L_d; - Word32 L_peak; - Word32 L_nf, L_pe; - Word32 L_pe_mean[HVQ_NSUB_32k], L_nf_mean[HVQ_NSUB_32k]; - - Word16 inv_nsub; - Word16 sharp_dist; - Word16 exp1, exp2; - Word16 tmp; - Word16 shift; - Word16 idx; - Word16 frac; - Word16 inv_nf_mean; - Word16 inv_gains_nsub; - Word16 nf_mean_norm; - Word16 num_sharp_bands, i, j, k, q, peak_th, nsub, pindx, N, offset; - Word16 num_peak_cands, high, low; - Word16 sharp[HVQ_NSUB_32k]; - Word16 peak_cand_idx[HVQ_THRES_BIN_32k], avail_peaks[HVQ_NSUB_32k]; - - L_input_max = L_deposit_l(0); - set32_fx(L_thr, 0, L_FRAME16k); - - IF ( L_sub(L_core_brate, HQ_24k40) == 0 ) - { - nsub = HVQ_NSUB_24k; - move16(); - inv_nsub = 4681; - move16(); /* 1/7 in Q15 */ - inv_gains_nsub = 10923; - move16(); /* 1/3 in Q15 */ - } - ELSE - { - nsub = HVQ_NSUB_32k; - move16(); - inv_nsub = 3277; - move16(); /* 1/10 in Q15 */ - inv_gains_nsub = 6554; - move16(); /* 1/5 in Q15 */ - } - - N = shl(nsub, 5); /* Mult by 32 (HVQ_BW) */ - - test(); - test(); - IF ( sub(*hqswb_clas, HQ_HARMONIC) == 0 && last_core != ACELP_CORE && sub(last_core, AMR_WB_CORE) != 0 ) - { - FOR ( i = 0; i < N; i++ ) - { - L_input_abs[i] = L_abs(input[i]); - if (L_input_abs[i] > L_input_max) - { - L_input_max = L_input_abs[i]; - move16(); - } - } - - exp1 = norm_l(L_input_max); - - *Npeaks = 0; - move16(); - L_nf = 3276800; - move32(); /* 800 in Q12 */ - L_pe = 3276800; - move32(); /* 800 in Q12 */ - num_sharp_bands = 0; - move16(); - k = 0; - move16(); - q = 0; - move16(); - sharp_dist = 0; - move16(); - - /* Find peak threshold */ - FOR ( i = 0; i < nsub; i++ ) - { - L_peak = 0; - L_nf_mean[i] = 0; - L_pe_mean[i] = 0; - FOR ( j = 0; j < HVQ_BW; j++ ) - { - L_d = L_input_abs[q]; - IF ( L_sub(L_d, L_nf) > 0 ) - { - /*nf = HVQ_NF_WEIGHT1 * nf + (1 - HVQ_NF_WEIGHT1) * d; */ - Mpy_32_16_ss(L_d, HVQ_NF_WEIGHT1B, &L_tmp, &lsb); /* 12+15-15=12 */ - Mpy_32_16_ss(L_nf, HVQ_NF_WEIGHT1_FX, &L_nf, &lsb); /* 12+15-15=12 */ - L_nf = L_add(L_nf, L_tmp); /*Q12 */ - } - ELSE - { - /*nf = HVQ_NF_WEIGHT2 * nf + (1 - HVQ_NF_WEIGHT2) * d; */ - Mpy_32_16_ss(L_d, HVQ_NF_WEIGHT2B, &L_tmp, &lsb); /* 12+15-15=12 */ - Mpy_32_16_ss(L_nf, HVQ_NF_WEIGHT2_FX, &L_nf, &lsb); /* 12+15-15=12 */ - L_nf = L_add(L_nf, L_tmp); /*Q12 */ - } - - IF ( L_sub(L_d, L_pe) > 0 ) - { - /*pe = HVQ_PE_WEIGHT1 * pe + (1 - HVQ_PE_WEIGHT1) * d; */ - Mpy_32_16_ss(L_d, HVQ_PE_WEIGHT1B, &L_tmp, &lsb); /* 12+15-15=12 */ - Mpy_32_16_ss(L_pe, HVQ_PE_WEIGHT1_FX, &L_pe, &lsb); /* 12+15-15=12 */ - L_pe = L_add(L_pe, L_tmp); /*Q12 */ - } - ELSE - { - /*pe = HVQ_PE_WEIGHT2 * pe + (1 - HVQ_PE_WEIGHT2) * d; */ - Mpy_32_16_ss(L_d, HVQ_PE_WEIGHT2B, &L_tmp, &lsb); /* 12+15-15=12 */ - Mpy_32_16_ss(L_pe, HVQ_PE_WEIGHT2_FX, &L_pe, &lsb); /* 12+15-15=12 */ - L_pe = L_add(L_pe, L_tmp); /*Q12 */ - } - - L_nf_mean[i] = L_add(L_nf_mean[i], L_nf); - L_pe_mean[i] = L_add(L_pe_mean[i], L_pe); - - IF ( L_sub(L_d, L_peak) > 0 ) - { - L_peak = L_add(L_d, 0); - } - - q = add(q, 1); - } - L_nf_mean[i] = L_shr(L_nf_mean[i], 5); /* Divide by 5 (HVQ_BW) */ - L_pe_mean[i] = L_shr(L_pe_mean[i], 5); /* Divide by 5 (HVQ_BW) */ - - /*thr_tmp = (float)pow( pe_mean[i]/nf_mean[i], HVQ_THR_POW ) * nf_mean[i]; */ - exp1 = norm_l(L_nf_mean[i]); - nf_mean_norm = extract_h(L_shl(L_nf_mean[i], exp1)); /* 12+s-16=s-4 */ - IF ( nf_mean_norm == 0 ) - { - inv_nf_mean = 0; - } - ELSE - { - inv_nf_mean = div_s(1<<14, nf_mean_norm); /* 15+14-s+4=33-s */ - } - Mpy_32_16_ss(L_pe_mean[i], inv_nf_mean, &L_tmp, &lsb); /*12+33-s-15=30-s */ - - exp2 = norm_l(L_tmp); - tmp = Log2_norm_lc(L_shl(L_tmp, exp2)); /* Q15 */ - exp2 = exp1 - exp2; /* Q0 */ - L_tmp = Mpy_32_16(exp2, tmp, 32767); /* 1 in Q15. Q16 */ - Mpy_32_16_ss(L_tmp, 28836, &L_tmp, &lsb); /* 16+15-15=16 */ - frac = L_Extract_lc(L_tmp, &tmp); /* Q15 and Q0 */ - L_tmp = Pow2(14, frac); /* Q14 */ - L_tmp = L_shl(L_tmp, tmp); /* Q14 */ - - Mpy_32_16_ss(L_tmp, nf_mean_norm, &L_tmp, &lsb); /*14+s-4-15=s-5 */ - shift = sub(17, exp1); /* 16-(s-5)=17-s */ - L_thr_tmp = L_shl(L_tmp, shift); /* Q16 */ - L_thr_tmp = L_add(L_thr_tmp, lshr(lsb, sub(16, shift))); /*Q16 */ - - set32_fx(&L_thr[k], L_thr_tmp, HVQ_BW); - k = add(k, HVQ_BW); - - /*sharp[i] = peak/nf_mean[i]; */ - Mpy_32_16_ss(L_peak, inv_nf_mean, &L_tmp, &lsb); /* 12+33-s-15=30-s */ - shift = sub(exp1, 8); - sharp[i] = extract_h(L_shl(L_tmp, shift)); /* 30-s+s-8-16 -> Q6 */ - - /*sharp_dist += (sharp[i]-HVQ_SHARP_THRES); */ - sharp_dist = add(sharp_dist, sub(sharp[i], HVQ_SHARP_THRES_FX)); - - if ( sub(sharp[i], HVQ_SHARP_THRES_FX) > 0 ) - { - num_sharp_bands = add(num_sharp_bands, 1); - } - } - - /* Estimate noise floor gains */ - offset = s_and(nsub, 1); - FOR ( i = 0; i < s_and(nsub, (Word16)0xFFFE); i++ ) - { - /*(2*i+1)/nsub */ - idx = mult(add(shl(i, 1), 1), add(inv_nsub, 1)); /*0+15-15 = 0 */ - L_nf_gains[idx] = L_add(L_nf_gains[idx], L_nf_mean[i+offset]); - L_pe_gains[idx] = L_add(L_pe_gains[idx], L_pe_mean[i+offset]); - } - - FOR ( i = 0; i < HVQ_NF_GROUPS; i++ ) - { - Mpy_32_16_ss(L_nf_gains[i], inv_gains_nsub, &L_nf_gains[i], &lsb); /*12+15-15=12 */ - Mpy_32_16_ss(L_pe_gains[i], inv_gains_nsub, &L_pe_gains[i], &lsb); /*12+15-15=12 */ - } - - /* Allocate available peaks */ - FOR ( i = 0; i < nsub; i++ ) - { - avail_peaks[i] = HVQ_PA_PEAKS_SHARP1; - move16(); - idx = mult(add(shl(i, 1), 1), add(inv_nsub, 1)); /*0+15-15 = 0 */ - Mpy_32_16_ss(L_nf_gains[idx], HVQ_PA_FAC_FX, &L_tmp, &lsb); /* 12+15-15 -> Q12 */ - IF( L_sub(L_nf_mean[i], L_tmp) < 0 ) - { - IF ( sub(sharp[i], HVQ_PA_SHARP_THRES3_FX) < 0 ) - { - avail_peaks[i] = HVQ_PA_PEAKS_SHARP3; - move16(); - } - ELSE IF( sub(sharp[i], HVQ_PA_SHARP_THRES2_FX) < 0 ) - { - avail_peaks[i] = HVQ_PA_PEAKS_SHARP2; - move16(); - } - } - } - - - - /* Adjust threshold around previous peaks */ - FOR ( i = 0; i < *prev_Npeaks; i++ ) - { - j = sub(prev_peaks[i], 2); - k = add(prev_peaks[i], 2); - p_adj = hvq_thr_adj_fx; - - FOR( q = j; q < k; q++ ) - { - Mpy_32_16_ss(L_thr[q], *p_adj++, &L_thr[q], &lsb); /* 12+15-15=12 */ - move32(); - } - } - - num_peak_cands = 0; - move16(); - - /* Remove everything below threshold for peak search */ - L_input_abs[0] = L_deposit_l(0); - L_input_abs[1] = L_deposit_l(0); - L_input_abs[N-2] = L_deposit_l(0); - L_input_abs[N-1] = L_deposit_l(0); - FOR ( i = 0; i < N-2; i++ ) - { - IF ( L_sub(L_input_abs[i], L_thr[i]) < 0 ) - { - L_input_abs[i] = L_deposit_l(0); - } - ELSE - { - L_input_abs[num_peak_cands] = L_input_abs[i]; - move32(); - peak_cand_idx[num_peak_cands] = i; - move16(); - num_peak_cands = add(num_peak_cands, 1); - } - } - - IF ( L_sub(L_core_brate, HQ_24k40) == 0 ) - { - peak_th = HVQ_MAX_PEAKS_24k_CLAS; - move16(); - } - ELSE - { - peak_th = HVQ_MAX_PEAKS_32k; - move16(); - } - - /* Find peaks */ - pindx = maximum_32_fx(L_input_abs, num_peak_cands, &L_m); - i = 0; - move16(); - - WHILE ( L_m > 0 && sub(i, peak_th+1) < 0) - { - idx = mult(peak_cand_idx[pindx], INV_HVQ_BW); /* 0+15-15=0 */ - IF ( avail_peaks[idx] > 0 ) - { - peaks[i++] = peak_cand_idx[pindx]; - avail_peaks[idx]--; - } - - j = sub(pindx, 2); - k = add(pindx, 2); - - if ( j < 0 ) - { - j = 0; - move16(); - } - - tmp = sub(num_peak_cands, 1); - if ( sub(k, tmp) > 0 ) - { - k = tmp; - move16(); - } - - low = sub(peak_cand_idx[pindx], 2); - high = add(peak_cand_idx[pindx], 2); - - if ( low < 0 ) - { - low = 0; - move16(); - } - - tmp = sub(N, 1); - if ( sub(high, tmp) > 0 ) - { - high = tmp; - move16(); - } - - FOR( q = j; q <= pindx; q++ ) - { - IF( sub(peak_cand_idx[q], low) >= 0 ) - { - peak_cand_idx[q] = 0; - move16(); - L_input_abs[q] = 0; - move16(); - } - } - - FOR( q = pindx + 1; q <= k; q++ ) - { - IF ( sub(peak_cand_idx[q], high) <= 0 ) - { - peak_cand_idx[q] = 0; - move16(); - L_input_abs[q] = 0; - move16(); - } - } - - pindx = maximum_32_fx(L_input_abs, num_peak_cands, &L_m); - } - - *Npeaks = i; - move16(); - IF ( sub(*Npeaks, HVQ_MIN_PEAKS) > 0 ) - { - test(); - IF ( sub(num_sharp_bands, sub(nsub, 3)) > 0 && sub(*Npeaks, peak_th) <= 0 ) - { - sharp_dist = mult(sharp_dist, inv_nsub); /*x+15-15=x */ - test(); - IF ( sub(sharp_dist, SHARP_DIST_THRES_FX) <= 0 && *hvq_hangover < 0 ) - { - *hvq_hangover = add(*hvq_hangover, 1); - } - ELSE - { - *hqswb_clas = HQ_HVQ; - move16(); - *hvq_hangover = 2; - move16(); - } - - /* update memory */ - *prev_Npeaks = *Npeaks; - move16(); - Copy( peaks, prev_peaks, *Npeaks ); - } - ELSE - { - IF( *hvq_hangover > 0 ) - { - *hqswb_clas = HQ_HVQ; - move16(); - *hvq_hangover = sub(*hvq_hangover, 1); - move16(); - } - ELSE - { - *hvq_hangover = -1; - move16(); - } - } - } - ELSE - { - /* Zero peaks, likely silence input. */ - *hvq_hangover = -1; - move16(); - } - - - IF ( L_sub(L_core_brate, HQ_24k40) == 0 ) - { - *Npeaks = s_min( HVQ_MAX_PEAKS_24k, *Npeaks ); - move16(); - } - ELSE - { - *Npeaks = s_min( HVQ_MAX_PEAKS_32k, *Npeaks ); - move16(); - } - } - ELSE - { - *prev_Npeaks = 0; - move16(); - *hvq_hangover = 0; - move16(); - } - - - return; -} - - diff --git a/src/libs/libevs/lib_enc/hq_core_enc.cpp b/src/libs/libevs/lib_enc/hq_core_enc.cpp new file mode 100644 index 00000000..d03927a3 --- /dev/null +++ b/src/libs/libevs/lib_enc/hq_core_enc.cpp @@ -0,0 +1,158 @@ +/*==================================================================================== + EVS Codec 3GPP TS26.443 Nov 13, 2018. Version 12.11.0 / 13.7.0 / 14.3.0 / 15.1.0 + ====================================================================================*/ + +#include +#include "options.h" +#include "cnst.h" +#include "prot.h" +#include "rom_com.h" + +/*-------------------------------------------------------------------------- + * hq_core_enc() + * + * HQ core encoder + *--------------------------------------------------------------------------*/ + +void hq_core_enc( + Encoder_State *st, /* i/o: encoder state structure */ + const float *audio, /* i : input audio signal */ + const short input_frame_orig,/* i : frame length */ + const short hq_core_type, /* i : HQ core type */ + const short Voicing_flag /* i : HQ core voicing flag */ +) +{ + short i, is_transient, num_bits, extra_unused; + float wtda_audio[2 * L_FRAME48k]; + float t_audio[L_FRAME48k]; + short inner_frame, input_frame; + float ener_match; + + + set_f( t_audio, 0, L_FRAME48k ); + st->Nb_ACELP_frames = 0; + + /* set input_frame length */ + input_frame = input_frame_orig; + + st->tcx_cfg.tcx_last_overlap_mode = st->tcx_cfg.tcx_curr_overlap_mode; + st->tcx_cfg.tcx_curr_overlap_mode = ALDO_WINDOW; + + /*-------------------------------------------------------------------------- + * Preprocessing in the first HQ frame after ACELP frame + * Find the number of bits for PVQ coding + * Write signalling information + *--------------------------------------------------------------------------*/ + + num_bits = (short)(st->total_brate / 50); + extra_unused = 0; + + /*-------------------------------------------------------------------------- + * Detect signal transition + *--------------------------------------------------------------------------*/ + + is_transient = detect_transient( audio, st, input_frame, HQ_CORE ); + + /*-------------------------------------------------------------------------- + * Windowing and time-domain aliasing + * DCT transform + *--------------------------------------------------------------------------*/ + + wtda( audio, wtda_audio, NULL, st->tcx_cfg.tcx_last_overlap_mode, st->tcx_cfg.tcx_curr_overlap_mode, input_frame ); + + if ( st->last_core == ACELP_CORE || st->last_core == AMR_WB_CORE ) + { + /* Preprocessing in the first HQ frame after ACELP frame */ + core_switching_hq_prepare_enc( st, &num_bits, input_frame, wtda_audio, audio ); + + /* During ACELP->HQ core switching, limit the HQ core bitrate to 48kbps */ + if( num_bits > HQ_48k / 50 ) + { + extra_unused = num_bits - (short)(HQ_48k / 50); + num_bits = (short)(HQ_48k / 50); + } + } + /* subtract signalling bits */ + num_bits -= st->nb_bits_tot; + direct_transform( wtda_audio, t_audio, is_transient, input_frame ); + + /* scale coefficients to their nominal level (8kHz) */ + if( input_frame != NORM_MDCT_FACTOR ) + { + ener_match = (float)sqrt((float)NORM_MDCT_FACTOR/(float)input_frame); + + for( i=0; ibwidth]; + + if( input_frame > inner_frame ) + { + if( is_transient ) + { + for( i = 1; i < NUM_TIME_SWITCHING_BLOCKS; i++ ) + { + mvr2r( t_audio + i*input_frame/NUM_TIME_SWITCHING_BLOCKS, t_audio + i*inner_frame/NUM_TIME_SWITCHING_BLOCKS, inner_frame/NUM_TIME_SWITCHING_BLOCKS ); + } + } + + set_f( t_audio + inner_frame, 0.0f, input_frame - inner_frame ); + } + + /*-------------------------------------------------------------------------- + * Classify whether to put extra bits for FER mitigation + *--------------------------------------------------------------------------*/ + + if( st->last_core == HQ_CORE && st->core_brate > MINIMUM_RATE_TO_ENCODE_VOICING_FLAG ) + { + if ( Voicing_flag > 0 ) + { + push_indice( st, IND_HQ_VOICING_FLAG, 1, 1 ); + num_bits -= 1; + } + else + { + push_indice( st, IND_HQ_VOICING_FLAG, 0, 1 ); + num_bits -= 1; + } + } + + /*-------------------------------------------------------------------------- + * Transform-domain encoding + *--------------------------------------------------------------------------*/ + + if( hq_core_type == LOW_RATE_HQ_CORE ) + { + /* HQ low rate encoder */ + hq_lr_enc( st, t_audio, inner_frame, &num_bits, is_transient ); + } + else + { + /* HQ high rate encoder */ + hq_hr_enc( st, t_audio, inner_frame, &num_bits, is_transient ); + } + + /* write all unused bits to the bitstream */ + num_bits += extra_unused; + + while( num_bits >= 16 ) + { + push_indice( st, IND_UNUSED, 0, 16 ); + num_bits -= 16; + } + + if( num_bits != 0 ) + { + push_indice( st, IND_UNUSED, 0, num_bits ); + } + + + + + return; +} + diff --git a/src/libs/libevs/lib_enc/hq_core_enc_fx.cpp b/src/libs/libevs/lib_enc/hq_core_enc_fx.cpp deleted file mode 100755 index 9c679d59..00000000 --- a/src/libs/libevs/lib_enc/hq_core_enc_fx.cpp +++ /dev/null @@ -1,202 +0,0 @@ -/*==================================================================================== - EVS Codec 3GPP TS26.442 Apr 03, 2018. Version 12.11.0 / 13.6.0 / 14.2.0 - ====================================================================================*/ - -#include "options.h" /* Compilation switches */ -#include "rom_com_fx.h" /* Static table prototypes */ -#include "cnst_fx.h" /* Common constants */ -#include "prot_fx.h" /* Function prototypes */ -#include "stl.h" - -/*-------------------------------------------------------------------------- - * hq_core_enc() - * - * HQ core encoder - *--------------------------------------------------------------------------*/ - -void hq_core_enc_fx( - Encoder_State_fx *st_fx, - const Word16 *audio, /* i : input audio signal Q0 */ - const Word16 input_frame_orig, /* i : frame length */ - const Word16 hq_core_type, /* i : HQ core type */ - const Word16 Voicing_flag -) -{ - Word16 i, is_transient, num_bits, extra_unused; - Word32 wtda_audio[2 * L_FRAME48k]; - Word32 t_audio[L_FRAME48k]; /* Q12 */ - Word16 Q_audio = 0; - Word16 inner_frame, input_frame; - Word16 ener_match; /* Q13/Q15 */ - - Word16 tmp; - Word32 L_tmp; - UWord16 lsb; - - Word16 two_frames_buffer[2*L_FRAME48k]; - - set32_fx( t_audio, 0, L_FRAME48k ); - st_fx->Nb_ACELP_frames_fx = 0; - move16(); - - /* set input_frame length */ - input_frame = input_frame_orig; - move16(); - - st_fx->tcx_cfg.tcx_last_overlap_mode = st_fx->tcx_cfg.tcx_curr_overlap_mode; - move16(); - st_fx->tcx_cfg.tcx_curr_overlap_mode = ALDO_WINDOW; - move16(); - - /*-------------------------------------------------------------------------- - * Preprocessing in the first HQ frame after ACELP frame - * Find the number of bits for PVQ coding - * Write signalling information - *--------------------------------------------------------------------------*/ - - /*num_bits = (short)(st->total_brate / 50); */ - Mpy_32_16_ss(st_fx->total_brate_fx, 5243, &L_tmp, &lsb); /* 5243 is 1/50 in Q18. (0+18-15=3) */ - num_bits = extract_l(L_shr(L_tmp, 3)); /*Q0 */ - extra_unused = 0; - move16(); - - /*-------------------------------------------------------------------------- - * Detect signal transition - *--------------------------------------------------------------------------*/ - - is_transient = detect_transient_fx( audio, input_frame, HQ_CORE, 0, st_fx); - - /*-------------------------------------------------------------------------- - * Windowing and time-domain aliasing - * DCT transform - *--------------------------------------------------------------------------*/ - - Copy( st_fx->old_input_signal_fx, two_frames_buffer, input_frame ); - Copy( audio, two_frames_buffer+input_frame, input_frame ); - - wtda_fx( two_frames_buffer+input_frame, &Q_audio, wtda_audio, NULL, 0, - st_fx->tcx_cfg.tcx_last_overlap_mode, st_fx->tcx_cfg.tcx_curr_overlap_mode, input_frame ); - - test(); - IF ( st_fx->last_core_fx == ACELP_CORE || sub(st_fx->last_core_fx, AMR_WB_CORE) == 0 ) - { - /* Preprocessing in the first HQ frame after ACELP frame */ - core_switching_hq_prepare_enc_fx( st_fx, &num_bits, input_frame, wtda_audio, two_frames_buffer+input_frame ); - - /* During ACELP->HQ core switching, limit the HQ core bitrate to 48kbps */ - IF ( sub(num_bits, ACELP_48k_BITS) > 0 ) - { - extra_unused = sub(num_bits, ACELP_48k_BITS); - num_bits = ACELP_48k_BITS; - move16(); - } - } - - /* subtract signalling bits */ - num_bits = sub(num_bits, st_fx->nb_bits_tot_fx); - - direct_transform_fx( wtda_audio, t_audio, is_transient, input_frame, &Q_audio ); - - /* scale coefficients to their nominal level (8kHz) */ - IF ( sub(input_frame, NORM_MDCT_FACTOR) != 0 ) - { - IF (sub(input_frame, L_FRAME32k) == 0) - { - Q_audio = add(Q_audio, 1); /* Divide by 2 */ - } - ELSE - { - tmp = mult_r(input_frame, 410/2); /* 1/8000 in Q15 */ - ener_match = hq_nominal_scaling[tmp]; - FOR( i=0; i < input_frame; i++ ) - { - /*t_audio_q[i] *= ener_match; */ - Mpy_32_16_ss(t_audio[i], ener_match, &t_audio[i], &lsb); - move16(); /* Q12 */ - } - } - } - - /* limit encoded band-width according to the command-line OR BWD limitation */ - inner_frame = inner_frame_tbl[st_fx->bwidth_fx]; - move16(); - - IF( sub(input_frame, inner_frame) > 0 ) - { - IF( sub(is_transient, 1) == 0 ) - { - FOR ( i = 1; i < NUM_TIME_SWITCHING_BLOCKS; i++ ) - { - tmp = i_mult2(i, shr(input_frame, 2)); - tmp = shr(inner_frame, 2); - Copy32( t_audio + i_mult2(i, shr(input_frame, 2)), t_audio + i_mult2(i, tmp), tmp ); - } - } - - set32_fx( t_audio + inner_frame, 0, sub(input_frame, inner_frame) ); - } - - /*-------------------------------------------------------------------------- - * Classify whether to put extra bits for FER mitigation - *--------------------------------------------------------------------------*/ - - test(); - IF ( sub(st_fx->last_core_fx, HQ_CORE) == 0 && L_sub(st_fx->core_brate_fx, MINIMUM_RATE_TO_ENCODE_VOICING_FLAG) > 0 ) - { - IF ( Voicing_flag > 0 ) - { - push_indice_fx( st_fx, IND_HQ_VOICING_FLAG, 1, 1 ); - num_bits = sub(num_bits, 1); - - } - ELSE - { - push_indice_fx( st_fx, IND_HQ_VOICING_FLAG, 0, 1 ); - num_bits = sub(num_bits, 1); - } - } - - /*-------------------------------------------------------------------------- - * Transform-domain encoding - *--------------------------------------------------------------------------*/ - - IF ( sub(hq_core_type, LOW_RATE_HQ_CORE) == 0 ) - { - /* HQ low rate encoder */ - FOR (i = 0; i < inner_frame; i++) - { - t_audio[i] = L_shr(t_audio[i], sub(Q_audio, 12)); /* Q12 */ - } - hq_lr_enc_fx( st_fx, t_audio, inner_frame, &num_bits, is_transient ); - Q_audio = 12; - move16(); - } - ELSE - { - /* HQ high rate encoder */ - FOR (i = 0; i < inner_frame; i++) - { - t_audio[i] = L_shr(t_audio[i], sub(Q_audio, 12)); /* Q12 */ - } - - hq_hr_enc_fx( st_fx, t_audio, inner_frame, &num_bits, is_transient ); - Q_audio = 12; - move16(); - } - - /* write all unused bits to the bitstream */ - num_bits = add(num_bits, extra_unused); - - WHILE( num_bits >= 16 ) - { - push_indice_fx( st_fx, IND_UNUSED, 0, 16 ); - num_bits = sub(num_bits, 16); - } - - IF ( num_bits != 0 ) - { - push_indice_fx( st_fx, IND_UNUSED, 0, num_bits ); - } - - return; -} diff --git a/src/libs/libevs/lib_enc/hq_env_enc.cpp b/src/libs/libevs/lib_enc/hq_env_enc.cpp new file mode 100644 index 00000000..c576c880 --- /dev/null +++ b/src/libs/libevs/lib_enc/hq_env_enc.cpp @@ -0,0 +1,528 @@ +/*==================================================================================== + EVS Codec 3GPP TS26.443 Nov 13, 2018. Version 12.11.0 / 13.7.0 / 14.3.0 / 15.1.0 + ====================================================================================*/ + +#include +#include +#include "options.h" +#include "prot.h" +#include "rom_com.h" +#include "rom_enc.h" + +/*--------------------------------------------------------------------------------------* + * encode_envelope_indices() + * + * Encode envelope indices + *--------------------------------------------------------------------------------------*/ + +short encode_envelope_indices( /* o : Number of bits if flag_pack=0,0 if flag_pack=1 */ + Encoder_State *st, /* i/o: encoder state structure */ + const short num_sfm, /* i : Number of subbands */ + const short numnrmibits, /* i : Bitrate of fall-back coding mode */ + short *difidx, /* i/o: Diff indices/encoded diff indices */ + short *LCmode, /* o : Coding mode if flag_pack=0, i : if flag_pack=1 */ + const short flag_pack, /* i : indicator of packing or estimating bits */ + const short flag_HQ2, /* i : indicator of HQ2 core */ + const short is_transient /* i : transient flag */ +) +{ + short bits; + short prevj; + short hcode_l; + short i,j; + short difidx_flag; + short index_max, index_min, index_rad; + short difidx_org[NB_SFM]; /* lenght of this buffer is max(BANDS_MAX,NB_SFM) */ + short m, r; + short v, k; + + set_s( difidx_org, 0, NB_SFM ); + difidx_flag = 0; + + /*------------------------------------------------------------------* + * Check Huffman encoding for QNorm indices + *------------------------------------------------------------------*/ + + /* LC mode index is changed to synchronize LR-MDCT signaling */ + /* LC mode 0 = Context based coding */ + /* LC mode 1 = resized huffman coding */ + /* LC mode 2 = normal Huffman Coding */ + /* LC mode 3 = bit packing */ + if ( flag_pack == 0 ) + { + if(is_transient && flag_HQ2 == LOW_RATE_HQ_CORE_TRAN) + { + bits = 0; + index_max = 0; + index_min = 31; + for( i = 0; i< num_sfm; i++ ) + { + if( difidx[i] > index_max ) + { + index_max = difidx[i]; + } + if( difidx[i] < index_min ) + { + index_min = difidx[i]; + } + } + if(index_min > 10 && index_max < 22) + { + for( i = 1; i < num_sfm; i++ ) + { + j = difidx[i]; + bits += huffsizn_tran[j]; + } + } + hcode_l= 0; + *LCmode = 0; + prevj = difidx[0] + OFFSET_NORM; + /* LC mode 0 = Context based coding */ + for( i = 1; i < num_sfm; i++ ) + { + j = difidx[i]; + if( prevj>HTH_NORM ) + { + /* above */ + hcode_l += huffsizn_n[31-j]; + } + else + { + if( prevj= bits && bits !=0) + { + /* LC mode 1 Transient Huffman Coding */ + *LCmode = 1; + hcode_l = bits; + } + } + else + { + /* Check bits if LC mode == 3 -> Check bits if LC mode == 0 */ + hcode_l= 0; + prevj = difidx[0] + OFFSET_NORM; + for( i = 1; i < num_sfm; i++ ) + { + j = difidx[i]; + if( prevj>HTH_NORM ) + { + /* above */ + hcode_l += huffsizn_n[31-j]; + } + else + { + if( prevj Check bits if LC mode == 2 */ + bits = 0; + for( i = 1; i < num_sfm; i++ ) + { + j = difidx[i]; + bits += huffsizn[j]; + } + + /*------------------------------------------------------------------------------* + * comparing bit expenses of coding mode 2 with that of the optimal coding mode + *------------------------------------------------------------------------------*/ + + if( hcode_l > bits ) + { + *LCmode = 2; + hcode_l = bits; + } + } + + /* Check bits if LC mode == 2 -> Check bits if LC mode == 1 */ + bits = 0; + index_max = 0; + index_min = 31; + for( i = 1; i < num_sfm; i++ ) + { + difidx_org[i] = difidx[i]; + } + + difidx_flag = 0; + for( i = 2; i < num_sfm; i++ ) + { + if( difidx_org[i-1] > 17 ) + { + difidx[i] = difidx_org[i] + min((difidx_org[i-1]-17),3); + if( difidx[i] > 31 ) + { + difidx_flag = 1; + break; + } + } + + if( difidx_org[i-1] < 13 ) + { + difidx[i] = difidx_org[i] + max((difidx_org[i-1]-13),-3); + if( difidx[i] < 0 ) + { + difidx_flag = 1; + break; + } + } + } + + index_rad = 0; + if( difidx_flag != 1 ) + { + for( i = 1; i< num_sfm; i++ ) + { + if( difidx[i] > index_max ) + { + index_max = difidx[i]; + } + + if( difidx[i] < index_min ) + { + index_min = difidx[i]; + } + } + + index_rad = max((15 - index_min),(index_max - 15)); + + if( index_rad <= HUFF_THR ) + { + for( i = 1; i < num_sfm; i++ ) + { + j = difidx[i]; + bits += resize_huffsizn[j]; + } + + /*------------------------------------------------------------------* + * comparing bit expenses of coding mode 1 with that of coding mode 0 + *------------------------------------------------------------------*/ + + if( hcode_l > bits ) + { + hcode_l = bits; + *LCmode = 1; + } + } + } + + /* LR-MDCT core doesn't have coding mode 2 and 3 */ + if( flag_HQ2 == NORMAL_HQ_CORE ) + { + /*------------------------------------------------------------------------------* + * comparing bit expenses of coding mode 3 with that of the optimal coding mode + *------------------------------------------------------------------------------*/ + + if( hcode_l >= numnrmibits ) + { + hcode_l = numnrmibits; + *LCmode = 3; + } + } + + if( (*LCmode != 1 && flag_HQ2 == NORMAL_HQ_CORE ) || flag_HQ2 == LOW_RATE_HQ_CORE ) + { + for(i = 2; i< num_sfm; i++) + { + difidx[i] = difidx_org[i]; + } + } + } + } + else + { + if(flag_HQ2 == LOW_RATE_HQ_CORE_TRAN || flag_HQ2 == LOW_RATE_HQ_CORE) + { + push_indice( st, IND_HQ2_DENG_HMODE, *LCmode, BITS_DE_HMODE); + push_indice( st, IND_HQ2_DIFF_ENERGY, difidx[0], BITS_DE_FCOMP); + } + else + { + push_indice( st, IND_LC_MODE, *LCmode, 2 ); + push_indice( st, IND_YNRM, difidx[0], NORM0_BITS ); + } + + if(is_transient && flag_HQ2 == LOW_RATE_HQ_CORE_TRAN) + { + hcode_l = 0; + if ( *LCmode == 1 ) + { + /* LC mode 0 Transient Huffman Coding */ + for( i = 1; i < num_sfm; i++ ) + { + j = difidx[i]; + m = huffnorm_tran[j]; + r = huffsizn_tran[j]; + v = 0; + + /* Bit reverse */ + for( k = 0; k < r; k++ ) + { + v <<= 1; + v |= m & 1; + m >>= 1; + } + + push_indice(st,IND_HQ2_DIFF_ENERGY, v, r); + } + } + else + { + /* LC mode 1 context based Coding */ + prevj = difidx[0] + OFFSET_NORM; + for( i = 1; i < num_sfm; i++ ) + { + j = difidx[i]; + + if( prevj > HTH_NORM ) + { + /* above */ + r = huffsizn_n[31-j]; + m = huffnorm_n[31-j]; + } + else + { + if( prevj LC mode 0 */ + prevj = difidx[0] + OFFSET_NORM; + for( i = 1; i < num_sfm; i++ ) + { + j = difidx[i]; + + if( prevj > HTH_NORM ) + { + /* above */ + r = huffsizn_n[31-j]; + m = huffnorm_n[31-j]; + } + else + { + if( prevj 17) + { + difidx[i] = difidx_org[i] + min((difidx_org[i-1]-17),3); + if(difidx[i] > 31) + { + difidx_flag = 1; + break; + } + } + + if(difidx_org[i-1] < 13) + { + difidx[i] = difidx_org[i] + max((difidx_org[i-1]-13),-3); + if(difidx[i] < 0) + { + difidx_flag = 1; + break; + } + } + } + + if( difidx_flag != 1 ) + { + for(i = 1; i< num_sfm; i++) + { + if(difidx[i]>index_max) + { + index_max = difidx[i]; + } + + if(difidx[i] LC mode 1 */ + for( i = 1; i < num_sfm; i++ ) + { + j = difidx[i]; + + m = resize_huffnorm[j]; + r = resize_huffsizn[j]; + v = 0; + + /* Bit reverse */ + for( k = 0; k < r; k++ ) + { + v <<= 1; + v |= m & 1; + m >>= 1; + } + + if ( flag_HQ2 ) + { + push_indice( st,IND_HQ2_DIFF_ENERGY, v, r); + } + else + { + push_indice( st, IND_YNRM, v, r ); + } + } + } + else if( *LCmode == 2 ) + { + /* LC mode 1 -> LC mode 2 */ + for( i = 1; i < num_sfm; i++ ) + { + j = difidx[i]; + + m = huffnorm[j]; + r = huffsizn[j]; + + push_indice( st, IND_YNRM, m, r ); + } + } + else + { + for( i = 1; i < num_sfm; i++ ) + { + push_indice( st, IND_YNRM, difidx[i], NORMI_BITS ); + } + } + } + } + + return hcode_l; +} + +/*--------------------------------------------------------------------------* + * diff_envelope_coding() + * + * Create differential code of norm indices + *--------------------------------------------------------------------------*/ + +void diff_envelope_coding( + const short is_transient, /* i : transient indicator */ + const short num_env_bands, /* i : number of envelope bands to code */ + const short start_norm, /* i : start of envelope coding */ + short *ynrm, /* i/o: quantization indices for norms */ + short *normqlg2, /* i/o: quantized norms */ + short *difidx /* o : differential code */ +) +{ + short i; + short idxbuf[NB_SFM]; + short normbuf[NB_SFM]; + + /* Differential coding for indices of quantized norms */ + if( is_transient ) + { + /* Reorder quantization indices and quantized norms */ + reordernorm( ynrm, normqlg2, idxbuf, normbuf, num_env_bands ); + diffcod( num_env_bands, idxbuf, &difidx[1] ); + difidx[0] = idxbuf[0]; + recovernorm( idxbuf, ynrm, normqlg2, num_env_bands ); + } + else + { + diffcod( num_env_bands, &ynrm[start_norm], &difidx[1] ); + difidx[0] = ynrm[start_norm]; + + for( i = start_norm; i < start_norm + num_env_bands; i++ ) + { + normqlg2[i] = dicnlg2[ynrm[i]]; + } + } + + return; +} diff --git a/src/libs/libevs/lib_enc/hq_env_enc_fx.cpp b/src/libs/libevs/lib_enc/hq_env_enc_fx.cpp deleted file mode 100755 index a78c46bf..00000000 --- a/src/libs/libevs/lib_enc/hq_env_enc_fx.cpp +++ /dev/null @@ -1,597 +0,0 @@ -/*==================================================================================== - EVS Codec 3GPP TS26.442 Apr 03, 2018. Version 12.11.0 / 13.6.0 / 14.2.0 - ====================================================================================*/ - -#include -#include "options.h" /* Compilation switches */ -#include "prot_fx.h" /* Function prototypes */ -#include "rom_enc_fx.h" -#include "stl.h" - -/*--------------------------------------------------------------------------------------* - * encode_envelope_indices_fx() - * - * Encode envelope indices - *--------------------------------------------------------------------------------------*/ - -Word16 encode_envelope_indices_fx( /* o : Number of bits if flag_pack=0,0 if flag_pack=1 Q0 */ - Encoder_State_fx *st_fx, /* i/o: encoder state structure */ - const Word16 num_sfm, /* i : Number of subbands Q0 */ - const Word16 numnrmibits, /* i : Bitrate of fall-back coding mode Q0 */ - Word16 *difidx, /* i/o: Diff indices/encoded diff indices Q0 */ - Word16 *LCmode, /* o : Coding mode if flag_pack=0, i : if flag_pack=1 Q0 */ - const Word16 flag_pack, /* i : indicator of packing or estimating bits Q0 */ - const Word16 flag_HQ2 /* i : indicator of HQ2 core Q0 */ - ,const Word16 is_transient /* i : indicator of HQ_TRANSIENT Q0 */ -) -{ - Word16 bits; - Word16 prevj; - Word16 hcode_l; - Word16 i,j; - Word16 difidx_flag; - Word16 index_max, index_min, index_rad; - Word16 difidx_org[NB_SFM]; /* lenght of this buffer is max(BANDS_MAX,NB_SFM) */ - Word16 m, r; - Word16 v, k; - - set16_fx( difidx_org, 0, NB_SFM ); - difidx_flag = 0; - move16(); - - /*------------------------------------------------------------------* - * Check Huffman encoding for QNorm indices - *------------------------------------------------------------------*/ - - /* LC mode index is changed to synchronize LR_MDCT signaling */ - /* LC mode 0 = Context based coding */ - /* LC mode 1 = resized huffman coding */ - /* LC mode 2 = normal Huffman Coding */ - /* LC mode 3 = bit packing */ - IF ( flag_pack == 0 ) - { - test(); - IF( is_transient && sub(flag_HQ2, LOW_RATE_HQ_CORE_TRAN) == 0) - { - bits = 0; - move16(); - index_max = 0; - move16(); - index_min = 31; - move16(); - FOR( i = 0; i< num_sfm; i++ ) - { - IF( sub(difidx[i], index_max) > 0 ) - { - index_max = difidx[i]; - move16(); - } - IF( sub(difidx[i], index_min) < 0 ) - { - index_min = difidx[i]; - move16(); - } - } - test(); - IF(sub(index_min, 10) > 0 && sub(index_max, 22) < 0) - { - FOR( i = 1; i < num_sfm; i++ ) - { - j = difidx[i]; - move16(); - bits = add(bits, huffsizn_tran[j]); - } - } - hcode_l= 0; - move16(); - *LCmode = 0; - move16(); - prevj = add(difidx[0], OFFSET_NORM); - /* LC mode 0 = Context based coding */ - FOR( i = 1; i < num_sfm; i++ ) - { - j = difidx[i]; - move16(); - IF( sub(prevj, HTH_NORM) > 0 ) - { - /* above */ - hcode_l = add(hcode_l, huffsizn_n_fx[31-j]); - } - ELSE - { - IF( sub(prevj, LTH_NORM) < 0 ) - { - /* less */ - hcode_l = add(hcode_l, huffsizn_n_fx[j]); - } - ELSE - { - /* equal */ - hcode_l = add(hcode_l, huffsizn_e_fx[j]); - } - } - prevj = j; - move16(); - } - test(); - IF( sub(hcode_l, bits) >= 0 && bits !=0) - { - /* LC mode 1 Transient Huffman Coding */ - *LCmode = 1; - move16(); - hcode_l = bits; - move16(); - } - } - ELSE - { - /* Check bits if LC mode == 3 -> Check bits if LC mode == 0 */ - hcode_l= 0; - move16(); - prevj = add(difidx[0], OFFSET_NORM); - FOR( i = 1; i < num_sfm; i++ ) - { - j = difidx[i]; - move16(); - IF( sub(prevj, HTH_NORM) > 0 ) - { - /* above */ - hcode_l = add(hcode_l, huffsizn_n_fx[sub(31,j)]); - } - ELSE - { - IF( sub(prevj, LTH_NORM) < 0 ) - { - /* less */ - hcode_l = add(hcode_l, huffsizn_n_fx[j]); - } - ELSE - { - /* equal */ - hcode_l = add(hcode_l, huffsizn_e_fx[j]); - } - } - prevj = j; - move16(); - } - - *LCmode = 0; - move16(); - - /* LR-MDCT core doesn't have coding mode 2 and 3 */ - IF( flag_HQ2 == NORMAL_HQ_CORE ) - { - /* Check bits if LC mode == 1 -> Check bits if LC mode == 2 */ - bits = 0; - move16(); - FOR( i = 1; i < num_sfm; i++ ) - { - j = difidx[i]; - move16(); - bits = add(bits, huffsizn[j]); - } - - /*------------------------------------------------------------------------------* - * comparing bit expenses of coding mode 2 with that of the optimal coding mode - *------------------------------------------------------------------------------*/ - - if( sub(hcode_l, bits) > 0 ) - { - *LCmode = 2; - move16(); - } - hcode_l = s_min(hcode_l, bits); - } - - /* Check bits if LC mode == 2 -> Check bits if LC mode == 1 */ - bits = 0; - move16(); - index_max = 0; - move16(); - index_min = 31; - move16(); - FOR( i = 1; i < num_sfm; i++ ) - { - difidx_org[i] = difidx[i]; - move16(); - } - - difidx_flag = 0; - move16(); - FOR( i = 2; i < num_sfm; i++ ) - { - IF( sub(difidx_org[i-1], 17) > 0 ) - { - difidx[i] = add(difidx_org[i], s_min(sub(difidx_org[i-1],17),3)); - move16(); - IF( sub(difidx[i], 31) > 0 ) - { - difidx_flag = 1; - move16(); - BREAK; - } - } - - IF( sub(difidx_org[i-1], 13) < 0 ) - { - difidx[i] = add(difidx_org[i], s_max(sub(difidx_org[i-1],13),-3)); - move16(); - IF( difidx[i] < 0 ) - { - difidx_flag = 1; - move16(); - BREAK; - } - } - } - - index_rad = 0; - move16(); - IF( difidx_flag == 0 ) - { - FOR( i = 1; i< num_sfm; i++ ) - { - index_max = s_max(index_max, difidx[i]); - index_min = s_min(index_min, difidx[i]); - } - - index_rad = s_max(sub(15, index_min),sub(index_max, 15)); - - IF( sub(index_rad, HUFF_THR) <= 0 ) - { - FOR( i = 1; i < num_sfm; i++ ) - { - j = difidx[i]; - move16(); - bits = add(bits, resize_huffsizn[j]); - } - - /*------------------------------------------------------------------* - * comparing bit expenses of coding mode 1 with that of coding mode 0 - *------------------------------------------------------------------*/ - - if( sub(hcode_l, bits) > 0 ) - { - *LCmode = 1; - move16(); - } - hcode_l = s_min(hcode_l, bits); - - } - } - - /* LR-MDCT core doesn't have coding mode 2 and 3 */ - IF( flag_HQ2 == NORMAL_HQ_CORE ) - { - /*------------------------------------------------------------------------------* - * comparing bit expenses of coding mode 3 with that of the optimal coding mode - *------------------------------------------------------------------------------*/ - - if( sub(hcode_l, numnrmibits) >= 0 ) - { - *LCmode = 3; - move16(); - } - hcode_l = s_min(hcode_l, numnrmibits); - } - - test(); - test(); - IF( (sub(*LCmode, 1) != 0 && flag_HQ2 == NORMAL_HQ_CORE ) || sub(flag_HQ2, LOW_RATE_HQ_CORE) == 0 ) - { - FOR(i = 2; i< num_sfm; i++) - { - difidx[i] = difidx_org[i]; - move16(); - } - } - } - } - ELSE - { - test(); - IF( sub(flag_HQ2, LOW_RATE_HQ_CORE_TRAN) == 0 || sub(flag_HQ2, LOW_RATE_HQ_CORE) == 0 ) - { - push_indice_fx( st_fx, IND_HQ2_DENG_HMODE, *LCmode, BITS_DE_HMODE); - push_indice_fx( st_fx, IND_HQ2_DIFF_ENERGY, difidx[0], BITS_DE_FCOMP); - } - ELSE - { - push_indice_fx( st_fx, IND_LC_MODE, *LCmode, 2 ); - push_indice_fx( st_fx, IND_YNRM, difidx[0], NORM0_BITS ); - } - - test(); - IF(is_transient && sub(flag_HQ2, LOW_RATE_HQ_CORE_TRAN) == 0) - { - hcode_l = 0; - move16(); - IF ( sub(*LCmode, 1) == 0 ) - { - /* LC mode 0 Transient Huffman Coding */ - FOR( i = 1; i < num_sfm; i++ ) - { - j = difidx[i]; - move16(); - m = huffnorm_tran[j]; - move16(); - r = huffsizn_tran[j]; - move16(); - v = 0; - move16(); - - /* Bit reverse */ - FOR( k = 0; k < r; k++ ) - { - v = lshl(v, 1); - v = s_or(v, s_and(m, 1)); - m = lshr(m, 1); - } - - push_indice_fx(st_fx, IND_HQ2_DIFF_ENERGY, v, r); - } - } - ELSE - { - /* LC mode 1 context based Coding */ - prevj = add(difidx[0], OFFSET_NORM); - FOR( i = 1; i < num_sfm; i++ ) - { - j = difidx[i]; - move16(); - - IF( sub(prevj, HTH_NORM) > 0 ) - { - /* above */ - r = huffsizn_n_fx[sub(31,j)]; - move16(); - m = huffnorm_n_fx[sub(31,j)]; - move16(); - } - ELSE - { - IF( sub(prevj, LTH_NORM) < 0 ) - { - /* less */ - r = huffsizn_n_fx[j]; - move16(); - m = huffnorm_n_fx[j]; - move16(); - } - ELSE - { - /* equal */ - r = huffsizn_e_fx[j]; - move16(); - m = huffnorm_e_fx[j]; - move16(); - } - } - push_indice_fx(st_fx, IND_HQ2_DIFF_ENERGY, m, r); - prevj = j; - move16(); - } - } - } - ELSE - { - hcode_l = 0; - move16(); - IF ( *LCmode == 0 ) - { - /* LC mode 3 -> LC mode 0 */ - prevj = add(difidx[0], OFFSET_NORM); - FOR( i = 1; i < num_sfm; i++ ) - { - j = difidx[i]; - move16(); - - IF( sub(prevj, HTH_NORM) > 0 ) - { - /* above */ - r = huffsizn_n_fx[sub(31,j)]; - move16(); - m = huffnorm_n_fx[sub(31,j)]; - move16(); - } - ELSE - { - IF( sub(prevj, LTH_NORM) < 0 ) - { - /* less */ - r = huffsizn_n_fx[j]; - move16(); - m = huffnorm_n_fx[j]; - move16(); - } - ELSE - { - /* equal */ - r = huffsizn_e_fx[j]; - move16(); - m = huffnorm_e_fx[j]; - move16(); - } - } - - IF( sub(flag_HQ2, LOW_RATE_HQ_CORE) == 0 ) - { - push_indice_fx(st_fx, IND_HQ2_DIFF_ENERGY, m, r); - } - ELSE - { - push_indice_fx( st_fx, IND_YNRM, m, r ); - } - - prevj = j; - move16(); - } - } - ELSE IF( sub(*LCmode, 1) == 0 ) - { - IF ( sub(flag_HQ2, 1) == 0 ) - { - index_max = 0; - move16(); - index_min = 31; - move16(); - FOR(i = 1; i< num_sfm; i++) - { - difidx_org[i] = difidx[i]; - move16(); - } - - FOR(i = 2; i< num_sfm; i++) - { - IF(sub(difidx_org[i-1], 17) > 0) - { - difidx[i] = add(difidx_org[i], s_min(sub(difidx_org[i-1],17),3)); - move16(); - IF(sub(difidx[i], 31) > 0) - { - difidx_flag = 1; - move16(); - BREAK; - } - } - - IF(sub(difidx_org[i-1], 13) < 0) - { - difidx[i] = add(difidx_org[i], s_max(sub(difidx_org[i-1],13),-3)); - move16(); - IF(difidx[i] < 0) - { - difidx_flag = 1; - move16(); - BREAK; - } - } - } - - IF( difidx_flag == 0 ) - { - FOR(i = 1; i< num_sfm; i++) - { - index_max = s_max(index_max, difidx[i]); - index_min = s_min(index_min, difidx[i]); - } - - index_rad = s_max(sub(15, index_min),sub(index_max, 15)); - - IF(sub(index_rad, HUFF_THR) <= 0) - { - FOR (i = 1; i < num_sfm; i++) - { - j = difidx[i]; - move16(); - } - } - } - } - - /* LC mode 2 -> LC mode 1 */ - FOR( i = 1; i < num_sfm; i++ ) - { - j = difidx[i]; - move16(); - - m = resize_huffnorm_fx[j]; - move16(); - r = resize_huffsizn[j]; - move16(); - v = 0; - move16(); - - /* Bit reverse */ - FOR( k = 0; k < r; k++ ) - { - v = lshl(v, 1); - v = s_or(v,s_and(m, 1)); - m = lshr(m, 1); - } - - IF ( flag_HQ2 == 0 ) - { - push_indice_fx( st_fx, IND_YNRM, v, r ); - } - ELSE - { - push_indice_fx( st_fx, IND_HQ2_DIFF_ENERGY, v, r); - } - } - } - ELSE IF( sub(*LCmode, 2) == 0 ) - { - /* LC mode 1 -> LC mode 2 */ - FOR( i = 1; i < num_sfm; i++ ) - { - j = difidx[i]; - move16(); - - m = huffnorm_fx[j]; - move16(); - r = huffsizn[j]; - move16(); - - push_indice_fx( st_fx, IND_YNRM, m, r ); - } - } - ELSE - { - FOR( i = 1; i < num_sfm; i++ ) - { - push_indice_fx( st_fx, IND_YNRM, difidx[i], NORMI_BITS ); - } - } - } - } - - return hcode_l; -} - -/*--------------------------------------------------------------------------* - * diff_envelope_coding_fx() - * - * Differential envelope coding - *--------------------------------------------------------------------------*/ - -void diff_envelope_coding_fx( - const Word16 is_transient, /* i : transient indicator Q0 */ - const Word16 num_env_bands, /* i : number of envelope bands to code Q0 */ - const Word16 start_norm, /* i : start of envelope coding Q0 */ - Word16 *ynrm, /* i/o: quantization indices for norms Q0 */ - Word16 *normqlg2, /* i/o: quantized norms Q0 */ - Word16 *difidx /* o : differential code Q0 */ -) -{ - Word16 i, tmp; - Word16 idxbuf[NB_SFM]; - Word16 normbuf[NB_SFM]; - - /* Differential coding for indices of quantized norms */ - IF( is_transient != 0 ) - { - /* Reorder quantization indices and quantized norms */ - reordernorm_fx( ynrm, normqlg2, idxbuf, normbuf, num_env_bands ); - diffcod_fx( num_env_bands, idxbuf, &difidx[1] ); - difidx[0] = idxbuf[0]; - move16(); - recovernorm_fx( idxbuf, ynrm, normqlg2, num_env_bands ); - } - ELSE - { - diffcod_fx( num_env_bands, &ynrm[start_norm], &difidx[1] ); - difidx[0] = ynrm[start_norm]; - move16(); - - tmp = add(start_norm, num_env_bands); - FOR( i = start_norm; i < tmp; i++ ) - { - normqlg2[i] = dicnlg2[ynrm[i]]; - move16(); - move16(); - } - } - - return; -} diff --git a/src/libs/libevs/lib_enc/hq_hr_enc.cpp b/src/libs/libevs/lib_enc/hq_hr_enc.cpp new file mode 100644 index 00000000..5083822f --- /dev/null +++ b/src/libs/libevs/lib_enc/hq_hr_enc.cpp @@ -0,0 +1,196 @@ +/*==================================================================================== + EVS Codec 3GPP TS26.443 Nov 13, 2018. Version 12.11.0 / 13.7.0 / 14.3.0 / 15.1.0 + ====================================================================================*/ + +#include +#include "options.h" +#include "cnst.h" +#include "prot.h" +#include "rom_enc.h" +#include "rom_com.h" + +/*--------------------------------------------------------------------------* + * hq_hr_enc() + * + * HQ high rate encoding routine + *--------------------------------------------------------------------------*/ + +void hq_hr_enc( + Encoder_State *st, /* i/o: encoder state structure */ + float *t_audio, /* i/o: transform-domain coefficients */ + const short length, /* i : length of spectrum */ + short *num_bits, /* i : number of available bits */ + const short is_transient /* i : transient flag */ +) +{ + short nb_sfm; + short sum, hcode_l; + short difidx[NB_SFM]; + short normqlg2[NB_SFM], ynrm[NB_SFM]; + short nf_idx; + short LCmode; + short shape_bits, num_sfm, numnrmibits; + short hqswb_clas; + short num_env_bands; + short Npeaks, start_norm; + short difidx_org[NB_SFM]; + short R[NB_SFM]; + short peaks[HVQ_MAX_PEAKS]; + const short *sfmsize, *sfm_start, *sfm_end; + short npulses[NB_SFM], maxpulse[NB_SFM]; + short Rsubband[NB_SFM]; /* Q3 */ + float t_audio_q[L_FRAME48k]; + float nf_gains[HVQ_NF_GROUPS], pe_gains[HVQ_NF_GROUPS]; + float noise_level[HVQ_BWE_NOISE_BANDS]; + short hq_generic_offset; + float hq_generic_fenv[HQ_FB_FENV]; + short hq_generic_exc_clas = 0; + short core_sfm; + short har_freq_est1 = 0, har_freq_est2 = 0; + short flag_dis = 1; + const short *subband_search_offset; + short wBands[2]; + short b_delta_env; + + /*------------------------------------------------------------------* + * Initializations + *------------------------------------------------------------------*/ + + Npeaks = 0; + set_s( npulses, 0, NB_SFM ); + set_s( maxpulse, 0, NB_SFM ); + set_s( difidx_org, 0, NB_SFM ); + set_f( t_audio_q, 0.0f, L_FRAME48k ); + set_f( nf_gains, 0.0f, HVQ_NF_GROUPS ); + set_f( pe_gains, 0.0f, HVQ_NF_GROUPS ); + + /*------------------------------------------------------------------* + * Classification + *------------------------------------------------------------------*/ + + *num_bits -= hq_classifier_enc( st, length, t_audio, is_transient, &Npeaks, peaks, pe_gains, nf_gains, &hqswb_clas ); + + /*------------------------------------------------------------------* + * Set quantization parameters + *------------------------------------------------------------------*/ + + hq_configure( length, hqswb_clas, st->core_brate, &num_sfm, &nb_sfm, &start_norm, &num_env_bands, &numnrmibits, &hq_generic_offset, + &sfmsize, &sfm_start, &sfm_end ); + + /*------------------------------------------------------------------* + * Transient frame handling + *------------------------------------------------------------------*/ + + /* Interleave MLT coefficients of 4 sub-vectors in case of transient frame */ + if( is_transient ) + { + interleave_spectrum( t_audio, length ); + } + + /*------------------------------------------------------------------* + * Scalar quantization of norms + * Encode norm indices + *------------------------------------------------------------------*/ + + /* calculate and quantize norms */ + calc_norm( t_audio, ynrm, normqlg2, start_norm, num_env_bands, sfmsize, sfm_start ); + + /* create differential code of quantized norm indices */ + diff_envelope_coding( is_transient, num_env_bands, start_norm, ynrm, normqlg2, difidx ); + + /* Find norm coding mode and calculate number of bits */ + hcode_l = encode_envelope_indices( st, num_env_bands, numnrmibits, difidx, &LCmode, 0, NORMAL_HQ_CORE, is_transient ); + *num_bits -= hcode_l + NORM0_BITS + FLAGS_BITS; + + /* Encode norm indices */ + encode_envelope_indices( st, num_env_bands, numnrmibits, difidx, &LCmode, 1, NORMAL_HQ_CORE, is_transient ); + + /*------------------------------------------------------------------* + * HQ GENERIC BWE encoding + *------------------------------------------------------------------*/ + + if ( hqswb_clas == HQ_GEN_SWB || hqswb_clas == HQ_GEN_FB ) + { + hq_generic_hf_encoding( t_audio, hq_generic_fenv, hq_generic_offset, st, &hq_generic_exc_clas ); + if (hq_generic_exc_clas == HQ_GENERIC_SP_EXC) + { + (*num_bits)++; /* conditional 1 bit saving for representing FD3 BWE excitation class */ + } + map_hq_generic_fenv_norm(hqswb_clas, hq_generic_fenv, ynrm, normqlg2, num_env_bands, nb_sfm, hq_generic_offset); + } + + /*------------------------------------------------------------------* + * Bit allocation + *------------------------------------------------------------------*/ + + hq_bit_allocation( st->core_brate, length, hqswb_clas, num_bits, normqlg2, + nb_sfm, sfmsize, noise_level, R, Rsubband, &sum, + &core_sfm, num_env_bands); + + /*------------------------------------------------------------------* + * Normalize coefficients with quantized norms + *------------------------------------------------------------------*/ + if( hqswb_clas != HQ_HVQ ) + { + if (hqswb_clas == HQ_GEN_SWB || hqswb_clas == HQ_GEN_FB) + { + b_delta_env = calc_nor_delta_hf( st, t_audio, ynrm, Rsubband, num_env_bands, nb_sfm, sfmsize, sfm_start, core_sfm ); + sum -= b_delta_env; + } + normalizecoefs( t_audio, ynrm, nb_sfm, sfm_start, sfm_end ); + } + + /*------------------------------------------------------------------* + * Quantize/code spectral fine structure using PVQ or HVQ + *------------------------------------------------------------------*/ + + if( hqswb_clas == HQ_HVQ ) + { + sum = hvq_enc( st, st->core_brate, *num_bits, Npeaks, ynrm, R, peaks, nf_gains, + noise_level, pe_gains, t_audio, t_audio_q ); + *num_bits -= sum; + } + else + { + shape_bits = pvq_core_enc( st, t_audio, t_audio_q, sum, nb_sfm, sfm_start, sfm_end, sfmsize, Rsubband, R, npulses, maxpulse, HQ_CORE ); + *num_bits += (sum - shape_bits); + } + + if( hqswb_clas == HQ_HVQ || hqswb_clas == HQ_HARMONIC ) + { + subband_search_offset = subband_search_offsets_13p2kbps_Har; + wBands[0] = SWB_SB_BW_LEN0_16KBPS_HAR; + wBands[1] = SWB_SB_BW_LEN1_16KBPS_HAR; + + har_est( t_audio_q, 300, &har_freq_est1, &har_freq_est2, &flag_dis, &st->prev_frm_hfe2, subband_search_offset, wBands, &st->prev_stab_hfe2 ); + + st->prev_frm_hfe2 = har_freq_est2; + } + + if( hqswb_clas != HQ_HARMONIC || hqswb_clas != HQ_HVQ || flag_dis == 0) + { + st->prev_frm_hfe2 = 0; /*reset*/ + st->prev_stab_hfe2 = 0; /*reset*/ + } + + nf_idx = 0; + if ( !is_transient && hqswb_clas != HQ_HVQ && !(length == L_FRAME16k && st->core_brate == HQ_32k) ) + { + if (hqswb_clas == HQ_GEN_SWB || hqswb_clas == HQ_GEN_FB) + { + nf_idx = noise_adjust( t_audio, R, sfm_start, sfm_end, max(core_sfm,num_env_bands-1)); + push_indice( st, IND_NF_IDX, nf_idx, 2 ); + } + else + { + nf_idx = noise_adjust( t_audio, R, sfm_start, sfm_end, core_sfm ); + push_indice( st, IND_NF_IDX, nf_idx, 2 ); + } + } + + + /* updates */ + st->prev_hqswb_clas = hqswb_clas; + + return; +} diff --git a/src/libs/libevs/lib_enc/hq_hr_enc_fx.cpp b/src/libs/libevs/lib_enc/hq_hr_enc_fx.cpp deleted file mode 100755 index 31711eaa..00000000 --- a/src/libs/libevs/lib_enc/hq_hr_enc_fx.cpp +++ /dev/null @@ -1,235 +0,0 @@ -/*==================================================================================== - EVS Codec 3GPP TS26.442 Apr 03, 2018. Version 12.11.0 / 13.6.0 / 14.2.0 - ====================================================================================*/ - -#include "options.h" /* Compilation switches */ -#include "cnst_fx.h" /* Common constants */ -#include "prot_fx.h" /* Function prototypes */ -#include "rom_com_fx.h" /* Static table prototypes */ -#include "stl.h" - -/*--------------------------------------------------------------------------* - * hq_hr_enc_fx() - * - * HQ High rate encoding routine - *--------------------------------------------------------------------------*/ -void hq_hr_enc_fx( - Encoder_State_fx *st_fx, /* i/o: encoder state structure fx */ - Word32 *t_audio, /* i/o: transform-domain coefficients Q12 */ - const Word16 length, /* i : length of spectrum Q0 */ - Word16 *num_bits, /* i : number of available bits Q0 */ - const Word16 is_transient /* i : transient flag Q0 */ -) -{ - Word16 nb_sfm; /* Q0 */ - Word16 sum, hcode_l; /* Q0 */ - Word16 difidx[NB_SFM]; /* Q0 */ - Word16 normqlg2[NB_SFM], ynrm[NB_SFM]; /* Q0 */ - Word16 nf_idx; /* Q0 */ - Word16 bits; /* */ - Word16 LCmode; /* Q0 */ - Word16 shape_bits, num_sfm, numnrmibits; /* Q0 */ - Word16 hqswb_clas; /* Q0 */ - Word16 num_env_bands; /* Q0 */ - Word16 Npeaks, start_norm; /* Q0 */ - Word16 difidx_org[NB_SFM]; /* Q0 */ - Word16 R[NB_SFM]; /* Q0 */ - Word16 peaks[HVQ_MAX_PEAKS]; /* Q0 */ - const Word16 *sfmsize, *sfm_start, *sfm_end; /* Q0 */ - Word16 npulses[NB_SFM], maxpulse[NB_SFM]; /* Q0 */ - Word16 Rsubband[NB_SFM]; /* Q3 */ - Word32 t_audio_q[L_FRAME48k]; /* Q12 */ - Word32 nf_gains[HVQ_NF_GROUPS]; /* Q12 */ - Word32 pe_gains[HVQ_NF_GROUPS]; /* Q12 */ - Word16 noise_level[HVQ_BWE_NOISE_BANDS]; /* Q15 */ - Word16 hq_generic_offset; /* Q0 */ - Word16 hq_generic_fenv[HQ_FB_FENV]; /* Q1 */ - Word16 hq_generic_exc_clas = 0; /* Q0 */ - Word16 core_sfm; /* Q0 */ - Word16 har_freq_est1, har_freq_est2; - Word16 flag_dis; - const Word16 *subband_search_offset; - Word16 wBands[2]; - - Word16 t_audio_norm[L_FRAME48k]; - Word16 t_audio_q_norm[L_FRAME48k]; - Word16 Q_audio; - Word16 i; - Word16 b_delta_env; - Word16 Q_shift; - - /*------------------------------------------------------------------* - * Initializations - *------------------------------------------------------------------*/ - - Npeaks = 0; - Q_audio = 0; /* to avoid compilation warnings */ - - set16_fx( npulses, 0, NB_SFM ); - set16_fx( maxpulse, 0, NB_SFM ); - set16_fx( difidx_org, 0, NB_SFM ); - set32_fx( t_audio_q, 0, L_FRAME48k ); - set32_fx( nf_gains, 0, HVQ_NF_GROUPS ); - set32_fx( pe_gains, 0, HVQ_NF_GROUPS ); - flag_dis = 1; - move16(); - har_freq_est1 = 0; - move16(); - har_freq_est2 = 0; - move16(); - - /*------------------------------------------------------------------* - * Classification - *------------------------------------------------------------------*/ - - bits = hq_classifier_enc_fx( st_fx, length, t_audio, is_transient, &Npeaks, peaks, pe_gains, nf_gains, &hqswb_clas ); - - *num_bits = sub(*num_bits, bits); - - /*------------------------------------------------------------------* - * set quantization parameters - *------------------------------------------------------------------*/ - - hq_configure_fx( length, hqswb_clas, st_fx->core_brate_fx, &num_sfm, &nb_sfm, &start_norm, &num_env_bands, &numnrmibits, &hq_generic_offset, - &sfmsize, &sfm_start, &sfm_end ); - - /*------------------------------------------------------------------* - * Transient frame handling - *------------------------------------------------------------------*/ - - /* Interleave MLT coefficients of 4 sub-vectors in case of transient */ - IF( sub( is_transient, 1 ) == 0 ) - { - interleave_spectrum_fx( t_audio, length ); - } - - /*------------------------------------------------------------------* - * Scalar quantization of norms - * Encode norm indices - *------------------------------------------------------------------*/ - - /* calculate and quantize norms */ - calc_norm_fx( t_audio, 12, ynrm, normqlg2, start_norm, num_env_bands, sfmsize, sfm_start ); - - /* create differential code of quantized norm indices */ - diff_envelope_coding_fx(is_transient, num_env_bands, start_norm, ynrm, normqlg2, difidx); - - /* Find coding mode and calculate bit rate */ - hcode_l = encode_envelope_indices_fx( st_fx, num_env_bands, numnrmibits, difidx, &LCmode, 0, NORMAL_HQ_CORE, is_transient ); - *num_bits = sub(*num_bits, add( hcode_l, NORM0_BITS + FLAGS_BITS ) ); - - /* Encode norm indices */ - encode_envelope_indices_fx( st_fx, num_env_bands, numnrmibits, difidx, &LCmode, 1, NORMAL_HQ_CORE, is_transient ); - - /*------------------------------------------------------------------* - * HQ Generic HF encoding - *------------------------------------------------------------------*/ - - test(); - IF ( sub( hqswb_clas, HQ_GEN_SWB ) == 0 || sub( hqswb_clas, HQ_GEN_FB ) == 0 ) - { - hq_generic_encoding_fx(t_audio, hq_generic_fenv, hq_generic_offset, st_fx, &hq_generic_exc_clas); - IF (sub(hq_generic_exc_clas , HQ_GENERIC_SP_EXC) == 0) - { - *num_bits = add(*num_bits,1); /* conditional 1 bit saving for representing FD3 BWE excitation class */ - } - map_hq_generic_fenv_norm_fx( hqswb_clas, hq_generic_fenv, ynrm, normqlg2, num_env_bands, nb_sfm, hq_generic_offset ); - } - - /*------------------------------------------------------------------* - * Bit allocation - *------------------------------------------------------------------*/ - - hq_bit_allocation_fx( st_fx->core_brate_fx, length, hqswb_clas, num_bits, normqlg2, nb_sfm, sfmsize, noise_level, - R, Rsubband, &sum, &core_sfm, num_env_bands ); - - /*------------------------------------------------------------------* - * Normalize coefficients with quantized norms - *------------------------------------------------------------------*/ - IF( hqswb_clas != HQ_HVQ ) - { - test(); - IF (hqswb_clas == HQ_GEN_SWB || hqswb_clas == HQ_GEN_FB) - { - b_delta_env = calc_nor_delta_hf_fx( st_fx, t_audio, ynrm, Rsubband, num_env_bands, nb_sfm, sfmsize, sfm_start, core_sfm ); - sum -= b_delta_env; - } - normalizecoefs_fx( t_audio, ynrm, nb_sfm, sfm_start, sfm_end, t_audio_norm ); - Q_audio = 12; - } - - /*------------------------------------------------------------------* - * Quantize/code spectral fine structure using PVQ or HVQ - *------------------------------------------------------------------*/ - IF( sub( hqswb_clas, HQ_HVQ) == 0 ) - { - sum = hvq_enc_fx( st_fx, st_fx->core_brate_fx, *num_bits, Npeaks, ynrm, R, peaks, nf_gains, - noise_level, pe_gains, t_audio, t_audio_q ); - *num_bits = sub(*num_bits, sum); - } - ELSE - { - shape_bits = pvq_core_enc_fx( st_fx, t_audio_norm, t_audio_q_norm, &Q_audio, sum, nb_sfm, sfm_start, sfm_end, sfmsize, Rsubband, R, - npulses, maxpulse, HQ_CORE ); - *num_bits = add( *num_bits, sub( sum, shape_bits) ); - } - - test(); - IF ( sub(hqswb_clas, HQ_HVQ) == 0 || sub(hqswb_clas, HQ_HARMONIC) == 0 ) - { - subband_search_offset = subband_search_offsets_13p2kbps_Har_fx; - wBands[0] = SWB_SB_BW_LEN0_16KBPS_HAR; - move16(); - wBands[1] = SWB_SB_BW_LEN1_16KBPS_HAR; - move16(); - - IF (sub(hqswb_clas, HQ_HARMONIC) == 0) - { - Q_shift = sub(SWB_BWE_LR_Qs, Q_audio); - FOR (i = 0; i < 300; i++) - { - t_audio_q[i] = L_shl(L_deposit_l(t_audio_q_norm[i]), Q_shift); /* Q12 */ - } - } - - har_est_fx( t_audio_q, 300, &har_freq_est1, &har_freq_est2, &flag_dis, &st_fx->prev_frm_hfe2_fx, subband_search_offset, wBands, &st_fx->prev_stab_hfe2_fx ); - - st_fx->prev_frm_hfe2_fx = har_freq_est2; - move16(); - } - - test(); - test(); - IF ( sub(hqswb_clas, HQ_HARMONIC) != 0 || sub(hqswb_clas, HQ_HVQ) != 0 || flag_dis == 0) - { - st_fx->prev_frm_hfe2_fx = 0; /*reset*/ move16(); - st_fx->prev_stab_hfe2_fx = 0; /*reset*/ move16(); - } - - nf_idx = 0; - move16(); - test(); - test(); - test(); - IF ( sub(is_transient,1 ) != 0 && sub( hqswb_clas, HQ_HVQ )!= 0 && !(sub(length, L_FRAME16k) == 0 && L_sub( st_fx->core_brate_fx, HQ_32k) == 0) ) - { - test(); - IF (sub(hqswb_clas, HQ_GEN_SWB) == 0 || sub(hqswb_clas, HQ_GEN_FB) == 0) - { - nf_idx = noise_adjust_fx( t_audio_norm, 12, R, sfm_start, sfm_end, s_max(core_sfm,sub(num_env_bands,1))); - push_indice_fx( st_fx, IND_NF_IDX, nf_idx, 2 ); - } - ELSE - { - nf_idx = noise_adjust_fx( t_audio_norm, 12, R, sfm_start, sfm_end, core_sfm ); - push_indice_fx( st_fx, IND_NF_IDX, nf_idx, 2 ); - } - } - /* updates */ - st_fx->prev_hqswb_clas_fx = hqswb_clas; - move16(); - - - return; -} - diff --git a/src/libs/libevs/lib_enc/hq_lr_enc.cpp b/src/libs/libevs/lib_enc/hq_lr_enc.cpp new file mode 100644 index 00000000..d81ff373 --- /dev/null +++ b/src/libs/libevs/lib_enc/hq_lr_enc.cpp @@ -0,0 +1,1676 @@ +/*==================================================================================== + EVS Codec 3GPP TS26.443 Nov 13, 2018. Version 12.11.0 / 13.7.0 / 14.3.0 / 15.1.0 + ====================================================================================*/ + +#include "options.h" +#include "cnst.h" +#include "rom_enc.h" +#include "rom_com.h" +#include "prot.h" +#include "stl.h" +#include "basop_util.h" + +/*--------------------------------------------------------------------------* + * Local functions + *--------------------------------------------------------------------------*/ + +static short small_symbol_enc( Encoder_State *st, const int *qbidx, const short bands, short *hLCmode, const short flag_pack, const short is_transient ); + +static short small_symbol_enc_tran( Encoder_State *st, const int *qbidx, const short bands, short *hLCmode, const short flag_pack ,const short is_transient ); + +static float band_energy_quant( Encoder_State *st, const float *t_audio, const short band_start[], const short band_end[], float band_energy[], + const short bands, const Word32 L_qint, const Word16 eref_fx, const short is_transient ); + +static short p2a_threshold_quant( Encoder_State *st, const float *t_audio, const short band_start[], const short band_end[], const short band_width[], + const short bands, const short p2a_bands, const float p2a_th, short *p2a_flags ); + +static void mdct_spectrum_fine_gain_enc( Encoder_State *st, const float ybuf[], float y2[], const short band_start[], const short band_end[], + const short k_sort[], const short bands, const Word32 L_qint, const short Ngq, const short gqlevs, const short gqbits ); + +/*--------------------------------------------------------------------------* + * spt_shorten_domain_set() + * + * Track the spectral peak based on peak -avg analysis + *--------------------------------------------------------------------------*/ + +static void spt_shorten_domain_set( + Encoder_State *st, /* i: encoder state structure */ + const float t_audio[], /* i: input spectrum */ + const short p2a_flags[], /* i: p2a anlysis information */ + const short new_band_start[], /* i: new band start position */ + const short new_band_end[], /* i: new band end position */ + const short new_band_width[], /* i: new subband band width */ + const short bands, /* i: total number of subbands */ + short band_start[], /* i/o: band start position */ + short band_end[], /* i/o: band end position */ + short band_width[], /* i: sub band band width */ + short *bit_budget /* i/o: bit budget */ +) +{ + short i, j, k; + short kpos; + float max_y2; + short max_y2_pos; + short spt_shorten_flag[SPT_SHORTEN_SBNUM]; + + kpos = 0; + j = 0; + for( k=bands-SPT_SHORTEN_SBNUM; kprev_SWB_peak_pos[kpos] != 0) + { + max_y2 = 0.0f; + max_y2_pos = 0; + for( i=band_start[k]; i<=band_end[k]; i++ ) + { + if( max_y2 < fabs(t_audio[i]) ) + { + max_y2 =(float) fabs(t_audio[i]); + max_y2_pos = i; + } + } + if( max_y2_pos >= new_band_start[j] && max_y2_pos <= new_band_end[j] ) + { + band_start[k] = new_band_start[j]; + band_end[k] = new_band_end[j]; + band_width[k] = new_band_width[j]; + spt_shorten_flag[j] = 1; + } + } + push_indice( st, IND_HQ2_SPT_SHORTEN, spt_shorten_flag[j], 1 ); + *bit_budget -= 1; + } + + kpos++; + j++; + } + + return; +} + +/*--------------------------------------------------------------------------* + * hq_lr_enc() + * + * HQ low rate encoding routine + *--------------------------------------------------------------------------*/ + +void hq_lr_enc( + Encoder_State *st, /* i/o: encoder state structure */ + float t_audio[], /* i/o: transform-domain coefs. */ + const short inner_frame, /* i : inner frame length */ + short *num_bits, /* i/o: number of available bits */ + const short is_transient /* i : transient flag */ +) +{ + short i, k1, k2; + short bit_budget, pbits; + short bands, length, ni_seed, gqlevs, gqbits, Ngq, p2a_bands; + short p2a_flags[BANDS_MAX]; + short band_start[BANDS_MAX], band_end[BANDS_MAX], band_width[BANDS_MAX]; + float band_energy[BANDS_MAX], Rk[BANDS_MAX]; + Word32 Rk_fx[BANDS_MAX]; + float ebits; + float p2a_th, ni_coef, ni_pd_th, pd_thresh, ld_slope; + Word32 L_qint; /* Q29 */ + Word16 eref_fx; /* Q10 */ + Word16 bit_alloc_weight_fx; /* Q13 */ + short k_sort[BANDS_MAX]; + int npulses[BANDS_MAX]; + int inp_vector[L_FRAME48k]; + float y2[L_FRAME48k]; + float y2_ni[L_FRAME48k]; + short hqswb_clas; + short lowlength; + short highlength; + float m[L_FRAME32k]; + short har_bands; + float Ep[BANDS_MAX], enerH = 0.0f, enerL = 0.0f; + short lowband, highband, bw_low = 0, bw_high = 20; + float band_energy_tmp[BANDS_MAX]; + long bwe_br; + short trans_bit, p2a_flags_tmp[BANDS_MAX]; + short adjustFlag = 0; + short prev_SWB_peak_pos_tmp[SPT_SHORTEN_SBNUM]; + int k,j; + short flag_spt; + short org_band_start[SPT_SHORTEN_SBNUM]; + short org_band_end[SPT_SHORTEN_SBNUM]; + short org_band_width[SPT_SHORTEN_SBNUM]; + short new_band_start[SPT_SHORTEN_SBNUM]; + short new_band_end[SPT_SHORTEN_SBNUM]; + short new_band_width[SPT_SHORTEN_SBNUM]; + short bws_cnt=0; + Word32 L_tmp,L_tmp2,L_tmp3; + Word16 exp,tmp,exp2,tmp1,tmp2,tmp3,alpha_fx,frac1; + Word32 enerH_fx; + Word32 enerL_fx; + Word32 Ep_fx[BANDS_MAX]; + Word32 Ep_avrg_fx, Ep_vari_fx; + Word32 Ep_avrgL_fx; + Word32 Ep_peak_fx; + Word32 Ep_tmp_fx[BANDS_MAX]; + Word16 gama_fx;/*Q15 0.85f; */ + Word16 beta_fx;/*Q14 1.05f; */ + Word32 L_band_energy[BANDS_MAX],L_band_energy_tmp[BANDS_MAX]; + UWord16 lo; + Word16 Q_band_energy; + set_f( y2, 0.0f, L_FRAME48k ); + set_i( inp_vector, 0, inner_frame ); + flag_spt = 0; + set_s(prev_SWB_peak_pos_tmp, 0, SPT_SHORTEN_SBNUM); + + bwe_br = st->core_brate; + hqswb_clas = HQ_NORMAL; + if( st->bwidth == SWB && (bwe_br == HQ_16k40 || bwe_br == HQ_13k20) ) + { + if ( is_transient == 1 ) + { + hqswb_clas = HQ_TRANSIENT; + } + else + { + /* classification of HQ_HARMONIC and HQ_NORMAL frames for SWB BWE */ + hqswb_clas = peak_avrg_ratio( st->total_brate, t_audio, NUMC_N, &st->mode_count, &st->mode_count1); + } + + /* write the classification information into the bitstream */ + push_indice( st, IND_HQ2_SWB_CLAS, hqswb_clas, 2 ); + (*num_bits) -= 2; + + if( hqswb_clas == HQ_NORMAL ) + { + flag_spt = 1; + } + } + else + { + /* write the transient bit into the bitstream */ + push_indice( st, IND_HQ2_SWB_CLAS, is_transient, 1 ); + + /* subtract one bit for the transient flag */ + (*num_bits)--; + } + + /* Configure encoder for different bandwidths, bit rates, etc. */ + hq2_core_configure( inner_frame, *num_bits, is_transient, &bands, &length, band_width, band_start, band_end, &L_qint, &eref_fx, + &bit_alloc_weight_fx, &gqlevs, &Ngq, &p2a_bands, &p2a_th, &pd_thresh, &ld_slope, &ni_coef, &ni_pd_th, bwe_br ); + + highlength = band_end[bands-1]; + har_bands = bands; + + if( st->bwidth == SWB && is_transient == 0 && (bwe_br == HQ_16k40 || bwe_br == HQ_13k20) ) + { + /* reserve bits for HQ_NORMAL and HQ_HARMONIC modes */ + if( hqswb_clas == HQ_NORMAL || hqswb_clas == HQ_HARMONIC ) + { + (*num_bits) -= (short)get_usebit_npswb(hqswb_clas); + } + } + + if( (bwe_br == HQ_16k40 || bwe_br == HQ_13k20) && st->bwidth == SWB ) + { + if( st->prev_hqswb_clas != HQ_NORMAL ) + { + j = 0; + for( k=bands-SPT_SHORTEN_SBNUM; kprev_SWB_peak_pos[j] = 0; + j++; + } + } + } + + /* Check if input frame is larger than coded bandwidth */ + if( inner_frame > length && is_transient ) + { + /* If so, collapse transient frame (4 short transforms) to remove uncoded coefficients */ + for( i = 1; i < NUM_TIME_SWITCHING_BLOCKS; i++ ) + { + k1 = i*length/NUM_TIME_SWITCHING_BLOCKS; + k2 = i*inner_frame/NUM_TIME_SWITCHING_BLOCKS; + + mvr2r( &t_audio[k2], &t_audio[k1], length/NUM_TIME_SWITCHING_BLOCKS ); + } + } + + /* Spectral energy calculation/quantization */ + ebits = band_energy_quant( st, t_audio, band_start, band_end, band_energy, bands, L_qint, eref_fx, is_transient ); + + for( i = 0; i < bands; i++) + { + L_band_energy[i] = (Word32)(band_energy[i] * pow(2.0f, SWB_BWE_LR_Qbe)); + } + + /* First pass bit budget for TCQ of spectral band information */ + gqbits = (short int) log2_f ((float) gqlevs); + bit_budget = (*num_bits) - (short) ceil (ebits) - Ngq * gqbits; + + pbits = 0; + if( st->bwidth == SWB && (bwe_br == HQ_16k40 || bwe_br == HQ_13k20) ) + { + if( hqswb_clas == HQ_HARMONIC ) + { + set_s( p2a_flags, 1, har_bands ); + } + else + { + /* High band tonality detector based on per band peak-to-average ratio */ + pbits = p2a_threshold_quant( st, t_audio, band_start, band_end, band_width, bands, p2a_bands, p2a_th, p2a_flags ); + bit_budget -= pbits; + + if( hqswb_clas == HQ_NORMAL ) + { + return_bits_normal2( &bit_budget, p2a_flags, bands, bits_lagIndices_modeNormal ); + } + } + } + else + { + /* High band tonality detector based on per band peak-to-average ratio */ + pbits = p2a_threshold_quant( st, t_audio, band_start, band_end, band_width, bands, p2a_bands, p2a_th, p2a_flags ); + bit_budget -= pbits; + } + + if( flag_spt == 1 ) + { + /* initalize the desired parameters for SPT */ + spt_shorten_domain_band_save( bands, band_start, band_end, band_width, org_band_start, org_band_end, org_band_width ); + spt_shorten_domain_pre( band_start, band_end, st->prev_SWB_peak_pos, bands, bwe_br, new_band_start, new_band_end, new_band_width ); + spt_shorten_domain_set( st, t_audio, p2a_flags, new_band_start, new_band_end, new_band_width, bands, band_start, band_end, band_width, &bit_budget ); + } + + /* Estimate number of bits per band */ + + Q_band_energy = SWB_BWE_LR_Qbe; + FOR(i = 0; i < bands; i++) + { + L_tmp = L_shl(L_band_energy[i],sub(16,Q_band_energy));/*Q16 */ + + frac1 = L_Extract_lc(L_tmp, &exp); /* Extract exponent of L_tmp */ + L_tmp = Pow2(30, frac1); + exp = sub(exp, 30); + Ep_fx[i] = L_shl(L_tmp , sub(exp,6)); /* Q -6 */ + Ep[i] = (float)(Ep_fx[i]/pow(2.0,-6)); + } + + FOR( i = 0; i < bands; i++ ) + { + L_tmp2 = Ep_fx[i]; + L_tmp = L_max(1, L_tmp2); + exp = norm_l(L_tmp); + tmp = extract_h(L_shl(L_tmp, exp)); + + L_tmp3 = (Word32)band_width[i]; + exp2 = norm_l(L_tmp3); + tmp2 = extract_h(L_shl(L_tmp3, exp2)); + + exp2 = sub(exp, exp2); /* Denormalize and substract */ + + tmp3 = sub(tmp2, tmp); + IF (tmp3 > 0) + { + tmp2 = shr(tmp2, 1); + } + IF (tmp3 > 0) + { + exp2 = add(exp2, 1); + } + tmp = div_s(tmp2, tmp); + L_tmp = L_deposit_h(tmp); + L_tmp = Isqrt_lc1(L_tmp, &exp2); + move32();/*Q(31-exp2) */ + Ep_tmp_fx[i] = L_shr(L_tmp,sub(15,exp2));/*Q13 */ + } + + + if ( is_transient == 0 && inner_frame == L_FRAME8k && st->core_brate <= ACELP_13k20 ) + { + lowband = 6; + move16(); + trans_bit = 2; + move16(); + bit_budget =sub(bit_budget,trans_bit); + gama_fx = 27852; /*Q15 0.85f; */ + beta_fx = 17203; + move16();/*Q14 1.05f; */ + set_s( &p2a_flags_tmp[bands-trans_bit], 0, 2 ); + + IF( st->core_brate == ACELP_13k20 ) + { + beta_fx = 13107; + move16();/*14 1.25f; */ + gama_fx = 31130; + move16();/*0.95f; */ + mvs2s(&p2a_flags[sub(bands,trans_bit)], &p2a_flags_tmp[sub(bands,trans_bit)], trans_bit); + } + + /* calculate the the low band/high band energy and the variance/avrage of the envelopes */ + Ep_vari_fx = 0; + move32(); + Ep_avrg_fx = 0; + move32(); + Ep_avrgL_fx = 0; + move32(); + Ep_peak_fx = 0; + move32(); + FOR( i = 0; i < bands; i++ ) + { + IF( sub(i,lowband) >= 0) + { + Ep_vari_fx = L_add(Ep_vari_fx,L_abs(L_sub(Ep_tmp_fx[i],Ep_tmp_fx[sub(i,1)])));/*Q15 */ + Ep_avrg_fx = L_add(Ep_avrg_fx,Ep_tmp_fx[i]);/*Q15 */ + + } + ELSE + { + Ep_avrgL_fx = L_add(Ep_avrgL_fx,Ep_tmp_fx[i]);/*Q15 */ + IF(L_sub(Ep_tmp_fx[i],Ep_peak_fx) > 0) + { + Ep_peak_fx = Ep_tmp_fx[i]; + move32();/*Q15 */ + } + } + } + /* modify the last p2a_bands subbands band_energies */ + k = (int)bands; + mvi2i( L_band_energy,L_band_energy_tmp,k); /*Q_band_energy */ + Mpy_32_16_ss(Ep_peak_fx,24576,&L_tmp,&lo); + Mpy_32_16_ss(Ep_peak_fx,shl(sub(bands,lowband),9),&L_tmp2,&lo); + Mpy_32_16_ss(Ep_avrg_fx,1126,&L_tmp3,&lo); + + IF(( (L_sub(L_tmp, L_shr(Ep_avrgL_fx,1)) < 0 && st->core_brate == ACELP_13k20 ) || st->core_brate < ACELP_13k20 )&& + L_sub(L_tmp2, L_tmp3) < 0 && L_sub(L_tmp2, L_shr(Ep_avrg_fx,7)) > 0) + { + FOR(i = lowband; i < bands; i++) + { + Mpy_32_16_ss(Ep_avrg_fx,24576,&L_tmp,&lo); + IF(L_sub(L_shr(Ep_tmp_fx[i],1), L_tmp) < 0) + { + Mpy_32_16_ss(Ep_peak_fx,sub(bands,lowband),&L_tmp,&lo); + tmp = extract_h(L_shl(L_tmp,14));/*Q-4 */ + IF(tmp != 0) + { + exp = norm_s(tmp); + tmp = shl(tmp,exp);/*Q(exp) */ + tmp = div_s(16384,tmp);/*Q(15+14-exp=29-exp) */ + exp = sub(29,exp); + } + ELSE + { + /*when the divisor is zero, happens rarely*/ + tmp = 0x7fff; + move16(); + exp = 0; + move16(); + } + Mpy_32_16_ss(Ep_avrg_fx,tmp,&L_tmp,&lo); + L_tmp = L_shl(L_tmp,sub(13,exp));/*Q(13+exp-15 +13-exp +4 = 15) */ + L_tmp2 = L_add(L_tmp,13107); /*15 */ + tmp2 = extract_l(L_min(L_max(L_tmp2,16384),gama_fx)); /*15 = 15 */ + Mpy_32_16_ss(L_band_energy_tmp[i],tmp2,&L_band_energy_tmp[i],&lo); + } + } + } + ELSE + { + j = 0; + FOR(i = sub(bands,trans_bit); i < bands; i++) + { + alpha_fx = 16384; + move16();/*Q14 */ + IF( sub(p2a_flags_tmp[i],1) == 0) + { + Mpy_32_16_ss(Ep_tmp_fx[i],sub(bands,lowband),&L_tmp,&lo); + tmp = extract_h(L_shl(L_tmp,14));/*Q-4 */ + IF(tmp != 0) + { + exp = norm_s(tmp); + tmp = shl(tmp,exp);/*Q(exp) */ + tmp = div_s(16384,tmp);/*Q(15+14-exp=29-exp) */ + exp = sub(29,exp); + } + ELSE + { + /*when the divisor is zero, happens rarely*/ + tmp = 0x7fff; + move16(); + exp = 0; + move16(); + } + Mpy_32_16_ss(Ep_vari_fx,3277,&L_tmp,&lo); + Mpy_32_16_ss(L_tmp,tmp,&L_tmp,&lo); + L_tmp = L_shl(L_tmp,sub(12,exp));/*Q(13+exp-15 +12-exp +4 = 14) */ + + tmp2 = extract_h(Ep_avrg_fx);/*Q13-16=-3 */ + IF(tmp2 != 0) + { + exp = norm_s(tmp2); + tmp2 = shl(tmp2,exp);/*Q(exp) */ + tmp2 = div_s(16384,tmp2);/*Q(15+14-exp=29-exp) */ + exp = sub(29,exp); + } + ELSE + { + tmp2 = 0x7fff; + move16(); + exp = 0; + move16(); + } + Mpy_32_16_ss(Ep_vari_fx,6554,&L_tmp2,&lo); + Mpy_32_16_ss(L_tmp2,tmp2,&L_tmp2,&lo); + L_tmp2 = L_shl(L_tmp2,sub(13,exp));/*Q(13+exp-15 +13-exp +3 = 14) */ + L_tmp=L_min(L_tmp,L_tmp2);/*14 */ + tmp=extract_l(L_min(L_tmp,13107));/*14 */ + alpha_fx =add(16384,tmp); + + } + IF(sub(st->last_bitalloc_max_band[j++], 1) == 0) + { + Mpy_32_16_ss(Ep_tmp_fx[i],sub(bands,lowband),&L_tmp,&lo); + tmp = extract_h(L_shl(L_tmp,14));/*Q-2 */ + IF(tmp != 0) + { + exp = norm_s(tmp); + tmp = shl(tmp,exp);/*Q(exp) */ + tmp = div_s(16384,tmp);/*Q(15+14-exp=29-exp) */ + exp = sub(29,exp); + } + ELSE + { + tmp = 0x7fff; + move16(); + exp = 0; + move16(); + } + Mpy_32_16_ss(Ep_avrg_fx,tmp,&L_tmp,&lo); + L_tmp = L_shl(L_tmp,sub(14,exp));/*Q(13+exp-15 +14-exp+2 = 14) */ + L_tmp =L_max(L_tmp,16384); /*14 */ + tmp=extract_l(L_min(L_tmp,beta_fx)); /*14 */ + alpha_fx=shl(mult(alpha_fx,tmp),1);/*14+14-15 +1=14 */ + } + ELSE + { + tmp2 = extract_h(Ep_avrg_fx);/*13 -16 =-3 */ + IF(tmp2 != 0) + { + exp = norm_s(tmp2); + tmp2 = shl(tmp2,exp);/*Q(exp) */ + tmp2 = div_s(16384,tmp2);/*Q(15+14-exp=29-exp) */ + exp = sub(29,exp); + } + ELSE + { + /*when the divisor is zero, happens rarely*/ + tmp2 = 0x7fff; + move16(); + exp = 0; + move16(); + } + Mpy_32_16_ss(Ep_tmp_fx[i],tmp2,&L_tmp,&lo); + L_tmp = L_shl(L_tmp,sub(19,exp));/*Q(13+exp-15 +19-exp +3 = 20) */ + Mpy_32_16_ss(L_tmp,shl(sub(bands,lowband),9),&L_tmp,&lo); + L_tmp =L_max(L_tmp,13926); /*14 */ + tmp2 =extract_l(L_min(L_tmp,16384)); /*14 */ + alpha_fx=shl(mult(alpha_fx,tmp2),1);/*14+14-15+1 =14 */ + } + Mpy_32_16_ss(L_band_energy_tmp[i],alpha_fx,&L_tmp,&lo); + L_band_energy_tmp[i] = L_shl(L_tmp,1);/*Q(Q_band_energy+14-15 +1= Q_band_energy) */ + } + } + lowband = 3; + move16(); + Ep_avrg_fx = 0; + move32(); + Ep_avrgL_fx = 0; + move32(); + Ep_peak_fx = 0; + move32(); + FOR(i = 0; i < bands; i++) + { + IF(sub(i,lowband) >=0 ) + { + Ep_avrg_fx = L_add(Ep_avrg_fx,Ep_tmp_fx[i]);/*Q15 */ + } + ELSE + { + Ep_avrgL_fx = L_add(Ep_avrgL_fx,L_shr(Ep_tmp_fx[i],1));/*Q12 */ + IF(L_sub(Ep_tmp_fx[i],Ep_peak_fx) > 0) + { + Ep_peak_fx = Ep_tmp_fx[i]; + move32();/*Q13 */ + } + } + } + Mpy_32_16_ss(Ep_peak_fx,28262,&L_tmp,&lo); + Mpy_32_16_ss(Ep_avrgL_fx,24576,&L_tmp2,&lo); + IF( L_sub(L_shr(Ep_avrg_fx,2), L_tmp2) > 0 && L_sub(L_shr(Ep_avrg_fx,4), L_tmp2) < 0 && L_sub(L_tmp, Ep_avrgL_fx)>0) + { + adjustFlag = 1; + move16(); + FOR (i = 0; i < lowband; i++) + { + tmp = extract_h(Ep_avrgL_fx);/*Q-4 */ + IF(tmp != 0) + { + exp = norm_s(tmp); + tmp = shl(tmp,exp);/*Q(exp) */ + tmp = div_s(16384,tmp);/*Q(15+14-exp=29-exp) */ + exp = sub(29,exp); + } + ELSE + { + /*when the divisor is zero, happens rarely*/ + tmp = 0x7fff; + move16(); + exp = 0; + move16(); + } + Mpy_32_16_ss(Ep_peak_fx,tmp,&L_tmp,&lo); + Mpy_32_16_ss(L_tmp,lowband,&L_tmp,&lo); + Mpy_32_16_ss(L_tmp,18842,&L_tmp,&lo); + L_tmp = L_shl(L_tmp,sub(27,exp));/*Q14 0.5 */ + tmp2=extract_l(L_min(L_tmp,19661));/*14 */ + Mpy_32_16_ss(L_band_energy_tmp[i],tmp2,&L_tmp,&lo); + L_band_energy_tmp[i] = L_shl(L_tmp,1); /*Q_band_energy */ + } + } + for (i = 0; i < bands; i++) + { + band_energy_tmp[i] = (float)(L_band_energy_tmp[i]/pow(2.0f, SWB_BWE_LR_Qbe)); + } + + hq2_bit_alloc( band_energy_tmp, bands, Rk_fx, &bit_budget, p2a_flags, bit_alloc_weight_fx, band_width, + *num_bits, hqswb_clas, st->bwidth, is_transient ); + + /* encode the last p2a_bands-1 subbands bit-allocation index of the previous frame */ + for(i = 0; i < 2; i++) + { + push_indice ( st, IND_HQ2_LAST_BA_MAX_BAND, st->last_bitalloc_max_band[i], 1 ); + } + } + else if( is_transient == 0 && inner_frame == L_FRAME16k ) + { + bit_budget = sub(bit_budget,2);/* bits in high bands to indicate the last 2 subbands is allocated bits or not */ + FOR( i = 0; i < bands; i++ ) + { + Ep_tmp_fx[i] = L_shl(Ep_tmp_fx[i],2); + } + IF( st->core_brate == ACELP_13k20 ) + { + lowband = 8; + move16(); + highband = 15; + move16(); + bw_low = sub(band_start[highband],band_start[lowband]); + bw_high = sub(add(band_end[sub(bands,1)],1),band_start[highband]); + } + ELSE + { + lowband = 8; + move16(); + highband = 16; + move16(); + bw_low = sub(band_start[highband],band_start[lowband]); + bw_high = sub(add(band_end[sub(bands,1)],1),band_start[highband]); + } + /* calculate the the low band/high band energy and the variance/avrage of the envelopes */ + enerL_fx = 0; + move32(); + enerH_fx = 0; + move32(); + Ep_vari_fx = 0; + move32(); + Ep_avrg_fx = 0; + move32(); + FOR( i = 0; i < bands; i++ ) + { + IF( sub(i,lowband) >= 0 && add(sub(i,bands),p2a_bands) < 0) + { + Ep_vari_fx = L_add(Ep_vari_fx,L_abs(L_sub(Ep_tmp_fx[i],Ep_tmp_fx[sub(i,1)])));/*Q15 */ + Ep_avrg_fx = L_add(Ep_avrg_fx,Ep_tmp_fx[i]);/*Q15 */ + } + + IF(sub(i,highband) >= 0) + { + enerH_fx = L_add(enerH_fx,L_shl(Ep_fx[i],2));/*Q0 */ + } + ELSE IF(sub(i,lowband) >= 0) + { + enerL_fx = L_add(enerL_fx,L_shl(Ep_fx[i],2));/*Q0 */ + } + } + enerL = (float)(enerL_fx/pow(2.0,-4)); + enerH = (float)(enerH_fx/pow(2.0,-4)); + /* modify the last p2a_bands subbands band_energies */ + k = (int)bands; + mvi2i( L_band_energy,L_band_energy_tmp,k); /*Q_band_energy */ + + L_tmp = L_max(enerH_fx,enerL_fx); + tmp = s_max(bw_low,bw_high); + i = norm_l(L_tmp); + j = norm_s(tmp); + Mpy_32_16_ss(L_shl(enerH_fx,i),shl(bw_low,j),&L_tmp,&lo); + Mpy_32_16_ss(L_shl(enerL_fx,i),shl(bw_high,j),&L_tmp2,&lo); + L_tmp2 = L_sub(L_tmp,L_tmp2); + + FOR( i = sub(bands,p2a_bands); i < bands; i++ ) + { + IF( sub(p2a_flags[i],1) == 0 || L_tmp2 > 0 ) + { + tmp = sub(bands,p2a_bands); + tmp = sub(tmp,lowband);/*Q0 */ + + tmp1 = extract_h(L_shl(Ep_avrg_fx,1));/*Q0 */ + IF(tmp1 != 0) + { + exp = norm_s(tmp1); + tmp1 = shl(tmp1,exp);/*Q(exp) */ + tmp1 = div_s(16384,tmp1);/*Q(15+14-exp = 29-exp) */ + exp = sub(29,exp); + } + ELSE + { + tmp1 = 0x7fff; + move16(); + exp = 0; + move16(); + } + Mpy_32_16_ss(Ep_tmp_fx[i],tmp1,&L_tmp,&lo); + Mpy_32_16_ss(L_tmp,tmp,&L_tmp,&lo); + Mpy_32_16_ss(L_tmp,16384,&L_tmp,&lo); + L_tmp = L_shl(L_tmp,sub(32,exp));/*Q15 */ + tmp = extract_l(L_min(L_tmp,6554));/*Q15 */ + Mpy_32_16_ss(Ep_vari_fx,tmp1,&L_tmp,&lo); + Mpy_32_16_ss(L_tmp,tmp,&L_tmp,&lo); + L_tmp = L_shl(L_tmp,sub(15,exp));/*Q15 */ + tmp = extract_l(L_shr(L_min(L_tmp,13107),1));/*Q14 */ + alpha_fx = add(tmp,16384);/*Q14 */ + } + ELSE + { + alpha_fx = 16384; + move16();/*Q14 */ + } + + IF(add(sub(i,bands),p2a_bands) > 0) + { + tmp = sub(bands, p2a_bands); + IF(sub(st->last_bitalloc_max_band[sub(i, add(tmp, 1))], 1) == 0) + { + tmp = sub(tmp,lowband); + Mpy_32_16_ss(Ep_tmp_fx[i],tmp,&L_tmp,&lo); + tmp = extract_h(L_shl(L_tmp,16));/*Q0 */ + IF(tmp != 0) + { + exp = norm_s(tmp); + tmp = shl(tmp,exp);/*Q(exp) */ + tmp = div_s(16384,tmp);/*Q(15+14-exp=29-exp) */ + exp = sub(29,exp); + } + ELSE + { + tmp = 0x7fff; + move16(); + exp = 0; + move16(); + } + Mpy_32_16_ss(Ep_avrg_fx,tmp,&L_tmp,&lo); + L_tmp = L_shl(L_tmp,sub(14,exp));/*Q14 */ + tmp = extract_l(L_min(L_max(L_tmp,16384),20480));/*Q14 */ + L_tmp = L_mult(alpha_fx,tmp);/*Q(14+14+1=29) */ + alpha_fx = extract_l(L_shr(L_tmp,15)); /*Q14*/ + } + ELSE + { + tmp = sub(tmp,lowband); + + tmp1 = extract_h(L_shl(Ep_avrg_fx,1));/*Q0 */ + IF(tmp1 != 0) + { + exp = norm_s(tmp1); + tmp1 = shl(tmp1,exp);/*Q(exp) */ + tmp1 = div_s(16384,tmp1);/*Q(15+14-exp=29-exp) */ + exp = sub(29,exp); + } + ELSE + { + tmp1 = 0x7fff; + move16(); + exp = 0; + move16(); + } + Mpy_32_16_ss(Ep_tmp_fx[i],tmp1,&L_tmp,&lo); + Mpy_32_16_ss(L_tmp,tmp,&L_tmp,&lo); + L_tmp = L_shl(L_tmp,sub(29,exp));/*Q14 */ + tmp = extract_l(L_min(L_max(L_tmp,13926),16384));/*Q14 */ + L_tmp = L_mult(alpha_fx,tmp);/*Q(14+14+1=29) */ + alpha_fx = extract_l(L_shr(L_tmp,15)); /*Q14 */ + } + } + Mpy_32_16_ss(L_band_energy_tmp[i],alpha_fx,&L_tmp,&lo); + L_band_energy_tmp[i] = L_shl(L_tmp,1);/*Q Q_band_energy */ + } + lowband = 6; + move16(); + Ep_avrg_fx = 0; + move32(); + Ep_avrgL_fx = 0; + move32(); + Ep_peak_fx = 0; + move32(); + FOR(i = 0; i < bands; i++) + { + IF(sub(i,lowband) >= 0) + { + Ep_avrg_fx = L_add(Ep_avrg_fx,Ep_tmp_fx[i]);/*Q15 */ + } + ELSE + { + Ep_avrgL_fx = L_add(Ep_avrgL_fx,Ep_tmp_fx[i]);/*Q15 */ + IF(L_sub(Ep_tmp_fx[i],Ep_peak_fx) > 0) + { + Ep_peak_fx = Ep_tmp_fx[i]; + move32();/*Q15 */ + } + } + } + + Mpy_32_16_ss(Ep_peak_fx,24576,&L_tmp,&lo); + Mpy_32_16_ss(Ep_peak_fx,19661,&L_tmp2,&lo); + Mpy_32_16_ss(Ep_avrgL_fx,24576,&L_tmp3,&lo); + + IF( (L_sub(L_shr(Ep_avrgL_fx,1), Ep_avrg_fx)>0 && L_sub(L_tmp,L_shr(Ep_avrgL_fx,2)) > 0 && L_sub(L_shr(Ep_avrgL_fx,1),L_tmp2) < 0 ) || + (L_sub(L_shr(Ep_avrg_fx,1), Ep_avrgL_fx)>0 && L_sub(L_shr(Ep_avrg_fx,3),L_tmp3) < 0 && L_sub(L_tmp,L_shr(Ep_avrgL_fx,2)) > 0 ) ) + { + adjustFlag = 1; + move16(); + FOR (i = 0; i < lowband; i++) + { + tmp = extract_h(L_shl(Ep_avrgL_fx,1));/*Q0 */ + IF(tmp != 0) + { + exp = norm_s(tmp); + tmp = shl(tmp,exp);/*Q(exp) */ + tmp = div_s(16384,tmp);/*Q(15+14-exp=29-exp) */ + exp = sub(29,exp); + } + ELSE + { + tmp = 0x7fff; + move16(); + exp = 0; + move16(); + } + Mpy_32_16_ss(Ep_peak_fx,tmp,&L_tmp,&lo); + Mpy_32_16_ss(L_tmp,lowband,&L_tmp,&lo); + L_tmp = L_shl(L_tmp,sub(28,exp));/*Q14 0.5 */ + tmp = extract_l(L_min(L_tmp,19661));/*Q14 */ + Mpy_32_16_ss(L_band_energy_tmp[i],tmp,&L_tmp,&lo); + L_band_energy_tmp[i] = L_shl(L_tmp,1); /*Q_band_energy */ + } + } + for (i = 0; i < bands; i++) + { + band_energy_tmp[i] = (float)(L_band_energy_tmp[i]/pow(2.0f, SWB_BWE_LR_Qbe)); + } + + hq2_bit_alloc( band_energy_tmp, bands, Rk_fx, &bit_budget, p2a_flags, bit_alloc_weight_fx, band_width, + *num_bits, hqswb_clas, st->bwidth, is_transient ); + + /* encode the last p2a_bands-1 subbands bit-allocation index of the previous frame */ + for(i = 0; i < 2; i++) + { + push_indice( st, IND_HQ2_LAST_BA_MAX_BAND, st->last_bitalloc_max_band[i], 1 ); + } + } + else if( st->bwidth == SWB && hqswb_clas == HQ_HARMONIC && (bwe_br == HQ_16k40 || bwe_br == HQ_13k20) ) + { + /* bit allocation for harmonic mode */ + hq2_bit_alloc_har( band_energy, bit_budget, bands, Rk_fx, p2a_bands,bwe_br, p2a_flags, band_width); + } + else + { + + /* estimate number of bits per band */ + hq2_bit_alloc( band_energy, bands, Rk_fx, &bit_budget, p2a_flags, bit_alloc_weight_fx, band_width, + *num_bits, hqswb_clas, st->bwidth, is_transient ); + } + + tcq_core_LR_enc( st, inp_vector, t_audio, y2, bit_budget, bands, band_start, band_end, band_width, Rk_fx, + npulses, k_sort, p2a_flags, p2a_bands, st->last_bitalloc_max_band, inner_frame, adjustFlag, is_transient ); + + if((inner_frame == L_FRAME8k && st->core_brate <= ACELP_13k20) || inner_frame == L_FRAME16k) + { + j = 0; + for(i = 2; i > 0; i--) + { + if(npulses[bands-i] > 0) + { + st->last_bitalloc_max_band[j] = 1; + } + else + { + st->last_bitalloc_max_band[j] = 0; + } + j++; + } + } + + /* Prepare floating Rk for next modules */ + for( k = 0; k < bands; k++) + { + Rk[k] = WORD322FL_SCALE( Rk_fx[k], SWB_BWE_LR_QRk - 1); + } + + /* Denormalize the coded MDCT spectrum */ + mdct_spectrum_denorm( inp_vector, y2, band_start, band_end, band_width, band_energy, npulses, bands, ld_slope, pd_thresh ); + + /* Apply fine gain quantization to denormalized coded spectrum */ + mdct_spectrum_fine_gain_enc( st, t_audio, y2, band_start, band_end, k_sort, bands, L_qint, Ngq, gqlevs, gqbits ); + + /* reStore the subband information*/ + if(flag_spt == 1) + { + spt_shorten_domain_band_restore(bands, band_start, band_end, band_width, org_band_start, org_band_end, org_band_width); + } + + /* Inject noise into components having relatively low pulse energy per band */ + ni_seed = npulses[0] + npulses[1] + npulses[2] + npulses[3]; + + for(i=0; ilast_ni_gain, st->last_env, &st->last_max_pos_pulse, p2a_flags, p2a_bands, hqswb_clas, st->bwidth, bwe_br ); + + if( st->bwidth == SWB && (bwe_br == HQ_16k40 || bwe_br == HQ_13k20) ) + { + if( hqswb_clas == HQ_NORMAL || hqswb_clas == HQ_HARMONIC ) + { + preset_hq2_swb( hqswb_clas, band_end, &har_bands, p2a_bands,length, bands, &lowlength, &highlength, m ); + + swb_bwe_enc_lr( st, y2, t_audio, m , bwe_br, bands, band_start, band_end, band_energy, p2a_flags, + hqswb_clas, lowlength, highlength, st->prev_frm_index, har_bands, &st->prev_frm_hfe2, &st->prev_stab_hfe2,band_width, y2_ni, &ni_seed ); + + post_hq2_swb( m, lowlength, highlength, hqswb_clas, har_bands, bands, p2a_flags, band_start, band_end, y2, npulses ); + + if( hqswb_clas == HQ_NORMAL ) + { + spt_swb_peakpos_tmp_save(y2, bands, band_start, band_end, prev_SWB_peak_pos_tmp); + for( k=0; kbwidth, is_transient, hqswb_clas, &st->prev_hqswb_clas, + st->prev_SWB_peak_pos, prev_SWB_peak_pos_tmp, &st->prev_frm_hfe2, &st->prev_stab_hfe2, bws_cnt ); + + if( st->bwidth != SWB ) + { + /* reset HQ classifier memories */ + st->mode_count = 0; + st->mode_count1 = 0; + } + if( hqswb_clas != HQ_HARMONIC && (bwe_br == HQ_16k40 || bwe_br == HQ_13k20) && st->bwidth == SWB ) + { + st->prev_frm_index[0] = -1; + st->prev_frm_index[1] = -1; + } + /* update number of unused bits */ + *num_bits = 0; + + st->hvq_hangover = 0; + + return; +} + +/*--------------------------------------------------------------------------* + * small_symbol_enc_tran() + * + * Huffman encoding of differential energies, estimating or packing bits + * if flag_pack = 0, LC mode info. is output else LC mode info. is input + * if flag_pack = 0, estimatng else packing bits + *--------------------------------------------------------------------------*/ +static short small_symbol_enc_tran( /* o : bits */ + Encoder_State *st, /* i/o: encoder state structure */ + const int *qbidx, /* i : input of dequantized differential energy */ + const short BANDS, /* i : number of bands */ + short *hLCmode, /* i/o: LC mode info */ + const short flag_pack, /* i : indicator of packing or estimating bits */ + const short is_transient +) +{ + short i, bits; + short difidx[BANDS_MAX]; + + for( i=0; iLRMDCT_BE_LIMIT || difidx[i]<0) + { + /* Huffman cannot encode this vector */ + return -1; + } + } + + /* Preparing lossless coding input */ + if ( flag_pack == 0 ) + { + /* estimating # of bits */ + bits = encode_envelope_indices(st, BANDS, -1, difidx, hLCmode, flag_pack, LOW_RATE_HQ_CORE_TRAN , is_transient ); + bits += BITS_DE_FCOMP; /* xx bits for diff. energies + BITS_DE_FCOMP bits for first energies */ + } + else + { + bits = 0; + encode_envelope_indices(st, BANDS, -1, difidx, hLCmode, flag_pack, LOW_RATE_HQ_CORE_TRAN ,is_transient ); + } + + return bits + BITS_DE_HMODE; /* xx bits for diff. energies + 1 bit for LC coding mode */ +} + + +/*--------------------------------------------------------------------------* + * small_symbol_enc() + * + * Huffman encoding of differential energies, estimating or packing bits + * if flag_pack = 0, LC mode info. is output else LC mode info. is input + * if flag_pack = 0, estimatng else packing bits + *--------------------------------------------------------------------------*/ + +static short small_symbol_enc( /* o : bits */ + Encoder_State *st, /* i/o: encoder state structure */ + const int *qbidx, /* i : input of dequantized differential energy */ + const short BANDS, /* i : number of bands */ + short *hLCmode, /* i/o: LC mode info */ + const short flag_pack, /* i : indicator of packing or estimating bits */ + const short is_transient +) +{ + short i, bits; + short difidx[BANDS_MAX], LSB[BANDS_MAX]; + + /* Preparing lossless coding input */ + difidx[0] = (short)(qbidx[0]+DE_OFFSET0); + + for( i=1; i=DE_LIMIT || difidx[i]<0) + { + /* Huffman cannot encode this vector */ + return -1; + } + } + + /* splitting MSB and LSB */ + for( i=0; i>= 1; + } + + /* Preparing lossless coding input */ + if ( flag_pack == 0 ) + { + /* estimating # of bits */ + /* Encoding MSB bits */ + bits = encode_envelope_indices( st, BANDS, -1, difidx, hLCmode, flag_pack, LOW_RATE_HQ_CORE, is_transient ); + bits += BITS_DE_FCOMP; /* xx bits for diff. energies + BITS_DE_FCOMP bits for first energies */ + + /* Encoding LSB bit packing */ + bits += BANDS; + } + else + { + /* Encoding MSB bits */ + bits = 0; + encode_envelope_indices( st, BANDS, -1, difidx, hLCmode, flag_pack, LOW_RATE_HQ_CORE, is_transient ); + + /* Encoding LSB bit packing */ + for( i=0; iABS_ENG_OFFSET-1 || qbidx[0]<-ABS_ENG_OFFSET) + { + cnt_outlyer0 = 2; + } + else if (qbidx[0]>3 || qbidx[0]<-4) + { + cnt_outlyer0 = 1; + } + else + { + cnt_outlyer0 = 0; + } + + cnt_outlyer=0; + pos_outlyer = -1; + for( i=1; i3 || qbidx[i]<-4) + { + cnt_outlyer++; + pos_outlyer = i; + } + + if (qbidx[i]>ABS_ENG_OFFSET-1 || qbidx[i]<-ABS_ENG_OFFSET) + { + cnt_outlyer++; + } + } + + if (cnt_outlyer0 == 0 && cnt_outlyer<=1) + { + bitsmode0 = BITS_DE_8SMODE + BITS_DE_8SMODE_N0 + BITS_DE_8SMODE_N1; + if (cnt_outlyer == 1) + { + /* 01 */ + bitsmode0 += BITS_DE_8SPOS + BITS_ABS_ENG; + } + + for( i=0; imax_q) + { + max_q = (short)qbidx[i]; + } + + if (qbidx[i]= -(2<<(i+1))) + { + break; + } + } + basic_shift = i; + + min_bits=1000; + min_bits_pos = basic_shift; + for(offset0=basic_shift; offset0>offset0)+4]+(offset0)); + } + + if (min_bits>bitsmode1) + { + min_bits_pos = offset0; + min_bits = bitsmode1; + } + } + + bitsmode1 = min_bits; + lsbdepth1 = min_bits_pos; + + for( i=0; i>lsbdepth1; + } + } + + /* Preparing lossless coding input */ + if ( flag_pack == 0 ) + { + /* estimating # of bits */ + /* Encoding MSB bits */ + if (bitsmode0 0) + { + for(i=0; iMAXIMUM_ENERGY_LOWBRATE) + { + bq2[i] = MAXIMUM_ENERGY_LOWBRATE; + } + if (bq2[i] Qbe(Q14) */ + band_energy[k] = (float)(L_band_energy[k]/pow(2.0f, SWB_BWE_LR_Qbe)); + } + + if( is_transient ) + { + reverse_transient_frame_energies( band_energy, bands ); + } + + return( deng_bits ); +} + + +/*-------------------------------------------------------------------* + * p2a_threshold_quant() + * + * + *-------------------------------------------------------------------*/ + +static short p2a_threshold_quant( + Encoder_State *st, /* i/o: encoder state structure */ + const float *t_audio, + const short band_start[], + const short band_end[], + const short band_width[], + const short bands, + const short p2a_bands, + const float p2a_th, + short *p2a_flags +) +{ + short i, j, k; + float p, a, e; + float p2a; + + set_s( p2a_flags, 1, bands ); + + j = 0; + for (k = bands - p2a_bands; k < bands; k++) + { + a = 0.0f; + p = 0.0f; + for (i = band_start[k]; i <= band_end[k]; i++) + { + e = t_audio[i] * t_audio[i]; + if (e > p) + { + p = e; + } + a += e; + } + + if (a > 0.0f) + { + a /= band_width[k]; + p2a = 10.0f * (float) log10 (p / a); + + if (p2a <= p2a_th) + { + p2a_flags[k] = 0; + } + } + + push_indice( st, IND_HQ2_P2A_FLAGS, p2a_flags[k], 1 ); + j++; + } + + return( j ); +} + + +/*-------------------------------------------------------------------* + * mdct_spectrum_fine_gain_enc() + * + * + *-------------------------------------------------------------------*/ + +static void mdct_spectrum_fine_gain_enc( + Encoder_State *st, /* i/o: encoder state structure */ + const float ybuf[], + float y2[], + const short band_start[], + const short band_end[], + const short k_sort[], + const short bands, + const Word32 L_qint, + const short Ngq, + const short gqlevs, + const short gqbits +) +{ + short i, k, imin; + float Eyy, Exy, gamma; + float dmin, d; + float gain_table[MAX_GQLEVS]; + Word16 exp_normn, exp_normd; + Word16 delta_fx, Qdelta; + Word32 L_delta, L_q; + Word32 L_temp; + Word16 gain_table_fx[MAX_GQLEVS]; + Word16 Qgt; + Word16 temp_lo_fx, temp_hi_fx; + + /* Fine gain quantization on only the most significant energy bands */ + + /*delta = qint / gqlevs; */ + exp_normn = norm_l(L_qint); + exp_normn = sub(exp_normn, 1); + exp_normd = norm_s(gqlevs); + delta_fx = div_l(L_shl(L_qint, exp_normn), shl(gqlevs, exp_normd)); + Qdelta = add(sub(exp_normn, exp_normd), 28); /* 29+exp_normn-(exp_normd)-1; */ + L_delta = L_shl(L_deposit_h(delta_fx), sub(13, Qdelta)); + /*q = (-qint + delta) / 2.0f; */ + L_q = L_shr(L_sub(L_delta, L_qint), 1); + + FOR (i = 0; i < gqlevs; i++) + { + /*gain_table[i] = (float) pow (2.0f, q * 0.5f); */ + L_temp = L_shr(L_shr(L_q, 1), sub(29, 16)); + temp_lo_fx = L_Extract_lc(L_temp, &temp_hi_fx); + Qgt = sub(14, temp_hi_fx); + gain_table_fx[i] = extract_l(Pow2(14, temp_lo_fx)); /* Qgt */ + + /*q += delta; */ + L_q = L_add(L_q, L_delta); + gain_table_fx[i] = shl(gain_table_fx[i], sub(14, Qgt)); /* Qgt -> Q14 */ + gain_table[i] = (float)(gain_table_fx[i]/pow(2.0f, 14)); + } + + for (k = bands - Ngq; k < bands; k++) + { + Eyy = 0.0f; + Exy = 0.0f; + for (i = band_start[k_sort[k]]; i <= band_end[k_sort[k]]; i++) + { + Eyy += y2[i] * y2[i]; + Exy += ybuf[i] * y2[i]; + } + + if (Eyy > 0.0f && Exy > 0.0f) + { + gamma = Exy / Eyy; + dmin = FLT_MAX; + imin = -1; + for (i = 0; i < gqlevs; i++) + { + d = (float) fabs (gamma - gain_table[i]); + if (d < dmin) + { + dmin = d; + imin = i; + } + } + + gamma = gain_table[imin]; + + for (i = band_start[k_sort[k]]; i <= band_end[k_sort[k]]; i++) + { + y2[i] *= gamma; + } + } + else + { + imin = 0; + } + + push_indice( st, IND_HQ2_SUBBAND_GAIN, imin, gqbits ); + } + + return; +} diff --git a/src/libs/libevs/lib_enc/hq_lr_enc_fx.cpp b/src/libs/libevs/lib_enc/hq_lr_enc_fx.cpp deleted file mode 100755 index 2332be06..00000000 --- a/src/libs/libevs/lib_enc/hq_lr_enc_fx.cpp +++ /dev/null @@ -1,1928 +0,0 @@ -/*==================================================================================== - EVS Codec 3GPP TS26.442 Apr 03, 2018. Version 12.11.0 / 13.6.0 / 14.2.0 - ====================================================================================*/ - -#include -#include "options.h" -#include "cnst_fx.h" -#include "prot_fx.h" -#include "rom_com_fx.h" -#include "rom_enc_fx.h" -#include "stl.h" -#include "basop_mpy.h" - -/*--------------------------------------------------------------------------* - * Local functions - *--------------------------------------------------------------------------*/ - -static Word16 band_energy_quant_fx( Encoder_State_fx *st_fx, const Word32 *L_t_audio, const Word16 band_start_fx[], const Word16 band_end_fx[], Word32 L_band_energy[], - const Word16 bands_fx, const Word32 L_qint, const Word16 eref_fx, const Word16 is_transient_fx ); - -static Word16 p2a_threshold_quant_fx( Encoder_State_fx *st_fx, const Word32 *L_t_audio, const Word16 band_start[], const Word16 band_end[], const Word16 band_width[], - const Word16 bands, const Word16 p2a_bands, const Word16 p2a_th, Word16 *p2a_flags ); - -static void mdct_spectrum_fine_gain_enc_fx( Encoder_State_fx *st_fx, const Word32 L_ybuf[], Word32 L_y2[], const Word16 band_start[], const Word16 band_end[], - const Word16 k_sort[], const Word16 bands, - const Word32 L_qint, const Word16 Ngq, const Word16 gqlevs, const Word16 gqbits ); - -/*--------------------------------------------------------------------------* - * spt_shorten_domain_set() - * - * Track the spectral peak based on peak -avg analysis - *--------------------------------------------------------------------------*/ - -static void spt_shorten_domain_set_fx( - Encoder_State_fx *st_fx, /* i: encoder state structure */ - const Word32 L_t_audio[], /* i: input spectrum */ - const Word16 p2a_flags[], /* i: p2a anlysis information */ - const Word16 new_band_start[], /* i: new band start position */ - const Word16 new_band_end[], /* i: new band end position */ - const Word16 new_band_width[], /* i: new subband band width */ - const Word16 bands, /* i: total number of subbands */ - Word16 band_start[], /* i/o: band start position */ - Word16 band_end[], /* i/o: band end position */ - Word16 band_width[], /* i: sub band band width */ - Word16 *bit_budget /* i/o: bit budget */ -) -{ - Word16 i, j, k; - Word16 kpos; - Word32 L_max_y2; - Word16 max_y2_pos; - Word16 spt_shorten_flag[SPT_SHORTEN_SBNUM]; - - kpos = 0; - j = 0; - move16(); - FOR(k=sub(bands,SPT_SHORTEN_SBNUM); kprev_SWB_peak_pos_fx[kpos] != 0) - { - L_max_y2 = L_deposit_l(0); - max_y2_pos = 0; - move16(); - FOR(i=band_start[k]; i<=band_end[k]; i++) - { - IF( L_sub( L_max_y2, L_abs(L_t_audio[i])) < 0 ) - { - L_max_y2 = L_abs(L_t_audio[i]); - max_y2_pos = i; - move16(); - } - } - test(); - IF( sub(max_y2_pos, new_band_start[j]) >= 0 && sub(max_y2_pos, new_band_end[j]) <= 0 ) - { - band_start[k] = new_band_start[j]; - move16(); - band_end[k] = new_band_end[j]; - move16(); - band_width[k] = new_band_width[j]; - move16(); - spt_shorten_flag[j] = 1; - move16(); - } - } - push_indice_fx(st_fx, IND_HQ2_SPT_SHORTEN, spt_shorten_flag[j], 1); - *bit_budget = sub(*bit_budget, 1); - } - - kpos = add(kpos, 1); - j = add(j, 1); - } - - return; -} - -/*--------------------------------------------------------------------------* - * hq_lr_enc_fx() - * - * HQ Low rate encoding routine - *--------------------------------------------------------------------------*/ - -void hq_lr_enc_fx( - Encoder_State_fx *st_fx, /* i/o: : encoder state structure */ - Word32 L_t_audio[], /* i/o: Q12 : transform-domain coefs. */ - const Word16 inner_frame_fx, /* i : Q0 : inner frame length */ - Word16 *num_bits_fx, /* i/o: Q0 : number of available bits */ - const Word16 is_transient_fx /* i : Q0 : transient flag */ -) -{ - Word16 i, k1_fx, k2_fx; - Word16 bit_budget_fx, pbits_fx; - Word16 bands_fx, length_fx, ni_seed_fx, gqlevs_fx, gqbits_fx, Ngq_fx, p2a_bands_fx; - Word16 p2a_flags_fx[BANDS_MAX]; - Word16 band_start[BANDS_MAX], band_end[BANDS_MAX], band_width[BANDS_MAX]; - Word32 L_band_energy[BANDS_MAX], L_Rk[BANDS_MAX]; - Word16 ebits_fx; - - Word32 L_qint; - /*Word16 Qqint=29;*/ - Word16 eref_fx/*, Qeref=10*/; - Word16 bit_alloc_weight_fx/*, Qbaw=13*/; - Word16 ld_slope_fx/*, Qldslope=15*/; - Word16 p2a_th_fx/*, Qp2ath=11*/; - Word16 pd_thresh_fx/*, Qpdth=15*/; - Word16 ni_coef_fx/*, Qnicoef=14*/; - - Word16 k_sort_fx[BANDS_MAX]; - Word16 npulses_fx[BANDS_MAX]; - Word16 inp_vector_fx[L_FRAME48k]; - Word32 L_y2[L_FRAME48k]; - Word32 L_y2_ni[L_FRAME48k]; - Word16 hqswb_clas_fx; - Word16 lowlength_fx; - Word16 highlength_fx; - Word32 L_m[L_FRAME32k]; - Word16 har_bands_fx; - Word16 bw_low, bw_high; - Word32 L_band_energy_tmp[BANDS_MAX]; - Word32 L_bwe_br; - Word16 trans_bit; - Word16 adjustFlag; - Word16 prev_SWB_peak_pos_tmp_fx[SPT_SHORTEN_SBNUM]; - Word16 k,j; - Word16 flag_spt_fx; - Word16 org_band_start[SPT_SHORTEN_SBNUM]; - Word16 org_band_end[SPT_SHORTEN_SBNUM]; - Word16 org_band_width[SPT_SHORTEN_SBNUM]; - Word16 new_band_start[SPT_SHORTEN_SBNUM]; - Word16 new_band_end[SPT_SHORTEN_SBNUM]; - Word16 new_band_width[SPT_SHORTEN_SBNUM]; - - Word16 k1_step_fx, k2_step_fx; - Word16 exp_norm; - - Word16 lowband,highband,p2a_flags_tmp[BANDS_MAX]; - Word32 L_tmp,L_tmp2,L_tmp3; - Word16 exp,exp2,tmp,tmp1,tmp2,tmp3,frac1,alpha_fx,Q_band_energy; - Word32 enerH_fx; - Word32 enerL_fx; - Word32 Ep_fx[BANDS_MAX]; - Word32 Ep_avrg_fx, Ep_vari_fx; - Word32 Ep_avrgL_fx; - Word32 Ep_peak_fx; - Word32 Ep_tmp_fx[BANDS_MAX]; - Word16 gama_fx;/*Q15 0.85f;// */ - Word16 beta_fx;/*Q14 1.05f; */ - - set32_fx( L_y2, 0x0L, L_FRAME48k ); - set16_fx( inp_vector_fx, 0, inner_frame_fx ); - flag_spt_fx = 0; - move16(); - set16_fx(prev_SWB_peak_pos_tmp_fx, 0, SPT_SHORTEN_SBNUM); - adjustFlag = 0; - move16(); - bw_low = 0; - move16(); - bw_high = 20; - move16(); - enerL_fx = L_deposit_l(0); - enerH_fx = L_deposit_l(0); - - tmp2 = 0; /* to avoid compilation warnings */ - - L_bwe_br = L_add(st_fx->core_brate_fx, 0); - hqswb_clas_fx = HQ_NORMAL; - move16(); - test(); - test(); - IF( sub(st_fx->bwidth_fx, SWB) == 0 && (L_sub(L_bwe_br, HQ_16k40) == 0 || L_sub(L_bwe_br, HQ_13k20) == 0) ) - { - IF ( sub(is_transient_fx, 1) == 0 ) - { - hqswb_clas_fx = HQ_TRANSIENT; - move16(); - } - ELSE - { - hqswb_clas_fx = peak_avrg_ratio_fx( st_fx->total_brate_fx, L_t_audio, NUMC_N, &st_fx->mode_count_fx, &st_fx->mode_count1_fx, SWB_BWE_LR_Qs ); - } - - /* write the classification information into the bitstream */ - push_indice_fx( st_fx, IND_HQ2_SWB_CLAS, hqswb_clas_fx, 2 ); - (*num_bits_fx) = sub(*num_bits_fx, 2); - if( sub(hqswb_clas_fx, HQ_NORMAL) == 0 ) - { - flag_spt_fx = 1; - move16(); - } - } - ELSE - { - /* write the transient bit into the bitstream */ - push_indice_fx( st_fx, IND_HQ2_SWB_CLAS, is_transient_fx, 1 ); - - /* subtract one bit for the transient flag */ - (*num_bits_fx)--; - } - - hq2_core_configure_fx( inner_frame_fx, *num_bits_fx, is_transient_fx, &bands_fx, &length_fx, band_width, band_start, band_end, - &L_qint, &eref_fx, &bit_alloc_weight_fx, &gqlevs_fx, &Ngq_fx, &p2a_bands_fx, &p2a_th_fx, &pd_thresh_fx, &ld_slope_fx, &ni_coef_fx - ,L_bwe_br); - - highlength_fx = band_end[sub(bands_fx, 1)]; - move16(); - har_bands_fx = bands_fx; - move16(); - - test(); - test(); - test(); - IF( sub(st_fx->bwidth_fx, SWB) == 0 && is_transient_fx == 0 && (L_sub(L_bwe_br, HQ_16k40) == 0 || L_sub(L_bwe_br, HQ_13k20) == 0) ) - { - /* reserve bits for HQ_NORMAL2 and HQ_HARMONIC modes */ - test(); - IF( sub(hqswb_clas_fx, HQ_NORMAL) == 0 || sub(hqswb_clas_fx, HQ_HARMONIC) == 0 ) - { - (*num_bits_fx) = sub(*num_bits_fx, get_usebit_npswb_fx(hqswb_clas_fx)); - } - } - - test(); - test(); - IF(( L_sub(L_bwe_br, HQ_16k40) == 0 || L_sub(L_bwe_br, HQ_13k20) == 0) && sub(st_fx->bwidth_fx, SWB) == 0 ) - { - IF( sub(st_fx->prev_hqswb_clas_fx, HQ_NORMAL) != 0 ) - { - j = 0; - move16(); - FOR(k=sub(bands_fx,SPT_SHORTEN_SBNUM); kprev_SWB_peak_pos_fx[j] = 0; - move16(); - j = add(j, 1); - } - } - } - - /* Check if input frame is larger than coded bandwidth */ - test(); - IF ( sub(inner_frame_fx, length_fx) > 0 && is_transient_fx ) - { - /* If so, collapse transient frame (4 short transforms) to remove uncoded coefficients */ - - k1_step_fx = shr(length_fx, 2); /* k1 = length/NUM_TIME_SWITCHING_BLOCKS */ - k2_step_fx = shr(inner_frame_fx, 2); /* k2 = inner_frame/NUM_TIME_SWITCHING_BLOCKS */ - k1_fx = k1_step_fx; - k2_fx = k2_step_fx; - FOR (i = 1; i < NUM_TIME_SWITCHING_BLOCKS; i++) - { - /*k1 = i*length/NUM_TIME_SWITCHING_BLOCKS; */ - /*k2 = i*inner_frame/NUM_TIME_SWITCHING_BLOCKS; */ - - Copy32( &L_t_audio[k2_fx], &L_t_audio[k1_fx], k1_step_fx ); - - k1_fx = add(k1_fx, k1_step_fx); - k2_fx = add(k2_fx, k2_step_fx); - } - } - - /* Spectral energy calculation/quantization */ - ebits_fx = band_energy_quant_fx( st_fx, L_t_audio, band_start, band_end, L_band_energy, bands_fx, - L_qint, eref_fx, is_transient_fx ); - - /* First pass bit budget for TCQ of spectral band information */ - exp_norm = norm_s(gqlevs_fx); /* gqbits_fx = (short int) log2_f ((float) gqlevs_fx); */ - gqbits_fx = sub(14, exp_norm); - - bit_budget_fx = sub(sub(*num_bits_fx, ebits_fx), round_fx(L_shl(L_mult(Ngq_fx, gqbits_fx), 15))); /* (*num_bits) - (short) ceil (ebits) - Ngq * gqbits; */ - - - pbits_fx = 0; - move16(); - - test(); - test(); - IF( sub(st_fx->bwidth_fx, SWB) == 0 && (L_sub(L_bwe_br, HQ_16k40) == 0 || L_sub(L_bwe_br, HQ_13k20) == 0) ) - { - IF( sub(hqswb_clas_fx, HQ_HARMONIC) == 0 ) - { - set16_fx( p2a_flags_fx, 1, har_bands_fx ); - } - ELSE - { - /* High band tonality detector based on per band peak-to-average ratio */ - pbits_fx = p2a_threshold_quant_fx( st_fx, L_t_audio, band_start, band_end, band_width, bands_fx, p2a_bands_fx, p2a_th_fx, p2a_flags_fx ); - bit_budget_fx = sub(bit_budget_fx, pbits_fx); - - IF( sub(hqswb_clas_fx, HQ_NORMAL) == 0 ) - { - return_bits_normal2_fx( &bit_budget_fx, p2a_flags_fx, bands_fx, bits_lagIndices_modeNormal_fx ); - } - } - } - ELSE - { - /* High band tonality detector based on per band peak-to-average ratio */ - pbits_fx = p2a_threshold_quant_fx( st_fx, L_t_audio, band_start, band_end, band_width, bands_fx, p2a_bands_fx, p2a_th_fx, p2a_flags_fx ); - bit_budget_fx = sub(bit_budget_fx, pbits_fx); - } - - IF(sub(flag_spt_fx, 1) == 0) - { - spt_shorten_domain_band_save_fx(bands_fx, band_start, band_end, band_width, org_band_start, org_band_end, org_band_width); - spt_shorten_domain_pre_fx(band_start, band_end, st_fx->prev_SWB_peak_pos_fx, bands_fx, L_bwe_br, new_band_start, new_band_end, new_band_width); - spt_shorten_domain_set_fx(st_fx, L_t_audio, p2a_flags_fx, new_band_start, new_band_end, new_band_width, bands_fx, band_start, band_end, band_width, &bit_budget_fx); - } - - /* Estimate number of bits per band */ - Q_band_energy = SWB_BWE_LR_Qbe; - - FOR(i = 0; i < bands_fx; i++) - { - L_tmp = L_shl(L_band_energy[i],sub(16,Q_band_energy));/*Q16 */ - - frac1 = L_Extract_lc(L_tmp, &exp); /* Extract exponent of L_tmp */ - L_tmp = Pow2(30, frac1); - exp = sub(exp, 30); - Ep_fx[i] = L_shl(L_tmp , s_max(sub(exp,6), -31)); /* Q -6 */ - } - - FOR( i = 0; i < bands_fx; i++ ) - { - L_tmp2 = Ep_fx[i]; - L_tmp = L_max(1, L_tmp2); - exp = norm_l(L_tmp); - tmp = extract_h(L_shl(L_tmp, exp)); - - L_tmp3 = (Word32)band_width[i]; - exp2 = norm_l(L_tmp3); - tmp2 = extract_h(L_shl(L_tmp3, exp2)); - - exp2 = sub(exp, exp2); /* Denormalize and substract */ - - tmp3 = sub(tmp2, tmp); - if (tmp3 > 0) - { - tmp2 = shr(tmp2, 1); - } - if (tmp3 > 0) - { - exp2 = add(exp2, 1); - } - tmp = div_s(tmp2, tmp); - L_tmp = L_deposit_h(tmp); - L_tmp = Isqrt_lc(L_tmp, &exp2);/*Q(31-exp2) */ - Ep_tmp_fx[i] = L_shr(L_tmp,sub(15,exp2));/*Q13 */ - } - - test(); - test(); - test(); - test(); - test(); - test(); - IF ( is_transient_fx == 0 && sub(inner_frame_fx, L_FRAME8k) == 0 && L_sub(st_fx->core_brate_fx, ACELP_13k20) <= 0 ) - { - lowband = 6; - move16(); - trans_bit = 2; - move16(); - bit_budget_fx =sub(bit_budget_fx,trans_bit); - gama_fx = 27852; /*Q15 0.85f;// */ - beta_fx = 17203; - move16();/*Q14 1.05f; */ - - set16_fx( &p2a_flags_tmp[sub(bands_fx,trans_bit)], 0, 2 ); - - IF( L_sub(st_fx->core_brate_fx, ACELP_13k20) == 0 ) - { - beta_fx = 13107; - move16();/*14 1.25f; */ - gama_fx = 31130; - move16();/*0.95f; */ - Copy(&p2a_flags_fx[sub(bands_fx,trans_bit)], &p2a_flags_tmp[sub(bands_fx,trans_bit)], trans_bit); - } - /* calculate the the low band/high band energy and the variance/avrage of the envelopes */ - Ep_vari_fx = L_deposit_l(0); - Ep_avrg_fx = L_deposit_l(0); - Ep_avrgL_fx = L_deposit_l(0); - Ep_peak_fx = L_deposit_l(0); - FOR( i = 0; i < bands_fx; i++ ) - { - IF( sub(i,lowband) >= 0) - { - Ep_vari_fx = L_add(Ep_vari_fx,L_abs(L_sub(Ep_tmp_fx[i],Ep_tmp_fx[sub(i,1)])));/*Q15 */ - Ep_avrg_fx = L_add(Ep_avrg_fx,Ep_tmp_fx[i]);/*Q15 */ - - } - ELSE - { - Ep_avrgL_fx = L_add(Ep_avrgL_fx,Ep_tmp_fx[i]);/*Q15 */ - IF(L_sub(Ep_tmp_fx[i],Ep_peak_fx) > 0) - { - Ep_peak_fx = L_add(Ep_tmp_fx[i], 0); /*Q15 */ - } - } - } - /* modify the last p2a_bands subbands band_energies */ - Copy32( L_band_energy,L_band_energy_tmp,bands_fx ); /*Q_band_energy */ - L_tmp = Mult_32_16(Ep_peak_fx,24576);/*Q(13+14-15 = 12) 1.5 lowband = 6; */ - L_tmp2 =Mult_32_16(Ep_peak_fx,shl(sub(bands_fx,lowband),9));/*Q(13+9-15 = 7) */ - L_tmp3 =Mult_32_16(Ep_avrg_fx,1126);/*Q(13+9-15 = 7) */ - - test(); - test(); - test(); - test(); - IF(( (L_sub(L_tmp, L_shr(Ep_avrgL_fx,1)) < 0 && L_sub(st_fx->core_brate_fx, ACELP_13k20) == 0 ) || L_sub(st_fx->core_brate_fx, ACELP_13k20) < 0 )&& - L_sub(L_tmp2, L_tmp3) < 0 && L_sub(L_tmp2, L_shr(Ep_avrg_fx,7)) > 0) - { - FOR(i = lowband; i < bands_fx; i++) - { - L_tmp = Mult_32_16(Ep_avrg_fx,24576);/*Q(13+14-15 = 12) 1.5 */ - IF(L_sub(L_shr(Ep_tmp_fx[i],1), L_tmp) < 0) - { - L_tmp = Mult_32_16(Ep_peak_fx,sub(bands_fx,lowband));/*Q(13+0-15 = -2) */ - tmp = extract_h(L_shl(L_tmp,14));/*Q-4 */ - IF(tmp != 0) - { - exp = norm_s(tmp); - tmp = shl(tmp,exp);/*Q(exp) */ - tmp = div_s(16384,tmp);/*Q(15+14-exp=29-exp) */ - exp = sub(29,exp); - } - ELSE - { - /*when the divisor is zero, happens rarely*/ - tmp = 0x7fff; - move16(); - exp = 0; - move16(); - } - L_tmp = L_shl(Mult_32_16(Ep_avrg_fx,tmp),sub(13,exp));/*Q(13+exp-15 +13-exp +4 = 15) */ - L_tmp2 = L_add(L_tmp,13107); /*15 */ - tmp2 = extract_l(L_min(L_max(L_tmp2,16384),gama_fx)); /*15 = 15 */ - L_band_energy_tmp[i] = Mult_32_16(L_band_energy_tmp[i],tmp2);/*Q(Q_band_energy+15-15 = Q_band_energy) */ - } - } - } - ELSE - { - j = 0; - FOR(i = sub(bands_fx,trans_bit); i < bands_fx; i++) - { - alpha_fx = 16384; - move16();/*Q14 */ - IF( sub(p2a_flags_tmp[i],1) == 0) - { - L_tmp = Mult_32_16(Ep_tmp_fx[i],sub(bands_fx,lowband));/*Q(13+0-15 = -2) */ - tmp = extract_h(L_shl(L_tmp,14));/*Q-4 */ - IF(tmp != 0) - { - exp = norm_s(tmp); - tmp = shl(tmp,exp);/*Q(exp) */ - tmp = div_s(16384,tmp);/*Q(15+14-exp=29-exp) */ - exp = sub(29,exp); - } - ELSE - { - /*when the divisor is zero, happens rarely*/ - tmp = 0x7fff; - move16(); - exp = 0; - move16(); - } - L_tmp =Mult_32_16(Ep_vari_fx,3277);/*13+15-15=13 */ - L_tmp = L_shl(Mult_32_16(L_tmp,tmp),sub(12,exp));/*Q(13+exp-15 +12-exp +4 = 14) */ - - tmp2 = extract_h(Ep_avrg_fx);/*Q13-16=-3 */ - IF(tmp2 != 0) - { - exp = norm_s(tmp2); - tmp2 = shl(tmp2,exp);/*Q(exp) */ - tmp2 = div_s(16384,tmp2);/*Q(15+14-exp=29-exp) */ - exp = sub(29,exp); - } - ELSE - { - tmp2 = 0x7fff; - move16(); - exp = 0; - move16(); - } - L_tmp2 =Mult_32_16(Ep_vari_fx,6554);/*13+15-15=13 */ - L_tmp2 = L_shl(Mult_32_16(L_tmp2,tmp2),sub(13,exp));/*Q(13+exp-15 +13-exp +3 = 14) */ - L_tmp=L_min(L_tmp,L_tmp2);/*14 */ - tmp=extract_l(L_min(L_tmp,13107));/*14 */ - alpha_fx =add(16384,tmp); - - } - IF(sub(st_fx->last_bitalloc_max_band_fx[j++], 1) == 0) - { - L_tmp = Mult_32_16(Ep_tmp_fx[i],sub(bands_fx,lowband));/*Q(13+0-15 = -2) */ - tmp = extract_h(L_shl(L_tmp,14));/*Q-2 */ - IF(tmp != 0) - { - exp = norm_s(tmp); - tmp = shl(tmp,exp);/*Q(exp) */ - tmp = div_s(16384,tmp);/*Q(15+14-exp=29-exp) */ - exp = sub(29,exp); - } - ELSE - { - tmp = 0x7fff; - move16(); - exp = 0; - move16(); - } - L_tmp = L_shl(Mult_32_16(Ep_avrg_fx,tmp),sub(14,exp));/*Q(13+exp-15 +14-exp+2 = 14) */ - L_tmp =L_max(L_tmp,16384); /*14 */ - tmp=extract_l(L_min(L_tmp,beta_fx)); /*14 */ - alpha_fx=shl(mult(alpha_fx,tmp),1);/*14+14-15 +1=14 */ - } - ELSE - { - tmp2 = extract_h(Ep_avrg_fx);/*13 -16 =-3 */ - IF(tmp2 != 0) - { - exp = norm_s(tmp2); - tmp2 = shl(tmp2,exp);/*Q(exp) */ - tmp2 = div_s(16384,tmp2);/*Q(15+14-exp=29-exp) */ - exp = sub(29,exp); - } - ELSE - { - /*when the divisor is zero, happens rarely*/ - tmp2 = 0x7fff; - move16(); - exp = 0; - move16(); - } - L_tmp = L_shl(Mult_32_16(Ep_tmp_fx[i],tmp2),sub(19,exp));/*Q(13+exp-15 +19-exp +3 = 20) */ - L_tmp = Mult_32_16(L_tmp,shl(sub(bands_fx,lowband),9));/*20 +9 -15 =14 */ - L_tmp =L_max(L_tmp,13926); /*14 */ - tmp2 =extract_l(L_min(L_tmp,16384)); /*14 */ - alpha_fx=shl(mult(alpha_fx,tmp2),1);/*14+14-15+1 =14 */ - } - L_band_energy_tmp[i] = L_shl(Mult_32_16(L_band_energy_tmp[i],alpha_fx),1);/*Q(Q_band_energy+14-15 +1= Q_band_energy) */ - } - } - lowband = 3; - move16(); - Ep_avrg_fx = L_deposit_l(0); - Ep_avrgL_fx = L_deposit_l(0); - Ep_peak_fx = L_deposit_l(0); - FOR(i = 0; i < bands_fx; i++) - { - IF(sub(i,lowband) >=0 ) - { - Ep_avrg_fx = L_add(Ep_avrg_fx,Ep_tmp_fx[i]);/*Q15 */ - } - ELSE - { - Ep_avrgL_fx = L_add(Ep_avrgL_fx,L_shr(Ep_tmp_fx[i],1));/*Q12 */ - IF(L_sub(Ep_tmp_fx[i],Ep_peak_fx) > 0) - { - Ep_peak_fx = L_add(Ep_tmp_fx[i], 0); /*Q13 */ - } - } - } - L_tmp = Mult_32_16(Ep_peak_fx,28262);/*Q(13+14-15 = 12) 1.725 lowband = 3; */ - L_tmp2 =Mult_32_16(Ep_avrgL_fx,24576);/*Q(12+14-15 = 11) */ - test(); - test(); - IF( L_sub(L_shr(Ep_avrg_fx,2), L_tmp2) > 0 && L_sub(L_shr(Ep_avrg_fx,4), L_tmp2) < 0 && L_sub(L_tmp, Ep_avrgL_fx)>0) - { - adjustFlag = 1; - move16(); - FOR (i = 0; i < lowband; i++) - { - tmp = extract_h(Ep_avrgL_fx);/*Q-4 */ - IF(tmp != 0) - { - exp = norm_s(tmp); - tmp = shl(tmp,exp);/*Q(exp) */ - tmp = div_s(16384,tmp);/*Q(15+14-exp=29-exp) */ - exp = sub(29,exp); - } - ELSE - { - /*when the divisor is zero, happens rarely*/ - tmp = 0x7fff; - move16(); - exp = 0; - move16(); - } - L_tmp = Mult_32_16(Ep_peak_fx,tmp);/*Q(13+exp-15+4 = exp+2) */ - L_tmp = Mult_32_16(L_tmp,lowband);/*Q(exp+2+0-15 = exp-13) */ - L_tmp = Mult_32_16(L_tmp,18842);/*Q(exp-13+16-16 = exp-13) */ - L_tmp = L_shl(L_tmp,sub(27,exp));/*Q14 0.5 */ - tmp2=extract_l(L_min(L_tmp,19661));/*14 */ - L_tmp = Mult_32_16(L_band_energy_tmp[i],tmp2);/*Q(Q_band_energy+14-15 = Q_band_energy-1) */ - L_band_energy_tmp[i] = L_shl(L_tmp,1); /*Q_band_energy */ - } - } - hq2_bit_alloc_fx( L_band_energy_tmp, bands_fx, L_Rk, &bit_budget_fx, p2a_flags_fx, bit_alloc_weight_fx, band_width, - *num_bits_fx, hqswb_clas_fx, st_fx->bwidth_fx, is_transient_fx ); - - /* encode the last p2a_bands-1 subbands bit-allocation index of the previous frame */ - FOR(i = 0; i < 2; i++) - { - push_indice_fx ( st_fx, IND_HQ2_LAST_BA_MAX_BAND, st_fx->last_bitalloc_max_band_fx[i], 1 ); - } - } - ELSE IF( is_transient_fx == 0 && sub(inner_frame_fx, L_FRAME16k) == 0 ) - { - bit_budget_fx = sub(bit_budget_fx,2);/* bits in high bands to indicate the last 2 subbands is allocated bits or not */ - FOR( i = 0; i < bands_fx; i++ ) - { - Ep_tmp_fx[i] = L_shl(Ep_tmp_fx[i],2); - } - IF( L_sub( st_fx->core_brate_fx, ACELP_13k20 ) == 0) - { - lowband = 8; - move16(); - highband = 15; - move16(); - bw_low = sub(band_start[highband],band_start[lowband]); - bw_high = sub(add(band_end[sub(bands_fx,1)],1),band_start[highband]); - } - ELSE - { - lowband = 8; - move16(); - highband = 16; - move16(); - bw_low = sub(band_start[highband],band_start[lowband]); - bw_high = sub(add(band_end[sub(bands_fx,1)],1),band_start[highband]); - } - /* calculate the the low band/high band energy and the variance/avrage of the envelopes */ - enerL_fx = L_deposit_l(0); - enerH_fx = L_deposit_l(0); - Ep_vari_fx = L_deposit_l(0); - Ep_avrg_fx = L_deposit_l(0); - FOR( i = 0; i < bands_fx; i++ ) - { - test(); - IF( sub(i,lowband) >= 0 && add(sub(i,bands_fx),p2a_bands_fx) < 0) - { - Ep_vari_fx = L_add(Ep_vari_fx,L_abs(L_sub(Ep_tmp_fx[i],Ep_tmp_fx[sub(i,1)])));/*Q15 */ - Ep_avrg_fx = L_add(Ep_avrg_fx,Ep_tmp_fx[i]);/*Q15 */ - } - - IF(sub(i,highband) >= 0) - { - enerH_fx = L_add(enerH_fx,L_shl(Ep_fx[i],2));/*Q0 */ - } - ELSE IF(sub(i,lowband) >= 0) - { - enerL_fx = L_add(enerL_fx,L_shl(Ep_fx[i],2));/*Q0 */ - } - } - - /* modify the last p2a_bands subbands band_energies */ - Copy32( L_band_energy,L_band_energy_tmp,bands_fx ); /*Q_band_energy */ - L_tmp = L_max(enerH_fx,enerL_fx); - tmp = s_max(bw_low,bw_high); - i = norm_l(L_tmp); - j = norm_s(tmp); - L_tmp = Mult_32_16(L_shl(enerH_fx,i), shl(bw_low,j)); /* i + j -15 */ - L_tmp2 = Mult_32_16(L_shl(enerL_fx,i), shl(bw_high,j)); /*i + j -15 */ - L_tmp2 = L_sub(L_tmp,L_tmp2); - FOR( i = sub(bands_fx,p2a_bands_fx); i < bands_fx; i++ ) - { - test(); - IF( sub(p2a_flags_fx[i],1) == 0 || L_tmp2 > 0 ) - { - tmp = sub(bands_fx,p2a_bands_fx); - tmp = sub(tmp,lowband);/*Q0 */ - - tmp1 = extract_h(L_shl(Ep_avrg_fx,1));/*Q0 */ - IF(tmp1 != 0) - { - exp = norm_s(tmp1); - tmp1 = shl(tmp1,exp);/*Q(exp) */ - tmp1 = div_s(16384,tmp1);/*Q(15+14-exp = 29-exp) */ - exp = sub(29,exp); - } - ELSE - { - tmp1 = 0x7fff; - move16(); - exp = 0; - move16(); - } - L_tmp = Mult_32_16(Ep_tmp_fx[i],tmp1);/*Q(15+exp-15 = exp) */ - L_tmp = Mult_32_16(L_tmp,tmp);/*Q(exp+0-15 = exp-15) */ - L_tmp = Mult_32_16(L_tmp,16384);/*Q(exp-15+13-15 = exp-17) */ - L_tmp = L_shl(L_tmp,sub(32,exp));/*Q15 */ - tmp = extract_l(L_min(L_tmp,6554));/*Q15 */ - L_tmp = Mult_32_16(Ep_vari_fx,tmp1);/*Q(15+exp-15 = exp) */ - L_tmp = Mult_32_16(L_tmp,tmp);/*Q(exp+15-15 = exp) */ - L_tmp = L_shl(L_tmp,sub(15,exp));/*Q15 */ - tmp = extract_l(L_shr(L_min(L_tmp,13107),1));/*Q14 */ - alpha_fx = add(tmp,16384);/*Q14 */ - } - ELSE - { - alpha_fx = 16384; - move16();/*Q14 */ - } - - IF(add(sub(i,bands_fx),p2a_bands_fx) > 0) - { - tmp = sub(bands_fx,p2a_bands_fx); - IF(sub(st_fx->last_bitalloc_max_band_fx[sub(i, add(tmp, 1))], 1) == 0) - { - tmp = sub(tmp,lowband); - L_tmp = Mult_32_16(Ep_tmp_fx[i],tmp);/*Q(15+0-15 = 0) */ - tmp = extract_h(L_shl(L_tmp,16));/*Q0 */ - IF(tmp != 0) - { - exp = norm_s(tmp); - tmp = shl(tmp,exp);/*Q(exp) */ - tmp = div_s(16384,tmp);/*Q(15+14-exp=29-exp) */ - exp = sub(29,exp); - } - ELSE - { - tmp = 0x7fff; - move16(); - exp = 0; - move16(); - } - L_tmp = Mult_32_16(Ep_avrg_fx,tmp);/*Q(15+exp-15 = exp) */ - L_tmp = L_shl(L_tmp,sub(14,exp));/*Q14 */ - tmp = extract_l(L_min(L_max(L_tmp,16384),20480));/*Q14 */ - L_tmp = L_mult(alpha_fx,tmp);/*Q(14+14+1=29) */ - alpha_fx = extract_l(L_shr(L_tmp,15)); /*Q14 */ - } - ELSE - { - tmp = sub(tmp,lowband); - - tmp1 = extract_h(L_shl(Ep_avrg_fx,1));/*Q0 */ - IF(tmp1 != 0) - { - exp = norm_s(tmp1); - tmp1 = shl(tmp1,exp);/*Q(exp) */ - tmp1 = div_s(16384,tmp1);/*Q(15+14-exp=29-exp) */ - exp = sub(29,exp); - } - ELSE - { - tmp1 = 0x7fff; - move16(); - exp = 0; - move16(); - } - L_tmp = Mult_32_16(Ep_tmp_fx[i],tmp1);/*Q(15+exp-15 = exp) */ - L_tmp = Mult_32_16(L_tmp,tmp);/*Q(exp+0-15 = exp-15) */ - L_tmp = L_shl(L_tmp,sub(29,exp));/*Q14 */ - tmp = extract_l(L_min(L_max(L_tmp,13926),16384));/*Q14 */ - L_tmp = L_mult(alpha_fx,tmp);/*Q(14+14+1=29) */ - alpha_fx = extract_l(L_shr(L_tmp,15)); /*Q14 */ - } - } - L_tmp = Mult_32_16(L_band_energy_tmp[i],alpha_fx);/*Q(Q_band_energy+14-15=Q_band_energy-1) */ - L_band_energy_tmp[i] = L_shl(L_tmp,1);/*Q Q_band_energy */ - } - lowband = 6; - move16(); - Ep_avrg_fx = L_deposit_l(0); - Ep_avrgL_fx = L_deposit_l(0); - Ep_peak_fx = L_deposit_l(0); - FOR(i = 0; i < bands_fx; i++) - { - IF(sub(i,lowband) >= 0) - { - Ep_avrg_fx = L_add(Ep_avrg_fx,Ep_tmp_fx[i]);/*Q15 */ - } - ELSE - { - Ep_avrgL_fx = L_add(Ep_avrgL_fx,Ep_tmp_fx[i]);/*Q15 */ - IF(L_sub(Ep_tmp_fx[i],Ep_peak_fx) > 0) - { - Ep_peak_fx = L_add(Ep_tmp_fx[i], 0); /*Q15 */ - } - } - } - - L_tmp = Mult_32_16(Ep_peak_fx,24576);/*Q(15+12-15 = 12) lowband = 6; */ - L_tmp2 =Mult_32_16(Ep_peak_fx,19661);/*Q(15+14-15 = 14) */ - L_tmp3 =Mult_32_16(Ep_avrgL_fx,24576);/*Q(15+12-15 = 12) */ - - test(); - test(); - test(); - test(); - test(); - IF( (L_sub(L_shr(Ep_avrgL_fx,1), Ep_avrg_fx)>0 && L_sub(L_tmp,L_shr(Ep_avrgL_fx,2)) > 0 && L_sub(L_shr(Ep_avrgL_fx,1),L_tmp2) < 0 ) || - (L_sub(L_shr(Ep_avrg_fx,1), Ep_avrgL_fx)>0 && L_sub(L_shr(Ep_avrg_fx,3),L_tmp3) < 0 && L_sub(L_tmp,L_shr(Ep_avrgL_fx,2)) > 0 ) ) - { - adjustFlag = 1; - move16(); - FOR (i = 0; i < lowband; i++) - { - tmp = extract_h(L_shl(Ep_avrgL_fx,1));/*Q0 */ - IF(tmp != 0) - { - exp = norm_s(tmp); - tmp = shl(tmp,exp);/*Q(exp) */ - tmp = div_s(16384,tmp);/*Q(15+14-exp=29-exp) */ - exp = sub(29,exp); - } - ELSE - { - tmp = 0x7fff; - move16(); - exp = 0; - move16(); - } - L_tmp = Mult_32_16(Ep_peak_fx,tmp);/*Q(15+exp-15 = exp) */ - L_tmp = Mult_32_16(L_tmp,lowband);/*Q(exp+0-15 = exp-15) */ - L_tmp = L_shl(L_tmp,sub(28,exp));/*Q14 0.5 */ - tmp = extract_l(L_min(L_tmp,19661));/*//Q14 */ - L_tmp = Mult_32_16(L_band_energy_tmp[i],tmp);/*Q(Q_band_energy+14-15 = Q_band_energy-1) */ - L_band_energy_tmp[i] = L_shl(L_tmp,1); /*Q_band_energy */ - } - } - - hq2_bit_alloc_fx( L_band_energy_tmp, bands_fx, L_Rk, &bit_budget_fx, p2a_flags_fx, bit_alloc_weight_fx, band_width, - *num_bits_fx, hqswb_clas_fx, st_fx->bwidth_fx, is_transient_fx ); - - /* encode the last p2a_bands-1 subbands bit-allocation index of the previous frame */ - FOR(i = 0; i < 2; i++) - { - push_indice_fx( st_fx, IND_HQ2_LAST_BA_MAX_BAND, st_fx->last_bitalloc_max_band_fx[i], 1 ); - } - } - ELSE IF( sub(st_fx->bwidth_fx, SWB) == 0 && sub(hqswb_clas_fx, HQ_HARMONIC) == 0 && (L_sub(L_bwe_br, HQ_16k40) == 0 || L_sub(L_bwe_br, HQ_13k20) == 0) ) - { - /* bit allocation for harmonic mode */ - hq2_bit_alloc_har_fx( L_band_energy, bit_budget_fx, bands_fx, L_Rk, p2a_bands_fx, L_bwe_br, p2a_flags_fx, band_width ); - } - ELSE - { - - /* estimate number of bits per band */ - hq2_bit_alloc_fx( - L_band_energy, bands_fx, L_Rk, &bit_budget_fx, p2a_flags_fx, bit_alloc_weight_fx, band_width, - *num_bits_fx, hqswb_clas_fx, st_fx->bwidth_fx, is_transient_fx ); - } - - tcq_core_LR_enc_fx( st_fx, inp_vector_fx, /*t_audio, */L_t_audio, /*y2, */L_y2, bit_budget_fx, bands_fx, band_start, band_end, band_width, /*Rk*/L_Rk, npulses_fx, k_sort_fx, - p2a_flags_fx, p2a_bands_fx, st_fx->last_bitalloc_max_band_fx, inner_frame_fx, adjustFlag, is_transient_fx ); - - IF((sub(inner_frame_fx, L_FRAME8k) == 0 && L_sub(st_fx->core_brate_fx, ACELP_13k20) <= 0) || sub(inner_frame_fx, L_FRAME16k) == 0) - { - j = 0; - FOR(i = 2; i > 0; i--) - { - IF(npulses_fx[bands_fx-i] > 0) - { - st_fx->last_bitalloc_max_band_fx[j] = 1; - } - ELSE - { - st_fx->last_bitalloc_max_band_fx[j] = 0; - } - j++; - } - } - - /* Denormalize the coded MDCT spectrum */ - mdct_spectrum_denorm_fx( inp_vector_fx, L_y2, band_start, band_end, band_width, L_band_energy, npulses_fx, bands_fx, ld_slope_fx, pd_thresh_fx ); - - /* Apply fine gain quantization to denormalized coded spectrum */ - mdct_spectrum_fine_gain_enc_fx( st_fx, L_t_audio, L_y2, band_start, band_end, k_sort_fx, bands_fx, - L_qint, Ngq_fx, gqlevs_fx, gqbits_fx ); - - - /* Restore the band information */ - IF( sub(flag_spt_fx, 1) == 0 ) - { - spt_shorten_domain_band_restore_fx(bands_fx, band_start, band_end, band_width, org_band_start, org_band_end, org_band_width); - } - - /* Inject noise into components having relatively low pulse energy per band */ - ni_seed_fx = add(add(add(npulses_fx[0], npulses_fx[1]), npulses_fx[2]), npulses_fx[3]); - - Copy32(L_y2, L_y2_ni, band_end[bands_fx-1]+1); - hq2_noise_inject_fx( L_y2_ni, band_start, band_end, band_width, Ep_fx, L_Rk, npulses_fx, ni_seed_fx, bands_fx, 0, bw_low, bw_high, enerL_fx, enerH_fx, - st_fx->last_ni_gain_fx, st_fx->last_env_fx, &st_fx->last_max_pos_pulse_fx, p2a_flags_fx, p2a_bands_fx, - hqswb_clas_fx, st_fx->bwidth_fx, L_bwe_br ); - - test(); - test(); - IF( sub(st_fx->bwidth_fx, SWB) == 0 && (L_sub(L_bwe_br, HQ_16k40) == 0 || L_sub(L_bwe_br, HQ_13k20) == 0) ) - { - test(); - IF( sub(hqswb_clas_fx, HQ_NORMAL) == 0 || sub(hqswb_clas_fx, HQ_HARMONIC) == 0) - { - preset_hq2_swb_fx( hqswb_clas_fx, band_end, &har_bands_fx, p2a_bands_fx,length_fx, bands_fx, &lowlength_fx, &highlength_fx, L_m ); - - swb_bwe_enc_lr_fx( - st_fx, - L_y2, SWB_BWE_LR_Qs, L_t_audio, L_m, - L_bwe_br, - bands_fx, band_start, band_end, - L_band_energy, SWB_BWE_LR_Qbe, - p2a_flags_fx, - hqswb_clas_fx, lowlength_fx, highlength_fx, - st_fx->prev_frm_index_fx, - har_bands_fx, - &st_fx->prev_frm_hfe2_fx, &st_fx->prev_stab_hfe2_fx, - band_width, L_y2_ni, &ni_seed_fx - ); - - post_hq2_swb_fx( L_m, lowlength_fx, highlength_fx, hqswb_clas_fx, har_bands_fx, bands_fx, p2a_flags_fx, band_start, band_end, L_y2, npulses_fx ); - - IF( sub(hqswb_clas_fx, HQ_NORMAL) == 0 ) - { - spt_swb_peakpos_tmp_save_fx(L_y2, bands_fx, band_start, band_end, prev_SWB_peak_pos_tmp_fx); - FOR( k=0; kbwidth_fx, is_transient_fx, hqswb_clas_fx, &st_fx->prev_hqswb_clas_fx, - st_fx->prev_SWB_peak_pos_fx, prev_SWB_peak_pos_tmp_fx, &st_fx->prev_frm_hfe2_fx, &st_fx->prev_stab_hfe2_fx, 0 ); - - IF( sub(st_fx->bwidth_fx, SWB) != 0 ) - { - /* reset HQ classifier memories */ - st_fx->mode_count_fx = 0; - move16(); - st_fx->mode_count1_fx = 0; - move16(); - } - - test(); - test(); - test(); - IF( sub(hqswb_clas_fx, HQ_HARMONIC) != 0 && (L_sub(L_bwe_br, HQ_16k40) == 0 || L_sub(L_bwe_br, HQ_13k20) == 0 ) && sub(st_fx->bwidth_fx, SWB) == 0 ) - { - st_fx->prev_frm_index_fx[0] = -1; - move16(); - st_fx->prev_frm_index_fx[1] = -1; - move16(); - } - - /* update number of unused bits */ - *num_bits_fx = 0; - move16(); - - st_fx->hvq_hangover_fx = 0; - move16(); - - return; -} - -/*--------------------------------------------------------------------------* - * small_symbol_enc_tran() - * - * Huffman encoding of differential energies, estimating or packing bits - * if flag_pack = 0, LC mode info. is output else LC mode info. is input - * if flag_pack = 0, estimatng else packing bits - *--------------------------------------------------------------------------*/ - -static Word16 small_symbol_enc_tran_fx( /* o : bits */ - Encoder_State_fx *st_fx, /* i/o: encoder state structure */ - const Word16 *qbidx, /* i : input of dequantized differential energy */ - const Word16 BANDS, /* i : number of bands */ - Word16 *hLCmode, /* i/o: LC mode info */ - const Word16 flag_pack, /* i : indicator of packing or estimating bits */ - const Word16 is_transient -) -{ - Word16 i, bits; - Word16 difidx[BANDS_MAX]; - - FOR( i=0; i 0 || difidx[i] < 0 ) - { - /* Huffman cannot encode this vector */ - return -1; - } - } - - /* Preparing lossless coding input */ - IF ( flag_pack == 0 ) - { - /* estimating # of bits */ - bits = encode_envelope_indices_fx(st_fx, BANDS, -1, difidx, hLCmode, flag_pack, LOW_RATE_HQ_CORE_TRAN , is_transient ); - bits = add(bits, BITS_DE_FCOMP); /* xx bits for diff. energies + BITS_DE_FCOMP bits for first energies */ - } - ELSE - { - bits = 0; - move16(); - encode_envelope_indices_fx(st_fx, BANDS, -1, difidx, hLCmode, flag_pack, LOW_RATE_HQ_CORE_TRAN ,is_transient ); - } - - return add(bits, BITS_DE_HMODE); /* xx bits for diff. energies + 1 bit for LC coding mode */ -} - - -/*--------------------------------------------------------------------------* - * small_symbol_enc() - * - * Huffman encoding of differential energies, estimating or packing bits - * if flag_pack = 0, LC mode info. is output else LC mode info. is input - * if flag_pack = 0, estimatng else packing bits - *--------------------------------------------------------------------------*/ - -static Word16 small_symbol_enc_fx( /* o : bits */ - Encoder_State_fx *st_fx, /* i/o: encoder state structure */ - const Word16 *qbidx, /* i : input of dequantized differential energy */ - const Word16 BANDS, /* i : number of bands */ - Word16 *hLCmode, /* i/o: LC mode info */ - const Word16 flag_pack /* i : indicator of packing or estimating bits */ - ,const Word16 is_transient -) -{ - Word16 i, bits; - Word16 difidx[BANDS_MAX], LSB[BANDS_MAX]; - - /* Preparing lossless coding input */ - difidx[0] = add(qbidx[0], DE_OFFSET0); - move16(); - - FOR( i=1; i= 0 || difidx[i] < 0 ) - { - /* Huffman cannot encode this vector */ - return -1; - } - } - - /* splitting MSB and LSB */ - FOR( i=0; i 0 || sub(qbidx[0],-ABS_ENG_OFFSET) < 0) - { - cnt_outlyer0 = 2; - move16(); - } - ELSE IF ( sub(qbidx[0],3) > 0 || sub(qbidx[0],-4) < 0 ) - { - cnt_outlyer0 = 1; - move16(); - } - ELSE - { - cnt_outlyer0 = 0; - move16(); - } - - cnt_outlyer = 0; - move16(); - pos_outlyer = -1; - move16(); - FOR( i=1; i 0 || sub(qbidx[i],-4) < 0 ) - { - cnt_outlyer = add(cnt_outlyer, 1); - pos_outlyer = i; - move16(); - } - - test(); - if ( sub(qbidx[i], sub(ABS_ENG_OFFSET,1)) > 0 || sub(qbidx[i], -ABS_ENG_OFFSET) < 0 ) - { - cnt_outlyer = add(cnt_outlyer, 1); - } - } - - test(); - test(); - IF ( cnt_outlyer0 == 0 && sub(cnt_outlyer, 1) <= 0 ) - { - bitsmode0 = add(add(BITS_DE_8SMODE, BITS_DE_8SMODE_N0), BITS_DE_8SMODE_N1); - IF ( sub(cnt_outlyer, 1) == 0 ) - { - /* 01 */ - bitsmode0 = add(bitsmode0, add(BITS_DE_8SPOS, BITS_ABS_ENG)); - } - - FOR( i=0; i= -(2<<(i+1))) */ - test(); - IF ( sub(max_q, sub(shl(2, add(i,1)), 1)) <= 0 && sub(min_q, -shl(2,add(i,1))) >= 0 ) - { - BREAK; - } - } - basic_shift = i; - move16(); - - min_bits = 1000; - move16(); - min_bits_pos = basic_shift; - move16(); - tmp = add(basic_shift, 3); - FOR( offset0=basic_shift; offset0 0 ) - { - min_bits_pos = offset0; - move16(); - min_bits = bitsmode1; - move16(); - } - } - - bitsmode1 = min_bits; - move16(); - lsbdepth1 = min_bits_pos; - move16(); - - FOR( i=0; i 0 ) - { - FOR( i=0; i QE) */ - FOR (i = band_start[k]; i <= band_end[k]; i++) - { - /*E += yos[i] * yos[i]; */ - temp_fx = round_fx(L_shl(L_t_audio[i], exp_norm)); - L_E = L_mac(L_E, temp_fx, temp_fx); /* (Qs+exp_norm-16)*2+1 */ - } - - /*band_energy[k] = (float) log2_f (E + 1.0e-1f); */ - exp_norm2 = norm_l(L_E); - exp = add(add(shl(sub(add(SWB_BWE_LR_Qs, exp_norm), 16), 1), 1), exp_norm2); - L_E = L_shl(L_E, exp_norm2); - frac = Log2_norm_lc(L_E); - exp = sub(30, exp); - L_tmp = L_Comp(exp, frac); - L_band_energy[k] = L_shr(L_tmp, 2); /* Q16->Qbe(Q14) */ - } - - IF (is_transient_fx) - { - reverse_transient_frame_energies_fx( L_band_energy, bands_fx ); - } - - - /* Quantize the reference and band energies */ - exp_normd = norm_l(L_qint); - rev_qint_fx = div_s(0x4000, round_fx(L_shl(L_qint, exp_normd))); /* Q14-(29+exp_normd-16)+15 */ - Qrev_qint = sub(14-(29-16)+15, exp_normd); - - bq0_fx = round_fx(L_shl(L_mult(eref_fx, rev_qint_fx), sub(5, Qrev_qint))); /* 16-(10+Qrev_qint+1) */ - FOR (k = 0; k < bands_fx; k++) - { - /*bq1[k] = round_f (band_energy[k] / qint); */ - L_tmp = Mpy_32_16_1(L_band_energy[k], rev_qint_fx); /* Q14+Qrev_qint-15 */ - bq1_fx[k] = round_fx( L_shl(L_tmp, sub(17, Qrev_qint)) ); /* 16-(14+Qrev_qint-15) */ - } - - IF(is_transient_fx) - { - - Copy(bq1_fx, bq1_temp_fx, bands_fx); - - /* Calculate the differential energies */ - diffcod_lrmdct_fx(bands_fx, bq0_fx, bq1_temp_fx, bq2_temp_fx, is_transient_fx); - } - - /* Calculate the differential energies */ - bq2_fx[0] = sub(bq1_fx[0], bq0_fx); - FOR (k = 1; k < bands_fx; k++) - { - bq2_fx[k] = sub(bq1_fx[k], bq1_fx[k - 1]); - move16(); - } - - /* Modifying qbidx to be located in the range -256~255 */ - FOR( i=0; i 0 ) - { - bq2_fx[i] = MAXIMUM_ENERGY_LOWBRATE; - move16(); - } - if ( sub(bq2_fx[i], MINIMUM_ENERGY_LOWBRATE) < 0 ) - { - bq2_fx[i] = MINIMUM_ENERGY_LOWBRATE; - move16(); - } - } - - /* Get number of bits by Huffman0 coding */ - ebits = large_symbol_enc_fx( st_fx, bq2_fx, bands_fx, &hLCmode0, 0 ); - - IF(is_transient_fx) - { - /* Get number of bits by Huffman coding */ - hbits = small_symbol_enc_tran_fx(st_fx, bq2_temp_fx, bands_fx, &hLCmode1, 0 ,is_transient_fx); - } - ELSE - { - /* Get number of bits by Huffman coding */ - hbits = small_symbol_enc_fx( st_fx, bq2_fx, bands_fx, &hLCmode1, 0, is_transient_fx ); - } - - /* comparing used bits */ - test(); - IF ( sub(ebits, hbits) < 0 || sub(hbits, -1) == 0 ) - { - deng_cmode = 0; - move16(); - push_indice_fx ( st_fx, IND_HQ2_DENG_MODE, deng_cmode, BITS_DE_CMODE ); - large_symbol_enc_fx( st_fx, bq2_fx, bands_fx, &hLCmode0, 1 ); - deng_bits = add(ebits, BITS_DE_CMODE); - } - ELSE - { - /* setting energy difference coding mode and storing it */ - deng_cmode = 1; - move16(); - push_indice_fx( st_fx, IND_HQ2_DENG_MODE, deng_cmode, BITS_DE_CMODE ); - - deng_bits = add(hbits, BITS_DE_CMODE); - - /* packing indice */ - IF(is_transient_fx) - { - Copy(bq2_temp_fx, bq2_fx, bands_fx); - small_symbol_enc_tran_fx(st_fx, bq2_fx, bands_fx, &hLCmode1, 1 ,is_transient_fx); - } - ELSE - { - small_symbol_enc_fx( st_fx, bq2_fx, bands_fx, &hLCmode1, 1, is_transient_fx ); - } - } - - /* Reconstruct quantized spectrum */ - bq1_fx[0] = add(bq2_fx[0], bq0_fx); - move16(); - FOR (k = 1; k < bands_fx; k++) - { - bq1_fx[k] = add(bq2_fx[k], bq1_fx[k - 1]); - move16(); - } - - FOR (k = 0; k < bands_fx; k++) - { - L_band_energy[k] = Mpy_32_16_1(L_qint, bq1_fx[k]); /* 29+0-15 -> Qbe(Q14) */ - } - - IF (is_transient_fx) - { - reverse_transient_frame_energies_fx( L_band_energy, bands_fx ); - } - - return( deng_bits ); -} - - -/*-------------------------------------------------------------------* - * p2a_threshold_quant() - * - * - *-------------------------------------------------------------------*/ - -static Word16 p2a_threshold_quant_fx( - Encoder_State_fx *st, /* i/o: : encoder state structure */ - const Word32 *L_t_audio, /* i : Q12 : input spectrum */ - const Word16 band_start[], /* i : Q0 : table of start freq for every subband */ - const Word16 band_end[], /* i : Q0 : table of end freq for every subband */ - const Word16 band_width[], /* i : Q0 : table of bandwidth for every subband */ - const Word16 bands, /* i : Q0 : number of subbands */ - const Word16 p2a_bands, /* i : Q0 : tonality indicator */ - const Word16 p2a_th_fx, /* i : Q11 : threshold tonal or not */ - Word16 *p2a_flags_fx /* i/o: Q0 : tonality flag */ -) -{ - Word16 i, j, k; - Word32 L_a, L_p, L_e; - Word16 Qa; - Word32 L_tmp; - Word16 temp_fx; - Word16 exp_norm; - Word16 exp_safe; - Word16 exp_normn, exp_normd; - - Word16 norm_a_fx,Qnorm_a; - Word16 pa_fx, Qpa; - - Word16 exp, frac; - - Word32 L_p2a; - Word16 p2a_fx; - - exp_safe=4; /* never happen overflow. */ - - set16_fx(p2a_flags_fx, 1, bands); - - j = 0; - move16(); - FOR (k = sub(bands, p2a_bands); k < bands; k++) - { - L_a = L_deposit_l(0); - L_p = L_deposit_l(0); - - L_tmp = L_deposit_l(0); - FOR (i = band_start[k]; i <= band_end[k]; i++) - { - L_tmp = L_or(L_tmp, L_abs(L_t_audio[i])); - } - exp_norm = norm_l(L_tmp); - exp_norm = sub(exp_norm, exp_safe); - - FOR (i = band_start[k]; i <= band_end[k]; i++) - { - temp_fx = round_fx(L_shl(L_t_audio[i], exp_norm)); /* Q12+exp_norm-16 -> exp_norm-4 */ - L_e = L_mult(temp_fx, temp_fx); - - if ( L_sub(L_e, L_p) > 0 ) - { - L_p = L_add(L_e, 0); - } - L_a = L_add(L_a, L_e); - } - Qa = sub(shl(exp_norm, 1), 7); /* (exp_norm-4)*2+1 */ - - IF ( L_a > 0x0L ) - { - /* a /= band_width[k]; */ - exp_normn = norm_l(L_a); - exp_normn = sub(exp_normn, 1); - exp_normd = norm_s(band_width[k]); - norm_a_fx = div_l(L_shl(L_a, exp_normn), shl(band_width[k], exp_normd)); - Qnorm_a = sub(sub(add(Qa, exp_normn), exp_normd), 1); /* (Qa+exp_normn)-exp_normd-1); */ - - /*p2a = 10.0f * (float) log10 (p / a); */ - p2a_fx = 0; - move16(); - IF ( norm_a_fx > 0 ) - { - exp_normn = norm_l(L_p); - exp_normn = sub(exp_normn, 1); - exp_normd = norm_s(norm_a_fx); - pa_fx = div_l(L_shl(L_p, exp_normn), shl(norm_a_fx, exp_normd)); - Qpa = sub(sub(add(Qa, exp_normn), add(Qnorm_a, exp_normd)), 1); - - L_tmp = L_deposit_h(pa_fx); - Qpa = add(Qpa, 16); - exp = norm_l(L_tmp); - frac = Log2_norm_lc(L_shl(L_tmp, exp)); - exp = sub(30, exp); - exp = sub(exp, Qpa); - L_tmp = L_Comp(exp, frac); - - /* 10/( log(10)/log(2) ) = 3.01029995663981195211 24660(Q13) */ - L_p2a = Mpy_32_16_1(L_tmp, 24660); /* 16+13-15 -> Q14 */ - - p2a_fx = round_fx(L_shl(L_p2a, 13)); /* 27 -16 -> 11 */ - } - - if ( sub(p2a_fx, p2a_th_fx) <= 0 ) - { - p2a_flags_fx[k] = 0; - move16(); - } - } - ELSE - { - p2a_flags_fx[k] = 0; - move16(); - } - - push_indice_fx( st, IND_HQ2_P2A_FLAGS, p2a_flags_fx[k], 1 ); - j = add(j, 1); - } - - return( j ); -} - -/*-------------------------------------------------------------------* - * mdct_spectrum_fine_gain_enc() - * - * - *-------------------------------------------------------------------*/ - -static void mdct_spectrum_fine_gain_enc_fx( - Encoder_State_fx *st_fx, /* i/o: encoder state structure */ - const Word32 L_ybuf[], /* i : Q12 : input spectrum */ - Word32 L_y2[], /* i/o: Q12 : decoded spectrum */ - const Word16 band_start[], /* i : Q0 : table of start freq for every subband */ - const Word16 band_end[], /* i : Q0 : table of end freq for every subband */ - const Word16 k_sort[], /* i : Q0 : sort table by band_energy */ - const Word16 bands, /* i : Q0 : nubmber of subbands */ - const Word32 L_qint, /* i : Q29 : */ - const Word16 Ngq, /* i : Q0 : */ - const Word16 gqlevs, /* i : Q0 : quantized level */ - const Word16 gqbits /* i : Q0 : quantized bits */ -) -{ - Word16 i, k; - - Word16 delta_fx, Qdelta; - Word32 L_delta; - Word32 L_q; - - Word16 gain_table_fx[MAX_GQLEVS]; - Word16 Qgt; - Word16 gamma_fx; - Word16 Qgamma; - - Word16 exp_safe; - Word16 exp_normn, exp_normd; - Word16 exp_norm; - - Word32 L_temp; - Word16 temp_lo_fx, temp_hi_fx, temp_fx, temp2_fx; - - Word32 L_Eyy, L_Exy; - /*Word16 QE; */ - - Word16 d_fx; - Word16 dmin_fx; - Word16 imin_fx; - - /* Fine gain quantization on only the most significant energy bands */ - - /*delta = qint / gqlevs; */ - exp_normn = norm_l(L_qint); - exp_normn = sub(exp_normn, 1); - exp_normd = norm_s(gqlevs); - delta_fx = div_l(L_shl(L_qint, exp_normn), shl(gqlevs, exp_normd)); - Qdelta = add(sub(exp_normn, exp_normd), 28); /* 29+exp_normn-(exp_normd)-1; */ - L_delta = L_shl(L_deposit_h(delta_fx), sub(13, Qdelta)); - /*q = (-qint + delta) / 2.0f; */ - L_q = L_shr(L_sub(L_delta, L_qint), 1); - - FOR (i = 0; i < gqlevs; i++) - { - /*gain_table[i] = (float) pow (2.0f, q * 0.5f); */ - L_temp = L_shr(L_shr(L_q, 1), sub(29, 16)); - temp_lo_fx = L_Extract_lc(L_temp, &temp_hi_fx); - Qgt = sub(14, temp_hi_fx); - gain_table_fx[i] = extract_l(Pow2(14, temp_lo_fx)); /* Qgt */ - - /*q += delta; */ - L_q = L_add(L_q, L_delta); - gain_table_fx[i] = shl(gain_table_fx[i], sub(14, Qgt)); /* Qgt -> Q14 */ - } - - FOR (k = sub(bands, Ngq); k < bands; k++) - { - /*Eyy = 0.0f; */ - /*Exy = 0.0f; */ - /*for (i = band_start[k_sort[k]]; i <= band_end[k_sort[k]]; i++) */ - /*{ */ - /* Eyy += y2[i] * y2[i]; */ - /* Exy += ybuf[i] * y2[i]; */ - /*} */ - exp_safe = 4; - move16(); /* 4 is too large. but never happen overflow */ - L_temp = L_deposit_l(0); - FOR (i = band_start[k_sort[k]]; i <= band_end[k_sort[k]]; i++) - { - L_temp = L_or(L_temp, L_abs(L_y2[i])); - L_temp = L_or(L_temp, L_abs(L_ybuf[i])); - } - exp_norm = norm_l(L_temp); - exp_norm = sub(exp_norm, exp_safe); /* safe_shift */ - - L_Eyy = L_deposit_l(0); - L_Exy = L_deposit_l(0); - /*QE = add(shl(add(Qs-16, exp_norm), 1), 1); //(Qs+exp_norm-16)*2+1; */ - FOR (i = band_start[k_sort[k]]; i <= band_end[k_sort[k]]; i++) - { - /*Eyy += y2[i] * y2[i]; */ - temp_fx = round_fx(L_shl(L_y2[i], exp_norm)); - L_Eyy = L_mac(L_Eyy, temp_fx, temp_fx); - - /*Exy += ybuf[i] * y2[i]; */ - temp2_fx = round_fx(L_shl(L_ybuf[i], exp_norm)); - L_Exy = L_mac(L_Exy, temp2_fx, temp_fx); - } - - test(); - IF ( L_Eyy > 0x0L && L_Exy > 0x0L ) - { - /*gamma = Exy / Eyy; */ - exp_normn = norm_l(L_Exy); - exp_normn = sub(exp_normn, 1); - exp_normd = norm_l(L_Eyy); - gamma_fx = div_l(L_shl(L_Exy, exp_normn), round_fx(L_shl(L_Eyy, exp_normd))); - Qgamma = add(sub(exp_normn, exp_normd), 15); /* exp_normn - (exp_normd-16) - 1; */ - gamma_fx = shl(gamma_fx, sub(14, Qgamma)); /* Qgamma -> Q14 */ - - dmin_fx = 32767; - move16(); - imin_fx = -1; - move16(); - FOR (i = 0; i < gqlevs; i++) - { - d_fx = abs_s (sub(gamma_fx, gain_table_fx[i])); - IF ( sub(d_fx, dmin_fx) < 0 ) - { - dmin_fx = d_fx; - move16(); - imin_fx = i; - move16(); - } - } - - gamma_fx = gain_table_fx[imin_fx]; - move16(); /* Q14 */ - - FOR (i = band_start[k_sort[k]]; i <= band_end[k_sort[k]]; i++) - { - /*y2[i] *= gamma; */ - /* This IF statement for keeping same mantissa evenif y2 is plus or minus */ - IF ( L_y2[i] >= 0x0 ) - { - L_y2[i] = L_shl(Mpy_32_16_1(L_y2[i], gamma_fx), 1); - } - ELSE - { - L_y2[i] = L_negate(L_shl(Mpy_32_16_1(L_abs(L_y2[i]), gamma_fx), 1)); - } - } - } - ELSE - { - imin_fx = 0; - move16(); - } - - push_indice_fx( st_fx, IND_HQ2_SUBBAND_GAIN, imin_fx, gqbits ); - } - - return; -} diff --git a/src/libs/libevs/lib_enc/hvq_enc.cpp b/src/libs/libevs/lib_enc/hvq_enc.cpp new file mode 100644 index 00000000..290ada16 --- /dev/null +++ b/src/libs/libevs/lib_enc/hvq_enc.cpp @@ -0,0 +1,117 @@ +/*==================================================================================== + EVS Codec 3GPP TS26.443 Nov 13, 2018. Version 12.11.0 / 13.7.0 / 14.3.0 / 15.1.0 + ====================================================================================*/ + +#include +#include "options.h" +#include "cnst.h" +#include "prot.h" +#include "rom_enc.h" +#include "rom_com.h" + +/*--------------------------------------------------------------------------* + * hvq_enc() + * + * Harmonic VQ encoder + *--------------------------------------------------------------------------*/ + +short hvq_enc( /* o : Consumed bits */ + Encoder_State *st, /* i/o: encoder state structure */ + const long brate, /* i : Total bit rate */ + const short hvq_bits, /* i : HVQ bit budget */ + const short Npeaks, /* i : Number of peaks */ + const short *ynrm, /* i : Envelope coefficients */ + short *R, /* i/o: Bit allocation/updated bit allocation */ + short *peaks, /* i : Peak pos. / Encoded peak pos. */ + float *nf_gains, /* i/o: Noise fill gains / Quant. nf gains */ + float *noise_level, /* o : Quantized noise level */ + const float *pe_gains, /* i : Peak gains */ + const float *coefs, /* i : spectrum coefficients */ + float *coefs_out /* o : encoded spectrum coefficients */ +) +{ + short bin_th,q,j,i; + short nf_cnt; + short q_noise_level_idx[HVQ_BWE_NOISE_BANDS]; + float q_noise_level[HVQ_BWE_NOISE_BANDS]; + float d, nf, nf_mean, pe, pe_mean, nfpe; + short bits_used; + float lb_nfpe; + + bits_used = 0; + + bin_th = HVQ_THRES_BIN_32k; + if( brate == HQ_24k40 ) + { + bin_th = HVQ_THRES_BIN_24k; + } + + nf = 800; + pe = 800; + q = bin_th; + + /* Find HB noise level */ + for( i = 0; i < HVQ_BWE_NOISE_BANDS; i++ ) + { + nf_cnt = 0; + nf_mean = EPSILON; + pe_mean = EPSILON; + for( j = 0; j < (L_FRAME32k-bin_th)/HVQ_BWE_NOISE_BANDS; j++, q++ ) + { + d = (float)fabs(coefs[q]); + + if( d > pe ) + { + pe = HVQ_BWE_WEIGHT2 * pe + (1 - HVQ_BWE_WEIGHT2) * d; + } + else + { + pe = HVQ_BWE_WEIGHT1 * pe + (1 - HVQ_BWE_WEIGHT1) * d; + if( d > nf ) + { + nf = HVQ_BWE_WEIGHT1 * nf + (1 - HVQ_BWE_WEIGHT1) * d; + } + else + { + nf = HVQ_BWE_WEIGHT2 * nf + (1 - HVQ_BWE_WEIGHT2) * d; + } + nf_mean += nf; + nf_cnt++; + } + + pe_mean += pe; + } + + if( nf_cnt > 0 ) + { + nf_mean /= nf_cnt; + } + pe_mean /= (L_FRAME32k-bin_th)/HVQ_BWE_NOISE_BANDS; + + nfpe = HVQ_NFPE_FACTOR*nf_mean/pe_mean; + noise_level[i] = nfpe * nfpe * nfpe; + + q_noise_level_idx[i] = usquant( noise_level[i], &q_noise_level[i], 0.0f, 0.1f, 4 ); + push_indice( st, IND_HVQ_BWE_NL, q_noise_level_idx[i], 2 ); + bits_used += 2; + + noise_level[i] = q_noise_level[i]; + } + + for( i = 0; i < HVQ_NF_GROUPS; i ++ ) + { + lb_nfpe = HVQ_LB_NFPE_FACTOR*nf_gains[i]/pe_gains[i]; + lb_nfpe = lb_nfpe * lb_nfpe * lb_nfpe; + + if( lb_nfpe > 0.5f ) + { + lb_nfpe = 0.5f; + } + nf_gains[i] *= 2*lb_nfpe; + } + + bits_used += peak_vq_enc( st, coefs, coefs_out, (short)brate, hvq_bits - bits_used, + Npeaks, ynrm, R, peaks, &nf_gains[0] ); + + return bits_used; +} diff --git a/src/libs/libevs/lib_enc/hvq_enc_fx.cpp b/src/libs/libevs/lib_enc/hvq_enc_fx.cpp deleted file mode 100755 index 37e08064..00000000 --- a/src/libs/libevs/lib_enc/hvq_enc_fx.cpp +++ /dev/null @@ -1,232 +0,0 @@ -/*==================================================================================== - EVS Codec 3GPP TS26.442 Apr 03, 2018. Version 12.11.0 / 13.6.0 / 14.2.0 - ====================================================================================*/ - -#include "options.h" /* Compilation switches */ -#include "prot_fx.h" -#include "cnst_fx.h" -#include "stl.h" - -#define HVQ_ENC_NOISE_DELTA ((Word16)3277) /* 0.1 in Q15 */ - -static Word16 quant_lc(const Word16, Word16 *); - - -/*--------------------------------------------------------------------------* - * hvq_enc_fx() - * - * Harmonic VQ encoder - *--------------------------------------------------------------------------*/ - -Word16 hvq_enc_fx( /*o : Consumed bits */ - Encoder_State_fx *st_fx, /*i/o: encoder state structure */ - const Word32 brate, /*i : Total bit rate */ - const Word16 hvq_bits, /*i : HVQ bit budget */ - const Word16 Npeaks, /*i : Number of peaks */ - const Word16 *ynrm, /* i : Envelope coefficients */ - Word16 *R, /* i/o: Bit allocation/updated bit allocation */ - Word16 *peaks, /* i : Peak pos. / Encoded peak pos. */ - Word32 *nf_gains, /* i/o: Noise fill gains / Quant. nf gains */ - Word16 *noise_level, /* o : Quantized noise level */ - const Word32 *pe_gains, /* i : Peak gains */ - const Word32 *coefs, /* i : spectrum coefficients in Q12 */ - Word32 *coefs_out /* o : encoded spectrum coefficients in Q12 */ -) -{ - const Word32 *pCoefs; - Word16 bin_th,j,i,n; - Word16 nf_cnt; - Word16 q_noise_level_idx[HVQ_BWE_NOISE_BANDS]; - Word16 q_noise_level[HVQ_BWE_NOISE_BANDS]; - Word32 d, nf_mean; - Word32 nf, pe, pe_mean; - Word16 bits_used, nBits; - Word16 lb_nfpe; - UWord16 dontCare; - Word32 acc, numerator, denominator; - Word16 expPeMean, expNfMean, expNfpe, expNfpe3, expo, expo3; - Word16 manPeMean, manNfMean, manNfpe, man; - Word16 tmp16, adjust; - - bits_used = 0; - move16(); - - IF ( brate == HQ_24k40 ) - { - bin_th = HVQ_THRES_BIN_24k; - move16(); - n = (L_FRAME32k - HVQ_THRES_BIN_24k)/HVQ_BWE_NOISE_BANDS; - move16(); - } - ELSE - { - bin_th = HVQ_THRES_BIN_32k; - move16(); - n = (L_FRAME32k - HVQ_THRES_BIN_32k)/HVQ_BWE_NOISE_BANDS; - move16(); - } - - nf = 800*4096L; /* Q12 */ move32(); - pe = 800*4096L; /* Q12 */ move32(); - pCoefs = &coefs[bin_th]; - - /* Find HB noise level */ - FOR( i = 0; i < HVQ_BWE_NOISE_BANDS; i++ ) - { - nf_cnt = 0; - move16(); - nf_mean = L_deposit_l(0); - pe_mean = L_deposit_l(0); - FOR( j = 0; j < n; j++) - { - d = L_abs(*pCoefs++); /* Q12 */ - - IF( L_sub(d, pe) > 0L ) - { - /* W*pe + (1 - W)*d = (pe - d)*W + d */ - acc = L_sub(pe, d); - Mpy_32_16_ss(acc, HVQ_BWE_WEIGHT2_FX, &acc, &dontCare); - pe = L_add(acc, d); /* in Q12 and always positive */ - } - ELSE - { - /* W*pe + (1 - W)*d = (pe - d)*W + d */ - acc = L_sub(pe, d); - Mpy_32_16_ss(acc, HVQ_BWE_WEIGHT1_FX, &acc, &dontCare); - pe = L_add(acc, d); /* in Q12 and always positive */ - - IF( L_sub(d, nf) > 0L ) - { - acc = L_sub(nf, d); - Mpy_32_16_ss(acc, HVQ_BWE_WEIGHT1_FX, &acc, &dontCare); - nf = L_add(acc, d); /* in Q12 and always positive */ - } - ELSE - { - acc = L_sub(nf, d); - Mpy_32_16_ss(acc, HVQ_BWE_WEIGHT2_FX, &acc, &dontCare); - nf = L_add(acc, d); /* in Q12 always positive */ - } - nf_mean = L_add(nf_mean, nf); /* in Q12 and always positive */ - nf_cnt = add(nf_cnt, 1); /* Q0 */ - } - - pe_mean = L_add(pe_mean, pe); /* in Q12 and always positive */ - } - - IF (pe_mean > 0) - { - expPeMean = norm_l(pe_mean); /* exponent */ - manPeMean = extract_h(L_shl(pe_mean, expPeMean)); /* mantissa */ - expNfMean = norm_l(nf_mean); /* exponent */ - manNfMean = extract_h(L_shl(nf_mean, expNfMean)); /* mantissa */ - - numerator = L_mult0(manNfMean, n); - IF ( nf_cnt > 0 ) - { - denominator = L_mult0(manPeMean, nf_cnt); /* in Q15 */ - } - ELSE - { - denominator = L_mult0(manPeMean, 1); /* in Q15 */ - } - manNfpe = ratio(numerator, denominator, &expo); /* manNfpe in Q14 */ - expNfpe = add(sub(expNfMean, expPeMean), expo); - - tmp16 = mult_r(manNfpe, manNfpe); /* in Q(14+14+1-16) = Q13 */ - tmp16 = mult_r(tmp16, manNfpe); /* in Q(13+14+1-16) = Q12 */ - acc = L_mult(tmp16, HVQ_NFPE_FACTOR_CUBE_FX); /* in Q(12+6+1) = Q19 */ - expNfpe3 = extract_l(L_mult0(expNfpe, 3)); /* Cube operation */ - /* Number of bits required to adjust to Q15 */ - adjust = add(19 - (15 + 16), expNfpe3); /* +16 is due to the following extract_h(). */ - noise_level[i] = extract_h(L_shr(acc, adjust)); /* noise_level[] in Q15 */ - - q_noise_level_idx[i] = quant_lc( noise_level[i], &q_noise_level[i] ); - } - ELSE - { - q_noise_level_idx[i] = 0; - move16(); - q_noise_level[i] = 0; - move16(); - } - push_indice_fx(st_fx, IND_HVQ_BWE_NL, q_noise_level_idx[i], 2 ); - bits_used = add(bits_used, 2); - - noise_level[i] = q_noise_level[i]; /* in Q15 */ - } - - FOR( i = 0; i < HVQ_NF_GROUPS; i ++ ) - { - IF (pe_gains[i] != 0) - { - /* Neither pe_gains[] nor nf_gains[] is zero. */ - man = ratio(nf_gains[i], pe_gains[i], &expo); /* man in Q14 */ - tmp16 = mult_r(man, man); /* in Q(14+14+1-16) = Q13 */ - tmp16 = mult_r(tmp16, man); /* in Q(13+14+1-16) = Q12 */ - acc = L_mult(tmp16, HVQ_LB_NFPE_FACTOR_CUBE_FX); /* in Q(12+9+1) = Q22 */ - expo3 = extract_l(L_mult0(expo, 3)); /* Cube operation. */ - /* Number of bits required to adjust to Q15 */ - adjust = add(22 - (15 + 16), expo3); /* +16 is due to the following extract_h(). */ - lb_nfpe = extract_h(L_shr(acc, adjust)); /* noise_level[] in Q15 */ - - IF( lb_nfpe > 16384 ) /* in Q15 */ - { - lb_nfpe = 16384; - move16(); - } - Mpy_32_16_ss(nf_gains[i], shl(lb_nfpe, 1), &nf_gains[i], &dontCare); /* nf_gains[] in Q12 */ - } - ELSE - { - nf_gains[i] = 0; - move16(); - } - } - nBits = peak_vq_enc_fx( st_fx, coefs, coefs_out, brate, sub(hvq_bits, bits_used), - Npeaks, ynrm, R, peaks, &nf_gains[0] ); - bits_used = add(bits_used, nBits); - return bits_used; -} - -/*----------------------------------------------------------------------------- - * quant() - * - * Quantize the noise to one of the levels in {0, 0.1, 0.2, 0.3} - *----------------------------------------------------------------------------*/ -static Word16 quant_lc(const Word16 x, Word16 *qx) -{ - Word16 indx; - - IF (sub(x, HVQ_ENC_NOISE_DELTA/2) < 0) - { - indx = 0; - move16(); - *qx = 0; - move16(); - } - ELSE IF (sub(x, 3*HVQ_ENC_NOISE_DELTA/2) < 0) - { - indx = 1; - move16(); - *qx = HVQ_ENC_NOISE_DELTA; - move16(); - } - ELSE IF (sub(x, 5*HVQ_ENC_NOISE_DELTA/2) < 0) - { - indx = 2; - move16(); - *qx = 2*HVQ_ENC_NOISE_DELTA; - move16(); - } - ELSE - { - indx = 3; - move16(); - *qx = 3*HVQ_ENC_NOISE_DELTA; - move16(); - } - - return indx; -} - diff --git a/src/libs/libevs/lib_enc/igf_enc.cpp b/src/libs/libevs/lib_enc/igf_enc.cpp old mode 100755 new mode 100644 index f7d85e8e..f8414083 --- a/src/libs/libevs/lib_enc/igf_enc.cpp +++ b/src/libs/libevs/lib_enc/igf_enc.cpp @@ -1,52 +1,43 @@ /*==================================================================================== - EVS Codec 3GPP TS26.442 Apr 03, 2018. Version 12.11.0 / 13.6.0 / 14.2.0 + EVS Codec 3GPP TS26.443 Nov 13, 2018. Version 12.11.0 / 13.7.0 / 14.3.0 / 15.1.0 ====================================================================================*/ #include #include +#include +#include +#include #include #include "options.h" -#include "stl.h" -#include "prot_fx.h" -#include "cnst_fx.h" -#include "stat_enc_fx.h" -#include "basop_util.h" +#include "prot.h" +#include "cnst.h" +#include "stat_enc.h" /**********************************************************************/ /* write single bit to stream **************************************************************************/ -static void IGF_write_bit(Encoder_State_fx *st, /**< in: | encoder state structure */ - Word16 *bitCount, /**< in/out: | bit counter */ - Word16 bit /**< in: | value of bit */ +static void IGF_write_bit(Encoder_State *st, /**< in: | encoder state structure */ + int *bitCount, /**< in/out: | bit counter */ + int bit /**< in/out: | bit counter */ ) { IGFCommonFuncsWriteSerialBit(st, bitCount, bit); + return; } /**********************************************************************/ /* write bits to stream **************************************************************************/ -static void IGF_write_bits(Encoder_State_fx *st, /**< in: | encoder state structure */ - Word16 *bitCount, /**< in/out: | bit counter */ - Word16 value, /**< in: | value to be written */ - Word16 bits /**< in: Q0 | number of bits */ +static void IGF_write_bits(Encoder_State *st, /**< in: | encoder state structure */ + int *bitCount, /**< in/out: | bit counter */ + int value, /**< in/out: | bit counter */ + int bits /**< in: | number of bits */ ) { - Word16 tmp; - - WHILE (bits) + while (bits--) { - bits = sub(bits, 1); - tmp = s_and(value, shl(1, bits)); - IF (tmp == 0) - { - IGF_write_bit(st, bitCount, 0); - } - ELSE - { - IGF_write_bit(st, bitCount, 1); - } + IGF_write_bit(st, bitCount, ((value & (1 << bits)) == 0) ? 0 : 1); } return; @@ -57,229 +48,73 @@ static void IGF_write_bits(Encoder_State_fx *st, envelope estimation **************************************************************************/ static void IGF_CalculateEnvelope(const IGF_ENC_INSTANCE_HANDLE hInstance, /**< in: | instance handle of IGF Encoder */ - Word32 *pMDCTSpectrum, /**< in: Q31 | MDCT spectrum */ - Word16 MDCTSpectrum_e, /**< in: | exponent of MDCT spectrum */ - Word32 *pPowerSpectrum, /**< in: Q31 | MDCT^2 + MDST^2 spectrum, or estimate */ - Word16 PowerSpectrum_e, /**< in: | exponent of MDCT^2 + MDST^2 spectrum, or estimate */ - const Word16 igfGridIdx /**< in: Q0 | IGF grid index */ - + float *pMDCTSpectrum, /**< in: | MDCT spectrum */ + float *pPowerSpectrum, /**< in: | MDCT^2 + MDST^2 spectrum, or estimate */ + const int igfGridIdx /**< in: | IGF grid index */ ) { IGF_ENC_PRIVATE_DATA_HANDLE hPrivateData; H_IGF_GRID hGrid; - Word16 *swb_offset; - Word16 sfb; /* this is the actual scalefactor band */ - Word16 width; /* this is width in subbands of the actual scalefactor band */ - Word16 tile_idx; - Word16 strt_cpy; - Word16 gain; /* the gain which has to be applied to the source tile to get the destination energy */ - Word16 gain_exp; - Word16 tb; - Word16 zeroNrg; /* Q0 | flag indicating if the signal contains almost no energy */ - Word32 sfbEnergyR[IGF_MAX_SFB]; - Word16 sfbEnergyR_exp[IGF_MAX_SFB]; - Word32 sfbEnergyC[IGF_MAX_SFB]; /* the energy of the destination region of the tile */ - Word16 sfbEnergyC_exp[IGF_MAX_SFB]; - Word32 sfbEnergyTileR[IGF_MAX_SFB]; - Word16 sfbEnergyTileR_exp[IGF_MAX_SFB]; - Word32 sfbEnergyTileC[IGF_MAX_SFB]; /* the energy of the destination region of the tile */ - Word16 sfbEnergyTileC_exp[IGF_MAX_SFB]; - Word32 LFMDCTSpectrum[N_MAX]; - Word16 LFMDCTSpectrum_exp; - Word32 LFPowerSpectrum[N_MAX]; - Word16 tmp; - Word16 tmp_exp; - Word32 L_tmp; - Word16 shift; + int *swb_offset; + int sfb; /* this is the actual scalefactor band */ + int width; /* this is width in subbands of the actual scalefactor band */ + int tile_idx; + int strt_cpy; + float gain; /* the gain which has to be applied to the source tile to get the destination energy */ + int sb; + float sfbEnergyR; + float sfbEnergyC; /* the energy of the destination region of the tile */ + float sfbEnergyTileR; + float sfbEnergyTileC; /* the energy of the destination region of the tile */ + + mvr2r(pMDCTSpectrum + IGF_START_MN, hInstance->spec_be_igf, hInstance->infoStopLine-IGF_START_MN); + hPrivateData = &hInstance->igfData; + hGrid = &hPrivateData->igfInfo.grid[(int)igfGridIdx]; + swb_offset = hGrid->swb_offset; - /* initialize variables */ - Copy32(pMDCTSpectrum + IGF_START_MN, hInstance->spec_be_igf, hInstance->infoStopLine-IGF_START_MN); - hPrivateData = &hInstance->igfData; - hGrid = &hPrivateData->igfInfo.grid[igfGridIdx]; - swb_offset = hGrid->swb_offset; - move16(); - hInstance->spec_be_igf_e = MDCTSpectrum_e; - move16(); - zeroNrg = 0; - move16(); - - - IF (pPowerSpectrum != NULL) + for (tile_idx = 0; tile_idx < hGrid->nTiles; tile_idx++) { - FOR (tile_idx = 0; tile_idx < hGrid->nTiles; tile_idx++) - { - strt_cpy = hGrid->sbWrap[tile_idx]; - move16(); - FOR (sfb = hGrid->sfbWrap[tile_idx]; sfb < hGrid->sfbWrap[tile_idx + 1]; sfb++) - { - FOR (tb = swb_offset[ sfb ]; tb < swb_offset[ sfb+1 ]; tb++) - { - LFMDCTSpectrum[tb] = pMDCTSpectrum[strt_cpy]; - move32(); - LFPowerSpectrum[tb] = pPowerSpectrum[strt_cpy]; - move32(); - strt_cpy = add(strt_cpy, 1); - } - } - } - IGFCommonFuncsCalcSfbEnergyPowerSpec(hGrid->startSfb, - hGrid->stopSfb, - hGrid->swb_offset, - pPowerSpectrum, - &PowerSpectrum_e, - sfbEnergyC, - sfbEnergyC_exp); - IGFCommonFuncsCalcSfbEnergyPowerSpec(hGrid->startSfb, - hGrid->stopSfb, - hGrid->swb_offset, - LFPowerSpectrum, - &PowerSpectrum_e, - sfbEnergyTileC, - sfbEnergyTileC_exp); - IGFCommonFuncsMDCTSquareSpec(hGrid->startLine, - hGrid->stopLine, - LFMDCTSpectrum, - MDCTSpectrum_e, - LFMDCTSpectrum, - &LFMDCTSpectrum_exp, - 0); - IGFCommonFuncsCalcSfbEnergyPowerSpec(hGrid->startSfb, - hGrid->stopSfb, - hGrid->swb_offset, - LFMDCTSpectrum, - &LFMDCTSpectrum_exp, - sfbEnergyTileR, - sfbEnergyTileR_exp); - } - ELSE - { - IGFCommonFuncsMDCTSquareSpec(hGrid->startLine, - hGrid->stopLine, - pMDCTSpectrum, - MDCTSpectrum_e, - LFMDCTSpectrum, - &LFMDCTSpectrum_exp, - 0); - IGFCommonFuncsCalcSfbEnergyPowerSpec(hGrid->startSfb, - hGrid->stopSfb, - hGrid->swb_offset, - LFMDCTSpectrum, - &LFMDCTSpectrum_exp, - sfbEnergyR, - sfbEnergyR_exp); - } + strt_cpy = hGrid->sbWrap[tile_idx]; - FOR (tile_idx = 0; tile_idx < hGrid->nTiles; tile_idx++) - { - - FOR(sfb = hGrid->sfbWrap[tile_idx]; sfb < hGrid->sfbWrap[tile_idx + 1]; sfb++) + for (sfb = hGrid->sfbWrap[tile_idx]; sfb < hGrid->sfbWrap[tile_idx + 1]; sfb++) { - width = sub(swb_offset[sfb + 1], swb_offset[sfb]); - L_tmp = 0; - move16(); - gain_exp = 0; - move16(); + width = swb_offset[sfb + 1] - swb_offset[sfb]; + sfbEnergyTileR = FLT_EPSILON; + sfbEnergyTileC = FLT_EPSILON; + sfbEnergyC = FLT_EPSILON; - IF (pPowerSpectrum) + if (pPowerSpectrum) { - IF (sfbEnergyTileR[sfb] == 0) + + for (sb = swb_offset[sfb]; sb < swb_offset[sfb + 1]; sb++) { - sfbEnergyTileR[sfb] = 0x00010000; - move32(); - sfbEnergyTileR_exp[sfb] = 0; - move16(); - zeroNrg = 1; - move16(); - } - IF (sfbEnergyTileC[sfb] == 0) - { - sfbEnergyTileC[sfb] = 0x00010000; - move32(); - sfbEnergyTileC_exp[sfb] = 0; - move16(); - zeroNrg = 1; - move16(); - } - IF (sfbEnergyC[sfb] == 0) - { - sfbEnergyC[sfb] = 0x00010000; - move32(); - sfbEnergyC_exp[sfb] = 0; - move16(); - zeroNrg = 1; - move16(); + sfbEnergyC += pPowerSpectrum[sb]; + sfbEnergyTileR += pMDCTSpectrum[strt_cpy] * pMDCTSpectrum[strt_cpy]; + sfbEnergyTileC += pPowerSpectrum[strt_cpy]; + + + strt_cpy++; } - BASOP_Util_Divide_MantExp(round_fx(sfbEnergyTileR[sfb]), - sfbEnergyTileR_exp[sfb], - width, - 15, - &gain, - &gain_exp); - BASOP_Util_Divide_MantExp(round_fx(sfbEnergyC[sfb]), - sfbEnergyC_exp[sfb], - round_fx(sfbEnergyTileC[sfb]), - sfbEnergyTileC_exp[sfb], - &tmp, - &tmp_exp); - L_tmp = L_mult(gain, tmp); - gain_exp = add(gain_exp, tmp_exp); - + sfbEnergyTileR /= width; + gain = (float)(sfbEnergyTileR * (sfbEnergyC / sfbEnergyTileC)); } - ELSE + else { - IF(sfbEnergyR[sfb] == 0) - { - sfbEnergyR[sfb] = 0x00010000; - move32(); - sfbEnergyR_exp[sfb] = 0; - move16(); - zeroNrg = 1; - move16(); - } - BASOP_Util_Divide_MantExp(round_fx(sfbEnergyR[sfb]), - sfbEnergyR_exp[sfb], - width, - 15, - &gain, - &gain_exp); - L_tmp = L_deposit_h(gain); - + sfbEnergyR = FLT_EPSILON + sum2_f(pMDCTSpectrum + swb_offset[ sfb ], width) / width; + gain = (float)(sfbEnergyR); } - /* gain = 0.5f + (float)((2.885390081777927f * log(gain) + 16.f)); */ - L_tmp = BASOP_Util_Log2(L_tmp); - L_tmp = L_add(L_tmp, L_deposit_h(shl(gain_exp, 15-6))); - shift = norm_l(L_tmp); - gain = round_fx(L_shl(L_tmp, shift)); - gain_exp = sub(7, shift); - gain_exp = BASOP_Util_Add_MantExp(gain, gain_exp, 32767/*16 Q11*/, 4, &gain); - gain_exp = BASOP_Util_Add_MantExp(gain, gain_exp, 0x4000, 0, &gain); - gain = shr(gain, s_min(sub(15, gain_exp), 15)); + gain = 0.5f + (float) ((2.885390081777927f * log(gain) + 16.f)); + gain = min(gain, 91.f); /* 13+15+63, see arithocde encode residual */ + gain = max(gain, 0.f); - if (gain > 91) - { - gain = s_min(gain, 91); /* 13+15+63, see arithocde encode residual */ - } - if (gain < 0) - { - gain = s_max(gain, 0); - } - - /* set gain to zero if the signal contains too less energy */ - if (zeroNrg != 0) - { - gain = 0; - move16(); - } - - hPrivateData->igfScfQuantized[sfb] = gain; - move16(); + hPrivateData->igfScfQuantized[sfb] = (int)(gain); } } @@ -289,317 +124,213 @@ static void IGF_CalculateEnvelope(const IGF_ENC_INSTANCE_HANDLE hInstanc /**********************************************************************/ /* writes IGF SCF values **************************************************************************/ -static void IGF_WriteEnvelope( /**< out: Q0 | number of bits writen */ - const IGF_ENC_INSTANCE_HANDLE hInstance, /**< in: | instance handle of IGF Encoder */ - Encoder_State_fx *st, /**< in: | encoder state */ - Word16 *pBitOffset, /**< in: | ptr to bitOffset counter */ - const Word16 igfGridIdx, /**< in: Q0 | igf grid index see declaration of IGF_GRID_IDX for details */ - const Word16 isIndepFlag, /**< in: Q0 | if 1 frame is independent, 0 = frame is coded with data from previous frame */ - Word16 *igfAllZero /**< in: Q0 | returns 1 if all IGF scfs are zero, else 0 */ +static int IGF_WriteEnvelope( /**< out: | number of bits writen */ + const IGF_ENC_INSTANCE_HANDLE hInstance, /**< in: | instance handle of IGF Encoder */ + Encoder_State *st, /**< in: | encoder state */ + int *pBitOffset, /**< in: | ptr to bitOffset counter */ + const int igfGridIdx, /**< in: | igf grid index see declaration of IGF_GRID_IDX for details */ + const int isIndepFlag, /**< in: | if 1 frame is independent, 0 = frame is coded with data from previous frame */ + int *igfAllZero /**< in: | returns 1 if all IGF scfs are zero, else 0 */ ) { IGF_ENC_PRIVATE_DATA_HANDLE hPrivateData; H_IGF_GRID hGrid; - Word16 sfb; + int totBitCount; + int startBitCount; + int sfb; + startBitCount = *pBitOffset; + totBitCount = 0; *igfAllZero = 1; - move16(); hPrivateData = &hInstance->igfData; hGrid = &hPrivateData->igfInfo.grid[igfGridIdx]; - FOR (sfb = hGrid->startSfb; sfb < hGrid->stopSfb; sfb++) + for (sfb = hGrid->startSfb; sfb < hGrid->stopSfb; sfb++) { - IF (hPrivateData->igfScfQuantized[sfb] != 0) + if (hPrivateData->igfScfQuantized[sfb]!=0) { *igfAllZero = 0; - move16(); - BREAK; + break; } } - IF (*igfAllZero != 0) + if (*igfAllZero) { IGF_write_bit(st, pBitOffset, 1); - IF (NULL == st) + if (NULL == st) { IGFSCFEncoderSaveContextState(&hPrivateData->hIGFSCFArithEnc); } IGFSCFEncoderReset(&hPrivateData->hIGFSCFArithEnc); - IF (NULL == st) + if (NULL == st) { IGFSCFEncoderRestoreContextState(&hPrivateData->hIGFSCFArithEnc); } } - ELSE + else { IGF_write_bit(st, pBitOffset, 0); - IF (NULL == st) + + if (NULL == st) { IGFSCFEncoderSaveContextState(&hPrivateData->hIGFSCFArithEnc); } - *pBitOffset = IGFSCFEncoderEncode(&hPrivateData->hIGFSCFArithEnc, - st, - *pBitOffset, - &hPrivateData->igfScfQuantized[hGrid->startSfb], - isIndepFlag, - (NULL != st)); - move16(); - - IF (NULL == st) + *pBitOffset = IGFSCFEncoderEncode( &hPrivateData->hIGFSCFArithEnc,st, *pBitOffset, &hPrivateData->igfScfQuantized[hGrid->startSfb], isIndepFlag, (NULL != st) ); + if (NULL == st) { IGFSCFEncoderRestoreContextState(&hPrivateData->hIGFSCFArithEnc); } } + totBitCount = *pBitOffset - startBitCount; + return totBitCount; } /**********************************************************************/ /* identifies significant spectral content **************************************************************************/ -static void IGF_ErodeSpectrum(Word16 *highPassEner_exp, /**< out: | exponent of highPassEner */ - const IGF_ENC_INSTANCE_HANDLE hInstance, /**< in: | instance handle of IGF Encoder */ - Word32 *pSpectrum, /**< in/out: | MDCT spectrum */ - Word32 *pPowerSpectrum, /**< in/out: | power spectrum */ - Word16 pPowerSpectrum_exp, /**< in: | exponent of power spectrum */ - const Word16 igfGridIdx /**< in: Q0 | IGF grid index */ - ) +static float IGF_ErodeSpectrum( /**< out: | highPassEnergy */ + const IGF_ENC_INSTANCE_HANDLE hInstance, /**< in: | instance handle of IGF Encoder */ + float *pSpectrum, /**< in/out: | MDCT spectrum */ + float *pPowerSpectrum, /**< in/out: | power spectrum */ + const int igfGridIdx /**< in: Q0 | IGF grid index */ +) { IGF_ENC_PRIVATE_DATA_HANDLE hPrivateData; H_IGF_GRID hGrid; - Word16 i; - Word16 igfBgn; - Word16 igfEnd; - Word32 highPassEner; /* Q31 */ - Word32 lastLine; - Word32 nextLine; - Word32 L_c; - Word32 highPassEner_Ovfl; - Word16 s; - Word16 tmploop; - Word16 *swb_offset; - Word16 sfb; - Word16 startSfb; - Word16 stopSfb; - Word16 line; - Word16 flag; - Word16 *igfScaleF; - Word16 tmp; - Word32 L_tmp; + int i; + int igfBgn; + int igfEnd; + float highPassEner; + float lastLine; + float nextLine; + float factor; + int *igfScaleF; + int startSfb; + int stopSfb; + int *swb_offset; + int tmp; + int sfb; + int line; + highPassEner = 0.f; + hPrivateData = &hInstance->igfData; + hGrid = &hPrivateData->igfInfo.grid[(int)igfGridIdx]; + igfBgn = hGrid->startLine; + igfEnd = hGrid->stopLine; + startSfb = hGrid->startSfb; + stopSfb = hGrid->stopSfb; + swb_offset = hGrid->swb_offset; + igfScaleF = hPrivateData->igfScfQuantized; - hPrivateData = &hInstance->igfData; - hGrid = &hPrivateData->igfInfo.grid[igfGridIdx]; - igfBgn = hGrid->startLine; - move16(); - igfEnd = hGrid->stopLine; - move16(); - swb_offset = hGrid->swb_offset; - move16(); - startSfb = hGrid->startSfb; - move16(); - stopSfb = hGrid->stopSfb; - move16(); - igfScaleF = hPrivateData->igfScfQuantized; - move16(); - *highPassEner_exp = 0; - move16(); - highPassEner = L_add(0, 0); - - IF (NULL == pPowerSpectrum) + if (NULL == pPowerSpectrum) { - FOR (i = igfBgn; i< hGrid->infoGranuleLen; i++) + for (i = igfBgn; i< hGrid->infoGranuleLen; i++) { - pSpectrum[i] = L_deposit_l(0); + pSpectrum[i] = 0.f; } - return; + return 0; } - IF (igfBgn > 0) + if (igfBgn > 0) { - L_c = L_add(0, 0); - FOR (i = 0; i < igfBgn; i++) + for (i = 0; i < igfBgn; i++) { - Carry = 0; - highPassEner = L_add_c(highPassEner, Mpy_32_16_1(pPowerSpectrum[i], shl(i,4)/*Q4*/)/*Q20, pPowerSpectrum_exp*/); - Overflow = 0; - L_c = L_macNs(L_c, 0, 0); + highPassEner += (float)i * pPowerSpectrum[i]; } - highPassEner = norm_llQ31(L_c, highPassEner, highPassEner_exp); /*Q20, highPassEner_exp*/ - *highPassEner_exp = add(*highPassEner_exp, pPowerSpectrum_exp); - test(); - test(); - if ( sub(hPrivateData->igfInfo.bitRateIndex, IGF_BITRATE_SWB_9600) != 0 && - sub(hPrivateData->igfInfo.bitRateIndex, IGF_BITRATE_RF_SWB_13200) != 0 && - sub(hPrivateData->igfInfo.bitRateIndex, IGF_BITRATE_SWB_13200 ) != 0 ) + if ( hPrivateData->igfInfo.bitRateIndex == IGF_BITRATE_SWB_9600 || + hPrivateData->igfInfo.bitRateIndex == IGF_BITRATE_RF_SWB_13200 || + hPrivateData->igfInfo.bitRateIndex == IGF_BITRATE_SWB_13200 ) { - igfBgn = shl(igfBgn, 1); + factor = 1.f; } - highPassEner = L_deposit_l(BASOP_Util_Divide3216_Scale(highPassEner/*Q20, highPassEner_exp*/, igfBgn /*Q0*/,&s)); /*Q15, highPassEner_exp+11-16+s*/ - *highPassEner_exp = add(add(*highPassEner_exp,s),12 - 16 + (31 - 15)); /*Q15->Q31,highPassEner_exp*/ - lastLine = pSpectrum[i - 1]; - move32(); - nextLine = L_add(0, 0); - - /* May overflow - just for threshold comparison */ - /* negate because the negated may be 1 larger in abs, */ - /* so whenever compared to the negation of a maximum possible pPowerspectrum, it is still larger */ - BASOP_SATURATE_WARNING_OFF - highPassEner_Ovfl = L_shl(L_negate(highPassEner), sub(*highPassEner_exp, pPowerSpectrum_exp)); - L_tmp = L_add(pPowerSpectrum[i - 1], highPassEner_Ovfl); - BASOP_SATURATE_WARNING_ON - - if (L_tmp >= 0) + else { - nextLine = L_add(pSpectrum[i], 0); + factor = 2.f; } - tmploop = sub(igfEnd,1); - FOR (/*i*/; i < tmploop; i++) - { - /* May overflow - just for threshold comparison */ - BASOP_SATURATE_WARNING_OFF - L_tmp = L_add(pPowerSpectrum[i], highPassEner_Ovfl); - BASOP_SATURATE_WARNING_ON + highPassEner /= igfBgn * factor; /* for 9.6kbs use 1.f */ + lastLine = pSpectrum[i-1]; + nextLine = (pPowerSpectrum[i-1] < highPassEner) ? 0.0f : pSpectrum[i]; - IF (L_tmp < 0) + for (/*i*/; i < igfEnd - 1; i++) + { + if (pPowerSpectrum[i] < highPassEner) { - lastLine = L_add(pSpectrum[i], 0); + lastLine = pSpectrum[i]; pSpectrum[i] = nextLine; - move32(); - nextLine = L_add(0, 0); + nextLine = 0.0f; } - ELSE + else { pSpectrum[i-1] = lastLine; - move32(); - lastLine = L_add(pSpectrum[i], 0); - nextLine = L_add(pSpectrum[i+1], 0); + lastLine = pSpectrum[i]; + nextLine = pSpectrum[i+1]; } } - /* May overflow - just for threshold comparison */ - BASOP_SATURATE_WARNING_OFF - L_tmp = L_add(pPowerSpectrum[i], highPassEner_Ovfl); - BASOP_SATURATE_WARNING_ON - IF (L_tmp < 0) + /* i == igfEnd - 1 */ + if (pPowerSpectrum[i] < highPassEner) { - pSpectrum[i] = L_deposit_l(0); + pSpectrum[i] = 0.f; } } /* delete spectrum above igfEnd: */ - FOR (i = igfEnd; i < hGrid->infoGranuleLen; i++) + for (i = igfEnd; i < hGrid->infoGranuleLen; i++) { - pSpectrum[i] = L_deposit_l(0); - pPowerSpectrum[i] = L_deposit_l(0); + pSpectrum[i] = 0.f; + pPowerSpectrum[i] = 0.f; } - FOR (sfb = startSfb; sfb < stopSfb; sfb++) + if (NULL != pPowerSpectrum) { - flag = 0; - move16(); - FOR (line = swb_offset[sfb]; line < swb_offset[sfb+1]; line++) + for (sfb = startSfb; sfb < stopSfb; sfb++) { - if (pSpectrum[line] != 0) + tmp = 0; + for (line = swb_offset[sfb]; line < swb_offset[sfb+1]; line++) { - flag = 1; - move16(); + if (pSpectrum[line] != 0.f) tmp++; } - } - tmp = igfScaleF[sfb]; - move16(); - if(flag) - { - tmp = sub(igfScaleF[sfb], 1); - } - if (igfScaleF[sfb]) - { - igfScaleF[sfb] = tmp; - move16(); + if(tmp && igfScaleF[sfb]) igfScaleF[sfb]--; } } + return highPassEner; } /**********************************************************************/ /* crest factor calculation **************************************************************************/ -static Word16 IGF_getCrest( /**< out: Q15| crest factor */ - Word16 *crest_exp, /**< out: | exponent of crest factor */ - const Word32 *powerSpectrum, /**< in: Q31 | power spectrum */ - const Word16 powerSpectrum_exp, /**< in: | exponent of power spectrum */ - const Word16 start, /**< in: Q0 | start subband index */ - const Word16 stop /**< in: Q0 | stop subband index */ +static float IGF_getCrest( /**< out: | crest factor */ + const float *powerSpectrum, /**< in: | power spectrum */ + const int start, /**< in: | start subband index */ + const int stop /**< in: | stop subband index */ ) { - Word16 i; - Word16 x; - Word16 s; - Word32 x_eff32; - Word16 x_max; - Word16 crest; - Word16 tmp; - Word32 tmp32; + int i; + int x; + int x_eff = 0; + int x_max = 0; + float crest = 1.f; - x_eff32 = L_add(0, 0); - x_max = 0; - move16(); - crest = 16384/*.5f Q15*/; - move16(); - *crest_exp = 1; - move16(); - - FOR (i = start; i < stop; i++) + for (i = start; i < stop; i++) { - /*x = max(0, (int)(log(powerSpectrum[i]) * INV_LOG_2));*/ + x = max(0, (int)(log(max(FLT_MIN, powerSpectrum[i])) * INV_LOG_2)); + x_eff += x * x; - /*see IGF_getSFM for more comment */ - x = sub(sub(powerSpectrum_exp, norm_l(powerSpectrum[i])), 1); /*Q0*/ - if (powerSpectrum[i] == 0) /*special case: energy is zero*/ + if (x > x_max) { - x = 0; - move16(); + x_max = x; } - x = s_max(0, x); - x_eff32 = L_mac0(x_eff32, x ,x); /*Q0*/ - x_max = s_max(x_max, x); /*Q0*/ } - /*x_eff /= (stop - start);*/ - x_eff32 = BASOP_Util_Divide3216_Scale(x_eff32, sub(stop,start), &s); /*Q-1, s*/ - s = add(s, 32); /*make x_eff Q31*/ + x_eff /= (stop - start); - /*trunkate to int*/ - x_eff32 = L_shr(x_eff32, sub(31, s)); - x_eff32 = L_shl(x_eff32, sub(31, s)); - - test(); - IF (x_eff32 > 0 && x_max > 0) + if (x_eff > 0 && x_max > 0) { - /*crest = max(1.f, (float)x_max/sqrt(x_eff));*/ - tmp32 = ISqrt32(x_eff32, &s); /*Q31, s*/ - tmp32 = Mpy_32_16_1(tmp32/*Q31, s*/, x_max/*Q0*/); /*Q16, s*/ - i = norm_l(tmp32); - tmp32 = L_shl(tmp32, i); /*Q31, s-i+15*/ - crest = extract_h(tmp32); - *crest_exp = add(sub(s, i), 15); - - /* limit crest factor to a lower bound of 1, may overflow */ - BASOP_SATURATE_WARNING_OFF - tmp = shl(-1, sub(15, *crest_exp)); /* build negative threshold */ - tmp = add(crest, tmp); - BASOP_SATURATE_WARNING_ON - if (tmp < 0) - { - crest = 1; - move16(); - } - if (tmp < 0) - { - *crest_exp = 15; - move16(); - } + crest = max(1.f, (float)x_max/sqrt(x_eff)); } return crest; @@ -608,221 +339,117 @@ static Word16 IGF_getCrest( /************************************************************************* calculates spectral flatness measurment **************************************************************************/ -static Word16 IGF_getSFM( /**< out: Q15| SFM value */ - Word16 *SFM_exp, /**< out: | exponent of SFM Factor */ - const Word32 *energy, /**< in: Q31| energies */ - const Word16 *energy_exp, /**< in: | exponent of energies */ - const Word16 start, /**< in: Q0 | start subband index */ - const Word16 stop /**< in: Q0 | stop subband index */ +static float IGF_getSFM( /**< out: | SFM value */ + const float *powerSpectrum, /**< in: | energies */ + const int start, /**< in: | start subband index */ + const int stop /**< in: | stop subband index */ ) { - Word16 n,i, s; - Word32 num; - Word32 denom; - Word16 denom_exp; - Word16 invDenom_exp, numf_exp; - Word16 numf; - Word32 SFM32; - Word32 L_c; - Word16 invDenom, SFM; + int n; + int i; + int num; + float denom; + float numf; + float tmp; + float sfm; - L_c = L_add(0, 0); - num = L_add(0, 0); - denom = L_shr(2147483 /*0,001 in Q31 - float is "1", here*/,s_min(*energy_exp, 31)); - denom = L_max(denom, 1); - *SFM_exp = 0; - move16(); - SFM = 32767/*1.0f Q15*/; - move16(); + num = 0.f; + denom = 1.f; + sfm = 1.f; - FOR (i = start; i < stop; i++) + for (i = start; i < stop; i++) { - /*ln(x * 2^-Qx * 2^xExp) = ln(x) - Qx + xExp*/ - - /* n = sub(sub(31,norm_l(tmp32)),1); */ /*<- ld */ - /* n = sub(n,31); */ /*<- -Qx */ - /* n = add(n,*energy_exp); */ /*<- +xExp */ - - n = sub(sub(*energy_exp, norm_l(energy[i])), 1); /*<-- short form*/ - - if (energy[i] == 0) /*special case: energy is zero*/ - { - n = 0; - move16(); - } - - n = s_max(0, n); - num = L_add(num, L_deposit_l(n)); /*Q0*/ - - Carry = 0; - denom = L_add_c(energy[i], denom); - Overflow = 0; - - L_c = L_macNs(L_c, 0, 0); + tmp = powerSpectrum[i]; + n = max(0, (int)(log(max(FLT_MIN, tmp)) * INV_LOG_2)); + num += n; + denom += tmp; } - denom = norm_llQ31(L_c, denom, &denom_exp); /*Q31*/ - denom_exp = add(denom_exp, *energy_exp); + numf = (float)num / (float)(stop - start); + denom /= (float)(stop - start); - /* calculate SFM only if signal is present */ - IF (denom != 0) + if (denom != 0) { - /*numf = (float)num / (float)(stop - start);*/ - numf = BASOP_Util_Divide3216_Scale(num, /*Q0*/ - sub(stop,start), /*Q0*/ - &s); /*Q-1 s*/ - numf_exp = add(s,16); /*-> numf Q15 numf_exp*/ - /*denom /= (float)(stop - start);*/ - /*return ((float)pow(2.0, numf + 0.5f) / denom);*/ - - /*SFM= ((float)pow(2.0, numf + 0.5f) * invDenom);*/ - invDenom = BASOP_Util_Divide3232_uu_1616_Scale(L_deposit_l(sub(stop, start)) /*Q0*/, - denom /*Q31, denom_exp*/, - &s); /*Q-16, s-denom_exp*/ - invDenom_exp = add(sub(s, denom_exp), 31); /*invDenom: Q15, invDenom_exp*/ - - /*add .5f to numf*/ - SFM32 = L_add(L_shl(L_deposit_l(numf), numf_exp) /*16Q15*/,16384l/*.5f Q15*/); /*16Q15*/ - s = norm_l(SFM32); - SFM32 = L_shl(SFM32, s); - s = sub(16, s); /*SFM32(numf) is Q31 now*/ - - /*do the pow2 and the mult*/ - SFM32 = BASOP_util_Pow2(SFM32, s, &s); - SFM32 = Mpy_32_16_1(SFM32, invDenom); - *SFM_exp = add(s, invDenom_exp); - - /*Transform to Q15*/ - s = norm_l(SFM32); - SFM = round_fx(L_shl(SFM32, s)); - *SFM_exp = sub(*SFM_exp, s); - - /**SFM_exp = s_min(*SFM_exp, 0);*/ - IF (*SFM_exp > 0) - { - *SFM_exp = 0; - move16(); - SFM = 32767/*1.0f Q15*/; - move16(); - } + sfm = min(((float)pow(2.0, numf + 0.5f) / denom), 1.0f); } - return SFM /*Q15*/; + return sfm; } /**********************************************************************/ /* calculates the IGF whitening levels by SFM and crest **************************************************************************/ static void IGF_Whitening(const IGF_ENC_INSTANCE_HANDLE hInstance, /**< in: | instance handle of IGF Encoder */ - Word32 *powerSpectrum, /**< in: Q31 | MDCT/MDST power spectrum */ - const Word16 powerSpectrum_exp, /**< in: | exponent of powerspectrum */ - const Word16 igfGridIdx, /**< in: Q0 | IGF grid index */ - Word16 isTransient, /**< in: Q0 | boolean, indicating if transient is detected */ - Word16 last_core_acelp /**< in: Q0 | indictaor if last frame was acelp coded */ + float *powerSpectrum, /**< in: Q31 | MDCT/MDST power spectrum */ + const int igfGridIdx, /**< in: Q0 | IGF grid index */ + int isTransient, /**< in: Q0 | boolean, indicating if transient is detected */ + int last_core_acelp /**< in: Q0 | indictaor if last frame was acelp coded */ ) { IGF_ENC_PRIVATE_DATA_HANDLE hPrivateData; H_IGF_GRID hGrid; - Word16 p; /*Q0*/ - Word16 tmp; - Word16 SFM; - Word16 crest; - Word16 SFM_exp; - Word16 crest_exp; - Word16 s; - Word32 tmp32; - Word32 SFM32; + int p; + float tmp; + float SFM; hPrivateData = &hInstance->igfData; - hGrid = &hPrivateData->igfInfo.grid[igfGridIdx]; + hGrid = &hPrivateData->igfInfo.grid[(int)igfGridIdx]; - IF (igfGridIdx != IGF_GRID_LB_NORM) + if (igfGridIdx != IGF_GRID_LB_NORM) { - FOR (p = 0; p < hGrid->nTiles; p++) + for (p = 0; p < hGrid->nTiles; p++) { /* reset filter */ - hPrivateData->prevSFM_FIR[p] = L_deposit_l(0); - hPrivateData->prevSFM_IIR[p] = 0; - move16(); + hPrivateData->prevSFM_FIR[p] = 0.f; + hPrivateData->prevSFM_IIR[p] = 0.f; /* preset values: */ hPrivateData->igfCurrWhiteningLevel[p] = IGF_WHITENING_OFF; - move16(); } } - FOR (p = 0; p < IGF_MAX_TILES; p++) + + for (p = 0; p < IGF_MAX_TILES; p++) { /* update prev data: */ hPrivateData->igfPrevWhiteningLevel[p] = hPrivateData->igfCurrWhiteningLevel[p]; - move16(); /* preset values: */ hPrivateData->igfCurrWhiteningLevel[p] = IGF_WHITENING_OFF; - move16(); } - IF (!s_or(isTransient, hPrivateData->wasTransient)) + if (!(isTransient || hPrivateData->wasTransient)) { - IF (powerSpectrum) + if (powerSpectrum) { - Word16 nT = hGrid->nTiles; - SWITCH (hPrivateData->igfInfo.bitRateIndex) + for (p = 0; p < hGrid->nTiles; p++) { - case IGF_BITRATE_WB_9600: - case IGF_BITRATE_SWB_9600: - case IGF_BITRATE_SWB_16400: - case IGF_BITRATE_SWB_24400: - case IGF_BITRATE_SWB_32000: - case IGF_BITRATE_FB_16400: - case IGF_BITRATE_FB_24400: - case IGF_BITRATE_FB_32000: - nT = sub(nT, 1); - BREAK; - default: - BREAK; - } - FOR (p = 0; p < nT; p++) - { - /*tmp = IGF_getSFM(powerSpectrum, hGrid->tile[p], hGrid->tile[p+1]) / IGF_getCrest(powerSpectrum, hGrid->tile[p], hGrid->tile[p+1]);*/ - SFM = IGF_getSFM(&SFM_exp, powerSpectrum, &powerSpectrum_exp, hGrid->tile[p], hGrid->tile[p + 1]); - crest = IGF_getCrest(&crest_exp, powerSpectrum, powerSpectrum_exp, hGrid->tile[p], hGrid->tile[p + 1]); + tmp = IGF_getSFM(powerSpectrum, hGrid->tile[p], hGrid->tile[p + 1]) / IGF_getCrest(powerSpectrum, hGrid->tile[p], hGrid->tile[p + 1]); - tmp = BASOP_Util_Divide1616_Scale(SFM, crest, &s); /* Q15 */ - s = add(s, sub(SFM_exp, crest_exp)); - tmp32 = L_shl(L_deposit_l(tmp)/*16Q15, s*/,add(s,1)); /* 15Q16 */ - - test(); - IF (last_core_acelp || hPrivateData->wasTransient) + if(last_core_acelp || hPrivateData->wasTransient) { - hPrivateData->prevSFM_FIR[p] = tmp32; /* 15Q16 */ move32(); - hPrivateData->prevSFM_IIR[p] = shr(tmp, 2); /* 2Q13 */ move16(); + hPrivateData->prevSFM_FIR[p] = hPrivateData->prevSFM_IIR[p] = tmp; } - /*SFM = tmp + hPrivateData->prevSFM_FIR[p] + 0.5f * hPrivateData->prevSFM_IIR[p];*/ - SFM32 = L_add(tmp32,hPrivateData->prevSFM_FIR[p]); - SFM32 = L_mac0(SFM32,hPrivateData->prevSFM_IIR[p]/*Q13*/,4/*.5f Q3*/);/*15Q16*/ + SFM = tmp + hPrivateData->prevSFM_FIR[p] + 0.5f * hPrivateData->prevSFM_IIR[p]; + SFM = min(2.7f, SFM); - BASOP_SATURATE_WARNING_OFF - /*SFM = min(2.7f, SFM);*/ - /*Overflow possible in shift, intended*/ - SFM = s_min(22118/*2.7f Q13*/,extract_h(L_shr(SFM32,16-29)/*->Q29*/)/*->Q13*/ ); - BASOP_SATURATE_WARNING_ON - - hPrivateData->prevSFM_FIR[p] = tmp32; /*15Q16*/ move32(); + hPrivateData->prevSFM_FIR[p] = tmp; hPrivateData->prevSFM_IIR[p] = SFM; - move16(); - IF (sub(SFM , hGrid->whiteningThreshold[1][p]) > 0) + if (SFM > hGrid->whiteningThreshold[1][p]) { hPrivateData->igfCurrWhiteningLevel[p] = IGF_WHITENING_STRONG; - move16(); } - ELSE IF (sub(SFM , hGrid->whiteningThreshold[0][p]) > 0) + else if (SFM > hGrid->whiteningThreshold[0][p]) { hPrivateData->igfCurrWhiteningLevel[p] = IGF_WHITENING_MID; - move16(); + } + else + { + hPrivateData->igfCurrWhiteningLevel[p] = IGF_WHITENING_OFF; } } - SWITCH (hPrivateData->igfInfo.bitRateIndex) + + switch (hPrivateData->igfInfo.bitRateIndex) { case IGF_BITRATE_WB_9600: case IGF_BITRATE_RF_WB_13200: @@ -834,201 +461,191 @@ static void IGF_Whitening(const IGF_ENC_INSTANCE_HANDLE hInstanc case IGF_BITRATE_FB_16400: case IGF_BITRATE_FB_24400: case IGF_BITRATE_FB_32000: - move16(); hPrivateData->igfCurrWhiteningLevel[hGrid->nTiles - 1] = hPrivateData->igfCurrWhiteningLevel[hGrid->nTiles - 2]; - BREAK; + break; default: - BREAK; + break; } } - ELSE + else { - FOR (p = 0; p < hGrid->nTiles; p++) + for (p = 0; p < hGrid->nTiles; p++) { hPrivateData->igfCurrWhiteningLevel[p] = IGF_WHITENING_MID; - move16(); } } } - ELSE + else { /* reset filter */ - FOR (p = 0; p < IGF_MAX_TILES; p++) + for (p = 0; p < IGF_MAX_TILES; p++) { - hPrivateData->prevSFM_FIR[p] = L_deposit_l(0); - hPrivateData->prevSFM_IIR[p] = 0; - move16(); + hPrivateData->prevSFM_FIR[p] = 0.f; + hPrivateData->prevSFM_IIR[p] = 0.f; } } - hPrivateData->wasTransient = isTransient; - move16(); + hPrivateData->wasTransient = isTransient; + + return; } + /**********************************************************************/ /* write whitening levels into bitstream **************************************************************************/ -static void IGF_WriteWhiteningTile( /**< out: Q0 | number of bits written */ - Encoder_State_fx *st, /**< in: | encoder state handle */ - Word16 *pBitOffset, /**< in: | ptr to bitOffset counter */ - Word16 whiteningLevel /**< in: Q0 | whitening levels to write */ +static int IGF_WriteWhiteningTile( /**< out: | number of bits written */ + Encoder_State *st, /**< in: | encoder state handle */ + int *pBitOffset, /**< in: | ptr to bitOffset counter */ + int whiteningLevel /**< in: Q0 | whitening levels to write */ ) { - IF (L_sub(whiteningLevel, IGF_WHITENING_MID) == 0) + int totBitCount; + int startBitCount; + + totBitCount = 0; + startBitCount = *pBitOffset; + + if (whiteningLevel == IGF_WHITENING_MID) { IGF_write_bits(st, pBitOffset, 0, 1); } - ELSE + else { IGF_write_bits(st, pBitOffset, 1, 1); - IF (L_sub(whiteningLevel , IGF_WHITENING_OFF) == 0) + if(whiteningLevel == IGF_WHITENING_OFF) { IGF_write_bits(st, pBitOffset, 0, 1); } - ELSE + else { IGF_write_bits(st, pBitOffset, 1, 1); } } + totBitCount = *pBitOffset - startBitCount; + + return totBitCount; } /**********************************************************************/ /* writes the whitening levels **************************************************************************/ -static void IGF_WriteWhiteningLevels( /**< out: Q0 | total number of bits written */ - const IGF_ENC_INSTANCE_HANDLE hInstance, /**< in: | instance handle of IGF encoder */ - Encoder_State_fx *st, /**< in: | encoder state */ - Word16 *pBitOffset, /**< in: | ptr to bitOffset counter */ - const Word16 igfGridIdx, /**< in: Q0 | igf grid index see declaration of IGF_GRID_IDX for details */ - const Word16 isIndepFlag /**< in: Q0 | if 1 frame is independent, 0 = frame is coded with data from previous frame */ +static int IGF_WriteWhiteningLevels( /**< out: Q0 | total number of bits written */ + const IGF_ENC_INSTANCE_HANDLE hInstance, /**< in: | instance handle of IGF encoder */ + Encoder_State *st, /**< in: | encoder state */ + int *pBitOffset, /**< in: | ptr to bitOffset counter */ + const int igfGridIdx, /**< in: Q0 | igf grid index see declaration of IGF_GRID_IDX for details */ + const int isIndepFlag /**< in: Q0 | if 1 frame is independent, 0 = frame is coded with data from previous frame */ ) { IGF_ENC_PRIVATE_DATA_HANDLE hPrivateData; H_IGF_GRID hGrid; - Word16 p; - Word16 nTiles; - Word16 isSame; - Word32 tmp32; - + int p; + int nTiles; + int totBitCount; + int isSame; + int startBitCount; + totBitCount = 0; isSame = 1; - move16(); + startBitCount = *pBitOffset; hPrivateData = &hInstance->igfData; hGrid = &hPrivateData->igfInfo.grid[igfGridIdx]; nTiles = hGrid->nTiles; - move16(); - IF (isIndepFlag) + if (isIndepFlag) { isSame = 0; - move16(); } - ELSE + else { - p = 0; - move16(); - tmp32 = L_add(0, 0); - - WHILE ((sub(p, nTiles) < 0) && (tmp32 == 0)) + for (p = 0; p < nTiles ; p++) { - test(); - tmp32 = L_sub(hPrivateData->igfCurrWhiteningLevel[p] , hPrivateData->igfPrevWhiteningLevel[p]); - if (tmp32 != 0) + if (hPrivateData->igfCurrWhiteningLevel[p] != hPrivateData->igfPrevWhiteningLevel[p]) { isSame = 0; - move16(); + break; } - p++; } } - IF (isSame) + if (isSame) { IGF_write_bits(st, pBitOffset, 1, 1); } - ELSE + else { - IF (!isIndepFlag) + if (!isIndepFlag) { IGF_write_bits(st, pBitOffset, 0, 1); } IGF_WriteWhiteningTile(st, pBitOffset, hPrivateData->igfCurrWhiteningLevel[0]); - p = 1; - move16(); - tmp32 = L_add(0, 0); - if (sub(p, nTiles) < 0) + for (p = 1; p < nTiles ; p++) { isSame = 1; - move16(); - } - - WHILE ((sub(p, nTiles) < 0) && (tmp32 == 0)) - { - test(); - tmp32 = L_sub(hPrivateData->igfCurrWhiteningLevel[p] , hPrivateData->igfCurrWhiteningLevel[p - 1]); - if (tmp32 != 0) + if (hPrivateData->igfCurrWhiteningLevel[p] != hPrivateData->igfCurrWhiteningLevel[p-1]) { isSame = 0; - move16(); + break; } - p++; } - - IF (!isSame) + if (!isSame) { IGF_write_bits(st, pBitOffset, 1, 1); - FOR (p = 1; p < nTiles; p++) + for (p = 1; p < nTiles ; p++) { IGF_WriteWhiteningTile(st, pBitOffset, hPrivateData->igfCurrWhiteningLevel[p]); } } - ELSE + else { IGF_write_bits(st, pBitOffset, 0, 1); } } + totBitCount = *pBitOffset - startBitCount; + return totBitCount; } /**********************************************************************/ /* write flattening trigger **************************************************************************/ -static void IGF_WriteFlatteningTrigger( /**< out: | number of bits written */ - const IGF_ENC_INSTANCE_HANDLE hInstance, /**< in: | instance handle of IGF Encoder */ - Encoder_State_fx *st, /**< in: | encoder state */ - Word16 *pBitOffset /**< in: | ptr to bitOffset counter */ +static int IGF_WriteFlatteningTrigger( /**< out: | number of bits written */ + const IGF_ENC_INSTANCE_HANDLE hInstance, /**< in: | instance handle of IGF Encoder */ + Encoder_State *st, /**< in: | encoder state */ + int *pBitOffset /**< in: | ptr to bitOffset counter */ ) { - Word16 flatteningTrigger; - + int totBitCount; + int startBitCount; + int flatteningTrigger; + totBitCount = 0; + startBitCount = *pBitOffset; flatteningTrigger = hInstance->flatteningTrigger; - move16(); IGF_write_bits(st, pBitOffset, flatteningTrigger, 1); + totBitCount = *pBitOffset - startBitCount; + + return totBitCount; } /**********************************************************************/ /* updates the start/stop frequency of IGF according to igfGridIdx **************************************************************************/ static void IGF_UpdateInfo(const IGF_ENC_INSTANCE_HANDLE hInstance, /**< in: | instance handle of IGF Encoder */ - const Word16 igfGridIdx /**< in: Q0 | IGF grid index */ + const int igfGridIdx /**< in: | IGF grid index */ ) { IGF_ENC_PRIVATE_DATA_HANDLE hPrivateData; H_IGF_GRID hGrid; - hPrivateData = &hInstance->igfData; hGrid = &hPrivateData->igfInfo.grid[igfGridIdx]; hInstance->infoStartFrequency = hGrid->startFrequency; - move16(); hInstance->infoStopFrequency = hGrid->stopFrequency; - move16(); hInstance->infoStartLine = hGrid->startLine; - move16(); hInstance->infoStopLine = hGrid->stopLine; - move16(); return; } @@ -1036,48 +653,43 @@ static void IGF_UpdateInfo(const IGF_ENC_INSTANCE_HANDLE hInstanc /**********************************************************************/ /* IGF bitsream writer **************************************************************************/ -Word16 IGFEncWriteBitstream( /**< out: | number of bits written per frame */ - const IGF_ENC_INSTANCE_HANDLE hInstance, /**< in: | instance handle of IGF Encoder */ - Encoder_State_fx *st, /**< in: | encoder state */ - Word16 *pBitOffset, /**< in: | ptr to bitOffset counter */ - const Word16 igfGridIdx, /**< in: Q0 | igf grid index see declaration of IGF_GRID_IDX for details */ - const Word16 isIndepFlag /**< in: Q0 | if 1 frame is independent, 0 = frame is coded with data from previous frame */ +int IGFEncWriteBitstream( /**< out: | number of bits written per frame */ + const IGF_ENC_INSTANCE_HANDLE hInstance, /**< in: | instance handle of IGF Encoder */ + void *st, /**< in: | encoder state */ + int *pBitOffset, /**< in: | ptr to bitOffset counter */ + const int igfGridIdx, /**< in: | igf grid index see declaration of IGF_GRID_IDX for details */ + const int isIndepFlag /**< in: | if 1 frame is independent, 0 = frame is coded with data from previous frame */ ) { - Word16 igfAllZero; - Word16 startBitCount; + int igfAllZero; + int startBitCount = *pBitOffset; - - startBitCount = *pBitOffset; - move16(); hInstance->infoTotalBitsPerFrameWritten = 0; - move16(); - + hInstance->infoFrameCount++; if (isIndepFlag) { hInstance->infoTotalBitsWritten = 0; - move16(); } IGF_WriteEnvelope(hInstance, /* i: instance handle of IGF Encoder */ - st, /* i: encoder state */ + (Encoder_State*)st, /* i: encoder state */ pBitOffset, /* i: ptr to bitOffset counter */ igfGridIdx, /* i: igf grid index see definition of IGF_GRID_IDX for details */ isIndepFlag, /* i: if 1 frame is independent, 0 = frame is coded with data from previous frame */ &igfAllZero); /* o: *igfAllZero */ IGF_WriteWhiteningLevels(hInstance, /* i: instance handle of IGF Encoder */ - st, /* i: encoder state */ + (Encoder_State*)st, /* i: encoder state */ pBitOffset, /* i: ptr to bitOffset counter */ igfGridIdx, /* i: igf grid index see definition of IGF_GRID_IDX for details */ isIndepFlag); /* i: if 1 frame is independent, 0 = frame is coded with data from previous frame */ IGF_WriteFlatteningTrigger(hInstance, /* i: instance handle of IGF Encoder */ - st, /* i: encoder state */ + (Encoder_State*)st, /* i: encoder state */ pBitOffset); /* i: ptr to bitOffset counter */ - hInstance->infoTotalBitsPerFrameWritten = sub(*pBitOffset, startBitCount); - hInstance->infoTotalBitsWritten = add(hInstance->infoTotalBitsWritten, hInstance->infoTotalBitsPerFrameWritten); + hInstance->infoTotalBitsPerFrameWritten = (*pBitOffset - startBitCount); + hInstance->infoTotalBitsWritten += hInstance->infoTotalBitsPerFrameWritten; return hInstance->infoTotalBitsPerFrameWritten; } @@ -1085,80 +697,57 @@ Word16 IGFEncWriteBitstream( /**********************************************************************/ /* sets the IGF mode according to given bitrate **************************************************************************/ -void IGFEncSetMode(const IGF_ENC_INSTANCE_HANDLE hInstance, /**< in: | instance handle of IGF Encoder */ - const Word32 bitRate, /**< in: Q0 | encoder bitrate */ - const Word16 mode /**< in: Q0 | encoder bandwidth mode */ - ,const Word16 rf_mode /**< in: Q0 | flag to signal the RF mode */ - ) +void IGFEncSetMode( + const IGF_ENC_INSTANCE_HANDLE hInstance, /**< in: | instance handle of IGF Encoder */ + const int bitRate, /**< in: | encoder bitrate */ + const int mode, /**< in: | encoder bandwidth mode */ + int const rf_mode /**< in: flag to signal the RF mode */ +) { + short i; IGF_ENC_PRIVATE_DATA_HANDLE hPrivateData; - Word16 i; hPrivateData = &hInstance->igfData; hPrivateData->igfBitstreamBits = 0; - move16(); - set16_fx(hPrivateData->igfScfQuantized, 0, IGF_MAX_SFB); - set16_fx(hPrivateData->igfCurrWhiteningLevel, 0, IGF_MAX_TILES); - set16_fx(hPrivateData->igfPrevWhiteningLevel, 0, IGF_MAX_TILES); - FOR( i = 0; i < BITBUFSIZE/8; i++) + set_i(hPrivateData->igfScfQuantized, 0, IGF_MAX_SFB); + set_i(hPrivateData->igfCurrWhiteningLevel, 0, IGF_MAX_TILES); + set_i(hPrivateData->igfPrevWhiteningLevel, 0, IGF_MAX_TILES); + for( i=0; iigfBitstream[i] = 0; - move16(); } hPrivateData->wasTransient = 0; - move16(); - set32_fx(hPrivateData->prevSFM_FIR, 0, IGF_MAX_TILES); - set16_fx(hPrivateData->prevSFM_IIR, 0, IGF_MAX_TILES); + set_f(hPrivateData->prevSFM_FIR, 0, IGF_MAX_TILES); + set_f(hPrivateData->prevSFM_IIR, 0, IGF_MAX_TILES); - IF (IGFCommonFuncsIGFConfiguration(bitRate, mode, &hPrivateData->igfInfo,rf_mode) != 0) + + if (IGFCommonFuncsIGFConfiguration(bitRate, mode, &hPrivateData->igfInfo, rf_mode)) { - IGFSCFEncoderOpen(&hPrivateData->hIGFSCFArithEnc, - sub(hPrivateData->igfInfo.grid[0].stopSfb, hPrivateData->igfInfo.grid[0].startSfb), - bitRate, - mode - ,rf_mode - - ); + IGFSCFEncoderOpen( &hPrivateData->hIGFSCFArithEnc, hPrivateData->igfInfo.grid[0].stopSfb - hPrivateData->igfInfo.grid[0].startSfb, bitRate, mode, rf_mode ); hInstance->infoSamplingRate = hPrivateData->igfInfo.sampleRate; - move32(); hInstance->infoStartFrequency = hPrivateData->igfInfo.grid[0].startFrequency; - move16(); hInstance->infoStopFrequency = hPrivateData->igfInfo.grid[0].stopFrequency; - move16(); hInstance->infoStartLine = hPrivateData->igfInfo.grid[0].startLine; - move16(); hInstance->infoStopLine = hPrivateData->igfInfo.grid[0].stopLine; - move16(); } - ELSE + else { /* IGF configuration failed -> error! */ - hInstance->infoSamplingRate = 0; - move32(); + hInstance->infoSamplingRate = 0; hInstance->infoStartFrequency = -1; - move16(); hInstance->infoStopFrequency = -1; - move16(); hInstance->infoStartLine = -1; - move16(); hInstance->infoStopLine = -1; - move16(); fprintf(stderr,"IGFEncSetMode: initialization error!\n"); } /* reset remaining variables */ hInstance->infoTotalBitsWritten = 0; - move16(); hInstance->infoTotalBitsPerFrameWritten = 0; - move16(); hInstance->flatteningTrigger = 0; - move16(); - hInstance->spec_be_igf_e = 0; - move16(); hInstance->tns_predictionGain = 0; - move16(); - set32_fx(hInstance->spec_be_igf, 0, N_MAX_TCX-IGF_START_MN); + set_f(hInstance->spec_be_igf, 0, N_MAX_TCX-IGF_START_MN); return; } @@ -1166,25 +755,25 @@ void IGFEncSetMode(const IGF_ENC_INSTANCE_HANDLE hInstance, IGF bitsream concatenation for TCX10 modes **************************************************************************/ void IGFEncConcatenateBitstream(const IGF_ENC_INSTANCE_HANDLE hInstance, /**< in: | instance handle of IGF Encoder */ - Word16 bsBits, /**< in: Q0 | number of IGF bits written to list of indices */ - Word16 *next_ind, /**< in/out: | pointer to actual bit indice */ - Word16 *nb_bits, /**< in/out: | total number of bits already written */ - Indice_fx *ind_list_fx /**< in: | pointer to list of indices */ + short bsBits, /**< in: | number of IGF bits written to list of indices */ + short *next_ind, /**< in/out: | pointer to actual bit indice */ + short *nb_bits, /**< in/out: | total number of bits already written */ + Indice *ind_list /**< in: | pointer to list of indices */ ) { IGF_ENC_PRIVATE_DATA_HANDLE hPrivateData; hPrivateData = &hInstance->igfData; - *next_ind = *next_ind - bsBits; + *next_ind -= bsBits; indices_to_serial_generic( - &ind_list_fx[*next_ind], + &ind_list[*next_ind], bsBits, hPrivateData->igfBitstream, &hPrivateData->igfBitstreamBits ); - *nb_bits = sub(*nb_bits, bsBits); + *nb_bits -= hInstance->infoTotalBitsPerFrameWritten; return; } @@ -1199,40 +788,34 @@ void IGFEncResetTCX10BitCounter(const IGF_ENC_INSTANCE_HANDLE hInstance hPrivateData = &hInstance->igfData; hPrivateData->igfBitstreamBits = 0; - move16(); hInstance->infoTotalBitsWritten = 0; - move16(); - - return; } /**********************************************************************/ /* IGF write concatenated bitsream for TCX10 modes **************************************************************************/ -Word16 IGFEncWriteConcatenatedBitstream( /**< out: Q0 | total number of bits written */ - const IGF_ENC_INSTANCE_HANDLE hInstance, /**< in: | instance handle of IGF Encoder */ - void *st /**< in: | encoder state */ +int IGFEncWriteConcatenatedBitstream( /**< out: | total number of bits written */ + const IGF_ENC_INSTANCE_HANDLE hInstance, /**< in: | instance handle of IGF Encoder */ + void *st /**< in: | encoder state */ ) { IGF_ENC_PRIVATE_DATA_HANDLE hPrivateData; - Word16 i; - Word16 tmp; - Word16 bitsLeft; + int i; + int bitsLeft; UWord8 *pBitstream; hPrivateData = &hInstance->igfData; - pBitstream = &hPrivateData->igfBitstream[0]; + pBitstream = hPrivateData->igfBitstream; - tmp = shr(hPrivateData->igfBitstreamBits, 3); - FOR (i = 0; i < tmp; i++) + for (i = 0; i < hPrivateData->igfBitstreamBits >> 3; i++) { - push_next_indice_fx((Encoder_State_fx*)st, pBitstream[i], 8); + push_next_indice((Encoder_State*)st, pBitstream[i], 8); } - bitsLeft = s_and(hPrivateData->igfBitstreamBits, 0x7); - IF(bitsLeft > 0) + bitsLeft = hPrivateData->igfBitstreamBits & 0x7; + if(bitsLeft > 0) { - push_next_indice_fx((Encoder_State_fx*)st, shr(pBitstream[i], sub(8, bitsLeft)), bitsLeft); + push_next_indice((Encoder_State*)st, pBitstream[i] >> (8 - bitsLeft), bitsLeft); } return hInstance->infoTotalBitsWritten; @@ -1242,66 +825,42 @@ Word16 IGFEncWriteConcatenatedBitstream( apply the IGF encoder, main encoder interface **************************************************************************/ void IGFEncApplyMono(const IGF_ENC_INSTANCE_HANDLE hInstance, /**< in: | instance handle of IGF Encoder */ - const Word16 igfGridIdx, /**< in: Q0 | IGF grid index */ - Encoder_State_fx *st, /**< in: | Encoder state */ - Word32 *pMDCTSpectrum, /**< in: Q31 | MDCT spectrum */ - Word16 MDCTSpectrum_e, /**< in: | exponent of MDCT spectrum */ - Word32 *pPowerSpectrum, /**< in: Q31 | MDCT^2 + MDST^2 spectrum, or estimate */ - Word16 PowerSpectrum_e, /**< in: | exponent of pPowerSpectrum */ - Word16 isTCX20, /**< in: Q0 | flag indicating if the input is TCX20 or TCX10/2xTCX5 */ - Word16 isTNSActive, /**< in: Q0 | flag indicating if the TNS is active */ - Word16 last_core_acelp /**< in: Q0 | indicator if last frame was acelp coded */ + const int igfGridIdx, /**< in: | IGF grid index */ + Encoder_State *st, /**< in: | Encoder state */ + float *pMDCTSpectrum, /**< in: | MDCT spectrum */ + float *pPowerSpectrum, /**< in: | MDCT^2 + MDST^2 spectrum, or estimate */ + int isTCX20, /**< in: | flag indicating if the input is TCX20 or TCX10/2xTCX5 */ + int isTNSActive, /**< in: | flag indicating if the TNS is active */ + int last_core_acelp /**< in: | indictaor if last frame was acelp coded */ ) { - Word32 *pPowerSpectrumParameter; /* If it is NULL it informs a function that specific handling is needed */ - Word32 *pPowerSpectrumParameterWhitening; /* If it is NULL it informs a function that specific handling is needed */ - Word16 highPassEner_exp; /*exponent of highpass energy - maybe not needed*/ + float *pPowerSpectrumParameter; /* If it is NULL it informs a function that specific handling is needed */ + pPowerSpectrumParameter = !isTNSActive && isTCX20 ? pPowerSpectrum : NULL; - pPowerSpectrumParameter = NULL; - test(); - if ((isTNSActive == 0) && (isTCX20 != 0)) - { - pPowerSpectrumParameter = pPowerSpectrum; - } - pPowerSpectrumParameterWhitening = NULL; - if (isTCX20 != 0) - { - pPowerSpectrumParameterWhitening = pPowerSpectrum; - } + IGF_UpdateInfo(hInstance, /* i: instance handle of IGF Encoder */ + igfGridIdx); /* i: IGF grid index */ - IGF_UpdateInfo(hInstance, /* i: instance handle of IGF Encoder */ - igfGridIdx); /* i: IGF grid index */ - - IGF_CalculateEnvelope(hInstance, /* i: instance handle of IGF Encoder */ - pMDCTSpectrum, /* i: MDCT spectrum */ - MDCTSpectrum_e, /* i: exponent of MDCT spectrum */ - pPowerSpectrumParameter, /* i: MDCT^2 + MDST^2 spectrum, or estimate */ - PowerSpectrum_e, /* i: exponent of pPowerSpectrum */ - igfGridIdx /* i: IGF grid index */ + IGF_CalculateEnvelope(hInstance, /* i: instance handle of IGF Encoder */ + pMDCTSpectrum, /* i: MDCT spectrum */ + pPowerSpectrumParameter, /* i: MDCT^2 + MDST^2 spectrum, or estimate */ + igfGridIdx /* i: IGF grid index */ ); - IGF_Whitening(hInstance, /* i: instance handle of IGF Encoder */ - pPowerSpectrumParameterWhitening, /* i: MDCT^2 + MDST^2 spectrum, or estimate */ - PowerSpectrum_e, /* i: exponent of powerSpectrum */ - igfGridIdx, /* i: IGF grid index */ + IGF_Whitening(hInstance, /* i: instance handle of IGF Encoder */ + isTCX20 ? pPowerSpectrum : NULL, /* i: MDCT^2 + MDST^2 spectrum, or estimate */ + igfGridIdx, /* i: IGF grid index */ (st->transientDetection.transientDetector.bIsAttackPresent == 1), - last_core_acelp); /* i: last frame was acelp indicator */ + last_core_acelp /* i: last frame was acelp indicator */ + ); - pPowerSpectrumParameter = NULL; - if (isTCX20 != 0) - { - pPowerSpectrumParameter = pPowerSpectrum; - } - - IGF_ErodeSpectrum( /* o: highpass energy */ - &highPassEner_exp, /* o: exponent of highPassEner */ - hInstance, /* i: instance handle of IGF Encoder */ - pMDCTSpectrum, /* i: MDCT spectrum */ - pPowerSpectrumParameter, /* i: MDCT^2 + MDST^2 spectrum, or estimate */ - PowerSpectrum_e, /* i: exponent of pPowerSpectrum */ - igfGridIdx); /* i: IGF grid index */ + pPowerSpectrumParameter = isTCX20 ? pPowerSpectrum : NULL; + IGF_ErodeSpectrum( /* o: highpass energy */ + hInstance, /* i: instance handle of IGF Encoder */ + pMDCTSpectrum, /* i: MDCT spectrum */ + pPowerSpectrumParameter, /* i: MDCT^2 + MDST^2 spectrum, or estimate */ + igfGridIdx); /* i: IGF grid index */ } diff --git a/src/libs/libevs/lib_enc/igf_scf_enc.cpp b/src/libs/libevs/lib_enc/igf_scf_enc.cpp old mode 100755 new mode 100644 index f708dab1..68ab3273 --- a/src/libs/libevs/lib_enc/igf_scf_enc.cpp +++ b/src/libs/libevs/lib_enc/igf_scf_enc.cpp @@ -1,205 +1,188 @@ /*==================================================================================== - EVS Codec 3GPP TS26.442 Apr 03, 2018. Version 12.11.0 / 13.6.0 / 14.2.0 + EVS Codec 3GPP TS26.443 Nov 13, 2018. Version 12.11.0 / 13.7.0 / 14.3.0 / 15.1.0 ====================================================================================*/ #include -#include -#include +#include "prot.h" #include "options.h" -#include "stl.h" -#include "prot_fx.h" -#include "stat_enc_fx.h" +#include "stat_enc.h" #include "stat_com.h" -#include "cnst_fx.h" -#include "basop_util.h" +#include "cnst.h" +/*---------------------------------------------------------------------* + * IGFSCFEncoderOpen() + * + * initialization of an instance of this module, pass a ptr to a hPublicData + *---------------------------------------------------------------------*/ -/**********************************************************************/ /** -initialization of an instance of this module -**************************************************************************/ void IGFSCFEncoderOpen( - IGFSCFENC_INSTANCE_HANDLE hPublicData, /* i/o: handle to public data */ - Word16 scfCountLongBlock, /* i: number of SCFs for a long block */ - Word32 bitRate, /* i: bitrate in bps */ - Word16 mode /* i: operating mode */ - , Word16 rf_mode /**< in: flag to signal the RF mode */ + IGFSCFENC_INSTANCE_HANDLE hPublicData, /**< inout: handle to public data */ + int scfCountLongBlock, + int bitRate, + int mode, + int rf_mode /**< in: flag to signal the RF mode */ ) { - hPublicData->ptrBitIndex = 0; - move16(); hPublicData->bitCount = 0; - move16(); - hPublicData->tSave = 0; - move16(); - hPublicData->context_saved = 0; - move16(); + hPublicData->Tsave = 0; + hPublicData->contex_saved = 0; hPublicData->acState.low = 0; - move32(); hPublicData->acState.high = 0; - move32(); hPublicData->acState.vobf = 0; - move16(); - set16_fx(hPublicData->prev, 0, 64); - set16_fx(hPublicData->prevSave, 0, 64); + set_i(hPublicData->prev, 0, 64); + set_i(hPublicData->prevSave, 0, 64); - hPublicData->scfCountLongBlock = scfCountLongBlock; - move16(); - hPublicData->t = 0; - move16(); /* protect against the invalid request of starting encoding with a dependent block */ + hPublicData->scfCountLongBlock = scfCountLongBlock; + hPublicData->t = 0; /* protect against the invalid request of starting encoding with a dependent block */ - IGFCommonFuncsIGFGetCFTables( - bitRate, - mode, - rf_mode, - &hPublicData->cf_se00, - &hPublicData->cf_se01, - &hPublicData->cf_off_se01, - &hPublicData->cf_se02, - &hPublicData->cf_off_se02, - &hPublicData->cf_se10, - &hPublicData->cf_off_se10, - &hPublicData->cf_se11, - &hPublicData->cf_off_se11 - ); + IGFCommonFuncsIGFGetCFTables( bitRate, mode, rf_mode, &hPublicData->cf_se00, &hPublicData->cf_se01, &hPublicData->cf_off_se01, + &hPublicData->cf_se02, &hPublicData->cf_off_se02, &hPublicData->cf_se10, + &hPublicData->cf_off_se10, &hPublicData->cf_se11, &hPublicData->cf_off_se11 ); + return; } -static Word16 quant_ctx( - Word16 ctx /* i: the context value to be quantized */ +/*---------------------------------------------------------------------* + * quant_ctx() + * + * + *---------------------------------------------------------------------*/ + +static int quant_ctx( + int ctx ) { /* ctx ... -5 -4 -3 -2 -1 0 1 2 3 4 5 ... Q(ctx)... -3 -3 -3 -2 -1 0 1 2 3 3 3 ... */ - Word16 result; - - - result = s_min(abs_s(ctx), IGF_CTX_OFFSET); /* limit the absolute value to IGF_CTX_OFFSET */ - if (ctx < 0) /* add the sign back, if needed */ + if (abs(ctx) <= 3) { - result = negate(result); + return ctx; + } + else if (ctx > 3) + { + return 3; + } + else /* ctx < -3 */ + { + return -3; } - - return result; } +/*---------------------------------------------------------------------* + * arith_encode_bits() + * + * + *---------------------------------------------------------------------*/ static void arith_encode_bits( - IGFSCFENC_INSTANCE_HANDLE hPrivateData, /* i/o: instance handle */ - Word16 *ptr, /* i/o: pointer to expanded bit buffer, one bit in each Word16 */ - Word16 x, /* i: value to encode */ - Word16 nBits /* i: number of bits to encode */ + IGFSCFENC_INSTANCE_HANDLE hPrivateData, /**< instance handle */ + int *ptr, /**< pointer to expanded bit buffer, one bit in each int */ + int x, /**< value to encode */ + int nBits /**< number of bits to encode */ ) { - Word16 i; - Word16 bit; + int i; + int bit; - - FOR (i = nBits - 1; i >= 0; --i) /* nBits > 0 */ + for (i = nBits - 1; i >= 0; --i) { - bit = s_and(shr(x, i), 1); - hPrivateData->ptrBitIndex = ari_encode_14bits_sign(ptr, - hPrivateData->ptrBitIndex, - 32767, /* disable the bit count limitation */ - &hPrivateData->acState, - bit - ); + bit = (x >> i) & 1; + hPrivateData->ptrBitIndex = ari_encode_14bits_sign(ptr, hPrivateData->ptrBitIndex, 32767, /* disable the bit count limitation */ &hPrivateData->acState, bit ); } + return; } + +/*---------------------------------------------------------------------* + * arith_encode_residual() + * + * + *---------------------------------------------------------------------*/ + static void arith_encode_residual( - IGFSCFENC_INSTANCE_HANDLE hPrivateData, /* i/o: instance handle */ - Word16 *ptr, /* i/o: pointer to expanded bit buffer, one bit in each Word16 */ - Word16 x, /* i: residual value to encode */ - const Word16 *cumulativeFrequencyTable, /* i: cumulative frequency table to be used */ - Word16 tableOffset /* i: offset used to align the table */ + IGFSCFENC_INSTANCE_HANDLE hPrivateData, /**< instance handle */ + int *ptr, /**< pointer to expanded bit buffer, one bit in each int */ + int x, /**< prediction residual to encode */ + const unsigned short *cumulativeFrequencyTable, /**< cumulative frequency table to be used */ + int tableOffset /**< offset used to align the table */ ) { - Word16 extra; - Word16 extra_tmp; - Word16 extra_safety; + int extra; - - x = add(x, tableOffset); - - test(); - IF ((sub(x, IGF_MIN_ENC_SEPARATE) >= 0) && (sub(x, IGF_MAX_ENC_SEPARATE) <= 0)) + x += tableOffset; + if ((x >= IGF_MIN_ENC_SEPARATE) && (x <= IGF_MAX_ENC_SEPARATE)) { - x = sub(x, IGF_MIN_ENC_SEPARATE - 1); /* (x - IGF_MIN_ENC_SEPARATE) + 1 */ /* encode one of the IGF_SYMBOLS_IN_TABLE == 27 alphabet symbols using the new raw AC function */ - hPrivateData->ptrBitIndex = ari_encode_14bits_ext(ptr, - hPrivateData->ptrBitIndex, - &hPrivateData->acState, - x, - (const UWord16*) cumulativeFrequencyTable - ); + hPrivateData->ptrBitIndex = ari_encode_14bits_ext( ptr, hPrivateData->ptrBitIndex, &hPrivateData->acState, (x - IGF_MIN_ENC_SEPARATE) + 1, cumulativeFrequencyTable ); return; } - - IF (sub(x, IGF_MIN_ENC_SEPARATE) < 0) + else if (x < IGF_MIN_ENC_SEPARATE) { /* send escape code 0 to indicate x <= IGF_MIN_ENC_SEPARATE - 1 */ - extra = sub(IGF_MIN_ENC_SEPARATE - 1, x); - hPrivateData->ptrBitIndex = ari_encode_14bits_ext(ptr, - hPrivateData->ptrBitIndex, - &hPrivateData->acState, - 0, - (const UWord16*) cumulativeFrequencyTable - ); + extra = (IGF_MIN_ENC_SEPARATE - 1) - x; + hPrivateData->ptrBitIndex = ari_encode_14bits_ext( ptr, hPrivateData->ptrBitIndex, &hPrivateData->acState, 0, cumulativeFrequencyTable ); } - ELSE /* x > IGF_MAX_ENC_SEPARATE */ + else { + /* x > IGF_MAX_ENC_SEPARATE */ /* send escape code (IGF_SYMBOLS_IN_TABLE - 1) to indicate x >= IGF_MAX_ENC_SEPARATE + 1 */ - extra = sub(x, IGF_MAX_ENC_SEPARATE + 1); - hPrivateData->ptrBitIndex = ari_encode_14bits_ext(ptr, - hPrivateData->ptrBitIndex, - &hPrivateData->acState, - IGF_SYMBOLS_IN_TABLE - 1, - (const UWord16*) cumulativeFrequencyTable - ); + extra = x - (IGF_MAX_ENC_SEPARATE + 1); + hPrivateData->ptrBitIndex = ari_encode_14bits_ext( ptr, hPrivateData->ptrBitIndex, &hPrivateData->acState, IGF_SYMBOLS_IN_TABLE - 1, cumulativeFrequencyTable ); } /* encode one of the tails of the distribution */ - extra_tmp = sub(extra, 15); - IF (extra_tmp < 0) + if (extra < 15) { /* encode extra with 4 bits if extra < 15 */ arith_encode_bits(hPrivateData, ptr, extra, 4); } - ELSE /* extra >= 15 */ + else { + /* extra >= 15 */ /* send escape code 15 to indicate extra >= 15 */ arith_encode_bits(hPrivateData, ptr, 15, 4); + extra -= 15; - extra_safety = sub(extra_tmp, 63); - IF (extra_safety < 0) + if (extra < 63) { /* encode additional extra with 6 bits */ - arith_encode_bits(hPrivateData, ptr, extra_tmp, 6); + arith_encode_bits(hPrivateData, ptr, extra, 6); } - ELSE { /* extra_tmp >= 63 */ + else /* extra >= 63 */ + { + arith_encode_bits(hPrivateData, ptr, 63, 6); + extra -= 63; /* encode safety extra with 7 bits */ - arith_encode_bits(hPrivateData, ptr, extra_safety, 7); + arith_encode_bits(hPrivateData, ptr, extra, 7); } } + return; } +/*---------------------------------------------------------------------* + * encode_sfe_vector() + * + * + *---------------------------------------------------------------------*/ + static void encode_sfe_vector( - IGFSCFENC_INSTANCE_HANDLE hPrivateData, /* i/o: instance handle */ - Word16 *ptr, /* i/o: pointer to expanded bit buffer, one bit in each Word16 */ - Word16 t, /* i: counter reset to 0 at each independent block */ - Word16 *prev_x, /* i: previous vector */ - Word16 *x, /* i: current vector to encode */ - Word16 length /* i: number of elements to encode */ + IGFSCFENC_INSTANCE_HANDLE hPrivateData, /**< instance handle */ + int *ptr, /**< pointer to expanded bit buffer, one bit in each int */ + int t, /**< frame counter reset to 0 at each independent frame */ + int *prev_x, /**< previous vector */ + int *x, /**< current vector to encode */ + int length, /**< number of elements to encode */ + int do_real_encoding /**< whether the real encoding is needed, otherwise only the number of bits is used */ ) { /* @@ -209,179 +192,129 @@ static void encode_sfe_vector( | c b | e --> t */ - Word16 f; - Word16 pred; - Word16 res; - Word16 ctx; - Word16 ctx_f; - Word16 ctx_t; - Word16 prev_offset; - Word32 index1; - Word32 index2; + int f; + int pred; + int ctx; + int ctx_f; + int ctx_t; + (void) do_real_encoding; /* avoid compiler warning: unreferenced formal parameter */ - FOR (f = 0; f < length; ++f) + for (f = 0; f < length; f++) { - IF (t == 0) + if (t == 0) { - IF (f == 0) + if (f == 0) { - /* (t == 0) && (f == 0) */ /* encode one of the IGF_SYMBOLS_IN_TABLE == 27 alphabet symbols using the new raw AC function */ - hPrivateData->ptrBitIndex = ari_encode_14bits_ext(ptr, - hPrivateData->ptrBitIndex, - &hPrivateData->acState, - shr(x[f], 2), - (const UWord16*) hPrivateData->cf_se00 - ); - arith_encode_bits(hPrivateData, ptr, s_and(x[f], 3), 2); /* LSBs as 2 bit raw */ + hPrivateData->ptrBitIndex = ari_encode_14bits_ext( ptr, hPrivateData->ptrBitIndex, &hPrivateData->acState, x[f] >> 2, hPrivateData->cf_se00 ); + arith_encode_bits(hPrivateData, ptr, x[f] & 3, 2); /* LSBs as 2 bit raw */ } - ELSE IF (sub(f, 1) == 0) + else if (f == 1) { - /* (t == 0) && (f == 1) */ - res = sub(x[f], x[0]); /* pred = b */ - arith_encode_residual(hPrivateData, - ptr, - res, - hPrivateData->cf_se01, - hPrivateData->cf_off_se01); + pred = x[f - 1]; /* pred = b */ + arith_encode_residual( hPrivateData, ptr, x[f] - pred, hPrivateData->cf_se01, hPrivateData->cf_off_se01 ); } - ELSE + else { - /* (t == 0) && (f >= 2) */ - prev_offset = sub(f, 1); - res = sub(x[f], x[prev_offset]); - move16(); /* pred = b */ - ctx = quant_ctx(sub(x[prev_offset], x[sub(prev_offset, 1)])); /* Q(b - e) */ - /* index1 is (IGF_SYMBOLS_IN_TABLE + 1) * (CTX_OFFSET + ctx) */ - index1 = L_mac0((IGF_SYMBOLS_IN_TABLE + 1) * IGF_CTX_OFFSET, (IGF_SYMBOLS_IN_TABLE + 1), ctx); - /* index2 is IGF_CTX_OFFSET + ctx */ - index2 = L_mac0(IGF_CTX_OFFSET, 1, ctx); - arith_encode_residual(hPrivateData, - ptr, - res, - hPrivateData->cf_se02 + index1, - hPrivateData->cf_off_se02[index2]); + /* f >= 2 */ + pred = x[f - 1]; /* pred = b */ + ctx = quant_ctx(x[f - 1] - x[f - 2]); /* Q(b - e) */ + arith_encode_residual( hPrivateData, ptr, x[f] - pred, &hPrivateData->cf_se02[(IGF_SYMBOLS_IN_TABLE + 1) * (IGF_CTX_OFFSET + ctx)], + hPrivateData->cf_off_se02[IGF_CTX_OFFSET + ctx] ); } } - ELSE + else { /* t == 1 */ - IF (f == 0) + if (f == 0) { - /* (t == 1) && (f == 0) */ - res = sub(x[f], prev_x[f]); - move16(); /* pred = a */ - arith_encode_residual(hPrivateData, - ptr, - res, - hPrivateData->cf_se10, - hPrivateData->cf_off_se10); + pred = prev_x[f]; /* pred = a */ + arith_encode_residual( hPrivateData, ptr, x[f] - pred, hPrivateData->cf_se10, hPrivateData->cf_off_se10 ); } - ELSE + else { /* (t == 1) && (f >= 1) */ - prev_offset = sub(f, 1); - pred = add(prev_x[f], x[prev_offset]); - pred = sub(pred, prev_x[prev_offset]); /* pred = a + b - c */ - res = sub(x[f], pred); - ctx_f = quant_ctx(sub(prev_x[f], prev_x[prev_offset])); /* Q(a - c) */ - ctx_t = quant_ctx(sub(x[prev_offset], prev_x[prev_offset])); /* Q(b - c) */ - /* index1 is (IGF_SYMBOLS_IN_TABLE + 1) * IGF_CTX_COUNT * (IGF_CTX_OFFSET + ctx_t) - + (IGF_SYMBOLS_IN_TABLE + 1) * (IGF_CTX_OFFSET + ctx_f) */ - index1 = L_mac0( - ((IGF_SYMBOLS_IN_TABLE + 1) * IGF_CTX_COUNT + (IGF_SYMBOLS_IN_TABLE + 1)) * IGF_CTX_OFFSET, - (IGF_SYMBOLS_IN_TABLE + 1) * IGF_CTX_COUNT, ctx_t); - index1 = L_mac0(index1, (IGF_SYMBOLS_IN_TABLE + 1), ctx_f); - /* index2 is IGF_CTX_COUNT * (IGF_CTX_OFFSET + ctx_t) + (IGF_CTX_OFFSET + ctx_f) */ - index2 = L_mac0((IGF_CTX_COUNT + 1) * IGF_CTX_OFFSET, IGF_CTX_COUNT, ctx_t); - index2 = L_mac0(index2, 1, ctx_f); - arith_encode_residual(hPrivateData, - ptr, - res, - hPrivateData->cf_se11 + index1, - hPrivateData->cf_off_se11[index2]); + pred = prev_x[f] + x[f - 1] - prev_x[f - 1]; /* pred = a + b - c */ + ctx_f = quant_ctx(prev_x[f] - prev_x[f - 1]); /* Q(a - c) */ + ctx_t = quant_ctx(x[f - 1] - prev_x[f - 1]); /* Q(b - c) */ + arith_encode_residual( hPrivateData, ptr, x[f] - pred, + &hPrivateData->cf_se11[(IGF_SYMBOLS_IN_TABLE + 1) * IGF_CTX_COUNT * (IGF_CTX_OFFSET + ctx_t) + (IGF_SYMBOLS_IN_TABLE + 1) * (IGF_CTX_OFFSET + ctx_f)], + hPrivateData->cf_off_se11[IGF_CTX_COUNT * (IGF_CTX_OFFSET + ctx_t) + (IGF_CTX_OFFSET + ctx_f)]); } } } + return; } -/**********************************************************************/ /** -resets the internal encoder memory (context memory) -**************************************************************************/ -void IGFSCFEncoderReset( - IGFSCFENC_INSTANCE_HANDLE hPublicData /* i/o: handle to public data */ +/*---------------------------------------------------------------------* + * IGFSCFEncoderReset() + * + * Reset of Arith enc context memory + *---------------------------------------------------------------------*/ + +int IGFSCFEncoderReset( + IGFSCFENC_INSTANCE_HANDLE hPublicData ) { - /* reset of coder */ - hPublicData->t = 0; - move16(); /* indicate that an independent block follows */ + hPublicData->t = 0; /* we do not need to fill hPublicData->prev with zeros, because when t = 0 no previous information is used */ + return 0; } -/**********************************************************************/ /** -main encoder function -**************************************************************************/ -Word16 IGFSCFEncoderEncode( - IGFSCFENC_INSTANCE_HANDLE hPublicData, /* i/o: handle to public data */ - Encoder_State_fx *st, /* i/o: pointer to encoder state */ - Word16 bitCount, /* i: offset to the first bit in bitbuffer which should be written by the raw AC functions */ - Word16 *sfe, /* i: pointer to an array which contains the quantized SCF energies to be encoded */ - Word16 indepFlag, /* i: 1 if the block is an independent block, 0 otherwise */ - Word16 doRealEncoding /* i: whether the real encoding is needed, otherwise only the number of bits is used */ + +/*---------------------------------------------------------------------* + * IGFSCFEncoderEncode() + * + * main IGF encoder function + *---------------------------------------------------------------------*/ + +int IGFSCFEncoderEncode( + IGFSCFENC_INSTANCE_HANDLE hPublicData, /**< inout: handle to public data or NULL in case there was no instance created */ + Encoder_State *st, /**< inout: pointer to decoder state */ + int bitCount, /**< in: offset to the first bit in bitbuffer which should be readed by iisArithDecoderDecode function */ + int *sfe, /**< in: ptr to an array which contain quantized scalefactor energies */ + int indepFlag, /**< in: if 1 on input the encoder will be forced to reset, + if 0 on input the encodder will be forced to encode without a reset */ + int doRealEncoding /**< in: whether the real encoding is needed, otherwise only the number of bits is used */ ) { - Word16 ptr[BITBUFSIZE]; /* temporary expanded bit buffer, one bit in each Word16 */ - Word16 i; - + int ptr[BITBUFSIZE]; /* temporary expanded bit buffer, one bit in each int */ + int i; /* insert data: */ hPublicData->ptrBitIndex = 0; - move16(); - hPublicData->bitCount = bitCount; - move16(); + hPublicData->bitCount = bitCount; ari_start_encoding_14bits(&hPublicData->acState); /* start AC encoding */ /* check if coder needs a reset and do it if necessary */ - IF (indepFlag != 0) + if (indepFlag) { - /* reset of coder */ - IGFSCFEncoderReset(hPublicData); + IGFSCFEncoderReset( hPublicData ); } - encode_sfe_vector(hPublicData, - ptr, - hPublicData->t, - hPublicData->prev, - sfe, - hPublicData->scfCountLongBlock - ); + encode_sfe_vector( hPublicData, ptr, hPublicData->t, hPublicData->prev, sfe, hPublicData->scfCountLongBlock, doRealEncoding ); - hPublicData->ptrBitIndex = ari_done_encoding_14bits(ptr, - hPublicData->ptrBitIndex, - &hPublicData->acState - ); /* finish AC encoding */ - hPublicData->bitCount = add(hPublicData->bitCount, hPublicData->ptrBitIndex); - - - /* advance history */ - Copy(sfe, hPublicData->prev, hPublicData->scfCountLongBlock); - hPublicData->t = add(hPublicData->t, 1); + hPublicData->ptrBitIndex = ari_done_encoding_14bits( ptr, hPublicData->ptrBitIndex, &hPublicData->acState ); /* finish AC encoding */ + hPublicData->bitCount = hPublicData->bitCount + hPublicData->ptrBitIndex; + /* advancing history: */ + mvi2i(sfe, hPublicData->prev, hPublicData->scfCountLongBlock); + hPublicData->t++; /* copy the bits from the temporary bit buffer, if doRealEncoding is enabled */ - IF (doRealEncoding != 0) + if (doRealEncoding != 0) { - FOR (i = 0; i < hPublicData->ptrBitIndex; ++i) + for (i = 0; i < hPublicData->ptrBitIndex; ++i) { - push_next_indice_fx(st, ptr[i], 1); + push_next_indice(st, ptr[i], 1); } } @@ -389,42 +322,41 @@ Word16 IGFSCFEncoderEncode( return hPublicData->bitCount; } -/**********************************************************************/ /** -for a closed loop encoder, the SCF encoder needs to memorize the context -**************************************************************************/ + +/*---------------------------------------------------------------------* + * IGFSCFEncoderSaveContextState() + * + * for a closed loop enc, the ArithEncoder needs to memorize the context + *---------------------------------------------------------------------*/ + void IGFSCFEncoderSaveContextState( - IGFSCFENC_INSTANCE_HANDLE hPublicData /* i/o: handle to public data */ + IGFSCFENC_INSTANCE_HANDLE hPublicData /**< inout: handle to public data or NULL in case there was no instance created */ ) { + hPublicData->Tsave = hPublicData->t; - hPublicData->tSave = hPublicData->t; - move16(); - - Copy(hPublicData->prev, - hPublicData->prevSave, - hPublicData->scfCountLongBlock - ); + mvi2i(hPublicData->prev, hPublicData->prevSave, hPublicData->scfCountLongBlock); + return; } -/**********************************************************************/ /** -for a closed loop encoder, the SCF encoder needs to memorize the context -**************************************************************************/ +/*---------------------------------------------------------------------* + * IGFSCFEncoderRestoreContextState() + * + * for a closed loop enc, the ArithEncoder needs to memorize the context + *---------------------------------------------------------------------*/ void IGFSCFEncoderRestoreContextState( - IGFSCFENC_INSTANCE_HANDLE hPublicData /* i/o: handle to public data */ + IGFSCFENC_INSTANCE_HANDLE hPublicData /**< inout: handle to public data or NULL in case there was no instance created */ ) { - hPublicData->t = hPublicData->tSave; - move16(); + hPublicData->t = hPublicData->Tsave; - Copy(hPublicData->prevSave, - hPublicData->prev, - hPublicData->scfCountLongBlock - ); + mvi2i(hPublicData->prevSave, hPublicData->prev, hPublicData->scfCountLongBlock); + return; } diff --git a/src/libs/libevs/lib_enc/init_enc.cpp b/src/libs/libevs/lib_enc/init_enc.cpp new file mode 100644 index 00000000..9ea27cda --- /dev/null +++ b/src/libs/libevs/lib_enc/init_enc.cpp @@ -0,0 +1,731 @@ +/*==================================================================================== + EVS Codec 3GPP TS26.443 Nov 13, 2018. Version 12.11.0 / 13.7.0 / 14.3.0 / 15.1.0 + ====================================================================================*/ + +#include "options.h" +#include "cnst.h" +#include "rom_com.h" +#include "rom_enc.h" +#include "prot.h" + + +/*-----------------------------------------------------------------------* + * init_encoder() + * + * Initialization of state variables + *-----------------------------------------------------------------------*/ + +void init_encoder( + Encoder_State *st /* i/o: Encoder static variables structure */ +) +{ + short i; + + st->nb_bits_tot = 0; + /*-----------------------------------------------------------------* + * ACELP core parameters + *-----------------------------------------------------------------*/ + + if ( st->Opt_AMR_WB ) + { + st->last_core = AMR_WB_CORE; + } + else + { + st->last_core = -1; + } + + st->L_frame = L_FRAME; + st->last_coder_type = GENERIC; + st->last_7k2_coder_type = GENERIC; + st->last_total_brate = st->total_brate; + st->last_total_brate_cng = -1; + st->last_core_brate = st->total_brate; + st->extl = -1; + st->last_extl = -1; + st->last_L_frame = L_FRAME; + st->rate_switching_reset = 0; + st->rate_switching_reset_16kHz = 0; + + mvr2r( GEWB_Ave, st->mem_AR, M ); + mvr2r( GEWB_Ave, st->lsfoldbfi0, M ); + mvr2r( GEWB_Ave, st->lsfoldbfi1, M ); + mvr2r( GEWB_Ave, st->lsf_adaptive_mean, M ); + init_lvq( st->offset_scale1, st->offset_scale2, st->offset_scale1_p, st->offset_scale2_p, st->no_scales, st->no_scales_p ); + st->next_force_safety_net = 0; + + st->pstreaklen = 0; + st->streaklimit = 1.0f; + set_f(st->mem_MA, 0, M ); + + init_gp_clip(st->clip_var); + pitch_ol_init( &st->old_thres, &st->old_pitch, &st->delta_pit, &st->old_corr) ; + + hf_cod_init( st->mem_hp400_enc, st->mem_hf_enc, st->mem_syn_hf_enc, st->mem_hf2_enc, &st->gain_alpha ); + + st->LPDmem.tilt_code = 0.0f; + st->LPDmem.gc_threshold = 0.0f; + + st->clas = UNVOICED_CLAS; + set_f( st->old_inp_12k8, 0, L_INP_MEM ); + set_f( st->old_wsp, 0, L_WSP_MEM ); + set_f( st->LPDmem.old_exc, 0, L_EXC_MEM ); + set_f( st->old_wsp2, 0, (L_WSP_MEM - L_INTERPOL)/OPL_DECIM ); + set_f( st->old_inp_16k, 0, L_INP_MEM ); + + st->mem_deemph = 0.0f; + st->mem_preemph = 0.0f; + st->mem_preemph16k = 0.0f; + st->mem_preemph_enc = 0.0; + + /* AVQ pre-quantizer memory */ + st->mem_preemp_preQ = 0.0f; + st->mem_deemp_preQ = 0.0f; + st->last_nq_preQ = 0; + st->use_acelp_preq = 0; + + /* (Decimated) Weighted Speech Memory */ + st->mem_wsp_enc = 0.0; + + set_f( st->mem_decim16k, 0, 2*L_FILT_MAX ); + st->mem_wsp = 0.0f; + st->LPDmem.mem_w0 = 0.0f; + set_f( st->LPDmem.mem_syn, 0, M ); + set_f( st->mem_syn1, 0, M ); + st->mem_deemph_old_syn = 0.0f; + set_f( st->LPDmem.mem_syn2, 0, M ); + set_f( st->mem_decim, 0, 2*L_FILT_MAX ); + set_f( st->mem_decim2, 0, 3 ); + set_f( st->Bin_E, 0, L_FFT ); + set_f( st->Bin_E_old, 0, L_FFT/2 ); + set_f( st->LPDmem.mem_syn3, 0, M ); + + st->ini_frame = 0; + st->ee_old = 10.0f; + st->Nb_ACELP_frames = 0; + st->audio_frame_cnt = AUDIO_COUNTER_INI; /* Initializatin of the audio frame counter mildly into the audio mode */ + + /* adaptive lag window memory */ + st->old_pitch_la = 0; + st->old_voicing_la = 0; + + set_f( st->mem_hp20_in, 0.0f, 4 ); + + set_f( st->dispMem, 0, 8 ); + + /* HF (6-7kHz) BWE */ + st->seed2_enc = RANDOM_INITSEED; + + for (i=0; ipast_qua_en[i] = -14.0f; /* gain quantization memory (used in AMR-WB IO mode) */ + } + + if( st->input_Fs == 8000 ) + { + st->min_band = 1; + st->max_band = 16; + } + else + { + st->min_band = 0; + st->max_band = 19; + } + + for( i=0; ifr_bands1[i] = 1e-5f; + st->fr_bands2[i] = 1e-5f; + st->ave_enr2[i] = E_MIN; + } + + if ( st->Opt_AMR_WB ) + { + mvr2r( mean_isf_amr_wb, st->lsf_old, M ); + isf2isp( st->lsf_old, st->lsp_old1, M, INT_FS_12k8 ); + } + else + { + mvr2r( GEWB_Ave, st->lsf_old, M ); + lsf2lsp( st->lsf_old, st->lsp_old1, M, INT_FS_12k8 ); + } + + mvr2r( st->lsf_old, st->lsf_old1, M ); + mvr2r( st->lsp_old1, st->lsp_old, M ); + mvr2r( st->lsp_old, st->lsp_old16k, M ); + mvr2r( st->lsp_old, st->lspold_enc, M ); + + st->stab_fac = 0.0f; + + MDCT_selector_reset( st ); + + /* Bass post-filter memories - enceder side of MODE2 */ + st->bpf_off = 0; + st->pst_mem_deemp_err = 0.0f; + st->pst_lp_ener = 0.0f; + + /* TC mode */ + st->tc_cnt = 0; + st->mCb1 = 0; + + /* AC mode */ + st->seed_tcx = 15687; + st->cor_strong_limit = 1; + set_f( st->last_exc_dct_in, 0, L_FRAME ); + st->last_ener = 0.0f; + set_s( st->last_bitallocation_band, 0, 6 ); + + st->mem_last_pit_band = BAND1k2+1; + + st->old_dE1 = 0.0f; + st->old_ind_deltaMax = 0; + set_f( st->old_enr_ssf, 0.0f, 2*NB_SSF ); + st->spike_hyst = -1; + st->music_hysteresis = 0; /* Counter of frames after AUDIO frame to prevent UC */ + st->last_harm_flag_acelp = 0; + st->GSC_noisy_speech = 0; + + /*-----------------------------------------------------------------* + * speech/music classifier + *-----------------------------------------------------------------*/ + + st->inact_cnt = 0; + set_s( st->past_dec, 0, HANG_LEN-1 ); + set_f( st->past_dlp, 0, HANG_LEN-1 ); + + for( i=0; ipast_log_enr[i] = (float)log(E_MIN); + } + + st->sp_mus_state = -8; + st->wdrop = 0.0f; + st->wdlp_0_95_sp = 0.0f; + set_f( st->last_lsp, 0.0f, M_LSP_SPMUS ); + st->last_cor_map_sum = 0.0f; + st->last_non_sta = 0.0f; + set_f( st->past_PS, 0.0f, HIGHEST_FBIN-LOWEST_FBIN ); + st->past_ps_diff = 0; + st->past_epsP2 = 01; + + st->gsc_thres[0] = TH_0_MIN; + st->gsc_thres[1] = TH_1_MIN; + st->gsc_thres[2] = TH_2_MIN; + st->gsc_thres[3] = TH_3_MIN; + set_f( st->gsc_lt_diff_etot, 0.0f, MAX_LT ); + st->gsc_mem_etot = 0.0f; + st->gsc_last_music_flag = 0; + st->gsc_nb_thr_1 = 0; + st->gsc_nb_thr_3 = 0; + st->mold_corr = 0.9f; + st->lt_gpitch = 0.0f; + st->mean_avr_dyn = 0.5f; + st->last_sw_dyn = 10.0f; + st->pit_exc_hangover = 0; + st->Last_pulse_pos = 0; + + /* speech/music classifier improvement */ + for ( i=0; ibuf_flux[i] = -100; + st->buf_pkh[i] = 0; + st->buf_epsP_tilt[i] = 0; + st->buf_cor_map_sum[i] = 0; + st->buf_Ntonal[i] = 0; + st->buf_Ntonal2[i] = 0; + st->buf_Ntonal_lf[i] = 0; + } + + set_f( st->lpe_buf, 0, HANG_LEN_INIT ); + set_f( st->voicing_buf, 0, HANG_LEN_INIT ); + st->gsc_hangover = 0; + set_f( st->sparse_buf, 0, HANG_LEN_INIT ); + set_f( st->hf_spar_buf, 0, HANG_LEN_INIT ); + st->LT_sparse = 0.0f; + st->gsc_cnt = 0; + st->last_vad_spa = 0; + + set_f( st->old_Bin_E, 0.0f, 3*N_OLD_BIN_E ); + set_f( st->buf_etot, 0, 4 ); + set_f( st->buf_dlp, 0, 10 ); + + st->UV_cnt1 = 300; + st->LT_UV_cnt1 = 250.0f; + st->onset_cnt = 0; + st->attack_hangover = 0; + st->dec_mov = 0.0f; + st->dec_mov1 = 0.0f; + st->mov_log_max_spl = 200.0f; + st->old_lt_diff[0] = 0.0f; + st->old_lt_diff[1] = 0.0f; + + st->Etot_h = 0.0f; + st->Etot_l = 0.0f; + st->Etot_l_lp = 0.0f; + st->Etot_last = 0.0f; + st->Etot_v_h2 = 0.0f; + st->sign_dyn_lp = 0.0f; + + /*-----------------------------------------------------------------* + * GSC + *-----------------------------------------------------------------*/ + + /* GSC - pitch excitation parameters */ + st->mem_w0_tmp = 0.0f; + set_f(st->mem_syn_tmp, 0.0f, M); + st->high_stable_cor = 0; + set_f(st->var_cor_t, 0.0f, VAR_COR_LEN); + + st->lps = 0.0f; + st->lpm = 0.0f; + st->Last_frame_ener = (float)MAX_32; + st->lt_dec_thres = 10.0f; + st->ener_RAT = 0.0f; + st->mid_dyn = 40.0f; + st->noise_lev = NOISE_LEVEL_SP0; + st->past_dyn_dec = 0; + + /*-----------------------------------------------------------------* + * VAD & noise estimator + *-----------------------------------------------------------------*/ + + wb_vad_init( &st->nb_active_frames, &st->hangover_cnt, &st->lp_speech, &st->nb_active_frames_he, &st->hangover_cnt_he, + &st->bcg_flux, &st->soft_hangover, &st->voiced_burst, &st->bcg_flux_init, &st->nb_active_frames_he1, &st->hangover_cnt_he1, + &st->vad_flag_reg_H, &st->vad_flag_reg_L, &st->vad_prim_reg, &st->vad_flag_cnt_50, &st->vad_prim_cnt_16, + &st->hangover_cnt_dtx, &st->flag_noisy_speech_snr, &st->hangover_cnt_music ); + + st->nb_active_frames_HE_SAD = 0; + + /* Noise estimator */ + noise_est_init( &st->totalNoise, &st->first_noise_updt, st->bckr, st->enrO, st->ave_enr, &st->pitO, &st->aEn, + &st->harm_cor_cnt, &st->bg_cnt, &st->lt_tn_track, &st->lt_tn_dist, + &st->lt_Ellp_dist,&st->lt_haco_ev,&st->low_tn_track_cnt + ,&st->Etot_st_est,&st->Etot_sq_st_est + ); + + st->epsP_0_2_lp = 1.0f; + st->epsP_0_2_ad_lp = 0.0f; + st->epsP_2_16_lp = 1.0f; + st->epsP_2_16_lp2 = 1.0f; + st->epsP_2_16_dlp_lp = 0.0f; + st->epsP_2_16_dlp_lp2 = 0.0f; + st->lt_aEn_zero = 0.0f; + st->prim_act_quick = 0.0f; + st->prim_act_slow = 0.0f; + st->prim_act = 0.0f; + st->prim_act_quick_he = 0.0f; + st->prim_act_slow_he = 0.0f; + st->prim_act_he = 0.0f; + st->bckr_tilt_lt = 0.f; + + /*-----------------------------------------------------------------* + * WB, SWB and FB bandwidth detector + *-----------------------------------------------------------------*/ + + st->lt_mean_NB = 0; + st->lt_mean_WB = 0; + st->lt_mean_SWB = 0; + st->count_WB = BWD_COUNT_MAX; + st->count_SWB = BWD_COUNT_MAX; + st->count_FB = BWD_COUNT_MAX; + st->bwidth = st->max_bwidth; + st->last_input_bwidth = st->bwidth; + st->last_bwidth = st->bwidth; + st->last_bwidth_cng = st->bwidth; + + /*-----------------------------------------------------------------* + * + *-----------------------------------------------------------------*/ + + /* Tonal detector */ + for ( i=0; iold_S[i] = 1; + } + set_f(st->cor_map, 0, L_FFT/2 ); + st->act_pred = 1; + st->noise_char = 0; + st->multi_harm_limit = THR_CORR; + st->coder_type_raw = VOICED; + st->last_coder_type_raw = st->coder_type_raw; + + /* Stationary noise UV modification */ + st->ge_sm = 10; + st->uv_count = 0; + st->act_count = 3; + mvr2r(st->lsp_old, st->lspold_s, M); + st->noimix_seed = RANDOM_INITSEED; + st->min_alpha = 1; + st->exc_pe = 0; + + /*-----------------------------------------------------------------* + * CNG and DTX + *-----------------------------------------------------------------*/ + + st->lp_noise = 0.0f; + mvr2r( st->lsp_old1, st->lspCNG, M ); + st->cng_seed = RANDOM_INITSEED; + st->cng_ener_seed = RANDOM_INITSEED; + st->cng_ener_seed1 = RANDOM_INITSEED; + st->lp_ener = 0.0f; + st->first_CNG = 0; + st->cnt_SID = 0; + st->max_SID = 2; + st->old_enr_index = -1; + st->Enew = 0.0f; + st->VarDTX_cnt_voiced = 0; + st->lt_ener_voiced = 0.0f; + st->VarDTX_cnt_noise = 0; + st->lt_ener_noise = 0.0f; + st->lt_ener_last_SID = 0.0f; + if( st->var_SID_rate_flag ) + { + st->interval_SID = 12; + } + st->lp_sp_enr = 0.0f; + st->last_allow_cn_step = 0; + + st->fd_cng_reset_flag = 0; + + if( st->Opt_DTX_ON ) + { + st->cng_hist_ptr = -1; + set_f( st->cng_lsp_hist, 0, DTX_HIST_SIZE*M ); + set_f( st->cng_ener_hist, 0, DTX_HIST_SIZE ); + st->cng_cnt = 0; + st->ho_hist_ptr = -1; + st->ho_sid_bw = 0; + set_f( st->ho_lsp_hist, 0, HO_HIST_SIZE*M ); + set_f( st->ho_ener_hist, 0, HO_HIST_SIZE ); + set_f( st->ho_env_hist, 0, HO_HIST_SIZE*NUM_ENV_CNG ); + st->ho_hist_size = 0; + st->act_cnt = 0; + } + + st->active_cnt = 0; + st->cng_type = -1; + + st->CNG_mode = -1; + st->last_active_brate = ACELP_7k20; + st->last_CNG_L_frame = L_FRAME; + set_s( st->ho_16k_lsp, 0, HO_HIST_SIZE ); + st->act_cnt2 = 0; + st->num_ho = 0; + st->hangover_terminate_flag = 0; + + st->ho_circ_ptr = -1; + set_f( st->ho_lsp_circ, 0, HO_HIST_SIZE*M ); + set_f( st->ho_ener_circ, 0, HO_HIST_SIZE ); + set_f( st->ho_env_circ, 0, HO_HIST_SIZE*NUM_ENV_CNG ); + st->ho_circ_size = 0; + st->burst_ho_cnt = 0; + st->cng_buf_cnt = 0; + + if( st->var_SID_rate_flag || ((!st->var_SID_rate_flag) && (st->interval_SID >= DTX_HIST_SIZE)) ) + { + st->cng_hist_size = DTX_HIST_SIZE; + } + else + { + st->cng_hist_size = st->interval_SID; + } + set_f(st->lp_env, 0.0f, 20); + set_f(st->cng_res_env, 0.0f, 20*8); + set_f(st->exc_mem, 0.0f, 24); + set_f(st->exc_mem1, 0.0f, 30); + set_f(st->exc_mem2, 0.0f, 30); + set_f(st->old_env, 0.0f, NUM_ENV_CNG); + /* SWB CNG/DTX */ + st->last_wb_cng_ener = -6.02f; + st->last_shb_cng_ener = -6.02f; + st->mov_wb_cng_ener = -6.02f; + st->mov_shb_cng_ener = -6.02f; + st->shb_cng_ini_cnt = 1; + st->shb__NO_DATA_cnt = 0; + st->last_SID_bwidth = min( st->max_bwidth, SWB ); + st->last_vad = 0; + /* FEC */ + st->last_clas = UNVOICED_CLAS; + + for (i=0; i<2*NB_SUBFR16k; i++) + { + st->old_pitch_buf[i] = L_SUBFR; + } + + st->old_Es_pred = 0; + set_f( st->old_Aq_12_8 + 1, 0, M ); + st->old_Aq_12_8[0] = 1; + + /*-----------------------------------------------------------------* + * CLDFB & resampling tools parameters + *-----------------------------------------------------------------*/ + + openCldfb( &st->cldfbAnaEnc, CLDFB_ANALYSIS, st->input_Fs ); + + st->currEnergyLookAhead = 6.1e-5f; + + /*-----------------------------------------------------------------* + * SC-VBR parameters + *-----------------------------------------------------------------*/ + + st->nelp_enc_seed = 0; + st->last_nelp_mode = 0; + st->pppcountE = 0; + st->last_ppp_mode = 0; + st->last_last_ppp_mode = 0; + st->firstTime_voicedenc = 1; + st->prev_ppp_gain_pit = 0.0; + st->prev_tilt_code = 0.0; + + st->ppp_mode = 0; + st->nelp_mode = 0; + + /* stable short pitch detection */ + st->voicing0_sm = 0; + st->voicing_sm = 0; + st->LF_EnergyRatio_sm = 1; + st->predecision_flag = 0; + st->diff_sm = 0; + st->energy_sm = 0; + + st->pattern_m = 0; + st->Last_Resort = 0; + st->set_ppp_generic = 0; + st->Q_to_F = 0; + + st->numactive = 0; /* keep the count of the frames inside current 600 frame bloack.*/ + st->sum_of_rates = 0.0f; /* sum of the rates of past 600 active frames*/ + st->global_avr_rate = 0.0f; /* global rate upto current time. recorded a (rate in kbps) *6000*/ + st->global_frame_cnt = 0; /* 600 active frame block count. Used to update the global rate*/ + + st->rate_control = 0; + st->SNR_THLD = 67.0f; + st->mode_QQF = 1; + st->last_Opt_SC_VBR = 0; + + set_f(st->shape1_filt_mem, 0, 20); + set_f(st->shape2_filt_mem, 0, 20); + set_f(st->shape3_filt_mem, 0, 20); + set_f(st->txlpf1_filt1_mem, 0, 20); + set_f(st->txlpf1_filt2_mem, 0, 20); + set_f(st->txhpf1_filt1_mem, 0, 20); + set_f(st->txhpf1_filt2_mem, 0, 20); + + /*-----------------------------------------------------------------* + * SWB BWE parameters + *-----------------------------------------------------------------*/ + + set_f( st->new_input_hp, 0, NS2SA(16000, ACELP_LOOK_NS + DELAY_FD_BWE_ENC_12k8_NS + DELAY_FIR_RESAMPL_NS - DELAY_CLDFB_NS)); + set_f( st->old_input, 0, NS2SA(48000, DELAY_FD_BWE_ENC_12k8_NS + DELAY_FIR_RESAMPL_NS) ); + set_f( st->old_input_wb, 0, NS2SA(16000, DELAY_FD_BWE_ENC_12k8_NS) ); + set_f( st->old_input_lp, 0, NS2SA(16000, ACELP_LOOK_NS + DELAY_FD_BWE_ENC_16k_NS) ); + set_f( st->old_syn_12k8_16k, 0, NS2SA(16000, DELAY_FD_BWE_ENC_NS) ); + + st->prev_mode = NORMAL; + set_f( st->old_wtda_swb, 0, L_FRAME48k ); + st->prev_L_swb_norm1 = 8; + st->prev_global_gain = 0.0f; + st->modeCount = 0; + st->EnergyLF = 0.0f; + + + /*-----------------------------------------------------------------* + * TBE parameters + *-----------------------------------------------------------------*/ + + InitSWBencBuffer(st); + ResetSHBbuffer_Enc(st); + set_f( st->old_speech_shb, 0.0f, L_LOOK_16k + L_SUBFR16k ); + set_f( st->old_speech_wb, 0.0f, (L_LOOK_12k8 + L_SUBFR) * 5/16 ); + set_f( st->old_input_fhb, 0.0f, NS2SA(48000, ACELP_LOOK_NS + DELAY_FD_BWE_ENC_12k8_NS + DELAY_FIR_RESAMPL_NS) - L_FRAME48k/2); + + for( i=0; i < LPC_SHB_ORDER; i++ ) + { + st->prev_lsp_shb[i] = i/20.0f; + } + + st->cldfbHBLT = 1.0f; + st->prev_gainFr_SHB = 0; + set_f( st->lsp_shb_slow_interpl, 0, LPC_SHB_ORDER ); + set_f( st->lsp_shb_fast_interpl, 0, LPC_SHB_ORDER ); + set_f( st->shb_inv_filt_mem, 0, LPC_SHB_ORDER ); + set_f( st->lsp_shb_spacing, 0.1f, 3); + st->prev_swb_GainShape = 0; + st->prev_frGainAtten = 0; + st->prev_wb_GainShape = 0; + set_f(st->fb_state_lpc_syn, 0, LPC_SHB_ORDER); + st->fb_tbe_demph = 0.0f; + st->tilt_mem = 0.0f; + + openCldfb( &st->cldfbSynTd, CLDFB_SYNTHESIS, 16000); + + st->prev_coder_type = GENERIC; + set_f( st->prev_lsf_diff, 0.5f, LPC_SHB_ORDER-2 ); + st->prev_tilt_para = 0.0f; + set_f( st->cur_sub_Aq, 0.0f, M+1 ); + + /* TD BWE post-processing */ + st->ptr_mem_stp_swb = st->mem_stp_swb + LPC_SHB_ORDER - 1; + set_f( st->mem_zero_swb, 0, LPC_SHB_ORDER ); + + for( i=0; iswb_lsp_prev_interp[i] = (float)cos( (float)i * EVS_PI / (float)10.0f ); + } + + set_f( st->dec_2_over_3_mem, 0.0f, 12 ); + set_f( st->dec_2_over_3_mem_lp, 0.0f, 6 ); + set_f( st->old_fdbwe_speech, 0.0f, L_FRAME48k ); + + /*-----------------------------------------------------------------* + * HQ core parameters + *-----------------------------------------------------------------*/ + + st->input = st->input_buff+L_FRAME48k+NS2SA(48000, DELAY_FIR_RESAMPL_NS); + set_zero( st->input_buff+L_FRAME48k, L_FRAME48k+NS2SA(48000, DELAY_FIR_RESAMPL_NS) ); + st->old_input_signal = st->input - NS2SA(st->input_Fs, DELAY_FIR_RESAMPL_NS) - (short)(st->input_Fs / 50); + + st->old_hpfilt_in = 0.0f; + st->old_hpfilt_out = 0.0f; + st->EnergyLT = 0.0f; + st->Energy_Old = 0; + st->TransientHangOver = 0; + + set_f( st->old_out, 0, L_FRAME32k ); + + st->mode_count = 0; + st->mode_count1 = 0; + + st->hq_generic_speech_class = 0; + st->prev_Npeaks = 0; + set_s( st->prev_peaks, 0, HVQ_MAX_PEAKS ); + st->hvq_hangover = 0; + st->prev_hqswb_clas = HQ_NORMAL; + set_s( st->prev_SWB_peak_pos, 0, SPT_SHORTEN_SBNUM ); + st->clas_sec_old = 1.0f; + st->clas_final_old = 1; + st->last_gain1 = 0.0f; + st->last_gain2 = 0.0f; + + /* speech/music classification */ + set_s( st->lt_old_mode, 1, 3 ); + st->lt_voicing = 0.5f; + st->lt_corr = 0.5f; + st->lt_tonality = 0; + set_s( st->lt_corr_pitch, 0, 3 ); + st->lt_hangover = 0; + st->lowrate_pitchGain = 0; + + st->lt_music_hangover = 0; + set_f( st->tonality2_buf, 0, HANG_LEN_INIT ); + set_f( st->tonality3_buf, 0, HANG_LEN_INIT ); + set_f( st->LPCErr_buf, 0,HANG_LEN_INIT ); + st->lt_music_state = 0; + st->lt_speech_state = 0; + st->lt_speech_hangover = 0; + st->consec_inactive = 0; + st->spectral_tilt_reset = 1; + st->running_avg = 0; + st->ra_deltasum = 0; + st->trigger_SID = 0; + st->snr_sum_vad = 0; + + set_s( st->prev_frm_index, -1, NB_SWB_SUBBANDS_HAR_SEARCH_SB ); + st->prev_frm_hfe2 = 0; + st->prev_stab_hfe2 = 0; + st->prev_ni_ratio = 0.5f; + set_f( st->prev_En_sb, 0.0f, NB_SWB_SUBBANDS ); + set_s( st->last_bitalloc_max_band, 0, 2 ); + set_f( st->last_ni_gain, 0, BANDS_MAX ); + set_f( st->last_env, 0, BANDS_MAX ); + st->last_max_pos_pulse = 0; + + + /*-----------------------------------------------------------------* + * Channel-aware mode + *-----------------------------------------------------------------*/ + + if( !st->Opt_RF_ON || (st->bwidth != WB && st->bwidth != SWB) || st->total_brate != ACELP_13k20 ) + { + if ( st->Opt_RF_ON ) + { + printf("\nWarning: Channel-aware mode only available for 13.2 kbps WB/SWB\n"); + printf(" Switched to normal mode!\n"); + st->Opt_RF_ON = 0; + st->rf_fec_offset = 0; + } + st->rf_mode = 0; + } + else + { + st->rf_mode = st->Opt_RF_ON; + } + + st->rf_mode_last = st->rf_mode; + + /* initialize RF indice buffers */ + reset_rf_indices( st ); + + /*-----------------------------------------------------------------* + * Mode 2 initialization + *-----------------------------------------------------------------*/ + + st->last_sr_core = st->last_L_frame * 50; + + if( st->codec_mode == MODE2 ) + { + st->igf = getIgfPresent( st->total_brate, st->bwidth, st->rf_mode ); + } + else + { + st->igf = 0; + } + + /* FD-CNG encoder */ + createFdCngEnc( &st->hFdCngEnc ); + initFdCngEnc( st->hFdCngEnc, st->input_Fs, st->cldfbAnaEnc->scale ); + configureFdCngEnc( st->hFdCngEnc, st->bwidth, st->rf_mode&&st->total_brate==13200?9600:st->total_brate ); + + /* INIT CORE CODER */ + + st->last_totalNoise = 0.f; + set_f( st->totalNoise_increase_hist, 0.f, TOTALNOISE_HIST_SIZE ); + st->totalNoise_increase_len = 0; + + init_coder_ace_plus( st ); + + InitTransientDetection( (int)(st->input_Fs / 50), NS2SA(st->input_Fs, DELAY_FIR_RESAMPL_NS), &st->transientDetection ); + + reset_indices_enc( st ); + + + st->vbr_generic_ho = 0; + + st->sharpFlag = 0; + + st->Local_VAD = 0; + set_f( st->nelp_lp_fit_mem, 0, NELP_LP_ORDER*2 ); + + return; +} + + + +/*-----------------------------------------------------------------------* + * destroy_encoder() + * + * Free memory which was allocated in init_encoder() + *-----------------------------------------------------------------------*/ + +void destroy_encoder( + Encoder_State *st /* i/o: Encoder static variables structure */ +) +{ + deleteCldfb( &st->cldfbSynTd ); + deleteCldfb( &st->cldfbAnaEnc ); + deleteFdCngEnc( &st->hFdCngEnc ); + + /* Close Core */ + + return; +} diff --git a/src/libs/libevs/lib_enc/init_enc_fx.cpp b/src/libs/libevs/lib_enc/init_enc_fx.cpp deleted file mode 100755 index cafabf70..00000000 --- a/src/libs/libevs/lib_enc/init_enc_fx.cpp +++ /dev/null @@ -1,1008 +0,0 @@ -/*==================================================================================== - EVS Codec 3GPP TS26.442 Apr 03, 2018. Version 12.11.0 / 13.6.0 / 14.2.0 - ====================================================================================*/ - -#include "options.h" /* Compilation switches */ -#include "cnst_fx.h" /* Common constants */ -#include "rom_com_fx.h" /* Static table prototypes */ -#include "prot_fx.h" /* Function prototypes */ -#include "stl.h" - - -/*-----------------------------------------------------------------------* - * init_encoder_fx() - * - * Initialization of state variables - *-----------------------------------------------------------------------*/ -void init_encoder_fx( - Encoder_State_fx *st_fx /* i/o: Encoder static variables structure */ -) -{ - Word16 i; - Word32 L_tmp; - - st_fx->nb_bits_tot_fx = 0; - move16(); - /*-----------------------------------------------------------------* - * ACELP core parameters - *-----------------------------------------------------------------*/ - st_fx->last_core_fx = -1; - move16(); - if ( st_fx->Opt_AMR_WB_fx ) - { - st_fx->last_core_fx = AMR_WB_CORE; - move16(); - } - - st_fx->L_frame_fx = L_FRAME; - move16(); - st_fx->last_coder_type_fx = GENERIC; - move16(); - st_fx->last_7k2_coder_type_fx = GENERIC; - move16(); - st_fx->last_total_brate_fx = st_fx->total_brate_fx; - move32(); - st_fx->last_total_brate_cng_fx = -1; - move32(); - st_fx->last_core_brate_fx = st_fx->total_brate_fx; - move32(); - st_fx->extl_fx = -1; - move16(); - st_fx->last_extl_fx = -1; - move16(); - st_fx->last_L_frame_fx = L_FRAME; - move16(); - st_fx->rate_switching_reset = 0; - move16(); - st_fx->rate_switching_reset_16kHz = 0; - move16(); - Copy( GEWB_Ave_fx, st_fx->mem_AR_fx, M ); - Copy( GEWB_Ave_fx, st_fx->lsfoldbfi0_fx, M ); - Copy( GEWB_Ave_fx, st_fx->lsfoldbfi1_fx, M ); - Copy( GEWB_Ave_fx, st_fx->lsf_adaptive_mean_fx, M ); - init_lvq_fx( st_fx->offset_scale1_fx, st_fx->offset_scale2_fx, st_fx->offset_scale1_p_fx, st_fx->offset_scale2_p_fx, st_fx->no_scales_fx, st_fx->no_scales_p_fx ); - st_fx->next_force_safety_net_fx = 0; - - st_fx->pstreaklen_fx = 0; - move16(); - st_fx->streaklimit_fx = 32767; - move16(); /*1;//Q15 */ - set16_fx( st_fx->mem_MA_fx, 0, M ); - - init_gp_clip_fx( st_fx->clip_var_fx ); - pitch_ol_init_fx( &st_fx->old_thres_fx, &st_fx->old_pitch, &st_fx->delta_pit_fx, &st_fx->old_corr_fx ) ; - - hf_cod_init_fx( st_fx->mem_hp400_enc_fx, st_fx->mem_hf_enc_fx, st_fx->mem_syn_hf_enc_fx, st_fx->mem_hf2_enc_fx, &st_fx->gain_alpha_fx ); - - st_fx->LPDmem.tilt_code = 0; - move16(); - st_fx->LPDmem.gc_threshold = 0; - move16(); - - st_fx->clas_fx = UNVOICED_CLAS; - move16(); - set16_fx( st_fx->old_inp_12k8_fx, 0, L_INP_MEM); /* memory of input signal at 12.8kHz */ - set16_fx( st_fx->old_wsp_fx, 0, L_WSP_MEM ); - set16_fx( st_fx->LPDmem.old_exc, 0, L_EXC_MEM ); - set16_fx( st_fx->old_wsp2_fx, 0, (L_WSP_MEM - L_INTERPOL)/OPL_DECIM ); - set16_fx( st_fx->old_inp_16k_fx, 0, L_INP_MEM ); - - st_fx->mem_deemph_fx = 0; - move16(); - st_fx->mem_preemph_fx = 0; - move16(); - st_fx->mem_preemph16k_fx = 0; - move16(); - st_fx->mem_preemph_enc = 0; - move16(); - - /* AVQ pre-quantizer memory */ - st_fx->mem_preemp_preQ_fx = 0; - move16(); - st_fx->mem_deemp_preQ_fx = 0; - move16(); - st_fx->last_nq_preQ_fx = 0; - move16(); - st_fx->use_acelp_preq = 0; - move16(); - - /* (Decimated) Weighted Speech Memory */ - st_fx->mem_wsp_enc = 0; - move16(); - - set16_fx( st_fx->mem_decim16k_fx, 0, 2*L_FILT_MAX ); - st_fx->mem_wsp_fx = 0; - move16(); - st_fx->LPDmem.mem_w0 = 0; - move16(); - set16_fx( st_fx->LPDmem.mem_syn, 0, M ); - set16_fx( st_fx->mem_syn1_fx, 0, M ); - st_fx->mem_deemph_old_syn_fx = 0; - move16(); - set16_fx( st_fx->LPDmem.mem_syn2, 0, M ); - set16_fx( st_fx->mem_decim_fx, 0, 2*L_FILT_MAX ); - set16_fx( st_fx->mem_decim2_fx, 0, 3 ); - set32_fx( st_fx->Bin_E_fx, 0, L_FFT ); - set16_fx( st_fx->lgBin_E_fx, 0, L_FFT/2 ); - set32_fx( st_fx->Bin_E_old_fx, 0, L_FFT/2 ); - set16_fx( st_fx->LPDmem.mem_syn3, 0, M ); - - st_fx->ini_frame_fx = 0; - move16(); - st_fx->ee_old_fx = 640; - move32();/*chk //10 in Q6 */ - st_fx->Nb_ACELP_frames_fx = 0; - move16(); - st_fx->audio_frame_cnt_fx = AUDIO_COUNTER_INI; - move16();/* Initializatin of the audio frame counter mildly into the audio mode */ - - /* adaptive lag window memory */ - st_fx->old_pitch_la = 0; - move16(); - st_fx->old_voicing_la = 0; - move16(); - set32_fx( st_fx->mem_hp20_in_fx, 0, 5 ); - - st_fx->Last_Resort_fx = 0; - st_fx->set_ppp_generic_fx = 0; - - st_fx->dm_fx.prev_state = 0; - move16(); /* This corresponds to st_fx->dispMem in FLP */ - st_fx->dm_fx.prev_gain_code = 0; - move32(); - - FOR(i=2; i<8; i++) - { - st_fx->dm_fx.prev_gain_pit[i-2] = 0; - move16(); - } - - st_fx->seed2_enc_fx = RANDOM_INITSEED; - move16(); - - - st_fx->old_hpfilt_in_fx = 0; - move16(); - st_fx->old_hpfilt_out_fx = 0; - move16(); - st_fx->EnergyLT_fx = 0; - move32(); - st_fx->prev_Q_new = 0; - move16(); - - - FOR (i=0; ipast_qua_en_fx[i] = -14336; /* Q10gain quantization memory (used also in AMR-WB IO mode) */ - } - - IF( L_sub(st_fx->input_Fs_fx,8000) == 0 ) - { - st_fx->min_band_fx = 1; - move16(); - st_fx->max_band_fx = 16; - move16(); - } - ELSE - { - st_fx->min_band_fx = 0; - move16(); - st_fx->max_band_fx = 19; - move16(); - } - - FOR( i=0; ifr_bands1_fx[i] = 1; - move32();/*1e-5f; */ - st_fx->fr_bands2_fx[i] = 1; - move32();/*1e-5f; */ - st_fx->ave_enr2_fx[i] = E_MIN_FX; - move32(); /*Q7//E_MIN; */ - } - IF ( st_fx->Opt_AMR_WB_fx ) - { - Copy( mean_isf_amr_wb_fx, st_fx->lsf_old_fx, M ); - E_LPC_isf_isp_conversion( st_fx->lsf_old_fx, st_fx->lsp_old1_fx, M); - } - ELSE - { - Copy( GEWB_Ave_fx, st_fx->lsf_old_fx, M ); - lsf2lsp_fx( st_fx->lsf_old_fx, st_fx->lsp_old1_fx, M, INT_FS_FX); - } - - Copy( st_fx->lsf_old_fx, st_fx->lsf_old1_fx, M ); - Copy( st_fx->lsp_old1_fx, st_fx->lsp_old_fx, M ); - Copy( st_fx->lsp_old_fx, st_fx->lsp_old16k_fx, M ); - Copy( st_fx->lsp_old_fx, st_fx->lspold_enc_fx, M ); - - st_fx->stab_fac_fx = 0; - move16(); - - MDCT_selector_reset(st_fx); - - /* Bass post-filter memories - encoder side of MODE2 */ - st_fx->bpf_off_fx = 0; - move16(); - - /* TC mode */ - st_fx->tc_cnt_fx = 0; - move16(); - st_fx->mCb1_fx = 0; - move16(); - - /* AC mode */ - st_fx->seed_tcx_fx = 15687; - move16(); - st_fx->cor_strong_limit_fx = 1; - move16(); - set16_fx( st_fx->last_exc_dct_in_fx, 0, L_FRAME ); - st_fx->last_ener_fx = 0; - set16_fx( st_fx->last_bitallocation_band_fx, 0, 6 ); - - st_fx->mem_last_pit_band_fx = BAND1k2+1; - move16(); - - st_fx->old_dE1_fx = 0; - move16(); - st_fx->old_ind_deltaMax_fx = 0; - move32(); - set32_fx( st_fx->old_enr_ssf_fx, 0, 2*NB_SSF ); - st_fx->spike_hyst_fx = -1; - move16(); - st_fx->music_hysteresis_fx = 0; - move16(); /* Counter of frames after AUDIO frame to prevent UC */ - st_fx->last_harm_flag_acelp_fx = 0; - move16(); - st_fx->GSC_noisy_speech_fx = 0; - move16(); - - /* speech/music classifier */ - st_fx->inact_cnt_fx = 0; - move16(); - set16_fx(st_fx->past_dec_fx, 0, HANG_LEN-1 ); - set16_fx(st_fx->past_dlp_fx, 0, HANG_LEN-1 ); - set16_fx(st_fx->past_log_enr_fx, -1448, NB_BANDS_SPMUS); /* log(E_MIN) in Q8 */ - - st_fx->sp_mus_state_fx = -8; - move16(); - st_fx->wdrop_fx = 0; - move16(); - st_fx->wdlp_0_95_sp_fx = 0; - move16(); - set16_fx( st_fx->last_lsp_fx, 0, M_LSP_SPMUS ); - st_fx->last_cor_map_sum_fx = 0; - move16(); - st_fx->last_non_sta_fx = 0; - move16(); - set32_fx( st_fx->past_PS_fx, 0, HIGHEST_FBIN-LOWEST_FBIN ); - st_fx->past_ps_diff_fx = 0; - move16(); - st_fx->past_epsP2_fx = 1024; - move16(); - - - st_fx->gsc_thres_fx[0] = TH_0_MIN_FX; - move16(); - st_fx->gsc_thres_fx[1] = TH_1_MIN_FX; - move16(); - st_fx->gsc_thres_fx[2] = TH_2_MIN_FX; - move16(); - st_fx->gsc_thres_fx[3] = TH_3_MIN_FX; - move16(); - set16_fx(st_fx->gsc_lt_diff_etot_fx, 0, 40); - st_fx->gsc_mem_etot_fx = 0; - move16(); - st_fx->gsc_last_music_flag_fx = 0; - move16(); - st_fx->gsc_nb_thr_1_fx = 0; - move16(); - st_fx->gsc_nb_thr_3_fx = 0; - move16(); - st_fx->mold_corr_fx = 29491; - move16(); - st_fx->lt_gpitch_fx = 0; - move16(); - st_fx->mean_avr_dyn_fx = 64; - move16();/*Q7 */ - st_fx->last_sw_dyn_fx = 2560; - move16(); - st_fx->pit_exc_hangover = 0; - move16(); - st_fx->Last_pulse_pos_fx = 0; - move16(); - - /* speech/music classifier improvement */ - FOR ( i=0; ibuf_flux_fx[i] = -12800; - move16(); /*-100.0 in Q7 */ - st_fx->buf_pkh_fx[i] = 0; - move16(); - st_fx->buf_epsP_tilt_fx[i] = 0; - move16(); - st_fx->buf_cor_map_sum_fx[i] = 0; - move16(); - st_fx->buf_Ntonal_fx[i] = 0; - move16(); - st_fx->buf_Ntonal2_fx[i] = 0; - move16(); - st_fx->buf_Ntonal_lf_fx[i] = 0; - move16(); - } - - set16_fx(st_fx->lpe_buf_fx, 0, HANG_LEN_INIT); - set16_fx(st_fx->voicing_buf_fx, 0, HANG_LEN_INIT); - st_fx->gsc_hangover_fx = 0; - move16(); - set16_fx(st_fx->sparse_buf_fx, 0, HANG_LEN_INIT); - set16_fx(st_fx->hf_spar_buf_fx, 0, HANG_LEN_INIT); - st_fx->LT_sparse_fx = 0; - move16(); - st_fx->gsc_cnt_fx = 0; - move16(); - st_fx->last_vad_spa_fx = 0; - move16(); - - set16_fx( st_fx->old_Bin_E_fx, 0, 3*N_OLD_BIN_E ); - set16_fx( st_fx->buf_etot_fx, 0, 4 ); - set16_fx( st_fx->buf_dlp_fx, 0, 10 ); - - st_fx->UV_cnt1_fx = 300; - move16(); - st_fx->LT_UV_cnt1_fx = 16000; - move16(); /*250.0f in Q6 */ - st_fx->onset_cnt_fx = 0; - move16(); - st_fx->attack_hangover_fx = 0; - move16(); - st_fx->dec_mov_fx = 0; - move16(); - st_fx->dec_mov1_fx = 0; - move16(); - st_fx->mov_log_max_spl_fx = 25600; - move16(); /*200.0 in Q7 */ - st_fx->old_lt_diff_fx[0] = 0; - move16(); - st_fx->old_lt_diff_fx[1] = 0; - move16(); - - /* GSC - pitch excitation parameters */ - st_fx->mem_w0_tmp_fx = 0; - move16(); - set16_fx(st_fx->mem_syn_tmp_fx, 0, M); - st_fx->high_stable_cor_fx = 0; - move16(); - set16_fx(st_fx->var_cor_t_fx, 0, VAR_COR_LEN); - - st_fx->lps_fx = 0; - move16(); - st_fx->lpm_fx = 0; - move16(); - st_fx->Last_frame_ener_fx = MAX_32; - move32(); - st_fx->lt_dec_thres_fx = 5120; - move16(); /*10 in Q9 */ - st_fx->ener_RAT_fx = 0; - move16(); - st_fx->mid_dyn_fx = 5120; - move16(); /*40 -> Q7 */ - st_fx->noise_lev_fx = NOISE_LEVEL_SP0; - move16(); - st_fx->past_dyn_dec_fx = 0; - move16(); - - wb_vad_init_fx( &st_fx->nb_active_frames_fx, &st_fx->hangover_cnt_fx, &st_fx->lp_speech_fx, &st_fx->nb_active_frames_he_fx, - &st_fx->hangover_cnt_he_fx, &st_fx->bcg_flux_fx, &st_fx->soft_hangover_fx, &st_fx->voiced_burst_fx, - &st_fx->bcg_flux_init_fx, &st_fx->nb_active_frames_he1_fx, &st_fx->hangover_cnt_he1_fx, - &st_fx->L_vad_flag_reg_H_fx, &st_fx->L_vad_flag_reg_L_fx, &st_fx->L_vad_prim_reg_fx, &st_fx->vad_flag_cnt_50_fx, - &st_fx->vad_prim_cnt_16_fx, &st_fx->hangover_cnt_dtx_fx, &st_fx->hangover_cnt_music_fx ); - - st_fx->nb_active_frames_HE_SAD_fx = 0; - move16(); - /* avoid uninitialized memory access */ - noise_est_init_fx( &st_fx->totalNoise_fx, &st_fx->first_noise_updt_fx, st_fx->bckr_fx, st_fx->enrO_fx, - st_fx->ave_enr_fx, &st_fx->pitO_fx, &st_fx->aEn_fx, &st_fx->harm_cor_cnt_fx,&st_fx->bg_cnt_fx, - &st_fx->lt_tn_track_fx, &st_fx->lt_tn_dist_fx, &st_fx->lt_Ellp_dist_fx, - &st_fx->lt_haco_ev_fx, &st_fx->low_tn_track_cnt_fx - ,&st_fx->Etot_st_est_fx,&st_fx->Etot_sq_st_est_fx - ); - - st_fx->epsP_0_2_lp_fx = 4096; /*1.0 Q12*/ move16(); - st_fx->epsP_0_2_ad_lp_fx = 0; - move16(); - st_fx->epsP_2_16_lp_fx = 4096; - move16(); - st_fx->epsP_2_16_lp2_fx = 4096; - move16(); - st_fx->epsP_2_16_dlp_lp2_fx = 0; - move16(); - st_fx->lt_aEn_zero_fx = 0; - move16(); - - - - - st_fx->prim_act_quick_fx=0; - move16(); - st_fx->prim_act_slow_fx=0; - move16(); - st_fx->prim_act_fx=0; - move16(); - st_fx->prim_act_quick_he_fx=0; - move16(); - st_fx->prim_act_slow_he_fx=0; - move16(); - st_fx->prim_act_he_fx=0; - move16(); - st_fx->bckr_tilt_lt=0; - move32(); - - /* WB, SWB and FB bandwidth detector */ - st_fx->lt_mean_NB_fx = 0; - move16(); - st_fx->lt_mean_WB_fx = 0; - move16(); - st_fx->lt_mean_SWB_fx = 0; - move16(); - st_fx->count_WB_fx = BWD_COUNT_MAX; - move16(); - st_fx->count_SWB_fx = BWD_COUNT_MAX; - move16(); - st_fx->count_FB_fx = BWD_COUNT_MAX; - move16(); - st_fx->bwidth_fx = st_fx->max_bwidth_fx; - move16(); - st_fx->last_input_bwidth_fx = st_fx->bwidth_fx; - move16(); - st_fx->last_bwidth_fx = st_fx->bwidth_fx; - move16(); - st_fx->last_bwidth_cng_fx = st_fx->bwidth_fx; - move16(); - - /* Tonal detector */ - FOR ( i=0; iold_S_fx[i] = 1; - move16(); - } - set16_fx( st_fx->cor_map_fx, 0, L_FFT/2 ); - st_fx->act_pred_fx = 32767; - move16(); - st_fx->noise_char_fx = 0; - move16(); - st_fx->multi_harm_limit_fx = THR_CORR_INIT_FX; - move16(); - st_fx->coder_type_raw_fx = VOICED; - st_fx->last_coder_type_raw_fx = st_fx->coder_type_raw_fx; - - /* Stationary noise UV modification */ - st_fx->ge_sm_fx = 640; - move32();/*Q(GE_SHIFT) */ - st_fx->uv_count_fx = 0; - move16(); - st_fx->act_count_fx = 3; - move16(); - Copy(st_fx->lsp_old_fx, st_fx->lspold_s_fx, M); - st_fx->noimix_seed_fx = RANDOM_INITSEED; - move16(); - st_fx->min_alpha_fx = 1; - move16(); - st_fx->exc_pe_fx = 0; - move16(); - - /* CNG and DTX */ - st_fx->lp_noise_fx = 0; - move16(); - Copy( st_fx->lsp_old1_fx, st_fx->lspCNG_fx, M ); - st_fx->cng_seed_fx = RANDOM_INITSEED; - move16(); - st_fx->cng_ener_seed_fx = RANDOM_INITSEED; - move16(); - st_fx->cng_ener_seed1_fx = RANDOM_INITSEED; - st_fx->lp_ener_fx = 0; - move32(); - st_fx->first_CNG_fx = 0; - move16(); - st_fx->cnt_SID_fx = 0; - move16(); - st_fx->max_SID_fx = 2; - move16(); - st_fx->old_enr_index_fx = -1; - move16(); - st_fx->Enew_fx = 0; - move32(); - st_fx->VarDTX_cnt_voiced_fx = 0; - move16(); - st_fx->lt_ener_voiced_fx = 0; - move32(); - st_fx->VarDTX_cnt_noise_fx = 0; - move16(); - st_fx->lt_ener_noise_fx = 0; - move32(); - st_fx->lt_ener_last_SID_fx = 0; - move32(); - if( st_fx->var_SID_rate_flag_fx ) - { - st_fx->interval_SID_fx = 12; - move16(); - } - st_fx->lp_sp_enr_fx = 0; - move16(); - st_fx->last_allow_cn_step_fx = 0; - move16(); - - st_fx->fd_cng_reset_flag = 0; - move16(); - - IF( st_fx->Opt_DTX_ON_fx ) - { - st_fx->cng_hist_ptr_fx = -1; - move16(); - set16_fx( st_fx->cng_lsp_hist_fx, 0, DTX_HIST_SIZE*M ); - set16_fx( st_fx->cng_ener_hist_fx, 0, DTX_HIST_SIZE ); - st_fx->cng_cnt_fx = 0; - move16(); - - st_fx->ho_hist_ptr_fx = -1; - move16(); - st_fx->ho_sid_bw_fx = L_deposit_l(0); - set16_fx( st_fx->ho_lsp_hist_fx, 0, HO_HIST_SIZE*M ); - set32_fx( st_fx->ho_ener_hist_fx, 0, HO_HIST_SIZE ); - set32_fx( st_fx->ho_env_hist_fx, 0, HO_HIST_SIZE*NUM_ENV_CNG ); - st_fx->ho_hist_size_fx = 0; - move16(); - st_fx->act_cnt_fx = 0; - move16(); - } - st_fx->active_fr_cnt_fx = 0; - move16(); - st_fx->cng_type_fx = -1; - move16(); - - st_fx->CNG_mode_fx = -1; - move16(); - st_fx->last_active_brate_fx = ACELP_7k20; - move32(); - st_fx->last_CNG_L_frame_fx = L_FRAME; - move16(); - set16_fx( st_fx->ho_16k_lsp_fx, 0, HO_HIST_SIZE ); - st_fx->act_cnt2_fx = 0; - move16(); - st_fx->num_ho_fx = 0; - move16(); - st_fx->hangover_terminate_flag_fx = 0; - move16(); - - st_fx->ho_circ_ptr_fx = -1; - move16(); - set16_fx( st_fx->ho_lsp_circ_fx, 0, HO_HIST_SIZE*M ); - set32_fx( st_fx->ho_ener_circ_fx, 0, HO_HIST_SIZE ); - set32_fx( st_fx->ho_env_circ_fx, 0, HO_HIST_SIZE*NUM_ENV_CNG ); - st_fx->ho_circ_size_fx = 0; - move16(); - st_fx->burst_ho_cnt_fx = 0; - move16(); - st_fx->cng_buf_cnt = 0; - move16(); - - test(); - test(); - IF( st_fx->var_SID_rate_flag_fx || ((!st_fx->var_SID_rate_flag_fx) && (st_fx->interval_SID_fx >= DTX_HIST_SIZE)) ) - { - st_fx->cng_hist_size_fx = DTX_HIST_SIZE; - move16(); - } - ELSE - { - st_fx->cng_hist_size_fx = st_fx->interval_SID_fx; - move16(); - } - set32_fx(st_fx->lp_env_fx, 0, 20); - set32_fx(st_fx->cng_res_env_fx, 0, 20*8); - set16_fx(st_fx->exc_mem_fx, 0, 24); - set16_fx(st_fx->exc_mem1_fx, 0, 30); - set16_fx(st_fx->exc_mem2_fx, 0, 30); - set32_fx(st_fx->old_env_fx, 0, NUM_ENV_CNG); - - /* SWB CNG/DTX */ - st_fx->last_wb_cng_ener_fx = -1541; - move16(); /* Q8 */ - st_fx->last_shb_cng_ener_fx = -1541; - move16(); /* Q8 */ - st_fx->mov_wb_cng_ener_fx = -1541; - move16(); /* Q8 */ - st_fx->mov_shb_cng_ener_fx = -1541; - move16(); /* Q8 */ - st_fx->shb_cng_ini_cnt_fx = 1; - move16(); - st_fx->shb_NO_DATA_cnt_fx = 0; - move16(); - st_fx->last_SID_bwidth_fx = s_min(st_fx->max_bwidth_fx, SWB); - st_fx->last_vad_fx = 0; - move16(); - - /* FEC */ - st_fx->last_clas_fx = UNVOICED_CLAS; - move16(); - - FOR (i=0; i<2*NB_SUBFR16k; i++) - { - st_fx->old_pitch_buf_fx[i] = L_SUBFR_Q6; - move16(); - } - st_fx->old_Es_pred_fx = 0; - move16(); - set16_fx(st_fx->old_Aq_12_8_fx + 1, 0, M ); - st_fx->old_Aq_12_8_fx[0] = 4096; - move16(); - - /*-----------------------------------------------------------------* - * CLDFB Analysis - *-----------------------------------------------------------------*/ - - /* open analysis for input SR */ - openCldfb ( &st_fx->cldfbAna_Fx, CLDFB_ANALYSIS, CLDFB_getNumChannels(st_fx->input_Fs_fx), st_fx->input_frame_fx ); - - openCldfb ( &st_fx->cldfbSyn_Fx, CLDFB_SYNTHESIS, CLDFB_getNumChannels(16000), L_FRAME16k); - - st_fx->energyCoreLookahead_Fx = 0; - move32(); - st_fx->sf_energyCoreLookahead_Fx = 0; - move16(); - - /*-----------------------------------------------------------------* - * SC-VBR parameters - *-----------------------------------------------------------------*/ - - st_fx->nelp_enc_seed_fx = 0; - move16(); - st_fx->last_nelp_mode_fx = 0; - move16(); - st_fx->pppcountE_fx = 0; - move16(); - st_fx->last_ppp_mode_fx = 0; - move16(); - st_fx->last_last_ppp_mode_fx = 0; - move16(); - st_fx->firstTime_voicedenc_fx = 1; - move16(); - st_fx->prev_ppp_gain_pit_fx = 0; - move16(); - st_fx->prev_tilt_code_fx = 0; - move16(); - - st_fx->ppp_mode_fx = 0; - move16(); - st_fx->nelp_mode_fx = 0; - move16(); - - /* stable short pitch detection */ - st_fx->voicing0_sm_fx = 0; - move16(); - st_fx->voicing_sm_fx = 0; - move16(); - st_fx->LF_EnergyRatio_sm_fx = 128; - move16(); - st_fx->predecision_flag_fx = 0; - move16(); - st_fx->diff_sm_fx = 0; - move32(); - st_fx->energy_sm_fx = 0; - move32(); - - st_fx->pattern_m_fx = 0; - move16(); - st_fx->Last_Resort_fx = 0; - move16(); - st_fx->Q_to_F_fx = 0; - move16(); - - st_fx->numactive_fx = 0; /* keep the count of the frames inside current 600 frame bloack.*/ - st_fx->sum_of_rates_fx = 0; /* sum of the rates of past 600 active frames*/ - st_fx->global_avr_rate_fx = 0; /* global rate upto current time. recorded a (rate in kbps) *6000*/ - st_fx->frame_cnt_ratewin_fx = 0; /* 600 active frame block count. Used to update the global rate*/ - st_fx->rate_control_fx = 0; - move16(); - st_fx->SNR_THLD_fx = SNR_THLD_FX_Q8; - move16(); - st_fx->mode_QQF_fx = 1; - move16(); - - - /*-----------------------------------------------------------------* - * SWB BWE parameters - *-----------------------------------------------------------------*/ - - set16_fx( st_fx->new_input_hp_fx, 0, NS2SA(16000, ACELP_LOOK_NS + DELAY_FD_BWE_ENC_12k8_NS + DELAY_FIR_RESAMPL_NS - DELAY_CLDFB_NS)); - set16_fx( st_fx->old_input_fx, 0, NS2SA(48000, DELAY_FD_BWE_ENC_12k8_NS + DELAY_FIR_RESAMPL_NS) ); - set16_fx( st_fx->old_input_wb_fx, 0, NS2SA(16000, DELAY_FD_BWE_ENC_12k8_NS) ); - set16_fx( st_fx->old_input_lp_fx, 0, NS2SA(16000, ACELP_LOOK_NS + DELAY_SWB_TBE_16k_NS) ); - set16_fx( st_fx->old_syn_12k8_16k_fx, 0, NS2SA(16000, DELAY_FD_BWE_ENC_NS) ); - - st_fx->prev_mode_fx = NORMAL; - move16(); - st_fx->modeCount_fx = 0; - move16(); - st_fx->EnergyLF_fx = 0; - move32(); - - set16_fx( st_fx->L_old_wtda_swb_fx, 0, L_FRAME48k ); - - st_fx->prev_Q_input_lp = 0; - move16(); - - st_fx->prev_global_gain_fx = 0; - move32(); - st_fx->prev_Q_shb = 0; - move16(); - st_fx->prev_L_swb_norm1_fx = 8; - move16(); - st_fx->last_Opt_SC_VBR_fx = 0; - move16(); - - /*-----------------------------------------------------------------* - * TBE parameters - *-----------------------------------------------------------------*/ - - InitSWBencBuffer_fx(st_fx); - ResetSHBbuffer_Enc_fx(st_fx); - set16_fx( st_fx->old_speech_shb_fx, 0, L_LOOK_16k + L_SUBFR16k ); - set16_fx( st_fx->old_speech_wb_fx, 0, (L_LOOK_12k8 + L_SUBFR) * 5/16); - set16_fx( st_fx->old_input_fhb_fx, 0, NS2SA(48000, ACELP_LOOK_NS + DELAY_FD_BWE_ENC_12k8_NS + DELAY_FIR_RESAMPL_NS) - L_FRAME48k/2); - st_fx->old_input_fhb_fx_Q = 0; - move16(); - st_fx->cldfbHBLT = 8192/*1.0f Q13*/; - - st_fx->prev_gainFr_SHB_fx = 0; - set16_fx(st_fx->lsp_shb_slow_interpl_fx, 0, LPC_SHB_ORDER); - set16_fx(st_fx->lsp_shb_fast_interpl_fx, 0, LPC_SHB_ORDER); - set16_fx( st_fx->shb_inv_filt_mem_fx, 0, LPC_SHB_ORDER ); - set16_fx( st_fx->lsp_shb_spacing_fx, 3277, 3); - st_fx->prev_swb_GainShape_fx= 0; - move16(); - st_fx->prev_frGainAtten_fx = 0; - move16(); - st_fx->prev_wb_GainShape = 0; - move16(); - st_fx->prev_Q_bwe_exc_fb = 51; - move16(); - set16_fx(st_fx->fb_state_lpc_syn_fx, 0, LPC_SHB_ORDER); - st_fx->fb_tbe_demph_fx = 0; - move16(); - st_fx->tilt_mem_fx = 0; - move16(); - st_fx->prev_coder_type_fx = GENERIC; - move16(); - set16_fx( st_fx->prev_lsf_diff_fx, 16384, LPC_SHB_ORDER-2 ); - st_fx->prev_tilt_para_fx = 0; - move16(); - set16_fx( st_fx->cur_sub_Aq_fx, 0, M+1 ); - - /* TD BWE post-processing */ - st_fx->ptr_mem_stp_swb_fx = st_fx->mem_stp_swb_fx + LPC_SHB_ORDER - 1; - set16_fx(st_fx->mem_zero_swb_fx, 0, LPC_SHB_ORDER); - - FOR ( i=0; iswb_lsp_prev_interp_fx[i] = swb_lsp_prev_interp_init[i]; - } - - set16_fx( st_fx->dec_2_over_3_mem_fx, 0, 12 ); - set16_fx( st_fx->dec_2_over_3_mem_lp_fx, 0, 6 ); - set16_fx( st_fx->old_fdbwe_speech_fx, 0, L_FRAME48k ); - - /*-----------------------------------------------------------------* - * HQ core parameters - *-----------------------------------------------------------------*/ - - st_fx->input = st_fx->input_buff+L_FRAME48k+NS2SA(48000, DELAY_FIR_RESAMPL_NS); - set16_fx( st_fx->input_buff+L_FRAME48k, 0, L_FRAME48k+NS2SA(48000, DELAY_FIR_RESAMPL_NS) ); - st_fx->old_input_signal_fx = st_fx->input - add(NS2SA_fx2(st_fx->input_Fs_fx, DELAY_FIR_RESAMPL_NS), st_fx->input_frame_fx); - - st_fx->Q_old_out = 0; - move16(); - - st_fx->Energy_Old_fx = 0; - move16(); - st_fx->Q_old_wtda=15; - move16(); - st_fx->EnergyLT_fx = 1; - move32(); - st_fx->EnergyLT_fx_exp = 30; - move16(); /* Set to a High Exponent so it is 1^-30 */ - st_fx->TransientHangOver_fx = 0; - move16(); - - set16_fx( st_fx->old_out_fx, 0, L_FRAME32k ); - st_fx->mode_count_fx = 0; - move16(); - st_fx->mode_count1_fx = 0; - move16(); - - st_fx->hq_generic_speech_class_fx = 0; - move16(); - st_fx->prev_Npeaks_fx = 0; - set16_fx(st_fx->prev_peaks_fx, 0, HVQ_MAX_PEAKS); - st_fx->hvq_hangover_fx = 0; - st_fx->prev_hqswb_clas_fx = HQ_NORMAL; - - set16_fx(st_fx->prev_SWB_peak_pos_fx, 0, SPT_SHORTEN_SBNUM); - st_fx->clas_sec_old_fx = 8192; /* 1.0f in Q13 */; - st_fx->clas_final_old_fx = 1; /* Q0 */ - st_fx->last_gain1 = 0; - move32(); - st_fx->last_gain2 = 0; - move32(); - st_fx->last_enerBuffer_exp = 0; - move16(); - /* speech/music classification */ - set16_fx(st_fx->lt_old_mode, 1, 3); - st_fx->lt_voicing = 16384/*0.5f Q15*/; - st_fx->lt_corr = 16384/*0.5f Q15*/; - st_fx->lt_tonality = 0; - move32(); - set16_fx(st_fx->lt_corr_pitch, 0, 3); - st_fx->lt_hangover = 0; - move16(); - st_fx->lowrate_pitchGain = 0; - move16(); - - - st_fx->lt_music_hangover_fx = 0; - move16(); - set16_fx(st_fx->tonality2_buf_fx,0,HANG_LEN_INIT); - set16_fx(st_fx->tonality3_buf_fx,0,HANG_LEN_INIT); - set16_fx(st_fx->LPCErr_buf_fx,0,HANG_LEN_INIT); - st_fx->lt_music_state_fx = 0; - move16(); - st_fx->lt_speech_state_fx = 0; - move16(); - st_fx->lt_speech_hangover_fx = 0; - move16(); - st_fx->consec_inactive_fx = 0; - move16(); - st_fx->spectral_tilt_reset_fx = 1; - move16(); - st_fx->running_avg_fx = 0; - move16(); - st_fx->ra_deltasum_fx = 0; - move16(); - st_fx->trigger_SID_fx = 0; - move16(); - st_fx->L_snr_sum_vad_fx = 0; - move32(); - - set16_fx( st_fx->prev_frm_index_fx, -1, NB_SWB_SUBBANDS_HAR_SEARCH_SB ); - st_fx->prev_frm_hfe2_fx = 0; - move16(); - st_fx->prev_stab_hfe2_fx = 0; - move16(); - st_fx->prev_ni_ratio_fx = 16384; - move16(); /* 0.5 */ - set16_fx(st_fx->prev_En_sb_fx, 0, NB_SWB_SUBBANDS); - set16_fx(st_fx->last_bitalloc_max_band_fx, 0, 2); - set32_fx( st_fx->last_ni_gain_fx, 0, BANDS_MAX ); - set16_fx( st_fx->last_env_fx, 0, BANDS_MAX ); - st_fx->last_max_pos_pulse_fx = 0; - move16(); - - /*-----------------------------------------------------------------* - * Channel-aware mode - *-----------------------------------------------------------------*/ - - - test(); - test(); - test(); - IF( st_fx->Opt_RF_ON == 0 || (sub(st_fx->bwidth_fx,WB) != 0 && sub(st_fx->bwidth_fx,SWB) != 0) || L_sub(st_fx->total_brate_fx,ACELP_13k20) != 0 ) - { - IF (sub(st_fx->Opt_RF_ON,1)==0 ) - { - printf("\nWarning: Channel-aware mode only available for 13.2 kbps WB/SWB\n"); - printf(" Switched to normal mode!\n"); - st_fx->Opt_RF_ON = 0; - move16(); - st_fx->rf_fec_offset = 0; - move16(); - } - st_fx->rf_mode = 0; - move16(); - } - ELSE - { - st_fx->rf_mode = st_fx->Opt_RF_ON; - move16(); - } - st_fx->rf_mode_last = st_fx->rf_mode; - - /* initialize RF indice buffers */ - reset_rf_indices( st_fx ); - - /*-----------------------------------------------------------------* - * MODE2 initialization - *-----------------------------------------------------------------*/ - - st_fx->last_sr_core = i_mult2 (st_fx->last_L_frame_fx, 50); - - - IF( sub(st_fx->codec_mode, MODE2) == 0 ) - { - st_fx->igf = getIgfPresent( st_fx->total_brate_fx, st_fx->bwidth_fx, st_fx->rf_mode); - } - ELSE - { - st_fx->igf = 0; - move16(); - } - - /* FD-CNG encoder */ - createFdCngEnc(&st_fx->hFdCngEnc_fx); - initFdCngEnc(st_fx->hFdCngEnc_fx, st_fx->input_Fs_fx, st_fx->cldfbAna_Fx->scale); - L_tmp = st_fx->total_brate_fx; - move32(); - test(); - if( st_fx->rf_mode && L_sub(st_fx->total_brate_fx,ACELP_13k20) == 0 ) - { - L_tmp = ACELP_9k60; - move32(); - } - configureFdCngEnc( st_fx->hFdCngEnc_fx, st_fx->bwidth_fx, L_tmp ); - - st_fx->last_totalNoise_fx = 0; - move16(); - set16_fx( st_fx->totalNoise_increase_hist_fx, 0, TOTALNOISE_HIST_SIZE ); - st_fx->totalNoise_increase_len_fx = 0; - move16(); - init_coder_ace_plus( st_fx, 0); - - InitTransientDetection( extract_l(Mult_32_16(st_fx->input_Fs_fx, 0x0290)), - NS2SA_fx2(st_fx->input_Fs_fx, DELAY_FIR_RESAMPL_NS), - &st_fx->transientDetection ); - - reset_indices_enc_fx( st_fx ); - - - st_fx->Q_syn2 = 0; - move16(); - st_fx->Q_syn = 0; - move16(); - set16_fx(st_fx->Q_max, Q_MAX, L_Q_MEM); - set16_fx(st_fx->Q_max_16k, Q_MAX, L_Q_MEM); - st_fx->Q_old = 15; - move16(); - st_fx->old_wsp_max = 0; - move16(); - st_fx->old_wsp_shift = 0; - move16(); - - st_fx->vbr_generic_ho_fx = 0; - move16(); - - st_fx->sharpFlag = 0; - move16(); - - st_fx->Local_VAD = 0; - - set16_fx( st_fx->nelp_lp_fit_mem, 0, NELP_LP_ORDER*2 ); - - return; -} - -/*-----------------------------------------------------------------------* - * destroy_encoder() - * - * Free memory which was allocated in init_encoder() - *-----------------------------------------------------------------------*/ - -void destroy_encoder_fx( - Encoder_State_fx *st_fx /* i/o: Encoder static variables structure */ -) -{ - deleteCldfb( &st_fx->cldfbAna_Fx ); - deleteCldfb( &st_fx->cldfbSyn_Fx ); - - deleteFdCngEnc( &st_fx->hFdCngEnc_fx ); - - return; -} diff --git a/src/libs/libevs/lib_enc/inov_enc.cpp b/src/libs/libevs/lib_enc/inov_enc.cpp new file mode 100644 index 00000000..2231500d --- /dev/null +++ b/src/libs/libevs/lib_enc/inov_enc.cpp @@ -0,0 +1,266 @@ +/*==================================================================================== + EVS Codec 3GPP TS26.443 Nov 13, 2018. Version 12.11.0 / 13.7.0 / 14.3.0 / 15.1.0 + ====================================================================================*/ + +#include "options.h" +#include "cnst.h" +#include "prot.h" +#include "rom_com.h" + + +/*---------------------------------------------------------------------* + * inov_encode() + * + * Encode the algebraic innovation + *---------------------------------------------------------------------*/ + +void inov_encode( + Encoder_State *st, /* i/o: encoder state structure */ + const long core_brate, /* i : core bitrate */ + const short Opt_AMR_WB, /* i : flag indicating AMR-WB IO mode */ + const short L_frame, /* i : length of the frame */ + const short last_L_frame, /* i : length of the last frame */ + const short coder_type, /* i : coding type */ + const short bwidth, /* i : input signal bandwidth */ + const short sharpFlag, /* i : formant sharpening flag */ + const short i_subfr, /* i : subframe index */ + const short tc_subfr, /* i : TC subframe index */ + const float *p_Aq, /* i : LP filter coefficients */ + const float gain_pit, /* i : adaptive excitation gain */ + float *cn, /* i/o: target vector in residual domain */ + const float *exc, /* i : pointer to excitation signal frame */ + float *h1, /* i/o: weighted filter input response */ + const float tilt_code, /* i : tilt of the excitation of previous subframe */ + const float pt_pitch, /* i : pointer to current subframe fractional pitch */ + const float *xn2, /* i : target vector for innovation search */ + float *code, /* o : algebraic excitation */ + float *y2, /* o : zero-memory filtered algebraic excitation */ + short *unbits /* o : number of unused bits for EVS_PI */ +) +{ + float dn[L_SUBFR]; /* Correlation between xn2 and h1 */ + short nBits, cmpl_flag; + short k; + float g1, g2; + float cn2[L_SUBFR]; + float Rw[L_SUBFR]; + short i, acelpautoc; + + if( L_frame == L_FRAME ) + { + g1 = FORMANT_SHARPENING_G1; + g2 = FORMANT_SHARPENING_G2; + } + else + { + g1 = FORMANT_SHARPENING_G1_16k; + g2 = FORMANT_SHARPENING_G2_16k; + } + + /*----------------------------------------------------------------* + * Update target vector for codebook search in residual domain + * Preemphasize the impulse response and include fixed-gain pitch contribution into impulse resp. h1[] (pitch sharpenning) + * Correlation between target xn2[] and impulse response h1[] + *----------------------------------------------------------------*/ + + if( core_brate > ACELP_13k20 && !Opt_AMR_WB ) + { + acelpautoc = 1; + + cb_shape( 1, 1, 0, sharpFlag, 0, g1, g2, p_Aq, h1, tilt_code, pt_pitch ); + + corr_xh( h1, Rw, h1, L_SUBFR ); + + for( k=0; k WB ) + { + if( i_subfr <= L_SUBFR ) + { + cmpl_flag -= 1; + } + else + { + cmpl_flag -= 2; + } + } + } + else if( core_brate <= ACELP_48k ) + { + cmpl_flag = 3; + + if( coder_type == TRANSITION ) + { + if( i_subfr <= L_SUBFR ) + { + cmpl_flag -= 1; + } + else + { + cmpl_flag -= 2; + } + } + } + else + { + cmpl_flag = 4; + + if( coder_type == TRANSITION ) + { + if( i_subfr <= L_SUBFR ) + { + cmpl_flag -= 1; + } + else + { + cmpl_flag -= 2; + } + } + } + + if( coder_type == INACTIVE ) + { + cmpl_flag = 4; + } + } + + /* reduce number of iterations in a frame where there is an internal sampling rate switch in order not to increase the WC complexity */ + if( L_frame != last_L_frame && core_brate > ACELP_13k20 && (core_brate < ACELP_32k || bwidth == WB) ) + { + if( cmpl_flag > 1 ) + { + cmpl_flag--; + } + } + + /*-----------------------------------------------------------------* + * Find and encode the algebraic innovation + *-----------------------------------------------------------------*/ + + set_f( y2, 0, L_SUBFR ); + + if( !Opt_AMR_WB ) + { + if( L_frame == L_FRAME ) + { + nBits = FCB_bits_tbl[BIT_ALLOC_IDX(core_brate, coder_type, i_subfr, TC_SUBFR2IDX(tc_subfr))]; + } + else /* L_frame == L_FRAME16k */ + { + nBits = FCB_bits_16kHz_tbl[BIT_ALLOC_IDX_16KHZ(core_brate, coder_type, i_subfr, TC_SUBFR2IDX_16KHZ(tc_subfr))]; + } + + if( nBits == 7 ) + { + acelp_1t64( st, dn, h1, code, y2 ); + } + else if( nBits == 12 ) + { + acelp_2t32( st, dn, h1, code, y2 ); + } + else + { + *unbits += acelp_4t64( st, dn, cn, h1, Rw, acelpautoc, code, y2, nBits, cmpl_flag, Opt_AMR_WB ); + } + } + else + { + if (core_brate == ACELP_6k60 ) + { + acelp_2t32( st, dn, h1, code, y2 ); + } + else if( (core_brate == ACELP_8k85) ) + { + acelp_4t64( st, dn, cn, h1, Rw, acelpautoc, code, y2, 20, cmpl_flag, Opt_AMR_WB ); + } + else if( core_brate == ACELP_12k65 ) + { + acelp_4t64( st, dn, cn, h1, Rw, acelpautoc, code, y2, 36, cmpl_flag, Opt_AMR_WB ); + } + else if( core_brate == ACELP_14k25 ) + { + acelp_4t64( st, dn, cn, h1, Rw, acelpautoc, code, y2, 44, cmpl_flag, Opt_AMR_WB ); + } + else if( core_brate == ACELP_15k85 ) + { + acelp_4t64( st, dn, cn, h1, Rw, acelpautoc, code, y2, 52, cmpl_flag, Opt_AMR_WB ); + } + else if( core_brate == ACELP_18k25 ) + { + acelp_4t64( st, dn, cn, h1, Rw, acelpautoc, code, y2, 64, cmpl_flag, Opt_AMR_WB ); + } + else if( core_brate == ACELP_19k85 ) + { + acelp_4t64( st, dn, cn, h1, Rw, acelpautoc, code, y2, 72, cmpl_flag, Opt_AMR_WB ); + } + else if( core_brate == ACELP_23k05 ) + { + acelp_4t64( st, dn, cn, h1, Rw, acelpautoc, code, y2, 88, cmpl_flag, Opt_AMR_WB ); + } + else if( core_brate == ACELP_23k85 ) + { + acelp_4t64( st, dn, cn, h1, Rw, acelpautoc, code, y2, 88, cmpl_flag, Opt_AMR_WB ); + } + } + + /*----------------------------------------------------------------* + * Pitch sharpening + *----------------------------------------------------------------*/ + + cb_shape( 1, 1, 0, sharpFlag, 0, g1, g2, p_Aq, code, tilt_code, pt_pitch ); + + return; +} diff --git a/src/libs/libevs/lib_enc/inov_enc_fx.cpp b/src/libs/libevs/lib_enc/inov_enc_fx.cpp deleted file mode 100755 index 62a1280f..00000000 --- a/src/libs/libevs/lib_enc/inov_enc_fx.cpp +++ /dev/null @@ -1,332 +0,0 @@ -/*==================================================================================== - EVS Codec 3GPP TS26.442 Apr 03, 2018. Version 12.11.0 / 13.6.0 / 14.2.0 - ====================================================================================*/ - -#include "options.h" /* Compilation switches */ -#include "cnst_fx.h" /* Common constants */ -#include "prot_fx.h" /* Function prototypes */ -#include "basop_util.h" -#include "rom_com_fx.h" /* Static table prototypes */ -#include "stl.h" - - -/*==============================================================================*/ -/* FUNCTION : inov_encode_fx() */ -/*------------------------------------------------------------------------------*/ -/* PURPOSE : Encode the algebraic innovation */ -/*------------------------------------------------------------------------------*/ -/* INPUT ARGUMENTS : */ -/* _ (Word16) core_brate: core bitrate Q0 */ -/* _ (Word16) Opt_AMR_WB: flag indicating AMR-WB IO mode Q0 */ -/* _ (Word16) bwidth : input signal bandwidth Q0 */ -/* _ (Word16) L_frame_fx : length of the frame Q0 */ -/* _ (Word16[]) h2 : weighted filter input response Q12 */ -/* _ (Word16[]) xn2 : target vector Q_new */ -/* _ (Word16) coder_type_fx : coding type Q0 */ -/* _ (Word16) i_subfr : current sub frame indicator Q0 */ -/* _ (Word16[]) exc_fx : pointer to excitation signal frame Q_new */ -/* _ (Word16) L_subfr : subframe length Q0 */ -/* _ (Word16) clip_gain : adaptive gain clipping flag Q0 */ -/* _ (Word16) gain_pit : adaptive excitation gain Q14 */ -/* _ (Word16) sharpFlag : formant sharpening flag Q0 */ -/* _ (Word16) tc_subfr : TC subframe index Q0 */ -/* _ (Word16) p_Aq : LP filter coefficients Q12 */ -/* _ (Word16) Jopt_flag :joint optimization flag Q0 */ -/* _ (Word16) y1 : Filtered adaptive excitation Q_new */ -/* _ (Word16) y2 :zero-memory filtered algebraic excitation Q_new */ -/* _ (Word16) cn : target vector in residual domain Q_new */ -/* _ (Word16) tilt_code : tilt of the excitation of previous subframe Q15 */ -/* _ (Word16) pt_pitch : pointer to current subframe fractional pitchQ6 */ -/* _ (Word16) index_buf_4T :5Sx4Track buffer for PI Q0 */ -/* _ (Word16) shift :shift */ -/* _ (Word16) Q_new : */ -/*------------------------------------------------------------------------------*/ -/* OUTPUT ARGUMENTS : */ -/* _ (Word16[]) exc_fx : adapt. excitation exc (Q0) */ -/* _ (Word16) cn : target vector in residual domain Q_new */ -/* _ (Word16) code :algebraic excitation Q9 */ -/* _ (Word16) y2 :zero-memory filtered algebraic excitation Q_new */ -/* _ (Word16) unbits :number of unused bits for PI Q0 */ -/*------------------------------------------------------------------------------*/ - -/*------------------------------------------------------------------------------*/ -/* RETURN ARGUMENTS : */ -/* _ None */ -/*==============================================================================*/ - -Word16 inov_encode_fx( - Encoder_State_fx *st_fx, /* i/o: encoder state structure */ - const Word32 core_brate, /* i : core bitrate */ - const Word16 Opt_AMR_WB, /* i : flag indicating AMR-WB IO mode */ - const Word16 L_frame, /* i : length of the frame */ - const Word16 last_L_frame, /* i : length of the last frame */ - const Word16 coder_type, /* i : coding type */ - const Word16 bwidth, /* i : input signal bandwidth */ - const Word16 sharpFlag, /* i : formant sharpening flag */ - const Word16 i_subfr, /* i : subframe index */ - const Word16 tc_subfr, /* i : TC subframe index */ - const Word16 *p_Aq, /* i : LP filter coefficients Q12*/ - const Word16 gain_pit, /* i : adaptive excitation gain Q14*/ - Word16 *cn, /* i/o: target vector in residual domain Q_new*/ - const Word16 *exc, /* i : pointer to excitation signal frame Q_new*/ - Word16 *h2, /* i/o: weighted filter input response Q12*/ - const Word16 tilt_code, /* i : tilt of the excitation of previous subframe Q15*/ - const Word16 pt_pitch, /* i : pointer to current subframe fractional pitch Q6*/ - const Word16 *xn2, /* i : target vector for innovation search Q_new-1+shift*/ - Word16 *code, /* o : algebraic excitation Q9*/ - Word16 *y2, /* o : zero-memory filtered algebraic excitation Q9*/ - Word16 *unbits, /* o : number of unused bits for PI */ - Word16 shift -) -{ - Word16 dn[L_SUBFR]; - Word16 nBits, cmpl_flag; - Word16 stack_pulses; - Word16 g1, g2; - Word16 Rw[L_SUBFR]; - Word16 acelpautoc; - - stack_pulses = 0; - move16(); - - IF( sub(L_frame,L_FRAME) == 0 ) - { - g1 = FORMANT_SHARPENING_G1; - move16(); - g2 = FORMANT_SHARPENING_G2; - move16(); - } - ELSE - { - g1 = FORMANT_SHARPENING_G1_16k; - move16(); - g2 = FORMANT_SHARPENING_G2_16k; - move16(); - } - - /*----------------------------------------------------------------* - * Update target vector for codebook search in residual domain - * Preemphasize the impulse response and include fixed-gain pitch contribution into impulse resp. h1[] (pitch sharpenning) - * Correlation between target xn2[] and impulse response h1[] - *----------------------------------------------------------------*/ - - test(); - IF (L_sub(core_brate, ACELP_13k20) > 0 && !Opt_AMR_WB) - { - acelpautoc = 1; - move16(); - - cb_shape_fx( 1, 1, 0, sharpFlag, 0, g1, g2, p_Aq, h2, tilt_code, shr(add(pt_pitch,26),6), 0 ); - /* h2: Q11, Rw: (Rw_e)Q */ - /* Rw_e = */ E_ACELP_hh_corr(h2, Rw, L_SUBFR, 3); - - E_ACELP_conv(xn2, h2, cn); - - /* dn_e -> Rw_e*Q_xn */ - /*dn_e = */ E_ACELP_toeplitz_mul( Rw, cn, dn, L_SUBFR, 1 ); - } - ELSE - { - acelpautoc = 0; - move16(); - updt_tar_fx( cn, cn, &exc[i_subfr], gain_pit, L_SUBFR ); - /* scaling of cn[] to limit dynamic at 12 bits */ - Scale_sig(cn, L_SUBFR, shift); - - cb_shape_fx( 1, 1, 0, sharpFlag, 0, g1, g2, p_Aq, h2, tilt_code, shr(add(pt_pitch,26),6), 0 ); - corr_xh_fx( xn2, dn, h2 ); - } - - /*-----------------------------------------------------------------* - * Set complexity reduction flag to limit the number of iterations - * in algebraic innovation search - *-----------------------------------------------------------------*/ - cmpl_flag = 0; - move16(); - test(); - IF( sub(L_frame,L_FRAME) == 0 && sub(coder_type,TRANSITION) == 0 ) - { - test(); - test(); - if( L_sub(core_brate,ACELP_8k00) == 0 && i_subfr == 0 && sub(tc_subfr,L_SUBFR) < 0 ) - { - cmpl_flag = 3; - move16(); - } - test(); - test(); - test(); - test(); - test(); - if( L_sub(core_brate,ACELP_11k60) == 0 && ( (i_subfr == 0 && sub(tc_subfr,L_SUBFR) < 0) || sub(tc_subfr,TC_0_0) == 0 || (sub(i_subfr,3*L_SUBFR ) == 0&& sub(tc_subfr,TC_0_64) == 0)) ) - { - cmpl_flag = 3; - move16(); - } - test(); - test(); - test(); - test(); - if( (L_sub(core_brate,ACELP_13k20) == 0 || L_sub(core_brate,ACELP_12k15) == 0 ) && ( (i_subfr == 0 && sub(tc_subfr,L_SUBFR) < 0) || sub(tc_subfr,TC_0_64) <= 0 ) ) - { - cmpl_flag = 3; - move16(); - } - } - - IF( sub(L_frame,L_FRAME16k) == 0) - { - IF( L_sub(core_brate,ACELP_32k) <= 0 ) - { - cmpl_flag = 4; - move16(); - - test(); - IF( sub(coder_type,TRANSITION) == 0 && sub(bwidth,WB) > 0 ) - { - IF( sub(i_subfr,L_SUBFR) <= 0 ) - { - cmpl_flag = sub(cmpl_flag,1); - } - ELSE - { - cmpl_flag = sub(cmpl_flag,2); - } - } - } - ELSE IF( L_sub(core_brate,ACELP_48k) <= 0 ) - { - cmpl_flag = 3; - move16(); - - IF( sub(coder_type,TRANSITION) == 0 ) - { - IF( sub(i_subfr,L_SUBFR) <= 0 ) - { - cmpl_flag = sub(cmpl_flag,1); - } - ELSE - { - cmpl_flag = sub(cmpl_flag,2); - } - } - } - ELSE - { - cmpl_flag = 4; - move16(); - - IF( sub(coder_type,TRANSITION) == 0 ) - { - IF( sub(i_subfr,L_SUBFR) <= 0 ) - { - cmpl_flag = sub(cmpl_flag,1); - } - ELSE - { - cmpl_flag = sub(cmpl_flag,2); - } - } - - if( sub(coder_type,INACTIVE) == 0 ) - { - cmpl_flag = 4; - move16(); - } - } - } - - test(); - test(); - test(); - IF( sub(L_frame,last_L_frame) != 0 && L_sub(core_brate,ACELP_13k20) > 0 && (L_sub(core_brate,ACELP_32k) < 0 || sub(bwidth,WB) == 0) ) - { - if( sub(cmpl_flag,1) > 0 ) - { - cmpl_flag = sub(cmpl_flag,1); - } - } - - /*-----------------------------------------------------------------* - * Find and encode the algebraic innovation - *-----------------------------------------------------------------*/ - - set16_fx( y2, 0, L_SUBFR ); - - IF ( !Opt_AMR_WB ) - { - IF( sub(L_frame,L_FRAME) == 0 ) - { - nBits = FCB_bits_tbl[BIT_ALLOC_IDX_fx(core_brate, coder_type, i_subfr, TC_SUBFR2IDX_fx(tc_subfr))]; - move16(); - } - ELSE /* L_frame == L_FRAME16k */ - { - nBits = FCB_bits_16kHz_tbl[BIT_ALLOC_IDX_16KHZ_fx(core_brate, coder_type, i_subfr, TC_SUBFR2IDX_16KHZ_fx(tc_subfr))]; - move16(); - } - - IF( sub(nBits,7) == 0 ) - { - acelp_1t64_fx( st_fx, dn, h2, code, y2 ); - } - ELSE IF( sub(nBits,12) == 0 ) - { - acelp_2t32_fx(st_fx, dn, h2, code, y2 ); - } - ELSE - { - *unbits = add(*unbits, acelp_4t64_fx(st_fx, dn, cn, h2, Rw, acelpautoc, code, y2, nBits, cmpl_flag, Opt_AMR_WB)); - move16(); - } - } - ELSE - { - IF (L_sub(core_brate,ACELP_6k60) == 0) - { - acelp_2t32_fx( st_fx, dn, h2, code, y2 ); - } - ELSE IF( (L_sub(core_brate,ACELP_8k85) == 0) ) - { - acelp_4t64_fx(st_fx, dn, cn, h2, Rw, acelpautoc, code, y2, 20, cmpl_flag, Opt_AMR_WB ); - } - ELSE IF( L_sub(core_brate,ACELP_12k65) == 0) - { - acelp_4t64_fx(st_fx, dn, cn, h2, Rw, acelpautoc, code, y2, 36, cmpl_flag, Opt_AMR_WB ); - } - ELSE IF( L_sub(core_brate,ACELP_14k25) == 0) - { - acelp_4t64_fx( st_fx, dn, cn, h2, Rw, acelpautoc, code, y2, 44, cmpl_flag, Opt_AMR_WB ); - } - ELSE IF( L_sub(core_brate,ACELP_15k85) == 0) - { - acelp_4t64_fx( st_fx, dn, cn, h2, Rw, acelpautoc, code, y2, 52, cmpl_flag, Opt_AMR_WB ); - } - ELSE IF( L_sub(core_brate,ACELP_18k25) == 0) - { - acelp_4t64_fx(st_fx, dn, cn, h2, Rw, acelpautoc, code, y2, 64, cmpl_flag, Opt_AMR_WB ); - } - ELSE IF( L_sub(core_brate,ACELP_19k85) == 0) - { - acelp_4t64_fx(st_fx, dn, cn, h2, Rw, acelpautoc, code, y2, 72, cmpl_flag, Opt_AMR_WB ); - } - ELSE IF( L_sub(core_brate,ACELP_23k05) == 0 ) - { - acelp_4t64_fx(st_fx, dn, cn, h2, Rw, acelpautoc, code, y2, 88, cmpl_flag, Opt_AMR_WB ); - } - ELSE IF( L_sub(core_brate,ACELP_23k85) == 0) - { - acelp_4t64_fx(st_fx, dn, cn, h2, Rw, acelpautoc, code, y2, 88, 1, Opt_AMR_WB); - } - } - - - /*----------------------------------------------------------------* - * Pitch sharpening - *----------------------------------------------------------------*/ - - cb_shape_fx( 1, 1, 0, sharpFlag, 0, g1, g2, p_Aq, code, tilt_code, shr(add(pt_pitch,26),6), 0 ); - - return stack_pulses; - -} diff --git a/src/libs/libevs/lib_enc/io_enc_fx.cpp b/src/libs/libevs/lib_enc/io_enc.cpp old mode 100755 new mode 100644 similarity index 75% rename from src/libs/libevs/lib_enc/io_enc_fx.cpp rename to src/libs/libevs/lib_enc/io_enc.cpp index 9aad0b5f..1dd77fd2 --- a/src/libs/libevs/lib_enc/io_enc_fx.cpp +++ b/src/libs/libevs/lib_enc/io_enc.cpp @@ -1,19 +1,16 @@ /*==================================================================================== - EVS Codec 3GPP TS26.442 Apr 03, 2018. Version 12.11.0 / 13.6.0 / 14.2.0 + EVS Codec 3GPP TS26.443 Nov 13, 2018. Version 12.11.0 / 13.7.0 / 14.3.0 / 15.1.0 ====================================================================================*/ #include #include #include -#include "stl.h" -#include "options.h" /* Compilation switches */ -#include "cnst_fx.h" /* Common constants */ -#include "prot_fx.h" /* Function prototypes */ -#include "rom_com_fx.h" /* Static table prototypes */ -#include "disclaimer.h" /* for disclaimer */ -#include +#include "options.h" +#include "cnst.h" +#include "prot.h" +#include "rom_com.h" #include "mime.h" -#include + /*-------------------------------------------------------------------* * Local functions @@ -22,29 +19,13 @@ static void usage_enc(void); static char *to_upper( char *str ); -static char * bit_rate_to_string(char *string, Word32 bit_rate) -{ - char *src, *dst; - - assert(bit_rate >= 100); - src = string + sprintf(string, "%i", bit_rate); - /* Insert a '.' before last two digits and remove last digit */ - /* What we want is to print %.2f of bit_rate/1000.0 */ - dst = src--; - *--dst = *--src; - *--dst = *--src; - *--dst = '.'; - - return string; -} - /*---------------------------------------------------------------------* * io_ini_enc() * * Processing of command line parameters *---------------------------------------------------------------------*/ -void io_ini_enc_fx( +void io_ini_enc( const int argc, /* i : command line arguments number */ char *argv[], /* i : command line arguments */ FILE **f_input, /* o : input signal file */ @@ -52,46 +33,45 @@ void io_ini_enc_fx( FILE **f_rate, /* o : bitrate switching profile (0 if N/A) */ FILE **f_bwidth, /* o : bandwidth switching profile (0 if N/A) */ FILE **f_rf, /* o : channel aware configuration file */ - Word16 *quietMode, /* o : limit printouts */ - Word16 *noDelayCmp, /* o : turn off delay compensation */ - Encoder_State_fx *st /* o : state structure */ + short *quietMode, /* o : limit printouts */ + short *noDelayCmp, /* o : turn off delay compensation */ + Encoder_State *st /* o : state structure */ ) { short i = 1, j; - short max_bwidth_user = -1; - char max_bwidth_string[4]; int tmp; + short max_bwidth_user = -1; + char max_bwidth_string[4]; char stmp[FILENAME_MAX]; + short rf_file_attempt = 1; char first_char; char rf_file_name[300]; - char bit_rate_string[14]; - print_disclaimer(stderr); + print_disclaimer( stderr ); /*-----------------------------------------------------------------* * Initialization *-----------------------------------------------------------------*/ - /*The complexity don't need to be taken into account given that is only initialisation */ *f_input = NULL; *f_stream = NULL; *quietMode = 0; + *noDelayCmp = 0; - st->input_Fs_fx = 16000; - st->total_brate_fx = ACELP_12k65; + st->input_Fs = 16000; + st->total_brate = ACELP_12k65; - st->Opt_AMR_WB_fx = 0; + st->Opt_AMR_WB = 0; + st->Opt_DTX_ON = 0; st->Opt_RF_ON = 0; st->rf_fec_offset = 0; st->rf_fec_indicator = 1; - - st->max_bwidth_fx = SWB; - st->interval_SID_fx = FIXED_SID_RATE; - st->var_SID_rate_flag_fx = 1; - st->Opt_HE_SAD_ON_fx = 0; - st->Opt_SC_VBR_fx = 0; - st->last_Opt_SC_VBR_fx = 0; + st->max_bwidth = SWB; + st->interval_SID = FIXED_SID_RATE; + st->var_SID_rate_flag = 1; + st->Opt_SC_VBR = 0; + st->last_Opt_SC_VBR =0; st->bitstreamformat = G192; if ( argc < 5 ) @@ -99,7 +79,6 @@ void io_ini_enc_fx( usage_enc(); } - /*-----------------------------------------------------------------* * Optional input arguments *-----------------------------------------------------------------*/ @@ -116,25 +95,26 @@ void io_ini_enc_fx( if (strcmp( to_upper(stmp), "-NB") == 0 || strcmp( to_upper(stmp), "NB") == 0) { - st->max_bwidth_fx = max_bwidth_user = NB; + st->max_bwidth = max_bwidth_user = NB; } else if (strcmp( to_upper(stmp), "-WB") == 0 || strcmp( to_upper(stmp), "WB") == 0) { - st->max_bwidth_fx = max_bwidth_user = WB; + st->max_bwidth = max_bwidth_user = WB; } else if (strcmp( to_upper(stmp), "-SWB") == 0 || strcmp( to_upper(stmp), "SWB") == 0) { - st->max_bwidth_fx = max_bwidth_user = SWB; + st->max_bwidth = max_bwidth_user = SWB; } else if (strcmp( to_upper(stmp), "-FB") == 0 || strcmp( to_upper(stmp), "FB") == 0) { - st->max_bwidth_fx = max_bwidth_user = FB; + st->max_bwidth = max_bwidth_user = FB; } else if ( (*f_bwidth = fopen(argv[i+1], "rb")) == NULL ) { fprintf(stderr, "Error: incorect bandwidth specification or the bandwidth profile file could not be opened: %s\n\n", argv[i+1]); usage_enc(); } + /* read first bandwidth value from the profile file (just to check validity) */ if ( *f_bwidth != NULL ) { @@ -146,7 +126,7 @@ void io_ini_enc_fx( rewind(*f_bwidth); - if ( (st->max_bwidth_fx = CONV_BWIDTH( stmp )) == -1 ) + if ( (st->max_bwidth = CONV_BWIDTH( stmp )) == -1 ) { fprintf (stderr,"Error: incorrect bandwidth specified (only NB, WB, SWB and FB are supported)\n\n"); usage_enc(); @@ -197,16 +177,17 @@ void io_ini_enc_fx( tmp = FIXED_SID_RATE; } - st->Opt_DTX_ON_fx = 1; + st->Opt_DTX_ON = 1; + if( tmp == 0 ) { - st->var_SID_rate_flag_fx = 1; - st->interval_SID_fx = 0; + st->var_SID_rate_flag = 1; + st->interval_SID = 0; } else if (tmp >= 3 && tmp <= 100) { - st->var_SID_rate_flag_fx = 0; - st->interval_SID_fx = (short)tmp; + st->var_SID_rate_flag = 0; + st->interval_SID = (short)tmp; } else { @@ -216,15 +197,14 @@ void io_ini_enc_fx( } /*-----------------------------------------------------------------* - * Deactivate delay compensation + * deactivate delay compensation *-----------------------------------------------------------------*/ + else if( strcmp( to_upper(argv[i]), "-NO_DELAY_CMP" ) == 0 ) { *noDelayCmp = 1; i++; } - - /*-----------------------------------------------------------------* * Activate channel-aware mode *-----------------------------------------------------------------*/ @@ -233,25 +213,24 @@ void io_ini_enc_fx( { st->Opt_RF_ON = 1; i++; - - if( i < argc - 4 ) + if( i < argc-4 ) { rf_file_attempt = 1; sscanf(argv[i], "%s", rf_file_name); - if ( ( strcmp( to_upper(argv[i]), "LO") == 0 ) ) + if (strcmp( to_upper(argv[i]), "LO") == 0) { st->rf_fec_indicator = 0; i++; rf_file_attempt = 0; } - else if ( ( strcmp( to_upper(argv[i]), "HI") == 0 ) ) + else if (strcmp( to_upper(argv[i]), "HI") == 0) { st->rf_fec_indicator = 1; i++; rf_file_attempt = 0; } - if ( ( sscanf(argv[i], "%d", &tmp) == 1 ) && ( i < argc - 4 ) ) + if ( ( sscanf(argv[i], "%d", &tmp) == 1 ) && ( i < argc-4 ) ) { if ( tmp == 0 ) { @@ -262,8 +241,8 @@ void io_ini_enc_fx( } else if( tmp == 2 || tmp == 3 || tmp == 5 || tmp == 7 ) { - st->rf_fec_offset = (Word16)tmp; - i++; + st->rf_fec_offset = tmp; + i += 1; rf_file_attempt = 0; } else @@ -298,13 +277,14 @@ void io_ini_enc_fx( } /*-----------------------------------------------------------------* - * MIME output file format - *-----------------------------------------------------------------*/ + * MIME output file format + *-----------------------------------------------------------------*/ else if( strcmp( to_upper(argv[i]), "-MIME" ) == 0 ) { st->bitstreamformat = MIME; i++; } + /*-----------------------------------------------------------------* * Option not recognized *-----------------------------------------------------------------*/ @@ -314,6 +294,7 @@ void io_ini_enc_fx( fprintf(stderr, "Error: option not recognized, %s\n\n", argv[i]); usage_enc(); } + } /* end of while */ /*-----------------------------------------------------------------* @@ -336,7 +317,7 @@ void io_ini_enc_fx( } /* read first bitrate value from the profile file (just to check validity)*/ - if ( fread( &st->total_brate_fx, 4, 1, *f_rate ) != 1 && feof(*f_rate) ) + if ( fread( &st->total_brate, 4, 1, *f_rate ) != 1 && feof(*f_rate) ) { fprintf (stderr,"Error: cannot read the bitrate profile file\n\n"); usage_enc(); @@ -348,39 +329,38 @@ void io_ini_enc_fx( } else { - st->total_brate_fx = tmp; + st->total_brate = tmp; /* channel-aware mode is supported only at 13.20 */ - if( st->Opt_RF_ON && st->total_brate_fx != ACELP_13k20 ) + if( st->Opt_RF_ON && st->total_brate != ACELP_13k20 ) { st->Opt_RF_ON = 0; } } /* SC-VBR at 5.90 kbps */ - if ( st->total_brate_fx == ACELP_5k90 ) + if ( st->total_brate == ACELP_5k90 ) { - st->Opt_SC_VBR_fx = 1; - st->last_Opt_SC_VBR_fx = st->Opt_SC_VBR_fx; - st->total_brate_fx = ACELP_7k20; - - if ( st->max_bwidth_fx != NB ) + st->Opt_SC_VBR = 1; + st->last_Opt_SC_VBR = st->Opt_SC_VBR; + st->total_brate = ACELP_7k20; + if ( st->max_bwidth != NB ) { - st->max_bwidth_fx = WB; + st->max_bwidth = WB; } } /* check if the entered bitrate is supported */ j = 0; - while ( j < SIZE_BRATE_TBL && st->total_brate_fx != brate_tbl[j] ) + while ( j < SIZE_BRATE_TBL && st->total_brate != brate_tbl[j] ) { j++; } - /* AMR-WB IO/EVS primary mode determination */ + /* AMR-WB IO mode/EVS primary mode determination */ if ( j >= SIZE_BRATE_TBL ) { - switch ( st->total_brate_fx ) + switch ( st->total_brate ) { case ACELP_6k60 : case ACELP_8k85 : @@ -394,16 +374,17 @@ void io_ini_enc_fx( break; default : { - fprintf(stderr, "Error: Incorrect bitrate specification: %d\n\n", st->total_brate_fx ); + fprintf(stderr, "Error: Incorrect bitrate specification: %ld\n\n", st->total_brate ); usage_enc(); } + break; } - st->Opt_AMR_WB_fx = 1; + st->Opt_AMR_WB = 1; } else { - st->Opt_AMR_WB_fx = 0; + st->Opt_AMR_WB = 0; } i++; @@ -420,16 +401,15 @@ void io_ini_enc_fx( if( i < argc-2 ) { - st->input_Fs_fx = (int) atoi( argv[i] ) * 1000; - if( st->Opt_RF_ON && st->input_Fs_fx == 8000 ) + st->input_Fs = (int) atoi( argv[i] ) * 1000; + if( st->Opt_RF_ON && st->input_Fs == 8000 ) { /* Reset RF parameters if NB input_Fs; For FB input @13.2kbps, the codec is shifted down to SWB below. */ st->Opt_RF_ON = 0; st->rf_fec_offset = 0; } - - if( (st->input_Fs_fx != 8000) && ( st->input_Fs_fx != 16000) && (st->input_Fs_fx != 32000) && (st->input_Fs_fx != 48000) ) + if( (st->input_Fs != 8000) && ( st->input_Fs != 16000) && (st->input_Fs != 32000) && (st->input_Fs != 48000) ) { fprintf(stderr, "Error: %d kHz is not a supported sampling rate\n\n", atoi( argv[i] ) ); usage_enc(); @@ -442,7 +422,6 @@ void io_ini_enc_fx( fprintf(stderr, "Error: no input sampling frequency specified\n\n"); usage_enc(); } - /*-----------------------------------------------------------------* * Input file *-----------------------------------------------------------------*/ @@ -475,6 +454,7 @@ void io_ini_enc_fx( fprintf(stderr, "Error: output bitstream file %s could not be opened\n\n", argv[i]); usage_enc(); } + fprintf(stdout, "Output bitstream file: %s\n", argv[i]); i++; /* If MIME/storage format selected, write the magic number at the beginning of the bitstream file */ @@ -483,9 +463,10 @@ void io_ini_enc_fx( char buf[4]; fwrite(EVS_MAGIC_NUMBER, sizeof(char), strlen(EVS_MAGIC_NUMBER), *f_stream); buf[0] = buf[1] = buf[2] = 0; - buf[3] = 1; + buf[3] = 1; /* one channel */ fwrite(&buf, sizeof(char), 4, *f_stream); fprintf(stdout, "Output bitstream file format: MIME"); + } } else @@ -498,86 +479,73 @@ void io_ini_enc_fx( /* Prevent st->max_bwidth from being higher than Fs/2 */ - if ( st->input_Fs_fx == 8000 && st->max_bwidth_fx > NB ) + if ( st->input_Fs == 8000 && st->max_bwidth > NB ) { - st->max_bwidth_fx = NB; + st->max_bwidth = NB; } - else if ( st->input_Fs_fx == 16000 && st->max_bwidth_fx > WB ) + else if ( st->input_Fs == 16000 && st->max_bwidth > WB ) { - st->max_bwidth_fx = WB; + st->max_bwidth = WB; } - else if ( st->input_Fs_fx == 32000 && st->max_bwidth_fx > SWB ) + else if ( st->input_Fs == 32000 && st->max_bwidth > SWB ) { - st->max_bwidth_fx = SWB; + st->max_bwidth = SWB; } - IF ( st->Opt_AMR_WB_fx ) + if ( st->Opt_AMR_WB ) { st->codec_mode = MODE1; - move16(); } - ELSE + else { - SWITCH ( st->total_brate_fx ) + switch ( st->total_brate ) { case 5900: st->codec_mode = MODE1; - move16(); - BREAK; + break; case 7200: st->codec_mode = MODE1; - move16(); - BREAK; + break; case 8000: st->codec_mode = MODE1; - move16(); - BREAK; + break; case 9600: st->codec_mode = MODE2; - move16(); - BREAK; + break; case 13200: st->codec_mode = MODE1; - move16(); - BREAK; + break; case 16400: st->codec_mode = MODE2; - move16(); - BREAK; + break; case 24400: st->codec_mode = MODE2; - move16(); - BREAK; + break; case 32000: st->codec_mode = MODE1; - move16(); - BREAK; + break; case 48000: st->codec_mode = MODE2; - move16(); - BREAK; + break; case 64000: st->codec_mode = MODE1; - move16(); - BREAK; + break; case 96000: st->codec_mode = MODE2; - move16(); - BREAK; + break; case 128000: st->codec_mode = MODE2; - move16(); - BREAK; + break; } } - IF( st->total_brate_fx == 13200 && st->Opt_RF_ON == 1) + if( st->total_brate == 13200 && st->Opt_RF_ON == 1) { st->codec_mode = MODE2; } st->last_codec_mode = st->codec_mode; - move16(); + /*-----------------------------------------------------------------* * Print info on screen *-----------------------------------------------------------------*/ @@ -585,34 +553,34 @@ void io_ini_enc_fx( * Print input signal sampling frequency *-----------------------------------------------------------------*/ - fprintf(stdout, "Input sampling rate: %d Hz\n", st->input_Fs_fx); + fprintf(stdout, "Input sampling rate: %d Hz\n", st->input_Fs); /*-----------------------------------------------------------------* * Print bitrate *-----------------------------------------------------------------*/ - if ( st->Opt_SC_VBR_fx ) + if ( st->Opt_SC_VBR ) { - fprintf(stdout, "Average bitrate: %s kbps\n", bit_rate_to_string(bit_rate_string, ACELP_5k90)); + fprintf(stdout, "Average bitrate: %.2f kbps\n", (float)ACELP_5k90/1000); } else { - fprintf(stdout, "Bitrate: %s kbps\n", bit_rate_to_string(bit_rate_string, st->total_brate_fx)); + fprintf(stdout, "Bitrate: %.2f kbps\n", (float)st->total_brate/1000); } /*-----------------------------------------------------------------* * Print CNG update interval, if DTX is activated *-----------------------------------------------------------------*/ - if ( st->Opt_DTX_ON_fx ) + if ( st->Opt_DTX_ON ) { - if( st->var_SID_rate_flag_fx ) + if( st->var_SID_rate_flag ) { fprintf(stdout, "DTX: ON, variable CNG update interval\n"); } else { - fprintf(stdout, "DTX: ON, CNG update interval = %d frames\n", st->interval_SID_fx); + fprintf(stdout, "DTX: ON, CNG update interval = %d frames\n", st->interval_SID); } } @@ -630,13 +598,12 @@ void io_ini_enc_fx( { fprintf(stdout, "Channel-aware mode: ON, Channel-aware config file name: %s \n", rf_file_name ); } - } /*-----------------------------------------------------------------* * Print potential limitation of audio bandwidth *-----------------------------------------------------------------*/ - switch(st->max_bwidth_fx) + switch( st->max_bwidth ) { case NB: strncpy(max_bwidth_string, "NB\0", sizeof(max_bwidth_string)); @@ -655,24 +622,24 @@ void io_ini_enc_fx( break; } - if ( st->Opt_SC_VBR_fx && !st->Opt_DTX_ON_fx) + if ( st->Opt_SC_VBR && !st->Opt_DTX_ON) { fprintf(stderr, "\nError: SC-VBR 5900 bit/s not supported without DTX\n\n"); exit(-1); } - if ( (max_bwidth_user != -1) && (st->max_bwidth_fx != max_bwidth_user) ) + if ( (max_bwidth_user != -1) && (st->max_bwidth != max_bwidth_user) ) { fprintf(stdout, "\nBandwidth limited to %s.\n", max_bwidth_string); } - if( (max_bwidth_user == -1) && (st->max_bwidth_fx < FB) && (st->input_Fs_fx == 48000) ) + if( (max_bwidth_user == -1) && (st->max_bwidth < FB) && (st->input_Fs == 48000) ) { fprintf(stdout, "\nBandwidth limited to %s. To enable FB coding, please use -max_band FB.\n", max_bwidth_string); } - if( (st->max_bwidth_fx == FB) && (st->total_brate_fx < ACELP_16k40) ) + if( (st->max_bwidth == FB) && (st->total_brate < ACELP_16k40) ) { - fprintf(stdout, "\nFB coding not supported below %s kbps. ", bit_rate_to_string(bit_rate_string, ACELP_16k40)); - if( st->total_brate_fx < ACELP_9k60 ) + fprintf(stdout, "\nFB coding not supported below %.2f kbps. ", ACELP_16k40 / 1000.f); + if( st->total_brate < ACELP_9k60 ) { fprintf(stdout, "Switching to WB.\n"); } @@ -681,46 +648,44 @@ void io_ini_enc_fx( fprintf(stdout, "Switching to SWB.\n"); } } - if( (st->max_bwidth_fx == SWB) && (st->total_brate_fx < ACELP_9k60) ) + if( (st->max_bwidth == SWB) && (st->total_brate < ACELP_9k60) ) { - fprintf(stdout, "\nSWB coding not supported below %s kbps. Switching to WB.", bit_rate_to_string(bit_rate_string, ACELP_9k60)); + fprintf(stdout, "\nSWB coding not supported below %.2f kbps. Switching to WB.", ACELP_9k60 / 1000.f); } /* in case of 8kHz input sampling or "-max_band NB", require the total bitrate to be below 24.40 kbps */ - if ( ((st->max_bwidth_fx == NB) || (st->input_Fs_fx == 8000)) && (st->total_brate_fx > ACELP_24k40) ) + if ( ((st->max_bwidth == NB) || (st->input_Fs == 8000)) && (st->total_brate > ACELP_24k40) ) { - fprintf(stderr, "\nError: Unsupported mode NB %d bit/s, NB mode supports rates 5900-24400 bit/s\n\n", st->total_brate_fx); - exit(-1); + fprintf(stderr, "\nError: Unsupported mode NB %ld bit/s, NB mode supports rates 5900-24400 bit/s\n\n", st->total_brate); + usage_enc(); } + fprintf(stdout, "\n"); return; } /*---------------------------------------------------------------------* - * read_next_rfparam_fx() + * read_next_rfparam() * * Read next channel aware configuration parameters * p: RF FEC indicator HI or LO, and * o: RF FEC offset in number of frame (2, 3, 5, or 7) *---------------------------------------------------------------------*/ -void read_next_rfparam_fx( - Word16 *rf_fec_offset, /* o: rf offset */ - Word16 *rf_fec_indicator, /* o: rf FEC indicator */ - FILE* f_rf /* i: file pointer to read parameters */ -) +void read_next_rfparam(short *rf_fec_offset, /* o: rf offset */ + short *rf_fec_indicator, /* o: rf FEC indicator */ + FILE *f_rf /* i: file pointer to read parameters */ + ) { char rline[10], str[4]; - Word32 tmp; + short tmp; /* initialize */ *rf_fec_offset = 0; *rf_fec_indicator = 1; - if( f_rf != NULL ) { - while ( fgets(rline, 10, f_rf) == NULL && feof(f_rf) ) { rewind(f_rf); @@ -731,7 +696,7 @@ void read_next_rfparam_fx( return; } - if ( sscanf (rline,"%s %d",str,&tmp) != 2) + if ( sscanf (rline,"%s %hd",str,&tmp) != 2) { fprintf(stderr, "Error in the RF configuration file. There is no proper configuration line.\n"); exit(-1); @@ -755,7 +720,7 @@ void read_next_rfparam_fx( /* Read RF FEC offset */ if( tmp == 0 || tmp == 2 || tmp == 3 || tmp == 5 || tmp == 7 ) { - *rf_fec_offset = (Word16)tmp; + *rf_fec_offset = tmp; } else { @@ -765,27 +730,24 @@ void read_next_rfparam_fx( } - - /*---------------------------------------------------------------------* * read_next_brate() * * Read next bitrate from profile file (only if invoked on cmd line) *---------------------------------------------------------------------*/ -void read_next_brate_fx( - Word32 *total_brate, /* i/o: total bitrate */ - const Word32 last_total_brate, /* i : last total bitrate */ - FILE *f_rate, /* i : bitrate switching profile (0 if N/A) */ - Word32 input_Fs, /* i : input sampling frequency */ - Word16 *Opt_AMR_WB, /* i : flag indicating AMR-WB IO mode */ - Word16 *Opt_SC_VBR, /* i/o: SC-VBR flag */ - Word16 *codec_mode /* i/o: MODE1 or MODE2 */ +void read_next_brate( + long *total_brate, /* i/o: total bitrate */ + const int last_total_brate, /* i : last total bitrate */ + FILE *f_rate, /* i : bitrate switching profile (0 if N/A) */ + int input_Fs, /* i : input sampling frequency */ + short *Opt_AMR_WB, /* i : flag indicating AMR-WB IO mode */ + short *Opt_SC_VBR, /* i/o: SC-VBR flag */ + short *codec_mode /* i/o: Mode 1 or 2 */ ) { - Word16 j; + short j; - /*The complexity don't need to be taken into account given that is only simulation */ /* read next bitrate value from the profile file */ if( f_rate != NULL ) { @@ -817,7 +779,7 @@ void read_next_brate_fx( j++; } - /* AMR-WB IO/EVS primary mode determination */ + /* AMR-WB IO mode/EVS primary mode determination */ if ( j >= SIZE_BRATE_TBL ) { switch (*total_brate) @@ -834,7 +796,7 @@ void read_next_brate_fx( break; default : { - fprintf(stderr, "Error: Incorrect bitrate specification: %d\n\n", *total_brate ); + fprintf(stderr, "Error: Incorrect bitrate specification: %ld\n\n", *total_brate ); usage_enc(); } break; @@ -846,11 +808,13 @@ void read_next_brate_fx( { *Opt_AMR_WB = 0; } + /* in case of 8kHz signal, limit the total bitrate to 24.40 kbps */ - if ( (input_Fs == 8000) && (*total_brate > ACELP_24k40) ) + if ( input_Fs == 8000 && *total_brate > ACELP_24k40 ) { *total_brate = ACELP_24k40; } + if ( *Opt_AMR_WB ) { *codec_mode = MODE1; @@ -861,73 +825,62 @@ void read_next_brate_fx( { case 2800: *codec_mode = MODE1; - move16(); - BREAK; + break; case 5900: *codec_mode = MODE1; - move16(); - BREAK; + break; case 7200: *codec_mode = MODE1; - move16(); - BREAK; + break; case 8000: *codec_mode = MODE1; - move16(); - BREAK; + break; case 9600: *codec_mode = MODE2; - move16(); - BREAK; + break; case 13200: *codec_mode = MODE1; - move16(); - BREAK; + break; case 16400: *codec_mode = MODE2; - move16(); - BREAK; + break; case 24400: *codec_mode = MODE2; - move16(); - BREAK; + break; case 32000: *codec_mode = MODE1; - move16(); - BREAK; + break; case 48000: *codec_mode = MODE2; - move16(); - BREAK; + break; case 64000: *codec_mode = MODE1; - move16(); - BREAK; + break; case 96000: *codec_mode = MODE2; - move16(); - BREAK; + break; case 128000: *codec_mode = MODE2; - move16(); - BREAK; + break; } } + return; } + /*---------------------------------------------------------------------* * read_next_bwidth() * * Read next bandwidth from profile file (only if invoked on cmd line) *---------------------------------------------------------------------*/ -void read_next_bwidth_fx( - Word16 *max_bwidth, /* i/o: maximum encoded bandwidth */ - FILE *f_bwidth, /* i : bandwidth switching profile (0 if N/A) */ - Word32 *bwidth_profile_cnt, /* i/o: counter of frames for bandwidth switching profile file */ - Word32 input_Fs /* i : input sampling frequency */ +void read_next_bwidth( + short *max_bwidth, /* i/o: maximum encoded bandwidth */ + FILE *f_bwidth, /* i : bandwidth switching profile (0 if N/A) */ + long *bwidth_profile_cnt, /* i/o: counter of frames for bandwidth switching profile file */ + int input_Fs /* i : input sampling rate */ ) { int res; @@ -936,7 +889,7 @@ void read_next_bwidth_fx( if ( *bwidth_profile_cnt == 0 ) { /* read next bandwidth value and number of frames from the profile file */ - while ( (res = fscanf( f_bwidth, "%d %3s", bwidth_profile_cnt, stmp)) != 2 && feof(f_bwidth)) + while ( (res = fscanf( f_bwidth, "%ld %3s", bwidth_profile_cnt, stmp)) != 2 && feof(f_bwidth)) { rewind(f_bwidth); } @@ -960,7 +913,7 @@ void read_next_bwidth_fx( *max_bwidth = FB; } - /* Prevent max_bwidth from being higher than Fs/2 */ + /* Prevent st->max_bwidth from being higher than Fs/2 */ if ( input_Fs == 8000 && *max_bwidth > NB ) { *max_bwidth = NB; @@ -974,6 +927,7 @@ void read_next_bwidth_fx( *max_bwidth = SWB; } + } else { @@ -1044,10 +998,11 @@ static void usage_enc( void ) fprintf(stdout, " alternatively, B can be a text file where each line contains\n"); fprintf(stdout, " \"nb_frames B\"\n"); fprintf(stdout, "-no_delay_cmp : Turn off delay compensation\n"); - fprintf(stdout, "-mime : Mime output bitstream file format\n"); - fprintf(stdout, " The encoder produces TS26.445 Annex.2.6 Mime Storage Format, (not RFC4867 Format)\n"); - fprintf(stdout, " default output bitstream file format is G.192\n"); + fprintf(stdout, "-mime : Mime output bitstream file format\n"); + fprintf(stdout, " The encoder produces TS26.445 Annex.2.6 Mime Storage Format, (not RFC4867 Mime Format).\n"); + fprintf(stdout, " default output bitstream file format is G.192\n"); fprintf(stdout, "\n"); + exit(-1); } diff --git a/src/libs/libevs/lib_enc/isf_enc_amr_wb.cpp b/src/libs/libevs/lib_enc/isf_enc_amr_wb.cpp new file mode 100644 index 00000000..ecd5e918 --- /dev/null +++ b/src/libs/libevs/lib_enc/isf_enc_amr_wb.cpp @@ -0,0 +1,487 @@ +/*==================================================================================== + EVS Codec 3GPP TS26.443 Nov 13, 2018. Version 12.11.0 / 13.7.0 / 14.3.0 / 15.1.0 + ====================================================================================*/ + +#include +#include "options.h" +#include "cnst.h" +#include "rom_enc.h" +#include "rom_com.h" +#include "prot.h" + + +/*-----------------------------------------------------------------* + * Local constants + *-----------------------------------------------------------------*/ + +#define DICO1_NS_19b 16 /* codebook dimensions for SID ISF quantizers */ +#define DICO2_NS_19b 16 +#define DICO3_NS_19b 16 +#define DICO4_NS_19b 8 +#define DICO5_NS_19b 16 + +#define DICO1_NS_28b 64 +#define DICO2_NS_28b 64 +#define DICO3_NS_28b 64 +#define DICO4_NS_28b 32 +#define DICO5_NS_28b 32 + +#define N_SURV_MAX 4 /* maximum number of survivors */ + +/*---------------------------------------------------------------------* + * Local functions + *---------------------------------------------------------------------*/ + +static void qisf_ns_28b( Encoder_State *st, float *isf ); +static void qisf_2s_46b( Encoder_State *st, float *isf, short nb_surv, float *mem_AR, float *mem_MA ); +static void qisf_2s_36b( Encoder_State *st, float *isf, short nb_surv, float *mem_AR, float *mem_MA ); +static void VQ_stage1(const float *x, const float *dico, const short dim, const short dico_size, short *index, const short surv); +static short sub_VQ(float *x, const float *dico, const short dim, const short dico_size, float *distance); + +/*-------------------------------------------------------------------* + * isf_enc_amr_wb() + * + * Quantization of ISF parameters in AMR-WB IO mode + *-------------------------------------------------------------------*/ + +void isf_enc_amr_wb( + Encoder_State *st, /* i/o: state structure */ + float *isf_new, /* i/o : quantized ISF vector */ + float *isp_new, /* i/o: ISP vector to quantize/quantized */ + float *Aq, /* o : quantized A(z) for 4 subframes */ + float *stab_fac /* o : ISF stability factor */ +) +{ + + /*---------------------------------* + * ISF quantization of SID frames + *---------------------------------*/ + + if ( st->core_brate == SID_1k75 ) + { + qisf_ns_28b( st, isf_new ); + + reorder_isf( isf_new, ISF_GAP, M, INT_FS_12k8 ); + + isf2isp( isf_new, isp_new, M, INT_FS_12k8 ); + + /* return if SID frame (conversion to A(z) done in the calling function) */ + return; + } + + /* check resonance for pitch clipping algorithm */ + gp_clip_test_lsf( st->core_brate, isf_new, st->clip_var, 1 ); + + /*---------------------------------------* + * ISF quantization of all other frames + *---------------------------------------*/ + + if ( st->core_brate == ACELP_6k60 ) + { + qisf_2s_36b( st, isf_new, 4, st->mem_AR, st->mem_MA); + } + else if( st->core_brate >= ACELP_8k85 ) + { + qisf_2s_46b( st, isf_new, 4, st->mem_AR, st->mem_MA); + } + + reorder_isf( isf_new, ISF_GAP, M, INT_FS_12k8 ); + + /* convert quantized ISFs back to ISPs */ + isf2isp( isf_new, isp_new, M, INT_FS_12k8 ); + + /*------------------------------------------------------------------* + * ISP interpolation + * A(z) calculation + *------------------------------------------------------------------*/ + + if( st->rate_switching_reset ) + { + mvr2r( isf_new, st->lsf_old, M ); + mvr2r( isp_new, st->lsp_old, M ); + } + + int_lsp( L_FRAME, st->lsp_old, isp_new, Aq, M, interpol_isp_amr_wb, 1 ); + + /*------------------------------------------------------------------* + * Calculate ISF stability (distance between old ISF and current ISF) + *------------------------------------------------------------------*/ + + *stab_fac = lsf_stab( isf_new, st->lsf_old, 1, st->L_frame ); + + + return; +} + +/*-------------------------------------------------------------------* +* qisf_ns_28b() +* +* ISF quantizer for SID frames (only in AMR-WB IO mode) +*-------------------------------------------------------------------*/ + +static void qisf_ns_28b( + Encoder_State *st, /* i/o: encoder state structure */ + float *isf /* i/o: unquantized/quantized ISF vector */ +) +{ + short i, indice[5]; + float tmp; + + for (i=0; i do not allow */ + + /* write indices to array */ + push_indice( st, IND_ISF_0_0, indice[0], 6 ); + push_indice( st, IND_ISF_0_1, indice[1], 6 ); + push_indice( st, IND_ISF_0_2, indice[2], 6 ); + push_indice( st, IND_ISF_0_3, indice[3], 5 ); + push_indice( st, IND_ISF_0_4, indice[4], 5 ); + + /* decoding the ISFs */ + disf_ns_28b( indice, isf ); + + return; +} + + +/*---------------------------------------------------------------------* + * qisf_2s_36b() + * + * ISF quantizer for AMR-WB 6k60 frames + * + * The ISF vector is quantized using two-stage MA-prediction VQ with split-by-2 + * in 1st stage and split-by-3 in the second stage. + *---------------------------------------------------------------------*/ + +static void qisf_2s_36b( + Encoder_State *st, /* i/o: encoder state structure */ + float *isf, /* i/o: unquantized/quantized ISF vector */ + short nb_surv, /* i : number of survivors (1, 2, 3 or 4) */ + float *mem_AR, /* o : quantizer memory for AR model */ + float *mem_MA /* i/o: quantizer memory for MA model */ +) +{ + short i, k, indice[5], tmp_ind[2]; + short surv1[N_SURV_MAX]; /* indices of survivors from 1st stage */ + float temp, min_err, distance, isf2[M]; + + /*------------------------------------------------------------------------* + * Subtract mean + *------------------------------------------------------------------------*/ + + for (i=0; i N_SURV_MAX) + { + nb_surv = N_SURV_MAX; + } + + for (k=0; k N_SURV_MAX) + { + nb_surv = N_SURV_MAX; + } + + for (k=0; kk; l--) + { + dist_min[l] = dist_min[l-1]; + index[l] = index[l-1]; + } + dist_min[k] = dist; + index[k] = i; + break; + } + } + } + return; +} + +/*-------------------------------------------------------------------* + * sub_VQ() + * + * Quantization of a subvector in Split-VQ of ISFs + *-------------------------------------------------------------------*/ + +static short sub_VQ( /* o : selected codebook vector index */ + float *x, /* i/o: ISF vector */ + const float *dico, /* i : ISF codebook */ + const short dim, /* i : codebook dimension */ + const short dico_size, /* i : codebook size */ + float *distance /* o : quantization error (min. distance) */ +) +{ + float dist_min, dist, temp; + const float *p_dico; + short i, j, index; + + + dist_min = 1.0e30f; + p_dico = dico; + + index = 0; + for (i = 0; i < dico_size; i++) + { + dist = 0.0f; + for (j = 0; j < dim; j++) + { + temp = x[j] - *p_dico++; + dist += temp * temp; + } + if (dist < dist_min) + { + dist_min = dist; + index = i; + } + } + + *distance = dist_min; + + /* Reading the selected vector */ + p_dico = &dico[index * dim]; + for (j = 0; j < dim; j++) + { + x[j] = *p_dico++; + } + return index; +} diff --git a/src/libs/libevs/lib_enc/isf_enc_amr_wb_fx.cpp b/src/libs/libevs/lib_enc/isf_enc_amr_wb_fx.cpp deleted file mode 100755 index cefdb328..00000000 --- a/src/libs/libevs/lib_enc/isf_enc_amr_wb_fx.cpp +++ /dev/null @@ -1,544 +0,0 @@ -/*==================================================================================== - EVS Codec 3GPP TS26.442 Apr 03, 2018. Version 12.11.0 / 13.6.0 / 14.2.0 - ====================================================================================*/ - -#include "options.h" /* Compilation switches */ -#include "cnst_fx.h" /* Common constants */ -#include "rom_enc_fx.h" /* Encoder static table prototypes */ -#include "rom_com_fx.h" /* Static table prototypes */ -#include "prot_fx.h" /* Function prototypes */ -#include "stl.h" /* required by wmc_tool */ - - -/*-----------------------------------------------------------------* - * Local constants - *-----------------------------------------------------------------*/ - -#define DICO1_NS_19b 16 /* codebook dimensions for SID ISF quantizers */ -#define DICO2_NS_19b 16 -#define DICO3_NS_19b 16 -#define DICO4_NS_19b 8 -#define DICO5_NS_19b 16 - -#define DICO1_NS_28b 64 -#define DICO2_NS_28b 64 -#define DICO3_NS_28b 64 -#define DICO4_NS_28b 32 -#define DICO5_NS_28b 32 - -#define N_SURV_MAX 4 /* maximum number of survivors */ - -/*---------------------------------------------------------------------* - * Local functions - *---------------------------------------------------------------------*/ - -static void qisf_ns_28b_fx( Encoder_State_fx *st, Word16 *isf ); -static void qisf_2s_46b_fx( Encoder_State_fx *st, Word16 *isf, Word16 nb_surv, Word16 *mem_AR, Word16 *mem_MA ); -static void qisf_2s_36b_fx( Encoder_State_fx *st, Word16 *isf, Word16 nb_surv, Word16 *mem_AR, Word16 *mem_MA ); -static void VQ_stage1_fx(const Word16 *x, const Word16 *dico, const Word16 dim, const Word16 dico_size, Word16 *index, const Word16 surv); -static Word16 sub_VQ_fx(Word16 *x, const Word16 *dico, const Word16 dim, const Word16 dico_size, Word32 *distance); - -/*-------------------------------------------------------------------* - * isf_enc_amr_wb() - * - * Quantization of ISF parameters in AMR-WB IO mode - *-------------------------------------------------------------------*/ - -void isf_enc_amr_wb_fx( - Encoder_State_fx *st, /* i/o: state structure */ - Word16 *isf_new, /* i/o: quantized ISF vector */ - Word16 *isp_new, /* i/o: ISP vector to quantize/quantized */ - Word16 *Aq, /* o : quantized A(z) for 4 subframes */ - Word16 *stab_fac /* o : ISF stability factor */ -) -{ - - - /*---------------------------------* - * ISF quantization of SID frames - *---------------------------------*/ - - IF ( L_sub(st->core_brate_fx,SID_1k75) == 0 ) - { - qisf_ns_28b_fx( st, isf_new ); - - reorder_isf_fx( isf_new, ISF_GAP_FX, M, Fs_2); - - E_LPC_isf_isp_conversion( isf_new, isp_new, M); - - /* return if SID frame (conversion to A(z) done in the calling function) */ - return; - } - - /* check resonance for pitch clipping algorithm */ - gp_clip_test_isf_fx( st->core_brate_fx, isf_new, st->clip_var_fx, 1 ); - - /*---------------------------------------* - * ISF quantization of all other frames - *---------------------------------------*/ - - IF ( L_sub(st->core_brate_fx,ACELP_6k60) == 0 ) - { - qisf_2s_36b_fx( st, isf_new, 4, st->mem_AR_fx, st->mem_MA_fx ); - } - ELSE IF( L_sub(st->core_brate_fx,ACELP_8k85) >= 0 ) - { - qisf_2s_46b_fx( st, isf_new, 4, st->mem_AR_fx, st->mem_MA_fx ); - } - - reorder_isf_fx( isf_new, ISF_GAP_FX, M, Fs_2 ); - /* convert quantized ISFs back to ISPs */ - E_LPC_isf_isp_conversion( isf_new, isp_new, M); - - /*-------------------------------------------------------------------------------------* - * ISP interpolation - * A(z) calculation - *-------------------------------------------------------------------------------------*/ - - if(st->rate_switching_reset) - { - Copy( isf_new, st->lsf_old_fx, M ); - Copy( isp_new, st->lsp_old_fx, M ); - } - - int_lsp_fx( L_FRAME, st->lsp_old_fx, isp_new, Aq, M, interpol_isp_amr_wb_fx, 1 ); - - /*------------------------------------------------------------------* - * Calculate ISF stability (distance between old ISF and current ISF) - *------------------------------------------------------------------*/ - - *stab_fac = lsf_stab_fx( isf_new, st->lsf_old_fx, 1, L_FRAME ); - - - return; -} - -/*-------------------------------------------------------------------* -* qisf_ns_28b() -* -* ISF quantizer for SID frames (only in AMR-WB IO mode) -*-------------------------------------------------------------------*/ - -static void qisf_ns_28b_fx( - Encoder_State_fx *st, /* i/o: encoder state structure */ - Word16 *isf /* i/o: unquantized/quantized ISF vector */ -) -{ - Word16 i, indice[5]; - Word32 tmp; - - FOR (i=0; i do not allow */ - - /* write indices to array */ - push_indice_fx( st, IND_ISF_0_0, indice[0], 6 ); - push_indice_fx( st, IND_ISF_0_1, indice[1], 6 ); - push_indice_fx( st, IND_ISF_0_2, indice[2], 6 ); - push_indice_fx( st, IND_ISF_0_3, indice[3], 5 ); - push_indice_fx( st, IND_ISF_0_4, indice[4], 5 ); - - /* decoding the ISFs */ - disf_ns_28b_fx( indice, isf); - - return; -} - - -/*---------------------------------------------------------------------* - * qisf_2s_36b() - * - * ISF quantizer for AMR-WB 6k60 frames - * - * The ISF vector is quantized using two-stage MA-prediction VQ with split-by-2 - * in 1st stage and split-by-3 in the second stage. - *---------------------------------------------------------------------*/ - -static void qisf_2s_36b_fx( - Encoder_State_fx *st, /* i/o: encoder state structure */ - Word16 *isf, /* i/o: unquantized/quantized ISF vector */ - Word16 nb_surv, /* i : number of survivors (1, 2, 3 or 4) */ - Word16 *mem_AR, /* o : quantizer memory for AR model */ - Word16 *mem_MA /* i/o: quantizer memory for MA model */ -) -{ - Word16 i, k, indice[5], tmp_ind[2]; - Word16 surv1[N_SURV_MAX], tmp16; /* indices of survivors from 1st stage */ - Word32 temp, min_err, distance; - Word16 isf2[M]; - - /*------------------------------------------------------------------------* - * Subtract mean - *------------------------------------------------------------------------*/ - - FOR (i=0; ik; l--) - { - dist_min[l] = dist_min[l - 1]; - move32(); - index[l] = index[l - 1]; - move16(); - } - dist_min[k] = dist; - move32(); - index[k] = i; - move16(); - BREAK; - } - } - } - return; -} - -/*-------------------------------------------------------------------* - * sub_VQ_fx() - * - * Quantization of a subvector in Split-VQ of ISFs - *-------------------------------------------------------------------*/ - -static Word16 sub_VQ_fx( /* o : selected codebook vector index */ - Word16 *x, /* i/o: ISF vector */ - const Word16 *dico, /* i : ISF codebook */ - const Word16 dim, /* i : codebook dimension */ - const Word16 dico_size, /* i : codebook size */ - Word32 *distance /* o : quantization error (min. distance) */ -) -{ - Word32 dist_min, dist; - const Word16 *p_dico; - Word16 i, j, index, temp; - - - dist_min = MAX_32; - move32(); - p_dico = dico; - move16(); - - index = 0; - move16(); - FOR (i = 0; i < dico_size; i++) - { - dist = L_deposit_l(0); - FOR (j = 0; j < dim; j++) - { - /*temp = x[j] - *p_dico++;*/ - temp = sub(x[j], *p_dico++); - /*dist += temp * temp;*/ - dist = L_mac(dist, temp, temp); - } - - IF (L_sub(dist,dist_min) < 0) - { - dist_min = L_add(dist, 0); - index = i; - move16(); - } - } - - *distance = dist_min; - move32(); - - /* Reading the selected vector */ - p_dico = &dico[i_mult2(index, dim)]; - FOR (j = 0; j < dim; j++) - { - x[j] = *p_dico++; - move16(); - } - return index; -} diff --git a/src/libs/libevs/lib_enc/lead_indexing.cpp b/src/libs/libevs/lib_enc/lead_indexing.cpp new file mode 100644 index 00000000..f41903d3 --- /dev/null +++ b/src/libs/libevs/lib_enc/lead_indexing.cpp @@ -0,0 +1,176 @@ +/*==================================================================================== + EVS Codec 3GPP TS26.443 Nov 13, 2018. Version 12.11.0 / 13.7.0 / 14.3.0 / 15.1.0 + ====================================================================================*/ + +#include +#include +#include "options.h" +#include "rom_com.h" +#include "prot.h" + + +/*-------------------------------------------------------------------* + * Local function prototypes + *-------------------------------------------------------------------*/ +static int fcb_encode_pos(int pos_vector[], int pulse_num, int pos_num); + +/*-------------------------------------------------------------------* + * re8_compute_base_index: + * + * Compute base index for RE8 + *-------------------------------------------------------------------*/ + +void re8_compute_base_index( + const int *x, /* i : Elemen of Q2, Q3 or Q4 */ + const int ka, /* i : Identifier of the absolute leader related to x */ + long *I /* o : index */ +) +{ + int i, j, k1,m; + int setor_8p[8], setor_8p_temp[8]; + int sign_8p; + int code_index, code_level, code_area; + int offset; + const int *a1,*a2; + + + a1 = vals_a[ka]; + a2 = vals_q[ka]; + + /* the sign process */ + + sign_8p = 0; + m = 0; + code_index = 0; + k1 = a2[0]; + + if ((a2[1]==2) && (a1[0] ^ 1) && (ka != 5)) + { + for (i=0; i<8; i++) + { + if (x[i] != 0) + { + sign_8p = sign_8p * 2; + setor_8p_temp[m] = i; + m++; + } + if (x[i] < 0) + { + sign_8p += 1; + } + } + + code_index = fcb_encode_pos(setor_8p_temp,8,m); + code_index = (code_index << k1) + sign_8p; + + offset = Is[ka]; + + + *I = offset + code_index; + } + else + { + for (i=0; i<8; i++) + { + setor_8p[i] = abs(x[i]); + + if (x[i] < 0) + { + sign_8p = sign_8p * 2 + 1; + m++; + } + if (x[i] > 0) + { + sign_8p = sign_8p * 2; + m++; + } + } + + if ( k1 != m ) + { + sign_8p = sign_8p >> 1; + } + + /* code level by level */ + + code_level = a2[1]; + code_area = 8; + + if ( a2[2] != 1 ) + { + for (j=0; j -#include "options.h" /* Compilation switches */ - -#include "prot_fx.h" -#include "rom_com_fx.h" -#include "stl.h" /* required for wmc_tool */ - -/*-------------------------------------------------------------------* - * Local function prototypes - *-------------------------------------------------------------------*/ -static Word16 fcb_encode_pos_fx(const Word16 pos_vector[], const Word16 pulse_num, - const Word16 pos_num); - -/*-------------------------------------------------------------------* - * re8_compute_base_index_fx: - * - * Compute base index for RE8 - *-------------------------------------------------------------------*/ -void re8_compute_base_index_fx( - const Word16 *x, /* i : Elemen of Q2, Q3 or Q4 */ - const Word16 ka, /* i : Identifier of the absolute leader related to x */ - UWord16 *I /* o : index */ -) -{ - Word16 i, j, k1 ,m; - Word16 setor_8p[8], setor_8p_temp[8]; - Word16 sign_8p; - Word16 code_level, code_area; - - const Word16 *a1,*a2; - Word16 code_index; - UWord16 offset; - - a1 = vals_a_fx[ka]; - move16(); - a2 = vals_q_fx[ka]; - move16(); - - /* the sign process */ - - sign_8p = 0; - move16(); - m = 0; - move16(); - code_index = 0; - move16(); - k1 = a2[0]; - move16(); - - test(); - test(); - IF (sub(a2[1], 2) == 0 && s_xor(a1[0], 1) && sub(ka, 5)) - { - FOR (i=0; i<8; i++) - { - IF (x[i] != 0) - { - sign_8p = shl(sign_8p, 1); - setor_8p_temp[m] = i; - move16(); - m = add(m, 1); - } - - IF (x[i] < 0) - { - sign_8p = add(sign_8p, 1); - } - } - - code_index = fcb_encode_pos_fx(setor_8p_temp,8,m); - code_index = add(shl(code_index,k1),sign_8p); - - offset = Is_fx[ka]; - move16(); - - *I = extract_l(L_add(offset, (Word32) code_index)); - } - ELSE - { - FOR (i=0; i<8; i++) - { - setor_8p[i] = abs_s(x[i]); - - IF (x[i] != 0) - { - sign_8p = shl(sign_8p, 1); - m = add(m, 1); - } - - IF (x[i] < 0) - { - sign_8p = add(sign_8p, 1); - } - } - - IF (sub(k1, m) != 0) - { - sign_8p = shr(sign_8p, 1); - } - - /* code level by level */ - - code_level = sub(a2[1], 1); - code_area = 8; - move16(); - - IF (sub(a2[2], 1) != 0) - { - FOR (j=0; jini_frame_fx, 4 ) < 0 ) + * Compute long term estimate of total noise energy + * and total active speech energy + *-----------------------------------------------------------------*/ + if( st->ini_frame < 4 ) { + st->lp_noise = st->totalNoise; + tmp = st->lp_noise + 10.0f; - st_fx->lp_noise_fx = st_fx->totalNoise_fx; - move16(); - tmp = add(st_fx->lp_noise_fx, 2560); /*10.0 in Q8*/ - st_fx->lp_speech_fx = s_max(st_fx->lp_speech_fx, tmp); - } - ELSE - { - /* if ( st->ini_frame < 150 ) { - st->lp_noise = 0.95f * st->lp_noise + 0.05f * st->totalNoise; - } else { - st->lp_noise = 0.98f * st->lp_noise + 0.02f * st->totalNoise; - } */ - alpha = 655; - move16();/* 0.02 Q15 */ - if ( sub(st_fx->ini_frame_fx, 150) < 0 ) /* should match HE_LT_CNT_INIT_FX */ + if( st->lp_speech < tmp ) { - alpha = 1638 ; - move16(); /* 0.05 Q15 */ + st->lp_speech = tmp; } - st_fx->lp_noise_fx = noise_est_AR1_Qx( st_fx->totalNoise_fx, st_fx->lp_noise_fx , alpha); /* Q8 state, alpha in Q15 */ - - test(); - IF ( (localVAD_HE_SAD != 0) - && ( high_lpn_flag == 0) ) + } + else + { + if ( st->ini_frame < 150 ) { - IF( sub(sub(st_fx->lp_speech_fx, Etot ), 10*256 ) < 0 ) /* 10.0 in Q8 */ - { - /* st->lp_speech = 0.98f * st->lp_speech + 0.02f * Etot; */ - st_fx->lp_speech_fx = noise_est_AR1_Qx(Etot, st_fx->lp_speech_fx, 655); /* Q8 state, 0.02 in Q15 */ - } - ELSE - { - st_fx->lp_speech_fx = sub(st_fx->lp_speech_fx, 13); /* st->lp_speech = st->lp_speech - 0.05f; linear decay*/ - } + st->lp_noise = 0.95f * st->lp_noise + 0.05f * st->totalNoise; + } + else + { + st->lp_noise = 0.98f * st->lp_noise + 0.02f * st->totalNoise; } + if ( localVAD_HE_SAD && !high_lpn_flag ) + { + if ( ( st->lp_speech - Etot ) < 10.0f ) + { + st->lp_speech = 0.98f * st->lp_speech + 0.02f * Etot; + } + else + { + st->lp_speech = st->lp_speech - 0.05f; + } + } } - /*-----------------------------------------------------------------* * Initialize parameters for energy tracking and signal dynamics *-----------------------------------------------------------------*/ diff --git a/src/libs/libevs/lib_enc/lp_exc_e.cpp b/src/libs/libevs/lib_enc/lp_exc_e.cpp new file mode 100644 index 00000000..44aa0504 --- /dev/null +++ b/src/libs/libevs/lib_enc/lp_exc_e.cpp @@ -0,0 +1,285 @@ +/*==================================================================================== + EVS Codec 3GPP TS26.443 Nov 13, 2018. Version 12.11.0 / 13.7.0 / 14.3.0 / 15.1.0 + ====================================================================================*/ + +#include "options.h" +#include "cnst.h" +#include "prot.h" + +/*-------------------------------------------------------------------* + * Local constants + *-------------------------------------------------------------------*/ + +#define GAIN_PIT_MAX 1.2f +#define ACELP_GAINS_CONST 0.8f /* adaptive codebook gain constraint */ + + +/*-------------------------------------------------------------------* + * Local functions + *-------------------------------------------------------------------*/ + +static float adpt_enr( const short codec_mode, const float *exc, const float *h1, float *y1, const short L_subfr, float *gain, float *g_corr, + const short clip_gain, const float *xn, float *xn2, short use_prev_sf_pit_gain ); + +/*-------------------------------------------------------------------* + * lp_filt_exc_enc() + * + * Low-pass filtering of the adaptive excitation + * Innovation target construction + * Gain quantization limitation + *-------------------------------------------------------------------*/ + +short lp_filt_exc_enc( + const short codec_mode, /* i : codec mode */ + const long core_brate, /* i : core bitrate */ + const short Opt_AMR_WB, /* i : flag indicating AMR-WB IO mode */ + const short coder_type, /* i : coding type */ + const short i_subfr, /* i : subframe index */ + float *exc, /* i/o: pointer to excitation signal frame */ + const float *h1, /* i : weighted filter input response */ + const float *xn, /* i : target vector */ + float *y1, /* o : zero-memory filtered adaptive excitation */ + float *xn2, /* o : target vector for innovation search */ + const short L_subfr, /* i : length of vectors for gain quantization */ + const short L_frame, /* i : frame size */ + float *g_corr, /* o : ACELP correlation values */ + const short clip_gain, /* i : adaptive gain clipping flag */ + float *gain_pit, /* o : adaptive excitation gain */ + short *lp_flag /* i/o : mode selection */ +) +{ + float ener, ener_tmp, gain1, gain2, g_corr2[2], exc_tmp[L_FRAME16k], xn2_tmp[L_FRAME16k]; + float y1_tmp[L_FRAME16k]; + short select, i; + short use_prev_sf_pit_gain; + + gain1 = 0.0f; + gain2 = 0.0f; + ener = 0.0f; + ener_tmp = 0.0f; + use_prev_sf_pit_gain = 0; + + /*-----------------------------------------------------------------* + * Select LP filtering flag + *-----------------------------------------------------------------*/ + + if( codec_mode == MODE1 ) + { + if ( ( Opt_AMR_WB || coder_type == GENERIC || coder_type == TRANSITION ) && core_brate < ACELP_11k60 ) + { + *lp_flag = LOW_PASS; + } + else if ( core_brate >= ACELP_11k60 && coder_type != AUDIO ) + { + *lp_flag = NORMAL_OPERATION; + } + else + { + *lp_flag = FULL_BAND; + } + } + + /*----------------------------------------------------------------* + * Find energy of the fixed cb. target with respect to adaptive + * exc. filtering + * Find flag about splitting the gain quantizer in half + * - find the target energy if adaptive exc. is not filtered + * - filter the adaptive excitation and find the target energy + * if the exc. is filtered. + *----------------------------------------------------------------*/ + + if( codec_mode == MODE2 && coder_type == 100 ) + { + use_prev_sf_pit_gain = 1; + } + + if( *lp_flag == FULL_BAND || *lp_flag == NORMAL_OPERATION ) + { + if( use_prev_sf_pit_gain == 1 ) + { + ener = adpt_enr( codec_mode, &exc[i_subfr], h1, y1, L_subfr, gain_pit, g_corr, clip_gain, xn, xn2, use_prev_sf_pit_gain ); + } + else + { + ener = adpt_enr( codec_mode, &exc[i_subfr], h1, y1, L_subfr, &gain1, g_corr, clip_gain, xn, xn2, use_prev_sf_pit_gain ); + } + } + + /*----------------------------------------------------------------* + * Find energy of the fixed cb. target with respect to adaptive + * exc. filtering + * filter the adaptive excitation and find the target energy + * if the exc. is filtered. + *----------------------------------------------------------------*/ + + if( *lp_flag == LOW_PASS || *lp_flag == NORMAL_OPERATION ) + { + if( codec_mode == MODE2 && L_frame == L_FRAME16k ) + { + for (i=0; i 0.95f ) + { + *gain = 0.95f; + } + + if( clip_gain == 2 && *gain > 0.65f ) + { + *gain = 0.65f; + } + } + + /* find energy of new target xn2[] */ + updt_tar( xn, xn2, y1, *gain, L_subfr ); + ener = dotp( xn2, xn2, L_subfr ); + + return ener; +} + +/*-------------------------------------------------------------------* + * corr_xy1() + * + * Find the correlations between the target xn[] and the filtered adaptive + * codebook excitation y1[]. ( and -2 ) + *-------------------------------------------------------------------*/ + +float corr_xy1( /* o : pitch gain (0..GAIN_PIT_MAX) */ + const float xn[], /* i : target signal */ + const float y1[], /* i : filtered adaptive codebook excitation */ + float g_corr[], /* o : correlations and -2 */ + const short L_subfr, /* i : vector length */ + const short norm_flag /* i : flag for constraining pitch contribution */ +) +{ + float temp1, temp2, gain,gain_p_snr; + + /*-----------------------------------------------------------------* + * Find the ACELP correlations and the pitch gain + * (for current subframe) + *-----------------------------------------------------------------*/ + + /* Compute scalar product */ + temp1 = dotp(xn, y1, L_subfr); + + /* Compute scalar product */ + temp2 = dotp(y1, y1, L_subfr) + 0.01f; + + g_corr[0] = temp2; + g_corr[1] = -2.0f*temp1 + 0.01f; + + /* find pitch gain and bound it by [0,GAIN_PIT_MAX] */ + if( norm_flag ) + { + gain = (temp1 + 0.01f)/temp2; + } + else + { + gain = temp1/temp2; + } + + if( gain < 0.0f ) + { + gain = 0.0f; + } + if( gain > GAIN_PIT_MAX ) + { + gain = GAIN_PIT_MAX; + } + + /*Limit the energy of pitch contribution*/ + if( norm_flag ) + { + /* Compute scalar product */ + temp1 = dotp(xn, xn, L_subfr); + gain_p_snr = ACELP_GAINS_CONST*sqrt(temp1/temp2); + + if( gain>gain_p_snr ) + { + gain = gain_p_snr; + } + } + + return gain; +} diff --git a/src/libs/libevs/lib_enc/lp_exc_e_fx.cpp b/src/libs/libevs/lib_enc/lp_exc_e_fx.cpp deleted file mode 100755 index 6d301904..00000000 --- a/src/libs/libevs/lib_enc/lp_exc_e_fx.cpp +++ /dev/null @@ -1,417 +0,0 @@ -/*==================================================================================== - EVS Codec 3GPP TS26.442 Apr 03, 2018. Version 12.11.0 / 13.6.0 / 14.2.0 - ====================================================================================*/ - -#include "options.h" /* Compilation switches */ -#include "cnst_fx.h" /* Common constants */ -#include "prot_fx.h" /* Function prototypes */ -#include "stl.h" -#include "basop_util.h" - -/*-------------------------------------------------------------------* - * Local constants - *-------------------------------------------------------------------*/ - -#define GAIN_PIT_MAX 19661 -#define HIGH_LTP_LIMIT 1.0f -#define LOW_LTP_LIMIT 0.55f - -/*-------------------------------------------------------------------* - * Local functions - *-------------------------------------------------------------------*/ - -static Word16 adpt_enr_fx(const Word16 codec_mode, const Word16 *exc, const Word16 *h1, Word16 *y1, const Word16 L_subfr, - Word16 *gain, Word16 *g_corr, const Word16 clip_gain, const Word16 *xn, Word16 *xn2, Word16 *exp_ener - ,Word16 use_prev_sf_pit_gain - ); - -/*-------------------------------------------------------------------* - * function lp_filt_exc_enc_fx() - * - * Low-pass filtering of the adaptive excitation - * Innovation target construction - * Gain quantization limitation - *-------------------------------------------------------------------*/ - -Word16 lp_filt_exc_enc_fx( - const Word16 codec_mode, /* i : MODE1 or MODE2 Q0 */ - const Word32 core_brate, /* i : core bitrate Q0 */ - const Word16 Opt_AMR_WB, /* i : flag indicating AMR-WB IO mode Q0 */ - const Word16 coder_type, /* i : coding type Q0 */ - const Word16 i_subfr, /* i : subframe index Q0 */ - Word16 *exc, /* i/o: pointer to excitation signal frame Q_new */ - const Word16 *h1, /* i : weighted filter input response Q(14+shift) */ - const Word16 *xn, /* i : target vector Q_new-1+shift */ - Word16 *y1, /* o : zero-memory filtered adaptive excitation Q_new-1+shift */ - Word16 *xn2, /* o : target vector for innovation search Q_new-1+shift */ - const Word16 L_subfr, /* i : length of vectors for gain quantization Q0 */ - const Word16 L_frame, /* i : frame size Q0 */ - Word16 *g_corr, /* o : ACELP correlation values mant/exp */ - const Word16 clip_gain, /* i : adaptive gain clipping flag Q0 */ - Word16 *gain_pit, /* o : adaptive excitation gain Q14 */ - Word16 *lp_flag /* i/o: mode selection Q0 */ -) -{ - Word16 gain1, gain2, g_corr2[4], exc_tmp[5*L_SUBFR], xn2_tmp[5*L_SUBFR]; - Word16 y1_tmp[5*L_SUBFR]; - Word16 select, i, exp_ener, exp_ener1; - Word16 wtmp, wtmp1; - Word32 Ltmp; - - Word16 use_prev_sf_pit_gain = 0; - - gain1 = 0; - move16(); - gain2 = 0; - move16(); - - /*-----------------------------------------------------------------* - * Select LP filtering flag - *-----------------------------------------------------------------*/ - - IF ( sub(codec_mode,MODE1) == 0 ) - { - test(); - test(); - test(); - test(); - IF ( ( Opt_AMR_WB || sub(coder_type,GENERIC) == 0|| sub(coder_type,TRANSITION) == 0 ) && L_sub(core_brate,ACELP_11k60) < 0 ) - { - *lp_flag = LOW_PASS; - move16(); - } - ELSE IF ( L_sub(core_brate,ACELP_11k60) >= 0 && sub(coder_type,AUDIO) != 0 ) - { - *lp_flag = NORMAL_OPERATION; - move16(); - } - ELSE - { - *lp_flag = FULL_BAND; - move16(); - } - - } - - /*----------------------------------------------------------------* - * Find the target energy if the adaptive exc. is not filtered - *----------------------------------------------------------------*/ - test(); - IF( sub(codec_mode,MODE2) == 0 && sub(coder_type,100) == 0) - { - use_prev_sf_pit_gain = 1; - } - exp_ener = 0; - move16(); - wtmp = 0; - move16(); - test(); - IF( sub(*lp_flag,FULL_BAND) == 0 || sub(*lp_flag,NORMAL_OPERATION) == 0 ) - { - wtmp = adpt_enr_fx( codec_mode, &exc[i_subfr], h1, y1, L_subfr, &gain1, g_corr, clip_gain, xn, xn2, &exp_ener, use_prev_sf_pit_gain); - move16(); - - } - - /*----------------------------------------------------------------* - * Filter the adaptive excitation - * Find the target energy if the adapt. exc. is filtered - *----------------------------------------------------------------*/ - - exp_ener1 = 0; - move16(); - wtmp1 = 0; - move16(); - test(); - IF( (sub(*lp_flag,LOW_PASS) == 0) || (sub(*lp_flag,NORMAL_OPERATION) == 0) ) - { - test(); - IF( sub(codec_mode,MODE2) == 0 && sub(L_frame,L_FRAME16k) == 0 ) - { - FOR ( i=0; i 0 ) - { - wtmp1 = shr(wtmp1, 1); - } - - /*-----------------------------------------------------------------* - * use the best prediction (minimize quadratic error) - *-----------------------------------------------------------------*/ - - test(); - test(); - IF( ( (sub(wtmp1,wtmp) < 0) && (sub(*lp_flag,NORMAL_OPERATION) == 0) ) || (sub(*lp_flag,LOW_PASS) == 0) ) - { - /* use the LP filter for pitch excitation prediction */ - select = LOW_PASS; - move16(); - Copy( exc_tmp, &exc[i_subfr], L_subfr ); - Copy( y1_tmp, y1, L_subfr ); - Copy( xn2_tmp, xn2, L_subfr ); - - IF(use_prev_sf_pit_gain == 0) - { - *gain_pit = gain2; - move16(); - g_corr[0] = g_corr2[0]; - move16(); - g_corr[1] = g_corr2[1]; - move16(); - g_corr[2] = g_corr2[2]; - move16(); - g_corr[3] = g_corr2[3]; - move16(); - } - } - ELSE - { - /* no LP filter used for pitch excitation prediction */ - select = FULL_BAND; - move16(); - IF(use_prev_sf_pit_gain == 0) - { - *gain_pit = gain1; - move16(); - } - } - - return select; -} - -/*-------------------------------------------------------------------* - * adpt_enr_fx() - * - * Find adaptive excitation energy - * This serves to decide about the filtering of the adaptive excitation - *-------------------------------------------------------------------*/ - -static Word16 adpt_enr_fx( /* o : adaptive excitation energy mant */ - const Word16 codec_mode, /* i : MODE1 or MODE2 */ - const Word16 *exc, /* i : excitation vector Q_new */ - const Word16 *h1, /* i : impuls response Q15 */ - Word16 *y1, /* o : zero-memory filtered adpt. excitation 12 bits */ - const Word16 L_subfr, /* i : vector length */ - Word16 *gain, /* o : subframe adaptive gain Q14 */ - Word16 *g_corr, /* o : correlations for adptive gain mant/exp*/ - const Word16 clip_gain, /* i : adaptive gain clipping flag Q0 */ - const Word16 *xn, /* i : adaptive codebook target 12 bits Q_new-1+shift*/ - Word16 *xn2, /* o : algebraic codebook target 12 bits Q_new-1+shift*/ - Word16 *exp_ener /* o : adaptive excitation energy exp */ - , Word16 use_prev_sf_pit_gain /* i : flag to use prev sf pitch gain or not */ -) -{ - Word16 ener, i; - Word16 exc_tmp[L_FRAME16k], xn_tmp[L_FRAME16k]; - Word32 Ltmp; - - Overflow = 0; - move16(); - conv_fx( exc, h1, y1, L_subfr ); - - IF (use_prev_sf_pit_gain == 0) - { - *gain = corr_xy1_fx( xn, y1, g_corr, L_subfr, codec_mode == MODE2 ); - move16(); - - test(); - IF( sub(L_subfr, L_SUBFR) > 0 && Overflow ) - { - FOR(i = 0; i< L_subfr; i++) - { - exc_tmp[i] = mult(exc[i], 8192); - move16(); - xn_tmp[i] = mult(xn[i], 8192); - move16(); - } - - conv_fx( exc_tmp, h1, y1, L_subfr ); - *gain = corr_xy1_fx( xn_tmp, y1, g_corr, L_subfr, codec_mode == MODE2 ); - move16(); - } - - /* clip gain, if necessary to avoid problems at decoder */ - test(); - if(sub(clip_gain,1) == 0 && sub(*gain,15565) > 0) /* constant in Q14 */ - { - *gain = 15565; - move16(); - } - - test(); - if( sub(clip_gain,2) == 0 && sub(*gain,10650) > 0 ) - { - *gain = 10650; - move16(); - } - } - - /* find energy of new target xn2[] */ - updt_tar_fx( xn, xn2, y1, *gain, L_subfr ); - - IF(sub(L_subfr, L_SUBFR) > 0) - { - /* could possibly happen in GSC */ - Ltmp = Calc_Energy_Autoscaled(xn2, 0, L_subfr, exp_ener); - i = norm_l(Ltmp); - ener = extract_h(L_shl(Ltmp,i)); - i = sub(31, i); - *exp_ener = sub(i, *exp_ener); - move16(); - } - ELSE - { - ener = extract_h(Dot_product12(xn2, xn2, L_SUBFR, exp_ener)); - } - - return ener; -} - -/*-------------------------------------------------------------------* - * corr_xy1() - * - * Find the correlations between the target xn[] and the filtered adaptive - * codebook excitation y1[]. ( and -2 ) - *-------------------------------------------------------------------*/ - -Word16 corr_xy1_fx( /* o : pitch gain (0..GAIN_PIT_MAX) */ - const Word16 xn_1[], /* i : target signal */ - const Word16 y1_1[], /* i : filtered adaptive codebook excitation */ - Word16 g_corr[], /* o : correlations and -2 */ - const Word16 L_subfr, /* i : vector length */ - const Word16 norm_flag /* i : flag for constraining pitch contribution */ -) -{ - Word16 i; - Word16 tmp, xx, xy, yy, exp_xy, exp_xx, exp_yy, exp_div, gain, gain_p_snr; - Word32 Ltmp1, Ltmp2; - Word16 xn[L_FRAME16k], y1[L_FRAME16k]; - - /*----------------------------------------------------------------* - * Find the ACELP correlations and the pitch gain - *----------------------------------------------------------------*/ - - /* Compute scalar product */ - Copy(xn_1, xn, L_subfr); - Copy(y1_1, y1, L_subfr); - Overflow = 0; - move16(); - Ltmp1 = Dot_product12(y1, y1, L_subfr, &exp_yy); - - IF( Overflow ) - { - FOR(i = 0; i < L_subfr; i++) - { - xn[i] = mult_r(xn_1[i], 4096); - move16(); - y1[i] = mult_r(y1_1[i], 4096); - move16(); - } - - Ltmp1 = Dot_product12(y1, y1, L_subfr, &exp_yy); - exp_yy = add(exp_yy, 6); - yy = extract_h(Ltmp1); - - /* Compute scalar product */ - Ltmp2 = Dot_product12(xn, y1, L_subfr, &exp_xy); - xy = extract_h(Ltmp2); - exp_xy = add(exp_xy, 6); - - g_corr[0] = yy; - move16(); - g_corr[1] = exp_yy; - move16(); - /* -2.0*temp1 + 0.01 is done in Gain_enc_2 function */ - g_corr[2] = xy; - move16(); - g_corr[3] = exp_xy; - move16(); - } - ELSE - { - yy = extract_h(Ltmp1); - /* Ltmp1 = L_shr(Ltmp1, sub(30, exp_yy));*/ - - /* Compute scalar product */ - Ltmp2 = Dot_product12(xn, y1, L_subfr, &exp_xy); - xy = extract_h(Ltmp2); - /* Ltmp2 = L_shr(Ltmp2, sub(30, exp_xy));*/ - - g_corr[0] = yy; - move16(); - g_corr[1] = exp_yy; - move16(); - /* -2.0*temp1 + 0.01 is done in Gain_enc_2 function*/ - g_corr[2] = xy; - move16(); - g_corr[3] = exp_xy; - move16(); - } - - /* find pitch gain and bound it by [0,GAIN_PIT_MAX] */ - test(); - IF ( xy >= 0 && sub(s_or(yy, xy), 16384) != 0 ) - { - /* compute gain = xy/yy */ - xy = shr(xy, 1); /* be sure that xy < yy */ - gain = div_s(xy, yy); - i = sub(exp_xy, exp_yy); - gain = shl(gain, i); /* saturation can occur here */ - - gain = s_max(gain, 0); - gain = s_min(gain, GAIN_PIT_MAX); /* 1.2 in Q14 */ - } - ELSE - { - gain = 0; - move16(); - } - - /* Limit the energy of pitch contribution */ - IF (norm_flag) - { - /* Compute scalar product */ - xx = round_fx(Dot_product12_offs(xn, xn, L_subfr, &exp_xx, 1)); - - /* gain_p_snr = sqrt(/) */ - tmp = BASOP_Util_Divide1616_Scale(xx, yy, &exp_div); - exp_xx = add(sub(exp_xx, exp_yy), exp_div); - tmp = Sqrt16(tmp, &exp_xx); - - /* Note: shl works as shl or shr. */ - exp_xx = sub(exp_xx,1); - BASOP_SATURATE_WARNING_OFF - gain_p_snr = round_fx(L_shl(Mpy_32_16_1( 1717986944l/*ACELP_GAINS_CONST Q31*/, tmp), exp_xx)); - BASOP_SATURATE_WARNING_ON - - gain = s_min(gain, gain_p_snr); - } - - return gain; -} diff --git a/src/libs/libevs/lib_enc/lsf_enc.cpp b/src/libs/libevs/lib_enc/lsf_enc.cpp new file mode 100644 index 00000000..6094f6d4 --- /dev/null +++ b/src/libs/libevs/lib_enc/lsf_enc.cpp @@ -0,0 +1,1949 @@ +/*==================================================================================== + EVS Codec 3GPP TS26.443 Nov 13, 2018. Version 12.11.0 / 13.7.0 / 14.3.0 / 15.1.0 + ====================================================================================*/ + +#include +#include +#include "options.h" +#include "cnst.h" +#include "rom_enc.h" +#include "rom_com.h" +#include "prot.h" +#include "basop_proto_func.h" + +/*-----------------------------------------------------------------* + * Local constants + *-----------------------------------------------------------------*/ + +#define MSVQ_MAXCNT 3000 /* was 300 */ +#define LOWEMPH_LSFI 1.0f /* bigger value means more weight for lower frequencies */ + +/*---------------------------------------------------------------------* + * Local functions + *---------------------------------------------------------------------*/ + +static void lsfq_CNG( Encoder_State *st, const float *lsf, const float *wghts, float *qlsf, unsigned int *p_offset_scale1, unsigned int * p_offset_scale2, + short * p_no_scales ); + +static void lsf_mid_enc( Encoder_State *st, const float int_fs, const float qisp0[], const float qisp1[], float isp[], const short coder_type, + const short bwidth, const long core_brate, float Bin_Ener[], short ppp_mode, short nelp_mode ); + +static float vq_lvq_lsf_enc( short pred_flag, short mode, float u[], short * levels, short stages, float w[], short Idx[], const float * lsf, + const float * pred, unsigned int p_offset_scale1[][MAX_NO_SCALES+1], unsigned int p_offset_scale2[][MAX_NO_SCALES+1], + short p_no_scales[][2], float *resq, float * lsfq ); + +static float qlsf_ARSN_tcvq_Enc_16k ( const float *x, float *y, short *indice, const float *w, const short nBits, short safety_net ); + +/*-------------------------------------------------------------------* + * lsf_enc() + * + * Quantization of LSF vector + *-------------------------------------------------------------------*/ + +void lsf_enc( + Encoder_State *st, /* i/o: state structure */ + const short L_frame, /* i : length of the frame */ + const short coder_type, /* i : coding type */ + float *lsf_new, /* o : quantized LSF vector */ + float *lsp_new, /* i/o: LSP vector to quantize/quantized */ + float *lsp_mid, /* i/o: mid-frame LSP vector */ + float *Aq, /* o : quantized A(z) for 4 subframes */ + float *stab_fac, /* o : LSF stability factor */ + const short Nb_ACELP_frames +) +{ + short nBits = 0; + float int_fs; + short force_sf = 0; + float fec_lsf[M], stab; + short i; + + /* initialize */ + if( L_frame == L_FRAME ) + { + int_fs = INT_FS_12k8; + } + else /* L_frame == L_FRAME16k */ + { + int_fs = INT_FS_16k; + } + + /* convert LSPs to LSFs */ + lsp2lsf( lsp_new, lsf_new, M, int_fs ); + + + /* check resonance for pitch clipping algorithm */ + gp_clip_test_lsf( st->core_brate, lsf_new, st->clip_var, 0 ); + + /*-------------------------------------------------------------------------------------* + * Find the number of bits for LSF quantization + *-------------------------------------------------------------------------------------*/ + + if ( st->core_brate == SID_2k40 ) + { + nBits = LSF_BITS_CNG; + } + else + { + if ( st->nelp_mode == 0 && st->ppp_mode == 0 ) + { + nBits = LSF_bits_tbl[LSF_BIT_ALLOC_IDX(st->core_brate, coder_type)]; + } + else if ( st->nelp_mode == 1 ) + { + if ( st->bwidth == NB ) + { + nBits = 32; /* Stole 1 bit for SID/NELP harmonization*/ + + } + else if ( st->bwidth == WB ) + { + nBits = 30; /* Stole 1 bit for SID/NELP harmonization */ + + } + } + else if ( st->ppp_mode == 1 ) + { + + /*The LSF bit scaling does not work here. */ + nBits = 26; /*Stole 1 bit for SID PPP harmonization*/ + + } + } + + if ( Nb_ACELP_frames < 3 ) + { + /* first three ACELP frames after an HQ frame shall be processed only with safety-net quantizer */ + force_sf = 1; + } + + if ( st->next_force_safety_net == 1 ) + { + /* in case of unstable filter, choose safety-net to help FEC */ + force_sf = 1; + st->next_force_safety_net = 0; + } + + /*-------------------------------------------------------------------------------------* + * LSF quantization + *-------------------------------------------------------------------------------------*/ + + + lsf_end_enc( st, lsf_new, lsf_new, st->mem_AR, st->mem_MA, nBits, coder_type, st->bwidth, st->Bin_E, int_fs, st->core_brate, + &st->streaklimit, &st->pstreaklen, force_sf, 0, 0, NULL, NULL, NULL, st->coder_type_raw ); + + /* convert quantized LSFs back to LSPs */ + lsf2lsp( lsf_new, lsp_new, M, int_fs ); + + if ( st->last_core == HQ_CORE && st->core == ACELP_CORE ) + { + /* don't use old LSF values if this is the first ACELP frame after HQ frames */ + mvr2r( lsf_new, st->lsf_old, M ); + } + + if ( st->core_brate == SID_2k40 ) + { + /* return if SID frame (conversion to A(z) done in the calling function) */ + return; + } + + /*-------------------------------------------------------------------------------------* + * FEC - enforce safety-net in the next frame in case of unstable filter + *-------------------------------------------------------------------------------------*/ + + if( st->last_L_frame != st->L_frame) + { + /* FEC - in case of core switching, use old LSFs that have been smoothed with adaptive mean */ + mvr2r( st->lsf_old, st->lsfoldbfi1, M ); + mvr2r( st->lsf_old, st->lsfoldbfi0, M ); + mvr2r( st->lsf_old, st->lsf_adaptive_mean, M ); + } + + FEC_lsf_estim_enc( st, st->L_frame, fec_lsf ); + + /* FEC - calculate LSF stability */ + stab = lsf_stab( lsf_new, fec_lsf, 0, st->L_frame); + + if (st->L_frame == L_FRAME16k && stab < STAB_FAC_LIMIT && coder_type == GENERIC ) + { + st->next_force_safety_net = 1; + } + else + { + if ( stab < STAB_FAC_LIMIT + && (st->clas == VOICED_CLAS + || (st->clas < VOICED_CLAS && coder_type == AUDIO) ) ) + { + st->next_force_safety_net = 1; + } + } + + /* FEC - update adaptive LSF mean vector */ + for (i=0; ilsf_adaptive_mean[i] = (st->lsfoldbfi1[i] + st->lsfoldbfi0[i] + lsf_new[i]) / 3; + } + + /* FEC - update LSF memories */ + mvr2r( st->lsfoldbfi0, st->lsfoldbfi1, M ); + mvr2r( lsf_new, st->lsfoldbfi0, M ); + + /*-------------------------------------------------------------------------------------* + * Mid-frame LSF encoding + * LSP interpolation and conversion of LSPs to A(z) + *-------------------------------------------------------------------------------------*/ + + if(st->rate_switching_reset) + { + /*extrapolation in case of unstable LSF convert*/ + mvr2r( lsp_new, st->lsp_old, M ); + mvr2r( lsf_new, st->lsf_old, M ); + } + + /* Mid-frame LSF encoding */ + lsf_mid_enc( st, int_fs, st->lsp_old, lsp_new, lsp_mid, coder_type, st->bwidth, + st->core_brate, st->Bin_E_old, st->ppp_mode, st->nelp_mode ); + + + if( st->last_core == HQ_CORE && st->core == ACELP_CORE ) + { + /* don't use old LSP/LSF values if this is the first ACELP frame after HQ frames */ + mvr2r( lsp_mid, st->lsp_old, M ); + lsp2lsf( lsp_mid, st->lsf_old, M, int_fs ); + } + + /* LSP interpolation and conversion of LSPs to A(z) */ + int_lsp4( L_frame, st->lsp_old, lsp_mid, lsp_new, Aq, M, 0 ); + + /*------------------------------------------------------------------* + * Check LSF stability (distance between old LSFs and current LSFs) + *------------------------------------------------------------------*/ + + *stab_fac = lsf_stab( lsf_new, st->lsf_old, 0, st->L_frame); + + return; +} + + +/*-------------------------------------------------------------------* + * lsfq_CNG() + * + * LSF quantizer for SID frames (uses 29 bits, 4 for VQ, 25 for LVQ) + * Note: + * The sampling frequency of the LP-CNG frame can be determined by checking the value of the highest order LSF + * coefficient (last coefficient of lsf). If the last LSF coefficient (lsf[M-1]) is larger than 6350 + * the decoded frame is WB2 with sampling rate of 16 kHz, otherwise it is sampled at 12.8kHz and contains + * either NB or WB LSF data. + *-------------------------------------------------------------------*/ + +static void lsfq_CNG( + Encoder_State *st, /* i/o: encoder state structure */ + const float *lsf, + const float *wghts, + float *qlsf_out, + unsigned int *p_offset_scale1, + unsigned int *p_offset_scale2, + short *p_no_scales +) +{ + short i, j, idx_cv, idx_lvq[3]; + float min_dist, dist, dd[M], ddq[M]; + const float *p_cb; + short first_cb, last_cb; + int idx_lead_cng[2], idx_scale_cng[2]; + + float qlsf[M]; + idx_cv = 0; + + /* quantize first stage with 4 bits */ + if ( lsf[M-1] > WB_LIMIT_LSF ) /* 16kHz sampled LSF vector*/ + { + p_cb = &CNG_SN1[0]; + first_cb = 0; + last_cb = 6; + } + else /* 12.8kHz sampled LSF vector*/ + { + p_cb = &CNG_SN1[6*M]; + first_cb = 6; + last_cb = M; + } + + min_dist = 1.0e30f; + for ( i = first_cb; i < last_cb; i++ ) + { + dist = 0.0f; + for( j=0; j streaklimit * op_loop_thr ) + { + /* Safety-net */ + safety_net = 1; + } + else + { + /* Predictive */ + safety_net = 0; + } + + return safety_net; +} + + + +/*-------------------------------------------------------------------* + * lsf_end_enc() + * + * Quantization of LSF parameters + *-------------------------------------------------------------------*/ +void lsf_end_enc( + Encoder_State *st, /* i/o: encoder state structure */ + const float *lsf, /* i : LSF in the frequency domain (0..6400) */ + float *qlsf, /* o : quantized LSF */ + float *mem_AR, /* i/o: quantizer memory for AR model */ + float *mem_MA, /* i/o: quantizer memory for MA model */ + const short nBits_in, /* i : number of bits to spend on ISF quantization */ + const short coder_type_org,/* i : coding type */ + const short bwidth, /* i : input signal bandwidth */ + float *Bin_Ener, /* i : FFT Bin energy 128 *2 sets */ + const float int_fs, /* i : sampling frequency */ + long core_brate, + float *streaklimit, /* i/o: Multiplier to prefer safety-net, more and more in long streaks of predictive frames*/ + short *pstreaklen, /* i/o: Count of consecutive predictive frames */ + short force_sf, /* i : Force safety-net usage (if possible), due to filter instability, MDCT-core switching etc. */ + short rf_flag, + short mode2_flag, + int * lpc_param, + short * no_indices, + short * bits_param_lpc, + short coder_type_raw +) +{ + short i; + short Idx0[MAX_VQ_STAGES+3]; /* Optimal codebook indices for safety-net quantizer */ + short Idx1[MAX_VQ_STAGES+3]; /* Optimal codebook indices for predictive quantizer */ + short indice[MAX_VQ_STAGES+3]; /* Temp. array of indice for vector de-quantizer */ + short mode_lvq = 0, mode_lvq_p = 0; + short bits0[MAX_VQ_STAGES], bits1[MAX_VQ_STAGES]; + const short *Bit_alloc1 = NULL; + float Err[2]; /* Quantization error for safety-net(0) and predictive(1) quantizers */ + float Tmp [M]; /* Temporary target vector (mean and prediction removed) */ + float pred0[M]; /* Prediction for the safety-net quantizer (usually mean) */ + float pred1[M]; /* Prediction for the predictive quantizer */ + float pred2[M]; /* Prediction for the predictive quantizer */ + float wghts[M]; /* Weighting used for quantizer (currently GSM based) */ + short stages0; /* Amount of stages used by safety-net quantizer */ + short stages1; /* Amount of stages used by predictive quantizer */ + short levels0[MAX_VQ_STAGES]; /* Sizes of different codebook stages for safety-net quantizer */ + short levels1[MAX_VQ_STAGES]; /* Sizes of different codebook stages for predictive quantizer */ + short predmode; /* 0: safety-net only, 1: predictive only, 2: best of the two */ + short safety_net, cumleft, num_bits; + short *Idx, stages, *bits; + float Tmp1[M], Tmp2[M]; /* Temporary target vectors for MA and AR quantizers respectively */ + float abs_threshold; /* Abslute Error value that is considered as "good enough" (in practice close to SD of 1.0dB)*/ + float lsfq[M*2], resq[M*2]; + + short coder_type; + short nBits; + short TCQIdx0[M+2]; /* Optimal codebook indices for VQ-TCQ quantizer */ + short *TCQIdx; + + + nBits = nBits_in; + + if((coder_type_org == GENERIC) && (int_fs == INT_FS_16k) && (rf_flag == 0) && (mode2_flag == 0)) + { + + if (coder_type_raw == VOICED) + { + coder_type = VOICED; /* Reflect Inactive mode */ + } + else + { + nBits--; /* This is for real Generic*/ + coder_type = coder_type_org; + } + } + else + { + coder_type = coder_type_org; + } + /*--------------------------------------------------------------------------------* + * Calculate the number of stages and levels for each stage based on allowed bit budget + * Set absolute threshold for codebook-type decision logic + *--------------------------------------------------------------------------------*/ + if ( bwidth == NB ) + { + abs_threshold = SFNETLOWLIMIT_NB; + } + else + { + abs_threshold = SFNETLOWLIMIT_WB; + } + Unified_weighting(&Bin_Ener[L_FFT/2], lsf, wghts, bwidth==NB, coder_type==UNVOICED, (int)(int_fs),M); + + /*--------------------------------------------------------------------------------* + * LSF quantization of SID frames + *--------------------------------------------------------------------------------*/ + + if ( core_brate == SID_2k40 ) + { + lsfq_CNG( st, lsf, wghts, qlsf, &st->offset_scale1[0][0], &st->offset_scale2[0][0], &st->no_scales[0][0] ); + v_sort( qlsf, 0, M-1 ); + reorder_lsf( qlsf, MODE1_LSF_GAP, M, int_fs ); + + return; + } + + predmode = find_pred_mode(coder_type, bwidth, int_fs, &mode_lvq, &mode_lvq_p,st->total_brate); + + /*----------------------------------------------------------------* + * Calculate number of stages and levels for each stage based on the allowed bit allocation + * (subtract one bit for LSF predictor selection) + *----------------------------------------------------------------*/ + + lsf_allocate( nBits-(predmode>>1), mode_lvq, mode_lvq_p, &stages0, &stages1, levels0, levels1, bits0, bits1 ); + + /*--------------------------------------------------------------------------------* + * LSF quantization of all other frames but SID frames + * Select safety-net or predictive mode + *--------------------------------------------------------------------------------*/ + + Err[0] = FLT_MAX; + Err[1] = FLT_MAX; + /* for mem_MA update */ + for (i=0; ioffset_scale1,st->offset_scale2, st->no_scales, resq, lsfq); + safety_net = 1; + *pstreaklen = 0; /* Streak is ended with safety-net */ + } + else if (predmode ==1) /* only MA prediction */ + { + v_sub(lsf, pred1, Tmp1, M); + Err[1] = vq_lvq_lsf_enc(2, mode_lvq_p, Tmp1, levels1, stages1, wghts, Idx1, lsf, pred1, + st->offset_scale1_p,st->offset_scale2_p,st->no_scales_p,resq, lsfq ); + + safety_net = 0; + } + else /* Switched Safety-Net/AR prediction */ + { + /* Subtract mean and AR prediction */ + mvr2r(ModeMeans[mode_lvq], pred0, M); + /* subtract only mean */ + v_sub(lsf, pred0, Tmp, M); + for (i = 0; i < M; i++) + { + /* subtract mean and AR prediction */ + pred2[i] = pred0[i] + Predictors[mode_lvq_p][i]*(mem_AR[i]-pred0[i]); + Tmp2[i] = lsf[i] - pred2[i]; + } + /* Adaptive scaling factor (multiplier) is updated in order to reduce the amount of consecutive predictive frames in + case of possible frame erasure. AR-predictive usage for VOICED mode is allowed to be higher than other modes. */ + if ( ((*pstreaklen > (STREAKLEN+3))&&(coder_type==VOICED)) || ((*pstreaklen > (STREAKLEN)) &&(coder_type!=VOICED))) + { + /* update the adaptive scaling factor to become smaller with increasing number of concecutive predictive frames. */ + *streaklimit *= STREAKMULT; + } + + if ( *pstreaklen == 0 ) + { + /* reset the adaptive scaling factor */ + *streaklimit = 1.0f; + } + + + /* VOICED_WB@16kHz */ + if ( int_fs == INT_FS_16k && coder_type == VOICED ) + { + /* select safety_net or predictive in open loop*/ + safety_net = qlsf_Mode_Select( lsf, wghts, pred2, *streaklimit, OP_LOOP_THR_HVO ); + + if ( force_sf == 1 ) + { + safety_net = 1; + } + + if ( safety_net ) + { + /* Safety-net - BC-TCQ quantization : SN */ + Err[0] = qlsf_ARSN_tcvq_Enc_16k( Tmp, lsfq, TCQIdx0, wghts, nBits-1, safety_net ); + *pstreaklen = 0; + } + else + { + /* predictive - BC-TCQ quantization : AR */ + /* For consistency Err[1] contains predictive error */ + Err[1] = qlsf_ARSN_tcvq_Enc_16k( Tmp2, lsfq, TCQIdx0, wghts, nBits-1, safety_net ); + (*pstreaklen)++; + } + } + /* all other frames (not VOICED@16kHz) */ + else + { + /* safety-net */ + Err[0] = vq_lvq_lsf_enc(0, mode_lvq, Tmp, levels0, stages0, wghts, Idx0, lsf, pred0, + st->offset_scale1,st->offset_scale2,st->no_scales, resq, lsfq); + /* Predictive quantizer is calculated only if it can be selected, this saves computation */ + if (!force_sf || Err[0] > abs_threshold) + { + Err[1] = vq_lvq_lsf_enc(2, mode_lvq_p, Tmp2, levels1, stages1, wghts, Idx1, lsf, pred2, + st->offset_scale1_p, st->offset_scale2_p, st->no_scales_p, &resq[M], &lsfq[M]); + } + /* Select whether to use safety-net or predictive LSF quantizer. The decision is based on following: + if the non-predictive (safety-net) quantization error (Err[0]) is low enough it is selected + or if the predictively quantized error (Err[1]) is by at least adaptive margin smaller than non-predictive quantizer. + or if the in case of frame erasure the resulting concealed predictive LSF would be unstable safety-net is selected */ + if ( force_sf || Err[0]*(*streaklimit) < PREFERSFNET * Err[1] || Err[0] < abs_threshold ) + { + safety_net = 1; + *pstreaklen = 0; /* Reset the consecutive predictive frame counter */ + } + else + { + safety_net = 0; + (*pstreaklen)++; /* Increase the consecutive predictive frame counter by one */ + } + } + } + + /*--------------------------------------------------------------------------* + * Write indices to array + *--------------------------------------------------------------------------*/ + + if (mode2_flag == 0) + { + /* write coder_type bit for VOICED@16kHz or GENERIC@16kHz */ + if((coder_type_org == GENERIC) + &&(int_fs == INT_FS_16k) + ) + { + /* VOICED =2 and GENERIC=3, so "coder_type-2" means VOICED =0 and GENERIC=1*/ + push_indice( st, IND_LSF_PREDICTOR_SELECT_BIT, coder_type-2, 1 ); + } + /* write predictor selection bit */ + if ( predmode == 2 ) + { + push_indice( st, IND_LSF_PREDICTOR_SELECT_BIT, safety_net, 1 ); + } + + if ( (coder_type == VOICED) && (int_fs == INT_FS_16k) ) + { + /* BC-TCVQ (only for VOICED@16kHz) */ + TCQIdx = &TCQIdx0[1]; + Bit_alloc1 = &BC_TCVQ_BIT_ALLOC_40B[1]; + for( i=0; i 0 ) + { + indice[i] = Idx[i]; + + if ( cumleft > LEN_INDICE ) + { + num_bits = LEN_INDICE; + } + else + { + num_bits = cumleft; + } + + cumleft -= num_bits; + + push_indice( st, IND_LSF, indice[i], num_bits ); + + i++; + } + } + } + else + { + if ( (coder_type == VOICED) && (int_fs == INT_FS_16k) ) + { + /* BC-TCVQ (only for VOICED@16kHz) */ + /* Number of quantization indices */ + *no_indices = 10; + for(i=0; i<*no_indices; i++) + { + lpc_param[i] = (int)TCQIdx0[i]; + bits_param_lpc[i] = BC_TCVQ_BIT_ALLOC_40B[i]; + } + } + else + { + /* Number of quantization indices */ + + /* there are 31 bits */ + if (safety_net==1) + { + Idx = Idx0; + *no_indices = stages0+1; + for(i=0; i0; i--) + { + lpc_param[i] = lpc_param[i-1]; + bits_param_lpc[i] = bits_param_lpc[i-1]; + } + lpc_param[0] = safety_net; /* put the safety net info on the last param */ + bits_param_lpc[0] = 1; + *no_indices = *no_indices+1; + } + } + } + + + /*--------------------------------------------------------------------------* + * De-quantize encoded LSF vector + *--------------------------------------------------------------------------*/ + + if ( safety_net ) + { + /* Safety-net */ + if ( coder_type == VOICED && int_fs == INT_FS_16k ) + { + /* BC-TCQ */ + mvr2r( lsfq, mem_MA, M ); + v_add( lsfq, pred0, qlsf, M ); + } + else + { + vq_dec_lvq( 1, qlsf, &indice[0], stages0, M, mode_lvq, levels0[stages0-1], + &st->offset_scale1[0][0], &st->offset_scale2[0][0], &st->offset_scale1_p[0][0], &st->offset_scale2_p[0][0], + &st->no_scales[0][0], &st->no_scales_p[0][0] ); + + v_add(qlsf, pred0, qlsf, M ); + v_sub(qlsf, pred1,mem_MA, M); + } + } + else + { + if ( (coder_type == VOICED) && (int_fs == INT_FS_16k) ) + { + /* BC-TCVQ */ + mvr2r( lsfq, mem_MA, M ); + v_add( lsfq, pred2, qlsf, M ); + } + else + { + /* LVQ */ + vq_dec_lvq( 0, qlsf, &indice[0], stages1, M, mode_lvq_p, levels1[stages1-1], + &st->offset_scale1[0][0], &st->offset_scale2[0][0], &st->offset_scale1_p[0][0], + &st->offset_scale2_p[0][0], &st->no_scales[0][0], &st->no_scales_p[0][0] ); + if (predmode==1) + { + mvr2r(qlsf, mem_MA, M); + v_add( qlsf, pred1, qlsf, M ); + } + else + { + v_add( qlsf, pred2, qlsf, M ); + v_sub(qlsf, pred1, mem_MA, M); + } + } + } + + /*--------------------------------------------------------------------------* + * Sort the quantized vector + * Verify stability + * Update AR-predictor memory + *--------------------------------------------------------------------------*/ + + /* Sort the quantized vector to ascending order */ + v_sort( qlsf, 0, M-1 ); + + /* Verify stability by adding minimum separation */ + reorder_lsf( qlsf, MODE1_LSF_GAP, M, int_fs ); + + /* Update predictor memories */ + mvr2r( qlsf, mem_AR, M ); + + + return; +} + + + +/*-------------------------------------------------------------------* + * first_VQstages() + * + * + *-------------------------------------------------------------------*/ + +static void first_VQstages( + const float * const *cb, + float u[], /* i : vector to be encoded (prediction and mean removed) */ + short *levels, /* i : number of levels in each stage */ + short stagesVQ, /* i : number of stages */ + float w[], /* i : weights */ + short N, /* i : vector dimension */ + short max_inner, /* i : maximum number of swaps in inner loop */ + short indices_VQstage[] +) +{ + float ftmp, resid_buf[2*LSFMBEST*M], *resid[2], dist_buf[2*LSFMBEST], *dist[2]; + float en, tmp, Tmp[M], *pTmp; + short *pTmp_short, idx_buf[2*LSFMBEST*MAX_VQ_STAGES], parents[LSFMBEST], counter=0, j, + m, s,c, c2, p_max, *indices[2]; + short maxC = LSFMBEST; + + /*float dd[16];*/ + const float *cb_stage, *cbp; + + /* Set pointers to previous (parent) and current node (parent node is indexed [0], current node is indexed [1]) */ + indices[0] = idx_buf; + indices[1] = idx_buf + maxC*stagesVQ; + resid[0] = resid_buf; + resid[1] = resid_buf + maxC*N; + dist[0] = dist_buf; + dist[1] = dist_buf + maxC; + + set_s( idx_buf, 0, (const short)(2*stagesVQ*maxC) ); + set_s( parents, 0, maxC ) ; + + /* Set up inital distance vector */ + for( tmp = 0, j=0; j0) + { + /* first VQ stages */ + first_VQstages( cb, u, levels, stagesVQ, w, M, MSVQ_MAXCNT, indices_firstVQ ); + } + + + for ( i=0; i>2][fins][stage4]; + index = NTRANS2[branch+2][*prev_state]; + + /* Prediction */ + pred[0] = itc[stage1][0][0] * Q[stage1][*prev_state][0] + itc[stage1][0][1] * Q[stage1][*prev_state][1]; + pred[1] = itc[stage1][1][0] * Q[stage1][*prev_state][0] + itc[stage1][1][1] * Q[stage1][*prev_state][1]; + target[0] = x[stage][0] - pred[0]; + target[1] = x[stage][1] - pred[1]; + + minDist = (target[0] - CB[stage4][index][0]) * (target[0] - CB[stage4][index][0]) * W[stage][0]; + minDist += (target[1] - CB[stage4][index][1]) * (target[1] - CB[stage4][index][1]) * W[stage][1]; + bestCode = index; + + for(index = index + 8; index < 32; index += 8) + { + dist = (target[0] - CB[stage4][index][0]) * (target[0] - CB[stage4][index][0]) * W[stage][0]; + dist += (target[1] - CB[stage4][index][1]) * (target[1] - CB[stage4][index][1]) * W[stage][1]; + + if(dist < minDist) + { + minDist = dist; + bestCode = index; + } + } + + /* Update */ + *prev_state = NTRANS2[branch][*prev_state]; + c[fins][stage4] = bestCode; + Q[stage][*prev_state][0] = CB[stage4][bestCode][0] + pred[0]; + Q[stage][*prev_state][1] = CB[stage4][bestCode][1] + pred[1]; + + return minDist; + +} + +/*--------------------------------------------------------------------------- + * optimalPath() + * + * + *--------------------------------------------------------------------------*/ + +static short optimalPath( + float cDist[][16], + float blockDist[], + short blockCodeword[][4], + short bestCodeword[], + short codeWord[][16], + short bestState[], + short preState[][16] +) +{ + short stage, state; + float opDist[NUM_STATE]; + float minDist; + short fBlock; + short prev_state; + + for(state = 0; state < NUM_STATE; state++) + { + opDist[state] = cDist[3][state] + blockDist[state]; + } + + minDist = opDist[0]; + fBlock = 0; + + for(state = 1; state < NUM_STATE; state++) + { + if(opDist[state] < minDist) + { + minDist = opDist[state]; + fBlock = state; + } + } + + prev_state = bestState[4] = fBlock; + + for(stage = N_STAGE_VQ - 5; stage >= 0; stage --) + { + bestCodeword[stage] = codeWord[stage][prev_state]; + bestState[stage] = preState[stage][prev_state]; + prev_state = bestState[stage]; + } + + for(stage = 0; stage < 4; stage ++) + { + bestCodeword[stage + 4] = blockCodeword[fBlock][stage]; + } + + return fBlock; +} + +/*--------------------------------------------------------------------------- + * quantEnc() + * + * + *--------------------------------------------------------------------------*/ + +static void quantEnc( + float *y, + short c[], + const float CB_SUB1[][128][2], + const float CB_SUB2[][64][2], + const float CB_SUB3[][32][2], + const float itc[][2][2] +) +{ + short i,j; + short stage; + float pred[N_DIM], Y[8][2]; + + /* stage #1 */ + Y[0][0] = CB_SUB1[0][c[0]][0]; + Y[0][1] = CB_SUB1[0][c[0]][1]; + + /* stage #2 */ + pred[0] = itc[0][0][0] * Y[0][0] + itc[0][0][1]*Y[0][1]; + pred[1] = itc[0][1][0] * Y[0][0] + itc[0][1][1]*Y[0][1]; + Y[1][0] = CB_SUB1[1][c[1]][0] + pred[0]; + Y[1][1] = CB_SUB1[1][c[1]][1] + pred[1]; + + /* stage #3 - #4 */ + for(stage = 2; stage < N_STAGE_VQ-4; stage ++) + { + pred[0] = itc[stage-1][0][0] * Y[stage-1][0] + itc[stage-1][0][1]*Y[stage-1][1]; + pred[1] = itc[stage-1][1][0] * Y[stage-1][0] + itc[stage-1][1][1]*Y[stage-1][1]; + + Y[stage][0] = CB_SUB2[stage-2][c[stage]][0] + pred[0]; + Y[stage][1] = CB_SUB2[stage-2][c[stage]][1] + pred[1]; + } + + /* stage #5 - #8 */ + for(stage = N_STAGE_VQ-4; stage < N_STAGE_VQ; stage ++) + { + pred[0] = itc[stage-1][0][0] * Y[stage-1][0] + itc[stage-1][0][1]*Y[stage-1][1]; + pred[1] = itc[stage-1][1][0] * Y[stage-1][0] + itc[stage-1][1][1]*Y[stage-1][1]; + + Y[stage][0] = CB_SUB3[stage-4][c[stage]][0] + pred[0]; + Y[stage][1] = CB_SUB3[stage-4][c[stage]][1] + pred[1]; + } + + /* Transform Vector to Scalar */ + for(i = 0; i < N_STAGE_VQ; i++) + { + for(j = 0; j < N_DIM; j++) + { + y[i*N_DIM+j] = Y[i][j]; + } + } + + return; +} + +/*--------------------------------------------------------------------------- + * buildCode() + * + * + *--------------------------------------------------------------------------*/ + +static void buildCode( + short *ind, + short fins, + short c[], + short s[] +) +{ + short stage; + short BrIndex[4]; + + set_s(BrIndex, 0, (N_STAGE_VQ - 4)); + + + for(stage = N_STAGE_VQ - 4; stage >= 1; stage--) + { + if(s[stage] > 7) + { + BrIndex[stage-1] = 1; + } + } + ind[0] = fins; + + /* stage #1 - #2 */ + for(stage = 0; stage < 2; stage++) + { + ind[stage+1] = BrIndex[stage] << 4; + ind[stage+1] += c[stage] >> 3; + } + + /* stage #3 - #4 */ + for(stage = 2; stage < N_STAGE_VQ - 4; stage++) + { + ind[stage+1] = BrIndex[stage] << 3; + ind[stage+1] += c[stage] >> 3; + } + + /* Stage #5 - #8 */ + for(stage = N_STAGE_VQ-4; stage < N_STAGE_VQ; stage++) + { + ind[stage+1] = c[stage] >> 3; + } + + return; +} + +/*--------------------------------------------------------------------------- + * BcTcvq() + * + * + *--------------------------------------------------------------------------*/ + +static void BcTcvq( + short snFlag, + const float *x, + float *y, + const float *weight, + short *ind +) +{ + float X[N_STAGE_VQ][N_DIM], W[N_STAGE_VQ][N_DIM]; + + /* Count Variable */ + short i,j; + + /* TCVQ Structure */ + short stage, state, prev_state; + short preState[N_STAGE_VQ][NUM_STATE]; + short codeWord[N_STAGE_VQ][NUM_STATE]; + float acumDist[N_STAGE_VQ-4][NUM_STATE]; + short inis, fins, ptr_fins; + short fBlock; + short fState[NUM_STATE]; + short fCodeword[4][4]; + short iniBlock[NUM_STATE]; + short blockCodeword[NUM_STATE][4]; + + /* Prediction variable */ + float quant[N_STAGE_VQ][NUM_STATE][N_DIM]; + + /* Distortion variable */ + float minDist; + float fDist; + float blockDist[NUM_STATE]; + + /* Decoding variable */ + short bestCodeword[N_STAGE_VQ]; + short bestState[N_STAGE_VQ]; + + /* Code Share variable */ + const float (*TCVQ_CB_SUB1)[128][2], (*TCVQ_CB_SUB2)[64][2], (*TCVQ_CB_SUB3)[32][2]; + const float (*IntraCoeff)[2][2]; + + /* Memoryless Module */ + if(snFlag) + { + TCVQ_CB_SUB1 = SN_TCVQ_CB_SUB1; + TCVQ_CB_SUB2 = SN_TCVQ_CB_SUB2; + TCVQ_CB_SUB3 = SN_TCVQ_CB_SUB3; + IntraCoeff = SN_IntraCoeff; + } + else /* Memory Module */ + { + TCVQ_CB_SUB1 = AR_TCVQ_CB_SUB1; + TCVQ_CB_SUB2 = AR_TCVQ_CB_SUB2; + TCVQ_CB_SUB3 = AR_TCVQ_CB_SUB3; + IntraCoeff = AR_IntraCoeff; + } + + /* Transform Scalar to Vector */ + for(i = 0; i < N_STAGE_VQ; i++) + { + for(j = 0; j < N_DIM; j++) + { + X[i][j] = x[(N_DIM*i) + j]; + W[i][j] = weight[(N_DIM*i) + j]; + } + } + + /* Initialzie */ + for(i=0; i= 0; stage--) + { + prev_state = preState[stage][prev_state]; + } + iniBlock[state] = prev_state; + } + + /* stage #5 - #8 */ + for(state = 0; state < NUM_STATE; state++) + { + inis = iniBlock[state]; + ptr_fins = inis >> 2; + + minDist = FLT_MAX; + + for(i = 0; i < 4; i++) + { + fins = ptr_fins*4 + i; + + prev_state = state; + fDist = BcTcvq_FixSearch(X, TCVQ_CB_SUB3, fCodeword, quant, FixBranch_tbl, N_STAGE_VQ-4, inis, i, &prev_state, W, IntraCoeff); + + for(stage = N_STAGE_VQ-3; stage < N_STAGE_VQ; stage++) + { + fDist += BcTcvq_FixSearch(X, TCVQ_CB_SUB3, fCodeword, quant, FixBranch_tbl, stage, inis, i, &prev_state, W, IntraCoeff); + } + + if(fDist < minDist) + { + minDist = fDist; + blockDist[state] = minDist; + fState[state] = fins; + + for(j = 0; j < 4; j++) + { + blockCodeword[state][j] = fCodeword[i][j]; + } + } + } + } + + /* Select optimal path */ + fBlock = optimalPath(acumDist, blockDist, blockCodeword, bestCodeword, codeWord, bestState, preState); + + /* Select Quantized Value */ + quantEnc(y, bestCodeword, TCVQ_CB_SUB1, TCVQ_CB_SUB2, TCVQ_CB_SUB3, IntraCoeff); + + /* Buid Code for Decoder */ + buildCode(ind, fState[fBlock], bestCodeword, bestState); + + return; +} + + +/*--------------------------------------------------------------------------- + * SVQ_2d() + * + * + *--------------------------------------------------------------------------*/ + +static short SVQ_2d( + float *x, + float *y, + const float *W, + const float CB[][8], + short Size +) +{ + short i, j; + short index = 0; + float distortion; + float temp; + + temp = FLT_MAX; + + for(i = 0; i < Size; i++) + { + distortion = 0.0; + for(j = 0; j < 8; j++) + { + distortion += (x[j] - CB[i][j])*(x[j] - CB[i][j])*W[j]; + } + + if(distortion < temp) + { + temp = distortion; + index = i; + } + } + + for(i = 0; i < M/2; i++) + { + y[i] = CB[index][i]; + } + + return index; +} + + +/*--------------------------------------------------------------------------- + * qlsf_ARSN_tcvq_Enc_16k() + * + * Predictive BC-TCQ encoder for LSF quantization + *--------------------------------------------------------------------------*/ + +static float qlsf_ARSN_tcvq_Enc_16k ( + const float *x, /* i : Vector to be encoded */ + float *y, /* o : Quantized LSF vector */ + short *indice, /* o : Indices */ + const float *w, /* i : LSF Weights */ + const short nBits, /* i : number of bits */ + short safety_net /* i : safety_net flag */ +) +{ + short i; + float temp_f; + float yy[M]; + float error_svq[M], error_svq_q[M]; + float x_q[M]; + if(safety_net == 1) + { + indice[0] = 1; + BcTcvq(1, x, x_q, w, &indice[1]); + + if(nBits>30) + { + /* SVQ */ + for(i = 0; i < M; i++) + { + error_svq[i] = (x[i] - x_q[i]) * scale_inv_ARSN[i]; + } + + /* 5bits 1st Split VQ for Residual*/ + indice[10] = SVQ_2d(error_svq, error_svq_q, w, AR_SVQ_CB1, 32); + /* 4bits 2nd Split VQ for Residual*/ + indice[11] = SVQ_2d(&error_svq[8], &error_svq_q[8], &w[8], AR_SVQ_CB2, 16 ); + + for(i = 0; i < M; i++) + { + x_q[i] = x_q[i] + (error_svq_q[i] * scale_ARSN[i]); + } + } + } + else + { + indice[0] = 0; + BcTcvq(0, x, x_q, w, &indice[1]); + + if(nBits>30) + { + /* SVQ */ + for(i = 0; i < M; i++) + { + error_svq[i] = x[i] - x_q[i]; + } + + /* 5bits 1st Split VQ for Residual*/ + indice[10] = SVQ_2d(error_svq, error_svq_q, w, AR_SVQ_CB1, 32 ); + /* 4bits 2nd Split VQ for Residual*/ + indice[11] = SVQ_2d(&error_svq[8], &error_svq_q[8], &w[8], AR_SVQ_CB2, 16 ); + + for(i = 0; i < M; i++) + { + x_q[i] = x_q[i] + error_svq_q[i]; + } + } + } + + v_sub( x_q, x, yy, M ); + v_mult( yy, yy, yy, M ); + temp_f = dotp( yy, w, M ); + + /* Recover the quantized LSF */ + mvr2r(x_q, y, M); + + return temp_f; +} + +/*-------------------------------------------------------------------* + * lsf_mid_enc() + * + * Mid-frame LSF quantization + --------------------------------------------------------------------*/ + +static void lsf_mid_enc( + Encoder_State *st, /* i/o: encoder state structure */ + const float int_fs, /* i : internal (ACELP) sampling frequency */ + const float qlsp0[], /* i : quantized LSPs from frame beginning */ + const float qlsp1[], /* i : quantized LSPs from frame end */ + float lsp[], /* i/o: mid-frame LSP */ + const short coder_type, /* i : coding type */ + const short bwidth, /* i : input signal bandwidth */ + const long core_brate, /* i : core bitrate */ + float Bin_Ener[], /* i : per bin log energy spectrum */ + short ppp_mode, + short nelp_mode +) +{ + float ftemp, lsf[M], qlsf[M], qlsf1[M], qlsf0[M], wghts[M], err, err_min; + short j, k, idx, nb_bits = 0, size = 0; + const float *ratio = 0; + + /* convert LSPs to LSFs */ + lsp2lsf( lsp, lsf, M, int_fs ); + lsp2lsf( qlsp0, qlsf0, M, int_fs ); + lsp2lsf( qlsp1, qlsf1, M, int_fs ); + + Unified_weighting( Bin_Ener, lsf, wghts, bwidth==NB, coder_type==UNVOICED, (int)(int_fs), M ); + + /* codebook selection, number of bits, size of the codebook */ + if ( ppp_mode == 0 && nelp_mode == 0 ) + { + nb_bits = mid_LSF_bits_tbl[LSF_BIT_ALLOC_IDX(core_brate, coder_type)]; + + /* codebook selection */ + if ( coder_type == VOICED ) + { + switch ( nb_bits ) + { + case 5: + { + ratio = tbl_mid_voi_wb_5b; + break; + } + case 4: + { + ratio = tbl_mid_voi_wb_4b; + break; + } + } + } + else if ( coder_type == UNVOICED ) + { + ratio = tbl_mid_unv_wb_5b; + } + else + { + /* GENERIC, TRANSITION, AUDIO and INACTIVE */ + switch ( nb_bits ) + { + case 5: + { + ratio = tbl_mid_gen_wb_5b; + break; + } + case 2: + { + ratio = tbl_mid_gen_wb_2b; + break; + } + } + } + + size = (short) pow2[nb_bits]; + } + else if ( ppp_mode == 1 ) + { + ratio = tbl_mid_voi_wb_1b; + nb_bits = 1; + size = 2; + } + else if ( nelp_mode == 1 ) + { + ratio = tbl_mid_unv_wb_4b; + nb_bits = 4; + size = 16; + } + + /* loop over codevectors */ + err_min = 1e30f; + idx = 0; + for ( k = 0; k < size; k++ ) + { + err = 0; + + for (j=0; j 0 && j < M && qlsf[j] < qlsf[j-1] + LSF_GAP_MID ) + { + qlsf[j] = qlsf[j-1] + LSF_GAP_MID; + } + + ftemp = lsf[j] - qlsf[j]; + err += wghts[j] * ftemp * ftemp; + } + + if ( err < err_min ) + { + err_min = err; + idx = k; + } + } + + /* calculate the quantized LSF vector */ + for ( j = 0; j < M; j++ ) + { + qlsf[j] = (1.0f - ratio[idx*M+j]) * qlsf0[j] + ratio[idx*M+j] * qlsf1[j]; + + if ( j > 0 && j < M && qlsf[j] < qlsf[j-1] + LSF_GAP_MID ) + { + qlsf[j] = qlsf[j-1] + LSF_GAP_MID; + } + } + + reorder_lsf( qlsf, LSF_GAP_MID, M, int_fs ); + + /* convert LSFs back to LSPs */ + lsf2lsp( qlsf, lsp, M, int_fs ); + + push_indice( st, IND_MID_FRAME_LSF_INDEX, idx, nb_bits ); + + return; +} diff --git a/src/libs/libevs/lib_enc/lsf_enc_fx.cpp b/src/libs/libevs/lib_enc/lsf_enc_fx.cpp deleted file mode 100755 index 5f26807d..00000000 --- a/src/libs/libevs/lib_enc/lsf_enc_fx.cpp +++ /dev/null @@ -1,2350 +0,0 @@ -/*==================================================================================== - EVS Codec 3GPP TS26.442 Apr 03, 2018. Version 12.11.0 / 13.6.0 / 14.2.0 - ====================================================================================*/ - -#include -#include "options.h" /* Compilation switches */ -#include "rom_enc_fx.h" -#include "rom_com_fx.h" /* Static table prototypes */ -#include "prot_fx.h" /* Function prototypes */ -#include "stl.h" -#include "prot_fx.h" - - - -/*-----------------------------------------------------------------* -* Local constants -*-----------------------------------------------------------------*/ -#define MIN_LOG_FX 0 -#define MIN_LOG_VAL_FX -15360 /* -60.0f in Q8 */ -#define MSVQ_MAXCNT 3000 -#define MAXINT32 MAX_32 - -/*---------------------------------------------------------------------* -* Local functions -*---------------------------------------------------------------------*/ - -static void lsfq_CNG_fx( Encoder_State_fx *st_fx, const Word16 *lsf, const Word16 *wghts, Word16 *qlsf, Word32 *p_offset_scale1, Word32 * p_offset_scale2, - Word16 * p_no_scales ); - -static Word32 vq_lvq_lsf_enc( Word16 pred_flag, Word16 mode, Word16 u[], Word16 * levels, Word16 stages, Word16 w[], Word16 Idx[], const Word16 * lsf, - const Word16 * pred, Word32 p_offset_scale1[][MAX_NO_SCALES+1], Word32 p_offset_scale2[][MAX_NO_SCALES+1], - Word16 p_no_scales[][2], Word16 *resq, Word16 * lsfq ); - -static void lsf_mid_enc_fx( Encoder_State_fx *st_fx,const Word16 int_fs, const Word16 qisp0[], const Word16 qisp1[], Word16 isp[], const Word16 coder_type, - const Word16 bwidth, const Word32 core_brate, Word32 Bin_Ener_old[], Word32 Bin_Ener[], Word16 Q_ener, Word16 ppp_mode, Word16 nelp_mode ); - - -/*===========================================================================*/ -/* FUNCTION : lsf_enc_fx() */ -/*---------------------------------------------------------------------------*/ -/* PURPOSE : Quantization of LSF vector */ -/*---------------------------------------------------------------------------*/ -/* INPUT ARGUMENTS : */ -/* _ (Word16) L_frame : length of the frame */ -/* _ (Word16) coder_type : coding type */ -/*---------------------------------------------------------------------------*/ -/* OUTPUT ARGUMENTS : */ -/* _ (Word16*) Aq : LP filter coefficient Q12 */ -/* _ (Word16*) lsf_ne w : LP filter coefficient Q(x2.56) */ -/* _ (Word16) st_fx->stab_fac_fx : LSF stability factor Q15 */ -/*---------------------------------------------------------------------------*/ -/* INPUT/OUTPUT ARGUMENTS : */ -/* _ (Struct) st_fx : state structure */ -/* _ (Word16*) lsp_new : LP filter coefficient Q15 */ -/* _ (Word16*) lsp_mid : LP filter coefficient Q15 */ -/* _ (Word16[]) st_fx->mem_AR_fx : AR memory of LSF quantizer */ -/* (past quantized LSFs without mean) x2.56 */ -/* _ (Word16[]) st_fx->clip_var_fx : pitch gain clipping memory x2.56*/ -/*---------------------------------------------------------------------------*/ - -/*---------------------------------------------------------------------------*/ -/* RETURN ARGUMENTS : */ -/* _ None */ -/*===========================================================================*/ -void lsf_enc_fx( - Encoder_State_fx *st_fx, /* i/o: state structure */ - const Word16 L_frame, /* i : length of the frame */ - const Word16 coder_type, /* i : coding type */ - Word16 *lsf_new, /* o : quantized LSF vector */ - Word16 *lsp_new, /* i/o: LSP vector to quantize/quantized */ - Word16 *lsp_mid, /* i/o : mid-frame LSP vector */ - Word16 *Aq, /* o : quantized A(z) for 4 subframes */ - Word16 *stab_fac, /* o : LSF stability factor */ - const Word16 Nb_ACELP_frames, - const Word16 Q_new -) -{ - Word16 nBits = 0; - Word16 int_fs; - Word16 force_sf = 0; - Word16 fec_lsf[M], stab; - Word16 i; - Word32 L_tmp; - - /* initialize */ - int_fs = INT_FS_16k_FX; - move16(); - if( sub(L_frame, L_FRAME) == 0 ) - { - int_fs = INT_FS_FX; - move16(); - } - - /* convert LSPs to LSFs */ - lsp2lsf_fx( lsp_new, lsf_new, M, int_fs); - - /* check resonance for pitch clipping algorithm */ - gp_clip_test_lsf_fx( lsf_new, st_fx->clip_var_fx, 0 ); - - /* Find the number of bits for LSF quantization */ - IF ( L_sub(st_fx->core_brate_fx, SID_2k40) == 0 ) - { - nBits = LSF_BITS_CNG; - move16(); - } - ELSE - { - test(); - IF ( (st_fx->nelp_mode_fx == 0) && (st_fx->ppp_mode_fx == 0) ) - { - nBits = LSF_bits_tbl[LSF_BIT_ALLOC_IDX_fx(st_fx->core_brate_fx, coder_type)]; - move16(); - } - ELSE IF ( sub(st_fx->nelp_mode_fx, 1) == 0 ) - { - nBits = 30; - move16(); - - if ( sub(st_fx->bwidth_fx,NB) == 0 ) - { - nBits = 32; - move16(); - } - } - ELSE IF ( sub(st_fx->ppp_mode_fx, 1) == 0 ) - { - nBits = 26; - move16(); - } - } - - /* first three ACELP frames after an HQ frame shall be processed only with safety-net quantizer */ - if( (sub(Nb_ACELP_frames, 3) < 0) ) - { - force_sf = 1; - move16(); - } - - /* in case of unstable filter in decoder FEC, choose safety-net to help FEC */ - IF ( sub(st_fx->next_force_safety_net_fx ,1) == 0 ) - { - force_sf = 1; - move16(); - st_fx->next_force_safety_net_fx = 0; - move16(); - } - - /*-------------------------------------------------------------------------------------* - * Frame end LSF quantization - *-------------------------------------------------------------------------------------*/ - - lsf_end_enc_fx( st_fx, lsf_new, lsf_new, st_fx->mem_AR_fx, st_fx->mem_MA_fx, nBits, coder_type, st_fx->bwidth_fx, - st_fx->Bin_E_fx, Q_new+QSCALE-2, int_fs, st_fx->core_brate_fx, &st_fx->streaklimit_fx, &st_fx->pstreaklen_fx, - force_sf, 0, 0, NULL, NULL, NULL, st_fx->coder_type_raw_fx ); - - /* convert quantized LSFs back to LSPs */ - lsf2lsp_fx( lsf_new, lsp_new, M, int_fs); - - test(); - IF ( sub(st_fx->last_core_fx, HQ_CORE) == 0 && sub(st_fx->core_fx,ACELP_CORE) == 0 ) - { - /* don't use old LSF values if this is the first ACELP frame after HQ frames */ - Copy( lsf_new, st_fx->lsf_old_fx, M ); - } - IF ( L_sub(st_fx->core_brate_fx, SID_2k40) == 0 ) - { - /* return if SID frame (conversion to A(z) done in the calling function) */ - return; - } - - /*-------------------------------------------------------------------------------------* - * FEC - enforce safety-net in the next frame in case of unstable filter - *-------------------------------------------------------------------------------------*/ - - IF( sub(st_fx->last_L_frame_fx, st_fx->L_frame_fx) != 0 ) - { - /* FEC - in case of core switching, use old LSFs */ - Copy( st_fx->lsf_old_fx, st_fx->lsfoldbfi1_fx, M ); - Copy( st_fx->lsf_old_fx, st_fx->lsfoldbfi0_fx, M ); - Copy( st_fx->lsf_old_fx, st_fx->lsf_adaptive_mean_fx, M ); - } - - FEC_lsf_estim_enc_fx( st_fx, st_fx->L_frame_fx, fec_lsf ); - - /* in case of FEC in decoder - calculate LSF stability */ - stab = lsf_stab_fx( lsf_new, fec_lsf, 0, st_fx->L_frame_fx ); - - test(); - test(); - test(); - /* If decoder FEC frame may be unstable force safety-net usage */ - IF ( (sub(st_fx->L_frame_fx, L_FRAME16k)==0) && (sub(stab, STAB_FAC_LIMIT_FX)< 0) && (sub(coder_type, GENERIC) == 0 )) - { - st_fx->next_force_safety_net_fx = 1; - move16(); - } - ELSE IF((sub(stab, STAB_FAC_LIMIT_FX) < 0) && (sub(st_fx->clas_fx, VOICED_CLAS)==0 || (sub(st_fx->clas_fx,VOICED_CLAS) < 0 && sub(coder_type,AUDIO) == 0) ) ) - { - st_fx->next_force_safety_net_fx = 1; - move16(); - } - - - /* FEC - update adaptive LSF mean vector */ - FOR (i=0; ilsfoldbfi1_fx[i], 10922); /*Q(x2.56+16)*/ - L_tmp = L_mac(L_tmp, st_fx->lsfoldbfi0_fx[i], 10922); /*Q(x2.56+16)*/ - st_fx->lsf_adaptive_mean_fx[i] = round_fx(L_tmp); /*Q(x2.56)*/ - } - - /* FEC - update LSF memories */ - Copy( st_fx->lsfoldbfi0_fx, st_fx->lsfoldbfi1_fx, M ); - Copy( lsf_new, st_fx->lsfoldbfi0_fx, M ); - - - /*-------------------------------------------------------------------------------------* - * Mid-frame LSF encoding - * LSP interpolation and conversion of LSPs to A(z) - *-------------------------------------------------------------------------------------*/ - if(st_fx->rate_switching_reset) - { - /*extrapolation in case of unstable LSF convert*/ - Copy( lsp_new, st_fx->lsp_old_fx, M ); - Copy( lsf_new, st_fx->lsf_old_fx, M ); - } - /* Mid-frame LSF encoding */ - lsf_mid_enc_fx( st_fx, int_fs, st_fx->lsp_old_fx, lsp_new, lsp_mid, coder_type, st_fx->bwidth_fx, st_fx->core_brate_fx, st_fx->Bin_E_old_fx, st_fx->Bin_E_fx, Q_new+QSCALE-2, st_fx->ppp_mode_fx, st_fx->nelp_mode_fx); - - test(); - IF ( sub(st_fx->last_core_fx,HQ_CORE) == 0 && sub(st_fx->core_fx,ACELP_CORE) == 0 ) - { - /* don't use old LSP/LSF values if this is the first ACELP frame after HQ frames */ - Copy( lsp_mid, st_fx->lsp_old_fx, M ); - lsp2lsf_fx( lsp_mid, st_fx->lsf_old_fx, M, int_fs ); - } - - /* LSP interpolation and conversion of LSPs to A(z) */ - int_lsp4_fx( L_frame, st_fx->lsp_old_fx, lsp_mid, lsp_new, Aq, M, 0 ); - - /*------------------------------------------------------------------* - * Check LSF stability (distance between old LSFs and current LSFs) - *------------------------------------------------------------------*/ - *stab_fac = lsf_stab_fx( lsf_new, st_fx->lsf_old_fx, 0, st_fx->L_frame_fx ); - - return; -} - - -/*-------------------------------------------------------------------* -* lsfq_CNG_fx() -* -* LSF quantizer for SID frames (uses 29 bits, 4 for VQ, 25 for LVQ) -* Note: -* The sampling frequency of the LP-CNG frame can be determined by checking the value of the highest order LSF -* coefficient (last coefficient of lsf). If the last LSF coefficient (lsf[M-1]) is larger than 6350 -* the decoded frame is WB2 with sampling rate of 16 kHz, otherwise it is sampled at 12.8kHz and contains -* either NB or WB LSF data. -*-------------------------------------------------------------------*/ - -static void lsfq_CNG_fx( - Encoder_State_fx *st_fx, - const Word16 *lsf, /*x2.56 unquantized LSF vector */ - const Word16 *wghts, /*Q10 LSF weights */ - Word16 *qlsf, /*x2.56 quantized LSF vecotor */ - Word32 *p_offset_scale1, - Word32 *p_offset_scale2, - Word16 *p_no_scales -) -{ - Word16 i, j, idx_cv, idx_lvq[3]; - Word32 min_dist, dist; - Word16 dd[M], ddq[M]; - const Word16 *p_cb; - Word16 first_cb, last_cb; - Word16 idx_lead_cng[2], idx_scale_cng[2]; - Word16 tmp; - - idx_cv = 0; - move16(); - - /* quantize first stage with 4 bits - The sampling frequency of the LP-CNG frame can be determined by checking the value of the highest order LSF - coefficient (last coefficient of lsf). If the last LSF coefficient (lsf[M-1]) is larger than 6350 - the decoded frame is WB2 with sampling rate of 16 kHz, otherwise it is sampled at 12.8kHz and contains - either NB or WB LSF data. */ - IF(sub(lsf[M - 1], WB_LIMIT_LSF_FX) > 0) /* 16kHz sampled LSF vector*/ - { - p_cb = &CNG_SN1_fx[0]; - move16(); - first_cb = 0; - move16(); - last_cb = 6; - move16(); - } - ELSE /* 12.8kHz sampled LSF vector*/ - { - p_cb = &CNG_SN1_fx[6*M]; - move16(); - first_cb = 6; - move16(); - last_cb = M; - move16(); - } - - - min_dist = L_add(MAXINT32, 0); - FOR ( i = first_cb; i < last_cb; i++ ) - { - tmp = sub(*p_cb,shl(lsf[0],1)); /*x2.56 */ - dist = Mult_32_16(L_mult0(wghts[0], *p_cb),tmp); /*Q8 + x2.56 -Q15 + x2.56 = Q-7 + x2.56+x.256 */ - p_cb++; - FOR (j=1; j 0) - { - /* Safety-net */ - safety_net = 1; - move16(); - } - ELSE - { - /* Predictive */ - safety_net = 0; - move16(); - } - return safety_net; -} - - -/*========================================================================*/ -/* FUNCTION : lsf_end_enc_fx() */ -/*------------------------------------------------------------------------*/ -/* PURPOSE : Quantization of LSF parameters */ -/*------------------------------------------------------------------------*/ -/* INPUT ARGUMENTS : */ -/* _ (Word16*) lsf : LSF in the frequency domain (0..6400) x2.56 */ -/* _ (Word16) coder_type : coding type */ -/* _ (Word16) bwidth : input signal bandwidth */ -/* _ (Word16) nBits : number of bits used for ISF quantization */ -/* _ (Word16*) stable_isp : most recent stable ISP (can be */ -/* removed after passing to LSF) Q15 */ -/* _ (Word16*) stable_lsp : most recent stable LSP Q15 */ -/* _ (Word32*) grid : Table of 100 grid points for evaluating */ -/* Chebyshev polynomials Q31 */ -/* _ (Word16) int_fs : sampling frequency */ -/* _ (Word32) core_brate : Coding Bit Rate */ -/* _ (Word16) force_sf : Force safety-net usage if possible */ -/* _ (Word32*) Bin_Ener : FFT Bin energy 128 *2 sets Q_ener */ -/* _ (Word16) Q_ener : Q format of Bin_Ener */ -/* _ (Word32*) offset_scale1: offsets for LSF LVQ structure 1st */ -/* 8-dim subvector Q0 */ -/* _ (Word32*) offset_scale2: offsets for LSF LVQ structure 2nd */ -/* 8-dim subvector Q0 */ -/* _ (Word32*) offset_scale1_p: offsets for LSF LVQ structure, pred. */ -/* case, 1st 8-dim subvector Q0 */ -/* _ (Word32*) offset_scale2_p: offsets for LSF LVQ structure, */ -/* pred. case, 2nd 8-dim subvector Q0 */ -/* _ (Word16*) no_scales : LSF LVQ structure Q0 */ -/* _ (Word16*) no_scales_p : LSF LVQ structure Q0 */ -/*------------------------------------------------------------------------*/ -/* INPUT/OUTPUT ARGUMENTS : */ -/* _ (Word16*) mem_AR : quantizer memory for AR model x2.56 */ -/*------------------------------------------------------------------------*/ -/* OUTPUT ARGUMENTS : */ -/* _ (Word16*) qlsf : quantized LSFs in the cosine domain x2.56 */ -/*------------------------------------------------------------------------*/ - -/*------------------------------------------------------------------------*/ -/* RETURN ARGUMENTS : */ -/* _ None */ -/*========================================================================*/ -void lsf_end_enc_fx( - Encoder_State_fx *st, /* i/o: encoder state structure */ - const Word16 *lsf, /* i : LSF in the frequency domain (0..6400) */ - Word16 *qlsf, /* o : quantized LSF */ - Word16 *mem_AR, /* i/o: quantizer memory for AR model */ - Word16 *mem_MA, /* i/o: quantizer memory for MA model */ - const Word16 nBits_in, /* i : number of bits to spend on ISF quantization */ - const Word16 coder_type_org,/* i : coding type */ - const Word16 bwidth, /* i : input signal bandwidth */ - Word32 *Bin_Ener, /* i : FFT Bin energy 128 *2 sets */ - Word16 Q_ener, /* i : Q valuen for Bin_Ener */ - const Word32 int_fs, /* i : sampling frequency */ - Word32 core_brate, /* i : ACELP core bitrate */ - Word16 *streaklimit, /* i/o: Multiplier to limit consecutive predictive usage */ - Word16 *pstreaklen, /* i/o: Lentght of the current predictive mode streak */ - Word16 force_sf, /* i : Force safety-net usage if coding type supports */ - Word16 rf_flag, /* i : Channel aware mode has some special cases */ - Word16 mode2_flag, /* i : MODE2 mode has some special cases */ - Word16 * lpc_param, - Word16 * no_indices, - Word16 * bits_param_lpc, - Word16 coder_type_raw /* i : Coder type (LSF coder_type have some special cases)*/ -) -{ - Word16 i; - Word16 Idx0[MAX_VQ_STAGES+3]; /* Optimal codebook indices for safety-net quantizer */ - Word16 Idx1[MAX_VQ_STAGES+3]; /* Optimal codebook indices for predictive quantizer */ - Word16 indice[MAX_VQ_STAGES+3]; /* Temp. array of indice for vector de-quantizer */ - Word16 mode_lvq = 0, mode_lvq_p = 0; /* LVQ mode and predictive LVQ mode */ - Word16 bits0[MAX_VQ_STAGES], bits1[MAX_VQ_STAGES]; - const Word16 *Bit_alloc1 = NULL; - Word32 Err[2]; /* Quantization error for safety-net(0) and predictive(1) quantizers */ - Word16 Tmp [M]; /* Temporary target vector (mean and prediction removed) */ - Word16 pred0[M]; /* Prediction for the safety-net quantizer (usually mean) */ - Word16 pred1[M]; /* Prediction for the predictive quantizer */ - Word16 pred2[M]; /* Prediction for the predictive quantizer */ - Word16 wghts[M]; /* Weighting used for quantizer (currently GSM based) */ - Word16 stages0; /* Amount of stages used by safety-net quantizer */ - Word16 stages1; /* Amount of stages used by predictive quantizer */ - Word16 levels0[MAX_VQ_STAGES]; /* Sizes of different codebook stages for safety-net quantizer */ - Word16 levels1[MAX_VQ_STAGES]; /* Sizes of different codebook stages for predictive quantizer */ - Word16 predmode; /* 0: safety-net only, 1: predictive only, 2: best of the two */ - Word16 safety_net, cumleft, num_bits; - Word16 *Idx, stages, *bits; - Word16 Tmp2[M], Tmp1[M]; - Word32 abs_threshold; /* Absolute threshold depending on signal bandwidth, that indicates - very good perceptual LSF quantization performance */ - Word16 lsfq[M*2], resq[M*2]; - Word16 coder_type; /* coder type (from LSF quantizer point of view) */ - Word16 nBits; /* Number of bits */ - Word16 TCQIdx0[M+2]; /* Optimal codebook indices for VQ-TCQ quantizer */ - Word16 *TCQIdx; - Word16 tmp; - - nBits = nBits_in; - move16(); - /* Update LSF coder_type for LSF quantizer for some special cases */ - test(); - test(); - test(); - IF(sub(coder_type_org, GENERIC)== 0 && L_sub(int_fs, INT_FS_16k)== 0 && (rf_flag == 0) && (mode2_flag == 0)) - { - IF (sub(coder_type_raw, VOICED) == 0) - { - coder_type = VOICED; - move16(); /* Reflect Inactive mode */ - } - ELSE - { - nBits = sub(nBits,1); /* This is for real Generic*/ - coder_type = coder_type_org; - move16(); - } - } - ELSE - { - coder_type = coder_type_org; - move16(); - } - - /*----------------------------------------------------------------------------------- -* - * Calculate the number of stages and levels for each stage based on allowed bit budget - * Set absolute threshold for codebook-type decision logic depending on signal bandwidth - *------------------------------------------------------------------------------------ -*/ - IF ( sub(bwidth, NB) == 0 ) - { - abs_threshold = L_add(SFNETLOWLIMIT_NB, 0); - } - ELSE - { - abs_threshold = L_add(SFNETLOWLIMIT_WB, 0); - } - /* Calculate LSF weighting coefficients */ - Unified_weighting_fx(&Bin_Ener[L_FFT/2], Q_ener, lsf, wghts, sub(bwidth, NB) == 0, sub(coder_type,UNVOICED) == 0, int_fs,M); - - /*--------------------------------------------------------------------------------* - * LSF quantization of SID frames - *--------------------------------------------------------------------------------*/ - IF ( L_sub(core_brate, SID_2k40) == 0 ) - { - lsfq_CNG_fx( st, lsf, wghts, qlsf, &st->offset_scale1_fx[0][0], &st->offset_scale2_fx[0][0], &st->no_scales_fx[0][0] ); - sort_fx( qlsf, 0, M-1 ); - reorder_lsf_fx( qlsf, MODE1_LSF_GAP_FX, M, int_fs ); - - return; - } - /* Find allowed predictor mode for current coder_type. (SN only (0), SN/AR switched (2) or MA predictive (1) */ - predmode = find_pred_mode(coder_type, bwidth, int_fs, &mode_lvq, &mode_lvq_p,st->total_brate_fx); - - /*----------------------------------------------------------------* - * Calculate number of stages and levels for each stage based on the allowed bit allocation - * (subtract one bit for LSF predictor selection) - *----------------------------------------------------------------*/ - lsf_allocate_fx( sub(nBits, shr(predmode,1)), mode_lvq, mode_lvq_p, &stages0, &stages1, levels0, levels1, bits0, bits1); - - - /*--------------------------------------------------------------------------------* - * LSF quantization of all other frames but SID frames - * Select safety-net or predictive mode - *--------------------------------------------------------------------------------*/ - - Err[0] = MAXINT32; - move32(); - Err[1] = MAXINT32; - move32(); - /* for mem_MA update */ - FOR (i=0; ioffset_scale1_fx,st->offset_scale2_fx, st->no_scales_fx, resq, lsfq); - safety_net = 1; - move16(); - *pstreaklen = 0; - move16();/* predictive LSF quantizer streak is ended with safety-net */ - } - ELSE IF (sub(predmode, 1) == 0) /* only MA prediction */ - { - Vr_subt(lsf, pred1, Tmp1, M); - Err[1] = vq_lvq_lsf_enc(2, mode_lvq_p, Tmp1, levels1, stages1, wghts, Idx1, lsf, pred1, - st->offset_scale1_p_fx,st->offset_scale2_p_fx,st->no_scales_p_fx,resq, lsfq ); - - safety_net = 0; - move16(); - } - ELSE - { - /* Adaptive scaling factor (multiplier) is updated in order to reduce the amount of consecutive predictive frames in - case of possible frame erasure. AR-predictive usage for VOICED mode is allowed to be higher than other modes. */ - test(); - test(); - test(); - IF ( ((sub(*pstreaklen, (STREAKLEN+3))>0)&&(sub(coder_type, VOICED)== 0)) || ((sub(*pstreaklen, (STREAKLEN)) >0) &&(sub(coder_type, VOICED) != 0))) - { - /* update the adaptive scaling factor to become smaller with increasing number of concecutive predictive frames. */ - *streaklimit = mult(*streaklimit,STREAKMULT_FX); - move16(); - } - - IF ( *pstreaklen == 0 ) - { - /* reset the consecutive AR-predictor multiplier */ - *streaklimit = 32767; /*1.0 in Q15 */ move16(); - } - - /* VOICED_WB@16kHz */ - test(); - IF ( L_sub(int_fs, INT_FS_16k) == 0 && sub(coder_type, VOICED) == 0 ) - { - /* Subtract mean and AR prediction */ - Copy( ModeMeans_fx[mode_lvq], pred0, M ); - /* subtract only mean */ - Vr_subt(lsf, pred0, Tmp, M); - - FOR (i = 0; i < M; i++) - { - /* subtract mean and AR prediction */ - pred2[i] = mult(Predictors_fx[mode_lvq_p][i],sub(mem_AR[i],pred0[i])); - Tmp2[i] = sub(Tmp[i], pred2[i]); - pred2[i] = add(pred2[i], pred0[i]); - } - - /* select safety_net or predictive */ - safety_net = qlsf_Mode_Select_fx( wghts, Tmp2, *streaklimit, OP_LOOP_THR_HVO ); - IF ( sub(force_sf, 1) == 0 ) - { - safety_net = 1; - move16(); - } - - IF ( safety_net ) - { - /* Safety-net - BC-TCQ quantization : SN */ - Err[0] = qlsf_ARSN_tcvq_Enc_16k_fx( Tmp, lsfq, TCQIdx0, wghts, sub(nBits,1), safety_net); - *pstreaklen = 0; - move16(); - } - ELSE - { - /* predictive - BC-TCQ quantization : AR */ - Err[1] = qlsf_ARSN_tcvq_Enc_16k_fx( Tmp2, lsfq, TCQIdx0, wghts, sub(nBits,1), safety_net); - *pstreaklen=add(*pstreaklen,1); - } - } - /* all other frames (not VOICED@16kHz) */ - ELSE - { - /* Subtract mean and AR prediction */ - Copy( ModeMeans_fx[mode_lvq], pred0, M ); - /* subtract only mean */ - Vr_subt(lsf, pred0, Tmp, M); - - FOR (i = 0; i < M; i++) - { - /* subtract mean and AR prediction */ - pred2[i] = add(pred0[i],mult(Predictors_fx[mode_lvq_p][i],sub(mem_AR[i],pred0[i]))); - Tmp2[i] = sub(lsf[i], pred2[i]); - } - - /* safety-net */ - Err[0] = vq_lvq_lsf_enc(0, mode_lvq, Tmp, levels0, stages0, wghts, Idx0, lsf, pred0, - st->offset_scale1_fx,st->offset_scale2_fx,st->no_scales_fx, resq, lsfq); - /* Predictive quantizer is calculated only if it can be selected */ - test(); - IF (!force_sf || L_sub(Err[0],abs_threshold) > 0 ) - { - Err[1] = vq_lvq_lsf_enc(2, mode_lvq_p, Tmp2, levels1, stages1, wghts, Idx1, lsf, pred2, - st->offset_scale1_p_fx, st->offset_scale2_p_fx, st->no_scales_p_fx, &resq[M], &lsfq[M]); - - } - test(); - test(); - /* Select whether to use safety-net (non-predictive) or predictive LSF quantizer. The decision is based on following: - if the non-predictive (safety-net) quantization error (Err[0]) is low enough (spectral distortion is low) it is selected - or if the predictively quantized error (Err[1]) is by at least adaptive margin smaller than non-predictive quantizer. - or if the in case of frame erasure the resulting concealed predictive LSF would be unstable safety-net is selected */ - IF ( force_sf || L_sub(Mult_32_16(Err[0],(*streaklimit)),L_add(Err[1],Mult_32_16(Err[1],PREFERSFNET_FX))) < 0 || L_sub(Err[0], abs_threshold) < 0 ) - { - safety_net = 1; - move16(); - *pstreaklen = 0; - move16(); /* Reset the consecutive predictive frame counter */ - } - ELSE - { - safety_net = 0; - move16(); /* Increase the consecutive predictive frame counter by one */ - *pstreaklen=add(*pstreaklen,1); - } - } - } - /*--------------------------------------------------------------------------* - * Write indices to array - *--------------------------------------------------------------------------*/ - - IF (mode2_flag == 0) - { - /* write coder_type bit for VOICED@16kHz or GENERIC@16kHz */ - test(); - IF(sub(coder_type_org, GENERIC)==0 && L_sub(int_fs, INT_FS_16k)==0) - { - /* VOICED =2 and GENERIC=3, so "coder_type-2" means VOICED =0 and GENERIC=1*/ - push_indice_fx( st, IND_LSF_PREDICTOR_SELECT_BIT, sub(coder_type,2), 1 ); - } - - /* write predictor selection bit */ - IF ( sub(predmode, 2) == 0 ) - { - push_indice_fx( st, IND_LSF_PREDICTOR_SELECT_BIT, safety_net, 1 ); - } - - test(); - IF ( sub(coder_type, VOICED)== 0 && L_sub(int_fs, INT_FS_16k) == 0 ) - { - /* BC-TCVQ (only for VOICED@16kHz) */ - TCQIdx = &TCQIdx0[1]; - Bit_alloc1 = &BC_TCVQ_BIT_ALLOC_40B[1]; - FOR( i=0; i<(M/2)+3; i++ ) - { - push_indice_fx( st, IND_LSF, TCQIdx[i], Bit_alloc1[i]); - } - } - ELSE - { - cumleft = nBits; - move16(); - IF (sub( predmode, 2 )==0) - { - /* subtract predictor selection bit */ - cumleft = sub(nBits, 1); - } - - IF ( safety_net ) - { - stages = stages0; - move16(); - Idx = Idx0; - move16(); - bits = bits0; - move16(); - } - ELSE - { - stages = stages1; - move16(); - Idx = Idx1; - move16(); - bits = bits1; - move16(); - } - - tmp = sub(stages,1); - FOR ( i=0; i 0 ) - { - indice[i] = Idx[i]; - move16(); - - IF ( sub(cumleft, LEN_INDICE) >0 ) - { - num_bits = LEN_INDICE; - move16(); - } - ELSE - { - num_bits = cumleft; - move16(); - } - - cumleft = sub(cumleft, num_bits); - push_indice_fx( st, IND_LSF, indice[i], num_bits ); - i=add(i,1); - } - } - } - ELSE - { - test(); - IF ( sub(coder_type, VOICED)==0 && L_sub(int_fs, INT_FS_16k)== 0 ) - { - /* BC-TCVQ (only for VOICED@16kHz) */ - /* Number of quantization indices */ - *no_indices = 10; - move16(); - FOR(i=0; i<*no_indices; i++) - { - lpc_param[i] = TCQIdx0[i]; - move16(); - bits_param_lpc[i] = BC_TCVQ_BIT_ALLOC_40B[i]; - move16(); - } - } - ELSE - { - /* Number of quantization indices */ - - /* there are 31 bits */ - IF (sub(safety_net, 1) == 0) - { - Idx = Idx0; - move16(); - *no_indices = add(stages0 ,1); - FOR( i=0; i0; i--) - { - tmp = sub(i,1); - lpc_param[i] = lpc_param[tmp]; - move16(); - bits_param_lpc[i] = bits_param_lpc[tmp]; - move16(); - } - lpc_param[0] = safety_net; - move16();/* put the safety net info on the last param */ - bits_param_lpc[0] = 1; - move16(); - *no_indices = add(*no_indices,1); - } - } - } - - - /*--------------------------------------------------------------------------* - * De-quantize encoded LSF vector - *--------------------------------------------------------------------------*/ - - IF ( safety_net ) - { - /* Safety-net */ - test(); - IF ( sub(coder_type, VOICED) == 0 && L_sub(int_fs, INT_FS_16k) == 0 ) - { - /* BC-TCQ */ - Copy( lsfq, mem_MA, M ); - Vr_add( lsfq, pred0, qlsf, M ); - } - ELSE - { - vq_dec_lvq_fx( 1, qlsf, &indice[0], stages0, M, mode_lvq, levels0[stages0-1], - &st->offset_scale1_fx[0][0], &st->offset_scale2_fx[0][0], &st->offset_scale1_p_fx[0][0], &st->offset_scale2_p_fx[0][0], - &st->no_scales_fx[0][0], &st->no_scales_p_fx[0][0] ); - - Vr_add( qlsf, pred0, qlsf, M ); - Vr_subt(qlsf, pred1,mem_MA, M); - } - } - ELSE - { - test(); - IF ( sub(coder_type, VOICED)== 0 && L_sub(int_fs, INT_FS_16k) == 0 ) - { - /* BC-TCVQ */ - Copy( lsfq, mem_MA, M ); - Vr_add( lsfq, pred2, qlsf, M ); - } - ELSE - { - /* LVQ */ - vq_dec_lvq_fx( 0, qlsf, &indice[0], stages1, M, mode_lvq_p, levels1[stages1-1], - &st->offset_scale1_fx[0][0], &st->offset_scale2_fx[0][0], &st->offset_scale1_p_fx[0][0], - &st->offset_scale2_p_fx[0][0], &st->no_scales_fx[0][0], &st->no_scales_p_fx[0][0] ); - IF (sub(predmode,1) == 0) - { - Copy(qlsf, mem_MA, M); - Vr_add( qlsf, pred1, qlsf, M ); - } - ELSE - { - Vr_add( qlsf, pred2, qlsf, M ); - Vr_subt(qlsf, pred1, mem_MA, M); - } - } - } - - /* Sort the quantized vector to ascending order */ - sort_fx( qlsf, 0, M-1 ); - - /* Verify stability by adding minimum separation */ - reorder_lsf_fx( qlsf, MODE1_LSF_GAP_FX, M, int_fs ); - - /* Update AR-predictor memories */ - Copy( qlsf, mem_AR, M ); - return; -} - - - - -/*-------------------------------------------------------------------* -* first_VQstages() -* -* -*-------------------------------------------------------------------*/ - -static void first_VQstages( - const Word16 * const *cb, - Word16 u[], /* i : vector to be encoded (prediction and mean removed) */ - Word16 *levels, /* i : number of levels in each stage */ - Word16 stagesVQ, /* i : number of stages */ - Word16 w[], /* i : weights */ - Word16 N, /* i : vector dimension */ - Word16 max_inner, /* i : maximum number of swaps in inner loop */ - Word16 indices_VQstage[] -) -{ - Word16 resid_buf[2*LSFMBEST*M], *resid[2]; - Word32 dist_buf[2*LSFMBEST], *dist[2], en; - Word32 f_tmp, L_tmp, L_tmp1, *pTmp32; - Word16 Tmp[M], *pTmp, cs; - Word16 *pTmp_short, idx_buf[2*LSFMBEST*MAX_VQ_STAGES], parents[LSFMBEST], counter=0, j, - m, s,c, c2, p_max, *indices[2]; - Word16 maxC = LSFMBEST; - - /*float dd[16];*/ - const Word16 *cb_stage, *cbp; - - /* Set pointers to previous (parent) and current node (parent node is indexed [0], current node is indexed [1]) */ - indices[0] = idx_buf; - move16(); - indices[1] = idx_buf + maxC*stagesVQ; - move16(); - resid[0] = resid_buf; - move16(); - resid[1] = resid_buf + maxC*N; - move16(); - dist[0] = dist_buf; - move16(); - dist[1] = dist_buf + maxC; - move16(); - - set16_fx( idx_buf, 0, (const Word16)(2*stagesVQ*maxC) ); - set16_fx( parents, 0, maxC ) ; - - /* Set up inital distance vector */ - L_tmp = L_deposit_l(0); - FOR( j=0; j0) - { - /* first VQ stages */ - first_VQstages( cb, u, levels, stagesVQ, w, M, MSVQ_MAXCNT, indices_firstVQ ); - } - - - FOR ( i=0; i= 0; stage --) - { - bestCodeword[stage] = codeWord[stage][prev_state]; - move16(); - bestState[stage] = preState[stage][prev_state]; - move16(); - prev_state = bestState[stage]; - move16(); - } - - FOR (stage = 0; stage < 4; stage ++) - { - bestCodeword[stage + 4] = blockCodeword[fBlock][stage]; - move16(); - } - - return fBlock; -} - -static void quantEnc_fx( - Word16 *y_fx, - Word16 c[], - const Word16 CB_SUB1_fx[][128][2], - const Word16 CB_SUB2_fx[][64][2], - const Word16 CB_SUB3_fx[][32][2], - const Word16 itc_fx[][2][2] -) -{ - Word16 i,j; - Word16 stage; - Word16 pred_fx[N_DIM], Y_fx[8][2]; - - /* stage #1 */ - Y_fx[0][0] = CB_SUB1_fx[0][c[0]][0]; - move16(); - Y_fx[0][1] = CB_SUB1_fx[0][c[0]][1]; - move16(); - - /* stage #2 */ - pred_fx[0] = add(mult_r(itc_fx[0][0][0], Y_fx[0][0]), mult_r(itc_fx[0][0][1], Y_fx[0][1])); - move16(); - pred_fx[1] = add(mult_r(itc_fx[0][1][0], Y_fx[0][0]), mult_r(itc_fx[0][1][1], Y_fx[0][1])); - move16(); - Y_fx[1][0] = add(CB_SUB1_fx[1][c[1]][0], pred_fx[0]); - move16(); - Y_fx[1][1] = add(CB_SUB1_fx[1][c[1]][1], pred_fx[1]); - move16(); - - /* stage #3 - #4 */ - FOR (stage = 2; stage < N_STAGE_VQ-4; stage ++) - { - pred_fx[0] = add(mult_r(itc_fx[stage-1][0][0], Y_fx[stage-1][0]), mult_r(itc_fx[stage-1][0][1], Y_fx[stage-1][1])); - move16(); - pred_fx[1] = add(mult_r(itc_fx[stage-1][1][0], Y_fx[stage-1][0]), mult_r(itc_fx[stage-1][1][1], Y_fx[stage-1][1])); - move16(); - - Y_fx[stage][0] = add(CB_SUB2_fx[stage-2][c[stage]][0], pred_fx[0]); - move16(); - Y_fx[stage][1] = add(CB_SUB2_fx[stage-2][c[stage]][1], pred_fx[1]); - move16(); - } - - /* stage #5 - #8 */ - FOR (stage = N_STAGE_VQ-4; stage < N_STAGE_VQ; stage ++) - { - pred_fx[0] = add(mult_r(itc_fx[stage-1][0][0], Y_fx[stage-1][0]), mult_r(itc_fx[stage-1][0][1], Y_fx[stage-1][1])); - move16(); - pred_fx[1] = add(mult_r(itc_fx[stage-1][1][0], Y_fx[stage-1][0]), mult_r(itc_fx[stage-1][1][1], Y_fx[stage-1][1])); - move16(); - - Y_fx[stage][0] = add(CB_SUB3_fx[stage-4][c[stage]][0], pred_fx[0]); - move16(); - Y_fx[stage][1] = add(CB_SUB3_fx[stage-4][c[stage]][1], pred_fx[1]); - move16(); - } - - /* Transform Vector to Scalar */ - FOR (i = 0; i < N_STAGE_VQ; i++) - { - FOR (j = 0; j < N_DIM; j++) - { - y_fx[i*N_DIM+j] = Y_fx[i][j]; - move16(); - } - } - - return; -} - -static void buildCode_fx( - Word16 *ind, - Word16 fins, - Word16 c[], - Word16 s[] -) -{ - Word16 stage; - Word16 BrIndex[4]; - - set16_fx(BrIndex, 0, (N_STAGE_VQ - 4)); - - - FOR (stage = N_STAGE_VQ - 4; stage >= 1; stage--) - { - if(sub(s[stage], 7) > 0) - { - BrIndex[stage-1] =1; - move16(); - } - } - ind[0] = fins; - move16(); - - /* stage #1 - #2 */ - FOR (stage = 0; stage < 2; stage++) - { - ind[stage+1] = shl(BrIndex[stage], 4); - move16(); - ind[stage+1] = add(ind[stage+1], shr(c[stage], 3)); - move16(); - } - - /* stage #3 - #4 */ - FOR (stage = 2; stage < N_STAGE_VQ - 4; stage++) - { - ind[stage+1] = shl(BrIndex[stage], 3); - move16(); - ind[stage+1] = add(ind[stage+1], shr(c[stage], 3)); - move16(); - } - - /* Stage #5 - #8 */ - FOR (stage = N_STAGE_VQ-4; stage < N_STAGE_VQ; stage++) - { - ind[stage+1] = shr(c[stage], 3); - move16(); - } - - return; -} -static void BcTcvq_fx( - Word16 snFlag, - const Word16 *x_fx, - Word16 *y_fx, - const Word16 *weight_fx, - Word16 *ind -) -{ - Word16 X_fx[N_STAGE_VQ][N_DIM], W_fx[N_STAGE_VQ][N_DIM]; - - /* Count Variable */ - Word16 i,j; - - /* TCVQ Structure */ - Word16 stage, state, prev_state; - Word16 preState[N_STAGE_VQ][NUM_STATE]; - Word16 codeWord[N_STAGE_VQ][NUM_STATE]; - Word32 acumDist_fx[N_STAGE_VQ-4][NUM_STATE]; - Word16 inis, fins, ptr_fins; - Word16 fBlock; - Word16 fState[NUM_STATE]; - Word16 fCodeword[4][4]; - Word16 iniBlock[NUM_STATE]; - Word16 blockCodeword[NUM_STATE][4]; - - /* Prediction variable */ - Word16 quant_fx[N_STAGE_VQ][NUM_STATE][N_DIM]; - - /* Distortion variable */ - Word32 minDist_fx; - Word32 fDist_fx; - Word32 blockDist_fx[NUM_STATE]; - - /* Decoding variable */ - Word16 bestCodeword[N_STAGE_VQ]; - Word16 bestState[N_STAGE_VQ]; - - /* Code Share variable */ - const Word16 (*TCVQ_CB_SUB1_fx)[128][2], (*TCVQ_CB_SUB2_fx)[64][2], (*TCVQ_CB_SUB3_fx)[32][2]/**/; - const Word16 (*IntraCoeff_fx)[2][2]; - - /* Memoryless Module */ - IF (snFlag) - { - TCVQ_CB_SUB1_fx = SN_TCVQ_CB_SUB1_fx; - TCVQ_CB_SUB2_fx = SN_TCVQ_CB_SUB2_fx; - TCVQ_CB_SUB3_fx = SN_TCVQ_CB_SUB3_fx; - IntraCoeff_fx = SN_IntraCoeff_fx; - } - ELSE /* Memory Module */ - { - TCVQ_CB_SUB1_fx = AR_TCVQ_CB_SUB1_fx; - TCVQ_CB_SUB2_fx = AR_TCVQ_CB_SUB2_fx; - TCVQ_CB_SUB3_fx = AR_TCVQ_CB_SUB3_fx; - IntraCoeff_fx = AR_IntraCoeff_fx; - } - - /* Transform Scalar to Vector */ - FOR (i = 0; i < N_STAGE_VQ; i++) - { - FOR(j = 0; j < N_DIM; j++) - { - X_fx[i][j] = x_fx[(N_DIM*i) + j]; - move16(); - W_fx[i][j] = weight_fx[(N_DIM*i) + j]; - move16(); - } - } - - /* Initialzie */ - FOR (i=0; i= 0; stage--) - { - prev_state = preState[stage][prev_state]; - move16(); - } - iniBlock[state] = prev_state; - move16(); - } - - /* stage #5 - #8 */ - FOR (state = 0; state < NUM_STATE; state++) - { - inis = iniBlock[state]; - move16(); - ptr_fins = shr(inis, 2); - minDist_fx = L_add(MAX_32, 0); - - FOR (i = 0; i < 4; i++) - { - fins = add(shl(ptr_fins, 2), i); - prev_state = state; - move16(); - fDist_fx = BcTcvq_FixSearch_fx(X_fx, TCVQ_CB_SUB3_fx, fCodeword, quant_fx, FixBranch_tbl, N_STAGE_VQ-4, inis, i, &prev_state, W_fx, IntraCoeff_fx); - - FOR (stage = N_STAGE_VQ-3; stage < N_STAGE_VQ; stage++) - { - fDist_fx = L_add(fDist_fx, BcTcvq_FixSearch_fx(X_fx, TCVQ_CB_SUB3_fx, fCodeword, quant_fx, FixBranch_tbl, stage, inis, i, &prev_state, W_fx, IntraCoeff_fx)); - } - IF (L_sub(fDist_fx, minDist_fx) < 0) - { - minDist_fx = L_add(fDist_fx, 0); - blockDist_fx[state] = minDist_fx; - move32(); - - fState[state] = fins; - move16(); - - blockCodeword[state][0] = fCodeword[i][0]; - move16(); - blockCodeword[state][1] = fCodeword[i][1]; - move16(); - blockCodeword[state][2] = fCodeword[i][2]; - move16(); - blockCodeword[state][3] = fCodeword[i][3]; - move16(); - } - } - } - - /* Select optimal path */ - fBlock = optimalPath_fx(acumDist_fx, blockDist_fx, blockCodeword, bestCodeword, codeWord, bestState, preState); - - /* Select Quantized Value */ - quantEnc_fx(y_fx, bestCodeword, TCVQ_CB_SUB1_fx, TCVQ_CB_SUB2_fx, TCVQ_CB_SUB3_fx, IntraCoeff_fx); - - /* Buid Code for Decoder */ - buildCode_fx(ind, fState[fBlock], bestCodeword, bestState); - - return; -} - -static Word16 SVQ_2d_fx( - Word16 *x_fx, - Word16 *y_fx, - const Word16 *W_fx, - const Word16 CB_fx[][8], - Word16 Size -) -{ - Word16 i, j; - Word16 index = 0; - Word32 distortion_fx; - Word32 temp_fx; - Word16 temp16_fx; - - temp_fx = L_add(MAX_32, 0); - - FOR (i = 0; i < Size; i++) - { - distortion_fx = L_deposit_l(0); - FOR (j = 0; j < 8; j++) - { - temp16_fx = sub(x_fx[j], CB_fx[i][j]); - distortion_fx = L_add(distortion_fx, - L_shr(Mult_32_16(L_mult(temp16_fx, temp16_fx), W_fx[j]), 1)); - } - - IF (L_sub(distortion_fx, temp_fx) < 0) - { - temp_fx = L_add(distortion_fx, 0); - index = i; - move16(); - } - } - - FOR (i = 0; i < M/2; i++) - { - y_fx[i] = CB_fx[index][i]; - move16(); - } - - return index; -} - - -Word32 qlsf_ARSN_tcvq_Enc_16k_fx ( - const Word16 *x_fx, /* i : Vector to be encoded x2.65 */ - Word16 *y_fx, /* o : Quantized LSF vector x2.65 */ - Word16 *indice, /* o : Indices */ - const Word16 *w_fx, /* i : LSF Weights Q8 */ - const Word16 nBits, /* i : number of bits */ - Word16 safety_net /* i : safety_net flag */ -) -{ - Word16 i; - Word16 x_q_fx[M]; - Word16 yy_fx[M]; - Word16 error_svq_fx[M], error_svq_q_fx[M]; - Word16 cl, cs; - Word32 temp_l; - IF (sub(safety_net, 1) == 0) - { - indice[0] = 1; - move16(); - BcTcvq_fx(1, /*x, x_q, w, */x_fx, x_q_fx, w_fx, &indice[1]); - - IF (sub(nBits, 30) > 0) - { - /* SVQ */ - FOR (i = 0; i < M; i++) - { - error_svq_fx[i] = mult_r(sub(x_fx[i], x_q_fx[i]), scale_inv_ARSN_fx[i]); - move16(); - } - - /* 5bits 1st Split VQ for Residual*/ - indice[10] = SVQ_2d_fx(error_svq_fx, error_svq_q_fx, w_fx, AR_SVQ_CB1_fx, 32); - /* 4bits 2nd Split VQ for Residual*/ - indice[11] = SVQ_2d_fx(&error_svq_fx[8], &error_svq_q_fx[8], &w_fx[8], AR_SVQ_CB2_fx, 16 ); - - FOR (i = 0; i < M; i++) - { - x_q_fx[i] = add(x_q_fx[i], extract_h(L_shl(L_mult0(error_svq_q_fx[i], scale_ARSN_fx[i]), 2))); - move16(); - } - } - } - ELSE - { - indice[0] = 0; - move16(); - BcTcvq_fx(0, /*x, x_q, w, */x_fx, x_q_fx, w_fx, &indice[1]); - - IF (sub(nBits, 30) > 0) - { - /* SVQ */ - FOR (i = 0; i < M; i++) - { - error_svq_fx[i] = sub(x_fx[i], x_q_fx[i]); - move16(); - } - - /* 5bits 1st Split VQ for Residual*/ - indice[10] = SVQ_2d_fx(error_svq_fx, error_svq_q_fx, w_fx, AR_SVQ_CB1_fx, 32); - /* 4bits 2nd Split VQ for Residual*/ - indice[11] = SVQ_2d_fx(&error_svq_fx[8], &error_svq_q_fx[8], &w_fx[8], AR_SVQ_CB2_fx, 16 ); - - FOR (i = 0; i < M; i++) - { - x_q_fx[i] = add(x_q_fx[i], error_svq_q_fx[i]); - move16(); - } - } - } - - cl = 0; - move16(); - FOR (i = 0; i < M; i ++) - { - yy_fx[i] = sub(x_fx[i], x_q_fx[i]); - move16(); - cl = s_max(cl, abs_s(yy_fx[i])); - } - cs = norm_s(cl); - temp_l = 0; - move16(); - - FOR (i = 0; i < M; i ++) - { - yy_fx[i] = shl(yy_fx[i], cs); - move16(); - temp_l = L_mac(temp_l, mult(yy_fx[i], shl(w_fx[i],2) ), yy_fx[i]); - } - cs = shl(cs, 1); - temp_l = L_shr(temp_l, cs); - temp_l = Mult_32_16(temp_l, LSF_1_OVER_256SQ); /* Q-4 */ - - /* Recover the quantized LSF */ - Copy(x_q_fx, y_fx, M); - - return temp_l; -} - -static void FFT_Mid_Interpol_16k_fx( - Word32 Bin_Ener_old[], /* i/o: Old 2nd FFT Bin energy (128) */ - Word32 Bin_Ener[], /* i : Current 2nd FFT Bin energy (128) */ - Word32 Bin_Ener_mid[] /* o : LP weighting filter (numerator) */ -) -{ - Word16 i; - - FOR( i=0; i 0 && sub(j, M) < 0 && sub(qlsf[j], add(qlsf[j-1], LSF_GAP_MID_FX)) < 0) - { - qlsf[j] = add(qlsf[j-1], LSF_GAP_MID_FX); - move16(); - } - - tmp = sub(lsf[j],qlsf[j]); - /* err += wghts[j] * ftemp * ftemp; */ - /* tmp is usually very small, we can have some extra precision with very rare saturation */ - tmp = shl(tmp, 4); - tmp = mult_r(tmp, tmp); - err = L_mac(err, tmp, shl(wghts[j],2) ); - } - /* err = L_shl(err,Wscale); */ - err = Mult_32_16(err,LSF_1_OVER_256SQ); - /* err = Mult_32_16(err,Wmult); */ - - IF ( L_sub(err,err_min) < 0 ) - { - err_min = L_add(err, 0); - idx = k; - move16(); - } - k1+=M; - move16(); - } - - /* calculate the quantized LSF vector */ - FOR ( j = 0; j < M; j++ ) - { - /* qlsf[j] = (1.0f - ratio[idx*M+j]) * qlsf0[j] + ratio[idx*M+j] * qlsf1[j]; */ - L_tmp = L_mult(sub(0x2000, ratio[idx*M+j]), qlsf0[j]); - L_tmp = L_mac(L_tmp,ratio[idx*M+j],qlsf1[j]); - qlsf[j] = round_fx(L_shl(L_tmp,2)); - - test(); - test(); - IF ( j > 0 && sub(j, M) < 0 && sub(qlsf[j], add(qlsf[j-1], LSF_GAP_MID_FX)) < 0 ) - { - qlsf[j] = add(qlsf[j-1], LSF_GAP_MID_FX); - move16(); - } - } - - reorder_lsf_fx( qlsf, LSF_GAP_MID_FX, M, int_fs ); - - /* convert LSFs back to LSPs */ - lsf2lsp_fx( qlsf, lsp, M, int_fs); - push_indice_fx( st_fx, IND_MID_FRAME_LSF_INDEX, idx, nb_bits ); - - return; -} - diff --git a/src/libs/libevs/lib_enc/lsf_msvq_ma_enc.cpp b/src/libs/libevs/lib_enc/lsf_msvq_ma_enc.cpp old mode 100755 new mode 100644 index c6dfdcdd..f2a7189b --- a/src/libs/libevs/lib_enc/lsf_msvq_ma_enc.cpp +++ b/src/libs/libevs/lib_enc/lsf_msvq_ma_enc.cpp @@ -1,657 +1,489 @@ /*==================================================================================== - EVS Codec 3GPP TS26.442 Apr 03, 2018. Version 12.11.0 / 13.6.0 / 14.2.0 + EVS Codec 3GPP TS26.443 Nov 13, 2018. Version 12.11.0 / 13.7.0 / 14.3.0 / 15.1.0 ====================================================================================*/ +#include #include #include -#include "cnst_fx.h" -#include "rom_com_fx.h" -#include "prot_fx.h" -#include "stl.h" -#include "basop_util.h" -#include "rom_enc_fx.h" +#include "options.h" +#include "cnst.h" +#include "prot.h" +#include "rom_com.h" +#include "rom_enc.h" +#include "basop_proto_func.h" -#define MAXINT32 2147483647 -#define swap(x,y,type) {type u__p; u__p=x; x=y; y=u__p;} - - - -#define depack_4_values(cbp, val0, val1, val2, val3) \ - val0 = shr((cbp)[0], 4); \ - val1 = shr((cbp)[1], 4); \ - val2 = shr((cbp)[2], 4); \ - val3 = add(add(shr(lshl((cbp)[2],12),4),lshr(lshl((cbp)[1],12),8)),s_and((cbp)[0],0xF)); - -static Word32 depack_mul_values(Word16 *Tmp, const Word16 *w, const Word16 *cbp, const Word16 N) -{ - Word16 i, val0, val1, val2, val3; - Word32 en; - - en = L_add(0,0); - FOR (i = 0; i < N; i+=4) - { - depack_4_values(cbp+i_mult(shr(i,2),3), val0, val1, val2, val3) - Tmp[i+0] = mult_r(shl(w[i+0],2),val0); - move16(); - en = L_mac(en, val0, Tmp[i+0]); - Tmp[i+1] = mult_r(shl(w[i+1],2),val1); - move16(); - en = L_mac(en, val1, Tmp[i+1]); - Tmp[i+2] = mult_r(shl(w[i+2],2),val2); - move16(); - en = L_mac(en, val2, Tmp[i+2]); - Tmp[i+3] = mult_r(shl(w[i+3],2),val3); - move16(); - en = L_mac(en, val3, Tmp[i+3]); - } - - return en; -} - -static void depack_sub_values(Word16 *pTmp, const Word16 *p1, const Word16 *cbp, const Word16 N) -{ - Word16 j, val0, val1, val2, val3; - - FOR (j=0; j 0) - { - p_max = 1; - move16(); - } - if (L_sub(dist[2], dist[p_max]) > 0) - { - p_max = 2; - move16(); - } - if (L_sub(dist[3], dist[p_max]) > 0) - { - p_max = 3; - move16(); - } - if (L_sub(dist[4], dist[p_max]) > 0) - { - p_max = 4; - move16(); - } - if (L_sub(dist[5], dist[p_max]) > 0) - { - p_max = 5; - move16(); - } - if (L_sub(dist[6], dist[p_max]) > 0) - { - p_max = 6; - move16(); - } - if (L_sub(dist[7], dist[p_max]) > 0) - { - p_max = 7; - move16(); - } - BASOP_SATURATE_WARNING_ON - return p_max; -} - -/* Unroll of inner search loop for maxC == 8 */ -static Word16 msvq_enc_find_p_max_6(Word32 dist[]) -{ - Word16 p_max; - - p_max = 0; - move16(); - - BASOP_SATURATE_WARNING_OFF - if (L_sub(dist[1], dist[p_max]) > 0) - { - p_max = 1; - move16(); - } - if (L_sub(dist[2], dist[p_max]) > 0) - { - p_max = 2; - move16(); - } - if (L_sub(dist[3], dist[p_max]) > 0) - { - p_max = 3; - move16(); - } - if (L_sub(dist[4], dist[p_max]) > 0) - { - p_max = 4; - move16(); - } - if (L_sub(dist[5], dist[p_max]) > 0) - { - p_max = 5; - move16(); - } - BASOP_SATURATE_WARNING_ON - return p_max; -} +#define kMaxC 8 +/*--------------------------------------------------------------------------* + * msvq_enc() + * + * MSVQ encoder + *--------------------------------------------------------------------------*/ void msvq_enc ( - const Word16 *const*cb,/* i : Codebook (indexed cb[*stages][levels][p]) (0Q15) */ - const Word16 dims[], /* i : Dimension of each codebook stage (NULL: full dim.) */ - const Word16 offs[], /* i : Starting dimension of each codebook stage (NULL: 0) */ - const Word16 u[], /* i : Vector to be encoded (prediction and mean removed)(3Q12) */ - const Word16 *levels, /* i : Number of levels in each stage */ - const Word16 maxC, /* i : Tree search size (number of candidates kept from */ - /* one stage to the next == M-best) */ - const Word16 stages, /* i : Number of stages */ - const Word16 w[], /* i : Weights */ - const Word16 N, /* i : Vector dimension */ - const Word16 maxN, /* i : Codebook dimension */ - Word16 Idx[] /* o : Indices */ + const float *const *cb, /* i : Codebook (indexed cb[*stages][levels][p]) */ + const int dims[], /* i : Dimension of each codebook stage (NULL: full dim.) */ + const int offs[], /* i : Starting dimension of each codebook stage (NULL: 0) */ + float u[], /* i : Vector to be encoded (prediction and mean removed) */ + const int *levels, /* i : Number of levels in each stage */ + int maxC, /* i : Tree search size (number of candidates kept from */ + /* one stage to the next == M-best) */ + int stages, /* i : Number of stages */ + float w[], /* i : Weights */ + int N, /* i : Vector dimension */ + int maxN, /* i : Codebook dimension */ + int Idx[] /* o : Indices */ ) { - Word16 j; - const Word16 *cbp; - Word16 p2i; - Word16 resid_buf[2*LSFMBEST_MAX*M_MAX], *resid[2]; - Word16 *pTmp,*p1; - Word16 *indices[2], m, s, c, c2, p_max, i, Tmp[M_MAX]; - Word16 idx_buf[2*LSFMBEST_MAX*MAX_VQ_STAGES_USED], parents[LSFMBEST_MAX]; - Word32 dist_buf[2*LSFMBEST_MAX], *dist[2], t1, tmp, en, ss2; - Word16 (*func_ptr)(Word32 *); - Word16 N34; - Word16 n, maxn, start; - - - + float *resid[2], *dist[2]; + float en, tmp, *pTmp,*p1; + const float *cb_stage, *cbp, *p2; + int *indices[2], j, m, s,c, c2, p_max, i; + float resid_buf[2*LSFMBEST_MAX*M_MAX], dist_buf[2*LSFMBEST_MAX], Tmp[M_MAX]; + int idx_buf[2*LSFMBEST_MAX*MAX_VQ_STAGES_USED], parents[LSFMBEST_MAX]; + int n, maxn, start; /*----------------------------------------------------------------* * Allocate memory for previous (parent) and current nodes. * Parent node is indexed [0], current node is indexed [1]. *----------------------------------------------------------------*/ + indices[0] = idx_buf; - indices[1] = idx_buf + maxC*stages; /*move16();*/ - /*vr_iset(0, idx_buf, 2*stages*maxC);*/ - set16_fx(idx_buf, 0, (Word16)(2*stages*maxC)); + indices[1] = idx_buf + maxC*stages; + set_i( idx_buf, 0, 2*stages*maxC ); resid[0] = resid_buf; - resid[1] = resid_buf + maxC*N; /*move16();*/ + pTmp = resid_buf + maxC*N; + resid[1] = pTmp; dist[0] = dist_buf; - dist[1] = dist_buf + maxC; /*move16();*/ + dist[1] = dist_buf + maxC; + set_i( parents, 0, maxC); - /*vr_iset(0, parents, maxC);*/ - set16_fx(parents, 0, maxC); - - - func_ptr = msvq_enc_find_p_max_6; - move16(); - if (sub(maxC,8) == 0) + /* Set up initial distance vector */ + for(tmp=0.0, j=0; j> 16 => Qwnorm-15/16 * Q0/16 << 1 => Qwnorm-14/32 * 6.5536 */ - ss2 = L_mult(mult(u[0], shl( w[0], 2 )), u[0]); - move16(); - FOR (j=1; j dist[1][p_max]) + { + p_max = c2; + } + } + } /* if (tmp <= dist[1][p_max]) */ + } /* for (j=0; j dist[1][p_max]) + { + p_max = c2; + } + } + } /* if (tmp <= dist[1][p_max]) */ + } /* for(c=0; c 0 && sub(j, M) < 0 && sub(qlsf[j], add(qlsf[j-1], LSF_GAP_MID_FX)) < 0) + pred[j] = (1.0f - ratio[k*N+j]) * qlsf0[j] + ratio[k*N+j] * qlsf1[j]; + + if ( j > 0 && j < N && pred[j] < pred[j-1] + LSF_GAP_MID ) { - qlsf[j] = add(qlsf[j-1], LSF_GAP_MID_FX); + pred[j] = pred[j-1] + LSF_GAP_MID; } - tmp = sub(lsf[j],qlsf[j]); - /* err += wghts[j] * ftemp * ftemp; */ - /* tmp is usually very small, we can have some extra precision with very rare saturation */ - tmp = shl(tmp, 4); - tmp = mult_r(tmp, tmp); - err = L_mac(err, tmp, wghts[j]); + tmp = lsf[j] - pred[j]; + err += wghts[j] * tmp * tmp; } - err = L_shl( err, 2 ); - /* err = L_shl(err,Wscale); */ - err = Mult_32_16(err,LSF_1_OVER_256SQ); - /* err = Mult_32_16(err,Wmult); */ - - IF ( L_sub(err,err_min) < 0 ) + if ( err < err_min ) { - err_min = L_add(err, 0); + err_min = err; *idx = k; - move16(); } - k1+=M; - move16(); } return; } -/* Returns: number of indices */ -Word16 Q_lsf_tcxlpc( - /* const */ Word16 lsf[], /* (I) original lsf */ - Word16 lsf_q[], /* (O) quantized lsf */ - Word16 lsp_q_ind[], /* (O) quantized lsp (w/o MA prediction) */ - Word16 indices[], /* (O) VQ indices */ - Word16 lpcorder, /* (I) LPC order */ - Word16 narrowband, /* (I) narrowband flag */ - Word16 cdk, /* (I) codebook selector */ - Word16 mem_MA[] /* (I) MA memory */ - , Word16 coder_type - , Word32 * Bin_Ener - ,const Word16 Q_ener +/*--------------------------------------------------------------------------* + * Q_lsf_tcxlpc() + * + * + *--------------------------------------------------------------------------*/ + +int Q_lsf_tcxlpc( /* o : number of indices */ + /* const */ float lsf[], /* (I) original lsf */ + float lsf_q[], /* (O) quantized lsf */ + Word16 lsp_q_ind[], /* (O) quantized lsp (w/o MA prediction) */ + int indices[], /* (O) VQ indices */ + int narrowband, /* (I) narrowband flag */ + int cdk, /* (I) codebook selector */ + float mem_MA[], /* (I) MA memory */ + int coder_type, /* (I) acelp extended mode */ + float *Bin_Ener /* (I) Spectrum energy */ ) { - Word16 weights[17]; - Word16 pred[M16k]; - Word16 i; - Word16 NumIndices; + float weights[M]; + float pred[M16k]; + int i; + int NumIndices; + const float *means; Word16 lsf_q_ind[M16k]; - const Word16 *means; - Word16 lsf_rem[M]; + float lsf_rem[M]; + float lsf_rem_q[M]; Word16 lsf_rem_q_ind[M]; - Unified_weighting_fx( Bin_Ener, Q_ener, lsf, weights, narrowband, sub(coder_type,UNVOICED)==0, 12800, M ); + Unified_weighting( &Bin_Ener[L_FFT/2], lsf, weights, narrowband, coder_type==UNVOICED, 12800, M ); - move16(); NumIndices = 0; /* Put disabled flag */ - indices[NumIndices] = 0; - move16(); - NumIndices = add(NumIndices, 1); + indices[NumIndices++] = 0; /* Inter-frame prediction */ - - means = lsf_means[narrowband]; /* 14Q1 * 1.28 */ - - FOR (i=0; i +#include "prot.h" -#include "basop_util.h" -#include "stl.h" -#include "vad_basop.h" -#include "prot_fx.h" -void ltd_stable(T_CldfbVadState *st, /*(io) vad state*/ - Word16 *ltd_stable_rate, /*(o) time-domain stable rate*/ - Word32 frame_energy, /*(i) current frame energy*/ - Word16 frameloop, /*(i) amount of frames*/ - Word16 Q_frames_power /*(i) the Scaling of frames_power*/ - ) +/*-------------------------------------------------------------------* + * ltd_stable() + * + * + *-------------------------------------------------------------------*/ + +void ltd_stable( + float frames_power[], /* i/o: energy of several frames */ + float ltd_stable_rate[], /* o : time-domain stable rate */ + float frame_energy, /* i : current frame energy */ + int frameloop /* i : number of frames */ +) { + int i; + float tmp; + float mid_frame_amp[28]; + float seg_amp; + float dif,apow; - Word32 i; - Word32 zerop001,maxVal; - Word32 mid_frame_amp_mul,tmp_mul; - Word32 *frames_power_32; - Word32 frame_energy_Sqr32; - Word32 seg_amp32; - Word32 mid_frame_ampadd32[20]; - Word16 tmp16[20]; - Word32 mid_frame_amp32[20]; - Word32 dif32, apow32; - Word32 tmp32[20]; + frames_power[0] = (float)(sqrt(frame_energy)+0.001); - Word16 Q_frames_power_last_32; - Word16 Q_dif,Q_apow; - Word16 frame_energy_Sqr; - Word16 Q_frames_power32; - Word16 leadingzero_tmp32; - Word16 leadingzero_midamp; - Word16 Qsum_dif32,Qsum_apow32; - Word16 ltd_stable_rate_Qtmp; - Word16 scale1; - Word32 seg_amp32tmp; - Word16 tmp; - - zerop001 = L_add(0, 0); - Q_dif = 0; - move16(); - Q_apow = 0; - move16(); - frames_power_32 = st->frames_power_32; - Q_frames_power_last_32 = st->Q_frames_power_32; - move16(); - leadingzero_midamp = 31; - move16(); - leadingzero_tmp32 = 31; - move16(); - Q_frames_power32 = Q_frames_power; - move16(); - - frame_energy_Sqr = FixSqrt(frame_energy, &Q_frames_power32); - frame_energy_Sqr32 = L_deposit_l(frame_energy_Sqr); - frame_energy_Sqr32 = L_shl(frame_energy_Sqr32,16); - Q_frames_power32 = add(Q_frames_power32, 16); - - /* +0.1 */ - IF (sub(Q_frames_power32, 40) >= 0) + if(frameloop<3) { - zerop001 = L_shr(CNT0P001, 1); - frame_energy_Sqr32 = L_shr(frame_energy_Sqr32,sub(Q_frames_power32, 39)); - Q_frames_power32 = 39; - move16(); - } - ELSE - { - Q_frames_power32 = sub(Q_frames_power32, 1); - frame_energy_Sqr32 = L_shr(frame_energy_Sqr32,1); - zerop001 = L_shr(CNT0P001, sub(40, Q_frames_power32)); - } - frames_power_32[0] = L_add(frame_energy_Sqr32, zerop001); - move32(); - - IF(sub(frameloop, 3) < 0) - { - FOR(i=1; i<40; i++) + for(i=1; i0) - { - scale1 = sub(Q_frames_power_last_32, Q_frames_power32); - scale1 = sub(scale1, leadingzero); - FOR(i=1; i<40; i++) - { - frames_power_32[i] = L_shr(frames_power_32[i],scale1); - move32(); - } - } - ELSE - { - scale1 = sub(Q_frames_power32, Q_frames_power_last_32); - frames_power_32[0] = L_shr(frames_power_32[0],scale1); - move32(); - Q_frames_power32 = Q_frames_power_last_32; - move16(); - FOR(i=1; i<40; i++) - { - frames_power_32[i] = L_shl(frames_power_32[i], leadingzero); - move32(); - } + frames_power[i] = frames_power[0]; } } - FOR(i=0; i<20; i++) + for(i=0; i<20; i++) { - mid_frame_ampadd32[i] = L_add(L_shr(frames_power_32[2*i], 1), L_shr(frames_power_32[2*i+1], 1)); - move32(); + mid_frame_amp[i] = frames_power[2*i] + frames_power[2*i+1]; + } + seg_amp = 0; + for(i=0; i<20; i++) + { + seg_amp += mid_frame_amp[i]; + } + seg_amp = seg_amp/20; + dif = 0; + apow = 0; + for(i=0; i<20; i++) + { + tmp = mid_frame_amp[i] - seg_amp; + dif += tmp*tmp; + apow += mid_frame_amp[i]*mid_frame_amp[i]; + } + tmp = dif/(apow+0.0001f); + ltd_stable_rate[0] = dif/(apow+FLT_MIN); + + + seg_amp = 0; + for(i=0; i<14; i++) + { + seg_amp += mid_frame_amp[i]; + } + seg_amp = seg_amp/14; + dif = 0; + apow = 0; + for(i=0; i<14; i++) + { + tmp = mid_frame_amp[i] - seg_amp; + dif += tmp*tmp; + apow += mid_frame_amp[i]*mid_frame_amp[i]; + } + ltd_stable_rate[1] = dif/(apow+0.0001f); + + seg_amp = 0; + for(i=0; i<8; i++) + { + seg_amp += mid_frame_amp[i]; + } + seg_amp = seg_amp/8; + dif = 0; + apow = 0; + for(i=0; i<8; i++) + { + tmp = mid_frame_amp[i] - seg_amp; + dif += tmp*tmp; + apow += mid_frame_amp[i]*mid_frame_amp[i]; + } + ltd_stable_rate[2] = (float)(dif/(apow+0.0001f)); + ltd_stable_rate[3] = 0.90f*ltd_stable_rate[3] + 0.1f*ltd_stable_rate[2]; + + for(i=POWER_NUM-1; i>0; i--) + { + frames_power[i] = frames_power[i-1]; } - maxVal = L_add(0, 0); - FOR(i=0; i<20; i++) - { - maxVal = L_max(maxVal,mid_frame_ampadd32[i]); - } - leadingzero_midamp = 31; - move16(); - if(maxVal) - leadingzero_midamp = norm_l(maxVal); - - FOR(i=0; i<20; i++) - { - mid_frame_amp32[i] = L_shl(mid_frame_ampadd32[i], leadingzero_midamp); - move32(); - } - - seg_amp32 = L_add(0, 0); - FOR(i=0; i<20; i++) - { - seg_amp32 = L_add(seg_amp32, L_shr(mid_frame_amp32[i], 5)); - } - seg_amp32 = MUL_F(seg_amp32, 0x0666); - - dif32 = L_add(0, 0); - apow32 = L_add(0, 0); - - seg_amp32tmp = L_shl(seg_amp32, 5); - FOR(i=0; i<20; i++) - { - tmp32[i] = L_sub(mid_frame_amp32[i],seg_amp32tmp); - move32(); - } - - maxVal = L_add(0, 0); - FOR(i=0; i<20; i++) - { - maxVal = L_max(maxVal,L_abs(tmp32[i])); - } - leadingzero_tmp32 = 31; - move16(); - if(maxVal) - leadingzero_tmp32 = norm_l(maxVal); - - FOR(i=0; i<20; i++) - { - tmp16[i] = extract_h(L_shl(tmp32[i], leadingzero_tmp32)); - } - - FOR(i=0; i<20; i++) - { - tmp_mul = L_mult(tmp16[i],tmp16[i]); - tmp_mul = L_shr(tmp_mul,5); - dif32 = L_add(dif32,tmp_mul); - - tmp = extract_h(mid_frame_amp32[i]); - mid_frame_amp_mul = L_mult(tmp,tmp); - mid_frame_amp_mul = L_shr(mid_frame_amp_mul,5); - apow32 = L_add(apow32,mid_frame_amp_mul); - } - - - IF (dif32==0) - { - ltd_stable_rate[0] = 0; - move16(); - } - ELSE - { - Q_dif = sub(norm_l(dif32), 1); - Q_apow = norm_l(apow32); - dif32 = L_shl(dif32,Q_dif); - apow32 = L_shl(apow32,Q_apow); - ltd_stable_rate[0] = div_l(dif32,extract_h(apow32)); - move16(); - } - - ltd_stable_rate_Qtmp = sub(Q_dif, Q_apow); - ltd_stable_rate_Qtmp = add(ltd_stable_rate_Qtmp, leadingzero_tmp32); - ltd_stable_rate_Qtmp = add(ltd_stable_rate_Qtmp, leadingzero_tmp32); - ltd_stable_rate_Qtmp = add(ltd_stable_rate_Qtmp, 15); - ltd_stable_rate_Qtmp = sub(ltd_stable_rate_Qtmp, ITD_STABLE_RATE_Q); - - ltd_stable_rate_Qtmp = limitScale16(ltd_stable_rate_Qtmp); - ltd_stable_rate[0] = shr(ltd_stable_rate[0],ltd_stable_rate_Qtmp); - move16(); - - maxVal = L_add(0, 0); - FOR(i=0; i<14; i++) - { - maxVal = L_max(maxVal, L_abs(mid_frame_ampadd32[i])); - } - leadingzero_midamp = 31; - move16(); - if(maxVal) - leadingzero_midamp = norm_l(maxVal); - - FOR(i=0; i<14; i++) - { - mid_frame_amp32[i] = L_shl(mid_frame_ampadd32[i],leadingzero_midamp); - move32(); - } - - seg_amp32 = L_add(0, 0); - FOR(i=0; i<14; i++) - { - seg_amp32 = L_add(seg_amp32, L_shr(mid_frame_amp32[i],4)); - } - seg_amp32 = MUL_F(seg_amp32, 0x0924); - - dif32 = L_add(0, 0); - apow32 = L_add(0, 0); - seg_amp32tmp = L_shl(seg_amp32, 4); - FOR(i=0; i<14; i++) - { - tmp32[i] = L_sub(mid_frame_amp32[i], seg_amp32tmp); - move32(); - } - - maxVal = L_add(0, 0); - FOR(i=0; i<14; i++) - { - maxVal = L_max(maxVal,L_abs(tmp32[i])); - } - leadingzero_tmp32 = 31; - move16(); - if(maxVal) - leadingzero_tmp32 = norm_l(maxVal); - - FOR(i=0; i<14; i++) - { - tmp32[i] = L_shl(tmp32[i], leadingzero_tmp32); - move32(); - } - - FOR(i=0; i<14; i++) - { - tmp = extract_h(tmp32[i]); - tmp_mul = L_mult(tmp, tmp); - tmp_mul = L_shr(tmp_mul, 4); - dif32 = L_add(dif32, tmp_mul); - - tmp = extract_h(mid_frame_amp32[i]); - mid_frame_amp_mul = L_mult(tmp,tmp); - mid_frame_amp_mul = L_shr(mid_frame_amp_mul, 4); - apow32 = L_add(apow32, mid_frame_amp_mul); - } - - Qsum_apow32 = add(Q_frames_power32, Q_frames_power32); - Qsum_apow32 = add(Qsum_apow32, leadingzero_midamp); - Qsum_apow32 = add(Qsum_apow32, leadingzero_midamp); - Qsum_apow32 = sub(Qsum_apow32, 37); - - Qsum_dif32 = add(Qsum_apow32, leadingzero_tmp32); - Qsum_dif32 = add(Qsum_dif32, leadingzero_tmp32); - - /* +0.1 */ - IF (sub(Qsum_apow32,44)>=0) - { - zerop001 = L_shr(CNT0P0001, 1); - apow32 = L_shr(apow32,limitScale32(sub(Qsum_apow32,43))); - Qsum_apow32 = 43; - move16(); - } - ELSE - { - Qsum_apow32 = sub(Qsum_apow32, 1); - apow32 = L_shr(apow32, 1); - zerop001 = L_shr(CNT0P0001, limitScale32(sub(44, Qsum_apow32))); - } - apow32 = L_add(apow32, zerop001); - IF (apow32 == 0) - { - apow32 = L_add(0, CNT0P0001); - Qsum_apow32 = 44; - move16(); - } - - IF (dif32 == 0) - { - ltd_stable_rate[1] = 0; - move16(); - } - ELSE - { - Q_dif=sub(norm_l(dif32), 1); - Q_apow=norm_l(apow32); - dif32 = L_shl(dif32,Q_dif); - apow32 = L_shl(apow32,Q_apow); - - ltd_stable_rate[1] = div_l(dif32,extract_h(apow32)); - move16(); - } - - ltd_stable_rate_Qtmp = add(Qsum_dif32, Q_dif); - ltd_stable_rate_Qtmp = sub(ltd_stable_rate_Qtmp, Qsum_apow32); - ltd_stable_rate_Qtmp = sub(ltd_stable_rate_Qtmp, Q_apow); - ltd_stable_rate_Qtmp = add(ltd_stable_rate_Qtmp, 15); - ltd_stable_rate_Qtmp = sub(ltd_stable_rate_Qtmp, ITD_STABLE_RATE_Q); - - ltd_stable_rate_Qtmp = limitScale16(ltd_stable_rate_Qtmp); - - ltd_stable_rate[1] = shr(ltd_stable_rate[1],ltd_stable_rate_Qtmp); - move16(); - - maxVal = L_add(0, 0); - FOR(i=0; i<8; i++) - { - maxVal = L_max(maxVal,L_abs(mid_frame_ampadd32[i])); - } - leadingzero_midamp = 31; - move16(); - if(maxVal) - leadingzero_midamp = norm_l(maxVal); - - FOR(i=0; i<8; i++) - { - mid_frame_amp32[i] = L_shl(mid_frame_ampadd32[i], leadingzero_midamp); - move32(); - } - - seg_amp32 = L_add(0, 0); - FOR(i=0; i<8; i++) - { - seg_amp32 = L_add(seg_amp32, L_shr(mid_frame_amp32[i], 3)); - } - seg_amp32 = MUL_F(seg_amp32, 0x1000); - - dif32 = L_add(0, 0); - apow32 = L_add(0, 0); - seg_amp32tmp = L_shl(seg_amp32, 3); - FOR(i=0; i<8; i++) - { - tmp32[i] = L_sub(mid_frame_amp32[i], seg_amp32tmp); - move32(); - } - - maxVal = L_add(0, 0); - FOR(i=0; i<8; i++) - { - maxVal = L_max(maxVal,L_abs(tmp32[i])); - } - leadingzero_tmp32 = 31; - move16(); - if(maxVal) - leadingzero_tmp32 = norm_l(maxVal); - - FOR(i=0; i<8; i++) - { - tmp32[i] = L_shl(tmp32[i],leadingzero_tmp32); - move32(); - } - - FOR(i=0; i<8; i++) - { - tmp = extract_h(tmp32[i]); - tmp_mul = L_mult(tmp,tmp); - tmp_mul = L_shr(tmp_mul, 3); - dif32 = L_add(dif32, tmp_mul); - - tmp = extract_h(mid_frame_amp32[i]); - mid_frame_amp_mul = L_mult(tmp,tmp); - mid_frame_amp_mul = L_shr(mid_frame_amp_mul,3); - apow32 = L_add(apow32, mid_frame_amp_mul); - } - - Qsum_apow32 = add(Q_frames_power32,Q_frames_power32); - Qsum_apow32 = add(Qsum_apow32,leadingzero_midamp); - Qsum_apow32 = add(Qsum_apow32,leadingzero_midamp); - Qsum_apow32 = sub(Qsum_apow32,36); - - Qsum_dif32 = add(Qsum_apow32,leadingzero_tmp32); - Qsum_dif32 = add(Qsum_dif32,leadingzero_tmp32); - - /* +0.1 */ - IF (sub(Qsum_apow32,44) >= 0) - { - zerop001 = L_shr(CNT0P0001, 1); - apow32 = L_shr(apow32,limitScale32(sub(Qsum_apow32,43))); - Qsum_apow32 = 43; - move16(); - } - ELSE - { - Qsum_apow32 = sub(Qsum_apow32, 1); - apow32 = L_shr(apow32,1); - zerop001 = L_shr(CNT0P0001, limitScale32(sub(44, Qsum_apow32))); - } - apow32 = L_add(apow32, zerop001); - IF (apow32 == 0) - { - apow32 = L_add(0, CNT0P0001); - Qsum_apow32 = 44; - move16(); - } - - IF (dif32 == 0) - { - ltd_stable_rate[2] = 0; - move16(); - } - ELSE - { - Q_dif = sub(norm_l(dif32), 1); - Q_apow = norm_l(apow32); - dif32 = L_shl(dif32, Q_dif); - apow32 = L_shl(apow32, Q_apow); - - ltd_stable_rate[2] = div_l(dif32, extract_h(apow32)); - move16(); - } - - ltd_stable_rate_Qtmp = add(Qsum_dif32, Q_dif); - ltd_stable_rate_Qtmp = sub(ltd_stable_rate_Qtmp, Qsum_apow32); - ltd_stable_rate_Qtmp = sub(ltd_stable_rate_Qtmp, Q_apow); - ltd_stable_rate_Qtmp = add(ltd_stable_rate_Qtmp, 15); - ltd_stable_rate_Qtmp = sub(ltd_stable_rate_Qtmp, ITD_STABLE_RATE_Q); - - ltd_stable_rate_Qtmp = limitScale16(ltd_stable_rate_Qtmp); - - ltd_stable_rate[2] = shr(ltd_stable_rate[2], ltd_stable_rate_Qtmp); - move16(); - ltd_stable_rate[3] = add(mult(ltd_stable_rate[3], 0x7333), mult(ltd_stable_rate[2], 0x0ccc)); - move16(); - - FOR(i=55; i>0; i--) - { - frames_power_32[i] = frames_power_32[i-1]; - move32(); - } - st->Q_frames_power_32 = Q_frames_power32; - move16(); - + return; } diff --git a/src/libs/libevs/lib_enc/mdct_classifier.cpp b/src/libs/libevs/lib_enc/mdct_classifier.cpp new file mode 100644 index 00000000..26652ed9 --- /dev/null +++ b/src/libs/libevs/lib_enc/mdct_classifier.cpp @@ -0,0 +1,246 @@ +/*==================================================================================== + EVS Codec 3GPP TS26.443 Nov 13, 2018. Version 12.11.0 / 13.7.0 / 14.3.0 / 15.1.0 + ====================================================================================*/ + +#include "options.h" +#include "cnst.h" +#include "prot.h" + +/*--------------------------------------------------------------------------* + * mdct_classifier() + * + * MDCT signal classifier for HQ_CORE/TCX_20_CORE + *--------------------------------------------------------------------------*/ + +#define SMOOTH_FILT_COEFF 0.8f +#define THRESH_UP 1.6f +#define THRESH_DOWN 1.1f +#define HQ_LOCAL 3 +#define TCX_LOCAL 1 + +short mdct_classifier( /* o : HQ_CORE/TCX_20_CORE decision */ + const float *Y, /* i : FFT spectrum from fft_rel */ + Encoder_State *st, /* i/o: Encoder state variable */ + short vadflag, + float *cldfbBuf_Ener /* i : CLDFB energies */ +) +{ + short c; + float X[129]; + short k; + float y[2]; + float nf; + float pe; + short np; + float max_cand; + short max_i; + float p_energy; + float n_energy; + short d_acc; + short pos_last; + float clas_sec; + short clas_final; + short i; + float gain1, gain2, gain3, gain11, gain4; + float peak_l, peak_h, avrg_l, avrg_h, peak_H1, avrg_H1, peak_H2, avrg_H2; + short condition1, condition2; + short condition3, condition4; + + for (k = 0; k < 127; k++) + { + X[1 + k] = Y[1 + k] * Y[1 + k] + Y[255 - k] * Y[255 - k]; + } + + for (k = 0; k < 2; k++) + { + y[k] = Y[k << 7] * Y[k << 7]; + } + + for (k = 0; k < 2; k++) + { + X[k << 7] = y[k]; + } + + nf = X[0]; + pe = X[0]; + np = 0; + max_cand = -1.0F; + max_i = 0; + p_energy = 0.0F; + n_energy = 0.0F; + d_acc = 0; + pos_last = -1; + + for (k = 0; k < 128; k++) + { + if (X[k + 1] > nf) + { + nf = 0.9578F * nf + 0.0422F * X[k + 1]; + } + else + { + nf = 0.6472F * nf + 0.3528F * X[k + 1]; + } + + if (X[k + 1] > pe) + { + pe = 0.42237F * pe + 0.57763F * X[k + 1]; + } + else + { + pe = 0.80285F * pe + 0.19715F * X[k + 1]; + } + + if (X[k + 1] > pe * 0.64F) + { + if (X[k + 1] > max_cand) + { + max_cand = X[k + 1]; + max_i = (short)(2 + k); + } + } + else + { + if (max_i > 0) + { + if (np > 0) + { + d_acc = (short)((short)(d_acc + max_i) - pos_last); + } + np++; + pos_last = max_i; + } + + max_cand = -1.0F; + max_i = 0; + } + + p_energy += pe * pe; + n_energy += nf * nf; + } + + if (np > 1) + { + nf = (float)d_acc / ((float)np - 1.0F); + } + else + { + nf = 0.0F; + } + gain1 = 0.0f; + gain2 = 0.0f; + gain3 = 0.0f; + for(i=0; i<8; i++) + { + gain1 += cldfbBuf_Ener[i]/8; + gain2 += cldfbBuf_Ener[8+i]/8; + gain3 += cldfbBuf_Ener[16+i]/8; + } + + gain11 = 8*(gain1 - cldfbBuf_Ener[0]/8)/7; + gain4 = 0.0f; + for(i=0; i<12; i++) + { + gain4 += cldfbBuf_Ener[12+i]/12; + } + + + peak_H1 = cldfbBuf_Ener[25]; + avrg_H1 = cldfbBuf_Ener[25]; + for(i=1; i<5; i++) + { + if(cldfbBuf_Ener[25+i] > peak_H1) + { + peak_H1 = cldfbBuf_Ener[25+i]; + } + avrg_H1 += cldfbBuf_Ener[25+i]; + } + + peak_H2 = cldfbBuf_Ener[20]; + avrg_H2 = cldfbBuf_Ener[20]; + for(i=1; i<5; i++) + { + if(cldfbBuf_Ener[20+i] > peak_H2) + { + peak_H2 = cldfbBuf_Ener[20+i]; + } + avrg_H2 += cldfbBuf_Ener[20+i]; + } + + + peak_l = 0.0f; + avrg_l = EPSILON; + peak_h = 0.0f; + avrg_h = EPSILON; + for(i=0; i<32; i++) + { + avrg_l += X[20+i]; + avrg_h += X[96+i]; + if(X[20+i] > peak_l) + { + peak_l = X[20+i]; + } + if(X[96+i] > peak_h) + { + peak_h = X[96+i]; + } + } + + condition1 = nf > 12.0F; + condition2 = p_energy - n_energy * 147.87276f > 0; + condition3 = gain3 > 1.2f*gain2 || + (gain3 >= 0.8f*gain2 && 5*peak_H1 > 2.0f*avrg_H1) || + (2.6f*peak_l*avrg_h < peak_h *avrg_l || peak_l*avrg_h > 2.6f*peak_h *avrg_l); + condition4 = (gain4 > 0.8f*gain11 && 2.56f*peak_l*avrg_h > peak_h *avrg_l && peak_l*avrg_h < 5.12f*peak_h *avrg_l) || + (gain4 > 0.3f*gain11 && 32*peak_h < 1.5f*avrg_h && 5*peak_H2 < 1.5f*avrg_H2) || + (2.56f*peak_l*avrg_h < peak_h *avrg_l && 32*peak_h > 1.5f*avrg_h) || (peak_l*avrg_h > 2.56f*peak_h *avrg_l && 32*peak_h < 1.5f*avrg_h); + + if ( ( st->total_brate == HQ_32k && ((!condition1 && condition2) || (condition1 && !condition2)|| condition3) ) + || (st->total_brate == HQ_24k40 && condition4)) + { + c = HQ_LOCAL; + } + else + { + c = TCX_LOCAL; + } + + /* Smooth decision from instantaneous decision*/ + clas_sec = (SMOOTH_FILT_COEFF * st->clas_sec_old) + ((1-SMOOTH_FILT_COEFF) * c); + + /* Do thresholding with hysteresis */ + if((st->clas_final_old == HQ_CORE || st->clas_final_old == TCX_20_CORE) + && ((st->last_gain1 > 0.5f*gain1 && st->last_gain1 < 2.0f*gain1) && (st->last_gain2 > 0.5f*gain2 && st->last_gain2 < 2.0f*gain2))) + { + clas_final = st->clas_final_old; + } + else if (clas_sec > st->clas_sec_old && clas_sec > THRESH_UP) /* Going up? */ + { + clas_final = HQ_CORE; + } + else if (clas_sec < THRESH_DOWN)/* Going down */ + { + clas_final = TCX_20_CORE; + } + else + { + clas_final = st->clas_final_old; + } + + /* Prevent the usage of HQ_CORE on noisy-speech or inactive */ + if ( st->mdct_sw_enable==MODE2 && (st->flag_noisy_speech_snr == 1 || vadflag == 0 ) && clas_final == HQ_CORE ) + { + clas_final = TCX_20_CORE; + } + + + /* Memory update */ + st->clas_sec_old = clas_sec; + st->clas_final_old = clas_final; + st->last_gain1 = gain1; + st->last_gain2 = gain2; + + return clas_final; +} + + diff --git a/src/libs/libevs/lib_enc/mdct_classifier_fx.cpp b/src/libs/libevs/lib_enc/mdct_classifier_fx.cpp deleted file mode 100755 index 6838f330..00000000 --- a/src/libs/libevs/lib_enc/mdct_classifier_fx.cpp +++ /dev/null @@ -1,470 +0,0 @@ -/*==================================================================================== - EVS Codec 3GPP TS26.442 Apr 03, 2018. Version 12.11.0 / 13.6.0 / 14.2.0 - ====================================================================================*/ - -#include "options.h" -#include "cnst_fx.h" -#include "prot_fx.h" -#include "stl.h" - -/*--------------------------------------------------------------------------* - * mdct_classifier() - * - * MDCT signal classifier - *--------------------------------------------------------------------------*/ - -#define MDCT_CLASSIFER_SMOOTH_FILT_COEFF 26214 /* 0.8 in Q15 */ -#define MDCT_CLASSIFER_THRESH_UP 13107 /* 1.6 in Q13 */ -#define MDCT_CLASSIFER_THRESH_DOWN 9011 /* 1.1 in Q13 */ -#define MDCT_CLASSIFER_HQ_LOCAL (3 << 13) /* Q13, Define those local to make the filtering operation robust in case classes numbers are changed */ -#define MDCT_CLASSIFER_TCX_LOCAL (1 << 13) /* Q13 */ - - -/*----------------------------------------------------------------------------- - * dft_mag_square_fx() - * - * Square magnitude of fft spectrum - *----------------------------------------------------------------------------*/ -static void dft_mag_square_fx( - const Word16 x[], /* i : Input vector: re[0], re[1], ..., re[n/2], im[n/2 - 1], im[n/2 - 2], ..., im[1] */ - Word32 magSq[], /* o : Magnitude square spectrum */ - const Word16 n /* i : Input vector length */ -) -{ - Word16 i, l; - const Word16 *pRe, *pIm; - Word32 *pMagSq, acc; - - /* Magnitude square at 0. */ - pMagSq = &magSq[0]; - pRe = &x[0]; - *pMagSq++ = L_mult0(*pRe, *pRe); - pRe++; - move32(); - - /* From 1 to (N/2 - 1). */ - l = sub(shr(n, 1), 1); /* N/2 - 1. */ - pIm = &x[n]; - pIm--; - FOR (i = 0; i < l; i++) - { - acc = L_mult0(*pRe, *pRe); - pRe++; - *pMagSq++ = L_mac0(acc, *pIm, *pIm); - pIm--; - move32(); - } - - /* The magnitude square at N/2 */ - *pMagSq = L_mult0(*pRe, *pRe); - move32(); - return; -} - -Word16 mdct_classifier_fx( /* o: MDCT A/B decision */ - const Word16 *Y, /* i: re[0], re[1], ..., re[n/2], im[n/2 - 1], im[n/2 - 2], ..., im[1] */ - Encoder_State_fx *st_fx, /* i/o: Encoder state variable */ - Word16 vadflag - , Word32 *cldfbBuf_Ener - ,Word16 enerBuffer_exp -) -{ - Word16 c; - Word32 magSq[129], *pMagSq, nf, pe; - Word16 k; - Word16 np; - Word32 max_cand; - Word16 max_i; - Word32 p_energy_man, n_energy_man, man; - Word16 p_energy_exp, n_energy_exp, expo; - Word16 d_acc; - Word16 pos_last; - Word16 clas_sec; - Word16 clas_final; - Word16 condition1, condition2; - Word16 factor; - Word32 acc; - UWord16 lsb16; - UWord32 lsb32; - Word32 gain1, gain2, gain3, gain11, gain4; - Word32 peak_l, peak_h, avrg_l, avrg_h, peak_H1, avrg_H1, peak_H2, avrg_H2; - Word16 condition3, condition4; - Word32 gain1_tmp = 0, gain2_tmp = 0; - Word16 exp, exp1, exp2, exp3; - Word32 L_tmp, L_tmp1; - - dft_mag_square_fx(Y, magSq, 256); - - nf = L_add(magSq[0], 0); - pe = L_add(magSq[0], 0); - np = 0; - move16(); - max_cand = L_negate(1); - max_i = 0; - move16(); - p_energy_man = L_deposit_l(0); - n_energy_man = L_deposit_l(0); - p_energy_exp = n_energy_exp = 32; - move16(); - move16(); - d_acc = 0; - move16(); - pos_last = -1; - move16(); - - pMagSq = magSq; - FOR (k = 0; k < 128; k++) - { - /* NB: a*f + b*(1 - f) needs two multiplies - * = (a - b)*f + b saves one multiply */ - IF (L_sub(*(++pMagSq), nf) > 0L) - { - factor = 31385; - move16();/* 0.9578 in Q15 */ - } - ELSE - { - factor = 21207; - move16();/* 0.6472 in Q15 */ - } - acc = L_sub(nf, *pMagSq); - Mpy_32_16_ss(acc, factor, &acc, &lsb16); - nf = L_add(acc, *pMagSq); - IF (L_sub(*pMagSq, pe) > 0L) - { - factor = 13840; - move16();/* 0.42237 in Q15 */ - } - ELSE - { - factor = 26308; - move16();/* 0.80285 in Q15 */ - } - acc = L_sub(pe, *pMagSq); - Mpy_32_16_ss(acc, factor, &acc, &lsb16); - pe = L_add(acc, *pMagSq); - Mpy_32_16_ss(pe, 20972, &acc, &lsb16); /* 0.64 in Q15 */ - IF (L_sub(*pMagSq, acc) > 0L) - { - IF (L_sub(*pMagSq, max_cand) > 0L) - { - max_cand = L_add(*pMagSq, 0); - max_i = add(2, k); - } - } - ELSE - { - IF (max_i > 0) - { - IF (sub(np, 0) > 0) - { - d_acc = sub(add(d_acc, max_i), pos_last); - } - np = add(np, 1); - pos_last = max_i; - move16(); - } - - max_cand = L_negate(1); - max_i = 0; - move16(); - } - - IF (pe != 0) - { - expo = norm_l(pe); - man = L_shl(pe, expo); - Mpy_32_32_ss(man, man, &man, &lsb32); /* pe square */ - expo = shl(expo, 1); /* Multiply by 2 due to squaring. */ - floating_point_add(&p_energy_man, &p_energy_exp, man, expo); - } - IF (nf != 0) - { - expo = norm_l(nf); - man = L_shl(nf, expo); - Mpy_32_32_ss(man, man, &man, &lsb32); /* nf square */ - expo = shl(expo, 1); /* Multiply by 2 due to squaring. */ - floating_point_add(&n_energy_man, &n_energy_exp, man, expo); - } - } - - gain1 = L_deposit_l(0); - gain2 = L_deposit_l(0); - gain3 = L_deposit_l(0); - FOR (k = 0; k < 8; k++) - { - gain1 = L_add(gain1, L_shr(cldfbBuf_Ener[k], 3)); - gain2 = L_add(gain2, L_shr(cldfbBuf_Ener[k + 8], 3)); - gain3 = L_add(gain3, L_shr(cldfbBuf_Ener[k + 16], 3)); - } - - /* gain11 = 8*(gain1 - cldfbBuf_Ener[0]/8)/7; */ - acc = L_shr(cldfbBuf_Ener[0], 3); - acc = L_sub(gain1, acc); - acc = Mult_32_16(acc, 4681); - gain11 = L_shl(acc, 3); - gain4 = L_deposit_l(0); - FOR (k = 0; k < 12; k++) - { - gain4 = L_add(gain4, Mult_32_16(cldfbBuf_Ener[k + 12], 2731)); - } - - - peak_H1 = L_add(cldfbBuf_Ener[25], 0); - Mpy_32_16_ss(cldfbBuf_Ener[25], 6554, &avrg_H1, &lsb16); - FOR (k = 1; k < 5; k++) - { - IF(L_sub(cldfbBuf_Ener[k + 25], peak_H1) > 0) - { - peak_H1 = L_add(cldfbBuf_Ener[k + 25], 0); - } - avrg_H1 = L_add(avrg_H1, Mult_32_16(cldfbBuf_Ener[k + 25], 6554)); - } - - peak_H2 = L_add(cldfbBuf_Ener[20], 0); - Mpy_32_16_ss(cldfbBuf_Ener[20], 6554, &avrg_H2, &lsb16); - FOR (k = 1; k < 5; k++) - { - IF (L_sub(cldfbBuf_Ener[k + 20], peak_H2) > 0) - { - peak_H2 = L_add(cldfbBuf_Ener[k + 20], 0); - } - avrg_H2 = L_add(avrg_H2, Mult_32_16(cldfbBuf_Ener[k + 20], 6554)); - } - - peak_l = L_deposit_l(0); - avrg_l = L_deposit_l(0); - peak_h = L_deposit_l(0); - avrg_h = L_deposit_l(0); - FOR (k = 0; k < 32; k++) - { - avrg_l = L_add(avrg_l, L_shr(magSq[k + 20], 5)); - avrg_h = L_add(avrg_h, L_shr(magSq[k + 96], 5)); - IF (L_sub(magSq[k + 20], peak_l) > 0) - { - peak_l = L_add(magSq[k + 20], 0); - } - IF (L_sub(magSq[k + 96], peak_h) > 0) - { - peak_h = L_add(magSq[k + 96], 0); - } - } - - /* Compute: d_acc - 12*(np -1). */ - acc = L_deposit_l(d_acc); - IF (L_msu(acc, 12/2, sub(np, 1)) > 0) /* 12/2 is to compensate the fractional mode multiply */ - { - condition1 = 1; /* Signifies: d_acc/(np - 1) > 12 */ move16(); - } - ELSE - { - condition1 = 0; /* Signifies: d_acc/(np - 1) <= 12 */ move16(); - /* NB: For np = 0 or 1, it fits this condition. */ - } - - /* Compute: p_energy - 147.87276*n_energy. */ - IF (n_energy_man != 0) - { - Mpy_32_16_ss(n_energy_man, 18928, &acc, &lsb16); /* 147.87276 in Q7 */ - expo = sub(n_energy_exp, 15 - 7); /* Due to 18928 in Q7 */ - acc = L_negate(acc); /* To facilitate the following floating_point_add() to perform subtraction. */ - floating_point_add(&acc, &expo, p_energy_man, p_energy_exp); - } - ELSE - { - acc = L_deposit_l(0); - } - IF (acc > 0) - { - condition2 = 1; /* Signifies: p_energy / n_energy > 147.87276 */ move16(); - } - ELSE - { - condition2 = 0; /* Signifies: p_energy / n_energy <= 147.87276 */ move16(); - } - - condition3 = 0; - move16(); - condition4 = 0; - move16(); - - L_tmp = Mult_32_16(peak_h, 12603); - IF(L_sub(peak_l, L_tmp) > 0) - { - exp = norm_l(peak_l); - } - ELSE - { - exp = norm_l(L_tmp); - } - IF(L_sub(avrg_h, avrg_l) > 0) - { - exp1 = norm_l(avrg_h); - } - ELSE - { - exp1 = norm_l(avrg_l); - } - - L_tmp1 = Mult_32_16(peak_l, 12603); - IF(L_sub(peak_h, L_tmp1) > 0) - { - exp2 = norm_l(peak_h); - } - ELSE - { - exp2 = norm_l(L_tmp1); - } - - test(); - test(); - test(); - test(); - IF (L_sub(Mult_32_16(gain3, 27307), gain2) > 0 || (L_sub(gain3, Mult_32_16(gain2, 26214)) >= 0 && L_sub(peak_H1, L_shl(avrg_H1, 1)) > 0) - || (L_sub(Mult_32_32(L_shl(peak_l, exp), L_shl(avrg_h, exp1)), Mult_32_32(L_shl(L_tmp, exp), L_shl(avrg_l, exp1))) < 0 - || L_sub(Mult_32_32(L_shl(L_tmp1, exp2), L_shl(avrg_h, exp1)), Mult_32_32(L_shl(peak_h, exp2), L_shl(avrg_l, exp1))) > 0)) - { - condition3 = 1; - move16(); - } - - L_tmp = Mult_32_16(peak_h, 12800); - IF(L_sub(peak_l, L_tmp) > 0) - { - exp = norm_l(peak_l); - } - ELSE - { - exp = norm_l(L_tmp); - } - - L_tmp1 = Mult_32_16(peak_l, 6400); - IF(L_sub(peak_h, L_tmp1) > 0) - { - exp2 = norm_l(peak_h); - } - ELSE - { - exp2 = norm_l(L_tmp1); - } - - IF(L_sub(peak_h, L_shl(L_tmp1, 1)) > 0) - { - exp3 = norm_l(peak_h); - } - ELSE - { - exp3 = sub(norm_l(L_tmp1), 1); - } - - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - IF ((L_sub(gain4, Mult_32_16(gain11, 26214)) > 0 && L_sub(Mult_32_32(L_shl(peak_l, exp), L_shl(avrg_h, exp1)), Mult_32_32(L_shl(Mult_32_16(peak_h, 12800), exp), L_shl(avrg_l, exp1))) > 0 - && L_sub(Mult_32_32(L_shl(Mult_32_16(peak_l, 6400), exp2), L_shl(avrg_h, exp1)), Mult_32_32(L_shl(peak_h, exp2), L_shl(avrg_l, exp1))) < 0) - || (L_sub(gain4, Mult_32_16(gain11, 9830)) > 0 && L_sub(Mult_32_16(peak_h, 21845), avrg_h) < 0 && L_sub(Mult_32_16(peak_H2, 21845), avrg_H2) < 0) - || (L_sub(Mult_32_32(L_shl(peak_l, exp), L_shl(avrg_h, exp1)), Mult_32_32(L_shl(Mult_32_16(peak_h, 12800), exp), L_shl(avrg_l, exp1))) < 0 && L_sub(Mult_32_16(peak_h, 21845), avrg_h) > 0) - || (L_sub(Mult_32_32(L_shl(Mult_32_16(peak_l, 12800), exp3), L_shl(avrg_h, exp1)), Mult_32_32(L_shl(peak_h, exp3), L_shl(avrg_l, exp1))) > 0 && L_sub(Mult_32_16(peak_h, 21845), avrg_h) < 0) ) - { - condition4 = 1; - move16(); - } - - test(); - test(); - test(); - test(); - IF ((L_sub(st_fx->total_brate_fx, HQ_32k) == 0 && (s_xor(condition1, condition2) != 0 || condition3)) - || (L_sub(st_fx->total_brate_fx, HQ_24k40) == 0 && condition4)) - { - c = MDCT_CLASSIFER_HQ_LOCAL; /* Q13 */ move16(); - } - ELSE - { - c = MDCT_CLASSIFER_TCX_LOCAL; /* Q13 */ move16(); - } - - /* Smooth decision from instantaneous decision*/ - acc = L_mult(st_fx->clas_sec_old_fx, MDCT_CLASSIFER_SMOOTH_FILT_COEFF); /* st_fx->clas_sec_old_fx in Q13 */ - clas_sec = mac_r(acc, c, 0x7fff - MDCT_CLASSIFER_SMOOTH_FILT_COEFF); /* clas_sec and c are in Q13 */ - /* Do thresholding with hysteresis */ - IF(sub(st_fx->last_enerBuffer_exp, enerBuffer_exp) > 0) - { - gain1_tmp = L_shr(gain1, sub(st_fx->last_enerBuffer_exp, enerBuffer_exp)); - move32(); - gain2_tmp = L_shr(gain2, sub(st_fx->last_enerBuffer_exp, enerBuffer_exp)); - move32(); - } - ELSE - { - st_fx->last_gain1 = L_shr(st_fx->last_gain1, sub(enerBuffer_exp, st_fx->last_enerBuffer_exp)); - move32(); - st_fx->last_gain2 = L_shr(st_fx->last_gain2, sub(enerBuffer_exp, st_fx->last_enerBuffer_exp)); - move32(); - gain1_tmp = gain1; - move32(); - gain2_tmp = gain2; - move32(); - } - - test(); - test(); - test(); - test(); - test(); - test(); - IF ((sub(st_fx->clas_final_old_fx, HQ_CORE) == 0 || sub(st_fx->clas_final_old_fx, TCX_20_CORE) == 0) - && ((L_sub(st_fx->last_gain1, L_shr(gain1_tmp, 1)) > 0 && L_sub(st_fx->last_gain1, L_shl(gain1_tmp, 1)) < 0) - && (L_sub(st_fx->last_gain2, L_shr(gain2_tmp, 1)) > 0 && L_sub(st_fx->last_gain2, L_shl(gain2_tmp, 1)) < 0))) - { - clas_final = st_fx->clas_final_old_fx; - move16(); - } - ELSE IF (sub(clas_sec, st_fx->clas_sec_old_fx) > 0 && sub(clas_sec, MDCT_CLASSIFER_THRESH_UP) > 0) /* Going up? */ - { - clas_final = HQ_CORE; /* Q0 */ move16(); - } - ELSE IF (sub(clas_sec, MDCT_CLASSIFER_THRESH_DOWN) < 0)/* Going down */ - { - clas_final = TCX_20_CORE; - move16(); - } - ELSE - { - clas_final = st_fx->clas_final_old_fx; - move16(); - } - - test(); - test(); - test(); - /* Prevent the usage of MDCTA on noisy-speech or inactive */ - if ( sub(st_fx->mdct_sw_enable, MODE2) == 0 && (sub(st_fx->flag_noisy_speech_snr, 1) == 0 || vadflag == 0 ) && sub(clas_final, HQ_CORE) == 0 ) - { - clas_final = TCX_20_CORE; - move16(); - } - - - /* Memory update */ - st_fx->clas_sec_old_fx = clas_sec; - move16(); /* Q13 */ - st_fx->clas_final_old_fx = clas_final; - move16(); /* Q0 */ - st_fx->last_gain1 = gain1; - move32(); - st_fx->last_gain2 = gain2; - move32(); - st_fx->last_enerBuffer_exp = enerBuffer_exp; - move16(); - - return clas_final; /* Q0 */ -} - - diff --git a/src/libs/libevs/lib_enc/mdct_selector.cpp b/src/libs/libevs/lib_enc/mdct_selector.cpp old mode 100755 new mode 100644 index 8df55718..df5ce8b1 --- a/src/libs/libevs/lib_enc/mdct_selector.cpp +++ b/src/libs/libevs/lib_enc/mdct_selector.cpp @@ -1,355 +1,259 @@ /*==================================================================================== - EVS Codec 3GPP TS26.442 Apr 03, 2018. Version 12.11.0 / 13.6.0 / 14.2.0 + EVS Codec 3GPP TS26.443 Nov 13, 2018. Version 12.11.0 / 13.7.0 / 14.3.0 / 15.1.0 ====================================================================================*/ #include +#include #include "options.h" -#include "stl.h" -#include "cnst_fx.h" -#include "prot_fx.h" +#include "cnst.h" +#include "rom_enc.h" +#include "rom_com.h" +#include "prot.h" #include +/*-----------------------------------------------------------------* + * Local constants + *-----------------------------------------------------------------*/ -# define MDCT_SW_SIG_LINE_THR 840 /* 2.85f*LOG_10 in Q7 */ /* Significant spectral line threshold above Etot (dB) */ -# define MDCT_SW_SIG_PEAK_THR 9216 /* 36.0f in Q8 */ /* Significant peak threshold below Etot (dB) */ -# define MDCT_SW_HI_SPARSE_THR 8192 /* 0.25f in Q15*/ /* Max. ratio of significant spectral lines for the spectrum to be considered sparse */ -# define MDCT_SW_HI_ENER_LO_THR 1920 /* 7.5f in Q8 */ /* Hi band low energy threshold (dB) */ -# define MDCT_SW_SPARSE_THR 6554 /* 0.25f*0.8f in Q15*/ -# define MDCT_SW_1_VOICING_THR 29491 /* 0.9f in Q15*/ /* Voicing threshold */ -# define MDCT_SW_1_VOICING_THR2 23593 /* 0.9f*0.8f in Q15*/ -# define MDCT_SW_1_HI_ENER_LO_THR 3200 /* 12.5f in Q8 */ /* Hi band high energy threshold (dB) */ -# define MDCT_SW_1_SIG_HI_LEVEL_THR 7168 /* 28.0f in Q8 */ /* High signal level threshold above noise floor (dB) */ -# define MDCT_SW_1_SIG_LO_LEVEL_THR 5760 /* 22.5f in Q8 */ /* Low signal level threshold above noise floor (dB) */ -# define MDCT_SW_1_COR_THR 20480 /* 80.0f in Q8 */ /* Threshold on cor_map_sum to indicate strongly tonal signal */ -# define MDCT_SW_1_COR_THR2 16384 /* 80.0f*0.8f in Q8 */ -# define MDCT_SW_1_SPARSENESS_THR 21299 /* 0.65f in Q15*/ /* Threshold on spectrum sparseness */ -# define MDCT_SW_1_SPARSENESS_THR2 17039 /* 0.65f*0.8f in Q15*/ +#define MDCT_SW_SIG_LINE_THR 2.85f /* Significant spectral line threshold above Etot (dB) */ +#define MDCT_SW_SIG_PEAK_THR 36.0f /* Significant peak threshold below Etot (dB) */ +#define MDCT_SW_HI_SPARSE_THR 0.25f /* Max. ratio of significant spectral lines for the spectrum to be considered sparse */ +#define MDCT_SW_HI_ENER_LO_THR 7.5f /* Hi band low energy threshold (dB) */ +#define MDCT_SW_1_VOICING_THR 0.9f /* Voicing threshold */ +#define MDCT_SW_1_HI_ENER_LO_THR 12.5f /* Hi band low energy threshold (dB) */ +#define MDCT_SW_1_SIG_HI_LEVEL_THR 28.0f /* High signal level threshold above noise floor (dB) */ +#define MDCT_SW_1_SIG_LO_LEVEL_THR 22.5f /* Low signal level threshold above noise floor (dB) */ +#define MDCT_SW_1_COR_THR 80.0f /* Threshold on cor_map_sum to indicate strongly tonal signal */ +#define MDCT_SW_1_SPARSENESS_THR 0.65f /* Threshold on spectrum sparseness */ -# define MDCT_SW_2_VOICING_THR 19661 /* 0.6f in Q15*/ /* Voicing threshold */ -# define MDCT_SW_2_VOICING_THR2 15729 /* 0.6f*0.8f in Q15*/ -# define MDCT_SW_2_HI_ENER_LO_THR 2432 /* 9.5f in Q8 */ /* Hi band low energy threshold (dB) */ -# define MDCT_SW_2_SIG_HI_LEVEL_THR 4864 /* 19.0f in Q8 */ /* High signal level threshold above noise floor (dB) */ -# define MDCT_SW_2_SIG_LO_LEVEL_THR 6016 /* 23.5f in Q8 */ /* Low signal level threshold above noise floor (dB) */ -# define MDCT_SW_2_COR_THR 16000 /* 62.5f in Q8 */ /* Threshold on cor_map_sum to indicate strongly tonal signal */ -# define MDCT_SW_2_COR_THR2 12800 /* 62.5f*0.8f in Q8 */ -# define MDCT_SW_2_SPARSENESS_THR 13107 /* 0.4f in Q15*/ /* Threshold on spectrum sparseness */ -# define MDCT_SW_2_SPARSENESS_THR2 10486 /* 0.4f*0.8f in Q15*/ +#define MDCT_SW_2_VOICING_THR 0.6f /* Voicing threshold */ +#define MDCT_SW_2_HI_ENER_LO_THR 9.5f /* Hi band low energy threshold (dB) */ +#define MDCT_SW_2_SIG_HI_LEVEL_THR 19.0f /* High signal level threshold above noise floor (dB) */ +#define MDCT_SW_2_SIG_LO_LEVEL_THR 23.5f /* Low signal level threshold above noise floor (dB) */ +#define MDCT_SW_2_COR_THR 62.5f /* Threshold on cor_map_sum to indicate strongly tonal signal */ +#define MDCT_SW_2_SPARSENESS_THR 0.4f /* Threshold on spectrum sparseness */ -static Word16 get_sparseness( /* Returns sparseness measure (Q15) */ - const Word16 Bin_E[], /* i : per bin energy dB Q7 */ - Word16 n, /* i : number of bins Q0 */ - Word16 thr /* i : peak threshold Q8 */ +#define MDCT_SW_HYST_FAC 0.8f /* Hysteresis tolerance factor */ + +#define LOG_10 2.30258509299f + +/*--------------------------------------------------------------------------* + * get_sparseness() + * + * + *--------------------------------------------------------------------------*/ + +static float get_sparseness( + const float Bin_E[], + short n, + float thr ) { - Word16 num_max, i; + short num_max, i; - thr = add(thr, mult(thr, 4958)); /* Convert to 10*log() domain from 10*log10() domain, and also to Q7 */ + thr *= log(10); /* Convert to 10*log() domain from 10*log10() domain */ - thr = s_max(thr, 384); /* 3.0 in Q7 */ /* Set an absolute minimum for close to silent signals */ + thr = max(thr, 3.0f); /* Set an absolute minimum for close to silent signals */ num_max = 0; - move16(); - - FOR (i=1; i 0) + if (Bin_E[i] > max(max(Bin_E[i-1], Bin_E[i+1]), thr)) { - num_max = add(num_max, 1); + ++num_max; } } - n = shr(sub(n, 2), 1); - return div_s(sub(n, num_max), n); + return 1.0f - num_max / (float)((n-2)/2); } -static Word16 get_mean_ener( /* Returns mean energy in dB (Q8) */ - const Word32 enerBuffer[], /* i : CLDFB buffers */ - Word16 enerBuffer_exp, /* i : exponent of enerBuffer */ - Word16 n /* i : number of bins */ -) -{ - Word32 L_tmp; - Word16 i, shift, frac_nrg, exp_nrg; - - shift = sub(14, norm_s(n)); - if (sub(shl(1, shift), n) < 0) shift = add(shift, 1); - - L_tmp = L_deposit_l(0); - FOR (i=0; imdct_sw_enable, MODE1) == 0 || sub(st->mdct_sw_enable, MODE2) == 0) + if( st->mdct_sw_enable == MODE1 || st->mdct_sw_enable == MODE2 ) { - Word16 hi_ener, frame_voicing, sparseness; - Word16 peak_count; - Word16 prefer_tcx, prefer_hq_core, switching_point, hi_sparse, sparse; - Word16 lob_cldfb, hib_cldfb, lob_fft, hib_fft; - Word16 i, tmp; - Word16 sig_lo_level_thr, sig_hi_level_thr, cor_thr, cor_thr2, voicing_thr, voicing_thr2, sparseness_thr, sparseness_thr2, hi_ener_lo_thr; - Word16 last_core; + float hi_ener, frame_voicing, sparseness; + int peak_count; + short prefer_tcx, prefer_hq_core, switching_point, hi_sparse, sparse; + int lob_cldfb, hib_cldfb, lob_fft, hib_fft; + int i; + float sig_lo_level_thr, sig_hi_level_thr, cor_thr, voicing_thr, sparseness_thr, hi_ener_lo_thr; + int last_core; - sp_floor = shl(sp_floor, 1); /* convert to Q8 */ - - IF (sub(st->bwidth_fx, NB) == 0) + if (st->bwidth == NB) { lob_cldfb = 3200/400; - move16(); hib_cldfb = 4000/400; - move16(); - lob_fft = (L_FFT/2)/2; /* 3.2 KHz */ move16(); - hib_fft = (40*(L_FFT/2))/64; /* 4.0 KHz */ move16(); + lob_fft = (L_FFT/2)/2; /* 3.2 KHz */ + hib_fft = (40*(L_FFT/2))/64; /* 4.0 KHz */ } - ELSE IF (sub(st->bwidth_fx, WB) == 0) + else if (st->bwidth == WB) { lob_cldfb = 4800/400; - move16(); hib_cldfb = 8000/400; - move16(); - lob_fft = 3*L_FFT/2/4; /* 4.8 KHz */ move16(); - hib_fft = L_FFT/2; /* 6.4 KHz (should be 8 KHz) */ move16(); + lob_fft = 3*L_FFT/2/4; /* 4.8 KHz */ + hib_fft = L_FFT/2; /* 6.4 KHz (should be 8 KHz) */ } - ELSE + else { lob_cldfb = 6400/400; - move16(); hib_cldfb = 16000/400; - move16(); - if (sub(st->bwidth_fx, FB) == 0) + if (st->bwidth == FB) { hib_cldfb = 24000/400; - move16(); } - lob_fft = L_FFT/2; /* 6.4 KHz */ move16(); - hib_fft = L_FFT/2; /* 6.4 KHz (should be 8 KHz) */ move16(); + lob_fft = L_FFT/2; /* 6.4 KHz */ + hib_fft = L_FFT/2; /* 6.4 KHz (should be 8 KHz) */ } - /* st->last_core_fx is reset to TCX_20_CORE in init_acelp() => fix it here */ - last_core = st->last_core_fx; - move16(); - test(); - if (sub(st->last_codec_mode, MODE1) == 0 && sub(last_core, TCX_20_CORE) == 0) + /* st->last_core is reset to TCX_20_CORE in init_acelp() => fix it here */ + last_core = st->last_core; + if( st->last_codec_mode == MODE1 && last_core == TCX_20_CORE ) { last_core = HQ_CORE; - move16(); } /* Voicing */ - frame_voicing = add(shr(voicing[0], 1), shr(voicing[1], 1)); + frame_voicing = (voicing[0]+voicing[1])*0.5f; /* Spectral sparseness */ - sparseness = get_sparseness(st->lgBin_E_fx, lob_fft, sub(Etot, MDCT_SW_SIG_PEAK_THR)); + sparseness = get_sparseness(st->Bin_E, lob_fft, Etot - MDCT_SW_SIG_PEAK_THR); /* Hi band energy */ - hi_ener = get_mean_ener(&enerBuffer[lob_cldfb], enerBuffer_exp, sub(hib_cldfb, lob_cldfb)); + hi_ener = (float)log10(mean(&enerBuffer[lob_cldfb], hib_cldfb-lob_cldfb)+0.0001f); /* Hi band sparseness */ - IF (sub(st->bwidth_fx, SWB) >= 0) + if (st->bwidth >= SWB) { /* For SWB, assume hi band sparseness based on 4.8 KHz-6.4 KHz band */ - lob_fft = 3*L_FFT/2/4; /* 4.8 KHz */ move16(); + lob_fft = 3*L_FFT/2/4; /* 4.8 KHz */ } + peak_count = 0; - move16(); - tmp = add(MDCT_SW_SIG_LINE_THR, shr(Etot, 1)); /* Q7 */ - FOR (i=lob_fft; ilgBin_E_fx[i], tmp) >= 0) + if (st->Bin_E[i] >= Etot + MDCT_SW_SIG_LINE_THR*LOG_10) { - peak_count = add(peak_count, 1); + ++peak_count; } } - - hi_sparse = 0; - move16(); - if (sub(peak_count, mult_r(sub(hib_fft, lob_fft), MDCT_SW_HI_SPARSE_THR)) <= 0) - { - hi_sparse = 1; - move16(); - } - - sparse = 0; - move16(); - if (sub(peak_count, mult_r(sub(hib_fft, lob_fft), MDCT_SW_SPARSE_THR)) <= 0) - { - sparse = 1; - move16(); - } + hi_sparse = peak_count <= anint((hib_fft - lob_fft) * MDCT_SW_HI_SPARSE_THR); + sparse = peak_count <= anint((hib_fft - lob_fft) * MDCT_SW_HI_SPARSE_THR/MDCT_SW_HYST_FAC); /* Hysteresis */ - test(); - test(); - if (st->prev_hi_sparse > 0 && sparse > 0 && sub(s_min(s_min(voicing[0], voicing[1]), voicing[2]), MDCT_SW_1_VOICING_THR) >= 0) + if (st->prev_hi_sparse > 0 && sparse > 0 && min(min(voicing[0], voicing[1]), voicing[2]) >= MDCT_SW_1_VOICING_THR) { hi_sparse = 1; - move16(); } /* Allowed switching point? */ - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - switching_point = (sub(last_core, HQ_CORE) != 0 && sub(last_core, TCX_20_CORE) != 0) || /* previous core was non-MDCT */ - (sub(st->prev_hi_ener, MDCT_SW_HI_ENER_LO_THR) <= 0 || sub(hi_ener, MDCT_SW_HI_ENER_LO_THR) <= 0) || /* hi band is close to silent */ - (sub(last_core, HQ_CORE) == 0 && (sub(st->mdct_sw_enable, MODE1) == 0 || (hi_sparse > 0 && st->prev_hi_sparse >= 0 && sub(st->prev_hi_sparse, 1) <= 0))) || /* HQ_CORE and hi band became sparse */ - (sub(last_core, TCX_20_CORE) == 0 && (hi_sparse == 0 && st->prev_hi_sparse > 0)); /* TCX and hi band became dense */ + switching_point = (last_core != HQ_CORE && last_core != TCX_20_CORE) || /* previous core was non-MDCT */ + (st->prev_hi_ener <= MDCT_SW_HI_ENER_LO_THR || hi_ener <= MDCT_SW_HI_ENER_LO_THR) || /* hi band is close to silent */ + (last_core == HQ_CORE && (st->mdct_sw_enable == MODE1 || (hi_sparse > 0 && st->prev_hi_sparse >= 0 && st->prev_hi_sparse <= 1))) || /* HQ_CORE and hi band became sparse */ + (last_core == TCX_20_CORE && (hi_sparse == 0 && st->prev_hi_sparse > 0)); /* TCX and hi band became dense */ - IF (sub(st->mdct_sw_enable, MODE1) == 0) + if (st->mdct_sw_enable == MODE1) { sig_lo_level_thr = MDCT_SW_1_SIG_LO_LEVEL_THR; - move16(); sig_hi_level_thr = MDCT_SW_1_SIG_HI_LEVEL_THR; - move16(); cor_thr = MDCT_SW_1_COR_THR; - move16(); - cor_thr2 = MDCT_SW_1_COR_THR2; - move16(); voicing_thr = MDCT_SW_1_VOICING_THR; - move16(); - voicing_thr2 = MDCT_SW_1_VOICING_THR2; - move16(); sparseness_thr = MDCT_SW_1_SPARSENESS_THR; - move16(); - sparseness_thr2 = MDCT_SW_1_SPARSENESS_THR2; - move16(); hi_ener_lo_thr = MDCT_SW_1_HI_ENER_LO_THR; - move16(); } - ELSE /* st->mdct_sw_enable == MODE2 */ + else { + /* st->mdct_sw_enable == MODE2 */ sig_lo_level_thr = MDCT_SW_2_SIG_LO_LEVEL_THR; - move16(); sig_hi_level_thr = MDCT_SW_2_SIG_HI_LEVEL_THR; - move16(); cor_thr = MDCT_SW_2_COR_THR; - move16(); - cor_thr2 = MDCT_SW_2_COR_THR2; - move16(); voicing_thr = MDCT_SW_2_VOICING_THR; - move16(); - voicing_thr2 = MDCT_SW_2_VOICING_THR2; - move16(); sparseness_thr = MDCT_SW_2_SPARSENESS_THR; - move16(); - sparseness_thr2 = MDCT_SW_2_SPARSENESS_THR2; - move16(); hi_ener_lo_thr = MDCT_SW_2_HI_ENER_LO_THR; - move16(); } - test(); - test(); - test(); - test(); - test(); - prefer_tcx = (sub(sub(Etot, sp_floor), sig_hi_level_thr) >= 0) && /* noise floor is low */ - (sub(cor_map_sum, cor_thr) >= 0 || sub(frame_voicing, voicing_thr) >= 0 || sub(sparseness, sparseness_thr) >= 0) && /* strong tonal components */ - (sub(hi_ener, hi_ener_lo_thr) <= 0 || hi_sparse > 0); /* high freqs have low energy or are sparse */ + prefer_tcx = (Etot - sp_floor >= sig_hi_level_thr) && /* noise floor is low */ + (cor_map_sum >= cor_thr || frame_voicing >= voicing_thr || sparseness >= sparseness_thr) && /* strong tonal components */ + (hi_ener <= hi_ener_lo_thr || hi_sparse > 0); /* high freqs have low energy or are sparse */ - test(); - test(); - test(); - test(); - test(); - test(); - prefer_hq_core = (sub(sub(Etot, sp_floor), sig_lo_level_thr) < 0) || /* noise floor is very high */ - (sub(cor_map_sum, cor_thr2) < 0 && sub(frame_voicing, voicing_thr2) < 0 && sub(sparseness, sparseness_thr2) < 0) || /* too weak tonal components */ - (sub(st->mdct_sw_enable, MODE1) == 0 && prefer_tcx == 0 && sub(st->transientDetection.transientDetector.bIsAttackPresent, 1) == 0); + prefer_hq_core = (Etot - sp_floor < sig_lo_level_thr) || /* noise floor is very high */ + (cor_map_sum < cor_thr*MDCT_SW_HYST_FAC && frame_voicing < voicing_thr*MDCT_SW_HYST_FAC && sparseness < sparseness_thr*MDCT_SW_HYST_FAC) || /* too weak tonal components */ + (st->mdct_sw_enable == MODE1 && !prefer_tcx && st->transientDetection.transientDetector.bIsAttackPresent == 1); /* Prefer HQ_CORE on transients */ - test(); - IF ( sub(st->mdct_sw_enable, MODE2) == 0 && sub(st->transientDetection.transientDetector.bIsAttackPresent, 1) == 0 ) + if ( st->mdct_sw_enable == MODE2 && st->transientDetection.transientDetector.bIsAttackPresent == 1 ) { prefer_tcx = 0; - move16(); prefer_hq_core = 1; - move16(); } - test(); - test(); - test(); - IF (switching_point && (prefer_tcx || prefer_hq_core)) + if (switching_point && (prefer_tcx || prefer_hq_core)) { - IF (prefer_tcx) + if (prefer_tcx) { - st->core_fx = TCX_20_CORE; - move16(); + st->core = TCX_20_CORE; } - ELSE /* prefer_hq_core */ + else /* prefer_hq_core */ { - st->core_fx = HQ_CORE; - move16(); + st->core = HQ_CORE; } } - ELSE IF (sub(last_core, HQ_CORE) == 0 || sub(last_core, TCX_20_CORE) == 0) + else if (last_core == HQ_CORE || last_core == TCX_20_CORE) { - st->core_fx = last_core; - move16(); + st->core = last_core; } - test(); - test(); - test(); /* Prevent the usage of HQ_CORE on noisy-speech or inactive */ - IF (sub(st->mdct_sw_enable, MODE2) == 0 && sub(st->core_fx, HQ_CORE) == 0 && (sub(st->flag_noisy_speech_snr, 1) == 0 || vadflag==0)) + if ( st->mdct_sw_enable==MODE2 && st->core == HQ_CORE && (st->flag_noisy_speech_snr == 1 || vadflag == 0 ) ) { - st->core_fx = TCX_20_CORE; - move16(); + st->core = TCX_20_CORE; } + /* Update memories */ - st->prev_hi_sparse = add(st->prev_hi_sparse, hi_sparse); - move16(); if (hi_sparse <= 0) { st->prev_hi_sparse = hi_sparse; - move16(); } - st->prev_hi_sparse = s_min(st->prev_hi_sparse, 2); + else + { + st->prev_hi_sparse += hi_sparse; + if (st->prev_hi_sparse >= 2) + { + st->prev_hi_sparse = 2; + } + } st->prev_hi_ener = hi_ener; - move16(); } + + return; } +/*--------------------------------------------------------------------------* + * MDCT_selector_reset() + * + * + *--------------------------------------------------------------------------*/ + void MDCT_selector_reset( - Encoder_State_fx *st /* i/o: Encoder State */ + Encoder_State *st /* i/o: Encoder State */ ) { st->prev_hi_ener = 0; - move16(); st->prev_hi_sparse = -1; - move16(); + + return; } diff --git a/src/libs/libevs/lib_enc/mslvq_enc.cpp b/src/libs/libevs/lib_enc/mslvq_enc.cpp new file mode 100644 index 00000000..9916532f --- /dev/null +++ b/src/libs/libevs/lib_enc/mslvq_enc.cpp @@ -0,0 +1,743 @@ +/*==================================================================================== + EVS Codec 3GPP TS26.443 Nov 13, 2018. Version 12.11.0 / 13.7.0 / 14.3.0 / 15.1.0 + ====================================================================================*/ + +#include +#include "prot.h" +#include "rom_com.h" +#include "cnst.h" + +/*-----------------------------------------------------------------* + * Local functions + *-----------------------------------------------------------------*/ + +static float quantize_data( float *data, const float *w_in, float *qin, float *cv_out, int *idx_lead, int *idx_scale, const float *sigma, + const float * inv_sigma, + const float *scales, short no_scales, const int *no_lead ); +static float q_data( float *pTmp1, const float *w1, float *quant, float *cv_out, int *idx_lead, int *idx_scale, + const float * p_inv_sigma, + const float *p_sigma, const float *p_scales, short *p_no_scales, const int *p_no_lead ); +static void prepare_data( float *xsort, int *sign, + float *data, float *w, const float *w_in, + const float * sigma, + const float * inv_sigma, + int *p_sig ); +static float calculate_min_dist( float cv_pot[LATTICE_DIM], int no_scales, const float *scale, const float *w, int *p_best_scale, + int *p_best_idx, const int *no_leaders, int sig, int * indx); +static int find_pos( float *c, int len, float arg, int *p ); +static void take_out_val( float *v, float *v_out, float val, int len ); +static int index_leaders( float *cv, int idx_lead, int dim ); +static int c2idx( int n, int *p, int k ); +static int encode_sign_pc1( int parity, float *cv); +static int encode_comb( float *cv, int idx_lead ); +static void sort_desc_ind( float *s, int len, int *ind ); + + +/*-----------------------------------------------------------------* + * mslvq() + * + * Encodes the LSF residual + *-----------------------------------------------------------------*/ +float mslvq ( + float *pTmp, /* i : M-dimensional input vector */ + float *quant, /* o : quantized vector */ + float *cv_out, /* o : corresponding 8-dim lattice codevectors (without the scaling) */ + int *idx_lead, /* o : leader index for each 8-dim subvector */ + int *idx_scale, /* o : scale index for each subvector */ + float *w, /* i : weights for LSF quantization */ + short mode, /* i : number indicating the coding type (V/UV/G...)*/ + short mode_glb, /* i : LVQ coding mode */ + int pred_flag, /* i : prediction flag (0: safety net, 1,2 - predictive )*/ + short no_scales[][2] +) +{ + float dist; + const float * p_scales, *p_sigma, *p_inv_sigma; + const int *p_no_lead; + short * p_no_scales; + + dist = 0.0f; + p_no_scales = no_scales[mode_glb]; + if ( pred_flag == 0 ) + { + p_sigma = sigma_MSLVQ[mode]; + /* inverse sigma is precomputed to save complexity */ + p_inv_sigma = inv_sigma_MSLVQ[mode]; + p_scales = scales[mode_glb]; + p_no_lead = no_lead[mode_glb]; + + } + else + { + p_sigma = sigma_p[mode]; + /* inverse sigma is precomputed to save complexity */ + p_inv_sigma = inv_sigma_p[mode]; + p_scales = scales_p[mode_glb]; + p_no_lead = no_lead_p[mode_glb]; + } + /* first subvector */ + dist += quantize_data( pTmp, w, quant, cv_out, idx_lead, idx_scale, + p_sigma, + p_inv_sigma, + p_scales, p_no_scales[0], p_no_lead ); + /* second subvector */ + dist += quantize_data( pTmp+LATTICE_DIM, w+LATTICE_DIM, quant+LATTICE_DIM, + cv_out+LATTICE_DIM, &idx_lead[1], &idx_scale[1], + p_sigma+LATTICE_DIM, + p_inv_sigma+LATTICE_DIM, + p_scales+MAX_NO_SCALES, + p_no_scales[1], p_no_lead+MAX_NO_SCALES ); + + return dist; +} +/*-----------------------------------------------------------------* + * q_data() + * + * (used for LSF quantization in CNG) + *-----------------------------------------------------------------*/ + +static float q_data ( + float *pTmp1, + const float *w1, + float *quant, + float *cv_out, + int *idx_lead, + int *idx_scale, + const float *p_sigma, + const float *p_inv_sigma, + const float *p_scales, + short *p_no_scales, + const int *p_no_lead +) +{ + float dist = 0.0f; + /* first subvector */ + dist += quantize_data( pTmp1, w1, quant, cv_out, idx_lead, idx_scale, p_sigma, + p_inv_sigma, p_scales, p_no_scales[0], p_no_lead ); + /* second subvector */ + dist += quantize_data( pTmp1+LATTICE_DIM, w1+LATTICE_DIM, quant+LATTICE_DIM, cv_out+LATTICE_DIM, &idx_lead[1], &idx_scale[1], + p_sigma+LATTICE_DIM,p_inv_sigma+LATTICE_DIM, + p_scales+MAX_NO_SCALES, p_no_scales[1], p_no_lead+MAX_NO_SCALES ); + + return dist; +} + +/*-----------------------------------------------------------------* + * mslvq_cng() + * + * Encodes the LSF residual in SID frames + *-----------------------------------------------------------------*/ + +float mslvq_cng ( + short idx_cv, /* i : index of cv from previous stage */ + float *pTmp, /* i : 16 dimensional input vector */ + float *quant, /* o : quantized vector */ + float *cv_out, /* o : corresponding 8-dim lattice codevectors (without the scaling) */ + int *idx_lead, /* o : leader index for each 8-dim subvector */ + int *idx_scale, /* o : scale index for each subvector */ + const float *w, /* i : weights for LSF quantization */ + short * no_scales +) +{ + float dist; + const float *p_scales, *p_sigma, *p_inv_sigma; + const int *p_no_lead; + short *p_no_scales; + short mode_glb, mode, i; + float pTmp1[M], w1[M]; + + dist = 0.0f; + mode = (short)LVQ_COD_MODES + idx_cv; + + /* for CNG there is only one bitrate but several quantizer structures, depending on the previous VQ stage */ + mode_glb = START_CNG + idx_cv; + + p_sigma = sigma_MSLVQ[mode]; + p_inv_sigma = inv_sigma_MSLVQ[mode]; + p_scales = scales[mode_glb]; + p_no_lead = no_lead[mode_glb]; + p_no_scales = &no_scales[mode_glb*2]; + /* check if LSF component permutation is needed or not */ + if ( cng_sort[idx_cv] ) + { + /* change order in subvecs */ + for( i=0; i0) + { + prepare_data( cv_pot, sign, data, w, w_in, sigma, inv_sigma, &sig ); + /* sorting of the input vector based on its absolute values; indx: permutation corresponding to the sorting */ + sort_desc_ind(cv_pot, LATTICE_DIM, indx); + smallest = indx[LATTICE_DIM-1]; + min_dist = calculate_min_dist(cv_pot, no_scales, scale, w, &best_scale, &best_idx, no_leaders, sig, indx); + if (best_scale > -1) + { + for(j=0; j -1 ) + { + index1 = encode_comb(quant, idx_lead[0]) + table_no_cv[idx_lead[0]] + p_offset_scale1[mode*len_offset +idx_scale[0]]; + } + + /* for second subvector */ + index2 = 0; + if ( idx_scale[1] > -1 ) + { + index2 = encode_comb(&quant[LATTICE_DIM], idx_lead[1]) + table_no_cv[idx_lead[1]] + p_offset_scale2[mode*len_offset+idx_scale[1]]; + } + + multiply32_32_64(index1, (unsigned int)(p_offset_scale2[mode*len_offset+p_no_scales[mode*2+1]]), idx); + + tmp = idx[0] + index2; + if ( tmp < idx[0] || tmp < index2 ) + { + idx[1] +=1; + } + + idx[0] = tmp; + + /* convert to 3 short */ + index[0] = ((idx[0])&(0xffff>>1)); + index[1] = ((idx[0])>>15)&(0xffff>>1); + index[2] = ((idx[0])>>30) + (((idx[1])<<2)&(0xffff>>1)); + + return; +} + + + +/*-----------------------------------------------------------------* + * encode_comb() + * + * creates an index for the lattice codevector + *-----------------------------------------------------------------*/ + +static int encode_comb( /* o : index of the absolute valued codevector */ + float *cv, /* i : codevector to be indexed */ + int idx_lead /* i : leader class index, to know the values */ +) +{ + int idx_sign, idx_ld_class; + + idx_sign = encode_sign_pc1( pl_par[idx_lead], cv ); + idx_ld_class = index_leaders( cv, idx_lead, LATTICE_DIM ); + + return idx_sign * pi0[idx_lead] + idx_ld_class; +} + + +/*-----------------------------------------------------------------* + * index_leaders() + * + * gives the index in a class of leaders without considering the sign yet + *-----------------------------------------------------------------*/ + +static int index_leaders( /* o : index */ + float *cv, /* i : codevector to be indexed */ + int idx_lead, /* i : leader class index */ + int dim /* i : vector dimension */ +) +{ + int index, i, no_vals_loc, nr, p[LATTICE_DIM], dim_loc; + float cv_copy[LATTICE_DIM], val_crt; + + no_vals_loc = no_vals[idx_lead]; + + if ( no_vals_loc == 1 ) + { + return 0; + } + + for( i=0; i 0 ) + { + cnt ++; + } + } + + return idx_sign; +} + +/*-----------------------------------------------------------------* + * take_out_val() + * + * removes the value val from the vector v + *-----------------------------------------------------------------*/ + +static void take_out_val( + float *v, /* i : input vector */ + float *v_out, /* o : output vector without the value val*/ + float val, /* i : value to be removed */ + int len /* i : input vector length */ +) +{ + int i, cnt; + + cnt = 0; + + for( i=0; i0) - { - max_nb = nb; - move16(); - } - } - max_nb1 = 0; - FOR(l=0; l0) - { - max_nb1 = nb; - move16(); - } - } - nb = sub(max_nb1,13); - if ( nb < 0 ) - { - nb = 0; - } - - nb = sub(30,add(max_nb,nb)); - /* sorting the weight based on the ordering indx[] of the input vector */ - FOR(l=0; l 0 ) - { - prepare_data_fx( cv_pot, sign, data, w, w_in, sigma, inv_sigma, &sig ); - move16(); - /* sorting of the input vector based on its absolute values; indx: permutation corresponding to the sorting */ - sort_desc_ind_fx( cv_pot, LATTICE_DIM, indx ); - smallest = indx[LATTICE_DIM-1]; - move16(); - - min_dist = calculate_min_dist_fx( cv_pot, no_scales, scale, w, &best_scale, &best_idx ,no_leaders, sig, indx); - - IF ( add(best_scale,1) > 0 ) - { - FOR(j=0; j 0 ; k-- ) - { - IF (sorted) - { - BREAK; - } - - sorted = 1; - move16(); - FOR ( i=0 ; i < k ; i++ ) - { - IF ( sub(s[i],s[i+1]) < 0 ) - { - sorted = 0; - move16(); - t = s[i]; - move16(); - s[i] = s[i+1]; - move16(); - s[i+1] = t; - move16(); - a = ind[i]; - move16(); - ind[i] = ind[i+1]; - move16(); - ind[i+1] = a; - move16(); - } - } - } - - return; -} - -/*-----------------------------------------------------------------* - * index_lvq() - * - * sorts in descending order and computes indices in the sorted vector - *-----------------------------------------------------------------*/ -void index_lvq_fx ( - Word16 *quant, /* i : codevector to be indexed (2 8-dim subvectors) Q13*/ - Word16 *idx_lead, /* i : leader class index for each subvector */ - Word16 *idx_scale, /* i :scale index for each subvector */ - Word16 mode, /* i : integer signalling the quantizer structure for the current bitrate */ - Word16 *index, /* o : encoded index (represented on 3 short each with 15 bits ) */ - Word32 * p_offset_scale1, /* i : scales for first subvector */ - Word32 * p_offset_scale2, /* i : scales for second subvector */ - Word16 * p_no_scales /* i : number of scales for each subvector */ -) -{ - Word32 index1, index2, tmp, idx[2]; - Word16 len_offset; - - len_offset = add(MAX_NO_SCALES,1); - move16(); - - index1 = 0; - move16(); - - /* for first subvector */ - IF ( add(idx_scale[0],1) >0 ) - { - index1 = L_add(encode_comb_fx(quant, idx_lead[0]), L_add(table_no_cv_fx[idx_lead[0]] , p_offset_scale1[i_mult2(mode,len_offset) +idx_scale[0]])); - } - - /* for second subvector */ - index2 = L_deposit_l(0); - - IF ( add(idx_scale[1], 1) >0 ) - { - index2 = L_add(encode_comb_fx(&quant[LATTICE_DIM], idx_lead[1]), L_add(table_no_cv_fx[idx_lead[1]], p_offset_scale2[i_mult2(mode,len_offset)+idx_scale[1]])); - } - - multiply32_32_64_fx(index1, p_offset_scale2[mode*len_offset+p_no_scales[mode*2+1]], idx); - - tmp = L_add(idx[0], index2); - test(); - IF ( (L_sub(tmp, idx[0]) <0) || (L_sub(tmp, index2) < 0) ) - { - idx[1] = L_add(idx[1], 1); - move32(); - } - - idx[0] = tmp; - move32(); - - /* convert to 3 short */ - index[0] = ((idx[0])&(0x7fff)); - move16(); - index[1] = ((idx[0])>>15)&(0x7fff); - move16(); - index[2] = (idx[1])&(0x7fff); - move16(); - - return; -} - - -/*-----------------------------------------------------------------* - * encode_comb() - * - * creates an index for the lattice codevector - *-----------------------------------------------------------------*/ - -static Word32 encode_comb_fx( /* o : index of the absolute valued codevector*/ - Word16 *cv, /* i : codevector to be indexed Q13*/ - Word16 idx_lead /* i : leader class index, to know the values */ -) -{ - Word16 idx_sign, idx_ld_class; - Word32 L_tmp; - - idx_sign = encode_sign_pc1_fx( pl_par_fx[idx_lead], cv ); - move16(); - idx_ld_class = index_leaders_fx( cv, idx_lead, LATTICE_DIM ); - move16(); - - L_tmp = L_mac0(idx_ld_class, idx_sign,pi0_fx[idx_lead]); - - return L_tmp; -} - -/*-----------------------------------------------------------------* - * index_leaders() - * - * gives the index in a class of leaders without considering the sign yet - *-----------------------------------------------------------------*/ - -static Word16 index_leaders_fx( /* o : index */ - Word16 *cv, /* i : codevector to be indexed Q13*/ - Word16 idx_lead, /* i : leader class index */ - Word16 dim /* i : vector dimension */ -) -{ - Word16 index; - Word16 i, no_vals_loc, nr, p[LATTICE_DIM], dim_loc; - Word16 cv_copy[LATTICE_DIM], val_crt; - - no_vals_loc = no_vals_fx[idx_lead]; - move16(); - - IF ( sub(no_vals_loc, 1) == 0 ) - { - return 0; - } - - FOR( i=0; i 0 ) - { - cnt = add(cnt, 1); - } - } - - return idx_sign; -} - -/*-----------------------------------------------------------------* - * take_out_val() - * - * removes the value val from the vector v - *-----------------------------------------------------------------*/ - -static void take_out_val_fx( - Word16 *v, /* i : input vector x2.56*/ - Word16 *v_out, /* o : output vector without the value val */ - Word16 val, /* i : value to be removed x2.56*/ - Word16 len /* i : input vector length */ -) -{ - Word16 i, cnt; - - cnt = 0; - move16(); - - FOR( i=0; i 0) + { + *sp_floor = 0; + for (i=0; i flor) + { + S[i] = Bin_E[i] - flor; + } + else + { + S[i] = 0; + } + + /* update the floor */ + flor += step; + } + } + else + { + *sp_floor = Bin_E[0]; + } + *sp_floor *= 1.0f/log(10); + + /* calculate the maximum dynamic per band */ + mean_dyn = mean( &S[L-40], 40 ); + mean_dyn = 0.6f * *st_mean_avr_dyn + 0.4f * mean_dyn; + + if ( mean_dyn < 9.6f && *cor_strong_limit != 0 ) + { + *cor_strong_limit = 0; + *st_last_sw_dyn = mean_dyn; + } + else if ((mean_dyn - *st_last_sw_dyn) > 4.5f) + { + *cor_strong_limit = 1; + } + + if( total_brate < ACELP_9k60 || total_brate > ACELP_16k40 ) + { + *cor_strong_limit = 1; + } + + *st_mean_avr_dyn = mean_dyn; + + /*------------------------------------------------------------------* + * calculation of the correlation map + *------------------------------------------------------------------*/ + + if (N_mins > 0) + { + corx2 = 0; + corxy = 0; + stemp = ind_mins[0]; + ftemp = old_S[stemp]; + cory2 = ftemp * ftemp; + k = 1; + for (i = stemp+1; i <= ind_mins[N_mins]; i++) + { + if (i == ind_mins[k]) + { + /* include the last peak point (new minimum) to the corr. sum */ + ftemp = old_S[i]; + cory2 += ftemp * ftemp; + + /* calculation of the norm. peak correlation */ + if ((corx2 == 0) || (cory2 == 0)) + { + cor = 0; + } + else + { + cor = corxy * corxy / (corx2 * cory2); + } + + /* save the norm. peak correlation in the correlation map */ + for (j=ind_mins[k-1]; j 0.95f) + { + cor_strong = 1; + } + } + + + /* summation of the LT correlation map */ + cor_map_LT_sum = sum_f(cor_map_LT, L); + + if ( bwidth == NB ) + { + cor_map_LT_sum *= 1.53f; + *cor_map_sum *= 1.53f; + } + + + /* final decision about multi-harmonicity */ + if ( (cor_map_LT_sum > *multi_harm_limit) || (cor_strong == 1) ) + { + harm = 1; + } + else + { + harm = 0; + } + + /*------------------------------------------------------------------* + * updating of the decision threshold + *------------------------------------------------------------------*/ + + if (cor_map_LT_sum > THR_CORR) + { + *multi_harm_limit -= THR_CORR_STEP; + } + else + { + *multi_harm_limit += THR_CORR_STEP; + } + + if (*multi_harm_limit > THR_CORR_MAX) + { + *multi_harm_limit = THR_CORR_MAX; + } + + if (*multi_harm_limit < THR_CORR_MIN) + { + *multi_harm_limit = THR_CORR_MIN; + } + + if (N_mins <= 0) + { + set_f(old_S, 0, L); + } + + return harm; +} diff --git a/src/libs/libevs/lib_enc/multi_harm_fx.cpp b/src/libs/libevs/lib_enc/multi_harm_fx.cpp deleted file mode 100755 index c174c0ef..00000000 --- a/src/libs/libevs/lib_enc/multi_harm_fx.cpp +++ /dev/null @@ -1,355 +0,0 @@ -/*==================================================================================== - EVS Codec 3GPP TS26.442 Apr 03, 2018. Version 12.11.0 / 13.6.0 / 14.2.0 - ====================================================================================*/ - -#include "options.h" /* Compilation switches */ -#include "cnst_fx.h" /* Common constants */ -#include "prot_fx.h" /* Function prototypes */ -#include "stl.h" - -#define THR_CORR_FX (56<<15) /* 56 in Q15 starting threshold of multi-harm. correlation */ -#define THR_CORR_MAX_FX 30720 /* 60 in Q9 upper threshold of multi-harm. correlation */ -#define THR_CORR_MIN_FX 25088 /* 49 in Q9 lower threshold of multi-harm. correlation */ -#define THR_CORR_STEP_FX 102 /* 0.2 in Q9 step for the threshold of multi-harm. correlation */ - -/*---------------------------------------------------------------------* - * multi_harm() - * - * Perform multi-harmonic analysis, information used for UV and VAD decision - *---------------------------------------------------------------------*/ - -Word16 multi_harm_fx( /* o : frame multi-harmonicity (1-harmonic, 0-not) */ - const Word16 Bin_E[], /* i : log-energy spectrum of the current frame Q7 */ - Word16 old_S[], /* i/o: prev. log-energy spectrum w. subtracted floor Q7 */ - Word16 cor_map_LT[], /* i/o: LT correlation map Q15 */ - Word16 *multi_harm_limit, /* i/o: multi harminic threshold Q9 */ - const Word32 total_brate, /* i : total bitrate Q0 */ - const Word16 bwidth, /* i : input signal bandwidth Q0 */ - Word16 *cor_strong_limit, /* i/o: HF correlation indicator Q0 */ - Word16 *st_mean_avr_dyn, /* i/o: long term average dynamic Q7 */ - Word16 *st_last_sw_dyn, /* i/o: last dynamic Q7 */ - Word16 *cor_map_sum /* Q8 */ - , Word16 *sp_floor /* o: noise floor estimate Q7 */ -) -{ - Word16 i, j, k, L, stemp, N_mins, ind_mins[L_FFT/4], *pt_mins, harm; - Word16 S[L_FFT/2], flor, step, sign_fx, tmp16, tmp2, ExpInd, tmpdB, ExpdB, Expx2, Expy2; - Word16 corx2, cory2, corxy, cor, cor_map[L_FFT/2], *pt1, *pt2, cor_strong; - Word32 L_acc; - Word32 Lcorx2, Lcory2, Lcorxy, Lcor_map_LT_sum; - Word16 mean_dyn; - - /*------------------------------------------------------------------* - * initialization - *------------------------------------------------------------------*/ - - /* length of the useful part of the spectrum (up to 6.4kHz) */ - L = L_FFT/2; - move16(); - if ( sub(bwidth,NB) == 0 ) - { - /* length of the useful part of the spectrum (up to 3.6kHz) */ - L = 76; - move16(); - } - - Copy(Bin_E, S, L); - - /*------------------------------------------------------------------* - * searching of spectral maxima and minima - *------------------------------------------------------------------*/ - - pt_mins = ind_mins; - move16(); - - /* index of the first minimum */ - if (sub(Bin_E[0],Bin_E[1]) < 0) - { - *pt_mins++ = 0; - move16(); - } - - FOR (i=1; i 0) - { - L_acc = L_deposit_l(0); - FOR (i=0; i 0/*4.5f*/) - { - *cor_strong_limit = 1; - move16(); - } - test(); - if( L_sub(total_brate,ACELP_9k60) < 0|| L_sub(total_brate,ACELP_16k40) > 0 ) - { - *cor_strong_limit = 1; - move16(); - } - - *st_mean_avr_dyn = mean_dyn; - move16(); - - /*------------------------------------------------------------------* - * calculation of the correlation map - *------------------------------------------------------------------*/ - - set16_fx(cor_map, 0,L); - IF (N_mins > 0) - { - Lcorx2 = L_deposit_l(0); - Lcorxy = L_deposit_l(0); - stemp = ind_mins[0]; - move16(); - Lcory2 = L_mult(old_S[stemp],old_S[stemp]); - k = 1; - move16(); - - FOR (i = add(stemp,1); i <= ind_mins[N_mins]; i++) - { - IF (sub(i,ind_mins[k]) == 0) - { - /* include the last peak point (new minimum) to the corr. sum */ - Lcory2 = L_mac(Lcory2, old_S[i], old_S[i]); - - /* calculation of the norm. peak correlation */ - test(); - IF (Lcorx2 != 0 && Lcory2 != 0) - { - /* corxy * corxy*/ - tmp16 = sub(norm_l(Lcorxy),1); - corxy = extract_h(L_shl(Lcorxy, tmp16)); - corxy = mult_r(corxy, corxy); - /* (corx2 * cory2) */ - Expx2 = norm_l(Lcorx2); - Expy2 = norm_l(Lcory2); - corx2 = extract_h(L_shl(Lcorx2, Expx2)); - cory2 = extract_h(L_shl(Lcory2, Expy2)); - corx2 = mult_r(corx2, cory2); - Expx2 = add(Expy2, Expx2); - /* Validate num < den */ - cor = sub(corx2, corxy); - cor = shr(cor, 15); - /* Add 1 to tmp16 & shr by 2 if corxy > corx2 */ - tmp16 = sub(tmp16, cor); - corxy = shl(corxy, cor); - corxy = shl(corxy, cor); - /* cor = corxy * corxy / (corx2 * cory2) */ - corxy = div_s(corxy, corx2); - cor = shr(corxy, sub(shl(tmp16, 1), Expx2)); /* Q15 */ - } - ELSE - { - cor = 0; - move16(); - } - - /* save the norm. peak correlation in the correlation map */ - FOR (j=ind_mins[k-1]; j 0/*0.95f*/) - { - cor_strong = 1; - move16(); - } - - pt1++; - pt2++; - } - - IF ( sub(bwidth,NB) == 0 ) - { - /* cor_map_LT_sum *= 1.53f; */ - /* tmp2 *= 1.53f; */ - Lcor_map_LT_sum = L_shl(Mult_32_16(Lcor_map_LT_sum, 25068), 1); - tmp2 = round_fx(L_mac(L_mult(tmp2, 32767), tmp2, 17367)); - } - *cor_map_sum = tmp2; - move16(); - - /* final decision about multi-harmonicity */ - harm = 0; - move16(); - test(); - if ( (L_msu0(Lcor_map_LT_sum, *multi_harm_limit, 64) > 0) || (cor_strong != 0) ) - { - harm = 1; - move16(); - } - - /*------------------------------------------------------------------* - * updating of the decision threshold - *------------------------------------------------------------------*/ - - stemp = add(*multi_harm_limit, THR_CORR_STEP_FX); - if (L_sub(Lcor_map_LT_sum, THR_CORR_FX) > 0) /* Q15 */ - { - /* *multi_harm_limit -= THR_CORR_STEP_FX */ - stemp = sub(*multi_harm_limit, THR_CORR_STEP_FX); - } - - stemp = s_min(stemp, THR_CORR_MAX_FX); - *multi_harm_limit = s_max(stemp, THR_CORR_MIN_FX); - move16(); - - IF (N_mins <= 0) - { - set16_fx(old_S, 0, L); - } - - return harm; -} diff --git a/src/libs/libevs/lib_enc/nelp_enc.cpp b/src/libs/libevs/lib_enc/nelp_enc.cpp new file mode 100644 index 00000000..8c926a2b --- /dev/null +++ b/src/libs/libevs/lib_enc/nelp_enc.cpp @@ -0,0 +1,408 @@ +/*==================================================================================== + EVS Codec 3GPP TS26.443 Nov 13, 2018. Version 12.11.0 / 13.7.0 / 14.3.0 / 15.1.0 + ====================================================================================*/ + +#include +#include "options.h" +#include "cnst.h" +#include "prot.h" +#include "rom_com.h" + +/*-------------------------------------------------------------------* + * quantize_uvg() + * + * Quantize unvoiced gains + *--------------------------------------------------------------------*/ + +static void quantize_uvg( + float *G, /* i : unvoiced gain */ + int *iG1, /* i : gain 1 index */ + int *iG2, /* i : gain 2 index */ + float *quantG, /* o : quantized gain */ + short bwidth +) +{ + float G1[2], G2[10]; + int i, j, k; + float mse, mmse; + const float (*UVG1CB)[2] = NULL; + const float (*UVG2CB1)[5] = NULL; + const float (*UVG2CB2)[5] = NULL; + + if ( bwidth == NB ) + { + UVG1CB = UVG1CB_NB; + UVG2CB1 = UVG2CB1_NB; + UVG2CB2 = UVG2CB2_NB; + } + else if ( bwidth == WB || bwidth == SWB ) + { + UVG1CB = UVG1CB_WB; + UVG2CB1 = UVG2CB1_WB; + UVG2CB2 = UVG2CB2_WB; + } + + for (i=0; i<2; i++) + { + G1[i] = 0; + for (j=0; j<5; j++) + { + G1[i] += SQR(G[i*5+j]); + } + G1[i] = (float) log10(sqrt(G1[i]/5)); + } + + mmse = (float) 1e30; + *iG1 = 0; + + for (i=0; i< UVG1_CBSIZE; i++) + { + mse = SQR(G1[0]-(UVG1CB[i][0]))+SQR(G1[1]-(UVG1CB[i][1])); + if (mse < mmse) + { + *iG1 = i; + mmse = mse; + } + } + + G1[0] = (float) pow(10.0,(UVG1CB[*iG1][0])); + G1[1] = (float) pow(10.0,(UVG1CB[*iG1][1])); + + for (i=0; i<2; i++) + { + for (j=0; j<5; j++) + { + G2[i*5+j] = G[i*5+j]/G1[i]; + } + } + + for (i=0; i<2; i++) + { + mmse = (float) 1e30; + iG2[i] = 0; + for (j=0; jrf_mode; + + if ((st->last_nelp_mode == 1) && (st->bwidth != st->last_bwidth)) + { + st->last_nelp_mode = 0; + } + + if ( st->bwidth == NB ) + { + if (st->last_nelp_mode != 1) + { + set_f(st->bp1_filt_mem_nb, 0, 7*2); + } + } + else if ( st->bwidth == WB || st->bwidth == SWB ) + { + if (st->last_nelp_mode != 1) + { + set_f(st->bp1_filt_mem_wb, 0, 4*2); + } + } + + if (st->last_nelp_mode != 1) + { + if ( st->bwidth == WB || st->bwidth == SWB ) + { + set_f(st->shape1_filt_mem, 0, 20); + set_f(st->shape2_filt_mem, 0, 20); + set_f(st->shape3_filt_mem, 0, 20); + set_f(st->txlpf1_filt1_mem, 0, 20); + set_f(st->txlpf1_filt2_mem, 0, 20); + set_f(st->txhpf1_filt1_mem, 0, 20); + set_f(st->txhpf1_filt2_mem, 0, 20); + } + } + + /* Start Unvoiced/NELP Processing */ + if ( st->bwidth == WB || st->bwidth == SWB ) + { + for (i=0, E1=0.001f; itxlpf1_filt1_mem); + + for (i=0, EL1=0.001f; itxhpf1_filt1_mem); + + for (i=0, EH1=0.001f; ilast_nelp_mode != 1) /* if prev frame was not NELP then init mem*/ + { + st->nelp_gain_mem = Gains[0]; + } + + tmp = (float) (20.0 * (log10 (Gains[0]) - log10 (st->nelp_gain_mem) ) ); + var_dB = tmp * tmp; + for (i = 1; i < 10; i++) + { + tmp = (float) (20.0 * (log10 (Gains[i]) - log10 (Gains[i - 1]))); + var_dB += tmp * tmp; + } + + if (st->last_nelp_mode!=1) + { + var_dB *= 0.111f; + } + else + { + var_dB *= 0.1f; + } + + fdbck = (float) (0.82f / (1.0f + exp (0.25f * (var_dB - 20.0f)))); + + for (i = 0; i < 10; i++) + { + Gains[i] = (float)((1.0f - fdbck) * Gains[i] + fdbck * st->nelp_gain_mem); + st->nelp_gain_mem = Gains[i]; + } + + quantize_uvg(Gains, &iG1, iG2, Gains, (short) st->bwidth ); + + if( rf_flag ) + { + st->rf_indx_nelp_iG1[0] = (short) iG1; + st->rf_indx_nelp_iG2[0][0] = (short) iG2[0]; + st->rf_indx_nelp_iG2[0][1] = (short) iG2[1]; + } + else + { + push_indice( st, IND_IG1, iG1, 5 ); + push_indice( st, IND_IG2A, iG2[0], 6 ); + push_indice( st, IND_IG2B, iG2[1], 6 ); + } + + if ( st->bwidth == WB || st->bwidth == SWB ) + { + gain_fac = 1.16f; + } + else + { + gain_fac = 1.37f; + } + + generate_nelp_excitation( &(st->nelp_enc_seed), Gains, ptr, gain_fac ); + + if ( st->bwidth == WB || st->bwidth == SWB ) + { + polezero_filter(ptr,ptr_tmp,L_FRAME,bp1_num_coef_wb,bp1_den_coef_wb,4,st->bp1_filt_mem_wb); + mvr2r(ptr_tmp,ptr,L_FRAME); + } + else if ( st->bwidth == NB ) + { + polezero_filter(ptr,ptr_tmp,L_FRAME,bp1_num_coef_nb_fx_order7,bp1_den_coef_nb_fx_order7,7,st->bp1_filt_mem_nb); + mvr2r(ptr_tmp,ptr,L_FRAME); + } + + for (i=0, E3=0.001f; ibwidth == WB || st->bwidth == SWB ) + { + polezero_filter(ptr,ptr_tmp,L_FRAME,shape1_num_coef,shape1_den_coef,10, st->shape1_filt_mem); + mvr2r(ptr_tmp,ptr,L_FRAME); + + for (i=0, E2=0.001f; itxlpf1_filt2_mem); + mvr2r(ptr_tmp,filtRes,L_FRAME); + + for (i=0, EL2=0.001f; itxhpf1_filt2_mem); + mvr2r(ptr_tmp,filtRes,L_FRAME); + + for (i=0, EH2=0.001f; ishape3_filt_mem); + + /* filter the residual to desired shape */ + polezero_filter(ptr,ptr_tmp,L_FRAME,shape2_num_coef,shape2_den_coef,10,st->shape2_filt_mem); + + mvr2r(ptr_tmp,ptr,L_FRAME); + + break; + case 2: + /* Update other filter memory */ + polezero_filter(ptr,filtRes,L_FRAME,shape2_num_coef,shape2_den_coef,10,st->shape2_filt_mem); + + /* filter the residual to desired shape */ + polezero_filter(ptr,ptr_tmp,L_FRAME,shape3_num_coef,shape3_den_coef,10,st->shape3_filt_mem); + + mvr2r(ptr_tmp,ptr,L_FRAME); + + break; + default: + /* Update other filter memory */ + polezero_filter(ptr,filtRes,L_FRAME,shape2_num_coef,shape2_den_coef,10,st->shape2_filt_mem); + polezero_filter(ptr,filtRes,L_FRAME,shape3_num_coef,shape3_den_coef,10,st->shape3_filt_mem); + + break; + } + + for (i=0, E2=0.001f; irf_indx_nelp_fid[0] = (short)fid; + } + else + { + push_indice( st, IND_NELP_FID, fid, 2 ); + } + } + + if(rf_flag==0) + { + for (i = 0; i < L_FRAME; i++) + { + exc[i] = ptr[i]; + } + } + return; +} diff --git a/src/libs/libevs/lib_enc/nelp_enc_fx.cpp b/src/libs/libevs/lib_enc/nelp_enc_fx.cpp deleted file mode 100755 index d9ea5127..00000000 --- a/src/libs/libevs/lib_enc/nelp_enc_fx.cpp +++ /dev/null @@ -1,975 +0,0 @@ -/*==================================================================================== - EVS Codec 3GPP TS26.442 Apr 03, 2018. Version 12.11.0 / 13.6.0 / 14.2.0 - ====================================================================================*/ - -#include "control.h" -#include "options.h" /* Compilation switches */ -#include "cnst_fx.h" /* Common constants */ -#include "prot_fx.h" /* Function prototypes */ -#include "rom_com_fx.h" - - -#include "stl.h" - -/*===================================================================*/ -/* FUNCTION : quantize_uvg_fx() */ -/*-------------------------------------------------------------------*/ -/* PURPOSE : This function returns the quantized gain vector */ -/* and corresponding table indices, given the - input unquantized gain vector */ -/*-------------------------------------------------------------------*/ -/* INPUT ARGUMENTS : */ -/* _ (Word16*) G : Un-quantized gain vector (Q0) */ -/*-------------------------------------------------------------------*/ -/* OUTPUT ARGUMENTS : */ -/* _ (Word16) iG1 : UVG1CB_fx table index (Q0) */ -/* _ (Word16*) iG2 : UVG2CB_fx table indices (Q0) */ -/* _ (Word16*) quantG : Output quantized gain vector */ -/*-------------------------------------------------------------------*/ -/* INPUT/OUTPUT ARGUMENTS : */ -/* _ None. */ -/*-------------------------------------------------------------------*/ -/* RETURN ARGUMENTS : */ -/* _ None. */ -/*===================================================================*/ - -void quantize_uvg_fx(Word16 *G, Word16 *iG1, Word16 *iG2, Word16 *quantG, Word16 bwidth_fx) -{ - Word16 G1[2], G2[10],L16,L16_1; - Word16 i, j, k, ind,temp; - Word32 mmse; - Word16 exp,tmp,frac; - Word32 Lacc,Lexp[2],L_tmp; - const Word16 (*UVG1CB_fx)[2]=NULL; - const Word16 (*UVG2CB1_fx)[5]=NULL; - const Word16 (*UVG2CB2_fx)[5]=NULL; - test(); - IF( sub(bwidth_fx,NB)== 0 ) - { - UVG1CB_fx = UVG1CB_NB_FX; - move16();/*Q13 */ - UVG2CB1_fx = UVG2CB1_NB_FX; - move16();/*Q12 */ - UVG2CB2_fx = UVG2CB2_NB_FX; - move16();/*Q12 */ - } - ELSE IF( sub(bwidth_fx,WB) == 0 || sub(bwidth_fx,SWB) == 0) - { - UVG1CB_fx = UVG1CB_WB_FX; - move16();/*Q13 */ - UVG2CB1_fx = UVG2CB1_WB_FX; - move16();/*Q12 */ - UVG2CB2_fx = UVG2CB2_WB_FX; - move16();/*Q12 */ - } - - - FOR (i=0; i<2; i++) - { - Lacc = L_deposit_l(0); - FOR (j=0; j<5; j++) - { - ind=add(shr(extract_l(L_mult(i,5)),1),j); - Lacc=L_mac0(Lacc,G[ind],G[ind]); /*Q0 */ - } - - IF (Lacc==0) - { - Lacc = L_deposit_l(1); /* to avoid log10(0) */ - } - - /*G1[i] = (float) log10(sqrt(G1[i]/5)); */ - L_tmp = Mult_32_16(Lacc,13108); - IF(L_tmp) - { - exp = norm_l(L_tmp); - frac = Log2_norm_lc(L_shl(L_tmp,exp)); - exp = (30-exp-1); - move16();/*(+1)=/2 in log */ - L_tmp = Mpy_32_16(exp,frac,4932); /*Q16 ; 0.5*log10(2) in Q15 */ - G1[i]= round_fx(L_shl(L_tmp,13)); /*Q13 */ - } - ELSE - { - G1[i] = 0; - move16(); - } - - } - - - mmse = L_add(MAX_32, 0); - *iG1=0; - move16(); - FOR (i=0; i< UVG1_CBSIZE; i++) - { - L16 = shr(sub(G1[0],UVG1CB_fx[i][0]),1); /* Q12 */ - L16_1 = shr(sub(G1[1],UVG1CB_fx[i][1]),1); /* Q12 */ - Lacc = 0; - Lacc = L_mac0(Lacc,L16,L16); /*Q24 */ - Lacc = L_mac0(Lacc,L16_1,L16_1);/*Q24 */ - - IF (L_sub(Lacc,mmse)<0) - { - *iG1 = i; - move16(); - mmse = Lacc; - } - - } - - L_tmp = L_mult0(UVG1CB_fx[*iG1][0], 27213);/*Q26 */ - L_tmp = L_shr(L_tmp, 10); /* From Q26 to Q16 */ - frac = L_Extract_lc(L_tmp, &exp); /* Extract exponent of L_tmp */ - L_tmp = Pow2(30, frac); - exp = exp-30; /*move16(); */ - Lexp[0] = L_shl(L_tmp,exp +15 ); - - - L_tmp = L_mult0(UVG1CB_fx[*iG1][1], 27213);/*Q26 */ - L_tmp = L_shr(L_tmp, 10); /* From Q26 to Q16 */ - frac = L_Extract_lc(L_tmp, &exp); /* Extract exponent of L_tmp */ - L_tmp = Pow2(30, frac); - exp = exp-30; /*move16(); */ - Lexp[1] = L_shl(L_tmp,exp +15 ); - - - FOR (i=0; i<2; i++) - { - FOR (j=0; j<5; j++) - { - exp = norm_l(Lexp[i]); - tmp = extract_h(L_shl(Lexp[i],exp)); - exp = sub(sub(30,exp),15); - tmp = div_s(16384,tmp); /*Q(15+exp) */ - L_tmp = L_shr(L_mult0(G[i*5+j],tmp),exp+3); /*Q12 */ - G2[i*5+j] = extract_l(L_tmp); /*Q12 */ - } - } - - - FOR (i=0; i<2; i++) - { - mmse=MAX_32; - iG2[i]=0; - FOR (j=0; jrf_mode; - - if (sub(st_fx->last_nelp_mode_fx,1) == 0 && sub(st_fx->bwidth_fx, st_fx->last_bwidth_fx) != 0) - { - st_fx->last_nelp_mode_fx = 0; - } - - qIn = *qIn1; - move16(); - test(); - IF (sub(st_fx->bwidth_fx,NB) == 0) - { - IF (st_fx->last_nelp_mode_fx != 1) - { - BP1_ORDER = 7; - move16(); - set32_fx(st_fx->bp1_filt_mem_nb_fx, 0, BP1_ORDER*2); - st_fx->qprevGain_fx = 0; - move16(); - } - } - ELSE IF (sub(st_fx->bwidth_fx,WB) == 0 || sub(st_fx->bwidth_fx,SWB) == 0) - { - IF (st_fx->last_nelp_mode_fx != 1) - { - BP1_ORDER =4; - move16(); - set16_fx(st_fx->bp1_filt_mem_wb_fx, 0, BP1_ORDER*2); - } - } - - IF (st_fx->last_nelp_mode_fx != 1) - { - test(); - IF (st_fx->bwidth_fx == WB || sub(st_fx->bwidth_fx,SWB) == 0) - { - set16_fx(st_fx->shape1_filt_mem_fx, 0, 10); - set16_fx(st_fx->shape2_filt_mem_fx, 0, 10); - set16_fx(st_fx->shape3_filt_mem_fx, 0, 10); - set16_fx(st_fx->txlpf1_filt1_mem_fx, 0, 10); - set16_fx(st_fx->txlpf1_filt2_mem_fx, 0, 10); - set16_fx(st_fx->txhpf1_filt1_mem_fx, 0, 10); - set16_fx(st_fx->txhpf1_filt2_mem_fx, 0, 10); - st_fx->qprevIn_fx = 0; - move16(); - st_fx->qprevGain_fx = 0; - move16(); - } - } - - /* Start Unvoiced/NELP Processing */ - test(); - IF ( sub(st_fx->bwidth_fx,WB) == 0 || sub(st_fx->bwidth_fx,SWB) == 0) - { - qE1 = qIn; - move16(); - E1_fx = L_deposit_l(0); - FOR (i=0 ; itxlpf1_filt1_mem_fx, 10, (qf-st_fx->qprevIn_fx)); - pz_filter_sp_fx(txlpf1_num_coef_fx,txlpf1_den_coef_fx, in_fx, filtRes_fx, st_fx->txlpf1_filt1_mem_fx,10,10, L_FRAME, 3);/*1 = (16-qformat of shape1 cofficient) */ - - qEL1 = qf; - move16(); - EL1_fx = L_deposit_l(0); - FOR (i=0 ; itxhpf1_filt1_mem_fx, 10, qf-st_fx->qprevIn_fx); - pz_filter_sp_fx(txhpf1_num_coef_fx,txhpf1_den_coef_fx, in_fx, filtRes_fx, st_fx->txhpf1_filt1_mem_fx,10,10, L_FRAME, 3);/*1 = (16-qformat of shape1 cofficient) */ - st_fx->qprevIn_fx = qf; - move16(); - - qEH1 = qf; - move16(); - EH1_fx = L_deposit_l(0); - FOR (i=0 ; ilast_nelp_mode_fx != 1) /* if prev frame was not NELP then init mem*/ - { - st_fx->nelp_gain_mem_fx = Gains_fx[0]; - move16(); - qNelpGain = qGain; - move16(); - } - - /* tmp = (float) (20.0 * (log10 (Gains[0]) - log10 (st->nelp_gain_mem) ) ); */ - /* var_dB = tmp * tmp; */ - L_tmp = L_deposit_l(Gains_fx[0]); - L_tmp = L_max(L_tmp,1); - exp2 = norm_l(L_tmp); - L_tmp = L_shl(L_tmp, exp2);/*15+qEL1-qEL2-exp1+exp2 */ - exp2 = 30-exp2-qGain; - move16(); - tmp1 = Log2_norm_lc(L_tmp); - Ltemp = Mpy_32_16(exp2, tmp1,9864); /*log(2) in Q13 format = Q0 format */ - /*tmp1 = round_fx(L_shl(Ltemp,12)); Q12 */ - - L_tmp = L_deposit_l(st_fx->nelp_gain_mem_fx); /*Q0 */ - L_tmp = L_max(L_tmp,1); - exp2 = norm_l(L_tmp); - L_tmp = L_shl(L_tmp, exp2);/*15+qEL1-qEL2-exp1+exp2 */ - exp2 = 30-exp2-qNelpGain; - move16(); - tmp2 = Log2_norm_lc(L_tmp); - Ltemp1 = Mpy_32_16(exp2, tmp2,9864); /*log(2) in Q13 format = Q0 format */ - Ltemp1 = L_sub(Ltemp, Ltemp1);/*Q16 */ - Ltemp = Mult_32_16(Ltemp1, 20480);/*Q11 (20 in Q10) */ - L_tmp = L_shl(Ltemp,12);/*Q23 */ - var_dB_fx = Mult_32_32(L_tmp, L_tmp);/*Q15 */ - - FOR (i = 1; i < 10; i++) - { - L_tmp = L_deposit_l(Gains_fx[i]); - L_tmp = L_max(L_tmp,1); - exp2 = norm_l(L_tmp); - L_tmp = L_shl(L_tmp, exp2);/*15+qEL1-qEL2-exp1+exp2 */ - exp2 = 30-exp2-qGain; - move16(); - tmp1 = Log2_norm_lc(L_tmp); - Ltemp = Mpy_32_16(exp2, tmp1,9864); /*log(2) in Q13 format = Q0 format */ - - L_tmp = L_deposit_l(Gains_fx[i-1]); /*Q0 */ - L_tmp = L_max(L_tmp,1); - exp2 = norm_l(L_tmp); - L_tmp = L_shl(L_tmp, exp2);/*15+qEL1-qEL2-exp1+exp2 */ - exp2 = 30-exp2-qGain; - move16(); - tmp2 = Log2_norm_lc(L_tmp); - Ltemp1 = Mpy_32_16(exp2, tmp2,9864); /*log(2) in Q13 format = Q0 format */ - Ltemp1 = L_sub(Ltemp, Ltemp1);/*Q16 */ - Ltemp = Mult_32_16(Ltemp1, 20480);/*Q11 (20 in Q10) */ - L_tmp = L_shl(Ltemp,12);/*Q23 */ - L_tmp = Mult_32_32(L_tmp, L_tmp);/*Q15 */ - var_dB_fx = L_add(L_tmp, var_dB_fx);/*Q15 */ - } - - IF (st_fx->last_nelp_mode_fx!=1) - { - /*var_dB *= 0.111f; */ - var_dB_fx = Mult_32_16(var_dB_fx, 3637); /*0.111 in Q15 */ - } - ELSE - { - /*var_dB *= 0.1f; */ - var_dB_fx = Mult_32_16(var_dB_fx, 3277); /*0.1 in Q15 */ - } - - max1 = 0; - move16(); - FOR(i = 0; i < 10; i++) - { - max1=s_max(max1, abs_s(Gains_fx[i])); - } - - qf=norm_s((Word16)max1); - test(); - IF((qf == 0)&&(((Word16)max1)==0)) - { - qf= 15; - move16(); - } - qf = sub(qf,1); - qGain = add(qGain,qf); - - Scale_sig(Gains_fx, 10, qf); - - L_tmp = L_sub(var_dB_fx, 655360); /* 20 in Q15 */ - Ltemp = L_shr_r(L_tmp, 2);/*Q15 */ - { - /*exp = pow(2, x*log2(e)) */ - L_tmp = Mult_32_16(Ltemp, 23637); /*15 + 14 -15 ->Q14 */ - L_tmp = L_shl(L_tmp, 2); /*Q16 */ - f_Noise = L_Extract_lc(L_tmp, &e_Noise); /*Q16 */ - etmp = extract_l(Pow2(14, f_Noise)); /* Put 14 as exponent */ - e_Noise = sub(e_Noise, 14); /* Retreive exponent of etmp */ - - - IF(e_Noise > 0) - { - L_tmp = L_shl(etmp,e_Noise); /* Result in Q30 */ - L_tmp = L_add(1, L_tmp); - - exp1 = norm_l(L_tmp); - tmp1 = extract_h(L_shl(L_tmp, exp1));/*exp1-16 */ - tmp1 = div_s(16384, tmp1);/*14-(exp1-16)-> 30+15-exp1 */ - fdbck_fx = mult(26870, tmp1);/*45-exp1+15-15=>45-exp1 */ - fdbck_fx = shr_r(fdbck_fx, 14); - exp1 = sub(31,exp1); - } - ELSE - { - L_tmp = L_shl(etmp,add(e_Noise, 14)); /* Result in Q30 */ - L_tmp = L_add(16384, L_tmp); - - exp1 = norm_l(L_tmp); - tmp1 = extract_h(L_shl(L_tmp, exp1));/*14+exp1-16 */ - tmp1 = div_s(16384, tmp1);/*14-(14+exp1-16)-> 16+15-exp1 */ - fdbck_fx = mult(26870, tmp1);/*31-exp1+15-15=>31-exp1 */ - exp1 = sub(31,exp1); - } - } - - IF(exp1 == 31) - { - L_const_1=0x7fffffff; - move32(); - } - ELSE - { - L_const_1 = L_shl(1, exp1); - } - - l_nelp_gain_mem = L_deposit_l(st_fx->nelp_gain_mem_fx); - IF(sub(qNelpGain,qGain) != 0) - { - l_nelp_gain_mem = L_shl(l_nelp_gain_mem, sub(qGain, qNelpGain)); - } - - FOR (i = 0; i < 10; i++) - { - /*Gains[i] = (float)((1.0f - fdbck) * Gains[i] + fdbck * st->nelp_gain_mem); */ - L_tmp = L_sub(L_const_1, L_deposit_l(fdbck_fx));/*31-exp1 */ - L_tmp = Mult_32_16(L_tmp, Gains_fx[i]);/*exp1+qGain-15=>exp1-15+qGain */ - Ltemp1 = Mult_32_16(l_nelp_gain_mem, fdbck_fx);/*exp1+qGain-15 */ - L_tmp = L_add(L_tmp, Ltemp1); - L_tmp = L_shr_r(L_tmp, (exp1-15)); - Gains_fx[i] = round_fx(L_shl(L_tmp,16)); - move16(); - l_nelp_gain_mem = L_tmp; - } - - st_fx->nelp_gain_mem_fx = round_fx(L_shl(l_nelp_gain_mem,16)); - - Scale_sig(&st_fx->nelp_gain_mem_fx, 1, -qGain); - Scale_sig(Gains_fx, 10, -qGain); - qGain =0; - move16(); - - quantize_uvg_fx(Gains_fx, &iG1_fx, iG2_fx, Gains_fx, st_fx->bwidth_fx); - - IF( sub(rf_flag,1) == 0 ) - { - st_fx->rf_indx_nelp_iG1[0] = iG1_fx; - st_fx->rf_indx_nelp_iG2[0][0] = iG2_fx[0]; - st_fx->rf_indx_nelp_iG2[0][1] = iG2_fx[1]; - } - ELSE - { - push_indice_fx( st_fx, IND_IG1, iG1_fx, 5); - push_indice_fx( st_fx, IND_IG2A, iG2_fx[0], 6 ); - push_indice_fx( st_fx, IND_IG2B, iG2_fx[1], 6 ); - } - - test(); - IF (sub(st_fx->bwidth_fx,WB) == 0 || sub(st_fx->bwidth_fx,SWB) == 0) - { - gain_fac_fx = 19005; - move16();/* 1.16f in Q14 */ - } - ELSE - { - gain_fac_fx = 22446; - move16(); /* 1.37f in Q14 */ - } - - /* Normalize Gains_fx[10] with headroom 4 */ - /* This fills up qGain with some new value */ - normalize_arr(Gains_fx, &qGain, 10, 4); - - generate_nelp_excitation_fx(&(st_fx->nelp_enc_seed_fx), Gains_fx, ptr_fx, gain_fac_fx); - test(); - IF (sub(st_fx->bwidth_fx,WB) == 0 || sub(st_fx->bwidth_fx,SWB) == 0) - { - BP1_ORDER = 4; - Scale_sig(st_fx->bp1_filt_mem_wb_fx, BP1_ORDER*2, qGain-st_fx->qprevGain_fx);/*qf-qAdj */ - pz_filter_sp_fx(bp1_num_coef_wb_fx,bp1_den_coef_wb_fx, ptr_fx, ptr_tmp_fx, st_fx->bp1_filt_mem_wb_fx, BP1_ORDER, BP1_ORDER, L_FRAME, 2); - Copy(ptr_tmp_fx,ptr_fx,L_FRAME); - } - ELSE IF (sub(st_fx->bwidth_fx,NB) == 0) - { - BP1_ORDER = 7; - move16(); - Scale_sig32(st_fx->bp1_filt_mem_nb_fx, BP1_ORDER*2, (qGain - st_fx->qprevGain_fx)); - pz_filter_dp_fx(bp1_num_coef_nb_fx_order7, bp1_den_coef_nb_fx_order7, ptr_fx, ptr_tmp_fx, st_fx->bp1_filt_mem_nb_fx, BP1_ORDER, BP1_ORDER, L_FRAME, (sub(16,BP1_COEF_NB_QF_ORDER7))); - Copy(ptr_tmp_fx,ptr_fx,L_FRAME); - - Scale_sig(ptr_fx, L_FRAME, -1); /* bring exc to qgain-1 */ - *qIn1 = qGain-1; /* use this temp only in the parent */ - } - - E3_fx = L_deposit_l(0); - FOR (i=0 ; ibwidth_fx == WB|| sub(st_fx->bwidth_fx,SWB) == 0) - { - Scale_sig(st_fx->shape1_filt_mem_fx, 10, (qGain-st_fx->qprevGain_fx)); - pz_filter_sp_fx(shape1_num_coef_fx,shape1_den_coef_fx, ptr_fx, ptr_tmp_fx, st_fx->shape1_filt_mem_fx,10,10, L_FRAME, 1);/*1 = (16-qformat of shape1 cofficient) */ - Copy(ptr_tmp_fx,ptr_fx,L_FRAME); - - qf = qGain; - move16(); - E2_fx = L_deposit_l(0); - FOR (i=0 ; i 30-qE1-exp1 */ - exp1 = sub(exp1, 30-qE1); - - L_tmp = L_deposit_h(tmp1); - L_tmp = Isqrt_lc(L_tmp, &exp1); - Ltemp = L_shl(L_tmp, sub(exp1, 12)); - R_fx = round_fx(Ltemp); - } - ELSE - { - exp1 = norm_l(E1_fx); - tmp1 = extract_h(L_shl(E1_fx, exp1));/*qE1+exp1-16 */ - tmp1 = div_s(16384, tmp1);/*14-(qE1+exp1-16)-> 30-qE1-exp1 */ - L_tmp = Mult_32_16(E2_fx, tmp1);/*qE2+30-qE1-exp1-15=>15+qE2-qE1-exp1 */ - - exp2 = norm_l(L_tmp); - L_tmp = L_shl(L_tmp, exp2);/*15+qE2-qE1-exp1+exp2 */ - exp2 = 30-(15+qE2-qE1-exp1+exp2); - move16(); - L_tmp = Isqrt_lc(L_tmp, &exp2);/*Q(31+exp2) */ - R_fx = round_fx(L_tmp); - exp1 = 31-exp2-16-7; - move16(); - } - - FOR (i=0; itxlpf1_filt2_mem_fx, 10, (qf1-st_fx->qprevGain_fx)); - - pz_filter_sp_fx(txlpf1_num_coef_fx,txlpf1_den_coef_fx, filtRes_fx, ptr_tmp_fx, st_fx->txlpf1_filt2_mem_fx,10,10, L_FRAME, 3);/*1 = (16-qformat of shape1 cofficient) */ - Copy(ptr_tmp_fx,filtRes_fx,L_FRAME); - - qEL2 = qf1; - move16(); - EL2_fx = L_deposit_l(0); - FOR (i=0; itxhpf1_filt2_mem_fx, 10, (qf-st_fx->qprevGain_fx)); - pz_filter_sp_fx(txhpf1_num_coef_fx,txhpf1_den_coef_fx, filtRes_fx, ptr_tmp_fx, st_fx->txhpf1_filt2_mem_fx,10,10, L_FRAME, 3);/*1 = (16-qformat of shape1 cofficient) */ - - Copy(ptr_tmp_fx,filtRes_fx,L_FRAME); - - qEH2 = qf; - move16(); - EH2_fx = L_deposit_l(0); - FOR (i=0; i 30-qEL2-exp1 */ - L_tmp = Mult_32_16(EL1_fx, tmp1);/*qEL1+30-qEL2-exp1-15=>15+qE1-qEL2-exp1 */ - - exp2 = norm_l(L_tmp); - L_tmp = L_shl(L_tmp, exp2);/*15+qEL1-qEL2-exp1+exp2 */ - exp2 = 30-(30+qEL1-qEL2-exp1+exp2); - move16(); - tmp1 = Log2_norm_lc(L_tmp); - Ltemp = Mpy_32_16(exp2, tmp1,9864); /*10*log(2) in Q15 format = Q0 format */ - tmp1 = round_fx(L_shl(Ltemp,12));/* Q12 */ - RL_fx = L_mult0(tmp1, 10); - } - - IF(EH2_fx==0) - { - exp2 = norm_l(EH2_fx); - L_tmp = L_shl(EH2_fx, exp2); - exp2 = 30-exp2-qEH2; - move16(); - tmp1 = Log2_norm_lc(L_tmp); - Ltemp = Mpy_32_16(exp2, tmp1,9864); /*10*log(2) in Q13 format = Q0 format */ - tmp1 = round_fx(L_shl(Ltemp,12));/* Q12 */ - RH_fx = L_mult0(tmp1, 10); - } - ELSE - { - exp1 = norm_l(EH2_fx); - tmp1 = extract_h(L_shl(EH2_fx, exp1));/*qEH2+exp1-16 */ - tmp1 = div_s(16384, tmp1);/*14-(qEH2+exp1-16)-> 30-qEH2-exp1 */ - L_tmp = Mult_32_16(EH1_fx, tmp1);/*15+qEH1-qEH2-exp1 */ - - exp2 = norm_l(L_tmp); - L_tmp = L_shl(L_tmp, exp2);/*15+qEH1-qEH2-exp1+exp2 */ - exp2 = 30-(30+qEH1-qEH2-exp1+exp2); - move16(); - tmp1 = Log2_norm_lc(L_tmp); - Ltemp = Mpy_32_16(exp2, tmp1,9864); /*10*log(2) in Q13 format = Q0 format */ - tmp1 = round_fx(L_shl(Ltemp,12));/* Q12 */ - RH_fx = L_mult0(tmp1, 10); - } - - fid = 0; - move16(); - IF (L_sub(RL_fx, -12288) < 0) /* -3 in Q12 */ - { - fid = 1; - move16(); - } - ELSE IF (L_sub(RH_fx, -12288) < 0) /* -3 in Q12 */ - { - fid = 2; - move16(); - } - - IF( rf_flag == 0 ) - { - - SWITCH(fid) - { - case 1: - /* Update other filter memory */ - Scale_sig(st_fx->shape3_filt_mem_fx, 10, (qGain-st_fx->qprevGain_fx)); - pz_filter_sp_fx(shape3_num_coef_fx,shape3_den_coef_fx, ptr_fx, filtRes_fx, st_fx->shape3_filt_mem_fx,10,10, L_FRAME, 1);/*1 = (16-qformat of shape1 cofficient) */ - - /* filter the residual to desired shape */ - Scale_sig(st_fx->shape2_filt_mem_fx, 10, (qGain-st_fx->qprevGain_fx)); - pz_filter_sp_fx(shape2_num_coef_fx,shape2_den_coef_fx, ptr_fx, ptr_tmp_fx, st_fx->shape2_filt_mem_fx,10,10, L_FRAME, 1);/*1 = (16-qformat of shape1 cofficient) */ - Copy(ptr_tmp_fx,ptr_fx,L_FRAME); - - BREAK; - case 2: - /* Update other filter memory */ - Scale_sig(st_fx->shape2_filt_mem_fx, 10, (qGain-st_fx->qprevGain_fx)); - pz_filter_sp_fx(shape2_num_coef_fx,shape2_den_coef_fx, ptr_fx, filtRes_fx, st_fx->shape2_filt_mem_fx,10,10, L_FRAME, 1);/*1 = (16-qformat of shape1 cofficient) */ - - /* filter the residual to desired shape */ - Scale_sig(st_fx->shape3_filt_mem_fx, 10, (qGain-st_fx->qprevGain_fx)); - pz_filter_sp_fx(shape3_num_coef_fx,shape3_den_coef_fx, ptr_fx, ptr_tmp_fx, st_fx->shape3_filt_mem_fx,10,10, L_FRAME, 1);/*1 = (16-qformat of shape1 cofficient) */ - - Copy(ptr_tmp_fx,ptr_fx,L_FRAME); - - BREAK; - default: - Scale_sig(st_fx->shape2_filt_mem_fx, 10, (qGain-st_fx->qprevGain_fx)); - pz_filter_sp_fx(shape2_num_coef_fx,shape2_den_coef_fx, ptr_fx, filtRes_fx, st_fx->shape2_filt_mem_fx,10,10, L_FRAME, 1);/*1 = (16-qformat of shape1 cofficient) */ - - Scale_sig(st_fx->shape3_filt_mem_fx, 10, (qGain-st_fx->qprevGain_fx)); - pz_filter_sp_fx(shape3_num_coef_fx,shape3_den_coef_fx, ptr_fx, filtRes_fx, st_fx->shape3_filt_mem_fx,10,10, L_FRAME, 1);/*1 = (16-qformat of shape1 cofficient) */ - - BREAK; - } - - qE2 = qGain; - move16(); - - E2_fx = L_deposit_l(0); - FOR (i=0 ; i 30-qE3-exp1 */ - exp1 = sub(exp1, 30-qE3); - - L_tmp = L_deposit_h(tmp1); - L_tmp = Isqrt_lc(L_tmp, &exp1); - Ltemp = L_shl(L_tmp, sub(exp1, 12)); - R_fx = round_fx(Ltemp); - } - ELSE - { - exp1 = norm_l(E3_fx); - tmp1 = extract_h(L_shl(E3_fx, exp1));/*qE3+exp1-16 */ - tmp1 = div_s(16384, tmp1);/*14-(qE3+exp1-16)-> 30-qE3-exp1 */ - L_tmp = Mult_32_16(E2_fx, tmp1);/*qE2+30-qE3-exp1-15=>15+qE2-qE3-exp1 */ - - exp2 = norm_l(L_tmp); - L_tmp = L_shl(L_tmp, exp2);/*15+qE2-qE3-exp1+exp2 */ - exp2 = 30-(15+qE2-qE3-exp1+exp2); - move16(); - L_tmp = Isqrt_lc(L_tmp, &exp2);/*Q(31+exp2) */ - R_fx = round_fx(L_tmp); - exp1 = 31-exp2-16-7; - move16(); - } - - FOR (i=0; irf_indx_nelp_fid[0] = fid; - move16(); - } - ELSE - { - push_indice_fx( st_fx, IND_NELP_FID, fid, 2 ); - } - } - - st_fx->qprevGain_fx = qGain; - move16(); - - IF( rf_flag == 0 ) - { - FOR (i = 0; i < L_FRAME; i++) - { - exc_fx[i] = ptr_fx[i]; - move16(); - } - } - - return; -} - - diff --git a/src/libs/libevs/lib_enc/nois_est.cpp b/src/libs/libevs/lib_enc/nois_est.cpp new file mode 100644 index 00000000..3a345da4 --- /dev/null +++ b/src/libs/libevs/lib_enc/nois_est.cpp @@ -0,0 +1,883 @@ +/*==================================================================================== + EVS Codec 3GPP TS26.443 Nov 13, 2018. Version 12.11.0 / 13.7.0 / 14.3.0 / 15.1.0 + ====================================================================================*/ + +#include +#include +#include "cnst.h" +#include "prot.h" + +/*-----------------------------------------------------------------* + * Local constants + *-----------------------------------------------------------------*/ + +#define ALPHA 0.1f + +#define COR_MIN8 0.65f +#define COR_MAX8 0.7f +#define TH_PC8 14 +#define TH_EPS8 10.4f +#define TH_STA8 5.0e5f +#define K_8 0.0091f +#define C_8 0.3185f +#define ALPHA_MAX8 0.999f +#define THR_NCHAR8 1.0f + +#define COR_MIN16 0.52f +#define COR_MAX16 0.85f +#define TH_PC16 4 +#define TH_EPS16 1.6f +/* 10.0e5f causes problems with music - as the noise estimate starts to track the music */ +#define TH_STA16 3.5e5f +#define K_16 0.0245f +#define C_16 -0.235f +#define ALPHA_MAX16 0.99f +#define THR_NCHAR16 1.0f + +#define TH_PC 12 +#define TH_PRED 0.8f +#define THR_SPDIV 5 + +#define HC_CNT 20 /* limit for harm corr count */ +#define HC_CNT_SLOW 80 /* limit for harm corr count slow */ +#define BCKR_SLOW_UPDATE_SCALE 0.1f /* step size for slow bckr update */ + +#define HE_LT_THR1 10.0f +#define HE_LT_THR2 30.0f +#define HE_LT_CNT 30 + +/*-----------------------------------------------------------------* + * noise_est_init() + * + * Initialization of Noise estimator + *-----------------------------------------------------------------*/ + +void noise_est_init( + float *totalNoise, /* o : noise estimate over all critical bands */ + short *first_noise_updt, /* o : noise update initialization flag */ + float bckr[], /* o : per band background noise energy estimate */ + float enrO[], /* o : per band old input energy */ + float ave_enr[], /* o : per band long-term average energies */ + short *pitO, /* o : open-loop pitch values from preceed. frame */ + short *aEn, /* o : noise adaptation hangover counter */ + short *st_harm_cor_cnt, /* i/o: 1st harm correlation timer */ + short *bg_cnt, /* i/o: pause burst length counter */ + float *lt_tn_track, + float *lt_tn_dist, + float *lt_Ellp_dist, + float *lt_haco_ev, + short *low_tn_track_cnt + ,float *Etot_st_est, + float *Etot_sq_st_est +) +{ + short i; + + for( i=0; i *Etot_h ) + { + *Etot_h = Etot; + } + *Etot_l += 0.08f; + + /* Could even be higher but it also delays first entry to DTX */ + if ( harm_cor_cnt > 50 ) + { + if ( ini_frame < min(150,MAX_FRAME_COUNTER-1) && + (*Etot_h - *Etot_lp) < 3.0f ) + { + *Etot_l += min(2,(*Etot_last-*Etot_l)*0.1f); + } + + /* Avoids large steps in short active segments */ + if ( *Etot_last - *Etot_l > HE_LT_THR2 && harm_cor_cnt > 250 ) + { + *Etot_l += (*Etot_last-*Etot_l)*0.02f; + } + else if ( (*Etot_last - *Etot_l) > HE_LT_THR1 ) + { + *Etot_l += 0.08f; + } + } + if ( Etot < *Etot_l ) + { + *Etot_l = Etot; + } + + if ( ini_frame < 100 && *Etot_l < *Etot_l_lp ) + { + *Etot_l_lp = 0.1f * *Etot_l + (1.0f - 0.1f) **Etot_l_lp; + } + else if ( ( harm_cor_cnt > HE_LT_CNT && (*Etot_last - *Etot_l) > HE_LT_THR2 ) || ( harm_cor_cnt > HE_LT_CNT && (ini_frame < 150 ) ) || + ( (*Etot_l_lp - *Etot_l) > HE_LT_THR2 ) ) + { + *Etot_l_lp = 0.03f * *Etot_l + (1.0f - 0.03f) **Etot_l_lp; + } + else + { + *Etot_l_lp = 0.02f * *Etot_l + (1.0f - 0.02f) **Etot_l_lp; + } + *sign_dyn_lp = 0.1f * (*Etot_h - *Etot_l) + (1.0f - 0.1f) **sign_dyn_lp; + } + + return; +} + +/*-----------------------------------------------------------------* + * noise_est_down() + * + * Down-ward noise udatation routine + * Total Noise computation, relative frame Energy computation + * Noise energy update - here, the energy is updated only if it is + * decreasing to improve noise suppression. Otherwise, the noise + * update is done on noise-only frames and this decision is made in + * nois_est() later in this file. + *-----------------------------------------------------------------*/ + +void noise_est_down( + const float fr_bands[], /* i : per band input energy (contains 2 vectors) */ + float bckr[], /* i/o: per band background noise energy estimate */ + float tmpN[], /* o : temporary noise update */ + float enr[], /* o : averaged energy over both subframes */ + const short min_band, /* i : minimum critical band */ + const short max_band, /* i : maximum critical band */ + float *totalNoise, /* o : noise estimate over all critical bands */ + const float Etot, /* i : Energy of current frame */ + float *Etot_last, /* i/o: Energy of last frame */ + float *Etot_v_h2 /* i/o: Energy variaions of noise frames */ +) +{ + const float *pt1, *pt2; + short i; + float Etot_v; + + /*-----------------------------------------------------------------* + * Estimate total noise energy + *-----------------------------------------------------------------*/ + + *totalNoise = 0.0f; + for( i = min_band; i <= max_band; i++ ) + { + *totalNoise += bckr[i]; + } + *totalNoise = 10.0f * (float)log10( *totalNoise ); + + /*-----------------------------------------------------------------* + * Average energy per frame for each frequency band + *-----------------------------------------------------------------*/ + + pt1 = fr_bands; + pt2 = fr_bands + NB_BANDS; + + for( i=0 ; i < NB_BANDS; i++ ) + { + enr[i] = 0.5f * ( *pt1++ + *pt2++ ); + } + + /*-----------------------------------------------------------------* + * Background noise energy update + *-----------------------------------------------------------------*/ + + for( i=0; i< NB_BANDS; i++ ) + { + tmpN[i] = (1-ALPHA) * bckr[i] + ALPHA * enr[i]; + if( tmpN[i] < bckr[i] ) + { + bckr[i] = tmpN[i]; /* Defend to increase noise estimate: keep as it is or decrease */ + } + } + + /*------------------------------------------------------------------* + * Energy variation update + *------------------------------------------------------------------*/ + + Etot_v = (float) fabs(*Etot_last - Etot); + *Etot_v_h2 = (1.0f-0.02f) **Etot_v_h2 + 0.02f * min(3.0f,Etot_v); + if (*Etot_v_h2 < 0.1f) + { + *Etot_v_h2 = 0.1f; + } + + return; +} + +/*-----------------------------------------------------------------* + * noise_est() + * + * Noise energy estimation (noise energy is updated in case of noise-only frame) + *-----------------------------------------------------------------*/ + +void noise_est( + Encoder_State *st, /* i/o: encoder state structure */ + const float tmpN[], /* i : temporary noise update */ + const short *pitch, /* i : open-loop pitch values for each half-frame */ + const float *voicing, /* i : normalized correlation for all half-frames */ + const float *epsP, /* i : LP prediction error energies */ + const float Etot, /* i : total channel E */ + const float relE, /* i : relative frame energy */ + const float corr_shift, /* i : normalized correlation correction */ + const float enr[], /* i : averaged energy over both subframes */ + float fr_bands[], /* i : spectrum per critical bands of the current frame */ + float *cor_map_sum, /* o : sum of correlation map from mult-harm analysis */ + float *sp_div, /* o : soectral diversity feature */ + float *non_staX, /* o : non-stationarity for sp/mus classifier */ + short *loc_harm, /* o : multi-harmonicity flag for UV classifier */ + const float *lf_E, /* i : per bin energy for low frequencies */ + short *st_harm_cor_cnt, /* i/o : 1st harm correlation timer */ + const float Etot_l_lp, /* i : Smoothed low energy */ + float *sp_floor /* o : noise floor estimate */ +) +{ + short i, tmp_pc, pc, spec_div, noise_char; + float alpha, th_eps, th_sta, non_sta, cor_min, cor_max; + float non_sta2, alpha2, sum_num, sum_den, *pt1, *pt2, ftemp, ftemp2, nchar_thr; + float updt_step,log_enr; + + short aE_bgd,sd1_bgd,bg_bgd2; + short tn_ini; + + float epsP_0_2,epsP_0_2_ad,epsP_0_2_ad_lp_max; + float epsP_2_16,epsP_2_16_dlp,epsP_2_16_dlp_max; + short PAU,BG_1,NEW_POS_BG; + + float haco_ev_max; + float Etot_l_lp_thr; + float comb_ahc_epsP,comb_hcm_epsP; + + short enr_bgd,cns_bgd,lp_bgd,ns_mask; + short lt_haco_mask, bg_haco_mask; + short SD_1,bg_bgd3,PD_1,PD_2,PD_3,PD_4,PD_5; + + float tmp_enr,tmp_ave,tmp_ave2; + float non_staB; + + float lim_Etot; + + /*-----------------------------------------------------------------* + * Initialization + *-----------------------------------------------------------------*/ + + st->ener_RAT = 10.0f * (float)log10( mean(lf_E, 8) ); + st->ener_RAT /= (Etot + 0.01f); + + if( st->ener_RAT < 0.0f ) + { + st->ener_RAT = 0.0f; + } + + if( st->ener_RAT > 1.0 ) + { + st->ener_RAT = 1.0f; + } + + /*-----------------------------------------------------------------* + * Set the threshold for eps & non_sta based on input sampling rate + * The reason is that in case of 8kHz sampling input, there is nothing + * between 4kHz-6.4kHz. In noisy conditions, this makes a fast + * transition even in noise-only parts, hence producing a "higher + * order" spectral envelope => the epsP ratio is much less effective. + *-----------------------------------------------------------------*/ + + if( st->input_bwidth != NB ) + { + /* WB input */ + th_eps = TH_EPS16; + th_sta = TH_STA16; + cor_min = COR_MIN16; + cor_max = COR_MAX16; + } + else + { + /* NB input */ + th_eps = TH_EPS8; + th_sta = TH_STA8; + cor_min = COR_MIN8; + cor_max = COR_MAX8; + } + + /*-----------------------------------------------------------------* + * Estimation of pitch stationarity + *-----------------------------------------------------------------*/ + + pc = (short)( abs(pitch[0] - st->pitO) + abs(pitch[1] - pitch[0]) ); + + if ( ( (voicing[0] + voicing[1] + voicing[2]) / 3.0f + corr_shift ) < cor_min ) + { + /* low correlation -> probably inactive signal */ + tmp_pc = TH_PC; + } + else + { + tmp_pc = pc; + } + + st->pitO = pitch[1]; + + /*-----------------------------------------------------------------* + * Multi-harmonic analysis + *-----------------------------------------------------------------*/ + + *loc_harm = multi_harm( st->Bin_E, st->old_S, st->cor_map, &st->multi_harm_limit, st->total_brate, + st->bwidth, &st->cor_strong_limit, &st->mean_avr_dyn, &st->last_sw_dyn, cor_map_sum, sp_floor ); + + /*-----------------------------------------------------------------* + * Detection of frames with non-stationary spectral content + *-----------------------------------------------------------------*/ + + /* weighted sum of spectral changes per critical bands */ + sum_num = 0; + sum_den = 0; + + pt1 = fr_bands + 10; + pt2 = st->fr_bands2 + 10; + for (i = 10; i <= st->max_band; i++) + { + if (*pt1 > *pt2) + { + sum_num += *pt1 **pt1 / *pt2; + sum_den += *pt1; + } + else + { + sum_num += *pt2 **pt2 / *pt1; + sum_den += *pt2; + } + + pt1++; + pt2++; + } + + /* calculation of spectral diversity */ + if (sum_num > THR_SPDIV * sum_den) + { + spec_div = 1; + } + else + { + spec_div = 0; + } + + *sp_div = sum_num / (sum_den + 1e-5f); + + /*-----------------------------------------------------------------* + * Detection of frames with high energy content in high frequencies + *-----------------------------------------------------------------*/ + + /* calculation of energy in first 10 critical bands */ + ftemp = sum_f( &fr_bands[st->min_band], 10 - st->min_band ); + + /* calculation of energy in the rest of bands */ + ftemp2 = sum_f( &fr_bands[10], st->max_band - 10 + 1 ); + + if ( ftemp < 1e2 || ftemp2 < 1e2 ) + { + ftemp2 = 0; + } + else + { + ftemp2 /= ftemp; + } + + if ( ftemp2 > 10 ) + { + ftemp2 = 10; + } + + /* update LT value of the final parameter */ + st->noise_char = M_ALPHA * st->noise_char + (1-M_ALPHA) * ftemp2; + + if( st->input_bwidth == NB ) + { + nchar_thr = THR_NCHAR8; + } + else + { + nchar_thr = THR_NCHAR16; + } + + if( st->noise_char > nchar_thr ) + { + noise_char = 1; + } + else + { + noise_char = 0; + } + + /* save the 2 last spectra per crit. bands for the future */ + mvr2r( st->fr_bands1, st->fr_bands2, NB_BANDS ); + mvr2r( fr_bands+NB_BANDS, st->fr_bands1, NB_BANDS ); + + /*-----------------------------------------------------------------* + * Non-stationarity estimation for each band (handicap high E frames in average computing) + *-----------------------------------------------------------------*/ + + /* set averaging factor */ + ftemp = relE; + if( ftemp < 0.0f ) + { + ftemp = 0.0f; + } + + alpha = 0.064f * ftemp + 0.75f; + + if( alpha > 0.999f ) + { + alpha = 0.999f; + } + + /* during significant attacks, replace LT energy by the */ + /* current energy - this will cause non_sta2 failures to occur in */ + /* different frames than non_sta failures */ + alpha2 = alpha; + if ( spec_div > 0) + { + alpha2 = 0.0f; + } + + /* calculate non-stationarity */ + non_sta = 1.0f; + non_sta2 = 1.0f; + *non_staX = 0.0f; + non_staB =0.0f; + for( i = st->min_band; i <= st->max_band; i++ ) + { + /* + 1.0f added to reduce sencitivity to non stationarity in low energies */ + tmp_enr = enr[i] + 1.0f; + if( non_sta <= th_sta ) /* Just to limit the saturation */ + { + tmp_ave = st->ave_enr[i] + 1.0f; + if( tmp_enr > tmp_ave ) + { + non_sta = non_sta * (tmp_enr / tmp_ave ); /* non_stationarity measure */ + } + else + { + non_sta = non_sta * (tmp_ave / tmp_enr ); /* non_stationarity measure */ + } + } + st->ave_enr[i] = alpha * st->ave_enr[i] + (1-alpha) * enr[i]; /* update long-term average */ + + /* calculation of another non-stationarity measure (following attacks) */ + if( non_sta2 <= th_sta ) + { + tmp_ave2 = st->ave_enr2[i] + 1.0f; + if( tmp_enr > tmp_ave2 ) + { + non_sta2 = non_sta2 * ( tmp_enr / tmp_ave2 ); + } + else + { + non_sta2 = non_sta2 * (tmp_ave2 / tmp_enr ); + } + } + + st->ave_enr2[i] = alpha2 * st->ave_enr2[i] + (1-alpha2) * enr[i]; + + /* calculate non-stationarity feature for speech/music classifier */ + if( i >= START_BAND_SPMUS && i < NB_BANDS_SPMUS+START_BAND_SPMUS ) + { + log_enr = (float)log(enr[i]); + if( log_enr > st->past_log_enr[i-START_BAND_SPMUS] ) + { + *non_staX += log_enr - st->past_log_enr[i-START_BAND_SPMUS]; + } + else + { + *non_staX += st->past_log_enr[i-START_BAND_SPMUS] - log_enr; + } + + st->past_log_enr[i-START_BAND_SPMUS] = log_enr; + } + /* calculate non-stationarity feature relative background */ + if (st->ini_frame < 100) + { + /* During init don't include updates */ + if ( i >= 2 && i <= 16 ) + { + non_staB += (float)fabs(log(enr[i] + 1.0f) - + log(E_MIN + 1.0f)); + } + } + else + { + /* After init compare with background estimate */ + if ( i >= 2 && i <= 16 ) + { + non_staB += (float)fabs(log(enr[i] + 1.0f) - + log(st->bckr[i] + 1.0f)); + } + } + if (non_staB >= 128) + { + non_staB = 32767.0/256.0f; + } + } + if ( Etot < -5.0f ) + { + non_sta = 1.0f; + non_sta2 = 1.0f; + } + + lim_Etot = max(20.0f,Etot); + + if ( st->ini_frame < 150 ) + { + /* Allow use of quicker filter during init - if needed */ + st->Etot_st_est = 0.25f * lim_Etot + (1.0f-0.25F) * st->Etot_st_est; + st->Etot_sq_st_est = 0.25f * lim_Etot * lim_Etot + (1.0f-0.25f) * st->Etot_sq_st_est; + } + else + { + st->Etot_st_est = 0.25f * lim_Etot + (1.0f-0.25f) * st->Etot_st_est; + st->Etot_sq_st_est = 0.25f * lim_Etot * lim_Etot + (1.0f-0.25f) * st->Etot_sq_st_est; + } + /*-----------------------------------------------------------------* + * Count frames since last correlation or harmonic event + *-----------------------------------------------------------------*/ + if ( Etot > 0 && + (*loc_harm > 0 || 0.5f * (voicing[0] + voicing[1]) > 0.85f) ) + + { + st->harm_cor_cnt = 0; + } + else + { + st->harm_cor_cnt += 1; + } + + if ( st->harm_cor_cnt > 1 && ( ( Etot < 15.0f ) || + ( st->ini_frame>10 && + ( Etot-st->Etot_lp ) > 7.0f ) + ) + ) + { + st->harm_cor_cnt = 1; + } + if ( st->harm_cor_cnt > 1 && + Etot > 30.0f && + (st->Etot_sq_st_est - st->Etot_st_est*st->Etot_st_est) > 8.0f) + { + st->harm_cor_cnt = max(1,(short) round_f( (float) st->harm_cor_cnt / 4.0f )) ; + } + + /*-----------------------------------------------------------------* + * Energy-based pause-length counter + *-----------------------------------------------------------------*/ + + if ( st->bg_cnt >= 0 && (Etot - st->Etot_l_lp) > 5 ) + { + /* probably speech burst */ + st->bg_cnt = -1; + } + else + { + if ( st->bg_cnt == -1 && (Etot - st->Etot_l_lp) < 5 ) + { + /* probably start of speech pause */ + st->bg_cnt = 0; + } + } + + if (st->bg_cnt >= 0) + { + st->bg_cnt += 1; + } + + /*-----------------------------------------------------------------* + * Linear predition efficiency 0 to 2 order + *-----------------------------------------------------------------*/ + + epsP_0_2 = max(0 , min(8, epsP[0] / epsP[2])); + st->epsP_0_2_lp = 0.15f * epsP_0_2 + (1.0f-0.15f) * st->epsP_0_2_lp; + epsP_0_2_ad = (float) fabs(epsP_0_2 - st->epsP_0_2_lp ); + if (epsP_0_2_ad < st->epsP_0_2_ad_lp) + { + st->epsP_0_2_ad_lp = 0.1f * epsP_0_2_ad + (1.0f - 0.1f) * st->epsP_0_2_ad_lp; + } + else + { + st->epsP_0_2_ad_lp = 0.2f * epsP_0_2_ad + (1.0f - 0.2f) * st->epsP_0_2_ad_lp; + } + epsP_0_2_ad_lp_max = max(epsP_0_2_ad,st->epsP_0_2_ad_lp); + + /*-----------------------------------------------------------------* + * Linear predition efficiency 2 to 16 order + *-----------------------------------------------------------------*/ + + epsP_2_16 = max(0 , min(8, epsP[2] / epsP[16])); + if (epsP_2_16 > st->epsP_2_16_lp) + { + st->epsP_2_16_lp = 0.2f * epsP_2_16 + (1.0f-0.2f) * st->epsP_2_16_lp; + } + else + { + st->epsP_2_16_lp = 0.03f * epsP_2_16 + (1.0f-0.03f) * st->epsP_2_16_lp; + } + st->epsP_2_16_lp2 = 0.02f * epsP_2_16 + (1.0f-0.02f) * st->epsP_2_16_lp2; + + epsP_2_16_dlp = st->epsP_2_16_lp-st->epsP_2_16_lp2; + + if (epsP_2_16_dlp < st->epsP_2_16_dlp_lp2 ) + { + st->epsP_2_16_dlp_lp2 = 0.02f * epsP_2_16_dlp + (1.0f-0.02f) * st->epsP_2_16_dlp_lp2; + } + else + { + st->epsP_2_16_dlp_lp2 = 0.05f * epsP_2_16_dlp + (1.0f-0.05f) * st->epsP_2_16_dlp_lp2; + } + + epsP_2_16_dlp_max = max(epsP_2_16_dlp,st->epsP_2_16_dlp_lp2); + + /*-----------------------------------------------------------------* + * long term extensions of frame features + *-----------------------------------------------------------------*/ + + st->lt_tn_track = 0.03f* (Etot - st->totalNoise < 10) + 0.97f*st->lt_tn_track; + st->lt_tn_dist = 0.03f* (Etot - st->totalNoise) + 0.97f*st->lt_tn_dist; + st->lt_Ellp_dist = 0.03f* (Etot - st->Etot_l_lp) + 0.97f*st->lt_Ellp_dist; + + if (st->harm_cor_cnt == 0) + { + st->lt_haco_ev = 0.03f + 0.97f*st->lt_haco_ev; + } + else + { + st->lt_haco_ev = 0.99f*st->lt_haco_ev; + } + + if (st->lt_tn_track<0.05f) + { + st->low_tn_track_cnt++; + } + else + { + st->low_tn_track_cnt=0; + } + + + /* update of the long-term non-stationarity measure (between 0 and 1) */ + if ( (non_sta > th_sta) || (*loc_harm > 0) ) + { + st->act_pred = M_GAMMA * st->act_pred + (1-M_GAMMA) * 1; + } + else + { + st->act_pred = M_GAMMA * st->act_pred + (1-M_GAMMA) * 0; + } + + /*-----------------------------------------------------------------* + * Increment/decrement counter for enabling background noise update + *-----------------------------------------------------------------*/ + if( ( (*st_harm_cor_cnt < 3*HC_CNT_SLOW ) && ( ( non_sta > th_sta ) || + ( tmp_pc < TH_PC ) || + ( noise_char > 0) ) + ) || + ( (st->ini_frame > 150) && (Etot - Etot_l_lp) > 10 ) || + ( 0.5f * (voicing[0]+voicing[1]) > cor_max ) || + ( epsP[2] / epsP[16] > th_eps ) || + ( *loc_harm > 0) || + ((st->act_pred > 0.8f) && (non_sta2 > th_sta)) + ) + + { + /* active signal present - increment counter */ + st->aEn = st->aEn + 2; + } + else + { + /* background noise present - decrement counter */ + st->aEn = st->aEn - 1; + } + + if( st->aEn > 6 ) + { + st->aEn = 6; + } + else if ( st->aEn < 0 ) + { + st->aEn = 0; + } + + /*--------------------------------------------------------------* + * Background noise update + * (if this is not noise-only frame, bckr has been already updated downwards in nois_est_down()) + *--------------------------------------------------------------*/ + /* Additional detectors */ + + comb_ahc_epsP = max(max(st->act_pred,st->lt_haco_ev),epsP_2_16_dlp); + comb_hcm_epsP = max(max(st->lt_haco_ev,epsP_2_16_dlp_max),epsP_0_2_ad_lp_max); + + haco_ev_max = max(*st_harm_cor_cnt==0,st->lt_haco_ev); + Etot_l_lp_thr = st->Etot_l_lp + (1.5f + 1.5f * (st->Etot_lp<50.0f))*st->Etot_v_h2; + + + enr_bgd = Etot < Etot_l_lp_thr; + cns_bgd = (epsP_0_2 > 7.95f) && (non_sta< 1e3f); + lp_bgd = epsP_2_16_dlp_max < 0.10f; + ns_mask = non_sta < 1e5f; + lt_haco_mask = st->lt_haco_ev < 0.5f; + bg_haco_mask = haco_ev_max < 0.4f; + + SD_1 = ( (epsP_0_2_ad > 0.5f) && (epsP_0_2 > 7.95f) ); + + bg_bgd3 = enr_bgd || ( ( cns_bgd || lp_bgd ) && ns_mask && lt_haco_mask && SD_1==0 ); + + PD_1 = (epsP_2_16_dlp_max < 0.10f ) ; + PD_2 = (epsP_0_2_ad_lp_max < 0.10f ) ; + PD_3 = (comb_ahc_epsP < 0.85f ); + PD_4 = comb_ahc_epsP < 0.15f; + PD_5 = comb_hcm_epsP < 0.30f; + + BG_1 = ( (SD_1==0) || (Etot < Etot_l_lp_thr) ) && bg_haco_mask && (st->act_pred < 0.85f) && (st->Etot_lp < 50.0f); + + PAU = (st->aEn==0) || ( (Etot < 55.0f) && (SD_1==0) && ( ( PD_3 && (PD_1 || PD_2 ) ) || ( PD_4 || PD_5 ) ) ); + + NEW_POS_BG = (PAU | BG_1) & bg_bgd3; + + /* Original silence detector works in most cases */ + aE_bgd = st->aEn == 0; + + /* When the signal dynamics is high and the energy is close to the background estimate */ + sd1_bgd = (st->sign_dyn_lp > 15) && (Etot - st->Etot_l_lp ) < 2*st->Etot_v_h2 && st->harm_cor_cnt > 20; + + /* init conditions steadily dropping act_pred and/or lt_haco_ev */ + tn_ini = st->ini_frame < 150 && st->harm_cor_cnt > 5 && + (Etot-st->Etot_lp) < 7 && + ( (st->act_pred < 0.59f && st->lt_haco_ev <0.23f ) || + st->act_pred < 0.38f || + st->lt_haco_ev < 0.15f || + non_staB < 50.0f || + aE_bgd + || ( Etot < 42.0f + && st->harm_cor_cnt > 10 + && st->lt_haco_ev <0.35f + && st->act_pred <0.8f ) + ); + /* Energy close to the background estimate serves as a mask for other background detectors */ + bg_bgd2 = Etot < Etot_l_lp_thr || tn_ini ; + + updt_step=0.0f; + if (( bg_bgd2 && ( aE_bgd || sd1_bgd || st->lt_tn_track >0.90f || NEW_POS_BG ) ) || + tn_ini ) + { + if( ( ( st->act_pred < 0.85f ) && + aE_bgd && + ( st->lt_Ellp_dist < 10 || sd1_bgd ) && st->lt_tn_dist<40 && + ( ( Etot - st->totalNoise ) < 10.0f ) ) || + ( st->first_noise_updt == 0 && st->harm_cor_cnt > 80 && aE_bgd && st->lt_aEn_zero > 0.5f ) || + ( tn_ini && ( aE_bgd || non_staB < 10.0 || st->harm_cor_cnt > 80 ) ) + ) + { + updt_step=1.0f; + st->first_noise_updt = 1; + for( i=0; i< NB_BANDS; i++ ) + { + st->bckr[i] = tmpN[i]; + } + } + else if ( ( ( st->act_pred < 0.80f ) && ( aE_bgd || PAU ) && st->lt_haco_ev < 0.10f ) || + ( ( st->act_pred < 0.70f ) && ( aE_bgd || non_staB < 17.0f ) && PAU && st->lt_haco_ev < 0.15f ) || + ( st->harm_cor_cnt > 80 && st->totalNoise > 5.0f && Etot < max(1.0f,Etot_l_lp + 1.5f* st->Etot_v_h2) ) || + ( st->harm_cor_cnt > 50 && st->first_noise_updt > 30 && aE_bgd && st->lt_aEn_zero>0.5f ) || + tn_ini + ) + { + updt_step=0.1f; + if ( !aE_bgd && + st->harm_cor_cnt < 50 && + ( st->act_pred > 0.6f || + ( !tn_ini && Etot_l_lp - st->totalNoise < 10.0f && non_staB > 8.0f ) ) ) + { + updt_step=0.01f; + } + if (updt_step > 0.0f ) + { + st->first_noise_updt = 1; + for( i=0; i< NB_BANDS; i++ ) + { + st->bckr[i] = st->bckr[i] + updt_step * (tmpN[i]-st->bckr[i]); + } + } + } + else if (aE_bgd || st->harm_cor_cnt > 100 ) + { + ( st->first_noise_updt) += 1; + } + } + else + { + /* If in music lower bckr to drop further */ + if ( st->low_tn_track_cnt > 300 && st->lt_haco_ev >0.9f && st->totalNoise > 0.0f) + { + updt_step=-0.02f; + for( i=0; i< NB_BANDS; i++ ) + { + if (st->bckr[i] > 2*E_MIN) + { + st->bckr[i] = 0.98f*st->bckr[i]; + } + } + } + } + st->lt_aEn_zero = 0.2f * (st->aEn==0) + (1-0.2f)*st->lt_aEn_zero; + return ; +} diff --git a/src/libs/libevs/lib_enc/nois_est_fx.cpp b/src/libs/libevs/lib_enc/nois_est_fx.cpp deleted file mode 100755 index ddcdc5d4..00000000 --- a/src/libs/libevs/lib_enc/nois_est_fx.cpp +++ /dev/null @@ -1,1721 +0,0 @@ -/*==================================================================================== - EVS Codec 3GPP TS26.442 Apr 03, 2018. Version 12.11.0 / 13.6.0 / 14.2.0 - ====================================================================================*/ - -#include -#include -#include "cnst_fx.h" -#include "prot_fx.h" -#include "stl.h" -#include "basop_util.h" - -/*-----------------------------------------------------------------* - * Local constants - *-----------------------------------------------------------------*/ - -#define ALPHA_FX 3277 /*.1 Q15*/ -#define ALPHAM1_FX 29491 /*.9 Q15*/ - -#define TH_PC_FX 12 /* max sum of pitch differencies */ - -#define BCKR_SLOW_UPDATE_SCALE_FX 3277 /*Q15 Step size for slow bckr update */ -#define COR_MIN16_FX 17039 /*.52 Q15 */ -#define COR_MAX16_FX 27853 /*.85 Q15 */ - -/* 10.0e5f causes problems with music - as the noise estimate starts to track the music */ -#define TH_STA16_FX (350000<<10) /* MODE1: 3.5e5f */ - -#define TH_EPS16_FX 3277 /* Q11 (1.6) tuned for speech only, not for music */ -#define K_16_FX 25690 /* Q20 (0.0245f) */ -#define C_16_FX -1925 /* Q13 (-0.235f) */ -#define ALPHA_MAX16_FX 32440 /* Q15 (0.99) */ - -#define COR_MIN8_FX 21299 /*.65 Q15 */ -#define COR_MAX8_FX 22938 /*.70 Q15 */ -#define TH_EPS8_FX 21299 /* 10.4 in Q11 Thresholds for NB processing - ... */ -#define TH_STA8_FX (500000<<10) -#define K_8_FX 9452 /* Q20 (0.0091f) */ -#define C_8_FX 2609 /* Q13 (0.0091f) */ -#define ALPHA_MAX8_FX 32735 /* Q15 (0.999) */ - -#define HC_CNT_SLOW_FX 80 /* limit for harm corr count slow */ - -#define HE_LT_CNT_PRE_FX 50 -#define HE_LT_CNT_INIT_FX 150 -#define HE_LT_CNT_PRE_SHORT_FX 250 -#define HE_LT_CNT_FX 30 - -#define LN_E_MIN_PLUS_ONE_FX 1 /* max(1, ln(E_MIN+1.0)) = max(1,ln(0.0035f+1f)) in Q8 */ -#define COR_MAX_NNE_FX 27853 /* 0.85 Q15 */ - -#define HE_LT_THR1_FX 2560 /*10.0 Q8*/ -#define HE_LT_THR2_FX 7680 /*30.0 Q8*/ - -/*-----------------------------------------------------------------* - * noise_est_AR1_Qx() - * - * y(n)(Qx) = alpha(Q15) * x(Qx) + (1.0f-alpha)* y(n-1) (Qx) - *-----------------------------------------------------------------*/ - -Word16 noise_est_AR1_Qx( /* o : Qx y(n) */ - Word16 x, /* i : Qx x(n) */ - Word16 y, /* i : Qx y(n-1) */ - Word16 alpha /*i : Q15 scaling of driving x(n) */ -) -{ - Word16 alpham1; - /*alpham1 = negate(add((Word16)-32768, alpha)); */ - alpham1 = sub(32767, alpha); /* one cycle less */ - - return mac_r(L_mult(y, alpham1), x, alpha); -} - -/*-----------------------------------------------------------------* - * noise_est_ln_q8_fx() - * - * q8 = (float)log( L_enr[i] + add1po*1.0 ); - *-----------------------------------------------------------------*/ - -static Word16 noise_est_ln_q8_fx( - Word32 L_enr, - Word16 flag_add1p0, /* flag to add 1.0 */ - Word16 q_new_plus_q_scale ) -{ - Word16 e_ener, f_ener; - Word32 L_tmp; - - L_tmp = L_add(L_enr, L_shl((Word32)1L, q_new_plus_q_scale)); /* +1.0f */ - if( flag_add1p0 == 0 ) - { - L_tmp = L_add(L_enr, 0); /* +0 , no offset */ - } - - L_tmp = L_max(L_tmp,(Word32)1L); /* make sure log2_norm_lc does not cause table reading out of bounds */ - - e_ener = norm_l(L_tmp); - f_ener = Log2_norm_lc(L_shl(L_tmp, e_ener)); - e_ener = sub(sub(30,e_ener),q_new_plus_q_scale); - L_tmp = Mpy_32_16(e_ener, f_ener, 22713); /* Q16 (22713 = Ln(2) in Q15)*/ - return round_fx(L_shl(L_tmp, 8)); /* Q8 */ -} - -/*-----------------------------------------------------------------* - * eps_quota_fx() - * - * - *-----------------------------------------------------------------*/ - -static Word32 eps_quota_fx( /* o: eps_num/eps_den in q_out */ - Word16 eps_num_h, /* num high ,*/ - Word16 eps_num_l, /* num low (signed) ,*/ - Word16 eps_den_h, /* den low */ - Word16 eps_den_l, /* den low (signed),*/ - Word16 q_out /* range 15...0 , tested with 11 and 12 */ -) -{ - Word32 L_tmp_num, L_tmp_den; - Word16 exp_num, exp_den; - Word16 m_num, m_den; - Word16 num_shift; - - - L_tmp_num = L_Comp(eps_num_h, eps_num_l); - L_tmp_den = L_Comp(eps_den_h, eps_den_l); - - exp_num = sub(norm_l(L_tmp_num), 1); /* make sure m_ num is lower than m_den */ - m_num = extract_h(L_shl(L_tmp_num, exp_num)); - exp_den = norm_l(L_tmp_den); - m_den = extract_h(L_shl(L_tmp_den, exp_den)); - - exp_num = sub(exp_num, exp_den); - if (m_den != 0) - { - assert(m_den >= m_num); - m_num = div_s(m_num, m_den); /* single basop */ - } - - num_shift = add(15-q_out, exp_num); - if (m_den == 0) - { - /* no division made due to zero denominator */ - m_num = 0; - move16(); - } - - return L_shr(m_num, num_shift); -} - -/*-----------------------------------------------------------------* - * noise_est_init_fx() - * - * Initialization of Noise estimator - *-----------------------------------------------------------------*/ - -void noise_est_init_fx( - Word16 *totalNoise, /* o : noise estimate over all critical bands */ - Word16 *first_noise_updt, /* o : noise update initialization flag */ - Word32 bckr[], /* o : per band background noise energy estimate */ - Word32 enrO[], /* o : per band old input energy */ - Word32 ave_enr[], /* o : per band long-term average energies */ - Word16 *pitO, /* o : open-loop pitch values from preceed. frame */ - Word16 *aEn, /* o : noise adaptation hangover counter */ - Word16 *st_harm_cor_cnt, /* i/o: 1st harm correlation timer */ - Word16 *bg_cnt, /* i/o: pause burst length counter */ - Word16 *lt_tn_track, /* Q15 */ - Word16 *lt_tn_dist, /* Q8 */ - Word16 *lt_Ellp_dist, /* Etot low lp same domain as *Etot_l_lp, Q8 */ - Word16 *lt_haco_ev, /* Q15 */ - Word16 *low_tn_track_cnt /* Q0 */ - ,Word16 *Etot_st_est, /* Q8 */ - Word16 *Etot_sq_st_est /* Q2 */ - -) -{ - Word16 i; - - FOR( i=0; i 0 ) - { - test(); - IF( ( sub( ini_frame_fx , s_min(HE_LT_CNT_INIT_FX ,MAX_FRAME_COUNTER-1) ) < 0 ) - && (sub(sub(*Etot_h, *Etot_lp),(Word16)3*256) < 0 ) /* 3.0 Q8 */ - ) - { - /* *Etot_l += min(2,(*Etot_last-*Etot_l)*0.1f); */ - tmp = mult_r(sub(*Etot_last, *Etot_l), 3277); /* factor in Q15 3277 .1*32768 */ - tmp = s_min(512, tmp); /* 2.0 in Q8 is 512*/ - *Etot_l = add(*Etot_l, tmp); - move16();/* Q8 */ - } - - /* Avoids large steps in short active segments */ - test(); - IF ( ( sub(sub(*Etot_last, *Etot_l), HE_LT_THR2_FX ) > 0 ) /* 30.0f*Q8 */ - && (sub(harm_cor_cnt,HE_LT_CNT_PRE_SHORT_FX)>0) - ) - { - /* *Etot_l += (*Etot_last-*Etot_l)*0.02f; */ - *Etot_l = add(*Etot_l, mult_r(sub(*Etot_last, *Etot_l), 655)); - move16();/* 0.02 = 655 Q8*/ - } - ELSE IF (sub(sub(*Etot_last, *Etot_l), HE_LT_THR1_FX ) > 0) /* 10.0 in Q8*/ - { - *Etot_l = add(*Etot_l, 20); - move16();/* 0.08 is 20 in Q8*/ - } - - } - - *Etot_l = s_min(*Etot_l, Etot); - - IF ( sub(ini_frame_fx,100)<0 && sub(*Etot_l,*Etot_l_lp)<0 ) - { - /**Etot_l_lp = 0.1f * *Etot_l + (1.0f - 0.1) * *Etot_l_lp; */ - *Etot_l_lp = mac_r(L_mult(3277, *Etot_l), 29491, *Etot_l_lp); - move16(); - } - ELSE - { - test(); - test(); - test(); - test(); - IF ( ( (sub(harm_cor_cnt, HE_LT_CNT_FX) > 0 ) - && (sub(sub(*Etot_last, *Etot_l), HE_LT_THR2_FX ) > 0 ) - ) - || ( sub(harm_cor_cnt, HE_LT_CNT_FX > 0 ) && (sub(ini_frame_fx, HE_LT_CNT_INIT_FX) < 0 ) ) - || (sub(sub(*Etot_l_lp, *Etot_l), HE_LT_THR2_FX ) > 0 ) - ) - { - /**Etot_l_lp = 0.03f * *Etot_l + (1.0f - 0.03f) * *Etot_l_lp; */ - *Etot_l_lp = mac_r(L_mult(983, *Etot_l), 31785, *Etot_l_lp); - move16(); - - } - ELSE - { - /* *Etot_l_lp = 0.02f * *Etot_l + (1.0f - 0.02f) * *Etot_l_lp; */ - *Etot_l_lp = round_fx(L_mac(L_mult(655 , *Etot_l), 32113 , *Etot_l_lp )); - } - } - /**sign_dyn_lp = 0.1f * (*Etot_h - *Etot_l) + (1.0f - 0.1f) * *sign_dyn_lp;*/ - *sign_dyn_lp = round_fx(L_mac(L_mult(3277, sub(*Etot_h, *Etot_l)), 29491, *sign_dyn_lp)); - } - - return; -} - -/*==================================================================================*/ -/* FUNCTION : noise_est_down_fx() */ -/*----------------------------------------------------------------------------------*/ -/* PURPOSE : Down-ward noise udatation routine */ -/*----------------------------------------------------------------------------------*/ -/* INPUT ARGUMENTS : */ -/* _ (Word32[]) fr_bands : per band input energy Q_new+QSCALE */ -/* _ (Word32[]) bckr : per band background noise energy estimate Q_new+QSCALE */ -/* _ (Word16 ) min_band : minimum critical band Q0 */ -/* _ (Word16 ) max_band : maximum critical band Q0 */ -/* _ (Word32[]) bckr_he : per band background noise energy estimate Q_new+QSCALE */ -/* _ (Word16 ) Etot : Energy of current frame Q8 */ -/* _ (Word16* ) Etot_last : Energy of last frame Q8 */ -/* _ (Word16* ) Etot_v_h2 : Energy variaions of noise frames Q8 */ -/* _ (Word16 ) Q_new : Qformat */ -/*----------------------------------------------------------------------------------*/ -/* OUTPUT ARGUMENTS : */ -/* _ (Word32[]) bckr : per band background noise energy estimate Q_new+QSCALE */ -/* _ (Word32[]) tmpN : temporary noise update Q_new+QSCALE */ -/* _ (Word32[]) enr : averaged energy over both subframes Q_new+QSCALE */ -/* _ (Word16* ) totalNoise : noise estimate over all critical bands Q8 */ -/* _ (Word16 ) Etot : Energy of current frame Q8 */ -/* _ (Word16* ) Etot_last : Energy of last frame Q8 */ -/* _ (Word16* ) Etot_v_h2 : Energy variaions of noise frames Q8 */ -/* _ (Word32[]) tmpN_he1 : temporary noise update 1 Q_new+QSCALE */ -/*----------------------------------------------------------------------------------*/ - - -void noise_est_down_fx( - const Word32 fr_bands[], /* i : per band input energy (contains 2 vectors) */ - Word32 bckr[], /* i/o: per band background noise energy estimate */ - Word32 tmpN[], /* o : temporary noise update */ - Word32 enr[], /* o : averaged energy over both subframes */ - const Word16 min_band, /* i : minimum critical band */ - const Word16 max_band, /* i : maximum critical band */ - Word16 *totalNoise, /* o : noise estimate over all critical bands */ - Word16 Etot, /* i : Energy of current frame */ - Word16 *Etot_last, /* i/o: Energy of last frame Q8 */ - Word16 *Etot_v_h2, /* i/o: Energy variations of noise frames Q8 */ - Word16 Q_new, - const Word32 e_min /* i : minimum energy scaled Q_new + QSCALE */ -) - -{ - Word32 Ltmp, L_tmp; - const Word32 *pt1, *pt2; - Word16 i; - Word16 e_Noise, f_Noise; - Word16 scale; - Word32 totalNoise_temp; - Word32 L_Etot, L_Etot_last, L_Etot_v_h2, L_Etot_v; - - L_Etot = L_shl(Etot, 16); /*Q24 for later AR1 computations*/ - L_Etot_last = L_shl(*Etot_last, 16); - L_Etot_v_h2 = L_shl(*Etot_v_h2, 16); - scale = add(Q_new,QSCALE); - move16(); - - /*-----------------------------------------------------------------* - * Estimate total noise energy - *-----------------------------------------------------------------*/ - - totalNoise_temp = L_deposit_l(0); - FOR (i = min_band; i <= max_band; i++) - { - totalNoise_temp = L_add(totalNoise_temp, bckr[i]); /*Q_new+QSCALE*/ - } - totalNoise_temp = L_max(totalNoise_temp,L_shl(e_min,4)); - - - totalNoise_temp = L_max(totalNoise_temp,(Word32)1L); /* make sure log2_norm_lc does not cause table reading out of bounds */ - - /*totalNoise = 10.0f * (float)log10( *totalNoise );*/ - e_Noise = norm_l(totalNoise_temp); - f_Noise = Log2_norm_lc(L_shl(totalNoise_temp, e_Noise)); - e_Noise = sub(30, e_Noise); - e_Noise = sub(e_Noise, scale); - Ltmp = Mpy_32_16(e_Noise, f_Noise, LG10); - *totalNoise = round_fx(L_shl(Ltmp, 10)); /*Q8*/ - - /*-----------------------------------------------------------------* - * Average energy per frame for each frequency band - *-----------------------------------------------------------------*/ - - pt1 = fr_bands; /*Q_new+QSCALE*/ - pt2 = fr_bands + NB_BANDS; - - FOR( i=0 ; i < NB_BANDS; i++ ) - { - Ltmp = L_add(L_shr_r(*pt1,1),L_shr_r(*pt2,1)); - /*Ltmp = L_shr_r(L_add(*pt1,*pt2),1);*/ - enr[i] = Ltmp; - move32();/*Q_new+QSCALE*/ - pt1++; - pt2++; - } - - /*-----------------------------------------------------------------* - * Background noise energy update - *-----------------------------------------------------------------*/ - - FOR( i=0; i< NB_BANDS; i++ ) - { - /* tmpN[i] = (1-ALPHA) * bckr[i] + ALPHA * enr[i]; */ - L_tmp = Mult_32_16(enr[i], ALPHA_FX); /*ALPHA * enr2*/ - tmpN[i] = Madd_32_16(L_tmp, bckr[i], ALPHAM1_FX); - move32();/*Q_new+QSCALE*/ - tmpN[i] =L_max( tmpN[i] , e_min); /* handle div by zero in find_tilt_fx */ - - /* if( tmpN[i] < bckr[i] ) { bckr[i] = tmpN[i]; }*/ - /* Defend to increase noise estimate: keep as it is or decrease */ - bckr[i] = L_max(L_min(bckr[i], tmpN[i]), e_min); - move32();/*Q_new+QSCALE*/ - } - - /*------------------------------------------------------------------* - * Energy variation update - *------------------------------------------------------------------*/ - /*Etot_v = (float) fabs(*Etot_last - Etot);*/ - L_Etot_v = L_abs(L_sub(L_Etot_last, L_Etot)); /* Q24 */ - - /* *Etot_v_h2 = (1.0f-0.02f) * *Etot_v_h2 + 0.02f * min(3.0f, Etot_v); */ - L_Etot_v_h2 = Mult_32_16(L_Etot_v_h2, 32113); /*.98 in Q15 , Q24+Q15+1 -16 => Q24 */ - L_Etot_v = L_min((Word32)(3*(1<<24)), L_Etot_v); - L_tmp = Mult_32_16(L_Etot_v, 655); /*.02 in Q15 , Q24+Q15+1 -16 ==> Q24 ) */ - - *Etot_v_h2 = round_fx(L_add(L_Etot_v_h2, L_tmp)); /*Q24->Q8*/ - - /* if (*Etot_v_h2 < 0.1f) { *Etot_v_h2 = 0.1f; } */ - *Etot_v_h2 = s_max(*Etot_v_h2, 26 ); /* 0.1 in Q8*/ - - return; -} - -/*-----------------------------------------------------------------* -* noise_est_fx() -* -* Noise energy estimation (noise energy is updated in case of noise-only frame) -*-----------------------------------------------------------------*/ -void noise_est_fx( - Encoder_State_fx *st_fx, /* i/o: state structure */ - const Word32 tmpN[], /* i : temporary noise update Q_new + QSCALE */ - const Word16 *pit, /* i : open-loop pitch values for each half-frame Q0 */ - const Word16 cor[], /* i : normalized correlation for all half-frames Q15 */ - const Word16 epsP_h[], /* i : msb prediction error energies Q_r-1 */ - const Word16 epsP_l[], /* i : msb prediction error energies Q_r-1 */ - const Word16 Etot, /* i : total channel E (see find_enr_fx.c) Q8 */ - const Word16 relE, /* i : (VA_CHECK addition) relative frame energy Q8? */ - const Word16 corr_shift, /* i : normalized correlation correction Q15 */ - const Word32 enr[], /* i : averaged energy over both subframes Q_new + Q_SCALE */ - Word32 fr_bands[], /* i : spectrum per critical bands of the current frame Q_new + Q_SCALE */ - Word16 *cor_map_sum, /* o : Q8 */ - Word16 *sp_div, /* o : Q_sp_div */ - Word16 *Q_sp_div, /* o : Q factor for sp_div */ - Word16 *non_staX, /* o : non-stationarity for sp/mus classifier */ - Word16 *loc_harm , /* o : multi-harmonicity flag for UV classifier */ - const Word32 *lf_E, /* i : per bin energy for low frequencies Q_new + Q_SCALE -2 */ - Word16 *st_harm_cor_cnt, /* i/o : 1st harm correlation timer Q0 */ - const Word16 Etot_l_lp, /* i : Smoothed low energy Q8 */ - const Word16 Etot_v_h2, /* i : Energy variations Q8 */ - Word16 *bg_cnt, /* i : Background burst length timer Q0 */ - Word16 EspecdB[], /* i/o: log E spectrum (with f=0) of the current frame Q7 for multi harm */ - Word16 Q_new, /* i : SCaling of current frame */ - const Word32 Le_min_scaled, /*i : Minimum energy value in Q_new + Q_SCALE */ - Word16 *sp_floor /* o : noise floor estimate Q7 */ -) -{ - Word16 alpha, alpha2, alpha2m1, alpham1; - Word16 cor_min, cor_max, num, den, ExpNum, ExpDen, noise_chartmp; - Word16 wtmp1,wtmp, ExpLmax, ExpLmax2, tmpExp, nchar_thr, cor_tmp; - Word16 i, tmp_pc, pc,th_eps; - Word32 th_sta, Lnum, Lden, non_sta, LepsP, Ltmpden; - Word16 e_ener, f_ener; - Word32 Ltmp, Ltmp1,Lsum_num, Lsum_den, *pt1, *pt2,Ltmp2, Lnon_sta2; - Word16 spec_div, noise_char; - Word16 log_enr16; - Word16 updt_step ; /* Q15 */ - Word16 aE_bgd,sd1_bgd,bg_bgd2; - Word16 tn_ini; - Word16 epsP_0_2,epsP_0_2_ad,epsP_0_2_ad_lp_max; - Word16 epsP_2_16,epsP_2_16_dlp,epsP_2_16_dlp_max; - Word16 PAU, BG_1, NEW_POS_BG; - - Word16 haco_ev_max; - Word16 Etot_l_lp_thr; - Word16 comb_ahc_epsP, comb_hcm_epsP; - - Word16 enr_bgd,cns_bgd,lp_bgd,ns_mask; - Word16 lt_haco_mask, bg_haco_mask; - Word16 SD_1,SD_1_inv, bg_bgd3,PD_1,PD_2,PD_3,PD_4,PD_5; - - Word16 non_staB; /* Q8 */ - Word32 L_tmp_enr, L_tmp_ave_enr, L_tmp_ave_enr2; - Word16 tmp_Q; - Word16 tmp, tmp2; /* general temp registers */ - Word16 tmp_enr, tmp_floor ; /* constants in Q8 */ - Word16 vad_bwidth_fx; /* vad ns control variabel for input bwidth from teh BWD */ - /* for DTX operation */ - Word16 vad_2nd_stage_fx; - - Word16 lim_Etot_fx; /* Q8 */ - Word16 lim_Etot_sq_fx; /* Q2 */ - Word16 st_E_var_est_fx; /* Q2 */ - - /*-----------------------------------------------------------------* - * Initialization - *-----------------------------------------------------------------*/ - - vad_bwidth_fx = st_fx->input_bwidth_fx; - move16(); - - /*st_fx->ener_RAT = 10.0f * (float)log10( mean(lf_E, 8));*/ - Ltmp = L_shr(lf_E[0],3); - FOR(i = 1; i < 8; i++) - { - Ltmp = L_add(Ltmp, L_shr(lf_E[i],3)); - } - Ltmp = L_max(Ltmp,(Word32)1L); /* make sure log2_norm_lc does not cause table reading out of bounds */ - e_ener = norm_l(Ltmp); - f_ener = Log2_norm_lc(L_shl(Ltmp, e_ener)); - e_ener = sub(30, e_ener); - e_ener = sub(e_ener, sub(add(Q_new,QSCALE),2)); - Ltmp = Mpy_32_16(e_ener, f_ener, LG10); - wtmp = round_fx(L_shl(Ltmp, 10));/*Q8*/ - - /* st_fx->ener_RAT /= (Etot + 0.01f); */ - wtmp1 = add(Etot,3);/*3 is 0.01 in Q8 */ - /* st_fx->ener_RAT_fx = wtmp/wtmp1 */ - st_fx->ener_RAT_fx = 0; - move16(); - IF( wtmp > 0 ) - { - st_fx->ener_RAT_fx = 32767; - move16(); /*Q15*/ - if(sub(wtmp1, wtmp ) >= 0 ) - { - st_fx->ener_RAT_fx = div_s(wtmp, wtmp1); /*Q15*//* wtmp1 gte than wtmp */ - } - } - - /*-----------------------------------------------------------------* - * Set the threshold for eps & non_sta based on input sampling rate - * The reason is that in case of 8kHz sampling input, there is nothing - * between 4kHz-6.4kHz. In noisy conditions, this makes a fast - * transition even in noise-only parts, hence producing a "higher - * order" spectral envelope => the epsP ratio is much less effective. - *-----------------------------------------------------------------*/ - - IF (sub(vad_bwidth_fx,NB) != 0) /* WB input */ - { - th_eps = TH_EPS16_FX; - move16();/*Q11*/ - th_sta = TH_STA16_FX; - move16();/*Q10 */ - cor_min = COR_MIN16_FX; - move16();/*Q15*/ - cor_max = COR_MAX16_FX; - move16();/*Q15*/ - } - ELSE /* NB input */ - { - th_eps = TH_EPS8_FX; - move16();/* Q11 */ - th_sta = TH_STA8_FX; - move16(); /* Q10 */ - cor_min = COR_MIN8_FX; - move16(); - cor_max = COR_MAX8_FX; - move16(); - } - - - /*-----------------------------------------------------------------* - * Estimation of pitch stationarity - *-----------------------------------------------------------------*/ - - /* pc = abs(pit[0] - pitO) + abs(pit[1] - pit[0]) */ /* needed in signal_clas() */ - wtmp = abs_s(sub(pit[0], st_fx->pitO_fx)); - wtmp1 = abs_s(sub(pit[1], pit[0])); - pc = add(wtmp, wtmp1); - - - Ltmp = L_deposit_h(corr_shift); - Ltmp = L_mac(Ltmp, cor[0], 10923); - Ltmp = L_mac(Ltmp, cor[1], 10923); - wtmp = mac_r(Ltmp, cor[2], 10923); - - tmp_pc = pc; - move16(); - if (sub(wtmp, cor_min) < 0) - { - tmp_pc = TH_PC_FX; - move16(); /* low correlation -> probably inactive signal */ - } - - st_fx->pitO_fx = pit[1]; - move16(); /* Update */ - - /*-----------------------------------------------------------------* - * Multi-harmonic analysis - *-----------------------------------------------------------------*/ - - *loc_harm = multi_harm_fx( EspecdB, st_fx->old_S_fx, st_fx->cor_map_fx, &st_fx->multi_harm_limit_fx, st_fx->total_brate_fx, - st_fx->bwidth_fx, &st_fx->cor_strong_limit_fx, &st_fx->mean_avr_dyn_fx, &st_fx->last_sw_dyn_fx, cor_map_sum, sp_floor ); - - /*-----------------------------------------------------------------* - * Detection of frames with non-stationary spectral content - *-----------------------------------------------------------------*/ - - /* weighted sum of spectral changes per critical bands */ - Lsum_num = L_deposit_l(0); - Lsum_den = L_deposit_l(0); - - /* Find a proper scaling to prevent overflow, but acheiving good computation on low level signals */ - tmpExp = 0; - move16(); - ExpLmax = sub(30, norm_l(fr_bands[10])); - ExpLmax2 = sub(30, norm_l(st_fx->fr_bands2_fx[10])); - tmpExp = s_max(tmpExp, sub(shl(s_max(ExpLmax,ExpLmax2), 1), s_min(ExpLmax, ExpLmax2))); - FOR (i = 11; i<= st_fx->max_band_fx; i++) - { - ExpLmax = sub(30, norm_l(fr_bands[i])); - ExpLmax2 = sub(30, norm_l(st_fx->fr_bands2_fx[i])); - tmpExp = s_max(tmpExp, sub(shl(s_max(ExpLmax,ExpLmax2), 1), s_min(ExpLmax, ExpLmax2))); - } - tmpExp = sub(tmpExp, 30-4-4); /* 4bits for internal summation and 4 bits for comparaison */ - - pt1 = fr_bands + 10; - pt2 = st_fx->fr_bands2_fx + 10; - FOR (i=10; i<=st_fx->max_band_fx; i++) - { - Lnum = L_max(*pt1, *pt2); /* Don't need if anymore */ - Lsum_den = L_add(Lsum_den, Lnum); - Ltmpden = L_min(*pt1, *pt2); - if( Ltmpden == 0 ) - { - Ltmpden = L_add(Ltmpden,1); - } - ExpNum = sub(norm_l(Lnum), 1); - num = extract_h(L_shl(Lnum, ExpNum)); - num = mult_r(num, num); - ExpDen = norm_l(Ltmpden); - den = extract_h(L_shl(Ltmpden, ExpDen)); - num = div_s(num, den); - Ltmp = L_shr(num, add(sub(sub(shl(ExpNum, 1), ExpDen), 15+1), tmpExp)); - Lsum_num = L_add(Lsum_num, Ltmp); - - pt1++; - pt2++; - } - Lsum_den = L_shr(Lsum_den, tmpExp); - - - /* calculation of spectral diversity */ - /* THR_SPDIV_FX = 5 , 1/5 Q15 = 6554 */ - spec_div = 0; - move16(); - if (L_sub(Mult_32_16(Lsum_num, 6554), Lsum_den) > 0) /* Qx+Q15+1-16 ==> Qx */ - { - spec_div = 1; - move16(); - } - - /* *sp_div = Lsum_num / (Lsum_den + 1e-5f); */ - ExpNum = sub(norm_l(Lsum_num), 1); - num = extract_h(L_shl(Lsum_num, ExpNum)); - - Lsum_den = L_add(Lsum_den,1); - - ExpDen = norm_l(Lsum_den); - den = extract_h(L_shl(Lsum_den, ExpDen)); - - *sp_div = div_s(num, den); - move16(); - - *Q_sp_div = add(15,sub(ExpNum ,ExpDen)); - move16(); - - /*-----------------------------------------------------------------* - * Detection of frames with high energy content in high frequencies - *-----------------------------------------------------------------*/ - - /* calculation of energy in first 10 critical bands */ - Ltmp = sum32_fx( &fr_bands[st_fx->min_band_fx], sub(10, st_fx->min_band_fx) ); - - /* calculation of energy in the rest of bands */ - Ltmp2 = sum32_fx( &fr_bands[10], sub(st_fx->max_band_fx,9) ); - - wtmp = shl(1, sub(add(Q_new, QSCALE), 1)); - - test(); - IF (L_msu(Ltmp, 100, wtmp) < 0 || L_msu(Ltmp2, 100, wtmp) < 0) - { - noise_chartmp = 0; - move16(); - } - ELSE - { - /* ftemp2 /= ftemp */ - ExpNum = sub(norm_l(Ltmp2), 1); - num = extract_h(L_shl(Ltmp2, ExpNum)); - - ExpDen = norm_l(Ltmp); - den = extract_h(L_shl(Ltmp, ExpDen)); - num = div_s(num, den); - noise_chartmp = extract_h(L_shr(num, add(sub(ExpNum, ExpDen), 4-16))); /* Q11 */ - } - - noise_chartmp = s_min(noise_chartmp, (Word16)10<<11); /* Q11 */ - - /* update LT value of the final parameter */ - /* *st_noise_char = M_ALPHA * *st_noise_char + (1-M_ALPHA) * noise_chartmp */ - st_fx->noise_char_fx = mac_r(L_mult(M_ALPHA_FX, st_fx->noise_char_fx), ONE_MINUS_M_ALPHA, noise_chartmp); - - - nchar_thr = THR_NCHAR_WB_FX; - move16(); /* 1.0 Q11 */ - if( sub(vad_bwidth_fx,NB) == 0 ) - { - nchar_thr = THR_NCHAR_NB_FX; - move16(); /* 1.0 Q11 */ - } - - noise_char = 0; - move16(); - if (sub(st_fx->noise_char_fx, nchar_thr) > 0) - { - noise_char = 1; - move16(); - } - - /* save the 2 last spectra per crit. bands for the future */ - Copy32(st_fx->fr_bands1_fx, st_fx->fr_bands2_fx, NB_BANDS); - Copy32(fr_bands+NB_BANDS, st_fx->fr_bands1_fx, NB_BANDS); - - /*-----------------------------------------------------------------* - * Non-stationarity estimation for each band - * Handicap high E frames in average computing - *-----------------------------------------------------------------*/ - - /* set averaging factor */ - /* ftemp = relE; */ - /* if( ftemp < 0.0f ) { ftemp = 0.0f; } */ - tmp = s_max(relE,0); /* Q8 */ - - /* alpha = 0.064f * ftemp + 0.75f; */ - Ltmp = Mult_32_16((Word32)137438953L, tmp); /* Q31(.064)+Q8+1-16 --> Q24 */ - Ltmp = L_mac(Ltmp,256,24576) ; /* Q8+Q15(.75)+1 --> Q24 */ - alpha = round_fx(L_shl(Ltmp,7)); /*Q24 +7 --> Q31 Q15*/ - - /*if( alpha > 0.999f { alpha = 0.999f;} */ - alpha = s_min(alpha, 32735 ); /*.999 in Q15*/ - alpham1 = negate(add(-32768, alpha)); /* 1.0 - alpha */ - /*--------------------------------------------------------------* - * during significant attacks, replace the LT energy by the - * current energy this will cause non_sta2 failures to occur in - * different frames than non_sta failures - *--------------------------------------------------------------*/ - - alpha2 = alpha; - move16(); - alpha2m1 = alpham1; - move16(); - IF (spec_div > 0) - { - alpha2 = 0; - move16(); - alpha2m1 = 32767; - move16(); - } - Lnon_sta2 = L_deposit_l(1<<10); - - non_sta = L_deposit_l(1<<10); - *non_staX = 0; - move16(); - non_staB = 0; - move16(); - - FOR( i = st_fx->min_band_fx; i <= st_fx->max_band_fx; i++ ) - { - /* + 1.0f added to reduce sensitivity to non stationarity in low energies */ - /* tmp_enr = enr[i] + 1.0f; */ - tmp_Q = add(Q_new, Q_SCALE); - Ltmp = L_shl((Word32)1L, tmp_Q); /* 1.0 added in the right dynamic domain */ - L_tmp_enr = L_add(enr[i] , Ltmp ); /* enr scale dynamic */ - L_tmp_ave_enr = L_add(st_fx->ave_enr_fx[i], Ltmp); /* ave__enr scale dynamic */ - - IF (L_sub(non_sta, th_sta) <= 0) /* Just to limit the saturation */ - { - /* if( enr[i] > st_ave_enr2[i] ) */ - /* non_sta2 = non_sta2 * ((enr[i]+1) / (st_ave_enr2[i]+1)) */ - Lnum = L_max(L_tmp_enr, L_tmp_ave_enr); - - /* else */ - /* non_sta2 = non_sta2 * ((st_ave_enr2[i]+1) / (enr[i]+1)) */ - Lden = L_min(L_tmp_enr, L_tmp_ave_enr); - - ExpNum = sub(norm_l(Lnum), 1); - num = extract_h(L_shl(Lnum, ExpNum)); - Lnum = L_shl(Lnum, ExpNum); - ExpDen = norm_l(Lden); - den = extract_h(L_shl(Lden, ExpDen)); - num = div_s(num, den); - Ltmp = Mult_32_16(non_sta, num); - non_sta = L_shr(Ltmp, sub(ExpNum, ExpDen)); /* Q10 */ - } - - /* st->ave_enr[i] = alpha * st->ave_enr[i] + (1-alpha) * enr[i];*/ /* update long-term average */ - Ltmp = Mult_32_16(st_fx->ave_enr_fx[i], alpha); - Ltmp = L_add(Ltmp, Mult_32_16(enr[i], alpham1)); - st_fx->ave_enr_fx[i] = L_max(Le_min_scaled, Ltmp); - move32(); - - /* calculation of another non-stationarity measure (following attacks) */ - /*if( non_sta2 <= th_sta ){ - tmp_ave2 = st->ave_enr2[i] + 1.0f; - if( tmp_enr > tmp_ave2 ){ - non_sta2 = non_sta2 * ( tmp_enr / tmp_ave2 ); - } else { - non_sta2 = non_sta2 * (tmp_ave2 / tmp_enr ); - } - } */ - - /* ave_enr2:: calculation of another non-stationarity measure (following attacks) */ - Ltmp = L_shl((Word32)1L, tmp_Q ); /* 1.0 added in the right dynamic domain */ - /*L_tmp_enr = L_add(enr[i] , Ltmp );*/ /* enr scale dynamic , done above */ - L_tmp_ave_enr2 = L_add(st_fx->ave_enr2_fx[i], Ltmp); /* ave__enr scale dynamic */ - - IF (L_sub(Lnon_sta2, th_sta ) <= 0) /* Just to limit the saturation */ - { - Lnum = L_max(L_tmp_enr, L_tmp_ave_enr2 ); - Lden = L_min(L_tmp_enr, L_tmp_ave_enr2 ); - - ExpNum = sub(norm_l(Lnum), 1); - num = extract_h(L_shl(Lnum, ExpNum)); - Lnum = L_shl(Lnum, ExpNum); - ExpDen = norm_l(Lden); - den = extract_h(L_shl(Lden, ExpDen)); - num = div_s(num, den); - Ltmp1 = Mult_32_16(Lnon_sta2, num); - Lnon_sta2 = L_shr(Ltmp1, sub(ExpNum, ExpDen)); /* Q10 */ - } - - /* st_ave_enr2[i] = (float)alpha2 * st_ave_enr2[i] - + (1.0f - alpha2) * (enr[i]) */ - Ltmp1 = Mult_32_16(st_fx->ave_enr2_fx[i], alpha2); - Ltmp1 = L_add(Ltmp1, Mult_32_16(enr[i], alpha2m1)); - st_fx->ave_enr2_fx[i] = L_max(Le_min_scaled, Ltmp1); - move32(); - - /* calculation of non-stationarity measure for speech/music classification */ - test(); - IF ( sub(i,START_BAND_SPMUS) >= 0 && sub(i,NB_BANDS_SPMUS+START_BAND_SPMUS) < 0 ) - { - /* log_enr = (float)ln_fx(enr[i]); */ - log_enr16 = noise_est_ln_q8_fx( enr[i], 0 ,tmp_Q); - wtmp = abs_s(sub(log_enr16, st_fx->past_log_enr_fx[i-START_BAND_SPMUS])); - *non_staX = add(*non_staX, wtmp); - move16(); /* Q8 */ - st_fx->past_log_enr_fx[i-START_BAND_SPMUS] = log_enr16; - move16(); - - /* calculate non-stationarity feature relative background */ - tmp_enr = noise_est_ln_q8_fx( enr[i], 1 , tmp_Q); /* 1.0f added */ - tmp_floor = LN_E_MIN_PLUS_ONE_FX ; - move16(); /* non dynamic init constant in Q8 */ - IF ( sub(st_fx->ini_frame_fx, 100 ) >= 0 ) - { - tmp_floor = noise_est_ln_q8_fx( st_fx->bckr_fx[i], 1, tmp_Q ); - } - non_staB = add(non_staB, abs_s(sub(tmp_enr, tmp_floor))); /* Q8 */ - } - - } /* end of band loop FOR( i = st_fx->min_band_fx; i <= st_fx->max_band_fx; i++ ) */ - - IF (sub(Etot,-1280) < 0 ) - { - non_sta = L_deposit_l(1024); /* 1.0 in Q10 */ - Lnon_sta2 = L_deposit_l(1024); /* 1.0 in Q10 */ - } - - lim_Etot_fx = s_max(5120,Etot); /* 20.0f Q8 */ - lim_Etot_sq_fx = extract_h(L_shl_r(L_mult(lim_Etot_fx,lim_Etot_fx),1)); /* Q2 */ - - if ( st_fx->ini_frame_fx < 150 ) - { - /* Allow use of quicker filter during init - if needed */ - /* st->Etot_st_est = 0.25f * lim_Etot + (1.0f-0.25F) * st->Etot_st_est; */ - st_fx->Etot_st_est_fx = mac_r(L_mult(8192, lim_Etot_fx), 24576, st_fx->Etot_st_est_fx); - move16(); - /* st->Etot_sq_st_est = 0.25f * lim_Etot * lim_Etot + (1.0f-0.25f) * st->Etot_sq_st_est; */ - st_fx->Etot_sq_st_est_fx = mac_r(L_mult(8192, lim_Etot_sq_fx), 24576, st_fx->Etot_sq_st_est_fx); - move16(); - } - else - { - /* st->Etot_st_est = 0.25f * lim_Etot + (1.0f-0.25F) * st->Etot_st_est; */ - st_fx->Etot_st_est_fx = mac_r(L_mult(8192, lim_Etot_fx), 24576, st_fx->Etot_st_est_fx); - move16(); - /* st->Etot_sq_st_est = 0.25f * lim_Etot * lim_Etot + (1.0f-0.25f) * st->Etot_sq_st_est; */ - st_fx->Etot_sq_st_est_fx = mac_r(L_mult(8192, lim_Etot_sq_fx), 24576, st_fx->Etot_sq_st_est_fx); - move16(); - } - - st_E_var_est_fx = sub(st_fx->Etot_sq_st_est_fx,extract_h(L_shl_r(L_mult(st_fx->Etot_st_est_fx,st_fx->Etot_st_est_fx),1))); - - - - /*-----------------------------------------------------------------* - * Count frames since last correlation or harmonic event - *-----------------------------------------------------------------*/ - - Ltmp = L_mult(cor[0], 16384); - Ltmp = L_mac(Ltmp, cor[1], 16384); - - test(); - test(); - *st_harm_cor_cnt = add(*st_harm_cor_cnt , 1); - if( (Etot > 0) && ( (*loc_harm > 0 ) || (sub(round_fx(Ltmp), COR_MAX_NNE_FX ) > 0) )) - { - *st_harm_cor_cnt = 0; - move16(); - } - - IF( (sub(*st_harm_cor_cnt,1) > 0 ) &&( ( sub(Etot,3840) < 0 ) || /* 15 in Q8 */ - ( sub(st_fx->ini_frame_fx,10) > 0 && - sub(sub(Etot,st_fx->Etot_lp_fx),1792)>0 )) /* 7 in Q8 */ - ) - { - *st_harm_cor_cnt = 1; - } - - if ( sub(*st_harm_cor_cnt,1) > 0 && - sub(Etot,7680) > 0 && /* 30.0f in Q8 */ - sub(st_E_var_est_fx,32 )>0 /* 8.0f in Q2 */ - ) - { - - /* st->harm_cor_cnt = max(1, (short) round_f( (float) st->harm_cor_cnt / 4.0f )) ; */ - *st_harm_cor_cnt = s_max(1, shr(add(*st_harm_cor_cnt,2),1)); - } - - - /*-----------------------------------------------------------------* - * Energy based pause length counter - *-----------------------------------------------------------------*/ - test(); - IF( (*bg_cnt >= 0) && (sub(sub(Etot , Etot_l_lp),1280) > 0/*5.0 in Q8*/)) - { - /* Possible speech burst */ - *bg_cnt = -1; - move16(); - } - ELSE - { - test(); - if( sub(*bg_cnt,-1) == 0 && ( sub(sub(Etot , Etot_l_lp),1280) < 0 )/*5 in Q8*/ ) - { - /* Possible start of speech pause */ - *bg_cnt = 0; - move16(); - } - } - if (*bg_cnt >= 0) - { - *bg_cnt = add(*bg_cnt,1); - move16(); - } - - /*-----------------------------------------------------------------* - * Linear predition efficiency 0 to 2 order - *-----------------------------------------------------------------*/ - - /*epsP_0_2 = max(0 , min(8, epsP[0] / epsP[2])); */ - Ltmp = eps_quota_fx(epsP_h[0], epsP_l[0], - epsP_h[2], epsP_l[2] , 12 ); /* Word32 Q12 */ - BASOP_SATURATE_WARNING_OFF /* may saturate*/ - epsP_0_2 = round_fx(L_shl(Ltmp,16)); /* Q12+16 -16 -> Q12 , NB saturation in Q12 sets max value to 7,999 */ - BASOP_SATURATE_WARNING_ON - - epsP_0_2 = s_max(0, epsP_0_2); /* min value is 0 , Q12 */ - - - /* st->epsP_0_2_lp = 0.15f * epsP_0_2 + (1.0f-0.15f) * st->epsP_0_2_lp; */ - alpha = 4915; - move16(); /*0.15 in Q15 */ - st_fx->epsP_0_2_lp_fx = noise_est_AR1_Qx(epsP_0_2, st_fx->epsP_0_2_lp_fx ,alpha); - - /* epsP_0_2_ad = (float) fabs(epsP_0_2 - st->epsP_0_2_lp ); */ - epsP_0_2_ad = abs_s(sub(epsP_0_2, st_fx->epsP_0_2_lp_fx)); /* Q12 */ - - /*if (epsP_0_2_ad < st->epsP_0_2_ad_lp) { - st->epsP_0_2_ad_lp = 0.1f * epsP_0_2_ad + (1.0f - 0.1f) * st->epsP_0_2_ad_lp; - } else { - st->epsP_0_2_ad_lp = 0.2f * epsP_0_2_ad + (1.0f - 0.2f) * st->epsP_0_2_ad_lp; - } */ - alpha = 6554; - move16();/* 0.2 Q15 */ - if (sub(epsP_0_2_ad, st_fx->epsP_0_2_ad_lp_fx) < 0 ) - { - alpha = shr(alpha,1); /* 0.1 Q15 */ - } - st_fx->epsP_0_2_ad_lp_fx = noise_est_AR1_Qx(epsP_0_2_ad, st_fx->epsP_0_2_ad_lp_fx ,alpha); - - /* epsP_0_2_ad_lp_max = max(epsP_0_2_ad,st->epsP_0_2_ad_lp);*/ - epsP_0_2_ad_lp_max = s_max(epsP_0_2_ad, st_fx->epsP_0_2_ad_lp_fx); /* Q12 */ - - - /*-----------------------------------------------------------------* - * Linear predition efficiency 2 to 16 order - *-----------------------------------------------------------------*/ - - /* epsP_2_16 = max(0 , min(8, epsP[2] / epsP[16])); */ - Ltmp = eps_quota_fx(epsP_h[2], epsP_l[2], - epsP_h[16], epsP_l[16] , 12 ); /* Word32 Q12 */ - BASOP_SATURATE_WARNING_OFF /* may saturate*/ - epsP_2_16 = round_fx(L_shl(Ltmp,16)); /* Q12+16 -16 -> Q12 , - NB saturation in Q12 sets max value to 7,999 */ - BASOP_SATURATE_WARNING_ON - - epsP_2_16 = s_max(0, epsP_2_16); /* min value is 0 , Q12 */ - - - /* if (epsP_2_16 > st->epsP_2_16_lp){ - st->epsP_2_16_lp = 0.2f * epsP_2_16 + (1.0f-0.2f) * st->epsP_2_16_lp; - } else { - st->epsP_2_16_lp = 0.03f * epsP_2_16 + (1.0f-0.03f) * st->epsP_2_16_lp; - } - - st->epsP_2_16_lp2 = 0.02f * epsP_2_16 + (1.0f-0.02f) * st->epsP_2_16_lp2; */ - - alpha = 983 ; - move16();/* 0.03 Q15 */ - if (sub(epsP_2_16 , st_fx->epsP_2_16_lp_fx) > 0 ) - { - alpha = 6554; - move16();/* 0.2 Q15 */ - } - st_fx->epsP_2_16_lp_fx = noise_est_AR1_Qx(epsP_2_16, st_fx->epsP_2_16_lp_fx , alpha); - - st_fx->epsP_2_16_lp2_fx = noise_est_AR1_Qx(epsP_2_16, st_fx->epsP_2_16_lp2_fx , 655); /* 0.02 */ - - epsP_2_16_dlp = sub(st_fx->epsP_2_16_lp_fx, st_fx->epsP_2_16_lp2_fx); - - - /* if (epsP_2_16_dlp < st->epsP_2_16_dlp_lp2 ) { - st->epsP_2_16_dlp_lp2 = 0.02f * epsP_2_16_dlp + (1.0f-0.02f) * st->epsP_2_16_dlp_lp2; - } else { - st->epsP_2_16_dlp_lp2 = 0.05f * epsP_2_16_dlp + (1.0f-0.05f) * st->epsP_2_16_dlp_lp2; - }*/ - alpha = 1638; - move16();/* 0.05 Q15 */ - if (sub(epsP_2_16_dlp , st_fx->epsP_2_16_dlp_lp2_fx) < 0 ) - { - alpha = 655; - move16();/* 0.02 Q15 */ - } - st_fx->epsP_2_16_dlp_lp2_fx = noise_est_AR1_Qx(epsP_2_16_dlp, st_fx->epsP_2_16_dlp_lp2_fx , alpha); - - /* epsP_2_16_dlp_max = max(epsP_2_16_dlp,st->epsP_2_16_dlp_lp2); */ - epsP_2_16_dlp_max = s_max(epsP_2_16_dlp, st_fx->epsP_2_16_dlp_lp2_fx); - - /*-----------------------------------------------------------------* - * long term extensions of frame features - *-----------------------------------------------------------------*/ - - tmp = sub(Etot, st_fx->totalNoise_fx ); /* Q8 */ - /* st->lt_tn_track = 0.03f* (Etot - st->totalNoise < 10) + 0.97f*st->lt_tn_track; */ - tmp2 = 0; - move16(); - if( sub(tmp, 2560 ) < 0 ) /*10 in Q8 */ - { - tmp2=32767; - move16(); - } - st_fx->lt_tn_track_fx = noise_est_AR1_Qx(tmp2, st_fx->lt_tn_track_fx , 983); /*0.03 in Q15 ,Q15 state*/ - - /* st->lt_tn_dist = 0.03f* (Etot - st->totalNoise) + 0.97f*st->lt_tn_dist; */ - st_fx->lt_tn_dist_fx = noise_est_AR1_Qx(tmp, st_fx->lt_tn_dist_fx , 983); /*0.03 in Q15 ,Q8 state*/ - - /* st->lt_Ellp_dist = 0.03f* (Etot - st->Etot_l_lp) + 0.97f*st->lt_Ellp_dist;*/ - tmp = sub(Etot,st_fx->Etot_l_lp_fx); /* Q8 */ - st_fx->lt_Ellp_dist_fx = noise_est_AR1_Qx(tmp, st_fx->lt_Ellp_dist_fx, 983); /*0.03 in Q15 ,Q8 state*/ - - - - /* if (st->harm_cor_cnt == 0) { - st->lt_haco_ev = 0.03f*1.0 + 0.97f*st->lt_haco_ev; - } else { - st->lt_haco_ev = 0.99f*st->lt_haco_ev; - } */ - IF ( *st_harm_cor_cnt == 0) - { - st_fx->lt_haco_ev_fx = noise_est_AR1_Qx((Word16)32767, st_fx->lt_haco_ev_fx, 983); /*.03 in Q15 , Q15 state */ - } - ELSE - { - st_fx->lt_haco_ev_fx = mult_r(32440, st_fx->lt_haco_ev_fx); /*.99 in Q15 , Q15 state */ - } - - - /* if (st->lt_tn_track < 0.05f) { - st->low_tn_track_cnt++; - } else { - st->low_tn_track_cnt=0; - }*/ - tmp = 0; - move16(); - move16(); - if( sub( st_fx->lt_tn_track_fx , 1638 ) < 0 ) /* 0.05 in Q15*/ - { - tmp = add(st_fx->low_tn_track_cnt_fx, 1); - } - st_fx->low_tn_track_cnt_fx = tmp; - move16(); - - - /* update of the long-term non-stationarity measure (between 0 and 1) */ - /* if ( (non_sta > th_sta) || (*loc_harm > 0) ) { - st->act_pred = M_GAMMA * st->act_pred + (1-M_GAMMA) * 1; - } else { - st->act_pred = M_GAMMA * st->act_pred + (1-M_GAMMA) * 0; - }*/ - Ltmp = L_mult(M_GAMMA_FX, st_fx->act_pred_fx); /*Q15*Q15+1 --> Q31 , 32440= .99 Q15 */ - tmp = round_fx(Ltmp); /* Q15 */ - test(); - if ( ( L_sub (non_sta, th_sta) > 0) /* float th_sta NB 5e10 , WB 3.5e10*/ - || (*loc_harm > 0) - ) - { - tmp = mac_r(Ltmp, (-32768+M_GAMMA_FX), -32768); /* (-0.01)*(-1.0) */ - } - st_fx->act_pred_fx = tmp ; - move16(); - - - - /*-----------------------------------------------------------------* - * Background noise adaptation enable flag - *-----------------------------------------------------------------*/ - Ltmp = L_mult(cor[0], 16384); - Ltmp = L_mac(Ltmp, cor[1], 16384); - cor_tmp = mac_r(Ltmp, corr_shift,MAX_16); - - LepsP = eps_quota_fx(epsP_h[2] , epsP_l[2], - epsP_h[16], epsP_l[16] , 11 ); /* L_epsP in Q11 */ - /* note this epsP2/eps16 is not limited to 8 as, epsP_2_16 is !! */ - - vad_2nd_stage_fx = 0; - move16(); /* background noise present - decrement counter */ - /* - if( ( (*st_harm_cor_cnt < 3*HC_CNT_SLOW ) - && ( ( non_sta > th_sta ) || - ( tmp_pc < TH_PC ) || - ( noise_char > 0) ) - ) - || - ( (st->ini_frame > 150) && (Etot - Etot_l_lp) > 10 ) || - ( 0.5f * (voicing[0]+voicing[1]) > cor_max ) || - ( epsP[2] / epsP[16] > th_eps ) || - ( *loc_harm > 0) || - ((st->act_pred > 0.8f) && (non_sta2 > th_sta)) - ) */ - - Ltmp = L_mult(cor[0], 16384); /* Q15 + Q15(.5)) + 1 -> Q31 */ - cor_tmp = mac_r(Ltmp, cor[1], 16384 ); /* Q31 -16 -> Q15 */ - if ( Etot < 0 ) - { - cor_tmp = 0; - move16(); - } - - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - - if( ( ( sub(*st_harm_cor_cnt, (3*HC_CNT_SLOW_FX) ) < 0 ) - && ( ( L_sub(non_sta, th_sta) > 0) || (sub(tmp_pc, TH_PC_FX) < 0) || ( noise_char > 0) ) ) - || - ( (sub(st_fx->ini_frame_fx, HE_LT_CNT_INIT_FX ) > 0 ) && ( sub(sub(Etot, Etot_l_lp), 2560) > 0 ) ) || - ( sub(cor_tmp, cor_max) > 0 ) || /* Q15 */ - ( L_sub(LepsP, th_eps) > 0 ) || /* Q11 */ - ( *loc_harm > 0 ) || - ((sub(st_fx->act_pred_fx, 26214) > 0) && (L_sub(Lnon_sta2, th_sta) > 0) ) /*act_pred in Q15 , th_sta in Q10 */ - ) - { - vad_2nd_stage_fx = 1; - move16(); /* active signal present - increment counter */ - } - - tmp = 2; - move16(); /* Signal present */ - if(vad_2nd_stage_fx == 0 ) - { - tmp = -1; - move16(); /* Background present */ - } - st_fx->aEn_fx = add(st_fx->aEn_fx, tmp); - - - st_fx->aEn_fx = s_min(st_fx->aEn_fx,6); - st_fx->aEn_fx = s_max(st_fx->aEn_fx,0); - - - - - /* Additional NNE detectors */ - - /* comb_ahc_epsP = max(max(st->act_pred, st->lt_haco_ev), epsP_2_16_dlp); */ - /* Q15 Q15 Q12 */ - comb_ahc_epsP = s_max(s_max(shr(st_fx->act_pred_fx,15-12), shr(st_fx->lt_haco_ev_fx, 15-12)), epsP_2_16_dlp); /* Q12 */ - - - /* comb_hcm_epsP = max(max(st->lt_haco_ev,epsP_2_16_dlp_max),epsP_0_2_ad_lp_max); */ - /* Q15 Q12 Q12 */ - comb_hcm_epsP = s_max(s_max(shr(st_fx->lt_haco_ev_fx,15-12), epsP_2_16_dlp_max), epsP_0_2_ad_lp_max); /* Q12 */ - - /*haco_ev_max = max(*st_harm_cor_cnt==0,st->lt_haco_ev); */ - tmp = 0; - move16(); - if ( *st_harm_cor_cnt == 0 ) - { - tmp = (Word16)32767; - move16(); - } - haco_ev_max = s_max(tmp, st_fx->lt_haco_ev_fx); /* Q15 */ - - /* Etot_l_lp_thr = st->Etot_l_lp + (1.5f + 1.5f * (st->Etot_lp<50.0f))*st->Etot_v_h2; */ - tmp = 12288; - move16();/* 1.5 Q13 */ - if( sub(st_fx->Etot_lp_fx, 12800 ) < 0 ) /* 50.0 in Q8 */ - { - tmp =shl(tmp,1); /*1.5 + 1.5 Q13 */ - } - Ltmp = L_deposit_h(st_fx->Etot_l_lp_fx); - Etot_l_lp_thr = round_fx(L_add(Ltmp, L_shl(L_mult(tmp, Etot_v_h2),2))); /* Q13+Q8+1 +2 = Q24 -> Q8*/ - - /* enr_bgd = Etot < Etot_l_lp_thr; */ - enr_bgd = 0; - move16(); - if(sub(Etot, Etot_l_lp_thr ) < 0 ) /* Q8 */ - { - enr_bgd = 1; - move16();/* Q0 */ - } - - /* cns_bgd = (epsP_0_2 > 7.95f) && (non_sta< 1e3f); */ - cns_bgd = 0 ; - move16(); - test(); - if( (sub(epsP_0_2, 32563) >0 ) /* 7.95 in Q12 */ - && (L_sub(non_sta, 1024000L) < 0 ) ) /* 1e3f in Q10 ? */ - { - cns_bgd = 1; - move16(); /* Q0 */ - } - - /*lp_bgd = epsP_2_16_dlp_max < 0.10f; */ - lp_bgd = 0; - move16(); - if( sub(epsP_2_16_dlp_max, 410) <0 ) /*0.10 Q12 */ - { - lp_bgd = 1; - move16(); /* Q0 */ - } - - - /* ns_mask = non_sta < 1e5f; */ - ns_mask = 0; - move16(); - if( L_sub(non_sta, (Word32)102400000L ) < 0) /* (1e5f in Q10)*/ - { - ns_mask = 1; - move16(); /* Q0 */ - } - - - /* lt_haco_mask = st->lt_haco_ev < 0.5f; */ - lt_haco_mask = 0; - move16(); - if( sub(st_fx->lt_haco_ev_fx, 16384 ) < 0 ) /* ( .5 in Q15)*/ - { - lt_haco_mask = 1; - move16(); /* Q0 */ - } - - /* bg_haco_mask = haco_ev_max < 0.4f; */ - bg_haco_mask = 0; - move16(); - if( sub(haco_ev_max, 13107) < 0 ) /* ( 0.4 in Q15)*/ - { - bg_haco_mask = 1; - move16(); /* Q0 */ - } - - - /* SD_1 = ( (epsP_0_2_ad > 0.5f) && (epsP_0_2 > 7.95f) ); */ - SD_1 = 0; - move16(); - test(); - if( (sub(epsP_0_2_ad,2048) > 0) /* 0.5 in Q12 */ - && (sub(epsP_0_2, 32563) > 0 )) /* 7.95 in Q12 */ - { - SD_1 = 1; - move16(); /* Q0 */ - } - SD_1_inv = sub(1, SD_1); /* Q0 */ - - /* NB "STL::test()"; has a cost of 2, using bitwise "s_and" , "s_or" at a cost of 1 */ - /* NB only lowest bit position is used, result is always 0 or 1 */ - - /* bg_bgd3 = enr_bgd || ( ( cns_bgd || lp_bgd ) && ns_mask && lt_haco_mask && SD_1==0 ); */ - tmp = s_and(s_and(s_and(s_or(cns_bgd, lp_bgd), ns_mask), lt_haco_mask ), SD_1_inv); - bg_bgd3 = s_or(enr_bgd, tmp); - - /*PD_1 = (epsP_2_16_dlp_max < 0.10f ) ; */ - PD_1 = 0; - move16(); - if( (sub( epsP_2_16_dlp_max, 410) < 0) ) /* 0.10 in Q12 */ - { - PD_1 = 1; - move16(); /* Q0 */ - } - - /*PD_2 = (epsP_0_2_ad_lp_max < 0.10f ) ; */ - PD_2 = 0; - move16(); - if( (sub( epsP_0_2_ad_lp_max, 410) < 0) ) /* 0.10 in Q12 */ - { - PD_2 = 1; - move16(); /* Q0 */ - } - - /*PD_3 = (comb_ahc_epsP < 0.85f ); */ - PD_3 = 0; - move16(); - if( (sub(comb_ahc_epsP, 3482 ) < 0) ) /* 0.85 in Q12 */ - { - PD_3 = 1; - move16(); /* Q0 */ - } - - /* PD_4 = comb_ahc_epsP < 0.15f; */ - PD_4 = 0; - move16(); - if( (sub(comb_ahc_epsP, 614) < 0) ) /* 0.15 in Q12 */ - { - PD_4 = 1; - move16(); /* Q0 */ - } - - /*PD_5 = comb_hcm_epsP < 0.30f; */ - PD_5 = 0; - move16(); - if( (sub(comb_hcm_epsP, 1229) < 0) ) /* 0.30 in Q12 */ - { - PD_5 = 1; - move16(); /* Q0 */ - } - - /* BG_1 = ( (SD_1==0) || (Etot < Etot_l_lp_thr) ) - && bg_haco_mask && (st->act_pred < 0.85f) && (st->Etot_lp < 50.0f); */ - BG_1 = 0; - move16(); - test(); - test(); - test(); - test(); - if( ( (SD_1 == 0) || (sub(Etot, Etot_l_lp_thr) < 0 ) ) - && (bg_haco_mask != 0) && ( sub(st_fx->act_pred_fx, 27853 ) < 0 ) /* 0.85f in Q15 */ - && (sub(st_fx->Etot_lp_fx, 50*256) < 0 )) /* 50.0 in Q8 */ - { - BG_1 = 1; - move16(); - } - - /* PAU = (st->aEn==0) - || ( (Etot < 55.0f) && (SD_1==0) - && ( ( PD_3 && (PD_1 || PD_2 ) ) || ( PD_4 || PD_5 ) ) ); */ - PAU=0; - move16();/*Q0*/ - if(st_fx->aEn_fx == 0) - { - PAU = 1; - move16();/*Q0*/ - } - tmp = 0; - move16();/*Q0*/ - if( sub(Etot, 55*256) <0) /*55.0 in Q8 */ - { - tmp = 1; - move16();/*Q0*/ - } - tmp = s_and(tmp, SD_1_inv); - PAU = s_or(PAU, s_and(tmp, s_or(s_and(PD_3, s_or(PD_1, PD_2 )) , s_or( PD_4, PD_5 )))) ; - - - /* NEW_POS_BG = (PAU | BG_1) & bg_bgd3; note bitwise logic in float */ - NEW_POS_BG = s_and(s_or(PAU, BG_1),bg_bgd3); - - /* Original silence detector works in most cases */ - /* aE_bgd = (st->aEn == 0);*/ - aE_bgd = 0; - move16(); - if(st_fx->aEn_fx == 0) - { - aE_bgd = 1; - move16(); - } - - - - /* When the signal dynamics is high and the energy is close to the background estimate */ - /* sd1_bgd = (st->sign_dyn_lp > 15) - && (Etot - st->Etot_l_lp ) < 2*st->Etot_v_h2 - && st->harm_cor_cnt > 20; */ - sd1_bgd = 0; - move16(); - test(); - test(); - if ( ( sub(st_fx->sign_dyn_lp_fx, 15*256) > 0 ) /* 15 in Q8 */ - && ( sub(sub(Etot, st_fx->Etot_l_lp_fx ), shl(Etot_v_h2, 1) ) < 0 ) /* Q8 , Etot_v_h2 has limited dynmics can be upscaled*/ - && (sub(*st_harm_cor_cnt, 20) > 0 ) ) - { - sd1_bgd = 1; - move16(); - } - - /* tn_ini = st->ini_frame < 150 && st->harm_cor_cnt > 5 && - ( (st->act_pred < 0.59f && st->lt_haco_ev <0.23f ) || - st->act_pred < 0.38f || - st->lt_haco_ev < 0.15f || - non_staB < 50.0f || - aE_bgd );*/ - - tmp = 0; - move16(); - test(); - test(); - test(); - test(); - test(); - if ( ( (sub(st_fx->act_pred_fx, 19333) < 0 ) && ( sub(st_fx->lt_haco_ev_fx, 7537) < 0 ) ) /* .59 in Q15 .23 in Q15 */ - || (sub(st_fx->act_pred_fx, 12452) < 0 ) /* .38 in Q15 */ - || (sub(st_fx->lt_haco_ev_fx, 4915) < 0 ) /* .15 in Q15 */ - || (sub(non_staB, 50*256 ) < 0 ) /* 50.0 in Q8 */ - || aE_bgd != 0 - || ( (sub(Etot,10752)<0) /* 42 in Q8 */ - && (sub(st_fx->harm_cor_cnt_fx, 10) > 0 ) - && ( sub(st_fx->lt_haco_ev_fx, 11469) < 0 ) /* 0.35 in Q15 */ - && ( sub(st_fx->act_pred_fx, 26214) < 0 ) /* 0.80 in Q15 */ - ) - ) - { - tmp = 1; - move16(); - } - - tn_ini = 0; - move16(); - test(); - test(); - if ( ( sub(st_fx->ini_frame_fx, HE_LT_CNT_INIT_FX ) < 0) - && ( sub(st_fx->harm_cor_cnt_fx,5) > 0 ) /* > 5 Q0 */ - && ( sub(sub(Etot,st_fx->Etot_lp_fx),1792 ) < 0 ) /* 7 in Q8 */ - && ( tmp != 0) ) - { - tn_ini = 1; - move16(); - } - - /* Energy close to the background estimate serves as a mask for other background detectors */ - /* bg_bgd2 = Etot < Etot_l_lp_thr || tn_ini ; */ - bg_bgd2 = 0; - move16(); - test(); - if ( ( sub(Etot, Etot_l_lp_thr) < 0 ) - || (tn_ini != 0 ) ) - { - bg_bgd2 = 1; - move16(); /* Q0 */ - } - - updt_step = 0; - move16(); /* Q15 */ - /*if (( bg_bgd2 && ( aE_bgd || sd1_bgd || st->lt_tn_track >0.90f || NEW_POS_BG ) ) - || tn_ini ) */ - tmp = 0; - move16(); - if( sub(st_fx->lt_tn_track_fx, 29491 ) > 0 ) /* .90 in Q15 */ - { - tmp = 1; - move16(); - } - - IF ( s_or(s_and(bg_bgd2 , s_or(aE_bgd, s_or(sd1_bgd, s_or(tmp, NEW_POS_BG)))), tn_ini) ) - { - /*if( ( ( st->act_pred < 0.85f ) - && (aE_bgd !=0) - && ( st->lt_Ellp_dist < 10 || sd1_bgd ) - && (st->lt_tn_dist<40) - && ( ( Etot - st->totalNoise ) < 10.0f ) - ) - || ( (st->first_noise_updt == 0) && (st->harm_cor_cnt > 80) && (aE_bgd!=0) && (st->lt_aEn_zero > 0.5f) ) - || ( (tn_ini!=0) && ( aE_bgd != 0) || (non_staB < 10.0) || (st->harm_cor_cnt > 80) ) - )*/ - - test(); - test(); - test(); - test(); - test(); - test(); - test(); /* for the ELSE IF below*/ - test(); - test(); - test(); - test(); - test(); - test(); /* for the ELSE IF below*/ - - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - IF( ( ( sub(st_fx->act_pred_fx, 27853) < 0 ) /* 0.85 in Q15 */ - && ( aE_bgd != 0 ) - && ( (sub(st_fx->lt_Ellp_dist_fx, 10*256) < 0) || ( sd1_bgd != 0 ) ) /* 10.0 in Q8*/ - && ( sub(st_fx->lt_tn_dist_fx, 40*256 ) < 0 ) /* 40.0 in Q8*/ - && ( sub(sub(Etot, st_fx->totalNoise_fx), 10*256) < 0 ) /* 10.0 in Q8*/ - ) - || ( (st_fx->first_noise_updt_fx == 0) && (sub(st_fx->harm_cor_cnt_fx,80) > 0) - && ( aE_bgd != 0 ) && (sub(st_fx->lt_aEn_zero_fx, 16384) > 0) /*.5 in Q15*/ - ) - || ( (tn_ini != 0 ) && ( ( aE_bgd != 0 ) || ( sub(non_staB, 10*256) < 0 ) || (sub(st_fx->harm_cor_cnt_fx, 80) > 0 ) ) /* 10.0 in Q8*/ - ) - ) - - { - updt_step = 32767; - move16(); - st_fx->first_noise_updt_fx = 1; - FOR( i=0; i< NB_BANDS; i++ ) - { - st_fx->bckr_fx[i] = tmpN[i]; - move32(); - } - } - /* else if ( ( ( st->act_pred < 0.80f ) && ( aE_bgd || PAU ) && st->lt_haco_ev < 0.10f ) - || ( ( st->act_pred < 0.70f ) && ( aE_bgd || non_staB < 17.0f ) && PAU && st->lt_haco_ev < 0.15f ) - || ( st->harm_cor_cnt > 80 && st->totalNoise > 5.0f && Etot < max(1.0f,Etot_l_lp + 1.5f* st->Etot_v_h2) ) - || - ( st->harm_cor_cnt > 50 && st->first_noise_updt > 30 && aE_bgd && st->lt_aEn_zero>0.5f ) - || tn_ini - ) */ - ELSE IF ( ( ( sub(st_fx->act_pred_fx, 26214) < 0 ) /* .8 in Q15*/ - && ( ( aE_bgd != 0 ) || ( PAU != 0 ) ) - && (sub(st_fx->lt_haco_ev_fx, 3277) < 0 ) ) /* .10 in q15*/ - || ( ( sub(st_fx->act_pred_fx, 22938 ) < 0 ) /* 0.70 in Q15 */ - && ( (aE_bgd!=0 ) || ( sub(non_staB, 17*256 ) < 0 ) )/* 17.0 in Q8 */ - && ( PAU != 0 ) - && ( sub(st_fx->lt_haco_ev_fx,4915) < 0 ) /* 0.15 in Q15 */ - ) - || ( (sub(st_fx->harm_cor_cnt_fx, 80)> 0 ) && (sub(st_fx->totalNoise_fx, 5*256) > 0 ) /* 5.0 in Q8 */ - && ( sub(Etot, s_max((Word16)1*256, add(Etot_l_lp, add(st_fx->Etot_v_h2_fx,shr(st_fx->Etot_v_h2_fx,1))))) < 0) /* 1.5= 1.0+.5 */ - ) - || ( (sub(st_fx->harm_cor_cnt_fx,50) >0) && (sub(st_fx->first_noise_updt_fx, 30) > 0) - && (aE_bgd != 0) && (sub(st_fx->lt_aEn_zero_fx, 16384) > 0) ) /*.5 in Q15*/ - || ( tn_ini != 0 ) - ) - - { - updt_step = 3277; - move16(); /* 0.1 in Q15 */ - /* if ( !aE_bgd && st->harm_cor_cnt < 50 - && ( (st->act_pred > 0.6f) - || ( (tn_ini==0) && (Etot_l_lp - st->totalNoise < 10.0f) && non_staB > 8.0f ) - ) - ) - */ - test(); - test(); - test(); - test(); - test(); - IF ( ( aE_bgd==0 ) - && ( sub(st_fx->harm_cor_cnt_fx, 50) < 0 ) - && ( ( sub(st_fx->act_pred_fx, 19661) > 0 ) /* 0.6 in Q15*/ - || ( ( tn_ini==0 ) - && (sub(sub(Etot_l_lp, st_fx->totalNoise_fx),10*256) < 0 ) /* 10.0 in Q8 */ - && (sub(non_staB, 8*256) > 0) /* 8.0 in in Q8*/ - ) - ) - ) - { - updt_step = 328; - move16(); /* 0.01 Q15 */ - } - /* - IF (updt_step > 0 ) - { - */ - st_fx->first_noise_updt_fx = 1; - move16(); - FOR( i=0; i< NB_BANDS; i++ ) - { - /* st->bckr[i] = st->bckr[i] + updt_step * (tmpN[i]-st->bckr[i]);*/ - /* 32 bit state update */ - Ltmp = L_sub(tmpN[i], st_fx->bckr_fx[i]); /*Q_new+Q_SCALE*/ - Ltmp = Mult_32_16(Ltmp, updt_step ); /* Q_new+Q_SCALE+15+1 -16*/ - st_fx->bckr_fx[i] = L_add(Ltmp, st_fx->bckr_fx[i]); - move32(); - } - /* - } */ - } - /*else if (aE_bgd || st->harm_cor_cnt > 100 )*/ - ELSE IF ( (aE_bgd !=0) || (sub(st_fx->harm_cor_cnt_fx, 100) > 0)) - { - st_fx->first_noise_updt_fx = add(st_fx->first_noise_updt_fx,1); - } - } - ELSE - { - /* If in music lower bckr to drop further */ - test(); - test(); - IF ( (sub(st_fx->low_tn_track_cnt_fx, 300) > 0) - && (sub(st_fx->lt_haco_ev_fx, 29491 ) > 0 ) /*.9 in Q15 */ - && (st_fx->totalNoise_fx > 0 ) ) - { - updt_step = -655; - move16(); /* for debug purposes */ - FOR( i=0; i< NB_BANDS; i++ ) - { - IF( L_sub(st_fx->bckr_fx[i], L_shl(Le_min_scaled, 1L) ) > 0 ) /* 2*E_MIN(float) in float, here we use 2*Le_min_scaled Q_new+Q_SCALE */ - { - /* st->bckr[i] = 0.98f*st->bckr[i]; */ - st_fx->bckr_fx[i] = Mult_32_16(st_fx->bckr_fx[i], 32113); /* .98 in Q15 */ - move32(); /* move to array */ - } - } - } - /*st->lt_aEn_zero = 0.2f * (st->aEn==0) + (1-0.2f) *st->lt_aEn_zero;*/ - /* y(n+1)= alpha*tmp + (1-alpha)*y(n) */ - tmp=0; - move16(); - if( st_fx->aEn_fx == 0 ) - { - tmp=32767; - move16(); - } - st_fx->lt_aEn_zero_fx = noise_est_AR1_Qx(tmp, st_fx->lt_aEn_zero_fx, 6554); /* alpha=0.2 , Q15 */ - - } - - - return; -} - - diff --git a/src/libs/libevs/lib_enc/noise_adjust.cpp b/src/libs/libevs/lib_enc/noise_adjust.cpp new file mode 100644 index 00000000..20f5c2e2 --- /dev/null +++ b/src/libs/libevs/lib_enc/noise_adjust.cpp @@ -0,0 +1,81 @@ +/*==================================================================================== + EVS Codec 3GPP TS26.443 Nov 13, 2018. Version 12.11.0 / 13.7.0 / 14.3.0 / 15.1.0 + ====================================================================================*/ + +#include +#include "options.h" +#include "cnst.h" +#include "rom_com.h" +#include "prot.h" + +/*--------------------------------------------------------------------------* + * noise_adjust() + * + * Calculate attenuation + *--------------------------------------------------------------------------*/ + +short noise_adjust( /* o : index of noise attenuation */ + const float *coeffs_norm, /* i : normalized coefficients */ + const short *bitalloc, /* i : bit allocation */ + const short *sfm_start, + const short *sfm_end, + const short core_sfm /* i : index of the end band for core */ +) +{ + short nf_idx, sfm, bin, num_coeffs; + int E, diff, tmp; + + E = 0; + num_coeffs = 0; + + for (sfm = 0; sfm <= core_sfm; sfm++) + { + if (bitalloc[sfm] == 0) + { + for (bin = sfm_start[sfm]; bin < sfm_end[sfm]; bin++) + { + if (coeffs_norm[bin] == 0) + { + E = E - 1; + } + else + { + tmp = (int)(floor(log10(fabs(coeffs_norm[bin] * L_FRAME))/0.301030f)+1); + if (tmp < 0) + { + tmp = 0; + } + E = E + tmp; + } + + num_coeffs = num_coeffs + 1; + } + } + } + + if (num_coeffs != 0) + { + E = E/num_coeffs; + } + else + { + E = 0; + } + + diff = 7 - E; + + if ( diff >= 0 ) + { + nf_idx = (short)diff; + if ( diff > 3 ) + { + nf_idx = 3; + } + } + else + { + nf_idx = 0; + } + + return nf_idx; +} diff --git a/src/libs/libevs/lib_enc/noise_adjust_fx.cpp b/src/libs/libevs/lib_enc/noise_adjust_fx.cpp deleted file mode 100755 index e1292dc0..00000000 --- a/src/libs/libevs/lib_enc/noise_adjust_fx.cpp +++ /dev/null @@ -1,69 +0,0 @@ -/*==================================================================================== - EVS Codec 3GPP TS26.442 Apr 03, 2018. Version 12.11.0 / 13.6.0 / 14.2.0 - ====================================================================================*/ - -#include "options.h" /* Compilation switches */ -#include "cnst_fx.h" /* Common constants */ -#include "rom_com_fx.h" /* Static table prototypes */ - -#include "prot_fx.h" /* Function prototypes */ -#include "stl.h" /* required for wmc_tool */ - -/*--------------------------------------------------------------------------* - * noise_adjust_fx() - * - * Calculate attenuation - *--------------------------------------------------------------------------*/ - -Word16 noise_adjust_fx( /* o : index of noise attenuation Q0 */ - const Word16 *coeffs_norm, /* i : normalized coefficients Qx */ - const Word16 qx, /* i : Q value of coeffs_norm */ - const Word16 *bitalloc, /* i : bit allocation Q0 */ - const Word16 *sfm_start, /* i : band start Q0 */ - const Word16 *sfm_end, /* i : band end Q0 */ - const Word16 core_sfm /* i : index of the end band for core Q0 */ -) -{ - Word16 nf_idx, sfm, bin, num_coeffs; - Word16 E, diff, inv_num_coeffs; - - E = 0; - move16(); - num_coeffs = 0; - move16(); - - FOR (sfm = 0; sfm <= core_sfm; sfm++) - { - IF (bitalloc[sfm] == 0) - { - FOR (bin = sfm_start[sfm]; bin < sfm_end[sfm]; bin++) - { - IF (coeffs_norm[bin] == 0) - { - E = sub(E, 1); - } - ELSE - { - E = add(E, sub(15+8,add(qx,norm_s(coeffs_norm[bin])))); - } - num_coeffs = add(num_coeffs, 1); - } - } - } - - IF (num_coeffs != 0) - { - inv_num_coeffs = div_s(1,num_coeffs); /* Q15 */ - E = mult(E,inv_num_coeffs); /* Q0 (0+15-15) */ - } - ELSE - { - E = 0; - move16(); - } - - diff = sub(7, E); - nf_idx = s_min(s_max(diff,0),3); - - return nf_idx; -} diff --git a/src/libs/libevs/lib_enc/normalizecoefs.cpp b/src/libs/libevs/lib_enc/normalizecoefs.cpp new file mode 100644 index 00000000..c24699c3 --- /dev/null +++ b/src/libs/libevs/lib_enc/normalizecoefs.cpp @@ -0,0 +1,37 @@ +/*==================================================================================== + EVS Codec 3GPP TS26.443 Nov 13, 2018. Version 12.11.0 / 13.7.0 / 14.3.0 / 15.1.0 + ====================================================================================*/ + +#include "options.h" +#include "rom_com.h" +#include "prot.h" + +/*-------------------------------------------------------------------------- + * normalizecoefs() + * + * Normalize MDCT coefficients with quantized norms + *--------------------------------------------------------------------------*/ + +void normalizecoefs( + float *coefs, /* i/o: MDCT coefficients */ + const short *ynrm, /* i : quantization indices for norms */ + const short num_bands, /* i : Number of bands */ + const short *band_start, /* i : Start of bands */ + const short *band_end /* i : End of bands */ +) +{ + short i, band; + float normq; + + for (band = 0; band < num_bands; band++) + { + normq = dicn_inv[ynrm[band]]; + + for (i = band_start[band]; i < band_end[band]; i++) + { + coefs[i] *= normq; + } + } + + return; +} diff --git a/src/libs/libevs/lib_enc/normalizecoefs_fx.cpp b/src/libs/libevs/lib_enc/normalizecoefs_fx.cpp deleted file mode 100755 index c603a7f3..00000000 --- a/src/libs/libevs/lib_enc/normalizecoefs_fx.cpp +++ /dev/null @@ -1,61 +0,0 @@ -/*==================================================================================== - EVS Codec 3GPP TS26.442 Apr 03, 2018. Version 12.11.0 / 13.6.0 / 14.2.0 - ====================================================================================*/ - -#include "options.h" /* Compilation switches */ -#include "stl.h" -#include "basop_mpy.h" -#include "prot_fx.h" -#include "cnst_fx.h" /* Common constants */ - - -/*-------------------------------------------------------------------------- - * normalizecoefs_fx() - * - * Normalize MDCT coefficients with quantized norms - *--------------------------------------------------------------------------*/ - -void normalizecoefs_fx( - Word32 *coefs, /* i : Input vector (Q12) */ - const Word16 *ynrm, /* i : quantization indices for norms */ - const Word16 num_bands, /* i : Number of bands */ - const Word16 *band_start, /* i : Start of bands */ - const Word16 *band_end, /* i : End of bands */ - Word16 *coefs_norm /* o : Normalized output vector */ -) -{ - Word16 band, j, k, r, v; - Word16 *pcoefs16; - Word32 *pcoefs; - Word16 subvec_start, subvec_end, num_coefs; - pcoefs = coefs; - pcoefs16 = coefs_norm; - - FOR (band = 0; band < num_bands; band++) - { - r = s_and(ynrm[band], 1); - v = shr(ynrm[band], 1); - k = sub(sub(17, r), v); - - subvec_start = band_start[band]; - move16(); - subvec_end = band_end[band]; - move16(); - num_coefs = sub(subvec_end, subvec_start); - - FOR (j = 0; j < num_coefs; j++) - { - IF (r!=0) - { - *pcoefs = Mpy_32_16_1(*pcoefs, INV2POWHALF); - move32(); - } - BASOP_SATURATE_WARNING_OFF /* May saturate for strong peaks in a high band, in which case saturation is desirable */ - *pcoefs16++ = round_fx( L_shl(*pcoefs++, 16-k) ); /* Q12 */ - BASOP_SATURATE_WARNING_ON - } - } - - return; -} - diff --git a/src/libs/libevs/lib_enc/peak_vq_enc.cpp b/src/libs/libevs/lib_enc/peak_vq_enc.cpp new file mode 100644 index 00000000..2c66b60b --- /dev/null +++ b/src/libs/libevs/lib_enc/peak_vq_enc.cpp @@ -0,0 +1,593 @@ +/*==================================================================================== + EVS Codec 3GPP TS26.443 Nov 13, 2018. Version 12.11.0 / 13.7.0 / 14.3.0 / 15.1.0 + ====================================================================================*/ + +#include +#include +#include "options.h" +#include "cnst.h" +#include "prot.h" +#include "rom_com.h" + +/*-------------------------------------------------------------------------- + * Local functions + *--------------------------------------------------------------------------*/ + +void quant_peaks( Encoder_State *st, const float *vect_in, float *vect_out, const float *peak_gain, short *vq_idx ,const short overlap, + const short brate, const short Npeaks ); + +static short hvq_code_pos( Encoder_State *st, const short *inp, const short length, const short num_peaks ); +static short sparse_code_pos( const short *inp, const short length, short *result ); + +/*-------------------------------------------------------------------------- + * peak_vq_enc() + * + * Vector Quantization of MDCT peaks + *--------------------------------------------------------------------------*/ + +short peak_vq_enc( + Encoder_State *st, /* i/o: encoder state structure */ + const float *coefs, /* i : Input coefficient vector */ + float *coefs_out, /* o : Quantized output vector */ + const short brate, /* i : Core bitrate */ + const short num_bits, /* i : Number of bits for HVQ */ + const short vq_peaks, /* i : Number of identified peaks */ + const short *ynrm, /* i : Envelope coefficients */ + short *R, /* i/o: Bit allocation/updated bit allocation */ + short *vq_peak_idx, /* i : Peak index vector */ + float *nf_gains /* i : Estimated noise floor gains */ +) +{ + short pos_bits; + float normq; + float pgain_q[HVQ_MAX_PEAKS_32k]; + float peak_gains[HVQ_MAX_PEAKS_32k]; + float coefs_pvq[HVQ_PVQ_BUF_LEN]; + float pvq_vector[HVQ_PVQ_BUF_LEN]; + float *pPvqVectorBandStart; + float fg_pred[NB_SFM_MAX]; + short i, j, k, m, r, pvq_bands, num_overlap_bins; + short hcode_l, FlagN, low_peak_bin, vq_cb_idx, max_peaks, bin_th; + short bits = 0; + short q_nf_gain_idx[HVQ_NF_GROUPS]; + short nf_seed = RANDOM_INITSEED; + short pgain_cb_idx[HVQ_MAX_PEAKS], pgain_difidx[HVQ_MAX_PEAKS]; + short pvq_norm[MAX_PVQ_BANDS]; + short pvq_bits, bit_budget; + short pos_vec[HVQ_THRES_BIN_32k]; + short npulses[MAX_PVQ_BANDS]; + short pvq_inp_vector[HVQ_PVQ_BUF_LEN]; + short k_sort[MAX_PVQ_BANDS]; + short Rk[MAX_PVQ_BANDS]; + short Rk_f[MAX_PVQ_BANDS]; /*Q3*/ + float gopt[NB_SFM]; + short sel_bnds[HVQ_NUM_SFM_24k]; + short n_sel_bnds; + int manE_peak, manPkEnrg; + short expE_peak, expPkEnrg; + short hvq_band_end[MAX_PVQ_BANDS]; + short hvq_band_start[MAX_PVQ_BANDS]; + short hvq_band_width[MAX_PVQ_BANDS]; + short n; + short s; + set_f( coefs_pvq, 0.0f, HVQ_PVQ_BUF_LEN ); + set_f( pvq_vector, 0.0f, HVQ_PVQ_BUF_LEN ); + set_s( npulses, 0, MAX_PVQ_BANDS ); + + /* Set bitrate dependent variables */ + if (brate == HQ_24k40) + { + max_peaks = HVQ_MAX_PEAKS_24k; + bin_th = HVQ_THRES_BIN_24k; + } + else + { + max_peaks = HVQ_MAX_PEAKS_32k; + bin_th = HVQ_THRES_BIN_32k; + } + + for (i = 0; i < bin_th; i++) + { + pos_vec[i] = 0; + } + + /* Quantize noise floor gains */ + for (i = 0; i < HVQ_NF_GROUPS; i++) + { + logqnorm(&nf_gains[i], &q_nf_gain_idx[i], 32, 1, &thren_HQ[0]); + nf_gains[i] = 0.5f*dicn[q_nf_gain_idx[i]]; + push_indice( st, IND_HVQ_NF_GAIN , q_nf_gain_idx[i], 5); + bits += 5; + } + + /* Signal number of peaks */ + i = max_peaks - vq_peaks; + push_indice( st, IND_NUM_PEAKS, i, 5); + bits += 5; + + /* Identify position of first peak and arrange peak gains by position */ + low_peak_bin = bin_th; + for (i = 0; i < vq_peaks; i++) + { + if (vq_peak_idx[i] < low_peak_bin) + { + low_peak_bin = vq_peak_idx[i]; + } + pos_vec[vq_peak_idx[i]] = (short) sign((float) coefs[vq_peak_idx[i]]); + } + + for (i = 0, j = 0; i < bin_th; i++) + { + if(pos_vec[i] != 0) + { + peak_gains[j] = (float) fabs(coefs[i]); + vq_peak_idx[j] = i; + j++; + } + } + + /* Scale down peak gains */ + for (i = 0; i < vq_peaks; i++) + { + peak_gains[i] *= 0.25f; + } + + /* Quantize peak gains */ + logqnorm(&peak_gains[0],&pgain_cb_idx[0],32,1,&thren_pg[0]); + for (i = 1; i < vq_peaks; i++) + { + logqnorm(&peak_gains[i],&pgain_cb_idx[i],45,1,&thren_pg[0]); + } + + /* Code quantized peak gain indices */ + diffcod(vq_peaks, pgain_cb_idx, &pgain_difidx[1]); + for(i = 0; i < vq_peaks; i++) + { + pgain_q[i] = dicn_pg[pgain_cb_idx[i]]; + } + pgain_difidx[0] = pgain_cb_idx[0]; + + /* Scale up peak gains and accumulate peak energy */ + manE_peak = 0; + expE_peak = 32; + for (i = 0; i < vq_peaks; i++) + { + pgain_q[i] *= 4.0f; + manPkEnrg = manPkEnrg_tbl[pgain_cb_idx[i]]; + expPkEnrg = expPkEnrg_tbl[pgain_cb_idx[i]]; + floating_point_add(&manE_peak, &expE_peak, manPkEnrg, expPkEnrg); + } + + /* Huffman coding */ + hcode_l = 0; + for (i = 1; i < vq_peaks; i++) + { + hcode_l += pgain_huffsizn[pgain_difidx[i]]; + } + + FlagN = HUFCODE; + + if (hcode_l >= GAINI_BITS * (vq_peaks - 1)) + { + hcode_l = GAINI_BITS * (vq_peaks - 1); + FlagN = NOHUFCODE; + } + + push_indice( st, IND_FLAGN, FlagN, 1); + push_indice( st, IND_PG_IDX, pgain_difidx[0], GAIN0_BITS); + + if (FlagN) + { + for (i = 1; i < vq_peaks; i++) + { + j = pgain_difidx[i]; + m = pgain_huffnorm[j]; + r = pgain_huffsizn[j]; + + push_indice( st, IND_PG_IDX, m, r ); + } + } + else + { + for (i = 1; i < vq_peaks; i++) + { + push_indice( st, IND_PG_IDX, pgain_difidx[i], GAINI_BITS ); + } + } + + /* Number of bits used for peak gain quantization */ + bits += FLAGN_BITS + GAIN0_BITS + hcode_l; + + /* Add sign for peak shape normalization */ + for (i = 0; i < vq_peaks; i++) + { + peak_gains[i] = pos_vec[vq_peak_idx[i]] * pgain_q[i]; + } + + /* Quantize peak shapes */ + for (i = 0; i < vq_peaks-1; i++) + { + num_overlap_bins = 5-(vq_peak_idx[i+1]-vq_peak_idx[i]); + quant_peaks( st, &coefs[vq_peak_idx[i]-2], &coefs_out[vq_peak_idx[i]-2], &peak_gains[i], &vq_cb_idx, num_overlap_bins, brate, vq_peaks ); + push_indice( st, IND_HVQ_PEAKS, vq_cb_idx, 8 ); + bits += 9; + } + + quant_peaks( st, &coefs[vq_peak_idx[i]-2], &coefs_out[vq_peak_idx[i]-2], &peak_gains[i], &vq_cb_idx, 0, brate, vq_peaks ); + push_indice( st, IND_HVQ_PEAKS, vq_cb_idx, 8 ); + bits += 9; + + pos_bits = hvq_code_pos( st, pos_vec, bin_th, vq_peaks ); + + bits += pos_bits; + bit_budget = num_bits - bits; + + /* Calculate number of PVQ bands to code and assign bits */ + pvq_bands = hvq_pvq_bitalloc(bit_budget, brate, st->bwidth, ynrm, manE_peak, expE_peak, Rk, R, sel_bnds, &n_sel_bnds ); + + /* Get band limits for concatenated PVQ target */ + hvq_concat_bands( pvq_bands, sel_bnds, n_sel_bnds, hvq_band_start, hvq_band_width, hvq_band_end ); + + /* Quantize PVQ bands */ + i = 0; + n = 0; + s = 0; + for (k = 0; k < pvq_bands; k++) + { + if( k >= pvq_bands - n_sel_bnds) + { + i = band_start_harm[sel_bnds[s]]; + s++; + } + k_sort[k] = (int) k; + j = 0; + pPvqVectorBandStart = &pvq_vector[n]; + while ( j < hvq_band_width[k] ) + { + if (coefs_out[i] == 0) + { + pvq_vector[n] = coefs[i]; + j++; + n++; + } + i++; + } + logqnorm( pPvqVectorBandStart, &pvq_norm[k], 40, hvq_band_width[k], &thren_HQ[0] ); + } + + normalizecoefs( pvq_vector, pvq_norm, pvq_bands, hvq_band_start, hvq_band_end ); + + bit_budget -= HVQ_PVQ_GAIN_BITS*pvq_bands; + for (k = 0; k < pvq_bands; k++) + { + Rk_f[k] = Rk[k] * 8; + } + + pvq_bits = bit_budget; + set_s( npulses, 0, MAX_PVQ_BANDS ); + + pvq_encode_frame( st, pvq_vector, coefs_pvq, gopt, npulses, pvq_inp_vector, hvq_band_start, + hvq_band_end, hvq_band_width, pvq_bands, Rk_f, pvq_bits, HQ_CORE ); + + for(i=0; i= pvq_bands - n_sel_bnds) + { + i = band_start_harm[sel_bnds[s++]]; + } + while (j < hvq_band_width[k]) + { + normq = dicn[pvq_norm[k]]; + if (coefs_out[i] == 0) + { + coefs_out[i] = coefs_pvq[n]*fg_pred[k]; + coefs_out[i] = coefs_out[i]*normq; + j++; + n++; + } + i++; + } + + } + + bits += pvq_bits; + + /* Noise fill unquantized coeffs with one gain per group */ + for (i = 0; i < HVQ_NF_GROUPS; i++) + { + for (j = i*(bin_th/HVQ_NF_GROUPS); j < (i+1)*(bin_th/HVQ_NF_GROUPS); j++) + { + if (coefs_out[j] == 0) + { + coefs_out[j] = ((float)own_random(&nf_seed)/MAX16B)*nf_gains[i]; + } + } + } + + return bits; +} + +/*-------------------------------------------------------------------------- + * quant_peaks() + * + * Applies VQ on input vector + *--------------------------------------------------------------------------*/ + +void quant_peaks( + Encoder_State *st, /* i/o: encoder state structure */ + const float *vect_in, /* i : Target vector */ + float *vect_out, /* i/o: Quantized vector */ + const float *peak_gain, /* i : Peak gain vector */ + short *vq_idx, /* o : Codebook index */ + const short overlap, /* i : Overlap indicator */ + const short brate, /* i : Core bitrate */ + const short Npeaks /* i : Number of peaks */ +) +{ + float x[4]; + float xq[4]; + short weights[4]; + short i, cb_class, search_overlap; + + set_s(weights,1,4); + + x[0] = vect_in[0] / (*peak_gain); + x[1] = vect_in[1] / (*peak_gain); + x[2] = vect_in[3] / (*peak_gain); + x[3] = vect_in[4] / (*peak_gain); + + if(vect_out[0] != 0 ) + { + if( fabs(peak_gain[-1]) > fabs(*peak_gain)) + { + weights[0] = 0; + + if (vect_out[1] != 0) + { + weights[1] = 0; + } + } + } + if(overlap > 0) + { + if( fabs(peak_gain[1]) > fabs(*peak_gain) ) + { + for(i = 3; i> 3-overlap; i--) + { + weights[i] = 0; + } + } + } + + + /* Classify */ + cb_class = (short) w_vquant(x, 0, weights, 0, hvq_class_c, HVQ_VQ_DIM-1, HVQ_NUM_CLASS, 0); + search_overlap = (brate == HQ_24k40) ? hvq_cb_search_overlap24k[HVQ_MAX_PEAKS_24k-Npeaks] : hvq_cb_search_overlap32k[HVQ_MAX_PEAKS_32k-Npeaks]; + + /* Quantize */ + if( cb_class == 0 ) + { + *vq_idx = (short) w_vquant(x, 0, weights, xq, hvq_peak_cb, 4, HVQ_CB_SIZE/2+search_overlap, 0); + push_indice( st, IND_HVQ_PEAKS, 0, 1 ); + } + else if( cb_class == 1 ) + { + *vq_idx = (short) w_vquant(x, 0, weights, xq, &hvq_peak_cb[HVQ_CB_SIZE*2-search_overlap*4], 4, HVQ_CB_SIZE/2+search_overlap, 0); + *vq_idx += HVQ_CB_SIZE/2-search_overlap; + push_indice( st, IND_HVQ_PEAKS, 0, 1 ); + } + else if( cb_class == 2 ) + { + *vq_idx = (short) w_vquant(x, 0, weights, xq, &hvq_peak_cb[HVQ_CB_SIZE*2-search_overlap*4], 4, HVQ_CB_SIZE/2+search_overlap, 1); + *vq_idx += HVQ_CB_SIZE/2-search_overlap; + push_indice( st, IND_HVQ_PEAKS, 1, 1 ); + } + else + { + *vq_idx = (short) w_vquant(x, 0, weights, xq, hvq_peak_cb, 4, HVQ_CB_SIZE/2+search_overlap, 1); + push_indice( st, IND_HVQ_PEAKS, 1, 1 ); + } + + vect_out[0] = weights[0] * (xq[0] * (*peak_gain)) + (weights[0]^1)*vect_out[0]; + vect_out[1] = weights[1] * (xq[1] * (*peak_gain)) + (weights[1]^1)*vect_out[1]; + vect_out[2] = *peak_gain; + vect_out[3] = weights[2] * (xq[2] * (*peak_gain)) + (weights[2]^1)*vect_out[3]; + vect_out[4] = weights[3] * (xq[3] * (*peak_gain)) + (weights[3]^1)*vect_out[4]; + + return; +} + +/*-------------------------------------------------------------------------- + * code_pos() + * + * Code pulse positions + *--------------------------------------------------------------------------*/ + +static short sparse_code_pos( + const short *inp, + const short length, + short *result +) +{ + short layer2[HVQ_CP_L2_MAX]; + short layer_length; + short i,j; + short val, idx; + short bits = 0; + short mask; + + set_s(layer2, 0, HVQ_CP_L2_MAX); + + layer_length = (short)((float)length/HVQ_CP_L1_LEN + 0.5); + + for (j = 0; j < layer_length; j++) + { + for (i = j*HVQ_CP_L1_LEN; i < min((j+1)*HVQ_CP_L1_LEN, length); i++) + { + if (inp[i]) + { + layer2[j] = 1; + break; + } + } + } + + for (i = 0; i < layer_length; i++) + { + result[i] = layer2[i]; + } + bits += layer_length; + + for (j = 0; j < layer_length; j++) + { + if (layer2[j]) + { + val = 0; + for (i = j*HVQ_CP_L1_LEN; i < min((j+1)*HVQ_CP_L1_LEN, length); i++) + { + val <<= 1; + val |= inp[i]; + } + + for (idx = 0; idx < HVQ_CP_MAP_LEN; idx++) + { + if (hvq_cp_layer1_map5[idx] == val) + { + break; + } + } + + mask = 1<<(HVQ_CP_MAP_IDX_LEN - 1); + for (i = 0; i < HVQ_CP_MAP_IDX_LEN; i++) + { + result[bits++] = (idx&mask) >> (HVQ_CP_MAP_IDX_LEN - 1 - i); + mask >>= 1; + } + } + } + + return bits; +} + +/*-------------------------------------------------------------------------- + * hvq_code_pos() + * + * Code pulse positions + *--------------------------------------------------------------------------*/ + +static short hvq_code_pos( + Encoder_State *st, /* i/o: encoder state structure */ + const short *inp, + const short length, + const short num_peaks +) +{ + short sparse_result[4*HVQ_THRES_BIN_32k/HVQ_CP_L1_LEN]; + short delta[HVQ_MAX_PEAKS_32k]; + short peak_idx[HVQ_MAX_PEAKS_32k]; + short inp_abs[HVQ_THRES_BIN_32k]; + short inp_sign[HVQ_MAX_PEAKS_32k]; + + short i, j; + short bits; + short delta_max; + short delta_bits, sparse_bits; + + bits = 0; + + /* Extract sorted peak index vector and sign vector */ + for (i = 0, j = 0; i < length; i++) + { + inp_abs[i] = (short)abs(inp[i]); + if (inp[i]) + { + peak_idx[j] = i; + inp_sign[j++] = inp[i]; + } + } + + /* Calculate delta */ + delta[0] = peak_idx[0] + HVQ_CP_HUFF_OFFSET; + delta_max = delta[0]; + for (i = 1; i < num_peaks; i++) + { + delta[i] = peak_idx[i] - peak_idx[i-1] - HVQ_CP_HUFF_OFFSET; + if (delta_max < delta[i]) + { + delta_max = delta[i]; + } + } + + /* Calculate bits needed for huffman coding of deltas */ + delta_bits = -1; + if (delta_max <= HVQ_CP_HUFF_MAX) + { + delta_bits = 0; + for (i = 0; i < num_peaks; i++) + { + delta_bits += hvq_cp_huff_len[delta[i]]; + } + } + + /* Calculate bits neeed for sparse coding */ + sparse_bits = sparse_code_pos(inp_abs, length, sparse_result); + + /* Decide which coding mode to use */ + if (delta_bits > sparse_bits || delta_bits < 0) + { + push_indice(st, IND_POS_IDX, HVQ_CP_SPARSE, 1); + + for (i = 0; i < sparse_bits; i++) + { + push_indice(st, IND_POS_IDX, sparse_result[i], 1); + } + bits += sparse_bits + 1; + } + else + { + push_indice(st, IND_POS_IDX, HVQ_CP_DELTA, 1); + + for (i = 0; i < num_peaks; i++) + { + j = delta[i]; + push_indice(st, IND_POS_IDX, hvq_cp_huff_val[j], hvq_cp_huff_len[j]); + } + bits += delta_bits + 1; + } + + /* Send sign */ + for (i = 0; i < num_peaks; i++) + { + push_indice(st, IND_POS_IDX, (inp_sign[i] < 0 ? 0 : 1), 1); + } + bits += num_peaks; + + return bits; +} + diff --git a/src/libs/libevs/lib_enc/peak_vq_enc_fx.cpp b/src/libs/libevs/lib_enc/peak_vq_enc_fx.cpp deleted file mode 100755 index 894a0c84..00000000 --- a/src/libs/libevs/lib_enc/peak_vq_enc_fx.cpp +++ /dev/null @@ -1,782 +0,0 @@ -/*==================================================================================== - EVS Codec 3GPP TS26.442 Apr 03, 2018. Version 12.11.0 / 13.6.0 / 14.2.0 - ====================================================================================*/ - -#include -#include "options.h" /* Compilation switches */ -#include "cnst_fx.h" /* Common constants */ -#include "prot_fx.h" -#include "rom_enc_fx.h" -#include "rom_com_fx.h" -#include "stl.h" /* required for wmc_tool */ - -/*-------------------------------------------------------------------------- - * Local functions - *--------------------------------------------------------------------------*/ - -static void quant_peaks_fx(Encoder_State_fx *, const Word32*, Word32*, const Word32*, - Word16*, const Word16, const Word32, const Word16); -static Word16 hvq_code_pos_fx(Encoder_State_fx *st_fx, const Word16 *inp, const Word16 length, const Word16 num_peaks); -static Word16 sparse_code_pos_fx(const Word16 *inp, const Word16 length, Word16 *result); - -/*-------------------------------------------------------------------------- - * peak_vq_enc_fx() - * - * Vector Quantization of MDCT peaks - *--------------------------------------------------------------------------*/ - -Word16 peak_vq_enc_fx( - Encoder_State_fx *st_fx, /* i/o: encoder state structure */ - const Word32 *coefs, /* i : Input coefficient vector Q12 */ - Word32 *coefs_out, /* o : Quantized output vector Q12 */ - const Word32 brate, /* i : Core bitrate */ - const Word16 num_bits, /* i : Number of bits for HVQ */ - const Word16 vq_peaks, /* i : Number of identified peaks */ - const Word16 *ynrm, /* i : Envelope coefficients */ - Word16 *R, /* i/o: Bit allocation/updated bit allocation */ - Word16 *vq_peak_idx, /* i : Peak index vector */ - Word32 *nf_gains /* i : Estimated noise floor gains Q12 */ -) -{ - Word16 pos_bits; - Word32 normq; - Word32 pgain_q[HVQ_MAX_PEAKS_32k]; - Word32 peak_gains[HVQ_MAX_PEAKS_32k]; - Word16 coefs_pvq[HVQ_PVQ_BUF_LEN], *pCoefsPvq; /* Q12 */ - Word32 pvq_vector[HVQ_PVQ_BUF_LEN], *pPvqVector; - Word32 *pPvqVectorBandStart; - Word16 pvq_vector_norm[HVQ_PVQ_BUF_LEN]; - Word16 fg_pred[NB_SFM_MAX]; - Word16 i, j, k, m, r, pvq_bands, num_overlap_bins; - Word16 hcode_l, FlagN, low_peak_bin, vq_cb_idx, max_peaks, bin_th, bin_th2; - Word16 bits; - Word16 nf_seed; - Word16 pgain_cb_idx[HVQ_MAX_PEAKS], pgain_difidx[HVQ_MAX_PEAKS]; /* Q0 */ - Word16 pvq_norm[MAX_PVQ_BANDS]; - Word16 pvq_bits, bit_budget; - Word16 pos_vec[HVQ_THRES_BIN_32k]; - Word16 npulses[MAX_PVQ_BANDS]; - Word16 pvq_inp_vector[HVQ_PVQ_BUF_LEN]; - Word16 k_sort[MAX_PVQ_BANDS]; - Word16 Rk[MAX_PVQ_BANDS]; - Word16 gopt[NB_SFM]; - Word16 tmp1, exp1; - Word16 Q_coefs; - - - Word16 indx, vqPeaksMinus1, tmp16, whiteNoise; - Word16 *pPgainDifIdx, *pPgainCbIdx, *pVqPeakIdx, *pPosVec; - Word32 *pPeakGains, *pCoefsOut; - const Word32 *pCoefs; - Word32 acc; - UWord16 dontCare16; - Word32 manE_peak, manPeakGains, manPkEnrg; /* Due to very wide dynamic range, use floating point format, i.e., (man, exp) */ - Word16 expE_peak, expPeakGains, expPkEnrg; - Word16 *pSelBnds; - Word16 sel_bnds[HVQ_NUM_SFM_24k]; - Word16 hvq_band_end[MAX_PVQ_BANDS]; - Word16 hvq_band_start[MAX_PVQ_BANDS]; - Word16 hvq_band_width[MAX_PVQ_BANDS]; - Word16 n_sel_bnds; - UWord32 lsb; - bits = 0; - move16(); - nf_seed = RANDOM_INITSEED; - move16(); - - - set16_fx(coefs_pvq, 0, HVQ_PVQ_BUF_LEN ); - set32_fx(pvq_vector, 0, HVQ_PVQ_BUF_LEN ); - set16_fx(pvq_vector_norm, 0, HVQ_PVQ_BUF_LEN ); - set16_fx(npulses, 0, MAX_PVQ_BANDS ); - - /* Set bit-rate dependent variables */ - IF (L_sub(brate, HQ_24k40) == 0) - { - max_peaks = HVQ_MAX_PEAKS_24k; - move16(); - bin_th = HVQ_THRES_BIN_24k; - move16(); - bin_th2 = HVQ_THRES_BIN_24k/HVQ_NF_GROUPS; - move16(); - } - ELSE - { - max_peaks = HVQ_MAX_PEAKS_32k; - move16(); - bin_th = HVQ_THRES_BIN_32k; - move16(); - bin_th2 = HVQ_THRES_BIN_32k/HVQ_NF_GROUPS; - move16(); - } - - FOR (i = 0; i < bin_th; i++) - { - pos_vec[i] = 0; - move16(); - } - - /* Quantize noise floor gains */ - FOR (i = 0; i < HVQ_NF_GROUPS; i++) - { - logqnorm_fx(&nf_gains[i], 12, &indx, 32, 1, 0); - - /* De-quantization */ - acc = L_add(dicn_fx[indx], 0); /* Q14 */ - nf_gains[i] = L_shr(acc, 1 + 2); /* nf_gains in Q12. dicn_fx is in Q14. Need extra shift +2. */ - push_indice_fx(st_fx, IND_HVQ_NF_GAIN , (int)indx, 5); - bits = add(bits, 5); - } - - /* Signal number of peaks */ - i = sub(max_peaks, vq_peaks); - push_indice_fx(st_fx, IND_NUM_PEAKS, (int)i, 5); - bits = add(bits, 5); - - /* Identify position of first peak and arrange peak gains by position */ - pVqPeakIdx = &vq_peak_idx[0]; - low_peak_bin = bin_th; - FOR (i = 0; i < vq_peaks; i++) - { - indx = *pVqPeakIdx++; - move16(); - IF (sub(indx, low_peak_bin) < 0) - { - low_peak_bin = indx; - move16(); - } - /* Store the sign information. */ - IF ( coefs[indx] < 0) - { - pos_vec[indx] = -1; /* Negative. */ move16(); - } - ELSE - { - pos_vec[indx] = 1; /* Positive */ move16(); - } - } - - pPeakGains = &peak_gains[0]; - pVqPeakIdx = &vq_peak_idx[0]; - pPosVec = &pos_vec[0]; - pCoefs = &coefs[0]; - FOR (i = 0; i < bin_th; i++) - { - acc = *pCoefs++; - IF(*pPosVec++ != 0) - { - *pPeakGains++ = L_abs(acc); /* in Q12 */ move32(); - *pVqPeakIdx++ = i; - move16(); - } - } - - /* Scale down peak gains */ - /* Divided by 4 is equivalent to consider peak_gains to be in Q14 from Q12. - * No physical bit shift is actually required. - */ - - /* Quantize peak gains */ - pPeakGains = &peak_gains[0]; - pPgainCbIdx = &pgain_cb_idx[0]; - logqnorm_fx(pPeakGains++, 14, pPgainCbIdx++, 32, 1, 1); - vqPeaksMinus1 = sub(vq_peaks, 1); - FOR (i = 0; i < vqPeaksMinus1; i++) - { - logqnorm_fx(pPeakGains++, 14, pPgainCbIdx++, 45, 1, 1); - } - - /* Code quantized peak gain indices - * and also scale up peak gains. */ - diffcod_fx(vq_peaks, pgain_cb_idx, &pgain_difidx[1]); - /* Accumulate peak energy. */ - manE_peak = L_deposit_l(0); - expE_peak = 32; - move16(); - FOR (i = 0; i < vq_peaks; i++) - { - indx = pgain_cb_idx[i]; - move16(); - /* Scale up peak gains */ - pgain_q[i] = L_shl(dicn_pg_fx[indx], 2); /* pgain_q in Q12 */ move32(); - /* Use floating point operation to deal with wide dynamic range.l - * 32-bit mantissa is used here. It should be even more accurate than - * the floating-point reference code with 24-bit mantissa! */ - expPeakGains = norm_l(pgain_q[i]); - manPeakGains = L_shl(pgain_q[i], expPeakGains); - Mpy_32_32_ss(manPeakGains, manPeakGains, &manPkEnrg, &lsb); /* peak_gains square */ - expPkEnrg = shl(expPeakGains, 1); /* Multiply by 2 due to squaring. */ - /* True floating value = manPkEng x 2^(32 - 1 - expPkEnrg - 2*12). - * In this context, the 32-bit manPkEng is in Q0. - * 32 is due to Mpy_32_32() only providing the 32 MSBs of the 64 bits product. - * -1 is due fractional mode Multiply. 2*12 is due to square of Q12. */ - floating_point_add(&manE_peak, &expE_peak, manPkEnrg, expPkEnrg); - } - pgain_difidx[0] = pgain_cb_idx[0]; - move16(); - - /* Huffman coding */ - hcode_l = 0; - pPgainDifIdx = &pgain_difidx[1]; - FOR (i = 0; i < vqPeaksMinus1; i++) - { - indx = *pPgainDifIdx++; - move16(); - hcode_l = add(hcode_l, pgain_huffsizn[indx]); - } - - FlagN = HUFCODE; - move16(); - - tmp16 = extract_l(L_mult0(GAINI_BITS, vqPeaksMinus1)); - IF ( sub(hcode_l, tmp16) >= 0) - { - hcode_l = tmp16; - move16(); - FlagN = NOHUFCODE; - move16(); - } - - push_indice_fx(st_fx, IND_FLAGN, (int)FlagN, 1); - push_indice_fx(st_fx, IND_PG_IDX, (int)pgain_difidx[0], GAIN0_BITS); - - IF (FlagN) - { - pPgainDifIdx = &pgain_difidx[1]; - FOR (i = 0; i < vqPeaksMinus1; i++) - { - j = *pPgainDifIdx++; - move16(); - m = pgain_huffnorm_fx[j]; - move16(); - r = pgain_huffsizn[j]; - move16(); - - push_indice_fx(st_fx, IND_PG_IDX, (int)m, r ); - } - } - ELSE - { - pPgainDifIdx = &pgain_difidx[1]; - FOR (i = 0; i < vqPeaksMinus1; i++) - { - push_indice_fx(st_fx, IND_PG_IDX, (int)(*pPgainDifIdx++), GAINI_BITS ); - } - } - - /* Number of bits used for peak gain quantization */ - bits = add(bits, add(FLAGN_BITS + GAIN0_BITS, hcode_l)); - - /* Add sign for peak shape normalization */ - FOR (i = 0; i < vq_peaks; i++) - { - indx = vq_peak_idx[i]; - move16(); - peak_gains[i] = pgain_q[i]; /* Q12 */ move32(); - IF (pos_vec[indx] < 0) - { - peak_gains[i] = L_negate(peak_gains[i]); /* Q12 */ - } - } - - /* Quantize peak shapes */ - FOR (i = 0; i < vqPeaksMinus1; i++) - { - num_overlap_bins = sub(5, sub(vq_peak_idx[i+1], vq_peak_idx[i])); - indx = sub(vq_peak_idx[i], 2); - quant_peaks_fx(st_fx, &coefs[indx], &coefs_out[indx], &peak_gains[i], &vq_cb_idx, num_overlap_bins, brate, vq_peaks); - push_indice_fx(st_fx, IND_HVQ_PEAKS, (UWord16)vq_cb_idx, 8 ); - bits = add(bits, 9); - } - - indx = sub(vq_peak_idx[i], 2); - quant_peaks_fx(st_fx, &coefs[indx], &coefs_out[indx], &peak_gains[i], &vq_cb_idx, 0, brate, vq_peaks); - push_indice_fx(st_fx, IND_HVQ_PEAKS, (UWord16)vq_cb_idx, 8 ); - bits = add(bits, 9); - - /* Quantize peak positions and sign with HVQ */ - pos_bits = hvq_code_pos_fx( st_fx, pos_vec, bin_th, vq_peaks ); - - bits = add(bits, pos_bits); - bit_budget = sub(num_bits, bits); - - /* Calculate number of PVQ bands to code and assign bits */ - pvq_bands = hvq_pvq_bitalloc_fx(bit_budget, brate, st_fx->bwidth_fx, ynrm, manE_peak, expE_peak, Rk, R, sel_bnds, - &n_sel_bnds); - - /* Get band limits for concatenated PVQ target */ - hvq_concat_bands_fx(pvq_bands, sel_bnds, n_sel_bnds, hvq_band_start, - hvq_band_width, hvq_band_end); - - /* Quantize PVQ bands */ - pCoefsOut = coefs_out; - pCoefs = coefs; - pPvqVector = pvq_vector; - pSelBnds = sel_bnds; - m = bin_th; - move16(); - FOR (k = 0; k < pvq_bands; k++) - { - IF (sub(k, sub(pvq_bands, n_sel_bnds)) >= 0) - { - i = band_start_harm[*pSelBnds++]; - move16(); - pCoefs = coefs + i; - pCoefsOut = coefs_out + i; - } - k_sort[k] = k; - j = 0; - move16(); - pPvqVectorBandStart = pPvqVector; - WHILE (sub(j, hvq_band_width[k]) < 0) - { - IF (*pCoefsOut++ == 0) - { - *pPvqVector++ = *pCoefs; /* Q12 */ move32(); - j = add(j, 1); - } - pCoefs++; - } - logqnorm_fx( pPvqVectorBandStart, 12, &pvq_norm[k], 40, hvq_band_width[k], 0 ); - - } - - /* Normalize coefficients */ - normalizecoefs_fx( pvq_vector, pvq_norm, pvq_bands, hvq_band_start, hvq_band_end, pvq_vector_norm ); - Q_coefs = 12; - move16(); - - bit_budget = sub(bit_budget, i_mult2(HVQ_PVQ_GAIN_BITS, pvq_bands)); - - pvq_bits = bit_budget; - move16(); - set16_fx( npulses, 0, MAX_PVQ_BANDS ); - - pvq_encode_frame_fx(st_fx, pvq_vector_norm, Q_coefs, coefs_pvq, gopt, npulses, pvq_inp_vector, hvq_band_start, hvq_band_end, hvq_band_width, pvq_bands, - Rk, pvq_bits, HQ_CORE ); - - FOR (i = 0; i < pvq_bands; i++) - { - k_sort[i] = i; - move16(); - } - - - fine_gain_pred_fx( hvq_band_start, hvq_band_end, hvq_band_width, k_sort, npulses, NULL, NULL, pvq_bands, coefs_pvq, - pvq_inp_vector, fg_pred, HQ_CORE ); - - pCoefsOut = &coefs_out[0]; - pSelBnds = &sel_bnds[0]; - pCoefsPvq = &coefs_pvq[0]; - FOR (k = 0; k < pvq_bands; k++) - { - indx = pvq_norm[k]; - tmp1 = ratio(gopt[k], fg_pred[k], &exp1); - tmp1 = shr(tmp1, sub(1, exp1)); /* Q13 */ - Mpy_32_16_ss(dicn_fx[indx], tmp1, &normq, &dontCare16); /* dicn_fx in Q14, sorted_pvq_gain_pred_err_fx in Q13. */ - - logqnorm_fx(&normq, 12, &pvq_norm[k], 40, 1, 0); /* normq in Q(14+(16+13)+1-32)=Q12 */ - pvq_norm[k] = sub(pvq_norm[k], 8); - IF (pvq_norm[k] < 0) - { - pvq_norm[k] = 0; - move16(); - } - - push_indice_fx(st_fx, IND_HVQ_PVQ_GAIN, pvq_norm[k], HVQ_PVQ_GAIN_BITS); - pvq_bits = add(pvq_bits, HVQ_PVQ_GAIN_BITS); - - pvq_norm[k] = add(pvq_norm[k], 8); - - indx = pvq_norm[k]; - move16(); - normq = L_add(dicn_fx[indx], 0); /* in Q14 */ - j = 0; - move16(); - IF (sub(k, sub(pvq_bands, n_sel_bnds)) >= 0) - { - i = band_start_harm[*pSelBnds++]; - move16(); - pCoefsOut = coefs_out + i; - } - WHILE (sub(j, hvq_band_width[k]) < 0) - { - IF (L_sub(*pCoefsOut, 0) == 0) - { - acc = L_mult(*pCoefsPvq++, fg_pred[k]); /* in Q(15 + 1 + 12 = 28) */ - tmp16 = extract_h(acc); /* in Q(28 - 16 = 12) */ - Mpy_32_16_ss(normq, tmp16, &acc, &dontCare16); /* acc(Q11), normq(Q14), tmp16(Q12) */ - *pCoefsOut = L_shl(acc, 12 - 11); /* Q12 */ - j = add(j, 1); - } - pCoefsOut++; - } - } - bits = add(bits, pvq_bits); - - /* Noise fill unqantized coeffs with one gain per group */ - pCoefsOut = &coefs_out[-1]; - FOR (i = 0; i < HVQ_NF_GROUPS; i++) - { - FOR (j = 0; j < bin_th2; j++) - { - IF (*(++pCoefsOut) == 0) - { - whiteNoise = Random(&nf_seed); /* Q15 */ - Mpy_32_16_ss(nf_gains[i], whiteNoise, pCoefsOut, &dontCare16); /* nf_gains in Q12. *pCoefsOut in Q12 */ - } - } - } - - return bits; -} - -/*-------------------------------------------------------------------------- - * quant_peaks_fx() - * - * Applies VQ on input vector - *--------------------------------------------------------------------------*/ - -static void quant_peaks_fx( - Encoder_State_fx *st_fx, /* i/o: encoder state structure */ - const Word32 *vect_in, /* i : Target vector in Q12 */ - Word32 *vect_out, /* i/o: Quantized vector in Q12 */ - const Word32 *peak_gain, /* i : Peak gain vector in Q12 */ - Word16 *vq_idx, /* o : Codebook index */ - const Word16 overlap, /* i : Overlap indicator */ - const Word32 brate, /* i : Core bitrate */ - const Word16 Npeaks /* i : Number of peaks */ -) -{ - Word16 x[4]; /* Qx */ - Word16 xq[4]; /* Q15 */ - Word16 weights[4]; /* Q0 */ - Word16 *pWeights; - Word16 i, cb_class, search_overlap, indx, cbSize; - Word16 expPeakGain, manPeakGain, expIn, manIn; - Word32 vectIn, absPeakGain1, absPeakGain; - UWord16 dontCare; - Word16 Qx_vec[4]; - Word16 Qx = 15; - - set16_fx(weights,1,4); - - /* Divide vect_in[] by peak_gain to yield x[]. */ - expPeakGain = norm_l(*peak_gain); /* exponent */ - manPeakGain = extract_h(L_shl(*peak_gain, expPeakGain)); /* mantissa */ - manPeakGain = abs_s(manPeakGain); /* Prepare for div_s() only accepting +ve. */ - FOR (i = 0; i < 4; i++) - { - indx = hvq_index_mapping_fx[i]; - move16(); - vectIn = L_add(vect_in[indx], 0); - expIn = norm_l(vectIn); /* exponent */ - expIn = sub(expIn, 1); - expIn = s_min(expIn, expPeakGain); /* highest Q is Q15 */ - manIn = extract_h(L_shl(vectIn, expIn)); /* mantissa */ - manIn = abs_s(manIn); /* Prepare for div_s() only accepting +ve. */ - - x[i] = div_s(manIn, manPeakGain); /* in Q(15+expIn-expPeakGain) */ - - Qx_vec[i] = add(15, sub(expIn, expPeakGain)); - Qx = s_min(Qx, Qx_vec[i]); - - /* Restore the sign destroyed by abs operations. */ - if (L_xor(vectIn, *peak_gain) < 0) /* Check the sign bits (MSB). */ - { - x[i] = negate(x[i]); - } - } - FOR (i = 0; i < 4; i++) - { - IF (sub(Qx_vec[i], Qx) != 0) - { - x[i] = shr(x[i], sub(Qx_vec[i], Qx)); /* Qx */ - } - } - absPeakGain = L_abs(peak_gain[0]); - IF (vect_out[0] != 0) - { - absPeakGain1 = L_abs(peak_gain[-1]); - IF (L_sub(absPeakGain1, absPeakGain) > 0) - { - weights[0] = 0; - move16(); - if (vect_out[1] != 0) - { - weights[1] = 0; - move16(); - } - } - } - IF (overlap > 0) - { - absPeakGain1 = L_abs(peak_gain[1]); - IF (L_sub(absPeakGain1, absPeakGain) > 0) - { - indx = sub(4, overlap); - pWeights = &weights[indx]; - FOR (i = 0; i < overlap; i++) - { - *pWeights++ = 0; - move16(); - } - } - } - - /* Classify */ -#if HVQ_VQ_DIM != 5 -#error w_vquant_fx() is hard-wired to dim = 4 = (HVQ_VQ_DIM - 1). -#endif - cb_class = w_vquant_fx(x, Qx, weights, 0, hvq_class_c_fx, HVQ_NUM_CLASS, 0); - IF (brate == HQ_24k40) - { - indx = sub(HVQ_MAX_PEAKS_24k, Npeaks); - search_overlap = hvq_cb_search_overlap24k[indx]; - move16(); - } - ELSE - { - indx = sub(HVQ_MAX_PEAKS_32k, Npeaks); - search_overlap = hvq_cb_search_overlap32k[indx]; - move16(); - } - - /* Quantize */ - cbSize = add(HVQ_CB_SIZE/2, search_overlap); - IF ( cb_class == 0 ) - { - *vq_idx = w_vquant_fx(x, Qx, weights, xq, hvq_peak_cb_fx, cbSize, 0); - push_indice_fx(st_fx, IND_HVQ_PEAKS, 0, 1 ); - } - ELSE IF( sub(cb_class, 1) == 0 ) - { - indx = sub(HVQ_CB_SIZE*2, shl(search_overlap,2)); - *vq_idx = w_vquant_fx(x, Qx, weights, xq, &hvq_peak_cb_fx[indx], cbSize, 0); - *vq_idx = add(*vq_idx, sub(HVQ_CB_SIZE/2, search_overlap)); - push_indice_fx(st_fx, IND_HVQ_PEAKS, 0, 1 ); - } - ELSE IF( sub(cb_class, 2) == 0 ) - { - indx = sub(HVQ_CB_SIZE*2, shl(search_overlap,2)); - *vq_idx = w_vquant_fx(x, Qx, weights, xq, &hvq_peak_cb_fx[indx], cbSize, 1); - *vq_idx = add(*vq_idx, sub(HVQ_CB_SIZE/2, search_overlap)); - push_indice_fx(st_fx, IND_HVQ_PEAKS, 1, 1 ); - } - ELSE - { - *vq_idx = w_vquant_fx(x, Qx, weights, xq, hvq_peak_cb_fx, cbSize, 1); - push_indice_fx(st_fx, IND_HVQ_PEAKS, 1, 1 ); - } - - FOR (i = 0; i < 4; i++) - { - indx = hvq_index_mapping_fx[i]; - move16(); - IF (weights[i] != 0) - { - Mpy_32_16_ss(*peak_gain, xq[i], &vect_out[indx], &dontCare); /* peak_gains in Q12, xq in Q15 -> Q12. */ - move32(); - } - } - vect_out[2] = *peak_gain; - move32(); /* vect_out in Q12 */ - - return; -} - -/*-------------------------------------------------------------------------- - * code_pos() - * - * Code pulse positions - *--------------------------------------------------------------------------*/ - -static Word16 sparse_code_pos_fx( - const Word16 *inp, - const Word16 length, - Word16 *result -) -{ - Word16 layer2[HVQ_CP_L2_MAX]; - Word16 layer_length; - Word16 i,j,tmp; - Word16 val, idx; - Word16 bits = 0; - Word16 mask; - - set16_fx(layer2, 0, HVQ_CP_L2_MAX); - - /*layer_length = (short)((float)length/HVQ_CP_L1_LEN + 0.5); */ - layer_length = round_fx(L_mult0(length, 13107)); /* 0+16-16, 13107 is 1/5 in Q16 */ - - FOR (j = 0; j < layer_length; j++) - { - tmp = s_min(i_mult2(add(j,1),HVQ_CP_L1_LEN), length); - FOR (i = i_mult2(j, HVQ_CP_L1_LEN); i < tmp; i++) - { - IF (inp[i] != 0) - { - layer2[j] = 1; - move16(); - BREAK; - } - } - } - - FOR (i = 0; i < layer_length; i++) - { - result[i] = layer2[i]; - move16(); - } - bits = add(bits, layer_length); - - FOR (j = 0; j < layer_length; j++) - { - IF (layer2[j] != 0) - { - val = 0; - move16(); - tmp = s_min(i_mult2(add(j,1),HVQ_CP_L1_LEN), length); - FOR (i = i_mult2(j, HVQ_CP_L1_LEN); i < tmp; i++) - { - val = shl(val, 1); - val = s_or(val, inp[i]); - } - - FOR (idx = 0; idx < HVQ_CP_MAP_LEN; idx++) - { - IF (sub(hvq_cp_layer1_map5[idx], val) == 0) - { - BREAK; - } - } - - mask = shl(1, HVQ_CP_MAP_IDX_LEN - 1); - FOR (i = 0; i < HVQ_CP_MAP_IDX_LEN; i++) - { - result[bits++] = shr(s_and(idx, mask), sub(HVQ_CP_MAP_IDX_LEN - 1, i)); - mask >>= 1; - } - } - } - - return bits; -} - -/*-------------------------------------------------------------------------- - * hvq_code_pos() - * - * Code pulse positions - *--------------------------------------------------------------------------*/ - -static Word16 hvq_code_pos_fx( - Encoder_State_fx *st_fx, /* i/o: encoder state structure */ - const Word16 *inp, - const Word16 length, - const Word16 num_peaks -) -{ - Word16 sparse_result[4*HVQ_THRES_BIN_32k/HVQ_CP_L1_LEN]; - Word16 delta[HVQ_MAX_PEAKS_32k]; - Word16 peak_idx[HVQ_MAX_PEAKS_32k]; - Word16 inp_abs[HVQ_THRES_BIN_32k]; - Word16 inp_sign[HVQ_MAX_PEAKS_32k]; - - Word16 i, j; - Word16 bits; - Word16 delta_max; - Word16 delta_bits, sparse_bits; - Word16 tmp; - - bits = 0; - move16(); - - /* Extract sorted peak index vector and sign vector */ - j = 0; - move16(); - FOR(i = 0; i < length; i++) - { - inp_abs[i] = abs_s(inp[i]); - IF (inp[i] != 0) - { - peak_idx[j] = i; - move16(); - inp_sign[j] = inp[i]; - move16(); - j = add(j, 1); - } - } - - /* Calculate delta */ - delta[0] = add(peak_idx[0], HVQ_CP_HUFF_OFFSET); - move16(); - delta_max = delta[0]; - move16(); - FOR (i = 1; i < num_peaks; i++) - { - delta[i] = sub(sub(peak_idx[i], peak_idx[i-1]), HVQ_CP_HUFF_OFFSET); - if (sub(delta_max, delta[i]) < 0) - { - delta_max = delta[i]; - move16(); - } - } - - /* Calculate bits needed for huffman coding of deltas */ - delta_bits = -1; - move16(); - IF (sub(delta_max, HVQ_CP_HUFF_MAX) <= 0) - { - delta_bits = 0; - move16(); - FOR (i = 0; i < num_peaks; i++) - { - delta_bits = add(delta_bits, hvq_cp_huff_len[delta[i]]); - } - } - - /* Calculate bits neeed for sparse coding */ - sparse_bits = sparse_code_pos_fx(inp_abs, length, sparse_result); - - /* Decide which coding mode to use */ - test(); - IF (sub(delta_bits, sparse_bits) > 0 || delta_bits < 0) - { - push_indice_fx(st_fx, IND_POS_IDX, HVQ_CP_SPARSE, 1); - - FOR (i = 0; i < sparse_bits; i++) - { - push_indice_fx(st_fx, IND_POS_IDX, sparse_result[i], 1); - } - bits = add(add(bits, sparse_bits), 1); - } - ELSE - { - push_indice_fx(st_fx, IND_POS_IDX, HVQ_CP_DELTA, 1); - - FOR (i = 0; i < num_peaks; i++) - { - j = delta[i]; - move16(); - push_indice_fx(st_fx, IND_POS_IDX, hvq_cp_huff_val[j], hvq_cp_huff_len[j]); - } - bits = add(add(bits, delta_bits), 1); - } - - /* Send sign */ - FOR (i = 0; i < num_peaks; i++) - { - tmp = 1; - move16(); - if (inp_sign[i] < 0) - { - tmp = 0; - move16(); - } - push_indice_fx(st_fx, IND_POS_IDX, tmp, 1); - } - bits = add(bits, num_peaks); - - return bits; -} - diff --git a/src/libs/libevs/lib_enc/pit_enc.cpp b/src/libs/libevs/lib_enc/pit_enc.cpp new file mode 100644 index 00000000..1e096e2d --- /dev/null +++ b/src/libs/libevs/lib_enc/pit_enc.cpp @@ -0,0 +1,1319 @@ +/*==================================================================================== + EVS Codec 3GPP TS26.443 Nov 13, 2018. Version 12.11.0 / 13.7.0 / 14.3.0 / 15.1.0 + ====================================================================================*/ + +#include +#include +#include +#include +#include "cnst.h" +#include "prot.h" +#include "rom_enc.h" +#include "rom_com.h" + + +/*------------------------------------------------------------------* + * pit_encode() + * + * Close-loop pitch lag search and pitch lag quantization + * Adaptive excitation construction + *------------------------------------------------------------------*/ + +float pit_encode( /* o : Fractional pitch for each subframe */ + Encoder_State *st, /* i/o: encoder state structure */ + const long core_brate, /* i : core bitrate */ + const short Opt_AMR_WB, /* i : flag indicating AMR-WB IO mode */ + const short L_frame, /* i : length of the frame */ + const short coder_type, /* i : coding type */ + short *limit_flag, /* i/o: restrained(0) or extended(1) Q limits */ + const short i_subfr, /* i : subframe index */ + float *exc, /* i/o: pointer to excitation signal frame */ + const short L_subfr, /* i : subframe length */ + const short *T_op, /* i : open loop pitch estimates in current frame */ + short *T0_min, /* i/o: lower limit for close-loop search */ + short *T0_max, /* i/o: higher limit for close-loop search */ + short *T0, /* i/o: close loop integer pitch */ + short *T0_frac, /* i/o: close loop fractional part of the pitch */ + const float *h1, /* i : weighted filter input response */ + const float *xn /* i : target vector */ +) +{ + float pitch; + short pit_flag, delta, mult_Top, nBits; + + /*----------------------------------------------------------------* + * Initializations + *----------------------------------------------------------------*/ + + /* Set pit_flag to 0 for every subframe with absolute pitch search */ + pit_flag = i_subfr; + if( i_subfr == 2*L_SUBFR ) + { + pit_flag = 0; + } + + /*-----------------------------------------------------------------* + * Limit range of pitch search + * Fractional pitch search + * Pitch quantization + *-----------------------------------------------------------------*/ + + mult_Top = 1; + + if( !Opt_AMR_WB ) + { + /*----------------------------------------------------------------* + * Set limit_flag to 0 for restrained limits, and 1 for extended limits + *----------------------------------------------------------------*/ + + if( i_subfr == 0 ) + { + *limit_flag = 1; + if( coder_type == VOICED ) + { + *limit_flag = 2; /* double-extended limits */ + } + + if( coder_type == GENERIC && core_brate == ACELP_7k20 ) + { + *limit_flag = 0; + } + } + else if( i_subfr == 2*L_SUBFR && coder_type == GENERIC && core_brate <= ACELP_13k20 ) + { + if( *T0 > (PIT_FR1_EXTEND_8b + PIT_MIN)>>1 ) + { + *limit_flag = 0; + } + } + + /* check the minimum pitch value */ + if( *limit_flag == 0 ) + { + if( ( i_subfr == 0 && T_op[0] < PIT_MIN ) || + ( i_subfr == 2*L_SUBFR && T_op[1] < PIT_MIN ) ) + { + mult_Top = 2; + } + } + + /*-------------------------------------------------------* + * Retrieve the number of Q bits + *-------------------------------------------------------*/ + + nBits = 0; + if( coder_type != AUDIO ) + { + /* find the number of bits */ + if( L_frame == L_FRAME ) + { + nBits = ACB_bits_tbl[BIT_ALLOC_IDX(core_brate, coder_type, i_subfr, 0)]; + } + else /* L_frame == L_FRAME16k */ + { + nBits = ACB_bits_16kHz_tbl[BIT_ALLOC_IDX_16KHZ(core_brate, coder_type, i_subfr, 0)]; + } + } + + if( coder_type == AUDIO ) + { + /*-------------------------------------------------------* + * Pitch encoding in AUDIO mode + * (both ACELP@12k8 and ACELP@16k cores) + *-------------------------------------------------------*/ + + delta = 4; + + if( L_subfr == L_frame/2 && i_subfr != 0 ) + { + pit_flag = L_SUBFR; + } + + if( pit_flag == 0 ) + { + nBits = 10; + } + else + { + nBits = 6; + } + + /* pitch lag search limitation */ + if( i_subfr == 0 ) + { + limit_T0( L_FRAME, delta, pit_flag, *limit_flag, mult_Top*T_op[0], 0, T0_min, T0_max ); + } + else if( i_subfr == 2*L_SUBFR && pit_flag == 0 ) + { + limit_T0( L_FRAME, delta, pit_flag, *limit_flag, mult_Top*T_op[1], 0, T0_min, T0_max ); + } + + /* search and encode the closed loop pitch period */ + *T0 = pitch_fr4( &exc[i_subfr], xn, h1, *T0_min, *T0_max, T0_frac, pit_flag, *limit_flag, PIT_MAX, PIT_MAX, L_FRAME, L_subfr ); + + pit_Q_enc( st, 0, nBits, delta, pit_flag, *limit_flag, *T0, *T0_frac, T0_min, T0_max ); + } + else if( coder_type == VOICED ) + { + /*-------------------------------------------------------* + * Pitch encoding in VOICED mode (ACELP@12k8 core only) + *-------------------------------------------------------*/ + + delta = 4; + + if( i_subfr == 2*L_SUBFR ) + { + pit_flag = i_subfr; + } + + /* pitch lag search limitation */ + if( i_subfr == 0 ) + { + limit_T0( L_FRAME, delta, pit_flag, *limit_flag, mult_Top*T_op[0], 0, T0_min, T0_max ); + } + + /* search and encode the closed loop pitch period */ + if( nBits == 9 || nBits == 5 ) + { + *T0 = pitch_fr4( &exc[i_subfr], xn, h1, *T0_min, *T0_max, T0_frac, pit_flag, *limit_flag, PIT_FR2_DOUBLEEXTEND_9b, PIT_FR1_DOUBLEEXTEND_9b, L_FRAME, L_SUBFR ); + } + else if( nBits == 10 ) + { + *T0 = pitch_fr4( &exc[i_subfr], xn, h1, *T0_min, *T0_max, T0_frac, pit_flag, *limit_flag, PIT_MAX, PIT_MAX, L_FRAME, L_SUBFR ); + } + + pit_Q_enc( st, 0, nBits, delta, pit_flag, *limit_flag, *T0, *T0_frac, T0_min, T0_max ); + } + else + { + /*-------------------------------------------------------* + * Pitch encoding in GENERIC mode + * (both ACELP@12k8 and ACELP@16k cores) + *-------------------------------------------------------*/ + + delta = 8; + + /* pitch lag search limitation */ + if( i_subfr == 0 ) + { + limit_T0( L_frame, delta, pit_flag, *limit_flag, mult_Top*T_op[0], 0, T0_min, T0_max ); + } + else if( i_subfr == 2*L_SUBFR ) + { + limit_T0( L_frame, delta, pit_flag, *limit_flag, mult_Top*T_op[1], 0, T0_min, T0_max ); + } + + /* search and encode the closed loop pitch period */ + if( L_frame == L_FRAME ) + { + if( nBits == 8 || nBits == 5 ) + { + if( *limit_flag == 0 ) + { + *T0 = pitch_fr4( &exc[i_subfr], xn, h1, *T0_min, *T0_max, T0_frac, pit_flag, *limit_flag, PIT_MIN, PIT_FR1_8b, L_FRAME, L_SUBFR ); + } + else + { + *T0 = pitch_fr4( &exc[i_subfr], xn, h1, *T0_min, *T0_max, T0_frac, pit_flag, *limit_flag, PIT_MIN_EXTEND, PIT_FR1_EXTEND_8b, L_FRAME, L_SUBFR ); + } + } + else if( nBits == 9 || nBits == 6 ) + { + if( *limit_flag == 0 ) + { + *T0 = pitch_fr4( &exc[i_subfr], xn, h1, *T0_min, *T0_max, T0_frac, pit_flag, *limit_flag, PIT_FR2_9b, PIT_FR1_9b, L_FRAME, L_SUBFR ); + } + else + { + *T0 = pitch_fr4( &exc[i_subfr], xn, h1, *T0_min, *T0_max, T0_frac, pit_flag, *limit_flag, PIT_FR2_EXTEND_9b, PIT_FR1_EXTEND_9b, L_FRAME, L_SUBFR ); + } + } + else if( nBits == 10 ) + { + *T0 = pitch_fr4( &exc[i_subfr], xn, h1, *T0_min, *T0_max, T0_frac, pit_flag, *limit_flag, PIT_MAX, PIT_MAX, L_FRAME, L_SUBFR ); + } + + pit_Q_enc( st, 0, nBits, delta, pit_flag, *limit_flag, *T0, *T0_frac, T0_min, T0_max ); + } + else /* L_frame == L_FRAME16k */ + { + if( nBits == 9 || nBits == 6 ) + { + *T0 = pitch_fr4( &exc[i_subfr], xn, h1, *T0_min, *T0_max, T0_frac, pit_flag, *limit_flag, PIT16k_FR2_EXTEND_9b, PIT16k_FR1_EXTEND_9b, L_FRAME16k, L_SUBFR ); + } + else if( nBits == 10 ) + { + *T0 = pitch_fr4( &exc[i_subfr], xn, h1, *T0_min, *T0_max, T0_frac, pit_flag, *limit_flag, PIT16k_FR2_EXTEND_10b, PIT16k_MAX, L_FRAME16k, L_SUBFR ); + } + + pit16k_Q_enc( st, nBits, *limit_flag, *T0, *T0_frac, T0_min, T0_max ); + } + } + } + + /*-------------------------------------------------------* + * Pitch encoding in AMR-WB IO mode + *-------------------------------------------------------*/ + + else + { + delta = 8; + *limit_flag = 0; + + if( core_brate == ACELP_6k60 ) + { + nBits = 5; + + /* pitch lag search limitation */ + if( i_subfr == 0 ) + { + limit_T0( L_FRAME, delta, pit_flag, *limit_flag, mult_Top*T_op[0], 0, T0_min, T0_max ); + nBits = 8; + } + + if( i_subfr == 2*L_SUBFR ) + { + /* rewrite pit_flag - it must not be zero */ + pit_flag = i_subfr; + } + + /* search and encode the closed loop pitch period */ + *T0 = pitch_fr4( &exc[i_subfr], xn, h1, *T0_min, *T0_max, T0_frac, pit_flag, *limit_flag, PIT_MIN, PIT_FR1_8b, L_FRAME, L_SUBFR ); + } + else if( core_brate == ACELP_8k85 ) + { + nBits = 5; + + /* pitch lag search limitation */ + if( i_subfr == 0 ) + { + limit_T0( L_FRAME, delta, pit_flag, *limit_flag, mult_Top*T_op[0], 0, T0_min, T0_max ); + nBits = 8; + } + else if( i_subfr == 2*L_SUBFR ) + { + limit_T0( L_FRAME, delta, pit_flag, *limit_flag, mult_Top*T_op[1], 0, T0_min, T0_max ); + nBits = 8; + } + + /* search and encode the closed loop pitch period */ + *T0 = pitch_fr4( &exc[i_subfr], xn, h1, *T0_min, *T0_max, T0_frac, pit_flag, *limit_flag, PIT_MIN, PIT_FR1_8b, L_FRAME, L_SUBFR ); + } + else + { + nBits = 6; + + /* pitch lag search limitation */ + if( i_subfr == 0 ) + { + limit_T0( L_FRAME, delta, pit_flag, *limit_flag, mult_Top*T_op[0], 0, T0_min, T0_max ); + nBits = 9; + } + else if( i_subfr == 2*L_SUBFR ) + { + limit_T0( L_FRAME, delta, pit_flag, *limit_flag, mult_Top*T_op[1], 0, T0_min, T0_max ); + nBits = 9; + } + else + { + limit_T0( L_FRAME, delta, pit_flag, 0, *T0, 0, T0_min, T0_max ); /* T0_frac==0 to keep IO with AMR-WB */ + } + + /* search and encode the closed loop pitch period */ + *T0 = pitch_fr4( &exc[i_subfr], xn, h1, *T0_min, *T0_max, T0_frac, pit_flag, *limit_flag, PIT_FR2_9b, PIT_FR1_9b, L_FRAME, L_SUBFR ); + } + + pit_Q_enc( st, 1, nBits, delta, pit_flag, *limit_flag, *T0, *T0_frac, T0_min, T0_max ); + } + + /*-------------------------------------------------------* + * Compute floating pitch output + *-------------------------------------------------------*/ + + pitch = (float)(*T0) + (float)(*T0_frac)/4.0f; /* save subframe pitch values */ + + return pitch; +} + +/*-------------------------------------------------------------------* + * pitch_fr4() + * + * Find the closed loop pitch period with 1/4 subsample resolution. + *-------------------------------------------------------------------*/ + +short pitch_fr4( /* o : chosen integer pitch lag */ + const float exc[], /* i : excitation buffer */ + const float xn[], /* i : target signal */ + const float h[], /* i : weighted synthesis filter impulse response */ + const short t0_min, /* i : minimum value in the searched range. */ + const short t0_max, /* i : maximum value in the searched range. */ + short *pit_frac, /* o : chosen fraction (0, 1, 2 or 3) */ + const short i_subfr, /* i : flag to first subframe */ + const short limit_flag, /* i : flag for limits (0=restrained, 1=extended) */ + const short t0_fr2, /* i : minimum value for resolution 1/2 */ + const short t0_fr1, /* i : minimum value for resolution 1 */ + const short L_frame, /* i : length of the frame */ + const short L_subfr /* i : size of subframe */ +) +{ + short i, fraction, step; + short t0, t1, t_min, t_max, pit_min; + float cor_max, max, temp; + float *corr, corr_v[15+2*L_INTERPOL1+1]; + + /* initialization */ + if( limit_flag == 0 ) + { + if( L_frame == L_FRAME ) + { + pit_min = PIT_MIN; + } + else /* L_frame == L_FRAME16k */ + { + pit_min = PIT16k_MIN; + } + } + else + { + if( L_frame == L_FRAME ) + { + pit_min = PIT_MIN_EXTEND; + if( limit_flag == 2 ) + { + pit_min = PIT_MIN_DOUBLEEXTEND; + } + } + else /* L_frame == L_FRAME16k */ + { + pit_min = PIT16k_MIN_EXTEND; + } + } + + + /*-----------------------------------------------------------------* + * - Find interval to compute normalized correlation + * - allocate memory to normalized correlation vector + * - Compute normalized correlation between target and filtered + * excitation + *-----------------------------------------------------------------*/ + + t_min = t0_min - L_INTERPOL1; + t_max = t0_max + L_INTERPOL1; + corr = &corr_v[-t_min]; /* corr[t_min..t_max] */ + + norm_corr( exc, xn, h, t_min, t_max, corr, L_subfr ); + + /*-----------------------------------------------------------------* + * Find integer pitch + *-----------------------------------------------------------------*/ + + max = corr[t0_min]; + t0 = t0_min; + + for( i=t0_min+1; i<=t0_max; i++ ) + { + if( corr[i] >= max) + { + max = corr[i]; + t0 = i; + } + } + + if( t0_fr1 == pit_min ) + { + /* don't search fraction (for 7b/4b quant) */ + if((i_subfr == 0) && (t0 >= t0_fr2)) + { + i = (t0>>1)*2; /* 2 samples resolution */ + if( (i+2) > PIT_MAX ) + { + i -= 2; + } + if( corr[i] > corr[i+2] ) + { + t0 = i; + } + else + { + t0 = i+2; + } + } + + *pit_frac = 0; + + return(t0); + } + if( (i_subfr == 0) && (t0 >= t0_fr1) ) + { + *pit_frac = 0; + + return(t0); + } + + /*------------------------------------------------------------------* + * Search fractionnal pitch with 1/4 subsample resolution. + * search the fractions around t0 and choose the one which maximizes + * the interpolated normalized correlation. + *-----------------------------------------------------------------*/ + + t1 = t0; + step = 1; /* 1/4 subsample resolution */ + fraction = 1; + if( ((i_subfr == 0) && (t0 >= t0_fr2)) || (t0_fr2 == pit_min) ) + { + step = 2; /* 1/2 subsample resolution */ + fraction = 2; + } + + if( t0 == t0_min ) /* Limit case */ + { + fraction = 0; + cor_max = interpolation( &corr[t0], E_ROM_inter4_1, fraction, PIT_UP_SAMP, 4 ); + } + else /* Process negative fractions */ + { + t0--; + cor_max = interpolation( &corr[t0], E_ROM_inter4_1, fraction, PIT_UP_SAMP, 4 ); + for( i=(fraction+step); i<=3; i=i+step ) + { + temp = interpolation( &corr[t0], E_ROM_inter4_1, i, PIT_UP_SAMP, 4 ); + if (temp > cor_max) + { + cor_max = temp; + fraction = i; + } + } + } + + for( i=0; i<=3; i=i+step ) /* Process positive fractions */ + { + temp = interpolation( &corr[t1], E_ROM_inter4_1, i, PIT_UP_SAMP, 4 ); + if( temp > cor_max ) + { + cor_max = temp; + fraction = i; + t0 = t1; + } + } + + *pit_frac = fraction; + + return (t0); +} + +/*-------------------------------------------------------------------* + * norm_corr() + * + * Find the normalized correlation between the target vector and the + * filtered past excitation (correlation between target and filtered + * excitation divided by the square root of energy of filtered + * excitation) + *---------------------------------------------------------------------*/ + +void norm_corr( + const float exc[], /* i : excitation buffer */ + const float xn[], /* i : target signal */ + const float h[], /* i : weighted synthesis filter impulse response */ + const short t_min, /* i : minimum value of searched range */ + const short t_max, /* i : maximum value of searched range */ + float corr_norm[], /* o : normalized correlation */ + const short L_subfr /* i : subframe size */ +) +{ + short t, j, k; + float excf[L_FRAME]; /* filtered past excitation */ /* length up to L_FRAME in GSC */ + float alp, ps, norm; + + k = - t_min; + + /*-----------------------------------------------------------------* + * compute the filtered excitation for the first delay t_min + *-----------------------------------------------------------------*/ + + conv( &exc[k], h, excf, L_subfr ); + + /*-----------------------------------------------------------------* + * loop for every possible period + *-----------------------------------------------------------------*/ + + for (t = t_min; t <= t_max; t++) + { + /* Compute correlation between xn[] and excf[] */ + + ps = 0.0f; + for (j = 0; j < L_subfr; ++j) + { + ps += xn[j]*excf[j]; + } + + /* Compute 1/sqrt(energie of excf[]) */ + + alp = 0.01f; + for (j = 0; j < L_subfr; ++j) + { + alp += excf[j]*excf[j]; + } + norm = inv_sqrt(alp); + + /* Normalize correlation = correlation * (1/sqrt(energie)) */ + corr_norm[t] = ps*norm; + + /* update the filtered excitation excf[] for the next iteration */ + if (t != t_max) + { + k--; + for (j = L_subfr-1; j > 0; j--) + { + excf[j] = excf[j-1] + exc[k]*h[j]; + } + excf[0] = exc[k]; + } + } + return; +} + +/*-------------------------------------------------------------------* + * abs_pit_enc() + * + * Encode pitch lag absolutely with resolution for shortest pitches + * depending on parameter 'fr_step': + * fr_step = 2: pitch range encoded with 8 bits + * fr_step = 4: pitch range encoded with 9 bits + *-------------------------------------------------------------------*/ + +short abs_pit_enc( /* o : pitch index */ + const short fr_steps, /* i : fractional resolution step */ + const short limit_flag, /* i : restrained(0) or extended(1) limits */ + const short T0, /* i : integer pitch lag */ + const short T0_frac /* i : pitch fraction */ +) +{ + short pitch_index; + + if( limit_flag == 0 ) + { + if( fr_steps == 2 ) + { + /*-----------------------------------------------------------------* + * The pitch range is encoded absolutely with 8 bits + * and is divided as follows: + * PIT_MIN to PIT_FR1_8b-1 resolution 1/2 (frac = 0 or 2) + * PIT_FR1_8b to PIT_MAX resolution 1 (frac = 0) + *-----------------------------------------------------------------*/ + if( T0 < PIT_FR1_8b ) + { + pitch_index = T0*2 + (T0_frac>>1) - (PIT_MIN*2); + } + else + { + pitch_index = T0 - PIT_FR1_8b + ((PIT_FR1_8b-PIT_MIN)*2); + } + + } + else if( fr_steps == 4 ) + { + /*-------------------------------------------------------------------* + * The pitch range is encoded absolutely with 9 bits + * and is divided as follows: + * PIT_MIN to PIT_FR2_9b-1 resolution 1/4 (frac = 0,1,2 or 3) + * PIT_FR2_9b to PIT_FR1_9b-1 resolution 1/2 (frac = 0 or 2) + * PIT_FR1_9b to PIT_MAX resolution 1 (frac = 0) + *-------------------------------------------------------------------*/ + if( T0 < PIT_FR2_9b ) + { + pitch_index = T0*4 + T0_frac - (PIT_MIN*4); + } + else if( T0 < PIT_FR1_9b ) + { + pitch_index = T0*2 + (T0_frac>>1) - (PIT_FR2_9b*2) + ((PIT_FR2_9b-PIT_MIN)*4); + } + else + { + pitch_index = T0 - PIT_FR1_9b + ((PIT_FR2_9b-PIT_MIN)*4) + ((PIT_FR1_9b-PIT_FR2_9b)*2); + } + + } + else /* fr_step == 0 */ + { + /* not used in the codec */ + pitch_index = 0; + } + } + else if( limit_flag == 1 ) /* extended Q range */ + { + if( fr_steps == 2 ) + { + /*-----------------------------------------------------------------* + * The pitch range is encoded absolutely with 8 bits + * and is divided as follows: + * PIT_MIN_EXTEND to PIT_FR1_EXTEND_8b-1 resolution 1/2 (frac = 0 or 2) + * PIT_FR1_EXTEND_8b to PIT_MAX resolution 1 (frac = 0) + *-----------------------------------------------------------------*/ + + if( T0 < PIT_FR1_EXTEND_8b ) + { + pitch_index = T0*2 + (T0_frac>>1) - (PIT_MIN_EXTEND*2); + } + else + { + pitch_index = T0 - PIT_FR1_EXTEND_8b + ((PIT_FR1_EXTEND_8b-PIT_MIN_EXTEND)*2); + } + + } + else if( fr_steps == 4 ) + { + /*-------------------------------------------------------------------* + * The pitch range is encoded absolutely with 9 bits + * and is divided as follows: + * PIT_MIN_EXTEND to PIT_FR2__EXTEND9b-1 resolution 1/4 (frac = 0,1,2 or 3) + * PIT_FR2_EXTEND_9b to PIT_FR1__EXTEND9b-1 resolution 1/2 (frac = 0 or 2) + * PIT_FR1_EXTEND_9b to PIT_MAX resolution 1 (frac = 0) + *-------------------------------------------------------------------*/ + + if( T0 < PIT_FR2_EXTEND_9b ) + { + pitch_index = T0*4 + T0_frac - (PIT_MIN_EXTEND*4); + } + else if( T0 < PIT_FR1_EXTEND_9b ) + { + pitch_index = T0*2 + (T0_frac>>1) - (PIT_FR2_EXTEND_9b*2) + ((PIT_FR2_EXTEND_9b-PIT_MIN_EXTEND)*4); + } + else + { + pitch_index = T0 - PIT_FR1_EXTEND_9b + ((PIT_FR2_EXTEND_9b-PIT_MIN_EXTEND)*4) + ((PIT_FR1_EXTEND_9b-PIT_FR2_EXTEND_9b)*2); + } + + } + else /* fr_step == 0 */ + { + /* not used in the codec */ + pitch_index = 0; + } + } + else /* double-extended Q range */ + { + if( fr_steps == 2 ) + { + /*-----------------------------------------------------------------* + * The pitch range is encoded absolutely with 8 bits + * and is divided as follows: + * PIT_MIN_DOUBLEEXTEND to PIT_FR1_DOUBLEEXTEND_8b-1 resolution 1/2 (frac = 0 or 2) + * PIT_FR1_DOUBLEEXTEND_8b to PIT_MAX resolution 1 (frac = 0) + *-----------------------------------------------------------------*/ + + if( T0 < PIT_FR1_DOUBLEEXTEND_8b ) + { + pitch_index = T0*2 + (T0_frac>>1) - (PIT_MIN_DOUBLEEXTEND*2); + } + else + { + pitch_index = T0 - PIT_FR1_DOUBLEEXTEND_8b + ((PIT_FR1_DOUBLEEXTEND_8b-PIT_MIN_DOUBLEEXTEND)*2); + } + } + else if( fr_steps == 4 ) + { + /*-------------------------------------------------------------------* + * The pitch range is encoded absolutely with 9 bits + * and is divided as follows: + * PIT_MIN_DOUBLEEXTEND to PIT_FR2_DOUBLEEXTEND9b-1 resolution 1/4 (frac = 0,1,2 or 3) + * PIT_FR2_DOUBLEEXTEND_9b to PIT_FR1_DOOBLEEXTEND9b-1 resolution 1/2 (frac = 0 or 2) + * PIT_FR1_DOUBLEEXTEND_9b to PIT_MAX resolution 1 (frac = 0) + *-------------------------------------------------------------------*/ + + if( T0 < PIT_FR2_DOUBLEEXTEND_9b ) + { + pitch_index = T0*4 + T0_frac - (PIT_MIN_DOUBLEEXTEND*4); + } + else if( T0 < PIT_FR1_DOUBLEEXTEND_9b ) + { + pitch_index = T0*2 + (T0_frac>>1) - (PIT_FR2_DOUBLEEXTEND_9b*2) + ((PIT_FR2_DOUBLEEXTEND_9b-PIT_MIN_DOUBLEEXTEND)*4); + } + else + { + pitch_index = T0 - PIT_FR1_DOUBLEEXTEND_9b + ((PIT_FR2_DOUBLEEXTEND_9b-PIT_MIN_DOUBLEEXTEND)*4) + ((PIT_FR1_DOUBLEEXTEND_9b-PIT_FR2_DOUBLEEXTEND_9b)*2); + } + } + else /* fr_step == 0 */ + { + /* not used in the codec */ + pitch_index = 0; + } + } + + return pitch_index; +} + +/*-------------------------------------------------------------------* + * delta_pit_enc() + * + * Encode pitch lag differentially from T0_min to T0_max + * with resolution depending on parameter 'fr_step': + * fr_step = 0: resolution 1 (frac = 0), or + * fr_step = 2: resolution 1/2 (frac = 0 or 2), or + * fr_step = 4: resolution 1/4 (frac = 0, 1, 2, or 3) + *-------------------------------------------------------------------*/ + +short delta_pit_enc( /* o : pitch index */ + const short fr_steps, /* i : fractional resolution step */ + const short T0, /* i : integer pitch lag */ + const short T0_frac, /* i : pitch fraction */ + const short T0_min /* i : delta search min */ +) +{ + short pitch_index; + + if( fr_steps == 0 ) + { + pitch_index = T0 - T0_min; + } + else if( fr_steps == 2 ) + { + pitch_index = (T0 - T0_min) * 2 + (T0_frac>>1); + } + else /* fr_steps == 4 */ + { + pitch_index = (T0 - T0_min) * 4 + T0_frac; + } + + return pitch_index; +} + +/*-------------------------------------------------------------------* + * pit_Q_enc() + * + * Encode subframe pitch lag + *-------------------------------------------------------------------*/ + +void pit_Q_enc( + Encoder_State *st, /* i/o: encoder state structure */ + const short Opt_AMR_WB, /* i : flag indicating AMR-WB IO mode */ + const short nBits, /* i : # of Q bits */ + const short delta, /* i : Half the CL searched interval */ + const short pit_flag, /* i : absolute(0) or delta(1) pitch Q */ + const short limit_flag, /* i : restrained(0) or extended(1) Q limits */ + const short T0, /* i : integer pitch lag */ + const short T0_frac, /* i : pitch fraction */ + short *T0_min, /* i/o: delta search min */ + short *T0_max /* o : delta search max */ +) +{ + short pitch_index; + + if( nBits == 10 ) /* absolute encoding with 10 bits */ + { + if( limit_flag == 0 ) + { + pitch_index = T0*4 + T0_frac - (PIT_MIN*4); + } + else if( limit_flag == 1 ) + { + pitch_index = T0*4 + T0_frac - (PIT_MIN_EXTEND*4); + } + else /* limit_flag == 2 */ + { + pitch_index = T0*4 + T0_frac - (PIT_MIN_DOUBLEEXTEND*4); + } + } + else if( nBits == 9 ) /* absolute encoding with 9 bits */ + { + pitch_index = abs_pit_enc( 4, limit_flag, T0, T0_frac ); + + /* find T0_min and T0_max for delta search */ + if( Opt_AMR_WB ) + { + limit_T0( L_FRAME, delta, pit_flag, 0, T0, 0, T0_min, T0_max ); /* T0_frac==0 to keep IO with AMR-WB */ + } + } + else if( nBits == 8 ) /* absolute encoding with 8 bits */ + { + pitch_index = abs_pit_enc( 2, limit_flag, T0, T0_frac ); + + /* find T0_min and T0_max for delta search */ + if( Opt_AMR_WB ) + { + limit_T0( L_FRAME, delta, pit_flag, 0, T0, 0, T0_min, T0_max ); /* T0_frac==0 to keep IO with AMR-WB */ + } + } + else if( nBits == 6 ) /* relative encoding with 6 bits */ + { + pitch_index = delta_pit_enc( 4, T0, T0_frac, *T0_min ); + } + else if( nBits == 5 ) /* relative encoding with 5 bits */ + { + if( delta == 8 ) + { + pitch_index = delta_pit_enc( 2, T0, T0_frac, *T0_min ); + } + else /* delta == 4 */ + { + pitch_index = delta_pit_enc( 4, T0, T0_frac, *T0_min ); + } + } + else /* nBits == 4 ) */ /* relative encoding with 4 bits */ + { + if( delta == 8 ) + { + pitch_index = delta_pit_enc( 0, T0, T0_frac, *T0_min ); + } + else /* delta == 4 */ + { + pitch_index = delta_pit_enc( 2, T0, T0_frac, *T0_min ); + } + } + + if( !Opt_AMR_WB ) + { + /* find T0_min and T0_max for delta search */ + limit_T0( L_FRAME, delta, L_SUBFR, limit_flag, T0, T0_frac, T0_min, T0_max ); + } + + push_indice( st, IND_PITCH, pitch_index, nBits ); + + return; +} + +/*-------------------------------------------------------------------* + * pit16k_Q_enc() + * + * Encode subframe pitch lag @16kHz core + *-------------------------------------------------------------------*/ + +void pit16k_Q_enc( + Encoder_State *st, /* i/o: encoder state structure */ + const short nBits, /* i : # of Q bits */ + const short limit_flag, /* i : restrained(0) or extended(1) Q limits */ + const short T0, /* i : integer pitch lag */ + const short T0_frac, /* i : pitch fraction */ + short *T0_min, /* i/o: delta search min */ + short *T0_max /* o : delta search max */ +) +{ + short pitch_index; + + if( nBits == 10 ) /* absolute encoding with 10 bits */ + { + { + if( T0 < PIT16k_FR2_EXTEND_10b ) + { + pitch_index = T0*4 + T0_frac - (PIT16k_MIN_EXTEND*4); + } + else + { + pitch_index = T0*2 + (T0_frac>>1) - (PIT16k_FR2_EXTEND_10b*2) + ((PIT16k_FR2_EXTEND_10b-PIT16k_MIN_EXTEND)*4); + } + } + + push_indice( st, IND_PITCH, pitch_index, nBits ); + } + else if( nBits == 9 ) /* absolute encoding with 9 bits */ + { + { + /*-------------------------------------------------------------------* + * The pitch range is encoded absolutely with 9 bits + * and is divided as follows: + * PIT16k_EXTEND_MIN to PIT16k_FR2_EXTEND_9b-1 resolution 1/4 (frac = 0,1,2 or 3) + * PIT16k_FR2_EXTEND_9b to PIT16k_FR1_EXTEND_9b-1 resolution 1/2 (frac = 0 or 2) + * PIT16k_FR1_EXTEND_9b to PIT16k_MAX resolution 1 (frac = 0) + *-------------------------------------------------------------------*/ + + if( T0 < PIT16k_FR2_EXTEND_9b ) + { + pitch_index = T0*4 + T0_frac - (PIT16k_MIN_EXTEND*4); + } + else if( T0 < PIT16k_FR1_EXTEND_9b ) + { + pitch_index = T0*2 + (T0_frac>>1) - (PIT16k_FR2_EXTEND_9b*2) + ((PIT16k_FR2_EXTEND_9b-PIT16k_MIN_EXTEND)*4); + } + else + { + pitch_index = T0 - PIT16k_FR1_EXTEND_9b + ((PIT16k_FR2_EXTEND_9b-PIT16k_MIN_EXTEND)*4) + ((PIT16k_FR1_EXTEND_9b-PIT16k_FR2_EXTEND_9b)*2); + } + } + + push_indice( st, IND_PITCH, pitch_index, 9 ); + } + else /* nBits == 6 */ /* relative encoding with 6 bits */ + { + pitch_index = (T0 - *T0_min) * 4 + T0_frac; + + push_indice( st, IND_PITCH, pitch_index, nBits ); + } + + limit_T0( L_FRAME16k, 8, L_SUBFR, limit_flag, T0, T0_frac, T0_min, T0_max ); + + return; +} + + +/*------------------------------------------------------------------* + * limit_T0_voiced2: + * + * + *------------------------------------------------------------------*/ + +static void limit_T0_voiced2( + int res, + const short *T_op, + int *T0_min, + int *T0_min_frac, + int *T0_max, + int *T0_max_frac, + short pit_min, + short pit_max, + int i_subfr +) +{ + int t, temp1, temp2; + + /* Lower-bound */ + if (i_subfr == 0) + { + temp1 = (T_op[0]*res) - 32; + } + else + { + temp1 = (T_op[1]*res) - 32; + } + + if (T_op[0]t) + { + temp1 = t; + } + + temp2 = temp1 / res; + *T0_max = temp2; + *T0_max_frac = temp1 - temp2*res; + + if ( *T0_max > pit_max) + { + *T0_max = pit_max; + *T0_max_frac = res - 1; + temp1 = (*T0_max*res) - 64 + res; + temp2 = temp1 / res; + *T0_min = temp2; + *T0_min_frac = temp1 - temp2*res; + } + + return; +} + + +/*------------------------------------------------------------------* + * Mode2_pit_encode: + * + * Close-loop pitch lag search and pitch lag quantization + * Adaptive excitation construction + *------------------------------------------------------------------*/ + +void Mode2_pit_encode( + short coder_type, /* i : coding model */ + short i_subfr, /* i : subframe index */ + int **pt_indice, /* i/o: quantization indices pointer */ + float *exc, /* i/o: pointer to excitation signal frame */ + const short *T_op, /* i : open loop pitch estimates in current frame */ + int *T0_min, /* i/o: lower limit for close-loop search */ + int *T0_min_frac, /* i/o: lower limit for close-loop search */ + int *T0_max, /* i/o: higher limit for close-loop search */ + int *T0_max_frac, /* i/o: higher limit for close-loop search */ + int *T0, /* i/o: close loop integer pitch */ + int *T0_frac, /* i/o: close loop fractional part of the pitch */ + int *T0_res, /* i/o: close loop pitch resolution */ + float *h1, /* i : weighted filter impulse response */ + float *xn, /* i : target vector */ + int pit_min, + int pit_fr1, + int pit_fr1b, + int pit_fr2, + int pit_max, + int pit_res_max) +{ + int pit_flag; + + /* Pitch flag */ + pit_flag = i_subfr; + + if (i_subfr == (2*L_SUBFR)) + { + pit_flag = 0; + } + + /*-----------------------------------------------------------------* + * - Limit range of pitch search + * - Fractional pitch search + * - Pitch quantization + *-----------------------------------------------------------------*/ + + if(coder_type == 0) /*Unvoiced Coding do nothing*/ + { + *T0 = L_SUBFR; + *T0_frac = 0; + *T0_res = 1; + } + else if(coder_type == 1) /* 8/4/4/4 (EVS) */ + { + if (i_subfr == 0) + { + limit_T0_voiced( 4, pit_res_max>>1, T_op[0], 0, 1, T0_min, T0_min_frac, T0_max, T0_max_frac, pit_min, pit_max ); + } + else + { + limit_T0_voiced( 4, pit_res_max>>1, *T0, *T0_frac, *T0_res, T0_min, T0_min_frac, T0_max, T0_max_frac, pit_min, pit_max ); + } + + *T0 = E_GAIN_closed_loop_search(exc, xn, h1, *T0_min, *T0_min_frac, *T0_max, *T0_max_frac, pit_res_max>>1, T0_frac, T0_res, pit_res_max, + i_subfr, pit_min, pit_min, pit_fr1b, L_SUBFR ); + + if (i_subfr == 0) + { + Mode2_abs_pit_enc( *T0, *T0_frac, pt_indice, pit_min, pit_fr1b, pit_min, pit_res_max ); + } + else + { + Mode2_delta_pit_enc( *T0, *T0_frac, (pit_res_max>>1), *T0_min, *T0_min_frac, pt_indice ); + } + + } + else if(coder_type == 2) /* 8/5/8/5 (EVS) */ + { + + if (i_subfr == 0) + { + limit_T0_voiced( 5, pit_res_max>>1, T_op[0], 0, 1, T0_min, T0_min_frac, T0_max, T0_max_frac, pit_min, pit_max ); + } + else if(i_subfr == 2*L_SUBFR) + { + limit_T0_voiced( 5, pit_res_max>>1, T_op[1], 0, 1, T0_min, T0_min_frac, T0_max, T0_max_frac, pit_min, pit_max ); + } + else + { + limit_T0_voiced( 5, pit_res_max>>1, *T0, *T0_frac, *T0_res, T0_min, T0_min_frac, T0_max, T0_max_frac, pit_min, pit_max ); + } + + *T0 = E_GAIN_closed_loop_search(exc, xn, h1, *T0_min, *T0_min_frac, *T0_max, *T0_max_frac, pit_res_max>>1, T0_frac, T0_res, pit_res_max, + pit_flag, pit_min, pit_min, pit_fr1b, L_SUBFR); + + if (pit_flag == 0) + { + Mode2_abs_pit_enc( *T0, *T0_frac, pt_indice, pit_min, pit_fr1b, pit_min, pit_res_max ); + } + else + { + Mode2_delta_pit_enc( *T0, *T0_frac, (pit_res_max>>1), *T0_min, *T0_min_frac, pt_indice ); + } + } + else if(coder_type == 3) /* 9/6/6/6 (HRs- VC) */ + { + int pit_res_max2 = pit_res_max; + + if ( pit_min==PIT_MIN_16k ) + { + + pit_res_max2 = pit_res_max >> 1; + } + + if (i_subfr == 0) + { + + limit_T0_voiced2( pit_res_max2, T_op, T0_min, T0_min_frac, T0_max, T0_max_frac, pit_min, pit_max, i_subfr ); + } + else + { + limit_T0_voiced( 6, pit_res_max2, *T0, 0, 1, T0_min, T0_min_frac, T0_max, T0_max_frac, pit_min, pit_max); + } + + *T0 = E_GAIN_closed_loop_search(exc, xn, h1, *T0_min, *T0_min_frac, *T0_max, *T0_max_frac, pit_res_max2, T0_frac, T0_res, pit_res_max, + i_subfr, pit_min, pit_fr2, pit_fr1, L_SUBFR); + + if (i_subfr == 0) /* if 1st subframe */ + { + Mode2_abs_pit_enc( *T0, *T0_frac, pt_indice, pit_min, pit_fr1, pit_fr2, pit_res_max ); + } + else + { + Mode2_delta_pit_enc( *T0, *T0_frac, pit_res_max2, *T0_min, *T0_min_frac, pt_indice ); + } + } + else if(coder_type == 4) /* 9/6/9/6 (AMRWB) */ + { + int pit_res_max2 = pit_res_max; + + if ( pit_min==PIT_MIN_16k ) + { + + pit_res_max2 = pit_res_max >> 1; + } + + + if ( (i_subfr == 0) || (i_subfr == 2*L_SUBFR) ) + { + + limit_T0_voiced2( pit_res_max2, T_op, T0_min, T0_min_frac, T0_max, T0_max_frac, pit_min, pit_max, i_subfr ); + } + else + { + limit_T0_voiced( 6, pit_res_max2, *T0, 0, 1, T0_min, T0_min_frac, T0_max, T0_max_frac, pit_min, pit_max); + } + + *T0 = E_GAIN_closed_loop_search(exc, xn, h1, *T0_min, *T0_min_frac, *T0_max, *T0_max_frac, pit_res_max2, T0_frac, T0_res, pit_res_max, + pit_flag, pit_min, pit_fr2, pit_fr1, L_SUBFR); + + if (pit_flag == 0) /* if 1st/3rd/5th subframe */ + { + Mode2_abs_pit_enc( *T0, *T0_frac, pt_indice, pit_min, pit_fr1, pit_fr2, pit_res_max ); + } + else /* if subframe 2 or 4 */ + { + Mode2_delta_pit_enc( *T0, *T0_frac, pit_res_max2, *T0_min, *T0_min_frac, pt_indice ); + } + } + else if(coder_type == 8) /* 8/5/5/5 (RF all pred mode) */ + { + if (i_subfr == 0) + { + limit_T0_voiced( 5, pit_res_max>>1, T_op[0], 0, 1, T0_min, T0_min_frac, T0_max, T0_max_frac, pit_min, pit_max ); + } + else + { + limit_T0_voiced( 5, pit_res_max>>1, *T0, *T0_frac, *T0_res, T0_min, T0_min_frac, T0_max, T0_max_frac, pit_min, pit_max ); + } + *T0 = E_GAIN_closed_loop_search(exc, xn, h1, *T0_min, *T0_min_frac, *T0_max, *T0_max_frac, pit_res_max>>1, T0_frac, T0_res, pit_res_max, + i_subfr, pit_min, pit_min, pit_fr1b, L_SUBFR ); + + if (i_subfr == 0) + { + Mode2_abs_pit_enc( *T0, *T0_frac, pt_indice, pit_min, pit_fr1b, pit_min, pit_res_max ); + } + else + { + Mode2_delta_pit_enc( *T0, *T0_frac, (pit_res_max>>1), *T0_min, *T0_min_frac, pt_indice ); + } + } + else if(coder_type == 9) /* 8/0/8/0 (RF mode Gen pred) */ + { + if (i_subfr == 0) + { + limit_T0_voiced( 4, pit_res_max>>1, T_op[0], 0, 1, T0_min, T0_min_frac, T0_max, T0_max_frac, pit_min, pit_max ); + } + else + { + limit_T0_voiced( 4, pit_res_max>>1, *T0, *T0_frac, *T0_res, T0_min, T0_min_frac, T0_max, T0_max_frac, pit_min, pit_max ); + } + *T0 = E_GAIN_closed_loop_search(exc, xn, h1, *T0_min, *T0_min_frac, *T0_max, *T0_max_frac, pit_res_max>>1, T0_frac, T0_res, pit_res_max, + i_subfr, pit_min, pit_min, pit_fr1b, L_SUBFR ); + + if (i_subfr == 0) + { + Mode2_abs_pit_enc( *T0, *T0_frac, pt_indice, pit_min, pit_fr1b, pit_min, pit_res_max ); + } + else + { + Mode2_delta_pit_enc( *T0, *T0_frac, (pit_res_max>>1), *T0_min, *T0_min_frac, pt_indice ); + } + } + else + { + assert(0); + } + + return; +} + + +/*-------------------------------------------------------------------* + * Mode2_abs_pit_enc: + * + * Encode pitch lag absolutely + *-------------------------------------------------------------------*/ + +void Mode2_abs_pit_enc( + short T0, /* i : integer pitch lag */ + int T0_frac, /* i : pitch fraction */ + int **pt_indice, /* i/o: pointer to Vector of Q indexes */ + short pit_min, + short pit_fr1, + short pit_fr2, + short pit_res_max +) +{ + short pit_res_max_half; + + pit_res_max_half= pit_res_max>>1; + + if (T0 < pit_fr2) + { + **pt_indice = T0*pit_res_max + T0_frac - (pit_min*pit_res_max); + } + else if (T0 < pit_fr1) + { + **pt_indice = T0*pit_res_max_half + T0_frac - (pit_fr2*pit_res_max_half) + ((pit_fr2-pit_min)*pit_res_max); + + } + else + { + **pt_indice = T0 - pit_fr1 + ((pit_fr2-pit_min)*pit_res_max) + ((pit_fr1-pit_fr2)*pit_res_max_half); + } + + (*pt_indice)++; + + return; +} + + +/*-------------------------------------------------------------------* + * Mode2_delta_pit_enc: + * + * Encode pitch lag differentially + *-------------------------------------------------------------------*/ + +void Mode2_delta_pit_enc( + short T0, /* i : integer pitch lag */ + int T0_frac, /* i : pitch fraction */ + int T0_res, /* i : pitch resolution */ + short T0_min, /* i/o: delta search min */ + short T0_min_frac, /* i/o: delta search min */ + int **pt_indice /* i/o: pointer to Vector of Q indexes */ +) +{ + + **pt_indice = (T0 - T0_min) * T0_res + T0_frac - T0_min_frac; + + (*pt_indice)++; + + return; +} diff --git a/src/libs/libevs/lib_enc/pit_enc_fx.cpp b/src/libs/libevs/lib_enc/pit_enc_fx.cpp deleted file mode 100755 index 679d99c3..00000000 --- a/src/libs/libevs/lib_enc/pit_enc_fx.cpp +++ /dev/null @@ -1,1505 +0,0 @@ -/*==================================================================================== - EVS Codec 3GPP TS26.442 Apr 03, 2018. Version 12.11.0 / 13.6.0 / 14.2.0 - ====================================================================================*/ - -#include -#include "options.h" /* Compilation switches */ -#include "cnst_fx.h" /* Common constants */ -#include "rom_enc_fx.h" /* Encoder static table prototypes */ -#include "rom_com_fx.h" /* Static table prototypes */ -#include "prot_fx.h" /* Function prototypes */ -#include "stl.h" -#include "rom_basop_util.h" - -#define inv_T0_res InvIntTable - -static void limit_T0_voiced2( Word16 res, const Word16 *T_op, Word16 *T0_min, Word16 *T0_min_frac, - Word16 *T0_max, Word16 *T0_max_frac, Word16 pit_min, Word16 pit_max, Word16 i_subfr ); - -/*==============================================================================*/ -/* FUNCTION : pit_encode_fx() */ -/*------------------------------------------------------------------------------*/ -/* PURPOSE : Close-loop pitch lag search and pitch lag quantization */ -/* Adaptive excitation construction */ -/*------------------------------------------------------------------------------*/ -/* INPUT ARGUMENTS : */ -/* _ (Word16) core_brate: core bitrate Q0 */ -/* _ (Word16) Opt_AMR_WB: flag indicating AMR-WB IO mode Q0 */ -/* _ (Word16) bwidth : input signal bandwidth Q0 */ -/* _ (Word16[]) T_op : open loop pitch estimates in current frame Q0 */ -/* _ (Word16) T0_min : lower limit for close-loop search Q0 */ -/* _ (Word16) T0_max : higher limit for close-loop search Q0 */ -/* _ (Word16) T0 : close loop integer pitch Q0 */ -/* _ (Word16) T0_frac : close loop fractional part of the pitch Q0 */ -/* _ (Word16) L_frame_fx : length of the frame Q0 */ -/* _ (Word16[]) h1 : weighted filter input response Q15 */ -/* _ (Word16[]) xn : target vector Q_new */ -/* _ (Word16) coder_type_fx : coding type Q0 */ -/* _ (Word16) i_subfr : current sub frame indicator Q0 */ -/* _ (Word16[]) exc_fx : pointer to excitation signal frame Q_new */ -/* _ (Word16[]) L_subfr : subframe length Q0 */ -/*------------------------------------------------------------------------------*/ -/* OUTPUT ARGUMENTS : */ -/* _ (Word16[]) exc_fx : adapt. excitation exc (Q0) */ -/* _ (Word16) T0_min : lower limit for close-loop search Q0 */ -/* _ (Word16) T0_max : higher limit for close-loop search Q0 */ -/* _ (Word16) T0 : close loop integer pitch Q0 */ -/* _ (Word16) T0_frac : close loop fractional part of the pitch Q0 */ -/*------------------------------------------------------------------------------*/ - -/*------------------------------------------------------------------------------*/ -/* RETURN ARGUMENTS : */ -/* _ None */ -/*==============================================================================*/ - -Word16 pit_encode_fx( /* o : Fractional pitch for each subframe */ - Encoder_State_fx *st_fx, /* i/o: encoder state structure */ - const Word32 core_brate, /* i : core bitrate */ - const Word16 Opt_AMR_WB, /* i : flag indicating AMR-WB IO mode */ - const Word16 L_frame, /* i : length of the frame */ - const Word16 coder_type, /* i : coding type */ - Word16 *limit_flag, /* i/o: restrained(0) or extended(1) Q limits */ - const Word16 i_subfr, /* i : subframe index */ - Word16 *exc, /* i/o: pointer to excitation signal frame */ - const Word16 L_subfr, /* i : subframe length */ - const Word16 *T_op, /* i : open loop pitch estimates in current frame */ - Word16 *T0_min, /* i/o: lower limit for close-loop search */ - Word16 *T0_max, /* i/o: higher limit for close-loop search */ - Word16 *T0, /* i/o: close loop integer pitch */ - Word16 *T0_frac, /* i/o: close loop fractional part of the pitch */ - const Word16 *h1, /* i : weighted filter input response */ - const Word16 *xn /* i : target vector */ -) -{ - Word16 pitch; - Word16 pit_flag, delta, mult_Top, nBits; - - - /*----------------------------------------------------------------* - * Set pit_flag to 0 for every subframe with absolute pitch search - *----------------------------------------------------------------*/ - pit_flag = i_subfr; - move16(); - if (sub(i_subfr,2*L_SUBFR) == 0) - { - pit_flag = 0; - move16(); - } - - /*-----------------------------------------------------------------* - * Limit range of pitch search - * Fractional pitch search - * Pitch quantization - *-----------------------------------------------------------------*/ - mult_Top = 1; - move16(); - - IF( !Opt_AMR_WB ) - { - /*----------------------------------------------------------------* - * pitch Q: Set limit_flag to 0 for restrained limits, and 1 for extended limits - *----------------------------------------------------------------*/ - test(); - test(); - IF( i_subfr == 0 ) - { - *limit_flag = 1; - move16(); - if( sub(coder_type,VOICED) == 0 ) - { - *limit_flag = 2; - move16(); /* double-extended limits */ - } - test(); - if( sub(coder_type,GENERIC) == 0 && L_sub(core_brate,ACELP_7k20) == 0 ) - { - *limit_flag = 0; - move16(); - } - } - ELSE IF( sub(i_subfr,2*L_SUBFR) == 0 && sub(coder_type,GENERIC) == 0 && L_sub(core_brate,ACELP_13k20) <= 0 ) - { - /*if( *T0 > (PIT_FR1_EXTEND_8b + PIT_MIN)>>1 )*/ - if( sub(*T0,shr(add(PIT_FR1_EXTEND_8b , PIT_MIN), 1)) > 0) - { - *limit_flag = 0; - move16(); - } - } - - IF( *limit_flag == 0 ) - { - test(); - test(); - IF( i_subfr == 0 && sub(T_op[0],PIT_MIN) < 0 ) - { - mult_Top = 2; - move16(); - } - ELSE IF( sub(i_subfr,2*L_SUBFR) == 0 && sub(T_op[1],PIT_MIN) < 0 ) - { - mult_Top = 2; - move16(); - } - } - /*-------------------------------------------------------* - * Retrieve the number of Q bits - *-------------------------------------------------------*/ - nBits = 0; - move16(); - IF( sub(coder_type,AUDIO) != 0 ) - { - /* find the number of bits */ - IF( sub(L_frame,L_FRAME) == 0 ) - { - { - nBits = ACB_bits_tbl[BIT_ALLOC_IDX_fx(core_brate, coder_type, i_subfr, 0)]; - move16(); - } - } - ELSE /* L_frame == L_FRAME16k */ - { - nBits = ACB_bits_16kHz_tbl[BIT_ALLOC_IDX_16KHZ_fx(core_brate, coder_type, i_subfr, 0)]; - move16(); - } - } - IF( sub(coder_type,AUDIO) == 0 ) - { - /*-------------------------------------------------------* - * Pitch encoding in AUDIO mode - * (both ACELP@12k8 and ACELP@16k cores) - *-------------------------------------------------------*/ - - delta = 4; - move16(); - test(); - test(); - if ( sub(L_subfr,L_frame/2) == 0 && i_subfr != 0 && sub(L_frame,L_FRAME) == 0 ) - { - pit_flag = L_SUBFR; - move16(); - } - IF ( pit_flag == 0 ) - { - nBits = 10; - move16(); - } - ELSE - { - nBits = 6; - move16(); - } - - /* pitch lag search limitation */ - test(); - IF( i_subfr == 0 ) - { - limit_T0_fx( L_frame, delta, pit_flag, *limit_flag, mult_Top*T_op[0], 0, T0_min, T0_max ); - } - ELSE IF( sub(i_subfr,2*L_SUBFR) == 0 && pit_flag == 0 ) - { - limit_T0_fx( L_frame, delta, pit_flag, *limit_flag, mult_Top*T_op[1], 0, T0_min, T0_max ); - } - - /* search and encode the closed loop pitch period */ - *T0 = pitch_fr4_fx( &exc[i_subfr], xn, h1, *T0_min, *T0_max, T0_frac, pit_flag, *limit_flag, PIT_MAX, PIT_MAX, L_FRAME, L_subfr ); - - pit_Q_enc_fx( st_fx, 0, nBits, delta, pit_flag, *limit_flag, *T0, *T0_frac, T0_min, T0_max ); - } - ELSE IF( sub(coder_type,VOICED) == 0 ) - { - /*-------------------------------------------------------* - * Pitch encoding in VOICED mode (ACELP@12k8 core only) - *-------------------------------------------------------*/ - - delta = 4; - move16(); - if ( sub(i_subfr,2*L_SUBFR) == 0 ) - { - pit_flag = i_subfr; - move16(); - } - - /* pitch lag search limitation */ - IF (i_subfr == 0) - { - limit_T0_fx( L_FRAME, delta, pit_flag, *limit_flag, mult_Top*T_op[0], 0, T0_min, T0_max ); - } - - /* search and encode the closed loop pitch period */ - test(); - test(); - IF( sub(nBits,9) == 0 || sub(nBits,5) == 0 ) - { - *T0 = pitch_fr4_fx( &exc[i_subfr], xn, h1, *T0_min, *T0_max, T0_frac, pit_flag, *limit_flag, PIT_FR2_DOUBLEEXTEND_9b, PIT_FR1_DOUBLEEXTEND_9b, L_FRAME, L_SUBFR ); - move16(); - } - ELSE IF( sub(nBits,10) == 0 ) - { - *T0 = pitch_fr4_fx( &exc[i_subfr], xn, h1, *T0_min, *T0_max, T0_frac, pit_flag, *limit_flag, PIT_MAX, PIT_MAX, L_FRAME, L_SUBFR ); - move16(); - } - - pit_Q_enc_fx( st_fx, 0, nBits, delta, pit_flag, *limit_flag, *T0, *T0_frac, T0_min, T0_max ); - } - ELSE - { - /*-------------------------------------------------------* - * Pitch encoding in GENERIC mode - * (both ACELP@12k8 and ACELP@16k cores) - *-------------------------------------------------------*/ - - delta = 8; - move16(); - - /* pitch lag search limitation */ - IF( i_subfr == 0 ) - { - limit_T0_fx( L_frame, delta, pit_flag, *limit_flag, mult_Top*T_op[0], 0, T0_min, T0_max ); - } - ELSE IF( sub(i_subfr,2*L_SUBFR) == 0) - { - limit_T0_fx( L_frame, delta, pit_flag, *limit_flag, mult_Top*T_op[1], 0, T0_min, T0_max ); - } - - /* search and encode the closed loop pitch period */ - IF( sub(L_frame,L_FRAME) == 0 ) - { - test(); - test(); - IF( sub(nBits,8) == 0 || sub(nBits,5) == 0 ) - { - IF( *limit_flag == 0 ) - { - *T0 = pitch_fr4_fx( &exc[i_subfr], xn, h1, *T0_min, *T0_max, T0_frac, pit_flag, *limit_flag, PIT_MIN, PIT_FR1_8b, L_FRAME, L_SUBFR ); - } - ELSE - { - *T0 = pitch_fr4_fx( &exc[i_subfr], xn, h1, *T0_min, *T0_max, T0_frac, pit_flag, *limit_flag, PIT_MIN_EXTEND, PIT_FR1_EXTEND_8b, L_FRAME, L_SUBFR ); - } - } - ELSE IF( sub(nBits,9) == 0 || sub(nBits,6) == 0) - { - IF( *limit_flag == 0 ) - { - *T0 = pitch_fr4_fx( &exc[i_subfr], xn, h1, *T0_min, *T0_max, T0_frac, pit_flag, *limit_flag, PIT_FR2_9b, PIT_FR1_9b, L_FRAME, L_SUBFR ); - } - ELSE - { - *T0 = pitch_fr4_fx( &exc[i_subfr], xn, h1, *T0_min, *T0_max, T0_frac, pit_flag, *limit_flag, PIT_FR2_EXTEND_9b, PIT_FR1_EXTEND_9b, L_FRAME, L_SUBFR ); - } - } - ELSE IF( sub(nBits,10) == 0 ) - { - *T0 = pitch_fr4_fx( &exc[i_subfr], xn, h1, *T0_min, *T0_max, T0_frac, pit_flag, *limit_flag, PIT_MAX, PIT_MAX, L_FRAME, L_SUBFR ); - } - - pit_Q_enc_fx( st_fx, 0, nBits, delta, pit_flag, *limit_flag, *T0, *T0_frac, T0_min, T0_max ); - } - ELSE /* L_frame == L_FRAME16k */ - { - test(); - IF( sub(nBits,9) == 0 || sub(nBits,6) == 0 ) - { - *T0 = pitch_fr4_fx( &exc[i_subfr], xn, h1, *T0_min, *T0_max, T0_frac, pit_flag, *limit_flag, PIT16k_FR2_EXTEND_9b, PIT16k_FR1_EXTEND_9b, L_FRAME16k, L_SUBFR ); - } - ELSE IF( nBits == 10 ) - { - *T0 = pitch_fr4_fx( &exc[i_subfr], xn, h1, *T0_min, *T0_max, T0_frac, pit_flag, *limit_flag, PIT16k_FR2_EXTEND_10b, PIT16k_MAX, L_FRAME16k, L_SUBFR ); - } - - pit16k_Q_enc_fx( st_fx, nBits, *limit_flag, *T0, *T0_frac, T0_min, T0_max ); - } - } - } - - /*-------------------------------------------------------* - * Pitch encoding in AMR-WB IO mode - *-------------------------------------------------------*/ - - ELSE - { - delta = 8; - move16(); - *limit_flag = 0; - move16(); - - IF( L_sub(core_brate,ACELP_6k60) == 0 ) - { - nBits = 5; - move16(); - - /* pitch lag search limitation */ - IF( i_subfr == 0 ) - { - limit_T0_fx( L_FRAME, delta, pit_flag, *limit_flag, i_mult2(mult_Top,T_op[0]), 0, T0_min, T0_max ); - nBits = 8; - move16(); - } - - if( sub(i_subfr,2*L_SUBFR) == 0 ) - { - /* rewrite pit_flag - it must not be zero */ - pit_flag = i_subfr; - move16(); - } - - /* search and encode the closed loop pitch period */ - *T0 = pitch_fr4_fx( &exc[i_subfr], xn, h1, *T0_min, *T0_max, T0_frac, pit_flag, *limit_flag, PIT_MIN, PIT_FR1_8b, L_FRAME, L_SUBFR ); - } - ELSE IF( L_sub(core_brate,ACELP_8k85) == 0 ) - { - nBits = 5; - move16(); - - /* pitch lag search limitation */ - IF( i_subfr == 0 ) - { - limit_T0_fx( L_FRAME, delta, pit_flag, *limit_flag, i_mult2(mult_Top,T_op[0]), 0, T0_min, T0_max ); - nBits = 8; - move16(); - } - ELSE IF( sub(i_subfr,2*L_SUBFR) == 0 ) - { - limit_T0_fx( L_FRAME, delta, pit_flag, *limit_flag, i_mult2(mult_Top,T_op[1]), 0, T0_min, T0_max ); - nBits = 8; - move16(); - } - - /* search and encode the closed loop pitch period */ - *T0 = pitch_fr4_fx( &exc[i_subfr], xn, h1, *T0_min, *T0_max, T0_frac, pit_flag, *limit_flag, PIT_MIN, PIT_FR1_8b, L_FRAME, L_SUBFR ); - } - ELSE - { - nBits = 6; - move16(); - - /* pitch lag search limitation */ - IF( i_subfr == 0 ) - { - limit_T0_fx( L_FRAME, delta, pit_flag, *limit_flag, i_mult2(mult_Top,T_op[0]), 0, T0_min, T0_max ); - nBits = 9; - move16(); - } - ELSE IF( sub(i_subfr,2*L_SUBFR) == 0 ) - { - limit_T0_fx( L_FRAME, delta, pit_flag, *limit_flag, i_mult2(mult_Top,T_op[1]), 0, T0_min, T0_max ); - nBits = 9; - move16(); - } - ELSE - { - limit_T0_fx( L_FRAME, delta, pit_flag, 0, *T0, 0, T0_min, T0_max ); /* T0_frac==0 to keep IO with AMR-WB */ - } - - /* search and encode the closed loop pitch period */ - *T0 = pitch_fr4_fx( &exc[i_subfr], xn, h1, *T0_min, *T0_max, T0_frac, pit_flag, *limit_flag, PIT_FR2_9b, PIT_FR1_9b, L_FRAME, L_SUBFR ); - } - - pit_Q_enc_fx( st_fx, 1, nBits, delta, pit_flag, *limit_flag, *T0, *T0_frac, T0_min, T0_max ); - } - - /*-------------------------------------------------------* - * Compute floating pitch output - *-------------------------------------------------------*/ - - /*pitch = (float)(*T0) + (float)(*T0_frac)/4.0f;*/ /* save subframe pitch values */ - pitch = shl(add(shl(*T0,2),*T0_frac),4); /* save subframe pitch values Q6 */ - - return pitch; - -} - -/*-------------------------------------------------------------------* - * abs_pit_enc() - * - * Encode pitch lag absolutely with resolution for shortest pitches - * depending on parameter 'fr_step': - * fr_step = 2: pitch range encoded with 8 bits - * fr_step = 4: pitch range encoded with 8 bits - *-------------------------------------------------------------------*/ - -Word16 abs_pit_enc_fx( /* o : pitch index */ - const Word16 fr_steps, /* i : fractional resolution steps (2 or 4) for shortest pitches*/ - const Word16 limit_flag, /* i : restrained(0) or extended(1) limits */ - const Word16 T0, /* i : integer pitch lag */ - const Word16 T0_frac /* i : pitch fraction */ -) -{ - Word16 pitch_index = 0; - - IF( limit_flag == 0 ) - { - IF( sub(fr_steps,2) == 0 ) - { - /*-----------------------------------------------------------------* - * The pitch range is encoded absolutely with 8 bits - * and is divided as follows: - * PIT_MIN to PIT_FR1_8b-1 resolution 1/2 (frac = 0 or 2) - * PIT_FR1_8b to PIT_MAX resolution 1 (frac = 0) - *-----------------------------------------------------------------*/ - - IF (sub(T0,PIT_FR1_8b) < 0) - { - /*pitch_index = T0*2 + (T0_frac>>1) - (PIT_MIN*2);*/ - pitch_index = sub(add(shl(T0,1),shr(T0_frac,1)),(PIT_MIN*2)); - } - ELSE - { - /*pitch_index = T0 - PIT_FR1_8b + ((PIT_FR1_8b-PIT_MIN)*2);*/ - pitch_index = add(sub(T0,PIT_FR1_8b),((PIT_FR1_8b-PIT_MIN)*2)); - } - } - ELSE IF( sub(fr_steps,4) == 0 ) - { - /*-------------------------------------------------------------------* - * The pitch range is encoded absolutely with 9 bits - * and is divided as follows: - * PIT_MIN to PIT_FR2_9b-1 resolution 1/4 (frac = 0,1,2 or 3) - * PIT_FR2_9b to PIT_FR1_9b-1 resolution 1/2 (frac = 0 or 2) - * PIT_FR1_9b to PIT_MAX resolution 1 (frac = 0) - *-------------------------------------------------------------------*/ - - IF (sub(T0,PIT_FR2_9b) < 0) - { - /*pitch_index = T0*4 + T0_frac - (PIT_MIN*4);*/ - pitch_index = add(shl(T0,2),sub(T0_frac,(PIT_MIN*4))); - } - ELSE IF (sub(T0,PIT_FR1_9b) < 0) - { - /* pitch_index = T0*2 + (T0_frac>>1) - (PIT_FR2_9b*2) + ((PIT_FR2_9b-PIT_MIN)*4);*/ - pitch_index = add(sub(add(shl(T0,1),shr(T0_frac,1)),(PIT_FR2_9b*2)),((PIT_FR2_9b-PIT_MIN)*4)); - } - ELSE - { - /* pitch_index = T0 - PIT_FR1_9b + ((PIT_FR2_9b-PIT_MIN)*4) + ((PIT_FR1_9b-PIT_FR2_9b)*2);*/ - pitch_index = add(add(sub(T0,PIT_FR1_9b),((PIT_FR2_9b-PIT_MIN)*4)),((PIT_FR1_9b-PIT_FR2_9b)*2)); - } - } - ELSE /* fr_step == 0 */ - { - /* not used in the codec */ - pitch_index = 0; - move16(); - } - } - ELSE IF( sub(limit_flag,1) == 0 ) /* extended Q range */ - { - IF( sub(fr_steps,2) == 0 ) - { - /*-----------------------------------------------------------------* - * The pitch range is encoded absolutely with 8 bits - * and is divided as follows: - * PIT_MIN_EXTEND to PIT_FR1_EXTEND_8b-1 resolution 1/2 (frac = 0 or 2) - * PIT_FR1_EXTEND_8b to PIT_MAX_EXTEND resolution 1 (frac = 0) - *-----------------------------------------------------------------*/ - - IF( sub(T0,PIT_FR1_EXTEND_8b) < 0 ) - { - /*pitch_index = T0*2 + (T0_frac>>1) - (PIT_MIN_EXTEND*2);*/ - pitch_index = sub(add(shl(T0,1),shr(T0_frac,1)),(PIT_MIN_EXTEND*2)); - } - ELSE - { - /*pitch_index = T0 - PIT_FR1_EXTEND_8b + ((PIT_FR1_EXTEND_8b-PIT_MIN_EXTEND)*2);*/ - pitch_index = add(sub(T0,PIT_FR1_EXTEND_8b),((PIT_FR1_EXTEND_8b-PIT_MIN_EXTEND)*2)); - } - } - ELSE IF( sub(fr_steps,4) == 0 ) - { - /*-------------------------------------------------------------------* - * The pitch range is encoded absolutely with 9 bits - * and is divided as follows: - * PIT_MIN_EXTEND to PIT_FR2__EXTEND9b-1 resolution 1/4 (frac = 0,1,2 or 3) - * PIT_FR2_EXTEND_9b to PIT_FR1__EXTEND9b-1 resolution 1/2 (frac = 0 or 2) - * PIT_FR1_EXTEND_9b to PIT_MAX_EXTEND resolution 1 (frac = 0) - *-------------------------------------------------------------------*/ - - IF( sub(T0,PIT_FR2_EXTEND_9b) < 0) - { - /*pitch_index = T0*4 + T0_frac - (PIT_MIN_EXTEND*4);*/ - pitch_index = add(shl(T0,2),sub(T0_frac,(PIT_MIN_EXTEND*4))); - } - ELSE IF( T0 < PIT_FR1_EXTEND_9b ) - { - /*pitch_index = T0*2 + (T0_frac>>1) - (PIT_FR2_EXTEND_9b*2) + ((PIT_FR2_EXTEND_9b-PIT_MIN_EXTEND)*4);*/ - pitch_index = add(sub(add(shl(T0,1),shr(T0_frac,1)),(PIT_FR2_EXTEND_9b*2)),((PIT_FR2_EXTEND_9b-PIT_MIN_EXTEND)*4)); - } - ELSE - { - /*pitch_index = T0 - PIT_FR1_EXTEND_9b + ((PIT_FR2_EXTEND_9b-PIT_MIN_EXTEND)*4) + ((PIT_FR1_EXTEND_9b-PIT_FR2_EXTEND_9b)*2);*/ - pitch_index = add(add(sub(T0,PIT_FR1_EXTEND_9b),((PIT_FR2_EXTEND_9b-PIT_MIN_EXTEND)*4)),((PIT_FR1_EXTEND_9b-PIT_FR2_EXTEND_9b)*2)); - } - - } - ELSE /* fr_step == 0 */ - { - /* not used in the codec */ - pitch_index = 0; - move16(); - } - } - ELSE /* double-extended Q range */ - { - IF( sub(fr_steps,2) == 0 ) - { - /*-----------------------------------------------------------------* - * The pitch range is encoded absolutely with 8 bits - * and is divided as follows: - * PIT_MIN_DOUBLEEXTEND to PIT_FR1_DOUBLEEXTEND_8b-1 resolution 1/2 (frac = 0 or 2) - * PIT_FR1_DOUBLEEXTEND_8b to PIT_MAX_EXTEND resolution 1 (frac = 0) - *-----------------------------------------------------------------*/ - - IF( sub(T0,PIT_FR1_DOUBLEEXTEND_8b) < 0) - { - /*pitch_index = T0*2 + (T0_frac>>1) - (PIT_MIN_DOUBLEEXTEND*2);*/ - pitch_index = sub(add(shl(T0,1),shr(T0_frac,1)),(PIT_MIN_DOUBLEEXTEND*2)); - } - ELSE - { - /*pitch_index = T0 - PIT_FR1_DOUBLEEXTEND_8b + ((PIT_FR1_DOUBLEEXTEND_8b-PIT_MIN_DOUBLEEXTEND)*2); */ - pitch_index = add(sub(T0,PIT_FR1_DOUBLEEXTEND_8b),((PIT_FR1_DOUBLEEXTEND_8b-PIT_MIN_DOUBLEEXTEND)*2)); - } - } - ELSE IF( sub(fr_steps,4) == 0 ) - { - /*-------------------------------------------------------------------* - * The pitch range is encoded absolutely with 9 bits - * and is divided as follows: - * PIT_MIN_DOUBLEEXTEND to PIT_FR2_DOUBLEEXTEND9b-1 resolution 1/4 (frac = 0,1,2 or 3) - * PIT_FR2_DOUBLEEXTEND_9b to PIT_FR1_DOOBLEEXTEND9b-1 resolution 1/2 (frac = 0 or 2) - * PIT_FR1_DOUBLEEXTEND_9b to PIT_MAX_EXTEND resolution 1 (frac = 0) - *-------------------------------------------------------------------*/ - - IF(sub(T0,PIT_FR2_DOUBLEEXTEND_9b) < 0) - { - /*pitch_index = T0*4 + T0_frac - (PIT_MIN_DOUBLEEXTEND*4);*/ - pitch_index = add(shl(T0,2),sub(T0_frac,(PIT_MIN_DOUBLEEXTEND*4))); - } - ELSE IF( sub(T0,PIT_FR1_DOUBLEEXTEND_9b) < 0 ) - { - /*pitch_index = T0*2 + (T0_frac>>1) - (PIT_FR2_DOUBLEEXTEND_9b*2) + ((PIT_FR2_DOUBLEEXTEND_9b-PIT_MIN_DOUBLEEXTEND)*4);*/ - pitch_index = add(sub(add(shl(T0,1),shr(T0_frac,1)),(PIT_FR2_DOUBLEEXTEND_9b*2)),((PIT_FR2_DOUBLEEXTEND_9b-PIT_MIN_DOUBLEEXTEND)*4)); - } - ELSE - { - /*pitch_index = T0 - PIT_FR1_DOUBLEEXTEND_9b + ((PIT_FR2_DOUBLEEXTEND_9b-PIT_MIN_DOUBLEEXTEND)*4) + ((PIT_FR1_DOUBLEEXTEND_9b-PIT_FR2_DOUBLEEXTEND_9b)*2);*/ - pitch_index = add(add(sub(T0,PIT_FR1_DOUBLEEXTEND_9b),((PIT_FR2_DOUBLEEXTEND_9b-PIT_MIN_DOUBLEEXTEND)*4)),((PIT_FR1_DOUBLEEXTEND_9b-PIT_FR2_DOUBLEEXTEND_9b)*2)); - } - } - ELSE /* fr_step == 0 */ - { - /* not used in the codec */ - pitch_index = 0; - move16(); - } - } - - return pitch_index; -} - - -/*-------------------------------------------------------------------* - * delta_pit_enc: - * - * Encode pitch lag differentially from T0_min to T0_max - * with resolution depending on parameter 'fr_step': - * fr_step = 0: resolusion 1 (frac = 0), or - * fr_step = 2: resolusion 1/2 (frac = 0 or 2), or - * fr_step = 4: resolution 1/4 (frac = 0, 1, 2, or 3) - *-------------------------------------------------------------------*/ - -Word16 delta_pit_enc_fx( /* o : pitch index */ - const Word16 fr_steps, /* i : fractional resolution steps (2 or 4)*/ - const Word16 T0, /* i : integer pitch lag */ - const Word16 T0_frac, /* i : pitch fraction */ - const Word16 T0_min /* i : delta search min */ -) -{ - Word16 pitch_index = 0; - - IF( fr_steps == 0 ) - { - pitch_index = sub(T0,T0_min); - } - ELSE IF( sub(fr_steps,2) == 0 ) - { - /* pitch_index = (T0 - T0_min) * 2 + (T0_frac>>1);*/ - pitch_index = add(shl(sub(T0,T0_min),1),shr(T0_frac,1)); - } - ELSE IF( sub(fr_steps,4) == 0 ) - { - /*pitch_index = (T0 - T0_min) * 4 + T0_frac;*/ - pitch_index = add(shl(sub(T0,T0_min),2),T0_frac); - } - - return pitch_index; -} - -/*-------------------------------------------------------------------* - * pitch_fr4() - * - * Find the closed loop pitch period with 1/4 subsample resolution. - *-------------------------------------------------------------------*/ - -Word16 pitch_fr4_fx( /* o : chosen integer pitch lag */ - const Word16 exc[], /* i : excitation buffer Q_new*/ - const Word16 xn[], /* i : target signal Q_new-1+shift*/ - const Word16 h[], /* i : weighted synthesis filter impulse response Q(14+shift)*/ - const Word16 t0_min, /* i : minimum value in the searched range. Q0*/ - const Word16 t0_max, /* i : maximum value in the searched range. Q0*/ - Word16 *pit_frac, /* o : chosen fraction (0, 1, 2 or 3) */ - const Word16 i_subfr, /* i : flag to first subframe */ - const Word16 limit_flag, /* i : flag for limits (0=restrained, 1=extended) */ - const Word16 t0_fr2, /* i : minimum value for resolution 1/2 */ - const Word16 t0_fr1, /* i : minimum value for resolution 1 */ - const Word16 L_frame, /* i : length of the frame */ - const Word16 L_subfr /* i : size of subframe */ -) -{ - Word16 i; - Word16 t_min, t_max; - Word16 max, t0, t1, fraction, step, temp; - Word16 *corr; - Word16 corr_v[15+2*L_INTERPOL1+1]; /* Total length = t0_max-t0_min+1+2*L_inter */ - Word16 pit_min; - Word16 cor_max; - - /* initialization */ - IF( limit_flag == 0 ) - { - IF( sub(L_frame,L_FRAME) == 0 ) - { - pit_min = PIT_MIN; - move16(); - } - ELSE /* L_frame == L_FRAME16k */ - { - pit_min = PIT16k_MIN; - move16(); - } - } - ELSE - { - IF( sub(L_frame,L_FRAME) == 0 ) - { - pit_min = PIT_MIN_EXTEND; - move16(); - IF( sub(limit_flag,2) == 0 ) - { - pit_min = PIT_MIN_DOUBLEEXTEND; - move16(); - } - } - ELSE /* L_frame == L_FRAME16k */ - { - pit_min = PIT16k_MIN_EXTEND; - move16(); - } - } - - /*-----------------------------------------------------------------* - * - Find interval to compute normalized correlation - * - allocate memory to normalized correlation vector - * - Compute normalized correlation between target and filtered - * excitation - *-----------------------------------------------------------------*/ - - t_min = sub(t0_min, L_INTERPOL1); - t_max = add(t0_max, L_INTERPOL1); - corr = &corr_v[-t_min]; - move16(); - move16(); /* corr[t_min..t_max] */ - - norm_corr_fx( exc, xn, h, t_min, t_max, corr, L_subfr ); - - /*-----------------------------------------------------------------* - * Find integer pitch - *-----------------------------------------------------------------*/ - - max = corr[t0_min]; - move16(); - t0 = t0_min; - move16(); - - FOR (i = add(t0_min, 1); i <= t0_max; i++) - { - if (corr[i] >= max) - { - t0 = i; - move16(); - } - max = s_max(corr[i], max); - } - - IF( sub(t0_fr1,pit_min) == 0 ) - { - /* don't search fraction (for 7b/4b quant) */ - test(); - IF((i_subfr == 0) && (sub(t0,t0_fr2) >= 0)) - { - i = shl(shr(t0,1),1); /* 2 samples resolution */ - if (sub(add(i,2),PIT_MAX) > 0) - { - i = sub(i,2); - } - IF (sub(corr[i],corr[i+2]) > 0) - { - t0 = i; - move16(); - } - ELSE - { - t0 = add(i,2); - } - } - *pit_frac = 0; - move16(); - - return(t0); - } - - test(); - IF( (i_subfr == 0) && (sub(t0,t0_fr1) >= 0) ) - { - *pit_frac = 0; - move16(); - - return(t0); - } - - /*------------------------------------------------------------------* - * Search fractionnal pitch with 1/4 subsample resolution. - * search the fractions around t0 and choose the one which maximizes - * the interpolated normalized correlation. - *-----------------------------------------------------------------*/ - - t1 = t0; - move16(); - step = 1; - move16(); /* 1/4 subsample resolution */ - fraction = 1; - move16(); - test(); - test(); - IF (((i_subfr == 0) && (sub(t0,t0_fr2) >= 0)) || (sub(t0_fr2,pit_min) == 0)) - { - step = 2; - move16(); /* 1/2 subsample resolution */ - fraction = 2; - move16(); - } - - IF (sub(t0,t0_min) == 0) /* Limit case */ - { - fraction = 0; - move16(); - cor_max = Interpol_4( &corr[t0], fraction); - } - ELSE - { - t0 = sub(t0, 1); - cor_max = Interpol_4( &corr[t0], fraction); - FOR(i = add(fraction, step); i <= 3; i = (Word16) (i + step)) - { - temp = Interpol_4( &corr[t0], i); - IF (sub(temp,cor_max) > 0) - { - cor_max = temp; - move16(); - fraction = i; - move16(); - } - } - } - - FOR (i = 0; i <= 3; i = (Word16) (i + step)) - { - temp = Interpol_4( &corr[t1], i); - IF (sub(temp,cor_max) > 0) - { - cor_max = temp; - move16(); - fraction = i; - move16(); - t0 = t1; - move16(); - } - } - - *pit_frac = fraction; - move16(); - - return (t0); - -} - -/*-------------------------------------------------------------------* - * norm_corr() - * - * Find the normalized correlation between the target vector and the - * filtered past excitation (correlation between target and filtered - * excitation divided by the square root of energy of filtered - * excitation) - *---------------------------------------------------------------------*/ - -void norm_corr_fx( - const Word16 exc[], /* i : excitation buffer Q_new*/ - const Word16 xn[], /* i : target signal Q_new-1+shift*/ - const Word16 h[], /* i : weighted synthesis filter impulse response Q(14+shift)*/ - const Word16 t_min, /* i : minimum value of searched range */ - const Word16 t_max, /* i : maximum value of searched range */ - Word16 ncorr[], /* o : normalized correlation Q15 */ - const Word16 L_subfr /* i : subframe size */ -) -{ - Word16 i, k, t; - Word16 corr, exp_corr, norm, exp_norm, exp, scale; - Word16 excf[L_FRAME16k]; - Word32 L_tmp; - - k = negate(t_min); - - /*-----------------------------------------------------------------* - * compute the filtered excitation for the first delay t_min - *-----------------------------------------------------------------*/ - - conv_fx( &exc[k], h, excf, L_subfr ); - - /* Compute rounded down 1/sqrt(energy of xn[]) */ - L_tmp = L_mac(1, xn[0], xn[0]); - FOR (i = 1; i < L_subfr; i++) - { - L_tmp = L_mac(L_tmp, xn[i], xn[i]); - } - exp = norm_l(L_tmp); - exp = sub(30, exp); - - exp = add(exp, 2); /* energy of xn[] x 2 + rounded up */ - scale = negate(shr(exp, 1)); /* (1< 0; i--) - { - /* saturation can occur in add() */ - /*excf[i] = add(mult(exc[k], h[i]), excf[i - 1]); move16(); */ - excf[i] = round_fx(L_mac(L_mult(excf[i - 1], 32767), exc[k], h[i])); - } - excf[0] = mult_r(exc[k], h[0]); - move16(); - } - } - - return; -} - -/*-------------------------------------------------------------------* - * pit_Q_enc() - * - * Encode subframe pitch lag - *-------------------------------------------------------------------*/ - -void pit_Q_enc_fx( - Encoder_State_fx *st_fx, /* i/o: encoder state structure */ - const Word16 Opt_AMR_WB, /* i : flag indicating AMR-WB IO mode */ - const Word16 nBits, /* i : # of Q bits */ - const Word16 delta, /* i : Half the CL searched interval */ - const Word16 pit_flag, /* i : absolute(0) or delta(1) pitch Q */ - const Word16 limit_flag, /* i : restrained(0) or extended(1) Q limits */ - const Word16 T0, /* i : integer pitch lag */ - const Word16 T0_frac, /* i : pitch fraction */ - Word16 *T0_min, /* i/o: delta search min */ - Word16 *T0_max /* o : delta search max */ -) -{ - Word16 pitch_index; - - IF( sub(nBits,10) == 0 ) /* absolute encoding with 10 bits */ - { - IF( limit_flag == 0 ) - { - /* pitch_index = T0*4 + T0_frac - (PIT_MIN*4);*/ - pitch_index = sub(add(shl(T0 , 2), T0_frac), (PIT_MIN*4)); - } - ELSE IF( sub(limit_flag,1) == 0 ) - { - /*pitch_index = T0*4 + T0_frac - (PIT_MIN_EXTEND*4);*/ - pitch_index = sub(add(shl(T0 , 2),T0_frac),(PIT_MIN_EXTEND*4)); - } - ELSE /* limit_flag == 2 */ - { - /*pitch_index = T0*4 + T0_frac - (PIT_MIN_DOUBLEEXTEND*4);*/ - pitch_index = sub(add(shl(T0 , 2) ,T0_frac) , (PIT_MIN_DOUBLEEXTEND*4)); - } - } - ELSE IF( sub(nBits,9) == 0 ) /* absolute encoding with 9 bits */ - { - pitch_index = abs_pit_enc_fx( 4, limit_flag, T0, T0_frac ); - - /* find T0_min and T0_max for delta search */ - IF( Opt_AMR_WB ) - { - limit_T0_fx( L_FRAME, delta, pit_flag, 0, T0, 0, T0_min, T0_max ); /* T0_frac==0 to keep IO with AMR-WB */ - } - } - ELSE IF( sub(nBits,8) == 0 ) /* absolute encoding with 8 bits */ - { - pitch_index = abs_pit_enc_fx( 2, limit_flag, T0, T0_frac ); - - /* find T0_min and T0_max for delta search */ - IF( Opt_AMR_WB ) - { - limit_T0_fx( L_FRAME, delta, pit_flag, 0, T0, 0, T0_min, T0_max ); /* T0_frac==0 to keep IO with AMR-WB */ - } - } - ELSE IF( sub(nBits,6) == 0 ) /* relative encoding with 6 bits */ - { - pitch_index = delta_pit_enc_fx( 4, T0, T0_frac, *T0_min ); - } - ELSE IF( sub(nBits,5) == 0 ) /* relative encoding with 5 bits */ - { - IF( sub(delta,8) == 0 ) - { - pitch_index = delta_pit_enc_fx( 2, T0, T0_frac, *T0_min ); - } - ELSE /* delta == 4 */ - { - pitch_index = delta_pit_enc_fx( 4, T0, T0_frac, *T0_min ); - } - } - ELSE /* nBits == 4 ) */ /* relative encoding with 4 bits */ - { - IF( sub(delta,8) == 0 ) - { - pitch_index = delta_pit_enc_fx( 0, T0, T0_frac, *T0_min ); - } - ELSE /* delta == 4 */ - { - pitch_index = delta_pit_enc_fx( 2, T0, T0_frac, *T0_min ); - } - } - - IF( !Opt_AMR_WB ) - { - /* find T0_min and T0_max for delta search */ - limit_T0_fx( L_FRAME, delta, L_SUBFR, limit_flag, T0, T0_frac, T0_min, T0_max ); - } - - { - push_indice_fx( st_fx, IND_PITCH, pitch_index, nBits ); - } - - return; -} - -/*-------------------------------------------------------------------* - * pit16k_Q_enc() - * - * Encode subframe pitch lag @16kHz core - *-------------------------------------------------------------------*/ - -void pit16k_Q_enc_fx( - Encoder_State_fx *st_fx, /* i/o: encoder state structure */ - const Word16 nBits, /* i : # of Q bits */ - const Word16 limit_flag, /* i : restrained(0) or extended(1) Q limits */ - const Word16 T0, /* i : integer pitch lag */ - const Word16 T0_frac, /* i : pitch fraction */ - Word16 *T0_min, /* i/o: delta search min */ - Word16 *T0_max /* o : delta search max */ -) -{ - Word16 pitch_index; - - IF( sub(nBits,10) == 0 ) /* absolute encoding with 10 bits */ - { - { - IF( sub(T0,PIT16k_FR2_EXTEND_10b) < 0) - { - /*pitch_index = T0*4 + T0_frac - (PIT16k_MIN_EXTEND*4);*/ - pitch_index = add(shl(T0 , 2) , sub(T0_frac , (PIT16k_MIN_EXTEND*4))); - } - ELSE - { - /*pitch_index = T0*2 + (T0_frac>>1) - (PIT16k_FR2_EXTEND_10b*2) + ((PIT16k_FR2_EXTEND_10b-PIT16k_MIN_EXTEND)*4);*/ - pitch_index = add(sub(add(shl(T0,1),shr(T0_frac,1)),(PIT16k_FR2_EXTEND_10b*2)),((PIT16k_FR2_EXTEND_10b-PIT16k_MIN_EXTEND)*4)); - } - } - - push_indice_fx( st_fx, IND_PITCH, pitch_index, nBits ); - } - ELSE IF( sub(nBits,9) == 0 ) /* absolute encoding with 9 bits */ - { - { - /*-------------------------------------------------------------------* - * The pitch range is encoded absolutely with 9 bits - * and is divided as follows: - * PIT16k_EXTEND_MIN to PIT16k_FR2_EXTEND_9b-1 resolution 1/4 (frac = 0,1,2 or 3) - * PIT16k_FR2_EXTEND_9b to PIT16k_FR1_EXTEND_9b-1 resolution 1/2 (frac = 0 or 2) - * PIT16k_FR1_EXTEND_9b to PIT16k_MAX_EXTEND resolution 1 (frac = 0) - *-------------------------------------------------------------------*/ - - IF( sub(T0,PIT16k_FR2_EXTEND_9b) < 0) - { - /*pitch_index = T0*4 + T0_frac - (PIT16k_MIN_EXTEND*4);*/ - pitch_index = add(shl(T0 , 2) , sub(T0_frac , (PIT16k_MIN_EXTEND*4))); - } - ELSE IF( sub(T0,PIT16k_FR1_EXTEND_9b) < 0 ) - { - /*pitch_index = T0*2 + (T0_frac>>1) - (PIT16k_FR2_EXTEND_9b*2) + ((PIT16k_FR2_EXTEND_9b-PIT16k_MIN_EXTEND)*4);*/ - pitch_index = add(sub(add(shl(T0,1),shr(T0_frac,1)),(PIT16k_FR2_EXTEND_9b*2)),((PIT16k_FR2_EXTEND_9b-PIT16k_MIN_EXTEND)*4)); - } - ELSE - { - /*pitch_index = T0 - PIT16k_FR1_EXTEND_9b + ((PIT16k_FR2_EXTEND_9b-PIT16k_MIN_EXTEND)*4) + ((PIT16k_FR1_EXTEND_9b-PIT16k_FR2_EXTEND_9b)*2);*/ - pitch_index = add(add(sub(T0, PIT16k_FR1_EXTEND_9b) , ((PIT16k_FR2_EXTEND_9b-PIT16k_MIN_EXTEND)*4)), ((PIT16k_FR1_EXTEND_9b-PIT16k_FR2_EXTEND_9b)*2)); - } - } - - push_indice_fx( st_fx, IND_PITCH, pitch_index, 9 ); - } - ELSE /* nBits == 6 */ /* relative encoding with 6 bits */ - { - /*pitch_index = (T0 - *T0_min) * 4 + T0_frac;*/ - pitch_index = add(shl(sub(T0,*T0_min),2),T0_frac); - - push_indice_fx( st_fx, IND_PITCH, pitch_index, nBits ); - } - - limit_T0_fx( L_FRAME16k, 8, L_SUBFR, limit_flag, T0, T0_frac, T0_min, T0_max ); - - return; -} - - -/*------------------------------------------------------------------* - * pit_encode: - * - * Close-loop pitch lag search and pitch lag quantization - * Adaptive excitation construction - *------------------------------------------------------------------*/ -void Mode2_pit_encode( - const Word16 coder_type, /* i : coding model */ - const Word16 i_subfr, /* i : subframe index */ - Word16 **pt_indice, /* i/o: quantization indices pointer */ - Word16 *exc, /* i/o: pointer to excitation signal frame */ - const Word16 *T_op, /* i : open loop pitch estimates in current frame */ - Word16 *T0_min, /* i/o: lower limit for close-loop search */ - Word16 *T0_min_frac, /* i/o: lower limit for close-loop search */ - Word16 *T0_max, /* i/o: higher limit for close-loop search */ - Word16 *T0_max_frac, /* i/o: higher limit for close-loop search */ - Word16 *T0, /* i/o: close loop integer pitch */ - Word16 *T0_frac, /* i/o: close loop fractional part of the pitch */ - Word16 *T0_res, /* i/o: close loop pitch resolution */ - Word16 *h1, /* i : weighted filter impulse response 1Q14+shift*/ - Word16 *xn, /* i : target vector */ - Word16 pit_min, - Word16 pit_fr1, - Word16 pit_fr1b, - Word16 pit_fr2, - Word16 pit_max, - Word16 pit_res_max -) -{ - Word16 pit_flag; - - BASOP_SATURATE_ERROR_ON; - - /* Pitch flag */ - pit_flag = i_subfr; - move16(); - if ( sub(i_subfr,(2*L_SUBFR)) == 0) - { - pit_flag = 0; - move16(); - } - - /*-----------------------------------------------------------------* - * - Limit range of pitch search - * - Fractional pitch search - * - Pitch quantization - *-----------------------------------------------------------------*/ - IF(coder_type == 0) /*Unvoiced Coding do nothing*/ - { - *T0 = L_SUBFR; - move16(); - *T0_frac = 0; - move16(); - *T0_res = 1; - move16(); - - } - ELSE IF(sub(coder_type,1) == 0) /* 8/4/4/4 (EVS) */ - { - IF (i_subfr == 0) - { - limit_T0_voiced( 4, shr(pit_res_max,1), T_op[0], 0, 1, T0_min, T0_min_frac, T0_max, T0_max_frac, pit_min, pit_max ); - } - ELSE - { - limit_T0_voiced( 4, shr(pit_res_max,1), *T0, *T0_frac, *T0_res, T0_min, T0_min_frac, T0_max, T0_max_frac, pit_min, pit_max ); - } - *T0 = E_GAIN_closed_loop_search(exc, xn, h1, *T0_min, *T0_min_frac, *T0_max, *T0_max_frac, shr(pit_res_max,1), T0_frac, T0_res, pit_res_max, - i_subfr, pit_min, pit_min, pit_fr1b, L_SUBFR); - move16(); - - IF (i_subfr == 0) - { - Mode2_abs_pit_enc( *T0, *T0_frac, pt_indice, pit_min, pit_fr1b, pit_min, pit_res_max ); - } - ELSE - { - Mode2_delta_pit_enc( *T0, *T0_frac, shr(pit_res_max,1), *T0_min, *T0_min_frac, pt_indice ); - } - - } - ELSE IF(sub(coder_type,2) == 0) /* 8/5/8/5 (EVS) */ - { - IF (i_subfr == 0) - { - limit_T0_voiced( 5, shr(pit_res_max,1), T_op[0], 0, 1, T0_min, T0_min_frac, T0_max, T0_max_frac, pit_min, pit_max ); - } - ELSE IF(i_subfr == 2*L_SUBFR) - { - limit_T0_voiced( 5, shr(pit_res_max,1), T_op[1], 0, 1, T0_min, T0_min_frac, T0_max, T0_max_frac, pit_min, pit_max ); - } - ELSE - { - limit_T0_voiced( 5, shr(pit_res_max,1), *T0, *T0_frac, *T0_res, T0_min, T0_min_frac, T0_max, T0_max_frac, pit_min, pit_max ); - } - *T0 = E_GAIN_closed_loop_search(exc, xn, h1, *T0_min, *T0_min_frac, *T0_max, *T0_max_frac, shr(pit_res_max,1), T0_frac, T0_res, pit_res_max, - pit_flag, pit_min, pit_min, pit_fr1b, L_SUBFR); - move16(); - - IF (pit_flag == 0) - { - Mode2_abs_pit_enc( *T0, *T0_frac, pt_indice, pit_min, pit_fr1b, pit_min, pit_res_max ); - } - ELSE - { - Mode2_delta_pit_enc( *T0, *T0_frac, shr(pit_res_max,1), *T0_min, *T0_min_frac, pt_indice ); - } - } - ELSE IF(sub(coder_type,3) == 0) /* 9/6/6/6 (HRs- VC) */ - { - Word16 pit_res_max2 = pit_res_max; - - if ( sub(pit_min,PIT_MIN_16k)==0 ) - { - pit_res_max2 = shr(pit_res_max, 1); - } - - IF ( (i_subfr == 0) ) - { - limit_T0_voiced2( pit_res_max2, T_op, T0_min, T0_min_frac, T0_max, T0_max_frac, pit_min, pit_max, i_subfr ); - } - ELSE - { - limit_T0_voiced( 6, pit_res_max2, *T0, 0, 1, T0_min, T0_min_frac, T0_max, T0_max_frac, pit_min, pit_max); - } - *T0 = E_GAIN_closed_loop_search(exc, xn, h1, *T0_min, *T0_min_frac, *T0_max, *T0_max_frac, pit_res_max2, T0_frac, T0_res, pit_res_max, - i_subfr, pit_min, pit_fr2, pit_fr1, L_SUBFR); - move16(); - - IF (i_subfr == 0) /* if 1st subframe */ - { - Mode2_abs_pit_enc( *T0, *T0_frac, pt_indice, pit_min, pit_fr1, pit_fr2, pit_res_max ); - } - ELSE - { - Mode2_delta_pit_enc( *T0, *T0_frac, pit_res_max2, *T0_min, *T0_min_frac, pt_indice ); - } - } - ELSE IF(coder_type == 4) /* 9/6/9/6 (AMRWB) */ - { - Word16 pit_res_max2 = pit_res_max; - if ( sub(pit_min,PIT_MIN_16k) == 0 ) - { - pit_res_max2 = shr(pit_res_max,1); - } - test(); - IF ( (i_subfr == 0) || sub(i_subfr,shl(L_SUBFR,1)) == 0 ) - { - limit_T0_voiced2( pit_res_max2, T_op, T0_min, T0_min_frac, T0_max, T0_max_frac, pit_min, pit_max, i_subfr ); - } - ELSE - { - limit_T0_voiced( 6, pit_res_max2, *T0, 0, 1, T0_min, T0_min_frac, T0_max, T0_max_frac, pit_min, pit_max); - } - *T0 = E_GAIN_closed_loop_search(exc, xn, h1, *T0_min, *T0_min_frac, *T0_max, *T0_max_frac, pit_res_max2, T0_frac, T0_res, pit_res_max, - pit_flag, pit_min, pit_fr2, pit_fr1, L_SUBFR); - IF (pit_flag == 0) /* if 1st/3rd/5th subframe */ - { - Mode2_abs_pit_enc( *T0, *T0_frac, pt_indice, pit_min, pit_fr1, pit_fr2, pit_res_max ); - } - ELSE /* if subframe 2 or 4 */ - { - Mode2_delta_pit_enc( *T0, *T0_frac, pit_res_max2, *T0_min, *T0_min_frac, pt_indice ); - } - } - ELSE IF(sub(coder_type,8) == 0) /* 8/5/5/5 (RF all pred mode) */ - { - IF (i_subfr == 0) - { - limit_T0_voiced( 5, shr(pit_res_max,1), T_op[0], 0, 1, T0_min, T0_min_frac, T0_max, T0_max_frac, pit_min, pit_max ); - } - ELSE - { - limit_T0_voiced( 5, shr(pit_res_max,1), *T0, *T0_frac, *T0_res, T0_min, T0_min_frac, T0_max, T0_max_frac, pit_min, pit_max ); - } - *T0 = E_GAIN_closed_loop_search( exc, xn, h1, *T0_min, *T0_min_frac, *T0_max, *T0_max_frac, shr(pit_res_max,1), T0_frac, T0_res, pit_res_max, - i_subfr, pit_min, pit_min, pit_fr1b, L_SUBFR ); - - IF (i_subfr == 0) - { - Mode2_abs_pit_enc( *T0, *T0_frac, pt_indice, pit_min, pit_fr1b, pit_min, pit_res_max ); - } - ELSE - { - Mode2_delta_pit_enc( *T0, *T0_frac, shr(pit_res_max,1), *T0_min, *T0_min_frac, pt_indice ); - } - } - ELSE IF(sub(coder_type,9) == 0) /* 8/0/8/0 (RF mode Gen pred) */ - { - IF (i_subfr == 0) - { - limit_T0_voiced( 4, shr(pit_res_max,1), T_op[0], 0, 1, T0_min, T0_min_frac, T0_max, T0_max_frac, pit_min, pit_max ); - } - ELSE - { - limit_T0_voiced( 4, shr(pit_res_max,1), *T0, *T0_frac, *T0_res, T0_min, T0_min_frac, T0_max, T0_max_frac, pit_min, pit_max ); - } - *T0 = E_GAIN_closed_loop_search( exc, xn, h1, *T0_min, *T0_min_frac, *T0_max, *T0_max_frac, shr(pit_res_max,1), T0_frac, T0_res, pit_res_max, - i_subfr, pit_min, pit_min, pit_fr1b, L_SUBFR ); - - IF (i_subfr == 0) - { - Mode2_abs_pit_enc( *T0, *T0_frac, pt_indice, pit_min, pit_fr1b, pit_min, pit_res_max ); - } - ELSE - { - Mode2_delta_pit_enc( *T0, *T0_frac, shr(pit_res_max,1), *T0_min, *T0_min_frac, pt_indice ); - } - } - - BASOP_SATURATE_ERROR_OFF; - - return; -} - -static void limit_T0_voiced2( - Word16 res, - const Word16 *T_op, - Word16 *T0_min, - Word16 *T0_min_frac, - Word16 *T0_max, - Word16 *T0_max_frac, - Word16 pit_min, - Word16 pit_max, - Word16 i_subfr -) -{ - Word16 t, temp1, temp2, res2; - - assert(res > 1 && res<=6); - - res2 = res; - move16(); - if(sub(res,6) == 0) - { - res2 =shr(res2,1); - } - - /* Lower-bound */ - IF (i_subfr == 0) - { - temp1 = sub(i_mult2(T_op[0],res),32); - } - ELSE - { - temp1 = sub(i_mult2(T_op[1],res),32); - } - - IF (sub(T_op[0],T_op[1])<0) - { - t = sub(i_mult2(T_op[0],res),16); - } - ELSE - { - t = sub(i_mult2(T_op[1],res),16); - } - - if (sub(temp1,t)<0) - { - temp1 = t; - } - - temp2 = mult(temp1,inv_T0_res[res2]); - if(sub(res,6) == 0) - { - temp2 = shr(temp2,1); - } - - *T0_min = temp2; - move16(); - - *T0_min_frac = sub(temp1,i_mult2(temp2,res)); - move16(); - - IF ( sub(*T0_min,pit_min) < 0) - { - *T0_min = pit_min; - move16(); - *T0_min_frac = 0; - move16(); - } - - /* Higher-bound */ - temp1 = add(i_mult2(*T0_min,res),add(*T0_min_frac,63)); - - IF (T_op[0]0) - { - temp1 = t; - move16(); - } - - temp2 = mult(temp1,inv_T0_res[res]); - - *T0_max = temp2; - move16(); - - *T0_max_frac = sub(temp1, i_mult2(temp2,res)); - - IF ( sub(*T0_max,pit_max) > 0) - { - *T0_max = pit_max; - *T0_max_frac = sub(res,1); - - temp1 = add(sub(i_mult2(*T0_max,res),64),res); - - temp2 = mult(temp1,inv_T0_res[res2]); - if(sub(res,6) == 0) - { - temp2 = shr(temp2,1); - } - - *T0_min = temp2; - move16(); - - *T0_min_frac = sub(temp1,i_mult2(temp2,res)); - move16(); - } - -} - -/*-------------------------------------------------------------------* - * abs_pit_enc: - * - * Encode pitch lag absolutely - *-------------------------------------------------------------------*/ - -void Mode2_abs_pit_enc( - Word16 T0, /* i : integer pitch lag */ - Word16 T0_frac, /* i : pitch fraction */ - Word16 **pt_indice, /* i/o: pointer to Vector of Q indexes */ - Word16 pit_min, - Word16 pit_fr1, - Word16 pit_fr2, - Word16 pit_res_max -) -{ - Word16 pit_res_max_half; - - - pit_res_max_half = shr(pit_res_max,1); - - IF (sub(T0, pit_fr2) < 0) - { - **pt_indice = add( i_mult2(T0, pit_res_max), sub( T0_frac, i_mult2(pit_min, pit_res_max) ) ); - } - ELSE IF (sub(T0, pit_fr1) < 0) - { - **pt_indice = add( sub( add(i_mult2(T0,pit_res_max_half), T0_frac), i_mult2(pit_fr2,pit_res_max_half) ), i_mult2(sub(pit_fr2, pit_min), pit_res_max) ); - } - ELSE - { - **pt_indice = add( add( sub(T0, pit_fr1), i_mult2( sub(pit_fr2, pit_min), pit_res_max) ), i_mult2( sub(pit_fr1, pit_fr2), pit_res_max_half) ); - } - - (*pt_indice)++; - -} - - -/*-------------------------------------------------------------------* - * delta_pit_enc: - * - * Encode pitch lag differentially - *-------------------------------------------------------------------*/ - -void Mode2_delta_pit_enc( - Word16 T0, /* i : integer pitch lag */ - Word16 T0_frac, /* i : pitch fraction */ - Word16 T0_res, /* i : pitch resolution */ - Word16 T0_min, /* i/o: delta search min */ - Word16 T0_min_frac, /* i/o: delta search min */ - Word16 **pt_indice /* i/o: pointer to Vector of Q indexes */ -) -{ - /***pt_indice = (T0 - T0_min) * T0_res + T0_frac - T0_min_frac;*/ - - **pt_indice = add(i_mult2(sub(T0, T0_min), T0_res), sub(T0_frac, T0_min_frac)); - move16(); - (*pt_indice)++; - -} - diff --git a/src/libs/libevs/lib_enc/pitch_ol.cpp b/src/libs/libevs/lib_enc/pitch_ol.cpp old mode 100755 new mode 100644 index be27796d..fc446b65 --- a/src/libs/libevs/lib_enc/pitch_ol.cpp +++ b/src/libs/libevs/lib_enc/pitch_ol.cpp @@ -1,285 +1,164 @@ /*==================================================================================== - EVS Codec 3GPP TS26.442 Apr 03, 2018. Version 12.11.0 / 13.6.0 / 14.2.0 + EVS Codec 3GPP TS26.443 Nov 13, 2018. Version 12.11.0 / 13.7.0 / 14.3.0 / 15.1.0 ====================================================================================*/ - #include -#include -#include "prot_fx.h" -#include "cnst_fx.h" -#include "basop_util.h" -#include "stl.h" -#include "rom_com_fx.h" -#include "rom_enc_fx.h" +#include "prot.h" +#include "cnst.h" +#include "rom_com.h" +#include "rom_enc.h" + +/*---------------------------------------------------------------------* + * Local constants + *---------------------------------------------------------------------*/ -/*-----------------------------------------------------------------* - * Local Constants - *-----------------------------------------------------------------*/ #define PIT_MIN2 20 /* pit_min for pitch tracking */ -#define PIT_MIN_1 44 /* for second pitch track */ +#define PIT_MIN_1 44 /* pitch tracking */ #define PIT_MIN2_1 24 - -#define THR_relE -2816 /* -11 (Q8) */ - -#define THRES0 4792 /* Threshold to favor smaller pitch lags; 1.17 (Q12) */ -#define DELTA0 2 /* multiples' search range initial */ -#define STEP 1 /* multiples' search range increment */ - -#define THRES1 13107 /* Threshold to favor pitch lags coherence for neighbours; 0.4 (Q15) */ -#define DELTA_COH 14 /* Maximum pitch lags difference for neighbours to be considered as coherent */ -#define THRES3 22938 /* Threshold to favor pitch lags coherence with previous frames; 0.7 (Q15) */ - -#define CORR_TH0 13107 /* Noise threshold for past frame correlations; 0.4 (Q15) */ -#define CORR_TH1 16384 /* Noise threshold for past frame correlations; 0.5 (Q15) */ - -#define LEN_X ((PIT_MAX/OPL_DECIM)-(PIT_MIN2/OPL_DECIM)+1) /* Correlation buffer length */ -#define COH_FAC 5734 /* Factor for measuring the pitch coherence; 1.4 (Q12) */ - -#define NSUBSECT 7 +#define THR_relE -11.0f +#define THRES0 1.17f /* Threshold to favor smaller pitch lags */ +#define DELTA0 2.0f /* initial range of multiples search */ +#define STEP 1.0f /* increment in range of multiples search */ +#define THRES1 0.4f /* Threshold to favor pitch lags coherence for neighbours */ +#define DELTA_COH 14 /* Maximum pitch lags difference for neighbours to be considered as coherent */ +#define THRES3 0.7f /* Threshold to favor pitch lags coherence with previous frames */ +#define CORR_TH0 0.4f /* Noise threshold for reinforcement with past frame pitch */ +#define CORR_TH1 0.5f /* Noise threshold for reinforcement with neighbourhood pitch correlations */ +#define LEN_X ((PIT_MAX/OPL_DECIM)-(PIT_MIN2/OPL_DECIM)+1) /* Correlation buffer length */ +#define COH_FAC 1.4f /* Factor for measuring the pitch coherence */ #define NSECT 4 #define NHFR 3 #define L_FIR_PO 5 #define L_MEM (L_FIR_PO-2) - /*-----------------------------------------------------------------* * Local function prototypes *-----------------------------------------------------------------*/ -static void LP_Decim2_Copy( - const Word16 x[], - Word16 y[], - Word16 l, - Word16 mem[] -); -static void pitch_neighbour_fx( - Word16 sect0, - Word16 pitch_tmp[], - Word16 pitch[3][2*NSECT], - Word16 corr_tmp[], - Word16 corr[3][2*NSECT], - Word16 thres1[2*NHFR], - Word16 ind_tmp[2*NHFR] -); +static void pitch_neighbour( const short sect0, const short pitch_tmp[], short pitch[NHFR][2*NSECT], + const float corr_tmp[], float corr[3][2*NSECT], const float thres1[2*NHFR], const short ind_tmp[2*NHFR] ); -static void find_mult_fx( - Word16 *fac, - Word16 pitch0, - Word16 pitch1, - Word16 pit_max0, - Word16 *corr, - Word16 *old_pitch, - Word16 *old_corr, - Word16 delta, - Word16 step -); +static void find_mult( float *fac, const short pitch0, const short pitch1, const short pit_max0, + float *corr, short *old_pitch, float *old_corr, float delta, const float step); -static Word16 pitch_coherence_fx( - Word16 pitch0, - Word16 pitch1, - Word16 fac_max, - Word16 diff_max -); +static short pitch_coherence( const short pitch0, const short pitch1, const float fac_max, const short diff_max ); -static Word32 Dot_product12_OL( - Word16 *sum1, - const Word16 x[], - const Word16 y[], - const Word16 lg, - const Word16 lg2, - Word16 *exp, - Word16 *exp2 -); - -static Word32 Dot_product12_OL_back( - Word16 *sum1, - const Word16 x[], - const Word16 y[], - const Word16 lg, - const Word16 lg2, - Word16 *exp, - Word16 *exp2 -); +static void lp_decim2( const float x[], float y[], const short l, float *mem ); /*-----------------------------------------------------------------* - * pitch_ol_init() + * pitch_ol_init * * Open loop pitch variable initialization *-----------------------------------------------------------------*/ -void pitch_ol_init_fx( - Word16 *old_thres, /* o : threshold for reinforcement of past pitch influence */ - Word16 *old_pitch, /* o : pitch of the 2nd half-frame of previous frame */ - Word16 *delta_pit, /* o : pitch evolution extrapolation */ - Word16 *old_corr /* o : correlation */ + +void pitch_ol_init( + float *old_thres, /* o : threshold for reinforcement of past pitch influence */ + short *old_pitch, /* o : pitch of the 1st half-frame of previous frame */ + short *delta_pit, /* o : pitch evolution extrapolation */ + float *old_corr /* o : correlation */ ) { - *old_thres = 0; - move16(); + *old_thres = 0.0f; *old_pitch = 0; - move16(); *delta_pit = 0; - move16(); - *old_corr = 0; - move16(); + *old_corr = 0.0f; + + return; } - -/*==================================================================================*/ -/* FUNCTION : pitch_ol_fx() */ -/*----------------------------------------------------------------------------------*/ -/* PURPOSE : +/*-----------------------------------------------------------------* + * pitch_ol() + * * Compute the open loop pitch lag. * - * The pitch lag search is divided into two sets. - * Each set is divided into three sections. + * The pitch lag search is divided in three sections of two sets. * Each section cannot have a pitch multiple. * We find a maximum for each section. * We compare the maxima of each section. * - * 1st set 2nd set - * 1st section: lag delay = 115 down to 62 and 115 down to 78 - * 2nd section: lag delay = 61 down to 32 and 77 down to 41 - * 3rd section: lag delay = 31 down to 17 and 40 down to 22 - * 4th section: lag delay = 16 down to 10 and 21 down to 12 - * * As there is a margin between section overlaps, especially for * longer delays, this section selection is more robust for not - * to find multiples in the same section when pitch evolves rapidly. + * to find multiples in the same section when pitch evolves rapidly * * For each section, the length of the vectors to correlate is - * greater/equal to the longest pitch delay. */ -/*----------------------------------------------------------------------------------*/ -/* INPUT ARGUMENTS : */ -/* _ (Word16[]) old_pitch : OL pitch of the 2nd half-frame of the last frame Q0 */ -/* _ (Word16[]) old_corr_fx : correlation Q15 */ -/* _ (Word16[]) corr_shift_fx : normalized correlation correction Q15 */ -/* _ (Word16[]) old_thres_fx : maximum correlation weighting with respect */ -/* to past frame pitch Q15 */ -/* _ (Word16[]) delta_pit : old pitch extrapolation correction Q0 */ -/* _ (Word16[]) st_old_wsp2_fx: weighted speech memory qwsp */ -/* _ (Word16[]) wsp_fx : weighted speech for current frame & look-ahead qwsp */ -/* _ (Word16[]) mem_decim2_fx : wsp decimation filter memory qwsp */ -/* _ (Word16[]) relE_fx : relative frame energy Q8 */ -/* _ (Word16[]) L_look : look-ahead Q0 */ -/* _ (Word16[]) Opt_SC_VBR : SC-VBR flag Q0 */ -/* _ (Word16*) qwsp : wsp & filter memory Qformat */ -/*----------------------------------------------------------------------------------*/ -/* OUTPUT ARGUMENTS : */ -/* _ (Word16[]) pitch : open loop pitch lag for each half-frame Q0 */ -/* _ (Word16[]) T_op : open loop pitch lag for each half-frm for quant Q0 */ -/* _ (Word16[]) voicing_fx : max normalized correlation for each half-frame QIn */ -/* _ (Word16[]) old_pitch : OL pitch of the 2nd half-frame of the last frame Q0 */ -/* _ (Word16[]) old_corr_fx : correlation Q15 */ -/* _ (Word16[]) old_thres_fx : maximum correlation weighting with respect */ -/* to past frame pitch Q15 */ -/* _ (Word16[]) delta_pit : old pitch extrapolation correction Q0 */ -/* _ (Word16[]) st_old_wsp2_fx: weighted speech memory qwsp */ -/* _ (Word16[]) mem_decim2_fx : wsp decimation filter memory qwsp */ -/*----------------------------------------------------------------------------------*/ + * greater than or equal to the longest pitch delay + *------------------------------------------------------------------*/ -/*----------------------------------------------------------------------------------*/ -/* RETURN ARGUMENTS : */ -/* _ None */ -/*==================================================================================*/ - -void pitch_ol_fx( - Word16 pitch[3], /* o : open loop pitch lag for each half-frame in range [29,231] Q0 */ - Word16 voicing[3], /* o : maximum normalized correlation for each half-frame in [0,1.0[ Q15 */ - Word16 *old_pitch, /* i/o: pitch of the 2nd half-frame of previous frame (i.e. pitch[1]) Q0 */ - Word16 *old_corr, /* i/o: correlation of old_pitch (i.e. voicing[1] or corr_mean) Q15 */ - Word16 corr_shift, /* i : normalized correlation correction Q15 */ - Word16 *old_thres, /* i/o: maximum correlation weighting with respect to past frame pitch Q15 */ - Word16 *delta_pit, /* i/o: old pitch extrapolation correction in range [-14,+14] Q0 */ - Word16 *st_old_wsp2, /* i/o: weighted speech memory qwsp */ - const Word16 *wsp, /* i : weighted speech for current frame and look-ahead qwsp */ - Word16 mem_decim2[3], /* i/o: wsp decimation filter memory qwsp */ - const Word16 relE, /* i : relative frame energy Q8 */ - const Word16 last_class, /* i : frame classification of last frame */ - const Word16 bwidth, /* i : bandwidth */ - const Word16 Opt_SC_VBR /* i : SC-VBR flag */ +void pitch_ol( + short pitch[3], /* o : open loop pitch lag for each half-frame */ + float voicing[3], /* o : maximum normalized correlation for each half-frame */ + short *old_pitch, /* i/o: OL pitch of the 2nd half-frame of the last frame */ + float *old_corr, /* i/o: correlation */ + float corr_shift, /* i : normalized correlation correction */ + float *old_thres, /* i/o: maximum correlation weighting with respect to past frame pitch */ + short *delta_pit, /* i/o: old pitch extrapolation correction (added to old pitch) */ + float *st_old_wsp2, /* i/o: weighted speech memory */ + const float *wsp, /* i : weighted speech for current frame and look-ahead */ + float mem_decim2[3], /* i/o: wsp decimation filter memory */ + const float relE, /* i : relative frame energy */ + const short L_look, /* i : look-ahead */ + const short last_class, /* i : frame classification of last frame */ + const short bwidth, /* i : bandwidth */ + const short Opt_SC_VBR /* i : SC-VBR flag */ ) { - Word16 ftmp, old_wsp2[(L_WSP-L_INTERPOL)/OPL_DECIM], *wsp2; - Word16 tmp_mem[3]; + float old_wsp2[(L_WSP-L_INTERPOL)/OPL_DECIM], *wsp2; + float tmp_mem[3], scale1[2*DELTA_COH-1]; + float scaled_buf[2*LEN_X + 3*(DELTA_COH-1)]; + float cor_temp, cor_buf[2*LEN_X], *pt1, *pt2, *pt3, *pt4, *pt5 = 0, *pt6 = 0, *pt_cor0, *pt_cor1, *pt_cor2, *pt_cor3, *pt_cor4; + float thres1[2*NHFR]; + short diff, cnt, ind, ind1, offset, offset1, offset_la = 0, offset_la1 = 0, coh_flag, coh_flag1; - Word16 scale1[2*DELTA_COH-1]; - Word16 scaled_buf[2*LEN_X + 3*(DELTA_COH-1)]; - Word16 scaled_buf_exp[2*LEN_X + 3*(DELTA_COH-1)], exp_sect[8], exp_sect1[8], exp_sect0; - Word16 cor_buf[2*LEN_X]; - Word16 *pt_exp1, *pt_exp2, *pt_exp3, *pt_exp4; - Word16 *pt1, *pt2, *pt3, *pt4, *pt5, *pt6; - Word16 *pt_cor0, *pt_cor1, *pt_cor2, *pt_cor3, *pt_cor4, *pt_cor5, *pt_cor6; - Word16 thres1[6]; - Word16 diff, cnt, ind, ind1, offset, offset1, offset_la, offset_la1, coh_flag, coh_flag1; - Word16 ind_corX, ind1_corX; + short i, j, k, m, pit_min, pit_min1, sect0, subsect0, old_tmp, old_tmp1, len_x, len_x1, len_temp, len_temp1; + short pitchX[NHFR][2*NSECT], pitch_tmp[2*NHFR], ind_tmp[2*NHFR], tmp_buf[NHFR+1]; + float enr, enr1 = 0.0f, enr_norm[NSECT], enr_norm1[NSECT], fac; + float scaledX[NHFR][2*NSECT], corX[NHFR][2*NSECT], cor_tmp[2*NHFR], cor_mean; - Word16 i, j, k, m, pit_min, pit_min1, sect0, subsect0, add_sect0, sub_sect0, old_tmp, old_tmp1, len_x, len_x1; - Word16 len_temp; - Word16 pitchX[NHFR][2*NSECT], pitch_tmp[2*NHFR], ind_tmp[2*NHFR], tmp_buf[NHFR+1]; - - Word16 enr0[NSECT], enr0_exp[NSECT], enr0_1[NSECT], enr0_1_exp[NSECT], enr1, enr1_exp, enr2_exp; - Word32 enr, enr2, Ltmp; - Word16 fac, tmp16, tmp16_2; - Word16 qCorX, qScaledX; - Word16 scaledX[NHFR][2*NSECT], corX[NHFR][2*NSECT], cor_tmp[2*NHFR], cor_mean; - const Word16 *len, *len1, *sublen, *sublen1, *pit_max, *sec_length, *sec_length1; - - Word16 pit_min_coding; + const short *nb_sect, *nb_subsect, *len, *len1, *sublen, *sublen1, *pit_max, *sec_length, *sec_length1; + short ind_corX, ind1_corX; + float pit_min_coding; /*--------------------------------------------------------------* * Initialization *--------------------------------------------------------------*/ - len = len_12k8_fx; - len1 = len1_12k8_fx; - sublen = sublen_12k8_fx; - sublen1 = sublen1_12k8_fx; - pit_max = pit_max_12k8_fx; - sec_length = sec_length_12k8_fx; - sec_length1 = sec_length1_12k8_fx; - test(); - if ((sub(last_class,VOICED_TRANSITION) < 0) && (sub(bwidth,NB) != 0)) + nb_sect = nb_sect_12k8; + nb_subsect = nb_subsect_12k8; + + len = len_12k8; + len1 = len1_12k8; + sublen = sublen_12k8; + sublen1 = sublen1_12k8; + pit_max = pit_max_12k8; + sec_length = sec_length_12k8; + sec_length1 = sec_length1_12k8; + + if( last_class < VOICED_TRANSITION && bwidth != NB ) { - /*reset last pitch reinforcement in case of unvoiced or transitions: it avoids some pitch doublings*/ - *old_thres = 0; - move16(); + /* reset last pitch reinforcement in case of unvoiced or transitions: it avoids some pitch doublings */ + *old_thres = 0.0f; } pit_min_coding = PIT_MIN_EXTEND; - move16(); - test(); - test(); - test(); - test(); - IF ( ( (sub(bwidth,NB) != 0) && (sub(*old_pitch,PIT_MIN) > 0 ) ) || - ( (sub(bwidth,NB) == 0) && ( (sub(*old_pitch,PIT_MIN2_1) > 0) || (sub(*old_thres,3277) < 0) ) ) ) /* 0.1 inQ15*/ + if( ( bwidth != NB && *old_pitch > PIT_MIN ) || + ( bwidth == NB && (*old_pitch > PIT_MIN2_1 || *old_thres < 0.1) ) ) { pit_min = PIT_MIN/OPL_DECIM; - move16(); pit_min1= PIT_MIN_1/OPL_DECIM; - move16(); subsect0 = 2; - move16(); sect0 = 1; - move16(); } - ELSE + else { pit_min = PIT_MIN2/OPL_DECIM; - move16(); pit_min1= PIT_MIN2_1/OPL_DECIM; - move16(); - subsect0 = 0; - move16(); + subsect0 = 0 ; sect0 = 0; - move16(); } - len_x = (PIT_MAX/OPL_DECIM - pit_min + 1); - move16(); - len_x1= (PIT_MAX/OPL_DECIM - pit_min1 + 1); - move16(); + len_x = PIT_MAX/OPL_DECIM - pit_min + 1; + len_x1= PIT_MAX/OPL_DECIM - pit_min1 + 1; /*--------------------------------------------------------------* * Find decimated weighted speech @@ -288,66 +167,64 @@ void pitch_ol_fx( * Extend the decimation of wsp to the end of the speech buffer * Update wsp memory *--------------------------------------------------------------*/ - Copy(st_old_wsp2, old_wsp2, (L_WSP_MEM-L_INTERPOL)/OPL_DECIM); + + mvr2r( st_old_wsp2, old_wsp2, (L_WSP_MEM-L_INTERPOL)/OPL_DECIM ); wsp2 = old_wsp2 + ((L_WSP_MEM-L_INTERPOL)/OPL_DECIM); + lp_decim2( wsp, wsp2, L_FRAME, mem_decim2 ); - LP_Decim2_Copy(wsp, wsp2, L_FRAME, mem_decim2); + mvr2r( mem_decim2, tmp_mem, 3 ); + lp_decim2( &wsp[L_FRAME], &wsp2[L_FRAME/OPL_DECIM], L_look, tmp_mem ); - /* Avoid uninitialized memory access */ - set16_fx(wsp2 + L_FRAME/2, 0, sizeof(old_wsp2)/sizeof(Word16)-((L_WSP_MEM-L_INTERPOL)/OPL_DECIM)-L_FRAME/2); - tmp_mem[0] = mem_decim2[0]; - move16(); - tmp_mem[1] = mem_decim2[1]; - move16(); - tmp_mem[2] = mem_decim2[2]; - move16(); - - LP_Decim2_Copy(&wsp[L_FRAME], &wsp2[shr(L_FRAME,1)], L_LOOK_12k8, tmp_mem); /* shr() used instead of division by OPL_DECIM*/ - - Copy(&old_wsp2[shr(L_FRAME,1)], st_old_wsp2, (L_WSP_MEM-L_INTERPOL)/OPL_DECIM); + mvr2r( &old_wsp2[L_FRAME/OPL_DECIM], st_old_wsp2, (L_WSP_MEM-L_INTERPOL)/OPL_DECIM ); /*-----------------------------------------------------------------* - * Attenuate the correlation correction factor due to noise. - * Reset correlation buffer outside the useful range. + * attenuate the correlation correction factor due to noise + * reset correlation buffer outside the useful range * Find the scaling functions for immediate neigbours and - * further ones. + * further ones *-----------------------------------------------------------------*/ - corr_shift = shr(corr_shift, 1); - - set16_fx( scaled_buf, 0, DELTA_COH-1 ); - set16_fx( scaled_buf + (DELTA_COH-1) + len_x, 0, DELTA_COH-1 ); - set16_fx( scaled_buf + 2*(DELTA_COH-1) + len_x + len_x1, 0, DELTA_COH-1 ); - set16_fx( scaled_buf_exp, 0, len_x + len_x1 + 3*(DELTA_COH-1)); + corr_shift *= 0.5f; + set_f( scaled_buf, 0, DELTA_COH-1 ); + set_f( scaled_buf + (DELTA_COH-1) + len_x, 0, DELTA_COH-1 ); + set_f( scaled_buf + 2*(DELTA_COH-1) + len_x + len_x1, 0, DELTA_COH-1 ); pt1 = scale1 + DELTA_COH-1; pt2 = pt1; - tmp16 = mult(negate(*old_thres), MAX_16/DELTA_COH); - k = *old_thres; - move16(); - FOR (i=0; i < DELTA_COH; i++) + for( i=0 ; i< DELTA_COH ; i++ ) { - /* - * *pt1 = ( -(*old_thres)/DELTA_COH * i + *old_thres+1.0f ); - * To keep Q15 values, the following code does not add 1 to the result. - * A scaling factor must be applied accordingly (see next use of scale1) - */ - *pt1 = k; - move16(); - k = add(k, tmp16); + *pt1 = -(*old_thres)/DELTA_COH * i + *old_thres + 1.0f; *pt2-- = *pt1++; - move16(); } - /*-----------------------------------------------------------------------------* - * Estimate the new pitch by extrapolating the old pitch value for 2 half-frames - *-----------------------------------------------------------------------------*/ - old_tmp = add(*old_pitch, *delta_pit); - old_tmp = s_min(old_tmp, PIT_MAX/OPL_DECIM); - old_tmp = s_max(old_tmp, pit_min); - old_tmp1 = add(old_tmp, *delta_pit); - old_tmp1 = s_min(old_tmp1, PIT_MAX/OPL_DECIM); - old_tmp1 = s_max(old_tmp1, pit_min); + /*-----------------------------------------------------------------* + * Estimate the new pitch by extrapolating the old pitch value + * for 2 half-frames + *-----------------------------------------------------------------*/ + + old_tmp = *old_pitch + *delta_pit; + + if( old_tmp > PIT_MAX/OPL_DECIM ) + { + old_tmp = PIT_MAX/OPL_DECIM; + } + + if( old_tmp < pit_min ) + { + old_tmp = pit_min; + } + + old_tmp1 = old_tmp + *delta_pit; + if( old_tmp1 > PIT_MAX/OPL_DECIM ) + { + old_tmp1 = PIT_MAX/OPL_DECIM; + } + + if( old_tmp1 < pit_min ) + { + old_tmp1 = pit_min; + } + /*-----------------------------------------------------------------* * Loop for all three half-frames (current frame + look-ahead) @@ -357,536 +234,344 @@ void pitch_ol_fx( pt_cor2 = pt_cor0 - pit_min + old_tmp; pt_cor4 = pt_cor0 - pit_min1 + old_tmp + (DELTA_COH-1) + len_x; - FOR( i=0; i Q12 */ - pt2 = pt1 - pit_min; /* *pt2 -> Q12 */ - pt4 = pt1 - pit_min1; /* *pt4 -> Q12 */ - - enr = L_deposit_l(1); - + pt1 = wsp2 + i*2*(L_SUBFR/OPL_DECIM); + pt2 = pt1 - pit_min; + enr = 0.01f; pt_cor1 = pt_cor0; + pt4 = pt1 - pit_min1; pt_cor3 = pt_cor0 + (DELTA_COH-1) + len_x; - pt_exp1 = scaled_buf_exp + DELTA_COH-1; - pt_exp2 = pt_exp1; - pt_exp3 = scaled_buf_exp + 2*(DELTA_COH-1) + len_x; - pt_exp4 = pt_exp3; - - IF( sub(i,NHFR-1) < 0 ) /* First two half-frames (current frame) */ + /*-----------------------------------------------------------------* + * First two half-frames (corresponding to current frame) + *-----------------------------------------------------------------*/ + if( i < NHFR-1 ) { pt3 = pt1; pt5 = pt1; - FOR( j = sect0; j < NSECT; j++ ) /* loop for each section */ + for( j = sect0; j < nb_sect[i]; j++ ) /* loop for each section */ { /*-----------------------------------------------------------------* * Find fixed vector energy *-----------------------------------------------------------------*/ /* 1st set */ - k = (Word16)(pt1 - pt3); - move16(); - - FOR (k = add(k, len[j]); k > 0; k--) + k = (short)(pt1 - pt3); + for( k = k+len[j]; k > 0; k-- ) { - enr = L_mac0(enr, *pt3, *pt3); + enr += *pt3 **pt3; pt3++; } - /* keep Q15 normalized result */ - cnt = norm_l(enr); - enr0[j] = extract_h(L_shl(enr, cnt)); - enr0_exp[j] = sub(30, cnt); - move16(); + enr_norm[j] = enr; - /* Reduce complexity (length of 'enr2' section is equal or larger than 'enr') */ + /* Reduce complexity (length of 'enr1' section is equal or larger than 'enr') */ pt5 = pt3; - enr2 = L_add(enr,0); /* sets to 'enr' in 1 clock */ + enr1 = enr; /* 2nd set */ - k = (Word16)(pt1 - pt5); - move16(); - - FOR (k = add(k, len1[j]); k > 0; k--) + k = (short)(pt1 - pt5); + for( k = k+len1[j]; k > 0; k-- ) { - enr2 = L_mac0(enr2, *pt5, *pt5); - pt5++; + enr1 += *pt5 **pt5 ; + pt5++ ; } - cnt = norm_l(enr2); - enr0_1[j] = extract_h(L_shl(enr2, cnt)); - enr0_1_exp[j] = sub(30, cnt); - move16(); + enr_norm1[j] = enr1 ; } - /*----------------------------------------------------------* + /*-----------------------------------------------------------------* * Find correlation for the non-overlapping pitch lag values - *----------------------------------------------------------*/ - exp_sect[subsect0] = 0; - move16(); - pt_cor5 = pt_cor1; - pt_cor6 = pt_cor3; - - tmp16 = exp_sect[subsect0]; - move16(); - - k = (Word16)(pt2 - pt1 + pit_max[subsect0]); - - IF (k >= 0) + *-----------------------------------------------------------------*/ + k = (short)(pt2 - pt1); + for( k = k + pit_max[subsect0]; k >= 0; k-- ) { - len_temp = sublen[0]; - move16(); + *pt_cor1++ = dotp( pt1, pt2--, sublen[0] ) ; + } - FOR (; k >= 0; k--) + /*-----------------------------------------------------------------* + * For each subsection, find the correlation + *-----------------------------------------------------------------*/ + for( j = subsect0; j < nb_subsect[i]; j++ ) + { + len_temp = sublen[j]; + len_temp1= sublen1[j]; + + k = (short)(pt2-pt1); + if (len_temp < len_temp1) { - /* Keep Q15 normalized result */ - /* shr by 1 to make room for scaling in the neighbourhood of the extrapolated pitch */ - /* Update exponent to reflect shr by 1 */ - *pt_cor1 = extract_h(L_shr(Dot_product12(pt1, pt2--, len_temp, pt_exp1), 1)); - - /* save the biggest exponent */ - tmp16 = s_max(tmp16, *pt_exp1); - - pt_cor1++; - pt_exp1++; + for ( k = k + pit_max[j+1]; k >= 0; k-- ) + { + cor_temp = pt1[0] * pt2[0]; + for ( m = 1; m < len_temp; m++ ) + { + cor_temp += pt1[m] * pt2[m]; + } + *pt_cor1++ = cor_temp; + for ( ; m < len_temp1; m++ ) + { + cor_temp += pt1[m] * pt2[m]; + } + *pt_cor3++ = cor_temp; + pt2--; + } + } + else + { + for ( k = k + pit_max[j+1]; k >= 0; k-- ) + { + cor_temp = pt1[0] * pt2[0]; + for ( m = 1; m < len_temp1; m++ ) + { + cor_temp += pt1[m] * pt2[m]; + } + *pt_cor3++ = cor_temp; + for ( ; m < len_temp; m++ ) + { + cor_temp += pt1[m] * pt2[m]; + } + *pt_cor1++ = cor_temp; + pt2--; + } } } - exp_sect[subsect0] = tmp16; - move16(); - - /*----------------------------------------------------------* - * For each subsection, find the correlation - *----------------------------------------------------------*/ - FOR (j = subsect0; j < NSUBSECT; j++) - { - len_temp = sublen[j]; - move16(); - - k = (Word16)(pt2 - pt1); - move16(); - k = add(k,pit_max[j+1]); - exp_sect[j+1] = 0; - move16(); - exp_sect1[j] = 0; - move16(); - - IF (k >= 0) - { - ind = exp_sect[j+1]; - move16(); - ind1 = exp_sect1[j]; - move16(); - - FOR (; k >= 0; k--) - { - /* Keep Q15 normalized result */ - /* shr by 1 to make room for scaling in the neighbourhood of the extrapolated pitch */ - /* Update exponent to reflect shr by 1 (done in Dot_product12_OL() for pt_cor3/pt_exp3) */ - *pt_cor1 = extract_h(L_shr(Dot_product12_OL(pt_cor3, pt1, pt2--, sublen[j], sublen1[j], pt_exp1, pt_exp3), 1)); - /* The line above replaces: - * *pt_cor1 = shr(extract_h(Dot_product12(pt1, pt2, Sublen[j], pt_exp1)),1); move16(); - * *pt_cor3 = shr(extract_h(Dot_product12(pt1, pt2--, Sublen1[j+i*7], pt_exp3)),1); move16(); - */ - - /* save the biggest exponent */ - ind = s_max(ind, *pt_exp1); - ind1 = s_max(ind1, *pt_exp3); - - pt_cor1++; - pt_exp1++; - pt_cor3++; - pt_exp3++; - } - exp_sect[j+1] = ind; - move16(); - exp_sect1[j] = ind1; - move16(); - } /* IF (k >= 0) */ - } /* FOR (j = subsect0; ... */ } - ELSE /* 3rd half-frame (look-ahead) */ - { - pt6 = pt1 + L_LOOK_12k8/OPL_DECIM - 1; - pt3 = pt6; - pt5 = pt6; + /*-----------------------------------------------------------------* + * Third half-frame (look-ahead) + *-----------------------------------------------------------------*/ + + else + { /*-----------------------------------------------------------------* * For each section in both sets, find fixed vector energy *-----------------------------------------------------------------*/ - FOR( j = sect0; j < NSECT; j++ ) /* loop for each section */ + pt6 = pt1 + L_look/OPL_DECIM - 1; + pt3 = pt6; + pt5 = pt6; + + for( j = sect0; j < nb_sect[i]; j++ ) /* loop for each section */ { /* 1st set */ - k = (Word16)(pt3 - pt6); - move16(); - - FOR (k = add(k, len[j]); k > 0; k--) + k = (short)(pt3 - pt6); + for( k = k + len[j]; k > 0; k-- ) { - enr = L_mac0(enr, *pt3, *pt3); + enr += *pt3 **pt3; pt3--; } - cnt = norm_l(enr); - enr0[j] = extract_h(L_shl(enr, cnt)); /*qwsp+cnt-16*/ - enr0_exp[j] = sub(30, cnt); - move16(); + enr_norm[j] = enr; - /* Reduce complexity (length of 'enr2' section is equal or larger than 'enr') */ pt5 = pt3; - enr2 = L_add(enr,0); + enr1 = enr; /* 2nd set */ - k = (Word16)(pt5 - pt6); - move16(); - - FOR (k = add(k, len1[j]); k > 0; k--) + k = (short)(pt5 - pt6); + for( k = k + len1[j]; k > 0; k-- ) { - enr2 = L_mac0(enr2, *pt5, *pt5); - pt5--; + enr1 += *pt5 **pt5 ; + pt5-- ; } - cnt = norm_l(enr2); - enr0_1[j] = extract_h(L_shl(enr2, cnt)); /*qwsp+cnt-16*/ - enr0_1_exp[j] = sub(30, cnt); - move16(); + enr_norm1[j] = enr1 ; } /* Set pointers */ - IF( sect0 != 0 ) - { - pt2 = pt6 - add(pit_max[1],1); - k = sub(pit_max[2],pit_max[1]); - move16(); - } - ELSE + if( sect0 == 0 ) { pt2 = pt6 - pit_min; k = 2; - move16(); + } + else + { + pt2 = pt6 - pit_max[1] - 1; + k = pit_max[2] - pit_max[1]; } /*-----------------------------------------------------------------* * Find correlation for the non-overlapping pitch lag values *-----------------------------------------------------------------*/ - exp_sect[subsect0] = 0; - move16(); - pt_cor5 = pt_cor1; - pt_cor6 = pt_cor3; - tmp16 = exp_sect[subsect0]; - move16(); - - IF (k > 0) + for( ; k > 0; k-- ) { - len_temp = sublen[0]; - move16(); - - FOR ( ; k > 0; k-- ) + *pt_cor1 = 0; + for( m=0; m 0; k-- ) + k = pit_max[j+1] - pit_max[j]; + if (len_temp < len_temp1) { - *pt_cor1 = extract_h(L_shr(Dot_product12_OL_back(pt_cor3, pt6, pt2--, sublen[j], sublen1[j], pt_exp1, pt_exp3), 1)); - - /* Save the biggest exponent */ - ind = s_max(ind, *pt_exp1); - ind1 = s_max(ind1, *pt_exp3); - - pt_cor1++; - pt_exp1++; - pt_cor3++; - pt_exp3++; + for ( ; k > 0; k-- ) + { + cor_temp = pt6[0] * pt2[0]; + for ( m = 1; m < len_temp; m++ ) + { + cor_temp += pt6[-m] * pt2[-m]; + } + *pt_cor1++ = cor_temp; + for ( ; m < len_temp1; m++ ) + { + cor_temp += pt6[-m] * pt2[-m]; + } + *pt_cor3++ = cor_temp; + pt2--; + } + } + else + { + for ( ; k > 0; k-- ) + { + cor_temp = pt6[0] * pt2[0]; + for ( m = 1; m < len_temp1; m++ ) + { + cor_temp += pt6[-m] * pt2[-m]; + } + *pt_cor3++ = cor_temp; + for ( ; m < len_temp; m++ ) + { + cor_temp += pt6[-m] * pt2[-m]; + } + *pt_cor1++ = cor_temp; + pt2--; + } } - exp_sect[j+1] = ind; - move16(); - exp_sect1[j] = ind1; - move16(); } - } /* 3rd half-frame (look-ahead) */ + } - /* Scale all values in each section to the same exponent for upcoming Find_max() */ - offset = 0; - move16(); - offset1 = 0; - move16(); - exp_sect1[7] = 0; /* padding */ move16(); - FOR (j = sect0; j < NSECT; j++) - { - exp_sect0 = s_max(exp_sect[j*2], exp_sect[j*2+1]); - - /* scaling of exp for track 1 */ - offset = add(offset, sec_length[j]); - k = (Word16)(pt_cor0 - pt_cor5); - move16(); - FOR (k = add(k, offset); k > 0; k--) - { - cnt = sub(exp_sect0, *pt_exp2); - tmp16 = s_min(15, cnt); - if (cnt > 0) - { - tmp16 = shr(*pt_cor5, tmp16); - } - if (cnt > 0) - { - *pt_cor5 = tmp16; - move16(); - } - *pt_exp2 = s_max(*pt_exp2, exp_sect0); - move16(); - pt_cor5++; - pt_exp2++; - } - - exp_sect0 = s_max(exp_sect1[j*2], exp_sect1[j*2+1]); - - /* scaling of exp for track 2 */ - offset1 = add(offset1, sec_length1[j]); - k = (Word16)(pt_cor0 - pt_cor6 + (DELTA_COH-1)); - move16(); - k = add(k, len_x); - FOR (k = add(k, offset1); k > 0; k--) - { - cnt = sub(exp_sect0, *pt_exp4); - tmp16 = s_min(15, cnt); - if (cnt > 0) - { - tmp16 = shr(*pt_cor6, tmp16); - } - if (cnt > 0) - { - *pt_cor6 = tmp16; - move16(); - } - *pt_exp4 = s_max(*pt_exp4, exp_sect0); - move16(); - pt_cor6++; - pt_exp4++; - } - } /* FOR (j = sect0; ... */ - - Copy( pt_cor0, cor_buf, len_x ); /* Save unscaled correlation vector */ - Copy( pt_cor0+(DELTA_COH-1)+len_x, cor_buf+len_x, len_x1 ) ; + /* Save unscaled correlation vector */ + mvr2r( pt_cor0, cor_buf, len_x ); + mvr2r( pt_cor0 + (DELTA_COH-1) + len_x, cor_buf + len_x, len_x1 ); /*-----------------------------------------------------------------* - * Scale correlation function in the neighbourhood of + * scale correlation function in the neighbourhood of * the extrapolated pitch *-----------------------------------------------------------------*/ pt_cor1 = pt_cor2 - (DELTA_COH-1); - pt_cor3 = pt_cor4 - (DELTA_COH-1); + pt_cor3 = pt_cor4 - (DELTA_COH-1) ; pt2 = scale1; - FOR( k=0 ; k < 2*DELTA_COH-1 ; k++ ) + for( k=0 ; k < 2*DELTA_COH-1 ; k++ ) { - /* all Q15 here */ - *pt_cor1 = add(*pt_cor1, mult(*pt_cor1, *pt2)); - move16(); - *pt_cor3 = add(*pt_cor3, mult(*pt_cor3, *pt2++)); - move16(); - - pt_cor1++; - pt_cor3++; + *pt_cor1++ *= (*pt2); + *pt_cor3++ *= (*pt2++); } - /* Update for next half-frame & look-ahead */ + /* update for next half-frame */ pt_cor2 = pt_cor0 - pit_min + old_tmp1; pt_cor4 = pt_cor0 - pit_min1 + old_tmp1 + (DELTA_COH-1) + len_x; - /*-----------------------------------------------------------------* * For each section, find maximum correlation and compute * normalized correlation *-----------------------------------------------------------------*/ pt_cor1 = pt_cor0; - pt_exp1 = scaled_buf_exp + DELTA_COH-1; offset = 0; - move16(); pt_cor3 = pt_cor0 + (DELTA_COH-1) + len_x; - pt_exp3 = scaled_buf_exp + 2*(DELTA_COH-1) + len_x; offset1 = 0; - move16(); - - FOR( j=sect0; j < NSECT; j++ ) /* loop for each section */ + for( j=sect0; j < nb_sect[i] ; j++ ) /* loop for each section */ { /* 1st set */ - offset_la = 0; - move16(); - if( sub(i,2)==0 ) + if( i==2 ) { - offset_la = sub(L_LOOK_12k8/OPL_DECIM,len[j]); + offset_la = L_look/OPL_DECIM - 1 - (len[j]-1); + } + else + { + offset_la = 0; } /* 2nd set */ - offset_la1 = 0; - move16(); - if( sub(i,2)==0 ) + if( i==2 ) { - offset_la1 = sub(L_LOOK_12k8/OPL_DECIM,len1[j]); + offset_la1 = L_look/OPL_DECIM - 1 - (len1[j]-1); + } + else + { + offset_la1 = 0; } /* 1st set of candidates */ - ind = add(maximum_fx( pt_cor1, sec_length[j], &ftmp ), offset); - pitchX[i][j] = add(ind, pit_min); - move16(); - pt2 = pt1 - pitchX[i][j] +/*-*/ offset_la; /* selected moving vector */ - - enr1_exp = 0; - move16(); - enr1 = add(extract_h(dotp_fx( pt2, pt2, len[j], &enr1_exp)), 1); - - enr2 = L_mult(enr0[j], enr1); - enr2_exp = norm_l(enr2); - enr2 = L_shl(enr2, enr2_exp); - enr2_exp = sub(31,add(sub(28,add(enr0_exp[j],enr1_exp)),add(enr2_exp,1))); - - enr2 = Isqrt_lc(enr2, &enr2_exp); /* 1/sqrt(energy) */ /*31-enr2_exp*/ - enr1_exp = norm_l(enr2); - enr1 = extract_h(L_shl(enr2, enr1_exp)); /*31-enr2_exp+enr1_exp-16*/ - enr1_exp = sub(enr2_exp, enr1_exp); /*15-enr1_exp*/ - - Ltmp = L_mult0(cor_buf[ind], enr1); - qCorX = add(sub(15,enr1_exp), sub(14,pt_exp1[ind])); - corX[i][j] = extract_h(L_shr(Ltmp, sub(qCorX,31))); - qCorX = 31; - move16(); - - Ltmp = L_mult0(pt_cor0[ind], enr1); - qScaledX = add(sub(15,enr1_exp),sub(14,pt_exp1[ind])); - scaledX[i][j] = round_fx(L_shl(Ltmp, sub(16+12,qScaledX))); - qScaledX =12; - move16(); + ind = maximum( pt_cor1, sec_length[j], 0 ) + offset; + pitchX[i][j] = ind + pit_min; + pt2 = pt1 - pitchX[i][j] + offset_la; /* selected moving vector */ + enr1 = dotp( pt2, pt2, len[j] ) + 0.01f; + enr1 = inv_sqrt( enr_norm[j] * enr1 ); /* 1/sqrt(energy) */ + corX[i][j] = cor_buf[ind] * enr1; /* find best normalized correlation per section */ + scaledX[i][j] = pt_cor0[ind] * enr1; /* find best scaled normalized correlation per section */ pt_cor1 += sec_length[j]; - move16(); - offset = add(offset,sec_length[j]); + offset = offset + sec_length[j]; /* 2nd set of candidates */ - ind1 = add(maximum_fx( pt_cor3, sec_length1[j], &ftmp ), offset1); - pitchX[i][j+NSECT] = add(ind1, pit_min1); - move16(); - pt4 = pt1 - pitchX[i][j+NSECT] +/*-*/ offset_la1; - move16(); /* selected moving vector */ - enr1_exp = 0; - move16(); - enr1 = add(extract_h(dotp_fx( pt4, pt4, len1[j], &enr1_exp)), 1); - - enr2 = L_mult(enr0_1[j], enr1); - enr2_exp = norm_l(enr2); - enr2 = L_shl(enr2, enr2_exp); - - enr2_exp = sub(31,add(sub(28,add(enr0_1_exp[j],enr1_exp)),add(enr2_exp,1))); - enr2 = Isqrt_lc(enr2, &enr2_exp); /* 1/sqrt(energy) */ /*31-enr2_exp*/ - enr1_exp = norm_l(enr2); - enr1 = extract_h(L_shl(enr2, enr1_exp)); /*31-enr2_exp+enr1_exp-16*/ - enr1_exp = sub(enr2_exp, enr1_exp); /*15-enr1_exp*/ - - Ltmp = L_mult0(cor_buf[ind1+len_x], enr1); - - qCorX = add(sub(15,enr1_exp),sub(14,pt_exp3[ind1])); - corX[i][j+NSECT] = extract_h(L_shr(Ltmp, qCorX-31)); - qCorX = 31; - move16(); - - Ltmp = L_mult0(pt_cor0[ind1+(DELTA_COH-1)+len_x], enr1); - qScaledX = add(sub(15,enr1_exp),sub(14,pt_exp3[ind1])); - scaledX[i][j+NSECT] = round_fx(L_shl(Ltmp, sub(16+12,qScaledX))); - /*scaledX[i][j+NSECT] = saturate(L_shr(Ltmp, qScaledX-12));*/ - qScaledX =12; - move16(); + ind1 = maximum( pt_cor3, sec_length1[j], 0 ) + offset1; + pitchX[i][j+NSECT] = ind1 + pit_min1; + pt4 = pt1 - pitchX[i][j+NSECT] + offset_la1; /* selected moving vector */ + enr1 = dotp( pt4, pt4, len1[j] ) + 0.01f; + enr1 = inv_sqrt( enr_norm1[j] * enr1 ); /* 1/sqrt(energy) */ + corX[i][j+NSECT] = cor_buf[ind1+len_x] * enr1; /* find best normalized correlation per section */ + scaledX[i][j+NSECT] = pt_cor0[ind1+(DELTA_COH-1)+len_x] * enr1; /* find best scaled normalized correlation per section */ pt_cor3 += sec_length1[j]; - move16(); - offset1 = add(offset1, sec_length1[j]); - - } /* FOR j < NSECT */ - } /* FOR i < NHFR */ - + offset1 = offset1 + sec_length1[j]; + } + } /*-----------------------------------------------------------------* * Favor a smaller delay if it happens that it has its multiple * in the longer-delay sections (harmonics check) *-----------------------------------------------------------------*/ - FOR( i=0; i < 2; i++ ) /* loop for the 2 half-frames */ + for( i=0; i<2; i++ ) /* loop for the 2 half-frames */ { fac = THRES0; - move16(); - find_mult_fx(&fac, pitchX[i][2], pitchX[i][3], pit_max[7], &scaledX[i][2], old_pitch, old_corr, DELTA0, STEP); /* Multiples in 3rd section */ - find_mult_fx(&fac, pitchX[i][1], pitchX[i][2], pit_max[5], &scaledX[i][1], old_pitch, old_corr, DELTA0, STEP); /* Multiples in 2nd section */ - test(); - IF((sect0==0) && sub(shl(pitchX[i][0],1),pit_min_coding)>=0) + find_mult( &fac, pitchX[i][2], pitchX[i][3], pit_max[7], &scaledX[i][2], old_pitch, old_corr, DELTA0, STEP ); /* Multiples in longest-delay section */ + find_mult( &fac, pitchX[i][1], pitchX[i][2], pit_max[5], &scaledX[i][1], old_pitch, old_corr, DELTA0, STEP ); /* Multiples in 3rd section */ + + if((sect0==0) && ((pitchX[i][0]*2) >= pit_min_coding)) { - find_mult_fx( &fac, pitchX[i][0], pitchX[i][1], pit_max[3], &scaledX[i][0], old_pitch, old_corr, DELTA0, STEP ); /* Multiples in 2nd section */ + find_mult( &fac, pitchX[i][0], pitchX[i][1], pit_max[3], &scaledX[i][0], + old_pitch, old_corr, DELTA0, STEP ); /* Multiples in 2nd section */ } fac = THRES0; - move16(); - find_mult_fx(&fac, pitchX[i][NSECT+2], pitchX[i][NSECT+3], pit_max[7], &scaledX[i][NSECT+2], old_pitch, old_corr, DELTA0, STEP); /* Multiples in 3rd section */ - find_mult_fx(&fac, pitchX[i][NSECT+1], pitchX[i][NSECT+2], pit_max[6], &scaledX[i][NSECT+1], old_pitch, old_corr, DELTA0, STEP); /* Multiples in 2nd section */ - test(); - IF((sect0==0) && sub(shl(pitchX[i][NSECT+0],1),pit_min_coding)>=0) + find_mult( &fac, pitchX[i][NSECT+2], pitchX[i][NSECT+3], pit_max[7], &scaledX[i][NSECT+2], old_pitch, old_corr, DELTA0, STEP ) ; /* Multiples in longest-delay section */ + find_mult( &fac, pitchX[i][NSECT+1], pitchX[i][NSECT+2], pit_max[6], &scaledX[i][NSECT+1], old_pitch, old_corr, DELTA0, STEP ) ; /* Multiples in 3rd section */ + + if( (sect0 == 0) && (pitchX[i][NSECT+0]*2 >= pit_min_coding) ) { - find_mult_fx( &fac, pitchX[i][NSECT+0], pitchX[i][NSECT+1], pit_max[4], &scaledX[i][NSECT+0], old_pitch, old_corr, DELTA0, STEP ); /* Multiples in 2nd section */ + find_mult( &fac, pitchX[i][NSECT+0], pitchX[i][NSECT+1], pit_max[4], &scaledX[i][NSECT+0], old_pitch, old_corr, DELTA0, STEP ); /* Multiples in 2nd section */ } } - fac = THRES0; - move16(); /* the look-ahead */ - find_mult_fx(&fac, pitchX[i][2], pitchX[i][3], pit_max[7], &scaledX[i][2], old_pitch, old_corr, 2, 2); /* Multiples in 3rd section */ - find_mult_fx(&fac, pitchX[i][1], pitchX[i][2], pit_max[5], &scaledX[i][1], old_pitch, old_corr, DELTA0, STEP); /* Multiples in 2nd section */ - test(); - IF((sect0==0) && sub(shl(pitchX[i][0],1),pit_min_coding)>=0) + fac = THRES0; /* the look-ahead */ + find_mult( &fac, pitchX[i][2], pitchX[i][3], pit_max[7], &scaledX[i][2], old_pitch, old_corr, 2.0f, 2.0f ); /* Multiples in longest-delay section */ + find_mult( &fac, pitchX[i][1], pitchX[i][2], pit_max[5], &scaledX[i][1], old_pitch, old_corr, DELTA0, STEP ); /* Multiples in 3rd section */ + + if( (sect0 == 0) && (pitchX[i][0]*2 >= pit_min_coding) ) { - find_mult_fx( &fac, pitchX[i][0], pitchX[i][1], pit_max[3], &scaledX[i][0], old_pitch, old_corr, DELTA0, STEP ); /* Multiples in 2nd section */ + find_mult( &fac, pitchX[i][0], pitchX[i][1], pit_max[3], &scaledX[i][0], old_pitch, old_corr, DELTA0, STEP ); /* Multiples in 2nd section */ } - fac = THRES0; - move16(); - find_mult_fx(&fac, pitchX[i][NSECT+2], pitchX[i][NSECT+3], pit_max[7], &scaledX[i][NSECT+2], old_pitch, old_corr, 2, 2); /* Multiples in 3rd section */ - find_mult_fx(&fac, pitchX[i][NSECT+1], pitchX[i][NSECT+2], pit_max[6], &scaledX[i][NSECT+1], old_pitch, old_corr, DELTA0, STEP); /* Multiples in 2nd section */ - test(); - IF((sect0==0) && sub(shl(pitchX[i][NSECT+0],1),pit_min_coding)>=0) + + fac = THRES0; /* the look-ahead */ + find_mult( &fac, pitchX[i][NSECT+2], pitchX[i][NSECT+3], pit_max[7], &scaledX[i][NSECT+2], old_pitch, old_corr, 2.0f, 2.0f ) ; /* Multiples in longest-delay section */ + find_mult( &fac, pitchX[i][NSECT+1], pitchX[i][NSECT+2], pit_max[6], &scaledX[i][NSECT+1], old_pitch, old_corr, DELTA0, STEP ) ; /* Multiples in 3rd section */ + + if( (sect0 == 0) && (pitchX[i][NSECT+0]*2 >= pit_min_coding)) { - find_mult_fx( &fac, pitchX[i][NSECT+0], pitchX[i][NSECT+1], pit_max[4], &scaledX[i][NSECT+0], old_pitch, old_corr, DELTA0, STEP ); /* Multiples in 2nd section */ /* Multiples in 2nd section */ + find_mult( &fac, pitchX[i][NSECT+0], pitchX[i][NSECT+1], pit_max[4], &scaledX[i][NSECT+0], old_pitch, old_corr, DELTA0, STEP ); /* Multiples in 2nd section */ } /*-----------------------------------------------------------------* @@ -895,37 +580,35 @@ void pitch_ol_fx( * Compute the maximum scaling for the neighbour correlation * reinforcement *-----------------------------------------------------------------*/ - add_sect0 = add(NSECT,sect0); - sub_sect0 = sub(NSECT,sect0); - FOR (i=0; i < NHFR; i++) - { - /* 1st set of pitch candidates */ - ind = add(maximum_fx(scaledX[i]+sect0, sub_sect0, &ftmp), sect0); - ind_tmp[i] = ind; - move16(); - pitch_tmp[i] = pitchX[i][ind]; - move16(); - cor_tmp[i] = add(corX[i][ind], corr_shift); - move16(); - /* Higher is the neighbour's correlation, higher is the weighting */ - /* operands are Q15, result is Q15 */ - thres1[i] = mult(THRES1, cor_tmp[i]); - move16(); + for( i=0; i 1.0f ) + { + cor_tmp[i] = 1.0f; + } + thres1[i] = THRES1 * cor_tmp[i]; /* Higher is the neighbour's correlation, higher is the weighting */ /* 2nd set of pitch candidates */ - ind1 = add(maximum_fx(scaledX[i]+add_sect0, sub_sect0, &ftmp), add_sect0); + ind1 = maximum( scaledX[i]+sect0+NSECT, (short)(NSECT-sect0), 0 ); + ind1 += (sect0 + NSECT); ind_tmp[i+NHFR] = ind1; - move16(); pitch_tmp[i+NHFR] = pitchX[i][ind1]; - move16(); - cor_tmp[i+NHFR] = add(corX[i][ind1], corr_shift); - move16(); + cor_tmp[i+NHFR] = corX[i][ind1]; + cor_tmp[i+NHFR] += corr_shift; - /* Higher is the neighbour's correlation, higher is the weighting */ - /* operands are Q15, result is Q15 */ - thres1[i+NHFR] = mult(THRES1, cor_tmp[i+NHFR]); - move16(); + if( cor_tmp[i+NHFR] > 1.0f ) + { + cor_tmp[i+NHFR] = 1.0f; + } + thres1[i+NHFR] = THRES1 * cor_tmp[i+NHFR]; /* Higher is the neighbour's correlation, higher is the weighting */ } /*-----------------------------------------------------------------* * Take into account previous and next pitch values of the present @@ -933,92 +616,76 @@ void pitch_ol_fx( * correlations for each half-frame & look-ahead *-----------------------------------------------------------------*/ - pitch_neighbour_fx(sect0, pitch_tmp, pitchX, cor_tmp, scaledX, thres1, ind_tmp); - FOR( i = 0; i < NHFR; i++ ) + pitch_neighbour( sect0, pitch_tmp, pitchX, cor_tmp, scaledX, thres1, ind_tmp ); + for( i=0; i 0 ) + if( scaledX[i][ind1] > scaledX[i][ind] ) { ind = ind1; - move16(); } - test(); - if ( Opt_SC_VBR && sub(corX[i][ind1_corX],corX[i][ind_corX]) > 0 ) + + if( Opt_SC_VBR && corX[i][ind1_corX] > corX[i][ind_corX] ) { ind_corX = ind1_corX; - move16(); } - test(); - test(); - test(); - IF (Opt_SC_VBR && (sub(mult(pitchX[i][ind], 13107 /*0.4 in Q15*/),pitchX[i][ind_corX]) < 0) && - (sub(mult(pitchX[i][ind], 19661 /*0.6 in Q15*/),pitchX[i][ind_corX]) > 0) && - (sub(corX[i][ind_corX],29491/*0.9 in Q15*/)>=0)) + + if( Opt_SC_VBR && (pitchX[i][ind]*0.4 < pitchX[i][ind_corX]) && (pitchX[i][ind]*0.6 > pitchX[i][ind_corX]) && (corX[i][ind_corX]>=0.9) ) /* && (pitchX[i][ind]>50)) */ { pitch[i] = pitchX[i][ind_corX]; - move16(); voicing[i] = corX[i][ind_corX]; - move16(); } - ELSE + else { pitch[i] = pitchX[i][ind]; - move16(); voicing[i] = corX[i][ind]; - move16(); } } /*-----------------------------------------------------------------* * Increase the threshold for correlation reinforcement with - * the past if correlation high and pitch stable + * the past if correlation is high and pitch is stable *-----------------------------------------------------------------*/ - /* all Q15 here */ - /* cor_mean = 0.5f * (voicing[0] + voicing[1]) + corr_shift; */ - Ltmp = L_mult(voicing[0], 16384); - Ltmp = L_mac(Ltmp, voicing[1], 16384); - cor_mean = round_fx(L_add(Ltmp, corr_shift)); - - /* pitch unstable in present frame or from previous frame or normalized correlation too low */ - coh_flag = pitch_coherence_fx(pitch[0], pitch[1], COH_FAC, DELTA_COH); - move16(); - coh_flag1 = pitch_coherence_fx(pitch[0], *old_pitch, COH_FAC, DELTA_COH); - move16(); - - test(); - test(); - test(); - IF ((coh_flag == 0) || (coh_flag1 == 0) || (sub(cor_mean, CORR_TH0) < 0) || (sub(relE, THR_relE) < 0)) + cor_mean = 0.5f * (voicing[0] + voicing[1]) + corr_shift; + if( cor_mean > 1.0f ) { - /* Reset the threshold */ - *old_thres = 0; - move16(); - } - ELSE - { - /* The threshold increase is directly dependent on normalized correlation */ - /* *old_thres += (0.16f * cor_mean); */ - *old_thres = round_fx(L_mac(L_deposit_h(*old_thres), 5243, cor_mean)); + cor_mean = 1.0f; } - *old_thres = s_min(*old_thres, THRES3); - move16(); + /* pitch unstable in present frame or from previous frame or normalized correlation too low */ + coh_flag = pitch_coherence( (short)pitch[0], (short)pitch[1], COH_FAC, DELTA_COH ); + coh_flag1 = pitch_coherence( (short)pitch[0], (short)*old_pitch, COH_FAC, DELTA_COH ); + if( ( coh_flag == 0 ) || ( coh_flag1 == 0 ) || ( cor_mean < CORR_TH0 ) || (relE < THR_relE) ) + { + *old_thres = 0.0f; /* Reset the threshold */ + } + else + { + *old_thres += (0.16f * cor_mean); /* The threshold increase is directly dependent on normalized correlation */ + } - IF (sub(voicing[1], voicing[0]) > 0) + if( *old_thres > THRES3 ) + { + *old_thres = THRES3; + } + + if( voicing[1] > voicing[0] ) { *old_corr = voicing[1]; - move16(); } - ELSE + else { *old_corr = cor_mean; - move16(); } /*-----------------------------------------------------------------* @@ -1027,231 +694,180 @@ void pitch_ol_fx( * in the next frame and is then used when the normalized * correlation is reinforced by the past estimate *-----------------------------------------------------------------*/ + tmp_buf[0] = *old_pitch; - move16(); - FOR( i = 0; i < NHFR; i++ ) + for( i=0; i (float)*old_pitch * 0.4f ) */ - IF (s_max(sub(19660, *old_corr), sub(pitch0, mult(*old_pitch, 13107))) > 0) + if ( *old_corr < 0.6f || (float)pitch0 > (float)*old_pitch * 0.4f ) { /* reinforce the normalized correlation */ - /* operands are Q12, result is Q12 */ - *corr = extract_h(L_tmp); + *corr *= *fac; } - /* operands are Q12, result is Q12 */ - *fac = extract_h(L_shl(L_mult(*fac, THRES0), 3)); + *fac *= THRES0; } - pit_min = add(pit_min, pitch0); /* next multiple */ - delta = add(delta, step); /* the incertitude to the allowed range */ + pit_min = pit_min + pitch0; /* next multiple */ + delta += step; /* add the incertitude to the allowed range */ } + return; } /*---------------------------------------------------------------------------* - * pitch_neighbour_fx + * pitch_neighbour * * Verifies if the maximum correlation pitch lag is coherent with neighbour * values *---------------------------------------------------------------------------*/ -static void pitch_neighbour_fx( - Word16 sect0, /* i : indicates whether section 0 (below PIT_MIN) is used */ - Word16 pitch_tmp[], /* i : estimated pitch values for each half-frame & look-ahead */ - Word16 pitch[3][2*NSECT], /* i : tested pitch values for each half-frame & look-ahead */ - Word16 corr_tmp[], /* i : raw normalized correlation (before different scalings) Q15*/ - Word16 corr[3][2*NSECT], /* i/o: normalized correlation for each half-frame & look-ahead Q12 */ - Word16 thres1[2*NHFR], /* i : maximum scaling for the immediate neighbours Q15 */ - Word16 ind_tmp[2*NHFR] /* i : best section index for each half-frame & look-ahead */ +static void pitch_neighbour( + const short sect0, /* i : indicates whether section 0 (below PIT_MIN) is used */ + const short pitch_tmp[], /* i : estimated pitch values for each half-frame & look-ahead */ + short pitch[NHFR][2*NSECT], /* i : tested pitch values for each half-frame & look-ahead */ + const float corr_tmp[], /* i : raw normalized correlation (before different scalings) */ + float corr[NHFR][2*NSECT], /* i/o: normalized correlation for each half-frame & look-ahead */ + const float thres1[2*NHFR], /* i : maximum scaling for the immediate neighbours */ + const short ind_tmp[2*NHFR] /* i : maximum section indices */ ) { - Word16 delta, i, j, k, K, coh_flag, fac; + short delta, i, j, k, K, coh_flag; - /*--------------------- - * 1st set of sections - ---------------------*/ - FOR ( k = sect0; k < NSECT; k++ ) /* loop for each section */ + for( k=sect0 ; k= 0) /* reinforcement can happen only if the correlation is high enough */ + if( corr_tmp[j] >= CORR_TH1 ) /* reinforcement can happen only if the correlation is high enough */ { - delta = abs_s(sub(pitch[i][k], pitch_tmp[j])); /* Find difference of pitch values */ - coh_flag = pitch_coherence_fx(pitch[i][k], pitch_tmp[j], COH_FAC, DELTA_COH); - - IF (coh_flag != 0) + delta = (short)abs( pitch[i][k] - pitch_tmp[j] ); /* Find difference of pitch values */ + coh_flag = pitch_coherence( (short)pitch[i][k], (short)pitch_tmp[j], COH_FAC, DELTA_COH ); + if( coh_flag != 0 ) { - /* Favour stability across sections, favour closer values */ - IF (sub(ind_tmp[j], k) == 0) + /* Favour section-wise stability */ + if ( ind_tmp[j] == k ) { - /* corr[i][k] *= ( -thres1[j]/DELTA1 * delta + thres1[j]+1 ); */ - /* operands are Q15, except corr[i][k] which is Q12 */ - fac = mult(negate(thres1[j]), MAX_16/DELTA_COH); - fac = add(i_mult2(fac, delta), thres1[j]); + corr[i][k] *= ( -thres1[j]/DELTA_COH * delta + thres1[j]+1.0f ); /* Favour closer values */ } - ELSE + else { - /* corr[i][k] *= ( -thres1[j]/DELTA1 * 0.625f * delta + 0.625f * thres1[j] +1.0f ); */ - fac = mult(negate(thres1[j]), 20479/DELTA_COH); - fac = add(i_mult2(fac,delta), mult(20479, thres1[j])); + corr[i][k] *= ( -thres1[j]/DELTA_COH * 0.625f * delta + thres1[j] * 0.625f +1.0f ) ; } - corr[i][k] = add(corr[i][k], mult(fac, corr[i][k])); - move16(); } } } } } } - - /*--------------------- + /*---------------------* * 2nd set of sections - ---------------------*/ - FOR ( k = sect0; k < NSECT; k++ ) /* loop for each section */ + *---------------------*/ + for( k=sect0 ; k= 0)/* reinforcement can happen only if the correlation is high enough */ + if( corr_tmp[j+NHFR] >= CORR_TH1 ) /* reinforcement can happen only if the correlation is high enough */ { - delta = abs_s(sub(pitch[i][NSECT+k], pitch_tmp[j+NHFR])); /* Find difference of pitch values */ - coh_flag = pitch_coherence_fx(pitch[i][NSECT+k], pitch_tmp[j+NHFR], COH_FAC, DELTA_COH); - - IF (coh_flag != 0) + delta = (short)abs( pitch[i][NSECT+k] - pitch_tmp[j+NHFR] ); /* Find difference of pitch values */ + coh_flag = pitch_coherence( (short)pitch[i][NSECT+k], (short)pitch_tmp[j+NHFR], COH_FAC, DELTA_COH ); + if( coh_flag != 0 ) { - /* Favour stability across sections, favour closer values */ - IF (sub(ind_tmp[j+NHFR], add(NSECT, k)) == 0) + /* Favour section-wise stability */ + if ( ind_tmp[j+NHFR] == (NSECT + k) ) { - /* corr[i][k] *= ( -thres1[j+NHFR]/DELTA1 * delta + thres1[j+NHFR]+1 ); */ - /* operands are Q15, except corr[i][NSECT+k] which is Q12 */ - fac = mult(negate(thres1[j+NHFR]), MAX_16/DELTA_COH); - fac = add(extract_l(L_shr(L_mult(fac, delta), 1)), thres1[j+NHFR]); - corr[i][NSECT+k] = add(corr[i][NSECT+k], mult(fac, corr[i][NSECT+k])); - move16(); + corr[i][NSECT+k] *= ( -thres1[j+NHFR]/DELTA_COH * delta + thres1[j+NHFR]+1.0f ); /* Favour closer values */ } - ELSE + else { - /* corr[i][k] *= ( -thres1[j+NHFR]/DELTA1 * 0.625f * delta + 0.625f * thres1[j+NHFR] +1.0f ); */ - fac = mult(negate(thres1[j+NHFR]), 20479/DELTA_COH); - fac = add(extract_l(L_shr(L_mult(fac,delta), 1)), mult(20479, thres1[j+NHFR])); - corr[i][NSECT+k] = add(corr[i][NSECT+k], mult(fac, corr[i][NSECT+k])); - move16(); + corr[i][NSECT+k] *= ( -thres1[j+NHFR]/DELTA_COH * 0.625f * delta + thres1[j+NHFR] * 0.625f +1.0f ) ; } } } @@ -1259,291 +875,86 @@ static void pitch_neighbour_fx( } } } + return; } /*-----------------------------------------------------------------* - * pitch_coherence_fx + * pitch_coherence * * Verify if pitch evolution is smooth *-----------------------------------------------------------------*/ -static Word16 pitch_coherence_fx( - Word16 pitch0, /* i : first pitch to compare */ - Word16 pitch1, /* i : 2nd pitch to compare */ - Word16 fac_max, /* i : max ratio of both values Q12 */ - Word16 diff_max /* i : max difference of both values */ + +static short pitch_coherence( + const short pitch0, /* i : first pitch to compare */ + const short pitch1, /* i : 2nd pitch to compare */ + const float fac_max, /* i : max ratio of both values */ + const short diff_max /* i : max difference of both values */ ) { - Word16 smaller, larger; - Word16 pc; - - smaller = s_min(pitch0, pitch1); - larger = s_max(pitch0, pitch1); - - pc = 0; - move16(); - test(); - if( (sub(larger, extract_h(L_shl(L_mult(fac_max, smaller), 3))) <= 0) && /* Changed to <= to keep BE */ - (sub(sub(larger, smaller), diff_max) < 0)) + short smaller, larger; + if( pitch1 < pitch0 ) /* Finds smaller and larger of 2 short values */ { - pc = 1; - move16(); + smaller = pitch1; + larger = pitch0; + } + else + { + smaller = pitch0; + larger = pitch1; + } + if( ((float)larger < fac_max * (float)smaller) && ( (larger-smaller) < diff_max) ) + { + return 1; + } + else + { + return 0; } - - return pc; } + /*-----------------------------------------------------------------* - * LP_Decim2_Copy: + * lp_decim2: * * Decimate a vector by 2 with 2nd order fir filter. *-----------------------------------------------------------------*/ -static void LP_Decim2_Copy( - const Word16 x[], /* i: signal to process */ - Word16 y[], /* o: signal to process */ - Word16 l, /* i : size of filtering */ - Word16 mem[] /* i/o: memory (size=3) */ +static void lp_decim2( + const float x[], /* i : signal to process */ + float y[], /* o : processed signals */ + const short l, /* i : size of filtering */ + float *mem /* i/o: memory (size=3) */ ) { - Word16 *p_x, x_buf[L_FRAME + L_MEM]; - Word16 i, j, k; - Word32 L_tmp; + const float *p_h; + float temp, *p_x, x_buf[L_FRAME_PLUS+L_MEM]; + short i, j, k; /* copy initial filter states into buffer */ p_x = x_buf; - FOR (i = 0; i < L_MEM; i++) + for (i=0; i= 0) - { - pitch_ol2_fx( PIT_MIN_SHORTER, T, &(new_op_fr[0]), &new_voicing[0], 0, wspeech, 2 ); - pitch_ol2_fx( PIT_MIN_SHORTER, T, &(new_op_fr[1]), &new_voicing[1], L_SUBFR, wspeech, 2 ); - /* IF(sub(add(new_voicing[0],new_voicing[1]),add(voicing_fr[0],voicing_fr[1]))>0 */ - IF( L_msu(L_msu(L_mac(L_mult(new_voicing[0], 8192),new_voicing[1], 8192), voicing_fr[0], 8192), voicing_fr[1], 8192) > 0 ) - { - new_Top[0]=T; - move16(); - T_op_fr[0]=new_op_fr[0]; - move16(); - T_op_fr[1]=new_op_fr[1]; - move16(); - voicing_fr[0]=new_voicing[0]; - move16(); - voicing_fr[1]=new_voicing[1]; - move16(); - } - } - - /* T= pitch_ol[1]/m; */ - T = mult(pitch_ol[1],One_div_fx[m-1]); - - IF(sub(T,PIT_MIN_12k8)>= 0) - { - pitch_ol2_fx( PIT_MIN_SHORTER, T, &(new_op_fr[0]), &new_voicing[0], 2*L_SUBFR, wspeech, 2 ); - pitch_ol2_fx( PIT_MIN_SHORTER, T, &(new_op_fr[1]), &new_voicing[1], 3*L_SUBFR, wspeech, 2 ); - /* IF(sub(add(new_voicing[0],new_voicing[1]),add(voicing_fr[2],voicing_fr[3]))>0) */ - IF( L_msu(L_msu(L_mac(L_mult(new_voicing[0], 8192),new_voicing[1], 8192), voicing_fr[2], 8192), voicing_fr[3], 8192) > 0 ) - { - new_Top[1]=T; - move16(); - T_op_fr[2]=new_op_fr[0]; - move16(); - T_op_fr[3]=new_op_fr[1]; - move16(); - voicing_fr[2]=new_voicing[0]; - move16(); - voicing_fr[3]=new_voicing[1]; - move16(); - } - } - } - - pitch_ol[0]=new_Top[0]; - move16(); - pitch_ol[1]=new_Top[1]; - move16(); - -}/*end of pitch doubling detection*/ diff --git a/src/libs/libevs/lib_enc/pitch_ol2.cpp b/src/libs/libevs/lib_enc/pitch_ol2.cpp new file mode 100644 index 00000000..98e6ca48 --- /dev/null +++ b/src/libs/libevs/lib_enc/pitch_ol2.cpp @@ -0,0 +1,302 @@ +/*==================================================================================== + EVS Codec 3GPP TS26.443 Nov 13, 2018. Version 12.11.0 / 13.7.0 / 14.3.0 / 15.1.0 + ====================================================================================*/ + +#include +#include "options.h" +#include "cnst.h" +#include "rom_enc.h" +#include "prot.h" + +/*-------------------------------------------------------------------* + * Local constants + *-------------------------------------------------------------------*/ + +#define MAX_DELTA 16 /* half-length of the delta search */ +#define COR_BUF_LEN (L_INTERPOL1*2 + MAX_DELTA*2 + 1) + +/*-------------------------------------------------------------------* + * pitch_ol2() + * + * Open-loop pitch precision improvement with 1/4 resolution + * The pitch is searched in the interval PIT_MAX ) + { + t0_max = PIT_MAX; + } + t_max = t0_max + L_INTERPOL1; + + pt_wsp = wsp + pos; + pt_cor = cor; + for ( t=t_min; t<=t_max; t++ ) + { + *pt_cor++ = dotp( pt_wsp, pt_wsp-t, L_SUBFR ); + } + + pt_cor = cor + L_INTERPOL1; + cor_max = *pt_cor++; + t1 = t0_min; + for ( t=t0_min+1; t<=t0_max; t++ ) + { + if ( *pt_cor > cor_max ) + { + cor_max = *pt_cor; + t1 = t; + } + pt_cor++; + } + + /*------------------------------------------------------------------* + * Search fractional pitch with 1/4 subsample resolution. + * search the fractions around t0 and choose the one which maximizes + * the interpolated normalized correlation. + *-----------------------------------------------------------------*/ + + pt_cor = cor + L_INTERPOL1 - t0_min; + t0 = t1; + + step = 1; /* 1/4 subsample resolution */ + fraction = 1; + + if (t0 == t0_min) /* Limit case */ + { + fraction = 0; + cor_max = interpolation( &pt_cor[t0], E_ROM_inter4_1, fraction, PIT_UP_SAMP, 4 ); + } + else /* Process negative fractions */ + { + t0--; + cor_max = interpolation( &pt_cor[t0], E_ROM_inter4_1, fraction, PIT_UP_SAMP, 4 ); + for ( i=(fraction+step); i<=3; i=i+step ) + { + temp = interpolation( &pt_cor[t0], E_ROM_inter4_1, i, PIT_UP_SAMP, 4 ); + if (temp > cor_max) + { + cor_max = temp; + fraction = i; + } + } + } + + for ( i=0; i<=3; i=i+step ) /* Process positive fractions */ + { + temp = interpolation( &pt_cor[t1], E_ROM_inter4_1, i, PIT_UP_SAMP, 4 ); + if (temp > cor_max) + { + cor_max = temp; + fraction = i; + t0 = t1; + } + } + + *pitch_fr = t0 + (float)fraction / 4.0f; + pred_lt4( pt_wsp, wsp_fr, t0, fraction, L_SUBFR, E_ROM_inter4_1, 4, PIT_UP_SAMP); + + enr_wsp = dotp( pt_wsp, pt_wsp, L_SUBFR ) + 0.01f; + enr_old = dotp( wsp_fr, wsp_fr, L_SUBFR ) + 0.01f; + *voicing_fr = cor_max * inv_sqrt(enr_wsp * enr_old); + + return; +} + + +/*-------------------------------------------------------------------* + * StableHighPitchDetect() + * + * Very short stable pitch detection + *-------------------------------------------------------------------*/ + +void StableHighPitchDetect( + short *flag_spitch, /* o : flag to indicate very short stable pitch */ + short pitch[], /* i/o: OL pitch buffer */ + const float voicing[], /* i : OL pitch gains */ + const float Bin_E[], /* i : per bin log energy spectrum */ + const float wsp[], /* i : weighted speech */ + const short localVAD, + float *voicing_sm, /* i/o: smoothed open-loop pitch gains */ + float *voicing0_sm, /* i/o: smoothed high pitch gains */ + float *LF_EnergyRatio_sm, /* i/o: smoothed [0, 300Hz] relative peak energy*/ + short *predecision_flag, /* i/o: predecision flag */ + float *diff_sm, /* i/o: smoothed pitch frequency difference */ + float *energy_sm /* i/o: smoothed energy around pitch frequency */ +) +{ + short i, pitch_freq_point, pit_min_up; + short T, Tp, pit_min; + + float voicing_m; + float energy0, energy1, ratio, cor_max, diff, sum_energy; + const float *pt_wsp; + + voicing_m = mean( voicing, 3 ); + *voicing_sm = 0.75f * (*voicing_sm) + 0.25f * voicing_m; + + + /* initial short pitch possibility pre-decision */ + pitch_freq_point = (short)(L_FFT/pitch[1] + 0.5f ); + diff = 0.0f; + sum_energy = 0.0f; + + for( i=1; i<2*pitch_freq_point; i++ ) + { + diff += (Bin_E[pitch_freq_point] - Bin_E[i]); + sum_energy += Bin_E[i]; + } + sum_energy /= (2*pitch_freq_point-1); + + *diff_sm = 0.2f * diff + 0.8f * *diff_sm; + *energy_sm = 0.2f * sum_energy + 0.8f * *energy_sm; + diff /= sum_energy; + + if( *diff_sm < -10 && *energy_sm < 38.5 && diff < -0.8 ) + { + *predecision_flag = 1; + } + + if( *diff_sm > 10 && *energy_sm > 83 && diff > 0.5 ) + { + *predecision_flag = 0; + } + + /* short pitch possiblity pre-decision */ + maximum(Bin_E, 7, &energy0); + maximum(Bin_E+8, 7, &energy1); + ratio = max(energy1-energy0,0); + ratio *= max(voicing_m,0); + + *LF_EnergyRatio_sm = (15*(*LF_EnergyRatio_sm) + ratio)/16; + + if( *LF_EnergyRatio_sm > 35 || ratio > 50 ) + { + *predecision_flag = 1; + } + + if( *LF_EnergyRatio_sm < 16 ) + { + *predecision_flag = 0; + } + + /* short pitch candidate detection */ + Tp = pitch[1]; + cor_max = 0; + + pt_wsp = wsp + 3*L_SUBFR; + pit_min = PIT_MIN_DOUBLEEXTEND; + pit_min_up = PIT_MIN; + + for( T=pit_min; T<=pit_min_up; T++ ) + { + energy1 = dotp( pt_wsp, pt_wsp-T, L_SUBFR ); + + if( energy1 > cor_max || T == pit_min ) + { + cor_max = energy1; + Tp = T; + } + } + + energy0 = dotp( pt_wsp, pt_wsp, L_SUBFR ) + 0.01f; + energy1 = dotp( pt_wsp-Tp, pt_wsp-Tp, L_SUBFR ) + 0.01f; + cor_max *= inv_sqrt( energy0*energy1 ); + *voicing0_sm = 0.75f*(*voicing0_sm) + 0.25f*cor_max; + + /* final short pitch correction */ + *flag_spitch = 0; + if( localVAD && *predecision_flag && *voicing0_sm > 0.65f && *voicing0_sm > 0.7f * (*voicing_sm) ) + { + *flag_spitch = 1; + + pitch[0] = Tp; + pitch[1] = Tp; + pitch[2] = Tp; + } + + return; +} + +/*-------------------------------------------------------------------* + * pitchDoubling_det() + * Multiple pitch doubling detector + * + *-------------------------------------------------------------------*/ + +void pitchDoubling_det( + float *wspeech, + short *pitch_ol, + float *pitch_fr, + float *voicing_fr +) +{ + float new_op_fr[2]; + float new_voicing[2]; + short new_Top[2]; + int m, T; + + /*save initial values*/ + new_Top[0]=pitch_ol[0]; + new_Top[1]=pitch_ol[1]; + for(m=2; m<5; m++) + { + T = pitch_ol[0]/m; + if(T>=PIT_MIN_12k8) + { + pitch_ol2( PIT_MIN_SHORTER, T, &new_op_fr[0], &new_voicing[0], 0, wspeech, 2 ); + pitch_ol2( PIT_MIN_SHORTER, T, &new_op_fr[1], &new_voicing[1], L_SUBFR, wspeech, 2 ); + + if((new_voicing[0]+new_voicing[1])>(voicing_fr[0]+voicing_fr[1])) + { + new_Top[0]=T; + pitch_fr[0]=new_op_fr[0]; + pitch_fr[1]=new_op_fr[1]; + voicing_fr[0]=new_voicing[0]; + voicing_fr[1]=new_voicing[1]; + } + } + + T = pitch_ol[1]/m; + if(T>=PIT_MIN_12k8) + { + pitch_ol2( PIT_MIN_SHORTER, T, &new_op_fr[0], &new_voicing[0], 2*L_SUBFR, wspeech, 2 ); + pitch_ol2( PIT_MIN_SHORTER, T, &new_op_fr[1], &new_voicing[1], 3*L_SUBFR, wspeech, 2 ); + + if((new_voicing[0]+new_voicing[1])>(voicing_fr[2]+voicing_fr[3])) + { + new_Top[1]=T; + pitch_fr[2]=new_op_fr[0]; + pitch_fr[3]=new_op_fr[1]; + voicing_fr[2]=new_voicing[0]; + voicing_fr[3]=new_voicing[1]; + } + } + } + pitch_ol[0]=new_Top[0]; + pitch_ol[1]=new_Top[1]; + + return; +} diff --git a/src/libs/libevs/lib_enc/pitch_ol2_fx.cpp b/src/libs/libevs/lib_enc/pitch_ol2_fx.cpp deleted file mode 100755 index 70d67f6c..00000000 --- a/src/libs/libevs/lib_enc/pitch_ol2_fx.cpp +++ /dev/null @@ -1,392 +0,0 @@ -/*==================================================================================== - EVS Codec 3GPP TS26.442 Apr 03, 2018. Version 12.11.0 / 13.6.0 / 14.2.0 - ====================================================================================*/ - -#include "options.h" /* Compilation switches */ -#include "cnst_fx.h" /* Common constants */ -#include "rom_enc_fx.h" /* Encoder static table prototypes */ -#include "rom_com_fx.h" /* Encoder static table prototypes */ -#include "rom_dec_fx.h" -#include "prot_fx.h" /* Function prototypes */ -#include "stl.h" - -/*-------------------------------------------------------------------* - * Local constants - *-------------------------------------------------------------------*/ - -#define MAX_DELTA 16 /* half-length of the delta search */ -#define COR_BUF_LEN (L_INTERPOL1*2 + MAX_DELTA*2 + 1) - -/*-------------------------------------------------------------------* - * pitch_ol2() - * - * Open-loop pitch precision improvement with 1/4 resolution - * The pitch is searched in the interval 0) - { - t1s = t; - move16(); - } - cor_max_fx = s_max(cor_max_fx, *pt_cor_fx); - pt_cor_fx++; - } - - /*----------------------------------------------------------------* - * Search fractionnal pitch with 1/4 subsample resolution. - * search the fractions around t0 and choose the one which maximizes - * the interpolated normalized correlation. - *----------------------------------------------------------------*/ - pt_cor_fx = cor_fx + sub(L_INTERPOL1, t0_min); - t0s = t1s; - move16(); - - step = 1; - move16(); /* 1/4 subsample resolution */ - fraction = 1; - move16(); - - IF (sub(t0s, t0_min) != 0) /* Process negative fractions */ - { - t0s = sub(t0s,1); - cor_max_fx = Interpol_4(&pt_cor_fx[t0s], fraction); - move16(); - FOR (i=add(fraction, step); i<=3; i+=step) - { - temp_fx = Interpol_4(&pt_cor_fx[t0s], i); - if (sub(temp_fx, cor_max_fx) > 0) - { - fraction = i; - move16(); - } - cor_max_fx = s_max(temp_fx, cor_max_fx); - } - } - ELSE /* Limit case */ - { - fraction = 0; - move16(); - cor_max_fx = Interpol_4(&pt_cor_fx[t0s], fraction); - move16(); - } - FOR (i = 0; i<=3; i+=step) /* Process positive fractions */ - { - temp_fx = Interpol_4(&pt_cor_fx[t1s], i); - move16(); - - IF (sub(temp_fx,cor_max_fx) > 0) - { - cor_max_fx = temp_fx; - move16(); - fraction = i; - move16(); - t0s = t1s; - move16(); - } - } - - *pitch_fr_fx = shl(add(shl(t0s, 2), fraction), 4); - move16(); /*Q7*/ - - IF( L_sub(t1, 1L) != 0 ) - { - pred_lt4(pt_wsp_fx, wsp_fr_fx, t0s, fraction, L_SUBFR, pitch_inter4_1, 4, PIT_UP_SAMP); - - R0 = cor_max_fx; - move16(); - R1 = L_mult(pt_wsp_fx[0], pt_wsp_fx[0]); - R2 = L_mult(wsp_fr_fx[0], wsp_fr_fx[0]); - FOR (j = 1; j < L_SUBFR; j++) - { - R1 = L_mac(R1, pt_wsp_fx[j], pt_wsp_fx[j]); - R2 = L_mac(R2, wsp_fr_fx[j], wsp_fr_fx[j]); - } - - /* *voicing_fr = cor_max * inv_sqrt(enr_wsp * enr_old) */ - /* *voicing_fr = R0 * inv_sqrt(R1 * R2) */ - exp_R0 = norm_s(R0); - R0 = shl(R0, exp_R0); - - exp_R1 = norm_l(R1); - R1 = L_shl(R1, exp_R1); - - exp_R2 = norm_l(R2); - R2 = L_shl(R2, exp_R2); - - R1 = L_mult(round_fx(R1), round_fx(R2)); - - i = norm_l(R1); - R1 = L_shl(R1, i); - - exp_R1 = add(exp_R1, exp_R2); - exp_R1 = add(exp_R1, i); - exp_R1 = sub(62, exp_R1); - - R1 = Isqrt_lc(R1, &exp_R1); - - R1 = L_mult(R0, round_fx(R1)); - exp_R0 = sub(31, exp_R0); - exp_R0 = sub(add(exp_R0, exp_R1),exp3); - - *voicing_fr_fx = round_fx(L_shl(R1, exp_R0)); /*Q15*/ - } - ELSE - { - *voicing_fr_fx = 0; - move16(); - } - - return; -} -/*-------------------------------------------------------------------* - * StableHighPitchDetect() - * - * stable very short pitch detection - *-------------------------------------------------------------------*/ -void StableHighPitchDetect_fx( - Word16 *flag_spitch, /* o : flag to indicate very short stable pitch */ - Word16 pitch[], /* i/o: OL pitch buffer */ - const Word16 voicing[], /* i : OL pitch gains */ - const Word16 wsp[], /* i : weighted speech */ - const Word16 localVAD, - Word16 *voicing_sm, /* i/o: smoothed open-loop pitch gains */ - Word16 *voicing0_sm, /* i/o: smoothed high pitch gains */ - Word16 *LF_EnergyRatio_sm, /* i/o: smoothed [0, 300Hz] relative peak energy*/ - Word16 *predecision_flag, /* i/o: predecision flag */ - Word32 *diff_sm, /* i/o: smoothed pitch frequency difference */ - Word32 *energy_sm , /* i/o: smoothed energy around pitch frequency */ - Word16 Q_new, - Word16 EspecdB[] -) -{ - Word16 i, pitch_freq_point; - Word16 T, Tp, pit_min; - Word16 energy0_16, energy1_16,ratio, voicing_m; - Word32 energy0, energy1, cor_max, diff, sum_energy; - const Word16 *pt_wsp; - Word16 tmp,tmp1,exp , diff16,cor_max16 ,exp1,exp2,pit_min_up; - Word32 L_tmp,L_tmp1; - Word16 Top; - - /*voicing = (voicing[0] + voicing[1] + voicing[2] )/3;*/ - L_tmp = L_mult(voicing[0],10923); - L_tmp = L_mac(L_tmp, voicing[1],10923); - L_tmp = L_mac(L_tmp, voicing[2],10923); - voicing_m = round_fx(L_tmp); - - /**voicing_sm = 0.75f*(*voicing_sm) + 0.25f*voicing;*/ - *voicing_sm = round_fx(L_mac(L_mult(*voicing_sm , 24576), voicing_m , 8192)); - - /* pitch_freq_point = (short)(L_FFT/(mult_fact*T_op[1])+0.5f);*/ - Top = pitch[1]; - exp = norm_s(Top); - tmp = div_s(shl(1,sub(14,exp)), Top);/*Q(29 - exp)*/ - L_tmp = L_mult0(tmp ,L_FFT);/*Q(29 - exp)*/ - pitch_freq_point = extract_h(L_add (L_shl(L_tmp , sub(exp, 13)),32768)) ; /* Q0*/ - diff = L_deposit_l(0); - sum_energy = L_deposit_l(0); - FOR( i=1; i<2*pitch_freq_point; i++ ) - { - diff = L_add(diff ,sub(EspecdB[pitch_freq_point], EspecdB[i])); - sum_energy = L_add(sum_energy, EspecdB[i]); - } - /*sum_energy /= (2*pitch_freq_point-1);*/ - tmp = sub(shl(pitch_freq_point,1) ,1); - exp = norm_s(tmp); - tmp1 = div_s(shl(1,sub(14,exp)),tmp);/*Q(29-exp)*/ - L_tmp = Mult_32_16(sum_energy ,tmp1); - sum_energy = L_shl(L_tmp, sub(exp,14)); - /**diff_sm = 0.2f * diff + 0.8f * *diff_sm;*/ - *diff_sm = L_add(Mult_32_16(diff,6554),Mult_32_16(*diff_sm,26214)); - move32(); - /**energy_sm = 0.2f * sum_energy + 0.8f * *energy_sm;*/ - *energy_sm = L_add(Mult_32_16(sum_energy,6554),Mult_32_16(*energy_sm,26214)); - move32(); - /*diff /= sum_energy;*/ - - IF(sum_energy) - { - exp = norm_l(sum_energy); - tmp = extract_h(L_shl(sum_energy,exp)); - exp = sub(sub(30,exp),7); - IF(tmp < 0) - { - tmp = abs_s(tmp); - tmp = div_s(16384,tmp); /*Q(15+exp)*/ - BASOP_SATURATE_WARNING_OFF - diff = L_negate( L_shr(Mult_32_16(diff,tmp),sub(exp+7 ,31) )); - BASOP_SATURATE_WARNING_ON - diff16 = round_fx(diff); - } - ELSE - { - tmp = div_s(16384,tmp); /*Q(15+exp)*/ - BASOP_SATURATE_WARNING_OFF - diff = L_shr(Mult_32_16(diff,tmp),sub(exp+7 ,31)); - BASOP_SATURATE_WARNING_ON - diff16 = round_fx(diff); - } - } - ELSE - { - diff16 = round_fx(L_shl(diff , 25)); - } - test(); - test(); - IF( L_sub(*diff_sm , -1280)<0 && L_sub( *energy_sm , 4928)< 0 && sub( diff16 , - 26214) <0 ) - { - *predecision_flag = 1; - move16(); - } - test(); - test(); - if( L_sub(*diff_sm ,1280)>0 && L_sub( *energy_sm , 10624)>0 && sub(diff16 ,16384)>0 ) - { - *predecision_flag = 0; - move16(); - } - - /* short pitch possiblity pre-decision */ - maximum_fx(EspecdB, 7, &energy0_16); - maximum_fx(EspecdB+8, 7, &energy1_16); - ratio = s_max(sub(energy1_16,energy0_16),0); /*Q7 */ - /*ratio *= max(voicing,0);*/ - tmp = s_max(voicing_m,0); - ratio = mult_r(ratio,tmp);/*Q7*/ - /**LF_EnergyRatio_sm = (15*(*LF_EnergyRatio_sm) + ratio)/16;*/ - L_tmp = L_mult(ratio,2048); - L_tmp = L_mac(L_tmp, *LF_EnergyRatio_sm,30720); - *LF_EnergyRatio_sm = round_fx(L_tmp); - test(); - if( sub(*LF_EnergyRatio_sm , 4480)>0 || sub( ratio ,6400)>0 ) - { - *predecision_flag=1; - move16(); - } - - if( sub(*LF_EnergyRatio_sm , 2048)<0 ) - { - *predecision_flag=0; - move16(); - } - - /* short pitch candidate detection */ - Tp = pitch[1]; - move16(); - cor_max = 0; - move16(); - pt_wsp = wsp + 3*L_SUBFR; - pit_min = PIT_MIN_DOUBLEEXTEND; - move16(); - pit_min_up = PIT_MIN; - move16(); - FOR( T=pit_min; T<=pit_min_up; T++ ) - { - energy1 = Dot_product( pt_wsp, pt_wsp-T, L_SUBFR ); - test(); - IF( (L_sub(energy1,cor_max)>0) || (sub(T,pit_min) ==0) ) - { - cor_max = L_add(energy1, 0); - Tp = T; - move16(); - } - } - energy0 = Dot_product12( pt_wsp, pt_wsp, L_SUBFR , &exp1 ) ; - exp1 = sub(exp1 ,shl(Q_new,1)); - energy1 = Dot_product12( pt_wsp-Tp, pt_wsp-Tp, L_SUBFR ,&exp2) ; - exp2 = sub(exp2 ,shl(Q_new,1)); - /* cor_max *= inv_sqrt( energy0*energy1 );*/ - L_tmp = Mult_32_32(energy0,energy1); - exp = norm_l(L_tmp); - L_tmp1 = L_shl(L_tmp,exp); - - exp = 31-exp-(31-exp1 -exp2); - move16(); - L_tmp1 = Isqrt_lc(L_tmp1, &exp); /*Q(31-exp)*/ - cor_max = Mult_32_32(cor_max, L_tmp1); - exp = 31 - (shl(Q_new,1)+1) - (31-exp) +31; - cor_max16 = round_fx(L_shl(cor_max, exp)); /*Q15*/ - /**voicing0_sm = add(mult_r(24576 ,(*voicing0_sm)) , mult_r(8192 , cor_max16));*/ - *voicing0_sm = round_fx(L_mac(L_mult(24576 ,*voicing0_sm), 8192 , cor_max16)); - - /* final short pitch detection */ - test(); - test(); - test(); - *flag_spitch = 0; - move16(); - IF( (sub(localVAD,1)==0) && (sub(*predecision_flag,1)==0) && - (sub(*voicing0_sm,16384)>0) && (sub(*voicing0_sm, mult_r(*voicing_sm,21299))>0 )) - { - *flag_spitch = 1; - move16(); - pitch[0] = Tp; - move16(); - pitch[1] = Tp; - move16(); - pitch[2] = Tp; - move16(); - } - - return; -} diff --git a/src/libs/libevs/lib_enc/plc_enc_ext.cpp b/src/libs/libevs/lib_enc/plc_enc_ext.cpp old mode 100755 new mode 100644 index 5c46a627..26d5e270 --- a/src/libs/libevs/lib_enc/plc_enc_ext.cpp +++ b/src/libs/libevs/lib_enc/plc_enc_ext.cpp @@ -1,136 +1,109 @@ /*==================================================================================== - EVS Codec 3GPP TS26.442 Apr 03, 2018. Version 12.11.0 / 13.6.0 / 14.2.0 + EVS Codec 3GPP TS26.443 Nov 13, 2018. Version 12.11.0 / 13.7.0 / 14.3.0 / 15.1.0 ====================================================================================*/ - #include +#include "prot.h" +#include "typedef.h" +#include "stat_enc.h" +#include "cnst.h" +#include "rom_com.h" -#include "stl.h" -#include "cnst_fx.h" -#include "stat_enc_fx.h" -#include "prot_fx.h" -#define NBITS_GACELP 5 - -extern const Word16 lsf_init[16]; +#define NBITS_GACELP 5 +/*-------------------------------------------------------------------* +* open_PLC_ENC_EVS() +* +* +*-------------------------------------------------------------------*/ void open_PLC_ENC_EVS( HANDLE_PLC_ENC_EVS hPlcExt, - Word32 sampleRate /* core coder SR */ + int sampleRate ) { - Word16 itr; + short itr; hPlcExt->enableGplc = 0; - move16(); hPlcExt->calcOnlylsf = 1; - move16(); hPlcExt->nBits = NBITS_GACELP; - move16(); - - hPlcExt->Q_exp = 0; - move16(); - hPlcExt->Q_new = 0; - move16(); - - set16_fx(hPlcExt->mem_MA_14Q1,0,M); - set16_fx(hPlcExt->mem_AR,0,M); - set16_fx(hPlcExt->lsfold_14Q1,0,M); - set16_fx(hPlcExt->lspold_Q15,0,M); - - set16_fx(hPlcExt->old_exc_Qold,0,8); - - set16_fx(hPlcExt->lsfoldbfi0_14Q1,0,M); - set16_fx(hPlcExt->lsfoldbfi1_14Q1,0,M); - set16_fx(hPlcExt->lsf_adaptive_mean_14Q1,0,M); - hPlcExt->stab_fac_Q15 = 0; - move16(); - IF( L_sub(sampleRate,12800)==0 ) + hPlcExt->stab_fac = 0; + set_f(hPlcExt->lsfoldbfi0, 0.0f, M); + set_f(hPlcExt->lsfoldbfi1, 0.0f, M); + set_f(hPlcExt->lsf_adaptive_mean, 0.0f, M); + set_f(hPlcExt->old_exc, 0.0f, 8); + set_f(hPlcExt->mem_MA, 0.0f, M); + set_f(hPlcExt->lsfold, 0.0f, M); + set_f(hPlcExt->lspold, 0.0f, M); + if( sampleRate == 12800 ) { hPlcExt->T0_4th = L_SUBFR; - move16(); hPlcExt->T0 = L_SUBFR; - move16(); - FOR( itr=0; itrlsf_con[itr] = lsf_init[itr]; - move16(); hPlcExt->last_lsf_ref[itr] = lsf_init[itr]; - move16(); hPlcExt->last_lsf_con[itr] = lsf_init[itr]; - move16(); } } - ELSE + else { hPlcExt->T0_4th = L_SUBFR; - move16(); hPlcExt->T0 = L_SUBFR; - move16(); - FOR( itr=0; itrlsf_con[itr] = add(lsf_init[itr],shr(lsf_init[itr],2)); - hPlcExt->last_lsf_ref[itr] = add(lsf_init[itr],shr(lsf_init[itr],2)); - hPlcExt->last_lsf_con[itr] = add(lsf_init[itr],shr(lsf_init[itr],2)); + hPlcExt->lsf_con[itr] = lsf_init[itr] * 1.25; + hPlcExt->last_lsf_ref[itr] = lsf_init[itr] * 1.25; + hPlcExt->last_lsf_con[itr] = lsf_init[itr] * 1.25; } } + return; } -/* - function to extract and write guided information -*/ -void gPLC_encInfo (HANDLE_PLC_ENC_EVS self, - Word32 modeBitrate, - Word16 modeBandwidth, - Word16 old_clas, - Word16 coder_type - ) +/*-------------------------------------------------------------------* +* gPLC_encInfo() +* +* Function to extract and write guided information +*-------------------------------------------------------------------*/ + +void gPLC_encInfo( + HANDLE_PLC_ENC_EVS self, + const int brate, + const int bwidth, + const short last_clas, + const int coder_type +) { - - - IF (self) + if (self) { self->calcOnlylsf = 1; - move16(); - test(); - test(); - test(); - test(); - test(); - IF ( ( sub(modeBandwidth, WB) == 0 && L_sub(modeBitrate, 24400) == 0 ) || - ( sub(modeBandwidth, SWB) == 0 && L_sub(modeBitrate, 24400) == 0 ) || - ( sub(modeBandwidth, FB) == 0 && L_sub(modeBitrate, 24400) == 0 ) ) + if(bwidth >= WB && brate == ACELP_24k40 ) { self->enableGplc = 1; - move16(); - self->nBits = 1; - move16(); - test(); - test(); - test(); - IF ( (sub(old_clas, VOICED_CLAS)==0 || sub(old_clas, ONSET)==0) && - (sub(coder_type, VOICED)==0 || sub(coder_type, GENERIC)==0 ) ) + + if( ( last_clas == VOICED_CLAS || last_clas == ONSET ) + && (coder_type == VOICED || coder_type == GENERIC) ) { self->nBits = NBITS_GACELP; - move16(); self->calcOnlylsf = 0; - move16(); + } + else + { + self->nBits = 1; } } - ELSE + else { self->enableGplc = 0; - move16(); - self->nBits = NBITS_GACELP; - move16(); + self->nBits = 0; } } + return; } - diff --git a/src/libs/libevs/lib_enc/ppp_enc.cpp b/src/libs/libevs/lib_enc/ppp_enc.cpp new file mode 100644 index 00000000..6bd3f17f --- /dev/null +++ b/src/libs/libevs/lib_enc/ppp_enc.cpp @@ -0,0 +1,202 @@ +/*==================================================================================== + EVS Codec 3GPP TS26.443 Nov 13, 2018. Version 12.11.0 / 13.7.0 / 14.3.0 / 15.1.0 + ====================================================================================*/ + +#include +#include +#include "cnst.h" +#include "prot.h" +#include "rom_com.h" + + +/*-------------------------------------------------------------------* + * ppp_quarter_encoder() + * + * PPP quarter encoder + *--------------------------------------------------------------------*/ + +short ppp_quarter_encoder( + Encoder_State *st, /* i/o: encoder state structure */ + DTFS_STRUCTURE *CURRCW_Q, /* o : Quantized (amp/phase) DTFS */ + DTFS_STRUCTURE *TARGETCW, /* o : DTFS with quant phase but unquant Amp */ + int prevCW_lag, /* i : previous lag */ + DTFS_STRUCTURE vCURRCW_NQ, /* i : Unquantized DTFS */ + const float *curr_lpc, /* i : LPCS */ + float *lastLgainE, /* i/o: last low band gain */ + float *lastHgainE, /* i/o: last high band gain */ + float *lasterbE, /* i/o: last ERB vector */ + DTFS_STRUCTURE PREV_CW_E /* i : past DTFS */ +) +{ + DTFS_STRUCTURE *PREVDTFS; + + float tmp, temp_pl, temp_l; + int l; + short returnFlag = 1; + int POWER_IDX; /* Codebook index for the power quantization for PPP */ + int AMP_IDX[2]; /* Codebook index for the Amplitude quantization for PPP */ + float Erot = 0.0, z = 0.0; + + PREVDTFS = DTFS_new(); + + DTFS_copy( CURRCW_Q, vCURRCW_NQ ); + DTFS_copy( PREVDTFS, PREV_CW_E ); + + l = CURRCW_Q->lag; + temp_l = (float) CURRCW_Q->lag; + temp_pl = (float) prevCW_lag; + + DTFS_adjustLag( PREVDTFS, l ); + + z = ((L_FRAME-temp_l)*(temp_l+temp_pl))/(2*temp_l*temp_pl); + + Erot = (float) (temp_l - rint_new(temp_l*(z - floor(z)))); + + DTFS_phaseShift( PREVDTFS, (float)(PI2*Erot/CURRCW_Q->lag)) ; + DTFS_car2pol(PREVDTFS); + + /* Amplitude Quantization */ + DTFS_car2pol(CURRCW_Q); /* at this point currCW_q=curr_nq */ + + returnFlag = DTFS_quant_cw(CURRCW_Q,prevCW_lag, curr_lpc, &POWER_IDX, AMP_IDX, lastLgainE, lastHgainE, lasterbE); + + push_indice( st, IND_AMP0, AMP_IDX[0], 6 ); + push_indice( st, IND_AMP1, AMP_IDX[1], 6 ); + push_indice( st, IND_POWER, POWER_IDX, 6 ); + + DTFS_copy(TARGETCW,*CURRCW_Q); + + /* Copying phase spectrum over */ + mvr2r(PREVDTFS->b, CURRCW_Q->b, (short)(CURRCW_Q->lag>>1)+1 ); + + DTFS_pol2car(CURRCW_Q); + DTFS_pol2car(TARGETCW); + tmp = DTFS_alignment_fine_new(*TARGETCW,*CURRCW_Q, 0.0) ; + + if (((tmp+3)>7) || ((tmp+3)<0)) + { + tmp = 0; + returnFlag = 0; + } + + DTFS_phaseShift( CURRCW_Q,(float)(PI2*tmp/CURRCW_Q->lag) ); + + push_indice( st, IND_GLOBAL_ALIGNMENT, (short) (tmp+3), 3 ); + + free( PREVDTFS ); + + return returnFlag; +} + +/*-------------------------------------------------------------------* + * set_ppp_mode() + * + * Determine if the current frame should be coded by PPP or not + * Impose PPP - CELP - CELP pattern + *-------------------------------------------------------------------*/ + +void set_ppp_mode( + Encoder_State *st, /* i/o: encoder state structure */ + short *coder_type, /* i/o: coder type */ + const short noisy_speech_HO, /* i : SC-VBR noisy speech HO flag */ + const short clean_speech_HO, /* i : SC-VBR clean speech HO flag */ + const short NB_speech_HO, /* i : SC-VBR NB speech HO flag */ + const short localVAD, + const short localVAD_he, /* i : HE-SAD flag without hangover */ + short *vad_flag + ,short T_op[] /* i : open loop pitch lag */ + ,short sp_aud_decision1 /* i : Speech Audio Decision */ +) +{ + if( *vad_flag == 1 && + ( noisy_speech_HO == 1 || clean_speech_HO == 1 || NB_speech_HO == 1 ) && + ( localVAD == 0 || localVAD_he == 0 ) ) + + { + *coder_type = UNVOICED; + } + + if( *coder_type == INACTIVE && *vad_flag == 0 && st->last_nelp_mode == 1 ) /* avoid HO frame go to GSC */ + { + *coder_type = UNVOICED; + } + + /* force the coder to NELP mode during the first five frames */ + /* this will indicate the decoder that the coder is operating in the VBR mode */ + if ( st->ini_frame < 5 ) + { + *coder_type = UNVOICED; + *vad_flag = 1; + } + + /* Pattern PPP-CELP-CELP (pppcountE holds number of consecutive PPP frames) */ + if ( *coder_type != VOICED || st->last_coder_type == TRANSITION ) + { + /* ensure no transient to PPP transition */ + st->pppcountE = 0; + } + else + { + /* current mode is voiced */ + st->pppcountE++; + + if ( ( st->pppcountE == 1 && st->last_last_ppp_mode != 1 && !st->rate_control ) || + ( st->pppcountE == 1 && st->mode_QQF ) ) + { + st->ppp_mode = 1; + st->core_brate = PPP_NELP_2k80; + } + else if ( st->pppcountE == 2 ) + { + if ( st->last_ppp_mode == 1 && !st->mode_QQF ) + { + /* QFF mode */ + st->ppp_mode = 0; + } + else + { + /* QQF Mode */ + st->ppp_mode = 1; + st->core_brate = PPP_NELP_2k80; + } + } + else + { + st->ppp_mode = 0; + st->pppcountE = 0; + } + } + + if ( st->ppp_mode == 0 && st->set_ppp_generic == 1 ) + { + st->set_ppp_generic = 0; + *coder_type = GENERIC; + } + + if( st->last_core == HQ_CORE ) + { + st->ppp_mode = 0; + st->set_ppp_generic = 0; + *coder_type = TRANSITION; + } + + if(st->last_ppp_mode && !st->ppp_mode && sp_aud_decision1 && st->bwidth == NB && st->Opt_SC_VBR) /*if it were about to go from ppp->HQ*/ + { + st->avoid_HQ_VBR_NB = 1; + *coder_type = GENERIC; + } + + if(st->last_nelp_mode && sp_aud_decision1 && st->bwidth == NB && st->Opt_SC_VBR) /*if it were about to go from nelp->HQ*/ + { + st->avoid_HQ_VBR_NB = 1; + *coder_type = GENERIC; + } + + if ((( st->old_pitch_buf[(2*NB_SUBFR)-1] > PPP_LAG_THRLD) || (T_op[1]>PPP_LAG_THRLD) || !st->last_Opt_SC_VBR ) && (st->ppp_mode==1)) + { + st->ppp_mode = 0; + st->core_brate = ACELP_7k20; + } + + return; +} diff --git a/src/libs/libevs/lib_enc/ppp_enc_fx.cpp b/src/libs/libevs/lib_enc/ppp_enc_fx.cpp deleted file mode 100755 index 5deb25c8..00000000 --- a/src/libs/libevs/lib_enc/ppp_enc_fx.cpp +++ /dev/null @@ -1,342 +0,0 @@ -/*==================================================================================== - EVS Codec 3GPP TS26.442 Apr 03, 2018. Version 12.11.0 / 13.6.0 / 14.2.0 - ====================================================================================*/ - -#include -#include "cnst_fx.h" -#include "prot_fx.h" -#include "rom_com_fx.h" -#include "stl.h" - -/*=======================================================================================*/ -/* FUNCTION : ppp_quarter_encoder_fx() */ -/*---------------------------------------------------------------------------------------*/ -/* PURPOSE : Quarter rate PPP encoder main routine */ -/*---------------------------------------------------------------------------------------*/ -/* INPUT ARGUMENTS : */ -/* _ (Word16 []) curr_lpc_fx: LPC coefficients, Q12 */ -/* _ (struct DTFS_STRUCTURE_FX) CURRCW_NQ_FX : prototype in Cartesian domain */ -/* (Word16) lag_fx: length of prototype */ -/* (Word16 []) a/b: harmonics, normalized */ -/* (Word16) Q: norm factor of a */ -/* _ (struct DTFS_STRUCTURE_FX) PREV_CW_E_FX : past dtfs in Cartesian domain */ -/* (Word16) lag: length of prototype */ -/* (Word16 []) a/b: harmonics, normalized */ -/* (Word16) Q: norm factor of a */ -/* _ (Word16) prevCW_lag_fx: Previous lag, Q0 */ -/* _ (Word16 *) exc : Global input (Q0) */ -/* _ (Word16 []) sinTab, Q15 : sin(2pi/4L*n), n=0,1,...,4L-1 */ -/* _ (Word16 []) cosTab, Q15 : cos(2pi/4L*n), n=0,1,...,4L-1 */ -/*---------------------------------------------------------------------------------------*/ -/* OUTPUT ARGUMENTS : */ -/* _ (Word16) pidx: Power index */ -/* _ (Word16[]) aidx: Amplitude indices, 2 words */ -/* _ (struct DTFS_fx *) CURRCW_Q_FX : quantized prototype in Cartesian domain */ -/* (Word16) lag_fx: length of prototype in time domain */ -/* (Word16 []) a/b: harmonics, normalized */ -/* (Word16) Q: norm factor of a */ -/* _ (struct DTFS_fx *) TARGETCW_FX : Target prototype in Cartesian domain */ -/* (Word16) lag_fx: length of prototype in time domain */ -/* (Word16 []) a/b: harmonics, normalized */ -/* (Word16) Q: norm factor of a */ -/*---------------------------------------------------------------------------------------*/ -/* INPUT/OUTPUT ARGUMENTS : */ -/* _ (Word16[]) lasterbE_fx: ERB history for differential */ -/* quantization, Q13 */ -/* _ (Word16) lastLgainE_fx: low band power history, log domain, */ -/* Q11 */ -/* _ (Word16) lastHgainE_fx: high band power history, log domain, */ -/* Q11 */ -/*---------------------------------------------------------------------------------------*/ -/* RETURN ARGUMENTS : */ -/* _ (Word16) returnFlag: flag indicating success/failure */ -/* (TRUE/FALSE) */ -/*---------------------------------------------------------------------------------------*/ -/* CALLED FROM : TX */ -/*=======================================================================================*/ - -Word16 ppp_quarter_encoder_fx( - DTFS_STRUCTURE_FX *CURRCW_Q_FX, /* o : Quantized (amp/phase) DTFS */ - DTFS_STRUCTURE_FX *TARGETCW_FX, /* o : DTFS with quant phase but unquant Amp */ - Word16 prevCW_lag, /* i : previous lag */ - DTFS_STRUCTURE_FX vCURRCW_NQ_FX, /* i : Unquantized DTFS */ - const Word16 *curr_lpc_fx, /* i : LPCS */ - Word16 *lastLgainE_fx, /* i/o: last low band gain */ - Word16 *lastHgainE_fx, /* i/o: last high band gain */ - Word16 *lasterbE_fx, /* i/o: last ERB vector */ - DTFS_STRUCTURE_FX PREV_CW_E_FX, /* i : past DTFS */ - Word16 *S_fx, /* i : sin table, Q15 */ - Word16 *C_fx, /* i : cos table, Q15 */ - Encoder_State_fx *st_fx -) -{ - DTFS_STRUCTURE_FX *PREVDTFS_FX = DTFS_new_fx(); - Word16 tmp_fx, temp_pl_fx, temp_l_fx; - Word16 temp; - Word16 l; - Word16 returnFlag = 1; - Word16 POWER_IDX_FX; /* Codebook index for the power quantization for PPP */ - Word16 AMP_IDX_fx[2]; /* Codebook index for the Amplitude quantization for PPP */ - Word16 Erot_fx = 0; - /* Word16 S_fx[PIT_MAX*4+1], C_fx[PIT_MAX*4+1];*/ - Word32 Ltempd,Ltempn; - Word32 L_tmp, L_tmp1; - Word16 tmp, exp; - DTFS_copy_fx( CURRCW_Q_FX, vCURRCW_NQ_FX ); - DTFS_copy_fx( PREVDTFS_FX, PREV_CW_E_FX ); - - l = CURRCW_Q_FX->lag_fx; - move16(); - temp_l_fx = CURRCW_Q_FX->lag_fx; - move16(); - temp_pl_fx = prevCW_lag; - move16(); - - DTFS_adjustLag_fx( PREVDTFS_FX, l ); - - - /* z = ((L_FRAME-temp_l)*(temp_l+temp_pl))/(2*temp_l*temp_pl); */ - /* Erot = (float) (temp_l - rint_new(temp_l*(z - floor(z)))); */ - temp = sub(L_FRAME,temp_l_fx); /*Q0 */ - exp = norm_s(temp_pl_fx); - tmp = div_s(shl(1,sub(14,exp)),temp_pl_fx); /*Q(29-exp) */ - L_tmp = L_mult(temp,tmp); /*Q(31-exp); +1 due to /2 */ - L_tmp = L_shl(L_tmp,sub(exp,15)); /*Q16 */ - - exp = norm_s(temp_l_fx); - tmp = div_s(shl(1,sub(14,exp)),temp_l_fx); /*Q(29-exp) */ - L_tmp1 = L_mult(temp,tmp); /*Q(31-exp); +1 due to /2 */ - L_tmp1 = L_shl(L_tmp1,sub(exp,15)); /*Q16 */ - - L_tmp = L_add(L_tmp,L_tmp1); /*Q16 */ - - tmp = lshr(extract_l(L_tmp),1); /*Q15 */ - L_tmp = L_mult(temp_l_fx,tmp); /*Q16 */ - temp = rint_new_fx(L_tmp); - Erot_fx = sub(temp_l_fx,temp); /*Q0 */ - - GetSinCosTab_fx(CURRCW_Q_FX->lag_fx,S_fx,C_fx);/*get cos and sin tables for lag */ - Q2phaseShift_fx(PREVDTFS_FX,shl(Erot_fx,2),CURRCW_Q_FX->lag_fx,S_fx,C_fx); - - DTFS_copy_fx(TARGETCW_FX,*CURRCW_Q_FX); - /* Amplitude Quantization */ - DTFS_car2pol_fx(CURRCW_Q_FX); /* at this point currCW_q=curr_nq */ - - /*As the upper cut of freqencies are normalized to 12800, we have to multiply upper cut off freq by - 2.56(1/12800 in Q15) */ - Ltempn = L_mult(CURRCW_Q_FX->upper_cut_off_freq_fx,10486);/* Q0+Q27 = Q28 */ - CURRCW_Q_FX->upper_cut_off_freq_fx = (Word16)L_shr(Ltempn,13);/*Q15 */ - Ltempn = L_mult(CURRCW_Q_FX->upper_cut_off_freq_of_interest_fx,10486);/* Q0+Q27 = Q28 */ - CURRCW_Q_FX->upper_cut_off_freq_of_interest_fx = (Word16)L_shr(Ltempn,13);/*Q15 */ - - returnFlag = DTFS_quant_cw_fx(CURRCW_Q_FX,prevCW_lag,curr_lpc_fx,&POWER_IDX_FX, - AMP_IDX_fx,lastLgainE_fx,lastHgainE_fx,lasterbE_fx,S_fx,C_fx); - move16(); - - /*De-normalize cut off frequencies */ - Ltempn = L_shl((Word32)CURRCW_Q_FX->upper_cut_off_freq_fx,13);/*Q28 */ - CURRCW_Q_FX->upper_cut_off_freq_fx = (Word16)find_remd(Ltempn, 20971,&Ltempd); - move16(); - Ltempn = L_shl((Word32)CURRCW_Q_FX->upper_cut_off_freq_of_interest_fx,13);/*Q28 */ - CURRCW_Q_FX->upper_cut_off_freq_of_interest_fx = (Word16)find_remd(Ltempn, 20971,&Ltempd); - - push_indice_fx( st_fx, IND_AMP0, AMP_IDX_fx[0], 6 ); - push_indice_fx( st_fx, IND_AMP1, AMP_IDX_fx[1], 6 ); - push_indice_fx( st_fx, IND_POWER, POWER_IDX_FX, 6); - - /*Phase copying is done through copy_phase instead of car2pol and pol2car */ - copy_phase_fx(TARGETCW_FX,*CURRCW_Q_FX,TARGETCW_FX); - /*Phase copying is done through copy_phase instead of car2pol and pol2car */ - copy_phase_fx(PREVDTFS_FX,*CURRCW_Q_FX,CURRCW_Q_FX); - /* Copying phase spectrum over */ - /*mvr2r(PREVDTFS->b, CURRCW_Q->b, (short)(CURRCW_Q->lag>>1)+1 ); */ - - /*DTFS_pol2car(CURRCW_Q); */ - /*DTFS_pol2car(TARGETCW); */ - - tmp_fx = DTFS_alignment_fine_new_fx(*TARGETCW_FX,*CURRCW_Q_FX,S_fx,C_fx); - move16(); - - test(); - IF (sub(add(tmp_fx,12),28)>0 || add(tmp_fx,12)<0) - { - tmp_fx = 0; - move16(); - returnFlag = 0; - move16(); - } - - /*DTFS_phaseShift( CURRCW_Q,(float)(PI2*tmp/CURRCW_Q->lag) ); */ - Q2phaseShift_fx(CURRCW_Q_FX,tmp_fx,CURRCW_Q_FX->lag_fx,S_fx,C_fx); - - push_indice_fx( st_fx, IND_GLOBAL_ALIGNMENT, shr(add(tmp_fx,12),2), 3 ); - - free(PREVDTFS_FX); - return returnFlag; -} - -/*-------------------------------------------------------------------* -* set_ppp_mode_fx() - * - * Determine if the current frame should be coded by PPP or not - * Impose PPP - CELP - CELP pattern - *-------------------------------------------------------------------*/ -void set_ppp_mode_fx( - Encoder_State_fx *st_fx, /* i/o: state structure */ - Word16 *coder_type /* i : coding type */ - ,const Word16 noisy_speech_HO, /* i : SC-VBR noisy speech HO flag */ - const Word16 clean_speech_HO, /* i : SC-VBR clean speech HO flag */ - const Word16 NB_speech_HO, /* i : SC-VBR NB speech HO flag */ - const Word16 localVAD, - const Word16 localVAD_he, /* i : HE-SAD flag without hangover */ - Word16 *vad_flag - ,Word16 T_op_fx[] /* i : open loop pitch lag */ - ,Word16 sp_aud_decision1 /* i : Speech Audio Decision */ -) -{ - - test(); - test(); - test(); - test(); - test(); - - IF ( sub( *vad_flag, 1) == 0 && - ( sub( noisy_speech_HO , 1 ) == 0 || sub( clean_speech_HO, 1 ) == 0 || sub( NB_speech_HO, 1) == 0 ) && - ( localVAD == 0 || localVAD_he == 0 ) ) - - { - *coder_type = UNVOICED; - move16(); - } - - test(); - test(); - IF ( sub( *coder_type , INACTIVE ) == 0 && ( *vad_flag == 0 ) && sub( st_fx->last_nelp_mode_fx, 1 ) == 0 ) /* avoid HO frame go to GSC */ - { - *coder_type = UNVOICED; - move16(); - } - - - /* force the coder to NELP mode during the first five frames */ - /* this will indicate the decoder that the coder is operating in the VBR mode */ - IF ( sub( st_fx->ini_frame_fx, 5) <0 ) - { - *coder_type = UNVOICED; - move16(); - *vad_flag = 1; - move16(); - } - /* Pattern PPP-CELP-CELP (pppcountE holds number of consecutive PPP frames) */ - test(); - IF ( sub( *coder_type, VOICED ) != 0 || sub( st_fx->last_coder_type_fx, TRANSITION ) == 0 ) - { - /* ensure no transient to PPP transition */ - st_fx->pppcountE_fx = 0; - move16(); - } - ELSE - { - /* current mode is voiced */ - st_fx->pppcountE_fx = add( st_fx->pppcountE_fx, 1); - test(); - test(); - test(); - test(); - IF ( ( sub( st_fx->pppcountE_fx, 1 ) == 0 && sub( st_fx->last_last_ppp_mode_fx, 1) != 0 && st_fx->rate_control_fx == 0 ) || - ( sub( st_fx->pppcountE_fx, 1 ) == 0 && st_fx->mode_QQF_fx != 0) ) - { - st_fx->ppp_mode_fx = 1; - move16(); - st_fx->core_brate_fx = PPP_NELP_2k80; - move32(); - } - ELSE IF ( sub(st_fx->pppcountE_fx, 2 ) == 0 ) - { - test(); - IF ( st_fx->last_ppp_mode_fx != 0 && st_fx->mode_QQF_fx == 0 ) - { - /* QFF mode */ - st_fx->ppp_mode_fx = 0; - move16(); - } - ELSE - { - /* QQF Mode */ - st_fx->ppp_mode_fx = 1; - move16(); - st_fx->core_brate_fx = PPP_NELP_2k80; - move32(); - } - } - ELSE - { - st_fx->ppp_mode_fx = 0; - move16(); - st_fx->pppcountE_fx = 0; - move16(); - } - } - - - test(); - IF ( st_fx->ppp_mode_fx == 0 && sub( st_fx->set_ppp_generic_fx, 1) == 0 ) - { - st_fx->set_ppp_generic_fx = 0; - move16(); - *coder_type = GENERIC; - move16(); - } - - IF ( st_fx->last_core_fx == HQ_CORE ) - { - st_fx->ppp_mode_fx = 0; - move16(); - st_fx->set_ppp_generic_fx = 0; - move16(); - *coder_type = TRANSITION; - move16(); - } - - test(); - test(); - test(); - test(); - IF ( (st_fx->last_ppp_mode_fx != 0 ) && ( st_fx->ppp_mode_fx == 0 ) && ( sp_aud_decision1 != 0) - && sub(st_fx->bwidth_fx, NB) == 0 && st_fx->Opt_SC_VBR_fx != 0 ) /*if it were about to go from ppp->HQ*/ - { - st_fx->avoid_HQ_VBR_NB = 1; - move16(); - *coder_type = GENERIC; - move16(); - } - - test(); - test(); - test(); - IF ( (st_fx->last_nelp_mode_fx != 0) && ( sp_aud_decision1 != 0) && sub( st_fx->bwidth_fx, NB) == 0 && ( st_fx->Opt_SC_VBR_fx != 0 ) ) /*if it were about to go from nelp->HQ*/ - { - st_fx->avoid_HQ_VBR_NB = 1; - move16(); - *coder_type = GENERIC; - move16(); - } - - - test(); - test(); - test(); - IF( ( sub(st_fx->old_pitch_buf_fx[(2*NB_SUBFR)-1], PPP_LAG_THRLD_Q6) > 0 || - sub(T_op_fx[1], PPP_LAG_THRLD)>0 || !st_fx->last_Opt_SC_VBR_fx ) && - sub(st_fx->ppp_mode_fx,1)==0 ) - { - st_fx->ppp_mode_fx=0; - move16(); - st_fx->core_brate_fx = ACELP_7k20; - move32(); - } - - - return; -} diff --git a/src/libs/libevs/lib_enc/pre_proc.cpp b/src/libs/libevs/lib_enc/pre_proc.cpp new file mode 100644 index 00000000..ebb7fc32 --- /dev/null +++ b/src/libs/libevs/lib_enc/pre_proc.cpp @@ -0,0 +1,899 @@ +/*==================================================================================== + EVS Codec 3GPP TS26.443 Nov 13, 2018. Version 12.11.0 / 13.7.0 / 14.3.0 / 15.1.0 + ====================================================================================*/ + +#include "options.h" +#include "cnst.h" +#include "rom_enc.h" +#include "rom_com.h" +#include "prot.h" + +/*-------------------------------------------------------------------* + * pre_proc() + * + * Pre-processing (spectral analysis, LP analysis, VAD, OL pitch calculation, coder mode selection, ...) + *--------------------------------------------------------------------*/ + +void pre_proc( + Encoder_State *st, /* i/o: encoder state structure */ + const short input_frame, /* i : frame length */ + const float signal_in[], /* i : new samples */ + float old_inp_12k8[], /* i/o: buffer of old input signal */ + float old_inp_16k[], /* i/o: buffer of old input signal @ 16kHz */ + float **inp, /* o : ptr. to inp. signal in the current frame */ + short *sp_aud_decision1, /* o : 1st stage speech/music classification */ + short *sp_aud_decision2, /* o : 2nd stage speech/music classification */ + float fr_bands[2*NB_BANDS], /* o : energy in frequency bands */ + short *vad_flag, + short *localVAD, + float *Etot, /* o : total energy */ + float *ener, /* o : residual energy from Levinson-Durbin */ + short pitch[3], /* o : open-loop pitch values for quantiz. */ + float voicing[3], /* o : OL maximum normalized correlation */ + float A[NB_SUBFR16k*(M+1)], /* o : A(z) unquantized for the 4 subframes */ + float Aw[NB_SUBFR16k*(M+1)], /* o : weighted A(z) unquantized for subframes */ + float epsP[M+1], /* o : LP prediction errors */ + float lsp_new[M], /* o : LSPs at the end of the frame */ + float lsp_mid[M], /* o : LSPs in the middle of the frame */ + short *coder_type, /* o : coder type */ + short *sharpFlag, /* o : formant sharpening flag */ + short *vad_hover_flag, + short *attack_flag, /* o : flag signalling attack encoded by AC mode (GSC) */ + float *new_inp_resamp16k, /* o : new input signal @16kHz, non pre-emphasised, used by the WB TBE/BWE */ + short *Voicing_flag, /* o : voicing flag for HQ FEC */ + float realBuffer[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX], /* i/o : real buffer */ + float imagBuffer[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX], /* i/o : imag buffer */ + short *hq_core_type /* o : HQ core type */ +) +{ + short delay; + float *inp_12k8, *new_inp_12k8, *inp_16k, *new_inp_16k; /* pointers to current frame and new data */ + float old_wsp[L_WSP], *wsp; /* weighted input signal buffer */ + float pitch_fr[NB_SUBFR]; /* fractional pitch values */ + float voicing_fr[NB_SUBFR]; /* fractional pitch gains */ + float lf_E[2*VOIC_BINS]; /* per bin spectrum energy in lf */ + float tmpN[NB_BANDS]; /* Temporary noise update */ + float tmpE[NB_BANDS]; /* Temporary averaged energy of 2 sf. */ + float ee[2]; /* Spectral tilt */ + float corr_shift; /* correlation shift */ + float relE; /* frame relative energy */ + short loc_harm; /* harmonicity flag */ + float cor_map_sum, sp_div, PS[128]; /* speech/music clasif. parameters */ + short L_look; /* length of look-ahead */ + float snr_sum_he; /* HE SAD parameters */ + short localVAD_HE_SAD; /* HE SAD parameters */ + short vad_flag_dtx; /* HE-SAD flag with additional DTX HO */ + short vad_flag_cldfb; + float old_cor; + short uc_clas; + float hp_E[2]; /* Energy in HF */ + short noisy_speech_HO, clean_speech_HO, NB_speech_HO; /* SC-VBR HO flags */ + float non_staX; /* unbound non-stationarity for sp/mus clas. */ + short sr_core_tmp; + short L_frame_tmp; + short flag_spitch; + float lsf_new[M], stab_fac; + float band_energies[2*NB_BANDS]; /* energy in critical bands without minimum noise floor E_MIN */ + float enerBuffer[CLDFB_NO_CHANNELS_MAX]; + float currFlatness; + short high_lpn_flag; + short cldfb_addition = 0; + short alw_pitch_lag_12k8[2]; + float alw_voicing[2]; + float fft_buff[2*L_FFT]; + float sp_floor; + short sp_aud_decision0; + short last_core_orig; + + + + /*------------------------------------------------------------------* + * Initialization + *------------------------------------------------------------------*/ + + localVAD_HE_SAD = 0; + NB_speech_HO = 0; + clean_speech_HO = 0; + noisy_speech_HO = 0; + snr_sum_he = 0; + currFlatness = 0; + + *vad_hover_flag = 0; + uc_clas = VOICED_CLAS; + *sp_aud_decision1 = 0; + *sp_aud_decision2 = 0; + *coder_type = GENERIC; + st->noise_lev = NOISE_LEVEL_SP0; + *attack_flag = 0; + + st->bump_up = 0; + st->ppp_mode = 0; + st->nelp_mode = 0; + st->avoid_HQ_VBR_NB = 0; + + L_look = L_LOOK_12k8; /* lookahead at 12.8kHz */ + + new_inp_12k8 = old_inp_12k8 + L_INP_MEM; /* pointer to new samples of the input signal in 12.8kHz core */ + inp_12k8 = new_inp_12k8 - L_look; /* pointer to the current frame of input signal in 12.8kHz core */ + mvr2r( st->old_inp_12k8, old_inp_12k8, L_INP_MEM ); + + mvr2r( st->old_wsp, old_wsp, L_WSP_MEM ); + wsp = old_wsp + L_WSP_MEM; /* pointer to the current frame of weighted signal in 12.8kHz core */ + + old_cor = st->old_corr; /* save old_cor for speech/music classifier */ + + st->rf_mode = st->Opt_RF_ON; + + last_core_orig = st->last_core; + + /*--------------------------------------------------------------* + * Cldfb analysis + *---------------------------------------------------------------*/ + + st->prevEnergyHF = st->currEnergyHF; + + analysisCldfbEncoder( st, signal_in, input_frame, realBuffer, imagBuffer, enerBuffer ); + + /*----------------------------------------------------------------* + * Change the sampling frequency to 12.8 kHz + *----------------------------------------------------------------*/ + + modify_Fs( signal_in, input_frame, st->input_Fs, new_inp_12k8, 12800, st->mem_decim,(st->max_bwidth == NB) ); + + /* save input resampled at 12.8kHz, non-preemhasised */ + mvr2r( new_inp_12k8, st->buf_speech_enc+L_FRAME32k, L_FRAME ); + + /*------------------------------------------------------------------* + * Perform fixed preemphasis (12.8 kHz signal) through 1 - g*z^-1 + *-----------------------------------------------------------------*/ + + preemph( new_inp_12k8, PREEMPH_FAC, L_FRAME, &st->mem_preemph ); + + /*-------------------------------------------------------------------------* + * Spectral analysis + *--------------------------------------------------------------------------*/ + + analy_sp( inp_12k8, st->Bin_E, st->Bin_E_old, fr_bands, lf_E, Etot, st->min_band, st->max_band, band_energies, PS, fft_buff ); + + /*----------------------------------------------------------------* + * SAD (1-signal, 0-noise) + *----------------------------------------------------------------*/ + + noise_est_pre( *Etot, st->ini_frame, &st->Etot_l, &st->Etot_h, &st->Etot_l_lp, &st->Etot_last, + &st->Etot_v_h2, &st->sign_dyn_lp, st->harm_cor_cnt, &st->Etot_lp ); + + *vad_flag = wb_vad( st, fr_bands, localVAD, &noisy_speech_HO, &clean_speech_HO, &NB_speech_HO, &snr_sum_he, &localVAD_HE_SAD, &(st->flag_noisy_speech_snr) ); + + vad_flag_cldfb = vad_proc( realBuffer, imagBuffer, enerBuffer, st->cldfbAnaEnc->no_channels, &st->vad_st, &cldfb_addition,*vad_flag ); + + + /* Combine decisions from SADS */ + if ( *vad_flag == 1 && vad_flag_cldfb == 0 ) + { + *localVAD = 0; + } + + *vad_flag = vad_flag_cldfb; + + vad_flag_dtx = dtx_hangover_addition( st, *localVAD, *vad_flag, st->lp_speech-st->lp_noise, cldfb_addition, vad_hover_flag ); + + /*----------------------------------------------------------------* + * NB/WB/SWB/FB bandwidth detector + *----------------------------------------------------------------*/ + + bw_detect( st, signal_in, *localVAD, enerBuffer ); + + /*----------------------------------------------------------------* + * Noise energy down-ward update and total noise energy estimation + * Long-term energies and relative frame energy updates + * Correlation correction as a function of total noise level + *----------------------------------------------------------------*/ + + noise_est_down( fr_bands, st->bckr, tmpN, tmpE, st->min_band, st->max_band, &st->totalNoise, *Etot, &st->Etot_last, &st->Etot_v_h2 ); + + relE = *Etot - st->lp_speech; + + corr_shift = correlation_shift( st->totalNoise ); + + /*----------------------------------------------------------------* + * FD-CNG Noise Estimator + *----------------------------------------------------------------*/ + + resetFdCngEnc ( st ); + + perform_noise_estimation_enc( band_energies, enerBuffer, st->hFdCngEnc ); + + /*-----------------------------------------------------------------* + * Select SID or FRAME__NO_DATA frame if DTX enabled + *-----------------------------------------------------------------*/ + + dtx( st, vad_flag_dtx, inp_12k8 ); + + /*----------------------------------------------------------------* + * Adjust FD-CNG Noise Estimator + *----------------------------------------------------------------*/ + + if( (st->last_total_brate != st->total_brate) || (st->last_bwidth != st->bwidth) ) + { + configureFdCngEnc( st->hFdCngEnc, st->bwidth, st->rf_mode&&st->total_brate==13200?9600:st->total_brate ); + } + if ( st->hFdCngEnc != NULL && st->Opt_DTX_ON ) + { + AdjustFirstSID( st->hFdCngEnc->hFdCngCom->npart, st->hFdCngEnc->msPeriodog, st->hFdCngEnc->energy_ho, + st->hFdCngEnc->msNoiseEst, st->hFdCngEnc->msNoiseEst_old, &(st->hFdCngEnc->hFdCngCom->active_frame_counter), st ); + } + + /*----------------------------------------------------------------* + * Reconfigure Mode 2 + *----------------------------------------------------------------*/ + + if ( st->codec_mode == MODE2 ) + { + SetModeIndex( st, st->total_brate, st->bwidth ); + } + + calcLoEnvCheckCorrHiLo( st->cldfbAnaEnc->no_col, freqTable, st->tecEnc.loBuffer, st->tecEnc.loTempEnv, + st->tecEnc.loTempEnv_ns, st->tecEnc.hiTempEnv, &(st->tecEnc.corrFlag) ); + + /*---------------------------------------------------------------* + * Time Domain Transient Detector + *---------------------------------------------------------------*/ + + if( st->tcx10Enabled || st->tcx20Enabled ) + { + RunTransientDetection( signal_in, input_frame, &st->transientDetection ); + + currFlatness = GetTCXAvgTemporalFlatnessMeasure( &st->transientDetection, NSUBBLOCKS, 0 ); + } + + /*----------------------------------------------------------------* + * LP analysis + *----------------------------------------------------------------*/ + + alw_pitch_lag_12k8[0] = st->old_pitch_la; + alw_pitch_lag_12k8[1] = st->old_pitch_la; + alw_voicing[0] = st->old_voicing_la; + alw_voicing[1] = st->old_voicing_la; + + analy_lp( inp_12k8, L_FRAME, L_look, ener, A, epsP, lsp_new, lsp_mid, st->lsp_old1, alw_pitch_lag_12k8, alw_voicing, 12800 ); + + lsp2lsf( lsp_new, lsf_new, M, 12800 ); + stab_fac = lsf_stab( lsf_new, st->lsf_old1, 0, L_FRAME ); + mvr2r( lsf_new, st->lsf_old1, M ); + + /*----------------------------------------------------------------* + * Compute weighted input (for OL pitch analysis) + * OL pitch analysis + * stable high pitch detection + * 1/4 pitch precision improvement + *----------------------------------------------------------------*/ + + find_wsp( L_FRAME, L_SUBFR, NB_SUBFR, A, Aw, inp_12k8, TILT_FAC, wsp, &st->mem_wsp, GAMMA1, L_look ); + + if( *vad_flag == 0 ) + { + /* reset the OL pitch tracker memories during inactive frames */ + pitch_ol_init( &st->old_thres, &st->old_pitch, &st->delta_pit, &st->old_corr ); + } + + pitch_ol( pitch, voicing, &st->old_pitch, &st->old_corr, corr_shift, &st->old_thres, &st->delta_pit, + st->old_wsp2, wsp, st->mem_decim2, relE, L_look, st->clas, st->input_bwidth, st->Opt_SC_VBR ); + + /* Updates for adaptive lag window memory */ + st->old_pitch_la = pitch[2]; + st->old_voicing_la = voicing[2]; + + /* Detection of very short stable pitch period (MODE1 bit-rates) */ + StableHighPitchDetect( &flag_spitch, pitch, voicing, st->Bin_E, wsp, *localVAD, &st->voicing_sm, &st->voicing0_sm, + &st->LF_EnergyRatio_sm, &st->predecision_flag, &st->diff_sm, &st->energy_sm ); + + /* 1/4 pitch precision improvement */ + if( st->total_brate <= ACELP_24k40 ) + { + pitch_ol2( PIT_MIN_EXTEND, pitch[0], &pitch_fr[0], &voicing_fr[0], 0, wsp, 7 ); + pitch_ol2( PIT_MIN_EXTEND, pitch[0], &pitch_fr[1], &voicing_fr[1], L_SUBFR, wsp, 7 ); + pitch_ol2( PIT_MIN_EXTEND, pitch[1], &pitch_fr[2], &voicing_fr[2], 2*L_SUBFR, wsp, 7 ); + pitch_ol2( PIT_MIN_EXTEND, pitch[1], &pitch_fr[3], &voicing_fr[3], 3*L_SUBFR, wsp, 7 ); + } + else + { + pitch_fr[0] = pitch[0]; + pitch_fr[1] = pitch[0]; + pitch_fr[2] = pitch[1]; + pitch_fr[3] = pitch[1]; + + voicing_fr[0] = voicing[0]; + voicing_fr[1] = voicing[0]; + voicing_fr[2] = voicing[1]; + voicing_fr[3] = voicing[1]; + } + + /*------------------------------------------------------------------* + * Update estimated noise energy and voicing cut-off frequency + *-----------------------------------------------------------------*/ + + noise_est( st, tmpN, pitch, voicing, epsP, *Etot, relE, corr_shift, tmpE, fr_bands, &cor_map_sum, + &sp_div, &non_staX, &loc_harm, lf_E, &st->harm_cor_cnt, st->Etot_l_lp, &sp_floor ); + + /*------------------------------------------------------------------* + * Update parameters used in the VAD and DTX + *-----------------------------------------------------------------*/ + + vad_param_updt( st, pitch, voicing, corr_shift, A ); + + /*-----------------------------------------------------------------* + * Find spectral tilt + * UC and VC frame selection + *-----------------------------------------------------------------*/ + + find_tilt( fr_bands, st->bckr, ee, pitch, voicing, lf_E, corr_shift, st->input_bwidth, + st->max_band, hp_E, st->codec_mode, &(st->bckr_tilt_lt), st->Opt_SC_VBR); + + *coder_type = find_uv( st, pitch_fr, voicing_fr, voicing, inp_12k8, *localVAD, ee, + corr_shift, relE, *Etot, hp_E, &flag_spitch, st->voicing_sm, last_core_orig ); + + /*-----------------------------------------------------------------* + * channel aware mode configuration * + *-----------------------------------------------------------------*/ + + if( !st->Opt_RF_ON ) + { + st->rf_mode = 0; + st->rf_target_bits_write = 0; + } + else if( st->rf_mode && st->core_brate != FRAME__NO_DATA && st->core_brate != SID_2k40 ) + { + /* the RF config is for (n- fec_offset)th frame that will be packed along with the n-th frame bistream */ + st->rf_mode = 1; + st->codec_mode = MODE2; + + st->rf_target_bits_write = st->rf_targetbits_buff[st->rf_fec_offset]; + } + else + { + st->rf_mode = 0; + st->codec_mode = MODE1; + st->rf_indx_frametype[0] = RF__NO_DATA; + st->rf_targetbits_buff[0] = 6; /* rf_mode: 1, rf_frame_type: 3, and fec_offset: 2 */ + } + + /*-----------------------------------------------------------------* + * Signal classification for FEC + * TC frame selection + *-----------------------------------------------------------------*/ + + st->clas = signal_clas( st, coder_type, voicing, inp_12k8, *localVAD, pitch, ee, relE, L_look, &uc_clas ); + + st->Local_VAD = *localVAD; + + /*----------------------------------------------------------------* + * Speech/music classification + * AC frame selection + *----------------------------------------------------------------*/ + + speech_music_classif( st, &sp_aud_decision0, sp_aud_decision1, sp_aud_decision2, new_inp_12k8, inp_12k8, *vad_flag, + *localVAD, localVAD_HE_SAD, pitch, voicing, lsp_new, cor_map_sum, epsP, PS, + *Etot, old_cor, coder_type, attack_flag, non_staX, relE, &high_lpn_flag, flag_spitch ); + + long_enr( st, *Etot, localVAD_HE_SAD, high_lpn_flag ); + + /*----------------------------------------------------------------* + * Final VAD correction ( when HE-SAD is used instead of the normal VAD, + * rewrite the VAD flag by VAD flag with DTX hangover for further processing) + *----------------------------------------------------------------*/ + + if( st->Opt_DTX_ON ) + { + *vad_flag = vad_flag_dtx; + } + + /*----------------------------------------------------------------* + * Selection of internal ACELP Fs (12.8 kHz or 16 kHz) + *----------------------------------------------------------------*/ + + if( st->codec_mode == MODE1 ) + { + if( st->core_brate == FRAME__NO_DATA ) + { + /* prevent "L_frame" changes in CNG segments */ + st->L_frame = st->last_L_frame; + } + else if( st->core_brate == SID_2k40 && st->bwidth >= WB && st->first_CNG && st->act_cnt2 < MIN_ACT_CNG_UPD ) + { + /* prevent "L_frame" changes in SID frame after short segment of active frames */ + st->L_frame = st->last_CNG_L_frame; + } + else if( ( st->core_brate == SID_2k40 && st->total_brate >= ACELP_9k60 && ((st->bwidth == WB && !( st->total_brate == ACELP_13k20 && st->cng_type == FD_CNG )) || (st->cng_type == LP_CNG && st->bwidth > WB && st->total_brate >= ACELP_16k40)) ) || + ( st->total_brate > ACELP_24k40 && st->total_brate < HQ_96k ) || ( st->total_brate == ACELP_24k40 && st->bwidth >= WB ) ) + { + st->L_frame = L_FRAME16k; + } + else + { + st->L_frame = L_FRAME; + } + + if( st->ini_frame == 0 ) + { + /* avoid switching of internal ACELP Fs in the very first frame */ + st->last_L_frame = st->L_frame; + } + + if( st->L_frame == L_FRAME ) + { + st->gamma = GAMMA1; + st->preemph_fac = PREEMPH_FAC; + } + else + { + st->gamma = GAMMA16k; + st->preemph_fac = PREEMPH_FAC_16k; + } + + st->sr_core = 50*st->L_frame; + st->encoderLookahead_enc = NS2SA(st->sr_core, ACELP_LOOK_NS); + st->encoderPastSamples_enc = (st->L_frame*9)>>4; + } + + /*-----------------------------------------------------------------* + * coder_type rewriting in case of switching + * IC frames selection + * enforce TC frames in case of switching + *-----------------------------------------------------------------*/ + + if( st->codec_mode == MODE1 ) + { + /* enforce TRANSITION frames */ + if( st->last_L_frame != st->L_frame && st->core_brate != FRAME__NO_DATA && st->core_brate != SID_2k40 && (st->coder_type_raw != VOICED) ) + { + /* enforce TC frame in case of ACELP@12k8 <-> ACELP@16k core switching */ + *coder_type = TRANSITION; + } + else if( st->last_core == HQ_CORE || st->last_core == TCX_10_CORE || st->last_core == TCX_20_CORE ) + { + /* enforce TC frame in case of HQ -> ACELP core switching */ + *coder_type = TRANSITION; + } + else if( st->last_core_brate <= SID_2k40 && st->cng_type == FD_CNG ) + { + /* enforce TC frame in case of FD_CNG -> ACELP switching (past excitation not available) */ + *coder_type = TRANSITION; + } + + /* select INACTIVE frames */ + else if( st->total_brate <= ACELP_24k40 && *vad_flag == 0 ) + { + /* inactive frames will be coded by GSC technology */ + /* except for the VBR mode. VBR mode uses NELP for that */ + if( !( st->Opt_SC_VBR && vad_flag_dtx) ) + { + *coder_type = INACTIVE; + st->noise_lev = NOISE_LEVEL_SP3; + } + } + else if( st->total_brate > ACELP_24k40 && + ( (*vad_flag == 0 && st->bwidth >= SWB && st->max_bwidth >= SWB) || (*localVAD == 0 && (st->bwidth <= WB || st->max_bwidth <= WB)) ) + ) + { + /* inactive frames will be coded by AVQ technology */ + *coder_type = INACTIVE; + } + } + else /* st->codec_mode == MODE2 */ + { + if( !(*vad_flag) ) + { + *coder_type = INACTIVE; + } + else if( *coder_type > GENERIC ) + { + *coder_type = GENERIC; + } + } + + /*---------------------------------------------------------------* + * SC-VBR - decision about PPP/NELP mode + *---------------------------------------------------------------*/ + + if( st->Opt_SC_VBR ) + { + set_ppp_mode( st, coder_type, noisy_speech_HO, clean_speech_HO, NB_speech_HO, + *localVAD, localVAD_HE_SAD, vad_flag, pitch, *sp_aud_decision1 ); + } + + if ( !st->Opt_AMR_WB && !st->rf_mode ) + { + if ( st->total_brate == ACELP_13k20 || st->total_brate == ACELP_32k ) + { + st->mdct_sw_enable = MODE1; + } + else if ( ACELP_16k40 <= st->total_brate && st->total_brate <= ACELP_24k40 ) + { + st->mdct_sw_enable = MODE2; + } + } + + if( st->codec_mode == MODE1 ) + { + /*---------------------------------------------------------------------* + * Decision matrix (selection of technologies) + *---------------------------------------------------------------------*/ + + decision_matrix_enc( st, *sp_aud_decision1, *sp_aud_decision2, *coder_type, *vad_flag, hq_core_type ); + + /* HQ_CORE/TCX_20_CORE decision */ + if( st->core == HQ_CORE ) /* Decision matrix decided for MDCT coding */ + { + if( (st->bwidth == SWB || st->bwidth == FB) && st->total_brate == ACELP_32k ) + { + /* Select MDCT Core */ + st->core = mdct_classifier( fft_buff, st, *vad_flag, enerBuffer ); + } + if( st->total_brate == ACELP_13k20 && st->bwidth != FB ) + { + MDCT_selector( st, sp_floor, *Etot, cor_map_sum, voicing, enerBuffer, *vad_flag ); + } + } + else + { + MDCT_selector_reset( st ); + } + + /* Switch to MODE2 if TCX_20_CORE */ + if( st->core == TCX_20_CORE ) + { + st->codec_mode = MODE2; + + if ( st->last_codec_mode == MODE1 ) + { + int last_total_brate = st->last_total_brate; + st->last_total_brate = -1; + SetModeIndex( st, st->total_brate, st->bwidth ); + st->last_total_brate = last_total_brate; + } + else + { + SetModeIndex( st, st->total_brate, st->bwidth ); + + st->sr_core = getCoreSamplerateMode2( st->total_brate, st->bwidth, st->rf_mode ); + st->L_frame = st->sr_core / 50; + st->encoderLookahead_enc = NS2SA(st->sr_core, ACELP_LOOK_NS); + st->encoderPastSamples_enc = (st->L_frame*9)>>4; + + if ( st->sr_core == 12800 ) + { + st->preemph_fac = PREEMPH_FAC; + st->gamma = GAMMA1; + } + else + { + st->preemph_fac = PREEMPH_FAC_16k; + st->gamma = GAMMA16k; + } + + st->igf = getIgfPresent( st->total_brate, st->bwidth, st->rf_mode ); + } + + *coder_type = st->coder_type_raw; + + if( *vad_flag == 0 ) + { + *coder_type = INACTIVE; + } + else if( *coder_type > GENERIC ) + { + *coder_type = GENERIC; + } + + st->mdct_sw = MODE1; + } + } + + /*-----------------------------------------------------------------* + * Update of ACELP harmonicity counter (used in ACELP transform codebook @32kbps) + *-----------------------------------------------------------------*/ + + if( st->total_brate == ACELP_32k && loc_harm == 1 && cor_map_sum > 50 && + st->clas == VOICED_CLAS && *coder_type == GENERIC ) + { + st->last_harm_flag_acelp++; + + if( st->last_harm_flag_acelp > 10 ) + { + st->last_harm_flag_acelp = 10; + } + } + else + { + st->last_harm_flag_acelp = 0; + } + + /*-----------------------------------------------------------------* + * Update audio frames counter (used for UV decision) + *-----------------------------------------------------------------*/ + + if( *coder_type == AUDIO ) + { + st->audio_frame_cnt += AUDIO_COUNTER_STEP; + } + else if (*coder_type != INACTIVE) + { + st->audio_frame_cnt--; + } + + if( st->audio_frame_cnt > AUDIO_COUNTER_MAX ) + { + st->audio_frame_cnt = AUDIO_COUNTER_MAX; + } + + if( st->audio_frame_cnt < 0 ) + { + st->audio_frame_cnt = 0; + } + + /*-----------------------------------------------------------------* + * Set formant sharpening flag + *-----------------------------------------------------------------*/ + + *sharpFlag = 0; + if( *coder_type == TRANSITION ) + { + if( ( st->total_brate > ACELP_48k && st->bwidth < SWB ) || /* Deactivate for core bitrates higher than 48.0 kb/s */ + ( st->total_brate >= ACELP_13k20 && st->total_brate <= ACELP_16k40 ) || /* Deactivate for bitrates <13.2, 16.4> kb/s (this is basically due to lack of signaling configurations */ + ( st->total_brate > ACELP_16k40 && st->lp_noise > FORMANT_SHARPENING_NOISE_THRESHOLD ) ) /* Deactivate for bitrates >= 24.4 kb/s if the long-term noise level exceeds 34 dB */ + { + *sharpFlag = 0; + } + else + { + *sharpFlag = 1; + } + } + + if( *coder_type == GENERIC || *coder_type == VOICED ) + { + if( *vad_hover_flag || + ( st->total_brate > ACELP_48k && st->bwidth < SWB ) || /* Deactivate for core bitrates higher than 48.0 kb/s */ + ( st->total_brate >= ACELP_13k20 && st->lp_noise > FORMANT_SHARPENING_NOISE_THRESHOLD + && st->total_brate > CNA_MAX_BRATE) ) /* Deactivate for bitrates >= 13.2 kb/s if the long-term noise level exceeds 34 dB */ + { + *sharpFlag = 0; + } + else + { + *sharpFlag = 1; + } + } + + /* channel-aware mode - due to lack of signalling bit, sharpFlag is 1 always in RF mode */ + if( st->rf_mode && ( *coder_type == VOICED || *coder_type == GENERIC ) ) + { + *sharpFlag = 1; + } + + /*-----------------------------------------------------------------* + * Set voicing flag for HQ FEC + *-----------------------------------------------------------------*/ + + if ( *sp_aud_decision1 == 0 && ( *coder_type == VOICED || *coder_type == GENERIC ) ) + { + *Voicing_flag = 1; + } + else + { + *Voicing_flag = 0; + } + + /*---------------------------------------------------------------* + * Preprocessing at other sampling frequency rate (16/25.6/32kHz) + *----------------------------------------------------------------*/ + + sr_core_tmp = (st->codec_mode == MODE1)? 16000 : max(16000,st->sr_core); /* indicates the ACELP sampling rate */ + L_frame_tmp = (st->codec_mode == MODE1)? L_FRAME16k : max(L_FRAME16k,st->L_frame); + + L_look = NS2SA(sr_core_tmp, ACELP_LOOK_NS); /* lookahead at other sampling rate (16kHz, 25.6kHz, 32kHz) */ + + new_inp_16k = old_inp_16k + L_INP_MEM; /* pointer to new samples of the input signal in 16kHz core */ + inp_16k = new_inp_16k - L_look; /* pointer to the current frame of input signal in 16kHz core */ + mvr2r( st->old_inp_16k, old_inp_16k, L_INP_MEM ); + + /*---------------------------------------------------------------* + * Change the sampling frequency to 16/25.6/32 kHz + *----------------------------------------------------------------*/ + + if( st->input_Fs == sr_core_tmp ) + { + /* no resampling needed, only delay adjustment to account for the FIR resampling delay */ + delay = NS2SA(st->input_Fs, DELAY_FIR_RESAMPL_NS); + mvr2r( st->mem_decim16k + delay, new_inp_16k, delay ); + mvr2r( signal_in, new_inp_16k + delay, input_frame - delay ); + mvr2r( signal_in + input_frame - 2*delay, st->mem_decim16k, 2*delay ); + } + else if( st->input_Fs == 32000 || st->input_Fs == 48000 ) + { + modify_Fs( signal_in, input_frame, st->input_Fs, new_inp_16k, sr_core_tmp, st->mem_decim16k, 0 ); + } + else /* keep memories up-to-date in case of bit-rate switching */ + { + /* no resampling needed, only delay adjustment to account for the FIR resampling delay */ + delay = NS2SA(st->input_Fs, DELAY_FIR_RESAMPL_NS); + mvr2r( st->mem_decim16k + delay, new_inp_16k, delay ); + mvr2r( signal_in, new_inp_16k + delay, input_frame - delay ); + mvr2r( signal_in + input_frame - 2*delay, st->mem_decim16k, 2*delay ); + } + + if( sr_core_tmp == 16000 ) + { + /* save input resampled at 16kHz, non-preemhasised */ + mvr2r( new_inp_16k, new_inp_resamp16k, L_FRAME16k ); + } + else if( sr_core_tmp > 16000 ) + { + /* reset the buffer, the signal is needed for WB BWEs */ + set_f( new_inp_resamp16k, 0.0f, L_FRAME16k ); + } + + /*------------------------------------------------------------------* + * Perform fixed preemphasis (16kHz signal) through 1 - g*z^-1 + *-----------------------------------------------------------------*/ + + if( (st->tcxonly == 0 || st->codec_mode == MODE1) && st->input_Fs > 8000 ) + { + st->mem_preemph_enc = new_inp_16k[L_frame_tmp-1]; + } + + if( st->input_Fs > 8000 && sr_core_tmp == 16000 ) + { + preemph( new_inp_16k, PREEMPH_FAC_16k, L_FRAME16k, &(st->mem_preemph16k) ); + } + else if( st->input_Fs > 8000 ) /* keep memory up-to-date in case of bit-rate switching */ + { + st->mem_preemph16k = new_inp_16k[L_frame_tmp-1]; + } + + /*-----------------------------------------------------------------* + * Redo LP analysis at 16kHz if ACELP@16k core was selected + * update buffers + *-----------------------------------------------------------------*/ + + if( ( ((st->tcxonly == 0) || !(st->core_brate != FRAME__NO_DATA || st->core_brate != SID_2k40)) && st->L_frame == L_FRAME16k && st->codec_mode == MODE2 ) || + ( st->L_frame == L_FRAME16k && st->codec_mode == MODE1 ) ) + { + /* update signal buffers */ + mvr2r( new_inp_resamp16k, st->buf_speech_enc+L_FRAME16k, L_FRAME16k ); + mvr2r( new_inp_16k, st->buf_speech_enc_pe+L_FRAME16k, L_FRAME16k ); + + /*--------------------------------------------------------------* + * LPC analysis + *---------------------------------------------------------------*/ + + if( st->last_L_frame == L_FRAME && st->codec_mode == MODE1 ) + { + /* this is just an approximation, but it is sufficient */ + mvr2r( st->lsp_old1, st->lspold_enc, M ); + } + + analy_lp( inp_16k, L_FRAME16k, L_look, ener, A, epsP, lsp_new, lsp_mid, st->lspold_enc, pitch, voicing, 16000 ); + + /*--------------------------------------------------------------* + * Compute Weighted Input + *---------------------------------------------------------------*/ + + if( st->codec_mode == MODE2 ) + { + find_wsp( L_FRAME16k, L_SUBFR, st->nb_subfr, A, Aw, st->speech_enc_pe, PREEMPH_FAC_16k, st->wspeech_enc, &st->mem_wsp_enc, st->gamma, L_LOOK_16k ); + } + else + { + weight_a_subfr( NB_SUBFR16k, A, Aw, GAMMA16k, M ); + } + + } + else + { + /* update signal buffers */ + mvr2r( new_inp_12k8, st->buf_speech_enc_pe+st->L_frame, L_FRAME ); + mvr2r( st->buf_speech_enc+L_FRAME32k, st->buf_speech_enc+st->L_frame, L_FRAME ); + + if( st->tcxonly == 0 ) + { + mvr2r( wsp, st->wspeech_enc, L_FRAME + L_LOOK_12k8 ); + } + } + + /*-----------------------------------------------------------------* + * ACELP/TCX20 Switching Decision + *-----------------------------------------------------------------*/ + + if( st->codec_mode == MODE2 ) + { + if( st->core_brate != FRAME__NO_DATA && st->core_brate != SID_2k40 && st->tcxonly == 0 ) + { + core_acelp_tcx20_switching( st, *vad_flag, sp_aud_decision0, non_staX, pitch, pitch_fr, + voicing_fr, currFlatness, lsp_mid, stab_fac ); + } + + if( st->mdct_sw_enable == MODE2 && !st->rf_mode ) + { + if (st->core == TCX_20_CORE) /* Switching only possible from TCX_20 frames, not from TCX_10 frames */ + { + /* Select MDCT Core */ + if( (st->bwidth == SWB || st->bwidth == FB) && st->total_brate == ACELP_24k40 ) + { + st->core = mdct_classifier( fft_buff, st, *vad_flag, enerBuffer ); + } + + if( st->total_brate == ACELP_16k40 && st->bwidth != FB ) + { + MDCT_selector( st, sp_floor, *Etot, cor_map_sum, voicing, enerBuffer, *vad_flag ); + } + } + else + { + MDCT_selector_reset( st ); + } + + /* Do the switching that was decided in the MDCT selector */ + if( st->core == HQ_CORE ) + { + st->codec_mode = MODE1; + st->mdct_sw = MODE2; + } + else if( st->last_codec_mode == MODE1 && st->last_core == HQ_CORE ) + { + int L_frame_old = st->last_L_frame; + st->last_L_frame = st->L_frame; + SetModeIndex( st, st->total_brate, st->bwidth ); + st->last_L_frame = L_frame_old; + } + } + + /*--------------------------------------------------------------* + * TCX mode decision + *---------------------------------------------------------------*/ + + SetTCXModeInfo( st, &st->transientDetection, &st->tcx_cfg.tcx_curr_overlap_mode ); + } + + /*-----------------------------------------------------------------* + * Updates + *-----------------------------------------------------------------*/ + + /* update old weighted speech buffer - for OL pitch analysis */ + mvr2r( &old_wsp[L_FRAME], st->old_wsp, L_WSP_MEM ); + + /* update old input signal buffer */ + mvr2r( &old_inp_12k8[L_FRAME], st->old_inp_12k8, L_INP_MEM ); + + /* update old input signal @16kHz buffer */ + if( st->input_Fs > 8000 && sr_core_tmp == 16000 ) + { + mvr2r( &old_inp_16k[L_frame_tmp], st->old_inp_16k, L_INP_MEM ); + } + else if( st->input_Fs > 8000 ) + { + lerp( st->old_inp_12k8+L_INP_MEM-L_INP_MEM*4/5, st->old_inp_16k, L_INP_MEM, L_INP_MEM*4/5 ); + } + + if( (sr_core_tmp == 16000) && st->tcxonly && st->codec_mode == MODE2 ) + { + /* copy input resampled at 16kHz, non-preemhasised */ + mvr2r( new_inp_resamp16k, new_inp_16k, L_FRAME16k ); + } + + /* update of old per-band energy spectrum */ + mvr2r( fr_bands + NB_BANDS, st->enrO, NB_BANDS ); + + /* set the pointer of the current frame for the ACELP core */ + if ( st->L_frame == L_FRAME ) + { + *inp = inp_12k8; + } + else + { + *inp = inp_16k; + } + + + return; +} diff --git a/src/libs/libevs/lib_enc/pre_proc_fx.cpp b/src/libs/libevs/lib_enc/pre_proc_fx.cpp deleted file mode 100755 index b379f53e..00000000 --- a/src/libs/libevs/lib_enc/pre_proc_fx.cpp +++ /dev/null @@ -1,1260 +0,0 @@ -/*==================================================================================== - EVS Codec 3GPP TS26.442 Apr 03, 2018. Version 12.11.0 / 13.6.0 / 14.2.0 - ====================================================================================*/ - -#include -#include -#include "options.h" -#include "cnst_fx.h" -#include "rom_com_fx.h" -#include "prot_fx.h" -#include "stl.h" - -/*-------------------------------------------------------------------* - * pre_proc() - * - * Pre-processing (spectral analysis, LP analysis, VAD, - * OL pitch calculation, coder mode selection, ...) - *--------------------------------------------------------------------*/ - -void pre_proc_fx( - Encoder_State_fx *st, /* i/o: encoder state structure */ - const Word16 input_frame, /* i : frame length */ - const Word16 signal_in[], /* i : new samples */ - Word16 old_inp_12k8[], /* i/o: buffer of old input signal */ - Word16 old_inp_16k[], /* i/o: buffer of old input signal @ 16kHz */ - Word16 **inp, /* o : ptr. to inp. signal in the current frame */ - Word16 *sp_aud_decision1, /* o : 1st stage speech/music classification */ - Word16 *sp_aud_decision2, /* o : 2nd stage speech/music classification */ - Word32 fr_bands[2*NB_BANDS], /* o : energy in frequency bands */ - Word16 *vad_flag, - Word16 *localVAD, - Word16 *Etot, /* o : total energy */ - Word32 *ener, /* o : residual energy from Levinson-Durbin */ - Word16 pitch[3], /* o : open-loop pitch values for quantiz. */ - Word16 voicing[3], /* o : OL maximum normalized correlation */ - Word16 A[NB_SUBFR16k*(M+1)], /* o : A(z) unquantized for the 4 subframes */ - Word16 Aw[NB_SUBFR16k*(M+1)], /* o : weighted A(z) unquantized for subframes */ - Word16 epsP_h[M+1], /* o : LP prediction errors */ - Word16 epsP_l[M+1], /* o : LP prediction errors */ - Word32 epsP[M+1], /* o : LP prediction errors */ - Word16 lsp_new[M], /* o : LSPs at the end of the frame */ - Word16 lsp_mid[M], /* o : LSPs in the middle of the frame */ - Word16 *coder_type, /* o : coder type */ - Word16 *sharpFlag, /* o : formant sharpening flag */ - Word16 *vad_hover_flag, - Word16 *attack_flag, /* o : flag signalling attack encoded by AC mode (GSC) */ - Word16 *new_inp_resamp16k, /* o : new input signal @16kHz, non pre-emphasised, used by the WB TBE/BWE */ - Word16 *Voicing_flag, /* o : voicing flag for HQ FEC */ - - Word32 realBuffer[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX], /* o : cldfb real buffer */ - Word32 imagBuffer[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX], /* o : cldfb imag buffer */ - CLDFB_SCALE_FACTOR *cldfbScale, /* o : cldfb scale*/ - Word16 *old_exc, - Word16 *hq_core_type, /* o : HQ core type */ - Word16 *Q_new, - Word16 *shift, - Word16 *Q_r -) -{ - Word16 delay; - Word16 i; - Word16 *inp_12k8, *new_inp_12k8, *inp_16k, *new_inp_16k; /* pointers to current frame and new data */ - Word16 old_wsp[L_WSP], *wsp; /* weighted input signal buffer */ - Word16 pitch_fr[NB_SUBFR]; /* fractional pitch values */ - Word16 voicing_fr[NB_SUBFR]; /* fractional pitch gains */ - Word32 lf_E[2*VOIC_BINS]; /* per bin spectrum energy in lf */ - Word32 tmpN[NB_BANDS]; /* Temporary noise update */ - Word32 tmpE[NB_BANDS]; /* Temporary averaged energy of 2 sf. */ - Word32 ee[2]; /* Spectral tilt */ - Word16 corr_shift; /* correlation shift */ - Word16 relE; /* frame relative energy */ - Word16 loc_harm; /* harmonicity flag */ - Word16 cor_map_sum, sp_div; /* speech/music clasif. parameters */ - Word32 PS[128]; - Word16 L_look; /* length of look-ahead */ - - Word16 Q_sp_div, Q_esp; - Word16 localVAD_HE_SAD; /* HE SAD parameters */ - Word16 snr_sum_he; /* HE SAD parameters */ - - Word16 vad_flag_cldfb; - - Word16 vad_flag_dtx; - Word16 old_cor; - Word16 uc_clas; - Word32 hp_E[2]; /* Energy in HF */ - Word16 noisy_speech_HO, clean_speech_HO, NB_speech_HO; /* SC-VBR HO flags */ - Word16 non_staX; /* unbound non-stationarity for sp/mus clas. */ - Word32 sr_core_tmp; - Word16 L_frame_tmp; - Word16 Q_exp, Q_wsp_exp, Q_new_16k; - Word16 shift_exp; - Word16 Scale_fac[2]; - Word32 Le_min_scaled; - Word16 excitation_max_test; - Word16 lsf_new[M], stab_fac; - Word32 enerBuffer[CLDFB_NO_CHANNELS_MAX]; - Word16 enerBuffer_exp; /*[CLDFB_NO_CHANNELS_MAX];*/ - Word16 realBuffer16[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX]; - Word16 imagBuffer16[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX]; - Word16 tmp_e; - Word16 currFlatness; - Word16 high_lpn_flag; - Word16 cldfb_addition = add(0, 0); - Word16 alw_pitch_lag_12k8[2]; - Word16 alw_voicing[2]; - Word16 flag_spitch; - Word16 sf_energySum[CLDFB_NO_CHANNELS_MAX]; - Word32 L_tmp; - UWord16 lsb; - Word16 fft_buff[2*L_FFT]; - Word16 sp_floor; - Word16 freqTable[2] = {20, 40}; - Word16 sp_aud_decision0; - Word16 last_core_orig; - Word16 headroom; - - /*------------------------------------------------------------------* - * Initializations - *------------------------------------------------------------------*/ - - vad_flag_dtx = 0; - move16(); - localVAD_HE_SAD = 0; - move16(); - NB_speech_HO = 0; - move16(); - clean_speech_HO = 0; - move16(); - noisy_speech_HO = 0; - move16(); - snr_sum_he = 0; - move16(); - currFlatness = 0; - move16(); - - Q_new_16k = 0; - move16(); - - *vad_hover_flag = 0; - move16(); - uc_clas = VOICED_CLAS; - move16(); - *sp_aud_decision1 = 0; - move16(); - *sp_aud_decision2 = 0; - move16(); - *coder_type = GENERIC; - move16(); - st->noise_lev_fx = NOISE_LEVEL_SP0; - move16(); - *attack_flag = 0; - move16(); - - st->bump_up_fx = 0; - move16(); - st->ppp_mode_fx = 0; - move16(); - st->nelp_mode_fx = 0; - move16(); - st->avoid_HQ_VBR_NB = 0; - move16(); - - L_look = L_LOOK_12k8; - move16(); /* lookahead at 12.8kHz */ - - new_inp_12k8 = old_inp_12k8 + L_INP_MEM; /* pointer to new samples of the input signal in 12.8kHz core */ - inp_12k8 = new_inp_12k8 - L_look; /* pointer to the current frame of input signal in 12.8kHz core */ - Copy( st->old_inp_12k8_fx, old_inp_12k8, L_INP_MEM ); - - Copy( st->old_wsp_fx, old_wsp, L_WSP_MEM ); - wsp = old_wsp + L_WSP_MEM; /* pointer to the current frame of weighted signal in 12.8kHz core */ - - old_cor = st->old_corr_fx; - move16(); /* save old_cor for speech/music classifier */ - - st->rf_mode = st->Opt_RF_ON; - move16(); - - last_core_orig = st->last_core_fx; - move16(); - - /*--------------------------------------------------------------* - * Cldfb analysis - *---------------------------------------------------------------*/ - - move32(); - move16(); - st->prevEnergyHF_fx = st->currEnergyHF_fx; - tmp_e = st->currEnergyHF_e_fx; - - analysisCldfbEncoder_fx( st, signal_in, realBuffer, imagBuffer, realBuffer16, imagBuffer16, enerBuffer, &enerBuffer_exp, cldfbScale); - cldfbScale->hb_scale = cldfbScale->lb_scale; - - /*----------------------------------------------------------------* - * Change the sampling frequency to 12.8 kHz - *----------------------------------------------------------------*/ - - modify_Fs_fx( signal_in, input_frame, st->input_Fs_fx, new_inp_12k8, 12800, st->mem_decim_fx, (sub(st->max_bwidth_fx,NB) == 0) ); - Copy( new_inp_12k8, st->buf_speech_enc+L_FRAME32k, L_FRAME ); - Scale_sig( st->buf_speech_enc+L_FRAME32k, L_FRAME, 1 ); - /*------------------------------------------------------------------* - * Perform fixed preemphasis (12.8 kHz signal) through 1 - g*z^-1 - *-----------------------------------------------------------------*/ - - /* rf_mode: first time Q_new is computed here inside Preemph_scaled() for primary copy - these are the same memories used in partial frame assembly as well */ - - headroom = 1; - move16(); - test(); - test(); - /* reserve an extra bit of headroom in case of NB coding and if there is a chance of energy above 4 kHz */ - /* st->bwidth_fx refers to the coded bandwidth of the previous frame */ - if( ((sub(st->bwidth_fx, NB) == 0) || (sub(st->max_bwidth_fx, NB) == 0)) && (L_sub(st->input_Fs_fx, 8000) > 0) ) - { - headroom = add(headroom, 1); - } - Preemph_scaled( new_inp_12k8, Q_new, &st->mem_preemph_fx, st->Q_max, - PREEMPH_FAC, 0, headroom, L_Q_MEM, L_FRAME, st->last_coder_type_fx, 1 ); - - Q_exp = sub(*Q_new, st->Q_old); - st->prev_Q_old=st->Q_old; - move16(); - st->Q_old = *Q_new; - move16(); - - /*------------------------------------------------------------------* - * Scaling of memories - *-----------------------------------------------------------------*/ - - Le_min_scaled = Scale_mem_pre_proc( st->ini_frame_fx, Q_exp, Q_new, old_inp_12k8, &(st->mem_wsp_fx), st->enrO_fx, st->bckr_fx, - st->ave_enr_fx, st->ave_enr2_fx, st->fr_bands1_fx, st->fr_bands2_fx, st->Bin_E_old_fx ); - - /*-------------------------------------------------------------------------* - * Spectral analysis - *--------------------------------------------------------------------------*/ - - analy_sp( inp_12k8, *Q_new, fr_bands, lf_E, Etot, st->min_band_fx, st->max_band_fx, Le_min_scaled, Scale_fac, st->Bin_E_fx, st->Bin_E_old_fx, - PS, st->lgBin_E_fx, st->band_energies, fft_buff ); - - st->band_energies_exp = sub(sub(WORD32_BITS-1,*Q_new),QSCALE); - move16(); - - /*----------------------------------------------------------------* - * SAD (1-signal, 0-noise) - *----------------------------------------------------------------*/ - - noise_est_pre_fx( *Etot, st->ini_frame_fx, &st->Etot_l_fx, &st->Etot_h_fx, &st->Etot_l_lp_fx, &st->Etot_last_fx, - &st->Etot_v_h2_fx, &st->sign_dyn_lp_fx, st->harm_cor_cnt_fx, &st->Etot_lp_fx ); - - *vad_flag = wb_vad_fx( st, fr_bands, localVAD, &noisy_speech_HO, &clean_speech_HO, &NB_speech_HO, - &snr_sum_he, &localVAD_HE_SAD, &(st->flag_noisy_speech_snr), *Q_new ); - - vad_flag_cldfb = vad_proc( &(st->vad_st),realBuffer, imagBuffer, cldfbScale->lb_scale, &cldfb_addition, - enerBuffer, enerBuffer_exp,st->cldfbAna_Fx->no_channels, *vad_flag ); - - /* Combine decisions from SADS */ - test(); - if( *vad_flag != 0 && vad_flag_cldfb == 0 ) - { - *localVAD = 0; - move16(); - } - - *vad_flag = vad_flag_cldfb; - move16(); - - /* apply DTX hangover for CNG analysis */ - vad_flag_dtx = dtx_hangover_addition_fx( st, *localVAD, *vad_flag, sub(st->lp_speech_fx,st->lp_noise_fx), cldfb_addition, vad_hover_flag ); - - /*----------------------------------------------------------------* - * NB/WB/SWB/FB bandwidth detector - *----------------------------------------------------------------*/ - - FOR( i=0; i< CLDFB_NO_CHANNELS_MAX; i++ ) - { - sf_energySum[i] = enerBuffer_exp; - move16(); - } - - bw_detect_fx( st, signal_in, *localVAD, enerBuffer, sf_energySum ); - - /*----------------------------------------------------------------* - * Noise energy down-ward update and total noise energy estimation - * Long-term energies and relative frame energy updates - * Correlation correction as a function of total noise level - *----------------------------------------------------------------*/ - - noise_est_down_fx( fr_bands, st->bckr_fx, tmpN, tmpE, st->min_band_fx, st->max_band_fx, &st->totalNoise_fx, - *Etot, &st->Etot_last_fx, &st->Etot_v_h2_fx, *Q_new , Le_min_scaled ); - - relE = sub(*Etot, st->lp_speech_fx); /* Q8 */ /* relE = *Etot - st->lp_speech;*/ - corr_shift = correlation_shift_fx( st->totalNoise_fx ); - - /*----------------------------------------------------------------* - * FD-CNG Noise Estimator - *----------------------------------------------------------------*/ - - resetFdCngEnc ( st ); - perform_noise_estimation_enc ( st->band_energies, st->band_energies_exp, enerBuffer, enerBuffer_exp, st->hFdCngEnc_fx ); - - /*-----------------------------------------------------------------* - * Select SID or FRAME_NO_DATA frame if DTX enabled - *-----------------------------------------------------------------*/ - - dtx_fx(st, vad_flag_dtx, inp_12k8, *Q_new); - - /*----------------------------------------------------------------* - * Adjust FD-CNG Noise Estimator - *----------------------------------------------------------------*/ - test(); - IF( (L_sub(st->last_total_brate_fx,st->total_brate_fx) != 0) || (sub(st->last_bwidth_fx,st->bwidth_fx) != 0) ) - { - L_tmp = st->total_brate_fx; - move32(); - test(); - if( st->rf_mode && L_sub(st->total_brate_fx,ACELP_13k20) == 0 ) - { - L_tmp = ACELP_9k60; - move32(); - } - configureFdCngEnc( st->hFdCngEnc_fx, st->bwidth_fx, L_tmp ); - } - test(); - IF ( st->hFdCngEnc_fx!=NULL && st->Opt_DTX_ON_fx ) - { - AdjustFirstSID( st->hFdCngEnc_fx->hFdCngCom->npart, st->hFdCngEnc_fx->msPeriodog, st->hFdCngEnc_fx->msPeriodog_exp, st->hFdCngEnc_fx->energy_ho, - &st->hFdCngEnc_fx->energy_ho_exp,st->hFdCngEnc_fx->msNoiseEst, &st->hFdCngEnc_fx->msNoiseEst_exp, st->hFdCngEnc_fx->msNoiseEst_old, - &st->hFdCngEnc_fx->msNoiseEst_old_exp, &(st->hFdCngEnc_fx->hFdCngCom->active_frame_counter), st ); - } - - /*----------------------------------------------------------------* - * Reconfigure MODE2 - *----------------------------------------------------------------*/ - - IF ( sub(st->codec_mode,MODE2) == 0 ) - { - SetModeIndex( st, st->total_brate_fx, st->bwidth_fx, *shift); - } - - calcLoEnvCheckCorrHiLo_Fix( st->cldfbAna_Fx->no_col, freqTable, (st->tecEnc).loBuffer, (st->tecEnc).loTempEnv, - (st->tecEnc).loTempEnv_ns, (st->tecEnc).hiTempEnv, &((st->tecEnc).corrFlag) ); - - /*---------------------------------------------------------------* - * Time-domain transient detector - *---------------------------------------------------------------*/ - - /* Adjust prevEnergyHF and currEnergyHF to same exponent */ - i = sub(st->currEnergyHF_e_fx, tmp_e); - - /* If i > 0: currEnergyHF is higher => shr prevEnergyHF, exponent remains as is */ - st->prevEnergyHF_fx = L_shr(st->prevEnergyHF_fx, s_max(0, i)); - move32(); - - /* If i < 0: currEnergyHF is lower => shr currEnergyHF, exponent changes to previous */ - st->currEnergyHF_fx = L_shl(st->currEnergyHF_fx, s_min(0, i)); - move32(); - - if ( i < 0 ) - { - st->currEnergyHF_e_fx = tmp_e; - move16(); - } - - test(); - IF( st->tcx10Enabled || st->tcx20Enabled ) - { - RunTransientDetection( signal_in, input_frame, &st->transientDetection); - currFlatness = GetTCXAvgTemporalFlatnessMeasure( &st->transientDetection, NSUBBLOCKS, 0 ); - } - - /*----------------------------------------------------------------* - * LP analysis - *----------------------------------------------------------------*/ - - alw_pitch_lag_12k8[0] = st->old_pitch_la; - move16(); - alw_pitch_lag_12k8[1] = st->old_pitch_la; - move16(); - alw_voicing[0] = st->old_voicing_la; - move16(); - alw_voicing[1] = st->old_voicing_la; - move16(); - - analy_lp_fx( inp_12k8, L_FRAME, L_look, ener, A, epsP_h, epsP_l, lsp_new, lsp_mid, st->lsp_old1_fx, alw_pitch_lag_12k8, alw_voicing, 12800, *Q_new, Q_r ); - - lsp2lsf_fx( lsp_new, lsf_new, M, INT_FS_FX ); - stab_fac = lsf_stab_fx( lsf_new, st->lsf_old1_fx, 0, L_FRAME ); - Copy( lsf_new, st->lsf_old1_fx, M ); - - /*----------------------------------------------------------------* - * Compute weighted input (for OL pitch analysis) - * OL pitch analysis - * 1/4 pitch precision improvement - *----------------------------------------------------------------*/ - - find_wsp( A, inp_12k8, wsp, &st->mem_wsp_fx, TILT_FAC_FX, L_FRAME, L_look, L_SUBFR, Aw, GAMMA1, NB_SUBFR ); - - Q_wsp_exp = Q_exp; - move16(); - Scale_wsp( wsp, &(st->old_wsp_max), shift, &Q_wsp_exp, &(st->old_wsp_shift), st->old_wsp2_fx, - st->mem_decim2_fx, old_wsp, add(L_FRAME, L_look) ); - shift_exp=sub(Q_wsp_exp, Q_exp); - - IF( *vad_flag == 0 ) - { - /* reset the OL pitch tracker memories during inactive frames */ - pitch_ol_init_fx( &st->old_thres_fx, &st->old_pitch, &st->delta_pit_fx, &st->old_corr_fx) ; - } - - pitch_ol_fx( pitch, voicing, &st->old_pitch, &st->old_corr_fx, corr_shift, &st->old_thres_fx, - &st->delta_pit_fx, st->old_wsp2_fx, wsp, st->mem_decim2_fx, relE, st->clas_fx, st->bwidth_fx, st->Opt_SC_VBR_fx ); - - /* Updates for adaptive lag window memory */ - st->old_pitch_la = pitch[2]; - move16(); - st->old_voicing_la = voicing[2]; - move16(); - - /* Detection of very short stable pitch period (MODE1 bit-rates) */ - StableHighPitchDetect_fx( &flag_spitch, pitch, voicing, wsp, *localVAD, &st->voicing_sm_fx, &st->voicing0_sm_fx, - &st->LF_EnergyRatio_sm_fx, &st->predecision_flag_fx, &st->diff_sm_fx, &st->energy_sm_fx,*Q_new,st->lgBin_E_fx); - - /* 1/4 pitch precision improvement */ - IF( L_sub(st->total_brate_fx,ACELP_24k40) <= 0 ) - { - /* 1/4 pitch precision improvement */ - pitch_ol2_fx( PIT_MIN_EXTEND, pitch[0], &pitch_fr[0], &voicing_fr[0], 0, wsp, 7 ); - pitch_ol2_fx( PIT_MIN_EXTEND, pitch[0], &pitch_fr[1], &voicing_fr[1], L_SUBFR, wsp, 7 ); - pitch_ol2_fx( PIT_MIN_EXTEND, pitch[1], &pitch_fr[2], &voicing_fr[2], 2*L_SUBFR, wsp, 7 ); - pitch_ol2_fx( PIT_MIN_EXTEND, pitch[1], &pitch_fr[3], &voicing_fr[3], 3*L_SUBFR, wsp, 7 ); - } - ELSE - { - pitch_fr[0] = pitch[0]; - move16(); - pitch_fr[1] = pitch[0]; - move16(); - pitch_fr[2] = pitch[1]; - move16(); - pitch_fr[3] = pitch[1]; - move16(); - - voicing_fr[0] = voicing[0]; - move16(); - voicing_fr[1] = voicing[0]; - move16(); - voicing_fr[2] = voicing[1]; - move16(); - voicing_fr[3] = voicing[1]; - move16(); - } - - /*------------------------------------------------------------------* - * Update estimated noise energy and voicing cut-off frequency - *-----------------------------------------------------------------*/ - - noise_est_fx( st, tmpN, pitch, voicing, epsP_h,epsP_l, *Etot, relE, corr_shift, tmpE, fr_bands, &cor_map_sum, - &sp_div, &Q_sp_div, &non_staX , &loc_harm, lf_E, &st->harm_cor_cnt_fx ,st->Etot_l_lp_fx, - st->Etot_v_h2_fx ,&st->bg_cnt_fx, st->lgBin_E_fx,*Q_new, Le_min_scaled, &sp_floor ); - - /*------------------------------------------------------------------* - * Update parameters used in the VAD and DTX - *-----------------------------------------------------------------*/ - - vad_param_updt_fx( st, pitch, voicing, corr_shift, *vad_flag, A ); - - /*-----------------------------------------------------------------* - * Find spectral tilt - * UC and VC frame selection - *-----------------------------------------------------------------*/ - - find_tilt_fx( fr_bands, st->bckr_fx, ee, pitch, voicing, lf_E, corr_shift, st->input_bwidth_fx, - st->max_band_fx, hp_E, st->codec_mode, *Q_new, &(st->bckr_tilt_lt), st->Opt_SC_VBR_fx ); - - *coder_type = find_uv_fx( st, pitch_fr, voicing_fr, voicing, inp_12k8, *localVAD, ee, corr_shift, - relE, *Etot, hp_E, *Q_new, &flag_spitch, st->voicing_sm_fx, *shift, last_core_orig ); - - /*----------------------------------------------------------------* - * channel aware mode configuration * - *-----------------------------------------------------------------*/ - test(); - test(); - test(); - IF( !st->Opt_RF_ON) - { - st->rf_mode = 0; - st->rf_target_bits_write = 0; - } - ELSE IF( st->rf_mode && L_sub(st->core_brate_fx,FRAME_NO_DATA) != 0 && L_sub(st->core_brate_fx,SID_2k40) != 0 ) - { - /* the RF config is for (n- fec_offset)th frame that will be packed along with the n-th frame bistream */ - st->rf_mode = 1; - st->codec_mode = MODE2; - - st->rf_target_bits_write = st->rf_targetbits_buff[st->rf_fec_offset]; - } - ELSE - { - st->rf_mode = 0; - st->codec_mode = MODE1; - st->rf_indx_frametype[0] = RF_NO_DATA; - st->rf_targetbits_buff[0] = 6; /* rf_mode: 1, rf_frame_type: 3, and fec_offset: 2 */ - } - - /*-----------------------------------------------------------------* - * Signal classification for FEC - * TC frame selection - *-----------------------------------------------------------------*/ - - st->clas_fx = signal_clas_fx( st, coder_type, voicing, inp_12k8, *localVAD, pitch, ee, relE, L_look, &uc_clas); - - st->Local_VAD = *localVAD; - - /*----------------------------------------------------------------* - * Speech/music classification - * AC frame selection - *----------------------------------------------------------------*/ - - FOR( i=0; iOpt_DTX_ON_fx ) - { - *vad_flag = vad_flag_dtx; - move16(); /* flag now with the DTX-HO for use in further high rate encoding below */ - } - - /*----------------------------------------------------------------* - * Selection of internal ACELP Fs (12.8 kHz or 16 kHz) - *----------------------------------------------------------------*/ - - IF( sub(st->codec_mode,MODE1) == 0 ) - { - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - IF( L_sub(st->core_brate_fx,FRAME_NO_DATA) == 0 ) - { - /* prevent "L_frame" changes in CNG segments */ - st->L_frame_fx = st->last_L_frame_fx; - move16(); - } - ELSE IF ( L_sub(st->core_brate_fx,SID_2k40) == 0 && sub(st->bwidth_fx, WB) >= 0 && st->first_CNG_fx && sub(st->act_cnt2_fx,MIN_ACT_CNG_UPD) < 0 ) - { - /* prevent "L_frame" changes in SID frame after short segment of active frames */ - st->L_frame_fx = st->last_CNG_L_frame_fx; - move16(); - } - ELSE IF ( ( L_sub(st->core_brate_fx,SID_2k40) == 0 && L_sub(st->total_brate_fx,ACELP_9k60) >= 0 && ((sub(st->bwidth_fx,WB) == 0 && !( L_sub(st->total_brate_fx,ACELP_13k20) == 0 && sub(st->cng_type_fx,FD_CNG) == 0)) || (sub(st->cng_type_fx,LP_CNG) == 0 && sub(st->bwidth_fx,WB) > 0 && L_sub(st->total_brate_fx,ACELP_16k40) >= 0)) ) || - ( L_sub(st->total_brate_fx,ACELP_24k40) > 0 && L_sub(st->total_brate_fx,HQ_96k) < 0 ) || ( L_sub(st->total_brate_fx,ACELP_24k40) == 0 && sub(st->bwidth_fx,WB) >= 0 ) ) - { - st->L_frame_fx = L_FRAME16k; - move16(); - } - ELSE - { - st->L_frame_fx = L_FRAME; - move16(); - } - - if( st->ini_frame_fx == 0 ) - { - /* avoid switching of internal ACELP Fs in the very first frame */ - st->last_L_frame_fx = st->L_frame_fx; - move16(); - } - - IF( sub(st->L_frame_fx,L_FRAME) == 0 ) - { - st->gamma = GAMMA1; - move16(); - st->preemph_fac = PREEMPH_FAC; - move16(); - } - ELSE - { - st->gamma = GAMMA16k; - move16(); - st->preemph_fac = PREEMPH_FAC_16k; - move16(); - } - - st->sr_core = L_mult0(50,st->L_frame_fx); - st->encoderLookahead_enc = NS2SA_fx2(st->sr_core, ACELP_LOOK_NS); - move16(); - st->encoderPastSamples_enc = shr(imult1616(st->L_frame_fx, 9), 4); - } - - /*-----------------------------------------------------------------* - * coder_type rewriting in case of switching - * IC frames selection - * enforce TC frames in case of switching - *-----------------------------------------------------------------*/ - - IF( sub(st->codec_mode,MODE1) == 0 ) - { - /* enforce TRANSITION frames */ - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - IF( sub(st->last_L_frame_fx,st->L_frame_fx) != 0 && L_sub(st->core_brate_fx,FRAME_NO_DATA) != 0 && L_sub(st->core_brate_fx,SID_2k40) != 0 && (sub(st->coder_type_raw_fx,VOICED) != 0) ) - { - /* enforce TC frame in case of ACELP@12k8 <-> ACELP@16k core switching */ - *coder_type = TRANSITION; - move16(); - } - ELSE IF( sub(st->last_core_fx,HQ_CORE) == 0 || sub(st->last_core_fx,TCX_10_CORE) == 0 || sub(st->last_core_fx,TCX_20_CORE) == 0 ) - { - /* enforce TC frame in case of HQ/TCX -> ACELP core switching */ - *coder_type = TRANSITION; - move16(); - } - ELSE IF( L_sub(st->last_core_brate_fx,SID_2k40) <= 0 && sub(st->cng_type_fx,FD_CNG) == 0 ) - { - /* enforce TC frame in case of FD_CNG -> ACELP switching (past excitation not available) */ - *coder_type = TRANSITION; - move16(); - } - - /* select INACTIVE frames */ - ELSE IF( L_sub(st->total_brate_fx,ACELP_24k40) <= 0 && *vad_flag == 0 ) - { - /* inactive frames will be coded by GSC technology */ - /* except for the VBR mode. VBR mode uses NELP for that */ - test(); - IF ( !( sub(st->Opt_SC_VBR_fx, 1) == 0 && sub(vad_flag_dtx, 1 ) == 0 ) ) - { - *coder_type = INACTIVE; - move16(); - st->noise_lev_fx = NOISE_LEVEL_SP3; - move16(); - } - } - ELSE IF( L_sub(st->total_brate_fx,ACELP_24k40) > 0 && - ( (*vad_flag == 0 && sub(st->bwidth_fx,SWB) >= 0 && sub(st->max_bwidth_fx,SWB) >= 0) || (*localVAD == 0 && (sub(st->bwidth_fx,WB) <= 0 || sub(st->max_bwidth_fx,WB) <= 0)) ) - ) - { - /* inactive frames will be coded by AVQ technology */ - *coder_type = INACTIVE; - move16(); - } - } - ELSE - { - IF( !(*vad_flag) ) - { - *coder_type = INACTIVE; - move16(); - } - ELSE IF( sub(*coder_type,GENERIC) > 0 ) - { - *coder_type = GENERIC; - move16(); - } - } - - /*---------------------------------------------------------------* - * SC-VBR - decision about PPP/NELP mode - *---------------------------------------------------------------*/ - - IF( st->Opt_SC_VBR_fx ) - { - set_ppp_mode_fx( st, coder_type, noisy_speech_HO, clean_speech_HO, NB_speech_HO, *localVAD, localVAD_HE_SAD, vad_flag, pitch, *sp_aud_decision1 ); - } - test(); - IF ( !st->Opt_AMR_WB_fx && !st->rf_mode ) - { - test(); - test(); - IF ( L_sub(st->total_brate_fx,ACELP_13k20) == 0 || L_sub(st->total_brate_fx,ACELP_32k) == 0 ) - { - st->mdct_sw_enable = MODE1; - move16(); - } - ELSE IF ( L_sub(ACELP_16k40,st->total_brate_fx) <= 0 && L_sub(st->total_brate_fx,ACELP_24k40) <= 0) - { - st->mdct_sw_enable = MODE2; - move16(); - } - } - - IF( sub(st->codec_mode,MODE1) == 0 ) - { - /*---------------------------------------------------------------------* - * Decision matrix (selection of technologies) - *---------------------------------------------------------------------*/ - - decision_matrix_enc_fx( st, *sp_aud_decision1, *sp_aud_decision2, *coder_type, *vad_flag, hq_core_type ); - - /* HQ_CORE/TCX_20_CORE decision */ - IF ( sub(st->core_fx,HQ_CORE) == 0 ) /* Decision matrix decided for MDCT coding */ - { - test(); - test(); - IF( (sub(st->bwidth_fx,SWB) == 0 || sub(st->bwidth_fx,FB) == 0) && L_sub(st->total_brate_fx,32000) == 0 ) - { - /* Select MDCT Core */ - st->core_fx = mdct_classifier_fx(fft_buff,st,*vad_flag, enerBuffer - ,sub(enerBuffer_exp, 31) - ); - } - test(); - IF( (L_sub(st->total_brate_fx,13200) == 0) && (sub(st->bwidth_fx,FB) != 0 )) - { - MDCT_selector( st, sp_floor, *Etot, cor_map_sum, voicing, enerBuffer, enerBuffer_exp, *vad_flag ); - } - } - ELSE - { - MDCT_selector_reset( st ); - } - - /* Switch to MODE2 if TCX_20_CORE */ - IF( sub(st->core_fx,TCX_20_CORE) == 0 ) - { - st->codec_mode = MODE2; - move16(); - IF( sub(st->last_codec_mode,MODE1) == 0 ) - { - Word32 last_total_brate = L_add(st->last_total_brate_fx, 0); - st->last_total_brate_fx = -1; - move32(); - SetModeIndex( st, st->total_brate_fx, st->bwidth_fx, *shift ); - st->last_total_brate_fx = last_total_brate; - move32(); - } - ELSE - { - SetModeIndex( st, st->total_brate_fx, st->bwidth_fx, *shift); - st->sr_core = getCoreSamplerateMode2( st->total_brate_fx, st->bwidth_fx, st->rf_mode); - - Mpy_32_16_ss(st->sr_core, 5243, &L_tmp, &lsb); /* 5243 is 1/50 in Q18. (0+18-15=3) */ - st->L_frame_fx = extract_l(L_shr(L_tmp, 3)); /* Q0 */ - st->encoderLookahead_enc = NS2SA_fx2(st->sr_core, ACELP_LOOK_NS); - move16(); - st->encoderPastSamples_enc = shr(imult1616(st->L_frame_fx, 9), 4); - assert(st->L_frame_fx == st->sr_core / 50); - - IF ( L_sub(st->sr_core,12800) == 0 ) - { - st->preemph_fac = PREEMPH_FAC; - move16(); - st->gamma = GAMMA1; - move16(); - } - ELSE - { - st->preemph_fac = PREEMPH_FAC_16k; - move16(); - st->gamma = GAMMA16k; - move16(); - } - - st->igf = getIgfPresent(st->total_brate_fx, st->bwidth_fx, st->rf_mode); - } - - *coder_type = st->coder_type_raw_fx; - move16(); - - IF( *vad_flag == 0 ) - { - *coder_type = INACTIVE; - move16(); - } - ELSE IF( sub((*coder_type),GENERIC) > 0 ) - { - *coder_type = GENERIC; - move16(); - } - - st->mdct_sw = MODE1; - move16(); - } - } - - /*-----------------------------------------------------------------* - * Update of ACELP harmonicity counter (used in ACELP transform codebook @32kbps) - *-----------------------------------------------------------------*/ - - test(); - test(); - test(); - test(); - IF( L_sub(st->total_brate_fx, ACELP_32k) == 0 && sub(loc_harm,1) == 0 && sub(cor_map_sum,50<<8) > 0 - && sub(st->clas_fx, VOICED_CLAS)== 0 && sub(*coder_type,GENERIC) == 0 ) - { - st->last_harm_flag_acelp_fx = add(st->last_harm_flag_acelp_fx,1); - st->last_harm_flag_acelp_fx = s_min(st->last_harm_flag_acelp_fx,10); - } - ELSE - { - st->last_harm_flag_acelp_fx = 0; - move16(); - } - - /*-----------------------------------------------------------------* - * Update audio frames counter (used for UV decision) - *-----------------------------------------------------------------*/ - - IF( sub(*coder_type,AUDIO) == 0 ) - { - st->audio_frame_cnt_fx = add(st->audio_frame_cnt_fx,AUDIO_COUNTER_STEP); - } - ELSE IF (sub(*coder_type,INACTIVE) != 0) - { - st->audio_frame_cnt_fx = sub(st->audio_frame_cnt_fx,1); - } - - st->audio_frame_cnt_fx = s_min(st->audio_frame_cnt_fx,AUDIO_COUNTER_MAX); - st->audio_frame_cnt_fx = s_max(st->audio_frame_cnt_fx,0); - - /*-----------------------------------------------------------------* - * Set formant sharpening flag - *-----------------------------------------------------------------*/ - - *sharpFlag = 0; - move16(); - IF( sub(*coder_type,TRANSITION) == 0 ) - { - test(); - test(); - test(); - test(); - test(); - IF( ( L_sub(st->total_brate_fx,ACELP_48k) > 0 && sub(st->bwidth_fx,SWB) < 0 ) || /* Deactivate for core bitrates higher than 48.0 kb/s */ - ( L_sub(st->total_brate_fx,ACELP_13k20) >= 0 && L_sub(st->total_brate_fx,ACELP_16k40) <= 0 ) || /* Deactivate for bitrates <13.2, 16.4> kb/s (this is basically due to lack of signaling configurations */ - ( L_sub(st->total_brate_fx,ACELP_16k40) > 0 && sub(st->lp_noise_fx,FORMANT_SHARPENING_NOISE_THRESHOLD_FX ) > 0 ) ) /* Deactivate for bitrates >= 24.4 kb/s if the long-term noise level exceeds 34 dB */ - { - *sharpFlag= 0; - move16(); - } - ELSE - { - *sharpFlag= 1; - move16(); - } - } - - test(); - IF( sub(*coder_type,GENERIC) == 0 || sub(*coder_type,VOICED) == 0 ) - { - test(); - test(); - test(); - test(); - test(); - IF( *vad_hover_flag || - ( L_sub(st->total_brate_fx,ACELP_48k) > 0 && sub(st->bwidth_fx,SWB) < 0 ) || /* Deactivate for core bitrates higher than 48.0 kb/s */ - ( L_sub(st->total_brate_fx,ACELP_13k20) >= 0 && sub(st->lp_noise_fx,FORMANT_SHARPENING_NOISE_THRESHOLD_FX) > 0 /* Deactivate for bitrates >= 13.2 kb/s if the long-term noise level exceeds 34 dB */ - && L_sub(st->total_brate_fx,CNA_MAX_BRATE) > 0 ) ) - { - *sharpFlag = 0; - move16(); - } - ELSE - { - *sharpFlag = 1; - move16(); - } - } - - /* channel-aware mode - due to lack of signalling bit, sharpFlag is 1 always in RF mode */ - test(); - test(); - IF( sub(st->rf_mode,1)==0 && ( sub(*coder_type,VOICED) == 0 || sub(*coder_type,GENERIC) == 0 ) ) - { - *sharpFlag = 1; - } - - /*-----------------------------------------------------------------* - * Set voicing flag for HQ FEC - *-----------------------------------------------------------------*/ - - *Voicing_flag = 0; - move16(); - test(); - test(); - if ( *sp_aud_decision1 == 0 && ( sub(*coder_type,VOICED) == 0 || sub(*coder_type,GENERIC) == 0 ) ) - { - *Voicing_flag = 1; - move16(); - } - - /*---------------------------------------------------------------* - * Preprocessing at other sampling frequency rate (16/25.6/32kHz) - *----------------------------------------------------------------*/ - - sr_core_tmp = L_max(INT_FS_16k_FX,st->sr_core); /* indicates the ACELP sampling rate for MODE2, 16 kHz for MODE1 */ - if( sub(st->codec_mode,MODE1) == 0 ) - { - sr_core_tmp = INT_FS_16k_FX; - move32(); - } - - L_frame_tmp = s_max(L_FRAME16k,st->L_frame_fx); - if( sub(st->codec_mode,MODE1) == 0 ) - { - L_frame_tmp = L_FRAME16k; - move16(); - } - L_look = NS2SA_fx2(sr_core_tmp, ACELP_LOOK_NS); - move16(); /* lookahead at other sampling rate (16kHz, 25.5kHz, 32kHz) */ - - new_inp_16k = old_inp_16k + L_INP_MEM; /* pointer to new samples of the input signal in 16kHz core */ - inp_16k = new_inp_16k - L_look; /* pointer to the current frame of input signal in 16kHz core */ - Copy( st->old_inp_16k_fx, old_inp_16k, L_INP_MEM ); /* Note: The merory has been rescaled at the begining of the function*/ - - /*---------------------------------------------------------------* - * Change the sampling frequency to 16/25.6/32 kHz - *----------------------------------------------------------------*/ - - test(); - IF( L_sub(st->input_Fs_fx,sr_core_tmp) == 0 ) - { - /* no resampling needed, only delay adjustement to account for the FIR resampling delay */ - delay = NS2SA_fx2(st->input_Fs_fx, DELAY_FIR_RESAMPL_NS); - Copy_Scale_sig( st->mem_decim16k_fx + delay, new_inp_16k, delay, -1 ); /* Input in Q0 -> Output in Q-1 to mimic the resampling filter */ - Copy_Scale_sig( signal_in, new_inp_16k + delay, input_frame - delay, -1 ); /* Input in Q0 -> Output in Q-1 to mimic the resampling filter */ - Copy( signal_in + input_frame - shl(delay,1), st->mem_decim16k_fx, shl(delay,1) ); /* memory still in Q0 */ - } - ELSE IF( L_sub(st->input_Fs_fx,32000) == 0 || L_sub(st->input_Fs_fx,48000) == 0 ) - { - modify_Fs_fx( signal_in, input_frame, st->input_Fs_fx, new_inp_16k, sr_core_tmp, st->mem_decim16k_fx, 0 ); - } - ELSE /* keep memories up-to-date in case of bit-rate switching */ - { - /* no resampling needed, only delay adjustement to account for the FIR resampling delay */ - delay = NS2SA_fx2(st->input_Fs_fx, DELAY_FIR_RESAMPL_NS); - Copy( st->mem_decim16k_fx + delay, new_inp_16k, delay ); - Copy( signal_in, new_inp_16k + delay, sub(input_frame, delay) ); - Copy( signal_in + sub(input_frame, shl(delay,1)), st->mem_decim16k_fx, shl(delay,1) ); - } - - IF( L_sub(sr_core_tmp,16000) == 0 ) - { - /* save input resampled at 16kHz, non-preemhasised */ - Copy( new_inp_16k, new_inp_resamp16k, L_FRAME16k ); - } - ELSE IF( L_sub(sr_core_tmp,16000) > 0 ) - { - /* reset the buffer, the signal is needed for WB BWEs */ - set16_fx( new_inp_resamp16k, 0, L_FRAME16k ); - } - - /*------------------------------------------------------------------* - * Perform fixed preemphasis (16kHz signal) through 1 - g*z^-1 - *-----------------------------------------------------------------*/ - - test(); - test(); - IF( ((st->tcxonly == 0) || (sub(st->codec_mode,MODE1) == 0)) && L_sub(st->input_Fs_fx,8000) > 0 ) - { - st->mem_preemph_enc = shl(new_inp_16k[sub(L_frame_tmp,1)],1); - } - - test(); - IF( L_sub(st->input_Fs_fx,8000) > 0 && L_sub(sr_core_tmp,16000) == 0) - { - Preemph_scaled( new_inp_16k, &Q_new_16k, &(st->mem_preemph16k_fx), st->Q_max_16k, PREEMPH_FAC_16k, 0, 1, L_Q_MEM, L_FRAME16k, st->last_coder_type_fx, 1); - } - ELSE IF( L_sub(st->input_Fs_fx,8000) > 0 ) /* keep memory up-to-date in case of bit-rate switching */ - { - st->mem_preemph16k_fx = new_inp_16k[sub(L_frame_tmp,1)]; - move16(); - } - - /*------------------------------------------------------------------* - * Core-encoder memories scaling - *-----------------------------------------------------------------*/ - - test(); - test(); - test(); - test(); - test(); - test(); - IF( ( ((st->tcxonly == 0) || !(L_sub(st->core_brate_fx,FRAME_NO_DATA) != 0 || L_sub(st->core_brate_fx,SID_2k40) != 0)) && sub(st->L_frame_fx,L_FRAME16k) == 0 && sub(st->codec_mode,MODE2) == 0 ) || - ( sub(st->L_frame_fx,L_FRAME16k) == 0 && sub(st->codec_mode,MODE1) == 0 ) ) - { - *Q_new = Q_new_16k; - move16(); - } - ELSE - { - IF( L_sub(st->input_Fs_fx,8000) > 0 && L_sub(sr_core_tmp,16000) == 0 ) - { - Scale_sig(new_inp_16k, L_FRAME16k, sub(*Q_new,Q_new_16k)); - } - } - - /* Above computed Q_new is used to scale primary copy exc and memory here by (Q_new, st->prev_Q_new) */ - - Q_exp = sub(*Q_new, st->prev_Q_new); - move16(); - Q_wsp_exp = add(Q_exp,shift_exp); - - Scale_mem_enc( Q_exp, old_inp_16k, old_exc, st->old_bwe_exc_fx, &(st->LPDmem.mem_w0), st->LPDmem.mem_syn, - st->LPDmem.mem_syn2, &st->mem_deemp_preQ_fx, st->last_exc_dct_in_fx, st->old_input_lp_fx ); - - /*-----------------------------------------------------------------* - * Redo LP analysis at 16kHz if ACELP@16k core was selected - * update buffers - *-----------------------------------------------------------------*/ - - test(); - test(); - test(); - test(); - test(); - test(); - IF( ( ((st->tcxonly == 0) || !(L_sub(st->core_brate_fx,FRAME_NO_DATA) != 0 || L_sub(st->core_brate_fx,SID_2k40) != 0)) && sub(st->L_frame_fx,L_FRAME16k) == 0 && sub(st->codec_mode,MODE2) == 0 ) || - ( sub(st->L_frame_fx,L_FRAME16k) == 0 && sub(st->codec_mode,MODE1) == 0 ) ) - { - /* update signal buffers */ - Copy( new_inp_resamp16k, st->buf_speech_enc+L_FRAME16k, L_FRAME16k ); - Scale_sig( st->buf_speech_enc+L_FRAME16k, L_FRAME16k, 1 ); - Copy( new_inp_16k, st->buf_speech_enc_pe+L_FRAME16k, L_FRAME16k ); - IF( Q_exp != 0 ) - { - Scale_sig(st->buf_speech_enc_pe, st->encoderPastSamples_enc+st->encoderLookahead_enc, Q_exp); - Scale_sig(&(st->mem_wsp_enc), 1, Q_exp); - } - - /*--------------------------------------------------------------* - * LPC analysis - *---------------------------------------------------------------*/ - - test(); - IF( sub(st->last_L_frame_fx,L_FRAME) == 0 && sub(st->codec_mode,MODE1) == 0 ) - { - /* this is just an approximation, but it is sufficient */ - Copy( st->lsp_old1_fx, st->lspold_enc_fx, M ); - } - - analy_lp_fx( inp_16k, L_FRAME16k, L_look, ener, A, epsP_h, epsP_l, lsp_new, lsp_mid, st->lspold_enc_fx, pitch, voicing, 16000, *Q_new, Q_r ); - - /*--------------------------------------------------------------* - * Compute Weighted Input - *---------------------------------------------------------------*/ - - IF( sub(st->codec_mode,MODE2) == 0 ) - { - find_wsp( A, st->speech_enc_pe, st->wspeech_enc, &st->mem_wsp_enc, PREEMPH_FAC_16k, L_FRAME16k, L_LOOK_16k, L_SUBFR, Aw, st->gamma, st->nb_subfr); - - /* This need to be harmonized with MODE2 */ - Scale_sig( st->wspeech_enc, L_FRAME16k+L_LOOK_16k, *shift ); - - } - ELSE - { - weight_a_subfr_fx( NB_SUBFR16k, A, Aw, GAMMA16k, M ); - } - } - ELSE - { - /* update signal buffers */ - Copy( new_inp_12k8, st->buf_speech_enc_pe+st->L_frame_fx, L_FRAME ); - Copy( st->buf_speech_enc+L_FRAME32k, st->buf_speech_enc+st->L_frame_fx, L_FRAME ); - - if ( st->tcxonly == 0 ) - { - Copy( wsp, st->buf_wspeech_enc+st->L_frame_fx+L_SUBFR, L_FRAME + L_LOOK_12k8 ); - } - test(); - test(); - IF( sub(st->codec_mode,MODE2) == 0 && st->tcxonly == 0 && Q_exp != 0 ) - { - Scale_sig( st->buf_speech_enc_pe, st->encoderPastSamples_enc+st->encoderLookahead_enc, Q_exp ); - Scale_sig( &(st->mem_wsp_enc), 1, Q_exp ); - } - } - - excitation_max_test = -32768; - move16(); - FOR( i = 0; i < L_EXC_MEM; i++ ) - { - excitation_max_test = s_max(abs_s(old_exc[i]),excitation_max_test); - } - - test(); - IF( sub(excitation_max_test,8192) > 0 && *shift == 0 ) - { - excitation_max_test = 1; - move16(); - *shift = -1; - move16(); - st->old_wsp_shift=-1; - move16(); - Scale_sig( old_wsp, L_WSP_MEM+L_FRAME+L_LOOK_12k8, -1 ); - } - ELSE - { - excitation_max_test = 0; - move16(); - } - - test(); - IF ( sub(st->codec_mode,MODE2) == 0 && st->tcxonly == 0 ) - { - IF (Q_wsp_exp != 0) - { - Scale_sig(st->buf_wspeech_enc, st->L_frame_fx+L_SUBFR, Q_wsp_exp); - } - IF( sub(excitation_max_test,1) == 0 ) - { - Scale_sig( st->buf_wspeech_enc, st->L_frame_fx+L_SUBFR+st->L_frame_fx+st->encoderLookahead_enc, -1 ); - } - } - - /*-----------------------------------------------------------------* - * ACELP/TCX20/HQ Switching Decision - *-----------------------------------------------------------------*/ - - IF ( sub(st->codec_mode,MODE2) == 0 ) - { - test(); - test(); - IF((L_sub(st->core_brate_fx,FRAME_NO_DATA) != 0 && L_sub(st->core_brate_fx,SID_2k40) != 0 && st->tcxonly == 0 )) - { - core_acelp_tcx20_switching( st,*vad_flag, - sp_aud_decision0, non_staX, - pitch, pitch_fr, voicing_fr, currFlatness, lsp_mid, stab_fac, *Q_new, *shift ); - } - - test(); - IF (sub(st->mdct_sw_enable,MODE2) == 0 && !st->rf_mode) - { - IF (sub(st->core_fx,TCX_20_CORE) == 0) /* Switching only possible from TCX_20 frames, not from TCX_10 frames */ - { - /* Select MDCT Core */ - test(); - test(); - IF ((sub(st->bwidth_fx,SWB)==0 || sub(st->bwidth_fx,FB)==0) && L_sub(st->total_brate_fx,24400)==0) - { - st->core_fx = mdct_classifier_fx(fft_buff,st,*vad_flag, enerBuffer - ,sub(enerBuffer_exp, 31) - ); - } - test(); - IF ((L_sub(st->total_brate_fx,16400) == 0) && (sub(st->bwidth_fx,FB) !=0 )) - { - MDCT_selector( st, sp_floor, *Etot, cor_map_sum, voicing, enerBuffer, enerBuffer_exp, *vad_flag ); - } - } - ELSE - { - MDCT_selector_reset( st ); - } - - /* Do the switching that was decided in the MDCT selector */ - test(); - IF( sub(st->core_fx,HQ_CORE) == 0 ) - { - st->codec_mode = MODE1; - move16(); - st->mdct_sw = MODE2; - move16(); - } - ELSE IF( sub(st->last_codec_mode,MODE1) == 0 && sub(st->last_core_fx,HQ_CORE) == 0 ) - { - Word16 L_frame_old = st->last_L_frame_fx; - move16(); - st->last_L_frame_fx = st->L_frame_fx; - move16(); - SetModeIndex( st, st->total_brate_fx, st->bwidth_fx, *shift ); - st->last_L_frame_fx = L_frame_old; - move16(); - } - } - - /*--------------------------------------------------------------* - * TCX mode decision - *---------------------------------------------------------------*/ - - SetTCXModeInfo( st, &st->transientDetection, &st->tcx_cfg.tcx_curr_overlap_mode ); - } - - /*-----------------------------------------------------------------* - * Updates - *-----------------------------------------------------------------*/ - - /* update old weighted speech buffer - for OL pitch analysis */ - Copy( &old_wsp[L_FRAME], st->old_wsp_fx, L_WSP_MEM ); - - /* update old input signal buffer */ - Copy( &old_inp_12k8[L_FRAME], st->old_inp_12k8_fx, L_INP_MEM ); - - /* update old input signal @16kHz buffer */ - test(); - IF( L_sub(st->input_Fs_fx,8000) > 0 && L_sub(sr_core_tmp,16000) == 0 ) - { - Copy( &old_inp_16k[L_frame_tmp], st->old_inp_16k_fx, L_INP_MEM ); - } - ELSE IF( L_sub(st->input_Fs_fx,8000) > 0 ) - { - lerp( st->old_inp_12k8_fx+L_INP_MEM-L_INP_MEM*4/5, st->old_inp_16k_fx, L_INP_MEM, L_INP_MEM*4/5); - Scale_sig(st->old_inp_16k_fx, L_INP_MEM, sub(*Q_new,st->Q_old)); - } - - test(); - test(); - IF( (L_sub(sr_core_tmp,16000) == 0) && st->tcxonly && sub(st->codec_mode,MODE2) == 0 ) - { - /* copy input resampled at 16kHz, non-preemhasised */ - Copy( new_inp_resamp16k, new_inp_16k, L_FRAME16k ); - } - - /* update of old per-band energy spectrum */ - Copy32( fr_bands + NB_BANDS, st->enrO_fx, NB_BANDS ); - - /* set the pointer of the current frame for the ACELP core */ - *inp = inp_16k; - if ( sub(st->L_frame_fx,L_FRAME) == 0 ) - { - *inp = inp_12k8; - } - - - return; -} diff --git a/src/libs/libevs/lib_enc/pvq_core_enc.cpp b/src/libs/libevs/lib_enc/pvq_core_enc.cpp new file mode 100644 index 00000000..6d277764 --- /dev/null +++ b/src/libs/libevs/lib_enc/pvq_core_enc.cpp @@ -0,0 +1,512 @@ + +/*==================================================================================== + EVS Codec 3GPP TS26.443 Nov 13, 2018. Version 12.11.0 / 13.7.0 / 14.3.0 / 15.1.0 + ====================================================================================*/ + +#include +#include +#include "options.h" +#include "rom_com.h" +#include "prot.h" +#include "prot.h" +#include "stl.h" + +/*-------------------------------------------------------------------* +* Local functions +*--------------------------------------------------------------------*/ + +static short calc_pvq_splits( Encoder_State *st, const short band_bits, const short sfmsize, const float *y, short *bits ); +static void obtainEnergyParameter( float Enear, float Eopp, short *param); + +static void densityIndexSymbolEncode( Encoder_State *st, short density , short r_dim, short l_dim , short index_phi); + +/*-------------------------------------------------------------------* +* pvq_encode_band() +* +* Encode band with PVQ +*--------------------------------------------------------------------*/ + +static void pvq_encode_band( + Encoder_State *st, + const float *coefs_norm, + short *pulse_vector, + short *npulses, + float *coefs_quant, + const short sfmsize, + const short band_bits, + short *bits_left, + const short strict_bits +) +{ + short K_val; + short j, Np; + float enr, E_part[MAX_SPLITS+1]; + short part_start[MAX_SPLITS+1], dim_part[MAX_SPLITS+1], bits_part[MAX_SPLITS+1]; + short pool_tot, pool_part, dim_parts; + float g_part[MAX_SPLITS]; + short g_part_s[MAX_SPLITS]; + short sg_part[MAX_SPLITS+1]; + short idx_sort[MAX_SPLITS+1]; + short js, band_bits_tot, split_bit; + + Np = calc_pvq_splits(st, band_bits, sfmsize, coefs_norm, &split_bit); + band_bits_tot = band_bits - split_bit; + + enr = 0.0f; + for(j = 0; j 1) + { + encode_energies( st, coefs_norm, Np, dim_part, E_part, bits_part, g_part_s, band_bits_tot, bits_left, enr, sfmsize, strict_bits ); + } + else + { + bits_part[0] = band_bits_tot; + } + + pool_tot = 0; + pool_part = 0; + + for (j = 0; j < Np; j++) + { + g_part[j] = -((float)g_part_s[j])/32768; + g_part_s[j] = -g_part_s[j]; + } + + srt_vec_ind(g_part_s,sg_part,idx_sort,Np); + for(j = 0; j < Np; j++) + { + js = idx_sort[Np-1-j]; + + + pool_part = shrtCDivSignedApprox(pool_tot, Np-j); + bits_part[js] = max(0, min(bits_part[js]+pool_part, 256)); + + conservativeL1Norm(dim_part[js],bits_part[js], strict_bits, *bits_left, pool_tot , *npulses, /* inputs */ + &K_val, bits_left, &pool_tot, npulses); /* outputs */ + if( K_val >= 1 ) + { + pvq_encode(st, coefs_norm + part_start[js], pulse_vector + part_start[js], + coefs_quant + part_start[js], K_val, dim_part[js], g_part[js]); + } + else + { + set_f(coefs_quant + part_start[js],0.0f,dim_part[js]); + set_s(pulse_vector + part_start[js],0,dim_part[js]); + } + } + + return; +} + +/*-------------------------------------------------------------------* +* pvq_encode_frame() +* +* +*--------------------------------------------------------------------*/ + +void pvq_encode_frame( + Encoder_State *st, + const float *coefs_norm, /* i : normalized coefficients to encode */ + float *coefs_quant, /* o : quantized coefficients */ + float *gopt, /* o : optimal shape gains */ + short *npulses, /* o : number of pulses per band */ + short *pulse_vector, /* o : non-normalized pulse shapes */ + const short *sfm_start, /* i : indices of first coefficients in the bands */ + const short *sfm_end, /* i : indices of last coefficients in the bands */ + const short *sfmsize, /* i : band sizes */ + const short nb_sfm, /* i : total number of bands */ + const short *R, /* i : bitallocation per band (Q3)*/ + const short pvq_bits, /* i : number of bits avaiable */ + const short core /* i : core */ +) +{ + short i, j; + short band_bits, bits_left; + short bit_pool = 0; + short coded_bands, bands_to_code; + short curr_bits; + short R_sort[NB_SFM]; /*Q3*/ + short is, i_sort[NB_SFM]; + short strict_bits; + + rc_enc_init(st, pvq_bits); + curr_bits = (pvq_bits - RC_BITS_RESERVED)<<3; + + bands_to_code = 0; + for (i = 0; i < nb_sfm; i++) + { + if (R[i] > 0) + { + bands_to_code++; + } + } + + if (core == ACELP_CORE) + { + strict_bits = 1; + srt_vec_ind (R, R_sort, i_sort, nb_sfm); + } + else + { + strict_bits = 0; + for(i=0; i 0) + { + bandBitsAdjustment(st->rc_num_bits, st->rc_range, curr_bits, bands_to_code, bands_to_code-coded_bands, sfmsize[is] ,R[is], bit_pool, /* inputs */ + &band_bits, &bits_left, &bit_pool); /* outputs */ + pvq_encode_band( st, &coefs_norm[sfm_start[is]], &pulse_vector[sfm_start[is]], + &npulses[is], &coefs_quant[sfm_start[is]], sfmsize[is], band_bits, + &bits_left, strict_bits); + gopt[is] = dotp(coefs_quant+sfm_start[is], coefs_norm+sfm_start[is], sfmsize[is]) / + (dotp(coefs_quant+sfm_start[is], coefs_quant+sfm_start[is], sfmsize[is]) + 1e-15f); + if (gopt[is] == 0.0f) + { + gopt[is] = 1e-10f; + } + /* Updates */ + coded_bands++; + } + else + { + for (j = sfm_start[is]; j < sfm_end[is]; j++) + { + coefs_quant[j] = 0.0f; + pulse_vector[j] = 0; + } + } + } + + rc_enc_finish(st); + + return; +} + +/*---------------------------------------------------------------------* + * pvq_core_enc() + * + * Main Generic Audio Encoder Routine + *---------------------------------------------------------------------*/ + +short pvq_core_enc ( + Encoder_State *st, + float coefs_norm[], + float coefs_quant[], + short bits_tot, /* total number of bits */ + short nb_sfm, + const short *sfm_start, + const short *sfm_end, + const short *sfmsize, + short *R, + short *Rs, + short *npulses, + short *maxpulse, + const short core +) +{ + short i; + short R_upd; /*Q3*/ + short ord[NB_SFM_MAX]; + float fg_pred[NB_SFM_MAX]; + short pvq_bits; + short pulse_vector[L_FRAME48k]; + float gopt[NB_SFM]; + short gain_bits_array[NB_SFM]; + short gain_bits_tot; + + R_upd = bits_tot * 8; + gain_bits_tot = assign_gain_bits( core, nb_sfm, sfmsize, R, gain_bits_array, &R_upd ); + pvq_bits = R_upd >> 3; + pvq_encode_frame( st, coefs_norm, coefs_quant, gopt, npulses, pulse_vector, + sfm_start, sfm_end, sfmsize, nb_sfm, R, pvq_bits, core ); + bits_tot = pvq_bits + gain_bits_tot; + + + + if( Rs != NULL ) + { + for(i=0; i 0); /* Update Rs in case no pulses were assigned */ + } + } + + for(i=0; i 0); /* Update in case no pulses were assigned */ + } + + get_max_pulses( sfm_start, sfm_end, ord, npulses, nb_sfm, pulse_vector, maxpulse ); + + fine_gain_pred( sfm_start, sfm_end, sfmsize, ord, npulses, maxpulse, R, nb_sfm, + coefs_quant, pulse_vector, fg_pred, core); + + fine_gain_quant(st, ord, nb_sfm, gain_bits_array, fg_pred, gopt); + + apply_gain(ord, sfm_start, sfm_end, nb_sfm, fg_pred, coefs_quant); + + return bits_tot; +} + + +/*-------------------------------------------------------------------* +* encode_energies() +* +* +*--------------------------------------------------------------------*/ + +void encode_energies( + Encoder_State *st, + const float *coefs, + short Np, + short *dim_part, + float *E_part, + short *bits_part, + short *g_part, + short qband, + + short *bits_left, + float enr, + short dim, + const short strict_bits +) +{ + short i, j, l_Np, r_Np; + short l_bits, r_bits, l_dim, r_dim; + float l_enr, r_enr; + short il, ir; + short oppRQ3, qzero; + short density; + short phi; + short index_phi=-1; + + l_Np = Np>>1; + r_Np = Np-l_Np; + + l_enr = 0.0f; + l_bits = 0; + l_dim = 0; + for(i=0; irc_num_bits, st->rc_range, &qzero); + densityAngle2RmsProjEnc(density, phi , &index_phi, &ir, &il, &oppRQ3); + densityIndexSymbolEncode(st, density, r_dim, l_dim, index_phi); + + for(i = 0; i> 15; + } + + for(i = l_Np; i> 15; + } + NearOppSplitAdjustment( qband, qzero, st->rc_num_bits, st->rc_range, *bits_left, + strict_bits, Np, dim_part[0], dim_part[Np-1], + l_dim, r_dim, oppRQ3, + &l_bits, &r_bits, bits_left); + if(l_Np > 1) + { + encode_energies( st, coefs, l_Np, dim_part, E_part, bits_part, g_part, l_bits, bits_left, l_enr, l_dim, strict_bits ); + } + else + { + E_part[0] = l_enr; + bits_part[0] = l_bits; + } + if(r_Np > 1) + { + encode_energies( st, &coefs[l_dim], r_Np, &dim_part[l_Np], &E_part[l_Np], &bits_part[l_Np], &g_part[l_Np], r_bits, bits_left, r_enr, r_dim, strict_bits ); + } + else + { + E_part[1] = r_enr; + bits_part[1] = r_bits; + } + return; +} + +static void densityIndexSymbolEncode(Encoder_State *st, + short density , + short opp_sz, + short near_sz , + short index_phi) +{ + short angle, c ; + int sym_freq = 1, cum_freq, tot; + short densityPlOne , densitySubC; + short densitySubIndex,nearFlag; + + if ((0xFFFE&density) != 0 ) /* even */ + { + angle = atan2_fx(SQRT_DIM_fx[opp_sz], SQRT_DIM_fx[near_sz]); + angle = shl(angle, 1); + angle = mult_r(angle, 20861); + c = mult_r(density, angle); + + densityPlOne = 1 + density; + densitySubC = density - c; + + tot = 2 + density*densityPlOne; /* c==0, c==density*/ + sym_freq = 1 + 2*index_phi ; /* c==density */ + cum_freq = index_phi*index_phi; /* c==density*/ + + if (c == 0) + { + sym_freq = 2*densityPlOne - sym_freq; + cum_freq = 2*index_phi*(densityPlOne) - cum_freq; + } + else if( densitySubC != 0 ) /* c n.eq. density */ + { + densitySubIndex = density - index_phi; + nearFlag = (index_phi <= c); + + tot = densityPlOne + density*c*(densitySubC); + sym_freq = nearFlag ? ( 1 + 2*index_phi*densitySubC ) : ( 1 + 2*densitySubIndex*c ); + cum_freq = nearFlag ? ( index_phi*((index_phi-1)*densitySubC + 1)) : + ( tot - densityPlOne - densitySubIndex*(densitySubIndex+1)*c + index_phi); + } + /* else keep values for c==density*/ + rc_encode(st, cum_freq, sym_freq, tot); + } + + return; +} + + +/*--------------------------------------------------------------------------* + * calc_pvq_splits() + * + * Calculate the number of segments needed + *--------------------------------------------------------------------------*/ + +static short calc_pvq_splits( /* o : Number of segments */ + Encoder_State *st, /* i/o: Encoder state */ + const short band_bits, /* i : Band bit rate */ + const short sfmsize, /* i : Band width */ + const float *y, /* i : Target vector */ + short *bits /* o : Consumed bits */ +) +{ + short Np; + short Npart; + short i,j,k; + float E[MAX_SPLITS]; + float Emean; + float tmp; + float max_dev; + Np = (short)(intLimCDivPos( (int)band_bits, 67)>>2); + if (band_bits - 268*Np != 0 || Np == 0 ) /* L_msu */ + { + Np++; /* ceil */ + } + *bits = 0; + + if ( Np < MAX_SPLITS && (band_bits - (8*sfmsize * THR_ADD_SPLIT ) > 0)) + { + Npart = (short) intLimCDivPos( (int)sfmsize, Np); + *bits = 8; + Emean = 0; + k = 0; + for ( i = 0; i < Np; i++) + { + E[i] = EPSILON; + for (j = 0; j < Npart; j++, k++) + { + E[i] += y[k]*y[k]; + } + E[i] = 30 - norm_l(max((int)E[i], 1)); /* a 0 input integer Ei yields a zeroed log2(Ei) out */ + Emean += E[i]; + } + Emean /= Np; + + max_dev = -1; + for ( i = 0; i < Np; i++) + { + tmp = (float)fabs(E[i] - Emean); + if ( tmp > max_dev ) + { + max_dev = tmp; + } + } + + if ( max_dev > (32 - band_bits/(8*Np)) ) + { + rc_enc_bits(st, 1, 1); + Np += 1; + } + else + { + rc_enc_bits(st, 0, 1); + } + } + + Np = max(Np, (short)(ceil((float)sfmsize/PVQ_MAX_BAND_SIZE))); + Np = min(MAX_SPLITS, Np); + Np = min((short)floor((float)sfmsize/MIN_BAND_SIZE), Np); + return Np; +} + + +#define EPSILON_obtainEnergyParameter 0.00373f /**/ +#define C_obtainEnergyParameter ((float)(1 << 15) / EVS_PI + EPSILON_obtainEnergyParameter) + +void obtainEnergyParameter( + float Enear, + float Eopp, + short *param +) +{ + if (!Eopp) + { + *param=0; + return; + } + if (!Enear) + { + *param = 1 << 14; + return; + } + *param = (short) (C_obtainEnergyParameter * atan2( (float)sqrt(Eopp) , (float) sqrt(Enear)) + 0.5f); + return; +} +#undef C_obtainEnergyParameter +#undef EPSILON_obtainEnergyParameter + + diff --git a/src/libs/libevs/lib_enc/pvq_core_enc_fx.cpp b/src/libs/libevs/lib_enc/pvq_core_enc_fx.cpp deleted file mode 100755 index 2fb1ad17..00000000 --- a/src/libs/libevs/lib_enc/pvq_core_enc_fx.cpp +++ /dev/null @@ -1,633 +0,0 @@ -#include "options.h" -/*==================================================================================== - EVS Codec 3GPP TS26.442 Apr 03, 2018. Version 12.11.0 / 13.6.0 / 14.2.0 - ====================================================================================*/ - -#include -#include "options.h" /* Compilation switches */ -#include "rom_com_fx.h" /* Static table prototypes */ -#include "prot_fx.h" /* Function prototypes */ -#include "stl.h" - -static Word16 calc_pvq_splits_fx(Encoder_State_fx *st_fx, const Word16 band_bits, const Word16 sfmsize, const Word16 *y, const Word16 Q_y, - Word16 *bits); - -static void densityIndexSymbolEncode_fx( Encoder_State_fx *st_fx, const Word16 density , const Word16 r_dim, const Word16 l_dim , const Word16 index_phi ); - -/* Encode band with PVQ */ - -static void pvq_encode_band_fx( - Encoder_State_fx *st_fx, - const Word16 *coefs_norm, - const Word16 Q_coefs, - Word16 *pulse_vector, - Word16 *npulses, - Word16 *coefs_quant, - const Word16 sfmsize, - const Word16 band_bits, - Word16 *bits_left, - const Word16 strict_bits -) -{ - - Word16 K_val; - Word16 j, Np; - Word32 enr, E_part[MAX_SPLITS+1]; - Word16 part_start[MAX_SPLITS+1], dim_part[MAX_SPLITS+1], bits_part[MAX_SPLITS+1]; - Word16 pool_tot, pool_part, dim_parts; - Word16 g_part[MAX_SPLITS]; - Word16 g_part_neg[MAX_SPLITS]; - Word16 sg_part[MAX_SPLITS+1]; - Word16 idx_sort[MAX_SPLITS+1]; - Word16 js, band_bits_tot, split_bit; - Word16 tmp; - Word32 L_coefs_quant_fx[PVQ_MAX_BAND_SIZE]; - - Np = calc_pvq_splits_fx(st_fx, band_bits, sfmsize, coefs_norm, Q_coefs, &split_bit); - band_bits_tot = sub(band_bits, split_bit); - - enr = L_deposit_l(0); - FOR (j = 0; j < sfmsize; j++) - { - /* This is of paramount importance that the number of bits down-shift here - * MUST BE IDENTICAL to that used to compute "l_enr" in encode_energies_fx(). - * If the number of bits down-shift is changed here, that in encode_energies_fx() - * must be changed to the same amount as well! - */ - tmp = shr(coefs_norm[j], 2); - enr = L_mac0(enr, tmp, tmp); - } - - dim_parts = extract_h(L_mult(negate(sfmsize),lim_neg_inv_tbl_fx[Np])); - set16_fx( dim_part, dim_parts, sub(Np, 1) ); - dim_part[Np-1] = sub(sfmsize, i_mult2(dim_parts, sub(Np, 1))); - move16(); - - part_start[0] = 0; - move16(); - FOR (j = 1; j < Np; j++) - { - part_start[j] = add(part_start[j-1], dim_part[j-1]); - move16(); - } - - /* Encode energies */ - set16_fx(g_part_neg, -32768, Np); /* -1.0 in Q15 */ - IF (sub(Np, 1) > 0) - { - encode_energies_fx( st_fx, coefs_norm, Q_coefs, Np, dim_part, E_part, bits_part, g_part_neg, band_bits_tot, bits_left, enr, sfmsize, strict_bits ); - } - ELSE - { - bits_part[0] = band_bits_tot; - move16(); - } - - pool_tot = 0; /* Word16 */ - pool_part = 0; /* Word16 */ - - FOR (j = 0; j < Np; j++) - { - g_part[j] = negate(g_part_neg[j]); - } - srt_vec_ind16_fx(g_part, sg_part, idx_sort, Np); - FOR(j = 0; j < Np; j++) - { - js = idx_sort[Np-1-j]; - pool_part = shrtCDivSignedApprox( pool_tot, sub(Np, j) ); - bits_part[js] = s_max(0, s_min(add(bits_part[js], pool_part), 256)); - - conservativeL1Norm_fx(dim_part[js], bits_part[js], strict_bits, *bits_left, pool_tot, *npulses, /* inputs */ - &K_val, bits_left, &pool_tot, npulses); /* outputs */ - - IF( K_val > 0 ) - { - pvq_encode_fx(st_fx,coefs_norm + part_start[js], pulse_vector + part_start[js], - coefs_quant + part_start[js], L_coefs_quant_fx, K_val, dim_part[js], g_part_neg[js]); - } - ELSE - { - set16_fx(coefs_quant + part_start[js], 0, dim_part[js]); - set16_fx(pulse_vector + part_start[js], 0, dim_part[js]); - } - } - - return; -} - -void pvq_encode_frame_fx( - Encoder_State_fx *st_fx, - const Word16 *coefs_norm, /* i : normalized coefficients to encode */ - Word16 Q_coefs, /* i : Q-point of coefs_norm[] */ - Word16 *coefs_quant, /* o : quantized coefficients */ - Word16 *gopt, /* o : optimal shape gains */ - Word16 *npulses, /* o : number of pulses per band */ - Word16 *pulse_vector, /* o : non-normalized pulse shapes */ - const Word16 *sfm_start, /* i : indices of first coefficients in the bands */ - const Word16 *sfm_end, /* i : indices of last coefficients in the bands */ - const Word16 *sfmsize, /* i : band sizes */ - const Word16 nb_sfm, /* i : total number of bands */ - const Word16 *R, /* i : bitallocation per band Q3 */ - const Word16 pvq_bits, /* i : number of bits avaiable */ - const Word16 core /* i : core */ -) -{ - Word16 i, j; - Word16 band_bits, bits_left; - - Word16 bit_pool = 0; - Word16 coded_bands, bands_to_code; - Word16 bits; - Word16 R_sort[NB_SFM]; - Word16 is, i_sort[NB_SFM]; - Word16 strict_bits; - Word16 exp, tmp, shift; - Word32 xy_corr, yy_corr; - rc_enc_init_fx(st_fx, pvq_bits); - - bits = shl(sub(pvq_bits, RC_BITS_RESERVED), 3); - - bands_to_code = 0; - move16(); - FOR (i = 0; i < nb_sfm; i++) - { - if (R[i] > 0) - { - bands_to_code = add(bands_to_code, 1); - } - } - - IF (core == ACELP_CORE) - { - strict_bits = 1; - move16(); - srt_vec_ind16_fx(R, R_sort, i_sort, nb_sfm); - } - ELSE - { - strict_bits = 0; - move16(); - FOR (i = 0; i < nb_sfm; i++) - { - i_sort[i] = i; - move16(); - } - } - - coded_bands = 0; - move16(); - FOR (i = 0; i < nb_sfm; i++) - { - is = i_sort[i]; - move16(); - gopt[is] = 0; - move16(); - IF (R[is] > 0) - { - bandBitsAdjustment_fx(st_fx->rc_num_bits_fx, st_fx->rc_range_fx, bits, bands_to_code, bands_to_code-coded_bands, sfmsize[is] ,R[is], bit_pool, /* inputs */ - &band_bits, &bits_left, &bit_pool); /* outputs */ - pvq_encode_band_fx( st_fx, &coefs_norm[sfm_start[is]], Q_coefs, &pulse_vector[sfm_start[is]], - &npulses[is], &coefs_quant[sfm_start[is]], sfmsize[is], band_bits, - &bits_left, strict_bits); - - xy_corr = L_deposit_l(0); - yy_corr = L_deposit_l(1); - shift = band_len_ener_shift[ band_len_idx[ shr(sfmsize[is], 3)] ]; - move16(); - FOR (j = 0; j < sfmsize[i]; j++) - { - tmp = shr(coefs_quant[sfm_start[is]+j], shift); - xy_corr = L_mac0(xy_corr, shr(coefs_norm[sfm_start[is]+j], 1), tmp); /* Q_coefs-1+15-shift */ - yy_corr = L_mac0(yy_corr, tmp, tmp); /* 2*(15-shift) */ - } - - tmp = ratio(xy_corr, yy_corr, &exp); - gopt[is] = shl(tmp, sub(sub(sub(14, Q_coefs), shift), exp)); - - if (gopt[is] == 0) - { - gopt[is] = 1; - move16(); - } - - /* Updates */ - coded_bands = add(coded_bands, 1); - } - ELSE - { - FOR (j = sfm_start[is]; j < sfm_end[is]; j++) - { - coefs_quant[j] = 0; - move16(); - pulse_vector[j] = 0; - move16(); - } - } - } - - rc_enc_finish_fx(st_fx); - - return; -} - -/*---------------------------------------------------------------------* - * pvq_core_enc() - * - * Main Generic Audio Encoder Routine - *---------------------------------------------------------------------*/ - -Word16 pvq_core_enc_fx( - Encoder_State_fx *st_fx, - Word16 coefs_norm[], - Word16 coefs_quant[], - Word16 *Q_coefs, - Word16 bits_tot, /* total number of bits */ - Word16 nb_sfm, - const Word16 *sfm_start, - const Word16 *sfm_end, - const Word16 *sfmsize, - Word16 *R, /* Q3 */ - Word16 *Rs, - Word16 *npulses, - Word16 *maxpulse, - const Word16 core -) -{ - Word16 i; - Word16 R_upd; /* Q3 */ - Word16 ord[NB_SFM_MAX]; - Word16 fg_pred[NB_SFM_MAX]; - Word16 pvq_bits; - - Word16 pulse_vector[L_FRAME48k]; - Word16 gopt[NB_SFM]; - Word16 gain_bits_array[NB_SFM]; - Word16 gain_bits_tot; - - - R_upd = shl(bits_tot, 3); - gain_bits_tot = assign_gain_bits_fx( core, nb_sfm, sfmsize, R, gain_bits_array, &R_upd ); - pvq_bits = shr(R_upd, 3); - - pvq_encode_frame_fx( st_fx, coefs_norm, *Q_coefs, coefs_quant, gopt, npulses, pulse_vector, sfm_start, sfm_end, sfmsize, nb_sfm, R, pvq_bits, core ); - - bits_tot = add(pvq_bits, gain_bits_tot); - - - IF( Rs != NULL ) - { - FOR (i=0; i < nb_sfm; i++) - { - if (npulses[i] <= 0) - { - Rs[i] = 0; - move16(); /* Update Rs in case no pulses were assigned */ - } - } - } - - FOR (i=0; i < nb_sfm; i++) - { - ord[i] = i; - move16(); - if (npulses[i] <= 0) - { - R[i] = 0; - move16(); /* Update in case no pulses were assigned */ - } - } - - get_max_pulses_fx( sfm_start, sfm_end, ord, npulses, nb_sfm, pulse_vector, maxpulse ); - - /* Fine gain prediction */ - fine_gain_pred_fx( sfm_start, sfm_end, sfmsize, ord, npulses, maxpulse, R, nb_sfm, - coefs_quant, pulse_vector, fg_pred, core); - - fine_gain_quant_fx(st_fx, ord, nb_sfm, gain_bits_array, fg_pred, gopt); - - apply_gain_fx(ord, sfm_start, sfm_end, nb_sfm, fg_pred, coefs_quant); - *Q_coefs = 12; - - return bits_tot; -} - -void encode_energies_fx( - Encoder_State_fx *st_fx, - const Word16 *coefs, /* In block-floating point format with a common block-exponent - not used in this function. Hence, the block-exponent is - not in the parameter list. */ - const Word16 Q_coefs, - Word16 Np, - Word16 *dim_part, - Word32 *E_part, /* 32-bit Q15 */ - Word16 *bits_part, - Word16 *g_part, /* Q15 */ - Word16 qband, - Word16 *bits_left, - Word32 enr, - Word16 dim, - const Word16 strict_bits -) -{ - Word16 i, j, l_Np, r_Np; - Word16 l_bits, r_bits, l_dim, r_dim; - Word32 l_enr, r_enr; - Word16 l_gain, r_gain; - Word16 il, ir; - Word16 density; - Word16 phi; - Word16 index_phi = -1; - Word16 oppRQ3, qzero ; - Word16 angle; - Word32 sqrt_r_enr, sqrt_l_enr; - Word16 exp1, exp2, tmp; - l_Np = shr(Np, 1); - r_Np = sub(Np, l_Np); - - l_enr = L_deposit_l(0); - l_bits = 0; - move16(); - l_dim = 0; - move16(); - FOR (i = 0; i < l_Np; i++) - { - l_dim = add(l_dim, dim_part[i]); - } - FOR (j = 0; j < l_dim; j++) - { - /* This is of paramount importance that the number of bits down-shift - * must be identical to that used to compute "enr" in pvq_encode_band_fx(). - * Otherwise, the subsequent "r_enr" will be computed incorrectly. - */ - tmp = shr(coefs[j], 2); - l_enr = L_mac0(l_enr, tmp, tmp); - } - r_enr = L_sub(enr, l_enr); - r_dim = sub(dim, l_dim); - - obtainEnergyQuantizerDensity_fx(dim, qband, &density); - sqrt_r_enr = Sqrt_l(r_enr, &exp1); - sqrt_l_enr = Sqrt_l(l_enr, &exp2); - - IF (sub(exp1, exp2) < 0) - { - sqrt_l_enr = L_shr(sqrt_l_enr, shr(sub(exp2, exp1), 1)); - } - ELSE IF (sub(exp2, exp1) < 0) - { - sqrt_r_enr = L_shr(sqrt_r_enr, shr(sub(exp1, exp2), 1)); - exp1 = exp2; - move16(); - } - - exp1 = add(shl(sub(Q_coefs, 2), 1), add(31, exp1)); /* 2x exponent */ - IF (sub(s_and(exp1, 1), 1) == 0) - { - sqrt_r_enr = Mult_32_16(sqrt_r_enr, 23170); /* Q(exp1/2) */ - sqrt_l_enr = Mult_32_16(sqrt_l_enr, 23170); /* Q(exp1/2) */ - } - - IF (sqrt_r_enr != 0) - { - angle = atan2_fx(sqrt_r_enr, sqrt_l_enr); /* Q14 */ - } - ELSE - { - angle = 0; - move16(); - } - - phi = mult_r(angle, 20861); - - rangeCoderFinalizationFBits_fx((Word16)st_fx->rc_num_bits_fx, (UWord32)st_fx->rc_range_fx, &qzero); - densityAngle2RmsProjEnc_fx(density, phi , &index_phi, &ir, &il, &oppRQ3); - densityIndexSymbolEncode_fx( st_fx, density , r_dim, l_dim , index_phi ); - - - - l_gain = il; /* Q15 */ move16(); - r_gain = ir; /* Q15 */ move16(); - - FOR (i = 0; i < l_Np; i++) - { - g_part[i] = mult_r(l_gain, g_part[i]); - } - - FOR (i = l_Np; i < Np; i++) - { - g_part[i] = mult_r(r_gain, g_part[i]); - } - - NearOppSplitAdjustment_fx( qband, qzero, st_fx->rc_num_bits_fx, st_fx->rc_range_fx, *bits_left, - strict_bits, Np, dim_part[0], dim_part[Np-1], - l_dim, r_dim, oppRQ3, - &l_bits, &r_bits, bits_left); - - IF (sub(l_Np, 1) > 0) - { - encode_energies_fx( st_fx, coefs, Q_coefs, l_Np, dim_part, E_part, bits_part, g_part, l_bits, bits_left, l_enr, l_dim, strict_bits ); - } - ELSE - { - E_part[0] = l_enr; - move32(); - bits_part[0] = l_bits; - move16(); - } - IF (sub(r_Np, 1) > 0) - { - encode_energies_fx( st_fx, &coefs[l_dim], Q_coefs, r_Np, &dim_part[l_Np], &E_part[l_Np], &bits_part[l_Np], &g_part[l_Np], r_bits, bits_left, r_enr, r_dim, strict_bits ); - } - ELSE - { - E_part[1] = r_enr; - move32(); - bits_part[1] = r_bits; - move16(); - } - - return; -} - - -void densityIndexSymbolEncode_fx( - Encoder_State_fx *st_fx, - const Word16 density , - const Word16 r_dim, - const Word16 l_dim, - const Word16 index_phi -) -{ - Word16 angle, c, densitySubIndex, densitySubC; - Word32 sym_freq, cum_freq, tot; - Word32 acc; - UWord16 lsb; - - sym_freq = L_deposit_l(1); - - IF( s_and((Word16)0xFFFE, density) != 0 ) /* even */ - { - angle = atan2_fx(SQRT_DIM_fx[r_dim], SQRT_DIM_fx[l_dim]); - angle = shl(angle, 1); - angle = mult_r(angle, 20861); - c = mult_r(density, angle); - - densitySubIndex = sub(density, index_phi); - densitySubC = sub(density, c); - - IF (c == 0) - { - tot = L_mac0(1L, density, add(density, 1)); - sym_freq = L_deposit_l(add(shl(sub(density, index_phi), 1), 1)); - cum_freq = L_mac0(L_mult(index_phi, density), index_phi, 1); - } - ELSE IF (sub(c, density) == 0) - { - tot = L_mac0(1L, density, add(density, 1)); - sym_freq = L_deposit_l(add(shl(index_phi, 1), 1)); - cum_freq = L_mult0(index_phi, index_phi); - } - ELSE - { - acc = L_mult0(density, c); /* density*c */ - Mpy_32_16_ss(acc, densitySubC, &acc, &lsb); /* density*c*(density - c) */ - acc = L_or(L_shl(acc, 16), L_and(lsb, 0xffffL)); /* Concatenate acc and lsb forming 48-bit; upshift 16 bits; keep 32 MSB. */ - acc = L_shr(acc, 1); /* Compensate fractional mode multiply (Mpy_32_16_ss) */ - tot = L_add(L_add(acc, (Word32)density), 1L); /* density*c*(density - c) + density + 1 */ - IF (sub(index_phi, c) <= 0) - { - sym_freq = L_mac(1L, index_phi, densitySubC); - acc = L_mult0(densitySubC, sub(index_phi, 1)); - acc = L_add(acc, 1); - Mpy_32_16_ss(acc, index_phi, &acc, &lsb); - acc = L_or(L_shl(acc, 16), L_and(lsb, 0xffffL)); - cum_freq = L_shr(acc, 1); - } - ELSE - { - sym_freq = L_mac(1L, densitySubIndex, c); - acc = L_mult0(densitySubIndex, add(densitySubIndex, 1)); - Mpy_32_16_ss(acc, c, &acc, &lsb); - acc = L_or(L_shl(acc, 16), L_and(lsb, 0xffffL)); - acc = L_shr(acc, 1); - acc = L_sub(acc, (Word32)index_phi); - acc = L_add(add(density, 1), acc); - cum_freq = L_sub(tot, acc); - } - } - - rc_encode_fx(st_fx, cum_freq, sym_freq, tot); - } - - return; -} - -/*--------------------------------------------------------------------------* - * calc_pvq_splits() - * - * Calculate the number of segments needed - *--------------------------------------------------------------------------*/ - -static Word16 calc_pvq_splits_fx( /* o : Number of segments */ - Encoder_State_fx *st_fx, /* i/o: Encoder state */ - const Word16 band_bits, /* i : Band bit rate */ - const Word16 sfmsize, /* i : Band width */ - const Word16 *y, /* i : Target vector */ - const Word16 Q_y, /* i : Q point of y */ - Word16 *bits /* o : Consumed bits */ -) -{ - Word16 Np; - Word16 Npart; - Word16 i,j; - Word16 E[MAX_SPLITS]; - Word16 Emean, eTotal; - Word16 tmp, expo; - const Word16 *pY; - Word16 max_dev,qPoint; - Word32 acc, acc1; - - IF (band_bits == 0) - { - Np = 1; - move16(); - } - ELSE - { - acc = L_mult0(band_bits, 0x7a44); - Np = extract_l(L_shr(acc, 23)); /* Get integer part. */ - if (L_and(acc, 0x7fffffL) != 0) /* If fractional part != 0, add 1. */ - { - Np = add(Np, 1); /* ceiling operation */ - } - } - *bits = 0; - move16(); - - IF (sub(Np, MAX_SPLITS) < 0) - { - acc = L_mult0(8*THR_ADD_SPLIT, sfmsize); - IF (L_sub(band_bits, acc) > 0) - { - Npart = extract_l((Word32)intLimCDivPos_fx(UL_deposit_l((UWord16)sfmsize), Np)); - *bits = 8; - move16(); - eTotal = 0; - move16(); - pY = y; - qPoint = shl(Q_y, 1); /* acc in 2*Q_y */ - FOR (i = 0; i < Np; i++) - { - acc = L_deposit_l(0); - FOR (j = 0; j < Npart; j++) - { - acc= L_mac0(acc, *pY, *pY); - pY++; - } - acc = L_shr(acc, qPoint); - - E[i] = sub(30, norm_l(L_max(1L,acc))); /* L_max needed to handle low subvector levels */ - eTotal = add(eTotal, E[i]); - } - - Emean = ratio(eTotal, Np, &expo); - Emean = shr(Emean, add(14 - 8, expo)); /* Emean in Q8 */ - - max_dev = -1; - move16(); - FOR (i = 0; i < Np; i++) - { - tmp = abs_s(sub(shl(E[i], 8), Emean)); /* in Q8 */ - max_dev = s_max(tmp, max_dev); - } - - acc = L_sub(L_shl(Np, 5 + 3 + 8), L_shl(band_bits, 8)); /* NB: max_dev in Q8 */ - acc1 = L_shl(L_mult0(Np, max_dev), 3); - - tmp = 0; - move16() ; - if( L_sub(acc1, acc) > 0) - { - tmp = 1; - move16(); - } - rc_enc_bits_fx(st_fx, tmp, 1); - Np = add(Np, tmp); - } - } - - /* Check constraints for number of splits */ - /* The following code assumes that PVQ_MAX_BAND_SIZE is 64 */ - i = shr(sfmsize, 6); /* 6 = log2(64) = log2(PVQ_MAX_BAND_SIZE) */ - if (s_and(sfmsize, 0x3f) != 0) - { - i = add(i, 1); /* ceiling operation */ - } - - Np = s_max(i, Np); - Np = s_min(MAX_SPLITS, Np); - Np = s_min(sfmsize, Np); /* The code line assumes that MIN_BAND_SIZE is 1 */ - return Np; -} - - diff --git a/src/libs/libevs/lib_enc/pvq_encode.cpp b/src/libs/libevs/lib_enc/pvq_encode.cpp new file mode 100644 index 00000000..d4bd8aee --- /dev/null +++ b/src/libs/libevs/lib_enc/pvq_encode.cpp @@ -0,0 +1,161 @@ +/*==================================================================================== + EVS Codec 3GPP TS26.443 Nov 13, 2018. Version 12.11.0 / 13.7.0 / 14.3.0 / 15.1.0 + ====================================================================================*/ + +#include "options.h" +#include "prot.h" +#include "rom_com.h" +#include "prot.h" +#include "math.h" + +static void pyramidSearch(const float *s, short L, short Ptot, float A, short *ztak, float *stak ) ; + +void pvq_encode( + Encoder_State *st, + const float *x, /* i: vector to quantize */ + short *y, /* o: quantized vector (non-scaled int)*/ + float *xq, /* o: quantized vector (scaled float) */ + const short pulses, /* i: number of allocated pulses */ + const short dim, /* i: Length of vector */ + const float gain /* i: Gain */ +) +{ + PvqEntry entry; + + pyramidSearch(x, dim, pulses, gain, y, xq ); + + entry = mpvq_encode_vec(y, dim, pulses); + if(dim != 1) + { + rc_enc_bits(st, (unsigned int)entry.lead_sign_ind, 1); + rc_enc_uniform(st, entry.index, entry.size); + } + else + { + rc_enc_bits(st, (unsigned int)entry.lead_sign_ind, 1); + } + return; + +} + +static float L1norm( + const float *s, + float *abso_s, + short *sign_s, + short L +) +{ + int i; + float ftmp, r = 0.0f; + + for( i=0; i < L; i++ ) + { + ftmp = s[i]; + sign_s[i] = (short)sign(ftmp); + abso_s[i] = fabs(ftmp); + r += abso_s[i]; + } + return r; +} + + +void pyramidSearch(const float *s, + short L, + short Ptot, + float A, + short *ztak, + float *stak + ) +{ + short i, high_pulse_dens; + short z[PVQ_MAX_BAND_SIZE]; + float sL1; + float energy,xcorr; + short P; + float energy1,energy2; + float xcorr1sq, xcorr2sq ; + float zscale, sscale; + float abso_s[PVQ_MAX_BAND_SIZE]; + short sign_s[PVQ_MAX_BAND_SIZE]; + short n = 0; + + high_pulse_dens = Ptot > (short )(0.501892089843750f * L); + sL1 = L1norm(s, abso_s,sign_s, L ); + if (high_pulse_dens && sL1 > 0 && A>0) + { + P = Ptot - PYR_OFFSET; + zscale = P/sL1; + for(i=0; i < L; i++) + { + z[i] = floor(zscale * abso_s[i]) ; + } + } + else + { + for( i=0; i < L; i++) + { + z[i] = 0; + } + } + + energy = 0.0f; + if (sL1 > 0 && A > 0) + { + xcorr = 0.0f; + P = 0; + for( i = 0; i < L; i++) + { + xcorr += abso_s[i] * z[i]; + energy += z[i] * z[i]; + P += z[i]; + } + energy = 0.5f*energy; + while( P < Ptot) + { + energy += 0.5f; + n = 0; + xcorr1sq = xcorr + abso_s[0]; + xcorr1sq *= xcorr1sq; + energy1 = energy + z[0]; + for( i = 1; i < L; i++) + { + xcorr2sq = xcorr + abso_s[i] ; + xcorr2sq *= xcorr2sq; + energy2 = energy + z[i] ; + + if ((xcorr1sq*energy2) < (xcorr2sq*energy1)) + { + n = i; + xcorr1sq = xcorr2sq; + energy1 = energy2; + } + } + z[n]++; + xcorr += abso_s[n]; + energy = energy1; + P++; + } + } + else + { + if (L > 1) + { + z[0] = (short)(Ptot*0.5f); + z[L-1] = - (Ptot - z[0]); + energy = 0.5f*(z[0] * z[0] + z[L-1] * z[L-1]); + } + else + { + z[0] = Ptot; + energy = 0.5f*(z[0] * z[0]); + } + } + + sscale = (float) A/(float)sqrt(2.0f * energy); + for(i = 0; i < L; i++) + { + ztak[i] = z[i] * sign_s[i]; + stak[i] = sscale * ztak[i] ; + } + return; +} diff --git a/src/libs/libevs/lib_enc/pvq_encode_fx.cpp b/src/libs/libevs/lib_enc/pvq_encode_fx.cpp deleted file mode 100755 index a19b5152..00000000 --- a/src/libs/libevs/lib_enc/pvq_encode_fx.cpp +++ /dev/null @@ -1,370 +0,0 @@ -/*==================================================================================== - EVS Codec 3GPP TS26.442 Apr 03, 2018. Version 12.11.0 / 13.6.0 / 14.2.0 - ====================================================================================*/ - -#include "options.h" /* Compilation switches */ -#include "cnst_fx.h" -#include "stl.h" -#include "prot_fx.h" -#include "rom_com_fx.h" - -#include -/* PVQ MIXED_SEARCH_LOOP: - low precision 16/32 + energy selective high precision 32/64, - mixed perf , 10 dB SEGSNR better than the low precision loop only, - active if k>=128 and accumulated energy is high enough, - comes at a controlled complexity cost, as dimensions decrease for high k's*/ - -static -Word16 max_val_fx( /* o : maximum value in the input vector */ - const Word16 *vec, /* i : input vector */ - const Word16 lvec /* i : length of input vector */ -) -{ - Word16 j,tmp; - - tmp = vec[0]; - move16(); - FOR ( j=1 ; j 0 ); -} - - -/* The inner search loop for one single additional unit pulse, starting from pulse_tot , - with information about required energy precision/down scaling for the dim loop in en_dn_shift, - and the current max_xabs absolute value to be used for an near optimal correlation upscaling. - returns the index of the best positioned unit pulse in imax -*/ -static -Word16 one_pulse_search(const Word16 dim, /* vector dimension */ - const Word16* x_abs, /* absolute vector values */ - Word16* y, /* output vector */ - Word16 *pulse_tot_ptr, - Word32* L_xy_ptr, /* accumulated correlation */ - Word32* L_yy_ptr, /* accumulated energy */ - Word16 high_prec_active, - Word16 en_dn_shift, - Word16 max_xabs) /* current accumulated max amplitude for pulses */ -{ - Word16 i, corr_up_shift, corr_tmp, imax, corr_sq_tmp, en_max_den, cmax_num, en_tmp; - Word32 L_tmp_en_lc, L_tmp_corr ; - Word32 L_tmp_en, L_en_max_den, L_corr_sq_max, L_tmp_corr_sq; - Word32 L_left_h, L_right_h; - UWord32 UL_left_l, UL_right_l, UL_dummy; - Word32 L_tmp; - UWord16 u_sgn; - - en_tmp = en_dn_shift; /* dummy assignment to avoid compiler warning for unused parameter */ - - /* maximize correlation precision, prior to every unit pulse addition in the vector */ - corr_up_shift = norm_l(L_mac(*L_xy_ptr, 1, max_xabs)); /* pre analyze worst case L_xy update in the dim loop , 2 ops */ - imax = -1; /* not needed for search, only added to avoid compiler warning */ - - /* clean BE code, with split out low/high precision loops */ - /* activate low complexity en/corr search section conditionally if resulting vector energy is within limits */ - /* typical case for higher dimensions */ - - IF( high_prec_active == 0 ) - { - en_max_den = 0; /*move16()*/; /* OPT: move saved by using high_prec_active as en_max_den */ /* 1 op */ - cmax_num = -1; - move16(); /* req. to force a 1st update for n==0 */ /* 1 op */ - - FOR(i = 0; i < dim; i++) /* FOR 3 ops */ - { - L_tmp_corr = L_shl(L_mac(*L_xy_ptr,1,x_abs[i]), corr_up_shift ); /* actual in-loop target value, 2 ops */ - corr_tmp = round_fx(L_tmp_corr); /* 1 op */ - corr_sq_tmp = mult(corr_tmp, corr_tmp); /* CorrSq, is a 16bit for low compelxity cross multiplication 1 op */ - - L_tmp_en_lc = L_mac(*L_yy_ptr, 1,y[i] ); /*Q1 result , energy may span up to ~14+1(Q1)+1(sign)=16 bits, 1 op */ - /* extract_l without shift can always be used for this section as energy is guaranteed to stay in the lower word, 1 op */ - en_tmp = extract_l(L_tmp_en_lc); /* L_shl + round_fx could also be used also but then adds an uphift cost (2-3 ops)*/ - - /* 16/32 bit comparison WC (4 +1+1 + (1+1+1) = 9 */ - IF( L_msu(L_mult(corr_sq_tmp, en_max_den),cmax_num , en_tmp) > 0) /* use L_mult and then a L_msu, 2 ops */ - { - cmax_num = corr_sq_tmp; - move16(); /* 1 op */ - en_max_den = en_tmp; - move16(); /* 1 op */ - imax = i; - move16(); /* 1 op */ - } - } /* dim */ - - } - ELSE - { - /* High resolution section activated when vector energy is becoming high (peaky or many pulses) */ - /* BASOP operator Mpy32_32_ss used to allow higher resolution for both the CorrSq term and the Energy term */ - - L_en_max_den = L_deposit_l(0); /* 1 op */ - L_corr_sq_max = L_deposit_l(-1); /* req. to force a 1st update */ /* 1 op */ - - FOR(i = 0; i < dim; i++) /* FOR 3 ops */ - { - L_tmp_corr = L_shl(L_mac(*L_xy_ptr,1,x_abs[i]), corr_up_shift ); /* actual in loop WC value 2 ops */ - Mpy_32_32_ss(L_tmp_corr,L_tmp_corr, &L_tmp_corr_sq, &UL_dummy); /* CorrSq 32 bits, 4 ops */ - - L_tmp_en = L_mac(*L_yy_ptr, 1, y[i]); /* Q1,energy may span up to sign+19 bits , 1 op */ - /* For highest accuracy use pairs of maximum upshifted 32x32 bit signed values */ - /* (L_tmp_corr_sq / L_tmp_en) > (L_corr_sq_max/L_en_max_den) */ - /* (L_tmp_corr_sq * L_en_max_den) > (L_corr_sq_max * L_tmp_en) */ - Mpy_32_32_ss( L_en_max_den, L_tmp_corr_sq, &L_left_h, &UL_left_l); /* 4 ops */ - Mpy_32_32_ss( L_tmp_en, L_corr_sq_max, &L_right_h, &UL_right_l); /* 4 ops */ - - /* STL optimized "Lazy evaluation" of: - IF( (L_left_h > L_right_h) || ( (L_left_h == L_right_h) && (UL_left_l > UL_right_l) ) - */ - /* 32/64 bit Lazy eval comparison WC cost is (1+ 1+1+1 + 4 +(2+2+1) = 13 , and average is ~12 */ - /* Unoptimized 32/64 bit comparison WC cost is (1+1+ 2x2 + 4 +(2+2+1) = 15 */ - L_tmp = L_sub(L_left_h, L_right_h); /* high signed word check 1 op */ - u_sgn = 0; - move16(); /* 1 op */ - if(L_tmp == 0) /* L_tmp high Word testing is always needed */ - { - /* The returned UL value from UL_subNs is not needed, only u_sgn is needed */ - UL_subNs(UL_right_l, UL_left_l, &u_sgn); /* low unsigned word check, note left/right order switch of ">" due to ">=" inside UL_subNs, 1 op */ - } - if( u_sgn != 0) - { - L_tmp = L_add(L_tmp, 1); /* 0+1 --> 1 use wrap/sign result of low Word u_sgn check */ /* 1 op */ - } - IF( L_tmp > 0 ) /* IF 4 ops */ - { - L_corr_sq_max = L_add(L_tmp_corr_sq, 0); /* 1-2 ops */ - L_en_max_den = L_add(L_tmp_en, 0); /* 1-2 ops */ - imax = i; - move16(); /* 1 op */ - } - } /* dim loop */ - - } - /* Complexity comparison per coeff for low precision vs. high precision - low precision: pulse_tot <= 127, 16 bit: WC 2+3 +(15)*dim ops, dim=5 --> 5+15*5 = 90 ops, 18 ops/coeff - high precision: pulse_tot > 127, 32 bit: WC 1+3+3 +(26-28)*dim ops, WC-band dim=5 --> 7+28*5 = 147 ops, 29 ops/coeff ~61% increase - */ - - /* finally add found unit pulse contribution to past L_xy, Lyy, for next pulse loop */ - *L_xy_ptr = L_mac(*L_xy_ptr, x_abs[imax], 1); /* Q12+1 */ - *L_yy_ptr = L_mac(*L_yy_ptr, 1, y[imax]); - - y[imax] = add(y[imax],1); - move16(); /* Q0 added pulse */ - (*pulse_tot_ptr) = add((*pulse_tot_ptr) ,1); /* increment total pulse sum */ - - return imax; -} -/*-----------------------------------------------------------------------* - * Function pvq_encode_fx() * - * * - *-----------------------------------------------------------------------*/ -void pvq_encode_fx( - Encoder_State_fx *st_fx, - const Word16 *x, /* i: vector to quantize Q15-3=>Q12 */ - Word16 *y, /* o: raw pulses (non-scaled short) Q0 */ - Word16 *xq, /* o: quantized vector Q15 */ - Word32 *L_xq, /* o: quantized vector Q31 fot eval */ - const Word16 pulses, /* i: number of allocated pulses */ - const Word16 dim, /* i: Length of vector */ - const Word16 neg_gain /* i: - Gain use - negative gain in Q15 0..1 */ -) -{ - Word16 i; - Word16 pulse_tot; - Word16 xabs[PVQ_MAX_BAND_SIZE]; - Word16 max_xabs; - Word32 L_xsum; - Word32 L_proj_fac; - Word32 L_yy, L_xy; - Word16 max_amp_y, imax; - Word16 k, en_margin, en_dn_shift, high_prec_active ; - - Word32 L_num, L_tmp; - Word16 proj_fac, tmp, shift_den,shift_num,shift_delta, num,den; - - UWord16 u16_tmp; - Word16 dim_m1; - Word32 L_isqrt; - Word16 neg_gain_norm, shift_tot; - Word16 high_pulse_density_flag; - PvqEntry_fx entry; - - L_proj_fac = 4096; - L_xsum = L_deposit_h(0); - max_xabs = -1; - move16(); - - FOR( i = 0; i < dim; i++) - { - xabs[i] = abs_s(x[i]); - move16(); /* Q12 */ - max_xabs = s_max(max_xabs, xabs[i] ); /* for efficient search correlation scaling */ - L_xsum = L_mac0(L_xsum, 1, xabs[i] ); /* stay in Q12 */ - y[i] = 0; - move16(); /* init, later only non-zero values need to be normalized */ - } - - test(); - IF( L_xsum == 0 || neg_gain == 0 ) - { - pulse_tot = pulses; - move16(); - dim_m1 = sub(dim,1); - y[dim_m1] = 0; - move16(); - y[0] = shr(pulses,1); - move16(); - y[dim_m1] = add(y[dim_m1], sub(pulses, y[0])); - move16(); - L_yy = L_mult(y[0],y[0]); /* L_yy needed for normalization */ - if(dim_m1 != 0) - { - L_yy = L_mac(L_yy, y[dim_m1],y[dim_m1]); /* (single basop) */ - } - } - ELSE - { - - num = sub(pulses, PYR_OFFSET); - high_pulse_density_flag = pyramidSearchProjInit_fx(dim, pulses ); - - test(); - IF( (num > 0) && (high_pulse_density_flag != 0) ) - { - shift_den = norm_l(L_xsum); /* x_sum input Q12 */ - den = extract_h(L_shl(L_xsum, shift_den)); /* now in Q12+shift_den */ - - L_num = L_deposit_l(num); - shift_num = sub(norm_l(L_num) ,1); - L_num = L_shl(L_num, shift_num) ; /* now in Q0 +shift_num -1 */ - proj_fac = div_l(L_num, den ); /* L_num always has to be less than den<<16 */ - - shift_delta=sub(shift_num,shift_den); - L_proj_fac = L_shl(L_deposit_l(proj_fac), sub(9, shift_delta)); /* bring to a fixed Q12 */ - } - - pulse_tot = 0; - move16(); - L_yy = L_deposit_l(0); - L_xy = L_deposit_l(0); - test(); - IF( (num > 0 ) && (high_pulse_density_flag != 0 ) ) - { - FOR( i = 0; i < dim ; i++) /* max 64 */ - { - Mpy_32_16_ss(L_proj_fac,xabs[i],&L_tmp,&u16_tmp); /*Q12 *Q12 +1 */ - y[i] = extract_l(L_shr( L_tmp, 12+12-16+1 )); - move16();/* Q12 *Q12 -> Q0 */ - - pulse_tot = add(pulse_tot, y[i]); /* Q0 */ - L_yy = L_mac(L_yy, y[i], y[i]); /* Energy, result will scale up by 2 by L_mac */ - L_xy = L_mac(L_xy, xabs[i], y[i]); /* Corr, Q0*Q12 +1 --> Q13 */ - } - } - - - L_yy=L_shr(L_yy,1); - IF (sub(pulses,127)<=0 ) - { - /* LC inner loop, enters here always for dimensions 6 and higher, and also sometimes for dimensions 1 .. 5 */ - /* ( if high energy precision is inactive, max_amp_y is not needed , no max_amp_y(k-1) update ) */ - FOR (k=pulse_tot; k +#include +#include "options.h" +#include "prot.h" +#include "cnst.h" +#include "rom_com.h" + + +/*-------------------------------------------------------------------------* + * Local functions * + *-------------------------------------------------------------------------*/ + +static int gain_enc_uv( const float *code, int lcode, float *gain_pit, float *gain_code, + ACELP_CbkCorr *coeff, float *past_gcode, float *gain_inov ); + +static int gain_enc_gacelp_uv( const float *code, const float *code2, int lcode, const float mean_ener, float *gain_pit, float *gain_code, + float *gain_code2, ACELP_CbkCorr *coeff, float *past_gcode, float *gain_inov, short noisy_speech_flag ); + + /*-------------------------------------------------------------------------* * procedure q_gain2_plus * * ~~~~~~~~~~~~~~~~~~~~~~ * @@ -12,103 +31,56 @@ * The pitch gain and the code gain are vector quantized and the * * mean-squared weighted error criterion is used in the quantizer search. * *-------------------------------------------------------------------------*/ -#include -#include "prot_fx.h" -#include "stl.h" -#include "basop_util.h" -#include "rom_com_fx.h" - -enum FUNC_GAIN_ENC -{ - FUNC_GAIN_ENC_MLESS = 0, /* Memory-less gain coding */ - FUNC_GAIN_ENC_2 = 1, /* AMR-WB gains quantizer (6bits/subfr (mode 4) or 7bits/subfr (mode 5)) */ /* !!! to be removed !!! */ - FUNC_GAIN_ENC_UV, /* UV gains quantizer (5bits/subfr) */ - FUNC_GAIN_ENC_GACELP_UV /* UV GACELP gain quantizer ((7=5-2bits/subfr) */ -}; - - void encode_acelp_gains( - Word16 *code, - Word16 gains_mode, - Word16 mean_ener_code, - Word16 clip_gain, + float *code, + int gains_mode, + float mean_ener_code, + short clip_gain, ACELP_CbkCorr *g_corr, - Word16 *gain_pit, - Word32 *gain_code, - Word16 **pt_indice, - Word32 *past_gcode, - Word16 *gain_inov, - Word16 L_subfr - , Word16 *code2, - Word32 *gain_code2 - ,Word8 noisy_speech_flag /* (i) : noisy speech flag */ + float *gain_pit, + float *gain_code, + int **pt_indice, + float *past_gcode, + float *gain_inov, + int L_subfr, + float *code2, + float *gain_code2, + short noisy_speech_flag ) { - Word16 index = 0, func_type = 0; + int index = 0; - BASOP_SATURATE_ERROR_ON; - - SWITCH(gains_mode) + if (((gains_mode>0) && (gains_mode <4))) { - case 1: - case 2: - case 3: /* Memory-less gain coding */ - gains_mode = sub(gains_mode, 1); - func_type = FUNC_GAIN_ENC_MLESS; - move16(); - BREAK; - case 4: - case 5: - assert(0); - BREAK; - case 6: - /* UV gains quantizer (6 bits/subfr) */ - gains_mode = sub(gains_mode, 6); - func_type = FUNC_GAIN_ENC_UV; - move16(); - BREAK; - case 7: - gains_mode = sub(gains_mode, 7); - func_type = FUNC_GAIN_ENC_GACELP_UV; - move16(); - BREAK; - default: + index = Mode2_gain_enc_mless( code, L_subfr, gain_pit, gain_code, g_corr, mean_ener_code, + clip_gain, past_gcode, gain_inov,gains_mode-1 ); + } + else if (gains_mode == 6) + { + /* UV gains quantizer (6bits/subfr) */ + index = gain_enc_uv(code, L_subfr, gain_pit, gain_code, g_corr, past_gcode, gain_inov ); + } + else if (gains_mode == 7) + { + /* GACELP_UV gains quantizer (7=5-2bits/subfr) */ + index = gain_enc_gacelp_uv(code, code2, L_subfr, mean_ener_code, gain_pit, gain_code,gain_code2, g_corr, past_gcode, gain_inov, noisy_speech_flag ); + } + else + { fprintf(stderr, "invalid gains coding for acelp!\n"); assert(0); - func_type = 0; - move16(); /*To avoid compiler warning*/ - BREAK; } - IF( func_type == FUNC_GAIN_ENC_MLESS ) - { - index = gain_enc(code, - L_subfr, gain_pit, gain_code, g_corr, mean_ener_code, - clip_gain, past_gcode, gain_inov, gains_mode, func_type); - } - ELSE - { - index = gain_enc_uv(code, - code2, - L_subfr, gain_pit, gain_code, - gain_code2, - noisy_speech_flag, - g_corr, mean_ener_code, - past_gcode, gain_inov, - func_type); - } - - move16(); **pt_indice = index; (*pt_indice)++; - BASOP_SATURATE_ERROR_OFF; + return; } /*---------------------------------------------------------------------* - * procedure gain_enc_mless + * procedure Mode2_gain_enc_mless * Quantization of pitch and codebook gains. * - an initial predicted gain, gcode0, is first determined based on * the predicted scaled innovation energy @@ -117,537 +89,279 @@ void encode_acelp_gains( * - the mean-squared weighted error criterion is used for the quantizer search *---------------------------------------------------------------------*/ -Word16 gain_enc( /* o : quantization pitch index */ - const Word16 *code, /* i : algebraic excitation */ - Word16 lcode, /* (i) : Subframe size in range: 40,64,80 */ - Word16 *gain_pit, /* o : quantized pitch gain */ - /* i/o : only func=1,coder_type=1 quantized pitch gain */ - Word32 *gain_code, /* o : quantized codebook gain */ - ACELP_CbkCorr *g_coeff, /* i : correlations , -2,, -2 and 2 */ - Word16 mean_ener, /* (i) : only func=0: mean_ener defined in open-loop (3 bits) */ - const Word16 clip_gain, /* i : only func=0,1: gain pitch clipping flag (1 = clipping) */ - Word32 *past_gcode, /* o : past gain of code */ - Word16 *gain_inov, /* (o) : Q12 innovation gain */ - const Word16 coder_type, /* (i) : only func=0,1: coder type */ - const Word16 func_type /* (i) : algorithm: 0=gain_enc_mless, 1=gain_enc_2 */ +int Mode2_gain_enc_mless( + const float *code, /* i : algebraic excitation */ + int lcode, /* (i) : Subframe size */ + float *gain_pit, /* o : quantized pitch gain */ + float *gain_code, /* o : quantized codebook gain */ + ACELP_CbkCorr *pcoeff, /* i/o : correlations , -2,, -2 and 2*/ + float mean_ener, /* (i) : mean_ener defined in open-loop (3 bits) */ + const short clip_gain, /* i : gain pitch clipping flag (1 = clipping) */ + float *past_gcode, /* (i/o): past gain of code */ + float *gain_inov, /* (o) : unscaled innovation gain */ + const short coder_type /* (i) : coder type */ ) { - Word16 i, j, index, size, min_index, exp_L_tmp1; - Word16 gcode0, gcode0_gi, exp_gcode0, exp_sum, exp_code, g_code_shl; + short index, i, size,size_clip; + const Word16 *p, *t_qua_gain; + float dist, dist_min, g_pitch, g_code, gcode0, ener_code; + ACELP_CbkCorr coeff; - Word16 g_code; - Word16 coeff0, coeff1, coeff2, coeff3, coeff4, exp_coeff0, exp_coeff1, exp_coeff2, exp_coeff3, exp_coeff4; - Word16 shr_coeff0, shr_coeff1, shr_coeff2, shr_coeff3, shr_coeff4; - const Word16 *p; - const Word16 *t_qua_gain; - Word32 L_tmp, dist_min, L_tmp1; - - - - assert((func_type != FUNC_GAIN_ENC_UV) && (func_type != FUNC_GAIN_ENC_GACELP_UV)); - - /* Debug test value (not instrumented) */ - gcode0 = -3000; - move16(); - - /*----------------------------------------------------------------* + /*-----------------------------------------------------------------* * - calculate the unscaled innovation energy * - calculate the predicted gain code - *----------------------------------------------------------------*/ + *-----------------------------------------------------------------*/ - /* gain_inov = 1.0f / sqrt((dot_product(code, code, L_SUBFR) + 0.01) / L_SUBFR) */ - L_tmp = calc_gain_inov(code, lcode, &L_tmp1, &exp_L_tmp1); - move16(); - *gain_inov = round_fx(L_shl(L_tmp, 15-3)); /* gain_inov in Q12 */ - - /*----------------------------------------------------------------* - * calculate the predicted gain code - *----------------------------------------------------------------*/ - IF (func_type == FUNC_GAIN_ENC_MLESS) + if(coder_type == 0) { - /*j = 10 * log10((dot_product(code, code, lcode) + 0.01) / lcode) */ - j = BASOP_Util_lin2dB(L_tmp1, exp_L_tmp1, 1); /* Q8 */ - - /* predicted codebook gain */ - gcode0 = sub(mean_ener, j); /* Q8 */ - + *gain_inov = 1.0f/ (float)sqrt( ( dotp( code, code, lcode ) + 0.01f ) / lcode ); + ener_code = 10 * (float)log10( ( dotp( code, code, lcode ) + 0.01f ) / lcode ); + gcode0 = (float) pow(10, 0.05 * (mean_ener - ener_code)); } + else + { + ener_code = 0.01F; + for(i=0; i and have been computed in Adpt_enr() and - * are in vector g_coeff[]. - *----------------------------------------------------------------*/ + *gain_inov = (float)sqrt((float)lcode / ener_code); - coeff0 = g_coeff->y1y1; - move16(); - exp_coeff0 = g_coeff->y1y1_e; - move16(); - coeff2 = g_coeff->y2y2; - move16(); - exp_coeff2 = g_coeff->y2y2_e; - move16(); - - coeff1 = g_coeff->xy1; - move16(); - exp_coeff1 = add(g_coeff->xy1_e, 1); - coeff3 = g_coeff->xy2; - move16(); - exp_coeff3 = add(g_coeff->xy2_e, 1); - coeff4 = g_coeff->y1y2; - move16(); - exp_coeff4 = add(g_coeff->y1y2_e, 1); - - /*---------------------------------------------------------------* - * Decode codebook gain and the adaptive excitation low-pass - * filtering factor (Finalize computation ) - *---------------------------------------------------------------*/ - - - /* gcode0 = pow(10, 0.05 * (Es_pred - Ei)) */ - /*----------------------------------------------------------------* - * gcode0 = pow(10.0, gcode0/20) gcode in Q8 - * = pow(2, 3.321928*gcode0/20) - * = pow(2, 0.166096*gcode0) - *----------------------------------------------------------------*/ - - /* Check if gcode0 was uninitialized. */ - assert(gcode0 != -3000); - - L_tmp = L_mult(gcode0, 5443/*0.166096f Q15*/); - exp_gcode0 = add(1,extract_l(L_shr(L_tmp, 24))); - L_tmp = L_lshl(L_tmp, 7); - L_tmp = L_and(0x7FFFFFFF, L_tmp); - - L_tmp = Pow2(30,round_fx(L_tmp)); - gcode0 = round_fx(L_tmp); - /* exponent of gcode0 = exp_gcode0 */ + ener_code = (float)(-10.0 * log10((float)lcode / ener_code)); + gcode0 = mean_ener - ener_code; + gcode0 = (float)pow(10.0,gcode0/20.0); /* predicted gain */ + } /*-----------------------------------------------------------------* * gain quantization initializations * - find the initial quantization pitch index * - set the gains searching range - *----------------------------------------------------------------*/ - - /*----------------------------------------------------------------* - * Find the best quantizer - * - * Before doing the computation we need to align exponents of coeff[] - * to be sure to have the maximum precision. - * - * In the table the pitch gains are in Q14, the code gains are in Q11 and - * are multiplied by gcode0 which have been multiplied by 2^exp_gcode0. - * Also when we compute g_pitch*g_pitch, g_code*g_code and g_pitch*g_code - * we divide by 2^15. - * Considering all the scaling above we have: - * - * exp_code = exp_gcode0 + 4 - * if (func_type == gain_enc_2) - * gcode0 *= gain_inov (in Q12) => exp_code += 3 - * - * g_pitch*g_pitch = +1+1 - * g_pitch = +1 - * g_code*g_code = (2*exp_code) - * g_code = exp_code - * g_pitch*g_code = + 1 + exp_code - * - * g_pitch*g_pitch * coeff[0] ;exp_max0 = exp_coeff[0] + 2 - * g_pitch * coeff[1] ;exp_max1 = exp_coeff[1] + 1 - * g_code*g_code * coeff[2] ;exp_max2 = exp_coeff[2] + (2*exp_code) - * g_code * coeff[3] ;exp_max3 = exp_coeff[3] + exp_code - * g_pitch*g_code * coeff[4] ;exp_max4 = exp_coeff[4] + 1 + exp_code - *----------------------------------------------------------------*/ - - exp_code = add(exp_gcode0, 4); - - exp_coeff0 = add(exp_coeff0, 2); - exp_coeff1 = add(exp_coeff1, 1); - exp_coeff2 = add(exp_coeff2, shl(exp_code, 1)); - exp_coeff3 = add(exp_coeff3, exp_code); - exp_coeff4 = add(exp_coeff4, add(1, exp_code)); - - /* Find maximum exponent */ - exp_sum = s_max(exp_coeff1, exp_coeff0); - exp_sum = s_max(exp_coeff2, exp_sum); - exp_sum = s_max(exp_coeff3, exp_sum); - exp_sum = s_max(exp_coeff4, exp_sum); - exp_sum = add(exp_sum,2); - - /* Align exponents of summands in loop far below. */ - shr_coeff0 = sub(exp_sum, exp_coeff0); - shr_coeff1 = sub(exp_sum, exp_coeff1); - shr_coeff2 = sub(exp_sum, exp_coeff2); - shr_coeff3 = sub(exp_sum, exp_coeff3); - shr_coeff4 = sub(exp_sum, exp_coeff4); - /* Codebook search */ - - dist_min = L_deposit_h(MAX_16); - - min_index = 0; - move16(); + *-----------------------------------------------------------------*/ + if( coder_type == 0) { - Word16 size_clip; - - - IF( coder_type == 0) - { - - t_qua_gain = E_ROM_qua_gain5b_const; - size_clip=9; - size=NB_QUA_GAIN5B; - } - ELSE IF(coder_type == 1) - { - - t_qua_gain = E_ROM_qua_gain6b_const; - size_clip=6; - size = NB_QUA_GAIN6B; /* searching range of the gain quantizer */ - } - ELSE - { - - t_qua_gain = E_ROM_qua_gain7b_const; - size_clip=21; - size = NB_QUA_GAIN7B; - } - - if ( sub(clip_gain,1) == 0) - { - size = sub(size, size_clip); /* limit pitch gain to 1.0 */ - } - gcode0_gi = gcode0; - move16(); - + t_qua_gain = E_ROM_qua_gain5b_const; + size_clip=9; + size = NB_QUA_GAIN5B; + } + else if(coder_type == 1) + { + t_qua_gain = E_ROM_qua_gain6b_const; + size_clip=6; + size = NB_QUA_GAIN6B; /* searching range of the gain quantizer */ + } + else + { + t_qua_gain = E_ROM_qua_gain7b_const; + size_clip=21; + size = NB_QUA_GAIN7B; } - move16(); - p = t_qua_gain; + if( clip_gain == 1 ) + { + size -= size_clip; /* limit pitch gain to 1.0 */ + } + + coeff = *pcoeff; + coeff.xy1 *= -2.0f; + coeff.xy2 *= -2.0f; + coeff.y1y2 *= 2.0f; + + /*-----------------------------------------------------------------* + * search for the best quantizer + *-----------------------------------------------------------------*/ + + p=t_qua_gain; + dist_min = FLT_MAX; index = 0; - move16(); - /* divide all coeff1,2,3,4 by coeff0 */ - /* in order to skip multiplication with coeff0 in loop */ - assert(coeff0 >= 0x4000); - coeff0 = div_s(0x4000,coeff0); - coeff1 = mult_r(coeff1,coeff0); - coeff2 = mult_r(coeff2,coeff0); - coeff3 = mult_r(coeff3,coeff0); - coeff4 = mult_r(coeff4,coeff0); - - FOR (i = 0; i < size; i++) + for (i = 0; i Q27 */ - exp_gcode0 = add(exp_gcode0,-11); - L_tmp = L_shl(L_tmp, exp_gcode0); /* Q27 -> Q16 */ - - - *gain_code = L_tmp; - move32(); - /* Q16/Q12 => Q5 */ - L_tmp = L_deposit_h(BASOP_Util_Divide3216_Scale(L_tmp,*gain_inov,&i)); - *past_gcode = L_shl(L_tmp,sub(i,15-12)); + *gain_pit = (float)(t_qua_gain[index*2])/(1<<14); + *gain_code = (float)(t_qua_gain[index*2+1])/(1<<11) * gcode0; + *past_gcode = *gain_code / *gain_inov; return index; } -Word16 gain_enc_uv( /* o : quantization pitch index */ - const Word16 *code, /* i : algebraic excitation */ - const Word16 *code2, /* i : gaussian excitation */ - Word16 lcode, /* (i) : Subframe size in range: 40,64,80 */ - Word16 *gain_pit, /* o : quantized pitch gain */ - Word32 *gain_code, /* o : quantized codebook gain */ - Word32 *gain_code2, /* o : quantized codebook gain */ - Word8 noisy_speech_flag, /* (i) : noisy speech flag */ - ACELP_CbkCorr *g_coeff, /* i : correlations , -2,, -2 and 2 */ - Word16 mean_ener, /* (i) : only func=0: mean_ener defined in open-loop (3 bits) */ - Word32 *past_gcode, /* o : past gain of code */ - Word16 *gain_inov, /* (o) : Q12 innovation gain */ - const Word16 func_type /* (i) : algorithm: 2=gain_enc_uv, 3=gain_enc_gacelp_uv */ +/*---------------------------------------------------------------------* +* procedure gain_enc_uv +* Quantization of pitch and codebook gains. +* - an initial predicted gain, gcode0, is first determined based on +* the predicted scaled innovation energy +* - the correction factor gamma = g_code / gcode0 is then vector quantized +* along with gain_pit +* - the mean-squared weighted error criterion is used for the quantizer search +*---------------------------------------------------------------------*/ + +static int gain_enc_uv( + const float *code, /* i : algebraic excitation */ + int lcode, /* (i) : Subframe size */ + float *gain_pit, /* o : quantized pitch gain */ + float *gain_code, /* o : quantized codebook gain */ + ACELP_CbkCorr *coeff, /* i/o : correlations , -2,, -2 and 2 */ + float *past_gcode, /* (i/o): past gain of code */ + float *gain_inov /* (o) : unscaled innovation gain */ ) { - Word16 i, index, exp_L_tmp1, tmp; - Word16 exp_gcode; - Word16 g_code; - Word32 L_tmp, L_tmp1; - Word8 gacelp_uv; - Word32 pred_nrg_frame; - Word16 exp_gcode2, g_code2, norm_code2; - Word16 c, c_e, c_index2, c_index2_e, c_first, c_first_e; - Word16 s, tmp1, s1; - Word16 index2; - const Word16 log2_scale=16; + short index; + float g_code,g_code_corr,g_code_nrg; - pred_nrg_frame = 0; /* to suppress compilation warnings */ - g_code2 = 0; /* to suppress compilation warnings */ - exp_gcode2 = 0; /* to suppress compilation warnings */ - - - assert((func_type != FUNC_GAIN_ENC_MLESS) ); - - /* Debug check value (not instrumented) */ - index2 = -3000; - move16(); - - gacelp_uv = 0; - move16(); - if (sub(func_type, FUNC_GAIN_ENC_GACELP_UV) == 0) - { - gacelp_uv = 1; - move16(); - } - - /*----------------------------------------------------------------* + /*-----------------------------------------------------------------* * - calculate the unscaled innovation energy - * - calculate the predicted gain code - *----------------------------------------------------------------*/ + *-----------------------------------------------------------------*/ - /* gain_inov = 1.0f / sqrt((dot_product(code, code, L_SUBFR) + 0.01) / L_SUBFR) */ - L_tmp = calc_gain_inov(code, lcode, NULL, NULL); - *gain_inov = round_fx(L_shl(L_tmp, 15-3)); /* gain_inov in Q12 */ + *gain_inov = 1.0f/ (float)sqrt( ( dotp( code, code, lcode ) + 0.01f ) / lcode ); - /*----------------------------------------------------------------* - * calculate the predicted gain code - *----------------------------------------------------------------*/ - IF (gacelp_uv != 0) + g_code_corr = coeff->xy2/(coeff->y2y2*(*gain_inov)); /*Correlation based*/ + + (void) g_code_nrg; + g_code=g_code_corr; + + /*90dB max of gain for 2^15 amplitude code, */ + if( g_code>0.000001f ) { - /* pred_nrg_frame = (float)pow(10.0,mean_ener/20.0); */ - L_tmp = L_mult(mean_ener, 10885/*0.166096f * 2 Q15*/); /* 6Q25 */ - pred_nrg_frame = BASOP_Util_InvLog2(L_sub(L_tmp, 503316480l/*15.f Q25*/)); /* 15Q16 */ + index=(int)(((20.f*log10(g_code)+30.f)/1.9f)+0.5f); - /* gcode = pred_nrg_frame * (*gain_inov); */ - L_tmp = Mpy_32_16_1(pred_nrg_frame, *gain_inov); /* 18Q13 */ - i = norm_l(L_tmp); - g_code = round_fx(L_shl(L_tmp, i)); - exp_gcode = sub(18, i); - - /* norm_code2 = 1.0f / sqrt((dot_product(code2, code2, lcode) + 0.01f) / lcode); */ - L_tmp = calc_gain_inov(code2, lcode, NULL, NULL); - norm_code2 = round_fx(L_shl(L_tmp, 15-3)); /* Q12 */ - - /* g_code2 = pred_nrg_frame * norm_code2; */ - L_tmp = Mpy_32_16_1(pred_nrg_frame, norm_code2); /* 18Q13 */ - i = norm_l(L_tmp); - g_code2 = round_fx(L_shl(L_tmp, i)); - exp_gcode2 = sub(18, i); - } - ELSE - { - g_code = *gain_inov; - move16(); - exp_gcode = 3; - move16(); - } - - tmp = BASOP_Util_Divide1616_Scale(g_coeff->xy2, mult_r(g_coeff->y2y2, g_code), &i); /*Correlation based*/ - L_tmp = L_shl( L_deposit_h(tmp), add(i, sub(g_coeff->xy2_e, add(g_coeff->y2y2_e, add(exp_gcode, log2_scale)))) ); - /* exponent of L_tmp is 16, accounted below by adding log2(2^16) */ - - index = 0; - move16(); - - IF (L_tmp > 0) - { - /*index = (int)(((20.f*log10(g_code)+30.f)/1.9f)+0.5f))); */ - /* Since ((20*log10(x)+30)/1.9)+0.5 = 63 (max index) implies x is between 2^15 and 2^16, - L_tmp might saturate at 65535 and above. That is why log2_scale is 16. */ - tmp = BASOP_Util_lin2dB(L_tmp, 16, 0); /* Q8 */ - - IF (gacelp_uv != 0) + if( index>63 ) { - L_tmp = L_mult(add(tmp, 5120/*20.0f Q8*/), 26214/*1.0f/1.25f Q15*/); + index=63; } - ELSE + else if(index<0) { - L_tmp = L_mult(add(tmp, 7680/*30.0f Q8*/), 17246/*1.0f/1.9f Q15*/); + index=0; } - - index = round_fx(L_shr(L_tmp, 8)); - index = s_max(0, s_min(63, index)); - if (gacelp_uv != 0) index = s_min(31, index); } - - /* *gain_code= (float) pow(10.f,(((index*1.9f)-30.f)/20.f)); */ - - /*----------------------------------------------------------------* - * gcode0 = pow(10.0, gcode0/20) - * = pow(2, 3.321928*gcode0/20) - * = pow(2, 0.166096*gcode0) - *----------------------------------------------------------------*/ - IF (gacelp_uv != 0) + else { - L_tmp = L_mac(-111465139l/*-0.166096*20.0f Q25*/,shl(index, 16-7), 6803/*0.166096f*1.25f Q15*/); - } - ELSE - { - L_tmp = L_mac(-167197708l/*-0.166096*30.0f Q25*/,shl(index, 16-7), 10341/*0.166096f*1.9f Q15*/); - } - i = add(1,extract_l(L_shr(L_tmp, 25))); - L_tmp = L_lshl(L_tmp, 6); - L_tmp = L_and(0x7FFFFFFF, L_tmp); - - L_tmp = Pow2(30,round_fx(L_tmp)); - L_tmp = L_shl(L_tmp, i-(31-16)); /* Q16 */ - - IF (gacelp_uv != 0) - { - /* *past_gcode = L_tmp * pred_nrg_frame; */ - i = norm_l(L_tmp); - L_tmp1 = L_shl(L_tmp, i); - exp_L_tmp1 = sub(15, i); - - i = norm_l(pred_nrg_frame); - L_tmp1 = Mpy_32_32(L_tmp1, L_shl(pred_nrg_frame, i)); - exp_L_tmp1 = add(exp_L_tmp1, sub(15, i)); - - *past_gcode = L_shl(L_tmp1, sub(exp_L_tmp1, 15)); /* Q16 */ move32(); - } - ELSE - { - *past_gcode = L_tmp; /*unscaled gain*/ move32(); - } - - - *gain_code = L_shl(Mpy_32_16_1(*past_gcode, *gain_inov), 3); - move32(); - - *gain_pit = 0; - move16(); - - IF (gacelp_uv != 0) - { - /* c_first = 0.8f*g_coeff->xx - (*gain_code) * (*gain_code) * g_coeff->y2y2; */ - /* c_first = g_coeff->xx - (*gain_code) * (*gain_code) * g_coeff->y2y2; */ - tmp = g_coeff->xx; - move16(); - if (noisy_speech_flag != 0) - { - tmp = mult_r(26214/*0.8f Q15*/, tmp); - } - - s1 = norm_l(*gain_code); - tmp1 = round_fx(L_shl(*gain_code, s1)); - s1 = sub(15, s1); - tmp1 = mult_r(mult_r(tmp1, tmp1), g_coeff->y2y2); - - c_first_e = BASOP_Util_Add_MantExp(tmp, g_coeff->xx_e, - negate(tmp1), add(g_coeff->y2y2_e, shl(s1, 1)), - &c_first); - - L_tmp = Mpy_32_16_1(*gain_code, BASOP_Util_Divide1616_Scale(g_code2, g_code, &s)); - L_tmp = L_shl(L_tmp, sub(sub(add(s, exp_gcode2), exp_gcode), 2)); /* Q16 */ - L_tmp1 = L_add(L_tmp, 0); - - s1 = norm_l(*gain_code); - tmp1 = round_fx(L_shl(*gain_code, s1)); - s1 = sub(15, s1); - - c_index2 = 0x7FFF; - move16(); - c_index2_e = 127; - move16(); - FOR (i = 0; i < 4; i++) - { - /* c = c_first - L_tmp1 * (L_tmp1 * g_coeff->y1y1 + 2 * (*gain_code) * g_coeff->y1y2); */ - s = norm_l(L_tmp1); - tmp = round_fx(L_shl(L_tmp1, s)); - s = sub(15, s); - - c_e = BASOP_Util_Add_MantExp(mult_r(tmp, g_coeff->y1y1), add(s, g_coeff->y1y1_e), - mult_r(tmp1, g_coeff->y1y2), add(add(s1, g_coeff->y1y2_e), 1), - &c); - c = mult_r(c, tmp); - c_e = add(c_e, s); - c_e = BASOP_Util_Add_MantExp(c_first, c_first_e, negate(c), c_e, &c); - - tmp = 0; - move16(); - if (sub(c_e, c_index2_e) < 0) - { - tmp = 1; - move16(); - } - test(); - if (sub(c_e, c_index2_e) == 0 && sub(abs_s(c), abs_s(c_index2)) < 0) - { - tmp = 1; - move16(); - } - - IF (tmp != 0) - { - index2 = i; - move16(); - c_index2 = c; - move16(); - c_index2_e = c_e; - move16(); - *gain_code2 = L_tmp1; - move32(); - } - - L_tmp1 = L_add(L_tmp1, L_tmp); - } - - /* check if value was uninitialized */ - assert(index2 != -3000); - index = add(index, shl(index2, 5)); + index=0; } + *gain_code= (float) pow(10.f,(((index*1.9f)-30.f)/20.f)); + *past_gcode=*gain_code; /*unscaled gain*/ + *gain_code *= *gain_inov; /*scaled gain*/ + *gain_pit=0.f; return index; } +/*---------------------------------------------------------------------* +* procedure gain_enc_gacelp_uv +* Quantization of pitch and codebook gains. +* - an initial predicted gain, gcode0, is first determined based on +* the predicted scaled innovation energy +* - the correction factor gamma = g_code / gcode0 is then vector quantized +* along with gain_pit +* - the mean-squared weighted error criterion is used for the quantizer search +*---------------------------------------------------------------------*/ + +static int gain_enc_gacelp_uv( + const float *code, /* i : algebraic excitation */ + const float *code2, /* i : gaussian excitation */ + int lcode, /* (i) : Subframe size */ + const float mean_ener, /* i : quantized mean energy of the frame */ + float *gain_pit, /* o : quantized pitch gain */ + float *gain_code, /* o : quantized codebook gain */ + float *gain_code2, /* o : quantized codebook gain */ + ACELP_CbkCorr *coeff, /* i/o : correlations , -2,, -2 and 2 */ + float *past_gcode, /* (i/o): past gain of code */ + float *gain_inov /* (o) : unscaled innovation gain */ + ,short noisy_speech_flag /* (i) : noisy speech flag */ +) +{ + short index; + float gcode,gcode2,pred_nrg_frame; + float norm_code2; + short i; + float c, c_index2,c_first; + short index2; + + /*-----------------------------------------------------------------* + * - calculate the unscaled innovation energy + *-----------------------------------------------------------------*/ + + *gain_inov = 1.0f/ (float)sqrt( ( dotp( code, code, lcode ) + 0.01f ) / lcode ); + pred_nrg_frame = (float)pow(10.0,mean_ener/20.0); + gcode=pred_nrg_frame*(*gain_inov); + norm_code2 = 1.0f/ (float)sqrt( ( dotp( code2, code2, lcode ) + 0.01f ) / lcode ); + gcode2=pred_nrg_frame*(norm_code2); + + /*-----------------------------------------------------------------* + * search for the best quantizer + *-----------------------------------------------------------------*/ + + *gain_code = coeff->xy2/(coeff->y2y2*gcode); + + if(*gain_code>0.000001f) + { + index=(int)(((20.f*log10(*gain_code)+20.f)/1.25f)+0.5f); + + if(index>31) + { + index=31; + } + else if(index<0) + { + index=0; + } + } + else + { + index=0; + } + + *gain_code= (float) pow(10.f,(((index*1.25f)-20.f)/20.f)); + *gain_code *= gcode; + + if( noisy_speech_flag ) + { + c_first=0.8f*coeff->xx-(*gain_code)*(*gain_code)*coeff->y2y2; + } + else + { + c_first=coeff->xx-(*gain_code)*(*gain_code)*coeff->y2y2; + } + index2=0; + *gain_code2 = (float) (index2*0.25f+0.25f)*(*gain_code*(gcode2/gcode)); + + c_index2=c_first-(*gain_code2)*(*gain_code2)*coeff->y1y1-2*(*gain_code)*(*gain_code2)*coeff->y1y2; + + for(i=1; i<4; i++) + { + *gain_code2 = (float) (i*0.25f+0.25f)*(*gain_code*(gcode2/gcode)); + + c=c_first-(*gain_code2)*(*gain_code2)*coeff->y1y1-2*(*gain_code)*(*gain_code2)*coeff->y1y2; + + if(fabs(c) #include -#include -#include "stl.h" -#include "control.h" -#include "prot_fx.h" +#include "prot.h" -/* Prototypes */ +/*-------------------------------------------------------------------* +* qlpc_avq() +* +* +*--------------------------------------------------------------------*/ void qlpc_avq( - const Word16 *lsf, /* (i) Input LSF vectors (14Q1*1.28) */ - const Word16 *lsfmid, /* (i) Input LSF vectors (14Q1*1.28) */ - Word16 *lsf_q, /* (o) Quantized LFS vectors (14Q1*1.28) */ - Word16 *lsfmid_q, /* (o) Quantized LFS vectors (14Q1*1.28) */ - Word16 *index, /* (o) Quantization indices */ - Word16 *nb_indices, /* (o) Number of quantization indices */ - Word16 *nbbits, /* (o) Number of quantization bits */ - const Word16 core, /* (i) TCX10 or TCX20 */ - Word32 sr_core + const float *lsf, /* (i) Input LSF vectors */ + const float *lsfmid, + float *lsf_q, /* (o) Quantized LFS vectors */ + float *lsfmid_q, + int *index, /* (o) Quantization indices */ + int *nb_indices, /* (o) Number of quantization indices */ + int *nbbits, /* (o) Number of quantization bits */ + int core, + float sr_core ) { - Word16 i; - Word16 lsfmid_q0[M]; - Word16 *tmp_index, indxt[256], nit, nbits, nbt; - Word16 dummy[M]; - + int i; + float lsfmid_q0[M]; + int *tmp_index, indxt[256], nbits, nbt, nit; + float dummy[M]; /* Init */ tmp_index = &index[0]; *nb_indices = 0; - move16(); - tmp_index[0] = vlpc_1st_cod(lsf, lsf_q, dummy, 0); + /* Quantize end_frame LPC */ + for (i=0; i 0; ind--) + while (ind >= 16) { - push_next_indice_fx(st, 1, 1); - nb_bits = add(nb_bits, 1); + push_next_indice(st, 0xffffU, 16); + nb_bits += 16; + ind -= 16; + } + if (ind > 0) + { + push_next_indice(st, (1U< 4; nbits -= 4) + while (nbits > 4) { - push_next_indice_fx(st, prm[i], 4); - i = add(i, 1); + push_next_indice(st, prm[i], 4); + nbits -= 4; + i++; } - push_next_indice_fx(st, prm[i], nbits); - i = add(i, 1); + push_next_indice(st, prm[i], nbits); + i++; } return(i); } -Word16 encode_lpc_avq( Encoder_State_fx *st, Word16 numlpc, Word16 *param_lpc, Word16 mode ) -{ - Word16 k,j; - Word16 q_type, nb_ind; - Word16 i,qn1,qn2,nb,avqBits,st1; - Word16 nb_bits; - move16(); - move16(); - move16(); - st1=0; + +/*-------------------------------------------------------------------* +* encode_lpc_avq() +* +* +*--------------------------------------------------------------------*/ + +int encode_lpc_avq( + Encoder_State *st, + int numlpc, + int *param_lpc, + int mode +) +{ + int k,j; + int q_type, nb_ind; + int i,qn1,qn2,nb,avqBits,st1=0; + int nb_bits; + j = 0; nb_bits = 0; - FOR (k=0; k0) ) + if ((i<0) || (i>3)) { - move16(); i = 3; } - push_next_indice_fx(st, i, 2); + push_next_indice(st, i, 2); - i = sub(qn2, 2); + i = qn2-2; - if ( s_or(i<0, sub(i,3)>0) ) + if ((i<0) || (i>3)) { - move16(); i = 3; } - push_next_indice_fx(st, i, 2); + push_next_indice(st, i, 2); /* Unary code for abs and rel LPC0/LPC2 */ /* Q5 = 0, Q6=10, Q0=110, Q7=1110, ... */ - move16(); nb = qn1; - IF ( sub(nb,6) > 0) + if (nb > 6) { - nb = sub(nb, 3); + nb -= 3; } - ELSE IF ( sub(nb,4) > 0) + else if (nb > 4) { - nb = sub(nb, 4); + nb -= 4; } - ELSE IF (nb == 0) + else if (nb == 0) { - move16(); nb = 3; } - ELSE + else { - move16(); nb = 0; } - IF (nb > 0) + if (nb > 0) { unary_code(nb, st); } - nb_bits = add(nb_bits, nb); + nb_bits += nb; - move16(); nb = qn2; - IF ( sub(nb,6) > 0) + if (nb > 6) { - nb = sub(nb, 3); + nb -= 3; } - ELSE IF ( sub(nb,4) > 0) + else if (nb > 4) { - nb = sub(nb, 4); + nb -= 4; } - ELSE IF (nb == 0) + else if (nb == 0) { - move16(); nb = 3; } - ELSE + else { - move16(); nb = 0; } - IF (nb > 0) + if (nb > 0) { unary_code(nb, st); } - nb_bits = add(nb_bits, nb); + nb_bits += nb; - avqBits = shl(qn1,2); + avqBits = 4*qn1; unpack4bits(avqBits, ¶m_lpc[j], st); - j = add(j, qn1); - nb_bits = add(nb_bits, avqBits); + j += qn1; + nb_bits += avqBits; - avqBits = shl(qn2, 2); + avqBits = 4*qn2; unpack4bits(avqBits, ¶m_lpc[j], st); - j = add(j, qn2); - nb_bits = add(nb_bits, avqBits); + j += qn2; + nb_bits += avqBits; } - ELSE + else { - j = add(j, nb_ind); + j += nb_ind; } } return(nb_bits); } - diff --git a/src/libs/libevs/lib_enc/qlpc_stoch.cpp b/src/libs/libevs/lib_enc/qlpc_stoch.cpp old mode 100755 new mode 100644 index a288c071..64f63ff4 --- a/src/libs/libevs/lib_enc/qlpc_stoch.cpp +++ b/src/libs/libevs/lib_enc/qlpc_stoch.cpp @@ -1,437 +1,314 @@ /*==================================================================================== - EVS Codec 3GPP TS26.442 Apr 03, 2018. Version 12.11.0 / 13.6.0 / 14.2.0 + EVS Codec 3GPP TS26.443 Nov 13, 2018. Version 12.11.0 / 13.7.0 / 14.3.0 / 15.1.0 ====================================================================================*/ - #include #include #include +#include "options.h" +#include "cnst.h" +#include "prot.h" +#include "rom_com.h" +#include "rom_enc.h" +#include "basop_proto_func.h" -#include "cnst_fx.h" -#include "rom_enc_fx.h" -#include "rom_com_fx.h" -#include "stl.h" -#include "prot_fx.h" -#include "basop_util.h" -#include "rom_basop_util.h" - - +/*-------------------------------------------------------------------* +* lpc_quantization() +* +* +*--------------------------------------------------------------------*/ void lpc_quantization( - Encoder_State_fx * st, - const Word16 core, - const Word16 lpcQuantization, - const Word16 lsfold_q[], - const Word16 lsp[], - const Word16 lspmid[], - Word16 lsp_q[], - Word16 lsf_q[], /* 14Q1*1.28 */ - Word16 lspmid_q[], - Word16 lspq_ind[], - Word16 clip_var[], - Word16 mem_MA[], - Word16 mem_AR[], - const Word8 narrowBand, - const Word16 coder_type, - const Word8 acelp_midLpc, - Word16 param_lpc[], - Word16 nbits_lpc[], - Word16 * bits_param_lpc, - Word16 *no_param_lpc, - Word16 *seed_acelp, - Word32 * Bin_Ener, - Word32 * Bin_Ener_old, - const Word16 Q_ener + Encoder_State * st, + int core, + int lpcQuantization, + float lsf_old[], + const float lsp[], + const float lspmid[], + float lsp_q[], + float lsf_q[], + float lspmid_q[], + float mem_MA[], + float mem_AR[], + int narrowBand, + short coder_type, + int acelp_midLpc, + int param_lpc[], + int nbits_lpc[], + short *seed_acelp, + int sr_core, + float *Bin_Ener, + float *Bin_Ener_old, + short * bits_param_lpc, + short * no_param_lpc ) { + int nb_indices=0; + float lsfmid_q[M]; + short lsfmid_idx; + int i; + float lsf[M], lsfmid[M]; + short force_sf; - Word16 nb_indices; - Word16 lsfmid_q[M]; /* 14Q1*1.28 */ - Word16 lsfmid_idx; - Word16 i, force_sf; - Word16 lsf[M], lsfmid[M]; + float fec_lsf[M], stab; - Word16 fec_lsf[M], stab; - - nb_indices = 0; - move16(); /****** High-rate LPC quantizer *******/ - - IF (lpcQuantization==0) + if( lpcQuantization == 0 ) { - E_LPC_lsp_lsf_conversion(lsp, lsf, M); + lsp2lsf( lsp, lsf, M, sr_core ); - /* check resonance for pitch clipping algorithm */ - gp_clip_test_lsf_fx( lsf, clip_var, M ); - - IF ( (sub(core, TCX_10_CORE) == 0) ) + if( core == TCX_10_CORE ) { - E_LPC_lsp_lsf_conversion(lspmid, lsfmid, M); + lsp2lsf( lspmid, lsfmid, M, sr_core ); } - /* LPC quantizer */ - qlpc_avq(lsf, lsfmid, lsf_q, lsfmid_q, param_lpc, &nb_indices, nbits_lpc, core, st->sr_core); + qlpc_avq( lsf, lsfmid, lsf_q, lsfmid_q, param_lpc, &nb_indices, nbits_lpc, core, sr_core ); - E_LPC_lsf_lsp_conversion(lsf_q, lsp_q, M); + lsf2lsp( lsf_q, lsp_q, M, sr_core ); - IF( sub(core, TCX_10_CORE) == 0 ) + if( core == TCX_10_CORE ) { - E_LPC_lsf_lsp_conversion( lsfmid_q, lspmid_q, M ); + lsf2lsp( lsfmid_q, lspmid_q, M, sr_core ); } - /* assert(nb_indices<=NPRM_LPC_NEW); */ + assert(nb_indices<=NPRM_LPC_NEW); } /****** Low-rate LPC quantizer *******/ - ELSE IF ( sub(lpcQuantization, 1) == 0) + else if( lpcQuantization == 1 ) { - lsp2lsf_fx(lsp, lsf, M, extract_l(st->sr_core)); - gp_clip_test_lsf_fx( lsf, clip_var, M ); + lsp2lsf( lsp, lsf, M, sr_core ); force_sf = 0; - move16(); /*Force safety net when possible in case of transitions*/ - test(); - test(); - IF( st->tc_cnt_fx >= 1 || L_sub(st->last_core_brate_fx,SID_2k40) <= 0 || (sub(st->next_force_safety_net_fx ,1) == 0) ) + if( st->tc_cnt >= 1 || st->last_core_brate <= SID_2k40 || st->next_force_safety_net ) { force_sf = 1; - move16(); - st->next_force_safety_net_fx = 0; - move16(); + st->next_force_safety_net = 0; } - test(); - IF ( sub(st->next_force_safety_net_fx,1) == 0 && sub(st->Opt_RF_ON,1)==0 ) + if( st->next_force_safety_net == 1 && st->Opt_RF_ON ) { force_sf = 1; - st->next_force_safety_net_fx = 0; + st->next_force_safety_net = 0; } - test(); - IF ( L_sub(st->sr_core, INT_FS_16k)== 0 && sub(coder_type,UNVOICED) == 0 ) + if( sr_core == INT_FS_16k && coder_type == UNVOICED ) { - lsf_end_enc_fx( st, lsf, lsf_q, mem_AR, mem_MA, ENDLSF_NBITS, GENERIC, st->bwidth_fx, Bin_Ener, Q_ener, st->sr_core, st->core_brate_fx, - &st->streaklimit_fx, &st->pstreaklen_fx, force_sf, 0, - 1, param_lpc, no_param_lpc, bits_param_lpc, GENERIC ); + lsf_end_enc( st, lsf, lsf_q, mem_AR, mem_MA, ENDLSF_NBITS, GENERIC, st->bwidth, Bin_Ener, sr_core, st->core_brate, + &st->streaklimit, &st->pstreaklen, force_sf, 0, 1, param_lpc, no_param_lpc, bits_param_lpc, GENERIC ); - nb_indices = *no_param_lpc; + nb_indices = (int)(*no_param_lpc); } - ELSE + else { - lsf_end_enc_fx( st, lsf, lsf_q, mem_AR, mem_MA, ENDLSF_NBITS, coder_type, st->bwidth_fx, Bin_Ener, Q_ener, st->sr_core, st->core_brate_fx, - &st->streaklimit_fx, &st->pstreaklen_fx, force_sf, 0, - 1, param_lpc, no_param_lpc, bits_param_lpc, coder_type ); + lsf_end_enc( st, lsf, lsf_q, mem_AR, mem_MA, ENDLSF_NBITS, coder_type, st->bwidth, Bin_Ener, sr_core, st->core_brate, + &st->streaklimit, &st->pstreaklen, force_sf, 0, 1, param_lpc, no_param_lpc, bits_param_lpc, coder_type ); - nb_indices = *no_param_lpc; + nb_indices = (int)(*no_param_lpc); } - - FEC_lsf_estim_enc_fx( st, st->L_frame_fx, fec_lsf ); + FEC_lsf_estim_enc( st, st->L_frame, fec_lsf ); /* FEC - calculate LSF stability */ - stab = lsf_stab_fx( lsf_q, fec_lsf, 0, st->L_frame_fx); /*Q15*/ + stab = lsf_stab( lsf_q, fec_lsf, 0, st->L_frame); - - test(); - test(); - test(); - IF ( sub(stab,add(STAB_FAC_LIMIT_FX, 6553/* =0.2 in Q15*/)) < 0 && - ( sub(coder_type,VOICED) == 0 || sub(coder_type,GENERIC) == 0) && sub(st->Opt_RF_ON,1)==0 ) + if (stab < ( STAB_FAC_LIMIT + 0.2 ) && ( coder_type == VOICED || coder_type == GENERIC) && st->Opt_RF_ON ) { - st->next_force_safety_net_fx = 1; + st->next_force_safety_net = 1; } - lsf2lsp_fx(lsf_q, lsp_q, M, st->sr_core); + lsf2lsp( lsf_q, lsp_q, M, sr_core ); *nbits_lpc = ENDLSF_NBITS; - move16(); - } - ELSE + else { assert(0); } - IF (lspq_ind != NULL) + *seed_acelp = 0; + for( i=nb_indices-1; i>=0; i-- ) { - E_LPC_lsf_lsp_conversion( lsf_q, lspq_ind, M ); - } - - *seed_acelp=0; - move16(); - FOR(i=nb_indices-1; i>=0; i--) - { - *seed_acelp = extract_l(L_mac0(L_mac0(13849, shr(*seed_acelp, 1), 31821), param_lpc[i], 31821)); - move16(); + /* rightshift before *seed_acelp+param_lpc[i] to avoid overflows*/ + *seed_acelp=(short)((((*seed_acelp)>>1)+param_lpc[i]) * 31821L + 13849L); } /* Mid-frame LPC quantization */ - - test(); - IF(lpcQuantization && acelp_midLpc) + if( lpcQuantization && acelp_midLpc ) { - - IF(st->rate_switching_reset==0) + if( st->rate_switching_reset == 0 ) { - lsp2lsf_fx(lspmid, lsfmid, M, extract_l(st->sr_core)); + lsp2lsf( lspmid, lsfmid, M, sr_core ); + midlsf_enc( lsf_old, lsf_q, lsfmid, &lsfmid_idx, M, Bin_Ener_old, narrowBand, sr_core, coder_type ); + param_lpc[nb_indices++] = (int)lsfmid_idx; - midlsf_enc ( lsfold_q, lsf_q, lsfmid, &lsfmid_idx, M, Bin_Ener_old, Q_ener, narrowBand, st->sr_core, coder_type ); - param_lpc[nb_indices++] = lsfmid_idx; - move16(); - midlsf_dec (lsfold_q, lsf_q, lsfmid_idx, lsfmid_q, coder_type - ,NULL,0,1 - ); + midlsf_dec( lsf_old, lsf_q, lsfmid_idx, lsfmid_q, M, coder_type, NULL, 0, 1 ); - reorder_lsf_fx( lsfmid_q, LSF_GAP_MID_FX, M, st->sr_core ); - lsf2lsp_fx(lsfmid_q, lspmid_q, M, st->sr_core); + reorder_lsf( lsfmid_q, LSF_GAP_MID, M, sr_core ); + lsf2lsp( lsfmid_q, lspmid_q, M, sr_core ); } - ELSE + else { param_lpc[nb_indices++] = 0; - move16(); } } - - return; } -#define MIN_LOG_FX 0 -#define MIN_LOG_VAL_FX -15360 /* -60.0f in Q8 */ +/*-------------------------------------------------------------------* + * Unified_weighting() + * + * LSF weighting + *-------------------------------------------------------------------*/ -void Unified_weighting_fx( - Word32 Bin_Ener_128_fx[], /* i : FFT Bin energy 128 bins in two sets Q_ener */ - Word16 Q_ener, - const Word16 lsf_fx[], /* i : LSF vector x2.56 */ - Word16 w_fx[], /* o : LP weighting filter (numerator) Q8 */ - const Word16 narrowBand, /* i : flag for Narrowband */ - const Word16 unvoiced, /* i : flag for Unvoiced frame */ - const Word32 sr_core, /* i : sampling rate of core-coder */ - const Word16 order /* i : LP order */ +void Unified_weighting( + float Bin_Ener_128[], /* i : FFT Bin energy 128 bins in two sets */ + const float lsf[], /* i : LSF vector */ + float w[], /* o : LP weighting filter (numerator) */ + const short narrowBand, /* i : flag for Narrowband */ + const short unvoiced, /* i : flag for Unvoiced frame */ + const short sr_core, /* i : sampling rate of core-coder */ + const int order /* i : LP order */ ) { - Word16 i; + short i; + float nf; const Word16 (*ptr_lsf_fit_model)[M]; - Word16 last_bin; + int norm_lsf[M]; + float tmp, min; + float w_fft[M]; + float Bin_Ener_160[160]; + float *Bin_Ener; + const float *Freq_w_Table; + short last_bin; /*float compen;*/ - Word16 exp, frac; - Word16 w_fft_fx[M]/*, w_fx[M]*/; - Word16 norm_lsf_fx[M]; /* Q0 */ - Word16 tmp_fx, min_fx, tmp1_fx, tmp2_fx, s1, s2; - Word32 L_tmp; - Word16 nf_fx; - Word32 Bin_Ener_160_fx[160]; - Word32 *Bin_Ener_fx; - const Word32 *Freq_w_Table_fx; - /*Config. weighting*/ - IF ( narrowBand ) + if( narrowBand ) { ptr_lsf_fit_model = lsf_unified_fit_model_nb; - nf_fx = 16384; - move16(); /* x2.56 */ + nf = 6400.f; last_bin = 127; - move16(); - Bin_Ener_fx = Bin_Ener_128_fx; + Bin_Ener = Bin_Ener_128; } - ELSE IF( L_sub(sr_core, 12800) == 0 ) + else if( sr_core == 12800 ) { ptr_lsf_fit_model = lsf_unified_fit_model_wb; - nf_fx = 16384; - move16(); /* x2.56 */ + nf = 6400.f; last_bin = 127; - move16(); - Bin_Ener_fx = Bin_Ener_128_fx; + Bin_Ener = Bin_Ener_128; } - ELSE + else { ptr_lsf_fit_model = lsf_unified_fit_model_wbhb; - nf_fx = 20480; - move16(); /* x2.56 */ + nf = 8000.f; /* Fill the missing part (128~159) of the bin energy */ last_bin = 159; - move16(); - Copy32(Bin_Ener_128_fx, Bin_Ener_160_fx, L_FFT/2); + mvr2r( Bin_Ener_128, Bin_Ener_160, L_FFT/2 ); /* Find average bin energy (32 Energy) */ - L_tmp = L_deposit_l(0); - FOR ( i=95; i<127; i++ ) + tmp = 0.f; + for( i=95; i<127; i++ ) { - L_tmp = L_add(L_tmp, Bin_Ener_160_fx[i]); + tmp += Bin_Ener_160[i]; } - L_tmp = L_shr(L_tmp, 5); - FOR ( i=127; i<160; i++ ) + tmp = tmp/32.f; + for( i=127; i<160; i++ ) { - Bin_Ener_160_fx[i] = L_tmp; - move32(); + Bin_Ener_160[i] = tmp; } - Bin_Ener_fx = Bin_Ener_160_fx; + Bin_Ener = Bin_Ener_160; } /* 1) FFT weights*/ - Freq_w_Table_fx = Freq_Weight_Com_fx; - if ( unvoiced ) + if( unvoiced ) { - Freq_w_Table_fx = Freq_Weight_UV_fx; + Freq_w_Table = Freq_Weight_UV; + } + else + { + Freq_w_Table = Freq_Weight_Com; } /* Use Envelope */ - min_fx = MAX_16; - move16(); - FOR ( i=0; i 0) - { - tmp1_fx = sub(tmp1_fx, lsf_fx[i-1]); - } + w[i] = 1.f/( lsf[i] - lsf[i-1] ) + 1.f/( lsf[i+1] - lsf[i] ); + } + w[order-1] = 1.f/( lsf[order-1] - lsf[order-2] ) + + 1.f/( nf - lsf[order-1] ); - tmp2_fx = nf_fx; - move16(); - if (sub(i, order - 1) != 0) - { - tmp2_fx = lsf_fx[i+1]; - move16(); - } - tmp2_fx = sub(tmp2_fx, lsf_fx[i]); + /* 3) Fitting model combining the two weights*/ + for( i=0; i +#include +#include +#include "options.h" +#include "cnst.h" +#include "rom_com.h" +#include "prot.h" + +/*-------------------------------------------------------------------* + * Local functions + *-------------------------------------------------------------------*/ + +static void rc_enc_shift(Encoder_State *st); +static void rc_enc_write(Encoder_State *st, short byte, short bits); + + +/*-------------------------------------------------------------------* + * rc_enc_init() + * + * Initalize range coder + *-------------------------------------------------------------------*/ + +void rc_enc_init( + Encoder_State *st, /* i/o: Encoder state */ + short tot_bits /* i : Total bit budget */ +) +{ + st->rc_low = 0; + st->rc_range = 0xffffffff; + st->rc_cache = -1; + st->rc_carry = 0; + st->rc_carry_count = 0; + st->rc_num_bits = 0; + st->rc_tot_bits = tot_bits; + st->rc_offset = 0; + + return; +} + +/*-------------------------------------------------------------------* + * rc_encode() + * + * Encode symbol with range coder + *-------------------------------------------------------------------*/ + +void rc_encode( + Encoder_State *st, /* i/o: Encoder state */ + unsigned int cum_freq, /* i : Cumulative frequency up to symbol */ + unsigned int sym_freq, /* i : Symbol probability */ + unsigned int tot /* i : Total cumulative frequency */ +) +{ + unsigned int r, tmp; + unsigned int inv_tot; + short exp; + + inv_tot = UL_inverse(tot, &exp); + tmp = UMult_32_32(st->rc_range, inv_tot); + r = tmp >> (exp - 32); + tmp = r*cum_freq; + + st->rc_low = st->rc_low + tmp; + if (st->rc_low < tmp) + { + st->rc_carry = 1; + } + + st->rc_range = r*sym_freq; + + while (st->rc_range < 1<<24) + { + st->rc_range = st->rc_range << 8; + st->rc_num_bits += 8; + rc_enc_shift(st); + } + + return; +} + +/*-------------------------------------------------------------------* + * rc_enc_finish() + * + * Finalize range coder + *-------------------------------------------------------------------*/ + +void rc_enc_finish( + Encoder_State *st /* i/o: Encoder state */ +) +{ + unsigned int val, mask, high; + short bits, over1, over2; + + bits = norm_ul(st->rc_range) + 1; /* aligned to BASOP */ + + mask = 0xffffffff >> bits; + + val = st->rc_low + mask; + high = st->rc_low + st->rc_range; + + over1 = val < st->rc_low; + over2 = high < st->rc_low; + + val = val & ~mask; + + if ( !(over1 ^ over2) ) + { + if ((val + mask) >= high) + { + bits++; + mask >>= 1; + val = (st->rc_low + mask) & ~mask; + } + + if (val < st->rc_low) + { + st->rc_carry = 1; + } + } + + st->rc_low = val; + + if (bits > st->rc_tot_bits - st->rc_num_bits) + { + bits = st->rc_tot_bits - st->rc_num_bits; + + } + + st->rc_num_bits += bits; + while (bits > 0) + { + rc_enc_shift(st); + bits -= 8; + } + + bits += 8; + + if ( st->rc_carry_count > 0 ) + { + rc_enc_write(st, st->rc_cache + st->rc_carry, 8); + + while (st->rc_carry_count > 1) + { + rc_enc_write(st, (st->rc_carry + 0xff), 8); + st->rc_carry_count--; + } + rc_enc_write(st, (st->rc_carry + 0xff) & ((1<rc_cache + st->rc_carry)>>(8-bits), bits); + } + + bits = st->rc_num_bits; + while (bits < st->rc_tot_bits-16) + { + rc_enc_write(st, 0, 16); + bits += 16; + } + + bits = st->rc_tot_bits - bits; + if (bits > 0) + { + rc_enc_write(st, 0, bits); + } + + return; +} + +/*-------------------------------------------------------------------* + * rc_enc_shift() + * + * Shift a byte out to bitstream + *-------------------------------------------------------------------*/ + +static void rc_enc_shift( + Encoder_State *st /* i/o: Encoder state */ +) +{ + if ( st->rc_low < (0xffUL << 24) || st->rc_carry ) + { + if (st->rc_cache >= 0) + { + rc_enc_write(st, st->rc_cache + st->rc_carry, 8); + } + + while (st->rc_carry_count > 0) + { + rc_enc_write(st, (st->rc_carry + 0xff) & 255, 8); + st->rc_carry_count--; + } + + st->rc_cache = st->rc_low >> 24; + st->rc_carry = 0; + } + else + { + st->rc_carry_count++; + } + + st->rc_low = st->rc_low << 8; + + return; +} + +/*-------------------------------------------------------------------* + * rc_enc_bits() + * + * + *-------------------------------------------------------------------*/ + +void rc_enc_bits( + Encoder_State *st, /* i/o: Encoder state */ + unsigned int value, /* i : Value to encode */ + short bits /* i : Number of bits used */ +) +{ + if ( rc_get_bits2(st->rc_num_bits, st->rc_range) + bits <= st->rc_tot_bits) + { + st->rc_num_bits += bits; + if ( bits > 16 ) + { + push_indice(st, IND_RC_END - st->rc_offset, value >> 16, bits - 16); + st->rc_offset++; + + push_indice(st, IND_RC_END - st->rc_offset, value & ((1 << 16) - 1), 16); + st->rc_offset++; + } + else + { + push_indice(st, IND_RC_END - st->rc_offset++, value, bits); + } + } + else + { + } + + return; +} + +/*-------------------------------------------------------------------* + * rc_enc_uniform() + * + * Encode with uniform distribution + *-------------------------------------------------------------------*/ + +void rc_enc_uniform( + Encoder_State *st, /* i/o: Encoder state */ + unsigned int value, /* i : Value to encode */ + unsigned int tot /* i : Maximum value */ +) +{ + short n; + + n = 32 - norm_ul(tot-1); /* aligned to BASOP */ + + if (n <= 8) + { + rc_encode(st, value, 1, tot); + } + else + { + n -= 8; + rc_encode(st, value >> n, 1, (tot >> n) + 1); + rc_enc_bits(st, value & ((1< -#include -#include "options.h" /* Compilation switches */ -#include "cnst_fx.h" /* Common constants */ -#include "rom_com_fx.h" /* Static table prototypes */ -#include "prot_fx.h" /* Function prototypes */ - -#include "stl.h" - -static void rc_enc_shift_fx(Encoder_State_fx *st_fx); -static void rc_enc_write_fx(Encoder_State_fx *st_fx, Word16 byte, Word16 bits); - -/*-------------------------------------------------------------------* - * rc_enc_init() - * - * Initalize range coder - *-------------------------------------------------------------------*/ - -void rc_enc_init_fx( - Encoder_State_fx *st_fx, /* i/o: Encoder state */ - Word16 tot_bits /* i : Total bit budget */ -) -{ - st_fx->rc_low_fx = L_deposit_l(0); - st_fx->rc_range_fx = 0xffffffff; - move32(); - st_fx->rc_cache_fx = -1; - move16(); - st_fx->rc_carry_fx = 0; - move16(); - st_fx->rc_carry_count_fx = 0; - move16(); - st_fx->rc_num_bits_fx = 0; - move16(); - st_fx->rc_tot_bits_fx = tot_bits; - move16(); - st_fx->rc_offset_fx = 0; - move16(); - - return; -} - -/*-------------------------------------------------------------------* - * rc_encode() - * - * Encode symbol with range coder - *-------------------------------------------------------------------*/ - -void rc_encode_fx( - Encoder_State_fx *st_fx, /* i/o: Encoder state */ - UWord32 cum_freq, /* i : Cumulative frequency up to symbol */ - UWord32 sym_freq, /* i : Symbol probability */ - UWord32 tot /* i : Total cumulative frequency */ -) -{ - UWord32 r, tmp, inv_tot, lsb; - Word16 exp; - UWord16 carry; - - inv_tot = UL_inverse(tot, &exp); - Mpy_32_32_uu(st_fx->rc_range_fx, inv_tot, &tmp, &lsb); /*0+exp-32 */ - r = UL_lshr(tmp, sub(exp, 32)); /* exp-32-exp3+32 = 0 */ - tmp = UL_Mpy_32_32(r, cum_freq); - - st_fx->rc_low_fx = UL_addNs(st_fx->rc_low_fx, tmp, &carry); - if (carry != 0) - { - st_fx->rc_carry_fx = carry; - move16(); - } - - st_fx->rc_range_fx = UL_Mpy_32_32(r, sym_freq); - - WHILE (st_fx->rc_range_fx < 1<<24) - { - L_sub(0, 0); /* Comparison in while */ - st_fx->rc_range_fx = UL_lshl(st_fx->rc_range_fx, 8); - st_fx->rc_num_bits_fx = add(st_fx->rc_num_bits_fx, 8); - rc_enc_shift_fx(st_fx); - } - - return; -} - -/*-------------------------------------------------------------------* - * rc_enc_finish() - * - * Finalize range coder - *-------------------------------------------------------------------*/ - -void rc_enc_finish_fx( - Encoder_State_fx *st_fx /* i/o: Encoder state */ -) -{ - UWord32 val, mask, high; - Word16 bits; - UWord16 over1, over2; - - bits = add(norm_ul(st_fx->rc_range_fx), 1); - mask = UL_lshr(0xffffffff, bits); - - val = UL_addNs(st_fx->rc_low_fx, mask, &over1); - high = UL_addNs(st_fx->rc_low_fx, st_fx->rc_range_fx, &over2); - - val = L_and(val, ~mask); - L_xor(0,0); /* For bit not */ - - IF ( (L_xor(over1, over2)) == 0 ) - { - L_sub(0, 0); /* For comparision in if */ - IF (UL_addNsD(val, mask) >= high) - { - bits = add(bits, 1); - mask = UL_lshr(mask, 1); - val = UL_and(UL_addNsD(st_fx->rc_low_fx, mask), ~mask); - L_xor(0,0); /* For bit not */ - } - - if (val < st_fx->rc_low_fx) - { - st_fx->rc_carry_fx = 1; - move16(); - } - } - - st_fx->rc_low_fx = val; - move32(); - - IF ( sub(bits, sub(st_fx->rc_tot_bits_fx, st_fx->rc_num_bits_fx)) > 0 ) - { - bits = sub(st_fx->rc_tot_bits_fx, st_fx->rc_num_bits_fx); - - } - - st_fx->rc_num_bits_fx = add(st_fx->rc_num_bits_fx, bits); - FOR ( ; bits > 0; bits -= 8) - { - rc_enc_shift_fx(st_fx); - } - bits = add(bits, 8); - - IF ( st_fx->rc_carry_count_fx > 0 ) - { - rc_enc_write_fx(st_fx, add(st_fx->rc_cache_fx, st_fx->rc_carry_fx), 8); - - FOR ( ; st_fx->rc_carry_count_fx > 1; st_fx->rc_carry_count_fx--) - { - rc_enc_write_fx(st_fx, (st_fx->rc_carry_fx + 0xff), 8); - } - rc_enc_write_fx(st_fx, s_and(add(st_fx->rc_carry_fx, 0xff), sub(lshl(1, bits), 1)), bits); - } - ELSE - { - rc_enc_write_fx(st_fx, lshr(add(st_fx->rc_cache_fx, st_fx->rc_carry_fx), sub(8, bits)), bits); - } - - bits = st_fx->rc_num_bits_fx; - move16(); - WHILE (sub(bits, sub(st_fx->rc_tot_bits_fx, 16)) < 0) - { - rc_enc_write_fx(st_fx, 0, 16); - bits = add(bits, 16); - } - - bits = sub(st_fx->rc_tot_bits_fx, bits); - IF (bits > 0) - { - rc_enc_write_fx(st_fx, 0, bits); - } - - return; -} - -/*-------------------------------------------------------------------* - * rc_enc_shift() - * - * Shift a byte out to bitstream - *-------------------------------------------------------------------*/ - -static void rc_enc_shift_fx( - Encoder_State_fx *st_fx /* i/o: Encoder state */ -) -{ - test(); - L_sub(0, 0); /* For comparision in if */ - IF (st_fx->rc_low_fx < (0xff000000UL) || sub(st_fx->rc_carry_fx, 1) == 0) - { - IF (st_fx->rc_cache_fx >= 0) - { - rc_enc_write_fx(st_fx, add(st_fx->rc_cache_fx, st_fx->rc_carry_fx), 8); - } - - WHILE (st_fx->rc_carry_count_fx > 0) - { - rc_enc_write_fx(st_fx, s_and(add(st_fx->rc_carry_fx, 0xff), 255), 8); - st_fx->rc_carry_count_fx = sub(st_fx->rc_carry_count_fx, 1); - } - - st_fx->rc_cache_fx = u_extract_l(UL_lshr(st_fx->rc_low_fx, 24)); - st_fx->rc_carry_fx = 0; - move16(); - } - ELSE - { - st_fx->rc_carry_count_fx = add(st_fx->rc_carry_count_fx, 1); - } - st_fx->rc_low_fx = UL_lshl(st_fx->rc_low_fx, 8); - - return; -} - -/*-------------------------------------------------------------------* - * rc_enc_bits() - * - * - *-------------------------------------------------------------------*/ - -void rc_enc_bits_fx( - Encoder_State_fx *st_fx, /* i/o: Encoder state */ - UWord32 value, /* i : Value to encode */ - Word16 bits /* i : Number of bits used */ -) -{ - IF ( sub(add(rc_get_bits2_fx(st_fx->rc_num_bits_fx, st_fx->rc_range_fx), bits), st_fx->rc_tot_bits_fx) <= 0) - { - st_fx->rc_num_bits_fx = add(st_fx->rc_num_bits_fx, bits); - - IF ( sub(bits, 16) > 0 ) - { - push_indice_fx(st_fx, sub(IND_RC_END, st_fx->rc_offset_fx), u_extract_l(UL_lshr(value, 16)), sub(bits, 16)); - st_fx->rc_offset_fx = add(st_fx->rc_offset_fx, 1); - push_indice_fx(st_fx, sub(IND_RC_END, st_fx->rc_offset_fx), u_extract_l(UL_and(value, 0x0000ffff)), 16); - st_fx->rc_offset_fx = add(st_fx->rc_offset_fx, 1); - } - ELSE - { - push_indice_fx(st_fx, sub(IND_RC_END, st_fx->rc_offset_fx), u_extract_l(value), bits); - st_fx->rc_offset_fx = add(st_fx->rc_offset_fx, 1); - } - } - ELSE - { - } - - return; -} - -/*-------------------------------------------------------------------* - * rc_enc_uniform() - * - * Encode with uniform distribution - *-------------------------------------------------------------------*/ - -void rc_enc_uniform_fx( - Encoder_State_fx *st_fx, /* i/o: Encoder state */ - UWord32 value, /* i : Value to encode */ - UWord32 tot /* i : Maximum value */ -) -{ - Word16 n; - - n = sub(32, norm_ul(UL_subNsD(tot, 1))); - - IF (sub(n, 8) <= 0) - { - rc_encode_fx(st_fx, value, 1, tot); - } - ELSE - { - n = sub(n, 8); - rc_encode_fx(st_fx, UL_lshr(value, n), 1, UL_addNsD(UL_lshr(tot, n), 1)); - rc_enc_bits_fx(st_fx, UL_and(value, UL_subNsD(UL_lshl(1, n), 1)), n); - } - - return; -} - -/*-------------------------------------------------------------------* - * rc_enc_write() - * - * Write a byte to bitstream - *-------------------------------------------------------------------*/ - -static void rc_enc_write_fx( - Encoder_State_fx *st_fx, /* i/o: Encoder state */ - Word16 byte, /* i : Byte to write */ - Word16 bits /* i : Number of bits */ -) -{ - push_indice_fx(st_fx, IND_RC_START, byte, bits); - - return; -} diff --git a/src/libs/libevs/lib_enc/re8_cod_fx.cpp b/src/libs/libevs/lib_enc/re8_cod.cpp old mode 100755 new mode 100644 similarity index 62% rename from src/libs/libevs/lib_enc/re8_cod_fx.cpp rename to src/libs/libevs/lib_enc/re8_cod.cpp index da6f9afe..c16c550c --- a/src/libs/libevs/lib_enc/re8_cod_fx.cpp +++ b/src/libs/libevs/lib_enc/re8_cod.cpp @@ -1,27 +1,28 @@ /*==================================================================================== - EVS Codec 3GPP TS26.442 Apr 03, 2018. Version 12.11.0 / 13.6.0 / 14.2.0 + EVS Codec 3GPP TS26.443 Nov 13, 2018. Version 12.11.0 / 13.7.0 / 14.3.0 / 15.1.0 ====================================================================================*/ -#include "options.h" /* Compilation switches */ -#include "prot_fx.h" -#include "stl.h" +#include "options.h" +#include "prot.h" + /*------------------------------------------------------------------------ - * RE8_cod: + * re8_cod() * * MULTI-RATE INDEXING OF A POINT y in THE LATTICE RE8 (INDEX COMPUTATION) * note: the index I is defined as a 32-bit word, but only * 16 bits are required (long can be replaced by unsigned integer) *--------------------------------------------------------------------------*/ -void re8_cod_fx( - Word16 x[], /* i : point in RE8 (8-dimensional integer vector) */ - Word16 *n, /* i : codebook number (*n is an integer defined in {0,2,3,4,..,n_max}) */ - UWord16 *I, /* o : index of c (pointer to unsigned 16-bit word) */ - Word16 k[] /* o : index of v (8-dimensional vector of binary indices) = Voronoi index */ +void re8_cod( + int x[], /* i : point in RE8 (8-dimensional integer vector) */ + int *n, /* i : codebook number (*n is an integer defined in {0,2,3,4,..,n_max}) */ + long *I, /* o : index of c (pointer to unsigned 16-bit word) */ + int k[] /* o : index of v (8-dimensional vector of binary indices) = Voronoi index */ ) { - Word16 ka_fx, c_fx[8]; + int ka, c[8]; + /*---------------------------------------------------------------------- * decompose x as x = 2^r c + v, where r is an integer >=0, c is an element * of Q0, Q2, Q3 or Q4, and v is an element of a Voronoi code in RE8 @@ -33,20 +34,20 @@ void re8_cod_fx( * - the index I of c * - the index k[] of v ----------------------------------------------------------------------*/ - re8_vor_fx(x, n, k, c_fx, &ka_fx); + + re8_vor( x, n, k, c, &ka ); /* safeguard in case that the AVQ subquantizer is not found - might happen for extremely strong onsets at the end of the frame */ - IF( sub(ka_fx,NB_LEADER) >= 0 ) + if( ka >= NB_LEADER ) { *n = 0; - move16(); - set16_fx( x, 0, 8 ); + set_i( x, 0, 8 ); } /* compute the index I (only if c is in Q2, Q3 or Q4) */ - IF (*n > 0) + if( *n > 0 ) { - re8_compute_base_index_fx(c_fx, ka_fx, I); + re8_compute_base_index( c, ka, I ); } return; diff --git a/src/libs/libevs/lib_enc/reordernorm.cpp b/src/libs/libevs/lib_enc/reordernorm.cpp new file mode 100644 index 00000000..f0291463 --- /dev/null +++ b/src/libs/libevs/lib_enc/reordernorm.cpp @@ -0,0 +1,57 @@ +/*==================================================================================== + EVS Codec 3GPP TS26.443 Nov 13, 2018. Version 12.11.0 / 13.7.0 / 14.3.0 / 15.1.0 + ====================================================================================*/ + +#include "options.h" +#include "prot.h" +#include "cnst.h" +#include "rom_com.h" + +/*--------------------------------------------------------------------------*/ +/* Function reordernorm */ +/* ~~~~~~~~~~~~~~~~~~~~~ */ +/* */ +/* Reorder quantization indices and norms */ +/*--------------------------------------------------------------------------*/ +/* short *ynrm (i) quantization indices for norms */ +/* short *normqlg2 (i) quantized norms */ +/* short *idxbuf (o) reordered quantization indices */ +/* short *normbuf (o) reordered quantized norms */ +/* short *nb_sfm (i) number of bands */ +/*--------------------------------------------------------------------------*/ + +void reordernorm( + const short *ynrm, + const short *normqlg2, + short *idxbuf, + short *normbuf, + const short nb_sfm +) +{ + short i; + const short *order = NULL; + + switch(nb_sfm) + { + case NB_SFM: + order = norm_order_48; + break; + case SFM_N_SWB: + order = norm_order_32; + break; + case SFM_N_WB: + order = norm_order_16; + break; + default: + order = norm_order_48; + break; + } + + for (i = 0; i < nb_sfm; i++) + { + idxbuf[i] = ynrm[order[i]]; + normbuf[i] = normqlg2[order[i]]; + } + + return; +} diff --git a/src/libs/libevs/lib_enc/reordernorm_fx.cpp b/src/libs/libevs/lib_enc/reordernorm_fx.cpp deleted file mode 100755 index 32630468..00000000 --- a/src/libs/libevs/lib_enc/reordernorm_fx.cpp +++ /dev/null @@ -1,57 +0,0 @@ -/*==================================================================================== - EVS Codec 3GPP TS26.442 Apr 03, 2018. Version 12.11.0 / 13.6.0 / 14.2.0 - ====================================================================================*/ - -#include "options.h" /* Compilation switches */ -#include "cnst_fx.h" /* Common constants */ -#include "rom_com_fx.h" - -#include "prot_fx.h" -#include "stl.h" /* required for wmc_tool */ - -/*--------------------------------------------------------------------------*/ -/* Function reordernorm_fx */ -/* ~~~~~~~~~~~~~~~~~~~~~ */ -/* */ -/* Reorder quantization indices and norms */ -/*--------------------------------------------------------------------------*/ - -void reordernorm_fx( - const Word16 *ynrm, /* i : quantization indices for norms Q0 */ - const Word16 *normqlg2, /* i : quantized norms Q0 */ - Word16 *idxbuf, /* o : reordered quantization indices Q0 */ - Word16 *normbuf, /* o : reordered quantized norms Q0 */ - const Word16 nb_sfm /* i : number of bands Q0 */ -) -{ - Word16 i; - const Word16 *order = NULL; - - SWITCH(nb_sfm) - { - case NB_SFM: - order = norm_order_48; - BREAK; - case SFM_N_SWB: - order = norm_order_32; - BREAK; - case SFM_N_WB: - order = norm_order_16; - BREAK; - default: - order = norm_order_48; - BREAK; - } - - FOR (i = 0; i < nb_sfm; i++) - { - idxbuf[i] = ynrm[order[i]]; - move16(); - move16(); - normbuf[i] = normqlg2[order[i]]; - move16(); - move16(); - } - - return; -} diff --git a/src/libs/libevs/lib_enc/rom_enc.cpp b/src/libs/libevs/lib_enc/rom_enc.cpp new file mode 100644 index 00000000..9248bd8e --- /dev/null +++ b/src/libs/libevs/lib_enc/rom_enc.cpp @@ -0,0 +1,702 @@ +/*==================================================================================== + EVS Codec 3GPP TS26.443 Nov 13, 2018. Version 12.11.0 / 13.7.0 / 14.3.0 / 15.1.0 + ====================================================================================*/ + +#include "options.h" +#include "cnst.h" + +const short hangover_hd_tbl[3] = {1, 1, 3}; +const short hangover_sf_tbl[6] = {1, 3, 4, 1, 1, 2}; +const short bwd_start_bin[BWD_N_BINS_MAX] = {1, 3, 6, 11}; +const short bwd_end_bin[BWD_N_BINS_MAX] = {1, 4, 9, 12}; + +const short BAND_NUM_TAB[5] = {10,10,20,40,60}; /* {OFFSET, NB, WB, SWB, FB} */ + +const float M_inr[16] = +{ + 1.00000000f, 0.98078525f, 0.92387950f, 0.83146960f, 0.70710677f, 0.55557019f, 0.38268343f, 0.19509035f, + 0.00000008f, -0.19509020f, -0.38268328f, -0.55557019f, -0.70710677f, -0.83146966f, -0.92387962f, -0.98078531f +}; + +const float M_ini[16] = +{ + 0.00000000f, 0.19509032f, 0.38268346f, 0.55557024f, 0.70710677f, 0.83146966f, 0.92387950f, 0.98078525f, + 1.00000000f, 0.98078531f, 0.92387956f, 0.83146966f, 0.70710677f, 0.55557019f, 0.38268328f, 0.19509009f +}; + +const float M_r[8] = +{ + 1.00000000f, 0.92387950f, 0.70710677f, 0.38268343f, -0.00000004f, -0.38268352f, -0.70710677f, -0.92387950f +}; + +const float M_i[8] = +{ + 0.00000000f, 0.38268346f, 0.70710677f, 0.92387950f, 1.00000000f, 0.92387950f, 0.70710677f, 0.38268349f +}; + +const float M_Wr[16]= +{ + 9.9518473e-001f, 9.5694034e-001f, 8.8192126e-001f, 7.7301045e-001f, 6.3439328e-001f, 4.7139674e-001f, 2.9028468e-001f, 9.8017140e-002f, + -9.8017140e-002f, -2.9028468e-001f, -4.7139674e-001f, -6.3439328e-001f, -7.7301045e-001f, -8.8192126e-001f, -9.5694034e-001f, -9.9518473e-001f +}; + +const float M_Wi[16] = +{ + 9.8017140e-002f, 2.9028468e-001f, 4.7139674e-001f, 6.3439328e-001f, 7.7301045e-001f, 8.8192126e-001f, 9.5694034e-001f, 9.9518473e-001f, + 9.9518473e-001f, 9.5694034e-001f, 8.8192126e-001f, 7.7301045e-001f, 6.3439328e-001f, 4.7139674e-001f, 2.9028468e-001f, 9.8017140e-002f +}; + +const short SP_CENTER_BAND_NUM_TAB[5] = {10, 10, 20, 24, 24}; + +/* 107374184.f = 32768.f * 32768.f * 0.1 */ +const float DELTA1[5] = {107374184.f, 0.0f, 107374184.f, 107374184.f, 0.0f}; +const float DELTA2[5] = {107374184.f, 1.f, 107374184.f, 107374184.f, 107374184.f}; + +const int NREGION_INDEX_NB[9] = {0,1,2,3,4,5,6,7, 9}; +const int NREGION_INDEX_WB[13] = {0,1,2,3,4,5,6,8,10,12,16}; +const int NREGION_INDEX_SWB[16] = {0,1,2,3,4,5,6,8,10,12,16,24,36}; +const int NREGION_INDEX_FB[16] = {0,1,2,3,4,5,6,8,10,12,16,24,36}; +const int ENERGY_BAND_NUM[4] = {8,10,12,MAX_SUBBAND_NUM}; +const int *const REGION_INDEX[4] = {NREGION_INDEX_NB, NREGION_INDEX_WB,NREGION_INDEX_SWB,NREGION_INDEX_FB}; +const float MAX_LF_SNR_TAB[4] = {0.8f, 0.8f, 1.6f, 0.8f}; + +const float COMVAD_INIT_SNR_DELTA[5] = {1.0f, 0.6f, 0.86f, 1.16f, 1.0f}; +const float LS_MIN_SELENCE_SNR[3] = {7.5f, 7.5f, 6.8f}; +const float LT_MIN_SILENCE_SNR[3] = {4.5f, 4.5f, 4.5f}; + +/* half of the square root hanning window for spectral analysis */ +const float sqrt_han_window[L_FFT/2+1]= +{ + 0.000000f, 0.012272f, 0.024541f, 0.036807f, 0.049068f, 0.061321f, 0.073565f, 0.085797f, + 0.098017f, 0.110222f, 0.122411f, 0.134581f, 0.146730f, 0.158858f, 0.170962f, 0.183040f, + 0.195090f, 0.207111f, 0.219101f, 0.231058f, 0.242980f, 0.254866f, 0.266713f, 0.278520f, + 0.290285f, 0.302006f, 0.313682f, 0.325310f, 0.336890f, 0.348419f, 0.359895f, 0.371317f, + 0.382683f, 0.393992f, 0.405241f, 0.416430f, 0.427555f, 0.438616f, 0.449611f, 0.460539f, + 0.471397f, 0.482184f, 0.492898f, 0.503538f, 0.514103f, 0.524590f, 0.534998f, 0.545325f, + 0.555570f, 0.565732f, 0.575808f, 0.585798f, 0.595699f, 0.605511f, 0.615232f, 0.624860f, + 0.634393f, 0.643832f, 0.653173f, 0.662416f, 0.671559f, 0.680601f, 0.689541f, 0.698376f, + 0.707107f, 0.715731f, 0.724247f, 0.732654f, 0.740951f, 0.749136f, 0.757209f, 0.765167f, + 0.773010f, 0.780737f, 0.788346f, 0.795837f, 0.803208f, 0.810457f, 0.817585f, 0.824589f, + 0.831470f, 0.838225f, 0.844854f, 0.851355f, 0.857729f, 0.863973f, 0.870087f, 0.876070f, + 0.881921f, 0.887640f, 0.893224f, 0.898674f, 0.903989f, 0.909168f, 0.914210f, 0.919114f, + 0.923880f, 0.928506f, 0.932993f, 0.937339f, 0.941544f, 0.945607f, 0.949528f, 0.953306f, + 0.956940f, 0.960431f, 0.963776f, 0.966976f, 0.970031f, 0.972940f, 0.975702f, 0.978317f, + 0.980785f, 0.983105f, 0.985278f, 0.987301f, 0.989177f, 0.990903f, 0.992480f, 0.993907f, + 0.995185f, 0.996313f, 0.997290f, 0.998118f, 0.998795f, 0.999322f, 0.999699f, 0.999925f, + 1.000000f +}; + +/*----------------------------------------------------------------------------------* + * Starting points for pulse position search in Algebraic innovation codebook + *----------------------------------------------------------------------------------*/ + +const short tipos[40] = +{ + 0, 1, 2, 3, /* starting point &ipos[0], 1st iter */ + 1, 2, 3, 0, /* starting point &ipos[4], 2nd iter */ + 2, 3, 0, 1, /* starting point &ipos[8], 3rd iter */ + 3, 0, 1, 2, /* starting point &ipos[12], 4th iter */ + 0, 1, 2, 3, + 1, 2, 3, 0, + 2, 3, 0, 1, + 3, 0, 1, 2, + 0, 1, 2, 3, + 1, 2, 3, 0 /* end point for 28 pulses &ipos[39], 4th iter */ +}; + +/*----------------------------------------------------------------------------------* + * 1/4 resolution interpolation filter (-3 dB at 0.791*fs/2) + * for fractional pitch search + *----------------------------------------------------------------------------------*/ + +/* 1/4 resolution interpolation filter (-3 dB at 0.791*fs/2) */ +const float E_ROM_inter4_1[PIT_UP_SAMP * L_INTERPOL1 + 1] = +{ + 0.900000F, + 0.818959F, 0.604850F, 0.331379F, 0.083958F, + -0.075795F, -0.130717F, -0.105685F, -0.046774F, + 0.004467F, 0.027789F, 0.025642F, 0.012571F, + 0.001927F, -0.001571F, -0.000753F, 0.000000f +}; + +/* 1/6 resolution interpolation filter (-3 dB at 0.9*fs/2) */ +const float E_ROM_inter6_1[PIT_UP_SAMP6 * L_INTERPOL1 + 1] = +{ + 0.900848F, + 0.864136F, 0.760071F, 0.605408F, 0.424072F, + 0.242462F, 0.0840759F, -0.0343933F, -0.105560F, + -0.131348F, -0.121124F, -0.0884705F, -0.0476379F, + -0.0102539F, 0.0162964F, 0.0296021F, 0.0312195F, + 0.0251160F, 0.0157471F, 0.00671387F, 0.000000F, + -0.00399780F, -0.00592041F, -0.00656128F, 0.000000F +}; + +/*----------------------------------------------------------------------------------* + * Open-loop pitch tables + *----------------------------------------------------------------------------------*/ +const short nb_sect_12k8[3] = { 4, 4, 4 }; +const short nb_subsect_12k8[3] = { 7, 7, 7 }; +const short pit_max_12k8[8] = { 11, 16, 21, 31, 40, 61, 77, 115}; + +const short len_12k8[4] = { 40, 40, 62, 115 }; +const short len1_12k8[4] = { 40, 50, 80, 115 }; +const short sublen_12k8[7] = { 40, 40, 40, 62, 62, 115, 115 }; +const short sublen1_12k8[7] = { 40, 40, 50, 50, 80, 80, 115 } ; +const short sec_length_12k8[4] = { 7, 15, 30, 54 }; +const short sec_length1_12k8[4] = { 10, 19, 37, 38 }; +const float h_fir[5] = {0.13f, 0.23f, 0.28f, 0.23f, 0.13f}; + +const float W_HIST[DTX_HIST_SIZE] = +{ + 0.2f, 0.16f, 0.128f, 0.1024f, 0.08192f, 0.065536f, 0.0524288f, 0.01048576f +}; + +const float preemphCompensation[NB_BANDS] = { 9.7461f, 9.5182f, 9.0262f, 8.3493f, 7.5764f, 6.7838f, 5.8377f, 4.8502f, 4.0346f, 3.2788f, 2.6283f, 2.0920f, 1.6304f, 1.2850f, 1.0108f, 0.7916f, 0.6268f, 0.5011f, 0.4119f, 0.3637f }; + +/*----------------------------------------------------------------------------------* + * LSF quantizer + *----------------------------------------------------------------------------------*/ + +const int lsf_numlevels[TCXLPC_NUMSTAGES] = { 32, 16, 16 }; +const int lsf_ind_numlevels[TCXLPC_IND_NUMSTAGES] = { 4 }; + +const short lsf_unified_fit_model_nb[4][16] = +{ + {12506 , -17641 , -6444 , -6646 , -3523 , -2132 , -511 , -92 , 699 , 1062 , 2578 , 3564 , 3200 , -285 , 2928 , -250}, + {20383 , 18855 , 8494 , 8062 , 8105 , 6211 , 5068 , 4408 , 3741 , 3458 , 2732 , 3174 , 2412 , 17421 , -21717 , 0}, + {-717 , -617 , -144 , -117 , -229 , -144 , -141 , -98 , -92 , -69 , -51 , -87 , -37 , -3019 , 19864 , 8034}, + {-2424 , 8999 , 5723 , 5629 , 4239 , 3423 , 2507 , 2019 , 1245 , 736 , -907 , -2237 , -2558 , -1979 , -652 , 1657} +}; + +const short lsf_unified_fit_model_wb[4][16] = +{ + {8323 , -567 , 3402 , 1389 , 1437 , 1820 , 1407 , 1299 , 1292 , 1206 , 1031 , 928 , 898 , 832 , 840 , 681}, + {24635 , 19605 , 9294 , 7407 , 6419 , 5459 , 4966 , 4189 , 3394 , 2964 , 2425 , 2110 , 2140 , 1972 , 1540 , 2252}, + {-867 , -666 , -168 , -114 , -90 , -122 , -129 , -101 , -65 , -56 , -39 , -35 , -40 , -42 , -35 , -56}, + {-2313 , 3035 , 1677 , 2854 , 2334 , 1232 , 1347 , 1034 , 863 , 707 , 886 , 891 , 432 , 357 , 206 , -310} +}; + +const short lsf_unified_fit_model_wbhb[4][16] = +{ + {5312 , 1967 , 2914 , 1438 , 2595 , 1848 , 1980 , 2021 , 1535 , 1489 , 1651 , 1502 , 1447 , 1311 , 1353 , 1202}, + {28135 , 16053 , 10129 , 7366 , 5898 , 5341 , 3290 , 2780 , 3146 , 2423 , 1613 , 1370 , 1294 , 1635 , 1105 , 1431}, + {-615 , -308 , -147 , -119 , -104 , -105 , -30 , -28 , -50 , -39 , -15 , -14 , -14 , -21 , -19 , -29}, + {1534 , 3569 , 3138 , 4023 , 2105 , 2023 , 2046 , 1264 , 1340 , 1067 , 780 , 547 , 188 , -540 , -722 , -479} +}; + +/* LPC weights used in SWB TBE */ +const float lpc_weights[LPC_SHB_ORDER+1] = +{ + 1.0f, 0.975000000f, 0.950625000f, 0.926859375f, 0.903687891f, + 0.881095693f, 0.859068301f, 0.837591593f, 0.816651804f, + 0.796235509f, 0.776329621f +}; + +/* LSF weighting */ +const float Freq_Weight_Com[160] = +{ + 0.50000000f, 0.62940955f, 0.75000000f, 0.85355341f, 0.93301272f, 0.98296291f, 1.00000000f, 1.00000000f, + 1.00000000f, 1.00000000f, 1.00000000f, 1.00000000f, 1.00000000f, 1.00000000f, 1.00000000f, 1.00000000f, + 1.00000000f, 1.00000000f, 1.00000000f, 1.00000000f, 1.00000000f, 0.97272730f, 0.94690263f, 0.92241377f, + 0.89915967f, 0.87704921f, 0.85600001f, 0.83593750f, 0.81679392f, 0.79850745f, 0.78102189f, 0.76428574f, + 0.74825174f, 0.73287672f, 0.71812081f, 0.70394737f, 0.69032258f, 0.67721522f, 0.66459626f, 0.65243900f, + 0.64071858f, 0.62941176f, 0.61849713f, 0.60795456f, 0.59776539f, 0.58791208f, 0.57837838f, 0.56914896f, + 0.56020945f, 0.55154639f, 0.54314721f, 0.53500003f, 0.52709359f, 0.51941746f, 0.51196170f, 0.50471699f, + 0.49767441f, 0.49082568f, 0.48416290f, 0.47767857f, 0.47136563f, 0.46521738f, 0.45922747f, 0.45338982f, + 0.44769874f, 0.44214877f, 0.43673471f, 0.43145162f, 0.42629483f, 0.42125985f, 0.41634241f, 0.41153845f, + 0.40684411f, 0.40225562f, 0.39776951f, 0.39338234f, 0.38909090f, 0.38489208f, 0.38078293f, 0.37676057f, + 0.37282231f, 0.36896551f, 0.36518770f, 0.36148649f, 0.35785952f, 0.35430464f, 0.35081968f, 0.34740260f, + 0.34405145f, 0.34076434f, 0.33753943f, 0.33437499f, 0.33126935f, 0.32822084f, 0.32522798f, 0.32228917f, + 0.31940299f, 0.31656805f, 0.31378299f, 0.31104651f, 0.30835736f, 0.30571428f, 0.30311614f, 0.30056179f, + 0.29805014f, 0.29558012f, 0.29315069f, 0.29076087f, 0.28840971f, 0.28609625f, 0.28381962f, 0.28157896f, + 0.27937338f, 0.27720207f, 0.27506426f, 0.27295917f, 0.27088606f, 0.26884422f, 0.26683292f, 0.26485148f, + 0.26289925f, 0.26097560f, 0.25907990f, 0.25721154f, 0.25536993f, 0.25355449f, 0.25176471f, 0.25000000f, + 0.24825986f, 0.24654378f, 0.24485126f, 0.24318182f, 0.24153499f, 0.23991032f, 0.23830736f, 0.23672566f, + 0.23516484f, 0.23362446f, 0.23210412f, 0.23060344f, 0.22912206f, 0.22765957f, 0.22621565f, 0.22478992f, + 0.22338204f, 0.22199170f, 0.22061856f, 0.21926230f, 0.21792261f, 0.21659920f, 0.21529175f, 0.21400000f, + 0.21272366f, 0.21146245f, 0.21021610f, 0.20898438f, 0.20776699f, 0.20656371f, 0.20537429f, 0.20419848f +}; + +const float Freq_Weight_UV[160] = +{ + 0.50000000f, 0.62940955f, 0.75000000f, 0.85355341f, 0.93301272f, 0.98296291f, 1.00000000f, 0.99180329f, + 0.98373985f, 0.97580647f, 0.96799999f, 0.96031743f, 0.95275593f, 0.94531250f, 0.93798447f, 0.93076921f, + 0.92366409f, 0.91666669f, 0.90977442f, 0.90298510f, 0.89629632f, 0.88970590f, 0.88321167f, 0.87681162f, + 0.87050360f, 0.86428571f, 0.85815603f, 0.85211265f, 0.84615386f, 0.84027779f, 0.83448273f, 0.82876712f, + 0.82312924f, 0.81756759f, 0.81208056f, 0.80666667f, 0.80132449f, 0.79605263f, 0.79084969f, 0.78571427f, + 0.78064513f, 0.77564102f, 0.77070063f, 0.76582277f, 0.76100630f, 0.75625002f, 0.75155282f, 0.74691355f, + 0.74233127f, 0.73780489f, 0.73333335f, 0.72891569f, 0.72455090f, 0.72023809f, 0.71597636f, 0.71176469f, + 0.70760232f, 0.70348835f, 0.69942194f, 0.69540232f, 0.69142854f, 0.68750000f, 0.68361580f, 0.67977530f, + 0.67597765f, 0.67222220f, 0.66850829f, 0.66483516f, 0.66120219f, 0.65760869f, 0.65405405f, 0.65053761f, + 0.64705884f, 0.64361703f, 0.64021164f, 0.63684213f, 0.63350785f, 0.63020831f, 0.62694299f, 0.62371135f, + 0.62051284f, 0.61734694f, 0.61421317f, 0.61111110f, 0.60804021f, 0.60500002f, 0.60199004f, 0.59900987f, + 0.59605908f, 0.59313726f, 0.59024388f, 0.58737862f, 0.58454108f, 0.58173078f, 0.57894737f, 0.57619047f, + 0.57345974f, 0.57075471f, 0.56807512f, 0.56542057f, 0.56279069f, 0.56018519f, 0.55760366f, 0.55504584f, + 0.55251139f, 0.55000001f, 0.54751134f, 0.54504502f, 0.54260087f, 0.54017860f, 0.53777778f, 0.53539824f, + 0.53303963f, 0.53070176f, 0.52838427f, 0.52608699f, 0.52380955f, 0.52155173f, 0.51931328f, 0.51709402f, + 0.51489359f, 0.51271188f, 0.51054853f, 0.50840336f, 0.50627613f, 0.50416666f, 0.50207472f, 0.50000000f, + 0.49794239f, 0.49590164f, 0.49387756f, 0.49186993f, 0.48987854f, 0.48790324f, 0.48594376f, 0.48400000f, + 0.48207173f, 0.48015872f, 0.47826087f, 0.47637796f, 0.47450981f, 0.47265625f, 0.47081712f, 0.46899223f, + 0.46718147f, 0.46538460f, 0.46360153f, 0.46183205f, 0.46007603f, 0.45833334f, 0.45660377f, 0.45488721f, + 0.45318353f, 0.45149255f, 0.44981414f, 0.44814816f, 0.44649446f, 0.44485295f, 0.44322345f, 0.44160584f +}; + +/*----------------------------------------------------------------------------------* + * Speech/music classification + *----------------------------------------------------------------------------------*/ + +const float w_spmus[HANG_LEN][HANG_LEN] = +{ + {1.0f, 0, 0, 0, 0, 0, 0, 0}, + {0.6f, 0.4f, 0, 0, 0, 0, 0, 0}, + {0.47f, 0.33f, 0.2f, 0, 0, 0, 0, 0}, + {0.4f, 0.3f, 0.2f, 0.1f, 0, 0, 0, 0}, + {0.30f, 0.25f, 0.2f, 0.15f, 0.1f, 0, 0, 0}, + {0.233f, 0.207f, 0.18f, 0.153f, 0.127f, 0.1f, 0, 0}, + {0.235f, 0.205f, 0.174f, 0.143f, 0.112f, 0.081f, 0.05f, 0}, + {0.200f, 0.179f, 0.157f, 0.136f, 0.114f, 0.093f, 0.071f, 0.05f} +}; + +const float m_speech[N_MIXTURES*N_FEATURES] = +{ + 0.287950f, 0.915145f, 0.146341f, 0.215938f, 0.337233f, 0.416424f, 0.464061f, 0.463680f, 0.059083f, 0.853025f, 0.768184f, 0.314352f, + 0.306930f, 0.936427f, 0.255783f, 0.304095f, 0.328435f, 0.264893f, 0.353664f, 0.481807f, 0.050087f, 0.816373f, 0.828952f, 0.335445f, + 0.241923f, 0.953049f, 0.219456f, 0.259538f, 0.436515f, 0.498549f, 0.456902f, 0.490619f, 0.062629f, 0.832243f, 0.845146f, 0.331393f, + 0.424629f, 0.528660f, 0.325986f, 0.502250f, 0.543419f, 0.561620f, 0.591057f, 0.386511f, 0.067280f, 0.903251f, 0.891515f, 0.344377f, + 0.380487f, 0.727792f, 0.209973f, 0.314364f, 0.421881f, 0.398734f, 0.446999f, 0.402498f, 0.105313f, 0.867979f, 0.877883f, 0.317694f, + 0.344962f, 0.658148f, 0.240913f, 0.348251f, 0.433178f, 0.480324f, 0.498983f, 0.419444f, 0.187060f, 0.868077f, 0.855516f, 0.347290f +}; + +const float invV_speech[N_MIXTURES*N_FEATURES*N_FEATURES] = +{ + -39.495125f, -14.409725f, -38.632778f, -17.688078f, 8.772461f, -11.402443f, 0.439471f, -10.340120f, -48.738274f, 0.349716f, 16.818443f, 32.142887f, + -14.409725f, -195.908417f, -27.029999f, -27.433266f, -16.451397f, -6.243556f, 5.814015f, 12.751663f, -65.479347f, -46.738777f, -8.373536f, 18.300566f, + -38.632782f, -27.029999f, -753.940247f, 115.388985f, -47.167007f, 27.107189f, -36.896187f, 72.593445f, -298.310120f, -22.776127f, 177.255432f, 89.802238f, + -17.688076f, -27.433270f, 115.388954f, -222.724594f, 40.140877f, -45.163593f, 21.461746f, 7.970023f, -27.137230f, 76.520920f, 25.476706f, 38.804222f, + 8.772461f, -16.451405f, -47.167007f, 40.140877f, -94.404678f, 40.199402f, -17.781452f, 3.901072f, -14.428046f, 23.148809f, 13.478944f, 17.505091f, + -11.402439f, -6.243560f, 27.107193f, -45.163593f, 40.199394f, -93.411865f, 57.189003f, 3.581622f, 0.100851f, 5.812640f, 9.256781f, 10.823537f, + 0.439471f, 5.814015f, -36.896187f, 21.461748f, -17.781452f, 57.189003f, -89.808571f, -5.465971f, -46.055283f, -15.567553f, 14.521687f, 10.769546f, + -10.340121f, 12.751663f, 72.593445f, 7.970019f, 3.901072f, 3.581622f, -5.465971f, -100.358055f, 24.768887f, -20.986031f, -47.276218f, 13.192144f, + -48.738274f, -65.479347f, -298.310120f, -27.137238f, -14.428048f, 0.100851f, -46.055275f, 24.768887f, -1377.781250f, -56.637291f, 233.195129f, -114.883377f, + 0.349715f, -46.738777f, -22.776127f, 76.520912f, 23.148806f, 5.812638f, -15.567553f, -20.986031f, -56.637291f, -216.730820f, -0.914011f, 39.627998f, + 16.818443f, -8.373537f, 177.255432f, 25.476713f, 13.478942f, 9.256781f, 14.521687f, -47.276218f, 233.195129f, -0.914013f, -153.435181f, -48.048389f, + 32.142887f, 18.300564f, 89.802223f, 38.804218f, 17.505091f, 10.823533f, 10.769546f, 13.192144f, -114.883377f, 39.628006f, -48.048389f, -313.631622f, + -53.471222f, -47.464245f, -0.896915f, -25.132132f, 30.892912f, -27.316641f, 22.758862f, -18.016706f, -66.564011f, -3.584184f, -7.795120f, 35.122147f, + -47.464249f, -438.709412f, -11.227010f, -14.463504f, 12.490106f, -11.184597f, 2.622577f, -3.664124f, -84.887161f, -29.377838f, -53.413090f, 17.047739f, + -0.896916f, -11.227015f, -251.993881f, 153.947250f, 4.508913f, 26.900564f, -22.145449f, 7.110321f, -215.903503f, -47.320839f, 78.247871f, 16.021702f, + -25.132132f, -14.463490f, 153.947235f, -326.623169f, 62.711872f, 7.543400f, 23.738796f, 19.846117f, -97.089355f, 2.828130f, 75.120659f, 34.945835f, + 30.892912f, 12.490105f, 4.508915f, 62.711872f, -289.161591f, 178.348740f, -26.642651f, 11.309997f, -10.248929f, 16.504482f, 48.839104f, 20.334949f, + -27.316643f, -11.184605f, 26.900568f, 7.543384f, 178.348740f, -267.764130f, 15.141651f, 4.242836f, -7.640367f, 77.632545f, -2.166305f, 12.531335f, + 22.758862f, 2.622574f, -22.145449f, 23.738796f, -26.642651f, 15.141647f, -71.479584f, 2.006794f, -4.579958f, 30.676281f, 15.085149f, 8.568682f, + -18.016706f, -3.664128f, 7.110321f, 19.846119f, 11.309998f, 4.242836f, 2.006794f, -76.086823f, 56.165844f, -8.384334f, -103.682259f, 6.086752f, + -66.564011f, -84.887161f, -215.903488f, -97.089355f, -10.248927f, -7.640366f, -4.579959f, 56.165840f, -1920.100708f, -8.861668f, 500.888123f, -16.967447f, + -3.584186f, -29.377846f, -47.320839f, 2.828135f, 16.504475f, 77.632553f, 30.676281f, -8.384336f, -8.861669f, -181.010406f, -15.615012f, 8.247152f, + -7.795123f, -53.413109f, 78.247864f, 75.120659f, 48.839104f, -2.166309f, 15.085151f, -103.682251f, 500.888123f, -15.615015f, -433.988953f, -70.138153f, + 35.122147f, 17.047737f, 16.021706f, 34.945835f, 20.334948f, 12.531336f, 8.568681f, 6.086751f, -16.967451f, 8.247154f, -70.138176f, -217.081589f, + -94.138069f, -64.204018f, 0.309024f, -46.150829f, 42.051434f, -41.965660f, 10.197500f, -19.122877f, -42.942600f, -19.220772f, -21.222412f, 46.903416f, + -64.204025f, -818.921143f, 30.093992f, -42.236637f, 6.486305f, -4.382217f, 10.975861f, 0.330433f, -16.922922f, -58.340889f, -111.845398f, -1.666081f, + 0.309030f, 30.093992f, -342.960907f, 202.719925f, -66.503586f, 59.412266f, -81.710594f, 14.449543f, -155.271118f, 13.000940f, 119.772522f, 37.219341f, + -46.150829f, -42.236637f, 202.719910f, -315.177094f, 74.731415f, -97.374359f, 58.435394f, 19.693314f, -62.044556f, 6.968471f, 74.460442f, 22.385506f, + 42.051434f, 6.486304f, -66.503578f, 74.731415f, -93.988602f, 52.841560f, -21.181007f, 2.344793f, -35.600548f, -19.262661f, 37.872654f, 6.642675f, + -41.965660f, -4.382209f, 59.412254f, -97.374352f, 52.841560f, -278.285614f, 214.990295f, -0.626728f, -43.822613f, -21.303955f, 15.663709f, 3.870531f, + 10.197496f, 10.975868f, -81.710587f, 58.435387f, -21.181000f, 214.990295f, -234.196167f, 1.970801f, -16.810629f, -1.859668f, 16.002600f, 3.998644f, + -19.122877f, 0.330433f, 14.449545f, 19.693314f, 2.344791f, -0.626729f, 1.970801f, -57.165413f, 20.255400f, -9.028506f, -83.099960f, 8.659401f, + -42.942604f, -16.922922f, -155.271103f, -62.044556f, -35.600552f, -43.822613f, -16.810629f, 20.255400f, -986.222534f, 27.520060f, 397.979370f, -10.706357f, + -19.220772f, -58.340889f, 13.000940f, 6.968470f, -19.262661f, -21.303955f, -1.859668f, -9.028505f, 27.520063f, -181.756256f, -31.725298f, 5.532037f, + -21.222410f, -111.845398f, 119.772507f, 74.460449f, 37.872654f, 15.663704f, 16.002598f, -83.099960f, 397.979370f, -31.725298f, -499.032318f, -64.723236f, + 46.903416f, -1.666086f, 37.219345f, 22.385508f, 6.642675f, 3.870531f, 3.998645f, 8.659404f, -10.706349f, 5.532042f, -64.723228f, -245.227646f, + -20.650835f, 1.359996f, -2.309748f, 3.667799f, -4.431922f, -1.491803f, 2.244124f, -6.511281f, -7.420423f, -2.656161f, -5.103209f, 2.977657f, + 1.359996f, -45.519173f, -27.833733f, 11.524545f, -5.826983f, 8.198447f, -4.084381f, 13.450377f, 18.150373f, -9.569582f, -6.539153f, -3.438999f, + -2.309748f, -27.833733f, -75.630455f, 54.383217f, -10.366678f, 10.230091f, -6.134814f, 5.390231f, -18.911335f, 8.611535f, -4.468428f, 2.542004f, + 3.667800f, 11.524545f, 54.383224f, -148.724060f, 102.126076f, -8.536950f, 14.920280f, -2.707708f, 16.232759f, -12.092183f, -2.761442f, 5.324492f, + -4.431922f, -5.826983f, -10.366676f, 102.126083f, -239.405472f, 114.426819f, -4.901945f, 3.331610f, -2.787818f, -19.461893f, 9.501407f, 1.843912f, + -1.491803f, 8.198447f, 10.230090f, -8.536962f, 114.426842f, -252.874207f, 133.055328f, -2.890811f, -8.063058f, -19.651783f, -6.576759f, -6.167914f, + 2.244124f, -4.084381f, -6.134819f, 14.920280f, -4.901949f, 133.055328f, -188.368149f, 0.868558f, -5.905251f, -73.150818f, 15.489239f, 3.931309f, + -6.511280f, 13.450379f, 5.390231f, -2.707708f, 3.331610f, -2.890812f, 0.868557f, -291.328827f, 8.357405f, 5.690188f, -65.318748f, -3.008168f, + -7.420423f, 18.150373f, -18.911335f, 16.232759f, -2.787818f, -8.063062f, -5.905251f, 8.357409f, -817.866455f, -35.719170f, 465.940338f, -57.209427f, + -2.656161f, -9.569582f, 8.611535f, -12.092187f, -19.461897f, -19.651789f, -73.150826f, 5.690184f, -35.719170f, -273.267426f, 28.788002f, 35.708652f, + -5.103208f, -6.539154f, -4.468427f, -2.761442f, 9.501406f, -6.576763f, 15.489231f, -65.318748f, 465.940338f, 28.788004f, -993.901489f, -74.051056f, + 2.977657f, -3.439001f, 2.542004f, 5.324495f, 1.843912f, -6.167918f, 3.931307f, -3.008166f, -57.209423f, 35.708649f, -74.051048f, -188.919189f, + -29.690845f, -6.602296f, -5.942207f, -8.191399f, 12.539626f, -17.187153f, 8.095049f, -11.539900f, -3.959312f, -2.929833f, -13.009781f, 14.593680f, + -6.602297f, -27.784903f, -12.036678f, -8.735461f, 10.268900f, -8.173005f, -0.508073f, 2.189236f, -3.210277f, -19.652676f, 0.174784f, 12.064508f, + -5.942207f, -12.036678f, -176.179718f, 87.371017f, -19.441795f, 2.946336f, -40.577980f, 4.105769f, -30.427385f, -23.225182f, 84.964821f, 43.734604f, + -8.191399f, -8.735461f, 87.371017f, -143.001602f, 51.919571f, -27.973251f, 29.284573f, -2.447426f, -11.954906f, 27.745192f, 11.595254f, 0.393728f, + 12.539626f, 10.268898f, -19.441788f, 51.919567f, -178.068130f, 128.031281f, -3.544543f, 6.851246f, -10.772905f, -42.477104f, 34.736156f, 40.172005f, + -17.187153f, -8.173005f, 2.946335f, -27.973251f, 128.031281f, -165.563629f, 51.259937f, -4.838826f, 3.758103f, 40.516190f, -7.739178f, -19.154724f, + 8.095048f, -0.508073f, -40.577976f, 29.284571f, -3.544538f, 51.259933f, -108.403847f, -0.894440f, 3.337809f, 2.241667f, 3.315053f, 1.456518f, + -11.539901f, 2.189236f, 4.105764f, -2.447426f, 6.851246f, -4.838827f, -0.894440f, -214.332535f, -4.848935f, -3.779825f, -75.247871f, -1.171161f, + -3.959312f, -3.210277f, -30.427393f, -11.954905f, -10.772905f, 3.758103f, 3.337807f, -4.848933f, -266.199005f, 2.878902f, 180.030838f, -44.094963f, + -2.929832f, -19.652674f, -23.225182f, 27.745188f, -42.477104f, 40.516193f, 2.241667f, -3.779825f, 2.878902f, -156.775406f, -11.596662f, 4.385890f, + -13.009781f, 0.174784f, 84.964828f, 11.595254f, 34.736156f, -7.739182f, 3.315054f, -75.247871f, 180.030838f, -11.596662f, -489.502777f, -57.779266f, + 14.593680f, 12.064507f, 43.734604f, 0.393729f, 40.172005f, -19.154715f, 1.456519f, -1.171165f, -44.094959f, 4.385883f, -57.779274f, -250.653564f, + -23.921967f, -5.683947f, -2.099401f, 0.128250f, 5.166994f, -10.038282f, 6.450608f, -0.731379f, -2.247439f, -4.157187f, 6.583568f, 4.081524f, + -5.683947f, -30.142115f, -8.658390f, -12.576810f, -1.309613f, 1.993960f, -4.383123f, 6.826682f, -0.827366f, -21.146013f, 3.620328f, 11.092305f, + -2.099401f, -8.658390f, -121.018547f, 88.485786f, -27.739552f, 24.281445f, -27.560604f, 3.724861f, 6.288231f, -12.520897f, 2.671664f, 12.669825f, + 0.128251f, -12.576811f, 88.485771f, -144.032974f, 84.679276f, -37.420727f, 25.546324f, 1.023258f, -7.474452f, 16.698721f, 8.763003f, 1.241009f, + 5.166994f, -1.309613f, -27.739553f, 84.679291f, -144.411407f, 72.554382f, -14.219510f, 2.006990f, 17.638592f, 1.209377f, -4.082684f, 14.381269f, + -10.038282f, 1.993960f, 24.281441f, -37.420734f, 72.554382f, -164.510483f, 115.127594f, -0.853720f, -16.850563f, 0.659630f, 12.865159f, -12.793469f, + 6.450607f, -4.383123f, -27.560604f, 25.546320f, -14.219501f, 115.127594f, -144.301163f, -12.984586f, 2.706392f, -4.143620f, -4.696592f, 1.570192f, + -0.731379f, 6.826682f, 3.724859f, 1.023259f, 2.006988f, -0.853720f, -12.984586f, -75.763382f, -31.576742f, -4.753652f, 9.548754f, -6.625205f, + -2.247438f, -0.827366f, 6.288230f, -7.474454f, 17.638592f, -16.850563f, 2.706394f, -31.576742f, -68.203148f, 11.220890f, 20.883671f, -23.079214f, + -4.157187f, -21.146011f, -12.520897f, 16.698721f, 1.209376f, 0.659629f, -4.143620f, -4.753652f, 11.220889f, -148.282272f, -2.460779f, 12.595567f, + 6.583566f, 3.620328f, 2.671665f, 8.763003f, -4.082685f, 12.865157f, -4.696593f, 9.548755f, 20.883675f, -2.460779f, -59.110310f, -3.725027f, + 4.081524f, 11.092305f, 12.669825f, 1.241007f, 14.381269f, -12.793469f, 1.570194f, -6.625203f, -23.079216f, 12.595569f, -3.725027f, -62.429104f +}; + +const float lvm_speech[N_MIXTURES] = +{ + 31.996607f, 32.762783f, 32.964325f, 31.979258f, 30.885334f, 26.185850f +}; + +const float m_music[N_MIXTURES*N_FEATURES] = +{ + 0.451772f, 0.776554f, 0.271046f, 0.354725f, 0.395602f, 0.413925f, 0.451482f, 0.627645f, 0.031510f, 0.835348f, 0.725457f, 0.357440f, + 0.487510f, 0.629043f, 0.236111f, 0.388441f, 0.440188f, 0.465005f, 0.494082f, 0.465069f, 0.069486f, 0.918461f, 0.858141f, 0.351628f, + 0.538064f, 0.605061f, 0.283209f, 0.430647f, 0.474700f, 0.497116f, 0.519075f, 0.527071f, 0.034547f, 0.951717f, 0.846345f, 0.380536f, + 0.484100f, 0.744331f, 0.238170f, 0.341071f, 0.358081f, 0.365782f, 0.392370f, 0.702362f, 0.021764f, 0.879612f, 0.725783f, 0.420504f, + 0.305845f, 0.692470f, 0.378321f, 0.465361f, 0.486968f, 0.499951f, 0.520584f, 0.473288f, 0.125325f, 0.726521f, 0.692794f, 0.374433f, + 0.513981f, 0.696380f, 0.246046f, 0.343276f, 0.374858f, 0.396051f, 0.418772f, 0.646286f, 0.026468f, 0.930184f, 0.778228f, 0.369588f +}; + +const float invV_music[N_MIXTURES*N_FEATURES*N_FEATURES] = +{ + -7.693553f, -0.657163f, -1.988950f, -0.864460f, -0.230076f, -0.650926f, 0.731884f, -1.685300f, -19.945335f, -0.839110f, 2.405366f, 3.916922f, + -0.657164f, -30.621262f, -1.553432f, -2.976453f, -1.828387f, 1.246830f, -3.716787f, 8.629019f, 5.424546f, -1.983033f, -10.816823f, -7.156825f, + -1.988950f, -1.553432f, -64.019180f, 41.928944f, -11.140388f, 11.880524f, 0.733497f, 8.586295f, 23.512827f, -15.433292f, -2.485986f, -2.458197f, + -0.864460f, -2.976454f, 41.928940f, -86.408936f, 41.949852f, -12.773962f, 4.663799f, 14.073083f, 23.178215f, -5.600554f, 14.946990f, 14.853354f, + -0.230076f, -1.828387f, -11.140390f, 41.949852f, -88.611122f, 37.060493f, -1.752939f, 3.927101f, -34.439037f, 12.153290f, 13.335299f, 16.994671f, + -0.650926f, 1.246830f, 11.880524f, -12.773962f, 37.060493f, -84.266197f, 37.053310f, 3.348819f, -5.522115f, 5.531706f, 8.455176f, -0.010933f, + 0.731884f, -3.716787f, 0.733498f, 4.663802f, -1.752939f, 37.053310f, -76.037888f, -8.315558f, -72.524521f, 21.789789f, 3.751793f, 0.630349f, + -1.685300f, 8.629018f, 8.586294f, 14.073083f, 3.927101f, 3.348819f, -8.315558f, -57.921276f, -118.393280f, 1.583935f, -8.300871f, 4.850578f, + -19.945335f, 5.424546f, 23.512829f, 23.178215f, -34.439041f, -5.522115f, -72.524521f, -118.393280f, -5404.569336f, 171.743378f, 241.973938f, -289.196930f, + -0.839109f, -1.983034f, -15.433292f, -5.600554f, 12.153290f, 5.531708f, 21.789789f, 1.583935f, 171.743362f, -101.897446f, -1.140457f, 31.464947f, + 2.405366f, -10.816823f, -2.485986f, 14.946990f, 13.335299f, 8.455174f, 3.751793f, -8.300871f, 241.973923f, -1.140458f, -77.658661f, -44.502563f, + 3.916922f, -7.156825f, -2.458197f, 14.853354f, 16.994675f, -0.010933f, 0.630349f, 4.850579f, -289.196899f, 31.464947f, -44.502563f, -243.168915f, + -9.878029f, 0.598697f, -4.302856f, -0.393763f, 0.713794f, 0.876955f, 0.341871f, -1.948222f, -8.764623f, -0.165505f, -1.265450f, 1.204445f, + 0.598697f, -29.943895f, -12.133356f, -1.089194f, -1.817891f, 2.837961f, -2.426654f, 12.585359f, -8.634910f, -11.784335f, 4.719538f, 2.997951f, + -4.302856f, -12.133356f, -84.521080f, 48.461727f, -11.249048f, 15.025650f, -19.584152f, 20.383547f, -13.363368f, 27.676975f, 22.609833f, -0.788566f, + -0.393763f, -1.089193f, 48.461727f, -128.134705f, 79.103844f, 1.020304f, 3.012457f, 7.957530f, -11.608212f, -3.021832f, 42.826736f, 14.192619f, + 0.713794f, -1.817891f, -11.249048f, 79.103836f, -220.859680f, 112.957855f, 8.839993f, -6.276199f, -19.145348f, -19.927418f, 7.305478f, 5.922347f, + 0.876955f, 2.837961f, 15.025646f, 1.020303f, 112.957878f, -275.141998f, 147.030670f, -5.400043f, 0.264864f, -5.583443f, 1.633528f, 7.493776f, + 0.341871f, -2.426655f, -19.584156f, 3.012456f, 8.839993f, 147.030670f, -196.030136f, -21.359327f, -9.146851f, 10.225628f, -2.139116f, 3.010611f, + -1.948222f, 12.585359f, 20.383547f, 7.957529f, -6.276197f, -5.400044f, -21.359325f, -108.690598f, -28.919056f, -26.963711f, -53.457581f, -9.210483f, + -8.764623f, -8.634909f, -13.363366f, -11.608211f, -19.145348f, 0.264862f, -9.146851f, -28.919056f, -602.275146f, 73.117203f, 185.012711f, -77.751747f, + -0.165505f, -11.784335f, 27.676975f, -3.021834f, -19.927414f, -5.583444f, 10.225626f, -26.963711f, 73.117210f, -350.919952f, -12.616115f, 28.914690f, + -1.265450f, 4.719537f, 22.609833f, 42.826729f, 7.305476f, 1.633531f, -2.139116f, -53.457581f, 185.012711f, -12.616107f, -398.114899f, -16.563597f, + 1.204445f, 2.997951f, -0.788567f, 14.192617f, 5.922347f, 7.493775f, 3.010611f, -9.210481f, -77.751747f, 28.914690f, -16.563597f, -176.464386f, + -12.120523f, 5.409175f, -1.857854f, 0.089656f, 2.747151f, 0.330849f, -0.110976f, -1.052840f, -23.532089f, -2.869304f, -1.769891f, 0.390127f, + 5.409175f, -35.374779f, -7.060057f, -0.748528f, -2.384489f, 2.017226f, -2.828100f, 8.307317f, 16.044216f, -11.155272f, -11.784020f, -0.186719f, + -1.857854f, -7.060059f, -112.721130f, 43.297070f, 11.361997f, 13.618838f, -3.489388f, 22.195547f, -71.385941f, 116.419769f, 68.520813f, 4.576182f, + 0.089655f, -0.748527f, 43.297066f, -183.503693f, 79.711113f, 24.255428f, 12.465648f, 1.436299f, -42.306995f, -23.502007f, 43.622116f, 3.459679f, + 2.747151f, -2.384489f, 11.361995f, 79.711113f, -288.300781f, 101.748329f, 51.744507f, -3.170304f, -142.892792f, -76.845322f, 33.559555f, -2.748073f, + 0.330848f, 2.017227f, 13.618836f, 24.255434f, 101.748344f, -339.510773f, 165.319336f, -4.353420f, -124.114395f, -92.283844f, 41.981186f, 5.566007f, + -0.110976f, -2.828100f, -3.489391f, 12.465652f, 51.744499f, 165.319336f, -302.816223f, -18.169355f, -26.544678f, -18.664721f, -2.650121f, 0.010451f, + -1.052840f, 8.307317f, 22.195547f, 1.436298f, -3.170304f, -4.353420f, -18.169355f, -67.658730f, 39.626808f, -46.781792f, -132.578033f, -6.489147f, + -23.532089f, 16.044214f, -71.385941f, -42.306988f, -142.892792f, -124.114395f, -26.544678f, 39.626808f, -8048.467285f, -69.854523f, 1809.758301f, -171.409134f, + -2.869304f, -11.155272f, 116.419769f, -23.502005f, -76.845306f, -92.283836f, -18.664721f, -46.781792f, -69.854530f, -1329.704834f, -35.750607f, 26.050083f, + -1.769890f, -11.784019f, 68.520813f, 43.622116f, 33.559555f, 41.981186f, -2.650122f, -132.578033f, 1809.758423f, -35.750607f, -1306.246704f, -81.942009f, + 0.390127f, -0.186719f, 4.576182f, 3.459679f, -2.748072f, 5.566006f, 0.010449f, -6.489147f, -171.409149f, 26.050083f, -81.942001f, -218.411270f, + -8.602416f, 3.247867f, -1.244849f, -1.473311f, 1.389639f, 1.193549f, -0.749351f, -3.831526f, -63.977875f, -5.851153f, 9.731353f, 3.762766f, + 3.247867f, -31.158295f, -1.860033f, 4.017265f, -4.594161f, 1.111136f, -0.570251f, 10.457798f, 101.742371f, 5.974397f, -29.646946f, -5.117320f, + -1.244849f, -1.860033f, -180.090790f, 66.379784f, -17.006353f, 31.490606f, -6.954518f, 15.675142f, -2.924051f, -51.747025f, 22.995018f, 27.119001f, + -1.473310f, 4.017266f, 66.379791f, -156.629517f, 84.327309f, -8.737753f, 13.449555f, 8.031604f, 3.398430f, 2.564645f, 23.766497f, 1.825905f, + 1.389639f, -4.594161f, -17.006353f, 84.327293f, -194.113434f, 66.407173f, 7.188343f, 13.696414f, 10.890992f, 22.594927f, 12.302410f, 9.738532f, + 1.193549f, 1.111136f, 31.490606f, -8.737754f, 66.407173f, -162.236801f, 56.553402f, 17.216257f, 115.981384f, 38.547184f, 1.763872f, 7.097052f, + -0.749351f, -0.570251f, -6.954517f, 13.449550f, 7.188342f, 56.553402f, -120.315659f, 2.011221f, 46.796513f, 58.099625f, 10.238644f, -4.947532f, + -3.831526f, 10.457799f, 15.675138f, 8.031604f, 13.696414f, 17.216261f, 2.011219f, -88.214516f, -358.424683f, -29.549349f, -19.958910f, -2.982261f, + -63.977875f, 101.742371f, -2.924051f, 3.398430f, 10.890991f, 115.981384f, 46.796513f, -358.424683f, -16459.796875f, -177.281921f, 882.743164f, -92.799385f, + -5.851152f, 5.974398f, -51.747017f, 2.564646f, 22.594927f, 38.547184f, 58.099625f, -29.549349f, -177.281921f, -313.395386f, -11.227232f, 55.211266f, + 9.731353f, -29.646946f, 22.995022f, 23.766500f, 12.302408f, 1.763873f, 10.238644f, -19.958918f, 882.743225f, -11.227232f, -192.809204f, -15.728045f, + 3.762767f, -5.117321f, 27.118999f, 1.825905f, 9.738532f, 7.097054f, -4.947530f, -2.982259f, -92.799385f, 55.211269f, -15.728045f, -105.412018f, + -14.256830f, -2.369603f, -4.383267f, 2.198855f, 0.019220f, -0.679427f, -2.574428f, 5.400897f, 1.071412f, 0.106907f, 1.327079f, 2.677950f, + -2.369603f, -22.438606f, 1.295039f, -4.309244f, -6.401002f, 0.194309f, -2.196638f, 15.858343f, 6.752327f, -6.119870f, 1.303229f, -0.311533f, + -4.383267f, 1.295039f, -37.935478f, 39.653362f, -15.988548f, -0.134974f, 6.192506f, 2.302801f, -5.721854f, 1.463135f, -1.312438f, -3.824724f, + 2.198855f, -4.309245f, 39.653366f, -92.374901f, 67.554337f, -3.709706f, -16.418154f, -5.289310f, -10.926604f, -3.034606f, 2.011261f, -3.425366f, + 0.019220f, -6.401002f, -15.988548f, 67.554329f, -118.435379f, 53.987152f, 0.083914f, 3.628703f, 11.506127f, -9.430386f, 3.335730f, 0.535830f, + -0.679426f, 0.194309f, -0.134974f, -3.709705f, 53.987152f, -103.065208f, 60.766655f, 5.174506f, 3.534084f, 1.888132f, -2.451842f, 0.595043f, + -2.574428f, -2.196638f, 6.192506f, -16.418154f, 0.083914f, 60.766647f, -77.825020f, -7.066206f, -9.501147f, -2.838846f, 2.729818f, 0.055436f, + 5.400897f, 15.858343f, 2.302801f, -5.289312f, 3.628702f, 5.174504f, -7.066205f, -51.364357f, -39.811016f, -5.072917f, 2.924570f, 10.896112f, + 1.071412f, 6.752328f, -5.721853f, -10.926604f, 11.506124f, 3.534082f, -9.501149f, -39.811012f, -93.637161f, 18.029125f, 2.729363f, -18.075464f, + 0.106908f, -6.119870f, 1.463135f, -3.034606f, -9.430385f, 1.888131f, -2.838846f, -5.072917f, 18.029125f, -28.455194f, 2.956357f, 16.863293f, + 1.327079f, 1.303229f, -1.312438f, 2.011261f, 3.335730f, -2.451841f, 2.729818f, 2.924570f, 2.729363f, 2.956357f, -10.622586f, -6.668186f, + 2.677950f, -0.311532f, -3.824724f, -3.425365f, 0.535831f, 0.595042f, 0.055436f, 10.896112f, -18.075462f, 16.863293f, -6.668186f, -47.191391f, + -9.240052f, 2.899430f, -1.061725f, -1.878852f, 1.384787f, -0.341924f, 0.387138f, -3.050452f, -34.497913f, 0.665648f, 3.172123f, 5.710633f, + 2.899430f, -28.464540f, -2.599636f, 2.343385f, -2.987666f, 2.706673f, 0.826991f, 8.178236f, 58.632381f, -6.619084f, -22.678297f, -7.513733f, + -1.061725f, -2.599636f, -168.556702f, 81.834229f, 2.535699f, 32.237877f, 3.761089f, 12.106804f, 80.076279f, -79.117699f, 15.459833f, 34.635460f, + -1.878852f, 2.343384f, 81.834229f, -199.355972f, 64.456390f, 2.859692f, 17.605833f, 14.360981f, 8.356211f, 15.654006f, 43.245403f, 35.328991f, + 1.384787f, -2.987666f, 2.535698f, 64.456375f, -197.841049f, 46.107910f, 19.035957f, 10.296391f, -4.554988f, 45.390419f, 10.640046f, 17.738880f, + -0.341924f, 2.706673f, 32.237885f, 2.859688f, 46.107910f, -193.370590f, 74.545746f, 13.889868f, 120.411064f, 69.282364f, 1.826012f, 8.071488f, + 0.387138f, 0.826990f, 3.761087f, 17.605829f, 19.035957f, 74.545746f, -173.431549f, -5.219500f, 77.031425f, 112.113403f, -0.166995f, 3.456159f, + -3.050452f, 8.178238f, 12.106802f, 14.360980f, 10.296390f, 13.889872f, -5.219500f, -66.011856f, -245.560532f, -53.745152f, -21.376526f, 7.093097f, + -34.497917f, 58.632385f, 80.076279f, 8.356211f, -4.554988f, 120.411072f, 77.031425f, -245.560532f, -12485.017578f, -211.927429f, 791.254944f, -708.115784f, + 0.665648f, -6.619084f, -79.117699f, 15.654002f, 45.390419f, 69.282356f, 112.113403f, -53.745152f, -211.927429f, -775.154602f, -7.915978f, 73.130432f, + 3.172123f, -22.678297f, 15.459837f, 43.245403f, 10.640046f, 1.826011f, -0.166995f, -21.376526f, 791.254944f, -7.915982f, -312.138367f, -76.008308f, + 5.710633f, -7.513731f, 34.635460f, 35.328983f, 17.738880f, 8.071489f, 3.456159f, 7.093094f, -708.115784f, 73.130432f, -76.008293f, -469.943726f +}; + +const float lvm_music[N_MIXTURES] = +{ + 27.932661f, 30.347250f, 34.528702f, 31.239647f, 20.447638f, 33.589111f +}; + +const float m_noise[N_MIXTURES*N_FEATURES] = +{ + 0.452427f, 0.570086f, 0.242006f, 0.342721f, 0.403700f, 0.415107f, 0.444218f, 0.438761f, 0.034564f, 0.893050f, 0.819168f, 0.404974f, + 0.436768f, 0.457530f, 0.286204f, 0.393398f, 0.429530f, 0.444983f, 0.474495f, 0.377982f, 0.032033f, 0.980933f, 0.864315f, 0.377762f, + 0.554771f, 0.507113f, 0.244596f, 0.401393f, 0.425160f, 0.441338f, 0.467793f, 0.361573f, 0.031537f, 0.971703f, 0.866892f, 0.372985f, + 0.482864f, 0.545745f, 0.098616f, 0.246756f, 0.304649f, 0.303124f, 0.352083f, 0.363268f, 0.031057f, 0.901759f, 0.838419f, 0.339094f, + 0.421798f, 0.491610f, 0.266544f, 0.367277f, 0.407442f, 0.415130f, 0.458496f, 0.395402f, 0.035484f, 0.951506f, 0.861898f, 0.362091f, + 0.422524f, 0.475384f, 0.321804f, 0.436169f, 0.468526f, 0.481682f, 0.505572f, 0.389095f, 0.048487f, 0.967269f, 0.878799f, 0.409561f +}; + +const float invV_noise[N_MIXTURES*N_FEATURES*N_FEATURES] = +{ + -10.867715f, -0.756548f, -0.787901f, 4.638586f, -4.208551f, -1.593690f, 1.654504f, 0.517274f, -24.544769f, -2.342500f, 1.593914f, 1.892730f, + -0.756548f, -42.676064f, -5.171525f, -22.601748f, -3.989791f, -1.960918f, 9.223408f, 12.652583f, 16.718012f, 10.374084f, -17.742804f, -14.035854f, + -0.787901f, -5.171525f, -115.159836f, 77.010605f, -22.974529f, 22.149885f, -7.457938f, 51.154774f, 20.176580f, -1.104116f, 17.582054f, -18.231829f, + 4.638585f, -22.601746f, 77.010605f, -162.083023f, 69.046974f, -0.931657f, 9.922201f, 6.555853f, 49.297676f, 18.854517f, -9.951534f, 16.527628f, + -4.208551f, -3.989791f, -22.974525f, 69.046974f, -181.796692f, 112.212860f, -28.314665f, 9.765093f, 17.263042f, -17.941118f, -20.316977f, -12.281874f, + -1.593690f, -1.960918f, 22.149881f, -0.931659f, 112.212860f, -230.312469f, 120.808189f, -3.664834f, 21.109715f, 8.984108f, 15.273976f, -10.366921f, + 1.654504f, 9.223406f, -7.457942f, 9.922205f, -28.314672f, 120.808205f, -152.423096f, -1.527340f, -7.447964f, 5.038412f, 13.851591f, -12.278207f, + 0.517274f, 12.652583f, 51.154770f, 6.555853f, 9.765094f, -3.664836f, -1.527341f, -113.809120f, -127.203827f, -2.824038f, -50.058937f, -1.399267f, + -24.544767f, 16.718014f, 20.176580f, 49.297676f, 17.263042f, 21.109715f, -7.447963f, -127.203827f, -6696.807617f, -22.621326f, 415.747192f, -168.268478f, + -2.342500f, 10.374086f, -1.104114f, 18.854517f, -17.941120f, 8.984108f, 5.038413f, -2.824039f, -22.621326f, -153.911545f, 9.088697f, 20.155067f, + 1.593914f, -17.742804f, 17.582056f, -9.951534f, -20.316977f, 15.273976f, 13.851592f, -50.058945f, 415.747162f, 9.088697f, -180.485260f, -2.179248f, + 1.892730f, -14.035856f, -18.231823f, 16.527628f, -12.281875f, -10.366921f, -12.278206f, -1.399268f, -168.268478f, 20.155067f, -2.179248f, -92.283646f, + -23.031761f, -1.252800f, 2.168407f, 5.677273f, -1.038399f, -5.394459f, 4.921468f, -0.398360f, -7.562253f, 64.160614f, -4.832063f, 1.192536f, + -1.252800f, -99.841995f, 18.003206f, -17.730101f, -6.070672f, 16.703362f, -1.826001f, 24.508341f, 95.143112f, 31.486519f, -75.776428f, -4.459583f, + 2.168407f, 18.003206f, -298.278900f, 136.582794f, 23.557480f, 32.080963f, -44.544701f, 44.470726f, 121.132362f, 294.113434f, -22.118645f, 3.540136f, + 5.677273f, -17.730099f, 136.582779f, -552.121826f, 236.890076f, 45.754177f, 49.528828f, -18.333956f, -155.456558f, 137.723495f, 87.803368f, 9.539282f, + -1.038398f, -6.070671f, 23.557480f, 236.890076f, -779.760498f, 250.522018f, 101.655136f, 9.155396f, -82.543655f, -398.953156f, 95.902740f, 4.389515f, + -5.394459f, 16.703358f, 32.080971f, 45.754185f, 250.522049f, -825.768005f, 305.349487f, -6.825818f, 49.064461f, -530.656738f, -41.630035f, 0.097057f, + 4.921468f, -1.825999f, -44.544685f, 49.528828f, 101.655106f, 305.349457f, -714.934082f, 14.071314f, 81.227341f, -137.562592f, -2.118532f, -2.266444f, + -0.398360f, 24.508341f, 44.470741f, -18.333960f, 9.155393f, -6.825818f, 14.071318f, -306.676453f, 267.131439f, -29.354313f, -247.414047f, -3.381219f, + -7.562254f, 95.143112f, 121.132362f, -155.456558f, -82.543648f, 49.064457f, 81.227341f, 267.131439f, -18849.244141f, -929.838013f, 3582.389648f, -91.670364f, + 64.160622f, 31.486523f, 294.113434f, 137.723495f, -398.953186f, -530.656738f, -137.562607f, -29.354321f, -929.838013f, -15657.494141f, -160.551666f, -23.622292f, + -4.832063f, -75.776428f, -22.118641f, 87.803375f, 95.902733f, -41.630043f, -2.118535f, -247.414047f, 3582.389648f, -160.551666f, -2443.248535f, -102.662750f, + 1.192536f, -4.459581f, 3.540133f, 9.539283f, 4.389517f, 0.097059f, -2.266439f, -3.381226f, -91.670372f, -23.622292f, -102.662750f, -246.260574f, + -11.285410f, 5.316821f, 1.028375f, 1.780153f, -1.713055f, -6.356722f, 3.452291f, -0.472106f, 5.616539f, 22.361168f, -4.266212f, 2.444066f, + 5.316821f, -59.978729f, -45.510380f, 0.510493f, -4.121831f, 5.250934f, -14.358817f, 2.281706f, 4.310630f, 4.492869f, 17.377964f, 5.232576f, + 1.028376f, -45.510380f, -192.404053f, 60.491817f, 29.311884f, 10.877782f, -13.830601f, 4.475446f, 14.358991f, 170.638504f, 103.112320f, 3.708024f, + 1.780153f, 0.510493f, 60.491817f, -566.125488f, 303.482666f, -24.292496f, -8.399674f, -1.485864f, -37.162815f, -301.527344f, 10.013409f, 11.255829f, + -1.713055f, -4.121831f, 29.311880f, 303.482666f, -852.739014f, 287.208618f, 7.622868f, 2.283498f, -27.422876f, -496.049957f, -5.396815f, -1.631967f, + -6.356722f, 5.250934f, 10.877782f, -24.292484f, 287.208618f, -723.304810f, 301.939606f, -18.888754f, -49.648453f, -140.429428f, 26.881662f, 4.222802f, + 3.452292f, -14.358817f, -13.830603f, -8.399690f, 7.622864f, 301.939575f, -496.315796f, 24.400175f, 203.557098f, -224.619278f, -47.202961f, -9.425015f, + -0.472106f, 2.281706f, 4.475447f, -1.485866f, 2.283498f, -18.888754f, 24.400175f, -354.005493f, 136.772644f, -115.911537f, -131.393005f, 0.959444f, + 5.616539f, 4.310630f, 14.358991f, -37.162819f, -27.422880f, -49.648449f, 203.557098f, 136.772644f, -20332.845703f, -321.084869f, 3009.444580f, -97.580765f, + 22.361168f, 4.492869f, 170.638519f, -301.527344f, -496.049957f, -140.429428f, -224.619293f, -115.911537f, -321.084839f, -7067.310059f, -220.679733f, -46.764927f, + -4.266212f, 17.377964f, 103.112320f, 10.013409f, -5.396815f, 26.881662f, -47.202957f, -131.393005f, 3009.444336f, -220.679733f, -2442.017334f, -122.001373f, + 2.444066f, 5.232576f, 3.708023f, 11.255831f, -1.631966f, 4.222802f, -9.425015f, 0.959446f, -97.580765f, -46.764931f, -122.001373f, -270.966095f, + -14.192688f, 3.186916f, -7.950537f, 12.989626f, 5.455102f, 1.765226f, -5.165048f, 0.461338f, 7.198293f, -20.877787f, -2.402384f, 0.581967f, + 3.186916f, -44.923344f, -55.269123f, 8.982286f, -0.746719f, 13.665676f, 5.123918f, 2.567272f, -14.412151f, -21.068356f, 5.512080f, 3.727387f, + -7.950538f, -55.269123f, -874.676270f, 396.753632f, -241.704224f, 70.721024f, -240.685715f, 31.769787f, -186.425156f, -72.526421f, 58.346741f, 10.030197f, + 12.989626f, 8.982285f, 396.753632f, -538.253601f, 134.091171f, 33.957142f, -5.240913f, 40.302223f, 65.792999f, 256.190460f, 41.462269f, 59.464478f, + 5.455101f, -0.746719f, -241.704254f, 134.091171f, -942.252197f, 384.468231f, 36.093376f, 5.026894f, 111.673508f, 64.876976f, -19.179228f, 18.067732f, + 1.765226f, 13.665678f, 70.721085f, 33.957142f, 384.468231f, -885.075134f, 358.333008f, 13.728846f, 74.583847f, 277.755707f, 15.872023f, 32.199970f, + -5.165048f, 5.123920f, -240.685776f, -5.240921f, 36.093372f, 358.333008f, -694.631653f, 22.914997f, 82.867088f, 154.286697f, 2.264358f, 21.074474f, + 0.461338f, 2.567272f, 31.769791f, 40.302223f, 5.026892f, 13.728846f, 22.915001f, -341.417511f, -72.276520f, -87.553932f, -17.271832f, 7.437448f, + 7.198294f, -14.412151f, -186.425171f, 65.792999f, 111.673508f, 74.583847f, 82.867088f, -72.276520f, -16628.691406f, -258.116119f, 387.521759f, -260.230133f, + -20.877787f, -21.068354f, -72.526451f, 256.190460f, 64.876984f, 277.755707f, 154.286697f, -87.553932f, -258.116089f, -851.111816f, 3.469927f, 2.253677f, + -2.402384f, 5.512080f, 58.346741f, 41.462273f, -19.179226f, 15.872023f, 2.264359f, -17.271832f, 387.521759f, 3.469929f, -327.105011f, -45.187340f, + 0.581967f, 3.727389f, 10.030209f, 59.464478f, 18.067736f, 32.199970f, 21.074471f, 7.437444f, -260.230133f, 2.253681f, -45.187363f, -348.881165f, + -20.546539f, -1.232953f, -6.539483f, 7.977976f, -1.242327f, -4.323449f, 4.044850f, -8.261212f, -61.714569f, -16.814053f, 0.693824f, 2.217177f, + -1.232953f, -81.245918f, -33.514919f, -26.628014f, 2.160939f, -0.234839f, -0.764257f, 21.764839f, 133.689529f, 9.364232f, -27.287352f, -6.621866f, + -6.539483f, -33.514919f, -321.563904f, 105.228661f, 0.660729f, -32.550903f, -45.134315f, 42.045963f, -200.154724f, -42.022831f, 200.115005f, 19.959410f, + 7.977976f, -26.628016f, 105.228653f, -362.669098f, 100.723396f, 10.423860f, 45.250904f, -3.221930f, -63.687748f, -41.052856f, -5.156573f, 12.700191f, + -1.242327f, 2.160941f, 0.660730f, 100.723396f, -410.276917f, 189.899841f, 1.538413f, 21.637842f, -26.361103f, 35.868237f, 46.390850f, 13.527671f, + -4.323449f, -0.234840f, -32.550911f, 10.423860f, 189.899841f, -359.953278f, 149.268143f, 13.839684f, 104.534042f, 43.236813f, -23.356220f, -8.712662f, + 4.044850f, -0.764257f, -45.134308f, 45.250904f, 1.538413f, 149.268143f, -274.089874f, -8.017480f, 39.217266f, 23.817112f, 13.071558f, 8.212641f, + -8.261212f, 21.764839f, 42.045967f, -3.221937f, 21.637842f, 13.839684f, -8.017480f, -250.062653f, 77.902710f, -1.225836f, -98.802437f, 0.740895f, + -61.714565f, 133.689514f, -200.154709f, -63.687748f, -26.361105f, 104.534027f, 39.217266f, 77.902695f, -12793.175781f, 257.379974f, 1953.936523f, -236.987503f, + -16.814053f, 9.364232f, -42.022831f, -41.052856f, 35.868237f, 43.236813f, 23.817108f, -1.225832f, 257.379974f, -1194.391846f, -211.503952f, -22.654963f, + 0.693823f, -27.287352f, 200.115005f, -5.156573f, 46.390850f, -23.356216f, 13.071561f, -98.802437f, 1953.936523f, -211.503983f, -1273.349854f, -88.061317f, + 2.217178f, -6.621865f, 19.959414f, 12.700191f, 13.527678f, -8.712662f, 8.212641f, 0.740895f, -236.987518f, -22.654963f, -88.061317f, -364.010010f, + -23.764925f, -0.313664f, -1.392676f, 1.488295f, 1.913436f, -4.066601f, 6.848008f, -3.074351f, -7.675101f, 9.171298f, 3.117799f, 2.142688f, + -0.313664f, -88.759735f, -8.855761f, -26.637909f, 5.178853f, 10.666278f, 2.244489f, 21.984133f, 16.797499f, 4.685480f, 13.074540f, -2.708393f, + -1.392676f, -8.855759f, -175.915054f, 83.474174f, 41.251793f, 14.369057f, -12.605553f, 33.395245f, 65.670242f, 39.710125f, 36.098553f, -9.562349f, + 1.488295f, -26.637909f, 83.474182f, -383.095245f, 216.683212f, 12.198986f, 32.383698f, -14.022625f, 7.763216f, -100.727264f, -28.525242f, -5.235438f, + 1.913436f, 5.178854f, 41.251801f, 216.683212f, -586.877808f, 253.507355f, 29.591257f, 7.710151f, -31.813087f, -112.656593f, 20.279724f, -7.102311f, + -4.066601f, 10.666278f, 14.369057f, 12.198978f, 253.507355f, -597.128113f, 296.967621f, 6.174671f, -41.961372f, -36.203259f, -20.597570f, -14.877533f, + 6.848009f, 2.244488f, -12.605548f, 32.383701f, 29.591269f, 296.967590f, -456.794678f, 26.321606f, -34.872383f, 28.424320f, 34.979023f, -8.548788f, + -3.074351f, 21.984133f, 33.395245f, -14.022625f, 7.710150f, 6.174670f, 26.321606f, -265.545593f, 2.918175f, 0.831582f, -125.449432f, -11.139709f, + -7.675101f, 16.797503f, 65.670242f, 7.763219f, -31.813070f, -41.961380f, -34.872383f, 2.918175f, -1731.894409f, -210.794144f, 739.213074f, -97.542229f, + 9.171299f, 4.685479f, 39.710129f, -100.727264f, -112.656593f, -36.203262f, 28.424320f, 0.831581f, -210.794113f, -2326.243652f, -106.282173f, 1.036536f, + 3.117799f, 13.074540f, 36.098553f, -28.525242f, 20.279724f, -20.597570f, 34.979023f, -125.449432f, 739.213074f, -106.282112f, -1878.532593f, -113.480858f, + 2.142687f, -2.708396f, -9.562349f, -5.235439f, -7.102309f, -14.877532f, -8.548790f, -11.139709f, -97.542229f, 1.036536f, -113.480865f, -101.406532f +}; + +const float lvm_noise[N_MIXTURES] = +{ + 28.723963f, 41.180500f, 39.296734f, 38.508724f, 37.029205f, 35.496319f +}; + +const float SF[N_FEATURES*2] = +{ + 0.0048f, -0.0952f, + 1.0002f, 0, + 0.6226f, -0.0695f, + 0.5497f, -0.1265f, + 0.4963f, -0.2230f, + 0.5049f, -0.4103f, + 0.5069f, -0.5717f, + 0.0041f, 0, + 0.0022f, -0.0029f, + 0.0630f, 1.0015f, + 0.0684f, 0.9103f, + 0.1159f, -0.2931f +}; + +const float SF_8k[N_FEATURES*2] = +{ + 0.0041f, 0, + 0.8572f, 0.1020f, + 0.6739f, -0.1000f, + 0.6257f, -0.1678f, + 0.5495f, -0.2380f, + 0.5793f, -0.4646f, + 0.2502f, 0, + 0.0041f, 0, + 0.0020f, 0, + 0.0630f, 1.0015f, + 0.0598f, 0.8967f, + 0.0631f, 0 +}; + + +/* searching thresholds for quantization of peak gains */ +const float thren_pg[44] = +{ + 120193.5539509f, 101070.3286539f, + 84989.6770536f, 71467.5147680f, + 60096.7769755f, 50535.1643270f, + 42494.8385268f, 35733.7573840f, + 30048.3884877f, 25267.5821635f, + 19483.9693722f, 13777.2468675f, + 9741.9846861f, 6888.6234338f, + 4870.9923431f, 3444.3117169f, + 2435.4961715f, 1722.1558584f, + 1217.7480858f, 861.0779292f, + 608.8740429f, 430.5389646f, + 304.4370214f, 215.2694823f, + 152.2185107f, 107.6347412f, + 76.1092554f, 53.8173706f, + 38.0546277f, 26.9086853f, + 19.0273138f, 13.4543426f, + 9.5136569f, 6.7271713f, + 4.7568285f, 3.3635857f, + 2.3784142f, 1.6817928f, + 1.1892071f, 0.840896f, + 0.594604f, 0.420448f, + 0.297302f, 0.210224f +}; + +/* Huffmann coding - searching thresholds for quantization of peak gains */ +const short huffnorm_e[32] = +{ + 1062, 550, 314, 274, 273, 272, 156, 79, 69, 38, + 18, 40, 5, 3, 0, 1, 3, 4, 11, 21, + 41, 32, 35, 67, 133, 264, 530, 315, 551, 2126, 4254, 4255 +}; + +const short huffnorm_n[32] = +{ + 14831, 14830, 7414, 3706, 593, 927, 462, 297, 230, 116, + 50, 36, 13, 8, 5, 1, 0, 2, 6, 7, + 15, 19, 24, 56, 59, 51, 114, 117, 75, 149, 592, 1852 +}; + +const short huffsizn_e[32] = +{ + 13, 12, 11, 11, 11, 11, 10, 9, 9, 8, + 7, 6, 5, 4, 3, 2, 2, 3, 4, 5, + 6, 8, 8, 9, 10, 11, 12, 11, 12, 14, 15, 15 +}; + +const short huffsizn_n[32] = +{ + 14, 14, 13, 12, 10, 10, 9, 9, 8, 7, + 7, 6, 5, 4, 3, 3, 3, 3, 3, 4, + 4, 5, 6, 6, 6, 7, 7, 7, 7, 8, 10, 11 +}; + +const short resize_huffnorm[32] = +{ + 0, 0, 0, 0, 0, 1023, 511, 255, 127, 63, 31, 15, 7, 3, 1, 0, + 2, 5, 11, 23, 47, 95, 191, 383, 767, 2047, 0, 0, 0, 0, 0, 0 +}; + +const short huffnorm[32] = +{ + 26, 58, 90, 122, 27, 59, 91, 123, 12, 28, 44, 60, 2, 6, 4, 6, + 0, 2, 10, 14, 14, 30, 46, 62, 30, 62, 94, 126, 31, 63, 95, 127 +}; + +const short pgain_huffnorm[32] = +{ + 1, 1, 2, 3, 3, 2, 2, 2, 3, 3, 4, 5, 6, 7, 8, 9, + 10, 11, 12, 13, 14, 15, 4, 5, 3, 2, 3, 3, 4, 5, 0, 1 +}; + +const short hessize[8]= +{ + 7, 5, 3, 2, 1, 4, 6, 7 +}; + +const short hescode[8]= +{ + 11, 3, 1, 1, 1, 0, 4, 10 +}; + +/*----------------------------------------------------------------------------------* + * BWD + *----------------------------------------------------------------------------------*/ + +const float hann_window_320[BWD_TOTAL_WIDTH/2] = +{ + 0.0f, 0.000096984948331f, 0.000387902169007f, 0.000872638803658f, + 0.001551006803657f, 0.002422743003060f, 0.003487509220708f, 0.004744892391413f, + 0.006194404726209f, 0.007835483901579f, 0.009667493277608f, 0.011689722144956f, + 0.013901386000576f, 0.016301626852047f, 0.018889513550430f, 0.021664042151495f, + 0.024624136305188f, 0.027768647673197f, 0.031096356374430f, 0.034605971458262f, + 0.038296131405342f, 0.042165404655783f, 0.046212290164521f, 0.050435217983627f, + 0.054832549871356f, 0.059402579927684f, 0.064143535256096f, 0.069053576651361f, + 0.074130799313035f, 0.079373233584409f, 0.084778845716614f, 0.090345538657597f, + 0.096071152865649f, 0.101953467147178f, 0.107990199518396f, 0.114179008090596f, + 0.120517491978659f, 0.127003192232455f, 0.133633592790768f, 0.140406121457376f, + 0.147318150898908f, 0.154366999664091f, 0.161549933223991f, 0.168864165032848f, + 0.176306857609086f, 0.183875123636085f, 0.191566027082286f, 0.199376584340196f, + 0.207303765383847f, 0.215344494944262f, 0.223495653702478f, 0.231754079499652f, + 0.240116568563785f, 0.248579876752599f, 0.257140720812064f, 0.265795779650105f, + 0.274541695624985f, 0.283375075847868f, 0.292292493499057f, 0.301290489157390f, + 0.310365572142292f, 0.319514221867944f, 0.328732889209064f, 0.338017997877748f, + 0.347365945810858f, 0.356773106567405f, 0.366235830735390f, 0.375750447347553f, + 0.385313265305494f, 0.394920574811589f, 0.404568648808175f, 0.414253744423419f, + 0.423972104423331f, 0.433719958669339f, 0.443493525580883f, 0.453289013602435f, + 0.463102622674396f, 0.472930545707291f, 0.482768970058690f, 0.492614079012283f, + 0.502462053258538f, 0.512309072376361f, 0.522151316315189f, 0.531984966876945f, + 0.541806209197260f, 0.551611233225420f, 0.561396235202429f, 0.571157419136643f, + 0.580890998276382f, 0.590593196578969f, 0.600260250175597f, 0.609888408831494f, + 0.619473937400779f, 0.629013117275481f, 0.638502247828131f, 0.647937647847382f, + 0.657315656966103f, 0.666632637081372f, 0.675884973765851f, 0.685069077669957f, + 0.694181385914321f, 0.703218363471965f, 0.712176504539683f, 0.721052333898081f, + 0.729842408259752f, 0.738543317605065f, 0.747151686505047f, 0.755664175430844f, + 0.764077482049264f, 0.772388342503876f, 0.780593532681191f, 0.788689869461429f, + 0.796674211953372f, 0.804543462712845f, 0.812294568944333f, 0.819924523685287f, + 0.827430366972643f, 0.834809186991105f, 0.842058121202763f, 0.849174357457574f, + 0.856155135084319f, 0.862997745961565f, 0.869699535568266f, 0.876257904013544f, + 0.882670307045301f, 0.888934257037231f, 0.895047323953867f, 0.901007136293294f, + 0.906811382007145f, 0.912457809397536f, 0.917944227990593f, 0.923268509386220f, + 0.928428588083795f, 0.933422462283452f, 0.938248194662667f, 0.942903913127819f, + 0.947387811540448f, 0.951698150417930f, 0.955833257608292f, 0.959791528938907f, + 0.963571428838810f, 0.967171490934417f, 0.970590318618383f, 0.973826585591401f, + 0.976879036376732f, 0.979746486807249f, 0.982427824484824f, 0.984922009211872f, + 0.987228073394887f, 0.989345122419805f, 0.991272334999066f, 0.993008963490220f, + 0.994554334185968f, 0.995907847575523f, 0.997068978577180f, 0.998037276742018f, + 0.998812366428647f, 0.999393946948934f, 0.999781792684653f, 0.999975753175008f +}; + +/*----------------------------------------------------------------------------------* + * Starting line for the noise measurement in TCX. + *----------------------------------------------------------------------------------*/ +const int startLineWB[11] = { 8, 23, 36, 45, 66, 128 /* 13.2kbps */, 200, 320, 320, 320 /* 48kbps */, 320 }; +const int startLineSWB[9] = { 8, 44, 96 /* 13.2kbps */, 160, 320, 320, 256 /* 48kbps */, 341, 640 }; diff --git a/src/libs/libevs/lib_enc/rom_enc.h b/src/libs/libevs/lib_enc/rom_enc.h new file mode 100644 index 00000000..ead5d6a5 --- /dev/null +++ b/src/libs/libevs/lib_enc/rom_enc.h @@ -0,0 +1,147 @@ +/*==================================================================================== + EVS Codec 3GPP TS26.443 Nov 13, 2018. Version 12.11.0 / 13.7.0 / 14.3.0 / 15.1.0 + ====================================================================================*/ + +#ifndef ROM_ENC_H +#define ROM_ENC_H + +#include +#include "options.h" +#include "stat_enc.h" +#include "cnst.h" + +/*----------------------------------------------------------------------------------* + * General tables + *----------------------------------------------------------------------------------*/ + +extern const float sqrt_han_window[]; /* Half of the square root hanning window */ +extern const short tipos[]; /* Starting points for pulse position search in Algebraic innovation codebook */ +extern const Float32 E_ROM_inter4_1[PIT_UP_SAMP * L_INTERPOL1 + 1]; +extern const Float32 E_ROM_inter6_1[PIT_UP_SAMP6 * L_INTERPOL1 + 1]; +extern const Float32 E_ROM_inter4_1[PIT_UP_SAMP * L_INTERPOL1 + 1]; +extern const Float32 E_ROM_inter6_1[PIT_UP_SAMP6 * L_INTERPOL1 + 1]; +extern const float W_HIST[DTX_HIST_SIZE]; /* CNG & DTX - table for calculation of average excitation energy */ + +extern const short bwd_start_bin[]; +extern const short bwd_end_bin[]; + +extern const float h_fir[]; /* 2nd order fir filter for wsp, decimation by 2 */ + +extern const float preemphCompensation[]; + +/*----------------------------------------------------------------------------------* + * VAD tables + *----------------------------------------------------------------------------------*/ +extern const short hangover_hd_tbl[3]; +extern const short hangover_sf_tbl[6]; +/*----------------------------------------------------------------------------------* + * Open-loop pitch search tables + *----------------------------------------------------------------------------------*/ + +extern const short nb_sect_12k8[]; +extern const short nb_subsect_12k8[]; +extern const short len_12k8[]; +extern const short len1_12k8[]; +extern const short sublen_12k8[]; +extern const short sublen1_12k8[]; +extern const short pit_max_12k8[]; +extern const short sec_length_12k8[]; +extern const short sec_length1_12k8[]; + +/*----------------------------------------------------------------------------------* + * LSF quantizer + *----------------------------------------------------------------------------------*/ + +extern const int lsf_numlevels[TCXLPC_NUMSTAGES]; +extern const int lsf_ind_numlevels[TCXLPC_IND_NUMSTAGES]; + +extern const short lsf_unified_fit_model_nb[4][16]; +extern const short lsf_unified_fit_model_wb[4][16]; +extern const short lsf_unified_fit_model_wbhb[4][16]; + +extern const float Freq_Weight_Com[160]; +extern const float Freq_Weight_UV[160]; + +/*----------------------------------------------------------------------------------* + * Speech/music classification + *----------------------------------------------------------------------------------*/ + +extern const float w_spmus[HANG_LEN][HANG_LEN]; + +extern const float m_speech[]; +extern const float invV_speech[]; +extern const float lvm_speech[]; + +extern const float m_music[]; +extern const float invV_music[]; +extern const float lvm_music[]; + +extern const float m_noise[]; +extern const float invV_noise[]; +extern const float lvm_noise[]; + +extern const float SF[]; +extern const float SF_8k[]; + +/*----------------------------------------------------------------------------------* + * SWB TBE + *----------------------------------------------------------------------------------*/ + +extern const float lpc_weights[]; + +/*----------------------------------------------------------------------------------* + * WB, SWB and FB bandwidth detector + *----------------------------------------------------------------------------------*/ + +extern const float hann_window_320[]; + +/*----------------------------------------------------------------------------------* + * Huffman coding + *----------------------------------------------------------------------------------*/ + +extern const short huffsizn_e[32]; +extern const short huffsizn_n[32]; + +extern const short huffnorm_e[32]; +extern const short huffnorm_n[32]; +extern const short hessize[8]; +extern const short hescode[8]; + +/*----------------------------------------------------------------------------------* + * VAD + *----------------------------------------------------------------------------------*/ + +extern const short BAND_NUM_TAB[5]; + +extern const float M_inr[16]; +extern const float M_ini[16]; +extern const float M_r[8]; +extern const float M_i[8]; +extern const float M_Wr[16]; +extern const float M_Wi[16]; + +extern const short SP_CENTER_BAND_NUM_TAB[5]; +extern const float DELTA1[5]; +extern const float DELTA2[5]; + +extern const int NREGION_INDEX_NB[9]; +extern const int NREGION_INDEX_WB[13]; +extern const int NREGION_INDEX_SWB[16]; +extern const int NREGION_INDEX_FB[16]; +extern const int ENERGY_BAND_NUM[4]; +extern const int *const REGION_INDEX[4]; +extern const float MAX_LF_SNR_TAB[4]; + +extern const float COMVAD_INIT_SNR_DELTA[5]; +extern const float LS_MIN_SELENCE_SNR[3]; +extern const float LT_MIN_SILENCE_SNR[3]; + +/*----------------------------------------------------------------------------------* + * Starting line for the noise measurement in TCX. + *----------------------------------------------------------------------------------*/ +extern const int startLineWB[11]; +extern const int startLineSWB[9]; + + +#endif + diff --git a/src/libs/libevs/lib_enc/rom_enc_fx.cpp b/src/libs/libevs/lib_enc/rom_enc_fx.cpp deleted file mode 100755 index a7a2bead..00000000 --- a/src/libs/libevs/lib_enc/rom_enc_fx.cpp +++ /dev/null @@ -1,696 +0,0 @@ -/*==================================================================================== - EVS Codec 3GPP TS26.442 Apr 03, 2018. Version 12.11.0 / 13.6.0 / 14.2.0 - ====================================================================================*/ - -#include "options.h" /* Compilation switches */ -#include "stl.h" -#include "cnst_fx.h" /* Common constants */ -#include "rom_enc_fx.h" -#include "basop_util.h" - -/*----------------------------------------------------------------------------------* - * VAD tables - *----------------------------------------------------------------------------------*/ -const Word16 hangover_hd_tbl_fx[3] = {1, 1, 3}; -const Word16 hangover_sf_tbl_fx[6] = {1, 3, 4, 1, 1, 2}; - -const Word16 H_fir[] = { 4260, 7536, 9175, 7536, 4260 }; -const Word16 pit_max_12k8_fx[9] = { 11, 16, 21, 31, 40, 61, 77, 115, 115 }; - -const Word16 len_12k8_fx[4] = { 40, 40, 62, 115 } ; -const Word16 len1_12k8_fx[4] = { 40, 50, 80, 115 }; -const Word16 sublen_12k8_fx[7] = { 40, 40, 40, 62, 62, 115, 115 }; -const Word16 sublen1_12k8_fx[7] = { 40, 40, 50, 50, 80, 80, 115 } ; - -const Word16 sec_length_12k8_fx[4] = { 7, 15, 30, 54 }; -const Word16 sec_length1_12k8_fx[4] = { 10, 19, 37, 38 }; -const Word16 SF_mult_fx[N_FEATURES] = -{ - 20133, /*Q22*/ - 32767, /*Q15*/ - 20401, /*Q15*/ - 18013, /*Q15*/ - 16263, /*Q15*/ - 16545, /*Q15*/ - 16610, /*Q15*/ - 17197, /*Q22*/ - 18455, /*Q23*/ - 16515, /*Q18*/ - 17931, /*Q18*/ - 30382 /*Q18*/ -}; - -const Word32 SF_add_fx[N_FEATURES] = -{ - -798595, /*Q23*/ - 0, /*Q31*/ - -37312528, /*Q29*/ - -67914170, /*Q29*/ - -119722213, /*Q29*/ - -220278135, /*Q29*/ - -306929100, /*Q29*/ - 0, /*Q30*/ - -6227703, /*Q31*/ - 537676218, /*Q29*/ - 488713591, /*Q29*/ - -314713729 /*Q30*/ -}; - -const Word16 SF_8k_mult_fx[N_FEATURES] = -{ - 17197, /*Q22*/ - 28088, /*Q15*/ - 22082, /*Q15*/ - 20503, /*Q15*/ - 18006, /*Q15*/ - 18983, /*Q15*/ - 8199 , /*Q15*/ - 17197, /*Q22*/ - 16777, /*Q23*/ - 16515, /*Q18*/ - 15676, /*Q18*/ - 16541 /*Q18*/ -}; - -const Word32 SF_8k_add_fx[N_FEATURES] = -{ - 0, /*Q23*/ - 219043332, /*Q31*/ - -53687091, /*Q29*/ - -90086939, /*Q29*/ - -127775277, /*Q29*/ - -249430226, /*Q29*/ - 0, /*Q29*/ - 0, /*Q30*/ - 0, /*Q31*/ - 537676218, /*Q29*/ - 481412147, /*Q29*/ - 0 /*Q30*/ -}; - -const Word16 w_spmus_fx[HANG_LEN][HANG_LEN] = -{ - /*Q15*/ - {32767, 0, 0, 0, 0, 0, 0, 0,}, - {19661, 13107, 0, 0, 0, 0, 0, 0,}, - {15401, 10813, 6554, 0, 0, 0, 0, 0,}, - {13107, 9830, 6554, 3277, 0, 0, 0, 0,}, - { 9830, 8192, 6554, 4915, 3277, 0, 0, 0,}, - { 7635, 6783, 5898, 5014, 4162, 3277, 0, 0,}, - { 7700, 6717, 5702, 4686, 3670, 2654, 1638, 0,}, - { 6554, 5865, 5145, 4456, 3736, 3047, 2327, 1638} -}; -const Word16 m_speech_fx[N_MIXTURES*N_FEATURES] = -{ - /*Q15*/ - 9436, 29987, 4795, 7076, 11050, 13645, 15206, 15194, 1936, 27952, 25172, 10301, - 10057, 30685, 8381, 9965, 10762, 8680, 11589, 15788, 1641, 26751, 27163, 10992, - 7927, 31230, 7191, 8505, 14304, 16336, 14972, 16077, 2052, 27271, 27694, 10859, - 13914, 17323, 10682, 16458, 17807, 18403, 19368, 12665, 2205, 29598, 29213, 11285, - 12468, 23848, 6880, 10301, 13824, 13066, 14647, 13189, 3451, 28442, 28766, 10410, - 11304, 21566, 7894, 11411, 14194, 15739, 16351, 13744, 6130, 28445, 28034, 11380 -}; -const Word32 invV_speech_fx[N_MIXTURES*N_FEATURES*N_FEATURES] = -{ - /*Q10*/ - -40443, -14756, -39560, -18113, 8983, -11676, 450, -10588, -49908, 358, 17222, 32914, - -14756, -200610, -27679, -28092, -16846, -6393, 5954, 13058, -67051, -47861, -8575, 18740, - -39560, -27679, -772035, 118158, -48299, 27758, -37782, 74336, -305470, -23323, 181510, 91957, - -18113, -28092, 118158, -228070, 41104, -46248, 21977, 8161, -27789, 78357, 26088, 39736, - 8983, -16846, -48299, 41104, -96670, 41164, -18208, 3995, -14774, 23704, 13802, 17925, - -11676, -6393, 27758, -46248, 41164, -95654, 58562, 3668, 103, 5952, 9479, 11083, - 450, 5954, -37782, 21977, -18208, 58562, -91964, -5597, -47161, -15941, 14870, 11028, - -10588, 13058, 74336, 8161, 3995, 3668, -5597, -102767, 25363, -21490, -48411, 13509, - -49908, -67051, -305470, -27789, -14774, 103, -47161, 25363, -1410848, -57997, 238792, -117641, - 358, -47861, -23323, 78357, 23704, 5952, -15941, -21490, -57997, -221932, -936, 40579, - 17222, -8575, 181510, 26088, 13802, 9479, 14870, -48411, 238792, -936, -157118, -49202, - 32914, 18740, 91957, 39736, 17925, 11083, 11028, 13509, -117641, 40579, -49202, -321159, - -54755, -48603, -918, -25735, 31634, -27972, 23305, -18449, -68162, -3670, -7982, 35965, - -48603, -449238, -11496, -14811, 12790, -11453, 2686, -3752, -86924, -30083, -54695, 17457, - -918, -11496, -258042, 157642, 4617, 27546, -22677, 7281, -221085, -48457, 80126, 16406, - -25735, -14811, 157642, -334462, 64217, 7724, 24309, 20322, -99420, 2896, 76924, 35785, - 31634, 12790, 4617, 64217, -296101, 182629, -27282, 11581, -10495, 16901, 50011, 20823, - -27972, -11453, 27546, 7724, 182629, -274190, 15505, 4345, -7824, 79496, -2218, 12832, - 23305, 2686, -22677, 24309, -27282, 15505, -73195, 2055, -4690, 31413, 15447, 8774, - -18449, -3752, 7281, 20322, 11581, 4345, 2055, -77913, 57514, -8586, -106171, 6233, - -68162, -86924, -221085, -99420, -10495, -7824, -4690, 57514, -1966183, -9074, 512909, -17375, - -3670, -30083, -48457, 2896, 16901, 79496, 31413, -8586, -9074, -185355, -15990, 8445, - -7982, -54695, 80126, 76924, 50011, -2218, 15447, -106171, 512909, -15990, -444405, -71821, - 35965, 17457, 16406, 35785, 20823, 12832, 8774, 6233, -17375, 8445, -71821, -222292, - -96397, -65745, 316, -47258, 43061, -42973, 10442, -19582, -43973, -19682, -21732, 48029, - -65745, -838575, 30816, -43250, 6642, -4487, 11239, 338, -17329, -59741, -114530, -1706, - 316, 30816, -351192, 207585, -68100, 60838, -83672, 14796, -158998, 13313, 122647, 38113, - -47258, -43250, 207585, -322741, 76525, -99711, 59838, 20166, -63534, 7136, 76247, 22923, - 43061, 6642, -68100, 76525, -96244, 54110, -21689, 2401, -36455, -19725, 38782, 6802, - -42973, -4487, 60838, -99711, 54110, -284964, 220150, -642, -44874, -21815, 16040, 3963, - 10442, 11239, -83672, 59838, -21689, 220150, -239817, 2018, -17214, -1904, 16387, 4095, - -19582, 338, 14796, 20166, 2401, -642, 2018, -58537, 20742, -9245, -85094, 8867, - -43973, -17329, -158998, -63534, -36455, -44874, -17214, 20742, -1009892, 28181, 407531, -10963, - -19682, -59741, 13313, 7136, -19725, -21815, -1904, -9245, 28181, -186118, -32487, 5665, - -21732, -114530, 122647, 76248, 38782, 16040, 16387, -85094, 407531, -32487, -511009, -66277, - 48029, -1706, 38113, 22923, 6802, 3963, 4095, 8867, -10963, 5665, -66277, -251113, - -21146, 1393, -2365, 3756, -4538, -1528, 2298, -6668, -7599, -2720, -5226, 3049, - 1393, -46612, -28502, 11801, -5967, 8395, -4182, 13773, 18586, -9799, -6696, -3522, - -2365, -28502, -77446, 55688, -10615, 10476, -6282, 5520, -19365, 8818, -4576, 2603, - 3756, 11801, 55688, -152293, 104577, -8742, 15278, -2773, 16622, -12382, -2828, 5452, - -4538, -5967, -10615, 104577, -245151, 117173, -5020, 3412, -2855, -19929, 9729, 1888, - -1528, 8395, 10476, -8742, 117173, -258943, 136249, -2960, -8257, -20123, -6735, -6316, - 2298, -4182, -6282, 15278, -5020, 136249, -192889, 889, -6047, -74906, 15861, 4026, - -6668, 13773, 5520, -2773, 3412, -2960, 889, -298321, 8558, 5827, -66886, -3080, - -7599, 18586, -19365, 16622, -2855, -8257, -6047, 8558, -837495, -36576, 477123, -58582, - -2720, -9799, 8818, -12382, -19929, -20123, -74906, 5827, -36576, -279826, 29479, 36566, - -5226, -6696, -4576, -2828, 9729, -6735, 15861, -66886, 477123, 29479, -1017755, -75828, - 3049, -3522, 2603, 5452, 1888, -6316, 4026, -3080, -58582, 36566, -75828, -193453, - -30403, -6761, -6085, -8388, 12841, -17600, 8289, -11817, -4054, -3000, -13322, 14944, - -6761, -28452, -12326, -8945, 10515, -8369, -520, 2242, -3287, -20124, 179, 12354, - -6085, -12326, -180408, 89468, -19908, 3017, -41552, 4204, -31158, -23783, 87004, 44784, - -8388, -8945, 89468, -146434, 53166, -28645, 29987, -2506, -12242, 28411, 11874, 403, - 12841, 10515, -19908, 53166, -182342, 131104, -3630, 7016, -11031, -43497, 35570, 41136, - -17600, -8369, 3017, -28645, 131104, -169537, 52490, -4955, 3848, 41489, -7925, -19614, - 8289, -520, -41552, 29987, -3630, 52490, -111006, -916, 3418, 2295, 3395, 1491, - -11817, 2242, 4204, -2506, 7016, -4955, -916, -219477, -4965, -3871, -77054, -1199, - -4054, -3287, -31158, -12242, -11031, 3848, 3418, -4965, -272588, 2948, 184352, -45153, - -3000, -20124, -23783, 28411, -43497, 41489, 2295, -3871, 2948, -160538, -11875, 4491, - -13322, 179, 87004, 11874, 35570, -7925, 3395, -77054, 184352, -11875, -501251, -59166, - 14944, 12354, 44784, 403, 41136, -19614, 1491, -1199, -45153, 4491, -59166, -256669, - -24496, -5820, -2150, 131, 5291, -10279, 6605, -749, -2301, -4257, 6742, 4179, - -5820, -30866, -8866, -12879, -1341, 2042, -4488, 6991, -847, -21654, 3707, 11359, - -2150, -8866, -123923, 90609, -28405, 24864, -28222, 3814, 6439, -12821, 2736, 12974, - 131, -12879, 90609, -147490, 86712, -38319, 26159, 1048, -7654, 17099, 8973, 1271, - 5291, -1341, -28405, 86712, -147877, 74296, -14561, 2055, 18062, 1238, -4181, 14726, - -10279, 2042, 24864, -38319, 74296, -168459, 117891, -874, -17255, 675, 13174, -13101, - 6605, -4488, -28222, 26159, -14561, 117891, -147764, -13296, 2771, -4243, -4809, 1608, - -749, 6991, 3814, 1048, 2055, -874, -13296, -77582, -32335, -4868, 9778, -6784, - -2301, -847, 6439, -7654, 18062, -17255, 2771, -32335, -69840, 11490, 21385, -23633, - -4257, -21654, -12821, 17099, 1238, 675, -4243, -4868, 11490, -151841, -2520, 12898, - 6742, 3707, 2736, 8973, -4181, 13174, -4809, 9778, 21385, -2520, -60529, -3814, - 4179, 11359, 12974, 1271, 14726, -13101, 1608, -6784, -23633, 12898, -3814, -63927 -}; -const Word32 lvm_speech_fx[N_MIXTURES] = -{ - /*Q10*/ - 32765, 33549, 33755, 32747, 31627, 26814 -}; -const Word16 m_music_fx[N_MIXTURES*N_FEATURES] = -{ - /*Q15*/ - 14804, 25446, 8882, 11624, 12963, 13563, 14794, 20567, 1033, 27373, 23772, 11713, - 15975, 20612, 7737, 12728, 14424, 15237, 16190, 15239, 2277, 30096, 28120, 11522, - 17631, 19827, 9280, 14111, 15555, 16289, 17009, 17271, 1132, 31186, 27733, 12469, - 15863, 24390, 7804, 11176, 11734, 11986, 12857, 23015, 713, 28823, 23782, 13779, - 10022, 22691, 12397, 15249, 15957, 16382, 17058, 15509, 4107, 23807, 22701, 12269, - 16842, 22819, 8062, 11248, 12283, 12978, 13722, 21178, 867, 30480, 25501, 12111 -}; -const Word32 invV_music_fx[N_MIXTURES*N_FEATURES*N_FEATURES] = -{ - /*Q10*/ - -7878, -673, -2037, -885, -236, -667, 749, -1726, -20424, -859, 2463, 4011, - -673, -31356, -1591, -3048, -1872, 1277, -3806, 8836, 5555, -2031, -11076, -7329, - -2037, -1591, -65556, 42935, -11408, 12166, 751, 8792, 24077, -15804, -2546, -2517, - -885, -3048, 42935, -88483, 42957, -13081, 4776, 14411, 23734, -5735, 15306, 15210, - -236, -1872, -11408, 42957, -90738, 37950, -1795, 4021, -35266, 12445, 13655, 17403, - -667, 1277, 12166, -13081, 37950, -86289, 37943, 3429, -5655, 5664, 8658, -11, - 749, -3806, 751, 4776, -1795, 37943, -77863, -8515, -74265, 22313, 3842, 645, - -1726, 8836, 8792, 14411, 4021, 3429, -8515, -59311, -121235, 1622, -8500, 4967, - -20424, 5555, 24077, 23734, -35266, -5655, -74265, -121235, -5534279, 175865, 247781, -296138, - -859, -2031, -15804, -5735, 12445, 5664, 22313, 1622, 175865, -104343, -1168, 32220, - 2463, -11076, -2546, 15306, 13655, 8658, 3842, -8500, 247781, -1168, -79522, -45571, - 4011, -7329, -2517, 15210, 17403, -11, 645, 4967, -296138, 32220, -45571, -249005, - -10115, 613, -4406, -403, 731, 898, 350, -1995, -8975, -169, -1296, 1233, - 613, -30663, -12425, -1115, -1862, 2906, -2485, 12887, -8842, -12067, 4833, 3070, - -4406, -12425, -86550, 49625, -11519, 15386, -20054, 20873, -13684, 28341, 23152, -807, - -403, -1115, 49625, -131210, 81002, 1045, 3085, 8149, -11887, -3094, 43855, 14533, - 731, -1862, -11519, 81002, -226160, 115669, 9052, -6427, -19605, -20406, 7481, 6064, - 898, 2906, 15386, 1045, 115669, -281745, 150559, -5530, 271, -5717, 1673, 7674, - 350, -2485, -20054, 3085, 9052, 150559, -200735, -21872, -9366, 10471, -2190, 3083, - -1995, 12887, 20873, 8149, -6427, -5530, -21872, -111299, -29613, -27611, -54741, -9432, - -8975, -8842, -13684, -11887, -19605, 271, -9366, -29613, -616730, 74872, 189453, -79618, - -169, -12067, 28341, -3094, -20406, -5717, 10471, -27611, 74872, -359342, -12919, 29609, - -1296, 4833, 23152, 43855, 7481, 1673, -2190, -54741, 189453, -12919, -407670, -16961, - 1233, 3070, -807, 14533, 6064, 7674, 3083, -9432, -79618, 29609, -16961, -180700, - -12411, 5539, -1902, 92, 2813, 339, -114, -1078, -24097, -2938, -1812, 399, - 5539, -36224, -7229, -766, -2442, 2066, -2896, 8507, 16429, -11423, -12067, -191, - -1902, -7230, -115426, 44336, 11635, 13946, -3573, 22728, -73099, 119214, 70165, 4686, - 92, -766, 44336, -187908, 81624, 24838, 12765, 1471, -43322, -24066, 44669, 3543, - 2813, -2442, 11635, 81624, -295220, 104190, 52986, -3246, -146322, -78690, 34365, -2814, - 339, 2066, 13946, 24838, 104190, -347659, 169287, -4458, -127093, -94499, 42989, 5700, - -114, -2896, -3573, 12765, 52986, 169287, -310084, -18605, -27182, -19113, -2714, 11, - -1078, 8507, 22728, 1471, -3246, -4458, -18605, -69283, 40578, -47905, -135760, -6645, - -24097, 16429, -73099, -43322, -146322, -127093, -27182, 40578, -8241631, -71531, 1853193, -175523, - -2938, -11423, 119214, -24066, -78690, -94499, -19113, -47905, -71531, -1361618, -36609, 26675, - -1812, -12067, 70165, 44669, 34365, 42989, -2714, -135760, 1853193, -36609, -1337597, -83909, - 399, -191, 4686, 3543, -2814, 5700, 11, -6645, -175523, 26675, -83909, -223653, - -8809, 3326, -1275, -1509, 1423, 1222, -767, -3923, -65513, -5992, 9965, 3853, - 3326, -31906, -1905, 4114, -4704, 1138, -584, 10709, 104184, 6118, -30358, -5240, - -1275, -1905, -184413, 67973, -17415, 32246, -7121, 16051, -2994, -52989, 23547, 27770, - -1509, 4114, 67973, -160389, 86351, -8947, 13772, 8224, 3480, 2626, 24337, 1870, - 1423, -4704, -17415, 86351, -198772, 68001, 7361, 14025, 11152, 23137, 12598, 9972, - 1222, 1138, 32246, -8947, 68001, -166130, 57911, 17629, 118765, 39472, 1806, 7267, - -767, -584, -7121, 13772, 7361, 57911, -123203, 2059, 47920, 59494, 10484, -5066, - -3923, 10709, 16051, 8224, 14025, 17629, 2059, -90332, -367027, -30259, -20438, -3054, - -65513, 104184, -2994, 3480, 11152, 118765, 47920, -367027, -16854832, -181537, 903929, -95027, - -5992, 6118, -52989, 2626, 23137, 39472, 59494, -30259, -181537, -320917, -11497, 56536, - 9965, -30358, 23547, 24337, 12598, 1806, 10484, -20438, 903929, -11497, -197437, -16106, - 3853, -5240, 27770, 1870, 9972, 7267, -5066, -3054, -95027, 56536, -16106, -107942, - -14599, -2426, -4488, 2252, 20, -696, -2636, 5531, 1097, 109, 1359, 2742, - -2426, -22977, 1326, -4413, -6555, 199, -2249, 16239, 6914, -6267, 1335, -319, - -4488, 1326, -38846, 40605, -16372, -138, 6341, 2358, -5859, 1498, -1344, -3917, - 2252, -4413, 40605, -94592, 69176, -3799, -16812, -5416, -11189, -3107, 2060, -3508, - 20, -6555, -16372, 69176, -121278, 55283, 86, 3716, 11782, -9657, 3416, 549, - -696, 199, -138, -3799, 55283, -105539, 62225, 5299, 3619, 1933, -2511, 609, - -2636, -2249, 6341, -16812, 86, 62225, -79693, -7236, -9729, -2907, 2795, 57, - 5531, 16239, 2358, -5416, 3716, 5299, -7236, -52597, -40766, -5195, 2995, 11158, - 1097, 6914, -5859, -11189, 11782, 3619, -9729, -40766, -95884, 18462, 2795, -18509, - 109, -6267, 1498, -3107, -9657, 1933, -2907, -5195, 18462, -29138, 3027, 17268, - 1359, 1335, -1344, 2060, 3416, -2511, 2795, 2995, 2795, 3027, -10878, -6828, - 2742, -319, -3917, -3508, 549, 609, 57, 11158, -18509, 17268, -6828, -48324, - -9462, 2969, -1087, -1924, 1418, -350, 396, -3124, -35326, 682, 3248, 5848, - 2969, -29148, -2662, 2400, -3059, 2772, 847, 8375, 60040, -6778, -23223, -7694, - -1087, -2662, -172602, 83798, 2597, 33012, 3851, 12397, 81998, -81017, 15831, 35467, - -1924, 2400, 83798, -204141, 66003, 2928, 18028, 14706, 8557, 16030, 44283, 36177, - 1418, -3059, 2597, 66003, -202589, 47215, 19493, 10544, -4664, 46480, 10895, 18165, - -350, 2772, 33012, 2928, 47215, -198011, 76335, 14223, 123301, 70945, 1870, 8265, - 396, 847, 3851, 18028, 19493, 76335, -177594, -5345, 78880, 114804, -171, 3539, - -3124, 8375, 12397, 14706, 10544, 14223, -5345, -67596, -251454, -55035, -21890, 7263, - -35326, 60040, 81998, 8557, -4664, 123301, 78880, -251454, -12784658, -217014, 810245, -725111, - 682, -6778, -81017, 16030, 46480, 70945, 114804, -55035, -217014, -793758, -8106, 74886, - 3248, -23223, 15831, 44283, 10895, 1870, -171, -21890, 810245, -8106, -319630, -77833, - 5848, -7694, 35467, 36177, 18165, 8265, 3539, 7263, -725111, 74886, -77832, -481222 -}; -const Word32 lvm_music_fx[N_MIXTURES] = -{ - /*Q10*/ - 28603, 31076, 35357, 31989, 20938, 34395 -}; -const Word16 m_noise_fx[N_MIXTURES*N_FEATURES] = -{ - /*Q15*/ - 14825, 18681, 7930, 11230, 13228, 13602, 14556, 14377, 1133, 29263, 26842, 13270, - 14312, 14992, 9378, 12891, 14075, 14581, 15548, 12386, 1050, 32143, 28322, 12379, - 18179, 16617, 8015, 13153, 13932, 14462, 15329, 11848, 1033, 31841, 28406, 12222, - 15822, 17883, 3231, 8086, 9983, 9933, 11537, 11904, 1018, 29549, 27473, 11111, - 13821, 16109, 8734, 12035, 13351, 13603, 15024, 12957, 1163, 31179, 28243, 11865, - 13845, 15577, 10545, 14292, 15353, 15784, 16567, 12750, 1589, 31695, 28796, 13420 -}; -const Word32 invV_noise_fx[N_MIXTURES*N_FEATURES*N_FEATURES] = -{ - /*Q10*/ - -11129, -775, -807, 4750, -4310, -1632, 1694, 530, -25134, -2399, 1632, 1938, - -775, -43700, -5296, -23144, -4086, -2008, 9445, 12956, 17119, 10623, -18169, -14373, - -807, -5296, -117924, 78859, -23526, 22681, -7637, 52382, 20661, -1131, 18004, -18669, - 4750, -23144, 78859, -165973, 70704, -954, 10160, 6713, 50481, 19307, -10190, 16924, - -4310, -4086, -23526, 70704, -186160, 114906, -28994, 9999, 17677, -18372, -20805, -12577, - -1632, -2008, 22681, -954, 114906, -235840, 123708, -3753, 21616, 9200, 15641, -10616, - 1694, 9445, -7637, 10160, -28994, 123708, -156081, -1564, -7627, 5159, 14184, -12573, - 530, 12956, 52382, 6713, 9999, -3753, -1564, -116541, -130257, -2892, -51260, -1433, - -25134, 17119, 20661, 50481, 17677, 21616, -7627, -130257, -6857531, -23164, 425725, -172307, - -2399, 10623, -1131, 19307, -18372, 9200, 5159, -2892, -23164, -157605, 9307, 20639, - 1632, -18169, 18004, -10190, -20805, 15641, 14184, -51260, 425725, 9307, -184817, -2232, - 1938, -14373, -18669, 16924, -12577, -10616, -12573, -1433, -172307, 20639, -2232, -94498, - -23585, -1283, 2220, 5814, -1063, -5524, 5040, -408, -7744, 65700, -4948, 1221, - -1283, -102238, 18435, -18156, -6216, 17104, -1870, 25097, 97427, 32242, -77595, -4567, - 2220, 18435, -305438, 139861, 24123, 32851, -45614, 45538, 124040, 301172, -22649, 3625, - 5814, -18156, 139861, -565373, 242575, 46852, 50718, -18774, -159188, 141029, 89911, 9768, - -1063, -6216, 24123, 242575, -798475, 256535, 104095, 9375, -84525, -408528, 98204, 4495, - -5524, 17104, 32851, 46852, 256535, -845586, 312678, -6990, 50242, -543393, -42629, 99, - 5040, -1870, -45614, 50718, 104095, 312678, -732093, 14409, 83177, -140864, -2169, -2321, - -408, 25097, 45538, -18774, 9375, -6990, 14409, -314037, 273543, -30059, -253352, -3462, - -7744, 97427, 124040, -159188, -84525, 50242, 83177, 273543, -19301626, -952154, 3668367, -93870, - 65700, 32242, 301172, 141029, -408528, -543393, -140864, -30059, -952154, -16033274, -164405, -24189, - -4948, -77595, -22649, 89911, 98204, -42629, -2169, -253352, 3668367, -164405, -2501887, -105127, - 1221, -4567, 3625, 9768, 4495, 99, -2321, -3462, -93870, -24189, -105127, -252171, - -11556, 5444, 1053, 1823, -1754, -6509, 3535, -483, 5751, 22898, -4369, 2503, - 5444, -61418, -46603, 523, -4221, 5377, -14703, 2336, 4414, 4601, 17795, 5358, - 1053, -46603, -197022, 61944, 30015, 11139, -14163, 4583, 14704, 174734, 105587, 3797, - 1823, 523, 61944, -579713, 310766, -24876, -8601, -1522, -38055, -308764, 10254, 11526, - -1754, -4221, 30015, 310766, -873205, 294102, 7806, 2338, -28081, -507955, -5526, -1671, - -6509, 5377, 11139, -24876, 294102, -740664, 309186, -19342, -50840, -143800, 27527, 4324, - 3535, -14703, -14163, -8601, 7806, 309186, -508227, 24986, 208442, -230010, -48336, -9651, - -483, 2336, 4583, -1522, 2338, -19342, 24986, -362502, 140055, -118693, -134546, 982, - 5751, 4414, 14704, -38055, -28081, -50840, 208442, 140055, -20820834, -328791, 3081671, -99923, - 22898, 4601, 174734, -308764, -507955, -143800, -230010, -118693, -328791, -7236926, -225976, -47887, - -4369, 17795, 105587, 10254, -5526, 27527, -48336, -134546, 3081671, -225976, -2500626, -124929, - 2503, 5358, 3797, 11526, -1671, 4324, -9651, 982, -99923, -47887, -124929, -277469, - -14533, 3263, -8141, 13301, 5586, 1808, -5289, 472, 7371, -21379, -2460, 596, - 3263, -46002, -56596, 9198, -765, 13994, 5247, 2629, -14758, -21574, 5644, 3817, - -8141, -56596, -895669, 406276, -247505, 72418, -246462, 32532, -190899, -74267, 59747, 10271, - 13301, 9198, 406276, -551172, 137309, 34772, -5367, 41269, 67372, 262339, 42457, 60892, - 5586, -765, -247505, 137309, -964866, 393695, 36960, 5148, 114354, 66434, -19640, 18501, - 1808, 13994, 72418, 34772, 393695, -906317, 366933, 14058, 76374, 284422, 16253, 32973, - -5289, 5247, -246462, -5367, 36960, 366933, -711303, 23465, 84856, 157990, 2319, 21580, - 472, 2629, 32532, 41269, 5148, 14058, 23465, -349612, -74011, -89655, -17686, 7616, - 7371, -14758, -190899, 67372, 114354, 76374, 84856, -74011, -17027780, -264311, 396822, -266476, - -21379, -21574, -74267, 262339, 66434, 284422, 157990, -89655, -264311, -871539, 3553, 2308, - -2460, 5644, 59747, 42457, -19640, 16253, 2319, -17686, 396822, 3553, -334956, -46272, - 596, 3817, 10271, 60892, 18501, 32973, 21580, 7616, -266476, 2308, -46272, -357254, - -21040, -1263, -6696, 8169, -1272, -4427, 4142, -8459, -63196, -17218, 710, 2270, - -1263, -83196, -34319, -27267, 2213, -240, -783, 22287, 136898, 9589, -27942, -6781, - -6696, -34319, -329281, 107754, 677, -33332, -46218, 43055, -204958, -43031, 204918, 20438, - 8169, -27267, 107754, -371373, 103141, 10674, 46337, -3299, -65216, -42038, -5280, 13005, - -1272, 2213, 677, 103141, -420124, 194457, 1575, 22157, -26994, 36729, 47504, 13852, - -4427, -240, -33332, 10674, 194457, -368592, 152851, 14172, 107043, 44274, -23917, -8922, - 4142, -783, -46218, 46337, 1575, 152851, -280668, -8210, 40158, 24389, 13385, 8410, - -8459, 22287, 43055, -3299, 22157, 14172, -8210, -256064, 79772, -1255, -101174, 759, - -63196, 136898, -204958, -65216, -26994, 107043, 40158, 79772, -13100212, 263557, 2000831, -242675, - -17218, 9589, -43031, -42038, 36729, 44274, 24389, -1255, 263557, -1223057, -216580, -23199, - 710, -27942, 204918, -5280, 47504, -23917, 13385, -101174, 2000831, -216580, -1303910, -90175, - 2270, -6781, 20438, 13005, 13852, -8922, 8410, 759, -242675, -23199, -90175, -372746, - -24335, -321, -1426, 1524, 1959, -4164, 7012, -3148, -7859, 9391, 3193, 2194, - -321, -90890, -9068, -27277, 5303, 10922, 2298, 22512, 17201, 4798, 13388, -2773, - -1426, -9068, -180137, 85478, 42242, 14714, -12908, 34197, 67246, 40663, 36965, -9792, - 1524, -27277, 85478, -392290, 221884, 12492, 33161, -14359, 7950, -103145, -29210, -5361, - 1959, 5303, 42242, 221884, -600963, 259592, 30301, 7895, -32577, -115360, 20766, -7273, - -4164, 10922, 14714, 12492, 259592, -611459, 304095, 6323, -42968, -37072, -21092, -15235, - 7012, 2298, -12908, 33161, 30301, 304095, -467758, 26953, -35709, 29107, 35819, -8754, - -3148, 22512, 34197, -14359, 7895, 6323, 26953, -271919, 2988, 852, -128460, -11407, - -7859, 17201, 67246, 7950, -32577, -42968, -35709, 2988, -1773460, -215853, 756954, -99883, - 9391, 4798, 40663, -103145, -115360, -37072, 29107, 852, -215853, -2382074, -108833, 1061, - 3193, 13388, 36965, -29210, 20766, -21092, 35819, -128460, 756954, -108833, -1923617, -116204, - 2194, -2773, -9792, -5361, -7273, -15235, -8754, -11407, -99883, 1061, -116204, -103840 -}; -const Word32 lvm_noise_fx[N_MIXTURES] = -{ - /*Q10*/ - 29413, 42169, 40240, 39433, 37918, 36348 -}; -/* Inv possible delta used in gaus_enc (1.0/(1.0+delta*delta)) and delta = [1,7] */ -const Word16 inv_delta_tab[7] = /*Q15*/ -{ - 32640, - 32264, - 31655, - 30840, - 29855, - 28728, - 27504 -}; - -const Word16 lsf_unified_fit_model_nb[4][16] = -{ - {12506 , -17641 , -6444 , -6646 , -3523 , -2132 , -511 , -92 , 699 , 1062 , 2578 , 3564 , 3200 , -285 , 2928 , -250}, - {20383 , 18855 , 8494 , 8062 , 8105 , 6211 , 5068 , 4408 , 3741 , 3458 , 2732 , 3174 , 2412 , 17421 , -21717 , 0}, - {-717 , -617 , -144 , -117 , -229 , -144 , -141 , -98 , -92 , -69 , -51 , -87 , -37 , -3019 , 19864 , 8034}, - {-2424 , 8999 , 5723 , 5629 , 4239 , 3423 , 2507 , 2019 , 1245 , 736 , -907 , -2237 , -2558 , -1979 , -652 , 1657} -}; - -const Word16 lsf_unified_fit_model_wb[4][16] = -{ - {8323 , -567 , 3402 , 1389 , 1437 , 1820 , 1407 , 1299 , 1292 , 1206 , 1031 , 928 , 898 , 832 , 840 , 681}, - {24635 , 19605 , 9294 , 7407 , 6419 , 5459 , 4966 , 4189 , 3394 , 2964 , 2425 , 2110 , 2140 , 1972 , 1540 , 2252}, - {-867 , -666 , -168 , -114 , -90 , -122 , -129 , -101 , -65 , -56 , -39 , -35 , -40 , -42 , -35 , -56}, - {-2313 , 3035 , 1677 , 2854 , 2334 , 1232 , 1347 , 1034 , 863 , 707 , 886 , 891 , 432 , 357 , 206 , -310} -}; - -const Word16 lsf_unified_fit_model_wbhb[4][16] = -{ - {5312 , 1967 , 2914 , 1438 , 2595 , 1848 , 1980 , 2021 , 1535 , 1489 , 1651 , 1502 , 1447 , 1311 , 1353 , 1202}, - {28135 , 16053 , 10129 , 7366 , 5898 , 5341 , 3290 , 2780 , 3146 , 2423 , 1613 , 1370 , 1294 , 1635 , 1105 , 1431}, - {-615 , -308 , -147 , -119 , -104 , -105 , -30 , -28 , -50 , -39 , -15 , -14 , -14 , -21 , -19 , -29}, - {1534 , 3569 , 3138 , 4023 , 2105 , 2023 , 2046 , 1264 , 1340 , 1067 , 780 , 547 , 188 , -540 , -722 , -479} -}; - -const Word32 Freq_Weight_Com_fx[160] = /*Q31 */ -{ - 1073741824, 1351646720, 1610612736, 1832992000, 2003629568, 2110896768, 2147483647, 2147483647, - 2147483647, 2147483647, 2147483647, 2147483647, 2147483647, 2147483647, 2147483647, 2147483647, - 2147483647, 2147483647, 2147483647, 2147483647, 2147483647, 2088915968, 2033457920, 1980868480, - 1930930688, 1883448832, 1838246016, 1795162112, 1754051584, 1714781696, 1677231744, 1641291136, - 1606858368, 1573840768, 1542152704, 1511715456, 1482456448, 1454308608, 1427209600, 1401102080, - 1375932672, 1351651456, 1328212480, 1305572480, 1283691392, 1262531584, 1242058112, 1222238080, - 1203040640, 1184436864, 1166399744, 1148903808, 1131924864, 1115440512, 1099429376, 1083871488, - 1068747648, 1054040128, 1039731904, 1025806912, 1012249984, 999046720, 986183488, 973647232, - 961425728, 949507264, 937880640, 926535296, 915461184, 904648640, 894088512, 883772096, - 873691072, 863837376, 854203520, 844782144, 835566336, 826549440, 817725120, 809087168, - 800629824, 792347392, 784234624, 776286336, 768497472, 760863424, 753379520, 746041408, - 738844864, 731785856, 724860416, 718064832, 711395520, 704848896, 698421760, 692110720, - 685912704, 679824704, 673843840, 667967296, 662192384, 656516416, 650936960, 645451520, - 640057792, 634753472, 629536320, 624404224, 619355136, 614387008, 609497984, 604686208, - 599949760, 595286912, 590696000, 586175360, 581723392, 577338560, 573019328, 568764224, - 564571840, 560440832, 556369856, 552357568, 548402752, 544504128, 540660608, 536870912, - 533133984, 529448736, 525814080, 522228992, 518692448, 515203488, 511761152, 508364480, - 505012640, 501704704, 498439808, 495217120, 492035872, 488895200, 485794400, 482732672, - 479709280, 476723552, 473774752, 470862208, 467985248, 465143232, 462335520, 459561504, - 456820576, 454112160, 451435648, 448790528, 446176224, 443592192, 441037920, 438512896 -}; - - -const Word32 Freq_Weight_UV_fx[160] = /*Q31 */ -{ - 1073741824, 1351646720, 1610612736, 1832992000, 2003629568, 2110896768, 2147483647, 2129881344, - 2112565248, 2095528448, 2078764160, 2062265984, 2046027776, 2030043136, 2014306304, 1998811648, - 1983553536, 1968526720, 1953725696, 1939145728, 1924781696, 1910628864, 1896682624, 1882938624, - 1869392256, 1856039424, 1842876032, 1829897984, 1817101568, 1804482816, 1792038016, 1779763840, - 1767656576, 1755713024, 1743929728, 1732303488, 1720831232, 1709510016, 1698336768, 1687308544, - 1676422656, 1665676416, 1655067008, 1644591872, 1634248576, 1624034560, 1613947392, 1603984640, - 1594144256, 1584423936, 1574821376, 1565334528, 1555961216, 1546699520, 1537547520, 1528503040, - 1519564416, 1510729728, 1501997184, 1493365120, 1484831488, 1476395008, 1468053760, 1459806336, - 1451650944, 1443586176, 1435610624, 1427722624, 1419920896, 1412203904, 1404570368, 1397018880, - 1389548288, 1382157056, 1374844032, 1367608064, 1360447744, 1353362048, 1346349824, 1339409920, - 1332541184, 1325742464, 1319012736, 1312351104, 1305756416, 1299227648, 1292763776, 1286363904, - 1280027136, 1273752576, 1267539072, 1261385984, 1255292416, 1249257344, 1243280000, 1237359616, - 1231495424, 1225686400, 1219932032, 1214231424, 1208583808, 1202988544, 1197444736, 1191951872, - 1186509184, 1181116032, 1175771648, 1170475264, 1165226496, 1160024704, 1154868992, 1149758976, - 1144693888, 1139673344, 1134696576, 1129763200, 1124872448, 1120023808, 1115216768, 1110450944, - 1105725568, 1101040384, 1096394624, 1091787904, 1087219712, 1082689664, 1078197248, 1073741824, - 1069323136, 1064940672, 1060593984, 1056282624, 1052006144, 1047764224, 1043556288, 1039382080, - 1035241152, 1031132992, 1027057408, 1023013888, 1019002048, 1015021568, 1011072064, 1007153152, - 1003264576, 999405824, 995576704, 991776768, 988005760, 984263360, 980549120, 976862848, - 973204224, 969572864, 965968512, 962390848, 958839552, 955314432, 951815104, 948341312, -}; -const Word16 hann_window_320_fx[BWD_TOTAL_WIDTH/2] = -{ - 0, 1, 3, 7, 13, 20, 29, 39, - 51, 64, 79, 96, 114, 134, 155, 177, - 202, 227, 255, 283, 314, 345, 379, 413, - 449, 487, 525, 566, 607, 650, 695, 740, - 787, 835, 885, 935, 987, 1040, 1095, 1150, - 1207, 1265, 1323, 1383, 1444, 1506, 1569, 1633, - 1698, 1764, 1831, 1899, 1967, 2036, 2106, 2177, - 2249, 2321, 2394, 2468, 2543, 2617, 2693, 2769, - 2846, 2923, 3000, 3078, 3156, 3235, 3314, 3394, - 3473, 3553, 3633, 3713, 3794, 3874, 3955, 4035, - 4116, 4197, 4277, 4358, 4438, 4519, 4599, 4679, - 4759, 4838, 4917, 4996, 5075, 5153, 5231, 5308, - 5385, 5461, 5537, 5612, 5687, 5761, 5834, 5907, - 5979, 6050, 6121, 6190, 6259, 6327, 6395, 6461, - 6526, 6591, 6654, 6717, 6778, 6839, 6898, 6956, - 7014, 7070, 7125, 7178, 7231, 7282, 7332, 7381, - 7429, 7475, 7520, 7563, 7606, 7647, 7686, 7724, - 7761, 7796, 7830, 7863, 7894, 7923, 7951, 7978, - 8003, 8026, 8048, 8068, 8087, 8105, 8121, 8135, - 8147, 8158, 8168, 8176, 8182, 8187, 8190, 8192 -}; -const Word16 W_HIST_FX[DTX_HIST_SIZE] = {13107, 10486, 8389, 6711, 5369, 4295, 3436, 687}; /* Q16 */ -const Word16 W_HIST_S_FX[DTX_HIST_SIZE] = {20480, 11378, 8393, 6938, 6092, 5551, 5183, 5115}; /* Q12 */ - -/*----------------------------------------------------------------------------------* - * Starting points for pulse position search in Algebraic innovation codebook - * Used in lib_enc\cod4t64.c - *----------------------------------------------------------------------------------*/ - - - -const Word16 huffnorm_e_fx[32] = -{ - 1062, 550, 314, 274, 273, 272, 156, 79, 69, 38, - 18, 40, 5, 3, 0, 1, 3, 4, 11, 21, - 41, 32, 35, 67, 133, 264, 530, 315, 551, 2126, 4254, 4255 -}; - -const Word16 huffnorm_n_fx[32] = -{ - 14831, 14830, 7414, 3706, 593, 927, 462, 297, 230, 116, - 50, 36, 13, 8, 5, 1, 0, 2, 6, 7, - 15, 19, 24, 56, 59, 51, 114, 117, 75, 149, 592, 1852 -}; - -const Word16 huffsizn_e_fx[32] = -{ - 13, 12, 11, 11, 11, 11, 10, 9, 9, 8, - 7, 6, 5, 4, 3, 2, 2, 3, 4, 5, - 6, 8, 8, 9, 10, 11, 12, 11, 12, 14, 15, 15 -}; - -const Word16 huffsizn_n_fx[32] = -{ - 14, 14, 13, 12, 10, 10, 9, 9, 8, 7, - 7, 6, 5, 4, 3, 3, 3, 3, 3, 4, - 4, 5, 6, 6, 6, 7, 7, 7, 7, 8, 10, 11 -}; - -const Word16 resize_huffnorm_fx[32] = -{ - 0, 0, 0, 0, 0, 1023, 511, 255, 127, 63, 31, 15, 7, 3, 1, 0, - 2, 5, 11, 23, 47, 95, 191, 383, 767, 2047, 0, 0, 0, 0, 0, 0 -}; - -const Word16 huffnorm_fx[32] = -{ - 26, 58, 90, 122, 27, 59, 91, 123, 12, 28, 44, 60, 2, 6, 4, 6, - 0, 2, 10, 14, 14, 30, 46, 62, 30, 62, 94, 126, 31, 63, 95, 127 -}; - -const Word16 pgain_huffnorm_fx[32] = -{ - 1, 1, 2, 3, 3, 2, 2, 2, 3, 3, 4, 5, 6, 7, 8, 9, - 10, 11, 12, 13, 14, 15, 4, 5, 3, 2, 3, 3, 4, 5, 0, 1 -}; - -const Word16 hessize_fx[8]= -{ - 7, 5, 3, 2, 1, 4, 6, 7 -}; - -const Word16 hescode_fx[8]= -{ - 11, 3, 1, 1, 1, 0, 4, 10 -}; - -/*----------------------------------------------------------------------------------* - * Encoder TABLE ROM - *----------------------------------------------------------------------------------*/ - -/* [129] - half of the square root hanning window for spectral analysis and NS */ -const Word16 sqrt_han_window[L_FFT/2+1] = -{ - 0, 402, 804, 1206, 1608, 2009, 2410, 2811, 3212, - 3612, 4011, 4410, 4808, 5205, 5602, 5998, 6393, 6786, - 7179, 7571, 7962, 8351, 8739, 9126, 9512, 9896, 10278, - 10659, 11039, 11417, 11793, 12167, 12539, 12910, 13279, 13645, - 14010, 14372, 14732, 15090, 15446, 15800, 16151, 16499, 16846, - 17189, 17530, 17869, 18204, 18537, 18868, 19195, 19519, 19841, - 20159, 20475, 20787, 21096, 21403, 21705, 22005, 22301, 22594, - 22884, 23170, 23452, 23731, 24007, 24279, 24547, 24811, 25072, - 25329, 25582, 25832, 26077, 26319, 26556, 26790, 27019, 27245, - 27466, 27683, 27896, 28105, 28310, 28510, 28706, 28898, 29085, - 29268, 29447, 29621, 29791, 29956, 30117, 30273, 30424, 30571, - 30714, 30852, 30985, 31113, 31237, 31356, 31470, 31580, 31685, - 31785, 31880, 31971, 32057, 32137, 32213, 32285, 32351, 32412, - 32469, 32521, 32567, 32609, 32646, 32678, 32705, 32728, 32745, - 32757, 32765, 32767 -}; - -/*------------------------------------------------------------------------------* - * Critical bands in Q0 - *------------------------------------------------------------------------------*/ -const Word16 crit_bands[] = -{ - 100, 200, 300, 400, 510, 630, 770, 920, 1080, 1270, - 1480, 1720, 2000, 2320, 2700, 3150, 3700, 4400, 5300, 6350 -}; - -/*----------------------------------------------------------------------------------* - * Open-loop pitch tables, - * Used in lib_enc\pitch_ol.c - *----------------------------------------------------------------------------------*/ - - -/* integer square (i*i) */ -const Word16 int_sqr[17] = -{ - 0, 1, 4, 9, 16, 25, 36, 49, 64, 81, 100, 121, 144, 169, 196, 225, 256 -}; - - -/*ari_hm_enc.c*/ -/* Q13 format */ -const Word16 kLowPeriodicityThr[2] = { 4096/*0.5f Q13*/, 1638/*0.2f Q13*/ }; - -/* pow(3 * i + 1, 0.3) / pow(256 - 1, 0.3) */ -const Word16 Weight[86] = -{ - 0x1848, 0x24CD, 0x2B87, 0x3072, 0x3469, 0x37C8, 0x3ABB, 0x3D5F, 0x3FC6, 0x41FA, 0x4406, 0x45EF, 0x47BB, 0x496E, 0x4B0A, - 0x4C93, 0x4E0A, 0x4F71, 0x50CA, 0x5216, 0x5357, 0x548C, 0x55B8, 0x56DA, 0x57F4, 0x5905, 0x5A10, 0x5B13, 0x5C10, 0x5D06, 0x5DF7, - 0x5EE2, 0x5FC8, 0x60A9, 0x6185, 0x625D, 0x6331, 0x6401, 0x64CD, 0x6595, 0x6659, 0x671B, 0x67D9, 0x6893, 0x694B, 0x6A00, 0x6AB2, - 0x6B62, 0x6C0F, 0x6CB9, 0x6D61, 0x6E07, 0x6EAB, 0x6F4C, 0x6FEB, 0x7088, 0x7124, 0x71BD, 0x7254, 0x72EA, 0x737E, 0x7410, 0x74A1, - 0x752F, 0x75BD, 0x7649, 0x76D3, 0x775C, 0x77E3, 0x7869, 0x78EE, 0x7971, 0x79F3, 0x7A74, 0x7AF4, 0x7B72, 0x7BF0, 0x7C6C, 0x7CE7, - 0x7D61, 0x7DDA, 0x7E51, 0x7EC8, 0x7F3E, 0x7FB3, 0x7FFF -}; - -const Word16 lsf_numlevels[TCXLPC_NUMSTAGES] = { 32, 16, 16 }; -const Word16 lsf_ind_numlevels[TCXLPC_IND_NUMSTAGES] = { 4 }; - -/*----------------------------------------------------------------------------------* - * Starting line for the noise measurement in TCX. - *----------------------------------------------------------------------------------*/ -const Word16 startLineWB[11] = { 8, 23, 36, 45, 66, 128 /* 13.2kbps */, 200, 320, 320, 320 /* 48kbps */, 320 }; -const Word16 startLineSWB[9] = { 8, 44, 96 /* 13.2kbps */, 160, 320, 320, 256 /* 48kbps */, 341, 640 }; - -/*----------------------------------------------------------------------------------* - * CLDFB-based VAD - *----------------------------------------------------------------------------------*/ -/* SNR_calc.c */ -const Word16 Nregion_index_NB[9] = {0,1,2,3,4,5,6,7, 9}; -const Word16 Nregion_index_WB[13] = {0,1,2,3,4,5,6,8,10,12,16}; -const Word16 Nregion_index_SWB[16] = {0,1,2,3,4,5,6,8,10,12,16,24,36}; -const Word16 Nregion_index_FB[16] = {0,1,2,3,4,5,6,8,10,12,16,24,36}; -const Word16 Nregion_preoff[12] = {0,0,0,0,0,0,1,1,1,2,3,4}; -const Word16 SNR_SUB_BAND_NUM[4] = {8,10,12,MAX_SUBBAND_NUM}; -const Word16 BAND_MUL[4] = {4096/* 1/8.0 Q15 */,3277/* 1/10.0 Q15 */,2731/* 1/12.0 Q15 */,2731/* 1/12.0 Q15 */}; -const Word16 *REGION_INDEX[4] = {Nregion_index_NB, Nregion_index_WB,Nregion_index_SWB,Nregion_index_FB}; -const Word32 MAX_LF_SNR_TAB[5] = {26843545/* 0.8 Q25 */,26843545/* 0.8 Q25 */,53687090/* 1.6 Q25 */,26843545/* 0.8 Q25 */,26843545/* 0.8 Q25 */}; -const Word32 LS_MIN_SILENCE_SNR[4] = {251658233/* 7.5 Q25 */, 251658233/* 7.5 Q25 */, 228170137/* 6.8 Q25 */,228170137/* 6.8 Q25 */}; -const Word32 LT_MIN_SILENCE_SNR[4] = {150994940/* 4.5 Q25 */, 150994940/* 4.5 Q25 */, 150994940/* 4.5 Q25 */,150994940/* 4.5 Q25 */}; -const Word32 COMVAD_INIT_SNR_DELTA[5] = {33554431/* 1.0 Q25 */, 20132659/* 0.6 Q25 */, 28856811/* 0.86 Q25 */, 38923139/* 1.16 Q25 */, 33554431/* 1.0 Q25 */}; - -/* spec_center.c */ -const Word16 i_t_1[10]= {2048,4096,6144,8192,10240,12288,14336,16384,18432,20480}; -const Word16 i_t_2[23]= {1024,2048,3072,4096,5120,6144,7168,8192,9216,10240,11264,12288,13312,14336,15360,16384,17408,18432,19456,20480,21504,22528,23552}; - -/* subband_fft.c */ -const complex_16 wnk_table_16[16] = -{ - {32767, 0}, {30274, 12540}, {23170, 23170}, {12540, 30274}, - {32767, 0}, {23170, 23170}, {0, 32767}, {-23170, 23170}, - {32767, 0}, {12540, 30274}, {-23170, 23170}, {-30274, -12540}, - {32767, 0}, {32767, 0}, {32767, 0}, {0, -32768}, -}; - -/* x(n)*W_2N^n */ -const complex_16 M_in_fix16[16] = -{ - {32767, 0}, {32138, 6393}, {30274, 12540}, {27246, 18205}, - {23170, 23170}, {18205, 27246}, {12540, 30274}, {6393, 32138}, - {0, 32767}, {-6393, 32138}, {-12540, 30274}, {-18205, 27246}, - {-23170, 23170},{ -27246, 18205}, {-30274, 12540}, {-32138, 6393}, -}; -/*W_2N^(k+1/2)*/ - -const Word16 M_Wr_fix16[16] = -{ - 32609/* 9.9518473e-001f Q15 */,31356/* 9.5694034e-001f Q15 */,28898/* 8.8192126e-001f Q15 */,25329/* 7.7301045e-001f Q15 */,20787/* 6.3439328e-001f Q15 */,15446/* 4.7139674e-001f Q15 */, 9512/* 2.9028468e-001f Q15 */, 3212/* 9.8017140e-002f Q15 */, - -3212/* -9.8017140e-002f Q15 */,-9512/* -2.9028468e-001f Q15 */,-15446/* -4.7139674e-001f Q15 */,-20787/* -6.3439328e-001f Q15 */,-25329/* -7.7301045e-001f Q15 */,-28898/* -8.8192126e-001f Q15 */,-31356/* -9.5694034e-001f Q15 */,-32609/* -9.9518473e-001f Q15 */ -}; - -const Word16 M_Wi_fix16[16] = -{ - 3212/* 9.8017140e-002f Q15 */, 9512/* 2.9028468e-001f Q15 */,15446/* 4.7139674e-001f Q15 */,20787/* 6.3439328e-001f Q15 */,25329/* 7.7301045e-001f Q15 */,28898/* 8.8192126e-001f Q15 */,31356/* 9.5694034e-001f Q15 */,32609/* 9.9518473e-001f Q15 */, - 32609/* 9.9518473e-001f Q15 */,31356/* 9.5694034e-001f Q15 */,28898/* 8.8192126e-001f Q15 */,25329/* 7.7301045e-001f Q15 */,20787/* 6.3439328e-001f Q15 */,15446/* 4.7139674e-001f Q15 */, 9512/* 2.9028468e-001f Q15 */, 3212/* 9.8017140e-002f Q15 */ -}; - -/* vad_proc.c */ -const Word16 BAND_NUM_TAB[5] = {10,10,20,40,60}; /* {OFFSET, NB, WB, SWB, FB} */ -const Word16 BAND_SCALE_AJ[5] = {3,3,5,6,6}; /* {OFFSET, NB, WB, SWB, FB} */ - -/* enc_acelp.c, enc_acelpx.c */ -const UWord8 E_ROM_tipos[40] = -{ - 0, 1, 2, 3, /* starting point &ipos[0], 1st iter */ - 1, 2, 3, 0, /* starting point &ipos[4], 2nd iter */ - 2, 3, 0, 1, /* starting point &ipos[8], 3rd iter */ - 3, 0, 1, 2, /* starting point &ipos[12], 4th iter */ - 0, 1, 2, 3, - 1, 2, 3, 0, - 2, 3, 0, 1, - 3, 0, 1, 2, - 0, 1, 2, 3, /* end point for 24 pulses &ipos[35], 4th iter */ - 1, 2, 3, 0 /* end point for 36 pulses &ipos[39], 2nd iter */ -}; - -/* bw_detect_fx.c */ -const Word16 bwd_start_bin_fx[4] = {1, 3, 6, 11}; -const Word16 bwd_end_bin_fx[4] = {1, 4, 9, 12}; - - - - diff --git a/src/libs/libevs/lib_enc/rom_enc_fx.h b/src/libs/libevs/lib_enc/rom_enc_fx.h deleted file mode 100755 index 0e786087..00000000 --- a/src/libs/libevs/lib_enc/rom_enc_fx.h +++ /dev/null @@ -1,120 +0,0 @@ -/*==================================================================================== - EVS Codec 3GPP TS26.442 Apr 03, 2018. Version 12.11.0 / 13.6.0 / 14.2.0 - ====================================================================================*/ - -#ifndef ROM_ENC_FX_H -#define ROM_ENC_FX_H - -#include -#include "options.h" -#include "cnst_fx.h" -#include "stat_enc_fx.h" - - -/*----------------------------------------------------------------------------------* - * General tables - *----------------------------------------------------------------------------------*/ - -extern const Word16 sqrt_han_window[]; /* LP analysis: half of the square root hanning window */ -extern const Word16 crit_bands[]; /* LP analysis: critical bands */ - -extern const Word16 hangover_hd_tbl_fx[3]; -extern const Word16 hangover_sf_tbl_fx[6]; - -extern const Word16 H_fir[]; -extern const Word16 len_12k8_fx[]; -extern const Word16 len1_12k8_fx[]; -extern const Word16 sublen_12k8_fx[]; -extern const Word16 sublen1_12k8_fx[]; -extern const Word16 pit_max_12k8_fx[]; -extern const Word16 sec_length_12k8_fx[]; -extern const Word16 sec_length1_12k8_fx[]; -extern const Word16 w_spmus_fx[HANG_LEN][HANG_LEN]; -extern const Word16 SF_mult_fx[N_FEATURES]; -extern const Word16 SF_8k_mult_fx[N_FEATURES]; -extern const Word32 SF_add_fx[N_FEATURES]; -extern const Word32 SF_8k_add_fx[N_FEATURES]; - -extern const Word32 lvm_noise_fx[]; -extern const Word32 invV_noise_fx[N_MIXTURES*N_FEATURES*N_FEATURES]; -extern const Word16 m_noise_fx[N_MIXTURES*N_FEATURES]; -extern const Word32 lvm_music_fx[N_MIXTURES]; -extern const Word32 invV_music_fx[N_MIXTURES*N_FEATURES*N_FEATURES]; -extern const Word16 m_music_fx[N_MIXTURES*N_FEATURES]; -extern const Word32 invV_speech_fx[N_MIXTURES*N_FEATURES*N_FEATURES]; -extern const Word32 lvm_speech_fx[N_MIXTURES]; -extern const Word16 m_speech_fx[N_MIXTURES*N_FEATURES]; -extern const Word16 inv_delta_tab[7]; - -extern const Word16 lsf_unified_fit_model_nb[4][16]; -extern const Word16 lsf_unified_fit_model_wb[4][16]; -extern const Word16 lsf_unified_fit_model_wbhb[4][16]; - -extern const Word32 Freq_Weight_Com_fx[160]; -extern const Word32 Freq_Weight_UV_fx[160]; /*Q31*/ -extern const Word16 hann_window_320_fx[]; -extern const Word16 W_HIST_FX[]; -extern const Word16 W_HIST_S_FX[]; - - -/*----------------------------------------------------------------------------------* - * Huffman coding - *----------------------------------------------------------------------------------*/ - -extern const Word16 huffsizn_e_fx[32]; -extern const Word16 huffsizn_n_fx[32]; - -extern const Word16 huffnorm_e_fx[32]; -extern const Word16 huffnorm_n_fx[32]; -extern const Word16 hessize_fx[8]; -extern const Word16 hescode_fx[8]; - -extern const Word16 resize_huffnorm_fx[32]; -extern const Word16 huffnorm_fx[32]; -extern const Word16 pgain_huffnorm_fx[32]; - -extern const Word16 Weight[86]; -extern const Word16 kLowPeriodicityThr[2]; /* ari_hm_enc.c */ - -extern const UWord8 E_ROM_tipos[]; /* ACELP indexing */ - -extern const Word16 lsf_numlevels[TCXLPC_NUMSTAGES]; -extern const Word16 lsf_ind_numlevels[TCXLPC_IND_NUMSTAGES]; - -/*----------------------------------------------------------------------------------* - * Starting line for the noise measurement in TCX. - *----------------------------------------------------------------------------------*/ -extern const Word16 startLineWB[11]; -extern const Word16 startLineSWB[9]; - -/*----------------------------------------------------------------------------------* -* CLDFB-VAD -*----------------------------------------------------------------------------------*/ -extern const Word16 BAND_NUM_TAB[5]; -extern const Word16 BAND_SCALE_AJ[5]; -extern const Word32 LS_MIN_SILENCE_SNR[4] ; -extern const Word32 LT_MIN_SILENCE_SNR[4] ; -extern const Word16 Nregion_index_NB[9]; -extern const Word16 Nregion_index_WB[13]; -extern const Word16 Nregion_index_SWB[16] ; -extern const Word16 Nregion_index_FB[16] ; -extern const Word16 Nregion_preoff[12]; -extern const Word16 SNR_SUB_BAND_NUM[4]; -extern const Word16 BAND_MUL[4] ; -extern const Word16 *REGION_INDEX[4] ; -extern const Word32 MAX_LF_SNR_TAB[5]; -extern const Word16 band_num[4]; -extern const Word32 COMVAD_INIT_SNR_DELTA[5]; -extern const Word16 i_t_1[10]; -extern const Word16 i_t_2[23]; -extern const complex_16 wnk_table_16[16]; -extern const complex_16 M_in_fix16[16]; -extern const Word16 M_Wr_fix16[16]; -extern const Word16 M_Wi_fix16[16]; - -/* bw_detect_fx.c */ -extern const Word16 bwd_start_bin_fx[4]; -extern const Word16 bwd_end_bin_fx[4]; - -#endif /* ROM_ENC_FX_H */ - diff --git a/src/libs/libevs/lib_enc/rst_enc.cpp b/src/libs/libevs/lib_enc/rst_enc.cpp new file mode 100644 index 00000000..d9b4b6bd --- /dev/null +++ b/src/libs/libevs/lib_enc/rst_enc.cpp @@ -0,0 +1,58 @@ +/*==================================================================================== + EVS Codec 3GPP TS26.443 Nov 13, 2018. Version 12.11.0 / 13.7.0 / 14.3.0 / 15.1.0 + ====================================================================================*/ + +#include "options.h" +#include "cnst.h" +#include "rom_com.h" +#include "prot.h" + + +/*-------------------------------------------------------------------* + * CNG_reset_enc() + * + * Reset encoder static variables after a CNG frame + *-------------------------------------------------------------------*/ + +void CNG_reset_enc( + Encoder_State *st, /* i/o: encoder state structure */ + LPD_state *mem, /* i/o: encoder memories */ + float *pitch_buf, /* o : floating pitch for each subframe */ + float *voice_factors /* o : voicing factors */ + ,short VBR_cng_reset_flag +) +{ + init_gp_clip(st->clip_var); + mvr2r( UVWB_Ave, st->mem_AR, M ); + set_f(st->mem_MA, 0, M ); + mem->mem_w0 = 0.0f; + mem->tilt_code = 0.0f; + mem->gc_threshold = 0.0f; + if( VBR_cng_reset_flag ) + { + set_f( mem->mem_syn, 0, M ); + } + set_f( st->dispMem, 0, 8 ); + + /* last good received frame for FEC in ACELP */ + st->clas = UNVOICED_CLAS; + /* reset the pitch buffer in case of FRAME__NO_DATA or SID frames */ + if(st->L_frame == L_FRAME ) + { + set_f( pitch_buf, (float)L_SUBFR, NB_SUBFR ); + } + else /* st->L_frame == L_FRAME16k */ + { + set_f( pitch_buf, (float)L_SUBFR16k, NB_SUBFR16k ); + } + + set_f( voice_factors, 1.0, NB_SUBFR16k ); + + /* Reset active frame counter */ + st->act_cnt2 = 0; + + /* deactivate bass post-filter */ + st->bpf_off = 1; + + return; +} diff --git a/src/libs/libevs/lib_enc/rst_enc_fx.cpp b/src/libs/libevs/lib_enc/rst_enc_fx.cpp deleted file mode 100755 index 58ba0e3e..00000000 --- a/src/libs/libevs/lib_enc/rst_enc_fx.cpp +++ /dev/null @@ -1,69 +0,0 @@ -/*==================================================================================== - EVS Codec 3GPP TS26.442 Apr 03, 2018. Version 12.11.0 / 13.6.0 / 14.2.0 - ====================================================================================*/ - -#include "options.h" /* Compilation switches */ -#include "cnst_fx.h" /* Common constants */ -#include "rom_com_fx.h" /* Static table prototypes */ -#include "prot_fx.h" /* Function prototypes */ -#include "stl.h" - -/*-------------------------------------------------------------------* - * CNG_reset_enc() - * - * Reset encoder static variables after a CNG frame - *-------------------------------------------------------------------*/ - -void CNG_reset_enc_fx( - Encoder_State_fx *st_fx, /* i/o: encoder state structure */ - LPD_state *mem, /* i/o: acelp memories */ - Word16 *pitch_buf, /* o : floating pitch for each subframe */ - Word16 *voice_factors /* o : voicing factors */ - ,Word16 VBR_cng_reset_flag -) -{ - init_gp_clip_fx( st_fx->clip_var_fx ); - Copy( UVWB_Ave_fx, st_fx->mem_AR_fx, M ); - set16_fx( st_fx->mem_MA_fx, 0, M ); - mem->mem_w0 = 0; - move16(); - mem->tilt_code = 0; - move16(); - mem->gc_threshold = 0; - move16(); - IF( sub(VBR_cng_reset_flag,1) == 0 ) - { - set16_fx( mem->mem_syn, 0, M ); - } - /*set16_fx( st_fx->dispMem_fx , 0, 8 ); */ - set16_fx( st_fx->dm_fx.prev_gain_pit , 0, 6 ); - st_fx->dm_fx.prev_gain_code = L_deposit_l(0); - st_fx->dm_fx.prev_state = 0; - move16(); - - /* last good received frame for FEC in ACELP */ - st_fx->clas_fx = UNVOICED_CLAS; - move16(); - - /* reset the pitch buffer in case of FRAME_NO_DATA or SID frames */ - IF( sub(st_fx->L_frame_fx,L_FRAME) == 0 ) - { - set16_fx( pitch_buf, L_SUBFR, NB_SUBFR ); - } - ELSE /* st->L_frame == L_FRAME16k */ - { - set16_fx( pitch_buf, L_SUBFR16k, NB_SUBFR16k ); - } - - set16_fx( voice_factors, 1, NB_SUBFR16k ); - - /* deactivate bass post-filter */ - st_fx->bpf_off_fx = 1; - move16(); - - /* Reset active frame counter */ - st_fx->act_cnt2_fx = 0; - move16(); - - return; -} diff --git a/src/libs/libevs/lib_enc/scale_enc_fx.cpp b/src/libs/libevs/lib_enc/scale_enc_fx.cpp deleted file mode 100755 index 86ae2f1e..00000000 --- a/src/libs/libevs/lib_enc/scale_enc_fx.cpp +++ /dev/null @@ -1,273 +0,0 @@ -/*==================================================================================== - EVS Codec 3GPP TS26.442 Apr 03, 2018. Version 12.11.0 / 13.6.0 / 14.2.0 - ====================================================================================*/ - -#include "options.h" /* Compilation switches */ -#include "cnst_fx.h" /* Common constants */ -#include "rom_com_fx.h" /* Static table prototypes */ -#include "prot_fx.h" /* Function prototypes */ -#include "stl.h" - -/*-------------------------------------------------------------------* - * Scale_wsp - * - * Find scaling factor for weighted speech input - *-------------------------------------------------------------------*/ -void Scale_wsp( - Word16 *wsp, /* i : Weigthed speech */ - Word16 *old_wsp_max, /* i : Last weigthed speech maximal valu */ - Word16 *shift, /* i/o: Scaling of current frame */ - Word16 *Q_exp, /* i/o: Differential scaling factor */ - Word16 *old_wsp_shift, /* i/o: Last wsp scaling */ - Word16 *old_wsp, /* i/o: Old weighted speech buffer */ - Word16 *mem_decim2, /* i/o: Decimation buffer */ - Word16 *old_wsp12k8, /* i/o: wsp memory @ 12.8 kHz used in pitol2 */ - const Word16 Len_p_look /* i : L_frame + look ahead */ -) -{ - Word16 max, i, tmp; - - /* find maximum value on wsp[] for 12 bits scaling */ - max = 0; - move16(); - FOR (i = 0; i < Len_p_look; i++) - { - tmp = abs_s(wsp[i]); - max = s_max(max,tmp); - } - tmp = *old_wsp_max; - move16(); - tmp = s_max(max, tmp); - *old_wsp_max = max; - move16(); - - *shift = sub(norm_s(tmp), 3); - move16(); - - *shift = s_min(*shift, 0); - move16(); /* shift = 0..-3 */ - - - Scale_sig(wsp, Len_p_look, *shift); - /* scale old_wsp (warning: exp must be Q_new-Q_old) */ - *Q_exp= add(*Q_exp, sub(*shift, *old_wsp_shift)); - move16(); - *old_wsp_shift = *shift; - move16(); - Scale_sig(old_wsp12k8, L_WSP_MEM, *Q_exp); /* Already scaled with premphasis */ - Scale_sig(old_wsp, (L_WSP_MEM - L_INTERPOL)/OPL_DECIM, *Q_exp ); - Scale_sig(mem_decim2, 3, *Q_exp); - - Copy( old_wsp12k8, wsp - L_WSP_MEM, L_WSP_MEM ); /* Now memory and wsp vector have the same scaling */ -} - -/*-------------------------------------------------------------------* - * Preemph_scaled - * - * Find scaled preemphasis vector and its scaling factor - *-------------------------------------------------------------------*/ -void Preemph_scaled( - Word16 new_speech[], /* i : Speech to scale already on 14 bits*/ - Word16 *Q_new, /* o : Scaling factor */ - Word16 *mem_preemph, /* i/o: Preemph memory */ - Word16 *Q_max, /* i/o: Q_new limitation */ - const Word16 Preemph_factor, /* i : Preemphasis factor Q15 */ - const Word16 bits, /* i : Bit to remove from the output to (15-bits)*/ - const Word16 bit1, /* i : Limit the output scaling to ((15-bits)-bit1) bits */ - const Word16 L_Q_mem, /* i : Number of old scaling to take into account */ - const Word16 Lframe, /* i : Frame length */ - const Word16 last_coder_type, /* i : coder_type */ - const Word16 Search_scaling /* i : enable the search of a proper scaling factor*/ -) -{ - Word16 i, tmp_fixed; - Word16 mu, shift, QVal; - Word32 L_tmp, L_maxloc; - Word16 Q_min; - - /*---------------------------------------------------------------* - * Perform fixed preemphasis through 1 - g z^-1 * - * Scale signal to get maximum of precision in filtering * - *---------------------------------------------------------------*/ - - BASOP_SATURATE_WARNING_OFF - QVal = shl(1, sub(15,bits)); - BASOP_SATURATE_WARNING_ON - mu = shr(Preemph_factor, bits); /* Q15 --> Q(15-bits) */ - - IF(sub(Search_scaling,1)==0) - { - /* get max of new preemphased samples (L_FRAME+L_FILT) */ - - L_tmp = L_mult(new_speech[0], QVal); - L_tmp = L_msu(L_tmp, *mem_preemph, mu); - L_maxloc = L_abs(L_tmp); - - FOR (i = 1; i < Lframe; i++) - { - /* Equivalent to tmp = max((abs(x[i] - mu*x[i-1]),tmp) - * finds the max of preemphasized signal */ - L_tmp = L_mult(new_speech[i], QVal); - L_tmp = L_msu(L_tmp, new_speech[i - 1], mu); - L_tmp = L_abs(L_tmp); - L_maxloc = L_max(L_tmp, L_maxloc); - } - - /* get scaling factor for new and previous samples */ - /* limit scaling to Q_MAX to keep dynamic for ringing in low signal */ - /* limit scaling to Q_MAX also to avoid a[0]<1 in syn_filt_32 */ - tmp_fixed = s_max(extract_h(L_maxloc),1); - - /* output on 14 bits: needed unless the resampling itself removes 1 bit*/ - shift = sub(norm_s(tmp_fixed), add(bits,bit1)); - shift = s_max(shift, 0); - shift = s_min(shift, Q_MAX); - - minimum_fx(Q_max, L_Q_mem, &Q_min); - *Q_new = s_min(shift, Q_min); - move16(); - - IF (tmp_fixed == 0) - { - IF ( sub(last_coder_type, UNVOICED) != 0 ) - { - *Q_new = s_min(*Q_new, 1); - move16(); - } - } - - FOR(i = L_Q_mem-1; i > 0; i--) - { - Q_max[i] = Q_max[i-1]; - move16(); - } - Q_max[i] = shift; - move16(); - } - - /*---------------------------------------------------------------* - * preemphasis with scaling (L_FRAME+L_FILT) - * now do the actual preemphasis, since we have the - * proper scaling factor. - * Done backwards to save storage space - *---------------------------------------------------------------*/ - - tmp_fixed = new_speech[Lframe - 1]; - move16(); - - FOR (i = sub(Lframe,1); i > 0; i--) - { - L_tmp = L_mult(new_speech[i], QVal); - L_tmp = L_msu(L_tmp, new_speech[i - 1], mu); - L_tmp = L_shl(L_tmp, *Q_new); - new_speech[i] = round_fx(L_tmp); - } - - L_tmp = L_mult(new_speech[0], QVal); - L_tmp = L_msu(L_tmp, *mem_preemph, mu); - L_tmp = L_shl(L_tmp, *Q_new); - new_speech[0] = round_fx(L_tmp); - - *mem_preemph = tmp_fixed; - move16(); -} -/*-------------------------------------------------------------------* - * Scale_mem - * - * Rescale memories - *-------------------------------------------------------------------*/ -Word32 Scale_mem_pre_proc( /* o : Min energy scaled */ - Word16 ini_frame_fx, /* i : Frame number */ - Word16 Q_exp, /* i : Diff scaling factor */ - Word16 *Q_new, /* i/o: Absolute scaling factor */ - Word16 *old_speech, /* i/o: Speech memory */ - Word16 *mem_wsp, /* i/o: wsp vector memory */ - Word32 *enrO, /* i/o: Enr mem */ - Word32 *bckr, /* i/o: Back ground_fx ener mem */ - Word32 *ave_enr, /* i/o: Ave_enr mem */ - Word32 *ave_enr2, /* i/o: Ave_enr2 mem */ - Word32 *st_fr_bands1, /* i/o: spectrum per critical bands of the previous frame */ - Word32 *st_fr_bands2, /* i/o: spectrum per critical bands 2 frames ago */ - Word32 *st_Bin_E_old -) -{ - Word16 i; - Word32 e_min_scaled; - - e_min_scaled = L_shr_r(L_add(L_shr(E_MIN_FXQ15,sub(14,add(*Q_new,QSCALE))),1),1); - - /* scale previous samples and memory (Q_exp - Q_new - Q_old) */ - /* Scale( x, y, z ) : shift left vector x of size y by z bits ) */ - IF (Q_exp != 0) - { - IF(old_speech != NULL) - { - Scale_sig(old_speech, L_INP_MEM, Q_exp); - } - Scale_sig(mem_wsp, 1, Q_exp); - IF( ini_frame_fx ==0 ) - { - /* Scaling noise vectors if frame ==1*/ - Scale_sig32(enrO, NB_BANDS,*Q_new); - Scale_sig32(bckr, NB_BANDS, *Q_new); - Scale_sig32(ave_enr, NB_BANDS, *Q_new); - Scale_sig32(ave_enr2, NB_BANDS, *Q_new); - Scale_sig32(st_fr_bands1, NB_BANDS, *Q_new); - Scale_sig32(st_fr_bands2, NB_BANDS, *Q_new); - Scale_sig32(st_Bin_E_old, L_FFT/2, *Q_new); - } - ELSE - { - /* Do scaling and valide minimum energy value */ - FOR (i = 0; i < NB_BANDS; i++) - { - enrO[i] = L_max(L_shl(enrO[i], Q_exp),e_min_scaled); - move32(); - bckr[i] = L_max(L_shl(bckr[i], Q_exp),e_min_scaled); - move32(); - ave_enr[i] = L_max(L_shl(ave_enr[i], Q_exp),e_min_scaled); - move32(); - ave_enr2[i] = L_max(L_shl(ave_enr2[i], Q_exp),e_min_scaled); - move32(); - st_fr_bands1[i] = L_max(L_shl(st_fr_bands1[i], Q_exp),e_min_scaled); - move32(); - st_fr_bands2[i] = L_max(L_shl(st_fr_bands2[i], Q_exp),e_min_scaled); - move32(); - } - } - } - return e_min_scaled; -} - -void Scale_mem_enc( - Word16 Q_exp, /* i : Diff scaling factor */ - Word16 *old_speech16k, /* i/o: Speech memory */ - Word16 *old_exc, /* i/o: excitation memory */ - Word16 *old_bwe_exc, /* i/o: BWE excitation memory */ - Word16 *mem_w0, /* i/o: target vector memory */ - Word16 *mem_syn, /* i/o: synthesis memory */ - Word16 *mem_syn2, /* i/o: synthesis memory */ - Word16 *mem_deemp_preQ_fx, /*i/o: deemphasis memory for the high rate celp codec */ - Word16 *last_exc_dct_in, - Word16 *old_input_lp -) -{ - /* scale previous samples and memory (Q_exp - Q_new - Q_old) */ - /* Scale( x, y, z ) : shift left vector x of size y by z bits ) */ - IF (Q_exp != 0) - { - Scale_sig(old_speech16k, L_INP_MEM, Q_exp); - Scale_sig(mem_w0, 1, Q_exp); - /* Scaling excitation */ - Scale_sig(old_exc,L_EXC_MEM, Q_exp); - Scale_sig(old_bwe_exc, PIT16k_MAX*2, Q_exp); - Scale_sig(mem_syn, M, Q_exp); - Scale_sig(mem_syn2, M, Q_exp); - Scale_sig(last_exc_dct_in,L_FRAME, Q_exp); - Scale_sig(mem_deemp_preQ_fx, 1, Q_exp); - Scale_sig(old_input_lp, NS2SA(16000, ACELP_LOOK_NS + DELAY_SWB_TBE_16k_NS + DELAY_FIR_RESAMPL_NS), Q_exp); - } - - return; -} - diff --git a/src/libs/libevs/lib_enc/set_impulse.cpp b/src/libs/libevs/lib_enc/set_impulse.cpp new file mode 100644 index 00000000..fb093e73 --- /dev/null +++ b/src/libs/libevs/lib_enc/set_impulse.cpp @@ -0,0 +1,301 @@ +/*==================================================================================== + EVS Codec 3GPP TS26.443 Nov 13, 2018. Version 12.11.0 / 13.7.0 / 14.3.0 / 15.1.0 + ====================================================================================*/ + +#include "cnst.h" +#include "rom_com.h" +#include "prot.h" + +/*-----------------------------------------------------------------* + * Local constant + *-----------------------------------------------------------------*/ +#define INPOL 4 /* +- range in samples for impulse position searching */ + +/*-----------------------------------------------------------------* + * Local function prototype + *-----------------------------------------------------------------*/ +static void convolve_tc(const float g[], const float h[], float y[], const short L_1, const short L_2); +static void correlate_tc(const float *x, float *y, const float *h, const short start, const short L_1, + const short L_2); +static void convolve_tc2(const float g[], const float h[], float y[], const short pos_max); + +/*---------------------------------------------------------------------------------------* + * Function set_impulse() for TC * + * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ * + * Builds glottal codebook contribution based on glotal impulses positions finding. * + * * + * Returns a position of the glotal impulse center and * + * a number of the glotal impulse shape. * + * * + * |----| |----| xn * + * imp_pos-> || | imp_shape-> | g1 | | * + * | | | | g2 | exc |---| y1 ---- | * + * | | |--------------| |---------| h |-------|gain|-------(-)---> xn2 * + * | || | gn | |---| ---- * + * |----| |----| * + * codebook excitation h_orig gain * + * * + * * + * nominator dd * * + * Searching criterion: maximize ------------- = ---- = ----------------- * + * denominator rr * + * * + * Notice: gain = gain_trans * gain_pit (computed in trans_enc() function) * + * * + *---------------------------------------------------------------------------------------*/ + +void set_impulse( + const float xn[], /* i : target signal */ + const float h_orig[], /* i : impulse response of weighted synthesis filter */ + float exc[], /* o : adaptive codebook excitation */ + float y1[], /* o : filtered adaptive codebook excitation */ + short *imp_shape, /* o : adaptive codebook index */ + short *imp_pos, /* o : position of the glotal impulse center index */ + float *gain_trans /* o : transition gain */ +) +{ + float rr[L_SUBFR]; /* criterion: nominator coeficients */ + float dd[L_SUBFR]; /* criterion: denominator coeficients */ + float gh[L_SUBFR]; /* convolution of 'g' and 'h' filters */ + float krit, krit_max; + short i, j, m; + short start1, start2, end1; + + + krit_max = -1.0e+12f; + + /* main loop */ + /* impulse */ + for( m = 0; m < NUM_IMPULSE; m++ ) + { + /* set searching ranges */ + if( *imp_posINPOL ) + { + start1 = *imp_pos-INPOL; + } + else + { + start1 = 0; + } + if( start1>L_IMPULSE2 ) + { + start2 = start1; + } + else + { + start2 = L_IMPULSE2; + } + + /*-----------------------------------------------------* + * nominator & DEnominator, gh=conv(g,h) + *-----------------------------------------------------*/ + if( start1 */ + for( i=0; i < L_SUBFR; i++ ) + { + rr[start1] += gh[i]*gh[i]; + dd[start1] += gh[i]*xn[i]; + } + for( i=start1+1; i */ + for( j=L_SUBFR-1; j > 0; j-- ) + { + gh[j] = gh[j-1] + glottal_cdbk[m*L_IMPULSE+L_IMPULSE2-i]*h_orig[j]; + rr[i] += gh[j]*gh[j]; + dd[i] += gh[j]*xn[j]; + } + gh[0] = glottal_cdbk[m*L_IMPULSE+L_IMPULSE2-i]*h_orig[0]; + rr[i] += gh[0]*gh[0]; + dd[i] += gh[0]*xn[0]; + /* move rr and dd into rr[i] and dd[i] */ + } + /* complete convolution(excitation,h_orig) */ + for( j=L_SUBFR-1; j > 0; j-- ) + { + gh[j] = gh[j-1] + glottal_cdbk[m*L_IMPULSE]*h_orig[j]; + } + } + else + { + convolve_tc( &glottal_cdbk[m*L_IMPULSE], &h_orig[0], gh, L_IMPULSE, L_SUBFR ); + } + if( end1>=start2 ) + { + /* Denominator row */ + rr[L_SUBFR-1] = 0; + for (j=0; j <= L_IMPULSE2; j++) + { + rr[L_SUBFR-1] += gh[j]*gh[j]; + } + /* move rr into rr[L_SUBFFR-1 */ + /* Denominator rows */ + for( i=L_SUBFR-2; i >= start2; i-- ) + { + rr[i] = rr[i+1] + gh[L_SUBFR+L_IMPULSE2-1-i]*gh[L_SUBFR+L_IMPULSE2-1-i]; + } + + /* nominator rows */ + correlate_tc( xn, &dd[L_IMPULSE2], gh, (short) (start2-L_IMPULSE2), L_SUBFR, (short)(end1-L_IMPULSE2) ); + } + + /*------------------------------------------------------* + * maxim. criterion + *------------------------------------------------------*/ + for( i=start1; i < end1; i++ ) + { + krit = (float)(dd[i]*dd[i])/rr[i]; + if( krit > krit_max ) + { + krit_max = krit; + *imp_pos = i; + *imp_shape = m; + } + } + } + + /*--------------------------------------------------------* + * Build the excitation using found codeword + *--------------------------------------------------------*/ + + set_f(exc, 0, L_SUBFR); + set_f(y1, 0, L_SUBFR); + for( i=(*imp_pos-L_IMPULSE2); i<=(*imp_pos+L_IMPULSE2); i++ ) + { + if( (i >= 0) && (i < L_SUBFR) ) + { + exc[i] = glottal_cdbk[(*imp_shape)*L_IMPULSE+i-(*imp_pos)+L_IMPULSE2]; + } + } + + /*------------------------------------------------------* + * Form filtered excitation, find gain_trans + *------------------------------------------------------*/ + + convolve_tc2( exc, h_orig, y1, *imp_pos ); + + /* Find the ACELP correlations and the pitch gain (for current subframe) */ + *gain_trans = dotp( xn, y1, L_SUBFR )/(dotp( y1, y1, L_SUBFR ) + 0.01f); + + return; + +} + +/*-------------------------------------------------------------------* + * convolve_tc: + * + * convolution for different vectors' lengths + *-------------------------------------------------------------------*/ +static void convolve_tc( + const float g[], /* i : input vector */ + const float h[], /* i : impulse response (or second input vector) */ + float y[], /* o : output vetor (result of convolution) */ + const short L_1, /* i : vector h size */ + const short L_2 /* i : vector g size */ +) +{ + float temp; + short i, n; + + + for( n = 0; n < L_2; n++ ) + { + temp = g[0] * h[n]; + for( i = 1; i < ((n L_SUBFR) + { + i_end = L_SUBFR; + } + for( n = i_start; n < L_SUBFR; n++ ) + { + temp = g[0] * h[n]; + i_end2 = ((n<=i_end) ? (n+1) : i_end); + for( i = 1; i < i_end2; i++ ) + { + temp += g[i] * h[n-i]; + } + y[n] = temp; + } + return; +} + +/*-------------------------------------------------------------------* + * correlate_tc: + * + * correlation for different vectors' lengths + *-------------------------------------------------------------------*/ +static void correlate_tc( + const float *x, /* i: target signal */ + float *y, /* o: correlation between x[] and h[] */ + const float *h, /* i: impulse response (of weighted synthesis filter) */ + const short start, /* i: index of iterest */ + const short L_1, /* i: vector size */ + const short L_2 /* i: index of interest */ +) +{ + short i, j; + float s; + + + for( i = start; i < L_2; i++ ) + { + s = 0.0f; + for( j = i; j < L_1; j++ ) + { + s += x[j]*h[j-i]; + } + y[i] = s; + } + + return; +} diff --git a/src/libs/libevs/lib_enc/set_impulse_fx.cpp b/src/libs/libevs/lib_enc/set_impulse_fx.cpp deleted file mode 100755 index 368b3984..00000000 --- a/src/libs/libevs/lib_enc/set_impulse_fx.cpp +++ /dev/null @@ -1,348 +0,0 @@ -/*==================================================================================== - EVS Codec 3GPP TS26.442 Apr 03, 2018. Version 12.11.0 / 13.6.0 / 14.2.0 - ====================================================================================*/ - -#include "cnst_fx.h" /* Common constants */ -#include "rom_com_fx.h" /* Static table prototypes */ -#include "prot_fx.h" /* Function prototypes */ -#include "stl.h" - -/*-----------------------------------------------------------------* - * Local constant - *-----------------------------------------------------------------*/ -#define INPOL 4 /* +- range in samples for impulse position searching */ - -/*-----------------------------------------------------------------* - * Local function prototype - *-----------------------------------------------------------------*/ -static void convolve_tc_fx(const Word16 g[],const Word16 h[],Word16 y[],const Word16 L_1,const Word16 L_2); -static void correlate_tc_fx(const Word16 *x, Word16 *y, const Word16 *h, const Word16 start, const Word16 L_1,const Word16 L_2); -static void convolve_tc2_fx(const Word16 g[],const Word16 h[], Word16 y[], const Word16 pos_max); - -/*---------------------------------------------------------------------------------------* - * Function set_impulse() for TC * - * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ * - * Builds glottal codebook contribution based on glotal impulses positions finding. * - * * - * Returns a position of the glotal impulse center and * - * a number of the glotal impulse shape. * - * * - * |----| |----| xn * - * imp_pos-> || | imp_shape-> | g1 | | * - * | | | | g2 | exc |---| y1 ---- | * - * | | |--------------| |---------| h |-------|gain|-------(-)---> xn2 * - * | || | gn | |---| ---- * - * |----| |----| * - * codebook excitation h_orig gain * - * * - * * - * nominator dd * * - * Searching criterion: maximize ------------- = ---- = ----------------- * - * denominator rr * - * * - * Notice: gain = gain_trans * gain_pit (computed in trans_enc() function) * - * * - *---------------------------------------------------------------------------------------*/ -void set_impulse_fx( - const Word16 xn_fx[], /* i : target signal */ - const Word16 h_orig_fx[], /* i : impulse response of weighted synthesis filter */ - Word16 exc_fx[], /* o : adaptive codebook excitation */ - Word16 yy1_fx[], /* o : filtered adaptive codebook excitation */ - Word16 *imp_shape, /* o : adaptive codebook index */ - Word16 *imp_pos, /* o : position of the glotal impulse center index */ - Word32 *gain_trans_fx, /* o : transition gain Q7 */ - Word16 Q_new /* i : Current scaling */ -) -{ - Word16 i, j, m; - Word16 start1, start2, end1; - Word32 rr_fx[L_SUBFR]; /* criterion: nominator coeficients */ - Word16 dd_fx[L_SUBFR],tmp16; /* criterion: denominator coeficients */ - Word16 gh_fx[L_SUBFR], num, den, exp_num, exp_den; /* convolution of 'g' and 'h' filters */ - Word16 krit_fx, krit_max_fx, gain16; - Word32 Lrr, Ldd, Ltmp,Ltmp1; - const Word16 *pt_Glt; - krit_max_fx = -32768; - move16(); - - /* main loop */ - /* impulse */ - FOR (m = 0; m < NUM_IMPULSE; m++) - { - /* set searching ranges */ - IF (sub(*imp_pos, L_SUBFR-INPOL) < 0) - { - end1 = add(*imp_pos, INPOL); - } - ELSE - { - end1 = L_SUBFR; - move16(); - } - IF (sub(*imp_pos, INPOL) > 0) - { - start1 = sub(*imp_pos, INPOL); - } - ELSE - { - start1 = 0; - move16(); - } - IF (sub(start1, L_IMPULSE2)>0) - { - start2 = start1; - move16(); - } - ELSE - { - start2 = L_IMPULSE2; - move16(); - } - - /*-----------------------------------------------------------* - * nominator & DEnominator, gh=convolve(g,h) - *-----------------------------------------------------------*/ - IF (sub(start1, L_IMPULSE2) <0 ) - { - Lrr = L_deposit_l(0); - Ldd = L_deposit_l(0); - convolve_tc_fx(&Glottal_cdbk_fx[m*L_IMPULSE+L_IMPULSE2-start1], - &h_orig_fx[0], gh_fx, add(L_IMPULSE-L_IMPULSE2, start1), L_SUBFR); - - /* nominator & DEnominator row <0> */ - FOR (i=0; i < L_SUBFR; i++) - { - Lrr = L_mac(Lrr, gh_fx[i], gh_fx[i]); - Ldd = L_mac(Ldd, gh_fx[i], xn_fx[i]); - } - rr_fx[start1] = Lrr; - move32(); - dd_fx[start1] = round_fx(Ldd); - rr_fx[start1] = L_max(rr_fx[start1], 1); - - FOR (i=add(start1, 1); i */ - FOR (j = L_SUBFR-1; j > 0; j--) - { - /* gh_fx[j] = gh_fx[j-1] + glottal_cdbk[m*L_IMPULSE+L_IMPULSE2-i]*h_orig_fx[j] */ - gh_fx[j] = mac_r(L_deposit_h(gh_fx[j-1]), - Glottal_cdbk_fx[m*L_IMPULSE+L_IMPULSE2-i], h_orig_fx[j]); - move16(); - Lrr = L_mac(Lrr, gh_fx[j], gh_fx[j]); - Ldd = L_mac(Ldd, gh_fx[j], xn_fx[j]); - } - - gh_fx[0] = mult_r(Glottal_cdbk_fx[m*L_IMPULSE+L_IMPULSE2-i],h_orig_fx[0]); - move16(); - Lrr = L_mac(Lrr, gh_fx[0], gh_fx[0]); - Ldd = L_mac(Ldd, gh_fx[0], xn_fx[0]); - dd_fx[i] = round_fx(Ldd); - rr_fx[i] = L_max(Lrr, 1); - move32(); - /* move rr and dd into rr[i] and dd[i] */ - } - - /* complete convolution(excitation,h_orig) */ - FOR (j=L_SUBFR-1; j > 0; j--) - { - gh_fx[j] = mac_r(L_deposit_h(gh_fx[j-1]), - Glottal_cdbk_fx[m*L_IMPULSE], h_orig_fx[j]); - } - } - ELSE - { - convolve_tc_fx(&Glottal_cdbk_fx[m*L_IMPULSE], h_orig_fx, gh_fx, L_IMPULSE, L_SUBFR); - } - - IF (sub(end1, start2) >= 0) - { - /* DEnominator row */ - Lrr = L_mult(gh_fx[0], gh_fx[0]); - FOR (j=1; j <= L_IMPULSE2; j++) - { - /*rr[L_SUBFR-1] += gh[j]*gh[j];*/ - Lrr = L_mac(Lrr, gh_fx[j], gh_fx[j]); - } - rr_fx[L_SUBFR-1] = Lrr; - move32(); - /* DEnominator rows */ - FOR (i = L_SUBFR-2; i >= start2; i--) - { - /*rr[i] = rr[i+1] + gh[L_SUBFR+L_IMPULSE2-1-i]*gh[L_SUBFR+L_IMPULSE2-1-i];*/ - rr_fx[i] = L_mac(rr_fx[i+1], gh_fx[L_SUBFR+L_IMPULSE2-1-i], - gh_fx[L_SUBFR+L_IMPULSE2-1-i]); - move32(); - } - /* nominator rows */ - correlate_tc_fx(xn_fx, &dd_fx[L_IMPULSE2], gh_fx, sub(start2, L_IMPULSE2), - L_SUBFR, sub(end1, L_IMPULSE2)); - } - /*------------------------------------------------------------* - * maxim. criterion - *------------------------------------------------------------*/ - FOR (i = start1; i < end1; i++) - { - /* krit = (float)(dd[i]*dd[i])/rr[i] */ - exp_num = sub(norm_s(dd_fx[i]), 1); - num = shl(dd_fx[i], exp_num); - num = mult_r(num, num); - - exp_den = norm_l(rr_fx[i]); - den = extract_h(L_shl(rr_fx[i], exp_den)); - - num = div_s(num,den); - krit_fx = shr(num, sub(sub(shl(exp_num, 1), exp_den), 2)); /* Q18 */ - - IF (sub(krit_fx, krit_max_fx) > 0) - { - krit_max_fx = krit_fx; - move16(); - *imp_pos = i; - move16(); - *imp_shape = m; - move16(); - } - } - } - - /*---------------------------------------------------------------* - * Build the excitation using found codeword - *---------------------------------------------------------------*/ - - set16_fx(exc_fx, 0, L_SUBFR); - set16_fx(yy1_fx, 0, L_SUBFR); - tmp16 = sub(extract_l(L_mac0(L_IMPULSE2, *imp_shape, L_IMPULSE)), *imp_pos); - pt_Glt = &Glottal_cdbk_fx[tmp16]; - move16(); - j = add(*imp_pos, L_IMPULSE2); - FOR (i = sub(*imp_pos, L_IMPULSE2); i <= j; i++) - { - test(); - if (i >= 0 && sub(i, L_SUBFR) < 0) - { - exc_fx[i] = pt_Glt[i]; - move16();/*Q13*/ - } - } - - /*---------------------------------------------------------------* - * Form filtered excitation, find gain_trans - *---------------------------------------------------------------*/ - convolve_tc2_fx(exc_fx, h_orig_fx, yy1_fx, *imp_pos); - - /* Find the ACELP correlations and the pitch gain (for current subframe) */ - /**gain_trans = dot_product( xn, yy1, L_SUBFR )/(dot_product( yy1, yy1, L_SUBFR ) + 0.01f);*/ - /* Compute scalar product */ - Ltmp = Dot_product(yy1_fx, yy1_fx, L_SUBFR); - exp_den = norm_l(Ltmp); - den = extract_h(L_shl(Ltmp, exp_den)); - - /* Compute scalar product */ - Ltmp1 = Dot_product(xn_fx, yy1_fx, L_SUBFR); - exp_num = sub(norm_l(Ltmp1), 1); - num = extract_h(L_shl(Ltmp1, exp_num)); - tmp16 = s_or(shr(num, 16), 1); /* extract sign if num < 0 tmp16 = -1 else tmp16 = 1 */ - num = abs_s(num); - - /* compute gain = xy/yy */ - gain16= div_s(num, den); - - i = add(exp_num, sub(Q_new, 1+1+3)); - i = sub(i, exp_den); /* Gain_trans in Q7 */ - gain16 = i_mult2(gain16, tmp16);/* apply sign */ - *gain_trans_fx = L_shr(L_deposit_l(gain16), i); - move32(); - -} -/*-------------------------------------------------------------------* - * convolve_tc_fx: - * - * convolution for different vectors' lengths - *-------------------------------------------------------------------*/ -static void convolve_tc_fx( - const Word16 g[], /* i : input vector Qx */ - const Word16 h[], /* i : impulse response (or second input vector) Q15 */ - Word16 y[], /* o : output vetor (result of convolution) 12 bits */ - const Word16 L_1, /* i : vector h size */ - const Word16 L_2 /* i : vector g size */ -) -{ - Word16 i, n, len; - Word32 L_sum; - - FOR (n = 0; n < L_2; n++) - { - len = s_min(add(n,1), L_1); - L_sum = L_mult(g[0], h[n]); - FOR (i = 1; i < len; i++) - { - L_sum = L_mac(L_sum, g[i], h[n - i]); - } - - y[n] = round_fx(L_sum); /* Q12*/ - } -} -/*-------------------------------------------------------------------* - * convolve_tc2_fx: - * - * convolution for one vector with only L_IMPULSE nonzero coefficients - *-------------------------------------------------------------------*/ -static void convolve_tc2_fx( - const Word16 g[], /* i : input vector Qx */ - const Word16 h[], /* i : impulse response (or second input vector) Q15 */ - Word16 y[], /* o : output vetor (result of convolution) 12 bits */ - const Word16 pos_max /* o : artificial impulse position */ -) -{ - Word32 temp; - Word16 i, n; - Word16 i_start, i_end, i_end2; - - i_start = sub(pos_max,L_IMPULSE2); - i_start = s_max(i_start, 0); - - i_end = add(pos_max, L_IMPULSE); - i_end = s_min(i_end, L_SUBFR); - - FOR (n = i_start; n < L_SUBFR; n++) - { - temp = L_mult(g[0], h[n]); - i_end2 = s_min(add(n, 1), i_end); - - FOR (i = 1; i < i_end2; i++) - { - temp = L_mac(temp, g[i], h[n-i]); - } - y[n] = round_fx(temp); - } -} -/*-------------------------------------------------------------------* - * correlate_tc: - * - * correlation for different vectors' lengths - *-------------------------------------------------------------------*/ -static void correlate_tc_fx( - const Word16 *x, /* i: target signal */ - Word16 *y, /* o: correlation between x[] and h[] -Q3 */ - const Word16 *h, /* i: impulse response (of weighted synthesis filter) */ - const Word16 start, /* i: index of iterest */ - const Word16 L_1, /* i: vector size */ - const Word16 L_2 /* i: index of interest */ -) -{ - Word16 i, j; - Word32 s; - - FOR (i = start; i < L_2; i++) - { - s = L_deposit_l(0); - FOR (j = i; j < L_1; j++) - { - s = L_mac(s, x[j],h[j-i]); - } - y[i] = round_fx(s); - } -} diff --git a/src/libs/libevs/lib_enc/setmodeindex.cpp b/src/libs/libevs/lib_enc/setmodeindex.cpp old mode 100755 new mode 100644 index b87f15c3..afa1de30 --- a/src/libs/libevs/lib_enc/setmodeindex.cpp +++ b/src/libs/libevs/lib_enc/setmodeindex.cpp @@ -1,18 +1,17 @@ /*==================================================================================== - EVS Codec 3GPP TS26.442 Apr 03, 2018. Version 12.11.0 / 13.6.0 / 14.2.0 + EVS Codec 3GPP TS26.443 Nov 13, 2018. Version 12.11.0 / 13.7.0 / 14.3.0 / 15.1.0 ====================================================================================*/ #include #include #include #include - #include "options.h" -#include "stl.h" -#include "prot_fx.h" -#include "cnst_fx.h" -#include "rom_com_fx.h" -#include "rom_enc_fx.h" +#include "prot.h" +#include "cnst.h" +#include "rom_com.h" +#include "rom_enc.h" + /*--------------------------------------------------------------------------- @@ -25,24 +24,15 @@ ---------------------------------------------------------------------------*/ void SetModeIndex( - Encoder_State_fx *st, - Word32 total_brate, - Word16 bwidth, - const Word16 shift) + Encoder_State *st, + const long total_brate, + const short bwidth) { /* Reconfigure the core coder */ - test(); - test(); - test(); - IF( - (L_sub(st->last_total_brate_fx,total_brate) != 0) || - (sub(st->last_bwidth_fx,bwidth) != 0) || - (sub(st->last_codec_mode,MODE1) == 0 ) - || (sub(st->rf_mode_last,st->rf_mode) != 0 ) - ) + if( (st->last_total_brate != total_brate) || (st->last_bwidth != bwidth) || (st->last_codec_mode == MODE1) || (st->rf_mode_last != st->rf_mode) ) { - core_coder_mode_switch( st, st->bwidth_fx, total_brate, shift); + core_coder_mode_switch( st, st->bwidth, total_brate ); } diff --git a/src/libs/libevs/lib_enc/sig_clas.cpp b/src/libs/libevs/lib_enc/sig_clas.cpp old mode 100755 new mode 100644 index a950a843..348fe8d2 --- a/src/libs/libevs/lib_enc/sig_clas.cpp +++ b/src/libs/libevs/lib_enc/sig_clas.cpp @@ -1,64 +1,54 @@ /*==================================================================================== - EVS Codec 3GPP TS26.442 Apr 03, 2018. Version 12.11.0 / 13.6.0 / 14.2.0 + EVS Codec 3GPP TS26.443 Nov 13, 2018. Version 12.11.0 / 13.7.0 / 14.3.0 / 15.1.0 ====================================================================================*/ #include -#include "options.h" /* Compilation switches */ -#include "cnst_fx.h" /* Common constants */ -#include "prot_fx.h" /* Function prototypes */ -#include "stl.h" +#include +#include "options.h" +#include "cnst.h" +#include "prot.h" /*---------------------------------------------------------------------* * Local constants *---------------------------------------------------------------------*/ -#define K_COR_FX 23405 /* Q13 2.857 */ -#define C_COR_FX -10535 /* Q13 -1.286 */ - -#define K_EE_FX 1365 /* Q15 0.04167 */ -#define C_EE_FX 0 - -#define K_ZC_FX -1311 /* Q15 -0.04 */ -#define C_ZC_FX 19661 /* Q13 2.4 */ - -#define K_RELE_FX 1638 /* Q15 0.05 */ -#define C_RELE_FX 14746 /* Q15 0.45 */ - -#define K_PC_FX -2341 /* Q15 -0.07143*/ -#define C_PC_FX 30425 /* Q1 1.857 */ - -#define K_SNR_FX 3541 /* Q15 .1111 */ -#define C_SNR_FX -10921 /* Q15 -0.3333f */ - - -#define THRES_EEN 514206 /* 251.077 => (10^(1/(K_EE*10))) Q11*/ +#define K_COR_ENC 2.857f +#define C_COR_ENC -1.286f +#define K_EE_ENC 0.04167f +#define C_EE_ENC 0.0f +#define K_ZC_ENC -0.04f +#define C_ZC_ENC 2.4f +#define K_RELE_ENC 0.05f +#define C_RELE_ENC 0.45f +#define K_PC_ENC -0.07143f +#define C_PC_ENC 1.857f +#define K_SNR_ENC 0.1111f +#define C_SNR_ENC -0.3333f /*-------------------------------------------------------------------* - * signal_clas_fx() + * signal_clas() * - * classification state machine for FEC - * TC frames selection + * Classification state machine for FEC + * Coder type modification *-------------------------------------------------------------------*/ -Word16 signal_clas_fx( /* o : classification for current frames */ - Encoder_State_fx *st, /* i/o: encoder state structure */ - Word16 *coder_type, /* i/o: coder type */ - const Word16 voicing[3], /* i : normalized correlation for 3 half-frames */ - const Word16 *speech, /* i : pointer to speech signal for E computation */ - const Word16 localVAD, /* i : vad without hangover */ - const Word16 pit[3], /* i : open loop pitch values for 3 half-frames */ - const Word32 *ee, /* i : lf/hf E ration for 2 half-frames */ - const Word16 relE, /* i : frame relative E to the long term average */ - const Word16 L_look , /* i : look-ahead */ - Word16 *uc_clas /* o : temporary classification used in music/speech class*/ +short signal_clas( /* o : classification for current frames */ + Encoder_State *st, /* i/o: encoder state structure */ + short *coder_type, /* i/o: coder type */ + const float voicing[3], /* i : normalized correlation for 3 half-frames */ + const float *speech, /* i : pointer to speech signal for E computation */ + const short localVAD, /* i : vad without hangover */ + const short pit[3], /* i : open loop pitch values for 3 half-frames */ + const float *ee, /* i : lf/hf E ration for 2 half-frames */ + const float relE, /* i : frame relative E to the long term average */ + const short L_look, /* i : look-ahead */ + short *uc_clas /* o : flag for unvoiced class used in sp/mus classifier */ ) { - Word32 Ltmp; - Word16 mean_voi2, een, corn, zcn, relEn, pcn, fmerit1; - Word16 i, clas, pc, zc, lo, lo2, hi, hi2, exp_ee, frac_ee; - Word16 tmp16, tmpS; - const Word16 *pt1; - Word16 unmod_coder_type; + float mean_voi2, mean_ee2, tmp; + float een, corn, zcn, relEn, pcn, fmerit1; + short i, clas, pc, zc; + short unmod_coder_type; /*----------------------------------------------------------------* * Calculate average voicing @@ -67,92 +57,87 @@ Word16 signal_clas_fx( /* o : classification for current frames * Calculate pitch stability *----------------------------------------------------------------*/ - /* average voicing on second half-frame and look-ahead */ - Ltmp = L_mult(voicing[1], 16384); - mean_voi2 = mac_r(Ltmp, voicing[2], 16384); + /* average voicing on second half-frame and look-ahead */ + mean_voi2 = 0.5f * (voicing[1] + voicing[2]); /* average spectral tilt in dB */ - lo = L_Extract_lc(ee[0], &hi); - lo2 = L_Extract_lc(ee[1], &hi2); - Ltmp = L_mult(lo, lo2); /* Q5*Q5->Q11 */ + tmp = ee[0] * ee[1]; + if( tmp < 1.0f ) + { + tmp = 1.0f; + } - test(); - test(); - IF (L_sub(Ltmp, 2048) < 0) - { - een = 0; - move16(); - } - ELSE IF (L_sub(Ltmp, THRES_EEN) > 0 || hi > 0 || hi2 > 0) - { - een = 512; - move16(); - } - ELSE - { - /* mean_ee2 = 0.5f * 20.0f * (float)log10( tmp ); */ - /* een = K_EE_ENC * mean_ee2 + C_EE_ENC; */ - exp_ee = norm_l(Ltmp); - frac_ee = Log2_norm_lc(L_shl(Ltmp, exp_ee)); - exp_ee = sub(30-11, exp_ee); - Ltmp = Mpy_32_16(exp_ee, frac_ee, LG10); /* Ltmp Q14 */ - een = round_fx(L_shl(Ltmp, 16-5)); /* Q14 -> Q9 */ - een = mac_r(C_EE_FX, een, K_EE_FX); - } + mean_ee2 = 0.5f * 20.0f * (float)log10( tmp ); /* compute zero crossing rate */ - pt1 = speech + L_look - 1; - tmpS = shr(*pt1, 15); /* sets 'tmpS to -1 if *pt1 < 0 */ - Ltmp = L_deposit_l(0); - FOR (i = 0; i < L_FRAME; i++) + zc = 0; + for( i = L_look; i < L_FRAME + L_look; i++ ) { - tmp16 = add(1, tmpS); - pt1++; - tmpS = shr(*pt1, 15); /* pt1 >=0 ---> 0 OTHERWISE -1 */ - Ltmp = L_msu0(Ltmp, tmpS, tmp16); + if( speech[i] <= 0.0f && speech[i-1] > 0.0f ) + { + zc++; + } } - zc = extract_l(Ltmp); /* compute pitch stability */ - pc = add( abs_s(sub(pit[1], pit[0])), abs_s(sub(pit[2], pit[1]))); + pc = (short)(abs(pit[1] - pit[0]) + abs(pit[2] - pit[1])); /*-----------------------------------------------------------------* * Transform parameters to the range <0:1> * Compute the merit function *-----------------------------------------------------------------*/ - /* corn = K_COR * mean_voi2 + C_COR */ - Ltmp = L_mult(C_COR_FX, 32767); - corn = round_fx(L_shl(L_mac(Ltmp, mean_voi2, K_COR_FX),-4)); /*Q13+Q13*Q15 =>Q13->Q9*/ - /* Limit [0, 1] */ - corn = s_max(corn, 0); - corn = s_min(corn, 512); + een = K_EE_ENC * mean_ee2 + C_EE_ENC; + if( een > 1.0f ) + { + een = 1.0f; + } + else if( een < 0.0f ) + { + een = 0.0f; + } - Ltmp = L_mult(C_ZC_FX, 4); /*Q13*Q2 -> Q16*/ - zcn = round_fx(L_shl(L_mac(Ltmp, zc, K_ZC_FX),16-7)); /*Q0*Q15 + Q16*/ - /* Limit [0, 1] */ - zcn = s_max(zcn, 0); - zcn = s_min(zcn, 512); + corn = K_COR_ENC * mean_voi2 + C_COR_ENC; + if( corn > 1.0f ) + { + corn = 1.0f; + } + else if( corn < 0.0f ) + { + corn = 0.0f; + } - Ltmp = L_mult(C_RELE_FX, 256); /*Q15 ->Q24*/ - relEn = round_fx(L_shl(L_mac(Ltmp, relE, K_RELE_FX), 1)); /*relE in Q8 but relEn in Q9*/ - /* Limit [0.5, 1] */ - relEn = s_max(relEn, 256); - relEn = s_min(relEn, 512); + zcn = K_ZC_ENC * zc + C_ZC_ENC; + if( zcn > 1.0f ) + { + zcn = 1.0f; + } + else if( zcn < 0.0f ) + { + zcn = 0.0f; + } - Ltmp = L_mult(C_PC_FX, 2); /*Q14*Q1 -> Q16*/ - pcn = round_fx(L_shl(L_mac(Ltmp, pc, K_PC_FX),16-7)); /*Q16 + Q0*Q15*/ - /* Limit [0, 1] */ - pcn = s_max(pcn, 0); - pcn = s_min(pcn, 512); + relEn = K_RELE_ENC * relE + C_RELE_ENC; + if( relEn > 1.0f ) + { + relEn = 1.0f; + } + else if( relEn < 0.5f ) + { + relEn = 0.5f; + } - Ltmp = L_mult(een, 10923); - Ltmp = L_mac(Ltmp, corn, 21845); - Ltmp = L_mac(Ltmp, zcn, 10923); - Ltmp = L_mac(Ltmp, relEn, 10923); - Ltmp = L_mac(Ltmp, pcn, 10923); + pcn = K_PC_ENC * pc + C_PC_ENC; + if( pcn > 1.0f ) + { + pcn = 1.0f; + } + else if( pcn < 0.0f ) + { + pcn = 0.0f; + } - fmerit1 = round_fx(L_shl(Ltmp, 16-10-1)); /* fmerit1 ->Q15 */ + fmerit1 = (1.0f/6.0f) * (een + 2.0f*corn + zcn + relEn + pcn); /*-----------------------------------------------------------------* * FEC classification @@ -161,82 +146,64 @@ Word16 signal_clas_fx( /* o : classification for current frames /* FEC classification */ - test(); - test(); - IF (localVAD == 0 || sub(*coder_type,UNVOICED) == 0 || sub(relE,-1536) < 0) + if( localVAD == 0 || *coder_type == UNVOICED || relE < -6.0f ) { clas = UNVOICED_CLAS; - move16(); } - ELSE + else { - SWITCH (st->last_clas_fx) + switch( st->last_clas ) { case VOICED_CLAS: case ONSET: case VOICED_TRANSITION: - - IF (sub(fmerit1, 16056) < 0) /*0.49f*/ + if( fmerit1 < 0.49f ) { clas = UNVOICED_CLAS; - move16(); } - ELSE IF (sub(fmerit1, 21626) < 0) /*0.66*/ + else if( fmerit1 < 0.66f ) { clas = VOICED_TRANSITION; - move16(); } - ELSE + else { clas = VOICED_CLAS; - move16(); } - BREAK; + + break; case UNVOICED_CLAS: case UNVOICED_TRANSITION: - IF (sub(fmerit1, 20643) > 0) /*0.63*/ + if( fmerit1 > 0.63f ) { clas = ONSET; - move16(); } - ELSE IF (sub(fmerit1, 19169) > 0) /*0.585*/ + else if( fmerit1 > 0.585f ) { clas = UNVOICED_TRANSITION; - move16(); } - ELSE + else { clas = UNVOICED_CLAS; - move16(); } - BREAK; + + break; default: clas = UNVOICED_CLAS; - move16(); - BREAK; + + break; } } /* set flag for unvoiced class, it will be used in sp/mus classifier */ *uc_clas = clas; - move16(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - if( ( (sub(*coder_type,UNVOICED) == 0) || - (sub(st->input_bwidth_fx,NB) != 0 && sub(fmerit1,13435) < 0 && sub(st->mold_corr_fx,21299) > 0 ) || /* WB case */ - (sub(st->input_bwidth_fx,NB) == 0 && sub(mult_r(fmerit1,28836),13435) < 0 && sub(st->mold_corr_fx,18022) > 0 ) ) && /* NB case */ - sub(relE,-3840) > 0 && sub(st->lt_dec_thres_fx,768) < 0 ) /* to compute unvoiced on frame that tends to speech */ + if( ( ( *coder_type == UNVOICED ) || + ( st->input_bwidth != NB && fmerit1 < 0.41f && st->mold_corr > 0.65f ) || /* WB case */ + ( st->input_bwidth == NB && fmerit1 * 0.88f < 0.41f && st->mold_corr > 0.55f ) ) && /* NB case */ + relE > -15.0f && st->lt_dec_thres < 1.5f ) { - *uc_clas = UNVOICED_CLAS; - move16(); + *uc_clas = UNVOICED_CLAS; } /* Onset classification */ @@ -246,26 +213,22 @@ Word16 signal_clas_fx( /* o : classification for current frames /* tc_cnt == 1: onset/transition frame, coded by GC mode */ /* tc_cnt == 2: frame after onset/transition frame, coded by TC mode */ - if( sub(clas,UNVOICED_CLAS ) == 0) + if( clas == UNVOICED_CLAS ) { - st->tc_cnt_fx = 0; - move16(); + st->tc_cnt = 0; } - test(); - if( sub(clas,VOICED_TRANSITION) >= 0 && st->tc_cnt_fx >= 0 ) + if( clas >= VOICED_TRANSITION && st->tc_cnt >= 0 ) { - st->tc_cnt_fx = add(st->tc_cnt_fx,1); - move16(); + st->tc_cnt += 1; } - if( sub(st->tc_cnt_fx,2) > 0 ) + if( st->tc_cnt > 2 ) { - st->tc_cnt_fx = -1; - move16(); + st->tc_cnt = -1; } - IF ( sub(st->codec_mode,MODE1) == 0 ) + if ( st->codec_mode == MODE1 ) { /*---------------------------------------------------------------------* * Coder type modification @@ -276,101 +239,71 @@ Word16 signal_clas_fx( /* o : classification for current frames *---------------------------------------------------------------------*/ /* At higher rates, use GC coding instead of UC coding to improve quality */ - test(); - if( L_sub(st->total_brate_fx,ACELP_9k60) > 0 && sub(*coder_type,UNVOICED) == 0 ) + if( st->total_brate > ACELP_9k60 && *coder_type == UNVOICED ) { *coder_type = GENERIC; - move16(); } /* Prevent UC coding on mixed content at 9.6 kb/s */ - test(); - test(); - if( L_sub(st->total_brate_fx,ACELP_9k60) == 0 && sub(*coder_type,UNVOICED) == 0 && st->audio_frame_cnt_fx != 0 ) + if( st->total_brate == ACELP_9k60 && *coder_type == UNVOICED && st->audio_frame_cnt != 0 ) { *coder_type = GENERIC; - move16(); } unmod_coder_type = *coder_type; - move16(); /* Enforce GC mode on inactive signal (this can be later overwritten to INACTIVE) */ - test(); - test(); - test(); - test(); - test(); - test(); - test(); - if( localVAD == 0 && ( - ( - sub(*coder_type,UNVOICED) == 0 - && ( ( st->Opt_SC_VBR_fx == 0) || ( ( st->Opt_SC_VBR_fx == 1 ) && st->vbr_generic_ho_fx == 0 && sub(st->last_coder_type_fx,UNVOICED) > 0 )) ) - || sub(*coder_type,TRANSITION) == 0 || sub(*coder_type,VOICED) == 0 ) - + if( localVAD == 0 && ( (*coder_type == UNVOICED && (!st->Opt_SC_VBR || + ( st->Opt_SC_VBR && st->vbr_generic_ho == 0 && st->last_coder_type > UNVOICED )) ) + || *coder_type == TRANSITION || *coder_type == VOICED ) ) { *coder_type = GENERIC; - move16(); + } + if( *coder_type == GENERIC && unmod_coder_type == UNVOICED && st->Opt_SC_VBR ) + { + st->vbr_generic_ho = 1; } - test(); - test(); - if( sub(*coder_type,GENERIC) == 0 && sub(unmod_coder_type,UNVOICED) == 0 && ( st->Opt_SC_VBR_fx == 1 ) ) + if ( *coder_type > UNVOICED && st->Opt_SC_VBR ) { - st->vbr_generic_ho_fx = 1; - move16(); + st->vbr_generic_ho = 0; } - test(); - if ( sub(*coder_type,UNVOICED) > 0 && ( st->Opt_SC_VBR_fx == 1 ) ) + if( localVAD == 0 && *coder_type == UNVOICED ) { - st->vbr_generic_ho_fx = 0; - move16(); + st->last_7k2_coder_type = GENERIC; + } + else + { + st->last_7k2_coder_type = *coder_type; } - st->last_7k2_coder_type_fx = *coder_type; - move16(); - test(); - if( localVAD == 0 && sub( *coder_type, UNVOICED ) == 0 ) + /* Select TC mode for appropriate frames which is in general MODE1_VOICED_TRANSITION, VOICED_CLAS or MODE1_ONSET frames following UNVOICED_CLAS frames */ + if( localVAD != 0 && st->tc_cnt >= 1 ) { - st->last_7k2_coder_type_fx = GENERIC; - move16(); - } - - /* Select TC mode for appropriate frames which is in general VOICED_TRANSITION, VOICED_CLAS or MODE1_ONSET frames following UNVOICED_CLAS frames */ - test(); - IF( localVAD != 0 && sub(st->tc_cnt_fx,1) >= 0 ) /* TC mode is allowed only in active signal */ - { - /* frame after onset/transition frame is coded by TC mode */ - *coder_type = TRANSITION; - move16(); - if ( sub(st->tc_cnt_fx,1) == 0 ) + if ( st->tc_cnt == 1 ) { /* onset/transition frame is always coded using GC mode */ *coder_type = GENERIC; - move16(); + } + else + { + /* frame after onset/transition frame is coded by TC mode */ + *coder_type = TRANSITION; } } /* At higher rates and with 16kHz core, allow only GC and TC mode */ - test(); - test(); - if( (L_sub(st->total_brate_fx,ACELP_24k40) >= 0) && sub(*coder_type,GENERIC) != 0 && sub(*coder_type,TRANSITION) != 0 ) + if( st->total_brate >= ACELP_24k40 && *coder_type != GENERIC && *coder_type != TRANSITION ) { *coder_type = GENERIC; - move16(); } /* Patch for certain low-level signals for which the gain quantizer sometimes goes out of its dynamic range */ - test(); - test(); - test(); - if( sub(*coder_type,VOICED) == 0 && sub(st->input_bwidth_fx,NB) == 0 && sub(relE,-2560) < 0 && L_sub(st->total_brate_fx,ACELP_8k00) <= 0 ) + if( *coder_type == VOICED && st->input_bwidth == NB && relE < -10.0f && st->total_brate <= ACELP_8k00 ) { *coder_type = GENERIC; - move16(); } } diff --git a/src/libs/libevs/lib_enc/spec_center.cpp b/src/libs/libevs/lib_enc/spec_center.cpp old mode 100755 new mode 100644 index aa23f1cf..79fe75be --- a/src/libs/libevs/lib_enc/spec_center.cpp +++ b/src/libs/libevs/lib_enc/spec_center.cpp @@ -1,311 +1,61 @@ /*==================================================================================== - EVS Codec 3GPP TS26.442 Apr 03, 2018. Version 12.11.0 / 13.6.0 / 14.2.0 + EVS Codec 3GPP TS26.443 Nov 13, 2018. Version 12.11.0 / 13.7.0 / 14.3.0 / 15.1.0 ====================================================================================*/ -#include "basop_util.h" -#include "stl.h" -#include "vad_basop.h" -#include "prot_fx.h" -#include "rom_enc_fx.h" +#include "prot.h" +#include "rom_enc.h" +#include "cnst.h" +/*-------------------------------------------------------------------* + * spec_center() + * + * + *-------------------------------------------------------------------*/ -void spec_center(Word32* sb_power, /*(i) energy of sub-band divided uniformly*/ - Word16* sp_center, /*(o) spectral center*/ - Word32 bandwith, /*(i) band width*/ - Word16 Q_sb_p /*(i) the Scaling of sb_power*/ - ) +void spec_center( + float spec_power[], /*(i) energy of sub-band divided uniformly*/ + float sp_center[], /*(o) spectral centroid*/ + int bandwidth /*(i) band width*/ +) { - Word16 i; + int i; + float t_sp_center,frame_power; - Word32 t_sp_center, frame_power; - Word32 t_sp_center_num, frame_power_den; - Word32 sb_power_mlt; - Word32 t_sp_center_nb, frame_power_nb; - Word32 zerop1; - Word32 sb_power_shr[24]; + short sp_center_band_num = SP_CENTER_BAND_NUM_TAB[bandwidth]; + float sp_center_mem; - Word16 d_t_sp_center; - Word16 Q_t_sp_center, Q_frame_power; - Word16 Q_t_sc,Q_f_p; - Word16 d_t_sp_center_Qtmp; + t_sp_center = 0; + frame_power = 0; - - zerop1 = L_add(0, 0); - t_sp_center = L_add(0, 0); - frame_power = L_add(0, 0); - - FOR (i=0; i<10; i++) + for(i=1; i=0) - { - t_sp_center = L_shr(t_sp_center,sub(Q_t_sc, 33)); - zerop1 = L_shr(CNT0P1,1); - Q_t_sc = 33; - move16(); - } - ELSE - { - Q_t_sc = sub(Q_t_sc, 1); - t_sp_center = L_shr(t_sp_center,1); - zerop1 = L_shr(CNT0P1, sub(34, Q_t_sc)); - } - t_sp_center_num = L_add(t_sp_center, zerop1); - - Q_f_p = sub(Q_sb_p, 5); - IF (sub(Q_f_p,34)>=0) - { - frame_power = L_shr(frame_power,sub(Q_f_p, 33)); - zerop1 = L_shr(CNT0P1,1); - Q_f_p = 33; - move16(); - } - ELSE - { - Q_f_p = sub(Q_f_p, 1); - frame_power = L_shr(frame_power,1); - zerop1 = L_shr(CNT0P1, sub(34, Q_f_p)); - } - - frame_power_den = L_add(frame_power, zerop1); - IF (frame_power == 0) - { - frame_power_den = L_add(CNT0P1, 0); - Q_f_p = 34; - move16(); - } - /*div */ - Q_t_sp_center = sub(norm_l(t_sp_center_num), 1); - Q_frame_power = norm_l(frame_power_den); - t_sp_center_num = L_shl(t_sp_center_num,Q_t_sp_center); - frame_power_den = L_shl(frame_power_den,Q_frame_power); - - d_t_sp_center = div_l(t_sp_center_num,extract_h(frame_power_den)); - - d_t_sp_center_Qtmp = add(Q_t_sc,Q_t_sp_center); - d_t_sp_center_Qtmp = sub(d_t_sp_center_Qtmp,Q_frame_power); - d_t_sp_center_Qtmp = sub(d_t_sp_center_Qtmp,Q_f_p); - d_t_sp_center_Qtmp = add(d_t_sp_center_Qtmp,15); - d_t_sp_center_Qtmp = sub(d_t_sp_center_Qtmp,SP_CENTER_Q); - - d_t_sp_center = shr(d_t_sp_center,d_t_sp_center_Qtmp); - sp_center[0] = add(mult(sp_center[0],0x5999),mult(d_t_sp_center,0x2666)); - move16(); - sp_center[2] = d_t_sp_center; - move16(); - - t_sp_center = L_add(0, 0); - frame_power = L_add(0, 0); - IF(L_sub(bandwith,CLDFBVAD_WB_ID)==0) - { - FOR (i=10; i<20; i++) - { - sb_power_shr[i] = L_shr(sb_power[i],5); - move32(); - } - - FOR(i=1; i<20; i++) - { - sb_power_mlt = Mpy_32_16_1(sb_power[i],i_t_2[i-1]); - t_sp_center = L_add(L_shr(sb_power_mlt,8), t_sp_center); - frame_power = L_add(sb_power_shr[i], frame_power);/*1-19 */ - } - /*+0.1 */ - Q_t_sc = sub(Q_sb_p, 13); - - IF (sub(Q_t_sc, 34) >= 0) - { - t_sp_center = L_shr(t_sp_center,sub(Q_t_sc, 33)); - zerop1 = L_shr(CNT0P1,1); - Q_t_sc = 33; - move16(); - } - ELSE - { - Q_t_sc = sub(Q_t_sc, 1); - t_sp_center = L_shr(t_sp_center,1); - zerop1 = L_shr(CNT0P1, s_min(31, sub(34, Q_t_sc))); - } - t_sp_center_num = L_add(t_sp_center, zerop1); - - Q_f_p = sub(Q_sb_p, 5); - IF (sub(Q_f_p,34)>=0) - { - frame_power = L_shr(frame_power, sub(Q_f_p, 33)); - zerop1 = L_shr(CNT0P1,1); - Q_f_p = 33; - move16(); - } - ELSE - { - Q_f_p = sub(Q_f_p, 1); - frame_power = L_shr(frame_power,1); - zerop1 = L_shr(CNT0P1, sub(34, Q_f_p)); - } - frame_power_den = L_add(frame_power, zerop1); - IF (frame_power == 0) - { - frame_power_den = L_add(0, CNT0P1); - Q_f_p = 34; - move16(); - } - - /*div */ - Q_t_sp_center = sub(norm_l(t_sp_center_num), 1); - Q_frame_power = norm_l(frame_power_den); - t_sp_center_num = L_shl(t_sp_center_num,Q_t_sp_center); - frame_power_den = L_shl(frame_power_den,Q_frame_power); - - d_t_sp_center = div_l(t_sp_center_num,extract_h(frame_power_den)); - - d_t_sp_center_Qtmp = add(Q_t_sc,Q_t_sp_center); - d_t_sp_center_Qtmp = sub(d_t_sp_center_Qtmp,Q_frame_power); - d_t_sp_center_Qtmp = sub(d_t_sp_center_Qtmp,Q_f_p); - d_t_sp_center_Qtmp = add(d_t_sp_center_Qtmp,15); - d_t_sp_center_Qtmp = sub(d_t_sp_center_Qtmp,SP_CENTER_Q); - - sp_center[3]= shr(d_t_sp_center,d_t_sp_center_Qtmp); - move16(); - } - ELSE IF(L_sub(bandwith, CLDFBVAD_SWB_ID)==0) - { - FOR (i=10; i<24; i++) - { - sb_power_shr[i] = L_shr(sb_power[i],5); - move32(); - } - - FOR(i=1; i<24; i++) - { - sb_power_mlt = Mpy_32_16_1(sb_power[i],i_t_2[i-1]); - t_sp_center = L_add(L_shr(sb_power_mlt,9), t_sp_center); - frame_power = L_add(sb_power_shr[i], frame_power);/*1-23 */ - } - - /*+0.1 */ - Q_t_sc = sub(Q_sb_p, 14); - - IF (sub(Q_t_sc,34)>=0) - { - t_sp_center = L_shr(t_sp_center, limitScale32(sub(Q_t_sc, 33))); - zerop1 = L_shr(CNT0P1,1); - Q_t_sc = 33; - move16(); - } - ELSE - { - Q_t_sc = sub(Q_t_sc, 1); - t_sp_center = L_shr(t_sp_center,1); - zerop1 = L_shr(CNT0P1, limitScale32(sub(34, Q_t_sc))); - } - t_sp_center_num = L_add(t_sp_center, zerop1); - - Q_f_p = sub(Q_sb_p, 5); - IF (sub(Q_f_p,34)>=0) - { - frame_power = L_shr(frame_power,sub(Q_f_p, 33)); - zerop1 = L_shr(CNT0P1,1); - Q_f_p = 33; - move16(); - } - ELSE - { - Q_f_p = sub(Q_f_p, 1); - frame_power = L_shr(frame_power,1); - zerop1 = L_shr(CNT0P1, sub(34, Q_f_p)); - } - frame_power_den = L_add(frame_power, zerop1); - IF (frame_power == 0) - { - frame_power_den = L_add(0, CNT0P1); - Q_f_p = 34; - move16(); - } - - /*div*/ - Q_t_sp_center=sub(norm_l(t_sp_center_num), 1); - Q_frame_power=norm_l(frame_power_den); - t_sp_center_num = L_shl(t_sp_center_num,Q_t_sp_center); - frame_power_den = L_shl(frame_power_den,Q_frame_power); - - d_t_sp_center = div_l(t_sp_center_num,extract_h(frame_power_den)); - - d_t_sp_center_Qtmp = add(Q_t_sc,Q_t_sp_center); - d_t_sp_center_Qtmp = sub(d_t_sp_center_Qtmp,Q_frame_power); - d_t_sp_center_Qtmp = sub(d_t_sp_center_Qtmp,Q_f_p); - d_t_sp_center_Qtmp = add(d_t_sp_center_Qtmp,15); - d_t_sp_center_Qtmp = sub(d_t_sp_center_Qtmp,SP_CENTER_Q); - sp_center[3]= shr(d_t_sp_center,d_t_sp_center_Qtmp); - move16(); - } - ELSE - { - t_sp_center = L_add(0, t_sp_center_nb); - frame_power = L_add(0, frame_power_nb); - - IF (frame_power==0) - { - d_t_sp_center = 0; - move16(); - } - ELSE - { - /*div*/ - Q_t_sp_center = sub(norm_l(t_sp_center), 1); - Q_frame_power = norm_l(frame_power); - t_sp_center_num = L_shl(t_sp_center,Q_t_sp_center); - frame_power_den = L_shl(frame_power,Q_frame_power); - - d_t_sp_center = div_l(t_sp_center_num,extract_h(frame_power_den)); - d_t_sp_center = shr(d_t_sp_center,sub(add(sub(Q_t_sp_center,Q_frame_power),10),SP_CENTER_Q)); - } - - sp_center[0] = add(mult(sp_center[0], 0x5999), mult(d_t_sp_center, 0x2666)); - sp_center[2] = d_t_sp_center; - move16(); - move16(); - - t_sp_center = L_add(0, 0); - frame_power = L_add(0, 0); - FOR(i=1; i<10; i++) - { - sb_power_mlt = Mpy_32_16_1(sb_power[i],i_t_1[i-1]); - t_sp_center = L_add(L_shr(sb_power_mlt,6), t_sp_center); - frame_power = L_add(sb_power_shr[i], frame_power); /*1-9 */ - } - IF (frame_power==0) - { - sp_center[3] = 0; - move16(); - } - ELSE - { - /*div */ - Q_t_sp_center = sub(norm_l(t_sp_center), 1); - Q_frame_power = norm_l(frame_power); - t_sp_center_num = L_shl(t_sp_center,Q_t_sp_center); - frame_power_den = L_shl(frame_power,Q_frame_power); - - d_t_sp_center = div_l(t_sp_center_num,extract_h(frame_power_den)); - sp_center[3] = shr(d_t_sp_center,sub(add(sub(Q_t_sp_center, Q_frame_power), 10),SP_CENTER_Q)); - move16(); - } + t_sp_center = (float)( (sp_center_mem)/(frame_power+FLT_MIN)); + sp_center[0]= 0.7f*sp_center[0]+0.3f*t_sp_center; + sp_center[2]= t_sp_center; } + return; } diff --git a/src/libs/libevs/lib_enc/spec_flatness.cpp b/src/libs/libevs/lib_enc/spec_flatness.cpp old mode 100755 new mode 100644 index 222d6d7a..008979ab --- a/src/libs/libevs/lib_enc/spec_flatness.cpp +++ b/src/libs/libevs/lib_enc/spec_flatness.cpp @@ -1,307 +1,97 @@ /*==================================================================================== - EVS Codec 3GPP TS26.442 Apr 03, 2018. Version 12.11.0 / 13.6.0 / 14.2.0 + EVS Codec 3GPP TS26.443 Nov 13, 2018. Version 12.11.0 / 13.7.0 / 14.3.0 / 15.1.0 ====================================================================================*/ +#include +#include "prot.h" -#include "basop_util.h" -#include "stl.h" -#include "vad_basop.h" -#include "prot_fx.h" +#include -void spec_flatness(Word32 *spec_amp, /*(i) spectral amplitude*/ - Word32 smooth_spec_amp[], /*(i) smoothed spectral amplitude*/ - Word16 sSFM[5] /*(o) spectral flatness rate*/ - ) + +/*-------------------------------------------------------------------* + * spec_flatness() + * + * + *-------------------------------------------------------------------*/ + +void spec_flatness( + float spec_amp[], /*(i) spectral amplitude*/ + float smooth_spec_amp[], /*(i) smoothed spectral amplitude*/ + float sSFM[] /*(o) spectral flatness rate*/ +) { - Word32 i; - Word32 *smooth_spec_amp32; - Word32 prods,prods_Exp; - Word32 sums,prods_ExpM; - Word32 zerop1; + int i; + double prods,sums; - Word16 smooth_spec_amp16; - Word16 Qnorm_prods,Qnorm_sums; - Word16 SFM; - Word16 prods_s,prods_Exps; - Word16 prods_leadingzero,prods_Expleadingzero; - - Word16 leadingzero_prod, leadingzero_spec_amp; - Word16 prods_Q_last,prods_ExpQ; - Word16 SFM_Qtmp; - Word16 prods_Q; - - - smooth_spec_amp32 = smooth_spec_amp; - zerop1 = L_add(0,0); - prods_Q = 0; - move16(); - FOR(i=MIN_AMP_ID; i<=MAX_AMP_ID; i++) + float SFM; + for(i=MIN_AMP_ID; i<=MAX_AMP_ID; i++) { - smooth_spec_amp32[i-MIN_AMP_ID] = L_add(MUL_F(smooth_spec_amp32[i-MIN_AMP_ID],0x5999),MUL_F(spec_amp[i],0x2666)); - move32(); + smooth_spec_amp[i-MIN_AMP_ID] = smooth_spec_amp[i-MIN_AMP_ID]*0.7f + spec_amp[i]*0.3f; } - /*sSFM1*/ - sums = L_add(0,0); - prods = L_add(1,0); - prods_Q = 0; - move16(); - - - FOR(i=(5-MIN_AMP_ID); i<(20-MIN_AMP_ID); i++) + /* sSFM1 */ + prods = 1; + sums = 0; + assert(MIN_AMP_ID<=5); + for(i=(5-MIN_AMP_ID); i<(20-MIN_AMP_ID); i++) { - sums = L_add(sums, smooth_spec_amp32[i]); - leadingzero_spec_amp = norm_l(smooth_spec_amp32[i]); - smooth_spec_amp16 = extract_h(L_shl(smooth_spec_amp32[i],leadingzero_spec_amp)); - leadingzero_prod = norm_l(prods); - prods = L_shl(prods,leadingzero_prod); - prods_s = extract_h(prods); - prods = L_mult(prods_s, smooth_spec_amp16); - prods_Q = add(add(prods_Q, leadingzero_spec_amp),leadingzero_prod); - } - prods_Q = sub(prods_Q, 255); - - prods_Q_last = prods_Q; - move16(); - prods_ExpM = L_mult(prods_Q_last,-2184); - - prods = VAD_Pow(prods,0x08888888,0,31,&prods_Q); - prods_Exp = VAD_Pow2(prods_ExpM,16, &prods_ExpQ); - - prods_leadingzero = norm_l(prods); - prods_Expleadingzero = norm_l(prods_Exp); - prods_s = extract_h(L_shl(prods,prods_leadingzero)); - prods_Exps = extract_h(L_shl(prods_Exp,prods_Expleadingzero)); - - prods = L_mult(prods_s, prods_Exps); - prods_Q = add(prods_Q, prods_leadingzero); - prods_Q = add(prods_Q, prods_ExpQ); - prods_Q = add(prods_Q, prods_Expleadingzero); - prods_Q = sub(prods_Q, 31); - - prods = L_max(prods, 0); - - if(prods <= 0) - { - prods_Q = 34; - move16(); - } - sums = MUL_F(sums, 0x0888); - - /*+0.1 */ - IF (sub(prods_Q, 34) >= 0) - { - prods = L_shr(prods, sub(prods_Q, 33)); - zerop1 = L_shr(CNT0P1, 1); - prods_Q = 33; - move16(); - } - ELSE - { - prods_Q = sub(prods_Q, 1); - prods = L_shr(prods, 1); - zerop1 = L_shr(CNT0P1, sub(34, prods_Q)); - } - prods = L_add(prods, zerop1); - - zerop1 = L_shr(CNT0P1, 20); - sums = L_add(sums, zerop1); - - /*div*/ - Qnorm_prods = sub(norm_l(prods), 1); - Qnorm_sums = norm_l(sums); - prods = L_shl(prods,Qnorm_prods); - sums = L_shl(sums,Qnorm_sums); - - SFM = div_l(prods, extract_h(sums)); - - SFM_Qtmp = add(prods_Q, Qnorm_prods); - SFM_Qtmp = sub(SFM_Qtmp, Qnorm_sums); - SFM_Qtmp = add(SFM_Qtmp, 15); - SFM_Qtmp = sub(SFM_Qtmp, SPEC_AMP_Q); - SFM_Qtmp = sub(SFM_Qtmp, SFM_Q); - - sSFM[0] = add(mult(sSFM[0], 0x6ccc), shr(mult(SFM, 0x1333), SFM_Qtmp)); - move16(); - - /*sSFM2*/ - sums = L_add(0,0); - prods = L_add(1,0); - prods_Q = 0; - move16(); - - FOR(i=(20-MIN_AMP_ID); i<(40-MIN_AMP_ID); i++) - { - sums = L_add(sums, smooth_spec_amp32[i]); - leadingzero_spec_amp = norm_l(smooth_spec_amp32[i]); - smooth_spec_amp16 = extract_h(L_shl(smooth_spec_amp32[i],leadingzero_spec_amp)); - leadingzero_prod = norm_l(prods); - prods = L_shl(prods,leadingzero_prod); - prods_s = extract_h(prods); - prods = L_mult(prods_s, smooth_spec_amp16); - prods_Q = add(add(prods_Q, leadingzero_spec_amp),leadingzero_prod); - } - prods_Q = sub(prods_Q, 340); - - prods_Q_last = prods_Q; - move16(); - prods_ExpM = L_mult(prods_Q_last,-1638); - - prods = VAD_Pow(prods,0x06666666,0,31,&prods_Q); - prods_Exp = VAD_Pow2(prods_ExpM,16, &prods_ExpQ); - - prods_leadingzero = norm_l(prods); - prods_Expleadingzero = norm_l(prods_Exp); - prods_s = extract_h(L_shl(prods,prods_leadingzero)); - prods_Exps = extract_h(L_shl(prods_Exp,prods_Expleadingzero)); - - prods = L_mult(prods_s, prods_Exps); - prods_Q = add(prods_Q, prods_leadingzero); - prods_Q = add(prods_Q, prods_ExpQ); - prods_Q = add(prods_Q, prods_Expleadingzero); - prods_Q = sub(prods_Q, 31); - - prods = L_max(prods, 0); - - if(prods<=0) - { - prods_Q = 34; - move16(); - } - sums = MUL_F(sums, 0x0666); - - /*+0.1 */ - IF (sub(prods_Q, 34) >= 0) - { - prods = L_shr(prods,sub(prods_Q, 33)); - zerop1 = L_shr(CNT0P1,1); - prods_Q = 33; - move16(); - } - ELSE - { - prods_Q = sub(prods_Q,1); - prods = L_shr(prods,1); - zerop1 = L_shr(CNT0P1, sub(34, prods_Q)); - } - prods = L_add(prods, zerop1); - - zerop1 = L_shr(CNT0P1, 20); - sums = L_add(sums, zerop1); - - /*div*/ - Qnorm_prods=sub(norm_l(prods), 1); - Qnorm_sums=norm_l(sums); - prods = L_shl(prods, Qnorm_prods); - sums = L_shl(sums, Qnorm_sums); - - SFM = div_l(prods, extract_h(sums)); - - SFM_Qtmp = add(prods_Q, Qnorm_prods); - SFM_Qtmp = sub(SFM_Qtmp, Qnorm_sums); - SFM_Qtmp = add(SFM_Qtmp, 15); - SFM_Qtmp = sub(SFM_Qtmp, SPEC_AMP_Q); - SFM_Qtmp = sub(SFM_Qtmp, SFM_Q); - - sSFM[1] = add(mult(sSFM[1],0x6ccc),shr(mult(SFM,0x1333),SFM_Qtmp)); - move16(); - /*sSFM3*/ - sums = L_add(0,0); - prods = L_add(1,0); - prods_Q = 0; - move16(); - - FOR(i=(40-MIN_AMP_ID); i<=(MAX_AMP_ID-MIN_AMP_ID); i++) - { - sums = L_add(sums, smooth_spec_amp32[i]); - leadingzero_spec_amp = norm_l(smooth_spec_amp32[i]); - smooth_spec_amp16 = extract_h(L_shl(smooth_spec_amp32[i],leadingzero_spec_amp)); - leadingzero_prod = norm_l(prods); - prods = L_shl(prods,leadingzero_prod); - prods_s = extract_h(prods); - prods = L_mult(prods_s, smooth_spec_amp16); - prods_Q = add(add(prods_Q, leadingzero_spec_amp),leadingzero_prod); - } - prods_Q = sub(prods_Q, 425); - - prods_Q_last = prods_Q; - move16(); - prods_ExpM = L_mult(prods_Q_last,-1310); - - prods = VAD_Pow(prods,0x051eb851,0,31,&prods_Q); - prods_Exp = VAD_Pow2(prods_ExpM,16, &prods_ExpQ); - - prods_leadingzero = norm_l(prods); - prods_Expleadingzero = norm_l(prods_Exp); - prods_s = extract_h(L_shl(prods,prods_leadingzero)); - prods_Exps = extract_h(L_shl(prods_Exp,prods_Expleadingzero)); - - prods = L_mult(prods_s, prods_Exps); - prods_Q = add(prods_Q, prods_leadingzero); - prods_Q = add(prods_Q, prods_ExpQ); - prods_Q = add(prods_Q, prods_Expleadingzero); - prods_Q = sub(prods_Q, 31); - - prods = L_max(prods, 0); - if(prods <= 0) - { - prods_Q = 34; - move16(); + prods = smooth_spec_amp[i]*prods; + sums = sums + smooth_spec_amp[i]; } - sums = MUL_F(sums, 0x051e); - - /*+0.1 */ - IF (sub(prods_Q, 34)>=0) + if(prods>0) { - prods = L_shr(prods,sub(prods_Q, 33)); - zerop1 = L_shr(CNT0P1,1); - prods_Q = 33; - move16(); + prods = pow(prods,1.0/15); } - ELSE + else { - prods_Q = sub(prods_Q, 1); - prods = L_shr(prods,1); - zerop1 = L_shr(CNT0P1, sub(34, prods_Q)); + prods=0; } - prods = L_add(prods, zerop1); + sums = sums/15; - zerop1 = L_shr(CNT0P1, 20); - sums = L_add(sums, zerop1); + SFM = (float)((prods+3276.8f)/(sums+3276.8f)); + sSFM[0] = 0.85f*sSFM[0] + 0.15f*SFM; - /*div*/ - Qnorm_prods = sub(norm_l(prods), 1); - Qnorm_sums = norm_l(sums); - prods = L_shl(prods,Qnorm_prods); - sums = L_shl(sums,Qnorm_sums); + /* sSFM2 */ + prods = 1; + sums = 0; + for(i=(20-MIN_AMP_ID); i<(40-MIN_AMP_ID); i++) + { + prods = smooth_spec_amp[i]*prods; + sums = sums + smooth_spec_amp[i]; + } - SFM = div_l(prods,extract_h(sums)); + if(prods>0) + { + prods = pow(prods,1.0/20); + } + else + { + prods =0; + } + sums = sums/20; + SFM= (float)((prods+3276.8f)/(sums+3276.8f)); + sSFM[1] = 0.85f*sSFM[1] + 0.15f*SFM; + /* sSFM3 */ + prods = 1; + sums = 0; + for(i=(40-MIN_AMP_ID); i<=(MAX_AMP_ID-MIN_AMP_ID); i++) + { + prods = smooth_spec_amp[i]*prods; + sums = sums + smooth_spec_amp[i]; + } - SFM_Qtmp = add(prods_Q, Qnorm_prods); - SFM_Qtmp = sub(SFM_Qtmp, Qnorm_sums); - SFM_Qtmp = add(SFM_Qtmp, 15); - SFM_Qtmp = sub(SFM_Qtmp, SPEC_AMP_Q); - SFM_Qtmp = sub(SFM_Qtmp, SFM_Q); + if(prods>0) + { + prods = pow(prods,0.04); + } + else + { + prods =0; + } + sums = sums/25; + SFM = (float)((prods+3276.8f)/(sums+3276.8f)); + sSFM[2] = 0.85f*sSFM[2] + 0.15f*SFM; - sSFM[2] = add(mult(sSFM[2],0x6ccc),shr(mult(SFM,0x1333),SFM_Qtmp)); - move16(); + + return; } - - - - - - - - - - - - - - - - - - - diff --git a/src/libs/libevs/lib_enc/speech_music_classif.cpp b/src/libs/libevs/lib_enc/speech_music_classif.cpp new file mode 100644 index 00000000..d13b0590 --- /dev/null +++ b/src/libs/libevs/lib_enc/speech_music_classif.cpp @@ -0,0 +1,1893 @@ +/*==================================================================================== + EVS Codec 3GPP TS26.443 Nov 13, 2018. Version 12.11.0 / 13.7.0 / 14.3.0 / 15.1.0 + ====================================================================================*/ + +#include +#include +#include +#include "options.h" +#include "cnst.h" +#include "prot.h" +#include "rom_enc.h" +#include "rom_com.h" /* Common static table prototypes */ + + +/*---------------------------------------------------------------------* + * Local constants + *---------------------------------------------------------------------*/ + +#define ATT_NSEG 32 +#define ATT_SEG_LEN (L_FRAME/ATT_NSEG) +#define ATT_3LSUB_POS (3 * ATT_NSEG / NB_SUBFR) +#define ATT_3LSUB_POS_16k (short)((4.0f * ATT_NSEG / (float)NB_SUBFR16k) + 0.5f) + +/*---------------------------------------------------------------------* + * Local functions + *---------------------------------------------------------------------*/ + +static short sp_mus_classif_1st( Encoder_State *st, const short localVAD, const short pitch[3], const float voicing[3], const float lsp_new[M], + const float cor_map_sum, const float epsP[M+1], const float PS[], float non_sta, float relE, + float *voi_fv, float *cor_map_sum_fv, float *LPCErr, short *high_lpn_flag ); + +static void music_mixed_classif_improv( Encoder_State *st, const float *new_inp, short *sp_aud_decision1, + const short vad_flag, const float *voicing, const float *epsP, const float etot, + const float old_cor, const float cor_map_sum ); + +static void spec_analysis( float *Bin_E, float *p2v_map ); + +static void flux( float *Bin_E, float *p2v_map, float *old_Bin_E, float *buf_flux, short attack_hangover, float dec_mov ); + +static void tonal_dist( float *p2v_map, float *buf_pkh, float *buf_Ntonal, float *buf_Ntonal2, float *buf_Ntonal_lf ); + +static short mode_decision( Encoder_State *st, short len, float *dec_mov, float *buf_flux, float *buf_epsP_tilt, float *buf_pkh, float *buf_cor_map_sum, + float *buf_Ntonal, float *buf_Ntonal2, float *buf_Ntonal_lf, float *buf_dlp ); + + +static void sp_mus_classif_2nd( Encoder_State *st, const short sp_aud_decision1, short *sp_aud_decision2, const short pitch[], + const float Etot, short *coder_type, short *attack_flag, + const float *inp, const short localVAD, const short vad_flag ); + +static void var_cor_calc( const float old_corr, float *mold_corr, float var_cor_t[], short *high_stable_cor ); + +static short attack_det( const float *inp, const short last_clas, const short localVAD, const short coder_type, const int total_brate ); + +static void tonal_context_improv( Encoder_State *st, const float PS[], short *sp_aud_decision1, short *sp_aud_decision2, + const short vad_flag, const short pitch[3], const float voicing[3], const float voi_fv, + const float cor_map_sum_fv, const float LPCErr ); +static void order_spectrum( float *vec, short len ); + +static void detect_sparseness( Encoder_State *st, const short localVAD_HE_SAD, short *sp_aud_decision1, + short *sp_aud_decision2, const float voi_fv ); + + +/*---------------------------------------------------------------------* + * speech_music_classif() + * + * Speech/music classification + * + * The following technologies are used based on the outcome of the sp/mus classifier + * sp_aud_decision1 sp_aud_decision2 + * 0 0 use ACELP (+TD BWE) + * 1 0 use ACELP (+FD BWE) or HQ/LR-MDCT depending on bitrate + * 1 1 use GSC (+FD BWE) or HQ/LR-MDCT depending on bitrate + * + * 0 1 exceptionally use GSC (+FD BWE) instead of LR-MDCT at 13.2 kbps (WB/SWB) for sparse spectra + *---------------------------------------------------------------------*/ + +void speech_music_classif( /* o : 1st stage decision (1-music, 0-speech or noise) */ + Encoder_State *st, /* i/o: state structure */ + short *sp_aud_decision0, /* o : 1st stage speech/music decision */ + short *sp_aud_decision1, /* o : 1st stage speech/music decision */ + short *sp_aud_decision2, /* o : 2nd stage speech/music decision */ + const float *new_inp, /* i : new input signal */ + const float *inp, /* i : input signal to locate attach position */ + const short vad_flag, + const short localVAD, + const short localVAD_HE_SAD, /* i : HE-SAD flag without hangover */ + const short pitch[3], /* i : open-loop pitch estimate in three subframes */ + const float voicing[3], /* i : voicing estimate in three subframes */ + const float lsp_new[M], /* i : LSPs in current frame */ + const float cor_map_sum, /* i : correlation map sum (from multi-harmonic anal.) */ + const float epsP[M+1], /* i : LP prediciton error */ + const float PS[], /* i : energy spectrum */ + const float Etot, /* i : total frame energy */ + const float old_cor, /* i : max correlation from previous frame */ + short *coder_type, /* i/o: coding type */ + short *attack_flag, /* o : flag to indicate if attack is to be treated by TC or GSC */ + const float non_sta, /* i : unbound non-stationarity for sp/mus classifier */ + const float relE, /* i : relative frame energy */ + short *high_lpn_flag, + const short flag_spitch /* i : flag to indicate very short stable pitch */ +) +{ + float voi_fv, cor_map_sum_fv, LPCErr; + + /* 1st stage speech/music classification based on the GMM model */ + *sp_aud_decision1 = sp_mus_classif_1st( st, localVAD_HE_SAD, pitch, voicing, lsp_new, cor_map_sum, + epsP, PS, non_sta, relE, &voi_fv, &cor_map_sum_fv, &LPCErr, high_lpn_flag ); + + if( st->codec_mode == MODE1 || st->sr_core == 12800) + { + + /* Improvement of the 1st stage decision for mixed/music content */ + if ( !st->Opt_SC_VBR && (st->total_brate != ACELP_24k40) ) + { + music_mixed_classif_improv( st, new_inp, sp_aud_decision1, vad_flag, voicing, epsP, Etot, old_cor, cor_map_sum ); + } + + *sp_aud_decision0 = *sp_aud_decision1; + + /* 2nd stage speech/music classification (rewrite music to speech in onsets) */ + *sp_aud_decision2 = *sp_aud_decision1; + + if( st->bwidth > NB ) + { + sp_mus_classif_2nd( st, *sp_aud_decision1, sp_aud_decision2, pitch, Etot, coder_type, attack_flag, + inp, localVAD, vad_flag ); + + if ( flag_spitch && st->bwidth == WB && st->total_brate < ACELP_13k20 ) + { + /* avoid switch to AUDIO/MUSIC class for very short stable high pitch + and/or stable pitch with high correlation at low bitrates*/ + *sp_aud_decision2 = 0; + } + } + + /* Context-based improvement of 1st and 2nd stage decision on stable tonal signals */ + if( !st->Opt_SC_VBR && (st->total_brate != ACELP_24k40) ) + { + tonal_context_improv( st, PS, sp_aud_decision1, sp_aud_decision2, vad_flag, pitch, voicing, + voi_fv, cor_map_sum_fv, LPCErr ); + } + + /* Avoid using LR-MDCT on sparse spectra, use GSC instead at 13.2 kbps (WB/SWB) */ + if ( !st->Opt_SC_VBR && st->total_brate == 13200 && vad_flag == 1 && + ( st->bwidth == WB || st->bwidth == SWB ) ) + { + detect_sparseness( st, localVAD_HE_SAD, sp_aud_decision1, sp_aud_decision2, voi_fv ); + } + + /* override speech/music classification to ACELP when background noise level reaches certain level */ + /* this is a patch against mis-classifications during active noisy speech segments */ + if ( st->lp_noise > 12.0f ) + { + *sp_aud_decision1 = 0; + *sp_aud_decision2 = 0; + } + + /* set GSC noisy speech flag on unvoiced SWB segments */ + st->GSC_noisy_speech = 0; + if ( vad_flag == 1 && st->total_brate >= ACELP_13k20 && st->total_brate < ACELP_24k40 && + st->lp_noise > 12.0f && *sp_aud_decision1 == 0 && st->bwidth >= SWB && + st->coder_type_raw == UNVOICED ) + { + st->GSC_noisy_speech = 1; + } + + /* Select AUDIO frames */ + if ( st->codec_mode == MODE1 && (*sp_aud_decision2 || st->GSC_noisy_speech) ) + { + *coder_type = AUDIO; + st->noise_lev = NOISE_LEVEL_SP0; + } + + } + + return; +} + + +/*---------------------------------------------------------------------* + * sp_mus_classif_1st() + * + * 1st stage speech/music classification (based on the GMM model) + *---------------------------------------------------------------------*/ + +static short sp_mus_classif_1st( /* o : decision flag (1-music, 0-speech or noise) */ + Encoder_State *st, /* i/o: state structure */ + const short localVAD, + const short pitch[3], /* i : open-loop pitch estimate in three subframes */ + const float voicing[3], /* i : voicing estimate in three subframes */ + const float lsp_new[M], /* i : LSPs in current frame */ + const float cor_map_sum, /* i : correlation map sum (from multi-harmonic anal.) */ + const float epsP[M+1], /* i : LP prediciton error */ + const float PS[], /* i : energy spectrum */ + float non_sta, /* i : unbound non-stationarity */ + float relE, /* i : relative frame energy */ + float *voi_fv, /* o : scaled voicing feature */ + float *cor_map_sum_fv, /* o : scaled correlation map feature */ + float *LPCErr, /* o : scaled LP prediction error feature */ + short *high_lpn_flag + +) +{ + short i, k, p, dec, vad; + float dlp, ftmp, lepsP1, sum_PS, ps_diff, ps_sta, wrelE, wdrop, wght, mx; + float FV[N_FEATURES], *pFV = FV, PS_norm[128], dPS[128], lsp[M]; + float pys, pym, xm[N_FEATURES], py, lps = 0, lpm = 0; + const float *pSF; + float pyn, lpn = 0; + + /*------------------------------------------------------------------* + * Initialization + *------------------------------------------------------------------*/ + + vad = localVAD; + + /*------------------------------------------------------------------* + * Preparation of the feature vector + *------------------------------------------------------------------*/ + + /* [0] OL pitch */ + if ( st->tc_cnt == 1 || st->tc_cnt == 2 ) + { + *pFV++ = (float)pitch[2]; + } + else + { + *pFV++ = (float)(pitch[0] + pitch[1] + pitch[2]) / 3.0f; + } + + /* [1] voicing */ + if ( st->tc_cnt == 1 || st->tc_cnt == 2 ) + { + *pFV++ = voicing[2]; + } + else + { + *pFV++ = (float)(voicing[0] + voicing[1] + voicing[2]) / 3.0f; + } + + /* [2,3,4,5,6] LSFs */ + mvr2r( lsp_new, lsp, M ); + + ftmp = (float)acos(lsp[1]); + *pFV++ = ftmp + st->last_lsp[1]; + st->last_lsp[1] = ftmp; + + ftmp = (float)acos(lsp[2]); + *pFV++ = ftmp + st->last_lsp[2]; + st->last_lsp[2] = ftmp; + + ftmp = (float)acos(lsp[3]); + *pFV++ = ftmp + st->last_lsp[3]; + st->last_lsp[3] = ftmp; + + ftmp = (float)acos(lsp[4]); + *pFV++ = ftmp + st->last_lsp[4]; + st->last_lsp[4] = ftmp; + + ftmp = (float)acos(lsp[5]); + *pFV++ = ftmp + st->last_lsp[5]; + st->last_lsp[5] = ftmp; + + /* [7] cor_map_sum */ + *pFV++ = cor_map_sum + st->last_cor_map_sum; + st->last_cor_map_sum = cor_map_sum; + + /* [8] non_sta */ + *pFV++ = non_sta + st->last_non_sta; + st->last_non_sta = non_sta; + + /* [9] epsP */ + if ( st->bwidth == NB ) + { + /* do not take into account (statistics are too different) */ + *pFV++ = -1.647f; + } + else + { + lepsP1 = (float)log(epsP[1] + 1e-5f); + ftmp = (float)log(epsP[13]) - lepsP1; + *pFV++ = ftmp + st->past_epsP2; + st->past_epsP2 = ftmp; + } + + /* calculation of differential normalized power spectrum */ + sum_PS = 1e-5f; + for ( i = LOWEST_FBIN; i < HIGHEST_FBIN; i++ ) + { + sum_PS += PS[i]; + } + + for ( i = LOWEST_FBIN; i < HIGHEST_FBIN; i++ ) + { + PS_norm[i] = PS[i] / sum_PS; + dPS[i] = (float)fabs(PS_norm[i] - st->past_PS[i-LOWEST_FBIN]); + } + + /* [10] ps_diff (spectral difference) */ + ps_diff = 0; + for ( i = LOWEST_FBIN; i < HIGHEST_FBIN; i++ ) + { + ps_diff += dPS[i]; + } + + ps_diff = (float)log(ps_diff + 1e-5f); + *pFV++ = ps_diff + st->past_ps_diff; + st->past_ps_diff = ps_diff; + + /* [11] ps_sta (spectral stationarity) */ + ps_sta = 0; + for ( i = LOWEST_FBIN; i < HIGHEST_FBIN; i++ ) + { + mx = PS_norm[i] > st->past_PS[i-LOWEST_FBIN] ? PS_norm[i] : st->past_PS[i-LOWEST_FBIN]; + ps_sta += mx / (dPS[i] + 1e-5f); + } + + *pFV++ = (float)log(ps_sta + 1e-5f); + mvr2r( &PS_norm[LOWEST_FBIN], st->past_PS, HIGHEST_FBIN-LOWEST_FBIN ); + + /*------------------------------------------------------------------* + * Scaling of the feature vector + *------------------------------------------------------------------*/ + + pFV = FV; + if ( st->bwidth == NB ) + { + pSF = SF_8k; + } + else + { + pSF = SF; + } + + for ( i=0; i lps && lpn > lpm ) + { + *high_lpn_flag = 1; + } + if ( !vad ) + { + /* artificially increase log-probability of noise */ + lps = lpn * 1.2f; + } + + st->lpm = lpm; + st->lps = lps; + + /* determine HQ Generic speech class */ + if ( lps > lpm + 0.5f ) + { + st->hq_generic_speech_class = 1; + } + else + { + st->hq_generic_speech_class = 0; + } + + /*------------------------------------------------------------------* + * State machine (sp_mus_state < 0 .. inactive, > 0 .. entry, = 0 .. active ) + *------------------------------------------------------------------*/ + + if ( vad ) + { + if ( relE < -20 || (lps <= -5 && lpm <= -5) ) + { + if ( st->sp_mus_state > 0 ) + { + if ( st->sp_mus_state < HANG_LEN ) + { + /* energy is too low but we are in entry period -> reset the inactive counter to allow new entry later */ + st->inact_cnt = 0; + } + + /* energy is too low -> we are going to instable state */ + st->sp_mus_state = 0; + } + else if ( st->sp_mus_state > -HANG_LEN ) + { + /* energy is still too low -> we are still in instable state */ + st->sp_mus_state--; + } + } + else if ( st->sp_mus_state <= 0 ) + { + if ( st->inact_cnt == 0 ) + { + + st->sp_mus_state = 1; + } + else + { + + st->sp_mus_state = HANG_LEN; + } + + st->inact_cnt = 12; + } + else if ( st->sp_mus_state > 0 && st->sp_mus_state < HANG_LEN ) + { + /* we are inside an entry period -> increment the counter of entry frames */ + st->sp_mus_state++; + } + + if ( st->sp_mus_state < 0 && st->inact_cnt > 0 ) + { + st->inact_cnt--; + } + } + else + { + if ( st->sp_mus_state > 0 && st->sp_mus_state < HANG_LEN ) + { + st->inact_cnt = 0; + } + else if ( st->inact_cnt > 0 ) + { + st->inact_cnt--; + } + + if ( st->sp_mus_state > 0 && st->sp_mus_state < HANG_LEN ) + { + + st->sp_mus_state = -HANG_LEN; + } + else if ( st->sp_mus_state > 0 ) + { + + st->sp_mus_state = -1; + } + else if ( st->sp_mus_state > -HANG_LEN ) + { + /* we are in inactive state */ + st->sp_mus_state--; + } + + } + + /*------------------------------------------------------------------* + * Decision without hangover + * Weighted decision + *------------------------------------------------------------------*/ + + /* decision without hangover (0 - speech/noise, 1 - music) */ + dec = lpm > lps; + dlp = lpm - lps; + + if ( !vad ) + { + dec = 0; + dlp = 0; + } + + /* calculate weight based on relE (close to 0.01 in low-E regions, close to 1 in high-E regions) */ + wrelE = 1.0f + relE/15; + + if ( wrelE > 1.0f ) + { + wrelE = 1.0f; + } + else if ( wrelE < 0.01f ) + { + wrelE = 0.01f; + } + + /* calculate weight based on drops of dlp (close to 1 during sudden drops of dlp, close to 0 otherwise) */ + if ( dlp < 0 && dlp < st->past_dlp[0] ) + { + if ( st->past_dlp[0] > 0 ) + { + st->wdrop = -dlp; + } + else + { + st->wdrop += st->past_dlp[0] - dlp; + } + } + else + { + st->wdrop = 0; + } + + wdrop = st->wdrop/20; + + if ( wdrop > 1.0f ) + { + wdrop = 1.0f; + } + else if ( wdrop < 0.1f ) + { + wdrop = 0.1f; + } + + /* combine weights into one */ + wght = wrelE * wdrop; + if ( wght < 0.01f ) + { + wght = 0.01f; + } + + /* calculate weighted decision */ + st->wdlp_0_95_sp = wght * dlp + (1 - wght) * st->wdlp_0_95_sp; + + if ( st->sp_mus_state == -HANG_LEN ) + { + st->wdlp_0_95_sp = 0; + } + + /*------------------------------------------------------------------* + * Final speech/music decision + *------------------------------------------------------------------*/ + + if ( !vad && st->sp_mus_state == -HANG_LEN ) + { + /* inactive state */ + dec = 0; + } + else if ( st->sp_mus_state <= 0 ) + { + /* transition from active to inactive state or instable state */ + dec = st->past_dec[0]; + } + else if ( st->sp_mus_state > 0 && st->sp_mus_state < HANG_LEN ) + { + /* entry state -> final decision is calculated based on weighted average of past non-binary decisions */ + ftmp = w_spmus[st->sp_mus_state-1][0] * dlp; + ftmp += dotp( &w_spmus[st->sp_mus_state-1][1], st->past_dlp, HANG_LEN-1 ); + dec = ftmp > 2.0f; + } + else + { + /* stable active state */ + if ( st->wdlp_0_95_sp > 0 && st->past_dec[0] == 0 && st->past_dec[1] == 0 && st->past_dec[2] == 0 ) + { + /* switching from speech to music */ + dec = 1; + } + else if ( st->past_dec[0] == 1 && st->wdlp_0_95_sp < 0 ) + { + /* switching from music to speech */ + dec = 0; + } + else + { + dec = st->past_dec[0]; + } + } + + /*------------------------------------------------------------------* + * Updates + *------------------------------------------------------------------*/ + + /* update buffer of past non-binary decisions */ + mvr2r( &st->past_dlp[0], &st->past_dlp[1], HANG_LEN-2 ); + st->past_dlp[0] = dlp; + + /* update buffer of past binary decisions */ + mvs2s( &st->past_dec[0], &st->past_dec[1], HANG_LEN-2 ); + st->past_dec[0] = dec; + + return dec; +} + + +/*---------------------------------------------------------------------* + * sp_mus_classif_2nd() + * + * 2nd stage speech/music classifier (convert music to speech for onsets) + *---------------------------------------------------------------------*/ + +static void sp_mus_classif_2nd( + Encoder_State *st, /* i/o: encoder state structure */ + const short sp_aud_decision1, /* i : 1st stage decision flag */ + short *sp_aud_decision2, /* o : 2nd stage decision flag */ + const short pitch[3], /* i : open-loop pitch estimate in three subframes */ + const float Etot, /* i : total frame energy */ + short *coder_type, /* i/o: coder type */ + short *attack_flag, /* i/o: attack flag (GSC or TC) */ + const float *inp, /* i : input signal */ + const short localVAD, + const short vad_flag +) +{ + short attack; + + /* initialization */ + *attack_flag = 0; + + /* signal stability estimation */ + stab_est( Etot, st->gsc_lt_diff_etot, &st->gsc_mem_etot, + &st->gsc_nb_thr_3, &st->gsc_nb_thr_1, st->gsc_thres, &st->gsc_last_music_flag, vad_flag ); + + /* calculate variance of correlation */ + var_cor_calc( st->old_corr, &st->mold_corr, st->var_cor_t, &st->high_stable_cor ); + + /* attack detection */ + attack = attack_det( inp, st->clas, localVAD, *coder_type, st->total_brate ); + + /* change decision from music hto speech in certain special cases */ + if( sp_aud_decision1 == 1 ) + { + if( st->ener_RAT < 0.18f && st->lt_dec_thres > 15.0f ) + { + /* strong music decision but almost no content below 1kHz */ + *sp_aud_decision2 = 0; + } + else if( st->high_stable_cor && pitch[0] >= 130 ) + { + /* prevent GSC in highly correlated signal with low energy variation */ + /* this is basically a patch against bassoon-type of music */ + *sp_aud_decision2 = 0; + + if ( st->codec_mode == MODE1 && *coder_type == TRANSITION ) + { + *coder_type = GENERIC; + } + } + else if( st->gsc_lt_diff_etot[MAX_LT-1] > 4.5f && + (st->gsc_lt_diff_etot[MAX_LT-1] - st->gsc_lt_diff_etot[MAX_LT-2] > 10.0f) ) + { + if ( st->tc_cnt == 1 ) + { + /* do TC coding instead of GC/VC if onset has been already declared before */ + *sp_aud_decision2 = 0; + if ( st->codec_mode == MODE1 ) + { + *coder_type = TRANSITION; + } + } + else + { + if( attack >= ATT_3LSUB_POS ) + { + /* do TC coding if attack is located in the last subframe */ + *sp_aud_decision2 = 0; + *attack_flag = 1; + if ( st->codec_mode == MODE1 ) + { + *coder_type = TRANSITION; + } + } + else if( attack >= ATT_SEG_LEN/2 ) + { + /* do GSC coding if attack is located after the first quarter of the first subframe */ + /* (pre-echo will be treated at the decoder side) */ + *attack_flag = 1; + } + } + } + } + else if ( localVAD == 1 && *coder_type == GENERIC && + ( (attack >= ATT_3LSUB_POS && st->total_brate < ACELP_24k40) || + (attack >= ATT_3LSUB_POS_16k && st->total_brate >= ACELP_24k40 && st->total_brate < ACELP_48k) ) + ) + { + /* do TC coding an attack is located in the last subframe */ + *attack_flag = 1; + if ( st->codec_mode == MODE1 ) + { + *coder_type = TRANSITION; + } + } + + return; +} + +/*---------------------------------------------------------------------* + * var_cor_calc() + * + * Calculate variance of correlation + *---------------------------------------------------------------------*/ + +static void var_cor_calc( + const float old_corr, + float *mold_corr, + float var_cor_t[], + short *high_stable_cor +) +{ + short i; + float var_cor; + + /* update buffer of old correlation values */ + for( i = VAR_COR_LEN-1; i > 0; i-- ) + { + var_cor_t[i] = var_cor_t[i-1]; + } + var_cor_t[i] = old_corr; + + /* calculate variance of correlation */ + var_cor = var( var_cor_t, VAR_COR_LEN ); + + /* set flag in case of highly-correlated stable signal */ + if( *mold_corr > 0.8f && var_cor < 5e-4f ) + { + *high_stable_cor = 1; + } + else + { + *high_stable_cor = 0; + } + + /* update average correlation */ + *mold_corr = 0.1f * old_corr + 0.9f * *mold_corr; + + return; +} + +/*---------------------------------------------------------------------* + * attack_det() + * + * Attack detection + *---------------------------------------------------------------------*/ + +static short attack_det( + const float *inp, /* i : input signal */ + const short last_clas, /* i : last signal clas */ + const short localVAD, + const short coder_type, /* i : coder type */ + const int total_brate /* i : total bit-rate */ +) +{ + short i, attack; + float etmp, etmp2, finc[ATT_NSEG]; + short att_3lsub_pos; + + att_3lsub_pos = ATT_3LSUB_POS; + if( total_brate >= ACELP_24k40 ) + { + att_3lsub_pos = ATT_3LSUB_POS_16k; + } + + /* compute energy per section */ + for( i=0; i etmp2 ) + { + /* stop, if the attack is not sufficiently strong */ + attack = 0; + } + + if( last_clas == VOICED_CLAS && etmp * 20 > etmp2 ) + { + /* stop, if the signal was voiced and the attack is not sufficiently strong */ + attack = 0; + } + + /* compare wrt. other sections (reduces miss-classification) */ + if( attack > 0 ) + { + etmp2 = finc[attack]; + + for( i=2; i etmp2 ) + { + /* stop, if the attack is not sufficiently strong */ + attack = 0; + break; + } + } + } + } + + /* compare wrt. other sections (reduces miss-classification) */ + else if( attack > 0 ) + { + etmp2 = finc[attack]; + + for( i=2; i etmp2 ) + { + /* stop, if the attack is not sufficiently strong */ + attack = 0; + break; + } + } + } + + return attack; +} + + +/*------------------------------------------------------------------------* + * music_mixed_classif_improv() + * + * Improve 1st stage speech/music decision for mixed&music signals + *------------------------------------------------------------------------*/ + +static void music_mixed_classif_improv( + Encoder_State *st, /* i/o: Encoder state structure */ + const float *new_inp, /* i : new input signal */ + short *sp_aud_decision1, /* i/o: improved 1st stage speech/music decision */ + const short vad_flag, + const float *voicing, /* i : voicing estimate */ + const float *epsP, /* i : LP prediction error */ + const float etot, /* i : total frame energy */ + const float old_cor, /* i : normalized correlation */ + const float cor_map_sum /* i : correlation map sum */ +) +{ + short i, dec, len, percus_flag; + float p2v_map[128], ftmp, ftmp1, lt_diff, log_max_spl, epsP_tilt, max_spl; + + /* find sample with maximum absolute amplitude */ + max_spl = 0; + for ( i=0; i max_spl ) + { + max_spl = (float)fabs(new_inp[i]); + } + } + + /* music is considered only appearing in high SNR condition and active signal */ + if ( vad_flag == 0 || st->lp_speech - st->lp_noise < 25 ) + { + st->dec_mov = 0.5f; + st->dec_mov1 = 0.5f; + + if ( vad_flag == 0 ) + { + st->onset_cnt = 0; + } + + return; + } + + st->onset_cnt++; + + if ( st->onset_cnt > 9 ) + { + st->onset_cnt = 9; + } + + if ( st->onset_cnt == 1 ) + { + set_f( st->buf_flux, -100, BUF_LEN ); + } + + /* spectral analysis */ + spec_analysis( st->Bin_E, p2v_map ); + + /* percussive music detection */ + log_max_spl = 20 * (float)log(max_spl + 0.0001f); + lt_diff = log_max_spl - st->mov_log_max_spl; + + for ( i=0; i<3; i++ ) + { + st->buf_etot[i] = st->buf_etot[i+1]; + } + st->buf_etot[i] = etot; + + percus_flag = 0; + if ( st->buf_etot[1] - st->buf_etot[0] > 6 && st->buf_etot[2] < st->buf_etot[1] && st->buf_etot[1] - st->lp_speech > 3 ) + { + if ( st->buf_etot[1] - st->buf_etot[3] > 3 && st->buf_etot[3] < st->buf_etot[2] && 0.5f * (0.5f * (voicing[0] + voicing[1]) + old_cor) < 0.75f ) + { + if ( st->dec_mov > 0.8f ) + { + percus_flag = 1; + } + else if ( old_cor < 0.75f && voicing[0] < 0.75f && voicing[1] < 0.75f && st->old_lt_diff[0] > 10 ) + { + percus_flag = 1; + } + } + } + + /* sound attack detection */ + if ( st->buf_etot[3] - st->buf_etot[2] > 6 && st->dec_mov > 0.9f && etot - st->lp_speech > 5 && st->old_lt_diff[0] > 5 ) + { + st->attack_hangover = 3; + } + + if ( voicing[0] > 0.9f && voicing[1] > 0.9f ) + { + if ( log_max_spl > st->mov_log_max_spl ) + { + st->mov_log_max_spl = 0.75f * st->mov_log_max_spl + (1 - 0.75f) * log_max_spl; + } + else + { + st->mov_log_max_spl = 0.995f * st->mov_log_max_spl + (1 - 0.995f) * log_max_spl; + } + } + + st->old_lt_diff[0] = st->old_lt_diff[1]; + st->old_lt_diff[1] = lt_diff; + + /* calculate and buffer spectral energy fluctuation */ + flux( st->Bin_E, p2v_map, st->old_Bin_E, st->buf_flux, st->attack_hangover, st->dec_mov ); + + st->attack_hangover--; + if ( st->attack_hangover < 0 ) + { + st->attack_hangover = 0; + } + + /* identify flux buffer status */ + len = 0; + for ( i = BUF_LEN-1; i >= 0 && st->buf_flux[i] >= 0; i-- ) + { + len++; + } + + /* reset flux buffer if percussive music is detected */ + if ( percus_flag == 1 ) + { + set_f( &st->buf_flux[BUF_LEN-len], 5, len ); + } + + /* calculate and buffer the tilt of residual LP analysis energies */ + ftmp = 0.00001f; + ftmp1 = 0; + for ( i=1; i<16; i++ ) + { + ftmp += epsP[i] * epsP[i]; + ftmp1 += epsP[i] * epsP[i+1]; + } + + epsP_tilt = ftmp1/ftmp; + + for ( i=0; ibuf_epsP_tilt[i] = st->buf_epsP_tilt[i+1]; + } + st->buf_epsP_tilt[i] = epsP_tilt; + + /* calculate and buffer highband spectral peakness */ + tonal_dist( p2v_map, st->buf_pkh, st->buf_Ntonal, st->buf_Ntonal2, st->buf_Ntonal_lf ); + + /* buffer sum of correlation map */ + for ( i=0; ibuf_cor_map_sum[i] = st->buf_cor_map_sum[i+1]; + } + st->buf_cor_map_sum[i] = cor_map_sum; + + /* buffer voicing metric */ + for ( i=0; i<9; i++ ) + { + st->buf_dlp[i] = st->buf_dlp[i+1]; + } + st->buf_dlp[i] = st->lps - st->lpm; + + /* classification */ + dec = mode_decision( st, len, &st->dec_mov, st->buf_flux, st->buf_epsP_tilt, st->buf_pkh, st->buf_cor_map_sum, + st->buf_Ntonal, st->buf_Ntonal2, st->buf_Ntonal_lf, st->buf_dlp ); + + /* update long term moving average of the classification decisions */ + if ( len > 30 ) + { + st->dec_mov = 0.97f * st->dec_mov + (1 - 0.97f) * dec; + st->dec_mov1 = 0.97f * st->dec_mov1 + (1 - 0.97f) * dec; + } + + /* update long-term unvoiced counter */ + if ( (st->coder_type_raw == UNVOICED || st->coder_type_raw == INACTIVE) && etot > 1.5f && st->buf_Ntonal2[59] < 2 ) + { + st->UV_cnt1 -= 8; + } + else + { + st->UV_cnt1++; + } + + if ( st->UV_cnt1 > 300 ) + { + st->UV_cnt1 = 300; + } + else if ( st->UV_cnt1 < 0 ) + { + st->UV_cnt1 = 0; + } + + st->LT_UV_cnt1 = 0.9f * st->LT_UV_cnt1 + 0.1f * st->UV_cnt1; + + /* revert classification decision due to long-term unvoiced counter */ + if ( dec == 1 && st->dec_mov1 < 0.2f && st->LT_UV_cnt1 < 200 ) + { + dec = 0; + } + + /* overwrite 1st stage speech/music decision to music */ + if ( dec == 1 ) + { + *sp_aud_decision1 = 1; + } + + return; +} + + +/*---------------------------------------------------------------------* + * spec_analysis() + * + * Spectral analysis for mixed/music classification improvement + *---------------------------------------------------------------------*/ + +static void spec_analysis( + float *Bin_E, /* i : log energy spectrum of the current frame */ + float *p2v_map /* o : spectral peakiness map */ +) +{ + short i, k, m; + float peak[L_FFT/4+1]; + float valley[L_FFT/4+1]; + short peak_idx[L_FFT/4+1]; + short valey_idx[L_FFT/4+1]; + float p2v[L_FFT/4+1]; + + /* find spectral peaks */ + k = 0; + for ( i=1; i Bin_E[i-1] && Bin_E[i] > Bin_E[i+1] ) + { + peak[k] = Bin_E[i]; + peak_idx[k] = i; + k++; + } + } + assert(k+1= 0 && Bin_E[i+1] > Bin_E[i]; i-- ) + { + k = i; + } + + for ( i=1; i valey_idx[i] && peak_idx[k] < valey_idx[i+1] ) + { + p2v[k] = 2*peak[k] - valley[i] - valley[i+1]; + k++; + } + } + + for ( i=0; i 20 && dec_mov > 0.8f ) + { + flux = 20; + } + + /* update old Bin_E buffer */ + pt1 = old_Bin_E; + pt2 = old_Bin_E + N_OLD_BIN_E; + pt3 = Bin_E; + pt4 = old_Bin_E + N_OLD_BIN_E; + pt5 = old_Bin_E + 2*N_OLD_BIN_E; + pt6 = old_Bin_E + 2*N_OLD_BIN_E; + + for ( i=0; i 55 ) + { + Ntonal++; + } + + if ( p2v_map[i] > 80 ) + { + Ntonal2++; + Ntonal_lf++; + } + } + + for ( i=64; i<127; i++ ) + { + if ( p2v_map[i] != 0 ) + { + pk += p2v_map[i]; + } + + if ( p2v_map[i] > 55 ) + { + Ntonal++; + } + + if ( p2v_map[i] > 80 ) + { + Ntonal2++; + } + } + + /* update buffers */ + for ( i=0; i 0.5f; + + if ( len <= 5 ) + { + return ( mode ); + } + else if ( len < 10 ) + { + M_pkh = mean( buf_pkh+BUF_LEN-len, len ); + M_cor_map_sum = mean( buf_cor_map_sum+BUF_LEN-len, len ); + M_Ntonal = mean( buf_Ntonal+BUF_LEN-len, len ); + V_epsP_tilt = var( buf_epsP_tilt+BUF_LEN-len, len ); + + voiced_cnt = 0; + for ( i=9; i>3; i-- ) + { + if ( buf_dlp[i] > 0.0f ) + { + voiced_cnt++; + } + } + + if ( (M_pkh > 1100 || V_epsP_tilt < 0.00008f || M_cor_map_sum > 100) && voiced_cnt < 4 ) + { + mode = 1; + } + else if ( M_Ntonal > 27 && voiced_cnt < 4 ) + { + mode = 1; + } + } + else + { + voiced_cnt = 0; + for ( i=0; i<10; i++ ) + { + if ( buf_dlp[i] > 0.0f ) + { + voiced_cnt++; + } + } + + M_flux = mean( &buf_flux[BUF_LEN-10], 10 ); + M_pkh = mean( buf_pkh+BUF_LEN-10, 10 ); + M_cor_map_sum = mean( buf_cor_map_sum+BUF_LEN-10, 10 ); + V_epsP_tilt = var( buf_epsP_tilt+BUF_LEN-10, 10 ); + + if ( (M_flux < 8.5f || (V_epsP_tilt < 0.001f && M_flux < 12.0f) || M_pkh > 1050 || M_cor_map_sum > 100) + && voiced_cnt < 3 && mean( &buf_flux[55], 5 ) < 15 ) + { + mode = 1; + *dec_mov = 1; + return ( mode ); + } + + if ( M_flux > 16.0f || (M_flux > 15 && voiced_cnt > 2) || mean( &buf_flux[55], 5 ) > 19.0f || (buf_flux[59] >= 20 && st->lps-st->lpm > 0) ) + { + *dec_mov = 0; + mode = 0; + return ( mode ); + } + + for ( i=10; i 1050-5.0f*(len-10) || M_cor_map_sum > 95-0.3f*(len-10)) && voiced_cnt < 3 ) + { + mode = 1; + return( mode ); + } + } + + if ( len == BUF_LEN ) + { + M_Ntonal = mean( buf_Ntonal, BUF_LEN ); + lf_Ntonal_ratio = sum_f(buf_Ntonal_lf, BUF_LEN)/(sum_f(buf_Ntonal2, BUF_LEN) + 0.0001f); + + if ( M_Ntonal > 18 || lf_Ntonal_ratio < 0.2f ) + { + mode = 1; + } + else if ( M_Ntonal < 1 ) + { + mode = 0; + } + } + } + + return( mode ); +} + +/*----------------------------------------------------------------------------------* + * tonal_context_improv() + * + * Context-based improvement of 1st/2nd stage speech/music decision on stable tonal signals + *----------------------------------------------------------------------------------*/ + +static void tonal_context_improv( + Encoder_State *st, /* i/o: encoder state structure */ + const float PS[], /* i : energy spectrum */ + short *sp_aud_decision1, /* i/o: 1st stage speech/music decision */ + short *sp_aud_decision2, /* i/o: 2nd stage speech/music decision */ + const short vad_flag, + const short pitch[3], /* i : open-loop pitch estimate in three subframes */ + const float voicing[3], /* i : voicing estimate in three subframes */ + const float voi_fv, /* i : scaled voicing feature */ + const float cor_map_sum_fv, /* i : scaled correlation map feature */ + const float LPCErr /* i : scaled LP prediction error feature */ +) +{ + short lt_pitch_diff; + float sort_max, sort_avg, sort_val[80]; + float tonality, tonality1, tonality2, tonality3, t2, t3, tL, err, cor, dft; + + /* reset in case of codec mode swithing */ + if( st->last_codec_mode == MODE2 ) + { + set_f( st->tonality2_buf, 0, HANG_LEN_INIT ); + set_f( st->tonality3_buf, 0, HANG_LEN_INIT ); + set_f( st->LPCErr_buf, 0, HANG_LEN_INIT ); + st->lt_music_hangover = 0; + st->lt_music_state = 0; + st->lt_speech_state = 0; + st->lt_speech_hangover= 0; + } + + /* estimate maximum tonality in bands [0-1 kHz], [1-2kHz] and [2-4kHz] */ + mvr2r( PS, sort_val, 80 ); + + /* tonality in band 0-1 kHz */ + v_sort(sort_val, 0, 19); + sort_max = sort_val[19]; + sort_avg = sum_f(&sort_val[0], 10); + tonality1 = sort_max / sort_avg; + + /* tonality in band 1-2 kHz */ + v_sort(sort_val, 20, 39); + sort_max = sort_val[39]; + sort_avg = sum_f(&sort_val[20], 10); + tonality2 = sort_max / sort_avg; + + /* tonality in band 2-4 kHz */ + v_sort(sort_val, 40, 79); + sort_max = sort_val[79]; + sort_avg = sum_f(&sort_val[40], 20); + tonality3 = sort_max / sort_avg; + + tonality = max(max(tonality1, tonality2), tonality3); + + if( st->hangover_cnt == 10 && vad_flag == 1 ) + { + /* long-term voicing parameter */ + st->lt_voicing = 0.1f * st->lt_voicing + 0.9f * *voicing; + + /* long-term correlation value */ + st->lt_corr = 0.1f * st->lt_corr + 0.9f * st->old_corr; + + /* long-term tonality measure */ + st->lt_tonality = 0.1f * st->lt_tonality + 0.9f * tonality; + } + else + { + /* long-term voicing parameter */ + st->lt_voicing = 0.7f * st->lt_voicing + 0.3f * *voicing; + + /* long-term correlation value */ + st->lt_corr = 0.7f * st->lt_corr + 0.3f * st->old_corr; + + /* long-term tonality measure */ + st->lt_tonality = 0.5f * st->lt_tonality + 0.5f * tonality; + } + + /* pitch difference w.r.t to past 3 frames */ + lt_pitch_diff = (short)abs(st->lt_corr_pitch[0] - pitch[0]); + lt_pitch_diff += (short)abs(st->lt_corr_pitch[1] - pitch[0]); + lt_pitch_diff += (short)abs(st->lt_corr_pitch[2] - pitch[0]); + + st->lt_corr_pitch[0] = st->lt_corr_pitch[1]; + st->lt_corr_pitch[1] = st->lt_corr_pitch[2]; + st->lt_corr_pitch[2] = pitch[0]; + + st->lt_old_mode[0] = st->lt_old_mode[1]; + st->lt_old_mode[1] = st->lt_old_mode[2]; + + if ( *sp_aud_decision1 == 1 && + ( min(min(tonality1, tonality2), tonality3) > 50.0f ) && + ( tonality1+tonality2 > 200.0f && tonality2 + tonality3 > 200.0f && tonality1 + tonality3 > 200.0f ) && + ( st->lt_tonality < 20000.0f ) && + ( ( st->lt_tonality > 1000 && max(st->lt_voicing, *voicing) > 0.99f ) || + ( st->lt_tonality > 1500 && st->lt_corr > 0.99f ) || + ( st->lt_tonality > 3000 && st->lowrate_pitchGain > 0.96f ) || + ( lt_pitch_diff == 0 && st->lowrate_pitchGain > 0.89f ) ) ) + { + if( sum_s(st->lt_old_mode, 2) < 2 ) + { + /* probably speech - change the decision to speech */ + *sp_aud_decision1 = 0; + *sp_aud_decision2 = 0; + + if( st->lt_hangover == 0 ) + { + st->lt_hangover = 6; + } + } + } + else + { + /* not speech, but still in the hangover period - change the decision to speech */ + if( st->lt_hangover > 0 ) + { + *sp_aud_decision1 = 0; + *sp_aud_decision2 = 0; + st->lt_hangover--; + } + } + + /* calculate standard deviation of log-tonality */ + mvr2r( st->tonality2_buf + 1, st->tonality2_buf, HANG_LEN_INIT - 1 ); + st->tonality2_buf[HANG_LEN_INIT - 1] = 0.2f*(float)log10(tonality2); + t2 = std_dev( st->tonality2_buf, HANG_LEN_INIT ); + + mvr2r( st->tonality3_buf + 1, st->tonality3_buf, HANG_LEN_INIT - 1 ); + st->tonality3_buf[HANG_LEN_INIT - 1] = 0.2f*(float)log10(tonality3); + t3 = std_dev( st->tonality3_buf, HANG_LEN_INIT ); + + tL = 0.2f*(float)log10(st->lt_tonality); + + /* calculate standard deviation of residual LP energy */ + mvr2r( st->LPCErr_buf + 1, st->LPCErr_buf, HANG_LEN_INIT - 1 ); + st->LPCErr_buf[HANG_LEN_INIT - 1] = LPCErr; + err = std_dev( st->LPCErr_buf, HANG_LEN_INIT ); + + cor = max( voi_fv - cor_map_sum_fv, 0.0f ); + dft = 0.2f * (float) fabs( log10(tonality2) - log10(tonality3) ); + + /* state machine for strong music */ + if( *sp_aud_decision1 == 1 && st->lt_music_state == 0 && st->lt_music_hangover == 0 && + t2 < 0.54f && t2 > 0.26f && t3 > 0.22f && tL < 0.54f && tL > 0.26f && err > 0.5f ) + { + st->lt_music_state = 1; + st->lt_music_hangover = 6; + } + else if( st->lt_music_state == 1 && st->lt_music_hangover == 0 && + t2 < 0.34 && t3 < 0.26f && tL < 0.45f) + { + st->lt_music_state = 0; + st->lt_music_hangover = 6; + } + + if( st->lt_music_hangover > 0 ) + { + st->lt_music_hangover--; + } + + /* state machine for strong speech */ + if( *sp_aud_decision1 == 1 && st->lt_speech_state == 0 && st->lt_speech_hangover == 0 && + cor > 0.40f && dft < 0.1f && voi_fv > 2 * cor_map_sum_fv + 0.12f && + t2 < cor && t3 < cor && tL < cor && cor_map_sum_fv < cor && voi_fv > cor && voi_fv > 0.76f ) + { + st->lt_speech_state = 1; + st->lt_speech_hangover = 6; + } + else if( st->lt_speech_state == 1 && st->lt_speech_hangover == 0 && cor < 0.40f ) + { + st->lt_speech_state = 0; + st->lt_speech_hangover = 6; + } + + if( st->lt_speech_hangover > 0 ) + { + st->lt_speech_hangover--; + } + + /* final decision */ + if ( *sp_aud_decision1 == 1 && st->lt_speech_state == 1 ) + { + /* strong speech - probably error in speech/music classification */ + *sp_aud_decision1 = 0; + *sp_aud_decision2 = 0; + } + else if ( *sp_aud_decision1 == 0 && st->lt_music_state == 1 ) + { + /* strong music - probably error in speech/music classification */ + *sp_aud_decision1 = 1; + *sp_aud_decision2 = 1; + } + + /* update the buffer of past decisions */ + st->lt_old_mode[2] = *sp_aud_decision1; + + return; +} + +/*---------------------------------------------------------------------* + * detect_sparseness() + * + * + *---------------------------------------------------------------------*/ + +static void detect_sparseness( + Encoder_State *st, /* i/o: encoder state structure */ + const short localVAD_HE_SAD, /* i : HE-SAD flag without hangover */ + short *sp_aud_decision1, /* i/o: 1st stage speech/music decision */ + short *sp_aud_decision2, /* i/o: 2nd stage speech/music decision */ + const float voi_fv /* i : scaled voicing feature */ +) +{ + float sum; + float ftmp; + float ftmp1; + float S1[128]; + short i,j; + short hb_sp_high_flag = 0; + short lb_sp_high_flag = 0; + float sumh; + float sparse; + float tmp_buf[4]; + float Mlpe = 0.0f; + float Mv = 0.0f; + float Msp; + + mvr2r( st->Bin_E, S1, 128 ); + + sum = 0; + for ( i=0; i<80; i++ ) + { + if ( S1[i] < 0 ) + { + S1[i] = 0; + } + sum += S1[i]; + } + + sumh = 0; + for ( i=80; i<128; i++ ) + { + if ( S1[i] < 0 ) + { + S1[i] = 0; + } + sumh += S1[i]; + } + + sum += sumh; + + /* order spectral from max to min */ + order_spectrum(S1, 128); + + /* calculate spectral sparseness in the range 0 - 6.4 kHz */ + j = 0; + ftmp = 0.0f; + ftmp1 = 0.75f * sum; + for ( i=0; i<128; i++ ) + { + ftmp += S1[i]; + if ( ftmp > ftmp1 ) + { + j = i; + break; + } + } + + for ( i=0; isparse_buf[i] = st->sparse_buf[i+1]; + } + + sparse = (float)j; + st->sparse_buf[i] = sparse; + + if ( st->bwidth == WB ) + { + Msp = mean(st->sparse_buf, 8); + + /* find long-term smoothed sparseness */ + if ( st->last_vad_spa == 0 ) + { + set_f( &st->sparse_buf[0], sparse, HANG_LEN_INIT-1 ); + st->LT_sparse = sparse; + } + else + { + set_f(tmp_buf, 0.0f, 4); + + for ( i=0; isparse_buf[i] > tmp_buf[j] ) + { + mvr2r(&tmp_buf[j], &tmp_buf[j+1], 3-j); + tmp_buf[j] = st->sparse_buf[i]; + break; + } + } + } + + ftmp = 0.25f*(HANG_LEN_INIT*Msp - sum_f(tmp_buf, 4)) - st->LT_sparse; + + st->LT_sparse = st->LT_sparse + 0.25f * ftmp; + } + + /* find high-band sparseness */ + mvr2r(st->Bin_E+80, S1, 48); + order_spectrum(S1, 48); + + for ( i=0; ihf_spar_buf[i] = st->hf_spar_buf[i+1]; + } + st->hf_spar_buf[i] = sum_f(S1, 5)/(sumh + 0.1f); + if ( mean(st->hf_spar_buf, 8) > 0.2f ) + { + hb_sp_high_flag = 1; + } + + /* find low-band sparseness */ + mvr2r(st->Bin_E, S1, 60); + order_spectrum(S1, 60); + + if ( sum_f(S1, 5)/sum_f(S1,60) > 0.18f ) + { + lb_sp_high_flag = 1; + } + + /* find smoothed linear prediction efficiency */ + for ( i=0; i<7; i++ ) + { + st->lpe_buf[i] = st->lpe_buf[i+1]; + } + + st->lpe_buf[i] = st->past_epsP2; + Mlpe = mean(st->lpe_buf, 8); + + /* find smoothed voicing */ + for ( i=0; ivoicing_buf[i] = st->voicing_buf[i+1]; + } + + st->voicing_buf[i] = voi_fv; + Mv = mean(st->voicing_buf, 8); + } + + /* avoid using LR-MDCT on sparse spectra */ + if ( *sp_aud_decision1 == 1 ) + { + if ( st->bwidth == WB ) + { + ftmp = 90; + } + else + { + ftmp = 91; + } + if ( sparse > ftmp ) + { + *sp_aud_decision1 = 0; + *sp_aud_decision2 = 1; + st->gsc_hangover = 1; + } + else if ( st->gsc_hangover == 1 ) + { + if ( sparse > 85 ) + { + *sp_aud_decision1 = 0; + *sp_aud_decision2 = 1; + } + else if ( fabs(sparse - mean(&st->sparse_buf[HANG_LEN_INIT-1-st->gsc_cnt], st->gsc_cnt)) < 7.0f ) + { + *sp_aud_decision1 = 0; + *sp_aud_decision2 = 1; + } + } + + if ( st->bwidth == WB ) + { + if ( st->LT_sparse > 60 && sparse > 50 && Mlpe < -1.3f && Mv > 0.85f && + lb_sp_high_flag == 0 && ( (hb_sp_high_flag == 0 && sumh > 0.15f * sum) || sumh <= 0.15f * sum ) ) + { + *sp_aud_decision1 = 0; + *sp_aud_decision2 = 1; + st->gsc_hangover = 1; + } + else if ( st->gsc_hangover == 1 && !( *sp_aud_decision1 == 0 && *sp_aud_decision2 == 1) ) + { + if ( fabs(sparse - mean(&st->sparse_buf[HANG_LEN_INIT-1-st->gsc_cnt], st->gsc_cnt)) < 7.0f ) + { + *sp_aud_decision1 = 0; + *sp_aud_decision2 = 1; + } + } + } + } + + /* update the counter of consecutive GSC frames with sparse spectrum */ + if ( *sp_aud_decision1 == 0 && *sp_aud_decision2 == 1 ) + { + (st->gsc_cnt)++; + if ( st->gsc_cnt > 7 ) + { + st->gsc_cnt = 7; + } + } + else + { + st->gsc_cnt = 0; + st->gsc_hangover = 0; + } + + st->last_vad_spa = localVAD_HE_SAD; + + return; +} + + +static void order_spectrum( float *vec, short len ) +{ + short i, j, imax, imin; + float temp; + + for (i = 0; i vec[imax]) + { + imax = j; + } + else + { + if (vec[j] < vec[imin]) + { + imin = j; + } + } + } + + temp = vec[i]; + vec[i] = vec[imax]; + vec[imax] = temp; + + if (imin == i) imin = imax; + + temp = vec[len - i - 1]; + vec[len - i - 1] = vec[imin]; + vec[imin] = temp; + } + + return; +} + + diff --git a/src/libs/libevs/lib_enc/speech_music_classif_fx.cpp b/src/libs/libevs/lib_enc/speech_music_classif_fx.cpp deleted file mode 100755 index 954d180f..00000000 --- a/src/libs/libevs/lib_enc/speech_music_classif_fx.cpp +++ /dev/null @@ -1,2884 +0,0 @@ -/*==================================================================================== - EVS Codec 3GPP TS26.442 Apr 03, 2018. Version 12.11.0 / 13.6.0 / 14.2.0 - ====================================================================================*/ - -#include -#include -#include "options.h" -#include "cnst_fx.h" -#include "prot_fx.h" -#include "rom_enc_fx.h" -#include "rom_com_fx.h" -#include "stl.h" - -/*---------------------------------------------------------------------* - * Local constants - *---------------------------------------------------------------------*/ -#define ATT_NSEG 32 -#define ATT_SEG_LEN (L_FRAME/ATT_NSEG) -#define ATT_3LSUB_POS (3 * ATT_NSEG / NB_SUBFR) -#define ATT_3LSUB_POS_16k 26 /* (short)((4.0f * ATT_NSEG / (float)NB_SUBFR16k) + 0.5f) */ - -#define LOG_PROB_CONST 11292 /*0.5f * N_FEATURES * LOG_PI2 in Q10 */ - -/*---------------------------------------------------------------------* - * Local functions - *---------------------------------------------------------------------*/ - -static Word16 sp_mus_classif_gmm_fx( Encoder_State_fx *st_fx, const Word16 localVAD, const Word16 pitch[3], const Word16 voicing[3], - const Word16 lsp_new[M], const Word16 cor_map_sum, const Word32 epsP[M+1], const Word32 PS[], - Word16 non_sta, Word16 relE, Word16 *voi_fv, Word16 *cor_map_sum_fv, Word16 *LPCErr, Word16 Q_esp - , Word16 *high_lpn_flag_ptr); - - -static void sp_mus_classif_2nd_fx( Encoder_State_fx *st, const Word16 sp_aud_decision1, Word16 *sp_aud_decision2, - const Word16 pitch[3], const Word16 Etot, Word16 *coder_type, Word16 *attack_flag, - const Word16 *inp, const Word16 Qx, const Word16 localVAD, const Word16 vad_flag ); - -static void music_mixed_classif_improv_fx( Encoder_State_fx *st, const Word16 *new_inp, Word16 *sp_aud_decision1, Word16 vad_flag, - const Word16 *voicing, const Word32 *epsP, Word16 Q_epsP, Word16 etot, Word16 old_cor, - Word16 cor_map_sum ); - -static void tonal_context_improv_fx( Encoder_State_fx *st_fx, const Word32 PS[], Word16 *sp_aud_decision1, Word16 *sp_aud_decision2, - const Word16 vad_flag, const Word16 pitch[3], const Word16 voicing[3], const Word16 voi_fv, - const Word16 cor_map_sum_fv, const Word16 LPCErr, const Word16 Qx ); - -static void var_cor_calc_fx( const Word16 old_corr, Word16 *mold_corr, Word16 var_cor_t[], Word16 *high_stable_cor ); - -static Word16 attack_det_fx( const Word16 *inp, const Word16 Qx, const Word16 last_clas, const Word16 localVAD, const Word16 coder_type - ,const Word32 total_brate - - ); - -static void order_spectrum_fx( Word16 *vec, Word16 len ); - -static void detect_sparseness_fx( Encoder_State_fx *st_fx, const Word16 localVAD_HE_SAD, Word16 *sp_aud_decision1, - Word16 *sp_aud_decision2, const Word16 voi_fv ); - - -/*---------------------------------------------------------------------* - * speech_music_classif() - * - * Speech/music classification - * - * The following technologies are used based on the outcome of the sp/mus classifier - * sp_aud_decision1 sp_aud_decision2 - * 0 0 use ACELP (+TD BWE) - * 1 0 use ACELP (+FD BWE) or HQ/LR-MDCT depending on bitrate - * 1 1 use GSC (+FD BWE) or HQ/LR-MDCT depending on bitrate - * - * 0 1 exceptionally use GSC (+FD BWE) instead of LR-MDCT at 13.2 kbps (WB/SWB) for sparse spectra - *---------------------------------------------------------------------*/ - -void speech_music_classif_fx( - Encoder_State_fx *st, /* i/o: state structure */ - Word16 *sp_aud_decision0, - Word16 *sp_aud_decision1, /* o : 1st stage speech/music decision for GSC */ - Word16 *sp_aud_decision2, /* o : 2nd stage speech/music decision for GSC */ - const Word16 *new_inp, /* i : new input signal */ - const Word16 *inp, /* i : input signal to locate attach position */ - const Word16 vad_flag, - const Word16 localVAD, - const Word16 localVAD_HE_SAD, /* i : HE-SAD flag without hangover */ - const Word16 pitch[3], /* i : open-loop pitch estimate in three subframes */ - const Word16 voicing[3], /* i : voicing estimate in three subframes Q15 */ - const Word16 lsp_new[M], /* i : LSPs in current frame Q15 */ - const Word16 cor_map_sum, /* i : correlation map sum (from multi-harmonic anal.)Q8*/ - const Word32 epsP[M+1], /* i : LP prediciton error Q_esp*/ - const Word32 PS[], /* i : energy spectrum Q_new+QSCALE*/ - const Word16 Etot, /* i : total frame energy Q8 */ - const Word16 old_cor, /* i : max correlation from previous frame Q15 */ - Word16 *coder_type, /* i/o: coding type */ - Word16 *attack_flag, /* o : flag to indicate if attack is to be treated by TC or GSC */ - Word16 non_sta, /* i : unbound non-stationarity for sp/mus classifier */ - Word16 relE, /* i : relative frame energy */ - Word16 Q_esp, /* i : scaling of esP */ - Word16 Q_inp, /* i : scaling of input */ - Word16 *high_lpn_flag_ptr, /* o : noise log prob flag for NOISE_EST */ - Word16 flag_spitch /* i : flag to indicate very short stable pitch */ -) -{ - Word16 voi_fv, cor_map_sum_fv, LPCErr; - - - /* 1st stage speech/music classifier based on the GMM model */ - *sp_aud_decision1 = sp_mus_classif_gmm_fx( st, localVAD_HE_SAD, pitch, voicing, lsp_new, cor_map_sum, - epsP, PS, non_sta, relE, &voi_fv, &cor_map_sum_fv, &LPCErr, - - - Q_esp, high_lpn_flag_ptr ); - - test(); - IF ( sub( st->codec_mode, MODE1) == 0 || L_sub(st->sr_core, 12800) == 0 ) - { - - - /* Improvement of the 1st stage decision on mixed/music content */ - test(); - IF ( st->Opt_SC_VBR_fx == 0 && ( L_sub(st->total_brate_fx, ACELP_24k40) != 0 ) ) - { - - - music_mixed_classif_improv_fx( st, new_inp, sp_aud_decision1, vad_flag, voicing, epsP, Q_esp, Etot, - old_cor, cor_map_sum ); - - - } - - *sp_aud_decision0 = *sp_aud_decision1; - - - /* 2nd stage speech/music classifier (rewrite music to speech in onsets) */ - *sp_aud_decision2 = *sp_aud_decision1; - move16(); - - IF ( sub(st->bwidth_fx,NB) > 0 ) - { - sp_mus_classif_2nd_fx( st, *sp_aud_decision1, sp_aud_decision2, pitch, Etot, coder_type, - attack_flag, inp, Q_inp-1, localVAD, vad_flag ); - - /* avoid switch to AUDIO/MUSIC class for very short stable high pitch - and/or stable pitch with high correlation at low bitrates*/ - test(); - test(); - IF ( flag_spitch && sub(st->bwidth_fx,WB) == 0 && L_sub(st->total_brate_fx,ACELP_13k20) < 0 ) - { - *sp_aud_decision2 = 0; - move16(); - } - } - - - - /* Context-based improvement of 1st and 2nd stage decision on stable tonal signals */ - test(); - IF ( st->Opt_SC_VBR_fx == 0 && ( L_sub(st->total_brate_fx, ACELP_24k40) != 0 ) ) - { - tonal_context_improv_fx( st, PS, sp_aud_decision1, sp_aud_decision2, vad_flag, pitch, voicing, - voi_fv, cor_map_sum_fv, LPCErr, Q_inp + QSCALE -2 ); - } - - /* Avoid using LR-MDCT on sparse spectra, use GSC instead at 13.2 kbps (WB/SWB) */ - test(); - test(); - test(); - test(); - IF ( !st->Opt_SC_VBR_fx && L_sub(st->total_brate_fx, ACELP_13k20) == 0 && sub(vad_flag, 1) == 0 && - ( sub(st->bwidth_fx, WB) == 0 || sub(st->bwidth_fx, SWB) == 0 ) ) - { - detect_sparseness_fx( st, localVAD_HE_SAD, sp_aud_decision1, sp_aud_decision2, voi_fv ); - } - - /* override speech/music classification to ACELP when background noise level reaches certain level */ - /* this is a patch against mis-classifications during active noisy speech segments */ - IF ( sub(st->lp_noise_fx, 3072) > 0 ) - { - *sp_aud_decision1 = 0; - move16(); - *sp_aud_decision2 = 0; - move16(); - } - - - /* select GSC on SWB noisy speech (only on active unvoiced SWB noisy speech segments) */ - st->GSC_noisy_speech_fx = 0; - move16(); - test(); - test(); - test(); - test(); - test(); - test(); - IF ( sub(vad_flag,1) == 0 && L_sub(st->total_brate_fx,ACELP_13k20) >= 0 && L_sub(st->total_brate_fx,ACELP_24k40) < 0 && - sub(st->lp_noise_fx,3072) > 0 && *sp_aud_decision1 == 0 && sub(st->bwidth_fx,SWB) >= 0 && - sub(st->coder_type_raw_fx,UNVOICED) == 0 ) - { - st->GSC_noisy_speech_fx = 1; - move16(); - } - - /* Select AUDIO frames */ - test(); - test(); - test(); - test(); - IF ( sub(st->codec_mode,MODE1) == 0 && ( *sp_aud_decision2 || st->GSC_noisy_speech_fx ) ) - { - *coder_type = AUDIO; - move16(); - st->noise_lev_fx = NOISE_LEVEL_SP0; - move16(); - } - - } - - return; -} - -/*---------------------------------------------------------------------* - * sp_mus_classif_gmm_fx() - * - * Speech/music classification based on GMM model - *---------------------------------------------------------------------*/ - -static Word16 sp_mus_classif_gmm_fx( /* o : decision flag (1-music, 0-speech or noise) */ - Encoder_State_fx *st_fx, /* i/o: state structure */ - const Word16 localVAD, - const Word16 pitch[3], /* i : open-loop pitch estimate in three subframes Q0 */ - const Word16 voicing[3], /* i : voicing estimate in three subframes Q15 */ - const Word16 lsp_new[M], /* i : LSPs in current frame Q15 */ - const Word16 cor_map_sum, /* i : correlation map sum (from multi-harmonic anal.)Q8 */ - const Word32 epsP[M+1], /* i : LP prediciton error Q_esp */ - const Word32 PS[], /* i : energy spectrum Q_new+Qscale-2 */ - Word16 non_sta, /* i : unbound non-stationarity for sp/mus classifier */ - Word16 relE, /* i : relative frame energy */ - Word16 *voi_fv, /* o : scaled voicing feature */ - Word16 *cor_map_sum_fv, /* o : scaled correlation map feature */ - Word16 *LPCErr, /* o : scaled LP prediction error feature */ - Word16 Q_esp /* i : scaling of epsP */ - ,Word16 *high_lpn_flag_ptr /* o : noise log prob flag for NOISE_EST */ -) -{ - Word16 i, k, p, dec, vad; - - Word16 lsp[M], FV[N_FEATURES], *pFV = FV; - const Word32 *pSF_a; - const Word16 *pSF_m; - Word16 lsf2acos_fact, wrelE, dlp, wdrop, wght; - - Word32 mx; - Word32 sum_PS; - Word16 ftmp, tmp16; - Word16 xm[N_FEATURES]; - Word16 lps, lpm; - Word16 lpn; - Word16 e_tmp, f_tmp; - Word32 L_tmp; - Word16 exp1; - Word32 ps_sta; - Word32 ps_diff; - Word16 ps_diff_16; - Word32 dPS[128], PS_norm[128]; - Word32 lepsP1; - Word32 max_s=0, max_m=0, py_s, py_m; - Word32 max_n, py_n; /* pyn */ - Word16 ishift[12] = {8,0,2,2,2,2,2,1,0,2,2,1}; - Word16 tmp; - Word16 tmp1,tmp2,exp2,scale,exp3; - - /*------------------------------------------------------------------* - * Initialization - *------------------------------------------------------------------*/ - - vad = localVAD; - move16(); - - /*------------------------------------------------------------------* - * Preparation of the feature vector - *------------------------------------------------------------------*/ - - /* [0] OL pitch Q0 */ - /*(float)(pitch[0] + pitch[1] + pitch[2]) / 3.0f;*/ - L_tmp = L_mult(pitch[0], 10923); - L_tmp = L_mac(L_tmp, pitch[1], 10923); - L_tmp = L_mac(L_tmp, pitch[2], 10923); - - test(); - IF ( sub(st_fx->tc_cnt_fx,1) == 0 || sub(st_fx->tc_cnt_fx,2) == 0 ) - { - *pFV++ = pitch[2]; - move16(); - } - ELSE - { - *pFV++ = round_fx(L_tmp); - } - - /* [1] voicing Q15 */ - /*(float)(voicing[0] + voicing[1] + voicing[2]) / 3.0f*/ - test(); - IF ( sub(st_fx->tc_cnt_fx,1) == 0 || sub(st_fx->tc_cnt_fx,2) == 0 ) - { - *pFV++ = voicing[2]; - move16(); - } - ELSE - { - L_tmp = L_mult(voicing[0], 10923); - L_tmp = L_mac(L_tmp, voicing[1], 10923); - L_tmp = L_mac(L_tmp, voicing[2], 10923); - *pFV++ = round_fx(L_tmp); - } - - /* [2,3,4,5,6] LSFs Q15*/ - Copy( lsp_new, lsp, M ); - lsf2acos_fact = 25735; - move16(); /* PI/6400 -> Q27 */ - - /*ftmp = (float)acos(lsp[1...5]);*/ - /**pFV++ = ftmp + st->last_lsp[1...5];*/ - /*st->last_lsp[1...5] = ftmp;*/ - FOR(i= 1; i < M_LSP_SPMUS; i++) - { - L_tmp = sub_lsp2lsf_fx(lsp[i]); - tmp16 = round_fx(L_shl(L_mult0(extract_l(L_tmp),lsf2acos_fact),2)); - *pFV++ = add(tmp16,st_fx->last_lsp_fx[i]); - move16(); /*Q13*/ - st_fx->last_lsp_fx[i] = tmp16; - move16(); - } - - /* [7] cor_map_sum Q8 */ - *pFV++ = round_fx(L_mac(L_mult(cor_map_sum, 16384), st_fx->last_cor_map_sum_fx, 16384)); /* Q8 ->Q7*/ - st_fx->last_cor_map_sum_fx = cor_map_sum; - move16(); - - /* [8] non_sta Q8*/ - *pFV++ = round_fx(L_mac(L_mult(non_sta,16384), st_fx->last_non_sta_fx, 16384)); /* Q8 -> Q7 */ - st_fx->last_non_sta_fx = non_sta; - move16(); - - /* [9] epsP Q10 */ - IF ( sub(st_fx->bwidth_fx,NB) == 0) - { - *pFV++ = -1687; - move16(); /*Q10*/ - } - ELSE - { - /*lepsP1 = (float)log(epsP[1] + 1e-5f);*/ - IF(epsP[1] != 0) - { - e_tmp = norm_l(epsP[1]); - f_tmp = Log2_norm_lc(L_shl(epsP[1],e_tmp)); - e_tmp = sub(30,add(e_tmp,Q_esp)); - lepsP1 = Mpy_32_16(e_tmp, f_tmp, 22713); /* Q16 */ /* 22713 = ln(2) in Q15 */ - } - ELSE - { - lepsP1 = L_deposit_l(0); - } - - /*ftmp = (float)log(epsP[13]);*/ - IF(epsP[13] != 0) - { - e_tmp = norm_l(epsP[13]); - f_tmp = Log2_norm_lc(L_shl(epsP[13],e_tmp)); - e_tmp = sub(30,add(e_tmp,Q_esp)); - L_tmp = Mpy_32_16(e_tmp, f_tmp, 22713); /* Q16 */ /* 22713 = ln(2) in Q15 */ - } - ELSE - { - L_tmp = L_deposit_l(0); - } - - /*ftmp = (float)log(epsP[13]) - lepsP1;*/ - L_tmp = L_sub(L_tmp, lepsP1); /*Q16 */ - ftmp = round_fx(L_shl(L_tmp,10)); /*Q10 */ - - /**pFV++ = ftmp + st->past_epsP2;*/ - *pFV++ = add(ftmp,st_fx->past_epsP2_fx); - move16(); /*Q10 */ - - /*st->past_epsP2 = ftmp;*/ - st_fx->past_epsP2_fx = ftmp; - move16(); /*Q10 */ - } - - /* calculation of differential normalized power spectrum */ - sum_PS = L_deposit_l(0); - FOR ( i = LOWEST_FBIN; i < HIGHEST_FBIN; i++ ) - { - sum_PS = L_add(sum_PS,PS[i]); - } - exp1 = norm_l(sum_PS); - tmp1 = round_fx(L_shl(sum_PS,exp1)); - exp1 = sub(30,exp1); - - FOR ( i = LOWEST_FBIN; i < HIGHEST_FBIN; i++ ) - { - /*PS_norm[i] = PS[i] / sum_PS;*/ - /*dPS[i] = (float)fabs(PS_norm[i] - st->past_PS[i]);*/ - exp2 = norm_l(PS[i]); - tmp2 = round_fx(L_shl(PS[i],exp2)); - exp2 = sub(30,exp2); - - scale = shr(sub(tmp1, tmp2), 15); - tmp2 = shl(tmp2, scale); - exp2 = sub(exp2, scale); - - exp3 = sub(exp1,exp2); - - tmp = div_s(tmp2, tmp1); /*Q(15+exp3) */ - PS_norm[i] = L_shl(tmp,sub(10,exp3)); - move32(); /*Q25 */ - dPS[i] = L_abs(L_sub(PS_norm[i],st_fx->past_PS_fx[i-LOWEST_FBIN])); - move32(); /*Q25 */ - } - - /* [10] ps_diff (spectral difference) Q10*/ - ps_diff = 0; - move16(); - FOR ( i = LOWEST_FBIN; i < HIGHEST_FBIN; i++ ) - { - /*ps_diff += dPS[i];*/ - ps_diff = L_add(ps_diff,dPS[i]); /*Q25*/ - } - - /*ps_diff = (float)log(ps_diff + 1e-5f);*/ - IF( ps_diff != 0 ) - { - e_tmp = norm_l(ps_diff); - f_tmp = Log2_norm_lc(L_shl(ps_diff,e_tmp)); - e_tmp = sub(30-25,e_tmp); - ps_diff = Mpy_32_16(e_tmp, f_tmp, 22713);/* Q16 */ /* 22713 = ln(2) in Q15 */ - ps_diff_16 = round_fx(L_shl(ps_diff,10)); /*Q10 */ - } - ELSE - { - ps_diff_16 = -11789; - move16(); /*Q10 */ - } - - *pFV++ = add(ps_diff_16, st_fx->past_ps_diff_fx); - move16();/*Q10 */ - st_fx->past_ps_diff_fx = ps_diff_16; - move16(); /*Q10 */ - - /* [11] ps_sta (spectral stationarity) Q11 */ - ps_sta = 0; - move16(); - FOR ( i = LOWEST_FBIN; i < HIGHEST_FBIN; i++ ) - { - /*mx = PS_norm[i] > st->past_PS[i] ? PS_norm[i] : st->past_PS[i];*/ - IF (L_sub(PS_norm[i],st_fx->past_PS_fx[i-LOWEST_FBIN]) > 0) - { - mx = PS_norm[i]; - move16(); /*Q25 */ - } - ELSE - { - mx = st_fx->past_PS_fx[i-LOWEST_FBIN]; - move16(); /*Q25 */ - } - - /*ps_sta += mx / (dPS[i] + 1e-5f);*/ - IF( !dPS[i] ) - { - ps_sta = L_add(ps_sta,L_shr(mx,9)); /*Q16 */ - } - ELSE - { - exp1 = norm_l(L_add(dPS[i],336)); - tmp1 = round_fx(L_shl(L_add(dPS[i],336),exp1)); - exp1 = sub(30,exp1); - - exp2 = norm_l(mx); - tmp2 = round_fx(L_shl(mx,exp2)); - exp2 = sub(30,exp2); - - scale = shr(sub(tmp1, tmp2), 15); - tmp2 = shl(tmp2, scale); - exp2 = sub(exp2, scale); - - exp3 = sub(exp1,exp2); - move16(); - - tmp = div_s(tmp2, tmp1); /*Q(15+exp3) */ - L_tmp = L_shl(tmp,sub(1,exp3)); /*Q16 */ - ps_sta = L_add(ps_sta,L_tmp); /*Q16 */ - } - } - - /**pFV++ = (float)log(ps_sta + 1e-5f);*/ - ps_sta = L_add(ps_sta, 336); - e_tmp = norm_l(ps_sta); - f_tmp = Log2_norm_lc(L_shl(ps_sta,e_tmp)); - e_tmp = sub(30-16,e_tmp); - L_tmp = Mpy_32_16(e_tmp, f_tmp, 22713); /* Q16 */ /* 22713 = ln(2) in Q15 */ - *pFV++ = round_fx(L_shl(L_tmp,11)); /*Q11 */ - - /* update PS vector */ - Copy32( &PS_norm[LOWEST_FBIN], st_fx->past_PS_fx, HIGHEST_FBIN-LOWEST_FBIN ); - - /*------------------------------------------------------------------* - * Scaling of the feature vector - *------------------------------------------------------------------*/ - - /* FV[0] -> Q0 */ - /* FV[1...6] -> Q13*/ - /* FV[7,8] -> Q7 */ - /* FV[9,10] -> Q10 */ - /* FV[11] -> Q11 */ - - - pFV = FV; - move16(); - IF ( sub(st_fx->bwidth_fx,NB) == 0 ) - { - pSF_m = SF_8k_mult_fx; - pSF_a = SF_8k_add_fx; - } - ELSE - { - pSF_m = SF_mult_fx; - pSF_a = SF_add_fx; - } - - FOR ( i=0; i 0) - && (sub(lpn, lpm) > 0) ) - { - *high_lpn_flag_ptr = 1; - move16(); - } - - - IF ( !vad ) - { - /* increase log-probability of noise */ - /* lps = lpn * 1.2f; */ - lps = add(lpn,mult_r(6554,lpn)); /* Q9 */ - } - - st_fx->lpm_fx = lpm; - move16(); - st_fx->lps_fx = lps; - move16(); - - /* determine HQ GENERIC speech class */ - st_fx->hq_generic_speech_class_fx = 0; - move16(); - if( sub(lps,add(lpm,256)) > 0 ) - { - st_fx->hq_generic_speech_class_fx = 1; - move16(); - } - - - /*------------------------------------------------------------------* - * State machine (sp_mus_state < 0 .. inactive, > 0 .. entry, = 0 .. active ) - *------------------------------------------------------------------*/ - - IF ( vad ) - { - test(); - test(); - test(); - IF ( sub(relE,-20*256) < 0 || (sub(lps,-5*512) <= 0 && sub(lpm,-5*512) <= 0) ) - { - IF ( st_fx->sp_mus_state_fx > 0 ) - { - if ( sub(st_fx->sp_mus_state_fx,HANG_LEN) < 0 ) - { - /* energy is too low but we are in entry period -> reset the inactive counter to allow new entry later */ - st_fx->inact_cnt_fx = 0; - move16(); - } - - /* energy is too low -> we are going to instable state */ - st_fx->sp_mus_state_fx = 0; - move16(); - } - ELSE IF ( sub(st_fx->sp_mus_state_fx,-HANG_LEN) > 0 ) - { - /* energy is still too low -> we are still in instable state */ - st_fx->sp_mus_state_fx = sub(st_fx->sp_mus_state_fx,1); - } - } - ELSE IF ( st_fx->sp_mus_state_fx <= 0 ) - { - IF ( st_fx->inact_cnt_fx == 0 ) - { - - st_fx->sp_mus_state_fx = 1; - move16(); - } - ELSE - { - - st_fx->sp_mus_state_fx = HANG_LEN; - move16(); - } - - st_fx->inact_cnt_fx = 12; - move16(); - } - ELSE IF ( st_fx->sp_mus_state_fx > 0 && sub(st_fx->sp_mus_state_fx,HANG_LEN) < 0 ) - { - /* we are inside an entry period -> increment the counter of entry frames */ - st_fx->sp_mus_state_fx = add(st_fx->sp_mus_state_fx,1); - } - - test(); - if ( st_fx->sp_mus_state_fx < 0 && st_fx->inact_cnt_fx > 0 ) - { - st_fx->inact_cnt_fx = sub(st_fx->inact_cnt_fx,1); - } - } - ELSE - { - test(); - IF ( st_fx->sp_mus_state_fx > 0 && sub(st_fx->sp_mus_state_fx,HANG_LEN) < 0 ) - { - st_fx->inact_cnt_fx = 0; - move16(); - } - ELSE IF ( st_fx->inact_cnt_fx > 0 ) - { - st_fx->inact_cnt_fx = sub(st_fx->inact_cnt_fx,1); - } - - test(); - IF ( st_fx->sp_mus_state_fx > 0 && sub(st_fx->sp_mus_state_fx,HANG_LEN) < 0 ) - { - - st_fx->sp_mus_state_fx = -HANG_LEN; - move16(); - } - ELSE IF ( st_fx->sp_mus_state_fx > 0 ) - { - - st_fx->sp_mus_state_fx = -1; - move16(); - } - ELSE IF ( sub(st_fx->sp_mus_state_fx,-HANG_LEN) > 0 ) - { - /* we are in inactive state */ - st_fx->sp_mus_state_fx = sub(st_fx->sp_mus_state_fx,1); - } - } - - /*------------------------------------------------------------------* - * Decision without hangover - * Weighted decision - *------------------------------------------------------------------*/ - - /* decision without hangover (0 - speech/noise, 1 - music) */ - logic16(); - dec = sub(lpm,lps) > 0; - move16(); - dlp = sub(lpm,lps); /*Q9*/ - - IF ( !vad ) - { - dec = 0; - move16(); - dlp = 0; - move16(); - } - - /* calculate weight based on relE (close to 0.01 in low-E regions, close to 1 in high-E regions) */ - /*wrelE = 1.0f + relE/15;*/ - wrelE = add(2048, mult_r(relE,17476)); /* 1/15 in Q18 -> 17476 result in Q11 */ - - - wrelE = s_min(wrelE, 2048); - wrelE = s_max(wrelE, 20); - - /* calculate weight based on drops of dlp (close to 1 during sudden drops of dlp, close to 0 otherwise) */ - test(); - IF ( dlp < 0 && sub(dlp,st_fx->past_dlp_fx[0]) < 0 ) - { - IF ( st_fx->past_dlp_fx[0] > 0 ) - { - st_fx->wdrop_fx = negate(dlp); /*Q9*/ - } - ELSE - { - st_fx->wdrop_fx = add(st_fx->wdrop_fx, sub(st_fx->past_dlp_fx[0], dlp)); /*Q9*/ - } - } - ELSE - { - st_fx->wdrop_fx = 0; - move16(); - } - - /*wdrop = st->wdrop/20;*/ - wdrop = mult_r(st_fx->wdrop_fx, 26214); /*Q9*Q19->Q13*/ - wdrop = s_min(wdrop,8192); /* limitation [0.1,1] Q13 */ - wdrop = s_max(wdrop,819); - - /* combine weights into one */ - /*wght = wrelE * wdrop;*/ - wght = mult_r(wrelE, wdrop); /* Q11*Q13 -> Q9*/ - wght = s_max(wght,5); - - /* calculate weighted decision */ - /*st->wdlp_0_95_sp = wght * dlp + (1 - wght) * st->wdlp_0_95_sp;*/ - /* = Q9 * Q9 + (Q9-Q9)*Q9 */ - L_tmp = L_mac(L_mult(wght, dlp), sub(512, wght), st_fx->wdlp_0_95_sp_fx); - st_fx->wdlp_0_95_sp_fx = round_fx(L_shl(L_tmp, 6)); - - if ( sub(st_fx->sp_mus_state_fx,-HANG_LEN) == 0 ) - { - st_fx->wdlp_0_95_sp_fx = 0; - move16(); - } - - /*------------------------------------------------------------------* - * Final speech/music decision - *------------------------------------------------------------------*/ - - test(); - test(); - IF ( !vad && sub(st_fx->sp_mus_state_fx,-HANG_LEN) == 0 ) - { - /* inactive state */ - dec = 0; - move16(); - } - ELSE IF ( st_fx->sp_mus_state_fx <= 0 ) - { - /* transition from active to inactive state or instable state */ - dec = st_fx->past_dec_fx[0]; - move16(); - } - ELSE IF ( st_fx->sp_mus_state_fx > 0 && sub(st_fx->sp_mus_state_fx,HANG_LEN) < 0 ) - { - /* entry state -> final decision is calculated based on weighted average of past non-binary decisions */ - L_tmp = L_mult(w_spmus_fx[st_fx->sp_mus_state_fx-1][0], dlp); /*Q15*Q9 */ - - /*ftmp += dotp( &w[st_fx->sp_mus_state_fx-1][1], st_fx->past_dlp_fx, HANG_LEN-1 );*/ - L_tmp = L_add(L_tmp, Dot_product( &w_spmus_fx[st_fx->sp_mus_state_fx-1][1], st_fx->past_dlp_fx, HANG_LEN-1 )); - logic16(); - move16(); - - /*dec = ftmp > 2.0f;*/ - dec = L_sub(L_tmp, 2*(1<<25))>0; - } - ELSE - { - /* stable active state */ - test(); - test(); - test(); - test(); - IF ( st_fx->wdlp_0_95_sp_fx > 0 && st_fx->past_dec_fx[0] == 0 && st_fx->past_dec_fx[1] == 0 && st_fx->past_dec_fx[2] == 0 ) - { - /* switching from speech to music */ - dec = 1; - move16(); - } - ELSE IF ( st_fx->past_dec_fx[0] == 1 && st_fx->wdlp_0_95_sp_fx < 0 ) - { - /* switching from music to speech */ - dec = 0; - move16(); - } - ELSE - { - dec = st_fx->past_dec_fx[0]; - move16(); - } - } - - - /*------------------------------------------------------------------* - * Updates - *------------------------------------------------------------------*/ - - /* update the buffer of past non-binary decisions */ - Copy( &st_fx->past_dlp_fx[0], &st_fx->past_dlp_fx[1], HANG_LEN-2 ); - st_fx->past_dlp_fx[0] = dlp; - move16(); - - /* update the buffer of past binary decisions */ - Copy( &st_fx->past_dec_fx[0], &st_fx->past_dec_fx[1], HANG_LEN-2 ); - st_fx->past_dec_fx[0] = dec; - move16(); - - return dec; -} - - -/*---------------------------------------------------------------------* - * sp_mus_classif_2nd_fx() - * - * 2nd stage speech/music classifier (convert music to speech for onsets) - *---------------------------------------------------------------------*/ - -static void sp_mus_classif_2nd_fx( - Encoder_State_fx *st, /* i/o: Encoder state structure */ - const Word16 sp_aud_decision1, /* i : 1st stage decision flag */ - Word16 *sp_aud_decision2, /* i/o: 2nd stage decision flag */ - const Word16 pitch[3], /* i : open-loop pitch estimate in three subframes */ - const Word16 Etot, /* i : total frame energy */ - Word16 *coder_type, /* i/o: coder type */ - Word16 *attack_flag, /* i/o: attack flag (GSC or TC) */ - const Word16 *inp, /* i : input signal */ - const Word16 Qx, - const Word16 localVAD, - const Word16 vad_flag -) -{ - Word16 attack; - - /* initialization */ - *attack_flag = 0; - move16(); - - /* signal stability estimation */ - stab_est_fx( Etot, st->gsc_lt_diff_etot_fx, &st->gsc_mem_etot_fx - , &st->gsc_nb_thr_3_fx, &st->gsc_nb_thr_1_fx, st->gsc_thres_fx, &st->gsc_last_music_flag_fx, vad_flag ); - - /* calculate variance of correlation */ - var_cor_calc_fx( st->old_corr_fx, &st->mold_corr_fx, st->var_cor_t_fx, &st->high_stable_cor_fx ); - - /* attack detection */ - attack = attack_det_fx( inp, Qx, st->clas_fx, localVAD, *coder_type - , st->total_brate_fx); - - test(); - test(); - test(); - test(); - test(); - test(); - IF( sub(sp_aud_decision1,1) == 0 ) - { - test(); - test(); - test(); - IF( sub(st->ener_RAT_fx,5898) < 0 && sub (st->lt_dec_thres_fx,7680) > 0 ) - { - *sp_aud_decision2 = 0; - move16(); - } - ELSE IF( sub(st->high_stable_cor_fx, 1) == 0 && sub(pitch[0], 130) >= 0 ) - { - /* prevent GSC in highly correlated signal with low energy variation */ - /* this is basically a patch against bassoon-type of music */ - *sp_aud_decision2 = 0; - move16(); - - test(); - IF( sub(st->codec_mode,MODE1) == 0 && sub(*coder_type,TRANSITION) == 0 ) - { - *coder_type = GENERIC; - move16(); - } - } - ELSE IF( sub(st->gsc_lt_diff_etot_fx[MAX_LT-1],1152) > 0 && - sub(sub(st->gsc_lt_diff_etot_fx[MAX_LT-1], st->gsc_lt_diff_etot_fx[MAX_LT-2]),2560) > 0 ) /* 10.0f in Q8 */ - { - IF ( sub(st->tc_cnt_fx,1) == 0 ) - { - *sp_aud_decision2 = 0; - move16(); - - IF( sub(st->codec_mode,MODE1) == 0 ) - { - *coder_type = TRANSITION; - move16(); - } - } - ELSE - { - IF( sub(attack, ATT_3LSUB_POS) >= 0 ) - { - /* do TC coding if attack is located in the last subframe */ - *sp_aud_decision2 = 0; - move16(); - *attack_flag = 1; - move16(); - IF( sub(st->codec_mode,MODE1) == 0 ) - { - *coder_type = TRANSITION; - move16(); - } - } - ELSE IF( sub(attack,ATT_SEG_LEN/2) >= 0 ) - { - /* do GSC coding if attack is located after the first quarter of the first subframe */ - /* (pre-echo will be treated at the decoder side) */ - *attack_flag = 1; - move16(); - } - } - } - } - ELSE IF( sub(localVAD,1) == 0 && sub(*coder_type,GENERIC) == 0 && - ( (sub(attack,ATT_3LSUB_POS) >= 0 && L_sub(st->total_brate_fx,ACELP_24k40) < 0) || - (sub(attack,ATT_3LSUB_POS_16k) >= 0 && L_sub(st->total_brate_fx,ACELP_24k40) >= 0 && L_sub(st->total_brate_fx,ACELP_48k) < 0) ) - ) - { - /* do TC coding if attack is located in the last subframe */ - *attack_flag = 1; - move16(); - IF( sub(st->codec_mode,MODE1) == 0 ) - { - *coder_type = TRANSITION; - move16(); - } - } - - return; -} - - -/*---------------------------------------------------------------------* - * var_cor_calc_fx() - * - * Calculate variance of correlation - *---------------------------------------------------------------------*/ - -static void var_cor_calc_fx( - const Word16 old_corr, - Word16 *mold_corr, - Word16 var_cor_t[], - Word16 *high_stable_cor -) -{ - Word16 i, var_cor; - - /* update buffer of old correlation values */ - FOR( i = VAR_COR_LEN-1; i > 0; i-- ) - { - var_cor_t[i] = var_cor_t[i-1]; /*Q11*/ move16(); - } - var_cor_t[i] = old_corr; - move16(); - - /* calculate variance of correlation */ - var_cor = var_fx( var_cor_t, 11, VAR_COR_LEN ); - - *high_stable_cor = 0; - move16(); - test(); - IF( sub(*mold_corr,26214) > 0 && sub(var_cor,2) < 0 ) - { - *high_stable_cor = 1; - move16(); - } - - /* update average correlation */ - /*st->mold_corr = 0.1f * st->old_corr + 0.9f * st->mold_corr;*/ - *mold_corr = mac_r(L_mult(3277,old_corr),29491,*mold_corr); /*Q15 */ - - return; -} - -/*---------------------------------------------------------------------* - * attack_det_fx() - * - * Attack detection - *---------------------------------------------------------------------*/ - -static Word16 attack_det_fx( /* o : attack flag */ - const Word16 *inp, /* i : input signal */ - const Word16 Qx, - const Word16 last_clas, /* i : last signal clas */ - const Word16 localVAD, - const Word16 coder_type /* i : coder type */ - ,const Word32 total_brate /* i : total bit-rate */ -) -{ - Word16 i, j, tmp, tmp1, attack, exp1; - Word32 L_tmp, etmp, etmp2, finc[ATT_NSEG]; - Word16 att_3lsub_pos; - - att_3lsub_pos = ATT_3LSUB_POS; - move16(); - if( L_sub(total_brate,ACELP_24k40) >= 0 ) - { - att_3lsub_pos = ATT_3LSUB_POS_16k; - move16(); - } - - /* compute energy per section */ - FOR( i=0; i 0 ) - { - /* stop, if the attack is not sufficiently strong */ - attack = 0; - move16(); - } - - test(); - if( sub(last_clas,VOICED_CLAS) == 0 && L_sub(L_add(L_shl(etmp,4),L_shl(etmp,2)),etmp2) > 0 ) - { - /* stop, if the signal was voiced and the attack is not sufficiently strong */ - attack = 0; - move16(); - } - - /* compare also wrt. other sections (reduces a misclassification) */ - IF( attack > 0 ) - { - etmp2 = L_add(finc[attack], 0); - etmp = Mult_32_16(etmp2, 16384); /* etmp2 / 2.0 = (etmp2*0.5) */ - FOR( i=2; i 0 ) - { - attack = 0; - move16(); - BREAK; - } - } - } - } - ELSE IF( attack > 0 ) - { - etmp2 = L_add(finc[attack], 0); - etmp = Mult_32_16(etmp2, 25206); /* etmp2 / 1.3 = (etmp2*0.76923) */ - FOR( i=2; i etmp2 ) -> finc[i] > (etmp2*0.76923) */ - test(); - IF( sub(i,attack) != 0 && L_sub(finc[i],etmp) > 0 ) - { - attack = 0; - move16(); - BREAK; - } - } - } - - return attack; -} - -/*---------------------------------------------------------------------* - * mode_decision_fx() - * - * - *---------------------------------------------------------------------*/ - -static Word16 mode_decision_fx( - Encoder_State_fx *st, /* i : endoer state structure */ - Word16 len, /* i : buffering status */ - Word16 *dec_mov, /* i/o: moving average of classifier decision Q15*/ - Word16 *buf_flux, /* i : buffer storing spectral energy fluctuation Q7*/ - Word16 *buf_epsP_tilt, /* i : buffer storing LP prediciton error tilt Q15*/ - Word16 *buf_pkh, /* i : buffer storing highband spectral peakiness Q1*/ - Word16 *buf_cor_map_sum, /* i : buffer storing correlation map sum Q8*/ - Word16 *buf_Ntonal, /* i : buffer storing No.of 1st spectral tone Q0*/ - Word16 *buf_Ntonal2, /* i : buffer storing No.of 2nd spectral tone Q0*/ - Word16 *buf_Ntonal_lf, /* i : buffer storing low band spectral tone ratio Q0*/ - Word16 *buf_dlp /* i : buffer storing log probability diff between speech and music Q9*/ -) -{ - Word16 mode; - Word16 i; - Word16 voiced_cnt; - Word16 M_pkh; - Word16 M_cor_map_sum; - Word16 M_Ntonal; - Word16 M_flux; - Word32 V_epsP_tilt; - Word16 lf_Ntonal_ratio; - Word16 tmp, tmp1; - Word32 L_tmp; - Word16 inv_len; - Word16 j; - Word16 M_flux10; - - - mode = *dec_mov > 16384; - logic16(); - move16(); - - IF ( sub(len,5) <= 0 ) - { - return (mode); - } - ELSE - { - IF ( sub(len,10) < 0 ) - { - inv_len = div_s(1,len); /*Q15 */ - - L_tmp = L_deposit_l(0); - FOR(i=0; i3; i-- ) - { - if ( buf_dlp[i] > 0 ) - { - voiced_cnt = add(voiced_cnt,1); - } - } - - test(); - test(); - test(); - test(); - IF ( (sub(M_pkh,2200) > 0 || L_sub(V_epsP_tilt,171799) < 0 || sub(M_cor_map_sum,25600) > 0) && voiced_cnt < 4 ) - { - mode = 1; - move16(); - } - ELSE IF ( sub(M_Ntonal,108) > 0 && voiced_cnt < 4 ) /*27 in Q2 */ - { - mode = 1; - move16(); - } - } - ELSE - { - voiced_cnt = 0; - move16(); - FOR ( i=0; i<10; i++ ) - { - if ( buf_dlp[i] > 0 ) - { - voiced_cnt = add(voiced_cnt,1); - } - } - - inv_len = 3277; /*Q15 */ - - L_tmp = L_deposit_l(0); - FOR(i=0; i<10; i++) - { - L_tmp = L_add(L_tmp,L_shl(buf_flux[BUF_LEN-10+i],2)); /*Q9 */ - } - L_tmp = Mult_32_16(L_tmp,inv_len); /*Q9 */ - M_flux10 = extract_l(L_tmp); /*Q9 */ - - L_tmp = L_deposit_l(0); - FOR(i=0; i<10; i++) - { - L_tmp = L_add(L_tmp,buf_pkh[BUF_LEN-10+i]); /*Q1 */ - } - L_tmp = Mult_32_16(L_tmp,inv_len); /*Q1 */ - M_pkh = extract_l(L_tmp); /*Q1 */ - - L_tmp = L_deposit_l(0); - FOR(i=0; i<10; i++) - { - L_tmp = L_add(L_tmp,buf_cor_map_sum[BUF_LEN-10+i]); /*Q8 */ - } - L_tmp = Mult_32_16(L_tmp,inv_len); /*Q8 */ - M_cor_map_sum = extract_l(L_tmp); /*Q8 */ - - V_epsP_tilt = var_fx_32( buf_epsP_tilt+BUF_LEN-10, 15, 10 ); /*Q31 */ - - L_tmp = L_deposit_l(0); - FOR(i=0; i<5; i++) - { - L_tmp = L_add(L_tmp,L_shl(buf_flux[BUF_LEN-5+i],2)); /*Q9 */ - } - L_tmp = Mult_32_16(L_tmp,6554); /*Q9 */ - tmp = extract_l(L_tmp); /*Q9 */ - - test(); - test(); - test(); - test(); - test(); - test(); - IF ( (sub(M_flux10,4352) < 0 || (L_sub(V_epsP_tilt,2147484) < 0 && sub(M_flux10,6144) < 0)|| sub(M_pkh,2100) > 0 || sub(M_cor_map_sum,25600) > 0) && - sub(voiced_cnt,3) < 0 && sub(tmp,7680) < 0 ) - { - mode = 1; - move16(); - *dec_mov = 32767; - move16(); - return ( mode ); - } - - test(); - test(); - test(); - test(); - test(); - IF ( sub(M_flux10,8192) > 0 || (sub(M_flux10,7680) > 0 && voiced_cnt > 2) || sub(tmp,9728) > 0 || (sub(buf_flux[59],2560) >= 0 && sub(st->lps_fx,st->lpm_fx) > 0) ) - { - mode = 0; - move16(); - *dec_mov = 0; - move16(); - return ( mode ); - } - - FOR ( i=10; i 0 || - sub(M_cor_map_sum,sub(24320,extract_l(L_mult0(77,sub(len,10))))) > 0) && sub(voiced_cnt,3) < 0 ) - { - mode = 1; - move16(); - return( mode ); - } - } - - IF ( sub(len,BUF_LEN) == 0 ) - { - tmp = 0; - move16(); - FOR(i=0; i 0 || sub(lf_Ntonal_ratio,6554) < 0 ) - { - mode = 1; - move16(); - } - ELSE IF ( sub(M_Ntonal,4) < 0 ) - { - mode = 0; - move16(); - } - } - } - } - - return ( mode ); -} - -/*---------------------------------------------------------------------* -* tonal_dist_fx() -* -* -*---------------------------------------------------------------------*/ - -static void tonal_dist_fx( - Word16 *p2v_map, /* i : spectral peakiness map Q7*/ - Word16 *buf_pkh, /* i/o: buffer storing highband spectral peakiness Q1*/ - Word16 *buf_Ntonal, /* i/o: buffer storing No.of 1st spectral tone Q0*/ - Word16 *buf_Ntonal2, /* i/o: buffer storing No.of 2nd spectral tone Q0*/ - Word16 *buf_Ntonal_lf /* i/o: buffer storing low band spectral tone ratio Q0*/ -) -{ - Word16 i; - Word32 pk; - Word16 Ntonal; - Word16 Ntonal2; - Word16 Ntonal_lf; - - - /* find number of tonals, number of tonals at low-band, - spectral peakiness at high-band */ - pk = L_deposit_l(0); - Ntonal = 0; - move16(); - Ntonal2 = 0; - move16(); - Ntonal_lf = 0; - move16(); - FOR ( i=0; i<64; i++ ) - { - if ( sub(p2v_map[i],7040) > 0 ) - { - Ntonal = add(Ntonal,1); - } - - IF ( sub(p2v_map[i],10240) > 0 ) - { - Ntonal2 = add(Ntonal2,1); - Ntonal_lf = add(Ntonal_lf,1); - } - } - - FOR ( i=64; i<127; i++ ) - { - if ( p2v_map[i] != 0 ) - { - pk = L_add(pk,p2v_map[i]); /*Q7 */ - } - if ( sub(p2v_map[i],7040) > 0 ) - { - Ntonal = add(Ntonal,1); - } - if ( sub(p2v_map[i],10240) > 0 ) - { - Ntonal2 = add(Ntonal2,1); - } - } - - /* update buffers */ - FOR ( i=0; i 0 && sub(dec_mov,26214) > 0 ) - { - flux = 2560; - move16(); /*20 in Q7 */ - } - - /* update old Bin_E buffer */ - pt1 = old_Bin_E; - pt2 = old_Bin_E + N_OLD_BIN_E; - pt3 = Bin_E; - pt4 = old_Bin_E + N_OLD_BIN_E; - pt5 = old_Bin_E + 2*N_OLD_BIN_E; - pt6 = old_Bin_E + 2*N_OLD_BIN_E; - - FOR ( i=0; i 0 && sub(Bin_E[i],Bin_E[i+1]) > 0 ) - { - peak[k] = Bin_E[i]; - move16(); - peak_idx[k] = i; - move16(); - k = add(k,1); - } - } - assert(k+1<65); - peak_idx[k] = -1; - move16(); - peak_idx[k+1] = -1; - move16(); - IF ( k == 0 ) - { - FOR ( i=0; i<127; i++ ) - { - p2v_map[i] = 0; - move16(); - } - - return; - } - - /* find spectral valleys */ - m = 0; - move16(); - - IF ( sub(Bin_E[0],Bin_E[1]) < 0 ) - { - valley[0] = Bin_E[0]; - move16(); - valey_idx[0] = 0; - move16(); - m = add(m,1); - } - - k = 126; - move16(); - FOR ( i=125; i>=0; i-- ) - { - IF (sub(Bin_E[i+1],Bin_E[i]) <= 0) - { - BREAK; - } - k = i; - move16(); - } - - FOR ( i=1; i 0 && sub(peak_idx[k],valey_idx[i+1]) < 0 ) - { - p2v[k] = sub(shl(peak[k],1),add(valley[i],valley[i+1])); - k = add(k,1); - } - } - - FOR ( i=0; i<127; i++ ) - { - p2v_map[i] = 0; - move16(); - } - - FOR ( i=0; ilp_speech_fx,st->lp_noise_fx),6400) < 0 ) /* 25 in Q8 */ - { - /* st->dec_mov = 0.5f; */ - /* st->dec_mov1 = 0.5f; */ - st->dec_mov_fx = 16384; - move16(); - st->dec_mov1_fx = 16384; - move16(); - - if ( vad_flag == 0 ) - { - st->onset_cnt_fx = 0; - move16(); - } - - return; - } - - st->onset_cnt_fx = add(st->onset_cnt_fx,1); - st->onset_cnt_fx = s_min(st->onset_cnt_fx, 9); - - IF ( sub(st->onset_cnt_fx,1) == 0 ) - { - set16_fx( st->buf_flux_fx, -12800, BUF_LEN ); /*-100.0 in Q7 */ - } - - /* spectral analysis */ - spec_analysis_fx( st->lgBin_E_fx, p2v_map ); - - /* percussive music detection */ - log_max_spl = 0; - move16(); - IF ( max_spl ) - { - L_tmp = L_deposit_h(max_spl); /*Q16 */ - exp = norm_l(L_tmp); - frac = Log2_norm_lc(L_shl(L_tmp,exp)); - exp = sub(sub(30,exp),16); - L_tmp = Mpy_32_16(exp,frac,28391); /*Q12 */ - log_max_spl = round_fx(L_shl(L_tmp,11)); /*Q7 */ - } - - lt_diff = sub(log_max_spl,st->mov_log_max_spl_fx); /*Q7 */ - - FOR ( i=0; i<3; i++ ) - { - st->buf_etot_fx[i] = st->buf_etot_fx[i+1]; - move16(); /*Q8 */ - } - st->buf_etot_fx[i] = etot; - move16();/*Q8 */ - - percus_flag = 0; - move16(); - test(); - test(); - IF ( sub(sub(st->buf_etot_fx[1],st->buf_etot_fx[0]),1536) > 0 && - sub(st->buf_etot_fx[2],st->buf_etot_fx[1]) < 0 && - sub(sub(st->buf_etot_fx[1],st->lp_speech_fx),768) > 0 ) /* 3 in Q8 */ - { - /*tmp = add(shr(voicing[0],2),shr(voicing[1],2)); //Q15 */ - /*tmp = add(tmp,shr(old_cor,1)); //Q15 */ - tmp = mac_r(L_mac(L_mult(voicing[0],8192),voicing[1],8192),old_cor, 16384); - test(); - test(); - IF ( sub(sub(st->buf_etot_fx[1],st->buf_etot_fx[3]),768) > 0 && - sub(st->buf_etot_fx[3],st->buf_etot_fx[2]) < 0 && - sub(tmp,24576) < 0 ) /* 0.75 in Q15 */ - { - IF ( sub(st->dec_mov_fx,26214) > 0 ) /* 0.8 in Q15 */ - { - percus_flag = 1; - move16(); - } - ELSE - { - test(); - test(); - test(); - IF ( sub(old_cor,24576) < 0 && sub(voicing[0],24576) < 0 && sub(voicing[1],24576) < 0 && sub(st->old_lt_diff_fx[0],1280) > 0 ) - { - percus_flag = 1; - move16(); - } - } - } - } - - /* sound attack detection */ - test(); - test(); - test(); - IF ( sub(sub(st->buf_etot_fx[3],st->buf_etot_fx[2]),1536) > 0 - && sub(st->dec_mov_fx,29491) > 0 - && sub(sub(etot,st->lp_speech_fx),1280) > 0 - && sub(st->old_lt_diff_fx[0],640) > 0 ) - { - st->attack_hangover_fx = 3; - move16(); - } - - test(); - IF ( sub(voicing[0],29491) > 0 && sub(voicing[1],29491) > 0 ) - { - IF ( sub(log_max_spl,st->mov_log_max_spl_fx) > 0 ) - { - /**mov_log_max_spl = add(mult_r(31130,(*mov_log_max_spl)),mult_r(1638,log_max_spl)); //Q7 */ - st->mov_log_max_spl_fx = round_fx(L_mac(L_mult(31130,st->mov_log_max_spl_fx),1638,log_max_spl)); /*Q7 */ - } - ELSE - { - /**mov_log_max_spl = add(mult_r(32604,(*mov_log_max_spl)),mult_r(164,log_max_spl)); //Q7 */ - st->mov_log_max_spl_fx = round_fx(L_mac(L_mult(32604,st->mov_log_max_spl_fx),164,log_max_spl)); /*Q7 */ - } - } - - st->old_lt_diff_fx[0] = st->old_lt_diff_fx[1]; - move16(); /*Q7 */ - st->old_lt_diff_fx[1] = lt_diff; - move16(); /*Q7 */ - - /* calculate and buffer spectral energy fluctuation */ - flux_fx( st->lgBin_E_fx, p2v_map, st->old_Bin_E_fx, st->buf_flux_fx, st->attack_hangover_fx, st->dec_mov_fx ); - - st->attack_hangover_fx = sub(st->attack_hangover_fx,1); - st->attack_hangover_fx = s_max(st->attack_hangover_fx,0); - - /* identify flux buffer buffering status */ - len = 0; - move16(); - FOR ( i=BUF_LEN-1; i>=0; i-- ) - { - IF (st->buf_flux_fx[i] < 0) - { - BREAK; - } - - len = add(len,1); - } - - /* reset flux buffer if percussive music is detected */ - IF ( sub(percus_flag,1) == 0 ) - { - set16_fx( &st->buf_flux_fx[BUF_LEN-len], 640, len ); /* 5 in Q7 */ - } - - /* calculate and buffer the tilt of residual LP energies */ - ftmp = 0; - move16(); - ftmp1 = 0; - move16(); - FOR( i=1; i<=16; i++ ) - { - epsP_max = L_max(epsP_max , epsP[i]); - } - - FOR ( i=1; i<16; i++ ) - { - IF(L_sub(epsP[i], epsP_max) == 0) - { - tmp = -32768; - move16(); - L_tmp = Mult_32_16(epsP[i],tmp); /* Q_epsP */ - ftmp = L_sub(ftmp,L_shr(L_tmp,4)); /* Q(Q_epsP-4) */ - } - ELSE - { - expn = norm_l(epsP[i]); - fracn = extract_h(L_shl(epsP[i],expn)); - expn = sub(sub(30,expn),Q_epsP); - - expd = norm_l(epsP_max); - fracd = extract_h(L_shl(epsP_max,expd)); - expd = sub(sub(30,expd),Q_epsP); - - scale = shr(sub(fracd,fracn),15); - fracn = shl(fracn,scale); - expn = sub(expn,scale); - - tmp = div_s(fracn,fracd); /*Q(15+expd-expn) */ - tmp = shl(tmp,sub(expn,expd)); /*Q15 */ - - L_tmp = Mult_32_16(epsP[i],tmp); /*Q_epsP */ - ftmp = L_add(ftmp,L_shr(L_tmp,4)); /*Q(Q_epsP-4) */ - } - } - - FOR ( i=1; i<16; i++ ) - { - IF(L_sub(epsP[i], epsP_max) == 0) - { - tmp = -32768; - move16(); - L_tmp = Mult_32_16(epsP[i+1],tmp); /*Q_epsP */ - ftmp1 = L_sub(ftmp1,L_shr(L_tmp,4)); /*Q(Q_epsP-4) */ - } - ELSE IF(L_sub(epsP[i+1],epsP_max) == 0) - { - tmp = -32768; - move16(); - L_tmp = Mult_32_16(epsP[i],tmp); /*Q_epsP */ - ftmp1 = L_sub(ftmp1,L_shr(L_tmp,4)); /*Q(Q_epsP-4) */ - } - ELSE - { - expn = norm_l(epsP[i]); - fracn = extract_h(L_shl(epsP[i],expn)); - expn = sub(sub(30,expn),Q_epsP); - - expd = norm_l(epsP_max); - fracd = extract_h(L_shl(epsP_max,expd)); - expd = sub(sub(30,expd),Q_epsP); - - scale = shr(sub(fracd,fracn),15); - fracn = shl(fracn,scale); - expn = sub(expn,scale); - - tmp = div_s(fracn,fracd); /*Q(15+expd-expn) */ - tmp = shl(tmp,sub(expn,expd)); /*Q15 */ - - L_tmp = Mult_32_16(epsP[i+1],tmp); /*Q_epsP */ - ftmp1 = L_add(ftmp1,L_shr(L_tmp,4)); /*Q(Q_epsP-4) */ - } - } - - /* epsP_tilt = ftmp1/ftmp; */ - expn = norm_l(ftmp1); - fracn = extract_h(L_shl(ftmp1,expn)); - expn = sub(sub(30,expn),Q_epsP-4); - - expd = norm_l(ftmp); - fracd = round_fx(L_shl(ftmp,expd)); - expd = sub(sub(30,expd),sub(Q_epsP,4)); - - scale = shr(sub(fracd,fracn),15); - fracn = shl(fracn,scale); - expn = sub(expn,scale); - - tmp = div_s(fracn,fracd); /*Q(15+expd-expn) */ - - epsP_tilt = shl(tmp,sub(expn,expd)); /*Q15 */ - - FOR ( i=0; ibuf_epsP_tilt_fx[i] = st->buf_epsP_tilt_fx[i+1]; - move16(); /*Q15 */ - } - st->buf_epsP_tilt_fx[i] = epsP_tilt; - move16(); /*Q15 */ - - /* calculate and buffer highband spectral peakness */ - tonal_dist_fx( p2v_map, st->buf_pkh_fx, st->buf_Ntonal_fx, st->buf_Ntonal2_fx, st->buf_Ntonal_lf_fx ); - - /* buffer sum of correlation map */ - FOR ( i=0; ibuf_cor_map_sum_fx[i] = st->buf_cor_map_sum_fx[i+1]; - move16(); /*Q8 */ - } - st->buf_cor_map_sum_fx[i] = cor_map_sum; - move16(); /*Q8 */ - - /* buffer voicing metric */ - FOR ( i=0; i<9; i++ ) - { - st->buf_dlp_fx[i] = st->buf_dlp_fx[i+1]; - move16(); - } - st->buf_dlp_fx[i] = sub(st->lps_fx, st->lpm_fx); - move16();/*Q9 */ - - /* classification */ - dec = mode_decision_fx( st, len, &st->dec_mov_fx, st->buf_flux_fx, st->buf_epsP_tilt_fx, st->buf_pkh_fx, - st->buf_cor_map_sum_fx, st->buf_Ntonal_fx, st->buf_Ntonal2_fx, st->buf_Ntonal_lf_fx, - st->buf_dlp_fx ); - move16(); - - /* update long term moving average of the classification decisions */ - IF ( sub(len,30) > 0 ) - { - IF( dec == 0 ) - { - st->dec_mov_fx = mult_r(31785,st->dec_mov_fx); /*Q15 */ - st->dec_mov1_fx = mult_r(31785,st->dec_mov1_fx); /*Q15 */ - } - ELSE - { - st->dec_mov_fx = add(mult_r(31785,st->dec_mov_fx),983); /*Q15 */ - st->dec_mov1_fx = add(mult_r(31785,st->dec_mov1_fx),983); /*Q15 */ - } - } - - /* update long term unvoiced counter */ - test(); - test(); - test(); - IF ( (sub(st->coder_type_raw_fx,UNVOICED) == 0 || sub(st->coder_type_raw_fx,INACTIVE) == 0) && - sub(etot,384) > 0 && sub(st->buf_Ntonal2_fx[59],2) < 0 ) - { - st->UV_cnt1_fx = sub(st->UV_cnt1_fx,8); - } - ELSE - { - st->UV_cnt1_fx = add(st->UV_cnt1_fx,1); - } - - st->UV_cnt1_fx = s_min(st->UV_cnt1_fx,300); - st->UV_cnt1_fx = s_max(st->UV_cnt1_fx,0); - - /**LT_UV_cnt1 = add(mult_r(29491,*LT_UV_cnt1),mult_r(3277,shl(*UV_cnt1,6)));*/ /* Q6 */ - st->LT_UV_cnt1_fx = round_fx(L_mac(L_mult(29491,st->LT_UV_cnt1_fx),3277,shl(st->UV_cnt1_fx,6))); /*Q6 */ - - /* revert classification decision due to long-term unvoiced counter */ - test(); - test(); - IF ( sub(dec,1) == 0 && sub(st->dec_mov1_fx,6554) < 0 && sub(st->LT_UV_cnt1_fx,12800) < 0 ) - { - dec = 0; - move16(); - } - - /* overwrite 1st stage speech/music decision to music */ - IF (sub(dec,1) == 0 ) - { - *sp_aud_decision1 = 1; - move16(); - } - - return; -} - - - -/*----------------------------------------------------------------------------------* - * tonal_context_improv_fx() - * - * Context-based improvement of 1st/2nd stage speech/music decision on stable tonal signals - *----------------------------------------------------------------------------------*/ - -static void tonal_context_improv_fx( - Encoder_State_fx *st_fx, /* i/o: Encoder state structure */ - const Word32 PS[], /* i : energy spectrum */ - Word16 *sp_aud_decision1, /* i/o: 1st stage speech/music decision */ - Word16 *sp_aud_decision2, /* i/o: 2nd stage speech/music decision */ - const Word16 vad_flag, - const Word16 pitch[3], /* i : open-loop pitch estimate in three subframes */ - const Word16 voicing[3], /* i : voicing estimate in three subframes */ - const Word16 voi_fv, /* i : scaled voicing feature */ - const Word16 cor_map_sum_fv, /* i : scaled correlation map feature */ - const Word16 LPCErr, /* i : scaled LP prediction error feature */ - const Word16 Qx -) -{ - Word16 t2_fx, t3_fx, tL_fx, err_fx, cor_fx, dft_fx; - Word16 exp, expa, expb, fraca, fracb, scale, exp1, exp2, exp3, tmp; - Word16 voi_mean, lt_pitch_diff; - Word32 L_tmp, tonality, tonality1, tonality2, tonality3, sort_max, sort_avg, sort_val[80]; - - IF ( sub(st_fx->last_codec_mode, MODE2) == 0) - { - set16_fx(st_fx->tonality2_buf_fx,0,HANG_LEN_INIT); - set16_fx(st_fx->tonality3_buf_fx,0,HANG_LEN_INIT); - set16_fx(st_fx->LPCErr_buf_fx,0,HANG_LEN_INIT); - st_fx->lt_music_hangover_fx = 0; - move16(); - st_fx->lt_music_state_fx = 0; - move16(); - st_fx->lt_speech_state_fx = 0; - move16(); - st_fx->lt_speech_hangover_fx= 0; - move16(); - } - - /* estimate maximum tonality in bands [0-1 kHz], [1-2kHz] and [2-4kHz] */ - Copy32( PS, sort_val, 80 ); - - /* tonality in band [0-1 kHz] */ - sort_32_fx(sort_val, 0, 19); - sort_max = L_add(sort_val[19], 0); - sort_avg = sum32_fx(&sort_val[0], 10); - - /* tonality1 = sort_max / sort_avg; */ - IF( sort_avg ) - { - expa = norm_l(sort_max); - fraca = extract_h(L_shl(sort_max,expa)); - expa = sub(30,add(expa, Qx)); - - expb = norm_l(sort_avg); - fracb = extract_h(L_shl(sort_avg,expb)); - expb = sub(30,add(expb, Qx)); - - scale = shr(sub(fracb,fraca),15); - fraca = shl(fraca,scale); - expa = sub(expa,scale); - - tmp = div_s(fraca,fracb); - exp1 = sub(expa,expb); - - tonality1 = L_shl(tmp , exp1); - } - ELSE - { - tonality1 = L_shl(sort_max,sub(15,Qx)); /*Q15 */ - } - - /* tonality in band [1-2 kHz] */ - sort_32_fx(sort_val, 20, 39); - sort_max = sort_val[39]; - sort_avg = sum32_fx(&sort_val[20], 10); - - IF( sort_avg ) - { - /* tonality2 = sort_max / sort_avg; */ - expa = norm_l(sort_max); - fraca = extract_h(L_shl(sort_max,expa)); - expa = sub(30,add(expa, Qx)); - - - expb = norm_l(sort_avg); - fracb = extract_h(L_shl(sort_avg,expb)); - expb = sub(30,add(expb, Qx)); - - scale = shr(sub(fracb,fraca),15); - fraca = shl(fraca,scale); - expa = sub(expa,scale); - - tmp = div_s(fraca,fracb); - exp2 = sub(expa,expb); - - tonality2 = L_shl(tmp , exp2); - } - ELSE - { - tonality2 = L_shl(sort_max,sub(15,Qx)); /*Q15 */ - } - - /* tonality in band [2-4 kHz] */ - sort_32_fx(sort_val, 40, 79); - sort_max = sort_val[79]; - sort_avg = sum32_fx(&sort_val[40], 20); - - IF( sort_avg ) - { - /* tonality3 = sort_max / sort_avg; */ - expa = norm_l(sort_max); - fraca = extract_h(L_shl(sort_max,expa)); - expa = sub(30,add(expa, Qx)); - - expb = norm_l(sort_avg); - fracb = extract_h(L_shl(sort_avg,expb)); - expb = sub(30,add(expb, Qx)); - - scale = shr(sub(fracb,fraca),15); - fraca = shl(fraca,scale); - expa = sub(expa,scale); - - tmp = div_s(fraca,fracb); - exp3 = sub(expa,expb); - - tonality3 = L_shl(tmp , exp3); - } - ELSE - { - tonality3 = L_shl(sort_max,sub(15,Qx)); /*Q15 */ - } - - tonality = L_max(L_max(tonality1, tonality2), tonality3); - - /* voi_mean = 0.33f * (voicing[0] + voicing[1] + voicing[2]); */ - L_tmp = L_mult(voicing[0], 10923); - L_tmp = L_mac(L_tmp, voicing[1], 10923); - voi_mean = mac_r(L_tmp, voicing[2], 10923); /* Q15 */ - - test(); - IF( sub(st_fx->hangover_cnt_fx,10) == 0&& sub(vad_flag,1) == 0 ) - { - /* long-term voicing parameter */ - st_fx->lt_voicing = round_fx(L_mac(L_mult(3277,st_fx->lt_voicing),29491, voi_mean)); - - /* long-term correlation value */ - st_fx->lt_corr = round_fx(L_mac(L_mult(3277,st_fx->lt_corr),29491, st_fx->old_corr_fx)); - - /* long-term tonality measure */ - st_fx->lt_tonality = L_add(Mult_32_16(st_fx->lt_tonality,3277),Mult_32_16(tonality,29491)); - } - ELSE - { - /* long-term voicing parameter */ - st_fx->lt_voicing = round_fx(L_mac(L_mult(22938,st_fx->lt_voicing),9830, voi_mean)); - - /* long-term correlation value */ - st_fx->lt_corr = round_fx(L_mac(L_mult(22938,st_fx->lt_corr),9830, st_fx->old_corr_fx)); - - /* long-term tonality measure */ - st_fx->lt_tonality = L_add(Mult_32_16(st_fx->lt_tonality,16384),Mult_32_16(tonality,16384)); - } - - /* Pitch difference w.r.t to past 3 frames */ - lt_pitch_diff = abs_s(sub(st_fx->lt_corr_pitch[0], pitch[0])); - lt_pitch_diff = add(lt_pitch_diff , abs_s(sub(st_fx->lt_corr_pitch[1], pitch[0]))); - lt_pitch_diff = add(lt_pitch_diff,abs_s(sub(st_fx->lt_corr_pitch[2], pitch[0]))); - - st_fx->lt_corr_pitch[0] = st_fx->lt_corr_pitch[1]; - move16(); - st_fx->lt_corr_pitch[1] = st_fx->lt_corr_pitch[2]; - move16(); - st_fx->lt_corr_pitch[2] = pitch[0]; - move16(); - - st_fx->lt_old_mode[0] = st_fx->lt_old_mode[1]; - move16(); - st_fx->lt_old_mode[1] = st_fx->lt_old_mode[2]; - move16(); - - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - IF ( *sp_aud_decision1 == 1 && - ( L_sub(L_min(L_min(tonality1, tonality2), tonality3),1638400) > 0 ) && - ( L_sub(L_add(tonality1, tonality2),6553600) > 0 && L_sub(L_add(tonality2, tonality3),6553600) > 0 && L_sub(L_add(tonality1, tonality3),6553600) > 0 ) && - ( L_sub(st_fx->lt_tonality,655360000) < 0 ) && - ( ( L_sub(st_fx->lt_tonality,32768000) > 0 && sub(s_max(st_fx->lt_voicing, voi_mean),32440) > 0 ) || - ( L_sub(st_fx->lt_tonality,49152000) > 0 && sub(st_fx->lt_corr,32440) > 0 ) || - ( L_sub(st_fx->lt_tonality,98304000) > 0 && sub(st_fx->lowrate_pitchGain,15729) > 0 ) || - ( lt_pitch_diff == 0 && sub(st_fx->lowrate_pitchGain,14582) > 0 ) ) ) - { - IF( sub(sum16_fx(st_fx->lt_old_mode, 2),2) < 0 ) - { - /* probably speech - change the decision to speech */ - *sp_aud_decision1 = 0; - move16(); - *sp_aud_decision2 = 0; - move16(); - - if( st_fx->lt_hangover == 0 ) - { - st_fx->lt_hangover = 6; - move16(); - } - } - } - ELSE - { - /* not speech, but still in the hangover period - change the decision to speech */ - IF( st_fx->lt_hangover > 0 ) - { - *sp_aud_decision1 = 0; - move16(); - *sp_aud_decision2 = 0; - move16(); - - st_fx->lt_hangover = sub(st_fx->lt_hangover,1); - } - } - - /* calculate standard deviation of log-tonality */ - Copy( st_fx->tonality2_buf_fx + 1, st_fx->tonality2_buf_fx, HANG_LEN_INIT - 1 ); - /* st->tonality2_buf[HANG_LEN_INIT - 1] = 0.2f*(float)log10(tonality2); */ - exp = norm_l(tonality2); - tmp = Log2_norm_lc(L_shl(tonality2, exp));/*15 */ - exp = sub(30, add(exp, 16)); - L_tmp = Mpy_32_16(exp, tmp, 15783);/*19 //3945, 0.2*log10(2), Q18 */ - st_fx->tonality2_buf_fx[HANG_LEN_INIT - 1] = round_fx(L_shl(L_tmp, 11));/*14 */ - /* t2 = std( st->tonality2_buf, HANG_LEN_INIT ); */ - t2_fx = std_fx( st_fx->tonality2_buf_fx, HANG_LEN_INIT ); /*14 */ - - Copy( st_fx->tonality3_buf_fx + 1, st_fx->tonality3_buf_fx, HANG_LEN_INIT - 1 ); - /* st->tonality3_buf[HANG_LEN_INIT - 1] = 0.2f*(float)log10(tonality3); */ - exp = norm_l(tonality3); - tmp = Log2_norm_lc(L_shl(tonality3, exp));/*15 */ - exp = sub(30, add(exp, 16)); - L_tmp = Mpy_32_16(exp, tmp, 15783);/*19 //3945, 0.2*log10(2), Q18 */ - st_fx->tonality3_buf_fx[HANG_LEN_INIT - 1] = round_fx(L_shl(L_tmp, 11));/*14 */ - t3_fx = std_fx( st_fx->tonality3_buf_fx, HANG_LEN_INIT ); /*14 */ - - /* tL = 0.2f*(float)log10(st->lt_tonality); */ - exp = norm_l(st_fx->lt_tonality); - tmp = Log2_norm_lc(L_shl(st_fx->lt_tonality, exp));/*15 */ - exp = sub(30, add(exp, 16)); - L_tmp = Mpy_32_16(exp, tmp, 15783);/*19 //3945, 0.2*log10(2), Q18 */ - tL_fx = round_fx(L_shl(L_tmp, 11));/*14 */ - - /* calculate standard deviation of residual LP energy */ - Copy( st_fx->LPCErr_buf_fx + 1, st_fx->LPCErr_buf_fx, HANG_LEN_INIT - 1 ); - st_fx->LPCErr_buf_fx[HANG_LEN_INIT - 1] = LPCErr; - /* err = std( st->LPCErr_buf, HANG_LEN_INIT ); */ - err_fx = std_fx( st_fx->LPCErr_buf_fx, HANG_LEN_INIT ); - - cor_fx = s_max(sub(voi_fv, cor_map_sum_fv), 0);/*15 */ - dft_fx = abs_s(sub(st_fx->tonality2_buf_fx[HANG_LEN_INIT - 1], st_fx->tonality3_buf_fx[HANG_LEN_INIT - 1]));/*14 */ - - - /* state machine for strong music */ - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - IF ( (sub(*sp_aud_decision1, 1) == 0) && st_fx->lt_music_state_fx == 0 && st_fx->lt_music_hangover_fx == 0 && - (sub(t2_fx, 8847) < 0) && (sub(t2_fx, 4260) > 0) && (sub(t3_fx, 3604) > 0) && (sub(tL_fx, 8847) < 0) && (sub(tL_fx, 4260) > 0) && (sub(err_fx, 8192) > 0) ) - { - st_fx->lt_music_state_fx = 1; - move16(); - st_fx->lt_music_hangover_fx = 6; - move16(); - } - ELSE IF( sub(st_fx->lt_music_state_fx, 1) == 0 && st_fx->lt_music_hangover_fx == 0 && - (sub(t2_fx, 5571) < 0) && (sub(t3_fx, 4260) < 0) && (sub(tL_fx, 7373) < 0) ) - { - st_fx->lt_music_state_fx = 0; - move16(); - st_fx->lt_music_hangover_fx = 6; - move16(); - } - - IF ( st_fx->lt_music_hangover_fx > 0 ) - { - st_fx->lt_music_hangover_fx = sub(st_fx->lt_music_hangover_fx,1); - } - - /* state machine for strong speech */ - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - IF ( (sub(*sp_aud_decision1, 1) == 0) && st_fx->lt_speech_state_fx == 0 && st_fx->lt_speech_hangover_fx == 0 && - (sub(cor_fx, 13107) > 0) && (sub(dft_fx, 1638) < 0) && sub(shr(voi_fv,1), add(cor_map_sum_fv, 1966)) > 0 && - (sub(t2_fx, shr(cor_fx, 1)) < 0) && (sub(t3_fx, shr(cor_fx, 1)) < 0) && (sub(tL_fx, shr(cor_fx, 1)) < 0) && - (sub(cor_map_sum_fv, cor_fx) < 0) && (sub(voi_fv, cor_fx) > 0) && (sub(voi_fv, 24903) > 0) ) - { - st_fx->lt_speech_state_fx = 1; - move16(); - st_fx->lt_speech_hangover_fx = 6; - move16(); - } - ELSE IF ( (sub(st_fx->lt_speech_state_fx, 1) == 0) && st_fx->lt_speech_hangover_fx == 0 && (sub(cor_fx, 13107) < 0) ) - { - st_fx->lt_speech_state_fx = 0; - move16(); - st_fx->lt_speech_hangover_fx = 6; - move16(); - } - - IF ( st_fx->lt_speech_hangover_fx > 0) - { - st_fx->lt_speech_hangover_fx = sub(st_fx->lt_speech_hangover_fx,1); - } - - /* final decision */ - test(); - test(); - IF ( sub(*sp_aud_decision1,1) == 0 && sub(st_fx->lt_speech_state_fx,1) == 0 ) - { - /* strong speech - probably error in speech/music classification */ - *sp_aud_decision1 = 0; - move16(); - *sp_aud_decision2 = 0; - move16(); - } - ELSE IF ( *sp_aud_decision1 == 0 && sub(st_fx->lt_speech_state_fx,1) == 0 ) - { - /* strong music - probably error in speech/music classification */ - *sp_aud_decision1 = 0; - move16(); - *sp_aud_decision2 = 0; - move16(); - } - - /* update the buffer of past decisions */ - st_fx->lt_old_mode[2] = *sp_aud_decision1; - move16(); - - return; -} - - -static void detect_sparseness_fx( - Encoder_State_fx *st_fx, /* i/o: encoder state structure */ - const Word16 localVAD_HE_SAD, /* i : HE-SAD flag without hangover */ - Word16 *sp_aud_decision1, /* i/o: 1st stage speech/music decision */ - Word16 *sp_aud_decision2, /* i/o: 2nd stage speech/music decision */ - const Word16 voi_fv /* i : scaled voicing feature */ -) -{ - Word16 sum, sumh; - Word32 L_tmp,L_tmp1; - Word16 tmp, tmp1; - Word16 S1[128]; - Word16 i,j; - Word16 hb_sp_high_flag = 0; - Word16 lb_sp_high_flag = 0; - Word16 sparse; - Word16 tmp_buf[4]; - Word16 Mlpe=0, Mv=0, Msp; - - Copy(st_fx->lgBin_E_fx, S1, 128); - - L_tmp = L_deposit_l(0); - FOR (i = 0; i < 80; i++) - { - if (S1[i] < 0) - { - S1[i] = 0; - move16(); /* Q7 */ - } - L_tmp = L_add(L_tmp, L_deposit_l(S1[i])); - } - - L_tmp1 = L_deposit_l(0); - FOR (i = 80; i < 128; i++) - { - if (S1[i] < 0) - { - S1[i] = 0; - move16(); - } - L_tmp1 = L_add(L_tmp1, L_deposit_l(S1[i])); - } - - sumh = extract_l(L_shr(L_tmp1, 7)); /* Q0 */ - sum = add(extract_l(L_shr(L_tmp, 7)), sumh); /* Q0 */ - - /* order spectral from max to min */ - order_spectrum_fx(S1, 128); - - /* calculate spectral sparseness in the range 0 - 6.4 kHz */ - j = 0; - move16(); - L_tmp = 0; - move16(); - L_tmp1 = L_deposit_l(mult(sum, 24576)); - FOR (i = 0; i < 128; i++) - { - L_tmp = L_add(L_tmp, L_deposit_l(S1[i])); - IF (L_sub(L_shr(L_tmp, 7), L_tmp1) > 0) - { - j = i; - move16(); - BREAK; - } - } - - FOR (i = 0; i < HANG_LEN_INIT-1; i++) - { - st_fx->sparse_buf_fx[i] = st_fx->sparse_buf_fx[i+1]; - move16(); - } - - sparse = j; - move16(); - st_fx->sparse_buf_fx[i] = sparse; - move16(); - - IF (sub(st_fx->bwidth_fx, WB) == 0) - { - Msp = 0; - move16(); - FOR (i = 0; i < 8; i++) - { - Msp = add(Msp, st_fx->sparse_buf_fx[i]); - } - Msp = shl(Msp, 5); /* Q8 */ - - /* find long-term smoothed sparseness */ - IF (st_fx->last_vad_spa_fx == 0 ) - { - set16_fx( &st_fx->sparse_buf_fx[0], sparse, HANG_LEN_INIT-1 ); - st_fx->LT_sparse_fx = sparse; - move16(); - } - ELSE - { - set16_fx(tmp_buf, 0, 4); - - FOR (i = 0; i < HANG_LEN_INIT; i++) - { - FOR (j = 0; j < 4; j++) - { - IF (sub(st_fx->sparse_buf_fx[i], tmp_buf[j]) > 0) - { - Copy(&tmp_buf[j], &tmp_buf[j+1], sub(3, j)); - tmp_buf[j] = st_fx->sparse_buf_fx[i]; - move16(); - BREAK; - } - } - } - - /* ftmp = 0.25f*(HANG_LEN_INIT*Msp - sum_f(tmp_buf, 4)) - st->LT_sparse; */ - tmp = shl(sum16_fx(tmp_buf, 4), 5); - tmp = shl(sub(Msp, tmp), 1); - tmp = sub(tmp, st_fx->LT_sparse_fx); - - st_fx->LT_sparse_fx = add(st_fx->LT_sparse_fx, shr(tmp, 2)); /* Q8 */ - } - - /* find high-band sparseness */ - Copy(st_fx->lgBin_E_fx+80, S1, 48); - - order_spectrum_fx(S1, 48); - - FOR (i = 0; i < HANG_LEN_INIT-1; i++) - { - st_fx->hf_spar_buf_fx[i] = st_fx->hf_spar_buf_fx[i+1]; - move16(); - } - - /* st_fx->hf_spar_buf_fx[i] = sum_f(S1, 5)/sumh; */ - L_tmp = L_deposit_l(0); - FOR (i = 0; i < 5; i++) - { - if (S1[i] < 0) - { - S1[i] = 0; - move16(); - } - - L_tmp = L_add(L_tmp, S1[i]); - } - - tmp = extract_l(L_shr(L_tmp, 7)); - IF (tmp == 0) - { - st_fx->hf_spar_buf_fx[HANG_LEN_INIT-1] = 0; - move16(); - } - ELSE - { - st_fx->hf_spar_buf_fx[HANG_LEN_INIT-1] = div_s(tmp, sumh); - } - - tmp = 0; - move16(); - FOR (i = 0; i < 8; i++) - { - tmp = add(tmp, shr(st_fx->hf_spar_buf_fx[i], 3)); - } - IF (sub(tmp, 6554) > 0) - { - hb_sp_high_flag = 1; - move16(); - } - - /* find low-band sparseness */ - Copy(st_fx->lgBin_E_fx, S1, 60); - - order_spectrum_fx(S1, 60); - L_tmp = L_deposit_l(0); - L_tmp1 = L_deposit_l(0); - FOR (i = 0; i < 5; i++) - { - if (S1[i] < 0) - { - S1[i] = 0; - move16(); - } - - L_tmp = L_add(L_tmp, S1[i]); - } - - FOR (; i < 60; i++) - { - if (S1[i] < 0) - { - S1[i] = 0; - move16(); - } - - L_tmp1 = L_add(L_tmp1, S1[i]); - } - - /* if ( sum_f(S1, 5)/sum_f(S1,60) > 0.18f ) */ - tmp = extract_l(L_shr(L_tmp, 7)); - IF (tmp != 0) - { - tmp = div_s(tmp, add(tmp, extract_l(L_shr(L_tmp1, 7)))); - if (sub(tmp, 5898) > 0) - { - lb_sp_high_flag = 1; - move16(); - } - } - - /* find smoothed linear prediction efficiency */ - FOR (i = 0; i < 7; i++) - { - st_fx->lpe_buf_fx[i] = st_fx->lpe_buf_fx[i+1]; - move16(); - } - - st_fx->lpe_buf_fx[i] = st_fx->past_epsP2_fx; - move16(); - Mlpe = 0; - move16(); - FOR (i = 0; i < 8; i++) - { - Mlpe = add(Mlpe, shr(st_fx->lpe_buf_fx[i], 3)); - } - - /* find smoothed voicing */ - FOR (i = 0; i < HANG_LEN_INIT-1; i++) - { - st_fx->voicing_buf_fx[i] = st_fx->voicing_buf_fx[i+1]; - move16(); - } - - st_fx->voicing_buf_fx[i] = voi_fv; - move16(); - Mv = 0; - move16(); - FOR (i = 0; i < 8; i++) - { - Mv = add(Mv, shr(st_fx->voicing_buf_fx[i], 3)); - } - } - - /* avoid using LR-MDCT on sparse spectra */ - IF (sub(*sp_aud_decision1, 1) == 0) - { - tmp = 91; - move16(); - if (sub(st_fx->bwidth_fx, WB) == 0) - { - tmp = 90; - } - - IF (sub(sparse, tmp) > 0) - { - *sp_aud_decision1 = 0; - move16(); - *sp_aud_decision2 = 1; - move16(); - st_fx->gsc_hangover_fx = 1; - move16(); - } - ELSE IF (sub(st_fx->gsc_hangover_fx, 1) == 0) - { - IF (sub(sparse, 85) > 0) - { - *sp_aud_decision1 = 0; - move16(); - *sp_aud_decision2 = 1; - move16(); - } - ELSE - { - tmp = 0; - move16(); - FOR (i=0; igsc_cnt_fx; i++) - { - tmp = add(tmp, st_fx->sparse_buf_fx[HANG_LEN_INIT-1-st_fx->gsc_cnt_fx+i]); - } - tmp1 = div_s(1, st_fx->gsc_cnt_fx); - tmp = mult(tmp, tmp1); - - IF (sub(abs_s(sub(sparse, tmp)), 7) < 0) - { - *sp_aud_decision1 = 0; - move16(); - *sp_aud_decision2 = 1; - move16(); - } - } - } - - IF (sub(st_fx->bwidth_fx, WB) == 0) - { - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - IF (sub(st_fx->LT_sparse_fx, 15360) > 0 && sub(sparse, 50) > 0 && sub(Mlpe, -1331) < 0 && sub(Mv, 27853) > 0 && - lb_sp_high_flag == 0 && ((hb_sp_high_flag == 0 && sub(sumh, mult_r(4915, sum)) > 0) || sub(sumh, mult_r(4915, sum)) <= 0)) - { - *sp_aud_decision1 = 0; - move16(); - *sp_aud_decision2 = 1; - move16(); - st_fx->gsc_hangover_fx = 1; - move16(); - } - ELSE IF (sub(st_fx->gsc_hangover_fx, 1) == 0 && !( *sp_aud_decision1 == 0 && *sp_aud_decision2 == 1)) - { - IF (sub(abs_s(sub(sparse, mean_fx(&st_fx->sparse_buf_fx[HANG_LEN_INIT-1-st_fx->gsc_cnt_fx], st_fx->gsc_cnt_fx))), 7) < 0) - { - *sp_aud_decision1 = 0; - move16(); - *sp_aud_decision2 = 1; - move16(); - } - } - } - } - - /* update the counter of consecutive GSC frames with sparse spectrum */ - test(); - IF (*sp_aud_decision1 == 0 && sub(*sp_aud_decision2, 1) == 0) - { - st_fx->gsc_cnt_fx = add(st_fx->gsc_cnt_fx, 1); - IF (sub(st_fx->gsc_cnt_fx, 7) > 0) - { - st_fx->gsc_cnt_fx = 7; - move16(); - } - } - ELSE - { - st_fx->gsc_cnt_fx = 0; - move16(); - st_fx->gsc_hangover_fx = 0; - move16(); - } - - st_fx->last_vad_spa_fx = localVAD_HE_SAD; - move16(); - - return; -} - - -static void order_spectrum_fx( - Word16 *vec, - Word16 len -) -{ - Word16 i, j, end, end_1, len_2, tmp; - Word16 smax, smin; - Word16 imax, imin; - - len_2 = shr(len, 1); - FOR(i = 0; i < len_2; i++) - { - imax = i; - move16(); - imin = i; - move16(); - smax = vec[i]; - move16(); - smin = vec[i]; - move16(); - end = sub(len, i); - FOR(j = i; j < end; j++) - { - IF(sub(vec[j], smax) > 0) - { - smax = vec[j]; - move16(); - imax = j; - move16(); - } - ELSE - { - IF(sub(vec[j], smin) < 0) - { - smin = vec[j]; - move16(); - imin = j; - move16(); - } - } - } - - tmp = vec[i]; - move16(); - vec[i] = smax; - move16(); - vec[imax] = tmp; - move16(); - - IF(sub(imin, i) == 0) - { - imin = imax; - move16(); - } - - end_1 = sub(end, 1); - tmp = vec[end_1]; - move16(); - vec[end_1] = smin; - move16(); - vec[imin] = tmp; - move16(); - } -} - diff --git a/src/libs/libevs/lib_enc/stat_enc.h b/src/libs/libevs/lib_enc/stat_enc.h new file mode 100644 index 00000000..0ebc70d9 --- /dev/null +++ b/src/libs/libevs/lib_enc/stat_enc.h @@ -0,0 +1,1230 @@ +/*==================================================================================== + EVS Codec 3GPP TS26.443 Nov 13, 2018. Version 12.11.0 / 13.7.0 / 14.3.0 / 15.1.0 + ====================================================================================*/ + +#ifndef STAT_ENC_H +#define STAT_ENC_H + +#include "options.h" +#include "stat_com.h" /* Common structures */ +#include "cnst.h" + + +/*------------------------------------------------------------------------------------------* + * Indice + *------------------------------------------------------------------------------------------*/ + +typedef struct +{ + unsigned short value; /* value of the quantized indice */ + short nb_bits; /* number of bits used for the quantization of the indice */ +} Indice; + +typedef struct +{ + /* signal memory */ + float syn[1+M]; /* Synthesis memory (non-pe) */ + + /* ACELP memories*/ + float old_exc[L_EXC_MEM]; /* ACELP exc memory (Aq) */ + float mem_w0; + float mem_syn[M]; /* ACELP synthesis memory (pe) before post-proc */ + float mem_syn2[M]; /* ACELP synthesis memory (pe) after post-proc */ + float mem_syn_r[L_SYN_MEM]; /* ACELP synthesis memory for 1.25ms */ + float mem_syn3[M]; + + float tilt_code; + float gc_threshold; /* Noise enhancer - threshold for gain_code */ + + /* TCX memory */ + float Txnq[L_FRAME32k/2+64];/* Q target (overlap or ACELP+ZIR, use Aq) */ + float *acelp_zir; + float tcx_target_bits_fac; + + +} LPD_state; + +typedef struct PLC_ENC_EVS +{ + + int nBits; /* number of bits */ + + int enableGplc; + int T0_4th; + int T0; + int calcOnlylsf; + int pit_min; + int pit_max; + + float mem_MA[M]; + float mem_AR[M]; + + float lsfold[M]; /* old lsf (frequency domain) */ + float lspold[M]; /* old lsp (immittance spectral pairs) */ + + float lsfoldbfi0[M]; /* Previous frame lsf */ + float lsfoldbfi1[M]; /* Past previous frame lsf */ + float lsf_adaptive_mean[M]; /* Mean lsf for bfi cases */ + float stab_fac; + + LPD_state *LPDmem; + float old_exc[8]; /* ACELP exc memory (Aq) */ + + float lsf_con[M]; + float last_lsf_ref[M]; + float last_lsf_con[M]; +} PLC_ENC_EVS; + +/* Arrays and variables specific to encoder */ +typedef struct +{ + HANDLE_FD_CNG_COM hFdCngCom; + + float msPeriodog[NPART]; /* Periodogram */ + float msBminWin[NPART]; + float msBminSubWin[NPART]; + float msPsd[NPART]; /* Power Spectral Density estimate (i.e., smoothed periodogram) */ + float msAlpha[NPART]; /* Optimal smoothing parameter */ + float msMinBuf[MSNUMSUBFR*NPART]; /* Buffer of minima */ + float msCurrentMinOut[NPART]; + float msCurrentMin[NPART]; + float msCurrentMinSubWindow[NPART]; + int msLocalMinFlag[NPART]; + int msNewMinFlag[NPART]; + float msPsdFirstMoment[NPART]; + float msPsdSecondMoment[NPART]; + float msNoiseFloor[NPART]; /* Estimated noise floor */ + float msNoiseEst[NPART]; /* Estimated noise level */ + float energy_ho[NPART]; + float msNoiseEst_old[NPART]; + float msLogPeriodog[NPART]; /* Periodogram */ + float msLogNoiseEst[NPART]; /* Estimated noise level */ + + float msPeriodogBuf[MSBUFLEN*NPART]; + int msPeriodogBufPtr; + + int stopFFTbinDec; + int startBandDec; + int stopBandDec; + int npartDec; + int midbandDec[NPART]; + int nFFTpartDec; + int partDec[NPART]; +} +FD_CNG_ENC; +typedef FD_CNG_ENC *HANDLE_FD_CNG_ENC; + +/* transient_detection.h */ +/** Delay buffer. + * Used to buffer input samples and to define the subblock size of a transient detector. + */ +typedef struct +{ + /** Subblock size of a transient detector that uses this delay buffer. */ + int nSubblockSize; + /** Delay buffer */ + float buffer[L_FRAME_MAX/NSUBBLOCKS]; + /** Size of the delay buffer in use. Maximum delay from all users of this buffer. */ + int nDelay; +} DelayBuffer; + +/** Subblock energies. + * Holds subblock energies and recursively accumulated energies. + * Also buffers the energies. + */ +typedef struct +{ + /** Delay buffer. */ + DelayBuffer * pDelayBuffer; + /** Subblock energies with a delay buffering. */ + float subblockNrg[NSUBBLOCKS+MAX_TD_DELAY]; + /** Recursively accumulated subblock energies with a delay buffering. + At index i the value corresponds to the accumulated subblock energy up to i-1, + including block i-1 and without block i. */ + float accSubblockNrg[NSUBBLOCKS+MAX_TD_DELAY+1]; + /** subblockNrgChange[i] = max(subblockNrg[i]/subblockNrg[i-1], subblockNrg[i-1]/subblockNrg[i]) */ + float subblockNrgChange[NSUBBLOCKS+MAX_TD_DELAY]; + /** Size of the delay buffer in use, as number of subblocks. Maximum delay from all users of this buffer. */ + int nDelay; + /* Delay of the input (modulo pDelayBuffer->nSubblockSize), nPartialDelay <= pDelayBuffer->nDelay. */ + int nPartialDelay; + + /** Decay factor for the recursive accumulation */ + float facAccSubblockNrg; + + /** High-pass filter states (delay line) */ + float firState1; + float firState2; + +} SubblockEnergies; + +struct TransientDetector; + +/** Attack detection function. + * Definition of a function used for checking the presence of an attack, given subblock energies, accumulated subblock energies and a threshold. + * @param pSubblockNrg Subblock energies. + * @param pAccSubblockNrg Recursively accumulated subblock energies. + At index i the value corresponds to the accumulated subblock energy up to i-1, + including block i-1 and without block i. + * @param nSubblocks Number of subblocks available (those with an index >= 0). Subblocks from 0 to NSUBBLOCKS-1 correspond to the current frame. + * @param nPastSubblocks Number of past subblocks available (those with a negative index). + * @param attackRatioThreshold Attack ratio threshold. + * @param pbIsAttackPresent Pointer to an output variable that will be set to TRUE if an attack is found, otherwise set to FALSE. + * @param pAttackIndex Pointer to an output variable that will hold an attack position. + */ +typedef void (* TCheckSubblocksForAttack)(float const * pSubblockNrg, float const * pAccSubblockNrg, int nSubblocks, int nPastSubblocks, float attackRatioThreshold, int * pbIsAttackPresent, int * pAttackIndex); + +/** Transient detector. + */ +typedef struct TransientDetector +{ + /** Subblock energies used in this transient detector. */ + SubblockEnergies * pSubblockEnergies; + /* Delay of the transient detector in number of subblocks, nDelay <= pSubblockEnergies->nDelay. */ + int nDelay; + /** Number of subblocks to check for transients. */ + int nSubblocksToCheck; + /** Function for checking a presence of an attack. */ + TCheckSubblocksForAttack CheckSubblocksForAttack; + /** Attack ratio threshold. */ + float attackRatioThreshold; + /** True when an attack was detected. */ + int bIsAttackPresent; + /** The index of an attack. */ + int attackIndex; + +} TransientDetector; + +/** Transient detection. + * Holds all transient detectors and buffers used by them. + */ +typedef struct TransientDetection +{ + /** Transient detector. */ + TransientDetector transientDetector; + /** Delay buffer used by the transient detectors. */ + DelayBuffer delayBuffer; + /** Subblock energies used by the transient detector. */ + SubblockEnergies subblockEnergies; +} TransientDetection; + + +typedef struct +{ + int bw_index; /* index of band width */ + + /* feature */ + float sp_center[SP_CENTER_NUM]; /* spectral center*/ + float ltd_stable_rate[STABLE_NUM]; /* time-domain stable rate*/ + float sfm[SFM_NUM]; /* spectral flatness*/ + float f_tonality_rate[TONA_NUM]; /* tonality rate*/ + float frame_sb_energy[BG_ENG_NUM]; /* energy of sub-band divided non-uniformly*/ + float frames_power[POWER_NUM]; /* energy of several frames*/ + float pre_spec_low_dif[PRE_SPEC_DIF_NUM]; /* low frequency spectral different*/ + float t_bg_energy; /* time background energy of several frames*/ + float t_bg_energy_sum; /* number of time background energy*/ + int tbg_energy_count; /* sum of time background energy of several frames*/ + int bg_update_count; /* time of background update*/ + float frame_energy_smooth; /* smoothed energy of several frames*/ + + + /************************************************************************/ + /* history parameters */ + /************************************************************************/ + float smooth_spec_amp[SPEC_AMP_NUM]; /* smoothed spectral amplitude*/ + float sb_bg_energy[BG_ENG_NUM]; /* sub-band background energy*/ + float pre_snr[PRE_SNR_NUM]; /* previous time SNR*/ + float lt_snr_org; /* original long time SNR*/ + float lf_snr_smooth; /* smoothed lf_snr*/ + float l_silence_snr; /* sum of snr's of non active frames*/ + float l_speech_snr; /* sum of snr's of active frames*/ + int l_silence_snr_count; /* number of non active frames*/ + int l_speech_snr_count; /* number of active frames*/ + float fg_energy ; /* foreground energy sum */ + float bg_energy ; /* background energy sum */ + int fg_energy_count ; /* number of the foreground energy frame */ + int bg_energy_count ; /* number of the background energy frame */ + int fg_energy_est_start; /* flag by that indicate whether if estimate energy*/ + int speech_flag; /* residual number of hangover 1 */ + int continuous_noise_num; /* time of continuous noise frames*/ + int continuous_speech_num; /* time of continuous speech frames*/ + int continuous_speech_num2; /* time 2 of continuous speech frames*/ + int frameloop; /* number of frame*/ + float tonality_rate3 ; /* tonality rate*/ + float music_background_rate; /* music background rate*/ + float lt_noise_sp_center_diff_sum; /* different sum of long time noise sp_center*/ + float lt_noise_sp_center_diff_counter; /* number of the member lt_noise_sp_center_diff_sum*/ + float lt_noise_sp_center0 ; /* long time noise sp_center0*/ + float lt_noise_sp_center3 ; /* long time noise sp_center3*/ + float lt_bg_highf_eng; /* average of long time high frequency energy*/ + int update_num_with_snr; /* the number of the background update with SNR*/ + int update_count; + short warm_hang_num; /* the number of hangover for warm up*/ + short vad_flag_for_bk_update; +} T_CldfbVadState; + + +typedef struct igfscfenc_public_data_struct +{ + int ptrBitIndex; + int bitCount; + int prev[64]; /* no more than 64 SCFs for the IGF energy envelope of one block */ + int prevSave[64]; + int scfCountLongBlock; + int t; + int Tsave; + int contex_saved; + const unsigned short *cf_se00; + const unsigned short *cf_se01; + short cf_off_se01; + const unsigned short *cf_se02; + const short *cf_off_se02; + const unsigned short *cf_se10; + short cf_off_se10; + const unsigned short *cf_se11; + const short *cf_off_se11; + Tastat acState; +} IGFSCFENC_INSTANCE, *IGFSCFENC_INSTANCE_HANDLE; + + +typedef struct igf_enc_private_data_struct +{ + IGF_INFO igfInfo; + int igfScfQuantized[IGF_MAX_SFB]; + IGFSCFENC_INSTANCE hIGFSCFArithEnc; + + + int igfCurrWhiteningLevel[IGF_MAX_TILES]; + int igfPrevWhiteningLevel[IGF_MAX_TILES]; + + float prevSFM_FIR[IGF_MAX_TILES]; + float prevSFM_IIR[IGF_MAX_TILES]; + int wasTransient; + + UWord8 igfBitstream[BITBUFSIZE/8]; + short igfBitstreamBits; + + +} IGF_ENC_PRIVATE_DATA, *IGF_ENC_PRIVATE_DATA_HANDLE; + +/**********************************************************************/ /** +Definition of public data for this module +**************************************************************************/ +typedef struct igf_enc_instance_struct +{ + IGF_ENC_PRIVATE_DATA igfData; + int infoSamplingRate; + int infoStartFrequency; + int infoStopFrequency; + int infoStartLine; + int infoStopLine; + int infoTotalBitsWritten; + int infoTotalBitsPerFrameWritten; + int infoFrameCount; + int flatteningTrigger; + float spec_be_igf[N_MAX_TCX-IGF_START_MN]; + float tns_predictionGain; +} IGF_ENC_INSTANCE, *IGF_ENC_INSTANCE_HANDLE; + +/*----------------------------------------------------------------------------------* + * + * Main encoder structure + * + *----------------------------------------------------------------------------------*/ + +typedef struct +{ + + /*----------------------------------------------------------------------------------* + * Common parameters + *----------------------------------------------------------------------------------*/ + + short codec_mode; /* Mode1 or Mode2 */ + short last_codec_mode; /* previous frame Mode 1 or 2 */ + short last_codec_mode_cng; /* previous inactive frame Mode 1 or 2 */ + short mdct_sw_enable; /* MDCT switching enable flag */ + short mdct_sw; /* MDCT switching indicator */ + float prev_hi_ener; + short prev_hi_sparse; + float clas_sec_old; + short clas_final_old; + float last_gain1; + float last_gain2; + + short nb_bits_tot; /* total number of bits already written */ + Indice *ind_list; /* list of indices */ + short bitstreamformat; /* Bitstream format flag (G.192/MIME) */ + short next_ind; /* pointer to the next empty slot in the list of indices */ + short last_ind; /* last written indice */ + + int input_Fs; /* input signal sampling frequency in Hz */ + long total_brate; /* total bitrate in kbps of the codec */ + long last_total_brate; /* last frame's total bitrate in kbps of the codec */ + long last_total_brate_cng; /* last inactive frame's total bitrate in kbps of the codec */ + short core; /* core (ACELP_CORE, TCX_20_CORE, TCX_10_CORE, HQ_CORE, AMR_WB_CORE) */ + long core_brate; /* core bitrate */ + long last_core_brate; /* previous frame core bitrate */ + short extl; /* extension layer */ + short last_extl; /* previous extension layer */ + long extl_brate; /* extension layer bitrate */ + short input_bwidth; /* input signal bandwidth */ + short bwidth; /* encoded bandwidth NB, WB, SWB or FB */ + short max_bwidth; /* maximum encoded bandwidth */ + short last_input_bwidth; /* input signal bandwidth in the previous frame */ + short last_bwidth; /* coded bandwidth in the previous frame */ + short last_bwidth_cng; /* coded bandwidth in the previous inactive frame */ + short L_frame; /* ACELP core internal frame length */ + short Opt_AMR_WB; /* flag indicating AMR-WB IO mode */ + short Opt_DTX_ON; /* flag indicating DTX operation */ + short cng_type; /* flag indicating LP or CLDFB based SID/CNG */ + short active_cnt; /* counter of active frames */ + short Opt_SC_VBR; /* flag indicating SC-VBR mode */ + short last_Opt_SC_VBR; /* flag indicating prev frame's SC-VBR mode */ + short lp_cng_mode2; + /*----------------------------------------------------------------------------------* + * ACELP core parameters + *----------------------------------------------------------------------------------*/ + + LPD_state LPDmem; /* ACELP memories */ + + short clas; /* current frame clas */ + short last_clas; /* previous frame signal classification */ + float Bin_E[L_FFT]; /* per bin energy of two frames */ + float Bin_E_old[L_FFT/2]; /* per bin energy of old 2nd frames */ + float lsp_old1[M]; /* old unquantized LSP vector at the end of the frame at 12k8 */ + float lsf_old1[M]; /* old unquantized LSF vector at the end of the frame at 12k8 */ + float lsp_old[M]; /* old LSP vector at the end of the frame */ + float lsf_old[M]; /* old LSF vector at the end of the frame */ + float lsp_old16k[M]; /* old LSP vector at the end of the frame @16kHz */ + float lspold_enc[M]; /* old lsp (immittance spectral pairs) */ + short pstreaklen; /* LSF quantizer */ + float streaklimit; /* LSF quantizer */ + unsigned int offset_scale1[MAX_NO_MODES+1][MAX_NO_SCALES+1]; /* offsets for LSF LVQ structure 1st 8-dim subvector*/ + unsigned int offset_scale2[MAX_NO_MODES+1][MAX_NO_SCALES+1]; /* offsets for LSF LVQ structure 2nd 8-dim subvector*/ + unsigned int offset_scale1_p[MAX_NO_MODES_p+1][MAX_NO_SCALES+1]; /* offsets for LSF LVQ structure, pred. case, 1st 8-dim subvector*/ + unsigned int offset_scale2_p[MAX_NO_MODES_p+1][MAX_NO_SCALES+1]; /* offsets for LSF LVQ structure, pred. case, 2nd 8-dim subvector*/ + short no_scales[MAX_NO_MODES][2]; /* LSF LVQ structure */ + short no_scales_p[MAX_NO_MODES_p][2]; /* LSF LVQ structure */ + float stab_fac; /* LSF stability factor */ + float mem_decim[2*L_FILT_MAX]; /* decimation filter memory */ + float mem_deemph; /* deemphasis filter memory */ + float mem_preemph; /* preemphasis filter memory */ + float mem_hp20_in[4]; /* HP filter memory */ + float old_inp_12k8[L_INP_MEM]; /* memory of input signal at 12.8kHz */ + float old_wsp[L_WSP_MEM]; /* old weighted signal vector */ + float old_wsp2[(L_WSP_MEM - L_INTERPOL)/OPL_DECIM]; /* old decimated weighted signal vector */ + float fr_bands1[NB_BANDS]; /* spectrum per critical bands of the previous frame */ + float fr_bands2[NB_BANDS]; /* spectrum per critical bands 2 frames ago */ + float mem_wsp; /* weighted signal vector memory */ + float mem_decim2[3]; /* weighted signal decimation filter memory */ + float mem_syn1[M]; /* synthesis filter memory (for core switching and FD BWE) */ + + float clip_var[6]; /* pitch gain clipping memory */ + float past_qua_en[4]; /* gain quantization memory (used also in AMR-WB IO mode) */ + float mem_AR[M]; /* AR memory of LSF quantizer (past quantized LSFs without mean) */ + float mem_MA[M]; /* MA memory of LSF quantizer (past quantized residual) (used also in AMR-WB IO mode) */ + short mCb1; /* LSF quantizer - counter of stationary frames after a transition frame */ + short coder_type_raw; /* raw coder_type (before UNVOICED is lost) */ + short last_coder_type_raw; /* raw last_coder_type (coming from the sigal classification) */ + short last_coder_type; /* previous coding type */ + short ini_frame; /* initialization frames counter */ + float old_thres; /* normalized correlation weighting in open-loop pitch */ + float old_corr; /* normalized correlation in previous frame (mean value) */ + short old_pitch; /* previous pitch for open-loop pitch search */ + short delta_pit; /* open-loop pitch extrapolation correction */ + float ee_old; /* previous frame low/high frequency energy ratio */ + short min_band; /* minimum critical band of useful bandwidth */ + short max_band; /* maximum critical band of useful bandwidth */ + short tc_cnt; /* TC frame counter */ + short audio_frame_cnt; /* Counter of relative presence of audio frames */ + float old_dE1; /* Maximum energy increase in previous frame */ + short old_ind_deltaMax; /* Index of the sub-subframe of maximum energy in previous frame */ + float old_enr_ssf[2*NB_SSF]; /* Maxima of energies per sub-subframes of previous frame */ + short spike_hyst; /* Hysteresis to prevent UC after sharp energy spike */ + short music_hysteresis; /* Counter of frames after AUDIO coding mode to prevent UC */ + short last_harm_flag_acelp; /* harmonicity flag for ACELP @32kbps rate */ + float old_Aq_12_8[M+1]; /* old Aq[] for core switching */ + float old_Es_pred; /* old Es_pred for core switching */ + short high_stable_cor; + + short seed_tcx; /* AC mode (GSC) - seed for noise fill*/ + short cor_strong_limit; /* AC mode (GSC) - Indicator about high spectral correlation per band */ + short GSC_noisy_speech; /* AC mode (GSC) - flag to indicate GSC on SWB noisy speech */ + short mem_last_pit_band; /* AC mode (GSC) - memory of the last band where pitch contribution was significant */ + float mem_w0_tmp; + float mem_syn_tmp[M]; + float var_cor_t[VAR_COR_LEN]; + float mid_dyn; /* AC mode (GSC) - signal dynamic */ + short noise_lev; /* AC mode (GSC) - noise level */ + short past_dyn_dec; /* AC mode (GSC) - Past noise level decision */ + float Last_frame_ener; /* AC mode (GSC) - Last frame energy */ + short pit_exc_hangover; /* AC mode (GSC) - Hangover for the time contribution switching*/ + + float last_exc_dct_in[L_FRAME]; /* AC mode (GSC) - previous excitation */ + float last_ener; /* AC mode (GSC) - previous energy */ + short last_bitallocation_band[6]; /* AC mode (GSC) - previous bit allocation of each band */ + + + short last_act_dec_hang; /* Speech/music classifier - decision from the last active frame */ + float past_PS[HIGHEST_FBIN-LOWEST_FBIN]; + float past_ps_diff; + float past_epsP2; + short inact_cnt; + float wdrop; + float wdlp_0_95_sp; + short sp_mus_state; + short past_dec[HANG_LEN-1]; /* Speech/music classifier - buffer of past binary decisions */ + float past_dlp[HANG_LEN-1]; /* Speech/music classifier - buffer of past non-binary decisions */ + float last_lsp[M_LSP_SPMUS]; + float last_cor_map_sum; + float last_non_sta; + float past_log_enr[NB_BANDS_SPMUS]; /* Speech/music classifier - last average per-band log energy used for non_staX */ + float gsc_thres[4]; /* Speech/music classifier - classification threshold */ + float gsc_lt_diff_etot[MAX_LT]; /* Speech/music classifier - long-term total energy variation */ + float gsc_mem_etot; /* Speech/music classifier - total energy memory */ + short gsc_last_music_flag; /* Speech/music classifier - last music flag */ + short gsc_nb_thr_1; /* Speech/music classifier - number of consecutives frames of level 1 */ + short gsc_nb_thr_3; /* Speech/music classifier - number of consecutives frames of level 3 */ + float mold_corr; + float lt_gpitch; + float mean_avr_dyn; /* Speech/music classifier - long term average dynamic */ + float last_sw_dyn; /* Speech/music classifier - last dynamic */ + float lt_dec_thres; /* Speech/music classifier - Long term speech/music thresold values */ + float ener_RAT; /* Speech/music classifier - LF/to total energy ratio */ + + /* speech/music classifier improvement parameters */ + float old_Bin_E[3*N_OLD_BIN_E]; + float buf_flux[BUF_LEN]; + float buf_pkh[BUF_LEN]; + float buf_epsP_tilt[BUF_LEN]; + float buf_cor_map_sum[BUF_LEN]; + float buf_Ntonal[BUF_LEN]; + float buf_Ntonal2[BUF_LEN]; + float buf_Ntonal_lf[BUF_LEN]; + float buf_dlp[10]; + short onset_cnt; + float buf_etot[4]; + short attack_hangover; + float dec_mov; + float dec_mov1; + float mov_log_max_spl; + float old_lt_diff[2]; + short UV_cnt1; + float LT_UV_cnt1; + + short lt_music_hangover; + float tonality2_buf[HANG_LEN_INIT]; + float tonality3_buf[HANG_LEN_INIT]; + float LPCErr_buf[HANG_LEN_INIT]; + short lt_music_state; + short lt_speech_state; + short lt_speech_hangover; + float lpe_buf[HANG_LEN_INIT]; + float voicing_buf[HANG_LEN_INIT]; + short gsc_hangover; + float sparse_buf[HANG_LEN_INIT]; + float hf_spar_buf[HANG_LEN_INIT]; + float LT_sparse; + short gsc_cnt; + + short Last_pulse_pos; /* FEC - last position of the first glottal pulse in the frame */ + float lsfoldbfi0[M]; /* FEC - LSF vector of the previous frame */ + float lsfoldbfi1[M]; /* FEC - LSF vector of the past previous frame */ + float lsf_adaptive_mean[M]; /* FEC - adaptive mean LSF vector for FEC */ + short next_force_safety_net; /* FEC - flag to force safety net in next frame */ + float old_S[L_FFT/2]; /* Tonal detector - prev. log-energy spectrum with subtracted floor */ + float cor_map[L_FFT / 2]; /* Tonal detector - LT correlation map */ + float noise_char; /* Tonal detector - LT noise character */ + float ave_enr2[NB_BANDS]; /* Tonal detector - LT average E per crit. band (for non_sta2) */ + float act_pred; /* Tonal detector - prediction of speech activity from 0 to 1 (0-inactive, 1-active) */ + float multi_harm_limit; /* Tonal detector - adaptive threshold */ + float enrO[NB_BANDS]; /* Noise estimator - previous energy per critical band */ + float bckr[NB_BANDS]; /* Noise estimator - background noise estimation per critical band */ + float ave_enr[NB_BANDS]; /* Noise estimator - long-term average energy per critical band */ + short pitO; /* Noise estimator - previous open-loop pitch value */ + short aEn; /* Noise estimator - noise estimator adaptation flag */ + float totalNoise; /* Noise estimator - total noise energy */ + short first_noise_updt; /* Noise estimator - flag used to determine if the first noise update frame */ + short harm_cor_cnt; /* Noise estimator - 1st memory counter of harm or correlation frame */ + short bg_cnt; /* Noise estimator - pause length counter */ + float prim_act_quick; /* Noise estimator - primary activity quick */ + float prim_act_slow; /* Noise estimator - primary activity slow */ + float prim_act; /* Noise estimator - primary activity slow rise quick fall */ + float prim_act_quick_he; /* Noise estimator - primary activity quick */ + float prim_act_slow_he; /* Noise estimator - primary activity slow */ + float prim_act_he; /* Noise estimator - primary activity slow rise quick fall */ + float Etot_l; /* Noise estimator - Track energy from below */ + float Etot_h; /* Noise estimator - Track energy from above */ + float Etot_l_lp; /* Noise estimator - Smoothed low energy */ + float Etot_last; /* Noise estimator - Energy of last frame */ + float Etot_lp; /* Noise estimator - Filtered input energy */ + float lt_tn_track; + float lt_tn_dist; + float lt_Ellp_dist; + float lt_haco_ev; + short low_tn_track_cnt; + float epsP_0_2_lp; + float epsP_0_2_ad_lp; + float epsP_2_16_lp; + float epsP_2_16_lp2; + float epsP_2_16_dlp_lp; + float epsP_2_16_dlp_lp2; + float lt_aEn_zero; + + float Etot_st_est; /* Noise estimation - short term estimate of E{ Etot } */ + float Etot_sq_st_est; /* Noise estimation - short term estimate of E{ Etot^2 } */ + + + short nb_active_frames; + short hangover_cnt; + float lp_speech; + float Etot_v_h2; + float sign_dyn_lp; + short nb_active_frames_he; + short hangover_cnt_he; + short nb_active_frames_HE_SAD; + long vad_flag_reg_H; + long vad_flag_reg_L; + long vad_prim_reg; + + short vad_flag_cnt_50; + short vad_prim_cnt_16; + + short hangover_cnt_dtx; + short hangover_cnt_music; + + float bcg_flux; + short soft_hangover; + short voiced_burst; + short bcg_flux_init; + float voicing_old; + short nb_active_frames_he1; + short hangover_cnt_he1; + + float bckr_tilt_lt; + + short var_SID_rate_flag; /* CNG and DTX - flag for variable SID rate */ + float lp_ener; /* CNG and DTX - low-pass filtered energy for CNG */ + short cng_seed; /* CNG and DTX - seed for white noise random generator */ + float lspCNG[M]; /* CNG and DTX - LP filtered ISPs */ + short first_CNG; /* CNG and DTX - first CNG frame flag */ + float lp_noise; /* CNG and DTX - LP filterend total noise estimation */ + short cnt_SID; /* CNG and DTX - counter of SID update for the interop. mode or dtx, if enabled */ + short max_SID; /* CNG and DTX - max allowed number of CNG FRAME__NO_DATA frames */ + short interval_SID; /* CNG and DTX - interval of SID update, default 8 */ + short old_enr_index; /* CNG and DTX - index of last encoded CNG energy */ + float Enew; /* CNG and DTX - CNG target residual energy */ + short VarDTX_cnt_voiced; /* CNG and DTX - counter for variable DTX activation (speech) */ + float lt_ener_voiced; /* CNG and DTX - long-term energy of signal (measured on voiced parts) */ + short VarDTX_cnt_noise; /* CNG and DTX - counter for variable DTX activation (noise) */ + float lt_ener_noise; /* CNG and DTX - long-term energy of background noise */ + float lt_ener_last_SID; /* CNG and DTX - long-term energy of last SID frame */ + short cng_hist_size; /* CNG and DTX - size of CNG history buffer for averaging, <0,DTX_HIST_SIZE> */ + short cng_hist_ptr; /* CNG and DTX - pointer for averaging buffers */ + float cng_lsp_hist[DTX_HIST_SIZE*M]; /* CNG and DTX - old LSP buffer for averaging */ + float cng_ener_hist[DTX_HIST_SIZE]; /* CNG and DTX - log energy buffer for averaging */ + short cng_cnt; /* CNG and DTX - counter of CNG frames for averaging */ + short cng_ener_seed; /* CNG and DTX - seed for random generator for variation of excitation energy */ + short cng_ener_seed1; + float frame_ener; + float lp_sp_enr; + short last_allow_cn_step; + short ho_hist_size; /* CNG and DTX - size of DTX hangover history buffer for averaging, <0,HO_HIST_SIZE> */ + short ho_hist_ptr; /* CNG and DTX - pointer for averaging buffers */ + long ho_sid_bw; /* CNG and DTX - SID bandwidth flags */ + float ho_lsp_hist[HO_HIST_SIZE*M]; /* CNG and DTX - old LSP buffer for averaging */ + float ho_ener_hist[HO_HIST_SIZE]; /* CNG and DTX - energy buffer for averaging */ + float ho_env_hist[HO_HIST_SIZE*NUM_ENV_CNG]; + short act_cnt; /* CNG and DTX - counter of active frames */ + short ho_circ_size; /* CNG and DTX - size of DTX hangover history buffer for averaging, <0,HO_HIST_SIZE> */ + short ho_circ_ptr; /* CNG and DTX - pointer for averaging buffers */ + float ho_lsp_circ[HO_HIST_SIZE*M]; /* CNG and DTX - old LSP buffer for averaging */ + float ho_ener_circ[HO_HIST_SIZE]; /* CNG and DTX - energy buffer for averaging */ + float ho_env_circ[HO_HIST_SIZE*NUM_ENV_CNG]; + short burst_ho_cnt; /* CNG and DTX - counter of hangover frames at end of active burst */ + short cng_buf_cnt; /* CNG and DTX - Counter of buffered CNG parameters */ + float cng_exc2_buf[HO_HIST_SIZE*L_FFT]; /* CNG and DTX - exc2 buffer for storing */ + long cng_brate_buf[HO_HIST_SIZE]; /* CNG and DTX - buffer for storing last_active_brate */ + + short CNG_mode; /* CNG and DTX - mode for DTX configuration */ + long last_active_brate; /* CNG and DTX - last active frame bitrate used for CNG_mode control */ + short ho_16k_lsp[HO_HIST_SIZE]; /* CNG and DTX - 16k LSPs flags */ + short last_CNG_L_frame; /* CNG and DTX - last CNG frame length */ + short act_cnt2; /* CNG and DTX - counter of active frames for CNG_mode switching */ + float ho_lsp_circ2[HO_HIST_SIZE*M]; /* CNG and DTX - second buffer of LSPs */ + short num_ho; /* CNG and DTX - number of selected hangover frames */ + short hangover_terminate_flag; /* CNG and DTX - flag indicating whether to early terminate DTX hangover */ + float old_env[NUM_ENV_CNG]; + float lp_env[NUM_ENV_CNG]; + float cng_res_env[NUM_ENV_CNG*HO_HIST_SIZE]; + float exc_mem[24]; + float exc_mem1[30]; + float exc_mem2[30]; + + float dispMem[8]; /* Noise enhancer - phase dispersion algorithm memory */ + + short uv_count; /* Stationary noise UV modification - unvoiced counter */ + short act_count; /* Stationary noise UV modification - activation counter */ + float ge_sm; /* Stationary noise UV modification - smoothed excitation gain */ + float lspold_s[M]; /* Stationary noise UV modification - old LSP vector */ + short noimix_seed; /* Stationary noise UV modification - mixture seed */ + float min_alpha; /* Stationary noise UV modification - minimum alpha */ + float exc_pe; /* Stationary noise UV modification - memory of the preemphasis filter */ + + short last_L_frame; /* ACELP@16kHz - last L_frame value */ + float mem_decim16k[2*L_FILT_MAX]; /* ACELP@16kHz - decimation filter memory @16kHz */ + float mem_preemph16k; /* ACELP@16kHz - preemphasis filter memory @16kHz */ + float old_inp_16k[L_INP_MEM]; /* ACELP@16kHz - memory of input signal @16 kHz */ + float mem_deemp_preQ; /* ACELP@16kHz - prequantizer deemhasis memory */ + float mem_preemp_preQ; /* ACELP@16kHz - prequantizer preemhasis memory */ + short last_nq_preQ; /* ACELP@16kHz - AVQ subquantizer number of the last sub-band of the last subframe */ + short use_acelp_preq; /* ACELP@16kHz - flag of prequantizer usage */ + + short bpf_off; /* Bass post-filter - do not use BPF when this flag is set to 1 */ + float old_pitch_buf[2*NB_SUBFR16k]; /* Bass post-filter - buffer of old subframe pitch values */ + float pst_mem_deemp_err; /* Bass post-filter - filter memory of noise LP filter */ + float pst_lp_ener; /* Bass post-filter - long-term energy */ + float lps; + float lpm; + + /* stable short pitch detection */ + float voicing0_sm; + float voicing_sm; + float LF_EnergyRatio_sm; + short predecision_flag; + float diff_sm; + float energy_sm; + + + /*----------------------------------------------------------------------------------* + * HF WB BWE for AMR-WB IO mode at 23.85 kbps + *----------------------------------------------------------------------------------*/ + + float gain_alpha; + float mem_hf2_enc[L_FIR-1]; + float mem_hp400_enc[4]; + float mem_hf_enc[L_FIR-1]; + float mem_syn_hf_enc[M]; + short seed2_enc; + + /*----------------------------------------------------------------------------------* + * CLDFB analysis + *----------------------------------------------------------------------------------*/ + + HANDLE_CLDFB_FILTER_BANK cldfbAnaEnc; /* main analysis filter bank handle */ + HANDLE_CLDFB_FILTER_BANK cldfbSynTd; + + + /*----------------------------------------------------------------------------------* + * FD CNG handle + *----------------------------------------------------------------------------------*/ + + HANDLE_FD_CNG_ENC hFdCngEnc; + short fd_cng_reset_flag; + float last_totalNoise; + float totalNoise_increase_hist[TOTALNOISE_HIST_SIZE]; + short totalNoise_increase_len; + + /*----------------------------------------------------------------------------------* + * SC-VBR parameters + *----------------------------------------------------------------------------------*/ + + float vadsnr; + float vadnoise; + + /* NELP variables */ + float shape1_filt_mem[20]; + float shape2_filt_mem[20]; + float shape3_filt_mem[20]; + float txlpf1_filt1_mem[20]; + float txlpf1_filt2_mem[20]; + float txhpf1_filt1_mem[20]; + float txhpf1_filt2_mem[20]; + float bp1_filt_mem_wb[8]; + float nelp_lp_fit_mem[NELP_LP_ORDER*2]; + float bp1_filt_mem_nb[14]; + short nelp_enc_seed; + float nelp_gain_mem; + short last_nelp_mode; + short nelp_mode; + + /* PPP variables */ + short pppcountE; + short bump_up; + short last_ppp_mode; + short last_last_ppp_mode; + short ppp_mode; + float prev_ppp_gain_pit; + float prev_tilt_code; + + /* voiced encoder variables */ + int firstTime_voicedenc; + + /* DTFS variables */ + float dtfs_enc_a[MAXLAG_WI]; + float dtfs_enc_b[MAXLAG_WI]; + int dtfs_enc_lag; + int dtfs_enc_nH; + int dtfs_enc_nH_4kHz; + float dtfs_enc_upper_cut_off_freq_of_interest; + float dtfs_enc_upper_cut_off_freq; + + float prev_cw_en; + float ph_offset_E; + float lastLgainE; /* Previous gain value for the low band */ + float lastHgainE; /* Previous gain value for the high band */ + float lasterbE[NUM_ERB_WB]; /* Previous Amplitude spectrum (ERB) */ + + short mode_QQF; + short rate_control; + float SNR_THLD; + short Q_to_F; + short pattern_m; + short patterncount; + short Last_Resort; + short numactive; /* keep the count of the frames inside current 600 frame block */ + float sum_of_rates; /* sum of the rates of past 600 active frames */ + float global_avr_rate; /* global rate up to current time. recorded a (rate in kbps) * 6000 */ + int global_frame_cnt; /* 600 active frame block count. Used to update the global rate */ + short set_ppp_generic; + short avoid_HQ_VBR_NB; + + /*----------------------------------------------------------------------------------* + * HQ core parameters + *----------------------------------------------------------------------------------*/ + + float input_buff[L_FRAME48k+L_FRAME48k+NS2SA(48000, DELAY_FIR_RESAMPL_NS)]; + float * input; + float * old_input_signal; + + float old_hpfilt_in; + float old_hpfilt_out; + float EnergyLT; + float Energy_Old; + short TransientHangOver; + float old_out[L_FRAME32k]; /* buffer for OLA; at the encoder, the maximum length is L_FRAME32k (corresponds to maximum internal L_frame length) */ + short last_core; + short hq_generic_speech_class; + short mode_count; /* HQ_HARMONIC mode count */ + short mode_count1; /* HQ_NORMAL mode count */ + short Nb_ACELP_frames; + short prev_Npeaks; /* number of peaks in previous frame */ + short prev_peaks[HVQ_MAX_PEAKS]; /* indices of the peaks in previous frame */ + short hvq_hangover; + short prev_hqswb_clas; + short prev_SWB_peak_pos[SPT_SHORTEN_SBNUM]; + + /* speech/music classification */ + short last_vad_spa; + short lt_old_mode[3]; + float lt_voicing; + float lt_corr; + float lt_tonality; + short lt_corr_pitch[3]; + short lt_hangover; + float lowrate_pitchGain; + + short prev_frm_index[NB_SWB_SUBBANDS_HAR_SEARCH_SB]; + short prev_frm_hfe2; + short prev_stab_hfe2; + float prev_ni_ratio; + float prev_En_sb[NB_SWB_SUBBANDS]; + short last_bitalloc_max_band[2]; + float last_ni_gain[BANDS_MAX]; + float last_env[BANDS_MAX]; + short last_max_pos_pulse; + + /* PVQ range coder state */ + unsigned int rc_low; + unsigned int rc_range; + short rc_cache; + short rc_carry; + short rc_carry_count; + short rc_num_bits; + short rc_tot_bits; + short rc_offset; + /*----------------------------------------------------------------------------------* + * TBE parameters + *----------------------------------------------------------------------------------*/ + + float old_speech_shb[L_LOOK_16k + L_SUBFR16k]; /* Buffer memories */ + float old_speech_wb[(L_LOOK_12k8 + L_SUBFR) * 5/16]; /* Buffer memories */ + float old_input_fhb[NS2SA(48000, ACELP_LOOK_NS + DELAY_FD_BWE_ENC_12k8_NS + DELAY_FIR_RESAMPL_NS) - L_FRAME48k/2]; + float prev_lsp_shb[LPC_SHB_ORDER]; + float state_ana_filt_shb[ 2 * ALLPASSSECTIONS_STEEP + 1 ]; /* states for the analysis filters */ + float cldfbHBLT; + /* states for the filters used in generating SHB excitation from WB excitation*/ + float mem_csfilt[2]; + + /* states for the filters used in generating SHB signal from SHB excitation*/ + float state_syn_shbexc[L_SHB_LAHEAD]; + float state_lpc_syn[LPC_SHB_ORDER]; + float old_bwe_exc[PIT16k_MAX * 2]; /* old excitation */ + short bwe_seed[2]; + float bwe_non_lin_prev_scale; + float old_bwe_exc_extended[NL_BUFF_OFFSET]; + float syn_overlap[L_SHB_LAHEAD]; /* overlap buffer used to Adjust SHB Frame Gain*/ + float decim_state1[(2*ALLPASSSECTIONS_STEEP+1)]; + float decim_state2[(2*ALLPASSSECTIONS_STEEP+1)]; + float mem_genSHBexc_filt_down_wb2[(2*ALLPASSSECTIONS_STEEP+1)]; + float mem_genSHBexc_filt_down_wb3[(2*ALLPASSSECTIONS_STEEP+1)]; + float mem_genSHBexc_filt_down_shb[(2*ALLPASSSECTIONS_STEEP+1)]; + + float elliptic_bpf_2_48k_mem[4][4]; + float prev_fb_energy; + float prev_gainFr_SHB; + float lsp_shb_slow_interpl[LPC_SHB_ORDER]; + float lsp_shb_fast_interpl[LPC_SHB_ORDER]; + float shb_inv_filt_mem[LPC_SHB_ORDER]; + float lsp_shb_spacing[3]; + float prev_swb_GainShape; + short prev_frGainAtten; + + short spectral_tilt_reset; + short consec_inactive; + float ra_deltasum; + short trigger_SID; + float running_avg; + float snr_sum_vad; + + float prev_wb_GainShape; + float swb_lsp_prev_interp[LPC_SHB_ORDER]; + float fb_state_lpc_syn[LPC_SHB_ORDER]; + float fb_tbe_demph; + float tilt_mem; + + + short prev_coder_type; + float prev_lsf_diff[LPC_SHB_ORDER-2]; + float prev_tilt_para; + float cur_sub_Aq[M+1]; + + /* quantized data */ + short lsf_idx[NUM_Q_LSF]; + short m_idx; + short grid_idx; + short idxSubGains; + short idxFrameGain; + short idx_shb_fr_gain; + short idx_res_gs[NB_SUBFR16k]; + short idx_mixFac; + + short lsf_WB; + short gFrame_WB; + + short idxGain; + float dec_2_over_3_mem[12]; + float dec_2_over_3_mem_lp[6]; + + + /*----------------------------------------------------------------------------------* + * SWB BWE parameters + *----------------------------------------------------------------------------------*/ + + float new_input_hp[NS2SA(16000, ACELP_LOOK_NS + DELAY_FD_BWE_ENC_NS + DELAY_FIR_RESAMPL_NS - DELAY_CLDFB_NS)]; + float old_input[NS2SA(48000, DELAY_FD_BWE_ENC_NS + DELAY_FIR_RESAMPL_NS)]; + float old_input_wb[NS2SA(16000, DELAY_FD_BWE_ENC_NS)]; + float old_input_lp[NS2SA(16000, ACELP_LOOK_NS + DELAY_FD_BWE_ENC_NS)]; + float old_syn_12k8_16k[NS2SA(16000, DELAY_FD_BWE_ENC_NS)]; + float old_fdbwe_speech[L_FRAME48k]; + float mem_deemph_old_syn; + short prev_mode; + float old_wtda_swb[L_FRAME48k]; + short prev_L_swb_norm1; + float prev_global_gain; + short modeCount; + float EnergyLF; + float tbe_demph; + float tbe_premph; + float mem_stp_swb[LPC_SHB_ORDER]; + float *ptr_mem_stp_swb; + float gain_prec_swb; + float mem_zero_swb[LPC_SHB_ORDER]; + + /*----------------------------------------------------------------------------------* + * WB, SWB and FB bandwidth detector + *----------------------------------------------------------------------------------*/ + + float lt_mean_NB; + float lt_mean_WB; + float lt_mean_SWB; + short count_WB; + short count_SWB; + short count_FB; + + /*----------------------------------------------------------------------------------* + * SWB DTX/CNG parameters + *----------------------------------------------------------------------------------*/ + + short last_vad; + float last_wb_cng_ener; + float last_shb_cng_ener; + float mov_wb_cng_ener; + float mov_shb_cng_ener; + short shb_cng_ini_cnt; + short last_SID_bwidth; + short shb__NO_DATA_cnt; + + /*----------------------------------------------------------------------------------* + * Channel-aware mode + *----------------------------------------------------------------------------------*/ + + short rf_mode; /* flag to signal the RF mode */ + short rf_mode_last; + short last_rf_mode_cng; + short Opt_RF_ON; + short rf_frame_type; + + short rf_target_bits_write; + short rf_fec_offset; + short rf_targetbits_buff[MAX_RF_FEC_OFFSET]; + int rf_indx_frametype[MAX_RF_FEC_OFFSET]; + + float rf_mem_w0; + float rf_clip_var[6]; + float rf_tilt_code; + float rf_mem_syn2[M]; + float rf_dispMem[8]; + float rf_gc_threshold; + + short rf_target_bits; + float rf_tilt_buf[NB_SUBFR16k]; + + short rf_indx_lsf[MAX_RF_FEC_OFFSET][3]; + int rf_indx_pitch[MAX_RF_FEC_OFFSET][NB_SUBFR16k]; + int rf_indx_fcb[MAX_RF_FEC_OFFSET][NB_SUBFR16k]; + int rf_indx_gain[MAX_RF_FEC_OFFSET][NB_SUBFR16k]; + int rf_indx_EsPred[MAX_RF_FEC_OFFSET]; + int rf_indx_ltfMode[MAX_RF_FEC_OFFSET][NB_SUBFR16k]; + + short rf_indx_nelp_fid[MAX_RF_FEC_OFFSET]; + short rf_indx_nelp_iG1[MAX_RF_FEC_OFFSET]; + short rf_indx_nelp_iG2[MAX_RF_FEC_OFFSET][2]; + + short rf_indx_tbeGainFr[MAX_RF_FEC_OFFSET]; + + int rf_tcxltp_pitch_int_past; + int rf_last_tns_active; + int rf_second_last_tns_active; + int rf_second_last_core; + short rf_clas[MAX_RF_FEC_OFFSET]; + int rf_gain_tcx[MAX_RF_FEC_OFFSET]; + int rf_tcxltp_param[MAX_RF_FEC_OFFSET]; + + short rf_fec_indicator; + short RF_bwe_gainFr_ind; + + /*----------------------------------------------------------------------------------* + * Local synthesis parameters + *----------------------------------------------------------------------------------*/ + + + /*----------------------------------------------------------------------------------* + * + * Mode2 + * + *----------------------------------------------------------------------------------*/ + + int frame_size_index; /*0-FRAME_SIZE_NB-1: index determining the frame size*/ + int bits_frame_nominal; /*avg bits per frame on active frame*/ + int bits_frame; /*bits per frame overall */ + int bits_frame_core; /*bits per frame for the core*/ + int narrowBand; + + /*ACELP config*/ + ACELP_config acelp_cfg; /*configuration set for each frame*/ + + ACELP_config acelp_cfg_rf; /* configuration for RF frame */ + + /*TCX config*/ + TCX_config tcx_cfg; + int L_frameTCX; + + /* cod_main.c */ + float mem_preemph_enc; /* speech preemph filter memory (at encoder-sampling-rate) */ + + /* Signal Buffers and Pointers at encoder-sampling-rate */ + float *speech_enc; + float *speech_enc_pe; + float *new_speech_enc; + float *new_speech_enc_pe; + float buf_speech_enc[L_PAST_MAX_32k+L_FRAME32k+L_NEXT_MAX_32k]; + float buf_speech_enc_pe[L_PAST_MAX_32k+L_FRAME32k+L_NEXT_MAX_32k]; + float *wspeech_enc; + float buf_wspeech_enc[L_FRAME16k+L_SUBFR+L_FRAME16k+L_NEXT_MAX_16k]; + float *synth; + float buf_synth[OLD_SYNTH_SIZE_ENC+L_FRAME32k]; /*can be reduced to PIT_MAX_MAX+L_FRAME_MAX if no rate switching*/ + float *speech_TCX; + float *new_speech_TCX; + + /* Core Signal Analysis Outputs */ + float *spectrum[2]; /* MDCT output for a short block */ + float spectrum_long[N_MAX]; /* MDCT output for a long block. Points to spectrum */ + float noiseTiltFactor; /* compensation for LPC tilt in noise filling */ + int noiseLevelMemory; /* counter of consecutive low TCX noise levels */ + STnsData tnsData[2]; + int fUseTns[2]; + + int enableTcxLpc; /* global toggle for the TCX LPC quantizer */ + int envWeighted; /* are is{p,f}_old_q[] weighted or not? */ + + int acelpEnabled; /* Flag indicating if ACELP can be used */ + int tcx10Enabled; /* Flag indicating if TCX 10 can be used */ + int tcx20Enabled; /* Flag indicating if TCX 20 can be used */ + + short tcxMode; /* Chosen TCX mode for this frame */ + + float mem_wsp_enc; /* wsp vector memory */ + + int nb_bits_header_ace; /* number of bits for the header */ + int nb_bits_header_tcx; /* number of bits for the header */ + + /* restrict the possible in EVS: 0 base 10 = d.c.b.a base 2*/ + /* a = 0/1 : ACELP on/off*/ + /* b = 0/1 : TCX20 on/off*/ + /* c = 0/1 : TCX40 on/off*/ + /* d = 0/1 : TCX80 on/off*/ + short restrictedMode; + + + + + /* Framing */ + int nb_subfr; + + float preemph_fac; /*Preemphasis factor*/ + float gamma; + + TransientDetection transientDetection; + int transient_info[3]; + + int acelpFramesCount; + float prevTempFlatness; + + float prevEnergyHF; + float currEnergyHF; + float currEnergyLookAhead; + + int lpcQuantization; + + int encoderLookahead_enc; + int encoderPastSamples_enc; + int encoderLookahead_FB; + + /* pitch_ol for adaptive lag window */ + int old_pitch_la; /* past open loop pitch lag from look-ahead */ + float old_voicing_la; /* past open loop pitch gain from look-ahead */ + + + int tcxonly; + + short flag_noisy_speech_snr; /* encoder detector for noisy speech */ + + int fscale; + int sr_core; + int acelp_autocorr; /* Optimize acelp in 0 covariance or 1 correlation domain */ + + int pit_min; + int pit_fr1; + int pit_fr1b; + int pit_fr2; + int pit_max; + int pit_res_max; + + /* for FAC */ + int L_frame_past; + + int memQuantZeros[L_FRAME_PLUS]; /* Quantization deadzone flags */ + + /*Adaptive BPF*/ + int bpf_gain_param; + float mem_bpf[2*L_FILT16k]; + float mem_error_bpf[2*L_FILT16k]; + + /* TCX-LTP */ + int tcxltp; + int tcxltp_pitch_int; + int tcxltp_pitch_fr; + float tcxltp_gain; + int tcxltp_pitch_int_past; + int tcxltp_pitch_fr_past; + float tcxltp_gain_past; + float tcxltp_norm_corr_past; + float buf_speech_ltp[L_PAST_MAX_32k+L_FRAME32k+L_NEXT_MAX_32k]; + float *speech_ltp; + float *new_speech_ltp; + short tcxltp_filt_idx; + int tcxltp_bits; + int tcxltp_param[LTPSIZE]; + + float measuredBwRatio; /* measured bw; used for TCX noise-filling */ + int nmStartLine; /* Starting line for the noise measurement */ + + short glr; + short glr_idx[2]; + float mean_gc[2]; + float prev_lsf4_mean; + short glr_reset; + int last_sr_core; + float last_stab_fac; + + /*for rate switching*/ + short rate_switching_reset; /*Rate switching flag requiring a reset of memories at least partially */ + short rate_switching_reset_16kHz; + + short enablePlcWaveadjust; + short Tonal_SideInfo; + + short seed_acelp; + + short tcx_lpc_shaped_ari; + + PLC_ENC_EVS plcExt; + T_CldfbVadState vad_st; + + IGF_ENC_INSTANCE hIGFEnc; + short igf; + + short tec_tfa; + TEMPORAL_ENVELOPE_CODING_ENCODER tecEnc; + short tec_flag; + short tfa_flag; + float tfa_enr[N_TEC_TFA_SUBFR]; + + short vbr_generic_ho; + float last_7k2_coder_type; + + short sharpFlag; + + + short Local_VAD; + +} Encoder_State; + + +/*---------------------------------------------------------------* + * Encoder Static RAM * + *---------------------------------------------------------------*/ + +typedef struct GainItemStr +{ + float nmrValue; + short gainIndex; +} GainItem; + +/* Structure for storing correlations between ACELP codebook components and target */ +typedef struct +{ + float xx; /* energy of target x */ + float y1y1; /* energy of adaptive cbk contribution y1 */ + float y2y2; /* energy of fixed cbk contribution y2 */ + float xy1; /* correlation of x and y1 */ + float xy2; /* correlation of x and y2 */ + float y1y2; /* correlation of y1 and y2 */ +} ACELP_CbkCorr; + +struct PLC_ENC_EVS; +typedef struct PLC_ENC_EVS * HANDLE_PLC_ENC_EVS; + + +#endif diff --git a/src/libs/libevs/lib_enc/stat_enc_fx.h b/src/libs/libevs/lib_enc/stat_enc_fx.h deleted file mode 100755 index e7fecc63..00000000 --- a/src/libs/libevs/lib_enc/stat_enc_fx.h +++ /dev/null @@ -1,1325 +0,0 @@ -/*==================================================================================== - EVS Codec 3GPP TS26.442 Apr 03, 2018. Version 12.11.0 / 13.6.0 / 14.2.0 - ====================================================================================*/ - -#ifndef STAT_ENC_FX_H -#define STAT_ENC_FX_H - -#include -#include "options.h" /* Compilation switches */ -#include "cnst_fx.h" /* Common constants */ -#include "stat_dec_fx.h" /* Compilation switches */ - - -/*------------------------------------------------------------------------------------------* - * Indice - *------------------------------------------------------------------------------------------*/ - -typedef struct -{ - UWord16 value; /* value of the quantized indice */ - Word16 nb_bits; /* number of bits used for the quantization of the indice */ -} Indice_fx; - -typedef struct -{ - Word32 r; - Word32 i; -} complex_32; -typedef struct -{ - Word16 r; - Word16 i; -} complex_16; -typedef struct -{ - Word16 s16Exp; - Word32 s32Mantissa; -} T_VAD_EXP; - -typedef struct -{ - Word16 bw_index; /* index of band width */ - - /* feature */ - Word16 sp_center[SP_CENTER_NUM]; /* spectral center*/ - Word16 ltd_stable_rate[STABLE_NUM]; /* time-domain stable rate*/ - Word16 sfm[SFM_NUM]; /* spectral flatness*/ - Word16 f_tonality_rate[TONA_NUM]; /* tonality rate*/ - Word16 pre_spec_low_dif[PRE_SPEC_DIF_NUM]; /* low frequency spectral different*/ - Word32 frames_power_32[POWER_NUM]; /* energy of several frames*/ - Word32 frame_sb_energy[BG_ENG_NUM]; /* energy of sub-band divided non-uniformly*/ - Word32 t_bg_energy; /* time background energy of several frames*/ - T_VAD_EXP t_bg_energy_sum; /* number of time background energy*/ - Word16 tbg_energy_count; /* sum of time background energy of several frames*/ - Word16 bg_update_count; /* time of background update*/ - Word32 frame_energy_smooth; /* smoothed energy of several frames*/ - - /************************************************************************/ - /* history parameters */ - /************************************************************************/ - Word32 smooth_spec_amp[SPEC_AMP_NUM]; /* smoothed spectral amplitude*/ - Word32 pre_snr[PRE_SNR_NUM]; /* previous time SNR*/ - Word32 sb_bg_energy[BG_ENG_NUM]; /* sub-band background energy*/ - Word16 continuous_noise_num; /* time of continuous noise frames*/ - Word16 continuous_speech_num; /* time of continuous speech frames*/ - Word16 continuous_speech_num2; /* time 2 of continuous speech frames*/ - Word32 fg_energy_est_start; /* flag by that indicate whether if estimate energy*/ - Word16 speech_flag; /* residual number of hangover 1 */ - Word32 lt_noise_sp_center_diff_counter; /* number of the member lt_noise_sp_center_diff_sum*/ - Word32 fg_energy; /* foreground energy sum */ - Word32 bg_energy; /* background energy sum */ - Word32 lt_bg_highf_eng; /* average of long time high frequency energy*/ - Word32 lt_noise_sp_center_diff_sum; /* different sum of long time noise sp_center*/ - Word32 lt_snr_org; /* original long time SNR*/ - Word32 l_speech_snr; /* sum of snr's of active frames*/ - Word32 l_silence_snr; /* sum of snr's of non active frames*/ - Word32 l_speech_snr_count; /* number of active frames*/ - Word32 l_silence_snr_count; /* number of non active frames*/ - Word32 lf_snr_smooth; /* smoothed lf_snr*/ - Word16 frameloop; /* number of frame*/ - Word16 lt_noise_sp_center0; /* long time noise sp_center0*/ - Word16 lt_noise_sp_center3; /* long time noise sp_center3*/ - Word16 music_background_rate; /* music background rate*/ - Word16 tonality_rate3; /* tonality rate*/ - Word16 bg_energy_count; /* number of the background energy frame */ - Word16 fg_energy_count; /* number of the foreground energy frame */ - Word16 Q_frames_power_32; /* the Scaling of frames_power_fix32*/ - Word16 scale_spec_low_dif; /* the Scaling of spec_low_dif*/ - Word16 sb_bg_energy_scale; /* the Scaling of sb_bg_energy*/ - Word16 frame_sb_energy_scale; /* the Scaling of frame_sb_energy*/ - Word16 scale_t_bg_energy; /* the Scaling of t_bg_energy*/ - Word16 frame_energy_smooth_scale; /* the Scaling of frame_energy_smooth*/ - Word16 bg_energy_scale; /* the Scaling of bg_energy*/ - Word16 fg_energy_scale; /* the Scaling of fg_energy*/ - Word16 updateNumWithSnr; /* the number of the background update with SNR*/ - Word16 update_count; /* the number of the background update*/ - Word16 warm_hang_num; /* the number of hangover for warm up*/ - Word16 vad_flag_for_bk_update; -} T_CldfbVadState; - -/*ari.h*/ -typedef struct -{ - Word32 low,high; - Word16 vobf; -} TastatEnc; - -/*---------------------------------------------------------------* - * IGF * - *---------------------------------------------------------------*/ -/* IGFSCFEncoder.h */ -typedef struct -{ - Word16 ptrBitIndex; - Word16 bitCount; - Word16 prev[64]; /* no more than 64 SCFs for the IGF energy envelope of one block, short or long */ - Word16 prevSave[64]; - Word16 scfCountLongBlock; - Word16 t; - Word16 tSave; - Word16 context_saved; - const Word16 *cf_se00; - const Word16 *cf_se01; - Word16 cf_off_se01; - const Word16 *cf_se02; - const Word16 *cf_off_se02; - const Word16 *cf_se10; - Word16 cf_off_se10; - const Word16 *cf_se11; - const Word16 *cf_off_se11; - TastatEnc acState; -} IGFSCFENC_INSTANCE, *IGFSCFENC_INSTANCE_HANDLE; - -/* IGFEnc.h */ -typedef struct igf_enc_private_data_struct -{ - IGF_INFO igfInfo; - Word16 igfScfQuantized[IGF_MAX_SFB]; - IGFSCFENC_INSTANCE hIGFSCFArithEnc; - - - /*** whitening ***/ - Word16 igfCurrWhiteningLevel[IGF_MAX_TILES]; - Word16 igfPrevWhiteningLevel[IGF_MAX_TILES]; - - Word32 prevSFM_FIR[IGF_MAX_TILES]; /* 15Q16 */ - Word16 prevSFM_IIR[IGF_MAX_TILES]; /* 2Q13 */ - Word16 wasTransient; /* 15Q0 */ - - UWord8 igfBitstream[BITBUFSIZE/8]; - Word16 igfBitstreamBits; - -} IGF_ENC_PRIVATE_DATA, *IGF_ENC_PRIVATE_DATA_HANDLE; - -typedef struct igf_enc_instance_struct -{ - IGF_ENC_PRIVATE_DATA igfData; - Word32 infoSamplingRate; - Word16 infoStartFrequency; - Word16 infoStopFrequency; - Word16 infoStartLine; - Word16 infoStopLine; - Word16 infoTotalBitsWritten; - Word16 infoTotalBitsPerFrameWritten; - Word16 flatteningTrigger; - Word32 spec_be_igf[N_MAX_TCX-IGF_START_MN]; /* copy of MDCT spectrum */ - Word16 spec_be_igf_e; /* exponent of copy of MDCT spectrum */ - Word16 tns_predictionGain; -} IGF_ENC_INSTANCE, *IGF_ENC_INSTANCE_HANDLE; - - - -typedef struct -{ - Word16 nbits; /* number of bits used by ACELP or TCX */ - - /* signal memory */ - Word16 syn[1+M]; /* Synthesis memory (non-pe) */ - /*Word16 wsyn;*/ /* Weighted synthesis memory */ - Word16 mem_syn[M]; /* ACELP synthesis memory (pe) before post-proc */ - Word16 mem_syn2[M]; /* ACELP synthesis memory (pe) after post-proc */ - Word16 mem_w0; /* weighting filter memory */ - Word16 tilt_code; - Word16 mem_syn_r[L_SYN_MEM]; /* ACELP synthesis memory for 1.25ms */ - Word16 mem_syn3[M]; - - /* ACELP memory */ - Word16 old_exc[L_EXC_MEM]; /* ACELP exc memory (Aq) */ - - /* TCX memory */ - Word16 Txnq[L_FRAME32k/2+64]; /* Q target (overlap or ACELP+ZIR, use Aq) */ - Word16 *acelp_zir; - Word16 tcx_target_bits_fac; - - Word32 gc_threshold; /* exponent = 15, 15Q16 */ - -} LPD_state; - - -typedef struct PLC_ENC_EVS -{ - - Word16 nBits; /* number of bits */ - Word16 enableGplc; - - Word16 Q_new; - Word16 Q_exp; - - Word16 T0_4th; - Word16 T0; - Word16 old_exc_Qold[8]; /* ACELP exc memory (Aq) */ - Word8 calcOnlylsf; - Word16 pit_min; - Word16 pit_max; - - Word16 lsfoldbfi0_14Q1[M]; /* Previous frame LSF */ - Word16 lsfoldbfi1_14Q1[M]; /* Past previous frame LSF */ - Word16 lsfold_14Q1[M]; /* old lsf (frequency domain) */ - Word16 lspold_Q15[M]; /* old lsp (immittance spectral pairs) */ - - Word16 mem_MA_14Q1[M]; - Word16 mem_AR[M]; - Word16 lsf_adaptive_mean_14Q1[M]; /* Mean isf for bfi cases */ - Word16 stab_fac_Q15; - - - /* For TCX case */ - - LPD_state *LPDmem; - Word16 lsf_con[M]; - Word16 last_lsf_ref[M]; - Word16 last_lsf_con[M]; -} PLC_ENC_EVS, *HANDLE_PLC_ENC_EVS; - - -/*****************************************/ -/* MODE2 STAT ENC */ -/*****************************************/ - -/*transient_detection.h*/ -/** Delay buffer. - * Used to buffer input samples and to define the subblock size of a transient detector. - */ -typedef struct -{ - /** Subblock size of a transient detector that uses this delay buffer. */ - Word16 nSubblockSize; - /** Delay buffer */ - Word16 buffer[L_FRAME48k/NSUBBLOCKS]; - /** Size of the delay buffer in use. Maximum delay from all users of this buffer. */ - Word16 nDelay; -} DelayBuffer; - -/** Subblock energies. - * Holds subblock energies and recursively accumulated energies. - * Also buffers the energies. - */ -typedef struct -{ - /** Delay buffer. */ - DelayBuffer * pDelayBuffer; - /** Subblock energies with a delay buffering. */ - Word32 subblockNrg[NSUBBLOCKS+MAX_TD_DELAY]; - /** Recursively accumulated subblock energies with a delay buffering. - At index i the value corresponds to the accumulated subblock energy up to i-1, - including block i-1 and without block i. */ - Word32 accSubblockNrg[NSUBBLOCKS+MAX_TD_DELAY+1]; - /** subblockNrgChange[i] = max(subblockNrg[i]/subblockNrg[i-1], subblockNrg[i-1]/subblockNrg[i]) */ - Word16 subblockNrgChange[NSUBBLOCKS+MAX_TD_DELAY]; - /** Size of the delay buffer in use, as number of subblocks. Maximum delay from all users of this buffer. */ - Word16 nDelay; - /* Delay of the input (modulo pDelayBuffer->nSubblockSize), nPartialDelay <= pDelayBuffer->nDelay. */ - Word16 nPartialDelay; - - /** Decay factor for the recursive accumulation */ - Word16 facAccSubblockNrg; - - /** High-pass filter states (delay line) */ - Word16 firState1; - Word16 firState2; - -} SubblockEnergies; - -struct TransientDetector; - -/** Attack detection function. - * Definition of a function used for checking the presence of an attack, given subblock energies, accumulated subblock energies and a threshold. - * @param pSubblockNrg Subblock energies. - * @param pAccSubblockNrg Recursively accumulated subblock energies. - At index i the value corresponds to the accumulated subblock energy up to i-1, - including block i-1 and without block i. - * @param nSubblocks Number of subblocks available (those with an index >= 0). Subblocks from 0 to NSUBBLOCKS-1 correspond to the current frame. - * @param nPastSubblocks Number of past subblocks available (those with a negative index). - * @param attackRatioThreshold Attack ratio threshold. - * @param pbIsAttackPresent Pointer to an output variable that will be set to TRUE if an attack is found, otherwise set to FALSE. - * @param pAttackIndex Pointer to an output variable that will hold an attack position. - */ -typedef void (* TCheckSubblocksForAttack)(Word32 const * pSubblockNrg, Word32 const * pAccSubblockNrg, Word16 nSubblocks, Word16 nPastSubblocks, Word16 attackRatioThreshold, Word16 * pbIsAttackPresent, Word16 * pAttackIndex); - -/** Transient detector. - */ -typedef struct TransientDetector -{ - /** Subblock energies used in this transient detector. */ - SubblockEnergies * pSubblockEnergies; - /* Delay of the transient detector in number of subblocks, nDelay <= pSubblockEnergies->nDelay. */ - Word16 nDelay; - /** Number of subblocks to check for transients. */ - Word16 nSubblocksToCheck; - /** Function for checking a presence of an attack. */ - TCheckSubblocksForAttack CheckSubblocksForAttack; - /** Attack ratio threshold. */ - Word16 attackRatioThreshold; - /** True when an attack was detected. */ - Word16 bIsAttackPresent; - /** The index of an attack. */ - Word16 attackIndex; - -} TransientDetector; - - -/** Transient detection. - * Holds all transient detectors and buffers used by them. - */ -typedef struct TransientDetection -{ - /** Transient detector. */ - TransientDetector transientDetector; - /** Delay buffer used by the transient detectors. */ - DelayBuffer delayBuffer; - /** Subblock energies used by the transient detector. */ - SubblockEnergies subblockEnergies; -} TransientDetection; - -/* Arrays and variables specific to encoder */ -typedef struct -{ - HANDLE_FD_CNG_COM hFdCngCom; - - Word32 msPeriodog[NPART]; /* Periodogram */ - Word16 msPeriodog_exp; /* Common exponent for fft and cldfb energies */ - Word16 msPeriodog_exp_fft; - Word16 msPeriodog_exp_cldfb; - Word32 msBminWin[NPART]; - Word32 msBminSubWin[NPART]; - Word16 msPsd[NPART]; /* Power Spectral Density estimate (i.e., smoothed periodogram) */ - Word32 msAlpha[NPART]; /* Optimal smoothing parameter */ - Word32 msMinBuf[MSNUMSUBFR*NPART]; /* Buffer of minima */ - Word32 msCurrentMinOut[NPART]; - Word32 msCurrentMin[NPART]; - Word32 msCurrentMinSubWindow[NPART]; - Word16 msLocalMinFlag[NPART]; - Word16 msNewMinFlag[NPART]; - Word16 msPsdFirstMoment[NPART]; - Word32 msPsdSecondMoment[NPART]; - Word16 msNoiseFloor[NPART]; /* Estimated noise floor */ - Word32 msNoiseEst[NPART]; /* Estimated noise level */ - Word16 msNoiseEst_exp; - Word32 energy_ho[NPART]; - Word16 energy_ho_exp; - Word32 msNoiseEst_old[NPART]; - Word16 msNoiseEst_old_exp; - - Word16 msPeriodogBuf[MSBUFLEN*NPART]; - Word16 msPeriodogBufPtr; - - Word16 stopFFTbinDec; - Word16 startBandDec; - Word16 stopBandDec; - Word16 npartDec; - Word16 midbandDec[NPART]; - Word16 nFFTpartDec; - Word16 partDec[NPART]; - - Word16 msLogPeriodog[NPART]; - Word16 msLogNoiseEst[NPART]; -} -FD_CNG_ENC; -typedef FD_CNG_ENC *HANDLE_FD_CNG_ENC; - - -struct MEM_BPF -{ - Word16 noise_buf[2*L_FILT16k]; - Word16 error_buf[L_FILT16k]; - Word32 lp_error; - Word32 lp_error_ener; - Word16 noise_shift_old; -} mem_bpf; - - -typedef struct Encoder_State_fx -{ - - /*----------------------------------------------------------------------------------* - * Common parameters - *----------------------------------------------------------------------------------*/ - - Word16 codec_mode; /* MODE1 or MODE2 */ - Word16 last_codec_mode; /* Previous Codec Mode*/ - Word16 last_codec_mode_cng; /* Codec Mode of the last inactive frame*/ - Word16 mdct_sw_enable; /* MDCT switching enable flag */ - Word16 mdct_sw; /* MDCT switching indicator */ - Word16 prev_hi_ener; - Word16 prev_hi_sparse; - Word16 clas_sec_old_fx; /* MDCT classifier secondary decision memory */ - Word16 clas_final_old_fx; /* MDCT classifier final decision memory */ - Word32 last_gain1; - Word32 last_gain2; - Word16 last_enerBuffer_exp; - Word16 nb_bits_tot_fx; /* total number of bits already written */ - Word16 next_bit_pos_fx; /* position of the next bit to be written in the bitstream */ - Indice_fx *ind_list_fx; /* list of indices */ - Word16 next_ind_fx; /* pointer to the next empty slot in the list of indices */ - Word16 last_ind_fx; /* last written indice */ - Word16 bitstreamformat; /* Bitstream format flag (G.192/MIME) */ - - Word32 input_Fs_fx; /* input signal sampling frequency in Hz */ - Word32 total_brate_fx; /* total bitrate in kbps of the codec */ - Word32 last_total_brate_fx; /* total bitrate in kbps of the codec */ - Word32 last_total_brate_cng_fx; /* total bitrate in kbps of the last inactive frame */ - Word16 core_fx; /* core (ACELP_CORE, TCX_20_CORE, TCX_10_CORE, HQ_CORE, AMR_WB_CORE) */ - Word32 core_brate_fx; /* core bitrate */ - Word32 last_core_brate_fx; /* previous frame core bitrate */ - Word16 input_frame_fx; /* Frame lenght (function of input_Fs) */ - Word16 extl_fx; /* extension layer */ - Word16 last_extl_fx; /* previous extension layer */ - Word32 extl_brate_fx; /* extension layer bitrate */ - Word16 input_bwidth_fx; /* input signal bandwidth */ - Word16 last_input_bwidth_fx; /* input signal bandwidth in the previous frame */ - Word16 bwidth_fx; /* encoded bandwidth NB, WB, SWB or FB */ - Word16 max_bwidth_fx; /* maximum encoded bandwidth */ - Word16 last_bwidth_fx; /* input signal bandwidth in the previous frame */ - Word16 last_bwidth_cng_fx; /* input signal bandwidth in the previous inactive frame */ - Word16 L_frame_fx; /* ACELP core internal frame length */ - Word16 Opt_AMR_WB_fx; /* flag indicating AMR-WB IO mode */ - Word16 Opt_DTX_ON_fx; /* flag indicating DTX operation */ - Word16 cng_type_fx; /* flag indicating LP or CLDFB based SID/CNG */ - Word16 active_fr_cnt_fx; /* counter of active frames */ - Word16 Opt_SC_VBR_fx; /* flag indicating SC-VBR mode */ - Word16 last_Opt_SC_VBR_fx; /* flag indicating SC-VBR mode in the last frame */ - Word16 lp_cng_mode2; - - /*----------------------------------------------------------------------------------* - * ACELP core parameters - *----------------------------------------------------------------------------------*/ - - Word16 clas_fx; /* current frame clas */ - Word16 last_clas_fx; /* previous frame signal classification */ - Word32 Bin_E_fx[L_FFT]; /* Q_new + Q_SCALE -2 per bin energy of two frames */ - Word32 Bin_E_old_fx[L_FFT/2]; /* per bin energy of old 2nd frames */ - Word16 lsp_old1_fx[M]; /* old unquantized LSP vector at the end of the frame */ - Word16 lsf_old1_fx[M]; /* old LSF vector at the end of the frame */ - Word16 lsp_old_fx[M]; /* old LSP vector at the end of the frame */ - Word16 lsf_old_fx[M]; /* old LSF vector at the end of the frame */ - Word16 lsp_old16k_fx[M]; /* old LSP vector at the end of the frame @16kHz */ - Word16 lspold_enc_fx[M]; /* old LSP vector at the end of the frame @16kHz */ - Word16 pstreaklen_fx; /* LSF quantizer */ - Word16 streaklimit_fx; /* LSF quantizer */ - Word32 offset_scale1_fx[MAX_NO_MODES+1][MAX_NO_SCALES+1]; /* offsets for LSF LVQ structure 1st 8-dim subvector*/ - Word32 offset_scale2_fx[MAX_NO_MODES+1][MAX_NO_SCALES+1]; /* offsets for LSF LVQ structure 2nd 8-dim subvector*/ - Word32 offset_scale1_p_fx[MAX_NO_MODES_p+1][MAX_NO_SCALES+1]; /* offsets for LSF LVQ structure, pred. case, 1st 8-dim subvector*/ - Word32 offset_scale2_p_fx[MAX_NO_MODES_p+1][MAX_NO_SCALES+1]; /* offsets for LSF LVQ structure, pred. case, 2nd 8-dim subvector*/ - Word16 no_scales_fx[MAX_NO_MODES][2]; /* LSF LVQ structure Q0*/ - Word16 no_scales_p_fx[MAX_NO_MODES_p][2]; /* LSF LVQ structure Q0*/ - Word16 stab_fac_fx; /* LSF stability factor */ - Word16 mem_decim_fx[2*L_FILT_MAX]; /* decimation filter memory */ - Word16 mem_deemph_fx; /* deemphasis filter memory */ - Word16 mem_preemph_fx; /* preemphasis filter memory */ - Word32 mem_hp20_in_fx[5]; /* HP filter memory for AMR-WB IO */ - Word16 old_inp_12k8_fx[L_INP_MEM]; /* memory of input signal at 12.8kHz */ - Word16 old_wsp_fx[L_WSP_MEM]; /* old weighted signal vector */ - /*Word16 old_exc_fx[L_EXC_MEM];*/ /* old excitation vector */ - Word16 old_wsp2_fx[(L_WSP_MEM - L_INTERPOL)/OPL_DECIM]; /* old decimated weighted signal vector qwsp */ - Word32 fr_bands1_fx[NB_BANDS]; /* Q_new + Q_SCALE spectrum per critical bands of the previous frame */ - Word32 fr_bands2_fx[NB_BANDS]; /* Q_new + Q_SCALE spectrum per critical bands 2 frames ago */ - Word16 mem_wsp_fx; /* weighted signal vector memory */ - Word16 mem_decim2_fx[3]; /* weighted signal decimation filter memory qwsp */ - Word16 mem_syn1_fx[M]; /* synthesis filter memory (for core switching and FD BWE) */ - - Word16 clip_var_fx[6]; - Word16 past_qua_en_fx[4]; - Word16 mem_AR_fx[M]; /* AR memory of LSF quantizer (past quantized LSFs without mean) */ - Word16 mem_MA_fx[M]; /* MA memory of LSF quantizer (past quantized residual) (used also in AMR-WB IO mode) */ - Word16 mCb1_fx; /* LSF quantizer - counter of stationary frames after a transition frame */ - Word16 coder_type_raw_fx; - Word16 last_coder_type_raw_fx; /* raw last_coder_type (coming from the sigal classification) */ - Word16 last_coder_type_fx; /*Q0 previous coding type */ - Word16 ini_frame_fx; /* initialization frames counter */ - Word16 old_thres_fx; /* normalized correlation weighting in open-loop pitch Q15 */ - Word16 old_corr_fx; /* normalized correlation in previous frame (mean value) Q15 */ - Word16 old_pitch; /* previous pitch for open-loop pitch search Q0 */ - Word16 delta_pit_fx; /* open-loop pitch extrapolation correction Q0 */ - Word32 ee_old_fx; - Word16 min_band_fx; /* Q0 minimum critical band of useful bandwidth */ - Word16 max_band_fx; /* Q0 maximum critical band of useful bandwidth */ - Word16 tc_cnt_fx; /* TC frame counter */ - Word16 audio_frame_cnt_fx; /* Counter of relative presence of audio frames */ - Word32 old_dE1_fx; /* Maximum energy increase in previous frame */ - Word16 old_ind_deltaMax_fx; /* Index of the sub-subframe of maximum energy in previous frame */ - Word32 old_enr_ssf_fx[2*NB_SSF]; /* Maxima of energies per sub-subframes of previous frame */ - Word16 spike_hyst_fx; /* Hysteresis to prevent UC after sharp energy spike */ - Word16 music_hysteresis_fx; /* Counter of frames after AUDIO coding mode to prevent UC */ - Word16 last_harm_flag_acelp_fx; /* harmonicity flag for ACELP @32kbps rate */ - Word16 old_Aq_12_8_fx[M+1]; /* Q12 old Aq[] for core switching */ - Word16 old_Es_pred_fx; /* Q8 old Es_pred for core switching */ - Word16 high_stable_cor_fx; /* flag for stable high correlation */ - - Word16 seed_tcx_fx ; /* AC mode (GSC) - seed for noise fill*/ - Word16 cor_strong_limit_fx; /* AC mode (GSC) - Indicator about high spectral correlation per band */ - Word16 GSC_noisy_speech_fx; /* AC mode (GSC) - flag to indicate GSC on SWB noisy speech */ - Word16 mem_last_pit_band_fx; /* AC mode (GSC) - memory of the last band where pitch contribution was significant */ - Word16 mem_w0_tmp_fx; - Word16 mem_syn_tmp_fx[M]; - Word16 var_cor_t_fx[VAR_COR_LEN]; - Word16 mid_dyn_fx; /* AC mode (GSC) - signal dynamic */ - Word16 noise_lev_fx; /* AC mode (GSC) - Q0 noise level */ - Word16 past_dyn_dec_fx; /* AC mode (GSC) - Past noise level decision */ - Word32 Last_frame_ener_fx; /* AC mode (GSC) - Last frame energy */ - Word16 pit_exc_hangover; /* AC mode (GSC) - Hangover for the time contribution switching*/ - - Word16 last_exc_dct_in_fx[L_FRAME]; /* AC mode (GSC) - previous exciation */ - Word16 last_bitallocation_band_fx[6]; /* AC mode (GSC) - previous bit allocation of each band */ - - Word32 past_PS_fx[HIGHEST_FBIN-LOWEST_FBIN]; - Word16 past_ps_diff_fx; - Word16 past_epsP2_fx; - Word16 inact_cnt_fx; - Word16 wdrop_fx; - Word16 wdlp_0_95_sp_fx; - Word16 sp_mus_state_fx; - Word16 past_dec_fx[HANG_LEN-1]; - Word16 past_dlp_fx[HANG_LEN-1]; /* Speech/music classifier - buffer of past non-binary decisions */ - Word16 last_lsp_fx[M_LSP_SPMUS]; - Word16 last_cor_map_sum_fx; - Word16 last_non_sta_fx; - Word16 past_log_enr_fx[NB_BANDS_SPMUS]; /* Speech/music classifier - last average per-band log energy used for non_staX */ - - Word16 mold_corr_fx; - Word16 lt_gpitch_fx; /*Q15 */ - Word16 mean_avr_dyn_fx; /* Q7 Speech/music classifier - long term average dynamic */ - Word16 last_sw_dyn_fx; /* Q7 Speech/music classifier - last dynamic */ - Word16 lt_dec_thres_fx; /* Speech/music classifier - Long term speech/music thresold values */ - Word16 ener_RAT_fx; /* Q15 Speech/music classifier - LF/to total energy ratio */ - Word16 lgBin_E_fx[L_FFT/2]; /* Q8 per bin energy of two frames */ - - /* speech/music classifier improvement parameters */ - Word16 old_Bin_E_fx[3*N_OLD_BIN_E]; - Word16 buf_flux_fx[BUF_LEN]; - Word16 buf_pkh_fx[BUF_LEN]; - Word16 buf_epsP_tilt_fx[BUF_LEN]; - Word16 buf_cor_map_sum_fx[BUF_LEN]; - Word16 buf_Ntonal_fx[BUF_LEN]; - Word16 buf_Ntonal2_fx[BUF_LEN]; - Word16 buf_Ntonal_lf_fx[BUF_LEN]; - Word16 buf_dlp_fx[10]; - Word16 onset_cnt_fx; - Word16 buf_etot_fx[4]; - Word16 attack_hangover_fx; - Word16 dec_mov_fx; - Word16 dec_mov1_fx; - Word16 mov_log_max_spl_fx; - Word16 old_lt_diff_fx[2]; - Word16 UV_cnt1_fx; - Word16 LT_UV_cnt1_fx; - Word16 lpe_buf_fx[HANG_LEN_INIT]; - Word16 voicing_buf_fx[HANG_LEN_INIT]; - Word16 gsc_hangover_fx; - Word16 sparse_buf_fx[HANG_LEN_INIT]; - Word16 hf_spar_buf_fx[HANG_LEN_INIT]; - Word16 LT_sparse_fx; - Word16 gsc_cnt_fx; - Word16 last_vad_spa_fx; - - Word16 lt_music_hangover_fx; - Word16 tonality2_buf_fx[HANG_LEN_INIT]; - Word16 tonality3_buf_fx[HANG_LEN_INIT]; - Word16 LPCErr_buf_fx[HANG_LEN_INIT]; - Word16 lt_music_state_fx; - Word16 lt_speech_state_fx; - Word16 lt_speech_hangover_fx; - - Word16 Last_pulse_pos_fx; /* FEC - last position of the first glotal pulse in the frame */ - Word16 lsfoldbfi0_fx[M]; /* FEC - LSF vector of the previous frame */ - Word16 lsfoldbfi1_fx[M]; /* FEC - LSF vector of the past previous frame */ - Word16 lsf_adaptive_mean_fx[M]; /* FEC - adaptive mean LSF vector for FEC */ - Word16 next_force_safety_net_fx; /* FEC - flag to force safety net in next frame */ - Word16 gsc_last_music_flag_fx; /* Speech/music classifier - last music flag */ - Word16 gsc_lt_diff_etot_fx[MAX_LT]; /* Speech/music classifier - long-term total energy variation */ - Word16 gsc_thres_fx[4]; /* Speech/music classifier - classification threshold */ - Word16 gsc_nb_thr_1_fx; /* Speech/music classifier - number of consecutives frames of level 1 */ - Word16 gsc_nb_thr_3_fx; /* Speech/music classifier - number of consecutives frames of level 3 */ - Word16 gsc_mem_etot_fx; /* Speech/music classifier - total energy memory */ - - Word16 old_S_fx[L_FFT/2]; /* Q7 Tonal detector - prev. log-energy spectrum with subtracted floor */ - Word16 cor_map_fx[L_FFT/2]; /* Q15 Tonal detector - LT correlation map */ - Word16 noise_char_fx; /* Q11 Tonal detector - LT noise character */ - Word32 ave_enr2_fx[NB_BANDS]; /* Q_new + Q_SCALE Tonal detector - LT average E per crit. band (for non_sta2) */ - Word16 act_pred_fx; /* Q15 Tonal detector - prediction of speech activity from 0 to 1 (0-inactive, 1-active) */ - Word16 multi_harm_limit_fx; /* Q9 Tonal detector - adaptive threshold */ - Word32 enrO_fx[NB_BANDS]; /* Noise estimator - previous energy per critical band */ - Word32 bckr_fx[NB_BANDS]; /* Q_new + Q_SCALE Noise estimator - background noise estimation per critical band */ - Word32 ave_enr_fx[NB_BANDS]; /* Q_new + Q_SCALE Noise estimator - long-term average energy per critical band */ - Word16 pitO_fx; /* Q0 Noise estimator - previous open-loop pitch value */ - Word16 aEn_fx; /* Q0 Noise estimator - noise estimator adaptation flag */ - Word16 totalNoise_fx; /* Q8 Noise estimator - total noise energy */ - Word16 first_noise_updt_fx; /* Q0 Noise estimator - flag used to determine if the first noise update frame */ - Word16 harm_cor_cnt_fx; /* Q0 Noise estimator - 1st memory counter of harm or correlation frame */ - Word16 bg_cnt_fx; /* Q0 Noise estimator - pause length counter */ - Word16 prim_act_quick_fx; /* Noise estimator - primary activity quick */ - Word16 prim_act_slow_fx; /* Noise estimator - primary activity slow */ - Word16 prim_act_fx; /* Noise estimator - primary activity slow rise quick fall */ - Word16 prim_act_quick_he_fx; /* Noise estimator - primary activity quick */ - Word16 prim_act_slow_he_fx; /* Noise estimator - primary activity slow */ - Word16 prim_act_he_fx; /* Q15 Noise estimator - primary activity slow rise quick fall */ - Word16 Etot_l_fx; /* Q8 Noise estimator - Track energy from below */ - Word16 Etot_h_fx; /* Q8 Noise estimator - Track energy from above */ - Word16 Etot_l_lp_fx; /* Q8 Noise estimator - Smoothed low energy */ - Word16 Etot_last_fx; /*Q8*/ - Word16 Etot_lp_fx; /* Q8 Noise estimator - Filtered input energy */ - Word16 lt_tn_track_fx; /* Q15 */ - Word16 lt_tn_dist_fx; /* Q8*/ - Word16 lt_Ellp_dist_fx; /* Etot low lp same domain as *Etot_l_lp, Q8 */ - Word16 lt_haco_ev_fx; /* Q15 */ - Word16 low_tn_track_cnt_fx; /* Q0 */ - Word16 epsP_0_2_lp_fx; /* Q12, all epsP quotas , range ]8.0 ..0]*/ - Word16 epsP_0_2_ad_lp_fx; - Word16 epsP_2_16_lp_fx; - Word16 epsP_2_16_lp2_fx; - Word16 epsP_2_16_dlp_lp2_fx; /* Q12 */ - Word16 lt_aEn_zero_fx; /* Q15 */ - - Word16 Etot_st_est_fx; /* Q8 Noise estimation - short term estimate of E{ Etot } */ - Word16 Etot_sq_st_est_fx; /* Q2 Noise estimation - short term estimate of E{ Etot^2 } */ - - Word16 nb_active_frames_fx; - Word16 hangover_cnt_fx; - Word16 lp_speech_fx; - Word16 Etot_v_h2_fx; - - Word16 sign_dyn_lp_fx; /*Q8*/ - Word16 Opt_HE_SAD_ON_fx; - Word16 nb_active_frames_he_fx; - Word16 hangover_cnt_he_fx; - Word16 nb_active_frames_HE_SAD_fx; - - /* should be L_var */ - Word32 L_vad_flag_reg_H_fx; - Word32 L_vad_flag_reg_L_fx; - Word32 L_vad_prim_reg_fx; - Word16 vad_flag_cnt_50_fx; - Word16 vad_prim_cnt_16_fx; - - Word16 hangover_cnt_dtx_fx; - Word16 hangover_cnt_music_fx; - - - Word16 bcg_flux_fx; - Word16 soft_hangover_fx; - Word16 voiced_burst_fx; - Word16 bcg_flux_init_fx; - Word16 voicing_old_fx; - Word16 nb_active_frames_he1_fx; - Word16 hangover_cnt_he1_fx; - - - Word32 bckr_tilt_lt; - - Word16 var_SID_rate_flag_fx; /* CNG and DTX - flag for variable SID rate */ - Word32 lp_ener_fx; /* CNG and DTX - low-pass filtered energy for CNG */ - Word16 cng_seed_fx; /* CNG and DTX - seed for white noise random generator */ - Word16 lspCNG_fx[M]; /* CNG and DTX - LP filtered lsps */ - Word16 first_CNG_fx; /* CNG and DTX - first CNG frame flag */ - Word16 lp_noise_fx; /* CNG and DTX - LP filterend total noise estimation */ - Word16 cnt_SID_fx; /* CNG and DTX - counter of SID update for the interop. mode or dtx, if enabled*/ - Word16 max_SID_fx; /* CNG and DTX - max allowed number of CNG FRAME_NO_DATA frames */ - Word16 interval_SID_fx; /* CNG and DTX - interval of SID update, default 8 */ - Word16 old_enr_index_fx; /* CNG and DTX - index of last encoded CNG energy */ - Word32 Enew_fx; /* CNG and DTX - CNG target residual energy */ - Word16 VarDTX_cnt_voiced_fx; /* CNG and DTX - counter for variable DTX activation (speech) */ - Word32 lt_ener_voiced_fx; /* CNG and DTX - long-term energy of signal (measured on voiced parts) */ - Word16 VarDTX_cnt_noise_fx; /* CNG and DTX - counter for variable DTX activation (noise) */ - Word32 lt_ener_noise_fx; /* CNG and DTX - long-term energy of background noise */ - Word32 lt_ener_last_SID_fx; /* CNG and DTX - long-term energy of last SID frame */ - Word16 cng_hist_size_fx; /* CNG and DTX - size of CNG history buffer for averaging, <0,DTX_HIST_SIZE> */ - Word16 cng_hist_ptr_fx; /* CNG and DTX - pointer for averaging buffers */ - Word16 cng_lsp_hist_fx[DTX_HIST_SIZE*M]; /* CNG and DTX - old LSP buffer for averaging */ - Word16 cng_ener_hist_fx[DTX_HIST_SIZE]; /* CNG and DTX - log energy buffer for averaging */ - Word16 cng_cnt_fx; /* CNG and DTX - counter of CNG frames for averaging */ - Word16 cng_ener_seed_fx; /* CNG and DTX - seed for random generator for variation of excitation energy */ - Word16 cng_ener_seed1_fx; - Word32 frame_ener_fx; - Word16 lp_sp_enr_fx; /*Q8*/ - Word16 last_allow_cn_step_fx; - Word16 ho_hist_size_fx; /* CNG and DTX - size of DTX hangover history buffer for averaging, <0,HO_HIST_SIZE> */ - Word16 ho_hist_ptr_fx; /* CNG and DTX - pointer for averaging buffers */ - Word32 ho_sid_bw_fx; /* CNG and DTX - SID bandwidth flags */ - Word16 ho_lsp_hist_fx[HO_HIST_SIZE*M]; /* CNG and DTX - old LSP buffer for averaging */ - Word32 ho_ener_hist_fx[HO_HIST_SIZE]; /* CNG and DTX - energy buffer for averaging */ - Word32 ho_env_hist_fx[HO_HIST_SIZE*NUM_ENV_CNG]; - Word16 act_cnt_fx; /* CNG and DTX - counter of active frames */ - Word16 ho_circ_size_fx; /* CNG and DTX - size of DTX hangover history buffer for averaging, <0,HO_HIST_SIZE> */ - Word16 ho_circ_ptr_fx; /* CNG and DTX - pointer for averaging buffers */ - Word16 ho_lsp_circ_fx[HO_HIST_SIZE*M]; /* CNG and DTX - old LSP buffer for averaging */ - Word32 ho_ener_circ_fx[HO_HIST_SIZE]; /* CNG and DTX - energy buffer for averaging */ - Word32 ho_env_circ_fx[HO_HIST_SIZE*NUM_ENV_CNG]; - Word16 burst_ho_cnt_fx; /* CNG and DTX - counter of hangover frames at end of active burst */ - Word16 cng_buf_cnt; /* CNG and DTX - Counter of buffered CNG parameters */ - Word16 cng_exc2_buf[HO_HIST_SIZE*L_FFT]; /* CNG and DTX - exc2 buffer for storing */ - Word16 cng_Qexc_buf[HO_HIST_SIZE]; /* CNG and DTX - Q_exc buffer for storing */ - Word32 cng_brate_buf[HO_HIST_SIZE]; /* CNG and DTX - buffer for storing last_active_brate */ - - - Word16 CNG_mode_fx; /* CNG and DTX - mode for DTX configuration */ - Word32 last_active_brate_fx; /* CNG and DTX - last active frame bitrate used for CNG_mode control */ - Word16 ho_16k_lsp_fx[HO_HIST_SIZE]; /* CNG and DTX - 16k LSPs flags */ - Word16 last_CNG_L_frame_fx; /* CNG and DTX - last CNG frame length */ - Word16 act_cnt2_fx; /* CNG and DTX - counter of active frames for CNG_mode switching */ - Word16 ho_lsp_circ2_fx[HO_HIST_SIZE*M]; /* CNG and DTX - second buffer of LSPs */ - Word16 num_ho_fx; /* CNG and DTX - number of selected hangover frames */ - Word16 hangover_terminate_flag_fx; /* CNG and DTX - flag indicating whether to early terminate DTX hangover */ - Word32 old_env_fx[NUM_ENV_CNG]; - Word32 lp_env_fx[NUM_ENV_CNG]; - Word32 cng_res_env_fx[NUM_ENV_CNG*HO_HIST_SIZE]; - Word16 exc_mem_fx[24]; - Word16 exc_mem1_fx[30]; - Word16 exc_mem2_fx[30]; - - struct dispMem_fx dm_fx; /* Noise enhancer - phase dispersion algorithm memory */ - - Word16 uv_count_fx; /*Q0*/ /* Stationary noise UV modification - unvoiced counter */ - Word16 act_count_fx; /*Q0*/ /* Stationary noise UV modification - activation counter */ - Word32 ge_sm_fx; /* Stationary noise UV modification - smoothed excitation gain */ - Word16 lspold_s_fx[M]; /*Q15*/ /* Stationary noise UV modification - old LSP vector */ - Word16 noimix_seed_fx; /*Q0*/ /* Stationary noise UV modification - mixture seed */ - Word16 min_alpha_fx; /*Q15*/ /* Stationary noise UV modification - minimum alpha */ - Word16 exc_pe_fx; /* Stationary noise UV modification - memory of the preemphasis filter */ - - Word16 last_L_frame_fx; /* ACELP@16kHz - last L_frame value */ - Word16 mem_decim16k_fx[2*L_FILT_MAX]; /* ACELP@16kHz - decimation filter memory @16kHz */ - Word16 mem_preemph16k_fx; /* ACELP@16kHz - preemphasis filter memory @16kHz */ - Word16 old_inp_16k_fx[L_INP_MEM]; /* ACELP@16kHz - memory of input signal @16 kHz */ - Word16 mem_deemp_preQ_fx; /* ACELP@16kHz - prequantizer deemhasis memory */ - Word16 mem_preemp_preQ_fx; /* ACELP@16kHz - prequantizer preemhasis memory */ - Word16 last_nq_preQ_fx; /* ACELP@16kHz - AVQ subquantizer number of the last sub-band of the last subframe */ - Word16 use_acelp_preq; /* ACELP@16kHz - flag of prequantizer usage */ - - Word16 bpf_off_fx; - Word16 old_pitch_buf_fx[2*NB_SUBFR16k]; /*Q6 Bass post-filter - buffer of old subframe pitch values */ - - Word16 lps_fx; - Word16 lpm_fx; - - /* stable short pitch detection */ - Word16 voicing0_sm_fx; - Word16 voicing_sm_fx; - Word16 LF_EnergyRatio_sm_fx; - Word16 predecision_flag_fx; - Word32 diff_sm_fx; - Word32 energy_sm_fx; - - Word16 last_ener_fx; /* AC mode (GSC) - previous energy */ - - /*----------------------------------------------------------------------------------* - * HF WB BWE for AMR-WB IO mode at 23.85 kbps - *----------------------------------------------------------------------------------*/ - - Word16 gain_alpha_fx; - Word16 mem_hf2_enc_fx[L_FIR-1]; - Word16 mem_hp400_enc_fx[6]; - Word16 mem_hf_enc_fx[L_FIR-1]; - Word16 mem_syn_hf_enc_fx[M]; - Word16 seed2_enc_fx; - - /*----------------------------------------------------------------------------------* - * CLDFB analysis - *----------------------------------------------------------------------------------*/ - HANDLE_CLDFB_FILTER_BANK cldfbAna_Fx; - - HANDLE_CLDFB_FILTER_BANK cldfbSyn_Fx; - - /*----------------------------------------------------------------------------------* - * FD CNG handle - *----------------------------------------------------------------------------------*/ - HANDLE_FD_CNG_ENC hFdCngEnc_fx; - Word16 fd_cng_reset_flag; - Word16 last_totalNoise_fx; - Word16 totalNoise_increase_hist_fx[TOTALNOISE_HIST_SIZE]; - Word16 totalNoise_increase_len_fx; - /*----------------------------------------------------------------------------------* - * SC-VBR parameters - *----------------------------------------------------------------------------------*/ - - Word16 vadsnr_fx; /*Q7*/ - Word16 vadnoise_fx; - - /* NELP variables */ - Word16 shape1_filt_mem_fx[10]; - Word16 shape2_filt_mem_fx[10]; - Word16 shape3_filt_mem_fx[10]; - Word16 txlpf1_filt1_mem_fx[10]; - Word16 txlpf1_filt2_mem_fx[10]; - Word16 txhpf1_filt1_mem_fx[10]; - Word16 txhpf1_filt2_mem_fx[10]; - Word16 bp1_filt_mem_wb_fx[8]; - Word32 bp1_filt_mem_nb_fx[14]; - Word16 nelp_lp_fit_mem[NELP_LP_ORDER*2]; - Word16 nelp_enc_seed_fx; - Word16 nelp_gain_mem_fx; - Word16 last_nelp_mode_fx; - Word16 nelp_mode_fx; - Word16 qprevIn_fx; - Word16 qprevGain_fx; - - /* PPP variables */ - Word16 pppcountE_fx; - Word16 bump_up_fx; /*Q0*/ - Word16 last_ppp_mode_fx; /*Q0*/ - Word16 ppp_mode_fx; - Word16 prev_ppp_gain_pit_fx; /*Q14*/ - Word16 prev_tilt_code_fx; - - /* voiced encoder variables */ - Word16 firstTime_voicedenc_fx; /*Q0*/ - - /* DTFS variables */ - Word16 dtfs_enc_a_fx[MAXLAG_WI]; /*Q0*/ - Word16 dtfs_enc_b_fx[MAXLAG_WI]; /*Q0*/ - Word16 dtfs_enc_lag_fx; - Word16 dtfs_enc_nH_fx; - Word16 dtfs_enc_nH_4kHz_fx; - Word16 dtfs_enc_upper_cut_off_freq_of_interest_fx; - Word16 dtfs_enc_upper_cut_off_freq_fx; - Word16 dtfs_enc_Q; - - Word32 prev_cw_en_fx; /*Q_prev_cw_en_fx*/ - Word16 ph_offset_E_fx; /*Q15 normalized y 2*Pi */ - Word16 lastLgainE_fx; /*Q11 Previous gain value for the low band */ - Word16 lastHgainE_fx; /*Q11 Previous gain value for the high band */ - Word16 lasterbE_fx[NUM_ERB_WB]; /*Q13 Previous Amplitude spectrum (ERB) */ - Word16 Q_prev_cw_en_fx; - - Word16 mode_QQF_fx; - Word16 rate_control_fx; - Word16 SNR_THLD_fx; - Word16 Q_to_F_fx; - Word16 pattern_m_fx; - Word16 patterncount_fx; - Word16 Last_Resort_fx; - Word16 numactive_fx; /* keep the count of the frames inside current 600 frame bloack.*/ - Word32 sum_of_rates_fx; /* sum of the rates of past 600 active frames*/ - Word32 global_avr_rate_fx; /* global rate upto current time. recorded a (rate in kbps) *6000*/ - Word16 frame_cnt_ratewin_fx; /* keep count of how many ratewin (600) windows */ - - Word16 set_ppp_generic_fx; - Word16 avoid_HQ_VBR_NB; - - /*----------------------------------------------------------------------------------* - * HQ core parameters - *----------------------------------------------------------------------------------*/ - Word16 input_buff[L_FRAME48k+L_FRAME48k+NS2SA(48000, DELAY_FIR_RESAMPL_NS)]; - Word16 * input; - Word16 * old_input_signal_fx; - Word16 Q_old_wtda; - Word16 old_hpfilt_in_fx; - Word16 old_hpfilt_out_fx; - Word32 EnergyLT_fx; - Word32 Energy_Old_fx; - Word16 TransientHangOver_fx; - Word16 old_out_fx[L_FRAME32k]; /* buffer for OLA; at the encoder, the maximum length is L_FRAME32k (corresponds to maximum internal L_frame length) */ - Word16 Q_old_out; - Word16 last_core_fx; - Word16 hq_generic_speech_class_fx; - Word16 mode_count_fx; /* HQ_HARMONIC mode count */ - Word16 mode_count1_fx; /* HQ_NORMAL mode count */ - Word16 Nb_ACELP_frames_fx; - Word16 prev_Npeaks_fx; /* number of peaks in previous frame */ - Word16 prev_peaks_fx[HVQ_MAX_PEAKS]; /* indices of the peaks in previous frame */ - Word16 hvq_hangover_fx; - Word16 prev_hqswb_clas_fx; - Word16 prev_SWB_peak_pos_fx[SPT_SHORTEN_SBNUM]; - - - Word16 lt_old_mode[3]; - Word16 lt_voicing; - Word16 lt_corr; - Word32 lt_tonality; - Word16 lt_corr_pitch[3]; - Word16 lt_hangover; - Word16 lowrate_pitchGain; - - Word16 prev_frm_index_fx[NB_SWB_SUBBANDS_HAR_SEARCH_SB]; - Word16 prev_frm_hfe2_fx; - Word16 prev_stab_hfe2_fx; - Word16 prev_ni_ratio_fx; /* 15 */ - Word16 prev_En_sb_fx[NB_SWB_SUBBANDS]; /* QsEn(4) */ - - Word16 last_bitalloc_max_band_fx[2]; - Word32 last_ni_gain_fx[BANDS_MAX]; - Word16 last_env_fx[BANDS_MAX]; - Word16 last_max_pos_pulse_fx; - - /* PVQ range coder state */ - UWord32 rc_low_fx; - UWord32 rc_range_fx; - Word16 rc_cache_fx; - Word16 rc_carry_fx; - Word16 rc_carry_count_fx; - Word16 rc_num_bits_fx; - Word16 rc_tot_bits_fx; - Word16 rc_offset_fx; - /*----------------------------------------------------------------------------------* - * TBE parameters - *----------------------------------------------------------------------------------*/ - - Word16 old_speech_shb_fx[L_LOOK_16k + L_SUBFR16k]; /* Buffer memories */ - Word16 old_speech_wb_fx[(L_LOOK_12k8 + L_SUBFR) * 5/16]; /* Buffer memories */ - Word16 old_input_fhb_fx[NS2SA(48000, ACELP_LOOK_NS + DELAY_FD_BWE_ENC_12k8_NS + DELAY_FIR_RESAMPL_NS) - L_FRAME48k/2]; - Word16 old_input_fhb_fx_Q; - - Word16 state_ana_filt_shb_fx[ (2*ALLPASSSECTIONS_STEEP+1) ]; - Word16 cldfbHBLT; - /* states for the filters used in generating SHB excitation from WB excitation*/ - Word32 mem_csfilt_fx[2]; - - /* states for the filters used in generating SHB signal from SHB excitation*/ - Word16 state_syn_shbexc_fx[L_SHB_LAHEAD]; - Word16 state_lpc_syn_fx[LPC_SHB_ORDER]; - Word16 old_bwe_exc_fx[PIT16k_MAX * 2]; /*Q_exc*/ - Word16 bwe_seed_fx[2]; - Word32 bwe_non_lin_prev_scale_fx; /*Q30*/ - Word16 old_bwe_exc_extended_fx[NL_BUFF_OFFSET]; - Word16 syn_overlap_fx[L_SHB_LAHEAD]; - Word16 decim_state1_fx[(2*ALLPASSSECTIONS_STEEP+1)]; - Word16 decim_state2_fx[(2*ALLPASSSECTIONS_STEEP+1)]; - Word16 mem_genSHBexc_filt_down_wb2_fx[(2*ALLPASSSECTIONS_STEEP+1)]; - Word16 mem_genSHBexc_filt_down_wb3_fx[(2*ALLPASSSECTIONS_STEEP+1)]; - Word16 mem_genSHBexc_filt_down_shb_fx[(2*ALLPASSSECTIONS_STEEP+1)]; - Word32 elliptic_bpf_2_48k_mem_fx[4][4]; - Word16 elliptic_bpf_2_48k_mem_fx_Q[4]; - Word32 prev_fb_energy_fx; - Word16 prev_fb_energy_fx_Q; - Word32 prev_gainFr_SHB_fx; - Word16 lsp_shb_slow_interpl_fx[LPC_SHB_ORDER]; - Word16 lsp_shb_fast_interpl_fx[LPC_SHB_ORDER]; - Word16 shb_inv_filt_mem_fx[LPC_SHB_ORDER]; - Word16 lsp_shb_spacing_fx[3]; - Word16 prev_swb_GainShape_fx; - Word16 prev_frGainAtten_fx; - - Word16 spectral_tilt_reset_fx; - Word16 consec_inactive_fx; - Word16 ra_deltasum_fx; - Word16 trigger_SID_fx; - Word16 running_avg_fx; /*Q15 */ - Word32 L_snr_sum_vad_fx; /*Q4*/ - Word16 prev_wb_GainShape; - Word16 swb_lsp_prev_interp_fx[LPC_SHB_ORDER]; - Word16 fb_state_lpc_syn_fx[LPC_SHB_ORDER]; - Word16 prev_Q_bwe_exc_fb; - Word16 fb_tbe_demph_fx; - Word16 tilt_mem_fx; - - Word16 prev_coder_type_fx; - Word16 prev_lsf_diff_fx[LPC_SHB_ORDER-2]; - Word16 prev_tilt_para_fx; - Word16 cur_sub_Aq_fx[M+1]; - - /* quantized data */ - Word16 lsf_idx_fx[NUM_Q_LSF]; - Word16 m_idx_fx; - Word16 grid_idx_fx; - Word16 idxSubGains_fx; - Word16 idxFrameGain_fx; - Word16 idx_shb_fr_gain_fx; - Word16 idx_res_gs_fx[NB_SUBFR16k]; - Word16 idx_mixFac_fx; - - Word16 lsf_WB_fx; - Word16 gFrame_WB_fx; - - Word16 idxGain_fx; - Word16 dec_2_over_3_mem_fx[12]; - Word16 dec_2_over_3_mem_lp_fx[6]; - /*----------------------------------------------------------------------------------* - * SWB BWE parameters - *----------------------------------------------------------------------------------*/ - - Word16 new_input_hp_fx[NS2SA(16000, ACELP_LOOK_NS + DELAY_FD_BWE_ENC_NS + DELAY_FIR_RESAMPL_NS - DELAY_CLDFB_NS)]; - Word16 old_input_fx[NS2SA(48000, DELAY_FD_BWE_ENC_NS + DELAY_FIR_RESAMPL_NS)]; - Word16 old_input_wb_fx[NS2SA(16000, DELAY_FD_BWE_ENC_NS)]; - Word16 old_input_lp_fx[NS2SA(16000, ACELP_LOOK_NS + DELAY_FD_BWE_ENC_NS)]; - Word16 old_syn_12k8_16k_fx[NS2SA(16000, DELAY_FD_BWE_ENC_NS)]; - Word16 old_fdbwe_speech_fx[L_FRAME48k]; - Word16 mem_deemph_old_syn_fx; - Word16 prev_mode_fx; - Word16 L_old_wtda_swb_fx[L_FRAME48k]; - Word16 prev_Q_input_lp; - Word16 prev_L_swb_norm1_fx; - Word32 prev_global_gain_fx; - Word16 modeCount_fx; - Word32 EnergyLF_fx; - Word16 tbe_demph_fx; - Word16 tbe_premph_fx; - Word16 mem_stp_swb_fx[LPC_SHB_ORDER]; - Word16 *ptr_mem_stp_swb_fx; - Word16 gain_prec_swb_fx; - Word16 mem_zero_swb_fx[LPC_SHB_ORDER]; - - /*----------------------------------------------------------------------------------* - * WB, SWB and FB bandwidth detector - *----------------------------------------------------------------------------------*/ - - Word16 lt_mean_NB_fx; - Word16 lt_mean_WB_fx; - Word16 lt_mean_SWB_fx; - Word16 count_WB_fx; - Word16 count_SWB_fx; - Word16 count_FB_fx; - - /*----------------------------------------------------------------------------------* - * SWB DTX/CNG parameters - *----------------------------------------------------------------------------------*/ - - Word16 last_vad_fx; - Word16 last_wb_cng_ener_fx; - Word16 last_shb_cng_ener_fx; - Word16 mov_wb_cng_ener_fx; - Word16 mov_shb_cng_ener_fx; - Word16 shb_cng_ini_cnt_fx; - Word16 last_SID_bwidth_fx; - Word16 shb_NO_DATA_cnt_fx; - - /*----------------------------------------------------------------------------------* - * Channel-aware mode - *----------------------------------------------------------------------------------*/ - - - Word16 rf_mode; - Word16 rf_mode_last; - Word16 Opt_RF_ON; - Word16 rf_frame_type; - - Word16 rf_target_bits_write; - Word16 rf_fec_offset; - Word16 rf_fec_indicator; - - Word16 rf_targetbits_buff[MAX_RF_FEC_OFFSET]; - Word16 rf_indx_frametype[MAX_RF_FEC_OFFSET]; - - Word16 rf_mem_w0; - Word16 rf_clip_var[6]; - Word16 rf_tilt_code; - Word16 rf_mem_syn2[M]; - struct dispMem_fx rf_dm_fx; - Word32 rf_gc_threshold; - - Word16 rf_target_bits; - Word16 rf_tilt_buf[NB_SUBFR16k]; - - Word16 rf_indx_lsf[MAX_RF_FEC_OFFSET][3]; - Word16 rf_indx_pitch[MAX_RF_FEC_OFFSET][NB_SUBFR16k]; - Word16 rf_indx_fcb[MAX_RF_FEC_OFFSET][NB_SUBFR16k]; - Word16 rf_indx_gain[MAX_RF_FEC_OFFSET][NB_SUBFR16k]; - Word16 rf_indx_EsPred[MAX_RF_FEC_OFFSET]; - Word16 rf_indx_ltfMode[MAX_RF_FEC_OFFSET][NB_SUBFR16k]; - - Word16 rf_indx_nelp_fid[MAX_RF_FEC_OFFSET]; - Word16 rf_indx_nelp_iG1[MAX_RF_FEC_OFFSET]; - Word16 rf_indx_nelp_iG2[MAX_RF_FEC_OFFSET][2]; - - Word16 rf_indx_tbeGainFr[MAX_RF_FEC_OFFSET]; - - Word16 rf_tcxltp_pitch_int_past; - Word16 rf_last_tns_active; - Word16 rf_second_last_tns_active; - Word16 rf_second_last_core; - Word16 rf_clas[MAX_RF_FEC_OFFSET]; - Word16 rf_gain_tcx[MAX_RF_FEC_OFFSET]; - Word16 rf_tcxltp_param[MAX_RF_FEC_OFFSET]; - - Word16 rf_bwe_gainFr_ind; - - - - /*----------------------------------------------------------------------------------* - * Fixed point only variables - *----------------------------------------------------------------------------------*/ - - Word16 prev_Q_bwe_exc; - Word16 prev_Q_bwe_syn; - Word16 Q_stat_noise_ge; - Word16 Q_stat_noise; - Word16 Q_syn2; - Word16 Q_syn; - Word16 Q_max[L_Q_MEM]; - Word16 Q_max_16k[L_Q_MEM]; - Word16 Q_old; - Word16 prev_Q_old; - Word16 old_wsp_max; /* Last weigthed speech maximal value */ - Word16 old_wsp_shift; /* Last wsp scaling */ - Word16 prev_Q_new; - Word16 prev_Q_shb; - - /*----------------------------------------------------------------------------------* - * - *----------------------------------------------------------------------------------*/ - - Word16 EnergyLT_fx_exp; - Word16 prev_lsp_shb_fx[LPC_SHB_ORDER]; - Word16 prev_lsp_wb_fx[LPC_SHB_ORDER_WB]; - Word16 prev_lpc_wb_fx[LPC_SHB_ORDER_WB]; - Word16 last_last_ppp_mode_fx; - Word16 prev_lsp_wb_temp_fx[LPC_SHB_ORDER_WB]; - - Word16 frame_size_index; /* 0-FRAME_SIZE_NB-1: index determining the frame size */ - Word16 bits_frame_nominal; /* avg bits per frame on active frame */ - Word16 bits_frame; /* total bits per frame */ - Word16 bits_frame_core; /* bits per frame for the core */ - Word8 narrowBand; - - /*ACELP config*/ - ACELP_config acelp_cfg; /* configuration set for each frame */ - - ACELP_config acelp_cfg_rf; /* configuration for RF frame */ - - Word16 mode_index; /* Mode Index for LPD core */ - - /*TCX config*/ - TCX_config tcx_cfg; - Word16 L_frameTCX; - - /* cod_main.c */ - Word16 mem_preemph_enc; /* speech preemph filter memory (at encoder-sampling-rate) */ - - Word16 *speech_TCX; - Word16 *new_speech_TCX; - - Word16 *speech_enc; - Word16 *speech_enc_pe; - Word16 *new_speech_enc; - Word16 *new_speech_enc_pe; - Word16 buf_speech_enc[L_PAST_MAX_32k+L_FRAME32k+L_NEXT_MAX_32k]; - Word16 buf_speech_enc_pe[L_PAST_MAX_32k+L_FRAME32k+L_NEXT_MAX_32k]; - Word16 *wspeech_enc; - Word16 buf_wspeech_enc[L_FRAME16k+L_SUBFR+L_FRAME16k+L_NEXT_MAX_16k]; /*normally there is a lookahead for 12k8 and 16k but L_FRAME_MAX=L_FRAME_16K+L_NEXT_16k*/ - Word16 *synth; - Word16 buf_synth[OLD_SYNTH_SIZE_ENC+L_FRAME32k]; - - /* Core Signal Analysis Outputs */ - Word16 noiseTiltFactor; /* compensation for LPC tilt in noise filling */ - Word16 noiseLevelMemory; /* counter of consecutive low TCX noise levels */ - STnsData tnsData[2]; - Word8 fUseTns[2]; - - Word8 enableTcxLpc; /* global toggle for the TCX LPC quantizer */ - Word16 envWeighted; /* are is{p,f}_old_q[] weighted or not? */ - - Word8 acelpEnabled; /* Flag indicating if ACELP can be used */ - Word8 tcx10Enabled; /* Flag indicating if TCX 10 can be used */ - Word8 tcx20Enabled; /* Flag indicating if TCX 20 can be used */ - - Word16 tcxMode; /* Chosen TCX mode for this frame */ - - LPD_state LPDmem; - - Word16 mem_wsp_enc; /* wsp vector memory */ - - Word16 nb_bits_header_ace; /* number of bits for the header */ - Word16 nb_bits_header_tcx; /* number of bits for the header */ - - /*Added by fcs : restrict the possible in EVS: 0 base 10 = d.c.b.a base 2*/ - /* a = 0/1 : ACELP on/off*/ - /* b = 0/1 : TCX20 on/off*/ - /* c = 0/1 : TCX40 on/off*/ - /* d = 0/1 : TCX80 on/off*/ - Word8 restrictedMode; - - /* Framing */ - Word16 nb_subfr; - - Word16 preemph_fac; /*Preemphasis factor*/ - - Word16 gamma; - Word16 inv_gamma; - - TransientDetection transientDetection; - Word16 transient_info[3]; - - Word16 acelpFramesCount; /* Acelp frame counter. Counts upto 50 only !!! */ - - Word16 prevTempFlatness_fx; /* exponent is AVG_FLAT_E */ - - Word32 prevEnergyHF_fx; - Word32 currEnergyHF_fx; - Word16 currEnergyHF_e_fx; /* exponent of currEnergyHF and prevEnergyHF */ - Word32 energyCoreLookahead_Fx; - Word16 sf_energyCoreLookahead_Fx; - - /* lsf quantizer*/ - Word16 parcorr[2]; - Word16 parcorr_mid[2]; - - Word16 lpcQuantization; - Word16 numlpc; - Word16 encoderLookahead_enc; - Word16 encoderPastSamples_enc; - Word16 encoderLookahead_FB; - - /* pitch_ol for adaptive lag window */ - Word16 old_pitch_la; /* past open loop pitch lag from look-ahead */ - Word16 old_voicing_la; /* past open loop pitch gain from look-ahead */ - - Word32 band_energies[2*NB_BANDS]; /* energy in critical bands without minimum noise floor MODE2_E_MIN */ - Word16 band_energies_exp; /* exponent for energy in critical bands without minimum noise floor MODE2_E_MIN */ - - Word8 tcxonly; - - Word16 Q_max_enc[2]; - - Word16 finalVAD; - Word8 flag_noisy_speech_snr; /*encoder detector for noisy speech*/ - - Word16 fscale; - Word32 sr_core; - Word32 last_sr_core; - Word8 acelp_autocorr; /* Optimize acelp in 0 covariance or 1 correlation domain */ - - Word16 pit_min; - Word16 pit_fr1; - Word16 pit_fr1b; - Word16 pit_fr2; - Word16 pit_max; - Word16 pit_res_max; /* goes from 1 upto 6 (see core_enc_init.c: init_acelp()) */ - - /* for FAC */ - Word16 L_frame_past; - Word8 memQuantZeros[L_FRAME_PLUS]; - - /*Adaptive BPF*/ - Word16 bpf_gain_param; - Word16 bpf_T[NB_SUBFR16k]; - Word16 bpf_gainT[NB_SUBFR16k]; - - struct MEM_BPF mem_bpf; - - /* TCX-LTP */ - Word8 tcxltp; - Word16 tcxltp_pitch_int; - Word16 tcxltp_pitch_fr; - Word16 tcxltp_gain; - Word16 tcxltp_pitch_int_past; - Word16 tcxltp_pitch_fr_past; - Word16 tcxltp_gain_past; - Word16 tcxltp_norm_corr_past; - Word16 buf_speech_ltp[L_PAST_MAX_32k+L_FRAME32k+L_NEXT_MAX_32k]; - Word16 *speech_ltp; - Word16 *new_speech_ltp; - Word16 tcxltp_bits; - Word16 tcxltp_param[LTPSIZE]; - - Word16 measuredBwRatio; /* measured bw; used for TCX noise-filling. 1Q14 */ - Word16 nmStartLine; /* Starting line for the noise measurement. Q0 */ - - Word8 glr; - Word16 glr_idx[2]; - Word32 gain_code[NB_SUBFR16k]; - Word32 mean_gc[2]; - Word16 prev_lsf4_mean; - Word16 last_stab_fac; - Word8 glr_reset; - - /*for rate switching*/ - Word16 rate_switching_reset; /*Rate switching flag requiring a reset of memories at least partially */ - Word16 rate_switching_reset_16kHz; - - Word16 enablePlcWaveadjust; - Word16 Tonal_SideInfo; - IGF_ENC_INSTANCE hIGFEnc; - Word16 igf; - - Word16 seed_acelp; - - Word16 tcx_lpc_shaped_ari; - - PLC_ENC_EVS plcExt; - - Word16 tec_tfa; - TEMPORAL_ENVELOPE_CODING_ENCODER_FX tecEnc; - Word16 tec_flag; - Word16 tfa_flag; - Word32 tfa_enr[N_TEC_TFA_SUBFR]; - - Word16 nTimeSlots; /* for CLDFB */ - - T_CldfbVadState vad_st; - - Word16 vbr_generic_ho_fx; - Word16 last_7k2_coder_type_fx; - - Word16 sharpFlag; - - Word16 Local_VAD; - -} Encoder_State_fx; - -/* Structure for storing correlations between ACELP codebook components and target */ -typedef struct -{ - Word16 xx; /* energy of target x */ - Word16 y1y1; /* energy of adaptive cbk contribution y1 */ - Word16 y2y2; /* energy of fixed cbk contribution y2 */ - Word16 xy1; /* correlation of x and y1 */ - Word16 xy2; /* correlation of x and y2 */ - Word16 y1y2; /* correlation of y1 and y2 */ - - Word16 xx_e; /* energy of target x */ - Word16 y1y1_e; /* energy of adaptive cbk contribution y1 */ - Word16 y2y2_e; /* energy of fixed cbk contribution y2 */ - Word16 xy1_e; /* correlation of x and y1 */ - Word16 xy2_e; /* correlation of x and y2 */ - Word16 y1y2_e; /* correlation of y1 and y2 */ -} ACELP_CbkCorr; - -#endif diff --git a/src/libs/libevs/lib_enc/stat_noise_uv_enc.cpp b/src/libs/libevs/lib_enc/stat_noise_uv_enc.cpp new file mode 100644 index 00000000..b531ec2e --- /dev/null +++ b/src/libs/libevs/lib_enc/stat_noise_uv_enc.cpp @@ -0,0 +1,71 @@ +/*==================================================================================== + EVS Codec 3GPP TS26.443 Nov 13, 2018. Version 12.11.0 / 13.7.0 / 14.3.0 / 15.1.0 + ====================================================================================*/ + +#include "options.h" +#include "prot.h" +#include "rom_com.h" + +/*-----------------------------------------------------------------* + * stat_noise_uv_enc() + * + * Modifies excitation signal when the noise is stationary + *-----------------------------------------------------------------*/ + +void stat_noise_uv_enc( + Encoder_State *st, /* i/o: state structure */ + const short coder_type, /* i : coding type */ + const float *epsP, /* i : LP prediction errors */ + float *isp_new, /* i : immittance spectral pairs at 4th sfr */ + float *isp_mid, /* i : immittance spectral pairs at 2nd sfr */ + float *Aq, /* i : A(z) quantized for the 4 subframes */ + float *exc2 /* i/o: excitation buffer */ +) +{ + short noisiness = 0; + + /*-----------------------------------------------------------------* + * Calculate and write the noisiness parameter + *-----------------------------------------------------------------*/ + + if ( coder_type == UNVOICED || ( coder_type == INACTIVE && st->core_brate <= ACELP_9k60 ) ) + { + if ( st->bwidth != NB ) + { + /* WB case */ + noisiness = (short)(((epsP[2] / epsP[16]) - 1) * 2.0f * 32); + } + else if ( coder_type == INACTIVE && st->bwidth == NB ) + { + /* NB GSC case */ + noisiness = (short)(((epsP[2] / epsP[16]) - 1) * 0.25f * 32); + } + else + { + /* NB case */ + noisiness = (short)(((epsP[2] / epsP[16]) - 1) * 0.5f * 32); + } + + if( noisiness < 0 ) + { + noisiness = 0; + } + + if( noisiness > 31 ) + { + noisiness = 31; + } + + push_indice( st, IND_NOISINESS, noisiness, 5 ); + } + + /*-----------------------------------------------------------------* + * Modify the stationary noise excitation signal + *-----------------------------------------------------------------*/ + + stat_noise_uv_mod( coder_type, noisiness, st->lsp_old, isp_new, isp_mid, Aq, exc2, 0, &st->ge_sm, + &st->uv_count, &st->act_count, st->lspold_s, &st->noimix_seed, &st->min_alpha, &st->exc_pe, + st->core_brate, st->bwidth ); + + return; +} diff --git a/src/libs/libevs/lib_enc/stat_noise_uv_enc_fx.cpp b/src/libs/libevs/lib_enc/stat_noise_uv_enc_fx.cpp deleted file mode 100755 index df0a7132..00000000 --- a/src/libs/libevs/lib_enc/stat_noise_uv_enc_fx.cpp +++ /dev/null @@ -1,103 +0,0 @@ -/*==================================================================================== - EVS Codec 3GPP TS26.442 Apr 03, 2018. Version 12.11.0 / 13.6.0 / 14.2.0 - ====================================================================================*/ - -#include "options.h" /* Compilation switches */ -#include "prot_fx.h" /* Function prototypes */ -#include "rom_com_fx.h" /* Static table prototypes */ -#include "stl.h" - -/*======================================================================*/ -/* FUNCTION : stat_noise_uv_enc_fx */ -/*----------------------------------------------------------------------*/ -/* PURPOSE : Modifies excitation signal in UC mode */ -/* when the noise is stationary */ -/*----------------------------------------------------------------------*/ -/* INPUT ARGUMENTS : */ -/* _ (Encoder_State_fx) st_fx : Encoder state Structure */ -/* _ (Word16) coder_type : coding type */ -/* _ (Word16*) epsP : LP prediction errors */ -/* _ (Word16*) isp_new : immittance spectral pairs at 4th sfr Q15 */ -/* _ (Word16*) isp_mid : immittance spectral pairs at 2nd sfr Q15 */ -/* _ (Word16*) Aq : A(z) quantized for the 4 subframes Q12 */ -/*-----------------------------------------------------------------------*/ -/* INPUT/OUTPUT ARGUMENTS : */ -/* _ (Word16*) exc2 : excitation buffer Q_exc */ -/*-----------------------------------------------------------------------*/ -/* OUTPUT ARGUMENTS : */ -/*-----------------------------------------------------------------------*/ - -/* _ None */ -/*-----------------------------------------------------------------------*/ -/* RETURN ARGUMENTS : */ -/* _ None */ -/*=======================================================================*/ -void stat_noise_uv_enc_fx( - Encoder_State_fx *st_fx, /* i/o: state structure */ - const Word16 coder_type, /* i : coding type */ - const Word32 *LepsP, /* i : LP prediction errors */ - Word16 *isp_new, /* i : immittance spectral pairs at 4th sfr */ - Word16 *isp_mid, /* i : immittance spectral pairs at 2nd sfr */ - Word16 *Aq, /* i : A(z) quantized for the 4 subframes */ - Word16 *exc2, /* i/o: excitation buffer */ - Word16 Q_new -) -{ - Word16 noisiness = 0; - Word16 num,den,expn,expd; - - test(); - test(); - IF ( sub(coder_type,UNVOICED) == 0 || ( sub(coder_type,INACTIVE) == 0 && L_sub(st_fx->core_brate_fx,ACELP_9k60) <= 0 ) ) - { - - /*-----------------------------------------------------------------* - * Calculate and write the noisiness parameter - *-----------------------------------------------------------------*/ - /* epsP[2] is located in LepsP[0] and epsP[16] in LepsP[1] */ - expn = sub(norm_l(LepsP[0]),1); - num = extract_h(L_shl(LepsP[0],expn));/*expn-16*/ - expd = norm_l(LepsP[1]); - den = extract_h(L_shl(LepsP[1],expd));/*expd-16*/ - - num = div_s(num,den);/*expn-expd+15*/ - num = shr(num,add(sub(expn,expd),5));/*Q10*/ - num = sub(num,1024);/*num - 1*/ - - test(); - IF ( sub(st_fx->bwidth_fx,NB) != 0 ) - { - /* WB case */ - /* noisiness = (Word16)(((epsP[2] / epsP[16]) - 1)*2 * 32);*/ - noisiness = shr(num,4);/*Q10 x64 -> Q0 */ - } - ELSE IF ( sub(coder_type,INACTIVE) == 0 && sub(st_fx->bwidth_fx,NB) == 0) - { - /* NB GSC case */ - /* noisiness = (Word16)(((epsP[2] / epsP[16]) - 1)*.25f * 32);*/ - noisiness = shr(num,4+3);/*Q10 x8 -> Q0 */ - } - ELSE - { - /* NB case */ - noisiness = shr(num,4+2);/*Q16 x16 -> Q0 */ - } - - noisiness = s_max(noisiness, 0); - noisiness = s_min(noisiness, 31); - - push_indice_fx( st_fx, IND_NOISINESS, noisiness, 5 ); - } - - /*-----------------------------------------------------------------* - * Modify the stationary noise excitation signal - *-----------------------------------------------------------------*/ - - stat_noise_uv_mod_fx( coder_type, noisiness, st_fx->lsp_old_fx, isp_new, isp_mid, Aq - ,exc2, Q_new, 0, &st_fx->ge_sm_fx, &st_fx->uv_count_fx, &st_fx->act_count_fx, - st_fx->lspold_s_fx, &st_fx->noimix_seed_fx, &st_fx->min_alpha_fx, &st_fx->exc_pe_fx, - st_fx->core_brate_fx, st_fx->bwidth_fx, &st_fx->Q_stat_noise, &st_fx->Q_stat_noise_ge ); - - - return; -} diff --git a/src/libs/libevs/lib_enc/subband_fft.cpp b/src/libs/libevs/lib_enc/subband_fft.cpp old mode 100755 new mode 100644 index 79ef453b..d119d46c --- a/src/libs/libevs/lib_enc/subband_fft.cpp +++ b/src/libs/libevs/lib_enc/subband_fft.cpp @@ -1,346 +1,186 @@ /*==================================================================================== - EVS Codec 3GPP TS26.442 Apr 03, 2018. Version 12.11.0 / 13.6.0 / 14.2.0 + EVS Codec 3GPP TS26.443 Nov 13, 2018. Version 12.11.0 / 13.7.0 / 14.3.0 / 15.1.0 ====================================================================================*/ +#include +#include "prot.h" +#include "rom_enc.h" -#include "basop_util.h" -#include "stl.h" -#include "vad_basop.h" -#include "prot_fx.h" -#include "rom_enc_fx.h" -#define RE(A) A.r -#define IM(A) A.i -typedef struct + +/*-------------------------------------------------------------------* + * fft16() + * + * + *-------------------------------------------------------------------*/ + +static void fft16(float *r_samp, float *i_samp) { - complex_16 work[32]; - complex_16 const* tab; -} cfft_info_16; + int i,j,N,Nv2,nm1,k; + float tmpr[16],tmpi[16]; + float r1,s1,r2,s2; -static void ComplexMult_16(Word16 *y1, Word16 *y2, Word16 x1, Word16 x2, Word16 c1, Word16 c2) -{ - *y1 = add(mult(x1, c1) , mult(x2, c2)); - move16(); - *y2 = sub(mult(x2, c1) , mult(x1, c2)); - move16(); + + for (i = 0; i < 16; i++) + { + tmpr[i] = r_samp[i]*M_inr[i] - i_samp[i]*M_ini[i]; + tmpi[i] = r_samp[i]*M_ini[i] + i_samp[i]*M_inr[i]; + } + + for (i = 0; i < 8; i++) + { + s1 = tmpr[i] - tmpr[8+i]; + r1 = tmpi[i] - tmpi[8+i]; + + tmpr[i] = tmpr[i] + tmpr[8+i]; + tmpi[i] = tmpi[i] + tmpi[8+i]; + + tmpr[i+8] = s1*M_r[i] - r1*M_i[i]; + tmpi[i+8] = s1*M_i[i] + r1*M_r[i]; + } + + for (i = 0; i < 4; i++) + { + s1 = tmpr[i] - tmpr[4+i]; + r1 = tmpi[i] - tmpi[4+i]; + + tmpr[i] = tmpr[i] + tmpr[4+i]; + tmpi[i] = tmpi[i] + tmpi[4+i]; + + tmpr[i+4] = s1*M_r[2*i] - r1*M_i[2*i]; + tmpi[i+4] = s1*M_i[2*i] + r1*M_r[2*i]; + + } + for (i = 0; i < 4; i++) + { + s1 = tmpr[i+8] - tmpr[12+i]; + r1 = tmpi[i+8] - tmpi[12+i]; + + tmpr[i+8] = tmpr[i+8] + tmpr[12+i]; + tmpi[i+8] = tmpi[i+8] + tmpi[12+i]; + + tmpr[i+12] = s1*M_r[2*i] - r1*M_i[2*i]; + tmpi[i+12] = s1*M_i[2*i] + r1*M_r[2*i]; + + } + + + for (i = 0; i< 16; i=i+4) + { + s1 = tmpr[i] - tmpr[2+i]; + r1 = tmpi[i] - tmpi[2+i]; + s2 = tmpr[i+1] - tmpr[3+i]; + r2 = tmpi[i+1] - tmpi[3+i]; + + tmpr[i] = tmpr[i] + tmpr[2+i]; + tmpi[i] = tmpi[i] + tmpi[2+i]; + tmpr[i+1] = tmpr[i+1] + tmpr[3+i]; + tmpi[i+1] = tmpi[i+1] + tmpi[3+i]; + + tmpr[i+2] = s1*M_r[0] - r1*M_i[0]; + tmpi[i+2] = s1*M_i[0] + r1*M_r[0]; + tmpr[i+3] = s2*M_r[4] - r2*M_i[4]; + tmpi[i+3] = s2*M_i[4] + r2*M_r[4]; + } + + for (i = 0; i < 16; i= i+2) + { + s1 = tmpr[i] - tmpr[1+i]; + r1 = tmpi[i] - tmpi[1+i]; + + tmpr[i] = tmpr[i] + tmpr[1+i]; + tmpi[i] = tmpi[i] + tmpi[1+i]; + + tmpr[i+1] = s1*M_r[0] - r1*M_i[0]; + tmpi[i+1] = s1*M_i[0] + r1*M_r[0]; + } + + + N = 16; + Nv2=N>>1; + nm1=N-1; + j=0; + for(i=0; i>=1; + } + j+=k; + } + + r_samp[15] = tmpr[15]*M_Wr[15] - tmpi[15]*M_Wi[15]; + i_samp[15] = tmpr[15]*M_Wi[15] + tmpi[15]*M_Wr[15]; + + return; } -Word16 ffr_getSfWord32(Word32 *vector, /*!< Pointer to input vector */ - Word16 len) /*!< Length of input vector */ -{ - Word32 maxVal; - Word16 i; - Word16 resu; - - - maxVal = L_add(0,0); - FOR(i=0; i +#include +#include "options.h" +#include "cnst.h" +#include "prot.h" +#include "rom_com.h" +#include "rom_enc.h" +#include "basop_util.h" +#include "basop_proto_func.h" + +/*---------------------------------------------------------------------* + * Local functions + *---------------------------------------------------------------------*/ +static short SWB_BWE_encoding( Encoder_State *st, const float *insig, const float *insig_lp, const float *insig_hp, const float *synth, + const float *yos, float *SWB_fenv, const float tilt_nb, const short st_offset, const short coder_type ); +static void MSVQ_Interpol_Tran( float *SWB_env_energy, short *indice ); +static void calculate_tonality( const float *org, const float *gen, float *SFM_org, float *SFM_gen, const short length ); +static short WB_BWE_encoding( const short coder_type, const float *yos, float *WB_fenv, Encoder_State *st ); +static void energy_control( Encoder_State *st, const short core, const short mode, const short coder_type, const float *org, const short offset, float *energy_factor ); +static short decision_hq_generic_class (const float *coefs, const short hq_generic_offset ); + +/*-------------------------------------------------------------------* + * wb_bwe_enc() + * + * WB BWE encoder + *-------------------------------------------------------------------*/ + +void wb_bwe_enc( + Encoder_State *st, /* i/o: encoder state structure */ + const float *new_wb_speech, /* i : original input signal at 16kHz */ + short coder_type /* i : coding type */ +) +{ + float old_input[NS2SA(16000, DELAY_FD_BWE_ENC_NS + DELAY_FIR_RESAMPL_NS) + L_FRAME16k]; + float *new_input; /* pointer to original input signal */ + float yorig[L_FRAME16k]; /* MDCT spectrum of weighted original */ + short mode = 0; + float wtda_old_input[2*L_FRAME16k]; + float WB_fenv[SWB_FENV]; + short Sample_Delay_WB_BWE; + + if( st->total_brate == ACELP_13k20 ) + { + /*---------------------------------------------------------------------* + * Delay the original input signal to be synchronized with ACELP core synthesis + *---------------------------------------------------------------------*/ + + set_f( old_input, 0, NS2SA(16000, DELAY_FD_BWE_ENC_12k8_NS + DELAY_FIR_RESAMPL_NS) + L_FRAME16k ); + + Sample_Delay_WB_BWE = NS2SA( 16000, DELAY_FD_BWE_ENC_12k8_NS ); + + new_input = old_input + Sample_Delay_WB_BWE; + mvr2r( st->old_input_wb, old_input, Sample_Delay_WB_BWE ); + mvr2r( new_wb_speech, new_input, L_FRAME16k ); + mvr2r( old_input + L_FRAME16k, st->old_input_wb, Sample_Delay_WB_BWE ); + + /*---------------------------------------------------------------------* + * WB BWE encoding + *---------------------------------------------------------------------*/ + + /* MDCT of the original signal */ + wtda( old_input, wtda_old_input, st->old_wtda_swb, ALDO_WINDOW, ALDO_WINDOW, L_FRAME16k ); + + direct_transform( wtda_old_input, yorig, 0, L_FRAME16k ); + + mode = WB_BWE_encoding( coder_type, yorig, WB_fenv, st ); + + push_indice( st, IND_WB_CLASS, mode - 2, 1 ); + } + + + st->prev_mode = mode; + + return; +} + +/*-------------------------------------------------------------------* + * get_normalize_spec() + * + *-------------------------------------------------------------------*/ + +static void get_normalize_spec( + const short core, /* i : core selected */ + const short extl, /* i : extension layer selected */ + const short mode, /* i : SHB BWE class */ + const short core_type, /* i : coding type */ + const float *org, /* i : input spectrum */ + float *SWB_signal, /* o : output spectrum */ + short *prev_L_swb_norm, /* i : previous norm. len */ + const short offset /* i : frequency offset */ +) +{ + short n_freq, L_swb_norm; + float envelope[L_FRAME32k]; + short frq_end; + + set_f( SWB_signal, 0, HQ_GENERIC_HIGH0+offset ); + calc_normal_length(core, org, mode, extl, &L_swb_norm, prev_L_swb_norm); + if( extl == SWB_BWE || extl == FB_BWE ) + { + if( mode == HARMONIC ) + { + mvr2r( org, &SWB_signal[240+offset], 240 ); + mvr2r( &org[128], &SWB_signal[480+offset], 80 ); + } + else + { + mvr2r( &org[112], &SWB_signal[240+offset], 128 ); + mvr2r( &org[112], &SWB_signal[368+offset], 128 ); + mvr2r( &org[176], &SWB_signal[496+offset], 64 ); + } + frq_end = 560+offset; + } + else if (extl == WB_BWE) + { + if( core_type == 0 ) + { + mvr2r(&org[160], &SWB_signal[240], 80); + } + else + { + mvr2r(&org[80], &SWB_signal[240], 80); + } + frq_end = L_FRAME16k; + } + else + { + mvr2r( org+HQ_GENERIC_OFFSET, SWB_signal+HQ_GENERIC_HIGH0+offset, HQ_GENERIC_LEN0 ); + mvr2r( org+HQ_GENERIC_OFFSET, SWB_signal+HQ_GENERIC_HIGH1+offset, HQ_GENERIC_LEN0 ); + if ( offset == HQ_GENERIC_FOFFSET_24K4 ) + { + mvr2r( org+HQ_GENERIC_LOW0, SWB_signal+HQ_GENERIC_HIGH2+offset, HQ_GENERIC_END_FREQ-HQ_GENERIC_HIGH2 ); + } + frq_end = L_FRAME32k; + } + + /* calculate envelope */ + calc_norm_envelop( SWB_signal, envelope, L_swb_norm, frq_end - offset, offset ); + + /* Normalize with envelope */ + for( n_freq = swb_bwe_subband[0]+offset; n_freqextl == SWB_BWE || st->extl == FB_BWE ) + { + input_hi = &fSpectrum[256]; + numsharp = NUM_SHARP; + if ( ( st->last_extl == SWB_BWE && st->extl == SWB_BWE ) || ( st->last_extl == FB_BWE && st->extl == FB_BWE ) ) + { + gain_tmp = fGain / (st->prev_global_gain + EPSILON); + if (st->prev_mode == TRANSIENT) + { + numharmonic = numharmonic * 2; + } + else if (st->prev_mode == NORMAL || st->prev_mode == NOISE) + { + numharmonic = 3 * numharmonic / 2; + } + } + else + { + gain_tmp = 1; + if (st->prev_mode == HARMONIC) + { + numharmonic = numharmonic / 2; + sharplimit = sharplimit / 2; + } + else + { + numharmonic = numharmonic * 2; + sharplimit = sharplimit * 2; + } + } + } + else if (st->extl == WB_BWE) + { + input_hi = &fSpectrum[224]; + numsharp = NUM_SHARP / 3; + if (st->prev_mode == HARMONIC) + { + numharmonic = numharmonic / 4; + } + else + { + numharmonic = numharmonic / 2; + } + if (st->last_extl != WB_BWE) + { + if (st->prev_mode == HARMONIC) + { + sharplimit = sharplimit / 2; + } + else + { + sharplimit = sharplimit * 2; + } + } + } + + meanH = EPSILON; + for(i = 0; i < numsharp; i ++) + { + peak = 0.0f; + mean[i] = 0; + + for(j = 0; j < SHARP_WIDTH; j ++) + { + mag = (float) fabs(*input_hi); + if (mag > peak) + { + peak = mag; + } + mean[i] += mag; + input_hi ++; + } + meanH += mean[i]; + + if(mean[i] != peak) + { + sharp = (float) (peak * (SHARP_WIDTH - 1) / (mean[i] - peak)); + } + else + { + sharp = 0.0f; + } + + if (sharp > 4.5 && peak > 8) + { + k += 1; + } + else if (sharp < 3.0) + { + noise += 1; + } + + if (sharp > sharpPeak) + { + sharpPeak = sharp; + } + } + + if ( st->extl == SWB_BWE || st->extl == FB_BWE ) + { + if(k >= numharmonic && gain_tmp > 0.5f && gain_tmp < 1.8f && sharpPeak > sharplimit) + { + sharpMod = 1; + } + else + { + sharpMod = 0; + } + meanH /= 288; + mean_d = 0.0f; + for(i=0; iextl == WB_BWE) + { + if (k >= numharmonic && sharpPeak > sharplimit) + { + sharpMod = 1; + } + else + { + sharpMod = 0; + } + } + + if (sharpMod && st->modeCount < 12) + { + st->modeCount++; + } + else if (sharpMod == 0 && st->modeCount > 0) + { + st->modeCount--; + } + + if (st->modeCount >= 2) + { + sharpMod = 1; + } + + if (sharpMod) + { + mode = HARMONIC; + } + else if ( st->extl == SWB_BWE || st->extl == FB_BWE ) + { + if (noise > 4 && mean_d < 4.8f*meanH && tilt_nb < 5) + { + mode = NOISE; + } + } + + return mode; +} + +/*-------------------------------------------------------------------* + * WB_BWE_encoding() + * + * WB BWE main encoder + *-------------------------------------------------------------------*/ + +static short WB_BWE_encoding( /* o : classification of wb signal */ + const short coder_type, + const float *yos, /* i : MDCT coefficients of weighted original */ + float *WB_fenv, /* i/o: energy of WB envelope */ + Encoder_State *st /* i/o: Encoder structure */ +) +{ + short mode; + float global_gain; + float energy; + short i, n_coeff, n_band; + short index; + float energy_factor[4]; + + /* Energy for the different bands and global energies */ + global_gain = EPSILON; + + for (i = 0, n_band = 0; i < 2; i++) + { + energy = EPSILON; + for (n_coeff = swb_bwe_subband[n_band]; n_coeff < swb_bwe_subband[n_band+2]; n_coeff++) + { + energy += yos[n_coeff] * yos[n_coeff]; + } + + WB_fenv[i] = energy; + n_band += 2; + global_gain += energy; + } + + mode = FD_BWE_class(yos, global_gain, 0, st); + + energy_control( st, ACELP_CORE, mode, coder_type, yos, 0, energy_factor ); + + for (i = 0; i < 2; i++) + { + WB_fenv[i] = (float)(log10( WB_fenv[i]*energy_factor[i<<1]/40 )*FAC_LOG2); + } + + index = WB_BWE_fenv_q( WB_fenv, F_2_5, 32, 2 ); + + push_indice( st, IND_WB_FENV, index, 5 ); + + + return (mode); + +} + + +/*-------------------------------------------------------------------* + * swb_bwe_enc() + * + * SWB BWE encoder (only for 32kHz signals) + *-------------------------------------------------------------------*/ + +void swb_bwe_enc( + Encoder_State *st, /* i/o: encoder state structure */ + const float *old_input_12k8, /* i : input signal @12.8kHz for SWB BWE */ + const float *old_input_16k, /* i : input signal @16kHz for SWB BWE */ + const float *old_syn_12k8_16k, /* i : ACELP core synthesis at 12.8kHz or 16kHz*/ + const float *new_swb_speech, /* i : original input signal at 32kHz */ + const float *shb_speech, /* i : SHB target signal (6-14kHz) at 16kHz */ + const short coder_type /* i : coding type */ +) +{ + short i, inner_frame, idxGain; + float *new_input; + long inner_Fs; + float old_input[NS2SA(48000, DELAY_FD_BWE_ENC_NS + DELAY_FIR_RESAMPL_NS) + L_FRAME48k]; + float old_input_lp[L_FRAME16k], new_input_hp[L_FRAME16k]; + float yorig[L_FRAME48k]; + float wtda_old_input[2*L_FRAME48k]; + float SWB_fenv[SWB_FENV]; + float tilt_nb; + short Sample_Delay_SWB_BWE, Sample_Delay_HP, Sample_Delay_LP; + float ener_low, energy_fbe_fb, fb_ener_adjust, ener_adjust_quan; + + ener_adjust_quan = 0.0f; + idxGain = 0; + + /*---------------------------------------------------------------------* + * Delay the original input signal to be synchronized with ACELP core synthesis + *---------------------------------------------------------------------*/ + + if( st->extl == FB_BWE ) + { + inner_frame = L_FRAME48k; + inner_Fs = 48000; + } + else + { + inner_frame = L_FRAME32k; + inner_Fs = 32000; + } + + set_f( old_input, 0.0f, NS2SA(inner_Fs, DELAY_FD_BWE_ENC_12k8_NS + DELAY_FIR_RESAMPL_NS) + inner_frame ); + + if( st->L_frame == L_FRAME ) + { + Sample_Delay_SWB_BWE = NS2SA(inner_Fs, DELAY_FD_BWE_ENC_12k8_NS + DELAY_FIR_RESAMPL_NS); + Sample_Delay_HP = NS2SA(16000, ACELP_LOOK_NS + DELAY_FD_BWE_ENC_12k8_NS + DELAY_FIR_RESAMPL_NS - DELAY_CLDFB_NS); + Sample_Delay_LP = NS2SA(12800, ACELP_LOOK_NS + DELAY_FD_BWE_ENC_12k8_NS); + + mvr2r( st->old_input_lp, old_input_lp, Sample_Delay_LP ); + mvr2r( old_input_12k8 + L_INP_MEM, &old_input_lp[Sample_Delay_LP], L_FRAME-Sample_Delay_LP ); + mvr2r( old_input_12k8 + L_INP_MEM + L_FRAME - Sample_Delay_LP, st->old_input_lp, Sample_Delay_LP ); + } + else + { + Sample_Delay_SWB_BWE = NS2SA(inner_Fs, DELAY_FD_BWE_ENC_16k_NS + DELAY_FIR_RESAMPL_NS); + Sample_Delay_HP = NS2SA(16000, ACELP_LOOK_NS + DELAY_FD_BWE_ENC_16k_NS + DELAY_FIR_RESAMPL_NS - DELAY_CLDFB_NS); + Sample_Delay_LP = NS2SA(16000, ACELP_LOOK_NS + DELAY_FD_BWE_ENC_16k_NS); + + mvr2r( st->old_input_lp, old_input_lp, Sample_Delay_LP ); + mvr2r( old_input_16k + L_INP_MEM, &old_input_lp[Sample_Delay_LP], L_FRAME16k-Sample_Delay_LP ); + mvr2r( old_input_16k + L_INP_MEM + L_FRAME16k - Sample_Delay_LP, st->old_input_lp, Sample_Delay_LP ); + } + + mvr2r( st->new_input_hp, new_input_hp, Sample_Delay_HP ); + mvr2r( shb_speech, new_input_hp + Sample_Delay_HP, L_FRAME16k - Sample_Delay_HP ); + mvr2r( shb_speech + L_FRAME16k - Sample_Delay_HP, st->new_input_hp, Sample_Delay_HP ); + + new_input = old_input + Sample_Delay_SWB_BWE; + mvr2r( st->old_input, old_input, Sample_Delay_SWB_BWE ); + mvr2r( new_swb_speech, new_input, inner_frame ); + mvr2r( old_input + inner_frame, st->old_input, Sample_Delay_SWB_BWE ); + + /*----------------------------------------------------------------------* + * Calculate tilt of the input signal and the ACELP core synthesis + *----------------------------------------------------------------------*/ + + calc_tilt_bwe( old_input_lp, &tilt_nb, L_FRAME ); + + /*---------------------------------------------------------------------* + * SWB BWE encoding + * FB BWE encoding + *---------------------------------------------------------------------*/ + + /* windowing of the original input signal */ + wtda( old_input, wtda_old_input, st->old_wtda_swb, ALDO_WINDOW,ALDO_WINDOW,inner_frame ); + + /* DCT of the original input signal */ + direct_transform( wtda_old_input, yorig, 0, inner_frame ); + + /* FB BWE encoding */ + if ( st->extl == FB_BWE ) + { + energy_fbe_fb = sum2_f( yorig + FB_BAND_BEGIN, FB_BAND_WIDTH ) + EPSILON; + ener_low = EPSILON; + for( i=FB_BAND_BEGIN - FB_BAND_WIDTH; iL_frame == L_FRAME16k) + { + SWB_BWE_encoding( st, old_input, old_input_lp, new_input_hp, old_syn_12k8_16k, yorig, SWB_fenv, tilt_nb, 80, coder_type ); + } + else + { + SWB_BWE_encoding( st, old_input, old_input_lp, new_input_hp, old_syn_12k8_16k, yorig, SWB_fenv, tilt_nb, 6, coder_type ); + } + + /* write FB BWE frame gain to the bitstream */ + if( st->extl == FB_BWE ) + { + push_indice( st, IND_FB_SLOPE, idxGain, NUM_BITS_FB_FRAMEGAIN ); + } + + + return; +} + +/*-------------------------------------------------------------------* + * Freq_weights() + * + *-------------------------------------------------------------------*/ +static +void freq_weights( + const float Band_Ener[], /* i : Band energy */ + const float f_weighting[], /* i : weigting coefs. */ + float w_env[], /* o : Freq. weighting */ + const short Nbands /* i : Number of bands */ +) +{ + short i; + float tmp, w1[SWB_FENV], w2[SWB_FENV]; + float min_b, max_b; + + /* Find Max band energy */ + min_b = Band_Ener[0]; + max_b = Band_Ener[0]; + for( i=1; i max_b ) + { + max_b = Band_Ener[i]; + } + } + + /* Find weighting function */ + tmp = 1.f/(max_b-min_b); + for( i=0; i k; l-- ) + { + dist_min[l] = dist_min[l - 1]; + index[l] = index[l - 1]; + } + dist_min[k] = dist; + index[k] = i; + break; + } + } + } + } + else + { + set_f( dist_min, 3.402823466e+38F, surv ); /* FLT_MAX */ + + for (i = 0; i < surv; i++) + { + index[i] = i; + } + + p_E_ROM_dico = E_ROM_dico; + + for( i = 0; i < E_ROM_dico_size; i++ ) + { + dist = x[0] - *p_E_ROM_dico++; + dist *= dist; + + for( j = 1; j < dim; j++ ) + { + temp1 = x[j] - *p_E_ROM_dico++; + dist += temp1 * temp1; + } + + for( k = 0; k < surv; k++ ) + { + if( dist < dist_min[k] ) + { + for( l = surv - 1; l > k; l-- ) + { + dist_min[l] = dist_min[l-1]; + index[l] = index[l-1]; + } + dist_min[k] = dist; + index[k] = i; + break; + } + } + } + } + + return; +} + +/*-------------------------------------------------------------------* + * vqSimple_w() + * + *-------------------------------------------------------------------*/ +static +short vqSimple_w( + const float *x, /* i : input for quantizer */ + float *y, /* i : quantized value */ + const float *cb, /* i : codebooks */ + const float *w, /* i : weight */ + const short dim, /* i : dimension */ + const short l, /* i : number of candidates */ + const short flag /* i : flag indicationg weighted distortion metric */ +) +{ + short i, j, index; + const float *cbP; + float dist_min, dist, temp; + + index = 0; + dist_min = FLT_MAX; + cbP = cb; + + if( flag ) + { + for( i = 0; i < l; i++ ) + { + dist = x[0] - *cbP++; + dist *= (dist * w[0]); + for( j = 1; j < dim; j++ ) + { + temp = x[j] - *cbP++; + dist += temp * temp * w[j]; + } + + if( dist < dist_min ) + { + dist_min = dist; + index = i; + } + } + } + else + { + for( i = 0; i < l; i++ ) + { + dist = x[0] - *cbP++; + dist *= dist; + for( j = 1; j < dim; j++ ) + { + temp = x[j] - *cbP++; + dist += temp * temp; + } + + if( dist < dist_min ) + { + dist_min = dist; + index = i; + } + } + } + + /* Reading the selected vector */ + mvr2r( &cb[index * dim], y, dim ); + + return(index); +} + +/*-------------------------------------------------------------------* + * MSVQ_Interpol_Tran() + * + *-------------------------------------------------------------------*/ + +static void MSVQ_Interpol_Tran( + float *SWB_env_energy, /* i/o : (original/quantized) energy */ + short *indice /* o : quantized index */ +) +{ + short k, n_band, candInd[N_CAND_TR], ind_tmp[2]; + float env_temp11[SWB_FENV_TRANS/2], env_temp12[SWB_FENV_TRANS/2]; + float dist, minDist, tmp_q; + float quant_tmp[SWB_FENV_TRANS], quant_tmp2[SWB_FENV_TRANS]; + float distCand[N_CAND_TR], quant_select[SWB_FENV_TRANS]; + + /* Extract target vector */ + for( n_band = 0; n_band < DIM_TR1; n_band++ ) + { + env_temp11[n_band] = SWB_env_energy[2*n_band]; + env_temp12[n_band] = SWB_env_energy[2*n_band+1]; + } + + vqWithCand_w( env_temp11, Env_TR_Cdbk1, DIM_TR1, N_CB_TR1, candInd, N_CAND_TR, distCand, NULL, 0 ); + + minDist = FLT_MAX; + for( k=0; ktotal_brate <= ACELP_8k00 ) + { + core_type = 0; + } + else + { + core_type = 1; + } + + get_normalize_spec( core, st->extl, mode, core_type, org, SWB_signal, &(st->prev_L_swb_norm1), offset ); + + if ( st->extl == WB_BWE) + { + max_band = 4; + band_step = 2; + } + } + else /* HQ core */ + { + gamma = 0.55f; + get_normalize_spec( core, -1, mode, -1, org, SWB_signal, &(st->prev_L_swb_norm1), offset ); + + if ( offset == HQ_GENERIC_FOFFSET_32K ) + { + max_band = 12; + } + } + + for( n_band=0; n_bandL_frame == L_FRAME ) + { + L = L_SUBFR; + } + else + { + L = L_SUBFR16k; + } + + /* HF transient detect */ + IsTransient = detect_transient( insig_hp, st, L_FRAME16k, coder_type ); + + /* LF transient detect */ + IsTransient_LF = 0; + for ( n_band = 0; n_band < 4; n_band++ ) + { + energy = EPSILON; + for ( i = 0; i < L; i++ ) + { + energy += insig_lp[i + n_band*L] * insig_lp[i + n_band*L]; + } + + if( energy > 5.5f * st->EnergyLF ) + { + IsTransient_LF = 1; + } + + st->EnergyLF = energy; + } + calc_tilt_bwe(insig, &tilt, L_FRAME32k); + if( IsTransient == 1 && (tilt > 8.0 || st->clas > 1) ) + { + IsTransient = 0; + st->TransientHangOver = 0; + } + + if( IsTransient == 1 ) + { + mode = IsTransient; + push_indice( st, IND_SWB_CLASS, mode, 2 ); + + /* Energy for the different bands and global energies */ + global_gain = 0; + for (n_band = 0; n_band < SWB_FENV_TRANS; n_band++) + { + energy = EPSILON; + for (n_coeff = swb_bwe_trans_subband[n_band]+st_offset; n_coeff < swb_bwe_trans_subband[n_band+1]+st_offset; n_coeff++) + { + energy += yos[n_coeff] * yos[n_coeff]; + } + global_gain += energy; + SWB_fenv[n_band] = energy; + } + global_gain *= 0.5f; + + for (n_band = 0; n_band < SWB_FENV_TRANS; n_band++) + { + SWB_fenv[n_band] = 10.0f * (float)log10( SWB_fenv[n_band]/swb_bwe_trans_subband_width[n_band] ) - Mean_env_tr[n_band]; + } + + WB_tenv_orig = EPSILON; + WB_tenv_syn = EPSILON; + for(n_band = 0; n_band < SWB_TENV; n_band++) + { + SWB_tenv[n_band] = EPSILON; + + for(i = 0; i < L_SUBFR16k; i++) + { + SWB_tenv[n_band] += insig_hp[i + n_band*L_SUBFR16k] * insig_hp[i + n_band*L_SUBFR16k]; + } + + for(i=0; i 1) + { + Rat_tenv = 1.0f; + } + + for(n_band = 0; n_band < SWB_TENV; n_band++) + { + SWB_tenv[n_band] *= Rat_tenv; + } + + max = SWB_tenv[0]; + pos = 0; + for(n_band = 1; n_band < SWB_TENV; n_band++) + { + if(SWB_tenv[n_band] > max) + { + max = SWB_tenv[n_band]; + pos = n_band; + } + } + + max = SWB_tenv[0]; + for(n_band = 1; n_band < SWB_TENV; n_band++) + { + if(SWB_tenv[n_band] > 5.0f*SWB_tenv[n_band-1]) + { + break; + } + } + + if(n_band < SWB_TENV) + { + energy = 0.0f; + for(n_band = (pos+1); n_band < SWB_TENV; n_band++) + { + energy += SWB_tenv[n_band]; + } + if(pos == SWB_TENV-1) + { + energy = 0.0f; + } + else + { + energy /= (SWB_TENV-pos-1); + } + + for(n_band = 0; n_band < pos; n_band++) + { + SWB_tenv[n_band] *= 0.5f; + } + + SWB_tenv[pos] *= 1.005f; + if(energy < SWB_tenv[pos]) + { + for(n_band = pos+1; n_band < SWB_TENV; n_band++) + { + SWB_tenv[n_band] *= 0.9f; + } + } + } + else + { + for(n_band = 1; n_band < SWB_TENV; n_band++) + { + if(SWB_tenv[n_band-1] > SWB_tenv[n_band]) + { + SWB_tenv[n_band-1] = 0.5f*(SWB_tenv[n_band-1]+SWB_tenv[n_band]); + } + else + { + SWB_tenv[n_band] = 0.5f*(SWB_tenv[n_band-1]+SWB_tenv[n_band]); + } + } + + for(n_band = 0; n_band < SWB_TENV; n_band++) + { + SWB_tenv[n_band] *= 0.9f; + } + } + + if(IsTransient_LF == 0 && coder_type == INACTIVE && st->TransientHangOver == 1) + { + for(n_band = 0; n_band < SWB_TENV; n_band++) + { + SWB_tenv[n_band] *= 0.5f; + } + for(n_band = 0; n_band < SWB_FENV_TRANS; n_band++) + { + SWB_fenv[n_band] *= 0.05f; + } + } + else + { + SWB_fenv[2] *= 0.1f; + SWB_fenv[3] *= 0.05f; + } + + for(n_band = 0; n_band < SWB_TENV; n_band++) + { + SWB_tenv_tmp[n_band] = (float) log10( SWB_tenv[n_band] + EPSILON ) * FAC_LOG2; + if (SWB_tenv_tmp[n_band] > 15) + { + index = 15; + } + else if (SWB_tenv_tmp[n_band] < 0) + { + index = 0; + } + else + { + index = (short)(SWB_tenv_tmp[n_band]+0.5f); + } + + push_indice( st, IND_SWB_TENV, index, 4 ); + + } + + MSVQ_Interpol_Tran(SWB_fenv, indice); + + push_indice( st, IND_SWB_FENV, indice[0], 7 ); + push_indice( st, IND_SWB_FENV, indice[1], 6 ); + + } + else + { + /* Energy for the different bands and global energies */ + global_gain = 0; + for (n_band = 0; n_band < SWB_FENV; n_band++) + { + energy = EPSILON; + for (n_coeff = swb_bwe_subband[n_band]+st_offset; n_coeff < swb_bwe_subband[n_band+1]+st_offset; n_coeff++) + { + energy += yos[n_coeff] * yos[n_coeff]; + } + + if (n_bandprev_mode = mode; + st->prev_global_gain = global_gain; + + return mode; +} + +static short decision_hq_generic_class ( + const float *coefs, /* i: original MDCT spectrum */ + const short hq_generic_offset /* i: frequency offset of high frequency spectrum */ +) +{ + short i, k; + float p, a, e; + float p2a; + float avgp2a; + short nband; + + if ( hq_generic_offset == HQ_GENERIC_FOFFSET_24K4 ) + { + nband = 10; + } + else + { + nband = 8; + } + + avgp2a = 0.f; + for (k = 0; k < nband; k++) + { + a = 0.0f; + p = 0.0f; + for (i = swb_bwe_subband[k]+hq_generic_offset; i p) + { + p = e; + } + + a += e; + } + + if (a > 0.0f) + { + a *= swb_inv_bwe_subband_width[k]; + p2a = 10.0f * (float) log10 (p / a); + avgp2a += p2a; + } + } + + avgp2a /= (float)(nband); + + if ( avgp2a > 8.6f ) + { + return HQ_GENERIC_EXC1; + } + else + { + return HQ_GENERIC_EXC0; + } +} + +/*-------------------------------------------------------------------* + * hq_generic_hf_encoding() + * + *-------------------------------------------------------------------*/ + +void hq_generic_hf_encoding( + const float *coefs, /* i : MDCT coefficients of weighted original */ + float *hq_generic_fenv, /* i/o: energy of SWB envelope */ + const short hq_generic_offset, /* i : frequency offset for extracting energy */ + Encoder_State *st, /* i/o: encoder state structure */ + short *hq_generic_exc_clas /* o : HF excitation class */ +) +{ + short n_coeff, n_band; + float energy; + float energy_factor[SWB_FENV], w_env[SWB_FENV]; + short indice[HQ_GENERIC_NVQIDX]; + short nenv; + + if ( hq_generic_offset <= HQ_GENERIC_FOFFSET_24K4 ) + { + nenv = SWB_FENV; + } + else + { + nenv = SWB_FENV-2; + } + + for( n_band = 0; n_band < nenv; n_band++ ) + { + energy = EPSILON; + for( n_coeff = swb_bwe_subband[n_band]+hq_generic_offset; n_coeff < swb_bwe_subband[n_band+1] + hq_generic_offset; n_coeff++ ) + { + energy += coefs[n_coeff] * coefs[n_coeff]; + } + + hq_generic_fenv[n_band] = energy; + } + + if ( st->bwidth == FB ) + { + for( n_band = 0; n_band < DIM_FB; n_band++ ) + { + energy = EPSILON; + for( n_coeff = fb_bwe_subband[n_band]; n_coeff < fb_bwe_subband[n_band+1]; n_coeff++ ) + { + energy += coefs[n_coeff] * coefs[n_coeff]; + } + + hq_generic_fenv[n_band+nenv] = energy; + } + } + + energy_control( st, HQ_CORE, -1, -1, coefs, hq_generic_offset, energy_factor ); + + if ( st->hq_generic_speech_class == 1 ) + { + push_indice( st, IND_HQ_SWB_EXC_SP_CLAS, 1, 1 ); + *hq_generic_exc_clas = HQ_GENERIC_SP_EXC; + } + else + { + *hq_generic_exc_clas = decision_hq_generic_class(coefs, hq_generic_offset); + push_indice( st, IND_HQ_SWB_EXC_SP_CLAS, 0, 1 ); + push_indice( st, IND_HQ_SWB_EXC_CLAS, *hq_generic_exc_clas, 1 ); + } + + for( n_band = 0; n_band < nenv; n_band++ ) + { + hq_generic_fenv[n_band] *= energy_factor[n_band]; + hq_generic_fenv[n_band] = 10.0f * (float)log10( hq_generic_fenv[n_band]*swb_inv_bwe_subband_width[n_band] ); + } + + if ( st->bwidth == FB ) + { + for( n_band = 0; n_band < DIM_FB; n_band++ ) + { + hq_generic_fenv[n_band+nenv] = 10.0f * (float)log10( hq_generic_fenv[n_band+nenv]*fb_inv_bwe_subband_width[n_band] ); + } + } + + freq_weights( hq_generic_fenv, w_NOR, w_env, nenv ); + + for( n_band = 0; n_band < nenv; n_band++ ) + { + hq_generic_fenv[n_band] -= Mean_env[n_band]; + } + + if ( st->bwidth == FB ) + { + for( n_band = 0; n_band < DIM_FB; n_band++ ) + { + hq_generic_fenv[n_band+nenv] -= Mean_env_fb[n_band]; + } + } + + /* Energy VQ */ + if ( hq_generic_offset <= HQ_GENERIC_FOFFSET_24K4 ) + { + msvq_interpol( hq_generic_fenv, w_env, indice ); + } + else + { + msvq_interpol_2( hq_generic_fenv, w_env, indice, nenv ); + } + + if ( st->bwidth == FB ) + { + indice[5] = vqSimple_w( hq_generic_fenv+nenv, hq_generic_fenv+nenv, EnvCdbkFB, NULL, DIM_FB, N_CB_FB, 0 ); + } + + push_indice( st, IND_SWB_FENV_HQ, indice[0], 5 ); + push_indice( st, IND_SWB_FENV_HQ, indice[1], 7 ); + push_indice( st, IND_SWB_FENV_HQ, indice[2], 6 ); + push_indice( st, IND_SWB_FENV_HQ, indice[3], 5 ); + + if ( hq_generic_offset <= HQ_GENERIC_FOFFSET_24K4 ) + { + push_indice( st, IND_SWB_FENV_HQ, indice[4], 6 ); + } + else + { + push_indice( st, IND_SWB_FENV_HQ, indice[4], 5 ); + } + + if ( st->bwidth == FB ) + { + push_indice( st, IND_FB_FENV_HQ, indice[5], 5 ); + } + + for( n_band = 0; n_band < nenv; n_band++ ) + { + Word16 tmp,frac,exp; + Word32 L_tmp; + tmp = add((short)(hq_generic_fenv[n_band]*256),(short)(Mean_env[n_band]*256)); /*Q8 */ + + L_tmp = L_mult(tmp, 21771); /* 0.166096 in Q17 -> Q26 */ + L_tmp = L_shr(L_tmp, 10); /* From Q26 to Q16 */ + frac = L_Extract_lc(L_tmp, &exp); /* Extract exponent of L_tmp */ + + tmp = extract_l(Pow2(13, frac));/* Put 13 as exponent so that */ + /* output of Pow2() will be: */ + /* 16384 < Pow2() <= 32767 */ + exp = sub(exp, 13); + tmp = shl(tmp, add(exp,1)); /*Q1 */ + hq_generic_fenv[n_band] = (float)tmp*0.5f;; /*Q1 */ + } + + if ( st->bwidth == FB ) + { + for( n_band = 0; n_band < DIM_FB; n_band++ ) + { + Word16 tmp,frac,exp; + Word32 L_tmp; + + tmp = add((short)(hq_generic_fenv[n_band + nenv]*128),(short)(Mean_env_fb[n_band]*128)); /*Q7 */ + L_tmp = L_mult(tmp, 21771); /* 0.166096 in Q17 -> Q25 */ + L_tmp = L_shr(L_tmp, 9); /* From Q25 to Q16 */ + frac = L_Extract_lc(L_tmp, &exp); /* Extract exponent of L_tmp */ + + tmp = extract_l(Pow2(13, frac));/* Put 13 as exponent so that */ + /* output of Pow2() will be: */ + /* 16384 < Pow2() <= 32767 */ + exp = sub(exp, 13); + tmp = shl(tmp, add(exp, 1));/*Q1 */ + hq_generic_fenv[add(n_band,nenv)] = (float)tmp*0.5f; + } + } + + return; +} diff --git a/src/libs/libevs/lib_enc/swb_bwe_enc_fx.cpp b/src/libs/libevs/lib_enc/swb_bwe_enc_fx.cpp deleted file mode 100755 index 53fa531e..00000000 --- a/src/libs/libevs/lib_enc/swb_bwe_enc_fx.cpp +++ /dev/null @@ -1,2833 +0,0 @@ -/*==================================================================================== - EVS Codec 3GPP TS26.442 Apr 03, 2018. Version 12.11.0 / 13.6.0 / 14.2.0 - ====================================================================================*/ - -#include -#include "options.h" - -#include "prot_fx.h" -#include "cnst_fx.h" -#include "rom_com_fx.h" -#include "stl.h" - -/*---------------------------------------------------------------------* - * Local functions - *---------------------------------------------------------------------*/ - -static Word16 SWB_BWE_encoding_fx( - Encoder_State_fx *st_fx, /* i/o: encoder state structure */ - Word16 *insig_fx, /* i/o: delayed original input signal at 32kHz (might be rescaled)*/ - const Word16 *insig_lp_fx, /* i : delayed original lowband input signal at 32kHz */ - const Word16 *insig_hp_fx, /* i : delayed original highband input signal at 32kHz */ - const Word16 *synth_fx, /* i : delayed ACELP core synthesis at 12.8kHz */ - const Word16 *yos_fx, /* i : MDCT coefficients of the windowed original input signal at 32kHz */ - Word16 *SWB_fenv_fx, /* o : frequency-domain quantized BWE envelope */ - const Word16 tilt_nb_fx, /* i : SWB tilt */ - const Word16 st_offset, /* i : start frequency offset for BWE envelope */ - const Word16 coder_type, /* i : coding type */ - Word16 Q_insig_lp, - Word16 Q_shb, - Word16 Q_synth, - Word16 Q_synth_lf -); - -static void delay_input_signal_fx( - Word16 *old_sig, - Word16 *cur_sig, - Word16 *new_sig, - Word16 m1, - Word16 m2, - Word16 *Q_old, - Word16 *Q_new -) -{ - Word16 i; - Word16 max; - Word16 max1_exp, max2_exp; - - max = abs_s(old_sig[0]); - FOR(i=1; i 0) - { - Copy_Scale_sig(new_sig, new_sig, m2, max2_exp); - Copy_Scale_sig(old_sig, old_sig, m1, sub(add(max2_exp, *Q_new), *Q_old)); - *Q_new = add(max2_exp, *Q_new); - } - ELSE IF(sub(add(max1_exp, *Q_old), add(max2_exp, *Q_new)) < 0) - { - Copy_Scale_sig(new_sig, new_sig, m2, sub(add(max1_exp, *Q_old), *Q_new)); - Copy_Scale_sig(old_sig, old_sig, m1, max1_exp); - *Q_new = add(max1_exp, *Q_old); - } - ELSE - { - Copy_Scale_sig(new_sig, new_sig, m2, max2_exp); - Copy_Scale_sig(old_sig, old_sig, m1, max1_exp); - *Q_new = add(max1_exp, *Q_old); - } - *Q_old = *Q_new; - move16(); - Copy(old_sig, cur_sig, m1); - Copy( new_sig, &cur_sig[m1], sub(m2,m1) ); - Copy( new_sig + sub(m2,m1), old_sig, m1 ); - - return; -} - -/*-------------------------------------------------------------------* - * wb_bwe_enc() - * - * WB BWE encoder - *-------------------------------------------------------------------*/ -void wb_bwe_enc_fx( - Encoder_State_fx *st_fx, /* i/o: encoder state structure */ - const Word16 *new_wb_speech_fx, /* i : original input signal at 16kHz */ - Word16 coder_type /* i : coding type */ -) -{ - Word16 mode = 0; - Word16 Sample_Delay_WB_BWE; - Word16 old_input_fx[NS2SA(16000, DELAY_FD_BWE_ENC_NS + DELAY_FIR_RESAMPL_NS) + L_FRAME16k]; - Word32 yorig_32[L_FRAME16k]; - Word16 yorig_fx[L_FRAME16k]; - Word32 L_wtda_synth_fx[2*L_FRAME16k]; - Word16 *new_input_fx; /* pointer to original input signal */ - Word16 scl, new_input_fx_exp; - Word16 Q_synth; - Word16 WB_fenv_fx[SWB_FENV]; - - IF( L_sub(st_fx->total_brate_fx, ACELP_13k20) == 0 ) - { - /*---------------------------------------------------------------------* - * Delay the original input signal to be synchronized with ACELP core synthesis - *---------------------------------------------------------------------*/ - set16_fx( old_input_fx, 0, NS2SA(16000, DELAY_FD_BWE_ENC_12k8_NS + DELAY_FIR_RESAMPL_NS) + L_FRAME16k ); - Sample_Delay_WB_BWE = NS2SA( 16000, DELAY_FD_BWE_ENC_12k8_NS); - - new_input_fx = old_input_fx + Sample_Delay_WB_BWE; - Copy( st_fx->old_input_wb_fx, old_input_fx, Sample_Delay_WB_BWE ); - Copy( new_wb_speech_fx, new_input_fx, L_FRAME16k ); - Copy( old_input_fx + L_FRAME16k, st_fx->old_input_wb_fx, Sample_Delay_WB_BWE ); - - /*---------------------------------------------------------------------*/ - /* WB BWE encoding */ - - - /* MDCT of the core synthesis signal */ - /*---------------------------------------------------------------------*/ - new_input_fx_exp = 0; - move16(); - - wtda_fx(old_input_fx, &new_input_fx_exp, L_wtda_synth_fx, st_fx->L_old_wtda_swb_fx, - &st_fx->Q_old_wtda,ALDO_WINDOW,ALDO_WINDOW, /* window overlap of current frame (0: full, 2: none, or 3: half) */ - L_FRAME16k ); - - /* DCT of the ACELP core synthesis */ - direct_transform_fx(L_wtda_synth_fx, yorig_32, 0, L_FRAME16k, &new_input_fx_exp); - - /* Convert to 16 Bits (Calc Shift Required to Stay within MAX_Q_NEW_INPUT) */ - scl = sub(16+8/*MAX_Q_NEW_INPUT*/, new_input_fx_exp); - /* Possible to Upscale? */ - IF (scl > 0) - { - /* Yes */ - /* Calc Room to Upscale */ - Q_synth = Find_Max_Norm32(yorig_32, L_FRAME16k); - - /* Stay within MAX_Q_NEW_INPUT */ - scl = s_min(Q_synth, scl); - } - Copy_Scale_sig32_16(yorig_32, yorig_fx, L_FRAME16k, scl); - Q_synth = add(sub(new_input_fx_exp, 16), scl) - 1; - - mode = WB_BWE_encoding_fx( coder_type, yorig_fx, WB_fenv_fx, st_fx, Q_synth, Q_synth); - push_indice_fx(st_fx, IND_WB_CLASS, mode - 2, 1 ); - } - - st_fx->prev_mode_fx = mode; - - return; -} - -/*-------------------------------------------------------------------* -* swb_bwe_enc() -* -* SWB BWE encoder (only for 32kHz signals) -*-------------------------------------------------------------------*/ -void swb_bwe_enc_fx( - Encoder_State_fx *st_fx, /* i/o: encoder state structure */ - Word16 *old_input_12k8_fx, /* i : input signal @12.8kHz for SWB BWE */ - Word16 *old_input_16k_fx, /* i : input signal @16kHz for SWB BWE */ - const Word16 *old_syn_12k8_16k_fx, /* i : ACELP core synthesis at 12.8kHz or 16kHz */ - const Word16 *new_swb_speech_fx, /* i : original input signal at 32kHz */ - Word16 *shb_speech_fx, /* i : SHB target signal (6-14kHz) at 16kHz */ - const Word16 coder_type, /* i : coding type */ - Word16 Q_shb_speech, - Word16 Q_slb_speech -) -{ - Word16 i; - Word16 *new_input_fx; - Word16 tmp, exp, exp1; - Word16 frac; - Word32 L_tmp; - Word16 inner_frame; - Word32 inner_Fs; - Word32 L_old_input_fx[2*L_FRAME48k]; - Word32 yorig_32[L_FRAME48k]; - Word16 old_input_fx[NS2SA(48000, DELAY_FD_BWE_ENC_NS + DELAY_FIR_RESAMPL_NS) + L_FRAME48k]; - Word16 old_input_lp_fx[L_FRAME16k]; - Word16 new_input_hp_fx[L_FRAME16k]; - Word16 yorig_fx[L_FRAME48k]; - Word16 scl, new_input_fx_exp; - Word16 max; - Word16 Sample_Delay_SWB_BWE; - Word16 Sample_Delay_HP; - Word16 Sample_Delay_LP; - Word16 idxGain = 0; - - Word16 Q_synth_hf, Q_synth, Q_shb; - Word16 tilt_nb_fx; - Word16 SWB_fenv_fx[SWB_FENV]; - Word32 ener_low_fx; - Word32 energy_fbe_fb_fx = 0; - Word16 fb_ener_adjust_fx; - Word16 ener_adjust_quan_fx = 0; - - - /*---------------------------------------------------------------------* - * Delay the original input signal to be synchronized with ACELP core synthesis - *---------------------------------------------------------------------*/ - IF( sub(st_fx->extl_fx, FB_BWE) == 0 ) - { - inner_frame = L_FRAME48k; - inner_Fs = 48000; - } - ELSE - { - inner_frame = L_FRAME32k; - inner_Fs = 32000; - } - - set16_fx( old_input_fx, 0, add(NS2SA(inner_Fs, DELAY_FD_BWE_ENC_12k8_NS + DELAY_FIR_RESAMPL_NS), inner_frame) ); - - IF( sub(st_fx->L_frame_fx, L_FRAME) == 0 ) - { - Sample_Delay_SWB_BWE = NS2SA(inner_Fs, DELAY_FD_BWE_ENC_12k8_NS + DELAY_FIR_RESAMPL_NS); - Sample_Delay_HP = NS2SA(16000, ACELP_LOOK_NS + DELAY_FD_BWE_ENC_12k8_NS + DELAY_FIR_RESAMPL_NS - DELAY_CLDFB_NS); - Sample_Delay_LP = NS2SA(12800, ACELP_LOOK_NS + DELAY_FD_BWE_ENC_12k8_NS); - - delay_input_signal_fx( st_fx->old_input_lp_fx, old_input_lp_fx, &old_input_12k8_fx[L_INP_MEM], Sample_Delay_LP, L_FRAME, &st_fx->prev_Q_input_lp, &Q_slb_speech ); - } - ELSE - { - Sample_Delay_SWB_BWE = NS2SA(inner_Fs, DELAY_FD_BWE_ENC_16k_NS + DELAY_FIR_RESAMPL_NS); - Sample_Delay_HP = NS2SA(16000, ACELP_LOOK_NS + DELAY_FD_BWE_ENC_16k_NS + DELAY_FIR_RESAMPL_NS - DELAY_CLDFB_NS); - Sample_Delay_LP = NS2SA(16000, ACELP_LOOK_NS + DELAY_FD_BWE_ENC_16k_NS); - - delay_input_signal_fx( st_fx->old_input_lp_fx, old_input_lp_fx, &old_input_16k_fx[L_INP_MEM], Sample_Delay_LP, L_FRAME16k, &st_fx->prev_Q_input_lp, &Q_slb_speech ); - } - - Copy(st_fx->new_input_hp_fx, new_input_hp_fx, Sample_Delay_HP); - Copy( shb_speech_fx, &new_input_hp_fx[Sample_Delay_HP], L_FRAME16k-Sample_Delay_HP ); - Copy( shb_speech_fx + L_FRAME16k-Sample_Delay_HP, st_fx->new_input_hp_fx, Sample_Delay_HP ); - new_input_fx = old_input_fx + Sample_Delay_SWB_BWE; - Copy( st_fx->old_input_fx, old_input_fx, Sample_Delay_SWB_BWE ); - Copy( new_swb_speech_fx, new_input_fx, inner_frame ); - Copy( old_input_fx + inner_frame, st_fx->old_input_fx, Sample_Delay_SWB_BWE ); - /*----------------------------------------------------------------------* - * Calculate tilt of the input signal and the ACELP core synthesis - *----------------------------------------------------------------------*/ - - /* tilt returned in Q24 goto to Q11 */ - tilt_nb_fx = round_fx(L_shl(calc_tilt_bwe_fx(old_input_lp_fx, Q_slb_speech, st_fx->L_frame_fx), 3)); - /*---------------------------------------------------------------------* - * SWB BWE encoding - * FB BWE encoding - *---------------------------------------------------------------------*/ - new_input_fx_exp = 0; - /* MDCT of the core synthesis signal */ - wtda_fx(old_input_fx, &new_input_fx_exp, L_old_input_fx, st_fx->L_old_wtda_swb_fx, - &st_fx->Q_old_wtda, ALDO_WINDOW, ALDO_WINDOW, /* window overlap of current frame (0: full, 2: none, or 3: half) */ - inner_frame ); - - /* DCT of the ACELP core synthesis */ - direct_transform_fx(L_old_input_fx, yorig_32, 0, inner_frame, &new_input_fx_exp); - - /* Convert to 16 Bits (Calc Shift Required to Stay within MAX_Q_NEW_INPUT) */ - scl = sub(16+8, new_input_fx_exp); - /* Possible to Upscale? */ - IF (scl > 0) - { - /* Yes */ - /* Calc Room to Upscale */ - Q_synth = Find_Max_Norm32(yorig_32, inner_frame); - /* Stay within MAX_Q_NEW_INPUT */ - scl = s_min(Q_synth, scl); - } - Copy_Scale_sig32_16(yorig_32, yorig_fx, inner_frame, scl); - Q_synth = add(sub(new_input_fx_exp, 16), scl); - - max = 0; - move16(); - Q_synth_hf = 0; - move16(); - IF (sub(st_fx->L_frame_fx, L_FRAME16k) == 0) - { - scl = 300; - move16(); - } - ELSE - { - scl = 240; - move16(); - } - FOR(i=scl; ilast_extl_fx, SWB_BWE) == 0 || sub(st_fx->last_extl_fx, FB_BWE) == 0) - { - exp = norm_l(st_fx->EnergyLT_fx); - IF(add(st_fx->EnergyLT_fx_exp, exp) > shl(sub(Q_synth_hf, 4), 1)) - { - Q_shb = sub(Q_synth_hf, 4); - st_fx->EnergyLT_fx = L_shr(st_fx->EnergyLT_fx, sub(st_fx->EnergyLT_fx_exp, shl(Q_shb, 1))); - } - ELSE - { - Q_shb = shr(add(st_fx->EnergyLT_fx_exp, exp), 1); - IF(s_and(exp, 0x0001) == 1) - { - exp = sub(exp, 1); - } - st_fx->EnergyLT_fx = L_shl(st_fx->EnergyLT_fx, exp); - } - } - ELSE - { - Q_shb = sub(Q_synth_hf, 4); - } - Copy_Scale_sig(new_input_hp_fx, new_input_hp_fx, L_FRAME16k, sub(Q_shb, Q_shb_speech)); - /* SWB BWE encoding */ - IF (sub(st_fx->L_frame_fx, L_FRAME16k) == 0) - { - SWB_BWE_encoding_fx( st_fx, old_input_fx, old_input_lp_fx, new_input_hp_fx, old_syn_12k8_16k_fx, yorig_fx, - SWB_fenv_fx, tilt_nb_fx, 80, coder_type, Q_slb_speech, Q_shb, Q_synth_hf, Q_synth ); - - } - ELSE - { - SWB_BWE_encoding_fx( st_fx, old_input_fx, old_input_lp_fx, new_input_hp_fx, old_syn_12k8_16k_fx, yorig_fx, - SWB_fenv_fx, tilt_nb_fx, 6, coder_type, Q_slb_speech, Q_shb, Q_synth_hf, Q_synth ); - } - - /* FB BWE encoding */ - IF ( sub(st_fx->extl_fx, FB_BWE) == 0 ) - { - energy_fbe_fb_fx = L_deposit_l(0); - FOR( i=FB_BAND_BEGIN; i45-(exp+2*(Q_synth_hf-4)) */ - L_tmp = Mult_32_16(ener_low_fx, tmp); /*45-(exp+2*(Q_synth_hf-4)) + 2*(Q_synth_hf-4) - 15 = 30-exp */ - exp1 = norm_l(L_tmp); - L_tmp = L_shl(L_tmp, exp1); - exp = 31-exp1-(30-exp); - L_tmp = Isqrt_lc(L_tmp, &exp); /*31-exp */ - fb_ener_adjust_fx = round_fx(L_shl(L_tmp, exp)); /*Q15 */ - - } - ELSE - { - fb_ener_adjust_fx = 0; - move16(); - } - - fb_ener_adjust_fx = s_min(fb_ener_adjust_fx, 16384); /*Q15 */ - idxGain = usquant_fx( fb_ener_adjust_fx, &ener_adjust_quan_fx, 0, 512, shl(1, NUM_BITS_FB_FRAMEGAIN) ); - } - - /* write FB BWE frame gain to the bitstream */ - IF( sub(st_fx->extl_fx, FB_BWE) == 0 ) - { - push_indice_fx(st_fx, IND_FB_SLOPE, idxGain, NUM_BITS_FB_FRAMEGAIN ); - } - - return; -} -/*==========================================================================*/ -/* FUNCTION : static Word16 WB_BWE_fenv_q_fx() */ -/*--------------------------------------------------------------------------*/ -/* PURPOSE : Scalar quantizer routine */ -/*--------------------------------------------------------------------------*/ -/* INPUT ARGUMENTS : */ -/* Word16 *cb i: quantizer codebook Q10 */ -/* Word16 cb_length i: length of codebook */ -/* Word16 cb_dim i: dimension of codebook */ -/*--------------------------------------------------------------------------*/ -/* OUTPUT ARGUMENTS : */ -/*--------------------------------------------------------------------------*/ -/* INPUT/OUTPUT ARGUMENTS : */ -/* Word16 *x i/o: energy of WB envelop Q10 */ -/*--------------------------------------------------------------------------*/ -/* RETURN ARGUMENTS : */ -/* _ None */ -/*--------------------------------------------------------------------------*/ -/* */ -/*==========================================================================*/ -static Word16 WB_BWE_fenv_q_fx( /* o: quantized gain index */ - Word16 *x, /* i/o: energy of WB envelop Q10*/ - const Word16 *cb, /* i: quantizer codebook Q10 */ - const Word16 cb_length, /* i: length of codebook */ - const Word16 cb_dim /* i: dimension of codebook */ -) -{ - Word16 i, j, indx = 0; - Word32 dist, min_dist; - const Word16 *pit = cb;/*Q10 */ - Word16 tmp; - Word32 L_tmp; - - min_dist = L_add(MAX_32, 0); - FOR (i=0; iQ20 */ - dist = L_add(dist, L_tmp); - - pit++; - } - - IF( L_sub(dist,min_dist) < 0) - { - min_dist = L_add(dist, 0); - indx = i; - move16(); - } - } - - FOR(j=0; jextl_fx, SWB_BWE) == 0 || sub(st_fx->extl_fx, FB_BWE) == 0 ) - { - input_hi = &fSpectrum[256]; - move16(); - numsharp = NUM_SHARP; - move16(); - - test(); - test(); - test(); - IF ( ( sub(st_fx->last_extl_fx, SWB_BWE) == 0 && sub(st_fx->extl_fx, SWB_BWE) == 0 ) || ( sub(st_fx->last_extl_fx, FB_BWE) == 0 && sub(st_fx->extl_fx, FB_BWE) == 0 ) ) - { - IF(st_fx->prev_global_gain_fx == 0) - { - gain_tmp = round_fx(L_shl(fGain, 30)); /*Q14 */ - } - ELSE - { - expn = norm_l(fGain); - num = extract_h(L_shl(fGain, expn)); - expn = sub(sub(30, expn), shl(Q_shb,1)); - - expd = norm_l(st_fx->prev_global_gain_fx); - den = extract_h(L_shl(st_fx->prev_global_gain_fx, expd)); - expd = sub(sub(30, expd), shl(st_fx->prev_Q_shb,1)); - - scale = shr(sub(den, num), 15); - num = shl(num, scale); - expn = sub(expn, scale); - - tmp = div_s(num, den); - expn = sub(expn, expd); - gain_tmp = shl(tmp, sub(expn,1));/*Q14 */ - } - test(); - IF (sub(st_fx->prev_mode_fx,TRANSIENT) == 0) - { - numharmonic = shl(numharmonic, 1); - } - ELSE IF (sub(st_fx->prev_mode_fx, NORMAL) == 0 || sub(st_fx->prev_mode_fx, NOISE) == 0) - { - numharmonic = add(shr(numharmonic, 1), numharmonic); - } - } - ELSE - { - gain_tmp = 16384; - move16(); - IF (sub(st_fx->prev_mode_fx, HARMONIC) == 0) - { - numharmonic = shr(numharmonic, 1); - sharplimit = shr(sharplimit, 1); - } - ELSE - { - numharmonic = shl(numharmonic, 1); - sharplimit = shl(sharplimit, 1); - } - } - } - ELSE IF (sub(st_fx->extl_fx, WB_BWE) == 0) - { - input_hi = &fSpectrum[224]; - move16(); - numsharp = 3; - move16(); - - IF (sub(st_fx->prev_mode_fx, HARMONIC) == 0) - { - numharmonic = shr(numharmonic, 2); - } - ELSE - { - numharmonic = shr(numharmonic, 1); - } - IF (sub(st_fx->last_extl_fx, WB_BWE) != 0) - { - IF (sub(st_fx->prev_mode_fx, HARMONIC) == 0) - { - sharplimit = shr(sharplimit, 1); - } - ELSE - { - sharplimit = shl(sharplimit, 1); - } - } - } - - L_meanH = L_deposit_l(0); - FOR(i = 0; i < numsharp; i ++) - { - peak = 0; - move16(); - mean[i] = L_deposit_l(0); - - FOR(j = 0; j < SHARP_WIDTH; j ++) - { - mag = abs_s(*input_hi); - IF (sub(mag, peak) > 0) - { - peak = mag; - move16();/*Q_syn */ - } - mean[i] = L_add(mean[i], mag); - move32();/*Q_syn */ - input_hi ++; - } - - L_meanH = L_add(L_meanH, mean[i]);/*Q_syn */ - - IF(L_sub(mean[i], L_deposit_l(peak)) != 0) - { - L_tmp = L_sub(mean[i], peak);/*Q_syn */ - L_tmp = Mult_32_16(L_tmp, 16913); /* 1/31->Q19 -> Q_syn+19-15 */ - den = extract_l(L_shr(L_tmp, 4)); /*Q_syn */ - IF(den == 0) - { - den = 1; - move16(); - } - expd = norm_s(den); - tmp = div_s(shl(1,sub(14,expd)), den); /*Q(29-expd-Q_syn) */ - L_tmp = L_mult(tmp, peak); /*Q(30-expd) */ - sharp = round_fx(L_shl(L_tmp, sub(expd, 4)));/*Q10 */ - } - ELSE - { - sharp = 0; - move16(); - } - - test(); - IF (sub(sharp, 4608) > 0 && sub(peak, shl(1, add(Q_syn, 3))) > 0) - { - k = add(k, 1); - move16(); - } - ELSE IF (sub(sharp, 3072) < 0) - { - noise = add(noise, 1); - move16(); - } - - IF (sub(sharp, sharpPeak) > 0) - { - sharpPeak = sharp; - move16(); - } - } - test(); - IF ( sub(st_fx->extl_fx, SWB_BWE) == 0 || sub(st_fx->extl_fx, FB_BWE) == 0 ) - { - test(); - test(); - test(); - IF(sub(k, numharmonic) >= 0 && sub(gain_tmp, 8192) > 0 && sub(gain_tmp, 29491) < 0 && sub(sharpPeak, shl(sharplimit, 10)) > 0) - { - sharpMod = 1; - move16(); - } - ELSE - { - sharpMod = 0; - move16(); - } - - L_meanH = Mult_32_16(L_meanH, 29127); /*Q_syn+8 */ - L_mean_d = 0; - move16(); - FOR(i=0; iextl_fx, WB_BWE) == 0) - { - test(); - IF (sub(k,numharmonic) >= 0 && sub(sharpPeak,shl(sharplimit, 10)) > 0) - { - sharpMod = 1; - move16(); - } - ELSE - { - sharpMod = 0; - move16(); - } - } - - test(); - test(); - IF (sharpMod && sub(st_fx->modeCount_fx, 12) < 0) - { - st_fx->modeCount_fx = add(st_fx->modeCount_fx, 1); - } - ELSE IF (sharpMod == 0 && st_fx->modeCount_fx > 0) - { - st_fx->modeCount_fx = sub(st_fx->modeCount_fx, 1); - } - - IF (sub(st_fx->modeCount_fx, 2) >= 0) - { - sharpMod = 1; - move16(); - } - - test(); - IF (sharpMod) - { - mode = HARMONIC; - move16(); - } - ELSE IF ( sub(st_fx->extl_fx, SWB_BWE) == 0 || sub(st_fx->extl_fx, FB_BWE) == 0 ) - { - L_tmp = Mult_32_16(L_mean_d, 6827); /*Q_syn+8 ; 1/4.8 in Q15 */ - - test(); - test(); - test(); - IF (sub(noise, 4) > 0 && (L_sub(L_tmp, L_meanH) < 0 || L_meanH == 0) && sub(tilt_nb, 10240) < 0) - { - mode = NOISE; - move16(); - } - } - - return (mode); -} -/*-------------------------------------------------------------------* -* freq_weights_fx() -* -*-------------------------------------------------------------------*/ -static void freq_weights_fx( - const Word16 Band_Ener[], /* i : Band energy Q8 */ - const Word16 f_weighting[], /* i : weigting coefs. Q15 */ - Word16 w_env[], /* o : Freq. weighting Q13 */ - const Word16 Nbands /* i : Number of bands */ -) -{ - Word16 i; - Word16 tmp, tmp1, w1[SWB_FENV], w2[SWB_FENV]; - Word16 min_b, max_b; - Word32 L_tmp; - Word16 exp; - - /* Find Max band energy */ - min_b = Band_Ener[0]; - move16(); - max_b = Band_Ener[0]; - move16(); - FOR( i=1; i 0 ) - { - max_b = Band_Ener[i]; - move16();/*Q8 */ - } - } - - /* Find weighting function */ - tmp = sub(max_b, min_b);/*Q8 */ - IF(tmp != 0) - { - exp = norm_s(tmp); - tmp = div_s(shl(1,sub(14,exp)), tmp); /*(21-exp) */ - tmp = shl(tmp, sub(exp, 6)); /*Q15 */ - } - ELSE - { - tmp = 32767; - move16(); - } - - FOR( i=0; i k; l-- ) - { - dist_min[l] = dist_min[l - 1]; - move32(); - index[l] = index[l - 1]; - move16(); - } - dist_min[k] = L_dist; - move32(); - index[k] = i; - move16(); - BREAK; - } - } - } - } - ELSE - { - set32_fx( dist_min, MAX_32, surv ); /* FLT_MAX */ - - FOR (i = 0; i < surv; i++) - { - index[i] = i; - move16(); - } - - p_E_ROM_dico = E_ROM_dico; - move16(); - - FOR( i = 0; i < E_ROM_dico_size; i++ ) - { - dist = sub(x[0],*p_E_ROM_dico++);/*Q8 */ - L_dist = L_mult(dist,dist);/*Q17 */ - L_dist = L_shr(L_dist,12);/*Q5 */ - - FOR( j = 1; j < dim; j++ ) - { - temp1 = sub(x[j],*p_E_ROM_dico++);/*Q8 */ - L_tmp = L_mult(temp1,temp1);/*Q17 */ - L_dist = L_add(L_dist,L_shr(L_tmp,12));/*Q5 */ - } - - FOR( k = 0; k < surv; k++ ) - { - IF( L_sub(L_dist,dist_min[k]) < 0 ) - { - FOR( l = surv - 1; l > k; l-- ) - { - dist_min[l] = dist_min[l-1]; - move32(); - index[l] = index[l-1]; - move16(); - } - dist_min[k] = L_dist; - move32(); - index[k] = i; - move16(); - BREAK; - } - } - } - } - - return; -} - -/*-------------------------------------------------------------------* -* vqSimple_w_fx() -* -*-------------------------------------------------------------------*/ - -static Word16 vqSimple_w_fx( - const Word16 *x, /* i : input for quantizer Q8 */ - Word16 *y, /* i : quantized value Q8 */ - const Word16 *cb, /* i : codebooks Q8 */ - const Word16 *w, /* i : weight Q13 */ - const Word16 dim, /* i : dimension */ - const Word16 l, /* i : number of candidates */ - const Word16 flag /* i : flag indicationg weighted distortion metric */ -) -{ - Word16 i, j, index; - const Word16 *cbP; - Word16 dist, temp; - Word32 L_dist,L_tmp,L_dist_min; - - index = 0; - move16(); - L_dist_min = L_add(MAX_32, 0); /* FLT_MAX */ - cbP = cb; - move16(); - IF( flag ) - { - FOR( i = 0; i < l; i++ ) - { - /*dist = x[0] - *cbP++; */ - /*dist *= (dist * w[0]); */ - dist = sub(x[0],*cbP++);/*Q8 */ - L_dist = L_mult(dist,w[0]);/*Q22 */ - L_dist = Mult_32_16(L_dist,dist);/*Q15 */ - L_dist = L_shr(L_dist,10);/*Q5 */ - - FOR( j = 1; j < dim; j++ ) - { - /*temp = x[j] - *cbP++; */ - /*dist += temp * temp * w[j]; */ - temp = sub(x[j],*cbP++); - L_tmp = L_mult(temp,w[j]);/*Q22 */ - L_tmp = Mult_32_16(L_tmp,temp);/*Q15 */ - L_dist = L_add(L_dist,L_shr(L_tmp,10));/*Q5 */ - } - IF (L_sub(L_dist, L_dist_min) < 0) - { - L_dist_min = L_add(L_dist, 0);/*Q5 */ - index = i; - move16(); - } - } - } - ELSE - { - FOR( i = 0; i < l; i++ ) - { - /*dist = x[0] - *cbP++; */ - dist = sub(x[0],*cbP++); - /*dist *= dist; */ - L_dist = L_mult(dist,dist);/*Q17 */ - L_dist = L_shr(L_dist,12); - - FOR( j = 1; j < dim; j++ ) - { - /*temp = x[j] - *cbP++; */ - temp = sub(x[j] , *cbP++); - /*dist += temp * temp; */ - L_tmp = L_mult(temp,temp);/*Q17 */ - L_dist = L_add(L_dist,L_shr(L_tmp,12));/*Q5 */ - } - IF (L_sub(L_dist, L_dist_min) < 0) - { - L_dist_min = L_add(L_dist, 0); - index = i; - move16(); - } - } - } - - - /* Reading the selected vector */ - Copy( &cb[index * dim], y, dim ); - - return(index); -} - - - -/*-------------------------------------------------------------------* -* MSVQ_Interpol_Tran_fx() -* -*-------------------------------------------------------------------*/ -static void MSVQ_Interpol_Tran_fx( - Word16 *SWB_env_energy, /* i/o : (original/quantized) energy Q8 */ - Word16 *indice /* o : quantized index */ -) - -{ - Word16 k, n_band, candInd[N_CAND_TR], ind_tmp[2],tmp; - Word16 env_temp11[SWB_FENV_TRANS/2], env_temp12[SWB_FENV_TRANS/2]; - Word16 tmp_q; - Word16 quant_tmp[SWB_FENV_TRANS], quant_tmp2[SWB_FENV_TRANS]; - Word16 quant_select[SWB_FENV_TRANS]; - Word32 L_tmp, L_dist, L_minDist,distCand[N_CAND_TR]; - - /* Extract target vector */ - FOR( n_band = 0; n_band < DIM_TR1; n_band++ ) - { - env_temp11[n_band] = SWB_env_energy[2*n_band]; - move16();/*Q8 */ - env_temp12[n_band] = SWB_env_energy[2*n_band+1]; - move16();/*Q8 */ - } - - vqWithCand_w_fx( env_temp11, Env_TR_Cdbk1_fx, DIM_TR1, N_CB_TR1, candInd, N_CAND_TR, distCand, NULL, 0 ); - - L_minDist = L_add(MAX_32, 0); /* FLT_MAX */ - - FOR( k=0; ktotal_brate_fx,ACELP_8k85)<0 ) - { - core_type = 0; - move16(); - } - ELSE - { - core_type = 1; - move16(); - } - get_normalize_spec_fx(core, st_fx->extl_fx, mode, core_type, org_fx, SWB_signal_fx, &(st_fx->prev_L_swb_norm1_fx), offset, Q_new_lf); - - IF ( sub(st_fx->extl_fx,WB_BWE) == 0) - { - max_band = 4; - move16(); - band_step = 2; - move16(); - } - ELSE - { - max_band = SWB_FENV; - move16(); - band_step = 1; - move16(); - } - } - ELSE /* HQ core */ - { - gamma_fx = 18022; - move16();/*.55 in Q15 */ - get_normalize_spec_fx(core, st_fx->extl_fx, mode, -1, org_fx, SWB_signal_fx, &(st_fx->prev_L_swb_norm1_fx), offset, Q_new_lf); - - band_step = 1; - move16(); - IF ( sub(offset,HQ_GENERIC_FOFFSET_32K) == 0 ) - { - max_band = 12; - move16(); - } - ELSE - { - max_band = SWB_FENV; - move16(); - } - } - - FOR( n_band=0; n_bandL_frame_fx, L_FRAME ) == 0) - { - L = L_SUBFR; - move16(); - } - ELSE - { - L = L_SUBFR16k; - move16(); - } - - /* HF transient detect */ - IsTransient = detect_transient_fx( insig_hp_fx, L_FRAME16k, coder_type, Q_shb, st_fx); - st_fx->EnergyLT_fx_exp = shl(Q_shb, 1); - - /* LF transient detect */ - IsTransient_LF = 0; - move16(); - FOR ( n_band = 0; n_band < 4; n_band++ ) - { - tmp = i_mult2(n_band, L); - energy_fx = L_deposit_l(0); - FOR(i=0; iEnergyLF_fx) > 0) - { - IsTransient_LF = 1; - move16(); - } - - st_fx->EnergyLF_fx = energy_fx; - move32(); - } - - /* tilt returned in Q24 go to Q11 */ - tilt_fx = round_fx(L_shl(calc_tilt_bwe_fx(insig_fx, 0, L_FRAME32k), 3)); - - test(); - test(); - IF( sub(IsTransient,1) == 0 && (sub(tilt_fx, 16384) > 0 || sub(st_fx->clas_fx,1) > 0) ) - { - IsTransient = 0; - move16(); - st_fx->TransientHangOver_fx = 0; - move16(); - } - - IF( sub(IsTransient,1) == 0 ) - { - mode = IsTransient; - move16(); - push_indice_fx(st_fx, IND_SWB_CLASS, mode, 2 ); - - /* Energy for the different bands and global energies */ - global_gain_fx = L_deposit_l(0); - FOR (n_band = 0; n_band < SWB_FENV_TRANS; n_band++) - { - energy_fx = L_deposit_l(0); - FOR (n_coeff = swb_bwe_trans_subband_fx[n_band]+st_offset; n_coeff < swb_bwe_trans_subband_fx[n_band+1]+st_offset; n_coeff++) - { - L_tmp = L_shr(L_mult0(yos_fx[n_coeff], yos_fx[n_coeff]), 7); /*2*Q_synth-7 */ - energy_fx = L_add(L_tmp, energy_fx); /*2*Q_synth-7 */ - } - global_gain_fx = L_add(global_gain_fx, L_shr(energy_fx, sub(sub(shl(Q_synth,1),7), shl(Q_shb,1)))); /*2*Q_shb */ - L_SWB_fenv_fx[n_band] = energy_fx; - move32(); - } - global_gain_fx = L_shr(global_gain_fx, 1); /*2*Q_shb */ - - FOR (n_band = 0; n_band < SWB_FENV_TRANS; n_band++) - { - expd = norm_s(swb_bwe_trans_subband_width_fx[n_band]); - tmp = div_s(shl(1,sub(14,expd)), swb_bwe_trans_subband_width_fx[n_band]);/*Q(29-expd) */ - L_tmp = Mult_32_16(L_SWB_fenv_fx[n_band], tmp); /*2*Q_synth-7+29-expd - 15 */ - exp = norm_l(L_tmp); - tmp = Log2_norm_lc(L_shl(L_tmp, exp)); - move16(); - exp = sub(sub(30, exp), sub(add(shl(Q_synth,1),7),expd)); - L_tmp = Mpy_32_16(exp, tmp, 24660); /* Q14 */ /*10log10(2) in Q13 */ - tmp = round_fx(L_shl(L_tmp, 10)); /* Q8 */ - - SWB_fenv_fx[n_band] = sub(tmp, Mean_env_tr_fx[n_band]); - move16();/*Q8 */ - } - - WB_tenv_orig_fx = L_deposit_l(0); - WB_tenv_syn_fx = L_deposit_l(1); - FOR(n_band = 0; n_band < SWB_TENV; n_band++) - { - tmp = i_mult2(n_band, L_SUBFR16k); - L_SWB_tenv = L_deposit_l(0); - FOR(i = 0; i < L_SUBFR16k; i++) - { - L_SWB_tenv = L_add(L_SWB_tenv, L_mult0(insig_hp_fx[i + tmp], insig_hp_fx[i + tmp])); /*2*Q_shb */ - } - - tmp = i_mult2(n_band, L); - FOR(i=0; iQ_syn2 - 7 */ - WB_tenv_orig_fx = L_add(WB_tenv_orig_fx, L_shr(L_mult0(insig_lp_fx[i + tmp], insig_lp_fx[i + tmp]), 7)); /*2*Q_insig_lp - 7 */ - } - - L_tmp = Mult_32_16(L_SWB_tenv, INV_L_SUBFR16k_FX);/*2*Q_shb */ - SWB_tenv_fx[n_band] = 0; - move16(); - IF(L_tmp != 0) - { - exp = norm_l(L_tmp); - tmp = extract_h(L_shl(L_tmp, exp)); - exp = sub(exp, sub(30, 2*Q_shb)); - - tmp = div_s(16384, tmp); - L_tmp = L_deposit_h(tmp); - L_tmp = Isqrt_lc(L_tmp, &exp); /*Q(31-exp) */ - - SWB_tenv_fx[n_band] = round_fx(L_shl(L_tmp, sub(exp, 12))); /*Q3 */ - } - } - - IF(WB_tenv_orig_fx != 0) - { - expn = norm_l(WB_tenv_orig_fx); - num = extract_h(L_shl(WB_tenv_orig_fx, expn)); - expn = sub(sub(30, expn), sub(shl(Q_insig_lp,1),7)); - - expd = norm_l(WB_tenv_syn_fx); - den = round_fx(L_shl(WB_tenv_syn_fx, expd)); - expd = sub(sub(30, expd), sub(shl(st_fx->Q_syn2, 1), 7)); - - scale = shr(sub(den, num), 15); - num = shl(num, scale); - expn = sub(expn, scale); - - tmp = div_s(num, den); - expn = sub(expn, expd); - - L_tmp = L_deposit_h(tmp); - L_tmp = Isqrt_lc(L_tmp, &expn); /*31-expn */ - - Rat_tenv_fx = round_fx(L_shl(L_tmp, sub(expn, 1)));/*Q14 */ - } - ELSE - { - Rat_tenv_fx = 16384; - move16(); - } - - IF(sub(Rat_tenv_fx, 8192) < 0) - { - L_tmp = L_mult(Rat_tenv_fx, 19661);/*Q29 */ - Rat_tenv_fx = round_fx(L_shl(L_tmp, 2));/*Q15 */ - } - ELSE IF (sub(Rat_tenv_fx, 16384)> 0) - { - Rat_tenv_fx = 32767; - move16(); - } - - FOR(n_band = 0; n_band < SWB_TENV; n_band++) - { - SWB_tenv_fx[n_band] = mult_r(SWB_tenv_fx[n_band], Rat_tenv_fx); - move16();/*Q3 */ - } - - max_fx = SWB_tenv_fx[0]; - move16(); - pos = 0; - move16(); - FOR(n_band = 1; n_band < SWB_TENV; n_band++) - { - IF(sub(SWB_tenv_fx[n_band],max_fx) > 0) - { - max_fx = SWB_tenv_fx[n_band]; - move16(); - pos = n_band; - move16(); - } - } - - max_fx = SWB_tenv_fx[0]; - move16(); - FOR(n_band = 1; n_band < SWB_TENV; n_band++) - { - tmp = sub(mult_r(SWB_tenv_fx[n_band], 6554), SWB_tenv_fx[n_band-1]); - IF(tmp > 0) - { - BREAK; - } - } - - IF(n_band < SWB_TENV) - { - energy_fx = L_deposit_l(0); - FOR(n_band = (pos+1); n_band < SWB_TENV; n_band++) - { - energy_fx = L_add(energy_fx, SWB_tenv_fx[n_band]);/*Q3 */ - } - - IF(pos == sub(SWB_TENV, 1)) - { - energy_fx = L_deposit_l(0); - } - ELSE - { - tmp = sub(SWB_TENV, pos+1); - tmp = div_s(1, tmp); /*Q15 */ - energy_fx = Mult_32_16(energy_fx, tmp);/*Q3 */ - } - - FOR(n_band = 0; n_band < pos; n_band++) - { - SWB_tenv_fx[n_band] = mult_r(SWB_tenv_fx[n_band], 16384); - move16(); - } - - /*SWB_tenv_fx[pos] = add(SWB_tenv_fx[pos], mult_r(SWB_tenv_fx[pos], 164)); move16();//Q3 */ - SWB_tenv_fx[pos] = round_fx(L_mac(L_mult(SWB_tenv_fx[pos],32767), SWB_tenv_fx[pos], 164)); /*Q3 */ - - IF(L_sub(energy_fx, SWB_tenv_fx[pos]) < 0) - { - FOR(n_band = pos+1; n_band < SWB_TENV; n_band++) - { - SWB_tenv_fx[n_band] = mult_r(SWB_tenv_fx[n_band], 29491); - move16();/*Q3 */ - } - } - } - ELSE - { - FOR(n_band = 1; n_band < SWB_TENV; n_band++) - { - IF(sub(SWB_tenv_fx[n_band-1], SWB_tenv_fx[n_band]) > 0) - { - /*SWB_tenv_fx[n_band-1] = add(mult_r(SWB_tenv_fx[n_band-1], 16384), mult_r(SWB_tenv_fx[n_band], 16384)); move16();//Q3 */ - SWB_tenv_fx[n_band-1] = round_fx(L_mac(L_mult(SWB_tenv_fx[n_band-1], 16384), SWB_tenv_fx[n_band], 16384)); /*Q3 */ - } - ELSE - { - /*SWB_tenv_fx[n_band] = add(mult_r(SWB_tenv_fx[n_band-1], 16384), mult_r(SWB_tenv_fx[n_band], 16384)); move16();//Q3 */ - SWB_tenv_fx[n_band] = round_fx(L_mac(L_mult(SWB_tenv_fx[n_band-1], 16384), SWB_tenv_fx[n_band], 16384)); /*Q3 */ - } - } - - FOR(n_band = 0; n_band < SWB_TENV; n_band++) - { - SWB_tenv_fx[n_band] = mult_r(SWB_tenv_fx[n_band], 29491); - move16();/*Q3 */ - } - } - - test(); - test(); - IF(IsTransient_LF == 0 && sub(coder_type,INACTIVE) == 0 && sub(st_fx->TransientHangOver_fx,1) == 0) - { - FOR(n_band = 0; n_band < SWB_TENV; n_band++) - { - SWB_tenv_fx[n_band] = mult_r(SWB_tenv_fx[n_band], 16384); - move16(); - } - FOR(n_band = 0; n_band < SWB_FENV_TRANS; n_band++) - { - SWB_fenv_fx[n_band] = mult_r(SWB_fenv_fx[n_band], 1638); - move16(); - } - } - ELSE - { - SWB_fenv_fx[2] = mult_r(SWB_fenv_fx[2], 3277); - move16(); - SWB_fenv_fx[3] = mult_r(SWB_fenv_fx[3], 1638); - move16(); - } - - FOR(n_band = 0; n_band < SWB_TENV; n_band++) - { - IF(SWB_tenv_fx[n_band] == 0) - { - SWB_tenv_tmp_fx[n_band] = -32768; - move16(); /*-16 in Q11 */ - } - ELSE - { - L_tmp = L_deposit_h(SWB_tenv_fx[n_band]); /*Q19 */ - expn = norm_l(L_tmp); - tmp = Log2_norm_lc(L_shl(L_tmp, expn)); - expn = sub(sub(30, expn), 19); - L_tmp = Mpy_32_16(expn, tmp, 32767); /* Q16 */ /*1 in Q15 */ - SWB_tenv_tmp_fx[n_band] = round_fx(L_shl(L_tmp, 11)); /* Q11 */ - } - - IF (sub(SWB_tenv_tmp_fx[n_band], 30720) > 0) - { - index = 15; - move16(); - } - ELSE IF (SWB_tenv_tmp_fx[n_band] < 0) - { - index = 0; - move16(); - } - ELSE - { - index = shr(add(SWB_tenv_tmp_fx[n_band], 1024), 11); - } - - push_indice_fx(st_fx, IND_SWB_TENV, index, 4 ); - } - - MSVQ_Interpol_Tran_fx(SWB_fenv_fx, indice); - - push_indice_fx(st_fx, IND_SWB_FENV, indice[0], 7 ); - push_indice_fx(st_fx, IND_SWB_FENV, indice[1], 6 ); - } - ELSE - { - /* Energy for the different bands and global energies */ - global_gain_fx = L_deposit_l(0); - FOR (n_band = 0; n_band < SWB_FENV; n_band++) - { - energy_fx = L_deposit_l(0); - FOR (n_coeff = swb_bwe_subband_fx[n_band]+st_offset; n_coeff < swb_bwe_subband_fx[n_band+1]+st_offset; n_coeff++) - { - L_tmp = L_shr(L_mult0(yos_fx[n_coeff], yos_fx[n_coeff]), 5); /*2*Q_synth-5 */ - energy_fx = L_add(L_tmp, energy_fx); /*2*Q_synth-5 */ - } - - IF (sub(n_band, sub(SWB_FENV,2)) < 0) - { - global_gain_fx = L_add(global_gain_fx, L_shr(energy_fx, sub(2*Q_synth-5, 2*Q_shb))); /*2*Q_shb */ - } - L_SWB_fenv_fx[n_band] = energy_fx; - move32(); - } - - global_gain_fx = L_shr(global_gain_fx, 1); /*2*Q_shb */ - mode = FD_BWE_class_fx(yos_fx, global_gain_fx, tilt_nb_fx, Q_synth, Q_shb, st_fx); - push_indice_fx(st_fx, IND_SWB_CLASS, mode, 2 ); - - energy_control_fx( st_fx, ACELP_CORE, mode, -1, yos_fx, st_offset, energy_factor_fx, Q_synth_lf ); - - FOR (n_band = 0; n_band < SWB_FENV; n_band++) - { - L_tmp = Mult_32_16(L_SWB_fenv_fx[n_band],energy_factor_fx[n_band]);/*2*Q_synth-5 */ - L_tmp = Mult_32_16(L_tmp,swb_inv_bwe_subband_width_fx[n_band]);/*2*Q_synth-5 */ - - IF(L_tmp != 0) - { - expn = norm_l(L_tmp); - tmp = Log2_norm_lc(L_shl(L_tmp,expn)); - expn = sub(30,add(expn,sub(shl(Q_synth,1),5))); - L_tmp = Mpy_32_16(expn, tmp, 24660); /* Q14 */ /*10log10(2) in Q13 */ - SWB_fenv_fx[n_band] = round_fx(L_shl(L_tmp, 10)); /* Q8 */ - } - ELSE - { - SWB_fenv_fx[n_band] = -24576; - move16(); - } - } - freq_weights_fx(SWB_fenv_fx, w_NOR_fx, w_env_fx, SWB_FENV); - - FOR (n_band = 0; n_band < SWB_FENV; n_band++) - { - SWB_fenv_fx[n_band] = sub(SWB_fenv_fx[n_band] , Mean_env_fx[n_band]); - move16(); - } - - /* Energy VQ */ - msvq_interpol_fx(SWB_fenv_fx, w_env_fx, indice); - - push_indice_fx(st_fx, IND_SWB_FENV, indice[0], 5 ); - push_indice_fx(st_fx, IND_SWB_FENV, indice[1], 7 ); - push_indice_fx(st_fx, IND_SWB_FENV, indice[2], 6 ); - push_indice_fx(st_fx, IND_SWB_FENV, indice[3], 5 ); - push_indice_fx(st_fx, IND_SWB_FENV, indice[4], 6 ); - - } - st_fx->prev_mode_fx = mode; - move16(); - st_fx->prev_global_gain_fx = global_gain_fx; - move32(); - st_fx->prev_Q_shb = Q_shb; - move16(); - - return mode; -} - -/*-------------------------------------------------------------------* - * get_normalize_spec_fx_32() - * - *-------------------------------------------------------------------*/ - -static void get_normalize_spec_fx_32( - const Word16 core, /* i : core selected : Q0 */ - const Word16 extl, /* i : extension layer selected: Q0 */ - const Word16 mode, /* i : SHB BWE class : Q0 */ - const Word16 core_type, /* i : coding type : Q0 */ - const Word32 *org_fx, /* i : input spectrum : Q12 */ - Word32 *SWB_signal_fx, /* o : output spectrum : Q20 */ - Word16 *prev_L_swb_norm, /* i : previous norm. len : Q0 */ - const Word16 offset /* i : frequency offset : Q0 */ -) -{ - Word16 n_freq, L_swb_norm; - Word16 frq_end; - Word16 exp1, exp2, tmp; - Word32 L_tmp; - Word32 envelope_fx[L_FRAME32k]; - - set32_fx(SWB_signal_fx, 0, HQ_GENERIC_HIGH0+offset); - calc_normal_length_fx_32(core, org_fx, mode, extl, &L_swb_norm, prev_L_swb_norm); - test(); - IF(sub(extl , SWB_BWE) == 0 || sub( extl , FB_BWE) == 0 ) - { - IF ( sub(mode ,HARMONIC) == 0 ) - { - Copy32(org_fx, &SWB_signal_fx[add(240,offset)], 240); - Copy32(&org_fx[128], &SWB_signal_fx[add(480,offset)], 80); - } - ELSE - { - Copy32( &org_fx[112], &SWB_signal_fx[add(240,offset)], 128 ); - Copy32( &org_fx[112], &SWB_signal_fx[add(368,offset)], 128 ); - Copy32( &org_fx[176], &SWB_signal_fx[add(496,offset)], 64 ); - } - frq_end = 560+offset; - move16(); - } - ELSE IF (sub(extl , WB_BWE)==0) - { - IF ( core_type == 0 ) - { - Copy32(&org_fx[160], &SWB_signal_fx[240], 80); - } - ELSE - { - Copy32(&org_fx[80], &SWB_signal_fx[240], 80); - } - frq_end = L_FRAME16k; - move16(); - } - ELSE - { - Copy32( org_fx+HQ_GENERIC_OFFSET, SWB_signal_fx+HQ_GENERIC_HIGH0+offset, HQ_GENERIC_LEN0 ); - Copy32( org_fx+HQ_GENERIC_OFFSET, SWB_signal_fx+HQ_GENERIC_HIGH1+offset, HQ_GENERIC_LEN0 ); - IF ( sub(offset , HQ_GENERIC_FOFFSET_24K4) == 0 ) - { - Copy32( org_fx+HQ_GENERIC_LOW0, SWB_signal_fx+HQ_GENERIC_HIGH2+offset, HQ_GENERIC_END_FREQ-HQ_GENERIC_HIGH2 ); - } - frq_end = L_FRAME32k; - move16(); - } - - /* calculate envelope */ - calc_norm_envelop_fx_32(SWB_signal_fx, envelope_fx, L_swb_norm, frq_end - offset, offset); - - /* Normalize with envelope */ - FOR ( n_freq = add(swb_bwe_subband_fx[0],offset); n_freqtotal_brate_fx , ACELP_8k00)<=0 ) - { - core_type = 0; - move16(); - } - ELSE - { - core_type = 1; - move16(); - } - - get_normalize_spec_fx_32(core, st_fx->extl_fx, mode, core_type, org_fx, SWB_signal_fx, &(st_fx->prev_L_swb_norm1_fx), offset ); - - IF ( sub(st_fx->extl_fx , WB_BWE) == 0) - { - max_band = 4; - move16(); - band_step = 2; - move16(); - } - } - ELSE /* HQ core */ - { - gamma_fx = 18021; - move16(); - get_normalize_spec_fx_32(core, -1, mode, -1, org_fx, SWB_signal_fx, &(st_fx->prev_L_swb_norm1_fx), offset ); - - IF ( sub(offset , HQ_GENERIC_FOFFSET_32K) == 0 ) - { - max_band = 12; - move16(); - } - } - - FOR ( n_band=0; n_band 0) - { - p_fx = L_add(L_tmp, 0);/*6 */ - } - a_fx = L_add(a_fx, L_tmp);/*6 */ - } - - IF (a_fx > 0) - { - a_fx = Mult_32_16(a_fx, swb_inv_bwe_subband_width_fx[k]);/*6 */ - - exp = norm_l(p_fx); - tmp = Log2_norm_lc(L_shl(p_fx, exp));/*15 */ - exp = sub(30, add(exp, 6)); - L_tmp1 = L_add(L_deposit_h(exp), L_shr(L_deposit_h(tmp), 15));/*16 */ - - exp = norm_l(a_fx); - tmp = Log2_norm_lc(L_shl(a_fx, exp)); - exp = sub(30, add(exp, 6)); - L_tmp2 = L_add(L_deposit_h(exp), L_shr(L_deposit_h(tmp), 15));/*16 */ - - p2a_fx = L_sub(L_tmp1, L_tmp2);/*16 */ - avgp2a_fx = L_add(avgp2a_fx, p2a_fx);/*16 */ - } - } - avgp2a_fx = Mult_32_16(avgp2a_fx, inv_band_fx);/*16 + 15 - 15 */ - IF (L_sub(avgp2a_fx , 187227)>0)/*8.6 / 10log10(2), Q16 */ - { - return HQ_GENERIC_EXC1; - } - ELSE - { - return HQ_GENERIC_EXC0; - } -} - -/*-------------------------------------------------------------------* - * hq_generic_encoding_fx() - * - *-------------------------------------------------------------------*/ -void hq_generic_encoding_fx( - const Word32 *coefs_fx, /* i : MDCT coefficients of weighted original : Q12 */ - Word16 *hq_generic_fenv_fx, /* i/o: energy of SWB envelope : Q3 */ - const Word16 hq_generic_offset, /* i : frequency offset for extracting energy : Q0 */ - Encoder_State_fx *st_fx, /* i/o: encoder state structure */ - Word16 *hq_generic_exc_clas /* o : bwe excitation class : Q0 */ -) -{ - Word16 n_coeff, n_band; - Word16 indice[HQ_GENERIC_NVQIDX]; - Word16 nenv; - - Word16 energy_factor_fx[SWB_FENV] = {0}; - Word16 cs, exp, tmp, tmp2; - Word32 energy_fx; - Word32 L_tmp, max_coefs_fx; - Word16 w_env_fx[SWB_FENV]; - - IF ( sub(hq_generic_offset , HQ_GENERIC_FOFFSET_24K4)<=0 ) - { - nenv = SWB_FENV; - move16(); - } - ELSE - { - nenv = SWB_FENV-2; - move16(); - } - - - energy_control_fx_32(st_fx, HQ_CORE, -1, -1, coefs_fx, hq_generic_offset, energy_factor_fx); - - IF ( sub(st_fx->hq_generic_speech_class_fx , 1) == 0 ) - { - push_indice_fx( st_fx, IND_HQ_SWB_EXC_SP_CLAS, 1, 1 ); - *hq_generic_exc_clas = HQ_GENERIC_SP_EXC; - move16(); - } - ELSE - { - *hq_generic_exc_clas = decision_hq_generic_class_fx_32(coefs_fx, hq_generic_offset); - push_indice_fx( st_fx, IND_HQ_SWB_EXC_SP_CLAS, 0, 1 ); - push_indice_fx( st_fx, IND_HQ_SWB_EXC_CLAS, *hq_generic_exc_clas, 1 ); - } - - FOR ( n_band = 0; n_band < nenv; n_band++ ) - { - energy_fx = L_deposit_l(0); - max_coefs_fx = L_deposit_l(0); - tmp2 = add(swb_bwe_subband_fx[n_band+1] , hq_generic_offset); - FOR ( n_coeff = add(swb_bwe_subband_fx[n_band],hq_generic_offset); n_coeff < tmp2; n_coeff++ ) - { - IF (L_sub(max_coefs_fx , L_abs(coefs_fx[n_coeff])) < 0) - { - max_coefs_fx = L_abs(coefs_fx[n_coeff]); - } - } - cs = norm_l(max_coefs_fx); - tmp2 = add(swb_bwe_subband_fx[n_band+1] , hq_generic_offset); - FOR ( n_coeff = add(swb_bwe_subband_fx[n_band],hq_generic_offset); n_coeff < tmp2; n_coeff++ ) - { - tmp = extract_h(L_shl(coefs_fx[n_coeff], cs));/*12 + cs - 16 */ - L_tmp = L_mult0(tmp, tmp);/*2*cs - 8 */ - energy_fx = L_add(energy_fx, L_shr(L_tmp, 5)); - } - - IF (energy_fx != 0) - { - L_tmp = Mult_32_16(energy_fx, energy_factor_fx[n_band]);/*2*cs - 13 */ - L_tmp = Mult_32_16(L_tmp, swb_inv_bwe_subband_width_fx[n_band]);/*2*cs - 13 + 15 - 15 */ - - exp = norm_l(L_tmp); - tmp = Log2_norm_lc(L_shl(L_tmp, exp)); - exp = sub(30, add(exp, 2*cs-13)); - - L_tmp = Mpy_32_16(exp, tmp, 24660); /* Q14 */ /*10log10(2) in Q13 */ - hq_generic_fenv_fx[n_band] = round_fx(L_shl(L_tmp, 10));/*Q8 */ - } - ELSE - { - hq_generic_fenv_fx[n_band] = -24576; - move16(); - } - } - - IF ( sub(st_fx->bwidth_fx , FB) == 0 ) - { - FOR ( n_band = 0; n_band < DIM_FB; n_band++ ) - { - energy_fx = L_deposit_l(0); - max_coefs_fx = L_deposit_l(0); - tmp2 = fb_bwe_subband[add(n_band,1)]; - FOR ( n_coeff = fb_bwe_subband[n_band]; n_coeff < tmp2; n_coeff++ ) - { - IF (L_sub(max_coefs_fx, L_abs(coefs_fx[n_coeff])) < 0) - { - max_coefs_fx = L_abs(coefs_fx[n_coeff]); - } - } - cs = norm_l(max_coefs_fx); - tmp2 = fb_bwe_subband[add(n_band,1)]; - FOR ( n_coeff = fb_bwe_subband[n_band]; n_coeff < tmp2; n_coeff++ ) - { - tmp = extract_h(L_shl(coefs_fx[n_coeff], cs));/*12 + cs - 16 */ - L_tmp = L_mult0(tmp, tmp);/*2*cs - 8 */ - energy_fx = L_add(energy_fx, L_shr(L_tmp, 5)); - } - - IF (energy_fx != 0) - { - L_tmp = Mult_32_16(energy_fx, fb_inv_bwe_subband_width_fx[n_band]);/*2*cs - 13 + 18 - 15 */ - - exp = norm_l(L_tmp); - tmp = Log2_norm_lc(L_shl(L_tmp, exp)); - exp = sub(30, add(exp, 2*cs-13)); - - L_tmp = Mpy_32_16(exp, tmp, 24660); /* Q14 */ /*10log10(2) in Q13 */ - hq_generic_fenv_fx[add(n_band,nenv)] = round_fx(L_shl(L_tmp, 10));/*Q8 */ - } - ELSE - { - hq_generic_fenv_fx[add(n_band,nenv)] = -24576; - move16(); - } - } - } - - freq_weights_fx(hq_generic_fenv_fx, w_NOR_fx, w_env_fx, nenv); - - FOR ( n_band = 0; n_band < nenv; n_band++ ) - { - hq_generic_fenv_fx[n_band] = sub(hq_generic_fenv_fx[n_band], Mean_env_fx[n_band]); - } - - IF ( st_fx->bwidth_fx == FB ) - { - FOR ( n_band = 0; n_band < DIM_FB; n_band++ ) - { - hq_generic_fenv_fx[add(n_band,nenv)] = sub(shr(hq_generic_fenv_fx[add(n_band,nenv)], 1), Mean_env_fb_fx[n_band]); - } - } - - - /* Energy VQ */ - IF ( sub(hq_generic_offset , HQ_GENERIC_FOFFSET_24K4) <= 0 ) - { - msvq_interpol_fx( hq_generic_fenv_fx, w_env_fx, indice ); - } - ELSE - { - msvq_interpol_2_fx(hq_generic_fenv_fx, w_env_fx, indice, nenv); - } - - IF ( sub(st_fx->bwidth_fx , FB) == 0 ) - { - indice[5] = vqSimple_w_fx(hq_generic_fenv_fx+nenv, hq_generic_fenv_fx+nenv, EnvCdbkFB_fx, NULL, DIM_FB, N_CB_FB, 0); - } - - push_indice_fx( st_fx, IND_SWB_FENV_HQ, indice[0], 5 ); - push_indice_fx( st_fx, IND_SWB_FENV_HQ, indice[1], 7 ); - push_indice_fx( st_fx, IND_SWB_FENV_HQ, indice[2], 6 ); - push_indice_fx( st_fx, IND_SWB_FENV_HQ, indice[3], 5 ); - - IF ( sub(hq_generic_offset , HQ_GENERIC_FOFFSET_24K4) <= 0 ) - { - push_indice_fx( st_fx, IND_SWB_FENV_HQ, indice[4], 6 ); - } - ELSE - { - push_indice_fx( st_fx, IND_SWB_FENV_HQ, indice[4], 5 ); - } - - IF ( sub(st_fx->bwidth_fx , FB) == 0 ) - { - push_indice_fx( st_fx, IND_FB_FENV_HQ, indice[5], 5 ); - } - - FOR ( n_band = 0; n_band < nenv; n_band++ ) - { - tmp = add(hq_generic_fenv_fx[n_band], Mean_env_fx[n_band]);/*8 */ - L_tmp = L_mult(tmp, 21771);/*26 */ - L_tmp = L_shr(L_tmp, 10);/*16 */ - L_Extract(L_tmp, &exp, &tmp);/* */ - tmp = extract_l(Pow2(13, tmp)); - exp = sub(exp, 13); - hq_generic_fenv_fx[n_band] = shl(tmp, add(exp, 1));/*1 */ - } - - - IF ( sub(st_fx->bwidth_fx , FB) == 0 ) - { - FOR ( n_band = 0; n_band < DIM_FB; n_band++ ) - { - tmp = add(hq_generic_fenv_fx[add(n_band,nenv)], Mean_env_fb_fx[n_band]);/*7 */ - L_tmp = L_mult(tmp, 21771);/*25 */ - L_tmp = L_shr(L_tmp, 9);/*16 */ - L_Extract(L_tmp, &exp, &tmp); - tmp = extract_l(Pow2(13, tmp)); - exp = sub(exp, 13); - hq_generic_fenv_fx[add(n_band,nenv)] = shl(tmp, add(exp, 1));/*2 */ - } - } - - return; -} - - diff --git a/src/libs/libevs/lib_enc/swb_bwe_enc_hr.cpp b/src/libs/libevs/lib_enc/swb_bwe_enc_hr.cpp new file mode 100644 index 00000000..d47f6520 --- /dev/null +++ b/src/libs/libevs/lib_enc/swb_bwe_enc_hr.cpp @@ -0,0 +1,473 @@ +/*==================================================================================== + EVS Codec 3GPP TS26.443 Nov 13, 2018. Version 12.11.0 / 13.7.0 / 14.3.0 / 15.1.0 + ====================================================================================*/ + +#include +#include "options.h" +#include "prot.h" +#include "rom_com.h" + +/*-------------------------------------------------------------------* + * en_band_quant() + * + * Quantize the band envelop + *-------------------------------------------------------------------*/ + +static short en_band_quant( /* o : quantization index */ + float *en_band, /* i/o: (un)quantized envelope value */ + const float *env_code, /* i : envelope codebook */ + const short N /* i : codebook dimension */ +) +{ + float maxerr, err; + short i, j, ind; + + maxerr = FLT_MAX; + ind = 0; + + for( i = 0; i < N; i++ ) + { + err = FLT_MIN; + for (j = 0; j < 2; j++) + { + err += (en_band[j] - env_code[i*2+j]) * (en_band[j] - env_code[i*2+j]); + } + if (err < maxerr) + { + maxerr = err; + ind = i; + } + } + + en_band[0] = env_code[2*ind]; + en_band[1] = env_code[2*ind+1]; + + return( ind ); +} + +/*-------------------------------------------------------------------* + * swb_bwe_enc_hr() + * + * HR SWB BWE encoder + *-------------------------------------------------------------------*/ + +void swb_bwe_enc_hr( + Encoder_State *st, /* i/o: encoder state structure */ + const float *new_input, /* i : input signal */ + const short input_frame, /* i : frame length */ + const short coder_type, /* i : coding type */ + const short unbits /* i : number of core unused bits */ +) +{ + short i, j, k, nBits, nBits_total, nBits_block, Nsv, Nsv2, width_noncoded; + short is_transient, pos; + int x_norm[NSV_MAX*(WIDTH_BAND+1)], x_norm1[NSV_MAX*(WIDTH_BAND+1)]; + float t_audio[L_FRAME48k], t_audio_tmp[L_FRAME48k]; + float gain, gain2, en_band[N_BANDS_BWE_HR]; + short ind1, ind2; + short nq[NSV_MAX], nq2[NSV_MAX]; + float tmpF, min_env; + float en_noncoded; + + /*---------------------------------------------------------------------* + * initializations + *---------------------------------------------------------------------*/ + + ind2 = 0; /* only to suppress warnings */ + Nsv2 = 0; /* only to suppress warnings */ + gain2 = 0 ; /* only to suppress warnings */ + en_noncoded = 0;/* only to suppress warnings */ + + /* reset memories in case that last frame was a different technology */ + if( st->last_core == HQ_CORE || st->last_extl != st->extl ) + { + set_f( st->old_wtda_swb, 0, L_FRAME48k ); + } + + /* calculate SWB BWE bit-budget (extension layer bit-rate + AVQ unused bits from the core layer) */ + nBits = (short)(st->extl_brate) / 50 + unbits; + nBits_total = nBits; + + + /*---------------------------------------------------------------------* + * detect transient frames + *---------------------------------------------------------------------*/ + + is_transient = detect_transient( new_input, st, input_frame, coder_type ); + push_indice( st, IND_HR_IS_TRANSIENT, is_transient, 1 ); + + /*---------------------------------------------------------------------* + * OLA and MDCT + *---------------------------------------------------------------------*/ + + wtda( new_input, t_audio_tmp, st->old_wtda_swb, ALDO_WINDOW, ALDO_WINDOW, input_frame ); + + direct_transform( t_audio_tmp, t_audio, is_transient, input_frame ); + + if( is_transient ) + { + nBits = -1; /* is_transient flag */ + nBits_block = nBits_total / NUM_TIME_SWITCHING_BLOCKS; + nBits += nBits_total % NUM_TIME_SWITCHING_BLOCKS; + + /* set width of noncoded (blind estimated) spectrum */ + if( st->extl == SWB_BWE_HIGHRATE ) + { + width_noncoded = L_FRAME32k/NUM_TIME_SWITCHING_BLOCKS - NUM_TRANS_END_FREQ_COEF; + } + else /* st->extl == FB_BWE_HIGHRATE */ + { + width_noncoded = (2*END_FREQ_BWE_FULL_FB/50)/NUM_TIME_SWITCHING_BLOCKS - NUM_TRANS_END_FREQ_COEF; + } + + /*---------------------------------------------------------------------* + * transient frames: processing in blocks (subframes) + *---------------------------------------------------------------------*/ + + for( k = 0; k < NUM_TIME_SWITCHING_BLOCKS; k++ ) + { + nBits += nBits_block; + + /* compute energy of noncoded (14.4-20kHz) spectrum */ + if( st->extl == FB_BWE_HIGHRATE ) + { + en_noncoded = sum2_f( t_audio + k*input_frame/NUM_TIME_SWITCHING_BLOCKS + NUM_TRANS_END_FREQ_COEF, width_noncoded ) + 0.001f; + en_noncoded = (float)sqrt( en_noncoded / width_noncoded ); + } + + /* keep only frequencies in interest */ + set_f( t_audio + k*input_frame/NUM_TIME_SWITCHING_BLOCKS, 0, NUM_TRANS_START_FREQ_COEF ); + set_f( t_audio + k*input_frame/NUM_TIME_SWITCHING_BLOCKS + L_FRAME32k/NUM_TIME_SWITCHING_BLOCKS, 0, (input_frame-L_FRAME32k)/NUM_TIME_SWITCHING_BLOCKS ); + + /*---------------------------------------------------------------------* + * global gain coding + *---------------------------------------------------------------------*/ + + /* compute and quantize global energy */ + gain = sum2_f( t_audio + k*input_frame/NUM_TIME_SWITCHING_BLOCKS + NUM_TRANS_START_FREQ_COEF, WIDTH_TRANS_FREQ_COEF*N_BANDS_TRANS_BWE_HR ) + 0.001f; + gain = (float)sqrt( gain ) / (WIDTH_TRANS_FREQ_COEF*N_BANDS_TRANS_BWE_HR); + ind1 = gain_quant( &gain, MIN_GLOB_GAIN_BWE_HR, MAX_GLOB_GAIN_BWE_HR, NBITS_GLOB_GAIN_BWE_HR ); + + push_indice( st, IND_HR_GAIN, ind1, NBITS_GLOB_GAIN_BWE_HR ); + nBits -= NBITS_GLOB_GAIN_BWE_HR; + + /* normalization with global gain */ + tmpF = 1/gain; + for( i=0; iextl == SWB_BWE_HIGHRATE ) + { + en_noncoded = en_band[N_BANDS_TRANS_BWE_HR-1]; + } + else /* st->extl == FB_BWE_HIGHRATE */ + { + en_noncoded /= (gain * en_band[N_BANDS_TRANS_BWE_HR-1]); + + ind1 = 0; + if( en_noncoded < BWE_HR_TRANS_EN_LIMIT1 ) + { + ind1 = 1; + en_noncoded = en_band[N_BANDS_TRANS_BWE_HR-1] * BWE_HR_TRANS_EN_LIMIT1; + } + else if( en_noncoded < BWE_HR_TRANS_EN_LIMIT2 ) + { + ind1 = 2; + en_noncoded = en_band[N_BANDS_TRANS_BWE_HR-1] * BWE_HR_TRANS_EN_LIMIT2; + } + else if( en_noncoded < BWE_HR_TRANS_EN_LIMIT3 ) + { + ind1 = 3; + en_noncoded = en_band[N_BANDS_TRANS_BWE_HR-1] * BWE_HR_TRANS_EN_LIMIT3; + } + else + { + en_noncoded = en_band[N_BANDS_TRANS_BWE_HR-1]; + } + push_indice( st, IND_HR_HF_GAIN, ind1, NBITS_HF_GAIN_BWE_HR ); + nBits -= NBITS_HF_GAIN_BWE_HR; + } + + /*---------------------------------------------------------------------* + * AVQ coding (quantize normalized spectrum) + *---------------------------------------------------------------------*/ + + Nsv = (NUM_TRANS_END_FREQ_COEF - NUM_TRANS_START_FREQ_COEF) / WIDTH_BAND; + AVQ_cod( t_audio + k*input_frame/NUM_TIME_SWITCHING_BLOCKS + NUM_TRANS_START_FREQ_COEF, x_norm, nBits, Nsv ); + AVQ_encmux( st, st->extl, x_norm, &nBits, Nsv, nq ); + + } + } + else /* !is_transient */ + { + nBits--; /* is_transient flag */ + + /*---------------------------------------------------------------------* + * processing of normal (non-transient) frames + *---------------------------------------------------------------------*/ + + /* set width of noncoded (blind estimated) spectrum */ + if( st->extl == SWB_BWE_HIGHRATE ) + { + width_noncoded = L_FRAME32k - NUM_NONTRANS_END_FREQ_COEF; + } + else /* st->extl == FB_BWE_HIGHRATE */ + { + width_noncoded = 2*END_FREQ_BWE_FULL_FB/50 - NUM_NONTRANS_END_FREQ_COEF; + } + + /* compute energy of noncoded (14.4-20kHz) spectrum */ + if( st->extl == FB_BWE_HIGHRATE ) + { + en_noncoded = sum2_f( t_audio + NUM_NONTRANS_END_FREQ_COEF, width_noncoded ) + 0.001f; + en_noncoded = (float)sqrt( en_noncoded / width_noncoded ); + } + + /* keep only frequencies in interest */ + set_f( t_audio, 0, NUM_NONTRANS_START_FREQ_COEF ); + set_f( t_audio + NUM_NONTRANS_END_FREQ_COEF, 0, input_frame-NUM_NONTRANS_END_FREQ_COEF ); + + /*---------------------------------------------------------------------* + * global gain coding + *---------------------------------------------------------------------*/ + + /* compute and quantize global gain */ + gain = sum2_f( t_audio + NUM_NONTRANS_START_FREQ_COEF, WIDTH_NONTRANS_FREQ_COEF*N_BANDS_BWE_HR ) + 0.001f; + gain = (float)sqrt(gain) / (WIDTH_NONTRANS_FREQ_COEF*N_BANDS_BWE_HR); + ind1 = gain_quant( &gain, MIN_GLOB_GAIN_BWE_HR, MAX_GLOB_GAIN_BWE_HR, NBITS_GLOB_GAIN_BWE_HR ); + + push_indice( st, IND_HR_GAIN, ind1, NBITS_GLOB_GAIN_BWE_HR ); + nBits -= NBITS_GLOB_GAIN_BWE_HR; + + /* normalization with global gain */ + tmpF = 1/gain; + for( i=0; i NBITS_THRESH_BWE_HR ) + { + i = NUM_NONTRANS_END_FREQ_COEF - NUM_NONTRANS_START_FREQ_COEF; + mvr2r( t_audio + NUM_NONTRANS_START_FREQ_COEF, t_audio_tmp, NUM_NONTRANS_END_FREQ_COEF - NUM_NONTRANS_START_FREQ_COEF ); + } + else + { + /* reorder the spectrum */ + ind1 = (pos*64 + pos/2 * WIDTH_BAND); + mvr2r( t_audio + NUM_NONTRANS_START_FREQ_COEF, t_audio_tmp, ind1 ); + + ind2 = ((pos+1)*64 + (pos+1)/2 * WIDTH_BAND); + mvr2r( t_audio + NUM_NONTRANS_START_FREQ_COEF + ind2, t_audio_tmp + ind1, NUM_NONTRANS_END_FREQ_COEF - NUM_NONTRANS_START_FREQ_COEF - ind2 ); + + i = ind1 + NUM_NONTRANS_END_FREQ_COEF - NUM_NONTRANS_START_FREQ_COEF - ind2; + } + + /*---------------------------------------------------------------------* + * estimate energy of noncoded spectrum (14.4-20kHz) + *---------------------------------------------------------------------*/ + + if( st->extl == SWB_BWE_HIGHRATE ) + { + en_noncoded = 0.5f * min_env; + } + else /* st->extl == FB_BWE_HIGHRATE */ + { + en_noncoded /= (gain * min_env); + + ind1 = 0; + if( en_noncoded < BWE_HR_NONTRANS_EN_LIMIT1 ) + { + ind1 = 1; + en_noncoded = 0.5f * min_env * BWE_HR_NONTRANS_EN_LIMIT1; + } + else if( en_noncoded > BWE_HR_NONTRANS_EN_LIMIT2 ) + { + ind1 = 2; + en_noncoded = min_env * BWE_HR_NONTRANS_EN_LIMIT2; + } + else if( en_noncoded > BWE_HR_NONTRANS_EN_LIMIT3 ) + { + ind1 = 3; + en_noncoded = min_env * BWE_HR_NONTRANS_EN_LIMIT3; + } + else + { + en_noncoded = 0.5f * min_env; + } + + push_indice( st, IND_HR_HF_GAIN, ind1, NBITS_HF_GAIN_BWE_HR ); + nBits -= NBITS_HF_GAIN_BWE_HR; + } + + /*---------------------------------------------------------------------* + * AVQ coding (quantize normalized spectrum) + *---------------------------------------------------------------------*/ + + Nsv = i / WIDTH_BAND; + AVQ_cod( t_audio_tmp, x_norm, nBits, Nsv ); + AVQ_encmux( st, st->extl, x_norm, &nBits, Nsv, nq ); + + /*---------------------------------------------------------------------* + * second stage coding + *---------------------------------------------------------------------*/ + + if( nBits >= 9 + NBITS_GLOB_GAIN_BWE_HR && sum_s( nq, Nsv) > 0 ) + { + /* select spectrum of the second stage coding */ + k = 0; + for( i=0; i 396 ) + { + Nsv2 = 33; + } + else + { + Nsv2 = nBits/12; + } + + /* second stage global gain estimation and coding */ + gain2 = sum2_f( t_audio, Nsv2*WIDTH_BAND ) + 0.001f; + gain2 = (float)(16*sqrt( gain2 / (Nsv2*WIDTH_BAND) )); + ind1 = gain_quant( &gain2, MIN_GLOB_GAIN_BWE_HR, MAX_GLOB_GAIN_BWE_HR, NBITS_GLOB_GAIN_BWE_HR ); + + push_indice( st, IND_HR_GAIN, ind1, NBITS_GLOB_GAIN_BWE_HR ); + nBits -= NBITS_GLOB_GAIN_BWE_HR; + + /* normalize with global gain */ + gain2 *= 0.0625f; /* 1/16 */ + tmpF = 1/gain2; + for( i=0; iextl, x_norm1, &nBits, Nsv2, nq2 ); + } + + } + + /* write unused bits */ + while( nBits > 0 ) + { + i = min( nBits, 16 ); + push_indice( st, IND_UNUSED, 0, i ); + nBits -= i; + } + + + return; +} diff --git a/src/libs/libevs/lib_enc/swb_bwe_enc_hr_fx.cpp b/src/libs/libevs/lib_enc/swb_bwe_enc_hr_fx.cpp deleted file mode 100755 index 2a792c16..00000000 --- a/src/libs/libevs/lib_enc/swb_bwe_enc_hr_fx.cpp +++ /dev/null @@ -1,787 +0,0 @@ -/*==================================================================================== - EVS Codec 3GPP TS26.442 Apr 03, 2018. Version 12.11.0 / 13.6.0 / 14.2.0 - ====================================================================================*/ - -#include "options.h" /* Compilation switches */ -#include "cnst_fx.h" /* Common constants */ -#include "rom_enc_fx.h" /* Encoder static table prototypes */ -#include "rom_com_fx.h" /* Static table prototypes */ -#include "prot_fx.h" /* Function prototypes */ -#include "stl.h" - - -/*-------------------------------------------------------------------* - * Local constants - *-------------------------------------------------------------------*/ - -/* Values that Allow to Use Left/Right Shifting instead of Division & - 'and' (&) instead of 'modulo' (%) which is also a costly division. */ -#define NUM_TIME_SW_BLKS_SHIFT 2 -#define NUM_TIME_SW_BLKS_MASK (NUM_TIME_SWITCHING_BLOCKS-1) -#define WIDTH_BAND_SHIFT 3 - -/* Values for Max Scaling of Different Sub Function */ -#define DETECT_TRANSIENT_MAX_Q (11+2) -#define MAX_Q_NEW_INPUT 8 -#define NON_TRANSIENT_RESCALE_Q_GUARD 4 -#define TRANSIENT_RESCALE_Q_GUARD 0 -#define SPECTRUM_RESCALE_Q_GUARD 1 -#define MAX_Q_UPSCALING 6 -#define MAX_AVQ_COD_Q_IN 14 - -/*-------------------------------------------------------------------* - * en_band_quant_fx() - * - * Quantize the band envelop - *-------------------------------------------------------------------*/ - -static Word16 en_band_quant_fx(/* o : quantization index */ - Word16 *en_band, /* i/o: (un)quantized envelope value */ - const Word16 *env_code, /* i : envelope codebook */ - const Word16 N /* i : codebook dimension */ -) -{ - Word16 i, ind, tmp16; - Word32 L_err, L_maxerr; - - L_maxerr = 2147483647L; - move32(); - ind = 0; - move16(); - - FOR( i = 0; i < N; i++ ) - { - /* This is More Efficient */ - tmp16 = sub(en_band[0], env_code[i*2]); - L_err = L_mult0(tmp16, tmp16); - tmp16 = sub(en_band[1], env_code[i*2+1]); - L_err = L_mac0(L_err, tmp16, tmp16); - /* L_err = 0; move32(); - FOR (j = 0; j < 2; j++) - { - tmp16 = sub(en_band[j], env_code[i*2+j]); - L_err = L_mac0(L_err, tmp16, tmp16); - } */ - if (L_sub(L_err, L_maxerr) < 0) - { - ind = i; - move16(); - } - L_maxerr = L_min(L_maxerr, L_err); - } - - en_band[0] = env_code[2*ind]; - move16(); - en_band[1] = env_code[2*ind+1]; - move16(); - - return( ind ); -} - -/*-------------------------------------------------------------------* - * swb_bwe_enc_hr_fx() - * - * HR SWB BWE encoder - *-------------------------------------------------------------------*/ -void swb_bwe_enc_hr_fx( - Encoder_State_fx *st_fx, /* i/o: encoder state structure */ - Word16 *new_input_fx, /* i : input signal */ - Word16 new_input_fx_exp, /* i : Exponent of input signal */ - const Word16 input_frame, /* i : frame length */ - const Word16 coder_type, /* i : coding type */ - const Word16 unbits /* i : number of core unused bits */ -) -{ - Word16 i, j, k, nBits, nBits_total, nBits_block, Nsv, Nsv2, width_noncoded; - Word16 is_transient, pos; - Word16 x_norm_fx[NSV_MAX*(WIDTH_BAND+1)], x_norm1_fx[NSV_MAX*(WIDTH_BAND+1)]; - Word32 t_audio32[L_FRAME48k]; - Word16 *t_audio_fx, t_audio_fx_exp; - Word16 *t_audio_tmp_fx; /* same exponent as 't_audio_fx' */ - Word16 en_band_fx[N_BANDS_BWE_HR]; /* in Q9 */ - Word16 gain1_fx, exp1, gain2_fx, exp2; - Word32 L_gain_fx; - Word16 ind1, ind2; - Word16 nq[NSV_MAX], nq2[NSV_MAX]; - Word32 L_tmp, L_temp; - Word16 temp, temp2; - Word16 *ptr16; - Word16 min_env_fx; - Word32 L_en_noncoded_fx; /* in Q16 */ - Word16 en_noncoded_fx_exp; - Word16 scl; -#if (N_BANDS_BWE_HR*WIDTH_NONTRANS_FREQ_COEF) > L_FRAME48k - Word32 L_t_audio_tmp_fx[N_BANDS_BWE_HR*WIDTH_NONTRANS_FREQ_COEF]; -#else - Word32 L_t_audio_tmp_fx[L_FRAME48k]; -#endif - Word32 *ptr32; - - /*---------------------------------------------------------------------* - * initializations - *---------------------------------------------------------------------*/ - - /* Use 32 Bits Buffer to Store Two 16 Bits Vectors in Order to Save Stack Space */ - t_audio_fx = (Word16 *)&t_audio32[0]; - move16(); - t_audio_tmp_fx = (Word16 *)&t_audio32[L_FRAME48k/2]; - move16(); - - ind2 = 0; - move16();/* only to suppress warnings */ - Nsv2 = 0; - move16();/* only to suppress warnings */ - L_en_noncoded_fx = 0; - move16();/* only to suppress warnings */ - en_noncoded_fx_exp = 0; - move16();/* only to suppress warnings */ - gain2_fx = 0; - move16(); - - /* reset memories in case that last frame was a different technology */ - test(); - IF( sub(st_fx->last_core_fx, HQ_CORE) == 0 || sub(st_fx->last_extl_fx, st_fx->extl_fx) != 0 ) - { - set16_fx( st_fx->L_old_wtda_swb_fx, 0, L_FRAME48k ); - st_fx->Q_old_wtda = 0; - move16(); - } - - /* calculate SWB BWE bit-budget (extension layer bit-rate + AVQ unused bits from the core layer) */ - /* nBits = st->extl_brate/50 + unbits */ - nBits = add(320,unbits); /* st->extl_brate_fx is always 16kbps */ - nBits_total = nBits; - move16(); - - /*---------------------------------------------------------------------* - * detect transient frames - *---------------------------------------------------------------------*/ - /* Calc Room for Energy */ - temp = norm_l(st_fx->EnergyLT_fx); - /* Calc Max Exponent for 'new_input_fx' */ - temp = shr(temp, 1); - temp = add(temp, st_fx->EnergyLT_fx_exp); - temp = sub(temp, new_input_fx_exp); - /* Do not Upscale */ - temp = s_min(0, temp); - /* Limit Input to 'Q_DETECT_TRANSIENT_MAX_Q' (to avoid overflow in 'detect_transient_fx' for Energy Loop)*/ - exp1 = Find_Max_Norm16(new_input_fx, input_frame); - exp1 = sub(exp1, 15-DETECT_TRANSIENT_MAX_Q); - /* Downscale at Least by 'exp1' */ - temp = s_min(temp, exp1); - /* Set Exponent of Input */ - exp1 = add(new_input_fx_exp, temp); - - Copy_Scale_sig(new_input_fx, t_audio_fx, input_frame, temp); - /* Bring Energy in 2*Q'exp1' */ - st_fx->EnergyLT_fx = L_shl(st_fx->EnergyLT_fx, shl(sub(exp1, st_fx->EnergyLT_fx_exp), 1)); - - is_transient = detect_transient_fx( t_audio_fx, input_frame, coder_type, exp1, st_fx ); - st_fx->EnergyLT_fx_exp = exp1; - move16(); - - push_indice_fx( st_fx, IND_HR_IS_TRANSIENT, is_transient, 1 ); - - /*---------------------------------------------------------------------* - * OLA and MDCT - *---------------------------------------------------------------------*/ - - /* To Bring Back to Q15 + 'new_input_fx_exp' */ - /* Save Exponent of Memory (relative to Q15) */ - st_fx->Q_old_wtda = new_input_fx_exp; - move16(); - new_input_fx_exp=0; - wtda_fx( new_input_fx, &new_input_fx_exp, L_t_audio_tmp_fx, st_fx->L_old_wtda_swb_fx, - &st_fx->Q_old_wtda, ALDO_WINDOW, ALDO_WINDOW, input_frame ); - - direct_transform_fx(L_t_audio_tmp_fx, t_audio32, is_transient, input_frame, &new_input_fx_exp); - - /* Convert to 16 Bits (Calc Shift Required to Stay within MAX_Q_NEW_INPUT) */ - scl = sub(16+MAX_Q_NEW_INPUT, new_input_fx_exp); - /* Possible to Upscale? */ - IF (scl > 0) - { - /* Yes */ - /* Calc Room to Upscale */ - t_audio_fx_exp = Find_Max_Norm32(t_audio32, input_frame); - /* Stay within MAX_Q_NEW_INPUT */ - scl = s_min(t_audio_fx_exp, scl); - } - Copy_Scale_sig32_16(t_audio32, t_audio_fx, input_frame, scl); - t_audio_fx_exp = add(sub(new_input_fx_exp, 16), scl); - - IF( is_transient ) - { - nBits = -1; - move16(); /* is_transient flag */ - /* 'nBits_block = nBits_total / NUM_TIME_SWITCHING_BLOCKS' */ - nBits_block = shr(nBits_total, NUM_TIME_SW_BLKS_SHIFT); - /* 'nBits += nBits_total % NUM_TIME_SWITCHING_BLOCKS' */ - nBits = add(nBits, s_and(nBits_total, NUM_TIME_SW_BLKS_MASK)); - - /* set width of noncoded (blind estimated) spectrum */ - IF( sub(st_fx->extl_fx, SWB_BWE_HIGHRATE) == 0) - { - width_noncoded = L_FRAME32k/NUM_TIME_SWITCHING_BLOCKS - NUM_TRANS_END_FREQ_COEF; - move16(); - } - ELSE /* st->extl == FB_BWE_HIGHRATE */ - { - width_noncoded = (2*END_FREQ_BWE_FULL_FB/50)/NUM_TIME_SWITCHING_BLOCKS - NUM_TRANS_END_FREQ_COEF; - move16(); - } - - /* Find Max Scaling on Remaining Frequencies (after frequencies of non interest are zeroed) */ - temp = shr(input_frame, NUM_TIME_SW_BLKS_SHIFT); - scl = 99; - move16(); - ptr16 = &t_audio_fx[NUM_TRANS_START_FREQ_COEF]; - move16(); - FOR( k = 0; k < input_frame; k+=temp ) - { - /* from t_audio_fx[k..NUM_TRANS_START_FREQ_COEF+k-1] will be zeroed out */ - /* AND */ - /* from t_audio_fx[k+L_FRAME32k/NUM_TIME_SWITCHING_BLOCKS..k+switching_block_length-1] will be zeroed out */ - /* Find Max Scaling on Remaining Frequencies */ - scl = s_min(Find_Max_Norm16(ptr16+k, L_FRAME32k/NUM_TIME_SWITCHING_BLOCKS-NUM_TRANS_START_FREQ_COEF), scl); - IF (scl == 0) - { - BREAK; - } - } - /* Need to Keep at Least some Guard Bits */ - scl = s_max(0, sub(scl, TRANSIENT_RESCALE_Q_GUARD)); - /* Reduce if 't_audio_fx_exp' is Q14 or more (AVQ Cod overflow with more than Q14 Input) */ - scl = sub(scl, s_max(0, sub(add(scl, t_audio_fx_exp), MAX_AVQ_COD_Q_IN))); - /* Update Exponent of 't_audio_fx' */ - /* Here tne Signal is not Upscaled yet and some adjustement to 't_audio_fx_exp' will be used - until the signal is indeed upscaled by 'scl'. That Occurs at the 'normalization with global gain'. */ - t_audio_fx_exp = add(t_audio_fx_exp, scl); - - /*---------------------------------------------------------------------* - * transient frames: processing in blocks (subframes) - *---------------------------------------------------------------------*/ - - FOR( k = 0; k < NUM_TIME_SWITCHING_BLOCKS; k++ ) - { - nBits = add(nBits, nBits_block); - - temp = i_mult2(k, shr(input_frame, NUM_TIME_SW_BLKS_SHIFT)); - - /* Calculate Original Exponent (because the part of the signal that is used - to Calculate the Energy is not yet Scaled) */ - j = sub(t_audio_fx_exp, scl); - - /* compute energy of noncoded (14.4-20kHz) spectrum */ - IF( sub(st_fx->extl_fx, FB_BWE_HIGHRATE) == 0) - { - L_tmp = Calc_Energy_Autoscaled(t_audio_fx + add(temp, NUM_TRANS_END_FREQ_COEF), j, width_noncoded, &temp2); - L_en_noncoded_fx = Sqrt_Ratio32(L_tmp, temp2, L_deposit_l(width_noncoded), 0, &en_noncoded_fx_exp); - en_noncoded_fx_exp = sub(31, en_noncoded_fx_exp); - } - - /* keep only frequencies in interest */ - set16_fx( t_audio_fx + temp, 0, NUM_TRANS_START_FREQ_COEF ); - set16_fx( t_audio_fx + add(temp, L_FRAME32k/NUM_TIME_SWITCHING_BLOCKS), 0, shr(sub(input_frame, L_FRAME32k), NUM_TIME_SW_BLKS_SHIFT) ); - - /*---------------------------------------------------------------------* - * global gain coding - *---------------------------------------------------------------------*/ - - /* compute and quantize global energy */ - /* Original float Code: 'gain = (float)sqrt( gain ) / (WIDTH_TRANS_FREQ_COEF*N_BANDS_TRANS_BWE_HR)' */ - /* Put Divisor to Square to Move it Inside the Sqrt */ - /* So we can do 'sqrt( gain (WIDTH_TRANS_FREQ_COEF*N_BANDS_TRANS_BWE_HR)^2)' */ - L_temp = L_mult0(WIDTH_TRANS_FREQ_COEF*N_BANDS_TRANS_BWE_HR, WIDTH_TRANS_FREQ_COEF*N_BANDS_TRANS_BWE_HR); - L_tmp = Calc_Energy_Autoscaled(t_audio_fx + add(temp, NUM_TRANS_START_FREQ_COEF), j, WIDTH_TRANS_FREQ_COEF*N_BANDS_TRANS_BWE_HR, &temp2); - L_tmp = Sqrt_Ratio32(L_tmp, temp2, L_temp, /*L_temp is in Q0*/0, &exp2); - /* Put in Q16 */ - L_gain_fx = L_shr(L_tmp, sub(31-16, exp2)); /* 31: 'L_tmp' is already in Q31 */ - - ind1 = gain_quant_fx( &L_gain_fx, &gain1_fx, LG10_MIN_GLOB_GAIN_BWE_HR_Q14, LG10_MAX_GLOB_GAIN_BWE_HR_Q13, NBITS_GLOB_GAIN_BWE_HR, &exp1); - - push_indice_fx( st_fx, IND_HR_GAIN, ind1, NBITS_GLOB_GAIN_BWE_HR ); - nBits = sub(nBits, NBITS_GLOB_GAIN_BWE_HR); - - /* normalization with global gain */ - ptr16 = &t_audio_fx[add(NUM_TRANS_START_FREQ_COEF, temp)]; - move16(); - temp2 = negate(exp1); - gain2_fx = Invert16(gain1_fx, &temp2); - - /* Also Upscale by 'scl' */ - temp2 = sub(temp2, scl); - FOR( i=0; iextl_fx, SWB_BWE_HIGHRATE) != 0) - { - /* st->extl == FB_BWE_HIGHRATE */ - /* 'en_noncoded /= (gain * en_band[N_BANDS_TRANS_BWE_HR-1])' */ - /* Normalize 'L_en_noncoded_fx' */ - j = norm_l(L_en_noncoded_fx); - L_en_noncoded_fx = L_shl(L_en_noncoded_fx, j); - en_noncoded_fx_exp = add(en_noncoded_fx_exp, j); - /* Calc Divisor */ - L_temp = L_mult0(gain1_fx, en_band_fx[N_BANDS_TRANS_BWE_HR-1]); - /* Normalize Divisor */ - temp2 = norm_l(L_temp); - L_temp = L_shl(L_temp, temp2); - temp2 = sub(add(9, temp2), exp1); /* Q9 for 'en_band_fx' */ - j = Invert16(round_fx(L_temp), &temp2); - L_temp = Mult_32_16(L_en_noncoded_fx, j); - temp2 = add(temp2, en_noncoded_fx_exp); - /* Put in Q16 */ - L_temp = L_shr(L_temp, temp2); - - IF( L_msu0(L_temp, BWE_HR_TRANS_EN_LIMIT1_FX_Q16, 1) < 0) - { - ind1 = 1; - move16(); - L_en_noncoded_fx = L_mult0(en_band_fx[N_BANDS_TRANS_BWE_HR-1], BWE_HR_TRANS_EN_LIMIT1_FX_Q16); - } - ELSE IF( L_msu0(L_temp, BWE_HR_TRANS_EN_LIMIT2_FX_Q16, 1) < 0) - { - ind1 = 2; - move16(); - L_en_noncoded_fx = L_mult0(en_band_fx[N_BANDS_TRANS_BWE_HR-1], BWE_HR_TRANS_EN_LIMIT2_FX_Q16); - } - ELSE IF( L_msu0(L_temp, BWE_HR_TRANS_EN_LIMIT3_FX_Q16, 1) < 0) - { - ind1 = 3; - move16(); - L_en_noncoded_fx = L_mult0(en_band_fx[N_BANDS_TRANS_BWE_HR-1], BWE_HR_TRANS_EN_LIMIT3_FX_Q16); - } - ELSE - { - ind1 = 0; - move16(); - L_en_noncoded_fx = L_deposit_h(en_band_fx[N_BANDS_TRANS_BWE_HR-1]); /* to Put in Q16+9 */ - } - - push_indice_fx( st_fx, IND_HR_HF_GAIN, ind1, NBITS_HF_GAIN_BWE_HR ); - nBits = sub(nBits, NBITS_HF_GAIN_BWE_HR); - } - ELSE - { - L_en_noncoded_fx = L_deposit_h(en_band_fx[N_BANDS_TRANS_BWE_HR-1]); - } - en_noncoded_fx_exp = 9+16; - move16(); /* 9 for 'en_band_fx', 16 for 'BWE_HR_TRANS_EN_LIMIT...' */ - - /*---------------------------------------------------------------------* - * AVQ coding (quantize normalized spectrum) - *---------------------------------------------------------------------*/ - - Nsv = (NUM_TRANS_END_FREQ_COEF - NUM_TRANS_START_FREQ_COEF) / WIDTH_BAND; - move16(); - AVQ_cod_fx(t_audio_fx + add(temp, NUM_TRANS_START_FREQ_COEF), x_norm_fx, nBits, Nsv, t_audio_fx_exp); - AVQ_encmux_fx(st_fx, st_fx->extl_fx, x_norm_fx, &nBits, Nsv, nq); - - } - } - ELSE /* !is_transient */ - { - /* subtract one bit for is_transient flag */ - nBits = sub(nBits, 1); - - /*---------------------------------------------------------------------* - * processing of normal (non-transient) frames - *---------------------------------------------------------------------*/ - - /* set width of noncoded (blind estimated) spectrum */ - IF( sub(st_fx->extl_fx, SWB_BWE_HIGHRATE) == 0) - { - width_noncoded = L_FRAME32k - NUM_NONTRANS_END_FREQ_COEF; - move16(); - } - ELSE /* st->extl == FB_BWE_HIGHRATE */ - { - width_noncoded = 2*END_FREQ_BWE_FULL_FB/50 - NUM_NONTRANS_END_FREQ_COEF; - move16(); - } - - /* compute energy of noncoded (14.4-20kHz) spectrum */ - IF( sub(st_fx->extl_fx, FB_BWE_HIGHRATE) == 0) - { - L_tmp = Calc_Energy_Autoscaled(t_audio_fx + NUM_NONTRANS_END_FREQ_COEF, t_audio_fx_exp, width_noncoded, &temp2); - L_en_noncoded_fx = Sqrt_Ratio32(L_tmp, temp2, L_deposit_l(width_noncoded), 0, &en_noncoded_fx_exp); - en_noncoded_fx_exp = sub(31, en_noncoded_fx_exp); - } - - /* keep only frequencies in interest */ - set16_fx( t_audio_fx, 0, NUM_NONTRANS_START_FREQ_COEF ); - set16_fx( t_audio_fx + NUM_NONTRANS_END_FREQ_COEF, 0, sub(input_frame, NUM_NONTRANS_END_FREQ_COEF) ); - - /*---------------------------------------------------------------------* - * global gain coding - *---------------------------------------------------------------------*/ - - /* compute and quantize global gain */ - L_tmp = Calc_Energy_Autoscaled(t_audio_fx + NUM_NONTRANS_START_FREQ_COEF, t_audio_fx_exp, WIDTH_NONTRANS_FREQ_COEF*N_BANDS_BWE_HR, &temp2); - /* Original float Code: 'gain = (float)sqrt( gain ) / (WIDTH_TRANS_FREQ_COEF*N_BANDS_TRANS_BWE_HR)' */ - /* Put Divisor to Square to Move it Inside the Sqrt */ - /* So we can do 'sqrt( gain (WIDTH_NONTRANS_FREQ_COEF*N_BANDS_BWE_HR)^2)' */ - L_temp = L_mult0(WIDTH_NONTRANS_FREQ_COEF*N_BANDS_BWE_HR, WIDTH_NONTRANS_FREQ_COEF*N_BANDS_BWE_HR); - L_tmp = Sqrt_Ratio32(L_tmp, temp2, L_temp, /*L_temp is in Q0*/0, &exp2); - /* Put in Q16 */ - L_gain_fx = L_shr(L_tmp, sub(31-16, exp2)); /* 31: 'L_tmp' is already in Q31 */ - ind1 = gain_quant_fx( &L_gain_fx, &gain1_fx, LG10_MIN_GLOB_GAIN_BWE_HR_Q14, LG10_MAX_GLOB_GAIN_BWE_HR_Q13, NBITS_GLOB_GAIN_BWE_HR, &exp1); - - push_indice_fx( st_fx, IND_HR_GAIN, ind1, NBITS_GLOB_GAIN_BWE_HR ); - nBits = sub(nBits, NBITS_GLOB_GAIN_BWE_HR); - - /* normalization with global gain */ - ptr16 = &t_audio_fx[NUM_NONTRANS_START_FREQ_COEF]; - move16(); - /* Find Max Scaling on Remaining Frequencies */ - temp2 = Find_Max_Norm16(ptr16, NUM_NONTRANS_END_FREQ_COEF-NUM_NONTRANS_START_FREQ_COEF); - temp2 = s_max(0, sub(temp2, NON_TRANSIENT_RESCALE_Q_GUARD)); - temp2 = s_min(temp2, MAX_Q_UPSCALING); - t_audio_fx_exp = add(t_audio_fx_exp, temp2); - temp2 = sub(temp2, exp1); - temp = Invert16(gain1_fx, &temp2); - - FOR( i=0; i 0) - { - i = NUM_NONTRANS_END_FREQ_COEF - NUM_NONTRANS_START_FREQ_COEF; - move16(); - Copy( t_audio_fx + NUM_NONTRANS_START_FREQ_COEF, t_audio_tmp_fx, NUM_NONTRANS_END_FREQ_COEF - NUM_NONTRANS_START_FREQ_COEF ); - } - ELSE - { - /* reorder the spectrum */ - ind1 = add(shl(pos, 6), shl(shr(pos, 1), WIDTH_BAND_SHIFT)); - Copy( t_audio_fx + NUM_NONTRANS_START_FREQ_COEF, t_audio_tmp_fx, ind1 ); - - ind2 = add(pos, 1); - ind2 = add(shl(ind2, 6), shl(shr(ind2, 1), WIDTH_BAND_SHIFT)); - Copy( t_audio_fx + add(NUM_NONTRANS_START_FREQ_COEF, ind2), t_audio_tmp_fx + ind1, sub(NUM_NONTRANS_END_FREQ_COEF - NUM_NONTRANS_START_FREQ_COEF, ind2) ); - - i = sub(add(ind1, NUM_NONTRANS_END_FREQ_COEF - NUM_NONTRANS_START_FREQ_COEF), ind2); - } - - /*---------------------------------------------------------------------* - * estimate energy of noncoded spectrum (14.4-20kHz) - *---------------------------------------------------------------------*/ - IF( sub(st_fx->extl_fx, SWB_BWE_HIGHRATE) != 0) - { - /* st->extl == FB_BWE_HIGHRATE */ - /* 'en_noncoded /= (gain * min_env)' */ - /* Normalize 'L_en_noncoded_fx' */ - temp = norm_l(L_en_noncoded_fx); - L_en_noncoded_fx = L_shl(L_en_noncoded_fx, temp); - en_noncoded_fx_exp = add(en_noncoded_fx_exp, temp); - /* Calc Divisor */ - L_temp = L_mult0(gain1_fx, min_env_fx); - /* Normalize Divisor */ - temp2 = norm_l(L_temp); - L_temp = L_shl(L_temp, temp2); - temp2 = sub(add(9, temp2), exp1); /* Q9 for 'min_env_fx', 'exp1' for 'gain1' */ - j = Invert16(round_fx(L_temp), &temp2); - L_temp = Mult_32_16(L_en_noncoded_fx, j); - temp2 = add(temp2, en_noncoded_fx_exp); - /* Put in Q16 */ - L_temp = L_shr(L_temp, temp2); - IF( L_msu(L_temp, BWE_HR_NONTRANS_EN_LIMIT1_FX_Q15, 1) < 0) - { - ind1 = 1; - move16(); - /* 'en_noncoded = 0.5f * min_env * BWE_HR_NONTRANS_EN_LIMIT1' */ - L_en_noncoded_fx = L_mult0(min_env_fx, BWE_HR_NONTRANS_EN_LIMIT1_FX_Q15/2); - } - ELSE IF( L_msu(L_temp, BWE_HR_NONTRANS_EN_LIMIT2_FX_Q14, 2) > 0) - { - ind1 = 2; - move16(); - /* 'min_env * BWE_HR_NONTRANS_EN_LIMIT2' */ - L_en_noncoded_fx = L_mult(min_env_fx, BWE_HR_NONTRANS_EN_LIMIT2_FX_Q14); - } - ELSE IF( L_msu(L_temp, BWE_HR_NONTRANS_EN_LIMIT3_FX_Q15, 1) > 0) - { - ind1 = 3; - move16(); - L_en_noncoded_fx = L_mult0(min_env_fx, BWE_HR_NONTRANS_EN_LIMIT3_FX_Q15); - } - ELSE - { - ind1 = 0; - move16(); - L_en_noncoded_fx = L_mult0(min_env_fx, 16384); - } - - push_indice_fx( st_fx, IND_HR_HF_GAIN, ind1, NBITS_HF_GAIN_BWE_HR ); - nBits = sub(nBits, NBITS_HF_GAIN_BWE_HR); - } - ELSE - { - L_en_noncoded_fx = L_mult0(min_env_fx, 16384); - } - en_noncoded_fx_exp = 9+16-1; - move16(); /* 9 for 'en_band_fx', 16 for 'BWE_HR_TRANS_EN_LIMIT...' & -1 becaues of 'L_mult0' */ - - /*---------------------------------------------------------------------* - * AVQ coding (quantize normalized spectrum) - *---------------------------------------------------------------------*/ - - Nsv = shr(i, WIDTH_BAND_SHIFT); - AVQ_cod_fx(t_audio_tmp_fx/*same exponent as t_audio_fx*/, x_norm_fx, nBits, Nsv, t_audio_fx_exp); - AVQ_encmux_fx(st_fx, st_fx->extl_fx, x_norm_fx, &nBits, Nsv, nq); - - /*---------------------------------------------------------------------* - * second stage coding - *---------------------------------------------------------------------*/ - - test(); - IF( sub(nBits, 9 + NBITS_GLOB_GAIN_BWE_HR) >= 0 && sum16_fx( nq, Nsv) > 0 ) - { - /* select spectrum of the second stage coding */ - ptr16 = &t_audio_fx[0]; - move16(); - FOR( i=0; i 0 ) - { - Nsv2 = 33; - move16(); - } - ELSE - { - /* Here what is acheived is an integer divide by 12 with truncation. */ - /* nBits/12 */ - Nsv2 = mult(nBits, 2731); - /* But, we have imprecision of the fraction so correction is necessary. */ - /* We crosscheck if 'Nsv2' is either too high or too low. */ - /* Finally, the result must satisfy: */ - /* Nsv2 * 12 <= nBits (Nsv2 is not too high) AND */ - /* nBits - Nsv2 * 12 < 12 (Nsv2 is the highest divisor) */ - L_temp = L_msu0(L_deposit_l(nBits), 12, Nsv2); - if (L_sub(L_temp, 12L) >= 0) - Nsv2 = add(Nsv2, 1); - if (L_temp < 0) - Nsv2 = sub(Nsv2, 1); - } - - /* second stage global gain estimation and coding */ - L_tmp = L_mult0(Nsv2, WIDTH_BAND); - L_temp = Calc_Energy_Autoscaled(t_audio_fx, t_audio_fx_exp, extract_l(L_tmp), &temp2); - /* Original Float Code: 'gain2 = (float)(16*sqrt( gain2 / (Nsv2*WIDTH_BAND) ))' */ - /* Or Instead: 'gain2 = (float)sqrt( gain2 / (Nsv2*WIDTH_BAND) * 256) )' */ - L_temp = Sqrt_Ratio32(L_temp, temp2, L_tmp, /*Log2 of 256*/8, &temp2); - /* Put in Q16 */ - L_gain_fx = L_shr(L_temp, sub(31-16, temp2)); /* 31: 'L_temp' is already in Q31 */ - ind1 = gain_quant_fx( &L_gain_fx, &gain2_fx, LG10_MIN_GLOB_GAIN_BWE_HR_Q14, LG10_MAX_GLOB_GAIN_BWE_HR_Q13, NBITS_GLOB_GAIN_BWE_HR, &exp2); - push_indice_fx( st_fx, IND_HR_GAIN, ind1, NBITS_GLOB_GAIN_BWE_HR ); - nBits = sub(nBits, NBITS_GLOB_GAIN_BWE_HR); - - /* normalize with global gain */ - temp2 = sub(4, exp2); /* 1/16 */ - temp = Invert16(gain2_fx, &temp2); - FOR( i=0; iextl_fx, x_norm1_fx, &nBits, Nsv2, nq2 ); - } - - } /* 'ELSE' of ' IF( is_transient )' */ - - /* write unused bits */ - WHILE( nBits > 0 ) - { - i = s_min( nBits, 16 ); - push_indice_fx( st_fx, IND_UNUSED, 0, i ); - nBits = sub(nBits, i); - } - return; -} - diff --git a/src/libs/libevs/lib_enc/swb_bwe_enc_lr.cpp b/src/libs/libevs/lib_enc/swb_bwe_enc_lr.cpp new file mode 100644 index 00000000..34891808 --- /dev/null +++ b/src/libs/libevs/lib_enc/swb_bwe_enc_lr.cpp @@ -0,0 +1,673 @@ +/*==================================================================================== + EVS Codec 3GPP TS26.443 Nov 13, 2018. Version 12.11.0 / 13.7.0 / 14.3.0 / 15.1.0 + ====================================================================================*/ + +#include +#include +#include "options.h" +#include "cnst.h" +#include "prot.h" +#include "rom_com.h" +#include "stat_com.h" + +/*--------------------------------------------------------------------------* + * GetSubbandCorrIndex2_har() + * + * Finds the index of best correlation between highband (*inBuf) and lowband (*predBuf) for current subband of length (fLen) + *--------------------------------------------------------------------------*/ + +static short GetSubbandCorrIndex2_har( /* o : best correlation index */ + const float *inBuf, /* i : target buffer (i.e., highband signal) */ + const float *predBuf, /* i : prediction buffer (i.e., lowband) */ + const short fLen, /* i : window length */ + const short maxLag, /* i : search length */ + const GainItem *G_item, /* i : nZero nonzero components (value+index) */ + const short nZero, /* i : number of nonzero components used in */ + short *prev_frame_bstindx /* i : previous frame best Indices */ +) +{ + short bestIdx, i, j; + float corr, energy, corr_sq; + float lagCorr_sq, lagEnergy, eOld; + short absPos; + short N1, N2; + + + absPos = 0; + bestIdx = 0; + lagCorr_sq = 0.0f; + lagEnergy = 1e30f; + + for( i = 0, energy = 0.0f; i < fLen - 1; i++, predBuf++ ) + { + energy += *predBuf **predBuf; + } + + predBuf -= fLen-1; + eOld = 0.0f; + N1 = max(0, *prev_frame_bstindx-maxLag/2); + if( *prev_frame_bstindx < 0 ) + { + N2 = maxLag-1; + } + else + { + N2 = min(maxLag-1, *prev_frame_bstindx+maxLag/2); + } + + predBuf +=N1; + + /* find the best lag */ + for( i = N1; i <= N2; i++ ) + { + corr = 0.0f; + + /* get the energy, remove the old and update with the new energy index */ + for(j = 0, energy = 0.0f; j < fLen; j++, predBuf++) + { + energy += *predBuf **predBuf; + } + + predBuf -= fLen; + + /* energy to be removed in the next lag */ + eOld = *predBuf; + eOld *= eOld; + + /* get cross-correlation */ + if( energy ) + { + for(j = 0, corr = 0.0f; j < nZero; j++) + { + corr += inBuf[G_item[j].gainIndex]* predBuf[G_item[j].gainIndex]; + } + + corr_sq = corr*corr; + + if( (double)lagCorr_sq*(double)energy < (double)corr_sq*(double)lagEnergy ) + { + bestIdx = i; + lagCorr_sq = corr_sq; + lagEnergy = energy; + } + } + + predBuf++; + absPos++; + } + + if( lagCorr_sq == 0.0f && *prev_frame_bstindx < 0 ) + { + bestIdx = 0; + } + else + { + if( lagCorr_sq == 0.0f ) + { + bestIdx = *prev_frame_bstindx; + } + } + + *prev_frame_bstindx = bestIdx; + + return bestIdx; +} + + + +/*--------------------------------------------------------------------------* + * getswbindices_har() + * + * Finds the pulse index of best correlation between highband (*yos) and lowband (*y2) for two groups of length sbLen + *--------------------------------------------------------------------------*/ + +static void getswbindices_har( + float *yos, /* i : original input spectrum */ + float *y2, /* i : decoded spectrum */ + const short nBands_search, /* i : number of bands */ + short *lagIndices, /* o : pulse index */ + short *prev_frame_bstindx, /* i/o: prev frame index */ + const short swb_lowband, /* i : length of the LF spectrum */ + const short *subband_offsets, + const short *sbWidth, + const short *subband_search_offset + +) +{ + GainItem Nbiggest[(NB_SWB_SUBBANDS_HAR_SEARCH_SB)*N_NBIGGEST_PULSEARCH]; + const float *refBuf,*predBuf; + short search_offset[NB_SWB_SUBBANDS_HAR_SEARCH_SB]; + short nlags[NB_SWB_SUBBANDS_HAR_SEARCH_SB]; + short j, k, sb; + short n_nbiggestsearch[NB_SWB_SUBBANDS_HAR]; + float low_freqsgnl[L_FRAME32k]; + + /* Initializations */ + predBuf = y2; + + /* Get the number of HF groups for performing Similarity search */ + for( sb = 0; sb < nBands_search; sb++ ) + { + nlags[sb] = (short)pow(2, bits_lagIndices_mode0_Har[sb]); + } + + for( sb=0; sb search_offset[sb] - sbWidth[sb] - nlags[sb]/2; j-- ) + { + low_freqsgnl[k] = predBuf[j]; + k++; + } + } + /* correlation b/w HF spectrum Group1 of length sbLen and decoded LF spectrum */ + lagIndices[sb] = GetSubbandCorrIndex2_har( yos + swb_lowband + subband_offsets[sb], low_freqsgnl, + sbWidth[sb], nlags[sb], Nbiggest+(sb*N_NBIGGEST_PULSEARCH), + n_nbiggestsearch[sb], &prev_frame_bstindx[sb] ); + } + + return; +} + +static short GetSubbandCorrIndex2_pulsestep( + const float *inBuf, + const float *predBuf, + const float *predBufMa, + const short fLen, + const short maxLag, + const GainItem *G_item, + const short nZero, + short ssearch_buflim, + const float *predBuf_ni +) +{ + short bestIdx, i, j; + float corr, energy, corr_sq; + float lagCorr_sq, lagEnergy; + short absPos; + short ib_flag = 0; + + + absPos = 0; + bestIdx = -1; + lagCorr_sq = 0.0f; + lagEnergy = 1e30f; + + /* Get the initial energy for zero lag */ + while( *predBuf == 0.0f && absPos < ssearch_buflim ) + { + predBuf++; + absPos++; + predBuf_ni++; + } + + if( absPos == ssearch_buflim ) + { + predBuf--; + absPos--; + predBuf_ni--; + } + for( i = 0, energy = 0.0f; i < fLen; i++, predBuf_ni++ ) + { + energy += *predBuf_ni **predBuf_ni; + } + + predBuf_ni -= fLen; + lagEnergy = energy; + + /* Find the best lag */ + for( i = 0; i < maxLag; i++ ) + { + corr = 0.0f; + + /* Get the energy, remove the old and update with the new energy index */ + for(j = 0, energy = 0.0f; j < fLen; j++, predBuf_ni++) + { + energy += *predBuf_ni **predBuf_ni; + } + predBuf_ni -= fLen; + + /* Get cross-correlation */ + if( energy ) + { + for(j = 0, corr = 0.0f; j < nZero; j++) + { + corr += inBuf[G_item[j].gainIndex]* predBufMa[G_item[j].gainIndex]; + } + + corr_sq = corr*corr; + + if( (lagCorr_sq == 0.0f && corr_sq == 0.0f) || (double)lagCorr_sq*(double)energy < (double)corr_sq*(double)lagEnergy ) + { + bestIdx = i; + lagCorr_sq = corr_sq; + lagEnergy = energy; + } + } + + predBuf++; + absPos++; + predBuf_ni++; + while( *predBuf == 0.0f && absPos < ssearch_buflim ) + { + predBuf++; + absPos++; + predBuf_ni++; + } + + if( absPos >= ssearch_buflim ) + { + if( bestIdx == -1 ) + { + ib_flag = 1; + } + + break; + } + } + if( ib_flag ) + { + bestIdx = 0; + } + return bestIdx; +} + + +/*--------------------------------------------------------------------------* + * GetSWBIndices() + * + * Finds the subband lags for subband coding. Each lag corresponds to + * the section that is copied and scaled from the low-frequency band + * to form the high-frequency subband. + * + * The subbands are searched in two steps to reduce the complexity of + * the search relative to full search. In first step, a most representative + * subband is selected based on the similarity of the subbands.Full search + * is performed for the selected subband.Based on the lagIndice value for + * this subband, the region of highest interest is selected. A partial + * search is performed for rest of the subbands around this region of the + * low-frequency range. + *--------------------------------------------------------------------------*/ + +static void GetSWBIndices( + const float *predBuf, /* i : low-frequency band */ + const float *targetBuf, /* i : high-frequency band */ + const short nBands_search, /* i : number of search subbands */ + const short *sbWidth, /* i : subband lengths */ + short *lagIndices, /* o : selected lags for subband coding */ + const short predBufLen, /* i : low-frequency band length */ + GainItem *Nbiggest, /* o : most representative region */ + const short *subband_offsets, /* o : N biggest components */ + float *predBuf_ni /* i : low-frequency band filled noise */ +) +{ + const float *refBuf; + short search_offset[NB_SWB_SUBBANDS]; + short nlags[NB_SWB_SUBBANDS]; + short sbLen; + short j, sb; + short n_nbiggestsearch[NB_SWB_SUBBANDS]; + short ssearch_buflim; + float sspectra_ma[L_FRAME32k]; + + /* Initializations */ + for (sb = 0; sb < nBands_search; sb++) + { + j = sb * N_NBIGGEST_PULSEARCH; + sbLen = sbWidth[sb]; + refBuf = targetBuf + subband_offsets[sb]; + FindNBiggest2_simple(refBuf, Nbiggest+j, sbLen, &n_nbiggestsearch[sb],N_NBIGGEST_PULSEARCH); + } + + /* Selection of most representative subband (full search) */ + for ( sb = 0; sb < nBands_search; sb++ ) + { + nlags[sb] = (short)pow(2, bits_lagIndices_modeNormal[sb]); + } + + for ( sb = 0; sb < nBands_search; sb++ ) + { + search_offset[sb] = subband_search_offsets[sb]; + } + sspectra_ma[0] = (predBuf_ni[0]+predBuf_ni[1])/2.0f; + + for( sb=1; sb < predBufLen-1; sb++ ) + { + sspectra_ma[sb] = (predBuf_ni[sb-1] + predBuf_ni[sb] + predBuf_ni[sb+1])/3.0f; + } + + sspectra_ma[sb] = (predBuf_ni[sb-1]+predBuf_ni[sb])/2.0f; + /* Partial search for rest of subbands except the last which is fixed */ + for( sb = 0; sb < nBands_search; sb++ ) + { + sbLen = sbWidth[sb]; + ssearch_buflim = predBufLen - (sbLen + search_offset[sb]); + lagIndices[sb] = GetSubbandCorrIndex2_pulsestep( targetBuf + subband_offsets[sb], predBuf + search_offset[sb], + sspectra_ma + search_offset[sb], sbLen, nlags[sb], Nbiggest+(sb*N_NBIGGEST_PULSEARCH),n_nbiggestsearch[sb], + ssearch_buflim, predBuf_ni + search_offset[sb]); + } + + return; +} + + + +static void gethar_noisegn( + Encoder_State *st, + float spectra[], + float noise_flr[], + float xSynth_har[], + const short sbWidth[], + const short lagIndices[], + const short bands, + const short har_bands, + const short fLenLow, + const short fLenHigh, + const short subband_offsets[], + const short subband_search_offset[], + short band_start[], + short band_end[], + short band_width[], + float band_energy[], + float be_tonal[], + float *sspectra, + const short har_freq_est2, + const short pos_max_hfe2, + short *pul_res, + GainItem pk_sf[] +) +{ + GainItem get_pk[N_NBIGGEST_SEARCH_LRG_B]; + short n_nbiggestsearch,imin,gqlevs; + short i; + float hfspec[L_FRAME32k]; + float g,g1,g2,dmin,d; + + /*Generate HF noise*/ + genhf_noise( noise_flr, xSynth_har, sspectra, bands, har_bands, har_freq_est2, pos_max_hfe2, pul_res, pk_sf, fLenLow, + fLenHigh, sbWidth, lagIndices, subband_offsets, subband_search_offset ); + + mvr2r(spectra+fLenLow,hfspec,fLenHigh); + FindNBiggest2_simple(hfspec, get_pk, fLenHigh, &n_nbiggestsearch,N_NBIGGEST_SEARCH_LRG_B); + for(i=0; iprev_hqswb_clas, &st->prev_ni_ratio ); + + /* Find best indices for each group */ + getswbindices_har(spectra, sspectra_ni,nBands_search, lagIndices, prev_frm_index,fLenLow,subband_offsets, sbWidth , subband_search_offset); + /* Write the indices into the bitstream */ + for (k = 0; k < nBands_search; k++) + { + push_indice( st,IND_LAGINDICES, lagIndices[k], bits_lagIndices_mode0_Har[k]); + } + + if(flag_dis == 0) + { + if(har_freq_est2 != SWB_HAR_RAN1 || har_freq_est2 != *prev_frm_hfe2) + { + har_freq_est2 += lagIndices[0]; + } + } + + /*noise generation*/ + gethar_noisegn( st, spectra, sspectra_diff, xSynth_har, sbWidth, lagIndices, BANDS, har_bands, fLenLow, fLenHigh, subband_offsets, subband_search_offset, + band_start, band_end, band_width, band_energy, be_tonal, sspectra, har_freq_est2, pos_max_hfe2, pul_res, pk_sf ); + + /*HF Spectrum Generation*/ + Gettonl_scalfact( xSynth_har, spectra_ni, fLenLow, fLenHigh, har_bands, BANDS, band_energy, band_start, band_end, p2a_flags, be_tonal, pk_sf, pul_res ); + + if(flag_dis == 0) + { + *prev_frm_hfe2 = 0; + } + else + { + *prev_frm_hfe2 = har_freq_est2; + } + + for( k = har_bands; k < BANDS; k++ ) + { + for( i = band_start[k]; i <= band_end[k]; i++ ) + { + spectra[i] = xSynth_har[i-fLenLow]; + } + } + } + else + { + /* Spectrum normalization for the corecoder*/ + ss_min = spectrumsmooth_noiseton(spectra,spectra_ni,sspectra,sspectra_diff,sspectra_ni,fLenLow, ni_seed); + + /* Get lag indices */ + GetSWBIndices( sspectra, spectra + fLenLow, nBands, sbWidth, lagIndices, fLenLow, + Nbiggest, subband_offsets, sspectra ); + /* Bitstream operations */ + for (k = 0; k < nBands; k++) + { + if( p2a_flags[BANDS-NB_SWB_SUBBANDS+k] == 0 ) + { + push_indice( st,IND_LAGINDICES,lagIndices[k], bits_lagIndices_modeNormal[k] ); + } + else + { + lagIndices[k] = 0; + } + } + convert_lagIndices_pls2smp( lagIndices, nBands, lagIndices, sspectra, sbWidth, fLenLow ); + /*get levels for missing bands*/ + GetlagGains( sspectra_ni, &band_energy[BANDS-NB_SWB_SUBBANDS], nBands, sbWidth, lagIndices, fLenLow, lagGains ); + for(k=0; kprev_En_sb, p2a_flags, BANDS, band_start, band_end, fLenLow ); + + for( k = BANDS - NB_SWB_SUBBANDS; k < BANDS; k++ ) + { + if( p2a_flags[k] == 0 ) + { + for( i = band_start[k]; i <= band_end[k]; i++ ) + { + spectra[i] = xSynth_har[i-fLenLow]; + } + } + else + { + for( i = band_start[k]; i <= band_end[k]; i++ ) + { + spectra[i] = spectra_ni[i]; + } + } + } + } + + return; +} + +/*--------------------------------------------------------------------------* + * swb_bwe_enc_lr() + * + * Main encoding routine of SWB BWE for the LR MDCT core + *--------------------------------------------------------------------------*/ + +void swb_bwe_enc_lr( + Encoder_State *st, /* i/o: encoder state structure */ + const float m_core[], /* i : lowband synthesis */ + const float m_orig[], /* i/o: scaled orig signal (MDCT) */ + float m[], /* o : highband synthesis with lowband zeroed */ + const long total_brate, /* i : total bitrate for selecting subband pattern */ + short BANDS, /* i : Total number of Subbands in a frame */ + short *band_start, /* i : band start of each SB */ + short *band_end, /* i : band end of each SB */ + float *band_energy, /* i : band_energy of each SB */ + short *p2a_flags, /* i : HF tonal indicator */ + const short hqswb_clas, /* i : HQ_NORMAL or HQ_HARMONIC mode */ + short lowlength, /* i : lowband length */ + short highlength, /* i : highband length */ + short *prev_frm_index, /* i/o: previous frame lag index for harmonic mode */ + const short har_bands, /* i : Number of LF harmonic bands */ + short *prev_frm_hfe2, + short *prev_stab_hfe2, + short band_width[], /* i : subband bandwidths */ + const float y2_ni[], /* i/o: Sparse filled core coder */ + short *ni_seed /* i/o: random seed for search buffer NI */ +) +{ + short k; + short nBands; + short nBands_search; + short wBands[NB_SWB_SUBBANDS]; + short lagIndices[NB_SWB_SUBBANDS]; + float lagGains[NB_SWB_SUBBANDS]; + const short *subband_offsets; + short swb_lowband, swb_highband; + const short *subband_search_offset; + subband_search_offset = subband_search_offsets_13p2kbps_Har; + subband_offsets = subband_offsets_sub5_13p2kbps_Har; + hf_parinitiz(total_brate,hqswb_clas,lowlength,highlength,wBands,&subband_search_offset,&subband_offsets,&nBands,&nBands_search,&swb_lowband,&swb_highband); + /* Prepare m[], low part from WB core, high part from 32k input */ + mvr2r( m_core, m, swb_lowband ); + mvr2r( m_orig + swb_lowband, m + swb_lowband, swb_highband ); + + /* SWB BWE encoding */ + EncodeSWBSubbands( st, m, swb_lowband, swb_highband, nBands, nBands_search, wBands, subband_offsets, + lagIndices, lagGains, BANDS, band_start, band_end, band_energy, p2a_flags, + hqswb_clas, prev_frm_index, har_bands, subband_search_offset, prev_frm_hfe2, prev_stab_hfe2,band_width, y2_ni, ni_seed ); + m[swb_lowband+swb_highband-1] *= 0.0625f; + m[swb_lowband+swb_highband-2] *= 0.125f; + m[swb_lowband+swb_highband-3] *= 0.25f; + m[swb_lowband+swb_highband-4] *= 0.5f; + + /* set frequencies below 6.4 kHz to zero */ + if(hqswb_clas == HQ_NORMAL) + { + for (k=0; k < swb_lowband; k++) + { + m[k] = 0.0f; + } + } + + return; +} + diff --git a/src/libs/libevs/lib_enc/swb_bwe_enc_lr_fx.cpp b/src/libs/libevs/lib_enc/swb_bwe_enc_lr_fx.cpp deleted file mode 100755 index b593f19c..00000000 --- a/src/libs/libevs/lib_enc/swb_bwe_enc_lr_fx.cpp +++ /dev/null @@ -1,1067 +0,0 @@ -/*==================================================================================== - EVS Codec 3GPP TS26.442 Apr 03, 2018. Version 12.11.0 / 13.6.0 / 14.2.0 - ====================================================================================*/ - -#include -#include "options.h" - -#include "prot_fx.h" -#include "rom_com_fx.h" -#include "stl.h" -#include "basop_mpy.h" - -/*--------------------------------------------------------------------------* - * GetSubbandCorrIndex2_har() - * - * Finds the index of best correlation between highband (*inBuf) and lowband (*predBuf) for current subband of length (fLen) - *--------------------------------------------------------------------------*/ -static -Word16 GetSubbandCorrIndex2_har_fx( /* o : best correlation index */ - const Word32 *L_inBuf, /* i : target buffer (i.e., highband signal) : spectra */ - const Word16 fLen, /* i : window length */ - const Word16 *predBuf_fx, /* i : prediction buffer (i.e., lowband) : sspectra */ - const Word16 predBufLen, /* i : sspectra buffer size */ - const Word16 maxLag_fx, /* i : search length */ - const GainItem_fx *G_item_fx, /* i : */ - const Word16 nZero_fx, /* i : number of nonzero components used in */ - Word16 *prev_frame_bstindx_fx /* i : previous frame best Indices */ -) -{ - Word16 i, j; - Word16 bestIdx_fx; - Word32 L_lagCorr_sq; - Word32 L_lagEnergy; - - Word32 L_energy; - Word32 L_corr; - Word32 L_corr_sq; - - Word16 corr_sq_hi_fx; - Word32 L_corr_sq_tmp; - Word32 L_lagCorr_sq_tmp; - Word16 corr_sq_fx; - Word16 lagCorr_sq_fx; - Word32 L_energy_tmp; - Word32 L_lagEnergy_tmp; - Word16 energy_fx; - Word16 lagEnergy_fx; - - Word16 N1_fx, N2_fx; - Word16 exp_safe_e; - - Word16 exp_corr; - Word16 exp_energy; - - Word32 L_buf; - - Word16 ibuf_fx[L_FRAME32k]; - Word16 pbuf_fx[L_FRAME32k]; - Word16 *ptr_pbuf; - Word16 exp_shift; - - Word16 exp_norm; - - Word32 L_tmp; - - exp_safe_e = 4; - - L_tmp = L_deposit_l(0); - FOR(i=0; i Overflow */ - L_corr_sq = L_shl(L_corr, exp_norm); - corr_sq_hi_fx = extract_h(L_corr_sq); - L_corr_sq = L_mult(corr_sq_hi_fx, corr_sq_hi_fx); /* (((Qhi:Qsh+exp_norm_hi-16)+Qss+1)+exp_norm-16)*2+1 */ - L_corr_sq = L_shr(L_corr_sq, s_min(shl(exp_norm, 1), 31)); /* (QCorr-16)*2+1 */ - - IF(Overflow != 0) - { - L_corr_sq = 0x0L; - move16(); - Overflow = 0; - move16(); - } - - /* normalize for L_lagCorr_sq and L_corr_sq */ - L_buf = L_or(L_lagCorr_sq, L_corr_sq); - exp_corr = norm_l(L_buf); - L_corr_sq_tmp = L_shl(L_corr_sq, exp_corr); - L_lagCorr_sq_tmp = L_shl(L_lagCorr_sq, exp_corr); - corr_sq_fx = extract_h(L_corr_sq_tmp); - lagCorr_sq_fx = extract_h(L_lagCorr_sq_tmp); - - /* normalize for L_lagEnergy and L_energy */ - L_buf = L_or(L_lagEnergy, L_energy); - exp_energy = norm_l(L_buf); - L_energy_tmp = L_shl(L_energy, exp_energy); - L_lagEnergy_tmp = L_shl(L_lagEnergy, exp_energy); - energy_fx = extract_h(L_energy_tmp); - lagEnergy_fx = extract_h(L_lagEnergy_tmp); - - /*if( (double)lagCorr_sq*(double)energy < (double)corr_sq*(double)lagEnergy ) */ - IF (L_msu(L_mult(lagCorr_sq_fx, energy_fx), corr_sq_fx, lagEnergy_fx) < 0) - { - bestIdx_fx = i; - move16(); - L_lagCorr_sq = L_add(L_corr_sq, 0); - L_lagEnergy = L_add(L_energy, 0); - } - - } - predBuf_fx++; - ptr_pbuf++; - } - - test(); - IF( L_lagCorr_sq == 0x0 && *prev_frame_bstindx_fx < 0 ) - { - bestIdx_fx = 0x0; - move16(); - } - ELSE - { - if( L_lagCorr_sq == 0x0 ) - { - bestIdx_fx = *prev_frame_bstindx_fx; - move16(); - } - } - - *prev_frame_bstindx_fx = bestIdx_fx; - move16(); - - return bestIdx_fx; -} - -/*--------------------------------------------------------------------------* - * getswbindices_har() - * - * Finds the pulse index of best correlation between highband (*yos) and lowband (*y2) for two groups of length sbLen - *--------------------------------------------------------------------------*/ - -static void getswbindices_har_fx( - const Word32 *L_yos, /* i : original input spectrum */ - Word16 exp_refBuf, /* i : */ - Word16 *y2_fx, /* i : decoded spectrum */ - const Word16 nBands_search_fx, /* i : number of bands */ - Word16 *lagIndices_fx, /* o : pulse index */ - Word16 *prev_frame_bstindx_fx, /* i/o: prev frame index */ - const Word16 swb_lowband_fx, /* i : length of the LF spectrum */ - const Word16 *subband_offsets_fx, /* i : */ - const Word16 *sbWidth_fx, /* i : */ - const Word16 *subband_search_offset_fx /* i : */ -) -{ - Word16 i, j, k, sb, tmp; - Word16 *ptr_predBuf; - GainItem_fx Nbiggest_fx[(NB_SWB_SUBBANDS_HAR_SEARCH_SB)*N_NBIGGEST_PULSEARCH]; - Word16 n_nbiggestsearch_fx[NB_SWB_SUBBANDS_HAR]; - - Word16 search_offset_fx[NB_SWB_SUBBANDS_HAR_SEARCH_SB]; - Word16 nlags_fx[NB_SWB_SUBBANDS_HAR_SEARCH_SB]; - - Word16 low_freqsgnl_fx[L_FRAME32k]; /* Qy2 (sspectra) */ - - ptr_predBuf = y2_fx; - - /* Get the number of HF groups for performing Similarity search */ - FOR( sb = 0; sb < nBands_search_fx; sb++ ) - { - /*nlags[sb] = (short)pow(2, bits_lagIndices_mode0_Har[sb]); */ - nlags_fx[sb] = shl(1, bits_lagIndices_mode0_Har_fx[sb]); - } - - j = 0; - move16(); - FOR( sb=0; sb tmp; j-- ) - { - low_freqsgnl_fx[k] = y2_fx[j]; - k = add(k, 1); - } - } - /* correlation b/w HF spectrum Group1 of length sbLen and decoded LF spectrum */ - lagIndices_fx[sb] = (Word16)GetSubbandCorrIndex2_har_fx( L_yos + add(swb_lowband_fx, subband_offsets_fx[sb]), - sbWidth_fx[sb], - low_freqsgnl_fx, - add(sbWidth_fx[sb], nlags_fx[sb]), - nlags_fx[sb], Nbiggest_fx+(sb*N_NBIGGEST_PULSEARCH), - n_nbiggestsearch_fx[sb], &prev_frame_bstindx_fx[sb] - ); - } - - return; -} - -static Word16 GetSubbandCorrIndex2_pulsestep_fx( - const Word32 *L_inBuf, /* i: original input vector (highband) */ - const Word16 *predBuf_fx, /* i: spectrum smoothing vector */ - const Word16 *predBufMa_fx, /* i: moving averaged spectrum smoothing vector Q=Qss */ - const Word16 fLen, /* i: subband length of highband */ - const Word16 maxLag, /* i: number of search pulse number */ - const GainItem_fx *gi_fx, /* i: lag gain structure */ - const Word16 nZero, /* i: */ - const Word16 ssearch_buflim, /* i: length of search buffer */ - const Word16 *predBuf_ni_fx /* i: spectrum including noise smoothing vector */ -) -{ - Word16 i, j; - Word16 absPos_fx; - Word16 bestIdx_fx; - Word32 L_lagCorr_sq; - Word32 L_lagEnergy; - - const Word16 *ptr_predBuf; - const Word16 *ptr_predBuf_ni; - - Word32 L_energy; - Word32 L_corr; - Word16 corr_fx; - - Word32 L_corr_sq; - - - Word16 hiBuf_fx[L_FRAME32k]; - Word16 exp_norm_hi; - - Word16 exp_norm; - Word32 L_corr_sq_tmp; - Word32 L_lagCorr_sq_tmp; - Word16 corr_sq_fx; - Word16 lagCorr_sq_fx; - Word32 L_energy_tmp; - Word32 L_lagEnergy_tmp; - Word16 energy_fx; - Word16 lagEnergy_fx; - - Word16 ib_flag_fx; - - Word32 L_buf; - Word32 L_buf2; - Word32 L_temp; - - Word16 ssBuf_fx[L_FRAME32k]; - Word16 ssBuf_ni_fx[L_FRAME32k]; - Word16 *ptr_ssBuf_ni_fx; - Word16 exp_norm_ss; - - set16_fx(hiBuf_fx, 0x0, L_FRAME32k); - set16_fx(ssBuf_fx, 0x0, L_FRAME32k); - - ib_flag_fx = 0; - move16(); - - absPos_fx = 0; - move16(); - bestIdx_fx = -1; - move16(); - L_lagCorr_sq = L_deposit_l(0); - L_lagEnergy = 0x7FFFFFFFL; - move32(); - - ptr_predBuf = predBuf_fx; - ptr_predBuf_ni = predBuf_ni_fx; - - /* This part must be computed on parent function. */ - exp_norm_ss = 2; - move16(); - - j = add(ssearch_buflim,fLen); - FOR (i=0; i Overflow */ - L_corr_sq = L_shl(L_corr, exp_norm); - corr_fx = extract_h(L_corr_sq); - L_corr_sq = L_mult(corr_fx, corr_fx); /* (((Qhi:Qsh+exp_norm_hi-16)+Qss+1)+exp_norm-16)*2+1 */ - L_corr_sq = L_shr(L_corr_sq, s_min(shl(exp_norm, 1), 31)); /* (QCorr-16)*2+1 */ - - /*if( (lagCorr_sq == 0.0f && corr_sq == 0.0f) || (double)lagCorr_sq*(double)energy < (double)corr_sq*(double)lagEnergy ) */ - /*{ */ - /* bestIdx = i; */ - /* bestAbsPos = absPos; */ - /* lagCorr_sq = corr_sq; */ - /* lagCorr = corr; */ - /* lagEnergy = energy; */ - /*} */ - /* normalize for L_lagCorr_sq and L_corr_sq */ - L_buf = L_or(L_lagCorr_sq, L_corr_sq); - exp_norm = norm_l(L_buf); /* overflow allowed */ - L_corr_sq_tmp = L_shl(L_corr_sq, exp_norm); - L_lagCorr_sq_tmp = L_shl(L_lagCorr_sq, exp_norm); - corr_sq_fx = extract_h(L_corr_sq_tmp); - lagCorr_sq_fx = extract_h(L_lagCorr_sq_tmp); - - /* normalize for L_lagEnergy and L_energy */ - L_buf = L_or(L_lagEnergy, L_energy); - exp_norm = norm_l(L_buf); /* overflow allowed */ - L_energy_tmp = L_shl(L_energy, exp_norm); - L_lagEnergy_tmp = L_shl(L_lagEnergy, exp_norm); - energy_fx = extract_h(L_energy_tmp); - lagEnergy_fx = extract_h(L_lagEnergy_tmp); - - L_buf = L_or(L_lagCorr_sq, L_corr_sq); - L_buf2 = L_msu(L_mult(lagCorr_sq_fx, energy_fx), corr_sq_fx, lagEnergy_fx); - test(); - IF( L_buf == 0 || L_buf2 < 0 ) - { - bestIdx_fx = i; - move16(); - L_lagCorr_sq = L_add(L_corr_sq, 0); - L_lagEnergy = L_add(L_energy, 0); - } - } - ptr_predBuf++; - ptr_ssBuf_ni_fx++; - ptr_predBuf_ni++; - absPos_fx++; - - WHILE( *ptr_predBuf == 0 && sub(absPos_fx, ssearch_buflim) < 0 ) - { - ptr_predBuf++; - ptr_ssBuf_ni_fx++; - ptr_predBuf_ni++; - absPos_fx = add(absPos_fx, 1); - } - - IF( sub(absPos_fx, ssearch_buflim) >= 0 ) - { - if( sub(bestIdx_fx, -1) == 0 ) - { - ib_flag_fx = 1; - move16(); - } - - BREAK; - } - } - - IF( sub(ib_flag_fx, 1) == 0 ) - { - bestIdx_fx = 0; - move16(); - } - - return bestIdx_fx; -} - -static void GetSWBIndices_fx( - const Word16 *predBuf_fx, /* i : low-frequency band */ - /*const Word16 Qss,*/ /* i : Q value of predBuf_fx */ - const Word32 *L_targetBuf, /* i : SWB MDCT coeff. */ - const Word16 Qsh, /* i : Q value of L_targetBuf */ - const Word16 nBands_search, /* i : number of search subbands */ - const Word16 *sbWidth, /* i : subband lengths */ - Word16 *lagIndices, /* o : selected lags for subband coding */ - const Word16 predBufLen, /* i : low-frequency band length */ - GainItem_fx *gi_fx, /* o : most representative region */ - const Word16 *subband_offsets, /* o : N biggest components */ - Word16 *predBuf_ni_fx /* i : low-frequency band filled noise */ -) -{ - Word16 j; - Word16 sb, tmp; - Word16 sbLen; - Word16 n_nbiggestsearch_fx[NB_SWB_SUBBANDS]; - Word16 ssearch_buflim_fx; - Word16 search_offset_fx[NB_SWB_SUBBANDS]; - Word16 nlags_fx[NB_SWB_SUBBANDS]; - - Word16 exp_refBuf; - Word16 sspectra_ma_fx[L_FRAME32k]; - - - Word32 L_temp; - - - /* Initializations */ - exp_refBuf = Qsh; - - j = 0; - move16(); - FOR (sb = 0; sb < nBands_search; sb++) - { - FindNBiggest2_simple_fx_har( L_targetBuf + subband_offsets[sb], exp_refBuf, gi_fx+j, sbWidth[sb], &n_nbiggestsearch_fx[sb], N_NBIGGEST_PULSEARCH ); - - j = add(j, N_NBIGGEST_PULSEARCH); - move16(); - } - - /* Selection of most representative subband (full search) */ - FOR ( sb = 0; sb < nBands_search; sb++ ) - { - nlags_fx[sb] = shl(1, bits_lagIndices_modeNormal_fx[sb]); - move16(); - } - - FOR ( sb = 0; sb < nBands_search; sb++ ) - { - search_offset_fx[sb] = subband_search_offsets_fx[sb]; - move16(); - } - - sspectra_ma_fx[0] = add(shr(predBuf_ni_fx[0],1), shr(predBuf_ni_fx[1],1)); - tmp = sub(predBufLen, 1); - FOR( sb=1; sb < tmp; sb++ ) - { - /*sspectra_ma[sb] = (predBuf[sb-1] + predBuf[sb] + predBuf[sb+1])/3.0f; */ - L_temp = L_mult(predBuf_ni_fx[sb], 10922); /* 10922 = 0.33333 (Q15) */ - L_temp = L_add(L_temp, L_mult(predBuf_ni_fx[sb-1], 10922)); - L_temp = L_add(L_temp, L_mult(predBuf_ni_fx[sb+1], 10922)); /* Qss+15+1 */ - sspectra_ma_fx[sb] = round_fx(L_temp); - } - sspectra_ma_fx[sb] = add(shr(predBuf_ni_fx[sb-1],1), shr(predBuf_ni_fx[sb],1)); - - /* Partial search for rest of subbands except the last which is fixed */ - FOR ( sb=0; sb 0x0 ) - { - L_temp = L_deposit_l(sqrt_fx); - - exp = norm_l(L_temp); - frac = Log2_norm_lc(L_shl(L_temp, exp)); - exp = sub(30, exp); - exp = sub(exp, Qsqrt); - L_temp = L_Comp(exp, frac); - - L_temp = Mpy_32_16_1(L_temp, 19728); /* log(2)/log(10)=.30102999566398119521 = 19728.3(Q16) Q(0+16+1)=Q17 */ - L_temp = L_shl(L_temp, 13); /* Q17+13=30 30-16=14 */ - g_fx = round_fx(L_temp); - } - - gqlevs_fx = 4; - move16(); - dmin_fx = 32767; - move16(); - imin_fx = 0; - move16(); - - FOR (i = 0; i < gqlevs_fx; i++) - { - d_fx = abs_s(g_fx - gain_table_SWB_BWE_fx[i]); - IF (sub(d_fx, dmin_fx) < 0) - { - dmin_fx = d_fx; - move16(); - imin_fx = i; - move16(); - } - } - } - - push_indice_fx( st_fx,IND_NOISEG, imin_fx, 2); - - /*g=(float) pow (10.0f,gain_table[imin]);*/ - L_temp = L_mult(gain_table_SWB_BWE_fx[imin_fx], 27213); /* Q14+Q13+1=Q28 log(10)/log(2)=3.3219 27213.23(Q13) */ - L_temp = L_shr(L_temp, 12); /* Q28-Q12 -> Q16 */ - temp_lo = L_Extract_lc(L_temp, &temp_hi); - Qg = sub(14, temp_hi); - g_fx = extract_l(Pow2(14, temp_lo)); - g_fx = shl(g_fx, sub(11, Qg)); - - ton_ene_est_fx( - L_xSynth_har, QsL, L_be_tonal, QbeL, L_band_energy, Qbe, - band_start, band_end, band_width, fLenLow, fLenHigh, bands, har_bands, g_fx, - pk_sf_fx, Qss, pul_res_fx - ); - - return; -} - -static void EncodeSWBSubbands_fx( - Encoder_State_fx *st_fx, /* i/o: encoder state structure */ - Word32 *L_spectra, /* i/o: MDCT domain spectrum */ - Word16 QsL, /* i : Q value for L_spectra */ - const Word16 fLenLow_fx, /* i : lowband length */ - const Word16 fLenHigh_fx, /* i : highband length */ - const Word16 nBands_fx, /* i : number of subbands */ - const Word16 nBands_search_fx, /* i : number of subbands to be searched for BWE */ - const Word16 *sbWidth_fx, /* i : subband lengths */ - const Word16 *subband_offsets_fx, /* i : Subband offset for BWE */ - Word16 *lagIndices_fx, /* o : lowband index for each subband */ - const Word16 BANDS_fx, /* i : noise estimate from WB part */ - const Word16 *band_start_fx, /* i : Number subbands/Frame */ - const Word16 *band_end_fx, /* i : Band Start of each SB */ - Word32 *L_band_energy, /* i : Band end of each SB, :Qbe */ - Word16 Qbe, /* i : Q value of band energy */ - const Word16 *p2a_flags_fx, /* i : BAnd energy of each SB */ - const Word16 hqswb_clas_fx, /* i : lowband synthesis */ - Word16 *prev_frm_index_fx, /* i : clas information */ - const Word16 har_bands_fx, /* i/o: Index of the previous Frame */ - const Word16 *subband_search_offset_fx,/* i : Number of harmonic LF bands */ - Word16 *prev_frm_hfe2_fx, /* i/o: */ - Word16 *prev_stab_hfe2_fx, /* i/o: */ - const Word16 band_width_fx[], /* i : band width */ - const Word32 L_spectra_ni[], /* i : Qs noise injected spectra */ - Word16 *ni_seed_fx /* i/o: random seed */ -) -{ - Word16 i, k; - Word16 sspectra_fx[L_FRAME32k]; - Word16 sspectra_ni_fx[L_FRAME32k]; - Word16 sspectra_diff_fx[L_FRAME32k]; - Word16 Qss; /* Q value of Smoothed Spectrum low-subband */ - Word32 L_be_tonal[SWB_HAR_RAN1]; /* Q */ - Word16 ss_min_fx; /* Qss */ - Word32 L_th_g[NB_SWB_SUBBANDS]; - Word16 QbeL; - GainItem_fx pk_sf_fx[(NB_SWB_SUBBANDS)*8]; - Word16 pul_res_fx[NB_SWB_SUBBANDS]; - - GainItem_fx Nbiggest_fx[NB_SWB_SUBBANDS*N_NBIGGEST_PULSEARCH]; - - Word32 L_xSynth_har[L_FRAME32k]; /* Qs */ - - Word16 lagGains_fx[NB_SWB_SUBBANDS]; - Word16 QlagGains[NB_SWB_SUBBANDS]; - Word16 har_freq_est1,har_freq_est2; - Word16 flag_dis; - Word16 pos_max_hfe2; - - har_freq_est1 = 0; - move16(); - har_freq_est2 = 0; - move16(); - flag_dis = 1; - move16(); - pos_max_hfe2 = 0; - move16(); - - set16_fx(sspectra_fx, 0, fLenLow_fx); - set16_fx(sspectra_ni_fx, 0, fLenLow_fx); - set32_fx(L_xSynth_har, 0, L_FRAME32k); - set16_fx(pul_res_fx,0,NB_SWB_SUBBANDS); - - - IF( sub(hqswb_clas_fx, HQ_HARMONIC) == 0 ) - { - pos_max_hfe2 = har_est_fx( L_spectra, fLenLow_fx, &har_freq_est1, &har_freq_est2, &flag_dis, prev_frm_hfe2_fx, subband_search_offset_fx, sbWidth_fx, prev_stab_hfe2_fx ); - noise_extr_corcod_fx(L_spectra, L_spectra_ni, sspectra_fx, sspectra_diff_fx, sspectra_ni_fx, fLenLow_fx , st_fx->prev_hqswb_clas_fx ,&st_fx->prev_ni_ratio_fx, &Qss); - /* Find best indices for each group */ - getswbindices_har_fx( - L_spectra, - QsL, sspectra_ni_fx, - nBands_search_fx, lagIndices_fx, prev_frm_index_fx, fLenLow_fx, subband_offsets_fx, sbWidth_fx , subband_search_offset_fx); - - /* Write the indices into the bitstream */ - FOR (k = 0; k < nBands_search_fx; k++) - { - push_indice_fx( st_fx, IND_LAGINDICES, lagIndices_fx[k], bits_lagIndices_mode0_Har_fx[k]); - } - - IF ( flag_dis == 0 ) - { - test(); - if ( sub(har_freq_est2, SWB_HAR_RAN1) != 0 || sub(har_freq_est2, *prev_frm_hfe2_fx) != 0 ) - { - har_freq_est2 = add(har_freq_est2, lagIndices_fx[0]); - move16(); - } - } - - gethar_noisegn_fx( - st_fx, - L_spectra, QsL, sspectra_diff_fx, Qss, L_xSynth_har, - sbWidth_fx, lagIndices_fx, BANDS_fx, har_bands_fx, fLenLow_fx, fLenHigh_fx, - subband_offsets_fx, subband_search_offset_fx, band_start_fx, band_end_fx, band_width_fx, - L_band_energy, Qbe, L_be_tonal, &QbeL, sspectra_fx, - har_freq_est2, pos_max_hfe2, pul_res_fx, pk_sf_fx); - - - Gettonl_scalfact_fx( - L_xSynth_har, QsL, L_spectra_ni, fLenLow_fx, fLenHigh_fx, har_bands_fx, BANDS_fx, L_band_energy, Qbe, band_start_fx, band_end_fx, - p2a_flags_fx, L_be_tonal, QbeL, pk_sf_fx ,Qss, pul_res_fx); - - IF( flag_dis == 0 ) - { - *prev_frm_hfe2_fx = 0; - move16(); - } - ELSE - { - *prev_frm_hfe2_fx = har_freq_est2; - move16(); - } - - FOR( k = BANDS_fx - NB_SWB_SUBBANDS; k < BANDS_fx; k++ ) - { - FOR( i = band_start_fx[k]; i <= band_end_fx[k]; i++ ) - { - L_spectra[i] = L_xSynth_har[i-fLenLow_fx]; - move32(); /* QsL */ - } - } - } - ELSE - { - ss_min_fx = spectrumsmooth_noiseton_fx( - L_spectra, /*QsL,*/ L_spectra_ni, sspectra_fx, sspectra_diff_fx, sspectra_ni_fx, &Qss, fLenLow_fx, ni_seed_fx); - - /* Get lag indices */ - GetSWBIndices_fx( sspectra_fx, /*Qss,*/ - L_spectra + fLenLow_fx, QsL, - nBands_fx, sbWidth_fx, lagIndices_fx, fLenLow_fx, - Nbiggest_fx, subband_offsets_fx, sspectra_fx - ); - - /* Bitstream operations */ - FOR(k=0; k QsL */ - } - } - - GetSynthesizedSpecThinOut_fx(sspectra_ni_fx, Qss, L_xSynth_har, QsL, nBands_fx, sbWidth_fx, lagIndices_fx, lagGains_fx, QlagGains, fLenLow_fx); - - /*Level adjustment for the missing bands*/ - noiseinj_hf_fx( - L_xSynth_har, QsL, L_th_g, L_band_energy, Qbe, - st_fx->prev_En_sb_fx, - p2a_flags_fx, BANDS_fx, band_start_fx, band_end_fx, fLenLow_fx, fLenHigh_fx); - - - FOR( k = BANDS_fx - NB_SWB_SUBBANDS; k < BANDS_fx; k++ ) - { - IF( p2a_flags_fx[k] == 0 ) - { - FOR( i = band_start_fx[k]; i <= band_end_fx[k]; i++ ) - { - L_spectra[i] = L_xSynth_har[i-fLenLow_fx]; - move32(); /* Qob */ - } - } - ELSE - { - FOR( i = band_start_fx[k]; i <= band_end_fx[k]; i++ ) - { - L_spectra[i] = L_spectra_ni[i]; - move32(); - } - } - } - } - - return; -} - -void swb_bwe_enc_lr_fx( - Encoder_State_fx *st_fx, /* i/o: encoder state structure */ - const Word32 L_m_core[], /* i : lowband synthesis */ - Word16 QsL, /* i : Q value */ - const Word32 L_m_orig[], /* i/o: scaled orig signal (MDCT) */ - Word32 L_m[], /* o : highband synthesis with lowband zeroed */ - const Word32 L_total_brate, /* i : total bitrate for selecting subband pattern */ - Word16 BANDS_fx, /* i : Total number of Subbands in a frame */ - Word16 *band_start_fx, /* i : band start of each SB */ - Word16 *band_end_fx, /* i : band end of each SB */ - Word32 *L_band_energy, /* i : band_energy of each SB */ - Word16 Qbe, /* i : Q value of band energy */ - Word16 *p2a_flags_fx, /* i : HF tonal indicator */ - const Word16 hqswb_clas_fx, /* i : HQ_NORMAL2 or HQ_HARMONIC mode */ - Word16 lowlength_fx, /* i : lowband length */ - Word16 highlength_fx, /* i : highband length */ - Word16 *prev_frm_index_fx, /* i/o: previous frame lag index for harmonic mode */ - const Word16 har_bands_fx, /* i : Number of LF harmonic bands */ - Word16 *prev_frm_hfe2, /* i/o: */ - Word16 *prev_stab_hfe2, /* i/o: */ - const Word16 band_width_fx[], /* i : band_width information */ - const Word32 L_y2_ni[], /* i : band_width information */ - Word16 *ni_seed_fx /* i/o: random seed for search buffer NI */ -) -{ - Word16 k; - Word16 nBands_fx; - Word16 nBands_search_fx; - Word16 wBands_fx[NB_SWB_SUBBANDS]; - Word16 lagIndices_fx[NB_SWB_SUBBANDS]; - Word16 swb_lowband_fx, swb_highband_fx, allband_fx; - - const Word16 *subband_offsets_fx; - const Word16 *subband_search_offset_fx; - - Word32 *p_L_m; - - subband_search_offset_fx = subband_search_offsets_13p2kbps_Har_fx; - subband_offsets_fx = subband_offsets_sub5_13p2kbps_Har_fx; - - hf_parinitiz_fx(L_total_brate,hqswb_clas_fx,lowlength_fx,highlength_fx,wBands_fx,&subband_search_offset_fx,&subband_offsets_fx,&nBands_fx,&nBands_search_fx,&swb_lowband_fx,&swb_highband_fx); - allband_fx = add(swb_lowband_fx, swb_highband_fx); - move16(); - - /* Prepare m[], low part from WB core, high part from 32k input */ - Copy32( L_m_core, L_m, swb_lowband_fx ); - Copy32(&L_m_orig[swb_lowband_fx], &L_m[swb_lowband_fx], swb_highband_fx ); - - EncodeSWBSubbands_fx( - st_fx, - L_m, QsL, - swb_lowband_fx, swb_highband_fx, nBands_fx, nBands_search_fx, wBands_fx, subband_offsets_fx, - lagIndices_fx, - BANDS_fx, band_start_fx, band_end_fx, - L_band_energy, Qbe, - p2a_flags_fx, - hqswb_clas_fx, prev_frm_index_fx, har_bands_fx, subband_search_offset_fx, - prev_frm_hfe2, prev_stab_hfe2, - band_width_fx, L_y2_ni, ni_seed_fx - ); - - p_L_m = &L_m[sub(allband_fx, 1)]; - *p_L_m = Mult_32_16(*p_L_m, 2028); - move32(); - p_L_m--; /* 0.0625 = 2028 (Q15) */ - *p_L_m = Mult_32_16(*p_L_m, 4096); - move32(); - p_L_m--; /* 0.125 = 4096 (Q15) */ - *p_L_m = Mult_32_16(*p_L_m, 8192); - move32(); - p_L_m--; /* 0.25 = 8192 (Q15) */ - *p_L_m = Mult_32_16(*p_L_m, 16384); - move32(); - p_L_m--; /* 0.5 = 16384 (Q15) */ - - /* set low frequencies to zero */ - FOR ( k = 0; k < swb_lowband_fx; k++ ) - { - L_m[k] = L_deposit_l(0); - } - - return; -} diff --git a/src/libs/libevs/lib_enc/swb_pre_proc.cpp b/src/libs/libevs/lib_enc/swb_pre_proc.cpp new file mode 100644 index 00000000..579f5c58 --- /dev/null +++ b/src/libs/libevs/lib_enc/swb_pre_proc.cpp @@ -0,0 +1,310 @@ +/*==================================================================================== + EVS Codec 3GPP TS26.443 Nov 13, 2018. Version 12.11.0 / 13.7.0 / 14.3.0 / 15.1.0 + ====================================================================================*/ + +#include +#include +#include "options.h" +#include "cnst.h" +#include "prot.h" +#include "rom_com.h" +#include "rom_enc.h" + + +/*-------------------------------------------------------------------* + * Local constants + * + *-------------------------------------------------------------------*/ + +#define CLDFB_NO_CHANNELS_HB 20 + + +/*-------------------------------------------------------------------* + * wb_pre_proc() + * + * - Resampling of input signal when input signal sampling rate + * is above 16kHz + * - Common WB TBE and WB BWE pre-processing + *-------------------------------------------------------------------*/ + +void wb_pre_proc( + Encoder_State *st, /* i/o: encoder state structure */ + const float *new_inp_resamp16k, /* i : original input signal */ + float *hb_speech /* o : HB target signal (6-8kHz) at 16kHz */ +) +{ + short Sample_Delay_WB_BWE, ramp_flag; + float old_input[NS2SA(16000, DELAY_FD_BWE_ENC_NS + DELAY_FIR_RESAMPL_NS) + L_FRAME16k]; + float *highband_new_speech, highband_old_speech [(L_LOOK_12k8 + L_SUBFR + L_FRAME) * 5/16]; + short fSwitchFromIO = 0; + + if ( (st->last_total_brate == ACELP_6k60) || + (st->last_total_brate == ACELP_8k85) || + (st->last_total_brate == ACELP_12k65) || + (st->last_total_brate == ACELP_14k25) || + (st->last_total_brate == ACELP_15k85) || + (st->last_total_brate >= ACELP_18k25 && st->last_total_brate <= ACELP_23k85) ) + { + fSwitchFromIO = 1; + } + + set_f( old_input, 0, NS2SA(16000, DELAY_FD_BWE_ENC_12k8_NS + DELAY_FIR_RESAMPL_NS) + L_FRAME16k ); + + if ( st->extl == WB_BWE || st->extl == WB_TBE || st->igf ) + { + ramp_flag = 0; + if( (st->last_extl != WB_TBE && st->last_extl != WB_BWE && !st->igf) || (st->igf && fSwitchFromIO) ) + { + ramp_flag = 1; + } + + if ( !st->ppp_mode) + { + flip_spectrum_and_decimby4( new_inp_resamp16k, hb_speech, L_FRAME16k, st->decim_state1, st->decim_state2, ramp_flag ); + + if( st->extl != WB_TBE ) + { + /* Update the previous wideband speech buffer in case of a WB_BWE frame - this code is in wb_tbe_enc */ + Sample_Delay_WB_BWE = (L_LOOK_12k8 + L_SUBFR) * 5/16; + + highband_new_speech = highband_old_speech + Sample_Delay_WB_BWE; + mvr2r( hb_speech, highband_new_speech, L_FRAME16k / 4 ); + mvr2r( highband_old_speech + L_FRAME16k / 4, st->old_speech_wb, Sample_Delay_WB_BWE ); + } + } + } + else + { + set_f( st->decim_state1, 0.0f, (2*ALLPASSSECTIONS_STEEP+1) ); + set_f( st->decim_state2, 0.0f, (2*ALLPASSSECTIONS_STEEP+1) ); + set_f( st->old_speech_wb, 0.0f, (L_LOOK_12k8 + L_SUBFR) * 5/16 ); + } + + /* st->old_input_wb and st->old_wtda_wb must be updated each frame, or there are often some clicks during WB TBE <-> WB BWE switching */ + if ( (st->extl != WB_BWE || (st->extl == WB_BWE && st->total_brate <= ACELP_8k00)) && !st->ppp_mode ) + { + Sample_Delay_WB_BWE = NS2SA( 16000, DELAY_FD_BWE_ENC_12k8_NS ); + + mvr2r( new_inp_resamp16k, &old_input[Sample_Delay_WB_BWE], L_FRAME16k ); + mvr2r( st->old_input_wb, old_input, Sample_Delay_WB_BWE ); + mvr2r( new_inp_resamp16k + L_FRAME16k - Sample_Delay_WB_BWE, st->old_input_wb, Sample_Delay_WB_BWE ); + if ((st->extl != SWB_BWE) && (st->extl != FB_BWE)) + { + mvr2r( old_input, st->old_wtda_swb, L_FRAME16k ); + } + } + + return; +} + + +/*-------------------------------------------------------------------* + * swb_pre_proc() + * + * - Calculate the 6 to 14 kHz (or 7.5 - 15.5 kHz) SHB target signal + * for SWB TBE or SWB BWE coding + * - Common SWB TBE and SWB BWE pre-processing + *-------------------------------------------------------------------*/ + +void swb_pre_proc( + Encoder_State *st, /* i/o: encoder state structure */ + const float *input, /* i : original input signal */ + float *new_swb_speech, /* o : original input signal at 32kHz */ + float *shb_speech, /* o : SHB target signal (6-14kHz) at 16kHz */ + float realBuffer[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX], /* i : real buffer */ + float imagBuffer[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX] /* i : imag buffer */ +) +{ + short Sample_Delay_SWB_BWE, inner_frame, delay; + long inner_Fs; + float old_input[NS2SA(48000, DELAY_FD_BWE_ENC_NS + DELAY_FIR_RESAMPL_NS) + L_FRAME48k]; + float spchTmp[640]; + short i, j; + short startB, endB; + float *realBufferFlipped[CLDFB_NO_COL_MAX]; + float *imagBufferFlipped[CLDFB_NO_COL_MAX]; + float realBufferTmp[CLDFB_NO_COL_MAX][20]; + float imagBufferTmp[CLDFB_NO_COL_MAX][20]; + short ts, nB, uB; + float sign; + + for( j=0; j < CLDFB_NO_COL_MAX; j++ ) + { + set_f( realBufferTmp[j], 0, 20 ); + set_f( imagBufferTmp[j], 0, 20 ); + realBufferFlipped[j] = realBufferTmp[j]; + imagBufferFlipped[j] = imagBufferTmp[j]; + } + + set_f( old_input, 0.0f, NS2SA(48000, DELAY_FD_BWE_ENC_12k8_NS + DELAY_FIR_RESAMPL_NS) + L_FRAME48k ); + + if( st->input_Fs == 32000 ) + { + mvr2r( input, new_swb_speech, L_FRAME32k ); + if( st->last_extl != SWB_BWE && st->last_extl != FB_BWE && st->extl != SWB_BWE_HIGHRATE) + { + Sample_Delay_SWB_BWE = NS2SA( 32000, DELAY_FD_BWE_ENC_12k8_NS + DELAY_FIR_RESAMPL_NS ); + mvr2r( st->old_fdbwe_speech, &old_input[Sample_Delay_SWB_BWE], L_FRAME32k ); + set_f( old_input, 0, Sample_Delay_SWB_BWE ); + mvr2r( st->old_fdbwe_speech + L_FRAME32k - Sample_Delay_SWB_BWE, st->old_input, Sample_Delay_SWB_BWE ); + mvr2r( old_input, st->old_wtda_swb, L_FRAME32k ); + } + + if( st->extl != SWB_BWE && st->extl != FB_BWE ) + { + mvr2r( input, st->old_fdbwe_speech, L_FRAME32k ); + } + } + else /* 48 kHz */ + { + if( st->codec_mode == MODE1 ) + { + if( st->extl != SWB_BWE && st->extl != FB_BWE && st->core == ACELP_CORE) + { + /* move the resampling out of the TDBWE path as new_swb_speech is not needed for TDBWE. */ + mvr2r( input, st->old_fdbwe_speech, L_FRAME48k ); + } + else + { + if( st->last_extl != SWB_BWE && st->last_extl != FB_BWE ) + { + /* resample 48 kHz to 32kHz */ + if( st->last_bwidth == FB ) + { + inner_frame = L_FRAME48k; + inner_Fs = 48000; + mvr2r( st->old_fdbwe_speech, new_swb_speech, L_FRAME48k ); + } + else + { + inner_frame = L_FRAME32k; + inner_Fs = 32000; + decimate_2_over_3_allpass( st->old_fdbwe_speech, L_FRAME48k, new_swb_speech, st->dec_2_over_3_mem, allpass_poles_3_ov_2, + decimate_3_ov_2_lowpass_num, decimate_3_ov_2_lowpass_den, st->dec_2_over_3_mem_lp ); + } + + Sample_Delay_SWB_BWE = NS2SA( inner_Fs, DELAY_FD_BWE_ENC_12k8_NS + DELAY_FIR_RESAMPL_NS ); + mvr2r( new_swb_speech, &old_input[Sample_Delay_SWB_BWE], inner_frame ); + set_f( old_input, 0, Sample_Delay_SWB_BWE ); + mvr2r( new_swb_speech + inner_frame - Sample_Delay_SWB_BWE, st->old_input, Sample_Delay_SWB_BWE ); + mvr2r( old_input, st->old_wtda_swb, inner_frame ); + } + /* resample 48 kHz to 32kHz */ + if( st->bwidth == FB ) + { + mvr2r( input, new_swb_speech, L_FRAME48k ); + } + else + { + decimate_2_over_3_allpass( input, L_FRAME48k, new_swb_speech, st->dec_2_over_3_mem, allpass_poles_3_ov_2, + decimate_3_ov_2_lowpass_num, decimate_3_ov_2_lowpass_den, st->dec_2_over_3_mem_lp ); + } + } + } + else + { + /* resample 48 kHz to 32kHz */ + if( st->bwidth == FB ) + { + mvr2r( input, new_swb_speech, L_FRAME48k ); + } + else + { + decimate_2_over_3_allpass( input, L_FRAME48k, new_swb_speech, st->dec_2_over_3_mem, allpass_poles_3_ov_2, + decimate_3_ov_2_lowpass_num, decimate_3_ov_2_lowpass_den, st->dec_2_over_3_mem_lp ); + } + } + } + + if( ( st->core == ACELP_CORE && st->extl != SWB_BWE_HIGHRATE && st->extl != FB_BWE_HIGHRATE ) || + ( ( st->total_brate == ACELP_9k60 || st->rf_mode ) && st->bwidth == SWB ) ) + { + if( st->L_frame == L_FRAME ) + { + startB= 34; + endB= 14; + for( ts = 0; ts < CLDFB_NO_COL_MAX; ts++ ) + { + for( nB = startB, uB=0; nB > endB; nB--,uB++ ) + { + sign = (ts%2) ? 1.0f : -1.0f; + realBufferFlipped[ts][uB] = -sign*realBuffer[ts][nB]; + imagBufferFlipped[ts][uB] = sign*imagBuffer[ts][nB]; + } + } + } + else + { + startB = 39; + endB = 19; + for( ts = 0; ts < CLDFB_NO_COL_MAX; ts++ ) + { + for( nB = startB, uB=0; nB > endB; nB--,uB++ ) + { + realBufferFlipped[ts][uB] = -realBuffer[ts][nB]; + imagBufferFlipped[ts][uB] = imagBuffer[ts][nB]; + } + } + } + + { + float CldfbHB = 0; + for (nB = 0; nB < 10; nB++) + { + for (ts = 0; ts < CLDFB_NO_COL_MAX; ts++) + { + CldfbHB += (realBufferFlipped[ts][nB] * realBufferFlipped[ts][nB] + imagBufferFlipped[ts][nB] * imagBufferFlipped[ts][nB]); + } + } + if( CldfbHB <= 0 ) + { + CldfbHB = 1.0f; + } + st->cldfbHBLT = 0.9f * st->cldfbHBLT + 0.1f * ( 0.221462f /*=1/log10(32768)*/ * (log10(CldfbHB) - 1.0f) ); + } + cldfbSynthesis( realBufferFlipped, imagBufferFlipped, shb_speech, -1, st->cldfbSynTd ); + + if( st->extl != WB_TBE && st->extl != SWB_TBE && st->extl != FB_TBE ) + { + /* Update the previous superwideband speech buffer in case of a SWB_BWE frame - this code is in swb_tbe_enc */ + delay = L_LOOK_16k + L_SUBFR16k; + mvr2r( shb_speech + L_FRAME16k - delay, st->old_speech_shb, delay ); + } + } + else + { + if( st->bwidth == FB || st->core == ACELP_CORE) + { + set_f( st->old_speech_shb, 0, L_LOOK_16k + L_SUBFR16k ); + set_f( shb_speech, 0, L_FRAME16k ); /* shb_speech for FB/SWB BWE_HIGHRATE is not used at 64kbps */ + } + else + { + /* flip the spectrm */ + mvr2r( new_swb_speech, spchTmp, L_FRAME32k ); + + for( i = 0; i < L_FRAME32k; i = i+2 ) + { + spchTmp[i] = -spchTmp[i]; + } + + Decimate_allpass_steep( spchTmp, st->state_ana_filt_shb, L_FRAME32k, shb_speech ); + mvr2r( shb_speech + L_FRAME16k - (L_LOOK_16k + L_SUBFR16k), st->old_speech_shb, L_LOOK_16k + L_SUBFR16k ); + } + + /* Reset CLDFB synthesis buffer */ + set_f( st->cldfbSynTd->cldfb_state, 0.0f, st->cldfbSynTd->p_filter_length + st->cldfbSynTd->no_channels*st->cldfbSynTd->no_col ); + } + + /* Memory reset to compensate for 0.9375 ms offset when transitioning from IO to SWB */ + if( st->last_extl == -1 ) + { + delay = NS2SA(st->input_Fs, DELAY_FIR_RESAMPL_NS); + for( i = 0; i < delay; i++ ) + { + shb_speech[i] = (float)i * (0.03f * shb_speech[2*delay-1-i]); + } + } + + return; +} diff --git a/src/libs/libevs/lib_enc/swb_pre_proc_fx.cpp b/src/libs/libevs/lib_enc/swb_pre_proc_fx.cpp deleted file mode 100755 index 86c31420..00000000 --- a/src/libs/libevs/lib_enc/swb_pre_proc_fx.cpp +++ /dev/null @@ -1,432 +0,0 @@ -/*==================================================================================== - EVS Codec 3GPP TS26.442 Apr 03, 2018. Version 12.11.0 / 13.6.0 / 14.2.0 - ====================================================================================*/ - -#include -#include "options.h" -#include "cnst_fx.h" -#include "prot_fx.h" -#include "rom_com_fx.h" -#include "stl.h" -#include "basop_util.h" - -#include - -/*========================================================================*/ -/* FUNCTION : wb_pre_proc_fx() */ -/*------------------------------------------------------------------------*/ -/* PURPOSE : Resampling of input signal when input signal sample rate */ -/* is above 16kHz */ -/*------------------------------------------------------------------------*/ -/* INPUT ARGUMENTS : */ -/* Encoder_State_fx *st_fx : Encoder State Structure */ -/* _ (Word16*) input : original input signal */ -/*------------------------------------------------------------------------*/ -/* INPUT/OUTPUT ARGUMENTS : */ -/* _None */ -/*------------------------------------------------------------------------*/ -/* OUTPUT ARGUMENTS : */ -/* _ (Word16*) new_wb_speech : original input signal at 16kHz Q-1 */ -/*------------------------------------------------------------------------*/ - -/* st_fx->old_wtda_wb_fx */ -/*------------------------------------------------------------------------*/ -/* RETURN ARGUMENTS : */ -/* _ None */ -/*========================================================================*/ - -void wb_pre_proc_fx( - Encoder_State_fx *st_fx, /* i/o: encoder state structure */ - const Word16 *new_inp_resamp16k, /* i : original input signal in Q-1 */ - Word16 *hb_speech /* o : HB target signal (6-8kHz) at 16kHz in Q-1 */ -) -{ - Word16 Sample_Delay_WB_BWE; - Word16 ramp_flag; - Word16 old_input[NS2SA(16000, DELAY_FD_BWE_ENC_NS + DELAY_FIR_RESAMPL_NS) + L_FRAME16k]; - Word16 *highband_new_speech; - Word16 highband_old_speech[(L_LOOK_12k8+L_SUBFR+L_FRAME)*5/16]; - Word16 temp_buf[320]; - Word16 Q_wb_sp, i, max_wb; - Word16 fSwitchFromIO = 0; - Word32 temp1 = 0; - Word32 temp2 = 0; - - test(); - test(); - test(); - test(); - test(); - test(); - IF ( (L_sub(st_fx->last_total_brate_fx, ACELP_6k60)==0) || - (L_sub(st_fx->last_total_brate_fx, ACELP_8k85)==0) || - (L_sub(st_fx->last_total_brate_fx, ACELP_12k65)==0) || - (L_sub(st_fx->last_total_brate_fx, ACELP_14k25)==0) || - (L_sub(st_fx->last_total_brate_fx, ACELP_15k85)==0) || - (L_sub(st_fx->last_total_brate_fx, ACELP_18k25)>=0 && L_sub(st_fx->last_total_brate_fx, ACELP_23k85)<=0) ) - { - fSwitchFromIO = 1; - move16(); - } - - set16_fx( old_input, 0, NS2SA_fx2(16000, DELAY_FD_BWE_ENC_12k8_NS + DELAY_FIR_RESAMPL_NS) + L_FRAME16k ); - - max_wb = 1; - move16(); - FOR (i = 0; i < L_FRAME16k; i++ ) - { - max_wb = s_max(max_wb, abs_s(new_inp_resamp16k[i])); - } - Q_wb_sp = norm_s(max_wb); - - Copy_Scale_sig(new_inp_resamp16k, temp_buf, L_FRAME16k, -3); - temp1 = L_mac0(temp1, temp_buf[0], temp_buf[0]); - FOR (i = 1; i < L_FRAME16k; i++) - { - temp1 = L_mac0(temp1, temp_buf[i], temp_buf[i]); - temp2 = L_mac0(temp2, temp_buf[i-1], temp_buf[i]); - } - - if( temp2 < Mult_32_16(temp1, 31129 /*0.95f*/) ) - { - Q_wb_sp = sub(Q_wb_sp, 3); /* leave 3 bit headroom */ - } - Copy_Scale_sig(new_inp_resamp16k, temp_buf, L_FRAME16k, Q_wb_sp); - Scale_sig(st_fx->decim_state1_fx, (2*ALLPASSSECTIONS_STEEP+1), Q_wb_sp); - Scale_sig(st_fx->decim_state2_fx, (2*ALLPASSSECTIONS_STEEP+1), Q_wb_sp); - /* temp_buf, and the memory states are in Q_wb_sp */ - - test(); - test(); - IF ( sub(st_fx->extl_fx, WB_BWE) == 0 || sub(st_fx->extl_fx, WB_TBE) == 0 || st_fx->igf != 0 ) - { - ramp_flag = 0; - - test(); - test(); - test(); - test(); - IF( (sub(st_fx->last_extl_fx, WB_TBE) != 0 && sub(st_fx->last_extl_fx, WB_BWE) != 0 && st_fx->igf == 0) || - (st_fx->igf != 0 && fSwitchFromIO != 0) ) - { - ramp_flag = 1; - } - - IF ( !st_fx->ppp_mode_fx) - { - /* temp_buf is in Q_wb_sp - hb_speech and the two decimator memories are in Q_wb_sp */ - flip_spectrum_and_decimby4_fx( temp_buf, hb_speech, L_FRAME16k, st_fx->decim_state1_fx, st_fx->decim_state2_fx, ramp_flag ); - - /* rescale the hb_speech and memories back to Q-1 to keep the downstream BWE coding unaffected */ - Scale_sig(hb_speech, L_FRAME16k/4, -Q_wb_sp); - Scale_sig(st_fx->decim_state1_fx, (2*ALLPASSSECTIONS_STEEP+1), -Q_wb_sp); - Scale_sig(st_fx->decim_state2_fx, (2*ALLPASSSECTIONS_STEEP+1), -Q_wb_sp); - - IF( sub(st_fx->extl_fx, WB_TBE) != 0 ) - { - /* Update the previous wideband speech buffer in case of a WB_BWE frame */ - Sample_Delay_WB_BWE = (L_LOOK_12k8 + L_SUBFR) * 5/16; - - highband_new_speech = highband_old_speech + Sample_Delay_WB_BWE; - Copy( hb_speech, highband_new_speech, L_FRAME16k / 4 ); - Copy( highband_old_speech + L_FRAME16k / 4, st_fx->old_speech_wb_fx, Sample_Delay_WB_BWE ); - } - } - } - ELSE - { - set16_fx( st_fx->decim_state1_fx, 0, (2*ALLPASSSECTIONS_STEEP+1) ); - set16_fx( st_fx->decim_state2_fx, 0, (2*ALLPASSSECTIONS_STEEP+1) ); - set16_fx( st_fx->old_speech_wb_fx, 0, (L_LOOK_12k8 + L_SUBFR) * 5/16 ); - } - - /* st->old_input_wb and st->old_wtda_wb must be updated each frame, or there are often some clicks during WB TBE <-> WB BWE switching */ - test(); - test(); - test(); - IF ( (sub(st_fx->extl_fx, WB_BWE) != 0 || (sub(st_fx->extl_fx, WB_BWE) == 0 && L_sub(st_fx->total_brate_fx, ACELP_8k00) <= 0)) && !st_fx->ppp_mode_fx ) - { - Sample_Delay_WB_BWE = NS2SA_fx2( 16000, DELAY_FD_BWE_ENC_12k8_NS ); - - Copy( new_inp_resamp16k, &old_input[Sample_Delay_WB_BWE], L_FRAME16k ); - Copy( st_fx->old_input_wb_fx, old_input, Sample_Delay_WB_BWE ); - Copy( new_inp_resamp16k + L_FRAME16k - Sample_Delay_WB_BWE, st_fx->old_input_wb_fx, Sample_Delay_WB_BWE ); - Copy( old_input, st_fx->L_old_wtda_swb_fx, L_FRAME16k ); - } - return; -} - - -/*========================================================================*/ -/* FUNCTION : swb_pre_proc_fx() */ -/*------------------------------------------------------------------------*/ -/* PURPOSE : Calculate the 6 to 14 kHz (or 7.5 - 15.5 kHz) */ -/* SHB target signal for SWB TBE or SWB BWE coding */ -/* Common SWB TBE and SWB BWE pre-processing */ -/*------------------------------------------------------------------------*/ -/* INPUT ARGUMENTS : */ -/* Encoder_State_fx *st_fx : Encoder State Structure Q0 */ -/* _ (Word16*) input_fx : original input signal Q0 */ -/*------------------------------------------------------------------------*/ -/* INPUT/OUTPUT ARGUMENTS : */ -/* _None */ -/*------------------------------------------------------------------------*/ -/* OUTPUT ARGUMENTS : */ -/* _ (Word16*) new_swb_speech_fx : original input signal at 16kHz Q0 */ -/* _ (Word16*) shb_speech_fx : original input signal at 16kHz Q0 */ -/*------------------------------------------------------------------------*/ - -/* st_fx->old_input_fx */ -/* st_fx->old_wtda_shb_fx */ -/*------------------------------------------------------------------------*/ -/* RETURN ARGUMENTS : */ -/* _ None */ -/*========================================================================*/ - -void swb_pre_proc_fx( - Encoder_State_fx *st_fx, /* i/o: encoder state structure */ - const Word16 *input_fx, /* i : original input signal */ - Word16 *new_swb_speech_fx, /* o : original input signal at 32kHz */ - Word16 *shb_speech_fx, /* o : SHB target signal (6-14kHz) at 16kHz */ - Word16 *Q_shb_spch, - Word32 realBuffer[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX], /* i : real CLDFB buffer for target synthesis */ - Word32 imagBuffer[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX], /* i : imag CLDFB buffer for target synthesis */ - const CLDFB_SCALE_FACTOR *cldfbScale /* i : scale data of real and imag CLDFB buffers */ -) -{ - Word16 Sample_Delay_SWB_BWE, delay; - Word16 inner_frame; - UWord16 inner_Fs; - Word16 old_input_fx[NS2SA(48000, DELAY_FD_BWE_ENC_NS + DELAY_FIR_RESAMPL_NS) + L_FRAME48k]; - Word16 spchTmp_fx[L_FRAME32k]; - Word16 i; - Word16 startB, endB; - Word16 j; - Word32 *realBufferFlipped[CLDFB_NO_COL_MAX]; - Word32 *imagBufferFlipped[CLDFB_NO_COL_MAX]; - Word32 realBufferTmp[CLDFB_NO_COL_MAX][20]; - Word32 imagBufferTmp[CLDFB_NO_COL_MAX][20]; - Word32 cldfbWorkBuffer[256]; - Word16 ts, nB, uB; - /* Highband energy computation using CLDFB */ - Word32 CldfbHB_ener; - Word16 realQ_neg1, imagQ_neg1, exp, Cldfbtemp1; - - FOR( j=0; j < CLDFB_NO_COL_MAX; j++ ) - { - set32_fx(realBufferTmp[j], 0, 20); - set32_fx(imagBufferTmp[j], 0, 20); - realBufferFlipped[j] = realBufferTmp[j]; - imagBufferFlipped[j] = imagBufferTmp[j]; - } - - set16_fx( old_input_fx, 0, NS2SA_fx2(48000, DELAY_FD_BWE_ENC_12k8_NS + DELAY_FIR_RESAMPL_NS) + L_FRAME48k ); - - IF( L_sub(st_fx->input_Fs_fx, 32000) == 0 ) - { - Copy(input_fx, new_swb_speech_fx, L_FRAME32k); /*Q0 */ - test(); - test(); - IF( sub(st_fx->last_extl_fx, SWB_BWE) != 0 && sub(st_fx->last_extl_fx, FB_BWE) != 0 && sub(st_fx->extl_fx, SWB_BWE_HIGHRATE) != 0 ) - { - Sample_Delay_SWB_BWE = NS2SA_fx2( 32000, DELAY_FD_BWE_ENC_12k8_NS + DELAY_FIR_RESAMPL_NS ); - Copy( st_fx->old_fdbwe_speech_fx, &old_input_fx[Sample_Delay_SWB_BWE], L_FRAME32k ); - set16_fx( old_input_fx, 0, Sample_Delay_SWB_BWE ); - Copy( st_fx->old_fdbwe_speech_fx + L_FRAME32k - Sample_Delay_SWB_BWE, st_fx->old_input_fx, Sample_Delay_SWB_BWE ); - - Copy( old_input_fx, st_fx->L_old_wtda_swb_fx, L_FRAME32k ); - } - - test(); - IF( sub(st_fx->extl_fx, SWB_BWE) != 0 && sub(st_fx->extl_fx, FB_BWE) != 0 ) - { - Copy( input_fx, st_fx->old_fdbwe_speech_fx, L_FRAME32k ); - } - } - ELSE /* 48 kHz */ - { - /* 48kHz sampled processing needs review of FD2 memory handling/Q-factors */ - IF( sub(st_fx->codec_mode,MODE1) == 0 ) - { - test(); - test(); - IF( sub(st_fx->extl_fx,SWB_BWE) != 0 && sub(st_fx->extl_fx,FB_BWE) != 0 && sub(st_fx->core_fx,ACELP_CORE) == 0 ) - { - /* move the resampling out of the TDBWE path as new_swb_speech is not needed for TDBWE. */ - Copy( input_fx, st_fx->old_fdbwe_speech_fx, L_FRAME48k ); - } - ELSE - { - test(); - IF( sub(st_fx->last_extl_fx,SWB_BWE) != 0 && sub(st_fx->last_extl_fx,FB_BWE) != 0 ) - { - /* resample 48 kHz to 32kHz */ - IF( sub(st_fx->last_bwidth_fx,FB) == 0 ) - { - inner_frame = L_FRAME48k; - inner_Fs = 48000; - Copy( st_fx->old_fdbwe_speech_fx, new_swb_speech_fx, L_FRAME48k ); - } - ELSE - { - inner_frame = L_FRAME32k; - inner_Fs = 32000; - decimate_2_over_3_allpass_fx( st_fx->old_fdbwe_speech_fx, L_FRAME48k, new_swb_speech_fx, st_fx->dec_2_over_3_mem_fx, allpass_poles_3_ov_2, - decimate_3_ov_2_lowpass_num, decimate_3_ov_2_lowpass_den, st_fx->dec_2_over_3_mem_lp_fx ); - } - - Sample_Delay_SWB_BWE = NS2SA_fx2( inner_Fs, DELAY_FD_BWE_ENC_12k8_NS + DELAY_FIR_RESAMPL_NS ); - Copy( new_swb_speech_fx, &old_input_fx[Sample_Delay_SWB_BWE], inner_frame ); - set16_fx( old_input_fx, 0, Sample_Delay_SWB_BWE ); - Copy( new_swb_speech_fx + inner_frame - Sample_Delay_SWB_BWE, st_fx->old_input_fx, Sample_Delay_SWB_BWE ); - Copy( old_input_fx, st_fx->L_old_wtda_swb_fx, inner_frame ); - st_fx->Q_old_wtda = 0; - move16(); - } - /* resample 48 kHz to 32kHz */ - IF( sub(st_fx->bwidth_fx,FB) == 0 ) - { - Copy( input_fx, new_swb_speech_fx, L_FRAME48k ); - } - ELSE - { - decimate_2_over_3_allpass_fx( input_fx, L_FRAME48k, new_swb_speech_fx, st_fx->dec_2_over_3_mem_fx, allpass_poles_3_ov_2, - decimate_3_ov_2_lowpass_num, decimate_3_ov_2_lowpass_den, st_fx->dec_2_over_3_mem_lp_fx ); - } - } - } - ELSE - { - /* resample 48 kHz to 32kHz */ - IF( sub(st_fx->bwidth_fx,FB) == 0 ) - { - Copy( input_fx, new_swb_speech_fx, L_FRAME48k ); - } - ELSE - { - decimate_2_over_3_allpass_fx( input_fx, L_FRAME48k, new_swb_speech_fx, st_fx->dec_2_over_3_mem_fx, allpass_poles_3_ov_2, - decimate_3_ov_2_lowpass_num, decimate_3_ov_2_lowpass_den, st_fx->dec_2_over_3_mem_lp_fx ); - } - } - } - - test(); - test(); - test(); - test(); - test(); - IF( ( sub(st_fx->core_fx, ACELP_CORE) == 0 && sub( st_fx->extl_fx, SWB_BWE_HIGHRATE) != 0 && sub(st_fx->extl_fx, FB_BWE_HIGHRATE) != 0 ) - || ( ( L_sub(st_fx->total_brate_fx, 9600) == 0 || st_fx->rf_mode != 0 ) && sub(st_fx->bwidth_fx, SWB) == 0 ) ) - { - IF( sub(st_fx->L_frame_fx, L_FRAME) == 0 ) - { - startB= 34; - endB= 14; - FOR( ts = 0; ts < CLDFB_NO_COL_MAX; ts++ ) - { - uB = 0; - FOR( nB = startB; nB > endB; nB-- ) - { - move16(); - realBufferFlipped[ts][uB] = realBuffer[ts][nB]; - if (s_and(ts, 1) != 0) - { - realBufferFlipped[ts][uB] = L_negate(realBufferFlipped[ts][uB]); - } - imagBufferFlipped[ts][uB] = imagBuffer[ts][nB]; - if (s_and(ts, 1) == 0) - { - imagBufferFlipped[ts][uB] = L_negate(imagBufferFlipped[ts][uB]); - } - uB = add(uB, 1); /* uB ++ */ - } - } - } - ELSE - { - startB = 39; - endB = 19; - FOR( ts = 0; ts < CLDFB_NO_COL_MAX; ts++ ) - { - uB = 0; - FOR( nB = startB; nB > endB; nB-- ) - { - realBufferFlipped[ts][uB] = L_negate(realBuffer[ts][nB]); - imagBufferFlipped[ts][uB] = imagBuffer[ts][nB]; - uB = add(uB, 1); /* uB ++ */ - } - } - } - - /* Highband energy computation for gain shape control in case of bandwidth switching fix*/ - { - CldfbHB_ener = 0; - FOR (nB = 0; nB < 10; nB++) - { - FOR (ts = 0; ts < CLDFB_NO_COL_MAX; ts++) - { - realQ_neg1 = extract_l(L_shr(realBufferFlipped[ts][nB], 31-(15+cldfbScale->hb_scale)+1)); - imagQ_neg1 = extract_l(L_shr(imagBufferFlipped[ts][nB], 31-(15+cldfbScale->hb_scale)+1)); /* Q(-1), headroom needed */ - - CldfbHB_ener = L_mac0(CldfbHB_ener, realQ_neg1, realQ_neg1); - CldfbHB_ener = L_mac0(CldfbHB_ener, imagQ_neg1, imagQ_neg1); /* Q(-2) */ - } - } - - exp = norm_l(CldfbHB_ener); - CldfbHB_ener = L_shl(CldfbHB_ener, exp); /* CldfbHB_ener = CldfbHB_fl*2^(exp) */ - Cldfbtemp1 = (Log2_norm_lc(CldfbHB_ener)); - Cldfbtemp1 = add(shr(Cldfbtemp1, 6), shl(sub(30, sub(exp, 2)), 9));/* Log2_norm_lc(CldfbHB_ener) = 2^15*(log2(CldfbHB_ener/2^30)) = 2^15*(log2(CldfbHB_fl*(2^-2)*2^exp/2^30)) = 2^15*(log2(CldfbHB_fl) + exp-2-30) => 2^(-6)*l2nc + 2^9(20-(exp-2)) = 2^9*log2(CldfbHB_fl), Q9 */ - CldfbHB_ener = L_mult(sub(Cldfbtemp1, 1741/*3.401 Q9*/), 3495); /* 3495 = Q19 log10(2)*0.1/log10(32768), Q = 19+9+1 = 29 */ - st_fx->cldfbHBLT = mac_r(CldfbHB_ener, 29491/*0.9 Q15*/, st_fx->cldfbHBLT); /* cldfbHBLT is in Q13 */ - } - cldfbSynthesisFiltering( st_fx->cldfbSyn_Fx, realBufferFlipped, imagBufferFlipped, - cldfbScale, shb_speech_fx, 0, CLDFB_NO_COL_MAX, cldfbWorkBuffer ); - *Q_shb_spch = 0; /*shb_speech_fx : Q0*/ - - test(); - test(); - IF( sub(st_fx->extl_fx, WB_TBE) != 0 && sub(st_fx->extl_fx, SWB_TBE) != 0 && sub(st_fx->extl_fx, FB_TBE) != 0 ) - { - /* Update the previous superwideband speech buffer in case of a SWB_BWE frame - this code is in swb_tbe_enc */ - delay = L_LOOK_16k + L_SUBFR16k; - Copy( shb_speech_fx + L_FRAME16k - delay, st_fx->old_speech_shb_fx, delay ); - } - } - ELSE - { - IF( sub(st_fx->bwidth_fx, FB) == 0 || sub(st_fx->core_fx, ACELP_CORE) == 0) - { - set16_fx( st_fx->old_speech_shb_fx, 0, L_LOOK_16k + L_SUBFR16k ); - set16_fx( shb_speech_fx, 0, L_FRAME16k ); /* shb_speech for FB/SWB BWE_HIGHRATE is not used at 64kbps */ - } - ELSE - { - /* flip the spectrm */ - Copy( new_swb_speech_fx, spchTmp_fx, L_FRAME32k ); - - FOR( i = 0; i < L_FRAME32k; i = i+2 ) - { - spchTmp_fx[i] = negate(spchTmp_fx[i]); - } - - Decimate_allpass_steep_fx( spchTmp_fx, st_fx->state_ana_filt_shb_fx, L_FRAME32k, shb_speech_fx ); - Copy( shb_speech_fx + L_FRAME16k - (L_LOOK_16k + L_SUBFR16k), st_fx->old_speech_shb_fx, L_LOOK_16k + L_SUBFR16k ); - } - - /* Reset CLDFB synthesis buffer */ - set16_fx( st_fx->cldfbSyn_Fx->FilterStates, 0, st_fx->cldfbSyn_Fx->p_filter_length + st_fx->cldfbSyn_Fx->no_channels*st_fx->cldfbSyn_Fx->no_col ); - } - IF( st_fx->last_extl_fx == -1 ) - { - delay = NS2SA(st_fx->input_Fs_fx, DELAY_FIR_RESAMPL_NS); - FOR( i = 0; i < delay; i++ ) - { - shb_speech_fx[i] = mult_r( mult_r(i, 983/*0.03f Q15*/), shb_speech_fx[2*delay-1-i] ); - } - } - - return; -} - diff --git a/src/libs/libevs/lib_enc/swb_tbe_enc.cpp b/src/libs/libevs/lib_enc/swb_tbe_enc.cpp new file mode 100644 index 00000000..e268fab8 --- /dev/null +++ b/src/libs/libevs/lib_enc/swb_tbe_enc.cpp @@ -0,0 +1,2029 @@ +/*==================================================================================== + EVS Codec 3GPP TS26.443 Nov 13, 2018. Version 12.11.0 / 13.7.0 / 14.3.0 / 15.1.0 + ====================================================================================*/ + +#include +#include +#include "options.h" +#include "cnst.h" +#include "prot.h" +#include "rom_com.h" +#include "rom_enc.h" + +/*-----------------------------------------------------------------* + * Local functions + *-----------------------------------------------------------------*/ + +static void return_M_Least( const float *inp, const short n_cols, const float *codebook, const short num_grp, + const float *weight, const short interNum, short *least ); +static void singlevectortest_gain( const float *inp, const short dimen, const short cb_size, short *index, + const float *weight, float *recon, const float *codebook ); +static void determine_gain_weights( const float *gain, float *weights, const short dims ); +static void QuantizeSHBsubgains( Encoder_State *st, float *subgains, const short extl ); +static void QuantizeSHBframegain( Encoder_State *st, float *GainFrame, const short extl, long extl_brate, short *rf_gainFrame_ind ); +static short closest_centroid( const float *data, const float *weights, const float *quantizer, const short centroids, const short length); +static void EstimateSHBFrameGain( const short length, const float *oriSHB, const float *synSHB, float *subgain, float *GainFrame, const float *win_shb, const float *subwin ); +static void EstimateSHBGainShape( const short length, const float *oriSHB, const float *synSHB, float *subgain, const float *subwin ); +static float pow_off_pk(float a[], short len, short step); +static void Quant_lower_LSF( const float lsf[], float lsf_q[], short lsf_idx[] ); +static short Quant_mirror_point(const float lsf[], const float lsf_q[], float *m); +static short Find_LSF_grid(const float lsf[], float lsf_q[], const float m); +static void gainFrSmooth_En(Encoder_State *st, float *shb_frame, const float *lpc_shb, const float *lsp_shb, float *MA_lsp_shb_spacing, short *frGainAttenuate, short *frGainSmoothEn ); +static void Quant_BWE_LSF( Encoder_State *st, const float lsp_shb[], float Q_lsfs[] ); +static void Quant_shb_ener_sf( Encoder_State *st, float *shb_ener_sf ); +static void Quant_shb_res_gshape( Encoder_State *st, float *shb_res_gshape ); + + +/*-------------------------------------------------------------------* + * InitSWBencBuffer() + * + * Initialize SWB buffers + *-------------------------------------------------------------------*/ + +void InitSWBencBuffer( + Encoder_State *st /* i/o: SHB encoder structure */ +) +{ + set_f( st->old_speech_shb, 0.0f, L_LOOK_16k + L_SUBFR16k ); + set_f(st->old_bwe_exc, 0.0f, (PIT16k_MAX * 2)); + st->bwe_seed[0] = 23; + st->bwe_seed[1] = 59; + set_f( st->old_bwe_exc_extended, 0.0f, NL_BUFF_OFFSET ); + st->bwe_non_lin_prev_scale = 0; + + + set_f( st->state_ana_filt_shb, 0.0f, (2*ALLPASSSECTIONS_STEEP+1) ); + + set_f( st->elliptic_bpf_2_48k_mem[0], 0.0f, 4 ); + set_f( st->elliptic_bpf_2_48k_mem[1], 0.0f, 4 ); + set_f( st->elliptic_bpf_2_48k_mem[2], 0.0f, 4 ); + set_f( st->elliptic_bpf_2_48k_mem[3], 0.0f, 4 ); + st->prev_fb_energy = 0.0f; + + return; +} + + +/*-------------------------------------------------------------------* + * ResetSHBbuffer_Enc() + * + *-------------------------------------------------------------------*/ + +void ResetSHBbuffer_Enc( + Encoder_State *st /* i/o: SHB encoder structure */ +) +{ + /* states for the filters used in generating SHB excitation from WB excitation*/ + set_f( st->mem_genSHBexc_filt_down_shb,0, (2*ALLPASSSECTIONS_STEEP+1) ); + set_f( st->mem_csfilt, 0, 2 ); + + /* states for the filters used in generating SHB signal from SHB excitation*/ + set_f( st->state_syn_shbexc, 0, L_SHB_LAHEAD ); + set_f( st->state_lpc_syn, 0, LPC_SHB_ORDER ); + if( sub(st->extl, FB_TBE) == 0 ) + { + set_f( st->fb_state_lpc_syn, 0, LPC_SHB_ORDER ); + st->fb_tbe_demph = 0; + } + /* states for the filters used in generating WB signal from WB excitation*/ + set_f( st->decim_state1, 0.0f, (2*ALLPASSSECTIONS_STEEP+1) ); + set_f( st->decim_state2, 0.0f, (2*ALLPASSSECTIONS_STEEP+1) ); + set_f( st->mem_genSHBexc_filt_down_wb2, 0, (2*ALLPASSSECTIONS_STEEP+1) ); + set_f( st->mem_genSHBexc_filt_down_wb3, 0, (2*ALLPASSSECTIONS_STEEP+1) ); + + + /* overlap buffer used to Adjust SHB Frame Gain */ + set_f( st->mem_stp_swb, 0, LPC_SHB_ORDER ); + st->gain_prec_swb = 1.0f; + set_f( st->syn_overlap,0,L_SHB_LAHEAD ); + st->tbe_demph = 0.0f; + st->tbe_premph = 0.0f; + + return; +} + + +/*-------------------------------------------------------------------* +* wb_tbe_enc() +* +* WB TBE encoder, 6 - 8 kHz band encoding module +*-------------------------------------------------------------------*/ + +void wb_tbe_enc( + Encoder_State *st, /* i/o: encoder state structure */ + const short coder_type, /* i : coding type */ + const float *hb_speech, /* i : HB target signal (6-8kHz) at 16kHz */ + const float *bwe_exc_extended, /* i : bandwidth extended exciatation */ + const float voice_factors[], /* i : voicing factors */ + const float pitch_buf[], /* i : pitch for each subframe */ + const float voicing[] /* i : OL maximum normalized correlation */ +) +{ + short i, j, k, delay; + float hb_old_speech[(L_LOOK_12k8 + L_SUBFR + L_FRAME) * 5/16]; + float shaped_wb_excitation [ (L_FRAME16k + L_SHB_LAHEAD)/4]; + float exc4kWhtnd [L_FRAME16k / 4]; + short ana_align_delay = - L_SHB_LAHEAD / 4 - 5; + float GainFrame, GainShape[NUM_SHB_SUBFR]; + float lpc_wb[LPC_SHB_ORDER_WB+1]; + float lsp_wb[LPC_SHB_ORDER_WB], weights_lsp[LPC_SHB_ORDER_WB] = {1.0, 1.0}; + float *hb_new_speech, *hb_frame; + float R[LPC_SHB_ORDER_WB+2], ervec[LPC_SHB_ORDER_WB+1]; + float prev_pow, curr_pow, scale; + float p2m_in, p2m_out; + short uv_flag; + float pitBufAvg, voicingBufAvg; + float vf_modified[NB_SUBFR16k]; + float temp_wb_fac, feedback; + float lsp_spacing; + float ervec_temp[LPC_SHB_ORDER_WB+1]; + float lsp_wb_temp[LPC_SHB_ORDER_WB], lpc_wb_temp[LPC_SHB_ORDER_WB+1]; + + /* delay alignment */ + delay = (L_LOOK_12k8 + L_SUBFR) * 5/16; + + hb_new_speech = hb_old_speech + delay; + hb_frame = hb_old_speech + L_SUBFR * 5/16 + ana_align_delay; + + mvr2r( st->old_speech_wb, hb_old_speech, delay ); + mvr2r( hb_speech, hb_new_speech, L_FRAME16k / 4 ); + mvr2r( hb_old_speech + L_FRAME16k / 4, st->old_speech_wb, delay ); + if( ( st->last_extl != WB_TBE && st->last_extl != WB_BWE ) && + ( st->clas == UNVOICED_CLAS || ( voicing[0] < 0.5f && voicing[1] < 0.5f && voicing[2] < 0.5f ) ) && + ( !st->igf ) ) + { + /* In case of unvoiced signals after switching cores, back-propagate the target signal */ + mvr2r( hb_speech, hb_old_speech, delay ); + + for( i = (L_LOOK_12k8 + L_SUBFR) * 5/16, j = k = 0; j < L_SUBFR16k; i--, j+=4, k++ ) + { + hb_old_speech[i] *= ola_win_shb_switch_fold[j]; + hb_old_speech[i] += hb_speech[k] * ola_win_shb_switch_fold[L_SUBFR16k-4-j]; + } + } + + autocorr( hb_old_speech, R, LPC_SHB_ORDER_WB+1, (NS2SA(INT_FS_12k8, 5000000L) + L_SUBFR + L_FRAME) * 5/16, win_lpc_hb_wb, 0, 1, 1 ); /* VE2QC: to be tuned later */ + lev_dur( lpc_wb_temp, R, LPC_SHB_ORDER_WB, ervec_temp ); + a2lsp( lsp_wb_temp, lpc_wb_temp, LPC_SHB_ORDER_WB ); + lsp_spacing = 0.5f; + + for( i = 0; i < LPC_SHB_ORDER_WB; i++ ) + { + lsp_spacing = min(lsp_spacing, (float)( i == 0 ? lsp_wb_temp[0] : (lsp_wb_temp[i] - lsp_wb_temp[i -1]))); + } + + /* Spectral smoothing of autocorrelation coefficients */ + for (i = 0; i <= LPC_SHB_ORDER_WB; i++) + { + R[i] = R[i] * wac[i]; + } + R[0] = max( R[0], 1.0e-8f ); + + if ( st->rf_mode == 1 || st->extl_brate == WB_TBE_0k35 ) + { + lev_dur( lpc_wb, R, LPC_SHB_ORDER_LBR_WB, ervec ); + + /* Expand bandwidth of the LP coeffs */ + for (i = 0; i <= LPC_SHB_ORDER_LBR_WB; i++) + { + lpc_wb[i] *= lpc_weights[i]; + } + + /* convert into lsps and calculate weights */ + a2lsp(lsp_wb,lpc_wb, LPC_SHB_ORDER_LBR_WB); + lsp_weights(lsp_wb, weights_lsp, LPC_SHB_ORDER_LBR_WB); + + /* Quantization of LSFs */ + i = closest_centroid( lsp_wb, weights_lsp, lbr_wb_bwe_lsfvq_cbook_2bit, 4, LPC_SHB_ORDER_LBR_WB ); + if( st->codec_mode == MODE2 ) + { + st->lsf_WB = i; + } + else + { + push_indice( st, IND_SHB_LSF, i, NUM_BITS_LBR_WB_LSF ); + } + + mvr2r( lbr_wb_bwe_lsfvq_cbook_2bit + i*LPC_SHB_ORDER_LBR_WB, lsp_wb, LPC_SHB_ORDER_LBR_WB); + + lsp2a( lpc_wb, lsp_wb, LPC_SHB_ORDER_LBR_WB ); + set_f( lpc_wb + LPC_SHB_ORDER_LBR_WB+1, 0.0f, (LPC_SHB_ORDER_WB - LPC_SHB_ORDER_LBR_WB) ); + } + else + { + lev_dur( lpc_wb, R, LPC_SHB_ORDER_WB, ervec ); + + /* Expand bandwidth of the LP coeffs */ + for (i = 0; i <= LPC_SHB_ORDER_WB; i++) + { + lpc_wb[i] *= lpc_weights[i]; + } + + /* convert into lsps and calculate weights */ + a2lsp(lsp_wb,lpc_wb, LPC_SHB_ORDER_WB); + lsp_weights(lsp_wb, weights_lsp, LPC_SHB_ORDER_WB); + + /* Quantization of LSFs */ + i = closest_centroid( lsp_wb, weights_lsp, wb_bwe_lsfvq_cbook_8bit, 256, LPC_SHB_ORDER_WB ); + push_indice( st, IND_SHB_LSF, i, NUM_BITS_WB_LSF ); + + mvr2r( wb_bwe_lsfvq_cbook_8bit + i*LPC_SHB_ORDER_WB, lsp_wb, LPC_SHB_ORDER_WB); + + lsp2a( lpc_wb, lsp_wb, LPC_SHB_ORDER_WB ); + } + + uv_flag = 0; + if ( st->extl_brate == WB_TBE_1k05 && st->coder_type_raw == UNVOICED ) + { + uv_flag = 1; + } + + mvr2r( voice_factors, vf_modified, NB_SUBFR16k ); + if( coder_type == VOICED ) + { + for ( i = 1; i < NB_SUBFR; i++ ) + { + vf_modified[i] = 0.8f * voice_factors[i] + 0.2f * voice_factors[i-1]; + } + + if(st->L_frame != L_FRAME ) + { + vf_modified[4] = 0.8f * voice_factors[4] + 0.2f * voice_factors[3]; + } + } + + /* From low band excitation, generate highband excitation */ + mvr2r( st->state_syn_shbexc, shaped_wb_excitation, L_SHB_LAHEAD/4 ); + GenShapedWBExcitation( shaped_wb_excitation + L_SHB_LAHEAD/4, lpc_wb, exc4kWhtnd, st->mem_csfilt, st->mem_genSHBexc_filt_down_shb, + st->mem_genSHBexc_filt_down_wb2, st->mem_genSHBexc_filt_down_wb3, st->state_lpc_syn, coder_type, + bwe_exc_extended, st->bwe_seed, vf_modified, uv_flag, st->igf ); + + prev_pow = sum2_f( shaped_wb_excitation, L_SHB_LAHEAD/4 ); + curr_pow = sum2_f( shaped_wb_excitation + L_SHB_LAHEAD/4, L_SHB_LAHEAD/4 ); + + if( voice_factors[0] > 0.75f ) + { + curr_pow *= 0.25; + } + + if( prev_pow == 0 ) + { + scale = 0; + } + else + { + scale = sqrt(curr_pow/prev_pow); + } + + for( i = 0; i < (L_SHB_LAHEAD/4 - 1); i++ ) + { + shaped_wb_excitation[i] *= scale; + } + + scale = sqrt( scale ); + + shaped_wb_excitation[L_SHB_LAHEAD/4 - 1] *= scale; + + /* Update WB excitation */ + mvr2r( shaped_wb_excitation + L_FRAME16k/4, st->state_syn_shbexc, L_SHB_LAHEAD/4 ); + + /* estimate the gain shape parameter */ + EstimateSHBGainShape( SHB_OVERLAP_LEN/2, hb_frame, shaped_wb_excitation, GainShape, subwin_wb ); + + /* Gain frame adjustment factor */ + temp_wb_fac = (float)log( (GainShape[0]+0.00001f) / (st->prev_wb_GainShape+0.0001f) ); + feedback = temp_wb_fac * temp_wb_fac ; + for (i = 1; i < NUM_SHB_SUBFR/4; i++) + { + temp_wb_fac = (float)log( (GainShape[i]+0.00001f) / (GainShape[i-1]+0.0001f) ); + feedback += (temp_wb_fac * temp_wb_fac); + } + feedback = 0.4f / (1 + 0.5f * feedback); + + temp_wb_fac = st->prev_wb_GainShape; + for (i = 0; i < NUM_SHB_SUBFR/4; i++) + { + GainShape[i] = (1 - feedback) * GainShape[i] + feedback * temp_wb_fac; + temp_wb_fac = GainShape[i]; + } + st->prev_wb_GainShape = GainShape[NUM_SHB_SUBFR/4-1]; + + /* Compute the power of gains away from the peak gain prior to quantization */ + p2m_in = pow_off_pk(GainShape, NUM_SHB_SUBFR / 4, 1); + + if ( st->extl_brate == WB_TBE_0k35 ) + { + for (i=0; i<8; i++) + { + GainShape[i] = RECIP_ROOT_EIGHT; + } + } + else + { + push_indice( st, IND_UV_FLAG, uv_flag, 1 ); + + /* Quantization of the subframe gain parameter */ + QuantizeSHBsubgains( st, GainShape, st->extl ); + } + + /* Compute the power of gains away from the peak gain after quantization */ + p2m_out = pow_off_pk(GainShape, NUM_SHB_SUBFR/2, 2); + + /* Estimate the gain parameter */ + EstimateSHBFrameGain( SHB_OVERLAP_LEN/2, hb_frame, shaped_wb_excitation, GainShape, &GainFrame, window_wb, subwin_wb ); + + /* If there's a big difference in the power of gains away from the peak gain */ + /* due to poor quantization then suppress energy of the high band. */ + if ( p2m_out > 2.0f * p2m_in ) + { + float temp = 0; + if(p2m_in >= 0 && p2m_out > 0) + { + temp = sqrt((2.0f * p2m_in) / p2m_out); + } + GainFrame *= temp; + } + + pitBufAvg = 0.0025f * sum_f( pitch_buf, NB_SUBFR ); + voicingBufAvg = 0.333f * sum_f( voicing, 3 ); + if(voicingBufAvg <= 0.0f && (pitBufAvg != 0)) + { + voicingBufAvg = pitBufAvg/1.001f; + } + else if(voicingBufAvg <= 0.0f) + { + voicingBufAvg = 1.0f; + } + + GainFrame *= max(min((float)(pitBufAvg/voicingBufAvg), 1.0f), 0.7f); + + if( lsp_spacing < 0.01f ) + { + GainFrame *= 0.65f; + } + + /* Quantization of the frame gain parameter */ + if( st->igf && coder_type == VOICED ) + { + GainFrame *= 0.5f; + } + else if( st->igf && (0.25f*sum_f(voice_factors, NB_SUBFR) > 0.35f) ) + { + GainFrame *= 0.75f; + } + + QuantizeSHBframegain( st, &GainFrame, st->extl, st->extl_brate, &st->RF_bwe_gainFr_ind ); + + /* Adjust the subframe and frame gain of the synthesized SHB signal */ + /* Scale the shaped excitation*/ + ScaleShapedSHB( SHB_OVERLAP_LEN/2, shaped_wb_excitation, st->syn_overlap, GainShape, GainFrame, window_wb, subwin_wb ); + + + return; +} + + +/*-------------------------------------------------------------------* + * swb_tbe_enc() + * + * SWB TBE encoder, 6 - 14 kHz (or 7.5 - 15.5 kHz) band encoding module + *-------------------------------------------------------------------*/ + +void swb_tbe_enc( + Encoder_State *st, /* i/o: encoder state structure */ + const short coder_type, /* i : coding type */ + float *shb_speech, /* i : SHB target signal (6-14kHz) at 16kHz */ + const float *bwe_exc_extended, /* i : bandwidth extended exciatation */ + const float voice_factors[], /* i : voicing factors */ + float *White_exc16k, /* o : shaped white excitation for the FB TBE */ + const float voicing[], /* i : OL maximum normalized correlation */ + const float pitch_buf[] /* i : pitch for each subframe */ +) +{ + short i, j, delay; + float shb_old_speech[L_LOOK_16k + L_SUBFR16k + L_FRAME16k]; + float shaped_shb_excitation [L_FRAME16k + L_SHB_LAHEAD]; + float GainFrame, GainShape[NUM_SHB_SUBFR]; + float lpc_shb[LPC_SHB_ORDER+1]; + float weights_lsp[LPC_SHB_ORDER]; + float *shb_frame, *shb_new_speech; + float lsf_shb_orig[LPC_SHB_ORDER]; + float lsp_shb_1[LPC_SHB_ORDER], lsp_shb_2[LPC_SHB_ORDER], lsp_temp[LPC_SHB_ORDER]; + float lpc_shb_sf[4*(LPC_SHB_ORDER+1)]; + const float *ptr_lsp_interp_coef; + short tmp; + float shb_ener_sf; + float lsf_shb[LPC_SHB_ORDER]; + float shb_res[L_FRAME16k]; + float shb_res_gshape[NB_SUBFR16k], normFac; + short vf_ind; + float sd_uq_q, vf_modified[NB_SUBFR16k]; + float pitBufAvg, voicingBufAvg; + float R[LPC_SHB_ORDER+2], ervec[LPC_SHB_ORDER+1]; + short ana_align_delay[2] = {-L_SHB_LAHEAD - (NL_BUFF_OFFSET/2), -L_SHB_LAHEAD - (NL_BUFF_OFFSET/2)}; + + float prev_pow, curr_pow, scale; + float p2m_in, p2m_out; + short frGainAttenuate, frGainSmoothEn; + float MA_lsp_shb_spacing; + float temp_swb_fac, feedback; + float shaped_shb_excitationTemp[L_FRAME16k]; + float lsf_diff[LPC_SHB_ORDER], w[LPC_SHB_ORDER]; + float refl[M]; + float tilt_para; + float formant_fac; + float temp; + short stab_check = 1; + + /* initializations */ + set_f( shaped_shb_excitationTemp, 0.0f, L_FRAME16k ); + + /* compensate for the delay in target generation and subframe LA */ + shb_frame = shb_old_speech + L_SUBFR16k + ana_align_delay[0]; + + /* set up the speech buffers for TBE processing*/ + delay = L_LOOK_16k + L_SUBFR16k; + shb_new_speech = shb_old_speech + delay; + mvr2r( st->old_speech_shb, shb_old_speech, delay ); + mvr2r( shb_speech, shb_new_speech, L_FRAME16k ); + mvr2r( shb_old_speech + L_FRAME16k, st->old_speech_shb, delay ); + + autocorr( shb_old_speech, + R, + LPC_SHB_ORDER+1, + NS2SA(INT_FS_16k, ACELP_LOOK_NS) + L_SUBFR16k + L_FRAME16k, + win_lpc_shb, 0, 1, 1 ); + + /* Spectral smoothing of autocorrelation coefficients */ + if(st->rf_mode || st->total_brate == ACELP_9k60) + { + for (i = 0; i <= LPC_SHB_ORDER; i++) + { + R[i] = R[i] * wac_swb[i]; + } + } + /* Set the autocorr[0] element to a non-negative value */ + R[0] = max( R[0], 1.0e-8f); + + lev_dur( lpc_shb, R, LPC_SHB_ORDER, ervec ); + { + float enerG, lpc_shb1[M+1]; + + /* extend the lpc_shb to a 16th order gain calc */ + set_f(lpc_shb1, 0, M+1); + mvr2r(lpc_shb, lpc_shb1, LPC_SHB_ORDER + 1); + + /* estimate the LP gain */ + enerG = enr_1_Az(lpc_shb1, 2*L_SUBFR); + + /* if the LP gain is greater than a threshold, avoid saturation. + The function 'is_numeric_float' used to check for infinity enerG */ + if(enerG > 32 || !(is_numeric_float(enerG)) ) + { + set_f(lpc_shb, 0, LPC_SHB_ORDER+1); + lev_dur( lpc_shb, R, 2, ervec ); + } + } + + /* Expand bandwidth of the LP coeffs */ + if(st->rf_mode || st->total_brate == ACELP_9k60) + { + for( i = 0; i <= LPC_SHB_ORDER; i++ ) + { + lpc_shb[i] *= lpc_weights[i]; + } + } + + /* convert to LSFs */ + stab_check = a2lsp( lsf_shb, lpc_shb, LPC_SHB_ORDER ); + + if( (st->last_extl != SWB_TBE && st->last_extl != FB_TBE) || st->ini_frame == 0 ) + { + for( i=0; i < LPC_SHB_ORDER; i++ ) + { + st->prev_lsp_shb[i] = i/20.0f; + } + } + + if( stab_check == 0 ) + { + mvr2r( st->prev_lsp_shb, lsf_shb, LPC_SHB_ORDER ); + } + + mvr2r( lsf_shb, st->prev_lsp_shb, LPC_SHB_ORDER ); + + mvr2r(lsf_shb, lsf_shb_orig, LPC_SHB_ORDER); + + gainFrSmooth_En( st, shb_frame, lpc_shb, lsf_shb, &MA_lsp_shb_spacing, &frGainAttenuate, &frGainSmoothEn); + + if(st->rf_mode || st->total_brate == ACELP_9k60) + { + lsp_weights( lsf_shb, weights_lsp, LPC_SHB_ORDER ); + + /* to compensate for the 1.1* weighting done inside the function lsp_weights */ + weights_lsp[3]*=0.909091f; + weights_lsp[4]*=0.909091f; + + /* 8-bit VQ, 10 dimension */ + i = closest_centroid(lsf_shb, weights_lsp, swb_tbe_lsfvq_cbook_8b, 256, LPC_SHB_ORDER); + mvr2r(swb_tbe_lsfvq_cbook_8b + i * LPC_SHB_ORDER, lsf_shb, LPC_SHB_ORDER); + + set_s(st->lsf_idx, 0, NUM_Q_LSF); + st->lsf_idx[0] = i; + } + else + { + /* Quantization of LSFs */ + Quant_BWE_LSF( st, lsf_shb, lsf_shb ); + } + + space_lsfs( lsf_shb, LPC_SHB_ORDER ); + + /* voice factor adjustment and gainframe attenuation factor */ + sd_uq_q = 0; + for( i = 0; i < LPC_SHB_ORDER; i++ ) + { + /* Estimate the QD in lsps between UQ and Q*/ + sd_uq_q += (lsf_shb[i] - lsf_shb_orig[i]) * (lsf_shb[i] - lsf_shb_orig[i]); + } + + mvr2r(voice_factors, vf_modified, NB_SUBFR16k); + + if( coder_type == VOICED || mean(voice_factors, 4) > 0.4f ) + { + for( i = 1; i < NB_SUBFR; i++ ) + { + vf_modified[i] = 0.8f * voice_factors[i] + 0.2f * voice_factors[i-1]; + } + + if( st->L_frame != L_FRAME ) + { + vf_modified[4] = 0.8f * voice_factors[4] + 0.2f * voice_factors[3]; + } + } + + /* SHB LSF from current frame; and convert to LSP for interpolation */ + lsf2lsp( lsf_shb, lsp_shb_2, LPC_SHB_ORDER, 1.0f ); + + if( st->last_extl == SWB_TBE || st->last_extl == FB_TBE ) + { + /* SHB LSP values from prev. frame for interpolation */ + mvr2r( st->swb_lsp_prev_interp, lsp_shb_1, LPC_SHB_ORDER ); + } + else + { + /* Use current frame's LSPs; in effect no interpolation */ + mvr2r( lsp_shb_2, lsp_shb_1, LPC_SHB_ORDER ); + } + + lsf_diff[0] = lsf_diff[LPC_SHB_ORDER-1] = 0.5f; + for( i=1; i<(LPC_SHB_ORDER-1); i++ ) + { + lsf_diff[i] = lsf_shb[i] - lsf_shb[i-1]; + } + a2rc (st->cur_sub_Aq+1, refl, (short) M); + + /* LSP interpolation for 13.2 kbps and 16.4 kbps */ + tilt_para = 6.6956f * (1.0f + refl[0]) * (1.0f + refl[0]) - 3.8714f * (1.0f + refl[0]) + 1.3041f; + if( st->last_extl != SWB_TBE ) + { + for( i=1; iprev_lsf_diff[i-1] = 0.5f*lsf_diff[i]; + } + } + + if( st->total_brate <= ACELP_16k40 ) + { + if(!(st->prev_tilt_para > 5.0f && (coder_type == TRANSITION || tilt_para < 1.0f)) && !(((st->prev_tilt_para < 3.0f && st->prev_coder_type >= VOICED)) && tilt_para > 5.0f)) + { + for( i = 1; i < (LPC_SHB_ORDER-1); i++ ) + { + w[i] = (lsf_diff[i] < st->prev_lsf_diff[i-1]) ? min(max(0.8f*lsf_diff[i]/st->prev_lsf_diff[i-1], 0.5f), 1.0f) : min(max(0.8f*st->prev_lsf_diff[i-1]/lsf_diff[i], 0.5f), 1.0f); + } + w[0] = w[1]; + w[LPC_SHB_ORDER-1] = w[LPC_SHB_ORDER-2]; + + for( i = 0; i < LPC_SHB_ORDER; i++ ) + { + lsp_temp[i] = lsp_shb_1[i]*(1.0f-w[i]) + lsp_shb_2[i]*w[i]; + } + } + else + { + mvr2r(lsp_shb_2, lsp_temp, LPC_SHB_ORDER); + } + } + + mvr2r( lsf_diff+1, st->prev_lsf_diff, LPC_SHB_ORDER-2 ); + st->prev_tilt_para = tilt_para; + + if( st->total_brate == ACELP_24k40 || st->total_brate == ACELP_32k ) + { + /* SHB LSP interpolation */ + ptr_lsp_interp_coef = interpol_frac_shb; + for( j = 0; j < 4; j++ ) + { + for( i = 0; i < LPC_SHB_ORDER; i++ ) + { + lsp_temp[i] = lsp_shb_1[i]*(*ptr_lsp_interp_coef) + + lsp_shb_2[i]*(*(ptr_lsp_interp_coef+1)); + } + ptr_lsp_interp_coef += 2; + + tmp = j*(LPC_SHB_ORDER+1); + /* convert from lsp to lsf */ + lsp2lsf( lsp_temp, lpc_shb_sf+tmp, LPC_SHB_ORDER, 1.0f ); + /* convert lsf to lpc for SHB synthesis */ + lsp2a( lpc_shb_sf+tmp, lpc_shb_sf+tmp, LPC_SHB_ORDER ); + lpc_shb_sf[j*(LPC_SHB_ORDER+1)] = 1.0f; + } + + /* -------- Calculate the SHB Energy -------- */ + shb_ener_sf = 0.003125f * sum2_f( shb_frame + L_SHB_LAHEAD, L_FRAME16k ); + Quant_shb_ener_sf( st, &shb_ener_sf ); + + /* -------- calculate the residuals using the FOUR subframe LPCs -------- */ + + set_f( shb_res, 0, L_FRAME16k ); + residu( lpc_shb_sf, LPC_SHB_ORDER, shb_frame + L_SHB_LAHEAD, shb_res, 80 ); + residu( lpc_shb_sf + (LPC_SHB_ORDER+1), LPC_SHB_ORDER, shb_frame + L_SHB_LAHEAD + 80, shb_res + 80, 80 ); + residu( lpc_shb_sf + 2*(LPC_SHB_ORDER+1), LPC_SHB_ORDER, shb_frame + L_SHB_LAHEAD + 160, shb_res + 160, 80 ); + residu( lpc_shb_sf + 3*(LPC_SHB_ORDER+1), LPC_SHB_ORDER, shb_frame + L_SHB_LAHEAD + 240, shb_res + 240, 80 ); + + set_f( shb_res_gshape, 0, NB_SUBFR16k ); + for( i = 0; i < NB_SUBFR16k; i++ ) + { + shb_res_gshape[i] = sum2_f( shb_res+i*64, 64 ); + } + + maximum(shb_res_gshape, NB_SUBFR16k, &normFac); + normFac = (float)1.0f/(0.0001f + normFac); + for( i = 0; i < NB_SUBFR16k; i++ ) + { + shb_res_gshape[i] = sqrt(shb_res_gshape[i]*normFac); + } + + Quant_shb_res_gshape(st, shb_res_gshape); + } + + /* Save the SWB LSP values from current frame for interpolation */ + mvr2r( lsp_shb_2, st->swb_lsp_prev_interp, LPC_SHB_ORDER ); + + + + /* For 13.2 and 16.4kbps, convert LSPs back into LP coeffs */ + /* convert from lsp to lsf */ + lsp2lsf( lsp_temp, lpc_shb, LPC_SHB_ORDER, 1.0f ); + /* convert lsf to lpc for SHB synthesis */ + lsp2a( lpc_shb, lpc_shb, LPC_SHB_ORDER ); + lpc_shb[0] = 1.0f; + + /* Save the SWB LSP values from current frame for interpolation */ + mvr2r( lsp_shb_2, st->swb_lsp_prev_interp, LPC_SHB_ORDER ); + mvr2r( st->state_syn_shbexc, shaped_shb_excitation, L_SHB_LAHEAD ); + + /* Determine formant PF strength */ + formant_fac = swb_formant_fac( lpc_shb[1], &st->tilt_mem ); + + vf_ind = 20; + GenShapedSHBExcitation( shaped_shb_excitation + L_SHB_LAHEAD, lpc_shb, White_exc16k, st->mem_csfilt, + st->mem_genSHBexc_filt_down_shb, st->state_lpc_syn, coder_type, bwe_exc_extended, st->bwe_seed, + vf_modified, st->extl, &(st->tbe_demph), &(st->tbe_premph), lpc_shb_sf, &shb_ener_sf, shb_res_gshape, + shb_res, &vf_ind, formant_fac, st->fb_state_lpc_syn,&(st->fb_tbe_demph), st->total_brate, 0 ); + + if( st->total_brate == ACELP_24k40 || st->total_brate == ACELP_32k ) + { + if(st->codec_mode == MODE2) + st->idx_mixFac = vf_ind; + else + push_indice( st, IND_SHB_VF, vf_ind, NUM_BITS_SHB_VF); + } + + for( i=0; imem_stp_swb, + st->ptr_mem_stp_swb, &(st->gain_prec_swb), st->mem_zero_swb, formant_fac ); + } + + mvr2r( shaped_shb_excitationTemp, &shaped_shb_excitation[L_SHB_LAHEAD], L_FRAME16k ); + + prev_pow = sum2_f( shaped_shb_excitation, L_SHB_LAHEAD + 10 ); + curr_pow = sum2_f( shaped_shb_excitation + L_SHB_LAHEAD + 10, L_SHB_LAHEAD + 10 ); + + if( voice_factors[0] > 0.75f ) + { + curr_pow *= 0.25; + } + + if( prev_pow == 0 ) + { + scale = 0; + } + else + { + scale = sqrt( curr_pow/ prev_pow ); + } + for( i=0; istate_syn_shbexc, L_SHB_LAHEAD ); + /* Estimate the gain-shape parameter */ + EstimateSHBGainShape( SHB_OVERLAP_LEN, shb_frame, shaped_shb_excitation, GainShape, subwin_shb ); + + /* Gain shape BWS/high band low energy fix */ + if( st->cldfbHBLT < 1.0f ) + { + /* There is not much HB past 10kHz; the temporal resolution is quite coarse, so reduce the dynamic range */ + for(i = 0; i < NUM_SHB_SUBGAINS; i++) + { + /* 0.35f +/- delta variation; delta = 0.1*(GS-0.35)*/ + GainShape[i] = 0.315f + 0.1f * GainShape[i]; + } + } + /* Gain frame adjustment factor */ + temp_swb_fac = (float)log( (GainShape[0]+0.00001f) / (st->prev_swb_GainShape+0.0001f) ); + feedback = temp_swb_fac * temp_swb_fac ; + for (i = 1; i < NUM_SHB_SUBGAINS; i++) + { + temp_swb_fac = (float)log( (GainShape[i]+0.00001f) / (GainShape[i-1]+0.0001f) ); + feedback += (temp_swb_fac * temp_swb_fac); + } + feedback = 0.4f / (1 + 0.5f * feedback); + + if( frGainAttenuate == 1 || ( sum_f(voicing, 3) > 2.4f && sum_f(voice_factors, 4) > 0.8f ) ) + { + temp_swb_fac = st->prev_swb_GainShape; + for( i = 0; i < NUM_SHB_SUBGAINS; i++ ) + { + GainShape[i] = (1 - feedback) * GainShape[i] + feedback * temp_swb_fac; + temp_swb_fac = GainShape[i]; + } + } + st->prev_swb_GainShape = GainShape[3]; + + /* Compute the power of gains away from the peak gain prior to quantization */ + p2m_in = pow_off_pk(GainShape, NUM_SHB_SUBGAINS, 1); + + /* Quantization of the gain shape parameter */ + QuantizeSHBsubgains( st, GainShape, st->extl ); + + /* Compute the power of gains away from the peak gain after quantization */ + p2m_out = pow_off_pk(GainShape, NUM_SHB_SUBFR, 4); + + /* Estimate the gain parameter */ + EstimateSHBFrameGain( SHB_OVERLAP_LEN, shb_frame, shaped_shb_excitation, GainShape, &GainFrame, window_shb, subwin_shb ); + + if( st->tec_tfa == 1 ) + { + tfaCalcEnv( shb_frame, st->tfa_enr ); + } + + /* If there's a big difference in the power of gains away from the peak gain */ + /* due to poor quantization then suppress energy of the high band. */ + if( p2m_out > 2.0f * p2m_in ) + { + temp = 0.f; + if(p2m_in >= 0 && p2m_out > 0) + { + temp = sqrt((2.0f * p2m_in)/p2m_out); + } + GainFrame *= temp; + } + + if( frGainSmoothEn == 1 && st->prev_gainFr_SHB < GainFrame ) + { + GainFrame = 0.5f * (st->prev_gainFr_SHB + GainFrame); + } + + if( frGainAttenuate == 1 && MA_lsp_shb_spacing <= 0.0024f ) + { + GainFrame = (float)pow( GainFrame, 0.8f ); + } + else if( st->prev_frGainAtten == 1 && GainFrame > 3.0f * st->prev_gainFr_SHB ) + { + GainFrame *= (0.8f + 0.5f*feedback); + } + st->prev_frGainAtten = frGainAttenuate; + + st->prev_gainFr_SHB = GainFrame; + + /* Gain attenuation when the SWB LSF quantization error is larger than a threshold */ + sd_uq_q = (sd_uq_q/0.0025f); + if( st->L_frame == L_FRAME ) + { + sd_uq_q = 1 - 0.2f* (sd_uq_q * sd_uq_q); + } + else + { + sd_uq_q = 1 - 0.1f* (sd_uq_q * sd_uq_q); + } + + sd_uq_q = max(min(sd_uq_q, 1.0f), 0.5f); + + pitBufAvg = 0.0025f * sum_f(pitch_buf, 4); + voicingBufAvg = (sum_f(voice_factors, 4) > 0.6f) ? 0.333f : 0.1667f; + voicingBufAvg = voicingBufAvg * sum_f(voicing, 3); + + if(voicingBufAvg <= 0.0f && (sd_uq_q*pitBufAvg != 0)) + { + voicingBufAvg = sd_uq_q*pitBufAvg/1.001f; + } + else if(voicingBufAvg <= 0.0f) + { + voicingBufAvg = 1.0f; + } + + /* Controlled gain evolution in SWB for stronger voiced segments */ + GainFrame *= max(min((float)(sd_uq_q*pitBufAvg/voicingBufAvg), 1.0f), 0.6f); + if( st->L_frame == L_FRAME16k || st->rf_mode == 1 ) + { + /* Compensate for energy increase mismatch due to memory-less synthesis*/ + GainFrame *= 0.85f; + } + + /* Quantization of the frame gain parameter */ + QuantizeSHBframegain( st, &GainFrame, st->extl, 0, &st->RF_bwe_gainFr_ind ); + + /* Adjust the subframe and frame gain of the synthesized SHB signal */ + /* Scale the shaped excitation */ + + + if( st->extl == FB_TBE) + { + for( i=0; i a[j]) + { + j = i; + } + } + + sum -= a[j] * a[j]; + + return (sum); +} + + +/*-------------------------------------------------------------------* + * EstimateSHBGainShape() + * + * Estimate temporal gain parameters + *-------------------------------------------------------------------*/ + +static void EstimateSHBGainShape( + const short length, /* i : SHB overlap length */ + const float *oriSHB, /* i : target original SHB frame */ + const float *synSHB, /* i : shaped SHB excitation */ + float *subgain, /* o : estimate of gain shape */ + const float *subwin /* i : SHB subframe window */ +) +{ + const short *skip; + short i, k; + float sum_gain, oriNrg, synNrg, sig; + short num_join, num_gains, join_length; + + float normFact; + + num_join = NUM_SHB_SUBFR/NUM_SHB_SUBGAINS; + num_gains = NUM_SHB_SUBGAINS; + skip = skip_bands_SWB_TBE; + + if( length == SHB_OVERLAP_LEN/2 ) + { + num_gains = NUM_SHB_SUBFR/4; + skip = skip_bands_WB_TBE; + } + + /* calculate and normalize the subgain */ + sum_gain = (float)1e-10; + oriNrg = 0.0f; + synNrg = 0.0f; + + if( length == SHB_OVERLAP_LEN/2 ) + { + for( i=0; i MAX_LSF/2) + { + offset = lsf_map[0]; + scale = (MAX_LSF - m)/m; + for (i = 0; i < NUM_MAP_LSF; i++) + { + lsf_map[i] = (lsf_map[i] - offset)*scale + offset; + } + } + + last_q_lsf = lsf_q[NUM_Q_LSF - 1]; + scale = MAX_LSF - last_q_lsf; + + for (i = 0; i < NUM_LSF_GRIDS; i++) + { + for (j = 0; j < NUM_MAP_LSF; j++) + { + grid[i][j] = lsf_grid[i][j]*scale + last_q_lsf; + } + } + + D_best = QUANT_DIST_INIT; + for (i = 0; i < NUM_LSF_GRIDS; i++) + { + D = EPSILON; + for (j = 0; j < NUM_MAP_LSF; j++) + { + lsf_t[j] = (1 - grid_smoothing[j])*lsf_map[j] + grid_smoothing[j]*grid[i][j]; + D += (lsf_t[j] - lsf[NUM_Q_LSF + j])*(lsf_t[j] - lsf[NUM_Q_LSF + j]); + } + + if (D < D_best) + { + mvr2r(lsf_t, lsf_smooth, NUM_MAP_LSF); + D_best = D; + I_best = i; + } + } + + for (i = 0; i < NUM_MAP_LSF; i++) + { + lsf_q[NUM_Q_LSF + i] = lsf_smooth[i]; + } + + return I_best; +} + +/*-------------------------------------------------------------------* +* gainFrSmooth_En() +* +* Gain frame smoothing and attenuation control +*-------------------------------------------------------------------*/ +static void gainFrSmooth_En( + Encoder_State *st, + float *shb_frame, + const float *lpc_shb, + const float *lsp_shb, + float *MA_lsp_shb_spacing, + short *frGainAttenuate, + short *frGainSmoothEn +) +{ + float lsp_slow_evol_rate = 0, lsp_fast_evol_rate = 0, lsp_spacing = 0.5f; + float temp_shb_frame[L_FRAME16k+L_SHB_LAHEAD]; + int i; + + for( i = 0; i < LPC_SHB_ORDER; i++ ) + { + lsp_spacing = min(lsp_spacing, (float)( i == 0 ? lsp_shb[0] : (lsp_shb[i] - lsp_shb[i -1]))); + + /* estimate the mean square error in lsps from current frame to past frames */ + lsp_slow_evol_rate += (lsp_shb[i] - st->lsp_shb_slow_interpl[i]) * (lsp_shb[i] - st->lsp_shb_slow_interpl[i]); + lsp_fast_evol_rate += (lsp_shb[i] - st->lsp_shb_fast_interpl[i]) * (lsp_shb[i] - st->lsp_shb_fast_interpl[i]); + + /* update the slow and fast interpolation lsps for next frame */ + st->lsp_shb_slow_interpl[i] = 0.7f * st->lsp_shb_slow_interpl[i] + 0.3f * lsp_shb[i]; + st->lsp_shb_fast_interpl[i] = 0.3f * st->lsp_shb_fast_interpl[i] + 0.7f * lsp_shb[i]; + } + + if( st->last_extl != SWB_TBE && st->last_extl != FB_TBE && lsp_spacing < 0.008f ) + { + st->lsp_shb_spacing[0] = lsp_spacing; + st->lsp_shb_spacing[1] = lsp_spacing; + st->lsp_shb_spacing[2] = lsp_spacing; + st->prev_frGainAtten = 1; + } + + *MA_lsp_shb_spacing = 0.1f*st->lsp_shb_spacing[0] + 0.2f*st->lsp_shb_spacing[1] + 0.3f*st->lsp_shb_spacing[2] + 0.4f*lsp_spacing; + + st->lsp_shb_spacing[0] = st->lsp_shb_spacing[1]; + st->lsp_shb_spacing[1] = st->lsp_shb_spacing[2]; + st->lsp_shb_spacing[2] = lsp_spacing; + + *frGainAttenuate = 0; + *frGainSmoothEn = 0; + + if( (lsp_spacing < 0.008f && (*MA_lsp_shb_spacing < 0.005f || st->prev_frGainAtten == 1)) || lsp_spacing <= 0.0032f ) + { + *frGainAttenuate = 1; + mvr2r(shb_frame, temp_shb_frame, L_FRAME16k+L_SHB_LAHEAD); + + fir( temp_shb_frame, lpc_shb, shb_frame, st->shb_inv_filt_mem, L_FRAME16k+L_SHB_LAHEAD, LPC_SHB_ORDER, 1 ); + + if( lsp_slow_evol_rate < 0.001f && lsp_fast_evol_rate < 0.001f ) + { + *frGainSmoothEn = 1; + } + } +} + +/*-------------------------------------------------------------------* + * Quant_BWE_LSF() + * + * Quantize super highband spectral envolope + *-------------------------------------------------------------------*/ + +static void Quant_BWE_LSF( + Encoder_State *st, /* i/o: encoder state structure */ + const float lsf_shb[], /* i : unquanitzed LSFs */ + float Q_lsfs[] /* o : quanitzed LSFs */ +) +{ + float lsf[LPC_SHB_ORDER]; + float lsf_q[LPC_SHB_ORDER]; + short lsf_idx[NUM_Q_LSF]; + short i; + short m_idx; + float m; + short grid_idx; + + for (i = 0; i < LPC_SHB_ORDER; i++) + { + lsf[i] = 0.5f - lsf_shb[LPC_SHB_ORDER - 1 - i]; + } + + Quant_lower_LSF( lsf, lsf_q, lsf_idx ); + + for (i = 0; i < NUM_Q_LSF; i++) + { + if(st->codec_mode == MODE2) + { + st->lsf_idx[i] = lsf_idx[i]; + } + else + { + push_indice( st, IND_SHB_LSF, lsf_idx[i], lsf_q_num_bits[i] ); + } + } + + m_idx = Quant_mirror_point(lsf, lsf_q, &m); + + if(st->codec_mode == MODE2) + st->m_idx = m_idx; + else + push_indice( st,IND_SHB_MIRROR, m_idx, MIRROR_POINT_BITS); + + grid_idx = Find_LSF_grid(lsf, lsf_q, m); + + if(st->codec_mode == MODE2) + st->grid_idx = grid_idx; + else + push_indice( st,IND_SHB_GRID, grid_idx, NUM_LSF_GRID_BITS); + + for (i = 0; i < LPC_SHB_ORDER; i++) + { + Q_lsfs[i] = 0.5f - lsf_q[LPC_SHB_ORDER - 1 - i]; + } + + return; +} + +/*-------------------------------------------------------------------* + * closest_centroid() + * + * Determine a set of closest VQ centroids for a given input + *-------------------------------------------------------------------*/ + +static short closest_centroid( + const float *data, /* i : input data */ + const float *weights, /* i : weights */ + const float *quantizer, /* i : quantizer table */ + const short centroids, /* i : number of centroids */ + const short length) /* i : dimension of quantiser */ +{ + short i,j, index; + float tmp, werr, best_werr; + + index = 0; + best_werr = 1.0E20f; + + for( i=0; i best_werr) break; + } + + if( werr < best_werr ) + { + best_werr = werr; + index = i; + } + } + + return index; +} + +/*-------------------------------------------------------------------* + * QuantizeSHBsubgains() + * + * Quantize super highband temporal gains + *-------------------------------------------------------------------*/ + +static void QuantizeSHBsubgains( + Encoder_State *st, /* i/o: encoder state structure */ + float subgains[], /* i/o: super highband temporal gains */ + const short extl /* i : extension layer */ +) +{ + short i, idxSubGain; + float Unit_weights10[NUM_SHB_SUBFR]; + + if( extl == WB_TBE ) + { + set_f( Unit_weights10, 1.0f, (short)NUM_SHB_SUBFR/4 ); + + for( i=0; i=0; i-- ) + { + subgains[i] = subgains[i/2]; + } + } + else + { + for(i = 0; i < NUM_SHB_SUBGAINS; i++) + { + subgains[i] = (float) log10(subgains[i] + 0.001f); + } + + idxSubGain = (short)vquant(subgains, 0, subgains, SHBCB_SubGain5bit, NUM_SHB_SUBGAINS, 1<= 0; i--) + { + subgains[i] = subgains[i*NUM_SHB_SUBGAINS/NUM_SHB_SUBFR]; + } + + if( st->codec_mode == MODE2 ) + { + st->idxSubGains = idxSubGain; + } + else + { + push_indice(st, IND_SHB_SUBGAIN, idxSubGain, NUM_BITS_SHB_SUBGAINS); + } + } + + return; +} + +/*-------------------------------------------------------------------* + * Quant_shb_ener_sf() + * + * Quantize SHB subframe energies + *-------------------------------------------------------------------*/ + +static void Quant_shb_ener_sf( + Encoder_State *st, /* i/o: encoder state structure */ + float *shb_ener_sf /* i/o: super highband subframe energies */ +) +{ + short idxSubEner; + + float temp_shb_ener_sf, sum; + + sum = *shb_ener_sf; + *shb_ener_sf = (float)log10(sum); + + temp_shb_ener_sf = 0; + idxSubEner = usquant(*shb_ener_sf, &temp_shb_ener_sf, 0, 0.042f, 1<codec_mode == MODE2) + st->idx_shb_fr_gain = idxSubEner; + else + push_indice( st, IND_SHB_ENER_SF, idxSubEner, NUM_BITS_SHB_ENER_SF); + + return; +} + +/*-------------------------------------------------------------------* +* Quant_shb_res_gshape() +* +* Quantize SHB gain shapes in residual domain +*-------------------------------------------------------------------*/ + +static void Quant_shb_res_gshape( + Encoder_State *st, /* i/o: encoder state structure */ + float shb_res_gshape[] /* i/o: super highband gain shapes */ +) +{ + short i, idxSubGain[NB_SUBFR16k]; + + for(i = 0; i < NB_SUBFR16k; i++) + { + idxSubGain[i] = usquant(shb_res_gshape[i], &shb_res_gshape[i], 0.125, 0.125f, 1<codec_mode == MODE2) + st->idx_res_gs[i] = idxSubGain[i]; + else + push_indice( st, IND_SHB_RES_GS1+i, idxSubGain[i], NUM_BITS_SHB_RES_GS); + } +} + +/*-------------------------------------------------------------------* + * QuantizeSHBframegains() + * + * Quantize super highband frame gain + *-------------------------------------------------------------------*/ + +static void QuantizeSHBframegain( + Encoder_State *st, /* i/o: encoder state structure */ + float *GainFrame, /* i/o: Gain */ + const short extl, /* i : extension layer */ + long extl_brate /* i : extension layer bitrate */ + ,short *rf_gainFrame_ind +) +{ + short idxFrameGain; + float Q_GainFrame; + float Unit_weights1 = 1.0f; + + float GainFrameLog; + + if ( extl == WB_TBE ) + { + determine_gain_weights( GainFrame, &(Unit_weights1), 1 ); + + if( extl_brate == WB_TBE_0k35 ) + { + singlevectortest_gain( GainFrame, 1, 1< *GainFrame * 1.06f && idxFrameGain > 0 ) /* 1.06 = +0.5 dB */ + { + idxFrameGain--; + Q_GainFrame = SHBCB_FrameGain16[idxFrameGain]; + } + + st->gFrame_WB = idxFrameGain; + *rf_gainFrame_ind = idxFrameGain; + } + else + { + singlevectortest_gain( GainFrame, 1, 1< GainFrameLog + 0.495*SHB_GAIN_QDELTA && idxFrameGain != 0) + { + idxFrameGain = idxFrameGain - 1; + Q_GainFrame = idxFrameGain*SHB_GAIN_QDELTA + SHB_GAIN_QLOW; + } + + Q_GainFrame = (float) pow(10.0, Q_GainFrame ); + if( st->codec_mode == MODE2 ) + { + st->idxFrameGain = idxFrameGain; + } + else + { + push_indice( st, IND_SHB_FRAMEGAIN, idxFrameGain, NUM_BITS_SHB_FRAMEGAIN ); + } + *rf_gainFrame_ind = idxFrameGain; + } + if( st->rf_mode ) + { + /*Currently intended for SWB only. Modify for WB is needed later!*/ + if( st->rf_frame_type == RF_NELP ) + { + *rf_gainFrame_ind = idxFrameGain; /* NELP Frame uses full 5 bits */ + } + else /*RF_ALLPRED, RF_GENPRED, RF_NOPRED modes*/ + { + if( *GainFrame <= 1.25 ) /* [0 to 1.25] range --> 0.5*/ + *rf_gainFrame_ind = 0; + else if ( *GainFrame <= 3 ) /* (1.25 to 3] --> 2 */ + *rf_gainFrame_ind = 1; + else if ( *GainFrame <= 6 ) /* (3 to 6] --> 4 */ + *rf_gainFrame_ind = 2; + else /* (6 to Inf) --> 8 */ + *rf_gainFrame_ind = 3; + } + } + + *GainFrame = Q_GainFrame; + + return; +} + + + +/*-------------------------------------------------------------------* + * determine_gain_weights() + * + * Determine weights for gain quantization + *-------------------------------------------------------------------*/ + +static void determine_gain_weights ( + const float *gain, /* i : Gain parameter */ + float *weights, /* o : gain weights */ + const short dims /* i : number of gains */ +) +{ + short j; + + for( j = 0; j < dims; j++ ) + { + if( gain[j] > 1e-6 ) + { + weights[j] = (float)(pow (fabs (gain[j]), -0.9f)); + } + else + { + weights[j] = 501.187233628f; + } + } + + return; +} + +/*-------------------------------------------------------------------* + * singlevectortest_gain() + * + * VQ for coding superhigh band gain + *-------------------------------------------------------------------*/ + +static void singlevectortest_gain ( + const float *inp, /* i : input gain vector */ + const short dimen, /* i : dimension of the input vector */ + const short cb_size, /* i : codebook size */ + short *index, /* o : quanitzation index */ + const float *weight, /* i : Weights for the quanitzation */ + float *recon, /* o : Reconstruction */ + const float *codebook /* i : Codebook */ +) +{ + short k, interNum, flag; + float meanU, meanQ; + short least[4]; + + interNum = 4; + + return_M_Least( inp, dimen, codebook, cb_size, weight, interNum, least ); + + meanU = sum_f( inp, dimen ); + mvr2r( codebook + dimen*least[0], recon, dimen ); + + index[0] = least[0]; + flag = 0; + for( k = 0; k < interNum; k++ ) + { + if( flag == 0 ) + { + meanQ = sum_f( codebook + dimen*least[k], dimen ); + + if( meanQ <= 1.1 * meanU ) + { + flag = 1; + mvr2r( codebook + dimen*least[k], recon, dimen ); + index[0] = least[k]; + } + } + } + + return; +} + +static void return_M_Least( + const float *inp, /* i: input */ + const short n_cols, /* i: vector size */ + const float *codebook, /* i: codebook */ + const short num_grp, /* i: number of centroids */ + const float *weight, /* i: gain weights */ + const short interNum, /* i: number on short list prior to 2nd stage search*/ + short *least /* o: return value */ +) +{ + short i, k; + float distance[1024], mindist, tmp; + + mindist = QUANT_DIST_INIT; + for( i = 0; i < num_grp; i++ ) + { + distance[i] = 0; + for( k = 0; k < n_cols; k++ ) + { + tmp = inp[k] - codebook[n_cols*i + k]; + distance[i] += weight[k] * tmp * tmp; + } + + if( distance[i] < mindist ) + { + mindist = distance[i]; + least[0] = i; + } + } + + distance[least[0]] = QUANT_DIST_INIT; + + for( k = 1; k < interNum; k++ ) + { + mindist = QUANT_DIST_INIT; + for( i = 0; i < num_grp; i++ ) + { + if( distance[i] < mindist ) + { + mindist = distance[i]; + least[k] = i; + } + } + + distance[least[k]] = QUANT_DIST_INIT; + } + + return; +} + + +/*-------------------------------------------------------------------* + * fb_tbe_reset_enc() + * + * Reset the extra parameters needed for FB TBE encoding + *-------------------------------------------------------------------*/ + +void fb_tbe_reset_enc( + float elliptic_bpf_2_48k_mem[][4], + float *prev_fb_energy +) +{ + set_f( elliptic_bpf_2_48k_mem[0], 0.0f, 4 ); + set_f( elliptic_bpf_2_48k_mem[1], 0.0f, 4 ); + set_f( elliptic_bpf_2_48k_mem[2], 0.0f, 4 ); + set_f( elliptic_bpf_2_48k_mem[3], 0.0f, 4 ); + *prev_fb_energy = 0.0f; + + return; +} + +/*-------------------------------------------------------------------* + * fb_tbe_enc() + * + * FB TBE encoder, 14(resp. 15.5) - 20 kHz band encoding module + *-------------------------------------------------------------------*/ + +void fb_tbe_enc( + Encoder_State *st, /* i/o: encoder state structure */ + const float new_input[], /* i : input speech at 48 kHz sample rate */ + const float fb_exc[] /* i : FB excitation from the SWB part */ +) +{ + float fb_exc_energy, ratio, temp2; + float tmp_vec[L_FRAME48k]; + short idxGain; + float input_fhb[L_FRAME48k]; + short Sample_Delay_HP; + + elliptic_bpf_48k_generic( new_input, tmp_vec, st->elliptic_bpf_2_48k_mem, full_band_bpf_2 ); + + Sample_Delay_HP = NS2SA(48000, ACELP_LOOK_NS + DELAY_FD_BWE_ENC_12k8_NS + DELAY_FIR_RESAMPL_NS) - L_FRAME48k/2 ; + + if( st->last_extl != FB_TBE ) + { + set_f( st->old_input_fhb, 0.0f, Sample_Delay_HP ); + set_f(tmp_vec, 0.0f, 320); + } + + mvr2r( st->old_input_fhb, input_fhb, Sample_Delay_HP ); + mvr2r( tmp_vec, input_fhb + Sample_Delay_HP, L_FRAME48k-Sample_Delay_HP ); + mvr2r( tmp_vec + L_FRAME48k - Sample_Delay_HP, st->old_input_fhb, Sample_Delay_HP ); + + /* Compute the energy of the Fullband component over 4kHz (16kHz to 20kHz) */ + temp2 = sum2_f( input_fhb, L_FRAME48k/2 ) + st->prev_fb_energy; + st->prev_fb_energy = sum2_f( input_fhb + L_FRAME48k/2, L_FRAME48k/2 ); + fb_exc_energy = sum2_f( fb_exc, L_FRAME16k ) + EPSILON; + ratio = (float) sqrt( temp2 / fb_exc_energy ); + idxGain = (short)( log2_f ((float)ratio) + 0.5f ); + idxGain = max( 0, min(15,idxGain) ); + ratio = (float)(1 << idxGain); + + if( st->codec_mode == MODE2 ) + { + st->idxGain = idxGain; + } + else + { + push_indice( st, IND_FB_SLOPE, idxGain, 4 ); + } + + + return; +} + + +/*---------------------------------------------------------------------* + * tbe_write_bitstream() + * + * Write TBE bitstream. + *---------------------------------------------------------------------*/ +void tbe_write_bitstream( + Encoder_State *st +) +{ + short i; + + if ( (st->rf_mode || st->total_brate == ACELP_9k60) && st->bwidth == WB) + { + /* WB LSF */ + push_next_indice( st, st->lsf_WB, NUM_BITS_LBR_WB_LSF ); + + /* WB frame */ + push_next_indice( st, st->gFrame_WB, NUM_BITS_SHB_FrameGain_LBR_WB ); + } + else if (st->total_brate >= ACELP_9k60 && st->total_brate <= ACELP_32k && (st->bwidth == SWB || st->bwidth == FB)) + { + /* LSF coefficients */ + + if(st->rf_mode || st->total_brate == ACELP_9k60) + { + push_next_indice( st, st->lsf_idx[0], 8 ); + } + else + { + for (i = 0; i < NUM_Q_LSF; i++) + { + push_next_indice( st, st->lsf_idx[i], lsf_q_num_bits[i] ); + } + + /* LSF mirror points */ + push_next_indice( st, st->m_idx, MIRROR_POINT_BITS ); + + /* LSF grid points */ + push_next_indice( st, st->grid_idx, NUM_LSF_GRID_BITS ); + } + + /* Gain shape */ + push_next_indice( st, st->idxSubGains, NUM_BITS_SHB_SUBGAINS ); + + /* frame gain */ + push_next_indice( st, st->idxFrameGain, NUM_BITS_SHB_FRAMEGAIN ); + + if (st->total_brate >= ACELP_24k40) + { + /* sub frame energy*/ + push_next_indice( st, st->idx_shb_fr_gain, NUM_BITS_SHB_ENER_SF ); + + /* gain shapes residual */ + for (i = 0; i < NB_SUBFR16k; i++) + { + push_next_indice( st, st->idx_res_gs[i], NUM_BITS_SHB_RES_GS ); + } + + /* voicing factor */ + push_next_indice( st, st->idx_mixFac, NUM_BITS_SHB_VF ); + } + + if( st->tec_tfa == 1 ) + { + push_next_indice( st, st->tec_flag, BITS_TEC ); + push_next_indice( st, st->tfa_flag, BITS_TFA ); + } + } + + if (st->bwidth == FB) + { + push_next_indice( st, st->idxGain, 4 ); + } +} + + + +void TBEreset_enc( + Encoder_State *st, /* i/o: encoder state structure */ + short bandwidth /* i : bandwidth mode */ +) +{ + if(st->last_core != ACELP_CORE) + { + set_f( st->old_bwe_exc, 0.0f, PIT16k_MAX * 2 ); + st->bwe_non_lin_prev_scale = 0.f; + } + + if( bandwidth == WB ) + { + wb_tbe_extras_reset( st->mem_genSHBexc_filt_down_wb2, st->mem_genSHBexc_filt_down_wb3 ); + set_f( st->mem_genSHBexc_filt_down_shb, 0, 7 ); + set_f( st->state_lpc_syn, 0, 10 ); + set_f( st->state_syn_shbexc, 0, L_SHB_LAHEAD/4 ); + set_f( st->syn_overlap, 0, L_SHB_LAHEAD ); + set_f( st->mem_csfilt, 0, 2 ); + } + else if( bandwidth == SWB || bandwidth == FB ) + { + set_f( st->state_ana_filt_shb, 0.0f, (2*ALLPASSSECTIONS_STEEP+1) ); + + swb_tbe_reset( st->mem_csfilt, st->mem_genSHBexc_filt_down_shb, st->state_lpc_syn, + st->syn_overlap, st->state_syn_shbexc, &(st->tbe_demph), &(st->tbe_premph), + st->mem_stp_swb, &(st->gain_prec_swb) ); + + + if( bandwidth == FB ) + { + set_f(st->fb_state_lpc_syn, 0, LPC_SHB_ORDER); + st->fb_tbe_demph = 0; + fb_tbe_reset_enc( st->elliptic_bpf_2_48k_mem, &st->prev_fb_energy ); + } + + } + + return; +} + diff --git a/src/libs/libevs/lib_enc/swb_tbe_enc_fx.cpp b/src/libs/libevs/lib_enc/swb_tbe_enc_fx.cpp deleted file mode 100755 index e189e58c..00000000 --- a/src/libs/libevs/lib_enc/swb_tbe_enc_fx.cpp +++ /dev/null @@ -1,3677 +0,0 @@ -/*==================================================================================== - EVS Codec 3GPP TS26.442 Apr 03, 2018. Version 12.11.0 / 13.6.0 / 14.2.0 - ====================================================================================*/ - - -#include -#include "options.h" -#include "cnst_fx.h" -#include "prot_fx.h" -#include "rom_com_fx.h" -#include "stl.h" - -/*-----------------------------------------------------------------* -* Local functions -*-----------------------------------------------------------------*/ -static void return_M_Least_fx_GainFrame( const Word32* inp, - const Word32* codebook, const Word16 num_grp, - const Word16 interNum, Word16* least ); - - -static void singlevectortest_gain_fx( const Word32* inp, const Word16 dimen, - const Word16 cb_size, Word16* index, - Word32* recon, const Word32* codebook ); - - -static void determine_gain_weights_fx( const Word32* gain, Word16* weights, - const Word16 dims ); - -static void QuantizeSHBsubgains_fx( Encoder_State_fx* st_fx, Word16* subgains, const Word16 extl ); - - -static void QuantizeSHBframegain_fx( Encoder_State_fx* st_fx, Word32* GainFrame, const Word16 extl, Word32 extl_brate - ,Word16 *rf_gainFrame_ind); - -static Word16 closest_centroid_fx( const Word16* data, const Word16* weights, - const Word16* quantizer, const Word16 centroids, const Word16 length ); - -static Word16 closest_centroid_lc_fx( const Word16* data, const Word16* quantizer, const Word16 centroids ); - -static void EstimateSHBFrameGain_fx( const Word16 length, - const Word16* oriSHB, const Word16 Q_oriSHB, - const Word16* synSHB, const Word16 Q_synSHB, Word16* subgain, - Word32* GainFrame, const Word16* win_shb, const Word16* subwin_shb, const Word16 n_subfr_saturation ); - - -static void EstimateSHBGainShape_fx( const Word16 length, - const Word16* oriSHB, const Word16 Q_oriSHB, - const Word16* synSHB, const Word16 Q_synSHB, - Word16* subgain, const Word16* subwin, Word16* n_subfr_saturation ); - - -static Word32 pow_off_pk_fx( Word16 a[], Word16 len, Word16 step ); - -static void find_max_mem_enc( Encoder_State_fx *st_fx, Word16 *n_mem, Word16 *n_mem2 ); -static void rescale_genSHB_mem_enc( Encoder_State_fx* st_fx, Word16 sf ); -static void find_max_mem_wb_enc( Encoder_State_fx* st_fx, Word16* n_mem ); -static void rescale_genWB_mem_enc( Encoder_State_fx* st_fx, Word16 sf ); - -static void Quant_lower_LSF_fx( const Word16 lsf[], - Word16 lsf_q[], - Word16 lsf_idx[]); - -static Word16 Quant_mirror_point_fx( const Word16 lsf[], const Word16 lsf_q[], - Word16* m ); -static Word16 Find_LSF_grid_fx( const Word16 lsf[], Word16 lsf_q[], - const Word16 m ); -static void Quant_BWE_LSF_fx( Encoder_State_fx* st_fx, const Word16 lsp_shb[], Word16 Q_lsfs[]); -static void Quant_shb_ener_sf_fx(Encoder_State_fx *st_fx, Word32 *shb_ener_sf_fx_32, Word16 Q_shb); -static void Quant_shb_res_gshape_fx(Encoder_State_fx *st_fx, Word16 *shb_res_gshape_fx); - -static void gainFrSmooth_En_fx(Encoder_State_fx *st_fx, - Word16 *shb_frame_fx, - const Word16 *lpc_shb_fx, - const Word16 *lsp_shb_fx, - Word16 *MA_lsp_shb_spacing, - Word16 *frGainAttenuate, - Word16 *frGainSmoothEn - ); - - -/*-------------------------------------------------------------------* - * find_max_mem_enc() - * - * Find norm and max in TBE memories and past buffers - *-------------------------------------------------------------------*/ -void find_max_mem_enc( - Encoder_State_fx *st_fx, - Word16 *n_mem, - Word16 *n_mem2 -) -{ - Word16 i; - Word16 n_mem_32; - Word16 max = 0; - Word32 Lmax = 0; - Word16 tempQ15, max2 = 0; - - /* old BWE exc max */ - FOR( i = 0; i < NL_BUFF_OFFSET; i++ ) - { - tempQ15 = abs_s( st_fx->old_bwe_exc_extended_fx[i] ); - max = s_max( max, tempQ15 ); - } - - /* decimate all-pass steep memory */ - FOR ( i = 0; i < (2*ALLPASSSECTIONS_STEEP+1); i++ ) - { - tempQ15 = abs_s( st_fx->mem_genSHBexc_filt_down_shb_fx[i] ); - max = s_max(max, tempQ15); - } - - /* -- keep norm of state_lpc_syn_fx, state_syn_shbexc_fx, - and mem_stp_swb_fx separately for 24.4 and 32kbps ----*/ - /* findMaxMem2() inside tbe com */ - FOR ( i = 0; i < LPC_SHB_ORDER; i++ ) - { - tempQ15 = abs_s( st_fx->state_lpc_syn_fx[i] ); - max2 = s_max(max2, tempQ15); - } - - /* findMaxMem2() inside tbe com */ - FOR ( i = 0; i < L_SHB_LAHEAD; i++ ) - { - tempQ15 = abs_s( st_fx->state_syn_shbexc_fx[i] ); - max2 = s_max(max2, tempQ15); - } - - /* findMaxMem2() inside tbe com */ - FOR ( i = 0; i < LPC_SHB_ORDER; i++ ) - { - tempQ15 = abs_s( st_fx->mem_stp_swb_fx[i] ); - max2 = s_max(max2, tempQ15); - } - - /* for total_brate > 16.4kbps, use n_mem2; else account for the max2 for n_mem calculation */ - *n_mem2 = norm_s(max2); - if(max2 == 0) *n_mem2 = 15; - if(L_sub(st_fx->total_brate_fx, ACELP_24k40) < 0) - { - max = s_max(max, max2); - } - - /* de-emph and pre-emph memory */ - tempQ15 = abs_s( st_fx->tbe_demph_fx ); - max = s_max(max, tempQ15); - - tempQ15 = abs_s( st_fx->tbe_premph_fx ); - max = s_max(max, tempQ15); - - IF( sub(st_fx->extl_fx, FB_TBE) == 0 ) - { - FOR ( i = 0; i < LPC_SHB_ORDER; i++ ) - { - tempQ15 = abs_s( st_fx->fb_state_lpc_syn_fx[i] ); - max = s_max(max, tempQ15); - } - /* FB de-emph memory */ - tempQ15 = abs_s( st_fx->fb_tbe_demph_fx); - max = s_max(max, tempQ15); - } - /* estimate the norm for 16-bit memories */ - *n_mem = norm_s( max ); - if( max == 0 ) - { - *n_mem = 15; - } - - /* estimate the norm for 32-bit memories */ - Lmax = L_abs( st_fx->mem_csfilt_fx[0] ); /* only element [0] is used in env. shaping */ - - n_mem_32 = norm_l( Lmax ); - if( Lmax == 0 ) - { - n_mem_32 = 31; - } - - tempQ15 = sub( s_min( *n_mem, n_mem_32 ), 1 ); - *n_mem = s_max( tempQ15, 0 ); -} - - -/*-------------------------------------------------------------------* - * rescale_genSHB_mem_enc() - * - * Rescale genSHB memories - *-------------------------------------------------------------------*/ -void rescale_genSHB_mem_enc( Encoder_State_fx* st_fx, Word16 sf ) -{ - Word16 i; - - FOR( i = 0; i old_bwe_exc_extended_fx[i] = shl( st_fx->old_bwe_exc_extended_fx[i], sf ); - move16(); - } - - FOR ( i = 0; i < 7; i++ ) - { - st_fx->mem_genSHBexc_filt_down_shb_fx[i] = shl( st_fx->mem_genSHBexc_filt_down_shb_fx[i], sf ); - move16(); - } - - /* -- Apply memory scaling for 13.2 and 16.4k bps using sf ----*/ - IF(L_sub(st_fx->total_brate_fx, ACELP_24k40) < 0) - { - FOR ( i = 0; i < LPC_SHB_ORDER; i++ ) - { - st_fx->state_lpc_syn_fx[i] = shl( st_fx->state_lpc_syn_fx[i], sf ); - move16(); - } - - FOR ( i = 0; i < L_SHB_LAHEAD; i++ ) - { - st_fx->state_syn_shbexc_fx[i] = shl( st_fx->state_syn_shbexc_fx[i], sf ); - move16(); - } - } - - st_fx->mem_csfilt_fx[0] = L_shl( st_fx->mem_csfilt_fx[0], sf ); - move32(); - - st_fx->tbe_demph_fx = shl_r( st_fx->tbe_demph_fx, sf ); - move16(); - st_fx->tbe_premph_fx = shl_r( st_fx->tbe_premph_fx, sf ); - move16(); - -} - -void find_max_mem_wb_enc( Encoder_State_fx* st_fx, Word16* n_mem ) -{ - Word16 i; - Word16 n_mem_32; - Word16 max =0; - Word32 Lmax =0; - - FOR ( i = 0; i < NL_BUFF_OFFSET; i++ ) - max = s_max( max, abs_s( st_fx->old_bwe_exc_extended_fx[i] ) ); - - FOR ( i = 0; i < 7; i++ ) - { - IF ( abs_s( st_fx->mem_genSHBexc_filt_down_shb_fx[i] ) > max ) - max = abs_s( st_fx->mem_genSHBexc_filt_down_shb_fx[i] ); - } - - FOR ( i = 0; i < 7; i++ ) - { - IF ( abs_s( st_fx->mem_genSHBexc_filt_down_wb2_fx[i] ) > max ) - max = abs_s( st_fx->mem_genSHBexc_filt_down_wb2_fx[i] ); - } - - FOR ( i = 0; i < 7; i++ ) - { - IF ( abs_s( st_fx->mem_genSHBexc_filt_down_wb3_fx[i] ) > max ) - max = abs_s( st_fx->mem_genSHBexc_filt_down_wb3_fx[i] ); - } - - FOR ( i = 0; i < 10; i++ ) - { - IF ( abs_s( st_fx->state_lpc_syn_fx[i] ) > max ) - max = abs_s( st_fx->state_lpc_syn_fx[i] ); - } - - FOR ( i = 0; i < 5; i++ ) - { - IF ( abs_s( st_fx->state_syn_shbexc_fx[i] ) > max ) - max = abs_s( st_fx->state_syn_shbexc_fx[i] ); - } - - IF ( max == 0 ) - { - *n_mem = 15; - move16(); - } - ELSE - { - *n_mem = norm_s( max ); - move16(); - } - - FOR ( i = 0; i < 2; i++ ) - { - IF ( L_abs( st_fx->mem_csfilt_fx[i] ) > Lmax ) - Lmax = L_abs( st_fx->mem_csfilt_fx[i] ); - } - - - IF ( Lmax == 0 ) - { - n_mem_32 = 31; - move16(); - } - ELSE - { - n_mem_32 = norm_l( Lmax ); - } - - *n_mem = sub( s_min( *n_mem, n_mem_32 ), 1 ); - move16(); - *n_mem = s_max( *n_mem, 0 ); -} - -void rescale_genWB_mem_enc( Encoder_State_fx* st_fx, Word16 sf ) -{ - Word16 i; - - FOR ( i = 0; i < NL_BUFF_OFFSET; i++ ) - { - st_fx->old_bwe_exc_extended_fx[i] = shl( st_fx->old_bwe_exc_extended_fx[i], sf ); - move16(); - } - - FOR ( i = 0; i < 10; i++ ) - { - st_fx->state_lpc_syn_fx[i] = shl( st_fx->state_lpc_syn_fx[i], sf ); - move16(); - } - - FOR ( i = 0; i < 5; i++ ) - { - st_fx->state_syn_shbexc_fx[i] = shl( st_fx->state_syn_shbexc_fx[i], sf ); - move16(); - } - - FOR ( i = 0; i < 7; i++ ) - { - st_fx->mem_genSHBexc_filt_down_shb_fx[i] = shl( st_fx->mem_genSHBexc_filt_down_shb_fx[i], sf ); - move16(); - } - - FOR ( i = 0; i < 7; i++ ) - { - st_fx->mem_genSHBexc_filt_down_wb2_fx[i] = shl( st_fx->mem_genSHBexc_filt_down_wb2_fx[i], sf ); - move16(); - } - - FOR ( i = 0; i < 7; i++ ) - { - st_fx->mem_genSHBexc_filt_down_wb3_fx[i] = shl( st_fx->mem_genSHBexc_filt_down_wb3_fx[i], sf ); - move16(); - } - - FOR ( i = 0; i < 2; i++ ) - { - st_fx->mem_csfilt_fx[i] = L_shl( st_fx->mem_csfilt_fx[i], sf ); - move32(); - } -} - - -/*-------------------------------------------------------------------* - * InitSWBencBuffer() - * - * Initialize SWB buffers - *-------------------------------------------------------------------*/ -void InitSWBencBuffer_fx( - Encoder_State_fx* st_fx /* i/o: SHB encoder structure */ -) -{ - set16_fx( st_fx->old_speech_shb_fx, 0, L_LOOK_16k + L_SUBFR16k ); - set16_fx( st_fx->old_bwe_exc_fx, 0, ( PIT16k_MAX * 2 ) ); - st_fx->bwe_seed_fx[0] = 23; - move16(); - st_fx->bwe_seed_fx[1] = 59; - move16(); - set16_fx( st_fx->old_bwe_exc_extended_fx, 0, NL_BUFF_OFFSET ); - - st_fx->bwe_non_lin_prev_scale_fx = L_deposit_l(0); - - set16_fx(st_fx->state_ana_filt_shb_fx, 0, (2*ALLPASSSECTIONS_STEEP+1)); - set32_fx( st_fx->elliptic_bpf_2_48k_mem_fx[0], 0, 4 ); - set32_fx( st_fx->elliptic_bpf_2_48k_mem_fx[1], 0, 4 ); - set32_fx( st_fx->elliptic_bpf_2_48k_mem_fx[2], 0, 4 ); - set32_fx( st_fx->elliptic_bpf_2_48k_mem_fx[3], 0, 4 ); - st_fx->prev_fb_energy_fx = 0; - move16(); - set16_fx( st_fx->elliptic_bpf_2_48k_mem_fx_Q, 0, 4 ); - st_fx->prev_fb_energy_fx_Q = 0; - move16(); - set16_fx( st_fx->prev_lsp_shb_fx, 0, 10 ); - st_fx->prev_Q_bwe_exc = 31; - move16(); - st_fx->prev_Q_bwe_syn = 31; - move16(); - set16_fx( st_fx->prev_lsp_wb_fx, 0, 6 ); - set16_fx( st_fx->prev_lsp_wb_temp_fx, 0, 6 ); - - set16_fx( st_fx->prev_lpc_wb_fx, 0, LPC_SHB_ORDER_WB); - - return; -} - -/*-------------------------------------------------------------------* - * ResetSHBbuffer_Enc() - * - *-------------------------------------------------------------------*/ -void ResetSHBbuffer_Enc_fx( - Encoder_State_fx* st_fx /* i/o: SHB encoder structure */ -) -{ - /* states for the filters used in generating SHB excitation from WB excitation*/ - set16_fx( st_fx->mem_genSHBexc_filt_down_shb_fx, 0, 2*ALLPASSSECTIONS_STEEP+1); - set32_fx( st_fx->mem_csfilt_fx, 0, 2 ); - - /* states for the filters used in generating SHB signal from SHB excitation*/ - set16_fx( st_fx->state_syn_shbexc_fx, 0, L_SHB_LAHEAD ); - set16_fx( st_fx->state_lpc_syn_fx, 0, LPC_SHB_ORDER ); - - IF( sub(st_fx->extl_fx, FB_TBE) == 0 ) - { - set16_fx( st_fx->fb_state_lpc_syn_fx, 0, LPC_SHB_ORDER ); - st_fx->fb_tbe_demph_fx = 0; - move16(); - } - /* states for the filters used in generating WB signal from WB excitation*/ - set16_fx( st_fx->decim_state1_fx, 0, 2*ALLPASSSECTIONS_STEEP+1 ); - set16_fx( st_fx->decim_state2_fx, 0, 2*ALLPASSSECTIONS_STEEP+1); - set16_fx( st_fx->mem_genSHBexc_filt_down_wb2_fx, 0, 2*ALLPASSSECTIONS_STEEP+1 ); - set16_fx( st_fx->mem_genSHBexc_filt_down_wb3_fx, 0, 2*ALLPASSSECTIONS_STEEP+1 ); - - /* overlap buffer used to Adjust SHB Frame Gain */ - set16_fx(st_fx->mem_stp_swb_fx, 0, LPC_SHB_ORDER); - st_fx->gain_prec_swb_fx = 16384;/*Q14=1 */ - set16_fx( st_fx->syn_overlap_fx, 0, L_SHB_LAHEAD ); - st_fx->tbe_demph_fx = 0; - st_fx->tbe_premph_fx = 0; - - - return; -} - - -/*==========================================================================*/ -/* FUNCTION : void wb_tbe_enc_fx() */ -/*--------------------------------------------------------------------------*/ -/* PURPOSE : WB TBE encoder, 6 - 8 kHz band encoding module */ -/*--------------------------------------------------------------------------*/ -/* INPUT ARGUMENTS : */ -/* Word16 coder_type i : coding type */ -/* Word16 *new_speech i : original input signal Q0 */ -/* Word32 *bwe_exc_extended i : bandwidth extended exciatation 2*Q_new*/ -/* Word16 voice_factors[] i : voicing factors Q15 */ -/* Word16 pitch_buf[] i : pitch for each subframe Q6 */ -/*--------------------------------------------------------------------------*/ -/* OUTPUT ARGUMENTS : */ -/* Word16 *synth o : WB SHB final synthesis */ -/*--------------------------------------------------------------------------*/ -/* INPUT/OUTPUT ARGUMENTS : */ -/* Encoder_State_fx *st_fx i/o: encoder state structure */ -/*--------------------------------------------------------------------------*/ -/* RETURN ARGUMENTS : */ -/* _ None */ -/*--------------------------------------------------------------------------*/ -/* */ -/*==========================================================================*/ - -#define WBTBE_LOOK_LSUFBR_5_OVER_16 (L_LOOK_12k8 + L_SUBFR)*5/16 -#define WBTBE_LSUBFR_5_OVER_16 L_SUBFR*5/16 -#define WBTBE_ANA_ALIGNDELAY -(L_SHB_LAHEAD/4 + 5) -#define LFRAME16K_OVER_4 L_FRAME16k/4 -#define WBTBE_LPCWIN_LENGTH (L_LOOK_12k8 + L_SUBFR + L_FRAME) * 5/16 - 1 - -void wb_tbe_enc_fx( - Encoder_State_fx *st_fx, /* i/o: encoder state structure */ - const Word16 coder_type, /* i : coding type */ - const Word16 *hb_speech, /* i : HB target signal (6-8kHz) at 16kHz at Q-1 */ - const Word32 *bwe_exc_extended, /* i : bandwidth extended exciatation */ - const Word16 Q_new, /* i : input HB speech Q factor */ - const Word16 voice_factors[], /* i : voicing factors */ - const Word16 pitch_buf[], /* i : pitch for each subframe */ - const Word16 voicing_fx[] /* i : OL maximum normalized correlation */ -) -{ - Word16 i, j, k; - Word16 hb_old_speech [(L_LOOK_12k8 + L_SUBFR + L_FRAME)*5/16]; - Word16 bwe_exc_extended_16[ L_FRAME32k+NL_BUFF_OFFSET ]; - - Word16 shaped_wb_excitation[(L_FRAME16k + L_SHB_LAHEAD)/4]; - Word16 exc4kWhtnd[L_FRAME16k/4]; - /*Word16 ana_align_delay = WBTBE_ANA_ALIGNDELAY; */ /* -L_SHB_LAHEAD/4 - 5 */ - Word32 GainFrame; - Word16 GainShape[NUM_SHB_SUBFR]; - Word16 lpc_wb[LPC_SHB_ORDER_WB+1]; - Word32 lpc_wb_32_fx[LPC_SHB_ORDER_WB + 1]; - Word16 lsp_wb[LPC_SHB_ORDER_WB], weights_lsp[LPC_SHB_ORDER_WB] = {32767, 32767}; - Word16 *hb_new_speech, *hb_frame/*, hb_speech[ L_FRAME16k ]*/; - Word16 R_h[ LPC_SHB_ORDER_WB + 2 ], R_l[ LPC_SHB_ORDER_WB + 2 ]; - Word16 Q_R; - Word32 LepsP[LPC_SHB_ORDER_WB+1]; - - Word32 prev_pow, curr_pow, Lscale; - /* Word16 scale; */ - /*Word16 ramp_flag;*/ - Word32 p2m_in, p2m_out; - /*Word16 cnt, max =0;*/ - Word16 n_mem, Q_bwe_exc, Q_bwe_exc_ext, exp_out; /* Q_hb_frame; */ - Word32 L_tmp, Lmax; - Word16 tmp, exp, Q_out, sc; - Word16 Q_ns = -1; - - Word16 pitBufAvg_fx, voicingBufAvg_fx; - Word16 vf_modified_fx[NB_SUBFR16k]; - Word16 temp_wb_fac_fx, feedback_fx; - Word16 lsp_spacing_fx; - Word16 lsp_wb_temp_fx[ LPC_SHB_ORDER_WB ], lpc_wb_temp_fx[ LPC_SHB_ORDER_WB + 1 ]; - Word32 L_feedback; - Word16 frac, exp1; - Word16 uv_flag; - Word16 dummy=0; - Word16 avg_voice_fac; - /*Word16 att = 32767;*/ - - hb_new_speech = hb_old_speech + WBTBE_LOOK_LSUFBR_5_OVER_16; - hb_frame = hb_old_speech + WBTBE_LSUBFR_5_OVER_16 + WBTBE_ANA_ALIGNDELAY; - - Copy( st_fx->old_speech_wb_fx, hb_old_speech, WBTBE_LOOK_LSUFBR_5_OVER_16 ); - Copy( hb_speech, hb_new_speech, LFRAME16K_OVER_4 ); - Copy( hb_old_speech + LFRAME16K_OVER_4, st_fx->old_speech_wb_fx, WBTBE_LOOK_LSUFBR_5_OVER_16 ); - - test(); - test(); - test(); - test(); - test(); - test(); - IF ( ( sub (st_fx->last_extl_fx, WB_TBE) != 0 && sub( st_fx->last_extl_fx, WB_BWE) != 0 ) - && ( sub( st_fx->clas_fx, UNVOICED_CLAS) == 0 || ( sub( voicing_fx[0], 16384 ) < 0 && sub( voicing_fx[1], 16384 ) < 0 && sub( voicing_fx[2], 16384 ) < 0 ) ) - && st_fx->igf == 0 ) - { - /* In case of unvoiced signals after switching cores, back-propagate the target signal */ - Copy( hb_speech, hb_old_speech, WBTBE_LOOK_LSUFBR_5_OVER_16 ); - - i = WBTBE_LOOK_LSUFBR_5_OVER_16; - move16(); - k = 0; - move16(); - - FOR ( j = 0; j < L_SUBFR16k; j = j + 4 ) - { - L_tmp = L_mult( hb_old_speech[i], ola_win_shb_switch_fold_fx[j] ); - hb_old_speech[i] = mac_r( L_tmp, hb_speech[j], ola_win_shb_switch_fold_fx[ L_SUBFR16k - 4 - j ] ); - move16(); - i--; - k++; - } - } - - autocorr_fx( hb_old_speech, LPC_SHB_ORDER_WB + 1, R_h, R_l, &Q_R, WBTBE_LPCWIN_LENGTH, win_lpc_hb_wb_fx, 0, 1 ); - - E_LPC_lev_dur(R_h, R_l, lpc_wb_temp_fx, LepsP, LPC_SHB_ORDER_WB, NULL); - - Copy_Scale_sig( lpc_wb_temp_fx, lpc_wb_temp_fx, LPC_SHB_ORDER_WB+1, sub(norm_s(lpc_wb_temp_fx[0]),2) ); - - /* convert into lsps and calculate weights */ - FOR ( i = 0; i <= LPC_SHB_ORDER_WB; i++ ) - { - lpc_wb_32_fx[i] = L_negate( L_shr( L_deposit_h( lpc_wb_temp_fx[i] ), 1 ) ); - move32(); - } - - lpc2lsp_fx( &lpc_wb_32_fx[1], lsp_wb_temp_fx, st_fx->prev_lsp_wb_temp_fx, LPC_SHB_ORDER_WB ); - - FOR ( i = 0; i < LPC_SHB_ORDER_WB; i++ ) - { - st_fx->prev_lsp_wb_temp_fx[i] = lsp_wb_temp_fx[i]; - move16(); - } - - /* lsp_spacing_fx = 16384; move16(); */ - lsp_spacing_fx = lsp_wb_temp_fx[0]; - move16(); - FOR ( i = 1; i < LPC_SHB_ORDER_WB; i++ ) - { - /*if ( i == 0 ) - { - tmp = lsp_wb_temp_fx[0]; move16(); - } - else - {*/ - tmp = sub( lsp_wb_temp_fx[i], lsp_wb_temp_fx[i - 1] ); - /*} */ - - lsp_spacing_fx = s_min( lsp_spacing_fx, tmp ); - } - - /* Spectral smoothing of autocorrelation coefficients */ - FOR ( i = 1; i <= LPC_SHB_ORDER_WB; i++ ) - { - L_tmp = Mpy_32( R_h[i], R_l[i], wac_h[i - 1], wac_l[i - 1] ); - L_Extract( L_tmp, &R_h[i], &R_l[i] ); - } - R_l[0] = s_max( R_l[0], 1 ); - move16(); - - test(); - IF ( sub(st_fx->rf_mode, 1) == 0 || L_sub(st_fx->extl_brate_fx, WB_TBE_0k35) == 0 ) - { - E_LPC_lev_dur(R_h, R_l, lpc_wb, LepsP, LPC_SHB_ORDER_LBR_WB, NULL); - Copy_Scale_sig( lpc_wb, lpc_wb, LPC_SHB_ORDER_LBR_WB+1, sub(norm_s(lpc_wb[0]),2) ); - - /* Expand bandwidth of the LP coeffs */ - FOR ( i = 0; i <= LPC_SHB_ORDER_LBR_WB; i++ ) - { - lpc_wb[i] = mult_r( lpc_wb[i], lpc_weights_fx[i] ); - move16(); - } - - /* convert into lsps and calculate weights */ - FOR ( i = 0; i <= LPC_SHB_ORDER_LBR_WB; i++ ) - { - lpc_wb_32_fx[i] = L_negate( L_shr( L_deposit_h( lpc_wb[i] ),1 ) ); - move32();/*Q27 */ - } - lpc2lsp_fx( &lpc_wb_32_fx[1], lsp_wb, st_fx->prev_lsp_wb_fx,LPC_SHB_ORDER_LBR_WB ); - - FOR ( i = 0; i < LPC_SHB_ORDER_LBR_WB; i++ ) - { - st_fx->prev_lsp_wb_fx[i] = lsp_wb[i]; - move16(); - } - - lsp_weights_fx( lsp_wb, weights_lsp, LPC_SHB_ORDER_LBR_WB, &Q_out ); - - /* Quantization of LSFs */ - i = closest_centroid_fx( lsp_wb, weights_lsp, lbr_wb_bwe_lsfvq_cbook_2bit_fx, 4, LPC_SHB_ORDER_LBR_WB ); - IF( sub(st_fx->codec_mode, MODE2) == 0 ) - { - st_fx->lsf_WB_fx = i; - move16(); - } - ELSE - { - push_indice_fx( st_fx, IND_SHB_LSF, i, NUM_BITS_LBR_WB_LSF ); - } - - Copy( lbr_wb_bwe_lsfvq_cbook_2bit_fx + i * LPC_SHB_ORDER_LBR_WB, lsp_wb, LPC_SHB_ORDER_LBR_WB ); - - lsp2lpc_fx( &lpc_wb[1], lsp_wb, st_fx->prev_lpc_wb_fx, LPC_SHB_ORDER_LBR_WB ); - - set16_fx( lpc_wb + LPC_SHB_ORDER_LBR_WB + 1, 0, ( LPC_SHB_ORDER_WB - LPC_SHB_ORDER_LBR_WB ) ); - FOR ( i = 0; i < LPC_SHB_ORDER_WB; i++ ) - { - st_fx->prev_lpc_wb_fx[i] = lpc_wb[i + 1]; - move16(); - } - - FOR ( i = 1; i < LPC_SHB_ORDER_LBR_WB + 1; i++ ) - { - lpc_wb[i] = negate( lpc_wb[i] ); - move16(); - } - lpc_wb[0] = 4096; - move16(); - } - ELSE /* 13.2kbps */ - { - E_LPC_lev_dur(R_h, R_l, lpc_wb, LepsP, LPC_SHB_ORDER_WB, NULL); - Copy_Scale_sig( lpc_wb, lpc_wb, LPC_SHB_ORDER_WB+1, sub(norm_s(lpc_wb[0]),2) ); - - /* Expand bandwidth of the LP coeffs */ - FOR ( i = 0; i <= LPC_SHB_ORDER_WB; i++ ) - { - lpc_wb[i] = mult_r( lpc_wb[i], lpc_weights_fx[i] ); - move16(); - } - - /* convert into lsps and calculate weights */ - FOR ( i = 0; i <= LPC_SHB_ORDER_WB; i++ ) - { - lpc_wb_32_fx[i] = L_negate( L_shr( L_deposit_h( lpc_wb[i] ), 1 ) ); - move32();/*Q27 */ - } - - lpc2lsp_fx( &lpc_wb_32_fx[1], lsp_wb, st_fx->prev_lsp_wb_fx, LPC_SHB_ORDER_WB ); - - - FOR( i = 0; i < LPC_SHB_ORDER_WB; i++ ) - { - st_fx->prev_lsp_wb_fx[i] = lsp_wb[i]; - move16(); - } - - lsp_weights_fx( lsp_wb, weights_lsp, LPC_SHB_ORDER_WB, &Q_out ); - - /* Quantization of LSFs */ - i = closest_centroid_fx( lsp_wb, weights_lsp, wb_bwe_lsfvq_cbook_8bit_fx, 256, LPC_SHB_ORDER_WB );/*move16(); */ - - IF( sub(st_fx->codec_mode, MODE2) == 0 ) - { - st_fx->lsf_WB_fx = i; - move16(); - } - ELSE - { - push_indice_fx( st_fx, IND_SHB_LSF, i, NUM_BITS_WB_LSF ); - } - Copy( wb_bwe_lsfvq_cbook_8bit_fx + i * LPC_SHB_ORDER_WB, lsp_wb, LPC_SHB_ORDER_WB ); - - lsp2lpc_fx( &lpc_wb[1], lsp_wb, st_fx->prev_lpc_wb_fx, LPC_SHB_ORDER_WB ); - - - FOR( i = 0; i < LPC_SHB_ORDER_WB; i++ ) - { - st_fx->prev_lpc_wb_fx[i] = lpc_wb[i + 1]; - move16(); - } - FOR( i = 1; i < LPC_SHB_ORDER_WB + 1; i++ ) - { - lpc_wb[i] = negate( lpc_wb[i] ); - move16(); - } - lpc_wb[0] = 4096; - move16(); - } - - uv_flag = 0; - move16(); - test(); - if( L_sub(st_fx->extl_brate_fx, WB_TBE_1k05) == 0 && sub(st_fx->coder_type_raw_fx,UNVOICED) == 0 ) - { - uv_flag = 1; - move16(); - } - - Copy( voice_factors, vf_modified_fx, NB_SUBFR16k ); - IF( sub(coder_type,VOICED) == 0 ) - { - FOR( i = 1; i < NB_SUBFR; i++ ) - { - /*vf_modified[i] = 0.8f * voice_factors[i] + 0.2f * voice_factors[i-1];*/ - vf_modified_fx[i] = add( mult_r( 26214, voice_factors[i] ), mult_r( 6553, voice_factors[i - 1] ) ); - } - IF( sub(st_fx->L_frame_fx, L_FRAME) != 0 ) - { - vf_modified_fx[4] = add( mult_r( 26214, voice_factors[4] ), mult_r( 6553, voice_factors[3] ) ); - } - } - - /* From low band excitation, generate highband excitation */ - Lmax = L_deposit_l(0); - FOR( i = 0; i < L_FRAME32k; i++ ) - { - Lmax = L_max( Lmax, L_abs( bwe_exc_extended[i] ) ); - } - - Q_bwe_exc = 31; - if( Lmax != 0 ) - { - Q_bwe_exc = norm_l( Lmax ); - } - Q_bwe_exc = sub( Q_bwe_exc, 3 ); - Q_bwe_exc = add( Q_bwe_exc, add( Q_new, Q_new ) ); - - find_max_mem_wb_enc( st_fx, &n_mem ); - - if( sub(sub( Q_bwe_exc, st_fx->prev_Q_bwe_exc ),n_mem) > 0 ) - { - Q_bwe_exc = add( st_fx->prev_Q_bwe_exc, n_mem ); - } - - IF( uv_flag ) - { - if( sub( Q_bwe_exc, 20 ) > 0 ) - { - Q_bwe_exc = 20; - move16();/* restrict this to 20 due to the Q factor requireemnt of the random number generator (keep 1 bit headroom) */ - } - } - - prev_pow = 0; - move16(); - FOR( i = 0; i < L_SHB_LAHEAD / 4; i++ ) - { - prev_pow = L_mac0( prev_pow, st_fx->state_syn_shbexc_fx[i], st_fx->state_syn_shbexc_fx[i] ); /* Q(2*st_fx->prev_Q_bwe_exc) */ - } - - rescale_genWB_mem_enc( st_fx, sub( Q_bwe_exc, st_fx->prev_Q_bwe_exc ) ); - - Copy( st_fx->old_bwe_exc_extended_fx, bwe_exc_extended_16, NL_BUFF_OFFSET ); - sc = sub( Q_bwe_exc, add( Q_new, Q_new ) ); - FOR ( i = 0; i < L_FRAME32k; i++ ) - { - bwe_exc_extended_16[i + NL_BUFF_OFFSET] = round_fx( L_shl( bwe_exc_extended[i], sc ) ); - } - Copy( bwe_exc_extended_16 + L_FRAME32k, st_fx->old_bwe_exc_extended_fx, NL_BUFF_OFFSET ); - - - Copy( st_fx->state_syn_shbexc_fx, shaped_wb_excitation, L_SHB_LAHEAD / 4 ); - Q_bwe_exc_ext = sub( Q_bwe_exc, 16 ); - - - GenShapedWBExcitation_fx( shaped_wb_excitation + L_SHB_LAHEAD / 4, lpc_wb, exc4kWhtnd, st_fx->mem_csfilt_fx, - st_fx->mem_genSHBexc_filt_down_shb_fx, st_fx->mem_genSHBexc_filt_down_wb2_fx, st_fx->mem_genSHBexc_filt_down_wb3_fx, - st_fx->state_lpc_syn_fx, coder_type, bwe_exc_extended_16, Q_bwe_exc_ext, st_fx->bwe_seed_fx, - vf_modified_fx, uv_flag - , st_fx->igf - ); - - curr_pow = 0; - move16(); - FOR ( i = 0; i < L_SHB_LAHEAD / 4; i++ ) - { - curr_pow = L_mac0( curr_pow, shaped_wb_excitation[i + L_SHB_LAHEAD/4], shaped_wb_excitation[i + L_SHB_LAHEAD / 4] ); /* Q(2*Q_bwe_exc_ext) */ - } - - IF ( sub( voice_factors[0], 24576 ) > 0 ) - { - curr_pow = L_shr( curr_pow, 2 ); /* Q(2*Q_bwe_exc_ext) */ - } - - Lscale = root_a_over_b_fx( curr_pow, shl_r( Q_bwe_exc_ext, 1 ), prev_pow, shl_r( sub( st_fx->prev_Q_bwe_exc, 16 ), 1 ), &exp ); - - - FOR ( i = 0; i < L_SHB_LAHEAD / 4 - 1; i++ ) - { - L_tmp = Mult_32_16( Lscale, shaped_wb_excitation[i] ); /* Q(16-exp+Q_bwe_exc_ext) */ - shaped_wb_excitation[i] = round_fx( L_shl( L_tmp, exp ) ); /* Q_bwe_exc_ext */ - } - - Lscale = root_a_fx( Lscale, 31 - exp, &exp ); - L_tmp = Mult_32_16( Lscale, shaped_wb_excitation[L_SHB_LAHEAD / 4 - 1] ); /* Q(16-exp+Q_bwe_exc_ext) */ - shaped_wb_excitation[L_SHB_LAHEAD / 4 - 1] = round_fx( L_shl( L_tmp, exp ) ); /* Q_bwe_exc_ext */ - - /* Update WB excitation */ - Copy( shaped_wb_excitation + L_FRAME16k / 4, st_fx->state_syn_shbexc_fx, L_SHB_LAHEAD / 4 ); - - EstimateSHBGainShape_fx( SHB_OVERLAP_LEN / 2, hb_frame, Q_ns, - shaped_wb_excitation, Q_bwe_exc_ext, GainShape,subwin_wb_fx, NULL ); - - /* Gain frame adjustment factor */ - test(); - IF( GainShape[0] && st_fx->prev_wb_GainShape ) - { - exp = norm_s( st_fx->prev_wb_GainShape ); - tmp = div_s( shl(1,sub( 14,exp )), st_fx->prev_wb_GainShape ); - L_tmp = L_mult( GainShape[0], tmp ); /* Q(30 - exp) */ - - exp1 = norm_l( L_tmp ); - frac = Log2_norm_lc( L_shl( L_tmp, exp1 ) ); - exp1 = sub( exp, exp1 ); - L_tmp = Mpy_32_16( exp1, frac, 22713 ); - temp_wb_fac_fx = round_fx( L_shl( L_tmp, 10 ) ); - } - ELSE - { - temp_wb_fac_fx = 0; - move16(); - } - L_feedback = L_mult0( temp_wb_fac_fx, temp_wb_fac_fx ); - FOR( i = 1; i < NUM_SHB_SUBFR / 4; i++ ) - { - /* temp_swb_fac = (float)log( (GainShape[i]+0.00001f) / (GainShape[i-1]+0.0001f) ); */ - test(); - IF( GainShape[i] && GainShape[i - 1] ) - { - exp = norm_s( GainShape[i - 1] ); - tmp = div_s( shl(1,sub( 14,exp )), GainShape[i - 1] ); - L_tmp = L_mult( GainShape[i], tmp );/*Q(30 - exp) */ - - exp1 = norm_l( L_tmp ); - frac = Log2_norm_lc( L_shl( L_tmp, exp1 ) ); - move16(); - exp1 = sub( exp, exp1 ); - L_tmp = Mpy_32_16( exp1, frac, 22713 ); - temp_wb_fac_fx = round_fx( L_shl( L_tmp, 10 ) ); - } - ELSE - { - temp_wb_fac_fx = 0; - move16(); - } - - L_feedback = L_mac( L_feedback, temp_wb_fac_fx, temp_wb_fac_fx ); - - } - L_tmp = L_add( L_shr( L_feedback, 1 ), 1 << 21 ); /* Q30 */ - - IF( L_tmp != 0 ) - { - exp = norm_l( L_tmp ); - tmp = extract_h( L_shl( L_tmp, exp ) ); - exp = sub( sub( 30, exp ), 21 ); - tmp = div_s( 16384, tmp ); /* Q(15+exp) */ - L_tmp = L_shr( L_mult( 13107, tmp ), exp ); /* Q31 */ - feedback_fx = round_fx( L_tmp ); /* Q15 */ - } - ELSE - { - feedback_fx = 8738; - move16();/* Q15 */ - } - - - temp_wb_fac_fx = st_fx->prev_wb_GainShape; - move16(); - FOR( i = 0; i < NUM_SHB_SUBFR / 4; i++ ) - { - GainShape[i] = add( mult_r( sub( 32767, feedback_fx ), GainShape[i] ), mult_r( feedback_fx, temp_wb_fac_fx ) ); - move16(); - temp_wb_fac_fx = GainShape[i]; - move16(); - } - - st_fx->prev_wb_GainShape = GainShape[sub(shr(NUM_SHB_SUBFR,2),1)]; - move16(); - p2m_in = pow_off_pk_fx( GainShape, shr(NUM_SHB_SUBFR,2), 1 ); - move16(); - - IF( L_sub(st_fx->extl_brate_fx,WB_TBE_0k35) == 0 ) - { - FOR( i = 0; i < 8; i++ ) - { - GainShape[i] = RECIP_ROOT_EIGHT_FX; - move16(); - } - - } - ELSE - { - push_indice_fx( st_fx, IND_UV_FLAG, uv_flag, 1 ); - - /* Quantization of the subframe gain parameter */ - QuantizeSHBsubgains_fx( st_fx, GainShape, st_fx->extl_fx ); - } - - /* Compute the power of gains away from the peak gain after quantization */ - p2m_out = pow_off_pk_fx( GainShape, NUM_SHB_SUBFR / 2, 2 ); - - /* Estimate the gain parameter */ - EstimateSHBFrameGain_fx( SHB_OVERLAP_LEN / 2, hb_frame, Q_ns, shaped_wb_excitation, Q_bwe_exc_ext, GainShape, - &GainFrame, window_wb_fx, subwin_wb_fx, 0 ); - - - /* If there's a big difference in the power of gains away from the peak gain */ - /* due to poor quantization then suppress energy of the high band. */ - - IF( L_sub( p2m_out, L_shl( p2m_in, 1 ) ) > 0 ) - { - L_tmp = root_a_over_b_fx( L_shl( p2m_in, 1 ), 29, p2m_out, 29, &exp_out ); - GainFrame = L_shl( Mult_32_32( GainFrame, L_tmp ), exp_out ); /* Q18 */ - } - - pitBufAvg_fx = 0; - move16(); - - FOR( i = 0; i < NB_SUBFR; i++ ) - { - pitBufAvg_fx = add( pitBufAvg_fx, mult_r( pitch_buf[i], 82 ) ); /*Q6 */ - } - voicingBufAvg_fx = 0; - move16(); - FOR( i = 0; i < 3; i++ ) - { - voicingBufAvg_fx = add( voicingBufAvg_fx, mult_r( voicing_fx[i], 10912 ) ); /*Q15 */ - } - /* GainFrame *= max(min((float)(pitBufAvg/voicingBufAvg), 1.0f), 0.7f); */ - tmp = 32767; - move16(); - IF( voicingBufAvg_fx > 0 ) - { - exp = norm_s( voicingBufAvg_fx ); - tmp = div_s( shl(1,sub( 14,exp )), voicingBufAvg_fx );/* (14-exp) */ - L_tmp = L_mult( pitBufAvg_fx, tmp ); /* (21-exp) */ - L_tmp = L_shl( L_tmp, add(exp, 10) ); - tmp = round_fx( L_tmp ); /* Q15 */ - } - - tmp = s_max( s_min( tmp, 32767 ), 22938 ); /* Q15 */ - GainFrame = Mult_32_16( GainFrame, tmp ); /* Q18 */ - - IF( sub( lsp_spacing_fx, 328 ) < 0 && lsp_spacing_fx ) - { - GainFrame = Mult_32_16( GainFrame, 21299 ); /* Q18 */ - } - - IF( sub(st_fx->codec_mode, MODE1) == 0 ) - { - /*wbbwe_em_factor = add( mult_r( 29491, st_fx->prev_wbbwe_em_factor_fx ), mult_r( 3277, wbbwe_em_factor ) ); */ /* Q15 */ - } - - - /*0.25f*sum_f(voice_factors, NB_SUBFR)*/ - L_tmp = L_mult(voice_factors[0], 8192); - FOR (i=1; iigf != 0 && sub(coder_type, VOICED) == 0 ) - { - /*GainFrame *= 0.5f;*/ - - GainFrame = Mult_32_16( GainFrame, 16384 ); - } - ELSE IF( st_fx->igf != 0 && sub( avg_voice_fac, 11469 ) > 0 ) /*Q15 -> 0.35f*/ - { - /*GainFrame *= 0.75f;*/ - GainFrame = Mult_32_16( GainFrame, 24576 ); - } - - /* Quantization of the frame gain parameter */ - QuantizeSHBframegain_fx( st_fx, &GainFrame, st_fx->extl_fx, st_fx->extl_brate_fx, &st_fx->rf_bwe_gainFr_ind ); - - /* Adjust the subframe and frame gain of the synthesized SHB signal */ - /* Scale the shaped excitation*/ - ScaleShapedSHB_fx( SHB_OVERLAP_LEN / 2, shaped_wb_excitation, st_fx->syn_overlap_fx, GainShape, GainFrame, window_wb_fx, subwin_wb_fx, - &Q_bwe_exc_ext, &dummy, dummy, dummy ); - - st_fx->prev_Q_bwe_exc = Q_bwe_exc; - move16(); - - return; -} - - -void fb_tbe_reset_enc_fx( - Word32 elliptic_bpf_2_48k_mem_fx[][4], - Word32 *prev_fb_energy_fx - ,Word16 elliptic_bpf_2_48k_mem_fx_Q[], - Word16 *prev_fb_energy_fx_Q -) -{ - set32_fx( elliptic_bpf_2_48k_mem_fx[0], 0, 4 ); - set32_fx( elliptic_bpf_2_48k_mem_fx[1], 0, 4 ); - set32_fx( elliptic_bpf_2_48k_mem_fx[2], 0, 4 ); - set32_fx( elliptic_bpf_2_48k_mem_fx[3], 0, 4 ); - *prev_fb_energy_fx = 0; - move16(); - set16_fx(elliptic_bpf_2_48k_mem_fx_Q, 0, 4); - *prev_fb_energy_fx_Q = 0; - move16(); - - return; -} -/*======================================================================================*/ -/* FUNCTION : void swb_tbe_enc_fx () */ -/*--------------------------------------------------------------------------------------*/ -/* PURPOSE : SWB TBE encoder, 6 - 14 kHz (or 7.5 - 15.5 kHz) band encoding module */ -/*--------------------------------------------------------------------------------------*/ -/* INPUT ARGUMENTS : */ -/* _(Word16) coder_type_fx : coding type */ -/* _(Word16*) shb_speech_fx : SHB target signal (6-14kHz) at 16kHz Q0 */ -/* _(Word16*) bwe_exc_extended :bandwidth extended exciatation Q0 */ -/* _(Word16[]) voice_factors :voicing factors Q15 */ -/* _(Word16*) Q_white_exc :Q Format of White Exc */ -/*--------------------------------------------------------------------------------------*/ -/* OUTPUT ARGUMENTS : */ -/* _(Word16[])White_exc16k_fx : shaped white excitation for the FB TBE Q_white_exc */ -/* _(Word16*)fb_slope_fx : slope +ve (high freq > low freq), -ve or neutral Q12 */ -/*--------------------------------------------------------------------------------------*/ -/* INPUT/OUTPUT ARGUMENTS : */ -/* _ Encoder_State_fx *st_fx: : Encoder state structure */ -/*--------------------------------------------------------------------------------------*/ -/* RETURN ARGUMENTS : */ -/* _ None */ -/*--------------------------------------------------------------------------------------*/ -/* CALLED FROM : TX */ -/*======================================================================================*/ - -void swb_tbe_enc_fx( - Encoder_State_fx *st_fx, /* i/o: encoder state structure */ - const Word16 coder_type_fx, /* i : coding type */ - Word16 *shb_speech_fx, /* i : SHB target signal (6-14kHz) at 16kHz Q_shb*/ - Word32 *bwe_exc_extended, /* i : bandwidth extended exciatation 2*Q_new*/ - const Word16 voice_factors_fx[], /* i : voicing factors Q15*/ - Word16 *White_exc16k_fx, /* o : shaped white excitation for the FB TBE Q_white_exc*/ - Word16 *Q_white_exc, - Word16 Q_new, - Word16 Q_shb, - Word16 *voicing, /* i : OL maximum normalized correlation */ - const Word16 pitch_buf[] /* i : subframe pitch Q6*/ -) -{ - Word16 i, j; - - Word16 shb_old_speech_fx[ L_LOOK_16k + L_SUBFR16k + L_FRAME16k ]; - Word16 bwe_exc_extended_16[ L_FRAME32k+NL_BUFF_OFFSET ]; - - Word16 shaped_shb_excitation_fx [ L_FRAME16k + L_SHB_LAHEAD ]; - Word32 GainFrame_fx; - Word16 GainShape_fx[ NUM_SHB_SUBFR ]; - Word16 lpc_shb_fx[ LPC_SHB_ORDER + 1 ], lsp_shb_fx[ LPC_SHB_ORDER ], lsf_shb_fx[ LPC_SHB_ORDER ]; - Word16 weights_lsp[LPC_SHB_ORDER]; - Word16 Q_out; - Word16* shb_frame_fx, *shb_new_speech_fx; - Word16 R_h[ LPC_SHB_ORDER+ 2 ]; /* Autocorrelations of windowed speech MSB */ - Word16 R_l[ LPC_SHB_ORDER+ 2 ]; /* Autocorrelations of windowed speech LSB */ - Word16 Q_R; - Word32 LepsP[LPC_SHB_ORDER+1]; - - Word16 ana_align_delay[2] = {-L_SHB_LAHEAD - (NL_BUFF_OFFSET/2), -L_SHB_LAHEAD - (NL_BUFF_OFFSET/2)}; - Word32 prev_pow_fx, curr_pow_fx, Lscale; - Word32 p2m_in_fx, p2m_out_fx; - - Word16 exp_out, exp, exp1, frac; - Word16 cnt, n_mem, n_mem2; - Word32 L_tmp, L_tmp1; - Word16 Q_bwe_exc; - - Word16 frGainAttenuate, frGainSmoothEn; - Word16 MA_lsp_shb_spacing; - Word16 temp_swb_fac, feedback; - Word32 L_feedback; - Word16 tmp, tmp1, tmp2; - Word32 Lmax; - Word16 sc; - Word16 lsf_shb_orig_fx[LPC_SHB_ORDER]; - Word16 sd_uq_q_fx; - Word16 vf_modified_fx[NB_SUBFR16k]; - Word16 pitBufAvg_fx; - Word16 voicingBufAvg_fx; - Word16 sum1, sum2; - Word16 recip,Q_recip; - const Word16 *ptr_lsp_interp_coef_fx; - - Word16 lsp_shb_1_fx[LPC_SHB_ORDER], lsp_shb_2_fx[LPC_SHB_ORDER], lsp_temp_fx[LPC_SHB_ORDER]; - Word16 lpc_shb_sf_fx[4*(LPC_SHB_ORDER+1)]; - - /*Word32 shb_ener_sf_fx_32[4];*/ - Word32 shb_ener_sf_Q31; - Word16 shb_res_fx[L_FRAME16k]; - Word16 shb_res_gshape_fx[NB_SUBFR16k]; - Word32 shb_res_gshape_fx_32[NB_SUBFR16k]; - Word16 vf_ind_fx; - - Word16 formant_fac_fx; - Word16 shaped_shb_excitationTemp_fx[L_FRAME16k]; - - Word16 mean_vf; - Word16 lsf_diff[LPC_SHB_ORDER], w[LPC_SHB_ORDER]; - Word16 refl[M]; - Word16 tilt_para; - Word16 Q_bwe_exc_fb; - Word16 n_subfr_saturation; - - /* init and buffers set up */ - exp1 = 0; /* to avoid compilation warnings */ - set16_fx( shaped_shb_excitationTemp_fx, 0, L_FRAME16k ); - - /* compensate for the delay in target generation and subframe LA */ - shb_frame_fx = shb_old_speech_fx + L_SUBFR16k + ana_align_delay[0]; - move16(); - - /* set up the speech buffers for TBE processing*/ - shb_new_speech_fx = shb_old_speech_fx + (L_LOOK_16k + L_SUBFR16k); - move16(); - Copy( st_fx->old_speech_shb_fx, shb_old_speech_fx, (L_LOOK_16k + L_SUBFR16k) ); - Copy( shb_speech_fx, shb_new_speech_fx, L_FRAME16k ); - Copy( shb_old_speech_fx + L_FRAME16k, st_fx->old_speech_shb_fx, (L_LOOK_16k + L_SUBFR16k) ); - - /* autocorrelation of SHB speech for 10-th order LP analysis */ - autocorr_fx( shb_old_speech_fx, - LPC_SHB_ORDER + 1, - R_h, /* autocorr (msb) Q15 */ - R_l, /* autocorr (lsb) */ - &Q_R, - NS2SA(INT_FS_16k, ACELP_LOOK_NS) + L_SUBFR16k + L_FRAME16k, - win_lpc_shb_fx, - 0, - 1 ); - - - /* Spectral smoothing of autocorrelation coefficients */ - test(); - IF( (st_fx->rf_mode != 0) || L_sub( st_fx->total_brate_fx, ACELP_9k60 ) == 0 ) - { - FOR( i = 1; i <= LPC_SHB_ORDER; i++ ) - { - L_tmp = Mpy_32( R_h[i], R_l[i], wac_swb_h[i - 1], wac_swb_l[i - 1] ); - L_Extract( L_tmp, &R_h[i], &R_l[i] ); - } - } - - /* Set the autocorr[0] element to a non-negative value */ - R_l[0] = s_max( R_l[0], 1 ); - move16(); - - E_LPC_lev_dur(R_h, R_l, lpc_shb_fx, LepsP, LPC_SHB_ORDER, NULL); /* LPC in Q14 */ - { - Word16 enerG, lpc_shb1[M+1]; - - /* extend the lpc_shb to a 16th order gain calc */ - set16_fx(lpc_shb1, 0, M+1); - Copy(lpc_shb_fx, lpc_shb1, LPC_SHB_ORDER + 1); - - /* estimate the LP gain */ - enerG = Enr_1_Az_fx(lpc_shb1, 2*L_SUBFR); /* Q3 */ - - /* if the LP gain is greater than a threshold, avoid saturation */ - IF(sub(enerG, 256/*32 Q3*/) > 0) - { - set16_fx(lpc_shb_fx, 0, LPC_SHB_ORDER+1); - E_LPC_lev_dur(R_h, R_l, lpc_shb_fx, LepsP, 2, NULL); /* LPC in Q14 */ - } - } - - /* this is needed as the E_LPC_lev_dur function outputs lpc in Q14 */ - Copy_Scale_sig( lpc_shb_fx, lpc_shb_fx, LPC_SHB_ORDER+1, sub(norm_s(lpc_shb_fx[0]),2) ); - - /* Expand bandwidth of the LP coeffs */ - test(); - IF( (st_fx->rf_mode != 0) || L_sub( st_fx->total_brate_fx, ACELP_9k60 ) == 0 ) - { - FOR( i = 1; i <= LPC_SHB_ORDER; i++ ) - { - lpc_shb_fx[i] = mult_r(lpc_shb_fx[i], lpc_weights_fx[i]); - } - } - - /* LPC to LSP conversion */ - /* LPC: Q12, LSP: Q15 */ - E_LPC_a_lsp_conversion(lpc_shb_fx, lsp_shb_fx, st_fx->prev_lsp_shb_fx, LPC_SHB_ORDER ); - - /* LSP to LSF conversion */ - /* LSP: Q15, LSF: Q15 */ - E_LPC_lsp_lsf_conversion( lsp_shb_fx, lsf_shb_fx, LPC_SHB_ORDER ); - - /* Input signal filtering in case of tonal sounds in the high band - gain Frame smoothing and attenuation control */ - gainFrSmooth_En_fx(st_fx, shb_frame_fx, lpc_shb_fx, lsf_shb_fx, &MA_lsp_shb_spacing, &frGainAttenuate, &frGainSmoothEn); - - Copy( lsp_shb_fx, st_fx->prev_lsp_shb_fx, LPC_SHB_ORDER ); - Copy( lsf_shb_fx, lsf_shb_orig_fx, LPC_SHB_ORDER ); - - test(); - IF( (sub(st_fx->rf_mode,1)==0) || L_sub( st_fx->total_brate_fx, ACELP_9k60 ) == 0 ) - { - lsp_weights_fx( lsf_shb_fx, weights_lsp, LPC_SHB_ORDER, &Q_out ); - - /* to compensate for the 1.1* weighting done inside the function lsp_weights */ - /*weights_lsp[3]*=0.909091f; weights_lsp[4]*=0.909091f; */ - weights_lsp[3] = mult_r( weights_lsp[3], 29789/*0.909091f Q15*/ ); - weights_lsp[4] = mult_r( weights_lsp[4], 29789/*0.909091f Q15*/ ); - - /* 8-bit VQ, 10 dimension */ - i = closest_centroid_fx( lsf_shb_fx, weights_lsp, swb_tbe_lsfvq_cbook_8b, 256, LPC_SHB_ORDER ); - Copy(swb_tbe_lsfvq_cbook_8b + i*LPC_SHB_ORDER, lsf_shb_fx, LPC_SHB_ORDER); - - set16_fx(st_fx->lsf_idx_fx, 0, NUM_Q_LSF); - st_fx->lsf_idx_fx[0] = i; - } - ELSE - { - /* LSF quantization (21 bits) */ - Quant_BWE_LSF_fx( st_fx, lsf_shb_fx, lsf_shb_fx ); - } - - /* space the lsfs to assert a minimum distance */ - space_lsfs_fx( lsf_shb_fx, LPC_SHB_ORDER ); - - /* voice factor adjustment and gainframe attenuation factor */ - tmp = sub( lsf_shb_fx[0], lsf_shb_orig_fx[0] ); - L_tmp = L_mult(tmp, tmp); - FOR( i = 1; i < LPC_SHB_ORDER; i++ ) - { - /* Estimate the QD in lsfs between UQ and Q */ - tmp = sub( lsf_shb_fx[i], lsf_shb_orig_fx[i] ); - L_tmp = L_mac( L_tmp, tmp, tmp ); - } - sd_uq_q_fx = round_fx(L_tmp); /* sd_uq_q_fx in Q15 */ - /* voice factor modification to limit any spurious jumps in the middle of voiced subframes*/ - /* mean(voice_factors_fx[i], 4); */ - - L_tmp = L_mult(voice_factors_fx[0], 8192); - L_tmp = L_mac(L_tmp, voice_factors_fx[1], 8192); - L_tmp = L_mac(L_tmp, voice_factors_fx[2], 8192); - mean_vf = mac_r(L_tmp, voice_factors_fx[3], 8192); - - Copy( voice_factors_fx, vf_modified_fx, NB_SUBFR16k ); - - test(); - IF( sub(coder_type_fx, VOICED) == 0 || sub(mean_vf, 13107/*0.4f Q15*/ ) > 0 ) - { - FOR( i = 1; i < NB_SUBFR; i++ ) - { - L_tmp = L_mult(voice_factors_fx[i], 26214); - vf_modified_fx[i] = mac_r(L_tmp, voice_factors_fx[i-1], 6554); - move16(); - } - IF( sub(st_fx->L_frame_fx, L_FRAME) != 0 ) - { - L_tmp = L_mult(voice_factors_fx[4], 26214); - vf_modified_fx[4] = mac_r(L_tmp, voice_factors_fx[3], 6554); - move16(); - } - } - - /* convert quantized LSFs to LSPs for interpolation */ - E_LPC_lsf_lsp_conversion(lsf_shb_fx, lsp_shb_2_fx, LPC_SHB_ORDER); - - test(); - IF( sub(st_fx->last_extl_fx, SWB_TBE) == 0 || sub(st_fx->last_extl_fx, FB_TBE) == 0) - { - /* SHB LSP values from prev. frame for interpolation */ - Copy(st_fx->swb_lsp_prev_interp_fx, lsp_shb_1_fx, LPC_SHB_ORDER); - } - ELSE - { - /* Use current frame's LSPs; in effect no interpolation */ - Copy(lsp_shb_2_fx, lsp_shb_1_fx, LPC_SHB_ORDER); - } - - lsf_diff[0] = lsf_diff[sub(LPC_SHB_ORDER,1)] = 16384;/*Q15*/ - FOR(i=1; i < LPC_SHB_ORDER-1; i++) - { - lsf_diff[i] = sub(lsf_shb_fx[i],lsf_shb_fx[sub(i,1)]); - } - a2rc_fx (st_fx->cur_sub_Aq_fx+1, refl, M); - - /* LSP interpolation for 13.2 kbps and 16.4 kbps */ - /* tilt_para = 6.6956f * (1.0f + refl[0]) * (1.0f + refl[0]) - - 3.8714f * (1.0f + refl[0]) - + 1.3041f; */ - tmp = add(16384,shr(refl[0],1));/*Q14*/ - tmp1 = mult(27425 /*Q12*/,tmp);/*Q11*/ - tmp1 = mult(tmp1,tmp); - tmp2 = shr(mult(31715,tmp),2); /* Q11 */ - tilt_para = add(sub(tmp1,tmp2),1335);/*Q10*/ - - IF(sub(st_fx->last_extl_fx,SWB_TBE) != 0) - { - FOR( i=1; iprev_lsf_diff_fx[i-1] = mult(lsf_diff[i],16384);/*Q15*/ - } - } - - IF( L_sub(st_fx->total_brate_fx,ACELP_16k40) <= 0 ) - { - test(); - test(); - test(); - test(); - test(); - IF(!(sub(st_fx->prev_tilt_para_fx,5120) > 0 && (sub(coder_type_fx,TRANSITION) == 0 || sub(tilt_para,1024) < 0)) && - !(((sub(st_fx->prev_tilt_para_fx,3072) < 0 && sub(st_fx->prev_coder_type_fx,VOICED) >= 0)) && sub(tilt_para,5120) > 0)) - { - FOR( i = 1; i < LPC_SHB_ORDER-1; i++ ) - { - IF(sub(lsf_diff[i],st_fx->prev_lsf_diff_fx[i-1]) < 0) - { - tmp = mult(26214,lsf_diff[i]); - tmp = div_s(tmp,st_fx->prev_lsf_diff_fx[i-1]); - tmp = s_max(tmp,16384); - w[i] = s_min(tmp,32767); - } - ELSE - { - tmp = mult(26214,st_fx->prev_lsf_diff_fx[i-1]); - tmp = div_s(tmp,lsf_diff[i]); - tmp = s_max(tmp,16384); - w[i] = s_min(tmp,32767); - } - } - w[0] = w[1]; - w[sub(LPC_SHB_ORDER,1)] = w[sub(LPC_SHB_ORDER,2)]; - - FOR( i = 0; i < LPC_SHB_ORDER; i++ ) - { - tmp1 = mult(lsp_shb_1_fx[i],sub(32767,w[i])); - tmp2 = mult(lsp_shb_2_fx[i],w[i]); - lsp_temp_fx[i] =add(tmp1,tmp2); - } - } - ELSE - { - Copy(lsp_shb_2_fx, lsp_temp_fx, LPC_SHB_ORDER); - } - } - - Copy( lsf_diff + 1, st_fx->prev_lsf_diff_fx, LPC_SHB_ORDER-2 ); - st_fx->prev_tilt_para_fx = tilt_para; - - shb_ener_sf_Q31 = 0; - move16(); - test(); - IF ( L_sub(st_fx->total_brate_fx, ACELP_24k40 ) == 0 || L_sub( st_fx->total_brate_fx, ACELP_32k) == 0 ) - { - /* ---------- SHB LSP interpolation ---------- */ - ptr_lsp_interp_coef_fx = interpol_frac_shb; /* Q15 */ - FOR( j = 0; j < 4; j++ ) - { - FOR( i = 0; i < LPC_SHB_ORDER; i++ ) - { - /*lsp_temp_fx[i] = lsp_shb_1_fx[i]*(*ptr_lsp_interp_coef_fx) */ - /* + lsp_shb_2_fx[i]*(*(ptr_lsp_interp_coef_fx+1)); */ - L_tmp = L_mult(lsp_shb_1_fx[i], (*ptr_lsp_interp_coef_fx)); - lsp_temp_fx[i] = mac_r(L_tmp, lsp_shb_2_fx[i], (*(ptr_lsp_interp_coef_fx+1))); - move16(); - } - ptr_lsp_interp_coef_fx += 2; - - tmp = i_mult2(j, (LPC_SHB_ORDER+1)); - /* convert LSPs to LPC coefficients for SHB synthesis*/ - E_LPC_f_lsp_a_conversion(lsp_temp_fx, lpc_shb_sf_fx+tmp, LPC_SHB_ORDER); - /* Bring the LPCs to Q12 */ - Copy_Scale_sig( lpc_shb_sf_fx+tmp, lpc_shb_sf_fx+tmp, LPC_SHB_ORDER+1, sub(norm_s(lpc_shb_sf_fx[tmp]),2) ); - } - - /* -------- Calculate the SHB Energy -------- */ - /*shb_ener_sf[0] = 0.003125f * sum2_f( shb_frame + L_SHB_LAHEAD, 320 );*/ - FOR( i = L_SHB_LAHEAD; i < L_FRAME16k + L_SHB_LAHEAD; i++) - { - /* shbEner = shbEner + in[i] * in[i] */ - shb_ener_sf_Q31 = L_mac0(shb_ener_sf_Q31, shb_frame_fx[i], shb_frame_fx[i]); - /* o: shb_ener_sf_Q31 in (2*Q_shb) */ - } - shb_ener_sf_Q31= Mult_32_16(shb_ener_sf_Q31, 102/*0.003125f Q15*/); - shb_ener_sf_Q31= L_add(1l/*1 Q0*/, shb_ener_sf_Q31); - Quant_shb_ener_sf_fx(st_fx, &shb_ener_sf_Q31, (2*Q_shb)); - - /* -------- calculate the residuals using the FOUR subframe LPCs -------- */ - set16_fx(shb_res_fx, 0, L_FRAME16k); - Residu3_10_fx(lpc_shb_sf_fx, shb_frame_fx + L_SHB_LAHEAD, shb_res_fx, 80, 0); - Residu3_10_fx(lpc_shb_sf_fx + (LPC_SHB_ORDER+1), shb_frame_fx + L_SHB_LAHEAD + 80, shb_res_fx + 80, 80, 0); - Residu3_10_fx(lpc_shb_sf_fx + 2*(LPC_SHB_ORDER+1), shb_frame_fx + L_SHB_LAHEAD + 160, shb_res_fx + 160, 80, 0); - Residu3_10_fx(lpc_shb_sf_fx + 3*(LPC_SHB_ORDER+1), shb_frame_fx + L_SHB_LAHEAD + 240, shb_res_fx + 240, 80, 0); - /* i: shb_frame_fx in Q_shb */ - /* o: shb_res_fx in Q_shb */ - - set32_fx(shb_res_gshape_fx_32, 0, NB_SUBFR16k); - FOR(i = 0; i < NB_SUBFR16k; i++) - { - shb_res_gshape_fx_32[i] = sum2_fx(shb_res_fx+i*64, 64); - } - /* o: shb_res_gshape_fx_32 in (2*Q_shb+1) */ - - maximum_32_fx(shb_res_gshape_fx_32, NB_SUBFR16k, &L_tmp); - - /* root_a_over_b_fx(shb_res_gshape_fx_32[i], (2*Q_shb+1), L_tmp, (2*Q_shb+1), &exp);*/ - /* First, find 1/L_tmp, L_tmp in QA = (2*Q_shb+1) */ - - /* case when den = 0 */ - recip = 0; /*instead of 32767 to be compatible with previous root_a_over_b_fx() output */ - Q_recip = 0; - - IF(L_tmp) - { - exp = norm_l(L_tmp); - tmp = extract_h(L_shl(L_tmp,exp)); - recip = div_s(16384,tmp); - Q_recip = 31-(exp-14); /* = 31-(exp+2*Q_shb+1-14), but adjusted by (2*Q_shb+1) for use at Mult_32_16 below */ - } - - FOR(i = 0; i < NB_SUBFR16k; i++) - { - L_tmp1 = Mult_32_16(shb_res_gshape_fx_32[i], recip); /*Q = Q_recip+1-16*/ - L_tmp = root_a_fx( L_tmp1, Q_recip+1-16, &exp ); - shb_res_gshape_fx[i] = round_fx(L_shl(L_tmp, exp-1)); /* Q14 */ - } - - Quant_shb_res_gshape_fx(st_fx, shb_res_gshape_fx); - } - - /* for 13.2 and 16.4kbps */ - E_LPC_f_lsp_a_conversion(lsp_temp_fx, lpc_shb_fx, LPC_SHB_ORDER); - Copy_Scale_sig( lpc_shb_fx, lpc_shb_fx, LPC_SHB_ORDER+1, sub(norm_s(lpc_shb_fx[0]),2) ); /* Q12 */ - - /* Save the SWB LSP values from current frame for interpolation */ - Copy(lsp_shb_2_fx, st_fx->swb_lsp_prev_interp_fx, LPC_SHB_ORDER); /* lsp_shb_2_fx in Q15 */ - - /* -------- start of memory rescaling -------- */ - /* ----- calculate optimum Q_bwe_exc and rescale memories accordingly ----- */ - Lmax = L_deposit_l(0); - FOR( cnt = 0; cnt < L_FRAME32k; cnt++ ) - { - Lmax = L_max( Lmax, L_abs( bwe_exc_extended[cnt] ) ); - } - Q_bwe_exc = norm_l( Lmax ); - if(Lmax == 0) - { - Q_bwe_exc = 31; - } - Q_bwe_exc = add( Q_bwe_exc, add( Q_new, Q_new ) ); - - /* Account for any outliers in the memories from previous frame for rescaling to avoid saturation */ - find_max_mem_enc( st_fx, &n_mem, &n_mem2); - - tmp2 = add( st_fx->prev_Q_bwe_exc, n_mem ); - if( sub( Q_bwe_exc, tmp2) > 0 ) - { - Q_bwe_exc = tmp2; - } - - /* rescale the memories if Q_bwe_exc is different from previous frame */ - sc = sub( Q_bwe_exc, st_fx->prev_Q_bwe_exc ); - IF( sc != 0 ) - { - rescale_genSHB_mem_enc( st_fx, sc ); - } - - /* rescale the bwe_exc_extended and bring it to 16-bit single precision with dynamic norm */ - Copy( st_fx->old_bwe_exc_extended_fx, bwe_exc_extended_16, NL_BUFF_OFFSET ); - sc = sub( Q_bwe_exc, add( Q_new, Q_new ) ); - - FOR( cnt = 0; cnt < L_FRAME32k; cnt++ ) - { - bwe_exc_extended_16[cnt + NL_BUFF_OFFSET] = round_fx( L_shl( bwe_exc_extended[cnt], sc ) ); - } - Copy( bwe_exc_extended_16 + L_FRAME32k, st_fx->old_bwe_exc_extended_fx, NL_BUFF_OFFSET ); - - /* state_syn_shbexc_fx is kept at (st_fx->prev_Q_bwe_syn) for 24.4/32kbps or is kept at Q_bwe_exc for 13.2/16.4kbps */ - Copy( st_fx->state_syn_shbexc_fx, shaped_shb_excitation_fx, L_SHB_LAHEAD ); - - /* save the previous Q factor of the buffer */ - st_fx->prev_Q_bwe_exc = Q_bwe_exc; - move16(); - - Q_bwe_exc = sub( Q_bwe_exc, 16 ); /* Q_bwe_exc reflecting the single precision dynamic norm-ed buffers from here */ - - /* -------- end of rescaling memories -------- */ - Q_bwe_exc_fb = st_fx->prev_Q_bwe_exc_fb; - move16(); - /* Determine formant PF strength */ - formant_fac_fx = swb_formant_fac_fx( lpc_shb_fx[1], &st_fx->tilt_mem_fx ); - /* i:lpc_shb_fx Q12, o:formant_fac_fx Q15 */ - - /* Calculate the 6 to 14 kHz (or 7.5 - 15.5 kHz) SHB excitation signal from the ACELP core excitation */ - vf_ind_fx = 20; - move16(); - - GenShapedSHBExcitation_fx( shaped_shb_excitation_fx + L_SHB_LAHEAD, lpc_shb_fx, White_exc16k_fx, - st_fx->mem_csfilt_fx, st_fx->mem_genSHBexc_filt_down_shb_fx, st_fx->state_lpc_syn_fx, - coder_type_fx, bwe_exc_extended_16, st_fx->bwe_seed_fx, vf_modified_fx, st_fx->extl_fx, - &( st_fx->tbe_demph_fx ), &( st_fx->tbe_premph_fx ), lpc_shb_sf_fx, shb_ener_sf_Q31, - shb_res_gshape_fx, shb_res_fx, &vf_ind_fx, formant_fac_fx, st_fx->fb_state_lpc_syn_fx, - &(st_fx->fb_tbe_demph_fx), &Q_bwe_exc,&Q_bwe_exc_fb, Q_shb, n_mem2, st_fx->prev_Q_bwe_syn, st_fx->total_brate_fx, 0 ); - - *Q_white_exc = Q_bwe_exc_fb; - IF( sub(st_fx->extl_fx, FB_TBE) == 0 ) - { - st_fx->prev_Q_bwe_exc_fb = Q_bwe_exc_fb; - } - ELSE - { - /*Indirectly a memory reset of FB memories for next frame such that rescaling of memories would lead to 0 due to such high prev. Q value. - 51 because of 31 + 20(shift of Q_bwe_exc_fb before de-emphasis)*/ - st_fx->prev_Q_bwe_exc_fb = 51; - move16(); - } - - test(); - IF( L_sub(st_fx->total_brate_fx, ACELP_24k40) == 0 || L_sub(st_fx->total_brate_fx, ACELP_32k) == 0 ) - { - IF( sub( st_fx->codec_mode, MODE2 ) == 0 ) - { - st_fx->idx_mixFac_fx = vf_ind_fx; - move16(); - } - ELSE - { - push_indice_fx( st_fx, IND_SHB_VF, vf_ind_fx, NUM_BITS_SHB_VF); - } - } - - FOR( i = 0; i < LPC_SHB_ORDER; i++ ) - { - st_fx->mem_stp_swb_fx[i] = shl(st_fx->mem_stp_swb_fx[i], sub(Q_bwe_exc, st_fx->prev_Q_bwe_syn) ); - } - - FOR( i = 0; i < L_FRAME16k; i += L_SUBFR16k ) - { - PostShortTerm_fx( &shaped_shb_excitation_fx[L_SHB_LAHEAD+i], lpc_shb_fx, &shaped_shb_excitationTemp_fx[i], st_fx->mem_stp_swb_fx, - st_fx->ptr_mem_stp_swb_fx, &(st_fx->gain_prec_swb_fx), st_fx->mem_zero_swb_fx, formant_fac_fx ); - /* i: shaped_shb_excitation_fx in Q_bwe_exc */ - /* i: lpc_shb_fx in Q12 */ - } - Copy( shaped_shb_excitationTemp_fx, &shaped_shb_excitation_fx[L_SHB_LAHEAD], L_FRAME16k ); - - - - tmp = sub(shl(Q_bwe_exc, 1), 31); - prev_pow_fx = L_shl(21475l/*0.00001f Q31*/, tmp); /* 2*(Q_bwe_exc) */ - curr_pow_fx = L_shl(21475l/*0.00001f Q31*/, tmp); /* 2*(Q_bwe_exc) */ - FOR( i = 0; i < L_SHB_LAHEAD + 10; i++ ) - { - prev_pow_fx = L_mac0( prev_pow_fx, shaped_shb_excitation_fx[i], shaped_shb_excitation_fx[i] ); /* 2*Q_bwe_exc */ - curr_pow_fx = L_mac0( curr_pow_fx, shaped_shb_excitation_fx[i + L_SHB_LAHEAD + 10], shaped_shb_excitation_fx[i + L_SHB_LAHEAD + 10] ); /* 2*Q_bwe_exc */ - } - - if( sub( voice_factors_fx[0], 24576/*0.75f Q15*/ ) > 0 ) - { - /*curr_pow_fx = Mult_32_16( curr_pow_fx, 8192);*/ /* Q(2*Q_bwe_exc) */ - curr_pow_fx = L_shr(curr_pow_fx, 2); /* scale by 0.25 */ - } - - Lscale = root_a_over_b_fx( curr_pow_fx, - shl(Q_bwe_exc, 1), - prev_pow_fx, - shl(Q_bwe_exc, 1), - &exp ); - FOR( i = 0; i < L_SHB_LAHEAD; i++ ) - { - L_tmp = Mult_32_16( Lscale, shaped_shb_excitation_fx[i] ); /* Q(16-exp+Q_bwe_exc) */ - shaped_shb_excitation_fx[i] = round_fx( L_shl( L_tmp, exp ) ); /* Q_bwe_exc */ - } - IF( exp < 0 ) - { - Lscale = L_shl(Lscale, exp); - exp = 0; - } - FOR( ; i < L_SHB_LAHEAD + 10; i++ ) - { - tmp = i_mult(sub(i,19), 3277/*0.1f Q15*/); /* Q15 */ - L_tmp1 = Mult_32_16(L_shl(1, sub(31,exp)), tmp); /* Q31-exp */ - tmp = sub(32767/*1.0f Q15*/, tmp); - Lscale = L_add(Mult_32_16(Lscale, tmp), L_tmp1); - L_tmp = Mult_32_16( Lscale, shaped_shb_excitation_fx[i] ); /* Q_bwe_exc + (31-exp) - 15 */ - shaped_shb_excitation_fx[i] = round_fx( L_shl( L_tmp, exp ) ); /* Q_bwe_exc */ - } - - /* Update SHB excitation */ - Copy( shaped_shb_excitation_fx + L_FRAME16k, st_fx->state_syn_shbexc_fx, L_SHB_LAHEAD ); /* Q_bwe_exc */ - - /* Estimate the gain-shape parameter */ - n_subfr_saturation = 0; - move16(); - EstimateSHBGainShape_fx( SHB_OVERLAP_LEN, shb_frame_fx, Q_shb, shaped_shb_excitation_fx, - Q_bwe_exc, GainShape_fx, subwin_shb_fx, &n_subfr_saturation ); - - /* Gain shape BWS/high band low energy fix */ - IF( sub(st_fx->cldfbHBLT, 8192/*1.0f Q13*/) < 0 ) /* cldfbHBLT in Q13 */ - { - /* There is not much HB past 10kHz; the temporal resolution is quite coarse, so reduce the dynamic range */ - FOR(i = 0; i < NUM_SHB_SUBGAINS; i++) - { - /* 0.35f +/- delta variation; delta = 0.1*(GS-0.35)*/ - /* GainShape[i] = 0.315f + 0.1f * GainShape[i]; */ - GainShape_fx[i] = mac_r(676457349l/*0.315 Q31*/, 3277/*0.1 Q15*/, GainShape_fx[i]); - } - } - - /* Gain frame adjustment factor */ - /* log( (GainShape[0]) / (st->prev_wb_GainShape) )*/ - test(); - IF( GainShape_fx[0] && st_fx->prev_swb_GainShape_fx ) - { - exp = norm_s( st_fx->prev_swb_GainShape_fx ); - tmp = div_s( shl(1, sub( 14, exp )), st_fx->prev_swb_GainShape_fx ); - L_tmp = L_mult( GainShape_fx[0], tmp );/*Q(30 - exp) */ - - exp1 = norm_l( L_tmp ); - frac = Log2_norm_lc( L_shl( L_tmp, exp1 ) );/*move16(); */ - exp1 = sub(exp, exp1 ); /*move16(); */ - L_tmp = Mpy_32_16( exp1, frac, 22713 ); - temp_swb_fac = round_fx( L_shl( L_tmp, 10 ) ); - } - ELSE - { - temp_swb_fac = 0; - move16(); - } - L_feedback = L_mult0( temp_swb_fac, temp_swb_fac ); - - - FOR( i = 1; i < NUM_SHB_SUBGAINS; i++ ) - { - test(); - IF( GainShape_fx[i] && GainShape_fx[i - 1] ) - { - exp = norm_s( GainShape_fx[i - 1] ); - tmp = div_s( shl(1, sub( 14, exp )), GainShape_fx[i - 1] ); - L_tmp = L_mult( GainShape_fx[i], tmp );/* Q(30 - exp) */ - - exp1 = norm_l( L_tmp ); - frac = Log2_norm_lc( L_shl( L_tmp, exp1 ) ); - exp1 = sub( exp , exp1 ); - L_tmp = Mpy_32_16( exp1, frac, 22713 ); - temp_swb_fac = round_fx( L_shl( L_tmp, 10 ) ); - } - ELSE - { - temp_swb_fac = 0; - move16(); - } - - L_feedback = L_mac( L_feedback, temp_swb_fac, temp_swb_fac ); - } - - /* feedback = 0.4f / (1 + 0.5f * feedback) */ - L_tmp = L_add( L_shr( L_feedback, 1 ), L_shl(1,21) ); /* Q21 */ - IF( L_tmp != 0 ) - { - exp = norm_l( L_tmp ); - tmp = extract_h( L_shl( L_tmp, exp ) ); - exp = sub( sub( 30, exp ), 21 ); - tmp = div_s( 16384, tmp ); /*Q(15+exp) */ - L_tmp = L_shr( L_mult( 13107, tmp ), exp ); /*Q31 */ - feedback = round_fx( L_tmp ); /*Q15 */ - } - ELSE - { - feedback = 8738; - move16(); /*Q15 */ - } - - /* voicing in Q15 */ - L_tmp = L_mult(voicing[0],8192); - L_tmp = L_mac(L_tmp, voicing[1],8192); - L_tmp = L_mac(L_tmp, voicing[2],8192); - tmp = sum1 = round_fx(L_tmp); /* sum1 used again below - Q13 */ - tmp = add(tmp,1); /* To ensure change is BE */ - - /* voice_factors_fx in Q15 */ - L_tmp = L_mult(voice_factors_fx[0],8192); - L_tmp = L_mac(L_tmp, voice_factors_fx[1],8192); - L_tmp = L_mac(L_tmp, voice_factors_fx[2],8192); - L_tmp = L_mac(L_tmp, voice_factors_fx[3],8192); - tmp1 = sum2 = round_fx(L_tmp); /* sum2 used again below - Q13 */ - - - test(); - test(); - IF( sub(frGainAttenuate,1) == 0 || ( sub( tmp, 19661 ) > 0 && sub( tmp1, 6554 ) > 0 ) ) - - { - temp_swb_fac = st_fx->prev_swb_GainShape_fx; - FOR( i = 0; i < NUM_SHB_SUBGAINS; i++ ) - { - /*GainShape_fx[i] = (1 - feedback) * GainShape[i] + feedback * temp_swb_fac; */ - GainShape_fx[i] = round_fx(L_mac(L_mult(sub( 32767, feedback ), GainShape_fx[i] ),feedback, temp_swb_fac ) ); - temp_swb_fac = GainShape_fx[i]; - move16(); - } - } - st_fx->prev_swb_GainShape_fx = GainShape_fx[3]; - move16(); - - /* Compute the power of gains away from the peak gain prior to quantization */ - p2m_in_fx = pow_off_pk_fx( GainShape_fx, NUM_SHB_SUBGAINS, 1 ); - - /* Quantization of the gain shape parameter */ - - QuantizeSHBsubgains_fx( st_fx, GainShape_fx, st_fx->extl_fx ); - /* o: GainShape_fx in Q15 */ - /* Compute the power of gains away from the peak gain after quantization */ - p2m_out_fx = pow_off_pk_fx( GainShape_fx, NUM_SHB_SUBFR, 4 ); - - /* Estimate the gain parameter */ - EstimateSHBFrameGain_fx( SHB_OVERLAP_LEN, shb_frame_fx, Q_shb, shaped_shb_excitation_fx, Q_bwe_exc, - GainShape_fx, &GainFrame_fx, window_shb_fx, subwin_shb_fx, n_subfr_saturation ); - - IF( sub(st_fx->tec_tfa, 1) == 0 ) - { - tfaCalcEnv_fx( shb_frame_fx, st_fx->tfa_enr ); - } - - /* If there's a big difference in the power of gains away from the peak gain */ - /* due to poor quantization then suppress energy of the high band. */ - IF( L_sub( p2m_out_fx, L_shl( p2m_in_fx, 1 ) ) > 0 ) - { - L_tmp = root_a_over_b_fx( p2m_in_fx, 28, p2m_out_fx, 29, &exp_out ); - GainFrame_fx = L_shl( Mult_32_32( GainFrame_fx, L_tmp ), exp_out ); /* Q18 */ - } - test(); - IF( sub(frGainSmoothEn,1) == 0 && L_sub( st_fx->prev_gainFr_SHB_fx, GainFrame_fx ) < 0 ) - { - GainFrame_fx = L_add( L_shr(st_fx->prev_gainFr_SHB_fx, 1), L_shr(GainFrame_fx, 1) ); /* Q18 */ - } - - test(); - IF( sub(frGainAttenuate, 1) == 0 && sub( MA_lsp_shb_spacing, 79/*0.0024f Q15*/ ) <= 0 ) - { - exp1 = norm_l( GainFrame_fx ); - frac = Log2_norm_lc( L_shl( GainFrame_fx, exp1 ) ); - exp = sub(30, add( exp1, 21 ) ); - L_tmp = Mpy_32_16( exp, frac, 26214 ); /* Q16 */ - frac = L_Extract_lc( L_tmp, &exp ); - GainFrame_fx = Pow2( 30, frac ); - exp = sub( exp, 30); - GainFrame_fx = L_shl( GainFrame_fx, exp + 18 ); /* Q18 */ - } - ELSE IF( sub(st_fx->prev_frGainAtten_fx, 1) == 0 && L_sub( Mult_32_16( GainFrame_fx, 10923 ), st_fx->prev_gainFr_SHB_fx ) > 0 ) - { - /*GainFrame *= (0.8f + 0.5f*feedback); */ - tmp = add( 26214, mult_r( feedback, 16384 ) ); - GainFrame_fx = Mult_32_16( GainFrame_fx, tmp ); /* Q18 */ - } - st_fx->prev_frGainAtten_fx = frGainAttenuate; - move16(); - st_fx->prev_gainFr_SHB_fx = GainFrame_fx; - move16(); /* Q18 */ - - - /* Gain attenuation when the SWB LSF quantization error is larger than a threshold */ - tmp = mult_r(25600/*400 Q6*/, sd_uq_q_fx); /* Q6 * Q15 => Q6 */ - IF(sub(st_fx->L_frame_fx, L_FRAME) == 0) - { - tmp1 = mult_r(6554/*0.2f Q15*/, tmp); /* Q15, Q6 => Q6 */ - L_tmp = L_msu(8192l/*1.0f Q13*/, tmp1, tmp); /* Q13 */ - } - ELSE - { - tmp1 = mult_r(3277/*0.1f Q15*/, tmp); /* Q15, Q6 => Q6 */ - L_tmp = L_msu(8192l/*1.0f Q13*/, tmp1, tmp); /* Q13 */ - } - /* sd_uq_q = max(min(sd_uq_q, 1.0f), 0.5f); */ - L_tmp = L_min(L_tmp, 8192l/*1.0f Q13*/); - L_tmp = L_max(L_tmp, 4096l/*0.5f Q13*/); /* Q13 */ - /* keep the L_tmp; dont overwrite */ - - /* pitBufAvg = 0.0025f * sum_f(pitch_buf, 4); */ - /* pitch_buf: Q6 */ - pitBufAvg_fx = mult_r(pitch_buf[0],1311) ; - pitBufAvg_fx = add( pitBufAvg_fx, mult_r(pitch_buf[1],1311) ); - pitBufAvg_fx = add( pitBufAvg_fx, mult_r(pitch_buf[2],1311) ); - pitBufAvg_fx = add( pitBufAvg_fx, mult_r(pitch_buf[3],1311) ); /* Q10 */ - - /* voicingBufAvg = (sum_f(voice_factors, 4)=sum2 > 0.6f) ? 0.333f : 0.1667f; */ - tmp2 = 5462/*0.1667f Q15*/; - if(sub(sum2, 4915/*0.6f Q13*/) > 0) - { - tmp2 = 10912/*0.333f Q15*/; /* Q15 */ - } - voicingBufAvg_fx = shl(mult(tmp2, sum1),2); /* Q15 */ - - - - /* max(min((float)(sd_uq_q*pitBufAvg/voicingBufAvg), 1.0f), 0.6f) */ - /* sd_uq_q: Q13, pitBufAvg_fx: Q6, voicingBufAvg_fx: Q15 */ - - /* 1/voicingBufAvg_fx */ - tmp = 32767; - move16(); - IF( voicingBufAvg_fx > 0 ) - { - exp = norm_s( voicingBufAvg_fx ); - tmp = div_s( shl(1, sub( 14, exp )), voicingBufAvg_fx ); /* (14-exp) */ - - /* sd_uq_q*pitBufAvg */ - L_tmp = Mult_32_16(L_tmp, pitBufAvg_fx); /* Q13 * Q10 + 1 -16 => Q8 */ - L_tmp = Mult_32_16(L_tmp, tmp ); /* Q8 + (14 - exp) - 15 => Q7 - exp */ - tmp = round_fx(L_shl(L_tmp, 31-(7-exp))); /* Q15 */ - } - - tmp = s_min(tmp, 32767/*1.0f Q15*/); - tmp = s_max(tmp, 19661/*0.6f Q15*/); - GainFrame_fx = Mult_32_16(GainFrame_fx, tmp); /* Q18 + Q15 + 1 - 16 : Q18 */ - - test(); - IF(sub(st_fx->L_frame_fx, L_FRAME16k) == 0 || sub(st_fx->rf_mode,1) == 0) - { - /* Compensate for energy increase mismatch due to memory-less synthesis*/ - GainFrame_fx = Mult_32_16(GainFrame_fx, 27853/*0.85f Q15*/ ); /* Q18 */ - } - - /* Quantization of the frame gain parameter */ - QuantizeSHBframegain_fx( st_fx, &GainFrame_fx, st_fx->extl_fx, 0, &st_fx->rf_bwe_gainFr_ind ); - - /* Adjust the subframe and frame gain of the synthesized SHB signal */ - /* Scale the shaped excitation */ - IF( L_sub(st_fx->extl_fx,FB_TBE) == 0 ) - { - tmp = norm_l( GainFrame_fx ); - if(GainFrame_fx == 0) - { - tmp = 31; - } - L_tmp = L_shl(GainFrame_fx,tmp);/* 18 + tmp */ - - tmp1 =0; - FOR( i = 0; i < L_FRAME16k; i++ ) - { - L_tmp1 = Mult_32_16( L_tmp, GainShape_fx[NUM_SHB_SUBFR * i / L_FRAME16k] ); /* Q : 18 + tmp +15 -15*/ - /*White_exc16k_fx[i] = round_fx( L_shl(Mult_32_16( L_tmp1, White_exc16k_fx[i]),(23 - tmp -*Q_white_exc)) );*/ - /*18 + tmp +*Q_white_exc -15 + 23 - tmp -*Q_white_exc -16 = 10*/ - White_exc16k_fx[i] = round_fx( Mult_32_16( L_tmp1, White_exc16k_fx[i] ) );/* 18 + tmp +*Q_white_exc -15 -16 */ - /*Lmax = L_max(Lmax,White_exc16k_fx[i]);*/ - tmp1 = s_max(tmp1,abs_s(White_exc16k_fx[i])); - /*White_exc16k_fx[i] =32767;*/ - /*White_exc16k_fx[i] = shr(White_exc16k_fx[i],5);*/ - } - *Q_white_exc = sub(add(*Q_white_exc, tmp),13); /* *Q_white_exc + 18 + tmp -15 -16 */ - tmp = norm_s( tmp1 ); - if(tmp1 == 0) - { - tmp = 15; - } - - FOR(i=0; iprev_Q_bwe_syn = Q_bwe_exc; - move16(); - - return; -} - - -/*==========================================================================*/ -/* FUNCTION : static void EstimateSHBFrameGain_fx() */ -/*--------------------------------------------------------------------------*/ -/* PURPOSE : Estimate the overall gain factor needed to scale */ -/* synthesized highband to original highband signal level. */ -/*--------------------------------------------------------------------------*/ -/* INPUT ARGUMENTS : */ -/* _(Word16) length : SHB overlap length Q0 */ -/* _(Word16*) oriSHB : target original SHB frame Q_oriSHB */ -/* _(Word16*) synSHB : shaped SHB excitation Q_synSHB */ -/* _(Word16*) win_shb : SHB window Q15 */ -/* _(Word16*) subwin_shb : SHB subframe window Q15 */ -/* _(Word16) Q_oriSHB : Q format of oriSHB */ -/* _(Word16) Q_synSHB : Q format of synSHB */ -/*--------------------------------------------------------------------------*/ -/* OUTPUT ARGUMENTS : */ -/* _(Word32*)GainFrame :estimat of gain frame Q18 */ -/*--------------------------------------------------------------------------*/ -/* INPUT/OUTPUT ARGUMENTS : */ -/* _None */ -/*--------------------------------------------------------------------------*/ -/* RETURN ARGUMENTS : */ -/* _ None */ -/*--------------------------------------------------------------------------*/ - -static void EstimateSHBFrameGain_fx( - const Word16 length, /* i : SHB overlap length */ - const Word16* oriSHB, /* i : target original SHB frame Q_oriSHB */ - const Word16 Q_oriSHB, - const Word16* synSHB, /* i : shaped SHB excitation Q_synSHB */ - const Word16 Q_synSHB, - Word16* subgain, /* i : estimate of gain shape Q15 */ - Word32* GainFrame, /* o : estimat of gain frame Q18 */ - const Word16* win_shb, /* i : SHB window Q15 */ - const Word16* subwin_shb /* i : SHB subframe window Q15 */ - ,const Word16 n_subfr_saturation /* i : Number of subframes which saturated in GainShape oriNrg calculation */ -) -{ - const Word16* skip; - Word16 i, j, k, l_shb_lahead, l_frame; - Word16 join_length, num_join, sig; - Word32 mod_syn[L_FRAME16k+L_SHB_LAHEAD]; - Word32 oriNrg = 0, synNrg = 0; - Word16 sum_gain; - Word32 frame_gain; - Word32 L_tmp; - Word16 exp_out; - Word16 tmp; - Word16 scaling = 0; - - - /* initilaization */ - l_frame = L_FRAME16k; - move16(); - l_shb_lahead = L_SHB_LAHEAD; - move16(); - skip = skip_bands_SWB_TBE; - - - IF( sub(length,SHB_OVERLAP_LEN / 2) == 0 ) - { - skip = skip_bands_WB_TBE; - l_frame = L_FRAME16k / 4; - move16(); - l_shb_lahead = L_SHB_LAHEAD / 4; - move16(); - } - - /* apply gain for each subframe, and store noise output signal using overlap-add*/ - set32_fx( mod_syn, 0, l_frame + l_shb_lahead ); - - - IF( sub(length,SHB_OVERLAP_LEN / 2 ) == 0) - { - sum_gain = 0; - move16(); - j = skip[0]; - move16(); - FOR( k = 0; k < length / 2; k++ ) - { - sum_gain = mult_r( subwin_shb[2 * k + 2], subgain[0] ); /* Q15 */ - mod_syn[j + k] = L_mult( synSHB[j + k], sum_gain ); - move32();/* Q(16+Q_synSHB) */ - mod_syn[j + k + length / 2] = L_mult( synSHB[j + k + length / 2], subgain[0] ); - move32();/* Q(16+Q_synSHB) */ - } - - FOR( i = 1; i < NUM_SHB_SUBFR / 2; i++ ) - { - j = skip[i]; - move16(); - FOR( k = 0; k < length; k++ ) - { - - L_tmp = L_mult0( subwin_shb[k + 1], subgain[i] ); /* Q30 */ - sum_gain = round_fx( L_mac0( L_tmp, subwin_shb[length - k - 1], subgain[i - 1] ) );/* Q14 */ - mod_syn[j + k] = L_shl( L_mult( sum_gain, synSHB[j + k] ), 1 ); - move32();/* Q(16+Q_synSHB) */ - } - } - FOR( k = 0; k < length / 2; k++ ) - { - j = skip[i]; - move16(); - sum_gain = mult_r( subwin_shb_fx[ length - 2 * k - 2 ], subgain[i - 1] ); /* Q15 */ - mod_syn[ j + k ] = L_mult( synSHB[j + k], sum_gain ); - move32();/* Q(16+Q_synSHB) */ - } - } - ELSE - { - num_join = NUM_SHB_SUBFR / NUM_SHB_SUBGAINS; - move16(); - join_length = i_mult2( num_join, length ); - j = 0; - move16(); - FOR( k = 0; k < length; k++ ) - { - sum_gain = mult_r( subwin_shb[k + 1], subgain[0] ); /* Q15 */ - mod_syn[j] = L_mult( synSHB[j], sum_gain ); - move32(); /* Q(16+Q_synSHB) */ - j++; - } - FOR( i = 0; i < NUM_SHB_SUBGAINS - 1; i++ ) - { - FOR( k = 0; k < join_length - length; k++ ) - { - mod_syn[j] = L_mult( synSHB[j], subgain[i * num_join] ); - move32(); /* Q(16+Q_synSHB) */ - j++; - } - - FOR( k = 0; k < length; k++ ) - { - L_tmp = L_mult0( subwin_shb[length - k - 1], subgain[i * num_join] ); - tmp = round_fx( L_mac0( L_tmp, subwin_shb[k + 1], subgain[( i + 1 ) * num_join] ) ); /* Q14 */ - mod_syn[j] = L_shl( L_mult( tmp, synSHB[j] ), 1 ); - move32(); /* Q(16+Q_synSHB) */ - j++; - } - } - FOR( k = 0; k < join_length - length; k++ ) - { - mod_syn[j] = L_mult( synSHB[j], subgain[( NUM_SHB_SUBGAINS - 1 ) * num_join] ); - move32();/* Q(16+Q_synSHB)*/ - j++; - } - FOR( k = 0; k < length; k++ ) - { - tmp = mult_r( subwin_shb[length - k - 1], subgain[( NUM_SHB_SUBGAINS - 1 ) * num_join] ); /* Q15 */ - mod_syn[j] = L_mult( tmp, synSHB[j] ); - move32();/* Q(16+Q_synSHB ) */ - j++; - } - - } - /* adjust frame energy */ - oriNrg = L_deposit_l(0); - synNrg = L_deposit_l(0); - - FOR( i = 0; i < l_shb_lahead; i++ ) - { - sig = mult_r( oriSHB[i], win_shb[i] ); /* Q_oriSHB */ - oriNrg = L_mac0( oriNrg, sig, sig ); /* 2*Q_orisHB*/ - sig = round_fx( Mult_32_16( mod_syn[i], win_shb[i] ) ); /*Q_synSHB */ - synNrg = L_mac0( synNrg, sig, sig ); /* 2*Q_synSHB */ - } - - FOR( ; i < l_frame; i++) - { - oriNrg = L_mac0( oriNrg, oriSHB[i], oriSHB[i] ); /* 2*Q_oriSHB */ - sig = round_fx( mod_syn[i] ); /* Q_oriSHB */ - synNrg = L_mac0( synNrg, sig, sig ); /* 2*Q_oriSHB */ - } - - tmp = add(l_frame, l_shb_lahead); - FOR( ; i < tmp; i++) - { - sig = mult_r( oriSHB[i], win_shb[l_frame + l_shb_lahead - 1 - i] ); /* Q_oriSHB */ - oriNrg = L_mac0( oriNrg, sig, sig ); /* 2*Q_oriSHB */ - - sig = round_fx( Mult_32_16( mod_syn[i], win_shb[l_frame + l_shb_lahead - 1 - i] ) ); /* Q_oriSHB */ - synNrg = L_mac0( synNrg, sig, sig ); /* 2*Q_oriSHB */ - } - IF(L_sub(oriNrg, MAX_32) == 0) - { - scaling = negate(shr(n_subfr_saturation, 1) + 1); - move16(); - oriNrg = 0; - move32(); - FOR( i = 0; i < l_shb_lahead; i++ ) - { - sig = mult_r( shl(oriSHB[i], scaling), win_shb[i] ); - oriNrg = L_mac0( oriNrg, sig, sig ); /* 2*Q_oriSHB + 2*scaling */ - } - FOR( ; i < l_frame; i++) - { - sig = shl(oriSHB[i], scaling); - oriNrg = L_mac0( oriNrg, sig, sig ); /* 2*Q_oriSHB + 2*scaling */ - } - FOR( ; i < tmp; i++) - { - sig = mult_r( shl(oriSHB[i], scaling), win_shb[l_frame + l_shb_lahead - 1 - i] ); - oriNrg = L_mac0( oriNrg, sig, sig ); /* 2*Q_oriSHB + 2*scaling */ - } - } - L_tmp = root_a_over_b_fx( oriNrg, 2 * Q_oriSHB, synNrg, 2 * Q_synSHB, &exp_out ); - exp_out = sub(exp_out, scaling); - frame_gain = L_shl( L_tmp, sub( exp_out, 13 ) ); /* Q18 */ - *GainFrame = frame_gain; - move32(); - - return; -} - - -static Word32 pow_off_pk_fx( Word16 a[], Word16 len, Word16 step ) -{ - Word16 i, j = 0; - Word32 sum, L_tmp; - - sum = L_shr( L_mult0( a[0], a[0] ), 1 ); /* Q29 */ - - j = 0; - move16(); - FOR( i=1; i < len; i += step) - { - L_tmp = L_shr( L_mult0( a[i], a[i] ), 1 ); /* Q29 */ - sum = L_add( sum, L_tmp ); /* Q29 */ - if( sub( a[i], a[j] ) > 0 ) - { - j = i; - move16(); - } - } - L_tmp = L_shr( L_mult0( a[j], a[j] ), 1 ); /* Q29 */ - sum = L_sub( sum, L_tmp ); /* Q29 */ - - return ( sum ); -} - - -/*==========================================================================*/ -/* FUNCTION : static void EstimateSHBGainShape_fx() */ -/*--------------------------------------------------------------------------*/ -/* PURPOSE : Estimate temporal gain parameters */ -/*--------------------------------------------------------------------------*/ -/* INPUT ARGUMENTS : */ -/* _(Word16) length : SHB overlap length Q0 */ -/* _(Word16*) oriSHB : target original SHB frame Q_oriSHB */ -/* _(Word16*) synSHB : shaped SHB excitation Q_synSHB */ -/* _(Word16*) subwin : SHB subframe window Q15 */ -/* _(Word16) Q_oriSHB : Q format of oriSHB */ -/* _(Word16) Q_synSHB : Q format of synSHB */ -/*--------------------------------------------------------------------------*/ -/* OUTPUT ARGUMENTS : */ -/* _(Word16*)subgain :estimate of gain shape Q15 */ -/*--------------------------------------------------------------------------*/ -/* INPUT/OUTPUT ARGUMENTS : */ -/* _None */ -/*--------------------------------------------------------------------------*/ -/* RETURN ARGUMENTS : */ -/* _ None */ -/*--------------------------------------------------------------------------*/ -static void EstimateSHBGainShape_fx( - const Word16 length, /* i : SHB overlap length */ - const Word16* oriSHB, /* i : target original SHB frame Q_oriSHB*/ - const Word16 Q_oriSHB, - const Word16* synSHB, /* i : shaped SHB excitation Q_synSHB*/ - const Word16 Q_synSHB, - Word16* subgain, /* o : estimate of gain shape Q15*/ - const Word16* subwin /* i : SHB subframe window Q15*/ - ,Word16* n_subfr_saturation /* o : Number of subframes which saturated while calculating oriNrg */ -) -{ - const Word16* skip; - Word16 i, j, k; - Word16 sig; - Word32 L_subgain[NUM_SHB_SUBFR]; - Word32 L_sum_gain = 0; - Word32 oriNrg, synNrg; - Word16 num_join, num_gains, join_length; - Word16 norm[NUM_SHB_SUBFR]; - Word16 n_max = -32768; - Word16 n; - Word16 length2 = shl(length, 1); - Word16 length_tmp; - Word32 L_tmp, normFact; - Word16 scaling = 0; - move16(); - num_join = NUM_SHB_SUBFR / NUM_SHB_SUBGAINS; - move16(); - num_gains = NUM_SHB_SUBGAINS; - move16(); - skip = skip_bands_SWB_TBE; - - IF( sub(length,SHB_OVERLAP_LEN / 2) == 0 ) - { - num_gains = NUM_SHB_SUBFR / 4; - move16(); - skip = skip_bands_WB_TBE; - move16(); - } - /* calculate and normalize the subgain */ - oriNrg = 0; - move16(); - synNrg = 0; - move16(); - - IF( sub(length,SHB_OVERLAP_LEN / 2) == 0 ) - { - FOR( i = 0; i < NUM_SHB_SUBFR / 2; i++ ) - { - logic16(); - IF( ( i & 0x1 ) == 0 ) - { - oriNrg = 0; - move16(); - synNrg = 0; - move16(); - } - j = skip[i]; - IF( i == 0 ) - { - FOR( k = 0; k < length / 2; k++ ) - { - sig = mult_r( oriSHB[j + k], subwin[2 * k + 2] ); /* Q_oriSHB */ - oriNrg = L_mac0( oriNrg, sig, sig ); /* 2* Q_oriSHB */ - sig = mult_r( synSHB[j + k], subwin[2 * k + 2] ); /* Q_synSHB */ - synNrg = L_mac0( synNrg, sig, sig ); /* 2* Q_synSHB */ - } - FOR( k = length / 2; k < length; k++ ) - { - sig = oriSHB[j + k]; - move16(); - oriNrg = L_mac0( oriNrg, sig, sig ); /* 2* Q_oriSHB */ - sig = synSHB[j + k]; - move16(); - synNrg = L_mac0( synNrg, sig, sig ); /* 2* Q_synSHB */ - } - } - ELSE - { - FOR( k = 0; k < length; k++ ) - { - sig = mult_r( oriSHB[j + k], subwin[k + 1] ); /* Q_oriSHB */ - oriNrg = L_mac0( oriNrg, sig, sig ); /* 2* Q_oriSHB */ - - sig = mult_r( synSHB[j + k], subwin[k + 1] ); /* Q_synSHB */ - synNrg = L_mac0( synNrg, sig, sig ); /* 2* Q_synSHB */ - - } - } - IF( i == NUM_SHB_SUBFR / 2 - 1 ) - { - length_tmp = sub(length2, shr(length, 1)); - FOR( ; k < length_tmp; k++ ) - { - sig = mult_r( oriSHB[j + k], subwin[3 * length - 2 * k - 2] ); /* Q_oriSHB */ - oriNrg = L_mac0( oriNrg, sig, sig ); /* 2* Q_oriSHB */ - - sig = mult_r( synSHB[j + k], subwin[3 * length - 2 * k - 2] ); /* Q_synSHB */ - synNrg = L_mac0( synNrg, sig, sig ); /* 2* Q_synSHB */ - } - } - ELSE - { - FOR(; k < length2; k++ ) - { - sig = mult_r( oriSHB[j + k], subwin[2 * length - k - 1] ); /* Q_oriSHB */ - oriNrg = L_mac0( oriNrg, sig, sig ); /* 2* Q_oriSHB */ - - sig = mult_r( synSHB[j + k], subwin[2 * length - k - 1] ); /* Q_synSHB */ - synNrg = L_mac0( synNrg, sig, sig ); /* 2* Q_synSHB */ - } - } - - logic16(); - IF( sub(( i & 0x1 ),1) == 0 ) - { - L_subgain[i / 2] = root_a_over_b_fx( oriNrg, 2 * Q_oriSHB, synNrg, 2 * Q_synSHB, &n ); - move16(); /* Q(31-n) */ - norm[i / 2] = n; - move16(); - IF( sub(norm[i / 2],n_max) > 0 ) - { - n_max = norm[i / 2]; - move16(); - } - } - } - } - ELSE - { - join_length = i_mult2( num_join, length ); - FOR( i = 0; i < num_gains; i++ ) - { - oriNrg = 0; - move16(); - synNrg = 0; - move16(); - - j = join_length * i; - move16(); - FOR( k = 0; k < length; k++ ) - { - sig = mult_r( oriSHB[j + k], subwin[k + 1] ); /* Q_oriSHB */ - oriNrg = L_mac0( oriNrg, sig, sig ); /* 2* Q_oriSHB */ - - sig = mult_r( synSHB[j + k], subwin[k + 1] ); /* Q_oriSHB */ - synNrg = L_mac0( synNrg, sig, sig ); /* 2* Q_oriSHB */ - } - - FOR( k = 0; k < ( join_length - length ); k++ ) - { - sig = mult_r( oriSHB[length + j + k], 32767 ); /* Q_oriSHB */ - oriNrg = L_mac0( oriNrg, sig, sig ); /* 2* Q_oriSHB */ - - sig = mult_r( synSHB[length + j + k], 32767 ); /* Q_oriSHB */ - synNrg = L_mac0( synNrg, sig, sig ); /* 2* Q_oriSHB */ - } - - FOR( k = 0; k < length; k++ ) - { - sig = mult_r( oriSHB[j + join_length + k], subwin[length - k - 1] ); /* Q_oriSHB */ - oriNrg = L_mac0( oriNrg, sig, sig ); /* 2* Q_oriSHB */ - - sig = mult_r( synSHB[j + join_length + k], subwin[length - k - 1] ); /* Q_oriSHB */ - synNrg = L_mac0( synNrg, sig, sig ); /* 2* Q_oriSHB */ - } - /* Only implemented in SWB because the length of samples in SWB frame is longer, more likely to saturate */ - scaling = 0; - move16(); - IF(L_sub(oriNrg, MAX_32) == 0) - { - if(n_subfr_saturation != NULL) - { - *n_subfr_saturation = add(*n_subfr_saturation, 1); - } - scaling = -1; - move16(); - oriNrg = 0; - move32(); - FOR( k = 0; k < length; k++ ) - { - sig = mult_r( oriSHB[j + k], subwin[k + 1] ); - oriNrg = L_mac0( oriNrg, sig, sig ); /* 2*Q_oriSHB - 2*/ - } - FOR( k = 0; k < ( join_length - length ); k++ ) - { - sig = shr(oriSHB[length + j + k], 1); - oriNrg = L_mac0( oriNrg, sig, sig ); /* 2*Q_oriSHB - 2*/ - } - FOR( k = 0; k < length; k++ ) - { - sig = mult_r( shr(oriSHB[j + join_length + k], 1), subwin[length - k - 1] ); /* Q_oriSHB - 1(scaling) */ - oriNrg = L_mac0( oriNrg, sig, sig ); /* 2*Q_oriSHB - 2 */ - } - } - L_subgain[i] = root_a_over_b_fx( oriNrg, 2 * Q_oriSHB, synNrg, 2 * Q_synSHB, &n ); - move32(); /* Q(31-n) */ - n = sub(n, scaling); - norm[i] = n; - move16(); - IF( sub(norm[i],n_max) > 0 ) - { - n_max = norm[i]; - move16(); - } - } - } - - FOR( i = 0; i < num_gains; i++ ) - { - subgain[i] = round_fx( L_shl( L_subgain[i], sub( norm[i], n_max + 1 ) ) ); /* Q(14-n_max) */ - L_sum_gain = L_mac0( L_sum_gain, subgain[i], subgain[i] ); /* Q(28-2*n_max) */ - } - - /* normalize the subgain */ - n = norm_l( L_sum_gain ); - L_sum_gain = L_shl( L_sum_gain, n ); - n = sub(31, add (n, (sub( 28 , n_max*2 ) ))); - normFact = Isqrt_lc( L_sum_gain, &n ); - - FOR( i = 0; i < num_gains; i++ ) - { - L_tmp = Mult_32_16( normFact, subgain[i] ); /*Q(31-n) * Q(31-norm[i]) */ /* Q(30-n-n_max) */ - subgain[i] = s_max( round_fx( L_shl( L_tmp, add( n, n_max + 1 ) ) ), 3277/*0.1f Q15*/); /* Q15 */ - } - - return; -} - - - -/*==========================================================================*/ -/* FUNCTION :static short closest_centroid_fx () */ -/*--------------------------------------------------------------------------*/ -/* PURPOSE : Determine a set of closest VQ centroids for a given input*/ -/*--------------------------------------------------------------------------*/ -/* INPUT ARGUMENTS : */ -/* _(Word16*) data : input data Q15 */ -/* _(Word16*) weights : weights Q0 */ -/* _(Word16*) quantizer : quantizer table Q15 */ -/* _(Word16) centroids : number of centroids Q0 */ -/* _(Word16) length : dimension of quantiser Q0 */ -/*--------------------------------------------------------------------------*/ -/* OUTPUT ARGUMENTS : */ -/* _None */ -/*--------------------------------------------------------------------------*/ -/* INPUT/OUTPUT ARGUMENTS : */ -/* _None */ -/*--------------------------------------------------------------------------*/ -/* RETURN ARGUMENTS : */ -/* _ Word16 : index Q0 */ -/*--------------------------------------------------------------------------*/ -static Word16 closest_centroid_fx( - const Word16* data, /* i : input data Qx*/ - const Word16* weights, /* i : weights */ - const Word16* quantizer, /* i : quantizer table Qx*/ - const Word16 centroids, /* i : number of centroids */ - const Word16 length ) /* i : dimension of quantiser */ -{ - Word16 i, j, index; - Word16 tmp, tmpL; - Word32 werr, best_werr; - Word32 L_tmp; - - index = 0; - move16(); - best_werr = L_add(MAX_32, 0); - - FOR( i = 0; i < centroids; i++ ) - { - werr = L_deposit_l(0); - tmpL = i_mult2(i, length); - FOR( j = 0; j < length; j++ ) - { - tmp = sub( data[j], quantizer[tmpL + j] ); - L_tmp = L_mult( tmp, tmp ); - werr = Madd_32_16( werr, L_tmp, weights[j] ); - } - if( L_sub( werr, best_werr ) < 0 ) - { - index = i; - move16(); - } - best_werr = L_min(best_werr, werr); - - } - - return index; -} - -/*==========================================================================*/ -/* FUNCTION :static short closest_centroid_lc_fx () */ -/*--------------------------------------------------------------------------*/ -/* PURPOSE : Determine a set of closest VQ centroids for a given input */ -/* Gain shape is 4 dimensional */ -/*--------------------------------------------------------------------------*/ -static Word16 closest_centroid_lc_fx( - const Word16 *data, /* i : input data Qx*/ - const Word16 *quantizer, /* i : quantizer table Qx*/ - const Word16 centroids) /* i : number of centroids */ -{ - Word16 i, index, tmp, tmpL; - Word32 werr, best_werr; - - index = 0; - move16(); - best_werr = MAX_32; - move32(); - - FOR( i = 0; i < centroids; i++ ) - { - /* Gain shape dimension 4 */ - tmpL = shl(i, 2); - - /* index 0 */ - tmp = sub( data[0], quantizer[tmpL] ); - werr = L_mult(tmp, tmp); - - /* index 1 */ - tmp = sub( data[1], quantizer[tmpL + 1] ); - werr = L_mac(werr, tmp, tmp); - - /* index 2 */ - tmp = sub( data[2], quantizer[tmpL + 2] ); - werr = L_mac(werr, tmp, tmp); - - /* index 3 */ - tmp = sub( data[3], quantizer[tmpL + 3] ); - werr = L_mac(werr, tmp, tmp); - - if( L_sub( werr, best_werr ) < 0 ) - { - index = i; - move16(); - } - best_werr = L_min(best_werr, werr); - } - - return index; -} - -/*============================================================*/ -/* FUNCTION : static void QuantizeSHBsubgains_fx() */ -/*------------------------------------------------------------*/ -/* PURPOSE : Quantize super highband temporal gains */ -/*------------------------------------------------------------*/ -/* INPUT ARGUMENTS : */ -/* _(Word16) extl : extension layer Q0 */ -/*------------------------------------------------------------*/ -/* OUTPUT ARGUMENTS : */ -/* _ None */ -/*------------------------------------------------------------*/ -/* INPUT/OUTPUT ARGUMENTS : */ -/* _(Word16[])subgains :super highband temporal gains Q15 */ -/*------------------------------------------------------------*/ -/* RETURN ARGUMENTS : */ -/* _ None */ -/*------------------------------------------------------------*/ - -static void QuantizeSHBsubgains_fx( - Encoder_State_fx *st_fx, /* i/o: encoder state structure */ - Word16 subgains[], /* i/o: super highband temporal gains Q15*/ - const Word16 extl /* i : extension layer */ -) -{ - Word16 i, idxSubGain; - Word16 Unit_weights10[NUM_SHB_SUBFR]; - Word16 exp, frac; - Word32 L_tmp; - - IF( sub(extl, WB_TBE) == 0 ) - { - set16_fx( Unit_weights10, 32767, ( Word16 )NUM_SHB_SUBFR / 4 ); - FOR( i = 0; i < NUM_SHB_SUBFR / 4; i++ ) - { - IF( subgains[i] == 0 ) - { - subgains[i + NUM_SHB_SUBFR / 4] = -18432; - move16(); /* (-72) in Q8 */ - } - ELSE - { - L_tmp = L_deposit_h( subgains[i] ); /* Q31 */ - exp = norm_l( L_tmp ); - frac = Log2_norm_lc( L_shl( L_tmp, exp ) ); /* move16(); */ - /*exp = -1 - exp; */ - exp = sub(-1, exp); - L_tmp = Mpy_32_16( exp, frac, 24660 );/* Q13 ; 20.0 * log10(2) in Q12*/ - subgains[i + NUM_SHB_SUBFR / 4] = round_fx( L_shl( L_tmp, 11 ) ); /* Q8 */ - } - } - idxSubGain = closest_centroid_lc_fx( subgains + NUM_SHB_SUBFR / 4, HBCB_SubGain5bit_fx, 1 << NUM_BITS_SHB_SUBGAINS ); - Copy( HBCB_SubGain5bit_fx + idxSubGain * NUM_SHB_SUBFR / 4, subgains, NUM_SHB_SUBFR / 4 ); - - push_indice_fx( st_fx, IND_SHB_SUBGAIN, idxSubGain, NUM_BITS_SHB_SUBGAINS ); - - FOR( i = 0; i < NUM_SHB_SUBFR / 4; i++ ) - { - L_tmp = L_mult( subgains[i], 21771 ); /* *0.166096 in Q17 -> Q26 */ - L_tmp = L_shr( L_tmp, 10 ); /* From Q26 to Q16 */ - frac = L_Extract_lc( L_tmp, &exp ); - subgains[i] = extract_l( Pow2( 14, frac ) ); - /* Put 14 as exponent so that */ - /* output of Pow2() will be: */ - /* 16384 < Pow2() <= 32767 */ - subgains[i] = shl( subgains[i], exp + 1 ); - move16();/*Q15 */ - } - - FOR( i = NUM_SHB_SUBFR / 2 - 1; i >= 0; i-- ) - { - subgains[i] = subgains[i / 2]; - move16(); - } - } - ELSE - { - FOR( i = 0; i < NUM_SHB_SUBGAINS; i++ ) - { - IF( subgains[i] == 0 ) - { - subgains[i] = -12288; - move16(); /* (-3) in Q12 */ - } - ELSE - { - L_tmp = L_deposit_h( subgains[i] ); /* Q31 */ - exp = norm_l( L_tmp ); - frac = Log2_norm_lc( L_shl( L_tmp, exp ) ); - /*exp = -1 - exp; */ - exp = sub(-1, exp); - - L_tmp = Mpy_32_16( exp, frac, 9864 ); /*move32(); // Q16 ; log10(2) in Q15 */ - subgains[i] = round_fx( L_shl( L_tmp, 12 ) ); /*Q12 */ - } - } - - idxSubGain = ( Word16 )vquant_fx( subgains, 0, subgains, SHBCB_SubGain5bit_12_fx, NUM_SHB_SUBGAINS, 1 << NUM_BITS_SHB_SUBGAINS ); - - FOR( i = 0; i < NUM_SHB_SUBGAINS; i++ ) - { - L_tmp = L_mult( subgains[i], 27213 ); /* *3.321928 in Q13 -> Q26 */ - L_tmp = L_shr( L_tmp, 10 ); /* From Q26 to Q16 */ - frac = L_Extract_lc( L_tmp, &exp ); - subgains[i] = extract_l( Pow2( 14, frac ) ); - /* Put 14 as exponent so that */ - /* output of Pow2() will be: */ - /* 16384 < Pow2() <= 32767 */ - subgains[i] = shl( subgains[i], exp + 1 ); - move16();/*Q15 */ - } - - FOR( i = NUM_SHB_SUBFR - 1; i >= 0; i-- ) - { - subgains[i] = subgains[i * NUM_SHB_SUBGAINS / NUM_SHB_SUBFR]; - move16(); - } - - st_fx->idxSubGains_fx = idxSubGain; - move16(); - IF( sub( st_fx->codec_mode, MODE2 ) != 0 ) - { - push_indice_fx( st_fx, IND_SHB_SUBGAIN, idxSubGain, NUM_BITS_SHB_SUBGAINS ); - } - } - - return; -} - - - -/*-------------------------------------------------------------------* - * Quant_shb_ener_sf_fx_fx() - * - * Quantize SHB subframe energies - *-------------------------------------------------------------------*/ - -static void Quant_shb_ener_sf_fx( - Encoder_State_fx *st_fx, /* i/o: encoder state structure */ - Word32 *shb_ener_sf_Q31, /* i/o: super highband subframe energies */ - Word16 Q_ener -) -{ - Word16 idxSubEner_fx; - Word16 temp_shb_ener_sf_fx; - Word16 exp/*, exp2*/,frac; - Word32 L_tmp1, L_tmp; - Word32 sum; - Word16 tmp; - - /* shb_ener_sf_fx[0] = log10(0.003125*shb_ener_sf[0:319]); */ - sum = *shb_ener_sf_Q31; /* L_tmp in Q_ener = (2*Q_shb+1) */ - - exp = norm_l(sum); - frac = Log2_norm_lc(L_shl(sum, exp)); - exp = sub(30, add(exp, Q_ener)); /* 30-(exp+Q_ener ) */ - L_tmp1 = Mpy_32_16(exp, frac, 617); /* 2466=LOG10(2) in Q11, so answer Ltmp in Q12 */ - - tmp = round_fx(L_shl(L_tmp1, 30-14)); /* tmp in Q12 */ - - temp_shb_ener_sf_fx = 0; - move16(); - idxSubEner_fx = usquant_fx(tmp, &temp_shb_ener_sf_fx, 0, 86, shl(1,NUM_BITS_SHB_ENER_SF)); /* 86 = 0.042f in Q11 = Qin-1 */ - /* o: temp_shb_ener_sf_fx in Q12 */ - - /* shb_ener_sf_fx[0] = pow(10.0, temp_shb_ener_sf_fx ); */ - /* = pow(2, 3.321928*temp_shb_ener_sf_fx) */ - L_tmp = L_mult(temp_shb_ener_sf_fx, 27213 ); /* 3.321928 in Q13 -> L_tmp in Q12+Q13+1 = Q26 */ - L_tmp = L_shl( L_tmp, -10 ); /* bring L_tmp from Q26 to Q16 */ - frac = L_Extract_lc( L_tmp, &exp ); /* Extract exponent */ - L_tmp = Pow2(14, frac ); - *shb_ener_sf_Q31 = L_shl(L_tmp, exp-14+Q_ener ); /* In Q_ener */ - - st_fx->idx_shb_fr_gain_fx = idxSubEner_fx; - move16(); - IF( sub( st_fx->codec_mode, MODE2 ) != 0 ) - { - push_indice_fx( st_fx, IND_SHB_ENER_SF, idxSubEner_fx, NUM_BITS_SHB_ENER_SF); - } - return; -} - - -/*-------------------------------------------------------------------* -* Quant_shb_res_gshape_fx() -* -* Quantize SHB gain shapes in residual domain -*-------------------------------------------------------------------*/ - -static void Quant_shb_res_gshape_fx( - Encoder_State_fx *st_fx, /* i/o: encoder state structure */ - Word16 shb_res_gshape_fx[] /* i/o: super highband gain shapes Q14 */ -) -{ - Word16 i, idxSubGain_fx[NB_SUBFR16k]; - - FOR(i = 0; i < NB_SUBFR16k; i++) - { - idxSubGain_fx[i] = usquant_fx(shb_res_gshape_fx[i], - &shb_res_gshape_fx[i], - 2048/*0.125f Q14*/, /*2048 = 0.125 in Q14 */ - 1024/*0.125f Q13*/, /*1024 = 0.125 in Q13 */ - shl(1,NUM_BITS_SHB_RES_GS)); - - st_fx->idx_res_gs_fx[i] = idxSubGain_fx[i]; - IF ( sub( st_fx->codec_mode, MODE2 ) != 0 ) - { - push_indice_fx( st_fx, IND_SHB_RES_GS1+i, idxSubGain_fx[i], NUM_BITS_SHB_RES_GS); - } - } -} - -/*==========================================================================*/ -/* FUNCTION : static void QuantizeSHBframegain_fx() */ -/*--------------------------------------------------------------------------*/ -/* PURPOSE : QQuantize super highband frame gain */ -/*--------------------------------------------------------------------------*/ -/* INPUT ARGUMENTS : */ -/* Word16 extl i : extension layer */ -/* Word32 extl_brate i : extension layer bitrate */ -/*--------------------------------------------------------------------------*/ -/* OUTPUT ARGUMENTS : */ -/*--------------------------------------------------------------------------*/ -/* INPUT/OUTPUT ARGUMENTS : */ -/* Word32 *GainFrame i/o: Gain Q18 */ -/*--------------------------------------------------------------------------*/ -/* RETURN ARGUMENTS : */ -/* _ None */ -/*--------------------------------------------------------------------------*/ -/* */ -/*==========================================================================*/ -static void QuantizeSHBframegain_fx( - Encoder_State_fx* st_fx, /* i/o: encoder state structure */ - Word32* GainFrame, /* i/o: Gain Q18 */ - const Word16 extl, /* i : extension layer */ - Word32 extl_brate /* i : extension layer bitrate */ - ,Word16 *rf_gainFrame_ind -) -{ - Word16 idxFrameGain; - Word32 Q_GainFrame; - Word16 Unit_weights1 = 1; - Word16 exp, frac, tmp; - Word32 L_tmp; - Word32 GainFrameLog; - - IF( sub(extl, WB_TBE) == 0 ) - { - determine_gain_weights_fx( GainFrame, &( Unit_weights1 ), 1 ); - IF( L_sub(extl_brate,WB_TBE_0k35) == 0 ) - { - singlevectortest_gain_fx( GainFrame, 1, - 1 << NUM_BITS_SHB_FrameGain_LBR_WB, &idxFrameGain, - &Q_GainFrame, SHBCB_FrameGain16_fx ); - test(); - IF( L_sub( Q_GainFrame, L_shl( Mult_32_16( *GainFrame, 17367 ), 1 ) ) > 0 && idxFrameGain > 0 ) /* 1.06 = +0.5 dB */ - { - idxFrameGain--; - Q_GainFrame = L_add(SHBCB_FrameGain16_fx[idxFrameGain], 0); /* Q18 */ - } - st_fx->gFrame_WB_fx = idxFrameGain; - move16(); - *rf_gainFrame_ind = idxFrameGain; - } - ELSE - { - singlevectortest_gain_fx( GainFrame, 1, - 1 << NUM_BITS_SHB_FrameGain, &idxFrameGain, &Q_GainFrame, - SHBCB_FrameGain64_fx ); - - push_indice_fx( st_fx, IND_SHB_FRAMEGAIN, idxFrameGain, NUM_BITS_SHB_FrameGain ); - *rf_gainFrame_ind = idxFrameGain; - move16(); /* Q18 */ - } - } - ELSE - { - IF( *GainFrame == 0 ) - { - GainFrameLog = -196608; - move32(); - } - ELSE - { - exp = norm_l( *GainFrame ); - frac = Log2_norm_lc( L_shl( *GainFrame, exp ) ); - exp = ( 30 - exp - 18 ); - GainFrameLog = Mpy_32_16( exp, frac, 9864 ); - /*GainFrameLog= round_fx(L_shl(L_tmp,12)); //Q12 */ - } - - exp = norm_s( SHB_GAIN_QDELTA_FX_15 ); - tmp = div_s( shl(1, sub(14, exp)), SHB_GAIN_QDELTA_FX_15 ); - L_tmp = Mult_32_16( L_sub( GainFrameLog, SHB_GAIN_QLOW_FX_16 ), tmp ); - idxFrameGain = extract_l( L_shr( L_add( L_tmp, shl(1, sub(14, exp)) ), sub(15, exp) ) ); /*Q0*/ - IF( sub( idxFrameGain, ( 1 << NUM_BITS_SHB_FRAMEGAIN ) - 1 ) > 0 ) - { - idxFrameGain = sub( ( 1 << NUM_BITS_SHB_FRAMEGAIN ), 1 ); - } - ELSE - { - if( idxFrameGain < 0 ) - { - idxFrameGain = 0; - move16(); - } - } - - L_tmp = SHB_GAIN_QLOW_FX_16; - Q_GainFrame = L_mac( L_tmp, idxFrameGain, SHB_GAIN_QDELTA_FX_15 ); - - WHILE( L_sub( Q_GainFrame, L_add( GainFrameLog, 4866 ) ) > 0 && - idxFrameGain != 0 ) - { - idxFrameGain = sub(idxFrameGain, 1); - Q_GainFrame = L_mac0( SHB_GAIN_QLOW_FX_16, idxFrameGain, SHB_GAIN_QDELTA_FX_16 ); - } - - /* Q_GainFrame = (float) pow(10.0, Q_GainFrame ); */ - /* i: Q_GainFrame in Q16 */ - L_tmp = Mult_32_16( Q_GainFrame, 27213 ); /* *3.321928 in Q13 -> Q25 */ - L_tmp = L_shr( L_tmp, -2 ); /* From Q26 to Q16 */ - frac = L_Extract_lc( L_tmp, &exp ); - Q_GainFrame = Pow2( 30, frac ); - exp = sub ( exp, 30) ; - Q_GainFrame = L_shl( Q_GainFrame, exp + 18 ); /* Q18 */ - - st_fx->idxFrameGain_fx = idxFrameGain; - move16(); - IF ( sub( st_fx->codec_mode, MODE2 ) != 0 ) - { - push_indice_fx( st_fx, IND_SHB_FRAMEGAIN, idxFrameGain, NUM_BITS_SHB_FRAMEGAIN ); - } - *rf_gainFrame_ind = idxFrameGain; - } - - IF( sub(st_fx->rf_mode,1)==0) - { - /*Currently intended for SWB only. Modify for WB is needed later!*/ - IF( sub(st_fx->rf_frame_type,RF_NELP) == 0) - { - *rf_gainFrame_ind = idxFrameGain; /* NELP Frame uses full 5 bits */ - } - ELSE /*RF_ALLPRED, RF_GENPRED, RF_NOPRED modes*/ - { - IF( *GainFrame <= 327680 /*1.25 in Q18*/ ) /* [0 to 1.25] range --> 0.5*/ - *rf_gainFrame_ind = 0; - ELSE IF ( *GainFrame <= 786432 /*3 in Q18*/ ) /* (1.25 to 3] --> 2 */ - *rf_gainFrame_ind = 1; - ELSE IF ( *GainFrame <= 1572864 /*6 in Q18*/ ) /* (3 to 6] --> 4 */ - *rf_gainFrame_ind = 2; - ELSE /* (6 to Inf) --> 8 */ - *rf_gainFrame_ind = 3; - } - } - - *GainFrame = Q_GainFrame; - move32(); /* Q18 */ - - return; -} - - -/*============================================================*/ -/* FUNCTION : static void determine_gain_weights_fx() */ -/*------------------------------------------------------------*/ -/* PURPOSE : Determine weights for gain quantization */ -/*------------------------------------------------------------*/ -/* INPUT ARGUMENTS : */ -/* _(Word32*)gain :Gain parameter Q18 */ -/* _(Word16) dims : number of gains */ -/*------------------------------------------------------------*/ -/* OUTPUT ARGUMENTS : */ -/* _(Word16*)weights : gain weights Q12/Q6 */ -/*------------------------------------------------------------*/ -/* INPUT/OUTPUT ARGUMENTS : */ -/* _ None */ -/*------------------------------------------------------------*/ -/* RETURN ARGUMENTS : */ -/* _ None */ -/*------------------------------------------------------------*/ -static void determine_gain_weights_fx ( - const Word32* gain, /* i : Gain parameter Q18 */ - Word16* weights, /* o : gain weights Q12/Q6*/ - const Word16 dims /* i : number of gains */ ) -{ - Word16 j; - Word16 exp, exp1, frac, tmp, exp2; - Word32 L_tmp; - - FOR( j = 0; j < dims; j++ ) - { - IF( L_sub(gain[j],8) > 0 )/* 8 = 0.001 in Q13 */ - { - /*weights[j] = (float)(pow (fabs (gain[j]), -0.9f)); = pow(2,(-0.9)*log2(gain[j])) */ - exp1 = norm_l( gain[j] ); - frac = Log2_norm_lc( L_shl( gain[j], exp1 ) ); - move16(); - exp = 30 - exp1 - 18; - move16(); - L_tmp = Mpy_32_16( exp, frac, -29491 ); /* Q16 */ - frac = L_Extract_lc( L_tmp, &exp ); - tmp = extract_l( Pow2( 14, frac ) ); /* Q14 */ - - exp2 = sub(exp,8); - if( sub(exp1,21) <= 0 ) - { - exp2 = sub(exp,2); - } - weights[j] = shl( tmp, exp2); - move16(); /* Q12 */ - } - ELSE - { - weights[j] = 32076; - move16();/* (501.187233628f) in Q6*/ - } - } - - return; -} - - - - -/*==============================================================================*/ -/* FUNCTION : static singlevectortest_gain_fx () */ -/*------------------------------------------------------------------------------*/ -/* PURPOSE : Single stage VQ for coding */ -/*------------------------------------------------------------------------------*/ -/* INPUT ARGUMENTS : */ -/* _(Word32*) inp : input gain vector Q18 */ -/* _(Word16) dimen : dimension of the input vector */ -/* _(Word16) cb_size : codebook size */ -/* _(Word16*) weight : Weights for the quanitzation */ -/* _(Word32*) codebook : Codebook 19Q13 */ -/*------------------------------------------------------------------------------*/ -/* OUTPUT ARGUMENTS : */ -/* _(Word16*)index :quanitzation index */ -/* _(Word32*)recon :Reconstruction 19Q13 */ -/*------------------------------------------------------------------------------*/ -/* INPUT/OUTPUT ARGUMENTS : */ -/* _None */ -/*------------------------------------------------------------------------------*/ -/* RETURN ARGUMENTS : */ -/* _ None */ -/*------------------------------------------------------------------------------*/ -static void singlevectortest_gain_fx ( - const Word32* inp, /* i : input gain vector Q18*/ - const Word16 dimen, /* i : dimension of the input vector */ - const Word16 cb_size, /* i : codebook size */ - Word16* index, /* o : quanitzation index */ - Word32* recon, /* o : Reconstruction Q18 */ - const Word32* codebook - /* i : Codebook Q18*/ ) -{ - Word16 k, interNum, flag; - Word32 meanU, meanQ; - Word16 least[4]; - Word32 L_tmp; - - interNum = 4; - move16(); - - return_M_Least_fx_GainFrame( inp, codebook, cb_size, interNum, least ); - - meanU = sum32_fx( inp, dimen ); /* Q18 */ - Copy32( codebook + dimen * least[0], recon, dimen ); - - L_tmp = L_shl( Mult_32_16( meanU, 18022 ), 1 ); /* Q18 */ - index[0] = least[0]; - move16(); - flag = 0; - move16(); - FOR( k = 0; k < interNum; k++ ) - { - IF( flag == 0 ) - { - meanQ = sum32_fx( codebook + dimen * least[k], dimen ); /* Q18 */ - IF( L_sub( meanQ, L_tmp ) <= 0 ) - { - flag = 1; - move16(); - Copy32( codebook + dimen * least[k], recon, dimen ); - index[0] = least[k]; - move16(); - } - } - } - - return; -} - - - - -/*==============================================================================*/ -/* FUNCTION : return_M_Least_fx_GainFrame () */ -/*------------------------------------------------------------------------------*/ -/* PURPOSE : */ -/*------------------------------------------------------------------------------*/ -/* INPUT ARGUMENTS : */ -/* _(Word32*) inp : input Q18 */ -/* _(Word16*) weight : input gain weights */ -/* _(Word16) n_cols : vector size */ -/* _(Word16) num_grp : number of centroids for 1st stage */ -/* _(Word16) interNum : number on short list prior to 2nd stage search */ -/* _(Word32*) codebook : first stage codebook Q18 */ -/*------------------------------------------------------------------------------*/ -/* OUTPUT ARGUMENTS : */ -/* _(Word16*)least :return value */ -/*------------------------------------------------------------------------------*/ -/* INPUT/OUTPUT ARGUMENTS : */ -/* _None */ -/*------------------------------------------------------------------------------*/ -/* RETURN ARGUMENTS : */ -/* _ None */ -/*------------------------------------------------------------------------------*/ -static void return_M_Least_fx_GainFrame( - const Word32* inp, /* i: input Q18*/ - const Word32* codebook, /* i: codebook Q18*/ - const Word16 num_grp, /* i: number of centroids */ - const Word16 interNum, /* i: number on short list prior to 2nd stage search*/ - Word16* least /* o: return value */ ) -{ - Word16 i, k; - Word32 distance[1024], mindist; - - Word16 n; - Word32 diff[1024]; - Word32 max_diff; - mindist = L_add(MAX_32, 0); - - diff[0] = L_sub( *inp, codebook[0] ); - move32(); - max_diff = L_abs( diff[0] ); - FOR( i = 1; i < num_grp; i++ ) - { - diff[i] = L_sub( *inp, codebook[i] ); - move32(); - max_diff = L_max(max_diff , L_abs( diff[i] )); - } - n = 31; - if( max_diff != 0 ) - { - n = norm_l(max_diff); - } - - FOR( i = 0; i < num_grp; i++ ) - { - diff[i] = L_shl( diff[i], n ); - move32(); - } - - FOR( i = 0; i < num_grp; i++ ) - { - distance[i] = L_deposit_l(0); - distance[i] = Mult_32_32( diff[i], diff[i] ); - move32(); - - if( L_sub( distance[i], mindist ) < 0 ) - { - least[0] = i; - move16(); - } - mindist = L_min(mindist,distance[i]); - } - - distance[least[0]] = MAX_32; - move32(); - - FOR( k = 1; k < interNum; k++ ) - { - mindist = L_add(MAX_32, 0); - FOR( i = 0; i < num_grp; i++ ) - { - if( L_sub( distance[i], mindist ) < 0 ) - { - least[k] = i; - move16(); - } - mindist = L_min(mindist,distance[i]); - } - - distance[least[k]] = MAX_32; - move32(); - } - - return; -} - - -/*-------------------------------------------------------------------* -* Quant_lower_LSF_fx() -*-------------------------------------------------------------------*/ -static void Quant_lower_LSF_fx( - const Word16 lsf[], /* i : Input LSFs Q15 */ - Word16 lsf_q[], /* o : Quantized LSFs Q15 */ - Word16 lsf_idx[] /* o : Quantized LSFs indices */ -) -{ - Word16 i; - - lsf_idx[0] = ( Word16 )squant_fx( lsf[0], &lsf_q[0], lsf_q_cb_fx[0], lsf_q_cb_size_fx[0] ); - FOR( i = 1; i < NUM_Q_LSF; i++ ) - { - lsf_idx[i] = ( Word16 )squant_fx( sub( lsf[i], lsf_q[i - 1] ), &lsf_q[i], lsf_q_cb_fx[i], lsf_q_cb_size_fx[i] ); - move16(); - lsf_q[i] = add( lsf_q[i - 1], lsf_q[i] ); - move16(); - } - - return; -} - - -/*-------------------------------------------------------------------* -* Quant_mirror_point_fx() -*-------------------------------------------------------------------*/ -static Word16 Quant_mirror_point_fx( - const Word16 lsf[], /* i : Input LSFs */ - const Word16 lsf_q[], - Word16* m /* o : Mirror point */ -) -{ - Word16 m_diff; - Word16 m_idx; - - m_diff = mult_r( sub( lsf[NUM_Q_LSF], lsf_q[NUM_Q_LSF - 1] ), 16384 ); - - m_idx = ( Word16 )squant_fx( m_diff, m, mirror_point_q_cb_fx, - MIRROR_POINT_Q_CB_SIZE ); /*move16(); */ - - *m = add( lsf_q[NUM_Q_LSF - 1], *m ); - move16(); - - return m_idx; -} - -/*-------------------------------------------------------------------* -* Find_LSF_grid() -* -* Find the best grid for the LSFs -*-------------------------------------------------------------------*/ - -static Word16 Find_LSF_grid_fx( - const Word16 lsf[], /* i : Input LSFs */ - Word16 lsf_q[], /* o : Quantized LSFs */ - const Word16 m /* i : Mirror point */ -) -{ - Word16 lsf_map[NUM_MAP_LSF]; - Word16 grid[NUM_LSF_GRIDS][NUM_MAP_LSF]; - Word16 offset; - Word16 last_q_lsf; - Word16 lsf_t[NUM_MAP_LSF]; - Word16 lsf_smooth[NUM_MAP_LSF]; - Word32 D, D_best; - Word16 I_best = 0; - Word16 i, j; - Word16 scale; - - Word16 tmp, exp, tmp1; - Word32 L_tmp; - - - tmp = shl(m, 1); - lsf_map[0] = sub( tmp, lsf_q[NUM_MAP_LSF-1-0] ); - move16(); - lsf_map[1] = sub( tmp, lsf_q[NUM_MAP_LSF-1-1] ); - move16(); - lsf_map[2] = sub( tmp, lsf_q[NUM_MAP_LSF-1-2] ); - move16(); - lsf_map[3] = sub( tmp, lsf_q[NUM_MAP_LSF-1-3] ); - move16(); - lsf_map[4] = sub( tmp, lsf_q[NUM_MAP_LSF-1-4] ); - move16(); - - - IF( sub( m, MAX_LSF_FX_2 ) > 0 ) - { - offset = lsf_map[0]; - move16(); - exp = norm_s( m ); - tmp = div_s( shl(1, sub(14, exp)), m ); - L_tmp = L_mult( sub( MAX_LSF_FX, m ), tmp ); - scale = round_fx( L_shl( L_tmp, exp + 1 ) ); - - FOR( i = 0; i < NUM_MAP_LSF; i++ ) - { - tmp = mult_r( sub( lsf_map[i], offset ), scale ); - lsf_map[i] = add( tmp, offset ); - move16(); - } - } - - last_q_lsf = lsf_q[NUM_Q_LSF - 1]; - move16(); - scale = sub( MAX_LSF_FX, last_q_lsf ); - - FOR( i = 0; i < NUM_LSF_GRIDS; i++ ) - { - FOR( j = 0; j < NUM_MAP_LSF; j++ ) - { - grid[i][j] = add( mult_r( lsf_grid_fx[i][j], scale ), last_q_lsf ); - move16(); - } - } - - D_best = L_add(MAX_32, 0); - FOR( i = 0; i < NUM_LSF_GRIDS; i++ ) - { - D = L_deposit_l(0); - FOR( j = 0; j < NUM_MAP_LSF; j++ ) - { - /*lsf_t[j] = (1 - grid_smoothing[j])*lsf_map[j] + grid_smoothing[j]*grid[i][j]; */ - tmp = sub( 32767, grid_smoothing_fx[j] ); - tmp = mult_r( tmp, lsf_map[j] ); - tmp1 = mult_r( grid_smoothing_fx[j], grid[i][j] ); - lsf_t[j] = add( tmp, tmp1 ); - move16(); - - tmp = sub( lsf_t[j], lsf[NUM_Q_LSF + j] ); - D = L_mac0( D, tmp, tmp ); - - /* D += (lsf_t[j] - lsf[NUM_Q_LSF + j])*(lsf_t[j] - lsf[NUM_Q_LSF + j]); */ - } - IF( L_sub( D, D_best ) < 0 ) - { - Copy( lsf_t, lsf_smooth, NUM_MAP_LSF ); - D_best = L_add(D, 0); - I_best = i; - move16(); - } - } - - FOR( i = 0; i < NUM_MAP_LSF; i++ ) - { - lsf_q[NUM_Q_LSF + i] = lsf_smooth[i]; - move16(); - } - - return I_best; -} - -/*-------------------------------------------------------------------* -* gainFrSmooth_En_fx() -* -* Gain frame smoothing and attenuation control -*-------------------------------------------------------------------*/ -static void gainFrSmooth_En_fx(Encoder_State_fx *st_fx, - Word16 *shb_frame_fx, - const Word16 *lpc_shb_fx, - const Word16 *lsp_shb_fx, - Word16 *MA_lsp_shb_spacing, - Word16 *frGainAttenuate, - Word16 *frGainSmoothEn - ) -{ - Word16 temp_shb_frame[L_FRAME16k+L_SHB_LAHEAD]; - Word32 lsp_slow_evol_rate, lsp_fast_evol_rate; - Word16 lsp_spacing; - - Word32 tempQ31; - Word16 tempQ15_1, tempQ15_2; - Word16 i; - - /* inits */ - *frGainAttenuate = 0; - move16(); - *frGainSmoothEn = 0; - move16(); - *MA_lsp_shb_spacing = 16384; - move16(); - lsp_spacing = lsp_shb_fx[0]; - move16(); - - /* estimate the mean square error in lsps from current frame to past frames */ - tempQ15_1 = sub( lsp_shb_fx[0], st_fx->lsp_shb_slow_interpl_fx[0] ); - tempQ15_2 = sub( lsp_shb_fx[0], st_fx->lsp_shb_fast_interpl_fx[0] ); - lsp_slow_evol_rate = L_mult(tempQ15_1, tempQ15_1 ); - lsp_fast_evol_rate = L_mult(tempQ15_2, tempQ15_2 ); - - /* update the slow and fast lsp interp for next frame */ - tempQ31 = L_mult(st_fx->lsp_shb_slow_interpl_fx[0], 22937 ); - st_fx->lsp_shb_slow_interpl_fx[0] = mac_r(tempQ31, lsp_shb_fx[0], 9830 ); - move16(); - tempQ31 = L_mult(st_fx->lsp_shb_fast_interpl_fx[0], 9830 ); - st_fx->lsp_shb_fast_interpl_fx[0] = mac_r(tempQ31, lsp_shb_fx[0], 22937 ); - move16(); - - FOR( i = 1; i < LPC_SHB_ORDER; i++ ) - { - tempQ15_1 = sub(lsp_shb_fx[i], lsp_shb_fx[i-1]); - lsp_spacing = s_min( lsp_spacing, tempQ15_1); - - /* estimate the mean square error in lsps from current frame to past frames */ - tempQ15_1 = sub( lsp_shb_fx[i], st_fx->lsp_shb_slow_interpl_fx[i] ); - tempQ15_2 = sub( lsp_shb_fx[i], st_fx->lsp_shb_fast_interpl_fx[i] ); - lsp_slow_evol_rate = L_mac(lsp_slow_evol_rate, tempQ15_1, tempQ15_1 ); - lsp_fast_evol_rate = L_mac(lsp_fast_evol_rate , tempQ15_2, tempQ15_2 ); - - /* update the slow and fast interpolation lsps for next frame */ - tempQ31 = L_mult(st_fx->lsp_shb_slow_interpl_fx[i], 22937 ); - st_fx->lsp_shb_slow_interpl_fx[i] = mac_r(tempQ31, lsp_shb_fx[i], 9830 ); - move16(); - tempQ31 = L_mult(st_fx->lsp_shb_fast_interpl_fx[i], 9830 ); - st_fx->lsp_shb_fast_interpl_fx[i] = mac_r(tempQ31, lsp_shb_fx[i], 22937 ); - move16(); - } - - test(); - test(); - IF( sub( st_fx->last_extl_fx, SWB_TBE ) != 0 - && sub(st_fx->last_extl_fx, FB_TBE) != 0 - && sub( lsp_spacing, 262 ) < 0 ) - { - st_fx->lsp_shb_spacing_fx[0] = lsp_spacing; - move16(); - st_fx->lsp_shb_spacing_fx[1] = lsp_spacing; - move16(); - st_fx->lsp_shb_spacing_fx[2] = lsp_spacing; - move16(); - st_fx->prev_frGainAtten_fx = 1; - move16(); - set16_fx(st_fx->shb_inv_filt_mem_fx, 0, LPC_SHB_ORDER); - } - - /* Estimate the moving average LSP spacing */ - tempQ31 = L_mult(st_fx->lsp_shb_spacing_fx[0], 3277); /* 0.1f */ - tempQ31 = L_mac(tempQ31, st_fx->lsp_shb_spacing_fx[1], 6553); /* 0.2f */ - tempQ31 = L_mac(tempQ31, st_fx->lsp_shb_spacing_fx[2], 9830); /* 0.3f */ - *MA_lsp_shb_spacing = mac_r(tempQ31, lsp_spacing, 13107); /* 0.4f */ - - st_fx->lsp_shb_spacing_fx[0] = st_fx->lsp_shb_spacing_fx[1]; - move16(); - st_fx->lsp_shb_spacing_fx[1] = st_fx->lsp_shb_spacing_fx[2]; - move16(); - st_fx->lsp_shb_spacing_fx[2] = lsp_spacing; - move16(); - - test(); - test(); - test(); - IF( ( sub( lsp_spacing, 262 ) < 0 && ( sub( *MA_lsp_shb_spacing, 164 ) < 0 || sub(st_fx->prev_frGainAtten_fx, 1) == 0 ) ) - || sub( lsp_spacing, 105 ) <= 0 ) - { - *frGainAttenuate = 1; - move16(); - - IF( L_sub(st_fx->total_brate_fx , ACELP_24k40) != 0 ) - { - Copy( shb_frame_fx, temp_shb_frame, L_FRAME16k + L_SHB_LAHEAD ); - fir_fx( temp_shb_frame, lpc_shb_fx, shb_frame_fx, st_fx->shb_inv_filt_mem_fx, L_FRAME16k + L_SHB_LAHEAD, LPC_SHB_ORDER, 1,3); - } - ELSE - { - set16_fx(st_fx->shb_inv_filt_mem_fx, 0, LPC_SHB_ORDER); - } - - test(); - IF ( L_sub( lsp_slow_evol_rate, 2147484l/*0.001f Q31*/ ) < 0 && L_sub( lsp_fast_evol_rate, 2147484l/*0.001f Q31*/ ) < 0 ) - { - *frGainSmoothEn = 1; - move16(); - } - } - -} - -/*-------------------------------------------------------------------* -* Quant_BWE_LSF() -* -* Quantize super highband spectral envolope -*-------------------------------------------------------------------*/ - -static void Quant_BWE_LSF_fx( - - Encoder_State_fx* st_fx, /* i/o: encoder state structure */ - const Word16 lsf_shb[], /* i : unquanitzed LSFs */ - Word16 Q_lsfs[] /* o : quanitzed LSFs */ -) -{ - Word16 lsf[LPC_SHB_ORDER]; - Word16 lsf_q[LPC_SHB_ORDER]; - Word16 lsf_idx[NUM_Q_LSF]; - Word16 i; - Word16 m_idx; - Word16 m; - Word16 grid_idx; - - FOR( i = 0; i < LPC_SHB_ORDER; i++ ) - { - lsf[i] = sub( 16384, lsf_shb[LPC_SHB_ORDER - 1 - i] ); - move16(); - } - - Quant_lower_LSF_fx( lsf, lsf_q, lsf_idx); - /* i: lsf in Q15 */ - /* o: lsf_q in Q15 */ - - FOR( i = 0; i < NUM_Q_LSF; i++ ) - { - st_fx->lsf_idx_fx[i] = lsf_idx[i]; - move16(); - IF( sub( st_fx->codec_mode, MODE2 ) != 0 ) - { - push_indice_fx( st_fx, IND_SHB_LSF, lsf_idx[i], lsf_q_num_bits[i] ); - } - } - - m_idx = Quant_mirror_point_fx( lsf, lsf_q, &m ); - - st_fx->m_idx_fx = m_idx; - move16(); - IF( sub( st_fx->codec_mode, MODE2 ) != 0 ) - { - push_indice_fx( st_fx, IND_SHB_MIRROR, m_idx, MIRROR_POINT_BITS ); - } - - grid_idx = Find_LSF_grid_fx( lsf, lsf_q, m ); - - st_fx->grid_idx_fx = grid_idx; - IF( sub( st_fx->codec_mode, MODE2 ) != 0 ) - { - push_indice_fx( st_fx, IND_SHB_GRID, grid_idx, NUM_LSF_GRID_BITS ); - } - - FOR( i = 0; i < LPC_SHB_ORDER; i++ ) - { - Q_lsfs[i] = sub( 16384, lsf_q[LPC_SHB_ORDER - 1 - i] ); - move16(); - } - - return; -} - -/*-------------------------------------------------------------------* - * fb_tbe_enc() - * - * FB TBE encoder, 14(resp. 15.5) - 20 kHz band encoding module - *-------------------------------------------------------------------*/ - -void fb_tbe_enc_fx( - Encoder_State_fx *st, /* i/o: encoder state structure */ - const Word16 new_input[], /* i : input speech at 48 kHz sample rate */ - const Word16 fb_exc[], /* i : FB excitation from the SWB part */ - Word16 Q_fb_exc -) -{ - Word16 ratio; - Word16 tmp_vec[L_FRAME48k]; - Word16 idxGain; - Word16 input_fhb[L_FRAME48k]; - Word16 Sample_Delay_HP; - Word32 fb_exc_energy, temp2; - Word32 L_tmp; - Word16 tmp,tmp1,tmp2,exp,exp2,exp_norm; - Word16 s_max_value,exp_temp,i; - - s_max_value = 0; - FOR( i = 0; i < L_FRAME48k; i++ ) - { - s_max_value = s_max(s_max_value,abs_s(new_input[i])); - } - exp_temp = norm_s( s_max_value ); - if( s_max_value == 0 ) - { - exp_temp = 15; - } - exp_temp = sub(exp_temp,1); - - Copy_Scale_sig( new_input, input_fhb, L_FRAME48k, exp_temp ); - - elliptic_bpf_48k_generic_fx( input_fhb, &exp_temp , tmp_vec, st->elliptic_bpf_2_48k_mem_fx, st->elliptic_bpf_2_48k_mem_fx_Q,full_band_bpf_2_fx ); - Sample_Delay_HP = NS2SA(48000, ACELP_LOOK_NS + DELAY_FD_BWE_ENC_12k8_NS + DELAY_FIR_RESAMPL_NS) - L_FRAME48k/2 ; - - IF( sub(st->last_extl_fx,FB_TBE) != 0 ) - { - set16_fx( st->old_input_fhb_fx, 0, Sample_Delay_HP ); - st->old_input_fhb_fx_Q = 0; - move16(); - set16_fx( tmp_vec, 0, L_FRAME16k ); - } - Copy_Scale_sig( st->old_input_fhb_fx, st->old_input_fhb_fx, Sample_Delay_HP, sub(exp_temp,st->old_input_fhb_fx_Q) ); - st->old_input_fhb_fx_Q = exp_temp; - Copy( st->old_input_fhb_fx, input_fhb, Sample_Delay_HP ); - Copy( tmp_vec, input_fhb + Sample_Delay_HP, L_FRAME48k-Sample_Delay_HP ); - Copy( tmp_vec + L_FRAME48k - Sample_Delay_HP, st->old_input_fhb_fx, Sample_Delay_HP ); - temp2 = sum2_fx_mod( input_fhb, L_FRAME48k/2 );/* Q11 */ - temp2 = L_add(temp2,L_shl(st->prev_fb_energy_fx,sub(sub(add(exp_temp,exp_temp),6),st->prev_fb_energy_fx_Q)));/* Q11 */ - st->prev_fb_energy_fx = sum2_fx_mod( input_fhb + L_FRAME48k/2, L_FRAME48k/2 );/*Q11*/ - st->prev_fb_energy_fx_Q = sub(add(exp_temp,exp_temp),6); - fb_exc_energy = sum2_fx_mod( fb_exc, L_FRAME16k );/* Q(2*Q_fb_exc+1 -7) */ - - /*ratio = (float) sqrt( temp2 / fb_exc_energy );*/ - L_tmp = L_max(1, temp2); /*Q6*/ - exp = norm_l(L_tmp); - tmp = extract_h(L_shl(L_tmp, exp)); - exp = sub(sub(31,sub(add(exp_temp,exp_temp),8)), exp); /* in Q15 (L_tmp in Q6)*/ - - exp2 = norm_l(fb_exc_energy); - tmp2 = extract_h(L_shl(fb_exc_energy, exp2)); - tmp1 = sub(add(Q_fb_exc,Q_fb_exc), 8);/*1 - 9*/ - exp2 = sub(sub(31,tmp1), exp2); /* in Q15 (L_tmp in Q6)*/ - - exp = sub(exp2, exp); /* Denormalize and substract */ - IF (sub(tmp2, tmp) > 0) - { - tmp2 = shr(tmp2, 1); - exp = add(exp, 1); - } - IF( 0 != tmp ) - { - tmp = div_s(tmp2, tmp); - L_tmp = L_deposit_h(tmp); - L_tmp = Isqrt_lc(L_tmp, &exp); /*Q(31-exp)*/ - L_tmp = L_max(L_shr(L_tmp,sub(31,exp)),0x1);/* Q0 */ - } - ELSE - { - L_tmp =0; - } - - /* idxGain = (short)( log2_f ((float)ratio) + 0.5f ); - idxGain = max( 0, min(15,idxGain) ); */ - ratio = 0; - IF(L_sub(L_tmp,32768) >= 0) - { - idxGain = 15; - } - ELSE - { - ratio = extract_l(L_tmp); - exp_norm = norm_s(ratio); - idxGain = sub(14, exp_norm); - idxGain = s_max(0,idxGain); - } - IF(sub(idxGain,2) > 0 && sub(idxGain,15) < 0 && sub(ratio,add(shl(2,sub(idxGain,1)),shl(2,sub(idxGain,2)))) > 0) - { - idxGain = add(idxGain,1); - } - - /* ratio = (float)(1 << idxGain);*/ - IF( st->codec_mode == MODE2 ) - { - st->idxGain_fx = idxGain; - } - ELSE - { - push_indice_fx( st, IND_FB_SLOPE, idxGain, 4 ); - } - - return; -} -void tbe_write_bitstream_fx( - Encoder_State_fx *st_fx /* i/o: encoder state structure */ -) -{ - Word16 i; - - test(); - test(); - test(); - test(); - test(); - IF ( ( st_fx->rf_mode || L_sub( st_fx->total_brate_fx, ACELP_9k60 ) == 0 ) && ( sub( st_fx->bwidth_fx, WB ) == 0 ) ) - { - /* WB LSF */ - push_next_indice_fx( st_fx, st_fx->lsf_WB_fx, NUM_BITS_LBR_WB_LSF ); - - /* WB frame */ - push_next_indice_fx( st_fx, st_fx->gFrame_WB_fx, NUM_BITS_SHB_FrameGain_LBR_WB ); - } - ELSE IF ( ( L_sub( st_fx->total_brate_fx, ACELP_9k60 ) >= 0 ) && ( L_sub( st_fx->total_brate_fx, ACELP_32k ) <= 0 ) && - ( ( sub( st_fx->bwidth_fx, SWB ) == 0 ) || ( sub( st_fx->bwidth_fx, FB ) == 0 ) ) ) - { - /* LSF coefficients */ - - test(); - IF( (sub(st_fx->rf_mode,1)==0) || L_sub( st_fx->total_brate_fx, ACELP_9k60 ) == 0 ) - { - push_next_indice_fx( st_fx, st_fx->lsf_idx_fx[0], 8 ); - } - ELSE - { - FOR (i = 0; i < NUM_Q_LSF; i++) - { - push_next_indice_fx( st_fx, st_fx->lsf_idx_fx[i], lsf_q_num_bits[i] ); - } - - /* LSF mirror points */ - push_next_indice_fx( st_fx, st_fx->m_idx_fx, MIRROR_POINT_BITS ); - - /* LSF grid points */ - push_next_indice_fx( st_fx, st_fx->grid_idx_fx, NUM_LSF_GRID_BITS ); - } - - /* Gain shape */ - push_next_indice_fx( st_fx, st_fx->idxSubGains_fx, NUM_BITS_SHB_SUBGAINS ); - - /* frame gain */ - push_next_indice_fx( st_fx, st_fx->idxFrameGain_fx, NUM_BITS_SHB_FRAMEGAIN ); - - IF ( L_sub( st_fx->total_brate_fx, ACELP_24k40 ) >= 0 ) - { - /* sub frame energy*/ - push_next_indice_fx( st_fx, st_fx->idx_shb_fr_gain_fx, NUM_BITS_SHB_ENER_SF ); - - /* gain shapes residual */ - FOR (i = 0; i < NB_SUBFR16k; i++) - { - push_next_indice_fx( st_fx, st_fx->idx_res_gs_fx[i], NUM_BITS_SHB_RES_GS ); - } - - /* voicing factor */ - push_next_indice_fx( st_fx, st_fx->idx_mixFac_fx, NUM_BITS_SHB_VF ); - } - - IF( sub(st_fx->tec_tfa, 1) == 0 ) - { - push_next_indice_fx( st_fx, st_fx->tec_flag, BITS_TEC ); - push_next_indice_fx( st_fx, st_fx->tfa_flag, BITS_TFA ); - } - } - - IF ( sub( st_fx->bwidth_fx, FB ) == 0 ) - { - push_next_indice_fx( st_fx, st_fx->idxGain_fx, 4 ); - } -} - - -void TBEreset_enc_fx( - Encoder_State_fx *st_fx, /* i/o: encoder state structure */ - Word16 bandwidth /* i : bandwidth mode */ -) -{ - IF( sub(st_fx->last_core_fx,ACELP_CORE) != 0 ) - { - set16_fx( st_fx->old_bwe_exc_fx, 0, PIT16k_MAX * 2 ); - st_fx->bwe_non_lin_prev_scale_fx = L_deposit_l(0); - st_fx->prev_Q_bwe_exc = 31; - move16(); - } - - test(); - IF( sub( bandwidth, WB ) == 0 ) - { - wb_tbe_extras_reset_fx( st_fx->mem_genSHBexc_filt_down_wb2_fx, st_fx->mem_genSHBexc_filt_down_wb3_fx ); - set16_fx( st_fx->mem_genSHBexc_filt_down_shb_fx, 0, 7 ); - set16_fx( st_fx->state_lpc_syn_fx, 0, 10 ); - set16_fx( st_fx->state_syn_shbexc_fx, 0, L_SHB_LAHEAD/4 ); - set16_fx( st_fx->syn_overlap_fx, 0, L_SHB_LAHEAD ); - set32_fx( st_fx->mem_csfilt_fx, 0, 2 ); - } - ELSE IF( ( sub( bandwidth, SWB ) == 0 ) || ( sub( bandwidth, FB ) == 0 ) ) - { - set16_fx( st_fx->state_ana_filt_shb_fx, 0, (2*ALLPASSSECTIONS_STEEP+1) ); - - swb_tbe_reset_fx( st_fx->mem_csfilt_fx, st_fx->mem_genSHBexc_filt_down_shb_fx, st_fx->state_lpc_syn_fx, - st_fx->syn_overlap_fx, st_fx->state_syn_shbexc_fx, &(st_fx->tbe_demph_fx), &(st_fx->tbe_premph_fx), - st_fx->mem_stp_swb_fx, &(st_fx->gain_prec_swb_fx) ); - - IF( sub( bandwidth, FB ) == 0 ) - { - set16_fx( st_fx->fb_state_lpc_syn_fx, 0, LPC_SHB_ORDER ); - st_fx->fb_tbe_demph_fx = 0; - move16(); - fb_tbe_reset_enc_fx( st_fx->elliptic_bpf_2_48k_mem_fx, &st_fx->prev_fb_energy_fx,st_fx->elliptic_bpf_2_48k_mem_fx_Q,&st_fx->prev_fb_energy_fx_Q); - } - } -} - - diff --git a/src/libs/libevs/lib_enc/tcq_core_enc.cpp b/src/libs/libevs/lib_enc/tcq_core_enc.cpp new file mode 100644 index 00000000..57c9ceac --- /dev/null +++ b/src/libs/libevs/lib_enc/tcq_core_enc.cpp @@ -0,0 +1,431 @@ +/*==================================================================================== + EVS Codec 3GPP TS26.443 Nov 13, 2018. Version 12.11.0 / 13.7.0 / 14.3.0 / 15.1.0 + ====================================================================================*/ + +#include +#include +#include +#include "options.h" +#include "rom_com.h" +#include "prot.h" +#include "cnst.h" +#include "basop_util.h" +#include "basop_proto_func.h" + + +/*---------------------------------------------------------------------* + * tcq_core_LR_enc() + * + * Main Generic Audio Encoder Routine for LR-MDCT + *---------------------------------------------------------------------*/ + +void tcq_core_LR_enc( + Encoder_State *st, + int inp_vector[], + const float coefs_norm[], + float coefs_quant[], + const short bit_budget, /* number of bits */ + const short BANDS, + const short *sfm_start, + const short *sfm_end, + const short *sfmsize, + Word32 *Rk_fx, + int *npulses, + short *k_sort, + const short *p2a_flags, + const short p2a_bands, + const short *last_bitalloc, + const short input_frame, + const short adjustFlag, + const short is_transient +) +{ + short i, j, k, size, nb_bytes; + int nzp; + + float gain; + float step_scale[NB_SFM]; + + short pos_index[NB_SFM]; + float Rk_sort[NB_SFM]; + int USQ_TCQ[NB_SFM]; /* TCQ is selected by default*/ + float coefs_norm_dec[L_FRAME32k]; /* New output buffer (TCQ+USQ)*/ + + float pulses, crosscorr, selfcorr; + int savedstates[TCQ_MAX_BAND_SIZE]; + ARCODEC arenc, *parenc; + BITSTREAM bs, *pbs; + short k_num[2]; + + int flag_wbnb = 0; + int lsbtcq_bits = TCQ_AMP; + int tcq_arbits = 2; + int nzbands = 0; + short bcount = 0; + float abuffer[560]; + float mbuffer[560]; + float sbuffer[560]; + short dpath[280]; + /*Word32 Rk_fx[NB_SFM];*/ /* Q16 */ + Word32 Rk_sort_fx[NB_SFM]; /* Q16 */ + Word32 bsub_fx = 0; + Word32 est_frame_bits_fx; + + Word16 nzb = 0; + Word32 delta_fx; + Word32 surplus_fx; + Word32 bit_surplus_fx[2]; + + Word32 leftbits = 0; + Word32 sepbits = 0; + Word32 divider = 0; + + set_s(dpath, 0, 280); + set_f(abuffer, 0.f, 560); + set_f(mbuffer, 0.f, 560); + + set_f(sbuffer, FLT_MAX, 560); + + /* initialization */ + set_f( Rk_sort, 0.f, NB_SFM ); + set_i( USQ_TCQ, 0, NB_SFM ); + set_f( coefs_norm_dec, 0.f, L_FRAME32k ); + InitLSBTCQ(&bcount); + + if( input_frame <= L_FRAME16k && adjustFlag == 0 && is_transient == 0 ) + { + flag_wbnb = 1; + lsbtcq_bits = 0; + tcq_arbits = 0; + } + + parenc = &arenc; + pbs = &bs; + + pbs->curPos = 7; + pbs->numbits = 0; + pbs->numByte = 0; + memset(pbs->buf, 0, MAX_SIZEBUF_PBITSTREAM); + ar_encoder_start(parenc, pbs, bit_budget); + + /* TCQ Index initialize */ + memset( pos_index, 0, sizeof(short)*NB_SFM ); + + /* Bits distribution analysis */ + for( i = 0; i < BANDS; i++ ) + { + if ( L_sub(ar_div(Rk_fx[i], sfmsize[i]), 49152) >= 0 ) + { + /* USQ used for high importance bands*/ + USQ_TCQ[i] = 1; + } + else + { + /* TCQ used for usual bands */ + USQ_TCQ[i] = 0; + } + if( Rk_fx[i] > 0 ) + { + nzbands++; + } + } + + for( j = 0; j < BANDS; j++ ) + { + if( Rk_fx[j] > 0 ) + { + nzb++; + } + } + + bsub_fx = L_shl(L_add(tcq_arbits, lsbtcq_bits), 16); + IF( bsub_fx > 0) + { + bsub_fx = L_add( bsub_fx, 2048); + } + for( j = BANDS - 1; j >= 0; j-- ) + { + if( Rk_fx[j] > 0 ) + { + Rk_fx[j] = L_sub(Rk_fx[j], ar_div(bsub_fx, nzb)); + if( Rk_fx[j] < 0) + { + bsub_fx = L_sub(bsub_fx, L_add(ar_div(bsub_fx, nzb), Rk_fx[j])); + Rk_fx[j] = 0; + } + else + { + bsub_fx = L_sub(bsub_fx, ar_div(bsub_fx, nzb)); + } + nzb = sub(nzb, 1); + } + } + + srt_vec_ind_fx( Rk_fx, Rk_sort_fx, k_sort, BANDS); + /* Quantize spectral band shapes using TCQ */ + /* Select ISC */ + set_f( coefs_quant, 0.0, sfm_end[BANDS-1]+1 ); + + mvr2r( coefs_norm, coefs_quant,sfm_end[BANDS-1]+1 ); + + delta_fx = 0; + est_frame_bits_fx = 0; + if( input_frame <= L_FRAME16k && adjustFlag == 0 && is_transient == 0 ) + { + surplus_fx = -131072; + bit_allocation_second_fx( Rk_fx, Rk_sort_fx, BANDS, sfmsize, k_sort, k_num, p2a_flags, p2a_bands, last_bitalloc, input_frame ); + + nzbands = 0; + for ( j = 0; j < BANDS; j++ ) + { + if( sub(j, k_num[0]) != 0 && sub(j, k_num[1]) != 0) + { + leftbits = L_add( leftbits, Rk_fx[k_sort[j]]); + if( Rk_fx[k_sort[j]] > 0 ) + { + nzbands = add(nzbands, 1); + } + } + else + { + sepbits = L_add( sepbits, Rk_fx[k_sort[j]]); + } + } + + /* Separate the position information from the input signal(coefs_norm) */ + /* Gather the NZ coefficients*/ + for( k = 0; k < BANDS; k++) /* Loop through non-zero blocks */ + { + if( k != k_num[0] && k != k_num[1]) + { + if( Rk_fx[k_sort[k]] > 0 && USQ_TCQ[k_sort[k]] == 0 ) /* Then have non-zero block AND WILL BE ENCODED BY TCQ */ + { + /* Encode Position Info, NZ Info, Signs */ + size = sfmsize[k_sort[k]]; + /* Determine scale step, ISC and TCQ quantizer */ + GetISCScale( &coefs_quant[sfm_start[k_sort[k]]], size, L_add( Rk_fx[k_sort[k]], delta_fx), + &coefs_norm_dec[ sfm_start[ k_sort[k]]], &step_scale[k_sort[k]], &surplus_fx, &pulses, savedstates, 0, &nzp, 0, 0, 0, 0 ); + leftbits = L_sub( leftbits, L_add( Rk_fx[k_sort[k]], delta_fx) ); + + npulses[ k_sort[k]] = (int)pulses; + + encode_position_ari_fx( parenc, &coefs_norm_dec[ sfm_start[ k_sort[k]]], size, &est_frame_bits_fx ); + encode_magnitude_tcq_fx( parenc, &coefs_norm_dec[ sfm_start[ k_sort[k]]], size, npulses[k_sort[k]], nzp, savedstates, &est_frame_bits_fx ); + encode_signs_fx( parenc, &coefs_norm_dec[ sfm_start[ k_sort[k]]], size, nzp, &est_frame_bits_fx ); + nzbands--; + + } + /* Have USQ coded band */ + else if( Rk_fx[k_sort[k]] > 0 && sub(USQ_TCQ[k_sort[k]], 1) == 0 ) + { + size = sfmsize[k_sort[k]]; + GetISCScale( &coefs_quant[ sfm_start[ k_sort[k]]], size, L_add( Rk_fx[k_sort[k]], delta_fx), + &coefs_norm_dec[ sfm_start[ k_sort[k]]], &step_scale[k_sort[k]], &surplus_fx, &pulses, savedstates, 1, &nzp, 0, 0, 0, 0 ); + leftbits = L_sub( leftbits, L_add( Rk_fx[k_sort[k]], delta_fx) ); + + npulses[ k_sort[ k]] = (int)pulses; + + encode_position_ari_fx( parenc, &coefs_norm_dec[sfm_start[k_sort[k]]], size, &est_frame_bits_fx ); + encode_magnitude_usq_fx( parenc, &coefs_norm_dec[sfm_start[k_sort[k]]], size, npulses[k_sort[k]], nzp, &est_frame_bits_fx ); + encode_signs_fx( parenc, &coefs_norm_dec[ sfm_start[ k_sort[ k]]], size, nzp, &est_frame_bits_fx ); + + nzbands--; + } + else /* Then have zero block */ + { + npulses[ k_sort[ k]] = 0; + size = sfmsize[k_sort[k]]; + } + + if( Rk_fx[k_sort[k]] > 0 && surplus_fx < 0 ) + { + IF( nzbands <= 1 ) + { + divider = 0; + } + ELSE + { + divider = 2; + } + + IF( L_add( L_add( surplus_fx, sepbits), ar_div( leftbits, divider) ) < 0 ) + { + /* Overflow possible => start to distribute negative surplus */ + delta_fx = ar_div( surplus_fx + sepbits, nzbands); + } + else + { + delta_fx = 0; + } + surplus_fx = L_sub(surplus_fx, delta_fx); + } + else + { + delta_fx = 0; + } + } + } + + if (( L_sub(surplus_fx,524288) > 0 && sub(input_frame,L_FRAME8k) == 0 ) || ( L_sub(surplus_fx,786432) > 0 && sub(input_frame,L_FRAME16k) == 0 )) + { + bit_surplus_fx[0] = Mult_32_16(surplus_fx,24576); /* Q16 */ + bit_surplus_fx[1] = Mult_32_16(surplus_fx,8192); /* Q16 */ + } + else + { + bit_surplus_fx[0] = surplus_fx; + bit_surplus_fx[1] = 0; + } + for( k = 0; k < BANDS; k++ ) + { + for( j = 0; j < 2; j++ ) + { + if( k == k_num[j] ) + { + Rk_fx[k_sort[k]] = L_add(Rk_fx[k_sort[k]],bit_surplus_fx[j]); + + if( Rk_fx[k_sort[k]] > 0 && USQ_TCQ[k_sort[k]] == 0 ) /* Then have non-zero block AND WILL BE ENCODED BY TCQ */ + { + /* Encode Position Info, NZ Info, Signs */ + size = sfmsize[k_sort[k]]; + + /* Determine scale step, ISC and TCQ quantizer */ + GetISCScale( &coefs_quant[sfm_start[k_sort[k]]], size, Rk_fx[k_sort[k]], &coefs_norm_dec[ sfm_start[ k_sort[k]]], + &step_scale[k_sort[k]], &surplus_fx, &pulses, savedstates, 0, &nzp, 0, 0, 0, 0 ); + + npulses[ k_sort[k]] = pulses; + + encode_position_ari_fx( parenc, &coefs_norm_dec[ sfm_start[ k_sort[k]]], size, &est_frame_bits_fx ); + encode_magnitude_tcq_fx( parenc, &coefs_norm_dec[ sfm_start[ k_sort[k]]], size, npulses[k_sort[k]], nzp, savedstates, &est_frame_bits_fx ); + encode_signs_fx( parenc, &coefs_norm_dec[ sfm_start[ k_sort[k]]], size, nzp, &est_frame_bits_fx ); + } + /* Have USQ coded band */ + else if( Rk_fx[k_sort[k]] > 0 && sub(USQ_TCQ[k_sort[k]], 1) == 0 ) + { + size = sfmsize[k_sort[k]]; + + GetISCScale( &coefs_quant[ sfm_start[ k_sort[k]]], size, Rk_fx[k_sort[k]], &coefs_norm_dec[ sfm_start[ k_sort[k]]], + &step_scale[k_sort[k]], &surplus_fx, &pulses, savedstates, 1, &nzp, 0, 0, 0, 0 ); + + npulses[ k_sort[k]] = pulses; + + encode_position_ari_fx( parenc, &coefs_norm_dec[sfm_start[k_sort[k]]], size, &est_frame_bits_fx ); + encode_magnitude_usq_fx( parenc, &coefs_norm_dec[sfm_start[k_sort[k]]], size, npulses[k_sort[k]], nzp, &est_frame_bits_fx ); + encode_signs_fx( parenc, &coefs_norm_dec[ sfm_start[ k_sort[k]]], size, nzp, &est_frame_bits_fx ); + } + else /* Then have zero block */ + { + npulses[ k_sort[k]] = 0; + size = sfmsize[k_sort[k]]; + } + } + } + } + } + else + { + surplus_fx = 0; + + /* Separate the position information from the input signal(coefs_norm) */ + /* Gather the NZ coefficients*/ + for( k = 0; k < BANDS; k++) /* Loop through non-zero blocks */ + { + if( Rk_fx[k_sort[k]] > 0 ) + { + size = sfmsize[k_sort[k]]; + GetISCScale( &coefs_quant[ sfm_start[ k_sort[k]]], size, L_add( Rk_fx[k_sort[k]], delta_fx), &coefs_norm_dec[ sfm_start[ k_sort[k]]], &step_scale[k_sort[k]], &surplus_fx, &pulses, savedstates, 1, &nzp, &bcount, abuffer, mbuffer, sbuffer); + + npulses[ k_sort[k]] = pulses; + encode_position_ari_fx(parenc, &coefs_norm_dec[sfm_start[k_sort[k]]], size, &est_frame_bits_fx); + encode_magnitude_usq_fx(parenc, &coefs_norm_dec[sfm_start[k_sort[k]]], size, npulses[k_sort[k]], nzp, &est_frame_bits_fx); + encode_signs_fx(parenc, &coefs_norm_dec[ sfm_start[ k_sort[k]]], size, nzp, &est_frame_bits_fx); + + /* nzbands--; */ + nzbands = sub(nzbands, 1); + } + else /* Then have zero block */ + { + npulses[ k_sort[k]] = 0; + size = sfmsize[k_sort[k]]; + } + + /* Surplus distribution */ + if( surplus_fx > 0 && nzbands > 0 ) + { + delta_fx = ar_div(surplus_fx, nzbands); + surplus_fx = L_sub(surplus_fx, delta_fx); + } + } + } + + TCQLSB( bcount, abuffer, mbuffer, sbuffer, dpath ); + + /* Save TCQ path to bitstream */ + SaveTCQdata( parenc, dpath, lsbtcq_bits ); + + /* Add tcq sequence to decoding buffer */ + InitLSBTCQ( &bcount ); + + ar_encoder_done( parenc ); + + /* Loop through non-zero blocks */ + if( !flag_wbnb ) + { + for( k = 0; k < BANDS; k++ ) + { + if( Rk_fx[k_sort[k]] > 0 ) + { + size = sfmsize[k_sort[k]]; + RestoreTCQ( &coefs_norm_dec[ sfm_start[ k_sort[k]]], size, &bcount, mbuffer ); + } + } + } + + nb_bytes = bit_budget >> 3; + j = bit_budget - (nb_bytes << 3); + for( i = 0; i < nb_bytes; i++ ) + { + push_indice(st, IND_HQ2_SUBBAND_TCQ, pbs->buf[i], 8); + } + if( j > 0 ) + { + push_indice(st, IND_HQ2_SUBBAND_TCQ, (pbs->buf[nb_bytes] >> (8 - j)), j); + } + + /* Clear decoding buffer */ + set_f( coefs_quant, 0.0, sfm_end[BANDS-1]+1 ); + /* New analysis of decoded frame */ + for( i = 0; i < BANDS; i++ ) + { + if( Rk_fx[ k_sort[i]] > 0 ) + { + gain = 0.0f; + + crosscorr = 0.0f; + selfcorr = EPSILON; + for( j = 0; j < sfmsize[k_sort[i]]; j++ ) + { + crosscorr += (coefs_norm[sfm_start[k_sort[i]]+j] * coefs_norm_dec[sfm_start[k_sort[i]]+j]); + selfcorr += (coefs_norm_dec[sfm_start[k_sort[i]]+j] * coefs_norm_dec[sfm_start[k_sort[i]]+j]); + } + + gain = crosscorr / selfcorr; + + if( gain == 0 ) + { + gain = 1e-10f; + } + + /* Use optimal gain */ + for( j = 0; j < sfmsize[k_sort[i]]; j++ ) + { + inp_vector[sfm_start[k_sort[i]]+j] = round_f( ((1.0f/QTCQ)*coefs_norm_dec[sfm_start[k_sort[i]]+j]) ); + coefs_quant[sfm_start[k_sort[i]]+j] = gain*coefs_norm_dec[sfm_start[k_sort[i]]+j]; + } + } + } + + + return; + +} diff --git a/src/libs/libevs/lib_enc/tcq_core_enc_fx.cpp b/src/libs/libevs/lib_enc/tcq_core_enc_fx.cpp deleted file mode 100755 index a4bcfe4e..00000000 --- a/src/libs/libevs/lib_enc/tcq_core_enc_fx.cpp +++ /dev/null @@ -1,474 +0,0 @@ -/*==================================================================================== - EVS Codec 3GPP TS26.442 Apr 03, 2018. Version 12.11.0 / 13.6.0 / 14.2.0 - ====================================================================================*/ - -#include -#include "options.h" /* Compilation switches */ -#include "prot_fx.h" -#include "stl.h" - -void tcq_core_LR_enc_fx( - Encoder_State_fx* st_fx, - Word16 inp_vector_fx[], /* x5 */ - const Word32 coefs_norm_fx[], /* Q12 */ - Word32 coefs_quant_fx[], /* Q12 */ - const Word16 bit_budget, /* number of bits */ - const Word16 BANDS, - const Word16 *sfm_start, - const Word16 *sfm_end, - const Word16 *sfmsize, - Word32 *R_fx, /* Q16 */ - Word16 *npulses, - Word16 *k_sort, - const Word16 *p2a_flags, - const Word16 p2a_bands, - const Word16 *last_bitalloc, - const Word16 input_frame, - const Word16 adjustFlag, - const Word16 is_transient -) -{ - Word16 i, j, k, size, nb_bytes; - - Word16 USQ_TCQ[NB_SFM]; /* TCQ is selected by default*/ - Word16 coefs_norm_dec_fx[L_FRAME32k]; /* New output buffer (TCQ+USQ)*/ - Word32 savedstates[TCQ_MAX_BAND_SIZE]; - ARCODEC_FX arenc_fx, *parenc_fx; - BITSTREAM_FX bs_fx, *pbs_fx; - Word16 k_num[2]; - Word32 bit_surplus_fx[2]; - - Word16 flag_wbnb = 0; - Word16 lsbtcq_bits = TCQ_AMP; - Word16 tcq_arbits = 2; - Word16 nzb = 0; - Word16 nzbands = 0; - Word16 bcount = 0; - Word32 bsub_fx = 0; - Word32 abuffer_fx[MAX_PULSES]; - Word16 mbuffer_fx[MAX_PULSES]; - Word32 sbuffer_fx[MAX_PULSES]; - Word16 dpath[280]; - Word32 Rk_sort_fx[NB_SFM]; - Word32 step_scale_fx[NB_SFM]; - Word16 pulses_fx, nzp_fx; - - Word32 gain_fx, crosscorr_fx, selfcorr_fx; - Word16 hi, lo, exp; - Word32 surplus_fx, delta_fx, est_frame_bits_fx; - - Word32 leftbits = 0; - Word32 sepbits = 0; - Word32 divider = 0; - - set16_fx(dpath, 0, 280); - set32_fx(abuffer_fx, 0, MAX_PULSES); - set32_fx(sbuffer_fx, 0, MAX_PULSES); - set16_fx(mbuffer_fx, 0, MAX_PULSES); - /* initialization */ - set32_fx(Rk_sort_fx, 0, NB_SFM); - set16_fx(USQ_TCQ, 0, NB_SFM); - set16_fx(coefs_norm_dec_fx, 0, L_FRAME32k); - - InitLSBTCQ_fx(&bcount); - - test(); - test(); - IF( input_frame <= L_FRAME16k && adjustFlag == 0 && is_transient == 0 ) - { - flag_wbnb = 1; - move16(); - lsbtcq_bits = 0; - move16(); - tcq_arbits = 0; - move16(); - } - - /* TCQ Index initialize */ - parenc_fx = &arenc_fx; - pbs_fx = &bs_fx; - - pbs_fx->curPos = 7; - move16(); - pbs_fx->numbits = L_deposit_l(0); - pbs_fx->numByte = L_deposit_l(0); - FOR (i = 0; i < MAX_SIZEBUF_PBITSTREAM; i++) - { - pbs_fx->buf[i] = 0; - move16(); - } - ar_encoder_start_fx(parenc_fx, pbs_fx, L_deposit_l(bit_budget)); - - /* Bits distribution analysis */ - FOR ( i = 0; i < BANDS; i++ ) - { - IF ( L_sub(ar_div(R_fx[i], sfmsize[i]), 49152) >= 0 ) - { - /* USQ used for high importance bands*/ - USQ_TCQ[i] = 1; - move16(); - } - ELSE - { - /* TCQ used for usual bands */ - USQ_TCQ[i] = 0; - move16(); - } - - IF( R_fx[i] > 0 ) - { - /* nzbands++; */ - nzbands = add(nzbands, 1); - } - } - - FOR ( j = 0; j < BANDS; j++ ) - { - IF ( R_fx[j] > 0 ) - { - nzb++; - } - } - - bsub_fx = L_shl(add(tcq_arbits, lsbtcq_bits), 16); /* Q16 */ - IF( bsub_fx > 0) - { - bsub_fx = L_add( bsub_fx, 2048); - } - FOR ( j = BANDS - 1; j >= 0; j-- ) - { - IF( R_fx[j] > 0 ) - { - R_fx[j] = L_sub(R_fx[j], ar_div(bsub_fx, nzb)); - - IF( R_fx[j] < 0) - { - bsub_fx = L_sub(bsub_fx, L_add(ar_div(bsub_fx, nzb), R_fx[j])); - R_fx[j] = L_deposit_l(0); - } - ELSE - { - bsub_fx = L_sub(bsub_fx, ar_div(bsub_fx, nzb)); - } - /* nzb--; */ - nzb = sub(nzb, 1); - } - } - - /* Sort the bit allocation table (R) in ascending order, figure out number of pulses per band */ - srt_vec_ind_fx(R_fx, Rk_sort_fx, k_sort, BANDS); - - /* Quantize spectral band shapes using TCQ */ - /* Select ISC */ - set32_fx(coefs_quant_fx, 0, sfm_end[BANDS - 1]+1); - Copy32( coefs_norm_fx, coefs_quant_fx,sfm_end[BANDS-1]+1); - - delta_fx = L_deposit_l(0); - est_frame_bits_fx = L_deposit_l(0); - - test(); - test(); - IF ( sub(input_frame, L_FRAME16k) <= 0 && adjustFlag == 0 && is_transient == 0 ) - { - surplus_fx = -131072; - move32(); - bit_allocation_second_fx( R_fx, Rk_sort_fx, BANDS, sfmsize, k_sort, k_num, p2a_flags, p2a_bands, last_bitalloc, input_frame ); - - nzbands = 0; - move16(); - FOR ( j = 0; j < BANDS; j++ ) - { - IF( sub(j, k_num[0]) != 0 && sub(j, k_num[1]) != 0) - { - leftbits = L_add( leftbits, R_fx[k_sort[j]]); - if( R_fx[k_sort[j]] > 0 ) - { - nzbands = add(nzbands, 1); - } - } - ELSE - { - sepbits = L_add( sepbits, R_fx[k_sort[j]]); - } - } - /* Separate the position information from the input signal(coefs_norm) */ - /* Gather the NZ coefficients*/ - FOR ( k = 0; k < BANDS; k++) /* Loop through non-zero blocks */ - { - test(); - IF ( sub(k, k_num[0]) != 0 && sub(k, k_num[1]) != 0) - { - test(); - test(); - IF ( R_fx[k_sort[k]] > 0 && USQ_TCQ[k_sort[k]] == 0 ) /* Then have non-zero block AND WILL BE ENCODED BY TCQ */ - { - /* Encode Position Info, NZ Info, Signs */ - size = sfmsize[k_sort[k]]; - move16(); - - /* Determine scale step, ISC and TCQ quantizer */ - GetISCScale_fx( &coefs_quant_fx[sfm_start[k_sort[k]]], size, - L_add( R_fx[k_sort[k]], delta_fx), - /* R_fx[k_sort[k]], */ - &coefs_norm_dec_fx[ sfm_start[ k_sort[k]]], &step_scale_fx[k_sort[k]], &surplus_fx, &pulses_fx, savedstates, 0, &nzp_fx - , 0, 0, 0, 0 - ); - leftbits = L_sub( leftbits, L_add( R_fx[k_sort[k]], delta_fx) ); - npulses[ k_sort[k]] = pulses_fx; - move16(); - - encode_position_ari_fx( parenc_fx, &coefs_norm_dec_fx[ sfm_start[ k_sort[k]]], size, &est_frame_bits_fx ); - encode_magnitude_tcq_fx( parenc_fx, &coefs_norm_dec_fx[ sfm_start[ k_sort[k]]], size, npulses[k_sort[k]], nzp_fx, savedstates, &est_frame_bits_fx ); - encode_signs_fx( parenc_fx, &coefs_norm_dec_fx[ sfm_start[ k_sort[k]]], size, nzp_fx, &est_frame_bits_fx ); - nzbands--; - } - /* Have USQ coded band */ - ELSE IF( R_fx[k_sort[k]] > 0 && sub(USQ_TCQ[k_sort[k]], 1) == 0 ) - { - size = sfmsize[k_sort[k]]; - move16(); - - GetISCScale_fx( &coefs_quant_fx[ sfm_start[ k_sort[k]]], size, - L_add( R_fx[k_sort[k]], delta_fx), - /* R_fx[k_sort[k]], */ - &coefs_norm_dec_fx[ sfm_start[ k_sort[k]]], &step_scale_fx[k_sort[k]], &surplus_fx, &pulses_fx, savedstates, 1, &nzp_fx - , 0, 0, 0, 0 - ); - leftbits = L_sub( leftbits, L_add( R_fx[k_sort[k]], delta_fx) ); - npulses[ k_sort[k]] = pulses_fx; - move16(); - - encode_position_ari_fx( parenc_fx, &coefs_norm_dec_fx[sfm_start[k_sort[k]]], size, &est_frame_bits_fx ); - encode_magnitude_usq_fx( parenc_fx, &coefs_norm_dec_fx[sfm_start[k_sort[k]]], size, npulses[k_sort[k]], nzp_fx, &est_frame_bits_fx ); - encode_signs_fx( parenc_fx, &coefs_norm_dec_fx[ sfm_start[ k_sort[ k]]], size, nzp_fx, &est_frame_bits_fx ); - nzbands--; - } - ELSE /* Then have zero block */ - { - npulses[ k_sort[ k]] = 0; - move16(); - size = sfmsize[k_sort[k]]; - move16(); - } - - delta_fx = L_deposit_l(0); - test(); - IF( R_fx[k_sort[k]] > 0 && surplus_fx < 0 ) - { - /* delta_fx = L_deposit_h( div_l( surplus_fx, nzbands ) ); */ - IF( nzbands <= 1 ) - { - divider = 0; - } - ELSE - { - divider = 2; - } - - IF( L_add( L_add( surplus_fx, sepbits), ar_div( leftbits, divider) ) < 0 ) - { - /* Overflow possible => start to distribute negative surplus */ - delta_fx = ar_div( surplus_fx + sepbits, nzbands); - } - else - { - delta_fx = 0; - } - surplus_fx = L_sub(surplus_fx, delta_fx); - } - } - } - - test(); - test(); - test(); - IF (( L_sub(surplus_fx,524288) > 0 && sub(input_frame,L_FRAME8k) == 0 ) || ( L_sub(surplus_fx,786432) > 0 && sub(input_frame,L_FRAME16k) == 0 )) - { - bit_surplus_fx[0] = Mult_32_16(surplus_fx,24576); /* Q16 */ - bit_surplus_fx[1] = Mult_32_16(surplus_fx,8192); /* Q16 */ - } - ELSE - { - bit_surplus_fx[0] = surplus_fx; - move32(); - bit_surplus_fx[1] = L_deposit_l(0); - } - - FOR ( k = 0; k < BANDS; k++ ) - { - FOR ( j = 0; j < 2; j++ ) - { - IF ( sub(k, k_num[j]) == 0 ) - { - R_fx[k_sort[k]] = L_add(R_fx[k_sort[k]],bit_surplus_fx[j]); - - test(); - test(); - IF ( R_fx[k_sort[k]] > 0 && USQ_TCQ[k_sort[k]] == 0 ) /* Then have non-zero block AND WILL BE ENCODED BY TCQ */ - { - /* Encode Position Info, NZ Info, Signs */ - size = sfmsize[k_sort[k]]; - move16(); - - /* Determine scale step, ISC and TCQ quantizer */ - GetISCScale_fx( &coefs_quant_fx[sfm_start[k_sort[k]]], size, R_fx[k_sort[k]], &coefs_norm_dec_fx[ sfm_start[ k_sort[k]]], &step_scale_fx[k_sort[k]], &surplus_fx, &pulses_fx, savedstates, 0, &nzp_fx - , 0, 0, 0, 0 - ); - - npulses[ k_sort[k]] = pulses_fx; - move16(); - - encode_position_ari_fx( parenc_fx, &coefs_norm_dec_fx[ sfm_start[ k_sort[k]]], size, &est_frame_bits_fx ); - encode_magnitude_tcq_fx( parenc_fx, &coefs_norm_dec_fx[ sfm_start[ k_sort[k]]], size, npulses[k_sort[k]], nzp_fx, savedstates, &est_frame_bits_fx ); - encode_signs_fx( parenc_fx, &coefs_norm_dec_fx[ sfm_start[ k_sort[k]]], size, nzp_fx, &est_frame_bits_fx ); - } - /* Have USQ coded band */ - ELSE IF( R_fx[k_sort[k]] > 0 && sub(USQ_TCQ[k_sort[k]], 1) == 0 ) - { - size = sfmsize[k_sort[k]]; - move16(); - - GetISCScale_fx( &coefs_quant_fx[ sfm_start[ k_sort[k]]], size, R_fx[k_sort[k]], &coefs_norm_dec_fx[ sfm_start[ k_sort[k]]], &step_scale_fx[k_sort[k]], &surplus_fx, &pulses_fx, savedstates, 1, &nzp_fx - , 0, 0, 0, 0 - ); - - npulses[ k_sort[k]] = pulses_fx; - move16(); - - encode_position_ari_fx( parenc_fx, &coefs_norm_dec_fx[sfm_start[k_sort[k]]], size, &est_frame_bits_fx ); - encode_magnitude_usq_fx( parenc_fx, &coefs_norm_dec_fx[sfm_start[k_sort[k]]], size, npulses[k_sort[k]], nzp_fx, &est_frame_bits_fx ); - encode_signs_fx( parenc_fx, &coefs_norm_dec_fx[ sfm_start[ k_sort[k]]], size, nzp_fx, &est_frame_bits_fx ); - } - ELSE /* Then have zero block */ - { - npulses[ k_sort[k]] = 0; - move16(); - size = sfmsize[k_sort[k]]; - move16(); - } - } - } - } - } - ELSE - { - surplus_fx = L_deposit_l(0); - - /* Separate the position information from the input signal(coefs_norm) */ - /* Gather the NZ coefficients*/ - FOR( k = 0; k < BANDS; k++) /* Loop through non-zero blocks */ - { - IF( R_fx[k_sort[k]] > 0 ) - { - size = sfmsize[k_sort[k]]; - move16(); - GetISCScale_fx( &coefs_quant_fx[ sfm_start[ k_sort[k]]], size, R_fx[k_sort[k]] + delta_fx, &coefs_norm_dec_fx[ sfm_start[ k_sort[k]]], &step_scale_fx[k_sort[k]], &surplus_fx, &pulses_fx, savedstates, 1, &nzp_fx, &bcount, abuffer_fx, mbuffer_fx, sbuffer_fx); - - npulses[ k_sort[k]] = pulses_fx; - move16(); - encode_position_ari_fx(parenc_fx, &coefs_norm_dec_fx[sfm_start[k_sort[k]]], size, &est_frame_bits_fx); - encode_magnitude_usq_fx(parenc_fx, &coefs_norm_dec_fx[sfm_start[k_sort[k]]], size, npulses[k_sort[k]], nzp_fx, &est_frame_bits_fx); - encode_signs_fx(parenc_fx, &coefs_norm_dec_fx[ sfm_start[ k_sort[k]]], size, nzp_fx, &est_frame_bits_fx); - - /* nzbands--; */ - nzbands = sub(nzbands, 1); - } - ELSE /* Then have zero block */ - { - npulses[ k_sort[k]] = 0; - move16(); - size = sfmsize[k_sort[k]]; - move16(); - } - - /* Surplus distribution */ - /* if( surplus > 0.0f && nzbands > 0 ) */ - test(); - IF( surplus_fx > 0 && nzbands > 0 ) - { - /* delta = surplus / nzbands; - surplus -= delta; */ - - delta_fx = ar_div(surplus_fx, nzbands); - surplus_fx = L_sub(surplus_fx, delta_fx); - } - } - } - - TCQLSB_fx(bcount, /*abuffer, */abuffer_fx, /*mbuffer, */mbuffer_fx, /*sbuffer, */sbuffer_fx, dpath); - - /* Save TCQ path to bitstream */ - SaveTCQdata_fx(parenc_fx, dpath, lsbtcq_bits); - - /* Add tcq sequence to decoding buffer */ - InitLSBTCQ_fx(&bcount); - - ar_encoder_done_fx(parenc_fx); - - /* Loop through non-zero blocks */ - FOR (i = 0; i < L_FRAME32k; i++) - { - coefs_norm_dec_fx[i] = extract_l(L_mult0(coefs_norm_dec_fx[i], 5)); - } - IF( !flag_wbnb ) - { - FOR ( k = 0; k < BANDS; k++) - { - IF( R_fx[k_sort[k]] > 0 ) - { - size = sfmsize[k_sort[k]]; - move16(); - RestoreTCQ_fx( &coefs_norm_dec_fx[ sfm_start[ k_sort[k]]], size, &bcount, mbuffer_fx ); - } - } - } - - nb_bytes = shr(bit_budget, 3); - j = sub(bit_budget, shl(nb_bytes, 3)); - FOR( i = 0; i < nb_bytes; i++ ) - { - push_indice_fx(st_fx, IND_HQ2_SUBBAND_TCQ, pbs_fx->buf[i], 8); - } - IF( j > 0 ) - { - push_indice_fx(st_fx, IND_HQ2_SUBBAND_TCQ, shr(pbs_fx->buf[nb_bytes],(8 - j)), j); - } - /* Clear decoding buffer */ - set32_fx(coefs_quant_fx, 0, sfm_end[BANDS-1]+1); - - /* New analysis of decoded frame */ - FOR ( i = 0; i < BANDS; i++ ) - { - IF ( R_fx[ k_sort[i]] > 0 ) - { - gain_fx = L_deposit_l(0); - - crosscorr_fx = L_deposit_l(0); - selfcorr_fx = L_deposit_l(0); - - FOR ( j = 0; j < sfmsize[k_sort[i]]; j++ ) - { - crosscorr_fx = L_add( crosscorr_fx, Mult_32_16( coefs_norm_fx[sfm_start[k_sort[ i]]+j], shl(coefs_norm_dec_fx[sfm_start[k_sort[ i]]+j], 2) ) );/*1 */ - selfcorr_fx = L_mac0(selfcorr_fx, coefs_norm_dec_fx[sfm_start[k_sort[ i]]+j], coefs_norm_dec_fx[sfm_start[k_sort[ i]]+j]); - } - - exp =sub(norm_l(crosscorr_fx), 1); - gain_fx = ar_div( L_shl(crosscorr_fx, exp), selfcorr_fx); /* 1 + exp */ - gain_fx = L_shl( gain_fx, sub( 16, 1 + exp) + 2);/* 0.2 * Q16 */ - lo = L_Extract_lc(gain_fx, &hi); - /* Use optimal gain */ - FOR ( j = 0; j < sfmsize[k_sort[i]]; j++ ) - { - inp_vector_fx[sfm_start[k_sort[i]]+j] = coefs_norm_dec_fx[sfm_start[k_sort[i]]+j]; - move16(); - coefs_quant_fx[sfm_start[k_sort[ i]]+j] = L_add(L_shl(L_mult0(hi, coefs_norm_dec_fx[sfm_start[k_sort[ i]]+j]), 12), - L_shr(L_mult0(lo, coefs_norm_dec_fx[sfm_start[k_sort[ i]]+j]), 3)); /* Q12 */ - } - } - } - - - - return; - -} diff --git a/src/libs/libevs/lib_enc/tcx_ltp_enc.cpp b/src/libs/libevs/lib_enc/tcx_ltp_enc.cpp old mode 100755 new mode 100644 index f639e800..b81961e8 --- a/src/libs/libevs/lib_enc/tcx_ltp_enc.cpp +++ b/src/libs/libevs/lib_enc/tcx_ltp_enc.cpp @@ -1,189 +1,118 @@ /*==================================================================================== - EVS Codec 3GPP TS26.442 Apr 03, 2018. Version 12.11.0 / 13.6.0 / 14.2.0 + EVS Codec 3GPP TS26.443 Nov 13, 2018. Version 12.11.0 / 13.7.0 / 14.3.0 / 15.1.0 ====================================================================================*/ -#include #include "options.h" -#include "prot_fx.h" -#include "stl.h" -#include "cnst_fx.h" -#include "basop_util.h" -#include "rom_com_fx.h" - -static Word32 dot(const Word16 *X, const Word16 *Y, Word16 n) -{ - Word32 acc; - Word16 i; +#include "prot.h" +#include "rom_enc.h" +#include "rom_com.h" - acc = L_deposit_l(0); - - FOR (i = 0; i < n; i++) - { - acc = L_mac0(acc, X[i], Y[i]); - } - return acc; -} - -static Word32 interpolate_corr( /* o : interpolated value */ - const Word32 *x, /* i : input vector */ - const Word16 frac, /* i : fraction of lag */ - const Word16 frac_max /* i : max fraction */ +static float interpolate_corr( /* o : interpolated value */ + const float *x, /* i : input vector */ + const short frac, /* i : fraction of lag */ + const short frac_max /* i : max fraction */ ) { - Word32 s; - const Word16 *c, *win; + short i; + float s; + const float *c1, *c2, *x1, *x2, *win; - win = E_ROM_inter4_1; - if (sub(frac_max, 6) == 0) win = E_ROM_inter6_1; + if ( frac_max == 6 ) + { + win = E_ROM_inter6_1; + } + else + { + win = E_ROM_inter4_1; + } - - s = L_deposit_l(0); - - c = &win[frac]; - s = L_add(s, Mpy_32_16_1(x[0], *c)); - c += frac_max; - s = L_add(s, Mpy_32_16_1(x[-1], *c)); - c += frac_max; - s = L_add(s, Mpy_32_16_1(x[-2], *c)); - c += frac_max; - s = L_add(s, Mpy_32_16_1(x[-3], *c)); - - c = &win[frac_max-frac]; - s = L_add(s, Mpy_32_16_1(x[1], *c)); - c += frac_max; - s = L_add(s, Mpy_32_16_1(x[2], *c)); - c += frac_max; - s = L_add(s, Mpy_32_16_1(x[3], *c)); - c += frac_max; - s = L_add(s, Mpy_32_16_1(x[4], *c)); + x1 = &x[0]; + x2 = &x[1]; + c1 = &win[frac]; + c2 = &win[frac_max-frac]; + s = 0.0f; + for(i=0; i<4; i++, c1+=frac_max, c2+=frac_max) + { + s+= (*x1--) * (*c1) + (*x2++) * (*c2); + } return s; } -void tcx_ltp_pitch_search( - Word16 pitch_ol, - Word16 *pitch_int, - Word16 *pitch_fr, - Word16 *index, - Word16 *norm_corr, - const Word16 len, - Word16 *wsp, - Word16 pitmin, - Word16 pitfr1, - Word16 pitfr2, - Word16 pitmax, - Word16 pitres +static void tcx_ltp_pitch_search( + int pitch_ol, + int *pitch_int, + int *pitch_fr, + int *index, + float *norm_corr, + const short len, + float *wsp, + int pitmin, + int pitfr1, + int pitfr2, + int pitmax, + int pitres ) { - Word16 i, t, t0, t1, step, fraction, t0_min, t0_max, t_min, t_max, delta, temp_m, temp_e, s, s_wsp; - Word32 cor_max, cor[256], *pt_cor, temp; - Word16 wsp2[L_FRAME_PLUS+PIT_MAX_MAX+L_INTERPOL1]; + short i, t, t0, t1, step, fraction, t0_min, t0_max, t_min, t_max, delta; + float temp, cor_max, cor[256], *pt_cor; - - delta = 16; - move16(); - if ( sub(pitres, 6) == 0 ) + if ( pitres == 6 ) { delta = 8; - move16(); + } + else + { + delta = 16; } - t0_min = sub(pitch_ol, shr(delta, 1)); - t0_max = sub(add(t0_min, delta), 1); + t0_min = (short)pitch_ol - (delta>>1); + t0_max = (short)pitch_ol + (delta>>1) - 1; - IF ( sub(t0_min, pitmin) < 0 ) + if( t0_min < pitmin ) { t0_min = pitmin; - move16(); - t0_max = sub(add(t0_min, delta), 1); + t0_max = t0_min + delta - 1; } - - IF ( sub(t0_max, pitmax) > 0 ) + if( t0_max > pitmax ) { t0_max = pitmax; - move16(); - t0_min = add(sub(t0_max, delta), 1); + t0_min = t0_max - delta + 1; } - - t_min = sub(t0_min, L_INTERPOL1); - t_max = add(t0_max, L_INTERPOL1); - - /* normalize wsp */ - assert(len+t_max <= L_FRAME_PLUS+PIT_MAX_MAX+L_INTERPOL1); - s_wsp = getScaleFactor16(wsp - t_max, add(len, t_max)); - s_wsp = sub(s_wsp, 4); - FOR (t = negate(t_max); t < len; t++) - { - wsp2[t+t_max] = shl(wsp[t], s_wsp); - move16(); - } - wsp = wsp2 + t_max; + t_min = t0_min - L_INTERPOL1; + t_max = t0_max + L_INTERPOL1; pt_cor = cor; - - FOR ( t=t_min; t<=t_max; t++ ) + for ( t=t_min; t<=t_max; t++ ) { - *pt_cor = dot(wsp, wsp-t, len); - pt_cor++; + *pt_cor++ = dotp( wsp, wsp-t, len ); } pt_cor = cor + L_INTERPOL1; - cor_max = L_add(*pt_cor++, 0); + cor_max = *pt_cor++; t1 = t0_min; - move16(); - - FOR ( t = add(t0_min, 1); t <= t0_max; t++ ) + for ( t=t0_min+1; t<=t0_max; t++ ) { - IF ( *pt_cor > cor_max ) + if ( *pt_cor > cor_max ) { cor_max = *pt_cor; t1 = t; } pt_cor++; } - - temp = dot(wsp, wsp, len); - s = norm_l(temp); - temp_m = extract_h(L_shl(temp, s)); - temp_e = negate(s); - - temp = dot(wsp-t1, wsp-t1, len); - s = norm_l(temp); - temp_m = mult(temp_m, extract_h(L_shl(temp, s))); - temp_e = sub(temp_e, s); - - temp_m = Sqrt16(temp_m, &temp_e); - - if (temp_m == 0) - { - temp_m = 1; - move16(); - } - s = sub(norm_l(cor_max), 1); - temp_m = divide1616(extract_h(L_shl(cor_max, s)), temp_m); - temp_e = sub(negate(s), temp_e); - - BASOP_SATURATE_WARNING_OFF - *norm_corr = shl(temp_m, temp_e); - BASOP_SATURATE_WARNING_ON - - IF ( sub(t1, pitfr1) >= 0 ) + temp = dotp( wsp, wsp, len ) * dotp( wsp-t1, wsp-t1, len ); + *norm_corr = cor_max / (float)sqrt( temp + 0.1f ); + if ( t1 >= pitfr1 ) { *pitch_int = t1; - move16(); *pitch_fr = 0; - move16(); - - *index = add(sub(t1, pitfr1), extract_l(L_mac0(L_mult0(sub(pitfr2, pitmin), pitres), - sub(pitfr1, pitfr2), shr(pitres,1)))); - move16(); - + *index = t1 - pitfr1 + ((pitfr2-pitmin)*pitres) + ((pitfr1-pitfr2)*(pitres>>1)); return; } @@ -193,422 +122,300 @@ void tcx_ltp_pitch_search( * the interpolated normalized correlation. *-----------------------------------------------------------------*/ - pt_cor = cor + sub(L_INTERPOL1, t0_min); + pt_cor = cor + L_INTERPOL1 - t0_min; t0 = t1; - move16(); - - step = 1; - move16(); - if (sub(t0, pitfr2) >= 0) + if ( t0 >= pitfr2 ) { step = 2; - move16(); + fraction = 2; + } + else + { + step = 1; + fraction = 1; } - fraction = step; - move16(); - IF (sub(t0, t0_min) == 0) /* Limit case */ + if (t0 == t0_min) /* Limit case */ { fraction = 0; - move16(); cor_max = interpolate_corr( &pt_cor[t0], fraction, pitres ); } - ELSE /* Process negative fractions */ + else /* Process negative fractions */ { - t0 = sub(t0, 1); + t0--; cor_max = interpolate_corr( &pt_cor[t0], fraction, pitres ); - - FOR ( i = add(fraction, step); i < pitres; i += step ) + for ( i=(fraction+step); i<=pitres-1; i=i+step ) { temp = interpolate_corr( &pt_cor[t0], i, pitres ); - - IF (L_sub(temp, cor_max) > 0) + if (temp > cor_max) { - cor_max = L_add(temp, 0); + cor_max = temp; fraction = i; - move16(); } } } - i = 0; - FOR ( i = 0; i < pitres; i += step ) /* Process positive fractions */ + for ( i=0; i<=pitres-1; i=i+step ) /* Process positive fractions */ { temp = interpolate_corr( &pt_cor[t1], i, pitres ); - - IF (L_sub(temp, cor_max) > 0) + if (temp > cor_max) { - cor_max = L_add(temp, 0); + cor_max = temp; fraction = i; - move16(); t0 = t1; - move16(); } } - *pitch_int = t0; - move16(); *pitch_fr = fraction; - move16(); + if ( t0 >= pitfr2 ) + { + *index = t0*(pitres>>1) + (fraction>>1) - (pitfr2*(pitres>>1)) + ((pitfr2-pitmin)*pitres); + } + else + { + *index = t0*pitres + fraction - (pitmin*pitres); + } - IF ( sub(t0, pitfr2) >= 0 ) - { - *index = add( extract_l(L_mac0(L_mult0(sub(t0, pitfr2), shr(pitres,1)), - sub(pitfr2, pitmin), pitres)), shr(fraction,1) ); - move16(); - } - ELSE - { - *index = add(imult1616(sub(t0, pitmin), pitres), fraction); - move16(); - } } - -static void tcx_ltp_find_gain( Word16 *speech, Word16 *pred_speech, Word16 L_frame, Word16 *gain, Word16 *gain_index ) +static void tcx_ltp_find_gain( float *speech, float *pred_speech, int L_frame, float *gain, int *gain_index ) { - Word32 corr, ener; - Word16 i, g, s1, s2, tmp; + int gainbits = 2; - - s1 = sub(getScaleFactor16(speech, L_frame), 4); - s2 = sub(getScaleFactor16(pred_speech, L_frame), 4); - /* Find gain */ - corr = L_deposit_l(0); - ener = L_deposit_l(1); - - FOR (i = 0; i < L_frame; i++) - { - tmp = shl(pred_speech[i], s2); - corr = L_mac0(corr, shl(speech[i], s1), tmp); - ener = L_mac0(ener, tmp, tmp); - } - - s1 = sub(1, add(s1, s2)); - s2 = sub(1, shl(s2, 1)); - - tmp = sub(norm_l(corr), 1); - corr = L_shl(corr, tmp); - s1 = sub(s1, tmp); - - tmp = norm_l(ener); - ener = L_shl(ener, tmp); - s2 = sub(s2, tmp); - - g = divide1616(round_fx(corr), round_fx(ener)); - BASOP_SATURATE_WARNING_OFF - g = shl(g, sub(s1, s2)); - BASOP_SATURATE_WARNING_ON + *gain = get_gain( speech, pred_speech, L_frame, NULL); /* Quantize gain */ - g = shr(sub(g, 0x1000), 13); - g = s_max(g, -1); - - *gain_index = g; - move16(); - + if (*gain >= 0.875f) + { + *gain_index = 3; /* 1.00/2 */ + } + else if (*gain >= 0.625f) + { + *gain_index = 2; /* 0.75/2 */ + } + else if (*gain >= 0.375f) + { + *gain_index = 1; /* 0.50/2 */ + } + else if (*gain >= 0.125f) + { + *gain_index = 0; /* 0.25/2 */ + } + else + { + *gain_index = -1; /* escape */ + } /* Dequantize gain */ - *gain = imult1616(add(g, 1), 0x1400); - move16(); - + *gain = (float)(*gain_index + 1) * 0.625f/(float)(1< 0 && - sub(tempFlatness, 448/*3.5f Q7*/) < 0 - ) || - ( - tcxOnly != 0 && - sub(tcxMode, TCX_10) == 0 && - sub(s_max(norm_corr, *norm_corr_past), 0x4000) > 0 && - sub(maxEnergyChange, 448/*3.5f Q7*/) < 0 - ) || - ( /* Use LTP for lower correlation when pitch lag is big, L_frame*(1.2f-norm_corr) < pitch_int <=> norm_corr > 1.2f-pitch_int/L_frame */ - tcxOnly != 0 && - sub(norm_corr, 14418/*0.44f Q15*/) > 0 && - L_msu(L_mult(L_frame, sub(19661/*1.2f Q14*/, shr(norm_corr, 1))), *pitch_int, 1<<14) < 0 /* L_frame*(1.2f-norm_corr) < pitch_int */ - ) || - ( - tcxOnly != 0 && - sub(tcxMode, TCX_20) == 0 && - sub(norm_corr, 14418/*0.44f Q15*/) > 0 && - ( - sub(tempFlatness, 768/*6.0f Q7*/) < 0 || - ( - sub(tempFlatness, 896/*7.0f Q7*/) < 0 && - sub(maxEnergyChange, 2816/*22.0f Q7*/) < 0 - ) - ) - ) - ) + if ( ( tcxOnly == 0 && tcxMode == TCX_20 && norm_corr **norm_corr_past > 0.25f && tempFlatness < 3.5f ) || + ( tcxOnly == 1 && tcxMode == TCX_10 && max(norm_corr, *norm_corr_past) > 0.5f && maxEnergyChange < 3.5f ) || + /* Use LTP for lower correlation when pitch lag is big, L_frame*(1.2f-norm_corr) < *pitch_int <=> norm_corr > 1.2f-*pitch_int/L_frame */ + ( tcxOnly == 1 && norm_corr > 0.44f && L_frameTCX*(1.2f-norm_corr) < *pitch_int) || + ( tcxOnly == 1 && tcxMode == TCX_20 && norm_corr > 0.44f && (tempFlatness < 6.0f || (tempFlatness < 7.0f && maxEnergyChange < 22.0f)) ) ) { - ltp_param[0] = 1; - move16(); + { + ltp_param[0] = 1; + } } - BASOP_SATURATE_WARNING_ON; } - - IF (ltp_param[0] != 0) + if ( ltp_param[0] ) { /* Find predicted signal */ - predict_signal( speech, pred_speech, *pitch_int, *pitch_fr, pitres, L_frame ); + predict_signal( speech, pred_speech, *pitch_int, *pitch_fr, pitres, L_frameTCX ); /* Find gain */ - tcx_ltp_find_gain( speech, pred_speech, L_frame, gain, <p_param[2] ); + tcx_ltp_find_gain( speech, pred_speech, L_frameTCX, gain, <p_param[2] ); /* Total number of bits for LTP */ - IF (add(ltp_param[2], 1) != 0) /* gain > 0 */ + if (ltp_param[2] + 1) /* gain > 0 */ { *ltp_bits = 12; - move16(); } - ELSE /* gain <= 0 -> turn off LTP */ + else /* gain <= 0 -> turn off LTP */ { ltp_param[0] = 0; - move16(); } } - - IF (ltp_param[0] == 0) + if (!ltp_param[0]) { /* No LTP -> set everything to zero */ - *pitch_int = L_frame; - move16(); + *pitch_int = L_frameTCX; *pitch_fr = 0; - move16(); ltp_param[1] = 0; - move16(); - set16_fx( pred_speech, 0, L_frame ); - *gain = 0; - move16(); + set_zero( pred_speech, L_frameTCX ); + *gain = 0.f; ltp_param[2] = 0; - move16(); - - *ltp_bits = 0; - move16(); - test(); - if (tcxltp_on != 0 || SideInfoOnly != 0) + if ( tcxltp_on || SideInfoOnly) { *ltp_bits = 1; - move16(); + } + else + { + *ltp_bits = 0; } } - if (SideInfoOnly != 0) + if (SideInfoOnly) { - *gain = 0; - move16(); + *gain = 0.f; } - test(); - IF (*gain_past == 0 && *gain == 0) + if ( *gain_past==0.f && *gain==0.f ) { - Copy(speech, speech_ltp, L_subfr); + mvr2r( speech, speech_ltp, L_subfr ); } - ELSE IF (*gain_past == 0) + else if ( *gain_past==0.f ) { - alpha = 0; - move16(); - - /* step = 1.f/(float)(L_subfr); */ - step = shl(2, norm_s(L_subfr)); - if (s_and(L_subfr, sub(L_subfr, 1)) != 0) + alpha = 0.f; + step = 1.f/(float)(L_subfr); + for ( n=0; n 0) + if ( *gain>0.f ) { - predict_signal(speech-lpcorder, buf_zir, *pitch_int, *pitch_fr, pitres, lpcorder); + predict_signal( speech-lpcorder, buf_zir, *pitch_int, *pitch_fr, pitres, lpcorder ); } - ELSE { - set16_fx(buf_zir, 0, lpcorder); - } - - FOR (n = 0; n < lpcorder; n++) + else { - buf_zir[n] = add(sub(speech_ltp[n-lpcorder], speech[n-lpcorder]), mult_r(*gain, buf_zir[n])); - move16(); + set_f( buf_zir, 0.0f, lpcorder ); + } + for ( n=0; n #include +#include #include -#include "stl.h" #include "options.h" -#include "prot_fx.h" -#include "rom_basop_util.h" -#include "basop_util.h" -#include "cnst_fx.h" +#include "prot.h" +#include "rom_com.h" +#include "cnst.h" -#define inv_int InvIntTable -extern const Word16 int_sqr[17]; -static Word16 quantize(Word32 x, Word16 invGain, Word16 shift, Word32 offset) -{ - Word16 tmp16; - Word32 tmp32; - - tmp32 = Mpy_32_16_1(L_abs(x), invGain); /* multiply */ - tmp32 = L_shl(tmp32, shift); /* convert to 15Q16 */ - tmp32 = L_add(tmp32, offset); /* add offset */ - tmp16 = extract_h(tmp32); /* truncate */ - if (x < 0) tmp16 = negate(tmp16); /* restore sign */ - - return tmp16; -} /* compute noise-measure flags for spectrum filling and quantization (0: tonal, 1: noise-like) */ -void ComputeSpectrumNoiseMeasure(const Word32 *powerSpec, - Word16 L_frame, - Word16 startLine, - Word8 resetMemory, - Word8 *noiseFlags, - Word16 lowpassLine) +static void ComputeSpectrumNoiseMeasure( + const float *powerSpec, + int L_frame, + int startLine, + int resetMemory, + int *noiseFlags, + int lowpassLine +) { - Word16 i, lastTone; - Word32 s, c; - Word16 tmp16; - Word32 tmp1, tmp2 = 0; /* initialization only to avoid compiler warning, not counted */ - - - IF (resetMemory != 0) + int i, lastTone; + float s; + if (resetMemory) { - FOR (i = 0; i < lowpassLine; i++) + for (i = 0; i < lowpassLine; i++) { noiseFlags[i] = 0; - move16(); } } - - FOR (i = lowpassLine; i < L_frame; i++) + for (i = lowpassLine; i < L_frame; i++) { noiseFlags[i] = 1; - move16(); } - - test(); - IF (powerSpec != NULL && sub(add(startLine, 6), L_frame) < 0) + if (powerSpec && startLine+6= 0) + float c = powerSpec[i-1] + powerSpec[i] + powerSpec[i+1]; /**/ + s += powerSpec[i+7] - powerSpec[i-8]; + if (s >= (1.75f - 0.5f * noiseFlags[i]) * c) { noiseFlags[i] = 1; - move16(); } - if (tmp2 < 0) + else { noiseFlags[i] = 0; - move16(); - } - if (tmp2 < 0) - { lastTone = i; - move16(); } } - /* lower L_frame*startRatio lines are tonal (0), upper 7 lines are processed separately */ - tmp16 = sub(lowpassLine, 1); - FOR (; i < tmp16; i++) + for (; i < lowpassLine - 1; i++) { - c = L_shr(powerSpec[i-1], 4); - c = L_add(c, L_shr(powerSpec[i], 4)); - c = L_add(c, L_shr(powerSpec[i+1], 4)); - - tmp1 = L_shr(c, 2); - if (noiseFlags[i] == 0) c = L_shl(c, 1); - if (noiseFlags[i] == 0) tmp2 = L_sub(c, tmp1); /* 1.75 * c */ - if (noiseFlags[i] != 0) tmp2 = L_add(c, tmp1); /* 1.25 * c */ - + float c = powerSpec[i-1] + powerSpec[i] + powerSpec[i+1]; /**/ /* running sum can't be updated any more, just use the latest one */ - tmp2 = L_sub(s, tmp2); - if (tmp2 >= 0) + if (s >= (1.75f - 0.5f * noiseFlags[i]) * c) { noiseFlags[i] = 1; - move16(); } - if (tmp2 < 0) + else { noiseFlags[i] = 0; - move16(); /* lastTone = i; */ } } - noiseFlags[i] = 1; /* uppermost line is defined as noise-like (1) */ move16(); + noiseFlags[i] = 1; /* uppermost line is defined as noise-like (1) */ if (lastTone > 0) /* spread uppermost tonal line one line upward */ { noiseFlags[lastTone+1] = 0; - move16(); } } - } -void detectLowpassFac(const Word32 *powerSpec, Word16 powerSpec_e, Word16 L_frame, Word8 rectWin, Word16 *pLpFac, Word16 lowpassLine) +static void detectLowpassFac(const float *powerSpec, int L_frame, int rectWin, float *pLpFac, int lowpassLine) { - Word16 i, tmp; - Word32 threshold; + int i; + float threshold; - - threshold = 256l/*0.1f * 2*NORM_MDCT_FACTOR Q3*/; /* Q3 */ - BASOP_SATURATE_WARNING_OFF /* Allow saturation, because threshold is being compared to powerSpec[i] below. */ - threshold = L_shl(threshold, sub(28, powerSpec_e)); - - if (rectWin != 0) + threshold = 0.1f * 2*NORM_MDCT_FACTOR; + if (rectWin) { /* compensate for bad side-lobe attenuation with asymmetric windows */ - threshold = L_shl(threshold, 1); + threshold *= 2.f; } - BASOP_SATURATE_WARNING_ON - - tmp = shr(lowpassLine, 1); - FOR (i = sub(lowpassLine, 1); i >= tmp; i--) + for (i = lowpassLine-1; i >= lowpassLine/2; i--) { - IF (L_sub(powerSpec[i], threshold) > 0) + if (powerSpec[i] > threshold) { - BREAK; + break; } } - - tmp = getInvFrameLen(L_frame); - - tmp = mult_r(22938/*0.7f Q15*/, round_fx(L_shl(L_mult0(add(i, 1), tmp), 9))); - *pLpFac = add(tmp, mult_r(9830/*0.3f Q15*/, *pLpFac)); - move16(); - + *pLpFac = + (0.3f * (*pLpFac)) + + (0.7f * ((float) (i+1) / (float) L_frame)); } /*-----------------------------------------------------------* @@ -195,1746 +113,1106 @@ void detectLowpassFac(const Word32 *powerSpec, Word16 powerSpec_e, Word16 L_fram * Detect low pass if present. * *-----------------------------------------------------------*/ void AnalyzePowerSpectrum( - Encoder_State_fx *st, /* i/o: encoder states */ - Word16 L_frame, /* input: frame length */ - Word16 L_frameTCX, /* input: full band frame length */ - Word16 left_overlap, /* input: left overlap length */ - Word16 right_overlap, /* input: right overlap length */ - Word32 const mdctSpectrum[], /* input: MDCT spectrum */ - Word16 mdctSpectrum_e, - Word16 const signal[], /* input: windowed signal corresponding to mdctSpectrum */ - Word32 powerSpec[], /* output: Power spectrum. Can point to signal */ - Word16 *powerSpec_e + Encoder_State *st, /* i/o: encoder states */ + int L_frame, /* input: frame length */ + int L_frameTCX, /* input: full band frame length */ + int left_overlap, /* input: left overlap length */ + int right_overlap, /* input: right overlap length */ + float const mdctSpectrum[], /* input: MDCT spectrum */ + float const signal[], /* input: windowed signal corresponding to mdctSpectrum */ + float powerSpec[] /* output: Power spectrum. Can point to signal */ ) { - Word16 i, iStart, iEnd, lowpassLine; - Word16 tmp, s1, s2; - Word32 tmp32; - Word8 tmp8; + int i, iStart, iEnd, lowpassLine; lowpassLine = L_frameTCX; - move16(); - - *powerSpec_e = 16; - move16(); - TCX_MDST(signal, - powerSpec, - powerSpec_e, - left_overlap, - sub(L_frameTCX, shr(add(left_overlap, right_overlap), 1)), - right_overlap); - + { + TCX_MDST(signal, powerSpec, left_overlap, L_frameTCX-(left_overlap+right_overlap)/2, right_overlap); + } iStart = 0; - move16(); iEnd = L_frameTCX; - move16(); - IF (st->narrowBand != 0) + if(st->narrowBand) { attenuateNbSpectrum(L_frameTCX, powerSpec); } - /* get shift to common exponent */ - s1 = 0; - move16(); - s2 = 0; - move16(); - tmp = sub(mdctSpectrum_e, *powerSpec_e); - if (tmp > 0) - { - s2 = negate(tmp); - } - if (tmp < 0) - { - s1 = tmp; - move16(); - } - - /* get headroom */ - tmp = sub(getScaleFactor32(mdctSpectrum, L_frameTCX), s1); - tmp = s_min(tmp, sub(getScaleFactor32(powerSpec, L_frameTCX), s2)); - s1 = add(s1, tmp); - s2 = add(s2, tmp); - /* power spectrum: MDCT^2 + MDST^2 */ - FOR (i = iStart; i < iEnd; i++) + for (i = iStart; i < iEnd; i++) { - tmp = round_fx(L_shl(mdctSpectrum[i], s1)); - tmp32 = L_mult0(tmp, tmp); - - tmp = round_fx(L_shl(powerSpec[i], s2)); - tmp32 = L_mac0(tmp32, tmp, tmp); - - powerSpec[i] = tmp32; - move32(); + powerSpec[i] *= powerSpec[i]; + powerSpec[i] += mdctSpectrum[i] * mdctSpectrum[i]; } - - *powerSpec_e = add(shl(sub(mdctSpectrum_e, s1), 1), 1); - move16(); - - tmp8 = 0; - move16(); - test(); - if ( L_msu0(L_mult0(st->L_frame_fx, extract_l(st->last_sr_core)), st->L_frame_past, extract_l(st->sr_core)) != 0 - || sub(st->last_core_fx, TCX_20_CORE ) != 0 ) + ComputeSpectrumNoiseMeasure(powerSpec, L_frameTCX, st->nmStartLine*L_frame/st->L_frame, (st->L_frame*st->last_sr_core != st->L_frame_past*st->sr_core) || (st->last_core != TCX_20_CORE), st->memQuantZeros, lowpassLine); + if( st->total_brate <= ACELP_24k40 ) { - tmp8 = 1; - move16(); + lowpassLine = (int)(2.0f*st->tcx_cfg.bandwidth*L_frame); + detectLowpassFac(powerSpec, L_frame, (st->last_core == ACELP_CORE), &st->measuredBwRatio, lowpassLine); } - - ComputeSpectrumNoiseMeasure(powerSpec, - L_frameTCX, - divide3216(L_mult(st->nmStartLine, L_frame), st->L_frame_fx), - tmp8, - st->memQuantZeros, - lowpassLine); - - IF( L_sub(st->total_brate_fx, ACELP_24k40) <= 0 ) + else { - lowpassLine = shl(mult(st->tcx_cfg.bandwidth, L_frame), 1); - - test(); - detectLowpassFac(powerSpec, *powerSpec_e, - L_frame, - sub(st->last_core_fx, ACELP_CORE) == 0, - &st->measuredBwRatio, - lowpassLine); - } - ELSE - { - st->measuredBwRatio = 0x4000; - move16(); + st->measuredBwRatio = 1.0f; } } -void AdaptLowFreqEmph(Word32 x[], - Word16 x_e, - Word16 xq[], - Word16 invGain, - Word16 invGain_e, - Word16 tcx_lpc_shaped_ari, - Word16 lpcGains[], Word16 lpcGains_e[], - const Word16 lg +void mdct_preShaping(float x[], int lg, const float gains[]) +{ + int i, j, k, l; + float g; + int m, n, k1, k2; + + j = 0; /* not counted, is included in ptr init */ + /* FDNS_NPTS = 64 !!! */ + k = lg/FDNS_NPTS; + m = lg%FDNS_NPTS; + if (m) + { + if ( m <= (FDNS_NPTS/2) ) + { + n = FDNS_NPTS/m; + k1 = k; + k2 = k + 1; + } + else + { + n = FDNS_NPTS/(FDNS_NPTS-m); + k1 = k + 1; + k2 = k; + } + for (i=0; i= 0) && (tmp32 >= 0x3A000)) /* 0x3A000 -> 3.625 (15Q16) */ + if (((xq[i] <= -2) || (xq[i] >= 2)) && + ((invGain * x[i] <= -3.625f) || (invGain * x[i] >= 3.625f))) { - - /* Debug initialization to catch illegal cases of xq[i] */ - tmp16 = 0; - - if (xq[i] > 0) - { - tmp16 = 2; - move16(); - } - if (xq[i] < 0) - { - tmp16 = -2; - move16(); - } - - assert(tmp16 != 0); - - xq[i] = add(xq[i], tmp16); - move16(); - + xq[i] += (xq[i] < 0) ? -2 : 2; i_max = i; - move16(); - BREAK; + break; } } - - s = sub(add(x_e, invGain_e), 15); - /* 2. compress value range of all xq up to i_max: add two steps */ - FOR (i = 0; i < i_max; i++) + for (i = 0; i < i_max; i++) { - xq[i] = quantize(x[i], invGain, s, 0x6000); - move16(); + if (x[i] < 0.0f) + { + xq[i] = (int)(invGain * x[i] - 0.375f); + } + else + { + xq[i] = (int)(invGain * x[i] + 0.375f); + } } - /* 3. find first mag. maximum below i_max which is half as high */ i_max_old = i_max; - move16(); - - IF (i_max_old >= 0) + if (i_max_old > -1) { - invGain_e = add(invGain_e, 1); - i_max = -1; /* reset first maximum, update inverse gain */ move16(); - - FOR (i = 0; i < lg_4; i++) + invGain *= 2.0f; + i_max = -1; /* reset first maximum, update inverse gain */ + for (i = 0; i < lg/4; i++) { - tmp32 = Mpy_32_16_1(L_abs(x[i]), invGain); /* multiply */ - tmp32 = L_shl(tmp32, sub(add(x_e, invGain_e), 15)); /* convert to 15Q16 */ - - test(); - IF ((sub(abs_s(xq[i]), 2) >= 0) && (tmp32 >= 0x3A000)) /* 0x3A000 -> 3.625 (15Q16) */ + if (((xq[i] <= -2) || (xq[i] >= 2)) && + ((invGain * x[i] <= -3.625f) || (invGain * x[i] >= 3.625f))) { - - /* Debug initialization to catch illegal cases of xq[i] */ - tmp16 = 0; - - if (xq[i] > 0) - { - tmp16 = 2; - move16(); - } - if (xq[i] < 0) - { - tmp16 = -2; - move16(); - } - - assert(tmp16 != 0); - - xq[i] = add(xq[i], tmp16); - move16(); - + xq[i] += (xq[i] < 0) ? -2 : 2; i_max = i; - move16(); - BREAK; + break; } } } - - s = sub(add(x_e, invGain_e), 15); - /* 4. re-compress and quantize all xq up to half-height i_max+1 */ - FOR (i = 0; i < i_max; i++) + for (i = 0; i < i_max; i++) { - xq[i] = quantize(x[i], invGain, s, 0x6000); - move16(); + if (x[i] < 0.0f) + { + xq[i] = (int)(invGain * x[i] - 0.375f); + } + else + { + xq[i] = (int)(invGain * x[i] + 0.375f); + } } - /* 5. always compress 2 lines; lines could be at index 0 and 1! */ - IF (i_max_old >= 0) + if (i_max_old > -1) { - invGain_e = sub(invGain_e, 1); /* reset inverse gain */ - if (sub(i_max, i_max_old) < 0) + invGain *= 0.5f; /* reset inverse gain */ + if (i_max < i_max_old) { i_max = i_max_old; - move16(); } } - - i = add(i_max, 1); - - tmp32 = Mpy_32_16_1(L_abs(x[i]), invGain); /* multiply */ - tmp32 = L_shl(tmp32, sub(add(x_e, invGain_e), 15)); /* convert to 15Q16 */ - IF (L_sub(tmp32, 0x3A000) >= 0) + i = i_max + 1; + if (x[i] < 0.0f) { - - /* Debug initialization to catch illegal cases of xq[i] */ - tmp16 = 0; - - if (xq[i] > 0) - { - tmp16 = 2; - move16(); - } - if (xq[i] < 0) - { - tmp16 = -2; - move16(); - } - - assert(tmp16 != 0); - - xq[i] = add(xq[i], tmp16); - move16(); + xq[i] = (invGain * x[i] <= -3.625f) ? xq[i] - 2 : (int)(invGain * x[i] - 0.375f); } - ELSE + else { - xq[i] = quantize(x[i], invGain, sub(add(x_e, invGain_e), 15), 0x6000); - move16(); + xq[i] = (invGain * x[i] >= 3.625f) ? xq[i] + 2 : (int)(invGain * x[i] + 0.375f); } - - i = add(i, 1); - - tmp32 = Mpy_32_16_1(L_abs(x[i]), invGain); /* multiply */ - tmp32 = L_shl(tmp32, sub(add(x_e, invGain_e), 15)); /* convert to 15Q16 */ - IF (L_sub(tmp32, 0x3A000) >= 0) + i++; + if (x[i] < 0.0f) { - - /* Debug initialization to catch illegal cases of xq[i] */ - tmp16 = 0; - - if (xq[i] > 0) - { - tmp16 = 2; - move16(); - } - if (xq[i] < 0) - { - tmp16 = -2; - move16(); - } - - assert(tmp16 != 0); - - xq[i] = add(xq[i], tmp16); - move16(); + xq[i] = (invGain * x[i] <= -3.625f) ? xq[i] - 2 : (int)(invGain * x[i] - 0.375f); } - ELSE + else { - xq[i] = quantize(x[i], invGain, sub(add(x_e, invGain_e), 15), 0x6000); - move16(); + xq[i] = (invGain * x[i] >= 3.625f) ? xq[i] + 2 : (int)(invGain * x[i] + 0.375f); } - - } - ELSE /*if(!tcx_lpc_shaped_ari)*/ + else /*if(!tcx_lpc_shaped_ari)*/ { - PsychAdaptLowFreqEmph(x, lpcGains, lpcGains_e); + PsychAdaptLowFreqEmph(x, lpcGains); }/*if(!tcx_lpc_shaped_ari)*/ - } -void PsychAdaptLowFreqEmph(Word32 x[], - const Word16 lpcGains[], const Word16 lpcGains_e[] +void PsychAdaptLowFreqEmph(float x[], + const float lpcGains[] ) { - Word16 i; - Word16 max, max_e, fac, min, min_e, tmp, tmp_e; - Word32 L_tmp; + int i; + float max, fac, tmp; + max = tmp = lpcGains[0]; - - - assert(lpcGains[0] >= 0x4000); - - max = lpcGains[0]; - move16(); - max_e = lpcGains_e[0]; - move16(); - min = lpcGains[0]; - move16(); - min_e = lpcGains_e[0]; - move16(); - - /* find minimum (min) and maximum (max) of LPC gains in low frequencies */ - FOR (i = 1; i < 9; i++) + /* find minimum (tmp) and maximum (max) of LPC gains in low frequencies */ + for (i = 1; i < 9; i++) { - IF (compMantExp16Unorm(lpcGains[i], lpcGains_e[i], min, min_e) < 0) + if (tmp > lpcGains[i]) { - min = lpcGains[i]; - move16(); - min_e = lpcGains_e[i]; - move16(); + tmp = lpcGains[i]; } - - IF (compMantExp16Unorm(lpcGains[i], lpcGains_e[i], max, max_e) > 0) + if (max < lpcGains[i]) { max = lpcGains[i]; - move16(); - max_e = lpcGains_e[i]; - move16(); } } - - min_e = add(min_e, 5); /* min *= 32.0f; */ - - test(); - IF ((compMantExp16Unorm(max, max_e, min, min_e) < 0) && (max > 0)) + tmp *= 32.0f; + if ((max < tmp) && (max > FLT_MIN)) { - /* fac = tmp = (float)pow(min / max, 0.0078125f); */ - tmp_e = max_e; - move16(); - tmp = Inv16(max, &tmp_e); - L_tmp = L_shl(L_mult(tmp, min), sub(add(tmp_e, min_e), 6)); /* Q25 */ - L_tmp = L_add(BASOP_Util_Log2(L_tmp), 6<<25); /* Q25 */ - L_tmp = L_shr(L_tmp, 7); /* 0.0078125f = 1.f/(1<<7) */ - L_tmp = BASOP_Util_InvLog2(L_sub(L_tmp, 1<<25)); /* Q30 */ - tmp = round_fx(L_tmp); /* Q14 */ - fac = shr(tmp, 1); /* Q13 */ + fac = tmp = (float)pow(tmp / max, 0.0078125f); - /* gradual boosting of lowest 32 bins; DC is boosted by (min/max)^1/4 */ - FOR (i = 31; i >= 0; i--) + /* gradual boosting of lowest 32 bins; DC is boosted by (tmp/max)^1/4 */ + for (i = 31; i >= 0; i--) { - x[i] = L_shl(Mpy_32_16_1(x[i], fac), 2); - move32(); - fac = shl(mult_r(fac, tmp), 1); + x[i] *= fac; + fac *= tmp; } } } -Word16 SQ_gain( /* output: SQ gain */ - Word32 x[], /* input: vector to quantize */ - Word16 x_e, /* input: exponent */ - Word16 nbitsSQ, /* input: number of bits targeted */ - Word16 lg, /* input: vector size (2048 max) */ - Word16 *gain_e) /* output: SQ gain exponent */ +float SQ_gain( /* output: SQ gain */ + float x[], /* input: vector to quantize */ + int nbitsSQ, /* input: number of bits targeted */ + int lg) /* input: vector size (2048 max) */ { - Word16 i, iter, lg_4, s, tmp16; - Word32 ener, tmp32; - Word32 target, fac, offset; - Word32 en[N_MAX/4]; + int i, iter; + float ener, tmp, target, fac, offset; + float en[N_MAX/4]; - lg_4 = shr(lg, 2); - /* energy of quadruples with 9dB offset */ - FOR (i=0; i>2] = (float)log10(ener); /* saves a MAC */ } /* SQ scale: 4 bits / 6 dB per quadruple */ - target = L_mult(0x3FC8, sub(nbitsSQ, shr(lg, 4))); /* 0x3FC8 -> 0.15*log2(10) */ - fac = L_add(0x2A854B, 0); /* -> 12.8f*log2(10); */ - offset = L_add(fac, 0); + target = 0.15f * (float)(nbitsSQ - (lg>>4)); + fac = 12.8f; + offset = fac; /* find offset (0 to 128 dB with step of 0.125dB) */ - FOR (iter=0; iter<10; iter++) + for (iter=0; iter<10; iter++) { - fac = L_shr(fac, 1); - offset = L_sub(offset, fac); - ener = L_deposit_l(0); + fac *= 0.5f; + offset -= fac; + ener = 0.0f; - FOR (i=0; i 0) /* 0xFF20 -> 0.3*log2(10); */ + if (tmp > 0.3f) { - ener = L_add(ener, tmp32); - } + ener += tmp; - /* if ener is above target -> break and increase offset */ - IF (L_sub(ener, target) > 0) - { - offset = L_add(offset, fac); - BREAK; + /* if ener is above target -> break and increase offset */ + if (ener > target) + { + offset += fac; + break; + } } } } - offset = L_add(L_shr(offset, 1), 0x17EB0); /* 0x17EB0 -> 0.45*log2(10) */ - - *gain_e = add(extract_h(offset), 1); - move16(); - offset = L_sub(L_and(offset, 0xFFFF), 0x10000); - tmp16 = extract_h(BASOP_Util_InvLog2(L_shl(offset, 9))); - /* return gain */ - return tmp16; + + return (float)pow(10.0f, 0.45f + 0.5f*offset); } void tcx_scalar_quantization( - Word32 *x, /* i: input coefficients */ - Word16 x_e, /* i: exponent */ - Word16 *xq, /* o: quantized coefficients */ - Word16 L_frame, /* i: frame length */ - Word16 gain, /* i: quantization gain */ - Word16 gain_e, /* i: quantization gain exponent */ - Word16 offset, /* i: rounding offset (deadzone) */ - Word8 const *memQuantZeros, /* i: coefficients to be set to 0 */ - const Word16 alfe_flag + float *x, /* i: input coefficients */ + int *xq, /* o: quantized coefficients */ + int L_frame, /* i: frame length */ + float gain, /* i: quantization gain */ + float offset, /* i: rounding offset (deadzone) */ + int *memQuantZeros, /* o: coefficients set to 0 */ + const int alfe_flag ) { - Word16 i, tmp16, s; - Word32 tmp32, offs32; + int i; + float gainInv, rounding, rounding2; - /* common exponent for x and gain for comparison */ - tmp16 = sub(gain_e, x_e); - tmp32 = L_shl(L_deposit_h(gain), s_max(-31, s_min(tmp16, 0))); - tmp16 = negate(s_max(tmp16, 0)); + /* Init scalar quantizer */ + gainInv = 1.0f/gain; + rounding = offset; + rounding2 = -offset; - i = sub(L_frame, 1); - WHILE ((memQuantZeros[i] != 0) && (L_sub(L_abs(L_shl(x[i], tmp16)), tmp32) < 0)) + for (i = L_frame - 1; (memQuantZeros[i]) && ((float)fabs(x[i]) * gainInv < 1.0f); i--) { - test(); xq[i] = 0; - move16(); - i = sub(i, 1); } - - /* invert gain */ - gain = Inv16(gain, &gain_e); - - s = sub(add(x_e, gain_e), 15); - - /*It should almost never happen and if so the quantization will be discarded later on (saturation of gain Quantizer).*/ - IF( sub(s,31) > 0 ) + for (; i >= 0; i--) { - /* Limit the inverse gain to maximal possible value=sqrtL_spec/NORM_MDCT_FACTOR)*/ - gain = 22435; /*sqrt(1200/NORM_MDCT_FACTOR) in 2Q13*/ - gain_e = 2; - - s = sub(add(x_e, gain_e), 15); + if (x[i]>0.f) + { + xq[i] = ((int) (rounding + x[i]*gainInv)); + } + else + { + xq[i] = ((int) (rounding2 + x[i]*gainInv)); + } } - /* substract 0x8000 to affect the mac_r in the following loop - so it acts like extract_h. the 0x4000 will be multiplied by 2 - by the mac_r to get to 0x8000 and disable the round. */ - offset = sub(offset, 0x4000); - - FOR (; i >= 0; i--) + /* don't instrument; BASOP code restricts to 16 bit by using 16 bit operators only*/ + for(i=0; i 0) + if(tcxRateLoopOpt >= 1) { stopFlag = 0; - move16(); + } + else + { + stopFlag = 1; } sqBits = ACcontextMapping_encode2_estimate_no_mem_s17_LC( xq, L_frame, &lastnz, - nEncoded, target, &stopFlag, - hm_cfg - ); + nEncoded, target, &stopFlag, hm_cfg); - IF ( tcxRateLoopOpt > 0 ) + if( tcxRateLoopOpt >= 1 ) { - test(); - test(); - test(); - test(); - test(); - test(); - IF ( ((sub(*nEncoded, old_nEncoded) >= 0) && (sub(stopFlag, old_stopFlag) >= 0)) || - ((sub(*nEncoded, old_nEncoded) > 0) && ((stopFlag == 0) && (old_stopFlag > 0))) || - ((stopFlag == 0) && (old_stopFlag == 0)) ) + if((*nEncoded>=old_nEncoded && (stopFlag>=old_stopFlag)) || (*nEncoded>old_nEncoded && (stopFlag==0 && old_stopFlag>0)) || (stopFlag==0 && old_stopFlag==0)) { *gain = sqGain; - move16(); - *gain_e = sqGain_e; - move16(); - old_nEncoded = *nEncoded; - move16(); - old_stopFlag = stopFlag; - move16(); + old_nEncoded=*nEncoded; + old_stopFlag=stopFlag; old_sqBits = sqBits; - move16(); *lastnz_out = lastnz; - move16(); } } } /* for ( iter=0 ; iter 0 ) + if( tcxRateLoopOpt >= 1 ) { /* Quantize spectrum */ - tcx_scalar_quantization( x, x_e, xq, L_frame, *gain, *gain_e, offset, memQuantZeros, tcxonly ); + tcx_scalar_quantization( x, xq, L_frame, *gain, offset, memQuantZeros, tcxonly ); /* Output */ *nEncoded = old_nEncoded; - move16(); sqBits = old_sqBits; - move16(); *stop = old_stopFlag; - move16(); } - ELSE + else { /* Output */ *gain = sqGain; - move16(); - *gain_e = sqGain_e; - move16(); *stop = stopFlag; - move16(); *lastnz_out = lastnz; - move16(); } + return sqBits; } -void QuantizeGain(Word16 n, Word16 *pGain, Word16 *pGain_e, Word16 *pQuantizedGain) +void QuantizeGain(int n, float * pGain, int * pQuantizedGain) { - Word16 ener, ener_e, enerInv, enerInv_e, gain, gain_e; - Word16 quantizedGain; - Word32 tmp32; + float ener, gain; + int quantizedGain; + ener = (float)sqrt((float)n / (float)NORM_MDCT_FACTOR); - ener = mult_r(shl(n, 5), 26214/*128.f/NORM_MDCT_FACTOR Q15*/); - ener_e = 15-5-7; - move16(); - IF( n >= 1024 ) - { - /*reduce precision for avoiding overflow*/ - ener = mult_r(shl(n, 4), 26214/*128.f/NORM_MDCT_FACTOR Q15*/); - ener_e = 15-4-7; - } - BASOP_Util_Sqrt_InvSqrt_MantExp(ener, ener_e, &ener, &ener_e, &enerInv, &enerInv_e); - - gain = mult(*pGain, ener); - gain_e = *pGain_e + ener_e; + gain = *pGain * ener; assert(gain > 0); /* quantize gain with step of 0.714 dB */ - quantizedGain = add(round_fx(BASOP_Util_Log2(L_deposit_h(gain))), shl(gain_e, 9)); /* 6Q9 */ - quantizedGain = mult(quantizedGain, 0x436E); /* 10Q5; 0x436E -> 28/log2(10) (4Q11) */ - quantizedGain = shr(add(quantizedGain, 0x10), 5); /* round */ + quantizedGain = (int)floor(0.5f + 28.0f * (float)log10(gain)); if (quantizedGain < 0) { quantizedGain = 0; - move16(); } - if (quantizedGain > 127) { quantizedGain = 127; - move16(); } *pQuantizedGain = quantizedGain; - move16(); - - tmp32 = L_shl(L_mult0(quantizedGain, 0x797D), 7); /* 6Q25; 0x797D -> log2(10)/28 (Q18) */ - gain_e = add(extract_l(L_shr(tmp32, 25)), 1); /* get exponent */ - gain = round_fx(BASOP_Util_InvLog2(L_or(tmp32, 0xFE000000))); - - *pGain = mult(gain, enerInv); - move16(); - *pGain_e = add(gain_e, enerInv_e); - move16(); - + *pGain = (float)pow(10.0f, ((float)quantizedGain)/28.0f) / ener; } void tcx_noise_factor( - Word32 *x_orig, /* i: unquantized mdct coefficients */ - Word16 x_orig_e, /* i: exponent */ - Word32 *sqQ, /* i: quantized mdct coefficients */ - Word16 iFirstLine, /* i: first coefficient to be considered */ - Word16 lowpassLine, /* i: last nonzero coefficients after low-pass */ - Word16 nTransWidth, /* i: minimum size of hole to be checked */ - Word16 L_frame, /* i: frame length */ - Word16 gain_tcx, /* i: tcx gain */ - Word16 gain_tcx_e, /* i: gain exponent */ - Word16 tiltCompFactor, /* i: LPC tilt compensation factor */ - Word16 *fac_ns, /* o: noise factor */ - Word16 *quantized_fac_ns/* o: quantized noise factor */ + float *x_orig, /* i: unquantized mdct coefficients */ + float *sqQ, /* i: quantized mdct coefficients */ + int iFirstLine, /* i: first coefficient to be considered */ + int lowpassLine, /* i: last nonzero coefficients after low-pass */ + int nTransWidth, /* i: minimum size of hole to be checked */ + int L_frame, /* i: frame length */ + float gain_tcx, /* i: tcx gain */ + float tiltCompFactor, /* i: LPC tilt compensation factor */ + float *fac_ns, /* o: noise factor */ + int *quantized_fac_ns /* o: quantized noise factor */ ) { - Word16 i, k, maxK, segmentOffset; - Word32 sqErrorNrg, n; - Word16 inv_gain2, inv_gain2_e, tilt_factor, nTransWidth_1; - Word32 accu1, accu2, tmp32; - Word16 tmp1, tmp2, s; - Word16 c1, c2; - Word16 att; /* noise level attenuation factor for transient windows */ - Word32 xMax; + int i, k, win, segmentOffset; + float inv_gain2, sqErrorNrg, n, tilt_factor, tmp; + float att; /* noise level attenuation factor for transient windows */ - assert(nTransWidth <= 16); - - c1 = sub(shl(nTransWidth, 1), 4); - c2 = mult(9216/*0.28125f Q15*/, inv_int[nTransWidth]); - nTransWidth_1 = sub(nTransWidth, 1); - /*Adjust noise filling level*/ - sqErrorNrg = L_deposit_l(0); - n = L_deposit_l(0); - - /* get inverse frame length */ - tmp1 = getInvFrameLen(L_frame); - - /* tilt_factor = 1.0f /(float)pow(max(0.375f, tiltCompFactor), 1.0f/(float)L_frame); */ - tmp32 = BASOP_Util_Log2(L_deposit_h(s_max(0x3000, tiltCompFactor))); /* 6Q25 */ - tmp32 = L_shr(Mpy_32_16_1(tmp32, negate(tmp1)), 6); - tilt_factor = round_fx(BASOP_Util_InvLog2(L_sub(tmp32, 0x2000000))); /* 1Q14 */ - - /* inv_gain2 = 1.0f / ((float)(nTransWidth * nTransWidth) * gain_tcx); */ - tmp32 = L_mult(imult1616(nTransWidth, nTransWidth), gain_tcx); /* 15Q16 */ - tmp1 = norm_l(tmp32); - inv_gain2 = round_fx(L_shl(tmp32, tmp1)); - inv_gain2_e = add(sub(15, tmp1), gain_tcx_e); - inv_gain2 = Inv16(inv_gain2, &inv_gain2_e); - inv_gain2 = shr(inv_gain2, 2); /* 2 bits headroom */ - inv_gain2_e = add(inv_gain2_e, 2); + sqErrorNrg = 0.0f; + n = 0.0f; + /* max() */ + tilt_factor = 1.0f /(float)pow(max(0.375f, tiltCompFactor), 1.0f/(float)L_frame); /* 1/(a^b) = a^-b */ + inv_gain2 = 1.0f / ((float)(nTransWidth * nTransWidth) * gain_tcx); /* find last nonzero line below iFirstLine, use it as start offset */ - tmp1 = shr(iFirstLine, 1); - FOR (i = iFirstLine; i > tmp1; i--) + for (i = iFirstLine; i > iFirstLine/2; i--) { - IF (sqQ[i] != 0) + if (sqQ[i] != 0.0f) { - BREAK; + break; } } - /* inv_gain2 *= (float)pow(tilt_factor, (float)i); */ - FOR (k = 0; k < i; k++) - { - inv_gain2 = shl(mult(inv_gain2, tilt_factor), 1); - } + inv_gain2 *= (float)pow(tilt_factor, (float)i); - /* initialize left (k) and right (maxK) non-zero neighbor pointers */ - k = 0; - move16(); - FOR (maxK = 1; maxK < nTransWidth; maxK++) + segmentOffset = ++i; + if (nTransWidth <= 3) { - IF (sqQ[i+maxK] != 0) + att = tmp = FLT_MIN; + for (k = i & 0xFFFE; k < lowpassLine; k++) { - BREAK; + att += x_orig[k] * x_orig[k]; /* even-index bins, left sub-win */ + k++; + tmp += x_orig[k] * x_orig[k]; /* odd-index bins, right sub-win */ } + att = (float)sqrt((min(att, tmp)*2.0f) / (att + tmp)); } - i = add(i, 1); - segmentOffset = i; - move16(); - - IF (sub(nTransWidth, 3) <= 0) + else { - accu1 = L_deposit_l(0); - accu2 = L_deposit_l(0); - xMax = L_deposit_l(0); - - FOR (k = s_and(i, (Word16)0xFFFE); k < lowpassLine; k++) - { - xMax = L_max(xMax, L_abs(x_orig[k])); - } - s = sub(norm_l(xMax), 4); - - FOR (k = s_and(i, (Word16)0xFFFE); k < lowpassLine; k += 2) - { - /* even-index bins, left sub-win */ - tmp1 = round_fx(L_shl(x_orig[k], s)); - accu1 = L_mac0(accu1, tmp1, tmp1); - - /* odd-index bins, right sub-win */ - tmp1 = round_fx(L_shl(x_orig[k+1], s)); - accu2 = L_mac0(accu2, tmp1, tmp1); - } - k = 0; - move16(); - - if (accu1 == 0) accu1 = L_deposit_l(1); - if (accu2 == 0) accu2 = L_deposit_l(1); - - att = BASOP_Util_Divide3232_Scale( L_shl(L_min(accu1, accu2), 1), L_add(accu1, accu2), &s ); - att = Sqrt16(att, &s); - BASOP_SATURATE_WARNING_OFF; /* att is always <= 1.0 */ - att = shl(att, s); - BASOP_SATURATE_WARNING_ON; + att = 1.0f; } - ELSE + win = 0; + for (; i < lowpassLine; i++) { - att = 0x7FFF; - move16(); - } - - accu1 = L_deposit_l(0); - - tmp1 = sub(lowpassLine, nTransWidth); - FOR (; i <= tmp1; i++) - { - inv_gain2 = shl(mult(inv_gain2, tilt_factor), 1); - - IF (sub(maxK, 1) == 0) /* current line is not zero, so reset pointers */ + inv_gain2 *= tilt_factor; + if (sqQ[i] != 0) /* current line is not zero, so reset pointers */ { - k = sub(i, segmentOffset); - - IF (k > 0) /* add segment sum to sum of segment magnitudes */ + if (win > 0) /* add segment sum to sum of segment magnitudes */ { - IF (sub(nTransWidth, 3) <= 0) + k = i - segmentOffset; + if (nTransWidth <= 3) { - tmp2 = sub(k, c1); - if (tmp2 > 0) n = L_msu(n, k, (Word16)0x8000); - if (tmp2 > 0) n = L_mac(n, nTransWidth_1, (Word16)0x8000); - if (tmp2 <= 0) n = L_mac(n, int_sqr[k], c2); + n += (k > 2 * nTransWidth - 4) ? (float)(k - nTransWidth + 1) + : (float)(k*k) * 0.28125f/nTransWidth; /* table lookup instead of */ } - ELSE + else { - tmp2 = sub(k, 12); - if (tmp2 > 0) n = L_msu(n, k, (Word16)0x8000); - if (tmp2 > 0) n = L_sub(n, 0x70000); - if (tmp2 <= 0) n = L_mac(n, int_sqr[k], 1152/*0.03515625f Q15*/); + n += (k > 12) ? (float)k - 7.0f : (float)(k*k) * 0.03515625f; } - sqErrorNrg = L_add(sqErrorNrg, accu1); - accu1 = L_deposit_l(0); /* segment ended here, so reset segment sum */ - k = 0; - move16(); - } - - FOR (; maxK < nTransWidth; maxK++) - { - IF (sqQ[i+maxK] != 0) + for (k = segmentOffset; k < i-win; k++) { - BREAK; + sqErrorNrg += sqQ[k] * (float)nTransWidth; + sqQ[k] = 0; + } + for (; win > 0; win--) + { + sqErrorNrg += sqQ[k] * (float)win; + sqQ[k++] = 0; } } - segmentOffset = add(i, 1); /* new segment might start at next line */ + segmentOffset = i + 1; /* new segment might start at next line */ } - ELSE /* current line is zero, so update pointers & segment sum */ + else /* current line is zero, so update pointers & segment sum */ { - if (sub(k, nTransWidth) < 0) + if (win < nTransWidth) { - k = add(k, 1); + win++; } - - tmp2 = sub(maxK, nTransWidth); - if (tmp2 < 0) - { - maxK = sub(maxK, 1); - } - - test(); - if ((tmp2 >= 0) && (sqQ[i+sub(nTransWidth, 1)] != 0)) - { - maxK = sub(nTransWidth, 1); - } - /* update segment sum: magnitudes scaled by smoothing function */ - /*accu1 += (float)fabs(x_orig[i]) * inv_gain2 * (float)(k * maxK);*/ - tmp2 = mult(inv_gain2, shl(imult1616(k, maxK), 8)); - accu1 = L_add(accu1, L_abs(Mpy_32_16_1(x_orig[i], tmp2))); + sqQ[i] = (float)fabs(x_orig[i]) * (float)win * inv_gain2; } } - - FOR (; i < lowpassLine; i++) + if (win > 0) /* add last segment sum to sum of segment magnitudes */ { - inv_gain2 = shl(mult(inv_gain2, tilt_factor), 1); - - IF (sub(maxK, 1) == 0) /* current line is not zero, so reset pointers */ + k = i - segmentOffset; + if (nTransWidth <= 3) { - k = sub(i, segmentOffset); - - IF (k > 0) /* add segment sum to sum of segment magnitudes */ - { - IF (sub(nTransWidth, 3) <= 0) - { - tmp2 = sub(k, c1); - if (tmp2 > 0) n = L_msu(n, k, (Word16)0x8000); - if (tmp2 > 0) n = L_mac(n, nTransWidth_1, (Word16)0x8000); - if (tmp2 <= 0) n = L_mac(n, int_sqr[k], c2); - } - ELSE - { - tmp2 = sub(k, 12); - if (tmp2 > 0) n = L_msu(n, k, (Word16)0x8000); - if (tmp2 > 0) n = L_sub(n, 0x70000); - if (tmp2 <= 0) n = L_mac(n, int_sqr[k], 1152/*0.03515625f Q15*/); - } - sqErrorNrg = L_add(sqErrorNrg, accu1); - } - segmentOffset = add(i, 1); /* no new segments since maxK remains 1 */ + n += (k > 2 * nTransWidth - 4) ? (float)(k - nTransWidth + 1) + : (float)(k*k) * 0.28125f/nTransWidth; /* table lookup instead of */ } - ELSE /* current line is zero, so update pointers & energy sum */ + else { - if (sub(k, nTransWidth) < 0) - { - k = add(k, 1); - } - if (sub(maxK, nTransWidth) < 0) - { - maxK = sub(maxK, 1); - } - - /* update segment sum: magnitudes scaled by smoothing function */ - /*accu1 += (float)fabs(x_orig[i]) * inv_gain2 * (float)(k * maxK);*/ - tmp2 = mult(inv_gain2, shl(imult1616(k, maxK), 8)); - accu1 = L_add(accu1, L_abs(Mpy_32_16_1(x_orig[i], tmp2))); + n += (k > 12) ? (float)k - 7.0f : (float)(k*k) * 0.03515625f; } - } - - k = sub(i, segmentOffset); - IF (k > 0) /* add last segment sum to sum of segment magnitudes */ - { - IF (sub(nTransWidth, 3) <= 0) + for (k = segmentOffset; k < i-win; k++) { - tmp2 = sub(k, c1); - if (tmp2 > 0) n = L_msu(n, k, (Word16)0x8000); - if (tmp2 > 0) n = L_mac(n, nTransWidth_1, (Word16)0x8000); - if (tmp2 <= 0) n = L_mac(n, int_sqr[k], c2); + sqErrorNrg += sqQ[k] * (float)nTransWidth; + sqQ[k] = 0; } - ELSE + for (; win > 0; win--) { - tmp2 = sub(k, 12); - if (tmp2 > 0) n = L_msu(n, k, (Word16)0x8000); - if (tmp2 > 0) n = L_sub(n, 0x70000); - if (tmp2 <= 0) n = L_mac(n, int_sqr[k], 1152/*0.03515625f Q15*/); + sqErrorNrg += sqQ[k] * (float)win; + sqQ[k++] = 0; } - sqErrorNrg = L_add(sqErrorNrg, accu1); } /* noise level factor: average of segment magnitudes of noise bins */ - IF (n > 0) + if (n > 0.0f) { - tmp1 = BASOP_Util_Divide3232_Scale(Mpy_32_16_1(sqErrorNrg, att), n, &s); - s = add(add(add(s, x_orig_e), inv_gain2_e), 7 - 15); - BASOP_SATURATE_WARNING_OFF; - tmp1 = shl(tmp1, s); - BASOP_SATURATE_WARNING_ON; + *fac_ns = (sqErrorNrg * att) / n; } - ELSE + else { - tmp1 = 0; - move16(); + *fac_ns = 0.0f; } /* quantize, dequantize noise level factor (range 0.09375 - 0.65625) */ - tmp2 = round_fx(L_shr(L_mult(tmp1, 22016/*1.34375f Q14*/), 14-NBITS_NOISE_FILL_LEVEL)); - - if (sub(tmp2, (1< 0) + *quantized_fac_ns = (int)(0.5f + *fac_ns * 1.34375f*(1< (1<syn, buf, M+1); + synth = buf + 1 + m; + mvr2r(LPDmem->syn, buf, 1+m); - Copy(xn_buf, synth, L_frame_glob); - Copy(synth + sub(L_frame_glob, M+1), LPDmem->syn, M+1); + mvr2r(xn_buf, synth, L_frame_glob); + mvr2r(synth+L_frame_glob-m-1, LPDmem->syn, 1+m); - IF (st->tcxonly == 0) + if(!st->tcxonly) { /* Update weighted synthesis */ - Residu3_fx(Ai+(st->nb_subfr-1)*(M+1), synth + sub(L_frame_glob, 1), &tmp, 1, Q_new+shift-1); - LPDmem->mem_w0 =sub(wsig[sub(L_frame_glob, 1)], tmp); - move16(); - LPDmem->mem_w0 =shr(LPDmem->mem_w0, shift); /*Qnew-1*/ + residu(Ai+(st->nb_subfr-1)*(M+1), M,synth+L_frame_glob-1, &tmp, 1); + LPDmem->mem_w0=wsig[L_frame_glob-1]-tmp; } /* Emphasis of synth -> synth_pe */ - tmp = synth[-(M+1)]; - move16(); - E_UTIL_f_preemph2(Q_new-1, synth - M, preemph, add(M, L_frame_glob), &tmp); + tmp = synth[-m-1]; + preemph(synth-m, preemph_f, m+L_frame_glob, &tmp); + mvr2r(synth+L_frame_glob-m, LPDmem->mem_syn, m); + mvr2r(synth+L_frame_glob-m, LPDmem->mem_syn2, m); + mvr2r( synth+L_frame_glob-L_SYN_MEM, LPDmem->mem_syn_r, L_SYN_MEM); - Copy(synth + sub(L_frame_glob, M), LPDmem->mem_syn, M); - Copy(synth + sub(L_frame_glob, M), LPDmem->mem_syn2, M); - Copy(synth + sub(L_frame_glob, L_SYN_MEM), LPDmem->mem_syn_r, L_SYN_MEM); - - test(); - IF (st->tcxonly == 0 || sub(L_frame_glob,L_FRAME16k)<=0) + if ( !st->tcxonly || (L_frame_glob==L_FRAME16k)) { /* Update excitation */ - IF (sub(L_frame_glob, L_EXC_MEM) < 0) + if (L_frame_glob < L_EXC_MEM) { - Copy( LPDmem->old_exc + L_frame_glob, LPDmem->old_exc, sub(L_EXC_MEM, L_frame_glob) ); - Residu3_fx(A, synth, LPDmem->old_exc + sub(L_EXC_MEM, L_frame_glob), L_frame_glob, 1); + mvr2r( LPDmem->old_exc+(L_frame_glob), LPDmem->old_exc, L_EXC_MEM-(L_frame_glob) ); + residu(A, M,synth, LPDmem->old_exc+L_EXC_MEM-(L_frame_glob), (L_frame_glob)); } - ELSE + else { - Residu3_fx(A, synth + sub(L_frame_glob, L_EXC_MEM), LPDmem->old_exc, L_EXC_MEM, 1); + residu(A, M,synth+(L_frame_glob)-L_EXC_MEM, LPDmem->old_exc, L_EXC_MEM); } - } - } + /*--------------------------------------------------------------- * Residual Quantization *--------------------------------------------------------------*/ -/* Returns: number of bits used (including "bits") Q0 */ -Word16 tcx_ari_res_Q_spec( - const Word32 x_orig[], /* i: original spectrum Q31-e */ - Word16 x_orig_e, /* i: original spectrum exponent Q0 */ - const Word16 signs[], /* i: signs (x_orig[.]<0) Q0 */ - Word32 x_Q[], /* i/o: quantized spectrum Q31-e */ - Word16 x_Q_e, /* i: quantized spectrum exponent Q0 */ - Word16 L_frame, /* i: number of lines Q0 */ - Word16 gain, /* i: TCX gain Q15-e */ - Word16 gain_e, /* i: TCX gain exponent Q0 */ - Word16 prm[], /* o: bit-stream Q0 */ - Word16 target_bits, /* i: number of bits available Q0 */ - Word16 bits, /* i: number of bits used so far Q0 */ - Word16 deadzone, /* i: quantizer deadzone Q15 */ - const Word16 x_fac[] /* i: spectrum post-quantization factors Q14 */ +/* Returns: number of bits used (including "bits") */ +int tcx_ari_res_Q_spec( + const float x_orig[], /* i: original spectrum */ + const int signs[], /* i: signs (x_orig[.]<0) */ + float x_Q[], /* i/o: quantized spectrum */ + int L_frame, /* i: number of lines */ + float gain, /* i: TCX gain */ + int prm[], /* o: bit-stream */ + int target_bits, /* i: number of bits available */ + int bits, /* i: number of bits used so far */ + float deadzone, /* i: quantizer deadzone */ + const float x_fac[] /* i: spectrum post-quantization factors */ ) { - Word16 i, j, num_zeros; - Word16 zeros[L_FRAME_PLUS]; - Word16 fac_p, sign; - Word32 thres, x_Q_m, x_Q_p; - Word32 L_tmp, L_tmp2; - Word16 s, s2; + int i, j, num_zeros; + int zeros[L_FRAME_PLUS]; + float fac_m, fac_p, thres, sign, x_Q_m, x_Q_p; /* Limit the number of residual bits */ - target_bits = s_min(target_bits, NPRM_RESQ); + target_bits = min(target_bits, NPRM_RESQ); /* Requantize the spectrum line-by-line */ - /* fac_m = deadzone * 0.5f; - fac_p = 0.5f - fac_m; */ + fac_m = deadzone * 0.5f; + fac_p = 0.5f - fac_m; num_zeros = 0; - move16(); - - s = sub(add(gain_e, x_Q_e), x_orig_e); - FOR (i=0; i < L_frame; i++) + for (i=0; i= 0) /* no bits left */ + if (bits >= target_bits) { - BREAK; + /* no bits left */ + break; } - - IF (x_Q[i] != 0) + if (x_Q[i] != 0) { - sign = x_fac[i]; - move16(); - if (signs[i] != 0) sign = negate(sign); + sign = (1-2*signs[i])*x_fac[i]; - /* x_Q_m = x_Q[i] - sign*fac_m; - x_Q_p = x_Q[i] + sign*fac_p; */ - - L_tmp = L_mult(sign, deadzone); /* sign*deadzone/2 in Q31 */ - x_Q_m = L_sub(x_Q[i], L_shr(L_tmp, x_Q_e)); - - L_tmp = L_mac(L_tmp, sign, (Word16)0x8000); /* sign*(deadzone-1)/2 in Q31 */ - x_Q_p = L_sub(x_Q[i], L_shr(L_tmp, x_Q_e)); - - /* if (fabs(x_orig[i] - gain * x_Q_m) < fabs(x_orig[i] - gain * x_Q_p)) */ - L_tmp = L_abs(L_sub(x_orig[i], L_shl(Mpy_32_16_1(x_Q_m, gain), s))); - L_tmp2 = L_abs(L_sub(x_orig[i], L_shl(Mpy_32_16_1(x_Q_p, gain), s))); - - IF (L_sub(L_tmp, L_tmp2) < 0) /* Decrease magnitude */ + x_Q_m = x_Q[i] - sign*fac_m; + x_Q_p = x_Q[i] + sign*fac_p; + if (fabs(x_orig[i] - gain * x_Q_m) < fabs(x_orig[i] - gain * x_Q_p)) /* Decrease magnitude */ { x_Q[i] = x_Q_m; - move32(); - prm[bits] = 0; - move16(); + prm[bits++] = 0; } - ELSE /* Increase magnitude */ + else /* Increase magnitude */ { x_Q[i] = x_Q_p; - move32(); - prm[bits] = 1; - move16(); + prm[bits++] = 1; } - bits = add(bits, 1); } - ELSE + else { - zeros[num_zeros] = i; - move16(); - num_zeros = add(num_zeros, 1); + zeros[num_zeros++] = i; } } /* Requantize zeroed-lines of the spectrum */ - fac_p = msu_r(1417339264l/*2*0.33f Q31*/, deadzone, 21627/*2*0.33f Q15*/); /* Q16 */ - target_bits = sub(target_bits, 1); /* reserve 1 bit for the check below */ - - s = sub(gain_e, x_orig_e); - s2 = sub(x_Q_e, 1); - FOR (j = 0; j < num_zeros; j++) + fac_p = (1.0f - deadzone)*0.33f; + --target_bits; /* reserve 1 bit for the check below */ + for (j=0; j= 0) /* 1 or 0 bits left */ + if (bits >= target_bits) { - BREAK; + /* 1 or 0 bits left */ + break; } i = zeros[j]; - move16(); - thres = L_mult(fac_p, x_fac[i]); /* Q31 */ - - IF (L_sub(L_abs(x_orig[i]), L_shl(Mpy_32_16_1(thres, gain), s)) > 0) + thres = fac_p * x_fac[i]; + if (fabs(x_orig[i]) > thres * gain) { - prm[bits] = 1; - move16(); - bits = add(bits, 1); - - prm[bits] = sub(1, signs[i]); - move16(); - bits = add(bits, 1); - - L_tmp = L_shr(thres, s2); - if (signs[i]) L_tmp = L_negate(L_tmp); - x_Q[i] = L_tmp; - move32(); + prm[bits++] = 1; + prm[bits++] = 1-signs[i]; + x_Q[i] = (2-4*signs[i]) * thres; } - ELSE + else { - prm[bits] = 0; - move16(); - bits = add(bits, 1); + prm[bits++] = 0; } } - return bits; } #define kMaxEstimatorOvershoot 5 #define kMaxEstimatorUndershoot 0 -Word16 tcx_res_Q_gain( - Word16 sqGain, - Word16 sqGain_e, - Word16 *gain_tcx, - Word16 *gain_tcx_e, - Word16 *prm, - Word16 sqTargetBits + +int tcx_res_Q_gain( + float sqGain, + float *gain_tcx, + int *prm, + int sqTargetBits ) { - Word16 bits; - Word16 gain_reQ, gain_reQ_e; + int bits; + float gain_reQ; /*Refine the gain quantization : Normal greedy gain coding */ - - gain_reQ = *gain_tcx; - move16(); - gain_reQ_e = *gain_tcx_e; - move16(); - - /* make sure we have a bit of headroom */ - IF (sub(gain_reQ, 0x7000) > 0) + gain_reQ=*gain_tcx; + for(bits=0; bits thres * sqGain) + { + /* was (b > thres) */ + prm[(*bits)++] = 1; + prm[(*bits)++] = 1; + *x_Q = 2.f*thres; + } + else if (x_orig < -thres * sqGain) + { + /* was (b < -thres) */ + prm[(*bits)++] = 1; + prm[(*bits)++] = 0; + *x_Q = -2.f*thres; + } + else + { + prm[(*bits)++] = 0; + } + + return; +} + + +int tcx_res_Q_spec( + float *x_orig, + float *x_Q, + int L_frame, + float sqGain, + int *prm, + int sqTargetBits, + int bits, + float sq_round, + const float lf_deemph_factors[] ) { - Word16 i; - Word16 fac_m, fac_p; - Word32 tmp1, tmp2; - Word16 s, s2, lf_deemph_factor; - Word16 c; - Word32 thres; - + int i; + float fac_m, fac_p; /* Limit the number of residual bits */ - sqTargetBits = s_min(sqTargetBits, NPRM_RESQ); + sqTargetBits = min(sqTargetBits, NPRM_RESQ); /* Requantize the spectrum line-by-line */ - fac_m = shr(sq_round, 1); - fac_p = sub(0x4000, fac_m); - - /* exponent difference of x_orig and x_Q * sqGain */ - s = sub(x_orig_e, add(x_Q_e, sqGain_e)); - - lf_deemph_factor = 0x4000; - move16(); - s2 = sub(x_Q_e, 1); - - FOR (i = 0; i < L_frame; i++) + fac_p = 0.5f - sq_round * 0.5f; + fac_m = sq_round * 0.5f; + if (!lf_deemph_factors) { - IF (sub(bits, sub(sqTargetBits, kMaxEstimatorUndershoot)) >= 0) + for (i = 0; i < L_frame; i++) { - fac_m = 0; - move16(); - fac_p = 0; - move16(); - - IF (sub(bits, s_min(NPRM_RESQ, add(sqTargetBits, kMaxEstimatorOvershoot))) >= 0) + if (bits >= sqTargetBits-kMaxEstimatorUndershoot) { - BREAK; + fac_m=fac_p=0; + if (bits >= min(NPRM_RESQ,sqTargetBits+kMaxEstimatorOvershoot)) + { + break; + } + } + + if (x_Q[i] != 0.0f) + { + if(x_orig[i]<(sqGain)*x_Q[i]) + { + prm[bits++]=0; + x_Q[i]-=(x_Q[i]>0)?fac_m : fac_p; + } + else + { + prm[bits++]=1; + x_Q[i]+=(x_Q[i]>0)?fac_p : fac_m; + } + } + } + sqTargetBits -= 2; /* Quantize zeroed lines of the spectrum */ + for (i = 0; (i < L_frame) && (bits < sqTargetBits); i++) + { + /* bits < sqTargetBits */ + if (x_Q[i] == 0.0f) + { + refine_0(x_orig[i], &x_Q[i], sqGain, prm, &bits, sq_round, 1.0f); /* inlined */ + } + } + /* Make sure that all possible bits are initialized */ + for (i = bits; i < NPRM_RESQ; i++) + { + prm[i] = 0; + } + return bits; + } + for (i = 0; i < L_frame; i++) + { + if (bits >= sqTargetBits-kMaxEstimatorUndershoot) + { + fac_m=fac_p=0; + if (bits >= min(NPRM_RESQ,sqTargetBits+kMaxEstimatorOvershoot)) + { + break; } } - test(); - test(); - IF ((x_Q[i] != 0) && ((lf_deemph_factors == NULL) || (sub(lf_deemph_factors[i], 0x2000) > 0))) + if (x_Q[i] != 0 && lf_deemph_factors[i] > 0.5f) { - tmp1 = L_add(x_orig[i], 0); - tmp2 = Mpy_32_16_1(x_Q[i], sqGain); - if (s > 0) tmp2 = L_shr(tmp2, s); - if (s < 0) tmp1 = L_shl(tmp1, s); - - if (lf_deemph_factors != NULL) + if(x_orig[i]<(sqGain)*x_Q[i]) { - lf_deemph_factor = lf_deemph_factors[i]; - move16(); + prm[bits++]=0; + x_Q[i]-=(x_Q[i]>0)?fac_m*lf_deemph_factors[i]:fac_p*lf_deemph_factors[i]; } - - IF (L_sub(tmp1, tmp2) < 0) + else { - prm[bits] = 0; - move16(); - bits = add(bits, 1); - - if (x_Q[i] > 0) tmp1 = L_mult(fac_m, lf_deemph_factor); - if (x_Q[i] < 0) tmp1 = L_mult(fac_p, lf_deemph_factor); - x_Q[i] = L_sub(x_Q[i], L_shr(tmp1, s2)); - move32(); - } - ELSE - { - prm[bits] = 1; - move16(); - bits = add(bits, 1); - - if (x_Q[i] > 0) tmp1 = L_mult(fac_p, lf_deemph_factor); - if (x_Q[i] < 0) tmp1 = L_mult(fac_m, lf_deemph_factor); - x_Q[i] = L_add(x_Q[i], L_shr(tmp1, s2)); - move32(); + prm[bits++]=1; + x_Q[i]+=(x_Q[i]>0)?fac_p*lf_deemph_factors[i]:fac_m*lf_deemph_factors[i]; } } } /*Quantize zeroed-line of the spectrum*/ - c = sub(21627/*0.66f Q15*/, mult_r(sq_round, 21627/*0.66f Q15*/)); - - FOR (i = 0; i < L_frame; i++) + for (i = 0; (i < L_frame) && (bits < (sqTargetBits-2)); i++) { - IF (sub(bits, sub(sqTargetBits, 2)) >= 0) + /* For (bits >= (sqTargetBits-2)) */ + if (x_Q[i] == 0 && lf_deemph_factors[i] > 0.5f) { - BREAK; - } - - test(); - test(); - IF ((x_Q[i] == 0) && ((lf_deemph_factors == NULL) || (sub(lf_deemph_factors[i], 0x2000) > 0))) - { - if (lf_deemph_factors != NULL) - { - lf_deemph_factor = lf_deemph_factors[i]; - move16(); - } - - thres = L_mult(c, lf_deemph_factor); - tmp1 = L_shl(Mpy_32_16_1(thres, sqGain), sub(sqGain_e, x_orig_e)); - - IF (L_sub(x_orig[i], tmp1) > 0) - { - prm[bits] = 1; - move16(); - bits = add(bits, 1); - - prm[bits] = 1; - move16(); - bits = add(bits, 1); - - x_Q[i] = L_shl(thres, sub(1, x_Q_e)); - move32(); - } - ELSE IF (L_add(x_orig[i], tmp1) < 0) - { - prm[bits] = 1; - move16(); - bits = add(bits, 1); - - prm[bits] = 0; - move16(); - bits = add(bits, 1); - - x_Q[i] = L_shl(L_negate(thres), sub(1, x_Q_e)); - move32(); - } - ELSE - { - prm[bits] = 0; - move16(); - bits = add(bits, 1); - } + refine_0(x_orig[i], &x_Q[i], sqGain, prm, &bits, sq_round, lf_deemph_factors[i]); } } /*Be sure that every possible bits are initialized*/ - FOR (i = bits; i < NPRM_RESQ; i++) + for (i = bits; i < NPRM_RESQ; i++) { - prm[i] = 0; - move16(); + prm[i]=0; } - return bits; } + + void ProcessIGF( - IGF_ENC_INSTANCE_HANDLE const hInstance, /**< in: instance handle of IGF Encoder */ - Encoder_State_fx *st, /**< in: Encoder state */ - Word32 pMDCTSpectrum[], /**< in: MDCT spectrum */ - Word16 *pMDCTSpectrum_e, - Word32 pPowerSpectrum[], /**< in: MDCT^2 + MDST^2 spectrum, or estimate */ - Word16 *pPowerSpectrum_e, - Word16 isTCX20, /**< in: flag indicating if the input is TCX20 or TCX10/2xTCX5 */ - Word16 isTNSActive, /**< in: flag indicating if the TNS is active */ - Word16 isTransition, /**< in: flag indicating if the input is the transition from from ACELP to TCX20/TCX10 */ - Word16 frameno /**< in: flag indicating index of current subframe */ + IGF_ENC_INSTANCE_HANDLE const hInstance, /**< in: instance handle of IGF Encoder */ + Encoder_State *st, /**< in: Encoder state */ + float *pMDCTSpectrum, /**< in: MDCT spectrum */ + float *pPowerSpectrum, /**< in: MDCT^2 + MDST^2 spectrum, or estimate */ + int isTCX20, /**< in: flag indicating if the input is TCX20 or TCX10/2xTCX5 */ + int isTNSActive, /**< in: flag indicating if the TNS is active */ + int isTransition, /**< in: flag indicating if the input is the transition from from ACELP to TCX20/TCX10 */ + int frameno /**< in: flag indicating index of current subframe */ ) { - Word16 igfGridIdx; - Word16 isIndepFlag; - Word16 bsBits; - Word16 bsStart; - + int igfGridIdx; + int isIndepFlag; + int bsBits; + int pBsStart; isIndepFlag = 1; - move16(); - test(); - IF (isTransition && isTCX20) + if (isTransition && isTCX20) { igfGridIdx = IGF_GRID_LB_TRAN; - move16(); } - ELSE + else if (isTCX20) { - IF (isTCX20) + igfGridIdx = IGF_GRID_LB_NORM; + } + else + { + /* It is short block */ + igfGridIdx = IGF_GRID_LB_SHORT; + if (frameno == 1) { - igfGridIdx = IGF_GRID_LB_NORM; - move16(); - } - ELSE - { - /* It is short block */ - igfGridIdx = IGF_GRID_LB_SHORT; - move16(); - if (sub(frameno, 1) == 0) - { - isIndepFlag = 0; - move16(); - } + isIndepFlag = 0; } } - IGFEncApplyMono(hInstance, /**< in: instance handle of IGF Encoder */ igfGridIdx, /**< in: IGF grid index */ st, /**< in: Encoder state */ pMDCTSpectrum, /**< in: MDCT spectrum */ - *pMDCTSpectrum_e, pPowerSpectrum, /**< in: MDCT^2 + MDST^2 spectrum, or estimate */ - *pPowerSpectrum_e, isTCX20, /**< in: flag indicating if the input is TCX20 or TCX10/2xTCX5 */ - isTNSActive, /**< in: flag indicating if the TNS is active */ - (st->last_core_fx == ACELP_CORE) - ); + isTNSActive, + (st->last_core == ACELP_CORE) + ); /**< in: flag indicating if the TNS is active */ + + { - const Word32 tns_predictionGain = (&st->hIGFEnc)->tns_predictionGain; - const Word16 startLine = (&st->hIGFEnc)->infoStartLine; - const Word16 endLine = (&st->hIGFEnc)->infoStopLine; - const Word16 maxOrder = 8; - const Word32 *spec_before = (&st->hIGFEnc)->spec_be_igf; - Word16 curr_order = 0; - Word16 A[ITF_MAX_FILTER_ORDER+1]; - Word16 Q_A; - Word16 predictionGain = 0; - Word16 *flatteningTrigger = &(&st->hIGFEnc)->flatteningTrigger; - ITF_Detect_fx( spec_before, startLine, endLine, maxOrder, A, &Q_A, &predictionGain, &curr_order, shl((&st->hIGFEnc)->spec_be_igf_e, 1) ); - *flatteningTrigger = 0; - test(); - IF (L_sub(tns_predictionGain, 9646899l/*1.15 Q23*/) < 0 && - sub(predictionGain, 147/*1.15 Q7*/) < 0) - { - *flatteningTrigger = 1; - } + const float tns_predGain = (&st->hIGFEnc)->tns_predictionGain; + const short int startLine = (&st->hIGFEnc)->infoStartLine; + const short int endLine = (&st->hIGFEnc)->infoStopLine; + const int maxOrder = 8; + const float* spec_before = (&st->hIGFEnc)->spec_be_igf; + int curr_order = 0; + float A[ITF_MAX_FILTER_ORDER+1]; + float predictionGain = 0; + int* flatteningTrigger = &(&st->hIGFEnc)->flatteningTrigger; + ITF_Detect( spec_before, startLine, endLine, maxOrder, A, &predictionGain, &curr_order ); + + *flatteningTrigger = tns_predGain < 1.15 && predictionGain < 1.15; } - bsStart = st->next_ind_fx; - move16(); + pBsStart = st->next_ind; hInstance->infoTotalBitsPerFrameWritten = 0; - move16(); - IF (isTCX20) + IGFEncWriteBitstream( hInstance, isTCX20 ? NULL : st, &hInstance->infoTotalBitsPerFrameWritten, igfGridIdx, isIndepFlag ); + + bsBits = st->next_ind - pBsStart; + if (!isTCX20) { - IGFEncWriteBitstream(hInstance, - NULL, - &hInstance->infoTotalBitsPerFrameWritten, - igfGridIdx, - isIndepFlag); - } - ELSE - { - IGFEncWriteBitstream(hInstance, - st, - &hInstance->infoTotalBitsPerFrameWritten, - igfGridIdx, - isIndepFlag); - } - - bsBits = sub(st->next_ind_fx, bsStart); - IF (!isTCX20) - { - IGFEncConcatenateBitstream(hInstance, bsBits, &st->next_ind_fx, &st->nb_bits_tot_fx, st->ind_list_fx); + IGFEncConcatenateBitstream(hInstance, bsBits, &st->next_ind, &st->nb_bits_tot, st->ind_list); } + return; } -void attenuateNbSpectrum(Word16 L_frame, Word32 *spectrum) + +void attenuateNbSpectrum(int L_frame, float *spectrum) { - Word16 i, length, att; + int i; + int length = L_frame / 20; + float att = (length == 8)?0.6f:0.66f; - length = idiv1616U(L_frame, 20); - - att = 21627/*0.66f Q15*/; - move16(); - if (sub(length, 8) == 0) + for(i=0; i #include -#include "stl.h" -#include "basop_util.h" -#include "cnst_fx.h" -#include "prot_fx.h" +#include "prot.h" -void tfaCalcEnv_fx(const Word16* shb_speech, Word32* enr) + +void tfaCalcEnv(const float* shb_speech, float* enr) { - Word16 i, j, k; - - k = 0; - move16(); - FOR (i=0; i 0.70 && pitch_buf_sum > 4.0 * 110 && voicing_sum > 2.0 * 0.70) || + (last_core == TCX_20_CORE && flatness > 0.50 && voicing_sum < 2.0 * 0.70)) + { + tfa_flag = 1; + } /* energy lower limit */ - IF(L_sub(m_a, m_a_bottom) < 0) + if(m_a < m_a_bottom) { tfa_flag = 0; - move16(); - } - ELSE - { - exp = norm_l(m_a); - L_tmp = BASOP_Util_Log2(L_shl(m_a, exp)); - exp = sub(sub(31, exp), Q_enr); - m_a = L_add(L_shl(L_deposit_h(exp), 9), L_tmp);/* Q25 */ - L_tmp = L_add(m_a, -17266211l/*log10(0.7f)/log10(2.f) Q25*/); - L_tmp1 = L_add(m_a, -33554432l/*log10(0.5f)/log10(2.f) Q25*/); - - voicing_sum = add(shr(voicing[0], 1), shr(voicing[1], 1)); - - pitch_buf_sum = shr(add(shr(pitch_buf[0], 1), shr(pitch_buf[1], 1)), 1); - pitch_buf_sum = add(pitch_buf_sum, shr(add(shr(pitch_buf[2], 1), shr(pitch_buf[3], 1)), 1)); - - test(); - test(); - test(); - test(); - test(); - IF ((L_sub(m_g, L_tmp) > 0 && sub(pitch_buf_sum, 7040/*110 Q6*/) > 0 && sub(voicing_sum, 22938/*0.70 Q15*/) > 0) || - (sub(last_core, TCX_20_CORE) == 0 && L_sub(m_g, L_tmp1) > 0 && sub(voicing_sum, 22938/*0.70 Q15*/) < 0)) - { - tfa_flag = 1; - move16(); - } } return tfa_flag; } - diff --git a/src/libs/libevs/lib_enc/tns_base_enc.cpp b/src/libs/libevs/lib_enc/tns_base_enc.cpp old mode 100755 new mode 100644 index d0eb4589..2960873a --- a/src/libs/libevs/lib_enc/tns_base_enc.cpp +++ b/src/libs/libevs/lib_enc/tns_base_enc.cpp @@ -1,26 +1,30 @@ /*==================================================================================== - EVS Codec 3GPP TS26.442 Apr 03, 2018. Version 12.11.0 / 13.6.0 / 14.2.0 + EVS Codec 3GPP TS26.443 Nov 13, 2018. Version 12.11.0 / 13.7.0 / 14.3.0 / 15.1.0 ====================================================================================*/ +#include "cnst.h" +#include "rom_com.h" +#include "prot.h" - -#include "stl.h" -#include "prot_fx.h" -#include "basop_util.h" -#include "stl.h" #include +#include #include -#include "rom_com_fx.h" + #define HLM_MIN_NRG (32768.0f * 2*NORM_MDCT_FACTOR / (640*640)) +static float Autocorrelation(float const x[], int n, int lag) +{ + return dotp(x, x+lag, n-lag); +} + /** Get TNS filter parameters from autocorrelation. * * @param rxx Autocorrelation function/coefficients. * @param maxOrder Maximum filter order/number of coefficients. * @param pTnsFilter Pointer to the output filter. */ -static void GetFilterParameters(Word32 rxx[], Word16 maxOrder, STnsFilter * pTnsFilter); +static void GetFilterParameters(float const rxx[], int maxOrder, STnsFilter * pTnsFilter); /** Quantization for reflection coefficients. * @@ -28,7 +32,7 @@ static void GetFilterParameters(Word32 rxx[], Word16 maxOrder, STnsFilter * pTns * @param index output quantized values. * @param order number of coefficients/values. */ -static void Parcor2Index(Word16 const parCoeff[], Word16 index[], Word16 order); +static void Parcor2Index(float const parCoeff[], int index[], int order); /** Linear prediction analysis/synthesis filter definition. * @param order filter order. @@ -37,8 +41,7 @@ static void Parcor2Index(Word16 const parCoeff[], Word16 index[], Word16 order); * @param x the current input value. * @return the output of the filter. */ -typedef Word32 (* TLinearPredictionFilter)(Word16 order, Word16 const parCoeff[], Word32 * state, Word32 x); - +typedef float (* TLinearPredictionFilter)(int order, float const parCoeff[], float * state, float x); /********************************/ /* Interface functions */ @@ -46,295 +49,156 @@ typedef Word32 (* TLinearPredictionFilter)(Word16 order, Word16 const parCoeff[] #define MAX_SUBDIVISIONS 3 -Word16 DetectTnsFilt(STnsConfig const * pTnsConfig, - Word32 const pSpectrum[], - STnsData * pTnsData, - Word16 *predictionGain) +int DetectTnsFilt(STnsConfig const * pTnsConfig, + float const pSpectrum[], + STnsData * pTnsData + , float* predictionGain + ) { - Word16 facs[TNS_MAX_NUM_OF_FILTERS][MAX_SUBDIVISIONS]; - Word16 facs_e[TNS_MAX_NUM_OF_FILTERS][MAX_SUBDIVISIONS]; /* exponents of facs[][] */ - Word16 shifts[TNS_MAX_NUM_OF_FILTERS][MAX_SUBDIVISIONS]; - Word16 iFilter = 0; + float norms[TNS_MAX_NUM_OF_FILTERS][MAX_SUBDIVISIONS]; + int iFilter = 0; + short i; + for( i=0; imaxOrder <= 0) + if (pTnsConfig->maxOrder <= 0) { return 0; } /* Calculate norms for each spectrum part */ - FOR (iFilter = 0; iFilter < pTnsConfig->nMaxFilters; iFilter++) + for (iFilter = 0; iFilter < pTnsConfig->nMaxFilters; iFilter++) { - Word16 idx0; - Word16 idx1; - Word16 nSubdivisions; - Word16 iSubdivisions; - - move16(); - move16(); - move16(); - idx0 = pTnsConfig->iFilterBorders[iFilter+1]; - idx1 = pTnsConfig->iFilterBorders[iFilter]; - nSubdivisions = pTnsConfig->pTnsParameters[iFilter].nSubdivisions; - + int const idx0 = pTnsConfig->iFilterBorders[iFilter+1]; + int const idx1 = pTnsConfig->iFilterBorders[iFilter]; + int const nSubdivisions = pTnsConfig->pTnsParameters[iFilter].nSubdivisions; + int iSubdivisions; + /* Variable initialization */ assert(pTnsConfig->pTnsParameters[iFilter].nSubdivisions <= MAX_SUBDIVISIONS); - - FOR (iSubdivisions = 0; iSubdivisions < nSubdivisions; iSubdivisions++) + for (iSubdivisions = 0; iSubdivisions < nSubdivisions; iSubdivisions++) { - Word16 iStartLine; - Word16 iEndLine; - Word16 tmp, headroom, shift; - Word32 L_tmp, tmp32; - - /* iStartLine = idx0 + (idx1-idx0)*iSubdivisions/nSubdivisions; - iEndLine = idx0 + (idx1-idx0)*(iSubdivisions+1)/nSubdivisions; */ - assert((nSubdivisions == 1) || (nSubdivisions == 3)); - - tmp = sub(idx1, idx0); - iStartLine = imult1616(tmp, iSubdivisions); - iEndLine = add(iStartLine, tmp); - - if (sub(nSubdivisions, 3) == 0) iStartLine = mult(iStartLine, 0x2AAB); - iStartLine = add(iStartLine, idx0); - - if (sub(nSubdivisions, 3) == 0) iEndLine = mult(iEndLine, 0x2AAB); - iEndLine = add(iEndLine, idx0); - - /*norms[iFilter][iSubdivisions] = norm2FLOAT(pSpectrum+iStartLine, iEndLine-iStartLine);*/ - headroom = getScaleFactor32(&pSpectrum[iStartLine], sub(iEndLine, iStartLine)); - - /* Calculate norm of spectrum band */ - L_tmp = Norm32Norm(pSpectrum+iStartLine, headroom, sub(iEndLine, iStartLine), &shift); - - /* Check threshold HLM_MIN_NRG */ - BASOP_SATURATE_WARNING_OFF; - tmp32 = L_sub(L_shl(L_tmp, s_min(31, sub(shift, 24-31*2))), 3277l/*HLM_MIN_NRG Q7*/); - BASOP_SATURATE_WARNING_ON; - - /* get pre-shift for autocorrelation */ - tmp = sub(shift, norm_l(L_tmp)); /* exponent for normalized L_tmp */ - tmp = shr(sub(1, tmp), 1); /* pre-shift to apply before autocorrelation */ - shifts[iFilter][iSubdivisions] = s_min(tmp, headroom); - move16(); - - /* calc normalization factor */ - facs[iFilter][iSubdivisions] = 0; - move16(); - facs_e[iFilter][iSubdivisions] = 0; - move16(); - - if (tmp32 > 0) - { - facs[iFilter][iSubdivisions] = 0x7FFF; - move16(); /* normalization not needed for one subdivision */ - } - - test(); - IF ((tmp32 > 0) && (sub(nSubdivisions, 1) > 0)) - { - move16(); - facs_e[iFilter][iSubdivisions] = shl(sub(tmp, shifts[iFilter][iSubdivisions]), 1); - - tmp = sub(1, shl(tmp, 1)); /* exponent of autocorrelation */ - L_tmp = L_shl(L_tmp, sub(shift, tmp)); /* shift L_tmp to that exponent */ - - /* calc factor (with 2 bits headroom for sum of 3 subdivisions) */ - move16(); - facs[iFilter][iSubdivisions] = div_s(0x2000, round_fx(L_tmp)); /* L_tmp is >= 0x2000000 */ - } + int const iStartLine = idx0 + (idx1-idx0)*iSubdivisions/nSubdivisions; + int const iEndLine = idx0 + (idx1-idx0)*(iSubdivisions+1)/nSubdivisions; + /* Variable initialization */ + norms[iFilter][iSubdivisions] = sum2_f(pSpectrum+iStartLine, iEndLine-iStartLine); /* No need for indirect, PTR_INIT used instead */ } - } /* Calculate normalized autocorrelation for spectrum subdivision and get TNS filter parameters based on it */ - FOR (iFilter = 0; iFilter < pTnsConfig->nMaxFilters; iFilter++) + for (iFilter = 0; iFilter < pTnsConfig->nMaxFilters; iFilter++) { -#define RXX_E (3) - Word32 rxx[TNS_MAX_FILTER_ORDER+1]; - Word16 idx0; - Word16 idx1; - Word16 spectrumLength; - STnsFilter * pFilter; - Word16 nSubdivisions; - Word16 iSubdivisions; - Word16 tmpbuf[325]; + float rxx[TNS_MAX_FILTER_ORDER+1]; + int const idx0 = pTnsConfig->iFilterBorders[iFilter+1]; + int const idx1 = pTnsConfig->iFilterBorders[iFilter]; + int const spectrumLength = idx1 - idx0; + STnsFilter * const pFilter = pTnsData->filter + iFilter; + int const nSubdivisions = pTnsConfig->pTnsParameters[iFilter].nSubdivisions; + int iSubdivisions; - set32_fx(rxx, 0, TNS_MAX_FILTER_ORDER+1); - - move16(); - move16(); - move16(); - idx0 = pTnsConfig->iFilterBorders[iFilter+1]; - idx1 = pTnsConfig->iFilterBorders[iFilter]; - spectrumLength = sub(idx1, idx0); - pFilter = pTnsData->filter + iFilter; - nSubdivisions = pTnsConfig->pTnsParameters[iFilter].nSubdivisions; - - FOR (iSubdivisions = 0; iSubdivisions < nSubdivisions; iSubdivisions++) + set_f( rxx, 0, TNS_MAX_FILTER_ORDER+1 ); /* WMOPS: This initialization is required */ + /* Variable initialization */ + for (iSubdivisions = 0; (iSubdivisions < nSubdivisions) && (norms[iFilter][iSubdivisions] > HLM_MIN_NRG); iSubdivisions++) { - Word16 iStartLine, n, i; - Word16 iEndLine; - const Word16 * pWindow; - Word16 lag, shift; - Word32 L_tmp; - - IF ( facs[iFilter][iSubdivisions] == 0 ) + float const fac = 1.0f/norms[iFilter][iSubdivisions]; + int const iStartLine = idx0 + spectrumLength*iSubdivisions/nSubdivisions; + int const iEndLine = idx0 + spectrumLength*(iSubdivisions+1)/nSubdivisions; + float const * pWindow = tnsAcfWindow; + float const * pEndWindowCoeff = &tnsAcfWindow[sizeof(tnsAcfWindow)/sizeof(tnsAcfWindow[0])]; /* WMOPS: Not counted as it is used only in the assertion */ + int lag; + (void)pEndWindowCoeff; + /* For additional loop condition */ + /* Variable initialization */ + for (lag = 1; lag <= pTnsConfig->maxOrder; lag++) { - BREAK; + rxx[lag] += fac * (*pWindow) * Autocorrelation(pSpectrum+iStartLine, iEndLine-iStartLine, lag); + pWindow++; } - - - /* iStartLine = idx0 + (idx1-idx0)*iSubdivisions/nSubdivisions; - iEndLine = idx0 + (idx1-idx0)*(iSubdivisions+1)/nSubdivisions; */ - assert((nSubdivisions == 1) || (nSubdivisions == 3)); - - iStartLine = imult1616(spectrumLength, iSubdivisions); - iEndLine = add(iStartLine, spectrumLength); - - if (sub(nSubdivisions, 3) == 0) iStartLine = mult(iStartLine, 0x2AAB); - iStartLine = add(iStartLine, idx0); - - if (sub(nSubdivisions, 3) == 0) iEndLine = mult(iEndLine, 0x2AAB); - iEndLine = add(iEndLine, idx0); - - - move16(); - shift = shifts[iFilter][iSubdivisions]; - - move16(); - pWindow = tnsAcfWindow; - - n = sub(iEndLine, iStartLine); - assert(n < (Word16)(sizeof(tmpbuf)/sizeof(Word16))); - FOR (i = 0; i < n; i++) - { - tmpbuf[i] = round_fx(L_shl(pSpectrum[iStartLine+i], shift)); - } - - FOR (lag = 0; lag <= pTnsConfig->maxOrder; lag++) - { - n = sub(sub(iEndLine,lag), iStartLine); - - L_tmp = L_deposit_l(0); - FOR (i = 0; i < n; i++) - { - L_tmp = L_mac0(L_tmp, tmpbuf[i], tmpbuf[i+lag]); - } - - if (lag != 0) L_tmp = Mpy_32_16_1(L_tmp, *pWindow++); - - L_tmp = Mpy_32_16_1(L_tmp, facs[iFilter][iSubdivisions]); - L_tmp = L_shl(L_tmp, facs_e[iFilter][iSubdivisions]); - - rxx[lag] = L_add(rxx[lag], L_tmp); - move32(); - } - } - - IF ( sub(iSubdivisions,nSubdivisions) == 0 ) /* meaning there is no subdivision with low energy */ + if (iSubdivisions == nSubdivisions) /* meaning there is no subdivision with low energy */ { + rxx[0] = (float)pTnsConfig->pTnsParameters[iFilter].nSubdivisions; pFilter->spectrumLength = spectrumLength; - move16(); /* Limit the maximum order to spectrum length/4 */ - GetFilterParameters(rxx, s_min (pTnsConfig->maxOrder, shr(pFilter->spectrumLength,2)), pFilter); + GetFilterParameters(rxx, min(pTnsConfig->maxOrder, pFilter->spectrumLength/4), pFilter); } } if (predictionGain) { assert(pTnsConfig->nMaxFilters == 1); - move16(); *predictionGain = pTnsData->filter->predictionGain; } /* We check the filter's decisions in the opposite direction */ - FOR (iFilter = sub(pTnsConfig->nMaxFilters,1); iFilter >= 0; iFilter--) + for (iFilter = pTnsConfig->nMaxFilters-1; iFilter >= 0; iFilter--) { - STnsFilter * pFilter; - struct TnsParameters const * pTnsParameters; + STnsFilter * const pFilter = pTnsData->filter + iFilter; + struct TnsParameters const * const pTnsParameters = pTnsConfig->pTnsParameters + iFilter; - move16(); - move16(); - pFilter = pTnsData->filter + iFilter; - pTnsParameters = pTnsConfig->pTnsParameters + iFilter; - - IF ( s_or(sub(pFilter->predictionGain,pTnsParameters->minPredictionGain) > 0, - sub(pFilter->avgSqrCoef,pTnsParameters->minAvgSqrCoef) > 0 ) ) + /* TNS decision function */ + if ((pFilter->predictionGain > pTnsParameters->minPredictionGain) + || (pFilter->avgSqrCoef > pTnsParameters->minAvgSqrCoef)) { - move16(); - pTnsData->nFilters = add(pTnsData->nFilters,1); + ++pTnsData->nFilters; } - ELSE IF (pTnsData->nFilters > 0) /* If a previous filter is turned on */ + else if (pTnsData->nFilters > 0) /* If a previous filter is turned on */ { /* Since TNS filter of order 0 is not allowed we haved to signal in the stream filter of order 1 with the 0th coefficient equal to 0 */ ClearTnsFilterCoefficients(pFilter); - move16(); - move16(); pFilter->order = 1; - pTnsData->nFilters = add(pTnsData->nFilters,1); + ++pTnsData->nFilters; } - ELSE + else { ClearTnsFilterCoefficients(pFilter); } } - - - test(); - return (pTnsData->nFilters > 0); + return (pTnsData->nFilters > 0) ? 1 : 0; } -Word16 EncodeTnsData(STnsConfig const * pTnsConfig, STnsData const * pTnsData, Word16 * stream, Word16 * pnSize, Word16 * pnBits) +TNS_ERROR EncodeTnsData(STnsConfig const * pTnsConfig, STnsData const * pTnsData, int * stream, int * pnSize, int * pnBits) { - - move16(); - move16(); *pnSize = 0; *pnBits = 0; - - IF ( sub(pTnsConfig->nMaxFilters, 1) > 0 ) + if (pTnsConfig->nMaxFilters > 1) { - - IF ( sub(pTnsConfig->iFilterBorders[0],512) < 0 ) + if (pTnsConfig->iFilterBorders[0] < 512) { - GetParameters(tnsEnabledSWBTCX10BitMap, 1, pTnsData, &stream, pnSize, pnBits); + GetParameters(&tnsEnabledSWBTCX10BitMap, 1, pTnsData, &stream, pnSize, pnBits); } - ELSE + else { - GetParameters(tnsEnabledSWBTCX20BitMap, 1, pTnsData, &stream, pnSize, pnBits); + GetParameters(&tnsEnabledSWBTCX20BitMap, 1, pTnsData, &stream, pnSize, pnBits); } } - ELSE + else { - GetParameters(tnsEnabledWBTCX20BitMap, 1, pTnsData, &stream, pnSize, pnBits); + GetParameters(&tnsEnabledWBTCX20BitMap, 1, pTnsData, &stream, pnSize, pnBits); } - return TNS_NO_ERROR; } -Word16 WriteTnsData(STnsConfig const * pTnsConfig, Word16 const * stream, Word16 * pnSize, Encoder_State_fx *st, Word16 * pnBits) +TNS_ERROR WriteTnsData(STnsConfig const * pTnsConfig, int const * stream, int * pnSize, Encoder_State *st, int * pnBits) { - - IF ( sub(pTnsConfig->nMaxFilters,1) > 0 ) + if (pTnsConfig->nMaxFilters > 1) { - - IF ( sub(pTnsConfig->iFilterBorders[0],512) < 0 ) + if (pTnsConfig->iFilterBorders[0] < 512) { - WriteToBitstream(tnsEnabledSWBTCX10BitMap, 1, &stream, pnSize, st, pnBits); + WriteToBitstream(&tnsEnabledSWBTCX10BitMap, 1, &stream, pnSize, st, pnBits); } - ELSE + else { - WriteToBitstream(tnsEnabledSWBTCX20BitMap, 1, &stream, pnSize, st, pnBits); + WriteToBitstream(&tnsEnabledSWBTCX20BitMap, 1, &stream, pnSize, st, pnBits); } } - ELSE + else { - WriteToBitstream(tnsEnabledWBTCX20BitMap, 1, &stream, pnSize, st, pnBits); + WriteToBitstream(&tnsEnabledWBTCX20BitMap, 1, &stream, pnSize, st, pnBits); } - - return TNS_NO_ERROR; } @@ -342,105 +206,110 @@ Word16 WriteTnsData(STnsConfig const * pTnsConfig, Word16 const * stream, Word16 /* Definitions of functions used in the mapping between TNS parameters and a bitstream. */ /*********************************************************************************************/ -/* Helper functions for Hufmann table coding */ +/* Helper functions for hufmann table coding */ /********************************/ /* Private functions */ /********************************/ -static void GetFilterParameters(Word32 rxx[], Word16 maxOrder, STnsFilter * pTnsFilter) +/** Autocorrelation to parcor coefficients. + * Conversion of autocorrelation to parcor/reflection coefficients. + * @param input Autocorrelation function/coefficients. + * @param parCoeff output filter (PARCOR) coefficients. + * @param order filter order. + * @return prediction gain. + */ +static float AutoToParcor(const float input[], float parCoeff[], int order) { - Word16 i; - Word16 parCoeff[TNS_MAX_FILTER_ORDER]; - Word32 epsP[TNS_MAX_FILTER_ORDER+1], L_tmp; -#if TNS_COEF_RES == 5 - Word16 const * values = tnsCoeff5; -#elif TNS_COEF_RES == 4 - Word16 const * values = tnsCoeff4; -#elif TNS_COEF_RES == 3 - Word16 const * values = tnsCoeff3; -#endif - Word16 * indexes = pTnsFilter->coefIndex; + int i, j; + float tmp, tmp2; + float workBuffer[2*TNS_MAX_FILTER_ORDER]; + float * const pWorkBuffer = &workBuffer[order]; /* temp pointer */ /* WMOPS: No need for counting as it can be realized as a separate buffer */ + for(i=0; icoefIndex; + /* Variable initialization */ /* compute TNS filter in lattice (ParCor) form with LeRoux-Gueguen algorithm */ - L_tmp = E_LPC_schur(rxx, parCoeff, epsP, maxOrder); - BASOP_SATURATE_WARNING_OFF /* Allow saturation, this value is compared against a threshold. */ - pTnsFilter->predictionGain = divide3232(L_shr(epsP[0], PRED_GAIN_E), L_tmp); - BASOP_SATURATE_WARNING_ON + pTnsFilter->predictionGain = AutoToParcor(rxx, parCoeff, maxOrder); /* non-linear quantization of TNS lattice coefficients with given resolution */ Parcor2Index(parCoeff, indexes, maxOrder); /* reduce filter order by truncating trailing zeros */ - i = sub(maxOrder,1); - - WHILE ((i >= 0) && (indexes[i] == 0)) + i = maxOrder - 1; + while ((i >= 0) && (indexes[i] == 0)) { - i = sub(i, 1); + --i; + /* Loop condition */ } - - move16(); - pTnsFilter->order = add(i, 1); + pTnsFilter->order = i + 1; /* compute avg(coef*coef) */ - L_tmp = L_deposit_l(0); - - FOR (i = pTnsFilter->order-1; i >= 0; i--) + pTnsFilter->avgSqrCoef = 0; + for (i = pTnsFilter->order-1; i >= 0; i--) { - Word16 value ; - - move16(); - value = shr(values[indexes[i]+INDEX_SHIFT], 1); - - move16(); - L_tmp = L_mac0(L_tmp, value, value); + float const value = values[indexes[i]+INDEX_SHIFT]; + /* Variable initialization */ + pTnsFilter->avgSqrCoef += value * value; } - move16(); - pTnsFilter->avgSqrCoef = round_fx(L_tmp); - - /* assert(maxOrder == 8); - pTnsFilter->avgSqrCoef = shr(pTnsFilter->avgSqrCoef, 3); */ - + pTnsFilter->avgSqrCoef /= maxOrder; } -static void Parcor2Index(const Word16 parCoeff[] /*Q15*/, Word16 index[], Word16 order) +static void Parcor2Index(const float parCoeff[], int index[], int order) { - Word16 nValues; - Word16 const * values; - Word16 i; - Word16 iIndex; - Word16 x; - - - move16(); - move16(); - nValues = 1 << TNS_COEF_RES; -#if TNS_COEF_RES == 5 - values = tnsCoeff5; -#elif TNS_COEF_RES == 4 - values = tnsCoeff4; -#elif TNS_COEF_RES == 3 - values = tnsCoeff3; -#endif - - FOR (i = 0; i < order; i++) + int const nValues = 1 << TNS_COEF_RES; /* WMOPS: This is just a constant */ + float const * values = tnsCoeff4; + int i; + int iIndex; + float x; + for (i = 0; i < order; i++) { - move16(); - move16(); iIndex = 1; x = parCoeff[i]; - - /* parCoeff is in the range of -1.0 ... 1.0 by definition */ - /* assert((x >= FL2WORD16(-1.0f)) && (x <= FL2WORD16(1.0f))); */ - - WHILE ((iIndex < nValues) && (x > add(shr(values[iIndex-1], 1), shr(values[iIndex], 1))) ) + /* Variable initialization */ + assert((x >= -1.0f) && (x <= 1.0f)); + while ((iIndex < nValues) && (x > 0.5f*(values[iIndex-1]+values[iIndex]))) { - iIndex = add(iIndex,1); - + ++iIndex; + /* Loop condition */ } - index[i] = sub(iIndex, 1 + INDEX_SHIFT); + index[i] = (iIndex-1) - INDEX_SHIFT; } - } diff --git a/src/libs/libevs/lib_enc/transient_detection.cpp b/src/libs/libevs/lib_enc/transient_detection.cpp old mode 100755 new mode 100644 index df35023a..bede7001 --- a/src/libs/libevs/lib_enc/transient_detection.cpp +++ b/src/libs/libevs/lib_enc/transient_detection.cpp @@ -1,27 +1,20 @@ /*==================================================================================== - EVS Codec 3GPP TS26.442 Apr 03, 2018. Version 12.11.0 / 13.6.0 / 14.2.0 + EVS Codec 3GPP TS26.443 Nov 13, 2018. Version 12.11.0 / 13.7.0 / 14.3.0 / 15.1.0 ====================================================================================*/ - #include "options.h" -#include "stl.h" -#include "basop_util.h" -#include "prot_fx.h" +#include "stat_enc.h" +#include "cnst.h" +#include "prot.h" #include #include #include #include +#include -/* Exponent of attack threshold. Picked according to current threshold values. */ -#define ATTACKTHRESHOLD_E 4 -/* Exponent of subblock energies and accumulated subblock energies. - The current value of 2 does not prevent saturations to happen in all cases. */ -#define SUBBLOCK_NRG_E 4 -/* Exponent of the subblock energy change. - This value is coupled to the transient detector API. */ -#define SUBBLOCK_NRG_CHANGE_E NRG_CHANGE_E -#define MIN_BLOCK_ENERGY ((Word32)1) + +#define MIN_BLOCK_ENERGY 107.37f /************************************************/ @@ -30,15 +23,15 @@ /* */ /************************************************/ -static void InitDelayBuffer(Word16 nFrameLength, Word16 nDelay, DelayBuffer * pDelayBuffer); -static void InitSubblockEnergies(Word16 nFrameLength, Word16 nDelay, DelayBuffer * pDelayBuffer, SubblockEnergies * pSubblockEnergies); -static void InitTransientDetector(SubblockEnergies * pSubblockEnergies, Word16 nDelay, Word16 nSubblocksToCheck, +static void InitDelayBuffer(int nFrameLength, int nDelay, DelayBuffer * pDelayBuffer); +static void InitSubblockEnergies(int nFrameLength, int nDelay, DelayBuffer * pDelayBuffer, SubblockEnergies * pSubblockEnergies); +static void InitTransientDetector(SubblockEnergies * pSubblockEnergies, int nDelay, int nSubblocksToCheck, TCheckSubblocksForAttack pCheckSubblocksForAttack, - Word16 attackRatioThreshold, TransientDetector * pTransientDetector); -static void UpdateDelayBuffer(Word16 const * input, Word16 nSamplesAvailable, DelayBuffer * pDelayBuffer); -static void HighPassFilter(Word16 const * input, Word16 length, Word16 * pFirState1, Word16 * pFirState2, Word16 * output); -static void UpdateSubblockEnergies(Word16 const * input, Word16 nSamplesAvailable, SubblockEnergies * pSubblockEnergies); -static void CalculateSubblockEnergies(Word16 const * input, Word16 nSamplesAvailable, SubblockEnergies * pSubblockEnergies); + float attackRatioThreshold, TransientDetector * pTransientDetector); +static void UpdateDelayBuffer(float const * input, int nSamplesAvailable, DelayBuffer * pDelayBuffer); +static void HighPassFilter(float const * input, int length, float * pFirState1, float * pFirState2, float * output); +static void UpdateSubblockEnergies(float const * input, int nSamplesAvailable, SubblockEnergies * pSubblockEnergies); +static void CalculateSubblockEnergies(float const * input, int nSamplesAvailable, SubblockEnergies * pSubblockEnergies); static void RunTransientDetector(TransientDetector * pTransientDetector); /************************************************/ @@ -48,103 +41,95 @@ static void RunTransientDetector(TransientDetector * pTransientDetector); /************************************************/ /** TCX decision. - * Check IF there is an attack in a subblock. Version FOR TCX Long/Short decision. - * See TCheckSubblocksForAttack FOR definition of parameters. + * Check if there is an attack in a subblock. Version for TCX Long/Short decision. + * See TCheckSubblocksForAttack for definition of parameters. * It is assumed that the delay of MDCT overlap was not taken into account, so that the last subblock corresponds to the newest input subblock. */ -static void GetAttackForTCXDecision(Word32 const * pSubblockNrg, Word32 const * pAccSubblockNrg, Word16 nSubblocks, Word16 nPastSubblocks, Word16 attackRatioThreshold, Word16 * pbIsAttackPresent, Word16 * pAttackIndex) +static void GetAttackForTCXDecision(float const * pSubblockNrg, float const * pAccSubblockNrg, int nSubblocks, int nPastSubblocks, float attackRatioThreshold, int * pbIsAttackPresent, int * pAttackIndex) { - Word16 i; - Word16 bIsAttackPresent, attackIndex; - Word16 attackRatioThreshold_1_5; + int i; + int bIsAttackPresent, attackIndex; (void)nPastSubblocks; (void)nSubblocks; assert(nSubblocks >= NSUBBLOCKS); assert(nPastSubblocks >= 2); - /* attackRatioThreshold_1_5 = attackRatioThreshold * 1.5, exponent is ATTACKTHRESHOLD_E+1 */ - attackRatioThreshold_1_5 = add(shr(attackRatioThreshold,2),shr(attackRatioThreshold,1)); - - move16(); - move16(); bIsAttackPresent = FALSE; - attackIndex = 0; + attackIndex = -1; /* Search for the last attack in the subblocks */ - if ( s_or(L_sub(L_shr(pSubblockNrg[-1],ATTACKTHRESHOLD_E), Mpy_32_16_1(pAccSubblockNrg[-1], attackRatioThreshold)) > 0, - L_sub(L_shr(pSubblockNrg[-2],ATTACKTHRESHOLD_E), Mpy_32_16_1(pAccSubblockNrg[-2], attackRatioThreshold)) > 0) ) + if ((pSubblockNrg[-1] > pAccSubblockNrg[-1] * attackRatioThreshold) + || (pSubblockNrg[-2] > pAccSubblockNrg[-2] * attackRatioThreshold) + ) { - move16(); bIsAttackPresent = TRUE; + attackIndex = 0; } - - FOR (i = 0; i < NSUBBLOCKS; i++) + /* PTR_INIT for pSubblockNrg[i-1] */ + for (i = 0; i < NSUBBLOCKS; i++) { - IF ( L_sub(L_shr(pSubblockNrg[i],ATTACKTHRESHOLD_E), Mpy_32_16_1(pAccSubblockNrg[i], attackRatioThreshold)) > 0 ) + if (pSubblockNrg[i] > pAccSubblockNrg[i] * attackRatioThreshold) { if (i < 6) { - move16(); bIsAttackPresent = TRUE; } - - if ( s_and(sub(attackIndex,2) != 0, sub(attackIndex,6) != 0) ) + if ((attackIndex != 2) && (attackIndex != 6)) { - move16(); attackIndex = i; + if ((pSubblockNrg[i] < pAccSubblockNrg[i] * 1.125f * attackRatioThreshold) && (i == 2 || i == 6)) + { + attackIndex++; /* avoid minimum overlap to prevent clicks */ + } } } - ELSE /* no attack, but set index anyway in case of strong energy increase */ + else /* no attack, but set index anyway in case of strong energy increase */ { - IF ( s_and(( L_sub(L_shr(pSubblockNrg[i],1+ATTACKTHRESHOLD_E), Mpy_32_16_1(pSubblockNrg[sub(i,1)], attackRatioThreshold_1_5)) > 0 ), - ( L_sub(L_shr(pSubblockNrg[i],1+ATTACKTHRESHOLD_E), Mpy_32_16_1(pSubblockNrg[sub(i,2)], attackRatioThreshold_1_5)) > 0 )) ) + if ((pSubblockNrg[i] > pSubblockNrg[i-1] * 1.5f * attackRatioThreshold) && + (pSubblockNrg[i] > pSubblockNrg[i-2] * 1.5f * attackRatioThreshold)) { - - if ( s_and(sub(attackIndex,2) != 0, sub(attackIndex,6) != 0) ) + if ((attackIndex != 2) && (attackIndex != 6)) { - move16(); attackIndex = i; + + if (((pSubblockNrg[i] < pSubblockNrg[i-1] * 2.0f * attackRatioThreshold) || + (pSubblockNrg[i] < pSubblockNrg[i-2] * 2.0f * attackRatioThreshold)) && (i == 2 || i == 6)) + { + attackIndex++; /* avoid minimum overlap to prevent clicks */ + } } } } } /* avoid post-echos on click sounds (very short transients) due to TNS aliasing */ - if ( sub(attackIndex,4) == 0 ) + if (attackIndex == 4) { - move16(); attackIndex = 7; } - if ( sub(attackIndex,5) == 0 ) + else if (attackIndex == 5) { - move16(); attackIndex = 6; } - - move16(); - move16(); *pAttackIndex = attackIndex; *pbIsAttackPresent = bIsAttackPresent; - } - /** Initialize TCX transient detector. * See InitTransientDetector for definition of parameters. */ -static void InitTCXTransientDetector(Word16 nDelay, SubblockEnergies * pSubblockEnergies, TransientDetector * pTransientDetector) +static void InitTCXTransientDetector(int nDelay, SubblockEnergies * pSubblockEnergies, TransientDetector * pTransientDetector) { - InitTransientDetector(pSubblockEnergies, nDelay, NSUBBLOCKS, GetAttackForTCXDecision, 17408/*8.5f/(1<delayBuffer, &pTransientDetection->subblockEnergies); /* Init the TCX Short/Long transient detector. */ InitTCXTransientDetector(nTCXDelay, &pTransientDetection->subblockEnergies, &pTransientDetection->transientDetector); - /* We need two past subblocks for the TCX TD and NSUBBLOCKS+1 for the temporal flatness measure FOR the TCX LTP. */ - pTransientDetection->transientDetector.pSubblockEnergies->nDelay = - add(pTransientDetection->transientDetector.pSubblockEnergies->nDelay, NSUBBLOCKS+1); + /* We need two past subblocks for the TCX TD and NSUBBLOCKS+1 for the temporal flatness measure for the TCX LTP. */ + pTransientDetection->transientDetector.pSubblockEnergies->nDelay += NSUBBLOCKS+1; } -/** - * \brief Calculate average of temporal energy change. - * \return average temporal energy change with exponent = 8 - */ -Word16 GetTCXAvgTemporalFlatnessMeasure(struct TransientDetection const * pTransientDetection, Word16 nCurrentSubblocks, Word16 nPrevSubblocks) +float GetTCXAvgTemporalFlatnessMeasure(struct TransientDetection const * pTransientDetection, int nCurrentSubblocks, int nPrevSubblocks) { - Word16 i; - TransientDetector const * pTransientDetector; - SubblockEnergies const * pSubblockEnergies; - Word16 nDelay; - Word16 nRelativeDelay; - Word16 const * pSubblockNrgChange; - Word32 sumTempFlatness; - Word16 nTotBlocks; - - + int i; + TransientDetector const * pTransientDetector = &pTransientDetection->transientDetector; + SubblockEnergies const * pSubblockEnergies = pTransientDetector->pSubblockEnergies; + int const nDelay = pTransientDetector->nDelay; /* */ + int const nRelativeDelay = pSubblockEnergies->nDelay - nDelay; /* */ + float const * pSubblockNrgChange = NULL; + float sumTempFlatness; + int const nTotBlocks = nCurrentSubblocks+nPrevSubblocks; /* */ /* Initialization */ - pTransientDetector = &pTransientDetection->transientDetector; - pSubblockEnergies = pTransientDetector->pSubblockEnergies; - move16(); - nDelay = pTransientDetector->nDelay; - nRelativeDelay = sub(pSubblockEnergies->nDelay, nDelay); - pSubblockNrgChange = NULL; - nTotBlocks = add(nCurrentSubblocks,nPrevSubblocks); - assert(nTotBlocks > 0); - - sumTempFlatness = L_deposit_l(0); - - assert((nPrevSubblocks <= nRelativeDelay) && (nCurrentSubblocks <= NSUBBLOCKS+nDelay)); - - move16(); - pSubblockNrgChange = &pSubblockEnergies->subblockNrgChange[sub(nRelativeDelay,nPrevSubblocks)]; - - FOR (i = 0; i < nTotBlocks; i++) - { - sumTempFlatness = L_add(sumTempFlatness, L_deposit_l(pSubblockNrgChange[i])); - } - - /* exponent = AVG_FLAT_E */ - i = div_l(L_shl(sumTempFlatness,16-15+SUBBLOCK_NRG_CHANGE_E-AVG_FLAT_E), nTotBlocks); - - return i; -} - -Word16 GetTCXMaxenergyChange(struct TransientDetection const * pTransientDetection, - const Word8 isTCX10, - const Word16 nCurrentSubblocks, const Word16 nPrevSubblocks) -{ - Word16 i; - TransientDetector const * pTransientDetector; - SubblockEnergies const * pSubblockEnergies; - Word16 nDelay; - Word16 nRelativeDelay; - Word16 const * pSubblockNrgChange; - Word16 maxEnergyChange; - Word16 nTotBlocks; - - - pTransientDetector = &pTransientDetection->transientDetector; - pSubblockEnergies = pTransientDetector->pSubblockEnergies; - move16(); - nDelay = pTransientDetector->nDelay; - nRelativeDelay = sub(pSubblockEnergies->nDelay, nDelay); - pSubblockNrgChange = NULL; - nTotBlocks = nCurrentSubblocks+nPrevSubblocks; - - assert(nTotBlocks > 0); - maxEnergyChange = 0/*0.0f Q7*/; + sumTempFlatness = 0.0f; assert((nPrevSubblocks <= nRelativeDelay) && (nCurrentSubblocks <= NSUBBLOCKS+nDelay)); pSubblockNrgChange = &pSubblockEnergies->subblockNrgChange[nRelativeDelay-nPrevSubblocks]; - - IF ( s_or(pTransientDetector->bIsAttackPresent, isTCX10) ) /* frame is TCX-10 */ + for (i = 0; i < nTotBlocks; i++) { - Word32 const * pSubblockNrg = &pSubblockEnergies->subblockNrg[sub(nRelativeDelay,nPrevSubblocks)]; - Word32 nrgMin, nrgMax; - Word16 idxMax = 0; - - move16(); - - nrgMax = L_add(pSubblockNrg[0], 0); - - /* find subblock with maximum energy */ - FOR (i = 1; i < nTotBlocks; i++) - { - if ( L_sub(nrgMax, pSubblockNrg[i]) < 0 ) - { - idxMax = i; - move16(); - } - nrgMax = L_max(nrgMax, pSubblockNrg[i]); - } - - nrgMin = L_add(nrgMax, 0); - - /* find minimum energy after maximum */ - FOR (i = idxMax + 1; i < nTotBlocks; i++) - { - nrgMin = L_min(nrgMin, pSubblockNrg[i]); - } - /* lower maxEnergyChange if energy doesn't decrease much after energy peak */ - /* if (nrgMin > 0.375f * nrgMax) */ - if ( 0 > L_sub(Mpy_32_16_1(nrgMax, 12288/*0.375f Q15*/), nrgMin) ) - { - nTotBlocks = sub(idxMax, 3); - } + sumTempFlatness += pSubblockNrgChange[i]; } - - FOR (i = 0; i < nTotBlocks; i++) - { - maxEnergyChange = s_max(maxEnergyChange, pSubblockNrgChange[i]); - } - - move16(); - i = maxEnergyChange; - - return i; + return sumTempFlatness / (float)nTotBlocks; } -void RunTransientDetection(Word16 const * input, Word16 nSamplesAvailable, TransientDetection * pTransientDetection) +float GetTCXMaxenergyChange(struct TransientDetection const * pTransientDetection, + const int isTCX10, + const int nCurrentSubblocks, const int nPrevSubblocks) { - Word16 filteredInput[L_FRAME48k]; - SubblockEnergies * pSubblockEnergies = &pTransientDetection->subblockEnergies; - TransientDetector * pTransientDetector = &pTransientDetection->transientDetector; + int i; + TransientDetector const * pTransientDetector = &pTransientDetection->transientDetector; + SubblockEnergies const * pSubblockEnergies = pTransientDetector->pSubblockEnergies; + int const nDelay = pTransientDetector->nDelay; /* */ + int const nRelativeDelay = pSubblockEnergies->nDelay - nDelay; /* */ + float const * pSubblockNrgChange = NULL; + float maxEnergyChange; + int nTotBlocks = nCurrentSubblocks+nPrevSubblocks; /* */ + /* Initialization */ + assert(nTotBlocks > 0); + maxEnergyChange = 0.0f; + + assert((nPrevSubblocks <= nRelativeDelay) && (nCurrentSubblocks <= NSUBBLOCKS+nDelay)); + pSubblockNrgChange = &pSubblockEnergies->subblockNrgChange[nRelativeDelay-nPrevSubblocks]; + if (pTransientDetector->bIsAttackPresent || isTCX10) /* frame is TCX-10 */ + { + float const * pSubblockNrg = &pSubblockEnergies->subblockNrg[nRelativeDelay-nPrevSubblocks]; + float nrgMin, nrgMax = pSubblockNrg[0]; + int idxMax = 0; + /* find subblock with maximum energy */ + for (i = 1; i < nTotBlocks; i++) + { + if (nrgMax < pSubblockNrg[i]) + { + nrgMax = pSubblockNrg[i]; + idxMax = i; + } + } + nrgMin = nrgMax; + /* find minimum energy after maximum */ + for (i = idxMax + 1; i < nTotBlocks; i++) + { + if (nrgMin > pSubblockNrg[i]) + { + nrgMin = pSubblockNrg[i]; + } + } + /* lower maxEnergyChange if energy doesn't decrease much after energy peak */ + if (nrgMin > 0.375f * nrgMax) + { + nTotBlocks = idxMax - 3; + } + } + for (i = 0; i < nTotBlocks; i++) + { + maxEnergyChange = max(maxEnergyChange, pSubblockNrgChange[i]); + } + + return maxEnergyChange; +} + +/*---------------------------------------------------------------* + * RunTransientDetection() + * + * Time Domain Transient Detector for TCX + *---------------------------------------------------------------*/ + +void RunTransientDetection( + float const * input, + int nSamplesAvailable, + TransientDetection * pTransientDetection +) +{ + float filteredInput[L_FRAME_MAX]; + SubblockEnergies * pSubblockEnergies = &pTransientDetection->subblockEnergies; /* */ + TransientDetector * pTransientDetector = &pTransientDetection->transientDetector; /* */ assert((input != NULL) && (pTransientDetection != NULL) && (pSubblockEnergies != NULL) && (pTransientDetector != NULL)); - + /* Variable initializations */ HighPassFilter(input, nSamplesAvailable, &pSubblockEnergies->firState1, &pSubblockEnergies->firState2, filteredInput); /* Update subblock energies. */ @@ -296,130 +248,114 @@ void RunTransientDetection(Word16 const * input, Word16 nSamplesAvailable, Trans /* Update the delay buffer. */ UpdateDelayBuffer(filteredInput, nSamplesAvailable, &pTransientDetection->delayBuffer); + + return; } -void SetTCXModeInfo(Encoder_State_fx *st, - TransientDetection const * pTransientDetection, - Word16 * tcxModeOverlap) -{ - assert(pTransientDetection != NULL); - IF( sub(st->codec_mode,MODE2) == 0 ) +void SetTCXModeInfo(Encoder_State *st, /* i/o: encoder state structure */ + TransientDetection const * pTransientDetection, + short * tcxModeOverlap + ) +{ + if( st->codec_mode == MODE2 ) { + assert(pTransientDetection != NULL); /* determine window sequence (1 long or 2 short windows) */ - - test(); - IF ( st->tcx10Enabled != 0 && st->tcx20Enabled != 0 ) + if (st->tcx10Enabled && st->tcx20Enabled) { /* window switching based on transient detector output */ - test(); - test(); - test(); - IF ( ((pTransientDetection->transientDetector.bIsAttackPresent != 0) - || (L_sub(Mpy_32_16_1(st->currEnergyHF_fx, 840/*1.0f/39.0f Q15*/), st->prevEnergyHF_fx) > 0)) - && ((sub(st->last_core_fx, ACELP_CORE) != 0) && (sub(st->last_core_fx, AMR_WB_CORE) != 0)) ) + if ( + ((pTransientDetection->transientDetector.bIsAttackPresent) + || (st->currEnergyHF > st->prevEnergyHF * 39.0f)) && + ((st->last_core != ACELP_CORE) && (st->last_core != AMR_WB_CORE))) { - move16(); st->tcxMode = TCX_10; } - ELSE + else { - move16(); st->tcxMode = TCX_20; } } - ELSE + else { /* window selection (non-adaptive) based on flags only */ - IF (st->tcx10Enabled) + if (st->tcx10Enabled) { - move16(); st->tcxMode = TCX_10; } - ELSE IF (st->tcx20Enabled) + else if (st->tcx20Enabled) { - move16(); st->tcxMode = TCX_20; } - ELSE { - move16(); + else + { st->tcxMode = NO_TCX; } } - test(); - test(); - IF (st->last_core_fx == ACELP_CORE || st->last_core_fx == AMR_WB_CORE) + + /* set the left window overlap */ + + if (st->last_core == ACELP_CORE || st->last_core == AMR_WB_CORE) { - move16(); st->tcx_cfg.tcx_last_overlap_mode = TRANSITION_OVERLAP; } - ELSE IF ( (sub(st->tcxMode, TCX_10) == 0) && (sub(st->tcx_cfg.tcx_curr_overlap_mode, ALDO_WINDOW) == 0)) + else if ((st->tcxMode == TCX_10) && (st->tcx_cfg.tcx_curr_overlap_mode == ALDO_WINDOW)) { - move16(); st->tcx_cfg.tcx_last_overlap_mode = FULL_OVERLAP; } - ELSE + else { - move16(); st->tcx_cfg.tcx_last_overlap_mode = st->tcx_cfg.tcx_curr_overlap_mode; } - /* determine window overlaps (0 full, 2 none, or 3 half) */ - - IF ( sub(st->tcxMode, TCX_10) == 0 ) + /* determine the right window overlap */ + if( st->tcxMode == TCX_10 ) { - IF( pTransientDetection->transientDetector.attackIndex < 0) + if (pTransientDetection->transientDetector.attackIndex < 0) { - move16(); *tcxModeOverlap = HALF_OVERLAP; } - ELSE + else { - move16(); - *tcxModeOverlap = s_and(pTransientDetection->transientDetector.attackIndex, 3); - if ( sub(*tcxModeOverlap,1) == 0 ) + *tcxModeOverlap = pTransientDetection->transientDetector.attackIndex % 4; + if (*tcxModeOverlap == 1) { - move16(); *tcxModeOverlap = FULL_OVERLAP; } } } - ELSE IF ( sub(st->tcxMode, TCX_20) == 0 ) + else if (st->tcxMode == TCX_20) { - IF (sub(pTransientDetection->transientDetector.attackIndex, 7) == 0) + if (pTransientDetection->transientDetector.attackIndex == 7) { - move16(); *tcxModeOverlap = HALF_OVERLAP; } - ELSE IF (sub(pTransientDetection->transientDetector.attackIndex, 6) == 0) + else if (pTransientDetection->transientDetector.attackIndex == 6) { - move16(); *tcxModeOverlap = MIN_OVERLAP; } - ELSE + else { - move16(); *tcxModeOverlap = ALDO_WINDOW; } } - ELSE /* NO_TCX */ + else { - move16(); + /* NO_TCX */ *tcxModeOverlap = TRANSITION_OVERLAP; } - test(); - if ((sub(st->tcx_cfg.tcx_last_overlap_mode, TRANSITION_OVERLAP) == 0) && (sub(*tcxModeOverlap, ALDO_WINDOW) == 0)) + + /* for the ACELP -> TCX transition frames use full right window overlap */ + + if ((st->tcx_cfg.tcx_last_overlap_mode == TRANSITION_OVERLAP) && (*tcxModeOverlap == ALDO_WINDOW)) { - move16(); *tcxModeOverlap = FULL_OVERLAP; } - - /* Sanity check */ - assert(*tcxModeOverlap !=1); - } + return; } /************************************************/ @@ -428,164 +364,150 @@ void SetTCXModeInfo(Encoder_State_fx *st, /* */ /************************************************/ -static void InitDelayBuffer(Word16 nFrameLength, Word16 nDelay, DelayBuffer * pDelayBuffer) +static void InitDelayBuffer(int nFrameLength, int nDelay, DelayBuffer * pDelayBuffer) { - Word16 const nMaxBuffSize = sizeof(pDelayBuffer->buffer)/sizeof(pDelayBuffer->buffer[0]); + int const nMaxBuffSize = sizeof(pDelayBuffer->buffer)/sizeof(pDelayBuffer->buffer[0]); - - move16(); - move16(); assert((nFrameLength > NSUBBLOCKS) && (nFrameLength % NSUBBLOCKS == 0) && (nDelay >= 0) && (pDelayBuffer != NULL)); pDelayBuffer->nSubblockSize = nFrameLength/NSUBBLOCKS; assert(pDelayBuffer->nSubblockSize <= nMaxBuffSize); - set16_fx(pDelayBuffer->buffer, 0, nMaxBuffSize); + set_f(pDelayBuffer->buffer, 0.0f, nMaxBuffSize); pDelayBuffer->nDelay = nDelay % pDelayBuffer->nSubblockSize; assert(pDelayBuffer->nDelay <= nMaxBuffSize); + return; } -static void InitSubblockEnergies(Word16 nFrameLength, Word16 nDelay, DelayBuffer * pDelayBuffer, SubblockEnergies * pSubblockEnergies) -{ - Word16 const nMaxBuffSize = sizeof(pSubblockEnergies->subblockNrg)/sizeof(pSubblockEnergies->subblockNrg[0]); - (void)nFrameLength; +static void InitSubblockEnergies(int nFrameLength, int nDelay, DelayBuffer * pDelayBuffer, SubblockEnergies * pSubblockEnergies) +{ + int const nMaxBuffSize = sizeof(pSubblockEnergies->subblockNrg)/sizeof(pSubblockEnergies->subblockNrg[0]); + (void)nFrameLength; assert((pDelayBuffer != NULL) && (pSubblockEnergies != NULL) && (pDelayBuffer->nSubblockSize * NSUBBLOCKS == nFrameLength) && (pDelayBuffer->nSubblockSize > 0)); - set32_fx(pSubblockEnergies->subblockNrg, MIN_BLOCK_ENERGY, nMaxBuffSize); - set32_fx(pSubblockEnergies->accSubblockNrg, MIN_BLOCK_ENERGY, nMaxBuffSize+1); - set16_fx(pSubblockEnergies->subblockNrgChange, 0x7fff, nMaxBuffSize); + set_f(pSubblockEnergies->subblockNrg, MIN_BLOCK_ENERGY, nMaxBuffSize); + set_f(pSubblockEnergies->accSubblockNrg, MIN_BLOCK_ENERGY, nMaxBuffSize+1); + set_f(pSubblockEnergies->subblockNrgChange, 1.0f, nMaxBuffSize); pSubblockEnergies->nDelay = nDelay / pDelayBuffer->nSubblockSize; assert(pSubblockEnergies->nDelay < nMaxBuffSize); pSubblockEnergies->nPartialDelay = nDelay % pDelayBuffer->nSubblockSize; - pSubblockEnergies->facAccSubblockNrg = 26624/*0.8125f Q15*/; /* Energy accumulation factor */ - pSubblockEnergies->firState1 = 0; - pSubblockEnergies->firState2 = 0; + pSubblockEnergies->facAccSubblockNrg = 0.8125f; /* Energy accumulation factor */ + pSubblockEnergies->firState1 = 0.0f; + pSubblockEnergies->firState2 = 0.0f; pSubblockEnergies->pDelayBuffer = pDelayBuffer; - pDelayBuffer->nDelay = s_max(pDelayBuffer->nDelay, pSubblockEnergies->nPartialDelay); + pDelayBuffer->nDelay = max(pDelayBuffer->nDelay, pSubblockEnergies->nPartialDelay); + return; } /** Init transient detector. * Fills TransientDetector structure with sensible content and enable it. * @param pSubblockEnergies Subblock energies used in this transient detector. - * @param nDelay Delay FOR this transient detector. + * @param nDelay Delay for this transient detector. * @param nSubblocksToCheck Number of subblocks to check in this transient detector. - * @param pCheckSubblockForAttack Attack detection function FOR this transient detector. - * @param pSetAttackPosition Function FOR finalizing this transient detector. - * @param attackRatioThreshold Attack ratio threshold with exponent ATTACKTHRESHOLD_E. + * @param pCheckSubblockForAttack Attack detection function for this transient detector. + * @param pSetAttackPosition Function for finalizing this transient detector. + * @param attackRatioThreshold Attack ratio threshold. * @param pTransientDetector Structure to be initialized. */ -static void InitTransientDetector(SubblockEnergies * pSubblockEnergies, Word16 nDelay, Word16 nSubblocksToCheck, +static void InitTransientDetector(SubblockEnergies * pSubblockEnergies, int nDelay, int nSubblocksToCheck, TCheckSubblocksForAttack pCheckSubblocksForAttack, - Word16 attackRatioThreshold, TransientDetector * pTransientDetector) + float attackRatioThreshold, TransientDetector * pTransientDetector) { - Word16 nMaxBuffSize; - - move16(); - nMaxBuffSize = sizeof(pSubblockEnergies->subblockNrg)/sizeof(pSubblockEnergies->subblockNrg[0]); - + int const nMaxBuffSize = sizeof(pSubblockEnergies->subblockNrg)/sizeof(pSubblockEnergies->subblockNrg[0]); + (void)nMaxBuffSize; assert((pSubblockEnergies != NULL) && (pSubblockEnergies->pDelayBuffer != NULL) && (pTransientDetector != NULL) && (pSubblockEnergies->pDelayBuffer->nSubblockSize != 0)); pTransientDetector->pSubblockEnergies = pSubblockEnergies; pTransientDetector->nDelay = (nDelay - pSubblockEnergies->nPartialDelay) / pSubblockEnergies->pDelayBuffer->nSubblockSize; assert(nDelay == pTransientDetector->nDelay * pSubblockEnergies->pDelayBuffer->nSubblockSize + pSubblockEnergies->nPartialDelay); assert(pTransientDetector->nDelay < nMaxBuffSize); - pSubblockEnergies->nDelay = s_max(pSubblockEnergies->nDelay, pTransientDetector->nDelay); + pSubblockEnergies->nDelay = max(pSubblockEnergies->nDelay, pTransientDetector->nDelay); assert(nSubblocksToCheck <= NSUBBLOCKS + pTransientDetector->nDelay); pTransientDetector->nSubblocksToCheck = nSubblocksToCheck; pTransientDetector->CheckSubblocksForAttack = pCheckSubblocksForAttack; pTransientDetector->attackRatioThreshold = attackRatioThreshold; pTransientDetector->bIsAttackPresent = FALSE; pTransientDetector->attackIndex = -1; + + return; } /* This function should be inlined and WMOPS instrumentation takes that into account, meaning that all references are considered as local variables */ -static Word32 InlineFilter(Word16 inValue, Word16 firState1, Word16 firState2) +static float InlineFilter(float inValue, float firState1, float firState2) { - /* 0.375f * inValue - 0.5f * firState1 + 0.125f * firState2 */ - - return L_msu(L_mac(L_mult(firState2, 4096/*0.125f Q15*/), inValue, 12288/*0.375f Q15*/), firState1, 16384/*0.5f Q15*/); + return 0.375f * inValue - 0.5f * firState1 + 0.125f * firState2; } -static void HighPassFilter(Word16 const * input, Word16 length, Word16 * pFirState1, Word16 * pFirState2, Word16 * output) + +static void HighPassFilter(float const * input, int length, float * pFirState1, float * pFirState2, float * output) { - Word16 i; - - output[0] = round_fx(InlineFilter(input[0], *pFirState1, *pFirState2)); - output[1] = round_fx(InlineFilter(input[1], input[0], *pFirState1)); - - FOR (i = 2; i < length; i++) + int i; + output[0] = InlineFilter(input[0], *pFirState1, *pFirState2); + output[1] = InlineFilter(input[1], input[0], *pFirState1); + for (i = 2; i < length; i++) { - output[i] = round_fx(InlineFilter(input[i], input[i-1], input[i-2])); + output[i] = InlineFilter(input[i], input[i-1], input[i-2]); } - /* update filter states: shift time samples through delay line */ - move16(); - move16(); *pFirState2 = input[length-2]; *pFirState1 = input[length-1]; + return; } + static void RunTransientDetector(TransientDetector * pTransientDetector) { - Word16 const attackRatioThreshold = pTransientDetector->attackRatioThreshold; - SubblockEnergies const * pSubblockEnergies = pTransientDetector->pSubblockEnergies; - Word16 const nDelay = pTransientDetector->nDelay; - Word16 const nRelativeDelay = pSubblockEnergies->nDelay - nDelay; - Word32 const * pSubblockNrg = &pSubblockEnergies->subblockNrg[nRelativeDelay]; - Word32 const * pAccSubblockNrg = &pSubblockEnergies->accSubblockNrg[nRelativeDelay]; + float const attackRatioThreshold = pTransientDetector->attackRatioThreshold; /* */ + SubblockEnergies const * pSubblockEnergies = pTransientDetector->pSubblockEnergies; /* */ + int const nDelay = pTransientDetector->nDelay; /* */ + int const nRelativeDelay = pSubblockEnergies->nDelay - nDelay; /* */ + float const * pSubblockNrg = &pSubblockEnergies->subblockNrg[nRelativeDelay]; /* */ + float const * pAccSubblockNrg = &pSubblockEnergies->accSubblockNrg[nRelativeDelay]; /* */ assert((pTransientDetector->CheckSubblocksForAttack != NULL)); - + /* Variable initialization */ pTransientDetector->CheckSubblocksForAttack(pSubblockNrg, pAccSubblockNrg, NSUBBLOCKS+nDelay, nRelativeDelay, attackRatioThreshold, &pTransientDetector->bIsAttackPresent, &pTransientDetector->attackIndex); + return; } -static void UpdateDelayBuffer(Word16 const * input, Word16 nSamplesAvailable, DelayBuffer * pDelayBuffer) +static void UpdateDelayBuffer(float const * input, int nSamplesAvailable, DelayBuffer * pDelayBuffer) { - Word16 i; - Word16 nDelay; - - - move16(); - nDelay = pDelayBuffer->nDelay; - + int i; + int const nDelay = pDelayBuffer->nDelay; assert((nDelay >= 0) && (nDelay <= (int)sizeof(pDelayBuffer->buffer)/(int)sizeof(pDelayBuffer->buffer[0]))); assert(nSamplesAvailable <= NSUBBLOCKS*pDelayBuffer->nSubblockSize); /* If this is not the last frame */ - IF (nSamplesAvailable == NSUBBLOCKS*pDelayBuffer->nSubblockSize) + if (nSamplesAvailable == NSUBBLOCKS*pDelayBuffer->nSubblockSize) { /* Store the newest samples into the delay buffer */ - FOR (i = 0; i < nDelay; i++) + for (i = 0; i < nDelay; i++) { - move16(); pDelayBuffer->buffer[i] = input[i+nSamplesAvailable-nDelay]; } } + return; } -static void UpdateSubblockEnergies(Word16 const * input, Word16 nSamplesAvailable, SubblockEnergies * pSubblockEnergies) + +static void UpdateSubblockEnergies(float const * input, int nSamplesAvailable, SubblockEnergies * pSubblockEnergies) { - Word16 i; - - + int i; assert((pSubblockEnergies->nDelay >= 0) && (pSubblockEnergies->nDelay+NSUBBLOCKS <= (int)sizeof(pSubblockEnergies->subblockNrg)/(int)sizeof(pSubblockEnergies->subblockNrg[0]))); assert(pSubblockEnergies->nPartialDelay <= pSubblockEnergies->pDelayBuffer->nDelay); /* At least one block delay is required when subblock energy change is required */ assert(pSubblockEnergies->nDelay >= 1); /* Shift old subblock energies */ - FOR (i = 0; i < pSubblockEnergies->nDelay; i++) + for (i = 0; i < pSubblockEnergies->nDelay; i++) { - move32(); - move32(); - move16(); pSubblockEnergies->subblockNrg[i] = pSubblockEnergies->subblockNrg[i+NSUBBLOCKS]; pSubblockEnergies->accSubblockNrg[i] = pSubblockEnergies->accSubblockNrg[i+NSUBBLOCKS]; pSubblockEnergies->subblockNrgChange[i] = pSubblockEnergies->subblockNrgChange[i+NSUBBLOCKS]; @@ -594,136 +516,83 @@ static void UpdateSubblockEnergies(Word16 const * input, Word16 nSamplesAvailabl /* Compute filtered subblock energies for the new samples */ CalculateSubblockEnergies(input, nSamplesAvailable, pSubblockEnergies); + return; } + /* This function should be inlined and WMOPS instrumentation takes that into account, meaning that all references are considered as local variables */ -static void UpdatedAndStoreAccWindowNrg(Word32 newWindowNrgF, Word32 * pAccSubblockNrg, Word16 facAccSubblockNrg, Word32 * pOutAccWindowNrgF) +static void UpdatedAndStoreAccWindowNrg(float newWindowNrgF, float * pAccSubblockNrg, float facAccSubblockNrg, float * pOutAccWindowNrgF) { /* Store the accumulated energy */ - move32(); *pOutAccWindowNrgF = *pAccSubblockNrg; /* Update the accumulated energy: maximum of the current and the accumulated energy */ - *pAccSubblockNrg = Mpy_32_16_1(*pAccSubblockNrg, facAccSubblockNrg); - - if ( L_sub(newWindowNrgF, *pAccSubblockNrg) > 0 ) + *pAccSubblockNrg *= facAccSubblockNrg; + if (newWindowNrgF > *pAccSubblockNrg) { - move32(); *pAccSubblockNrg = newWindowNrgF; } + + return; } -static void CalculateSubblockEnergies(Word16 const * input, Word16 nSamplesAvailable, SubblockEnergies * pSubblockEnergies) + +static void CalculateSubblockEnergies(float const * input, int nSamplesAvailable, SubblockEnergies * pSubblockEnergies) { - DelayBuffer * pDelayBuffer; - Word16 nSubblockSize; - Word16 nDelay; - Word16 nPartialDelay; - Word16 * delayBuffer; - Word16 facAccSubblockNrg; - Word32 * pSubblockNrg; - Word32 * pAccSubblockNrg; - Word16 * pSubblockNrgChange; - Word32 * pAccSubblockTmp; - Word16 nWindows; - Word16 w, k, k2, tmp; - Word16 firState1, firState2; - Word32 w0, w1; - Word32 accu; - - move16(); - pDelayBuffer = pSubblockEnergies->pDelayBuffer; - facAccSubblockNrg = pSubblockEnergies->facAccSubblockNrg; - - move16(); - move16(); - move16(); - nSubblockSize = pDelayBuffer->nSubblockSize; - nDelay = pSubblockEnergies->nDelay; - nPartialDelay = pSubblockEnergies->nPartialDelay; - - delayBuffer = &pDelayBuffer->buffer[sub(pDelayBuffer->nDelay, nPartialDelay)]; - pSubblockNrg = &pSubblockEnergies->subblockNrg[nDelay]; - pAccSubblockNrg = &pSubblockEnergies->accSubblockNrg[nDelay]; - pSubblockNrgChange = &pSubblockEnergies->subblockNrgChange[nDelay]; - - move16(); - move16(); - /* nWindows = (nSamplesAvailable + nPartialDelay) / nSubblockSize */ - nWindows = shr(div_s( add(nSamplesAvailable,nPartialDelay), shl(nSubblockSize, 7)),8); - firState1 = pSubblockEnergies->firState1; - firState2 = pSubblockEnergies->firState2; + DelayBuffer * pDelayBuffer = pSubblockEnergies->pDelayBuffer; /* */ + int const nSubblockSize = pDelayBuffer->nSubblockSize; /* */ + int const nDelay = pSubblockEnergies->nDelay; /* */ + int const nPartialDelay = pSubblockEnergies->nPartialDelay; /* */ + float const * delayBuffer = &pDelayBuffer->buffer[pDelayBuffer->nDelay - nPartialDelay]; /* */ + float const facAccSubblockNrg = pSubblockEnergies->facAccSubblockNrg; /* */ + float * pSubblockNrg = &pSubblockEnergies->subblockNrg[nDelay]; /* */ + float * pAccSubblockNrg = &pSubblockEnergies->accSubblockNrg[nDelay]; /* */ + float * pSubblockNrgChange = &pSubblockEnergies->subblockNrgChange[nDelay]; /* */ + float * pAccSubblockTmp; + int nWindows; + int i, w, k; + /* Variable initializations */ + nWindows = (nSamplesAvailable+nPartialDelay)/nSubblockSize; pAccSubblockTmp = &pAccSubblockNrg[nWindows]; - IF (nWindows > 0) + set_f(pSubblockNrg, MIN_BLOCK_ENERGY, NSUBBLOCKS); + if (nWindows > 0) { /* Process left over samples from the previous frame. */ - accu = L_add(MIN_BLOCK_ENERGY, 0); - assert((SUBBLOCK_NRG_E & 1) == 0); - FOR (k = 0; k < nPartialDelay; k++) + for (k = 0; k < nPartialDelay; k++) { - tmp = shr(delayBuffer[k], SUBBLOCK_NRG_E/2); - accu = L_mac0(accu, tmp, tmp); + pSubblockNrg[0] += delayBuffer[k] * delayBuffer[k]; } - + k = 0; /* Process new samples in the 0. subblock. */ - w = sub(nSubblockSize,nPartialDelay); - assert((SUBBLOCK_NRG_E & 1) == 0); - FOR (k = 0; k < w; k++) + for (i = nPartialDelay; i < nSubblockSize; i++, k++) { - tmp = shr(input[k], SUBBLOCK_NRG_E/2); - accu = L_mac0(accu, tmp, tmp); + pSubblockNrg[0] += input[k] * input[k]; } - - move32(); - pSubblockNrg[0] = accu; /* Set accumulated subblock energy at this point. */ UpdatedAndStoreAccWindowNrg(pSubblockNrg[0], pAccSubblockTmp, facAccSubblockNrg, &pAccSubblockNrg[0]); - - FOR (w = 1; w < nWindows; w++) + for (w = 1; w < nWindows; w++) { - accu = L_add(MIN_BLOCK_ENERGY, 0); /* Process new samples in the w. subblock. */ - k2 = add(k, nSubblockSize); - assert((SUBBLOCK_NRG_E & 1) == 0); - FOR (; k < k2; k++) + for (i = 0; i < nSubblockSize; i++, k++) { - tmp = shr(input[k], SUBBLOCK_NRG_E/2); - accu = L_mac0(accu, tmp, tmp); + pSubblockNrg[w] += input[k] * input[k]; } - move32(); - pSubblockNrg[w] = accu; /* Set accumulated subblock energy at this point. */ UpdatedAndStoreAccWindowNrg(pSubblockNrg[w], pAccSubblockTmp, facAccSubblockNrg, &pAccSubblockNrg[w]); } - /* Calculate energy change for each block. */ - FOR (w = 0; w < nWindows; w++) + for (w = 0; w < nWindows; w++) { - w0 = L_add(pSubblockNrg[w], 0); - w1 = L_add(pSubblockNrg[sub(w,1)], 0); - - IF ( L_sub(w0, w1) > 0 ) + if (pSubblockNrg[w] > pSubblockNrg[w-1]) { - k2 = BASOP_Util_Divide3232_uu_1616_Scale(w0, w1, &k); + pSubblockNrgChange[w] = pSubblockNrg[w]/pSubblockNrg[w-1]; } - ELSE + else { - k2 = BASOP_Util_Divide3232_uu_1616_Scale(w1, w0, &k); - } - move16(); - pSubblockNrgChange[w] = MAX_16; - IF ( sub(k,SUBBLOCK_NRG_CHANGE_E) < 0 ) - { - move16(); - pSubblockNrgChange[w] = shr(k2, sub(SUBBLOCK_NRG_CHANGE_E,k)); + pSubblockNrgChange[w] = pSubblockNrg[w-1]/pSubblockNrg[w]; } } } - move16(); - move16(); - pSubblockEnergies->firState1 = firState1; - pSubblockEnergies->firState2 = firState2; + return; } - - diff --git a/src/libs/libevs/lib_enc/transition_enc.cpp b/src/libs/libevs/lib_enc/transition_enc.cpp new file mode 100644 index 00000000..7806ec9e --- /dev/null +++ b/src/libs/libevs/lib_enc/transition_enc.cpp @@ -0,0 +1,977 @@ +/*==================================================================================== + EVS Codec 3GPP TS26.443 Nov 13, 2018. Version 12.11.0 / 13.7.0 / 14.3.0 / 15.1.0 + ====================================================================================*/ + +#include +#include +#include "options.h" +#include "cnst.h" +#include "rom_com.h" +#include "prot.h" + +/*-----------------------------------------------------------------* + * Local functions + *-----------------------------------------------------------------*/ + +static void gain_trans_enc( float *gain_trans, float exc[], short *quant_index, short *quant_sign ); + +static void tc_enc( Encoder_State *st, const long core_brate, const short L_frame, const short i_subfr, short *tc_subfr, short *position, + const float *h1, const float *xn, float *exc, float *y1, short *T0_min, short *T0_max, short *T0, + short *T0_frac, float *gain_pit, float g_corr[], float *bwe_exc ); + +/*-----------------------------------------------------------------* + * transition_enc() + * + * Principal function for adaptive excitation construction in TC + *-----------------------------------------------------------------*/ + +void transition_enc( + Encoder_State *st, /* i/o: encoder state structure */ + const long core_brate, /* i : core bitrate */ + const short L_frame, /* i : length of the frame */ + const short coder_type, /* i : coding type */ + const short i_subfr, /* i : subframe index */ + short *tc_subfr, /* i/o: TC subframe index */ + short *Jopt_flag, /* i : joint optimization flag */ + short *position, /* i/o: maximum of residual signal index */ + const float voicing[], /* i : normalized correlations (from OL pitch) */ + const short T_op[], /* i : open loop pitch estimates in current frame */ + short *T0, /* i/o: close loop integer pitch */ + short *T0_frac, /* i/o: close loop fractional part of the pitch */ + short *T0_min, /* i/o: lower limit for close-loop search */ + short *T0_max, /* i/o: higher limit for close-loop search */ + float *exc, /* i/o: pointer to excitation signal frame */ + float *y1, /* o : zero-memory filtered adaptive excitation */ + const float *res, /* i : pointer to the LP residual signal frame */ + const float *h1, /* i : weighted filter input response */ + const float *xn, /* i : target vector */ + float *xn2, /* o : target vector for innovation search */ + float *gp_cl, /* i/o: memory of gain of pitch clipping algorithm */ + float *gain_pit, /* o : adaptive excitation gain */ + float *g_corr, /* o : ACELP correlation values */ + short *clip_gain, /* i/o: adaptive gain clipping flag */ + float **pt_pitch, /* o : floating pitch values */ + float *bwe_exc /* o : excitation for SWB TBE */ +) +{ + short i, pit_flag, pit_start, pit_limit, index, nBits; + float temp; + short limit_flag, mult_Top; + short lp_select, lp_flag; + int offset=0; + /* set limit_flag to 0 for restrained limits, and 1 for extended limits */ + limit_flag = 0; + + pit_start = PIT_MIN; + + /*-----------------------------------------------------------------* + * TC: subrame determination for glottal shape search + * ------------------------------------------------------- + * tc_subfr == 0 - TC in 1st subframe + * tc_subfr == TC_0_0 - TC in 1st subframe + information about T0 + * tc_subfr == L_SUBFR - TC in 2nd subframe + * tc_subfr == 2*L_SUBFR - TC in 3rd subframe + * tc_subfr == 3*L_SUBFR - TC in 4th subframe + *-----------------------------------------------------------------*/ + + if( i_subfr == 0 ) + { + if( *tc_subfr == 3*L_SUBFR ) + { + if( L_frame == L_FRAME ) + { + *position = emaximum( res + 3*L_SUBFR,min(T_op[0]+2,L_SUBFR), &temp ) + 3*L_SUBFR; + *tc_subfr = 3*L_SUBFR; + } + else /* L_frame == L_FRAME16k */ + { + *position = emaximum( res + 4*L_SUBFR,min(T_op[0]+2,L_SUBFR), &temp ) + 4*L_SUBFR; + *tc_subfr = 4*L_SUBFR; + } + } + else + { + *position = emaximum( res, (short)(T_op[0]+2), &temp ); + + /* correction in case of possibly wrong T_op (double-pitch values) */ + if( (L_frame == L_FRAME && T_op[0] > 2*PIT_MIN) || + (L_frame == L_FRAME16k && T_op[0] > 2*PIT16k_MIN) + ) + { + short position_tmp, len; + float aver, temp2; + + len = (short)(T_op[0]/2+2); + + position_tmp = emaximum( res, len, &temp2 ); + aver = dotp( res, res, len) + 0.01f; + aver = sqrt(aver/len); + + temp = sqrt(temp); + temp2 = sqrt(temp2); + + if( temp2 > 0.8f * temp && aver < 0.25f * temp ) + { + *position = position_tmp; + } + } + + *tc_subfr = (short) floor((*position)/L_SUBFR)*L_SUBFR; + } + + mult_Top = 1; + if( limit_flag == 0 ) + { + if( L_frame == L_FRAME && T_op[1] < PIT_MIN ) + { + mult_Top = 2; + } + + if( L_frame == L_FRAME16k && T_op[1] < PIT16k_MIN ) + { + mult_Top = 2; + } + } + + limit_T0( L_frame, 8, 0, limit_flag, mult_Top*T_op[1], 0, T0_min, T0_max ); + } + + /*-----------------------------------------------------------------* + * zero adaptive excitation signal construction + *-----------------------------------------------------------------*/ + + if ( *tc_subfr > i_subfr ) + { + *gain_pit = 0.0f; + *clip_gain = 0; + g_corr[0] = 1.0f; + g_corr[1] = 1.0f; + + set_f(&exc[i_subfr], 0, L_SUBFR); /* set excitation for current subrame to 0 */ + + if( L_frame == L_FRAME ) + { + set_f(&bwe_exc[i_subfr*HIBND_ACB_L_FAC], 0, (short) (L_SUBFR*HIBND_ACB_L_FAC)); /* set past excitation buffer to 0 */ + } + else + { + set_f(&bwe_exc[i_subfr*2], 0, (short) (L_SUBFR*2)); /* set past excitation buffer to 0 */ + } + + set_f(y1, 0, L_SUBFR); /* set filtered adaptive excitation to 0 */ + mvr2r(xn, xn2, L_SUBFR); /* target vector for codebook search */ + *T0 = L_SUBFR; + *T0_frac = 0; + + **pt_pitch = (float)(*T0) + (float)(*T0_frac)/4.0f; /* save subframe pitch values */ + } + + /*-----------------------------------------------------------------* + * glottal codebook contribution construction + *-----------------------------------------------------------------*/ + + else if ( *tc_subfr == i_subfr ) + { + if( L_frame == L_FRAME ) + { + set_f( bwe_exc-PIT_MAX*HIBND_ACB_L_FAC, 0, PIT_MAX*HIBND_ACB_L_FAC); /* set past excitation buffer to 0 */ + } + else + { + set_f( bwe_exc-PIT16k_MAX*2, 0, PIT16k_MAX*2); /* set past excitation buffer to 0 */ + } + + tc_enc( st, core_brate, L_frame, i_subfr, tc_subfr, position, h1, xn, exc, y1, T0_min, T0_max, T0, T0_frac, gain_pit, g_corr, bwe_exc ); + + *clip_gain = gp_clip( core_brate, voicing, i_subfr, coder_type, xn, gp_cl ); + updt_tar( xn, xn2, y1, *gain_pit, L_SUBFR ); + + **pt_pitch = (float)(*T0) + (float)(*T0_frac)/4.0f; /* save subframe pitch values */ + *Jopt_flag = 1; + } + + /*--------------------------------------------------------------* + * other subframes -> GENERIC encoding type, + * standard adaptive excitation contribution + * - exemption only in case when first glottal impulse is + * in the 1st subframe and the second one in 2nd subframe + * and later + *--------------------------------------------------------------*/ + + else if ( *tc_subfr < i_subfr) + { + if( L_frame == L_FRAME ) + { + *Jopt_flag = 1; + + /* pit_flag for T0 bits number coding determination */ + if( ((i_subfr - *tc_subfr) == L_SUBFR) || ((i_subfr - *tc_subfr) == L_SUBFR-TC_0_0) ) + { + pit_flag = 0; + } + else + { + pit_flag = L_SUBFR; + } + if( *tc_subfr == TC_0_0 ) + { + if( i_subfr == L_SUBFR ) + { + limit_T0( L_FRAME, 8, pit_flag, limit_flag, *T0, 0, T0_min, T0_max ); + } + pit_flag = 1; + } + + /*----------------------------------------------------------* + * if tc_subfr==0, change tc_subfr corresponding to the + * second glot. impulse position + *----------------------------------------------------------*/ + + if( (*tc_subfr == 0) && (i_subfr == L_SUBFR) ) + { + if( PIT_MIN > (*position) ) + { + pit_start = L_SUBFR - (*position); + } + else + { + pit_start = PIT_MIN; + } + if( pit_start < PIT_MIN ) + { + pit_start = PIT_MIN; + } + + pit_limit = 2*pit_start + (*position); + + /* Find the closed loop pitch period */ + *T0 = pitch_fr4( &exc[i_subfr], xn, h1, *T0_min, *T0_max, T0_frac, pit_flag, limit_flag, pit_start, pit_limit, L_FRAME, L_SUBFR ); + + offset = tbe_celp_exc_offset(*T0, *T0_frac); + for (i=0; i(2*L_SUBFR-(*position)) ) + { + if( (*T0) + (*position) >= 3*L_SUBFR) + { + /* second glottal impulse is in the 4th subframe */ + *tc_subfr = TC_0_192; + } + else + { + /* second glottal impulse is in the 3rd subframe */ + *tc_subfr = TC_0_128; + } + } + else if( (*tc_subfr == 0) && (i_subfr == L_SUBFR) ) + { + /* second glottal impulse is in the 2nd subframe */ + *tc_subfr = TC_0_64; + } + } + + /*-----------------------------------------------------------------* + * get number of bits for pitch encoding + *-----------------------------------------------------------------*/ + + nBits = ACB_bits_tbl[BIT_ALLOC_IDX(core_brate, TRANSITION, i_subfr, TC_SUBFR2IDX(*tc_subfr))]; + + /*-----------------------------------------------------------------* + * Find adaptive part of excitation, encode pitch period + *-----------------------------------------------------------------*/ + + /* first glottal impulse is in the 1st subrame */ + if( (i_subfr == L_SUBFR) && (*tc_subfr >= TC_0_128) ) + { + /*--------------------------------------------------------* + * second glottal impulse is in the 3rd or 4th subframe + * - build exc[] in 2nd subframe + *--------------------------------------------------------*/ + + *T0 = 2*L_SUBFR; + *T0_frac = 0; + *Jopt_flag = 0; + + set_f( &exc[i_subfr], 0, (short)(L_SUBFR+1) ); + set_f( &bwe_exc[i_subfr*HIBND_ACB_L_FAC], 0, (short)(L_SUBFR*HIBND_ACB_L_FAC) ); + } + else if( (i_subfr == L_SUBFR) && (*tc_subfr == TC_0_64) ) + { + /*--------------------------------------------------------* + * second glottal impulse is in the 2nd subframe, + * - build exc[] in 2nd subframe + *--------------------------------------------------------*/ + + if( (*T0)+(*position) < L_SUBFR ) + { + /* impulse must be in the 2nd subframe (not in 1st) */ + *T0 = L_SUBFR - (*position); + *T0_frac = 0; + } + + if( (*T0)+(*position) >= 2*L_SUBFR ) + { + /* impulse must be in the 2nd subframe (not in 3rd) */ + *T0 = 2*L_SUBFR-1-(*position); + *T0_frac = 2; + } + + limit_T0( L_FRAME, 8, pit_flag, limit_flag, *T0, 0, T0_min, T0_max ); /* find T0_min and T0_max for delta search */ + + /* 7bit ENCODER */ + index = (*T0-pit_start)*2 + *T0_frac/2; + push_indice( st, IND_PITCH, index, nBits ); + + /* Find the adaptive codebook vector - ACELP long-term prediction */ + pred_lt4( &exc[i_subfr], &exc[i_subfr], *T0, *T0_frac, L_SUBFR+1, inter4_2, L_INTERPOL2, PIT_UP_SAMP); + + offset = tbe_celp_exc_offset(*T0, *T0_frac); + for (i=0; i= 3*L_SUBFR ) + { + /* impulse must be in the 3rd subframe (not in 4th) */ + *T0 = 3*L_SUBFR - 1 - (*position); + *T0_frac = 2; + } + + limit_T0( L_FRAME, 8, pit_flag, limit_flag, *T0, 0, T0_min, T0_max ); /* find T0_min and T0_max for delta search */ + + index = (*T0-pit_start)*2 + *T0_frac/2; + push_indice( st, IND_PITCH, index, nBits ); + + /* Find the adaptive codebook vector - ACELP long-term prediction */ + pred_lt4( &exc[i_subfr], &exc[i_subfr], *T0, *T0_frac, L_SUBFR+1, inter4_2, L_INTERPOL2, PIT_UP_SAMP ); + + offset = tbe_celp_exc_offset(*T0, *T0_frac); + for (i=0; i= 2*L_SUBFR) && (i_subfr == 3*L_SUBFR) ) + { + (*pt_pitch) -= 3; + **pt_pitch = (float)(*T0) + (float)(*T0_frac)/4.0f; + (*pt_pitch)++; + **pt_pitch = (float)(*T0) + (float)(*T0_frac)/4.0f; + (*pt_pitch)++; + **pt_pitch = (float)(*T0) + (float)(*T0_frac)/4.0f; + (*pt_pitch)++; + } + else if( (*tc_subfr == L_SUBFR) && (i_subfr == 2*L_SUBFR) ) + { + (*pt_pitch) -= 2; + **pt_pitch = (float)(*T0) + (float)(*T0_frac)/4.0f; + (*pt_pitch)++; + **pt_pitch = (float)(*T0) + (float)(*T0_frac)/4.0f; + (*pt_pitch)++; + } + else if( (*tc_subfr == TC_0_64) && (i_subfr == L_SUBFR) ) + { + (*pt_pitch) -= 1; + **pt_pitch = (float)(*T0) + (float)(*T0_frac)/4.0f; + (*pt_pitch)++; + } + else if( (*tc_subfr == TC_0_128) && (i_subfr == 2*L_SUBFR) ) + { + (*pt_pitch) -= 2; + **pt_pitch = (float)(*T0) + (float)(*T0_frac)/4.0f; + (*pt_pitch)++; + **pt_pitch = (float)(*T0) + (float)(*T0_frac)/4.0f; + (*pt_pitch)++; + } + else if( (*tc_subfr == TC_0_192) && (i_subfr == 3*L_SUBFR) ) + { + (*pt_pitch) -= 3; + **pt_pitch = (float)(*T0) + (float)(*T0_frac)/4.0f; + (*pt_pitch)++; + **pt_pitch = (float)(*T0) + (float)(*T0_frac)/4.0f; + (*pt_pitch)++; + **pt_pitch = (float)(*T0) + (float)(*T0_frac)/4.0f; + (*pt_pitch)++; + } + } + else /* L_frame == L_FRAME16k */ + { + if( i_subfr >= 2*L_SUBFR ) + { + limit_flag = 1; + } + + if( i_subfr <= 2*L_SUBFR ) + { + if( i_subfr < 2*L_SUBFR ) + { + mult_Top = 1; + if( T_op[0] < PIT16k_MIN ) + { + mult_Top = 2; + } + limit_T0( L_FRAME16k, 8, 0, limit_flag, mult_Top*T_op[0], 0, T0_min, T0_max ); /* TC0 second subfr. */ + } + else + { + limit_T0( L_FRAME16k, 8, 0, limit_flag, T_op[1], 0, T0_min, T0_max ); /* TC0 third subfr., or TC64 third subfr. */ + } + } + + /*-----------------------------------------------------------------* + * get number of bits for pitch encoding + *-----------------------------------------------------------------*/ + + nBits = ACB_bits_16kHz_tbl[BIT_ALLOC_IDX_16KHZ(core_brate, coder_type, i_subfr, TC_SUBFR2IDX_16KHZ(*tc_subfr))]; + + /*-----------------------------------------------------------------* + * Find adaptive part of excitation, encode pitch period + *-----------------------------------------------------------------*/ + + if( nBits == 10 ) + { + *T0 = pitch_fr4( &exc[i_subfr], xn, h1, *T0_min, *T0_max, T0_frac, 0, limit_flag, PIT16k_FR2_EXTEND_10b, PIT16k_MAX, L_frame, L_SUBFR ); + pit16k_Q_enc( st, nBits, limit_flag, *T0, *T0_frac, T0_min, T0_max ); + } + else if( nBits == 8 ) /* tc_subfr==0 && i_subfr==L_SUBFR */ + { + /*-----------------------------------------------------------------------------* + * The pitch range is encoded absolutely with 8 bits and is divided as follows: + * PIT16k_MIN to PIT16k_FR2_TC0_2SUBFR-1 resolution 1/4 (frac = 0,1,2 or 3) + * PIT16k_FR2_TC0_2SUBFR to 2*L_SUBFR resolution 1/2 (frac = 0 or 2) + *-----------------------------------------------------------------------------*/ + + *T0 = pitch_fr4( &exc[i_subfr], xn, h1, *T0_min, *T0_max, T0_frac, 0, limit_flag, PIT16k_FR2_TC0_2SUBFR, 2*L_SUBFR, L_frame, L_SUBFR ); + + if( *T0_max > 2*L_SUBFR ) + { + *T0 = 2*L_SUBFR; + *T0_frac = 0; + } + + if( *T0 < PIT16k_FR2_TC0_2SUBFR ) + { + index = (*T0)*4 + (*T0_frac) - (PIT16k_MIN*4); + } + else + { + index = (*T0)*2 + ((*T0_frac)>>1) - (PIT16k_FR2_TC0_2SUBFR*2) + ((PIT16k_FR2_TC0_2SUBFR-PIT16k_MIN)*4); + } + + push_indice( st, IND_PITCH, index, nBits ); + } + else if( nBits == 6 ) + { + /* delta search */ + *T0 = pitch_fr4( &exc[i_subfr], xn, h1, *T0_min, *T0_max, T0_frac, L_SUBFR, limit_flag, PIT16k_FR2_EXTEND_9b, PIT16k_FR1_EXTEND_9b, L_frame, L_SUBFR ); + + index = delta_pit_enc( 4, *T0, *T0_frac, *T0_min ); + + push_indice( st, IND_PITCH, index, nBits ); + } + if( nBits == 6 ) + { + limit_T0( L_FRAME16k, 8, L_SUBFR, limit_flag, *T0, *T0_frac, T0_min, T0_max ); + } + + /*-----------------------------------------------------------------* + * - gain clipping test to avoid unstable synthesis + * - LP filtering of the adaptive excitation + * - codebook target computation + *-----------------------------------------------------------------*/ + + if( (i_subfr == L_SUBFR) && (*T0 == 2*L_SUBFR) ) + { + *gain_pit = 0.0f; + *clip_gain = 0; + g_corr[0] = 0.01f; + g_corr[1] = 0.01f; + *Jopt_flag = 0; + + set_f( &exc[i_subfr], 0, L_SUBFR+1 ); /* set excitation for current subrame to 0 */ + + push_indice( st, IND_LP_FILT_SELECT, 0, 1 ); /* this bit is actually not needed */ + + mvr2r( xn, xn2, L_SUBFR ); /* target vector for codebook search */ + set_f( y1, 0, L_SUBFR ); /* set filtered adaptive excitation to 0 */ + set_f( &bwe_exc[i_subfr * 2], 0, L_SUBFR * 2 ); + } + else + { + /* Find the adaptive codebook vector - ACELP long-term prediction */ + pred_lt4( &exc[i_subfr], &exc[i_subfr], *T0, *T0_frac, L_SUBFR+1, inter4_2, L_INTERPOL2, PIT_UP_SAMP ); + + for (i=0; i|| | imp_shape->| g1 | | + * | | | | g2 | ---- exc |---| y1 ---- | + * | | |-------------| |----|gain|-------| h |------|gain|----(-)---> xn2 + * | || | gn | ---- |---| ---- + * |----| |----| + * codebook excitation gain_trans h_orig gain_pit + * + *-------------------------------------------------------------------------------------------*/ + +static void tc_enc( + Encoder_State *st, /* i/o: encoder state structure */ + const long core_brate, /* i : core bitrate */ + const short L_frame, /* i : length of the frame */ + const short i_subfr, /* i : subrame index */ + short *tc_subfr, /* i/o: TC subframe index */ + short *position, /* i/o: index of the residual signal maximum */ + const float *h1, /* i : weighted filter input response */ + const float *xn, /* i : target signal */ + float *exc, /* o : glottal codebook contribution */ + float *y1, /* o : filtered glottal codebook contribution */ + short *T0_min, /* o : lower pitch limit */ + short *T0_max, /* o : higher pitch limit */ + short *T0, /* o : close loop integer pitch */ + short *T0_frac, /* o : close loop fractional part of the pitch */ + float *gain_pit, /* o : pitch gain (0..GAIN_PIT_MAX) */ + float g_corr[], /* o : correlations and -2 */ + float *bwe_exc /* i/o: excitation for SWB TBE */ +) +{ + short imp_shape, imp_pos, imp_sign, imp_gain, index, nBits; + float gain_trans; + + imp_pos = *position-i_subfr; + + /*-----------------------------------------------------------------* + * get number of bits for pitch encoding + *-----------------------------------------------------------------*/ + + if( L_frame == L_FRAME ) + { + nBits = ACB_bits_tbl[BIT_ALLOC_IDX(core_brate, TRANSITION, i_subfr, TC_SUBFR2IDX(*tc_subfr))]; + } + else /* L_frame == L_FRAME16k */ + { + nBits = ACB_bits_16kHz_tbl[BIT_ALLOC_IDX_16KHZ(core_brate, TRANSITION, i_subfr, TC_SUBFR2IDX_16KHZ(*tc_subfr))]; + } + + /*--------------------------------------------------------------* + * Closed loop pitch search + *--------------------------------------------------------------*/ + + *T0_frac = 0; + if( L_frame == L_FRAME ) + { + if( (*T0_min <= L_SUBFR) || (*tc_subfr == 3*L_SUBFR) ) + { + if( nBits == 9 ) + { + *T0 = pitch_fr4( &exc[i_subfr], xn, h1, *T0_min, *T0_max, T0_frac, 0, 0, PIT_FR2_9b, PIT_FR1_9b, L_FRAME, L_SUBFR ); + } + else if( nBits == 6 ) + { + *T0 = pitch_fr4( &exc[i_subfr], xn, h1, *T0_min, *T0_max, T0_frac, 0, 0, PIT_MIN, L_SUBFR, L_FRAME, L_SUBFR ); + } + else + { + *T0 = pitch_fr4( &exc[i_subfr], xn, h1, *T0_min, *T0_max, T0_frac, 0, 0, PIT_MAX, PIT_MIN, L_FRAME, L_SUBFR ); + } + } + else + { + *T0 = L_SUBFR; + } + + if( (*tc_subfr == L_SUBFR) && (*T0 < L_SUBFR) ) + { + *T0 = L_SUBFR; + } + } + else /* L_frame == L_FRAME16k */ + { + if( nBits == 10 ) + { + *T0 = pitch_fr4( &exc[i_subfr], xn, h1, *T0_min, *T0_max, T0_frac, 0, 1, PIT16k_FR2_EXTEND_10b, PIT16k_MAX, L_FRAME16k, L_SUBFR ); + } + else if( nBits == 6 ) + { + /* T0_frac with 1/2 sample resolution */ + *T0 = pitch_fr4( &exc[i_subfr], xn, h1, *T0_min, *T0_max, T0_frac, 0, 0, PIT16k_MIN, L_SUBFR, L_FRAME16k, L_SUBFR ); + + if( *T0 > L_SUBFR ) + { + *T0 = L_SUBFR; + *T0_frac = 0; + } + } + } + + /* set tc_subfr to TC_0_0 */ + if( i_subfr == 0 && L_frame == L_FRAME && ( *T0 < L_SUBFR || *tc_subfr == 3*L_SUBFR ) ) + { + *tc_subfr = TC_0_0; + } + + /*--------------------------------------------------------------* + * Builds glottal codebook contribution + *--------------------------------------------------------------*/ + + set_impulse( xn, h1, &exc[i_subfr], y1, &imp_shape, &imp_pos, &gain_trans ); + + /*--------------------------------------------------------------* + * quantize gain_trans and scale glottal codebook contribution + *--------------------------------------------------------------*/ + + gain_trans_enc( &gain_trans, &exc[i_subfr], &imp_gain, &imp_sign ); + + /* set past excitation buffer to zeros */ + set_f( exc-L_EXC_MEM, 0, L_EXC_MEM ); + + /*--------------------------------------------------------------* + * adapt. search of the second impulse in the same subframe + * (when appears) + *--------------------------------------------------------------*/ + + pred_lt4_tc( exc, *T0, *T0_frac, inter4_2, imp_pos, i_subfr); + + if( L_frame == L_FRAME ) + { + interp_code_5over2(&exc[i_subfr], &bwe_exc[i_subfr * HIBND_ACB_L_FAC], L_SUBFR); + } + else + { + interp_code_4over2(&exc[i_subfr], &bwe_exc[i_subfr * 2], L_SUBFR); + } + + /*--------------------------------------------------------------* + * compute glottal-shape codebook excitation + *--------------------------------------------------------------*/ + + /* create filtered glottal codebook contribution */ + conv( &exc[i_subfr], h1, y1, L_SUBFR ); + + /* gain_pit computation */ + *gain_pit = corr_xy1( xn, y1, g_corr, L_SUBFR,0); + + /*--------------------------------------------------------------* + * Encode parameters and write indices + *--------------------------------------------------------------*/ + + if( L_frame == L_FRAME ) + { + if( ( (i_subfr != 0) || (*tc_subfr == TC_0_0) ) + && (*tc_subfr != L_SUBFR)) + { + /* write pitch index */ + if( (*T0 >= L_SUBFR) && (*tc_subfr != 3*L_SUBFR) ) + { + push_indice( st, IND_PITCH, 0, nBits ); + } + else if( *tc_subfr == 3*L_SUBFR ) + { + if( nBits == 9 ) + { + index = abs_pit_enc( 4, 0, *T0, *T0_frac ); + } + else + { + index = abs_pit_enc( 2, 0, *T0, *T0_frac ); + } + + push_indice( st, IND_PITCH, index, nBits ); + + limit_T0( L_FRAME, 8, 0, 0, *T0, 0, T0_min, T0_max ); + } + else + { + if( nBits == 6 ) + { + index = delta_pit_enc( 2, *T0, *T0_frac, PIT_MIN-1 ); + push_indice( st, IND_PITCH, index, nBits ); + } + else + { + index = delta_pit_enc( 0, *T0, *T0_frac, PIT_MIN-1 ); + push_indice( st, IND_PITCH, index, nBits ); + } + } + } + } + else /* L_frame == L_FRAME16k */ + { + if( nBits == 10 ) + { + pit16k_Q_enc( st, nBits, 1, *T0, *T0_frac, T0_min, T0_max ); + } + else if( nBits == 6 ) + { + index = 2*(*T0 - PIT16k_MIN) + *T0_frac/2; + push_indice( st, IND_PITCH, index, nBits ); + } + } + + push_indice( st, IND_TC_IMP_SHAPE, imp_shape, 3 ); + push_indice( st, IND_TC_IMP_POS, imp_pos, 6 ); + push_indice( st, IND_TC_IMP_SIGN, imp_sign, 1 ); + push_indice( st, IND_TC_IMP_GAIN, imp_gain, 3 ); + + *position = imp_pos + i_subfr; + + return; +} + +/*-----------------------------------------------------------------* + * gain_trans_enc() + * + * Quantize gain_trans of TC (gains of glottal impulses). + * - Uses scalar quantization prototypes tbl_gain_trans_tc[N_GAIN_TC]. + * - Gains the glottal codebook contibution signal. + *-----------------------------------------------------------------*/ + +static void gain_trans_enc( + float *gain_trans, /* i/o: gain for TC */ + float exc[], /* i/o: glottal codebook contribution */ + short *quant_index, /* o : index of quantized gain_trans */ + short *quant_sign /* o : sign of quantized gain_trans */ +) +{ + short i; + + + if( *gain_trans < 0 ) + { + *gain_trans *= -1; + *quant_sign = 0; + } + else + { + *quant_sign = 1; + } + + *quant_index = N_GAIN_TC-1; + + for( i=0; i -#include "options.h" /* Compilation switches */ -#include "cnst_fx.h" /* Common constants */ -#include "rom_com_fx.h" /* Static table prototypes */ -#include "prot_fx.h" /* Function prototypes */ -#include "stl.h" - -/*-----------------------------------------------------------------* - * Local functions - *-----------------------------------------------------------------*/ - -static void gain_trans_enc_fx(Word32 gain_trans32, Word16 exc[], Word16 *quant_index, Word16 *quant_sign, Word16 Q_new); - -static void tc_enc_fx(Encoder_State_fx *st_fx, const Word32 core_brate, const Word16 L_frame, const Word16 i_subfr, Word16 *tc_subfr, Word16 *position, - const Word16 *h1_fx, const Word16 *xn_fx, Word16 *exc_fx, Word16 *yy1_fx, Word16 *T0_min, Word16 *T0_max, - Word16 *T0, Word16 *T0_frac, Word16 *gain_pit_fx, Word16 g_corr_fx[], Word16 *bwe_exc_fx, Word16 Q_new); - - -/*==========================================================================*/ -/* FUNCTION : void transition_enc_fx () */ -/*--------------------------------------------------------------------------*/ -/* PURPOSE :Principal function for adaptive excitation construction in TC*/ -/*--------------------------------------------------------------------------*/ -/* INPUT ARGUMENTS : */ -/* (Word32) core_brate : core bitrate Q0 */ -/* (Word16) L_frame : length of the frame Q0 */ -/* (Word16) coder_type : coding type Q0 */ -/* (Word16) bwidth : input signal bandwidth Q0 */ -/* (Word16) i_subfr : subrame index Q0 */ -/* (Word16*) Jopt_flag : joint optimization flag Q0 */ -/* (Word16[]) voicing_fx : normalized correlations(from OL pitch)Q15 */ -/* (Word16[]) T_op_fx : open loop pitch estimates in current frameQ0*/ -/* (Word16*) res_fx : pointer to the LP residual signal frameQ_new*/ -/* (Word16*) h1_fx : weighted filter input response Q14 */ -/* (Word16*) xn_fx : target signal Q_new*/ -/* (Word16) Q_new : input scaling */ -/*--------------------------------------------------------------------------*/ -/* OUTPUT ARGUMENTS : */ -/* (Word16*) y1_fx : zero-memory filtered adaptive excitation Q12*/ -/* (Word16*) xn2_fx : target vector for innovation search Qnew */ -/* (Word16*) gain_pit_fx : pitch gain (0..GAIN_PIT_MAX) Q14*/ -/* (Word16[])g_corr_fx : correlations and -2 */ -/* (Word16**)pt_pitch_fx : floating pitch values Q6 */ -/* (Word16*) bwe_exc_fx : excitation for SWB TBE Q0 */ -/*--------------------------------------------------------------------------*/ -/* INPUT/OUTPUT ARGUMENTS : */ -/* (Word16*) tc_subfr : TC subframe index Q0 */ -/* (Word16*) position : index of the residual signal maximum Q0 */ -/* (Word16*) T0_min : lower pitch limit Q0 */ -/* (Word16*) T0_max : higher pitch limit Q0 */ -/* (Word16*) T0 : close loop integer pitch Q0 */ -/* (Word16*) T0_frac : close loop fractional part of the pitch Q0*/ -/* (Word16*) exc_fx : pointer to excitation signal frame */ -/* (Word16*) gp_cl_fx : memory of gain of pitch clipping algorithm*/ -/* (Word16*) clip_gain : adaptive gain clipping flag Q0 */ -/*--------------------------------------------------------------------------*/ -/* RETURN ARGUMENTS : */ -/* _ None */ -/*--------------------------------------------------------------------------*/ - -void transition_enc_fx( - Encoder_State_fx *st_fx, /* i/o: encoder state structure */ - const Word32 core_brate, /* i : core bitrate */ - const Word16 L_frame, /* i : length of the frame */ - const Word16 coder_type, /* i : coding type */ - const Word16 i_subfr, /* i : subframe index */ - Word16 *tc_subfr, /* i/o: TC subframe index */ - Word16 *Jopt_flag, /* i : joint optimization flag */ - Word16 *position, /* i/o: maximum of residual signal index */ - const Word16 voicing_fx[], /* i : normalized correlations (from OL pitch) Q15*/ - const Word16 T_op_fx[], /* i : open loop pitch estimates in current frame Q0*/ - Word16 *T0, /* i/o: close loop integer pitch Q0*/ - Word16 *T0_frac, /* i/o: close loop fractional part of the pitch Q0*/ - Word16 *T0_min, /* i/o: lower limit for close-loop search Q0*/ - Word16 *T0_max, /* i/o: higher limit for close-loop search Q0*/ - Word16 *exc_fx, /* i/o: pointer to excitation signal frame Q_new*/ - Word16 *y1_fx, /* o : zero-memory filtered adaptive excitation Q_new-1+shift*/ - const Word16 *res_fx, /* i : pointer to the LP residual signal frame Q_new*/ - const Word16 *h1_fx, /* i : weighted filter input response Q(14+shift)*/ - const Word16 *xn_fx, /* i : target vector Q_new-1+shift*/ - Word16 *xn2_fx, /* o : target vector for innovation search Q_new-1+shift*/ - Word16 *gp_cl_fx, /* i/o: memory of gain of pitch clipping algorithm */ - Word16 *gain_pit_fx, /* o : adaptive excitation gain Q14*/ - Word16 *g_corr_fx, /* o : ACELP correlation values */ - Word16 *clip_gain, /* i/o: adaptive gain clipping flag */ - Word16 **pt_pitch_fx, /* o : floating pitch values */ - Word16 *bwe_exc_fx, /* o : excitation for SWB TBE Q_new*/ - Word16 Q_new, /* i : Current scaling */ - Word16 shift /* i : downscaling needs for 12 bits convolutions */ - -) -{ - Word16 pit_flag, pit_start, pit_limit, index, nBits; - Word16 tmp, tmp1; - Word32 i, offset,temp; - Word16 shift_wsp; - Word16 limit_flag, mult_Top, lp_select, lp_flag; - - /* set limit_flag to 0 for restrained limits, and 1 for extended limits */ - limit_flag = 0; - move16(); - - pit_start = PIT_MIN; - move16(); - shift_wsp = add(Q_new,shift); - - /*-----------------------------------------------------------------* - * TC: subrame determination for glottal shape search - * ------------------------------------------------------- - * tc_subfr == 0 - TC in 1st subframe - * tc_subfr == TC_0_0 - TC in 1st subframe + information about T0 - * tc_subfr == L_SUBFR - TC in 2nd subframe - * tc_subfr == 2*L_SUBFR - TC in 3rd subframe - * tc_subfr == 3*L_SUBFR - TC in 4th subframe - *-----------------------------------------------------------------*/ - - IF( i_subfr == 0 ) - { - IF( sub(*tc_subfr,3*L_SUBFR) == 0 ) - { - IF( sub(L_frame,L_FRAME) == 0 ) - { - *position = emaximum_fx( Q_new, res_fx + 3*L_SUBFR,s_min(add(T_op_fx[0],2),L_SUBFR), &temp ) + 3*L_SUBFR; - move16(); - *tc_subfr = 3*L_SUBFR; - move16(); - } - ELSE /* L_frame == L_FRAME16k */ - { - *position = emaximum_fx( Q_new, res_fx + 4*L_SUBFR,s_min(add(T_op_fx[0],2),L_SUBFR), &temp ) + 4*L_SUBFR; - move16(); - *tc_subfr = 4*L_SUBFR; - move16(); - } - } - ELSE - { - *position = emaximum_fx( Q_new, res_fx, add(T_op_fx[0],2), &temp ); - - /* correction in case of possibly wrong T_op (double-pitch values) */ - test(); - test(); - test(); - IF( (sub(L_frame,L_FRAME) == 0 && sub(T_op_fx[0],2*PIT_MIN)>0 ) || - (sub(L_frame,L_FRAME16k) == 0 && sub(T_op_fx[0],2*PIT16k_MIN) >0) - ) - { - Word16 position_tmp, len, exp_aver=0, exp=0, exp2=0; - Word32 aver, temp2, L_sum, L_temp1, L_temp2; - - len = add(shr(T_op_fx[0],1), 2); - position_tmp = emaximum_fx( Q_new, res_fx, len, &temp2 ); - - L_sum = L_mac(1L, res_fx[0], res_fx[0]); - FOR (i = 1; i < len; i++) - { - L_sum = L_mac0(L_sum, res_fx[i], res_fx[i]); - } - aver = L_sum; /*Q = 2*Q_new */ - aver = root_a_over_b_fx(aver, 2*Q_new, L_shl(len,15), 15, &exp_aver); /*Q = 31-exp_aver*/ - - temp = root_a_fx(temp, 0, &exp); /* Q=31-exp */ - temp2 = root_a_fx(temp2, 0, &exp2); /* Q=31-exp2 */ - - L_temp2 = Mult_32_16(temp, 26214); /* Q=31-exp */ - L_temp1 = Mult_32_16(temp, 8192); /* Q=31-exp */ - - test(); - IF( L_sub(temp2, L_shl(L_temp2,(31-exp2)-(31-exp))) > 0 && - L_sub(aver, L_shl(L_temp1,(31-exp_aver)-(31-exp))) < 0 ) - { - *position = position_tmp; - } - } - *tc_subfr = s_and(*position, 0x7FC0); - } - mult_Top = 1; - IF( limit_flag == 0 ) - { - test(); - IF( sub(L_frame,L_FRAME) == 0 && sub(T_op_fx[1],PIT_MIN) < 0 ) - { - mult_Top = 2; - move16(); - } - test(); - if( sub(L_frame,L_FRAME16k) == 0 && sub(T_op_fx[1],PIT16k_MIN) < 0 ) - { - mult_Top = 2; - move16(); - } - } - - limit_T0_fx( L_frame, 8, 0, limit_flag, mult_Top*T_op_fx[1], 0, T0_min, T0_max ); - - } - /*-----------------------------------------------------------------* - * zero adaptive excitation signal construction - *-----------------------------------------------------------------*/ - IF ( sub(*tc_subfr,i_subfr) > 0 ) - { - *gain_pit_fx = 0; - move16(); - *clip_gain = 0; - move16(); - g_corr_fx[0] = 16384; - move16(); - g_corr_fx[1] = add(shl(sub(shift_wsp,1),1),1); - move16(); - g_corr_fx[2] = -16384; - move16(); - g_corr_fx[3] = shl(sub(shift_wsp,1),1); - - set16_fx(&exc_fx[i_subfr], 0, L_SUBFR); /* set excitation for current subrame to 0 */ - - IF( sub(L_frame,L_FRAME) == 0 ) - { - set16_fx(&bwe_exc_fx[i_subfr*HIBND_ACB_L_FAC], 0, (Word16)(L_SUBFR*HIBND_ACB_L_FAC)); /* set past excitation buffer to 0 */ - } - ELSE - { - set16_fx(&bwe_exc_fx[i_subfr*2], 0, L_SUBFR*2); /* set past excitation buffer to 0 */ - } - - set16_fx(y1_fx, 0, L_SUBFR); /* set filtered adaptive excitation to 0 */ - Copy(xn_fx, xn2_fx, L_SUBFR); /* target vector for codebook search */ - *T0 = L_SUBFR; - move16(); - *T0_frac = 0; - move16(); - - **pt_pitch_fx = shl(add(shl(*T0,2),*T0_frac),4); - move16(); /* save subframe pitch values Q6 */ - - } - - /*-----------------------------------------------------------------* - * glottal codebook contribution construction - *-----------------------------------------------------------------*/ - ELSE IF ( sub(*tc_subfr,i_subfr) == 0 ) - { - IF( sub(L_frame,L_FRAME) == 0 ) - { - set16_fx( bwe_exc_fx-PIT_MAX*HIBND_ACB_L_FAC, 0, PIT_MAX*HIBND_ACB_L_FAC); /* set past excitation buffer to 0 */ - } - ELSE - { - set16_fx( bwe_exc_fx-PIT16k_MAX*2, 0, PIT16k_MAX*2); /* set past excitation buffer to 0 */ - } - - tc_enc_fx( st_fx, core_brate, L_frame, i_subfr, tc_subfr, position, h1_fx, xn_fx, exc_fx, - y1_fx, T0_min, T0_max, T0, T0_frac, gain_pit_fx, g_corr_fx, bwe_exc_fx,Q_new); - - *clip_gain = gp_clip_fx( core_brate, voicing_fx, i_subfr, coder_type, xn_fx, gp_cl_fx, sub(shift_wsp,1) ); - updt_tar_fx( xn_fx, xn2_fx, y1_fx, *gain_pit_fx, L_SUBFR ); - - **pt_pitch_fx = shl(add(shl(*T0,2),*T0_frac),4); - move16(); - *Jopt_flag = 1; - move16(); - } - - /*--------------------------------------------------------------* - * other subframes -> GENERIC encoding type, - * standard adaptive excitation contribution - * - exemption only in case when first glottal impulse is - * in the 1st subframe and the second one in 2nd subframe - * and later - *--------------------------------------------------------------*/ - ELSE IF ( sub(*tc_subfr,i_subfr) < 0) - { - IF( sub(L_frame,L_FRAME) == 0 ) - { - *Jopt_flag = 1; - move16(); - /* pit_flag for T0 bits number coding determination */ - test(); - IF( (sub(sub(i_subfr,*tc_subfr),L_SUBFR) == 0) || (sub(sub(i_subfr, *tc_subfr),L_SUBFR-TC_0_0) == 0) ) - { - pit_flag = 0; - move16(); - } - ELSE - { - pit_flag = L_SUBFR; - move16(); - } - - IF( sub(*tc_subfr,TC_0_0) == 0 ) - { - IF( sub(i_subfr,L_SUBFR) == 0 ) - { - limit_T0_fx( L_FRAME, 8, pit_flag, limit_flag, *T0, 0, T0_min, T0_max ); - } - pit_flag = 1; - move16(); - } - - /*----------------------------------------------------------* - * if tc_subfr==0, change tc_subfr corresponding to the - * second glot. impulse position - *----------------------------------------------------------*/ - test(); - IF( (*tc_subfr == 0) && (sub(i_subfr,L_SUBFR) == 0) ) - { - IF( sub(PIT_MIN,(*position)) > 0 ) - { - pit_start = sub(L_SUBFR, (*position)); - } - ELSE - { - pit_start = PIT_MIN; - move16(); - } - pit_start = s_max(pit_start, PIT_MIN); - - pit_limit = add(shl(pit_start,1), *position); - - /* Find the closed loop pitch period */ - - *T0 = pitch_fr4_fx( &exc_fx[i_subfr], xn_fx, h1_fx, *T0_min, *T0_max, T0_frac, pit_flag, limit_flag, pit_start, pit_limit, L_FRAME, L_SUBFR ); - - offset = tbe_celp_exc_offset(*T0, *T0_frac, L_frame); - - - FOR (i=0; i 0 ) - { - IF( sub(add((*T0), (*position)),3*L_SUBFR) >= 0) - { - /* second glottal impulse is in the 4th subframe */ - *tc_subfr = TC_0_192; - move16(); - } - ELSE - { - /* second glottal impulse is in the 3rd subframe */ - *tc_subfr = TC_0_128; - move16(); - } - } - ELSE IF( (*tc_subfr == 0) && (sub(i_subfr,L_SUBFR) == 0) ) - { - /* second glottal impulse is in the 2nd subframe */ - *tc_subfr = TC_0_64; - move16(); - } - } - - /*-----------------------------------------------------------------* - * get number of bits for pitch encoding - *-----------------------------------------------------------------*/ - - nBits = ACB_bits_tbl[BIT_ALLOC_IDX_fx(core_brate, TRANSITION, i_subfr, TC_SUBFR2IDX_fx(*tc_subfr))]; - move16(); - - /*-----------------------------------------------------------------* - * Find adaptive part of excitation, encode pitch period - *-----------------------------------------------------------------*/ - test(); - test(); - test(); - test(); - test(); - test(); - /* first glottal impulse is in the 1st subrame */ - IF( (sub(i_subfr,L_SUBFR) == 0) && (sub(*tc_subfr,TC_0_128) >= 0) ) - { - /*--------------------------------------------------------* - * second glottal impulse is in the 3rd or 4th subframe - * - build exc[] in 2nd subframe - *--------------------------------------------------------*/ - *T0 = 2*L_SUBFR; - move16(); - *T0_frac = 0; - move16(); - *Jopt_flag = 0; - move16(); - set16_fx( &exc_fx[i_subfr], 0, (Word16)(L_SUBFR+1) ); - set16_fx( &bwe_exc_fx[i_subfr*HIBND_ACB_L_FAC], 0, (Word16)(L_SUBFR*HIBND_ACB_L_FAC) ); - - } - ELSE IF( (sub(i_subfr,L_SUBFR) == 0) && (sub(*tc_subfr,TC_0_64) == 0) ) - { - /*--------------------------------------------------------* - * second glottal impulse is in the 2nd subframe, - * - build exc[] in 2nd subframe - - *--------------------------------------------------------*/ - IF( sub(add(*T0,*position), L_SUBFR ) < 0 ) - { - /* impulse must be in the 2nd subframe (not in 1st) */ - *T0 = sub(L_SUBFR, (*position)); - move16(); - *T0_frac = 0; - move16(); - } - IF( sub(add(*T0,*position),2*L_SUBFR) >= 0 ) - { - /* impulse must be in the 2nd subframe (not in 3rd) */ - *T0 = sub(2*L_SUBFR-1,(*position)); - move16(); - *T0_frac = 2; - move16(); - } - - limit_T0_fx( L_FRAME, 8, pit_flag, limit_flag, *T0, 0, T0_min, T0_max ); /* find T0_min and T0_max for delta search */ - - /* 7bit ENCODER */ - /* index = (*T0-pit_start)*2 + *T0_frac/2;*/ - index = add(shl(sub(*T0,pit_start),1), shr(*T0_frac,1)); - push_indice_fx( st_fx, IND_PITCH, index, nBits ); - - /* Find the adaptive codebook vector - ACELP long-term prediction */ - pred_lt4(&exc_fx[i_subfr], &exc_fx[i_subfr], *T0, *T0_frac, L_SUBFR+1, pitch_inter4_2, L_INTERPOL2, PIT_UP_SAMP); - - - offset = tbe_celp_exc_offset(*T0, *T0_frac, L_frame); - - FOR (i=0; i= 0) - { - /* impulse must be in the 3rd subframe (not in 4th) */ - *T0 = sub(3*L_SUBFR - 1, (*position)); - move16(); - *T0_frac = 2; - move16(); - } - - limit_T0_fx( L_FRAME, 8, pit_flag, limit_flag, *T0, 0, T0_min, T0_max ); /* find T0_min and T0_max for delta search */ - - index = add(shl(sub(*T0, pit_start), 1), shr(*T0_frac,1)); - push_indice_fx( st_fx, IND_PITCH, index, nBits ); - - /* Find the adaptive codebook vector - ACELP long-term prediction */ - pred_lt4(&exc_fx[i_subfr], &exc_fx[i_subfr], *T0, *T0_frac, L_SUBFR+1, pitch_inter4_2, L_INTERPOL2, PIT_UP_SAMP); - - offset = tbe_celp_exc_offset(*T0, *T0_frac, L_frame); - - - FOR (i=0; i= 2*L_SUBFR) && (i_subfr == 3*L_SUBFR) ) - { - tmp = shl(add(shl(*T0,2),*T0_frac),4); - (*pt_pitch_fx) -= 3; - move16(); - **pt_pitch_fx = tmp; - move16(); - (*pt_pitch_fx)++; - move16(); - **pt_pitch_fx = tmp; - move16(); - (*pt_pitch_fx)++; - move16(); - **pt_pitch_fx = tmp; - move16(); - (*pt_pitch_fx)++; - } - ELSE IF( (*tc_subfr == L_SUBFR) && (i_subfr == 2*L_SUBFR) ) - { - tmp = shl(add(shl(*T0,2),*T0_frac),4); - (*pt_pitch_fx) -= 2; - move16(); - **pt_pitch_fx = tmp; - move16(); - (*pt_pitch_fx)++; - move16(); - **pt_pitch_fx = tmp; - move16(); - (*pt_pitch_fx)++; - move16(); - } - ELSE IF( (*tc_subfr == TC_0_64) && (i_subfr == L_SUBFR) ) - { - tmp = shl(add(shl(*T0,2),*T0_frac),4); - (*pt_pitch_fx) -= 1; - move16(); - **pt_pitch_fx = tmp; - move16(); - (*pt_pitch_fx)++; - move16(); - } - ELSE IF( (*tc_subfr == TC_0_128) && (i_subfr == 2*L_SUBFR) ) - { - tmp = shl(add(shl(*T0,2),*T0_frac),4); - (*pt_pitch_fx) -= 2; - move16(); - **pt_pitch_fx = tmp; - move16(); - (*pt_pitch_fx)++; - move16(); - **pt_pitch_fx = tmp; - move16(); - (*pt_pitch_fx)++; - move16(); - } - ELSE IF( (*tc_subfr == TC_0_192) && (i_subfr == 3*L_SUBFR) ) - { - tmp = shl(add(shl(*T0,2),*T0_frac),4); - (*pt_pitch_fx) -= 3; - move16(); - **pt_pitch_fx = tmp; - move16(); - (*pt_pitch_fx)++; - move16(); - **pt_pitch_fx = tmp; - move16(); - (*pt_pitch_fx)++; - move16(); - **pt_pitch_fx = tmp; - move16(); - (*pt_pitch_fx)++; - move16(); - } - } - ELSE /* L_frame == L_FRAME16k */ - { - if( sub(i_subfr,2*L_SUBFR) >= 0) - { - limit_flag = 1; - move16(); - } - IF( sub(i_subfr,2*L_SUBFR) <= 0) - { - IF( sub(i_subfr,2*L_SUBFR) < 0 ) - { - mult_Top = 1; - move16(); - if( sub(T_op_fx[0],PIT16k_MIN) < 0 ) - { - mult_Top = 2; - move16(); - } - - limit_T0_fx( L_FRAME16k, 8, 0, limit_flag, mult_Top*T_op_fx[0], 0, T0_min, T0_max ); /* TC0 second subfr. */ - - } - ELSE - { - limit_T0_fx( L_FRAME16k, 8, 0, limit_flag, T_op_fx[1], 0, T0_min, T0_max ); /* TC0 third subfr., or TC64 third subfr. */ - } - } - - /*-----------------------------------------------------------------* - * get number of bits for pitch encoding - *-----------------------------------------------------------------*/ - - nBits = ACB_bits_16kHz_tbl[BIT_ALLOC_IDX_16KHZ_fx(core_brate, coder_type, i_subfr, TC_SUBFR2IDX_16KHZ_fx(*tc_subfr))]; - move16(); - - /*-----------------------------------------------------------------* - * Find adaptive part of excitation, encode pitch period - *-----------------------------------------------------------------*/ - - IF( sub(nBits,10) == 0 ) - { - *T0 = pitch_fr4_fx( &exc_fx[i_subfr], xn_fx, h1_fx, *T0_min, *T0_max, T0_frac, 0, limit_flag, PIT16k_FR2_EXTEND_10b, PIT16k_MAX, L_frame, L_SUBFR ); - pit16k_Q_enc_fx( st_fx, nBits, limit_flag, *T0, *T0_frac, T0_min, T0_max ); - } - ELSE IF( sub(nBits,8) == 0 ) /* tc_subfr==0 && i_subfr==L_SUBFR */ - { - /*-----------------------------------------------------------------------------* - * The pitch range is encoded absolutely with 8 bits and is divided as follows: - * PIT16k_MIN to PIT16k_FR2_TC0_2SUBFR-1 resolution 1/4 (frac = 0,1,2 or 3) - * PIT16k_FR2_TC0_2SUBFR to 2*L_SUBFR resolution 1/2 (frac = 0 or 2) - *-----------------------------------------------------------------------------*/ - *T0 = pitch_fr4_fx( &exc_fx[i_subfr], xn_fx, h1_fx, *T0_min, *T0_max, T0_frac, 0, limit_flag, PIT16k_FR2_TC0_2SUBFR, 2*L_SUBFR, L_frame, L_SUBFR ); - - IF( sub(*T0_max,2*L_SUBFR) > 0) - { - *T0 = 2*L_SUBFR; - move16(); - *T0_frac = 0; - move16(); - } - - IF( sub(*T0,PIT16k_FR2_TC0_2SUBFR ) < 0) - { - /*index = (*T0)*4 + (*T0_frac) - (PIT16k_MIN*4);*/ - index = add(shl(*T0,2), sub(*T0_frac, PIT16k_MIN*4)); - } - ELSE - { - /*index = (*T0)*2 + ((*T0_frac)>>1) - (PIT16k_FR2_TC0_2SUBFR*2) + ((PIT16k_FR2_TC0_2SUBFR-PIT16k_MIN)*4);*/ - index = add(sub(add(shl(*T0,1), shr(*T0_frac,1)), (PIT16k_FR2_TC0_2SUBFR*2)), (PIT16k_FR2_TC0_2SUBFR-PIT16k_MIN)*4); - } - push_indice_fx( st_fx, IND_PITCH, index, nBits ); - } - ELSE IF( sub(nBits,6) == 0 ) - { - /* delta search */ - *T0 = pitch_fr4_fx( &exc_fx[i_subfr], xn_fx, h1_fx, *T0_min, *T0_max, T0_frac, L_SUBFR, limit_flag, PIT16k_FR2_EXTEND_9b, PIT16k_FR1_EXTEND_9b, L_frame, L_SUBFR ); - - index = delta_pit_enc_fx( 4, *T0, *T0_frac, *T0_min ); - push_indice_fx( st_fx, IND_PITCH, index, nBits ); - } - IF( sub(nBits,6) == 0 ) - { - limit_T0_fx( L_FRAME16k, 8, L_SUBFR, limit_flag, *T0, *T0_frac, T0_min, T0_max ); - } - - /*-----------------------------------------------------------------* - * - gain clipping test to avoid unstable synthesis - * - LP filtering of the adaptive excitation - * - codebook target computation - *-----------------------------------------------------------------*/ - test(); - IF( (sub(i_subfr,L_SUBFR) == 0) && (sub(*T0,2*L_SUBFR) == 0) ) - { - *gain_pit_fx = 0; - move16(); - *clip_gain = 0; - move16(); - g_corr_fx[0] = 0; - move16(); - g_corr_fx[1] = 0; - move16(); - *Jopt_flag = 0; - move16(); - - set16_fx( &exc_fx[i_subfr], 0, L_SUBFR+1 ); /* set excitation for current subrame to 0 */ - push_indice_fx( st_fx, IND_LP_FILT_SELECT, 0, 1 ); /* this bit is actually not needed */ - - Copy( xn_fx, xn2_fx, L_SUBFR ); /* target vector for codebook search */ - set16_fx( y1_fx, 0, L_SUBFR ); /* set filtered adaptive excitation to 0 */ - set16_fx( &bwe_exc_fx[i_subfr * 2], 0, L_SUBFR * 2 ); - } - ELSE - { - /* Find the adaptive codebook vector - ACELP long-term prediction */ - pred_lt4(&exc_fx[i_subfr], &exc_fx[i_subfr], *T0, *T0_frac, L_SUBFR+1, pitch_inter4_2, L_INTERPOL2, PIT_UP_SAMP); - offset = L_deposit_l(0); - - tmp = extract_l(L_mult(*T0_frac,32));/*Q8, 0.25 in Q7*/ - tmp = add(512,tmp);/*Q8; 2 in Q8*/ - tmp = mult_r(tmp,256);/*Q16->Q0; 2 in Q7*/ - - tmp1 = sub(*T0,2);/*Q0*/ - tmp1 = shl(tmp1,1);/*Q0 */ - - offset = add(tmp,tmp1);/*Q0*/ - FOR (i=0; i|| | imp_shape->| g1 | | - * | | | | g2 | ---- exc |---| y1 ---- | - * | | |-------------| |----|gain|-------| h |------|gain|----(-)---> xn2 - * | || | gn | ---- |---| ---- - * |----| |----| - * codebook excitation gain_trans h_orig gain_pit - * - *-------------------------------------------------------------------------------------------*/ - -static void tc_enc_fx( - Encoder_State_fx *st_fx, /* i/o: encoder state structure */ - const Word32 core_brate, /* i : core bitrate */ - const Word16 L_frame, /* i : length of the frame */ - const Word16 i_subfr, /* i : subrame index */ - Word16 *tc_subfr, /* i/o: TC subframe index */ - Word16 *position, /* i/o: index of the residual signal maximum */ - const Word16 *h1_fx, /* i : weighted filter input response Q(14+shift)*/ - const Word16 *xn_fx, /* i : target signal Q_new-1+shift*/ - Word16 *exc_fx, /* o : glottal codebook contribution Q_new*/ - Word16 *yy1_fx, /* o : filtered glottal codebook contribution */ - Word16 *T0_min, /* o : lower pitch limit Q0*/ - Word16 *T0_max, /* o : higher pitch limit Q0*/ - Word16 *T0, /* o : close loop integer pitch Q0*/ - Word16 *T0_frac, /* o : close loop fractional part of the pitch Q0*/ - Word16 *gain_pit_fx, /* o : pitch gain (0..GAIN_PIT_MAX) Q14*/ - Word16 g_corr_fx[], /* o : correlations and -2 */ - Word16 *bwe_exc_fx, /* i/o: excitation for SWB TBE Q_new*/ - Word16 Q_new /* i : input scaling */ -) -{ - Word16 i,imp_shape, imp_pos, index, nBits, h1_tmp_fx[L_SUBFR]; - Word16 pitch_index,pitch_sign_fx; - Word32 gain_trans32; - - imp_pos = sub(*position, i_subfr); - FOR (i = 0; i < L_SUBFR; i++) - { - h1_tmp_fx[i] = h1_fx[i]; - move16(); - } - /*-----------------------------------------------------------------* - * get number of bits for pitch encoding - *-----------------------------------------------------------------*/ - - IF( sub(L_frame,L_FRAME) == 0 ) - { - nBits = ACB_bits_tbl[BIT_ALLOC_IDX_fx(core_brate, TRANSITION, i_subfr, TC_SUBFR2IDX_fx(*tc_subfr))]; - move16(); - } - ELSE /* L_frame == L_FRAME16k */ - { - nBits = ACB_bits_16kHz_tbl[BIT_ALLOC_IDX_16KHZ_fx(core_brate, TRANSITION, i_subfr, TC_SUBFR2IDX_16KHZ_fx(*tc_subfr))]; - move16(); - } - - /*--------------------------------------------------------------* - * Closed loop pitch search - *--------------------------------------------------------------*/ - - *T0_frac = 0; - move16(); - - IF( sub(L_frame,L_FRAME) == 0 ) - { - test(); - IF( (sub(*T0_min,L_SUBFR) <= 0) || (sub(*tc_subfr,3*L_SUBFR) == 0) ) - { - IF( sub(nBits,9) == 0 ) - { - *T0 = pitch_fr4_fx( &exc_fx[i_subfr], xn_fx, h1_fx, *T0_min, *T0_max, T0_frac, 0, 0, PIT_FR2_9b, PIT_FR1_9b, L_FRAME, L_SUBFR ); - } - ELSE IF( sub(nBits,6) == 0 ) - { - *T0 = pitch_fr4_fx( &exc_fx[i_subfr], xn_fx, h1_fx, *T0_min, *T0_max, T0_frac, 0, 0, PIT_MIN, L_SUBFR, L_FRAME, L_SUBFR ); - } - ELSE - { - *T0 = pitch_fr4_fx( &exc_fx[i_subfr], xn_fx, h1_fx, *T0_min, *T0_max, T0_frac, 0, 0, PIT_MAX, PIT_MIN, L_FRAME, L_SUBFR ); - } - } - ELSE - { - *T0 = L_SUBFR; - move16(); - } - test(); - if( sub(*tc_subfr,L_SUBFR) == 0 && sub(*T0,L_SUBFR) < 0 ) - { - *T0 = L_SUBFR; - move16(); - } - } - ELSE /* L_frame == L_FRAME16k */ - { - IF( sub(nBits,10) == 0 ) - { - *T0 = pitch_fr4_fx( &exc_fx[i_subfr], xn_fx, h1_fx, *T0_min, *T0_max, T0_frac, 0, 1, PIT16k_FR2_EXTEND_10b, PIT16k_MAX, L_FRAME16k, L_SUBFR ); - } - ELSE IF( sub(nBits,6) == 0 ) - { - /* T0_frac with 1/2 sample resolution */ - *T0 = pitch_fr4_fx( &exc_fx[i_subfr], xn_fx, h1_fx, *T0_min, *T0_max, T0_frac, 0, 0, PIT16k_MIN, L_SUBFR, L_FRAME16k, L_SUBFR ); - IF( *T0 > L_SUBFR ) - { - *T0 = L_SUBFR; - move16(); - *T0_frac = 0; - move16(); - } - } - } - - - /* set tc_subfr to TC_0_0 */ - test(); - test(); - test(); - if( i_subfr == 0 && sub(L_frame,L_FRAME) == 0 && ( sub(*T0,L_SUBFR) < 0 || sub(*tc_subfr,3*L_SUBFR) == 0) ) - { - *tc_subfr = TC_0_0; - move16(); - } - - /*--------------------------------------------------------------* - * Builds glottal codebook contribution - *--------------------------------------------------------------*/ - - set_impulse_fx(xn_fx, h1_tmp_fx, &exc_fx[i_subfr], yy1_fx, &imp_shape, &imp_pos, &gain_trans32, Q_new);/*chk h1_tmp_fx*/ - - /*--------------------------------------------------------------* - * quantize gain_trans and scale glottal codebook contribution - *--------------------------------------------------------------*/ - - gain_trans_enc_fx( gain_trans32, &exc_fx[i_subfr], &pitch_index, &pitch_sign_fx, Q_new ); - - /* set past excitation buffer to zeros */ - set16_fx( exc_fx-L_EXC_MEM, 0, L_EXC_MEM ); - /*--------------------------------------------------------------* - * adapt. search of the second impulse in the same subframe - * (when appears) - *--------------------------------------------------------------*/ - - pred_lt4_tc_fx( exc_fx, *T0, *T0_frac, inter4_2_fx, imp_pos, i_subfr ); - - IF( sub(L_frame,L_FRAME) == 0 ) - { - interp_code_5over2_fx(&exc_fx[i_subfr], &bwe_exc_fx[i_subfr * HIBND_ACB_L_FAC], L_SUBFR); - } - ELSE - { - interp_code_4over2_fx(&exc_fx[i_subfr], &bwe_exc_fx[i_subfr * 2], L_SUBFR); - } - - /*--------------------------------------------------------------* - * compute glottal-shape codebook excitation - *--------------------------------------------------------------*/ - - /* create filtered glottal codebook contribution */ - conv_fx( &exc_fx[i_subfr], h1_fx, yy1_fx, L_SUBFR ); - - /* gain_pit computation */ - *gain_pit_fx = corr_xy1_fx( xn_fx, yy1_fx, g_corr_fx, L_SUBFR, 0 ); - - /*--------------------------------------------------------------* - * Encode parameters and write indices - *--------------------------------------------------------------*/ - IF( sub(L_frame,L_FRAME) == 0 ) - { - test(); - test(); - IF( ( (i_subfr != 0) || (sub(*tc_subfr,TC_0_0) == 0) ) - && (sub(*tc_subfr,L_SUBFR) != 0)) - { - test(); - /* write pitch index */ - IF( (sub(*T0,L_SUBFR) >= 0) && (sub(*tc_subfr,3*L_SUBFR) != 0) ) - { - push_indice_fx( st_fx, IND_PITCH, 0, nBits ); - } - ELSE IF( sub(*tc_subfr,3*L_SUBFR) == 0) - { - IF( sub(nBits,9) == 0 ) - { - index = abs_pit_enc_fx( 4, 0, *T0, *T0_frac ); - } - ELSE - { - index = abs_pit_enc_fx( 2, 0, *T0, *T0_frac ); - } - push_indice_fx( st_fx, IND_PITCH, index, nBits ); - - limit_T0_fx( L_FRAME, 8, 0, 0, *T0, 0, T0_min, T0_max ); - } - ELSE - { - IF( sub(nBits,6) == 0 ) - { - index = delta_pit_enc_fx( 2, *T0, *T0_frac, PIT_MIN-1 ); - push_indice_fx( st_fx, IND_PITCH, index, nBits ); - } - ELSE - { - index = delta_pit_enc_fx( 0, *T0, *T0_frac, PIT_MIN-1 ); - push_indice_fx( st_fx, IND_PITCH, index, nBits ); - } - } - } - } - ELSE /* L_frame == L_FRAME16k */ - { - IF( sub(nBits,10) == 0 ) - { - pit16k_Q_enc_fx( st_fx, nBits, 1, *T0, *T0_frac, T0_min, T0_max ); - } - ELSE IF( sub(nBits,6) == 0 ) - { - index = add(shl(sub(*T0,PIT16k_MIN),1) , shr(*T0_frac,1)); - push_indice_fx( st_fx, IND_PITCH, index, nBits ); - } - } - push_indice_fx( st_fx, IND_TC_IMP_SHAPE, imp_shape, 3 ); - push_indice_fx( st_fx, IND_TC_IMP_POS, imp_pos, 6 ); - push_indice_fx( st_fx, IND_TC_IMP_SIGN, pitch_sign_fx, 1 ); - push_indice_fx( st_fx, IND_TC_IMP_GAIN, pitch_index, 3 ); - - *position = add(imp_pos, i_subfr); - move16(); - return; -} - - -/*-----------------------------------------------------------------* - * gain_trans_enc() - * - * Quantize gain_trans of TC (gains of glottal impulses). - * - Uses scalar quantization prototypes tbl_gain_trans_tc[N_GAIN_TC]. - * - Gains the glottal codebook contibution signal. - *-----------------------------------------------------------------*/ -static void gain_trans_enc_fx( - Word32 gain_trans32, /* i : gain for mode Tc Q7 */ - Word16 exc[], /* i/o: glottal codebook contribution i:Q13 o:Q_new*gain_trans */ - Word16 *quant_index, /* o : index of quantized gain_trans */ - Word16 *quant_sign, /* o : sign of quantized gain_trans */ - Word16 Q_new /* i : curent scaling */ -) -{ - Word16 i, imax, istart, tmp16, gain_trans, gscale; - - istart = 0; - move16(); - imax = 4; - move16(); - gscale = 7; - move16(); - gain_trans = extract_h(L_shl(gain_trans32,16)); /* Q7 */ - - IF (L_sub(L_abs(gain_trans32), 29862L)>0) - { - gain_trans = extract_h(L_shl(gain_trans32,16-3)); /* Q4 */ - istart = 4; - move16(); - imax = N_GAIN_TC-1; - move16(); - gscale = 4; - move16(); - } - - /* qsign = 0 if *gain_trans < 0 else qsign = 1*/ - tmp16 = shr(gain_trans,16); - *quant_sign = add(1, tmp16); - move16();/* quantize sign */ - tmp16 = s_or(tmp16, 1); /* Keep sign */ - gain_trans = abs_s(gain_trans); - - *quant_index = N_GAIN_TC-1; - move16(); - FOR (i = istart; i < imax; i++) - { - IF (sub(gain_trans,tbl_gain_trans_tc_fx[i]) <= 0 ) - { - *quant_index = i; - move16(); - BREAK; - } - } - - gain_trans = i_mult2(tbl_gain_trans_tc_fx[i], tmp16); /* Retreive quantized gain with sign */ - tmp16 = sub(Q_new,add(gscale,13-16+1)); /*remove 16 from rounding */ - FOR (i = 0; i < L_SUBFR; i++) - { - /*exc[i] *= (*gain_trans);*/ - exc[i] = round_fx(L_shl(L_mult(exc[i], gain_trans),tmp16)); - } -} - diff --git a/src/libs/libevs/lib_enc/update_decision.cpp b/src/libs/libevs/lib_enc/update_decision.cpp old mode 100755 new mode 100644 index 1046363c..075c2f40 --- a/src/libs/libevs/lib_enc/update_decision.cpp +++ b/src/libs/libevs/lib_enc/update_decision.cpp @@ -1,463 +1,248 @@ /*==================================================================================== - EVS Codec 3GPP TS26.442 Apr 03, 2018. Version 12.11.0 / 13.6.0 / 14.2.0 + EVS Codec 3GPP TS26.443 Nov 13, 2018. Version 12.11.0 / 13.7.0 / 14.3.0 / 15.1.0 ====================================================================================*/ +#include "prot.h" +#include +#include + -#include "basop_util.h" -#include "stl.h" -#include "vad_basop.h" -#include "prot_fx.h" void bg_music_decision(T_CldfbVadState *st, - Word16 *music_backgound_f, /*(i) background music flag*/ - Word32 frame_energy, /*(i) current frame energy 1*/ - Word16 frame_energy_Q /*(i) the Scaling of current frame energy*/ + int *music_backgound_f, /*(i) background music flag*/ + float frame_energy /*(i) current frame energy 1*/ ) { - - Word16 *f_tonality_rate = st->f_tonality_rate; - Word16 *ltd_stable_rate = st->ltd_stable_rate; - Word16 *sp_center = st->sp_center; - Word16 *sSFM = st->sfm; - Word16 cmp_result; - Word32 music_background_frame; - Word32 tmp1; - Word16 tmp1_Q; - Word16 tmp_norm; - Word32 frame_energy_Mcount; - Word16 fg_energy_Qtmp; + int music_background_frame=0; + float *sp_center = st->sp_center; + float *ltd_stable_rate = st->ltd_stable_rate; + float *sSFM = st->sfm; + float *f_tonality_rate = st->f_tonality_rate; - music_background_frame = L_add(0,0); - tmp1 = L_mult(st->fg_energy_count,18842); - tmp1_Q = norm_l(tmp1); - tmp1 = L_shl(tmp1,tmp1_Q); - tmp_norm = extract_h(tmp1); - frame_energy_Mcount = MUL_F(frame_energy,tmp_norm); - - fg_energy_Qtmp = sub(frame_energy_Q, 18); - fg_energy_Qtmp = add(fg_energy_Qtmp, tmp1_Q); - - cmp_result = VAD_L_CMP(frame_energy_Mcount,fg_energy_Qtmp,st->fg_energy,st->fg_energy_scale); - - test(); - IF((sub(f_tonality_rate[1],9830/* 0.6 Q14 */)>0) - ||(sub(f_tonality_rate[0],14089/* 0.86 Q14 */)>0)) + if((f_tonality_rate[1]>0.60)||(f_tonality_rate[0]>0.86)) { - - test(); - test(); - test(); - test(); - if((sub(ltd_stable_rate[0], 2359/* 0.072 Q15 */)<0) - &&(sub(sp_center[0],1228/* 1.2 Q10 */)>0) - &&((sub(sSFM[0],24903/* 0.76 Q15 */)<0) - ||(sub(sSFM[1],28835/* 0.88 Q15 */)<0) - ||(sub(sSFM[2],31456/* 0.96 Q15 */)<0))) + if(ltd_stable_rate[0]<0.072&&sp_center[0]>1.2&&(sSFM[0]<0.76||sSFM[1]<0.88||sSFM[2]<0.96)) { - music_background_frame = L_add(1,0); + music_background_frame = 1; } } - - test(); - test(); - IF(music_background_frame - &&(cmp_result > 0) - &&(L_sub(st->fg_energy_est_start,1)==0)) + if(music_background_frame&&(4.6*st->fg_energy_count*frame_energy>st->fg_energy)&&(st->fg_energy_est_start==1)) { - st->music_background_rate = add(mult(st->music_background_rate,31949), 819); - move16(); + st->music_background_rate = st->music_background_rate*0.975f + 0.025f; } - ELSE IF(music_background_frame) + else if(music_background_frame) { - st->music_background_rate = add(mult(st->music_background_rate,32702), 66); - move16(); + st->music_background_rate = st->music_background_rate*0.998f + 0.002f; } - ELSE + else { - st->music_background_rate = mult(st->music_background_rate,32670); - move16(); + st->music_background_rate = st->music_background_rate*0.997f; } - - *music_backgound_f = 0; - move16(); - if(sub(st->music_background_rate, 16384)> 0) + if(st->music_background_rate>0.5) { *music_backgound_f = 1; - move16(); } - + else + { + *music_backgound_f = 0; + } } -Word16 update_decision(T_CldfbVadState *st, - Word32 frame_energy, /*(i) current frame energy*/ - Word32 HB_Power,/*(i) current frame high frequency energy*/ - Word16 frameloop,/*(i) amount of frames*/ - Word16 bw, /*(i) band width index*/ - Word16 frame_energy_Q, /*(i) the Scaling of current frame energy*/ - Word16 HB_Power_Q, /*(i) the Scaling of current frame high frequency energy*/ - Word32 snr, /*(i) frequency domain SNR */ - Word32 tsnr, /*(i) time domain SNR */ - Word16 vad_flag, - Word16 music_backgound_f/*(i) background music flag*/ - ) +int update_decision(T_CldfbVadState *st, + float snr, /*(i) frequency domain SNR */ + float tsnr, /*(i) time domain SNR */ + float frame_energy, /*(i) current frame energy*/ + float high_eng, /*(i) current frame high frequency energy*/ + int vad_flag, + int music_backgound_f /*(i) background music flag*/ + ) { - Word16 *sp_center = st->sp_center; - Word16 *ltd_stable_rate = st->ltd_stable_rate; - Word16 *sSFM = st->sfm; - Word16 *f_tonality_rate = st->f_tonality_rate; - - Word16 update_flag; - Word16 tonality_flag; - Word32 tmp1; - Word16 tmp1_Q; - Word16 tmp_norm; - Word32 frame_energy_Mcount; - Word32 lt_bg_highf_eng_trbl; - Word16 flag_high_eng; - Word16 fg_energy_Qtmp; - Word16 cmp_result; - Word16 tmpout; - Word16 sp_center3_diff; - - Word16 Q_counter; - Word16 Q_sum; - Word32 sum_num,counter_den; - Word16 div_r; - - Word16 div_r_Q; - Word32 div_r_32; + float g_high_eng_sacle = 0.0f; + float sp_center3_diff; + int update_flag = 1; + int tonality_flag = 0; + int frameloop = st->frameloop; + int bw = st->bw_index; + float *sp_center = st->sp_center; + float *ltd_stable_rate = st->ltd_stable_rate; + float *sSFM = st->sfm; + float *f_tonality_rate = st->f_tonality_rate; + float tmpout = frame_energy - 4*st->frame_energy_smooth; - update_flag = 1; - move16(); - tonality_flag = 0; - move16(); - - lt_bg_highf_eng_trbl = MUL_F(st->lt_bg_highf_eng,24576); - IF (sub(14,HB_Power_Q)>0) + g_high_eng_sacle = high_eng/(st->lt_bg_highf_eng + FLT_MIN); + sp_center3_diff = sp_center[3] - st->lt_noise_sp_center3; + if(frameloop>50) { - lt_bg_highf_eng_trbl = L_shr(lt_bg_highf_eng_trbl,sub(14,HB_Power_Q)); - } - ELSE - { - HB_Power = L_shr(HB_Power, s_min(31, sub(HB_Power_Q, 14))); - } - - flag_high_eng = 0; - move16(); - if (L_sub(HB_Power,lt_bg_highf_eng_trbl)>0) - { - flag_high_eng = 1; - move16(); - } - - sp_center3_diff = sub(sp_center[3], st->lt_noise_sp_center3); - - IF(sub(frameloop, 50) > 0) - { - if(sub(ltd_stable_rate[0],3932/* 0.12 Q15 */)>0) + if(ltd_stable_rate[0]>0.12) { - update_flag = 0; - move16(); + update_flag=0; } - tmpout= VAD_L_CMP(frame_energy, sub(frame_energy_Q,2), st->frame_energy_smooth,st->frame_energy_smooth_scale); - test(); - IF((sub(bw, CLDFBVAD_NB_ID) != 0) && tmpout>0 ) + if((bw == CLDFBVAD_WB_ID || bw == CLDFBVAD_SWB_ID) && st->frame_energy_smooth < 4*frame_energy) { - test(); - if((flag_high_eng) && (sub(sp_center3_diff, 409)> 0)) + if(g_high_eng_sacle > 3.0f && (sp_center3_diff > 0.4)) { update_flag = 0; - move16(); } - test(); - if((sub(sp_center[3],2864/* 2.8 Q10 */) >0)&&(sub(ltd_stable_rate[0], 655/* 0.02 Q15 */)>0)) + if((sp_center[3]>2.8f)&&(ltd_stable_rate[0]>0.02f)) { update_flag = 0; - move16(); } } } - test(); - if((sub(f_tonality_rate[1], 8192/* 0.5 Q14 */)>0 ) - && (sub(ltd_stable_rate[0],3277/* 0.1 Q15 */)>0)) + + + if((f_tonality_rate[1] > 0.50) && (ltd_stable_rate[0]>0.1)) { update_flag = 0; - move16(); + } + if(sSFM[1] < 0.92 && sSFM[0] < 0.92 && sSFM[2] < 0.92) + { + update_flag=0; + } + if(sSFM[0] < 0.80 || sSFM[1] < 0.78|| sSFM[2] < 0.80) + { + update_flag=0; } - test(); - test(); - IF((sub(sSFM[1], 30146/* 0.92 Q15 */) <0 ) - && (sub(sSFM[0], 30146/* 0.92 Q15 */)< 0) - && (sub(sSFM[2], 30146/* 0.92 Q15 */)< 0)) + if(frame_energy > 32*st->frame_energy_smooth) { update_flag = 0; - move16(); } - - test(); - test(); - IF((sub(sSFM[0], 26214/* 0.8 Q15 */)<0 ) - || (sub(sSFM[1],25558/* 0.78 Q15 */) <0 ) - || (sub(sSFM[2],26214/* 0.8 Q15 */) <0 )) + if((4.6*st->fg_energy_count*frame_energy>st->fg_energy)&&(st->fg_energy_est_start==1)&&(frame_energy>3)) { update_flag = 0; - move16(); } - - /*if(frame_energy > 32*st->frame_energy_smooth)*/ - tmpout= VAD_L_CMP(frame_energy, frame_energy_Q, st->frame_energy_smooth,sub(st->frame_energy_smooth_scale,5)); - - if(tmpout>0) + if((f_tonality_rate[1]>0.60)||(f_tonality_rate[0]>0.86)) { - update_flag = 0; - move16(); - } - tmp1 = L_mult(st->fg_energy_count,18842); - tmp1_Q = norm_l(tmp1); - tmp1 = L_shl(tmp1,tmp1_Q); - tmp_norm = extract_h(tmp1); - frame_energy_Mcount = MUL_F(frame_energy,tmp_norm); - - fg_energy_Qtmp = sub(frame_energy_Q, 18); - fg_energy_Qtmp = add(fg_energy_Qtmp, tmp1_Q); - - cmp_result = VAD_L_CMP(frame_energy_Mcount,fg_energy_Qtmp,st->fg_energy,st->fg_energy_scale); - - tmpout = VAD_L_CMP(frame_energy, frame_energy_Q, 3, 0); - - test(); - test(); - if((cmp_result>0) - &&(L_sub(st->fg_energy_est_start,1)==0) - &&(tmpout>0)) - { - update_flag = 0; - move16(); - } - - test(); - IF((sub(f_tonality_rate[1],9830/* 0.6 Q14 */)>0) - ||(sub(f_tonality_rate[0],14089/* 0.86 Q14 */)>0)) - { - update_flag = 0; - move16(); + update_flag = 0; tonality_flag = 1; - move16(); } - st->tonality_rate3 = mult(st->tonality_rate3, 32211); - move16(); + if(tonality_flag) { - st->tonality_rate3 = add(mult(st->tonality_rate3,32211), 557); - move16(); + st->tonality_rate3 = st->tonality_rate3*0.983f + 0.017f; + } + else + { + st->tonality_rate3 = st->tonality_rate3*0.983f; } - if(sub(st->tonality_rate3, 16384)>0) + if(st->tonality_rate3>0.5) { update_flag = 0; - move16(); } - test(); - if((sub(sp_center[0], 4092/* 4.0 Q10 */)> 0) - && (sub(ltd_stable_rate[0], 1311/* 0.04 Q15 */)>0)) + + if((sp_center[0] > 4.0f) && ltd_stable_rate[0]>0.04) { update_flag = 0; - move16(); } - - test(); - test(); - IF((sub(f_tonality_rate[1], 7536/* 0.46 Q14 */)> 0) - && ((sub(sSFM[1],30473/* 0.93 Q15 */) > 0) - ||(sub(ltd_stable_rate[0], 2949/* 0.09 Q15 */)>0))) - + if((f_tonality_rate[1] > 0.46) && ((sSFM[1] > 0.93)||(ltd_stable_rate[0]>0.09))) { update_flag = 0; - move16(); - } - test(); - test(); - test(); - IF( (sub(sSFM[1],30473/* 0.93 Q15 */) < 0 - && sub(sSFM[0], 30146/* 0.92 Q15 */)< 0 - && sub(sSFM[2], 31784/* 0.97 Q15 */)< 0) - && (sub(f_tonality_rate[1], 8192/* 0.5 Q14 */)> 0)) + } + if((sSFM[1] < 0.93 && sSFM[0] < 0.92 && sSFM[2] < 0.97) && (f_tonality_rate[1] > 0.5)) { update_flag = 0; - move16(); } - - test(); - test(); - IF((f_tonality_rate[1] > 7045/* 0.43 Q14 */) - &&(sSFM[0] < 31129/* 0.95 Q15 */) - &&(sp_center[1] > 1985/* 1.94 Q10 */)) + if((f_tonality_rate[1] > 0.43)&&(sSFM[0] < 0.95)&&(sp_center[1] > 1.94f)) { update_flag = 0; - move16(); } - IF(sub(update_flag, 1)==0) + if(update_flag) { - if(sub(st->update_count, 1000) < 0) + if(st->update_count < 1000) { - st->update_count = add(st->update_count,1); + st->update_count = st->update_count + 1; } + } - IF(update_flag) + if(update_flag) { - st->lt_noise_sp_center3 = add(mult(st->lt_noise_sp_center3,29491),mult(sp_center[3],3277)); - move16(); + st->lt_noise_sp_center3 = 0.9f*st->lt_noise_sp_center3 + 0.1f*sp_center[3]; } - - - - tmpout= VAD_L_CMP(frame_energy, frame_energy_Q, st->frame_energy_smooth,sub(st->frame_energy_smooth_scale,2)); - - - test(); - test(); - test(); - test(); - if((tmpout>0) - &&(sub(frameloop, 100) < 0) - &&(sub(f_tonality_rate[1],9174/* 0.56 Q14 */)<0) - &&((sub(sp_center[0], 1391/* 1.36 Q10 */)<0)||sub(ltd_stable_rate[0],983/* 0.03 Q15 */)<0)) + if((tmpout>0)&&(frameloop<100)&&(f_tonality_rate[1]<0.56)&&((sp_center[0]<1.36)||ltd_stable_rate[0]<0.03)) { update_flag = 1; - move16(); } + if(snr<0.3 && tmpout < 0 + &&tsnr<1.2&&vad_flag==0&&f_tonality_rate[1]<0.5 + &&(music_backgound_f==0)&<d_stable_rate[3]<0.1) - test(); - test(); - test(); - test(); - test(); - test(); - if((L_sub(snr,10066329/* 0.3 Q25 */) <0) && tmpout < 0 - &&(L_sub(L_shr(tsnr,1), 20132659/* 1.2/2.0 Q25 */)<0) - &&(vad_flag==0) - &&(sub(st->f_tonality_rate[1],8192/* 0.5 Q14 */)<0) - &&(music_backgound_f==0) - &&(sub(st->ltd_stable_rate[3],3277/* 0.1 Q15 */)<0)) { update_flag = 1; - move16(); } - - test(); - test(); - test(); - IF(vad_flag && L_sub(snr, 33554431/* 1.0 Q25 */)>0 && sub(bw, CLDFBVAD_SWB_ID)==0 && tmpout > 0) + if(vad_flag && (snr > 1.0) && bw == CLDFBVAD_SWB_ID && tmpout > 0) { update_flag = 0; } - test(); - test(); - test(); - IF(vad_flag && L_sub(snr, 50331647/* 1.5 Q25 */)>0 && sub(bw, CLDFBVAD_SWB_ID)!=0 && tmpout > 0) + if(vad_flag && (snr > 1.5) && bw != CLDFBVAD_SWB_ID && tmpout > 0) { update_flag = 0; } - IF(update_flag == 0) + if(update_flag == 0) { - st->updateNumWithSnr = 0; + st->update_num_with_snr = 0; } - ELSE + else { - test(); - test(); - IF(vad_flag && L_sub(snr, 100663293/* 3.0 Q25 */)>0 && sub(st->updateNumWithSnr, 10) < 0) + + if(vad_flag && (snr > 3.0) && st->update_num_with_snr < 10) { - update_flag = add(0, 0); - st->updateNumWithSnr = add(st->updateNumWithSnr, 1); + update_flag = 0; + st->update_num_with_snr++; } } - test(); - IF(vad_flag==0||sub(update_flag,1) == 0) - { - Word16 tmp_fix; - tmp_fix = sub(st->sp_center[2],st->lt_noise_sp_center0); - tmp_fix = abs_s(tmp_fix); - if (sub(tmp_fix, 2558/* 2.5 Q10 */)>0) - { - tmp_fix = 2558/* 2.5 Q10 */; - move16(); - } - st->lt_noise_sp_center_diff_sum = L_add(st->lt_noise_sp_center_diff_sum ,tmp_fix); - move32(); - st->lt_noise_sp_center_diff_counter = L_add(st->lt_noise_sp_center_diff_counter,1); - move32(); - IF(L_sub(st->lt_noise_sp_center_diff_counter, 128)==0) + if(vad_flag==0||update_flag == 1) + { + float tmpp =(float)fabs(st->sp_center[2]-st->lt_noise_sp_center0); + if(tmpp>2.5) { - st->lt_noise_sp_center_diff_sum = MUL_F(st->lt_noise_sp_center_diff_sum,24576); - move32(); + tmpp = 2.5f; + } + st->lt_noise_sp_center_diff_sum +=tmpp; + st->lt_noise_sp_center_diff_counter++; + if(st->lt_noise_sp_center_diff_counter==128) + { + st->lt_noise_sp_center_diff_sum = st->lt_noise_sp_center_diff_sum*0.75f; st->lt_noise_sp_center_diff_counter = 96; - move32(); } - - move16(); - move16(); - IF(sub((Word16)abs_s(sub(st->sp_center[0],st->lt_noise_sp_center0)), 2455/* 2.4 Q10 */) > 0) + if(fabs(sp_center[0]-st->lt_noise_sp_center0) >2.4 ) { - st->lt_noise_sp_center0 = add(mult(st->lt_noise_sp_center0,32637),mult(st->sp_center[0],131)); - move16(); + st->lt_noise_sp_center0 = 0.996f*st->lt_noise_sp_center0 + 0.004f*sp_center[0]; } - ELSE IF(sub((Word16)abs_s(sub(st->sp_center[0],st->lt_noise_sp_center0)), 1023/* 1.0 Q10 */) >0) + else if(fabs(sp_center[0]-st->lt_noise_sp_center0) >1.0 ) { - st->lt_noise_sp_center0 = add(mult(st->lt_noise_sp_center0,32440),mult(st->sp_center[0],328)); - move16(); + st->lt_noise_sp_center0 = 0.99f*st->lt_noise_sp_center0 + 0.01f*sp_center[0]; } - ELSE + else { - st->lt_noise_sp_center0 = add(mult(st->lt_noise_sp_center0,31457),mult(st->sp_center[0],1311)); - move16(); + st->lt_noise_sp_center0 = 0.96f*st->lt_noise_sp_center0 + 0.04f*sp_center[0]; } } - Q_sum = sub(norm_l(st->lt_noise_sp_center_diff_sum), 1); - Q_counter = norm_l(st->lt_noise_sp_center_diff_counter); - sum_num = L_shl(st->lt_noise_sp_center_diff_sum,Q_sum); - counter_den = L_shl(st->lt_noise_sp_center_diff_counter,Q_counter); - - IF(extract_h(counter_den)==0) - { - div_r = EVS_SW_MAX; - move16(); - } - ELSE - { - div_r = div_l(sum_num,extract_h(counter_den)); - } - - div_r = mult(div_r,24576); - div_r_32 = VAD_L_ADD(L_deposit_l(div_r),add(sub(Q_sum,Q_counter),22), 9830, 15,&div_r_Q); - div_r =extract_l(L_shr(div_r_32, sub(div_r_Q, SP_CENTER_Q))); - - test(); - if((sub(abs_s(sub(st->sp_center[2],st->lt_noise_sp_center0)), div_r)> 0) && (sub(frameloop, 200)>0)) + if((fabs(sp_center[2]-st->lt_noise_sp_center0) > (6*(st->lt_noise_sp_center_diff_sum/st->lt_noise_sp_center_diff_counter)+0.3))&&st->frameloop>200) { update_flag = 0; - move16(); } return update_flag; } + diff --git a/src/libs/libevs/lib_enc/updt_enc.cpp b/src/libs/libevs/lib_enc/updt_enc.cpp new file mode 100644 index 00000000..e0ea1dec --- /dev/null +++ b/src/libs/libevs/lib_enc/updt_enc.cpp @@ -0,0 +1,233 @@ +/*==================================================================================== + EVS Codec 3GPP TS26.443 Nov 13, 2018. Version 12.11.0 / 13.7.0 / 14.3.0 / 15.1.0 + ====================================================================================*/ + +#include "options.h" +#include "cnst.h" +#include "rom_com.h" +#include "prot.h" + +/*-------------------------------------------------------------------* + * updt_enc() + * + * Common updates (all frame types) + *-------------------------------------------------------------------*/ + +void updt_enc( + Encoder_State *st, /* i/o: state structure */ + const short L_frame, /* i : length of the frame */ + const short coder_type, /* i : speech coder type */ + const float *old_exc, /* i : buffer of excitation */ + const float *pitch_buf, /* i : floating pitch for each subframe */ + const float Es_pred, /* i : predicited scaled innovation energy */ + const float *Aq, /* i : A(z) quantized for all subframes */ + const float *lsf_new, /* i : current frame LSF vector */ + const float *lsp_new, /* i : current frame LSP vector */ + const float *old_bwe_exc /* i : buffer of excitation */ +) +{ + short i; + + /* update old excitation buffer */ + mvr2r( &old_exc[L_frame], st->LPDmem.old_exc, L_EXC_MEM ); + if( !st->Opt_AMR_WB ) + { + mvr2r( &old_bwe_exc[L_FRAME32k], st->old_bwe_exc, PIT16k_MAX * 2 ); + } + + /* update old LSP and LSF vector */ + mvr2r( lsp_new, st->lsp_old, M ); + mvr2r( lsf_new, st->lsf_old, M ); + + /* update last coder type */ + st->last_coder_type = coder_type; + if ( coder_type == INACTIVE || (st->bpf_off == 1 && coder_type != AUDIO && coder_type != TRANSITION) ) + { + st->last_coder_type = UNVOICED; + } + + /* this ensures that st->last_coder_type is never set to INACTIVE in case of AVQ inactive because the FEC does not distinguish between GSC inactive and AVQ inactive */ + if ( coder_type == INACTIVE && st->total_brate > ACELP_24k40 ) + { + st->last_coder_type = GENERIC; + } + + if( st->Opt_AMR_WB && coder_type == INACTIVE && st->core_brate != SID_1k75 && st->core_brate != FRAME__NO_DATA ) + { + /* overwrite previous coding type to help FEC */ + st->last_coder_type = UNVOICED; + } + + /* AC mode (GSC) - in speech we can consider that the last pitch band reached the max */ + if ( coder_type != AUDIO && coder_type != INACTIVE ) + { + st->mem_last_pit_band = 10 + BAND1k2; + st->past_dyn_dec = NOISE_LEVEL_SP0-1; /* tends to speech */ + st->noise_lev = NOISE_LEVEL_SP0-1; /* tends to speech */ + st->mid_dyn = 40.0f * 0.5f + st->mid_dyn * 0.5f; + } + + /* convert old LSP vector from 12kHz domain to 16kHz domain (needed in case of ACELP@12k8 <-> ACELP@16kHz switching) */ + if( L_frame == L_FRAME ) + { + mvr2r( st->lsp_old, st->lsp_old16k, M ); + + st->rate_switching_reset_16kHz=lsp_convert_poly( st->lsp_old16k, L_FRAME16k, st->Opt_AMR_WB ); + } + + /* update buffer of old subframe pitch values */ + if( st->last_L_frame != L_frame ) + { + if( L_frame == L_FRAME ) + { + for( i=0; iold_pitch_buf[NB_SUBFR+i] = 0.8f * st->old_pitch_buf[NB_SUBFR+i+1]; + } + } + else + { + for( i=NB_SUBFR; i>0; i-- ) + { + st->old_pitch_buf[NB_SUBFR+i] = 1.25f * st->old_pitch_buf[NB_SUBFR+i-1]; + } + st->old_pitch_buf[2*NB_SUBFR16k-1] = st->old_pitch_buf[2*NB_SUBFR16k-2]; + } + } + + mvr2r( &st->old_pitch_buf[L_frame/L_SUBFR], st->old_pitch_buf, L_frame/L_SUBFR ); + mvr2r( pitch_buf, &st->old_pitch_buf[L_frame/L_SUBFR], L_frame/L_SUBFR ); + + /* SC-VBR */ + st->last_Opt_SC_VBR = st->Opt_SC_VBR; + st->last_last_ppp_mode = st->last_ppp_mode; + st->last_ppp_mode = st->ppp_mode; + st->last_nelp_mode = st->nelp_mode; + + /* core switching updates */ + mvr2r( &Aq[(st->L_frame/L_SUBFR-1)*(M+1)], st->old_Aq_12_8, M+1 ); + st->old_Es_pred = Es_pred; + + return; +} + +/*-------------------------------------------------------------------* + * updt_IO_switch() + * + * Common updates for AMR-WB IO mode and EVS primary mode switching + *-------------------------------------------------------------------*/ + +void updt_IO_switch_enc( + Encoder_State *st, /* i/o: state structure */ + const short input_frame /* i : input frame length */ +) +{ + float xsp_tmp[M]; + + if( st->last_core == AMR_WB_CORE ) /* switching to EVS primary mode */ + { + /* reset onset detection counter */ + st->tc_cnt = -1; + + /* force safety-net LSFQ in the first frames after the switching */ + st->Nb_ACELP_frames = 0; + + /* AMR-WB IO mode uses ISF(ISP), but EVS primary mode LSF(LSP) */ + mvr2r( stable_LSP, xsp_tmp, M ); + isf2lsf( st->lsf_old, st->lsf_old, xsp_tmp, M, INT_FS_12k8 ); + mvr2r( stable_LSP, xsp_tmp, M ); + isp2lsp( st->lsp_old, st->lsp_old, xsp_tmp, M ); + isp2lsp( st->lsp_old1, st->lsp_old1, xsp_tmp, M ); + + mvr2r( stable_LSP, xsp_tmp, M ); + isp2lsp( st->lspCNG, st->lspCNG, xsp_tmp, M ); + if( st->old_enr_index >= 0 ) + { + st->old_enr_index = min( (short)((float)st->old_enr_index / STEP_AMR_WB_SID * STEP_SID), 127 ); + } + /* Perform preemphasis of the old input signal @16kHz */ + st->mem_preemph16k = 0; + preemph( st->old_inp_16k, PREEMPH_FAC_16k, L_INP_MEM, &(st->mem_preemph16k) ); + + /* reset TD BWE buffers */ + set_f( st->old_speech_shb, 0.0f, L_LOOK_16k + L_SUBFR16k ); + set_f( st->old_speech_wb, 0.0f, (L_LOOK_12k8 + L_SUBFR) * 5/16 ); + set_f( st->old_bwe_exc, 0.0f, PIT16k_MAX * 2 ); + set_f( st->old_bwe_exc_extended, 0.0f, NL_BUFF_OFFSET ); + + st->bwe_non_lin_prev_scale = 0.0; + set_f( st->decim_state1, 0.0f, (2*ALLPASSSECTIONS_STEEP+1) ); + set_f( st->decim_state2, 0.0f, (2*ALLPASSSECTIONS_STEEP+1) ); + set_f( st->old_wtda_swb, 0, L_FRAME16k ); + set_f( st->old_input_wb, 0, NS2SA(16000, DELAY_FD_BWE_ENC_NS) ); + + wb_tbe_extras_reset( st->mem_genSHBexc_filt_down_wb2, st->mem_genSHBexc_filt_down_wb3 ); + if( input_frame >= L_FRAME32k ) + { + swb_tbe_reset( st->mem_csfilt, st->mem_genSHBexc_filt_down_shb, st->state_lpc_syn, + st->syn_overlap, st->state_syn_shbexc, &(st->tbe_demph),&(st->tbe_premph), st->mem_stp_swb, &(st->gain_prec_swb) ); + } + + if( input_frame == L_FRAME48k ) + { + set_f( st->fb_state_lpc_syn, 0, LPC_SHB_ORDER ); + st->fb_tbe_demph = 0; + fb_tbe_reset_enc( st->elliptic_bpf_2_48k_mem, &st->prev_fb_energy ); + } + + /* reset FD BWE buffers */ + st->prev_mode = NORMAL; + + /* reset the unvoiced/audio signal improvement memories */ + st->seed_tcx = 15687; + + st->use_acelp_preq = 0; + + } + else /* switching to AMR-WB IO mode */ + { + set_f( st->mem_MA, 0, M ); + + /* AMR-WB IO mode uses ISF(ISP), but EVS primary mode LSF(LSP) */ + mvr2r( stable_ISP, xsp_tmp, M ); + lsf2isf( st->lsf_old, st->lsf_old, xsp_tmp, M, INT_FS_12k8 ); + mvr2r( stable_ISP, xsp_tmp, M ); + lsp2isp( st->lsp_old, st->lsp_old, xsp_tmp, M ); + mvr2r( st->lsp_old, st->lsp_old1, M ); + lsp2isp( st->lsp_old1, st->lsp_old1, xsp_tmp, M ); + mvr2r( stable_ISP, xsp_tmp, M ); + lsp2isp( st->lspCNG, st->lspCNG, xsp_tmp, M ); + if( st->old_enr_index >= 0 ) + { + st->old_enr_index = min( (short)((float)st->old_enr_index / STEP_SID * STEP_AMR_WB_SID), 63 ); + } + + /* gain quantization memory */ + set_f(st->past_qua_en, -14.0f, GAIN_PRED_ORDER ); + + /* reset VBR signalling */ + st->ppp_mode = 0; + st->nelp_mode = 0; + + /* reset the unvoiced/audio signal improvement memories */ + st->seed_tcx = 15687; + } + + /* Force SID in case of AMR-WB IO mode/EVS primary mode switching */ + st->cnt_SID = 0; + + /* CNG - reset */ + st->cng_cnt = 0; + st->ho_hist_size = 0; + st->burst_ho_cnt = 0; + + /* LP memories */ + mvr2r( UVWB_Ave, st->mem_AR, M ); + + /* FEC - update adaptive LSF mean vector */ + mvr2r( st->lsf_old, st->lsfoldbfi0, M ); + mvr2r( st->lsf_old, st->lsfoldbfi1, M ); + mvr2r( st->lsf_old, st->lsf_adaptive_mean, M ); + + return; +} diff --git a/src/libs/libevs/lib_enc/updt_enc_fx.cpp b/src/libs/libevs/lib_enc/updt_enc_fx.cpp deleted file mode 100755 index 6ef5694c..00000000 --- a/src/libs/libevs/lib_enc/updt_enc_fx.cpp +++ /dev/null @@ -1,271 +0,0 @@ -/*==================================================================================== - EVS Codec 3GPP TS26.442 Apr 03, 2018. Version 12.11.0 / 13.6.0 / 14.2.0 - ====================================================================================*/ - -#include "options.h" /* Compilation switches */ -#include "cnst_fx.h" /* Common constants */ -#include "rom_com_fx.h" /* Static table prototypes */ -#include "prot_fx.h" /* Function prototypes */ -#include "stl.h" - -/*-------------------------------------------------------------------* - * updt_enc() - * - * Common updates (all frame types) - *-------------------------------------------------------------------*/ - -void updt_enc_fx( - Encoder_State_fx *st, /* i/o: state structure */ - const Word16 L_frame, /* i : length of the frame */ - const Word16 coder_type, /* i : speech coder type */ - const Word16 *old_exc, /* i : buffer of excitation */ - const Word16 *pitch_buf, /* i : floating pitch for each subframe */ - const Word16 Es_pred, /* i : predicited scaled innovation energy */ - const Word16 *Aq, /* i : A(z) quantized for all subframes */ - const Word16 *lsf_new, /* i : current frame LSF vector */ - const Word16 *lsp_new, /* i : current frame LSP vector */ - const Word16 *old_bwe_exc /* i : buffer of excitation */ -) -{ - Word16 i, tmp; - - - /* update old excitation buffer */ - Copy( &old_exc[L_frame], st->LPDmem.old_exc, L_EXC_MEM ); - IF( !st->Opt_AMR_WB_fx ) - { - Copy( &old_bwe_exc[L_FRAME32k], st->old_bwe_exc_fx, PIT16k_MAX * 2 ); - } - - /* update old LSP and LSF vector */ - Copy( lsp_new, st->lsp_old_fx, M ); - Copy( lsf_new, st->lsf_old_fx, M ); - - /* update last coder type */ - st->last_coder_type_fx = coder_type; - move16(); - test(); - test(); - test(); - if( sub(coder_type,INACTIVE) == 0|| (sub(st->bpf_off_fx,1) == 0 && sub(coder_type,AUDIO) != 0 && sub(coder_type,TRANSITION) != 0) ) - { - st->last_coder_type_fx = UNVOICED; - move16(); - } - - /* this ensures that st->last_coder_type_fx is never set to INACTIVE in case of AVQ inactive because the FEC does not distinguish between GSC inactive and AVQ inactive */ - test(); - if ( sub(coder_type,INACTIVE) == 0 && L_sub(st->total_brate_fx,ACELP_24k40) > 0) - { - st->last_coder_type_fx = GENERIC; - move16(); - } - - test(); - test(); - test(); - IF( st->Opt_AMR_WB_fx && sub(coder_type,INACTIVE) == 0 && st->core_brate_fx != SID_1k75 && st->core_brate_fx != FRAME_NO_DATA ) - { - /* overwrite previous coding type to help FEC */ - st->last_coder_type_fx = UNVOICED; - move16(); - } - - /* AC mode (GSC) - in speech we can consider that the last pitch band reached the max */ - test(); - IF ( sub(coder_type,AUDIO) != 0 && sub(coder_type,INACTIVE) != 0 ) - { - st->mem_last_pit_band_fx = 10 + BAND1k2; - move16(); - st->past_dyn_dec_fx = NOISE_LEVEL_SP0-1; - move16(); /* tends to speech */ - st->noise_lev_fx = NOISE_LEVEL_SP0-1; - move16(); /* tends to speech */ - /*st->mid_dyn_fx = 40.0f * 0.5f + st->mid_dyn * 0.5f;*/ - st->mid_dyn_fx = add(20*128, mult_r(st->mid_dyn_fx, 16384)); /*Q7*/ - } - - /* convert old LSP vector from 12kHz domain to 16kHz domain (needed in case of ACELP@12k8 <-> ACELP@16kHz switching) */ - IF( sub(L_frame,L_FRAME) == 0 ) - { - Copy( st->lsp_old_fx, st->lsp_old16k_fx, M ); - st->rate_switching_reset_16kHz=lsp_convert_poly_fx( st->lsp_old16k_fx, L_FRAME16k, st->Opt_AMR_WB_fx ); - } - - /* update buffer of old subframe pitch values */ - IF( sub(st->last_L_frame_fx,L_frame) != 0 ) - { - IF( sub(L_frame,L_FRAME) == 0 ) - { - FOR( i=0; iold_pitch_buf_fx[NB_SUBFR+i] = mult_r(26214, st->old_pitch_buf_fx[NB_SUBFR+i+1]); - move16(); - } - } - ELSE - { - FOR( i=NB_SUBFR; i>0; i-- ) - { - st->old_pitch_buf_fx[NB_SUBFR+i] = add(mult_r(8192, st->old_pitch_buf_fx[NB_SUBFR+i-1]),st->old_pitch_buf_fx[NB_SUBFR+i-1]); - move16(); - } - st->old_pitch_buf_fx[2*NB_SUBFR16k-1] = st->old_pitch_buf_fx[2*NB_SUBFR16k-2]; - move16(); - } - } - tmp = shr(L_frame,6); - Copy( &st->old_pitch_buf_fx[tmp], st->old_pitch_buf_fx, tmp); - Copy( pitch_buf, &st->old_pitch_buf_fx[tmp], tmp); - - /* SC-VBR */ - st->last_Opt_SC_VBR_fx = st->Opt_SC_VBR_fx; - move16(); - st->last_last_ppp_mode_fx = st->last_ppp_mode_fx; - move16(); - st->last_ppp_mode_fx = st->ppp_mode_fx; - move16(); - st->last_nelp_mode_fx = st->nelp_mode_fx; - move16(); - - /* core switching updates */ - Copy( &Aq[(st->L_frame_fx/L_SUBFR-1)*(M+1)], st->old_Aq_12_8_fx, M+1 ); - st->old_Es_pred_fx = Es_pred; - - return; -} - -/*-------------------------------------------------------------------* - * updt_IO_switch() - * - * Common updates for AMR-WB IO mode and EVS primary mode switching - *-------------------------------------------------------------------*/ - -void updt_IO_switch_enc_fx( - Encoder_State_fx *st, /* i/o: state structure */ - const Word16 input_frame /* i : input frame length */ -) -{ - Word16 xsp_tmp[M]; - - IF( sub(st->last_core_fx,AMR_WB_CORE) == 0 ) /* switching to EVS primary mode */ - { - /* reset onset detection counter */ - st->tc_cnt_fx = -1; - - /* force safety-net LSFQ in the first frames after the switching */ - st->Nb_ACELP_frames_fx = 0; - move16(); - - /* AMR-WB IO mode uses ISF(ISP), but EVS primary mode LSF(LSP) */ - Copy( stable_LSP_fx, xsp_tmp, M ); - isf2lsf_fx( st->lsf_old_fx, st->lsf_old_fx, xsp_tmp); - Copy( stable_LSP_fx, xsp_tmp, M ); - isp2lsp_fx( st->lsp_old_fx, st->lsp_old_fx, xsp_tmp, M); - isp2lsp_fx( st->lsp_old1_fx, st->lsp_old1_fx, xsp_tmp, M); - - Copy( stable_LSP_fx, xsp_tmp, M ); - isp2lsp_fx( st->lspCNG_fx, st->lspCNG_fx, xsp_tmp, M); - /*st->old_enr_index = min( (short)((float)st->old_enr_index / STEP_AMR_WB_SID * STEP_SID), 127 );*/ - IF( st->old_enr_index_fx >=0 ) - { - /* old index is initialized to -1, and may only be updated after it has been calculated properly at least once once */ - st->old_enr_index_fx = s_min(mult(shl(st->old_enr_index_fx,1), 32459), 127 ); /*32459 = 2/(STEP_SID/STEP_AMR_WB_SID)*/ - } - /* Perform preemphasis of the old input signal @16kHz */ - st->mem_preemph16k_fx = 0; - move16(); - preemph_fx( st->old_inp_16k_fx, PREEMPH_FAC_16k, L_INP_MEM, &(st->mem_preemph16k_fx) ); - Scale_sig(st->old_inp_16k_fx, L_INP_MEM, st->prev_Q_new); - /* reset TD BWE buffers */ - set16_fx( st->old_speech_shb_fx, 0, L_LOOK_16k + L_SUBFR16k ); - set16_fx( st->old_speech_wb_fx, 0, (L_LOOK_12k8 + L_SUBFR) * 5/16 ); - set16_fx( st->old_bwe_exc_fx, 0, PIT16k_MAX * 2 ); - set16_fx( st->old_bwe_exc_extended_fx, 0, NL_BUFF_OFFSET ); - - st->bwe_non_lin_prev_scale_fx = 0; - move16(); - set16_fx( st->decim_state1_fx, 0, (2*ALLPASSSECTIONS_STEEP+1) ); - set16_fx( st->decim_state2_fx, 0, (2*ALLPASSSECTIONS_STEEP+1) ); - set16_fx( st->L_old_wtda_swb_fx, 0, L_FRAME16k ); - set16_fx( st->old_input_wb_fx, 0, NS2SA(16000, DELAY_FD_BWE_ENC_NS) ); - - wb_tbe_extras_reset_fx( st->mem_genSHBexc_filt_down_wb2_fx, st->mem_genSHBexc_filt_down_wb3_fx ); - - IF( sub(input_frame,L_FRAME32k) >= 0 ) - { - swb_tbe_reset_fx( st->mem_csfilt_fx, st->mem_genSHBexc_filt_down_shb_fx, st->state_lpc_syn_fx, - st->syn_overlap_fx, st->state_syn_shbexc_fx, &(st->tbe_demph_fx),&(st->tbe_premph_fx), st->mem_stp_swb_fx, &(st->gain_prec_swb_fx) ); - - } - - IF( sub(input_frame,L_FRAME48k) == 0 ) - { - set16_fx(st->fb_state_lpc_syn_fx, 0, LPC_SHB_ORDER); - st->fb_tbe_demph_fx = 0; - move16(); - fb_tbe_reset_enc_fx( st->elliptic_bpf_2_48k_mem_fx, &st->prev_fb_energy_fx,st->elliptic_bpf_2_48k_mem_fx_Q,&st->prev_fb_energy_fx_Q); - } - - /* reset FD BWE buffers */ - st->prev_mode_fx = NORMAL; - move16(); - - /* reset the unvoiced/audio signal improvement memories */ - st->seed_tcx_fx = 15687; - move16(); - - st->use_acelp_preq = 0; - move16(); - - } - ELSE /* switching to AMR-WB IO mode */ - { - set16_fx(st->mem_MA_fx, 0, M ); - - /* AMR-WB IO mode uses ISF(ISP), but EVS primary mode LSF(LSP) */ - Copy( stable_ISP_fx, xsp_tmp, M ); - lsf2isf_fx( st->lsf_old_fx, st->lsf_old_fx, xsp_tmp, M); - Copy( stable_ISP_fx, xsp_tmp, M ); - lsp2isp_fx( st->lsp_old_fx, st->lsp_old_fx, xsp_tmp, M); - lsp2isp_fx( st->lsp_old1_fx, st->lsp_old1_fx, xsp_tmp, M); - Copy( stable_ISP_fx, xsp_tmp, M ); - lsp2isp_fx( st->lspCNG_fx, st->lspCNG_fx, xsp_tmp, M); - - IF( st->old_enr_index_fx >= 0 ) - { - /* old_enr__index is initialized to -1, and may only be updated this way after it has been calculated properly at least once once */ - /*st->old_enr_index = min( (short)((float)st->old_enr_index / STEP_SID * STEP_AMR_WB_SID), 63 );*/ - st->old_enr_index_fx = s_max(s_min(mult(st->old_enr_index_fx, 16384), 63 ),0); /*32459 = 2/(STEP_SID/STEP_AMR_WB_SID)*/ - } - /* gain quantization memory */ - set16_fx(st->past_qua_en_fx, (-14*1024), GAIN_PRED_ORDER ); - /* reset VBR signalling */ - st->ppp_mode_fx = 0; - move16(); - st->nelp_mode_fx = 0; - move16(); - } - - /* Force SID in case of AMR-WB IO/EVS primary mode switching */ - st->cnt_SID_fx = 0; - move16(); - - /* CNG - reset */ - st->cng_cnt_fx = 0; - move16(); - st->ho_hist_size_fx = 0; - move16(); - st->burst_ho_cnt_fx = 0; - move16(); - - /* LP memories */ - Copy( UVWB_Ave_fx, st->mem_AR_fx, M ); - - /* FEC - update adaptive LSF mean vector */ - Copy( st->lsf_old_fx, st->lsfoldbfi0_fx, M ); - Copy( st->lsf_old_fx, st->lsfoldbfi1_fx, M ); - Copy( st->lsf_old_fx, st->lsf_adaptive_mean_fx, M ); - - return; -} diff --git a/src/libs/libevs/lib_enc/updt_tar.cpp b/src/libs/libevs/lib_enc/updt_tar.cpp new file mode 100644 index 00000000..eb75844f --- /dev/null +++ b/src/libs/libevs/lib_enc/updt_tar.cpp @@ -0,0 +1,28 @@ +/*==================================================================================== + EVS Codec 3GPP TS26.443 Nov 13, 2018. Version 12.11.0 / 13.7.0 / 14.3.0 / 15.1.0 + ====================================================================================*/ + +#include "options.h" +#include "prot.h" + +/*----------------------------------------------------------------------------------* + * procedure updt_tar: + * + * Update the target vector for codebook search. + *----------------------------------------------------------------------------------*/ +void updt_tar( + const float *x, /* i : old target (for pitch search) */ + float *x2, /* o : new target (for codebook search) */ + const float *y, /* i : filtered adaptive codebook vector */ + const float gain, /* i : adaptive codebook gain */ + const short L /* i : subframe size */ +) +{ + short i; + + + for (i = 0; i < L; i++) + { + x2[i] = x[i] - gain*y[i]; + } +} diff --git a/src/libs/libevs/lib_enc/updt_tar_fx.cpp b/src/libs/libevs/lib_enc/updt_tar_fx.cpp deleted file mode 100755 index 88ff0e56..00000000 --- a/src/libs/libevs/lib_enc/updt_tar_fx.cpp +++ /dev/null @@ -1,60 +0,0 @@ -/*==================================================================================== - EVS Codec 3GPP TS26.442 Apr 03, 2018. Version 12.11.0 / 13.6.0 / 14.2.0 - ====================================================================================*/ - -#include "options.h" /* Compilation switches */ -#include "prot_fx.h" /* Function prototypes */ -#include "stl.h" - -/*----------------------------------------------------------------------------------* - * procedure updt_tar: - * - * Update the target vector for codebook search. - *----------------------------------------------------------------------------------*/ -void updt_tar_fx( - const Word16 *x, /* i : old target (for pitch search) */ - Word16 *x2, /* o : new target (for codebook search) */ - const Word16 *y, /* i : filtered adaptive codebook vector */ - const Word16 gain, /* i : adaptive codebook gain */ - const Word16 L /* i : subframe size */ -) -{ - Word16 i; - Word32 L_tmp; - - - FOR (i = 0; i < L; i++) - { - /*x2[i] = x[i] - gain*y[i];*/ - L_tmp = L_mult(x[i], 16384); - L_tmp = L_msu(L_tmp, y[i], gain); - x2[i] = extract_h(L_shl(L_tmp, 1)); - } -} -/*----------------------------------------------------------------------------------* - * procedure updt_tar: - * - * Update the target vector for codebook search. - *----------------------------------------------------------------------------------*/ -void updt_tar_HR_fx( - const Word16 *x, /* i : old target (for pitch search) */ - Word16 *x2, /* o : new target (for codebook search) */ - const Word16 *y, /* i : filtered adaptive codebook vector */ - const Word16 gain, /* i : adaptive codebook gain Q2 */ - const Word16 Qx, /* i : Scaling factor to adapt output to input */ - const Word16 L /* i : subframe size */ -) -{ - Word16 i; - Word32 L_tmp, L_tmp1; - - - FOR (i = 0; i < L; i++) - { - /*x2[i] = x[i] - gain*y[i];*/ - L_tmp = L_mult(x[i], 32767); - L_tmp1 = L_shl(L_mult(y[i], gain), Qx); - L_tmp = L_sub(L_tmp, L_tmp1); - x2[i] = extract_h(L_tmp); - } -} diff --git a/src/libs/libevs/lib_enc/vad.cpp b/src/libs/libevs/lib_enc/vad.cpp new file mode 100644 index 00000000..fdd26ba5 --- /dev/null +++ b/src/libs/libevs/lib_enc/vad.cpp @@ -0,0 +1,1009 @@ +/*==================================================================================== + EVS Codec 3GPP TS26.443 Nov 13, 2018. Version 12.11.0 / 13.7.0 / 14.3.0 / 15.1.0 + ====================================================================================*/ + +#include +#include "options.h" +#include "cnst.h" +#include "prot.h" +#include "rom_enc.h" + + +/*-----------------------------------------------------------------* + * Local constants + *-----------------------------------------------------------------*/ + +#define HANGOVER_LONG 10 /* Hangover for CNG */ +#define HANGOVER_LONG_HE 20 /* Hangover of CNG */ +#define HANGOVER_LONG_MUSIC 20 /* Hangover of CNG */ +#define HANGOVER_LONG_NB 8 /* Hangover for CNG */ +#define ACTIVE_FRAMES 3 /* Number of consecutive active SPEECH frames necessary to trigger HO */ + +#define TH16_2 35.0f /* long-term SNR that separates the curves for clean speech and noisy speech */ +#define TH8_1 20.0f /* long-term SNR that separates the curves for clean speech and noisy speech */ +#define TH16_2_NFLAG 35.0f +#define TH8_1_NFLAG 35.0f + + +#define SNR_OUTLIER_WGHT_1 1.00f +#define SNR_OUTLIER_WGHT_2 1.01f +#define SNR_OUTLIER_WGHT_3 1.02f +#define OUTLIER_THR_1 10.0f +#define OUTLIER_THR_2 6.0f +#define MAX_SNR_OUTLIER_IND 17 +#define MAX_SNR_OUTLIER_1 10.0f +#define MAX_SNR_OUTLIER_2 25.0f +#define MAX_SNR_OUTLIER_3 50.0f + +/*---------------------------------------------------------------------* + * wb_vad_init() + * + * VAD initializations + *---------------------------------------------------------------------*/ + +void wb_vad_init( + short *nb_active_frames, /* o : nb of consecutive active speech frames */ + short *hangover_cnt, + float *lp_speech, /* o : long-term active speech level */ + short *nb_active_frames_he, /* o : nb of consecutive active speech frames */ + short *hangover_cnt_he, + float *bcg_flux, /* o : background noise fluctuation */ + short *soft_hangover, /* o : soft hangover counter */ + short *voiced_burst, /* o : consecutive voiced speech counter */ + short *bcg_flux_init, /* o : initialization period for noise fluctuation estimation */ + short *nb_active_frames_he1, /* o : nb of consecutive active speech frames 1 */ + short *hangover_cnt_he1, + long *vad_flag_reg_H, + long *vad_flag_reg_L, + long *vad_prim_reg, + short *vad_flag_cnt_50, + short *vad_prim_cnt_16, + short *hangover_cnt_dtx, + short *flag_noisy_speech_snr + ,short *hangover_cnt_music /* o : counter of VAD DTX Music hangover frames */ +) +{ + *hangover_cnt = 0; /* Hangover counter initialized to 0 */ + *nb_active_frames = ACTIVE_FRAMES; /* The counter of SPEECH frames necessary to trigger HO */ + /* is set to max (-> start with hangover) */ + *lp_speech = 45.0f; /* Initialize the long-term active speech level in dB */ + *flag_noisy_speech_snr=0; + + *vad_flag_reg_H = 0L; + *vad_flag_reg_L = 0L; + *vad_prim_reg = 0L; + *vad_flag_cnt_50 = 0; + *vad_prim_cnt_16 = 0; + + /* By default one should not start with a hangover */ + *hangover_cnt_dtx = HANGOVER_LONG; /* hangover for DTX */ + *hangover_cnt_music = HANGOVER_LONG_MUSIC; /* hangover for DTX */ + + *hangover_cnt_he = 0; /* Hangover counter initialized to 0 */ + *nb_active_frames_he = ACTIVE_FRAMES; /* The counter of SPEECH frames necessary to trigger HO */ + *bcg_flux = 70; + *soft_hangover = 0; + *voiced_burst = 0; + *bcg_flux_init = 50; + *nb_active_frames_he1 = ACTIVE_FRAMES; + *hangover_cnt_he1 = 0; + + return; +} + +/*-----------------------------------------------------------------* + * sing_thr_snr_acc() + * + * accumulate snr_sum with significance thresholds + *-----------------------------------------------------------------*/ + +static void sign_thr_snr_acc( + float *snr_sum, + float snr, + float sign_thr, + float min_snr +) +{ + if( snr >= sign_thr ) + { + *snr_sum = *snr_sum + snr; + } + else + { + *snr_sum = *snr_sum + min_snr; + } + + return; +} + +/*-----------------------------------------------------------------* + * dtx_hangover_addition() + * + * accumulate snr_sum with significance thresholds + *-----------------------------------------------------------------*/ + +short dtx_hangover_addition( + Encoder_State *st, /* i/o: encoder state structure */ + const short localVAD, + const short vad_flag, + const float lp_snr, + const short cldfb_subtraction, + short *vad_hover_flag +) +{ + short hangover_short_dtx, flag_dtx; + short ho_limit_clean; + + flag_dtx = 0; + + /* Determine initial hangover length */ + hangover_short_dtx = 2; /* was 1 */ + if ( ( lp_snr < 16.0f && st->input_bwidth != NB ) || + st->prim_act_he > 0.95f ) + { + hangover_short_dtx = 3; /* was 2 */ + } + + /* Adjust hangover according to activity history */ + if (st->vad_prim_cnt_16 > 12 ) /* 12 requires roughly > 80% primary activity */ + { + hangover_short_dtx = hangover_short_dtx + 2; + } + + if (st->vad_flag_cnt_50 >40 ) /* 40 requires roughtly > 80% flag activity */ + { + hangover_short_dtx = hangover_short_dtx + 5; + } + + /* Keep hangover_short lower than maximum hangover count */ + if (hangover_short_dtx > HANGOVER_LONG-1) + { + hangover_short_dtx = HANGOVER_LONG-1; + } + + /* Only allow short HO if not sufficient active frames */ + ho_limit_clean = 3; + if (st->core == AMR_WB_CORE ) + { + ho_limit_clean = 2; + } + + if ( st->input_bwidth != NB && st->core != AMR_WB_CORE && lp_snr > 25.0f ) + { + ho_limit_clean = 2; + } + + if ( ho_limit_clean != 0 ) + { + if ( (hangover_short_dtx > ho_limit_clean) && ( ( st->vad_prim_cnt_16 < 7 ) || ( lp_snr > 16 && st->prim_act_he < 0.85 ) ) ) + { + hangover_short_dtx = ho_limit_clean; + } + } + + + /* hangover adjustment from combined FFT + CLDFBVAD */ + if (st->core != AMR_WB_CORE) + { + hangover_short_dtx = hangover_short_dtx - cldfb_subtraction; + if( hangover_short_dtx < 0 ) + { + hangover_short_dtx = 0; + } + } + if ( vad_flag == 1 ) /* Speech present */ + { + flag_dtx = 1; + + /* Add hangover after sufficient # of active frames or sufficient activity during last second */ + if (st->nb_active_frames >= ACTIVE_FRAMES || st->vad_flag_cnt_50 >45 ) /* 45 requires roughtly > 90% flag activity */ + { + st->hangover_cnt_dtx = 0; + } + + /* inside HO period */ + if( st->hangover_cnt_dtx < HANGOVER_LONG && st->hangover_cnt_dtx != 0 ) + { + st->hangover_cnt_dtx++; + } + + st->hangover_terminate_flag = 0; + + /* Music hangover when music detected */ + if( st->prim_act_he > 0.98f && st->Etot_lp > 40 && st->vad_prim_cnt_16 > 14 && st->vad_flag_cnt_50 > 48 ) + { + st->hangover_cnt_music = 0; + } + + /* inside music HO period */ + if (st->hangover_cnt_music < HANGOVER_LONG_MUSIC && st->hangover_cnt_music != 0 ) + { + st->hangover_cnt_music++; + } + } + else + { + /* Reset the counter of speech frames necessary to start hangover algorithm */ + if(st->hangover_cnt_dtx < HANGOVER_LONG ) /* inside HO period */ + { + st->hangover_cnt_dtx++; + } + if(st->hangover_cnt_music < HANGOVER_LONG_MUSIC ) /* inside music HO period */ + { + st->hangover_cnt_music++; + } + /* fast terminate DTX hangover if st->hangover_terminate_flag is set */ + if ( st->hangover_terminate_flag == 1 ) + { + st->hangover_cnt = HANGOVER_LONG; + st->hangover_cnt_dtx = HANGOVER_LONG; + st->hangover_terminate_flag = 0; + /* only shorten music hangover when low energy frames */ + if ( st->Etot_lp < 20.0f ) + { + st->hangover_cnt_music = HANGOVER_LONG_MUSIC; + } + } + + if( st->hangover_cnt_dtx <= hangover_short_dtx ) /* "hard" hangover */ + { + flag_dtx = 1; + } + + if( st->hangover_cnt_music <= 15 ) /* "hard" hangover */ + { + flag_dtx = 1; + } + + } + + + if ( flag_dtx != 0 && localVAD == 0 ) + { + *vad_hover_flag = 1; + } + + return flag_dtx ; +} + + +/*-----------------------------------------------------------------* + * wb_vad() + * + * Voice Activity Detector + *-----------------------------------------------------------------*/ + +short wb_vad( + Encoder_State *st, /* i/o: encoder state structure */ + const float fr_bands[], /* i : per band input energy (contains 2 vectors) */ + short *localVAD, + short *noisy_speech_HO, /* o : SC-VBR noisy speech HO flag */ + short *clean_speech_HO, /* o : SC-VBR clean speech HO flag */ + short *NB_speech_HO, /* o : SC-VBR NB speech HO flag */ + float *snr_sum_he, /* o : Output snr_sum as weighted spectral measure */ + short *localVAD_HE_SAD, /* o : HE_SAD decision without hangovers */ + short *flag_noisy_speech_snr /* o: */ +) +{ + short i, j, flag, hangover_short; + float snr[NB_BANDS], snr_sum, thr1, thr2, lp_snr, nk, nc, th_clean; + const float *pt1, *pt2, *pt3; + float min_snr, sign_thr; + float fr_enr; + float ftmp, ftmp1; + float mssnr = 0; + float snr_sumt; + float vad_thr; + short hangover_hd; + short snr_idx; + float delta1, delta2, delta3; + short flag_he1; + float mssnr_hov; + short stmp; + float msnr; + float snr_outlier; + short snr_outlier_index; + float accum_ener_L, accum_ener_H; + float delta4; + float snr18=1.0f, snr19=1.0f; + short nb_sig_snr; + float nv; + float snr_sum_HE_SAD; + float sign_thr_HE_SAD,min_snr_HE_SAD; + float nv_ofs; + float thr1_ol; + float snr_sum_ol; + snr_outlier = 0; + snr_outlier_index = 0; + accum_ener_L = 0; + accum_ener_H = 0; + + if( st->input_bwidth == NB ) + { + st->min_band = 1; + st->max_band = 16; + } + else + { + st->min_band = 0; + st->max_band = 19; + } + + /*---------------------------------------------------------------------* + * set SNR thresholds depending on the input rate + *---------------------------------------------------------------------*/ + + if(st->max_band == 19 ) /* WB input */ + { + nk = 0.1f; + nc = 16.1f; + nv = 2.05f; + nv_ofs = 1.65f; + th_clean = TH16_2; + if ( st->input_bwidth == WB ) + { + sign_thr = 1.3f; + min_snr = 0.8f; + } + else + { + sign_thr = 1.75f; + min_snr = 0.25f; + } + sign_thr_HE_SAD = 2.5f; + min_snr_HE_SAD = 0.2f; + } + else /* NB input */ + { + nk = 0.10f; + nc = 16.0f; + nv = 4.00f; /* Was 4.5f but trunkated to 4.00 used when converted to short */ + nv_ofs = 1.15f; + th_clean = TH8_1; + sign_thr = 1.75f; + min_snr = 0.25f; + + sign_thr_HE_SAD = 2.65f; + min_snr_HE_SAD = 0.05f; + } + + hangover_short = 0; + + + if( st->Opt_SC_VBR ) + { + *noisy_speech_HO = 0; + *clean_speech_HO = 0; + *NB_speech_HO = 0; + } + + /*---------------------------------------------------------------------* + * compute SNR for each band & total + *---------------------------------------------------------------------*/ + + pt1 = fr_bands; + pt2 = fr_bands + NB_BANDS; + snr_sum = 0.0f; + *snr_sum_he = 0.0f; + snr_sumt = 0; + mssnr_hov = 0; + snr_sum_HE_SAD = 0.0f; + lp_snr = st->lp_speech - st->lp_noise; + + if ( lp_snr > 24.0f ) + { + snr_idx = 0; + } + else if ( lp_snr > 18 ) + { + snr_idx = 1; + } + else + { + snr_idx = 2; + } + + if ( snr_idx == 0 ) + { + stmp = 6; + delta1 = 0.0f; + delta2 = 0.0f; + delta3 = 0.0f; + delta4 = 0.0f; + vad_thr = 2.4f*lp_snr - 42.2f; + vad_thr = min(vad_thr, 80); + } + else if ( snr_idx == 1) + { + stmp = 6; + delta1 = 0.1f; + delta2 = 0.2f; + delta3 = 0.2f; + delta4 = 0.2f; + vad_thr = 2.4f*lp_snr - 40.2f; + vad_thr = min(vad_thr, 80); + } + else + { + stmp = 9; + delta1 = 0.2f; + delta2 = 0.4f; + delta3 = 0.3f; + delta4 = 0.4f; + vad_thr = 2.5f*lp_snr - 10.0f; + vad_thr = max(vad_thr, 1); + } + pt3 = st->bckr; + nb_sig_snr = 20; + + for( i=st->min_band; i<=st->max_band; i++ ) + { + ftmp = *pt1++; + ftmp1 = *pt2++; + fr_enr = ( 0.2f * st->enrO[i] + 0.4f * ftmp + 0.4f * ftmp1 ); + + if (ftmp > ftmp1) + { + snr[i] = ( 0.2f * st->enrO[i] + 0.4f * ftmp + 0.4f * ftmp1 ) / *pt3++; + } + else + { + snr[i] = ( 0.2f * st->enrO[i] + 0.3f * ftmp + 0.5f * ftmp1 ) / *pt3++; + } + + if ( snr[i] < 2.0f ) + { + nb_sig_snr--; + } + + if ( snr[i] < 1 ) + { + snr[i] = 1; + } + + snr[i] = (float)log10(snr[i]); + snr_sumt += snr[i]; + if (i < 2) + { + ftmp = snr[i] + delta1; + } + else if (i < 7) + { + ftmp = snr[i] + delta2; + } + else if (i <18) + { + ftmp = snr[i] + delta3; + } + else + { + ftmp = snr[i] + delta4; + } + ftmp1 = ftmp; + if ( i < 7 ) + { + ftmp1 = ftmp + 0.4f; + } + ftmp = min(ftmp, 2.0f); + ftmp1 = min(ftmp1, 2.0f); + msnr = 1; + for (j=0; jbckr[i]; + + sign_thr_snr_acc( &snr_sum_HE_SAD, snr[i], sign_thr_HE_SAD, min_snr_HE_SAD ); + sign_thr_snr_acc( &snr_sum,snr[i], sign_thr, min_snr ); + + /* To make snr[] compatible with older versions where snr[i] >= 1 + also this could be removed if this no longer is a requriement */ + if( snr[i] < 1.0f ) + { + snr[i] = 1.0f; + } + /* accumulate background noise energy in bands [0-2] and in bands [3-19]*/ + if( i < 3 ) + { + accum_ener_L = accum_ener_L + st->bckr[i]; + } + else + { + accum_ener_H = accum_ener_H + st->bckr[i]; + } + + /* identify the outlier band */ + if( snr[i] > snr_outlier ) + { + snr_outlier = snr[i]; + snr_outlier_index = i; + } + } + + if ( (st->max_band == 19) && (snr[18] > 5.0f) && (snr[19] > 5.0f) ) + { + ftmp = (mssnr + 3*(snr18 + snr19)) * 0.77f; + if ( ftmp > mssnr ) + { + mssnr = ftmp; + } + } + else if ( snr_idx != 0 && nb_sig_snr > 13 ) + { + if ( 2.5f*lp_snr - 15.5f > 0 ) + { + mssnr += 2.5f*lp_snr - 15.5f; + } + } + + + /* Separate SNR_SUM modification to */ + snr_sum_ol = snr_sum; + if(st->max_band == 19 && snr_outlier < MAX_SNR_OUTLIER_3 && snr_outlier_index > 3 && snr_outlier_index < MAX_SNR_OUTLIER_IND) /* Update the total SNR only for WB signals */ + { + if( (accum_ener_L > OUTLIER_THR_1 * accum_ener_H ) || (snr_outlier < MAX_SNR_OUTLIER_1) ) + { + snr_sum_ol = SNR_OUTLIER_WGHT_1 * (snr_sum_ol - snr_outlier); + } + else if( (accum_ener_L > OUTLIER_THR_2 * accum_ener_H ) || (snr_outlier < MAX_SNR_OUTLIER_2) ) + { + snr_sum_ol = SNR_OUTLIER_WGHT_2 * (snr_sum_ol - snr_outlier); + } + else + { + snr_sum_ol = SNR_OUTLIER_WGHT_3 * (snr_sum_ol - snr_outlier); + } + } + + st->snr_sum_vad = 0.5f * st->snr_sum_vad + 0.5f * snr_sum_ol; + + snr_sum_ol = 10.0f * (float)log10( snr_sum_ol ); + snr_sum = snr_sum_ol; /* for NB no outlier modification */ + + snr_sum_HE_SAD = 10.0f * (float)log10( snr_sum_HE_SAD ); + *snr_sum_he=snr_sum_HE_SAD; + + /*---------------------------------------------------------------------* + * compute thr1 for SAD decision + *---------------------------------------------------------------------*/ + + lp_snr = st->lp_speech - st->lp_noise; /* long-term SNR */ + + if (lp_snr < st->sign_dyn_lp) + { + lp_snr +=1; + + if (lp_snr > st->sign_dyn_lp) + { + lp_snr = st->sign_dyn_lp; + } + } + + thr1 = nk * lp_snr + nc + nv * ( st->Etot_v_h2 - nv_ofs); /* Linear function for noisy speech */ + + if (lp_snr > 20.0f ) + { + thr1 = thr1 + 0.3f * (lp_snr - 20.0f); + if ( st->max_band==16 && lp_snr > 40 && thr1 > 24.1f && st->lp_speech < 45.0f ) + { + thr1 = 24.1f; + } + } + + /*---------------------------------------------------------------------* + * WB input + * SNR threshold computing + * Hangover control & final VAD decision + *---------------------------------------------------------------------*/ + + if( st->input_bwidth != NB ) + { + /* Outlier Detection first calculates thr1_ol and snr_sum_ol instead of + thr1 and snr_sum */ + + thr1_ol = thr1; + if( lp_snr < th_clean ) + { + hangover_short = 4; + if( ( snr_outlier_index <= 4 && (st->last_coder_type > UNVOICED) && !st->Opt_SC_VBR ) || + ( snr_outlier_index <= 4 && (st->last_7k2_coder_type > UNVOICED) && st->Opt_SC_VBR ) ) + { + thr1_ol = thr1 - 1.0f ; + snr_sum_ol = 10.0f * (float)log10( st->snr_sum_vad ); + } + else if ( ( (st->last_coder_type <= UNVOICED) && (snr_outlier < MAX_SNR_OUTLIER_2) && !st->Opt_SC_VBR ) || + ( (st->last_7k2_coder_type <= UNVOICED) && (snr_outlier < MAX_SNR_OUTLIER_2) && st->Opt_SC_VBR ) ) + + { + thr1_ol = thr1 + (float)(1.0f - 0.04f * snr_outlier); + } + else + { + thr1_ol = thr1 + max(0, (float)(0.6f - 0.01f * snr_outlier)); + } + } + else + { + if( st->Opt_SC_VBR ) + { + hangover_short = 3; + } + else + { + hangover_short = 3; + } + } + + /* The use of outlier detection had been removed by accident at some point */ + snr_sum = snr_sum_ol; + thr1 = thr1_ol; + + /* DTX HANGOVER ADDITION MOVED TO pre_proc() */ + + flag_he1 = 0; + *localVAD = 0; + if ( mssnr > vad_thr ) + { + *localVAD = 1; /* he1 primary decision */ + flag_he1 = 1; + st->nb_active_frames_he1++; /* Counter of consecutive active speech frames */ + if ( st->nb_active_frames_he1 >= ACTIVE_FRAMES ) + { + st->nb_active_frames_he1 = ACTIVE_FRAMES; + st->hangover_cnt_he1 = 0; /* Reset the counter of hangover frames after at least "active_frames" speech frames */ + } + /* inside HO period */ + if ( st->hangover_cnt_he1 < HANGOVER_LONG_HE && st->hangover_cnt_he1 != 0 ) + { + st->hangover_cnt_he1++; + } + + if ( st->soft_hangover > 0 ) + { + st->soft_hangover--; + } + } + else + { + /* Reset the counter of speech frames necessary to start hangover algorithm */ + st->nb_active_frames_he1 = 0; + } + + + if ( st->voiced_burst > 3 ) + { + if ( st->bcg_flux < 40 ) + { + st->soft_hangover = hangover_sf_tbl[snr_idx+3]; + } + else + { + st->soft_hangover = hangover_sf_tbl[snr_idx]; + } + } + + + hangover_hd = hangover_hd_tbl[snr_idx]; + + if ( st->bcg_flux < 40 ) + { + hangover_hd = (hangover_hd>>1) + 1; + } + + + if ( flag_he1 == 0 && st->soft_hangover > 0 ) + { + if ( mssnr_hov > vad_thr ) + { + flag_he1 = 1; + st->soft_hangover--; + } + else + { + st->soft_hangover = 0; + } + + if ( st->soft_hangover < 0 ) + { + st->soft_hangover = 0; + } + } + + if ( flag_he1 == 0 && st->hangover_cnt_he1 < hangover_hd && st->soft_hangover == 0 ) + { + flag_he1 = 1; + st->hangover_cnt_he1++; + } + + /* Calculate background stationarity */ + if ( flag_he1 == 0 && st->first_noise_updt > 0 ) + { + if ( snr_sumt > st->bcg_flux ) + { + if ( st->bcg_flux_init-- > 0 ) + { + if ( snr_sumt > st->bcg_flux+50 ) + { + st->bcg_flux = 0.9f * st->bcg_flux + (1-0.9f)*(st->bcg_flux+50); + } + else + { + st->bcg_flux = 0.9f * st->bcg_flux + (1-0.9f)*snr_sumt; + } + } + else + { + if ( snr_sumt > st->bcg_flux+10 ) + { + st->bcg_flux = 0.99f * st->bcg_flux + (1-0.99f)*(st->bcg_flux+10); + } + else + { + st->bcg_flux = 0.99f * st->bcg_flux + (1-0.99f)*snr_sumt; + } + } + } + else + { + if ( st->bcg_flux_init-- > 0 ) + { + if ( snr_sumt < st->bcg_flux-30 ) + { + st->bcg_flux = 0.95f * st->bcg_flux + (1-0.95f)*(st->bcg_flux-30); + } + else + { + st->bcg_flux = 0.95f * st->bcg_flux + (1-0.95f)*snr_sumt; + } + } + else + { + if ( snr_sumt < st->bcg_flux-10 ) + { + st->bcg_flux = 0.9992f * st->bcg_flux + (1-0.9992f)*(st->bcg_flux-10); + } + else + { + st->bcg_flux = 0.9992f * st->bcg_flux + (1-0.9992f)*snr_sumt; + } + } + } + + if ( st->bcg_flux_init < 0 ) + { + st->bcg_flux_init = 0; + } + } + + flag = 0; + *localVAD = 0; + + if ( snr_sum > thr1 && flag_he1 == 1 ) /* Speech present */ + { + flag = 1; + *localVAD = 1; + st->nb_active_frames++; /* Counter of consecutive active speech frames */ + if (st->nb_active_frames >= ACTIVE_FRAMES ) + { + st->nb_active_frames = ACTIVE_FRAMES; + st->hangover_cnt = 0; /* Reset the counter of hangover frames after at least "active_frames" speech frames */ + } + + /* inside HO period */ + if(st->hangover_cnt < HANGOVER_LONG && st->hangover_cnt != 0 ) + { + st->hangover_cnt++; + } + } + else + { + /* Reset the counter of speech frames necessary to start hangover algorithm */ + st->nb_active_frames = 0; + if(st->hangover_cnt < HANGOVER_LONG ) /* inside HO period */ + { + st->hangover_cnt++; + } + + if(st->hangover_cnt <= hangover_short ) /* "hard" hangover */ + { + /* send the extra 3 HO frames to NELP */ + if ( (lp_snr < th_clean) && (st->Opt_SC_VBR) && (st->hangover_cnt >= 2) ) + { + *noisy_speech_HO = 1; + } + + if ( (lp_snr >= th_clean) && (st->Opt_SC_VBR) && (st->hangover_cnt >= 2) ) + { + *clean_speech_HO = 1; + } + + flag = 1; + } + + } + + /* localVAD and vad_flag for HE-SAD - in parallel with normal localVAD and vad_flag */ + *localVAD_HE_SAD = 0; + if( snr_sum_HE_SAD > thr1 && (flag_he1 == 1) ) /* Speech present */ + { + *localVAD_HE_SAD = 1; + } + } + + /*---------------------------------------------------------------------* + * NB input + * SNR threshold computing + * Hangover control & final VAD decision + *---------------------------------------------------------------------*/ + + else /* NB input */ + { + /* Add localVAD_HE_SAD also for NB operation for use with speech music classifier */ + *localVAD_HE_SAD = 0; + if (snr_sum_HE_SAD > thr1 ) + { + *localVAD_HE_SAD = 1; + } + + *localVAD = 0; /* init needed in NB, otherwise it can be undefined */ + if ( snr_sum > thr1 ) /* Speech present */ + { + st->nb_active_frames++; /* Counter of consecutive active speech frames */ + if (st->nb_active_frames >= ACTIVE_FRAMES ) + { + st->nb_active_frames = ACTIVE_FRAMES; + st->hangover_cnt = 0; /* Reset the counter of hangover frames after at least "active_frames" speech frames */ + } + + *localVAD = 1; + } + else + { + st->nb_active_frames = 0; /* Reset the counter of speech frames necessary to start hangover algorithm */ + } + + if(st->hangover_cnt < HANGOVER_LONG_NB ) + { + st->hangover_cnt++; + if( lp_snr < 19.0f ) /* very low SNR */ + { + thr1 -= 5.2f; + } + else if( lp_snr < 35.0f ) /* low SNR */ + { + thr1 -= 2.0f; + } + } + + if (st->Opt_DTX_ON) + { + if (lp_snr < th_clean) + { + thr2 = thr1 - 1.10f; + + } + else + { + thr2 = thr1 - 1.5f; + } + } + else + { + if (lp_snr < th_clean) + { + thr2 = thr1 - 1.3f; + } + else + { + thr2 = thr1 - 1.5f; + } + } + + flag = 0; + if ( snr_sum > thr1 ) /* Speech present */ + { + flag = 1; + } + + if ( (snr_sum < thr1) && (snr_sum > thr2) ) /* Speech present */ + { + flag = 1; + *localVAD = 0; + *NB_speech_HO = 1; + } + + /* Need to handle the case when switching from WB -> NB */ + } + + + + if( st->input_bwidth != NB ) + { + *flag_noisy_speech_snr = (lp_snr < TH16_2_NFLAG ); /*original threshold: 35dB*/ + } + else + { + *flag_noisy_speech_snr = (lp_snr < TH8_1_NFLAG ); /*original threshold: 20dB, not yet tested!*/ + } + + /* SC-VBR */ + st->vadsnr = snr_sum; + st->vadnoise = thr1; + + /* Updates */ + st->prim_act_quick = 0.2f * (*localVAD) + (1.0f -0.2f)* st->prim_act_quick; + st->prim_act_slow = 0.01f * (*localVAD) + (1.0f-0.01f)* st->prim_act_slow; + if (st->prim_act_quick <= st->prim_act_slow) + { + st->prim_act = 0.1f * st->prim_act_quick + (1.0f-0.1f)* st->prim_act; + } + else + { + st->prim_act = 0.1f * st->prim_act_slow + (1.0f-0.1f)* st->prim_act; + } + + st->prim_act_quick_he = 0.2f * *localVAD_HE_SAD + (1.0f -0.2f)* st->prim_act_quick_he; + st->prim_act_slow_he = 0.01f * *localVAD_HE_SAD + (1.0f-0.01f)* st->prim_act_slow_he; + + if (st->prim_act_quick_he <= st->prim_act_slow_he) + { + st->prim_act_he = 0.1f * st->prim_act_quick_he + (1.0f-0.1f)* st->prim_act_he; + } + else + { + st->prim_act_he = 0.1f * st->prim_act_slow_he + (1.0f-0.1f)* st->prim_act_he; + } + + + if ((st->vad_flag_reg_H & (long) 0x40000L) != 0) /* 0x4000L = 0x01L << 18 */ + { + st->vad_flag_cnt_50 = st->vad_flag_cnt_50-1; + } + + st->vad_flag_reg_H = (st->vad_flag_reg_H & (long) 0x3fffffffL ) << 1; + + if ( ( st->vad_flag_reg_L & (long) 0x40000000L) != 0) + { + st->vad_flag_reg_H = st->vad_flag_reg_H | 0x01L; + } + + st->vad_flag_reg_L = (st->vad_flag_reg_L & (long) 0x3fffffffL ) << 1; + + if ( flag ) /* should not include the extra DTX hangover */ + { + st->vad_flag_reg_L = st->vad_flag_reg_L | 0x01L; + st->vad_flag_cnt_50 = st->vad_flag_cnt_50+1; + } + + if ((st->vad_prim_reg & (long) 0x8000L ) != 0) /* 0x8000L = 1L << 15 */ + { + st->vad_prim_cnt_16 = st->vad_prim_cnt_16-1; + } + + st->vad_prim_reg = (st->vad_prim_reg & (long) 0x3fffffffL ) << 1; + + if(*localVAD) + { + st->vad_prim_reg = st->vad_prim_reg | 0x01L; + st->vad_prim_cnt_16 = st->vad_prim_cnt_16+1; + } + + + + return flag; +} diff --git a/src/libs/libevs/lib_enc/vad_basop.cpp b/src/libs/libevs/lib_enc/vad_basop.cpp deleted file mode 100755 index 0442e190..00000000 --- a/src/libs/libevs/lib_enc/vad_basop.cpp +++ /dev/null @@ -1,145 +0,0 @@ -/*==================================================================================== - EVS Codec 3GPP TS26.442 Apr 03, 2018. Version 12.11.0 / 13.6.0 / 14.2.0 - ====================================================================================*/ - -#include -#include -#include "prot_fx.h" -#include "vad_basop.h" -#include "basop_util.h" -#include "stl.h" -#include "options.h" /* Needed for Stack Counting Mechanism Macros (when Instrumented) */ - -Word32 vad_Sqrt_l( /* o : output value, Q31 */ - Word32 i_s32Val, - Word16 *io_s16Q -) -{ - Word16 exp; - Word32 result; - - exp = sub(31,*io_s16Q); - result = Sqrt32(i_s32Val, &exp); - *io_s16Q = sub(31,exp); - move16(); - - return (result); -} - -Word32 fft_vad_Sqrt_l( /* o : output value, Q31 */ - Word32 i_s32Val, - Word16 i_s16Q, - Word16 *o_s16Q -) -{ - Word16 exp; - Word32 result; - - exp = sub(31, i_s16Q); - result = Sqrt32(i_s32Val, &exp); - *o_s16Q = sub(31, exp); - move16(); - - return (result); -} - -Word32 VAD_L_div(Word32 L_var1, Word32 L_var2,Word16 Q_L_var1,Word16 Q_L_var2,Word16 *Q_OUT ) -{ - Word32 result; - - result = L_deposit_h(BASOP_Util_Divide3232_Scale(L_var1, L_var2, Q_OUT)); - move16(); - *Q_OUT = add(sub(sub(31, *Q_OUT), Q_L_var2), Q_L_var1); - return result; -} - -Word32 VAD_Log2(Word32 i_s32Val, Word16 i_s16Q) -{ - Word32 result; - - /* log10(x) = log2(x) * 1.0/log2(10), exponent LD_DATA_SCALE - 1 */ - result = BASOP_Util_Log2(i_s32Val); - - result = L_add(result, L_shl(L_deposit_l(sub(31, i_s16Q)), 31-LD_DATA_SCALE)); - - return result; -} - -T_VAD_EXP VAD_AddExp(T_VAD_EXP i_tExp1, T_VAD_EXP i_tExp2) -{ - Word16 s16Shift; - T_VAD_EXP tRtnVal; - - if(i_tExp1.s32Mantissa == 0) - { - return i_tExp2; - } - - if(i_tExp2.s32Mantissa == 0) - { - return i_tExp1; - } - s16Shift = sub(s_min(i_tExp1.s16Exp,i_tExp2.s16Exp),1); - tRtnVal.s32Mantissa = L_add(L_shr(i_tExp2.s32Mantissa, sub(i_tExp2.s16Exp,s16Shift)), L_shr(i_tExp1.s32Mantissa, sub(i_tExp1.s16Exp,s16Shift))); - tRtnVal.s16Exp = s16Shift; - move16(); - - s16Shift = norm_l(tRtnVal.s32Mantissa); - tRtnVal.s32Mantissa = L_shl(tRtnVal.s32Mantissa, s16Shift); - tRtnVal.s16Exp = add(tRtnVal.s16Exp,s16Shift); - - return tRtnVal; - -} -Word32 VAD_L_ADD(Word32 s32Mantissa1,Word16 i_tExp1, Word32 s32Mantissa2, Word16 i_tExp2,Word16 *s16Exp) -{ - Word32 result; - - result = BASOP_Util_Add_Mant32Exp(s32Mantissa1, sub(31, i_tExp1), s32Mantissa2, sub(31, i_tExp2), s16Exp); - - move16(); - *s16Exp = sub(31, *s16Exp); - - return result; -} - -Word16 VAD_L_CMP(Word32 s32Mantissa1,Word16 i_tExp1, Word32 s32Mantissa2, Word16 i_tExp2) -{ - Word16 ret; - - ret = BASOP_Util_Cmp_Mant32Exp(s32Mantissa1, sub(31, i_tExp1), s32Mantissa2, sub(31, i_tExp2)); - - return ret; -} - -Word16 FixSqrt(Word32 i_s32Val, Word16 *io_s16Q) -{ - Word16 result, exp; - - exp = sub(31, *io_s16Q); - result = round_fx(Sqrt32(i_s32Val, &exp)); - move16(); - *io_s16Q = sub(15, exp); - - return result; -} - -Word32 VAD_Pow(Word32 i_s32Base, Word32 i_s32Exp, - Word16 i_s16BaseQ, Word16 i_s16ExpQ, Word16 *o_pOuQ) -{ - Word32 result; - result = BASOP_Util_fPow(i_s32Base, sub(31, i_s16BaseQ), i_s32Exp, sub(31, i_s16ExpQ), o_pOuQ); - move16(); - *o_pOuQ = sub(31, *o_pOuQ); - return result; -} - -Word32 VAD_Pow2(Word32 i_s32X, Word16 i_s16Q, Word16 *o_pOuQ) -{ - Word32 result; - result = BASOP_util_Pow2(i_s32X, sub(31, i_s16Q), o_pOuQ); - move16(); - *o_pOuQ = sub(31, *o_pOuQ); - - return result; -} diff --git a/src/libs/libevs/lib_enc/vad_basop.h b/src/libs/libevs/lib_enc/vad_basop.h deleted file mode 100755 index 60069bc9..00000000 --- a/src/libs/libevs/lib_enc/vad_basop.h +++ /dev/null @@ -1,80 +0,0 @@ -/*==================================================================================== - EVS Codec 3GPP TS26.442 Apr 03, 2018. Version 12.11.0 / 13.6.0 / 14.2.0 - ====================================================================================*/ - -#ifndef __VAD_BASOP_H__ -#define __VAD_BASOP_H__ - -#include "typedef.h" -#include "basop32.h" -#include "stat_enc_fx.h" - -Word16 vadmin( Word16 a, - Word16 b - ); - -Word32 vad_Sqrt_l( Word32 i_s32Val, - Word16 *io_s16Q - ); - -Word32 fft_vad_Sqrt_l( Word32 i_s32Val, - Word16 i_s16Q, - Word16 *o_s16Q - ); - -T_VAD_EXP VAD_AddExp( T_VAD_EXP i_tExp1, - T_VAD_EXP i_tExp2 - ); - -Word16 VAD_L_CMP( Word32 s32Mantissa1, - Word16 i_tExp1, - Word32 s32Mantissa2, - Word16 i_tExp2 - ); - -Word32 VAD_L_ADD( Word32 s32Mantissa1, - Word16 i_tExp1, - Word32 s32Mantissa2, - Word16 i_tExp2, - Word16 *s16Exp - ); - -Word32 VAD_L_div( Word32 L_var1, - Word32 L_var2, - Word16 Q_L_var1, - Word16 Q_L_var2, - Word16 *Q_OUT - ); - -Word32 VAD_Log2( Word32 i_s32Val, - Word16 i_s16Q - ); - -Word16 ffr_getSfWord32( Word32 *vector, - Word16 len - ); - -Word32 VAD_Pow( Word32 i_s32Base, - Word32 i_s32Exp, - Word16 i_s16BaseQ, - Word16 i_s16ExpQ, - Word16 *o_pOuQ - ); - -Word32 VAD_Pow2( Word32 i_s32X, - Word16 i_s16Q, - Word16 *o_pOuQ - ); - -Word16 FixSqrt( Word32 i_s32Val, - Word16 *io_s16Q - ); - -void cfftf( Word16* scale, - complex_32 *c, - complex_32 *ch, - const complex_16 *wa - ); - - -#endif diff --git a/src/libs/libevs/lib_enc/vad_fx.cpp b/src/libs/libevs/lib_enc/vad_fx.cpp deleted file mode 100755 index a878d82e..00000000 --- a/src/libs/libevs/lib_enc/vad_fx.cpp +++ /dev/null @@ -1,1553 +0,0 @@ -/*==================================================================================== - EVS Codec 3GPP TS26.442 Apr 03, 2018. Version 12.11.0 / 13.6.0 / 14.2.0 - ====================================================================================*/ - -#include "options.h" /* Compilation switches */ -#include "cnst_fx.h" /* Common constants */ -#include "prot_fx.h" /* Function prototypes */ -#include "rom_enc_fx.h" -#include "stl.h" - - - -/*-----------------------------------------------------------------* - * Local constants - *-----------------------------------------------------------------*/ -/* old fx constants */ -#define HANGOVER_LONG 10 /* Hangover for CNG */ -#define HANGOVER_LONG_HE 20 /* Hangover of CNG */ -#define HANGOVER_LONG_NB 8 /* Hangover for CNG */ -#define ACTIVE_FRAMES 3 /* Number of consecutive active SPEECH frames necessary to trigger HO */ - -/* SNR threshold curve constants for WB input */ -#define SK16_2_FX 16930 /* Q14 (1.0333f)-> Linear function for clean speech */ -#define SC16_2_FX -4608 /* Q8 (-18)*/ -#define NK16_2_FX 13529 /* Q15 (.41287)-> Linear function for noisy speech */ -#define NC16_2_FX 3394 /* Q8 (13.259625)*/ -/* SNR threshold curve constants for NB input */ -#define NK8_1_FX 3509 /*Q15 (0.1071f) Linear function for noisy speech */ -#define NC8_1_FX 4224 /*Q8 (16.5f) */ -#define SK8_1_FX 12406 /*Q15 (0.3786f) Linear function for clean speech */ -#define SC8_1_FX 2834 /*Q8 (11.07f) */ -#define SIGN_THR_FX 40 /*Q4 (2.5f) Significanse threshold for per band snr calculation */ -#define MIN_SNR_FX 2 /*Q4 Minimum snr used for per band snr calculation */ - - -#define THR_M0_FX 3379 /* Q8 (13.2) Zero ofset for threshod */ -#define THR_K_BG_FX -8192 /* Q15(-0.25) Coefficient for dependence on background level */ -#define THR_K_BG_OFS_FX 5120 /* Q8 (20.0f) Zero offset for background level */ -#define THR_K_SNR_FX 3277 /* Q15 (0.1f) Coefficient for dependence on SNR */ -#define THR_K_EV_FX 18022 /* Q15 (0.55) Coefficient for dependence on noise variations */ - - -#define HO_DTX_CLEAN 1 /* Hangover for dtx in clean conditions */ -#define HO_DTX_NOISY 10 /* Hangover for dtx in noisy conditions */ -#define HO_DTX_NOISY2 4 /* Hangover for dtx in very noisy conditions */ -#define VAD_THR_MIN_FX 2688 - -#define ONE_LG10 2466 /* 1.0*log10(2) in Q13 */ - - -#define HANGOVER_LONG_FX 10 /* Hangover for CNG */ -#define HANGOVER_LONG_MUSIC_FX 20 /* Hangover of CNG */ -#define HANGOVER_LONG_HE_FX 20 /* Hangover of CNG */ -#define HANGOVER_LONG_NB_FX 8 /* Hangover for CNG */ -#define ACTIVE_FRAMES_FX 3 /* Number of consecutive active SPEECH frames necessary to trigger HO */ - -/* SNR threshold curve constants for WB input */ -#define TH16_2_FX 8960 /* Q8 (35) -> lp SNR that separates the curves for clean speech and noisy speech */ -#define TH8_1_FX 5120 /*Q8 (20.0f) long-term SNR that separates the curves for clean speech and noisy speech */ - -#define TH16_2_NFLAG_FX 8960 /* Q8 (35) */ -#define TH8_1_NFLAG_FX 8960 /* Q8 (35) */ - - -#define SNR_OUTLIER_WGHT_1_FX 16384 /* Q14 (1.00)*/ -#define SNR_OUTLIER_WGHT_2_FX 16548 /* Q14 (1.01)*/ -#define SNR_OUTLIER_WGHT_3_FX 16712 /* Q14 (1.02)*/ -#define INV_OUTLIER_THR_1_FX 3277 /* (1/10.0f) in Q15*/ -#define INV_OUTLIER_THR_2_FX 5461 /* (1/6.0f) in Q15 */ - -#define MAX_SNR_OUTLIER_IND_FX 17 /*Q0 */ -#define MAX_SNR_OUTLIER_1_FX 160 /*Q4 (10.0f)*/ -#define MAX_SNR_OUTLIER_2_FX 400 /*Q4 (25.0f)*/ -#define MAX_SNR_OUTLIER_3_FX 800 /*Q4 (50.0f)*/ - - -/* snr_sum = "scale" * (float)log10( L_snr_sum ) ;*/ -static -Word16 vad_snr_log_fx( /* o: Q8 */ - Word32 L_snr /* i: Q4 */ - , Word16 scale)/* i: scale Q13 , 10.0*log10(2) or 1.0*log10(2) */ -{ - Word16 e_snr,f_snr; - Word32 L_tmp; - - e_snr = norm_l(L_snr); - f_snr = Log2_norm_lc(L_shl(L_snr, e_snr)); - e_snr = sub(30-4, e_snr); - L_tmp=Mpy_32_16(e_snr, f_snr, scale); - return round_fx(L_shl(L_tmp, 10)); /* Q8 */ -} - - -void wb_vad_init_fx( - Word16 *nb_active_frames, /* o : nb of consecutive active speech frames */ - Word16 *hangover_cnt, - Word16 *lp_speech, /* o : long-term active speech level */ - Word16 *nb_active_frames_he, /* o : nb of consecutive active speech frames */ - Word16 *hangover_cnt_he, - Word16 *bcg_flux, /* o : background noise fluctuation */ - Word16 *soft_hangover, /* o : soft hangover counter */ - Word16 *voiced_burst, /* o : consecutive voiced speech counter */ - Word16 *bcg_flux_init, /* o : initialization period for noise fluctuation estimation */ - Word16 *nb_active_frames_he1, /* o : nb of consecutive active speech frames 1 */ - Word16 *hangover_cnt_he1, - Word32 *L_vad_flag_reg_H, - Word32 *L_vad_flag_reg_L, - Word32 *L_vad_prim_reg, - Word16 *vad_flag_cnt_50, - Word16 *vad_prim_cnt_16, - Word16 *hangover_cnt_dtx - , Word16 *hangover_cnt_music -) -{ - *hangover_cnt = 0; - move16(); /* Hangover counter initialized to 0 */ - *nb_active_frames = ACTIVE_FRAMES_FX; - move16(); /* The counter of SPEECH frames necessary to trigger HO */ - /* is set to max (-> start with hangover) */ - *lp_speech = 11520; - move16(); /*Q8 (45.0) */ /* Initialize the long-term active speech level in dB */ - - *L_vad_flag_reg_H = L_deposit_l(0); - *L_vad_flag_reg_L = L_deposit_l(0); - *L_vad_prim_reg = L_deposit_l(0); - *vad_flag_cnt_50 = 0; - move16(); - *vad_prim_cnt_16 = 0; - move16(); - - *hangover_cnt_dtx = HANGOVER_LONG_FX; - move16(); /* hangover for DTX */ - *hangover_cnt_music = HANGOVER_LONG_MUSIC_FX; - move16(); /* hangover for MUSIC DTX */ - - *hangover_cnt_he = 0; - move16(); /* Hangover counter initialized to 0 */ - *nb_active_frames_he = ACTIVE_FRAMES_FX; - move16(); /* The counter of SPEECH frames necessary to trigger HO */ - *bcg_flux = 1120; - move16(); /*70 in Q4 */ - *soft_hangover = 0; - move16(); - *voiced_burst = 0; - move16(); - *bcg_flux_init = 50; - move16(); - *nb_active_frames_he1 = ACTIVE_FRAMES_FX; - move16(); - *hangover_cnt_he1 = 0; - move16(); - return; -} - - -/*-----------------------------------------------------------------* - * sign_thr_snr_acc_fx() - * - * accumulate snr_sum with significance thresholds - *-----------------------------------------------------------------*/ -static -void sign_thr_snr_acc_fx( - Word32 *L_snr_sum, /* o: Q4 */ - Word32 L_snr, /* i: Q4 */ - Word16 sign_thr, /* i: Q4 */ - Word16 min_snr ) /* i: Q4 */ -{ - /*if( snr >= sign_thr ) */ - Word32 L_tmp; - - L_tmp = L_deposit_l(min_snr); - if( L_sub(L_snr, L_deposit_l(sign_thr)) >= 0 ) - { - L_tmp = L_add(L_snr, 0); - } - BASOP_SATURATE_WARNING_OFF /* may saturate in BASOP */ - *L_snr_sum = L_add(*L_snr_sum, L_tmp); /* Q4 */ - BASOP_SATURATE_WARNING_ON -} - -/*-----------------------------------------------------------------* - * dtx_hangover_addition_fx() - * - *-----------------------------------------------------------------*/ - -Word16 dtx_hangover_addition_fx( - Encoder_State_fx *st_fx, /* i/o: encoder state structure */ - const Word16 localVAD, /* i Q0 */ - const Word16 vad_flag, /* i Q0 */ - const Word16 lp_snr, /* i Q8 */ - const Word16 cldfb_subtraction, /* i Q0 number of DTX-HO frames CLDFB wants to reduce */ - Word16 *vad_hover_flag_ptr -) -{ - Word16 hangover_short_dtx ; - Word16 flag_dtx ; - Word16 tmp; - - - flag_dtx = 0; - move16(); - - /* Determine initial hangover length */ - hangover_short_dtx = 2; - move16(); - - test(); - test(); - if ( ( ( sub(lp_snr,(16*256)) < 0 ) - && ( sub(st_fx->input_bwidth_fx, NB) != 0 )) - || ( sub(st_fx->prim_act_he_fx, 31130) > 0 ) ) /*.95*Q15*/ - { - hangover_short_dtx = 3; - move16(); - } - - /* Adjust hangover according to activity history */ - if (sub(st_fx->vad_prim_cnt_16_fx, 12) > 0 ) /* 12 requires roughly > 80% primary activity */ - { - hangover_short_dtx = add(hangover_short_dtx,2); - } - - if (sub(st_fx->vad_flag_cnt_50_fx, 40) > 0) /* 40 requires roughtly > 80% flag activity */ - { - hangover_short_dtx = add(hangover_short_dtx,5); - } - - /* Keep hangover_short lower than maximum hangover count */ - if (sub(hangover_short_dtx, HANGOVER_LONG_FX-1) > 0 ) - { - hangover_short_dtx = (HANGOVER_LONG_FX-1); - move16(); - } - - /* Only allow short HO if not sufficient active frames in clean speech*/ - - tmp = 3; - move16(); /* default for EVS*/ - if (sub(st_fx->core_fx,AMR_WB_CORE) == 0 ) - { - tmp = 2; - move16(); /* default for AMRWBIO*/ - } - - /* need to be a bit stricter with the DTXHO in very clean WB, SWB cond for EVS12k8VAD section */ - test(); - test(); - if ( ( sub(st_fx->input_bwidth_fx, NB) != 0 ) /* WB or SWB or FB */ - && ( sub(st_fx->core_fx, AMR_WB_CORE) != 0 ) - && ( sub(lp_snr, 25*256) > 0 ) - ) - { - tmp = 2; - move16(); - } - - /* limit dtx hangover addition up to "tmp" frames in clean cond */ - IF ( tmp != 0 ) - { - test(); - test(); - test(); - if ( (sub(hangover_short_dtx, tmp) > 0 ) - && ( (sub(st_fx->vad_prim_cnt_16_fx, 7) < 0 ) - || ( (sub(lp_snr, (16*256)) > 0) - && (sub(st_fx->prim_act_he_fx, 27853) < 0) /*0.85f*2^15 */ - ) - ) - ) - { - hangover_short_dtx = tmp; - move16(); - } - } - - - /* hangover adjustment from combined FFT+CLDFBVAD */ - IF (sub(st_fx->core_fx,AMR_WB_CORE) != 0 ) - { - hangover_short_dtx = sub(hangover_short_dtx, cldfb_subtraction); - hangover_short_dtx = s_max(hangover_short_dtx, 0); - } - - IF ( vad_flag != 0 ) /* Speech present */ - { - flag_dtx = 1; - move16(); - - /* Add hangover after sufficient # of active frames or sufficient activity during last second */ - test(); - if ( ( sub(st_fx->nb_active_frames_fx, ACTIVE_FRAMES_FX) >=0 ) - || (sub(st_fx->vad_flag_cnt_50_fx,45) > 0) ) /* 45 requires roughly > 90% flag activity */ - { - st_fx->hangover_cnt_dtx_fx = 0; - move16(); - } - - /* inside HO period */ - test(); - if( ( sub(st_fx->hangover_cnt_dtx_fx, HANGOVER_LONG_FX) < 0) - && (st_fx->hangover_cnt_dtx_fx != 0) ) - { - st_fx->hangover_cnt_dtx_fx = add(st_fx->hangover_cnt_dtx_fx, 1); - } - st_fx->hangover_terminate_flag_fx = 0; - move16();/* float fix FIX_HO_TERMINATE */ - - /* Music hangover when music detected */ - test(); - test(); - test(); - if ( (sub(st_fx->prim_act_he_fx,31129) > 0) - && (sub(st_fx->Etot_lp_fx,40*256) > 0) - && (sub(st_fx->vad_prim_cnt_16_fx,14) > 0) - && (sub(st_fx->vad_flag_cnt_50_fx,48) > 0) ) /* 45 requires roughly > 95% flag activity */ - { - st_fx->hangover_cnt_music_fx = 0; - move16(); - } - - /* inside Music HO period */ - test(); - if( ( sub(st_fx->hangover_cnt_music_fx, HANGOVER_LONG_MUSIC_FX) < 0) - && (st_fx->hangover_cnt_music_fx != 0) ) - { - st_fx->hangover_cnt_music_fx = add(st_fx->hangover_cnt_music_fx, 1); - } - } - ELSE - { - /* Reset the counter of speech frames necessary to start hangover algorithm */ - if(sub(st_fx->hangover_cnt_dtx_fx,HANGOVER_LONG_FX) <0 ) /* inside HO period */ - { - st_fx->hangover_cnt_dtx_fx = add(st_fx->hangover_cnt_dtx_fx,1); - } - if(sub(st_fx->hangover_cnt_music_fx,HANGOVER_LONG_MUSIC_FX) <0 ) /* inside HO period */ - { - st_fx->hangover_cnt_music_fx = add(st_fx->hangover_cnt_music_fx,1); - } - - /* fast terminate DTX hangover if st->hangover_terminate_flag is set */ - IF ( st_fx->hangover_terminate_flag_fx != 0 ) - { - st_fx->hangover_cnt_fx = HANGOVER_LONG_FX; - move16(); - st_fx->hangover_cnt_dtx_fx = HANGOVER_LONG_FX; - move16(); - st_fx->hangover_terminate_flag_fx = 0; - move16(); - /* Only shorten music hangover when low energy frames */ - if (sub(st_fx->Etot_lp_fx,20*256)<0) - { - st_fx->hangover_cnt_music_fx = HANGOVER_LONG_MUSIC_FX; - move16(); - } - } - - if( sub(st_fx->hangover_cnt_dtx_fx, hangover_short_dtx) <= 0) /* "hard" hangover */ - { - flag_dtx = 1; - move16(); - } - - if( sub(st_fx->hangover_cnt_music_fx, 15) <= 0) /* "hard" hangover music */ - { - flag_dtx = 1; - move16(); - } - } - - - - test(); - if ( flag_dtx != 0 && localVAD == 0 ) - { - *vad_hover_flag_ptr = 1; - move16(); - } - - return flag_dtx ; -} - - -/* new simplified and harmonized code */ -Word16 wb_vad_fx( - Encoder_State_fx *st_fx, /* i/o: encoder state structure */ - const Word32 fr_bands[], /* i : per band input energy (contains 2 vectors) Q_new+QSCALE*/ - Word16 *localVAD, - Word16 *noisy_speech_HO, /* o : SC-VBR noisy speech HO flag */ - Word16 *clean_speech_HO, /* o : SC-VBR clean speech HO flag */ - Word16 *NB_speech_HO, /* o : SC-VBR NB speech HO flag */ - Word16 *snr_sum_he, /* o : Output snr_sum as weighted spectral measure*/ - Word16 *localVAD_HE_SAD, - Word8 *flag_noisy_speech_snr , /* o : */ - const Word16 Q_new /* i : scaling factor Q0 */ -) -{ - Word16 i, flag=0, hangover_short; - - Word16 snr_sum, thr1=0, thr1_nb_mod, thr2=0, nk=0, nc=0, th_clean=0; - Word16 lp_snr; /* Q8 */ - const Word32 *pt1; - const Word32 *pt2; - const Word32 *pt3; - - Word16 min_snr, sign_thr; - - Word32 L_snr, L_snr_sum ; - Word32 ftmp, ftmp1, ftmp2; - Word16 m_noise, e_noise, e_num, m_num, snr, snr_tmp, shift_snr; - - Word16 snr_sumt; - Word32 L_vad_thr; - Word16 hangover_hd; - Word16 snr_idx; - Word16 delta1, delta2, delta3,delta4; - - Word16 flag_he1; - Word16 stmp; - Word32 L_msnr, L_mssnr=0, L_mssnr_hov; - Word16 j, tmp, tmp1, tmp2 ; - Word32 L_tmp, L_tmp1, L_tmp2; - - Word32 L_snr18, L_snr19; /* Q4 */ - Word32 L_msnr18, L_msnr19; /* Q13 */ - Word16 nb_sig_snr; /* Q0 */ - - Word16 nv; - Word16 nv_ofs; /* Q8 */ - Word32 L_snr_sum_HE_SAD; /* Q4 */ - Word16 snr_sum_HE_SAD; /*Q8 log */ - Word16 sign_thr_HE_SAD, min_snr_HE_SAD; - - - Word16 thr1_ol; - Word32 L_snr_sum_ol; - Word16 snr_sum_ol; /* Q8 log */ - - Word32 L_snr_outlier; - Word16 snr_outlier_index; - Word32 L_accum_ener_L; - Word32 L_accum_ener_H; - Word16 vad_bwidth_fx; - - vad_bwidth_fx = st_fx->input_bwidth_fx; - move16(); - - L_snr_outlier = L_deposit_l(0); - snr_outlier_index = 0; - move16(); - L_accum_ener_L = L_deposit_l(0); - L_accum_ener_H = L_deposit_l(0); - - L_snr18 = L_deposit_l(0); /* Q4*/ - L_snr19 = L_deposit_l(0); /* Q4 */ - L_msnr18 = L_deposit_l(8192); /* 1.0 Q13*/ - L_msnr19 = L_deposit_l(8192); /* 1.0 Q13 */ - - - IF( sub(vad_bwidth_fx, NB) == 0) - { - st_fx->min_band_fx = 1; - move16(); - st_fx->max_band_fx = 16; - move16(); - } - ELSE - { - st_fx->min_band_fx = 0; - move16(); - st_fx->max_band_fx = 19; - move16(); - } - - /*---------------------------------------------------------------------* - * set SNR thresholds depending on the input bandwitdh - *---------------------------------------------------------------------*/ - IF( sub(st_fx->max_band_fx,19) == 0 ) /* WB input */ /* or SWB input */ - { - nk = 3277; - move16(); /*0.1 Q15 */ - nc = 4122 ; - move16(); /*16.1 Q8 */ - nv = 525; - move16();/* 2.05 Q8*/ - nv_ofs = 422; - move16();/* 1.65 Q8*/ - th_clean = TH16_2_FX; - move16();/* 35 Q8 */ - sign_thr = 21; - move16(); /*1.3 Q4 */ - tmp = sub(vad_bwidth_fx, WB); - if ( tmp != 0 ) - { - sign_thr = 28; - move16();/*1.75f; Q4 SWB */ - } - min_snr = 13; - move16(); /*0.8 Q4 WB */ - if ( tmp != 0 ) - { - min_snr = 4; - move16(); /*0.25f; Q4 SWB */ - } - - sign_thr_HE_SAD = 40; - move16();/* 2.5f Q4 */; - min_snr_HE_SAD = 3; - move16(); /* 0.2f Q4 */; - } - ELSE /* NB input */ - { - move16(); - nk = 3277; - move16(); /* 0.1 Q15 */ - nc = 4096; - move16(); /* 16.0 Q8 */ - nv = 1024; - move16(); /* 4.0 Q8 */ - nv_ofs = 294 ; - move16(); /*1.15 Q8*/ - th_clean = TH8_1_FX; - move16(); /*20 Q8 */ - sign_thr = 28; - move16(); /* 1.75 * Q4 SIGN_THR */ - min_snr = 4; - move16(); /* .25 *Q4 MIN_SNR */ - sign_thr_HE_SAD = 42; - move16(); /* 2.65f Q4 */; - min_snr_HE_SAD = 1; - move16(); /* 0.05f Q4 */; - } - - hangover_short = 0; - move16(); - - /* IF( st_fx->Opt_SC_VBR_fx != 0 ) */ - *noisy_speech_HO = 0; - move16(); - *clean_speech_HO = 0; - move16(); - *NB_speech_HO = 0; - move16(); - /* } */ - - /*---------------------------------------------------------------------* - * compute SNR for each band & total - *---------------------------------------------------------------------*/ - - lp_snr = sub(st_fx->lp_speech_fx, st_fx->lp_noise_fx); /*Q8 */ - - snr_idx = 2; - move16(); - if( sub(lp_snr,4608) > 0 ) /*18.0 Q8*/ - { - snr_idx = 1; - move16(); - } - if ( sub(lp_snr,6144) > 0 ) /*24.0 Q8*/ - { - snr_idx = 0; - move16(); - } - - - IF ( snr_idx == 0 ) - { - stmp = 6; - move16(); - delta1 = 0; - move16(); /*0.0f in Q13 */ - delta2 = 0; - move16(); /*0.0f in Q13 */ - delta3 = 0; - move16(); /*0.0f in Q13 */ - delta4 = 0; - move16(); - - - /*vad_thr = 2.4f*lp_snr - 42.2f; - vad_thr = min(vad_thr, 80 ); */ - - L_vad_thr = -345702; - move32() ; /* -42.2 Q13*/ - L_vad_thr = L_mac0(L_vad_thr,77,lp_snr) ; /* (2.4)Q5*(lp_snr)Q8 */ - L_vad_thr = L_min(L_vad_thr, 80*(1<<13) ); - } - ELSE IF ( sub(snr_idx,1) == 0 ) - { - stmp = 6; - move16(); - delta1 = 819; - move16(); /*0.1f in Q13 */ - delta2 = 1638; - move16(); /*0.2f in Q13 */ - delta3 = 1638; - move16(); /*0.2f in Q13 */ - delta4 = 1638; - move16(); /*0.2f in Q13 */ - - /* vad_thr = 2.4f*lp_snr - 40.2f; - vad_thr = min(vad_thr, 80); - */ - L_vad_thr = -329318; - move32() ; /* -40.2 Q13*/ - L_vad_thr = L_mac0(L_vad_thr,77,lp_snr) ; /* (2.4)Q5*(lp_snr)Q8 */ - L_vad_thr = L_min(L_vad_thr, 80*(1<<13) ); - } - ELSE - { - stmp = 9; - move16(); - delta1 = 1638; - move16(); /*0.2f in Q13 */ - delta2 = 3277; - move16(); /*0.4f in Q13 */ - delta3 = 2458; - move16(); /*0.3f in Q13 */ - delta4 = 3277; - move16(); /*0.4f in Q13 */ - /* vad_thr = 2.5f*lp_snr - 10.0f; - vad_thr = max(vad_thr, 1); - */ - L_vad_thr = -81920; - move32() ; /* -10 Q13*/ - L_vad_thr = L_mac0(L_vad_thr,80,lp_snr) ; /* (2.5)Q5*(lp_snr)Q8 */ - L_vad_thr = L_max(L_vad_thr, 1*(1<<13) ); - } - - nb_sig_snr = 20; - move16(); - - pt1 = fr_bands; - pt2 = fr_bands + NB_BANDS; - pt3 = st_fx->bckr_fx; - - L_snr_sum = L_deposit_l(0); - L_snr_sum_HE_SAD = L_deposit_l(0); - snr_sumt = 0; - move16(); - L_mssnr_hov = L_deposit_l(0); - *snr_sum_he = 0; - move16(); - snr_sum_HE_SAD = 0; - move16(); - - - FOR( i=st_fx->min_band_fx; i<=st_fx->max_band_fx; i++ ) - { - ftmp = L_add(*pt1++, 0); - ftmp1 = L_add(*pt2++, 0); - ftmp2 = L_add(*pt3++, 0); - - /*fr_enr = ( 0.2f * st->enrO[i] + 0.4f * ftmp + 0.4f * ftmp1 );*/ - L_tmp = Mult_32_16(st_fx->enrO_fx[i], 13107); /* L_tmp(high word) = Qenr0fx*Q16+1 -16 -> Qener0+1 */ - L_tmp1 = Madd_32_16(L_tmp, ftmp, 26214); /* 26214 = .4 in Q16 */ - L_tmp1 = Madd_32_16(L_tmp1, ftmp1, 26214); /* L_tmp1 re_used a bit later for final snr[i]*/ - - L_tmp2 = Madd_32_16(L_tmp, ftmp, 19661); /* 19661 = 0.3 in Q16 */ - L_tmp2 = Msub_32_16(L_tmp2, ftmp1, -32768); /* -32768= -0.5 in Q16 */ - - IF (L_sub(ftmp,ftmp1) > 0) - { - /*snr[i] = ( 0.2f * st->enrO[i] + 0.4f * ftmp + 0.4f * ftmp1 ) / ftmp2 ;*/ - /*snr[i] = L_tmp1/(ftmp2) */ - IF (ftmp2 != 0) - { - e_num = norm_l(L_tmp1); - m_num = extract_h(L_shl(L_tmp1,e_num)); - - e_noise = norm_l(ftmp2); - m_noise= extract_h(L_shl(ftmp2,e_noise)); - - m_num = shr(m_num,1); - shift_snr = add(sub(e_num, e_noise),15-4); - - snr_tmp = div_s(m_num, m_noise); - L_snr = L_shr(snr_tmp, shift_snr); /* L_snr in Q4 */ - } - ELSE - { - e_num = norm_l(L_tmp1); - m_num = extract_h(L_shl(L_tmp1,e_num)); - - /* if bckr[i] == 0; approx. L_snr */ - e_noise = add(30+1, abs_s(Q_new)); - - m_num = shr(m_num, 1); - shift_snr = add(sub(e_num, e_noise), 15-4); - - snr_tmp = div_s(m_num, 32767); - L_snr = L_shr(snr_tmp, shift_snr); /*L_snr in Q4*/ - } - } - ELSE - { - /*snr[i] = ( 0.2f * st->enrO[i] + 0.3f * ftmp + 0.5f * ftmp1 ) / ftmp2 ;*/ - /*snr[i] =L_tmp2/( ftmp2 ) */ - IF (ftmp2 != 0) - { - e_num = norm_l(L_tmp2); - m_num = extract_h(L_shl(L_tmp2,e_num)); - - e_noise = norm_l(ftmp2); - m_noise= extract_h(L_shl(ftmp2,e_noise)); - - m_num = shr(m_num,1); - shift_snr = add(sub(e_num, e_noise),15-4); - - snr_tmp = div_s(m_num, m_noise); - L_snr = L_shr(snr_tmp, shift_snr); /* L_snr in Q4 */ - } - ELSE - { - e_num = norm_l(L_tmp2); - m_num = extract_h(L_shl(L_tmp2,e_num)); - - /* if bckr[i] == 0; approx. L_snr */ - e_noise = add(30+1, abs_s(Q_new)); - - m_num = shr(m_num, 1); - shift_snr = add(sub(e_num, e_noise), 15-4); - - snr_tmp = div_s(m_num, 32767); - L_snr = L_shr(snr_tmp, shift_snr); /*L_snr in Q4*/ - } - } - - if(L_sub(L_snr,2*(1<<4))<0 ) - { - nb_sig_snr=sub(nb_sig_snr,1); /* nb_sig_snr--; */ - } - L_snr = L_max(L_snr, 1*(1<<4)); /* if ( snr[i] < 1 ){snr[i] = 1;}*/ - - - /* snr[i] = (float)log10(snr[i]); */ - snr = vad_snr_log_fx(L_snr, ONE_LG10); - - /* snr_sumt += snr[i];*/ - snr_sumt = add(snr_sumt,shr(snr,4)); /*Q4 */ - - - tmp = shl(snr,5); /* Q8 -> Q13 */ - IF (sub(i,2) < 0) - { - tmp = add(tmp,delta1); /*Q13 */ - } - ELSE IF (sub(i,7) < 0) - { - tmp = add(tmp,delta2); /*Q13 */ - } - ELSE IF (sub(i,18) < 0) - { - tmp = add(tmp,delta3); /*Q13 */ - } - ELSE - { - tmp = add(tmp,delta4); /*Q13 */ - } - - tmp1=tmp; - move16(); /* ftmp1 = ftmp; */ - sub(0,0); - if ( i < 7 ) - { - tmp1=add(tmp,3277); /*.4 in Q13 ftmp1 = ftmp + 0.4f; */ - } - - tmp=s_min(tmp,16384); /* Q13, ftmp = min(ftmp, 2.0f); */ - tmp1=s_min(tmp1,16384); /* Q13, ftmp1 = min(ftmp1, 2.0f); */ - - L_msnr = L_deposit_l(tmp); /*msnr = 1*tmp;*/ - FOR (j=1; jbckr[i] = L_tmp1/st->bckr[i];*/ - IF (st_fx->bckr_fx[i] != 0) - { - e_num = norm_l(L_tmp1); - m_num = extract_h(L_shl(L_tmp1,e_num)); - - e_noise = norm_l(st_fx->bckr_fx[i]); - m_noise= extract_h(L_shl(st_fx->bckr_fx[i],e_noise)); - - m_num = shr(m_num,1); - shift_snr = add(sub(e_num, e_noise),15-4); - - snr_tmp = div_s(m_num, m_noise); - L_snr = L_shr(snr_tmp, shift_snr); /* L_snr in Q4 */ - } - ELSE - { - e_num = norm_l(L_tmp1); - m_num = extract_h(L_shl(L_tmp1,e_num)); - - /* if bckr[i] == 0; approx. L_snr */ - e_noise = add(30+1, abs_s(Q_new)); - - m_num = shr(m_num, 1); - shift_snr = add(sub(e_num, e_noise), 15-4); - - snr_tmp = div_s(m_num, 32767); - L_snr = L_shr(snr_tmp, shift_snr); /*L_snr in Q4*/ - } - - - /* conditional snrsum, snr_sum = snr_sum + snr[i];*/ - sign_thr_snr_acc_fx(&L_snr_sum_HE_SAD,L_snr, sign_thr_HE_SAD, min_snr_HE_SAD); - sign_thr_snr_acc_fx(&L_snr_sum, L_snr, sign_thr, min_snr); - - L_snr = L_max(L_snr, 16); /*Q4, if( snr[i] < 1.0f ) { snr[i] = 1.0f;} */ - - /* float saves all snrs in an snr[] vector , - in fix we only save two bands */ - if ( sub(i,18) == 0 ) - { - L_snr18 = L_add(L_snr, 0); /*Q4 */ - } - if ( sub(i,19) == 0 ) - { - L_snr19 = L_add(L_snr, 0); /* Q4 */ - } - - /* accumulate background noise energy in bands [0-2] and in bands [3-19]*/ - IF(sub(i,3) < 0) - { - L_accum_ener_L = L_add(L_accum_ener_L , st_fx->bckr_fx[i]);/*Q_new+QSCALE */ - } - ELSE - { - L_accum_ener_H = L_add(L_accum_ener_H , st_fx->bckr_fx[i]);/*Q_new+QSCALE */ - } - - /* Identify the outlier band */ - IF( L_sub(L_snr, L_snr_outlier) > 0 ) - { - L_snr_outlier = L_add(L_snr, 0); /*Q4*/ - snr_outlier_index = i; - move16(); - } - } /* end of band loop */ - - test(); - test(); - test(); /* one additional test for ELSE IF */ - IF ( (sub(st_fx->max_band_fx, 19) == 0 ) - && ( L_sub(L_snr18, 5*(1<<4)) > 0 ) - && ( L_sub(L_snr19, 5*(1<<4)) > 0 ) ) - { - /* mssnr = (mssnr + 3*(msnr18 + msnr19)) * 0.77f; */ - /* mssnr = (mssnr*.77f + 2.31f*(msnr18 + msnr19)); */ - L_tmp1 = Mult_32_16(L_mssnr, 25231 ); /* Q13+Q15+1-16 --> Q13 */ - L_tmp = Mult_32_16(L_shl(L_add(L_msnr18, L_msnr19),2),18924 ); /* Q(13+2)+Q(15-2)+1-16 --> Q13 */ - L_tmp = L_add( L_tmp1, L_tmp); - if ( L_sub(L_tmp, L_mssnr) > 0 ) - { - L_mssnr = L_tmp; - } - } - ELSE IF ( (snr_idx != 0) - && sub(nb_sig_snr, 13) > 0 ) - { - L_tmp = -126976; - move32() ; /* -15.5 Q13 */ - L_tmp = L_mac0(L_tmp,80,lp_snr) ; /* 2.5f(Q5)*lp_snr(Q8) - 15.5f */ - if ( L_tmp > 0 ) /* 2.5f*lp_snr - 15.5f > 0 */ - { - L_mssnr = L_add(L_mssnr, L_tmp); /* mssnr += 2.5f*lp_snr - 15.5f; */ - } - } - - - /* Separated SNR_SUM outlier modification */ - L_snr_sum_ol = L_snr_sum; /* snr_sum_ol = snr_sum; */ - - test(); - test(); - test(); - IF( ( sub(st_fx->max_band_fx, 19) == 0 ) - && L_sub(L_snr_outlier , MAX_SNR_OUTLIER_3_FX) < 0 - && sub(snr_outlier_index, 3) > 0 - && sub(snr_outlier_index, MAX_SNR_OUTLIER_IND_FX) < 0) - { - /* Update the total SNR only for WB signals */ - - - /* corresponding float section - if( (accum_ener_L > OUTLIER_THR_1 * accum_ener_H ) || (snr_outlier < MAX_SNR_OUTLIER_1) ) - { - snr_sum_ol = SNR_OUTLIER_WGHT_1 * (snr_sum_ol - snr_outlier); - } - else if( (accum_ener_L > OUTLIER_THR_2 * accum_ener_H ) || (snr_outlier < MAX_SNR_OUTLIER_2) ) - { - snr_sum_ol = SNR_OUTLIER_WGHT_2 * (snr_sum_ol - snr_outlier); - } - else - { - snr_sum_ol = SNR_OUTLIER_WGHT_3 * (snr_sum_ol - snr_outlier); - } - } */ - - test(); - test(); - IF( L_sub(L_accum_ener_H, Mult_32_16(L_accum_ener_L,INV_OUTLIER_THR_1_FX)) < 0 /* float:: (accum_ener_L*INV_OUTLIER_THR_1 > accum_ener_H ) !!! */ - || L_sub(L_snr_outlier,MAX_SNR_OUTLIER_1_FX) < 0 ) - - { - /* as weight1 is 1.0 we do not need to multiply here , i.e. no need to loose any precisison */ - L_snr_sum_ol = L_sub(L_snr_sum_ol,L_snr_outlier); /*Q4 */ - - } - ELSE IF( L_sub(L_accum_ener_H, Mult_32_16(L_accum_ener_L,INV_OUTLIER_THR_2_FX)) < 0 /* float:: (accum_ener_L *INV_OUTLIER_THR_2 > accum_ener_H ) !!! */ - || L_sub(L_snr_outlier,MAX_SNR_OUTLIER_2_FX) < 0 ) - { - /* L_snr_sum = SNR_OUTLIER_WGHT_2 * (snr_sum - snr_outlier); */ - - /* 1.01*x -> (1*x + 0.01*x) to not drop down to Q3 */ - L_tmp = L_sub(L_snr_sum_ol,L_snr_outlier); - L_tmp2 = Mult_32_16(L_tmp, 20972); /* 0.01(in Q21)= 20972 Q4*Q21+1-16 -> Q10 */ - L_snr_sum_ol = L_add(L_tmp, L_shr(L_tmp2,6)); /* Q4 */ - } - ELSE - { - /* L_snr_sum = SNR_OUTLIER_WGHT_3 * (snr_sum - snr_outlier);*/ - /* 1.02*x -> (1*x + 0.02*x) to not drop down to Q3 */ - L_tmp = L_sub(L_snr_sum_ol,L_snr_outlier); - L_tmp2 = Mult_32_16(L_tmp, 20972); /* 0.02(in Q20)= 20972 Q4*Q20+1-16 -> Q9 */ - L_snr_sum_ol = L_add(L_tmp, L_shr(L_tmp2, 5)); /* Q4 */ - - } - } - /*st_fx->snr_sum_vad_fx = 0.5f * st->snr_sum_vad + 0.5f * snr_sum_ol;*/ - st_fx->L_snr_sum_vad_fx = L_shr(L_add(st_fx->L_snr_sum_vad_fx ,L_snr_sum_ol ),1); /*Q4*/ - - /* snr_sum_ol = 10.0f * (float)log10( snr_sum_ol ); */ - snr_sum_ol = vad_snr_log_fx(L_snr_sum_ol, LG10); - snr_sum = snr_sum_ol; - move16(); /* note for NB no outlier modification */ - - /* snr_sum_HE_SAD = 10.0f * (float)log10( snr_sum_HE_SAD ); */ - snr_sum_HE_SAD = vad_snr_log_fx( L_snr_sum_HE_SAD, LG10); - - *snr_sum_he=snr_sum_HE_SAD; - move16(); /* *snr_sum_he=snr_sum_HE_SAD; */ - - - /*---------------------------------------------------------------------* - * compute thr1 for SAD decision - *---------------------------------------------------------------------*/ - lp_snr = sub(st_fx->lp_speech_fx,st_fx->lp_noise_fx); /*Q8*/ - - sub(0,0); - IF ( sub(lp_snr, st_fx->sign_dyn_lp_fx) <0 ) - { - lp_snr = add(lp_snr,1<<8); /* lp_snr += 1; */ - - if (sub(lp_snr, st_fx->sign_dyn_lp_fx) > 0 ) - { - lp_snr = st_fx->sign_dyn_lp_fx; - move16(); - } - } - - /*thr1 = nk * lp_snr + nc*1.0 + nv * ( st->Etot_v_h2 - nv_ofs); */ /* Linear function for noisy speech */ - - L_tmp = L_shl(L_mult(sub(st_fx->Etot_v_h2_fx, nv_ofs), nv ),7); /* Q8+Q8+1 +7 --> Q24 */ - L_tmp = L_mac(L_tmp, nc, (Word16)32767); /* Q8+Q15+1 = Q24 */ - thr1 = mac_r(L_tmp, lp_snr, nk ); /* Q8+Q15+1 - 16 --> Q8 */ - - - IF (sub(lp_snr, (Word16)20*(1<<8)) > 0 ) /* if (lp_snr > 20.0f )*/ - { - /* thr1 = thr1 + 0.3f * (lp_snr - 20.0f); */ - thr1 = add(thr1, mult(9830, sub(lp_snr,(Word16) 20*(1<<8) ))); /* Q15*Q8+1 -16 --> Q8 */ - - test(); - test(); - test(); - if( sub(st_fx->max_band_fx,16) == 0 - && sub(lp_snr,40*256) > 0 - && sub(thr1,6600) > 0 - && sub(st_fx->lp_speech_fx,11520) < 0 ) - { - thr1 = 6600; - } - } - - - - - /*---------------------------------------------------------------------* - * WB input - * SNR threshold computing - * Hangover control & final VAD decision - *---------------------------------------------------------------------*/ - - IF( sub(vad_bwidth_fx, NB) != 0 ) - { - - /* Outlier Detection first calculates thr1_ol and snr_sum_ol instead of - modyfying thr1 and snr_sum */ - - thr1_ol = thr1; - move16(); - hangover_short = 3; - move16(); - - IF( sub(lp_snr,th_clean) < 0 ) - { - hangover_short = 4; - move16(); - - /* In this section the modified nk, and nc are used */ - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - IF( ( (sub(snr_outlier_index, 4) <= 0) && (sub(st_fx->last_coder_type_fx, UNVOICED) > 0) && ( st_fx->Opt_SC_VBR_fx != 0 ) ) || - ( (sub(snr_outlier_index, 4) <= 0) && (sub(st_fx->last_7k2_coder_type_fx, UNVOICED) > 0) && ( st_fx->Opt_SC_VBR_fx == 0 ) ) ) - - - { - thr1_ol = sub(thr1_ol,(Word16)(1<<8)); /*thr1_ol = thr1 - 1.0f ; */ - /*snr_sum_ol = 10.0f * (float)log10( st_fx->L_snr_sum_vad_fx );*/ - snr_sum_ol = vad_snr_log_fx(st_fx->L_snr_sum_vad_fx, LG10); /* snr in Q8 */ - - } - ELSE IF ( ((sub(st_fx->last_coder_type_fx, UNVOICED) <= 0) && (L_sub(L_snr_outlier,MAX_SNR_OUTLIER_2_FX) < 0) && (st_fx->Opt_SC_VBR_fx != 0) ) || - ((sub(st_fx->last_7k2_coder_type_fx, UNVOICED) <= 0) && (L_sub(L_snr_outlier,MAX_SNR_OUTLIER_2_FX) < 0) && ( st_fx->Opt_SC_VBR_fx == 0 ) ) ) - - { - /* thr1_ol = thr1 + (float)(1.0f - 0.04f * snr_outlier); */ - L_tmp2 = Msub_32_16( (Word32)(1<<(24-16)), L_snr_outlier, 20972 ); /* (1.0)Q24(Q8 in high 32bit word) - Q4*Q19+1 */ - tmp2 = round_fx( L_shl(L_tmp2,16)); /* high word is in Q8 */ - thr1_ol = add(thr1_ol, tmp2 ); /* (Q8 , Q8) */ - } - ELSE - { - /*thr1_ol = thr1 + max(0, (float)(0.6f - 0.01f * L_snr_outlier)); */ - thr1_ol = thr1; - move16(); - L_tmp2 = Msub_32_16( (Word32)614 , L_snr_outlier, 20972); /* .6*1024= */ /* 0.6 Q26(Q10 in high word) - Q4*Q21+1 */ - tmp2 = round_fx(L_shl(L_tmp2,14)); /* Q10(high word)+ 14 -16 --> Q8*/ - if(L_tmp2 > 0) - { - thr1_ol = add(thr1_ol, tmp2 ); /* Q24 >>16 + Q8 */ - } - } - } - - /* apply outlier modification */ - snr_sum = snr_sum_ol; - move16(); /*NB s*/ - thr1 = thr1_ol; - move16(); - - /* DTX HANGOVER is in pre_proc_fx() */ - flag_he1 = 0; - move16(); - - IF ( L_sub(L_mssnr, L_vad_thr) > 0 ) - { - flag_he1 = 1; - move16(); /* he1 primary decision */ - st_fx->nb_active_frames_he1_fx = add(st_fx->nb_active_frames_he1_fx,1); /* Counter of consecutive active speech frames */ - - IF ( sub(st_fx->nb_active_frames_he1_fx,ACTIVE_FRAMES_FX) >= 0 ) - { - st_fx->nb_active_frames_he1_fx = ACTIVE_FRAMES_FX; - move16(); - st_fx->hangover_cnt_he1_fx = 0; - move16(); /* Reset the counter of hangover frames after at least "active_frames" speech frames */ - } - - /* inside HO period */ - test(); - if ( sub(st_fx->hangover_cnt_he1_fx, HANGOVER_LONG_HE_FX < 0) && st_fx->hangover_cnt_he1_fx != 0 ) - { - st_fx->hangover_cnt_he1_fx = add(st_fx->hangover_cnt_he1_fx ,1); - } - - if ( st_fx->soft_hangover_fx > 0 ) - { - st_fx->soft_hangover_fx = sub(st_fx->soft_hangover_fx ,1); - } - } - ELSE - { - /* Reset the counter of speech frames necessary to start hangover algorithm */ - st_fx->nb_active_frames_he1_fx = 0; - move16(); - } - - - - - IF ( sub(st_fx->voiced_burst_fx, 3) > 0 ) - { - IF ( sub(st_fx->bcg_flux_fx, 640) < 0 ) /* Q4 */ - { - st_fx->soft_hangover_fx = hangover_sf_tbl_fx[add(snr_idx,3)]; - move16(); - } - ELSE - { - st_fx->soft_hangover_fx = hangover_sf_tbl_fx[snr_idx]; - move16(); - } - } - - - hangover_hd = hangover_hd_tbl_fx[snr_idx]; - move16(); - - IF ( sub(st_fx->bcg_flux_fx, 640) < 0 ) - { - hangover_hd = add(shr(hangover_hd,1), 1); - move16(); - } - - /* VAD hangover for he1 */ - test(); - IF ( flag_he1 == 0 && st_fx->soft_hangover_fx > 0 ) - { - IF ( L_sub(L_mssnr_hov, L_vad_thr) > 0 ) - { - flag_he1 = 1; - move16(); - st_fx->soft_hangover_fx=sub(st_fx->soft_hangover_fx,1); - } - ELSE - { - st_fx->soft_hangover_fx=0; - move16(); - } - - if( st_fx->soft_hangover_fx < 0) - { - st_fx->soft_hangover_fx=0; - move16(); - } - } - - test(); - test(); - IF ( (flag_he1 == 0) - && (sub(st_fx->hangover_cnt_he1_fx, hangover_hd) < 0 ) - && (st_fx->soft_hangover_fx == 0 ) ) - { - flag_he1 = 1; - move16(); - st_fx->hangover_cnt_he1_fx = add(st_fx->hangover_cnt_he1_fx,1); - } - - - - /* Calculate background stationarity */ - test(); - IF ( flag_he1 == 0 && st_fx->first_noise_updt_fx > 0 ) - { - IF ( sub(snr_sumt, st_fx->bcg_flux_fx) > 0 ) - { - IF ( st_fx->bcg_flux_init_fx-- > 0 ) - { - IF ( sub(snr_sumt,add(st_fx->bcg_flux_fx,800)) > 0 ) - { - /*st->bcg_flux = 0.9f * st->bcg_flux + (1-0.9f)*(st->bcg_flux+50);*/ - st_fx->bcg_flux_fx = mac_r(L_mult(st_fx->bcg_flux_fx,29491),add(st_fx->bcg_flux_fx,800),3277); /*Q4 */ - } - ELSE - { - /*st->bcg_flux = 0.9f * st->bcg_flux + (1-0.9f)*snr_sumt*/ - st_fx->bcg_flux_fx = mac_r(L_mult(st_fx->bcg_flux_fx,29491),snr_sumt,3277); /*Q4 */ - } - } - ELSE - { - IF ( sub(snr_sumt,add(st_fx->bcg_flux_fx,160)) > 0 ) - { - /*st->bcg_flux = 0.99f * st->bcg_flux + (1-0.99f)*(st->bcg_flux+10);*/ - st_fx->bcg_flux_fx = mac_r(L_mult(st_fx->bcg_flux_fx,32440),add(st_fx->bcg_flux_fx,160),328); /*Q4 */ - } - ELSE - { - /*st->bcg_flux = 0.99f * st->bcg_flux + (1-0.99f)*snr_sumt;*/ - st_fx->bcg_flux_fx = mac_r(L_mult(st_fx->bcg_flux_fx,32440),snr_sumt,328); /*Q4 */ - } - } - } - ELSE - { - IF ( st_fx->bcg_flux_init_fx-- > 0 ) - { - IF ( sub(snr_sumt,sub(st_fx->bcg_flux_fx,480)) < 0 ) - { - /*st->bcg_flux = 0.95f * st->bcg_flux + (1-0.95f)*(st->bcg_flux-30);*/ - st_fx->bcg_flux_fx = mac_r(L_mult(st_fx->bcg_flux_fx,31130),sub(st_fx->bcg_flux_fx,480),1638); /*Q4 */ - } - ELSE - { - /*st->bcg_flux = 0.95f * st->bcg_flux + (1-0.95f)*snr_sumt;*/ - st_fx->bcg_flux_fx = mac_r(L_mult(st_fx->bcg_flux_fx,31130),snr_sumt,1638); /*Q4 */ - } - } - ELSE - { - IF ( sub(snr_sumt,sub(st_fx->bcg_flux_fx,160)) < 0 ) - { - /*st->bcg_flux = 0.9992f * st->bcg_flux + (1-0.9992f)*(st->bcg_flux-10);*/ - st_fx->bcg_flux_fx = mac_r(L_mult(st_fx->bcg_flux_fx,32742),sub(st_fx->bcg_flux_fx,160),26); /*Q4 */ - } - ELSE - { - /*st->bcg_flux = 0.9992f * st->bcg_flux + (1-0.9992f)*snr_sumt;*/ - st_fx->bcg_flux_fx = mac_r(L_mult(st_fx->bcg_flux_fx,32742),snr_sumt,26); /*Q4 */ - } - } - } - - st_fx->bcg_flux_init_fx = s_max(st_fx->bcg_flux_init_fx,0); - } - - flag = 0; - move16(); - *localVAD = 0; - move16(); - /* if ( snr_sum > thr1 && flag_he1 == 1 ) *//* Speech present */ - test(); - - IF ( (sub(snr_sum, thr1) > 0) && (sub(flag_he1,1) == 0)) /* Speech present */ - { - flag = 1; - move16(); - *localVAD = 1; - move16(); - - st_fx->nb_active_frames_fx = add(st_fx->nb_active_frames_fx,1); /* Counter of consecutive active speech frames */ - - IF ( sub(st_fx->nb_active_frames_fx,ACTIVE_FRAMES_FX) >= 0 ) - { - st_fx->nb_active_frames_fx = ACTIVE_FRAMES_FX; - move16(); - st_fx->hangover_cnt_fx = 0; - move16(); /* Reset the counter of hangover frames after at least "active_frames" speech frames */ - } - - /* inside HO period */ - test(); - if( sub(st_fx->hangover_cnt_fx,HANGOVER_LONG_FX) < 0 - && st_fx->hangover_cnt_fx != 0 ) - { - st_fx->hangover_cnt_fx = add(st_fx->hangover_cnt_fx,1); - } - } - ELSE - { - /* Reset the counter of speech frames necessary to start hangover algorithm */ - st_fx->nb_active_frames_fx = 0; - move16(); - - if( sub(st_fx->hangover_cnt_fx,HANGOVER_LONG_FX) < 0 ) /* inside HO period */ - { - st_fx->hangover_cnt_fx = add(st_fx->hangover_cnt_fx,1); - } - - - IF( sub(st_fx->hangover_cnt_fx, hangover_short) <= 0 ) /* "hard" hangover */ - { - test(); - test(); - if ( (sub(lp_snr,th_clean) < 0) - && (st_fx->Opt_SC_VBR_fx != 0 ) - && (sub(st_fx->hangover_cnt_fx, 2) >= 0) ) - { - *noisy_speech_HO = 1; - move16(); - } - test(); - test(); - if ( (sub(lp_snr,th_clean) >= 0) - && (st_fx->Opt_SC_VBR_fx != 0 ) - && (sub(st_fx->hangover_cnt_fx, 2) >= 0) ) - { - *clean_speech_HO = 1; - move16(); - } - flag = 1; - move16(); /*HO*/ - } - } - - - /* localVAD and vad_flag for HE-SAD - in parallel with normal localVAD and vad_flag */ - - *localVAD_HE_SAD = 0; - move16(); - - test(); - IF ( (sub(snr_sum_HE_SAD, thr1) > 0) - && (sub(flag_he1, 1) == 0) ) /* Speech present */ - { - - *localVAD_HE_SAD = 1; - move16(); - } - } /* end of WB SWB */ - - /*---------------------------------------------------------------------* - * NB input - * SNR threshold computing - * Hangover control & final VAD decision - *---------------------------------------------------------------------*/ - - ELSE /* NB input */ - { - /* Add localVAD_HE_SAD also for NB operation for use with speech music classifier */ - *localVAD_HE_SAD = 0; - move16(); - if (sub(snr_sum_HE_SAD, thr1) > 0 ) - { - *localVAD_HE_SAD = 1; - move16(); - } - - *localVAD = 0; - move16(); /* safety inits for fx */ - IF ( sub(snr_sum,thr1) > 0 ) /* Speech present, possibly in hangover */ - { - st_fx->nb_active_frames_fx = add(st_fx->nb_active_frames_fx,1); /* Counter of consecutive active speech frames */ - IF ( sub(st_fx->nb_active_frames_fx,ACTIVE_FRAMES_FX) >= 0 ) - { - st_fx->nb_active_frames_fx = ACTIVE_FRAMES_FX; - move16(); - st_fx->hangover_cnt_fx = 0; - move16();/* Reset the counter of hangover frames after at least "active_frames" speech frames */ - } - - *localVAD = 1; - move16(); - } - ELSE - { - st_fx->nb_active_frames_fx = 0; - move16(); /* Reset the counter of speech frames necessary to start hangover algorithm */ - /* *localVAD = 0; move16(); */ /* set above */ - } - - thr1_nb_mod = thr1; - move16(); /* thr1 may be adjusted after this point */ - IF( sub(st_fx->hangover_cnt_fx,HANGOVER_LONG_NB_FX) < 0) - { - st_fx->hangover_cnt_fx = add(st_fx->hangover_cnt_fx,1); - - IF( sub(lp_snr, 4864 ) < 0) /*19.0f Q8*/ /* very low SNR */ - { - thr1_nb_mod = sub(thr1_nb_mod , 1331); /*thr1 -= 5.2f;*/ - } - ELSE IF( sub(lp_snr, 8960) < 0 ) /*35 in Q8 */ /* low SNR */ - { - thr1_nb_mod = sub(thr1_nb_mod , 512); /*thr1 -= 2.0f;*/ - } - } - - - thr2 = sub(thr1_nb_mod, 384); /*thr2 = thr1 - 1.5f; , clean speech */ - - /* -dtx condition dependency in noisy speech */ - tmp = 333; - move16(); /* 1.3f; */ - if ( st_fx->Opt_DTX_ON_fx == 0 ) - { - tmp = 282; - move16(); /* 1.10f; */ - } - if (sub(lp_snr,th_clean) < 0) - { - thr2 = sub(thr1_nb_mod, tmp); /*thr2 = thr1 - [ 1.10 || 1.3 ];*/ - } - - - flag = 0; - move16(); - IF ( sub(snr_sum, thr1_nb_mod) > 0 ) /* Speech assumed present, even though lowered thr1 */ - { - flag = 1; - move16(); - } - - - - test(); - IF ( (sub(snr_sum, thr1_nb_mod) < 0) - && (sub(snr_sum, thr2) > 0) ) /* Speech present */ - { - flag = 1; - move16(); - *localVAD = 0; - move16(); - *NB_speech_HO = 1; - move16(); - } - thr1 = thr1_nb_mod ; - move16(); /* needed for st_fx->vadnoise_fx update below */ - } /* end of NB */ - - - - /* *flag_noisy_speech_snr is a Word8 parameter */ - *flag_noisy_speech_snr = 0; - move16(); - IF( vad_bwidth_fx != NB ) - { - if(sub(lp_snr, TH16_2_NFLAG_FX ) < 0 ) /*now 27, original threshold: 35dB*/ - { - *flag_noisy_speech_snr = 1; - move16(); - } - } - ELSE - { - if(sub(lp_snr, TH8_1_NFLAG_FX ) < 0 ) /* now 20.0 */ - { - *flag_noisy_speech_snr = 1; - move16(); - } - } - - /* SC-VBR */ - st_fx->vadsnr_fx = snr_sum; - move16(); /* for ppp, voiced_enc */ - st_fx->vadnoise_fx = thr1; - move16(); /* used in nb for find_uv */ - - /* Updates */ - st_fx->prim_act_quick_fx = mult_r(26214,st_fx->prim_act_quick_fx); /*Q15 */ - - if(*localVAD != 0) - { - st_fx->prim_act_quick_fx = add(6554,st_fx->prim_act_quick_fx ); /*Q15 */ - } - - st_fx->prim_act_slow_fx = mult_r(32440,st_fx->prim_act_slow_fx); /*Q15 */ - - if(*localVAD != 0) - { - st_fx->prim_act_slow_fx = add(328, st_fx->prim_act_slow_fx ); /*Q15 */ - } - - tmp = st_fx->prim_act_slow_fx; - move16(); - if (sub(st_fx->prim_act_quick_fx,st_fx->prim_act_slow_fx) <= 0) - { - tmp=st_fx->prim_act_quick_fx; - move16(); - } - /*st->prim_act = 0.1f * tmp + (1.0f-0.1f)* st->prim_act;*/ - st_fx->prim_act_fx = mac_r(L_mult(3277,tmp),29491,st_fx->prim_act_fx); - - - - st_fx->prim_act_quick_he_fx = mult_r(26214,st_fx->prim_act_quick_he_fx); /*Q15 */ - if(*localVAD_HE_SAD != 0) - { - st_fx->prim_act_quick_he_fx = add(6554,st_fx->prim_act_quick_he_fx ); /*Q15 */ - } - - st_fx->prim_act_slow_he_fx = mult_r(32440,st_fx->prim_act_slow_he_fx); /*Q15 */ - if(*localVAD_HE_SAD != 0) - { - st_fx->prim_act_slow_he_fx = add(328, st_fx->prim_act_slow_he_fx ); /*Q15 */ - } - - tmp = st_fx->prim_act_slow_he_fx; - move16(); - if (sub(st_fx->prim_act_quick_he_fx,st_fx->prim_act_slow_he_fx) <= 0) - { - tmp = st_fx->prim_act_quick_he_fx; - move16(); - } - st_fx->prim_act_he_fx = mac_r(L_mult(3277,tmp),29491,st_fx->prim_act_he_fx); - - - if (L_and(st_fx->L_vad_flag_reg_H_fx, (Word32) 0x40000L) != 0) /* 0x4000L = 0x01L << 18 */ - { - st_fx->vad_flag_cnt_50_fx = sub(st_fx->vad_flag_cnt_50_fx,1); - } - - st_fx->L_vad_flag_reg_H_fx = L_shl(L_and(st_fx->L_vad_flag_reg_H_fx, (Word32) 0x3fffffffL ), 1); - - - if (L_and(st_fx->L_vad_flag_reg_L_fx, (Word32) 0x40000000L) != 0) - { - st_fx->L_vad_flag_reg_H_fx = L_or(st_fx->L_vad_flag_reg_H_fx, 0x01L); - } - - st_fx->L_vad_flag_reg_L_fx = L_shl(L_and(st_fx->L_vad_flag_reg_L_fx, (Word32) 0x3fffffffL ), 1); - - - IF ( flag != 0 ) /* should not include the extra DTX hangover */ - { - st_fx->L_vad_flag_reg_L_fx = L_or(st_fx->L_vad_flag_reg_L_fx, 0x01L); - st_fx->vad_flag_cnt_50_fx = add(st_fx->vad_flag_cnt_50_fx, 1); - } - - - if (L_and(st_fx->L_vad_prim_reg_fx, (Word32) 0x8000L) != 0) /* 0x8000L = 1L << 15 */ - { - st_fx->vad_prim_cnt_16_fx = sub(st_fx->vad_prim_cnt_16_fx,1); - } - - st_fx->L_vad_prim_reg_fx = L_shl(L_and(st_fx->L_vad_prim_reg_fx, (Word32) 0x3fffffffL ), 1); - - IF ( *localVAD != 0 ) - { - st_fx->L_vad_prim_reg_fx = L_or(st_fx->L_vad_prim_reg_fx, 0x01L); - st_fx->vad_prim_cnt_16_fx = add(st_fx->vad_prim_cnt_16_fx,1); - } - - return flag; -} - - - - diff --git a/src/libs/libevs/lib_enc/vad_param_updt.cpp b/src/libs/libevs/lib_enc/vad_param_updt.cpp new file mode 100644 index 00000000..417d427c --- /dev/null +++ b/src/libs/libevs/lib_enc/vad_param_updt.cpp @@ -0,0 +1,118 @@ +/*==================================================================================== + EVS Codec 3GPP TS26.443 Nov 13, 2018. Version 12.11.0 / 13.7.0 / 14.3.0 / 15.1.0 + ====================================================================================*/ + +#include +#include +#include "options.h" +#include "cnst.h" +#include "prot.h" + +/*-------------------------------------------------------------------* + * vad_param_updt() + * + * Update parameters used by the VAD or DTX + *--------------------------------------------------------------------*/ + +void vad_param_updt( + Encoder_State *st, /* i/o: encoder state structure */ + const short pitch[3], /* i : open loop pitch lag for each half-frame */ + const float voicing[3], /* i : maximum normalized correlation for each half-frame */ + const float corr_shift, /* i : correlation shift */ + const float A[] /* i : A(z) unquantized for the 4 subframes */ +) +{ + float refl[M+1]; + short tmp_active_flag; + + + if( !st->Opt_AMR_WB ) + { + /* fix explanation: after function dtx_fx, the "vad_flag" + parameter can not be used for SID scheduling purposes any + longer as dtx_fx can schedules active frames even if the + initial analyzed vad_flag is 0 ) in the worst case without + the fix an active frame could be classified as SID frame, + quite/very unlikley though + */ + tmp_active_flag = 0; + + if( (st->core_brate != SID_2k40) && (st->core_brate != 0) ) /* Note, core_brate_fx can be -1 */ + { + tmp_active_flag = 1; ; /* requires active coding according to dtx_fx logic */ + } + + if( st->Opt_DTX_ON != 0 && tmp_active_flag == 0 && st->ini_frame > 3) + + { + /* update the counter of consecutive inactive frames in DTX */ + st->consec_inactive++; + if( st->consec_inactive > 5 ) + { + st->consec_inactive = 5; + } + + if( st->consec_inactive == 5 ) + { + /* compute spectral tilt parameter */ + a2rc( &A[1], refl, M ); + + if( st->spectral_tilt_reset == 1 ) + { + st->spectral_tilt_reset = 0; + st->running_avg = refl[0]; + st->ra_deltasum = 0; + } + + st->ra_deltasum += (0.80f * st->running_avg + 0.20f * refl[0]) - st->running_avg; + st->running_avg = 0.80f * st->running_avg + 0.20f * refl[0]; + + if( fabs(st->ra_deltasum) > 0.2f ) + { + st->spectral_tilt_reset = 1; + st->running_avg = 0; + st->ra_deltasum = 0; + st->trigger_SID = 1; + } + } + } + else + { + st->trigger_SID = 0; + st->consec_inactive = 0; + } + + if( st->trigger_SID == 1 ) + { + if( st->cng_cnt >= 8 ) + { + /* Declare SID frame due to spectral tilt changes */ + st->cnt_SID = 1; + st->core_brate = SID_2k40; + st->trigger_SID = 0; + } + else if ( st->core_brate == SID_2k40 ) + { + /* SID fame has already been declared before */ + st->trigger_SID = 0; + } + } + } + + + if( (voicing[0] + voicing[1] + voicing[2]) / 3 + corr_shift > 0.65 && + (short)(abs(pitch[0] - st->pitO) + abs(pitch[1] - pitch[0]) + abs(pitch[2] - pitch[1])) / 3 < 14 ) + { + (st->voiced_burst)++; + } + else + { + st->voiced_burst = 0; + } + + /* Update previous voicing value for next frame use */ + st->voicing_old = (voicing[0] + voicing[1] + voicing[2]) / 3 + corr_shift; + + return; +} + diff --git a/src/libs/libevs/lib_enc/vad_param_updt_fx.cpp b/src/libs/libevs/lib_enc/vad_param_updt_fx.cpp deleted file mode 100755 index 3ed21e5d..00000000 --- a/src/libs/libevs/lib_enc/vad_param_updt_fx.cpp +++ /dev/null @@ -1,177 +0,0 @@ -/*==================================================================================== - EVS Codec 3GPP TS26.442 Apr 03, 2018. Version 12.11.0 / 13.6.0 / 14.2.0 - ====================================================================================*/ - -#include -#include "options.h" /* Compilation switches */ -#include "cnst_fx.h" /* Common constants */ -#include "prot_fx.h" /* Function prototypes */ -#include "stl.h" - -/*-------------------------------------------------------------------* - * vad_param_updt() - * - * Update parameters used by VAD - *--------------------------------------------------------------------*/ - -void vad_param_updt_fx( - Encoder_State_fx *st_fx, /* i/o: state structure */ - Word16 pitch[3], /* i : open loop pitch lag for each half-frame Q0*/ - Word16 voicing[3], /* i : maximum normalized correlation for each half-frame Q15*/ - Word16 corr_shift, /* i : correlation shift Q15*/ - Word16 vad_flag, /* i : vad flag Q0*/ - const Word16 Az[] /* i: a coeffs Q12 */ - -) -{ - Word16 voice_tmp, pitch_tmp; - Word32 L_tmp; - - - Word16 refl[M+1]; - Word16 tmp1,tmp2; - Word16 tmp_active_flag; - - IF( !st_fx->Opt_AMR_WB_fx ) - { - /* fix explanation - , after function dtx_fx, the "vad_flag" parameter can not be used for SID scheduling purposes any longer - as dtx_fx can schedules active frames even if the initial analyzed vad_flag is 0 ) - in the worst case without the fix an active frame could be classified as SID frame, quite/very unlikley though - */ - tmp1 = vad_flag; - move16(); /* kill MSVC warning */ - tmp_active_flag = 0; - move16(); - test(); - if( (L_sub(st_fx->core_brate_fx, (Word32)SID_2k40) != 0) && (st_fx->core_brate_fx != 0) ) /* Note, core_brate_fx can be -1 */ - { - tmp_active_flag = 1; - move16(); /* reqires active coding according to dtx_fx logic */ - } - test(); - test(); - IF( (st_fx->Opt_DTX_ON_fx != 0) && (tmp_active_flag == 0) && ( sub(st_fx->ini_frame_fx,3) > 0) ) - - - { - /* update the counter of consecutive inactive frames in DTX */ - st_fx->consec_inactive_fx = add(st_fx->consec_inactive_fx,1); - IF( sub(st_fx->consec_inactive_fx,5) > 0 ) - { - st_fx->consec_inactive_fx = 5; - move16(); - } - - IF( sub(st_fx->consec_inactive_fx,5) == 0 ) - { - /* compute spectral tilt parameter */ - a2rc_fx( &Az[1], refl, M ); /* cast to kill MSVC warning */ - /* i: Az in Q12 */ - /* o: refl in Q15 */ - - IF( sub(st_fx->spectral_tilt_reset_fx,1) == 0 ) - { - st_fx->spectral_tilt_reset_fx = 0; - move16(); - st_fx->running_avg_fx = refl[0]; - move16(); /*Q15*/ - st_fx->ra_deltasum_fx = 0; - move16(); /*Q15*/ - } - - /* st_fx->ra_deltasum_fx += (0.80f * st_fx->running_avg_fx + 0.20f * refl[0]) - st_fx->running_avg_fx; - st_fx->running_avg_fx = 0.80f * st_fx->running_avg_fx + 0.20f * refl[0]; */ - tmp1 = mult(6553, st_fx->running_avg_fx); /* = -0.80f * st_fx->running_avg_fx + st_fx->running_avg_fx*/ - tmp2 = mult(6553, refl[0]); - st_fx->ra_deltasum_fx = add(st_fx->ra_deltasum_fx, sub(tmp2,tmp1)); - move16(); - - tmp1 = mult(26214, st_fx->running_avg_fx); - st_fx->running_avg_fx = add(tmp1,tmp2); - move16(); - - IF( sub(abs_s(st_fx->ra_deltasum_fx), 6553) > 0 ) /*0.2 in Q15*/ - { - st_fx->spectral_tilt_reset_fx = 1; - move16(); - st_fx->running_avg_fx = 0; - move16(); - st_fx->ra_deltasum_fx = 0; - move16(); - st_fx->trigger_SID_fx = 1; - move16(); - } - } - } - ELSE - { - st_fx->trigger_SID_fx = 0; - move16(); - st_fx->consec_inactive_fx = 0; - move16(); - } - - IF( st_fx->trigger_SID_fx == 1 ) - { - IF( st_fx->cng_cnt_fx >= 8 ) - { - /* Declare SID frame due to spectral tilt changes */ - st_fx->cnt_SID_fx = 1; - move16(); - st_fx->core_brate_fx = SID_2k40; - move16(); - st_fx->trigger_SID_fx = 0; - move16(); - } - ELSE IF ( st_fx->core_brate_fx == SID_2k40 ) - { - /* SID fame has already been declared before */ - st_fx->trigger_SID_fx = 0; - move16(); - } - } - } - - - - /* (voicing[0] + voicing[1] + voicing[2]) / 3 + corr_shift */ - L_tmp = L_mult(voicing[0], 10923); - L_tmp = L_mac(L_tmp, voicing[1], 10923); - L_tmp = L_mac(L_tmp, voicing[2], 10923); /*Q15 */ - L_tmp = L_mac(L_tmp, corr_shift, 32767); /*Q15 */ - voice_tmp = round_fx(L_tmp); /*Q15 */ - - /* abs(pitch[0] - *pitO) + abs(pitch[1] - pitch[0]) + abs(pitch[2] - pitch[1]) */ - pitch_tmp = abs_s(sub(pitch[0],st_fx->pitO_fx)); /*Q0 */ - pitch_tmp = add(pitch_tmp,abs_s(sub(pitch[1],pitch[0]))); /*Q0 */ - pitch_tmp = add(pitch_tmp,abs_s(sub(pitch[2],pitch[1]))); /*Q0 */ - - - /* if( (voicing[0] + voicing[1] + voicing[2]) / 3 + corr_shift > 0.65 && - (short)(abs(pitch[0] - st->pitO) + abs(pitch[1] - pitch[0]) + abs(pitch[2] - pitch[1])) / 3 < 14 ) - { - (st->voiced_burst)++; - } else { - st->voiced_burst = 0; - } */ - - st_fx->voiced_burst_fx = add( st_fx->voiced_burst_fx,1); - move16(); - test(); - if ( ( sub(voice_tmp,21299) <= 0 ) /* 0.65 in Q15 */ - || ( sub(pitch_tmp,42) >= 0 ) ) /*3*14 = 42 Q0 */ - { - st_fx->voiced_burst_fx = 0; - move16(); - } - - /* Update previous voicing value for next frame use */ - /* st->voicing_old = (voicing[0] + voicing[1] + voicing[2]) / 3 + corr_shift; */ - st_fx->voicing_old_fx = voice_tmp; - move16(); - - - - return; -} diff --git a/src/libs/libevs/lib_enc/vad_proc.cpp b/src/libs/libevs/lib_enc/vad_proc.cpp old mode 100755 new mode 100644 index 6c84544d..173fad0f --- a/src/libs/libevs/lib_enc/vad_proc.cpp +++ b/src/libs/libevs/lib_enc/vad_proc.cpp @@ -1,168 +1,110 @@ /*==================================================================================== - EVS Codec 3GPP TS26.442 Apr 03, 2018. Version 12.11.0 / 13.6.0 / 14.2.0 + EVS Codec 3GPP TS26.443 Nov 13, 2018. Version 12.11.0 / 13.7.0 / 14.3.0 / 15.1.0 ====================================================================================*/ - +#include #include #include #include #include +#include "prot.h" +#include "rom_enc.h" -#include "basop_util.h" -#include "stl.h" -#include "vad_basop.h" -#include "prot_fx.h" -#include "stat_enc_fx.h" -#include "rom_enc_fx.h" -Word16 vad_init(T_CldfbVadState *vad_state) +/*-------------------------------------------------------------------* + * vad_init() + * + * + *-------------------------------------------------------------------*/ + +short vad_init( + T_CldfbVadState *st +) { - Word16 i = 0; + float sSFM[SFM_NUM]= {0.88f,0.92f,0.92f}; + short i = 0; - IF(vad_state == NULL) + if(st == NULL) { return -1; } - vad_state->frameloop=0; - move16(); - vad_state->continuous_noise_num = 0; - move16(); - vad_state->continuous_speech_num = 0; - move16(); - vad_state->continuous_speech_num2 = 0; - move16(); - vad_state->fg_energy_est_start = L_deposit_l(0); - vad_state->speech_flag = 0; - move16(); - vad_state->frame_sb_energy_scale = 0; - move16(); - vad_state->updateNumWithSnr=0; - move16(); - vad_state->update_count = 0; - move16(); - vad_state->warm_hang_num = 0; - move16(); - - FOR(i = 0; i < SPEC_AMP_NUM; i++) + st->frameloop = 0; + st->lt_snr_org = 1.0f; + st->lf_snr_smooth = 5.0f; + st->l_silence_snr = 0.5f; + st->l_speech_snr = 5.0f; + st->l_silence_snr_count = 1; + st->l_speech_snr_count = 1; + st->fg_energy = 16*(3.0518e-5f); + st->bg_energy = 16*(4.6566e-10f); + st->fg_energy_count = 16; + st->bg_energy_count = 16; + st->tonality_rate3 = 0.46f; + st->music_background_rate = 0.46f; + st->lt_noise_sp_center_diff_sum = 0.4f; + st->lt_noise_sp_center_diff_counter = 4; + st->lt_noise_sp_center0 = 1.8f; + st->lt_noise_sp_center3 = 2.0f; + st->lt_bg_highf_eng = 2.0f; + st->t_bg_energy = 0.01f; + st->t_bg_energy_sum = 0.01f; + st->tbg_energy_count = 1; + st->bg_update_count = 0; + st->frame_energy_smooth = 1.0f; + st->fg_energy_est_start = 0; + st->speech_flag = 0; + st->continuous_noise_num = 0; + st->continuous_speech_num = 0; + st->continuous_speech_num2 = 0; + st->update_num_with_snr = 0; /* the number of the background update with SNR*/ + st->update_count = 0; + st->warm_hang_num = 0; + for(i = 0; i < PRE_SNR_NUM; i++) { - vad_state->smooth_spec_amp[i] = L_deposit_l(0); + st->pre_snr[i] = 0.0f; } - FOR(i = 0; i < PRE_SNR_NUM; i++) + for(i = 0; i < POWER_NUM; i++) { - vad_state->pre_snr[i] = L_deposit_l(0); + st->frames_power[i] = 0; } - FOR(i = 0; i < BG_ENG_NUM; i++) + for(i = 0; i < SPEC_AMP_NUM; i++) { - vad_state->frame_sb_energy[i] = L_deposit_l(0); + st->smooth_spec_amp[i] = 0; } - vad_state->sfm[0] = 28835/* 0.88 Q15 */; - move16(); - vad_state->sfm[1] = 30146/* 0.92 Q15 */; - move16(); - vad_state->sfm[2] = 30146/* 0.92 Q15 */; - move16(); - vad_state->l_silence_snr_count = L_deposit_l(1); - vad_state->l_speech_snr_count = L_deposit_l(1); - vad_state->lt_snr_org = 33554432; - move32(); - vad_state->lf_snr_smooth = 167772155/* 5.0 Q25 */; - move32(); - vad_state->fg_energy = 1073741824; - move32(); - vad_state->fg_energy_scale = 41; - move16(); - - vad_state->bg_energy = 1073741824; - move32(); - vad_state->bg_energy_scale = 57; - move16(); - vad_state->lt_noise_sp_center_diff_counter = L_deposit_l(4); - - vad_state->t_bg_energy = 1374389535; - move32(); - vad_state->scale_t_bg_energy = 37; - move16(); - - vad_state->t_bg_energy_sum.s16Exp = 37; - move16(); - vad_state->t_bg_energy_sum.s32Mantissa = 1374389535; - move32(); - vad_state->tbg_energy_count = 1; - move16(); - vad_state->fg_energy_count = 16; - move16(); - vad_state->bg_energy_count = 16; - move16(); - - vad_state->bg_update_count = 0; - move16(); - vad_state->frame_energy_smooth = 1073741824; - move32(); - vad_state->frame_energy_smooth_scale = 30; - move16(); - vad_state->Q_frames_power_32 = 31; - move16(); - vad_state->lt_bg_highf_eng = 131070/* 2.0 Q16 */; - move16(); - vad_state->lt_noise_sp_center0 = 1841/* 0.4 Q10 */; - move16(); - vad_state->lt_noise_sp_center3 = 2046/* 0.4 Q10 */; - move16(); - vad_state->music_background_rate = 15073/* 0.46 Q15 */; - move16(); - vad_state->tonality_rate3 = 15073/* 0.46 Q15 */; - move16(); - vad_state->lt_noise_sp_center_diff_sum = 409/* 0.4 Q10 */; - move32(); - vad_state->l_silence_snr = 32768/* 0.5 Q16 */; - move32(); - vad_state->l_speech_snr = 327675/* 5.0 Q16 */; - move32(); - - FOR(i = 0; i < SP_CENTER_NUM; i++) + for(i = 0; i < SFM_NUM; i++) { - vad_state->sp_center[i] = 1228/* 1.2 Q10 */; - move16(); + st->sfm[i] = sSFM[i]; } - FOR(i = 0; i < STABLE_NUM; i++) + for(i = 0; i < SP_CENTER_NUM; i++) { - vad_state->ltd_stable_rate[i] = 2294/* 0.07 Q15 */; - move16(); + st->sp_center[i] = 1.2f; } - FOR(i = 0; i < BG_ENG_NUM; i++) + for(i = 0; i < STABLE_NUM; i++) { - vad_state->sb_bg_energy[i] =1374389535; - move32(); + st->ltd_stable_rate[i] = 0.07f; } - vad_state->sb_bg_energy_scale = 37; - move16(); - vad_state->f_tonality_rate[0] = 7864/* 0.48 Q14 */; - move16(); - vad_state->f_tonality_rate[1] = 7864/* 0.48 Q14 */; - move16(); - vad_state->f_tonality_rate[2] = 7864/* 0.48 Q14 */; - move16(); - - - FOR(i = 0; i < PRE_SPEC_DIF_NUM; i++) + for(i = 0; i < BG_ENG_NUM; i++) { - vad_state->pre_spec_low_dif[i] = 4095; - move16(); + st->sb_bg_energy[i] = 0.01f; + st->frame_sb_energy[i] = 0.001f; } - vad_state->scale_spec_low_dif = 12; - move16(); - FOR (i = 0; i < 56; i++) + for(i = 0; i < TONA_NUM; i++) { - vad_state->frames_power_32[i] = L_deposit_l(0); + st->f_tonality_rate[i] = 0.48f; + } + + for(i = 0; i < PRE_SPEC_DIF_NUM; i++) + { + st->pre_spec_low_dif[i] = 1.0f; } @@ -170,284 +112,153 @@ Word16 vad_init(T_CldfbVadState *vad_state) } -void UpdateState(T_CldfbVadState *vad_state, - Word16 vad_flag, - Word32 frame_energy, /*(i) current frame energy*/ - Word16 sacle_sbpower, /*(i) the Scaling of current frame energy*/ - Word32 update_flag, /*(i) current frame update flag*/ - Word16 music_backgound_f, /*(i) backgound music flag*/ - Word32 HB_Power, /*(i) current frame high frequency energy*/ - Word16 HB_Power_Q /*(i) the Scaling of current frame high frequency energy*/ - ,Word32 snr - ) +/*-------------------------------------------------------------------* + * UpdateState() + * + * + *-------------------------------------------------------------------*/ + +static void UpdateState( + T_CldfbVadState *st, + float frame_energy, /*(i) current frame energy */ + float high_eng, /*(i) current frame high frequency energy */ + int update_flag, /*(i) current frame update flag */ + int music_backgound_f, /*(i) background music flag */ + int vad_flag + ,float snr +) { - Word16 lt_bg_energy_scal; - Word32 tmp,tmp2; + st->frame_energy_smooth = st->frame_energy_smooth*0.95f + frame_energy*0.05f; - - tmp = MUL_F(vad_state->frame_energy_smooth, 31129/* 0.95 Q15 */); - tmp2 = MUL_F(frame_energy, 26214); - vad_state->frame_energy_smooth = VAD_L_ADD(tmp, vad_state->frame_energy_smooth_scale, tmp2, add(4, sacle_sbpower), <_bg_energy_scal); - move32(); - vad_state->frame_energy_smooth_scale = lt_bg_energy_scal; - move16(); - - - IF( vad_flag == 0 ) + if(vad_flag==0) { - vad_state->lt_bg_highf_eng = L_add(MUL_F(vad_state->lt_bg_highf_eng, 31130), L_shr(MUL_F(HB_Power, 1638), sub(HB_Power_Q, lt_bg_highf_eng_Q))); + st->lt_bg_highf_eng = st->lt_bg_highf_eng*0.95f + high_eng*0.05f; } - if(sub(vad_state->frameloop, 1000) < 0) + if(st->frameloop<1000) { - vad_state->frameloop = add(vad_state->frameloop, 1); - move16(); + st->frameloop++; } - - background_update(vad_state, - sacle_sbpower, - frame_energy, - update_flag, - music_backgound_f - ,snr - ); - IF( vad_flag== 0) + background_update( st, frame_energy, update_flag, music_backgound_f, snr); + if( vad_flag == 0) { - vad_state->continuous_speech_num2 = 0; - move16(); - IF(sub(vad_state->continuous_noise_num, 10) > 0) - { - vad_state->continuous_speech_num = 0; - move16(); - } - ELSE IF(L_sub(vad_state->continuous_speech_num, 9) > 0) - { - vad_state->continuous_speech_num = 9; - move16(); - } - vad_state->continuous_noise_num = add(vad_state->continuous_noise_num, 1); - move16(); + st->continuous_speech_num2 = 0; - if(sub(vad_state->continuous_noise_num, 2048) > 0) + if(st->continuous_noise_num > 10) { - vad_state->continuous_noise_num = 2048; - move16(); + st->continuous_speech_num = 0; + } + else if (st->continuous_speech_num > 9) + { + st->continuous_speech_num = 9; + } + + st->continuous_noise_num++; + + if(st->continuous_noise_num > 2048) + { + st->continuous_noise_num = 2048; } } - ELSE + else { - vad_state->continuous_noise_num = 0; - move16(); + st->continuous_noise_num = 0; + st->continuous_speech_num2++; + st->continuous_speech_num++; - vad_state->continuous_speech_num2 = add(vad_state->continuous_speech_num2, 1); - vad_state->continuous_speech_num = add(vad_state->continuous_speech_num, 1); - if(sub(vad_state->continuous_speech_num, 2048) > 0) + if(st->continuous_speech_num > 2048) { - vad_state->continuous_speech_num = 2048; - move16(); + st->continuous_speech_num = 2048; } - if(sub(vad_state->continuous_speech_num2, 2048) > 0) + if(st->continuous_speech_num2 > 2048) { - vad_state->continuous_speech_num2 = 2048; - move16(); + st->continuous_speech_num2 = 2048; } } + return; } -Word16 vad_proc(T_CldfbVadState *vad_st, - Word32 realBuffer[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX], /* i: real values */ - Word32 imagBuffer[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX], /* i: imag values */ - Word16 riBuffer_exp, /* i: exponent of real & imag Buffer */ - Word16 *cldfb_addition, /*o: adjust the harmonized hangover */ - Word32 enerBuffer[CLDFB_NO_CHANNELS_MAX], /* i: energy vector per band */ - Word16 enerBuffer_exp, /* i: exponent of energy vector */ - Word16 numBands, /* i: band width 1: NB; 2:WB;3:SWB;4:FB*/ - Word16 vada_flag - ) +/*-------------------------------------------------------------------* + * vad_proc() + * + * + *-------------------------------------------------------------------*/ + +short vad_proc( + float realValues[16][60], /* CLDFB real values */ + float imagValues[16][60], /* CLDFB imag values */ + float *sb_power, /* Energy of CLDFB data */ + int numBands, /* number of input bands */ + T_CldfbVadState *vad_st, + short *cldfb_addition, + short vada_flag +) { - Word16 i; - Word16 bandwidth; - Word16 music_backgound_f; - Word16 Q_cldfb; - Word16 frame_energy2_Q, HB_Power_Q; - Word16 sb_power_Q,frame_energy_Q; - Word32 frame_energy, frame_energy2, HB_Power; - Word32 spec_amp[120]; - Word32 update_flag,snr_flux,lt_snr_org,lt_snr,lf_snr; - Word32 snr,tsnr; - Word16 vad_flag; - Word32 *cldfbBufferReal[CLDFB_NO_COL_MAX]; /* dynamic scaling; cldfbBufferReal_float[x][y] = cldfbBufferReal[x][y] * 2^(-Q_cldfb) */ - Word32 *cldfbBufferImag[CLDFB_NO_COL_MAX]; /* dynamic scaling; cldfbBufferImag_float[x][y] = cldfbBufferReal[x][y] * 2^(-Q_cldfb) */ + float frame_energy,frame_energy2; + float spec_amp[8*10]; /* 120 */ + float snr, tsnr; + int update_flag; + int vad_flag; + int music_backgound_f=0; + float HB_Power=0; + float snr_flux; + float lt_snr; + float lt_snr_org; + float lf_snr; + int bandwidth; - music_backgound_f = add(0,0); - frame_energy = L_add(0,0); - - - IF(sub(numBands, 20) < 0) + if(numBands<20) { bandwidth = 1; - move16(); } - ELSE IF(sub(numBands, 40) < 0) + else if(numBands<40) { bandwidth = 2; - move16(); } - ELSE + else { bandwidth = 3; - move16(); } vad_st->bw_index = bandwidth; - move16(); - FOR (i=0; i=10); - Q_cldfb = sub(31, riBuffer_exp); + /* new optimized structure */ + est_energy(sb_power, vad_st->frame_sb_energy, &frame_energy, &frame_energy2, &HB_Power, bandwidth); - Q_cldfb = sub(Q_cldfb, 16); + subband_FFT(realValues,imagValues,spec_amp); + spec_center(sb_power,vad_st->sp_center,bandwidth); - est_energy(enerBuffer, - enerBuffer_exp, - vad_st->frame_sb_energy, - &frame_energy2, - &HB_Power, - &frame_energy, - &sb_power_Q, - &frame_energy2_Q, - &HB_Power_Q, - &frame_energy_Q, - &vad_st->frame_sb_energy_scale, - bandwidth - ); + ltd_stable(vad_st->frames_power,vad_st->ltd_stable_rate,frame_energy,vad_st->frameloop); - subband_FFT(cldfbBufferReal, - cldfbBufferImag, - spec_amp, - 0, - &Q_cldfb - ); + spec_flatness( spec_amp, vad_st->smooth_spec_amp, vad_st->sfm ); - frame_spec_dif_cor_rate(vad_st, spec_amp, - add(Q_cldfb, 8), - vad_st->f_tonality_rate - ); + frame_spec_dif_cor_rate( spec_amp, vad_st->pre_spec_low_dif, vad_st->f_tonality_rate ); - spec_center(enerBuffer, - vad_st->sp_center, - bandwidth, - sb_power_Q - ); + bg_music_decision( vad_st, &music_backgound_f, frame_energy ); - ltd_stable(vad_st, - vad_st->ltd_stable_rate, - frame_energy, - vad_st->frameloop, - frame_energy_Q - ); + SNR_calc( vad_st->frame_sb_energy, vad_st->sb_bg_energy, vad_st->t_bg_energy, &snr, &tsnr, frame_energy2, bandwidth ); - spec_flatness(spec_amp, - vad_st->smooth_spec_amp, - vad_st->sfm - ); + calc_snr_flux( tsnr, vad_st->pre_snr, &snr_flux ); - bg_music_decision(vad_st, - &music_backgound_f, - frame_energy, - frame_energy_Q - ); + calc_lt_snr( <_snr_org, <_snr, vad_st->fg_energy, vad_st->fg_energy_count, + vad_st->bg_energy, vad_st->bg_energy_count, bandwidth, vad_st->lt_noise_sp_center0 ); - snr_calc(vad_st, - frame_energy2_Q, - &snr, - &tsnr, - frame_energy2, - bandwidth - ); + calc_lf_snr( &vad_st->lf_snr_smooth, &lf_snr, vad_st->l_speech_snr, vad_st->l_speech_snr_count, + vad_st->l_silence_snr, vad_st->l_silence_snr_count, vad_st->fg_energy_count,vad_st->bg_energy_count, bandwidth ); - calc_snr_flux(tsnr, - vad_st->pre_snr, - &snr_flux - ); + vad_flag = comvad_decision( vad_st, snr, tsnr, snr_flux, lt_snr, lt_snr_org, lf_snr, frame_energy2, music_backgound_f, cldfb_addition, vada_flag ); - calc_lt_snr(vad_st, - <_snr_org, - <_snr, - vad_st->fg_energy, - vad_st->fg_energy_count, - vad_st->bg_energy, - vad_st->bg_energy_count, - bandwidth, - vad_st->lt_noise_sp_center0 - ); - - calc_lf_snr(&vad_st->lf_snr_smooth, - &lf_snr, - vad_st->l_speech_snr, - vad_st->l_speech_snr_count, - vad_st->l_silence_snr, - vad_st->l_silence_snr_count, - vad_st->fg_energy_count, - vad_st->bg_energy_count, - bandwidth - ); - - - vad_flag = comvad_decision(vad_st, - lf_snr, - lt_snr_org, - lt_snr, - snr_flux, - snr, - tsnr, - frame_energy2, - music_backgound_f, - frame_energy2_Q, - cldfb_addition, - vada_flag - ); - - - update_flag = update_decision(vad_st, - frame_energy, - HB_Power, - vad_st->frameloop, - bandwidth, - frame_energy_Q, - HB_Power_Q, - snr, - tsnr, - vad_st->vad_flag_for_bk_update, - music_backgound_f - ); - - - UpdateState(vad_st, - vad_st->vad_flag_for_bk_update, - frame_energy2, - frame_energy2_Q, - update_flag, - music_backgound_f, - HB_Power, - HB_Power_Q - ,snr - ); + update_flag = update_decision( vad_st,snr,tsnr, frame_energy,HB_Power,vad_st->vad_flag_for_bk_update, music_backgound_f ); + UpdateState( vad_st, frame_energy2, HB_Power, update_flag,music_backgound_f, vad_st->vad_flag_for_bk_update,snr); return vad_flag; } - - diff --git a/src/libs/libevs/lib_enc/vbr_average_rate.cpp b/src/libs/libevs/lib_enc/vbr_average_rate.cpp new file mode 100644 index 00000000..e0873483 --- /dev/null +++ b/src/libs/libevs/lib_enc/vbr_average_rate.cpp @@ -0,0 +1,168 @@ +/*==================================================================================== + EVS Codec 3GPP TS26.443 Nov 13, 2018. Version 12.11.0 / 13.7.0 / 14.3.0 / 15.1.0 + ====================================================================================*/ + +#include +#include "options.h" +#include "cnst.h" +#include "prot.h" +#include "rom_com.h" + + +/*------------------------------------------------------------------* + * Local constants + *------------------------------------------------------------------*/ + +#define RATEWIN 600 /* length of the rate control window. This is 600 active speech frames. This equals roughly 12s of active speech */ + +/*------------------------------------------------------------------* + * update_average_rate() + * + * SC-VBR update average data rate + *------------------------------------------------------------------*/ + +void update_average_rate( + Encoder_State *st /* i/o: encoder state structure */ +) +{ + float avratetarg; /* target rate for next RATEWIN active frames */ + float target; /* target set by VBR_ADR_MAX_TARGET*RATEWIN*10 */ + + if ( st->numactive == RATEWIN ) /* goes into rate control only the numactive ==RATEWIN. So rate control is triggered after each RATEWIN avtive frames */ + { + /* after 1000 blocks of RATEWIN frames, we change the way we control the average rate by using + st->global_avr_rate=0.99*st->global_avr_rate+0.01*st->sum_of_rates. This will avoid + veriables growing indefinitely while providing a good long term average rate */ + + if ( st->global_frame_cnt < 1000 ) + { + st->global_frame_cnt++; + st->global_avr_rate = (st->global_avr_rate * (st->global_frame_cnt-1) + st->sum_of_rates) / st->global_frame_cnt; + } + else + { + st->global_avr_rate = 0.01f * st->sum_of_rates + 0.99f * st->global_avr_rate; + } + + if ( st->sum_of_rates == 0 ) + { + st->sum_of_rates = (float) (RATEWIN * VBR_ADR_MAX_TARGET * 10); + } + + target = VBR_ADR_MAX_TARGET * 10 * RATEWIN; + + if ( target < st->global_avr_rate ) /* Action is taken to reduce the averge rate. Only initiated if the global rate > target rate */ + { + /* Check the vad snr values to table the noisey/not noisey decision */ + + if ( st->SNR_THLD < 67 ) /* Currently in QFF mode. The bumpup thresholds are slightly relaxed for noisy speech. */ + { + /* Increase the threshold so the the bumpup procedure is done using the noisy thresholds. + Use 3.5 steps to quickly ramp up the rate control to reduce the settling time */ + st->SNR_THLD += 3.5f; + } + else if ( st->mode_QQF == 0 && st->sum_of_rates > target ) /* Now SNR_THLD is in the max allowed. Sill the global average is higher and + last RATEWIN frames have a higher agerage than the target rate. Now slightly + more aggresive rate control is used by changing the mode to QQF. Still the + same strict bumpups (more bumpups,higher rate) are used. */ + { + /* Kick in QQF mode */ + st->mode_QQF = 1; + } + else if ( st->sum_of_rates > target ) /* Actions (1) and (2) are not sufficient to control the rate. Still the last RATEWIN active + frames have a higher average rate than the target rate. More aggresive rate control is + needed. At this point the rate_control flag is set. This will enable the more relaxed + bump up thresholds (less bump ups->reduced rate)*/ + { + /* Relaxed bump ups are used */ + st->rate_control = 1; + + /* This will be triggered only if the gloabl average rate is considerablly higher than the target rate. + Keep a higher threshold to avoid short term rate increases over the target rate. */ + if ( st->global_avr_rate > (target+420.0f) ) /* Last resort rate control. This is a safer rate control mechanism by increasing NELPS */ + { + st->Last_Resort = 1; /* compute based on a larger window as the last resort */ + } + else + { + st->Last_Resort = 0; + } + } + else if ( st->sum_of_rates < target ) /* If the average rate of last RATEWIN frames is controlled by above actions, disable the most + aggresive rate control mechanisms. Still keep QQF mode as the global rate is not under + the target rate*/ + { + st->Last_Resort = 0; + st->mode_QQF = 1; + st->rate_control = 0; + } + } + else + { + /* floding back to lesser and leser aggresive rate control mechanisms gradually if global rate is under control */ + st->Last_Resort = 0; + + if ( st->rate_control == 1 ) + { + st->rate_control = 0; + } + else if ( st->mode_QQF == 1) /* now rate control is not active and still the global rate is below the target. so go to QFF mode */ + { + st->mode_QQF = 0; + } + else + { + if ( st->SNR_THLD >= 60 ) + { + st->SNR_THLD -= 1.5f; + } + else + { + st->SNR_THLD = 60.0f; + } + } + } + + if ( st->global_avr_rate < target-120 ) /* In QFF mode and global rate is less than target rate-0.2kbps. We can send some Q frames + to F frames to improve the quality */ + { + /* kick in bouncing back from Q to F */ + st->Q_to_F = 1; + + /* average rate for next 600ms = global_rate * 2 - rate of the past RATEWIN active frames */ + avratetarg = (float)((RATEWIN * 10) * 2 * VBR_ADR_MAX_TARGET - st->global_avr_rate); + + /* compute the percentage of frames that needed to be sent to F. st->pattern_m is computed as % val * 1000. eg. if % is 10%, then + st->pattern_m=100 . Later this value is used in voiced.enc to bump up 10% of PPP frames to F frames. */ + st->pattern_m = (short)(1000 * (avratetarg - 6.15f * RATEWIN * 10)/(10 * RATEWIN * 0.1f) ); + + if ( st->pattern_m < 0 ) + { + st->pattern_m = 0; /* no bump up will ever happen */ + } + + if ( st->pattern_m > 1000 ) + { + st->pattern_m = 1000; /* 10% of bump ups */ + } + + st->patterncount = 0; + } + else + { + st->Q_to_F = 0; + } + + st->sum_of_rates = 0; + st->numactive = 0; + } + + st->numactive++; + + /* sum the total number of bits (in kbytes) * 10 here */ + st->sum_of_rates += (st->core_brate / 1000.0f) * 10; + + return; +} + + diff --git a/src/libs/libevs/lib_enc/vbr_average_rate_fx.cpp b/src/libs/libevs/lib_enc/vbr_average_rate_fx.cpp deleted file mode 100755 index 7d8b7f75..00000000 --- a/src/libs/libevs/lib_enc/vbr_average_rate_fx.cpp +++ /dev/null @@ -1,244 +0,0 @@ -/*==================================================================================== - EVS Codec 3GPP TS26.442 Apr 03, 2018. Version 12.11.0 / 13.6.0 / 14.2.0 - ====================================================================================*/ - -#include -#include "options.h" /* Compilation switches */ -#include "cnst_fx.h" /* Common constants */ -#include "prot_fx.h" /* Function prototypes */ -#include "rom_com_fx.h" /* Static table prototypes */ -#include "stat_enc_fx.h" /* Static table prototypes */ -#include "stl.h" - - -#define RATEWIN 600 /* length of the rate control window. This is 600 active speech frames. This equals roughly 12s of active speech */ - -/*=================================================================================*/ -/* FUNCTION : update_average_rate_fx */ -/*---------------------------------------------------------------------------------*/ -/* PURPOSE : SC-VBR update average data rate */ -/*---------------------------------------------------------------------------------*/ -/* INPUT ARGUMENTS : */ -/* _ (struct DTFS_STRUCTURE_FX) */ -/*---------------------------------------------------------------------------------*/ -/* INPUT/OUTPUT ARGUMENTS : */ -/* st_fx->global_avr_rate_fx Q13 */ -/* st_fx->sum_of_rates_fx Q13 */ -/* st_fx->SNR_THLD_fx Q8 */ -/* st_fx->Q_to_F_fx Q0 */ -/* st_fx->pattern_m_fx Q0 */ -/* st_fx->rate_control_fx Q0 */ -/*---------------------------------------------------------------------------------*/ -/*/* OUTPUT ARGUMENTS : */ -/* _ None */ -/*---------------------------------------------------------------------------------*/ -/* RETURN ARGUMENTS : _ None. */ -/*---------------------------------------------------------------------------------*/ -/* CALLED FROM : */ -/*=================================================================================*/ -void update_average_rate_fx( - Encoder_State_fx *st_fx /* i/o: encoder state structure */ -) -{ - Word32 avratetarg_fx; /* target rate for next RATEWIN active frames */ - Word32 target_fx; /* target set by VBR_ADR_MAX_TARGET*RATEWIN*10 */ - Word16 tmp; - Word32 L_tmp; - Word32 L_tmp1,L_tmp2; - - Word16 exp, recip, Qrecip; - - IF ( sub(st_fx->numactive_fx,RATEWIN) == 0 ) /* goes into rate control only the numactive ==RATEWIN. So rate control is triggered after each RATEWIN avtive frames */ - { - /* after 1000 blocks of RATEWIN frames, we change the way we control the average rate by using - st->global_avr_rate=0.99*st->global_avr_rate+0.01*st->sum_of_rates. This will avoid - veriables growing indefinitely while providing a good long term average rate */ - - IF ( L_sub(st_fx->frame_cnt_ratewin_fx,1000) < 0 ) - { - st_fx->frame_cnt_ratewin_fx = add(st_fx->frame_cnt_ratewin_fx,1); - - /*st->global_avr_rate = (st->global_avr_rate * (st->global_frame_cnt-1) + st->sum_of_rates) / st->global_frame_cnt; */ - exp = norm_s(st_fx->frame_cnt_ratewin_fx); - tmp = shl(st_fx->frame_cnt_ratewin_fx,exp); - recip = div_s(16384,tmp); - Qrecip = 15-(exp-14); - - IF(L_sub(st_fx->frame_cnt_ratewin_fx,1) >0) - { - tmp = div_s(sub(st_fx->frame_cnt_ratewin_fx,1),st_fx->frame_cnt_ratewin_fx); /*Q15*/ - L_tmp1 = Mult_32_16(st_fx->global_avr_rate_fx, tmp); /* Q13*Q15 = Q13 */ - - L_tmp2 = Mult_32_16(st_fx->sum_of_rates_fx, recip); /*Q13*Qrecip = 13+Qrecip+1-16 = Qrecip-2 */ - - st_fx->global_avr_rate_fx = L_add(L_tmp1, L_shl(L_tmp2,13-(Qrecip-2))); /*Q13 */ - } - ELSE - { - st_fx->global_avr_rate_fx = st_fx->sum_of_rates_fx; /*handle the first frame*/ - } - /* Q13 */ - } - ELSE - { - /* st->global_avr_rate = 0.01f * st->sum_of_rates + 0.99f * st->global_avr_rate; */ - st_fx->global_avr_rate_fx = L_add(Mult_32_16(st_fx->sum_of_rates_fx,328),Mult_32_16(st_fx->global_avr_rate_fx,32441) ); /*Q13 */ - } - - - IF ( st_fx->sum_of_rates_fx == 0 ) - { - /* st->sum_of_rates = (float) (RATEWIN * VBR_ADR_MAX_TARGET * 10); */ - st_fx->sum_of_rates_fx = L_shl(L_mult0(RATEWIN ,VBR_ADR_MAX_TARGET_x10_Q1 ),12); /*Q13 */ - } - - /* target = VBR_ADR_MAX_TARGET * 10 * RATEWIN; */ - target_fx = L_shl(L_mult0(VBR_ADR_MAX_TARGET_x10_Q1,RATEWIN ),12); /*Q13 */ - - IF ( L_sub(target_fx,st_fx->global_avr_rate_fx) < 0 ) /* Action is taken to reduce the averge rate. Only initiated if the global rate > target rate */ - { - /* Check the vad snr values to table the noisey/not noisey decision */ - - test(); - IF ( sub(st_fx->SNR_THLD_fx , 17152) < 0 ) /*Q8 */ /* Currently in QFF mode. The bumpup thresholds are slightly relaxed for noisy speech. */ - { - /* Increase the threshold so the the bumpup procedure is done using the noisy thresholds. - Use 3.5 steps to quickly ramp up the rate control to reduce the settling time */ - - /* st->SNR_THLD += 3.5f; */ - st_fx->SNR_THLD_fx = add(st_fx->SNR_THLD_fx , 896 ); /*Q8 */ - } - ELSE IF ( st_fx->mode_QQF_fx == 0 && L_sub(st_fx->sum_of_rates_fx, target_fx)>0 ) /* Now SNR_THLD is in the max allowed. Sill the global average is higher and - last RATEWIN frames have a higher agerage than the target rate. Now slightly - more aggresive rate control is used by changing the mode to QQF. Still the - same strict bumpups (more bumpups,higher rate) are used. */ - { - /* Kick in QQF mode */ - st_fx->mode_QQF_fx = 1; - move16(); - } - ELSE IF ( L_sub(st_fx->sum_of_rates_fx , target_fx) > 0 ) /* Actions (1) and (2) are not sufficient to control the rate. Still the last RATEWIN active - frames have a higher average rate than the target rate. More aggresive rate control is - needed. At this point the rate_control flag is set. This will enable the more relaxed - bump up thresholds (less bump ups->reduced rate)*/ - { - /* Relaxed bump ups are used */ - st_fx->rate_control_fx = 1; - move16(); - /* This will be triggered only if the gloabl average rate is considerablly higher than the target rate. - Keep a higher threshold to avoid short term rate increases over the target rate. */ - IF ( L_sub(st_fx->global_avr_rate_fx ,L_add(target_fx,3440640)) > 0 ) /* Last resort rate control. This is a safer rate control mechanism by increasing NELPS */ - { - st_fx->Last_Resort_fx = 1; - move16(); /* compute based on a larger window as the last resort */ - } - ELSE - { - st_fx->Last_Resort_fx = 0; - move16(); - } - } - ELSE IF ( L_sub(st_fx->sum_of_rates_fx, target_fx ) < 0) /* If the average rate of last RATEWIN frames is controlled by above actions, disable the most - aggresive rate control mechanisms. Still keep QQF mode as the global rate is not under - the target rate*/ - { - st_fx->Last_Resort_fx = 0; - move16(); - st_fx->mode_QQF_fx = 1; - move16(); - st_fx->rate_control_fx = 0; - move16(); - } - } - ELSE - { - /* floding back to lesser and leser aggresive rate control mechanisms gradually if global rate is under control */ - st_fx->Last_Resort_fx = 0; - move16(); - - IF ( sub(st_fx->rate_control_fx,1) == 0 ) - { - st_fx->rate_control_fx = 0; - move16(); - } - ELSE IF ( sub(st_fx->mode_QQF_fx,1) == 0) /* now rate control is not active and still the global rate is below the target. so go to QFF mode */ - { - st_fx->mode_QQF_fx = 0; - move16(); - } - ELSE - { - IF ( sub(st_fx->SNR_THLD_fx, 15360) >= 0 ) - { - st_fx->SNR_THLD_fx =sub(st_fx->SNR_THLD_fx ,384 ); /*Q8 */ - } - ELSE - { - st_fx->SNR_THLD_fx = 15360; - move16(); - } - } - } - - IF ( L_sub(st_fx->global_avr_rate_fx , L_sub(target_fx,983040)) < 0 ) /* In QFF mode and global rate is less than target rate-0.2kbps. We can send some Q frames - to F frames to improve the quality */ - { - /* kick in bouncing back from Q to F */ - st_fx->Q_to_F_fx = 1; - move16(); - - /* average rate for next 600ms = global_rate * 2 - rate of the past RATEWIN active frames */ - /* avratetarg = (float)((RATEWIN * 10) * 2 * VBR_ADR_MAX_TARGET - st->global_avr_rate); */ - avratetarg_fx = L_sub(L_shl(L_mult0(RATEWIN ,VBR_ADR_MAX_TARGET_x10_Q1 ),13), st_fx->global_avr_rate_fx ); - /* Q13 */ - - - /* compute the percentage of frames that needed to be sent to F. st->pattern_m is computed as % val * 1000. eg. if % is 10%, then - st->pattern_m=100 . Later this value is used in voiced.enc to bump up 10% of PPP frames to F frames. */ - /* st->pattern_m = (short)(1000 * (avratetarg - 6.15f * RATEWIN * 10)/(10 * RATEWIN * 0.1f) ); */ - - L_tmp = L_mult0(RATEWIN ,VBR_ADR_MAX_TARGET_x10_Q1 ); - L_tmp = L_shl(L_tmp , 12); - L_tmp = L_sub(avratetarg_fx , L_tmp); - tmp = extract_h(L_shl(Mult_32_16(L_tmp,27307),4)); - st_fx->pattern_m_fx =tmp; - move16(); - - if ( st_fx->pattern_m_fx < 0 ) - { - st_fx->pattern_m_fx = 0; - move16(); /* no bump up will ever happen */ - } - - if ( sub(st_fx->pattern_m_fx,1000) > 0 ) - { - st_fx->pattern_m_fx = 1000; - move16();/* 10% of bump ups */ - } - - st_fx->patterncount_fx = 0; - move16(); - } - ELSE - { - st_fx->Q_to_F_fx = 0; - move16(); - } - - st_fx->sum_of_rates_fx = 0; - move16(); - st_fx->numactive_fx = 0; - move16(); - - } - - st_fx->numactive_fx = add(st_fx->numactive_fx,1); - - /* sum the total number of bits (in kbytes) * 10 here */ - /*st->sum_of_rates += (st_fx->core_brate_fx / 1000.0f) * 10; */ - L_tmp = L_shl(Mult_32_16(st_fx->core_brate_fx ,20972),7); - st_fx->sum_of_rates_fx = L_add(st_fx->sum_of_rates_fx ,L_tmp); - - return; -} - diff --git a/src/libs/libevs/lib_enc/vlpc_1st_cod.cpp b/src/libs/libevs/lib_enc/vlpc_1st_cod.cpp old mode 100755 new mode 100644 index 4c21d926..bdf7d9cb --- a/src/libs/libevs/lib_enc/vlpc_1st_cod.cpp +++ b/src/libs/libevs/lib_enc/vlpc_1st_cod.cpp @@ -1,135 +1,119 @@ /*==================================================================================== - EVS Codec 3GPP TS26.442 Apr 03, 2018. Version 12.11.0 / 13.6.0 / 14.2.0 + EVS Codec 3GPP TS26.443 Nov 13, 2018. Version 12.11.0 / 13.7.0 / 14.3.0 / 15.1.0 ====================================================================================*/ +#include #include -#include "stl.h" -#include "control.h" -#include "cnst_fx.h" -#include "prot_fx.h" +#include "cnst.h" +#include "prot.h" -#define ISF_ONE 3/*1.0f*1.28f Q1*/ /*=1.0f in 14Q1*1.28*/ -extern const Word16 dico_lsf_abs_8b[]; +extern float const dico_lsf_abs_8b[]; + +/*------------------------------------------------------------------* +* lsf_weight() +* +* outputs only the weightings, doesn't do anything with the lsfq +*------------------------------------------------------------------*/ -/*outputs only the weightings, doesn't do anything with the lsfq*/ static void lsf_weight( - const Word16 *lsfq, /* input: quantized lsf coefficients (14Q1*1.28)*/ - Word16 *w /* output: lsf weighting vector (0Q15) */ + const float *lsfq, + float *w, + float sr_core ) { - Word16 i; - Word16 inv_di0, inv_di1; - + int i; + float inv_di0, inv_di1; + float scale = sr_core/INT_FS_12k8; + float freq_max = sr_core/2.f; + /* Verify, that M is pair, otherwise adapt exit of loop below */ + assert ((M & 1) == 0); /* weighting function */ - /*use the second element as the base to avoid the following division by 0*/ - /*this happens when the ac function is nearly flat*/ - i = lsfq[0]; - move16(); - if (lsfq[0] == 0) + inv_di0 = scale / lsfq[0]; + for (i=1; i<(M-2); i+=2) { - i = lsfq[1]; - move16(); - } - inv_di0 = 0x7fff; - move16(); - if (sub(i, ISF_ONE) > 0) - { - inv_di0 = div_s(ISF_ONE,i); /*0Q15*/ /*inv_di0 = 1.0f / lsfq[0];*/ - } + inv_di1 = scale / (lsfq[i] - lsfq[i-1]); + w[i-1] = inv_di0 + inv_di1; - /* Allow saturation during weight calculation, because the values that are - weighted later are used for a minimum search and experimental saturation - avoidance also showed no improvement. */ - BASOP_SATURATE_WARNING_OFF - FOR (i=1; i<(M-2); i+=2) /*for (i=1; i<(M-2); i+=2)*/ - { - inv_di1 = div_s(ISF_ONE,s_max(ISF_ONE, sub(lsfq[i],lsfq[i-1]))); /*0Q15*/ /*inv_di1 = 1.0f / (lsfq[i] - lsfq[i-1]);*/ - w[i-1] = add(inv_di0,inv_di1); - move16(); /*0Q15*/ /*w[i-1] = inv_di0 + inv_di1;*/ - inv_di0 = div_s(ISF_ONE,s_max(ISF_ONE, sub(lsfq[i+1],lsfq[i]))); /*0Q15*/ /*inv_di0 = 1.0f / (lsfq[i+1] - lsfq[i]);*/ - w[i] = add(inv_di1,inv_di0); - move16(); /*0Q15*/ /*w[i] = inv_di1 + inv_di0;*/ + inv_di0 = scale / (lsfq[i+1] - lsfq[i]); + w[i] = inv_di1 + inv_di0; } - inv_di1 = div_s(ISF_ONE, s_max(ISF_ONE, sub(lsfq[i],lsfq[i-1]))); /*inv_di1 = 1.0f / (lsfq[i] - lsfq[i-1]);*/ - w[i-1] = add(inv_di0,inv_di1); - move16(); /*w[i-1] = inv_di0 + inv_di1;*/ - inv_di0 = div_s(ISF_ONE, s_max(ISF_ONE, sub(FREQ_MAX,lsfq[i]))); /*inv_di0 = 1.0f / (FREQ_MAX - lsfq[i]);*/ - w[i] = add(inv_di1,inv_di0); - move16(); /*w[i] = inv_di1 + inv_di0;*/ - - BASOP_SATURATE_WARNING_ON + inv_di1 = scale / (lsfq[i] - lsfq[i-1]); + w[i-1] = inv_di0 + inv_di1; + inv_di0 = scale / (freq_max - lsfq[i]); + w[i] = inv_di1 + inv_di0; return; } -Word16 vlpc_1st_cod( /* output: codebook index */ - const Word16 *lsf, /* input: vector to quantize (14Q1*1.28) */ - Word16 *lsfq /* o: quantized lsf (14Q1*1.28) */ - ,Word16 *wout /* o: lsf weights */ - ,Word16 rf_mode +/*------------------------------------------------------------------* +* vlpc_1st_cod() +* +* +*------------------------------------------------------------------*/ + +int vlpc_1st_cod( /* output: codebook index */ + const float *lsf, /* input: vector to quantize */ + float *lsfq, /* i/o: i:prediction o:quantized lsf */ + float sr_core + ,float *wout /* o: lsf weights */ ) { - Word16 i, j, index, diff, wdiff; - Word16 w[M]; - Word32 dist_min, dist; - const Word16 *p_dico; - - + int i, j, index; + float w[M], x[M]; + float dist_min, dist, temp; + const float *p_dico; + int hit=0; + float scale = sr_core/INT_FS_12k8; + float scaleinv = 1.f / scale; /* weighting */ - lsf_weight(lsf, w);/*lsf:14Q1*1.28=>w:0Q15*/ - IF(sub(rf_mode, 1) == 0) - { - Word16 s; - s = Find_Max_Norm16(w, M); - Scale_sig(w, M, s); - } - Copy(w, wout, M); + lsf_weight(lsf, w, sr_core ); + + mvr2r( w, wout, M ); + /* remove lsf prediction/means */ - /*dist_min = 1.0e30f;*/ - dist_min = L_add(MAX_32, 0); - p_dico = dico_lsf_abs_8b; /*14Q1*1.28*/ - index = 0; - move16(); - - FOR (i = 0; i < 256; i++) + for( i=0; i since isfq[i] is 0, only data move is sufficient*/ - /*lsfq[j] = add(lsfq[j],*p_dico++);*/ - lsfq[j] = *p_dico++; - move16(); + lsfq[j] += scale **p_dico++; /* += cause it's differential */ } + assert(index < 256); + assert(hit>0); return index; } - - - diff --git a/src/libs/libevs/lib_enc/vlpc_2st_cod.cpp b/src/libs/libevs/lib_enc/vlpc_2st_cod.cpp old mode 100755 new mode 100644 index 13ef2b6a..2817eb47 --- a/src/libs/libevs/lib_enc/vlpc_2st_cod.cpp +++ b/src/libs/libevs/lib_enc/vlpc_2st_cod.cpp @@ -1,147 +1,106 @@ /*==================================================================================== - EVS Codec 3GPP TS26.442 Apr 03, 2018. Version 12.11.0 / 13.6.0 / 14.2.0 + EVS Codec 3GPP TS26.443 Nov 13, 2018. Version 12.11.0 / 13.7.0 / 14.3.0 / 15.1.0 ====================================================================================*/ #include #include +#include #include -#include "cnst_fx.h" -#include "prot_fx.h" -#include "stl.h" -#include "control.h" -#include "basop_util.h" +#include "cnst.h" +#include "prot.h" +/*------------------------------------------------------------------* +* vlpc_2st_cod() +* +* +*------------------------------------------------------------------*/ -Word16 vlpc_2st_cod( /* output: number of allocated bits */ - const Word16 *lsf, /* input: normalized vector to quantize (14Q1*1.28)*/ - Word16 *lsfq, /* i/o: i:1st stage o:1st+2nd stage (14Q1*1.28)*/ - Word16 *indx, /* output: index[] (4 bits per words) */ - Word16 mode, /* input: 0=abs, >0=rel */ - Word32 sr_core +int vlpc_2st_cod( /* output: number of allocated bits */ + const float *lsf, /* input: normalized vector to quantize */ + float *lsfq, /* i/o: i:1st stage o:1st+2nd stage */ + int *indx, /* output: index[] (4 bits per words) */ + int mode, /* input: 0=abs, >0=rel */ + float sr_core ) { - Word16 i, nbits; - Word16 w[M], x[M]; - Word16 nq, xq[M]; - Word32 L_tmp; - Word16 gap; - - + int i, nbits; + float w[M], x[M], tmp; + int nq, xq[M]; + float scale = sr_core/INT_FS_12k8; + float scaleinv = 1.f / scale; /* 0 bit with true weighting: save 0.5 bit */ - lsf_weight_2st(lsf, w, 1); /*w:0Q15*1.28*/ - FOR (i=1; i wops) */ - nbits = 6; /* 2*(2+1) */ move16(); - test(); - IF ( (mode == 0) || (sub(mode,3) == 0) ) - { - nbits = 10; /* 2*(2+3) */ move16(); - } - ELSE IF (sub(mode,1) == 0) - { - nbits = 2; /* 2*1 */ move16(); - } - - return nbits; + return(10); /* 2*(2+3) */ } /* weighting from the 1st stage */ - lsf_weight_2st(lsfq, w, mode); + lsf_weight_2st( lsfq, w, mode, sr_core ); - /* find lsf and scale the residual */ - FOR (i=0; i 0) - { - /*nbits += nq-3;*/ - nbits = add(nbits,sub(nq,3)); /* unary code (Q7=1110, ...) */ - } - ELSE IF (sub(nq,4) > 0) - { - /*nbits += nq-4;*/ - nbits = add(nbits,sub(nq,4)); /* Q5=0, Q6=10 */ - } - ELSE IF (nq == 0) - { - /*nbits += 3;*/ - nbits = add(nbits,3); /* Q0=110 */ - } - }/*FOR (i=0; i<2; i++)*/ + if (nq > 6) nbits += nq-3; /* unary code (Q7=1110, ...) */ + else if (nq > 4) nbits += nq-4; /* Q5=0, Q6=10 */ + else if (nq == 0) nbits += 3; /* Q0=110 */ + } /* reorder */ - sort_fx(lsfq, 0, M-1); - IF ( L_sub(sr_core,16000) == 0 ) - { - gap = 102; - } - ELSE IF ( L_sub(sr_core,25600) == 0 ) - { - gap = 64; - } - ELSE IF ( L_sub(sr_core,32000) == 0 ) - { - gap = 51; - } - ELSE - { - gap = 34; - } - reorder_lsf_fx(lsfq, gap, M, INT_FS_FX); + v_sort( lsfq, 0, M-1 ); + reorder_lsf( lsfq, LSF_GAP, M, sr_core ); - - return nbits; + return( nbits ); } diff --git a/src/libs/libevs/lib_enc/voiced_enc.cpp b/src/libs/libevs/lib_enc/voiced_enc.cpp new file mode 100644 index 00000000..64af9d45 --- /dev/null +++ b/src/libs/libevs/lib_enc/voiced_enc.cpp @@ -0,0 +1,647 @@ +/*==================================================================================== + EVS Codec 3GPP TS26.443 Nov 13, 2018. Version 12.11.0 / 13.7.0 / 14.3.0 / 15.1.0 + ====================================================================================*/ + +#include +#include +#include "prot.h" +#include "cnst.h" +#include "rom_com.h" + + +/*-------------------------------------------------------------------* + * Local functions + *--------------------------------------------------------------------*/ + +static void SynthesisFilter( float *output, float *input, float *coef, float *memory, short order, short length ); + +/*-------------------------------------------------------------------* + * ppp_voiced_encoder() + * + * voiced encoder for SC-VBR + *--------------------------------------------------------------------*/ + +void ppp_voiced_encoder( + Encoder_State *st, /* i/o: state structure */ + float *in, /* i : residual signal */ + float *out, /* o : Quantized residual signal */ + short delay, /* i : open loop pitch */ + float *lpc1, /* i : prev frame de-emphasized LPC */ + float* lpc2, /* i : current frame de-emphasized LPC */ + float *exc, /* i : previous frame quantized excitation */ + float *pitch, /* o : floating pitch values for each subframe */ + float vadsnr /* i : current frame SNR */ +) +{ + short i; + short spike_near_edge = 0; + short flag; + short delta_lag_E = 0, PPP_MODE_E, Q_delta_lag = 0; + short out_of_bound = 0; + float tmp, tmptmp, tmptmp1, res_enratio = 0, sp_enratio = 0; + double tmp2; + int pl, l; + float interp_delay[3], temp_pl, temp_l; + short upper_cut_off_freq_of_interest = 0, upper_cut_off_freq = 0; + float pos_nq, neg_nq, pos_q, neg_q; + float impzi[160]; + float impzo[160]; + float mem[10]; + float energy_impz = 0.0f; + float pos_nq0, neg_nq0, tmpres; + float sp_hb_enratio; + float low_band_en; + + DTFS_STRUCTURE *CURRP_NQ = DTFS_new(); + DTFS_STRUCTURE *TMPDTFS = DTFS_new(); + DTFS_STRUCTURE *TMPDTFS2 = DTFS_new(); + DTFS_STRUCTURE *TMPDTFS3 = DTFS_new(); + DTFS_STRUCTURE *CURRP_Q_E = DTFS_new(); + DTFS_STRUCTURE *dtfs_temp = DTFS_new(); + + if ( st->bwidth == WB ) + { + upper_cut_off_freq_of_interest = 4000; + upper_cut_off_freq = 6400; + } + else if ( st->bwidth == NB ) + { + upper_cut_off_freq_of_interest = 3300; + upper_cut_off_freq = 4000; + } + + /* Initialization */ + if (st->firstTime_voicedenc) + { + st->firstTime_voicedenc = 0; + st->dtfs_enc_lag = 0; + st->dtfs_enc_nH = 0; + st->dtfs_enc_nH_4kHz = 0; + st->dtfs_enc_upper_cut_off_freq_of_interest = 3300.0; + st->dtfs_enc_upper_cut_off_freq = 4000.0; + + set_f(st->dtfs_enc_a, 0, MAXLAG_WI); + set_f(st->dtfs_enc_b, 0, MAXLAG_WI); + } + + /* Figure out the PPP_MODE */ + if ( st->last_ppp_mode == 1 && !st->mode_QQF ) + { + st->bump_up = 1; + + free(CURRP_NQ); + free(TMPDTFS); + free(TMPDTFS2); + free(TMPDTFS3); + free(CURRP_Q_E); + free(dtfs_temp); + + return; + } + + /* Use the aggresive bumpups if there are two consecutive Q frames */ + /* Aggresive bump upsare only used in the second Q frame */ + if ( st->last_ppp_mode == 1 ) + { + st->rate_control = 0; + } + + PPP_MODE_E = 'Q'; + pl = min(MAX_LAG_PIT, (int)rint_new(st->old_pitch_buf[(2*NB_SUBFR)-1])); + l = min(MAX_LAG_PIT, (int)rint_new(delay)); + + /* Bump up if the lag is out_fx of range */ + if ((l-pl)>13 || (l-pl)<-11 || (l < 19) || (pl < 19) ) + { + st->bump_up = 1; + + free(CURRP_NQ); + free(TMPDTFS); + free(TMPDTFS2); + free(TMPDTFS3); + free(CURRP_Q_E); + free(dtfs_temp); + return; + } + + if (st->last_ppp_mode!=1) + { + /* Obtain DTFS of last pl values of past excitation */ + DTFS_to_fs(exc-pl, pl, dtfs_temp, st->bwidth == WB ? (short)16000 : (short)8000, 0 ); + + } + + if( st->last_coder_type_raw == UNVOICED ) + { + pl = l; /* if prev frame was sil/uv */ + } + + /* Use the out array as a temp storage for currp */ + spike_near_edge = ppp_extract_pitch_period(in, out, l, &out_of_bound) ; + + if (out_of_bound == 1) + { + st->bump_up = 1; + + free(CURRP_NQ); + free(TMPDTFS); + free(TMPDTFS2); + free(TMPDTFS3); + free(CURRP_Q_E); + free(dtfs_temp); + + return; + } + + /* Get DTFS of current prototype */ + DTFS_to_fs(out, l, CURRP_NQ, st->bwidth == WB ? (short)16000 : (short)8000, 0); + + /* Ensure the extracted prototype is time-synchronous to the + * last l samples of the frame. This proves to eliminate + * some of the PPP-CELP transition problems. + * Convert last samples into DTFS */ + if (spike_near_edge != 0) + { + DTFS_to_fs(in+L_FRAME-l, l, TMPDTFS, st->bwidth == WB ? (short)16000 : (short)8000 ,0); + + tmp = DTFS_alignment_extract(*TMPDTFS, *CURRP_NQ, 0.0, lpc2) ; /* figure out how much to shift currp_nq to align with TMP */ + + DTFS_phaseShift(CURRP_NQ, (float)(PI2*tmp/l)) ; + } + + temp_pl = (float) pl; + temp_l = (float) l; + + for(i = 0; i < NB_SUBFR; i++) + { + /* do the linear pitch interp to drive the nb_post_filt */ + Interpol_delay(interp_delay, &(temp_pl), &(temp_l), i, frac_4sf); + pitch[i] = interp_delay[0]; + } + + + + /* Restoring PPP memories when the last frame is non-PPP */ + if ( st->last_ppp_mode != 1 ) + { + st->ph_offset_E = 0.0 ; + st->prev_cw_en = DTFS_getEngy(*dtfs_temp); + + /* Copy over dtfs_temp into TMPDTFS */ + DTFS_copy(TMPDTFS, *dtfs_temp); + + DTFS_car2pol(TMPDTFS); + + st->lastLgainE = (float) log10(TMPDTFS->lag*DTFS_setEngyHarm(92.0, 1104.5, 0.0, 1104.5, 1.0, TMPDTFS)); + st->lastHgainE = (float) log10(TMPDTFS->lag*DTFS_setEngyHarm(1104.5, upper_cut_off_freq_of_interest, 1104.5, upper_cut_off_freq, 1.0, TMPDTFS)); + + DTFS_to_erb(*TMPDTFS, st->lasterbE); + } + else + { + /* Copy DTFS related parameters from 'st' to 'dtfs_temp' structure */ + dtfs_temp->lag = st->dtfs_enc_lag; + dtfs_temp->nH = st->dtfs_enc_nH; + dtfs_temp->nH_4kHz = st->dtfs_enc_nH_4kHz; + dtfs_temp->upper_cut_off_freq_of_interest = st->dtfs_enc_upper_cut_off_freq_of_interest; + dtfs_temp->upper_cut_off_freq = st->dtfs_enc_upper_cut_off_freq; + + mvr2r(st->dtfs_enc_a, dtfs_temp->a, MAXLAG_WI); + mvr2r(st->dtfs_enc_b, dtfs_temp->b, MAXLAG_WI); + } + + /*-----Open-loop Bump-Up-------- */ + + /* Energy ratio calculation in residual and speech domain */ + /* Also, compute correlation between the previous and the */ + /* current prototype */ + res_enratio = DTFS_getEngy(*CURRP_NQ) / DTFS_getEngy(*dtfs_temp); + + /* Copy over CURRP_NQ into TMPDTFS */ + DTFS_copy(TMPDTFS, *CURRP_NQ); + + /* Copy over dtfs_temp into TMPDTFS2 */ + DTFS_copy(TMPDTFS2, *dtfs_temp); + + tmptmp = DTFS_alignment_full(*TMPDTFS2, *TMPDTFS, TMPDTFS->lag*2); /* align of prev_cw wrt curr_cw, new method */ + + tmptmp1 = TMPDTFS->lag-tmptmp; + tmp = tmptmp1; + + DTFS_phaseShift(TMPDTFS, (float)(-PI2*tmp/TMPDTFS->lag)); /* fixed bug , phase shift by tmp computed in TMP.lag domain (above) */ + tmpres = (float)(DTFS_freq_corr(*TMPDTFS, *TMPDTFS2, 100.0f, 3700.0f)); + + DTFS_poleFilter(TMPDTFS, lpc2, M+1); + + DTFS_adjustLag(TMPDTFS2, TMPDTFS->lag); /* operate in CL domain */ + + DTFS_poleFilter(TMPDTFS2, lpc1, M+1); + + tmp = (float)(DTFS_freq_corr(*TMPDTFS, *TMPDTFS2, 100.0f, 3700.0f)); + + if ( DTFS_getEngy(*TMPDTFS2) > 0 ) + { + sp_enratio = DTFS_getEngy(*TMPDTFS)/DTFS_getEngy(*TMPDTFS2); + } + else + { + sp_enratio = 0.0f; + } + + if (PPP_MODE_E == 'Q') + { + /* Bump up if the lag is out of range */ + if (((l-pl)>13) ||((l-pl)<-11)) + { + PPP_MODE_E = 'B' ; + } + else + { + delta_lag_E=(short) (l-pl); + } + + /* Bump up if big change between the previous and the current CWs */ + if ( vadsnr < st->SNR_THLD ) + { + if ( res_enratio > 5.0 && tmp < 0.65 ) + { + PPP_MODE_E = 'B'; + } + } + else + { + if ( res_enratio > 3.0 && tmp < 1.2 ) + { + PPP_MODE_E = 'B'; + } + } + } + + /* Rapid rampdown frame where time resolution is important */ + /* Not a suitable PPP frame -> Bump to CELP */ + if ( vadsnr < st->SNR_THLD ) + { + if (res_enratio < 0.025) + { + st->bump_up = 1; + + free(CURRP_NQ); + free(TMPDTFS); + free(TMPDTFS2); + free(TMPDTFS3); + free(CURRP_Q_E); + free(dtfs_temp); + + return; + } + } + else + { + if ( res_enratio < 0.092f ) + { + st->bump_up = 1; + } + } + + if ( min(res_enratio, sp_enratio) < 0.075f && tmp < -0.5f ) + { + st->bump_up = 1; + } + + /* Rapid rampup frame where time resolution is important */ + /* Not a suitable PPP frame -> Bump to CELP */ + if ( vadsnr < st->SNR_THLD ) + { + if (res_enratio > 14.5) + { + st->bump_up = 1; + + free(CURRP_NQ); + free(TMPDTFS); + free(TMPDTFS2); + free(TMPDTFS3); + free(CURRP_Q_E); + free(dtfs_temp); + + return; + } + } + else + { + if (res_enratio > 7.0) + { + st->bump_up = 1; + } + } + + if ( st->bump_up == 1 ) + { + + free(CURRP_NQ); + free(TMPDTFS); + free(TMPDTFS2); + free(TMPDTFS3); + free(CURRP_Q_E); + free(dtfs_temp); + + return; + } + + /* Bump up when the previous frame is an unvoiced or a silent frame */ + if( st->last_coder_type_raw == UNVOICED ) + { + st->bump_up=1; + + free(CURRP_NQ); + free(TMPDTFS); + free(TMPDTFS2); + free(TMPDTFS3); + free(CURRP_Q_E); + free(dtfs_temp); + + return; + } + /* -----End Open-loop Bump-Up */ + + /* PPP-WI Quantization */ + if (PPP_MODE_E == 'Q') + { + flag = 1; + if (PPP_MODE_E == 'Q') + { + flag = ppp_quarter_encoder( st, CURRP_Q_E, TMPDTFS, dtfs_temp->lag, *CURRP_NQ, lpc2, &(st->lastLgainE), &(st->lastHgainE), &(st->lasterbE[0]), *dtfs_temp ); + } + + if (flag) + { + /* TMPDTFS : Target prototype: Amp Quantized + Phase Unquantized */ + /* TMPDTFS2: Quantized prototype: Amp Quantized + Phase Quantized */ + /* TMPDTFS3: Delta prototype: Diff betw. target and quant. in speech dom */ + + /* ----- Closed-loop Bump-Up ---------- */ + DTFS_peaktoaverage(*TMPDTFS, &pos_nq, &neg_nq); + DTFS_peaktoaverage(*CURRP_Q_E, &pos_q, &neg_q); + + /* Before we perform the peak-to-average ratio comparison, we have to */ + /* ensure that the energy is not decaying and also the pitch pulse */ + /* is clearly defined */ + + /* Usually triggers in the slow ramp down frames. Does not fall under the test condition (res_enratio < 0.025) as + both frames have little energy and the ratio is not very small. Not suitable for PPP */ + + if ( CURRP_Q_E->upper_cut_off_freq > 4000 ) + { + /* Use this bumup only for WB signals */ + if ( DTFS_getEngy_band_wb(*CURRP_Q_E, 0.0, 2000.0) > 0 ) + { + sp_hb_enratio = DTFS_getEngy_band_wb(*CURRP_Q_E, 2000.0, 6400.0)/DTFS_getEngy_band_wb(*CURRP_Q_E, 0.0, 2000.0); + } + else + { + sp_hb_enratio = 0; + } + + low_band_en = (float)DTFS_getEngy_band_wb(*CURRP_Q_E, 0.0, 2000.0); + + if ( low_band_en < 25.0f && sp_hb_enratio < 1.6f ) + { + PPP_MODE_E = 'B'; + } + } + + if ( vadsnr < st->SNR_THLD ) + { + if ( DTFS_getEngy(*CURRP_NQ) > 0.8f * st->prev_cw_en && max(pos_nq, neg_nq) > 3.0f && st->rate_control ) + { + if ( pos_nq > neg_nq && pos_nq > 2.0f * pos_q ) + { + PPP_MODE_E = 'B'; + } + + if ( pos_nq < neg_nq && neg_nq > 2.0f * neg_q ) + { + PPP_MODE_E = 'B'; + } + } + } + else + { + if ((((DTFS_getEngy(*CURRP_NQ) >(st->prev_cw_en))&&(max(pos_nq,neg_nq)>3.5))&&(st->rate_control))|| + (((DTFS_getEngy(*CURRP_NQ) >0.8*(st->prev_cw_en))&&(max(pos_nq,neg_nq)>3.0))&&(!st->rate_control))) + { + if (((pos_nq > neg_nq) && (pos_nq > 2.5*pos_q)&&(st->rate_control))|| + ((pos_nq > neg_nq) && (pos_nq > 2.0*pos_q)&&(!st->rate_control))) + { + PPP_MODE_E='B'; + } + + if ((((pos_nq < neg_nq) && (neg_nq > 2.5*neg_q))&&(st->rate_control))|| + ((pos_nq < neg_nq) && (neg_nq > 2.0*neg_q)&&(!st->rate_control))) + { + PPP_MODE_E='B'; + } + } + + if ( st->rate_control ) + { + DTFS_peaktoaverage(*CURRP_NQ, &pos_nq0,&neg_nq0); + + for (impzi[0]=1.0,i=1; i<160; i++) + { + impzi[i]=0.0; + } + + for (i=0; i<160; i++) + { + impzo[i]=0.0; + } + + for (i=0; i<10; i++) + { + mem[i]=0.0; + } + + SynthesisFilter(&impzo[0],&impzi[0],lpc2,&mem[0],10,160); + + for (i=0; i<160; i++) + { + energy_impz+=(impzo[i]*impzo[i]); + } + + energy_impz = (float)(10*log10((float)energy_impz)); + + if ((DTFS_getEngy(*CURRP_Q_E) > st->prev_cw_en)&&(max(pos_q,neg_q)>3.5)&&energy_impz>15.0&&tmpres>0.7) + { + if ((pos_q > neg_q) && ((pos_q>3.0*pos_nq0) || ((pos_q > 1.5*pos_nq0) && (neg_q < 1.5*neg_q)))) + { + PPP_MODE_E='B'; + } + + if ((pos_q <= neg_q) && ((neg_q>3.0*neg_nq0)|| ((neg_q > 1.5*neg_nq0) && (pos_q < 1.5*pos_q)))) + { + PPP_MODE_E='B'; + } + } + } + } + + DTFS_copy(TMPDTFS2,*CURRP_Q_E); + + DTFS_poleFilter(TMPDTFS,lpc2,M+1); + DTFS_poleFilter(TMPDTFS2,lpc2,M+1); + + *TMPDTFS3 = DTFS_sub(*TMPDTFS,*TMPDTFS2); + + /* operate in ADR mode only the rate control is active. This adds some bumpups to improve the speech quality */ + tmp2 = DTFS_getEngy_band(*TMPDTFS, 1500.0, upper_cut_off_freq_of_interest)/DTFS_getEngy(*TMPDTFS); + if (tmp2==0.0) + { + tmp2=0.001; + } + if ((tmp2> 0.05)&&(!st->rate_control)) + { + tmp2=DTFS_getEngy_band(*TMPDTFS,1500.0,upper_cut_off_freq_of_interest)/DTFS_getEngy_band(*TMPDTFS3,1500.0,upper_cut_off_freq_of_interest); + if (tmp2==0.0) + { + tmp2=0.001; + } + if (10.0*log10(tmp2) < 0.1) + { + if (res_enratio > 0.8) + { + PPP_MODE_E = 'B'; + } + } + } + + /* To increase bump up, raise first threshold, lower second */ + tmp = (float)(10.0*log10(DTFS_getEngy(*TMPDTFS)/DTFS_getEngy(*TMPDTFS3))); + + if ((tmp <= 0)&&(!st->rate_control)) + { + PPP_MODE_E = 'B'; + } + + if ( vadsnr < st->SNR_THLD ) + { + if ((( tmp < 3.05 && max(res_enratio,sp_enratio) > 0.8 )&&(st->rate_control))|| + (( tmp < 2.8 && max(res_enratio,sp_enratio) > 0.65 )&&(!st->rate_control))) + { + PPP_MODE_E = 'B'; + } + } + else + { + if ((( tmp < 2.4 && max(res_enratio,sp_enratio) > 0.94 ) &&(st->rate_control))|| + (( tmp < 4.5 && max(res_enratio,sp_enratio) > 0.5 ) &&(!st->rate_control))) + { + PPP_MODE_E = 'B'; + } + } + /* -----End closed-loop Bump-Up */ + } + else + { + PPP_MODE_E = 'B' ; /* Amplitude quantization is failing */ + } + } + else + { + } + + if (PPP_MODE_E == 'B') + { + st->bump_up = 1; + + free(CURRP_NQ); + free(TMPDTFS); + free(TMPDTFS2); + free(TMPDTFS3); + free(CURRP_Q_E); + free(dtfs_temp); + + return; + } + + if ( st->Q_to_F ) + { + st->patterncount += st->pattern_m; + + if (st->patterncount >= 1000) + { + st->patterncount -= 1000; + PPP_MODE_E = 'B'; + st->bump_up = 1; + + free(CURRP_NQ); + free(TMPDTFS); + free(TMPDTFS2); + free(TMPDTFS3); + free(CURRP_Q_E); + free(dtfs_temp); + + return; + } + } + + /* packetization of the delta lag in PPP */ + if (PPP_MODE_E == 'Q') + { + Q_delta_lag = delta_lag_E+11; /* to make it positive always */ + push_indice( st, IND_DELTALAG, Q_delta_lag, 5 ); + } + + WIsyn(*dtfs_temp, CURRP_Q_E, lpc2, &(st->ph_offset_E), out, L_FRAME, 0); + + DTFS_copy(dtfs_temp, *CURRP_Q_E); + st->prev_cw_en = DTFS_getEngy(*CURRP_NQ); + + /* Copy DTFS related parameters from 'dtfs_temp' to 'st' structure */ + st->dtfs_enc_lag = dtfs_temp->lag; + st->dtfs_enc_nH = dtfs_temp->nH; + st->dtfs_enc_nH_4kHz = dtfs_temp->nH_4kHz; + st->dtfs_enc_upper_cut_off_freq_of_interest = dtfs_temp->upper_cut_off_freq_of_interest; + st->dtfs_enc_upper_cut_off_freq = dtfs_temp->upper_cut_off_freq; + + mvr2r(dtfs_temp->a, st->dtfs_enc_a, MAXLAG_WI); + mvr2r(dtfs_temp->b, st->dtfs_enc_b, MAXLAG_WI); + + free(CURRP_NQ); + free(TMPDTFS); + free(TMPDTFS2); + free(TMPDTFS3); + free(CURRP_Q_E); + free(dtfs_temp); + + return; +} + +static void SynthesisFilter( + float *output, + float *input, + float *coef, + float *memory, + short order, + short length +) +{ + short i, j; + float acc; + + /* IIR filter for each subframe */ + for (i=0; i0; j-- ) + { + acc -= coef[j] * memory[j]; + memory[j] = memory[j - 1]; + } + + acc -= coef[0] * memory[0]; + *output++ = acc; + memory[0] = acc; + } + + return; +} + diff --git a/src/libs/libevs/lib_enc/voiced_enc_fx.cpp b/src/libs/libevs/lib_enc/voiced_enc_fx.cpp deleted file mode 100755 index 78b7133c..00000000 --- a/src/libs/libevs/lib_enc/voiced_enc_fx.cpp +++ /dev/null @@ -1,1205 +0,0 @@ -/*==================================================================================== - EVS Codec 3GPP TS26.442 Apr 03, 2018. Version 12.11.0 / 13.6.0 / 14.2.0 - ====================================================================================*/ - -#include -#include "prot_fx.h" -#include "cnst_fx.h" -#include "rom_com_fx.h" -#include "stl.h" - -/*-------------------------------------------------------------------* - * Local functions - *--------------------------------------------------------------------*/ -void synthesis_filter_fx (Word16 b[], Word16 x[], Word16 y[], Word16 buf[], - Word16 P, Word16 N ); - - -/*=======================================================================================*/ -/* FUNCTION : ppp_voiced_encoder_fx() */ -/*---------------------------------------------------------------------------------------*/ -/* PURPOSE : */ -/*---------------------------------------------------------------------------------------*/ -/* INPUT ARGUMENTS : */ -/* _ (Word16) delay_fx: open loop pitch, Q6 - WRONG, it is Q0 */ -/* _ (Word16) vadsnr_fx: SNR for current frame Q7 */ -/* _ (Word16) prevCW_lag_fx: Previous lag, Q0 */ -/* _ (Word16 *) in_fx : residual signal (Q_res) */ -/* _ (Word16 *) lpc1_fx : prev frame de-emphasized LPC Q12 */ -/* _ (Word16 *) lpc2_fx : current frame de-emphasized LPC Q12 */ -/* _ (Word16 *) exc_fx : prrevious frame quantized excitation (Q_exc) */ -/* _ (Word16) Q_res: Q factor for res */ -/* _ (Word16) Q_exc: Q factor for exc */ -/*---------------------------------------------------------------------------------------*/ -/* OUTPUT ARGUMENTS : */ -/* _ (Word16*) pitch_fx: floating pitch values for each subframe(Q6) */ -/* _ (Word16*) out_fx: Quantized residual signal (Q0) */ -/* _ Encoder_State_fx *st_fx: */ -/* _ lastLgainE_fx - Q11 */ -/* _ lastHgainE_fx - Q11 */ -/* _ lasterbE_fx - Q13 */ -/*---------------------------------------------------------------------------------------*/ -/* INPUT/OUTPUT ARGUMENTS : */ -/* _ Encoder_State_fx *st_fx: */ -/* _ st_fx->dtfs_enc_xxxx */ -/* _ a nd b in st_fx->dtfs_enc_Q */ -/* rest all in Q0 */ -/* - bump_up_fx - Q0 */ -/*---------------------------------------------------------------------------------------*/ -/* RETURN ARGUMENTS : */ -/* _ None. */ -/*---------------------------------------------------------------------------------------*/ -/* CALLED FROM : TX */ -/*=======================================================================================*/ - -void ppp_voiced_encoder_fx( - Encoder_State_fx *st_fx, /* i/o: state structure */ - Word16 *in_fx, /* i : residual signal */ - Word16 *out_fx, /* o : Quantized residual signal */ - Word16 delay_fx, /* i : open loop pitch */ - Word16 *lpc1_fx, /* i : prev frame de-emphasized LPC */ - Word16* lpc2_fx, /* i : current frame de-emphasized LPC */ - Word16 *exc_fx, /* i: previous frame quantized excitation */ - Word16 *pitch_fx, /* o: floating pitch values for each subframe */ - Word16 vadsnr_fx, /* i: current frame SNR Q7, later shl by 1 for compare */ - Word16 Qres -) -{ - Word16 i; - Word16 spike_near_edge = 0; - Word16 flag; - Word16 delta_lag_E = 0, PPP_MODE_E, Q_delta_lag = 0; - Word16 out_of_bound = 0; - Word16 tmp, tmptmp, tmptmp1; - Word16 pl, l; - Word16 interp_delay[3], temp_pl, temp_l; - Word16 upper_cut_off_freq_of_interest_fx = 0; - Word16 upper_cut_off_freq_of_interest_norm_fx = 0, upper_cut_off_freq_norm_fx = 0; - - Word16 S_fx[PIT_MAX*4+1], C_fx[PIT_MAX*4+1]; - Word16 Qtmpres; - Word32 Ltemp, logLag, Ltemp_q; - Word32 Lacc,Lacc1; - Word16 Ql, Qh,n,sft,flag1; - - Word16 pf_temp1[MAXLAG_WI]; /*maynot need more than MAXLAG_WI/2+1 */ - Word16 pf_temp2[MAXLAG_WI]; - Word16 pf_temp[MAXLAG_WI]; - Word16 pf_n2[MAXLAG_WI]; - Word16 exp,expa,expb,fraca,fracb,scale,frac; - Word32 L_tmp; - - Word16 x_fx; - Word16 impzi_fx[160],impzo_fx[160]; - Word16 exp_ee, frac_ee; - Word16 Qtmp; - Word32 res_enratio_fx =0 ; - Word16 mem_fx[10]; - Word32 energy_impz_fx = 0,tmpres_fx; - Word32 pos_nq0_fx,neg_nq0_fx,Ltmp; - Word32 Ltmp_32, Ltmp1_32, Ltemp1, Ltemp2, Ltemp_fx; - Word16 Qadj; - - Word32 tmp_fx = 0,sp_hb_enratio_fx = 0,sp_enratio_fx = 0; - Word32 low_band_en_fx; - Word32 curr_Engy,prev_Engy; - Word16 temp_Fs; - - - DTFS_STRUCTURE_FX *CURRP_NQ_FX = DTFS_new_fx(); - DTFS_STRUCTURE_FX *TMPDTFS_FX = DTFS_new_fx(); - DTFS_STRUCTURE_FX *TMPDTFS2_FX = DTFS_new_fx(); - DTFS_STRUCTURE_FX *TMPDTFS3_FX = DTFS_new_fx(); - DTFS_STRUCTURE_FX *CURRP_Q_E_FX = DTFS_new_fx(); - DTFS_STRUCTURE_FX *dtfs_temp_fx = DTFS_new_fx(); - - - - temp_Fs = 8000; - move16(); - - if ( sub( st_fx->bwidth_fx, WB) == 0 ) - { - temp_Fs = 16000; - move16(); - } - - test(); - IF (sub(st_fx->bwidth_fx,WB) == 0 || sub(st_fx->bwidth_fx,SWB) == 0) - { - upper_cut_off_freq_of_interest_fx = 4000; - move16(); - upper_cut_off_freq_of_interest_norm_fx = 10240; - move16();/*value normalized by 12800 */ - upper_cut_off_freq_norm_fx = 16384; - move16();/*value normalized by 12800 */ - } - ELSE IF (sub(st_fx->bwidth_fx,NB) == 0) - { - upper_cut_off_freq_of_interest_fx = 3300; - move16(); - upper_cut_off_freq_of_interest_norm_fx = 8448; - move16();/*value normalized by 12800 */ - upper_cut_off_freq_norm_fx = 10240; - move16();/*value normalized by 12800 */ - } - - /* Initialization */ - IF (st_fx->firstTime_voicedenc_fx) - { - st_fx->firstTime_voicedenc_fx = 0; - move16(); - st_fx->dtfs_enc_lag_fx = 0; - move16(); - st_fx->dtfs_enc_nH_fx = 0; - move16(); - st_fx->dtfs_enc_nH_4kHz_fx = 0; - move16(); - st_fx->dtfs_enc_upper_cut_off_freq_of_interest_fx = 3300; - move16(); - st_fx->dtfs_enc_upper_cut_off_freq_fx = 4000; - move16(); - set16_fx(st_fx->dtfs_enc_a_fx, 0, MAXLAG_WI); - set16_fx(st_fx->dtfs_enc_b_fx, 0, MAXLAG_WI); - } - test(); - /* Figure out the PPP_MODE */ - IF ( sub(st_fx->last_ppp_mode_fx,1) == 0 && !st_fx->mode_QQF_fx ) - { - st_fx->bump_up_fx = 1; - move16(); - free(CURRP_NQ_FX); - free(TMPDTFS_FX); - free(TMPDTFS2_FX); - free(TMPDTFS3_FX); - free(CURRP_Q_E_FX); - free(dtfs_temp_fx); - return; - } - - /* Use the aggresive bumpups if there are two consecutive Q frames */ - /* Aggresive bump upsare only used in the second Q frame */ - if ( st_fx->last_ppp_mode_fx == 1 ) - { - st_fx->rate_control_fx = 0; - } - - PPP_MODE_E = 'Q'; - move16(); - - pl = s_min(MAX_LAG_PIT, rint_new_fx(L_shl(st_fx->old_pitch_buf_fx[(2*NB_SUBFR)-1],10))); - move16(); - l = s_min(MAX_LAG_PIT, rint_new_fx(L_deposit_h(delay_fx))); - move16(); - /* st_fx->old_pitch_buf_fx in Q6*/ - - /* Bump up if the lag is out_fx of range */ - test(); - IF (sub(sub(l,pl),13)>0 || sub(sub(l,pl),-11) < 0 || sub(l,19) < 0 || sub(pl,19) < 0 ) - { - st_fx->bump_up_fx = 1; - move16(); - free(CURRP_NQ_FX); - free(TMPDTFS_FX); - free(TMPDTFS2_FX); - free(TMPDTFS3_FX); - free(CURRP_Q_E_FX); - free(dtfs_temp_fx); - return; - } - - IF (sub(st_fx->last_ppp_mode_fx,1)!=0) - { - /* Obtain DTFS of last pl values of past excitation */ - GetSinCosTab_fx(pl,S_fx,C_fx); - DTFS_to_fs_fx(exc_fx-pl, pl, dtfs_temp_fx, temp_Fs, 0,S_fx,C_fx); - } - - if (sub(st_fx->last_coder_type_raw_fx,UNVOICED) == 0) - { - pl = l; - move16(); /* if prev frame was sil/uv */ - } - - /* Use the out_fx array as a temp storage for currp */ - spike_near_edge = ppp_extract_pitch_period_fx(in_fx, out_fx, l, &out_of_bound,Qres) ; - move16(); - /* out_fx in Qres */ - - IF (out_of_bound == 1) - { - st_fx->bump_up_fx = 1; - move16(); - free(CURRP_NQ_FX); - free(TMPDTFS_FX); - free(TMPDTFS2_FX); - free(TMPDTFS3_FX); - free(CURRP_Q_E_FX); - free(dtfs_temp_fx); - return; - } - - /* Get DTFS of current prototype */ - GetSinCosTab_fx(l,S_fx,C_fx); - - DTFS_to_fs_fx(out_fx, l, CURRP_NQ_FX, temp_Fs, 0,S_fx,C_fx); - /* This requires input out_fx in Q0, but currently in Qres */ - - /* Ensure the extracted prototype is time-synchronous to the - * last l samples of the frame. This proves to eliminate - * some of the PPP-CELP transition problems. - * Convert last samples into DTFS */ - IF (spike_near_edge != 0) - { - /* These two function calls are combined in one call DTFS_alignment_extract_td_fx() */ - /* DTFS_to_fs(in+L_FRAME-l, l, TMPDTFS,(short) st->input_Fs,0); */ - /* tmp = DTFS_alignment_extract(*TMPDTFS, *CURRP_NQ, 0.0, lpc2) ; */ - tmp = DTFS_alignment_extract_td_fx(out_fx, in_fx+L_FRAME-l, l) ; - move16(); /*Q0 */ - tmp = negate(shl(tmp,2));/*Q2 */ - Q2phaseShift_fx(CURRP_NQ_FX, tmp, l, S_fx,C_fx) ; - /* output CURRP_NQ is correct */ - } - temp_pl = pl; - move16(); - temp_l = l; - move16(); - - FOR(i = 0; i < NB_SUBFR; i++) - { - /* do the linear pitch_fx interp to drive the nb_post_filt */ - Interpol_delay_fx(interp_delay, temp_pl, temp_l, i, frac_4sf_fx); /* interp_delay in Q4 */ - pitch_fx[i] = shl(interp_delay[0],2); - move16();/* pitch_fx in Q6 */ - } - curr_Engy=DTFS_getEngy_P2A_fx(CURRP_NQ_FX); /*2Q where Q=CURRP_NQ_FX->Q */ - - /* Restoring PPP memories when the last frame is non-PPP */ - IF (sub(st_fx->last_ppp_mode_fx,1)!=0) - { - - st_fx->ph_offset_E_fx = 0 ; - move16(); - - /* st->prev_cw_en = DTFS_getEngy(*dtfs_temp); */ - Lacc=DTFS_getEngy_P2A_fx(dtfs_temp_fx); /*2Q where Q = dtfs_temp_fx->Q */ - - - prev_Engy = L_add(Lacc, 0); - - st_fx->Q_prev_cw_en_fx=norm_l(Lacc); /* = K = headroom */ - - /*st_fx->Q_prev_cw_en_fx = (Lacc==0)?31: st_fx->Q_prev_cw_en_fx; */ - if (Lacc==0) - { - st_fx->Q_prev_cw_en_fx = 31; - move16(); - } - - st_fx->prev_cw_en_fx=(Word32) L_shl(Lacc,st_fx->Q_prev_cw_en_fx); /*2Q+K */ - st_fx->Q_prev_cw_en_fx = add(st_fx->Q_prev_cw_en_fx,shl(dtfs_temp_fx->Q,1)); - /* st_fx->Q_prev_cw_en_fx = 2*(dtfs_temp_fx->Q) + K */ - - DTFS_copy_fx(TMPDTFS_FX,*dtfs_temp_fx); /* output = TMPDTFS_FX */ - - DTFS_car2pol_fx(TMPDTFS_FX); - - logLag=log10_fx(TMPDTFS_FX->lag_fx); /* logLag=10*log10(pl), Q23 */ - Ltemp_q=L_shl(L_mult(shl(TMPDTFS_FX->Q,1),24660),9); /* Ltemp_q=2Q*10log10(2), Q23 */ - - /* Process low band */ - Ltemp=DTFS_setEngyHarm_fx(236,2828,0,2828, 1, 0, &Ql,TMPDTFS_FX);/* Q of Ltemp = 2*(TMPDTFS_FX->Q) = Ql ? */ - /* Compensate for Q factor of energy to get log10(lag*eng) */ - Ltemp=log10_fx(Ltemp); /* Ltemp=10log10(eng), Q23 */ - Ltemp=L_add(L_sub(Ltemp,Ltemp_q),logLag); /* Ltemp=10*log10(lag*eng), Q23 */ - /*st_fx->lastLgainE_fx=round_fx(L_shl((Word32)Mpy_32_16(extract_h(Ltemp),extract_l(Ltemp),0x6666),1)); // Q11, 0x6666 = 0.1 in Q18 */ - st_fx->lastLgainE_fx=round_fx(L_shl(Mult_32_16(Ltemp,0x6666),1)); /* Q11, 0x6666 = 0.1 in Q18 */ - - - /* Process high band */ - Ltemp=DTFS_setEngyHarm_fx(2828,upper_cut_off_freq_of_interest_norm_fx,2828,upper_cut_off_freq_norm_fx, 1, 0, &Qh,TMPDTFS_FX); - Ltemp=log10_fx(Ltemp); - Ltemp=L_add(L_sub(Ltemp,Ltemp_q),logLag); /* Ltemp=10*log10(lag*eng), Q23 */ - st_fx->lastHgainE_fx=round_fx(L_shl(Mult_32_16(Ltemp,0x6666),1)); /* Q11 */ - - /* Need to unify the Q factors of both bands */ - TMPDTFS_FX->Q=s_min(Ql,Qh); - move16();/* set Q factor to be the smaller one of Ql and Qh */ - n=sub(Ql,Qh); /* compare band Q factors */ - - IF (n<0) - { - rshiftHarmBand_fx(TMPDTFS_FX,2828, upper_cut_off_freq_norm_fx,n); - } - ELSE IF (n>0) - { - rshiftHarmBand_fx(TMPDTFS_FX,0, 2828, sub(Qh,Ql)); - } - - DTFS_to_erb_fx(*TMPDTFS_FX,st_fx->lasterbE_fx); /* output lasterbE_fx in Q13 */ - Lacc1 = L_max(prev_Engy, 1); - } - ELSE - { - /* Copy DTFS related parameters from 'st_fx' to 'dtfs_temp' structure */ - dtfs_temp_fx->lag_fx = st_fx->dtfs_enc_lag_fx; - move16(); - dtfs_temp_fx->nH_fx = st_fx->dtfs_enc_nH_fx; - move16(); - dtfs_temp_fx->nH_4kHz_fx = st_fx->dtfs_enc_nH_4kHz_fx; - move16(); - dtfs_temp_fx->upper_cut_off_freq_of_interest_fx = st_fx->dtfs_enc_upper_cut_off_freq_of_interest_fx; - move16(); - dtfs_temp_fx->upper_cut_off_freq_fx = st_fx->dtfs_enc_upper_cut_off_freq_fx; - move16(); - - Copy(st_fx->dtfs_enc_a_fx, dtfs_temp_fx->a_fx, MAXLAG_WI); - Copy(st_fx->dtfs_enc_b_fx, dtfs_temp_fx->b_fx, MAXLAG_WI); - - dtfs_temp_fx->Q = st_fx->dtfs_enc_Q; - move16(); - Lacc1=DTFS_getEngy_P2A_fx(dtfs_temp_fx); - prev_Engy = L_add(Lacc1, 0); - } - - /*-----Open-loop Bump-Up-------- */ - - /* Energy ratio calculation in_fx residual and speech domain */ - /* Also, compute correlation between the previous and the */ - /* current prototype */ - - /* res_enratio = DTFS_getEngy(*CURRP_NQ) / DTFS_getEngy(*dtfs_temp); */ - Lacc = L_add(curr_Engy, 0); - /* Lacc1 has been handled above */ - - sft=add(shl(sub(CURRP_NQ_FX->Q,dtfs_temp_fx->Q),1),4); - IF (sft>0) - { - if (L_sub(Lacc1,L_shr(Lacc,sft))<0) - { - res_enratio_fx=0x7FFF; - move16(); - } - } - ELSE - { - if (L_sub(L_shr(Lacc1,negate(sft)),Lacc)<0) - { - res_enratio_fx=0x7FFF; - move16(); - } - } - /* max value res_enratio compared against is 0x7400 (14.5 in Q11) */ - - IF (L_sub(res_enratio_fx,0x7FFF)!=0) - { - - expb = norm_l(Lacc); - fracb = extract_h(L_shl(Lacc,expb)); - expb = sub(30,add(expb, shl(CURRP_NQ_FX->Q, 1))); - - - expa = norm_l(Lacc1); - fraca = extract_h(L_shl(Lacc1,expa)); - expa = sub(30, add(expa, shl(dtfs_temp_fx->Q, 1))); - - scale = shr(sub(fraca,fracb),15); - fracb = shl(fracb,scale); - expb = sub(expb,scale); - - tmp = div_s(fracb,fraca); - exp = sub(expb,expa); - res_enratio_fx = shl(tmp,sub(exp,4)); - } - /* res_enratio_fx is Q11 */ - - /* Copy over CURRP_NQ into TMPDTFS */ - DTFS_copy_fx(TMPDTFS_FX, *CURRP_NQ_FX); /* output = TMPDTFS_FX with Q = CURRP_NQ_FX->Q */ - - /* Copy over dtfs_temp into TMPDTFS2 */ - DTFS_copy_fx(TMPDTFS2_FX, *dtfs_temp_fx); /* output = TMPDTFS2_FX with Q = dtfs_temp_fx->Q */ - - tmptmp = DTFS_alignment_full_fx(*TMPDTFS2_FX,*TMPDTFS_FX,st_fx->ph_offset_E_fx,S_fx,C_fx - , 0 - ); - - tmptmp1 = sub(shl(TMPDTFS_FX->lag_fx,1), tmptmp);/* (C_l-tmptmp) , Q1 */ - - Q2phaseShift_fx(TMPDTFS_FX, negate(shl(tmptmp1,1)), TMPDTFS_FX->lag_fx,S_fx,C_fx); /* fixed bug , phase shift by tmp computed in_fx TMP.lag domain (above) */ - - /*tmpres = (float)(DTFS_freq_corr(*TMPDTFS, *TMPDTFS2, 100.0f, 3700.0f));*/ - tmpres_fx = DTFS_freq_corr_fx(*TMPDTFS_FX, *TMPDTFS2_FX, 100, 3700, &Qtmpres); /* tmpres_fx has Q factor tmpres */ - - - - poleFilter_setup_fx(lpc2_fx, M+1, *TMPDTFS_FX, S_fx, C_fx, pf_temp1, pf_temp2, pf_temp, pf_n2); - DTFS_poleFilter_fx_9(TMPDTFS_FX, pf_temp1, pf_temp2, pf_temp, pf_n2); - /* lpc2_fx in Q12 */ - - DTFS_adjustLag_fx(TMPDTFS2_FX, TMPDTFS_FX->lag_fx); /* operate in_fx CL domain */ - - DTFS_poleFilter_fx(TMPDTFS2_FX,lpc1_fx,M+1, S_fx, C_fx); /* lpc1_fx in Q12 */ - - tmp_fx = DTFS_freq_corr_fx(*TMPDTFS_FX, *TMPDTFS2_FX, 100, 3700, &Qtmp); - /* tmp_fx Q = Qtmp */ - - - /******************************************************************************* - if ( DTFS_getEngy(*TMPDTFS2) > 0 ) - { - sp_enratio = DTFS_getEngy(*TMPDTFS)/DTFS_getEngy(*TMPDTFS2); - } - else - { - sp_enratio = 0.0f; - } - *******************************************************************************/ - Ltmp_32 = (DTFS_getEngy_fx(TMPDTFS2_FX)); /* Output Q=2*(TMPDTFS2_FX->Q) */ - IF ( Ltmp_32 > 0 ) - { - /*sp_enratio = DTFS_getEngy(*TMPDTFS)/DTFS_getEngy(*TMPDTFS2); in Q15 */ - Lacc=DTFS_getEngy_P2A_fx(TMPDTFS_FX); - Lacc1=Ltmp_32; - /* IF (L_sub(sp_enratio_fx,0x7FFF)!=0) */ - { - expb = norm_l(Lacc); - fracb = extract_h(L_shl(Lacc,expb)); - - expb = sub(30, add(expb, shl(TMPDTFS_FX->Q, 1))); - - expa = norm_l(Lacc1); - fraca = extract_h(L_shl(Lacc1,expa)); - - expa = sub(30, add(expa, shl(TMPDTFS2_FX->Q, 1))); - - scale = shr(sub(fraca,fracb),15); - fracb = shl(fracb,scale); - expb = sub(expb,scale); - - tmp = div_s(fracb,fraca); - exp = sub(expb,expa); - sp_enratio_fx = L_shl(tmp, exp); /* Q15 */ - } - } - ELSE - { - sp_enratio_fx = L_deposit_l(0);/* Q15 */ - } - - /*******************************************************************************/ - IF (sub(PPP_MODE_E,'Q') == 0) - { - /* Bump up if the lag is out_fx of range */ - test(); - IF (sub(sub(l,pl),13)>0 || sub(sub(l,pl),-11) < 0) - { - PPP_MODE_E = 'B' ; - move16(); - } - ELSE - { - delta_lag_E= sub(l,pl); - } - - /* Bump up if big change between the previous and the current CWs */ - IF ( sub(shl(vadsnr_fx,1) ,st_fx->SNR_THLD_fx) < 0 ) /*Q8 */ - { - /*if ( res_enratio > 5.0 && tmp < 0.65 ) */ - /* 5 in Q11, 0.65 in Q15 // L_shl(tmp_fx,sub(31,Qtmp)) makes tmp_fx FIXED Q31 */ - test(); - IF ((L_sub(res_enratio_fx,10240)>0) && (sub(extract_h(L_shl(tmp_fx,sub(31,Qtmp))),21299)<0)) - { - PPP_MODE_E = 'B'; - move16(); - } - } - ELSE - { - /* if ( res_enratio > 3.0 && tmp < 1.2 ) */ - /*3 in Q11, 1.2 in Q14 // L_shl(tmp_fx,sub(31,Qtmp)) makes tmp_fx FIXED Q14 */ - test(); - IF ( (L_sub(res_enratio_fx,6144)>0) && (sub(extract_h(L_shl(tmp_fx,sub(30,Qtmp))),19661)<0) ) - { - PPP_MODE_E = 'B'; - move16(); - } - } - } - - /* Rapid rampdown frame where time resolution is important */ - /* Not a suitable PPP frame -> Bump to CELP */ - - IF ( sub(shl(vadsnr_fx,1) ,st_fx->SNR_THLD_fx) < 0 ) /*Q8 */ - { - /* if (res_enratio < 0.025) */ - IF (L_sub(L_shl(res_enratio_fx,4),819)<0) /*0x0333 = 0.025 in Q15, res_enratio_fx in Q15 after shl 4 */ - { - st_fx->bump_up_fx = 1; - move16(); - free(CURRP_NQ_FX); - free(TMPDTFS_FX); - free(TMPDTFS2_FX); - free(TMPDTFS3_FX); - free(CURRP_Q_E_FX); - free(dtfs_temp_fx); - return; - } - } - ELSE - { - /* if ( res_enratio < 0.092f) */ - if ( L_sub(L_shl(res_enratio_fx,4), 3015)< 0 )/*3015 = 0.092 in Q15, res_enratio_fx in Q15 after shl 4 */ - { - st_fx->bump_up_fx = 1; - move16(); - } - } - - /* if (min(res_enratio, sp_enratio) < 0.075 && tmp < -0.5f)) : 2458 = 0.075 in Q15 */ - test(); - if ( L_sub(L_min(L_shl(res_enratio_fx,4), sp_enratio_fx), 2458) < 0 && L_sub(tmp_fx , shl(-1,sub(Qtmp,1)))<0 ) - { - st_fx->bump_up_fx = 1; - move16(); - } - - /* Rapid rampup frame where time resolution is important */ - /* Not a suitable PPP frame -> Bump to CELP */ - IF ( sub(shl(vadsnr_fx,1) ,st_fx->SNR_THLD_fx) < 0 ) /*Q8 */ - { - IF (L_sub(res_enratio_fx,29696)>0) /*14.5 in Q11 */ - { - st_fx->bump_up_fx = 1; - move16(); - free(CURRP_NQ_FX); - free(TMPDTFS_FX); - free(TMPDTFS2_FX); - free(TMPDTFS3_FX); - free(CURRP_Q_E_FX); - free(dtfs_temp_fx); - return; - } - } - ELSE - { - if (L_sub(res_enratio_fx,14336)>0) /* 7.0 in Q11 */ - { - st_fx->bump_up_fx = 1; - move16(); - } - } - - IF ( st_fx->bump_up_fx == 1 ) - { - free(CURRP_NQ_FX); - free(TMPDTFS_FX); - free(TMPDTFS2_FX); - free(TMPDTFS3_FX); - free(CURRP_Q_E_FX); - free(dtfs_temp_fx); - return; - } - - /* Bump up when the previous frame is an unvoiced or a silent frame */ - IF (sub(st_fx->last_coder_type_raw_fx,UNVOICED) == 0) - { - st_fx->bump_up_fx = 1; - move16(); - free(CURRP_NQ_FX); - free(TMPDTFS_FX); - free(TMPDTFS2_FX); - free(TMPDTFS3_FX); - free(CURRP_Q_E_FX); - free(dtfs_temp_fx); - return; - } - /* -----End Open-loop Bump-Up */ - - /* PPP-WI Quantization */ - IF (sub(PPP_MODE_E,'Q') == 0) - { - flag = 1; - move16(); - IF (sub(PPP_MODE_E,'Q') == 0) - { - flag = ppp_quarter_encoder_fx(CURRP_Q_E_FX, TMPDTFS_FX, dtfs_temp_fx->lag_fx, *CURRP_NQ_FX, - lpc2_fx, &st_fx->lastLgainE_fx, &st_fx->lastHgainE_fx, st_fx->lasterbE_fx, *dtfs_temp_fx, S_fx, C_fx, st_fx); - move16(); - } - - IF (flag) - { - /* TMPDTFS : Target prototype: Amp Quantized + Phase Unquantized */ - /* TMPDTFS2: Quantized prototype: Amp Quantized + Phase Quantized */ - /* TMPDTFS3: Delta prototype: Diff betw. target and quant. in_fx speech dom */ - - /* ----- Closed-loop Bump-Up ---------- */ - Word32 pos_nq_fx, neg_nq_fx,pos_q_fx,neg_q_fx; - Word16 Qposnq, Qnegnq, Qposq,Qnegq; - - DTFS_peaktoaverage_fx(*TMPDTFS_FX,&pos_nq_fx,&Qposnq,&neg_nq_fx,&Qnegnq); - DTFS_peaktoaverage_fx(*CURRP_Q_E_FX, &pos_q_fx, &Qposq,&neg_q_fx,&Qnegq); - - - /* Before we perform the peak-to-average ratio comparison, we have to */ - /* ensure that the energy is not decaying and also the pitch_fx pulse */ - /* is clearly defined */ - - /* Usually triggers in the slow ramp down frames. Does not fall under the test condition (res_enratio < 0.025) as - both frames have little energy and the ratio is not very small. Not suitable for PPP */ - - IF ( sub(CURRP_Q_E_FX->upper_cut_off_freq_fx , 4000) >0 ) - { - Ltemp2 = DTFS_getEngy_band_wb_fx(*CURRP_Q_E_FX, 0, 2000); - /* Use this bump-up only for WB signals */ - IF ( Ltemp2 > 0 ) - { - /* sp_hb_enratio = DTFS_getEngy_band_wb(*CURRP_Q_E, 2000.0, 6400.0)/DTFS_getEngy_band_wb(*CURRP_Q_E, 0.0, 2000.0); */ - Ltemp1 = DTFS_getEngy_band_wb_fx(*CURRP_Q_E_FX, 2000, 6400);/*Q13 */ - /*sp_hb_enratio_fx = divide_dp(Ltemp1,Ltemp2,0, 1);//Q29 */ - Qadj = 0; - move16(); - /*----------------------------------------------------------*/ - /* Ltemp_fx = (Word32)divide_dp(Ltemp1, Ltemp2, Qadj,1); Q29*/ - /*----------------------------------------------------------*/ - if(Ltemp1<0) - { - Ltemp1 = L_negate(Ltemp1); - } - expa = norm_l(Ltemp2); - fraca = extract_h(L_shl(Ltemp2,expa)); - expa = sub(30,expa); - - expb = norm_l(Ltemp1); - fracb = round_fx(L_shl(Ltemp1,expb)); - expb = sub(30, add(expb, Qadj)); - - scale = shr(sub(fraca,fracb),15); - fracb = shl(fracb,scale); - expb = sub(expb,scale); - - tmp = div_s(fracb,fraca); - exp = sub(expb,expa); - Ltemp_fx = L_shl(tmp, add(exp,14)); - /*-------------------------------------------*/ - sp_hb_enratio_fx = L_add(Ltemp_fx, 0); /* Q29 */ - } - ELSE - { - sp_hb_enratio_fx = L_deposit_l(0); - } - low_band_en_fx = Ltemp2; /*Q13 */ - - /* if ( low_band_en < 25.0f && sp_hb_enratio < 1.6f ) */ - /* 25.0 in Q13 = 204800, 1.6 in Q29 = 858993459 */ - test(); - IF ( L_sub(low_band_en_fx , 204800 )< 0 && L_sub(sp_hb_enratio_fx , 858993459 ) < 0 ) - { - PPP_MODE_E = 'B'; - move16(); - } - } - - Ltmp_32=DTFS_getEngy_fx(CURRP_NQ_FX); /*Q = 2*(CURRP_NQ_FX->Q) */ - Qadj = sub(st_fx->Q_prev_cw_en_fx, shl(CURRP_NQ_FX->Q, 1)); - - Ltmp_32 = L_shl(Ltmp_32,Qadj); /* shift left required to adjust Q of CURRP_NQ_FX = Q_prev_cw_en_fx */ - - /* Ltmp1_32 = 0.8f * st->prev_cw_en */ - Ltmp1_32 = Mult_32_16(st_fx->prev_cw_en_fx,26214); /* Q = (Q_prev_cw_en_fx + Q15+1)-Q16 = Q_prev_cw_en_fx */ - - IF ( sub(shl(vadsnr_fx,1) ,st_fx->SNR_THLD_fx) < 0 ) /*Q8 */ - { - /* if ( DTFS_getEngy(*CURRP_NQ) > 0.8f * st->prev_cw_en && max(pos_nq, neg_nq) > 3.0f && st->rate_control ) */ - /* pos_nq_fx and neg_nq_fx in Q28 ???? */ - test(); - test(); - IF ( L_sub( Ltmp_32, Ltmp1_32) > 0 && L_sub(L_max(pos_nq_fx, neg_nq_fx) , 805306368) > 0 && st_fx->rate_control_fx ) - { - /*if ( pos_nq > neg_nq && pos_nq > 2.0f * pos_q ) */ - test(); - IF ( L_sub(pos_nq_fx , neg_nq_fx) > 0 && L_sub(Mult_32_16(pos_nq_fx,16384), pos_q_fx) > 0 ) - { - PPP_MODE_E = 'B'; - move16(); - } - - test(); - /*if ( pos_nq < neg_nq && neg_nq > 2.0f * neg_q ) */ - IF ( L_sub(pos_nq_fx , neg_nq_fx) < 0 && L_sub(Mult_32_16(neg_nq_fx,16384), neg_q_fx) > 0 ) - { - PPP_MODE_E = 'B'; - move16(); - } - } - } - - ELSE - { - /* if ((((DTFS_getEngy(*CURRP_NQ) >(st->prev_cw_en))&&(max(pos_nq,neg_nq)>3.5))&&(st->rate_control))|| */ - /* (((DTFS_getEngy(*CURRP_NQ) >0.8*(st->prev_cw_en))&&(max(pos_nq,neg_nq)>3.0))&&(!st->rate_control))) */ - test(); - test(); - test(); - test(); - test(); - IF ((((L_sub(Ltmp_32 ,(st_fx->prev_cw_en_fx)>0))&&(L_sub(L_max(pos_nq_fx,neg_nq_fx),939524096)>0))&&(st_fx->rate_control_fx))|| - (((L_sub( Ltmp_32, Ltmp1_32) > 0 ) && (L_sub(L_max(pos_nq_fx,neg_nq_fx),805306368)>0))&&(!st_fx->rate_control_fx))) - { - /* if (((pos_nq > neg_nq) && (pos_nq > 2.5*pos_q)&&(st->rate_control))|| - ((pos_nq > neg_nq) && (pos_nq > 2.0*pos_q)&&(!st->rate_control))) */ - test(); - test(); - test(); - test(); - test(); - IF ((L_sub(pos_nq_fx , neg_nq_fx)>0 && L_sub(Mult_32_16(pos_nq_fx ,13107),pos_q_fx)>0 && (st_fx->rate_control_fx))|| - (L_sub(pos_nq_fx , neg_nq_fx)>0 && L_sub(Mult_32_16(pos_nq_fx,16384),pos_q_fx) >0 && (!st_fx->rate_control_fx))) - { - PPP_MODE_E='B'; - move16(); - } - - /* if ((((pos_nq < neg_nq) && (neg_nq > 2.5*neg_q))&&(st->rate_control))|| - ((pos_nq < neg_nq) && (neg_nq > 2.0*neg_q)&&(!st->rate_control))) */ - test(); - test(); - test(); - test(); - test(); - IF ((L_sub(pos_nq_fx , neg_nq_fx)<0 && L_sub(Mult_32_16(neg_nq_fx ,13107),neg_q_fx)>0 && (st_fx->rate_control_fx))|| - (L_sub(pos_nq_fx , neg_nq_fx)<0 && L_sub(Mult_32_16(neg_nq_fx,16384),neg_q_fx) >0 && (!st_fx->rate_control_fx))) - { - PPP_MODE_E='B'; - move16(); - } - } - - - IF ( st_fx->rate_control_fx ) - { - - DTFS_peaktoaverage_fx(*CURRP_NQ_FX,&pos_nq0_fx,&Qposnq,&neg_nq0_fx,&Qnegnq); - - impzi_fx[0]=1; - move16(); - FOR (x_fx=1; x_fx<160; x_fx++) - { - impzi_fx[x_fx]=0; - move16(); - } - - FOR (x_fx=0; x_fx<160; x_fx++) - { - impzo_fx[x_fx]=0; - move16(); - } - - FOR (x_fx=0; x_fx<10; x_fx++) - { - mem_fx[x_fx]=0; - move16(); - } - - /* lpc2_fx in Q12, so Qadj is set to 3 toi bring it to Q15 */ - Qadj = 15-12; - move16(); - synthesis_filter_fx(lpc2_fx,&impzi_fx[0],&impzo_fx[0],&mem_fx[0],10,160 ); - - /* compute energy of impz */ - FOR (x_fx=0; x_fx<160; x_fx++) - { - energy_impz_fx = L_add(energy_impz_fx , L_mult0(impzo_fx[x_fx],impzo_fx[x_fx])); - } - - /*energy_impz = (float)(10*log10((float)energy_impz)); */ - exp_ee = norm_l(energy_impz_fx); - frac_ee = Log2_norm_lc(L_shl(energy_impz_fx, exp_ee)); - exp_ee = sub(30, exp_ee); /*30-exp-Q0 */ - Ltmp = Mpy_32_16(exp_ee, frac_ee, LG10); /* Ltmp Q14 */ - energy_impz_fx =L_shr(Ltmp, 3); /* 16+11(4bits for 15 no) = 14+x => x= 11 */ - /* energy_impz_fx is Q11 */ - - Ltmp_32 = DTFS_getEngy_fx(CURRP_Q_E_FX); /*Q = 2*(CURRP_Q_E_FX->Q) */ - Qadj = sub(st_fx->Q_prev_cw_en_fx, shl(CURRP_Q_E_FX->Q, 1)); - Ltmp_32 = L_shl(Ltmp_32,Qadj); /* shift left required to adjust Q of CURRP_Q_E_FX = Q_prev_cw_en_fx */ - - /* if ((DTFS_getEngy(*CURRP_Q_E) > st->prev_cw_en)&&(max(pos_q,neg_q)>3.5) && energy_impz>15.0 && tmpres>0.7) */ - test(); - test(); - test(); - IF ((L_sub(Ltmp_32, st_fx->prev_cw_en_fx )>0) && (L_sub(L_max(pos_q_fx,neg_q_fx),939524096)>0) && (L_sub(energy_impz_fx,30720)>0) - && (L_sub(Mult_32_16(tmpres_fx,23265),shl(1,sub(Qtmpres,1)))>0) ) - { - /* if ((pos_q > neg_q) && ((pos_q>3.0*pos_nq0) || ((pos_q > 1.5*pos_nq0) && (neg_q < 1.5*neg_nq0)))) */ - test(); - test(); - test(); - IF ( (L_sub(pos_q_fx , neg_q_fx)>0) - && ((L_sub(Mult_32_16(pos_q_fx,10923), L_shr(pos_nq0_fx,sub(Qposnq,28)) )>0) - || ((L_sub( Mult_32_16(pos_q_fx,21845),L_shr(pos_nq0_fx,sub(Qposnq,28)) )>0) - && (L_sub(Mult_32_16(neg_q_fx,21846), L_shr(neg_nq0_fx,sub(Qnegnq,28)) )<0) )) - ) - /* 10923 = (1/3) oin Q15, pos_q_fx is Q28, so result of Mult_32_16(pos_q_fx,10923) = Q28 */ - /* L_shr(pos_nq0_fx,sub(Qposnq,28)) brings pos_nq0_fx with variable Q to fixed Q28 */ - { - PPP_MODE_E='B'; - move16(); - } - test(); - test(); - test(); - /* if ((pos_q <= neg_q) && ((neg_q>3.0*neg_nq0)|| ((neg_q > 1.5*neg_nq0) && (pos_q < 1.5*pos_nq0)))) */ - IF ( (L_sub(pos_q_fx ,neg_q_fx)<=0) - && ((L_sub(Mult_32_16(neg_q_fx,10923), L_shr(neg_nq0_fx,sub(Qnegnq,28)))>0) - || ((L_sub(Mult_32_16(neg_q_fx,21846), L_shr(neg_nq0_fx,sub(Qnegnq,28)))>0) - && (L_sub( Mult_32_16( pos_q_fx,21846),L_shr(pos_nq0_fx,sub(Qposnq,28)))<0))) - ) - { - PPP_MODE_E='B'; - move16(); - } - } - } - } - - DTFS_copy_fx(TMPDTFS2_FX,*CURRP_Q_E_FX); - DTFS_poleFilter_fx_9(TMPDTFS_FX, pf_temp1, pf_temp2, pf_temp, pf_n2); - DTFS_poleFilter_fx_9(TMPDTFS2_FX, pf_temp1, pf_temp2, pf_temp, pf_n2); - - *TMPDTFS3_FX = DTFS_sub_fx(*TMPDTFS_FX,*TMPDTFS2_FX); - - - /* operate in ADR mode only the rate control is active. This adds some bumpups to improve the speech quality */ - /* if ((DTFS_getEngy_band(*TMPDTFS, 1500.0, upper_cut_off_freq_of_interest)/DTFS_getEngy(*TMPDTFS) > 0.05)&&(!st->rate_control)) */ - Ltemp1 = DTFS_getEngy_band_fx(*TMPDTFS_FX, 1500, upper_cut_off_freq_of_interest_fx); /* Q = 2*TMPDTFS_FX->Q*/ - Ltemp2 = DTFS_getEngy_fx(TMPDTFS_FX); /* Q = 2*TMPDTFS_FX->Q */ - - IF (Ltemp2==0) - { - Ltemp_fx=0; - } - ELSE - { - expb = norm_l(Ltemp1); - fracb = extract_h(L_shl(Ltemp1,expb)); - expb = sub(30, add(expb,shl(TMPDTFS_FX->Q, 1))); - expa = norm_l(Ltemp2); - fraca = extract_h(L_shl(Ltemp2,expa)); - expa = sub(30, add(expa,shl(TMPDTFS_FX->Q, 1))); - - scale = shr(sub(fraca,fracb),15); - fracb = shl(fracb,scale); - expb = sub(expb,scale); - - tmp = div_s(fracb,fraca); /* tmp in Q15 */ - exp = sub(expb,expa); /* ans = tmp*2^(exp) */ - Ltemp_fx = L_shl(tmp, add(exp,12)); /* make tmp Q27 */ - - } - test(); - IF (L_sub(Ltemp_fx , 6710886)>0 && (!st_fx->rate_control_fx)) /* 0.05 in Q27 = 6710886 */ - { - /*if (10.0*log10(DTFS_getEngy_band(*TMPDTFS,1500.0,upper_cut_off_freq_of_interest)/ */ - /*DTFS_getEngy_band(*TMPDTFS3,1500.0,upper_cut_off_freq_of_interest)) < 0.1) */ - - Ltemp1 = DTFS_getEngy_band_fx(*TMPDTFS_FX,1500,upper_cut_off_freq_of_interest_fx); - Ltemp2 = DTFS_getEngy_band_fx(*TMPDTFS3_FX,1500,upper_cut_off_freq_of_interest_fx); - - /*--------------------------------------------------------------*/ - /* Ltemp_fx = (Word32)divide_dp(Ltemp1, Ltemp2, Qadj,1);//Q29+1 */ - /*--------------------------------------------------------------*/ - IF (Ltemp2==0) - { - Ltemp_fx=0; - } - ELSE - { - expa = norm_l(Ltemp2); - fraca = extract_h(L_shl(Ltemp2,expa)); - expa = sub(30, expa); - - expb = norm_l(Ltemp1); - fracb = round_fx(L_shl(Ltemp1,expb)); - expb = sub(30,expb); - - scale = shr(sub(fraca,fracb),15); - fracb = shl(fracb,scale); - expb = sub(expb,scale); - - tmp = div_s(fracb,fraca); - exp = sub(expb,expa); - Ltemp_fx = L_shl(tmp,add(exp,14)); /* answer in Q29 */ - - } - /*-------------------------------------------*/ - - /* 10.0*log10(Ltemp_fx) */ - exp_ee = norm_l(Ltemp_fx); - frac_ee = Log2_norm_lc(L_shl(Ltemp_fx, exp_ee)); - exp_ee = sub(30,add(exp_ee,29)); /* 30 fixed here, 29 is the Q of Ltemp_fx */ - Ltmp = Mpy_32_16(exp_ee, frac_ee, LG10); /* LG10 in Q13, so answer Ltmp in Q14 */ - - IF(L_sub(Ltmp,1638)<0) /* 1638 = 0.1 in Q14 */ - { - /* if (res_enratio > 0.8) */ - if (L_sub(res_enratio_fx , 1638)>0) /* 1638 = 0.8 in Q11, res_enratio_fx in Q11 */ - { - PPP_MODE_E = 'B'; - move16(); - } - } - } - - /* To increase bump up, raise first threshold, lower second */ - /*tmp = (float)(10.0*log10(DTFS_getEngy(*TMPDTFS)/DTFS_getEngy(*TMPDTFS3)));*/ - Lacc = DTFS_getEngy_P2A_fx(TMPDTFS_FX); /* Q = 2*(TMPDTFS_FX->Q) */ - Lacc1= DTFS_getEngy_P2A_fx(TMPDTFS3_FX); /* Q = 2*(TMPDTFS3_FX->Q) */ - - - sft=shl(sub(TMPDTFS_FX->Q,TMPDTFS3_FX->Q),1);/* to check if Lacc<=2*Lacc1 */ - flag1=0; - move16(); - IF (sft>0) - { - /*if (L_sub40_40(L_shr40(Lacc,sft),Lacc1)<=0) */ - Lacc = L_shr(Lacc,sft); - flag1=1; - move16(); /* do the divide */ - } - ELSE - { - /*if (L_sub40_40(Lacc,L_shr40(Lacc1,negate(sft)))<=0) */ - Lacc1 = L_shr(Lacc1,negate(sft)); - flag1=1; - move16();/* do the divide */ - } - IF (sub(flag1,1)==0) - { - expb = norm_l(Lacc); - fracb = extract_h(L_shl(Lacc,expb)); - expb = sub(30,add(expb,shl(TMPDTFS_FX->Q, 1))); - - expa = norm_l(Lacc1); - fraca = extract_h(L_shl(Lacc1,expa)); - expa = sub(30,add(expa,shl(TMPDTFS3_FX->Q, 1))); - - scale = shr(sub(fraca,fracb),15); - fracb = shl(fracb,scale); - expb = sub(expb,scale); - - tmp = div_s(fracb,fraca); /* tmp is always Q15 */ - exp = sub(expb,expa); /* Answer after division Lacc/Lacc1 = (2^exp)*(tmp/2^15) */ - - L_tmp = L_deposit_h(tmp); /* tmp is always Q15, L_tmp is always Q31 */ - expa = norm_l(L_tmp); - L_tmp = L_shl(L_tmp,expa); - exp = sub(30,add(expa,sub(31,exp))); - frac = Log2_norm_lc(L_tmp); - L_tmp = Mpy_32_16(exp,frac,12330); /* L_tmp is always Q13 */ - Ltemp = L_shl(L_tmp,10); /* Ltemp is always Q23 */ - } - ELSE - { - Ltemp = L_add(MAX_32, 0); - } - - test(); - if ((Ltemp <= 0)&&(!st_fx->rate_control_fx)) - { - PPP_MODE_E = 'B'; - move16(); - } - - IF ( sub(shl(vadsnr_fx,1) ,st_fx->SNR_THLD_fx) < 0 ) /* Q8 */ - { - /* if ((( tmp < 3.05 && max(res_enratio,sp_enratio) > 0.8 ) && (st->rate_control))|| - (( tmp < 2.8 && max(res_enratio,sp_enratio) > 0.65 ) && (!st->rate_control))) */ - /* First comparison in Q23, Second comparison in Q15 */ - test(); - test(); - test(); - test(); - test(); - if ((( L_sub(Ltemp, 25585254 ) < 0 && L_sub(L_max(L_shl(res_enratio_fx,4),sp_enratio_fx) , 6554)> 0 )&&(st_fx->rate_control_fx))|| - (( L_sub(Ltemp, 23488102 ) < 0 && L_sub(L_max(L_shl(res_enratio_fx,4),sp_enratio_fx) , 5325)> 0 )&&(!st_fx->rate_control_fx))) - { - PPP_MODE_E = 'B'; - move16(); - } - } - ELSE - { - /* if ((( tmp < 2.4 && max(res_enratio,sp_enratio) > 0.94) && (st->rate_control))|| - (( tmp < 4.5 && max(res_enratio,sp_enratio) > 0.5 ) && (!st->rate_control))) */ - test(); - test(); - test(); - test(); - test(); - if ((( L_sub(Ltemp ,20132659 ) < 0 && L_sub(L_max(L_shl(res_enratio_fx,4),sp_enratio_fx) , 7700)> 0 )&&(st_fx->rate_control_fx))|| - (( L_sub(Ltemp, 37748736 ) < 0 && L_sub(L_max(L_shl(res_enratio_fx,4),sp_enratio_fx) , 4096)> 0 )&&(!st_fx->rate_control_fx))) - { - PPP_MODE_E = 'B'; - move16(); - } - } - - /* -----End closed-loop Bump-Up */ - } - ELSE - { - PPP_MODE_E = 'B' ; - move16();/*Amplitude quantization is failing*/ - } - } - ELSE - { - } - if (PPP_MODE_E == 'B') - { - st_fx->bump_up_fx = 1; - move16(); - free(CURRP_NQ_FX); - free(TMPDTFS_FX); - free(TMPDTFS2_FX); - free(TMPDTFS3_FX); - free(CURRP_Q_E_FX); - free(dtfs_temp_fx); - return; - } - - IF ( st_fx->Q_to_F_fx ) - { - st_fx->patterncount_fx = add(st_fx->patterncount_fx ,st_fx->pattern_m_fx); - - IF (sub(st_fx->patterncount_fx , 1000)>=0) - { - st_fx->patterncount_fx = sub (st_fx->patterncount_fx , 1000); - PPP_MODE_E = 'B'; - move16(); - st_fx->bump_up_fx = 1; - move16(); - free(CURRP_NQ_FX); - free(TMPDTFS_FX); - free(TMPDTFS2_FX); - free(TMPDTFS3_FX); - free(CURRP_Q_E_FX); - free(dtfs_temp_fx); - return; - } - - } - - /* packetization of the delta lag in_fx PPP */ - IF (sub(PPP_MODE_E,'Q') == 0) - { - Q_delta_lag = add(delta_lag_E,11); /* to make it positive always */ - - push_indice_fx( st_fx, IND_DELTALAG, Q_delta_lag, 5 ); - } - - WIsyn_fx(*dtfs_temp_fx, CURRP_Q_E_FX, lpc2_fx, &(st_fx->ph_offset_E_fx), out_fx, L_FRAME,0,S_fx,C_fx, - pf_temp1,pf_temp2,pf_temp,pf_n2); - /* i/o ph_offset_fx in Q15, out_fx in Q0 */ - - DTFS_copy_fx(dtfs_temp_fx, *CURRP_Q_E_FX); - Lacc = DTFS_getEngy_P2A_fx(CURRP_NQ_FX); - st_fx->Q_prev_cw_en_fx=norm_l(Lacc); - - /* st_fx->Q_prev_cw_en_fx = (Lacc==0)?31: st_fx->Q_prev_cw_en_fx;move16(); */ - if (Lacc==0) - { - st_fx->Q_prev_cw_en_fx = 31; - move16(); - } - - st_fx->prev_cw_en_fx=(Word32) L_shl(Lacc,st_fx->Q_prev_cw_en_fx); /*2Q+Q_prev_cw_en_fx */ - st_fx->Q_prev_cw_en_fx=add(st_fx->Q_prev_cw_en_fx,shl(CURRP_NQ_FX->Q,1)); - /* Copy DTFS related parameters from 'dtfs_temp' to 'st_fx' structure */ - st_fx->dtfs_enc_lag_fx = dtfs_temp_fx->lag_fx; - move16(); - st_fx->dtfs_enc_nH_fx = dtfs_temp_fx->nH_fx; - move16(); - st_fx->dtfs_enc_nH_4kHz_fx = dtfs_temp_fx->nH_4kHz_fx; - move16(); - st_fx->dtfs_enc_upper_cut_off_freq_of_interest_fx = dtfs_temp_fx->upper_cut_off_freq_of_interest_fx; - move16(); - st_fx->dtfs_enc_upper_cut_off_freq_fx = dtfs_temp_fx->upper_cut_off_freq_fx; - move16(); - Copy(dtfs_temp_fx->a_fx, st_fx->dtfs_enc_a_fx, MAXLAG_WI); - Copy(dtfs_temp_fx->b_fx, st_fx->dtfs_enc_b_fx, MAXLAG_WI); - - st_fx->dtfs_enc_Q = dtfs_temp_fx->Q; - move16(); - - free(CURRP_NQ_FX); - free(TMPDTFS_FX); - free(TMPDTFS2_FX); - free(TMPDTFS3_FX); - free(CURRP_Q_E_FX); - free(dtfs_temp_fx); - - return; -} - - -/*===================================================================*/ -/* FUNCTION : synthesis_filter_fx () */ -/*-------------------------------------------------------------------*/ -/* PURPOSE : IIR-filter residual by the LPC sysnthesis filter */ -/*-------------------------------------------------------------------*/ -/* INPUT ARGUMENTS : */ -/* */ -/* _ (Word16 []) b : filter coefficients (Qc). */ -/* _ (Word16 []) x : residual input (Qn). */ -/* _ (Word16) P : filter order. */ -/* _ (Word16) N : number of input samples. */ -/* _ (Word16) Qa : Q factor compensation (Qa=15-Qc) */ -/*-------------------------------------------------------------------*/ -/* OUTPUT ARGUMENTS : */ -/* */ -/* _ (Word16 []) y : output speech (Qn) */ -/*-------------------------------------------------------------------*/ -/* INPUT/OUTPUT ARGUMENTS : */ -/* */ -/* _ (Word32 []) buf : filter memory (Q16+Qn) */ -/*-------------------------------------------------------------------*/ -/* RETURN ARGUMENTS : _ None. */ -/*===================================================================*/ -/* y(n)=sum(i=1 to 10){ */ -/* rxLpcCoeff(i)*rxFormSynthMem(n-i) */ -/* } */ -/* +fres(n) */ -/*===================================================================*/ -void synthesis_filter_fx (Word16 b[], Word16 x[], Word16 y[], Word16 buf[], - Word16 P, Word16 N ) -{ - Word32 acc; - Word16 i, j; - - FOR (i = 0; i < N; i++) - { - acc = L_deposit_h(*x++);/*Q16 */ - acc = L_shr(acc, 3);/*Q13 */ - - FOR (j = P - 1; j > 0; j--) - { - /* acc = L_sub(acc, L_mult(memory[j], coef[j])); */ - acc = L_msu(acc, buf[j], b[j]);/*Q13 */ - buf[j] = buf[j - 1]; - move16(); - } - /* acc = L_sub(acc, L_mult(memory[0], coef[0])); */ - acc = L_msu(acc, buf[0], b[0]); - acc = L_shl(acc, 3); - - *y++ = round_fx(acc); - buf[0] = round_fx(acc); - } -} - - - - - diff --git a/src/libs/libevs/lib_enc/waveadjust_fec_cod.cpp b/src/libs/libevs/lib_enc/waveadjust_fec_cod.cpp old mode 100755 new mode 100644 index 8b4d103f..91d3bb9c --- a/src/libs/libevs/lib_enc/waveadjust_fec_cod.cpp +++ b/src/libs/libevs/lib_enc/waveadjust_fec_cod.cpp @@ -1,76 +1,43 @@ /*==================================================================================== - EVS Codec 3GPP TS26.442 Apr 03, 2018. Version 12.11.0 / 13.6.0 / 14.2.0 + EVS Codec 3GPP TS26.443 Nov 13, 2018. Version 12.11.0 / 13.7.0 / 14.3.0 / 15.1.0 ====================================================================================*/ -#include +#include +#include #include -#include -#include "prot_fx.h" -#include "stat_com.h" -#include "stl.h" /* for wmc_tool */ +#include +#include "prot.h" -Word32 SFM_Cal(Word32 magn[], Word16 n) +/*-------------------------------------------------------------------* + * SFM_Cal() + * + * + *--------------------------------------------------------------------*/ + +float SFM_Cal( + float const fcoef[], + int n +) { - /* Counted Dymamic RAM: 16 words */ - Word32 logCurFlatness; - Word32 magn_abs, frac, logMagn, sumLogMagn, sumMagn; - Word16 i, norm_value, logSumMagn, logn; - sumLogMagn = L_deposit_l(0); - sumMagn = L_deposit_l(0); - FOR(i = 0; i < n; i++) - { - /* log2(magn(i)) */ - magn_abs = L_abs(magn[i]); - norm_value = norm_l(L_max(magn_abs, 1)); - /* next two codes lost precision. */ - frac = L_and(L_shr(L_shl(magn_abs, norm_value), 22), 0xFF); - logMagn = L_deposit_l(add(shl(sub(30, norm_value), 8), kLog2TableFrac_x[frac]));; /* Q8 */ - /* sum(log2(magn(i))) */ - sumLogMagn =L_add(sumLogMagn, logMagn); /* Q8 */ + int i, k; + double geoMean = 0, arithMean = 0, SFM; + double tmp[4] = {1, 1, 1, 1}; - sumMagn =L_add(sumMagn, magn_abs); - } - - IF(L_sub(sumMagn,MAX_32)==0) + for (k = 0; k < 4; k++) { - sumMagn = L_deposit_l(0); - FOR(i = 0; i < n; i++) + + for (i = k*(n>>2); i < (k+1)*(n>>2); i++) { - magn_abs = L_shr(L_abs(magn[i]), 8); - sumMagn = L_add(sumMagn, magn_abs); + tmp[k] *= (fabs(fcoef[i]) + EPSILON); + arithMean += fabs(fcoef[i]); } - /* log2(sumMagn) */ - norm_value = norm_l(sumMagn); - frac = L_and(L_shr(L_shl(sumMagn, norm_value), 22), 0xFF); - logSumMagn = add(shl(sub(38,norm_value), 8), kLog2TableFrac_x[frac]); /* Q8 */ - } - ELSE - { - /* log2(sumMagn) */ - norm_value = norm_l(sumMagn); - frac = L_and(L_shr(L_shl(sumMagn, norm_value), 22), 0xFF); - logSumMagn = add(shl(sub(30, norm_value), 8), kLog2TableFrac_x[frac]); /* Q8 */ } + geoMean = log(tmp[0])+log(tmp[1])+log(tmp[2])+log(tmp[3]); + geoMean = geoMean/n; + geoMean = exp(geoMean); + arithMean /= n; + SFM = (geoMean+EPSILON)/(arithMean+EPSILON); - /* log2(n) */ - norm_value = norm_l(n); - frac = L_and(L_shr(L_shl(n, norm_value), 22), 0xFF); - logn = add(shl(sub(30, norm_value), 8), kLog2TableFrac_x[frac]); /* Q8 */ - - - logMagn=L_sub(L_mult0(n, sub(logSumMagn, logn)), sumLogMagn); - logMagn = (Word32)L_max(0, logMagn); - - logCurFlatness = L_deposit_l(div_l(L_shl(logMagn, 1), n)); - frac = L_and(logCurFlatness, 0xFF); - norm_value = (Word16)L_shr(logCurFlatness, 8); - move16(); - - logCurFlatness = L_sub(kExp2TableFrac_x[frac], 33); - logCurFlatness = L_shl(logCurFlatness, sub(16, norm_value)); /* Q31 */ - - - return logCurFlatness; + return (float)SFM; } -